GAS LISTING /tmp/ccBMYMUB.s page 1 1 # 1 "/var/www/html/boot/syslinux/mbr/isohdppx.S" 1 #define PARTITION_SUPPORT 1 1 ... 0 0 2 #include "isohdpfx.S" 1 /* ----------------------------------------------------------------------- 2 * 3 * Copyright 2007-2009 H. Peter Anvin - All Rights Reserved 4 * Copyright 2009 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 /* 30 * Modified MBR code used on an ISO image in hybrid mode. 31 * 32 * This doesn't follow the El Torito spec at all -- it is just a stub 33 * loader of a hard-coded offset, but that's good enough to load 34 * ISOLINUX. 35 */ 36 37 #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 GAS LISTING /tmp/ccBMYMUB.s page 2 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. 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 38 39 .code16 40 .text 41 42 HYBRID_MAGIC = 0x7078c0fb 43 isolinux_hybrid_signature = 0x7c00+64 44 isolinux_start_hybrid = 0x7c00+64+4 45 46 .globl bootsec 47 /* Important: the top 6 words on the stack are passed to isolinux.bin */ 48 stack = 0x7c00 49 partoffset = (stack-8) 50 driveno = (stack-14) 51 heads = (stack-16) 52 sectors = (stack-18) 53 ebios_flag = (stack-20) 54 secpercyl = (stack-24) 55 56 BIOS_kbdflags = 0x417 GAS LISTING /tmp/ccBMYMUB.s page 3 57 BIOS_page = 0x462 58 59 /* gas/ld has issues with doing this as absolute addresses... */ 60 .section ".bootsec", "a", @nobits 61 .globl bootsec 62 bootsec: 63 0000 00000000 .space 512 63 00000000 63 00000000 63 00000000 63 00000000 64 65 .text 66 .globl _start 67 _start: 68 0000 33ED .byte 0x33, 0xed /* xorw %bp, %bp */ 69 0002 90 nop 70 0003 90 nop 71 0004 90 nop 72 0005 90 nop 73 0006 90 nop 74 0007 90 nop 75 0008 90 nop 76 0009 90 nop 77 000a 90 nop 78 000b 90 nop 79 000c 90 nop 80 000d 90 nop 81 000e 90 nop 82 000f 90 nop 83 0010 90 nop 84 0011 90 nop 85 0012 90 nop 86 0013 90 nop 87 0014 90 nop 88 0015 90 nop 89 0016 90 nop 90 0017 90 nop 91 0018 90 nop 92 0019 90 nop 93 001a 90 nop 94 001b 90 nop 95 001c 90 nop 96 001d 90 nop 97 001e 90 nop 98 001f 90 nop 99 0020 33ED .byte 0x33, 0xed /* xorw %bp, %bp */ 100 0022 FA cli 101 0023 8ED5 movw %bp, %ss 102 0025 BC007C movw $stack, %sp 103 0028 FB sti 104 0029 FC cld 105 106 /* Check to see if we have a partition table entry */ 107 002a 6631DB xorl %ebx, %ebx 108 002d 6631C9 xorl %ecx, %ecx 109 #ifdef PARTITION_SUPPORT GAS LISTING /tmp/ccBMYMUB.s page 4 110 0030 21F6 andw %si, %si /* %si == 0 -> no partition data */ 111 0032 7426 jz 1f 112 0034 F6047F testb $0x7f, (%si) /* Invalid active flag field? */ 113 0037 7521 jnz 1f 114 0039 384C04 cmpb %cl, 4(%si) /* Partition type zero == invalid? */ 115 003c 741C je 1f 116 003e 663D2147 cmpl $0x58504721, %eax /* !GPT signature in EAX? */ 116 5058 117 0044 7510 jne 2f 118 0046 807C04ED cmpb $0xed, 4(%si) /* EFI partition type? */ 119 004a 750A jne 2f 120 121 /* We have GPT partition information */ 122 004c 668B4C34 movl (32+20)(%si), %ecx 123 0050 668B5C38 movl (36+20)(%si), %ebx 124 0054 EB04 jmp 1f 125 126 /* We have non-GPT partition information */ 127 2: 128 0056 668B4C08 movl 8(%si), %ecx 129 #endif 130 1: 131 /* We have no partition information */ 132 005a 6653 pushl %ebx /* -4: partoffset_hi */ 133 005c 6651 pushl %ecx /* -8: partoffset_lo */ 134 005e 06 pushw %es /* -10: es:di -> $PnP header */ 135 005f 57 pushw %di /* -12: es:di -> $PnP header */ 136 137 0060 8EDD movw %bp, %ds 138 0062 8EC5 movw %bp, %es 139 140 0064 B280 ADJUST_DRIVE 141 0066 52 pushw %dx /* -14: dl -> drive number */ 142 143 /* Copy down to 0:0x600 */ 144 0067 BE007C movw $0x7c00, %si 145 006a BF0000 movw $_start, %di 146 006d B90001 movw $(512/2), %cx 147 0070 F3A5 rep; movsw 148 149 0072 EA000000 ljmpw $0, $next 149 00 150 next: 151 152 /* Check to see if we have EBIOS */ 153 0077 52 pushw %dx /* drive number */ 154 0078 B441 movb $0x41, %ah /* %al == 0 already */ 155 007a BBAA55 movw $0x55aa, %bx 156 007d 31C9 xorw %cx, %cx 157 007f 30F6 xorb %dh, %dh 158 0081 F9 stc 159 0082 CD13 int $0x13 160 0084 7216 jc 1f 161 0086 81FB55AA cmpw $0xaa55, %bx 162 008a 7510 jne 1f 163 008c 83E101 andw $1,%cx /* Bit 0 = fixed disk subset */ 164 008f 740B jz 1f GAS LISTING /tmp/ccBMYMUB.s page 5 165 166 /* We have EBIOS; patch in the following code at 167 read_sector_cbios: movb $0x42, %ah ; jmp read_common */ 168 0091 66C70600 movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \ 168 00B442EB 168 15 169 (read_sector_cbios) 170 009a EB02 jmp 2f 171 1: 172 009c 31C9 xor %cx, %cx /* Clear EBIOS flag. */ 173 2: 174 009e 5A popw %dx 175 009f 51 pushw %cx /* EBIOS flag */ 176 177 /* Get (C)HS geometry */ 178 00a0 B408 movb $0x08, %ah 179 00a2 CD13 int $0x13 180 00a4 5B popw %bx /* EBIOS flag */ 181 00a5 0FB6C6 movzbw %dh, %ax /* dh = max head */ 182 00a8 40 incw %ax /* From 0-based max to count */ 183 00a9 50 pushw %ax /* -16: Save heads on the stack */ 184 00aa 83E13F andw $0x3f, %cx /* Sector count */ 185 00ad 51 pushw %cx /* -18: Save sectors on the stack */ 186 00ae F7E1 mulw %cx /* Heads*sectors -> sectors per cylinder */ 187 188 00b0 53 pushw %bx /* -20: EBIOS flag */ 189 190 /* Save sectors/cylinder on the stack */ 191 00b1 52 pushw %dx /* -22: High word */ 192 00b2 50 pushw %ax /* -24: Low word */ 193 194 /* 195 * Load sectors. We do this one at a time mostly to avoid 196 * pitfalls and to share code with the stock MBR code. 197 */ 198 00b3 BB007C movw $0x7c00, %bx 199 00b6 B90400 movw $4, %cx /* Sector count */ 200 00b9 66A10000 movl (lba_offset), %eax 201 202 2: 203 00bd E84400 call read_sector 204 00c0 0F828000 jc disk_error 205 00c4 6640 incl %eax 206 00c6 80C702 addb $(512 >> 8), %bh 207 00c9 E2F2 loopw 2b 208 209 /* 210 * Okay, that actually worked... update the stack pointer 211 * and jump into isolinux.bin... 212 */ 213 00cb 66813E40 cmpl $HYBRID_MAGIC,(isolinux_hybrid_signature) 213 7CFBC078 213 70 214 00d4 7509 jne bad_signature 215 216 00d6 FA cli 217 00d7 BCEC7B movw $ebios_flag, %sp GAS LISTING /tmp/ccBMYMUB.s page 6 218 219 /* 220 * Use a ljmpw here to work around a bug in some unknown version 221 * of gas or ld when it comes to jumping to an absolute symbol... 222 * 223 * Look more closely into it if we ever are short on space. 224 */ 225 00da EA447C00 ljmpw $0, $isolinux_start_hybrid 225 00 226 227 bad_signature: 228 00df E88300 call error 229 00e2 69736F6C .ascii "isolinux.bin missing or corrupt.\r\n" 229 696E7578 229 2E62696E 229 206D6973 229 73696E67 230 231 /* 232 * read_sector: read a single sector pointed to by %eax to %es:%bx. 233 * CF is set on error. All registers saved. 234 */ 235 read_sector: 236 0104 6660 pushal 237 0106 6631D2 xorl %edx, %edx 238 0109 660306F8 addl (partoffset), %eax 238 7B 239 010e 661316FC adcl (partoffset+4), %edx 239 7B 240 0113 6652 pushl %edx /* MSW of LBA */ 241 0115 6650 pushl %eax /* LSW of LBA */ 242 0117 06 pushw %es /* Buffer segment */ 243 0118 53 pushw %bx /* Buffer offset */ 244 0119 6A01 pushw $1 /* Sector count */ 245 011b 6A10 pushw $16 /* Size of packet */ 246 011d 89E6 movw %sp, %si 247 248 /* This chunk is skipped if we have ebios */ 249 /* Do not clobber %eax before this chunk! */ 250 /* This also relies on %bx and %edx as set up above. */ 251 read_sector_cbios: 252 011f 66F736E8 divl (secpercyl) 252 7B 253 0124 C0E406 shlb $6, %ah 254 0127 88E1 movb %ah, %cl 255 0129 88C5 movb %al, %ch 256 012b 92 xchgw %dx, %ax 257 012c F636EE7B divb (sectors) 258 0130 88C6 movb %al, %dh 259 0132 08E1 orb %ah, %cl 260 0134 41 incw %cx /* Sectors are 1-based */ 261 0135 B80102 movw $0x0201, %ax 262 263 read_common: 264 0138 8A16F27B movb (driveno), %dl 265 013c CD13 int $0x13 266 013e 8D6410 leaw 16(%si), %sp /* Drop DAPA */ GAS LISTING /tmp/ccBMYMUB.s page 7 267 0141 6661 popal 268 0143 C3 ret 269 270 disk_error: 271 0144 E81E00 call error 272 0147 4F706572 .ascii "Operating system load error.\r\n" 272 6174696E 272 67207379 272 7374656D 272 206C6F61 273 274 /* 275 * Print error messages. This is invoked with "call", with the 276 * error message at the return address. 277 */ 278 error: 279 0165 5E popw %si 280 2: 281 0166 AC lodsb 282 0167 B40E movb $0x0e, %ah 283 0169 8A3E6204 movb (BIOS_page), %bh 284 016d B307 movb $0x07, %bl 285 016f CD10 int $0x10 /* May destroy %bp */ 286 0171 3C0A cmpb $10, %al /* Newline? */ 287 0173 75F1 jne 2b 288 289 0175 CD18 int $0x18 /* Boot failure */ 290 die: 291 0177 F4 hlt 292 0178 EBFD jmp die 293 294 /* Address of pointer to isolinux.bin */ 295 lba_offset = _start+432 296 ... GAS LISTING /tmp/ccBMYMUB.s page 8 DEFINED SYMBOLS /var/www/html/boot/syslinux/mbr/isohdpfx.S:42 *ABS*:000000007078c0fb HYBRID_MAGIC /var/www/html/boot/syslinux/mbr/isohdpfx.S:43 *ABS*:0000000000007c40 isolinux_hybrid_signature /var/www/html/boot/syslinux/mbr/isohdpfx.S:44 *ABS*:0000000000007c44 isolinux_start_hybrid /var/www/html/boot/syslinux/mbr/isohdpfx.S:62 .bootsec:0000000000000000 bootsec /var/www/html/boot/syslinux/mbr/isohdpfx.S:48 *ABS*:0000000000007c00 stack /var/www/html/boot/syslinux/mbr/isohdpfx.S:49 *ABS*:0000000000007bf8 partoffset /var/www/html/boot/syslinux/mbr/isohdpfx.S:50 *ABS*:0000000000007bf2 driveno /var/www/html/boot/syslinux/mbr/isohdpfx.S:51 *ABS*:0000000000007bf0 heads /var/www/html/boot/syslinux/mbr/isohdpfx.S:52 *ABS*:0000000000007bee sectors /var/www/html/boot/syslinux/mbr/isohdpfx.S:53 *ABS*:0000000000007bec ebios_flag /var/www/html/boot/syslinux/mbr/isohdpfx.S:54 *ABS*:0000000000007be8 secpercyl /var/www/html/boot/syslinux/mbr/isohdpfx.S:56 *ABS*:0000000000000417 BIOS_kbdflags /var/www/html/boot/syslinux/mbr/isohdpfx.S:57 *ABS*:0000000000000462 BIOS_page /var/www/html/boot/syslinux/mbr/isohdpfx.S:67 .text:0000000000000000 _start /var/www/html/boot/syslinux/mbr/isohdpfx.S:150 .text:0000000000000077 next /var/www/html/boot/syslinux/mbr/isohdpfx.S:263 .text:0000000000000138 read_common /var/www/html/boot/syslinux/mbr/isohdpfx.S:251 .text:000000000000011f read_sector_cbios /var/www/html/boot/syslinux/mbr/isohdpfx.S:67 .text:00000000000001b0 lba_offset /var/www/html/boot/syslinux/mbr/isohdpfx.S:235 .text:0000000000000104 read_sector /var/www/html/boot/syslinux/mbr/isohdpfx.S:270 .text:0000000000000144 disk_error /var/www/html/boot/syslinux/mbr/isohdpfx.S:227 .text:00000000000000df bad_signature /var/www/html/boot/syslinux/mbr/isohdpfx.S:278 .text:0000000000000165 error /var/www/html/boot/syslinux/mbr/isohdpfx.S:290 .text:0000000000000177 die NO UNDEFINED SYMBOLS