1 ; =============================================================================
2 ; Pure64 -- a 64-bit OS loader written in Assembly for x86-64 systems
3 ; Copyright (C) 2008-2012 Return Infinity -- see LICENSE.TXT
6 ; =============================================================================
9 ; -----------------------------------------------------------------------------
10 ; Default exception handler
17 cli ; Disable interrupts
19 jmp exception_gate_halt
20 ; -----------------------------------------------------------------------------
23 ; -----------------------------------------------------------------------------
24 ; Default interrupt handler
25 interrupt_gate: ; handler for all other interrupts
27 ; -----------------------------------------------------------------------------
30 ; -----------------------------------------------------------------------------
31 ; Keyboard interrupt. IRQ 0x01, INT 0x21
32 ; This IRQ runs whenever there is input on the keyboard
40 in al, 0x60 ; Get the scancode from the keyboard
46 mov [0x000B8088], al ; Dump the scancode to the screen
48 mov rax
, [os_Counter_RTC
]
50 mov [os_Counter_RTC
], rax
53 mov rdi
, [os_LocalAPICAddress
] ; Acknowledge the IRQ on APIC
61 ; -----------------------------------------------------------------------------
64 ; -----------------------------------------------------------------------------
65 ; Real-time clock interrupt. IRQ 0x08, INT 0x28
71 add qword [os_Counter_RTC
], 1 ; 64-bit counter started at bootup
75 mov rax
, [os_Counter_RTC
]
76 and al, 1 ; Clear all but lowest bit (Can only be 0 or 1)
79 mov al, 0x0C ; Select RTC register C
80 out 0x70, al ; Port 0x70 is the RTC index, and 0x71 is the RTC data
81 in al, 0x71 ; Read the value in register C
83 mov rdi
, [os_LocalAPICAddress
] ; Acknowledge the IRQ on APIC
91 ; -----------------------------------------------------------------------------
94 ; -----------------------------------------------------------------------------
95 ; Spurious interrupt. INT 0xFF
97 spurious: ; handler for spurious interrupts
101 ; -----------------------------------------------------------------------------
104 ; -----------------------------------------------------------------------------
105 ; CPU Exception Gates
108 jmp exception_gate_main
112 jmp exception_gate_main
116 jmp exception_gate_main
120 jmp exception_gate_main
124 jmp exception_gate_main
128 jmp exception_gate_main
132 jmp exception_gate_main
136 jmp exception_gate_main
140 jmp exception_gate_main
144 jmp exception_gate_main
148 jmp exception_gate_main
152 jmp exception_gate_main
156 jmp exception_gate_main
160 jmp exception_gate_main
164 jmp exception_gate_main
168 jmp exception_gate_main
172 jmp exception_gate_main
176 jmp exception_gate_main
180 jmp exception_gate_main
184 jmp exception_gate_main
187 call os_print_newline
190 mov rsi
, exc_string00
191 and rax
, 0xFF ; Clear out everything in RAX except for AL
193 mul bl ; AX = AL x BL
194 add rsi
, rax
; Use the value in RAX as an offset to get to the right message
199 mov rdi
, os_dump_reg_tstring
200 call os_int_to_hex_string
; Convert the register value to a hex string
201 mov rsi
, os_dump_reg_tstring
202 call os_print_string
; Print the hex string
203 call os_print_newline
206 exception_gate_main_hang:
208 jmp exception_gate_main_hang
; Hang. User must reset machine at this point
210 ; Strings for the error messages
211 int_string
db 'Pure64 - Exception ', 0
212 adr_string
db ' @ 0x', 0
213 exc_string
db '?? - Unknown', 0
215 exc_string00
db '00 - DE', 0
216 exc_string01
db '01 - DB', 0
217 exc_string02
db '02 ', 0
218 exc_string03
db '03 - BP', 0
219 exc_string04
db '04 - OF', 0
220 exc_string05
db '05 - BR', 0
221 exc_string06
db '06 - UD', 0
222 exc_string07
db '07 - NM', 0
223 exc_string08
db '08 - DF', 0
224 exc_string09
db '09 ', 0 ; No longer generated on new CPU's
225 exc_string10
db '10 - TS', 0
226 exc_string11
db '11 - NP', 0
227 exc_string12
db '12 - SS', 0
228 exc_string13
db '13 - GP', 0
229 exc_string14
db '14 - PF', 0
230 exc_string15
db '15 ', 0
231 exc_string16
db '16 - MF', 0
232 exc_string17
db '17 - AC', 0
233 exc_string18
db '18 - MC', 0
234 exc_string19
db '19 - XM', 0
237 ; =============================================================================