diff --git a/host-recipes/limine b/host-recipes/limine index 20b1e87e..7219c45c 100644 --- a/host-recipes/limine +++ b/host-recipes/limine @@ -1,7 +1,7 @@ name=limine from_source=limine revision=1 -imagedeps="build-essential mtools nasm" +imagedeps="build-essential mtools nasm clang lld llvm" configure() { "${source_dir}/configure" --enable-bios-cd --enable-bios-pxe --enable-bios --enable-uefi-ia32 --enable-uefi-x86-64 --enable-uefi-cd --prefix="${prefix}" diff --git a/kernel-src/Makefile b/kernel-src/Makefile index 4c89ae90..da8b9cf0 100644 --- a/kernel-src/Makefile +++ b/kernel-src/Makefile @@ -9,7 +9,7 @@ FLANTERMOPTS=-DFLANTERM_FB_DISABLE_BUMP_ALLOC # required for mpaland printf so it doesn't compile with floating point support, which results in build failures PRINTFOPTS=-DPRINTF_DISABLE_SUPPORT_FLOAT # flanterm includes break if the headers are moved into the include dir in the tree -FLANTERMINCDIR=$(shell pwd)/flanterm +FLANTERMINCDIR=$(shell pwd)/flanterm/src UACPIINCDIR=$(shell pwd)/io/acpi/uacpi/include UACPIOPTS=-DUACPI_OVERRIDE_LIBC -DUACPI_KERNEL_INITIALIZATION -DUACPI_NATIVE_ALLOC_ZEROED KERNELCONFIG=#-DX86_64_ENABLE_E9 -DENABLE_PROFILING #-DSYSCALL_LOGGING diff --git a/kernel-src/arch/x86-64/acpi.c b/kernel-src/arch/x86-64/acpi.c index 990051f2..16d76e10 100644 --- a/kernel-src/arch/x86-64/acpi.c +++ b/kernel-src/arch/x86-64/acpi.c @@ -5,7 +5,7 @@ #include static volatile struct limine_rsdp_request rsdp_request = { - .id = LIMINE_RSDP_REQUEST, + .id = LIMINE_RSDP_REQUEST_ID, .revision = 0 }; diff --git a/kernel-src/arch/x86-64/mmu.c b/kernel-src/arch/x86-64/mmu.c index 63ac1e0e..87a2b57f 100644 --- a/kernel-src/arch/x86-64/mmu.c +++ b/kernel-src/arch/x86-64/mmu.c @@ -314,8 +314,8 @@ static mmuflags_t kernelflags[3] = { extern volatile struct limine_memmap_request pmm_liminemap; -static volatile struct limine_kernel_address_request kaddrreq = { - .id = LIMINE_KERNEL_ADDRESS_REQUEST, +static volatile struct limine_executable_address_request kaddrreq = { + .id = LIMINE_EXECUTABLE_ADDRESS_REQUEST_ID, .revision = 0 }; @@ -389,11 +389,13 @@ void arch_mmu_init() { for (size_t i = 0; i < pmm_liminemap.response->entry_count; ++i) { struct limine_memmap_entry *e = pmm_liminemap.response->entries[i]; - if (e->type != LIMINE_MEMMAP_USABLE && e->type != LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE && e->type != LIMINE_MEMMAP_KERNEL_AND_MODULES && e->type != LIMINE_MEMMAP_FRAMEBUFFER) + if (e->type != LIMINE_MEMMAP_USABLE && e->type != LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE && e->type != LIMINE_MEMMAP_EXECUTABLE_AND_MODULES && e->type != LIMINE_MEMMAP_FRAMEBUFFER) continue; for (uint64_t i = 0; i < e->length; i += PAGE_SIZE) { uint64_t entry = ((e->base + i) & ADDRMASK) | ARCH_MMU_FLAGS_READ | ARCH_MMU_FLAGS_WRITE | ARCH_MMU_FLAGS_NOEXEC | ARCH_MMU_FLAGS_GLOBAL; + if (e->type == LIMINE_MEMMAP_FRAMEBUFFER) + entry |= ARCH_MMU_FLAGS_WC; __assert(add_page(FROM_HHDM(template), MAKE_HHDM((void *)(e->base + i)), entry, 0)); } } diff --git a/kernel-src/arch/x86-64/smp.c b/kernel-src/arch/x86-64/smp.c index aa83cfc0..d80868f8 100644 --- a/kernel-src/arch/x86-64/smp.c +++ b/kernel-src/arch/x86-64/smp.c @@ -12,22 +12,22 @@ DEFINE_KERNEL_ARGUMENT(nosmp, bool); -static volatile struct limine_smp_request smprequest = { - .id = LIMINE_SMP_REQUEST +static volatile struct limine_mp_request smprequest = { + .id = LIMINE_MP_REQUEST_ID }; // set to 1 because of the bsp size_t arch_smp_cpusawake = 1; // for panic. if the nosmp argument is given to the kernel, this is what the APs will jump to -static void cpuwakeuphalt(struct limine_smp_info *info) { +static void cpuwakeuphalt(struct limine_mp_info *info) { asm("cli"); for (;;) CPU_HALT(); } static long next_id = 1; -static void cpuwakeup(struct limine_smp_info *info) { +static void cpuwakeup(struct limine_mp_info *info) { cpu_set((cpu_t *)info->extra_argument); current_cpu()->internal_id = __atomic_fetch_add(&next_id, 1, __ATOMIC_SEQ_CST); @@ -69,7 +69,7 @@ size_t arch_smp_get_cpu_count(void) { if (GET_KERNEL_ARGUMENT(nosmp, bool)) return 1; - struct limine_smp_response *response = smprequest.response; + struct limine_mp_response *response = smprequest.response; if (response == NULL) return 1; @@ -84,7 +84,7 @@ cpu_t *arch_smp_get_cpu_by_internal_id(long id) { } void arch_smp_wakeup(void) { - struct limine_smp_response *response = smprequest.response; + struct limine_mp_response *response = smprequest.response; if (response == NULL) { // TODO try to detect the other processors manually printf("smp: limine smp request response not present\n"); @@ -103,7 +103,7 @@ void arch_smp_wakeup(void) { smp_cpus = alloc(response->cpu_count * sizeof(cpu_t *)); __assert(smp_cpus); - void (*wakeupfn)(struct limine_smp_info *) = GET_KERNEL_ARGUMENT(nosmp, bool) ? cpuwakeuphalt : cpuwakeup; + void (*wakeupfn)(struct limine_mp_info *) = GET_KERNEL_ARGUMENT(nosmp, bool) ? cpuwakeuphalt : cpuwakeup; // make the other processors jump to cpuwakeup() for (int i = 0; i < response->cpu_count; ++i) { diff --git a/kernel-src/fs/initrd.c b/kernel-src/fs/initrd.c index ffb7910a..a167a73c 100644 --- a/kernel-src/fs/initrd.c +++ b/kernel-src/fs/initrd.c @@ -102,7 +102,7 @@ static void buildentry(tarentry_t *entry, void *addr) { } static volatile struct limine_module_request modreq = { - .id = LIMINE_MODULE_REQUEST, + .id = LIMINE_MODULE_REQUEST_ID, .revision = 0 }; diff --git a/kernel-src/include/x86-64/arch/mmu.h b/kernel-src/include/x86-64/arch/mmu.h index 60f68ecd..6d945290 100644 --- a/kernel-src/include/x86-64/arch/mmu.h +++ b/kernel-src/include/x86-64/arch/mmu.h @@ -23,7 +23,7 @@ #define ARCH_MMU_FLAGS_WB 0 #define ARCH_MMU_FLAGS_WT (1 << 3) #define ARCH_MMU_FLAGS_UC (1 << 4) -#define ARCH_MMU_FLAGS_WC ((1 << 12) | (1 << 3)) // PAT5 (limine sets up the 5th PAT entry as WC) +#define ARCH_MMU_FLAGS_WC ((1 << 7) | (1 << 3)) // PAT5 (limine sets up the 5th PAT entry as WC) #define PAGE_MASK 0xfffffffffffff000lu diff --git a/kernel-src/io/fb.c b/kernel-src/io/fb.c index 0a408ee3..2061a239 100644 --- a/kernel-src/io/fb.c +++ b/kernel-src/io/fb.c @@ -70,7 +70,7 @@ typedef struct { #define FB_TYPE_PACKED_PIXELS 0 volatile struct limine_framebuffer_request fb_liminereq = { - .id = LIMINE_FRAMEBUFFER_REQUEST, + .id = LIMINE_FRAMEBUFFER_REQUEST_ID, .revision = 0 }; @@ -153,7 +153,7 @@ static int mmap(int minor, void *addr, uintmax_t offset, int flags) { memcpy(MAKE_HHDM(paddr), (void *)((uintptr_t)fbs[minor]->address + offset), size); - if (arch_mmu_map(current_vmm_context()->pagetable, paddr, addr, vnodeflagstommuflags(flags)) == false) { + if (arch_mmu_map(current_vmm_context()->pagetable, paddr, addr, vnodeflagstommuflags(flags) | ARCH_MMU_FLAGS_WC) == false) { pmm_release(paddr); return ENOMEM; } @@ -257,11 +257,6 @@ void fb_init() { printf("%s: %dx%d %d bpp\n", name, fb->width, fb->height, fb->bpp); } - - - void *fb_map = vmm_map(NULL, fbs[0]->pitch * fbs[0]->height, VMM_FLAGS_PHYSICAL, ARCH_MMU_FLAGS_READ | ARCH_MMU_FLAGS_WRITE | ARCH_MMU_FLAGS_NOEXEC | ARCH_MMU_FLAGS_WC, FROM_HHDM(fbs[0]->address)); - __assert(fb_map); - term_update_framebuffer(fb_map); } INIT_ROUTINE_DEFINE(fb, INIT_ROUTINE_FLAGS_NONE, fb_init, devfs); diff --git a/kernel-src/io/pci.c b/kernel-src/io/pci.c index 202dbbab..c0dbab05 100644 --- a/kernel-src/io/pci.c +++ b/kernel-src/io/pci.c @@ -124,6 +124,7 @@ size_t pci_initmsix(pcienum_t *e) { #define PCI_MSI_64BIT (1 << 7) size_t pci_initmsi(pcienum_t *e, int requested) { + // TODO maybe initialize mask if applicable? __assert(requested == 1); if (e->msi.exists == false) return 0; @@ -131,6 +132,7 @@ size_t pci_initmsi(pcienum_t *e, int requested) { uint16_t msgctl = PCI_READ16(e, e->msi.offset + 2); msgctl |= PCI_MSI_ENABLE; msgctl &= ~(PCI_MSI_MULTIPLE_MESSAGE_SUPPORT_MASK); // no multiple message support + PCI_WRITE16(e, e->msi.offset + 2, msgctl); pci_setcommand(e, PCI_COMMAND_IRQDISABLE, 1); diff --git a/kernel-src/io/term.c b/kernel-src/io/term.c index 1e987f28..58c07d3c 100644 --- a/kernel-src/io/term.c +++ b/kernel-src/io/term.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -11,6 +11,10 @@ #include #include +static volatile struct limine_flanterm_fb_init_params_request flanterm_request = { + .id = LIMINE_FLANTERM_FB_INIT_PARAMS_REQUEST_ID +}; + extern volatile struct limine_framebuffer_request fb_liminereq; static size_t xs, ys, fbxs, fbys; bool init_done; @@ -70,26 +74,29 @@ void term_init() { uint32_t defaultbg = 0x1b1c1b; uint32_t defaultfg = 0xffffff; - // TODO add support for a background if desired by the user - term_ctx = flanterm_fb_init(internalalloc, noop, fb->address, fb->width, fb->height, fb->pitch, - fb->red_mask_size, fb->red_mask_shift, fb->green_mask_size, fb->green_mask_shift, fb->blue_mask_size, fb->blue_mask_shift, - NULL, NULL, NULL, &defaultbg, &defaultfg, NULL, NULL, NULL, - 0, 0, 1, 1, 1, 0); + if (flanterm_request.response && flanterm_request.response->entry_count) { + struct limine_flanterm_fb_init_params *param = flanterm_request.response->entries[0]; + term_ctx = flanterm_fb_init(internalalloc, noop, fb->address, fb->width, fb->height, fb->pitch, + fb->red_mask_size, fb->red_mask_shift, fb->green_mask_size, fb->green_mask_shift, fb->blue_mask_size, fb->blue_mask_shift, + param->canvas, param->ansi_colours, param->ansi_bright_colours, + ¶m->default_bg, ¶m->default_fg, ¶m->default_bg_bright, ¶m->default_fg_bright, + param->font, param->font_width, param->font_height, param->font_spacing, param->font_scale_x, param->font_scale_y, + param->margin, param->rotation); + } else { + term_ctx = flanterm_fb_init(internalalloc, noop, fb->address, fb->width, fb->height, fb->pitch, + fb->red_mask_size, fb->red_mask_shift, fb->green_mask_size, fb->green_mask_shift, fb->blue_mask_size, fb->blue_mask_shift, + NULL, NULL, NULL, &defaultbg, &defaultfg, NULL, NULL, NULL, + 0, 0, 1, 1, 1, 0, 0); + } __assert(term_ctx); - xs = term_ctx->cols; - ys = term_ctx->rows; + flanterm_get_dimensions(term_ctx, &xs, &ys); fbxs = fb->width; fbys = fb->height; MUTEX_INIT(&term_mutex); - logging_sethook(term_putchar); } -void term_update_framebuffer(void *fb) { - ((struct flanterm_fb_context *)fb)->framebuffer = fb; -} - INIT_ROUTINE_DEFINE(term, INIT_ROUTINE_FLAGS_NONE, term_init, vmm); diff --git a/kernel-src/main.c b/kernel-src/main.c index a95a273e..88e66a9a 100644 --- a/kernel-src/main.c +++ b/kernel-src/main.c @@ -7,6 +7,9 @@ #include #include #include +#include + +__attribute__((used)) static uint64_t base_revision[] = LIMINE_BASE_REVISION(6); static cpu_t bsp_cpu; diff --git a/kernel-src/mm/pmm.c b/kernel-src/mm/pmm.c index 239eb771..9eb83265 100644 --- a/kernel-src/mm/pmm.c +++ b/kernel-src/mm/pmm.c @@ -35,12 +35,12 @@ static section_t sections[PMM_SECTION_COUNT] = { }; static volatile struct limine_hhdm_request hhdmreq = { - .id = LIMINE_HHDM_REQUEST, + .id = LIMINE_HHDM_REQUEST_ID, .revision = 0 }; volatile struct limine_memmap_request pmm_liminemap = { - .id = LIMINE_MEMMAP_REQUEST, + .id = LIMINE_MEMMAP_REQUEST_ID, .revision = 0 }; @@ -235,7 +235,7 @@ void pmm_init() { for (size_t i = 0; i < pmm_liminemap.response->entry_count; ++i) { struct limine_memmap_entry *e = pmm_liminemap.response->entries[i]; printf("pmm: %016p -> %016p: %d\n", e->base, e->base + e->length, e->type); - if (e->type == LIMINE_MEMMAP_USABLE || e->type == LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE || e->type == LIMINE_MEMMAP_KERNEL_AND_MODULES) { + if (e->type == LIMINE_MEMMAP_USABLE || e->type == LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE || e->type == LIMINE_MEMMAP_EXECUTABLE_AND_MODULES) { size_t sectiontop = e->base + e->length; if (sectiontop > top) top = sectiontop; diff --git a/kernel-src/mm/vmm.c b/kernel-src/mm/vmm.c index 461c2dcb..09ecd3d7 100644 --- a/kernel-src/mm/vmm.c +++ b/kernel-src/mm/vmm.c @@ -1024,10 +1024,13 @@ void vmm_init() { for (uint64_t i = 0; i < pmm_liminemap.response->entry_count; ++i) { struct limine_memmap_entry *e = pmm_liminemap.response->entries[i]; - if (e->type != LIMINE_MEMMAP_USABLE && e->type != LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE && e->type != LIMINE_MEMMAP_KERNEL_AND_MODULES && e->type != LIMINE_MEMMAP_FRAMEBUFFER) + if (e->type != LIMINE_MEMMAP_USABLE && e->type != LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE && e->type != LIMINE_MEMMAP_EXECUTABLE_AND_MODULES && e->type != LIMINE_MEMMAP_FRAMEBUFFER) continue; mmuflags_t mmuflags = ARCH_MMU_FLAGS_READ | ARCH_MMU_FLAGS_WRITE | ARCH_MMU_FLAGS_NOEXEC | ARCH_MMU_FLAGS_GLOBAL; + if (e->type == LIMINE_MEMMAP_FRAMEBUFFER) + mmuflags |= ARCH_MMU_FLAGS_WC; + __assert(vmm_map(MAKE_HHDM(e->base), e->length, VMM_FLAGS_EXACT, mmuflags, NULL)); } diff --git a/kernel-src/sys/kernel_args.c b/kernel-src/sys/kernel_args.c index 7a7fb9b1..2d9600ad 100644 --- a/kernel-src/sys/kernel_args.c +++ b/kernel-src/sys/kernel_args.c @@ -6,8 +6,8 @@ #define TOTAL_ARGUMENTS_CHARACTER_LIMIT 4096 -static volatile struct limine_kernel_file_request kernel_file_request = { - .id = LIMINE_KERNEL_FILE_REQUEST, +static volatile struct limine_executable_file_request executable_file_request = { + .id = LIMINE_EXECUTABLE_FILE_REQUEST_ID, .revision = 0 }; @@ -43,8 +43,8 @@ static void insert_argument(const char *key, const char *value) { } void kernel_arguments_parse(void) { - __assert(kernel_file_request.response); - const char *cmdline = kernel_file_request.response->kernel_file->cmdline; + __assert(executable_file_request.response); + const char *cmdline = executable_file_request.response->executable_file->string; __assert(cmdline); size_t length = min(strlen(cmdline), TOTAL_ARGUMENTS_CHARACTER_LIMIT); char temp_buffer[length + 1]; diff --git a/kernel-src/sys/timekeeper.c b/kernel-src/sys/timekeeper.c index b589e52e..94991d35 100644 --- a/kernel-src/sys/timekeeper.c +++ b/kernel-src/sys/timekeeper.c @@ -6,8 +6,8 @@ #include #include -static volatile struct limine_boot_time_request timereq = { - .id = LIMINE_BOOT_TIME_REQUEST, +static volatile struct limine_date_at_boot_request timereq = { + .id = LIMINE_DATE_AT_BOOT_REQUEST_ID, .revision = 0 }; @@ -135,7 +135,7 @@ void timekeeper_wait_us(time_t us) { void timekeeper_early_init(void) { __assert(timereq.response); - boot_unix = timereq.response->boot_time; + boot_unix = timereq.response->timestamp; current_cpu()->timekeeper_sync_isr = interrupt_allocate(timekeeper_sync_isr, ARCH_EOI, IPL_DPC); __assert(current_cpu()->timekeeper_sync_isr); diff --git a/recipes/limine b/recipes/limine index e2e05a0b..4a42ae7c 100644 --- a/recipes/limine +++ b/recipes/limine @@ -6,7 +6,7 @@ hostdeps="xgcc xbinutils" deps="base" configure() { - "${source_dir}/configure" --host=x86_64-astral --enable-bios-cd --enable-bios-pxe --enable-bios --enable-uefi-ia32 --enable-uefi-x86-64 --enable-uefi-cd --prefix="${prefix}" + TOOLCHAIN_FOR_TARGET=x86_64-astral- "${source_dir}/configure" --host=x86_64-astral --enable-bios-cd --enable-bios-pxe --enable-bios --enable-uefi-ia32 --enable-uefi-x86-64 --enable-uefi-cd --prefix="${prefix}" } build() { diff --git a/source-recipes/astral b/source-recipes/astral index 0343cfdc..4d93c0c0 100644 --- a/source-recipes/astral +++ b/source-recipes/astral @@ -3,14 +3,14 @@ version=0 source_dir="kernel-src" allow_network="yes" imagedeps="wget" -flanterm_commit="347d9cf1e3fced64aa20ab278e2fdcc834086035" +flanterm_commit="b5038e828de1dc6c049222a3c1670f7976e6c5a3" prepare() { rm -f include/limine.h rm -f io/printf.c rm -f include/printf.h rm -rf flanterm - curl https://raw.githubusercontent.com/limine-bootloader/limine-protocol/4607d68cbdbe653885937fb3178449588addb799/include/limine.h > include/limine.h + curl https://raw.githubusercontent.com/limine-bootloader/limine-protocol/26519f1b598564db409e50d1d84eb30642d58ba3/include/limine.h > include/limine.h pushd /tmp/ wget https://github.com/mpaland/printf/archive/refs/tags/v4.0.0.tar.gz tar -xf v4.0.0.tar.gz @@ -19,5 +19,5 @@ prepare() { popd cp /tmp/printf-4.0.0/printf.c io/printf.c cp /tmp/printf-4.0.0/printf.h include/printf.h - cp -r /tmp/flanterm-${flanterm_commit} flanterm + cp -r /tmp/Flanterm-${flanterm_commit} flanterm } diff --git a/source-recipes/limine b/source-recipes/limine index c6924bd8..566c645b 100644 --- a/source-recipes/limine +++ b/source-recipes/limine @@ -1,8 +1,8 @@ name=limine -version=8.0.10 +version=11.0.0 source_method=tarball tarball_url="https://github.com/limine-bootloader/limine/releases/download/v${version}/limine-${version}.tar.gz" -tarball_sha512="28110a666932197c01a7c8628ad8ff532695e56d4ed7047755601ede737b256f64e6978a2627d2a90c14fea9a545302e60bf7d9a2eac897e57f7dd7aa8133dbe" +tarball_sha512="d18ee2b657df89f29502706d3403fb69465c7e55c399c00f41504a0bc5acd8a3188bfef030cd9ea1464c450e6ca9f049b93b1262999f1d1a35fdd4b6fbc8f8f7" hostdeps="autoconf automake libtool pkgconfig" prepare() {