提交 4c1ef7b0 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Build init.

上级 7bbae2fb
#
# XXX compiling user progs with -mcmodel=kernel
#
# Custom config file? Set the default below..
-include config.mk
TOOLPREFIX ?= x86_64-jos-elf-
QEMU ?= qemu-system-x86_64
CPUS ?= 2
NM = $(TOOLPREFIX)nm
CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m64 \
-Werror -std=c99 -fms-extensions -mno-sse -mcmodel=kernel
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m64 -gdwarf-2
LDFLAGS += -m elf_x86_64
OBJS = \ OBJS = \
asm.o \ asm.o \
bio.o \ bio.o \
...@@ -26,24 +49,10 @@ OBJS = \ ...@@ -26,24 +49,10 @@ OBJS = \
trap.o \ trap.o \
trapasm.o trapasm.o
# Custom config file? Set the default below.. ULIB = ulib.o usys.o printf.o umalloc.o
-include config.mk
TOOLPREFIX ?= x86_64-jos-elf- UPROGS= \
QEMU ?= qemu-system-x86_64 _init \
CPUS ?= 2
NM = $(TOOLPREFIX)nm
CC = $(TOOLPREFIX)gcc
AS = $(TOOLPREFIX)gas
LD = $(TOOLPREFIX)ld
OBJCOPY = $(TOOLPREFIX)objcopy
OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m64 \
-Werror -std=c99 -fms-extensions -mno-sse -mcmodel=kernel
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m64 -gdwarf-2
LDFLAGS += -m elf_x86_64
kernel: boot.o $(OBJS) initcode bootother fs.img kernel: boot.o $(OBJS) initcode bootother fs.img
$(LD) $(LDFLAGS) -T kernel.ld -z max-page-size=4096 -e start \ $(LD) $(LDFLAGS) -T kernel.ld -z max-page-size=4096 -e start \
...@@ -66,6 +75,11 @@ xv6memfs.img: bootblock kernelmemfs ...@@ -66,6 +75,11 @@ xv6memfs.img: bootblock kernelmemfs
dd if=bootblock of=xv6memfs.img conv=notrunc dd if=bootblock of=xv6memfs.img conv=notrunc
dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc
_%: %.o $(ULIB)
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
$(OBJDUMP) -S $@ > $*.asm
$(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym
mkfs: mkfs.c fs.h mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o mkfs mkfs.c gcc -m32 -Werror -Wall -o mkfs mkfs.c
......
...@@ -11,7 +11,7 @@ printint(void (*putch) (void*, char), void *putarg, ...@@ -11,7 +11,7 @@ printint(void (*putch) (void*, char), void *putarg,
static char digits[] = "0123456789ABCDEF"; static char digits[] = "0123456789ABCDEF";
char buf[16]; char buf[16];
int i, neg; int i, neg;
uint x; int x;
neg = 0; neg = 0;
if(sgn && xx < 0){ if(sgn && xx < 0){
...@@ -51,9 +51,9 @@ vprintfmt(void (*putch) (void*, char), void *putarg, ...@@ -51,9 +51,9 @@ vprintfmt(void (*putch) (void*, char), void *putarg,
} }
} else if(state == '%'){ } else if(state == '%'){
if(c == 'd'){ if(c == 'd'){
printint(putch, putarg, va_arg(ap, uint), 10, 1); printint(putch, putarg, va_arg(ap, u32), 10, 1);
} else if(c == 'x' || c == 'p'){ } else if(c == 'x') {
printint(putch, putarg, va_arg(ap, uint), 16, 0); printint(putch, putarg, va_arg(ap, u32), 16, 0);
} else if(c == 's'){ } else if(c == 's'){
s = (char*) va_arg(ap, char*); s = (char*) va_arg(ap, char*);
if(s == 0) if(s == 0)
...@@ -63,7 +63,7 @@ vprintfmt(void (*putch) (void*, char), void *putarg, ...@@ -63,7 +63,7 @@ vprintfmt(void (*putch) (void*, char), void *putarg,
s++; s++;
} }
} else if(c == 'c'){ } else if(c == 'c'){
putch(putarg, va_arg(ap, uint)); putch(putarg, va_arg(ap, u32));
} else if(c == '%'){ } else if(c == '%'){
putch(putarg, c); putch(putarg, c);
} else { } else {
...@@ -80,7 +80,7 @@ vprintfmt(void (*putch) (void*, char), void *putarg, ...@@ -80,7 +80,7 @@ vprintfmt(void (*putch) (void*, char), void *putarg,
static void static void
writec(void *arg, char c) writec(void *arg, char c)
{ {
int fd = (int) arg; int fd = (int) (u64) arg;
write(fd, &c, 1); write(fd, &c, 1);
} }
...@@ -90,7 +90,7 @@ printf(int fd, char *fmt, ...) ...@@ -90,7 +90,7 @@ printf(int fd, char *fmt, ...)
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vprintfmt(writec, (void*) fd, fmt, ap); vprintfmt(writec, (void*) (u64)fd, fmt, ap);
va_end(ap); va_end(ap);
} }
...@@ -111,7 +111,7 @@ writebuf(void *arg, char c) ...@@ -111,7 +111,7 @@ writebuf(void *arg, char c)
} }
void void
vsnprintf(char *buf, uint n, char *fmt, va_list ap) vsnprintf(char *buf, u32 n, char *fmt, va_list ap)
{ {
struct bufstate bs = { buf, buf+n-1 }; struct bufstate bs = { buf, buf+n-1 };
vprintfmt(writebuf, (void*) &bs, fmt, ap); vprintfmt(writebuf, (void*) &bs, fmt, ap);
...@@ -119,7 +119,7 @@ vsnprintf(char *buf, uint n, char *fmt, va_list ap) ...@@ -119,7 +119,7 @@ vsnprintf(char *buf, uint n, char *fmt, va_list ap)
} }
void void
snprintf(char *buf, uint n, char *fmt, ...) snprintf(char *buf, u32 n, char *fmt, ...)
{ {
va_list ap; va_list ap;
......
...@@ -30,10 +30,10 @@ strcmp(const char *p, const char *q) ...@@ -30,10 +30,10 @@ strcmp(const char *p, const char *q)
{ {
while(*p && *p == *q) while(*p && *p == *q)
p++, q++; p++, q++;
return (uchar)*p - (uchar)*q; return (u8)*p - (u8)*q;
} }
uint unsigned int
strlen(char *s) strlen(char *s)
{ {
int n; int n;
...@@ -44,7 +44,7 @@ strlen(char *s) ...@@ -44,7 +44,7 @@ strlen(char *s)
} }
void* void*
memset(void *dst, int c, uint n) memset(void *dst, int c, unsigned int n)
{ {
stosb(dst, c, n); stosb(dst, c, n);
return dst; return dst;
...@@ -103,7 +103,7 @@ atoi(const char *s) ...@@ -103,7 +103,7 @@ atoi(const char *s)
} }
void* void*
memcpy(void *dst, const void *src, uint n) memcpy(void *dst, const void *src, unsigned int n)
{ {
return memmove(dst, (void *)src, n); return memmove(dst, (void *)src, n);
} }
......
...@@ -11,7 +11,7 @@ typedef long Align; ...@@ -11,7 +11,7 @@ typedef long Align;
union header { union header {
struct { struct {
union header *ptr; union header *ptr;
uint size; u32 size;
} s; } s;
Align x; Align x;
}; };
...@@ -44,7 +44,7 @@ free(void *ap) ...@@ -44,7 +44,7 @@ free(void *ap)
} }
static Header* static Header*
morecore(uint nu) morecore(u32 nu)
{ {
char *p; char *p;
Header *hp; Header *hp;
...@@ -61,10 +61,10 @@ morecore(uint nu) ...@@ -61,10 +61,10 @@ morecore(uint nu)
} }
void* void*
malloc(uint nbytes) malloc(u32 nbytes)
{ {
Header *p, *prevp; Header *p, *prevp;
uint nunits; u32 nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){ if((prevp = freep) == 0){
......
...@@ -33,11 +33,11 @@ void *memmove(void*, void*, int); ...@@ -33,11 +33,11 @@ void *memmove(void*, void*, int);
char* strchr(const char*, char c); char* strchr(const char*, char c);
int strcmp(const char*, const char*); int strcmp(const char*, const char*);
void printf(int, char*, ...); void printf(int, char*, ...);
void snprintf(char *buf, uint n, char *fmt, ...); void snprintf(char *buf, unsigned int n, char *fmt, ...);
char* gets(char*, int max); char* gets(char*, int max);
uint strlen(char*); unsigned int strlen(char*);
void* memset(void*, int, uint); void* memset(void*, int, unsigned int);
void* malloc(uint); void* malloc(unsigned int);
void free(void*); void free(void*);
int atoi(const char*); int atoi(const char*);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论