Setup simple kernel with Hello World output via debugcon (AI)
This commit is contained in:
32
src/kernel.c
32
src/kernel.c
@@ -1,3 +1,31 @@
|
||||
void _start() {
|
||||
while(1) {}
|
||||
#include <multiboot2.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static inline void outb(uint16_t port, uint8_t val)
|
||||
{
|
||||
asm volatile ( "outb %b0, %w1" : : "a"(val), "Nd"(port) );
|
||||
}
|
||||
|
||||
void offset_print(const char *str)
|
||||
{
|
||||
while (*str) {
|
||||
outb(0xE9, *str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
|
||||
|
||||
void kernel_main(uint32_t magic, uint32_t addr) {
|
||||
(void)addr; // Unused for now
|
||||
|
||||
if (magic != MULTIBOOT2_BOOTLOADER_MAGIC && magic != MULTIBOOT_BOOTLOADER_MAGIC) {
|
||||
offset_print("Invalid magic number: ");
|
||||
// I don't have hex print yet, but I can print something generic
|
||||
offset_print("Unknown\n");
|
||||
return;
|
||||
}
|
||||
|
||||
offset_print("Hello, world\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user