Archived
1
Fork 0

Shuffle around directories

This commit is contained in:
Joshua Goins 2022-06-06 22:06:43 -04:00
parent e50fb45ed5
commit 35e1d79fd6
8 changed files with 86 additions and 63 deletions

View file

@ -2,13 +2,21 @@
This is my custom kernel for learning purposes. I'm not a osdev at all, so please excuse the mess.
Right now it compiles for x86_64, 32-bit is not supported. Most of this is just skeleton code from osdev.org, but I cleaned
Right now it compiles for `x86_64`, 32-bit is not supported. Most of this is just skeleton code from osdev.org, but I cleaned
some stuff. I use Stivale for higher half kernel loading and not having to gaff about a bootloader for now. Limine is included
as my bootloader of choice.
## Organization
This file organization is definitely not final, and will be shuffled around as sen is developed. Currently it is:
* `src/` - All of the source files for sen, including ld configs etc.
* `boot/` - Bootloader-related sources and entrypoints.
* `drivers/` - Drivers for specific subsystems in the kernel, such as tty drivers.
* `kernel/` - Vendor-agnostic stuff like the actual loop, the startup sequence, etc. This also contains the public kernel interface.
## Building
Currently it requires GNU make, and some version of GCC. If you wish to build the iso, you also need xorriso.
Currently, sen requires GNU make, and some version of GCC. If you wish to build the iso, you also need xorriso.
Run make to build the elf:

View file

@ -1,6 +1,5 @@
#include <stdint.h>
#include <stddef.h>
#include <stivale2.h>
#include <boot/stivale/stivale.h>
#include <kernel/kernel.h>
// We need to tell the stivale bootloader where we want our stack to be.
// We are going to allocate our stack as an array in .bss.
@ -76,45 +75,12 @@ static struct stivale2_header stivale_hdr = {
// points to the first one in the linked list.
.tags = (uintptr_t)&framebuffer_hdr_tag
};
// We will now write a helper function which will allow us to scan for tags
// that we want FROM the bootloader (structure tags).
void *stivale2_get_tag(struct stivale2_struct *stivale2_struct, uint64_t id) {
struct stivale2_tag *current_tag = (void *)stivale2_struct->tags;
for (;;) {
// If the tag pointer is NULL (end of linked list), we did not find
// the tag. Return NULL to signal this.
if (current_tag == NULL) {
return NULL;
}
// Check whether the identifier matches. If it does, return a pointer
// to the matching tag.
if (current_tag->identifier == id) {
return current_tag;
}
// Get a pointer to the next tag in the linked list and repeat.
current_tag = (void *)current_tag->next;
}
}
struct stivale2_struct_tag_terminal *term_str_tag = NULL;
void *term_write_ptr = NULL;
void (*term_write)(const char *string, size_t length) = NULL;
struct stivale2_struct *stivale2_struct;
// The following will be our kernel's entry point.
void _start(struct stivale2_struct *stivale2_struct) {
// Let's get the terminal structure tag from the bootloader.
term_str_tag = stivale2_get_tag(stivale2_struct, STIVALE2_STRUCT_TAG_TERMINAL_ID);
// Check if the tag was actually found.
if (term_str_tag == NULL) {
// It wasn't found, just hang...
for (;;) {
asm ("hlt");
}
}
void _start(struct stivale2_struct *in) {
stivale2_struct = in;
kernel_main();
@ -122,19 +88,4 @@ void _start(struct stivale2_struct *stivale2_struct) {
for (;;) {
asm ("hlt");
}
}
void terminal_initialize() {
// stub for stivale
// Let's get the address of the terminal write function.
term_write_ptr = (void *)term_str_tag->term_write;
// Now, let's assign this pointer to a function pointer which
// matches the prototype described in the stivale2 specification for
// the stivale2_term_write function.
term_write = term_write_ptr;
}
void tty_print(const char* str, int length) {
term_write(str, length);
}
}

View file

@ -0,0 +1,10 @@
#ifndef _BOOT_STIVALE_H
#define _BOOT_STIVALE_H
#include <stdint.h>
#include <stddef.h>
#include <stivale2.h>
extern struct stivale2_struct *stivale2_struct;
#endif

49
src/drivers/tty/stivale.c Normal file
View file

@ -0,0 +1,49 @@
#include <boot/stivale/stivale.h>
#include <kernel/tty/tty.h>
// We will now write a helper function which will allow us to scan for tags
// that we want FROM the bootloader (structure tags).
void *stivale2_get_tag(struct stivale2_struct *stivale2_struct, uint64_t id) {
struct stivale2_tag *current_tag = (void *)stivale2_struct->tags;
for (;;) {
// If the tag pointer is NULL (end of linked list), we did not find
// the tag. Return NULL to signal this.
if (current_tag == NULL) {
return NULL;
}
// Check whether the identifier matches. If it does, return a pointer
// to the matching tag.
if (current_tag->identifier == id) {
return current_tag;
}
// Get a pointer to the next tag in the linked list and repeat.
current_tag = (void *)current_tag->next;
}
}
struct stivale2_struct_tag_terminal *terminal_tag = NULL;
// stivale function stubs
void (*term_write)(const char *string, size_t length) = NULL;
// for this driver we simply load all the function pointers from the terminal tag
void terminal_initialize() {
terminal_tag = stivale2_get_tag(stivale2_struct, STIVALE2_STRUCT_TAG_TERMINAL_ID);
// Check if the tag was actually found.
if (terminal_tag == NULL) {
// It wasn't found, just hang...
for (;;) {
asm ("hlt");
}
}
// the address from this struct is uint64, so we must convert to a pointer
term_write = (void *)terminal_tag->term_write;
}
void tty_print(const char* str, int length) {
term_write(str, length);
}

View file

@ -1,6 +0,0 @@
#include <tty.h>
void kernel_main(void) {
terminal_initialize();
tty_print("Hello, world!", 12);
}

9
src/kernel/kernel.c Normal file
View file

@ -0,0 +1,9 @@
#include <kernel/kernel.h>
#include <kernel/tty/tty.h>
void kernel_main(void) {
// initialize subsystems, currently only tty
terminal_initialize();
tty_print("Loading sen...", 15);
}

2
src/kernel/kernel.h Normal file
View file

@ -0,0 +1,2 @@
// this is the main kernel entrypoint
void kernel_main(void);