]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/BootSector/start32.asm
Porting Duet module from EDKI to EDKII
[mirror_edk2.git] / DuetPkg / BootSector / start32.asm
1 ;------------------------------------------------------------------------------
2 ;*
3 ;* Copyright 2006 - 2007, 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 ;* start32.asm
13 ;*
14 ;* Abstract:
15 ;*
16 ;------------------------------------------------------------------------------
17
18 .model small
19 .stack
20 .486p
21 .code
22
23 FAT_DIRECTORY_ENTRY_SIZE EQU 020h
24 FAT_DIRECTORY_ENTRY_SHIFT EQU 5
25 BLOCK_SIZE EQU 0200h
26 BLOCK_MASK EQU 01ffh
27 BLOCK_SHIFT EQU 9
28
29 org 0h
30 Ia32Jump:
31 jmp BootSectorEntryPoint ; JMP inst - 3 bytes
32 nop
33
34 OemId db "INTEL " ; OemId - 8 bytes
35 SectorSize dw 0 ; Sector Size - 2 bytes
36 SectorsPerCluster db 0 ; Sector Per Cluster - 1 byte
37 ReservedSectors dw 0 ; Reserved Sectors - 2 bytes
38 NoFats db 0 ; Number of FATs - 1 byte
39 RootEntries dw 0 ; Root Entries - 2 bytes
40 Sectors dw 0 ; Number of Sectors - 2 bytes
41 Media db 0 ; Media - 1 byte
42 SectorsPerFat16 dw 0 ; Sectors Per FAT for FAT12/FAT16 - 2 byte
43 SectorsPerTrack dw 0 ; Sectors Per Track - 2 bytes
44 Heads dw 0 ; Heads - 2 bytes
45 HiddenSectors dd 0 ; Hidden Sectors - 4 bytes
46 LargeSectors dd 0 ; Large Sectors - 4 bytes
47
48 ;******************************************************************************
49 ;
50 ;The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
51 ;the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
52 ;
53 ;******************************************************************************
54
55 SectorsPerFat32 dd 0 ; Sectors Per FAT for FAT32 - 4 bytes
56 ExtFlags dw 0 ; Mirror Flag - 2 bytes
57 FSVersion dw 0 ; File System Version - 2 bytes
58 RootCluster dd 0 ; 1st Cluster Number of Root Dir - 4 bytes
59 FSInfo dw 0 ; Sector Number of FSINFO - 2 bytes
60 BkBootSector dw 0 ; Sector Number of Bk BootSector - 2 bytes
61 Reserved db 12 dup(0) ; Reserved Field - 12 bytes
62 PhysicalDrive db 0 ; Physical Drive Number - 1 byte
63 Reserved1 db 0 ; Reserved Field - 1 byte
64 Signature db 0 ; Extended Boot Signature - 1 byte
65 VolId db " " ; Volume Serial Number - 4 bytes
66 FatLabel db " " ; Volume Label - 11 bytes
67 FileSystemType db "FAT32 " ; File System Type - 8 bytes
68
69 BootSectorEntryPoint:
70 ASSUME ds:@code
71 ASSUME ss:@code
72 ; ds = 1000, es = 2000 + x (size of first cluster >> 4)
73 ; cx = Start Cluster of EfiLdr
74 ; dx = Start Cluster of Efivar.bin
75
76 ; Re use the BPB data stored in Boot Sector
77 mov bp,07c00h
78
79
80 push cx
81 ; Read Efivar.bin
82 ; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
83 mov ax,01900h
84 mov es,ax
85 test dx,dx
86 jnz CheckVarStoreSize
87
88 mov al,1
89 NoVarStore:
90 push es
91 ; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
92 mov byte ptr es:[4],al
93 jmp SaveVolumeId
94
95 CheckVarStoreSize:
96 mov di,dx
97 cmp dword ptr ds:[di+2], 04000h
98 mov al,2
99 jne NoVarStore
100
101 LoadVarStore:
102 mov al,0
103 mov byte ptr es:[4],al
104 mov cx,word ptr[di]
105 ; ES:DI = 1500:0
106 xor di,di
107 push es
108 mov ax,01500h
109 mov es,ax
110 call ReadFile
111 SaveVolumeId:
112 pop es
113 mov ax,word ptr [bp+VolId]
114 mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
115 mov ax,word ptr [bp+VolId+2]
116 mov word ptr es:[2],ax
117
118 ; Read Efildr
119 pop cx
120 ; cx = Start Cluster of Efildr -> BS.com has filled already
121 ; ES:DI = 2000:0, first cluster will be read again
122 xor di,di ; di = 0
123 mov ax,02000h
124 mov es,ax
125 call ReadFile
126 mov ax,cs
127 mov word ptr cs:[JumpSegment],ax
128 JumpFarInstruction:
129 db 0eah
130 JumpOffset:
131 dw 0200h
132 JumpSegment:
133 dw 2000h
134
135
136
137
138 ; ****************************************************************************
139 ; ReadFile
140 ;
141 ; Arguments:
142 ; CX = Start Cluster of File
143 ; ES:DI = Buffer to store file content read from disk
144 ;
145 ; Return:
146 ; (ES << 4 + DI) = end of file content Buffer
147 ;
148 ; ****************************************************************************
149 ReadFile:
150 ; si = NumberOfClusters
151 ; cx = ClusterNumber
152 ; dx = CachedFatSectorNumber
153 ; ds:0000 = CacheFatSectorBuffer
154 ; es:di = Buffer to load file
155 ; bx = NextClusterNumber
156 pusha
157 mov si,1 ; NumberOfClusters = 1
158 push cx ; Push Start Cluster onto stack
159 mov dx,0fffh ; CachedFatSectorNumber = 0xfff
160 FatChainLoop:
161 mov ax,cx ; ax = ClusterNumber
162 and ax,0fff8h ; ax = ax & 0xfff8
163 cmp ax,0fff8h ; See if this is the last cluster
164 je FoundLastCluster ; Jump if last cluster found
165 mov ax,cx ; ax = ClusterNumber
166 shl ax,2 ; FatOffset = ClusterNumber * 4
167 push si ; Save si
168 mov si,ax ; si = FatOffset
169 shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
170 add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
171 and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
172 cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
173 je SkipFatRead
174 mov bx,2
175 push es
176 push ds
177 pop es
178 call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
179 pop es
180 mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
181 SkipFatRead:
182 mov bx,word ptr [si] ; bx = NextClusterNumber
183 mov ax,cx ; ax = ClusterNumber
184 pop si ; Restore si
185 dec bx ; bx = NextClusterNumber - 1
186 cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
187 jne ReadClusters
188 inc bx ; bx = NextClusterNumber
189 inc si ; NumberOfClusters++
190 mov cx,bx ; ClusterNumber = NextClusterNumber
191 jmp FatChainLoop
192 ReadClusters:
193 inc bx
194 pop ax ; ax = StartCluster
195 push bx ; StartCluster = NextClusterNumber
196 mov cx,bx ; ClusterNumber = NextClusterNumber
197 sub ax,2 ; ax = StartCluster - 2
198 xor bh,bh
199 mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
200 mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
201 add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
202 push ax ; save start sector
203 mov ax,si ; ax = NumberOfClusters
204 mul bx ; ax = NumberOfClusters * SectorsPerCluster
205 mov bx,ax ; bx = Number of Sectors
206 pop ax ; ax = Start Sector
207 call ReadBlocks
208 mov si,1 ; NumberOfClusters = 1
209 jmp FatChainLoop
210 FoundLastCluster:
211 pop cx
212 popa
213 ret
214
215
216 ; ****************************************************************************
217 ; ReadBlocks - Reads a set of blocks from a block device
218 ;
219 ; AX = Start LBA
220 ; BX = Number of Blocks to Read
221 ; ES:DI = Buffer to store sectors read from disk
222 ; ****************************************************************************
223
224 ; cx = Blocks
225 ; bx = NumberOfBlocks
226 ; si = StartLBA
227
228 ReadBlocks:
229 pusha
230 add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
231 add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
232 mov esi,eax ; esi = Start LBA
233 mov cx,bx ; cx = Number of blocks to read
234 ReadCylinderLoop:
235 mov bp,07bfch ; bp = 0x7bfc
236 mov eax,esi ; eax = Start LBA
237 xor edx,edx ; edx = 0
238 movzx ebx,word ptr [bp] ; bx = MaxSector
239 div ebx ; ax = StartLBA / MaxSector
240 inc dx ; dx = (StartLBA % MaxSector) + 1
241
242 mov bx,word ptr [bp] ; bx = MaxSector
243 sub bx,dx ; bx = MaxSector - Sector
244 inc bx ; bx = MaxSector - Sector + 1
245 cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
246 jg LimitTransfer
247 mov bx,cx ; bx = Blocks
248 LimitTransfer:
249 push ax ; save ax
250 mov ax,es ; ax = es
251 shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
252 and ax,07fh ; ax = Number of blocks into current seg
253 add ax,bx ; ax = End Block number of transfer
254 cmp ax,080h ; See if it crosses a 64K boundry
255 jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
256 sub ax,080h ; ax = Number of blocks past 64K boundry
257 sub bx,ax ; Decrease transfer size by block overage
258 NotCrossing64KBoundry:
259 pop ax ; restore ax
260
261 push cx
262 mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
263 xor dx,dx ; dx = 0
264 div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
265 ; dx = ax % (MaxHead + 1) = Head
266
267 push bx ; Save number of blocks to transfer
268 mov dh,dl ; dh = Head
269 mov bp,07c00h ; bp = 0x7c00
270 mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
271 mov ch,al ; ch = Cylinder
272 mov al,bl ; al = Blocks
273 mov ah,2 ; ah = Function 2
274 mov bx,di ; es:bx = Buffer address
275 int 013h
276 jc DiskError
277 pop bx
278 pop cx
279 movzx ebx,bx
280 add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
281 sub cx,bx ; Blocks = Blocks - NumberOfBlocks
282 mov ax,es
283 shl bx,(BLOCK_SHIFT-4)
284 add ax,bx
285 mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
286 cmp cx,0
287 jne ReadCylinderLoop
288 popa
289 ret
290
291 DiskError:
292 push cs
293 pop ds
294 lea si, [ErrorString]
295 mov cx, 7
296 jmp PrintStringAndHalt
297
298 PrintStringAndHalt:
299 mov ax,0b800h
300 mov es,ax
301 mov di,160
302 rep movsw
303 Halt:
304 jmp Halt
305
306 ErrorString:
307 db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
308
309 org 01fah
310 LBAOffsetForBootSector:
311 dd 0h
312
313 org 01feh
314 dw 0aa55h
315
316 ;******************************************************************************
317 ;******************************************************************************
318 ;******************************************************************************
319
320 DELAY_PORT equ 0edh ; Port to use for 1uS delay
321 KBD_CONTROL_PORT equ 060h ; 8042 control port
322 KBD_STATUS_PORT equ 064h ; 8042 status port
323 WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
324 ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
325
326 org 200h
327 jmp start
328 Em64String:
329 db 'E', 0ch, 'm', 0ch, '6', 0ch, '4', 0ch, 'T', 0ch, ' ', 0ch, 'U', 0ch, 'n', 0ch, 's', 0ch, 'u', 0ch, 'p', 0ch, 'p', 0ch, 'o', 0ch, 'r', 0ch, 't', 0ch, 'e', 0ch, 'd', 0ch, '!', 0ch
330
331 start:
332 mov ax,cs
333 mov ds,ax
334 mov es,ax
335 mov ss,ax
336 mov sp,MyStack
337
338 ; mov ax,0b800h
339 ; mov es,ax
340 ; mov byte ptr es:[160],'a'
341 ; mov ax,cs
342 ; mov es,ax
343
344 mov ebx,0
345 lea edi,MemoryMap
346 MemMapLoop:
347 mov eax,0e820h
348 mov ecx,20
349 mov edx,'SMAP'
350 int 15h
351 jc MemMapDone
352 add edi,20
353 cmp ebx,0
354 je MemMapDone
355 jmp MemMapLoop
356 MemMapDone:
357 lea eax,MemoryMap
358 sub edi,eax ; Get the address of the memory map
359 mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
360
361 xor ebx,ebx
362 mov bx,cs ; BX=segment
363 shl ebx,4 ; BX="linear" address of segment base
364 lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
365 mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
366 lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
367 mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
368 lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
369
370 add ebx,01000h ; Source of EFI32
371 mov dword ptr [JUMP+2],ebx
372 add ebx,01000h
373 mov esi,ebx ; Source of EFILDR32
374
375 ; mov ax,0b800h
376 ; mov es,ax
377 ; mov byte ptr es:[162],'b'
378 ; mov ax,cs
379 ; mov es,ax
380
381 ;
382 ; Enable A20 Gate
383 ;
384
385 mov ax,2401h ; Enable A20 Gate
386 int 15h
387 jnc A20GateEnabled ; Jump if it suceeded
388
389 ;
390 ; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
391 ;
392
393 call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
394 jnz Timeout8042 ; Jump if the 8042 timed out
395 out DELAY_PORT,ax ; Delay 1 uS
396 mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
397 out KBD_STATUS_PORT,al ; Send command to the 8042
398 call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
399 jnz Timeout8042 ; Jump if the 8042 timed out
400 mov al,ENABLE_A20_CMD ; gate address bit 20 on
401 out KBD_CONTROL_PORT,al ; Send command to thre 8042
402 call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
403 mov cx,25 ; Delay 25 uS for the command to complete on the 8042
404 Delay25uS:
405 out DELAY_PORT,ax ; Delay 1 uS
406 loop Delay25uS
407 Timeout8042:
408
409
410 A20GateEnabled:
411
412 ;
413 ; DISABLE INTERRUPTS - Entering Protected Mode
414 ;
415
416 cli
417
418 ; mov ax,0b800h
419 ; mov es,ax
420 ; mov byte ptr es:[164],'c'
421 ; mov ax,cs
422 ; mov es,ax
423
424 db 66h
425 lgdt fword ptr [gdtr]
426 db 66h
427 lidt fword ptr [idtr]
428
429 mov eax,cr0
430 or al,1
431 mov cr0,eax
432
433 mov eax,0008h ; Flat data descriptor
434 mov ebp,000400000h ; Destination of EFILDR32
435 mov ebx,000070000h ; Length of copy
436
437 JUMP:
438 ; jmp far 0010:00020000
439 db 066h
440 db 0eah
441 dd 000020000h
442 dw 00010h
443
444 Empty8042InputBuffer:
445 mov cx,0
446 Empty8042Loop:
447 out DELAY_PORT,ax ; Delay 1us
448 in al,KBD_STATUS_PORT ; Read the 8042 Status Port
449 and al,02h ; Check the Input Buffer Full Flag
450 loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
451 ret
452
453 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
454 ; data
455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
456
457 align 02h
458
459 gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
460 dd 0 ; (GDT base gets set above)
461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
462 ; global descriptor table (GDT)
463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
464
465 align 02h
466
467 public GDT_BASE
468 GDT_BASE:
469 ; null descriptor
470 NULL_SEL equ $-GDT_BASE
471 dw 0 ; limit 15:0
472 dw 0 ; base 15:0
473 db 0 ; base 23:16
474 db 0 ; type
475 db 0 ; limit 19:16, flags
476 db 0 ; base 31:24
477
478 ; linear data segment descriptor
479 LINEAR_SEL equ $-GDT_BASE
480 dw 0FFFFh ; limit 0xFFFFF
481 dw 0 ; base 0
482 db 0
483 db 092h ; present, ring 0, data, expand-up, writable
484 db 0CFh ; page-granular, 32-bit
485 db 0
486
487 ; linear code segment descriptor
488 LINEAR_CODE_SEL equ $-GDT_BASE
489 dw 0FFFFh ; limit 0xFFFFF
490 dw 0 ; base 0
491 db 0
492 db 09Ah ; present, ring 0, data, expand-up, writable
493 db 0CFh ; page-granular, 32-bit
494 db 0
495
496 ; system data segment descriptor
497 SYS_DATA_SEL equ $-GDT_BASE
498 dw 0FFFFh ; limit 0xFFFFF
499 dw 0 ; base 0
500 db 0
501 db 092h ; present, ring 0, data, expand-up, writable
502 db 0CFh ; page-granular, 32-bit
503 db 0
504
505 ; system code segment descriptor
506 SYS_CODE_SEL equ $-GDT_BASE
507 dw 0FFFFh ; limit 0xFFFFF
508 dw 0 ; base 0
509 db 0
510 db 09Ah ; present, ring 0, data, expand-up, writable
511 db 0CFh ; page-granular, 32-bit
512 db 0
513
514 ; spare segment descriptor
515 SPARE3_SEL equ $-GDT_BASE
516 dw 0 ; limit 0xFFFFF
517 dw 0 ; base 0
518 db 0
519 db 0 ; present, ring 0, data, expand-up, writable
520 db 0 ; page-granular, 32-bit
521 db 0
522
523 ; spare segment descriptor
524 SPARE4_SEL equ $-GDT_BASE
525 dw 0 ; limit 0xFFFFF
526 dw 0 ; base 0
527 db 0
528 db 0 ; present, ring 0, data, expand-up, writable
529 db 0 ; page-granular, 32-bit
530 db 0
531
532 ; spare segment descriptor
533 SPARE5_SEL equ $-GDT_BASE
534 dw 0 ; limit 0xFFFFF
535 dw 0 ; base 0
536 db 0
537 db 0 ; present, ring 0, data, expand-up, writable
538 db 0 ; page-granular, 32-bit
539 db 0
540
541 GDT_END:
542
543 align 02h
544
545
546
547 idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
548 dd 0 ; (IDT base gets set above)
549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
550 ; interrupt descriptor table (IDT)
551 ;
552 ; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
553 ; mappings. This implementation only uses the system timer and all other
554 ; IRQs will remain masked. The descriptors for vectors 33+ are provided
555 ; for convenience.
556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
557
558 ;idt_tag db "IDT",0
559 align 02h
560
561 public IDT_BASE
562 IDT_BASE:
563 ; divide by zero (INT 0)
564 DIV_ZERO_SEL equ $-IDT_BASE
565 dw 0 ; offset 15:0
566 dw SYS_CODE_SEL ; selector 15:0
567 db 0 ; 0 for interrupt gate
568 db 0eh OR 80h ; type = 386 interrupt gate, present
569 dw 0 ; offset 31:16
570
571 ; debug exception (INT 1)
572 DEBUG_EXCEPT_SEL equ $-IDT_BASE
573 dw 0 ; offset 15:0
574 dw SYS_CODE_SEL ; selector 15:0
575 db 0 ; 0 for interrupt gate
576 db 0eh OR 80h ; type = 386 interrupt gate, present
577 dw 0 ; offset 31:16
578
579 ; NMI (INT 2)
580 NMI_SEL equ $-IDT_BASE
581 dw 0 ; offset 15:0
582 dw SYS_CODE_SEL ; selector 15:0
583 db 0 ; 0 for interrupt gate
584 db 0eh OR 80h ; type = 386 interrupt gate, present
585 dw 0 ; offset 31:16
586
587 ; soft breakpoint (INT 3)
588 BREAKPOINT_SEL equ $-IDT_BASE
589 dw 0 ; offset 15:0
590 dw SYS_CODE_SEL ; selector 15:0
591 db 0 ; 0 for interrupt gate
592 db 0eh OR 80h ; type = 386 interrupt gate, present
593 dw 0 ; offset 31:16
594
595 ; overflow (INT 4)
596 OVERFLOW_SEL equ $-IDT_BASE
597 dw 0 ; offset 15:0
598 dw SYS_CODE_SEL ; selector 15:0
599 db 0 ; 0 for interrupt gate
600 db 0eh OR 80h ; type = 386 interrupt gate, present
601 dw 0 ; offset 31:16
602
603 ; bounds check (INT 5)
604 BOUNDS_CHECK_SEL equ $-IDT_BASE
605 dw 0 ; offset 15:0
606 dw SYS_CODE_SEL ; selector 15:0
607 db 0 ; 0 for interrupt gate
608 db 0eh OR 80h ; type = 386 interrupt gate, present
609 dw 0 ; offset 31:16
610
611 ; invalid opcode (INT 6)
612 INVALID_OPCODE_SEL equ $-IDT_BASE
613 dw 0 ; offset 15:0
614 dw SYS_CODE_SEL ; selector 15:0
615 db 0 ; 0 for interrupt gate
616 db 0eh OR 80h ; type = 386 interrupt gate, present
617 dw 0 ; offset 31:16
618
619 ; device not available (INT 7)
620 DEV_NOT_AVAIL_SEL equ $-IDT_BASE
621 dw 0 ; offset 15:0
622 dw SYS_CODE_SEL ; selector 15:0
623 db 0 ; 0 for interrupt gate
624 db 0eh OR 80h ; type = 386 interrupt gate, present
625 dw 0 ; offset 31:16
626
627 ; double fault (INT 8)
628 DOUBLE_FAULT_SEL equ $-IDT_BASE
629 dw 0 ; offset 15:0
630 dw SYS_CODE_SEL ; selector 15:0
631 db 0 ; 0 for interrupt gate
632 db 0eh OR 80h ; type = 386 interrupt gate, present
633 dw 0 ; offset 31:16
634
635 ; Coprocessor segment overrun - reserved (INT 9)
636 RSVD_INTR_SEL1 equ $-IDT_BASE
637 dw 0 ; offset 15:0
638 dw SYS_CODE_SEL ; selector 15:0
639 db 0 ; 0 for interrupt gate
640 db 0eh OR 80h ; type = 386 interrupt gate, present
641 dw 0 ; offset 31:16
642
643 ; invalid TSS (INT 0ah)
644 INVALID_TSS_SEL equ $-IDT_BASE
645 dw 0 ; offset 15:0
646 dw SYS_CODE_SEL ; selector 15:0
647 db 0 ; 0 for interrupt gate
648 db 0eh OR 80h ; type = 386 interrupt gate, present
649 dw 0 ; offset 31:16
650
651 ; segment not present (INT 0bh)
652 SEG_NOT_PRESENT_SEL equ $-IDT_BASE
653 dw 0 ; offset 15:0
654 dw SYS_CODE_SEL ; selector 15:0
655 db 0 ; 0 for interrupt gate
656 db 0eh OR 80h ; type = 386 interrupt gate, present
657 dw 0 ; offset 31:16
658
659 ; stack fault (INT 0ch)
660 STACK_FAULT_SEL equ $-IDT_BASE
661 dw 0 ; offset 15:0
662 dw SYS_CODE_SEL ; selector 15:0
663 db 0 ; 0 for interrupt gate
664 db 0eh OR 80h ; type = 386 interrupt gate, present
665 dw 0 ; offset 31:16
666
667 ; general protection (INT 0dh)
668 GP_FAULT_SEL equ $-IDT_BASE
669 dw 0 ; offset 15:0
670 dw SYS_CODE_SEL ; selector 15:0
671 db 0 ; 0 for interrupt gate
672 db 0eh OR 80h ; type = 386 interrupt gate, present
673 dw 0 ; offset 31:16
674
675 ; page fault (INT 0eh)
676 PAGE_FAULT_SEL equ $-IDT_BASE
677 dw 0 ; offset 15:0
678 dw SYS_CODE_SEL ; selector 15:0
679 db 0 ; 0 for interrupt gate
680 db 0eh OR 80h ; type = 386 interrupt gate, present
681 dw 0 ; offset 31:16
682
683 ; Intel reserved - do not use (INT 0fh)
684 RSVD_INTR_SEL2 equ $-IDT_BASE
685 dw 0 ; offset 15:0
686 dw SYS_CODE_SEL ; selector 15:0
687 db 0 ; 0 for interrupt gate
688 db 0eh OR 80h ; type = 386 interrupt gate, present
689 dw 0 ; offset 31:16
690
691 ; floating point error (INT 10h)
692 FLT_POINT_ERR_SEL equ $-IDT_BASE
693 dw 0 ; offset 15:0
694 dw SYS_CODE_SEL ; selector 15:0
695 db 0 ; 0 for interrupt gate
696 db 0eh OR 80h ; type = 386 interrupt gate, present
697 dw 0 ; offset 31:16
698
699 ; alignment check (INT 11h)
700 ALIGNMENT_CHECK_SEL equ $-IDT_BASE
701 dw 0 ; offset 15:0
702 dw SYS_CODE_SEL ; selector 15:0
703 db 0 ; 0 for interrupt gate
704 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
705 dw 0 ; offset 31:16
706
707 ; machine check (INT 12h)
708 MACHINE_CHECK_SEL equ $-IDT_BASE
709 dw 0 ; offset 15:0
710 dw SYS_CODE_SEL ; selector 15:0
711 db 0 ; 0 for interrupt gate
712 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
713 dw 0 ; offset 31:16
714
715 ; SIMD floating-point exception (INT 13h)
716 SIMD_EXCEPTION_SEL equ $-IDT_BASE
717 dw 0 ; offset 15:0
718 dw SYS_CODE_SEL ; selector 15:0
719 db 0 ; 0 for interrupt gate
720 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
721 dw 0 ; offset 31:16
722
723 ; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
724 db (85 * 8) dup(0)
725
726 ; IRQ 0 (System timer) - (INT 68h)
727 IRQ0_SEL equ $-IDT_BASE
728 dw 0 ; offset 15:0
729 dw SYS_CODE_SEL ; selector 15:0
730 db 0 ; 0 for interrupt gate
731 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
732 dw 0 ; offset 31:16
733
734 ; IRQ 1 (8042 Keyboard controller) - (INT 69h)
735 IRQ1_SEL equ $-IDT_BASE
736 dw 0 ; offset 15:0
737 dw SYS_CODE_SEL ; selector 15:0
738 db 0 ; 0 for interrupt gate
739 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
740 dw 0 ; offset 31:16
741
742 ; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
743 IRQ2_SEL equ $-IDT_BASE
744 dw 0 ; offset 15:0
745 dw SYS_CODE_SEL ; selector 15:0
746 db 0 ; 0 for interrupt gate
747 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
748 dw 0 ; offset 31:16
749
750 ; IRQ 3 (COM 2) - (INT 6bh)
751 IRQ3_SEL equ $-IDT_BASE
752 dw 0 ; offset 15:0
753 dw SYS_CODE_SEL ; selector 15:0
754 db 0 ; 0 for interrupt gate
755 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
756 dw 0 ; offset 31:16
757
758 ; IRQ 4 (COM 1) - (INT 6ch)
759 IRQ4_SEL equ $-IDT_BASE
760 dw 0 ; offset 15:0
761 dw SYS_CODE_SEL ; selector 15:0
762 db 0 ; 0 for interrupt gate
763 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
764 dw 0 ; offset 31:16
765
766 ; IRQ 5 (LPT 2) - (INT 6dh)
767 IRQ5_SEL equ $-IDT_BASE
768 dw 0 ; offset 15:0
769 dw SYS_CODE_SEL ; selector 15:0
770 db 0 ; 0 for interrupt gate
771 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
772 dw 0 ; offset 31:16
773
774 ; IRQ 6 (Floppy controller) - (INT 6eh)
775 IRQ6_SEL equ $-IDT_BASE
776 dw 0 ; offset 15:0
777 dw SYS_CODE_SEL ; selector 15:0
778 db 0 ; 0 for interrupt gate
779 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
780 dw 0 ; offset 31:16
781
782 ; IRQ 7 (LPT 1) - (INT 6fh)
783 IRQ7_SEL equ $-IDT_BASE
784 dw 0 ; offset 15:0
785 dw SYS_CODE_SEL ; selector 15:0
786 db 0 ; 0 for interrupt gate
787 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
788 dw 0 ; offset 31:16
789
790 ; IRQ 8 (RTC Alarm) - (INT 70h)
791 IRQ8_SEL equ $-IDT_BASE
792 dw 0 ; offset 15:0
793 dw SYS_CODE_SEL ; selector 15:0
794 db 0 ; 0 for interrupt gate
795 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
796 dw 0 ; offset 31:16
797
798 ; IRQ 9 - (INT 71h)
799 IRQ9_SEL equ $-IDT_BASE
800 dw 0 ; offset 15:0
801 dw SYS_CODE_SEL ; selector 15:0
802 db 0 ; 0 for interrupt gate
803 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
804 dw 0 ; offset 31:16
805
806 ; IRQ 10 - (INT 72h)
807 IRQ10_SEL equ $-IDT_BASE
808 dw 0 ; offset 15:0
809 dw SYS_CODE_SEL ; selector 15:0
810 db 0 ; 0 for interrupt gate
811 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
812 dw 0 ; offset 31:16
813
814 ; IRQ 11 - (INT 73h)
815 IRQ11_SEL equ $-IDT_BASE
816 dw 0 ; offset 15:0
817 dw SYS_CODE_SEL ; selector 15:0
818 db 0 ; 0 for interrupt gate
819 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
820 dw 0 ; offset 31:16
821
822 ; IRQ 12 (PS/2 mouse) - (INT 74h)
823 IRQ12_SEL equ $-IDT_BASE
824 dw 0 ; offset 15:0
825 dw SYS_CODE_SEL ; selector 15:0
826 db 0 ; 0 for interrupt gate
827 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
828 dw 0 ; offset 31:16
829
830 ; IRQ 13 (Floating point error) - (INT 75h)
831 IRQ13_SEL equ $-IDT_BASE
832 dw 0 ; offset 15:0
833 dw SYS_CODE_SEL ; selector 15:0
834 db 0 ; 0 for interrupt gate
835 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
836 dw 0 ; offset 31:16
837
838 ; IRQ 14 (Secondary IDE) - (INT 76h)
839 IRQ14_SEL equ $-IDT_BASE
840 dw 0 ; offset 15:0
841 dw SYS_CODE_SEL ; selector 15:0
842 db 0 ; 0 for interrupt gate
843 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
844 dw 0 ; offset 31:16
845
846 ; IRQ 15 (Primary IDE) - (INT 77h)
847 IRQ15_SEL equ $-IDT_BASE
848 dw 0 ; offset 15:0
849 dw SYS_CODE_SEL ; selector 15:0
850 db 0 ; 0 for interrupt gate
851 db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
852 dw 0 ; offset 31:16
853
854 IDT_END:
855
856 align 02h
857
858 MemoryMapSize dd 0
859 MemoryMap dd 0,0,0,0,0,0,0,0
860 dd 0,0,0,0,0,0,0,0
861 dd 0,0,0,0,0,0,0,0
862 dd 0,0,0,0,0,0,0,0
863 dd 0,0,0,0,0,0,0,0
864 dd 0,0,0,0,0,0,0,0
865 dd 0,0,0,0,0,0,0,0
866 dd 0,0,0,0,0,0,0,0
867 dd 0,0,0,0,0,0,0,0
868 dd 0,0,0,0,0,0,0,0
869 dd 0,0,0,0,0,0,0,0
870 dd 0,0,0,0,0,0,0,0
871 dd 0,0,0,0,0,0,0,0
872 dd 0,0,0,0,0,0,0,0
873 dd 0,0,0,0,0,0,0,0
874 dd 0,0,0,0,0,0,0,0
875 dd 0,0,0,0,0,0,0,0
876 dd 0,0,0,0,0,0,0,0
877 dd 0,0,0,0,0,0,0,0
878 dd 0,0,0,0,0,0,0,0
879 dd 0,0,0,0,0,0,0,0
880 dd 0,0,0,0,0,0,0,0
881 dd 0,0,0,0,0,0,0,0
882 dd 0,0,0,0,0,0,0,0
883 dd 0,0,0,0,0,0,0,0
884 dd 0,0,0,0,0,0,0,0
885 dd 0,0,0,0,0,0,0,0
886 dd 0,0,0,0,0,0,0,0
887 dd 0,0,0,0,0,0,0,0
888 dd 0,0,0,0,0,0,0,0
889
890 dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
891 dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
892
893 org 0fe0h
894 MyStack:
895 ; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
896 ; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
897 ; known low address (20f00) so it can be set up by PlMapIrqToVect in
898 ; 8259.c
899
900 int 8
901 iret
902
903 int 9
904 iret
905
906 int 10
907 iret
908
909 int 11
910 iret
911
912 int 12
913 iret
914
915 int 13
916 iret
917
918 int 14
919 iret
920
921 int 15
922 iret
923
924
925 org 0ffeh
926 BlockSignature:
927 dw 0aa55h
928
929 end