From 1b429c0fc28e5cd8b474ad5a1de1fa6f3d7c2e2a Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 12 Jul 2021 18:14:44 +0200 Subject: Renamed files to match presentation --- src/loader/inc/cfg.h | 39 ------------ src/loader/inc/config.h | 39 ++++++++++++ src/loader/inc/dev.h | 41 ------------- src/loader/inc/device.h | 41 +++++++++++++ src/loader/inc/disk.h | 21 +++++++ src/loader/inc/dsk.h | 21 ------- src/loader/inc/elf.h | 2 +- src/loader/inc/fs/ext2.h | 2 +- src/loader/inc/impl.h | 20 ------ src/loader/inc/impl/all.h | 12 ---- src/loader/inc/impl/mb1.h | 134 ----------------------------------------- src/loader/inc/impl/mb2.h | 61 ------------------- src/loader/inc/int.h | 49 --------------- src/loader/inc/interrupt.h | 49 +++++++++++++++ src/loader/inc/lib.h | 20 ------ src/loader/inc/library.h | 20 ++++++ src/loader/inc/log.h | 5 +- src/loader/inc/mbr.h | 2 +- src/loader/inc/mem.h | 32 ---------- src/loader/inc/memory.h | 32 ++++++++++ src/loader/inc/panic.h | 24 ++++++++ src/loader/inc/pic.h | 2 +- src/loader/inc/pnc.h | 24 -------- src/loader/inc/protocol.h | 20 ++++++ src/loader/inc/protocols/all.h | 12 ++++ src/loader/inc/protocols/mb1.h | 134 +++++++++++++++++++++++++++++++++++++++++ src/loader/inc/protocols/mb2.h | 61 +++++++++++++++++++ src/loader/inc/real.h | 29 +++++++++ src/loader/inc/rem.h | 29 --------- 29 files changed, 489 insertions(+), 488 deletions(-) delete mode 100644 src/loader/inc/cfg.h create mode 100644 src/loader/inc/config.h delete mode 100644 src/loader/inc/dev.h create mode 100644 src/loader/inc/device.h create mode 100644 src/loader/inc/disk.h delete mode 100644 src/loader/inc/dsk.h delete mode 100644 src/loader/inc/impl.h delete mode 100644 src/loader/inc/impl/all.h delete mode 100644 src/loader/inc/impl/mb1.h delete mode 100644 src/loader/inc/impl/mb2.h delete mode 100644 src/loader/inc/int.h create mode 100644 src/loader/inc/interrupt.h delete mode 100644 src/loader/inc/lib.h create mode 100644 src/loader/inc/library.h delete mode 100644 src/loader/inc/mem.h create mode 100644 src/loader/inc/memory.h create mode 100644 src/loader/inc/panic.h delete mode 100644 src/loader/inc/pnc.h create mode 100644 src/loader/inc/protocol.h create mode 100644 src/loader/inc/protocols/all.h create mode 100644 src/loader/inc/protocols/mb1.h create mode 100644 src/loader/inc/protocols/mb2.h create mode 100644 src/loader/inc/real.h delete mode 100644 src/loader/inc/rem.h (limited to 'src/loader/inc') diff --git a/src/loader/inc/cfg.h b/src/loader/inc/cfg.h deleted file mode 100644 index cb91ab2..0000000 --- a/src/loader/inc/cfg.h +++ /dev/null @@ -1,39 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef CFG_H -#define CFG_H - -#include -#include - -extern u8 boot_disk; - -// Global config element index (can actually be anything but wth) -#define CFG_GLOBAL 0 - -enum cfg_key { - CFG_NONE, - CFG_NAME, - CFG_TIMEOUT, - CFG_PATH, -}; - -struct cfg_entry { - u8 exists : 1; - char name[64]; - char full_path[64]; // With disk name - const char *path; // Without disk name - struct dev *dev; - struct impl impl; -}; - -struct cfg { - u32 timeout; - struct cfg_entry entry[16]; // Up to 16 different entries -}; - -void cfg_foreach(u8 (*cb)(struct cfg_entry *)); -void cfg_exec(struct cfg_entry *entry); -void cfg_read(void); - -#endif diff --git a/src/loader/inc/config.h b/src/loader/inc/config.h new file mode 100644 index 0000000..4f2d7dc --- /dev/null +++ b/src/loader/inc/config.h @@ -0,0 +1,39 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef CONFIG_H +#define CONFIG_H + +#include +#include + +extern u8 boot_disk; + +// Global config element index (can actually be anything but wth) +#define CONFIG_GLOBAL 0 + +enum config_key { + CONFIG_NONE, + CONFIG_NAME, + CONFIG_TIMEOUT, + CONFIG_PATH, +}; + +struct config_entry { + u8 exists : 1; + char name[64]; + char full_path[64]; // With disk name + const char *path; // Without disk name + struct dev *dev; + struct impl impl; +}; + +struct cfg { + u32 timeout; + struct config_entry entry[16]; // Up to 16 different entries +}; + +void config_foreach(u8 (*cb)(struct config_entry *)); +void config_exec(struct config_entry *entry); +void config_read(void); + +#endif diff --git a/src/loader/inc/dev.h b/src/loader/inc/dev.h deleted file mode 100644 index cbefe99..0000000 --- a/src/loader/inc/dev.h +++ /dev/null @@ -1,41 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef DEV_H -#define DEV_H - -#include -#include - -enum dev_type { - DEV_NONE, - DEV_DISK, - DEV_FB, -}; - -struct dev { - u8 id; - enum dev_type type; - char name[16]; - - s32 (*read)(void *, u32, u32, struct dev *); - s32 (*write)(const void *, u32, u32, struct dev *); - - union { - struct { - struct fs fs; - } disk; - // TODO: Other (framebuffer?) - } p; // Prototype union - - u32 data; // Optional (device-specific) data/information -}; - -struct dev *dev_get_by_id(u8 id); -struct dev *dev_get_by_name(const char *name, u32 len); -void dev_foreach(enum dev_type type, u8 (*cb)(struct dev *)); // cb=1 => break -u8 dev_register(enum dev_type type, char *name, u32 data, - s32 (*read)(void *, u32, u32, struct dev *), - s32 (*write)(const void *, u32, u32, struct dev *)); -void dev_print(void); - -#endif diff --git a/src/loader/inc/device.h b/src/loader/inc/device.h new file mode 100644 index 0000000..5081cb7 --- /dev/null +++ b/src/loader/inc/device.h @@ -0,0 +1,41 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef DEVICE_H +#define DEVICE_H + +#include +#include + +enum device_type { + DEVICE_NONE, + DEVICE_DISK, + DEVICE_FB, +}; + +struct dev { + u8 id; + enum device_type type; + char name[16]; + + s32 (*read)(void *, u32, u32, struct dev *); + s32 (*write)(const void *, u32, u32, struct dev *); + + union { + struct { + struct fs fs; + } disk; + // TODO: Other (framebuffer?) + } p; // Prototype union + + u32 data; // Optional (device-specific) data/information +}; + +struct dev *device_get_by_id(u8 id); +struct dev *device_get_by_name(const char *name, u32 len); +void device_foreach(enum device_type type, u8 (*cb)(struct dev *)); // cb=1 => break +u8 device_register(enum device_type type, char *name, u32 data, + s32 (*read)(void *, u32, u32, struct dev *), + s32 (*write)(const void *, u32, u32, struct dev *)); +void device_print(void); + +#endif diff --git a/src/loader/inc/disk.h b/src/loader/inc/disk.h new file mode 100644 index 0000000..e4fb285 --- /dev/null +++ b/src/loader/inc/disk.h @@ -0,0 +1,21 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef DISK_H +#define DISK_H + +#include + +// General disk assumptions +#define BLOCK_SIZE 1024 +#define BLOCK_COUNT 256 // BLOCK_SIZE / sizeof(u32) +#define SECTOR_SIZE 512 +#define SECTOR_COUNT (BLOCK_SIZE / SECTOR_SIZE) // 2 + +struct dev; +struct fs { + s32 (*read)(const char *, void *, u32, u32, struct dev *); +}; + +void disk_detect(struct dev *dev); + +#endif diff --git a/src/loader/inc/dsk.h b/src/loader/inc/dsk.h deleted file mode 100644 index 5b2dec9..0000000 --- a/src/loader/inc/dsk.h +++ /dev/null @@ -1,21 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef DSK_H -#define DSK_H - -#include - -// General disk assumptions -#define BLOCK_SIZE 1024 -#define BLOCK_COUNT 256 // BLOCK_SIZE / sizeof(u32) -#define SECTOR_SIZE 512 -#define SECTOR_COUNT (BLOCK_SIZE / SECTOR_SIZE) // 2 - -struct dev; -struct fs { - s32 (*read)(const char *, void *, u32, u32, struct dev *); -}; - -void dsk_detect(struct dev *dev); - -#endif diff --git a/src/loader/inc/elf.h b/src/loader/inc/elf.h index 4b19f2f..9cf5c2b 100644 --- a/src/loader/inc/elf.h +++ b/src/loader/inc/elf.h @@ -5,7 +5,7 @@ #define ELF_H #include -#include +#include #define ELF_MAG0 0x7F #define ELF_MAG1 'E' diff --git a/src/loader/inc/fs/ext2.h b/src/loader/inc/fs/ext2.h index 0c2052a..ce19ddb 100644 --- a/src/loader/inc/fs/ext2.h +++ b/src/loader/inc/fs/ext2.h @@ -4,7 +4,7 @@ #define FS_EXT2_H #include -#include +#include #define EXT2_BOOT 0 #define EXT2_SUPER 1 diff --git a/src/loader/inc/impl.h b/src/loader/inc/impl.h deleted file mode 100644 index 58ae706..0000000 --- a/src/loader/inc/impl.h +++ /dev/null @@ -1,20 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef IMPL_H -#define IMPL_H - -#include - -enum impl_type { - IMPL_NONE, - IMPL_MB1, - IMPL_MB2, -}; - -struct impl { - enum impl_type type; - u32 offset; // Of header/entry - void (*load)(struct dev *, const char *); -}; - -#endif diff --git a/src/loader/inc/impl/all.h b/src/loader/inc/impl/all.h deleted file mode 100644 index 01565a6..0000000 --- a/src/loader/inc/impl/all.h +++ /dev/null @@ -1,12 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef IMPL_ALL_H -#define IMPL_ALL_H - -#include -#include - -u8 impl_detect(struct cfg_entry *cfg); -void impl_exec(struct cfg_entry *cfg); - -#endif diff --git a/src/loader/inc/impl/mb1.h b/src/loader/inc/impl/mb1.h deleted file mode 100644 index 5e68ece..0000000 --- a/src/loader/inc/impl/mb1.h +++ /dev/null @@ -1,134 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef IMPL_MB1_H -#define IMPL_MB1_H - -#include -#include -#include - -#define MB1_MAGIC 0x1badb002 // Identifies kernel -#define MB1_LOAD_MAGIC 0x2badb002 // Passed to kernel - -#define MB1_INFO_MEMORY 0x00000001 -#define MB1_INFO_BOOTDEV 0x00000002 -#define MB1_INFO_CMDLINE 0x00000004 -#define MB1_INFO_MODS 0x00000008 -#define MB1_INFO_AOUT_SYMS 0x00000010 -#define MB1_INFO_ELF_SHDR 0x00000020 -#define MB1_INFO_MEM_MAP 0x00000040 -#define MB1_INFO_DRIVE_INFO 0x00000080 -#define MB1_INFO_CONFIG_TABLE 0x00000100 -#define MB1_INFO_BOOT_LOADER_NAME 0x00000200 -#define MB1_INFO_APM_TABLE 0x00000400 -#define MB1_INFO_VBE_INFO 0x00000800 -#define MB1_INFO_FRAMEBUFFER_INFO 0x00001000 - -#define MB1_FRAMEBUFFER_TYPE_INDEXED 0 -#define MB1_FRAMEBUFFER_TYPE_RGB 1 -#define MB1_FRAMEBUFFER_TYPE_EGA_TEXT 2 - -#define MB1_MEMORY_AVAILABLE 1 -#define MB1_MEMORY_RESERVED 2 -#define MB1_MEMORY_ACPI_RECLAIMABLE 3 -#define MB1_MEMORY_NVS 4 -#define MB1_MEMORY_BADRAM 5 - -#include - -struct mb1_aout_symbol_table { - u32 tabsize; - u32 strsize; - u32 addr; - u32 reserved; -}; - -struct mb1_elf_section_header_table { - u32 num; - u32 size; - u32 addr; - u32 shndx; -}; - -struct mb1_info { - u32 flags; - - u32 mem_lower; - u32 mem_upper; - - u32 boot_device; - - u32 cmdline; - - u32 mods_count; - u32 mods_addr; - - union { - struct mb1_aout_symbol_table aout_sym; - struct mb1_elf_section_header_table elf_sec; - } u; - - u32 mmap_length; - u32 mmap_addr; - - u32 drives_length; - u32 drives_addr; - - u32 config_table; - - u32 boot_loader_name; - - u32 apm_table; - - u32 vbe_control_info; - u32 vbe_mode_info; - u16 vbe_mode; - u16 vbe_interface_seg; - u16 vbe_interface_off; - u16 vbe_interface_len; - - u32 framebuffer_addr_high; - u32 framebuffer_addr_low; - u32 framebuffer_pitch; - u32 framebuffer_width; - u32 framebuffer_height; - u8 framebuffer_bpp; - u8 framebuffer_type; - union { - struct { - u32 framebuffer_palette_addr; - u16 framebuffer_palette_num_colors; - } palette; - struct { - u8 framebuffer_red_field_position; - u8 framebuffer_red_mask_size; - u8 framebuffer_green_field_position; - u8 framebuffer_green_mask_size; - u8 framebuffer_blue_field_position; - u8 framebuffer_blue_mask_size; - } colors; - } framebuffer_colors; -} PACKED; - -struct mb1_mmap_entry { - u32 struct_size; - u32 addr_low; - u32 addr_high; - u32 len_low; - u32 len_high; - u32 type; -} PACKED; - -struct mb1_mod_list { - u32 mod_start; - u32 mod_end; - - u32 cmdline; - - u32 pad; -}; - -u8 mb1_detect(struct cfg_entry *cfg); -void mb1_exec(struct cfg_entry *cfg); - -#endif diff --git a/src/loader/inc/impl/mb2.h b/src/loader/inc/impl/mb2.h deleted file mode 100644 index 3f64dbd..0000000 --- a/src/loader/inc/impl/mb2.h +++ /dev/null @@ -1,61 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef IMPL_MB2_H -#define IMPL_MB2_H - -#include -#include -#include - -#define MB2_MAGIC 0xe85250d6 // Identifies kernel -#define MB2_LOAD_MAGIC 0x36d76289 // Passed to kernel - -struct mb2_header { - u32 total_size; - u32 unknown; -} PACKED; - -struct mb2_tag { - u32 type; - u32 size; -} PACKED; - -struct mb2_memory { - u32 addr_low; - u32 addr_high; - u32 size_low; - u32 size_high; - u32 type; - u32 reserved; -} PACKED; - -struct mb2_module { - u32 start; - u32 end; - char string[1]; -} PACKED; - -struct mb2_fb { - u32 addr_low; - u32 addr_high; - u32 pitch; - u32 width; - u32 height; - u8 bpp; - u8 type; -} PACKED; - -enum mb2_tags { - MB2_TAG_END = 0, - MB2_TAG_CMDLINE = 1, - MB2_TAG_MODULE = 3, - MB2_TAG_MEMORY = 6, - MB2_TAG_FB = 8, - MB2_TAG_ACPI_1 = 14, - MB2_TAG_ACPI_2 = 15, -}; - -u8 mb2_detect(struct cfg_entry *cfg); -void mb2_exec(struct cfg_entry *cfg); - -#endif diff --git a/src/loader/inc/int.h b/src/loader/inc/int.h deleted file mode 100644 index ccd9ea8..0000000 --- a/src/loader/inc/int.h +++ /dev/null @@ -1,49 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef INT_H -#define INT_H - -#include - -#define INT_GATE 0x8e -#define INT_TRAP 0xef -#define INT_USER 0x60 -#define IDT_ENTRY(offset, selector, type) \ - (struct idt_entry) \ - { \ - .base_low = (u16)((offset)&0xffff), .sel = (selector), .zero = 0, .flags = (type), \ - .base_high = (u16)(((offset) >> 16) & 0xffff), \ - } - -struct int_frame { - u32 gs, fs, es, ds; - u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; - u32 int_no, err_code; - u32 eip, cs, eflags; -} PACKED; - -struct int_frame_user { - u32 gs, fs, es, ds; - u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; - u32 int_no, err_code; - u32 eip, cs, eflags; - u32 useresp, ss; -} PACKED; - -struct idt_entry { - u16 base_low; - u16 sel; // Kernel segment - u8 zero; // Always 0 - u8 flags; - u16 base_high; -} PACKED; - -struct idt_ptr { - u16 size; - void *base; -} PACKED; - -void idt_install(void); -void int_event_handler_add(u32 int_no, void (*handler)(void)); - -#endif diff --git a/src/loader/inc/interrupt.h b/src/loader/inc/interrupt.h new file mode 100644 index 0000000..4706dbe --- /dev/null +++ b/src/loader/inc/interrupt.h @@ -0,0 +1,49 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef INTERRUPT_H +#define INTERRUPT_H + +#include + +#define INTERRUPT_GATE 0x8e +#define INTERRUPT_TRAP 0xef +#define INTERRUPT_USER 0x60 +#define IDT_ENTRY(offset, selector, type) \ + (struct idt_entry) \ + { \ + .base_low = (u16)((offset)&0xffff), .sel = (selector), .zero = 0, .flags = (type), \ + .base_high = (u16)(((offset) >> 16) & 0xffff), \ + } + +struct interrupt_frame { + u32 gs, fs, es, ds; + u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; + u32 interrupt_no, err_code; + u32 eip, cs, eflags; +} PACKED; + +struct interrupt_frame_user { + u32 gs, fs, es, ds; + u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; + u32 interrupt_no, err_code; + u32 eip, cs, eflags; + u32 useresp, ss; +} PACKED; + +struct idt_entry { + u16 base_low; + u16 sel; // Kernel segment + u8 zero; // Always 0 + u8 flags; + u16 base_high; +} PACKED; + +struct idt_ptr { + u16 size; + void *base; +} PACKED; + +void idt_install(void); +void interrupt_event_handler_add(u32 interrupt_no, void (*handler)(void)); + +#endif diff --git a/src/loader/inc/lib.h b/src/loader/inc/lib.h deleted file mode 100644 index 2f49007..0000000 --- a/src/loader/inc/lib.h +++ /dev/null @@ -1,20 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef LIB_H -#define LIB_H - -#include - -u32 strlen(const char *str); -u32 strnlen(const char *s, u32 max); -u32 strlcpy(char *dst, const char *src, u32 size); -s32 strncmp(const char *s1, const char *s2, u32 n); - -void *memcpy(void *dest, const void *src, u32 n); -void *memset(void *dest, u32 val, u32 n); -s32 memcmp(const void *s1, const void *s2, u32 n); - -s32 itoa(s32 value, char *buffer, u32 base); -s32 atoi(const char *inp); - -#endif diff --git a/src/loader/inc/library.h b/src/loader/inc/library.h new file mode 100644 index 0000000..2f49007 --- /dev/null +++ b/src/loader/inc/library.h @@ -0,0 +1,20 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef LIB_H +#define LIB_H + +#include + +u32 strlen(const char *str); +u32 strnlen(const char *s, u32 max); +u32 strlcpy(char *dst, const char *src, u32 size); +s32 strncmp(const char *s1, const char *s2, u32 n); + +void *memcpy(void *dest, const void *src, u32 n); +void *memset(void *dest, u32 val, u32 n); +s32 memcmp(const void *s1, const void *s2, u32 n); + +s32 itoa(s32 value, char *buffer, u32 base); +s32 atoi(const char *inp); + +#endif diff --git a/src/loader/inc/log.h b/src/loader/inc/log.h index cb1acd8..f6a28e1 100644 --- a/src/loader/inc/log.h +++ b/src/loader/inc/log.h @@ -5,13 +5,14 @@ #include +u32 vsnprintf(char *str, u32 size, const char *format, va_list ap); + void serial_install(void); void serial_print(const char *data); +void log(const char *format, ...); void vga_put_at(char ch, u8 x, u8 y, u8 color); void vga_clear(void); - -void log(const char *format, ...); void vga_log(const char *format, ...); #endif diff --git a/src/loader/inc/mbr.h b/src/loader/inc/mbr.h index a9befe5..ec51944 100644 --- a/src/loader/inc/mbr.h +++ b/src/loader/inc/mbr.h @@ -4,7 +4,7 @@ #define MBR_H #include -#include +#include struct mbr_entry { u8 attributes; diff --git a/src/loader/inc/mem.h b/src/loader/inc/mem.h deleted file mode 100644 index 7153465..0000000 --- a/src/loader/inc/mem.h +++ /dev/null @@ -1,32 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef MEM_H -#define MEM_H - -#include - -enum mem_entry_type { - MEM_NONE, - MEM_USABLE, - MEM_RESERVED, - MEM_RECLAIMABLE, - MEM_ACPI_NVS, - MEM_UNUSABLE, -}; - -// Generalised memory map entry struct -struct mem_entry { - u32 base; - u32 length; - u32 type; -}; - -struct mem_map { - struct mem_entry *entry; - u32 count; -}; - -void mem_map(void); -struct mem_map *mem_map_get(void); - -#endif diff --git a/src/loader/inc/memory.h b/src/loader/inc/memory.h new file mode 100644 index 0000000..1a74884 --- /dev/null +++ b/src/loader/inc/memory.h @@ -0,0 +1,32 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef MEMORY_H +#define MEMORY_H + +#include + +enum memory_entry_type { + MEMORY_NONE, + MEMORY_USABLE, + MEMORY_RESERVED, + MEMORY_RECLAIMABLE, + MEMORY_ACPI_NVS, + MEMORY_UNUSABLE, +}; + +// Generalised memory map entry struct +struct memory_entry { + u32 base; + u32 length; + u32 type; +}; + +struct memory_map { + struct memory_entry *entry; + u32 count; +}; + +void memory_map(void); +struct memory_map *memory_map_get(void); + +#endif diff --git a/src/loader/inc/panic.h b/src/loader/inc/panic.h new file mode 100644 index 0000000..73819c9 --- /dev/null +++ b/src/loader/inc/panic.h @@ -0,0 +1,24 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef PNC_H +#define PNC_H + +#include + +#define panic(reason) \ + { \ + log("%s:%d: %s: Panic: %s", __FILE__, __LINE__, __func__, (reason)); \ + while (1) \ + __asm__ volatile("cli\nhlt"); \ + } + +#define assert(exp) \ + { \ + if (!(exp)) \ + panic("Assertion '" #exp "' failed\n"); \ + } + +// This shouldn't return, therefore this declaration belongs here (kinda) +void jmp_kernel(void *kernel, int args, ...); + +#endif diff --git a/src/loader/inc/pic.h b/src/loader/inc/pic.h index c2a7d87..d662454 100644 --- a/src/loader/inc/pic.h +++ b/src/loader/inc/pic.h @@ -6,6 +6,6 @@ #include void pic_install(void); -void pic_ack(u32 int_no); +void pic_ack(u32 interrupt_no); #endif diff --git a/src/loader/inc/pnc.h b/src/loader/inc/pnc.h deleted file mode 100644 index 73819c9..0000000 --- a/src/loader/inc/pnc.h +++ /dev/null @@ -1,24 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef PNC_H -#define PNC_H - -#include - -#define panic(reason) \ - { \ - log("%s:%d: %s: Panic: %s", __FILE__, __LINE__, __func__, (reason)); \ - while (1) \ - __asm__ volatile("cli\nhlt"); \ - } - -#define assert(exp) \ - { \ - if (!(exp)) \ - panic("Assertion '" #exp "' failed\n"); \ - } - -// This shouldn't return, therefore this declaration belongs here (kinda) -void jmp_kernel(void *kernel, int args, ...); - -#endif diff --git a/src/loader/inc/protocol.h b/src/loader/inc/protocol.h new file mode 100644 index 0000000..a667467 --- /dev/null +++ b/src/loader/inc/protocol.h @@ -0,0 +1,20 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef IMPL_H +#define IMPL_H + +#include + +enum impl_type { + IMPL_NONE, + IMPL_MB1, + IMPL_MB2, +}; + +struct impl { + enum impl_type type; + u32 offset; // Of header/entry + void (*load)(struct dev *, const char *); +}; + +#endif diff --git a/src/loader/inc/protocols/all.h b/src/loader/inc/protocols/all.h new file mode 100644 index 0000000..9b6e750 --- /dev/null +++ b/src/loader/inc/protocols/all.h @@ -0,0 +1,12 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef IMPL_ALL_H +#define IMPL_ALL_H + +#include +#include + +u8 impl_detect(struct config_entry *cfg); +void impl_exec(struct config_entry *cfg); + +#endif diff --git a/src/loader/inc/protocols/mb1.h b/src/loader/inc/protocols/mb1.h new file mode 100644 index 0000000..2a85bc0 --- /dev/null +++ b/src/loader/inc/protocols/mb1.h @@ -0,0 +1,134 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef IMPL_MB1_H +#define IMPL_MB1_H + +#include +#include +#include + +#define MB1_MAGIC 0x1badb002 // Identifies kernel +#define MB1_LOAD_MAGIC 0x2badb002 // Passed to kernel + +#define MB1_INFO_MEMORY 0x00000001 +#define MB1_INFO_BOOTDEV 0x00000002 +#define MB1_INFO_CMDLINE 0x00000004 +#define MB1_INFO_MODS 0x00000008 +#define MB1_INFO_AOUT_SYMS 0x00000010 +#define MB1_INFO_ELF_SHDR 0x00000020 +#define MB1_INFO_MEMORY_MAP 0x00000040 +#define MB1_INFO_DRIVE_INFO 0x00000080 +#define MB1_INFO_CONFIG_TABLE 0x00000100 +#define MB1_INFO_BOOT_LOADER_NAME 0x00000200 +#define MB1_INFO_APM_TABLE 0x00000400 +#define MB1_INFO_VBE_INFO 0x00000800 +#define MB1_INFO_FRAMEBUFFER_INFO 0x00001000 + +#define MB1_FRAMEBUFFER_TYPE_INDEXED 0 +#define MB1_FRAMEBUFFER_TYPE_RGB 1 +#define MB1_FRAMEBUFFER_TYPE_EGA_TEXT 2 + +#define MB1_MEMORY_AVAILABLE 1 +#define MB1_MEMORY_RESERVED 2 +#define MB1_MEMORY_ACPI_RECLAIMABLE 3 +#define MB1_MEMORY_NVS 4 +#define MB1_MEMORY_BADRAM 5 + +#include + +struct mb1_aout_symbol_table { + u32 tabsize; + u32 strsize; + u32 addr; + u32 reserved; +}; + +struct mb1_elf_section_header_table { + u32 num; + u32 size; + u32 addr; + u32 shndx; +}; + +struct mb1_info { + u32 flags; + + u32 memory_lower; + u32 memory_upper; + + u32 boot_device; + + u32 cmdline; + + u32 mods_count; + u32 mods_addr; + + union { + struct mb1_aout_symbol_table aout_sym; + struct mb1_elf_section_header_table elf_sec; + } u; + + u32 mmap_length; + u32 mmap_addr; + + u32 drives_length; + u32 drives_addr; + + u32 config_table; + + u32 boot_loader_name; + + u32 apm_table; + + u32 vbe_control_info; + u32 vbe_mode_info; + u16 vbe_mode; + u16 vbe_interface_seg; + u16 vbe_interface_off; + u16 vbe_interface_len; + + u32 framebuffer_addr_high; + u32 framebuffer_addr_low; + u32 framebuffer_pitch; + u32 framebuffer_width; + u32 framebuffer_height; + u8 framebuffer_bpp; + u8 framebuffer_type; + union { + struct { + u32 framebuffer_palette_addr; + u16 framebuffer_palette_num_colors; + } palette; + struct { + u8 framebuffer_red_field_position; + u8 framebuffer_red_mask_size; + u8 framebuffer_green_field_position; + u8 framebuffer_green_mask_size; + u8 framebuffer_blue_field_position; + u8 framebuffer_blue_mask_size; + } colors; + } framebuffer_colors; +} PACKED; + +struct mb1_mmap_entry { + u32 struct_size; + u32 addr_low; + u32 addr_high; + u32 len_low; + u32 len_high; + u32 type; +} PACKED; + +struct mb1_mod_list { + u32 mod_start; + u32 mod_end; + + u32 cmdline; + + u32 pad; +}; + +u8 mb1_detect(struct config_entry *cfg); +void mb1_exec(struct config_entry *cfg); + +#endif diff --git a/src/loader/inc/protocols/mb2.h b/src/loader/inc/protocols/mb2.h new file mode 100644 index 0000000..b471b0f --- /dev/null +++ b/src/loader/inc/protocols/mb2.h @@ -0,0 +1,61 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef IMPL_MB2_H +#define IMPL_MB2_H + +#include +#include +#include + +#define MB2_MAGIC 0xe85250d6 // Identifies kernel +#define MB2_LOAD_MAGIC 0x36d76289 // Passed to kernel + +struct mb2_header { + u32 total_size; + u32 unknown; +} PACKED; + +struct mb2_tag { + u32 type; + u32 size; +} PACKED; + +struct mb2_memory { + u32 addr_low; + u32 addr_high; + u32 size_low; + u32 size_high; + u32 type; + u32 reserved; +} PACKED; + +struct mb2_module { + u32 start; + u32 end; + char string[1]; +} PACKED; + +struct mb2_fb { + u32 addr_low; + u32 addr_high; + u32 pitch; + u32 width; + u32 height; + u8 bpp; + u8 type; +} PACKED; + +enum mb2_tags { + MB2_TAG_END = 0, + MB2_TAG_CMDLINE = 1, + MB2_TAG_MODULE = 3, + MB2_TAG_MEMORY = 6, + MB2_TAG_FB = 8, + MB2_TAG_ACPI_1 = 14, + MB2_TAG_ACPI_2 = 15, +}; + +u8 mb2_detect(struct config_entry *cfg); +void mb2_exec(struct config_entry *cfg); + +#endif diff --git a/src/loader/inc/real.h b/src/loader/inc/real.h new file mode 100644 index 0000000..a9d36dc --- /dev/null +++ b/src/loader/inc/real.h @@ -0,0 +1,29 @@ +// MIT License, Copyright (c) 2021 Marvin Borner +// Real mode emulation - Implementation by Napalm (see rem.asm) + +#ifndef REAL_H +#define REAL_H + +#include + +#define EFLAGS_CF (1 << 0) // Carry flag +#define EFLAGS_ZF (1 << 6) // Zero flag + +struct real_regs { + u16 gs; + u16 fs; + u16 es; + u16 ds; + u32 eflags; + u32 ebp; + u32 edi; + u32 esi; + u32 edx; + u32 ecx; + u32 ebx; + u32 eax; +} PACKED; + +void real_int(u8 interrupt_num, struct real_regs *out_regs, struct real_regs *in_regs); + +#endif diff --git a/src/loader/inc/rem.h b/src/loader/inc/rem.h deleted file mode 100644 index 61eb30a..0000000 --- a/src/loader/inc/rem.h +++ /dev/null @@ -1,29 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner -// Real mode emulation - Implementation by Napalm (see rem.asm) - -#ifndef REM_H -#define REM_H - -#include - -#define EFLAGS_CF (1 << 0) // Carry flag -#define EFLAGS_ZF (1 << 6) // Zero flag - -struct rem_regs { - u16 gs; - u16 fs; - u16 es; - u16 ds; - u32 eflags; - u32 ebp; - u32 edi; - u32 esi; - u32 edx; - u32 ecx; - u32 ebx; - u32 eax; -} PACKED; - -void rem_int(u8 int_num, struct rem_regs *out_regs, struct rem_regs *in_regs); - -#endif -- cgit v1.2.3