summaryrefslogtreecommitdiff
path: root/src/arch/amd64
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/arch/amd64/acpi.c14
-rw-r--r--src/arch/amd64/backtrace.c6
-rw-r--r--src/arch/amd64/boot.S30
-rw-r--r--src/arch/amd64/fb.c4
-rw-r--r--src/arch/amd64/idt.c6
-rw-r--r--src/arch/amd64/mboot.c112
-rw-r--r--src/arch/amd64/paging.c69
-rw-r--r--src/arch/amd64/paging.h2
-rw-r--r--src/arch/amd64/pic.c6
-rw-r--r--src/arch/amd64/serial.c8
-rw-r--r--src/arch/amd64/shim.c2
11 files changed, 109 insertions, 150 deletions
diff --git a/src/arch/amd64/acpi.c b/src/arch/amd64/acpi.c
index 70c2f38..d476ac8 100644
--- a/src/arch/amd64/acpi.c
+++ b/src/arch/amd64/acpi.c
@@ -162,13 +162,13 @@ static bool checksum(uint8_t *data, size_t len) {
static int read_s5_addr(struct acpi_state *state) {
uintptr_t ptr = state->fadt.dsdt;
- char *s5_addr = (void*) (ptr + 36);
+ char *s5_addr = (void *) (ptr + 36);
- int dsdt_len = *((int*) (ptr+1)) - 36;
+ int dsdt_len = *((int *) (ptr+1)) - 36;
while (0 < dsdt_len--) {
- if ( memcmp(s5_addr, "_S5_", 4) == 0)
- break;
- s5_addr++;
+ if (memcmp(s5_addr, "_S5_", 4) == 0)
+ break;
+ s5_addr++;
}
if (dsdt_len > 0) {
@@ -178,12 +178,12 @@ static int read_s5_addr(struct acpi_state *state) {
s5_addr += ((*s5_addr &0xC0)>>6) +2; // calculate PkgLength size
if (*s5_addr == 0x0A)
- s5_addr++; // skip byteprefix
+ s5_addr++; // skip byteprefix
state->SLP_TYPa = *(s5_addr)<<10;
s5_addr++;
if (*s5_addr == 0x0A)
- s5_addr++; // skip byteprefix
+ s5_addr++; // skip byteprefix
state->SLP_TYPb = *(s5_addr)<<10;
state->SLP_EN = 1<<13;
diff --git a/src/arch/amd64/backtrace.c b/src/arch/amd64/backtrace.c
index c882fa0..a5e8ffd 100644
--- a/src/arch/amd64/backtrace.c
+++ b/src/arch/amd64/backtrace.c
@@ -16,11 +16,11 @@ size_t backtrace(void **dst, size_t len) {
size_t backtrace_ex(void **dst, size_t len, void *ip, void *bp) {
struct stackframe *frame = bp;
__asm__ volatile ("mov %%rbp, %0" : "=r"(frame));
- if(len > 0) {
+ if (len > 0) {
dst[0] = ip;
}
size_t i;
- for(i = 1; frame && i < len; i++) {
+ for (i = 1; frame && i < len; i++) {
dst[i] = frame->rip;
frame = frame->rbp;
}
@@ -42,7 +42,7 @@ void log_backtrace_ex(void *ip, void *bp) {
serial_out_str(" 0x");
serial_out_str(buf);
serial_out_str("\n");
- while(frame) {
+ while (frame) {
ultoa((size_t)frame->rip, buf, 16);
serial_out_str(" 0x");
serial_out_str(buf);
diff --git a/src/arch/amd64/boot.S b/src/arch/amd64/boot.S
index 455b68b..d96e4ba 100644
--- a/src/arch/amd64/boot.S
+++ b/src/arch/amd64/boot.S
@@ -61,25 +61,25 @@ LONG_MODE equ 1 << 5
GDT:
.Null: equ $ - GDT
- dq 0
+ dq 0
.Code: equ $ - GDT
- dd 0xFFFF ; Limit & Base (low, bits 0-15)
- db 0 ; Base (mid, bits 16-23)
- db PRESENT | NOT_SYS | EXEC | RW ; Access
- db GRAN_4K | LONG_MODE | 0xF ; Flags & Limit (high, bits 16-19)
- db 0 ; Base (high, bits 24-31)
+ dd 0xFFFF ; Limit & Base (low, bits 0-15)
+ db 0 ; Base (mid, bits 16-23)
+ db PRESENT | NOT_SYS | EXEC | RW ; Access
+ db GRAN_4K | LONG_MODE | 0xF ; Flags & Limit (high, bits 16-19)
+ db 0 ; Base (high, bits 24-31)
.Data: equ $ - GDT
- dd 0xFFFF ; Limit & Base (low, bits 0-15)
- db 0 ; Base (mid, bits 16-23)
- db PRESENT | NOT_SYS | RW ; Access
- db GRAN_4K | SZ_32 | 0xF ; Flags & Limit (high, bits 16-19)
- db 0 ; Base (high, bits 24-31)
+ dd 0xFFFF ; Limit & Base (low, bits 0-15)
+ db 0 ; Base (mid, bits 16-23)
+ db PRESENT | NOT_SYS | RW ; Access
+ db GRAN_4K | SZ_32 | 0xF ; Flags & Limit (high, bits 16-19)
+ db 0 ; Base (high, bits 24-31)
.TSS: equ $ - GDT
- dd 0x00000068
- dd 0x00CF8900
+ dd 0x00000068
+ dd 0x00CF8900
.Pointer:
- dw $ - GDT - 1
- dq GDT
+ dw $ - GDT - 1
+ dq GDT
section .text
align 8
diff --git a/src/arch/amd64/fb.c b/src/arch/amd64/fb.c
index 0cd5b4f..9dd2ddf 100644
--- a/src/arch/amd64/fb.c
+++ b/src/arch/amd64/fb.c
@@ -9,8 +9,8 @@
#define INDEX 0x1CE
#define DATA 0x1CF
#define FB_ADDR 0xE0000000
-#define FB_MAX 0xFF000000
-#define FB_LEN (FB_MAX - FB_ADDR)
+#define FB_MAX 0xFF000000
+#define FB_LEN (FB_MAX - FB_ADDR)
#define PREFERRED_VY 4096
#define PREFERRED_B 32
diff --git a/src/arch/amd64/idt.c b/src/arch/amd64/idt.c
index b4a11bb..583b8a9 100644
--- a/src/arch/amd64/idt.c
+++ b/src/arch/amd64/idt.c
@@ -53,8 +53,8 @@ void idt_init(void) {
idtr.size = (uint16_t)sizeof(struct idt_entry) * IDT_SIZE - 1;
// initialize idt
- for(size_t vector = 0; vector < IDT_SIZE; vector++) {
- struct idt_entry* entry = &idt[vector];
+ for (size_t vector = 0; vector < IDT_SIZE; vector++) {
+ struct idt_entry *entry = &idt[vector];
uint64_t isr = (uint64_t)isr_stub_table[vector];
// interrupts before 0x20 are for cpu exceptions
@@ -120,7 +120,7 @@ void idt_exception_handler(uint64_t exception, uint64_t code, void *rip, void *r
strcat(msg, buf);
// page faults store the offending address in cr2
- if(exception == 0x0E) {
+ if (exception == 0x0E) {
strcat(msg, "\nPage fault address: 0x");
void *addr;
__asm__ volatile ("mov %%cr2, %0" : "=r"(addr));
diff --git a/src/arch/amd64/mboot.c b/src/arch/amd64/mboot.c
index b7124df..f39dd79 100644
--- a/src/arch/amd64/mboot.c
+++ b/src/arch/amd64/mboot.c
@@ -13,81 +13,73 @@
#define MBOOT_OLD_RSDP 14
#define MBOOT_NEW_RSDP 15
-extern char symtab;
-#define kaddr(addr) ((uintptr_t)(&addr))
-
-typedef uint8_t mboot_uint8_t;
-typedef uint16_t mboot_uint16_t;
-typedef uint32_t mboot_uint32_t;
-typedef uint64_t mboot_uint64_t;
-
struct mboot_info {
- mboot_uint32_t total_size;
- mboot_uint32_t reserved;
+ uint32_t total_size;
+ uint32_t reserved;
char tags[];
};
struct mboot_tag {
- mboot_uint32_t type;
- mboot_uint32_t size;
+ uint32_t type;
+ uint32_t size;
char data[];
};
struct mboot_tag_elf_sections {
- mboot_uint32_t type;
- mboot_uint32_t size;
- mboot_uint16_t num;
- mboot_uint16_t entsize;
- mboot_uint16_t shndx;
- mboot_uint16_t reserved;
+ uint32_t type;
+ uint32_t size;
+ uint16_t num;
+ uint16_t entsize;
+ uint16_t shndx;
+ uint16_t reserved;
char sections[];
};
struct mboot_tag_elf_sections_entry {
- mboot_uint32_t sh_name;
- mboot_uint32_t sh_type;
- mboot_uint64_t sh_flags;
- mboot_uint64_t sh_addr;
- mboot_uint64_t sh_offset;
- mboot_uint64_t sh_size;
- mboot_uint32_t sh_link;
- mboot_uint32_t sh_info;
- mboot_uint64_t sh_addralign;
- mboot_uint64_t sh_entsize;
+ uint32_t sh_name;
+ uint32_t sh_type;
+ uint64_t sh_flags;
+ uint64_t sh_addr;
+ uint64_t sh_offset;
+ uint64_t sh_size;
+ uint32_t sh_link;
+ uint32_t sh_info;
+ uint64_t sh_addralign;
+ uint64_t sh_entsize;
};
struct mboot_mmap_entry {
- mboot_uint64_t addr;
- mboot_uint64_t len;
- mboot_uint32_t type;
- mboot_uint32_t zero;
+ uint64_t addr;
+ uint64_t len;
+ uint32_t type;
+ uint32_t zero;
};
struct mboot_tag_mmap {
- mboot_uint32_t type;
- mboot_uint32_t size;
- mboot_uint32_t entry_size;
- mboot_uint32_t entry_version;
+ uint32_t type;
+ uint32_t size;
+ uint32_t entry_size;
+ uint32_t entry_version;
struct mboot_mmap_entry entries[];
};
struct mboot_tag_old_rsdp {
- mboot_uint32_t type;
- mboot_uint32_t size;
- mboot_uint8_t rsdp[];
+ uint32_t type;
+ uint32_t size;
+ uint8_t rsdp[];
};
struct mboot_tag_new_rsdp {
- mboot_uint32_t type;
- mboot_uint32_t size;
- mboot_uint8_t rsdp[];
+ uint32_t type;
+ uint32_t size;
+ uint8_t rsdp[];
};
struct mboot_tag_cmdline {
- mboot_uint32_t type;
- mboot_uint32_t size;
- mboot_uint8_t cmdline[];
+ uint32_t type;
+ uint32_t size;
+ uint8_t cmdline[];
};
static void read_symbols(
@@ -100,33 +92,33 @@ static void read_symbols(
// struct mboot_elf_section_header *section =
// (struct mboot_elf_section_header *) (layout->elf_section_headers);
//
-// for (mboot_uint32_t i = 0; i < layout->num; i++) {
+// for (uint32_t i = 0; i < layout->num; i++) {
// char buf[20];
//
// ultoa(i, buf, 10);
// serial_out_str("[");
-// serial_out_str(buf);
-// serial_out_str("]\t");
+// serial_out_str(buf);
+// serial_out_str("]\t");
//
// serial_out_str((char *)(kaddr(symtab) + section->sh_name));
// serial_out('\t');
//
// ultoa(section->sh_type, buf, 16);
// serial_out_str("type: 0x");
-// serial_out_str(buf);
-// serial_out('\t');
+// serial_out_str(buf);
+// serial_out('\t');
//
-// ultoa(section->sh_addr, buf, 16);
-// serial_out_str("addr: 0x");
-// serial_out_str(buf);
-// serial_out('\t');
+// ultoa(section->sh_addr, buf, 16);
+// serial_out_str("addr: 0x");
+// serial_out_str(buf);
+// serial_out('\t');
//
-// ultoa(section->sh_offset, buf, 16);
-// serial_out_str("offset: 0x");
-// serial_out_str(buf);
-// serial_out('\n');
+// ultoa(section->sh_offset, buf, 16);
+// serial_out_str("offset: 0x");
+// serial_out_str(buf);
+// serial_out('\n');
//
-// section++;
+// section++;
// }
}
@@ -134,7 +126,7 @@ static void read_cmdline(
struct boot_info *shim_info,
struct mboot_tag_cmdline *cmdline
) {
- mboot_uint32_t size = cmdline->size - 8;
+ uint32_t size = cmdline->size - 8;
if (size >= CMDLINE_MAX)
size = CMDLINE_MAX; // truncate :(
memcpy(shim_info->cmdline, cmdline->cmdline, size);
diff --git a/src/arch/amd64/paging.c b/src/arch/amd64/paging.c
index 18eb079..607267e 100644
--- a/src/arch/amd64/paging.c
+++ b/src/arch/amd64/paging.c
@@ -68,25 +68,18 @@ static struct pdpte *pdpt_mapped = (void *) (uintptr_t) 0x201000;
static struct pde *pd_mapped = (void *) (uintptr_t) 0x202000;
static struct pte *pt_mapped = (void *) (uintptr_t) 0x203000;
-static inline void
-invlpg(void *addr)
-{
+static inline void invlpg(void *addr) {
__asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
}
-static void
-load_addr(void *phys_addr)
-{
+static void load_addr(void *phys_addr) {
static struct pte *pt = &paging_pt[4];
pt->address = (uint64_t)phys_addr >> 12;
pt->flags = F_PRESENT | F_WRITEABLE;
invlpg(addr_mapped);
}
-static void
-load_pml4(
- void *phys
-) {
+static void load_pml4(void *phys) {
static struct pte *pt = &paging_pt[0];
if ((uint64_t)phys >> 12 == pt->address)
return;
@@ -95,10 +88,7 @@ load_pml4(
invlpg(pml4_mapped);
}
-static void
-load_pdpt(
- void *phys
-) {
+static void load_pdpt(void *phys) {
static struct pte *pt = &paging_pt[1];
if ((uint64_t)phys >> 12 == pt->address)
return;
@@ -107,10 +97,7 @@ load_pdpt(
invlpg(pdpt_mapped);
}
-static void
-load_pd(
- void *phys
-) {
+static void load_pd(void *phys) {
static struct pte *pt = &paging_pt[2];
if ((uint64_t)phys >> 12 == pt->address)
return;
@@ -119,10 +106,7 @@ load_pd(
invlpg(pdpt_mapped);
}
-static void
-load_pt(
- void *phys
-) {
+static void load_pt(void *phys) {
static struct pte *pt = &paging_pt[3];
if ((uint64_t)phys >> 12 == pt->address)
return;
@@ -135,8 +119,7 @@ load_pt(
#define PAG_CANNOT_ALLOC 1
#define PAG_NOT_PRESENT 2
-static int
-select_pdpt(
+static int select_pdpt(
void *virt,
unsigned int flags,
struct pml4e *root,
@@ -165,8 +148,7 @@ select_pdpt(
return PAG_SUCCESS;
}
-static int
-select_pd(
+static int select_pd(
void *virt,
unsigned int flags,
struct pdpte *pdpt,
@@ -195,8 +177,7 @@ select_pd(
return PAG_SUCCESS;
}
-static int
-select_pt(
+static int select_pt(
void *virt,
unsigned int flags,
struct pde *pd,
@@ -225,8 +206,7 @@ select_pt(
return PAG_SUCCESS;
}
-static void
-select_page(
+static void select_page(
void *virt,
struct pte *pt,
struct pte **res
@@ -238,8 +218,7 @@ select_page(
return;
}
-static inline void
-try_unmap_pml4(void) {
+static inline void try_unmap_pml4(void) {
for (int i = 0; i < 512; i++) {
if (pml4_mapped[i].flags & F_PRESENT)
return;
@@ -252,8 +231,7 @@ try_unmap_pml4(void) {
}
}
-static inline void
-try_unmap_pdpt(void) {
+static inline void try_unmap_pdpt(void) {
for (int i = 0; i < 512; i++) {
if (pdpt_mapped[i].flags & F_PRESENT)
return;
@@ -267,8 +245,7 @@ try_unmap_pdpt(void) {
try_unmap_pml4();
}
-static inline void
-try_unmap_pd(void) {
+static inline void try_unmap_pd(void) {
for (int i = 0; i < 512; i++) {
if (pd_mapped[i].flags & F_PRESENT)
return;
@@ -282,8 +259,7 @@ try_unmap_pd(void) {
try_unmap_pdpt();
}
-static inline void
-try_unmap_pt(void) {
+static inline void try_unmap_pt(void) {
for (int i = 0; i < 512; i++) {
if (pt_mapped[i].flags & F_PRESENT)
return;
@@ -297,12 +273,10 @@ try_unmap_pt(void) {
try_unmap_pd();
}
-static void
-unmap_page(
+static void unmap_page(
struct pml4e *root,
void *virt
) {
-
struct pdpte *pdpt;
struct pde *pd;
struct pte *pt;
@@ -331,13 +305,11 @@ unmap_page(
return;
}
-static void
-unmap_pages(
+static void unmap_pages(
struct pml4e *root,
void *virt_start,
long page_count
) {
-
uint64_t pml4_o = -1,
pdpt_o = -1,
pd_o = -1;
@@ -397,14 +369,12 @@ unmap_pages(
return;
}
-static int
-map_page(
+static int map_page(
struct pml4e *root,
void *virt,
void *phys,
unsigned int flags
) {
-
struct pdpte *pdpt;
struct pde *pd;
struct pte *pt;
@@ -430,15 +400,13 @@ map_page(
return 0;
}
-static int
-map_pages(
+static int map_pages(
struct pml4e *root,
void *virt_start,
void *phys_start,
unsigned int flags,
long page_count
) {
-
uint64_t pml4_o = -1,
pdpt_o = -1,
pd_o = -1;
@@ -502,7 +470,6 @@ failed:
}
void paging_init(void) {
-
kernel_pml4[0].flags = F_PRESENT | F_WRITEABLE;
kernel_pml4[0].address = (uint64_t)(&kernel_pdpt_0) >> 12;
diff --git a/src/arch/amd64/paging.h b/src/arch/amd64/paging.h
index 1768106..a76a172 100644
--- a/src/arch/amd64/paging.h
+++ b/src/arch/amd64/paging.h
@@ -4,7 +4,7 @@
#define F_WRITEABLE 0x002
#define F_UNPRIVILEGED 0x004
#define F_WRITETHROUGH 0x008
-#define F_CACHEDISABLE 0x010
+#define F_CACHEDISABLE 0x010
#define F_ACCESSED 0x020
#define F_DIRTY 0x040
#define F_MEGABYTE 0x080
diff --git a/src/arch/amd64/pic.c b/src/arch/amd64/pic.c
index 658911c..c25856b 100644
--- a/src/arch/amd64/pic.c
+++ b/src/arch/amd64/pic.c
@@ -53,7 +53,7 @@ void pic_remap(void) {
void pic_mask(int irq) {
uint16_t port;
uint8_t mask;
- if(irq < 8) {
+ if (irq < 8) {
port = PIC1_DATA;
} else {
port = PIC2_DATA;
@@ -66,7 +66,7 @@ void pic_mask(int irq) {
void pic_unmask(int irq) {
uint16_t port;
uint8_t mask;
- if(irq < 8) {
+ if (irq < 8) {
port = PIC1_DATA;
} else {
irq -= 8;
@@ -82,7 +82,7 @@ void pic_disable(void) {
}
void pic_eoi(int irq) {
- if(irq >= 8) {
+ if (irq >= 8) {
outb(PIC2_COMMAND, PIC_EOI);
}
outb(PIC1_COMMAND, PIC_EOI);
diff --git a/src/arch/amd64/serial.c b/src/arch/amd64/serial.c
index d63d9dd..fe21629 100644
--- a/src/arch/amd64/serial.c
+++ b/src/arch/amd64/serial.c
@@ -18,7 +18,7 @@ int serial_init(void) {
outb(PORT + 0, 0xAE); // test by sending 0xAE
uint8_t response = inb(PORT + 0);
- if(response != 0xAE) {
+ if (response != 0xAE) {
// TODO panic here?
return -1;
}
@@ -30,18 +30,18 @@ int serial_init(void) {
uint8_t serial_in(void) {
// wait for data to be available
- while((inb(PORT + 5) & 0x01) == 0);
+ while ((inb(PORT + 5) & 0x01) == 0);
return inb(PORT);
}
void serial_out(uint8_t ch) {
// wait for output to be free
- while((inb(PORT + 5) & 0x20) == 0);
+ while ((inb(PORT + 5) & 0x20) == 0);
outb(PORT, ch);
}
void serial_out_str(const char *str) {
- for(; *str != '\0'; str++) {
+ for (; *str != '\0'; str++) {
serial_out(*str);
}
}
diff --git a/src/arch/amd64/shim.c b/src/arch/amd64/shim.c
index 3c0bd72..c161c88 100644
--- a/src/arch/amd64/shim.c
+++ b/src/arch/amd64/shim.c
@@ -11,7 +11,7 @@
static struct boot_info boot_info;
-void* amd64_shim(long mboot_magic, void *mboot_data_ptr) {
+void *amd64_shim(long mboot_magic, void *mboot_data_ptr) {
serial_init();
paging_init();
pic_remap();