GAS LISTING /tmp/cc3Z1Wyl.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/cc3Z1Wyl.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) 49 .macro ADJUST_DRIVE 50 movb $0x80, %dl 51 .endm 52 #else 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 GAS LISTING /tmp/cc3Z1Wyl.s page 3 55 .text 56 .globl _start 57 _start: 58 0000 33C0 .byte 0x33, 0xc0 /* xorw %ax, %ax */ 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 B280 ADJUST_DRIVE 79 0021 52 pushw %dx /* 0(%bp) = %dl -> drive number */ 80 0022 89E5 movw %sp, %bp /* %bp -> frame pointer: LEAVE UNCHANGED */ 81 82 /* prepare to read sector size */ 83 0024 83EC1C sub $0x1c, %sp /* -28(%bp) == %sp */ 84 0027 6A1E pushw $0x1e /* -30(%bp) == %sp */ 85 0029 C746FA00 movw $0x200, -6(%bp) /* -6(%bp) sector size */ 85 02 86 87 /* Check to see if we have EBIOS */ 88 002e 52 pushw %dx /* drive number */ 89 002f B441 movb $0x41, %ah /* %al == 0 already */ 90 0031 BBAA55 movw $0x55aa, %bx 91 0034 31C9 xorw %cx, %cx 92 0036 30F6 xorb %dh, %dh 93 0038 F9 stc 94 0039 CD13 int $0x13 95 003b 5A popw %dx /* restore drive */ 96 003c B408 movb $0x08, %ah /* get CHS geometry */ 97 003e 7217 jc 1f 98 0040 81FB55AA cmpw $0xaa55, %bx 99 0044 7511 jne 1f 100 0046 D1E9 shrw %cx /* Bit 0 = fixed disk subset */ 101 0048 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 004a 66C70600 movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \ 105 00B442EB 105 13 106 (read_sector_cbios) 107 GAS LISTING /tmp/cc3Z1Wyl.s page 4 108 /* 109 * read sector size. 110 * Should not fail but if it does I assume that at least 111 * previous 512 value is not overridden 112 */ 113 0053 B448 movb $0x48, %ah 114 0055 89E6 movw %sp, %si 115 116 1: 117 /* Get (C)HS geometry */ 118 0057 CD13 int $0x13 119 120 /* here we computer CHS values or just do some dummy computation for EBIOS */ 121 0059 83E13F andw $0x3f, %cx /* Sector count */ 122 005c 51 pushw %cx /* -32(%bp) Save sectors on the stack */ 123 005d 0FB6C6 movzbw %dh, %ax /* dh = max head */ 124 0060 40 incw %ax /* From 0-based max to count */ 125 0061 F7E1 mulw %cx /* Heads*sectors -> sectors per cylinder */ 126 127 /* Save sectors/cylinder on the stack */ 128 0063 52 pushw %dx /* -34(%bp) High word */ 129 0064 50 pushw %ax /* -36(%bp) Low word */ 130 131 /* Load partition table header */ 132 0065 6631C0 xorl %eax,%eax 133 0068 6699 cltd 134 006a 40 incw %ax /* %edx:%eax = 1 */ 135 006b E8DC00 call read_sector_phdr 136 137 /* Number of partition sectors */ 138 /* We assume the partition table is 32K or less */ 139 006e 8B4E56 movw (80+6)(%bp),%cx /* NumberOfPartitionEntries */ 140 0071 8B465A movw (84+6)(%bp),%ax /* SizeOfPartitionEntry */ 141 0074 50 pushw %ax 142 0075 51 pushw %cx 143 0076 F7E1 mulw %cx 144 0078 F776FA divw -6(%bp) /* %dx == 0 here */ 145 007b 91 xchgw %ax,%cx 146 007c 41 incw %cx 147 148 /* Starting LBA of partition array */ 149 007d 668B464E movl (72+6)(%bp),%eax 150 0081 668B5652 movl (76+6)(%bp),%edx 151 152 0085 53 pushw %bx 153 get_ptab: 154 0086 E8C400 call read_sector 155 0089 E2FB loopw get_ptab 156 157 /* Find the boot partition */ 158 008b 31F6 xorw %si,%si /* Nothing found yet */ 159 008d 5F popw %di /* Partition table in memory */ 160 008e 59 popw %cx /* NumberOfPartitionEntries */ 161 008f 58 popw %ax /* SizeOfPartitionEntry */ 162 163 find_part: 164 /* If the PartitionTypeGUID is all zero, it's an empty slot */ GAS LISTING /tmp/cc3Z1Wyl.s page 5 165 0090 668B15 movl (%di),%edx 166 0093 660B5504 orl 4(%di),%edx 167 0097 660B5508 orl 8(%di),%edx 168 009b 660B550C orl 12(%di),%edx 169 009f 740C jz not_this 170 00a1 F6453004 testb $0x04,48(%di) 171 00a5 7406 jz not_this 172 00a7 21F6 andw %si,%si 173 00a9 7519 jnz found_multiple 174 00ab 89FE movw %di,%si 175 not_this: 176 00ad 01C7 addw %ax,%di 177 00af E2DF loopw find_part 178 179 00b1 21F6 andw %si,%si 180 00b3 752E jnz found_part 181 182 missing_os: 183 00b5 E8E100 call error 184 00b8 4D697373 .ascii "Missing OS\r\n" 184 696E6720 184 4F530D0A 185 186 found_multiple: 187 00c4 E8D200 call error 188 00c7 4D756C74 .ascii "Multiple active partitions\r\n" 188 69706C65 188 20616374 188 69766520 188 70617274 189 190 found_part: 191 00e3 91 xchgw %ax,%cx /* Set up %cx for rep movsb further down */ 192 193 00e4 BF0000 movw $dssi_out,%di 194 00e7 57 pushw %di 195 196 /* 80 00 00 00 ee 00 00 00 197 - bootable partition, type EFI (EE), no CHS information */ 198 00e8 6631C0 xorl %eax,%eax 199 00eb B080 movb $0x80,%al 200 00ed 66AB stosl 201 00ef B0ED movb $0xed,%al 202 00f1 66AB stosl 203 00f3 668B4420 movl 32(%si),%eax 204 00f7 668B5424 movl 36(%si),%edx 205 00fb E84000 call saturate_stosl /* Partition start */ 206 207 00fe 668B4428 movl 40(%si),%eax 208 0102 668B542C movl 44(%si),%edx 209 0106 662B4420 subl 32(%si),%eax 210 010a 661B5424 sbbl 36(%si),%edx 211 010e E87000 call inc64 212 0111 E82A00 call saturate_stosl /* Partition length */ 213 214 0114 660FB7C1 movzwl %cx,%eax /* Length of GPT entry */ 215 0118 66AB stosl GAS LISTING /tmp/cc3Z1Wyl.s page 6 216 217 011a F3A4 rep; movsb /* GPT entry follows MBR entry */ 218 011c 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 011d 668B4434 movl (32+20)(%si),%eax 227 0121 668B5438 movl (36+20)(%si),%edx 228 0125 E82200 call read_sector_phdr 229 0128 813EFE7D cmpw $0xaa55, (0x7c00+0x1fe) 229 55AA 230 012e 7585 jne missing_os /* Not a valid boot sector */ 231 0130 89EC movw %bp, %sp /* driveno == bootsec-6 */ 232 0132 5A popw %dx /* dl -> drive number */ 233 0133 5F popw %di /* es:di -> $PnP vector */ 234 0134 07 popw %es 235 0135 66B82147 movl $0x54504721,%eax /* !GPT magic number */ 235 5054 236 013b FA cli 237 013c 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 013e 6621D2 andl %edx,%edx 245 0141 7404 jz 1f 246 0143 6683C8FF orl $-1,%eax 247 0147 66AB 1: stosl 248 0149 C3 ret 249 250 read_sector_phdr: 251 014a 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 014d 6660 pushal 262 014f 6652 pushl %edx /* MSW of LBA */ 263 0151 6650 pushl %eax /* LSW of LBA */ 264 0153 06 pushw %es /* Buffer segment */ 265 0154 53 pushw %bx /* Buffer offset */ 266 0155 6A01 pushw $1 /* Sector count */ 267 0157 6A10 pushw $16 /* Size of packet */ 268 0159 89E6 movw %sp, %si 269 270 /* This chunk is skipped if we have ebios */ GAS LISTING /tmp/cc3Z1Wyl.s page 7 271 /* Do not clobber %es:%bx or %edx:%eax before this chunk! */ 272 read_sector_cbios: 273 015b 66F776DC divl -36(%bp) /* secpercyl */ 274 015f C0E406 shlb $6, %ah 275 0162 88E1 movb %ah, %cl 276 0164 88C5 movb %al, %ch 277 0166 92 xchgw %dx, %ax 278 0167 F676E0 divb -32(%bp) /* sectors */ 279 016a 88C6 movb %al, %dh 280 016c 08E1 orb %ah, %cl 281 016e 41 incw %cx /* Sectors are 1-based */ 282 016f B80102 movw $0x0201, %ax 283 284 read_common: 285 0172 8A5600 movb (%bp), %dl /* driveno */ 286 0175 CD13 int $0x13 287 0177 8D6410 leaw 16(%si), %sp /* Drop DAPA */ 288 017a 6661 popal 289 017c 720C jc disk_error 290 017e 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 0181 6683C001 addl $1,%eax 299 0185 6683D200 adcl $0,%edx 300 0189 C3 ret 301 302 disk_error: 303 018a E80C00 call error 304 018d 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 0199 5E popw %si 312 2: 313 019a AC lodsb 314 019b B40E movb $0x0e, %ah 315 019d 8A3E6204 movb (BIOS_page), %bh 316 01a1 B307 movb $0x07, %bl 317 01a3 CD10 int $0x10 /* May destroy %bp */ 318 01a5 3C0A cmpb $10, %al /* Newline? */ 319 01a7 75F1 jne 2b 320 321 01a9 CD18 int $0x18 /* Boot failure */ 322 die: 323 01ab F4 hlt 324 01ac EBFD jmp die GAS LISTING /tmp/cc3Z1Wyl.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:0000000000000172 read_common /var/www/html/boot/syslinux/mbr/gptmbr.S:272 .text:000000000000015b read_sector_cbios /var/www/html/boot/syslinux/mbr/gptmbr.S:250 .text:000000000000014a read_sector_phdr /var/www/html/boot/syslinux/mbr/gptmbr.S:153 .text:0000000000000086 get_ptab /var/www/html/boot/syslinux/mbr/gptmbr.S:260 .text:000000000000014d read_sector /var/www/html/boot/syslinux/mbr/gptmbr.S:163 .text:0000000000000090 find_part /var/www/html/boot/syslinux/mbr/gptmbr.S:175 .text:00000000000000ad not_this /var/www/html/boot/syslinux/mbr/gptmbr.S:186 .text:00000000000000c4 found_multiple /var/www/html/boot/syslinux/mbr/gptmbr.S:190 .text:00000000000000e3 found_part /var/www/html/boot/syslinux/mbr/gptmbr.S:182 .text:00000000000000b5 missing_os /var/www/html/boot/syslinux/mbr/gptmbr.S:310 .text:0000000000000199 error /var/www/html/boot/syslinux/mbr/gptmbr.S:243 .text:000000000000013e saturate_stosl /var/www/html/boot/syslinux/mbr/gptmbr.S:297 .text:0000000000000181 inc64 /var/www/html/boot/syslinux/mbr/gptmbr.S:225 .text:000000000000011d boot /var/www/html/boot/syslinux/mbr/gptmbr.S:302 .text:000000000000018a disk_error /var/www/html/boot/syslinux/mbr/gptmbr.S:322 .text:00000000000001ab die UNDEFINED SYMBOLS _phdr