From 5684556c19c50d38ad3873686d893481ea7d5509 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Wed, 5 Jun 2019 14:31:13 -0400 Subject: [PATCH] clean up -Wall --- Makefile | 35 +++-------------------------------- defs.h | 6 +++--- exec.c | 1 - file.c | 4 ---- proc.c | 11 ++++++----- trap.c | 19 ++++++------------- vm.c | 3 +-- 7 files changed, 19 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index 1e45056..57a57cd 100644 --- a/Makefile +++ b/Makefile @@ -25,36 +25,6 @@ OBJS = \ kernelvec.o \ plic.o -XXXOBJS = \ - bio.o\ - console.o\ - exec.o\ - file.o\ - fs.o\ - ide.o\ - ioapic.o\ - kalloc.o\ - kbd.o\ - lapic.o\ - log.o\ - main.o\ - mp.o\ - picirq.o\ - pipe.o\ - proc.o\ - sleeplock.o\ - spinlock.o\ - string.o\ - swtch.o\ - syscall.o\ - sysfile.o\ - sysproc.o\ - trapasm.o\ - trap.o\ - uart.o\ - vectors.o\ - vm.o\ - # riscv64-unknown-elf- or riscv64-linux-gnu- # perhaps in /opt/riscv/bin #TOOLPREFIX = @@ -79,8 +49,9 @@ LD = $(TOOLPREFIX)ld OBJCOPY = $(TOOLPREFIX)objcopy OBJDUMP = $(TOOLPREFIX)objdump -CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -Werror -fno-omit-frame-pointer -O -CFLAGS = -mcmodel=medany +# CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -Werror -fno-omit-frame-pointer -O +CFLAGS = -Wall -Werror +CFLAGS += -mcmodel=medany CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) diff --git a/defs.h b/defs.h index 2353e4a..2e991a1 100644 --- a/defs.h +++ b/defs.h @@ -122,8 +122,8 @@ void userinit(void); int wait(void); void wakeup(void*); void yield(void); -int either_copyout(int user_dst, uint64 dst, char *src, uint64 len); -int either_copyin(char *dst, int user_src, uint64 src, uint64 len); +int either_copyout(int user_dst, uint64 dst, void *src, uint64 len); +int either_copyin(void *dst, int user_src, uint64 src, uint64 len); // swtch.S void swtch(struct context*, struct context*); @@ -181,7 +181,7 @@ int uartgetc(void); void kvminit(void); void kvminithart(void); pagetable_t uvmcreate(void); -void uvminit(pagetable_t, char *, uint); +void uvminit(pagetable_t, uchar *, uint); uint64 uvmalloc(pagetable_t, uint64, uint64); uint64 uvmdealloc(pagetable_t, uint64, uint64); void uvmcopy(pagetable_t, pagetable_t, uint64); diff --git a/exec.c b/exec.c index 63b5b62..c9af395 100644 --- a/exec.c +++ b/exec.c @@ -129,7 +129,6 @@ loadseg(pagetable_t pagetable, uint64 va, struct inode *ip, uint offset, uint sz { uint i, n; uint64 pa; - pte_t *pte; if((va % PGSIZE) != 0) panic("loadseg: va must be page aligned"); diff --git a/file.c b/file.c index 2a903b0..6f27f22 100644 --- a/file.c +++ b/file.c @@ -106,9 +106,7 @@ filestat(struct file *f, uint64 addr) int fileread(struct file *f, uint64 addr, int n) { - struct proc *p = myproc(); int r = 0; - char *buf; if(f->readable == 0) return -1; @@ -133,9 +131,7 @@ fileread(struct file *f, uint64 addr, int n) int filewrite(struct file *f, uint64 addr, int n) { - struct proc *p = myproc(); int r, ret = 0; - char *buf; if(f->writable == 0) return -1; diff --git a/proc.c b/proc.c index 7093566..d23cb95 100644 --- a/proc.c +++ b/proc.c @@ -150,7 +150,7 @@ proc_freepagetable(pagetable_t pagetable, uint64 sz) // a user program that calls exec("/init") // od -t xC initcode -unsigned char initcode[] = { +uchar initcode[] = { 0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x05, 0x02, 0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x05, 0x02, 0x9d, 0x48, 0x73, 0x00, 0x00, 0x00, 0x89, 0x48, 0x73, 0x00, 0x00, 0x00, 0xef, 0xf0, 0xbf, 0xff, 0x2f, 0x69, 0x6e, 0x69, 0x74, 0x00, 0x00, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -429,9 +429,8 @@ yield(void) void forkret(void) { - struct proc *p = myproc(); - static int first = 1; + // Still holding ptable.lock from scheduler. release(&ptable.lock); @@ -535,13 +534,14 @@ kill(int pid) // depending on usr_dst. // Returns 0 on success, -1 on error. int -either_copyout(int user_dst, uint64 dst, char *src, uint64 len) +either_copyout(int user_dst, uint64 dst, void *src, uint64 len) { struct proc *p = myproc(); if(user_dst){ return copyout(p->pagetable, dst, src, len); } else { memmove((char *)dst, src, len); + return 0; } } @@ -549,13 +549,14 @@ either_copyout(int user_dst, uint64 dst, char *src, uint64 len) // depending on usr_src. // Returns 0 on success, -1 on error. int -either_copyin(char *dst, int user_src, uint64 src, uint64 len) +either_copyin(void *dst, int user_src, uint64 src, uint64 len) { struct proc *p = myproc(); if(user_src){ return copyin(p->pagetable, dst, src, len); } else { memmove(dst, (char*)src, len); + return 0; } } diff --git a/trap.c b/trap.c index 929f761..050a94d 100644 --- a/trap.c +++ b/trap.c @@ -129,7 +129,6 @@ kerneltrap() { uint64 sstatus = r_sstatus(); uint64 scause = r_scause(); - uint64 sepc = r_sepc(); // XXX needed only for check at end? if((sstatus & SSTATUS_SPP) == 0) panic("kerneltrap: not from supervisor mode"); @@ -141,12 +140,6 @@ kerneltrap() printf("sepc=%p stval=%p\n", r_sepc(), r_stval()); panic("kerneltrap"); } - - // XXX assert that we don't have to save/restore sstatus or sepc. - if(r_sstatus() != sstatus) - panic("kerneltrap sstatus"); - if(r_sepc() != sepc) - panic("kerneltrap sepc"); } // check if it's an external interrupt or software interrupt, @@ -166,8 +159,6 @@ devintr() if(irq == UART0_IRQ){ uartintr(); - } else { - printf("stray interrupt irq=%d\n", irq); } plic_complete(irq); @@ -175,10 +166,12 @@ devintr() } else if(scause == 0x8000000000000001){ // software interrupt from a machine-mode timer interrupt. - acquire(&tickslock); - ticks++; - wakeup(&ticks); - release(&tickslock); + if(cpuid() == 0){ + acquire(&tickslock); + ticks++; + wakeup(&ticks); + release(&tickslock); + } // acknowledge. w_sip(r_sip() & ~2); diff --git a/vm.c b/vm.c index 1d3887a..0ea6bca 100644 --- a/vm.c +++ b/vm.c @@ -190,7 +190,7 @@ uvmcreate() // for the very first process. // sz must be less than a page. void -uvminit(pagetable_t pagetable, char *src, uint sz) +uvminit(pagetable_t pagetable, uchar *src, uint sz) { char *mem; @@ -254,7 +254,6 @@ freewalk(pagetable_t pagetable) freewalk((pagetable_t)child); pagetable[i] = 0; } else if(pte & PTE_V){ - // XXX trampoline pages... panic("freewalk: leaf"); } }