summaryrefslogtreecommitdiffstats
path: root/userprog
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-27 14:44:42 +0200
committermanuel <manuel@mausz.at>2012-03-27 14:44:42 +0200
commitfb6b6d885f33a1dedf154d3fe873c1ee9639d1cd (patch)
tree4da30edf7d533e25b8719ce49f7843e3cb08e6d4 /userprog
parent7fb872391351d87fb2a1b95cbfca320edc1f7bdd (diff)
downloadprogos-fb6b6d885f33a1dedf154d3fe873c1ee9639d1cd.tar.gz
progos-fb6b6d885f33a1dedf154d3fe873c1ee9639d1cd.tar.bz2
progos-fb6b6d885f33a1dedf154d3fe873c1ee9639d1cd.zip
first part of stack setup
Diffstat (limited to 'userprog')
-rw-r--r--userprog/process.c25
1 files changed, 24 insertions, 1 deletions
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,
591static bool 591static bool
592setup_stack (void **esp, const char *args) 592setup_stack (void **esp, const char *args)
593{ 593{
594 uint8_t *kpage = NULL; 594 uint8_t *kpage = NULL, stack_total;
595 const char *name = thread_current ()->name;
595 596
596 kpage = palloc_get_page (PAL_USER | PAL_ZERO); 597 kpage = palloc_get_page (PAL_USER | PAL_ZERO);
597 if (kpage == NULL) 598 if (kpage == NULL)
@@ -601,6 +602,28 @@ setup_stack (void **esp, const char *args)
601 palloc_free_page (kpage); 602 palloc_free_page (kpage);
602 return false; 603 return false;
603 } 604 }
605 printf("cmd=%s\n", name);
606 printf("args=%s\n", args);
607
608 *esp = PHYS_BASE;
609 printf("esp=%p\n", *esp);
610
611 /* copy arguments to stack */
612 *esp -= strlen(args) + 1;
613 memcpy(*esp, args, strlen(args) + 1);
614 printf("esp=%p, off=%d\n", *esp, strlen(args) + 1);
615
616 /* copy executable name to stack */
617 *esp -= strlen(name) + 1;
618 memcpy(*esp, name, strlen(name) + 1);
619 printf("esp=%p, off=%d\n", *esp, strlen(name) + 1);
620
621 /* word align our stack so far */
622 stack_total = PHYS_BASE - *esp;
623 printf("stack_total=%u\n", stack_total);
624 printf("unaligned=%p off=%d\n", *esp, PHYS_BASE - *esp);
625 *esp -= (4 - stack_total % sizeof(char *)); /* by thomas */
626 printf("aligned=%p off=%d\n", *esp, PHYS_BASE - *esp);
604 627
605 /* Currently we assume that 'argc = 0' */ 628 /* Currently we assume that 'argc = 0' */
606 *esp = PHYS_BASE - 12; 629 *esp = PHYS_BASE - 12;