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