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)
.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
.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
# along with this program. If not, see <https://www.gnu.org/licenses/>.
.code16
- .section .boot,"a"
+ .section .boot,"ax"
.set stack_top, 0x7be0
.set read_retries, 0x7be8
# this is the second-stage boot loader
.code16
- .section .boot2,"a"
+ .section .boot2,"ax"
.set main_load_addr, 0x100000
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
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
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
# along with this program. If not, see <https://www.gnu.org/licenses/>.
.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:
yval: .long 0
frameno: .long 0
-numbuf: .space 16
-
logo_pal:
.incbin "logo.pal"