diff --git a/Makefile b/Makefile index 1363245..f8cc863 100644 --- a/Makefile +++ b/Makefile @@ -135,7 +135,6 @@ UPROGS=\ $U/_wc\ $U/_zombie\ $U/_clear\ - $U/_halt\ fs.img: mkfs/mkfs README.md $(UPROGS) mkfs/mkfs fs.img README.md $(UPROGS) diff --git a/kernel/defs.h b/kernel/defs.h index ecbcf26..a89c445 100644 --- a/kernel/defs.h +++ b/kernel/defs.h @@ -64,34 +64,10 @@ void ramdiskinit(void); void ramdiskintr(void); void ramdiskrw(struct buf *); -/** - * Kernel memory allocator - * - * Allocate one 4096-byte page of physical memory. - * Returns a pointer that the kernel can use. - * Returns 0 if the memory cannot be allocated. - * See: kalloc.c - */ +// kalloc.c void *kalloc(void); - -/** - * Kernel memory allocator - * - * Free the page of physical memory pointed at by pa, - * which normally should have been returned by a - * call to kalloc(). (The exception is when - * initializing the allocator; see kinit above.) - * See: kalloc.c - */ -void kfree(void *); - -/** - * Initialize kernel memory allocator - * - * Called by main() on the way to the kernel's main loop. - * See: kalloc.c - */ -void kinit(void); +void kfree(void *); +void kinit(void); // log.c void initlog(int, struct superblock *); diff --git a/kernel/kalloc.c b/kernel/kalloc.c index b880933..a3de3d5 100644 --- a/kernel/kalloc.c +++ b/kernel/kalloc.c @@ -3,23 +3,21 @@ // and pipe buffers. Allocates whole 4096-byte pages. #include "types.h" +#include "param.h" #include "memlayout.h" #include "spinlock.h" #include "riscv.h" #include "defs.h" -/** Free list of physical pages. */ void freerange(void *pa_start, void *pa_end); -/** first address after kernel. defined by kernel.ld. */ -extern char end[]; +extern char end[]; // first address after kernel. + // defined by kernel.ld. -/** A run is a node in the free list. */ struct run { struct run *next; }; -/** Kernel memory allocator. */ struct { struct spinlock lock; struct run *freelist; @@ -41,6 +39,10 @@ freerange(void *pa_start, void *pa_end) kfree(p); } +// Free the page of physical memory pointed at by pa, +// which normally should have been returned by a +// call to kalloc(). (The exception is when +// initializing the allocator; see kinit above.) void kfree(void *pa) { @@ -60,6 +62,9 @@ kfree(void *pa) release(&kmem.lock); } +// Allocate one 4096-byte page of physical memory. +// Returns a pointer that the kernel can use. +// Returns 0 if the memory cannot be allocated. void * kalloc(void) { diff --git a/kernel/kernel.ld b/kernel/kernel.ld index 2844edf..7ab21d8 100644 --- a/kernel/kernel.ld +++ b/kernel/kernel.ld @@ -15,25 +15,12 @@ SECTIONS * that reference the functions in your object file. */ .text : { - /* Match any section that starts with .text. */ *(.text .text.*) - - /* Align the next section to a 4KB (page) boundary. */ . = ALIGN(0x1000); - - /* Put the trampoline code here. */ _trampoline = .; - - /* Match any section that starts with .trampsec. */ *(trampsec) - - /* Align the next section to a 4KB (page) boundary. */ . = ALIGN(0x1000); - - /* Assert that the trampoline code is exactly 4KB (page) in size. */ ASSERT(. - _trampoline == 0x1000, "error: trampoline larger than one page"); - - /* Define symbol etext to be the current location. */ PROVIDE(etext = .); } @@ -42,7 +29,6 @@ SECTIONS * It is not unusual to find this data interleaved with the text section. */ .rodata : { - /* Align on quadword boundary. */ . = ALIGN(16); *(.srodata .srodata.*) /* do not need to distinguish this from .rodata */ . = ALIGN(16); @@ -73,6 +59,6 @@ SECTIONS *(.bss .bss.*) } - /* Define symbol end as current location, note that this is not aligned, see vm.c */ + /* PROVIDE, see vm.c */ PROVIDE(end = .); } diff --git a/kernel/proc.c b/kernel/proc.c index ccccf79..58a3160 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -650,8 +650,9 @@ either_copyin(void *dst, int user_src, u64 src, u64 len) void procdump(void) { - static char *states[] = { [UNUSED] = "unused", [USED] = "used", [SLEEPING] = "sleep ", - [RUNNABLE] = "runble", [RUNNING] = "run ", [ZOMBIE] = "zombie" }; + static char *states[] = { + [UNUSED] "unused", [USED] "used", [SLEEPING] "sleep ", [RUNNABLE] "runble", [RUNNING] "run ", [ZOMBIE] "zombie" + }; struct proc *p; char *state; diff --git a/kernel/syscall.c b/kernel/syscall.c index a027276..075fb36 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -102,7 +102,6 @@ extern u64 sys_link(void); extern u64 sys_mkdir(void); extern u64 sys_close(void); extern u64 sys_trace(void); -extern u64 sys_halt(void); // An array mapping syscall numbers from syscall.h // to the function that handles the system call. @@ -112,7 +111,7 @@ static u64 (*syscalls[])(void) = { [SYS_chdir] = sys_chdir, [SYS_dup] = sys_dup, [SYS_getpid] = sys_getpid, [SYS_sbrk] = sys_sbrk, [SYS_sleep] = sys_sleep, [SYS_uptime] = sys_uptime, [SYS_open] = sys_open, [SYS_write] = sys_write, [SYS_mknod] = sys_mknod, [SYS_unlink] = sys_unlink, [SYS_link] = sys_link, [SYS_mkdir] = sys_mkdir, - [SYS_close] = sys_close, [SYS_trace] = sys_trace, [SYS_halt] = sys_halt, + [SYS_close] = sys_close, [SYS_trace] = sys_trace, }; void diff --git a/kernel/syscall.h b/kernel/syscall.h index 0162584..dfc9645 100644 --- a/kernel/syscall.h +++ b/kernel/syscall.h @@ -23,4 +23,3 @@ #define SYS_mkdir 20 #define SYS_close 21 #define SYS_trace 22 -#define SYS_halt 23 diff --git a/kernel/sysproc.c b/kernel/sysproc.c index ba0aeb9..5645c72 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -96,9 +96,3 @@ sys_trace(void) /* TODO: Implement sys_trace */ return 0; } - -void -sys_halt(void) -{ - /* TODO: Implement sys_halt */ -} diff --git a/kernel/trap.c b/kernel/trap.c index 3db4558..359fe39 100644 --- a/kernel/trap.c +++ b/kernel/trap.c @@ -1,4 +1,5 @@ #include "types.h" +#include "param.h" #include "memlayout.h" #include "riscv.h" #include "spinlock.h" diff --git a/user/halt.c b/user/halt.c deleted file mode 100644 index ab73dd3..0000000 --- a/user/halt.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "user.h" - -/** Stops the machine */ -int -main(int argc, char *argv[]) -{ - halt(); - return 0; -} diff --git a/user/user.h b/user/user.h index ed10ca8..1e56f3d 100644 --- a/user/user.h +++ b/user/user.h @@ -74,9 +74,6 @@ int uptime(void); /** trace */ int trace(int); -/** halt */ -void halt(void); - /** * Library functions (ulib.c) */ diff --git a/user/usys.pl b/user/usys.pl index cdaec02..9c97b05 100755 --- a/user/usys.pl +++ b/user/usys.pl @@ -14,7 +14,7 @@ sub entry { print " ecall\n"; print " ret\n"; } - + entry("fork"); entry("exit"); entry("wait"); @@ -37,4 +37,3 @@ entry("sbrk"); entry("sleep"); entry("uptime"); entry("trace"); -entry("halt");