This commit is contained in:
Nicholas Orlowsky 2025-02-28 21:25:17 -05:00
parent ce2b373313
commit 9114529153
46 changed files with 126016 additions and 125522 deletions

9
arch/i386/asm/asm.c Normal file
View file

@ -0,0 +1,9 @@
#include "asm.h"
void __sl_acquire(uint32_t *lock_id) {
__asm__("retry_lock: lock bts $0,(%0); pause; jc retry_lock" : "+g"(lock_id));
}
void __sl_release(uint32_t *lock_id) {
__asm__("lock btr $0, (%0)" : "+g"(lock_id));
}

View file

@ -9,13 +9,8 @@ struct regs {
unsigned int eip, cs, eflags, useresp, ss;
};
void __sl_acquire(uint32_t *lock_id) {
__asm__("retry_lock: lock bts $0,(%0); pause; jc retry_lock" : "+g"(lock_id));
}
void __sl_release(uint32_t *lock_id) {
__asm__("lock btr $0, (%0)" : "+g"(lock_id));
}
void __sl_acquire(uint32_t *);
void __sl_release(uint32_t *);
static inline void outb(int port, int val) {
__asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
@ -37,6 +32,16 @@ static inline uint32_t inl(uint32_t port) {
return val;
}
static inline void outw(uint16_t port, uint16_t val) {
__asm__ volatile("outw %w0, %w1" : : "a"(val), "Nd"(port) : "memory");
}
static inline uint16_t inw(uint16_t port) {
uint32_t val;
__asm__ volatile("inw %w1, %w0" : "=a"(val) : "Nd"(port) : "memory");
return val;
}
static inline void interrupt_disable() { __asm__ volatile("cli"); }
static inline void interrupt_enable() { __asm__ volatile("sti"); }

View file

@ -1,15 +1,15 @@
#pragma once
#include "../../kernel/memory.c"
#include "../../kernel/memory/memory.h"
#include <stdint.h>
struct gdt_row_t {
uint16_t limit_low;
uint16_t base_low;
uint8_t base_middle;
uint8_t access;
uint8_t granularity_limit_high;
uint8_t base_high;
uint8_t base_middle;
uint8_t access;
uint8_t granularity_limit_high;
uint8_t base_high;
} __attribute__((packed));
struct gdt_ptr_t {

View file

@ -1,14 +1,14 @@
#pragma once
#include "../../kernel/memory.c"
#include "../../kernel/memory/memory.h"
#include "./handlers.h"
#include "gdt.c"
struct idt_row_t {
uint16_t base_lo;
uint16_t sel;
uint8_t unset;
uint8_t flags;
uint8_t unset;
uint8_t flags;
uint16_t base_hi;
} __attribute__((packed));
@ -26,7 +26,8 @@ enum idt_flag_t {
IDTFLAG_INTERRUPT = 0b00001110,
};
#define KERNEL_INTERRUPT_FLAG (IDTFLAG_PRESENT | IDTFLAG_DPL_KERNEL | IDTFLAG_INTERRUPT)
#define KERNEL_INTERRUPT_FLAG \
(IDTFLAG_PRESENT | IDTFLAG_DPL_KERNEL | IDTFLAG_INTERRUPT)
#define USER_TRAP_FLAG (IDTFLAG_PRESENT | IDTFLAG_DPL_USER | IDTFLAG_INTERRUPT)
#define IDT_SIZE (256)

View file

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "./gdt.c"
#include "./idt.c"

View file

@ -1,8 +1,8 @@
#pragma once
#include "../../kernel/ps2.c"
#include "../../kernel/syscall.c"
#include "./asm.c"
#include "../../kernel/drivers/ps2/ps2.h"
#include "../../kernel/syscall/syscall.h"
#include "./asm/asm.c"
#include "./idt.c"
#include "handlers.h"
@ -79,11 +79,11 @@ void irq_handler(struct regs *r) {
};
}
// Send EOI to follower controller
// Send EOI to follower controller
if (r->int_no >= 40 && r->int_no < 48) {
outb(0xA0, 0x20);
}
// Send EOI to leader controller
// Send EOI to leader controller
outb(0x20, 0x20);
}

View file

@ -1,13 +1,4 @@
#pragma once
#include "asm.c"
enum eflags_t {
EFLAG_CARRY = 0x0001,
EFLAG_RES = 0x0002,
EFLAG_PARITY = 0x0004,
EFLAG_INTERRUPT = 0x0200
};
#include "scheduler.h"
void initialize_registers(struct regs *new_regs, char *entrypoint,
uint32_t address_base, uint32_t address_space_size) {

View file

@ -0,0 +1,15 @@
#pragma once
#include "../asm/asm.h"
#include <stdint.h>
enum eflags_t {
EFLAG_CARRY = 0x0001,
EFLAG_RES = 0x0002,
EFLAG_PARITY = 0x0004,
EFLAG_INTERRUPT = 0x0200
};
void initialize_registers(struct regs *, char *, uint32_t, uint32_t);
void store_registers(struct regs *, struct regs *);
void switch_context(struct regs *, struct regs *);