diff --git a/include/vfs.h b/include/vfs.h index ada950d..41c3745 100644 --- a/include/vfs.h +++ b/include/vfs.h @@ -11,6 +11,6 @@ bool read_sector_callback(l9660_fs *fs, void *buf, uint32_t sector); void mount_fs(); void list_files(l9660_dir *dir); -size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size); +size_t vfs_read_file(l9660_file *file, uint8_t* buffer); #endif \ No newline at end of file diff --git a/src/fs/vfs.c b/src/fs/vfs.c index 8aa646c..4042c9e 100644 --- a/src/fs/vfs.c +++ b/src/fs/vfs.c @@ -49,8 +49,8 @@ void list_files(l9660_dir *dir) } } -//TODO: fix invalid opcode exception that somehow happens when the memcpy is called with buffer+total_read address being 0xE0008CA0 -size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size) + +size_t vfs_read_file(l9660_file *file, uint8_t* buffer) { size_t total_read = 0; l9660_status status; @@ -65,13 +65,6 @@ size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size) break; } - printf("total_read: %X status: %X buffer+total_read: %X/%X read: %X\n", total_read, status, buffer + total_read, final_size, read); - if(buffer+total_read == 0xE0008CA0) - { - printf("ERROR ERROR\n"); - printf("get_physaddr: %X", get_physaddr((void*)0xE0008CA0)); - } - //check for EOF if (read == 0) break; @@ -80,7 +73,5 @@ size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size) total_read += read; } - printf("total_read: %X\n", total_read); - return total_read; } \ No newline at end of file diff --git a/src/tasking/exec_from_file.c b/src/tasking/exec_from_file.c index 1c9a32d..b9b0b44 100644 --- a/src/tasking/exec_from_file.c +++ b/src/tasking/exec_from_file.c @@ -14,30 +14,29 @@ int read_file(const char* path, uint8_t** buffer, l9660_dir* dir) { - l9660_file file; + l9660_file* file = (l9660_file*)malloc(sizeof(l9660_file)); l9660_status err; - err = l9660_openat(&file, dir, path); + err = l9660_openat(file, dir, path); if (err != L9660_OK) { debug_log("read_file: err: 0x%X\n", err); return err; } - l9660_seek(&file, L9660_SEEK_END, 0); - uint32_t file_size = l9660_tell(&file); + l9660_seek(file, L9660_SEEK_END, 0); + uint32_t file_size = l9660_tell(file); debug_log("file_size: %X\n", file_size); - l9660_seek(&file, L9660_SEEK_SET, 0); + l9660_seek(file, L9660_SEEK_SET, 0); *buffer = (uint8_t*)malloc(file_size); debug_log("eeee\n"); size_t read; - uint32_t final_size = (uint32_t)*buffer + file_size; - - read = vfs_read_file(&file, *buffer, final_size); + read = vfs_read_file(file, *buffer); + free(file); debug_log("bytes read: 0x%X\n", read); return 0; @@ -46,11 +45,9 @@ int read_file(const char* path, uint8_t** buffer, l9660_dir* dir) void exec_from_file(const char* filename, const char* dirname) { asm volatile("cli"); - int err, cnt; - //err = fat_mount(&ops1, 0, &g_fat, "ebalo"); + int err; uint8_t* file; - //dir_t dir; l9660_dir dir; l9660_dir root_dir; l9660_status status; @@ -61,17 +58,23 @@ void exec_from_file(const char* filename, const char* dirname) status = l9660_opendirat(&dir, &root_dir, dirname); debug_log("l9660_opendirat status: 0x%X\n", status); - list_files(&dir); + //list_files(&dir); uint32_t bss_start, bss_end; - int result = read_file(filename, &file, &dir); + err = read_file(filename, &file, &dir); + + if(err != 0) + { + debug_log("read_file failed!\n"); + return; + } //debug_log("result: %X\n", result); //debug_log("buffer: %s\n", file); Elf32_Ehdr *elf_ehdr = (Elf32_Ehdr*)file; int program_header_table_entry_count = elf_ehdr->e_phnum; - int program_header_table_entry_size = elf_ehdr->e_phentsize; + //int program_header_table_entry_size = elf_ehdr->e_phentsize; //debug_log("magic: %X, type: %X, entry: 0x%X\n", elf_ehdr->e_ident, elf_ehdr->e_type, elf_ehdr->e_entry); //debug_log("PHNUM: %X\n", program_header_table_entry_count);