Compare commits

..

No commits in common. "fb981bf9942d52f6db1b6852123a452261e20a94" and "3e3df8e724f989a5e9034fdb038f7c9d0d79cdd6" have entirely different histories.

14 changed files with 90 additions and 189 deletions

View File

@ -35,8 +35,7 @@ bin/$(TARGET)-$(ARCH): $(OBJ)
obj/$(ARCH)/%.o: src/%.c $(HFILES) obj/$(ARCH)/%.o: src/%.c $(HFILES)
@mkdir -p $(@D) @mkdir -p $(@D)
@echo $(CC) $< $(CC) $(CFLAGS) -c $< -o $@
@$(CC) $(CFLAGS) -c $< -o $@
clean: clean:
rm -rf bin obj zig-cache rm -rf bin obj zig-cache

View File

@ -1 +0,0 @@
const char *arch = "i386";

View File

@ -2,3 +2,5 @@ void halt_catch_fire() {
asm volatile ("cli"); asm volatile ("cli");
while(1) asm volatile ("hlt"); while(1) asm volatile ("hlt");
} }
const char *arch = "i386";

View File

@ -1,9 +0,0 @@
#include "vga.h"
#include <hal/ops.h>
void panic(const char *message, const char *filename, int line) {
vga_clear(VGA_BLUE);
printf("KernOS kernel panic:\n%s\n", message);
printf("at %s:%d", filename, line);
halt_catch_fire();
}

View File

@ -1,11 +1,9 @@
#include <limine/stivale/stivale2.h> #include <limine/stivale/stivale2.h>
#include <print/print.h> #include <print/print.h>
#include <hal/info.h>
#include <stddef.h> #include <stddef.h>
void print_stivale2(struct stivale2_struct *info) { void parse_stivale2(struct stivale2_struct *info) {
struct stivale2_tag *tag = (struct stivale2_tag*)(info->tags); struct stivale2_tag *tag = (struct stivale2_tag*)(info->tags);
while(tag != 0) { while(tag != 0) {
switch(tag->identifier) { switch(tag->identifier) {
@ -78,78 +76,81 @@ void print_stivale2(struct stivale2_struct *info) {
tag = (struct stivale2_tag *)tag->next; tag = (struct stivale2_tag *)tag->next;
} }
} }
void parse_stivale2(struct stivale2_struct *info) {
boot_info.boot_protocol = "stivale2";
boot_info.bootloader_name = info->bootloader_brand;
boot_info.bootloader_ver = info->bootloader_version;
printf("Unrecogized tags: "); // void parse_stivale2(struct stivale2_struct *info) {
struct stivale2_tag *tag = (struct stivale2_tag*)(info->tags); // struct stivale2_tag *tag = (struct stivale2_tag*)(info->tags);
while(tag != 0) { // while(tag != 0) {
switch(tag->identifier) { // switch(tag->identifier) {
case STIVALE2_STRUCT_TAG_CMDLINE_ID: { // case STIVALE2_STRUCT_TAG_CMDLINE_ID: {
struct stivale2_struct_tag_cmdline *cmd = (struct stivale2_struct_tag_cmdline*)tag; // struct stivale2_struct_tag_cmdline *cmd = (struct stivale2_struct_tag_cmdline*)tag;
set_cmdline((const char*)cmd->cmdline); // printf("cmdline: %s\n", (const char*)cmd->cmdline);
break; // break;
} // }
case STIVALE2_STRUCT_TAG_MEMMAP_ID: { // case STIVALE2_STRUCT_TAG_MEMMAP_ID: {
struct stivale2_struct_tag_memmap *m = (struct stivale2_struct_tag_memmap *)tag; // struct stivale2_struct_tag_memmap *m = (struct stivale2_struct_tag_memmap *)tag;
for (size_t i = 0; i < m->entries; i++) { // printf("Memmap (%d entries):\n", m->entries);
struct stivale2_mmap_entry me = m->memmap[i]; // for (size_t i = 0; i < m->entries; i++) {
if(me.type == STIVALE2_MMAP_USABLE) { // struct stivale2_mmap_entry me = m->memmap[i];
set_memregion(me.base, me.length); // printf("\t[%x+%x] %x\n", me.base, me.length, me.type);
} // }
} // break;
break; // }
} // case STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID: {
case STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID: { // struct stivale2_struct_tag_framebuffer *f = (struct stivale2_struct_tag_framebuffer *)tag;
struct stivale2_struct_tag_framebuffer *f = (struct stivale2_struct_tag_framebuffer *)tag; // printf("Framebuffer tag: %dx%d at %x\n", f->framebuffer_width, f->framebuffer_height, f->framebuffer_addr);
printf("FRAMEBUFFER (%dx%d at %x)\n", f->framebuffer_width, f->framebuffer_height, f->framebuffer_addr); // printf("\tPitch: %d\n", f->framebuffer_pitch);
printf("\tPitch: %d\n", f->framebuffer_pitch); // printf("\tBPP: %d\n", f->framebuffer_bpp);
printf("\tBPP: %d\n", f->framebuffer_bpp); // printf("\tMemory model: %d\n", f->memory_model);
printf("\tMemory model: %d\n", f->memory_model); // printf("\tRed mask size: %d\n", f->red_mask_size);
printf("\tRed mask size: %d\n", f->red_mask_size); // printf("\tRed mask size: %d\n", f->red_mask_shift);
printf("\tRed mask size: %d\n", f->red_mask_shift); // printf("\tGreen mask size: %d\n", f->green_mask_size);
printf("\tGreen mask size: %d\n", f->green_mask_size); // printf("\tGreen mask size: %d\n", f->green_mask_shift);
printf("\tGreen mask size: %d\n", f->green_mask_shift); // printf("\tBlue mask size: %d\n", f->blue_mask_size);
printf("\tBlue mask size: %d\n", f->blue_mask_size); // printf("\tBlue mask size: %d\n", f->blue_mask_shift);
printf("\tBlue mask size: %d\n", f->blue_mask_shift); // break;
break; // }
} // case STIVALE2_STRUCT_TAG_MODULES_ID: {
case STIVALE2_STRUCT_TAG_MODULES_ID: { // struct stivale2_struct_tag_modules *m = (struct stivale2_struct_tag_modules *)tag;
struct stivale2_struct_tag_modules *m = (struct stivale2_struct_tag_modules *)tag; // printf("Modules tag (count: %d):", m->module_count);
printf("MODULES (%d) ", m->module_count); // for (size_t i = 0; i < m->module_count; i++) {
for (size_t i = 0; i < m->module_count; i++) { // struct stivale2_module me = m->modules[i];
struct stivale2_module *me = &m->modules[i]; // printf("\t[%x+%x] %s", me.begin, me.end, me.string);
printf("\t[%x+%x] %s\n", me->begin, me->end, me->string); // }
} // break;
break; // }
} // case STIVALE2_STRUCT_TAG_RSDP_ID: {
case STIVALE2_STRUCT_TAG_RSDP_ID: { // struct stivale2_struct_tag_rsdp *r = (struct stivale2_struct_tag_rsdp *)tag;
struct stivale2_struct_tag_rsdp *r = (struct stivale2_struct_tag_rsdp *)tag; // puts("RSDP tag:");
printf("RSDP (%x) ", r->rsdp); // printf("\tRSDP: %x\n", r->rsdp);
break; // break;
} // }
case STIVALE2_STRUCT_TAG_EPOCH_ID: { // case STIVALE2_STRUCT_TAG_EPOCH_ID: {
struct stivale2_struct_tag_epoch *e = (struct stivale2_struct_tag_epoch *)tag; // struct stivale2_struct_tag_epoch *e = (struct stivale2_struct_tag_epoch *)tag;
set_time(e->epoch); // printf("Epoch: %x", e->epoch);
break; // break;
} // }
case STIVALE2_STRUCT_TAG_FIRMWARE_ID: { // case STIVALE2_STRUCT_TAG_FIRMWARE_ID: {
struct stivale2_struct_tag_firmware *f = (struct stivale2_struct_tag_firmware *)tag; // struct stivale2_struct_tag_firmware *f = (struct stivale2_struct_tag_firmware *)tag;
printf("FW (%x) ", f->flags); // printf("Firmware flags: %x\n", f->flags);
break; // break;
} // }
case STIVALE2_STRUCT_TAG_SMP_ID: { // case STIVALE2_STRUCT_TAG_SMP_ID: {
struct stivale2_struct_tag_smp *s = (struct stivale2_struct_tag_smp *)tag; // struct stivale2_struct_tag_smp *s = (struct stivale2_struct_tag_smp *)tag;
printf("SMP (%d) ", s->cpu_count); // printf("SMP tag (cores: %d, bootstrap: %d, flags: %x)\n", s->cpu_count, s->bsp_lapic_id, s->flags);
break; // for (size_t i = 0; i < s->cpu_count; i++) {
} // struct stivale2_smp_info *in = &s->smp_info[i];
default: // printf("\tProcessor ID: %d\n", in->processor_id);
printf("???"); // printf("\tLAPIC ID: %d\n", in->lapic_id);
} // printf("\tTarget Stack: %x\n", in->target_stack);
// printf("\tGOTO Address: %x\n", in->goto_address);
// printf("\tExtra Argument: %x\n", in->extra_argument);
// }
// break;
// }
// default:
// printf("ERR: Unidentifier tag %x\n", tag->identifier);
// }
tag = (struct stivale2_tag *)tag->next; // tag = (struct stivale2_tag *)tag->next;
} // }
putchar('\n'); // }
}

View File

@ -1,2 +1 @@
void print_stivale2(struct stivale2_struct *info);
void parse_stivale2(struct stivale2_struct *info); void parse_stivale2(struct stivale2_struct *info);

View File

@ -11,7 +11,6 @@ static const size_t VGA_HEIGHT = 25;
static volatile size_t terminal_row; static volatile size_t terminal_row;
static volatile size_t terminal_column; static volatile size_t terminal_column;
static volatile uint8_t current_color = VGA_WHITE; static volatile uint8_t current_color = VGA_WHITE;
static volatile uint8_t bg_color = VGA_BLACK;
static uint16_t *terminal_buffer = (uint16_t*)0xb8000; static uint16_t *terminal_buffer = (uint16_t*)0xb8000;
void putchar(char c) { void putchar(char c) {
@ -28,7 +27,7 @@ void vga_putc(char c) {
return; return;
} }
if(c != '\n' && c != '\t') if(c != '\n' && c != '\t')
terminal_buffer[index] = (uint16_t)c | (uint16_t)(current_color) << 8 | (uint16_t)(bg_color) << 12; terminal_buffer[index] = (uint16_t)c | (uint16_t)(current_color) << 8;
if (c == '\n' || ++terminal_column == VGA_WIDTH) { if (c == '\n' || ++terminal_column == VGA_WIDTH) {
terminal_column = 0; terminal_column = 0;
@ -50,12 +49,3 @@ void vga_write_elsewhere(const char *c, size_t y, size_t x) {
terminal_row=old_row; terminal_row=old_row;
terminal_column=old_column; terminal_column=old_column;
} }
void vga_clear(uint8_t color) {
bg_color = color;
for(size_t i = 0; i < VGA_WIDTH*VGA_HEIGHT; i++) {
terminal_buffer[i] = (uint16_t)(current_color) << 8 | (uint16_t)(bg_color) << 12;
}
terminal_row = 0;
terminal_column = 0;
}

View File

@ -22,4 +22,3 @@ void vga_putc(char c);
void vga_puts(const char *c); void vga_puts(const char *c);
void vga_setcolor(uint8_t color); void vga_setcolor(uint8_t color);
void vga_write_elsewhere(const char *c, size_t y, size_t x); void vga_write_elsewhere(const char *c, size_t y, size_t x);
void vga_clear(uint8_t color);

View File

@ -1 +0,0 @@
const char *arch = "x86_64";

View File

@ -0,0 +1,6 @@
void halt_catch_fire() {
asm volatile ("cli");
while(1) asm volatile ("hlt");
}
const char *arch = "x86_64";

View File

@ -1,39 +0,0 @@
#include "info.h"
struct kornos_boot_info boot_info = {
.cmdline = "",
.usable = {0,0},
.epoch = 0,
.boot_protocol = "",
.bootloader_name = "",
.bootloader_ver = "",
};
bool validate_boot_info() {
return boot_info.cmdline &&
boot_info.usable.len > 0 &&
boot_info.boot_protocol &&
boot_info.bootloader_name &&
boot_info.bootloader_ver;
}
void set_time(uint64_t t) {
boot_info.epoch = t;
}
void set_cmdline(const char *cmd) {
boot_info.cmdline = cmd;
}
void set_boot_info(const char *protocol, const char *name, const char *version) {
boot_info.boot_protocol = protocol;
boot_info.bootloader_name = name;
boot_info.bootloader_ver = version;
}
void set_memregion(size_t start, size_t len) {
if(len > boot_info.usable.len) {
boot_info.usable.start = start;
boot_info.usable.len = len;
}
}

View File

@ -1,37 +0,0 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
extern const char *arch;
struct kornos_memmap_entry {
size_t start;
size_t len;
};
#define KORNOS_FRAMEBUF_TEXT 1
#define KORNOS_FRAMEBUF_RGB 2
struct kornos_framebuf_info {
uint8_t type;
size_t addr;
size_t width;
size_t height;
};
struct kornos_boot_info {
const char *cmdline;
struct kornos_memmap_entry usable;
struct kornos_framebuf_info framebuf;
uint64_t epoch;
const char *boot_protocol;
const char *bootloader_name;
const char *bootloader_ver;
};
extern struct kornos_boot_info boot_info;
bool validate_boot_info();
void set_time(uint64_t);
void set_cmdline(const char *);
void set_boot_info(const char*, const char*, const char*);
void set_memregion(size_t start, size_t len);

View File

@ -1,4 +1,3 @@
void halt_catch_fire(); void halt_catch_fire();
#define PANIC(m) panic(m, __FILE__, __LINE__) extern const char *arch;
void panic(const char *message, const char *filename, int line);

View File

@ -1,17 +1,10 @@
#include "arch/x86/vga.h" #include "arch/x86/vga.h"
#include "hal/ops.h" #include "hal/ops.h"
#include "hal/info.h"
#include "print/print.h" #include "print/print.h"
void kmain() { void kmain(int argc, char **argv) {
if(!validate_boot_info()) {
PANIC("Error: boot_info not entered!");
}
printf("Kernel initialized! Platform: %s\n", arch); printf("Kernel initialized! Platform: %s\n", arch);
printf("Bootloader type: %s (%s %s)\n", boot_info.boot_protocol, boot_info.bootloader_name, boot_info.bootloader_ver); printf("Bootloader type: %s (%s %s)\n", argv[0], argv[1], argv[2]);
printf("System time: %d\n", boot_info.epoch);
printf("Usable memory: %h (at %x)\n", boot_info.usable.len, boot_info.usable.start);
printf("Cmdline: %s", boot_info.cmdline);
vga_setcolor(VGA_DARK_GRAY); vga_setcolor(VGA_DARK_GRAY);
vga_write_elsewhere("(c) Quinten Kock 2020 (MIT License)", 24, 0); vga_write_elsewhere("(c) Quinten Kock 2020 (MIT License)", 24, 0);