TOOLPREFIX =
CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-builtin -O2 -Wall -MD -ggdb -m32
#CFLAGS += -fno-stack-protector
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m32
LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null)
qemu: bootblock
dd if=/dev/zero of=mcore.img count=10000
dd if=bootblock of=mcore.img conv=notrunc
qemu -hda mcore.img -boot c
bootblock: bootasm.S bootmain.c
$(CC) $(CFLAGS) -O -nostdinc -I. -c bootmain.c
$(CC) $(CFLAGS) -nostdinc -I. -c bootasm.S
$(LD) $(LDFLAGS) -N -e start -Ttext 0x7c00 -o bootblock.o bootasm.o bootmain.o
$(OBJDUMP) -S bootblock.o > bootblock.asm
$(OBJCOPY) -S -O binary bootblock.o bootblock
./sign.pl bootblock
clean:
rm -f *.o bootblock *.d *.asm *.img
|
1. $(LD) $(LDFLAGS) -N -e start -Ttext 0x7c00 -o bootblock.o bootasm.o bootmain.o
-N Set the text and data sections to be readable and writable.
-e entry. Use entry as the explicit symbol for beginning execution of your program, rather than the default entry point. If there is no symbol named entry, the linker will try to parse entry as a number,
-Ttext Locate a section in the output file at the absolute address given by org.
-o the output file name
上面命令的意思是:把bootasm.o 和 bootmain.o链接成bootblock.o, 并指定bootblock.0为可读可写,入口符合是start, 代码段的绝对起始地址是0x7c00.
2. $(OBJCOPY) -S -O binary bootblock.o bootblock
-S Do not copy relocation and symbol information from the source file.
-O bfdname. Write the output file using the object format bfdname.
即,copy bootblock.o到bootblock中,且不包含重定位和符合信息,且输出的格式是二进制。
#!/usr/bin/perl
open(SIG, $ARGV[0]) || die "open $ARGV[0]: $!";
$n = sysread(SIG, $buf, 1000);
if($n > 510){
print STDERR "boot block too large: $n bytes (max 510)\n";
exit 1;
}
print STDERR "boot block is $n bytes (max 510)\n";
$buf .= "\0" x (510-$n);
$buf .= "\x55\xAA";
open(SIG, ">$ARGV[0]") || die "open >$ARGV[0]: $!";
print SIG $buf;
close SIG;
|
阅读(958) | 评论(0) | 转发(0) |