 /*   20000121  Rick Hohensee  bootsector.S   GNU assembler syntax

We are 512 bytes loaded in RAM at 0x7c00 by the BIOS. 
Our brain is 80386 real address mode, 16 bit. We're in segment 0.
Certain IO addresses are known. We have a 16 bit BIOS.  
Howdy y'all!
We want to load stage 2 from floppy, turn into a 386+ maybe, and 
jump to stage 2.
We assume a floppy. We assume a real OS for a parent as far as building the
floppy. That means clean catenation, raw floppy writes and assembly of 
headerless binaries. On said floppy we can assume that all this stuff 
is in sectors 1 <-> 7 or so, with stage2 byte-adjacent to the bootsector. 
/help/HARDWARE.TXT
floppy
	*PS/2* FDC Diskette Status Register A at 3F0h 
	*PS/2* FDC Diskette Status Register B at 3F0h 
******	FDC Digital Output Register at 3F2h**************** motor control
	FDC Main Status Register at 3F4h 
	FDC Command Status Register 0 at 3F5h
*/

.code16			/* 
		GNU ../binutils<ver>/gas/doc/c-i386.html
			*/
.text			/* .text is a code segment. Go figure.		*/
.globl	_start		/*   GNU ld looks for _start by default		*/

/* sequence......
	wait for BIOS to relinquish the FDC	
	Turn on floppy motor. It's still spinning, so no delay this way.
	throw up some junk on the screen
	Load ourself and stage2. (and stage3 ?)
		We can overlay a bigger us over ourself if we don't have any
		state in memory. We don't, at this point.
	stash system info
		(Where's our stack? Who cares?)
	Turn into a 386
	branch to stage2, "main" 
*/

_start:					/* default GNU ld starting point */

wait_floppy_off:				/* loop till the floppy motor
						gets turned off	by the BIOS 
						leftovers.			*/
	mov     $0x3f1, %dx
	inb     %dx , %ax
	and	$0x01, %ax
	jne	wait_floppy_off

motor_on:
	mov 	$0x3f2, %dx			/* reset floppy controller  	*/
	mov 	$0x04, %ax
	outb    %al, %dx 	
	mov 	$0x3f2, %dx			/* turn on floppy motor  	*/
	mov 	$0xf0, %ax
	outb    %al, %dx 			/* opcode 0xee :o)  		*/

cLIeNUX:
        mov     $0x03 , %ah			/* set? cursor loc. 		*/
        xor     %bh , %bh
        int     $0x10
        mov     $0x0100 , %cx			/* display stuff	 	*/
        mov     $0x07 , %bx       			
        mov     $0x7c40 , %bp			
        mov     $0x1301 , %ax          			
        int     $0x10					

	cli

blazz:
	nop
	nop
	
	mov	$0x1, %eax		/* 	"	*/
	mov	%eax, %cr0		/*      "       */
	jmp  IA32
IA32:
	nop
	nop
	jmp IA32






endcode:				/* same place by 2 names. No worries. */
splash:
	.byte 10,13
	.byte 10,13
	.byte 10,13
	.ascii "cLIeNUX Bootsector."
	.byte 10,13

	.byte   0xb0
	.byte   0xb0
	.byte   0xb0
	.byte   0xb0
	.byte   0xb0

.org 510
boot_flag:
	.word 0xAA55
stage_2:

/* no nothing down here. This will be stage_2 courtesy of cat. It will
apparently be possible for stage 2 to be written in regular 32 bit gcc. 
Plus hand-rolled exception handlers, no libc of course, etc. etc. 
Should be fun in "C"  :/  */
