hw4: argument passing now works
This commit is contained in:
parent
ed609d68b7
commit
8a004c4604
1 changed files with 16 additions and 23 deletions
|
@ -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);
|
||||
|
|
Reference in a new issue