]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/CpuDxe/X64/CpuInterrupt.S
61de8e8e19c439abaf448a6d634b4a158566f2c6
[mirror_edk2.git] / DuetPkg / CpuDxe / X64 / CpuInterrupt.S
1 #------------------------------------------------------------------------------
2 #*
3 #* Copyright 2006, Intel Corporation
4 #* All rights reserved. This program and the accompanying materials
5 #* are licensed and made available under the terms and conditions of the BSD License
6 #* which accompanies this distribution. The full text of the license may be found at
7 #* http://opensource.org/licenses/bsd-license.php
8 #*
9 #* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 #* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 #*
12 #* CpuInterrupt.S
13 #*
14 #* Abstract:
15 #*
16 #------------------------------------------------------------------------------
17
18 #PUBLIC SystemTimerHandler
19 #PUBLIC SystemExceptionHandler
20 #EXTERNDEF mExceptionCodeSize:DWORD
21
22 #EXTERN TimerHandler: NEAR
23 #EXTERN ExceptionHandler: NEAR
24 #EXTERN mTimerVector: DWORD
25
26 .data
27 ASM_GLOBAL ASM_PFX(mExceptionCodeSize)
28 ASM_PFX(mExceptionCodeSize): .long 9
29
30 .text
31 ASM_GLOBAL ASM_PFX(InitDescriptor)
32
33 ASM_PFX(InitDescriptor):
34 movq $GDT_BASE,%rax # EAX=PHYSICAL address of gdt
35 movq %rax, gdtr + 2 # Put address of gdt into the gdtr
36 lgdt gdtr
37 movq $0x18, %rax
38 movq %rax, %gs
39 movq %rax, %fs
40 movq $IDT_BASE,%rax # EAX=PHYSICAL address of idt
41 movq %rax, idtr + 2 # Put address of idt into the idtr
42 lidt idtr
43 ret
44
45 # VOID
46 # InstallInterruptHandler (
47 # UINTN Vector,
48 # VOID (*Handler)(VOID)
49 # )
50 ASM_GLOBAL ASM_PFX(InstallInterruptHandler)
51 ASM_PFX(InstallInterruptHandler):
52 # Vector:DWORD @ 4(%esp)
53 # Handler:DWORD @ 8(%esp)
54 push %rbx
55 pushfq # save eflags
56 cli # turn off interrupts
57 subq $0x10, %rsp # open some space on the stack
58 movq %rsp, %rbx
59
60 sidt (%rbx) # get fword address of IDT
61 movq 2(%rbx), %rbx # move offset of IDT into RBX
62 addq $0x10, %rsp # correct stack
63 movq %rcx, %rax # Get vector number
64 shlq $4, %rax # multiply by 16 to get offset
65 addq %rax, %rbx # add to IDT base to get entry
66 movq %rdx, %rax # load new address into IDT entry
67 movw %ax, (%rbx) # write bits 15..0 of offset
68 shrq $16, %rax # use ax to copy 31..16 to descriptors
69 movw %ax, 6(%rbx) # write bits 31..16 of offset
70 shrq $16, %rax # use eax to copy 63..32 to descriptors
71 movl %eax, 8(%rbx) # write bits 63..32 of offset
72 popfq # restore flags (possible enabling interrupts)
73 pop %rbx
74 ret
75
76 .macro JmpCommonIdtEntry
77 # jmp commonIdtEntry - this must be hand coded to keep the assembler from
78 # using a 8 bit reletive jump when the entries are
79 # within 255 bytes of the common entry. This must
80 # be done to maintain the consistency of the size
81 # of entry points...
82 .byte 0xe9 # jmp 16 bit reletive
83 .long commonIdtEntry - . - 4 # offset to jump to
84 .endm
85
86 .p2align 1
87 ASM_GLOBAL ASM_PFX(SystemExceptionHandler)
88 ASM_PFX(SystemExceptionHandler):
89 INT0:
90 push $0x0 # push error code place holder on the stack
91 push $0x0
92 JmpCommonIdtEntry
93 # db 0e9h # jmp 16 bit reletive
94 # dd commonIdtEntry - $ - 4 # offset to jump to
95
96 INT1:
97 push $0x0 # push error code place holder on the stack
98 push $0x1
99 JmpCommonIdtEntry
100
101 INT2:
102 push $0x0 # push error code place holder on the stack
103 push $0x2
104 JmpCommonIdtEntry
105
106 INT3:
107 push $0x0 # push error code place holder on the stack
108 push $0x3
109 JmpCommonIdtEntry
110
111 INT4:
112 push $0x0 # push error code place holder on the stack
113 push $0x4
114 JmpCommonIdtEntry
115
116 INT5:
117 push $0x0 # push error code place holder on the stack
118 push $0x5
119 JmpCommonIdtEntry
120
121 INT6:
122 push $0x0 # push error code place holder on the stack
123 push $0x6
124 JmpCommonIdtEntry
125
126 INT7:
127 push $0x0 # push error code place holder on the stack
128 push $0x7
129 JmpCommonIdtEntry
130
131 INT8:
132 # Double fault causes an error code to be pushed so no phony push necessary
133 nop
134 nop
135 push $0x8
136 JmpCommonIdtEntry
137
138 INT9:
139 push $0x0 # push error code place holder on the stack
140 push $0x9
141 JmpCommonIdtEntry
142
143 INT10:
144 # Invalid TSS causes an error code to be pushed so no phony push necessary
145 nop
146 nop
147 push $10
148 JmpCommonIdtEntry
149
150 INT11:
151 # Segment Not Present causes an error code to be pushed so no phony push necessary
152 nop
153 nop
154 push $11
155 JmpCommonIdtEntry
156
157 INT12:
158 # Stack fault causes an error code to be pushed so no phony push necessary
159 nop
160 nop
161 push $12
162 JmpCommonIdtEntry
163
164 INT13:
165 # GP fault causes an error code to be pushed so no phony push necessary
166 nop
167 nop
168 push $13
169 JmpCommonIdtEntry
170
171 INT14:
172 # Page fault causes an error code to be pushed so no phony push necessary
173 nop
174 nop
175 push $14
176 JmpCommonIdtEntry
177
178 INT15:
179 push $0x0 # push error code place holder on the stack
180 push $15
181 JmpCommonIdtEntry
182
183 INT16:
184 push $0x0 # push error code place holder on the stack
185 push $16
186 JmpCommonIdtEntry
187
188 INT17:
189 # Alignment check causes an error code to be pushed so no phony push necessary
190 nop
191 nop
192 push $17
193 JmpCommonIdtEntry
194
195 INT18:
196 push $0x0 # push error code place holder on the stack
197 push $18
198 JmpCommonIdtEntry
199
200 INT19:
201 push $0x0 # push error code place holder on the stack
202 push $19
203 JmpCommonIdtEntry
204
205 INTUnknown:
206 # The following segment repeats (32 - 20) times:
207 # No. 1
208 push $0x0 # push error code place holder on the stack
209 # push xxh # push vector number
210 .byte 0x6a
211 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
212 JmpCommonIdtEntry
213 # No. 2
214 push $0x0 # push error code place holder on the stack
215 # push xxh # push vector number
216 .byte 0x6a
217 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
218 JmpCommonIdtEntry
219 # No. 3
220 push $0x0 # push error code place holder on the stack
221 # push xxh # push vector number
222 .byte 0x6a
223 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
224 JmpCommonIdtEntry
225 # No. 4
226 push $0x0 # push error code place holder on the stack
227 # push xxh # push vector number
228 .byte 0x6a
229 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
230 JmpCommonIdtEntry
231 # No. 5
232 push $0x0 # push error code place holder on the stack
233 # push xxh # push vector number
234 .byte 0x6a
235 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
236 JmpCommonIdtEntry
237 # No. 6
238 push $0x0 # push error code place holder on the stack
239 # push xxh # push vector number
240 .byte 0x6a
241 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
242 JmpCommonIdtEntry
243 # No. 7
244 push $0x0 # push error code place holder on the stack
245 # push xxh # push vector number
246 .byte 0x6a
247 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
248 JmpCommonIdtEntry
249 # No. 8
250 push $0x0 # push error code place holder on the stack
251 # push xxh # push vector number
252 .byte 0x6a
253 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
254 JmpCommonIdtEntry
255 # No. 9
256 push $0x0 # push error code place holder on the stack
257 # push xxh # push vector number
258 .byte 0x6a
259 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
260 JmpCommonIdtEntry
261 # No. 10
262 push $0x0 # push error code place holder on the stack
263 # push xxh # push vector number
264 .byte 0x6a
265 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
266 JmpCommonIdtEntry
267 # No. 11
268 push $0x0 # push error code place holder on the stack
269 # push xxh # push vector number
270 .byte 0x6a
271 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
272 JmpCommonIdtEntry
273 # No. 12
274 push $0x0 # push error code place holder on the stack
275 # push xxh # push vector number
276 .byte 0x6a
277 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
278 JmpCommonIdtEntry
279
280
281 ASM_GLOBAL ASM_PFX(SystemTimerHandler)
282 ASM_PFX(SystemTimerHandler):
283 push $0
284 push $ASM_PFX(mTimerVector)
285 JmpCommonIdtEntry
286
287 commonIdtEntry:
288 # +---------------------+
289 # + EFlags +
290 # +---------------------+
291 # + CS +
292 # +---------------------+
293 # + EIP +
294 # +---------------------+
295 # + Error Code +
296 # +---------------------+
297 # + Vector Number +
298 # +---------------------+
299 # + EBP +
300 # +---------------------+ <-- EBP
301
302 cli
303 push %rbp
304 movq %rsp,%rbp
305
306 #
307 # Since here the stack pointer is 16-byte aligned, so
308 # EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64
309 # is 16-byte aligned
310 #
311
312 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax#
313 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15#
314 push %r15
315 push %r14
316 push %r13
317 push %r12
318 push %r11
319 push %r10
320 push %r9
321 push %r8
322 push %rax
323 push %rcx
324 push %rdx
325 push %rbx
326 push 6*8(%rbp)
327 push (%rbp)
328 push %rsi
329 push %rdi
330
331 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss# insure high 16 bits of each is zero
332 movzx 7*8(%rbp), %rax
333 push %rax # for ss
334 movzx 4*8(%rbp), %rax
335 push %rax # for cs
336 movq %ds, %rax
337 push %rax
338 movq %es, %rax
339 push %rax
340 movq %fs, %rax
341 push %rax
342 movq %gs, %rax
343 push %rax
344
345 ## UINT64 Rip#
346 push 3*8(%rbp)
347
348 ## UINT64 Gdtr[2], Idtr[2]#
349 subq $16, %rsp
350 sidt (%rsp)
351 subq $16, %rsp
352 sgdt (%rsp)
353
354 ## UINT64 Ldtr, Tr#
355 xorq %rax, %rax
356 str %ax
357 push %rax
358 sldt %ax
359 push %rax
360
361 ## UINT64 RFlags#
362 push 5*8(%rbp)
363
364 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8#
365 movq %cr8, %rax
366 push %rax
367 movq %cr4, %rax
368 orq $0x208, %rax
369 movq %rax, %cr4
370 push %rax
371 movq %cr3, %rax
372 push %rax
373 movq %cr2, %rax
374 push %rax
375 xorq %rax, %rax
376 push %rax
377 movq %cr0, %rax
378 push %rax
379
380 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7#
381 movq %dr7, %rax
382 push %rax
383
384 ## clear Dr7 while executing debugger itself
385 xorq %rax, %rax
386 movq %rax, %dr7
387
388 movq %dr6, %rax
389 push %rax
390
391 ## insure all status bits in dr6 are clear...
392 xorq %rax, %rax
393 movq %rax, %dr6
394
395 movq %dr3, %rax
396 push %rax
397 movq %dr2, %rax
398 push %rax
399 movq %dr1, %rax
400 push %rax
401 movq %dr0, %rax
402 push %rax
403
404
405 ## FX_SAVE_STATE_X64 FxSaveState#
406 subq $512, %rsp
407 movq %rsp, %rdi
408 fxsave (%rdi)
409
410 ## UINT64 ExceptionData#
411 push 2*8 (%rbp)
412
413 ## call into exception handler
414 ## Prepare parameter and call
415 movq 1*8(%rbp), %rcx
416 movq %rsp, %rdx
417 #
418 # Per X64 calling convention, allocate maximum parameter stack space
419 # and make sure RSP is 16-byte aligned
420 #
421 subq $(4*8+8), %rsp
422 cmpq $32, %rcx
423 jb CallException
424 call ASM_PFX(TimerHandler)
425 jmp ExceptionDone
426 CallException:
427 call ASM_PFX(ExceptionHandler)
428 ExceptionDone:
429 addq $(4*8+8), %rsp
430
431 cli
432
433 ## UINT64 ExceptionData#
434 addq $8, %rsp
435
436 ## FX_SAVE_STATE_X64 FxSaveState#
437 movq %rsp, %rsi
438 fxrstor (%esi)
439 addq $512, %rsp
440
441
442 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7#
443 pop %rax
444 movq %rax, %dr0
445 pop %rax
446 movq %rax, %dr1
447 pop %rax
448 movq %rax, %dr2
449 pop %rax
450 movq %rax, %dr3
451 ## skip restore of dr6. We cleared dr6 during the context save.
452 addq $8, %rsp
453 pop %rax
454 movq %rax, %dr7
455
456 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8#
457 pop %rax
458 movq %rax, %cr0
459 addq $8, %rsp # not for Cr1
460 pop %rax
461 movq %rax, %cr2
462 pop %rax
463 movq %rax, %cr3
464 pop %rax
465 movq %rax, %cr4
466 pop %rax
467 mov %rax, %cr8
468
469 ## UINT64 RFlags#
470 pop 5*8(%rbp)
471
472 ## UINT64 Ldtr, Tr#
473 ## UINT64 Gdtr[2], Idtr[2]#
474 ## Best not let anyone mess with these particular registers...
475 addq $48, %rsp
476
477 ## UINT64 Rip#
478 pop 3*8(%rbp)
479
480 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss#
481 pop %rax
482 # mov gs, rax # not for gs
483 pop %rax
484 # mov fs, rax # not for fs
485 # (X64 will not use fs and gs, so we do not restore it)
486 pop %rax
487 movq %rax, %es
488 pop %rax
489 movq %rax, %ds
490 pop 4*8(%rbp) # for cs
491 pop 7*8(%rbp) # for ss
492
493 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax#
494 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15#
495 pop %rdi
496 pop %rsi
497 addq $8, %rsp # not for rbp
498 pop 6*8(%rbp) # for rsp
499 pop %rbx
500 pop %rdx
501 pop %rcx
502 pop %rax
503 pop %r8
504 pop %r9
505 pop %r10
506 pop %r11
507 pop %r12
508 pop %r13
509 pop %r14
510 pop %r15
511
512 movq %rbp, %rsp
513 pop %rbp
514 addq $16, %rsp
515 iretq
516
517
518 ##############################################################################
519 # data
520 ##############################################################################
521
522 .data
523 .p2align 4
524
525 gdtr: .short GDT_END - GDT_BASE - 1 # GDT limit
526 .quad 0 # (GDT base gets set above)
527 ##############################################################################
528 # global descriptor table (GDT)
529 ##############################################################################
530
531 .p2align 4
532
533 GDT_BASE:
534 # null descriptor
535 NULL_SEL = .-GDT_BASE
536 .short 0 # limit 15:0
537 .short 0 # base 15:0
538 .byte 0 # base 23:16
539 .byte 0 # type
540 .byte 0 # limit 19:16, flags
541 .byte 0 # base 31:24
542
543 # linear data segment descriptor
544 LINEAR_SEL = .-GDT_BASE
545 .short 0x0FFFF # limit 0xFFFFF
546 .short 0 # base 0
547 .byte 0
548 .byte 0x092 # present, ring 0, data, expand-up, writable
549 .byte 0x0CF # page-granular, 32-bit
550 .byte 0
551
552 # linear code segment descriptor
553 LINEAR_CODE_SEL = .-GDT_BASE
554 .short 0x0FFFF # limit 0xFFFFF
555 .short 0 # base 0
556 .byte 0
557 .byte 0x09A # present, ring 0, data, expand-up, writable
558 .byte 0x0CF # page-granular, 32-bit
559 .byte 0
560
561 # system data segment descriptor
562 SYS_DATA_SEL = .-GDT_BASE
563 .short 0x0FFFF # limit 0xFFFFF
564 .short 0 # base 0
565 .byte 0
566 .byte 0x092 # present, ring 0, data, expand-up, writable
567 .byte 0x0CF # page-granular, 32-bit
568 .byte 0
569
570 # system code segment descriptor
571 SYS_CODE_SEL = .-GDT_BASE
572 .short 0x0FFFF # limit 0xFFFFF
573 .short 0 # base 0
574 .byte 0
575 .byte 0x09A # present, ring 0, data, expand-up, writable
576 .byte 0x0CF # page-granular, 32-bit
577 .byte 0
578
579 # spare segment descriptor
580 SPARE3_SEL = .-GDT_BASE
581 .short 0 # limit 0xFFFFF
582 .short 0 # base 0
583 .byte 0
584 .byte 0 # present, ring 0, data, expand-up, writable
585 .byte 0 # page-granular, 32-bit
586 .byte 0
587
588 # spare segment descriptor
589 SPARE4_SEL = .-GDT_BASE
590 .short 0 # limit 0xFFFFF
591 .short 0 # base 0
592 .byte 0
593 .byte 0 # present, ring 0, data, expand-up, writable
594 .byte 0 # page-granular, 32-bit
595 .byte 0
596
597 # spare segment descriptor
598 SPARE5_SEL = .-GDT_BASE
599 .short 0 # limit 0xFFFFF
600 .short 0 # base 0
601 .byte 0
602 .byte 0 # present, ring 0, data, expand-up, writable
603 .byte 0 # page-granular, 32-bit
604 .byte 0
605
606 GDT_END:
607
608 .p2align 2
609
610
611
612 idtr: .short IDT_END - IDT_BASE - 1 # IDT limit
613 .quad 0 # (IDT base gets set above)
614 ##############################################################################
615 # interrupt descriptor table (IDT)
616 #
617 # Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
618 # mappings. This implementation only uses the system timer and all other
619 # IRQs will remain masked. The descriptors for vectors 33+ are provided
620 # for convenience.
621 ##############################################################################
622
623 #idt_tag .byte "IDT",0
624 .p2align 2
625
626 IDT_BASE:
627 # divide by zero (INT 0)
628 DIV_ZERO_SEL = .-IDT_BASE
629 .short 0 # offset 15:0
630 .short SYS_CODE_SEL # selector 15:0
631 .byte 0 # 0 for interrupt gate
632 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
633 .short 0 # offset 31:16
634
635 # debug exception (INT 1)
636 DEBUG_EXCEPT_SEL = .-IDT_BASE
637 .short 0 # offset 15:0
638 .short SYS_CODE_SEL # selector 15:0
639 .byte 0 # 0 for interrupt gate
640 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
641 .short 0 # offset 31:16
642
643 # NMI (INT 2)
644 NMI_SEL = .-IDT_BASE
645 .short 0 # offset 15:0
646 .short SYS_CODE_SEL # selector 15:0
647 .byte 0 # 0 for interrupt gate
648 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
649 .short 0 # offset 31:16
650
651 # soft breakpoint (INT 3)
652 BREAKPOINT_SEL = .-IDT_BASE
653 .short 0 # offset 15:0
654 .short SYS_CODE_SEL # selector 15:0
655 .byte 0 # 0 for interrupt gate
656 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
657 .short 0 # offset 31:16
658
659 # overflow (INT 4)
660 OVERFLOW_SEL = .-IDT_BASE
661 .short 0 # offset 15:0
662 .short SYS_CODE_SEL # selector 15:0
663 .byte 0 # 0 for interrupt gate
664 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
665 .short 0 # offset 31:16
666
667 # bounds check (INT 5)
668 BOUNDS_CHECK_SEL = .-IDT_BASE
669 .short 0 # offset 15:0
670 .short SYS_CODE_SEL # selector 15:0
671 .byte 0 # 0 for interrupt gate
672 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
673 .short 0 # offset 31:16
674
675 # invalid opcode (INT 6)
676 INVALID_OPCODE_SEL = .-IDT_BASE
677 .short 0 # offset 15:0
678 .short SYS_CODE_SEL # selector 15:0
679 .byte 0 # 0 for interrupt gate
680 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
681 .short 0 # offset 31:16
682
683 # device not available (INT 7)
684 DEV_NOT_AVAIL_SEL = .-IDT_BASE
685 .short 0 # offset 15:0
686 .short SYS_CODE_SEL # selector 15:0
687 .byte 0 # 0 for interrupt gate
688 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
689 .short 0 # offset 31:16
690
691 # double fault (INT 8)
692 DOUBLE_FAULT_SEL = .-IDT_BASE
693 .short 0 # offset 15:0
694 .short SYS_CODE_SEL # selector 15:0
695 .byte 0 # 0 for interrupt gate
696 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
697 .short 0 # offset 31:16
698
699 # Coprocessor segment overrun - reserved (INT 9)
700 RSVD_INTR_SEL1 = .-IDT_BASE
701 .short 0 # offset 15:0
702 .short SYS_CODE_SEL # selector 15:0
703 .byte 0 # 0 for interrupt gate
704 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
705 .short 0 # offset 31:16
706
707 # invalid TSS (INT 0ah)
708 INVALID_TSS_SEL = .-IDT_BASE
709 .short 0 # offset 15:0
710 .short SYS_CODE_SEL # selector 15:0
711 .byte 0 # 0 for interrupt gate
712 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
713 .short 0 # offset 31:16
714
715 # segment not present (INT 0bh)
716 SEG_NOT_PRESENT_SEL = .-IDT_BASE
717 .short 0 # offset 15:0
718 .short SYS_CODE_SEL # selector 15:0
719 .byte 0 # 0 for interrupt gate
720 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
721 .short 0 # offset 31:16
722
723 # stack fault (INT 0ch)
724 STACK_FAULT_SEL = .-IDT_BASE
725 .short 0 # offset 15:0
726 .short SYS_CODE_SEL # selector 15:0
727 .byte 0 # 0 for interrupt gate
728 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
729 .short 0 # offset 31:16
730
731 # general protection (INT 0dh)
732 GP_FAULT_SEL = .-IDT_BASE
733 .short 0 # offset 15:0
734 .short SYS_CODE_SEL # selector 15:0
735 .byte 0 # 0 for interrupt gate
736 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
737 .short 0 # offset 31:16
738
739 # page fault (INT 0eh)
740 PAGE_FAULT_SEL = .-IDT_BASE
741 .short 0 # offset 15:0
742 .short SYS_CODE_SEL # selector 15:0
743 .byte 0 # 0 for interrupt gate
744 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
745 .short 0 # offset 31:16
746
747 # Intel reserved - do not use (INT 0fh)
748 RSVD_INTR_SEL2 = .-IDT_BASE
749 .short 0 # offset 15:0
750 .short SYS_CODE_SEL # selector 15:0
751 .byte 0 # 0 for interrupt gate
752 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
753 .short 0 # offset 31:16
754
755 # floating point error (INT 0x10)
756 FLT_POINT_ERR_SEL = .-IDT_BASE
757 .short 0 # offset 15:0
758 .short SYS_CODE_SEL # selector 15:0
759 .byte 0 # 0 for interrupt gate
760 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
761 .short 0 # offset 31:16
762
763 # alignment check (INT 0x11)
764 ALIGNMENT_CHECK_SEL = .-IDT_BASE
765 .short 0 # offset 15:0
766 .short SYS_CODE_SEL # selector 15:0
767 .byte 0 # 0 for interrupt gate
768 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
769 .short 0 # offset 31:16
770
771 # machine check (INT 0x12)
772 MACHINE_CHECK_SEL = .-IDT_BASE
773 .short 0 # offset 15:0
774 .short SYS_CODE_SEL # selector 15:0
775 .byte 0 # 0 for interrupt gate
776 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
777 .short 0 # offset 31:16
778
779 # SIMD floating-point exception (INT 0x13)
780 SIMD_EXCEPTION_SEL = .-IDT_BASE
781 .short 0 # offset 15:0
782 .short SYS_CODE_SEL # selector 15:0
783 .byte 0 # 0 for interrupt gate
784 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
785 .short 0 # offset 31:16
786
787 # The following segment repeats (32 - 20) times:
788 # No. 1
789 .short 0 # offset 15:0
790 .short SYS_CODE_SEL # selector 15:0
791 .byte 0 # 0 for interrupt gate
792 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
793 .short 0 # offset 31:16
794 # No. 2
795 .short 0 # offset 15:0
796 .short SYS_CODE_SEL # selector 15:0
797 .byte 0 # 0 for interrupt gate
798 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
799 .short 0 # offset 31:16
800 # No. 3
801 .short 0 # offset 15:0
802 .short SYS_CODE_SEL # selector 15:0
803 .byte 0 # 0 for interrupt gate
804 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
805 .short 0 # offset 31:16
806 # No. 4
807 .short 0 # offset 15:0
808 .short SYS_CODE_SEL # selector 15:0
809 .byte 0 # 0 for interrupt gate
810 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
811 .short 0 # offset 31:16
812 # No. 5
813 .short 0 # offset 15:0
814 .short SYS_CODE_SEL # selector 15:0
815 .byte 0 # 0 for interrupt gate
816 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
817 .short 0 # offset 31:16
818 # No. 6
819 .short 0 # offset 15:0
820 .short SYS_CODE_SEL # selector 15:0
821 .byte 0 # 0 for interrupt gate
822 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
823 .short 0 # offset 31:16
824 # No. 7
825 .short 0 # offset 15:0
826 .short SYS_CODE_SEL # selector 15:0
827 .byte 0 # 0 for interrupt gate
828 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
829 .short 0 # offset 31:16
830 # No. 8
831 .short 0 # offset 15:0
832 .short SYS_CODE_SEL # selector 15:0
833 .byte 0 # 0 for interrupt gate
834 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
835 .short 0 # offset 31:16
836 # No. 9
837 .short 0 # offset 15:0
838 .short SYS_CODE_SEL # selector 15:0
839 .byte 0 # 0 for interrupt gate
840 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
841 .short 0 # offset 31:16
842 # No. 10
843 .short 0 # offset 15:0
844 .short SYS_CODE_SEL # selector 15:0
845 .byte 0 # 0 for interrupt gate
846 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
847 .short 0 # offset 31:16
848 # No. 11
849 .short 0 # offset 15:0
850 .short SYS_CODE_SEL # selector 15:0
851 .byte 0 # 0 for interrupt gate
852 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
853 .short 0 # offset 31:16
854 # No. 12
855 .short 0 # offset 15:0
856 .short SYS_CODE_SEL # selector 15:0
857 .byte 0 # 0 for interrupt gate
858 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
859 .short 0 # offset 31:16
860
861
862 # 72 unspecified descriptors
863 .fill 72 * 8, 1, 0
864
865 # IRQ 0 (System timer) - (INT 0x68)
866 IRQ0_SEL = .-IDT_BASE
867 .short 0 # offset 15:0
868 .short SYS_CODE_SEL # selector 15:0
869 .byte 0 # 0 for interrupt gate
870 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
871 .short 0 # offset 31:16
872
873 # IRQ 1 (8042 Keyboard controller) - (INT 0x69)
874 IRQ1_SEL = .-IDT_BASE
875 .short 0 # offset 15:0
876 .short SYS_CODE_SEL # selector 15:0
877 .byte 0 # 0 for interrupt gate
878 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
879 .short 0 # offset 31:16
880
881 # Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
882 IRQ2_SEL = .-IDT_BASE
883 .short 0 # offset 15:0
884 .short SYS_CODE_SEL # selector 15:0
885 .byte 0 # 0 for interrupt gate
886 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
887 .short 0 # offset 31:16
888
889 # IRQ 3 (COM 2) - (INT 6bh)
890 IRQ3_SEL = .-IDT_BASE
891 .short 0 # offset 15:0
892 .short SYS_CODE_SEL # selector 15:0
893 .byte 0 # 0 for interrupt gate
894 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
895 .short 0 # offset 31:16
896
897 # IRQ 4 (COM 1) - (INT 6ch)
898 IRQ4_SEL = .-IDT_BASE
899 .short 0 # offset 15:0
900 .short SYS_CODE_SEL # selector 15:0
901 .byte 0 # 0 for interrupt gate
902 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
903 .short 0 # offset 31:16
904
905 # IRQ 5 (LPT 2) - (INT 6dh)
906 IRQ5_SEL = .-IDT_BASE
907 .short 0 # offset 15:0
908 .short SYS_CODE_SEL # selector 15:0
909 .byte 0 # 0 for interrupt gate
910 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
911 .short 0 # offset 31:16
912
913 # IRQ 6 (Floppy controller) - (INT 6eh)
914 IRQ6_SEL = .-IDT_BASE
915 .short 0 # offset 15:0
916 .short SYS_CODE_SEL # selector 15:0
917 .byte 0 # 0 for interrupt gate
918 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
919 .short 0 # offset 31:16
920
921 # IRQ 7 (LPT 1) - (INT 6fh)
922 IRQ7_SEL = .-IDT_BASE
923 .short 0 # offset 15:0
924 .short SYS_CODE_SEL # selector 15:0
925 .byte 0 # 0 for interrupt gate
926 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
927 .short 0 # offset 31:16
928
929 # IRQ 8 (RTC Alarm) - (INT 0x70)
930 IRQ8_SEL = .-IDT_BASE
931 .short 0 # offset 15:0
932 .short SYS_CODE_SEL # selector 15:0
933 .byte 0 # 0 for interrupt gate
934 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
935 .short 0 # offset 31:16
936
937 # IRQ 9 - (INT 0x71)
938 IRQ9_SEL = .-IDT_BASE
939 .short 0 # offset 15:0
940 .short SYS_CODE_SEL # selector 15:0
941 .byte 0 # 0 for interrupt gate
942 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
943 .short 0 # offset 31:16
944
945 # IRQ 10 - (INT 0x72)
946 IRQ10_SEL = .-IDT_BASE
947 .short 0 # offset 15:0
948 .short SYS_CODE_SEL # selector 15:0
949 .byte 0 # 0 for interrupt gate
950 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
951 .short 0 # offset 31:16
952
953 # IRQ 11 - (INT 0x73)
954 IRQ11_SEL = .-IDT_BASE
955 .short 0 # offset 15:0
956 .short SYS_CODE_SEL # selector 15:0
957 .byte 0 # 0 for interrupt gate
958 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
959 .short 0 # offset 31:16
960
961 # IRQ 12 (PS/2 mouse) - (INT 0x74)
962 IRQ12_SEL = .-IDT_BASE
963 .short 0 # offset 15:0
964 .short SYS_CODE_SEL # selector 15:0
965 .byte 0 # 0 for interrupt gate
966 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
967 .short 0 # offset 31:16
968
969 # IRQ 13 (Floating point error) - (INT 0x75)
970 IRQ13_SEL = .-IDT_BASE
971 .short 0 # offset 15:0
972 .short SYS_CODE_SEL # selector 15:0
973 .byte 0 # 0 for interrupt gate
974 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
975 .short 0 # offset 31:16
976
977 # IRQ 14 (Secondary IDE) - (INT 0x76)
978 IRQ14_SEL = .-IDT_BASE
979 .short 0 # offset 15:0
980 .short SYS_CODE_SEL # selector 15:0
981 .byte 0 # 0 for interrupt gate
982 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
983 .short 0 # offset 31:16
984
985 # IRQ 15 (Primary IDE) - (INT 0x77)
986 IRQ15_SEL = .-IDT_BASE
987 .short 0 # offset 15:0
988 .short SYS_CODE_SEL # selector 15:0
989 .byte 0 # 0 for interrupt gate
990 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
991 .short 0 # offset 31:16
992
993 .fill 16, 1, 0
994
995 IDT_END:
996