From: John Tsiombikas Date: Tue, 24 Apr 2018 23:42:31 +0000 (+0300) Subject: second stage boot loader now loads the main program X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=commitdiff_plain;h=559dd7c3c836a69eac46bd12c7ef61bb5de8882c second stage boot loader now loads the main program --- diff --git a/Makefile b/Makefile index 7fa61b9..0722ce4 100644 --- a/Makefile +++ b/Makefile @@ -20,12 +20,20 @@ ifneq ($(shell uname -m), i386) ldarch = -m elf_i386 endif -floppy.img: $(bin) +floppy.img: boot.img dd if=/dev/zero of=$@ bs=512 count=2880 dd if=$< of=$@ conv=notrunc +boot.img: bootldr.bin $(bin) + cat bootldr.bin $(bin) >$@ + +# bootldr.bin will contain only .boot and .boot2 +bootldr.bin: $(elf) + objcopy -O binary -j '.boot*' $< $@ + +# the main binary will contain every section *except* .boot and .boot2 $(bin): $(elf) - objcopy -O binary $< $@ + objcopy -O binary -R '.boot*' $< $@ $(elf): $(obj) $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS) @@ -37,12 +45,21 @@ $(elf): $(obj) .PHONY: clean clean: - rm -f $(obj) $(bin) floppy.img + rm -f $(obj) $(bin) boot.img floppy.img link.map .PHONY: cleandep cleandep: rm -f $(dep) +.PHONY: disasm +disasm: bootldr.disasm $(elf).disasm + +bootldr.disasm: $(elf) + objdump -d $< -j .boot -j .boot2 -m i8086 >$@ + +$(elf).disasm: $(elf) + objdump -d $< -j .startup -j .text -m i386 >$@ + .PHONY: run run: $(bin) qemu-system-i386 -fda floppy.img -serial file:serial.log diff --git a/pcboot.ld b/pcboot.ld index 4879417..e2c0308 100644 --- a/pcboot.ld +++ b/pcboot.ld @@ -7,7 +7,11 @@ SECTIONS { .boot : { * (.boot); } /* second stage boot loader */ - .boot2 : { * (.boot2); } + .boot2 : { + * (.boot2); + /* pad the boot loader to the next sector boundary */ + . = ALIGN(512); + } _boot2_size = SIZEOF(.boot2); /* main program will be loaded at 1MB by the second stage diff --git a/src/boot/boot.s b/src/boot/boot.s index b976ec7..50817a3 100644 --- a/src/boot/boot.s +++ b/src/boot/boot.s @@ -15,7 +15,7 @@ # along with this program. If not, see . .code16 - .section .boot,"a" + .section .boot,"ax" .set stack_top, 0x7be0 .set read_retries, 0x7be8 diff --git a/src/boot/boot2.s b/src/boot/boot2.s index 161bd73..6372557 100644 --- a/src/boot/boot2.s +++ b/src/boot/boot2.s @@ -16,7 +16,7 @@ # this is the second-stage boot loader .code16 - .section .boot2,"a" + .section .boot2,"ax" .set main_load_addr, 0x100000 @@ -230,15 +230,15 @@ ldloop: mov $10, %ax call putchar - # DBG - hlt - ret rdtrk_msg: .asciz "Reading track: " rdcyl_msg: .asciz " - cyl: " rdhead_msg: .asciz " head: " rdsect_msg: .asciz " start sect: " +rdlast_msg: .asciz " ... " +rdok_msg: .asciz "OK\n" +rdfail_msg: .asciz "failed\n" read_retries: .short 0 @@ -292,8 +292,8 @@ read_try: call putstr mov trk_sect, %eax call print_num - mov $10, %al - call putchar + mov $rdlast_msg, %esi + call putstr # start sector (1-based) in cl[0, 5] mov trk_sect, %al @@ -320,11 +320,13 @@ read_try: jmp read_try read_fail: + mov $rdfail_msg, %esi + call putstr jmp abort_read read_ok: - mov $35, %ax - call putchar + mov $rdok_msg, %esi + call putstr # reset es to 0 before returning xor %ax, %ax diff --git a/src/startup.s b/src/startup.s index 42e4b21..bff3991 100644 --- a/src/startup.s +++ b/src/startup.s @@ -15,16 +15,19 @@ # along with this program. If not, see . .code32 - .section .startup + .section .startup,"ax" .extern _bss_start .extern _bss_end + # zero the BSS section xor %eax, %eax mov _bss_start, %edi mov _bss_size, %ecx + jz skip_bss_zero shr $4, %ecx rep stosl +skip_bss_zero: logohack: @@ -131,8 +134,6 @@ xval: .long 0 yval: .long 0 frameno: .long 0 -numbuf: .space 16 - logo_pal: .incbin "logo.pal"