Rename & scheduler stuff

This commit is contained in:
ssimnb 2026-01-24 08:15:08 +01:00
parent 4e40a040dd
commit 0066af13e8
25 changed files with 63 additions and 88 deletions

View file

@ -30,7 +30,7 @@ LDFLAGS += -m elf_x86_64 \
-z text \
-z max-page-size=0x1000 \
-T linker.ld
NASMFLAGS = -f elf64
NASMFLAGS = -f elf64 -g -F dwarf
dependencies:
# build limine
rm -rf limine

View file

@ -1,4 +1,4 @@
# SFB/25
# Neobbo
Hobby operating system for the x86_64 architecture written in C. Licensed under GPLv3
@ -10,12 +10,12 @@ Then run `make all` - make sure to adjust the `CC`, `AS` and `LD` flags to match
in the `build` folder you should have a `SFB25.iso` file.
To try out SFB/25 you can use QEMU:
To try out Neobbo you can use QEMU:
`qemu-system-x86_64 build/SFB25.iso -machine q35 -m 512M`
## External projects
- [Limine bootloader](https://github.com/limine-bootloader/limine) for the bootloader
- [Flanterm](https://github.com/mintsuki/flanterm) for the terminal
- [Flanterm](https://codeberg.org/mintsuki/flanterm) for the terminal
- [uACPI](https://github.com/uacpi/uacpi) for the AML interpreter and other ACPI stuff

View file

@ -2,7 +2,7 @@
timeout: 0
# The entry name that will be displayed in the boot menu.
/SFB/25 (KASLR on)
/Neobbo (KASLR on)
# We use the Limine boot protocol.
protocol: limine
@ -10,7 +10,7 @@ timeout: 0
kernel_path: boot():/SFB25.elf
# Same thing, but without KASLR.
/SFB/25 (KASLR off)
/Neobbo (KASLR off)
# We use the Limine boot protocol.
protocol: limine

View file

@ -1,5 +1,5 @@
#include <SFB25.h>
#include <neobbo.h>
#include <kprint.h>
#include "../hal/apic.h"
#include "../sys/pci.h"

View file

@ -1,6 +1,6 @@
#include "../sys/acpi.h"
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include <io.h>

View file

@ -5,7 +5,7 @@
#include "ioapic.h"
#include <lock.h>
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include <cpuid.h> // GCC specific
#define LAPIC_ID_REG 0x020

View file

@ -3,7 +3,7 @@
#include "timer.h"
#include <kprint.h>
#include <lock.h>
#include <SFB25.h>
#include <neobbo.h>
idt_descriptor idt[256] = {0};
idt_register idtr = {sizeof(idt)-1, (uint64_t)(&idt)};

View file

@ -1,7 +1,7 @@
#include <stdint.h>
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include "../sys/acpi.h"
#include "error.h"

View file

@ -2,7 +2,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include "gdt.h"
#include "smp.h"
#include "apic.h"

View file

@ -4,7 +4,7 @@
#include "../drivers/pmt.h"
#include "timer.h"
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
/* Determines which timer will be used for calibration */
int calibration_timer = -1;

View file

@ -8,7 +8,7 @@ enum {
LOG_SUCCESS,
};
void klog(const char *func, const char *msg);
void klog(const char *func, const char *msg, ...);
int kprintf(const char *format_string, ...);

View file

@ -1,6 +1,7 @@
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <lock.h>
#include "../include/kprint.h"
@ -22,7 +23,7 @@
extern bool serial_enabled;
void klog(const char *func, const char *msg){
void klog(const char *func, const char *msg, ...){
kprintf("{ksk}: {s}\n", ANSI_COLOR_MAGENTA, func, ANSI_COLOR_RESET, msg);
serial_kprintf("{ksk}: {s}\n", ANSI_COLOR_MAGENTA, func, ANSI_COLOR_RESET, msg);

View file

@ -1,6 +1,6 @@
#include <stdint.h>
#include <stddef.h>
#include <SFB25.h>
#include <neobbo.h>
#include <kprint.h>
#include <string.h>
#include "error.h"
@ -78,7 +78,7 @@ void _start(void){
0
);
kprintf("Welcome to SFB/25{n}");
kprintf("Welcome to Neobbo{n}");
extern link_symbol_ptr text_start_addr, text_end_addr;
@ -90,59 +90,22 @@ void _start(void){
klog("acpi", "Reading ACPI tables");
acpi_init();
klog("apic", "Initalizing APIC");
apic_init();
tsc_init();
klog("pmm", "Setting up the PMM");
pmm_init();
klog("vmm", "Setting up the page tables");
vmm_init();
init_page_array();
//struct ma_kcache *cache = ma_cache_create("bird", 1048576, 0, 0, 0);
//uint64_t *d = ma_cache_alloc(cache, 0);
//cache_info(cache);
//memset(d, 0, 1048576);
//for(;;);
//cache_info(cache);
_kmalloc_init();
int *my_int;
for(int i = 0;i < 3000;i++){
my_int = kmalloc(512);
*my_int = rand();
kprintf("my int: {d} on iter: {d}\n", *my_int, i);
kstatus status = kfree(my_int);
if(status != KERNEL_STATUS_SUCCESS){
kprintf("status: {d}\n", status);
}
}
kprintf("my int: {d}\n", *my_int);
//for(;;){}
klog("smp", "Starting APs");
smp_init();
@ -163,6 +126,7 @@ void _start(void){
bool kernel_killed = false;
void kkill(void){
kernel_killed = true;
kprintf("The kernel has been killed.\n");
asm volatile("cli; hlt");
for(;;);
}

View file

@ -26,7 +26,7 @@ size_t sizes[14] = {16, 32, 64, 128, 256, 512, 1024, 4096, 8192, 32768, 65536, 1
void *kmalloc(size_t size){
if(size > 1048576){
klog(__func__, "Attempted to allocate more than max size (1M)");
klog(__func__, "Attempted to allocate {d} bytes, more than max size (1M)");
return NULL;
}

View file

@ -1,7 +1,7 @@
#include "page.h"
#include <limine.h>
#include "vmm.h"
#include <SFB25.h>
#include <neobbo.h>
#include <stdatomic.h>
#include <kprint.h>
#include <stddef.h>

View file

@ -1,6 +1,6 @@
#include <limine.h>
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include <lock.h>
#include "pmm.h"
#include "kmalloc.h"

View file

@ -7,7 +7,7 @@
#include "page.h"
#include "slab.h"
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include <lock.h>
struct ma_kcache *caches = NULL;
@ -414,6 +414,8 @@ kstatus ma_cache_dealloc(void *object){
return KERNEL_STATUS_ERROR;
}
acquire_spinlock(&slab->lock);
struct ma_bufctl *buf = addr_to_bufctl(object);
if(buf == NULL){
@ -432,6 +434,8 @@ kstatus ma_cache_dealloc(void *object){
_ma_move_slab(slab, FREE);
}
free_spinlock(&slab->lock);
return KERNEL_STATUS_SUCCESS;
}

View file

@ -21,6 +21,8 @@ struct ma_slab {
uint32_t refcount; // The amount of active (not free) objects in the slabs
atomic_flag lock;
struct ma_bufctl *free; // Linked list of free buffers in the slab. Is equal to NULL once there are no more free objects
};

View file

@ -2,7 +2,7 @@
#include <stdatomic.h>
#include <stdint.h>
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include <string.h>
#include <limine.h>
#include "pmm.h"

View file

@ -1,6 +1,7 @@
global switch_context
global get_context
global restore_stack
; switch_context(struct context *old, struct context *new)
; ^RDI ^RSI
@ -31,6 +32,8 @@ switch_context:
jmp [rsi + 0x38]
ret
@ -51,3 +54,8 @@ get_context:
push r8
ret
; restore_stack(uint64_t rsp, uint64_t rbp)
restore_stack:
mov rsp, rdi
mov rbp, rsi
ret

View file

@ -1,21 +1,24 @@
#include <kprint.h>
#include <stdint.h>
#include <string.h>
#include <SFB25.h>
#include <neobbo.h>
#include "../hal/smp.h"
#include <error.h>
#include "../mm/kmalloc.h"
#include "sched.h"
extern context *save_context();
extern void get_context(struct context *ctx);
extern void switch_context(context *old, context *new);
extern void restore_stack(uint64_t rsp, uint64_t rbp);
#define QUANTUM_US 10000
int next_pid = 1;
void idle_task(){
kprintf("Hello world from bruhd task!\n");
kprintf("Hello world from idle task!\n");
}
void test_task(){
@ -32,32 +35,22 @@ proc *alloc_process(void){
proc *p = &proc_list[i];
p->state = READY;
kprintf("pstate = 0x{x}\n", READY);
kprintf("actual: 0x{x}\n", p->state);
p->kstack = kmalloc(INITIAL_STACK_SIZE);
kprintf("actua1l: 0x{x}\n", p->state);
p->pid = next_pid++;
kprintf("actua2l: 0x{x}\n", p->state);
memset(&p->context, 0, sizeof(context));
kprintf("actua3l: 0x{x}\n", p->state);
p->context.rbp = (uint64_t)p->kstack;
p->context.rsp = (uint64_t)p->context.rbp + INITIAL_STACK_SIZE;
kprintf("actua4l: 0x{x}\n", p->state);
return p;
}
}
kprintf("Couldn't find free process!");
klog(__func__, "Couldnt find free process!!!!!!\n");
}
kstatus add_task(uint64_t *entry){
proc *add_task(uint64_t *entry){
proc *proc = alloc_process();
if (proc == NULL) {
@ -67,7 +60,7 @@ kstatus add_task(uint64_t *entry){
proc->context.rip = (uint64_t)entry;
return KERNEL_STATUS_SUCCESS;
return proc;
}
void scheduler_init(){
@ -83,27 +76,32 @@ void scheduler_init(){
kkill();
}
kprintf("hi1\n");
proc *proc_list = state->process_list;
memset(proc_list, 0, sizeof(proc) * 512);
int pid = add_task((uint64_t*)idle_task);
proc *idle = add_task((uint64_t*)idle_task);
if(idle == NULL){
klog(__func__, "Failed to allocate idle task");
kkill();
}
state->current_process = idle;
add_task((uint64_t*)test_task);
for(;;){
for(int i = 0; i < PROC_MAX; i++){
if(proc_list[i].state == READY){
kprintf("Hell yeah");
context old_state = state->current_process->context;
state->current_process = &proc_list[i];
state->current_process->state = RUNNING;
get_context(&state->scheduler_context);
switch_context(&old_state, &state->current_process->context);
}
}
}
@ -112,8 +110,6 @@ void scheduler_init(){
void scheduler_tick(){
cpu_state *state = get_cpu_struct();
proc *proc_list = state->process_list;
switch_context(&state->current_process->context, &state->scheduler_context);
}

View file

@ -1,7 +1,7 @@
#include <limine.h>
#include <stddef.h>
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include <string.h>
#include <stdalign.h>
#include "acpi.h"

View file

@ -1,4 +1,4 @@
#include <SFB25.h>
#include <neobbo.h>
#include <kprint.h>
#include <string.h>
#include <lock.h>

View file

@ -4,7 +4,7 @@
#include "mm/kmalloc.h"
#include <limine.h>
#include <kprint.h>
#include <SFB25.h>
#include <neobbo.h>
#include <io.h>
uacpi_status uacpi_kernel_get_rsdp(uacpi_phys_addr *out_rsdp_address){