wok annotate linux/stuff/linux-header.u @ rev 17885

fusecloop/extract_compressed_fs: large file support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 02 10:46:24 2015 +0200 (2015-04-02)
parents e0cfbb41587f
children
rev   line source
pascal@17269 1 --- linux-3.2.53/arch/x86/boot/header.S
pascal@17269 2 +++ linux-3.2.53/arch/x86/boot/header.S
pascal@15203 3 @@ -7,12 +7,14 @@
slaxemulator@8085 4 * modified by more people than can be counted
slaxemulator@8085 5 *
pascal@12556 6 * Rewritten as a common file by H. Peter Anvin (Apr 2007)
pascal@16547 7 + * Rewritten by Pascal Bellard (Nov 2009)
slaxemulator@8085 8 *
slaxemulator@8085 9 * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment
slaxemulator@8085 10 * addresses must be multiplied by 16 to obtain their respective linear
pascal@15203 11 * addresses. To avoid confusion, linear addresses are written using leading
pascal@15203 12 * hex while segment addresses are written as segment:offset.
pascal@15203 13 *
pascal@15203 14 + * Assume protocol 2.00+ (kernel >= 1.3.73)
pascal@15203 15 */
pascal@15203 16
pascal@15203 17 #include <asm/segment.h>
pascal@15203 18 @@ -27,6 +29,8 @@
slaxemulator@8085 19
slaxemulator@8085 20 BOOTSEG = 0x07C0 /* original address of boot-sector */
slaxemulator@8085 21 SYSSEG = 0x1000 /* historical load address >> 4 */
slaxemulator@8085 22 +INITSEG = 0x9000 /* boot address >> 4 */
slaxemulator@8085 23 +SETUPSEG = 0x9020 /* setup address >> 4 */
slaxemulator@8085 24
slaxemulator@8085 25 #ifndef SVGA_MODE
slaxemulator@8085 26 #define SVGA_MODE ASK_VGA
pascal@17269 27 @@ -40,54 +44,752 @@
pascal@15203 28 #define ROOT_RDONLY 1
slaxemulator@8085 29 #endif
pascal@15203 30
pascal@15203 31 +setup_sects = 497
pascal@15203 32 +syssize = 500
pascal@17269 33 +vgamode = 506
pascal@15203 34 +cmd_line_ptr = 0x228
pascal@15203 35 +
pascal@15203 36 +/* some extra features */
pascal@16547 37 +#define EXE_SUPPORT real mode dos .exe file support
pascal@15203 38 +#define CMDLINE kernel >= 2.4
pascal@15203 39 +#define OLDCMDLINE kernel < 2.4
pascal@15203 40 +#define HELP display version for ? argument
pascal@15203 41 +#define MORETHAN16M up to 4Gb RAM, not 16Mb
pascal@15203 42 +#define KEYBOARDLESS_SUPPORT scan floppy swap each 5 seconds
pascal@15203 43 +
pascal@16547 44 +/* some limitations to reduce the code size */
pascal@17269 45 +//#define REALMODE_NOT_CHECKED exe crash when started in vm86
pascal@17269 46 +//#define FLOPPY_1440K_ONLY 1.44M floppies support only (no 720K, 1.68M, 2.88M...)
pascal@17269 47 +
pascal@17269 48 +#ifdef FLOPPY_ONLY
pascal@17269 49 +#undef EXE_SUPPORT
pascal@17269 50 +#undef FLOPPY_1440K_ONLY
pascal@17269 51 +#define EDIT_CMDLINE
pascal@17269 52 +#define CMDLINE_SUPPORT
pascal@17269 53 +#define MOVE_CMDLINE
pascal@17269 54 +#define INITRD_SUPPORT
pascal@17269 55 +#define INITRD_AUTOADDR
pascal@17269 56 +#endif
pascal@17269 57 +
pascal@17269 58 +#ifdef EXE_ONLY
pascal@17269 59 +#undef KEYBOARDLESS_SUPPORT
pascal@17269 60 +#define INITRD_SUPPORT
pascal@17269 61 +#define INITRD_KEYWORD
pascal@17269 62 +#define INITRD_AUTOADDR
pascal@17269 63 +#endif
pascal@15203 64 +
pascal@15203 65 .code16
pascal@15203 66 .section ".bstext", "ax"
slaxemulator@8085 67
slaxemulator@8085 68 .global bootsect_start
slaxemulator@8085 69 bootsect_start:
pascal@15203 70
pascal@15203 71 - # Normalize the start address
pascal@15203 72 - ljmp $BOOTSEG, $start2
pascal@15203 73 +stacktop = 0x9E00 # in 0x8000 .. 0xA000
pascal@17269 74 +zeroed = 48+10 # gdt + zeroed registers
pascal@17269 75 +.macro INIT_REGS
pascal@17269 76 + movw $stacktop-zeroed, %di # stacktop is an arbitrary value >=
pascal@17269 77 + # length of bootsect + length of
pascal@17269 78 + # setup + room for stack;
pascal@17269 79 + # 12 is disk parm size.
pascal@17269 80 + pushw $INITSEG
pascal@17269 81 + popw %ss # %ss contain INITSEG
pascal@17269 82 + movw %di, %sp # put stack at INITSEG:stacktop-...
pascal@17269 83 + pushw %ss
pascal@17269 84 + popw %es # %es = %ss = INITSEG
pascal@17269 85 + xorw %ax, %ax # %ax = 0
pascal@17269 86 +#if defined(CMDLINE)
pascal@17269 87 + movw $zeroed+1, %cx # clear gdt + offset, %ds, limits, cmdline=""
pascal@17269 88 + rep # don't worry about cld
pascal@17269 89 + stosb # already done above
pascal@17269 90 + decw %di
pascal@17269 91 +#else
pascal@17269 92 + movw $zeroed/2, %cx # clear gdt + offset, %ds, limits
pascal@17269 93 + rep # don't worry about cld
pascal@17269 94 + stosw # already done above
pascal@15203 95 +#endif
pascal@17269 96 + popw %bx # offset = 0
pascal@17269 97 +.endm
pascal@15203 98
pascal@15203 99 -start2:
pascal@15203 100 - movw %cs, %ax
pascal@15203 101 - movw %ax, %ds
pascal@15203 102 - movw %ax, %es
pascal@15203 103 - movw %ax, %ss
pascal@15203 104 - xorw %sp, %sp
pascal@15203 105 - sti
pascal@15203 106 - cld
pascal@17269 107 +#ifdef EXE_SUPPORT
pascal@17269 108 +#define CODESZ 0x8000
pascal@17269 109 +#define EXEADRS(x) x+0xE0
pascal@17269 110 + decw %bp // Magic number: MZ
pascal@17269 111 + popw %dx
pascal@17269 112 +#ifdef EXE_ONLY
pascal@17269 113 + .word 512 // Bytes on last page of file
pascal@17269 114 +#else
pascal@17269 115 + jmp fdstart // Bytes on last page of file
pascal@17269 116 +#endif
pascal@17269 117 + .word (CODESZ+511)/512 // Pages in file
pascal@17269 118 + .word 0 // Relocations
pascal@17269 119 + .word 2 // Size of header in paragraphs
pascal@17269 120 + .word 4096 // Minimum extra paragraphs needed
pascal@17269 121 + .word -1 // Maximum extra paragraphs needed
pascal@17269 122 + .word (CODESZ+15)/16 // Initial (relative) SS value
pascal@17269 123 + .word stacktop+4 // Initial SP value (+callf)
pascal@17269 124 + .word 0 // Checksum
pascal@17269 125 + .word EXEADRS(comstart) // Initial IP value
pascal@17269 126 + .word 0xFFF0 // Initial (relative) CS value
pascal@17269 127 +#ifdef EXE_ONLY
pascal@17269 128 +// .word 0x001C // File address of relocation table
pascal@17269 129 +// .word 0,0,0 // Overlay number
pascal@17269 130 + .ascii "(SliTaz)"
pascal@17269 131 +#else
pascal@17269 132 +swap_floppy:
pascal@17269 133 + .ascii "Next!"
pascal@17269 134 + .byte 7,13,0 # swap detection needs 13, 0
pascal@17269 135 +#endif
pascal@17269 136 +#ifdef OLDCMDLINE
pascal@17269 137 +# ifdef CMDLINE_SUPPORT
pascal@17269 138 + .word 0 # 0xA33F
pascal@17269 139 + .word 0 # stacktop
pascal@17269 140 +# else
pascal@17269 141 + .word 0xA33F
pascal@17269 142 + .word stacktop
pascal@17269 143 +# endif
pascal@17269 144 +#endif
pascal@17269 145 +#ifndef EXE_ONLY
pascal@17269 146 +fdstart:
pascal@17269 147 + pushw %dx
pascal@17269 148 +#endif
pascal@17269 149 +#endif
pascal@17269 150
pascal@17269 151 - movw $bugger_off_msg, %si
pascal@16547 152 +LOADSEG = 0x8000 # 0x1000 multiple, up to 512K zImage
pascal@16547 153 +LOADSZ = 0x10000
pascal@16547 154 +#ifdef EXE_SUPPORT
pascal@16547 155 +A20BUFFER = 0x68000 # a20 gate / himem.sys support
pascal@16547 156 +#define USEA20BUFFER
pascal@15203 157 +#endif
pascal@15203 158
pascal@17269 159 -msg_loop:
pascal@17269 160 +#ifndef EXE_ONLY
pascal@16547 161 +# bootsect_start:
pascal@17269 162 +#ifdef EXE_SUPPORT
pascal@17269 163 + call initregs
pascal@17269 164 + cwd # floppy = head = 0
pascal@17269 165 +#else
pascal@17269 166 + INIT_REGS
pascal@17269 167 +#endif
pascal@17269 168 + popw %ds # %ds = 0
pascal@17269 169 + movb setup_sects+0x7C00, %al # read bootsector + setup
pascal@17269 170 + incw %ax # %ax = setup_sects+bootsect
pascal@17269 171 + popw %fs # %fs = 0
pascal@17269 172 +
slaxemulator@8085 173 +# Many BIOS's default disk parameter tables will not recognize
slaxemulator@8085 174 +# multi-sector reads beyond the maximum sector number specified
slaxemulator@8085 175 +# in the default diskette parameter tables - this may mean 7
slaxemulator@8085 176 +# sectors in some cases.
slaxemulator@8085 177 +#
slaxemulator@8085 178 +# Since single sector reads are slow and out of the question,
slaxemulator@8085 179 +# we must take care of this by creating new parameter tables
slaxemulator@8085 180 +# (for the first disk) in RAM. We can set the maximum sector
slaxemulator@8085 181 +# count to 36 - the most we will encounter on an ED 2.88.
slaxemulator@8085 182 +#
slaxemulator@8085 183 +# High doesn't hurt. Low does. Let's use the max: 63
pascal@15203 184 +
pascal@12556 185 + ldsw 0x78(%bx), %si # %ds:%bx+0x78 is parameter table address
pascal@17269 186 + popw %di
slaxemulator@8085 187 + pushw %es
pascal@12556 188 + pushw %di
pascal@17269 189 +#ifdef CMDLINE_SUPPORT
pascal@17269 190 + movw $0, %bp # patched by installer (7C22)
pascal@17269 191 +skipcmdline:
pascal@17269 192 +#define cmd_line_ptr 0x22
pascal@17269 193 +#endif
slaxemulator@8085 194 + movb $6, %cl # copy 12 bytes
slaxemulator@8085 195 + rep # don't worry about cld
pascal@17269 196 + movsw # already done above
pascal@12556 197 + pushw %ss
slaxemulator@8085 198 + popw %ds # now %ds = %es = %ss = INITSEG
pascal@12556 199 + popl %fs:0x78(%bx) # update parameter table address
slaxemulator@8085 200 + movb $63, 0x4-12(%di) # patch sector count, %di = stacktop
slaxemulator@8085 201 + cli
slaxemulator@8085 202 +
slaxemulator@8085 203 + xchg %ax, %di # sector count
pascal@17269 204 +#ifndef FLOPPY_1440K_ONLY
slaxemulator@8085 205 + popw %ax # limits = 0
pascal@17269 206 +#endif
pascal@12556 207 + incw %cx # cylinder 0, sector 1, clear Z
slaxemulator@8085 208 + call read_first_sectors # read setup
pascal@17269 209 +#endif
pascal@15203 210 +loadsys:
slaxemulator@8085 211 + movw $0x200,%si
pascal@12556 212 +type_of_loader = 0x10
pascal@12556 213 +loadflags = 0x11
pascal@12556 214 +heap_end_ptr = 0x24
pascal@12556 215 + orw $0x8020, type_of_loader(%si) # loader type = 0x20 = bootsect-loader
pascal@12556 216 + movb $(stacktop-0x300)/256, heap_end_ptr+1(%si)
pascal@15203 217 + call puts_version # show which kernel we are loading
slaxemulator@8085 218 +
pascal@17269 219 +#ifdef CMDLINE_SUPPORT
pascal@17269 220 +# The cmdline can be entered and modifed at boot time.
pascal@17269 221 +# Only characters before the cursor are passed to the kernel.
pascal@17269 222 +
pascal@17269 223 + xorw %si, %si
pascal@17269 224 + orw cmd_line_ptr-7(%bx), %si
pascal@17269 225 + jz nocmdline
pascal@17269 226 + movw $0xA33F, cmd_line_ptr-2-7(%bx)
pascal@17269 227 + call puts
pascal@17269 228 +#if defined(MOVE_CMDLINE) || (defined(EDIT_CMDLINE) && defined(KEYBOARDLESS_SUPPORT))
pascal@17269 229 + pushw %di
pascal@17269 230 +#endif
pascal@17269 231 +#ifdef EDIT_CMDLINE
pascal@17269 232 +cmdlp:
pascal@17269 233 + movb $0x20, %al # clear end of line
pascal@17269 234 +cmdlpz:
pascal@17269 235 + call putc # with Space
pascal@17269 236 + subb $0x18, %al # and BackSpace
pascal@17269 237 + jnc cmdlpz
pascal@17269 238 + decw %si
pascal@17269 239 +cmdget:
pascal@17269 240 +#ifdef KEYBOARDLESS_SUPPORT
pascal@17269 241 + call wait4key
pascal@17269 242 +#else
pascal@17269 243 + int $0x16
pascal@17269 244 +#endif
pascal@17269 245 + cbw # %ah = 0, get keyboard character
pascal@17269 246 + cmpb $8, %al # BackSpace ?
pascal@17269 247 + je cmdbs
pascal@17269 248 + movb %al, (%si) # store char
pascal@17269 249 + lodsw # %si += 2
pascal@17269 250 +cmdbs:
pascal@17269 251 + cmpw %si, cmd_line_ptr-7(%bx)
pascal@17269 252 + je cmdget
pascal@17269 253 + call putc
pascal@17269 254 + cmpb $13, %al # Enter ?
pascal@17269 255 + jne cmdlp
pascal@17269 256 + movb %bh,-2(%si) # set end of string and remove CR
pascal@17269 257 +endcmdline:
pascal@17269 258 +#endif
pascal@17269 259 +#ifdef MOVE_CMDLINE
pascal@17269 260 + pushw %ss
pascal@17269 261 + popw %es
pascal@17269 262 + movw $0x8000, %di
pascal@17269 263 + movw %di, %si
pascal@17269 264 + xchgw %si, cmd_line_ptr-7(%bx)
pascal@17269 265 + movb $0x2, %ch
pascal@17269 266 + rep
pascal@17269 267 + movsb
pascal@17269 268 +#endif
pascal@17269 269 +#if defined(EDIT_CMDLINE) || (defined(MOVE_CMDLINE) && defined(KEYBOARD_TIMEOUT))
pascal@17269 270 + popw %di
pascal@17269 271 +#endif
pascal@17269 272 +nocmdline:
pascal@17269 273 +#endif
pascal@17269 274 +
pascal@12556 275 +# This routine loads the system at address LOADSEG, making sure
slaxemulator@8085 276 +# no 64kB boundaries are crossed. We try to load it as fast as
slaxemulator@8085 277 +# possible, loading whole tracks whenever we can.
pascal@15203 278 +
slaxemulator@8085 279 +ramdisk_image = 0x0218
slaxemulator@8085 280 +ramdisk_size = 0x021C
pascal@12556 281 +bootsect_src_limit = 16
pascal@12556 282 +bootsect_dst_limit = 24
pascal@12556 283 +bootsect_src_base = 18
pascal@15203 284 +bootsect_dst_base = 26 # bits 0..23
pascal@15203 285 +bootsect_dst_base_hi = 31 # bits 24..31
pascal@12556 286 + popw %bx # clear %bx
slaxemulator@8085 287 + movw %sp, %si # for bootsect_gdt
pascal@12556 288 +init_gdt:
pascal@12556 289 + decw bootsect_src_limit(%bx,%si) # max 64Kb
pascal@15203 290 + movw $0x9300+(LOADSEG/0x1000), bootsect_src_base+2(%bx,%si)
pascal@12556 291 + xorb $bootsect_dst_limit-bootsect_src_limit, %bl
pascal@12556 292 + jne init_gdt
pascal@17269 293 +#ifdef INITRD_SUPPORT
pascal@17269 294 +#ifdef INITRD_AUTOADDR
pascal@17269 295 + movb $0x88, %ah
pascal@17269 296 + int $0x15
pascal@17269 297 + jc NeedMoreRAM
pascal@17269 298 + cmpw $0xC000, %ax # more than 48M ?
pascal@17269 299 + jb NeedMoreRAM
pascal@17269 300 + movw $ramdisk_image+2, %bx
pascal@17269 301 + cmpw $0x100, (%bx) # already above 16M ?
pascal@17269 302 + ja NeedMoreRAM
pascal@17269 303 + movw $0x200, (%bx) # initramfs @ 32M
pascal@17269 304 +NeedMoreRAM:
pascal@17269 305 +#endif
pascal@17269 306 +#ifdef INITRD_KEYWORD
pascal@17269 307 +#ifdef INITRD_AUTOADDR
pascal@17269 308 + pushl -2(%bx)
pascal@17269 309 +#else
pascal@17269 310 + pushl ramdisk_image
pascal@17269 311 +#endif
pascal@17269 312 + pushw $stacktop # start of cmdline
pascal@17269 313 +#endif
pascal@17269 314 + movw $syssize, %bx
pascal@17269 315 + movb $5, %cl
pascal@17269 316 +code32_start = 0x214
pascal@17269 317 + movw code32_start+1, %ax # destination = 0x00100000 or 0x00010000
pascal@17269 318 +initrdlp:
pascal@17269 319 + movl (%bx), %ebx
pascal@17269 320 + decl %ebx
pascal@17269 321 + shrl %cl, %ebx
pascal@17269 322 +#else
pascal@12556 323 +code32_start = 0x214
pascal@12556 324 + movw code32_start+1, %ax # destination = 0x00100000 or 0x00010000
pascal@15203 325 + movl syssize, %ebx
pascal@12556 326 + decl %ebx
pascal@15203 327 + shrl $5, %ebx
pascal@17269 328 +#endif
pascal@16547 329 +#ifdef MORETHAN16M
pascal@15203 330 + incl %ebx
pascal@16547 331 +#else
pascal@16547 332 + incw %bx
pascal@16547 333 +#endif
pascal@16547 334 +#ifdef USEA20BUFFER
pascal@16547 335 + movw $0x00100000>>8, %di
pascal@16547 336 +#endif
slaxemulator@8085 337 +syslp:
pascal@16547 338 +#ifdef USEA20BUFFER
pascal@16547 339 + cmpw %ax, %di
pascal@16547 340 + jne nota20
pascal@16547 341 + xorw $(0x00100000+A20BUFFER)>>8, %ax
pascal@16547 342 +nota20:
pascal@16547 343 +#endif
pascal@12556 344 + movw %ax, bootsect_dst_base+1(%si)
pascal@16547 345 +#ifdef MORETHAN16M
pascal@16547 346 + movl $LOADSZ/512, %edi # size in sectors
pascal@16547 347 + subl %edi, %ebx
pascal@16547 348 +#else
pascal@15203 349 + movw $LOADSZ/512, %di # size in sectors
pascal@16547 350 + subw %di, %bx
pascal@16547 351 +#endif
slaxemulator@8085 352 + pushf
slaxemulator@8085 353 + jnc not_last
pascal@12556 354 + addw %bx, %di
slaxemulator@8085 355 +not_last:
slaxemulator@8085 356 + pushw %ax
slaxemulator@8085 357 + pushw %si
pascal@12556 358 + pushw %bx
pascal@12556 359 + xorw %bx,%bx
pascal@15203 360 + pushw $LOADSEG
pascal@15203 361 + popw %es
pascal@17269 362 +#ifdef EXE_ONLY
pascal@17269 363 + call read_sectors_dos
pascal@17269 364 +#else
pascal@15203 365 +patchcall:
pascal@12556 366 + call read_sectors # update %bp
pascal@17269 367 +#endif
pascal@12556 368 + popw %bx
slaxemulator@8085 369 + popw %si
pascal@17269 370 + movw %es, %cx # word count = LOADSZ/2 (= LOADSEG)
slaxemulator@8085 371 + movb $0x87, %ah
pascal@12556 372 + pushw %ss
pascal@12556 373 + popw %es # restore es
pascal@15203 374 + int $0x15 # max 16M, maybe more...
slaxemulator@8085 375 + popw %ax
pascal@17269 376 +#ifdef MORETHAN16M
pascal@17269 377 + addw $0x100, %ax # next dest (ax+=LOADSZ/256)
pascal@17269 378 + adcb %cl, bootsect_dst_base_hi(%si) # breaks 16M limit ?
pascal@17269 379 +#else
pascal@16547 380 + incb %ah # next dest (ax+=LOADSZ/256)
pascal@15203 381 +#endif
pascal@16547 382 +#ifdef USEA20BUFFER
pascal@16547 383 + movw $(LOADSZ+A20BUFFER)>>8, %di
pascal@16547 384 +#endif
slaxemulator@8085 385 + popf
slaxemulator@8085 386 + ja syslp
pascal@17269 387 +#ifdef INITRD_SUPPORT
pascal@17269 388 +initrdlp2:
pascal@17269 389 + movw ramdisk_image+1,%ax
pascal@17269 390 + movw $ramdisk_size,%bx
pascal@17269 391 + movb $9, %cl
pascal@17269 392 + cmpw %ax, bootsect_dst_base+1(%si)
pascal@17269 393 + jb initrdlp
pascal@17269 394 +#ifdef INITRD_KEYWORD
pascal@17269 395 + xorl %eax, %eax
pascal@17269 396 + xchgl %eax, (%bx)
pascal@17269 397 + addl $3, %eax
pascal@17269 398 + addl %eax, ramdisk_image-ramdisk_size(%bx)
pascal@17269 399 + andb $0xFC, ramdisk_image-ramdisk_size(%bx)
pascal@17269 400 + popw %si // current ptr in cmdline
pascal@17269 401 +kwchk:
pascal@17269 402 + movw $kwinitrd, %di
pascal@17269 403 +kwchk2:
pascal@17269 404 +#if 1
pascal@17269 405 + cmpl $0x3D616776, (%si) // look for vga=
pascal@17269 406 + jne notvga
pascal@17269 407 +#if 1
pascal@17269 408 + movw $0x312C, %ax
pascal@17269 409 + subw 4(%si), %ax // support -9 .. -1 only !
pascal@17269 410 + xchgb %al, %ah
pascal@17269 411 + cmpw $-8, %ax
pascal@17269 412 + jb notvga
pascal@17269 413 + decw %ax
pascal@17269 414 +#else
pascal@17269 415 + movb $'0', %al
pascal@17269 416 + subb 5(%si), %al // support -9 .. -1 only !
pascal@17269 417 + cbw
pascal@17269 418 +#endif
pascal@17269 419 + movw %ax, vgamode
pascal@17269 420 +notvga:
pascal@17269 421 +#endif
pascal@17269 422 + lodsb // look for initrd=
pascal@17269 423 + orb %al, %al
pascal@17269 424 + jz noinitrd
pascal@17269 425 + subb (%di), %al
pascal@17269 426 + //andb $0xDF, %al
pascal@17269 427 + jne kwchk
pascal@17269 428 + incw %di
pascal@17269 429 + cmpb (%di), %al
pascal@17269 430 + jne kwchk2
pascal@17269 431 + mov %si, %dx // %ds:%dx filename
pascal@17269 432 +chkeos:
pascal@17269 433 lodsb
pascal@17269 434 - andb %al, %al
pascal@17269 435 - jz bs_die
pascal@17269 436 + cmpb $0, %al
pascal@17269 437 + je gotoes
pascal@17269 438 + subb $0x20, %al
pascal@17269 439 + jne chkeos
pascal@17269 440 +gotoes:
pascal@17269 441 + decw %si
pascal@17269 442 + pushw (%si)
pascal@17269 443 + movb %al, (%si) // set eos
pascal@17269 444 + movb $0x3D, %ah // open, access = RO
pascal@17269 445 + int $0x21
pascal@17269 446 + popw (%si)
pascal@17269 447 + jc noinitrd
pascal@17269 448 + pushw %si // save ptr in cmdline
pascal@17269 449 + xchgw %ax, %bp // fd
pascal@17269 450 + movw $0x4202, %ax // lseek(SEEK_END)
pascal@17269 451 + movw %bp, %bx
pascal@17269 452 + xorw %cx, %cx
pascal@17269 453 + cwd
pascal@17269 454 + int $0x21
pascal@17269 455 + pushw %dx
pascal@17269 456 + pushw %ax
pascal@17269 457 + popl ramdisk_size
pascal@17269 458 + movw $0x4200, %ax // lseek(SEEK_SET)
pascal@17269 459 + xorw %cx, %cx
pascal@17269 460 + cwd
pascal@17269 461 + int $0x21 // set %ax = %dx = 0
pascal@17269 462 + jmp initrdlp2
pascal@17269 463 +noinitrd:
pascal@17269 464 + popl %eax // restore initial ramdisk address
pascal@17269 465 + movl %eax, %edx
pascal@17269 466 + xchgl %edx, ramdisk_image-ramdisk_size(%bx)
pascal@17269 467 + subl %eax, %edx
pascal@17269 468 + addl %edx, (%bx)
pascal@17269 469 +#endif
pascal@17269 470 +#endif
pascal@16547 471 +#ifdef USEA20BUFFER
pascal@16547 472 +#ifdef MORETHAN16M
pascal@17269 473 +#ifdef INITRD_SUPPORT
pascal@17269 474 + movb $0, bootsect_dst_base_hi(%si)
pascal@17269 475 +#else
pascal@16547 476 + movb %cl, bootsect_dst_base_hi(%si)
pascal@16547 477 +#endif
pascal@17269 478 +#endif
pascal@16547 479 + movb $0x10, bootsect_dst_base+2(%si)
pascal@16547 480 + movw $A20BUFFER/0x100, bootsect_src_base+1(%si)
pascal@16547 481 + movb $0x87, %ah
pascal@16547 482 + int $0x15
pascal@16547 483 +#endif
pascal@16547 484 +
slaxemulator@8085 485 +# This procedure turns off the floppy drive motor, so
slaxemulator@8085 486 +# that we enter the kernel in a known state, and
slaxemulator@8085 487 +# don't have to worry about it later.
pascal@15203 488 +
pascal@12556 489 +kill_motor:
pascal@12556 490 + xchgw %ax, %di # reset FDC (%di < 128)
pascal@12556 491 + int $0x13
slaxemulator@8085 492 +
slaxemulator@8085 493 +# After that (everything loaded), we jump to the setup-routine
slaxemulator@8085 494 +# loaded directly after the bootblock:
slaxemulator@8085 495 +# Segments are as follows: %ds = %ss = INITSEG
slaxemulator@8085 496 +
slaxemulator@8085 497 + ljmp $SETUPSEG, $0
slaxemulator@8085 498 +
slaxemulator@8085 499 +# read_sectors reads %di sectors into %es:0 buffer.
slaxemulator@8085 500 +# %es:0 is updated to the next memory location.
slaxemulator@8085 501 +# First, sectors are read sector by sector until
slaxemulator@8085 502 +# sector per track count is known. Then they are
slaxemulator@8085 503 +# read track by track.
slaxemulator@8085 504 +# Assume no error on first track.
slaxemulator@8085 505 +
pascal@17269 506 +#ifndef EXE_ONLY
pascal@17269 507 +
pascal@17269 508 +#define FLOPPY_CYLINDERS 80
pascal@17269 509 +#define FLOPPY_HEADS 2
slaxemulator@8085 510 +
slaxemulator@8085 511 +check_limits:
pascal@15203 512 +#ifndef FLOPPY_1440K_ONLY
pascal@15203 513 + popw %dx
slaxemulator@8085 514 + cmpb %al, %cl # max sector known ?
slaxemulator@8085 515 + ja next_head # no -> store it
pascal@15203 516 +#endif
slaxemulator@8085 517 + pushaw
slaxemulator@8085 518 + int $0x13 # reset controler
pascal@15203 519 + stc
pascal@15203 520 + call putcdot # print '-'
pascal@15203 521 +read_sectorslp:
slaxemulator@8085 522 + popaw
pascal@15203 523 +bdendlp:
slaxemulator@8085 524 + pushw %dx # some bios break dx...
pascal@15203 525 +#ifndef FLOPPY_1440K_ONLY
slaxemulator@8085 526 + pushw %ax # limits
slaxemulator@8085 527 + subb %cl, %al # sectors remaining in track
slaxemulator@8085 528 + ja tolastsect
slaxemulator@8085 529 + movb $1, %al # 1 sector mini
slaxemulator@8085 530 +tolastsect:
pascal@15203 531 +#else
pascal@17269 532 +#define FLOPPY_SECTORS 18
pascal@15203 533 + mov $FLOPPY_SECTORS+1, %al
pascal@15203 534 + subb %cl, %al # sectors remaining in track
pascal@17269 535 + cbw
pascal@15203 536 +#endif
slaxemulator@8085 537 + cmpw %di, %ax
slaxemulator@8085 538 + jb more1trk
slaxemulator@8085 539 + movw %di, %ax # sectors to read
slaxemulator@8085 540 +more1trk:
slaxemulator@8085 541 + pushw %ax # save context
slaxemulator@8085 542 + movb $2, %ah # cmd: read chs
slaxemulator@8085 543 + int $0x13
pascal@15203 544 +#ifndef FLOPPY_1440K_ONLY
pascal@15203 545 + popw %dx # save %ax
slaxemulator@8085 546 + popw %ax # limits
pascal@15203 547 +#else
pascal@15203 548 + popw %ax # restore context
slaxemulator@8085 549 + popw %dx
pascal@15203 550 +#endif
slaxemulator@8085 551 + jc check_limits
pascal@15203 552 +#ifndef FLOPPY_1440K_ONLY
slaxemulator@8085 553 + xchgw %ax, %bp
pascal@15203 554 + addw %dx,%cx # next sector
pascal@12556 555 + movw %cx, %gs
pascal@15203 556 + addb %dl,%bh
pascal@15203 557 + addb %dl,%bh # next location
pascal@15203 558 + subw %dx,%di # update sector counter
pascal@15203 559 + popw %dx
slaxemulator@8085 560 + jz putcdot
pascal@15203 561 +#else
pascal@15203 562 + addw %ax,%cx # next sector
pascal@15203 563 + movw %cx, %gs
pascal@15203 564 + addb %al,%bh
pascal@15203 565 + addb %al,%bh # next location
pascal@15203 566 + subw %ax,%di # update sector counter
pascal@15203 567 + jz putcdot
pascal@15203 568 +#endif
slaxemulator@8085 569 +read_sectors:
pascal@12556 570 + movw %gs, %cx
pascal@15203 571 +#ifndef FLOPPY_1440K_ONLY
pascal@12556 572 +# al is last sector+1
pascal@17269 573 +# ah is 0
slaxemulator@8085 574 + xchgw %ax, %bp
pascal@15203 575 +#endif
pascal@15203 576 +#ifndef FLOPPY_1440K_ONLY
slaxemulator@8085 577 + cmpb %al,%cl # reach sector limit ?
slaxemulator@8085 578 + jne bdendlp
slaxemulator@8085 579 +next_head:
slaxemulator@8085 580 + movb %cl,%al
pascal@15203 581 +#else
pascal@15203 582 + cmpb $FLOPPY_SECTORS+1,%cl # reach sector limit ?
pascal@15203 583 + jne bdendlp
pascal@15203 584 +#endif
pascal@17269 585 + movb $1, %cl # first sector
pascal@17269 586 +inc_head:
pascal@17269 587 + xorb %cl, %dh # next head
pascal@17269 588 + jne bdendlp # reach head limit ?
slaxemulator@8085 589 + incb %ch # next cylinder
slaxemulator@8085 590 +read_first_sectors:
pascal@15203 591 + cmpb $FLOPPY_CYLINDERS,%ch # reach cylinder limit ?
pascal@12556 592 + jne bdendlp
slaxemulator@8085 593 +next_floppy:
slaxemulator@8085 594 + movb $0,%ch # first cylinder
slaxemulator@8085 595 + pushaw
pascal@17269 596 +#ifdef FLOPPY_ONLY
pascal@17269 597 + movw $swap_floppy_tail,%si
pascal@17269 598 +next_digit:
pascal@17269 599 + decw %si
pascal@17269 600 + movb (%si), %al
pascal@17269 601 + incw %ax
pascal@17269 602 + aaa
pascal@17269 603 + movb %al, (%si)
pascal@17269 604 + jc next_digit
pascal@17269 605 +#endif
slaxemulator@8085 606 + movw $swap_floppy,%si
pascal@15203 607 +#ifdef KEYBOARDLESS_SUPPORT
slaxemulator@8085 608 + pushw %bx
pascal@12556 609 + call puts
slaxemulator@8085 610 + popw %bx
slaxemulator@8085 611 +waitfloppy:
slaxemulator@8085 612 + call wait
slaxemulator@8085 613 + jne waitfloppydone
slaxemulator@8085 614 + pushw %dx # some bios break dx...
slaxemulator@8085 615 + cbw
slaxemulator@8085 616 + int $0x13 # reset FDC
slaxemulator@8085 617 + movw $0x201,%ax
slaxemulator@8085 618 + int $0x13 # read first sector
slaxemulator@8085 619 + popw %dx
slaxemulator@8085 620 + rclb $1,%ah # floppy changed 06=>0D no error 00
slaxemulator@8085 621 + cmpb -2(%si), %ah # 0D then 00
slaxemulator@8085 622 + jne waitfloppy # no => try again
slaxemulator@8085 623 + incw %si
pascal@15203 624 + decw %ax # was 0001 ?
slaxemulator@8085 625 + jne waitfloppy
slaxemulator@8085 626 +waitfloppydone:
pascal@15203 627 +#else
pascal@15203 628 + call puts
pascal@15203 629 + cbw # %ah = 0, get keyboard character
pascal@17269 630 + int $0x16
pascal@15203 631 +#endif
slaxemulator@8085 632 + jmp read_sectorslp
pascal@17269 633 +#endif
pascal@17269 634 +
pascal@15203 635 +#ifdef EXE_SUPPORT
pascal@15203 636 +read_sectors_dos:
pascal@16547 637 + xorw %dx, %dx // write to %ds:%dx, not %es:%bx
pascal@16547 638 + call read_sectors_dosz
pascal@16547 639 +read_sectors_dosz:
pascal@15203 640 + pushw %es
pascal@15203 641 + popw %ds
pascal@15203 642 + movb $0x3F, %ah // read
pascal@15203 643 + movw %di, %cx
pascal@16547 644 + shlw $8, %cx // byte count / 2
pascal@15203 645 + movw %bp, %bx
pascal@15203 646 + int $0x21
pascal@16547 647 + xchgw %ax, %dx
pascal@15203 648 + pushw %ss
pascal@15203 649 + popw %ds
pascal@15203 650 +#endif
pascal@17269 651 +
slaxemulator@8085 652 +putcdot:
pascal@15203 653 + movb $'.'+3, %al // . = success, - = failure
slaxemulator@8085 654 +putclf:
pascal@15203 655 + sbbb $3, %al
slaxemulator@8085 656 +putc:
pascal@17269 657 movb $0xe, %ah
pascal@17269 658 - movw $7, %bx
pascal@17269 659 - int $0x10
pascal@17269 660 - jmp msg_loop
slaxemulator@8085 661 + movw $7, %bx # one dot each 64k
slaxemulator@8085 662 + int $0x10
slaxemulator@8085 663 + cmp $0xd, %al # CR ?
slaxemulator@8085 664 + je putclf
slaxemulator@8085 665 + ret
pascal@16547 666
pascal@17269 667 -bs_die:
pascal@17269 668 - # Allow the user to press a key, then reboot
pascal@17269 669 - xorw %ax, %ax
pascal@15203 670 +#ifdef KEYBOARDLESS_SUPPORT
slaxemulator@8085 671 +clock = 0x46C
slaxemulator@8085 672 +wait:
slaxemulator@8085 673 +wait4key:
slaxemulator@8085 674 + movw $clock, %di
slaxemulator@8085 675 +#define DELAY 5
pascal@15203 676 + movb $257-(DELAY*182)/10, %fs:(%di)
slaxemulator@8085 677 +waitkbd:
slaxemulator@8085 678 + movw $0x10D, %ax # test keyboard, timeout => CR
pascal@15203 679 + cmpb %fs:(%di),%ah
slaxemulator@8085 680 + je waitdone
pascal@17269 681 int $0x16
pascal@17269 682 - int $0x19
slaxemulator@8085 683 + jz waitkbd
slaxemulator@8085 684 + cbw
slaxemulator@8085 685 + int $0x16 # eat char
pascal@12556 686 + movw %di, %fs # disable timeout
slaxemulator@8085 687 + incw %di # clear Z
slaxemulator@8085 688 +waitdone:
slaxemulator@8085 689 + ret
pascal@15203 690 +#endif
pascal@17269 691
pascal@17269 692 - # int 0x19 should never return. In case it does anyway,
pascal@17269 693 - # invoke the BIOS reset code...
pascal@17269 694 - ljmp $0xf000,$0xfff0
pascal@15203 695 +#ifdef EXE_SUPPORT
pascal@15203 696 +comstart:
pascal@17269 697 +#ifndef EXE_ONLY
pascal@17269 698 + call initregs
pascal@17269 699 +#else
pascal@17269 700 + INIT_REGS
pascal@17269 701 +#endif
pascal@17269 702 + movb EXEADRS(setup_sects), %al # read bootsector + setup
pascal@17269 703 + incw %ax
pascal@15203 704 +#ifdef CMDLINE
pascal@15203 705 + movw $0x80, %si
pascal@17269 706 + movb (%si), %cl
pascal@17269 707 + incw %si
pascal@17269 708 +# ifdef OLDCMDLINE
pascal@17269 709 +# ifdef CMDLINE_SUPPORT
pascal@17269 710 + jcxz nocmdline
pascal@17269 711 + movw %di, EXEADRS(0x22)
pascal@17269 712 + movw $0xA33F, 0x7F(%si)
pascal@17269 713 +# endif
pascal@17269 714 +# endif
pascal@15203 715 + rep
pascal@15203 716 + movsb
pascal@17269 717 +nocmdline:
pascal@17269 718 + xchgw %ax, %di
pascal@15203 719 +# ifdef HELP
pascal@15203 720 + cmpb $'?', -1(%si)
pascal@15203 721 + movw $EXEADRS(0x200), %si
pascal@15203 722 + je puts_version
pascal@17269 723 +# ifndef REALMODE_NOT_CHECKED
pascal@15203 724 + smsww %ax
pascal@15203 725 + andb $1, %al
pascal@15203 726 + jne puts_version // real mode only...
pascal@17269 727 +# endif
pascal@15203 728 +# endif
pascal@15203 729 +#else
pascal@17269 730 + xchgw %ax, %di
pascal@15203 731 +#endif
pascal@15203 732 + movw 0x2C(%bx), %ds // DOS 3.0+
pascal@15203 733 +loop1:
pascal@15203 734 + incw %bx
pascal@15203 735 + cmpw %cx, (%bx)
pascal@15203 736 + jne loop1
pascal@15203 737 + leaw 4(%bx), %dx // %ds:%dx filename
pascal@17269 738 +#if !defined(REALMODE_NOT_CHECKED) && defined(CMDLINE) && defined(HELP)
pascal@15203 739 + movb $0x3D, %ah // open, access = RO
pascal@17269 740 +#else
pascal@17269 741 + movw $0x3D00, %ax // open, access = RO
pascal@17269 742 +#endif
pascal@15203 743 + int $0x21
pascal@15203 744 + jc dosexit
pascal@15203 745 + xchgw %ax, %bp // fd
pascal@15203 746 + call read_sectors_dos // update %ds
pascal@17269 747 +#ifndef EXE_ONLY
pascal@15203 748 + addb $read_sectors_dos-read_sectors, patchcall+1
pascal@17269 749 +#endif
pascal@15203 750 +#ifdef CMDLINE
pascal@15203 751 +# ifdef OLDCMDLINE
pascal@15203 752 + movw $0x202, %bx
pascal@17269 753 + cmpw %bx, 0x206-0x202(%bx) # new cmdline for version >= 0x202
pascal@15203 754 + jb oldcmdline
pascal@15203 755 + movw $INITSEG/16+stacktop/256, cmd_line_ptr+1-0x202(%bx)
pascal@15203 756 +# else
pascal@15203 757 + movw $INITSEG/16+stacktop/256, cmd_line_ptr+1
pascal@15203 758 +# endif
pascal@17269 759 +oldcmdline:
pascal@15203 760 +#endif
pascal@17269 761 +// ljmp $INITSEG, $loadsys
pascal@17269 762 + pushw %ds
pascal@17269 763 + .byte 0x6A, loadsys-bootsect_start
pascal@17270 764 + lretw
pascal@15203 765 +#endif
pascal@15203 766 +
pascal@16011 767 +#define kernel_version_offset 0xE
pascal@15203 768 +puts_version:
pascal@16011 769 + addw kernel_version_offset(%si),%si # starting protocol 2.00, Kernel 1.3.73
pascal@15203 770 +puts:
pascal@15203 771 + movb $0xd, %al # CR
pascal@15203 772 +putcs:
pascal@15203 773 + call putc
pascal@15203 774 + lodsb
pascal@15203 775 + cmpb $0, %al # end of string is any byte <= 0
pascal@15203 776 + jg putcs
pascal@15203 777 +dosexit:
pascal@15203 778 + ret
slaxemulator@8085 779
pascal@17269 780 - .section ".bsdata", "a"
pascal@17269 781 -bugger_off_msg:
pascal@17269 782 - .ascii "Direct booting from floppy is no longer supported.\r\n"
pascal@17269 783 - .ascii "Please use a boot loader program instead.\r\n"
pascal@17269 784 - .ascii "\n"
pascal@17269 785 - .ascii "Remove disk and press any key to reboot . . .\r\n"
pascal@17269 786 - .byte 0
pascal@17269 787 +#if !defined(FLOPPY_ONLY) && !defined(EXE_ONLY)
pascal@17269 788 +initregs:
pascal@17269 789 + popw %si
pascal@17269 790 + INIT_REGS
pascal@17269 791 + pushw %si # use new stack
pascal@17269 792 + ret
pascal@17269 793 +#endif
pascal@17269 794
pascal@17269 795 +#ifndef EXE_SUPPORT
pascal@17269 796 +swap_floppy:
pascal@17269 797 + .ascii "Insert floppy disk 001"
pascal@17269 798 +swap_floppy_tail:
pascal@17269 799 + .ascii " and press any key."
pascal@17269 800 + .byte 7,13,0 # swap detection needs 13, 0
pascal@17269 801 +#endif
pascal@17269 802
pascal@17269 803 +#ifdef INITRD_KEYWORD
pascal@17269 804 +kwinitrd:
pascal@17269 805 + .ascii "initrd="
pascal@17269 806 + .byte 0
pascal@17269 807 +#endif
slaxemulator@8085 808 # Kernel attributes; used by setup. This is part 1 of the
slaxemulator@8085 809 # header, from the old boot sector.
pascal@17269 810