1 #define BOOT_SEG 0x07c0
2 #define EXEC_SEG 0x0100
3 #define STACK_SEG 0x0200
4 #define STACK_SIZE 0x2000
8 .section ".prefix", "awx", @progbits
12 * Find active partition
15 * %dl : BIOS drive number
16 * %bp : Active partition handler routine
18 find_active_partition:
19 /* Set up stack at STACK_SEG:STACK_SIZE */
24 /* Relocate self to EXEC_SEG */
39 /* Check for LBA extensions */
47 movw $read_lba, read_sectors
49 /* Read and process root partition table */
56 /* Print failure message */
59 10: .asciz "Could not locate active partition\r\n"
62 * Print failure message and boot next device
65 * %si : Failure string
76 99: /* Boot next device */
80 * Process partition table
83 * %dl : BIOS drive number
85 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
86 * %ch : Low eight bits of cylinder
87 * %esi:%edi : LBA address
88 * %bp : Active partition handler routine
98 1: call process_partition
109 * %dl : BIOS drive number
111 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
112 * %ch : Low eight bits of cylinder
113 * %esi:%edi : LBA address
114 * %bx : Offset within partition table
115 * %bp : Active partition handler routine
119 /* Load C/H/S values from partition entry */
122 /* Update LBA address from partition entry */
123 addl %es:8(%bx), %edi
125 /* Check active flag */
126 testb $0x80, %es:(%bx)
128 call read_boot_sector
131 1: /* Check for extended partition */
139 2: call process_table
141 /* Reload original partition table */
142 call read_boot_sector
146 * Read single sector to %es:0000 and verify 0x55aa signature
149 * %dl : BIOS drive number
151 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
152 * %ch : Low eight bits of cylinder
153 * %esi:%edi : LBA address
163 cmpw $0xaa55, %es:(510)
170 * Read sectors to %es:0000
173 * %dl : BIOS drive number
175 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
176 * %ch : Low eight bits of cylinder
177 * %esi:%edi : LBA address
178 * %ax : Number of sectors (max 127)
183 read_sectors: .word read_chs
186 /* Read sectors using C/H/S address */
197 /* Read sectors using LBA address */
199 movw %ax, (lba_desc + 2)
202 movl %edi, (lba_desc + 8)
203 movl %esi, (lba_desc + 12)