forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
primitive fork and exit system calls
- Loading branch information
rtm
committed
Jun 15, 2006
1 parent
cb83c71
commit a4c03de
Showing
12 changed files
with
166 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
// kalloc.c | ||
char *kalloc(int n); | ||
void kfree(char *cp, int len); | ||
void kinit(void); | ||
|
||
// console.c | ||
void cprintf(char *fmt, ...); | ||
void panic(char *s); | ||
|
||
// proc.c | ||
struct proc; | ||
void setupsegs(struct proc *p); | ||
struct proc * newproc(struct proc *op); | ||
void setupsegs(struct proc *); | ||
struct proc * newproc(void); | ||
void swtch(void); | ||
|
||
// trap.c | ||
void tinit(void); | ||
|
||
// string.c | ||
void * memcpy(void *dst, void *src, unsigned n); | ||
void * memset(void *dst, int c, unsigned n); | ||
|
||
// syscall.c | ||
void syscall(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ struct proc{ | |
}; | ||
|
||
extern struct proc proc[]; | ||
extern struct proc *curproc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
#include "types.h" | ||
#include "defs.h" | ||
|
||
void * | ||
memcpy(void *dst, void *src, unsigned n) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "types.h" | ||
#include "param.h" | ||
#include "mmu.h" | ||
#include "proc.h" | ||
#include "defs.h" | ||
#include "x86.h" | ||
#include "traps.h" | ||
#include "syscall.h" | ||
|
||
/* | ||
* User code makes a system call with INT T_SYSCALL. | ||
* System call number in %eax. | ||
* Arguments on the stack. | ||
* | ||
* Return value? Error indication? Errno? | ||
*/ | ||
|
||
void | ||
sys_fork() | ||
{ | ||
newproc(); | ||
} | ||
|
||
void | ||
sys_exit() | ||
{ | ||
curproc->state = UNUSED; | ||
// XXX free resources. notify parent. abandon children. | ||
swtch(); | ||
} | ||
|
||
void | ||
syscall() | ||
{ | ||
int num = curproc->tf->tf_regs.reg_eax; | ||
|
||
cprintf("%x sys %d\n", curproc, num); | ||
switch(num){ | ||
case SYS_fork: | ||
sys_fork(); | ||
break; | ||
case SYS_exit: | ||
sys_exit(); | ||
break; | ||
default: | ||
cprintf("unknown sys call %d\n", num); | ||
// XXX fault | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define SYS_fork 1 | ||
#define SYS_exit 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// system defined: | ||
#define T_DIVIDE 0 // divide error | ||
#define T_DEBUG 1 // debug exception | ||
#define T_NMI 2 // non-maskable interrupt | ||
#define T_BRKPT 3 // breakpoint | ||
#define T_OFLOW 4 // overflow | ||
#define T_BOUND 5 // bounds check | ||
#define T_ILLOP 6 // illegal opcode | ||
#define T_DEVICE 7 // device not available | ||
#define T_DBLFLT 8 // double fault | ||
/* #define T_COPROC 9 */ // reserved (not generated by recent processors) | ||
#define T_TSS 10 // invalid task switch segment | ||
#define T_SEGNP 11 // segment not present | ||
#define T_STACK 12 // stack exception | ||
#define T_GPFLT 13 // genernal protection fault | ||
#define T_PGFLT 14 // page fault | ||
/* #define T_RES 15 */ // reserved | ||
#define T_FPERR 16 // floating point error | ||
#define T_ALIGN 17 // aligment check | ||
#define T_MCHK 18 // machine check | ||
#define T_SIMDERR 19 // SIMD floating point error | ||
|
||
// These are arbitrarily chosen, but with care not to overlap | ||
// processor defined exceptions or interrupt vectors. | ||
#define T_SYSCALL 48 // system call | ||
#define T_DEFAULT 500 // catchall |