GAS LISTING /tmp/ccTOt1EX.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/ccTOt1EX.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) 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 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: GAS LISTING /tmp/ccTOt1EX.s page 3 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 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 GAS LISTING /tmp/ccTOt1EX.s page 4 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 003a 60B402CD ADJUST_DRIVE 140 16A80461 140 7402B280 141 0046 52 pushw %dx /* -14: dl -> drive number */ 142 143 /* Copy down to 0:0x600 */ 144 0047 BE007C movw $0x7c00, %si 145 004a BF0000 movw $_start, %di 146 004d B90001 movw $(512/2), %cx 147 0050 F3A5 rep; movsw 148 149 0052 EA000000 ljmpw $0, $next 149 00 150 next: 151 152 /* Check to see if we have EBIOS */ 153 0057 52 pushw %dx /* drive number */ 154 0058 B441 movb $0x41, %ah /* %al == 0 already */ 155 005a BBAA55 movw $0x55aa, %bx 156 005d 31C9 xorw %cx, %cx 157 005f 30F6 xorb %dh, %dh 158 0061 F9 stc 159 0062 CD13 int $0x13 160 0064 7216 jc 1f 161 0066 81FB55AA cmpw $0xaa55, %bx 162 006a 7510 jne 1f 163 006c 83E101 andw $1,%cx /* Bit 0 = fixed disk subset */ 164 006f 740B jz 1f 165 166 /* We have EBIOS; patch in the following code at 167 read_sector_cbios: movb $0x42, %ah ; jmp read_common */ 168 0071 66C70600 movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \ 168 00B442EB GAS LISTING /tmp/ccTOt1EX.s page 5 168 15 169 (read_sector_cbios) 170 007a EB02 jmp 2f 171 1: 172 007c 31C9 xor %cx, %cx /* Clear EBIOS flag. */ 173 2: 174 007e 5A popw %dx 175 007f 51 pushw %cx /* EBIOS flag */ 176 177 /* Get (C)HS geometry */ 178 0080 B408 movb $0x08, %ah 179 0082 CD13 int $0x13 180 0084 5B popw %bx /* EBIOS flag */ 181 0085 0FB6C6 movzbw %dh, %ax /* dh = max head */ 182 0088 40 incw %ax /* From 0-based max to count */ 183 0089 50 pushw %ax /* -16: Save heads on the stack */ 184 008a 83E13F andw $0x3f, %cx /* Sector count */ 185 008d 51 pushw %cx /* -18: Save sectors on the stack */ 186 008e F7E1 mulw %cx /* Heads*sectors -> sectors per cylinder */ 187 188 0090 53 pushw %bx /* -20: EBIOS flag */ 189 190 /* Save sectors/cylinder on the stack */ 191 0091 52 pushw %dx /* -22: High word */ 192 0092 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 0093 BB007C movw $0x7c00, %bx 199 0096 B90400 movw $4, %cx /* Sector count */ 200 0099 66A10000 movl (lba_offset), %eax 201 202 2: 203 009d E84400 call read_sector 204 00a0 0F828000 jc disk_error 205 00a4 6640 incl %eax 206 00a6 80C702 addb $(512 >> 8), %bh 207 00a9 E2F2 loopw 2b 208 209 /* 210 * Okay, that actually worked... update the stack pointer 211 * and jump into isolinux.bin... 212 */ 213 00ab 66813E40 cmpl $HYBRID_MAGIC,(isolinux_hybrid_signature) 213 7CFBC078 213 70 214 00b4 7509 jne bad_signature 215 216 00b6 FA cli 217 00b7 BCEC7B movw $ebios_flag, %sp 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 * GAS LISTING /tmp/ccTOt1EX.s page 6 223 * Look more closely into it if we ever are short on space. 224 */ 225 00ba EA447C00 ljmpw $0, $isolinux_start_hybrid 225 00 226 227 bad_signature: 228 00bf E88300 call error 229 00c2 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 00e4 6660 pushal 237 00e6 6631D2 xorl %edx, %edx 238 00e9 660306F8 addl (partoffset), %eax 238 7B 239 00ee 661316FC adcl (partoffset+4), %edx 239 7B 240 00f3 6652 pushl %edx /* MSW of LBA */ 241 00f5 6650 pushl %eax /* LSW of LBA */ 242 00f7 06 pushw %es /* Buffer segment */ 243 00f8 53 pushw %bx /* Buffer offset */ 244 00f9 6A01 pushw $1 /* Sector count */ 245 00fb 6A10 pushw $16 /* Size of packet */ 246 00fd 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 00ff 66F736E8 divl (secpercyl) 252 7B 253 0104 C0E406 shlb $6, %ah 254 0107 88E1 movb %ah, %cl 255 0109 88C5 movb %al, %ch 256 010b 92 xchgw %dx, %ax 257 010c F636EE7B divb (sectors) 258 0110 88C6 movb %al, %dh 259 0112 08E1 orb %ah, %cl 260 0114 41 incw %cx /* Sectors are 1-based */ 261 0115 B80102 movw $0x0201, %ax 262 263 read_common: 264 0118 8A16F27B movb (driveno), %dl 265 011c CD13 int $0x13 266 011e 8D6410 leaw 16(%si), %sp /* Drop DAPA */ 267 0121 6661 popal 268 0123 C3 ret 269 270 disk_error: 271 0124 E81E00 call error GAS LISTING /tmp/ccTOt1EX.s page 7 272 0127 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 0145 5E popw %si 280 2: 281 0146 AC lodsb 282 0147 B40E movb $0x0e, %ah 283 0149 8A3E6204 movb (BIOS_page), %bh 284 014d B307 movb $0x07, %bl 285 014f CD10 int $0x10 /* May destroy %bp */ 286 0151 3C0A cmpb $10, %al /* Newline? */ 287 0153 75F1 jne 2b 288 289 0155 CD18 int $0x18 /* Boot failure */ 290 die: 291 0157 F4 hlt 292 0158 EBFD jmp die 293 294 /* Address of pointer to isolinux.bin */ 295 lba_offset = _start+432 GAS LISTING /tmp/ccTOt1EX.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:0000000000000057 next /var/www/html/boot/syslinux/mbr/isohdpfx.S:263 .text:0000000000000118 read_common /var/www/html/boot/syslinux/mbr/isohdpfx.S:251 .text:00000000000000ff 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:00000000000000e4 read_sector /var/www/html/boot/syslinux/mbr/isohdpfx.S:270 .text:0000000000000124 disk_error /var/www/html/boot/syslinux/mbr/isohdpfx.S:227 .text:00000000000000bf bad_signature /var/www/html/boot/syslinux/mbr/isohdpfx.S:278 .text:0000000000000145 error /var/www/html/boot/syslinux/mbr/isohdpfx.S:290 .text:0000000000000157 die NO UNDEFINED SYMBOLS