exec_from_file and vfs: fix reading file
This commit is contained in:
+1
-1
@@ -11,6 +11,6 @@ bool read_sector_callback(l9660_fs *fs, void *buf, uint32_t sector);
|
|||||||
void mount_fs();
|
void mount_fs();
|
||||||
void list_files(l9660_dir *dir);
|
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
|
#endif
|
||||||
+2
-11
@@ -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;
|
size_t total_read = 0;
|
||||||
l9660_status status;
|
l9660_status status;
|
||||||
@@ -65,13 +65,6 @@ size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size)
|
|||||||
break;
|
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
|
//check for EOF
|
||||||
if (read == 0)
|
if (read == 0)
|
||||||
break;
|
break;
|
||||||
@@ -80,7 +73,5 @@ size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size)
|
|||||||
total_read += read;
|
total_read += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("total_read: %X\n", total_read);
|
|
||||||
|
|
||||||
return total_read;
|
return total_read;
|
||||||
}
|
}
|
||||||
@@ -14,30 +14,29 @@
|
|||||||
|
|
||||||
int read_file(const char* path, uint8_t** buffer, l9660_dir* dir)
|
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;
|
l9660_status err;
|
||||||
|
|
||||||
err = l9660_openat(&file, dir, path);
|
err = l9660_openat(file, dir, path);
|
||||||
if (err != L9660_OK)
|
if (err != L9660_OK)
|
||||||
{
|
{
|
||||||
debug_log("read_file: err: 0x%X\n", err);
|
debug_log("read_file: err: 0x%X\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
l9660_seek(&file, L9660_SEEK_END, 0);
|
l9660_seek(file, L9660_SEEK_END, 0);
|
||||||
uint32_t file_size = l9660_tell(&file);
|
uint32_t file_size = l9660_tell(file);
|
||||||
debug_log("file_size: %X\n", file_size);
|
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);
|
*buffer = (uint8_t*)malloc(file_size);
|
||||||
debug_log("eeee\n");
|
debug_log("eeee\n");
|
||||||
|
|
||||||
size_t read;
|
size_t read;
|
||||||
|
|
||||||
uint32_t final_size = (uint32_t)*buffer + file_size;
|
read = vfs_read_file(file, *buffer);
|
||||||
|
free(file);
|
||||||
read = vfs_read_file(&file, *buffer, final_size);
|
|
||||||
debug_log("bytes read: 0x%X\n", read);
|
debug_log("bytes read: 0x%X\n", read);
|
||||||
|
|
||||||
return 0;
|
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)
|
void exec_from_file(const char* filename, const char* dirname)
|
||||||
{
|
{
|
||||||
asm volatile("cli");
|
asm volatile("cli");
|
||||||
int err, cnt;
|
int err;
|
||||||
//err = fat_mount(&ops1, 0, &g_fat, "ebalo");
|
|
||||||
|
|
||||||
uint8_t* file;
|
uint8_t* file;
|
||||||
//dir_t dir;
|
|
||||||
l9660_dir dir;
|
l9660_dir dir;
|
||||||
l9660_dir root_dir;
|
l9660_dir root_dir;
|
||||||
l9660_status status;
|
l9660_status status;
|
||||||
@@ -61,17 +58,23 @@ void exec_from_file(const char* filename, const char* dirname)
|
|||||||
status = l9660_opendirat(&dir, &root_dir, dirname);
|
status = l9660_opendirat(&dir, &root_dir, dirname);
|
||||||
debug_log("l9660_opendirat status: 0x%X\n", status);
|
debug_log("l9660_opendirat status: 0x%X\n", status);
|
||||||
|
|
||||||
list_files(&dir);
|
//list_files(&dir);
|
||||||
|
|
||||||
uint32_t bss_start, bss_end;
|
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("result: %X\n", result);
|
||||||
//debug_log("buffer: %s\n", file);
|
//debug_log("buffer: %s\n", file);
|
||||||
|
|
||||||
Elf32_Ehdr *elf_ehdr = (Elf32_Ehdr*)file;
|
Elf32_Ehdr *elf_ehdr = (Elf32_Ehdr*)file;
|
||||||
int program_header_table_entry_count = elf_ehdr->e_phnum;
|
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("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);
|
//debug_log("PHNUM: %X\n", program_header_table_entry_count);
|
||||||
|
|||||||
Reference in New Issue
Block a user