Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / arch / sparc32 / vectors.S
1 /*
2  * <vectors.S>
3  *
4  * Sparc V9 Trap Table(s) with SpitFire/Cheetah extensions.
5  *
6  *   Copyright (C) 1996, 2001 David S. Miller (davem@caip.rutgers.edu)
7  *
8  *   This program is free software; you can redistribute it and/or
9  *   modify it under the terms of the GNU General Public License
10  *   version 2 as published by the Free Software Foundation.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, write to the Free Software
19  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  *   MA  02110-1301, USA.
21  *   This program is free software; you can redistribute it and/or
22  *   modify it under the terms of the GNU General Public License V2
23  *   as published by the Free Software Foundation
24  */
25
26 #define __ASSEMBLY
27 #include "psr.h"
28 #include "asm/asi.h"
29 #define SER_ADDR5  0x71100004
30 #define SER_ADDR10 0xf1100004
31
32         .section ".text.vectors", "ax"
33         .align 4 /* Should be 16384, but alignment is handled by the ldscript */
34 /* Sparc32 trap table */
35         .globl trap_table, t_zero, t_wovf, t_wunf, __divide_error
36 trap_table:
37
38 #define WINDOW_SPILL \
39         rd %psr, %l0; rd %wim, %l3; b spill_window_entry; nop;
40
41 #define WINDOW_FILL \
42         rd %psr, %l0; rd %wim, %l3; b fill_window_entry; nop;
43
44 #define TRAP_DFAULT(lvl) \
45         rd %psr, %l0; rd %wim, %l3; b handle_dfault; mov lvl, %l7;
46
47 #define BTRAP(lvl) ba bug; mov lvl, %g1; nop; nop;
48 #define BTRAPS(x) BTRAP(x) BTRAP(x+1) BTRAP(x+2) BTRAP(x+3) BTRAP(x+4) BTRAP(x+5) BTRAP(x+6) BTRAP(x+7)
49 #define TRAP_ENTRY_INTERRUPT(int_level) \
50         sethi %hi(irq_entry ## int_level), %l7; \
51         or %l7, %lo(irq_entry ## int_level), %l7; \
52         jmp %l7; \
53          nop
54
55 t_zero:         b entry; nop; nop; nop;
56                 BTRAP(0x1) BTRAP(0x2) BTRAP(0x3) BTRAP(0x4)
57 t_wovf:         WINDOW_SPILL                        /* Window Overflow               */
58 t_wunf:         WINDOW_FILL                         /* Window Underflow              */
59                 BTRAP(0x7)
60                 BTRAP(0x8)
61                 TRAP_DFAULT(0x9)
62                 BTRAP(0xa) BTRAP(0xb) BTRAP(0xc) BTRAP(0xd) BTRAP(0xe) BTRAP(0xf)
63 #if 0
64                 BAD_TRAP(0x10)
65 t_irq1:         TRAP_ENTRY_INTERRUPT(1)             /* IRQ Software/SBUS Level 1     */
66 t_irq2:         TRAP_ENTRY_INTERRUPT(2)             /* IRQ SBUS Level 2              */
67 t_irq3:         TRAP_ENTRY_INTERRUPT(3)             /* IRQ SCSI/DMA/SBUS Level 3     */
68 t_irq4:         TRAP_ENTRY_INTERRUPT(4)             /* IRQ Software Level 4          */
69 t_irq5:         TRAP_ENTRY_INTERRUPT(5)             /* IRQ SBUS/Ethernet Level 5     */
70 t_irq6:         TRAP_ENTRY_INTERRUPT(6)             /* IRQ Software Level 6          */
71 t_irq7:         TRAP_ENTRY_INTERRUPT(7)             /* IRQ Video/SBUS Level 5        */
72 t_irq8:         TRAP_ENTRY_INTERRUPT(8)             /* IRQ SBUS Level 6              */
73 t_irq9:         TRAP_ENTRY_INTERRUPT(9)             /* IRQ SBUS Level 7              */
74 t_irq10:        TRAP_ENTRY_INTERRUPT(10)            /* IRQ Timer #1 (one we use)     */
75 t_irq11:        TRAP_ENTRY_INTERRUPT(11)            /* IRQ Floppy Intr.              */
76 t_irq12:        TRAP_ENTRY_INTERRUPT(12)            /* IRQ Zilog serial chip         */
77 t_irq13:        TRAP_ENTRY_INTERRUPT(13)            /* IRQ Audio Intr.               */
78 t_irq14:        TRAP_ENTRY_INTERRUPT(14)            /* IRQ Timer #2                  */
79 t_nmi:          BAD_TRAP(0x1f)                      /* Level 15 (NMI)                */
80 #else
81                 BTRAPS(0x10)
82                 BTRAP(0x18) BTRAP(0x19)
83 t_irq10:        TRAP_ENTRY_INTERRUPT(10)            /* IRQ Timer #1 (one we use)     */
84                 BTRAP(0x1b) BTRAP(0x1c) BTRAP(0x1d)
85 t_irq14:        TRAP_ENTRY_INTERRUPT(14)            /* IRQ Timer #2                  */
86                 BTRAP(0x1f)
87 #endif
88                 BTRAPS(0x20)
89                 BTRAP(0x28)
90                 TRAP_DFAULT(0x29)
91                 BTRAP(0x2a) BTRAP(0x2b) BTRAP(0x2c) BTRAP(0x2d) BTRAP(0x2e) BTRAP(0x2f)
92                 BTRAPS(0x30) BTRAPS(0x38)
93                 BTRAPS(0x40) BTRAPS(0x48)
94                 BTRAPS(0x50) BTRAPS(0x58)
95                 BTRAPS(0x60) BTRAPS(0x68)
96                 BTRAPS(0x70) BTRAPS(0x78)
97                 BTRAPS(0x80) BTRAPS(0x88)
98                 BTRAPS(0x90) BTRAPS(0x98)
99                 BTRAPS(0xa0) BTRAPS(0xa8)
100                 BTRAPS(0xb0) BTRAPS(0xb8)
101                 BTRAPS(0xc0) BTRAPS(0xc8)
102                 BTRAPS(0xd0) BTRAPS(0xd8)
103                 BTRAPS(0xe0) BTRAPS(0xe8)
104                 BTRAPS(0xf0) BTRAPS(0xf8)
105
106         .section ".text", "ax"
107         .align 4
108 __divide_error:
109 bug:
110         /* Dump the exception and its context */
111         ! Set up CPU state
112         rd      %psr, %g2
113         andn    %g2, PSR_ET, %g2
114         wr      %g2, %psr
115         ! Disable mmu, re-enable boot mode
116         set     _start, %g3
117         set     dump_exception, %g2
118         sub     %g2, %g3, %g3
119         set     3 << 13, %g2
120         jmp    %g3
121          sta    %g2, [%g0] ASI_M_MMUREGS
122
123 outstr:
124         /* void outstr (unsigned long port5, unsigned long port10,
125          * const unsigned char *str);
126          * Writes a string on an IO port.
127          */
128 1:      lduba    [%o2] ASI_M_KERNELTXT, %o3
129         cmp     %o3, 0
130         be      2f
131          nop
132         stba    %o3, [%o0] ASI_M_BYPASS
133         stba    %o3, [%o1] ASI_M_CTL
134         b       1b
135          inc    %o2
136 2:      retl
137          nop
138
139 outhex:
140         /* void outhex (unsigned long port5, unsigned long port10,
141          * uint32_t value);
142          * Dumps a 32 bits hex number on serial port
143          */
144         mov     %o2, %o4
145         set     28, %o3
146         srl     %o4, %o3, %o2
147 1:      and     %o2, 0xf, %o2
148         cmp     %o2, 9
149         bgt     2f
150          nop
151         b       3f
152          add    %o2, '0', %o2
153 2:      add     %o2, 'a' - 10, %o2
154 3:      stba    %o2, [%o0] ASI_M_BYPASS
155         stba    %o2, [%o1] ASI_M_CTL
156         subcc   %o3, 4, %o3
157         bge     1b
158          srl    %o4, %o3, %o2
159         retl
160          nop
161
162         /* void dump_exception ();
163          *
164          * Dump a message when catching an exception
165          */
166 dump_exception:
167         set     SER_ADDR5 + 2, %o0
168         set     SER_ADDR10 + 2, %o1
169         set     (_BUG_message_0), %o2
170         call    outstr
171          nop
172
173         call    outhex
174          mov    %g1, %o2
175
176         set     (_BUG_message_1), %o2
177         call    outstr
178          nop
179
180         call    outhex
181          mov    %l1, %o2
182
183         set     (_BUG_message_2), %o2
184         call    outstr
185          nop
186
187         call    outhex
188          mov    %l2, %o2
189
190         set     (_BUG_message_3), %o2
191         call    outstr
192          nop
193 _forever:
194         /* Loop forever */
195         b       _forever                                  ;
196          nop
197
198 irq_entry10:
199         sethi   %hi(counter_regs), %l7
200         ld      [%l7 + %lo(counter_regs)], %l7
201         sethi   0x10000, %l6
202         ld      [%l7 + %l6], %g0
203         jmp     %l1
204          rett   %l2
205
206 irq_entry14:
207         sethi   %hi(counter_regs), %l7
208         ld      [%l7 + %lo(counter_regs)], %l7
209         ld      [%l7], %g0
210         sethi   %hi(obp_ticks), %l7
211         ld      [%l7 + %lo(obp_ticks)], %l7
212         ld      [%l7], %l6
213         add     %l6, 10, %l6
214         st      %l6, [%l7]
215         jmp     %l1
216          rett  %l2
217
218 /* Register window handlers */
219 #include "wof.S"
220 #include "wuf.S"
221
222 /* Data fault handler */
223         .data
224         .align  4
225         .global ignore_dfault
226
227 ignore_dfault:
228         .word   0
229
230         .text
231         .align  4
232
233 handle_dfault:
234         /* If ignore_dfault is 0, fall through to normal exception handler */
235         sethi   %hi(ignore_dfault), %l4
236         ld      [%l4 + %lo(ignore_dfault)], %l4
237         tst     %l4
238         bz,a    bug
239          mov    %l7, %g1
240
241         /* Otherwise skip the faulting instruction and return */
242         jmp     %l2
243          rett   %l2 + 4
244
245
246         .section .rodata
247 _BUG_message_0:
248         .string "Unhandled Exception 0x"
249 _BUG_message_1:
250         .string "\r\nPC = 0x"
251 _BUG_message_2:
252         .string " NPC = 0x"
253 _BUG_message_3:
254         .string "\r\nStopping execution\r\n"