Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
109 changes: 69 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,88 @@ LD = ld

CFLAGS = -Wall -Wextra -std=c11 -ffreestanding -fno-stack-protector \
-fno-stack-check -fno-lto -fno-pic -m64 -march=x86-64 -mcmodel=kernel \
-mno-red-zone -fno-asynchronous-unwind-tables \
-I./include -I./kernel -I./kernel/drivers \
-I./external/limine \
-I./external/CherryUSB/common \
-I./external/CherryUSB/core \
-I./external/CherryUSB/class/msc \
-I./external/CherryUSB/class/hid \
-I./external/CherryUSB/class/hub \
-include kernel/usb_config.h -DKERNEL_MODE

LDFLAGS = -nostdlib -static -m elf_x86_64 -z max-page-size=0x1000 -T kernel/linker.ld

# All Source Objects
KERNEL_OBJS = kernel/kernel.o src/app_ui.o kernel/nuklear_kernel_impl.o \
src/nk_software_renderer.o kernel/usb_osal.o \
kernel/usb_hal_ports.o kernel/storage.o kernel/input.o \
kernel/usb_hal.o kernel/vfs.o kernel/scheduler.o \
kernel/i18n.o kernel/uac_policy.o kernel/tgx_impl.o \
kernel/tlsf_impl.o kernel/math.o kernel/panic.o \
kernel/malloc_glue.o kernel/storage_hal.o kernel/panic_hal.o \
kernel/drivers/pci.o kernel/drivers/xhci.o kernel/drivers/ehci.o \
kernel/drivers/nvme.o kernel/drivers/ahci.o \
external/CherryUSB/core/usbd_core.o \
external/CherryUSB/core/usbh_core.o \
external/CherryUSB/class/msc/usbh_msc.o \
external/CherryUSB/class/hid/usbh_hid.o \
external/CherryUSB/class/hub/usbh_hub.o \
external/CherryUSB/port/ehci/usb_hc_ehci.o

.PHONY: all clean environment iso

all: environment kernel/kernel iso

environment:
chmod +x build.sh
./build.sh
make -C external/limine limine

kernel/kernel: $(KERNEL_OBJS)
$(LD) $(LDFLAGS) $(KERNEL_OBJS) -o kernel/kernel
-I./external/CherryUSB/core/host \
-I./kernel/fatfs \
-I./external/TLSF \
-I./external/lwip/src/include \
-I./external/wolfssl \
-I./include \
-I./include/external \
-DFS_FATFS_WINDOW_ALIGNMENT=4 \
-DLWIP_NO_CTYPE_H=1 \
-DWOLFSSL_USER_SETTINGS

LDFLAGS = -nostdlib -static -m elf_x86_64 -z max-page-size=0x1000 -T boot/linker.ld

KERNEL_OBJS = kernel/unice64/limine_reqs.o \
kernel/unice64/main.o \
kernel/libs/services.o \
kernel/libs/vga_serial.o \
kernel/libs/arc_mem.o \
kernel/libs/bump_alloc.o \
kernel/libs/vdisk.o \
kernel/libs/usb_xhci.o \
kernel/libs/ahci.o \
kernel/libs/vfs.o \
kernel/libs/rsl_string.o \
kernel/libs/console.o \
kernel/libs/rsl_commands.o \
kernel/libs/panic.o \
kernel/libs/libc.o \
kernel/libs/typography.o \
kernel/libs/math_core.o \
kernel/libs/gdt.o \
kernel/libs/paging.o \
kernel/libs/syscall.o \
kernel/libs/syscall_entry.o \
kernel/libs/lwip_hal.o \
kernel/fatfs/ff.o \
kernel/fatfs/ffunicode.o \
external/TLSF/tlsf.o \
external/lwip/src/core/init.o \
external/lwip/src/core/mem.o \
external/lwip/src/core/memp.o \
external/lwip/src/core/netif.o \
external/lwip/src/core/pbuf.o \
external/lwip/src/core/ip.o \
external/lwip/src/core/ipv4/ip4.o \
external/lwip/src/core/ipv4/ip4_addr.o \
external/wolfssl/wolfcrypt/src/wc_port.o \
external/wolfssl/wolfcrypt/src/logging.o \
external/wolfssl/wolfcrypt/src/memory.o \
external/wolfssl/wolfcrypt/src/error.o

.PHONY: all clean environment iso run

all: kernel.elf

kernel.elf: $(KERNEL_OBJS)
$(LD) $(LDFLAGS) $(KERNEL_OBJS) -o kernel.elf

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

iso: kernel/kernel
%.o: %.S
$(CC) $(CFLAGS) -c $< -o $@

iso: kernel.elf
mkdir -p iso_root/boot/sys
cp kernel/kernel iso_root/boot/sys/kernel.elf
cp kernel.elf iso_root/boot/sys/kernel.elf
echo "/R-TECH OS" > iso_root/boot/limine.conf
echo "PROTOCOL=limine" >> iso_root/boot/limine.conf
echo "KERNEL_PATH=boot:///boot/sys/kernel.elf" >> iso_root/boot/limine.conf
echo "COMMENT=Entering the Bare-Metal Estate." >> iso_root/boot/limine.conf
cp external/limine/limine-bios.sys iso_root/boot/
cp external/limine/limine-bios-cd.bin iso_root/boot/
xorriso -as mkisofs -b boot/limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot boot/limine-bios-cd.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
iso_root -o os.iso
./external/limine/limine bios-install os.iso

clean:
rm -rf $(KERNEL_OBJS) kernel/kernel os.iso iso_root/boot/sys/kernel.elf
rm -f $(KERNEL_OBJS) kernel.elf os.iso
40 changes: 40 additions & 0 deletions boot/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(_start)

PHDRS
{
text PT_LOAD FLAGS(5); /* RX */
rodata PT_LOAD FLAGS(4); /* R */
data PT_LOAD FLAGS(6); /* RW */
}

SECTIONS
{
. = 0xffffffff80000000;

.text : {
*(.text .text.*)
} :text

. = ALIGN(0x1000);

.rodata : {
*(.rodata .rodata.*)
} :rodata

. = ALIGN(0x1000);

.data : {
*(.data .data.*)
} :data

.bss : {
*(.bss .bss.*)
*(COMMON)
} :data

/DISCARD/ : {
*(.eh_frame)
*(.note .note.*)
}
}
61 changes: 51 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
#!/bin/bash
set -e

echo "=== Baking Real Bare-Metal Environment ==="
echo "=== Baking Real Bare-Metal Environment (RTECH OSx2) ==="

mkdir -p external
mkdir -p include/external
mkdir -p iso_root/boot/sys

# 1. Get the Real Limine Binaries (Hardened acquisition)
# 1. Get the Real Limine Binaries
if [ ! -d "external/limine" ]; then
echo "[1/2] Fetching Static Limine Assets..."
git clone https://github.com/limine-bootloader/limine.git external/limine --branch=v8.x-binary --depth=1
echo "Building Limine deployment tool..."
make -C external/limine limine
echo "[1/8] Fetching Static Limine Assets..."
git clone https://github.com/limine-bootloader/limine.git external/limine --branch=v5.x-branch-binary --depth=1
make -C external/limine
fi
cp external/limine/limine.h include/

# 2. Fetch the Real CherryUSB Source Tree
# 2. Fetch the Real CherryUSB Stack
if [ ! -d "external/CherryUSB" ]; then
echo "[2/2] Fetching Genuine CherryUSB Stack..."
echo "[2/8] Fetching Genuine CherryUSB Stack..."
git clone https://github.com/cherry-embedded/CherryUSB.git external/CherryUSB --depth=1
# Remove .git to ensure tracking by parent repo if needed,
# but the directive was "include real source files".
rm -rf external/CherryUSB/.git
fi

# 3. Fetch stb_sprintf.h
if [ ! -f "include/external/stb_sprintf.h" ]; then
echo "[3/8] Fetching stb_sprintf..."
curl -Lo include/external/stb_sprintf.h https://raw.githubusercontent.com/nothings/stb/master/stb_sprintf.h
fi

# 4. Fetch FatFs (Using stm32duino mirror)
echo "[4/8] Fetching FatFs..."
rm -rf external/FatFs
git clone https://github.com/stm32duino/FatFs.git external/FatFs --depth=1
mkdir -p external/FatFs/include
cp external/FatFs/src/*.h external/FatFs/include/

# 5. Fetch Nuklear
if [ ! -f "include/nuklear.h" ]; then
echo "[5/8] Fetching Nuklear..."
curl -Lo include/nuklear.h https://raw.githubusercontent.com/Immediate-Mode-UI/Nuklear/master/nuklear.h
fi

# 6. Fetch TLSF
if [ ! -d "external/TLSF" ]; then
echo "[6/8] Fetching TLSF..."
git clone https://github.com/mattconte/tlsf.git external/TLSF --depth=1
fi

# 7. Fetch lwIP
if [ ! -d "external/lwip" ]; then
echo "[7/8] Fetching lwIP..."
git clone --depth 1 https://git.savannah.gnu.org/git/lwip.git external/lwip
fi

# 8. Fetch wolfSSL
if [ ! -d "external/wolfssl" ]; then
echo "[8/8] Fetching wolfSSL..."
git clone --depth 1 https://github.com/wolfSSL/wolfssl.git external/wolfssl
fi

# Fetch stb_truetype
if [ ! -f "include/external/stb_truetype.h" ]; then
curl -Lo include/external/stb_truetype.h https://raw.githubusercontent.com/nothings/stb/master/stb_truetype.h
fi

echo "Environment Armed. Ready for 'make'."
27 changes: 27 additions & 0 deletions include/arch/cc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef LWIP_ARCH_CC_H
#define LWIP_ARCH_CC_H

#include <stdint.h>
#include <pro_os.h>

#define LWIP_PLATFORM_DIAG(x) do { } while(0)
#define LWIP_PLATFORM_ASSERT(x) do { } while(0)

#define BYTE_ORDER LITTLE_ENDIAN

typedef uint8_t u8_t;
typedef int8_t s8_t;
typedef uint16_t u16_t;
typedef int16_t s16_t;
typedef uint32_t u32_t;
typedef int32_t s32_t;
typedef uintptr_t mem_ptr_t;

#define U16_F "hu"
#define S16_F "hd"
#define X16_F "hx"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"

#endif
Loading