| 1 | /* Copyright (c) 2011 Red Hat Incorporated. | 
|---|
| 2 |    All rights reserved. | 
|---|
| 3 |  | 
|---|
| 4 |    Redistribution and use in source and binary forms, with or without | 
|---|
| 5 |    modification, are permitted provided that the following conditions | 
|---|
| 6 |    are met:  | 
|---|
| 7 |  | 
|---|
| 8 |      Redistributions of source code must retain the above copyright  | 
|---|
| 9 |      notice, this list of conditions and the following disclaimer. | 
|---|
| 10 |  | 
|---|
| 11 |      Redistributions in binary form must reproduce the above copyright | 
|---|
| 12 |      notice, this list of conditions and the following disclaimer in the | 
|---|
| 13 |      documentation and/or other materials provided with the distribution. | 
|---|
| 14 |  | 
|---|
| 15 |      The name of Red Hat Incorporated may not be used to endorse  | 
|---|
| 16 |      or promote products derived from this software without specific  | 
|---|
| 17 |      prior written permission. | 
|---|
| 18 |  | 
|---|
| 19 |    This software is provided by the copyright holders and contributors | 
|---|
| 20 |    "AS IS" and any express or implied warranties, including, but not | 
|---|
| 21 |    limited to, the implied warranties of merchantability and fitness for | 
|---|
| 22 |    a particular purpose are disclaimed.  In no event shall Red Hat | 
|---|
| 23 |    incorporated be liable for any direct, indirect, incidental, special, | 
|---|
| 24 |    exemplary, or consequential damages (including, but not limited to, | 
|---|
| 25 |    procurement of substitute goods or services; loss of use, data, or | 
|---|
| 26 |    profits; or business interruption) however caused and on any theory of | 
|---|
| 27 |    liability, whether in contract, strict liability, or tort (including | 
|---|
| 28 |    negligence or otherwise) arising in any way out of the use of this | 
|---|
| 29 |    software, even if advised of the possibility of such damage.  */ | 
|---|
| 30 |  | 
|---|
| 31 | #include "rl78-sys.h" | 
|---|
| 32 |  | 
|---|
| 33 |         .section ".vec","a" | 
|---|
| 34 |         .short  _start | 
|---|
| 35 |  | 
|---|
| 36 |         .section ".ivec","a" | 
|---|
| 37 |         .macro  _iv     x | 
|---|
| 38 |         .weak   \x | 
|---|
| 39 |         .short  \x | 
|---|
| 40 |         .endm | 
|---|
| 41 | #define IV(x) _iv _##x##_handler | 
|---|
| 42 | #define IVx() .short 0 | 
|---|
| 43 |  | 
|---|
| 44 |         /* To use a vector, simply define a global function named foo_handler() | 
|---|
| 45 |            for any IV(foo) listed below (i.e. tm05_handler) */ | 
|---|
| 46 |  | 
|---|
| 47 |         .global _interrupt_vector_table | 
|---|
| 48 | _interrupt_vector_table: | 
|---|
| 49 |         IV(wdti) | 
|---|
| 50 |         IV(lvi) | 
|---|
| 51 |         IV(p0) | 
|---|
| 52 |         IV(p1) | 
|---|
| 53 |         IV(p2) | 
|---|
| 54 |         IV(p3) | 
|---|
| 55 |         IV(p4) | 
|---|
| 56 |         IV(p5) | 
|---|
| 57 |  | 
|---|
| 58 |         IV(st2) | 
|---|
| 59 |         IV(sr2) | 
|---|
| 60 |         IV(sre2) | 
|---|
| 61 |         IV(dma0) | 
|---|
| 62 |         IV(dma1) | 
|---|
| 63 |         IV(st0) | 
|---|
| 64 |         IV(sr0) | 
|---|
| 65 |         IV(tm01h) | 
|---|
| 66 |  | 
|---|
| 67 |         IV(st1) | 
|---|
| 68 |         IV(sr1) | 
|---|
| 69 |         IV(sre1) | 
|---|
| 70 |         IV(iica0) | 
|---|
| 71 |         IV(tm00) | 
|---|
| 72 |         IV(tm01) | 
|---|
| 73 |         IV(tm02) | 
|---|
| 74 |         IV(tm03) | 
|---|
| 75 |  | 
|---|
| 76 |         IV(ad) | 
|---|
| 77 |         IV(rtc) | 
|---|
| 78 |         IV(it) | 
|---|
| 79 |         IV(kr) | 
|---|
| 80 |         IV(st3) | 
|---|
| 81 |         IV(sr3) | 
|---|
| 82 |         IV(tm13) | 
|---|
| 83 |         IV(tm04) | 
|---|
| 84 |  | 
|---|
| 85 |         IV(tm05) | 
|---|
| 86 |         IV(tm06) | 
|---|
| 87 |         IV(tm07) | 
|---|
| 88 |         IV(p6) | 
|---|
| 89 |         IV(p7) | 
|---|
| 90 |         IV(p8) | 
|---|
| 91 |         IV(p9) | 
|---|
| 92 |         IV(p10) | 
|---|
| 93 |  | 
|---|
| 94 |         IV(p11) | 
|---|
| 95 |         IV(tm10) | 
|---|
| 96 |         IV(tm12) | 
|---|
| 97 |         IV(sre3) | 
|---|
| 98 |         IV(tm13h) | 
|---|
| 99 |         IV(md) | 
|---|
| 100 |         IV(iica1) | 
|---|
| 101 |         IV(fl) | 
|---|
| 102 |  | 
|---|
| 103 |         IV(dma2) | 
|---|
| 104 |         IV(dma3) | 
|---|
| 105 |         IV(tm14) | 
|---|
| 106 |         IV(tm15) | 
|---|
| 107 |         IV(tm16) | 
|---|
| 108 |         IV(tm17) | 
|---|
| 109 |         IVx() | 
|---|
| 110 |         IVx() | 
|---|
| 111 |  | 
|---|
| 112 |         IVx() | 
|---|
| 113 |         IVx() | 
|---|
| 114 |         IVx() | 
|---|
| 115 |         IVx() | 
|---|
| 116 |         IVx() | 
|---|
| 117 |         IV(brk) | 
|---|
| 118 |         /* Note: 126 vectors */ | 
|---|
| 119 |  | 
|---|
| 120 |         .section ".csstart", "ax" | 
|---|
| 121 |         .global __csstart | 
|---|
| 122 | __csstart:       | 
|---|
| 123 |         br      !!_start | 
|---|
| 124 |  | 
|---|
| 125 |         .weak   __rl78_option_byte_0 | 
|---|
| 126 |         .weak   __rl78_option_byte_1 | 
|---|
| 127 |         .weak   __rl78_option_byte_2 | 
|---|
| 128 |         .weak   __rl78_option_byte_3 | 
|---|
| 129 | __rl78_option_byte_0 = 0x6e | 
|---|
| 130 | __rl78_option_byte_1 = 0xff | 
|---|
| 131 | __rl78_option_byte_2 = 0xe8 | 
|---|
| 132 | __rl78_option_byte_3 = 0x85 | 
|---|
| 133 |  | 
|---|
| 134 |         .section ".opt", "a" | 
|---|
| 135 |         .byte   __rl78_option_byte_0 | 
|---|
| 136 |         .byte   __rl78_option_byte_1 | 
|---|
| 137 |         .byte   __rl78_option_byte_2 | 
|---|
| 138 |         .byte   __rl78_option_byte_3 | 
|---|
| 139 |  | 
|---|
| 140 |         .text | 
|---|
| 141 |  | 
|---|
| 142 |         .global _start | 
|---|
| 143 |         .type   _start, @function | 
|---|
| 144 | _start: | 
|---|
| 145 |         movw    sp, #__stack | 
|---|
| 146 |  | 
|---|
| 147 |  | 
|---|
| 148 | ;; block move to initialize .data | 
|---|
| 149 |  | 
|---|
| 150 |         mov     es, #0 | 
|---|
| 151 |         movw    bc, #__romdatacopysize | 
|---|
| 152 | 1:       | 
|---|
| 153 |         movw    ax, bc | 
|---|
| 154 |         cmpw    ax, #0 | 
|---|
| 155 |         bz      $1f | 
|---|
| 156 |         decw    bc | 
|---|
| 157 |         decw    bc | 
|---|
| 158 |         movw    ax, es:__romdatastart[bc] | 
|---|
| 159 |         movw    __datastart[bc], ax | 
|---|
| 160 |         br      $1b | 
|---|
| 161 | 1:       | 
|---|
| 162 |          | 
|---|
| 163 |         mov     es, #0 | 
|---|
| 164 |         movw    bc, #__romsaddrcopysize | 
|---|
| 165 | 1:       | 
|---|
| 166 |         movw    ax, bc | 
|---|
| 167 |         cmpw    ax, #0 | 
|---|
| 168 |         bz      $1f | 
|---|
| 169 |         decw    bc | 
|---|
| 170 |         decw    bc | 
|---|
| 171 |         movw    ax, es:__romsaddrstart[bc] | 
|---|
| 172 |         movw    __saddrstart[bc], ax | 
|---|
| 173 |         br      $1b | 
|---|
| 174 | 1:       | 
|---|
| 175 |  | 
|---|
| 176 |  | 
|---|
| 177 | ;; block fill to .bss | 
|---|
| 178 |  | 
|---|
| 179 |         movw    bc, #__bsssize | 
|---|
| 180 |         movw    ax, #0 | 
|---|
| 181 |         cmpw    ax, bc | 
|---|
| 182 |         bz      $_bss_zero_done | 
|---|
| 183 | 1: | 
|---|
| 184 |         decw    bc | 
|---|
| 185 |         decw    bc | 
|---|
| 186 |         movw    __bssstart[bc], ax | 
|---|
| 187 |         cmpw    ax, bc | 
|---|
| 188 |         bnz      $1b | 
|---|
| 189 |  | 
|---|
| 190 | _bss_zero_done: | 
|---|
| 191 |  | 
|---|
| 192 |         call    !!__rl78_init | 
|---|
| 193 |  | 
|---|
| 194 | #ifdef PROFILE_SUPPORT  /* Defined in gcrt0.S.  */ | 
|---|
| 195 |         movw    ax, # _start | 
|---|
| 196 |         push    ax | 
|---|
| 197 |         movw    ax, # _etext | 
|---|
| 198 |         push    ax | 
|---|
| 199 |         call    !!__monstartup | 
|---|
| 200 | #endif | 
|---|
| 201 |  | 
|---|
| 202 |         movw    ax, #0 | 
|---|
| 203 |         push    ax      /* envp */ | 
|---|
| 204 |         push    ax      /* argv */ | 
|---|
| 205 |         push    ax      /* argc */ | 
|---|
| 206 |         call    !!_main | 
|---|
| 207 | .LFE2: | 
|---|
| 208 |          | 
|---|
| 209 |         movw    ax, r8       ; Save return code. | 
|---|
| 210 |         push    ax | 
|---|
| 211 |  | 
|---|
| 212 | #ifdef PROFILE_SUPPORT | 
|---|
| 213 |         call    !!__mcleanup | 
|---|
| 214 | #endif | 
|---|
| 215 |  | 
|---|
| 216 |         call    !!_exit | 
|---|
| 217 |  | 
|---|
| 218 |         .size   _start, . - _start | 
|---|
| 219 |  | 
|---|
| 220 |         .global _rl78_run_preinit_array | 
|---|
| 221 |         .type   _rl78_run_preinit_array,@function | 
|---|
| 222 | _rl78_run_preinit_array: | 
|---|
| 223 |         movw    hl, #__preinit_array_start | 
|---|
| 224 |         movw    de, #__preinit_array_end | 
|---|
| 225 |         movw    bc, #-2 | 
|---|
| 226 |         br      $_rl78_run_inilist | 
|---|
| 227 |  | 
|---|
| 228 |         .global _rl78_run_init_array | 
|---|
| 229 |         .type   _rl78_run_init_array,@function | 
|---|
| 230 | _rl78_run_init_array: | 
|---|
| 231 |         movw    hl, #__init_array_start | 
|---|
| 232 |         movw    de, #__init_array_end | 
|---|
| 233 |         movw    bc, #2 | 
|---|
| 234 |         br      $_rl78_run_inilist | 
|---|
| 235 |  | 
|---|
| 236 |         .global _rl78_run_fini_array | 
|---|
| 237 |         .type   _rl78_run_fini_array,@function | 
|---|
| 238 | _rl78_run_fini_array: | 
|---|
| 239 |         movw    hl, #__fini_array_start | 
|---|
| 240 |         movw    de, #__fini_array_end | 
|---|
| 241 |         movw    bc, #-2 | 
|---|
| 242 |         /* fall through */ | 
|---|
| 243 |  | 
|---|
| 244 |         ;; HL = start of list | 
|---|
| 245 |         ;; DE = end of list | 
|---|
| 246 |         ;; BC = step direction (+2 or -2) | 
|---|
| 247 | _rl78_run_inilist: | 
|---|
| 248 | next_inilist: | 
|---|
| 249 |         movw    ax, hl | 
|---|
| 250 |         cmpw    ax, de | 
|---|
| 251 |         bz      $done_inilist | 
|---|
| 252 |         movw    ax, [hl] | 
|---|
| 253 |         cmpw    ax, #-1 | 
|---|
| 254 |         bz      $skip_inilist | 
|---|
| 255 |         cmpw    ax, #0 | 
|---|
| 256 |         bz      $skip_inilist | 
|---|
| 257 |         push    ax | 
|---|
| 258 |         push    bc | 
|---|
| 259 |         push    de | 
|---|
| 260 |         push    hl | 
|---|
| 261 |         call    ax | 
|---|
| 262 |         pop     hl | 
|---|
| 263 |         pop     de | 
|---|
| 264 |         pop     bc | 
|---|
| 265 |         pop     ax | 
|---|
| 266 | skip_inilist: | 
|---|
| 267 |         movw    ax, hl | 
|---|
| 268 |         addw    ax, bc | 
|---|
| 269 |         movw    hl, ax | 
|---|
| 270 |         br      $next_inilist | 
|---|
| 271 | done_inilist: | 
|---|
| 272 |         ret | 
|---|
| 273 |  | 
|---|
| 274 |         .section        .init,"ax" | 
|---|
| 275 |  | 
|---|
| 276 |         .global __rl78_init | 
|---|
| 277 | __rl78_init: | 
|---|
| 278 |  | 
|---|
| 279 |         .section        .fini,"ax" | 
|---|
| 280 |  | 
|---|
| 281 |         .global __rl78_fini | 
|---|
| 282 | __rl78_fini: | 
|---|
| 283 |         call    !!_rl78_run_fini_array | 
|---|
| 284 |  | 
|---|
| 285 |         .section .data | 
|---|
| 286 |         .global ___dso_handle | 
|---|
| 287 |         .weak   ___dso_handle | 
|---|
| 288 | ___dso_handle: | 
|---|
| 289 |         .long   0 | 
|---|
| 290 |  | 
|---|
| 291 | ;;; Provide Dwarf unwinding information that will help GDB stop | 
|---|
| 292 | ;;; backtraces at the right place.  This is stolen from assembly | 
|---|
| 293 | ;;; code generated by GCC with -dA. | 
|---|
| 294 |         .section        .debug_frame,"",@progbits | 
|---|
| 295 | .Lframe0: | 
|---|
| 296 |         .4byte  .LECIE0-.LSCIE0 ; Length of Common Information Entry | 
|---|
| 297 | .LSCIE0: | 
|---|
| 298 |         .4byte  0xffffffff      ; CIE Identifier Tag | 
|---|
| 299 |         .byte   0x1     ; CIE Version | 
|---|
| 300 |         .ascii "\0"     ; CIE Augmentation | 
|---|
| 301 |         .uleb128 0x1    ; CIE Code Alignment Factor | 
|---|
| 302 |         .sleb128 -1     ; CIE Data Alignment Factor | 
|---|
| 303 |         .byte   0xd     ; CIE RA Column | 
|---|
| 304 |         .byte   0xc     ; DW_CFA_def_cfa | 
|---|
| 305 |         .uleb128 0xc | 
|---|
| 306 |         .uleb128 0x3 | 
|---|
| 307 |         .byte   0x8d    ; DW_CFA_offset, column 0xd | 
|---|
| 308 |         .uleb128 0x3 | 
|---|
| 309 |         .p2align 2 | 
|---|
| 310 | .LECIE0: | 
|---|
| 311 | .LSFDE0: | 
|---|
| 312 |         .4byte  .LEFDE0-.LASFDE0        ; FDE Length | 
|---|
| 313 | .LASFDE0: | 
|---|
| 314 |         .4byte  .Lframe0        ; FDE CIE offset | 
|---|
| 315 |         .4byte  _start          ; FDE initial location | 
|---|
| 316 |         .4byte  .LFE2 - _start  ; FDE address range | 
|---|
| 317 |         .byte   0xf             ; DW_CFA_def_cfa_expression | 
|---|
| 318 |         .uleb128 1              ; length of expression | 
|---|
| 319 |         .byte   0x30            ; DW_OP_lit0 | 
|---|
| 320 |         .p2align 2 | 
|---|
| 321 | .LEFDE0: | 
|---|
| 322 |  | 
|---|
| 323 |         .text | 
|---|