mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 10:26:59 +00:00
Kernel V3.0.0
This commit is contained in:
30
src/kernel/userland/Makefile
Normal file
30
src/kernel/userland/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
CC = x86_64-elf-gcc
|
||||
AS = nasm
|
||||
LD = x86_64-elf-ld
|
||||
|
||||
CFLAGS = -Wall -Wextra -std=gnu11 -ffreestanding -O2 -fno-stack-protector -fno-stack-check -fno-lto -fno-pie -m64 -march=x86-64 -mno-80387 -mno-mmx -mno-sse -mno-sse2 -mno-red-zone -Ilibc
|
||||
LDFLAGS = -m elf_x86_64 -nostdlib -static -no-pie -Ttext=0x40000000 --no-dynamic-linker -z text -z max-page-size=0x1000 -e _start
|
||||
|
||||
LIBC_SOURCES = $(wildcard libc/*.c)
|
||||
LIBC_OBJS = $(LIBC_SOURCES:.c=.o) crt0.o
|
||||
|
||||
APP_SOURCES = $(wildcard *.c)
|
||||
APP_OBJS = $(APP_SOURCES:.c=.o)
|
||||
APP_ELFS = $(APP_SOURCES:.c=.elf)
|
||||
|
||||
all: $(APP_ELFS)
|
||||
|
||||
crt0.o: crt0.asm
|
||||
$(AS) -f elf64 $< -o $@
|
||||
|
||||
libc/%.o: libc/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.elf: $(LIBC_OBJS) %.o
|
||||
$(LD) $(LDFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o libc/*.o *.elf
|
||||
264
src/kernel/userland/calculator.c
Normal file
264
src/kernel/userland/calculator.c
Normal file
@@ -0,0 +1,264 @@
|
||||
#include "syscall.h"
|
||||
#include "libui.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SCALE 1000000LL
|
||||
|
||||
// Dark Mode Colors mapping to libui
|
||||
#define COLOR_DARK_BG 0xFF1E1E1E
|
||||
#define COLOR_DARK_PANEL 0xFF2D2D2D
|
||||
#define COLOR_DARK_TEXT 0xFFF0F0F0
|
||||
#define COLOR_DARK_BORDER 0xFF3A3A3A
|
||||
|
||||
static ui_window_t win_calculator;
|
||||
|
||||
static long long calc_acc = 0;
|
||||
static long long calc_curr = 0;
|
||||
static char calc_op = 0;
|
||||
static bool calc_new_entry = true;
|
||||
static bool calc_error = false;
|
||||
static bool calc_decimal_mode = false;
|
||||
static long long calc_decimal_divisor = 10;
|
||||
static char display_buffer[1024];
|
||||
static int display_buf_len = 0;
|
||||
|
||||
static long long isqrt(long long n) {
|
||||
if (n < 0) return -1;
|
||||
if (n == 0) return 0;
|
||||
long long x = n;
|
||||
long long y = 1;
|
||||
while (x > y) {
|
||||
x = (x + y) / 2;
|
||||
y = n / x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static void fixed_to_str(long long n, char *buf) {
|
||||
if (n == 0) {
|
||||
buf[0] = '0'; buf[1] = 0; return;
|
||||
}
|
||||
char temp[64];
|
||||
int pos = 0;
|
||||
bool neg = n < 0;
|
||||
if (neg) n = -n;
|
||||
long long int_part = n / SCALE;
|
||||
long long frac_part = n % SCALE;
|
||||
|
||||
char frac_buf[16];
|
||||
int f_idx = 0;
|
||||
for(int k=0; k<6; k++) {
|
||||
long long div = 100000;
|
||||
for(int m=0; m<k; m++) div /= 10;
|
||||
frac_buf[f_idx++] = '0' + ((frac_part / div) % 10);
|
||||
}
|
||||
frac_buf[f_idx] = 0;
|
||||
while (f_idx > 0 && frac_buf[f_idx-1] == '0') f_idx--;
|
||||
frac_buf[f_idx] = 0;
|
||||
if (f_idx > 0) {
|
||||
for (int i = f_idx - 1; i >= 0; i--) temp[pos++] = frac_buf[i];
|
||||
temp[pos++] = '.';
|
||||
}
|
||||
if (int_part == 0) {
|
||||
temp[pos++] = '0';
|
||||
} else {
|
||||
while (int_part > 0) {
|
||||
temp[pos++] = '0' + (int_part % 10);
|
||||
int_part /= 10;
|
||||
}
|
||||
}
|
||||
if (neg) temp[pos++] = '-';
|
||||
int j = 0;
|
||||
while (pos > 0) buf[j++] = temp[--pos];
|
||||
buf[j] = 0;
|
||||
}
|
||||
|
||||
static void update_display(void) {
|
||||
if (calc_error) {
|
||||
char *err = "Error";
|
||||
int i = 0; while(err[i]) { display_buffer[i] = err[i]; i++; }
|
||||
display_buffer[i] = 0;
|
||||
} else {
|
||||
fixed_to_str(calc_curr, display_buffer);
|
||||
}
|
||||
display_buf_len = 0; while(display_buffer[display_buf_len]) display_buf_len++;
|
||||
}
|
||||
|
||||
static void calculator_paint(void) {
|
||||
int w = 180;
|
||||
int h = 230;
|
||||
ui_draw_rect(win_calculator, 4, 30, w - 8, h - 34, COLOR_DARK_BG);
|
||||
ui_draw_rounded_rect_filled(win_calculator, 10, 36, w - 20, 25, 6, COLOR_DARK_PANEL);
|
||||
|
||||
int text_w = display_buf_len * 8;
|
||||
int text_x = w - 15 - text_w;
|
||||
ui_draw_string(win_calculator, text_x, 44, display_buffer, COLOR_DARK_TEXT);
|
||||
|
||||
const char *labels[] = {
|
||||
"C", "sqr", "rt", "/",
|
||||
"7", "8", "9", "*",
|
||||
"4", "5", "6", "-",
|
||||
"1", "2", "3", "+",
|
||||
"0", ".", "BS", "="
|
||||
};
|
||||
|
||||
int bw = 35;
|
||||
int bh = 25;
|
||||
int gap = 5;
|
||||
int start_x = 10;
|
||||
int start_y = 70;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
int r = i / 4;
|
||||
int c = i % 4;
|
||||
ui_draw_rounded_rect_filled(win_calculator, start_x + c*(bw+gap), start_y + r*(bh+gap), bw, bh, 4, COLOR_DARK_BORDER);
|
||||
int label_x = start_x + c*(bw+gap) + 5;
|
||||
int label_y = start_y + r*(bh+gap) + 9;
|
||||
ui_draw_string(win_calculator, label_x, label_y, labels[i], COLOR_DARK_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_op(void) {
|
||||
if (calc_op == '+') calc_acc += calc_curr;
|
||||
else if (calc_op == '-') calc_acc -= calc_curr;
|
||||
else if (calc_op == '*') {
|
||||
calc_acc = (calc_acc * calc_curr) / SCALE;
|
||||
}
|
||||
else if (calc_op == '/') {
|
||||
if (calc_curr == 0) calc_error = true;
|
||||
else calc_acc = (calc_acc * SCALE) / calc_curr;
|
||||
} else {
|
||||
calc_acc = calc_curr;
|
||||
}
|
||||
}
|
||||
|
||||
static void calculator_click(int x, int y) {
|
||||
int bw = 35;
|
||||
int bh = 25;
|
||||
int gap = 5;
|
||||
int start_x = 10;
|
||||
int start_y = 65; // Matches the hitboxes
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
int r = i / 4;
|
||||
int c = i % 4;
|
||||
int bx = start_x + c*(bw+gap);
|
||||
int by = start_y + r*(bh+gap);
|
||||
|
||||
if (x >= bx && x < bx + bw && y >= by && y < by + bh) {
|
||||
const char *labels[] = {
|
||||
"C", "s", "r", "/",
|
||||
"7", "8", "9", "*",
|
||||
"4", "5", "6", "-",
|
||||
"1", "2", "3", "+",
|
||||
"0", ".", "B", "="
|
||||
};
|
||||
char lbl = labels[i][0];
|
||||
|
||||
if (lbl >= '0' && lbl <= '9') {
|
||||
if (calc_new_entry || calc_error) {
|
||||
calc_curr = (lbl - '0') * SCALE;
|
||||
calc_new_entry = false;
|
||||
calc_decimal_mode = false;
|
||||
} else {
|
||||
if (calc_decimal_mode) {
|
||||
if (calc_decimal_divisor <= SCALE) {
|
||||
long long digit_val = ((long long)(lbl - '0') * SCALE) / calc_decimal_divisor;
|
||||
if (calc_curr >= 0) calc_curr += digit_val;
|
||||
else calc_curr -= digit_val;
|
||||
calc_decimal_divisor *= 10;
|
||||
}
|
||||
} else {
|
||||
if (calc_curr >= 0) calc_curr = calc_curr * 10 + (lbl - '0') * SCALE;
|
||||
else calc_curr = calc_curr * 10 - (lbl - '0') * SCALE;
|
||||
}
|
||||
}
|
||||
calc_error = false;
|
||||
} else if (lbl == '.') {
|
||||
if (calc_new_entry) {
|
||||
calc_curr = 0;
|
||||
calc_new_entry = false;
|
||||
}
|
||||
if (!calc_decimal_mode) {
|
||||
calc_decimal_mode = true;
|
||||
calc_decimal_divisor = 10;
|
||||
}
|
||||
} else if (lbl == 'C') {
|
||||
calc_curr = 0; calc_acc = 0; calc_op = 0;
|
||||
calc_new_entry = true; calc_error = false; calc_decimal_mode = false;
|
||||
} else if (lbl == 'B') {
|
||||
if (!calc_new_entry && !calc_error) {
|
||||
if (calc_decimal_mode) {
|
||||
if (calc_decimal_divisor > 10) {
|
||||
calc_decimal_divisor /= 10;
|
||||
long long unit = SCALE / calc_decimal_divisor;
|
||||
// This removes the last decimal digit
|
||||
calc_curr = (calc_curr / (unit * 10)) * (unit * 10);
|
||||
} else {
|
||||
// Backspace on the dot itself or first decimal
|
||||
calc_decimal_mode = false;
|
||||
calc_decimal_divisor = 10;
|
||||
// Ensure the fractional part is cleared
|
||||
calc_curr = (calc_curr / SCALE) * SCALE;
|
||||
}
|
||||
} else {
|
||||
// Integer backspace: remove last digit of integer part
|
||||
calc_curr = (calc_curr / SCALE / 10) * SCALE;
|
||||
}
|
||||
}
|
||||
} else if (lbl == 's') { // sqr
|
||||
calc_curr = (calc_curr * calc_curr) / SCALE; calc_new_entry = true;
|
||||
} else if (lbl == 'r') { // rt
|
||||
long long s = isqrt(calc_curr);
|
||||
if (s == -1) calc_error = true;
|
||||
else calc_curr = s * 1000;
|
||||
calc_new_entry = true;
|
||||
} else if (lbl == '=') {
|
||||
do_op();
|
||||
calc_curr = calc_acc; calc_op = 0; calc_new_entry = true; calc_decimal_mode = false;
|
||||
} else {
|
||||
if (!calc_new_entry) {
|
||||
if (calc_op) do_op();
|
||||
else calc_acc = calc_curr;
|
||||
}
|
||||
calc_op = lbl; calc_new_entry = true; calc_decimal_mode = false;
|
||||
}
|
||||
|
||||
update_display();
|
||||
calculator_paint();
|
||||
ui_mark_dirty(win_calculator, 0, 0, 180, 230);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
win_calculator = ui_window_create("Calculator", 200, 200, 180, 230);
|
||||
|
||||
calc_curr = 0;
|
||||
calc_acc = 0;
|
||||
calc_op = 0;
|
||||
calc_new_entry = true;
|
||||
update_display();
|
||||
|
||||
// First paint
|
||||
calculator_paint();
|
||||
ui_mark_dirty(win_calculator, 0, 0, 180, 230);
|
||||
|
||||
// Check events from Kernel User Interface queue
|
||||
gui_event_t ev;
|
||||
while (1) {
|
||||
if (ui_get_event(win_calculator, &ev)) {
|
||||
if (ev.type == GUI_EVENT_PAINT) {
|
||||
calculator_paint();
|
||||
ui_mark_dirty(win_calculator, 0, 0, 180, 230);
|
||||
} else if (ev.type == GUI_EVENT_CLICK) {
|
||||
calculator_click(ev.arg1, ev.arg2);
|
||||
} else if (ev.type == GUI_EVENT_CLOSE) {
|
||||
sys_exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
src/kernel/userland/calculator.elf
Executable file
BIN
src/kernel/userland/calculator.elf
Executable file
Binary file not shown.
12
src/kernel/userland/crash.c
Normal file
12
src/kernel/userland/crash.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "syscall.h"
|
||||
|
||||
int main() {
|
||||
const char* msg = "Attempting to crash via null dereference...\n";
|
||||
sys_write(1, msg, 45);
|
||||
|
||||
// Null pointer dereference
|
||||
volatile int* p = (int*)0;
|
||||
*p = 123;
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
src/kernel/userland/crash.elf
Executable file
BIN
src/kernel/userland/crash.elf
Executable file
Binary file not shown.
26
src/kernel/userland/crt0.asm
Normal file
26
src/kernel/userland/crt0.asm
Normal file
@@ -0,0 +1,26 @@
|
||||
; userland/crt0.asm
|
||||
global _start
|
||||
extern main
|
||||
extern sys_exit
|
||||
|
||||
section .text
|
||||
_start:
|
||||
; The kernel loads the ELF and jumps here.
|
||||
; RSP should point to the 0x800000 stack.
|
||||
|
||||
; Align the stack to 16 bytes for C functions (System V ABI)
|
||||
and rsp, -16
|
||||
|
||||
; Call main(argc, argv)
|
||||
; We don't have argc or argv yet, pass 0
|
||||
xor rdi, rdi
|
||||
xor rsi, rsi
|
||||
call main
|
||||
|
||||
; If main returns, call exit(status)
|
||||
mov rdi, rax ; Pass main's return value to exit syscall
|
||||
call sys_exit
|
||||
|
||||
; Fallback halt if exit miraculously returns
|
||||
.hang:
|
||||
jmp .hang
|
||||
BIN
src/kernel/userland/crt0.o
Normal file
BIN
src/kernel/userland/crt0.o
Normal file
Binary file not shown.
7
src/kernel/userland/hello.c
Normal file
7
src/kernel/userland/hello.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "syscall.h"
|
||||
|
||||
int main() {
|
||||
const char* msg = "Hello from Userland ELF!\n";
|
||||
sys_write(1, msg, 25);
|
||||
return 0;
|
||||
}
|
||||
BIN
src/kernel/userland/hello.elf
Executable file
BIN
src/kernel/userland/hello.elf
Executable file
Binary file not shown.
BIN
src/kernel/userland/hello.o
Normal file
BIN
src/kernel/userland/hello.o
Normal file
Binary file not shown.
40
src/kernel/userland/libc/libui.c
Normal file
40
src/kernel/userland/libc/libui.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "libui.h"
|
||||
#include "syscall.h"
|
||||
#include <stddef.h>
|
||||
|
||||
extern uint64_t syscall3(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||
extern uint64_t syscall4(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
|
||||
extern uint64_t syscall5(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5);
|
||||
|
||||
// sys_gui uses syscall #3
|
||||
#define SYS_GUI 3
|
||||
|
||||
ui_window_t ui_window_create(const char *title, int x, int y, int w, int h) {
|
||||
uint64_t params[4] = { (uint64_t)x, (uint64_t)y, (uint64_t)w, (uint64_t)h };
|
||||
return (ui_window_t)syscall3(SYS_GUI, GUI_CMD_WINDOW_CREATE, (uint64_t)title, (uint64_t)params);
|
||||
}
|
||||
|
||||
bool ui_get_event(ui_window_t win, gui_event_t *ev) {
|
||||
int res = (int)syscall3(SYS_GUI, GUI_CMD_GET_EVENT, (uint64_t)win, (uint64_t)ev);
|
||||
return res != 0;
|
||||
}
|
||||
|
||||
void ui_draw_rect(ui_window_t win, int x, int y, int w, int h, uint32_t color) {
|
||||
uint64_t params[4] = { (uint64_t)x, (uint64_t)y, (uint64_t)w, (uint64_t)h };
|
||||
syscall4(SYS_GUI, GUI_CMD_DRAW_RECT, (uint64_t)win, (uint64_t)params, (uint64_t)color);
|
||||
}
|
||||
|
||||
void ui_draw_rounded_rect_filled(ui_window_t win, int x, int y, int w, int h, int radius, uint32_t color) {
|
||||
uint64_t params[5] = { (uint64_t)x, (uint64_t)y, (uint64_t)w, (uint64_t)h, (uint64_t)radius };
|
||||
syscall4(SYS_GUI, GUI_CMD_DRAW_ROUNDED_RECT_FILLED, (uint64_t)win, (uint64_t)params, (uint64_t)color);
|
||||
}
|
||||
|
||||
void ui_draw_string(ui_window_t win, int x, int y, const char *str, uint32_t color) {
|
||||
uint64_t coords = ((uint64_t)x & 0xFFFFFFFF) | ((uint64_t)y << 32);
|
||||
syscall5(SYS_GUI, GUI_CMD_DRAW_STRING, (uint64_t)win, coords, (uint64_t)str, (uint64_t)color);
|
||||
}
|
||||
|
||||
void ui_mark_dirty(ui_window_t win, int x, int y, int w, int h) {
|
||||
uint64_t params[4] = { (uint64_t)x, (uint64_t)y, (uint64_t)w, (uint64_t)h };
|
||||
syscall3(SYS_GUI, GUI_CMD_MARK_DIRTY, (uint64_t)win, (uint64_t)params);
|
||||
}
|
||||
40
src/kernel/userland/libc/libui.h
Normal file
40
src/kernel/userland/libc/libui.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef LIBUI_H
|
||||
#define LIBUI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// GUI Command IDs
|
||||
#define GUI_CMD_WINDOW_CREATE 1
|
||||
#define GUI_CMD_DRAW_RECT 2
|
||||
#define GUI_CMD_DRAW_STRING 3
|
||||
#define GUI_CMD_MARK_DIRTY 4
|
||||
#define GUI_CMD_GET_EVENT 5
|
||||
#define GUI_CMD_DRAW_ROUNDED_RECT_FILLED 6
|
||||
|
||||
// Event Types
|
||||
#define GUI_EVENT_NONE 0
|
||||
#define GUI_EVENT_PAINT 1
|
||||
#define GUI_EVENT_CLICK 2
|
||||
#define GUI_EVENT_RIGHT_CLICK 3
|
||||
#define GUI_EVENT_CLOSE 4
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
int arg1; // For click: x
|
||||
int arg2; // For click: y
|
||||
} gui_event_t;
|
||||
|
||||
// Window Handle
|
||||
typedef int ui_window_t;
|
||||
|
||||
// libui API
|
||||
ui_window_t ui_window_create(const char *title, int x, int y, int w, int h);
|
||||
bool ui_get_event(ui_window_t win, gui_event_t *ev);
|
||||
|
||||
void ui_draw_rect(ui_window_t win, int x, int y, int w, int h, uint32_t color);
|
||||
void ui_draw_rounded_rect_filled(ui_window_t win, int x, int y, int w, int h, int radius, uint32_t color);
|
||||
void ui_draw_string(ui_window_t win, int x, int y, const char *str, uint32_t color);
|
||||
void ui_mark_dirty(ui_window_t win, int x, int y, int w, int h);
|
||||
|
||||
#endif
|
||||
71
src/kernel/userland/libc/syscall.c
Normal file
71
src/kernel/userland/libc/syscall.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "syscall.h"
|
||||
|
||||
|
||||
|
||||
uint64_t syscall0(uint64_t sys_num) {
|
||||
uint64_t ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(sys_num)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t syscall1(uint64_t sys_num, uint64_t arg1) {
|
||||
uint64_t ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(sys_num), "D"(arg1)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t syscall2(uint64_t sys_num, uint64_t arg1, uint64_t arg2) {
|
||||
uint64_t ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(sys_num), "D"(arg1), "S"(arg2)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t syscall3(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3) {
|
||||
uint64_t ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(sys_num), "D"(arg1), "S"(arg2), "d"(arg3)
|
||||
: "rcx", "r11", "memory", "r10", "r8", "r9");
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t syscall4(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4) {
|
||||
uint64_t ret;
|
||||
register uint64_t r10 asm("r10") = arg4;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(sys_num), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10)
|
||||
: "rcx", "r11", "memory", "r8", "r9");
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint64_t syscall5(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) {
|
||||
uint64_t ret;
|
||||
register uint64_t r10 asm("r10") = arg4;
|
||||
register uint64_t r8 asm("r8") = arg5;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret)
|
||||
: "a"(sys_num), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8)
|
||||
: "rcx", "r11", "memory", "r9");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// C-Friendly Wrappers
|
||||
|
||||
void sys_exit(int status) {
|
||||
syscall1(SYS_EXIT, (uint64_t)status);
|
||||
while (1); // Halt
|
||||
}
|
||||
|
||||
int sys_write(int fd, const char *buf, int len) {
|
||||
return (int)syscall3(SYS_WRITE, (uint64_t)fd, (uint64_t)buf, (uint64_t)len);
|
||||
}
|
||||
22
src/kernel/userland/libc/syscall.h
Normal file
22
src/kernel/userland/libc/syscall.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef SYSCALL_H
|
||||
#define SYSCALL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Standard syscalls available from Kernel mode
|
||||
#define SYS_EXIT 0
|
||||
#define SYS_WRITE 1
|
||||
|
||||
// Internal assembly entry into Ring 0
|
||||
extern uint64_t syscall0(uint64_t sys_num);
|
||||
extern uint64_t syscall1(uint64_t sys_num, uint64_t arg1);
|
||||
extern uint64_t syscall2(uint64_t sys_num, uint64_t arg1, uint64_t arg2);
|
||||
extern uint64_t syscall3(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3);
|
||||
extern uint64_t syscall4(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4);
|
||||
extern uint64_t syscall5(uint64_t sys_num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5);
|
||||
|
||||
// Public API
|
||||
void sys_exit(int status);
|
||||
int sys_write(int fd, const char *buf, int len);
|
||||
|
||||
#endif
|
||||
BIN
src/kernel/userland/libc/syscall.o
Normal file
BIN
src/kernel/userland/libc/syscall.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user