Initial commit
[rpi-open-firmware.git] / start.s
1 /*=============================================================================
2 Copyright (C) 2016 Kristina Brooks
3 All rights reserved.
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 FILE DESCRIPTION
16 Entry.
17
18 A small explanation. The ROM loads bootcode.bin at 0x80000000 and jumps to
19 0x80000200. This region corresponds to L1/L2 cached IO and cache is never
20 evicted as long as we don't touch memory above that. This gives us 128KB
21 of memory at startup.
22
23 Exception names are from the public release from:
24 brcm_usrlib\dag\vmcsx\vcfw\rtos\none\rtos_none.c
25
26 =============================================================================*/
27
28
29 .text
30
31 empty_space:
32 .space 0x200
33
34 .include "ghetto.s"
35
36 /* main entry point */
37
38 .globl _start
39 .align 2
40 _start:
41 mov r0, cpuid
42 mov r5, r0
43
44 # get addr of the exception vector table
45 lea r1, __INTERRUPT_VECTORS
46 mov r3, r1
47
48 /*
49 * populate the exception vector table using PC relative labels
50 * so the code isnt position dependent
51 */
52 .macro RegExceptionHandler label, exception_number
53 lea r2, Exc_\label
54 st r2, (r1)
55 add r1, #4
56 .endm
57
58 RegExceptionHandler zero, #0
59 RegExceptionHandler misaligned, #1
60 RegExceptionHandler dividebyzero, #2
61 RegExceptionHandler undefinedinstruction, #3
62 RegExceptionHandler forbiddeninstruction, #4
63 RegExceptionHandler illegalmemory, #5
64 RegExceptionHandler buserror, #6
65 RegExceptionHandler floatingpoint, #7
66 RegExceptionHandler isp, #8
67 RegExceptionHandler dummy, #9
68 RegExceptionHandler icache, #10
69 RegExceptionHandler veccore, #11
70 RegExceptionHandler badl2alias, #12
71 RegExceptionHandler breakpoint, #13
72 RegExceptionHandler unknown, #14
73
74 /*
75 * load the interrupt and normal stack pointers. these
76 * are chosen to be near the top of the available cache memory
77 */
78
79 mov r28, #0x1D000
80 mov sp, #0x1C000
81
82 /* set interrupt vector bases */
83 mov r0, #IC0_VADDR
84 st r3, (r0)
85 mov r0, #IC1_VADDR
86 st r3, (r0)
87
88 /* jump to C code */
89 mov r0, r5
90 lea r1, _start
91
92 ei
93
94 bl _main
95
96 /************************************************************
97 * Debug
98 ************************************************************/
99
100 blinker:
101 mov r1, #GPFSEL1
102 ld r0, (r1)
103 and r0, #(~(7<<18))
104 or r0, #(1<<18)
105 st r0, (r1)
106 mov r1, #GPSET0
107 mov r2, #GPCLR0
108 mov r3, #(1<<16)
109 loop:
110 st r3, (r1)
111 mov r0, #0
112 delayloop1:
113 add r0, #1
114 cmp r0, #0x100000
115 bne delayloop1
116 st r3, (r2)
117 mov r0, #0
118 delayloop2:
119 add r0, #1
120 cmp r0, #0x100000
121 bne delayloop2
122 b loop
123
124 /************************************************************
125 * Exception Handling
126 ************************************************************/
127
128 _sleh_generic_gate:
129 # get faulting PC
130 ld r1, 4(sp)
131 # call the C exception handler
132 b sleh_fatal
133
134
135 .macro ExceptionHandler label, exception_number
136 Exc_\label:
137 mov r0, \exception_number
138 b _sleh_generic_gate
139 .endm
140
141 ExceptionHandler zero, #0
142 ExceptionHandler misaligned, #1
143 ExceptionHandler dividebyzero, #2
144 ExceptionHandler undefinedinstruction, #3
145 ExceptionHandler forbiddeninstruction, #4
146 ExceptionHandler illegalmemory, #5
147 ExceptionHandler buserror, #6
148 ExceptionHandler floatingpoint, #7
149 ExceptionHandler isp, #8
150 ExceptionHandler dummy, #9
151 ExceptionHandler icache, #10
152 ExceptionHandler veccore, #11
153 ExceptionHandler badl2alias, #12
154 ExceptionHandler breakpoint, #13
155 ExceptionHandler unknown, #14
156
157 /************************************************************
158 * ISRs
159 ************************************************************/
160
161 .align 4
162 __INTERRUPT_VECTORS:
163 # 31 slots, 4 byte each for processor exceptions. patched to have the correct
164 # exception handler routines at runtime to allow the code to be loaded anywhere
165 .space 124, 0
This page took 0.100733 seconds and 5 git commands to generate.