Compare commits
4 Commits
6e92817f3f
...
09926f45ee
| Author | SHA1 | Date | |
|---|---|---|---|
| 09926f45ee | |||
| 32ee3895e6 | |||
| ff4362ca5b | |||
| 1dc41fe7ff |
+5
-5
@@ -57,7 +57,7 @@ void lapic_init(struct local_apic* lapic) {
|
|||||||
// Reset the TPR.
|
// Reset the TPR.
|
||||||
lapic_write_reg(lapic, APIC_REG_TPR, 0);
|
lapic_write_reg(lapic, APIC_REG_TPR, 0);
|
||||||
// Enable APIC bit in the SIVR.
|
// Enable APIC bit in the SIVR.
|
||||||
lapic_write_reg(lapic, APIC_REG_SIVR, lapic_read_reg(lapic, APIC_REG_SIVR) | 0x100);
|
lapic_write_reg(lapic, APIC_REG_SIVR, (lapic_read_reg(lapic, APIC_REG_SIVR) & ~0xFF) | 0x100 | IDT_SPURIOUS);
|
||||||
|
|
||||||
if (lapic->xapic_regs) {
|
if (lapic->xapic_regs) {
|
||||||
lapic_write_reg(lapic, APIC_REG_DFR, 0xF000'0000);
|
lapic_write_reg(lapic, APIC_REG_DFR, 0xF000'0000);
|
||||||
@@ -84,10 +84,10 @@ void lapic_eoi(struct local_apic* lapic) {
|
|||||||
lapic_write_reg(lapic, APIC_REG_EOI, 0);
|
lapic_write_reg(lapic, APIC_REG_EOI, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PIC1_COMMAND_PORT 0x20
|
constexpr uint16_t PIC1_COMMAND_PORT = 0x20;
|
||||||
#define PIC1_DATA_PORT 0x21
|
constexpr uint16_t PIC1_DATA_PORT = 0x21;
|
||||||
#define PIC2_COMMAND_PORT 0xA0
|
constexpr uint16_t PIC2_COMMAND_PORT = 0xA0;
|
||||||
#define PIC2_DATA_PORT 0xA1
|
constexpr uint16_t PIC2_DATA_PORT = 0xA1;
|
||||||
|
|
||||||
void pic_disable() {
|
void pic_disable() {
|
||||||
// We initialize the PIC properly, but completely disable it and use the APIC in favor of it.
|
// We initialize the PIC properly, but completely disable it and use the APIC in favor of it.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#include <zinnia/percpu.h>
|
#include <zinnia/percpu.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
#include <x86_64/asm.h>
|
#include <x86_64/asm.h>
|
||||||
#include <x86_64/defs.h>
|
#include <x86_64/defs.h>
|
||||||
#include <x86_64/gdt.h>
|
#include <x86_64/gdt.h>
|
||||||
|
|||||||
@@ -3,4 +3,3 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef uint64_t phys_t;
|
typedef uint64_t phys_t;
|
||||||
typedef uint64_t virt_t;
|
|
||||||
|
|||||||
@@ -198,4 +198,5 @@
|
|||||||
#define CPL_KERNEL (0x0)
|
#define CPL_KERNEL (0x0)
|
||||||
|
|
||||||
#define IDT_PF (0xE)
|
#define IDT_PF (0xE)
|
||||||
|
#define IDT_SPURIOUS (0xFE)
|
||||||
#define IDT_IPI_RESCHED (0xFF)
|
#define IDT_IPI_RESCHED (0xFF)
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
#include <zinnia/cmdline.h>
|
#include <zinnia/cmdline.h>
|
||||||
#include <zinnia/init.h>
|
#include <zinnia/init.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <zinnia/stdlib.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
// Defined in linker script.
|
// Defined in linker script.
|
||||||
extern const struct cmdline_option* __ld_cmdline_start[];
|
extern const struct cmdline_option* __ld_cmdline_start[];
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
#include <zinnia/init.h>
|
#include <zinnia/init.h>
|
||||||
#include <zinnia/print.h>
|
#include <zinnia/print.h>
|
||||||
#include <zinnia/utils.h>
|
#include <zinnia/utils.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
#include "limine.h"
|
#include "limine.h"
|
||||||
|
|
||||||
[[__initdata_sorted("limine.0")]]
|
[[__initdata_sorted("limine.0")]]
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#include <zinnia/cmdline.h>
|
#include <zinnia/cmdline.h>
|
||||||
#include <zinnia/console.h>
|
#include <zinnia/console.h>
|
||||||
#include <zinnia/print.h>
|
#include <zinnia/print.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
extern struct console* const __ld_console_start[];
|
extern struct console* const __ld_console_start[];
|
||||||
extern struct console* const __ld_console_end[];
|
extern struct console* const __ld_console_end[];
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
#include <zinnia/vma.h>
|
#include <zinnia/vma.h>
|
||||||
#include <zinnia/vmo.h>
|
#include <zinnia/vmo.h>
|
||||||
#include <bits/elf.h>
|
#include <bits/elf.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
struct exec_info {
|
struct exec_info {
|
||||||
struct vma* space;
|
struct vma* space;
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <zinnia/stdlib.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
static void reverse(char* s) {
|
static void reverse(char* s) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
#include <zinnia/utils.h>
|
#include <zinnia/utils.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
[[__hot]]
|
[[__hot]]
|
||||||
size_t strlen(const char* str) {
|
size_t strlen(const char* str) {
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
#include <zinnia/print.h>
|
#include <zinnia/print.h>
|
||||||
#include <zinnia/utils.h>
|
#include <zinnia/utils.h>
|
||||||
#include <zinnia/vma.h>
|
#include <zinnia/vma.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
extern uint8_t __ld_text_start[];
|
extern uint8_t __ld_text_start[];
|
||||||
extern uint8_t __ld_text_end[];
|
extern uint8_t __ld_text_end[];
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
#include <zinnia/spin.h>
|
#include <zinnia/spin.h>
|
||||||
#include <zinnia/vma.h>
|
#include <zinnia/vma.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
// TODO: For now, we assume that we can do generic PTE lookups on every arch that has a MMU.
|
// TODO: For now, we assume that we can do generic PTE lookups on every arch that has a MMU.
|
||||||
static_assert(CONFIG_HAVE_MMU_GENERIC);
|
static_assert(CONFIG_HAVE_MMU_GENERIC);
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
#include <zinnia/spin.h>
|
#include <zinnia/spin.h>
|
||||||
#include <zinnia/virt.h>
|
#include <zinnia/virt.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
uintptr_t mem_hhdm_base = 0;
|
uintptr_t mem_hhdm_base = 0;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
#include <zinnia/compiler.h>
|
#include <zinnia/compiler.h>
|
||||||
#include <zinnia/errno.h>
|
#include <zinnia/errno.h>
|
||||||
#include <zinnia/spin.h>
|
#include <zinnia/spin.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t num_pages; // Amount of pages connected to this slab.
|
size_t num_pages; // Amount of pages connected to this slab.
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
#include <zinnia/list.h>
|
#include <zinnia/list.h>
|
||||||
#include <zinnia/utils.h>
|
#include <zinnia/utils.h>
|
||||||
#include <zinnia/vmo.h>
|
#include <zinnia/vmo.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
errno_t vmo_read(struct vmo* obj, uintptr_t offset, void* buf, size_t len, size_t* actual_read) {
|
errno_t vmo_read(struct vmo* obj, uintptr_t offset, void* buf, size_t len, size_t* actual_read) {
|
||||||
const size_t page_size = arch_mem_page_size();
|
const size_t page_size = arch_mem_page_size();
|
||||||
|
|||||||
+2
-2
@@ -5,8 +5,8 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <zinnia/stdlib.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
typedef void (*log_fn_t)(void* ctx, const char* buf, size_t len);
|
typedef void (*log_fn_t)(void* ctx, const char* buf, size_t len);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include <zinnia/vma.h>
|
#include <zinnia/vma.h>
|
||||||
#include <arch/sched.h>
|
#include <arch/sched.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
static void idle_func(uintptr_t) {
|
static void idle_func(uintptr_t) {
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
typedef __builtin_va_list va_list;
|
|
||||||
#define va_start(v, l) __builtin_va_start(v, l)
|
|
||||||
#define va_end(v) __builtin_va_end(v)
|
|
||||||
#define va_arg(v, T) __builtin_va_arg(v, T)
|
|
||||||
#define va_copy(d, s) __builtin_va_copy(d, s)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
typedef unsigned long size_t;
|
|
||||||
typedef signed long ssize_t;
|
|
||||||
|
|
||||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
|
||||||
#define unreachable() __builtin_unreachable()
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
typedef __INT8_TYPE__ int8_t;
|
|
||||||
typedef __UINT8_TYPE__ uint8_t;
|
|
||||||
#define INT8_MAX __INT8_MAX__
|
|
||||||
#define UINT8_MAX __UINT8_MAX__
|
|
||||||
|
|
||||||
typedef __INT16_TYPE__ int16_t;
|
|
||||||
typedef __UINT16_TYPE__ uint16_t;
|
|
||||||
#define INT16_MAX __INT16_MAX__
|
|
||||||
#define UINT16_MAX __UINT16_MAX__
|
|
||||||
|
|
||||||
typedef __INT32_TYPE__ int32_t;
|
|
||||||
typedef __UINT32_TYPE__ uint32_t;
|
|
||||||
#define INT32_MAX __INT32_MAX__
|
|
||||||
#define UINT32_MAX __UINT32_MAX__
|
|
||||||
|
|
||||||
typedef __INT64_TYPE__ int64_t;
|
|
||||||
typedef __UINT64_TYPE__ uint64_t;
|
|
||||||
#define INT64_MAX __INT64_MAX__
|
|
||||||
#define UINT64_MAX __UINT64_MAX__
|
|
||||||
|
|
||||||
typedef __INTPTR_TYPE__ intptr_t;
|
|
||||||
typedef __UINTPTR_TYPE__ uintptr_t;
|
|
||||||
#define INTPTR_MAX __INTPTR_MAX__
|
|
||||||
#define UINTPTR_MAX __UINTPTR_MAX__
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef intptr_t __ssize_t;
|
||||||
typedef int64_t __off_t;
|
typedef int64_t __off_t;
|
||||||
typedef __off_t __off64_t;
|
typedef __off_t __off64_t;
|
||||||
typedef uintptr_t __blksize_t;
|
typedef uintptr_t __blksize_t;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <zinnia/errno.h>
|
#include <zinnia/errno.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
|
|
||||||
#define hashmap(K, V) \
|
#define hashmap(K, V) \
|
||||||
struct { \
|
struct { \
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
#include <uapi/types.h>
|
#include <uapi/types.h>
|
||||||
|
|
||||||
ASSERT_TYPE(phys_t);
|
ASSERT_TYPE(phys_t);
|
||||||
ASSERT_TYPE(virt_t);
|
|
||||||
|
|
||||||
|
typedef __ssize_t ssize_t;
|
||||||
typedef __off_t off_t;
|
typedef __off_t off_t;
|
||||||
typedef __off64_t off64_t;
|
typedef __off64_t off64_t;
|
||||||
typedef __blksize_t blksize_t;
|
typedef __blksize_t blksize_t;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <zinnia/alloc.h>
|
#include <zinnia/alloc.h>
|
||||||
#include <zinnia/errno.h>
|
#include <zinnia/errno.h>
|
||||||
#include <stddef.h> // IWYU pragma: keep
|
#include <stddef.h> // IWYU pragma: keep
|
||||||
#include <string.h> // IWYU pragma: keep
|
#include <zinnia/string.h> // IWYU pragma: keep
|
||||||
|
|
||||||
#define vec(T) \
|
#define vec(T) \
|
||||||
struct { \
|
struct { \
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ uintptr_t vm_page_addr(struct page* page);
|
|||||||
|
|
||||||
// Allocator for virtual memory.
|
// Allocator for virtual memory.
|
||||||
struct vm_alloc {
|
struct vm_alloc {
|
||||||
virt_t start_page;
|
uintptr_t start_page;
|
||||||
virt_t end_page;
|
uintptr_t end_page;
|
||||||
virt_t next_fit;
|
uintptr_t next_fit;
|
||||||
hashmap(int, void);
|
hashmap(int, void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,6 @@ add_languages('c', native: false, required: true)
|
|||||||
# Check if we're using a sane compiler.
|
# Check if we're using a sane compiler.
|
||||||
c_compiler = meson.get_compiler('c')
|
c_compiler = meson.get_compiler('c')
|
||||||
|
|
||||||
# Check for LP64
|
|
||||||
assert(c_compiler.sizeof('short') == 2)
|
|
||||||
assert(c_compiler.sizeof('int') == 4)
|
|
||||||
assert(c_compiler.sizeof('long') == 8)
|
|
||||||
assert(c_compiler.sizeof('long long') == 8)
|
|
||||||
|
|
||||||
# We require a compiler that supports the GNU C dialect.
|
# We require a compiler that supports the GNU C dialect.
|
||||||
assert(c_compiler.has_define('__GNUC__'))
|
assert(c_compiler.has_define('__GNUC__'))
|
||||||
|
|
||||||
@@ -39,7 +33,6 @@ add_project_arguments(
|
|||||||
'-ffunction-sections',
|
'-ffunction-sections',
|
||||||
'-fdata-sections',
|
'-fdata-sections',
|
||||||
'-ffreestanding',
|
'-ffreestanding',
|
||||||
'-nostdinc', # We provide our own headers.
|
|
||||||
'-fno-stack-protector',
|
'-fno-stack-protector',
|
||||||
language: 'c',
|
language: 'c',
|
||||||
)
|
)
|
||||||
|
|||||||
+20
-26
@@ -17,37 +17,31 @@ const struct syscall syscall_table[256] = {
|
|||||||
#include <zinnia/syscall_list.inc>
|
#include <zinnia/syscall_list.inc>
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Implement this
|
|
||||||
[[gnu::no_caller_saved_registers]]
|
|
||||||
struct syscall_ret syscall_dispatch_fast(
|
|
||||||
uintptr_t a0,
|
|
||||||
uintptr_t a1,
|
|
||||||
uintptr_t a2,
|
|
||||||
uintptr_t a3,
|
|
||||||
uintptr_t a4,
|
|
||||||
uintptr_t a5,
|
|
||||||
size_t num
|
|
||||||
) {
|
|
||||||
// No need to check the table size here. In order to get to this point,
|
|
||||||
// we already have to check if this is a fast syscall.
|
|
||||||
if (syscall_table[num].func == nullptr) {
|
|
||||||
return (struct syscall_ret){.errno = ENOSYS};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct syscall_ret (*func)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t) =
|
|
||||||
syscall_table[num].func;
|
|
||||||
|
|
||||||
return func(a0, a1, a2, a3, a4, a5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syscall_dispatch(struct arch_context* ctx) {
|
void syscall_dispatch(struct arch_context* ctx) {
|
||||||
const size_t num = ctx->ARCH_CTX_NUM;
|
const size_t num = ctx->ARCH_CTX_NUM;
|
||||||
|
|
||||||
if (num >= ARRAY_SIZE(syscall_table) || syscall_table[num].func == nullptr) {
|
if (num >= ARRAY_SIZE(syscall_table) || syscall_table[num].func == nullptr) {
|
||||||
ctx->ARCH_CTX_RET0 = ENOSYS;
|
ctx->ARCH_CTX_RET1 = ENOSYS;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*func)(struct arch_context* ctx) = syscall_table[num].func;
|
struct syscall_ret ret;
|
||||||
func(ctx);
|
if (syscall_table[num].num_args == -1) {
|
||||||
|
struct syscall_ret (*func)(struct arch_context*) = syscall_table[num].func;
|
||||||
|
ret = func(ctx);
|
||||||
|
} else {
|
||||||
|
struct syscall_ret (*func)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t) =
|
||||||
|
syscall_table[num].func;
|
||||||
|
ret = func(
|
||||||
|
ctx->ARCH_CTX_A0,
|
||||||
|
ctx->ARCH_CTX_A1,
|
||||||
|
ctx->ARCH_CTX_A2,
|
||||||
|
ctx->ARCH_CTX_A3,
|
||||||
|
ctx->ARCH_CTX_A4,
|
||||||
|
ctx->ARCH_CTX_A5
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->ARCH_CTX_RET0 = ret.value;
|
||||||
|
ctx->ARCH_CTX_RET1 = ret.errno;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
#include <zinnia/syscall.h>
|
#include <zinnia/syscall.h>
|
||||||
#include <zinnia/usercopy.h>
|
#include <zinnia/usercopy.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <string.h>
|
#include <zinnia/string.h>
|
||||||
#include <uapi/utsname.h>
|
#include <uapi/utsname.h>
|
||||||
|
|
||||||
static struct spinlock uname_lock = {};
|
static struct spinlock uname_lock = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user