summaryrefslogtreecommitdiff
path: root/src/kernel.c
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-10-09 09:06:04 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-10-09 09:06:04 -0700
commitc74bd1baa844eac1fcb17a266ef720ed0c1ae616 (patch)
tree9b5c7699c8704b0930daeddffa568990254a231b /src/kernel.c
parentf021512078e7d2447e46a4856a81c0ba6e030d43 (diff)
downloadmacaroni-c74bd1baa844eac1fcb17a266ef720ed0c1ae616.tar.gz
macaroni-c74bd1baa844eac1fcb17a266ef720ed0c1ae616.zip
Bit o a refactah
Diffstat (limited to 'src/kernel.c')
-rw-r--r--src/kernel.c129
1 files changed, 12 insertions, 117 deletions
diff --git a/src/kernel.c b/src/kernel.c
index 952eac2..2c2afcc 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -1,133 +1,28 @@
+#include "utils.h"
+#include "multiboot.h"
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-typedef unsigned long long u64;
-
-#ifndef asm
-#define asm __asm__ volatile
-#endif
-
-struct __attribute__((packed)) multiboot_info
-{
- /* Multiboot info version number */
- u32 flags;
-
- /* Available memory from BIOS */
- u32 mem_lower;
- u32 mem_upper;
-
- /* "root" partition */
- u32 boot_device;
-
- /* Kernel command line */
- u32 cmdline;
-
- /* Boot-Module list */
- u32 mods_count;
- u32 mods_addr;
-
-// union
-// {
-// multiboot_aout_symbol_table_t aout_sym;
-// multiboot_elf_section_header_table_t elf_sec;
-// } u;
- u32 unused_1;
- u32 unused_2;
- u32 unused_3;
- u32 unused_4;
-
- /* Memory Mapping buffer */
- u32 mmap_length;
- u32 mmap_addr;
-
- /* Drive Info buffer */
- u32 drives_length;
- u32 drives_addr;
-
- /* ROM configuration table */
- u32 config_table;
-
- /* Boot Loader Name */
- u32 boot_loader_name;
-
- /* APM table */
- u32 apm_table;
-
- /* Video */
- u32 vbe_control_info;
- u32 vbe_mode_info;
- u16 vbe_mode;
- u16 vbe_interface_seg;
- u16 vbe_interface_off;
- u16 vbe_interface_len;
-
- u64 framebuffer_addr;
- u32 framebuffer_pitch;
- u32 framebuffer_width;
- u32 framebuffer_height;
- u8 framebuffer_bpp;
-#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
-#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
-#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
- u8 framebuffer_type;
- union
- {
- struct
- {
- u32 framebuffer_palette_addr;
- u16 framebuffer_palette_num_colors;
- };
- 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;
- };
- };
-};
-typedef struct multiboot_info multiboot_info_t;
-
-u8 inportb(u16 port) {
- u8 r;
- asm("inb %1, %0" : "=a" (r) : "dN" (port));
- return r;
-}
-
-void outportb(u16 port, u8 data) {
- asm("outb %1, %0" : : "dN" (port), "a" (data));
-}
-
-void macaroni_panic(char* msg) {
- // we'll do something with msg later.
- while(true){ asm("nop\n\t"); }
-}
-
-void macaroni_assert(bool condition) {
- if (condition) {
- return;
- }
- macaroni_panic("thisisatest");
-}
+void validate_multiboot
void cmain(void) {
- u32 magic_response = 0x1;
+ uint32_t magic_response;
multiboot_info_t* p_multiboot_info;
asm("\t movl %%eax,%0" : "=r"(magic_response));
asm("\t movl %%ebx,%0" : "=r"(p_multiboot_info));
+ macaroni_assert(magic_response == 0x2BADB002, "im not a bad boo twooo");
+ macaroni_assert(p_multiboot_info->framebuffer_width == 640, "not gods width");
+ macaroni_assert(p_multiboot_info->framebuffer_height == 480, "not gods height");
+ macaroni_assert(p_multiboot_info->framebuffer_bpp == 16, "not gods bpp");
+ macaroni_assert(p_multiboot_info->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB, "not gods fbtype");
+ macaroni_assert(p_multiboot_info->framebuffer_red_field_position == 1, "bpp not formatted correctly");
+
void *fb = (void *) (unsigned long) p_multiboot_info->framebuffer_addr;
- u8* pixel = fb;
+ uint8_t* pixel = fb;
for (int i = 0; i < 10000; i++) {
*(pixel + i) = i * 2;
}
- macaroni_assert(magic_response == 0x2BADB002);
- //asm("int $0x13");
}