Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Debug options

#export DEBUG = 1
#export DEBUG_LOGGING = 1
export DEBUG_LOGGING = 1

# Global options

Expand Down
47 changes: 31 additions & 16 deletions boot/multiboot2/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,11 @@
#define LME 0x100
#define PG (1 << 31)

#define GDT_RW (1 << 1)
#define GDT_E (1 << 3)
#define GDT_S (1 << 4)
#define GDT_P (1 << 7)
#define GDT_L (1 << 5)
#define GDT_G (1 << 7)

#define KERNEL_PAGE_FLAGS (1 + 2)
#define PAGE_SZ (1 << 7)

#define PAGING_1GIB 0x40000000
#define IDENT_BASE 0xFFFFFF0000000000

.code32
.section .text.multiboot2
Expand Down Expand Up @@ -230,7 +224,8 @@ enter64:

.section .text
ktransfer:
addq $KERNEL_VMA, gdt_ptr64.addr
movq $IDENT_BASE, %rax
addq %rax, gdt_ptr64.addr
lgdt gdt_ptr64
addq $KERNEL_VMA, %rsp
pushq $0
Expand All @@ -250,24 +245,36 @@ gdt:
.short 0x0000 /* limit 0:15 */
.short 0x0000 /* base 0:15 */
.byte 0x00 /* base 16:23 */
.byte GDT_RW + GDT_E + GDT_S + GDT_P /* access: RW E S P */
.byte GDT_L + GDT_G /* limit 16:19 flag: L G */
.byte 0x98 /* access: DPL=0 P */
.byte 0x20 /* limit 16:19 flag: L */
.byte 0x00 /* base 24:31 */
gdt.dataseg:
.short 0x0000 /* limit 0:15 */
.short 0x0000 /* base 0:15 */
.byte 0x00 /* base 16:23 */
.byte GDT_RW + GDT_S + GDT_P /* access: RW S P */
.byte GDT_G /* limit 16:19 flag: G */
.byte 0x92 /* access: RW S P */
.byte 0x92 /* access: P */
.byte 0x00 /* limit 16:19 flag: */
.byte 0x00 /* base 24:31 */
gdt.ucodeseg:
.quad 0
.short 0x0000 /* limit 0:15 */
.short 0x0000 /* base 0:15 */
.byte 0x00 /* base 16:23 */
.byte 0xF8 /* access: DPL=3 P */
.byte 0x20 /* limit 16:19 flag: L */
.byte 0x00 /* base 24:31 */
gdt.udataseg:
.quad 0
.short 0x0000 /* limit 0:15 */
.short 0x0000 /* base 0:15 */
.byte 0x00 /* base 16:23 */
.byte 0x92 /* access: P */
.byte 0x00 /* limit 16:19 flag: */
.byte 0x00 /* base 24:31 */
gdt.tss:
.quad 0
.quad 0
gdt.end:
.globl gdt_end
gdt_end:

.equ CODE_SEG, gdt.codeseg - gdt
.equ DATA_SEG, gdt.dataseg - gdt
Expand All @@ -288,9 +295,10 @@ gdt_ptr64.addr:
kernel_pml4:
PML4:
.quad PDPT_0 + KERNEL_PAGE_FLAGS
.rept 0x200 - 2
.rept 0x200 - 3
.quad 0
.endr
.quad PDPT_510 + KERNEL_PAGE_FLAGS
.quad PDPT_511 + KERNEL_PAGE_FLAGS

PDPT_0:
Expand All @@ -300,6 +308,13 @@ PDPT_0:
.quad 0
.endr

PDPT_510:
.set i, 0
.rept 0x200
.quad (i * PAGING_1GIB) + KERNEL_PAGE_FLAGS + PAGE_SZ
.set i, i+1
.endr

PDPT_511:
.rept 0x200 - 2
.quad 0
Expand Down
11 changes: 10 additions & 1 deletion boot/multiboot2/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include <multiboot2/init.h>

#include <kernel/core/kentry.h>
#include <kernel/core/mm_init.h>
#include <kernel/core/mm.h>
#include <kernel/core/gdt.h>
#include <kernel/core/logging.h>
#include <kernel/core/proc_data.h>

#include <drivers/acpi/tables.h>

Expand All @@ -46,6 +47,9 @@
#define VIDEO_XRGB8888_BLUEMASK 0x08
#define VIDEO_XRGB8888_BPP 32

struct proc_data_t bsp_proc_data;
static struct proc_data_t* bsp_proc_data_ptr;

struct mb2_tag_memmap_entry_t {
uint64_t base;
uint64_t length;
Expand Down Expand Up @@ -134,11 +138,16 @@ static void next_segment(uint64_t* handle, struct mem_segment_t* seg) {


void multiboot2_init(struct mb2_info_t* info) {
bsp_proc_data_ptr = &bsp_proc_data;
proc_data_ptr = &bsp_proc_data_ptr;
proc_data_set_id(0);
proc_data_get()->arb_id = 0;
logging_init();

#ifdef SERIAL
serial_init_com1();
serial_init_com2();
serial_print_init();

serial_print_com1("COM1\r\n");
serial_print_com2("COM2\r\n");
Expand Down
50 changes: 21 additions & 29 deletions drivers/acpica_osl/osl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
#include <kernel/core/kentry.h>
#include <kernel/core/time.h>
#include <kernel/core/clock_src.h>
#include <kernel/core/lock.h>
#include <kernel/core/process.h>

ACPI_STATUS AcpiOsInitialize(void) {
return AE_OK;
}

ACPI_THREAD_ID AcpiOsGetThreadId(void) {
//TODO: implement
//logging_log_warning("Call to unfinished AcpiOsGetThreadId");
return 1;
return process_get_pid();
}

void ACPI_INTERNAL_XFACE AcpiOsPrintf(const char* fmt, ...) {
Expand All @@ -62,9 +62,7 @@ void* AcpiOsAllocate(ACPI_SIZE size) {
}

void AcpiOsFree(void* ptr) {
//TODO: implement
//logging_log_warning("Call to unfinished AcpiOsFree 0x%lx", ptr);
(void)ptr;
kfree(ptr);
}

ACPI_STATUS AcpiOsCreateSemaphore(UINT32 cap, UINT32 init, ACPI_SEMAPHORE* handle) {
Expand Down Expand Up @@ -101,30 +99,26 @@ ACPI_STATUS AcpiOsSignalSemaphore(ACPI_SEMAPHORE handle, UINT32 units) {
}

ACPI_STATUS AcpiOsCreateLock(ACPI_SPINLOCK* handle) {
//TODO: implement
*handle = (void*)1;
//logging_log_warning("Call to unfinished AcpiOsCreateLock");
return AE_OK;
*handle = kmalloc(sizeof(uint8_t));
if (*handle) {
lock_init(*handle);
return AE_OK;
}
return AE_ERROR;
}

void AcpiOsDeleteLock(ACPI_SPINLOCK handle) {
//TODO: implement
//logging_log_warning("Call to unfinished AcpiOsCreateLock");
(void)handle;
kfree(handle);
}

ACPI_CPU_FLAGS AcpiOsAcquireLock(ACPI_SPINLOCK handle) {
//TODO: implement
//logging_log_warning("Call to unfinished AcpiOsAcquireLock");
(void)handle;
lock_acquire(handle);
return 0;
}

void AcpiOsReleaseLock(ACPI_SPINLOCK handle, ACPI_CPU_FLAGS flg) {
//TODO: implement
//logging_log_warning("Call to unfinished AcpiOsReleaseLock");
(void)handle;
(void)flg;
lock_release(handle);
}

ACPI_STATUS AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS paddr, UINT64* val, UINT32 width) {
Expand Down Expand Up @@ -238,15 +232,10 @@ void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS paddr, ACPI_SIZE len) {
const uint64_t page_base = paddr & PAGE_BASE_MASK;
const uint64_t adj = paddr - page_base;
len += adj;
uint64_t order = mm_lowest_order(len);
if (order == (uint64_t)-1) {
logging_log_error("Could not allocate contigious virtual block of 0x%lx", (uint64_t)len);
panic(PANIC_NO_MEM);
}
const uint64_t vaddr = mm_alloc_dv((enum mm_order_t)order);
const uint64_t vaddr = mm_alloc_v(len);
if (!vaddr) {
logging_log_error("Could not allocate contigious virtual block of 0x%lx", (uint64_t)len);
panic(PANIC_NO_MEM);
return 0;
}

for (uint64_t i = 0; i < len; i += PAGE_SIZE_4K) {
Expand All @@ -257,9 +246,12 @@ void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS paddr, ACPI_SIZE len) {
}

void AcpiOsUnmapMemory(void* vaddr, ACPI_SIZE len) {
//logging_log_warning("Call to unfinished AcpiOsUnmapMemory");
(void)vaddr;
(void)len;
const uint64_t page_base = (uint64_t)vaddr & PAGE_BASE_MASK;
const uint64_t adj = (uint64_t)vaddr - page_base;
len += adj;
for (uint64_t i = 0; i < len; i += PAGE_SIZE_4K) {
paging_unmap(page_base + i, PAGE_4K);
}
}

ACPI_STATUS AcpiOsTableOverride(ACPI_TABLE_HEADER* existing, ACPI_TABLE_HEADER** override) {
Expand Down
Loading