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