kernel: some random modifications

This commit is contained in:
RaphProductions 2025-05-07 22:12:35 +02:00
parent e6a2c1e240
commit 175805604e
17 changed files with 141 additions and 237 deletions

0
kernel/src/fs/vfs.c Normal file
View file

66
kernel/src/fs/vfs.h Normal file
View file

@ -0,0 +1,66 @@
#pragma once
#include <stdint.h>
struct vfs {
struct vfs *vfs_next; /* next vfs in list */
struct vfsops *vfs_op; /* operations on vfs */
struct vnode *vfs_vnodecovered; /* vnode we cover */
int vfs_flag; /* flags */
int vfs_bsize; /* native block size */
uint64_t vfs_data; /* private data */
};
struct vfsops {
int (*vfs_mount)();
int (*vfs_unmount)();
int (*vfs_root)();
int (*vfs_statfs)();
int (*vfs_sync)();
int (*vfs_fid)();
int (*vfs_vget)();
};
enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VBAD };
struct vnode {
uint16_t v_flag; /* vnode flags */
uint16_t v_count; /* reference count */
uint16_t v_shlockc; /* # of shared locks */
uint16_t v_exlockc; /* # of exclusive locks */
struct vfs *v_vfsmountedhere; /* covering vfs */
struct vnodeops *v_op; /* vnode operations */
union {
struct socket *v_Socket; /* unix ipc */
struct stdata *v_Stream; /* stream */
};
struct vfs *v_vfsp; /* vfs we are in */
enum vtype v_type; /* vnode type */
uint64_t v_data; /* private data */
};
struct vnodeops {
int (*vn_open)();
int (*vn_close)();
int (*vn_rdwr)();
int (*vn_ioctl)();
int (*vn_select)();
int (*vn_getattr)();
int (*vn_setattr)();
int (*vn_access)();
int (*vn_lookup)();
int (*vn_create)();
int (*vn_remove)();
int (*vn_link)();
int (*vn_rename)();
int (*vn_mkdir)();
int (*vn_rmdir)();
int (*vn_readdir)();
int (*vn_symlink)();
int (*vn_readlink)();
int (*vn_fsync)();
int (*vn_inactive)();
int (*vn_bmap)();
int (*vn_strategy)();
int (*vn_bread)();
int (*vn_brelse)();
};

View file

@ -80,9 +80,9 @@ char kstack[8192];
// linker script accordingly.
void kmain(void) {
// Ensure the bootloader actually understands our base revision (see spec).
if (LIMINE_BASE_REVISION_SUPPORTED == false) {
/*if (LIMINE_BASE_REVISION_SUPPORTED == false) {
hcf();
}
}*/
// Ensure we got a framebuffer.
if (framebuffer_request.response == NULL
@ -118,11 +118,13 @@ void kmain(void) {
uint8_t *mem = pmm_request_page();
mem[0] = 0xCD;
mem[1] = 0x80;
mem[2] = 0xF4;
//mem[2] = 0xF4;
//mem[3] = 0xFE;
pagemap_t* pm = vmm_alloc_pm();
vmm_map(pm, 0x1000, (uint64_t)mem, VMM_PRESENT | VMM_USER);
sched_process *proc = sched_create("Init", 0x1000, pm, SCHED_USER_PROCESS);
sched_create("Init", 0x1000, pm, SCHED_USER_PROCESS);
log("kernel - Soaplin initialized sucessfully.\n");
while (1)

View file

@ -53,7 +53,7 @@ void rt_print(char *str) {
for (int i = 0; i < _rt_strlen(str); i++) {
if (str[i] == '\n' && _curctx.use_crlf_ending)
if (_curctx.y * 16 >= _curctx.framebuffer_height) {
if (_curctx.y * 16 >= (int)_curctx.framebuffer_height) {
_curctx.y = 0;
memset(
_curctx.framebuffer, _curctx.bg_color,
@ -63,7 +63,7 @@ void rt_print(char *str) {
}
else if (str[i] == '\n')
{
if (_curctx.y * 16 >= _curctx.framebuffer_height) {
if (_curctx.y * 16 >= (int)_curctx.framebuffer_height) {
_curctx.y = 0;
memset(
_curctx.framebuffer, _curctx.bg_color,

View file

@ -56,10 +56,12 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t* pm, uin
if (flags == SCHED_KERNEL_PROCESS) {
proc->stack_base = stack_phys;
proc->stack_base_physical = stack_phys;
proc->stack_end = proc_list->stack_base + PMM_PAGE_SIZE;
} else if (flags == SCHED_USER_PROCESS) {
vmm_map(proc->pm, (uint64_t)stack_virt, (uint64_t)stack_phys, VMM_PRESENT | VMM_WRITABLE | VMM_USER);
proc->stack_base = stack_virt;
proc->stack_base_physical = stack_phys;
proc->stack_end = proc_list->stack_base + PMM_PAGE_SIZE;
}
proc->regs.rip = (uint64_t)entry_point;
@ -91,6 +93,12 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t* pm, uin
return proc;
}
void sched_exit(int exit_code) {
log("sched - Process %d exited with code %d!", curr_proc->pid, exit_code);
curr_proc->type = SCHED_DIED;
schedule(&curr_proc->regs);
}
void schedule(registers_t *regs)
{
if (standby) {
@ -98,6 +106,22 @@ void schedule(registers_t *regs)
return;
}
if (curr_proc->type == SCHED_DIED) {
sched_process *prev_proc = proc_list;
while (prev_proc->next != curr_proc) {
prev_proc = prev_proc->next;
}
prev_proc->next = curr_proc->next;
// Now, it is safe to free the process's memory.
vmm_release_pm(curr_proc->pm);
pmm_free_page(curr_proc->stack_base_physical);
// R.I.P. process
pmm_free_page(curr_proc);
}
memcpy(&curr_proc->regs, regs, sizeof(registers_t));
curr_proc = curr_proc->next;

View file

@ -8,7 +8,7 @@
typedef enum {
SCHED_RUNNING,
SCHED_EXITED,
SCHED_DIED,
SCHED_EMPTY
} sched_proc_type;
@ -23,6 +23,7 @@ typedef struct _sched_process {
uint64_t *stack_end;
uint64_t *stack_base;
uint64_t *stack_base_physical;
struct _sched_process *next;
} sched_process;
@ -36,5 +37,5 @@ extern sched_process *proc_list;
void sched_init();
sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t *pm, uint32_t flags);
void sched_exit(sched_process *proc);
void sched_exit(int exit_code);
void schedule(registers_t *regs);

View file

@ -73,7 +73,8 @@ void exception_handler(registers_t *regs) {
{
log("syscall - Hello World! Current process: %s\n", curr_proc->name);
if (curr_proc->flags == SCHED_USER_PROCESS)
log("syscall - Btw we made it to userspace, baby!\n", curr_proc->name);
log("syscall - Btw we made it to userspace, baby!\n", curr_proc->name);
}
//logln(info, "arch/ints", "Received interrupt %d\n", regs->int_no);
pic_ack(regs->int_no - 32);

View file

@ -21,5 +21,6 @@ void rtc_init() {
}
void rtc_handle_interrupt(registers_t *regs) {
(void)regs;
printf("RTC!\n");
}

View file

@ -0,0 +1,6 @@
#include "sys/arch/x86_64/smp.h"
#include "limine.h"
void smp_init() {
}

View file

@ -0,0 +1,3 @@
#pragma once
void smp_init();

View file

@ -16,14 +16,14 @@ void log(char *format, ...) {
rt_print(buf);
char *date = "1970-01-01 00:00:00 | ";
for (int i;;i++) {
for (int i=0;;i++) {
if (date[i] == '\0')
break;
outb(0xE9, date[i]);
}
for (int i;;i++) {
for (int i=0;;i++) {
if (buf[i] == '\0')
break;