1 | /* |
---|
2 | * start.S -- startup file for Cogent CSB350 Au1100 based board |
---|
3 | * |
---|
4 | * Copyright (c) 2005 by Cogent Computer Systems |
---|
5 | * Written by Jay Monkman <jtm@lopingdog.com> |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | #include <rtems/asm.h> |
---|
14 | #include <bsp/regs.h> |
---|
15 | |
---|
16 | .text |
---|
17 | .align 2 |
---|
18 | |
---|
19 | /* Without the following nop, GDB thinks _start is a data variable. |
---|
20 | * This is probably a bug in GDB in handling a symbol that is at the |
---|
21 | * start of the .text section. |
---|
22 | */ |
---|
23 | nop |
---|
24 | |
---|
25 | .globl _start |
---|
26 | .ent _start |
---|
27 | _start: |
---|
28 | .set noreorder |
---|
29 | |
---|
30 | /* Get the address of start into $5 in a position independent |
---|
31 | * fashion. This lets us know whether we have been relocated or not. |
---|
32 | */ |
---|
33 | $LF1 = . + 8 |
---|
34 | bal $LF1 |
---|
35 | nop |
---|
36 | _branch: |
---|
37 | move $5, $31 /* $5 == where are we */ |
---|
38 | li $6, 0x8800000c /* $6 == where we want to be */ |
---|
39 | |
---|
40 | li v0, SR_CU1|SR_PE|SR_FR|SR_KX|SR_SX|SR_UX |
---|
41 | mtc0 v0, C0_SR |
---|
42 | mtc0 zero, C0_CAUSE |
---|
43 | |
---|
44 | 1: |
---|
45 | li v0, SR_PE|SR_FR|SR_KX|SR_SX|SR_UX |
---|
46 | mtc0 v0, C0_SR |
---|
47 | 2: |
---|
48 | /* Fix high bits, if any, of the PC so that exception handling |
---|
49 | doesn't get confused. */ |
---|
50 | la v0, 3f |
---|
51 | jr v0 |
---|
52 | nop |
---|
53 | 3: |
---|
54 | la gp, _gp /* set the global data pointer */ |
---|
55 | .end _start |
---|
56 | |
---|
57 | /* |
---|
58 | * zero out the bss section. |
---|
59 | */ |
---|
60 | .globl __memsize |
---|
61 | .globl zerobss |
---|
62 | .ent zerobss |
---|
63 | zerobss: |
---|
64 | la v0, _fbss |
---|
65 | la v1, _end |
---|
66 | 3: |
---|
67 | sw zero,0(v0) |
---|
68 | bltu v0,v1,3b |
---|
69 | addiu v0,v0,4 /* executed in delay slot */ |
---|
70 | |
---|
71 | la t0, _stack_init /* initialize stack so we */ |
---|
72 | /* We must subtract 24 bytes for the 3 8 byte arguments to main, in |
---|
73 | case main wants to write them back to the stack. The caller is |
---|
74 | supposed to allocate stack space for parameters in registers in |
---|
75 | the old MIPS ABIs. We must do this even though we aren't passing |
---|
76 | arguments, because main might be declared to have them. |
---|
77 | |
---|
78 | Some ports need a larger alignment for the stack, so we subtract |
---|
79 | 32, which satisifes the stack for the arguments and keeps the |
---|
80 | stack pointer better aligned. */ |
---|
81 | subu t0,t0,32 |
---|
82 | move sp,t0 /* set stack pointer */ |
---|
83 | .end zerobss |
---|
84 | |
---|
85 | .globl exit .text |
---|
86 | .globl init |
---|
87 | .ent init |
---|
88 | init: |
---|
89 | |
---|
90 | move a0,zero /* set command line to 0 */ |
---|
91 | jal boot_card /* call the program start function */ |
---|
92 | nop |
---|
93 | |
---|
94 | /* fall through to the "exit" routine */ |
---|
95 | jal _sys_exit /* call libc exit to run the G++ */ |
---|
96 | /* destructors */ |
---|
97 | move a0,v0 /* pass through the exit code */ |
---|
98 | .end init |
---|
99 | |
---|
100 | /* |
---|
101 | * _sys_exit -- Exit from the application. Normally we cause a user trap |
---|
102 | * to return to the ROM monitor for another run. NOTE: This is |
---|
103 | * the only other routine we provide in the crt0.o object, since |
---|
104 | * it may be tied to the "_start" routine. It also allows |
---|
105 | * executables that contain a complete world to be linked with |
---|
106 | * just the crt0.o object. |
---|
107 | */ |
---|
108 | .globl _sys_exit |
---|
109 | .ent _sys_exit |
---|
110 | _sys_exit: |
---|
111 | 7: |
---|
112 | #ifdef GCRT0 |
---|
113 | jal _mcleanup |
---|
114 | nop |
---|
115 | #endif |
---|
116 | /* break inst. can cope with 0xfffff, but GAS limits the range: */ |
---|
117 | break 1023 |
---|
118 | nop |
---|
119 | b 7b /* but loop back just in-case */ |
---|
120 | nop |
---|
121 | .end _sys_exit |
---|
122 | |
---|
123 | /* EOF crt0.S */ |
---|