Compare commits
2 commits
6374144f4a
...
89795c4ad8
Author | SHA1 | Date | |
---|---|---|---|
89795c4ad8 | |||
65ba98a089 |
11 changed files with 183 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ limine/
|
|||
ovmf/
|
||||
release/
|
||||
*.log
|
||||
.config*
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "external/flanterm"]
|
||||
path = external/flanterm
|
||||
url = https://codeberg.org/mintsuki/flanterm
|
4
.vscode/c_cpp_properties.json
vendored
4
.vscode/c_cpp_properties.json
vendored
|
@ -10,7 +10,9 @@
|
|||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"defines": [
|
||||
"LIMINE_API_REVISION=3"
|
||||
"LIMINE_API_REVISION=3",
|
||||
"FLANTERM_SUPPORT=1",
|
||||
"BUILD_MODE=\"\""
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
|
@ -13,6 +13,10 @@
|
|||
"emk.h": "c",
|
||||
"heap.h": "c",
|
||||
"vmm.h": "c",
|
||||
"align.h": "c"
|
||||
"align.h": "c",
|
||||
"cpu.h": "c",
|
||||
"nanoprintf.h": "c",
|
||||
"flanterm.h": "c",
|
||||
"serial.h": "c"
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
|
||||
QEMUFLAGS := -m 2G -serial stdio -display none
|
||||
QEMUFLAGS := -m 2G -serial stdio
|
||||
USER_QEMUFLAGS ?=
|
||||
IMAGE_NAME := release/emk
|
||||
|
||||
|
|
1
external/flanterm
vendored
Submodule
1
external/flanterm
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit bdecdcb1b7dad05ab5249e2c3e4d2c27a661e864
|
|
@ -8,19 +8,34 @@ BINDIR := bin
|
|||
|
||||
TARGET := $(BINDIR)/emk.elf
|
||||
|
||||
KCONFIG ?= kconfig-mconf
|
||||
CONFIG := .config
|
||||
|
||||
ifneq ("$(wildcard $(CONFIG))","")
|
||||
include $(CONFIG)
|
||||
endif
|
||||
|
||||
CC := gcc
|
||||
AS := gcc
|
||||
NASM := nasm
|
||||
|
||||
# Build mode configuration
|
||||
BUILD_MODE ?= dev
|
||||
ifeq ($(BUILD_MODE),)
|
||||
ifeq ($(CONFIG_BUILD_MODE_DEBUG),y)
|
||||
BUILD_MODE := debug
|
||||
else ifeq ($(CONFIG_BUILD_MODE_RELEASE),y)
|
||||
BUILD_MODE := release
|
||||
else
|
||||
BUILD_MODE := debug
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(BUILD_MODE),release)
|
||||
CFLAGS := -Os -pipe -Wall -Wextra -Werror -std=gnu11 -ffreestanding \
|
||||
-fno-stack-protector -fno-stack-check -fno-PIC \
|
||||
-ffunction-sections -fdata-sections -m64 -march=x86-64 \
|
||||
-mno-80387 -mno-mmx -mno-sse -mno-sse2 -mno-red-zone \
|
||||
-mcmodel=kernel -fno-unwind-tables -fno-asynchronous-unwind-tables \
|
||||
-s -Wno-unused-variable
|
||||
-s -Wno-unused-variable -DBUILD_MODE=\"release\"
|
||||
NASMFLAGS :=
|
||||
LDFLAGS := -nostdlib -static -z max-page-size=0x1000 -Wl,--gc-sections \
|
||||
-T linker.ld -Wl,-m,elf_x86_64 -Wl,--strip-all
|
||||
|
@ -29,7 +44,7 @@ else
|
|||
-fno-stack-protector -fno-stack-check -fno-PIC \
|
||||
-ffunction-sections -fdata-sections -m64 -march=x86-64 \
|
||||
-mno-80387 -mno-mmx -mno-sse -mno-sse2 -mno-red-zone \
|
||||
-mcmodel=kernel -Wno-unused-variable
|
||||
-mcmodel=kernel -Wno-unused-variable -DBUILD_MODE=\"dev\"
|
||||
NASMFLAGS := -F dwarf -g
|
||||
LDFLAGS := -nostdlib -static -z max-page-size=0x1000 -Wl,--gc-sections \
|
||||
-T linker.ld -Wl,-m,elf_x86_64
|
||||
|
@ -37,14 +52,48 @@ endif
|
|||
|
||||
CPPFLAGS := -I../external -I$(SRCDIR) -MMD -MP -DLIMINE_API_REVISION=3
|
||||
|
||||
SRCS := $(shell find $(SRCDIR) -type f \( -name '*.c' -o -name '*.S' -o -name '*.asm' \))
|
||||
OBJS := $(patsubst %.c,$(OBJDIR)/%.o,$(filter %.c,$(SRCS))) \
|
||||
$(patsubst %.S,$(OBJDIR)/%.o,$(filter %.S,$(SRCS))) \
|
||||
$(patsubst %.asm,$(OBJDIR)/%.o,$(filter %.asm,$(SRCS)))
|
||||
IMPLICIT_SRCS :=
|
||||
ifeq ($(CONFIG_KERNEL_HEAP_FF),y)
|
||||
IMPLICIT_SRCS += src/mm/heap/ff.c
|
||||
else
|
||||
$(error Error: No heap algorithm was defined. Please run "make menuconfig" and select one.)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_FLANTERM),y)
|
||||
IMPLICIT_SRCS += ../external/flanterm/flanterm.c
|
||||
IMPLICIT_SRCS += ../external/flanterm/backends/fb.c
|
||||
CFLAGS += -I../external/flanterm/ -DFLANTERM_SUPPORT=1
|
||||
endif
|
||||
|
||||
EXCLUDE_SRCS := \
|
||||
src/mm/heap/ff.c \
|
||||
../external/flanterm/flanterm.c \
|
||||
../external/flanterm/backends/fb.c
|
||||
EXCLUDE_PATTERNS := $(foreach file,$(EXCLUDE_SRCS),! -path "$(file)")
|
||||
|
||||
SRCS := $(IMPLICIT_SRCS) \
|
||||
$(shell find $(SRCDIR) -type f \( -name '*.c' -o -name '*.S' -o -name '*.asm' \) $(EXCLUDE_PATTERNS))
|
||||
|
||||
define src_to_obj
|
||||
$(OBJDIR)/$(patsubst ../%,%,$(1:.c=.o))
|
||||
endef
|
||||
|
||||
define src_to_obj_s
|
||||
$(OBJDIR)/$(patsubst ../%,%,$(1:.S=.o))
|
||||
endef
|
||||
|
||||
define src_to_obj_asm
|
||||
$(OBJDIR)/$(patsubst ../%,%,$(1:.asm=.o))
|
||||
endef
|
||||
|
||||
OBJS :=
|
||||
OBJS += $(foreach f,$(filter %.c,$(SRCS)),$(call src_to_obj,$(f)))
|
||||
OBJS += $(foreach f,$(filter %.S,$(SRCS)),$(call src_to_obj_s,$(f)))
|
||||
OBJS += $(foreach f,$(filter %.asm,$(SRCS)),$(call src_to_obj_asm,$(f)))
|
||||
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
|
||||
.PHONY: all clean distclean
|
||||
.PHONY: all clean distclean menuconfig
|
||||
all: $(TARGET)
|
||||
|
||||
$(OBJDIR) $(BINDIR):
|
||||
|
@ -54,16 +103,31 @@ $(TARGET): $(OBJS) | $(BINDIR)
|
|||
@echo " LD $@"
|
||||
@$(CC) $(LDFLAGS) -o $@ $(OBJS)
|
||||
|
||||
$(OBJDIR)/%.o: ../%.c | $(OBJDIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " CC ../$*"
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) -c ../$*.c -o $@
|
||||
|
||||
$(OBJDIR)/%.o: %.c | $(OBJDIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " CC $<"
|
||||
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/%.o: ../%.S | $(OBJDIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " AS ../$*"
|
||||
@$(AS) $(CPPFLAGS) $(CFLAGS) -c ../$*.S -o $@
|
||||
|
||||
$(OBJDIR)/%.o: %.S | $(OBJDIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " AS $<"
|
||||
@$(AS) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/%.o: ../%.asm | $(OBJDIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " NASM ../$*"
|
||||
@$(NASM) $(NASMFLAGS) ../$*.asm -o $@
|
||||
|
||||
$(OBJDIR)/%.o: %.asm | $(OBJDIR)
|
||||
@mkdir -p $(dir $@)
|
||||
@echo " NASM $<"
|
||||
|
@ -77,4 +141,7 @@ distclean: clean
|
|||
@echo " DISTCLEAN"
|
||||
@rm -rf $(BINDIR)
|
||||
|
||||
menuconfig: clean
|
||||
@$(KCONFIG) Kconfig
|
||||
|
||||
-include $(DEPS)
|
33
kernel/Kconfig
Normal file
33
kernel/Kconfig
Normal file
|
@ -0,0 +1,33 @@
|
|||
mainmenu "EMK Build Configuration"
|
||||
|
||||
choice
|
||||
prompt "Build Mode"
|
||||
default BUILD_MODE_DEBUG
|
||||
|
||||
config BUILD_MODE_DEBUG
|
||||
bool "Debug"
|
||||
help
|
||||
Build with debug symbols and no optimizations.
|
||||
|
||||
config BUILD_MODE_RELEASE
|
||||
bool "Release"
|
||||
help
|
||||
Build with optimizations and no debug symbols.
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Kernel Heap Algorithm"
|
||||
default KERNEL_HEAP_FF
|
||||
|
||||
config KERNEL_HEAP_FF
|
||||
bool "First-Fit"
|
||||
help
|
||||
Use the First-Fit memory allocation algorithm (ff.c).
|
||||
|
||||
endchoice
|
||||
|
||||
config ENABLE_FLANTERM
|
||||
bool "Enable Flanterm Support"
|
||||
help
|
||||
Includes support for the Flanterm terminal emulator. Useful for debugging real hardware.
|
|
@ -5,6 +5,9 @@
|
|||
#include <boot/limine.h>
|
||||
#include <stdint.h>
|
||||
#include <mm/vmm.h>
|
||||
#if FLANTERM_SUPPORT
|
||||
#include <flanterm/flanterm.h>
|
||||
#endif // FLANTERM_SUPPORT
|
||||
|
||||
extern uint64_t hhdm_offset;
|
||||
extern struct limine_memmap_response *memmap;
|
||||
|
@ -18,4 +21,16 @@ extern vctx_t *kvm_ctx;
|
|||
|
||||
#define BIT(x) (1ULL << (x))
|
||||
|
||||
#ifndef FLANTERM_SUPPORT
|
||||
#define FLANTERM_SUPPORT 0
|
||||
#endif // FLANTERM_SUPPORT
|
||||
|
||||
#ifndef BUILD_MODE
|
||||
#define BUILD_MODE "unknown"
|
||||
#endif // BUILD_MODE
|
||||
|
||||
#if FLANTERM_SUPPORT
|
||||
extern struct flanterm_context *ft_ctx;
|
||||
#endif // FLANTERM_SUPPORT
|
||||
|
||||
#endif // EMK_H
|
|
@ -13,6 +13,10 @@
|
|||
#include <arch/paging.h>
|
||||
#include <mm/vmm.h>
|
||||
#include <mm/heap.h>
|
||||
#if FLANTERM_SUPPORT
|
||||
#include <flanterm/flanterm.h>
|
||||
#include <flanterm/backends/fb.h>
|
||||
#endif // FLANTERM_SUPPORT
|
||||
|
||||
__attribute__((used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
|
||||
__attribute__((used, section(".limine_requests"))) static volatile struct limine_memmap_request memmap_request = {
|
||||
|
@ -24,6 +28,11 @@ __attribute__((used, section(".limine_requests"))) static volatile struct limine
|
|||
__attribute__((used, section(".limine_requests"))) volatile struct limine_executable_address_request kernel_address_request = {
|
||||
.id = LIMINE_EXECUTABLE_ADDRESS_REQUEST,
|
||||
.response = 0};
|
||||
#if FLANTERM_SUPPORT
|
||||
__attribute__((used, section(".limine_requests"))) volatile struct limine_framebuffer_request framebuffer_request = {
|
||||
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
||||
.response = 0};
|
||||
#endif // FLANTERM_SUPPORT
|
||||
__attribute__((used, section(".limine_requests_start"))) static volatile LIMINE_REQUESTS_START_MARKER;
|
||||
__attribute__((used, section(".limine_requests_end"))) static volatile LIMINE_REQUESTS_END_MARKER;
|
||||
|
||||
|
@ -34,6 +43,10 @@ uint64_t kphys = 0;
|
|||
uint64_t kstack_top = 0;
|
||||
vctx_t *kvm_ctx = NULL;
|
||||
|
||||
#if FLANTERM_SUPPORT
|
||||
struct flanterm_context *ft_ctx = NULL;
|
||||
#endif // FLANTERM_SUPPORT
|
||||
|
||||
void emk_entry(void)
|
||||
{
|
||||
__asm__ volatile("movq %%rsp, %0" : "=r"(kstack_top));
|
||||
|
@ -42,8 +55,28 @@ void emk_entry(void)
|
|||
/* Just halt and say nothing */
|
||||
hcf();
|
||||
}
|
||||
|
||||
/* Init flanterm if we compiled with support */
|
||||
#if FLANTERM_SUPPORT
|
||||
struct limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];
|
||||
ft_ctx = flanterm_fb_init(
|
||||
NULL,
|
||||
NULL,
|
||||
framebuffer->address, framebuffer->width, framebuffer->height, framebuffer->pitch,
|
||||
framebuffer->red_mask_size, framebuffer->red_mask_shift,
|
||||
framebuffer->green_mask_size, framebuffer->green_mask_shift,
|
||||
framebuffer->blue_mask_size, framebuffer->blue_mask_shift,
|
||||
NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, NULL,
|
||||
NULL, 0, 0, 1,
|
||||
0, 0,
|
||||
0);
|
||||
#endif // FLANTERM_SUPPORT
|
||||
|
||||
log_early("Experimental Micro Kernel (EMK) 1.0 Copytright (c) 2025 Piraterna");
|
||||
log_early("Compiled at %s %s", __TIME__, __DATE__);
|
||||
log_early("Compiled at %s %s, emk1.0-%s, flanterm support: %s", __TIME__, __DATE__, BUILD_MODE, FLANTERM_SUPPORT ? "yes" : "no");
|
||||
|
||||
if (!LIMINE_BASE_REVISION_SUPPORTED)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
/* EMK 1.0 Copyright (c) 2025 Piraterna */
|
||||
#include <dev/serial.h>
|
||||
#include <util/kprintf.h>
|
||||
#include <dev/serial.h>
|
||||
#include <boot/emk.h>
|
||||
#if FLANTERM_SUPPORT
|
||||
#include <flanterm/flanterm.h>
|
||||
#endif // FLANTERM_SUPPORT
|
||||
|
||||
#define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1
|
||||
#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 1
|
||||
|
@ -22,6 +26,10 @@ int kprintf(const char *fmt, ...)
|
|||
if (length >= 0 && length < (int)sizeof(buffer))
|
||||
{
|
||||
serial_write(COM1, (uint8_t *)buffer, length);
|
||||
#if FLANTERM_SUPPORT
|
||||
if (ft_ctx)
|
||||
flanterm_write(ft_ctx, (char *)buffer, length);
|
||||
#endif // FLANTERM_SUPPORT
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue