GAS LISTING /tmp/ccvLWzVj.s page 1 1 # 1 "/var/www/html/boot/syslinux/mbr/isohdpfx.S" 1 /* ----------------------------------------------------------------------- 1 ... 0 0 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 15 * be included in all copies or substantial portions of the Software. 16 * GAS LISTING /tmp/ccvLWzVj.s page 2 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 53 .macro ADJUST_DRIVE 54 .endm 55 #endif 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 GAS LISTING /tmp/ccvLWzVj.s page 3 56 BIOS_kbdflags = 0x417 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 GAS LISTING /tmp/ccvLWzVj.s page 4 109 #ifdef PARTITION_SUPPORT 110 andw %si, %si /* %si == 0 -> no partition data */ 111 jz 1f 112 testb $0x7f, (%si) /* Invalid active flag field? */ 113 jnz 1f 114 cmpb %cl, 4(%si) /* Partition type zero == invalid? */ 115 je 1f 116 cmpl $0x58504721, %eax /* !GPT signature in EAX? */ 117 jne 2f 118 cmpb $0xed, 4(%si) /* EFI partition type? */ 119 jne 2f 120 121 /* We have GPT partition information */ 122 movl (32+20)(%si), %ecx 123 movl (36+20)(%si), %ebx 124 jmp 1f 125 126 /* We have non-GPT partition information */ 127 2: 128 movl 8(%si), %ecx 129 #endif 130 1: 131 /* We have no partition information */ 132 0030 6653 pushl %ebx /* -4: partoffset_hi */ 133 0032 6651 pushl %ecx /* -8: partoffset_lo */ 134 0034 06 pushw %es /* -10: es:di -> $PnP header */ 135 0035 57 pushw %di /* -12: es:di -> $PnP header */ 136 137 0036 8EDD movw %bp, %ds 138 0038 8EC5 movw %bp, %es 139 140 ADJUST_DRIVE 141 003a 52 pushw %dx /* -14: dl -> drive number */ 142 143 /* Copy down to 0:0x600 */ 144 003b BE007C movw $0x7c00, %si 145 003e BF0000 movw $_start, %di 146 0041 B90001 movw $(512/2), %cx 147 0044 F3A5 rep; movsw 148 149 0046 EA000000 ljmpw $0, $next 149 00 150 next: 151 152 /* Check to see if we have EBIOS */ 153 004b 52 pushw %dx /* drive number */ 154 004c B441 movb $0x41, %ah /* %al == 0 already */ 155 004e BBAA55 movw $0x55aa, %bx 156 0051 31C9 xorw %cx, %cx 157 0053 30F6 xorb %dh, %dh 158 0055 F9 stc 159 0056 CD13 int $0x13 160 0058 7216 jc 1f 161 005a 81FB55AA cmpw $0xaa55, %bx 162 005e 7510 jne 1f 163 0060 83E101 andw $1,%cx /* Bit 0 = fixed disk subset */ 164 0063 740B jz 1f GAS LISTING /tmp/ccvLWzVj.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 0065 66C70600 movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \ 168 00B442EB 168 15 169 (read_sector_cbios) 170 006e EB02 jmp 2f 171 1: 172 0070 31C9 xor %cx, %cx /* Clear EBIOS flag. */ 173 2: 174 0072 5A popw %dx 175 0073 51 pushw %cx /* EBIOS flag */ 176 177 /* Get (C)HS geometry */ 178 0074 B408 movb $0x08, %ah 179 0076 CD13 int $0x13 180 0078 5B popw %bx /* EBIOS flag */ 181 0079 0FB6C6 movzbw %dh, %ax /* dh = max head */ 182 007c 40 incw %ax /* From 0-based max to count */ 183 007d 50 pushw %ax /* -16: Save heads on the stack */ 184 007e 83E13F andw $0x3f, %cx /* Sector count */ 185 0081 51 pushw %cx /* -18: Save sectors on the stack */ 186 0082 F7E1 mulw %cx /* Heads*sectors -> sectors per cylinder */ 187 188 0084 53 pushw %bx /* -20: EBIOS flag */ 189 190 /* Save sectors/cylinder on the stack */ 191 0085 52 pushw %dx /* -22: High word */ 192 0086 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 0087 BB007C movw $0x7c00, %bx 199 008a B90400 movw $4, %cx /* Sector count */ 200 008d 66A10000 movl (lba_offset), %eax 201 202 2: 203 0091 E84400 call read_sector 204 0094 0F828000 jc disk_error 205 0098 6640 incl %eax 206 009a 80C702 addb $(512 >> 8), %bh 207 009d E2F2 loopw 2b 208 209 /* 210 * Okay, that actually worked... update the stack pointer 211 * and jump into isolinux.bin... 212 */ 213 009f 66813E40 cmpl $HYBRID_MAGIC,(isolinux_hybrid_signature) 213 7CFBC078 213 70 214 00a8 7509 jne bad_signature 215 216 00aa FA cli 217 00ab BCEC7B movw $ebios_flag, %sp GAS LISTING /tmp/ccvLWzVj.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 00ae EA447C00 ljmpw $0, $isolinux_start_hybrid 225 00 226 227 bad_signature: 228 00b3 E88300 call error 229 00b6 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 00d8 6660 pushal 237 00da 6631D2 xorl %edx, %edx 238 00dd 660306F8 addl (partoffset), %eax 238 7B 239 00e2 661316FC adcl (partoffset+4), %edx 239 7B 240 00e7 6652 pushl %edx /* MSW of LBA */ 241 00e9 6650 pushl %eax /* LSW of LBA */ 242 00eb 06 pushw %es /* Buffer segment */ 243 00ec 53 pushw %bx /* Buffer offset */ 244 00ed 6A01 pushw $1 /* Sector count */ 245 00ef 6A10 pushw $16 /* Size of packet */ 246 00f1 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 00f3 66F736E8 divl (secpercyl) 252 7B 253 00f8 C0E406 shlb $6, %ah 254 00fb 88E1 movb %ah, %cl 255 00fd 88C5 movb %al, %ch 256 00ff 92 xchgw %dx, %ax 257 0100 F636EE7B divb (sectors) 258 0104 88C6 movb %al, %dh 259 0106 08E1 orb %ah, %cl 260 0108 41 incw %cx /* Sectors are 1-based */ 261 0109 B80102 movw $0x0201, %ax 262 263 read_common: 264 010c 8A16F27B movb (driveno), %dl 265 0110 CD13 int $0x13 266 0112 8D6410 leaw 16(%si), %sp /* Drop DAPA */ GAS LISTING /tmp/ccvLWzVj.s page 7 267 0115 6661 popal 268 0117 C3 ret 269 270 disk_error: 271 0118 E81E00 call error 272 011b 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 0139 5E popw %si 280 2: 281 013a AC lodsb 282 013b B40E movb $0x0e, %ah 283 013d 8A3E6204 movb (BIOS_page), %bh 284 0141 B307 movb $0x07, %bl 285 0143 CD10 int $0x10 /* May destroy %bp */ 286 0145 3C0A cmpb $10, %al /* Newline? */ 287 0147 75F1 jne 2b 288 289 0149 CD18 int $0x18 /* Boot failure */ 290 die: 291 014b F4 hlt 292 014c EBFD jmp die 293 294 /* Address of pointer to isolinux.bin */ 295 lba_offset = _start+432 GAS LISTING /tmp/ccvLWzVj.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:000000000000004b next /var/www/html/boot/syslinux/mbr/isohdpfx.S:263 .text:000000000000010c read_common /var/www/html/boot/syslinux/mbr/isohdpfx.S:251 .text:00000000000000f3 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:00000000000000d8 read_sector /var/www/html/boot/syslinux/mbr/isohdpfx.S:270 .text:0000000000000118 disk_error /var/www/html/boot/syslinux/mbr/isohdpfx.S:227 .text:00000000000000b3 bad_signature /var/www/html/boot/syslinux/mbr/isohdpfx.S:278 .text:0000000000000139 error /var/www/html/boot/syslinux/mbr/isohdpfx.S:290 .text:000000000000014b die NO UNDEFINED SYMBOLS