]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/CpuDxe/X64/CpuInterrupt.S
Pass X64 GCC building
[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 .globl ASM_PFX(mExceptionCodeSize)
28 ASM_PFX(mExceptionCodeSize): .long 9
29
30 .text
31 .globl 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 .globl 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 .align 2
87 .globl 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 .rept (32 - 20)
207 push $0x0 # push error code place holder on the stack
208 # push xxh # push vector number
209 .byte 0x6a
210 .byte ( . - INTUnknown - 3 ) / 9 + 20 # vector number
211 JmpCommonIdtEntry
212 .endr
213
214 .globl ASM_PFX(SystemTimerHandler)
215 ASM_PFX(SystemTimerHandler):
216 push $0
217 push $ASM_PFX(mTimerVector)
218 JmpCommonIdtEntry
219
220 commonIdtEntry:
221 # +---------------------+
222 # + EFlags +
223 # +---------------------+
224 # + CS +
225 # +---------------------+
226 # + EIP +
227 # +---------------------+
228 # + Error Code +
229 # +---------------------+
230 # + Vector Number +
231 # +---------------------+
232 # + EBP +
233 # +---------------------+ <-- EBP
234
235 cli
236 push %rbp
237 movq %rsp,%rbp
238
239 #
240 # Since here the stack pointer is 16-byte aligned, so
241 # EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64
242 # is 16-byte aligned
243 #
244
245 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax#
246 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15#
247 push %r15
248 push %r14
249 push %r13
250 push %r12
251 push %r11
252 push %r10
253 push %r9
254 push %r8
255 push %rax
256 push %rcx
257 push %rdx
258 push %rbx
259 push 6*8(%rbp)
260 push (%rbp)
261 push %rsi
262 push %rdi
263
264 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss# insure high 16 bits of each is zero
265 movzx 7*8(%rbp), %rax
266 push %rax # for ss
267 movzx 4*8(%rbp), %rax
268 push %rax # for cs
269 movq %ds, %rax
270 push %rax
271 movq %es, %rax
272 push %rax
273 movq %fs, %rax
274 push %rax
275 movq %gs, %rax
276 push %rax
277
278 ## UINT64 Rip#
279 push 3*8(%rbp)
280
281 ## UINT64 Gdtr[2], Idtr[2]#
282 subq $16, %rsp
283 sidt (%rsp)
284 subq $16, %rsp
285 sgdt (%rsp)
286
287 ## UINT64 Ldtr, Tr#
288 xorq %rax, %rax
289 str %ax
290 push %rax
291 sldt %ax
292 push %rax
293
294 ## UINT64 RFlags#
295 push 5*8(%rbp)
296
297 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8#
298 movq %cr8, %rax
299 push %rax
300 movq %cr4, %rax
301 orq $0x208, %rax
302 movq %rax, %cr4
303 push %rax
304 movq %cr3, %rax
305 push %rax
306 movq %cr2, %rax
307 push %rax
308 xorq %rax, %rax
309 push %rax
310 movq %cr0, %rax
311 push %rax
312
313 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7#
314 movq %dr7, %rax
315 push %rax
316
317 ## clear Dr7 while executing debugger itself
318 xorq %rax, %rax
319 movq %rax, %dr7
320
321 movq %dr6, %rax
322 push %rax
323
324 ## insure all status bits in dr6 are clear...
325 xorq %rax, %rax
326 movq %rax, %dr6
327
328 movq %dr3, %rax
329 push %rax
330 movq %dr2, %rax
331 push %rax
332 movq %dr1, %rax
333 push %rax
334 movq %dr0, %rax
335 push %rax
336
337
338 ## FX_SAVE_STATE_X64 FxSaveState#
339 subq $512, %rsp
340 movq %rsp, %rdi
341 fxsave (%rdi)
342
343 ## UINT64 ExceptionData#
344 push 2*8 (%rbp)
345
346 ## call into exception handler
347 ## Prepare parameter and call
348 movq 1*8(%rbp), %rcx
349 movq %rsp, %rdx
350 #
351 # Per X64 calling convention, allocate maximum parameter stack space
352 # and make sure RSP is 16-byte aligned
353 #
354 subq $(4*8+8), %rsp
355 cmpq $32, %rcx
356 jb CallException
357 call ASM_PFX(TimerHandler)
358 jmp ExceptionDone
359 CallException:
360 call ASM_PFX(ExceptionHandler)
361 ExceptionDone:
362 addq $(4*8+8), %rsp
363
364 cli
365
366 ## UINT64 ExceptionData#
367 addq $8, %rsp
368
369 ## FX_SAVE_STATE_X64 FxSaveState#
370 movq %rsp, %rsi
371 fxrstor (%esi)
372 addq $512, %rsp
373
374
375 ## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7#
376 pop %rax
377 movq %rax, %dr0
378 pop %rax
379 movq %rax, %dr1
380 pop %rax
381 movq %rax, %dr2
382 pop %rax
383 movq %rax, %dr3
384 ## skip restore of dr6. We cleared dr6 during the context save.
385 addq $8, %rsp
386 pop %rax
387 movq %rax, %dr7
388
389 ## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8#
390 pop %rax
391 movq %rax, %cr0
392 addq $8, %rsp # not for Cr1
393 pop %rax
394 movq %rax, %cr2
395 pop %rax
396 movq %rax, %cr3
397 pop %rax
398 movq %rax, %cr4
399 pop %rax
400 mov %rax, %cr8
401
402 ## UINT64 RFlags#
403 pop 5*8(%rbp)
404
405 ## UINT64 Ldtr, Tr#
406 ## UINT64 Gdtr[2], Idtr[2]#
407 ## Best not let anyone mess with these particular registers...
408 addq $48, %rsp
409
410 ## UINT64 Rip#
411 pop 3*8(%rbp)
412
413 ## UINT64 Gs, Fs, Es, Ds, Cs, Ss#
414 pop %rax
415 # mov gs, rax # not for gs
416 pop %rax
417 # mov fs, rax # not for fs
418 # (X64 will not use fs and gs, so we do not restore it)
419 pop %rax
420 movq %rax, %es
421 pop %rax
422 movq %rax, %ds
423 pop 4*8(%rbp) # for cs
424 pop 7*8(%rbp) # for ss
425
426 ## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax#
427 ## UINT64 R8, R9, R10, R11, R12, R13, R14, R15#
428 pop %rdi
429 pop %rsi
430 addq $8, %rsp # not for rbp
431 pop 6*8(%rbp) # for rsp
432 pop %rbx
433 pop %rdx
434 pop %rcx
435 pop %rax
436 pop %r8
437 pop %r9
438 pop %r10
439 pop %r11
440 pop %r12
441 pop %r13
442 pop %r14
443 pop %r15
444
445 movq %rbp, %rsp
446 pop %rbp
447 addq $16, %rsp
448 iretq
449
450
451 ##############################################################################
452 # data
453 ##############################################################################
454
455 .data
456 .align 0x10
457
458 gdtr: .short GDT_END - GDT_BASE - 1 # GDT limit
459 .quad 0 # (GDT base gets set above)
460 ##############################################################################
461 # global descriptor table (GDT)
462 ##############################################################################
463
464 .align 0x10
465
466 GDT_BASE:
467 # null descriptor
468 NULL_SEL = .-GDT_BASE
469 .short 0 # limit 15:0
470 .short 0 # base 15:0
471 .byte 0 # base 23:16
472 .byte 0 # type
473 .byte 0 # limit 19:16, flags
474 .byte 0 # base 31:24
475
476 # linear data segment descriptor
477 LINEAR_SEL = .-GDT_BASE
478 .short 0x0FFFF # limit 0xFFFFF
479 .short 0 # base 0
480 .byte 0
481 .byte 0x092 # present, ring 0, data, expand-up, writable
482 .byte 0x0CF # page-granular, 32-bit
483 .byte 0
484
485 # linear code segment descriptor
486 LINEAR_CODE_SEL = .-GDT_BASE
487 .short 0x0FFFF # limit 0xFFFFF
488 .short 0 # base 0
489 .byte 0
490 .byte 0x09A # present, ring 0, data, expand-up, writable
491 .byte 0x0CF # page-granular, 32-bit
492 .byte 0
493
494 # system data segment descriptor
495 SYS_DATA_SEL = .-GDT_BASE
496 .short 0x0FFFF # limit 0xFFFFF
497 .short 0 # base 0
498 .byte 0
499 .byte 0x092 # present, ring 0, data, expand-up, writable
500 .byte 0x0CF # page-granular, 32-bit
501 .byte 0
502
503 # system code segment descriptor
504 SYS_CODE_SEL = .-GDT_BASE
505 .short 0x0FFFF # limit 0xFFFFF
506 .short 0 # base 0
507 .byte 0
508 .byte 0x09A # present, ring 0, data, expand-up, writable
509 .byte 0x0CF # page-granular, 32-bit
510 .byte 0
511
512 # spare segment descriptor
513 SPARE3_SEL = .-GDT_BASE
514 .short 0 # limit 0xFFFFF
515 .short 0 # base 0
516 .byte 0
517 .byte 0 # present, ring 0, data, expand-up, writable
518 .byte 0 # page-granular, 32-bit
519 .byte 0
520
521 # spare segment descriptor
522 SPARE4_SEL = .-GDT_BASE
523 .short 0 # limit 0xFFFFF
524 .short 0 # base 0
525 .byte 0
526 .byte 0 # present, ring 0, data, expand-up, writable
527 .byte 0 # page-granular, 32-bit
528 .byte 0
529
530 # spare segment descriptor
531 SPARE5_SEL = .-GDT_BASE
532 .short 0 # limit 0xFFFFF
533 .short 0 # base 0
534 .byte 0
535 .byte 0 # present, ring 0, data, expand-up, writable
536 .byte 0 # page-granular, 32-bit
537 .byte 0
538
539 GDT_END:
540
541 .align 0x4
542
543
544
545 idtr: .short IDT_END - IDT_BASE - 1 # IDT limit
546 .quad 0 # (IDT base gets set above)
547 ##############################################################################
548 # interrupt descriptor table (IDT)
549 #
550 # Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
551 # mappings. This implementation only uses the system timer and all other
552 # IRQs will remain masked. The descriptors for vectors 33+ are provided
553 # for convenience.
554 ##############################################################################
555
556 #idt_tag .byte "IDT",0
557 .align 0x4
558
559 IDT_BASE:
560 # divide by zero (INT 0)
561 DIV_ZERO_SEL = .-IDT_BASE
562 .short 0 # offset 15:0
563 .short SYS_CODE_SEL # selector 15:0
564 .byte 0 # 0 for interrupt gate
565 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
566 .short 0 # offset 31:16
567
568 # debug exception (INT 1)
569 DEBUG_EXCEPT_SEL = .-IDT_BASE
570 .short 0 # offset 15:0
571 .short SYS_CODE_SEL # selector 15:0
572 .byte 0 # 0 for interrupt gate
573 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
574 .short 0 # offset 31:16
575
576 # NMI (INT 2)
577 NMI_SEL = .-IDT_BASE
578 .short 0 # offset 15:0
579 .short SYS_CODE_SEL # selector 15:0
580 .byte 0 # 0 for interrupt gate
581 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
582 .short 0 # offset 31:16
583
584 # soft breakpoint (INT 3)
585 BREAKPOINT_SEL = .-IDT_BASE
586 .short 0 # offset 15:0
587 .short SYS_CODE_SEL # selector 15:0
588 .byte 0 # 0 for interrupt gate
589 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
590 .short 0 # offset 31:16
591
592 # overflow (INT 4)
593 OVERFLOW_SEL = .-IDT_BASE
594 .short 0 # offset 15:0
595 .short SYS_CODE_SEL # selector 15:0
596 .byte 0 # 0 for interrupt gate
597 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
598 .short 0 # offset 31:16
599
600 # bounds check (INT 5)
601 BOUNDS_CHECK_SEL = .-IDT_BASE
602 .short 0 # offset 15:0
603 .short SYS_CODE_SEL # selector 15:0
604 .byte 0 # 0 for interrupt gate
605 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
606 .short 0 # offset 31:16
607
608 # invalid opcode (INT 6)
609 INVALID_OPCODE_SEL = .-IDT_BASE
610 .short 0 # offset 15:0
611 .short SYS_CODE_SEL # selector 15:0
612 .byte 0 # 0 for interrupt gate
613 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
614 .short 0 # offset 31:16
615
616 # device not available (INT 7)
617 DEV_NOT_AVAIL_SEL = .-IDT_BASE
618 .short 0 # offset 15:0
619 .short SYS_CODE_SEL # selector 15:0
620 .byte 0 # 0 for interrupt gate
621 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
622 .short 0 # offset 31:16
623
624 # double fault (INT 8)
625 DOUBLE_FAULT_SEL = .-IDT_BASE
626 .short 0 # offset 15:0
627 .short SYS_CODE_SEL # selector 15:0
628 .byte 0 # 0 for interrupt gate
629 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
630 .short 0 # offset 31:16
631
632 # Coprocessor segment overrun - reserved (INT 9)
633 RSVD_INTR_SEL1 = .-IDT_BASE
634 .short 0 # offset 15:0
635 .short SYS_CODE_SEL # selector 15:0
636 .byte 0 # 0 for interrupt gate
637 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
638 .short 0 # offset 31:16
639
640 # invalid TSS (INT 0ah)
641 INVALID_TSS_SEL = .-IDT_BASE
642 .short 0 # offset 15:0
643 .short SYS_CODE_SEL # selector 15:0
644 .byte 0 # 0 for interrupt gate
645 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
646 .short 0 # offset 31:16
647
648 # segment not present (INT 0bh)
649 SEG_NOT_PRESENT_SEL = .-IDT_BASE
650 .short 0 # offset 15:0
651 .short SYS_CODE_SEL # selector 15:0
652 .byte 0 # 0 for interrupt gate
653 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
654 .short 0 # offset 31:16
655
656 # stack fault (INT 0ch)
657 STACK_FAULT_SEL = .-IDT_BASE
658 .short 0 # offset 15:0
659 .short SYS_CODE_SEL # selector 15:0
660 .byte 0 # 0 for interrupt gate
661 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
662 .short 0 # offset 31:16
663
664 # general protection (INT 0dh)
665 GP_FAULT_SEL = .-IDT_BASE
666 .short 0 # offset 15:0
667 .short SYS_CODE_SEL # selector 15:0
668 .byte 0 # 0 for interrupt gate
669 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
670 .short 0 # offset 31:16
671
672 # page fault (INT 0eh)
673 PAGE_FAULT_SEL = .-IDT_BASE
674 .short 0 # offset 15:0
675 .short SYS_CODE_SEL # selector 15:0
676 .byte 0 # 0 for interrupt gate
677 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
678 .short 0 # offset 31:16
679
680 # Intel reserved - do not use (INT 0fh)
681 RSVD_INTR_SEL2 = .-IDT_BASE
682 .short 0 # offset 15:0
683 .short SYS_CODE_SEL # selector 15:0
684 .byte 0 # 0 for interrupt gate
685 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
686 .short 0 # offset 31:16
687
688 # floating point error (INT 0x10)
689 FLT_POINT_ERR_SEL = .-IDT_BASE
690 .short 0 # offset 15:0
691 .short SYS_CODE_SEL # selector 15:0
692 .byte 0 # 0 for interrupt gate
693 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
694 .short 0 # offset 31:16
695
696 # alignment check (INT 0x11)
697 ALIGNMENT_CHECK_SEL = .-IDT_BASE
698 .short 0 # offset 15:0
699 .short SYS_CODE_SEL # selector 15:0
700 .byte 0 # 0 for interrupt gate
701 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
702 .short 0 # offset 31:16
703
704 # machine check (INT 0x12)
705 MACHINE_CHECK_SEL = .-IDT_BASE
706 .short 0 # offset 15:0
707 .short SYS_CODE_SEL # selector 15:0
708 .byte 0 # 0 for interrupt gate
709 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
710 .short 0 # offset 31:16
711
712 # SIMD floating-point exception (INT 0x13)
713 SIMD_EXCEPTION_SEL = .-IDT_BASE
714 .short 0 # offset 15:0
715 .short SYS_CODE_SEL # selector 15:0
716 .byte 0 # 0 for interrupt gate
717 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
718 .short 0 # offset 31:16
719
720 .rept (32 - 20)
721 .short 0 # offset 15:0
722 .short SYS_CODE_SEL # selector 15:0
723 .byte 0 # 0 for interrupt gate
724 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
725 .short 0 # offset 31:16
726 .endr
727
728 # 72 unspecified descriptors
729 .rept 72 * 8
730 .byte 0
731 .endr
732
733 # IRQ 0 (System timer) - (INT 0x68)
734 IRQ0_SEL = .-IDT_BASE
735 .short 0 # offset 15:0
736 .short SYS_CODE_SEL # selector 15:0
737 .byte 0 # 0 for interrupt gate
738 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
739 .short 0 # offset 31:16
740
741 # IRQ 1 (8042 Keyboard controller) - (INT 0x69)
742 IRQ1_SEL = .-IDT_BASE
743 .short 0 # offset 15:0
744 .short SYS_CODE_SEL # selector 15:0
745 .byte 0 # 0 for interrupt gate
746 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
747 .short 0 # offset 31:16
748
749 # Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
750 IRQ2_SEL = .-IDT_BASE
751 .short 0 # offset 15:0
752 .short SYS_CODE_SEL # selector 15:0
753 .byte 0 # 0 for interrupt gate
754 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
755 .short 0 # offset 31:16
756
757 # IRQ 3 (COM 2) - (INT 6bh)
758 IRQ3_SEL = .-IDT_BASE
759 .short 0 # offset 15:0
760 .short SYS_CODE_SEL # selector 15:0
761 .byte 0 # 0 for interrupt gate
762 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
763 .short 0 # offset 31:16
764
765 # IRQ 4 (COM 1) - (INT 6ch)
766 IRQ4_SEL = .-IDT_BASE
767 .short 0 # offset 15:0
768 .short SYS_CODE_SEL # selector 15:0
769 .byte 0 # 0 for interrupt gate
770 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
771 .short 0 # offset 31:16
772
773 # IRQ 5 (LPT 2) - (INT 6dh)
774 IRQ5_SEL = .-IDT_BASE
775 .short 0 # offset 15:0
776 .short SYS_CODE_SEL # selector 15:0
777 .byte 0 # 0 for interrupt gate
778 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
779 .short 0 # offset 31:16
780
781 # IRQ 6 (Floppy controller) - (INT 6eh)
782 IRQ6_SEL = .-IDT_BASE
783 .short 0 # offset 15:0
784 .short SYS_CODE_SEL # selector 15:0
785 .byte 0 # 0 for interrupt gate
786 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
787 .short 0 # offset 31:16
788
789 # IRQ 7 (LPT 1) - (INT 6fh)
790 IRQ7_SEL = .-IDT_BASE
791 .short 0 # offset 15:0
792 .short SYS_CODE_SEL # selector 15:0
793 .byte 0 # 0 for interrupt gate
794 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
795 .short 0 # offset 31:16
796
797 # IRQ 8 (RTC Alarm) - (INT 0x70)
798 IRQ8_SEL = .-IDT_BASE
799 .short 0 # offset 15:0
800 .short SYS_CODE_SEL # selector 15:0
801 .byte 0 # 0 for interrupt gate
802 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
803 .short 0 # offset 31:16
804
805 # IRQ 9 - (INT 0x71)
806 IRQ9_SEL = .-IDT_BASE
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
813 # IRQ 10 - (INT 0x72)
814 IRQ10_SEL = .-IDT_BASE
815 .short 0 # offset 15:0
816 .short SYS_CODE_SEL # selector 15:0
817 .byte 0 # 0 for interrupt gate
818 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
819 .short 0 # offset 31:16
820
821 # IRQ 11 - (INT 0x73)
822 IRQ11_SEL = .-IDT_BASE
823 .short 0 # offset 15:0
824 .short SYS_CODE_SEL # selector 15:0
825 .byte 0 # 0 for interrupt gate
826 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
827 .short 0 # offset 31:16
828
829 # IRQ 12 (PS/2 mouse) - (INT 0x74)
830 IRQ12_SEL = .-IDT_BASE
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
837 # IRQ 13 (Floating point error) - (INT 0x75)
838 IRQ13_SEL = .-IDT_BASE
839 .short 0 # offset 15:0
840 .short SYS_CODE_SEL # selector 15:0
841 .byte 0 # 0 for interrupt gate
842 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
843 .short 0 # offset 31:16
844
845 # IRQ 14 (Secondary IDE) - (INT 0x76)
846 IRQ14_SEL = .-IDT_BASE
847 .short 0 # offset 15:0
848 .short SYS_CODE_SEL # selector 15:0
849 .byte 0 # 0 for interrupt gate
850 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
851 .short 0 # offset 31:16
852
853 # IRQ 15 (Primary IDE) - (INT 0x77)
854 IRQ15_SEL = .-IDT_BASE
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 .rept 1 * 16
862 .byte 0
863 .endr
864
865 IDT_END:
866