From 59fead6413261b10245508edc5f18316371cfaae Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 10 May 2008 15:49:20 -0400 Subject: [PATCH] Fix elf build; rename target file rom.bin to bios.bin. The main output file is now called out/bios.bin (instead of out/rom.bin). Use ld to build final elf file and call the result out/bios.bin.elf Make sure to long jump from external 32bit entry point. --- Makefile | 4 ++-- README | 6 +++--- src/post.c | 2 +- tools/buildrom.py | 7 +++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 3d7c3e2..c8e68bd 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables CFLAGS16 = $(CFLAGS16INC) -g TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC))) -all: $(OUT) $(OUT)rom.bin $(TABLETMP) +all: $(OUT) $(OUT)bios.bin $(TABLETMP) # Run with "make V=1" to see the actual compile commands ifdef V @@ -103,7 +103,7 @@ $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds @echo " Linking $@" $(Q)ld -T $(OUT)rombios32.lds $< -o $@ -$(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h +$(OUT)bios.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h @echo " Building $@" $(Q)./tools/buildrom.py diff --git a/README b/README index dc0a725..fe5f601 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ This code implements an X86 legacy bios. It is intended to be compiled using standard gnu tools (eg, gas and gcc). To build, one should be able to run "make" in the main directory. The -resulting file "out/rom.bin" contains the processed bios image. +resulting file "out/bios.bin" contains the processed bios image. The build requires gcc v4.1 or later. Some buggy versions of gcc have issues with the '-combine' compiler option - in particular, recent @@ -15,13 +15,13 @@ Testing of images: To test the bios under bochs, one will need to instruct bochs to use the new bios image. Use the 'romimage' option - for example: -bochs -q 'floppya: 1_44=myfdimage.img' 'romimage: file=out/rom.bin' +bochs -q 'floppya: 1_44=myfdimage.img' 'romimage: file=out/bios.bin' To test under qemu, one will need to create a directory with all the bios images and then overwrite the main bios image. For example: cp /usr/share/qemu/*.bin mybiosdir/ -cp out/rom.bin mybiosdir/bios.bin +cp out/bios.bin mybiosdir/ Once this is setup, one can instruct qemu to use the newly created directory for rom images. For example: diff --git a/src/post.c b/src/post.c index f69773f..0d8f18e 100644 --- a/src/post.c +++ b/src/post.c @@ -275,5 +275,5 @@ asm( "lidtl " __stringify(0xf0000 | OFFSET_pmode_IDT_info) "\n" "lgdtl " __stringify(0xf0000 | OFFSET_rombios32_gdt_48) "\n" "movl $" __stringify(CONFIG_STACK_OFFSET) ", %esp\n" - "jmp _start\n" + "ljmp $0x10, $_start\n" ); diff --git a/tools/buildrom.py b/tools/buildrom.py index 83bedde..7d48cb5 100755 --- a/tools/buildrom.py +++ b/tools/buildrom.py @@ -13,7 +13,7 @@ ROM16='out/rom16.bin' ROM32='out/rom32.bin' OFFSETS16='out/rom16.offset.auto.h' OFFSETS32='out/rom32.offset.auto.h' -OUT='out/rom.bin' +OUT='out/bios.bin' def align(v, a): return (v + a - 1) // a * a @@ -81,9 +81,8 @@ def main(): # Build elf file with 32bit entry point os.system( - "objcopy -I binary -O elf32-i386 -B i386" - " --change-addresses 0xf0000 --set-start %s %s %s" %( - int(o32['OFFSET_post32'], 16) - 0xf0000, OUT, OUT+".o")) + "ld -melf_i386 -e %s -Ttext 0xf0000 -b binary %s -o %s" % ( + int(o32['OFFSET_post32'], 16), OUT, OUT+".elf")) if __name__ == '__main__': main() -- 2.25.1