]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/BootSector/start.S
Duet X64 still use IA32 tool chain to generate bootsector. So update postbuild.bat...
[mirror_edk2.git] / DuetPkg / BootSector / start.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 #* start.S
13 #*
14 #* Abstract:
15 #*
16 #------------------------------------------------------------------------------
17
18
19
20
21
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
36 SectorSize: .word 0 # Sector Size - 16 bits
37 SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
38 ReservedSectors: .word 0 # Reserved Sectors - 16 bits
39 NoFats: .byte 0 # Number of FATs - 8 bits
40 RootEntries: .word 0 # Root Entries - 16 bits
41 Sectors: .word 0 # Number of Sectors - 16 bits
42 Media: .byte 0 # Media - 8 bits - ignored
43 SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
44 SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
45 Heads: .word 0 # Heads - 16 bits - ignored
46 HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
47 LargeSectors: .long 0 # Large Sectors - 32 bits
48 PhysicalDrive: .byte 0 # PhysicalDriveNumber - 8 bits - ignored
49 CurrentHead: .byte 0 # Current Head - 8 bits
50 Signature: .byte 0 # Signature - 8 bits - ignored
51 VolId: .ascii " " # Volume Serial Number- 4 bytes
52 FatLabel: .ascii " " # Label - 11 bytes
53 SystemId: .ascii "FAT12 " # SystemId - 8 bytes
54
55 BootSectorEntryPoint:
56 #ASSUME ds:@code
57 #ASSUME ss:@code
58 # ds = 1000, es = 2000 + x (size of first cluster >> 4)
59 # cx = Start Cluster of EfiLdr
60 # dx = Start Cluster of Efivar.bin
61
62 # Re use the BPB data stored in Boot Sector
63 movw $0x7c00, %bp
64
65 pushw %cx
66 # Read Efivar.bin
67 # 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
68 movw $0x1900, %ax
69 movw %ax, %es
70 testw %dx, %dx
71 jnz CheckVarStoreSize
72
73 movb $1, %al
74 NoVarStore:
75 pushw %es
76 # Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
77 movb %al, %es:4
78 jmp SaveVolumeId
79
80 CheckVarStoreSize:
81 movw %dx, %di
82 cmpl $0x4000, %ds:2(%di)
83 movb $2, %al
84 jne NoVarStore
85
86 LoadVarStore:
87 movb $0, %al
88 movb %al, %es:4
89 movw (%di), %cx
90 # ES:DI = 1500:0
91 xorw %di, %di
92 pushw %es
93 movw $0x1500, %ax
94 movw %ax, %es
95 call ReadFile
96 SaveVolumeId:
97 popw %es
98 movw VolId(%bp), %ax
99 movw %ax, %es:0 # Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
100 movw VolId+2(%bp), %ax
101 movw %ax, %es:2
102
103 # Read Efildr
104 popw %cx
105 # cx = Start Cluster of Efildr -> BS.com has filled already
106 # ES:DI = 2000:0, first cluster will be read again
107 xorw %di, %di # di = 0
108 movw $0x2000, %ax
109 movw %ax, %es
110 call ReadFile
111 movw %cs, %ax
112 movw %ax, %cs:JumpSegment
113
114 JumpFarInstruction:
115 .byte 0xea
116 JumpOffset:
117 .word 0x200
118 JumpSegment:
119 .word 0x2000
120
121
122
123 # ****************************************************************************
124 # ReadFile
125 #
126 # Arguments:
127 # CX = Start Cluster of File
128 # ES:DI = Buffer to store file content read from disk
129 #
130 # Return:
131 # (ES << 4 + DI) = end of file content Buffer
132 #
133 # ****************************************************************************
134 ReadFile:
135 # si = NumberOfClusters
136 # cx = ClusterNumber
137 # dx = CachedFatSectorNumber
138 # ds:0000 = CacheFatSectorBuffer
139 # es:di = Buffer to load file
140 # bx = NextClusterNumber
141 pusha
142 movw $1, %si # NumberOfClusters = 1
143 pushw %cx # Push Start Cluster onto stack
144 movw $0xfff, %dx # CachedFatSectorNumber = 0xfff
145 FatChainLoop:
146 movw %cx, %ax # ax = ClusterNumber
147 andw $0xff8, %ax # ax = ax & 0xff8
148 cmpw $0xff8, %ax # See if this is the last cluster
149 je FoundLastCluster # Jump if last cluster found
150 movw %cx, %ax # ax = ClusterNumber
151 shlw %ax # ax = ClusterNumber * 2
152 addw %cx, %ax # ax = ClusterNumber * 2 + ClusterNumber = ClusterNumber * 3
153 shrw %ax # FatOffset = ClusterNumber*3 / 2
154 pushw %si # Save si
155 movw %ax, %si # si = FatOffset
156 shrw $BLOCK_SHIFT, %ax # ax = FatOffset >> BLOCK_SHIFT
157 addw ReservedSectors(%bp), %ax # ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
158 andw $BLOCK_MASK,%si # si = FatOffset & BLOCK_MASK
159 cmpw %dx, %ax # Compare FatSectorNumber to CachedFatSectorNumber
160 je SkipFatRead
161 movw $2, %bx
162 pushw %es
163 pushw %ds
164 popw %es
165 call ReadBlocks # Read 2 blocks starting at AX storing at ES:DI
166 popw %es
167 movw %ax, %dx # CachedFatSectorNumber = FatSectorNumber
168 SkipFatRead:
169 movw (%si), %bx # bx = NextClusterNumber
170 movw %cx, %ax # ax = ClusterNumber
171 andw $1, %ax # See if this is an odd cluster number
172 je EvenFatEntry
173 shrw $4, %bx # NextClusterNumber = NextClusterNumber >> 4
174 EvenFatEntry:
175 andw $0xfff, %bx # Strip upper 4 bits of NextClusterNumber
176 popw %si # Restore si
177 decw %bx # bx = NextClusterNumber - 1
178 cmpw %cx, %bx # See if (NextClusterNumber-1)==ClusterNumber
179 jne ReadClusters
180 incw %bx # bx = NextClusterNumber
181 incw %si # NumberOfClusters++
182 movw %bx, %cx # ClusterNumber = NextClusterNumber
183 jmp FatChainLoop
184 ReadClusters:
185 incw %bx
186 popw %ax # ax = StartCluster
187 pushw %bx # StartCluster = NextClusterNumber
188 movw %bx, %cx # ClusterNumber = NextClusterNumber
189 subw $2, %ax # ax = StartCluster - 2
190 xorb %bh, %bh
191 movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
192 mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
193 addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
194 pushw %ax # save start sector
195 movw %si, %ax # ax = NumberOfClusters
196 mulw %bx # ax = NumberOfClusters * SectorsPerCluster
197 movw %ax, %bx # bx = Number of Sectors
198 popw %ax # ax = Start Sector
199 call ReadBlocks
200 movw $1, %si # NumberOfClusters = 1
201 jmp FatChainLoop
202 FoundLastCluster:
203 popw %cx
204 popa
205 ret
206
207
208 # ****************************************************************************
209 # ReadBlocks - Reads a set of blocks from a block device
210 #
211 # AX = Start LBA
212 # BX = Number of Blocks to Read
213 # ES:DI = Buffer to store sectors read from disk
214 # ****************************************************************************
215
216 # cx = Blocks
217 # bx = NumberOfBlocks
218 # si = StartLBA
219
220 ReadBlocks:
221 pusha
222 addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
223 addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
224 movl %eax, %esi # esi = Start LBA
225 movw %bx, %cx # cx = Number of blocks to read
226 ReadCylinderLoop:
227 movw $0x7bfc, %bp # bp = 0x7bfc
228 movl %esi, %eax # eax = Start LBA
229 xorl %edx, %edx # edx = 0
230 movzwl (%bp), %ebx # bx = MaxSector
231 divl %ebx # ax = StartLBA / MaxSector
232 incw %dx # dx = (StartLBA % MaxSector) + 1
233
234 movw (%bp), %bx # bx = MaxSector
235 subw %dx, %bx # bx = MaxSector - Sector
236 incw %bx # bx = MaxSector - Sector + 1
237 cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
238 jg LimitTransfer
239 movw %cx, %bx # bx = Blocks
240 LimitTransfer:
241 pushw %ax # save ax
242 movw %es, %ax # ax = es
243 shrw %ax # ax = Number of blocks into mem system
244 andw $0x7f, %ax # ax = Number of blocks into current seg
245 addw %bx, %ax # ax = End Block number of transfer
246 cmpw $0x80, %ax # See if it crosses a 64K boundry
247 jle NotCrossing64KBoundry # Branch if not crossing 64K boundry
248 subw $0x80, %ax # ax = Number of blocks past 64K boundry
249 subw %ax, %bx # Decrease transfer size by block overage
250 NotCrossing64KBoundry:
251 popw %ax # restore ax
252
253 pushw %cx
254 movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
255 xorw %dx, %dx # dx = 0
256 divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
257 # dx = ax % (MaxHead + 1) = Head
258
259 pushw %bx # Save number of blocks to transfer
260 movb %dl, %dh # dh = Head
261 movw $0x7c00, %bp # bp = 0x7c00
262 movb PhysicalDrive(%bp), %dl # dl = Drive Number
263 movb %al, %ch # ch = Cylinder
264 movb %bl, %al # al = Blocks
265 movb $2, %ah # ah = Function 2
266 movw %di, %bx # es:bx = Buffer address
267 int $0x13
268 jc DiskError
269 popw %bx
270 popw %cx
271 movzwl %bx, %ebx
272 addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
273 subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
274 movw %es, %ax
275 shlw %bx
276 addw %bx, %ax
277 movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
278 cmpw $0, %cx
279 jne ReadCylinderLoop
280 popa
281 ret
282
283 DiskError:
284 pushw %cs
285 popw %ds
286 leaw ErrorString, %si
287 movw $7, %cx
288 jmp PrintStringAndHalt
289
290 PrintStringAndHalt:
291 movw $0xb800, %ax
292 movw %ax, %es
293 movw $160, %di
294 rep
295 movsw
296 Halt:
297 jmp Halt
298
299 ErrorString:
300 .byte 'S', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!',0x0c
301
302 .org 0x0241 # For Code size overflow, Modified this just for pass build
303 LBAOffsetForBootSector:
304 .long 0x0
305
306 #.org 0x0227 # For Code size overflow, Modified this just for pass build
307 .word 0xaa55
308
309 #******************************************************************************
310 #******************************************************************************
311 #******************************************************************************
312
313 .equ DELAY_PORT, 0x0ed # Port to use for 1uS delay
314 .equ KBD_CONTROL_PORT, 0x060 # 8042 control port
315 .equ KBD_STATUS_PORT, 0x064 # 8042 status port
316 .equ WRITE_DATA_PORT_CMD, 0x0d1 # 8042 command to write the data port
317 .equ ENABLE_A20_CMD, 0x0df # 8042 command to enable A20
318
319 #.org 0x200
320 jmp start
321 Em64String:
322 .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
323
324 start:
325 movw %cs, %ax
326 movw %ax, %ds
327 movw %ax, %es
328 movw %ax, %ss
329 movw $MyStack, %sp
330
331 # mov ax,0b800h
332 # mov es,ax
333 # mov byte ptr es:[160],'a'
334 # mov ax,cs
335 # mov es,ax
336
337 movl $0, %ebx
338 leal MemoryMap, %edi
339 MemMapLoop:
340 movl $0xe820, %eax
341 movl $20, %ecx
342 movl $0x534d4150, %edx # SMAP
343 int $0x15
344 jc MemMapDone
345 addl $20, %edi
346 cmpl $0, %ebx
347 je MemMapDone
348 jmp MemMapLoop
349 MemMapDone:
350 leal MemoryMap, %eax
351 subl %eax, %edi # Get the address of the memory map
352 movl %edi, MemoryMapSize # Save the size of the memory map
353
354 xorl %ebx, %ebx
355 movw %cs, %bx # BX=segment
356 shll $4, %ebx # BX="linear" address of segment base
357 leal GDT_BASE(%ebx), %eax #
358 movl %eax, (gdtr + 2) #
359 leal IDT_BASE(%ebx), %eax #
360 movl %eax, (idtr + 2) #
361 leal MemoryMapSize(%ebx), %edx #
362
363 addl $0x1000, %ebx # Source of EFI32
364 movl %ebx, JUMP+2
365 addl $0x1000, %ebx
366 movl %ebx, %esi # Source of EFILDR32
367
368 # mov ax,0b800h
369 # mov es,ax
370 # mov byte ptr es:[162],'b'
371 # mov ax,cs
372 # mov es,ax
373
374 #
375 # Enable A20 Gate
376 #
377
378 movw $0x2401, %ax # Enable A20 Gate
379 int $0x15
380 jnc A20GateEnabled # Jump if it suceeded
381
382 #
383 # If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
384 #
385
386 call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
387 jnz Timeout8042 # Jump if the 8042 timed out
388 outw %ax, $DELAY_PORT # Delay 1 uS
389 mov $WRITE_DATA_PORT_CMD, %al # 8042 cmd to write output port
390 out %al, $KBD_STATUS_PORT # Send command to the 8042
391 call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
392 jnz Timeout8042 # Jump if the 8042 timed out
393 mov $ENABLE_A20_CMD, %al # gate address bit 20 on
394 out %al, $KBD_CONTROL_PORT # Send command to thre 8042
395 call Empty8042InputBuffer # Empty the Input Buffer on the 8042 controller
396 movw $25, %cx # Delay 25 uS for the command to complete on the 8042
397 Delay25uS:
398 outw %ax, $DELAY_PORT # Delay 1 uS
399 loop Delay25uS
400 Timeout8042:
401
402
403 A20GateEnabled:
404
405 #
406 # DISABLE INTERRUPTS - Entering Protected Mode
407 #
408
409 cli
410
411 # mov ax,0b800h
412 # mov es,ax
413 # mov byte ptr es:[164],'c'
414 # mov ax,cs
415 # mov es,ax
416
417 .byte 0x66
418 lgdt gdtr
419 .byte 0x66
420 lidt idtr
421
422 movl %cr0, %eax
423 orb $1, %al
424 movl %eax, %cr0
425
426 movl $0x008, %eax # Flat data descriptor
427 movl $0x00400000, %ebp # Destination of EFILDR32
428 movl $0x00070000, %ebx # Length of copy
429
430 JUMP:
431 # jmp far 0010:00020000
432 .byte 0x66
433 .byte 0xea
434 .long 0x00020000
435 .word 0x0010
436
437 Empty8042InputBuffer:
438 movw $0, %cx
439 Empty8042Loop:
440 outw %ax, $DELAY_PORT # Delay 1us
441 in $KBD_STATUS_PORT, %al # Read the 8042 Status Port
442 andb $0x2, %al # Check the Input Buffer Full Flag
443 loopnz Empty8042Loop # Loop until the input buffer is empty or a timout of 65536 uS
444 ret
445
446 ##############################################################################
447 # data
448 ##############################################################################
449
450 .align 0x2
451
452 gdtr: .long GDT_END - GDT_BASE - 1 # GDT limit
453 .long 0 # (GDT base gets set above)
454 ##############################################################################
455 # global descriptor table (GDT)
456 ##############################################################################
457
458 .align 0x2
459
460 GDT_BASE:
461 # null descriptor
462 .equ NULL_SEL, .-GDT_BASE
463 .word 0 # limit 15:0
464 .word 0 # base 15:0
465 .byte 0 # base 23:16
466 .byte 0 # type
467 .byte 0 # limit 19:16, flags
468 .byte 0 # base 31:24
469
470 # linear data segment descriptor
471 .equ LINEAR_SEL, .-GDT_BASE
472 .word 0xFFFF # limit 0xFFFFF
473 .word 0 # base 0
474 .byte 0
475 .byte 0x92 # present, ring 0, data, expand-up, writable
476 .byte 0xCF # page-granular, 32-bit
477 .byte 0
478
479 # linear code segment descriptor
480 .equ LINEAR_CODE_SEL, .-GDT_BASE
481 .word 0xFFFF # limit 0xFFFFF
482 .word 0 # base 0
483 .byte 0
484 .byte 0x9A # present, ring 0, data, expand-up, writable
485 .byte 0xCF # page-granular, 32-bit
486 .byte 0
487
488 # system data segment descriptor
489 .equ SYS_DATA_SEL, .-GDT_BASE
490 .word 0xFFFF # limit 0xFFFFF
491 .word 0 # base 0
492 .byte 0
493 .byte 0x92 # present, ring 0, data, expand-up, writable
494 .byte 0xCF # page-granular, 32-bit
495 .byte 0
496
497 # system code segment descriptor
498 .equ SYS_CODE_SEL, .-GDT_BASE
499 .word 0xFFFF # limit 0xFFFFF
500 .word 0 # base 0
501 .byte 0
502 .byte 0x9A # present, ring 0, data, expand-up, writable
503 .byte 0xCF # page-granular, 32-bit
504 .byte 0
505
506 # spare segment descriptor
507 .equ SPARE3_SEL, .-GDT_BASE
508 .word 0 # limit 0xFFFFF
509 .word 0 # base 0
510 .byte 0
511 .byte 0 # present, ring 0, data, expand-up, writable
512 .byte 0 # page-granular, 32-bit
513 .byte 0
514
515 # spare segment descriptor
516 .equ SPARE4_SEL, .-GDT_BASE
517 .word 0 # limit 0xFFFFF
518 .word 0 # base 0
519 .byte 0
520 .byte 0 # present, ring 0, data, expand-up, writable
521 .byte 0 # page-granular, 32-bit
522 .byte 0
523
524 # spare segment descriptor
525 .equ SPARE5_SEL, .-GDT_BASE
526 .word 0 # limit 0xFFFFF
527 .word 0 # base 0
528 .byte 0
529 .byte 0 # present, ring 0, data, expand-up, writable
530 .byte 0 # page-granular, 32-bit
531 .byte 0
532
533 GDT_END:
534
535 .align 0x2
536
537
538
539 idtr: .long IDT_END - IDT_BASE - 1 # IDT limit
540 .long 0 # (IDT base gets set above)
541 ##############################################################################
542 # interrupt descriptor table (IDT)
543 #
544 # Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
545 # mappings. This implementation only uses the system timer and all other
546 # IRQs will remain masked. The descriptors for vectors 33+ are provided
547 # for convenience.
548 ##############################################################################
549
550 #idt_tag db "IDT",0
551 .align 0x2
552
553 IDT_BASE:
554 # divide by zero (INT 0)
555 .equ DIV_ZERO_SEL, .-IDT_BASE
556 .word 0 # offset 15:0
557 .long SYS_CODE_SEL # selector 15:0
558 .byte 0 # 0 for interrupt gate
559 .byte 0x0e | 0x80 # type = 386 interrupt gate, present
560 .word 0 # offset 31:16
561
562 # debug exception (INT 1)
563 .equ DEBUG_EXCEPT_SEL, .-IDT_BASE
564 .word 0 # offset 15:0
565 .long 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 # NMI (INT 2)
571 .equ NMI_SEL, .-IDT_BASE
572 .word 0 # offset 15:0
573 .long 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 # soft breakpoint (INT 3)
579 .equ BREAKPOINT_SEL, .-IDT_BASE
580 .word 0 # offset 15:0
581 .long 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 # overflow (INT 4)
587 .equ OVERFLOW_SEL, .-IDT_BASE
588 .word 0 # offset 15:0
589 .long 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 # bounds check (INT 5)
595 .equ BOUNDS_CHECK_SEL, .-IDT_BASE
596 .word 0 # offset 15:0
597 .long 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 # invalid opcode (INT 6)
603 .equ INVALID_OPCODE_SEL, .-IDT_BASE
604 .word 0 # offset 15:0
605 .long 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 # device not available (INT 7)
611 .equ DEV_NOT_AVAIL_SEL, .-IDT_BASE
612 .word 0 # offset 15:0
613 .long 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 # double fault (INT 8)
619 .equ DOUBLE_FAULT_SEL, .-IDT_BASE
620 .word 0 # offset 15:0
621 .long 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 # Coprocessor segment overrun - reserved (INT 9)
627 .equ RSVD_INTR_SEL1, .-IDT_BASE
628 .word 0 # offset 15:0
629 .long 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 # invalid TSS (INT 0x0a)
635 .equ INVALID_TSS_SEL, .-IDT_BASE
636 .word 0 # offset 15:0
637 .long 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 # segment not present (INT 0x0b)
643 .equ SEG_NOT_PRESENT_SEL, .-IDT_BASE
644 .word 0 # offset 15:0
645 .long 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 # stack fault (INT 0x0c)
651 .equ STACK_FAULT_SEL, .-IDT_BASE
652 .word 0 # offset 15:0
653 .long 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 # general protection (INT 0x0d)
659 .equ GP_FAULT_SEL, .-IDT_BASE
660 .word 0 # offset 15:0
661 .long 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 # page fault (INT 0x0e)
667 .equ PAGE_FAULT_SEL, .-IDT_BASE
668 .word 0 # offset 15:0
669 .long 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 # Intel reserved - do not use (INT 0x0f)
675 .equ RSVD_INTR_SEL2, .-IDT_BASE
676 .word 0 # offset 15:0
677 .long 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 # floating point error (INT 0x10)
683 .equ FLT_POINT_ERR_SEL, .-IDT_BASE
684 .word 0 # offset 15:0
685 .long 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 # alignment check (INT 0x11)
691 .equ ALIGNMENT_CHECK_SEL, .-IDT_BASE
692 .word 0 # offset 15:0
693 .long SYS_CODE_SEL # selector 15:0
694 .byte 0 # 0 for interrupt gate
695 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
696 .word 0 # offset 31:16
697
698 # machine check (INT 0x12)
699 .equ MACHINE_CHECK_SEL, .-IDT_BASE
700 .word 0 # offset 15:0
701 .long SYS_CODE_SEL # selector 15:0
702 .byte 0 # 0 for interrupt gate
703 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
704 .word 0 # offset 31:16
705
706 # SIMD floating-point exception (INT 0x13)
707 .equ SIMD_EXCEPTION_SEL, .-IDT_BASE
708 .word 0 # offset 15:0
709 .long SYS_CODE_SEL # selector 15:0
710 .byte 0 # 0 for interrupt gate
711 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
712 .word 0 # offset 31:16
713
714 # 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
715 .fill 85 * 8, 1, 0 # db (85 * 8) dup(0)
716
717 # IRQ 0 (System timer) - (INT 0x68)
718 .equ IRQ0_SEL, .-IDT_BASE
719 .word 0 # offset 15:0
720 .long SYS_CODE_SEL # selector 15:0
721 .byte 0 # 0 for interrupt gate
722 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
723 .word 0 # offset 31:16
724
725 # IRQ 1 (8042 Keyboard controller) - (INT 0x69)
726 .equ IRQ1_SEL, .-IDT_BASE
727 .word 0 # offset 15:0
728 .long SYS_CODE_SEL # selector 15:0
729 .byte 0 # 0 for interrupt gate
730 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
731 .word 0 # offset 31:16
732
733 # Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 0x6a)
734 .equ IRQ2_SEL, .-IDT_BASE
735 .word 0 # offset 15:0
736 .long SYS_CODE_SEL # selector 15:0
737 .byte 0 # 0 for interrupt gate
738 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
739 .word 0 # offset 31:16
740
741 # IRQ 3 (COM 2) - (INT 0x6b)
742 .equ IRQ3_SEL, .-IDT_BASE
743 .word 0 # offset 15:0
744 .long SYS_CODE_SEL # selector 15:0
745 .byte 0 # 0 for interrupt gate
746 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
747 .word 0 # offset 31:16
748
749 # IRQ 4 (COM 1) - (INT 0x6c)
750 .equ IRQ4_SEL, .-IDT_BASE
751 .word 0 # offset 15:0
752 .long SYS_CODE_SEL # selector 15:0
753 .byte 0 # 0 for interrupt gate
754 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
755 .word 0 # offset 31:16
756
757 # IRQ 5 (LPT 2) - (INT 0x6d)
758 .equ IRQ5_SEL, .-IDT_BASE
759 .word 0 # offset 15:0
760 .long SYS_CODE_SEL # selector 15:0
761 .byte 0 # 0 for interrupt gate
762 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
763 .word 0 # offset 31:16
764
765 # IRQ 6 (Floppy controller) - (INT 0x6e)
766 .equ IRQ6_SEL, .-IDT_BASE
767 .word 0 # offset 15:0
768 .long SYS_CODE_SEL # selector 15:0
769 .byte 0 # 0 for interrupt gate
770 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
771 .word 0 # offset 31:16
772
773 # IRQ 7 (LPT 1) - (INT 0x6f)
774 .equ IRQ7_SEL, .-IDT_BASE
775 .word 0 # offset 15:0
776 .long SYS_CODE_SEL # selector 15:0
777 .byte 0 # 0 for interrupt gate
778 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
779 .word 0 # offset 31:16
780
781 # IRQ 8 (RTC Alarm) - (INT 0x70)
782 .equ IRQ8_SEL, .-IDT_BASE
783 .word 0 # offset 15:0
784 .long SYS_CODE_SEL # selector 15:0
785 .byte 0 # 0 for interrupt gate
786 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
787 .word 0 # offset 31:16
788
789 # IRQ 9 - (INT 0x71)
790 .equ IRQ9_SEL, .-IDT_BASE
791 .word 0 # offset 15:0
792 .long SYS_CODE_SEL # selector 15:0
793 .byte 0 # 0 for interrupt gate
794 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
795 .word 0 # offset 31:16
796
797 # IRQ 10 - (INT 0x72)
798 .equ IRQ10_SEL, .-IDT_BASE
799 .word 0 # offset 15:0
800 .long SYS_CODE_SEL # selector 15:0
801 .byte 0 # 0 for interrupt gate
802 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
803 .word 0 # offset 31:16
804
805 # IRQ 11 - (INT 0x73)
806 .equ IRQ11_SEL, .-IDT_BASE
807 .word 0 # offset 15:0
808 .long SYS_CODE_SEL # selector 15:0
809 .byte 0 # 0 for interrupt gate
810 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
811 .word 0 # offset 31:16
812
813 # IRQ 12 (PS/2 mouse) - (INT 0x74)
814 .equ IRQ12_SEL, .-IDT_BASE
815 .word 0 # offset 15:0
816 .long SYS_CODE_SEL # selector 15:0
817 .byte 0 # 0 for interrupt gate
818 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
819 .word 0 # offset 31:16
820
821 # IRQ 13 (Floating point error) - (INT 0x75)
822 .equ IRQ13_SEL, .-IDT_BASE
823 .word 0 # offset 15:0
824 .long SYS_CODE_SEL # selector 15:0
825 .byte 0 # 0 for interrupt gate
826 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
827 .word 0 # offset 31:16
828
829 # IRQ 14 (Secondary IDE) - (INT 0x76)
830 .equ IRQ14_SEL, .-IDT_BASE
831 .word 0 # offset 15:0
832 .long SYS_CODE_SEL # selector 15:0
833 .byte 0 # 0 for interrupt gate
834 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
835 .word 0 # offset 31:16
836
837 # IRQ 15 (Primary IDE) - (INT 0x77)
838 .equ IRQ15_SEL, .-IDT_BASE
839 .word 0 # offset 15:0
840 .long SYS_CODE_SEL # selector 15:0
841 .byte 0 # 0 for interrupt gate
842 .byte 0x0e | 0x80 # (10001110)type = 386 interrupt gate, present
843 .word 0 # offset 31:16
844
845 IDT_END:
846
847 .align 0x2
848
849 MemoryMapSize: .long 0
850 MemoryMap: .long 0,0,0,0,0,0,0,0
851 .long 0,0,0,0,0,0,0,0
852 .long 0,0,0,0,0,0,0,0
853 .long 0,0,0,0,0,0,0,0
854 .long 0,0,0,0,0,0,0,0
855 .long 0,0,0,0,0,0,0,0
856 .long 0,0,0,0,0,0,0,0
857 .long 0,0,0,0,0,0,0,0
858 .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
881 .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
882 .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
883
884 .org 0x0fe0
885 MyStack:
886 # below is the pieces of the IVT that is used to redirect INT 68h - 6fh
887 # back to INT 08h - 0fh when in real mode... It is 'org'ed to a
888 # known low address (20f00) so it can be set up by PlMapIrqToVect in
889 # 8259.c
890
891 int $8
892 iret
893
894 int $9
895 iret
896
897 int $10
898 iret
899
900 int $11
901 iret
902
903 int $12
904 iret
905
906 int $13
907 iret
908
909 int $14
910 iret
911
912 int $15
913 iret
914
915
916 .org 0x0ffe
917 BlockSignature:
918 .word 0xaa55
919
920