Use clang-format
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
#include <limine/limine.h>
|
||||
#include <amd64/init.h>
|
||||
#include <sys/debug.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <limine/limine.h>
|
||||
#include <mm/liballoc.h>
|
||||
#include <mm/pmm.h>
|
||||
#include <sys/debug.h>
|
||||
#include <uacpi/uacpi.h>
|
||||
|
||||
#define UACPI_MEMORY_BUFFER_MAX 4096
|
||||
|
||||
__attribute__((aligned(16))) static uint8_t uacpi_memory_buffer[UACPI_MEMORY_BUFFER_MAX];
|
||||
__attribute__ ((
|
||||
aligned (16))) static uint8_t uacpi_memory_buffer[UACPI_MEMORY_BUFFER_MAX];
|
||||
|
||||
void bootmain(void) {
|
||||
amd64_init();
|
||||
pmm_init();
|
||||
|
||||
uacpi_setup_early_table_access((void *)uacpi_memory_buffer, sizeof(uacpi_memory_buffer));
|
||||
void bootmain (void) {
|
||||
amd64_init ();
|
||||
pmm_init ();
|
||||
|
||||
int *a = malloc(sizeof(int));
|
||||
uacpi_setup_early_table_access (
|
||||
(void*)uacpi_memory_buffer, sizeof (uacpi_memory_buffer));
|
||||
|
||||
int* a = malloc (sizeof (int));
|
||||
*a = 6969;
|
||||
DEBUG("a=%p, *a=%d\n", a, *a);
|
||||
DEBUG ("a=%p, *a=%d\n", a, *a);
|
||||
|
||||
for (;;);
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -1,46 +1,47 @@
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <libk/printf.h>
|
||||
#include <sys/debug.h>
|
||||
#include <amd64/debug.h>
|
||||
#include <amd64/io.h>
|
||||
#include <libk/printf.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
#define PORT_COM1 0x03F8
|
||||
#define PORT_COM1 0x03F8
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
static bool amd64_debug_serial_tx_empty(void) {
|
||||
return (bool)(amd64_io_inb(PORT_COM1 + 5) & 0x20);
|
||||
static bool amd64_debug_serial_tx_empty (void) {
|
||||
return (bool)(amd64_io_inb (PORT_COM1 + 5) & 0x20);
|
||||
}
|
||||
|
||||
static void amd64_debug_serial_write(char x) {
|
||||
while (!amd64_debug_serial_tx_empty());
|
||||
amd64_io_outb(PORT_COM1, (uint8_t)x);
|
||||
static void amd64_debug_serial_write (char x) {
|
||||
while (!amd64_debug_serial_tx_empty ())
|
||||
;
|
||||
amd64_io_outb (PORT_COM1, (uint8_t)x);
|
||||
}
|
||||
|
||||
void debugprintf(const char *fmt, ...) {
|
||||
void debugprintf (const char* fmt, ...) {
|
||||
char buffer[BUFFER_SIZE];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
||||
va_end(ap);
|
||||
va_start (ap, fmt);
|
||||
vsnprintf (buffer, sizeof (buffer), fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
buffer[sizeof(buffer) - 1] = '\0';
|
||||
buffer[sizeof (buffer) - 1] = '\0';
|
||||
|
||||
const char *p = buffer;
|
||||
const char* p = buffer;
|
||||
while (*p) {
|
||||
amd64_debug_serial_write(*p);
|
||||
amd64_debug_serial_write (*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
void amd64_debug_init(void) {
|
||||
amd64_io_outb(PORT_COM1 + 1, 0x00);
|
||||
amd64_io_outb(PORT_COM1 + 3, 0x80);
|
||||
amd64_io_outb(PORT_COM1 + 0, 0x03);
|
||||
amd64_io_outb(PORT_COM1 + 1, 0x00);
|
||||
amd64_io_outb(PORT_COM1 + 3, 0x03);
|
||||
amd64_io_outb(PORT_COM1 + 2, 0xC7);
|
||||
amd64_io_outb(PORT_COM1 + 4, 0x0B);
|
||||
void amd64_debug_init (void) {
|
||||
amd64_io_outb (PORT_COM1 + 1, 0x00);
|
||||
amd64_io_outb (PORT_COM1 + 3, 0x80);
|
||||
amd64_io_outb (PORT_COM1 + 0, 0x03);
|
||||
amd64_io_outb (PORT_COM1 + 1, 0x00);
|
||||
amd64_io_outb (PORT_COM1 + 3, 0x03);
|
||||
amd64_io_outb (PORT_COM1 + 2, 0xC7);
|
||||
amd64_io_outb (PORT_COM1 + 4, 0x0B);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef _KERNEL_AMD64_DEBUG_H
|
||||
#define _KERNEL_AMD64_DEBUG_H
|
||||
|
||||
void amd64_debug_init(void);
|
||||
void amd64_debug_init (void);
|
||||
|
||||
#endif // _KERNEL_AMD64_DEBUG_H
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
#include <amd64/debug.h>
|
||||
#include <amd64/init.h>
|
||||
#include <amd64/intr.h>
|
||||
#include <amd64/tss.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <amd64/init.h>
|
||||
#include <amd64/tss.h>
|
||||
#include <amd64/debug.h>
|
||||
#include <amd64/intr.h>
|
||||
|
||||
#define GDT_KCODE 0x08
|
||||
#define GDT_KDATA 0x10
|
||||
#define GDT_UCODE 0x18
|
||||
#define GDT_UDATA 0x20
|
||||
#define GDT_TSS 0x28
|
||||
#define GDT_KCODE 0x08
|
||||
#define GDT_KDATA 0x10
|
||||
#define GDT_UCODE 0x18
|
||||
#define GDT_UDATA 0x20
|
||||
#define GDT_TSS 0x28
|
||||
|
||||
#define TSS 0x80
|
||||
#define TSS 0x80
|
||||
#define TSS_PRESENT 0x89
|
||||
|
||||
#define KSTACK_SIZE (8*1024)
|
||||
#define KSTACK_SIZE (8 * 1024)
|
||||
|
||||
struct gdt_entry {
|
||||
uint16_t limitlow;
|
||||
@@ -23,24 +23,26 @@ struct gdt_entry {
|
||||
uint8_t access;
|
||||
uint8_t gran;
|
||||
uint8_t basehigh;
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct gdt_ptr {
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct gdt_extended {
|
||||
struct gdt_entry old[5];
|
||||
struct gdt_entry tsslow;
|
||||
struct gdt_entry tsshigh;
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
__attribute__((aligned(16))) static volatile uint8_t kernel_stack[KSTACK_SIZE];
|
||||
__attribute__((aligned(16))) static volatile struct gdt_extended gdt;
|
||||
/* clang-format off */
|
||||
__attribute__ ((aligned (16))) static volatile uint8_t kernel_stack[KSTACK_SIZE];
|
||||
__attribute__ ((aligned (16))) static volatile struct gdt_extended gdt;
|
||||
/* clang-format on */
|
||||
|
||||
static void amd64_gdt_set(volatile struct gdt_entry *ent, uint32_t base,
|
||||
uint32_t limit, uint8_t acc, uint8_t gran) {
|
||||
static void amd64_gdt_set (volatile struct gdt_entry* ent, uint32_t base,
|
||||
uint32_t limit, uint8_t acc, uint8_t gran) {
|
||||
ent->baselow = (base & 0xFFFF);
|
||||
ent->basemid = (base >> 16) & 0xFF;
|
||||
ent->basehigh = (base >> 24) & 0xFF;
|
||||
@@ -49,25 +51,26 @@ static void amd64_gdt_set(volatile struct gdt_entry *ent, uint32_t base,
|
||||
ent->access = acc;
|
||||
}
|
||||
|
||||
static void amd64_gdt_init(void) {
|
||||
volatile struct tss *tss = amd64_get_tss();
|
||||
static void amd64_gdt_init (void) {
|
||||
volatile struct tss* tss = amd64_get_tss ();
|
||||
|
||||
memset((void *)&gdt, 0, sizeof(gdt));
|
||||
memset((void *)kernel_stack, 0, sizeof(kernel_stack));
|
||||
memset((void *)tss, 0, sizeof(*tss));
|
||||
memset ((void*)&gdt, 0, sizeof (gdt));
|
||||
memset ((void*)kernel_stack, 0, sizeof (kernel_stack));
|
||||
memset ((void*)tss, 0, sizeof (*tss));
|
||||
|
||||
tss->iopb_off = sizeof(*tss);
|
||||
tss->rsp0 = (uint64_t)((uintptr_t)kernel_stack + sizeof(kernel_stack));
|
||||
tss->iopb_off = sizeof (*tss);
|
||||
tss->rsp0 = (uint64_t)((uintptr_t)kernel_stack + sizeof (kernel_stack));
|
||||
|
||||
uint64_t tssbase = (uint64_t)&tss;
|
||||
uint64_t tsslimit = sizeof(*tss) - 1;
|
||||
uint64_t tsslimit = sizeof (*tss) - 1;
|
||||
|
||||
amd64_gdt_set(&gdt.old[0], 0, 0, 0, 0);
|
||||
amd64_gdt_set(&gdt.old[1], 0, 0xFFFFF, 0x9A, 0xA0);
|
||||
amd64_gdt_set(&gdt.old[2], 0, 0xFFFFF, 0x92, 0xC0);
|
||||
amd64_gdt_set(&gdt.old[3], 0, 0xFFFFF, 0xFA, 0xA0);
|
||||
amd64_gdt_set(&gdt.old[4], 0, 0xFFFFF, 0xF2, 0xC0);
|
||||
amd64_gdt_set(&gdt.tsslow, (tssbase & 0xFFFFFFFF), tsslimit, TSS_PRESENT | TSS, 0);
|
||||
amd64_gdt_set (&gdt.old[0], 0, 0, 0, 0);
|
||||
amd64_gdt_set (&gdt.old[1], 0, 0xFFFFF, 0x9A, 0xA0);
|
||||
amd64_gdt_set (&gdt.old[2], 0, 0xFFFFF, 0x92, 0xC0);
|
||||
amd64_gdt_set (&gdt.old[3], 0, 0xFFFFF, 0xFA, 0xA0);
|
||||
amd64_gdt_set (&gdt.old[4], 0, 0xFFFFF, 0xF2, 0xC0);
|
||||
amd64_gdt_set (
|
||||
&gdt.tsslow, (tssbase & 0xFFFFFFFF), tsslimit, TSS_PRESENT | TSS, 0);
|
||||
|
||||
uint32_t tssbasehigh = (tssbase >> 32);
|
||||
gdt.tsshigh.limitlow = (tssbasehigh & 0xFFFF);
|
||||
@@ -78,30 +81,28 @@ static void amd64_gdt_init(void) {
|
||||
gdt.tsshigh.gran = 0;
|
||||
|
||||
struct gdt_ptr gdtr;
|
||||
gdtr.limit = sizeof(gdt) - 1;
|
||||
gdtr.limit = sizeof (gdt) - 1;
|
||||
gdtr.base = (uint64_t)&gdt;
|
||||
__asm__ volatile("lgdt %0" :: "m"(gdtr) : "memory");
|
||||
__asm__ volatile ("lgdt %0" ::"m"(gdtr) : "memory");
|
||||
|
||||
__asm__ volatile(
|
||||
"pushq %[kcode]\n"
|
||||
"lea 1f(%%rip), %%rax\n"
|
||||
"pushq %%rax\n"
|
||||
"lretq\n"
|
||||
"1:\n"
|
||||
"movw %[kdata], %%ax\n"
|
||||
"movw %%ax, %%ds\n"
|
||||
"movw %%ax, %%es\n"
|
||||
"movw %%ax, %%ss\n"
|
||||
:
|
||||
: [kcode] "i"(GDT_KCODE), [kdata] "i"(GDT_KDATA)
|
||||
: "rax", "memory"
|
||||
);
|
||||
__asm__ volatile ("pushq %[kcode]\n"
|
||||
"lea 1f(%%rip), %%rax\n"
|
||||
"pushq %%rax\n"
|
||||
"lretq\n"
|
||||
"1:\n"
|
||||
"movw %[kdata], %%ax\n"
|
||||
"movw %%ax, %%ds\n"
|
||||
"movw %%ax, %%es\n"
|
||||
"movw %%ax, %%ss\n"
|
||||
:
|
||||
: [kcode] "i"(GDT_KCODE), [kdata] "i"(GDT_KDATA)
|
||||
: "rax", "memory");
|
||||
|
||||
__asm__ volatile("ltr %0" :: "r"((uint16_t)GDT_TSS));
|
||||
__asm__ volatile ("ltr %0" ::"r"((uint16_t)GDT_TSS));
|
||||
}
|
||||
|
||||
void amd64_init(void) {
|
||||
amd64_gdt_init();
|
||||
amd64_debug_init();
|
||||
amd64_intr_init();
|
||||
void amd64_init (void) {
|
||||
amd64_gdt_init ();
|
||||
amd64_debug_init ();
|
||||
amd64_intr_init ();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef _KERNEL_AMD64_INIT_H
|
||||
#define _KERNEL_AMD64_INIT_H
|
||||
|
||||
void amd64_init(void);
|
||||
void amd64_init (void);
|
||||
|
||||
#endif // _KERNEL_AMD64_INIT_H
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
#include <amd64/intr.h>
|
||||
#include <amd64/io.h>
|
||||
#include <libk/std.h>
|
||||
#include <libk/string.h>
|
||||
#include <sys/debug.h>
|
||||
#include <amd64/intr.h>
|
||||
#include <amd64/io.h>
|
||||
|
||||
/* 8259 PIC defs. */
|
||||
#define PIC1 0x20
|
||||
#define PIC2 0xA0
|
||||
#define PIC1_CMD PIC1
|
||||
#define PIC1_DATA (PIC1 + 1)
|
||||
#define PIC2_CMD PIC2
|
||||
#define PIC2_DATA (PIC2 + 1)
|
||||
#define PIC_EOI 0x20
|
||||
#define PIC1 0x20
|
||||
#define PIC2 0xA0
|
||||
#define PIC1_CMD PIC1
|
||||
#define PIC1_DATA (PIC1 + 1)
|
||||
#define PIC2_CMD PIC2
|
||||
#define PIC2_DATA (PIC2 + 1)
|
||||
#define PIC_EOI 0x20
|
||||
|
||||
#define ICW1_ICW4 0x01
|
||||
#define ICW1_SINGLE 0x02
|
||||
#define ICW1_INTVL4 0x04
|
||||
#define ICW1_LEVEL 0x08
|
||||
#define ICW1_INIT 0x10
|
||||
#define ICW1_ICW4 0x01
|
||||
#define ICW1_SINGLE 0x02
|
||||
#define ICW1_INTVL4 0x04
|
||||
#define ICW1_LEVEL 0x08
|
||||
#define ICW1_INIT 0x10
|
||||
|
||||
#define ICW4_8086 0x01
|
||||
#define ICW4_AUTO 0x02
|
||||
#define ICW4_8086 0x01
|
||||
#define ICW4_AUTO 0x02
|
||||
#define ICW4_BUFSLAVE 0x08
|
||||
#define ICW4_BUFMASER 0x0C
|
||||
#define ICW4_SFNM 0x10
|
||||
#define ICW4_SFNM 0x10
|
||||
|
||||
#define CASCADE_IRQ 2
|
||||
#define CASCADE_IRQ 2
|
||||
|
||||
/* IDT defs. */
|
||||
|
||||
@@ -39,42 +39,46 @@ struct idt_entry {
|
||||
uint16_t intrmid;
|
||||
uint32_t intrhigh;
|
||||
uint32_t resv;
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct idt {
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
__attribute__((aligned(16))) static volatile struct idt_entry idt_entries[IDT_ENTRIES_MAX];
|
||||
__attribute__ ((aligned (
|
||||
16))) static volatile struct idt_entry idt_entries[IDT_ENTRIES_MAX];
|
||||
static volatile struct idt idt;
|
||||
|
||||
extern void amd64_spin(void);
|
||||
extern void amd64_spin (void);
|
||||
|
||||
/* Remaps and disables old 8259 PIC, since we'll be using APIC. */
|
||||
static void amd64_init_pic(void) {
|
||||
#define IO_OP(fn, ...) fn(__VA_ARGS__); amd64_io_wait()
|
||||
static void amd64_init_pic (void) {
|
||||
#define IO_OP(fn, ...) \
|
||||
fn (__VA_ARGS__); \
|
||||
amd64_io_wait ()
|
||||
|
||||
IO_OP(amd64_io_outb, PIC1_CMD, (ICW1_INIT | ICW1_ICW4));
|
||||
IO_OP(amd64_io_outb, PIC2_CMD, (ICW1_INIT | ICW1_ICW4));
|
||||
IO_OP (amd64_io_outb, PIC1_CMD, (ICW1_INIT | ICW1_ICW4));
|
||||
IO_OP (amd64_io_outb, PIC2_CMD, (ICW1_INIT | ICW1_ICW4));
|
||||
|
||||
IO_OP(amd64_io_outb, PIC1_DATA, 0x20);
|
||||
IO_OP(amd64_io_outb, PIC2_DATA, 0x28);
|
||||
IO_OP (amd64_io_outb, PIC1_DATA, 0x20);
|
||||
IO_OP (amd64_io_outb, PIC2_DATA, 0x28);
|
||||
|
||||
IO_OP(amd64_io_outb, PIC1_DATA, (1 << CASCADE_IRQ));
|
||||
IO_OP(amd64_io_outb, PIC2_DATA, 2);
|
||||
IO_OP (amd64_io_outb, PIC1_DATA, (1 << CASCADE_IRQ));
|
||||
IO_OP (amd64_io_outb, PIC2_DATA, 2);
|
||||
|
||||
IO_OP(amd64_io_outb, PIC1_DATA, ICW4_8086);
|
||||
IO_OP(amd64_io_outb, PIC2_DATA, ICW4_8086);
|
||||
IO_OP (amd64_io_outb, PIC1_DATA, ICW4_8086);
|
||||
IO_OP (amd64_io_outb, PIC2_DATA, ICW4_8086);
|
||||
|
||||
/* Disable */
|
||||
IO_OP(amd64_io_outb, PIC1_DATA, 0xFF);
|
||||
IO_OP(amd64_io_outb, PIC2_DATA, 0xFF);
|
||||
IO_OP (amd64_io_outb, PIC1_DATA, 0xFF);
|
||||
IO_OP (amd64_io_outb, PIC2_DATA, 0xFF);
|
||||
|
||||
#undef IO_OP
|
||||
}
|
||||
|
||||
static void amd64_idt_set(volatile struct idt_entry *ent, uint64_t handler, uint8_t flags) {
|
||||
static void amd64_idt_set (
|
||||
volatile struct idt_entry* ent, uint64_t handler, uint8_t flags) {
|
||||
ent->intrlow = (handler & 0xFFFF);
|
||||
ent->kernel_cs = 0x08; // GDT_KCODE (init.c)
|
||||
ent->ist = 0;
|
||||
@@ -84,74 +88,104 @@ static void amd64_idt_set(volatile struct idt_entry *ent, uint64_t handler, uint
|
||||
ent->resv = 0;
|
||||
}
|
||||
|
||||
static void amd64_idt_init(void) {
|
||||
memset((void *)idt_entries, 0, sizeof(idt_entries));
|
||||
static void amd64_idt_init (void) {
|
||||
memset ((void*)idt_entries, 0, sizeof (idt_entries));
|
||||
|
||||
#define IDT_ENTRY(n) \
|
||||
extern void amd64_intr ## n(void); \
|
||||
amd64_idt_set(&idt_entries[(n)], (uint64_t)&amd64_intr ## n, 0x8E)
|
||||
IDT_ENTRY(0); IDT_ENTRY(1); IDT_ENTRY(2); IDT_ENTRY(3);
|
||||
IDT_ENTRY(4); IDT_ENTRY(5); IDT_ENTRY(6); IDT_ENTRY(7);
|
||||
IDT_ENTRY(8); IDT_ENTRY(9); IDT_ENTRY(10); IDT_ENTRY(11);
|
||||
IDT_ENTRY(12); IDT_ENTRY(13); IDT_ENTRY(14); IDT_ENTRY(15);
|
||||
IDT_ENTRY(16); IDT_ENTRY(17); IDT_ENTRY(18); IDT_ENTRY(19);
|
||||
IDT_ENTRY(20); IDT_ENTRY(21); IDT_ENTRY(22); IDT_ENTRY(23);
|
||||
IDT_ENTRY(24); IDT_ENTRY(25); IDT_ENTRY(26); IDT_ENTRY(27);
|
||||
IDT_ENTRY(28); IDT_ENTRY(29); IDT_ENTRY(30); IDT_ENTRY(31);
|
||||
IDT_ENTRY(32); IDT_ENTRY(33); IDT_ENTRY(34); IDT_ENTRY(35);
|
||||
IDT_ENTRY(36); IDT_ENTRY(37); IDT_ENTRY(38); IDT_ENTRY(39);
|
||||
IDT_ENTRY(40); IDT_ENTRY(41); IDT_ENTRY(42); IDT_ENTRY(43);
|
||||
IDT_ENTRY(44); IDT_ENTRY(45); IDT_ENTRY(46); IDT_ENTRY(47);
|
||||
#define IDT_ENTRY(n) \
|
||||
extern void amd64_intr##n (void); \
|
||||
amd64_idt_set (&idt_entries[(n)], (uint64_t)&amd64_intr##n, 0x8E)
|
||||
IDT_ENTRY (0);
|
||||
IDT_ENTRY (1);
|
||||
IDT_ENTRY (2);
|
||||
IDT_ENTRY (3);
|
||||
IDT_ENTRY (4);
|
||||
IDT_ENTRY (5);
|
||||
IDT_ENTRY (6);
|
||||
IDT_ENTRY (7);
|
||||
IDT_ENTRY (8);
|
||||
IDT_ENTRY (9);
|
||||
IDT_ENTRY (10);
|
||||
IDT_ENTRY (11);
|
||||
IDT_ENTRY (12);
|
||||
IDT_ENTRY (13);
|
||||
IDT_ENTRY (14);
|
||||
IDT_ENTRY (15);
|
||||
IDT_ENTRY (16);
|
||||
IDT_ENTRY (17);
|
||||
IDT_ENTRY (18);
|
||||
IDT_ENTRY (19);
|
||||
IDT_ENTRY (20);
|
||||
IDT_ENTRY (21);
|
||||
IDT_ENTRY (22);
|
||||
IDT_ENTRY (23);
|
||||
IDT_ENTRY (24);
|
||||
IDT_ENTRY (25);
|
||||
IDT_ENTRY (26);
|
||||
IDT_ENTRY (27);
|
||||
IDT_ENTRY (28);
|
||||
IDT_ENTRY (29);
|
||||
IDT_ENTRY (30);
|
||||
IDT_ENTRY (31);
|
||||
IDT_ENTRY (32);
|
||||
IDT_ENTRY (33);
|
||||
IDT_ENTRY (34);
|
||||
IDT_ENTRY (35);
|
||||
IDT_ENTRY (36);
|
||||
IDT_ENTRY (37);
|
||||
IDT_ENTRY (38);
|
||||
IDT_ENTRY (39);
|
||||
IDT_ENTRY (40);
|
||||
IDT_ENTRY (41);
|
||||
IDT_ENTRY (42);
|
||||
IDT_ENTRY (43);
|
||||
IDT_ENTRY (44);
|
||||
IDT_ENTRY (45);
|
||||
IDT_ENTRY (46);
|
||||
IDT_ENTRY (47);
|
||||
#undef IDT_ENTRY
|
||||
|
||||
idt.limit = sizeof(idt_entries) - 1;
|
||||
idt.limit = sizeof (idt_entries) - 1;
|
||||
idt.base = (uint64_t)idt_entries;
|
||||
|
||||
__asm__ volatile("lidt %0" :: "m"(idt));
|
||||
__asm__ volatile("sti");
|
||||
__asm__ volatile ("lidt %0" ::"m"(idt));
|
||||
__asm__ volatile ("sti");
|
||||
}
|
||||
|
||||
static void amd64_intr_exception(struct saved_regs *regs) {
|
||||
DEBUG("cpu exception %lu (%lu)\n", regs->trap, regs->error);
|
||||
static void amd64_intr_exception (struct saved_regs* regs) {
|
||||
DEBUG ("cpu exception %lu (%lu)\n", regs->trap, regs->error);
|
||||
|
||||
uint64_t cr2;
|
||||
__asm__ volatile("movq %%cr2, %0" : "=r"(cr2));
|
||||
__asm__ volatile ("movq %%cr2, %0" : "=r"(cr2));
|
||||
uint64_t cr3;
|
||||
__asm__ volatile("movq %%cr3, %0" : "=r"(cr3));
|
||||
__asm__ volatile ("movq %%cr3, %0" : "=r"(cr3));
|
||||
|
||||
debugprintf(
|
||||
"r15=%016lx r14=%016lx r13=%016lx\n"
|
||||
"r12=%016lx r11=%016lx r10=%016lx\n"
|
||||
"r9 =%016lx r8 =%016lx rbp=%016lx\n"
|
||||
"rdi=%016lx rsi=%016lx rdx=%016lx\n"
|
||||
"rcx=%016lx rax=%016lx trp=%016lx\n"
|
||||
"err=%016lx rip=%016lx cs =%016lx\n"
|
||||
"rfl=%016lx rsp=%016lx ss =%016lx\n"
|
||||
"cr2=%016lx cr3=%016lx rbx=%016lx\n",
|
||||
regs->r15, regs->r14, regs->r13,
|
||||
regs->r12, regs->r11, regs->r10,
|
||||
regs->r9, regs->r8, regs->rbp,
|
||||
regs->rdi, regs->rsi, regs->rdx,
|
||||
regs->rcx, regs->rax, regs->trap,
|
||||
regs->error, regs->rip, regs->cs,
|
||||
regs->rflags, regs->rsp, regs->ss,
|
||||
cr2, cr3, regs->rbx
|
||||
);
|
||||
debugprintf ("r15=%016lx r14=%016lx r13=%016lx\n"
|
||||
"r12=%016lx r11=%016lx r10=%016lx\n"
|
||||
"r9 =%016lx r8 =%016lx rbp=%016lx\n"
|
||||
"rdi=%016lx rsi=%016lx rdx=%016lx\n"
|
||||
"rcx=%016lx rax=%016lx trp=%016lx\n"
|
||||
"err=%016lx rip=%016lx cs =%016lx\n"
|
||||
"rfl=%016lx rsp=%016lx ss =%016lx\n"
|
||||
"cr2=%016lx cr3=%016lx rbx=%016lx\n",
|
||||
regs->r15, regs->r14, regs->r13, regs->r12, regs->r11, regs->r10,
|
||||
regs->r9, regs->r8, regs->rbp, regs->rdi, regs->rsi, regs->rdx, regs->rcx,
|
||||
regs->rax, regs->trap, regs->error, regs->rip, regs->cs, regs->rflags,
|
||||
regs->rsp, regs->ss, cr2, cr3, regs->rbx);
|
||||
|
||||
amd64_spin();
|
||||
amd64_spin ();
|
||||
}
|
||||
|
||||
void amd64_intr_handler(void *stack_ptr) {
|
||||
struct saved_regs *regs = stack_ptr;
|
||||
void amd64_intr_handler (void* stack_ptr) {
|
||||
struct saved_regs* regs = stack_ptr;
|
||||
|
||||
if (regs->trap <= 31) {
|
||||
amd64_intr_exception(regs);
|
||||
amd64_intr_exception (regs);
|
||||
} else {
|
||||
DEBUG("unknown trap %lu\n", regs->trap);
|
||||
DEBUG ("unknown trap %lu\n", regs->trap);
|
||||
}
|
||||
}
|
||||
|
||||
void amd64_intr_init(void) {
|
||||
amd64_init_pic();
|
||||
amd64_idt_init();
|
||||
void amd64_intr_init (void) {
|
||||
amd64_init_pic ();
|
||||
amd64_idt_init ();
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ struct saved_regs {
|
||||
uint64_t rflags;
|
||||
uint64_t rsp;
|
||||
uint64_t ss;
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
void amd64_intr_init(void);
|
||||
void amd64_intr_init (void);
|
||||
|
||||
#endif // _KERNEL_AMD64_INTR_H
|
||||
|
||||
@@ -1,54 +1,48 @@
|
||||
#include <libk/std.h>
|
||||
#include <amd64/io.h>
|
||||
#include <libk/std.h>
|
||||
|
||||
void amd64_io_outb(uint16_t port, uint8_t v) {
|
||||
__asm__ volatile("outb %1, %0" :: "dN"(port), "a"(v));
|
||||
void amd64_io_outb (uint16_t port, uint8_t v) {
|
||||
__asm__ volatile ("outb %1, %0" ::"dN"(port), "a"(v));
|
||||
}
|
||||
|
||||
void amd64_io_outw(uint16_t port, uint16_t v) {
|
||||
__asm__ volatile("outw %%ax, %%dx" :: "a"(v), "d"(port));
|
||||
void amd64_io_outw (uint16_t port, uint16_t v) {
|
||||
__asm__ volatile ("outw %%ax, %%dx" ::"a"(v), "d"(port));
|
||||
}
|
||||
|
||||
void amd64_io_outl(uint16_t port, uint32_t v) {
|
||||
__asm__ volatile("outl %%eax, %%dx" :: "d"(port), "a"(v));
|
||||
void amd64_io_outl (uint16_t port, uint32_t v) {
|
||||
__asm__ volatile ("outl %%eax, %%dx" ::"d"(port), "a"(v));
|
||||
}
|
||||
|
||||
void amd64_io_outsw(uint16_t port, const void *addr, int cnt) {
|
||||
__asm__ volatile(
|
||||
"cld; rep outsw"
|
||||
: "+S"(addr), "+c"(cnt)
|
||||
: "d"(port)
|
||||
: "memory", "cc"
|
||||
);
|
||||
void amd64_io_outsw (uint16_t port, const void* addr, int cnt) {
|
||||
__asm__ volatile ("cld; rep outsw"
|
||||
: "+S"(addr), "+c"(cnt)
|
||||
: "d"(port)
|
||||
: "memory", "cc");
|
||||
}
|
||||
|
||||
uint8_t amd64_io_inb(uint16_t port) {
|
||||
uint8_t amd64_io_inb (uint16_t port) {
|
||||
uint8_t r;
|
||||
__asm__ volatile("inb %1, %0" : "=a"(r) : "dN"(port));
|
||||
__asm__ volatile ("inb %1, %0" : "=a"(r) : "dN"(port));
|
||||
return r;
|
||||
}
|
||||
|
||||
uint16_t amd64_io_inw(uint16_t port) {
|
||||
uint16_t amd64_io_inw (uint16_t port) {
|
||||
uint16_t r;
|
||||
__asm__ volatile("inw %%dx, %%ax" : "=a"(r) : "d"(port));
|
||||
__asm__ volatile ("inw %%dx, %%ax" : "=a"(r) : "d"(port));
|
||||
return r;
|
||||
}
|
||||
|
||||
uint32_t amd64_io_inl(uint16_t port) {
|
||||
uint32_t amd64_io_inl (uint16_t port) {
|
||||
uint32_t r;
|
||||
__asm__ volatile("inl %%dx, %%eax" : "=a"(r) : "d"(port));
|
||||
__asm__ volatile ("inl %%dx, %%eax" : "=a"(r) : "d"(port));
|
||||
return r;
|
||||
}
|
||||
|
||||
void amd64_io_insw(uint16_t port, void *addr, int cnt) {
|
||||
__asm__ volatile(
|
||||
"cld; rep insw"
|
||||
: "+D"(addr), "+c"(cnt)
|
||||
: "d"(port)
|
||||
: "memory", "cc"
|
||||
);
|
||||
void amd64_io_insw (uint16_t port, void* addr, int cnt) {
|
||||
__asm__ volatile ("cld; rep insw"
|
||||
: "+D"(addr), "+c"(cnt)
|
||||
: "d"(port)
|
||||
: "memory", "cc");
|
||||
}
|
||||
|
||||
void amd64_io_wait(void) {
|
||||
amd64_io_outb(0x80, 0);
|
||||
}
|
||||
void amd64_io_wait (void) { amd64_io_outb (0x80, 0); }
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
#include <libk/std.h>
|
||||
|
||||
void amd64_io_outb(uint16_t port, uint8_t v);
|
||||
void amd64_io_outw(uint16_t port, uint16_t v);
|
||||
void amd64_io_outl(uint16_t port, uint32_t v);
|
||||
void amd64_io_outsw(uint16_t port, const void *addr, int cnt);
|
||||
uint8_t amd64_io_inb(uint16_t port);
|
||||
uint16_t amd64_io_inw(uint16_t port);
|
||||
uint32_t amd64_io_inl(uint16_t port);
|
||||
void amd64_io_insw(uint16_t port, void *addr, int cnt);
|
||||
void amd64_io_wait(void);
|
||||
void amd64_io_outb (uint16_t port, uint8_t v);
|
||||
void amd64_io_outw (uint16_t port, uint16_t v);
|
||||
void amd64_io_outl (uint16_t port, uint32_t v);
|
||||
void amd64_io_outsw (uint16_t port, const void* addr, int cnt);
|
||||
uint8_t amd64_io_inb (uint16_t port);
|
||||
uint16_t amd64_io_inw (uint16_t port);
|
||||
uint32_t amd64_io_inl (uint16_t port);
|
||||
void amd64_io_insw (uint16_t port, void* addr, int cnt);
|
||||
void amd64_io_wait (void);
|
||||
|
||||
#endif // _KERNEL_AMD64_IO_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifndef _KERNEL_AMD64_MM_H
|
||||
#define _KERNEL_AMD64_MM_H
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
#endif // _KERNEL_AMD64_MM_H
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#include <sys/spin_lock.h>
|
||||
|
||||
void spin_lock_relax(void) {
|
||||
__asm__ volatile("pause");
|
||||
}
|
||||
void spin_lock_relax (void) { __asm__ volatile ("pause"); }
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include <libk/std.h>
|
||||
#include <amd64/tss.h>
|
||||
#include <libk/std.h>
|
||||
|
||||
__attribute__((aligned(16))) static volatile struct tss tss;
|
||||
__attribute__ ((aligned (16))) static volatile struct tss tss;
|
||||
|
||||
volatile struct tss *amd64_get_tss(void) {
|
||||
return &tss;
|
||||
}
|
||||
volatile struct tss* amd64_get_tss (void) { return &tss; }
|
||||
|
||||
@@ -13,8 +13,8 @@ struct tss {
|
||||
uint64_t resv2;
|
||||
uint16_t resv3;
|
||||
uint16_t iopb_off;
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
volatile struct tss *amd64_get_tss(void);
|
||||
volatile struct tss* amd64_get_tss (void);
|
||||
|
||||
#endif // _KERNEL_AMD64_TSS_H
|
||||
|
||||
Reference in New Issue
Block a user