[444] | 1 | /* |
---|
| 2 | * Copyright (c) 2011 Aeroflex Gaisler |
---|
| 3 | * |
---|
| 4 | * BSD license: |
---|
| 5 | * |
---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 8 | * in the Software without restriction, including without limitation the rights |
---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 11 | * furnished to do so, subject to the following conditions: |
---|
| 12 | * |
---|
| 13 | * The above copyright notice and this permission notice shall be included in |
---|
| 14 | * all copies or substantial portions of the Software. |
---|
| 15 | * |
---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 22 | * THE SOFTWARE. |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | /* The traptable has to be the first code in a boot PROM. */ |
---|
| 27 | |
---|
| 28 | #include <asm-leon/head.h> |
---|
| 29 | |
---|
| 30 | #define TRAP(H) mov %psr, %l0; sethi %hi(H), %l4; jmp %l4+%lo(H); nop; |
---|
| 31 | #define TRAPL(H) mov %g0, %l0; sethi %hi(H), %l4; jmp %l4+%lo(H); nop; |
---|
| 32 | #define TRAP_ENTRY(H) rd %psr, %l0; b H; rd %wim, %l3; nop; |
---|
| 33 | |
---|
| 34 | #define WIM_INIT 2 |
---|
| 35 | #ifdef _SOFT_FLOAT |
---|
| 36 | #define PSR_INIT 0x0e0 |
---|
| 37 | #else |
---|
| 38 | #define PSR_INIT 0x10e0 |
---|
| 39 | #endif |
---|
| 40 | |
---|
| 41 | #define NUMREGWINDOWS 8 |
---|
| 42 | |
---|
| 43 | /* Unexcpected trap will halt the processor by forcing it to error state */ |
---|
| 44 | #define BAD_TRAP ta 0; nop; nop; nop; |
---|
| 45 | |
---|
| 46 | /* Software trap. Treat as BAD_TRAP */ |
---|
| 47 | #define SOFT_TRAP BAD_TRAP |
---|
| 48 | |
---|
| 49 | #define TT_MASK 0xff0 // trap type mask from tbr |
---|
| 50 | #define TT_SHL 4 // shift to get a tbr value |
---|
| 51 | |
---|
| 52 | .seg "text" |
---|
| 53 | |
---|
| 54 | /* ------- */ |
---|
| 55 | .weak _start_svt_weak |
---|
| 56 | .set _start_svt_weak,_start_svt_disp |
---|
| 57 | /* ------- */ |
---|
| 58 | |
---|
| 59 | .global _trap_table, cpuinit, _hardreset, _hardreset_svt |
---|
| 60 | .global _fpdis_enable_svt,_fpdis_svt,_window_overflow_svt,_window_underflow_svt |
---|
| 61 | .global _leonbare_irq_entry_svt,_irqcall_svt,_flush_windows_svt,_srmmu_fault_svt,_irqcall_disableirq_svt |
---|
| 62 | .global start, _start_svt_real |
---|
| 63 | |
---|
| 64 | _start_svt_real: |
---|
| 65 | nop |
---|
| 66 | |
---|
| 67 | _start_svt_disp: |
---|
| 68 | rd %tbr, %l3 |
---|
| 69 | rd %psr, %l0 |
---|
| 70 | ! here,locals have been set up as follows: |
---|
| 71 | ! %l0 = psr |
---|
| 72 | ! %l1 = pc |
---|
| 73 | ! %l2 = npc |
---|
| 74 | ! %l3 = tbr |
---|
| 75 | and %l3,TT_MASK,%l3 |
---|
| 76 | srl %l3,TT_SHL,%l3 |
---|
| 77 | |
---|
| 78 | /* |
---|
| 79 | struct get { |
---|
| 80 | int start,end,func; |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | struct get table[3] = { |
---|
| 84 | {0,1,..}, |
---|
| 85 | {0,0,0}, |
---|
| 86 | }; |
---|
| 87 | |
---|
| 88 | int gettrap(int nr){ |
---|
| 89 | struct get *p = table; |
---|
| 90 | while((p->start) || (p->end) || (p->func)) { |
---|
| 91 | if (p->start <= nr && p->end >= nr) { |
---|
| 92 | return p->func; |
---|
| 93 | } |
---|
| 94 | p++; |
---|
| 95 | } |
---|
| 96 | return 0; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | $sparc-elf-gcc -S gettrap.c -o test.S -O2 |
---|
| 100 | */ |
---|
| 101 | |
---|
| 102 | #define loc_o0 l3 |
---|
| 103 | #define loc_o1 l4 |
---|
| 104 | #define loc_o2 l5 |
---|
| 105 | #define loc_o3 l6 |
---|
| 106 | |
---|
| 107 | sethi %hi(trap_table), %loc_o2 |
---|
| 108 | or %loc_o2, %lo(trap_table), %loc_o2 |
---|
| 109 | mov %loc_o0, %loc_o3 |
---|
| 110 | ld [%loc_o2], %loc_o1 |
---|
| 111 | .LL13: |
---|
| 112 | cmp %loc_o1, %loc_o3 |
---|
| 113 | .LL12: |
---|
| 114 | bg,a .LL11 |
---|
| 115 | add %loc_o2, 12, %loc_o2 |
---|
| 116 | ld [%loc_o2+4], %loc_o0 |
---|
| 117 | cmp %loc_o0, %loc_o3 |
---|
| 118 | bge,a .LL1 |
---|
| 119 | ld [%loc_o2+8], %loc_o0 |
---|
| 120 | add %loc_o2, 12, %loc_o2 |
---|
| 121 | .LL11: |
---|
| 122 | ld [%loc_o2], %loc_o0 |
---|
| 123 | orcc %loc_o0, 0, %loc_o1 |
---|
| 124 | bne .LL12 |
---|
| 125 | cmp %loc_o1, %loc_o3 |
---|
| 126 | ld [%loc_o2+4], %loc_o0 |
---|
| 127 | cmp %loc_o0, 0 |
---|
| 128 | bne .LL12 |
---|
| 129 | cmp %loc_o1, %loc_o3 |
---|
| 130 | ld [%loc_o2+8], %loc_o0 |
---|
| 131 | cmp %loc_o0, 0 |
---|
| 132 | bne .LL12 |
---|
| 133 | cmp %loc_o1, %loc_o3 |
---|
| 134 | |
---|
| 135 | !not in table |
---|
| 136 | BAD_TRAP |
---|
| 137 | |
---|
| 138 | .LL1: |
---|
| 139 | jmp %loc_o0 |
---|
| 140 | nop |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | .global trap_table,svt_trap_table_ext,svt_trap_table_ext_end |
---|
| 144 | .section ".rodata" |
---|
| 145 | .align 4 |
---|
| 146 | trap_table: |
---|
| 147 | .long 0,0, _hardreset_svt |
---|
| 148 | .long 1,1, _srmmu_fault_svt ! 01 instruction_access_exception (in mmu_asm.S) |
---|
| 149 | .long 4,4 |
---|
| 150 | #ifndef _SOFT_FLOAT |
---|
| 151 | .long _fpdis_enable_svt ! 04 fp_disabled |
---|
| 152 | #else |
---|
| 153 | .long _fpdis_svt ! 04 fp_disabled |
---|
| 154 | #endif |
---|
| 155 | #ifndef _FLAT |
---|
| 156 | .long 5, 5, _window_overflow_svt ! 05 window_overflow |
---|
| 157 | .long 6, 6, _window_underflow_svt ! 06 window_underflow |
---|
| 158 | #endif |
---|
| 159 | .long 9,9, _srmmu_fault_svt ! 09 data_access_exception (in mmu_asm.S) |
---|
| 160 | .long 0x11,0x1f, _leonbare_irq_entry_svt ! 11-1f interrupt level |
---|
| 161 | .long 0x82,0x82, _irqcall_svt ! 82 |
---|
| 162 | #ifndef _FLAT |
---|
| 163 | .long 0x83,0x83, _flush_windows_svt ! 83 |
---|
| 164 | #endif |
---|
| 165 | .long 0x85,0x85, _irqcall_disableirq_svt ! 85 |
---|
| 166 | svt_trap_table_ext: |
---|
| 167 | .long 0,0,0 |
---|
| 168 | .long 0,0,0 |
---|
| 169 | .long 0,0,0 |
---|
| 170 | .long 0,0,0 |
---|
| 171 | .long 0,0,0 |
---|
| 172 | .long 0,0,0 |
---|
| 173 | .long 0,0,0 |
---|
| 174 | .long 0,0,0 |
---|
| 175 | .long 0,0,0 |
---|
| 176 | .long 0,0,0 |
---|
| 177 | .long 0,0,0 |
---|
| 178 | .long 0,0,0 |
---|
| 179 | .long 0,0,0 |
---|
| 180 | .long 0,0,0 |
---|
| 181 | .long 0,0,0 |
---|
| 182 | .long 0,0,0 |
---|
| 183 | .long 0,0,0 |
---|
| 184 | svt_trap_table_ext_end: |
---|
| 185 | .long 0,0,0 |
---|
| 186 | |
---|