stack.s 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. # Hitachi H8 testcase 'ldc'
  2. # mach(): all
  3. # as(h8300): --defsym sim_cpu=0
  4. # as(h8300h): --defsym sim_cpu=1
  5. # as(h8300s): --defsym sim_cpu=2
  6. # as(h8sx): --defsym sim_cpu=3
  7. # ld(h8300h): -m h8300helf
  8. # ld(h8300s): -m h8300self
  9. # ld(h8sx): -m h8300sxelf
  10. .include "testutils.inc"
  11. start
  12. .data
  13. .align 4
  14. stack:
  15. .if (sim_cpu == h8300)
  16. .fill 128, 2, 0
  17. .else
  18. .fill 128, 4, 0
  19. .endif
  20. stacktop:
  21. .text
  22. push_w:
  23. set_grs_a5a5 ; Fill all general regs with a fixed pattern
  24. set_ccr_zero
  25. .if (sim_cpu == h8300)
  26. mov.w #stacktop, r7
  27. .else
  28. mov.l #stacktop, er7
  29. .endif
  30. push.w r0 ; a5a5 is negative
  31. test_neg_set
  32. test_carry_clear
  33. test_zero_clear
  34. test_ovf_clear
  35. push.w r1
  36. push.w r2
  37. push.w r3
  38. test_gr_a5a5 0
  39. test_gr_a5a5 1
  40. test_gr_a5a5 2
  41. test_gr_a5a5 3
  42. mov @stacktop-2, r0
  43. test_gr_a5a5 0
  44. mov @stacktop-4, r0
  45. test_gr_a5a5 0
  46. mov @stacktop-6, r0
  47. test_gr_a5a5 0
  48. mov @stacktop-8, r0
  49. test_gr_a5a5 0
  50. mov.w #1, r1
  51. mov.w #2, r2
  52. mov.w #3, r3
  53. mov.w #4, r4
  54. push.w r1 ; #1 is non-negative, non-zero
  55. test_cc_clear
  56. push.w r2
  57. push.w r3
  58. push.w r4
  59. test_h_gr16 1 r1
  60. test_h_gr16 2 r2
  61. test_h_gr16 3 r3
  62. test_h_gr16 4 r4
  63. mov @stacktop-10, r0
  64. test_h_gr16 1 r0
  65. mov @stacktop-12, r0
  66. test_h_gr16 2 r0
  67. mov @stacktop-14, r0
  68. test_h_gr16 3 r0
  69. mov @stacktop-16, r0
  70. test_h_gr16 4 r0
  71. .if (sim_cpu == h8300)
  72. test_h_gr16 4 r0
  73. test_h_gr16 1 r1
  74. test_h_gr16 2 r2
  75. test_h_gr16 3 r3
  76. test_h_gr16 4 r4
  77. ;;; test_h_gr16 stacktop-16 r7 ; FIXME
  78. .else
  79. test_h_gr32 0xa5a50004 er0
  80. test_h_gr32 0xa5a50001 er1
  81. test_h_gr32 0xa5a50002 er2
  82. test_h_gr32 0xa5a50003 er3
  83. test_h_gr32 0xa5a50004 er4
  84. test_h_gr32 stacktop-16 er7
  85. .endif
  86. test_gr_a5a5 5
  87. test_gr_a5a5 6
  88. pop_w:
  89. set_grs_a5a5 ; Fill all general regs with a fixed pattern
  90. set_ccr_zero
  91. .if (sim_cpu == h8300)
  92. mov.w #stacktop-16, r7
  93. .else
  94. mov.l #stacktop-16, er7
  95. .endif
  96. pop.w r4
  97. pop.w r3
  98. pop.w r2
  99. pop.w r1 ; Should set all flags zero
  100. test_cc_clear
  101. test_h_gr16 1 r1
  102. test_h_gr16 2 r2
  103. test_h_gr16 3 r3
  104. test_h_gr16 4 r4
  105. pop.w r4
  106. pop.w r3
  107. pop.w r2
  108. pop.w r1 ; a5a5 is negative
  109. test_neg_set
  110. test_carry_clear
  111. test_zero_clear
  112. test_ovf_clear
  113. test_gr_a5a5 0
  114. test_gr_a5a5 1
  115. test_gr_a5a5 2
  116. test_gr_a5a5 3
  117. test_gr_a5a5 4
  118. test_gr_a5a5 5
  119. test_gr_a5a5 6
  120. .if (sim_cpu == h8300)
  121. ;;; test_h_gr16 stacktop r7 ; FIXME
  122. .else
  123. test_h_gr32 stacktop er7
  124. .endif
  125. .if (sim_cpu) ; non-zero means not h8300
  126. push_l:
  127. set_grs_a5a5 ; Fill all general regs with a fixed pattern
  128. set_ccr_zero
  129. mov.l #stacktop, er7
  130. push.l er0 ; a5a5 is negative
  131. test_neg_set
  132. test_carry_clear
  133. test_zero_clear
  134. test_ovf_clear
  135. push.l er1
  136. push.l er2
  137. push.l er3
  138. test_gr_a5a5 0
  139. test_gr_a5a5 1
  140. test_gr_a5a5 2
  141. test_gr_a5a5 3
  142. mov @stacktop-4, er0
  143. test_gr_a5a5 0
  144. mov @stacktop-8, er0
  145. test_gr_a5a5 0
  146. mov @stacktop-12, er0
  147. test_gr_a5a5 0
  148. mov @stacktop-16, er0
  149. test_gr_a5a5 0
  150. mov #1, er1
  151. mov #2, er2
  152. mov #3, er3
  153. mov #4, er4
  154. push.l er1 ; #1 is non-negative, non-zero
  155. test_cc_clear
  156. push.l er2
  157. push.l er3
  158. push.l er4
  159. test_h_gr32 1 er1
  160. test_h_gr32 2 er2
  161. test_h_gr32 3 er3
  162. test_h_gr32 4 er4
  163. mov @stacktop-20, er0
  164. test_h_gr32 1 er0
  165. mov @stacktop-24, er0
  166. test_h_gr32 2 er0
  167. mov @stacktop-28, er0
  168. test_h_gr32 3 er0
  169. mov @stacktop-32, er0
  170. test_h_gr32 4 er0
  171. test_h_gr32 4 er0
  172. test_h_gr32 1 er1
  173. test_h_gr32 2 er2
  174. test_h_gr32 3 er3
  175. test_h_gr32 4 er4
  176. test_gr_a5a5 5
  177. test_gr_a5a5 6
  178. test_h_gr32 stacktop-32 er7
  179. pop_l:
  180. set_grs_a5a5 ; Fill all general regs with a fixed pattern
  181. set_ccr_zero
  182. mov.l #stacktop-32, er7
  183. pop.l er4
  184. pop.l er3
  185. pop.l er2
  186. pop.l er1 ; Should set all flags zero
  187. test_cc_clear
  188. test_h_gr32 1 er1
  189. test_h_gr32 2 er2
  190. test_h_gr32 3 er3
  191. test_h_gr32 4 er4
  192. pop.l er4
  193. pop.l er3
  194. pop.l er2
  195. pop.l er1 ; a5a5 is negative
  196. test_neg_set
  197. test_carry_clear
  198. test_zero_clear
  199. test_ovf_clear
  200. test_gr_a5a5 0
  201. test_gr_a5a5 1
  202. test_gr_a5a5 2
  203. test_gr_a5a5 3
  204. test_gr_a5a5 4
  205. test_gr_a5a5 5
  206. test_gr_a5a5 6
  207. test_h_gr32 stacktop er7
  208. .endif
  209. ;; Jump over subroutine
  210. jmp _bsr
  211. bsr_jsr_func:
  212. test_ccr 0 ; call should not affect ccr
  213. mov.w #0, r0
  214. mov.w #1, r1
  215. mov.w #2, r2
  216. mov.w #3, r3
  217. mov.w #4, r4
  218. mov.w #5, r5
  219. mov.w #6, r6
  220. rts
  221. _bsr: set_grs_a5a5
  222. .if (sim_cpu == h8300)
  223. mov.w #stacktop, r7
  224. .else
  225. mov.l #stacktop, er7
  226. .endif
  227. set_ccr_zero
  228. bsr bsr_jsr_func
  229. test_h_gr16 0 r0
  230. test_h_gr16 1 r1
  231. test_h_gr16 2 r2
  232. test_h_gr16 3 r3
  233. test_h_gr16 4 r4
  234. test_h_gr16 5 r5
  235. test_h_gr16 6 r6
  236. .if (sim_cpu == h8300)
  237. ;;; test_h_gr16 stacktop, r7 ; FIXME
  238. .else
  239. test_h_gr32 stacktop, er7
  240. .endif
  241. _jsr: set_grs_a5a5
  242. .if (sim_cpu == h8300)
  243. mov.w #stacktop, r7
  244. .else
  245. mov.l #stacktop, er7
  246. .endif
  247. set_ccr_zero
  248. jsr bsr_jsr_func
  249. test_h_gr16 0 r0
  250. test_h_gr16 1 r1
  251. test_h_gr16 2 r2
  252. test_h_gr16 3 r3
  253. test_h_gr16 4 r4
  254. test_h_gr16 5 r5
  255. test_h_gr16 6 r6
  256. .if (sim_cpu == h8300)
  257. ;;; test_h_gr16 stacktop, r7 ; FIXME
  258. .else
  259. test_h_gr32 stacktop, er7
  260. .endif
  261. .if (sim_cpu) ; not zero ie. not h8300
  262. _trapa:
  263. set_grs_a5a5
  264. mov.l #trap_handler, er7 ; trap vector
  265. mov.l er7, @0x2c
  266. mov.l #stacktop, er7
  267. set_ccr_zero
  268. trapa #3
  269. test_cc_clear ; ccr should be restored by rte
  270. test_h_gr16 0x10 r0
  271. test_h_gr16 0x11 r1
  272. test_h_gr16 0x12 r2
  273. test_h_gr16 0x13 r3
  274. test_h_gr16 0x14 r4
  275. test_h_gr16 0x15 r5
  276. test_h_gr16 0x16 r6
  277. test_h_gr32 stacktop er7
  278. .endif
  279. .if (sim_cpu == h8sx)
  280. _rtsl: ; Test rts/l insn.
  281. set_grs_a5a5
  282. mov #0,r0l
  283. mov #1,r1l
  284. mov #2,r2l
  285. mov #3,r3l
  286. mov #4,r4l
  287. mov #5,r5l
  288. mov #6,r6l
  289. mov #stacktop, er7
  290. jsr rtsl1_func
  291. test_h_gr32 0xa5a5a500 er0
  292. test_h_gr32 0xa5a5a501 er1
  293. test_h_gr32 0xa5a5a502 er2
  294. test_h_gr32 0xa5a5a503 er3
  295. test_h_gr32 0xa5a5a504 er4
  296. test_h_gr32 0xa5a5a505 er5
  297. test_h_gr32 0xa5a5a506 er6
  298. test_h_gr32 stacktop er7
  299. jsr rtsl2_func
  300. test_h_gr32 0xa5a5a500 er0
  301. test_h_gr32 0xa5a5a501 er1
  302. test_h_gr32 0xa5a5a502 er2
  303. test_h_gr32 0xa5a5a503 er3
  304. test_h_gr32 0xa5a5a504 er4
  305. test_h_gr32 0xa5a5a505 er5
  306. test_h_gr32 0xa5a5a506 er6
  307. test_h_gr32 stacktop er7
  308. jsr rtsl3_func
  309. test_h_gr32 0xa5a5a500 er0
  310. test_h_gr32 0xa5a5a501 er1
  311. test_h_gr32 0xa5a5a502 er2
  312. test_h_gr32 0xa5a5a503 er3
  313. test_h_gr32 0xa5a5a504 er4
  314. test_h_gr32 0xa5a5a505 er5
  315. test_h_gr32 0xa5a5a506 er6
  316. test_h_gr32 stacktop er7
  317. jsr rtsl4_func
  318. test_h_gr32 0xa5a5a500 er0
  319. test_h_gr32 0xa5a5a501 er1
  320. test_h_gr32 0xa5a5a502 er2
  321. test_h_gr32 0xa5a5a503 er3
  322. test_h_gr32 0xa5a5a504 er4
  323. test_h_gr32 0xa5a5a505 er5
  324. test_h_gr32 0xa5a5a506 er6
  325. test_h_gr32 stacktop er7
  326. .endif ; h8sx
  327. pass
  328. exit 0
  329. ;; Handler for a software exception (trap).
  330. trap_handler:
  331. ;; Test the 'i' interrupt mask flag.
  332. stc ccr, r0l
  333. test_h_gr8 0x80, r0l
  334. ;; Change the registers (so we know we've been here)
  335. mov.w #0x10, r0
  336. mov.w #0x11, r1
  337. mov.w #0x12, r2
  338. mov.w #0x13, r3
  339. mov.w #0x14, r4
  340. mov.w #0x15, r5
  341. mov.w #0x16, r6
  342. ;; Change the ccr (which will be restored by RTE)
  343. orc #0xff, ccr
  344. rte
  345. .if (sim_cpu == h8sx)
  346. ;; Functions for testing rts/l
  347. rtsl1_func: ; Save and restore R0
  348. push.l er0
  349. ;; Now modify it, and verify the modification.
  350. mov #0xfeedface, er0
  351. test_h_gr32 0xfeedface, er0
  352. ;; Then use rts/l to restore them and return.
  353. rts/l er0
  354. rtsl2_func: ; Save and restore R5 and R6
  355. push.l er5
  356. push.l er6
  357. ;; Now modify them, and verify the modification.
  358. mov #0xdeadbeef, er5
  359. mov #0xfeedface, er6
  360. test_h_gr32 0xdeadbeef, er5
  361. test_h_gr32 0xfeedface, er6
  362. ;; Then use rts/l to restore them and return.
  363. rts/l (er5-er6)
  364. rtsl3_func: ; Save and restore R4, R5, and R6
  365. push.l er4
  366. push.l er5
  367. push.l er6
  368. ;; Now modify them, and verify the modification.
  369. mov #0xdeafcafe, er4
  370. mov #0xdeadbeef, er5
  371. mov #0xfeedface, er6
  372. test_h_gr32 0xdeafcafe, er4
  373. test_h_gr32 0xdeadbeef, er5
  374. test_h_gr32 0xfeedface, er6
  375. ;; Then use rts/l to restore them and return.
  376. rts/l (er4-er6)
  377. rtsl4_func: ; Save and restore R0 - R3
  378. push.l er0
  379. push.l er1
  380. push.l er2
  381. push.l er3
  382. ;; Now modify them, and verify the modification.
  383. mov #0xdadacafe, er0
  384. mov #0xfeedbeef, er1
  385. mov #0xdeadface, er2
  386. mov #0xf00dd00d, er3
  387. test_h_gr32 0xdadacafe, er0
  388. test_h_gr32 0xfeedbeef, er1
  389. test_h_gr32 0xdeadface, er2
  390. test_h_gr32 0xf00dd00d, er3
  391. ;; Then use rts/l to restore them and return.
  392. rts/l (er0-er3)
  393. .endif ; h8sx