| 1 | /* | 
|---|
| 2 | * __kentry.S - unified kernel entry point | 
|---|
| 3 | * | 
|---|
| 4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless | 
|---|
| 5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites | 
|---|
| 6 | * | 
|---|
| 7 | * This file is part of ALMOS-kernel. | 
|---|
| 8 | * | 
|---|
| 9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it | 
|---|
| 10 | * under the terms of the GNU General Public License as published by | 
|---|
| 11 | * the Free Software Foundation; version 2.0 of the License. | 
|---|
| 12 | * | 
|---|
| 13 | * ALMOS-kernel is distributed in the hope that it will be useful, but | 
|---|
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 16 | * General Public License for more details. | 
|---|
| 17 | * | 
|---|
| 18 | * You should have received a copy of the GNU General Public License | 
|---|
| 19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, | 
|---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 
|---|
| 21 | */ | 
|---|
| 22 |  | 
|---|
| 23 | #define DECLARE_EXCEPT_ERR(n)     \ | 
|---|
| 24 | .align 16                       ; \ | 
|---|
| 25 | cli                     ; \ | 
|---|
| 26 | pushl   $##n            ; \ | 
|---|
| 27 | jmp     unified_except_entry ; \ | 
|---|
| 28 | movl    %eax,   %eax | 
|---|
| 29 |  | 
|---|
| 30 | #define DECLARE_EXCEPT(n)       \ | 
|---|
| 31 | .align 16                       ; \ | 
|---|
| 32 | cli                     ; \ | 
|---|
| 33 | pushl   $0x0            ; \ | 
|---|
| 34 | pushl   $##n            ; \ | 
|---|
| 35 | jmp     unified_except_entry | 
|---|
| 36 |  | 
|---|
| 37 | #define DECLARE_IRQ(n)          \ | 
|---|
| 38 | .align 16                       ; \ | 
|---|
| 39 | cli                     ; \ | 
|---|
| 40 | pushl   $0x0            ; \ | 
|---|
| 41 | pushl   $##n            ; \ | 
|---|
| 42 | jmp     unified_irq_entry | 
|---|
| 43 |  | 
|---|
| 44 | .text | 
|---|
| 45 | .global __except | 
|---|
| 46 | .align 16 | 
|---|
| 47 | __except: | 
|---|
| 48 | DECLARE_EXCEPT(0)               /* Division By Zero Exception   */ | 
|---|
| 49 | DECLARE_EXCEPT(1)               /* Debug Exception              */ | 
|---|
| 50 | DECLARE_EXCEPT(2)               /* Non Maskable Interrupt Exception */ | 
|---|
| 51 | DECLARE_EXCEPT(3)               /* Breakpoint Exception         */ | 
|---|
| 52 | DECLARE_EXCEPT(4)               /* Into Detected Overflow Exception */ | 
|---|
| 53 | DECLARE_EXCEPT(5)               /* Out of Bounds Exception */ | 
|---|
| 54 | DECLARE_EXCEPT(6)               /* Invalid Opcode Exception */ | 
|---|
| 55 | DECLARE_EXCEPT(7)               /* No Coprocessor Exception */ | 
|---|
| 56 | DECLARE_EXCEPT_ERR(8)           /* Double Fault Exception */ | 
|---|
| 57 | DECLARE_EXCEPT(9)               /* Coprocessor Segment Overrun Exception */ | 
|---|
| 58 | DECLARE_EXCEPT_ERR(10)          /* Bad TSS Exception */ | 
|---|
| 59 | DECLARE_EXCEPT_ERR(11)          /* Segment Not Present Exception */ | 
|---|
| 60 | DECLARE_EXCEPT_ERR(12)          /* Stack Fault Exception */ | 
|---|
| 61 | DECLARE_EXCEPT_ERR(13)          /* General Protection Fault Exception */ | 
|---|
| 62 | DECLARE_EXCEPT_ERR(14)          /* Page Fault Exception */ | 
|---|
| 63 | DECLARE_EXCEPT(15)              /* Unknown Interrupt Exception */ | 
|---|
| 64 | DECLARE_EXCEPT(16)              /* Coprocessor Fault Exception */ | 
|---|
| 65 | DECLARE_EXCEPT(17)              /* Alignment Check Exception (486+) */ | 
|---|
| 66 | DECLARE_EXCEPT(18)              /* Machine Check Exception (Pentium/586+) */ | 
|---|
| 67 | DECLARE_EXCEPT(19)              /* Reserved */ | 
|---|
| 68 | DECLARE_EXCEPT(20)              /* Reserved */ | 
|---|
| 69 | DECLARE_EXCEPT(21)              /* Reserved */ | 
|---|
| 70 | DECLARE_EXCEPT(22)              /* Reserved */ | 
|---|
| 71 | DECLARE_EXCEPT(23)              /* Reserved */ | 
|---|
| 72 | DECLARE_EXCEPT(24)              /* Reserved */ | 
|---|
| 73 | DECLARE_EXCEPT(25)              /* Reserved */ | 
|---|
| 74 | DECLARE_EXCEPT(26)              /* Reserved */ | 
|---|
| 75 | DECLARE_EXCEPT(27)              /* Reserved */ | 
|---|
| 76 | DECLARE_EXCEPT(28)              /* Reserved */ | 
|---|
| 77 | DECLARE_EXCEPT(29)              /* Reserved */ | 
|---|
| 78 | DECLARE_EXCEPT(30)              /* Reserved */ | 
|---|
| 79 | DECLARE_EXCEPT(31)              /* Reserved */ | 
|---|
| 80 |  | 
|---|
| 81 | .text | 
|---|
| 82 | .global __irq | 
|---|
| 83 | .align 16 | 
|---|
| 84 | __irq: | 
|---|
| 85 | DECLARE_IRQ(0) | 
|---|
| 86 | DECLARE_IRQ(1) | 
|---|
| 87 | DECLARE_IRQ(2) | 
|---|
| 88 | DECLARE_IRQ(3) | 
|---|
| 89 | DECLARE_IRQ(4) | 
|---|
| 90 | DECLARE_IRQ(5) | 
|---|
| 91 | DECLARE_IRQ(6) | 
|---|
| 92 | DECLARE_IRQ(7) | 
|---|
| 93 | DECLARE_IRQ(8) | 
|---|
| 94 | DECLARE_IRQ(9) | 
|---|
| 95 | DECLARE_IRQ(10) | 
|---|
| 96 | DECLARE_IRQ(11) | 
|---|
| 97 | DECLARE_IRQ(12) | 
|---|
| 98 | DECLARE_IRQ(13) | 
|---|
| 99 | DECLARE_IRQ(14) | 
|---|
| 100 | DECLARE_IRQ(15) | 
|---|
| 101 | DECLARE_IRQ(16) | 
|---|
| 102 | DECLARE_IRQ(17) | 
|---|
| 103 | DECLARE_IRQ(18) | 
|---|
| 104 | DECLARE_IRQ(19) | 
|---|
| 105 | DECLARE_IRQ(20) | 
|---|
| 106 | DECLARE_IRQ(21) | 
|---|
| 107 | DECLARE_IRQ(22) | 
|---|
| 108 | DECLARE_IRQ(23) | 
|---|
| 109 | DECLARE_IRQ(24) | 
|---|
| 110 | DECLARE_IRQ(25) | 
|---|
| 111 | DECLARE_IRQ(26) | 
|---|
| 112 | DECLARE_IRQ(27) | 
|---|
| 113 | DECLARE_IRQ(28) | 
|---|
| 114 | DECLARE_IRQ(29) | 
|---|
| 115 | DECLARE_IRQ(30) | 
|---|
| 116 | DECLARE_IRQ(31) | 
|---|
| 117 | DECLARE_IRQ(32) | 
|---|
| 118 | DECLARE_IRQ(33) | 
|---|
| 119 | DECLARE_IRQ(34) | 
|---|
| 120 | DECLARE_IRQ(35) | 
|---|
| 121 | DECLARE_IRQ(36) | 
|---|
| 122 | DECLARE_IRQ(37) | 
|---|
| 123 | DECLARE_IRQ(38) | 
|---|
| 124 | DECLARE_IRQ(39) | 
|---|
| 125 | DECLARE_IRQ(40) | 
|---|
| 126 | DECLARE_IRQ(41) | 
|---|
| 127 | DECLARE_IRQ(42) | 
|---|
| 128 | DECLARE_IRQ(43) | 
|---|
| 129 | DECLARE_IRQ(44) | 
|---|
| 130 | DECLARE_IRQ(45) | 
|---|
| 131 | DECLARE_IRQ(46) | 
|---|
| 132 | DECLARE_IRQ(47) | 
|---|
| 133 | DECLARE_IRQ(48) | 
|---|
| 134 | DECLARE_IRQ(49) | 
|---|
| 135 | DECLARE_IRQ(50) | 
|---|
| 136 | DECLARE_IRQ(51) | 
|---|
| 137 | DECLARE_IRQ(52) | 
|---|
| 138 | DECLARE_IRQ(53) | 
|---|
| 139 | DECLARE_IRQ(54) | 
|---|
| 140 | DECLARE_IRQ(55) | 
|---|
| 141 | DECLARE_IRQ(56) | 
|---|
| 142 | DECLARE_IRQ(57) | 
|---|
| 143 | DECLARE_IRQ(58) | 
|---|
| 144 | DECLARE_IRQ(59) | 
|---|
| 145 | DECLARE_IRQ(60) | 
|---|
| 146 | DECLARE_IRQ(61) | 
|---|
| 147 | DECLARE_IRQ(62) | 
|---|
| 148 | DECLARE_IRQ(63) | 
|---|
| 149 | DECLARE_IRQ(64) /* End of Available IRQ in this version, this is also the syscall gate (INT 96). | 
|---|
| 150 | * this value is used by PIC_IRQ_MAX macor */ | 
|---|
| 151 |  | 
|---|
| 152 | #define SAVE_REGS         \ | 
|---|
| 153 | pusha           ; \ | 
|---|
| 154 | push    %ds     ; \ | 
|---|
| 155 | push    %es     ; \ | 
|---|
| 156 | push    %fs     ; \ | 
|---|
| 157 | push    %gs     ; \ | 
|---|
| 158 |  | 
|---|
| 159 | #define RESTORE_REGS      \ | 
|---|
| 160 | pop     %gs     ; \ | 
|---|
| 161 | pop     %fs     ; \ | 
|---|
| 162 | pop     %es     ; \ | 
|---|
| 163 | pop     %ds     ; \ | 
|---|
| 164 | popa | 
|---|
| 165 |  | 
|---|
| 166 | #define LOAD_KERNEL_SEGMENT       \ | 
|---|
| 167 | mov     $0x10,  %ax     ; \ | 
|---|
| 168 | mov     %ax,    %ds     ; \ | 
|---|
| 169 | mov     %ax,    %es     ; \ | 
|---|
| 170 | mov     %ax,    %fs     ; \ | 
|---|
| 171 | mov     %ax,    %gs     ; \ | 
|---|
| 172 |  | 
|---|
| 173 | .extern __do_exception | 
|---|
| 174 | .extern __do_interrupt | 
|---|
| 175 |  | 
|---|
| 176 | unified_except_entry: | 
|---|
| 177 | SAVE_REGS | 
|---|
| 178 | LOAD_KERNEL_SEGMENT | 
|---|
| 179 | mov     %esp,   %eax | 
|---|
| 180 | push    %eax | 
|---|
| 181 | call    __do_exception | 
|---|
| 182 | pop     %eax | 
|---|
| 183 | RESTORE_REGS | 
|---|
| 184 | add     $0x8,   %esp | 
|---|
| 185 | iret | 
|---|
| 186 |  | 
|---|
| 187 | unified_irq_entry: | 
|---|
| 188 | SAVE_REGS | 
|---|
| 189 | LOAD_KERNEL_SEGMENT | 
|---|
| 190 | mov     %esp,   %eax | 
|---|
| 191 | push    %eax | 
|---|
| 192 | call    __do_interrupt | 
|---|
| 193 | pop     %eax | 
|---|
| 194 | RESTORE_REGS | 
|---|
| 195 | add     $0x8,   %esp | 
|---|
| 196 | iret | 
|---|
| 197 |  | 
|---|