shifted RSDP detection to limine, got high half direct mapping setup
This commit is contained in:
parent
ba71067458
commit
531ce911ea
1
Makefile
1
Makefile
@ -106,6 +106,7 @@ override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
|
|||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: bin/$(OUTPUT)
|
all: bin/$(OUTPUT)
|
||||||
sh limine.sh
|
sh limine.sh
|
||||||
|
sh run.sh
|
||||||
|
|
||||||
# Include header dependencies.
|
# Include header dependencies.
|
||||||
-include $(HEADER_DEPS)
|
-include $(HEADER_DEPS)
|
||||||
|
|||||||
@ -5,9 +5,9 @@ dd if=/dev/zero bs=1M count=0 seek=64 of=image.hdd
|
|||||||
sgdisk image.hdd -n 1:2048 -t 1:ef00 -m 1
|
sgdisk image.hdd -n 1:2048 -t 1:ef00 -m 1
|
||||||
|
|
||||||
|
|
||||||
rm -rf limine
|
#rm -rf limine
|
||||||
# If first time: Download the latest Limine binary release for the 10.x branch.
|
# If first time: Download the latest Limine binary release for the 10.x branch.
|
||||||
git clone https://codeberg.org/Limine/Limine.git limine --branch=v10.x-binary --depth=1
|
#git clone https://codeberg.org/Limine/Limine.git limine --branch=v10.x-binary --depth=1
|
||||||
|
|
||||||
# Build "limine" utility.
|
# Build "limine" utility.
|
||||||
make -C limine
|
make -C limine
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
obj/src/int.c.o: src/int.c src/common.h
|
obj/src/int.c.o: src/int.c src/print.h src/common.h
|
||||||
|
src/print.h:
|
||||||
src/common.h:
|
src/common.h:
|
||||||
|
|||||||
BIN
obj/src/int.c.o
BIN
obj/src/int.c.o
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
obj/src/main.c.o: src/main.c src/../include/limine.h src/common.h \
|
obj/src/main.c.o: src/main.c src/../include/limine.h src/acpi.h \
|
||||||
src/print.h
|
src/common.h src/print.h
|
||||||
src/../include/limine.h:
|
src/../include/limine.h:
|
||||||
|
src/acpi.h:
|
||||||
src/common.h:
|
src/common.h:
|
||||||
src/print.h:
|
src/print.h:
|
||||||
|
|||||||
BIN
obj/src/main.c.o
BIN
obj/src/main.c.o
Binary file not shown.
61
src/acpi.c
61
src/acpi.c
@ -1,46 +1,26 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "print.h"
|
||||||
|
|
||||||
// root system description pointer, points
|
#include "../include/limine.h"
|
||||||
pstruct acpi_rsdp_header {
|
|
||||||
u8 signature[8];
|
|
||||||
u8 checksum;
|
|
||||||
u8 OEMID[6];
|
|
||||||
u8 revision;
|
|
||||||
u32 addr32_depr;
|
|
||||||
// v2
|
|
||||||
u32 len;
|
|
||||||
u64 addr;
|
|
||||||
u8 extended_checksum;
|
|
||||||
u8 resv[3];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// credit to dreamportdev's OSDev-Notes and the OSDev Wiki for table layouts
|
||||||
|
|
||||||
|
#include "acpi.h"
|
||||||
#define RSDT_SIGNATURE "RSDT"
|
#define RSDT_SIGNATURE "RSDT"
|
||||||
#define XSDT_SIGNATURE "XSDT"
|
#define XSDT_SIGNATURE "XSDT"
|
||||||
|
|
||||||
struct acpi_sdt_header {
|
bool rsdp_validate(const u8* data) {
|
||||||
u8 signature[4];
|
if(memcmp(data, (const u8*)RSDP_SIGNATURE, 8) != 0) {
|
||||||
u32 len;
|
/* to debug in memcmp is broken somehow */
|
||||||
u8 revision;
|
if(data[0] == 'R' && data[1] == 'S' && data[2] == 'D' && data[3] == 'T' && data[4] == ' ') {
|
||||||
u8 checksum;
|
printn((const char*)data, 8);
|
||||||
u8 OEMID[6];
|
}
|
||||||
u8 OEM_table_id[8];
|
return false;
|
||||||
u32 OEM_revision;
|
}
|
||||||
u32 creator_id;
|
|
||||||
u32 creator_revision;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct apci_rsdt {
|
struct acpi_rsdp_header* head = (struct acpi_rsdp_header*)data;
|
||||||
struct acpi_sdt_header header;
|
size_t len = sizeof(struct acpi_rsdp_header);
|
||||||
u32 addrs[];
|
len -= (head->revision == 2) * sizeof(u32) + sizeof(u64) + sizeof(u8) + sizeof(u8[3]);
|
||||||
};
|
|
||||||
|
|
||||||
struct xsdt {
|
|
||||||
struct acpi_rsdp_header header;
|
|
||||||
u64 addrs[];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
bool rsdp_validate(u8* data, size_t len) {
|
|
||||||
u32 sum_to_zero = 0;
|
u32 sum_to_zero = 0;
|
||||||
for(size_t i = 0; i < len; i++) {
|
for(size_t i = 0; i < len; i++) {
|
||||||
sum_to_zero += data[i];
|
sum_to_zero += data[i];
|
||||||
@ -49,4 +29,13 @@ bool rsdp_validate(u8* data, size_t len) {
|
|||||||
return (sum_to_zero & 0xFF) == 0;
|
return (sum_to_zero & 0xFF) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool use_xsdt = false;
|
||||||
|
|
||||||
|
static struct acpi_rsdt* rsdt;
|
||||||
|
static struct acpi_xsdt* xsdt;
|
||||||
|
|
||||||
|
struct acpi_sdt_header* acpi_get_header(size_t n) {
|
||||||
|
return (struct acpi_sdt_header*) (use_xsdt? xsdt->addrs[n] : (u64)rsdt->addrs[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct acpi_rsdp_header* rsdp;
|
||||||
|
|||||||
46
src/acpi.h
Normal file
46
src/acpi.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define RSDP_SIGNATURE "RSDT PTR "
|
||||||
|
|
||||||
|
|
||||||
|
pstruct acpi_rsdp_header {
|
||||||
|
u8 signature[8];
|
||||||
|
u8 checksum;
|
||||||
|
u8 OEMID[6];
|
||||||
|
u8 revision;
|
||||||
|
u32 addr32_depr;
|
||||||
|
// v2
|
||||||
|
u32 len;
|
||||||
|
u64 addr;
|
||||||
|
u8 extended_checksum;
|
||||||
|
u8 resv[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct acpi_sdt_header {
|
||||||
|
u8 signature[4];
|
||||||
|
u32 len;
|
||||||
|
u8 revision;
|
||||||
|
u8 checksum;
|
||||||
|
u8 OEMID[6];
|
||||||
|
u8 OEM_table_id[8];
|
||||||
|
u32 OEM_revision;
|
||||||
|
u32 creator_id;
|
||||||
|
u32 creator_revision;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct acpi_rsdt {
|
||||||
|
// signature == "RSDT"
|
||||||
|
struct acpi_sdt_header header;
|
||||||
|
u32 addrs[];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct acpi_xsdt {
|
||||||
|
// signature == "XSDT"
|
||||||
|
struct acpi_rsdp_header header;
|
||||||
|
u64 addrs[];
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct acpi_rsdp_header* rsdp;
|
||||||
15
src/common.h
15
src/common.h
@ -15,3 +15,18 @@ typedef int16_t i16;
|
|||||||
typedef int32_t i32;
|
typedef int32_t i32;
|
||||||
typedef int64_t i64;
|
typedef int64_t i64;
|
||||||
|
|
||||||
|
static inline void INT(int n) {
|
||||||
|
asm volatile (
|
||||||
|
"int %0"
|
||||||
|
:
|
||||||
|
: "i"(n)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* memcpy(void* restrict dst, const void* src, size_t n);
|
||||||
|
void* memset(void* s, int c, size_t n);
|
||||||
|
void* memmove(void* dst, const void* src, size_t n);
|
||||||
|
int memcmp(const void* s1, const void* s2, size_t n);
|
||||||
|
|
||||||
|
extern u64 hhdm_offset;
|
||||||
|
|||||||
23
src/int.c
23
src/int.c
@ -1,7 +1,14 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// for debugging
|
||||||
|
#include "print.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
|
// for trap debugging
|
||||||
|
u64 dbg_var = 0;
|
||||||
|
|
||||||
pstruct int_desc {
|
pstruct int_desc {
|
||||||
u16 addr_low;
|
u16 addr_low;
|
||||||
u16 selector;
|
u16 selector;
|
||||||
@ -22,6 +29,8 @@ enum INT_DESC_FLAGS {
|
|||||||
|
|
||||||
#define CODE64_SELECTOR 0x28
|
#define CODE64_SELECTOR 0x28
|
||||||
|
|
||||||
|
static int cnt = 0;
|
||||||
|
|
||||||
struct int_desc idt[256];
|
struct int_desc idt[256];
|
||||||
|
|
||||||
void set_idt(u8 vect, void* handler, u8 dpl) {
|
void set_idt(u8 vect, void* handler, u8 dpl) {
|
||||||
@ -29,7 +38,7 @@ void set_idt(u8 vect, void* handler, u8 dpl) {
|
|||||||
u64 addr = (u64) handler;
|
u64 addr = (u64) handler;
|
||||||
ent->addr_low = addr & 0xFFFF;
|
ent->addr_low = addr & 0xFFFF;
|
||||||
ent->addr_mid = (addr >> 16) & 0xFFFF;
|
ent->addr_mid = (addr >> 16) & 0xFFFF;
|
||||||
ent->addr_mid = addr >> 32;
|
ent->addr_high = addr >> 32;
|
||||||
|
|
||||||
ent->selector = CODE64_SELECTOR;
|
ent->selector = CODE64_SELECTOR;
|
||||||
ent->flags = ID_GATE_INT | dpl*ID_DPL | ID_PRESENT;
|
ent->flags = ID_GATE_INT | dpl*ID_DPL | ID_PRESENT;
|
||||||
@ -68,12 +77,16 @@ struct cpu_ctx {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct cpu_ctx* interrupt_dispatch(struct cpu_ctx* ctx) {
|
struct cpu_ctx* interrupt_dispatch(struct cpu_ctx* ctx) {
|
||||||
draw(ctx->vect);
|
print("\n[IRQ ");
|
||||||
|
print8(ctx->vect);
|
||||||
|
print("] with message: ");
|
||||||
|
print64(dbg_var);
|
||||||
|
print("\n");
|
||||||
|
while(1);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((naked))
|
||||||
void int_stub(void) {
|
void int_stub(void) {
|
||||||
__asm__ volatile (
|
__asm__ volatile (
|
||||||
"push %%rax\n"
|
"push %%rax\n"
|
||||||
@ -108,7 +121,7 @@ void int_stub(void) {
|
|||||||
"pop %%rbx\n"
|
"pop %%rbx\n"
|
||||||
"pop %%rax\n"
|
"pop %%rax\n"
|
||||||
"add $16, %%rsp\n"
|
"add $16, %%rsp\n"
|
||||||
"iret\n"
|
"iretq\n"
|
||||||
:
|
:
|
||||||
:
|
:
|
||||||
: "memory"
|
: "memory"
|
||||||
|
|||||||
102
src/main.c
102
src/main.c
@ -2,8 +2,9 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
#include "../include/limine.h"
|
#include "../include/limine.h"
|
||||||
|
|
||||||
|
#include "acpi.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
|
|
||||||
@ -18,6 +19,27 @@ static volatile struct limine_framebuffer_request fb_req = {
|
|||||||
.revision = 0
|
.revision = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
__attribute__((used, section(".limine_requests")))
|
||||||
|
static volatile struct limine_memmap_request mem_req = {
|
||||||
|
.id = LIMINE_MEMMAP_REQUEST_ID,
|
||||||
|
.revision = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
__attribute__((used, section(".limine_requests")))
|
||||||
|
static volatile struct limine_hhdm_request hhdm_req = {
|
||||||
|
.id = LIMINE_HHDM_REQUEST_ID,
|
||||||
|
.revision = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
__attribute__((used, section(".limine_requests")))
|
||||||
|
static volatile struct limine_rsdp_request rsdp_req = {
|
||||||
|
.id = LIMINE_RSDP_REQUEST_ID,
|
||||||
|
.revision = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
u64 hhdm_offset;
|
||||||
|
|
||||||
__attribute__((used, section(".limine_requests_start")))
|
__attribute__((used, section(".limine_requests_start")))
|
||||||
static volatile u64 limine_requests_start_marker[] = LIMINE_REQUESTS_START_MARKER;
|
static volatile u64 limine_requests_start_marker[] = LIMINE_REQUESTS_START_MARKER;
|
||||||
|
|
||||||
@ -99,6 +121,53 @@ void draw(u8 vect) {
|
|||||||
|
|
||||||
extern void init_idt(void);
|
extern void init_idt(void);
|
||||||
|
|
||||||
|
extern u32 fg;
|
||||||
|
extern u32 bg;
|
||||||
|
void print_memmap_entry(struct limine_memmap_entry* entry) {
|
||||||
|
u32 savefg = fg;
|
||||||
|
u32 savebg = bg;
|
||||||
|
static const char* type_strs[] = {
|
||||||
|
"Usable",
|
||||||
|
"Reserved",
|
||||||
|
"ACPI Reclaimable",
|
||||||
|
"ACPI NVS",
|
||||||
|
"BAD!!!",
|
||||||
|
"Bootloader Reclaimable",
|
||||||
|
"Executable and Modules",
|
||||||
|
"Framebuffer",
|
||||||
|
"ACPI Tables",
|
||||||
|
};
|
||||||
|
|
||||||
|
static u32 type_colors[] = {
|
||||||
|
0x00AF00,
|
||||||
|
0xAF1F00,
|
||||||
|
0x7f7f00,
|
||||||
|
0x7f7f00,
|
||||||
|
0xFF0000,
|
||||||
|
0x007f7f,
|
||||||
|
0x408000,
|
||||||
|
0x0000FF,
|
||||||
|
0x00FF00
|
||||||
|
};
|
||||||
|
|
||||||
|
bg = type_colors[entry->type];
|
||||||
|
fg = ~bg;
|
||||||
|
|
||||||
|
u64 addr = entry->base;
|
||||||
|
u64 end = addr + entry->length;
|
||||||
|
print("[");
|
||||||
|
print(type_strs[entry->type]);
|
||||||
|
print("]");
|
||||||
|
print64(addr);
|
||||||
|
print(" - ");
|
||||||
|
print64(end);
|
||||||
|
print("\n");
|
||||||
|
fg = savefg;
|
||||||
|
bg = savebg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void kmain() {
|
void kmain() {
|
||||||
if(LIMINE_BASE_REVISION_SUPPORTED(limine_base_revision) == false) {
|
if(LIMINE_BASE_REVISION_SUPPORTED(limine_base_revision) == false) {
|
||||||
hang();
|
hang();
|
||||||
@ -110,12 +179,39 @@ void kmain() {
|
|||||||
|
|
||||||
fb = fb_req.response->framebuffers[0];
|
fb = fb_req.response->framebuffers[0];
|
||||||
|
|
||||||
|
print_init(fb);
|
||||||
init_idt();
|
init_idt();
|
||||||
|
|
||||||
print_init(fb);
|
if(!mem_req.response) {
|
||||||
|
print("Failed to get memory map :(\n)");
|
||||||
|
hang();
|
||||||
|
}
|
||||||
|
|
||||||
print("TEST THIS\nMessage for me please Mr Kernel");
|
if(!hhdm_req.response) {
|
||||||
|
print("Failed to get higher half direct mapping\n.");
|
||||||
|
hang();
|
||||||
|
}
|
||||||
|
|
||||||
|
hhdm_offset = hhdm_req.response->offset;
|
||||||
|
|
||||||
|
if(!rsdp_req.response) {
|
||||||
|
print ("Failed to find rsdp\n.");
|
||||||
|
hang();
|
||||||
|
}
|
||||||
|
|
||||||
|
rsdp = (struct acpi_rsdp_header*)(rsdp_req.response->address);
|
||||||
|
|
||||||
|
for(size_t i = 0; i < mem_req.response->entry_count; i++) {
|
||||||
|
print_memmap_entry(mem_req.response->entries[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Found RSDP @ 0x");
|
||||||
|
print64((u64)rsdp);
|
||||||
|
put('\n');
|
||||||
|
|
||||||
|
print("With signature: ");
|
||||||
|
printn((char*)rsdp->signature, sizeof(rsdp->signature));
|
||||||
|
|
||||||
hang();
|
hang();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
32
src/print.c
32
src/print.c
@ -4,7 +4,7 @@
|
|||||||
#include "../include/limine.h"
|
#include "../include/limine.h"
|
||||||
|
|
||||||
u32 bg = 0x00000000;
|
u32 bg = 0x00000000;
|
||||||
u32 fg = 0x00030200;
|
u32 fg = (0x007F1754 << 1);
|
||||||
static size_t row;
|
static size_t row;
|
||||||
static size_t col;
|
static size_t col;
|
||||||
static size_t term_width, term_height;
|
static size_t term_width, term_height;
|
||||||
@ -71,7 +71,7 @@ void put(int ch) {
|
|||||||
for (size_t x = 0; x < TERM_WIDTH; x++) {
|
for (size_t x = 0; x < TERM_WIDTH; x++) {
|
||||||
size_t off = (py + y) * fb_width + (px + x);
|
size_t off = (py + y) * fb_width + (px + x);
|
||||||
bool padding = (y == 0 || y == TERM_HEIGHT-1 || x == 0 || x == TERM_WIDTH-1);
|
bool padding = (y == 0 || y == TERM_HEIGHT-1 || x == 0 || x == TERM_WIDTH-1);
|
||||||
fb_scr[off] = ((~glyph & 1) | padding )? bg : (x^y * off + y*term_width) * fg;
|
fb_scr[off] = ((~glyph & 1) | padding )? bg : fg;
|
||||||
glyph >>= !padding;
|
glyph >>= !padding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,3 +85,31 @@ void print(const char* msg) {
|
|||||||
put(*(msg++));
|
put(*(msg++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printn(const char* msg, size_t len) {
|
||||||
|
while(len-->0) {
|
||||||
|
put(*(msg++));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 digits[] = "0123456789ABCDEF";
|
||||||
|
|
||||||
|
void print8(u8 n) {
|
||||||
|
put(digits[n>>4]);
|
||||||
|
put(digits[n&0xf]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print16(u16 n) {
|
||||||
|
print8(n >> 8);
|
||||||
|
print8(n & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print32(u32 n) {
|
||||||
|
print16(n >> 16);
|
||||||
|
print16(n & 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print64(u64 n) {
|
||||||
|
print32(n >> 32);
|
||||||
|
print32(n & 0xFFFFFFFF);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,10 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
struct limine_framebuffer;
|
struct limine_framebuffer;
|
||||||
|
|
||||||
void put(int ch);
|
void put(int ch);
|
||||||
|
|
||||||
void print(const char* msg);
|
void print(const char* msg);
|
||||||
|
void printn(const char* msg, size_t len);
|
||||||
|
void print64(u64 n);
|
||||||
|
void print32(u32 n);
|
||||||
|
void print16(u16 n);
|
||||||
|
void print8(u8 n);
|
||||||
void print_init(struct limine_framebuffer* fb);
|
void print_init(struct limine_framebuffer* fb);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user