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