interrupts.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * (C) Copyright 2004
  3. * DAVE Srl
  4. * http://www.dave-tech.it
  5. * http://www.wawnet.biz
  6. * mailto:info@wawnet.biz
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/hardware.h>
  28. #include <asm/proc-armv/ptrace.h>
  29. /* we always count down the max. */
  30. #define TIMER_LOAD_VAL 0xffff
  31. /* macro to read the 16 bit timer */
  32. #define READ_TIMER (TCNTO1 & 0xffff)
  33. #ifdef CONFIG_USE_IRQ
  34. #error CONFIG_USE_IRQ NOT supported
  35. #else
  36. void enable_interrupts (void)
  37. {
  38. return;
  39. }
  40. int disable_interrupts (void)
  41. {
  42. return 0;
  43. }
  44. #endif
  45. void bad_mode (void)
  46. {
  47. panic ("Resetting CPU ...\n");
  48. reset_cpu (0);
  49. }
  50. void show_regs (struct pt_regs *regs)
  51. {
  52. unsigned long flags;
  53. const char *processor_modes[] =
  54. { "USER_26", "FIQ_26", "IRQ_26", "SVC_26", "UK4_26", "UK5_26",
  55. "UK6_26", "UK7_26",
  56. "UK8_26", "UK9_26", "UK10_26", "UK11_26", "UK12_26", "UK13_26",
  57. "UK14_26", "UK15_26",
  58. "USER_32", "FIQ_32", "IRQ_32", "SVC_32", "UK4_32", "UK5_32",
  59. "UK6_32", "ABT_32",
  60. "UK8_32", "UK9_32", "UK10_32", "UND_32", "UK12_32", "UK13_32",
  61. "UK14_32", "SYS_32"
  62. };
  63. flags = condition_codes (regs);
  64. printf ("pc : [<%08lx>] lr : [<%08lx>]\n"
  65. "sp : %08lx ip : %08lx fp : %08lx\n",
  66. instruction_pointer (regs),
  67. regs->ARM_lr, regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
  68. printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
  69. regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
  70. printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
  71. regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
  72. printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
  73. regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
  74. printf ("Flags: %c%c%c%c",
  75. flags & CC_N_BIT ? 'N' : 'n',
  76. flags & CC_Z_BIT ? 'Z' : 'z',
  77. flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
  78. printf (" IRQs %s FIQs %s Mode %s%s\n",
  79. interrupts_enabled (regs) ? "on" : "off",
  80. fast_interrupts_enabled (regs) ? "on" : "off",
  81. processor_modes[processor_mode (regs)],
  82. thumb_mode (regs) ? " (T)" : "");
  83. }
  84. void do_undefined_instruction (struct pt_regs *pt_regs)
  85. {
  86. printf ("undefined instruction\n");
  87. show_regs (pt_regs);
  88. bad_mode ();
  89. }
  90. void do_software_interrupt (struct pt_regs *pt_regs)
  91. {
  92. printf ("software interrupt\n");
  93. show_regs (pt_regs);
  94. bad_mode ();
  95. }
  96. void do_prefetch_abort (struct pt_regs *pt_regs)
  97. {
  98. printf ("prefetch abort\n");
  99. show_regs (pt_regs);
  100. bad_mode ();
  101. }
  102. void do_data_abort (struct pt_regs *pt_regs)
  103. {
  104. printf ("data abort\n");
  105. show_regs (pt_regs);
  106. bad_mode ();
  107. }
  108. void do_not_used (struct pt_regs *pt_regs)
  109. {
  110. printf ("not used\n");
  111. show_regs (pt_regs);
  112. bad_mode ();
  113. }
  114. void do_fiq (struct pt_regs *pt_regs)
  115. {
  116. printf ("fast interrupt request\n");
  117. show_regs (pt_regs);
  118. bad_mode ();
  119. }
  120. void do_irq (struct pt_regs *pt_regs)
  121. {
  122. printf ("interrupt request\n");
  123. show_regs (pt_regs);
  124. bad_mode ();
  125. }
  126. static ulong timestamp;
  127. static ulong lastdec;
  128. int interrupt_init (void)
  129. {
  130. TCFG0 = 0x000000E9;
  131. TCFG1 = 0x00000004;
  132. TCON = 0x00000900;
  133. TCNTB1 = TIMER_LOAD_VAL;
  134. TCMPB1 = 0;
  135. TCON = 0x00000B00;
  136. TCON = 0x00000900;
  137. lastdec = TCNTB1 = TIMER_LOAD_VAL;
  138. timestamp = 0;
  139. return 0;
  140. }
  141. /*
  142. * timer without interrupts
  143. */
  144. void reset_timer (void)
  145. {
  146. reset_timer_masked ();
  147. }
  148. ulong get_timer (ulong base)
  149. {
  150. return get_timer_masked () - base;
  151. }
  152. void set_timer (ulong t)
  153. {
  154. timestamp = t;
  155. }
  156. void udelay (unsigned long usec)
  157. {
  158. ulong tmo;
  159. tmo = usec / 1000;
  160. tmo *= CFG_HZ;
  161. tmo /= 8;
  162. tmo += get_timer (0);
  163. while (get_timer_masked () < tmo)
  164. /*NOP*/;
  165. }
  166. void reset_timer_masked (void)
  167. {
  168. /* reset time */
  169. lastdec = READ_TIMER;
  170. timestamp = 0;
  171. }
  172. ulong get_timer_masked (void)
  173. {
  174. ulong now = READ_TIMER;
  175. if (lastdec >= now) {
  176. /* normal mode */
  177. timestamp += lastdec - now;
  178. } else {
  179. /* we have an overflow ... */
  180. timestamp += lastdec + TIMER_LOAD_VAL - now;
  181. }
  182. lastdec = now;
  183. return timestamp;
  184. }
  185. void udelay_masked (unsigned long usec)
  186. {
  187. ulong tmo;
  188. ulong endtime;
  189. signed long diff;
  190. if (usec >= 1000) {
  191. tmo = usec / 1000;
  192. tmo *= CFG_HZ;
  193. tmo /= 8;
  194. } else {
  195. tmo = usec * CFG_HZ;
  196. tmo /= (1000*8);
  197. }
  198. endtime = get_timer(0) + tmo;
  199. do {
  200. ulong now = get_timer_masked ();
  201. diff = endtime - now;
  202. } while (diff >= 0);
  203. }