From 06c2adf7e5b6343339e899d7f5c7186d23fcfdae Mon Sep 17 00:00:00 2001 From: InventorXtreme Date: Wed, 24 Apr 2024 22:30:33 -0400 Subject: [PATCH] getting mem from mutliboot or whatever --- boot.s | 6 +++ kernel.c | 29 +++++++++++--- multiboot.h | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 multiboot.h diff --git a/boot.s b/boot.s index 66c98bc..a2baf4b 100644 --- a/boot.s +++ b/boot.s @@ -76,6 +76,12 @@ _start: runtime support to work as well. */ + /* + this will put the mutliboot structure into our c code + */ + push %ebx + + /* Enter the high-level kernel. The ABI requires the stack is 16-byte aligned at the time of the call instruction (which afterwards pushes diff --git a/kernel.c b/kernel.c index 44267f1..c99d848 100644 --- a/kernel.c +++ b/kernel.c @@ -1,7 +1,7 @@ #include #include #include - +#include "multiboot.h" /* Check if the compiler thinks you are targeting the wrong operating system. */ #if defined(__linux__) #error "You are not using a cross-compiler, you will most certainly run into trouble" @@ -114,7 +114,7 @@ void terminal_writestring(const char* data) { terminal_write(data, strlen(data)); } -void int_to_string(char * str, size_t strlen, int conv) { +void int_to_string(char * str, size_t strlen, size_t conv) { char buffer[100]; for (int i = 0; i < 100; i++) { buffer[i] = -1; @@ -140,15 +140,34 @@ void int_to_string(char * str, size_t strlen, int conv) { } -void kernel_main(void) { +void kernel_main(unsigned long addr) { /* Initialize terminal interface */ terminal_initialize(); - + //uint32_t * flags = (uint32_t *) addr; + /* Newline support is left as an exercise. */ + multiboot_info_t *mbi = (multiboot_info_t *) addr; + char x[50]; - int_to_string(x, 50, 12345); + for (int i = 0; i < 50; i++) { + x[i] = -1; + } + int_to_string(x, 50, mbi->mem_lower); terminal_writestring(x); + terminal_writestring("\n"); + + for (int i = 0; i < 50; i++) { + x[i] = -1; + } + + int_to_string(x, 50, mbi->mem_upper); + + terminal_writestring(x); + terminal_writestring("\n"); + + + terminal_writestring("erm what da sigma\n"); terminal_writestring("Hello, kernel World!\n"); terminal_writestring("Hello, kernel World!\n"); terminal_writestring("Hello, kernel World!\n"); diff --git a/multiboot.h b/multiboot.h new file mode 100644 index 0000000..f163418 --- /dev/null +++ b/multiboot.h @@ -0,0 +1,108 @@ +#ifndef MULTIBOOT_HEADER +#define MULTIBOOT_HEADER + +typedef unsigned char multiboot_uint8_t; +typedef unsigned short multiboot_uint16_t; +typedef unsigned int multiboot_uint32_t; +typedef unsigned long long multiboot_uint64_t; + +struct multiboot_aout_symbol_table +{ + multiboot_uint32_t tabsize; + multiboot_uint32_t strsize; + multiboot_uint32_t addr; + multiboot_uint32_t reserved; +}; +typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; + +struct multiboot_elf_section_header_table +{ + multiboot_uint32_t num; + multiboot_uint32_t size; + multiboot_uint32_t addr; + multiboot_uint32_t shndx; +}; +typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t; + + + +struct multiboot_info +{ + /* Multiboot info version number */ + multiboot_uint32_t flags; + + /* Available memory from BIOS */ + multiboot_uint32_t mem_lower; + multiboot_uint32_t mem_upper; + + /* "root" partition */ + multiboot_uint32_t boot_device; + + /* Kernel command line */ + multiboot_uint32_t cmdline; + + /* Boot-Module list */ + multiboot_uint32_t mods_count; + multiboot_uint32_t mods_addr; + + union + { + multiboot_aout_symbol_table_t aout_sym; + multiboot_elf_section_header_table_t elf_sec; + } u; + + /* Memory Mapping buffer */ + multiboot_uint32_t mmap_length; + multiboot_uint32_t mmap_addr; + + /* Drive Info buffer */ + multiboot_uint32_t drives_length; + multiboot_uint32_t drives_addr; + + /* ROM configuration table */ + multiboot_uint32_t config_table; + + /* Boot Loader Name */ + multiboot_uint32_t boot_loader_name; + + /* APM table */ + multiboot_uint32_t apm_table; + + /* Video */ + multiboot_uint32_t vbe_control_info; + multiboot_uint32_t vbe_mode_info; + multiboot_uint16_t vbe_mode; + multiboot_uint16_t vbe_interface_seg; + multiboot_uint16_t vbe_interface_off; + multiboot_uint16_t vbe_interface_len; + + multiboot_uint64_t framebuffer_addr; + multiboot_uint32_t framebuffer_pitch; + multiboot_uint32_t framebuffer_width; + multiboot_uint32_t framebuffer_height; + multiboot_uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + multiboot_uint8_t framebuffer_type; + union + { + struct + { + multiboot_uint32_t framebuffer_palette_addr; + multiboot_uint16_t framebuffer_palette_num_colors; + }; + struct + { + multiboot_uint8_t framebuffer_red_field_position; + multiboot_uint8_t framebuffer_red_mask_size; + multiboot_uint8_t framebuffer_green_field_position; + multiboot_uint8_t framebuffer_green_mask_size; + multiboot_uint8_t framebuffer_blue_field_position; + multiboot_uint8_t framebuffer_blue_mask_size; + }; + }; +}; +typedef struct multiboot_info multiboot_info_t; + +#endif