diff --git a/Makefile b/Makefile index b953e39..c4961a4 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,7 @@ all: boot.bin clean: - rm -f *.o - rm -f boot.elf boot.bin + rm -f *.o boot.elf boot.bin config.mk: | config.default.mk cp config.default.mk $@ @@ -14,8 +13,8 @@ config.mk: | config.default.mk boot.bin: boot.elf objcopy -O binary --only-section=.text boot.elf $@ -boot.elf: boot16.o fernlader.ld - $(LD) $(LDFLAGS) -o $@ boot16.o +boot.elf: lboot.o fernlader.ld + $(LD) $(LDFLAGS) -o $@ lboot.o .S.o: $(CC) $(CFLAGS) -c -o $@ $(@:.o=.S) diff --git a/boot16.S b/lboot.S similarity index 63% rename from boot16.S rename to lboot.S index 2455077..1fb6565 100644 --- a/boot16.S +++ b/lboot.S @@ -7,21 +7,23 @@ _start: cli cld - mov %cs, %ax + // we keep our text and data close to each other + xor %ax, %ax mov %ax, %ds - mov $message, %si + mov $msg_start, %si call print + mov $msg_a20, %si + call print call enable_a20 - lea message, %si + mov $msg_unreal, %si call print + call unreal - lgdt gdt_ptr - - call enter_prot - + mov $msg_fin, %si + call print 1: hlt jmp 1b @@ -31,11 +33,24 @@ enable_a20: // TODO more thorough implementation outb %al, $0x92 ret -enter_prot: mov %cr0, %eax - or $1, %al +unreal: push %ds + lgdt gdt_ptr + + mov %cr0, %eax + or $0x01, %al mov %eax, %cr0 - ret + ljmp $0x8, $1f + +1: mov $0x10, %cx + mov %cx, %ds + and $0xFE, %al + mov %eax, %cr0 + ljmp $0x0, $2f + +2: pop %ds + ret + print: xor %bx, %bx 1: lodsb @@ -72,4 +87,7 @@ gdt: // entry 0: null descriptor gdt_ptr: .word gdt_size-1 .long gdt -message: .asciz "Hello, World!\r\n" +msg_start: .asciz "Netboot via fernlader v1 ...\r\n" +msg_a20: .asciz " * Enabling A20\r\n" +msg_unreal: .asciz " * Unreal Mode\r\n" +msg_fin: .asciz "Finished.\r\n"