kernel - various changes
+ vmm: higher half should not be identify-mapped + panic: now displays current process + kernel: fix physical addresses (ḑ̷̩̜̦̥̰͔̻͔̖͎̳̗̫̓̓͊́̒͜ơ̸͙͎̠͎̩̤̭̬̙͚̬̣͇̤̼̑̐̿̿͆͠͝ ̷̗̟̘͎̥̤̭̂͛͆́͂͝͠ͅN̴̨̛̥̩̺͚̺̠͙̼̙̯̱͚̫̊̐̅̀̌̏͆̋̕͜͝͠ͅö̵̪͚̞̞̜͎͉̦́́̍̀̃̋̇̄̓͊̎͝t̶̡͍̩̤̹̤̂̑̓͌͂̾̑̈́͒̾̾́͐͆͊͂ ̴̨̫̺̦̊̍̒͛͌̌͂͘̚̚͘͘͝I̶̥͚̯̖̙̩͂́͜d̸̢̡̗͉̠̹̒͠e̸̡̪̺͎͖͚̗̟̟̥͍͑̈̋̉̋̓̐̊̚͘͜n̸̡̍͐͗̈͌̀̓̃́́͠t̶̢͈͈̦̻̰͎̪̰̒̄͒̃̐͜ĩ̴͕̼̻͓͚͕̲̬̤͈̜̣̐̍́̾̀̏̏̑͒̚ͅf̷̡̨̼̻̠̠͔̪͍͛y̴͉͓̓͒̆̎̚ ̶̟͙͖̙̟͍̟͕̞̥̹͇̌̉́̑͗͋̀̕ͅͅM̷͙̬̲̓a̶̫̰̞̺̖̍̀p̶̡̨̡̗̖̹̩̫̯̞̬͋͂̏̍̾̽͜ͅ ̶̧̨̧̫͉̝̮̳͎͍̱̟̪̝̀̽͑̂̿̄̈̇̓͘Ḫ̶̨̨̗̣̪͓̺͙͈͙̀ḭ̶̧̡͇̹͙̩͍͎̮̤̦̜̻͎̞̔̐̇̉̓͒͛̅̿͊̍͆͘̕g̷͖͙͍͓̯̪̩̑̑͋̈́͌͐̊̀͝͠͝ĥ̴̢̡̫̪̟̞̭̟͕̖͎͊͑͛̆͝e̴̡̨̗̱̱͙͔̻̤͎͆̒̾̾̓̈͊̓ͅr̵̛͈̩͍̔̌̃̇͊̽̀̉̽̊͌̿́ ̷̨̡̛̩̹̹̇̇̈́̑̍̊͒̄́͛H̷̨̪̜̤͍̻͎̲̜͋́̆͋̂̚͘͘͜͠ą̷̠͓̫̲́́̽̉̒͌́̓ͅl̴̢̛͈̤̺̱̙̬̆̎̄̊̈́̐̾̏̿̕f̸̢̰͓̦̺̰̯͚̣̙͔̺̂͜͜)
This commit is contained in:
parent
a8e919b033
commit
b2ec036055
32 changed files with 265 additions and 265 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@
|
||||||
*.iso
|
*.iso
|
||||||
*.hdd
|
*.hdd
|
||||||
/compile_commands.json
|
/compile_commands.json
|
||||||
|
/.idea
|
|
@ -1,11 +1,11 @@
|
||||||
// #include "sys/log.h"
|
// #include "sys/log.h"
|
||||||
|
#include "arch/x86_64/smp.h"
|
||||||
#include "dev/ioapic.h"
|
#include "dev/ioapic.h"
|
||||||
#include "dev/lapic.h"
|
#include "dev/lapic.h"
|
||||||
#include "mm/vmm.h"
|
#include "mm/vmm.h"
|
||||||
#include "arch/x86_64/smp.h"
|
|
||||||
#include "sys/errhnd/panic.h"
|
#include "sys/errhnd/panic.h"
|
||||||
|
#include <arch/x86_64/idt.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <arch//x86_64/idt.h>
|
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
|
|
||||||
__attribute__((aligned(0x10))) static idt_entry_t idt[256];
|
__attribute__((aligned(0x10))) static idt_entry_t idt[256];
|
||||||
|
@ -50,9 +50,9 @@ void idt_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not use the legacy PIC.
|
// Do not use the legacy PIC.
|
||||||
//pic_init();
|
// pic_init();
|
||||||
//pic_unmask_irq(1);
|
// pic_unmask_irq(1);
|
||||||
//pic_unmask_irq(8);
|
// pic_unmask_irq(8);
|
||||||
|
|
||||||
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
|
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
|
||||||
__asm__ volatile("sti"); // set the interrupt flag
|
__asm__ volatile("sti"); // set the interrupt flag
|
||||||
|
@ -60,10 +60,9 @@ void idt_init() {
|
||||||
log("idt - initialized\n");
|
log("idt - initialized\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void idt_int_handler(registers_t *regs) {
|
void idt_int_handler(registers_t *regs) {
|
||||||
vmm_load_pagemap(vmm_kernel_pm);
|
vmm_load_pagemap(vmm_kernel_pm);
|
||||||
//log("kernel - Interrupt %d\n", regs->int_no);
|
// log("kernel - Interrupt %d\n", regs->int_no);
|
||||||
|
|
||||||
if (regs->int_no < 32) {
|
if (regs->int_no < 32) {
|
||||||
panic_ctx("A CPU exception occured.", regs);
|
panic_ctx("A CPU exception occured.", regs);
|
||||||
|
@ -79,5 +78,5 @@ void idt_int_handler(registers_t *regs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lapic_eoi();
|
lapic_eoi();
|
||||||
//pic_ack(regs->int_no - 32);
|
// pic_ack(regs->int_no - 32);
|
||||||
}
|
}
|
|
@ -55,7 +55,7 @@ typedef struct {
|
||||||
uint64_t base;
|
uint64_t base;
|
||||||
} __attribute__((packed)) idtr_t;
|
} __attribute__((packed)) idtr_t;
|
||||||
|
|
||||||
typedef void(*idt_irq_handler_t)(registers_t *regs);
|
typedef void (*idt_irq_handler_t)(registers_t *regs);
|
||||||
|
|
||||||
void idt_register_irq(uint8_t vector, void *isr);
|
void idt_register_irq(uint8_t vector, void *isr);
|
||||||
void idt_set_descriptor(uint8_t vector, void *isr, uint8_t flags);
|
void idt_set_descriptor(uint8_t vector, void *isr, uint8_t flags);
|
||||||
|
|
|
@ -5,24 +5,14 @@
|
||||||
#define IA32_GS_MSR 0xC0000101
|
#define IA32_GS_MSR 0xC0000101
|
||||||
#define IA32_GS_KERNEL_MSR 0xC0000102
|
#define IA32_GS_KERNEL_MSR 0xC0000102
|
||||||
|
|
||||||
static inline void wrmsr(uint64_t msr, uint64_t value)
|
static inline void wrmsr(uint64_t msr, uint64_t value) {
|
||||||
{
|
|
||||||
uint32_t low = value & 0xFFFFFFFF;
|
uint32_t low = value & 0xFFFFFFFF;
|
||||||
uint32_t high = value >> 32;
|
uint32_t high = value >> 32;
|
||||||
asm volatile (
|
asm volatile("wrmsr" : : "c"(msr), "a"(low), "d"(high));
|
||||||
"wrmsr"
|
|
||||||
:
|
|
||||||
: "c"(msr), "a"(low), "d"(high)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t rdmsr(uint64_t msr)
|
static inline uint64_t rdmsr(uint64_t msr) {
|
||||||
{
|
|
||||||
uint32_t low, high;
|
uint32_t low, high;
|
||||||
asm volatile (
|
asm volatile("rdmsr" : "=a"(low), "=d"(high) : "c"(msr));
|
||||||
"rdmsr"
|
|
||||||
: "=a"(low), "=d"(high)
|
|
||||||
: "c"(msr)
|
|
||||||
);
|
|
||||||
return ((uint64_t)high << 32) | low;
|
return ((uint64_t)high << 32) | low;
|
||||||
}
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
#include "arch//x86_64/idt.h"
|
#include "arch/x86_64/idt.h"
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
|
#include <arch/x86_64/idt.h>
|
||||||
|
#include <arch/x86_64/pit.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <arch//x86_64/idt.h>
|
|
||||||
#include <arch//x86_64/pit.h>
|
|
||||||
|
|
||||||
uint32_t tick = 0;
|
uint32_t tick = 0;
|
||||||
|
|
||||||
void pit_handler(registers_t *regs) {
|
void pit_handler(registers_t *regs) {
|
||||||
//log("PIT");
|
// log("PIT");
|
||||||
tick++;
|
tick++;
|
||||||
schedule(regs);
|
schedule(regs);
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,13 @@ void pit_init() {
|
||||||
uint16_t div = (uint16_t)(1193180 / 1000);
|
uint16_t div = (uint16_t)(1193180 / 1000);
|
||||||
outb(0x40, (uint8_t)div);
|
outb(0x40, (uint8_t)div);
|
||||||
outb(0x40, (uint8_t)(div >> 8));
|
outb(0x40, (uint8_t)(div >> 8));
|
||||||
idt_register_irq(0, pit_handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pit_enable() { idt_register_irq(0, pit_handler); }
|
||||||
|
|
||||||
void pit_sleep(uint32_t ms) {
|
void pit_sleep(uint32_t ms) {
|
||||||
uint64_t start = tick;
|
uint64_t start = tick;
|
||||||
while (tick - start < ms) {
|
while (tick - start < ms) {
|
||||||
__asm__ volatile ("nop");
|
__asm__ volatile("nop");
|
||||||
}
|
}
|
||||||
}
|
}
|
3
kernel/src/arch/x86_64/pit.h
Executable file → Normal file
3
kernel/src/arch/x86_64/pit.h
Executable file → Normal file
|
@ -1,12 +1,13 @@
|
||||||
#ifndef PIT_H
|
#ifndef PIT_H
|
||||||
#define PIT_H
|
#define PIT_H
|
||||||
|
|
||||||
|
#include <arch/x86_64/io.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <arch//x86_64/io.h>
|
|
||||||
|
|
||||||
extern uint32_t tick;
|
extern uint32_t tick;
|
||||||
|
|
||||||
void pit_init();
|
void pit_init();
|
||||||
void pit_sleep(uint32_t ms);
|
void pit_sleep(uint32_t ms);
|
||||||
|
void pit_enable();
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,29 +1,30 @@
|
||||||
#include "arch//x86_64/smp.h"
|
#include "arch/x86_64/smp.h"
|
||||||
#include "lib/spinlock.h"
|
#include "lib/spinlock.h"
|
||||||
#include "sys/log.h"
|
|
||||||
#include "limine.h"
|
#include "limine.h"
|
||||||
|
#include "sys/log.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
__attribute__((
|
__attribute__((
|
||||||
used,
|
used, section(".limine_requests"))) static volatile struct limine_mp_request
|
||||||
section(".limine_requests"))) static volatile struct limine_mp_request
|
|
||||||
smp_request = {.id = LIMINE_MP_REQUEST, .revision = 0};
|
smp_request = {.id = LIMINE_MP_REQUEST, .revision = 0};
|
||||||
|
|
||||||
uint32_t bootstrap_lapic_id = 0;
|
uint32_t bootstrap_lapic_id = 0;
|
||||||
uint32_t smp_cpu_count = 0; // Number of processors
|
uint32_t smp_cpu_count = 0; // Number of processors
|
||||||
spinlock_t smp_lock = { 0 };
|
spinlock_t smp_lock = {0};
|
||||||
|
|
||||||
uint32_t ctr = 0;
|
uint32_t ctr = 0;
|
||||||
|
|
||||||
void smp_entry(struct limine_mp_info* smp_info) {
|
void smp_entry(struct limine_mp_info *smp_info) {
|
||||||
//spinlock_acquire(&smp_lock);
|
// spinlock_acquire(&smp_lock);
|
||||||
|
|
||||||
log("smp - CPU %d started (LAPIC ID: %d)\n", smp_info->processor_id, smp_info->lapic_id);
|
log("smp - CPU %d started (LAPIC ID: %d)\n", smp_info->processor_id,
|
||||||
|
smp_info->lapic_id);
|
||||||
__atomic_fetch_add(&ctr, 1, __ATOMIC_SEQ_CST);
|
__atomic_fetch_add(&ctr, 1, __ATOMIC_SEQ_CST);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
;;
|
;
|
||||||
//spinlock_release(&smp_lock);
|
;
|
||||||
|
// spinlock_release(&smp_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void smp_init() {
|
void smp_init() {
|
||||||
|
@ -36,12 +37,14 @@ void smp_init() {
|
||||||
if (smp_request.response->cpus[i]->lapic_id != bootstrap_lapic_id) {
|
if (smp_request.response->cpus[i]->lapic_id != bootstrap_lapic_id) {
|
||||||
uint32_t old_ctr = __atomic_load_n(&ctr, __ATOMIC_SEQ_CST);
|
uint32_t old_ctr = __atomic_load_n(&ctr, __ATOMIC_SEQ_CST);
|
||||||
|
|
||||||
__atomic_store_n(&smp_request.response->cpus[i]->goto_address, smp_entry, __ATOMIC_SEQ_CST);
|
__atomic_store_n(&smp_request.response->cpus[i]->goto_address, smp_entry,
|
||||||
|
__ATOMIC_SEQ_CST);
|
||||||
|
|
||||||
while (__atomic_load_n(&ctr, __ATOMIC_SEQ_CST) == old_ctr)
|
while (__atomic_load_n(&ctr, __ATOMIC_SEQ_CST) == old_ctr)
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
log("smp - CPU %d is the bootstrap processor (LAPIC ID: %d)\n", i, smp_request.response->cpus[i]->lapic_id);
|
log("smp - CPU %d is the bootstrap processor (LAPIC ID: %d)\n", i,
|
||||||
|
smp_request.response->cpus[i]->lapic_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <arch//x86_64/sse.h>
|
#include <arch/x86_64/sse.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <sys/printf.h>
|
#include <sys/printf.h>
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ void __x86_64_syscall_init() {
|
||||||
wrmsr(IA32_EFER, efer);
|
wrmsr(IA32_EFER, efer);
|
||||||
uint64_t star = 0;
|
uint64_t star = 0;
|
||||||
star |= ((uint64_t)0x28 << 32); // kernel cs
|
star |= ((uint64_t)0x28 << 32); // kernel cs
|
||||||
star |= ((uint64_t)0x30 << 48); // user cs base (SYSCALL adds 16 for CS=0x38, 24 for SS=0x40)
|
star |= ((uint64_t)0x30
|
||||||
|
<< 48); // user cs base (SYSCALL adds 16 for CS=0x38, 24 for SS=0x40)
|
||||||
wrmsr(IA32_STAR, star);
|
wrmsr(IA32_STAR, star);
|
||||||
wrmsr(IA32_LSTAR, (uint64_t)syscall_entry);
|
wrmsr(IA32_LSTAR, (uint64_t)syscall_entry);
|
||||||
wrmsr(IA32_CSTAR, 0x0);
|
wrmsr(IA32_CSTAR, 0x0);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "sys/acpi/madt.h"
|
#include "sys/acpi/madt.h"
|
||||||
#include <dev/ioapic.h>
|
#include <dev/ioapic.h>
|
||||||
#include <sys/log.h>
|
|
||||||
#include <mm/pmm.h>
|
#include <mm/pmm.h>
|
||||||
|
#include <sys/log.h>
|
||||||
|
|
||||||
void ioapic_init() {
|
void ioapic_init() {
|
||||||
madt_ioapic* ioapic = acpi_madt_ioapic_list[0];
|
madt_ioapic *ioapic = acpi_madt_ioapic_list[0];
|
||||||
|
|
||||||
uint32_t val = ioapic_read(ioapic, IOAPIC_VER);
|
uint32_t val = ioapic_read(ioapic, IOAPIC_VER);
|
||||||
uint32_t count = ((val >> 16) & 0xFF);
|
uint32_t count = ((val >> 16) & 0xFF);
|
||||||
|
@ -14,44 +14,49 @@ void ioapic_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i <= count; ++i) {
|
for (uint8_t i = 0; i <= count; ++i) {
|
||||||
ioapic_write(ioapic, IOAPIC_REDTBL+2*i, 0x00010000 | (32 + i));
|
ioapic_write(ioapic, IOAPIC_REDTBL + 2 * i, 0x00010000 | (32 + i));
|
||||||
ioapic_write(ioapic, IOAPIC_REDTBL+2*i+1, 0);
|
ioapic_write(ioapic, IOAPIC_REDTBL + 2 * i + 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
log("ioapic - initialized\n");
|
log("ioapic - initialized\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioapic_write(madt_ioapic* ioapic, uint8_t reg, uint32_t val) {
|
void ioapic_write(madt_ioapic *ioapic, uint8_t reg, uint32_t val) {
|
||||||
*((volatile uint32_t*)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_REGSEL)) = reg;
|
*((volatile uint32_t *)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_REGSEL)) =
|
||||||
*((volatile uint32_t*)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_IOWIN)) = val;
|
reg;
|
||||||
|
*((volatile uint32_t *)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_IOWIN)) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ioapic_read(madt_ioapic* ioapic, uint8_t reg) {
|
uint32_t ioapic_read(madt_ioapic *ioapic, uint8_t reg) {
|
||||||
*((volatile uint32_t*)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_REGSEL)) = reg;
|
*((volatile uint32_t *)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_REGSEL)) =
|
||||||
return *((volatile uint32_t*)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_IOWIN));
|
reg;
|
||||||
|
return *(
|
||||||
|
(volatile uint32_t *)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_IOWIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioapic_set_entry(madt_ioapic* ioapic, uint8_t idx, uint64_t data) {
|
void ioapic_set_entry(madt_ioapic *ioapic, uint8_t idx, uint64_t data) {
|
||||||
ioapic_write(ioapic, (uint8_t)(IOAPIC_REDTBL + idx * 2), (uint32_t)data);
|
ioapic_write(ioapic, (uint8_t)(IOAPIC_REDTBL + idx * 2), (uint32_t)data);
|
||||||
ioapic_write(ioapic, (uint8_t)(IOAPIC_REDTBL + idx * 2 + 1), (uint32_t)(data >> 32));
|
ioapic_write(ioapic, (uint8_t)(IOAPIC_REDTBL + idx * 2 + 1),
|
||||||
|
(uint32_t)(data >> 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t ioapic_gsi_count(madt_ioapic *ioapic) {
|
||||||
uint64_t ioapic_gsi_count(madt_ioapic* ioapic) {
|
|
||||||
return (ioapic_read(ioapic, 1) & 0xff0000) >> 16;
|
return (ioapic_read(ioapic, 1) & 0xff0000) >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
madt_ioapic* ioapic_get_gsi(uint32_t gsi) {
|
madt_ioapic *ioapic_get_gsi(uint32_t gsi) {
|
||||||
for (uint64_t i = 0; i < acpi_madt_ioapic_length; i++) {
|
for (uint64_t i = 0; i < acpi_madt_ioapic_length; i++) {
|
||||||
madt_ioapic* ioapic = acpi_madt_ioapic_list[i];
|
madt_ioapic *ioapic = acpi_madt_ioapic_list[i];
|
||||||
if (ioapic->gsi_base <= gsi && ioapic->gsi_base + ioapic_gsi_count(ioapic) > gsi)
|
if (ioapic->gsi_base <= gsi &&
|
||||||
|
ioapic->gsi_base + ioapic_gsi_count(ioapic) > gsi)
|
||||||
return ioapic;
|
return ioapic;
|
||||||
}
|
}
|
||||||
return (madt_ioapic*)0;
|
return (madt_ioapic *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioapic_redirect_gsi(uint32_t lapic_id, uint8_t vec, uint32_t gsi, uint16_t flags, bool mask) {
|
void ioapic_redirect_gsi(uint32_t lapic_id, uint8_t vec, uint32_t gsi,
|
||||||
madt_ioapic* ioapic = ioapic_get_gsi(gsi);
|
uint16_t flags, bool mask) {
|
||||||
|
madt_ioapic *ioapic = ioapic_get_gsi(gsi);
|
||||||
|
|
||||||
uint64_t redirect = vec;
|
uint64_t redirect = vec;
|
||||||
|
|
||||||
|
@ -63,8 +68,10 @@ void ioapic_redirect_gsi(uint32_t lapic_id, uint8_t vec, uint32_t gsi, uint16_t
|
||||||
redirect |= (1 << 15);
|
redirect |= (1 << 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask) redirect |= (1 << 16);
|
if (mask)
|
||||||
else redirect &= ~(1 << 16);
|
redirect |= (1 << 16);
|
||||||
|
else
|
||||||
|
redirect &= ~(1 << 16);
|
||||||
|
|
||||||
redirect |= (uint64_t)lapic_id << 56;
|
redirect |= (uint64_t)lapic_id << 56;
|
||||||
|
|
||||||
|
@ -73,9 +80,10 @@ void ioapic_redirect_gsi(uint32_t lapic_id, uint8_t vec, uint32_t gsi, uint16_t
|
||||||
ioapic_write(ioapic, redir_table + 1, (uint32_t)(redirect >> 32));
|
ioapic_write(ioapic, redir_table + 1, (uint32_t)(redirect >> 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ioapic_redirect_irq(uint32_t lapic_id, uint8_t vec, uint8_t irq, bool mask) {
|
void ioapic_redirect_irq(uint32_t lapic_id, uint8_t vec, uint8_t irq,
|
||||||
|
bool mask) {
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
madt_iso* iso = (madt_iso*)0;
|
madt_iso *iso = (madt_iso *)0;
|
||||||
|
|
||||||
while (idx < acpi_madt_iso_length) {
|
while (idx < acpi_madt_iso_length) {
|
||||||
iso = acpi_madt_iso_list[idx];
|
iso = acpi_madt_iso_list[idx];
|
||||||
|
@ -91,7 +99,7 @@ void ioapic_redirect_irq(uint32_t lapic_id, uint8_t vec, uint8_t irq, bool mask)
|
||||||
|
|
||||||
uint32_t ioapic_get_redirect_irq(uint8_t irq) {
|
uint32_t ioapic_get_redirect_irq(uint8_t irq) {
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
madt_iso* iso;
|
madt_iso *iso;
|
||||||
|
|
||||||
while (idx < acpi_madt_iso_length) {
|
while (idx < acpi_madt_iso_length) {
|
||||||
iso = acpi_madt_iso_list[idx];
|
iso = acpi_madt_iso_list[idx];
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
#define IOAPIC_ARB 0x02
|
#define IOAPIC_ARB 0x02
|
||||||
#define IOAPIC_REDTBL 0x10
|
#define IOAPIC_REDTBL 0x10
|
||||||
|
|
||||||
|
void ioapic_write(madt_ioapic *ioapic, uint8_t reg, uint32_t val);
|
||||||
|
uint32_t ioapic_read(madt_ioapic *ioapic, uint8_t reg);
|
||||||
|
|
||||||
void ioapic_write(madt_ioapic* ioapic, uint8_t reg, uint32_t val);
|
void ioapic_redirect_irq(uint32_t lapic_id, uint8_t vec, uint8_t irq,
|
||||||
uint32_t ioapic_read(madt_ioapic* ioapic, uint8_t reg);
|
bool mask);
|
||||||
|
|
||||||
void ioapic_redirect_irq(uint32_t lapic_id, uint8_t vec, uint8_t irq, bool mask);
|
|
||||||
uint32_t ioapic_get_redirect_irq(uint8_t irq);
|
uint32_t ioapic_get_redirect_irq(uint8_t irq);
|
||||||
|
|
||||||
void ioapic_set_entry(madt_ioapic* ioapic, uint8_t idx, uint64_t data);
|
void ioapic_set_entry(madt_ioapic *ioapic, uint8_t idx, uint64_t data);
|
||||||
|
|
||||||
void ioapic_init();
|
void ioapic_init();
|
|
@ -27,7 +27,7 @@ void lapic_calibrate_timer() {
|
||||||
lapic_write(LAPIC_TIMER_DIV, 0);
|
lapic_write(LAPIC_TIMER_DIV, 0);
|
||||||
lapic_write(LAPIC_TIMER_LVT, (1 << 16) | 0xff);
|
lapic_write(LAPIC_TIMER_LVT, (1 << 16) | 0xff);
|
||||||
lapic_write(LAPIC_TIMER_INITCNT, 0xFFFFFFFF);
|
lapic_write(LAPIC_TIMER_INITCNT, 0xFFFFFFFF);
|
||||||
//pit_sleep(1); // 1 ms
|
// pit_sleep(1); // 1 ms
|
||||||
lapic_write(LAPIC_TIMER_LVT, LAPIC_TIMER_DISABLE);
|
lapic_write(LAPIC_TIMER_LVT, LAPIC_TIMER_DISABLE);
|
||||||
uint32_t ticks = 0xFFFFFFFF - lapic_read(LAPIC_TIMER_CURCNT);
|
uint32_t ticks = 0xFFFFFFFF - lapic_read(LAPIC_TIMER_CURCNT);
|
||||||
apic_ticks = ticks;
|
apic_ticks = ticks;
|
||||||
|
@ -35,16 +35,14 @@ void lapic_calibrate_timer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void lapic_write(uint32_t reg, uint32_t val) {
|
void lapic_write(uint32_t reg, uint32_t val) {
|
||||||
*((volatile uint32_t*)(HIGHER_HALF(0xfee00000) + reg)) = val;
|
*((volatile uint32_t *)(HIGHER_HALF(0xfee00000) + reg)) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lapic_read(uint32_t reg) {
|
uint32_t lapic_read(uint32_t reg) {
|
||||||
return *((volatile uint32_t*)(HIGHER_HALF(0xfee00000) + reg));
|
return *((volatile uint32_t *)(HIGHER_HALF(0xfee00000) + reg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void lapic_eoi() {
|
void lapic_eoi() { lapic_write((uint8_t)0xb0, 0x0); }
|
||||||
lapic_write((uint8_t)0xb0, 0x0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void lapic_ipi(uint32_t id, uint8_t dat) {
|
void lapic_ipi(uint32_t id, uint8_t dat) {
|
||||||
lapic_write(LAPIC_ICRHI, id << LAPIC_ICDESTSHIFT);
|
lapic_write(LAPIC_ICRHI, id << LAPIC_ICDESTSHIFT);
|
||||||
|
@ -59,6 +57,4 @@ void lapic_send_others_int(uint32_t id, uint32_t vec) {
|
||||||
lapic_ipi(id, vec | LAPIC_ICRAES);
|
lapic_ipi(id, vec | LAPIC_ICRAES);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t lapic_get_id() {
|
uint32_t lapic_get_id() { return lapic_read(0x0020) >> LAPIC_ICDESTSHIFT; }
|
||||||
return lapic_read(0x0020) >> LAPIC_ICDESTSHIFT;
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "fs/vfs.h"
|
#include "fs/vfs.h"
|
||||||
|
#include "lib/string.h"
|
||||||
#include "mm/liballoc/liballoc.h"
|
#include "mm/liballoc/liballoc.h"
|
||||||
#include "mm/memop.h"
|
#include "mm/memop.h"
|
||||||
#include "lib/string.h"
|
|
||||||
|
|
||||||
vnode_t *vfs_create_node(char *name, vnode_type_t type) {
|
vnode_t *vfs_create_node(char *name, vnode_type_t type) {
|
||||||
vnode_t *node = (vnode_t *)malloc(sizeof(vnode_t));
|
vnode_t *node = (vnode_t *)malloc(sizeof(vnode_t));
|
||||||
|
@ -12,8 +12,8 @@ vnode_t *vfs_create_node(char *name, vnode_type_t type) {
|
||||||
strncpy(node->name, name, sizeof(node->name) - 1);
|
strncpy(node->name, name, sizeof(node->name) - 1);
|
||||||
node->type = type;
|
node->type = type;
|
||||||
node->ops = NULL;
|
node->ops = NULL;
|
||||||
//node->parent = NULL;
|
// node->parent = NULL;
|
||||||
//node->child = NULL;
|
// node->child = NULL;
|
||||||
//node->next = NULL;
|
// node->next = NULL;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
|
@ -11,36 +11,36 @@ struct vnode;
|
||||||
typedef uint32_t vnode_type_t;
|
typedef uint32_t vnode_type_t;
|
||||||
|
|
||||||
typedef struct vnode_ops {
|
typedef struct vnode_ops {
|
||||||
int (*read)(struct vnode* vn, void* buf, size_t off, size_t size);
|
int (*read)(struct vnode *vn, void *buf, size_t off, size_t size);
|
||||||
struct vnode* (*lookup)(struct vnode* vn, const char* name);
|
struct vnode *(*lookup)(struct vnode *vn, const char *name);
|
||||||
} vnode_ops_t;
|
} vnode_ops_t;
|
||||||
|
|
||||||
typedef struct vnode {
|
typedef struct vnode {
|
||||||
char name[256];
|
char name[256];
|
||||||
vnode_type_t type;
|
vnode_type_t type;
|
||||||
uint32_t refcount;
|
uint32_t refcount;
|
||||||
//struct vnode* parent;
|
// struct vnode* parent;
|
||||||
//struct vnode* child;
|
// struct vnode* child;
|
||||||
//struct vnode* next;
|
// struct vnode* next;
|
||||||
|
|
||||||
struct vnode_ops* ops;
|
struct vnode_ops *ops;
|
||||||
void* internal;
|
void *internal;
|
||||||
} vnode_t;
|
} vnode_t;
|
||||||
|
|
||||||
typedef struct mountpoint {
|
typedef struct mountpoint {
|
||||||
char name[32];
|
char name[32];
|
||||||
struct fs* fs;
|
struct fs *fs;
|
||||||
vnode_t* mountpoint;
|
vnode_t *mountpoint;
|
||||||
} mountpoint_t;
|
} mountpoint_t;
|
||||||
|
|
||||||
typedef struct fs {
|
typedef struct fs {
|
||||||
char name[32];
|
char name[32];
|
||||||
struct vnode* root;
|
struct vnode *root;
|
||||||
int (*mount)(struct vnode* mountpoint);
|
int (*mount)(struct vnode *mountpoint);
|
||||||
} fs_t;
|
} fs_t;
|
||||||
|
|
||||||
void vfs_init(void);
|
void vfs_init(void);
|
||||||
int vfs_mount(char *path, fs_t* fs);
|
int vfs_mount(char *path, fs_t *fs);
|
||||||
int vfs_unmount(char *path);
|
int vfs_unmount(char *path);
|
||||||
int vfs_open(const char* path, vnode_t** result);
|
int vfs_open(const char *path, vnode_t **result);
|
||||||
int vfs_read(vnode_t* vn, void* buf, size_t off, size_t size);
|
int vfs_read(vnode_t *vn, void *buf, size_t off, size_t size);
|
||||||
|
|
|
@ -8,7 +8,7 @@ typedef struct spinlock {
|
||||||
} spinlock_t;
|
} spinlock_t;
|
||||||
|
|
||||||
static inline void spinlock_acquire(spinlock_t *lock) {
|
static inline void spinlock_acquire(spinlock_t *lock) {
|
||||||
//uint64_t timeout = 1000000; // Adjust this value based on your needs
|
// uint64_t timeout = 1000000; // Adjust this value based on your needs
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (__atomic_exchange_n(&lock->locked, 1, __ATOMIC_ACQUIRE) == 0) {
|
if (__atomic_exchange_n(&lock->locked, 1, __ATOMIC_ACQUIRE) == 0) {
|
||||||
|
|
|
@ -78,4 +78,3 @@ char *strncpy(char *dest, const char *src, size_t n) {
|
||||||
dest[i] = '\0';
|
dest[i] = '\0';
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#include "arch/x86_64/pit.h"
|
||||||
|
#include "arch/x86_64/smp.h"
|
||||||
|
#include "arch/x86_64/sse.h"
|
||||||
#include "dev/ioapic.h"
|
#include "dev/ioapic.h"
|
||||||
#include "dev/lapic.h"
|
#include "dev/lapic.h"
|
||||||
#include "exec/elf.h"
|
#include "exec/elf.h"
|
||||||
|
@ -9,25 +12,22 @@
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "sys/acpi.h"
|
#include "sys/acpi.h"
|
||||||
#include "sys/acpi/madt.h"
|
#include "sys/acpi/madt.h"
|
||||||
#include "arch//x86_64/pit.h"
|
|
||||||
#include "arch//x86_64/smp.h"
|
|
||||||
#include "arch//x86_64/sse.h"
|
|
||||||
#include "sys/syscall.h"
|
#include "sys/syscall.h"
|
||||||
|
#include <arch/x86_64/fpu.h>
|
||||||
|
#include <arch/x86_64/gdt.h>
|
||||||
|
#include <arch/x86_64/idt.h>
|
||||||
#include <font.h>
|
#include <font.h>
|
||||||
|
#include <fs/vfs.h>
|
||||||
#include <limine.h>
|
#include <limine.h>
|
||||||
#include <mm/memop.h>
|
#include <mm/memop.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <arch//x86_64/fpu.h>
|
|
||||||
#include <arch//x86_64/gdt.h>
|
|
||||||
#include <arch//x86_64/idt.h>
|
|
||||||
#include <sys/errhnd/panic.h>
|
#include <sys/errhnd/panic.h>
|
||||||
#include <sys/gfx/flanterm/backends/fb.h>
|
#include <sys/gfx/flanterm/backends/fb.h>
|
||||||
#include <sys/gfx/flanterm/flanterm.h>
|
#include <sys/gfx/flanterm/flanterm.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
#include <sys/printf.h>
|
#include <sys/printf.h>
|
||||||
#include <fs/vfs.h>
|
|
||||||
|
|
||||||
__attribute__((
|
__attribute__((
|
||||||
used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
|
used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
|
||||||
|
@ -98,20 +98,19 @@ void kmain(void) {
|
||||||
syscall_init();
|
syscall_init();
|
||||||
sched_init();
|
sched_init();
|
||||||
|
|
||||||
//vfs_init();
|
// vfs_init();
|
||||||
|
|
||||||
|
// panic("No working initialization program found. (This is normal due to "
|
||||||
|
|
||||||
//panic("No working initialization program found. (This is normal due to "
|
|
||||||
// "Soaplin's current state, so please do not report this as a bug)");
|
// "Soaplin's current state, so please do not report this as a bug)");
|
||||||
|
|
||||||
program_t *p = elf_load(module_request.response->modules[0]->address, 1);
|
program_t *p = elf_load(module_request.response->modules[0]->address, 1);
|
||||||
|
|
||||||
sched_process *proc = sched_create("Test", p->entry, p->pm,
|
sched_process *proc =
|
||||||
SCHED_USER_PROCESS);
|
sched_create("Test", p->entry, p->pm, SCHED_USER_PROCESS);
|
||||||
|
|
||||||
log("kernel - Soaplin initialized sucessfully.\n");
|
log("kernel - Soaplin initialized sucessfully.\n");
|
||||||
|
|
||||||
|
pit_enable();
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
;
|
;
|
||||||
|
|
|
@ -49,7 +49,7 @@ void vmm_release_pm(pagemap_t *pm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vmm_sanity_check() {
|
void vmm_sanity_check() {
|
||||||
uint64_t *my_memory = pmm_request_page();
|
uint64_t *my_memory = HIGHER_HALF(pmm_request_page());
|
||||||
*my_memory = 0x40;
|
*my_memory = 0x40;
|
||||||
|
|
||||||
pagemap_t *pm = vmm_alloc_pm();
|
pagemap_t *pm = vmm_alloc_pm();
|
||||||
|
@ -113,14 +113,14 @@ void vmm_init() {
|
||||||
|
|
||||||
log("vmm - mapping address from 0x0 to 0x100000000...\n");
|
log("vmm - mapping address from 0x0 to 0x100000000...\n");
|
||||||
for (uint64_t gb4 = 0; gb4 < 0x100000000; gb4 += PMM_PAGE_SIZE) {
|
for (uint64_t gb4 = 0; gb4 < 0x100000000; gb4 += PMM_PAGE_SIZE) {
|
||||||
vmm_map(vmm_kernel_pm, gb4, gb4, VMM_PRESENT | VMM_WRITABLE);
|
//vmm_map(vmm_kernel_pm, gb4, gb4, VMM_PRESENT | VMM_WRITABLE);
|
||||||
vmm_map(vmm_kernel_pm, (uint64_t)HIGHER_HALF(gb4), gb4,
|
vmm_map(vmm_kernel_pm, (uint64_t)HIGHER_HALF(gb4), gb4,
|
||||||
VMM_PRESENT | VMM_WRITABLE);
|
VMM_PRESENT | VMM_WRITABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
vmm_load_pagemap(vmm_kernel_pm);
|
vmm_load_pagemap(vmm_kernel_pm);
|
||||||
|
|
||||||
vmm_sanity_check();
|
//vmm_sanity_check();
|
||||||
log("vmm - initialized!\n");
|
log("vmm - initialized!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
|
#include "arch/x86_64/idt.h"
|
||||||
#include "arch/x86_64/msr.h"
|
#include "arch/x86_64/msr.h"
|
||||||
#include "mm/memop.h"
|
#include "mm/memop.h"
|
||||||
#include "mm/pmm.h"
|
#include "mm/pmm.h"
|
||||||
#include "mm/vmm.h"
|
#include "mm/vmm.h"
|
||||||
#include "arch//x86_64/idt.h"
|
|
||||||
#include "sys/log.h"
|
#include "sys/log.h"
|
||||||
#include <lib/string.h>
|
#include <lib/string.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <mm/liballoc/liballoc.h>
|
#include <mm/liballoc/liballoc.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
sched_process *proc_list;
|
sched_process *proc_list;
|
||||||
sched_process *curr_proc;
|
sched_process *curr_proc;
|
||||||
|
@ -114,7 +114,6 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t *pm,
|
||||||
"disabled.\n");
|
"disabled.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
log("sched - created process '%s' (pid: %d, rip: %p)\n", proc->name,
|
log("sched - created process '%s' (pid: %d, rip: %p)\n", proc->name,
|
||||||
proc->pid, proc->regs.rip);
|
proc->pid, proc->regs.rip);
|
||||||
return proc;
|
return proc;
|
||||||
|
@ -158,6 +157,6 @@ void schedule(registers_t *regs) {
|
||||||
memcpy(regs, &curr_proc->regs, sizeof(registers_t));
|
memcpy(regs, &curr_proc->regs, sizeof(registers_t));
|
||||||
|
|
||||||
wrmsr(IA32_GS_KERNEL_MSR, (uint64_t)curr_proc);
|
wrmsr(IA32_GS_KERNEL_MSR, (uint64_t)curr_proc);
|
||||||
//log("sched - proc %d\n", curr_proc->pid);
|
// log("sched - proc %d\n", curr_proc->pid);
|
||||||
vmm_load_pagemap(curr_proc->pm);
|
vmm_load_pagemap(curr_proc->pm);
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "mm/vmm.h"
|
|
||||||
#include "arch/x86_64/idt.h"
|
#include "arch/x86_64/idt.h"
|
||||||
|
#include "mm/vmm.h"
|
||||||
|
|
||||||
#define SCHED_KERNEL_PROCESS 0 // A process that runs in kernel mode.
|
#define SCHED_KERNEL_PROCESS 0 // A process that runs in kernel mode.
|
||||||
#define SCHED_USER_PROCESS \
|
#define SCHED_USER_PROCESS \
|
||||||
|
|
|
@ -42,7 +42,7 @@ void *acpi_find_table(const char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void acpi_init() {
|
void acpi_init() {
|
||||||
acpi_rsdp *rsdp = (acpi_rsdp *)rsdp_req.response->address;
|
acpi_rsdp *rsdp = (acpi_rsdp *)HIGHER_HALF(rsdp_req.response->address);
|
||||||
|
|
||||||
if (memcmp(rsdp->sign, "RSD PTR", 7))
|
if (memcmp(rsdp->sign, "RSD PTR", 7))
|
||||||
panic("acpi: Invalid RSDP signature!");
|
panic("acpi: Invalid RSDP signature!");
|
||||||
|
@ -50,9 +50,9 @@ void acpi_init() {
|
||||||
if (rsdp->revision != 0) {
|
if (rsdp->revision != 0) {
|
||||||
__acpi_uses_xsdt = 1;
|
__acpi_uses_xsdt = 1;
|
||||||
acpi_xsdp *xsdp = (acpi_xsdp *)rsdp;
|
acpi_xsdp *xsdp = (acpi_xsdp *)rsdp;
|
||||||
__acpi_rsdt_ptr = (acpi_xsdt *)HIGHER_HALF((uint64_t)xsdp->xsdt_addr);
|
__acpi_rsdt_ptr = (void *)HIGHER_HALF(xsdp->xsdt_addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
__acpi_rsdt_ptr = (acpi_rsdt *)HIGHER_HALF((uint64_t)rsdp->rsdt_addr);
|
__acpi_rsdt_ptr = (void *)HIGHER_HALF(rsdp->rsdt_addr);
|
||||||
}
|
}
|
|
@ -4,13 +4,13 @@
|
||||||
#include <sys/errhnd/panic.h>
|
#include <sys/errhnd/panic.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
|
|
||||||
madt_ioapic* acpi_madt_ioapic_list[256] = {0};
|
madt_ioapic *acpi_madt_ioapic_list[256] = {0};
|
||||||
madt_iso* acpi_madt_iso_list[256] = {0};
|
madt_iso *acpi_madt_iso_list[256] = {0};
|
||||||
|
|
||||||
uint32_t acpi_madt_ioapic_length = 0;
|
uint32_t acpi_madt_ioapic_length = 0;
|
||||||
uint32_t acpi_madt_iso_length = 0;
|
uint32_t acpi_madt_iso_length = 0;
|
||||||
|
|
||||||
uint64_t* acpi_lapic_addr = 0;
|
uint64_t *acpi_lapic_addr = 0;
|
||||||
|
|
||||||
void madt_init() {
|
void madt_init() {
|
||||||
void *addr = acpi_find_table("APIC");
|
void *addr = acpi_find_table("APIC");
|
||||||
|
@ -26,16 +26,16 @@ void madt_init() {
|
||||||
if (offset > madt->sdt.len - sizeof(acpi_madt))
|
if (offset > madt->sdt.len - sizeof(acpi_madt))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
madt_entry* entry = (madt_entry*)(madt->table + offset);
|
madt_entry *entry = (madt_entry *)(madt->table + offset);
|
||||||
|
|
||||||
if (entry->type == 0)
|
if (entry->type == 0)
|
||||||
i++;
|
i++;
|
||||||
else if (entry->type == 1)
|
else if (entry->type == 1)
|
||||||
acpi_madt_ioapic_list[acpi_madt_ioapic_length++] = (madt_ioapic*)entry;
|
acpi_madt_ioapic_list[acpi_madt_ioapic_length++] = (madt_ioapic *)entry;
|
||||||
else if (entry->type == 2)
|
else if (entry->type == 2)
|
||||||
acpi_madt_iso_list[acpi_madt_iso_length++] = (madt_iso*)entry;
|
acpi_madt_iso_list[acpi_madt_iso_length++] = (madt_iso *)entry;
|
||||||
else if (entry->type == 5)
|
else if (entry->type == 5)
|
||||||
acpi_lapic_addr = (uint64_t*)((madt_lapic_addr*)entry)->phys_lapic;
|
acpi_lapic_addr = (uint64_t *)((madt_lapic_addr *)entry)->phys_lapic;
|
||||||
|
|
||||||
offset += entry->length;
|
offset += entry->length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,12 @@ typedef struct {
|
||||||
uint64_t phys_lapic;
|
uint64_t phys_lapic;
|
||||||
} madt_lapic_addr;
|
} madt_lapic_addr;
|
||||||
|
|
||||||
extern madt_ioapic* acpi_madt_ioapic_list[256];
|
extern madt_ioapic *acpi_madt_ioapic_list[256];
|
||||||
extern madt_iso* acpi_madt_iso_list[256];
|
extern madt_iso *acpi_madt_iso_list[256];
|
||||||
|
|
||||||
extern uint32_t acpi_madt_ioapic_length;
|
extern uint32_t acpi_madt_ioapic_length;
|
||||||
extern uint32_t acpi_madt_iso_length;
|
extern uint32_t acpi_madt_iso_length;
|
||||||
|
|
||||||
extern uint64_t* acpi_lapic_addr;
|
extern uint64_t *acpi_lapic_addr;
|
||||||
|
|
||||||
void madt_init();
|
void madt_init();
|
|
@ -1,8 +1,10 @@
|
||||||
#include "arch//x86_64/idt.h"
|
#include "arch/x86_64/idt.h"
|
||||||
#include "lib/spinlock.h"
|
#include "lib/spinlock.h"
|
||||||
#include <mm/memop.h>
|
#include <mm/memop.h>
|
||||||
#include <sys/log.h>
|
#include <sys/log.h>
|
||||||
|
|
||||||
|
#include "sched/sched.h"
|
||||||
|
|
||||||
static registers_t __panic_regdump;
|
static registers_t __panic_regdump;
|
||||||
|
|
||||||
static void __panic_dump_regs() {
|
static void __panic_dump_regs() {
|
||||||
|
@ -85,17 +87,14 @@ static void __panic_display_page_fault(registers_t *regs) {
|
||||||
|
|
||||||
static void __panic_display_regs(registers_t *regs) {
|
static void __panic_display_regs(registers_t *regs) {
|
||||||
log("-- REGISTER DUMP --\n");
|
log("-- REGISTER DUMP --\n");
|
||||||
log("RDI: %p, RSI: %p, RDX: %p, RCX: %p, R8: %p, R9: %p\n",
|
log("RDI: %p, RSI: %p, RDX: %p, RCX: %p, R8: %p, R9: %p\n", regs->rdi,
|
||||||
regs->rdi, regs->rsi, regs->rdx,
|
regs->rsi, regs->rdx, regs->rcx, regs->r8, regs->r9);
|
||||||
regs->rcx, regs->r8, regs->r9);
|
log("RAX: %p, RBP: %p, RBX: %p, R10: %p, R11: %p, R12: %p\n", regs->rax,
|
||||||
log("RAX: %p, RBP: %p, RBX: %p, R10: %p, R11: %p, R12: %p\n",
|
regs->rbp, regs->rbx, regs->r10, regs->r11, regs->r12);
|
||||||
regs->rax, regs->rbp, regs->rbx,
|
log("R13: %p, R14: %p, R15: %p\n", regs->r13, regs->r14, regs->r15);
|
||||||
regs->r10, regs->r11, regs->r12);
|
|
||||||
log("R13: %p, R14: %p, R15: %p\n", regs->r13, regs->r14,
|
|
||||||
regs->r15);
|
|
||||||
log("RIP: %p, CS: %x, SS: %x, RFLAGS: %d, INTERRUPT: %d, ERROR CODE: %d\n",
|
log("RIP: %p, CS: %x, SS: %x, RFLAGS: %d, INTERRUPT: %d, ERROR CODE: %d\n",
|
||||||
regs->rip, regs->cs, regs->ss,
|
regs->rip, regs->cs, regs->ss, regs->rflags, regs->int_no,
|
||||||
regs->rflags, regs->int_no, regs->err_code);
|
regs->err_code);
|
||||||
log("RSP: %p\n", regs->rsp);
|
log("RSP: %p\n", regs->rsp);
|
||||||
|
|
||||||
if (regs->int_no == 14) // If it's a page fault
|
if (regs->int_no == 14) // If it's a page fault
|
||||||
|
@ -136,13 +135,16 @@ void panic_ctx(char *msg, registers_t *regs) {
|
||||||
log("%s\n", msg);
|
log("%s\n", msg);
|
||||||
log("\n");
|
log("\n");
|
||||||
|
|
||||||
|
if (curr_proc) {
|
||||||
|
log("Current process: %s (PID: %d)\n", curr_proc->name, curr_proc->pid);
|
||||||
|
log("\n");
|
||||||
|
}
|
||||||
|
|
||||||
if (regs)
|
if (regs)
|
||||||
__panic_display_regs(regs);
|
__panic_display_regs(regs);
|
||||||
else
|
else
|
||||||
log("No register context provided.\n");
|
log("No register context provided.\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
log("System halted: Please restart your computer manually.\n");
|
log("System halted: Please restart your computer manually.\n");
|
||||||
|
|
||||||
asm("cli");
|
asm("cli");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "arch//x86_64/io.h"
|
#include "arch/x86_64/io.h"
|
||||||
#include "sys/gfx/flanterm/flanterm.h"
|
#include "sys/gfx/flanterm/flanterm.h"
|
||||||
#include <lib/spinlock.h>
|
#include <lib/spinlock.h>
|
||||||
#include <lib/string.h>
|
#include <lib/string.h>
|
||||||
|
@ -13,7 +13,7 @@ void log(char *format, ...) {
|
||||||
// TODO: replace this call with a call to printf() when the RTC is
|
// TODO: replace this call with a call to printf() when the RTC is
|
||||||
// implemented.
|
// implemented.
|
||||||
|
|
||||||
//spinlock_acquire(&log_lock);
|
// spinlock_acquire(&log_lock);
|
||||||
|
|
||||||
char *date = "1970-01-01 00:00:00 | ";
|
char *date = "1970-01-01 00:00:00 | ";
|
||||||
if (ft_ctx)
|
if (ft_ctx)
|
||||||
|
@ -42,5 +42,5 @@ void log(char *format, ...) {
|
||||||
outb(0xE9, buf[i]);
|
outb(0xE9, buf[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//spinlock_release(&log_lock);
|
// spinlock_release(&log_lock);
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "arch//x86_64/idt.h"
|
#include "arch/x86_64/idt.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/// A function that defines a system call.
|
/// A function that defines a system call.
|
||||||
|
|
Binary file not shown.
|
@ -3,6 +3,7 @@ section .text
|
||||||
global _start
|
global _start
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
|
mov rax, 1025
|
||||||
syscall
|
syscall
|
||||||
.loop:
|
.loop:
|
||||||
jmp .loop
|
jmp .loop
|
BIN
testing/test.o
BIN
testing/test.o
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue