crti-hw.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. .global _start
  2. _start:
  3. # START Interrupt Vector Table [[
  4. jmp __PMSIZE-4 # RESET Vector
  5. jmp interrupt_33 # Watchdog reset vector
  6. jmp interrupt_0
  7. jmp interrupt_1
  8. jmp interrupt_2
  9. jmp interrupt_3
  10. jmp interrupt_4
  11. jmp interrupt_5
  12. jmp interrupt_6
  13. jmp interrupt_7
  14. jmp interrupt_8
  15. jmp interrupt_9
  16. jmp interrupt_10
  17. jmp interrupt_11
  18. jmp interrupt_12
  19. jmp interrupt_13
  20. jmp interrupt_14
  21. jmp interrupt_15
  22. jmp interrupt_16
  23. jmp interrupt_17
  24. jmp interrupt_18
  25. jmp interrupt_19
  26. jmp interrupt_20
  27. jmp interrupt_21
  28. jmp interrupt_22
  29. jmp interrupt_23
  30. jmp interrupt_24
  31. jmp interrupt_25
  32. jmp interrupt_26
  33. jmp interrupt_27
  34. jmp interrupt_28
  35. jmp interrupt_29
  36. jmp interrupt_30
  37. jmp interrupt_31
  38. jmp __PMSIZE-8 # Interrupt vector 32 (NMI)
  39. # ]] END Interrupt Vector Table
  40. codestart:
  41. jmp init
  42. .global _exithook
  43. _exithook: # Debugger uses '_exithook' at 0x90 to catch program exit
  44. return
  45. init:
  46. ldk $sp,__RAMSIZE
  47. # Disable all interrupts
  48. lda $r1,0x10000
  49. lshr $r1,$r1,20
  50. cmp $r1,0x90
  51. ldk $r1,0x100e3 # FT900 IRQ Control Register
  52. jmpc z,1f
  53. ldk $r1,0x10123 # FT930 IRQ Control Register
  54. 1:
  55. ldk $r4,0x80
  56. sti.b $r1,0,$r4
  57. # Initialize DATA by copying from program memory
  58. ldk.l $r4,__data_load_start
  59. ldk.l $r1,__data_load_end
  60. ldk.l $r2,0 # Will use __data after binutils patch
  61. jmp .dscopy
  62. .dsloop:
  63. # Copy PM[$r4] to RAM $r2
  64. lpmi.l $r3,$r4,0
  65. sti.l $r2,0,$r3
  66. add.l $r4,$r4,4
  67. add.l $r2,$r2,4
  68. .dscopy:
  69. cmp.l $r4,$r1
  70. jmpc lt,.dsloop
  71. # Zero BSS
  72. ldk.l $r4,_bss_start
  73. ldk.l $r2,_end
  74. sub.l $r2,$r2,$r4
  75. ldk.l $r1,0
  76. ldk $r3,32764
  77. 1:
  78. cmp $r2,$r3
  79. jmpc lt,2f
  80. memset $r4,$r1,$r3
  81. add $r4,$r4,$r3
  82. sub $r2,$r2,$r3
  83. jmp 1b
  84. 2:
  85. memset $r4,$r1,$r2
  86. sub.l $sp,$sp,24 # Space for the caller argument frame
  87. call main
  88. .equ EXITEXIT,0x1fffc
  89. .global _exit
  90. _exit:
  91. sta.l EXITEXIT,$r0 # simulator end of test
  92. jmp _exithook
  93. # Macro to construct the interrupt stub code.
  94. # it just saves r0, loads r0 with the int vector
  95. # and branches to interrupt_common.
  96. .macro inth i=0
  97. interrupt_\i:
  98. push $r0 # {
  99. lda $r0,(vector_table + 4 * \i)
  100. jmp interrupt_common
  101. .endm
  102. inth 0
  103. inth 1
  104. inth 2
  105. inth 3
  106. inth 4
  107. inth 5
  108. inth 6
  109. inth 7
  110. inth 8
  111. inth 9
  112. inth 10
  113. inth 11
  114. inth 12
  115. inth 13
  116. inth 14
  117. inth 15
  118. inth 16
  119. inth 17
  120. inth 18
  121. inth 19
  122. inth 20
  123. inth 21
  124. inth 22
  125. inth 23
  126. inth 24
  127. inth 25
  128. inth 26
  129. inth 27
  130. inth 28
  131. inth 29
  132. inth 30
  133. inth 31
  134. inth 32
  135. inth 33
  136. # On entry: r0, already saved, holds the handler function
  137. interrupt_common:
  138. push $r1 # {
  139. push $r2 # {
  140. push $r3 # {
  141. push $r4 # {
  142. push $r5 # {
  143. push $r6 # {
  144. push $r7 # {
  145. push $r8 # {
  146. push $r9 # {
  147. push $r10 # {
  148. push $r11 # {
  149. push $r12 # {
  150. push $cc # {
  151. calli $r0
  152. pop $cc # }
  153. pop $r12 # }
  154. pop $r11 # }
  155. pop $r10 # }
  156. pop $r9 # }
  157. pop $r8 # }
  158. pop $r7 # }
  159. pop $r6 # }
  160. pop $r5 # }
  161. pop $r4 # }
  162. pop $r3 # }
  163. pop $r2 # }
  164. pop $r1 # }
  165. pop $r0 # } matching push in interrupt_0-31 above
  166. reti
  167. # Null function for unassigned interrupt to point at
  168. .global nullvector
  169. nullvector:
  170. return
  171. .section .data
  172. .global vector_table
  173. vector_table:
  174. .rept 34
  175. .long nullvector
  176. .endr
  177. .section .text
  178. .global __gxx_personality_sj0
  179. __gxx_personality_sj0: