getting mem from mutliboot or whatever

This commit is contained in:
InventorXtreme 2024-04-24 22:30:33 -04:00
parent 95e73a8e50
commit 06c2adf7e5
3 changed files with 138 additions and 5 deletions

6
boot.s
View file

@ -76,6 +76,12 @@ _start:
runtime support to work as well. 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 Enter the high-level kernel. The ABI requires the stack is 16-byte
aligned at the time of the call instruction (which afterwards pushes aligned at the time of the call instruction (which afterwards pushes

View file

@ -1,7 +1,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "multiboot.h"
/* Check if the compiler thinks you are targeting the wrong operating system. */ /* Check if the compiler thinks you are targeting the wrong operating system. */
#if defined(__linux__) #if defined(__linux__)
#error "You are not using a cross-compiler, you will most certainly run into trouble" #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)); 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]; char buffer[100];
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
buffer[i] = -1; 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 */ /* Initialize terminal interface */
terminal_initialize(); terminal_initialize();
//uint32_t * flags = (uint32_t *) addr;
/* Newline support is left as an exercise. */ /* Newline support is left as an exercise. */
multiboot_info_t *mbi = (multiboot_info_t *) addr;
char x[50]; 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(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"); terminal_writestring("Hello, kernel World!\n");
terminal_writestring("Hello, kernel World!\n"); terminal_writestring("Hello, kernel World!\n");

108
multiboot.h Normal file
View file

@ -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