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