1 /* NOTE: this boot sector contains instructions that need at least an 80186.
2 * Yes, as86 has a bug somewhere in the valid instruction set checks.
6 /* floppyload.S Copyright (C) 1991, 1992 Linus Torvalds
7 * modified by Drew Eckhardt
8 * modified by Bruce Evans (bde)
10 * floppyprefix.S is loaded at 0x0000:0x7c00 by the bios-startup routines.
12 * It then loads the system at SYSSEG<<4, using BIOS interrupts.
14 * The loader has been made as simple as possible, and continuous read errors
15 * will result in a unbreakable loop. Reboot by hand. It loads pretty fast by
16 * getting whole tracks at a time whenever possible.
19 .equ BOOTSEG, 0x07C0 /* original address of boot-sector */
21 .equ SYSSEG, 0x1000 /* system loaded at SYSSEG<<4 */
26 .section ".prefix", "ax", @progbits
29 jmp $BOOTSEG, $go /* reload cs:ip to match relocation addr */
31 movw $0x2000-12, %di /* 0x2000 is arbitrary value >= length */
32 /* of bootsect + room for stack + 12 for */
33 /* saved disk parm block */
38 movw %ax,%ss /* put stack at BOOTSEG:0x4000-12. */
41 /* Many BIOS's default disk parameter tables will not recognize multi-sector
42 * reads beyond the maximum sector number specified in the default diskette
43 * parameter tables - this may mean 7 sectors in some cases.
45 * Since single sector reads are slow and out of the question, we must take care
46 * of this by creating new parameter tables (for the first disk) in RAM. We
47 * will set the maximum sector count to 36 - the most we will encounter on an
48 * ED 2.88. High doesn't hurt. Low does.
50 * Segments are as follows: ds=es=ss=cs - BOOTSEG
54 movw %cx,%es /* access segment 0 */
55 movw $0x78, %bx /* 0:bx is parameter table address */
56 pushw %ds /* save ds */
57 /* 0:bx is parameter table address */
58 ldsw %es:(%bx),%si /* loads ds and si */
60 movw %ax,%es /* ax is BOOTSECT (loaded above) */
61 movb $6, %cl /* copy 12 bytes */
63 pushw %di /* keep a copy for later */
65 movsw /* ds:si is source, es:di is dest */
70 movw %cx,%ds /* access segment 0 */
74 popw %ds /* restore ds */
75 movw %di, dpoff /* save old parameters */
76 movw %si, dpseg /* to restore just before finishing */
78 popw %es /* reload es */
80 /* Note that es is already set up. Also cx is 0 from rep movsw above. */
82 xorb %ah,%ah /* reset FDC */
86 /* Get disk drive parameters, specifically number of sectors/track.
88 * It seems that there is no BIOS call to get the number of sectors. Guess
89 * 36 sectors if sector 36 can be read, 18 sectors if sector 18 can be read,
90 * 15 if sector 15 can be read. Otherwise guess 9.
93 movw $disksizes, %si /* table of sizes to try */
97 cbtw /* extend to word */
99 cmpw $disksizes+4, %si
100 jae got_sectors /* if all else fails, try 9 */
101 xchgw %cx,%ax /* cx = track and sector */
102 xorw %dx,%dx /* drive 0, head 0 */
103 movw $0x0200, %bx /* address after boot sector */
104 /* (512 bytes from origin, es = cs) */
105 movw $0x0201, %ax /* service 2, 1 sector */
107 jc probe_loop /* try next value */
110 movw $msg1end-msg1, %cx
114 /* ok, we've written the Loading... message, now we want to load the system */
117 movw %ax,%es /* segment of SYSSEG<<4 */
121 /* This turns off the floppy drive motor, so that we enter the kernel in a
122 * known state, and don't have to worry about it later.
129 pop %es /* = SYSSEG */
131 /* Restore original disk parameters */
140 /* Everything now loaded. %es = SYSSEG, so %es:0000 points to
141 * start of loaded image.
144 /* Jump to loaded copy */
145 ljmp $SYSSEG, $start_runtime
147 endseg: .word SYSSEG + _load_size_pgh
148 .section ".zinfo.fixup", "a" /* Compressor fixup information */
155 /* This routine loads the system at address SYSSEG<<4, making sure no 64kB
156 * boundaries are crossed. We try to load it as fast as possible, loading whole
157 * tracks whenever we can.
159 * in: es - starting address segment (normally SYSSEG)
162 movw $0,sread /* load whole image including prefix */
165 die: jne die /* es must be at 64kB boundary */
166 xorw %bx,%bx /* bx is starting address within segment */
171 shrw %cl,%dx /* bx is always divisible by 16 */
173 cmpw endseg, %ax /* have we loaded all yet? */
215 pushw %bp /* just in case the BIOS is buggy */
216 movw $0x0e2e, %ax /* 0x2e = . */
232 pushw %dx /* save for error dump */
243 bad_rt: pushw %ax /* save error code */
244 call print_all /* ah = error, al = read */
254 /* print_all is for debugging purposes. It will print out all of the registers.
255 * The assumption is that this is called from a routine, with a stack frame like
265 call print_nl /* nl for readability */
266 movw $5, %cx /* error code + 4 registers */
270 pushw %cx /* save count left */
273 jae no_reg /* see if register name is needed */
275 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
276 movw $0xe05+0x41-1, %ax
280 movb $0x58, %al /* 'X' */
283 movb $0x3A, %al /* ':' */
287 addw $2, %bp /* next register */
288 call print_hex /* print it */
289 movb $0x20, %al /* print a space */
293 call print_nl /* nl for readability */
297 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
298 movb $0x0e, %ah /* write char, tty mode */
306 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
307 movw $0xe0d, %ax /* CR */
309 movb $0xa, %al /* LF */
313 /* print_hex prints the word pointed to by ss:bp in hexadecimal. */
316 movw (%bp),%dx /* load word into dx */
318 movb $0x0e, %ah /* write char, tty mode */
319 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
325 rol %cl,%dx /* rotate so that lowest 4 bits are used */
326 movb $0x0f, %al /* mask for nybble */
328 addb $0x90, %al /* convert al to ascii hex (four instructions) */
335 sread: .word 0 /* sectors read of current track */
336 head: .word 0 /* current head */
337 track: .word 0 /* current track */
349 .ascii "Loading ROM image"
358 /* Set up real-mode stack */
362 /* Jump to .text16 segment */
366 .section ".text16", "awx", @progbits
371 popl %eax /* discard */
373 /* Boot next device */