wok-6.x annotate ipxe/stuff/lkrnprefix.S @ rev 16892

libwebkit-video: typo
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Mon Jul 14 13:34:17 2014 +0300 (2014-07-14)
parents 6c3718ca17b6
children 6aed6fc5819d
rev   line source
pascal@15368 1 /*
pascal@15368 2 Copyright (C) 2000, Entity Cyber, Inc.
pascal@15368 3
pascal@15368 4 Authors: Gary Byers (gb@thinguin.org)
pascal@15368 5 Marty Connor (mdc@thinguin.org)
pascal@15368 6
pascal@15368 7 This software may be used and distributed according to the terms
pascal@15368 8 of the GNU Public License (GPL), incorporated herein by reference.
pascal@15368 9
pascal@15368 10 Description:
pascal@15368 11
pascal@15368 12 This is just a little bit of code and data that can get prepended
pascal@15368 13 to a ROM image in order to allow bootloaders to load the result
pascal@15368 14 as if it were a Linux kernel image.
pascal@15368 15
pascal@15368 16 A real Linux kernel image consists of a one-sector boot loader
pascal@15368 17 (to load the image from a floppy disk), followed a few sectors
pascal@15368 18 of setup code, followed by the kernel code itself. There's
pascal@15368 19 a table in the first sector (starting at offset 497) that indicates
pascal@15368 20 how many sectors of setup code follow the first sector and which
pascal@15368 21 contains some other parameters that aren't interesting in this
pascal@15368 22 case.
pascal@15368 23
pascal@15368 24 We don't require much in the way of setup code. Historically, the
pascal@15368 25 Linux kernel required at least 4 sectors of setup code.
pascal@15368 26 Therefore, at least 4 sectors must be present even though we don't
pascal@15368 27 use them.
pascal@15368 28
pascal@15368 29 */
pascal@15368 30
pascal@15368 31 FILE_LICENCE ( GPL_ANY )
pascal@15368 32
pascal@15368 33 #define SETUPSECS 4 /* Minimal nr of setup-sectors */
pascal@15368 34 #define PREFIXSIZE ((SETUPSECS+1)*512)
pascal@15368 35 #define PREFIXPGH (PREFIXSIZE / 16 )
pascal@15368 36 #define BOOTSEG 0x07C0 /* original address of boot-sector */
pascal@15368 37 #define INITSEG 0x9000 /* we move boot here - out of the way */
pascal@15368 38 #define SETUPSEG 0x9020 /* setup starts here */
pascal@15368 39 #define SYSSEG 0x1000 /* system loaded at 0x10000 (65536). */
pascal@15368 40
pascal@15368 41 .text
pascal@15368 42 .code16
pascal@15368 43 .arch i386
pascal@15368 44 .org 0
pascal@15368 45 .section ".prefix", "ax", @progbits
pascal@15368 46 .globl _lkrn_start
pascal@15368 47 _lkrn_start:
pascal@15368 48
pascal@15368 49 bootsector:
pascal@15368 50 _start:
pascal@15368 51
pascal@15368 52 /* some extra features */
pascal@15368 53 #define EXE_SUPPORT real mode dos .exe file support
pascal@15368 54
pascal@15368 55 #define EXEADRS(x) (x+0xE0)
pascal@15368 56
pascal@15368 57 /* some contraints to reduce the size */
pascal@15368 58 //#define FLOPPY_1440K_ONLY 1.44M floppies support only
pascal@15368 59
pascal@15368 60 #ifdef EXE_SUPPORT
pascal@15368 61 /* Initial temporary stack size */
pascal@15368 62 #define EXE_STACK_SIZE 0x400
pascal@15368 63
pascal@15368 64 /* Temporary decompression area (avoid DOS high memory area) */
pascal@15368 65 #define EXE_DECOMPRESS_ADDRESS 0x110000
pascal@15368 66
pascal@15368 67 /* Fields within the Program Segment Prefix */
pascal@15368 68 #define PSP_CMDLINE_LEN 0x80
pascal@15368 69 #define PSP_CMDLINE_START 0x81
pascal@15368 70
pascal@15368 71 #define HEADER_SIZE 0x20
pascal@15368 72
pascal@15368 73 signature:
pascal@15368 74 decw %bp // Magic number: MZ
pascal@15368 75 popw %dx
pascal@15368 76 jmp start // Bytes on last page of file
pascal@15368 77 blocks:
pascal@15368 78 .word 0 // Pages in file
pascal@15368 79 .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
pascal@15368 80 .ascii "ADDW"
pascal@15368 81 .long blocks
pascal@15368 82 .long 512
pascal@15368 83 .long 0
pascal@15368 84 .previous
pascal@15368 85 .word 0 // Relocations
pascal@15368 86 .word ( HEADER_SIZE / 16 ) // Size of header in paragraphs
pascal@15368 87 .word ( EXE_STACK_SIZE / 16 ) // Minimum extra paragraphs needed
pascal@15368 88 .word ( EXE_STACK_SIZE / 16 ) // Maximum extra paragraphs needed
pascal@15368 89 init_ss:
pascal@15368 90 .word -( ( _exe_start - signature ) / 16 ) // Initial (relative) SS value
pascal@15368 91 .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
pascal@15368 92 .ascii "ADDW"
pascal@15368 93 .long init_ss
pascal@15368 94 .long 16
pascal@15368 95 .long 0
pascal@15368 96 .previous
pascal@15368 97 .word EXE_STACK_SIZE // Initial SP value
pascal@15368 98 .word 0 // Checksum
pascal@15368 99 .word _exe_start // Initial IP value
pascal@15368 100 /* Initial code segment (relative to start of executable) */
pascal@15368 101 .word -( HEADER_SIZE / 16 ) // Initial (relative) CS value
pascal@15368 102 // .word 0x001C // File address of relocation table
pascal@15368 103 // .word 0,0,0 // Overlay number
pascal@15368 104
pascal@15368 105 start:
pascal@15368 106 pushw %dx
pascal@15368 107 #endif
pascal@15368 108 cld # assume nothing
pascal@15368 109 stacktop = 0x9E00 # in 0x8000 .. 0xA000
pascal@15368 110 zeroed = 12 # zeroed registers
pascal@15368 111 movw $stacktop-12-zeroed, %di # stacktop is an arbitrary value >=
pascal@15368 112 # length of bootsect + length of
pascal@15368 113 # setup + room for stack;
pascal@15368 114 # 12 is disk parm size.
pascal@15368 115 pushw $INITSEG
pascal@15368 116 popw %ss # %ss contain INITSEG
pascal@15368 117 movw %di, %sp # put stack at INITSEG:stacktop-...
pascal@15368 118
pascal@15368 119 # Many BIOS's default disk parameter tables will not recognize
pascal@15368 120 # multi-sector reads beyond the maximum sector number specified
pascal@15368 121 # in the default diskette parameter tables - this may mean 7
pascal@15368 122 # sectors in some cases.
pascal@15368 123 #
pascal@15368 124 # Since single sector reads are slow and out of the question,
pascal@15368 125 # we must take care of this by creating new parameter tables
pascal@15368 126 # (for the first disk) in RAM. We can set the maximum sector
pascal@15368 127 # count to 36 - the most we will encounter on an ED 2.88.
pascal@15368 128 #
pascal@15368 129 # High doesn't hurt. Low does. Let's use the max: 63
pascal@15368 130
pascal@15368 131 pushw %ss
pascal@15368 132 popw %es # %es = %ss = INITSEG
pascal@15368 133 xorw %ax, %ax # %ax = 0
pascal@15472 134 #ifdef EXE_SUPPORT
pascal@15472 135 cwd # %dx = 0
pascal@15472 136 #endif
pascal@15368 137 movw $zeroed/2, %cx # clear gdt + offset, %ds, limits
pascal@15368 138 rep # don't worry about cld
pascal@15368 139 stosw # already done above
pascal@15368 140 popw %bx # offset = 0
pascal@15368 141 popw %ds # %ds = 0
pascal@15368 142 popw %fs # %fs = 0
pascal@15368 143
pascal@15368 144 movb setup_sects+0x7C00, %al # read bootsector + setup (%ds = 0)
pascal@15368 145 incw %ax
pascal@15368 146
pascal@15368 147 ldsw 0x78(%bx), %si # %ds:%bx+0x78 is parameter table address
pascal@15368 148 pushw %es
pascal@15368 149 pushw %di
pascal@15368 150 movb $6, %cl # copy 12 bytes
pascal@15368 151 rep # don't worry about cld
pascal@15368 152 movsw # already done above
pascal@15368 153 pushw %ss
pascal@15368 154 popw %ds # now %ds = %es = %ss = INITSEG
pascal@15368 155 popl %fs:0x78(%bx) # update parameter table address
pascal@15368 156 movb $63, 0x4-12(%di) # patch sector count, %di = stacktop
pascal@15368 157 cli
pascal@15368 158
pascal@15368 159 xchg %ax, %di # sector count
pascal@15368 160 popw %ax # limits = 0
pascal@15368 161 incw %cx # cylinder 0, sector 1, clear Z
pascal@15368 162 call read_first_sectors # read setup
pascal@15368 163
pascal@15368 164 # This routine loads the system at address LOADSEG, making sure
pascal@15368 165 # no 64kB boundaries are crossed. We try to load it as fast as
pascal@15368 166 # possible, loading whole tracks whenever we can.
pascal@15368 167
pascal@15368 168 popw %bx # clear %bx
pascal@15368 169 movw syssize, %di
pascal@15368 170 addw $(512/16)-1, %di
pascal@15368 171 shrw $9-4, %di
pascal@15368 172 movw $SYSSEG, %cx
pascal@15368 173 call read_sectorsCX
pascal@15368 174
pascal@15368 175 # This procedure turns off the floppy drive motor, so
pascal@15368 176 # that we enter the kernel in a known state, and
pascal@15368 177 # don't have to worry about it later.
pascal@15368 178
pascal@15368 179 kill_motor:
pascal@15368 180 xchgw %ax, %di # reset FDC (%di < 128)
pascal@15368 181 int $0x13
pascal@15368 182
pascal@15368 183 # After that (everything loaded), we jump to the setup-routine
pascal@15368 184 # loaded directly after the bootblock:
pascal@15368 185 # Segments are as follows: %ds = %ss = INITSEG
pascal@15368 186
pascal@15368 187 ljmp $SETUPSEG, $0
pascal@15368 188
pascal@15368 189 #ifdef EXE_SUPPORT
pascal@15368 190 dosexit:
pascal@15368 191 movw $0x4c00, %ax
pascal@15368 192 int $0x21
pascal@15368 193
pascal@15368 194 _exe_start:
pascal@15368 195 pushw $dosexit
pascal@15368 196 movw $EXEADRS(need386), %si
pascal@15368 197 pushfw // save flags
pascal@15368 198 // bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
pascal@15368 199 // flags 0 NT IOPL OF DF IF TF SF ZF 0 AF 0 PF 1 CF
pascal@15368 200 movb $0x10, %ah // DF = IF = TF = 0
pascal@15368 201 pushw %ax
pascal@15368 202 popfw // < 286 : flags[12..15] are forced 1
pascal@15368 203 pushfw // = 286 : flags[12..15] are forced 0
pascal@15368 204 popw %cx // > 286 : only flags[15] is forced 0
pascal@15368 205 popfw // restore flags
pascal@15485 206 cmpb %ah, %ch // test Fx and 0x cases
pascal@15485 207 js puts // S= not 386+
pascal@15368 208 // smsww %ax
pascal@15368 209 // andb $1, %al
pascal@15368 210 // jne puts
pascal@15368 211
pascal@15368 212 /* Terminate command line with a NUL */
pascal@15368 213 movzbw PSP_CMDLINE_LEN, %si
pascal@15368 214 movb $0, PSP_CMDLINE_START(%si)
pascal@15368 215 cmpb $'?', PSP_CMDLINE_START-1(%si)
pascal@15368 216 je help
pascal@15368 217 pushw %si
pascal@15368 218
pascal@15368 219 /* Install iPXE. Use a fixed temporary decompression area to
pascal@15368 220 * avoid trashing the DOS high memory area.
pascal@15368 221 */
pascal@15368 222 call alloc_basemem
pascal@15368 223 movl $EXE_DECOMPRESS_ADDRESS, %edi
pascal@15368 224 stc
pascal@15368 225 sbbl %ebp, %ebp /* Allow arbitrary relocation */
pascal@15368 226 xorl %esi, %esi
pascal@15368 227 call install_prealloc
pascal@15368 228
pascal@15368 229 xorl %ebp, %ebp
pascal@15368 230 xorl %ecx, %ecx
pascal@15368 231
pascal@15368 232 /* Calculate command line physical address */
pascal@15368 233 xorl %edx, %edx
pascal@15368 234 movw %ds, %dx
pascal@15368 235 shll $4, %edx
pascal@15368 236 popw %si
pascal@15368 237 orw %si, %si
pascal@15368 238 jne gotarg
pascal@15368 239 movw $EXEADRS(default_config), %bp
pascal@15368 240 addl %edx, %ebp
pascal@15368 241 movw $0xA00-default_config, %cx
pascal@15368 242 gotarg:
pascal@15368 243 addl $PSP_CMDLINE_START, %edx
pascal@15368 244
pascal@15368 245 jmp start_ipxe
pascal@15368 246
pascal@15368 247 help:
pascal@15368 248 movw $EXEADRS(helpmsg), %si
pascal@15368 249 puts:
pascal@15368 250 lodsb
pascal@15368 251 orb %al, %al
pascal@15368 252 je exit
pascal@15368 253 call putc
pascal@15368 254 jmp puts
pascal@15368 255 #endif
pascal@15368 256
pascal@15368 257 putcdot:
pascal@15368 258 movb $0x2E, %al
pascal@15368 259 putc:
pascal@15368 260 movb $0xE, %ah
pascal@15368 261 movw $7, %bx
pascal@15368 262 int $0x10
pascal@15368 263 exit:
pascal@15368 264 ret
pascal@15368 265
pascal@15368 266
pascal@15368 267 # read_sectors reads %di sectors into %es:0 buffer.
pascal@15368 268 # %es:0 is updated to the next memory location.
pascal@15368 269 # First, sectors are read sector by sector until
pascal@15368 270 # sector per track count is known. Then they are
pascal@15368 271 # read track by track.
pascal@15368 272 # Assume no error on first track.
pascal@15368 273
pascal@15368 274 #ifdef FLOPPY_1440K_ONLY
pascal@15368 275 #define FLOPPY_HEADS 2 /* 2 heads */
pascal@15368 276 #define FLOPPY_SECTORS 18 /* 18 sectors */
pascal@15368 277 #else
pascal@15368 278 #define FLOPPY_HEADS 2 /* 2 heads minimum */
pascal@15368 279 #define FLOPPY_SECTORS 9 /* 9 sectors minimum */
pascal@15368 280 #endif
pascal@15368 281
pascal@15368 282 check_limits:
pascal@15368 283 #ifndef FLOPPY_1440K_ONLY
pascal@15368 284 popw %dx
pascal@15368 285 #ifdef FLOPPY_SECTORS
pascal@15368 286 cmpb $FLOPPY_SECTORS+1, %cl # minimum sector count
pascal@15368 287 jb check_head
pascal@15368 288 #endif
pascal@15368 289 cmpb %al, %cl # max sector known ?
pascal@15368 290 ja next_head # no -> store it
pascal@15368 291 check_head:
pascal@15368 292 #ifdef FLOPPY_HEADS
pascal@15368 293 cmpb $FLOPPY_HEADS, %dh # 2 heads minimum
pascal@15368 294 jb check_cylinder
pascal@15368 295 #endif
pascal@15368 296 cmpb %ah, %dh # max head known ?
pascal@15368 297 ja next_cylinder # no -> store it
pascal@15368 298 check_cylinder:
pascal@15368 299 #endif
pascal@15368 300 pushaw
pascal@15368 301 #ifndef FLOPPY_1440K_ONLY
pascal@15368 302 cbw # %ah = 0
pascal@15368 303 #endif
pascal@15368 304 int $0x13 # reset controler
pascal@15368 305 popaw
pascal@15368 306 movb $1, %al # sector by sector...
pascal@15368 307 read_sectorslp:
pascal@15368 308 pushw %dx # some bios break dx...
pascal@15368 309 #ifndef FLOPPY_1440K_ONLY
pascal@15368 310 pushw %ax # limits
pascal@15368 311 subb %cl, %al # sectors remaining in track
pascal@15368 312 ja tolastsect
pascal@15368 313 movb $1, %al # 1 sector mini
pascal@15368 314 tolastsect:
pascal@15368 315 #else
pascal@15368 316 mov $FLOPPY_SECTORS+1, %al
pascal@15368 317 subb %cl, %al # sectors remaining in track
pascal@15368 318 #endif
pascal@15368 319 cbw
pascal@15368 320 cmpw %di, %ax
pascal@15368 321 jb more1trk
pascal@15368 322 movw %di, %ax # sectors to read
pascal@15368 323 more1trk:
pascal@15368 324 pushw %ax # save context
pascal@15368 325 movb $2, %ah # cmd: read chs
pascal@15368 326 int $0x13
pascal@15368 327 #ifndef FLOPPY_1440K_ONLY
pascal@15368 328 popw %dx # save %ax
pascal@15368 329 popw %ax # limits
pascal@15368 330 #else
pascal@15368 331 popw %ax # restore context
pascal@15368 332 popw %dx
pascal@15368 333 #endif
pascal@15368 334 jc check_limits
pascal@15368 335 #ifndef FLOPPY_1440K_ONLY
pascal@15368 336 xchgw %ax, %bp
pascal@15368 337 addw %dx,%cx # next sector
pascal@15368 338 movw %cx, %gs
pascal@15368 339 movw %es, %cx
pascal@15368 340 pushw %dx
pascal@15368 341 shlw $5, %dx
pascal@15368 342 addw %dx, %cx
pascal@15368 343 popw %dx
pascal@15368 344 subw %dx,%di # update sector counter
pascal@15368 345 popw %dx
pascal@15368 346 read_sectorsCX:
pascal@15368 347 movw %cx, %es # next location
pascal@15368 348 jz putcdot
pascal@15368 349 #else
pascal@15368 350 addw %ax,%cx # next sector
pascal@15368 351 movw %cx, %gs
pascal@15368 352 movw %es, %cx
pascal@15368 353 pushw %ax
pascal@15368 354 shlw $5, %ax
pascal@15368 355 addw %ax, %cx
pascal@15368 356 popw %ax
pascal@15368 357 subw %ax,%di # update sector counter
pascal@15368 358 read_sectorsCX:
pascal@15368 359 movw %cx, %es # next location
pascal@15368 360 jz putcdot
pascal@15368 361 #endif
pascal@15368 362 read_sectors:
pascal@15368 363 movw %gs, %cx
pascal@15368 364 #ifndef FLOPPY_1440K_ONLY
pascal@15368 365 # al is last sector+1
pascal@15368 366 # ah is last cylinder+1
pascal@15368 367 xchgw %ax, %bp
pascal@15368 368 #endif
pascal@15368 369 #ifndef FLOPPY_1440K_ONLY
pascal@15368 370 cmpb %al,%cl # reach sector limit ?
pascal@15368 371 jne bdendlp
pascal@15368 372 next_head:
pascal@15368 373 movb %cl,%al
pascal@15368 374 #else
pascal@15368 375 cmpb $FLOPPY_SECTORS+1,%cl # reach sector limit ?
pascal@15368 376 jne bdendlp
pascal@15368 377 #endif
pascal@15368 378 incb %dh # next head
pascal@15368 379 movb $1,%cl # first sector
pascal@15368 380 #ifndef FLOPPY_1440K_ONLY
pascal@15368 381 cmpb %ah, %dh # reach head limit ?
pascal@15368 382 jne bdendlp
pascal@15368 383 next_cylinder:
pascal@15368 384 movb %dh,%ah
pascal@15368 385 #else
pascal@15368 386 cmpb %cl,%dh # reach head limit ?
pascal@15368 387 je bdendlp
pascal@15368 388 #endif
pascal@15368 389 # NOTE : support 256 cylinders max
pascal@15368 390 incb %ch # next cylinder
pascal@15368 391 read_first_sectors:
pascal@15368 392 movb $0,%dh # first head
pascal@15368 393 bdendlp:
pascal@15368 394 jmp read_sectorslp
pascal@15368 395
pascal@15368 396 #ifdef EXE_SUPPORT
pascal@15368 397 need386:
pascal@15368 398 .ascii "No 386+."
pascal@15368 399 .byte 13,10
pascal@15368 400 .byte 0
pascal@15368 401 helpmsg:
pascal@15368 402 .ascii "No help available."
pascal@15368 403 .byte 13,10
pascal@15368 404 .byte 0
pascal@15368 405 #endif
pascal@15368 406
pascal@15368 407 /*
pascal@15368 408 The following header is documented in the Linux source code at
pascal@15368 409 Documentation/x86/boot.txt
pascal@15368 410 */
pascal@15368 411 .org 497
pascal@15368 412 setup_sects:
pascal@15368 413 .byte SETUPSECS
pascal@15368 414 root_flags:
pascal@15368 415 .word 0
pascal@15368 416 syssize:
pascal@15368 417 .long -PREFIXPGH
pascal@15368 418
pascal@15368 419 .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
pascal@15368 420 .ascii "ADDL"
pascal@15368 421 .long syssize
pascal@15368 422 .long 16
pascal@15368 423 .long 0
pascal@15368 424 .previous
pascal@15368 425
pascal@15368 426 ram_size:
pascal@15368 427 .word 0
pascal@15368 428 vid_mode:
pascal@15368 429 .word 0
pascal@15368 430 root_dev:
pascal@15368 431 .word 0
pascal@15368 432 boot_flag:
pascal@15368 433 .word 0xAA55
pascal@15368 434 jump:
pascal@15368 435 /* Manually specify a two-byte jmp instruction here rather
pascal@15368 436 * than leaving it up to the assembler. */
pascal@15368 437 .byte 0xeb
pascal@15368 438 .byte setup_code - header
pascal@15368 439 header:
pascal@15368 440 .byte 'H', 'd', 'r', 'S'
pascal@15368 441 version:
pascal@15368 442 .word 0x0207 /* 2.07 */
pascal@15368 443 realmode_swtch:
pascal@15368 444 .long 0
pascal@15368 445 start_sys:
pascal@15368 446 .word 0
pascal@15368 447 kernel_version:
pascal@15368 448 .word 0
pascal@15368 449 type_of_loader:
pascal@15368 450 .byte 0
pascal@15368 451 loadflags:
pascal@15368 452 .byte 0
pascal@15368 453 setup_move_size:
pascal@15368 454 .word 0
pascal@15368 455 code32_start:
pascal@15368 456 .long SYSSEG*16
pascal@15368 457 ramdisk_image:
pascal@15368 458 .long 0
pascal@15368 459 ramdisk_size:
pascal@15368 460 .long 0
pascal@15368 461 bootsect_kludge:
pascal@15368 462 .long 0
pascal@15368 463 heap_end_ptr:
pascal@15368 464 .word 0
pascal@15368 465 pad1:
pascal@15368 466 .word 0
pascal@15368 467 cmd_line_ptr:
pascal@15368 468 .long 0
pascal@15368 469 initrd_addr_max:
pascal@15368 470 /* We don't use an initrd but some bootloaders (e.g. SYSLINUX) have
pascal@15368 471 * been known to require this field. Set the value to 2 GB. This
pascal@15368 472 * value is also used by the Linux kernel. */
pascal@15368 473 .long 0x7fffffff
pascal@15368 474 kernel_alignment:
pascal@15368 475 .long 0
pascal@15368 476 relocatable_kernel:
pascal@15368 477 .byte 0
pascal@15368 478 pad2:
pascal@15368 479 .byte 0, 0, 0
pascal@15368 480 cmdline_size:
pascal@15368 481 .long 0x7ff
pascal@15368 482 hardware_subarch:
pascal@15368 483 .long 0
pascal@15368 484 hardware_subarch_data:
pascal@15368 485 .byte 0, 0, 0, 0, 0, 0, 0, 0
pascal@15368 486
pascal@15368 487 /*
pascal@15368 488 We don't need to do too much setup.
pascal@15368 489
pascal@15368 490 This code gets loaded at SETUPSEG:0. It wants to start
pascal@15368 491 executing the image that's loaded at SYSSEG:0 and
pascal@15368 492 whose entry point is SYSSEG:0.
pascal@15368 493 */
pascal@15368 494 setup_code:
pascal@15368 495 movl ramdisk_image, %eax
pascal@15368 496 orl %eax, %eax
pascal@15368 497 jnz setup_done
pascal@15368 498
pascal@15368 499 movw $default_config, %di
pascal@15368 500 movw $-1, %bx
pascal@15368 501
pascal@15368 502 movw $9, %cx
pascal@15368 503 1:
pascal@15368 504 pushw %ax
pascal@15368 505 loop 1b
pascal@15368 506 pushw $0x9310
pascal@15368 507 pushw %ax
pascal@15368 508 pushw %bx
pascal@15368 509 pushw %ax
pascal@15368 510 pushw $0x9300+(INITSEG>>12)
pascal@15368 511 pushw %di
pascal@15368 512 pushw %bx
pascal@15368 513 movb $8, %cl
pascal@15368 514 1:
pascal@15368 515 pushw %ax
pascal@15368 516 loop 1b
pascal@15368 517 1:
pascal@15368 518 incw %bx
pascal@15368 519 cmpb %al, (%bx,%di)
pascal@15368 520 jne 1b
pascal@15368 521 movw %bx, ramdisk_size
pascal@15368 522 movb $0x10, ramdisk_image+2
pascal@15368 523
pascal@15368 524 pushw %ss
pascal@15368 525 popw %es
pascal@15368 526 movw %sp, %si
pascal@15368 527 movb $0x87, %ah
pascal@15368 528 movw $(run_ipxe-default_config)/2+1, %cx
pascal@15368 529 int $0x15
pascal@15368 530
pascal@15368 531 setup_done:
pascal@15368 532 /* We expect to be contiguous in memory once loaded. The Linux image
pascal@15368 533 * boot process requires that setup code is loaded separately from
pascal@15368 534 * "non-real code". Since we don't need any information that's left
pascal@15368 535 * in the prefix, it doesn't matter: we just have to ensure that
pascal@15368 536 * %cs:0000 is where the start of the image *would* be.
pascal@15368 537 */
pascal@15368 538 ljmp $(SYSSEG-(PREFIXSIZE/16)), $run_ipxe
pascal@15368 539
pascal@15368 540 default_config:
pascal@15368 541
pascal@15368 542 .org PREFIXSIZE
pascal@15368 543 /*
pascal@15368 544 We're now at the beginning of the kernel proper.
pascal@15368 545 */
pascal@15368 546 run_ipxe:
pascal@15368 547 /* Set up stack just below 0x7c00 and clear direction flag */
pascal@15368 548 xorw %ax, %ax
pascal@15368 549 movw %ax, %ss
pascal@15368 550 movw $0x7c00, %sp
pascal@15368 551 cld
pascal@15368 552
pascal@15368 553 /* Retrieve command-line pointer */
pascal@15368 554 movl %ds:cmd_line_ptr, %edx
pascal@15368 555 testl %edx, %edx
pascal@15368 556 jz no_cmd_line
pascal@15368 557
pascal@15368 558 /* Set up %es:%di to point to command line */
pascal@15368 559 movl %edx, %edi
pascal@15368 560 andl $0xf, %edi
pascal@15368 561 rorl $4, %edx
pascal@15368 562 movw %dx, %es
pascal@15368 563
pascal@15368 564 /* Find length of command line */
pascal@15368 565 pushw %di
pascal@15368 566 movw $0xffff, %cx
pascal@15368 567 repnz scasb
pascal@15368 568 notw %cx
pascal@15368 569 popw %si
pascal@15368 570
pascal@15368 571 /* Make space for command line on stack */
pascal@15368 572 movw %sp, %di
pascal@15368 573 subw %cx, %di
pascal@15368 574 andw $~0xf, %di
pascal@15368 575 movw %di, %sp
pascal@15368 576
pascal@15368 577 /* Copy command line to stack */
pascal@15368 578 pushw %ds
pascal@15368 579 pushw %es
pascal@15368 580 popw %ds
pascal@15368 581 pushw %ss
pascal@15368 582 popw %es
pascal@15368 583 rep movsb
pascal@15368 584 popw %ds
pascal@15368 585
pascal@15368 586 /* Store new command-line pointer */
pascal@15368 587 movzwl %sp, %edx
pascal@15368 588 no_cmd_line:
pascal@15368 589
pascal@15368 590 /* Calculate maximum relocation address */
pascal@15368 591 movl ramdisk_image, %ebp
pascal@15368 592 testl %ebp, %ebp
pascal@15368 593 jnz 1f
pascal@15368 594 decl %ebp /* Allow arbitrary relocation if no initrd */
pascal@15368 595 1:
pascal@15368 596
pascal@15368 597 /* Install iPXE */
pascal@15368 598 call alloc_basemem
pascal@15368 599 xorl %esi, %esi
pascal@15368 600 xorl %edi, %edi
pascal@15368 601 call install_prealloc
pascal@15368 602
pascal@15368 603 /* Retrieve initrd pointer and size */
pascal@15368 604 movl ramdisk_image, %ebp
pascal@15368 605 movl ramdisk_size, %ecx
pascal@15368 606
pascal@15368 607 start_ipxe:
pascal@15368 608 /* Set up real-mode stack */
pascal@15368 609 movw %bx, %ss
pascal@15368 610 movw $_estack16, %sp
pascal@15368 611
pascal@15368 612 /* Jump to .text16 segment */
pascal@15368 613 pushw %ax
pascal@15368 614 pushw $1f
pascal@15368 615 lret
pascal@15368 616 .section ".text16", "awx", @progbits
pascal@15368 617 1:
pascal@15368 618 /* Set up %ds for access to .data16 */
pascal@15368 619 movw %bx, %ds
pascal@15368 620
pascal@15368 621 /* Store command-line pointer */
pascal@15368 622 movl %edx, cmdline_phys
pascal@15368 623
pascal@15368 624 /* Store initrd pointer and size */
pascal@15368 625 movl %ebp, initrd_phys
pascal@15368 626 movl %ecx, initrd_len
pascal@15368 627
pascal@15368 628 /* Run iPXE */
pascal@15368 629 pushl $main
pascal@15368 630 pushw %cs
pascal@15368 631 call prot_call
pascal@15368 632 popl %ecx /* discard */
pascal@15368 633
pascal@15368 634 /* Uninstall iPXE */
pascal@15368 635 call uninstall
pascal@15368 636
pascal@15368 637 /* Boot next device */
pascal@15368 638 int $0x18