From fb6b6d885f33a1dedf154d3fe873c1ee9639d1cd Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 27 Mar 2012 14:44:42 +0200 Subject: first part of stack setup --- userprog/process.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/userprog/process.c b/userprog/process.c index 8b6b86a..f5b7431 100644 --- a/userprog/process.c +++ b/userprog/process.c @@ -591,7 +591,8 @@ load_segment (struct file *file, off_t ofs, uint8_t *upage, static bool setup_stack (void **esp, const char *args) { - uint8_t *kpage = NULL; + uint8_t *kpage = NULL, stack_total; + const char *name = thread_current ()->name; kpage = palloc_get_page (PAL_USER | PAL_ZERO); if (kpage == NULL) @@ -601,6 +602,28 @@ setup_stack (void **esp, const char *args) palloc_free_page (kpage); return false; } + printf("cmd=%s\n", name); + printf("args=%s\n", args); + + *esp = PHYS_BASE; + printf("esp=%p\n", *esp); + + /* copy arguments to stack */ + *esp -= strlen(args) + 1; + memcpy(*esp, args, strlen(args) + 1); + printf("esp=%p, off=%d\n", *esp, strlen(args) + 1); + + /* copy executable name to stack */ + *esp -= strlen(name) + 1; + memcpy(*esp, name, strlen(name) + 1); + printf("esp=%p, off=%d\n", *esp, strlen(name) + 1); + + /* word align our stack so far */ + stack_total = PHYS_BASE - *esp; + printf("stack_total=%u\n", stack_total); + printf("unaligned=%p off=%d\n", *esp, PHYS_BASE - *esp); + *esp -= (4 - stack_total % sizeof(char *)); /* by thomas */ + printf("aligned=%p off=%d\n", *esp, PHYS_BASE - *esp); /* Currently we assume that 'argc = 0' */ *esp = PHYS_BASE - 12; -- cgit v1.2.3