Compare commits

..

No commits in common. "ced7c79bd81372f01354dfd36d913b00dee6520c" and "3e639fe25d0a90e58a36797d7b5fda16b4865145" have entirely different histories.

12 changed files with 20 additions and 73 deletions

View file

@ -135,7 +135,6 @@ UPROGS=\
$U/_wc\ $U/_wc\
$U/_zombie\ $U/_zombie\
$U/_clear\ $U/_clear\
$U/_halt\
fs.img: mkfs/mkfs README.md $(UPROGS) fs.img: mkfs/mkfs README.md $(UPROGS)
mkfs/mkfs fs.img README.md $(UPROGS) mkfs/mkfs fs.img README.md $(UPROGS)

View file

@ -64,34 +64,10 @@ void ramdiskinit(void);
void ramdiskintr(void); void ramdiskintr(void);
void ramdiskrw(struct buf *); void ramdiskrw(struct buf *);
/** // kalloc.c
* 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
*/
void *kalloc(void); void *kalloc(void);
void kfree(void *);
/** void kinit(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);
// log.c // log.c
void initlog(int, struct superblock *); void initlog(int, struct superblock *);

View file

@ -3,23 +3,21 @@
// and pipe buffers. Allocates whole 4096-byte pages. // and pipe buffers. Allocates whole 4096-byte pages.
#include "types.h" #include "types.h"
#include "param.h"
#include "memlayout.h" #include "memlayout.h"
#include "spinlock.h" #include "spinlock.h"
#include "riscv.h" #include "riscv.h"
#include "defs.h" #include "defs.h"
/** Free list of physical pages. */
void freerange(void *pa_start, void *pa_end); void freerange(void *pa_start, void *pa_end);
/** first address after kernel. defined by kernel.ld. */ extern char end[]; // first address after kernel.
extern char end[]; // defined by kernel.ld.
/** A run is a node in the free list. */
struct run { struct run {
struct run *next; struct run *next;
}; };
/** Kernel memory allocator. */
struct { struct {
struct spinlock lock; struct spinlock lock;
struct run *freelist; struct run *freelist;
@ -41,6 +39,10 @@ freerange(void *pa_start, void *pa_end)
kfree(p); 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 void
kfree(void *pa) kfree(void *pa)
{ {
@ -60,6 +62,9 @@ kfree(void *pa)
release(&kmem.lock); 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 * void *
kalloc(void) kalloc(void)
{ {

View file

@ -15,25 +15,12 @@ SECTIONS
* that reference the functions in your object file. * that reference the functions in your object file.
*/ */
.text : { .text : {
/* Match any section that starts with .text. */
*(.text .text.*) *(.text .text.*)
/* Align the next section to a 4KB (page) boundary. */
. = ALIGN(0x1000); . = ALIGN(0x1000);
/* Put the trampoline code here. */
_trampoline = .; _trampoline = .;
/* Match any section that starts with .trampsec. */
*(trampsec) *(trampsec)
/* Align the next section to a 4KB (page) boundary. */
. = ALIGN(0x1000); . = ALIGN(0x1000);
/* Assert that the trampoline code is exactly 4KB (page) in size. */
ASSERT(. - _trampoline == 0x1000, "error: trampoline larger than one page"); ASSERT(. - _trampoline == 0x1000, "error: trampoline larger than one page");
/* Define symbol etext to be the current location. */
PROVIDE(etext = .); PROVIDE(etext = .);
} }
@ -42,7 +29,6 @@ SECTIONS
* It is not unusual to find this data interleaved with the text section. * It is not unusual to find this data interleaved with the text section.
*/ */
.rodata : { .rodata : {
/* Align on quadword boundary. */
. = ALIGN(16); . = ALIGN(16);
*(.srodata .srodata.*) /* do not need to distinguish this from .rodata */ *(.srodata .srodata.*) /* do not need to distinguish this from .rodata */
. = ALIGN(16); . = ALIGN(16);
@ -73,6 +59,6 @@ SECTIONS
*(.bss .bss.*) *(.bss .bss.*)
} }
/* Define symbol end as current location, note that this is not aligned, see vm.c */ /* PROVIDE, see vm.c */
PROVIDE(end = .); PROVIDE(end = .);
} }

View file

@ -650,8 +650,9 @@ either_copyin(void *dst, int user_src, u64 src, u64 len)
void void
procdump(void) procdump(void)
{ {
static char *states[] = { [UNUSED] = "unused", [USED] = "used", [SLEEPING] = "sleep ", static char *states[] = {
[RUNNABLE] = "runble", [RUNNING] = "run ", [ZOMBIE] = "zombie" }; [UNUSED] "unused", [USED] "used", [SLEEPING] "sleep ", [RUNNABLE] "runble", [RUNNING] "run ", [ZOMBIE] "zombie"
};
struct proc *p; struct proc *p;
char *state; char *state;

View file

@ -102,7 +102,6 @@ extern u64 sys_link(void);
extern u64 sys_mkdir(void); extern u64 sys_mkdir(void);
extern u64 sys_close(void); extern u64 sys_close(void);
extern u64 sys_trace(void); extern u64 sys_trace(void);
extern u64 sys_halt(void);
// An array mapping syscall numbers from syscall.h // An array mapping syscall numbers from syscall.h
// to the function that handles the system call. // 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_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_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_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 void

View file

@ -23,4 +23,3 @@
#define SYS_mkdir 20 #define SYS_mkdir 20
#define SYS_close 21 #define SYS_close 21
#define SYS_trace 22 #define SYS_trace 22
#define SYS_halt 23

View file

@ -96,9 +96,3 @@ sys_trace(void)
/* TODO: Implement sys_trace */ /* TODO: Implement sys_trace */
return 0; return 0;
} }
void
sys_halt(void)
{
/* TODO: Implement sys_halt */
}

View file

@ -1,4 +1,5 @@
#include "types.h" #include "types.h"
#include "param.h"
#include "memlayout.h" #include "memlayout.h"
#include "riscv.h" #include "riscv.h"
#include "spinlock.h" #include "spinlock.h"

View file

@ -1,9 +0,0 @@
#include "user.h"
/** Stops the machine */
int
main(int argc, char *argv[])
{
halt();
return 0;
}

View file

@ -74,9 +74,6 @@ int uptime(void);
/** trace */ /** trace */
int trace(int); int trace(int);
/** halt */
void halt(void);
/** /**
* Library functions (ulib.c) * Library functions (ulib.c)
*/ */

View file

@ -14,7 +14,7 @@ sub entry {
print " ecall\n"; print " ecall\n";
print " ret\n"; print " ret\n";
} }
entry("fork"); entry("fork");
entry("exit"); entry("exit");
entry("wait"); entry("wait");
@ -37,4 +37,3 @@ entry("sbrk");
entry("sleep"); entry("sleep");
entry("uptime"); entry("uptime");
entry("trace"); entry("trace");
entry("halt");