context.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * Copyright 2007-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. /*
  7. * NOTE! The single-stepping code assumes that all interrupt handlers
  8. * start by saving SYSCFG on the stack with their first instruction.
  9. */
  10. /*
  11. * Code to save processor context.
  12. * We even save the register which are preserved by a function call
  13. * - r4, r5, r6, r7, p3, p4, p5
  14. */
  15. .macro save_context_with_interrupts
  16. [--sp] = SYSCFG;
  17. [--sp] = P0; /*orig_p0*/
  18. [--sp] = R0; /*orig_r0*/
  19. [--sp] = ( R7:0, P5:0 );
  20. [--sp] = fp;
  21. [--sp] = usp;
  22. [--sp] = i0;
  23. [--sp] = i1;
  24. [--sp] = i2;
  25. [--sp] = i3;
  26. [--sp] = m0;
  27. [--sp] = m1;
  28. [--sp] = m2;
  29. [--sp] = m3;
  30. [--sp] = l0;
  31. [--sp] = l1;
  32. [--sp] = l2;
  33. [--sp] = l3;
  34. [--sp] = b0;
  35. [--sp] = b1;
  36. [--sp] = b2;
  37. [--sp] = b3;
  38. [--sp] = a0.x;
  39. [--sp] = a0.w;
  40. [--sp] = a1.x;
  41. [--sp] = a1.w;
  42. [--sp] = LC0;
  43. [--sp] = LC1;
  44. [--sp] = LT0;
  45. [--sp] = LT1;
  46. [--sp] = LB0;
  47. [--sp] = LB1;
  48. [--sp] = ASTAT;
  49. [--sp] = r0; /* Skip reserved */
  50. [--sp] = RETS;
  51. r0 = RETI;
  52. [--sp] = r0;
  53. [--sp] = RETX;
  54. [--sp] = RETN;
  55. [--sp] = RETE;
  56. [--sp] = SEQSTAT;
  57. [--sp] = r0; /* Skip IPEND as well. */
  58. /* Switch to other method of keeping interrupts disabled. */
  59. #ifdef CONFIG_DEBUG_HWERR
  60. r0 = 0x3f;
  61. sti r0;
  62. #else
  63. cli r0;
  64. #endif
  65. #ifdef CONFIG_TRACE_IRQFLAGS
  66. sp += -12;
  67. call _trace_hardirqs_off;
  68. sp += 12;
  69. #endif
  70. [--sp] = RETI; /*orig_pc*/
  71. /* Clear all L registers. */
  72. r0 = 0 (x);
  73. l0 = r0;
  74. l1 = r0;
  75. l2 = r0;
  76. l3 = r0;
  77. .endm
  78. .macro save_context_syscall
  79. [--sp] = SYSCFG;
  80. [--sp] = P0; /*orig_p0*/
  81. [--sp] = R0; /*orig_r0*/
  82. [--sp] = ( R7:0, P5:0 );
  83. [--sp] = fp;
  84. [--sp] = usp;
  85. [--sp] = i0;
  86. [--sp] = i1;
  87. [--sp] = i2;
  88. [--sp] = i3;
  89. [--sp] = m0;
  90. [--sp] = m1;
  91. [--sp] = m2;
  92. [--sp] = m3;
  93. [--sp] = l0;
  94. [--sp] = l1;
  95. [--sp] = l2;
  96. [--sp] = l3;
  97. [--sp] = b0;
  98. [--sp] = b1;
  99. [--sp] = b2;
  100. [--sp] = b3;
  101. [--sp] = a0.x;
  102. [--sp] = a0.w;
  103. [--sp] = a1.x;
  104. [--sp] = a1.w;
  105. [--sp] = LC0;
  106. [--sp] = LC1;
  107. [--sp] = LT0;
  108. [--sp] = LT1;
  109. [--sp] = LB0;
  110. [--sp] = LB1;
  111. [--sp] = ASTAT;
  112. [--sp] = r0; /* Skip reserved */
  113. [--sp] = RETS;
  114. r0 = RETI;
  115. [--sp] = r0;
  116. [--sp] = RETX;
  117. [--sp] = RETN;
  118. [--sp] = RETE;
  119. [--sp] = SEQSTAT;
  120. [--sp] = r0; /* Skip IPEND as well. */
  121. [--sp] = RETI; /*orig_pc*/
  122. /* Clear all L registers. */
  123. r0 = 0 (x);
  124. l0 = r0;
  125. l1 = r0;
  126. l2 = r0;
  127. l3 = r0;
  128. .endm
  129. .macro save_context_no_interrupts
  130. [--sp] = SYSCFG;
  131. [--sp] = P0; /* orig_p0 */
  132. [--sp] = R0; /* orig_r0 */
  133. [--sp] = ( R7:0, P5:0 );
  134. [--sp] = fp;
  135. [--sp] = usp;
  136. [--sp] = i0;
  137. [--sp] = i1;
  138. [--sp] = i2;
  139. [--sp] = i3;
  140. [--sp] = m0;
  141. [--sp] = m1;
  142. [--sp] = m2;
  143. [--sp] = m3;
  144. [--sp] = l0;
  145. [--sp] = l1;
  146. [--sp] = l2;
  147. [--sp] = l3;
  148. [--sp] = b0;
  149. [--sp] = b1;
  150. [--sp] = b2;
  151. [--sp] = b3;
  152. [--sp] = a0.x;
  153. [--sp] = a0.w;
  154. [--sp] = a1.x;
  155. [--sp] = a1.w;
  156. [--sp] = LC0;
  157. [--sp] = LC1;
  158. [--sp] = LT0;
  159. [--sp] = LT1;
  160. [--sp] = LB0;
  161. [--sp] = LB1;
  162. [--sp] = ASTAT;
  163. #ifdef CONFIG_KGDB
  164. fp = 0(Z);
  165. r1 = sp;
  166. r1 += 60;
  167. r1 += 60;
  168. r1 += 60;
  169. [--sp] = r1;
  170. #else
  171. [--sp] = r0; /* Skip reserved */
  172. #endif
  173. [--sp] = RETS;
  174. r0 = RETI;
  175. [--sp] = r0;
  176. [--sp] = RETX;
  177. [--sp] = RETN;
  178. [--sp] = RETE;
  179. [--sp] = SEQSTAT;
  180. #ifdef CONFIG_DEBUG_KERNEL
  181. p1.l = lo(IPEND);
  182. p1.h = hi(IPEND);
  183. r1 = [p1];
  184. [--sp] = r1;
  185. #else
  186. [--sp] = r0; /* Skip IPEND as well. */
  187. #endif
  188. [--sp] = r0; /*orig_pc*/
  189. /* Clear all L registers. */
  190. r0 = 0 (x);
  191. l0 = r0;
  192. l1 = r0;
  193. l2 = r0;
  194. l3 = r0;
  195. .endm
  196. .macro restore_context_no_interrupts
  197. sp += 4; /* Skip orig_pc */
  198. sp += 4; /* Skip IPEND */
  199. SEQSTAT = [sp++];
  200. RETE = [sp++];
  201. RETN = [sp++];
  202. RETX = [sp++];
  203. r0 = [sp++];
  204. RETI = r0; /* Restore RETI indirectly when in exception */
  205. RETS = [sp++];
  206. sp += 4; /* Skip Reserved */
  207. ASTAT = [sp++];
  208. LB1 = [sp++];
  209. LB0 = [sp++];
  210. LT1 = [sp++];
  211. LT0 = [sp++];
  212. LC1 = [sp++];
  213. LC0 = [sp++];
  214. a1.w = [sp++];
  215. a1.x = [sp++];
  216. a0.w = [sp++];
  217. a0.x = [sp++];
  218. b3 = [sp++];
  219. b2 = [sp++];
  220. b1 = [sp++];
  221. b0 = [sp++];
  222. l3 = [sp++];
  223. l2 = [sp++];
  224. l1 = [sp++];
  225. l0 = [sp++];
  226. m3 = [sp++];
  227. m2 = [sp++];
  228. m1 = [sp++];
  229. m0 = [sp++];
  230. i3 = [sp++];
  231. i2 = [sp++];
  232. i1 = [sp++];
  233. i0 = [sp++];
  234. sp += 4;
  235. fp = [sp++];
  236. ( R7 : 0, P5 : 0) = [ SP ++ ];
  237. sp += 8; /* Skip orig_r0/orig_p0 */
  238. SYSCFG = [sp++];
  239. .endm
  240. .macro restore_context_with_interrupts
  241. sp += 4; /* Skip orig_pc */
  242. sp += 4; /* Skip IPEND */
  243. SEQSTAT = [sp++];
  244. RETE = [sp++];
  245. RETN = [sp++];
  246. RETX = [sp++];
  247. RETI = [sp++];
  248. #ifdef CONFIG_TRACE_IRQFLAGS
  249. sp += -12;
  250. call _trace_hardirqs_on;
  251. sp += 12;
  252. #endif
  253. RETS = [sp++];
  254. #ifdef CONFIG_SMP
  255. GET_PDA(p0, r0);
  256. r0 = [p0 + PDA_IRQFLAGS];
  257. #else
  258. p0.h = _bfin_irq_flags;
  259. p0.l = _bfin_irq_flags;
  260. r0 = [p0];
  261. #endif
  262. sti r0;
  263. sp += 4; /* Skip Reserved */
  264. ASTAT = [sp++];
  265. LB1 = [sp++];
  266. LB0 = [sp++];
  267. LT1 = [sp++];
  268. LT0 = [sp++];
  269. LC1 = [sp++];
  270. LC0 = [sp++];
  271. a1.w = [sp++];
  272. a1.x = [sp++];
  273. a0.w = [sp++];
  274. a0.x = [sp++];
  275. b3 = [sp++];
  276. b2 = [sp++];
  277. b1 = [sp++];
  278. b0 = [sp++];
  279. l3 = [sp++];
  280. l2 = [sp++];
  281. l1 = [sp++];
  282. l0 = [sp++];
  283. m3 = [sp++];
  284. m2 = [sp++];
  285. m1 = [sp++];
  286. m0 = [sp++];
  287. i3 = [sp++];
  288. i2 = [sp++];
  289. i1 = [sp++];
  290. i0 = [sp++];
  291. sp += 4;
  292. fp = [sp++];
  293. ( R7 : 0, P5 : 0) = [ SP ++ ];
  294. sp += 8; /* Skip orig_r0/orig_p0 */
  295. csync;
  296. SYSCFG = [sp++];
  297. csync;
  298. .endm
  299. .macro save_context_cplb
  300. [--sp] = (R7:0, P5:0);
  301. [--sp] = fp;
  302. [--sp] = a0.x;
  303. [--sp] = a0.w;
  304. [--sp] = a1.x;
  305. [--sp] = a1.w;
  306. [--sp] = LC0;
  307. [--sp] = LC1;
  308. [--sp] = LT0;
  309. [--sp] = LT1;
  310. [--sp] = LB0;
  311. [--sp] = LB1;
  312. [--sp] = RETS;
  313. .endm
  314. .macro restore_context_cplb
  315. RETS = [sp++];
  316. LB1 = [sp++];
  317. LB0 = [sp++];
  318. LT1 = [sp++];
  319. LT0 = [sp++];
  320. LC1 = [sp++];
  321. LC0 = [sp++];
  322. a1.w = [sp++];
  323. a1.x = [sp++];
  324. a0.w = [sp++];
  325. a0.x = [sp++];
  326. fp = [sp++];
  327. (R7:0, P5:0) = [SP++];
  328. .endm
  329. .macro pseudo_long_call func:req, scratch:req
  330. #ifdef CONFIG_ROMKERNEL
  331. \scratch\().l = \func;
  332. \scratch\().h = \func;
  333. call (\scratch);
  334. #else
  335. call \func;
  336. #endif
  337. .endm
  338. #if defined(CONFIG_BFIN_SCRATCH_REG_RETN)
  339. # define EX_SCRATCH_REG RETN
  340. #elif defined(CONFIG_BFIN_SCRATCH_REG_RETE)
  341. # define EX_SCRATCH_REG RETE
  342. #else
  343. # define EX_SCRATCH_REG CYCLES
  344. #endif