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
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ CFLAGS = -Wall -Wextra -Werror -std=c11 -ffreestanding -fno-stack-protector \
-isystem ./external/limine -isystem ./external/CherryUSB/common -isystem ./external/CherryUSB/core -isystem ./external/CherryUSB/class/msc -isystem ./external/CherryUSB/class/hid -isystem ./external/CherryUSB/class/hub \
-include kernel/usb_config.h -DKERNEL_MODE -Wno-unused-function
LDFLAGS = -nostdlib -static -m elf_x86_64 -z max-page-size=0x1000 -T kernel/linker.ld
KERNEL_OBJS = kernel/entry.o kernel/kernel.o src/app_ui.o src/chell.o src/lab.o src/installer.o \
KERNEL_OBJS = kernel/entry.o kernel/kernel.o src/app_ui.o \
kernel/nuklear_kernel_impl.o kernel/stb_image_impl.o \
src/nuklear_impl.o kernel/syscall.o kernel/sys_shell.o \
src/nuklear_impl.o src/nk_software_renderer.o kernel/syscall.o kernel/sys_shell.o \
kernel/crash_notify.o \
kernel/usb_osal.o kernel/usb_hal_ports.o kernel/storage.o kernel/input.o \
kernel/app_loader.o kernel/usb_hal.o kernel/vfs.o kernel/scheduler.o \
kernel/serial.o kernel/i18n.o kernel/uac_policy.o kernel/tgx_impl.o \
kernel/tlsf_impl.o kernel/math.o kernel/panic.o \
kernel/gdt.o kernel/interrupts.o kernel/isr_stubs.o \
kernel/gdt.o kernel/msr.o kernel/interrupts.o kernel/isr_stubs.o \
kernel/apic.o kernel/pmm.o kernel/comprec.o kernel/cm.o \
kernel/malloc_glue.o kernel/vga_log.o kernel/storage_hal.o src/main.o kernel/panic_hal.o \
kernel/diskio_impl.o kernel/ffsystem_impl.o \
kernel/fatfs/ff.o kernel/fatfs/ffunicode.o \
kernel/drivers/pci.o kernel/drivers/xhci.o kernel/drivers/ehci.o \
kernel/drivers/virtio_net.o kernel/drivers/virtio_net_linux.o \
kernel/linux_compat.o kernel/linux_irq.o kernel/linux_pci_compat.o \
src/app_studio.o kernel/drivers/nvme.o kernel/drivers/ahci.o kernel/drivers/ramdisk.o \
kernel/drivers/nvme.o kernel/drivers/ahci.o kernel/drivers/ramdisk.o \
kernel/drivers/ps2.o kernel/drivers/rtc.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 run
all: environment kernel/kernel iso
all: environment userland kernel/kernel iso
environment:
chmod +x build.sh
./build.sh
Expand Down Expand Up @@ -60,5 +61,9 @@ iso: kernel/kernel
./external/limine/limine bios-install os.iso
run: all
qemu-system-x86_64 -m 512M -cdrom os.iso -boot d -device qemu-xhci -device usb-kbd -device usb-mouse -serial stdio
userland:
make -C apps all

clean:
rm -rf $(KERNEL_OBJS) kernel/kernel kernel/ramdisk.img os.iso iso_root/
make -C apps clean
8 changes: 8 additions & 0 deletions apps/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SUBDIRS = shell lab studio notepad

all:
for dir in $(SUBDIRS); do $(MAKE) -C $$dir all; done

clean:
for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean; done
rm -f lib/*.o
24 changes: 24 additions & 0 deletions apps/app.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CC = gcc
LD = ld
LIB_DIR = ../lib
CFLAGS = -Wall -Wextra -Werror -std=c11 -ffreestanding -fno-stack-protector -fno-stack-check -fno-lto -fno-pic -m64 -march=x86-64 -I../../include -I../../kernel -I$(LIB_DIR)
LDFLAGS = -nostdlib -static -m elf_x86_64 -T $(LIB_DIR)/app.ld

OBJS = app.o $(LIB_DIR)/crt0.o $(LIB_DIR)/user_rsl.o

all: app.bin

app.bin: $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o app.bin

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

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

$(LIB_DIR)/%.o: $(LIB_DIR)/%.s
$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@

clean:
rm -f *.o app.bin
24 changes: 24 additions & 0 deletions apps/lab/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CC = gcc
LD = ld
LIB_DIR = ../lib
CFLAGS = -Wall -Wextra -Werror -std=c11 -ffreestanding -fno-stack-protector -fno-stack-check -fno-lto -fno-pic -m64 -march=x86-64 -I../../include -I../../kernel -I$(LIB_DIR)
LDFLAGS = -nostdlib -static -m elf_x86_64 -T $(LIB_DIR)/app.ld

OBJS = app.o $(LIB_DIR)/crt0.o $(LIB_DIR)/user_rsl.o

all: app.bin

app.bin: $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o app.bin

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

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

$(LIB_DIR)/%.o: $(LIB_DIR)/%.s
$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@

clean:
rm -f *.o app.bin
Binary file added apps/lab/app.bin
Binary file not shown.
6 changes: 6 additions & 0 deletions apps/lab/app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "user_rsl.h"

int main() {
rsl_printf("Diagnostics active.\n");
return 0;
}
23 changes: 23 additions & 0 deletions apps/lib/app.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ENTRY(_start)

SECTIONS
{
. = 0x400000;

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

.rodata : {
*(.rodata*)
}

.data : {
*(.data*)
}

.bss : {
*(.bss*)
}
}
9 changes: 9 additions & 0 deletions apps/lib/crt0.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.section .text.prologue
.global _start
_start:
call main
movq %rax, %rdi
/* Exit syscall */
movq $0x0E, %rax /* SYS_EXIT */
syscall
hlt
17 changes: 17 additions & 0 deletions apps/lib/user_rsl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "user_rsl.h"
#include <stdarg.h>
#include <stdio.h>

/* Very minimal vsnprintf for userland apps if we don't link with kernel implementation */
/* For now, just a dummy or we can try to reuse the kernel headers if we're careful. */
/* Userland shouldn't ideally include kernel headers. */

void rsl_printf(const char* fmt, ...) {
/* For simplicity in this demo, just send the raw string to serial */
/* Real implementation would use vsnprintf */
syscall(SYS_SERIAL_WRITE, fmt, NULL, 0);
}

int rsl_ls(const char* path, char* out, size_t sz) {
return (int)syscall(SYS_VFS_LS, path, out, sz);
}
36 changes: 36 additions & 0 deletions apps/lib/user_rsl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef USER_RSL_H
#define USER_RSL_H

#include <stddef.h>
#include <stdint.h>

/* These should match include/syscall_nums.h */
#define SYS_VFS_LS 1
#define SYS_VFS_CAT 2
#define SYS_VFS_MKDIR 3
#define SYS_VFS_WRITE 4
#define SYS_VFS_MOUNTS 5
#define SYS_DEVMGR_LIST 6
#define SYS_MALLOC 7
#define SYS_FREE 8
#define SYS_GET_UPTIME 9
#define SYS_I18N_TRANSLATE 10
#define SYS_VFS_READ 11
#define SYS_EXIT 12
#define SYS_SERIAL_WRITE 13

static inline long syscall(long num, const void* a1, void* a2, size_t a3) {
long ret;
__asm__ volatile (
"syscall"
: "=a"(ret)
: "a"(num), "D"(a1), "S"(a2), "d"(a3)
: "rcx", "r11", "memory"
);
return ret;
}

void rsl_printf(const char* fmt, ...);
int rsl_ls(const char* path, char* out, size_t sz);

#endif
24 changes: 24 additions & 0 deletions apps/notepad/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CC = gcc
LD = ld
LIB_DIR = ../lib
CFLAGS = -Wall -Wextra -Werror -std=c11 -ffreestanding -fno-stack-protector -fno-stack-check -fno-lto -fno-pic -m64 -march=x86-64 -I../../include -I../../kernel -I$(LIB_DIR)
LDFLAGS = -nostdlib -static -m elf_x86_64 -T $(LIB_DIR)/app.ld

OBJS = app.o $(LIB_DIR)/crt0.o $(LIB_DIR)/user_rsl.o

all: app.bin

app.bin: $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o app.bin

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

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

$(LIB_DIR)/%.o: $(LIB_DIR)/%.s
$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@

clean:
rm -f *.o app.bin
Binary file added apps/notepad/app.bin
Binary file not shown.
6 changes: 6 additions & 0 deletions apps/notepad/app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "user_rsl.h"

int main() {
rsl_printf("Notepad active.\n");
return 0;
}
24 changes: 24 additions & 0 deletions apps/shell/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CC = gcc
LD = ld
LIB_DIR = ../lib
CFLAGS = -Wall -Wextra -Werror -std=c11 -ffreestanding -fno-stack-protector -fno-stack-check -fno-lto -fno-pic -m64 -march=x86-64 -I../../include -I../../kernel -I$(LIB_DIR)
LDFLAGS = -nostdlib -static -m elf_x86_64 -T $(LIB_DIR)/app.ld

OBJS = app.o $(LIB_DIR)/crt0.o $(LIB_DIR)/user_rsl.o

all: app.bin

app.bin: $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o app.bin

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

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

$(LIB_DIR)/%.o: $(LIB_DIR)/%.s
$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@

clean:
rm -f *.o app.bin
Binary file added apps/shell/app.bin
Binary file not shown.
6 changes: 6 additions & 0 deletions apps/shell/app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "user_rsl.h"

int main() {
rsl_printf("Userland Shell Ready.\n");
return 0;
}
24 changes: 24 additions & 0 deletions apps/studio/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CC = gcc
LD = ld
LIB_DIR = ../lib
CFLAGS = -Wall -Wextra -Werror -std=c11 -ffreestanding -fno-stack-protector -fno-stack-check -fno-lto -fno-pic -m64 -march=x86-64 -I../../include -I../../kernel -I$(LIB_DIR)
LDFLAGS = -nostdlib -static -m elf_x86_64 -T $(LIB_DIR)/app.ld

OBJS = app.o $(LIB_DIR)/crt0.o $(LIB_DIR)/user_rsl.o

all: app.bin

app.bin: $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o app.bin

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

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

$(LIB_DIR)/%.o: $(LIB_DIR)/%.s
$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@

clean:
rm -f *.o app.bin
Binary file added apps/studio/app.bin
Binary file not shown.
6 changes: 6 additions & 0 deletions apps/studio/app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "user_rsl.h"

int main() {
rsl_printf("Studio active.\n");
return 0;
}
Loading