1 FILE_LICENCE ( GPL2_OR_LATER )
3 #define BOOT_SEG 0x07c0
4 #define EXEC_SEG 0x0100
5 #define STACK_SEG 0x0200
6 #define STACK_SIZE 0x2000
10 .section ".prefix", "awx", @progbits
14 * Find active partition
17 * %dl : BIOS drive number
18 * %bp : Active partition handler routine
20 find_active_partition:
21 /* Set up stack at STACK_SEG:STACK_SIZE */
26 /* Relocate self to EXEC_SEG */
41 /* Check for LBA extensions */
49 movw $read_lba, read_sectors
51 /* Read and process root partition table */
58 /* Print failure message */
61 10: .asciz "Could not locate active partition\r\n"
64 * Print failure message and boot next device
67 * %si : Failure string
78 99: /* Boot next device */
82 * Process partition table
85 * %dl : BIOS drive number
87 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
88 * %ch : Low eight bits of cylinder
89 * %esi:%edi : LBA address
90 * %bp : Active partition handler routine
100 1: call process_partition
111 * %dl : BIOS drive number
113 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
114 * %ch : Low eight bits of cylinder
115 * %esi:%edi : LBA address
116 * %bx : Offset within partition table
117 * %bp : Active partition handler routine
121 /* Load C/H/S values from partition entry */
124 /* Update LBA address from partition entry */
125 addl %es:8(%bx), %edi
127 /* Check active flag */
128 testb $0x80, %es:(%bx)
130 call read_boot_sector
133 1: /* Check for extended partition */
141 2: call process_table
143 /* Reload original partition table */
144 call read_boot_sector
148 * Read single sector to %es:0000 and verify 0x55aa signature
151 * %dl : BIOS drive number
153 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
154 * %ch : Low eight bits of cylinder
155 * %esi:%edi : LBA address
165 cmpw $0xaa55, %es:(510)
172 * Read sectors to %es:0000
175 * %dl : BIOS drive number
177 * %cl : Sector (bits 0-5), high two bits of cylinder (bits 6-7)
178 * %ch : Low eight bits of cylinder
179 * %esi:%edi : LBA address
180 * %ax : Number of sectors (max 127)
185 read_sectors: .word read_chs
188 /* Read sectors using C/H/S address */
199 /* Read sectors using LBA address */
201 movw %ax, (lba_desc + 2)
204 movl %edi, (lba_desc + 8)
205 movl %esi, (lba_desc + 12)