[8ef3818] | 1 | /* start.S |
---|
| 2 | * |
---|
| 3 | * This file contains the entry veneer for RTEMS programs |
---|
| 4 | * on the MBX8xx board. |
---|
| 5 | * It jumps to the BSP which is responsible for performing |
---|
| 6 | * all remaining initialization. |
---|
| 7 | * |
---|
| 8 | * This file is based on several others: |
---|
[6128a4a] | 9 | * |
---|
| 10 | * (1) start360.s from the gen68360 BSP by |
---|
[8ef3818] | 11 | * W. Eric Norum (eric@skatter.usask.ca) |
---|
| 12 | * with the following copyright and license: |
---|
| 13 | * |
---|
| 14 | * COPYRIGHT (c) 1989-1998. |
---|
| 15 | * On-Line Applications Research Corporation (OAR). |
---|
[6128a4a] | 16 | * |
---|
[8ef3818] | 17 | * The license and distribution terms for this file may in |
---|
| 18 | * the file LICENSE in this distribution or at |
---|
[1e7cbc5] | 19 | * http://www.rtems.com/license/LICENSE. |
---|
[8ef3818] | 20 | * |
---|
| 21 | * (2) start.s for the eth_comm port by |
---|
| 22 | * Jay Monkman (jmonkman@fracsa.com), |
---|
[6128a4a] | 23 | * which itself is based on the |
---|
| 24 | * |
---|
[8ef3818] | 25 | * (3) dlentry.s for the Papyrus BSP, written by: |
---|
| 26 | * Andrew Bray <andy@i-cubed.co.uk> |
---|
| 27 | * with the following copyright and license: |
---|
| 28 | * |
---|
| 29 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
[6128a4a] | 30 | * |
---|
[8ef3818] | 31 | * (4) start860.S for the MBX821/MBX860, written by: |
---|
| 32 | * Darlene A. Stewart <darlene.stewart@iit.nrc.ca> |
---|
| 33 | * Copyright (c) 1999, National Research Council of Canada |
---|
| 34 | * |
---|
| 35 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 36 | * without any express or implied warranty: |
---|
| 37 | * permission to use, copy, modify, and distribute this file |
---|
| 38 | * for any purpose is hereby granted without fee, provided that |
---|
| 39 | * the above copyright notice and this notice appears in all |
---|
| 40 | * copies, and that the name of i-cubed limited not be used in |
---|
| 41 | * advertising or publicity pertaining to distribution of the |
---|
| 42 | * software without specific, written prior permission. |
---|
| 43 | * i-cubed limited makes no representations about the suitability |
---|
| 44 | * of this software for any purpose. |
---|
| 45 | * |
---|
| 46 | * Modifications (for MBX8xx) of respective RTEMS files: |
---|
| 47 | * Copyright (c) 1999, National Research Council of Canada |
---|
| 48 | */ |
---|
| 49 | |
---|
[56aecad] | 50 | #include <rtems/asm.h> |
---|
[8ef3818] | 51 | |
---|
| 52 | /* |
---|
| 53 | * The initial stack is set to run BELOW the code base address. |
---|
| 54 | * (between the vectors and text sections) |
---|
| 55 | * |
---|
| 56 | * All the entry veneer has to do is to clear the BSS. |
---|
| 57 | */ |
---|
| 58 | |
---|
| 59 | /* |
---|
| 60 | * GDB likes to have debugging information for the entry veneer. |
---|
| 61 | * Play compiler and provide some DWARF information. |
---|
| 62 | * |
---|
| 63 | * CHANGE TO SUIT YOUR SETUP! |
---|
| 64 | */ |
---|
| 65 | |
---|
| 66 | .section .entry,"ax",@progbits |
---|
| 67 | .L_text_b: |
---|
| 68 | .L_LC1: |
---|
| 69 | .previous |
---|
| 70 | |
---|
| 71 | .section .debug_sfnames |
---|
| 72 | .L_sfnames_b: |
---|
| 73 | .byte "rtems/c/src/lib/libbsp/powerpc/mbx8xx/startup/" |
---|
| 74 | .byte 0 |
---|
| 75 | .L_F0: |
---|
| 76 | .byte "start.S" |
---|
| 77 | .byte 0 |
---|
| 78 | .previous |
---|
| 79 | |
---|
| 80 | .section .line |
---|
| 81 | .L_line_b: |
---|
| 82 | .4byte .L_line_e-.L_line_b |
---|
| 83 | .4byte .L_text_b |
---|
| 84 | .L_LE1: |
---|
| 85 | .L_line_last: |
---|
| 86 | .4byte 0x0 |
---|
| 87 | .2byte 0xffff |
---|
| 88 | .4byte .L_text_e-.L_text_b |
---|
| 89 | .L_line_e: |
---|
| 90 | .previous |
---|
| 91 | |
---|
| 92 | .section .debug_srcinfo |
---|
| 93 | .L_srcinfo_b: |
---|
| 94 | .4byte .L_line_b |
---|
| 95 | .4byte .L_sfnames_b |
---|
| 96 | .4byte .L_text_b |
---|
| 97 | .4byte .L_text_e |
---|
| 98 | .4byte 0xffffffff |
---|
| 99 | .4byte .L_LE1-.L_line_b |
---|
| 100 | .4byte .L_F0-.L_sfnames_b |
---|
| 101 | .4byte .L_line_last-.L_line_b |
---|
| 102 | .4byte 0xffffffff |
---|
| 103 | .previous |
---|
| 104 | |
---|
| 105 | .section .debug_pubnames |
---|
| 106 | .4byte .L_debug_b |
---|
| 107 | .4byte .L_P0 |
---|
| 108 | .byte "start" |
---|
| 109 | .byte 0 |
---|
| 110 | .4byte 0x0 |
---|
| 111 | .byte 0 |
---|
| 112 | .previous |
---|
| 113 | |
---|
| 114 | .section .debug_aranges |
---|
| 115 | .4byte .L_debug_b |
---|
| 116 | .4byte .L_text_b |
---|
| 117 | .4byte .L_text_e-.L_text_b |
---|
| 118 | .4byte 0 |
---|
| 119 | .4byte 0 |
---|
| 120 | .4byte 0 |
---|
| 121 | .4byte 0 |
---|
| 122 | .4byte 0 |
---|
| 123 | .4byte 0 |
---|
| 124 | .4byte 0x0 |
---|
| 125 | .4byte 0x0 |
---|
| 126 | .previous |
---|
| 127 | |
---|
| 128 | .section .debug |
---|
| 129 | .L_debug_b: |
---|
| 130 | .L_D1: |
---|
| 131 | .4byte .L_D1_e-.L_D1 |
---|
| 132 | .2byte 0x11 /* TAG_compile_unit */ |
---|
| 133 | .2byte 0x12 /* AT_sibling */ |
---|
| 134 | .4byte .L_D2 |
---|
| 135 | .2byte 0x38 /* AT_name */ |
---|
| 136 | .byte "start.S" |
---|
| 137 | .byte 0 |
---|
| 138 | .2byte 0x258 /* AT_producer */ |
---|
| 139 | .byte "GAS 2.5.2" |
---|
| 140 | .byte 0 |
---|
| 141 | .2byte 0x111 /* AT_low_pc */ |
---|
| 142 | .4byte .L_text_b |
---|
| 143 | .2byte 0x121 /* AT_high_pc */ |
---|
| 144 | .4byte .L_text_e |
---|
| 145 | .2byte 0x106 /* AT_stmt_list */ |
---|
| 146 | .4byte .L_line_b |
---|
| 147 | .2byte 0x1b8 /* AT_comp_dir */ |
---|
| 148 | .byte "rtems/c/src/lib/libbsp/powerpc/mbx8xx/startup/" |
---|
| 149 | .byte 0 |
---|
| 150 | .2byte 0x8006 /* AT_sf_names */ |
---|
| 151 | .4byte .L_sfnames_b |
---|
| 152 | .2byte 0x8016 /* AT_src_info */ |
---|
| 153 | .4byte .L_srcinfo_b |
---|
| 154 | .L_D1_e: |
---|
| 155 | .L_P0: |
---|
| 156 | .L_D3: |
---|
| 157 | .4byte .L_D3_e-.L_D3 |
---|
| 158 | .2byte 0x6 /* TAG_global_subroutine */ |
---|
| 159 | .2byte 0x12 /* AT_sibling */ |
---|
| 160 | .4byte .L_D4 |
---|
| 161 | .2byte 0x38 /* AT_name */ |
---|
| 162 | .byte "start" |
---|
| 163 | .byte 0 |
---|
| 164 | .2byte 0x278 /* AT_prototyped */ |
---|
| 165 | .byte 0 |
---|
| 166 | .2byte 0x111 /* AT_low_pc */ |
---|
| 167 | .4byte .L_text_b |
---|
| 168 | .2byte 0x121 /* AT_high_pc */ |
---|
| 169 | .4byte .L_text_e |
---|
| 170 | .2byte 0x8041 /* AT_body_begin */ |
---|
| 171 | .4byte .L_text_b |
---|
| 172 | .2byte 0x8051 /* AT_body_end */ |
---|
| 173 | .4byte .L_text_e |
---|
| 174 | .L_D3_e: |
---|
| 175 | |
---|
| 176 | .L_D4: |
---|
| 177 | .4byte .L_D4_e-.L_D4 |
---|
| 178 | .align 2 |
---|
| 179 | .L_D4_e: |
---|
| 180 | .L_D2: |
---|
| 181 | .previous |
---|
[6128a4a] | 182 | |
---|
[8ef3818] | 183 | /* |
---|
| 184 | * Tell C's eabi-ctor's that we have an atexit function, |
---|
| 185 | * and that it is to register __do_global_dtors. |
---|
| 186 | */ |
---|
| 187 | EXTERN_PROC(atexit) |
---|
| 188 | PUBLIC_VAR(__atexit) |
---|
| 189 | .section ".sdata","aw" |
---|
| 190 | .align 2 |
---|
[6128a4a] | 191 | SYM(__atexit): |
---|
[8ef3818] | 192 | EXT_PROC_REF(atexit)@fixup |
---|
| 193 | .previous |
---|
| 194 | |
---|
| 195 | .section ".fixup","aw" |
---|
| 196 | .align 2 |
---|
| 197 | EXT_SYM_REF(__atexit) |
---|
| 198 | .previous |
---|
| 199 | |
---|
| 200 | /* That should do it */ |
---|
[6128a4a] | 201 | |
---|
[8ef3818] | 202 | /* |
---|
| 203 | * Put the entry point in its own section. That way, we can guarantee |
---|
| 204 | * to put it first in the .text section in the linker script. |
---|
| 205 | */ |
---|
| 206 | .section .entry |
---|
| 207 | |
---|
| 208 | PUBLIC_VAR (start) |
---|
| 209 | SYM(start): |
---|
| 210 | bl .startup /* or bl .spin */ |
---|
[6128a4a] | 211 | base_addr: |
---|
[8ef3818] | 212 | |
---|
| 213 | /* |
---|
| 214 | * Parameters from linker |
---|
| 215 | */ |
---|
[6128a4a] | 216 | toc_pointer: |
---|
[8ef3818] | 217 | .long __GOT_START__ |
---|
[6128a4a] | 218 | bss_length: |
---|
[8ef3818] | 219 | .long bss.size |
---|
[6128a4a] | 220 | bss_addr: |
---|
[8ef3818] | 221 | .long bss.start |
---|
| 222 | |
---|
| 223 | PUBLIC_VAR (text_addr) |
---|
| 224 | text_addr: |
---|
| 225 | .long text.start |
---|
| 226 | |
---|
| 227 | PUBLIC_VAR (text_length) |
---|
| 228 | text_length: |
---|
| 229 | .long text.size |
---|
| 230 | |
---|
| 231 | /* |
---|
| 232 | * Spin, if necessary, to acquire control from debugger (CodeWarrior). |
---|
[6128a4a] | 233 | */ |
---|
[8ef3818] | 234 | spin: |
---|
| 235 | .long 0x0001 |
---|
| 236 | .spin: |
---|
| 237 | lis r3, spin@ha |
---|
| 238 | lwz r3, spin@l(r3) |
---|
| 239 | cmpwi r3, 0x1 |
---|
| 240 | beq .spin |
---|
[848e900] | 241 | /* |
---|
| 242 | * test function: blink orange led once |
---|
| 243 | */ |
---|
[3495c57] | 244 | #define LEDBLINK_DELAY (5*1000*1000) |
---|
[848e900] | 245 | #define LEDPORT 0xFA100001 |
---|
| 246 | #define LEDMASK 0xf0 |
---|
| 247 | #define LEDON 0x00 |
---|
| 248 | #define LEDOFF 0x08 |
---|
[3495c57] | 249 | |
---|
[848e900] | 250 | PUBLIC_VAR(ledblink) |
---|
| 251 | SYM(ledblink): |
---|
| 252 | lis r3,LEDBLINK_DELAY>>16 |
---|
[3495c57] | 253 | ledblink1: |
---|
[848e900] | 254 | subi r3,r3,1 |
---|
| 255 | cmpi 0,1,r3,0 |
---|
| 256 | bne ledblink1 |
---|
| 257 | /* |
---|
| 258 | * turn orange led off |
---|
| 259 | */ |
---|
| 260 | lis r3,LEDPORT@ha |
---|
| 261 | lbz r0,LEDPORT@l(r3) |
---|
| 262 | andi. r0,r0,LEDMASK |
---|
| 263 | ori r0,r0,LEDOFF |
---|
| 264 | stb r0,LEDPORT@l(r3) |
---|
[3495c57] | 265 | |
---|
[848e900] | 266 | lis r3,LEDBLINK_DELAY>>16 |
---|
[3495c57] | 267 | ledblink2: |
---|
[848e900] | 268 | subi r3,r3,1 |
---|
| 269 | cmpi 0,1,r3,0 |
---|
| 270 | bne ledblink2 |
---|
| 271 | /* |
---|
| 272 | * turn orange led on |
---|
| 273 | */ |
---|
| 274 | lis r3,LEDPORT@ha |
---|
| 275 | lbz r0,LEDPORT@l(r3) |
---|
| 276 | andi. r0,r0,LEDMASK |
---|
| 277 | ori r0,r0,LEDON |
---|
| 278 | stb r0,LEDPORT@l(r3) |
---|
[3495c57] | 279 | |
---|
| 280 | blr |
---|
[6128a4a] | 281 | /* |
---|
[35bb69b] | 282 | * #define LOADED_BY_EPPCBUG |
---|
| 283 | */ |
---|
[0eef948f] | 284 | #define LOADED_BY_EPPCBUG |
---|
[6128a4a] | 285 | #define EARLY_CONSOLE |
---|
[8ef3818] | 286 | /* |
---|
[6128a4a] | 287 | * Initialization code |
---|
[8ef3818] | 288 | */ |
---|
[6128a4a] | 289 | .startup: |
---|
[8ef3818] | 290 | /* Get the start address. */ |
---|
| 291 | mflr r1 |
---|
[6128a4a] | 292 | #ifdef LOADED_BY_EPPCBUG |
---|
[35bb69b] | 293 | /* Save pointer to residual/board data */ |
---|
| 294 | lis r9,eppcbugInfo@ha |
---|
| 295 | stw r3,eppcbugInfo@l(r9) |
---|
[6128a4a] | 296 | #endif |
---|
[8ef3818] | 297 | /* Initialize essential registers. */ |
---|
| 298 | bl initregs |
---|
| 299 | nop |
---|
| 300 | |
---|
| 301 | /* |
---|
| 302 | * C_setup. |
---|
| 303 | */ |
---|
| 304 | |
---|
| 305 | /* set toc */ |
---|
| 306 | lwz r2, toc_pointer-base_addr(r1) |
---|
| 307 | |
---|
| 308 | /* Set up stack pointer = beginning of text section - 56 */ |
---|
| 309 | addi r1, r1, -56-4 |
---|
| 310 | |
---|
| 311 | /* Initialize the memory mapped MPC821 registers (done in C). */ |
---|
| 312 | EXTERN_PROC (_InitMBX8xx) |
---|
| 313 | bl PROC (_InitMBX8xx) |
---|
| 314 | nop |
---|
[6128a4a] | 315 | |
---|
[8ef3818] | 316 | /* Clear the bss section. */ |
---|
| 317 | bl bssclr |
---|
| 318 | nop |
---|
[0eef948f] | 319 | #if defined(EARLY_CONSOLE) && defined(LOADED_BY_EPPCBUG) |
---|
| 320 | EXTERN_PROC (serial_init) |
---|
| 321 | bl PROC (serial_init) |
---|
[6128a4a] | 322 | #endif |
---|
[35bb69b] | 323 | lis r5,environ@ha |
---|
| 324 | la r5,environ@l(r5) /* environp */ |
---|
[976b159] | 325 | /* clear argc command line */ |
---|
[8ef3818] | 326 | xor r3, r3, r3 |
---|
[6128a4a] | 327 | |
---|
[8ef3818] | 328 | EXTERN_PROC (boot_card) |
---|
| 329 | bl PROC (boot_card) /* call the first C routine */ |
---|
| 330 | nop |
---|
[6128a4a] | 331 | |
---|
[8ef3818] | 332 | /* we should never return from boot_card, but in case we do ... */ |
---|
| 333 | /* The next instructions are dependent on your runtime environment */ |
---|
| 334 | |
---|
| 335 | /* Return to EPPCBug */ |
---|
| 336 | lis r10, 0x0400 /* Data cache disable */ |
---|
| 337 | mtspr 568, r10 |
---|
| 338 | isync |
---|
[6128a4a] | 339 | |
---|
[8ef3818] | 340 | mtspr 560, r10 /* Instruction cache disable */ |
---|
| 341 | isync |
---|
[6128a4a] | 342 | |
---|
[8ef3818] | 343 | stop_here: |
---|
| 344 | li r10, 0x0F00 /* .RETURN */ |
---|
| 345 | sc |
---|
[6128a4a] | 346 | |
---|
[8ef3818] | 347 | b stop_here |
---|
| 348 | nop |
---|
| 349 | |
---|
| 350 | /* |
---|
| 351 | * bssclr - zero out bss |
---|
| 352 | */ |
---|
| 353 | bssclr: |
---|
| 354 | lis r3, base_addr@ha |
---|
| 355 | addi r3, r3, base_addr@l |
---|
| 356 | lwz r4, bss_addr-base_addr(r3) /* Start of bss */ |
---|
| 357 | lwz r5, bss_length-base_addr(r3) /* Length of bss */ |
---|
| 358 | |
---|
| 359 | rlwinm. r5,r5,30,0x3FFFFFFF /* form length/4 */ |
---|
| 360 | beqlr /* no bss - return */ |
---|
| 361 | mtctr r5 /* set ctr reg */ |
---|
[6128a4a] | 362 | |
---|
[8ef3818] | 363 | li r5,0x0000 /* r5 = 0 */ |
---|
| 364 | clear_bss: |
---|
| 365 | stw r5,0(r4) /* store r6 */ |
---|
| 366 | addi r4,r4,0x4 /* update r4 */ |
---|
| 367 | bdnz clear_bss /* dec counter and loop */ |
---|
[6128a4a] | 368 | |
---|
[8ef3818] | 369 | blr /* return */ |
---|
| 370 | |
---|
| 371 | /* |
---|
| 372 | * initregs |
---|
| 373 | * Initialize the MSR and basic core PowerPC registers |
---|
| 374 | * |
---|
| 375 | * Register usage: |
---|
| 376 | * r0 - scratch |
---|
| 377 | */ |
---|
| 378 | initregs: |
---|
[6128a4a] | 379 | /* |
---|
[8ef3818] | 380 | * Disable address translation. We should already be running in real space, |
---|
| 381 | * so this should be a no-op, i.e. no need to switch instruction stream |
---|
| 382 | * addresses from virtual space to real space. Other bits set the processor |
---|
| 383 | * for big-endian mode, exceptions vectored to 0x000n_nnnn (vectors are |
---|
| 384 | * already in low memory!), no execution tracing, machine check exceptions |
---|
[6128a4a] | 385 | * enabled, floating-point not available (MPC8xx has none), supervisor |
---|
[8ef3818] | 386 | * priviledge level, external interrupts disabled, power management |
---|
| 387 | * disabled (normal operation mode). |
---|
| 388 | */ |
---|
| 389 | li r0, 0x1000 /* MSR_ME */ |
---|
| 390 | mtmsr r0 /* Context-synchronizing */ |
---|
| 391 | isync |
---|
[6128a4a] | 392 | |
---|
[8ef3818] | 393 | /* |
---|
| 394 | * Clear the exception handling registers. |
---|
| 395 | * Note SPRG3 is reserved for use by EPPCBug on the MBX8xx. |
---|
[6128a4a] | 396 | */ |
---|
[8ef3818] | 397 | li r0, 0x0000 |
---|
| 398 | mtdar r0 |
---|
| 399 | mtspr sprg0, r0 |
---|
| 400 | mtspr sprg1, r0 |
---|
| 401 | mtspr sprg2, r0 |
---|
| 402 | mtspr srr0, r0 |
---|
| 403 | mtspr srr1, r0 |
---|
[6128a4a] | 404 | |
---|
[8ef3818] | 405 | mr r6, r0 |
---|
| 406 | mr r7, r0 |
---|
| 407 | mr r8, r0 |
---|
| 408 | mr r9, r0 |
---|
| 409 | mr r10, r0 |
---|
[6128a4a] | 410 | mr r11, r0 |
---|
[8ef3818] | 411 | mr r12, r0 |
---|
| 412 | mr r13, r0 |
---|
| 413 | mr r14, r0 |
---|
| 414 | mr r15, r0 |
---|
| 415 | mr r16, r0 |
---|
| 416 | mr r17, r0 |
---|
| 417 | mr r18, r0 |
---|
| 418 | mr r19, r0 |
---|
| 419 | mr r20, r0 |
---|
| 420 | mr r21, r0 |
---|
| 421 | mr r22, r0 |
---|
| 422 | mr r23, r0 |
---|
| 423 | mr r24, r0 |
---|
| 424 | mr r25, r0 |
---|
| 425 | mr r26, r0 |
---|
| 426 | mr r27, r0 |
---|
| 427 | mr r28, r0 |
---|
| 428 | mr r29, r0 |
---|
| 429 | mr r30, r0 |
---|
| 430 | mr r31, r0 |
---|
[6128a4a] | 431 | |
---|
[8ef3818] | 432 | blr /* return */ |
---|
[6128a4a] | 433 | |
---|
[8ef3818] | 434 | .L_text_e: |
---|