Compare commits
13 changed files with 24 additions and 51 deletions
4
.gdbinit
4
.gdbinit
|
|
@ -1,4 +1,2 @@
|
||||||
set pagination off
|
|
||||||
set confirm off
|
|
||||||
file kernel.elf
|
file kernel.elf
|
||||||
target remote :1234
|
target remote localhost:1234
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
#include <drivers/tty.h>
|
#include <drivers/tty.h>
|
||||||
#include <drivers/serial.h>
|
#include <drivers/serial.h>
|
||||||
#include <lib/stdio.h>
|
#include <lib/stdio.h>
|
||||||
#include "arch/reg.h"
|
|
||||||
#include "descriptor.h"
|
#include "descriptor.h"
|
||||||
|
|
||||||
static struct tty tty_early = {0};
|
static struct tty tty_early = {0};
|
||||||
|
|
@ -23,11 +22,6 @@ void _panic()
|
||||||
|
|
||||||
void arch_early_init()
|
void arch_early_init()
|
||||||
{
|
{
|
||||||
/* enable SSE: CR4.OSFXSR (bit 9) + CR4.OSXMMEXCPT (bit 10) */
|
|
||||||
u64 cr4 = cr4_read();
|
|
||||||
cr4 |= (1 << 9) | (1 << 10);
|
|
||||||
cr4_write(cr4);
|
|
||||||
|
|
||||||
tty_early.serial_ops = &tty_early_ops;
|
tty_early.serial_ops = &tty_early_ops;
|
||||||
tty_early.priv = (void *)COM1;
|
tty_early.priv = (void *)COM1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,6 @@ cr3_read:
|
||||||
mov rax, cr3
|
mov rax, cr3
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.global cr4_read
|
|
||||||
cr4_read:
|
|
||||||
mov rax, cr4
|
|
||||||
ret
|
|
||||||
|
|
||||||
.global cr4_write
|
|
||||||
cr4_write:
|
|
||||||
mov cr4, rdi
|
|
||||||
ret
|
|
||||||
|
|
||||||
.global lgdt
|
.global lgdt
|
||||||
lgdt:
|
lgdt:
|
||||||
lgdt __gdtr
|
lgdt __gdtr
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ void cr2_write(u64 cr2);
|
||||||
u64 cr2_read();
|
u64 cr2_read();
|
||||||
void cr3_write(u64 cr3);
|
void cr3_write(u64 cr3);
|
||||||
u64 cr3_read();
|
u64 cr3_read();
|
||||||
void cr4_write(u64 cr4);
|
|
||||||
u64 cr4_read();
|
|
||||||
void lidt();
|
void lidt();
|
||||||
void lgdt();
|
void lgdt();
|
||||||
void ltr();
|
void ltr();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
.global arch_stack_init
|
.global arch_stack_init
|
||||||
arch_stack_init:
|
arch_stack_init:
|
||||||
pop rdx
|
pop rdx
|
||||||
sub rsi, 16
|
sub rsi, 8
|
||||||
add rdi, rsi
|
add rdi, rsi
|
||||||
mov rsp, rdi
|
mov rsp, rdi
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ static bool cpio_verify_header_footer(const char *file, size_t len)
|
||||||
if (offset_footer == sizeof(struct cpio_newc_header))
|
if (offset_footer == sizeof(struct cpio_newc_header))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (strncmp(file + offset_footer, CPIO_TRAILER, footer_len))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,18 +56,21 @@ static ssize_t read_next(fs_t *fs, const char *file, rbtree_t *list, dirent_t **
|
||||||
return -ENAMETOOLONG;
|
return -ENAMETOOLONG;
|
||||||
|
|
||||||
const char *cursor = file + sizeof(struct cpio_newc_header);
|
const char *cursor = file + sizeof(struct cpio_newc_header);
|
||||||
size_t data_offset = sizeof(struct cpio_newc_header) + ALIGN_UP(name_len, 4);
|
|
||||||
|
|
||||||
if (!strncmp(cursor, "./", 2)) {
|
if (!strncmp(cursor, "./", 2)) {
|
||||||
cursor += 2;
|
cursor += 2;
|
||||||
name_len -= 2;
|
name_len -= 2;
|
||||||
} else if (!strcmp(cursor, ".")) {
|
} else if (!strcmp(cursor, ".")) {
|
||||||
/* is root */
|
/* is root */
|
||||||
return data_offset;
|
cursor += name_len;
|
||||||
|
cursor = file + ALIGN_UP(cursor - file, 4);
|
||||||
|
return cursor - file;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(name, cursor, name_len);
|
memcpy(name, cursor, name_len);
|
||||||
cursor = file + data_offset;
|
cursor += name_len;
|
||||||
|
|
||||||
|
cursor = file + ALIGN_UP(cursor - file, 4);
|
||||||
|
|
||||||
char *parent_path = dirname(name);
|
char *parent_path = dirname(name);
|
||||||
char *leaf = basename(name);
|
char *leaf = basename(name);
|
||||||
|
|
@ -121,7 +127,7 @@ static ssize_t read_next(fs_t *fs, const char *file, rbtree_t *list, dirent_t **
|
||||||
|
|
||||||
/* advance past file data and align to next entry */
|
/* advance past file data and align to next entry */
|
||||||
cursor += file_len;
|
cursor += file_len;
|
||||||
cursor = file + data_offset + ALIGN_UP(file_len, 4);
|
cursor = file + ALIGN_UP(cursor - file, 4);
|
||||||
res = cursor - file;
|
res = cursor - file;
|
||||||
|
|
||||||
out_tidy:
|
out_tidy:
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@
|
||||||
extern struct limine_executable_address_response *kern_addr_res;
|
extern struct limine_executable_address_response *kern_addr_res;
|
||||||
extern struct limine_memmap_response *kern_map_res;
|
extern struct limine_memmap_response *kern_map_res;
|
||||||
extern struct limine_hhdm_response *kern_hhdm_res;
|
extern struct limine_hhdm_response *kern_hhdm_res;
|
||||||
extern struct limine_rsdp_response *kern_rsdp_res;
|
extern struct limine_rsdp_response *kern_rsdp_res ;
|
||||||
extern struct limine_module_response *module_res;
|
|
||||||
|
|
||||||
void requests_init();
|
void requests_init();
|
||||||
|
|
||||||
|
|
|
||||||
10
init/main.c
10
init/main.c
|
|
@ -23,7 +23,6 @@
|
||||||
#include <drivers/apic.h>
|
#include <drivers/apic.h>
|
||||||
|
|
||||||
#include <fs/vfs.h>
|
#include <fs/vfs.h>
|
||||||
#include <fs/cpio.h>
|
|
||||||
|
|
||||||
#include <lib/stdio.h>
|
#include <lib/stdio.h>
|
||||||
#include <lib/list.h>
|
#include <lib/list.h>
|
||||||
|
|
@ -68,15 +67,6 @@ static void kmain()
|
||||||
page_init();
|
page_init();
|
||||||
do_initcalls();
|
do_initcalls();
|
||||||
|
|
||||||
struct limine_file *file = module_res->modules[0];
|
|
||||||
|
|
||||||
fs_t *initramfs;
|
|
||||||
|
|
||||||
int res = cpio_read_and_init(file->address, file->size, &initramfs);
|
|
||||||
|
|
||||||
if (res < 0)
|
|
||||||
panic("failed to load initramfs: %s\n", strerror(-res));
|
|
||||||
|
|
||||||
/* do nothing, for now :) */
|
/* do nothing, for now :) */
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,17 @@
|
||||||
|
|
||||||
#define REQUEST __attribute__((used, section(".limine_requests"))) volatile
|
#define REQUEST __attribute__((used, section(".limine_requests"))) volatile
|
||||||
|
|
||||||
REQUEST u64 _limine_requests_start[] = LIMINE_REQUESTS_START_MARKER;
|
|
||||||
|
|
||||||
REQUEST struct limine_executable_address_request kern_addr_req = {.id = LIMINE_EXECUTABLE_ADDRESS_REQUEST_ID, .revision = 0};
|
REQUEST struct limine_executable_address_request kern_addr_req = {.id = LIMINE_EXECUTABLE_ADDRESS_REQUEST_ID, .revision = 0};
|
||||||
REQUEST struct limine_memmap_request memmap_req = {.id = LIMINE_MEMMAP_REQUEST_ID, .revision = 0};
|
REQUEST struct limine_memmap_request memmap_req = {.id = LIMINE_MEMMAP_REQUEST_ID, .revision = 0};
|
||||||
REQUEST struct limine_hhdm_request hhdm_req = {.id = LIMINE_HHDM_REQUEST_ID, .revision = 0};
|
REQUEST struct limine_hhdm_request hhdm_req = {.id = LIMINE_HHDM_REQUEST_ID, .revision = 0};
|
||||||
REQUEST struct limine_rsdp_request rsdp_req = {.id = LIMINE_RSDP_REQUEST_ID, .revision = 0};
|
REQUEST struct limine_rsdp_request rsdp_req = {.id = LIMINE_RSDP_REQUEST_ID, .revision = 0};
|
||||||
REQUEST struct limine_module_request module_req = {.id = LIMINE_MODULE_REQUEST_ID, .revision = 0};
|
|
||||||
REQUEST u64 limine_base_revision[] = LIMINE_BASE_REVISION(6);
|
|
||||||
|
|
||||||
REQUEST u64 _limine_requests_end[] = LIMINE_REQUESTS_END_MARKER;
|
REQUEST u64 limine_base_revision[] = LIMINE_BASE_REVISION(6);
|
||||||
|
|
||||||
struct limine_executable_address_response *kern_addr_res = NULL;
|
struct limine_executable_address_response *kern_addr_res = NULL;
|
||||||
struct limine_memmap_response *kern_map_res = NULL;
|
struct limine_memmap_response *kern_map_res = NULL;
|
||||||
struct limine_hhdm_response *kern_hhdm_res = NULL;
|
struct limine_hhdm_response *kern_hhdm_res = NULL;
|
||||||
struct limine_rsdp_response *kern_rsdp_res = NULL;
|
struct limine_rsdp_response *kern_rsdp_res = NULL;
|
||||||
struct limine_module_response *module_res = NULL;
|
|
||||||
|
|
||||||
vaddr_t hhdm_start = 0;
|
vaddr_t hhdm_start = 0;
|
||||||
|
|
||||||
|
|
@ -29,7 +24,6 @@ void requests_init()
|
||||||
kern_map_res = memmap_req.response;
|
kern_map_res = memmap_req.response;
|
||||||
kern_hhdm_res = hhdm_req.response;
|
kern_hhdm_res = hhdm_req.response;
|
||||||
kern_rsdp_res = rsdp_req.response;
|
kern_rsdp_res = rsdp_req.response;
|
||||||
module_res = module_req.response;
|
|
||||||
|
|
||||||
hhdm_start = kern_hhdm_res->offset;
|
hhdm_start = kern_hhdm_res->offset;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,6 @@ SECTIONS
|
||||||
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
||||||
__kernel_end = .;
|
__kernel_end = .;
|
||||||
|
|
||||||
.limine_requests : { KEEP(*(.limine_requests)) }
|
|
||||||
|
|
||||||
/DISCARD/ : {
|
/DISCARD/ : {
|
||||||
*(.eh_frame)
|
*(.eh_frame)
|
||||||
*(.note .note.*)
|
*(.note .note.*)
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ void *kalloc(size_t size, u64 flags)
|
||||||
ret = slab_alloc(slab);
|
ret = slab_alloc(slab);
|
||||||
if (ret)
|
if (ret)
|
||||||
size = slab->item_size;
|
size = slab->item_size;
|
||||||
alloc_type = ALLOC_TYPE_SLAB;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,14 @@ void page_init()
|
||||||
kpgd = pt_alloc();
|
kpgd = pt_alloc();
|
||||||
|
|
||||||
map_hhdm_zones(kpgd);
|
map_hhdm_zones(kpgd);
|
||||||
paddr_t kernel_paddr = kern_addr_res->physical_base;
|
paddr_t kernel_paddr = 0;
|
||||||
|
for (size_t i = 0; i < kern_map_res->entry_count; i++) {
|
||||||
|
struct limine_memmap_entry *ent = kern_map_res->entries[i];
|
||||||
|
if (ent->type == LIMINE_MEMMAP_EXECUTABLE_AND_MODULES) {
|
||||||
|
kernel_paddr = ent->base;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t kernel_size = (size_t)__kernel_end - (size_t)__kernel_start;
|
size_t kernel_size = (size_t)__kernel_end - (size_t)__kernel_start;
|
||||||
vaddr_t kernel_start = ((size_t)__kernel_start) & PAGE_MASK;
|
vaddr_t kernel_start = ((size_t)__kernel_start) & PAGE_MASK;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ $(IMG): limine/limine $(KERNEL)
|
||||||
mformat -F -v "ESP" -H 2048 -i $(IMG)@@1M
|
mformat -F -v "ESP" -H 2048 -i $(IMG)@@1M
|
||||||
|
|
||||||
mmd -i $(IMG)@@1M ::/EFI ::/EFI/BOOT ::/boot ::/boot/limine
|
mmd -i $(IMG)@@1M ::/EFI ::/EFI/BOOT ::/boot ::/boot/limine
|
||||||
mcopy -i $(IMG)@@1M kernel.elf initramfs.cpio ::/
|
mcopy -i $(IMG)@@1M kernel.elf ::/
|
||||||
mcopy -i $(IMG)@@1M limine.conf ::/boot/limine
|
mcopy -i $(IMG)@@1M limine.conf ::/boot/limine
|
||||||
mcopy -i $(IMG)@@1M limine/limine-bios.sys ::/boot/limine
|
mcopy -i $(IMG)@@1M limine/limine-bios.sys ::/boot/limine
|
||||||
mcopy -i $(IMG)@@1M limine/BOOTX64.EFI ::/EFI/BOOT
|
mcopy -i $(IMG)@@1M limine/BOOTX64.EFI ::/EFI/BOOT
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue