diff options
-rwxr-xr-x | run | 2 | ||||
-rw-r--r-- | src/kernel/fs/elf.c | 4 | ||||
-rw-r--r-- | src/kernel/fs/elf.h | 2 | ||||
-rw-r--r-- | src/kernel/fs/load.c | 38 | ||||
-rw-r--r-- | src/kernel/fs/load.h | 19 | ||||
-rw-r--r-- | src/kernel/fs/vfs.c | 47 | ||||
-rw-r--r-- | src/kernel/fs/vfs.h | 65 | ||||
-rw-r--r-- | src/kernel/kernel.c | 10 | ||||
-rw-r--r-- | src/userspace/linker.ld | 19 |
9 files changed, 84 insertions, 122 deletions
@@ -109,7 +109,7 @@ make_build() { compile_with_flags -O2 -c ./"${line}" -I ./src/userspace -o ./build/userspace/"${stripped}" done <./build/tmp rm ./build/tmp - compile_with_flags -emain -O2 ./build/userspace/*.o -I ./src/userspace -o ./build/user.bin + compile_with_flags -emain -O2 ./build/userspace/*.o -T ./src/userspace/linker.ld -I ./src/userspace -o ./build/user.bin # Create ISO mkdir -p ./iso/boot/ diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c index 2f1b463..62c4e8d 100644 --- a/src/kernel/fs/elf.c +++ b/src/kernel/fs/elf.c @@ -40,13 +40,13 @@ uint32_t load_elf(char *elf_data) v_begin = p_entry->vaddr; v_end = p_entry->vaddr + p_entry->memsz; if (v_begin < USER_OFFSET) { - printf("INFO: load_elf(): can't load executable below %x\n", + warn("load_elf(): can't load executable below %x\n", USER_OFFSET); return 0; } if (v_end > USER_STACK) { - printf("INFO: load_elf(): can't load executable above %x\n", + warn("load_elf(): can't load executable above %x\n", USER_STACK); return 0; } diff --git a/src/kernel/fs/elf.h b/src/kernel/fs/elf.h index ee89000..7e599b8 100644 --- a/src/kernel/fs/elf.h +++ b/src/kernel/fs/elf.h @@ -51,4 +51,4 @@ typedef struct { int is_elf(char *data); uint32_t load_elf(char *elf_data); -#endif +#endif
\ No newline at end of file diff --git a/src/kernel/fs/load.c b/src/kernel/fs/load.c new file mode 100644 index 0000000..c7bbb3d --- /dev/null +++ b/src/kernel/fs/load.c @@ -0,0 +1,38 @@ +#include <kernel/fs/load.h> +#include <kernel/fs/marfs/marfs.h> +#include <kernel/fs/ata_pio.h> +#include <kernel/fs/atapi_pio.h> +#include <kernel/system.h> +#include <kernel/fs/iso9660/iso9660.h> +#include <kernel/memory/alloc.h> +#include <kernel/lib/stdio.h> +#include <kernel/lib/lib.h> + +void load_binaries() +{ + userspace = (uint32_t)kmalloc(10000); + font = (struct font *)kmalloc(100000); // High quality shit + + uint8_t boot_drive_id = (uint8_t)(*((uint8_t *)0x9000)); + if (boot_drive_id != 0xE0) { + struct ata_interface *primary_master = new_ata(1, 0x1F0); + marfs_init(primary_master); + marfs_read_whole_file(4, (uint8_t *)userspace); + marfs_read_whole_file(5, (uint8_t *)font); + } else { + char *font_p[] = { "FONT.BIN" }; + struct iso9660_entity *font_e = ISO9660_get(font_p, 1); + if (!font_e) + panic("Font not found!"); + ATAPI_granular_read(1 + (font_e->length / 2048), font_e->lba, (uint8_t *)font); + kfree(font_e); + + char *user_p[] = { "USER.BIN" }; + struct iso9660_entity *user_e = ISO9660_get(user_p, 1); + if (!user_e) + panic("Userspace binary not found!"); + ATAPI_granular_read(1 + (user_e->length / 2048), user_e->lba, (uint8_t *)userspace); + kfree(user_e); + } + vga_log("Successfully loaded binaries"); +} diff --git a/src/kernel/fs/load.h b/src/kernel/fs/load.h new file mode 100644 index 0000000..2adefee --- /dev/null +++ b/src/kernel/fs/load.h @@ -0,0 +1,19 @@ +#ifndef MELVIX_LOAD_H +#define MELVIX_LOAD_H + +#include <stdint.h> + +uint32_t userspace; + +struct font *font; + +struct font { + uint16_t font_32[758][32]; + uint16_t font_24[758][24]; + uint8_t font_16[758][16]; + uint16_t cursor[19]; +}; + +void load_binaries(); + +#endif diff --git a/src/kernel/fs/vfs.c b/src/kernel/fs/vfs.c deleted file mode 100644 index f97a69b..0000000 --- a/src/kernel/fs/vfs.c +++ /dev/null @@ -1,47 +0,0 @@ -#include <kernel/fs/vfs.h> - -fs_node_t *fs_root = 0; - -uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) -{ - if (node->read != 0) - return node->read(node, offset, size, buffer); - else - return 0; -} - -uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) -{ - if (node->write != 0) - return node->write(node, offset, size, buffer); - else - return 0; -} - -void open_fs(fs_node_t *node, uint8_t read, uint8_t write) -{ - if (node->open != 0) - return node->open(node); -} - -void close_fs(fs_node_t *node) -{ - if (node->close != 0) - return node->close(node); -} - -struct dirent *readdir_fs(fs_node_t *node, uint32_t index) -{ - if ((node->flags & 0x7) == FS_DIRECTORY && node->readdir != 0) - return node->readdir(node, index); - else - return 0; -} - -fs_node_t *finddir_fs(fs_node_t *node, char *name) -{ - if ((node->flags & 0x7) == FS_DIRECTORY && node->finddir != 0) - return node->finddir(node, name); - else - return 0; -}
\ No newline at end of file diff --git a/src/kernel/fs/vfs.h b/src/kernel/fs/vfs.h deleted file mode 100644 index 4c92185..0000000 --- a/src/kernel/fs/vfs.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef MELVIX_VFS_H -#define MELVIX_VFS_H - -#include <stdint.h> - -#define FS_FILE 0x01 -#define FS_DIRECTORY 0x02 -#define FS_CHARDEVICE 0x03 -#define FS_BLOCKDEVICE 0x04 -#define FS_PIPE 0x05 -#define FS_SYMLINK 0x06 -#define FS_MOUNTPOINT 0x08 - -struct fs_node; - -typedef uint32_t (*read_type_t)(struct fs_node *, uint32_t, uint32_t, uint8_t *); - -typedef uint32_t (*write_type_t)(struct fs_node *, uint32_t, uint32_t, uint8_t *); - -typedef void (*open_type_t)(struct fs_node *); - -typedef void (*close_type_t)(struct fs_node *); - -typedef struct dirent *(*readdir_type_t)(struct fs_node *, uint32_t); - -typedef struct fs_node *(*finddir_type_t)(struct fs_node *, char *name); - -typedef struct fs_node { - char name[128]; - uint32_t mask; - uint32_t uid; - uint32_t gid; - uint32_t flags; - uint32_t inode; - uint32_t length; - uint32_t impl; - read_type_t read; - write_type_t write; - open_type_t open; - close_type_t close; - readdir_type_t readdir; - finddir_type_t finddir; - struct fs_node *ptr; -} fs_node_t; - -struct dirent { - char name[128]; - uint32_t ino; -}; - -extern fs_node_t *fs_root; - -uint32_t read_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer); - -uint32_t write_fs(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer); - -void open_fs(fs_node_t *node, uint8_t read, uint8_t write); - -void close_fs(fs_node_t *node); - -struct dirent *readdir_fs(fs_node_t *node, uint32_t index); - -fs_node_t *finddir_fs(fs_node_t *node, char *name); - -#endif
\ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e5cb666..e1822d8 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -57,14 +57,12 @@ void kernel_main(uint32_t initial_stack) install_melvix(); #endif - loader_init(); - elf_init(); - exec_start((uint8_t *)userspace); + load_elf((char *)userspace); - // syscalls_install(); - // exec(userspace); + // syscalls_install(); + // exec(userspace); panic("This should NOT happen!"); // asm ("div %0" :: "r"(0)); // Exception testing x/0 -}
\ No newline at end of file +} diff --git a/src/userspace/linker.ld b/src/userspace/linker.ld new file mode 100644 index 0000000..7c2941f --- /dev/null +++ b/src/userspace/linker.ld @@ -0,0 +1,19 @@ +ENTRY(_start) + +SECTIONS { + .text 0x40000000 : { + *(.text) + . = ALIGN(4096); + } + + .data : { + *(.data) + *(.rodata) + . = ALIGN(4096); + } + + .bss : { + *(.bss) + . = ALIGN(4096); + } +} |