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