提交 0a9fa87b 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Rejigger how the build embeds initcode, bootother, and fs.img in the ELF.

Instead of using ld -b binary, build incbin.S, which uses gas' .incbin.
上级 45a9876c
*~
_*
*.o
*.d
*.asm
*.sym
*.img
vectors.S
bootblock
bootother
bootother.out
initcode
initcode.out
kernel
mkfs
o.*
.gdbinit
/mtrace.out
/mtrace.txt
......
......@@ -62,7 +62,8 @@ OBJS = \
vm.o \
trap.o \
trapasm.o \
wq.o
wq.o \
incbin.o
OBJS := $(addprefix $(O)/, $(OBJS))
ULIB = ulib.o usys.o printf.o umalloc.o uthread.o
......@@ -81,10 +82,10 @@ UPROGS= \
_thrtest
UPROGS := $(addprefix $(O)/, $(UPROGS))
$(O)/kernel: $(O) $(O)/boot.o $(OBJS) initcode bootother fs.img
$(O)/kernel: $(O) $(O)/boot.o $(OBJS)
@echo " LD $@"
$(Q)$(LD) $(LDFLAGS) -T kernel.ld -z max-page-size=4096 -e start \
-o $@ $(O)/boot.o $(OBJS) -b binary initcode bootother fs.img
-o $@ $(O)/boot.o $(OBJS)
$(O):
$(Q)mkdir $(O)
......@@ -93,13 +94,15 @@ $(O)/%.o: %.c
@echo " CC $@"
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
$(O)/incbin.o: ASFLAGS+=-DMAKE_OUT=$(O)
$(O)/incbin.o: $(O)/initcode $(O)/bootother $(O)/fs.img
$(O)/%.o: %.S
@echo " CC $@"
$(Q)$(CC) $(ASFLAGS) -c -o $@ $<
initcode: TTEXT = 0x0
bootother: TTEXT = 0x7000
%: %.S
$(O)/initcode: TTEXT = 0x0
$(O)/bootother: TTEXT = 0x7000
$(O)/%: %.S
@echo " CC $@"
$(Q)$(CC) $(CFLAGS) -nostdinc -I. -c $< -o $@.o
$(Q)$(LD) $(LDFLAGS) -N -e start -Ttext $(TTEXT) -o $@.out $@.o
......@@ -114,17 +117,17 @@ _%: %.o $(ULIB)
@echo " LD $@"
$(Q)$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o mkfs mkfs.c
$(O)/mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o $@ mkfs.c
fs.img: mkfs README $(UPROGS)
$(O)/fs.img: $(O)/mkfs README $(UPROGS)
@echo " MKFS $@"
$(Q)./mkfs $@ README $(UPROGS)
$(Q)$(O)/mkfs $@ README $(UPROGS)
mscan.syms: kernel
$(O)/mscan.syms: $(O)/kernel
$(NM) -S $< > $@
mscan.kern: kernel
$(O)/mscan.kern: $(O)/kernel
cp $< $@
-include *.d
......@@ -148,9 +151,9 @@ gdb: $(O)/kernel
##
MTRACEOPTS = -rtc clock=vm -mtrace-enable -mtrace-file mtrace.out \
-mtrace-quantum 100
mtrace.out: mscan.kern mscan.syms
mtrace.out: $(O)/mscan.kern $(O)/mscan.syms
$(Q)rm -f mtrace.out
$(MTRACE) $(QEMUOPTS) $(MTRACEOPTS) -kernel mscan.kern
$(MTRACE) $(QEMUOPTS) $(MTRACEOPTS) -kernel $(O)/mscan.kern
mscan.out: $(QEMUSRC)/mtrace-tools/mscan mtrace.out
$(QEMUSRC)/mtrace-tools/mscan > $@ || (rm -f $@; exit 2)
......@@ -162,4 +165,4 @@ rsync: $(O)/kernel
rsync -avP $(O)/kernel amsterdam.csail.mit.edu:/tftpboot/$(HW)/kernel.xv6
clean:
rm -fr $(O) *.d *.asm *.sym initcode kernel bootother mkfs fs.img
rm -fr $(O)
#define __str_1(x...) #x
#define __str(x...) __str_1(x)
#define include_bin(file, name) \
.globl _##name##_start; \
_##name##_start:; \
.incbin __str(MAKE_OUT/file); \
_##name##_end:; \
.globl _##name##_size; \
_##name##_size:; \
.quad _##name##_end - _##name##_start
include_bin(initcode,initcode)
include_bin(bootother,bootother)
include_bin(fs.img,fs_img)
......@@ -41,7 +41,8 @@ mpboot(void)
static void
bootothers(void)
{
extern u8 _binary_bootother_start[], _binary_bootother_size[];
extern u8 _bootother_start[];
extern u64 _bootother_size;
extern void (*apstart)(void);
struct cpu *c;
char *stack;
......@@ -51,7 +52,7 @@ bootothers(void)
// The linker has placed the image of bootother.S in
// _binary_bootother_start.
code = p2v(0x7000);
memmove(code, _binary_bootother_start, (u64)_binary_bootother_size);
memmove(code, _bootother_start, _bootother_size);
for(c = cpus; c < cpus+ncpu; c++){
if(c == cpus+cpunum()) // We've started already.
......
......@@ -12,7 +12,8 @@
#include "traps.h"
#include "buf.h"
extern u8 _binary_fs_img_start[], _binary_fs_img_size[];
extern u8 _fs_img_start[];
extern u64 _fs_img_size;
static u64 disksize;
static u8 *memdisk;
......@@ -20,8 +21,8 @@ static u8 *memdisk;
void
initdisk(void)
{
memdisk = _binary_fs_img_start;
disksize = (u64)_binary_fs_img_size/512;
memdisk = _fs_img_start;
disksize = _fs_img_size/512;
}
// Interrupt handler.
......
......@@ -236,19 +236,20 @@ void
inituser(void)
{
struct proc *p;
extern char _binary_initcode_start[], _binary_initcode_size[];
extern u8 _initcode_start[];
extern u64 _initcode_size;
p = allocproc();
bootproc = p;
if((p->vmap = vmap_alloc()) == 0)
panic("userinit: out of vmaps?");
struct vmnode *vmn =
vmn_allocpg(PGROUNDUP((uptr)_binary_initcode_size) / PGSIZE);
vmn_allocpg(PGROUNDUP(_initcode_size) / PGSIZE);
if(vmn == 0)
panic("userinit: vmn_allocpg");
if(vmap_insert(p->vmap, vmn, 0) < 0)
panic("userinit: vmap_insert");
if(copyout(p->vmap, 0, _binary_initcode_start, (uptr)_binary_initcode_size) < 0)
if(copyout(p->vmap, 0, _initcode_start, _initcode_size) < 0)
panic("userinit: copyout");
memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = UCSEG | 0x3;
......
#!/usr/bin/perl -w
# Generate vectors.S, the trap/interrupt entry points.
# There has to be one entry point per interrupt number
# since otherwise there's no way for trap() to discover
# the interrupt number.
print "# generated by vectors.pl - do not edit\n";
print "# handlers\n";
print ".globl alltraps\n";
for(my $i = 0; $i < 256; $i++){
print ".globl vector$i\n";
print "vector$i:\n";
if(!($i == 8 || ($i >= 10 && $i <= 14) || $i == 17)){
print " pushl \$0\n";
}
print " pushl \$$i\n";
print " jmp alltraps\n";
}
print "\n# vector table\n";
print ".data\n";
print ".globl vectors\n";
print "vectors:\n";
for(my $i = 0; $i < 256; $i++){
print " .long vector$i\n";
}
# sample output:
# # handlers
# .globl alltraps
# .globl vector0
# vector0:
# pushl $0
# pushl $0
# jmp alltraps
# ...
#
# # vector table
# .data
# .globl vectors
# vectors:
# .long vector0
# .long vector1
# .long vector2
# ...
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论