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.
4 * SYS_SIZE is the number of clicks (16 bytes) to be loaded.
7 .equ SYSSIZE, _load_size_pgh
9 /* floppyload.S Copyright (C) 1991, 1992 Linus Torvalds
10 * modified by Drew Eckhardt
11 * modified by Bruce Evans (bde)
13 * floppyprefix.S is loaded at 0x0000:0x7c00 by the bios-startup routines.
15 * It then loads the system at SYSSEG<<4, using BIOS interrupts.
17 * The loader has been made as simple as possible, and continuous read errors
18 * will result in a unbreakable loop. Reboot by hand. It loads pretty fast by
19 * getting whole tracks at a time whenever possible.
22 .equ BOOTSEG, 0x07C0 /* original address of boot-sector */
24 .equ SYSSEG, 0x1000 /* system loaded at SYSSEG<<4 */
29 .section ".prefix", "ax", @progbits
32 jmp $BOOTSEG, $go /* reload cs:ip to match relocation addr */
34 xorw %ax,%ax /* put stack at 0000:7c00 */
38 movw $0x2000-12, %di /* 0x2000 is arbitrary value >= length */
39 /* of bootsect + room for stack + 12 for */
40 /* saved disk parm block */
46 /* Many BIOS's default disk parameter tables will not recognize multi-sector
47 * reads beyond the maximum sector number specified in the default diskette
48 * parameter tables - this may mean 7 sectors in some cases.
50 * Since single sector reads are slow and out of the question, we must take care
51 * of this by creating new parameter tables (for the first disk) in RAM. We
52 * will set the maximum sector count to 36 - the most we will encounter on an
53 * ED 2.88. High doesn't hurt. Low does.
55 * Segments are as follows: ds=es=cs - BOOTSEG
59 movw %cx,%es /* access segment 0 */
60 movw $0x78, %bx /* 0:bx is parameter table address */
61 pushw %ds /* save ds */
62 /* 0:bx is parameter table address */
63 ldsw %es:(%bx),%si /* loads ds and si */
65 movw %ax,%es /* ax is BOOTSECT (loaded above) */
66 movb $6, %cl /* copy 12 bytes */
68 pushw %di /* keep a copy for later */
70 movsw /* ds:si is source, es:di is dest */
75 movw %cx,%ds /* access segment 0 */
79 popw %ds /* restore ds */
80 movw %di, dpoff /* save old parameters */
81 movw %si, dpseg /* to restore just before finishing */
83 popw %es /* reload es */
85 /* Note that es is already set up. Also cx is 0 from rep movsw above. */
87 xorb %ah,%ah /* reset FDC */
91 /* Get disk drive parameters, specifically number of sectors/track.
93 * It seems that there is no BIOS call to get the number of sectors. Guess
94 * 36 sectors if sector 36 can be read, 18 sectors if sector 18 can be read,
95 * 15 if sector 15 can be read. Otherwise guess 9.
98 movw $disksizes, %si /* table of sizes to try */
102 cbtw /* extend to word */
104 cmpw $disksizes+4, %si
105 jae got_sectors /* if all else fails, try 9 */
106 xchgw %cx,%ax /* cx = track and sector */
107 xorw %dx,%dx /* drive 0, head 0 */
108 movw $0x0200, %bx /* address after boot sector */
109 /* (512 bytes from origin, es = cs) */
110 movw $0x0201, %ax /* service 2, 1 sector */
112 jc probe_loop /* try next value */
115 movw $msg1end-msg1, %cx
119 /* ok, we've written the Loading... message, now we want to load the system */
122 movw %ax,%es /* segment of SYSSEG<<4 */
126 /* This turns off the floppy drive motor, so that we enter the kernel in a
127 * known state, and don't have to worry about it later.
134 pop %es /* = SYSSEG */
136 /* Restore original disk parameters */
145 /* Everything now loaded. %es = SYSSEG, so %es:0000 points to
146 * start of loaded image.
149 /* Jump to loaded copy */
150 ljmp $SYSSEG, $start_runtime
152 /* This routine loads the system at address SYSSEG<<4, making sure no 64kB
153 * boundaries are crossed. We try to load it as fast as possible, loading whole
154 * tracks whenever we can.
156 * in: es - starting address segment (normally SYSSEG)
159 movw $0,sread /* load whole image including prefix */
162 die: jne die /* es must be at 64kB boundary */
163 xorw %bx,%bx /* bx is starting address within segment */
168 shrw %cl,%dx /* bx is always divisible by 16 */
170 cmpw $SYSSEG+SYSSIZE, %ax /* have we loaded all yet? */
212 pushw %bp /* just in case the BIOS is buggy */
213 movw $0x0e2e, %ax /* 0x2e = . */
229 pushw %dx /* save for error dump */
240 bad_rt: pushw %ax /* save error code */
241 call print_all /* ah = error, al = read */
251 /* print_all is for debugging purposes. It will print out all of the registers.
252 * The assumption is that this is called from a routine, with a stack frame like
262 call print_nl /* nl for readability */
263 movw $5, %cx /* error code + 4 registers */
267 pushw %cx /* save count left */
270 jae no_reg /* see if register name is needed */
272 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
273 movw $0xe05+0x41-1, %ax
277 movb $0x58, %al /* 'X' */
280 movb $0x3A, %al /* ':' */
284 addw $2, %bp /* next register */
285 call print_hex /* print it */
286 movb $0x20, %al /* print a space */
290 call print_nl /* nl for readability */
294 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
295 movb $0x0e, %ah /* write char, tty mode */
303 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
304 movw $0xe0d, %ax /* CR */
306 movb $0xa, %al /* LF */
310 /* print_hex prints the word pointed to by ss:bp in hexadecimal. */
313 movw (%bp),%dx /* load word into dx */
315 movb $0x0e, %ah /* write char, tty mode */
316 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
322 rol %cl,%dx /* rotate so that lowest 4 bits are used */
323 movb $0x0f, %al /* mask for nybble */
325 addb $0x90, %al /* convert al to ascii hex (four instructions) */
332 sread: .word 0 /* sectors read of current track */
333 head: .word 0 /* current head */
334 track: .word 0 /* current track */
346 .ascii "Loading ROM image"
355 /* Jump to .text16 segment */
359 .section ".text16", "awx", @progbits
364 popl %eax /* discard */
366 /* Boot next device */