#include "debug.h"
#include "file.h"
#include "filesys.h"
+#include "init.h"
#include "lib.h"
#include "mmu.h"
#include "malloc.h"
void (**start) (void))
{
struct Elf32_Ehdr ehdr;
- struct file *file = NULL;
+ struct file file;
+ bool file_open = false;
off_t file_ofs;
bool success = false;
int i;
as->pagedir = pagedir_create ();
- file = filesys_open (filename);
- if (file == NULL)
+ file_open = filesys_open (filename, &file);
+ if (!file_open)
LOAD_ERROR (("open failed"));
/* Read and verify executable header. */
- if (file_read (file, &ehdr, sizeof ehdr) != sizeof ehdr)
+ if (file_read (&file, &ehdr, sizeof ehdr) != sizeof ehdr)
LOAD_ERROR (("error reading executable header"));
if (memcmp (ehdr.e_ident, "\177ELF\1\1\1", 7) != 0)
LOAD_ERROR (("file is not ELF"));
{
struct Elf32_Phdr phdr;
- file_seek (file, file_ofs);
- if (file_read (file, &phdr, sizeof phdr) != sizeof phdr)
+ file_seek (&file, file_ofs);
+ if (file_read (&file, &phdr, sizeof phdr) != sizeof phdr)
LOAD_ERROR (("error reading program header"));
- printk ("%x: %08x, %08x %08x %08x %05x %05x\n",
- file_tell (file),
- phdr.p_type,
- phdr.p_offset, phdr.p_vaddr, phdr.p_paddr,
- phdr.p_filesz, phdr.p_memsz);
file_ofs += sizeof phdr;
switch (phdr.p_type)
{
printk ("unknown ELF segment type %08x\n", phdr.p_type);
break;
case PT_LOAD:
- if (!load_segment (as, file, &phdr))
+ if (!load_segment (as, &file, &phdr))
goto error;
break;
}
success = true;
error:
- if (file != NULL)
- file_close (file);
+ if (file_open)
+ file_close (&file);
if (!success)
addrspace_destroy (as);
return success;
if (as->pagedir != NULL)
pagedir_activate (as->pagedir);
+ tss->esp0 = (uint32_t) pg_round_down (as) + PGSIZE;
}