summaryrefslogtreecommitdiff
path: root/utils/hwstub/stub/atj213x/crt0.S
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2014-09-23 13:30:17 +0200
committerMarcin Bukat <marcin.bukat@gmail.com>2014-11-05 08:18:59 +0100
commitd11704fed5fd218b2ed26182de877bc6e5b513a4 (patch)
tree0eceaf96f006e9047b698ea99bf452faa79884d3 /utils/hwstub/stub/atj213x/crt0.S
parent791be56cff14a7a41774ce80ce401384291985d9 (diff)
downloadrockbox-d11704fed5fd218b2ed26182de877bc6e5b513a4.tar.gz
rockbox-d11704fed5fd218b2ed26182de877bc6e5b513a4.zip
hwstub: Add atj213x supportbootloader_zenxfi3_v1
Change-Id: Ic32200f9ab2c6977e503307a9cbe43a1328d0341
Diffstat (limited to 'utils/hwstub/stub/atj213x/crt0.S')
-rw-r--r--utils/hwstub/stub/atj213x/crt0.S206
1 files changed, 206 insertions, 0 deletions
diff --git a/utils/hwstub/stub/atj213x/crt0.S b/utils/hwstub/stub/atj213x/crt0.S
new file mode 100644
index 0000000000..16dd2ced8b
--- /dev/null
+++ b/utils/hwstub/stub/atj213x/crt0.S
@@ -0,0 +1,206 @@
1#include "mips.h"
2
3 .extern main
4 .global start
5
6 .set mips32r2
7 .set noreorder
8
9 .section .init.text,"ax",%progbits
10
11start:
12 di # disable interrupts
13 bltzal zero, load_addr # ra = PC + 8, branch not taken
14 nop
15
16load_addr:
17 addiu v0, ra, -12 # calc real load address
18 # account for branch delay slot
19 # and very first 'di' instruction
20
21 la t0, 0x80000000 # an idx op should use an unmappable address
22 ori t1, t0, 0x4000 # 16kB cache
23 mtc0 zero, C0_TAGLO
24 mtc0 zero, C0_TAGHI
25
26cache_init_loop:
27 cache ICIndexStTag, 0(t0) # index store icache tag
28 cache DCIndexStTag, 0(t0) # index store dcache tag
29 bne t0, t1, cache_init_loop
30 addiu t0, t0, 0x10
31
32 li t0, 3 # enable cache for kseg0 accesses
33 mtc0 t0, C0_CONFIG
34 ehb
35
36 la t0, relocstart
37 la t1, relocend
38 beq t0, v0, entry_point # no relocation needed
39 nop
40
41reloc_loop:
42 lw s0, 0(v0) # src
43 lw s1, 4(v0)
44 lw s2, 8(v0)
45 lw s3, 12(v0)
46
47 sw s0, 0(t0) # dst
48 sw s1, 4(t0)
49 sw s2, 8(t0)
50 sw s3, 12(t0)
51
52 synci 0(t0) # dcache writeback invalidate
53 # icache invalidate
54
55 addiu t0, t0, 16 # inc dst addr
56 blt t0, t1, reloc_loop
57 addiu v0, v0, 16 # inc src addr
58
59entry_point_jump:
60 la t0, entry_point
61 jr.hb t0
62 nop
63
64entry_point:
65intc_setup:
66 li t0, 0xb0020000 # INTC base
67 lw zero, 4(t0) # INTC_MSK mask all interrupt sources
68
69core_irq_setup:
70 li t0, 0x00404000 # BEV=1 for C0_EBASE setup, IM6=1, IE=0
71 mtc0 t0, C0_STATUS
72
73 la t0, _irqbase # vectors base address must be 4k aligned
74 mtc0 t0, C0_EBASE
75
76 li t0, 0x00004000
77 mtc0 t0, C0_STATUS # BEV=0, IM6=1, IE=0
78
79 li t1, 0x08800000
80 mtc0 t1, C0_CAUSE # DC=1, IV=1
81 mtc0 zero,C0_INTCTL # VS = 0
82
83 # clear bss
84 la t0, bssbegin
85 la t1, bssend
86 beq t0, t1, stack_setup
87 nop
88
89clear_bss_loop:
90 sw zero, 0(t0)
91 bne t0, t1, clear_bss_loop
92 addiu t0, 4
93
94stack_setup:
95 # setup stack
96 la k0, irqstackend
97 la sp, stackend
98 la t0, stackbegin
99 li t1, 0xdeadbeef
100
101stack_munge_loop:
102 sw t1, 0(t0)
103 bne t0, sp, stack_munge_loop
104 addiu t0, 4
105
106 # jump to C code with enabled interrupts
107 la t0, main
108 jr.hb t0
109 ei
110
111 .set at
112 .set reorder
113
114/* s0-s7 not saved as this are callee saved registers
115 * CO_STATUS is not saved as nested interrupts are not supported
116 *
117 * Separate irqstack is used for context save and irq processing
118 * k0 holds the address of the top of this stack and k1 is used
119 * to hold original sp value. Since we do not support nesting
120 * there is nothing to worry about
121 */
122 .extern INT_UDC
123
124 .global irq_handler
125 .set mips32r2
126 .set noreorder
127 .set noat
128 .section .irq_vector,"ax",%progbits
129
130irq_handler:
131 move k1, sp
132 move sp, k0
133 addiu sp, sp, -84
134
135 /* context save */
136 sw AT, 0(sp)
137 sw v0, 4(sp)
138 sw v1, 8(sp)
139 sw a0, 12(sp)
140 sw a1, 16(sp)
141 sw a2, 20(sp)
142 sw a3, 24(sp)
143 sw t0, 28(sp)
144 sw t1, 32(sp)
145 sw t2, 36(sp)
146 sw t3, 40(sp)
147 sw t4, 44(sp)
148 sw t5, 48(sp)
149 sw t6, 52(sp)
150 sw t7, 56(sp)
151 sw t8, 60(sp)
152 sw t9, 64(sp)
153 sw fp, 68(sp)
154 sw ra, 72(sp)
155
156 mfhi t0
157 mflo t1
158 sw t0, 76(sp)
159 sw t1, 80(sp)
160
161 /* handle interrupt */
162 lui t0, 0xb002 /* INTC base */
163 lw a0, 0(t0) /* INTC_PD */
164 lw a1, 4(t0) /* INTC_MSK */
165 and a0, a0, a1 /* mask */
166 andi a0, a0, 0x10 /* UDC flag */
167 beq a0, zero, restore
168 nop
169 /* irq dispatch */
170 la a0, INT_UDC
171 jalr a0
172 nop
173
174restore:
175 /* context restore */
176 lw t0, 76(sp)
177 lw t1, 80(sp)
178 mthi t0
179 mtlo t1
180 lw AT, 0(sp)
181 lw v0, 4(sp)
182 lw v1, 8(sp)
183 lw a0, 12(sp)
184 lw a1, 16(sp)
185 lw a2, 20(sp)
186 lw a3, 24(sp)
187 lw t0, 28(sp)
188 lw t1, 32(sp)
189 lw t2, 36(sp)
190 lw t3, 40(sp)
191 lw t4, 44(sp)
192 lw t5, 48(sp)
193 lw t6, 52(sp)
194 lw t7, 56(sp)
195 lw t8, 60(sp)
196 lw t9, 64(sp)
197 lw fp, 68(sp)
198 lw ra, 72(sp)
199
200 addiu sp, sp, 84
201 move sp, k1
202 eret
203
204 .set reorder
205 .set at
206