summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--defs.h2
-rw-r--r--kalloc.c4
-rw-r--r--syscall.c2
-rw-r--r--syscall.h1
-rw-r--r--sysproc.c16
-rw-r--r--trap.c2
-rw-r--r--usertests.c24
-rw-r--r--usys.S1
-rw-r--r--vm.c4
9 files changed, 47 insertions, 9 deletions
diff --git a/defs.h b/defs.h
index a051522..0197e70 100644
--- a/defs.h
+++ b/defs.h
@@ -142,7 +142,7 @@ void timerinit(void);
// trap.c
void idtinit(void);
-extern int ticks;
+extern uint ticks;
void tvinit(void);
extern struct spinlock tickslock;
diff --git a/kalloc.c b/kalloc.c
index 7695006..ca87018 100644
--- a/kalloc.c
+++ b/kalloc.c
@@ -23,14 +23,10 @@ struct {
int nfreemem;
// Initialize free list of physical pages.
-// This code cheats by just considering one megabyte of
-// pages after end. Real systems would determine the
-// amount of memory available in the system and use it all.
void
kinit(char *p, uint len)
{
initlock(&kmem.lock, "kmem");
- cprintf("end 0x%x free = %d(0x%x)\n", p, len);
nfreemem = 0;
kfree(p, len);
}
diff --git a/syscall.c b/syscall.c
index ce79dbd..9296cff 100644
--- a/syscall.c
+++ b/syscall.c
@@ -100,6 +100,7 @@ extern int sys_sleep(void);
extern int sys_unlink(void);
extern int sys_wait(void);
extern int sys_write(void);
+extern int sys_uptime(void);
static int (*syscalls[])(void) = {
[SYS_chdir] sys_chdir,
@@ -122,6 +123,7 @@ static int (*syscalls[])(void) = {
[SYS_unlink] sys_unlink,
[SYS_wait] sys_wait,
[SYS_write] sys_write,
+[SYS_uptime] sys_uptime,
};
void
diff --git a/syscall.h b/syscall.h
index f4b7807..3a0fbca 100644
--- a/syscall.h
+++ b/syscall.h
@@ -19,3 +19,4 @@
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_sleep 20
+#define SYS_uptime 21
diff --git a/sysproc.c b/sysproc.c
index 11770ff..efaa372 100644
--- a/sysproc.c
+++ b/sysproc.c
@@ -57,7 +57,8 @@ sys_sbrk(void)
int
sys_sleep(void)
{
- int n, ticks0;
+ int n;
+ uint ticks0;
if(argint(0, &n) < 0)
return -1;
@@ -73,3 +74,16 @@ sys_sleep(void)
release(&tickslock);
return 0;
}
+
+// return how many clock tick interrupts have occurred
+// since boot.
+int
+sys_uptime(void)
+{
+ uint xticks;
+
+ acquire(&tickslock);
+ xticks = ticks;
+ release(&tickslock);
+ return xticks;
+}
diff --git a/trap.c b/trap.c
index 1f35708..daee22f 100644
--- a/trap.c
+++ b/trap.c
@@ -11,7 +11,7 @@
struct gatedesc idt[256];
extern uint vectors[]; // in vectors.S: array of 256 entry pointers
struct spinlock tickslock;
-int ticks;
+uint ticks;
void
tvinit(void)
diff --git a/usertests.c b/usertests.c
index 9ad6448..670a4a8 100644
--- a/usertests.c
+++ b/usertests.c
@@ -322,8 +322,9 @@ void
mem(void)
{
void *m1, *m2;
- int pid;
+ int pid, ppid;
+ ppid = getpid();
if((pid = fork()) == 0){
m1 = 0;
while((m2 = malloc(10001)) != 0) {
@@ -338,6 +339,7 @@ mem(void)
m1 = malloc(1024*20);
if(m1 == 0) {
printf(1, "couldn't allocate mem?!!\n");
+ kill(ppid);
exit();
}
free(m1);
@@ -1233,6 +1235,7 @@ void
sbrktest(void)
{
int pid;
+ char *oldbrk = sbrk(0);
printf(stdout, "sbrk test\n");
@@ -1313,6 +1316,25 @@ sbrktest(void)
exit();
}
+ // can we read the kernel's memory?
+ for(a = (char*)(640*1024); a < (char *)2000000; a += 50000){
+ int ppid = getpid();
+ int pid = fork();
+ if(pid < 0){
+ printf(stdout, "fork failed\n");
+ exit();
+ }
+ if(pid == 0){
+ printf(stdout, "oops could read %x = %x\n", a, *a);
+ kill(ppid);
+ exit();
+ }
+ wait();
+ }
+
+ if(sbrk(0) > oldbrk)
+ sbrk(-(sbrk(0) - oldbrk));
+
printf(stdout, "sbrk test OK\n");
}
diff --git a/usys.S b/usys.S
index 2291b02..8bfd8a1 100644
--- a/usys.S
+++ b/usys.S
@@ -28,3 +28,4 @@ SYSCALL(dup)
SYSCALL(getpid)
SYSCALL(sbrk)
SYSCALL(sleep)
+SYSCALL(uptime)
diff --git a/vm.c b/vm.c
index 8755b82..98ac108 100644
--- a/vm.c
+++ b/vm.c
@@ -29,7 +29,7 @@
// (both in physical memory and in the kernel's virtual address
// space).
-#define PHYSTOP 0x300000
+#define PHYSTOP 0x1000000
#define USERTOP 0xA0000
static uint kerntext; // Linker starts kernel at 1MB
@@ -336,6 +336,8 @@ copyuvm(pde_t *pgdir, uint sz)
// Gather information about physical memory layout.
// Called once during boot.
+// Really should find out how much physical memory
+// there is rather than assuming PHYSTOP.
void
pminit(void)
{