gdb-low.S
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:7k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * gdb-low.S contains the low-level trap handler for the GDB stub.
  3.  *
  4.  * Copyright (C) 1995 Andreas Busse
  5.  */
  6. #include <linux/config.h>
  7. #include <linux/sys.h>
  8. #include <asm/asm.h>
  9. #include <asm/errno.h>
  10. #include <asm/mipsregs.h>
  11. #include <asm/regdef.h>
  12. #include <asm/stackframe.h>
  13. #include <asm/gdb-stub.h>
  14. /*
  15.  * The low level trap handler
  16.  */
  17. .align  5
  18. NESTED(trap_low, GDB_FR_SIZE, sp)
  19.   .set noat
  20. .set  noreorder
  21. mfc0 k0,CP0_STATUS
  22. sll k0,3      /* extract cu0 bit */
  23. bltz k0,1f
  24. move k1,sp
  25. /*
  26.  * Called from user mode, go somewhere else.
  27.  */
  28. lui k1,%hi(saved_vectors)
  29. mfc0 k0,CP0_CAUSE
  30. andi k0,k0,0x7c
  31. add k1,k1,k0
  32. lw k0,%lo(saved_vectors)(k1)
  33. jr k0
  34. nop
  35. 1:
  36. move k0,sp
  37. subu sp,k1,GDB_FR_SIZE
  38. sw k0,GDB_FR_REG29(sp)
  39. sw v0,GDB_FR_REG2(sp)
  40. /*
  41.  * First save the CP0 and special registers
  42.  */
  43. mfc0 v0,CP0_STATUS
  44. sw v0,GDB_FR_STATUS(sp)
  45. mfc0 v0,CP0_CAUSE
  46. sw v0,GDB_FR_CAUSE(sp)
  47. mfc0 v0,CP0_EPC
  48. sw v0,GDB_FR_EPC(sp)
  49. mfc0 v0,CP0_BADVADDR
  50. sw v0,GDB_FR_BADVADDR(sp)
  51. mfhi v0
  52. sw v0,GDB_FR_HI(sp)
  53. mflo v0
  54. sw v0,GDB_FR_LO(sp)
  55. /*
  56.  * Now the integer registers
  57.  */
  58. sw zero,GDB_FR_REG0(sp) /* I know... */
  59. sw $1,GDB_FR_REG1(sp)
  60. /* v0 already saved */
  61. sw v1,GDB_FR_REG3(sp)
  62. sw a0,GDB_FR_REG4(sp)
  63. sw a1,GDB_FR_REG5(sp)
  64. sw a2,GDB_FR_REG6(sp)
  65. sw a3,GDB_FR_REG7(sp)
  66. sw t0,GDB_FR_REG8(sp)
  67. sw t1,GDB_FR_REG9(sp)
  68. sw t2,GDB_FR_REG10(sp)
  69. sw t3,GDB_FR_REG11(sp)
  70. sw t4,GDB_FR_REG12(sp)
  71. sw t5,GDB_FR_REG13(sp)
  72. sw t6,GDB_FR_REG14(sp)
  73. sw t7,GDB_FR_REG15(sp)
  74. sw s0,GDB_FR_REG16(sp)
  75. sw s1,GDB_FR_REG17(sp)
  76. sw s2,GDB_FR_REG18(sp)
  77. sw s3,GDB_FR_REG19(sp)
  78. sw s4,GDB_FR_REG20(sp)
  79. sw s5,GDB_FR_REG21(sp)
  80. sw s6,GDB_FR_REG22(sp)
  81. sw s7,GDB_FR_REG23(sp)
  82. sw t8,GDB_FR_REG24(sp)
  83. sw t9,GDB_FR_REG25(sp)
  84. sw k0,GDB_FR_REG26(sp)
  85. sw k1,GDB_FR_REG27(sp)
  86. sw gp,GDB_FR_REG28(sp)
  87. /* sp already saved */
  88. sw fp,GDB_FR_REG30(sp)
  89. sw ra,GDB_FR_REG31(sp)
  90. CLI /* disable interrupts */
  91. /*
  92.  * Followed by the floating point registers
  93.  */
  94. mfc0 v0,CP0_STATUS /* FPU enabled? */
  95. srl v0,v0,16
  96. andi v0,v0,(ST0_CU1 >> 16)
  97. beqz v0,2f /* disabled, skip */
  98.  nop
  99. swc1 $0,GDB_FR_FPR0(sp)
  100. swc1 $1,GDB_FR_FPR1(sp)
  101. swc1 $2,GDB_FR_FPR2(sp)
  102. swc1 $3,GDB_FR_FPR3(sp)
  103. swc1 $4,GDB_FR_FPR4(sp)
  104. swc1 $5,GDB_FR_FPR5(sp)
  105. swc1 $6,GDB_FR_FPR6(sp)
  106. swc1 $7,GDB_FR_FPR7(sp)
  107. swc1 $8,GDB_FR_FPR8(sp)
  108. swc1 $9,GDB_FR_FPR9(sp)
  109. swc1 $10,GDB_FR_FPR10(sp)
  110. swc1 $11,GDB_FR_FPR11(sp)
  111. swc1 $12,GDB_FR_FPR12(sp)
  112. swc1 $13,GDB_FR_FPR13(sp)
  113. swc1 $14,GDB_FR_FPR14(sp)
  114. swc1 $15,GDB_FR_FPR15(sp)
  115. swc1 $16,GDB_FR_FPR16(sp)
  116. swc1 $17,GDB_FR_FPR17(sp)
  117. swc1 $18,GDB_FR_FPR18(sp)
  118. swc1 $19,GDB_FR_FPR19(sp)
  119. swc1 $20,GDB_FR_FPR20(sp)
  120. swc1 $21,GDB_FR_FPR21(sp)
  121. swc1 $22,GDB_FR_FPR22(sp)
  122. swc1 $23,GDB_FR_FPR23(sp)
  123. swc1 $24,GDB_FR_FPR24(sp)
  124. swc1 $25,GDB_FR_FPR25(sp)
  125. swc1 $26,GDB_FR_FPR26(sp)
  126. swc1 $27,GDB_FR_FPR27(sp)
  127. swc1 $28,GDB_FR_FPR28(sp)
  128. swc1 $29,GDB_FR_FPR29(sp)
  129. swc1 $30,GDB_FR_FPR30(sp)
  130. swc1 $31,GDB_FR_FPR31(sp)
  131. /*
  132.  * FPU control registers
  133.  */
  134. mfc1 v0,CP1_STATUS
  135. sw v0,GDB_FR_FSR(sp)
  136. mfc1 v0,CP1_REVISION
  137. sw v0,GDB_FR_FIR(sp)
  138. /*
  139.  * Current stack frame ptr
  140.  */
  141. 2:
  142. sw sp,GDB_FR_FRP(sp)
  143. /*
  144.  * CP0 registers (R4000/R4400 unused registers skipped)
  145.  */
  146. mfc0 v0,CP0_INDEX
  147. sw v0,GDB_FR_CP0_INDEX(sp)
  148. mfc0 v0,CP0_RANDOM
  149. sw v0,GDB_FR_CP0_RANDOM(sp)
  150. mfc0 v0,CP0_ENTRYLO0
  151. sw v0,GDB_FR_CP0_ENTRYLO0(sp)
  152. mfc0 v0,CP0_ENTRYLO1
  153. sw v0,GDB_FR_CP0_ENTRYLO1(sp)
  154. mfc0 v0,CP0_CONTEXT
  155. sw v0,GDB_FR_CP0_CONTEXT(sp)
  156. mfc0 v0,CP0_PAGEMASK
  157. sw v0,GDB_FR_CP0_PAGEMASK(sp)
  158. mfc0 v0,CP0_WIRED
  159. sw v0,GDB_FR_CP0_WIRED(sp)
  160. mfc0 v0,CP0_ENTRYHI
  161. sw v0,GDB_FR_CP0_ENTRYHI(sp)
  162. mfc0 v0,CP0_PRID
  163. sw v0,GDB_FR_CP0_PRID(sp)
  164. .set at
  165. /*
  166.  * Continue with the higher level handler
  167.  */
  168. move a0,sp
  169. jal handle_exception
  170.  nop
  171. /*
  172.  * Restore all writable registers, in reverse order
  173.  */
  174. .set noat
  175. lw v0,GDB_FR_CP0_ENTRYHI(sp)
  176. lw v1,GDB_FR_CP0_WIRED(sp)
  177. mtc0 v0,CP0_ENTRYHI
  178. mtc0 v1,CP0_WIRED
  179. lw v0,GDB_FR_CP0_PAGEMASK(sp)
  180. lw v1,GDB_FR_CP0_ENTRYLO1(sp)
  181. mtc0 v0,CP0_PAGEMASK
  182. mtc0 v1,CP0_ENTRYLO1
  183. lw v0,GDB_FR_CP0_ENTRYLO0(sp)
  184. lw v1,GDB_FR_CP0_INDEX(sp)
  185. mtc0 v0,CP0_ENTRYLO0
  186. lw v0,GDB_FR_CP0_CONTEXT(sp)
  187. mtc0 v1,CP0_INDEX
  188. mtc0 v0,CP0_CONTEXT
  189. /*
  190.  * Next, the floating point registers
  191.  */
  192. mfc0 v0,CP0_STATUS /* check if the FPU is enabled */
  193. srl v0,v0,16
  194. andi v0,v0,(ST0_CU1 >> 16)
  195. beqz v0,3f /* disabled, skip */
  196.  nop
  197. lwc1 $31,GDB_FR_FPR31(sp)
  198. lwc1 $30,GDB_FR_FPR30(sp)
  199. lwc1 $29,GDB_FR_FPR29(sp)
  200. lwc1 $28,GDB_FR_FPR28(sp)
  201. lwc1 $27,GDB_FR_FPR27(sp)
  202. lwc1 $26,GDB_FR_FPR26(sp)
  203. lwc1 $25,GDB_FR_FPR25(sp)
  204. lwc1 $24,GDB_FR_FPR24(sp)
  205. lwc1 $23,GDB_FR_FPR23(sp)
  206. lwc1 $22,GDB_FR_FPR22(sp)
  207. lwc1 $21,GDB_FR_FPR21(sp)
  208. lwc1 $20,GDB_FR_FPR20(sp)
  209. lwc1 $19,GDB_FR_FPR19(sp)
  210. lwc1 $18,GDB_FR_FPR18(sp)
  211. lwc1 $17,GDB_FR_FPR17(sp)
  212. lwc1 $16,GDB_FR_FPR16(sp)
  213. lwc1 $15,GDB_FR_FPR15(sp)
  214. lwc1 $14,GDB_FR_FPR14(sp)
  215. lwc1 $13,GDB_FR_FPR13(sp)
  216. lwc1 $12,GDB_FR_FPR12(sp)
  217. lwc1 $11,GDB_FR_FPR11(sp)
  218. lwc1 $10,GDB_FR_FPR10(sp)
  219. lwc1 $9,GDB_FR_FPR9(sp)
  220. lwc1 $8,GDB_FR_FPR8(sp)
  221. lwc1 $7,GDB_FR_FPR7(sp)
  222. lwc1 $6,GDB_FR_FPR6(sp)
  223. lwc1 $5,GDB_FR_FPR5(sp)
  224. lwc1 $4,GDB_FR_FPR4(sp)
  225. lwc1 $3,GDB_FR_FPR3(sp)
  226. lwc1 $2,GDB_FR_FPR2(sp)
  227. lwc1 $1,GDB_FR_FPR1(sp)
  228. lwc1 $0,GDB_FR_FPR0(sp)
  229. /*
  230.  * Now the CP0 and integer registers
  231.  */
  232. 3:
  233. mfc0 t0,CP0_STATUS
  234. ori t0,0x1f
  235. xori t0,0x1f
  236. mtc0 t0,CP0_STATUS
  237. lw v0,GDB_FR_STATUS(sp)
  238. lw v1,GDB_FR_EPC(sp)
  239. mtc0 v0,CP0_STATUS
  240. mtc0 v1,CP0_EPC
  241. lw v0,GDB_FR_HI(sp)
  242. lw v1,GDB_FR_LO(sp)
  243. mthi v0
  244. mtlo v0
  245. lw ra,GDB_FR_REG31(sp)
  246. lw fp,GDB_FR_REG30(sp)
  247. lw gp,GDB_FR_REG28(sp)
  248. lw k1,GDB_FR_REG27(sp)
  249. lw k0,GDB_FR_REG26(sp)
  250. lw t9,GDB_FR_REG25(sp)
  251. lw t8,GDB_FR_REG24(sp)
  252. lw s7,GDB_FR_REG23(sp)
  253. lw s6,GDB_FR_REG22(sp)
  254. lw s5,GDB_FR_REG21(sp)
  255. lw s4,GDB_FR_REG20(sp)
  256. lw s3,GDB_FR_REG19(sp)
  257. lw s2,GDB_FR_REG18(sp)
  258. lw s1,GDB_FR_REG17(sp)
  259. lw s0,GDB_FR_REG16(sp)
  260. lw t7,GDB_FR_REG15(sp)
  261. lw t6,GDB_FR_REG14(sp)
  262. lw t5,GDB_FR_REG13(sp)
  263. lw t4,GDB_FR_REG12(sp)
  264. lw t3,GDB_FR_REG11(sp)
  265. lw t2,GDB_FR_REG10(sp)
  266. lw t1,GDB_FR_REG9(sp)
  267. lw t0,GDB_FR_REG8(sp)
  268. lw a3,GDB_FR_REG7(sp)
  269. lw a2,GDB_FR_REG6(sp)
  270. lw a1,GDB_FR_REG5(sp)
  271. lw a0,GDB_FR_REG4(sp)
  272. lw v1,GDB_FR_REG3(sp)
  273. lw v0,GDB_FR_REG2(sp)
  274. lw $1,GDB_FR_REG1(sp)
  275. #ifdef CONFIG_CPU_R3000
  276. lw k0, GDB_FR_EPC(sp)
  277. lw sp, GDB_FR_REG29(sp) /* Deallocate stack */
  278. jr k0
  279. rfe
  280. #else
  281. lw sp, GDB_FR_REG29(sp) /* Deallocate stack */
  282. .set mips3
  283. eret
  284. .set mips0
  285. #endif
  286. .set at
  287. .set reorder
  288. END(trap_low)
  289. LEAF(kgdb_read_byte)
  290. .set push
  291. .set noreorder
  292. .set nomacro
  293. 4: lb t0, (a0)
  294. .set pop
  295. sb t0, (a1)
  296. li v0, 0
  297. jr ra
  298. .section __ex_table,"a"
  299. PTR 4b, kgdbfault
  300. .previous
  301. END(kgdb_read_byte)
  302. LEAF(kgdb_write_byte)
  303. .set push
  304. .set noreorder
  305. .set nomacro
  306. 5: sb a0, (a1)
  307. .set pop
  308. li v0, 0
  309. jr ra
  310. .section __ex_table,"a"
  311. PTR 5b, kgdbfault
  312. .previous
  313. END(kgdb_write_byte)
  314. .type kgdbfault@function
  315. .ent kgdbfault
  316. kgdbfault: li v0, -EFAULT
  317. jr ra
  318. .end kgdbfault