Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
472d569
* Make Makefile a bit more generic.
iProgramMC Oct 14, 2025
0a5a3be
* X86: The code now compiles, but doesn't link yet.
iProgramMC Oct 14, 2025
b7e64a8
* X86: Still doesn't link, but now shows the undefined references.
iProgramMC Oct 14, 2025
7a1ef09
* X86: Kernel now links. Untested.
iProgramMC Oct 15, 2025
31b903c
* X86: Userspace and test driver now build for i386!
iProgramMC Oct 15, 2025
ca17d4e
* I8042prt: Fix 32-bit specific bug
iProgramMC Oct 15, 2025
4464afd
* Ext2fs: Fix compiler error
iProgramMC Oct 15, 2025
bc3d63f
* Test: Fix C2x warnings
iProgramMC Oct 15, 2025
d2668eb
* Move the Limine ISO step to a separate file.
iProgramMC Oct 15, 2025
9345fc8
* Use different limine configs for 32-bit and 64-bit.
iProgramMC Oct 15, 2025
316f208
* Add i386 run and runw rules + move run scripts to tools/.
iProgramMC Oct 15, 2025
b366a9a
* Ke: Fix a bug in the foreinit code where the bootstrap page directo…
iProgramMC Oct 15, 2025
6513236
* Mm,Ke: Improve physical memory mapping on i386
iProgramMC Oct 15, 2025
7c32f56
* Ke,Mm: Add support for Multiboot memory maps for i386.
iProgramMC Oct 15, 2025
db1afea
* Hali386: Begin
iProgramMC Oct 17, 2025
a291dca
* X86: Now boots to the framebuffer terminal!
iProgramMC Oct 17, 2025
107350e
* Framebuf: Port to 32-bit
iProgramMC Oct 17, 2025
3560293
* X86: More work
iProgramMC Oct 17, 2025
84de01b
* X86: Even more work with interrupts and the PIT!
iProgramMC Oct 17, 2025
513e047
* X86: Get timers mostly working
iProgramMC Oct 17, 2025
65cc29c
* Mm: Fix pool allocator for 32-bit systems
iProgramMC Oct 17, 2025
eda333e
* X86,Ke: Fix a bug where kernel crashes if there is no active thread…
iProgramMC Oct 17, 2025
b8e8972
* Test: Fix pipe test for 32-bit systems
iProgramMC Oct 17, 2025
f8499d6
* Ke(i386): Turns out we don't need the timer suppression after all
iProgramMC Oct 17, 2025
83c6cec
* Ke(i386): Fix bug where thread routine wasn't called correctly.
iProgramMC Oct 17, 2025
7f439cc
* Mm(i386): Fix several page table bugs
iProgramMC Oct 17, 2025
43f00c6
* Mm(i386): Fix PFN DB location, make PFDBE power of 2 again because …
iProgramMC Oct 17, 2025
dd7b847
* Test: Fix fireworks test on 32-bit
iProgramMC Oct 17, 2025
96c1511
* Mm(i386): Some memory manager fixes
iProgramMC Oct 18, 2025
20ca16d
* X86: More fixes.
iProgramMC Oct 18, 2025
1f2a2d1
* Mm(i386): Add a way for pool header slabs to be mapped in without t…
iProgramMC Oct 18, 2025
6e02913
* Mm: Add MmBeginUsingHHDM() and MmEndUsingHHDM() - for 32-bit, this …
iProgramMC Oct 18, 2025
aa7d998
* Mm: Completely rework the Cache Control Block structure.
iProgramMC Oct 20, 2025
3aca491
* Mm(i386): Well, we still have to make it build on 32-bit, don't we?
iProgramMC Oct 20, 2025
ad00b9b
* Mm: Fix a bug and a typo
iProgramMC Oct 20, 2025
1fdb87c
* Hal(i386): Fix timer going backwards temporarily because interrupts…
iProgramMC Oct 21, 2025
b41210b
* StorNvme: Make the initial semaphore wait alertable.
iProgramMC Oct 21, 2025
88bbe37
* Rtl: Add validity checks for ELF loading
iProgramMC Oct 21, 2025
1178f4a
* X86: First run of libboron + first syscall!
iProgramMC Oct 22, 2025
1f4ba7b
* Ke: Fix parameter passing in KeDescendIntoUserMode.
iProgramMC Oct 26, 2025
5a5bb5c
* Ke(i386): Fix definition of OSReadFile and OSWriteFile
iProgramMC Oct 26, 2025
fcbe1ae
* Libboron: Do not relocate the interpreter, it already relocated its…
iProgramMC Oct 26, 2025
0a1b3ca
* User: Running a second process now works!
iProgramMC Oct 26, 2025
e612aec
* Ke,Hal: Clean up logs
iProgramMC Oct 26, 2025
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
36 changes: 16 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ TARGETL ?= $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F
KERNEL_NAME = kernel.elf
SYSDLL_NAME = libboron.so

ifeq ($(TARGET),AMD64)
DRIVERS_LIST = \
halx86 \
framebuf \
i8042prt \
stornvme \
ext2fs \
test
else ifeq ($(TARGET),I386)
DRIVERS_LIST = \
hali386 \
framebuf \
i8042prt \
ext2fs \
test
endif

# The build directory
BUILD_DIR = build/$(TARGETL)
Expand Down Expand Up @@ -75,23 +84,13 @@ clean:

image: limine $(IMAGE_TARGET)

$(IMAGE_TARGET): kernel drivers apps limine_config
@echo "Building iso..."
@rm -rf $(ISO_DIR)
@mkdir -p $(ISO_DIR)
@cp $(KERNEL_ELF) $(ISO_DIR)/$(KERNEL_NAME)
@cp -r $(BUILD_DIR)/*.exe $(BUILD_DIR)/*.sys $(BUILD_DIR)/*.so limine.cfg limine/limine-bios.sys limine/limine-bios-cd.bin $(ISO_DIR)
@xorriso -as mkisofs -b limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table --protective-msdos-label $(ISO_DIR) -o $@ 2>/dev/null
@limine/limine-deploy $@ 2>/dev/null
@rm -rf $(ISO_DIR)

run: image
@echo "Running..."
@./run-unix.sh

runw: image
@echo "Invoking WSL to run the OS..."
@./run.sh
ifeq ($(TARGET),AMD64)
include tools/build_iso_limine.mk
include tools/run_rule_amd64.mk
else ifeq ($(TARGET),I386)
include tools/build_iso_limine.mk
include tools/run_rule_i386.mk
endif

kernel: $(KERNEL_ELF)

Expand Down Expand Up @@ -119,7 +118,4 @@ $(BUILD_DIR)/%.sys: FORCE
@$(MAKE) -C $(patsubst $(BUILD_DIR)/%.sys,$(DRIVERS_DIR)/%,$@)
@cp $(patsubst $(BUILD_DIR)/%.sys,$(DRIVERS_DIR)/%/build/out.$(TARGETL).sys,$@) $@

limine_config: limine.cfg
@echo "[MK]\tlimine.cfg was updated"

FORCE: ;
107 changes: 41 additions & 66 deletions boron/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ VER_MINOR = 0
# Currently the only application is clearing the input buffers with zero once read.
SECURE ?= no

# Default Target
TARGET ?= AMD64

# This sucks.
TARGETL=$(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(TARGET)))))))))))))))))))))))))))

BUILD_DIR = build
SRC_DIR = source
INC_DIR = include
DDKI_DIR = ../common/include
DDK_DIR = ../common/include
SCRIPTS_DIR = scripts
LINKER_FILE = linker.ld
LINKER_FILE = linker.$(TARGETL).ld
ISO_DIR=$(BUILD_DIR)/iso_root
IMAGE_TARGET=$(BUILD_DIR)/image.iso

TARGET ?= AMD64

# This sucks.
TARGETL=$(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(TARGET)))))))))))))))))))))))))))

# This is the name that our final kernel executable will have.
# Change as needed.
override KERNEL := $(BUILD_DIR)/kernel.$(TARGETL).elf
Expand Down Expand Up @@ -74,60 +75,42 @@ else
DEFINES += -O3
endif

# It is highly recommended to use a custom built cross toolchain to build a kernel.
# We are only using "cc" as a placeholder here. It may work by using
# the host system's toolchain, but this is not guaranteed.
$(eval $(call DEFAULT_VAR,CC,cc))
$(eval $(call DEFAULT_VAR,CXX,c++))
IS_KERNEL = yes
include ../tools/toolchain.mk

# Same thing for "ld" (the linker).
$(eval $(call DEFAULT_VAR,LD,ld))
ifeq ($(SMP), yes)
ARCH_CFLAGS += -DCONFIG_SMP
endif

# User controllable CFLAGS.
CFLAGS ?= -pipe -Wall -Wextra -DTARGET_$(TARGET) -DKERNEL -DIS_KERNEL_MODE $(DEFINES)
CFLAGS ?= -pipe -Wall -Wextra -DTARGET_$(TARGET) -DBORON_TARGET=\"$(TARGETL)\" -DKERNEL -DIS_KERNEL_MODE $(DEFINES)

# User controllable CXXFLAGS.
CXXFLAGS ?= -pipe -Wall -Wextra -DTARGET_$(TARGET) -DKERNEL -DIS_KERNEL_MODE $(DEFINES)
CXXFLAGS ?= -pipe -Wall -Wextra -DTARGET_$(TARGET) -DBORON_TARGET=\"$(TARGETL)\" -DKERNEL -DIS_KERNEL_MODE $(DEFINES)

# User controllable preprocessor flags.
CPPFLAGS ?= -I $(INC_DIR) -I $(DDKI_DIR)
CPPFLAGS ?= -I $(INC_DIR) -I $(DDK_DIR)

# User controllable nasm flags.
NASMFLAGS ?= -F dwarf -I$(SRC_DIR) -I$(INC_DIR) -I$(DDKI_DIR)
NASMFLAGS ?= -F dwarf -I$(SRC_DIR) -I$(INC_DIR) -I$(DDK_DIR)

# User controllable linker flags. We set none by default.
LDFLAGS ?=

# Internal C flags that should not be changed by the user.
#
# NOTE 7.7.2024 -- No-reorder-functions was added because a certain functions
# was generating an "unlikely" section, which was placed at different addresses
# in kernel.elf and kernel2.elf, screwing up the symbol table... That's pretty
# bad.
#
# TODO: fix above ^^^
CFLAGS += \
-fno-omit-frame-pointer \
-std=c11 \
-std=c2x \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-lto \
-fno-pie \
-fno-pic \
-fno-reorder-functions \
-m64 \
-march=x86-64 \
-mabi=sysv \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-mno-red-zone \
-mcmodel=kernel \
-MMD \
-MP \
-I.
-I. \
$(ARCH_CFLAGS)

# Internal C++ flags that should not be changed by the user.
CXXFLAGS += \
Expand All @@ -140,25 +123,17 @@ CXXFLAGS += \
-fno-pie \
-fno-pic \
-fno-reorder-functions \
-m64 \
-march=x86-64 \
-mabi=sysv \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-mno-red-zone \
-mcmodel=kernel \
-MMD \
-MP \
-fno-exceptions \
-fno-rtti \
-I.
-I. \
$(ARCH_CFLAGS)

LDFLAGSBASE += \
-nostdlib \
-m elf_x86_64 \
-z max-page-size=0x1000
-m $(LINK_ARCH) \
$(ARCH_LDFLAGS)

# Internal linker flags that should not be changed by the user.
LDFLAGS += \
Expand All @@ -171,15 +146,15 @@ ifeq ($(shell $(LD) --help 2>&1 | grep 'no-pie' >/dev/null 2>&1; echo $$?),0)
endif

# Internal nasm flags that should not be changed by the user.
NASMFLAGS += \
-f elf64
NASMFLAGS += $(ARCH_ASFLAGS)

# Use find to glob all *.c, *.S, and *.asm files in the directory and extract the object names.
override CFILES := $(shell find $(SRC_DIR) -not -path '*/.*' -type f -name '*.c')
override CXXFILES := $(shell find $(SRC_DIR) -not -path '*/.*' -type f -name '*.cpp')
override ASFILES := $(shell find $(SRC_DIR) -not -path '*/.*' -type f -name '*.S')
override NASMFILES := $(shell find $(SRC_DIR) -not -path '*/.*' -type f -name '*.asm')
override OBJ := $(patsubst %.o,%.$(TARGETL).o,$(patsubst $(SRC_DIR)/%,$(BUILD_DIR)/%,$(CFILES:.c=.o) $(CXXFILES:.cpp=.o) $(ASFILES:.S=.o) $(NASMFILES:.asm=.o)))
EXCLUDE_WRONG_ARCH = '(' '(' -path 'source/ke/$(TARGETL)/*' ')' -o '(' -path 'source/mm/$(TARGETL)/*' ')' -o '(' -not -path 'source/ke/*/*' -not -path 'source/mm/*/*' ')' ')'
override CFILES := $(shell find $(SRC_DIR) -not -path '*/.*' $(EXCLUDE_WRONG_ARCH) -type f -name '*.c')
override CXXFILES := $(shell find $(SRC_DIR) -not -path '*/.*' $(EXCLUDE_WRONG_ARCH) -type f -name '*.cpp')
override ASFILES := $(shell find $(SRC_DIR) -not -path '*/.*' $(EXCLUDE_WRONG_ARCH) -type f -name '*.S')
override NASMFILES := $(shell find $(SRC_DIR) -not -path '*/.*' $(EXCLUDE_WRONG_ARCH) -type f -name '*.asm')
override OBJ := $(patsubst %.o,%.$(TARGETL).o,$(patsubst $(SRC_DIR)/%,$(BUILD_DIR)/%,$(CFILES:.c=.o) $(CXXFILES:.cpp=.o) $(ASFILES:.S=.o) $(NASMFILES:.asm=.o)))
override HEADER_DEPS := $(patsubst %.o,%.d,$(OBJ))

# It's kind of a mess, but basically, here's what everything does:
Expand All @@ -202,26 +177,26 @@ CFLAGS += -D__BORON_MAJOR=$(VER_MAJOR) -D__BORON_MINOR=$(VER_MINOR) -D__BORON_BU
# Link rules for the final kernel executable.
$(KERNEL): $(SYMBOLS)
@echo "[LD]\tBuilding $(KERNEL)"
@$(LD) $(OBJ) $(SYMBOLS) $(LDFLAGS) -o $@
@$(BLD) $(OBJ) $(SYMBOLS) $(LDFLAGS) -o $@

$(SYMBOLS): $(KERNEL2)
@echo "[NM]\tDumping and compiling symbols"
@nm -P $(KERNEL2) | $(SCRIPTS_DIR)/generate_symbols.py > $(BUILD_DIR)/_symtab.$(TARGETL).asm
@nasm $(NASMFLAGS) $(BUILD_DIR)/_symtab.$(TARGETL).asm -o $(BUILD_DIR)/_symtab.$(TARGETL).o
@nm -P $(KERNEL2) | $(SCRIPTS_DIR)/generate_symbols.py $(TARGETL) > $(BUILD_DIR)/_symtab.$(TARGETL).asm
@$(BASM) $(NASMFLAGS) $(BUILD_DIR)/_symtab.$(TARGETL).asm -o $(BUILD_DIR)/_symtab.$(TARGETL).o

$(KERNEL2): $(KERNEL_PARTIAL)
@echo "[LD]\tLinking kernel to extract symbols"
@$(LD) $(KERNEL_PARTIAL) -static $(LDFLAGS) -o $@
@$(BLD) $(KERNEL_PARTIAL) -static $(LDFLAGS) -o $@

# Link rules for the amalgam object file.
$(KERNEL_PARTIAL): $(OBJ) $(LINKER_FILE)
@echo "[LD]\tPartially linking kernel"
@$(LD) -r $(OBJ) $(LDFLAGSBASE) -o $@
@$(BLD) -m $(LINK_ARCH) -r $(OBJ) $(LDFLAGSBASE) -o $@

$(BUILD_DIR)/ke/version.$(TARGETL).o: $(filter-out $(BUILD_DIR)/ke/version.$(TARGETL).o, $(OBJ)) $(SRC_DIR)/ke/version.c
@echo "[CC]\tCompiling $(SRC_DIR)/ke/version.c"
@mkdir -p $(dir $@)
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $(SRC_DIR)/ke/version.c -o $@
@$(BCC) $(CPPFLAGS) $(CFLAGS) -c $(SRC_DIR)/ke/version.c -o $@
@echo "[MK]\tIncrementing build number"
@echo $$(($(VER_BUILD) + 1)) > $(BUILD_NUMBER_FILE)

Expand All @@ -232,25 +207,25 @@ $(BUILD_DIR)/ke/version.$(TARGETL).o: $(filter-out $(BUILD_DIR)/ke/version.$(TAR
$(BUILD_DIR)/%.$(TARGETL).o: $(SRC_DIR)/%.c
@echo "[CC]\tCompiling $<"
@mkdir -p $(dir $@)
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
@$(BCC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

# Compilation rules for *.cpp files.
$(BUILD_DIR)/%.$(TARGETL).o: $(SRC_DIR)/%.cpp
@echo "[CXX]\tCompiling $<"
@mkdir -p $(dir $@)
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
@$(BCXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

# Compilation rules for *.S files.
$(BUILD_DIR)/%.$(TARGETL).o: $(SRC_DIR)/%.S
@echo "[AS]\tCompiling $<"
@mkdir -p $(dir $@)
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
@$(BCC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

# Compilation rules for *.asm (nasm) files.
$(BUILD_DIR)/%.$(TARGETL).o: $(SRC_DIR)/%.asm
@echo "[AS]\tCompiling $<"
@mkdir -p $(dir $@)
@nasm $(NASMFLAGS) $< -o $@
@$(BASM) $(NASMFLAGS) $< -o $@

# Remove object files and the final executable.
.PHONY: clean
Expand Down
10 changes: 4 additions & 6 deletions boron/address_space.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ BORON Operating System Address Space (AMD64)
| higher half direct map |
+------------------------------+ - 0xFFFF800000000000

NOTE: file system caching will be implemented in the future

** User Mode **

Currently this is nothing more than a plan.
Expand All @@ -39,13 +37,13 @@ However, this is the plan for normal user processes.

+-----------------------------+ - 0x0000800000000000
| process environment block |
+-----------------------------+ - 0x00007ffffffff000
+-----------------------------+ - 0x00007FFFFFFFE000
| operating system DLLs |
+-----------------------------+ - 0x00007fff00000000
+-----------------------------+ - 0x00007FFF00000000
| thread environment blocks |
+-----------------------------+ - 0x00007ffe00000000
+-----------------------------+ - 0x00007FFE00000000
| thread stacks |
+-----------------------------+ - 0x00007e0000000000
+-----------------------------+ - 0x00007E0000000000
| user mappings |
+-----------------------------+ - 0x0000500000000000
| user heap |
Expand Down
60 changes: 60 additions & 0 deletions boron/address_space_i386.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
BORON Operating System Address Space (i386)

** Kernel Mode **

+------------------------------+ - 0xFFFFFFFF
| virtually linear page tables |
+------------------------------+ - 0xFFC00000
| unused |
+------------------------------+ - 0xF0000000
| more dynamic pool space |
+------------------------------+ - 0xE0000000
| unused |
+------------------------------+ - 0xD8000000
| page frame data base |
+------------------------------+ - 0xD4000000
| system module DLLs |
+------------------------------+ - 0xD2000000
| unused |
+------------------------------+ - 0xD1800000
| pool header slab magazines |
+------------------------------+ - 0xD1000000
| fast mapping in 16MB windows |
+------------------------------+ - 0xD0000000
| map of first 256 MB of phys |
| kernel code & data |
+------------------------------+ - 0xC0000000
| dynamic pool space |
+------------------------------+ - 0x80000000
| higher half direct map |
+------------------------------+ - 0x00000000

Notes:
- if we use the multiboot boot protocol, then "kernel code & data" really means "first 8MB of physical memory"

** User Mode **

Currently this is nothing more than a plan.
Now, a user process has complete control over its own
address space. (They will even be able to unmap the
PEB/TEBs if they want as well!)

However, this is the plan for normal user processes.

+-----------------------------+ - 0x80000000
| process environment block |
+-----------------------------+ - 0x7ffe0000
| thread environment blocks |
+-----------------------------+ - 0x7fe00000
| operating system DLLs |
+-----------------------------+ - 0x78000000
| thread stacks |
+-----------------------------+ - 0x70000000
| user DLLs |
+-----------------------------+ - 0x60000000
| user heap + mappings |
+-----------------------------+ - 0x10000000
| program executable |
+-----------------------------+ - 0x00001000
| |
+-----------------------------+ - 0x00000000
6 changes: 4 additions & 2 deletions boron/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
#include <main.h>

// ==== Platform specific defintions ====
#ifdef TARGET_AMD64
#if defined TARGET_AMD64
#include <arch/amd64.h>
#elif defined TARGET_I386
#include <arch/i386.h>
#endif

// ==== Forward declarations. Depending on the platform, we'll include platform specific definitions. ====
typedef struct KREGISTERS_tag KREGISTERS, *PKREGISTERS; // List of registers.

// Functions that do different things based on architecture,
// but exist everywhere
#ifdef TARGET_AMD64
#if defined TARGET_AMD64 || defined TARGET_I386

FORCE_INLINE
void KeWaitForNextInterrupt(void)
Expand Down
Loading