GAS LISTING /tmp/ccF6Ay5F.s page 1 1 # 1 "/var/www/html/boot/syslinux/mbr/gptmbr.S" 1 /* ----------------------------------------------------------------------- 1 ... 0 0 2 * 3 * Copyright 2007-2009 H. Peter Anvin - All Rights Reserved 4 * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin 5 * 6 * Permission is hereby granted, free of charge, to any person 7 * obtaining a copy of this software and associated documentation 8 * files (the "Software"), to deal in the Software without 9 * restriction, including without limitation the rights to use, 10 * copy, modify, merge, publish, distribute, sublicense, and/or 11 * sell copies of the Software, and to permit persons to whom 12 * the Software is furnished to do so, subject to the following 13 * conditions: 14 * 15 * The above copyright notice and this permission notice shall 16 * be included in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 * 27 * ----------------------------------------------------------------------- */ 28 29 #include "adjust.h" 1 /* -*- asm -*- ----------------------------------------------------------- 2 * 3 * Copyright 2009-2014 Intel Corporation; author: H. Peter Anvin 4 * 5 * Permission is hereby granted, free of charge, to any person 6 * obtaining a copy of this software and associated documentation 7 * files (the "Software"), to deal in the Software without 8 * restriction, including without limitation the rights to use, 9 * copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom 11 * the Software is furnished to do so, subject to the following 12 * conditions: 13 * 14 * The above copyright notice and this permission notice shall 15 * be included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 * OTHER DEALINGS IN THE SOFTWARE. GAS LISTING /tmp/ccF6Ay5F.s page 2 25 * 26 * ----------------------------------------------------------------------- */ 27 28 /* 29 * adjust.h 30 * 31 * Macros to adjust the drive number 32 */ 33 34 #ifndef ADJUST_H 35 #define ADJUST_H 36 37 #ifdef CTRL_80 38 .macro ADJUST_DRIVE 39 pusha 40 movb $0x02, %ah 41 int $0x16 42 testb $0x04, %al 43 popa 44 jz 1f 45 movb $0x80, %dl 46 1: 47 .endm 48 #elif defined(FORCE_80) 30 31 .code16 32 .text 33 34 .globl bootsec 35 stack = 0x7c00 36 37 /* Partition table header here */ 38 phdr = stack /* Above the stack, overwritten by bootsect */ 39 /* Partition table sector here */ 40 /* To handle > 32K we need to play segment tricks... */ 41 psec = _phdr + 512 42 43 /* Where we put DS:SI */ 44 dssi_out = _start + 0x1be 45 46 BIOS_kbdflags = 0x417 47 BIOS_page = 0x462 48 49 /* gas/ld has issues with doing this as absolute addresses... */ 50 .section ".bootsec", "a", @nobits 51 .globl bootsec 52 bootsec: 53 0000 00000000 .space 512 53 00000000 53 00000000 53 00000000 53 00000000 54 55 .text 56 .globl _start 57 _start: 58 0000 33C0 .byte 0x33, 0xc0 /* xorw %ax, %ax */ GAS LISTING /tmp/ccF6Ay5F.s page 3 59 0002 FA cli 60 0003 8ED8 movw %ax, %ds 61 0005 8ED0 movw %ax, %ss 62 0007 BC007C movw $stack, %sp 63 000a 89E6 movw %sp, %si 64 000c 06 pushw %es /* 4(%bp) es:di -> $PnP header */ 65 000d 57 pushw %di /* 2(%bp) */ 66 000e 8EC0 movw %ax, %es 67 0010 FB sti 68 0011 FC cld 69 70 /* Copy down to 0:0x600 */ 71 0012 BF0000 movw $_start, %di 72 0015 B90001 movw $(512/2), %cx 73 0018 F3A5 rep; movsw 74 75 001a EA000000 ljmpw $0, $next 75 00 76 next: 77 78 001f 60B402CD ADJUST_DRIVE 78 16A80461 78 7402B280 79 002b 52 pushw %dx /* 0(%bp) = %dl -> drive number */ 80 002c 89E5 movw %sp, %bp /* %bp -> frame pointer: LEAVE UNCHANGED */ 81 82 /* prepare to read sector size */ 83 002e 83EC1C sub $0x1c, %sp /* -28(%bp) == %sp */ 84 0031 6A1E pushw $0x1e /* -30(%bp) == %sp */ 85 0033 C746FA00 movw $0x200, -6(%bp) /* -6(%bp) sector size */ 85 02 86 87 /* Check to see if we have EBIOS */ 88 0038 52 pushw %dx /* drive number */ 89 0039 B441 movb $0x41, %ah /* %al == 0 already */ 90 003b BBAA55 movw $0x55aa, %bx 91 003e 31C9 xorw %cx, %cx 92 0040 30F6 xorb %dh, %dh 93 0042 F9 stc 94 0043 CD13 int $0x13 95 0045 5A popw %dx /* restore drive */ 96 0046 B408 movb $0x08, %ah /* get CHS geometry */ 97 0048 7217 jc 1f 98 004a 81FB55AA cmpw $0xaa55, %bx 99 004e 7511 jne 1f 100 0050 D1E9 shrw %cx /* Bit 0 = fixed disk subset */ 101 0052 730D jnc 1f 102 103 /* We have EBIOS; patch in the following code at 104 read_sector_cbios: movb $0x42, %ah ; jmp read_common */ 105 0054 66C70600 movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \ 105 00B442EB 105 13 106 (read_sector_cbios) 107 108 /* 109 * read sector size. GAS LISTING /tmp/ccF6Ay5F.s page 4 110 * Should not fail but if it does I assume that at least 111 * previous 512 value is not overridden 112 */ 113 005d B448 movb $0x48, %ah 114 005f 89E6 movw %sp, %si 115 116 1: 117 /* Get (C)HS geometry */ 118 0061 CD13 int $0x13 119 120 /* here we computer CHS values or just do some dummy computation for EBIOS */ 121 0063 83E13F andw $0x3f, %cx /* Sector count */ 122 0066 51 pushw %cx /* -32(%bp) Save sectors on the stack */ 123 0067 0FB6C6 movzbw %dh, %ax /* dh = max head */ 124 006a 40 incw %ax /* From 0-based max to count */ 125 006b F7E1 mulw %cx /* Heads*sectors -> sectors per cylinder */ 126 127 /* Save sectors/cylinder on the stack */ 128 006d 52 pushw %dx /* -34(%bp) High word */ 129 006e 50 pushw %ax /* -36(%bp) Low word */ 130 131 /* Load partition table header */ 132 006f 6631C0 xorl %eax,%eax 133 0072 6699 cltd 134 0074 40 incw %ax /* %edx:%eax = 1 */ 135 0075 E8DC00 call read_sector_phdr 136 137 /* Number of partition sectors */ 138 /* We assume the partition table is 32K or less */ 139 0078 8B4E56 movw (80+6)(%bp),%cx /* NumberOfPartitionEntries */ 140 007b 8B465A movw (84+6)(%bp),%ax /* SizeOfPartitionEntry */ 141 007e 50 pushw %ax 142 007f 51 pushw %cx 143 0080 F7E1 mulw %cx 144 0082 F776FA divw -6(%bp) /* %dx == 0 here */ 145 0085 91 xchgw %ax,%cx 146 0086 41 incw %cx 147 148 /* Starting LBA of partition array */ 149 0087 668B464E movl (72+6)(%bp),%eax 150 008b 668B5652 movl (76+6)(%bp),%edx 151 152 008f 53 pushw %bx 153 get_ptab: 154 0090 E8C400 call read_sector 155 0093 E2FB loopw get_ptab 156 157 /* Find the boot partition */ 158 0095 31F6 xorw %si,%si /* Nothing found yet */ 159 0097 5F popw %di /* Partition table in memory */ 160 0098 59 popw %cx /* NumberOfPartitionEntries */ 161 0099 58 popw %ax /* SizeOfPartitionEntry */ 162 163 find_part: 164 /* If the PartitionTypeGUID is all zero, it's an empty slot */ 165 009a 668B15 movl (%di),%edx 166 009d 660B5504 orl 4(%di),%edx GAS LISTING /tmp/ccF6Ay5F.s page 5 167 00a1 660B5508 orl 8(%di),%edx 168 00a5 660B550C orl 12(%di),%edx 169 00a9 740C jz not_this 170 00ab F6453004 testb $0x04,48(%di) 171 00af 7406 jz not_this 172 00b1 21F6 andw %si,%si 173 00b3 7519 jnz found_multiple 174 00b5 89FE movw %di,%si 175 not_this: 176 00b7 01C7 addw %ax,%di 177 00b9 E2DF loopw find_part 178 179 00bb 21F6 andw %si,%si 180 00bd 752E jnz found_part 181 182 missing_os: 183 00bf E8E100 call error 184 00c2 4D697373 .ascii "Missing OS\r\n" 184 696E6720 184 4F530D0A 185 186 found_multiple: 187 00ce E8D200 call error 188 00d1 4D756C74 .ascii "Multiple active partitions\r\n" 188 69706C65 188 20616374 188 69766520 188 70617274 189 190 found_part: 191 00ed 91 xchgw %ax,%cx /* Set up %cx for rep movsb further down */ 192 193 00ee BF0000 movw $dssi_out,%di 194 00f1 57 pushw %di 195 196 /* 80 00 00 00 ee 00 00 00 197 - bootable partition, type EFI (EE), no CHS information */ 198 00f2 6631C0 xorl %eax,%eax 199 00f5 B080 movb $0x80,%al 200 00f7 66AB stosl 201 00f9 B0ED movb $0xed,%al 202 00fb 66AB stosl 203 00fd 668B4420 movl 32(%si),%eax 204 0101 668B5424 movl 36(%si),%edx 205 0105 E84000 call saturate_stosl /* Partition start */ 206 207 0108 668B4428 movl 40(%si),%eax 208 010c 668B542C movl 44(%si),%edx 209 0110 662B4420 subl 32(%si),%eax 210 0114 661B5424 sbbl 36(%si),%edx 211 0118 E87000 call inc64 212 011b E82A00 call saturate_stosl /* Partition length */ 213 214 011e 660FB7C1 movzwl %cx,%eax /* Length of GPT entry */ 215 0122 66AB stosl 216 217 0124 F3A4 rep; movsb /* GPT entry follows MBR entry */ GAS LISTING /tmp/ccF6Ay5F.s page 6 218 0126 5E popw %si 219 220 /* 221 * boot: invoke the actual bootstrap. %ds:%si points to the 222 * partition information in memory. The top word on the stack 223 * is phdr == 0x7c00 == the address of the boot sector. 224 */ 225 boot: 226 0127 668B4434 movl (32+20)(%si),%eax 227 012b 668B5438 movl (36+20)(%si),%edx 228 012f E82200 call read_sector_phdr 229 0132 813EFE7D cmpw $0xaa55, (0x7c00+0x1fe) 229 55AA 230 0138 7585 jne missing_os /* Not a valid boot sector */ 231 013a 89EC movw %bp, %sp /* driveno == bootsec-6 */ 232 013c 5A popw %dx /* dl -> drive number */ 233 013d 5F popw %di /* es:di -> $PnP vector */ 234 013e 07 popw %es 235 013f 66B82147 movl $0x54504721,%eax /* !GPT magic number */ 235 5054 236 0145 FA cli 237 0146 FFE4 jmpw *%sp /* %sp == bootsec */ 238 239 /* 240 * Store the value in %eax to %di iff %edx == 0, otherwise store -1. 241 * Returns the value that was actually written in %eax. 242 */ 243 saturate_stosl: 244 0148 6621D2 andl %edx,%edx 245 014b 7404 jz 1f 246 014d 6683C8FF orl $-1,%eax 247 0151 66AB 1: stosl 248 0153 C3 ret 249 250 read_sector_phdr: 251 0154 BB007C movw $phdr, %bx 252 253 /* fall through and read sector */ 254 255 /* 256 * read_sector: read a single sector pointed to by %edx:%eax to 257 * %es:%bx. CF is set on error. All registers saved. 258 * %edx:%eax and %es:%bx are incremented to read next sector 259 */ 260 read_sector: 261 0157 6660 pushal 262 0159 6652 pushl %edx /* MSW of LBA */ 263 015b 6650 pushl %eax /* LSW of LBA */ 264 015d 06 pushw %es /* Buffer segment */ 265 015e 53 pushw %bx /* Buffer offset */ 266 015f 6A01 pushw $1 /* Sector count */ 267 0161 6A10 pushw $16 /* Size of packet */ 268 0163 89E6 movw %sp, %si 269 270 /* This chunk is skipped if we have ebios */ 271 /* Do not clobber %es:%bx or %edx:%eax before this chunk! */ 272 read_sector_cbios: GAS LISTING /tmp/ccF6Ay5F.s page 7 273 0165 66F776DC divl -36(%bp) /* secpercyl */ 274 0169 C0E406 shlb $6, %ah 275 016c 88E1 movb %ah, %cl 276 016e 88C5 movb %al, %ch 277 0170 92 xchgw %dx, %ax 278 0171 F676E0 divb -32(%bp) /* sectors */ 279 0174 88C6 movb %al, %dh 280 0176 08E1 orb %ah, %cl 281 0178 41 incw %cx /* Sectors are 1-based */ 282 0179 B80102 movw $0x0201, %ax 283 284 read_common: 285 017c 8A5600 movb (%bp), %dl /* driveno */ 286 017f CD13 int $0x13 287 0181 8D6410 leaw 16(%si), %sp /* Drop DAPA */ 288 0184 6661 popal 289 0186 720C jc disk_error 290 0188 027EFB addb -5(%bp), %bh /* bx += sector size: point to the next buffer */ 291 292 /* fall through and increment sector number */ 293 294 /* 295 * Increment %edx:%eax 296 */ 297 inc64: 298 018b 6683C001 addl $1,%eax 299 018f 6683D200 adcl $0,%edx 300 0193 C3 ret 301 302 disk_error: 303 0194 E80C00 call error 304 0197 4469736B .ascii "Disk error\r\n" 304 20657272 304 6F720D0A 305 306 /* 307 * Print error messages. This is invoked with "call", with the 308 * error message at the return address. 309 */ 310 error: 311 01a3 5E popw %si 312 2: 313 01a4 AC lodsb 314 01a5 B40E movb $0x0e, %ah 315 01a7 8A3E6204 movb (BIOS_page), %bh 316 01ab B307 movb $0x07, %bl 317 01ad CD10 int $0x10 /* May destroy %bp */ 318 01af 3C0A cmpb $10, %al /* Newline? */ 319 01b1 75F1 jne 2b 320 321 01b3 CD18 int $0x18 /* Boot failure */ 322 die: 323 01b5 F4 hlt 324 01b6 EBFD jmp die GAS LISTING /tmp/ccF6Ay5F.s page 8 DEFINED SYMBOLS /var/www/html/boot/syslinux/mbr/gptmbr.S:52 .bootsec:0000000000000000 bootsec /var/www/html/boot/syslinux/mbr/gptmbr.S:35 *ABS*:0000000000007c00 stack /var/www/html/boot/syslinux/mbr/gptmbr.S:38 *ABS*:0000000000007c00 phdr /var/www/html/boot/syslinux/mbr/gptmbr.S:44 .text:00000000000001be dssi_out /var/www/html/boot/syslinux/mbr/gptmbr.S:57 .text:0000000000000000 _start /var/www/html/boot/syslinux/mbr/gptmbr.S:46 *ABS*:0000000000000417 BIOS_kbdflags /var/www/html/boot/syslinux/mbr/gptmbr.S:47 *ABS*:0000000000000462 BIOS_page /var/www/html/boot/syslinux/mbr/gptmbr.S:76 .text:000000000000001f next /var/www/html/boot/syslinux/mbr/gptmbr.S:284 .text:000000000000017c read_common /var/www/html/boot/syslinux/mbr/gptmbr.S:272 .text:0000000000000165 read_sector_cbios /var/www/html/boot/syslinux/mbr/gptmbr.S:250 .text:0000000000000154 read_sector_phdr /var/www/html/boot/syslinux/mbr/gptmbr.S:153 .text:0000000000000090 get_ptab /var/www/html/boot/syslinux/mbr/gptmbr.S:260 .text:0000000000000157 read_sector /var/www/html/boot/syslinux/mbr/gptmbr.S:163 .text:000000000000009a find_part /var/www/html/boot/syslinux/mbr/gptmbr.S:175 .text:00000000000000b7 not_this /var/www/html/boot/syslinux/mbr/gptmbr.S:186 .text:00000000000000ce found_multiple /var/www/html/boot/syslinux/mbr/gptmbr.S:190 .text:00000000000000ed found_part /var/www/html/boot/syslinux/mbr/gptmbr.S:182 .text:00000000000000bf missing_os /var/www/html/boot/syslinux/mbr/gptmbr.S:310 .text:00000000000001a3 error /var/www/html/boot/syslinux/mbr/gptmbr.S:243 .text:0000000000000148 saturate_stosl /var/www/html/boot/syslinux/mbr/gptmbr.S:297 .text:000000000000018b inc64 /var/www/html/boot/syslinux/mbr/gptmbr.S:225 .text:0000000000000127 boot /var/www/html/boot/syslinux/mbr/gptmbr.S:302 .text:0000000000000194 disk_error /var/www/html/boot/syslinux/mbr/gptmbr.S:322 .text:00000000000001b5 die UNDEFINED SYMBOLS _phdr