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];
|
||||||
|
@ -60,7 +60,6 @@ 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);
|
||||||
|
|
|
@ -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,9 +1,9 @@
|
||||||
#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;
|
||||||
|
|
||||||
|
@ -18,9 +18,10 @@ 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) {
|
||||||
|
|
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,12 +1,11 @@
|
||||||
#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;
|
||||||
|
@ -18,11 +17,13 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,7 +1,7 @@
|
||||||
#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];
|
||||||
|
@ -22,21 +22,24 @@ void ioapic_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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)) =
|
||||||
|
reg;
|
||||||
*((volatile uint32_t *)(HIGHER_HALF(ioapic->apic_addr) + IOAPIC_IOWIN)) = val;
|
*((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;
|
||||||
}
|
}
|
||||||
|
@ -44,13 +47,15 @@ uint64_t ioapic_gsi_count(madt_ioapic* ioapic) {
|
||||||
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,
|
||||||
|
uint16_t flags, bool mask) {
|
||||||
madt_ioapic *ioapic = ioapic_get_gsi(gsi);
|
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,7 +80,8 @@ 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;
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
#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);
|
void ioapic_write(madt_ioapic *ioapic, uint8_t reg, uint32_t val);
|
||||||
uint32_t ioapic_read(madt_ioapic *ioapic, uint8_t reg);
|
uint32_t ioapic_read(madt_ioapic *ioapic, uint8_t reg);
|
||||||
|
|
||||||
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);
|
||||||
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);
|
||||||
|
|
|
@ -42,9 +42,7 @@ 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));
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -100,18 +100,17 @@ void kmain(void) {
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
|
@ -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>
|
||||||
|
|
|
@ -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