1 | /* |
---|
2 | * Copyright (c) 2014-2015 Hesham ALMatary <heshamelmatary@gmail.com> |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE |
---|
7 | */ |
---|
8 | #include <bsp/linker-symbols.h> |
---|
9 | |
---|
10 | /* The following macro defines the first instructions every exception |
---|
11 | * should execute before jumping to its handler function from the |
---|
12 | * exception vector table. r3 is saved into the stack and loaded with |
---|
13 | * vector number before jumping to _ISR_Handler. r3 value is restored |
---|
14 | * back from _ISR_Handler after handling the exception and before |
---|
15 | * returning from interrupt. |
---|
16 | */ |
---|
17 | #define EXCEPTION_SETUP(vector) \ |
---|
18 | l.nop ;\ |
---|
19 | l.addi r1, r1, -200 ;\ |
---|
20 | l.sw 0(r1), r3; \ |
---|
21 | l.addi r3, r0, vector; \ |
---|
22 | l.j _ISR_Handler; \ |
---|
23 | l.nop |
---|
24 | |
---|
25 | .extern boot_card |
---|
26 | .extern bsp_section_bss_begin |
---|
27 | .extern bsp_section_bss_end |
---|
28 | |
---|
29 | .extern bsp_start_vector_table_end |
---|
30 | .extern bsp_start_vector_table_size |
---|
31 | .extern bsp_vector_table_size |
---|
32 | .extern _ISR_Stack_area_end |
---|
33 | |
---|
34 | .extern exception_frame_save |
---|
35 | .extern _OR1K_Exception_Process |
---|
36 | .extern _OR1K_Exception_default |
---|
37 | .extern rtems_clock_tick |
---|
38 | .extern _exit |
---|
39 | .extern printk |
---|
40 | .extern bsp_interrupt_handler_default |
---|
41 | |
---|
42 | /* Global symbols */ |
---|
43 | .global _start |
---|
44 | .global bsp_start_vector_table_begin |
---|
45 | |
---|
46 | /* Popualte HW vector table */ |
---|
47 | |
---|
48 | .section .vector, "ax" |
---|
49 | |
---|
50 | .org 0x100 |
---|
51 | _reset: |
---|
52 | l.j _start |
---|
53 | l.nop |
---|
54 | |
---|
55 | .org 0x200 |
---|
56 | _buserr: |
---|
57 | EXCEPTION_SETUP(2) |
---|
58 | |
---|
59 | .org 0x300 |
---|
60 | _dPageFault: |
---|
61 | EXCEPTION_SETUP(3) |
---|
62 | |
---|
63 | .org 0x400 |
---|
64 | _iPageFaule: |
---|
65 | EXCEPTION_SETUP(4) |
---|
66 | |
---|
67 | .org 0x500 |
---|
68 | _timer: |
---|
69 | EXCEPTION_SETUP(5) |
---|
70 | |
---|
71 | .org 0x600 |
---|
72 | _unalign: |
---|
73 | EXCEPTION_SETUP(6) |
---|
74 | |
---|
75 | .org 0x700 |
---|
76 | _undefIns: |
---|
77 | EXCEPTION_SETUP(7) |
---|
78 | |
---|
79 | .org 0x800 |
---|
80 | _exInt: |
---|
81 | EXCEPTION_SETUP(8) |
---|
82 | |
---|
83 | .org 0x900 |
---|
84 | _dTLB: |
---|
85 | EXCEPTION_SETUP(9) |
---|
86 | |
---|
87 | .org 0xA00 |
---|
88 | _iTLB: |
---|
89 | EXCEPTION_SETUP(10) |
---|
90 | |
---|
91 | .org 0xB00 |
---|
92 | _range: |
---|
93 | EXCEPTION_SETUP(11) |
---|
94 | |
---|
95 | .org 0xC00 |
---|
96 | _syscall: |
---|
97 | EXCEPTION_SETUP(12) |
---|
98 | |
---|
99 | .org 0xD00 |
---|
100 | _fp: |
---|
101 | EXCEPTION_SETUP(13) |
---|
102 | |
---|
103 | .org 0xE00 |
---|
104 | _trap: |
---|
105 | EXCEPTION_SETUP(14) |
---|
106 | |
---|
107 | .org 0xF00 |
---|
108 | _undef1: |
---|
109 | EXCEPTION_SETUP(15) |
---|
110 | |
---|
111 | .org 0x1500 |
---|
112 | _undef2: |
---|
113 | EXCEPTION_SETUP(16) |
---|
114 | |
---|
115 | .org 0x1900 |
---|
116 | _undef3: |
---|
117 | EXCEPTION_SETUP(17) |
---|
118 | |
---|
119 | .org 0x1F00 |
---|
120 | |
---|
121 | bsp_start_vector_table_begin: |
---|
122 | |
---|
123 | .word 0 |
---|
124 | .word _start /* Reset */ |
---|
125 | .word _OR1K_Exception_default /* Bus Error */ |
---|
126 | .word _OR1K_Exception_default /* Data Page Fault */ |
---|
127 | .word _OR1K_Exception_default /* Instruction Page Fault */ |
---|
128 | .word _OR1K_Exception_default /* Tick timer */ |
---|
129 | .word _OR1K_Exception_default /* Alignment */ |
---|
130 | .word _OR1K_Exception_default /* Undefiend Instruction */ |
---|
131 | .word _OR1K_Exception_default /* External Interrupt */ |
---|
132 | .word _OR1K_Exception_default /* Data TLB Miss */ |
---|
133 | .word _OR1K_Exception_default /* Instruction TLB Miss */ |
---|
134 | .word _OR1K_Exception_default /* Range Exception */ |
---|
135 | .word _OR1K_Exception_default /* System Call */ |
---|
136 | .word _OR1K_Exception_default /* Floating Point Exception */ |
---|
137 | .word _OR1K_Exception_default /* Trap */ |
---|
138 | .word _OR1K_Exception_default /* Reserver for future use */ |
---|
139 | .word _OR1K_Exception_default /* Reserved for implementation-specific */ |
---|
140 | .word _OR1K_Exception_default /* Reserved for custom exceptions. */ |
---|
141 | |
---|
142 | bsp_start_vector_table_end: |
---|
143 | |
---|
144 | .section ".bsp_start_text", "ax" |
---|
145 | .type _start,@function |
---|
146 | |
---|
147 | _start: |
---|
148 | /* Set SR register to Supervision mode */ |
---|
149 | l.ori r1, r0, 0x1 |
---|
150 | l.mtspr r0, r1, 17 |
---|
151 | |
---|
152 | /* load stack and frame pointers */ |
---|
153 | l.movhi r1, hi(_ISR_Stack_area_end) |
---|
154 | l.ori r1, r1, lo(_ISR_Stack_area_end) |
---|
155 | l.add r2, r0, r1 |
---|
156 | |
---|
157 | /* Clearing .bss */ |
---|
158 | l.movhi r13, hi(bsp_section_bss_begin) |
---|
159 | l.ori r13, r13, lo(bsp_section_bss_begin) |
---|
160 | l.movhi r15, hi(bsp_section_bss_end) |
---|
161 | l.ori r15, r15, lo(bsp_section_bss_end) |
---|
162 | |
---|
163 | _loop_clear_bss: |
---|
164 | l.sfgeu r13, r15 |
---|
165 | l.bf _end_clear_bss |
---|
166 | l.addi r13, r13, 4 |
---|
167 | l.sw 0(r13), r0 |
---|
168 | l.j _loop_clear_bss |
---|
169 | l.nop |
---|
170 | _end_clear_bss: |
---|
171 | |
---|
172 | l.j boot_card |
---|
173 | l.nop |
---|
174 | |
---|
175 | /* Temporary code for unhandled exceptions */ |
---|
176 | .section .text |
---|
177 | .align |
---|
178 | .global _unhandled_exception |
---|
179 | |
---|
180 | unhandled_exception: |
---|
181 | l.nop |
---|