Skip to content
Snippets Groups Projects
Commit 8b8e13f2 authored by Wilke Pierre's avatar Wilke Pierre
Browse files

TP2 init

parent 6d6d03da
No related branches found
No related tags found
No related merge requests found
......@@ -146,10 +146,11 @@ UPROGS=\
$U/_rocky\
$U/_watchdog-panic\
$U/_sbrk-dealloc\
$U/_suicide\
$U/_sbrk-test\
$U/_rwtest\
$U/_naivefib\
$U/_stack-exec\
$U/_pagetable\
fs.img: mkfs/mkfs README $(UPROGS)
mkfs/mkfs fs.img README $(UPROGS)
......
......@@ -115,6 +115,7 @@ int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
void procdump(void);
void priodump(void);
void proc_vmprint(struct proc* p);
void proc_vmprint_by_pid(int pid);
// swtch.S
void swtch(struct context*, struct context*);
......@@ -190,7 +191,7 @@ void plicinithart(void);
int plic_claim(void);
void plic_complete(int);
int allocate_if_possible(pagetable_t pagetable, struct proc*, uint64 addr);
int do_allocate(pagetable_t pagetable, struct proc*, uint64 addr);
// virtio_disk.c
void virtio_disk_init(int);
......
This diff is collapsed.
......@@ -109,6 +109,7 @@ extern uint64 sys_nice(void);
extern uint64 sys_create_mutex(void);
extern uint64 sys_acquire_mutex(void);
extern uint64 sys_release_mutex(void);
extern uint64 sys_dump_pagetable(void);
static uint64 (*syscalls[])(void) = {
[SYS_fork] sys_fork,
......@@ -137,6 +138,7 @@ static uint64 (*syscalls[])(void) = {
[SYS_create_mutex] sys_create_mutex,
[SYS_acquire_mutex] sys_acquire_mutex,
[SYS_release_mutex] sys_release_mutex,
[SYS_dump_pagetable] sys_dump_pagetable,
};
void
......
......@@ -32,4 +32,6 @@
#define SYS_acquire_mutex 25
#define SYS_release_mutex 26
#define SYS_dump_pagetable 27
#endif
......@@ -100,3 +100,12 @@ sys_uptime(void)
release(&tickslock);
return xticks;
}
uint64
sys_dump_pagetable(void){
int pid;
if(argint(0, &pid) < 0)
return -1;
proc_vmprint_by_pid(pid);
return 0;
}
......@@ -36,7 +36,9 @@ trapinithart(void)
int handle_page_fault(struct proc* p, uint64 scause, uint64 stval, uint64 sepc){
uint64 addr = PGROUNDDOWN(stval);
acquire(&p->vma_lock);
int flags = allocate_if_possible(p->pagetable, p, addr);
printf("handle_page_fault pid=%d (%s), scause=%p, stval=%p, sepc=%p\n", p->pid, p->name, scause, stval, sepc);
// proc_vmprint(p);
int flags = do_allocate(p->pagetable, p, addr);
release(&p->vma_lock);
if(flags < 0){
if(flags == ENOVMA){
......
......@@ -79,7 +79,7 @@ static pte_t *
walk(pagetable_t pagetable, uint64 va, int alloc)
{
if(va >= MAXVA)
panic("walk");
return 0;
for(int level = 2; level > 0; level--) {
pte_t *pte = &pagetable[PX(level, va)];
......@@ -187,10 +187,9 @@ uvmunmap(pagetable_t pagetable, uint64 va, uint64 size, int do_free)
last = PGROUNDDOWN(va + size - 1);
for(; a <= last; a+=PGSIZE){
if((pte = walk(pagetable, a, 0)) == 0)
panic("uvmunmap: walk");
continue;
if((*pte & PTE_V) == 0){
printf("va=%p pte=%p\n", a, *pte);
panic("uvmunmap: not mapped");
continue;
}
if(PTE_FLAGS(*pte) == PTE_V)
panic("uvmunmap: not a leaf");
......@@ -320,9 +319,9 @@ uvmcopy(pagetable_t old, pagetable_t new, uint64 sz)
for(i = 0; i < sz; i += PGSIZE){
if((pte = walk(old, i, 0)) == 0)
panic("uvmcopy: pte should exist");
continue;
if((*pte & PTE_V) == 0)
panic("uvmcopy: page not present");
continue;
pa = PTE2PA(*pte);
flags = PTE_FLAGS(*pte);
if((mem = kalloc()) == 0)
......@@ -377,11 +376,11 @@ int load_from_file(char* file,
return 0;
}
int allocate_if_possible(pagetable_t pagetable, struct proc* p, uint64 addr){
int do_allocate(pagetable_t pagetable, struct proc* p, uint64 addr){
return 0;
}
int allocate_if_possible_range(pagetable_t pagetable, struct proc* p, uint64 addr, uint64 len){
int do_allocate_range(pagetable_t pagetable, struct proc* p, uint64 addr, uint64 len){
return 0;
}
......@@ -393,7 +392,7 @@ copyout(pagetable_t pagetable, uint64 dstva, char *src, uint64 len)
{
uint64 n, va0, pa0;
int f = allocate_if_possible_range(pagetable, myproc(), dstva, len);
int f = do_allocate_range(pagetable, myproc(), dstva, len);
if(f < 0) return -1;
while(len > 0){
......@@ -421,7 +420,7 @@ copyin(pagetable_t pagetable, char *dst, uint64 srcva, uint64 len)
{
uint64 n, va0, pa0;
int f = allocate_if_possible_range(pagetable, myproc(), srcva, len);
int f = do_allocate_range(pagetable, myproc(), srcva, len);
if(f < 0) return -1;
while(len > 0){
......@@ -448,13 +447,13 @@ copyin(pagetable_t pagetable, char *dst, uint64 srcva, uint64 len)
int
copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max)
{
uint64 n, va0, pa0;
uint64 n, va0, pa0;
int got_null = 0;
int num_allocated = 0;
acquire(&myproc()->vma_lock);
while(got_null == 0 && max > 0){
va0 = PGROUNDDOWN(srcva);
int f = allocate_if_possible(pagetable, myproc(), srcva);
int f = do_allocate(pagetable, myproc(), srcva);
if(f < 0) {
release(&myproc()->vma_lock);
return -1;
......
......@@ -8,7 +8,6 @@ text PT_LOAD FILEHDR PHDRS ;
data PT_LOAD ;
rodata PT_LOAD ;
bss PT_LOAD ;
sbss PT_LOAD ;
}
SECTIONS
......@@ -27,8 +26,5 @@ SECTIONS
. = ALIGN(0x1000);
.bss : { *(.bss) *(.sbss*) } :bss
. = ALIGN(0x1000);
.sbss : { *(.sbss*) } :sbss
}
......@@ -35,7 +35,7 @@ main(int argc, char** argv)
exit(1);
}
if ((n = read(fd, a, PGSIZE)) < 0) {
printf("%s: write sbrk failed\n", s);
printf("%s: read sbrk failed\n", s);
exit(1);
}
close(fd);
......@@ -43,22 +43,6 @@ main(int argc, char** argv)
a = sbrk(2*PGSIZE);
/* int i = 4069; */
/* a[i++] = 'H'; */
/* a[i++] = 'A'; */
/* a[i++] = 'H'; */
/* a[i++] = 'A'; */
/* a[i++] = '!'; */
/* a[i++] = '\0'; */
/* a[i++] = 'e'; */
/* a[i++] = 'c'; */
/* a[i++] = 'h'; */
/* a[i++] = 'o'; */
/* a[i++] = '\0'; */
/* *(char**)(a+i++) = &a[4075]; */
/* *(char**)(a+i++) = &a[4069]; */
/* char** uargv = (char**)(a+4080); */
a[PGSIZE-5] = 'H';
a[PGSIZE-4] = 'A';
a[PGSIZE-3] = 'H';
......
......@@ -38,6 +38,8 @@ int create_mutex();
int acquire_mutex(int fd);
int release_mutex(int fd);
int dump_pagetable(int pid);
// ulib.c
int stat(const char*, struct stat*);
char* strcpy(char*, const char*);
......
......@@ -1841,8 +1841,13 @@ bigargtest(char *s)
if(pid == 0){
static char *args[MAXARG];
int i;
uint sz = (USTACK_LIMIT / MAXARG + 2) * sizeof(char);
char* str = malloc(sz);
memset(str, ' ', sz - 1);
str[sz-1] = '\0';
for(i = 0; i < MAXARG-1; i++)
args[i] = "bigargs test: failed\n ";
//args[i] = "bigargs test: failed\n ";
args[i] = str;
args[MAXARG-1] = 0;
exec("echo", args);
fd = open("bigarg-ok", O_CREATE);
......@@ -1948,7 +1953,7 @@ stacktest(char *s)
pid = fork();
if(pid == 0) {
char *sp = (char *) r_sp();
sp -= PGSIZE;
sp -= USTACK_LIMIT;
// the *sp should cause a trap.
printf("%s: stacktest: read below stack %p\n", *sp);
exit(1);
......@@ -2096,6 +2101,7 @@ run(void f(char *), char *s) {
int xstatus;
printf("test %s: ", s);
fflush(1);
if((pid = fork()) < 0) {
printf("runtest: fork error\n");
exit(1);
......
......@@ -51,3 +51,4 @@ entry("nice");
entry("create_mutex");
entry("acquire_mutex");
entry("release_mutex");
entry("dump_pagetable");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment