From 8a004c46049a15e7fc6406d8c0b4ffceb26268b0 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Tue, 28 Apr 2020 14:34:43 +0200 Subject: [PATCH] hw4: argument passing now works --- pintos-env/pintos/userprog/process.c | 39 ++++++++++++---------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/pintos-env/pintos/userprog/process.c b/pintos-env/pintos/userprog/process.c index 9b14740..c9ebce2 100755 --- a/pintos-env/pintos/userprog/process.c +++ b/pintos-env/pintos/userprog/process.c @@ -78,37 +78,37 @@ start_process (void *file_name_) token = strtok_r(NULL, " ", &save_ptr)) { struct arg* it = malloc(sizeof(struct arg)); it->data = token; - printf("list_elem pushed: %s\n", token); list_push_back(&arg_list, it); } + char* program_name = list_entry(list_front(&arg_list), struct arg, elem)->data; + + /* Initialize interrupt frame and load executable. */ + memset (&if_, 0, sizeof if_); + if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG; + if_.cs = SEL_UCSEG; + if_.eflags = FLAG_IF | FLAG_MBS; + success = load (program_name, &if_.eip, &if_.esp); + list_reverse(&arg_list); - printf("ciao mamma!\n"); - struct list_elem* e; - for (e = list_begin(&arg_list); e != list_end(&arg_list); e = list_next(e)) { - struct arg* i = list_entry(e, struct arg, elem); - printf("list_elem: %s\n", i->data); - } - // put argv[i][...] on stack and keep track of addresses - char* program_name; + struct list_elem* e; for (e = list_begin(&arg_list); e != list_end(&arg_list); e = list_next(e)) { struct arg* i = list_entry(e, struct arg, elem); size_t bytes = strlen(i->data) + 1; if_.esp -= bytes; i->addr = if_.esp; - memcpy(&(if_.esp), i->data, bytes); + memcpy(if_.esp, i->data, bytes); } // put terminator of argv[] (argv[4] in example) size_t bytes = sizeof(void*); // size of pointers on stack if_.esp -= bytes; - printf("bytes: %d %X\n", bytes, if_.esp); { uint32_t write[1] = {0}; - memcpy(&(if_.esp), write, sizeof(uint32_t)); + memcpy(if_.esp, write, sizeof(uint32_t)); } // put addresses of argv[i] on stack @@ -117,7 +117,7 @@ start_process (void *file_name_) if_.esp -= bytes; { uint32_t write[1] = {i->addr}; - memcpy(&(if_.esp), write, sizeof(uint32_t)); + memcpy(if_.esp, write, sizeof(uint32_t)); } e = list_next(e); @@ -127,28 +127,21 @@ start_process (void *file_name_) if_.esp -= bytes; { uint32_t write[1] = {if_.esp + bytes}; - memcpy(&(if_.esp), write, sizeof(uint32_t)); + memcpy(if_.esp, write, sizeof(uint32_t)); } //put argc if_.esp -= bytes; { uint32_t write[1] = {list_size(&arg_list) - 1}; - memcpy(&(if_.esp), write, sizeof(uint32_t)); + memcpy(if_.esp, write, sizeof(uint32_t)); } //put return address if_.esp -= bytes; { uint32_t write[1] = {0}; - memcpy(&(if_.esp), write, sizeof(uint32_t)); + memcpy(if_.esp, write, sizeof(uint32_t)); } - - /* Initialize interrupt frame and load executable. */ - memset (&if_, 0, sizeof if_); - if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG; - if_.cs = SEL_UCSEG; - if_.eflags = FLAG_IF | FLAG_MBS; - success = load (program_name, &if_.eip, &if_.esp); /* If load failed, quit. */ palloc_free_page (program_name);