@@ -25,7 +25,7 @@ use x86_64::{
2525 } ,
2626 structures:: {
2727 gdt:: { Descriptor , DescriptorFlags , GlobalDescriptorTable , SegmentSelector } ,
28- idt:: { InterruptDescriptorTable , InterruptStackFrame , PageFaultErrorCode } ,
28+ idt:: { ExceptionVector , InterruptDescriptorTable , InterruptStackFrame , PageFaultErrorCode } ,
2929 paging:: Page ,
3030 tss:: TaskStateSegment ,
3131 } ,
@@ -154,6 +154,8 @@ pub fn load_idt() {
154154 idt. general_protection_fault
155155 . set_handler_fn ( general_protection_fault_handler) ;
156156 idt. page_fault . set_handler_fn ( page_fault_handler) ;
157+ idt. simd_floating_point
158+ . set_handler_fn ( simd_floating_point_handler) ;
157159 idt[ TLB_VECTOR ] . set_handler_fn ( tlb_shootdown_handler) ;
158160 idt[ TIMER_VECTOR ] . set_handler_fn ( timer_handler) ;
159161
@@ -178,12 +180,13 @@ extern "x86-interrupt" fn divide_error_handler(frame: InterruptStackFrame) {
178180 // Userspace code path:
179181 "swapgs" ,
180182 // Store the error code.
181- "mov byte ptr gs:[{VECTOR_OFFSET}], 0x0 " ,
183+ "mov byte ptr gs:[{VECTOR_OFFSET}], {VECTOR} " ,
182184 // Jump to the userspace exit point.
183185 "jmp {exception_entry}" ,
184186
185187 kernel_divide_error_handler = sym kernel_divide_error_handler,
186188 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
189+ VECTOR = const ExceptionVector :: Division as u8 ,
187190 exception_entry = sym exception_entry,
188191 ) ;
189192}
@@ -206,7 +209,7 @@ extern "x86-interrupt" fn page_fault_handler(
206209 // Userspace code path:
207210 "swapgs" ,
208211 // Store the error code.
209- "mov byte ptr gs:[{VECTOR_OFFSET}], 0xe " ,
212+ "mov byte ptr gs:[{VECTOR_OFFSET}], {VECTOR} " ,
210213 "pop qword ptr gs:[{ERROR_CODE_OFFSET}]" ,
211214 // Jump to the userspace exit point.
212215 "jmp {exception_entry}" ,
@@ -257,6 +260,7 @@ extern "x86-interrupt" fn page_fault_handler(
257260
258261 kernel_page_fault_handler = sym kernel_page_fault_handler,
259262 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
263+ VECTOR = const ExceptionVector :: Page as u8 ,
260264 ERROR_CODE_OFFSET = const offset_of!( PerCpu , error_code) ,
261265 exception_entry = sym exception_entry,
262266 ) ;
@@ -309,13 +313,14 @@ extern "x86-interrupt" fn general_protection_fault_handler(
309313 // Userspace code path:
310314 "swapgs" ,
311315 // Store the error code.
312- "mov byte ptr gs:[{VECTOR_OFFSET}], 0xd " ,
316+ "mov byte ptr gs:[{VECTOR_OFFSET}], {VECTOR} " ,
313317 "pop qword ptr gs:[{ERROR_CODE_OFFSET}]" ,
314318 // Jump to the userspace exit point.
315319 "jmp {exception_entry}" ,
316320
317321 kernel_general_protection_fault_handler = sym kernel_general_protection_fault_handler,
318322 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
323+ VECTOR = const ExceptionVector :: GeneralProtection as u8 ,
319324 ERROR_CODE_OFFSET = const offset_of!( PerCpu , error_code) ,
320325 exception_entry = sym exception_entry,
321326 ) ;
@@ -328,23 +333,50 @@ extern "x86-interrupt" fn kernel_general_protection_fault_handler(
328333 panic ! ( "general protection fault {frame:x?} {code:x?}" ) ;
329334}
330335
336+ #[ unsafe( naked) ]
337+ extern "x86-interrupt" fn simd_floating_point_handler ( frame : InterruptStackFrame ) {
338+ naked_asm ! (
339+ "cld" ,
340+ // Check whether the exception happened in userspace.
341+ "test word ptr [rsp+8], 3" ,
342+ "je {kernel_simd_floating_point_handler}" ,
343+
344+ // Userspace code path:
345+ "swapgs" ,
346+ // Store the error code.
347+ "mov byte ptr gs:[{VECTOR_OFFSET}], {VECTOR}" ,
348+ // Jump to the userspace exit point.
349+ "jmp {exception_entry}" ,
350+
351+ kernel_simd_floating_point_handler = sym kernel_simd_floating_point_handler,
352+ VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
353+ VECTOR = const ExceptionVector :: SimdFloatingPoint as u8 ,
354+ exception_entry = sym exception_entry,
355+ ) ;
356+ }
357+
358+ extern "x86-interrupt" fn kernel_simd_floating_point_handler ( frame : InterruptStackFrame ) {
359+ panic ! ( "simd floating point exception {frame:x?}" ) ;
360+ }
361+
331362#[ unsafe( naked) ]
332363extern "x86-interrupt" fn invalid_opcode_handler ( frame : InterruptStackFrame ) {
333364 naked_asm ! (
334365 "cld" ,
335366 // Check whether the exception happened in userspace.
336- "test word ptr [rsp+16 ], 3" ,
367+ "test word ptr [rsp+8 ], 3" ,
337368 "je {kernel_invalid_opcode_handler}" ,
338369
339370 // Userspace code path:
340371 "swapgs" ,
341372 // Store the error code.
342- "mov byte ptr gs:[{VECTOR_OFFSET}], 0x6 " ,
373+ "mov byte ptr gs:[{VECTOR_OFFSET}], {VECTOR} " ,
343374 // Jump to the userspace exit point.
344375 "jmp {exception_entry}" ,
345376
346377 kernel_invalid_opcode_handler = sym kernel_invalid_opcode_handler,
347378 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
379+ VECTOR = const ExceptionVector :: InvalidOpcode as u8 ,
348380 exception_entry = sym exception_entry,
349381 ) ;
350382}
@@ -422,13 +454,13 @@ extern "x86-interrupt" fn timer_handler(frame: InterruptStackFrame) {
422454 // Userspace code path:
423455 "swapgs" ,
424456 // Store the error code.
425- "mov byte ptr gs:[{VECTOR_OFFSET}], {TIMER_VECTOR }" ,
457+ "mov byte ptr gs:[{VECTOR_OFFSET}], {VECTOR }" ,
426458 // Jump to the userspace exit point.
427459 "jmp {interrupt_entry}" ,
428460
429461 kernel_timer_handler = sym kernel_timer_handler,
430462 VECTOR_OFFSET = const offset_of!( PerCpu , vector) ,
431- TIMER_VECTOR = const TIMER_VECTOR ,
463+ VECTOR = const TIMER_VECTOR ,
432464 interrupt_entry = sym interrupt_entry,
433465 ) ;
434466}
0 commit comments