This commit is contained in:
2026-04-25 00:12:38 +08:00
parent 4c17f1a24b
commit bdbbbe64c7
11 changed files with 1251 additions and 975 deletions

View File

@@ -354,7 +354,7 @@ if(CLEONOS_ENABLE)
"-DLOG_LEVEL=STEP"
"-DLOG_TEXT=launching qemu run"
-P "${CL_LOG_EMIT_SCRIPT}"
COMMAND ${QEMU_X86_64} -M pc -m 1024M -boot order=d -cdrom "${ISO_IMAGE}" -drive "file=${DISK_IMAGE},format=raw,if=none,id=clksdisk,media=disk" -device "ide-hd,drive=clksdisk,bus=ide.0" -serial stdio
COMMAND ${QEMU_X86_64} -M pc -m 1024M -boot order=d -cdrom "${ISO_IMAGE}" -drive "file=${DISK_IMAGE},format=raw,if=none,id=clksdisk,media=disk" -device "ide-hd,drive=clksdisk,bus=ide.0" -netdev "user,id=clksnet0" -device "e1000,netdev=clksnet0" -serial stdio
DEPENDS iso disk-image
USES_TERMINAL
)
@@ -365,7 +365,7 @@ if(CLEONOS_ENABLE)
"-DLOG_LEVEL=STEP"
"-DLOG_TEXT=launching qemu debug (-s -S)"
-P "${CL_LOG_EMIT_SCRIPT}"
COMMAND ${QEMU_X86_64} -M pc -m 1024M -boot order=d -cdrom "${ISO_IMAGE}" -drive "file=${DISK_IMAGE},format=raw,if=none,id=clksdisk,media=disk" -device "ide-hd,drive=clksdisk,bus=ide.0" -serial stdio -s -S
COMMAND ${QEMU_X86_64} -M pc -m 1024M -boot order=d -cdrom "${ISO_IMAGE}" -drive "file=${DISK_IMAGE},format=raw,if=none,id=clksdisk,media=disk" -device "ide-hd,drive=clksdisk,bus=ide.0" -netdev "user,id=clksnet0" -device "e1000,netdev=clksnet0" -serial stdio -s -S
DEPENDS iso disk-image
USES_TERMINAL
)

View File

@@ -128,6 +128,7 @@ list(SORT DOOMGENERIC_DEP_SOURCES_ABS)
set(USER_SHELL_COMMAND_APPS
help args ls cat grep head tail wc cut uniq sort pwd cd exec pid spawn wait sleep yield
ping
bg fg jobs kill ps top
procstat sysstat
diskinfo mkfsfat32 mount partctl

View File

@@ -1,17 +1,17 @@
#include "cmd_runtime.h"
static int ush_cmd_help(void) {
ush_writeln("commands:");
ush_writeln(" help");
ush_writeln(" args [a b c] (print argc/argv/envp)");
ush_writeln(" ls [-l] [-R] [path]");
ush_writeln(" cat [file] (reads pipeline input when file omitted)");
ush_writeln(" grep [-n] <pattern> [file]");
ush_writeln(" head [-n N] [file] / tail [-n N] [file]");
ush_writeln(" wc [file] / cut -d <char> -f <N> [file] / uniq [file] / sort [file]");
ush_writeln(" pwd");
ush_writeln(" cd [dir]");
ush_writeln(" exec|run <path|name> [args...]");
ush_writeln(" clear");
#include "cmd_runtime.h"
static int ush_cmd_help(void) {
ush_writeln("commands:");
ush_writeln(" help");
ush_writeln(" args [a b c] (print argc/argv/envp)");
ush_writeln(" ls [-l] [-R] [path]");
ush_writeln(" cat [file] (reads pipeline input when file omitted)");
ush_writeln(" grep [-n] <pattern> [file]");
ush_writeln(" head [-n N] [file] / tail [-n N] [file]");
ush_writeln(" wc [file] / cut -d <char> -f <N> [file] / uniq [file] / sort [file]");
ush_writeln(" pwd");
ush_writeln(" cd [dir]");
ush_writeln(" exec|run <path|name> [args...]");
ush_writeln(" clear");
ush_writeln(" ansi / ansitest / color");
ush_writeln(" bmpview <file.bmp> [cols]");
ush_writeln(" qrcode [--ecc <L|M|Q|H>] <text>");
@@ -19,9 +19,9 @@ static int ush_cmd_help(void) {
ush_writeln(" fastfetch [--plain]");
ush_writeln(" doom [wad_path] (framebuffer bootstrap renderer)");
ush_writeln(" memstat / fsstat / taskstat / userstat / shstat / stats");
ush_writeln(" tty [index]");
ush_writeln(" dmesg [n]");
ush_writeln(" kbdstat");
ush_writeln(" tty [index]");
ush_writeln(" dmesg [n]");
ush_writeln(" kbdstat");
ush_writeln(" mkdir <dir> (/temp only)");
ush_writeln(" touch <file> (/temp only)");
ush_writeln(" write <file> <text> (/temp only, or from pipeline)");
@@ -33,63 +33,64 @@ static int ush_cmd_help(void) {
ush_writeln(" mkfsfat32 [label]");
ush_writeln(" mount [path] (default suggested: /temp/disk)");
ush_writeln(" partctl <subcommand> (mbr partition control: list/init-mbr/create/delete/set-boot)");
ush_writeln(" ping <a.b.c.d> [count]");
ush_writeln(" pid");
ush_writeln(" spawn <path|name> [args...] / bg <path|name> [args...]");
ush_writeln(" wait <pid> / fg [pid]");
ush_writeln(" kill <pid> [signal]");
ush_writeln(" jobs [-a] / ps [-a] [-u] / procstat [pid|self] [-a]");
ush_writeln(" top [--once] [-n loops] [-d ticks] / sysstat [-a] [-n N]");
ush_writeln(" kdbg sym <addr> / kdbg bt <rbp> <rip> / kdbg regs");
ush_writeln(" sleep <ticks>");
ush_writeln(" spin (busy loop test for Alt+Ctrl+C)");
ush_writeln(" yield");
ush_writeln(" shutdown / restart");
ush_writeln(" exit [code]");
ush_writeln(" rusttest / panic / elfloader (kernel shell only)");
ush_writeln("pipeline/redirection: cmd1 | cmd2 | cmd3 > /temp/out.txt");
ush_writeln("redirection append: cmd >> /temp/out.txt");
ush_writeln("edit keys: Left/Right, Home/End, Up/Down history");
return 1;
}
int cleonos_app_main(void) {
ush_cmd_ctx ctx;
ush_cmd_ret ret;
ush_state sh;
char initial_cwd[USH_PATH_MAX];
int has_context = 0;
int success = 0;
ush_zero(&ctx, (u64)sizeof(ctx));
ush_zero(&ret, (u64)sizeof(ret));
ush_init_state(&sh);
ush_copy(initial_cwd, (u64)sizeof(initial_cwd), sh.cwd);
if (ush_command_ctx_read(&ctx) != 0) {
if (ctx.cmd[0] != '\0' && ush_streq(ctx.cmd, "help") != 0) {
has_context = 1;
if (ctx.cwd[0] == '/') {
ush_copy(sh.cwd, (u64)sizeof(sh.cwd), ctx.cwd);
ush_copy(initial_cwd, (u64)sizeof(initial_cwd), sh.cwd);
}
}
}
success = ush_cmd_help();
if (has_context != 0) {
if (ush_streq(sh.cwd, initial_cwd) == 0) {
ret.flags |= USH_CMD_RET_FLAG_CWD;
ush_copy(ret.cwd, (u64)sizeof(ret.cwd), sh.cwd);
}
if (sh.exit_requested != 0) {
ret.flags |= USH_CMD_RET_FLAG_EXIT;
ret.exit_code = sh.exit_code;
}
(void)ush_command_ret_write(&ret);
}
return (success != 0) ? 0 : 1;
}
ush_writeln(" spawn <path|name> [args...] / bg <path|name> [args...]");
ush_writeln(" wait <pid> / fg [pid]");
ush_writeln(" kill <pid> [signal]");
ush_writeln(" jobs [-a] / ps [-a] [-u] / procstat [pid|self] [-a]");
ush_writeln(" top [--once] [-n loops] [-d ticks] / sysstat [-a] [-n N]");
ush_writeln(" kdbg sym <addr> / kdbg bt <rbp> <rip> / kdbg regs");
ush_writeln(" sleep <ticks>");
ush_writeln(" spin (busy loop test for Alt+Ctrl+C)");
ush_writeln(" yield");
ush_writeln(" shutdown / restart");
ush_writeln(" exit [code]");
ush_writeln(" rusttest / panic / elfloader (kernel shell only)");
ush_writeln("pipeline/redirection: cmd1 | cmd2 | cmd3 > /temp/out.txt");
ush_writeln("redirection append: cmd >> /temp/out.txt");
ush_writeln("edit keys: Left/Right, Home/End, Up/Down history");
return 1;
}
int cleonos_app_main(void) {
ush_cmd_ctx ctx;
ush_cmd_ret ret;
ush_state sh;
char initial_cwd[USH_PATH_MAX];
int has_context = 0;
int success = 0;
ush_zero(&ctx, (u64)sizeof(ctx));
ush_zero(&ret, (u64)sizeof(ret));
ush_init_state(&sh);
ush_copy(initial_cwd, (u64)sizeof(initial_cwd), sh.cwd);
if (ush_command_ctx_read(&ctx) != 0) {
if (ctx.cmd[0] != '\0' && ush_streq(ctx.cmd, "help") != 0) {
has_context = 1;
if (ctx.cwd[0] == '/') {
ush_copy(sh.cwd, (u64)sizeof(sh.cwd), ctx.cwd);
ush_copy(initial_cwd, (u64)sizeof(initial_cwd), sh.cwd);
}
}
}
success = ush_cmd_help();
if (has_context != 0) {
if (ush_streq(sh.cwd, initial_cwd) == 0) {
ret.flags |= USH_CMD_RET_FLAG_CWD;
ush_copy(ret.cwd, (u64)sizeof(ret.cwd), sh.cwd);
}
if (sh.exit_requested != 0) {
ret.flags |= USH_CMD_RET_FLAG_EXIT;
ret.exit_code = sh.exit_code;
}
(void)ush_command_ret_write(&ret);
}
return (success != 0) ? 0 : 1;
}

181
cleonos/c/apps/ping_main.c Normal file
View File

@@ -0,0 +1,181 @@
#include "cmd_runtime.h"
#include <stdio.h>
static int ush_ping_parse_ipv4_be(const char *text, u64 *out_ipv4_be) {
u64 acc = 0ULL;
u64 value = 0ULL;
u64 parts = 0ULL;
u64 has_digit = 0ULL;
u64 i = 0ULL;
if (text == (const char *)0 || out_ipv4_be == (u64 *)0) {
return 0;
}
while (text[i] != '\0') {
char ch = text[i];
if (ch >= '0' && ch <= '9') {
value = (value * 10ULL) + (u64)(ch - '0');
if (value > 255ULL) {
return 0;
}
has_digit = 1ULL;
} else if (ch == '.') {
if (has_digit == 0ULL || parts >= 3ULL) {
return 0;
}
acc = (acc << 8ULL) | value;
parts++;
value = 0ULL;
has_digit = 0ULL;
} else {
return 0;
}
i++;
}
if (has_digit == 0ULL || parts != 3ULL) {
return 0;
}
acc = (acc << 8ULL) | value;
*out_ipv4_be = acc & 0xFFFFFFFFULL;
return 1;
}
static void ush_ping_print_ipv4(u64 ipv4_be) {
unsigned int a = (unsigned int)((ipv4_be >> 24ULL) & 0xFFULL);
unsigned int b = (unsigned int)((ipv4_be >> 16ULL) & 0xFFULL);
unsigned int c = (unsigned int)((ipv4_be >> 8ULL) & 0xFFULL);
unsigned int d = (unsigned int)(ipv4_be & 0xFFULL);
(void)printf("%u.%u.%u.%u", a, b, c, d);
}
static int ush_cmd_ping(const char *arg) {
char host[USH_PATH_MAX];
char count_text[32];
const char *rest = "";
const char *rest2 = "";
u64 target_ipv4_be = 0ULL;
u64 local_ipv4_be;
u64 count = 4ULL;
u64 i;
u64 received = 0ULL;
if (arg == (const char *)0 || arg[0] == '\0') {
(void)puts("ping: usage ping <a.b.c.d> [count]");
return 0;
}
if (ush_split_first_and_rest(arg, host, (u64)sizeof(host), &rest) == 0) {
(void)puts("ping: usage ping <a.b.c.d> [count]");
return 0;
}
if (ush_ping_parse_ipv4_be(host, &target_ipv4_be) == 0) {
(void)puts("ping: invalid ipv4 address");
return 0;
}
if (rest != (const char *)0 && rest[0] != '\0') {
if (ush_split_first_and_rest(rest, count_text, (u64)sizeof(count_text), &rest2) == 0) {
(void)puts("ping: usage ping <a.b.c.d> [count]");
return 0;
}
if (rest2 != (const char *)0 && rest2[0] != '\0') {
(void)puts("ping: usage ping <a.b.c.d> [count]");
return 0;
}
if (ush_parse_u64_dec(count_text, &count) == 0 || count == 0ULL || count > 64ULL) {
(void)puts("ping: count must be in range 1..64");
return 0;
}
}
if (cleonos_sys_net_available() == 0ULL) {
(void)puts("ping: network unavailable (e1000 not ready)");
return 0;
}
local_ipv4_be = cleonos_sys_net_ipv4_addr();
(void)fputs("PING ", 1);
ush_ping_print_ipv4(target_ipv4_be);
(void)fputs(" from ", 1);
ush_ping_print_ipv4(local_ipv4_be);
(void)putchar('\n');
for (i = 0ULL; i < count; i++) {
u64 ok = cleonos_sys_net_ping(target_ipv4_be, 300000ULL);
if (ok != 0ULL) {
(void)fputs("reply from ", 1);
ush_ping_print_ipv4(target_ipv4_be);
(void)printf(" seq=%llu\n", (unsigned long long)(i + 1ULL));
received++;
} else {
(void)fputs("timeout from ", 1);
ush_ping_print_ipv4(target_ipv4_be);
(void)printf(" seq=%llu\n", (unsigned long long)(i + 1ULL));
}
if (i + 1ULL < count) {
(void)cleonos_sys_sleep_ticks(30ULL);
}
}
(void)puts("");
(void)printf("ping stats: tx=%llu rx=%llu loss=%llu\n", (unsigned long long)count, (unsigned long long)received,
(unsigned long long)(count - received));
return (received > 0ULL) ? 1 : 0;
}
int cleonos_app_main(void) {
ush_cmd_ctx ctx;
ush_cmd_ret ret;
ush_state sh;
char initial_cwd[USH_PATH_MAX];
int has_context = 0;
int success = 0;
const char *arg = "";
ush_zero(&ctx, (u64)sizeof(ctx));
ush_zero(&ret, (u64)sizeof(ret));
ush_init_state(&sh);
ush_copy(initial_cwd, (u64)sizeof(initial_cwd), sh.cwd);
if (ush_command_ctx_read(&ctx) != 0) {
if (ctx.cmd[0] != '\0' && ush_streq(ctx.cmd, "ping") != 0) {
has_context = 1;
arg = ctx.arg;
if (ctx.cwd[0] == '/') {
ush_copy(sh.cwd, (u64)sizeof(sh.cwd), ctx.cwd);
ush_copy(initial_cwd, (u64)sizeof(initial_cwd), sh.cwd);
}
}
}
success = ush_cmd_ping(arg);
if (has_context != 0) {
if (ush_streq(sh.cwd, initial_cwd) == 0) {
ret.flags |= USH_CMD_RET_FLAG_CWD;
ush_copy(ret.cwd, (u64)sizeof(ret.cwd), sh.cwd);
}
if (sh.exit_requested != 0) {
ret.flags |= USH_CMD_RET_FLAG_EXIT;
ret.exit_code = sh.exit_code;
}
(void)ush_command_ret_write(&ret);
}
return (success != 0) ? 0 : 1;
}

View File

@@ -1,46 +1,46 @@
#ifndef CLEONOS_SYSCALL_H
#define CLEONOS_SYSCALL_H
typedef unsigned long long u64;
typedef unsigned long long usize;
#define CLEONOS_FS_NAME_MAX 96ULL
#define CLEONOS_PROC_PATH_MAX 192ULL
#define CLEONOS_PROC_STATE_UNUSED 0ULL
#define CLEONOS_PROC_STATE_PENDING 1ULL
#define CLEONOS_PROC_STATE_RUNNING 2ULL
#define CLEONOS_PROC_STATE_EXITED 3ULL
#define CLEONOS_PROC_STATE_STOPPED 4ULL
#define CLEONOS_SIGKILL 9ULL
#define CLEONOS_SIGTERM 15ULL
#define CLEONOS_SIGCONT 18ULL
#define CLEONOS_SIGSTOP 19ULL
#define CLEONOS_O_RDONLY 0x0000ULL
#define CLEONOS_O_WRONLY 0x0001ULL
#define CLEONOS_O_RDWR 0x0002ULL
#define CLEONOS_O_CREAT 0x0040ULL
#define CLEONOS_O_TRUNC 0x0200ULL
#define CLEONOS_O_APPEND 0x0400ULL
#define CLEONOS_FD_INHERIT ((u64) - 1)
#ifndef CLEONOS_SYSCALL_H
#define CLEONOS_SYSCALL_H
typedef unsigned long long u64;
typedef unsigned long long usize;
#define CLEONOS_FS_NAME_MAX 96ULL
#define CLEONOS_PROC_PATH_MAX 192ULL
#define CLEONOS_PROC_STATE_UNUSED 0ULL
#define CLEONOS_PROC_STATE_PENDING 1ULL
#define CLEONOS_PROC_STATE_RUNNING 2ULL
#define CLEONOS_PROC_STATE_EXITED 3ULL
#define CLEONOS_PROC_STATE_STOPPED 4ULL
#define CLEONOS_SIGKILL 9ULL
#define CLEONOS_SIGTERM 15ULL
#define CLEONOS_SIGCONT 18ULL
#define CLEONOS_SIGSTOP 19ULL
#define CLEONOS_O_RDONLY 0x0000ULL
#define CLEONOS_O_WRONLY 0x0001ULL
#define CLEONOS_O_RDWR 0x0002ULL
#define CLEONOS_O_CREAT 0x0040ULL
#define CLEONOS_O_TRUNC 0x0200ULL
#define CLEONOS_O_APPEND 0x0400ULL
#define CLEONOS_FD_INHERIT ((u64) - 1)
typedef struct cleonos_proc_snapshot {
u64 pid;
u64 ppid;
u64 state;
u64 started_tick;
u64 exited_tick;
u64 exit_status;
u64 runtime_ticks;
u64 mem_bytes;
u64 tty_index;
u64 last_signal;
u64 last_fault_vector;
u64 last_fault_error;
u64 last_fault_rip;
char path[CLEONOS_PROC_PATH_MAX];
u64 pid;
u64 ppid;
u64 state;
u64 started_tick;
u64 exited_tick;
u64 exit_status;
u64 runtime_ticks;
u64 mem_bytes;
u64 tty_index;
u64 last_signal;
u64 last_fault_vector;
u64 last_fault_error;
u64 last_fault_rip;
char path[CLEONOS_PROC_PATH_MAX];
} cleonos_proc_snapshot;
typedef struct cleonos_fb_info {
@@ -60,83 +60,99 @@ typedef struct cleonos_fb_blit_req {
u64 scale;
} cleonos_fb_blit_req;
#define CLEONOS_SYSCALL_LOG_WRITE 0ULL
#define CLEONOS_SYSCALL_TIMER_TICKS 1ULL
#define CLEONOS_SYSCALL_TASK_COUNT 2ULL
#define CLEONOS_SYSCALL_CUR_TASK 3ULL
#define CLEONOS_SYSCALL_SERVICE_COUNT 4ULL
#define CLEONOS_SYSCALL_SERVICE_READY_COUNT 5ULL
#define CLEONOS_SYSCALL_CONTEXT_SWITCHES 6ULL
#define CLEONOS_SYSCALL_KELF_COUNT 7ULL
#define CLEONOS_SYSCALL_KELF_RUNS 8ULL
#define CLEONOS_SYSCALL_FS_NODE_COUNT 9ULL
#define CLEONOS_SYSCALL_FS_CHILD_COUNT 10ULL
#define CLEONOS_SYSCALL_FS_GET_CHILD_NAME 11ULL
#define CLEONOS_SYSCALL_FS_READ 12ULL
#define CLEONOS_SYSCALL_EXEC_PATH 13ULL
#define CLEONOS_SYSCALL_EXEC_REQUESTS 14ULL
#define CLEONOS_SYSCALL_EXEC_SUCCESS 15ULL
#define CLEONOS_SYSCALL_USER_SHELL_READY 16ULL
#define CLEONOS_SYSCALL_USER_EXEC_REQUESTED 17ULL
#define CLEONOS_SYSCALL_USER_LAUNCH_TRIES 18ULL
#define CLEONOS_SYSCALL_USER_LAUNCH_OK 19ULL
#define CLEONOS_SYSCALL_USER_LAUNCH_FAIL 20ULL
#define CLEONOS_SYSCALL_TTY_COUNT 21ULL
#define CLEONOS_SYSCALL_TTY_ACTIVE 22ULL
#define CLEONOS_SYSCALL_TTY_SWITCH 23ULL
#define CLEONOS_SYSCALL_TTY_WRITE 24ULL
#define CLEONOS_SYSCALL_TTY_WRITE_CHAR 25ULL
#define CLEONOS_SYSCALL_KBD_GET_CHAR 26ULL
#define CLEONOS_SYSCALL_FS_STAT_TYPE 27ULL
#define CLEONOS_SYSCALL_FS_STAT_SIZE 28ULL
#define CLEONOS_SYSCALL_FS_MKDIR 29ULL
#define CLEONOS_SYSCALL_FS_WRITE 30ULL
#define CLEONOS_SYSCALL_FS_APPEND 31ULL
#define CLEONOS_SYSCALL_FS_REMOVE 32ULL
#define CLEONOS_SYSCALL_LOG_JOURNAL_COUNT 33ULL
#define CLEONOS_SYSCALL_LOG_JOURNAL_READ 34ULL
#define CLEONOS_SYSCALL_KBD_BUFFERED 35ULL
#define CLEONOS_SYSCALL_KBD_PUSHED 36ULL
#define CLEONOS_SYSCALL_KBD_POPPED 37ULL
#define CLEONOS_SYSCALL_KBD_DROPPED 38ULL
#define CLEONOS_SYSCALL_KBD_HOTKEY_SWITCHES 39ULL
#define CLEONOS_SYSCALL_GETPID 40ULL
#define CLEONOS_SYSCALL_SPAWN_PATH 41ULL
#define CLEONOS_SYSCALL_WAITPID 42ULL
#define CLEONOS_SYSCALL_EXIT 43ULL
#define CLEONOS_SYSCALL_SLEEP_TICKS 44ULL
#define CLEONOS_SYSCALL_YIELD 45ULL
#define CLEONOS_SYSCALL_SHUTDOWN 46ULL
#define CLEONOS_SYSCALL_RESTART 47ULL
#define CLEONOS_SYSCALL_AUDIO_AVAILABLE 48ULL
#define CLEONOS_SYSCALL_AUDIO_PLAY_TONE 49ULL
#define CLEONOS_SYSCALL_AUDIO_STOP 50ULL
#define CLEONOS_SYSCALL_EXEC_PATHV 51ULL
#define CLEONOS_SYSCALL_SPAWN_PATHV 52ULL
#define CLEONOS_SYSCALL_PROC_ARGC 53ULL
#define CLEONOS_SYSCALL_PROC_ARGV 54ULL
#define CLEONOS_SYSCALL_PROC_ENVC 55ULL
#define CLEONOS_SYSCALL_PROC_ENV 56ULL
#define CLEONOS_SYSCALL_PROC_LAST_SIGNAL 57ULL
#define CLEONOS_SYSCALL_PROC_FAULT_VECTOR 58ULL
#define CLEONOS_SYSCALL_PROC_FAULT_ERROR 59ULL
#define CLEONOS_SYSCALL_PROC_FAULT_RIP 60ULL
#define CLEONOS_SYSCALL_PROC_COUNT 61ULL
#define CLEONOS_SYSCALL_PROC_PID_AT 62ULL
#define CLEONOS_SYSCALL_PROC_SNAPSHOT 63ULL
#define CLEONOS_SYSCALL_PROC_KILL 64ULL
#define CLEONOS_SYSCALL_KDBG_SYM 65ULL
#define CLEONOS_SYSCALL_KDBG_BT 66ULL
#define CLEONOS_SYSCALL_KDBG_REGS 67ULL
#define CLEONOS_SYSCALL_STATS_TOTAL 68ULL
#define CLEONOS_SYSCALL_STATS_ID_COUNT 69ULL
#define CLEONOS_SYSCALL_STATS_RECENT_WINDOW 70ULL
#define CLEONOS_SYSCALL_STATS_RECENT_ID 71ULL
#define CLEONOS_SYSCALL_FD_OPEN 72ULL
#define CLEONOS_SYSCALL_FD_READ 73ULL
#define CLEONOS_SYSCALL_FD_WRITE 74ULL
#define CLEONOS_SYSCALL_FD_CLOSE 75ULL
#define CLEONOS_SYSCALL_FD_DUP 76ULL
typedef struct cleonos_net_udp_send_req {
u64 dst_ipv4_be;
u64 dst_port;
u64 src_port;
u64 payload_ptr;
u64 payload_len;
} cleonos_net_udp_send_req;
typedef struct cleonos_net_udp_recv_req {
u64 out_payload_ptr;
u64 payload_capacity;
u64 out_src_ipv4_ptr;
u64 out_src_port_ptr;
u64 out_dst_port_ptr;
} cleonos_net_udp_recv_req;
#define CLEONOS_SYSCALL_LOG_WRITE 0ULL
#define CLEONOS_SYSCALL_TIMER_TICKS 1ULL
#define CLEONOS_SYSCALL_TASK_COUNT 2ULL
#define CLEONOS_SYSCALL_CUR_TASK 3ULL
#define CLEONOS_SYSCALL_SERVICE_COUNT 4ULL
#define CLEONOS_SYSCALL_SERVICE_READY_COUNT 5ULL
#define CLEONOS_SYSCALL_CONTEXT_SWITCHES 6ULL
#define CLEONOS_SYSCALL_KELF_COUNT 7ULL
#define CLEONOS_SYSCALL_KELF_RUNS 8ULL
#define CLEONOS_SYSCALL_FS_NODE_COUNT 9ULL
#define CLEONOS_SYSCALL_FS_CHILD_COUNT 10ULL
#define CLEONOS_SYSCALL_FS_GET_CHILD_NAME 11ULL
#define CLEONOS_SYSCALL_FS_READ 12ULL
#define CLEONOS_SYSCALL_EXEC_PATH 13ULL
#define CLEONOS_SYSCALL_EXEC_REQUESTS 14ULL
#define CLEONOS_SYSCALL_EXEC_SUCCESS 15ULL
#define CLEONOS_SYSCALL_USER_SHELL_READY 16ULL
#define CLEONOS_SYSCALL_USER_EXEC_REQUESTED 17ULL
#define CLEONOS_SYSCALL_USER_LAUNCH_TRIES 18ULL
#define CLEONOS_SYSCALL_USER_LAUNCH_OK 19ULL
#define CLEONOS_SYSCALL_USER_LAUNCH_FAIL 20ULL
#define CLEONOS_SYSCALL_TTY_COUNT 21ULL
#define CLEONOS_SYSCALL_TTY_ACTIVE 22ULL
#define CLEONOS_SYSCALL_TTY_SWITCH 23ULL
#define CLEONOS_SYSCALL_TTY_WRITE 24ULL
#define CLEONOS_SYSCALL_TTY_WRITE_CHAR 25ULL
#define CLEONOS_SYSCALL_KBD_GET_CHAR 26ULL
#define CLEONOS_SYSCALL_FS_STAT_TYPE 27ULL
#define CLEONOS_SYSCALL_FS_STAT_SIZE 28ULL
#define CLEONOS_SYSCALL_FS_MKDIR 29ULL
#define CLEONOS_SYSCALL_FS_WRITE 30ULL
#define CLEONOS_SYSCALL_FS_APPEND 31ULL
#define CLEONOS_SYSCALL_FS_REMOVE 32ULL
#define CLEONOS_SYSCALL_LOG_JOURNAL_COUNT 33ULL
#define CLEONOS_SYSCALL_LOG_JOURNAL_READ 34ULL
#define CLEONOS_SYSCALL_KBD_BUFFERED 35ULL
#define CLEONOS_SYSCALL_KBD_PUSHED 36ULL
#define CLEONOS_SYSCALL_KBD_POPPED 37ULL
#define CLEONOS_SYSCALL_KBD_DROPPED 38ULL
#define CLEONOS_SYSCALL_KBD_HOTKEY_SWITCHES 39ULL
#define CLEONOS_SYSCALL_GETPID 40ULL
#define CLEONOS_SYSCALL_SPAWN_PATH 41ULL
#define CLEONOS_SYSCALL_WAITPID 42ULL
#define CLEONOS_SYSCALL_EXIT 43ULL
#define CLEONOS_SYSCALL_SLEEP_TICKS 44ULL
#define CLEONOS_SYSCALL_YIELD 45ULL
#define CLEONOS_SYSCALL_SHUTDOWN 46ULL
#define CLEONOS_SYSCALL_RESTART 47ULL
#define CLEONOS_SYSCALL_AUDIO_AVAILABLE 48ULL
#define CLEONOS_SYSCALL_AUDIO_PLAY_TONE 49ULL
#define CLEONOS_SYSCALL_AUDIO_STOP 50ULL
#define CLEONOS_SYSCALL_EXEC_PATHV 51ULL
#define CLEONOS_SYSCALL_SPAWN_PATHV 52ULL
#define CLEONOS_SYSCALL_PROC_ARGC 53ULL
#define CLEONOS_SYSCALL_PROC_ARGV 54ULL
#define CLEONOS_SYSCALL_PROC_ENVC 55ULL
#define CLEONOS_SYSCALL_PROC_ENV 56ULL
#define CLEONOS_SYSCALL_PROC_LAST_SIGNAL 57ULL
#define CLEONOS_SYSCALL_PROC_FAULT_VECTOR 58ULL
#define CLEONOS_SYSCALL_PROC_FAULT_ERROR 59ULL
#define CLEONOS_SYSCALL_PROC_FAULT_RIP 60ULL
#define CLEONOS_SYSCALL_PROC_COUNT 61ULL
#define CLEONOS_SYSCALL_PROC_PID_AT 62ULL
#define CLEONOS_SYSCALL_PROC_SNAPSHOT 63ULL
#define CLEONOS_SYSCALL_PROC_KILL 64ULL
#define CLEONOS_SYSCALL_KDBG_SYM 65ULL
#define CLEONOS_SYSCALL_KDBG_BT 66ULL
#define CLEONOS_SYSCALL_KDBG_REGS 67ULL
#define CLEONOS_SYSCALL_STATS_TOTAL 68ULL
#define CLEONOS_SYSCALL_STATS_ID_COUNT 69ULL
#define CLEONOS_SYSCALL_STATS_RECENT_WINDOW 70ULL
#define CLEONOS_SYSCALL_STATS_RECENT_ID 71ULL
#define CLEONOS_SYSCALL_FD_OPEN 72ULL
#define CLEONOS_SYSCALL_FD_READ 73ULL
#define CLEONOS_SYSCALL_FD_WRITE 74ULL
#define CLEONOS_SYSCALL_FD_CLOSE 75ULL
#define CLEONOS_SYSCALL_FD_DUP 76ULL
#define CLEONOS_SYSCALL_DL_OPEN 77ULL
#define CLEONOS_SYSCALL_DL_CLOSE 78ULL
#define CLEONOS_SYSCALL_DL_SYM 79ULL
@@ -155,86 +171,91 @@ typedef struct cleonos_fb_blit_req {
#define CLEONOS_SYSCALL_DISK_MOUNT_PATH 92ULL
#define CLEONOS_SYSCALL_DISK_READ_SECTOR 93ULL
#define CLEONOS_SYSCALL_DISK_WRITE_SECTOR 94ULL
u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
u64 cleonos_sys_log_write(const char *message, u64 length);
u64 cleonos_sys_timer_ticks(void);
u64 cleonos_sys_task_count(void);
u64 cleonos_sys_service_count(void);
u64 cleonos_sys_service_ready_count(void);
u64 cleonos_sys_context_switches(void);
u64 cleonos_sys_kelf_count(void);
u64 cleonos_sys_kelf_runs(void);
u64 cleonos_sys_fs_node_count(void);
u64 cleonos_sys_fs_child_count(const char *dir_path);
u64 cleonos_sys_fs_get_child_name(const char *dir_path, u64 index, char *out_name);
u64 cleonos_sys_fs_read(const char *path, char *out_buffer, u64 buffer_size);
u64 cleonos_sys_exec_path(const char *path);
u64 cleonos_sys_exec_pathv(const char *path, const char *argv_line, const char *env_line);
u64 cleonos_sys_exec_pathv_io(const char *path, const char *argv_line, const char *env_line, u64 stdin_fd,
u64 stdout_fd, u64 stderr_fd);
u64 cleonos_sys_exec_request_count(void);
u64 cleonos_sys_exec_success_count(void);
u64 cleonos_sys_user_shell_ready(void);
u64 cleonos_sys_user_exec_requested(void);
u64 cleonos_sys_user_launch_tries(void);
u64 cleonos_sys_user_launch_ok(void);
u64 cleonos_sys_user_launch_fail(void);
u64 cleonos_sys_tty_count(void);
u64 cleonos_sys_tty_active(void);
u64 cleonos_sys_tty_switch(u64 tty_index);
u64 cleonos_sys_tty_write(const char *text, u64 length);
u64 cleonos_sys_tty_write_char(char ch);
u64 cleonos_sys_kbd_get_char(void);
u64 cleonos_sys_fs_stat_type(const char *path);
u64 cleonos_sys_fs_stat_size(const char *path);
u64 cleonos_sys_fs_mkdir(const char *path);
u64 cleonos_sys_fs_write(const char *path, const char *data, u64 size);
u64 cleonos_sys_fs_append(const char *path, const char *data, u64 size);
u64 cleonos_sys_fs_remove(const char *path);
u64 cleonos_sys_log_journal_count(void);
u64 cleonos_sys_log_journal_read(u64 index_from_oldest, char *out_line, u64 out_size);
u64 cleonos_sys_kbd_buffered(void);
u64 cleonos_sys_kbd_pushed(void);
u64 cleonos_sys_kbd_popped(void);
u64 cleonos_sys_kbd_dropped(void);
u64 cleonos_sys_kbd_hotkey_switches(void);
u64 cleonos_sys_getpid(void);
u64 cleonos_sys_spawn_path(const char *path);
u64 cleonos_sys_spawn_pathv(const char *path, const char *argv_line, const char *env_line);
u64 cleonos_sys_wait_pid(u64 pid, u64 *out_status);
u64 cleonos_sys_exit(u64 status);
u64 cleonos_sys_sleep_ticks(u64 ticks);
u64 cleonos_sys_yield(void);
u64 cleonos_sys_shutdown(void);
u64 cleonos_sys_restart(void);
u64 cleonos_sys_audio_available(void);
u64 cleonos_sys_audio_play_tone(u64 hz, u64 ticks);
u64 cleonos_sys_audio_stop(void);
u64 cleonos_sys_proc_argc(void);
u64 cleonos_sys_proc_argv(u64 index, char *out_value, u64 out_size);
u64 cleonos_sys_proc_envc(void);
u64 cleonos_sys_proc_env(u64 index, char *out_value, u64 out_size);
u64 cleonos_sys_proc_last_signal(void);
u64 cleonos_sys_proc_fault_vector(void);
u64 cleonos_sys_proc_fault_error(void);
u64 cleonos_sys_proc_fault_rip(void);
u64 cleonos_sys_proc_count(void);
u64 cleonos_sys_proc_pid_at(u64 index, u64 *out_pid);
u64 cleonos_sys_proc_snapshot(u64 pid, cleonos_proc_snapshot *out_snapshot, u64 out_size);
u64 cleonos_sys_proc_kill(u64 pid, u64 signal);
u64 cleonos_sys_kdbg_sym(u64 addr, char *out_line, u64 out_size);
u64 cleonos_sys_kdbg_bt(u64 rbp, u64 rip, char *out_text, u64 out_size);
u64 cleonos_sys_kdbg_regs(char *out_text, u64 out_size);
u64 cleonos_sys_stats_total(void);
u64 cleonos_sys_stats_id_count(u64 id);
u64 cleonos_sys_stats_recent_window(void);
u64 cleonos_sys_stats_recent_id(u64 id);
u64 cleonos_sys_fd_open(const char *path, u64 flags, u64 mode);
u64 cleonos_sys_fd_read(u64 fd, void *out_buffer, u64 size);
u64 cleonos_sys_fd_write(u64 fd, const void *buffer, u64 size);
u64 cleonos_sys_fd_close(u64 fd);
u64 cleonos_sys_fd_dup(u64 fd);
#define CLEONOS_SYSCALL_NET_AVAILABLE 95ULL
#define CLEONOS_SYSCALL_NET_IPV4_ADDR 96ULL
#define CLEONOS_SYSCALL_NET_PING 97ULL
#define CLEONOS_SYSCALL_NET_UDP_SEND 98ULL
#define CLEONOS_SYSCALL_NET_UDP_RECV 99ULL
u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
u64 cleonos_sys_log_write(const char *message, u64 length);
u64 cleonos_sys_timer_ticks(void);
u64 cleonos_sys_task_count(void);
u64 cleonos_sys_service_count(void);
u64 cleonos_sys_service_ready_count(void);
u64 cleonos_sys_context_switches(void);
u64 cleonos_sys_kelf_count(void);
u64 cleonos_sys_kelf_runs(void);
u64 cleonos_sys_fs_node_count(void);
u64 cleonos_sys_fs_child_count(const char *dir_path);
u64 cleonos_sys_fs_get_child_name(const char *dir_path, u64 index, char *out_name);
u64 cleonos_sys_fs_read(const char *path, char *out_buffer, u64 buffer_size);
u64 cleonos_sys_exec_path(const char *path);
u64 cleonos_sys_exec_pathv(const char *path, const char *argv_line, const char *env_line);
u64 cleonos_sys_exec_pathv_io(const char *path, const char *argv_line, const char *env_line, u64 stdin_fd,
u64 stdout_fd, u64 stderr_fd);
u64 cleonos_sys_exec_request_count(void);
u64 cleonos_sys_exec_success_count(void);
u64 cleonos_sys_user_shell_ready(void);
u64 cleonos_sys_user_exec_requested(void);
u64 cleonos_sys_user_launch_tries(void);
u64 cleonos_sys_user_launch_ok(void);
u64 cleonos_sys_user_launch_fail(void);
u64 cleonos_sys_tty_count(void);
u64 cleonos_sys_tty_active(void);
u64 cleonos_sys_tty_switch(u64 tty_index);
u64 cleonos_sys_tty_write(const char *text, u64 length);
u64 cleonos_sys_tty_write_char(char ch);
u64 cleonos_sys_kbd_get_char(void);
u64 cleonos_sys_fs_stat_type(const char *path);
u64 cleonos_sys_fs_stat_size(const char *path);
u64 cleonos_sys_fs_mkdir(const char *path);
u64 cleonos_sys_fs_write(const char *path, const char *data, u64 size);
u64 cleonos_sys_fs_append(const char *path, const char *data, u64 size);
u64 cleonos_sys_fs_remove(const char *path);
u64 cleonos_sys_log_journal_count(void);
u64 cleonos_sys_log_journal_read(u64 index_from_oldest, char *out_line, u64 out_size);
u64 cleonos_sys_kbd_buffered(void);
u64 cleonos_sys_kbd_pushed(void);
u64 cleonos_sys_kbd_popped(void);
u64 cleonos_sys_kbd_dropped(void);
u64 cleonos_sys_kbd_hotkey_switches(void);
u64 cleonos_sys_getpid(void);
u64 cleonos_sys_spawn_path(const char *path);
u64 cleonos_sys_spawn_pathv(const char *path, const char *argv_line, const char *env_line);
u64 cleonos_sys_wait_pid(u64 pid, u64 *out_status);
u64 cleonos_sys_exit(u64 status);
u64 cleonos_sys_sleep_ticks(u64 ticks);
u64 cleonos_sys_yield(void);
u64 cleonos_sys_shutdown(void);
u64 cleonos_sys_restart(void);
u64 cleonos_sys_audio_available(void);
u64 cleonos_sys_audio_play_tone(u64 hz, u64 ticks);
u64 cleonos_sys_audio_stop(void);
u64 cleonos_sys_proc_argc(void);
u64 cleonos_sys_proc_argv(u64 index, char *out_value, u64 out_size);
u64 cleonos_sys_proc_envc(void);
u64 cleonos_sys_proc_env(u64 index, char *out_value, u64 out_size);
u64 cleonos_sys_proc_last_signal(void);
u64 cleonos_sys_proc_fault_vector(void);
u64 cleonos_sys_proc_fault_error(void);
u64 cleonos_sys_proc_fault_rip(void);
u64 cleonos_sys_proc_count(void);
u64 cleonos_sys_proc_pid_at(u64 index, u64 *out_pid);
u64 cleonos_sys_proc_snapshot(u64 pid, cleonos_proc_snapshot *out_snapshot, u64 out_size);
u64 cleonos_sys_proc_kill(u64 pid, u64 signal);
u64 cleonos_sys_kdbg_sym(u64 addr, char *out_line, u64 out_size);
u64 cleonos_sys_kdbg_bt(u64 rbp, u64 rip, char *out_text, u64 out_size);
u64 cleonos_sys_kdbg_regs(char *out_text, u64 out_size);
u64 cleonos_sys_stats_total(void);
u64 cleonos_sys_stats_id_count(u64 id);
u64 cleonos_sys_stats_recent_window(void);
u64 cleonos_sys_stats_recent_id(u64 id);
u64 cleonos_sys_fd_open(const char *path, u64 flags, u64 mode);
u64 cleonos_sys_fd_read(u64 fd, void *out_buffer, u64 size);
u64 cleonos_sys_fd_write(u64 fd, const void *buffer, u64 size);
u64 cleonos_sys_fd_close(u64 fd);
u64 cleonos_sys_fd_dup(u64 fd);
u64 cleonos_sys_dl_open(const char *path);
u64 cleonos_sys_dl_close(u64 handle);
u64 cleonos_sys_dl_sym(u64 handle, const char *symbol);
@@ -252,5 +273,10 @@ u64 cleonos_sys_disk_mounted(void);
u64 cleonos_sys_disk_mount_path(char *out_path, u64 out_size);
u64 cleonos_sys_disk_read_sector(u64 lba, void *out_sector);
u64 cleonos_sys_disk_write_sector(u64 lba, const void *sector_data);
u64 cleonos_sys_net_available(void);
u64 cleonos_sys_net_ipv4_addr(void);
u64 cleonos_sys_net_ping(u64 dst_ipv4_be, u64 poll_budget);
u64 cleonos_sys_net_udp_send(const cleonos_net_udp_send_req *req);
u64 cleonos_sys_net_udp_recv(cleonos_net_udp_recv_req *req);
#endif

View File

@@ -47,6 +47,18 @@ long long llabs(long long value) {
return (value < 0LL) ? -value : value;
}
double fabs(double value) {
return (value < 0.0) ? -value : value;
}
float fabsf(float value) {
return (value < 0.0f) ? -value : value;
}
long double fabsl(long double value) {
return (value < 0.0L) ? -value : value;
}
int atoi(const char *text) {
return (int)strtol(text, (char **)0, 10);
}

View File

@@ -1,357 +1,357 @@
#include <cleonos_syscall.h>
u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2) {
u64 ret;
__asm__ volatile("int $0x80" : "=a"(ret) : "a"(id), "b"(arg0), "c"(arg1), "d"(arg2) : "memory");
return ret;
}
u64 cleonos_sys_log_write(const char *message, u64 length) {
return cleonos_syscall(CLEONOS_SYSCALL_LOG_WRITE, (u64)message, length, 0ULL);
}
u64 cleonos_sys_timer_ticks(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TIMER_TICKS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_task_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TASK_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_service_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_SERVICE_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_service_ready_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_SERVICE_READY_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_context_switches(void) {
return cleonos_syscall(CLEONOS_SYSCALL_CONTEXT_SWITCHES, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kelf_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KELF_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kelf_runs(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KELF_RUNS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_node_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_NODE_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_child_count(const char *dir_path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_CHILD_COUNT, (u64)dir_path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_get_child_name(const char *dir_path, u64 index, char *out_name) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_GET_CHILD_NAME, (u64)dir_path, index, (u64)out_name);
}
u64 cleonos_sys_fs_read(const char *path, char *out_buffer, u64 buffer_size) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_READ, (u64)path, (u64)out_buffer, buffer_size);
}
u64 cleonos_sys_exec_path(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATH, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_exec_pathv(const char *path, const char *argv_line, const char *env_line) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATHV, (u64)path, (u64)argv_line, (u64)env_line);
}
struct cleonos_exec_pathv_io_req {
u64 env_line_ptr;
u64 stdin_fd;
u64 stdout_fd;
u64 stderr_fd;
};
u64 cleonos_sys_exec_pathv_io(const char *path, const char *argv_line, const char *env_line, u64 stdin_fd,
u64 stdout_fd, u64 stderr_fd) {
struct cleonos_exec_pathv_io_req req;
req.env_line_ptr = (u64)env_line;
req.stdin_fd = stdin_fd;
req.stdout_fd = stdout_fd;
req.stderr_fd = stderr_fd;
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATHV_IO, (u64)path, (u64)argv_line, (u64)&req);
}
u64 cleonos_sys_exec_request_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_REQUESTS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_exec_success_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_SUCCESS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_shell_ready(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_SHELL_READY, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_exec_requested(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_EXEC_REQUESTED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_launch_tries(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_TRIES, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_launch_ok(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_OK, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_launch_fail(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_FAIL, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_active(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_ACTIVE, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_switch(u64 tty_index) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_SWITCH, tty_index, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_write(const char *text, u64 length) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_WRITE, (u64)text, length, 0ULL);
}
u64 cleonos_sys_tty_write_char(char ch) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_WRITE_CHAR, (u64)(unsigned char)ch, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_get_char(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_GET_CHAR, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_stat_type(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_STAT_TYPE, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_stat_size(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_STAT_SIZE, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_mkdir(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_MKDIR, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_write(const char *path, const char *data, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_WRITE, (u64)path, (u64)data, size);
}
u64 cleonos_sys_fs_append(const char *path, const char *data, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_APPEND, (u64)path, (u64)data, size);
}
u64 cleonos_sys_fs_remove(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_REMOVE, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_log_journal_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_LOG_JOURNAL_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_log_journal_read(u64 index_from_oldest, char *out_line, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_LOG_JOURNAL_READ, index_from_oldest, (u64)out_line, out_size);
}
u64 cleonos_sys_kbd_buffered(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_BUFFERED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_pushed(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_PUSHED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_popped(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_POPPED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_dropped(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_DROPPED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_hotkey_switches(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_HOTKEY_SWITCHES, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_getpid(void) {
return cleonos_syscall(CLEONOS_SYSCALL_GETPID, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_spawn_path(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_SPAWN_PATH, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_spawn_pathv(const char *path, const char *argv_line, const char *env_line) {
return cleonos_syscall(CLEONOS_SYSCALL_SPAWN_PATHV, (u64)path, (u64)argv_line, (u64)env_line);
}
u64 cleonos_sys_wait_pid(u64 pid, u64 *out_status) {
return cleonos_syscall(CLEONOS_SYSCALL_WAITPID, pid, (u64)out_status, 0ULL);
}
u64 cleonos_sys_exit(u64 status) {
return cleonos_syscall(CLEONOS_SYSCALL_EXIT, status, 0ULL, 0ULL);
}
u64 cleonos_sys_sleep_ticks(u64 ticks) {
return cleonos_syscall(CLEONOS_SYSCALL_SLEEP_TICKS, ticks, 0ULL, 0ULL);
}
u64 cleonos_sys_yield(void) {
return cleonos_syscall(CLEONOS_SYSCALL_YIELD, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_shutdown(void) {
return cleonos_syscall(CLEONOS_SYSCALL_SHUTDOWN, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_restart(void) {
return cleonos_syscall(CLEONOS_SYSCALL_RESTART, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_audio_available(void) {
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_AVAILABLE, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_audio_play_tone(u64 hz, u64 ticks) {
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_PLAY_TONE, hz, ticks, 0ULL);
}
u64 cleonos_sys_audio_stop(void) {
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_STOP, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_argc(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ARGC, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_argv(u64 index, char *out_value, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ARGV, index, (u64)out_value, out_size);
}
u64 cleonos_sys_proc_envc(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ENVC, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_env(u64 index, char *out_value, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ENV, index, (u64)out_value, out_size);
}
u64 cleonos_sys_proc_last_signal(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_LAST_SIGNAL, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_fault_vector(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_VECTOR, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_fault_error(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_ERROR, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_fault_rip(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_RIP, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_pid_at(u64 index, u64 *out_pid) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_PID_AT, index, (u64)out_pid, 0ULL);
}
u64 cleonos_sys_proc_snapshot(u64 pid, cleonos_proc_snapshot *out_snapshot, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_SNAPSHOT, pid, (u64)out_snapshot, out_size);
}
u64 cleonos_sys_proc_kill(u64 pid, u64 signal) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_KILL, pid, signal, 0ULL);
}
struct cleonos_kdbg_bt_req {
u64 rbp;
u64 rip;
u64 out_ptr;
u64 out_size;
};
u64 cleonos_sys_kdbg_sym(u64 addr, char *out_line, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_SYM, addr, (u64)out_line, out_size);
}
u64 cleonos_sys_kdbg_bt(u64 rbp, u64 rip, char *out_text, u64 out_size) {
struct cleonos_kdbg_bt_req req;
req.rbp = rbp;
req.rip = rip;
req.out_ptr = (u64)out_text;
req.out_size = out_size;
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_BT, (u64)&req, 0ULL, 0ULL);
}
u64 cleonos_sys_kdbg_regs(char *out_text, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_REGS, (u64)out_text, out_size, 0ULL);
}
u64 cleonos_sys_stats_total(void) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_TOTAL, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_stats_id_count(u64 id) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_ID_COUNT, id, 0ULL, 0ULL);
}
u64 cleonos_sys_stats_recent_window(void) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_RECENT_WINDOW, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_stats_recent_id(u64 id) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_RECENT_ID, id, 0ULL, 0ULL);
}
u64 cleonos_sys_fd_open(const char *path, u64 flags, u64 mode) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_OPEN, (u64)path, flags, mode);
}
u64 cleonos_sys_fd_read(u64 fd, void *out_buffer, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_READ, fd, (u64)out_buffer, size);
}
u64 cleonos_sys_fd_write(u64 fd, const void *buffer, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_WRITE, fd, (u64)buffer, size);
}
u64 cleonos_sys_fd_close(u64 fd) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_CLOSE, fd, 0ULL, 0ULL);
}
u64 cleonos_sys_fd_dup(u64 fd) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_DUP, fd, 0ULL, 0ULL);
}
u64 cleonos_sys_dl_open(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_DL_OPEN, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_dl_close(u64 handle) {
return cleonos_syscall(CLEONOS_SYSCALL_DL_CLOSE, handle, 0ULL, 0ULL);
}
#include <cleonos_syscall.h>
u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2) {
u64 ret;
__asm__ volatile("int $0x80" : "=a"(ret) : "a"(id), "b"(arg0), "c"(arg1), "d"(arg2) : "memory");
return ret;
}
u64 cleonos_sys_log_write(const char *message, u64 length) {
return cleonos_syscall(CLEONOS_SYSCALL_LOG_WRITE, (u64)message, length, 0ULL);
}
u64 cleonos_sys_timer_ticks(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TIMER_TICKS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_task_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TASK_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_service_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_SERVICE_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_service_ready_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_SERVICE_READY_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_context_switches(void) {
return cleonos_syscall(CLEONOS_SYSCALL_CONTEXT_SWITCHES, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kelf_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KELF_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kelf_runs(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KELF_RUNS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_node_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_NODE_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_child_count(const char *dir_path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_CHILD_COUNT, (u64)dir_path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_get_child_name(const char *dir_path, u64 index, char *out_name) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_GET_CHILD_NAME, (u64)dir_path, index, (u64)out_name);
}
u64 cleonos_sys_fs_read(const char *path, char *out_buffer, u64 buffer_size) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_READ, (u64)path, (u64)out_buffer, buffer_size);
}
u64 cleonos_sys_exec_path(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATH, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_exec_pathv(const char *path, const char *argv_line, const char *env_line) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATHV, (u64)path, (u64)argv_line, (u64)env_line);
}
struct cleonos_exec_pathv_io_req {
u64 env_line_ptr;
u64 stdin_fd;
u64 stdout_fd;
u64 stderr_fd;
};
u64 cleonos_sys_exec_pathv_io(const char *path, const char *argv_line, const char *env_line, u64 stdin_fd,
u64 stdout_fd, u64 stderr_fd) {
struct cleonos_exec_pathv_io_req req;
req.env_line_ptr = (u64)env_line;
req.stdin_fd = stdin_fd;
req.stdout_fd = stdout_fd;
req.stderr_fd = stderr_fd;
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_PATHV_IO, (u64)path, (u64)argv_line, (u64)&req);
}
u64 cleonos_sys_exec_request_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_REQUESTS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_exec_success_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_EXEC_SUCCESS, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_shell_ready(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_SHELL_READY, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_exec_requested(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_EXEC_REQUESTED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_launch_tries(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_TRIES, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_launch_ok(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_OK, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_user_launch_fail(void) {
return cleonos_syscall(CLEONOS_SYSCALL_USER_LAUNCH_FAIL, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_active(void) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_ACTIVE, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_switch(u64 tty_index) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_SWITCH, tty_index, 0ULL, 0ULL);
}
u64 cleonos_sys_tty_write(const char *text, u64 length) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_WRITE, (u64)text, length, 0ULL);
}
u64 cleonos_sys_tty_write_char(char ch) {
return cleonos_syscall(CLEONOS_SYSCALL_TTY_WRITE_CHAR, (u64)(unsigned char)ch, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_get_char(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_GET_CHAR, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_stat_type(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_STAT_TYPE, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_stat_size(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_STAT_SIZE, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_mkdir(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_MKDIR, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_fs_write(const char *path, const char *data, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_WRITE, (u64)path, (u64)data, size);
}
u64 cleonos_sys_fs_append(const char *path, const char *data, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_APPEND, (u64)path, (u64)data, size);
}
u64 cleonos_sys_fs_remove(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_FS_REMOVE, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_log_journal_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_LOG_JOURNAL_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_log_journal_read(u64 index_from_oldest, char *out_line, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_LOG_JOURNAL_READ, index_from_oldest, (u64)out_line, out_size);
}
u64 cleonos_sys_kbd_buffered(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_BUFFERED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_pushed(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_PUSHED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_popped(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_POPPED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_dropped(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_DROPPED, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_kbd_hotkey_switches(void) {
return cleonos_syscall(CLEONOS_SYSCALL_KBD_HOTKEY_SWITCHES, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_getpid(void) {
return cleonos_syscall(CLEONOS_SYSCALL_GETPID, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_spawn_path(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_SPAWN_PATH, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_spawn_pathv(const char *path, const char *argv_line, const char *env_line) {
return cleonos_syscall(CLEONOS_SYSCALL_SPAWN_PATHV, (u64)path, (u64)argv_line, (u64)env_line);
}
u64 cleonos_sys_wait_pid(u64 pid, u64 *out_status) {
return cleonos_syscall(CLEONOS_SYSCALL_WAITPID, pid, (u64)out_status, 0ULL);
}
u64 cleonos_sys_exit(u64 status) {
return cleonos_syscall(CLEONOS_SYSCALL_EXIT, status, 0ULL, 0ULL);
}
u64 cleonos_sys_sleep_ticks(u64 ticks) {
return cleonos_syscall(CLEONOS_SYSCALL_SLEEP_TICKS, ticks, 0ULL, 0ULL);
}
u64 cleonos_sys_yield(void) {
return cleonos_syscall(CLEONOS_SYSCALL_YIELD, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_shutdown(void) {
return cleonos_syscall(CLEONOS_SYSCALL_SHUTDOWN, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_restart(void) {
return cleonos_syscall(CLEONOS_SYSCALL_RESTART, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_audio_available(void) {
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_AVAILABLE, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_audio_play_tone(u64 hz, u64 ticks) {
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_PLAY_TONE, hz, ticks, 0ULL);
}
u64 cleonos_sys_audio_stop(void) {
return cleonos_syscall(CLEONOS_SYSCALL_AUDIO_STOP, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_argc(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ARGC, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_argv(u64 index, char *out_value, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ARGV, index, (u64)out_value, out_size);
}
u64 cleonos_sys_proc_envc(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ENVC, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_env(u64 index, char *out_value, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_ENV, index, (u64)out_value, out_size);
}
u64 cleonos_sys_proc_last_signal(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_LAST_SIGNAL, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_fault_vector(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_VECTOR, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_fault_error(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_ERROR, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_fault_rip(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_FAULT_RIP, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_count(void) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_COUNT, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_proc_pid_at(u64 index, u64 *out_pid) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_PID_AT, index, (u64)out_pid, 0ULL);
}
u64 cleonos_sys_proc_snapshot(u64 pid, cleonos_proc_snapshot *out_snapshot, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_SNAPSHOT, pid, (u64)out_snapshot, out_size);
}
u64 cleonos_sys_proc_kill(u64 pid, u64 signal) {
return cleonos_syscall(CLEONOS_SYSCALL_PROC_KILL, pid, signal, 0ULL);
}
struct cleonos_kdbg_bt_req {
u64 rbp;
u64 rip;
u64 out_ptr;
u64 out_size;
};
u64 cleonos_sys_kdbg_sym(u64 addr, char *out_line, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_SYM, addr, (u64)out_line, out_size);
}
u64 cleonos_sys_kdbg_bt(u64 rbp, u64 rip, char *out_text, u64 out_size) {
struct cleonos_kdbg_bt_req req;
req.rbp = rbp;
req.rip = rip;
req.out_ptr = (u64)out_text;
req.out_size = out_size;
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_BT, (u64)&req, 0ULL, 0ULL);
}
u64 cleonos_sys_kdbg_regs(char *out_text, u64 out_size) {
return cleonos_syscall(CLEONOS_SYSCALL_KDBG_REGS, (u64)out_text, out_size, 0ULL);
}
u64 cleonos_sys_stats_total(void) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_TOTAL, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_stats_id_count(u64 id) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_ID_COUNT, id, 0ULL, 0ULL);
}
u64 cleonos_sys_stats_recent_window(void) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_RECENT_WINDOW, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_stats_recent_id(u64 id) {
return cleonos_syscall(CLEONOS_SYSCALL_STATS_RECENT_ID, id, 0ULL, 0ULL);
}
u64 cleonos_sys_fd_open(const char *path, u64 flags, u64 mode) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_OPEN, (u64)path, flags, mode);
}
u64 cleonos_sys_fd_read(u64 fd, void *out_buffer, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_READ, fd, (u64)out_buffer, size);
}
u64 cleonos_sys_fd_write(u64 fd, const void *buffer, u64 size) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_WRITE, fd, (u64)buffer, size);
}
u64 cleonos_sys_fd_close(u64 fd) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_CLOSE, fd, 0ULL, 0ULL);
}
u64 cleonos_sys_fd_dup(u64 fd) {
return cleonos_syscall(CLEONOS_SYSCALL_FD_DUP, fd, 0ULL, 0ULL);
}
u64 cleonos_sys_dl_open(const char *path) {
return cleonos_syscall(CLEONOS_SYSCALL_DL_OPEN, (u64)path, 0ULL, 0ULL);
}
u64 cleonos_sys_dl_close(u64 handle) {
return cleonos_syscall(CLEONOS_SYSCALL_DL_CLOSE, handle, 0ULL, 0ULL);
}
u64 cleonos_sys_dl_sym(u64 handle, const char *symbol) {
return cleonos_syscall(CLEONOS_SYSCALL_DL_SYM, handle, (u64)symbol, 0ULL);
}
@@ -411,3 +411,23 @@ u64 cleonos_sys_disk_read_sector(u64 lba, void *out_sector) {
u64 cleonos_sys_disk_write_sector(u64 lba, const void *sector_data) {
return cleonos_syscall(CLEONOS_SYSCALL_DISK_WRITE_SECTOR, lba, (u64)sector_data, 0ULL);
}
u64 cleonos_sys_net_available(void) {
return cleonos_syscall(CLEONOS_SYSCALL_NET_AVAILABLE, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_net_ipv4_addr(void) {
return cleonos_syscall(CLEONOS_SYSCALL_NET_IPV4_ADDR, 0ULL, 0ULL, 0ULL);
}
u64 cleonos_sys_net_ping(u64 dst_ipv4_be, u64 poll_budget) {
return cleonos_syscall(CLEONOS_SYSCALL_NET_PING, dst_ipv4_be, poll_budget, 0ULL);
}
u64 cleonos_sys_net_udp_send(const cleonos_net_udp_send_req *req) {
return cleonos_syscall(CLEONOS_SYSCALL_NET_UDP_SEND, (u64)req, 0ULL, 0ULL);
}
u64 cleonos_sys_net_udp_recv(cleonos_net_udp_recv_req *req) {
return cleonos_syscall(CLEONOS_SYSCALL_NET_UDP_RECV, (u64)req, 0ULL, 0ULL);
}

2
clks

Submodule clks updated: 82ef5fd38e...f7c89a3420

View File

@@ -1,37 +1,37 @@
# CLeonOS Syscall 文档
本文档描述 CLeonOS 用户态通过 `int 0x80` 进入内核的 syscall ABI 与当前实现行为。
## 1. 调用约定x86_64
用户态统一通过:
```c
u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
```
寄存器约定:
- `rax` = syscall id
- `rbx` = arg0
- `rcx` = arg1
- `rdx` = arg2
- 返回值在 `rax`
中断向量:
- `int 0x80`
头文件位置:
- `cleonos/c/include/cleonos_syscall.h`
# CLeonOS Syscall 文档
本文档描述 CLeonOS 用户态通过 `int 0x80` 进入内核的 syscall ABI 与当前实现行为。
## 1. 调用约定x86_64
用户态统一通过:
```c
u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
```
寄存器约定:
- `rax` = syscall id
- `rbx` = arg0
- `rcx` = arg1
- `rdx` = arg2
- 返回值在 `rax`
中断向量:
- `int 0x80`
头文件位置:
- `cleonos/c/include/cleonos_syscall.h`
内核分发位置:
- `clks/kernel/runtime/syscall.c`
## 2. 全局返回规则
## 2. 全局返回规则
- 成功时通常返回非负值(如长度、计数、状态)。
- 失败时多数接口返回 `0xFFFFFFFFFFFFFFFF`(即 `u64``-1`)。
- 部分接口失败返回 `0`(例如 `FS_READ` / `FS_WRITE` / `FS_APPEND` / `FS_REMOVE` / `LOG_JOURNAL_READ`)。
@@ -58,19 +58,19 @@ u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
- `SIGTERM` = `15`
- `SIGCONT` = `18`
- `SIGSTOP` = `19`
## 3. 当前实现中的长度/路径限制
## 3. 当前实现中的长度/路径限制
以下限制由内核 `clks/kernel/runtime/syscall.c` 当前实现决定:
- 日志写入 `LOG_WRITE`:最大拷贝 `191` 字节。
- 日志写入 `LOG_WRITE`:最大拷贝 `191` 字节。
- TTY 文本写入 `TTY_WRITE`:最大拷贝 `2048` 字节。
- 文件读取 `FS_READ`:最多读取 `min(file_size, buffer_size)` 字节。
- 文件读取 `FS_READ`:最多读取 `min(file_size, buffer_size)` 字节。
- 文件写入 `FS_WRITE` / `FS_APPEND`:内核按 `65536` 字节分块搬运;这是实现分块大小,不是文件大小上限。
- log journal 行读取缓冲:`256` 字节。
- 路径缓冲上限:`192` 字节(包含 `\0`)。
- 文件名输出上限:`96` 字节(与 `CLEONOS_FS_NAME_MAX` 对齐)。
- log journal 行读取缓冲:`256` 字节。
- 路径缓冲上限:`192` 字节(包含 `\0`)。
- 文件名输出上限:`96` 字节(与 `CLEONOS_FS_NAME_MAX` 对齐)。
文件系统写入类 syscall 的权限限制:
- `FS_MKDIR` / `FS_WRITE` / `FS_APPEND` / `FS_REMOVE` 仅允许 `/temp` 树下路径,或已挂载磁盘路径树下(默认挂载点通常为 `/temp/disk`)。
@@ -82,328 +82,328 @@ u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
- `/proc/list`:所有进程列表文本
- `/proc/<pid>`:指定 PID 快照文本
- `/proc` 为只读;写入类 syscall 不支持。
## 4. Syscall 列表0~94
### 0 `CLEONOS_SYSCALL_LOG_WRITE`
- 参数:
- `arg0`: `const char *message`
- `arg1`: `u64 length`
- 返回:实际写入长度
- 说明写入内核日志通道tag 为 `SYSCALL`),长度会被截断到 191。
### 1 `CLEONOS_SYSCALL_TIMER_TICKS`
- 参数:无
- 返回:系统 timer tick 计数
### 2 `CLEONOS_SYSCALL_TASK_COUNT`
- 参数:无
- 返回:任务总数
### 3 `CLEONOS_SYSCALL_CUR_TASK`
- 参数:无
- 返回:当前任务 ID
### 4 `CLEONOS_SYSCALL_SERVICE_COUNT`
- 参数:无
- 返回:服务总数
### 5 `CLEONOS_SYSCALL_SERVICE_READY_COUNT`
- 参数:无
- 返回ready 服务数
### 6 `CLEONOS_SYSCALL_CONTEXT_SWITCHES`
- 参数:无
- 返回:上下文切换计数
### 7 `CLEONOS_SYSCALL_KELF_COUNT`
- 参数:无
- 返回:内核态 ELF 应用计数
### 8 `CLEONOS_SYSCALL_KELF_RUNS`
- 参数:无
- 返回:内核态 ELF 累计运行次数
### 9 `CLEONOS_SYSCALL_FS_NODE_COUNT`
- 参数:无
- 返回VFS 节点总数
## 4. Syscall 列表0~99
### 0 `CLEONOS_SYSCALL_LOG_WRITE`
- 参数:
- `arg0`: `const char *message`
- `arg1`: `u64 length`
- 返回:实际写入长度
- 说明写入内核日志通道tag 为 `SYSCALL`),长度会被截断到 191。
### 1 `CLEONOS_SYSCALL_TIMER_TICKS`
- 参数:无
- 返回:系统 timer tick 计数
### 2 `CLEONOS_SYSCALL_TASK_COUNT`
- 参数:无
- 返回:任务总数
### 3 `CLEONOS_SYSCALL_CUR_TASK`
- 参数:无
- 返回:当前任务 ID
### 4 `CLEONOS_SYSCALL_SERVICE_COUNT`
- 参数:无
- 返回:服务总数
### 5 `CLEONOS_SYSCALL_SERVICE_READY_COUNT`
- 参数:无
- 返回ready 服务数
### 6 `CLEONOS_SYSCALL_CONTEXT_SWITCHES`
- 参数:无
- 返回:上下文切换计数
### 7 `CLEONOS_SYSCALL_KELF_COUNT`
- 参数:无
- 返回:内核态 ELF 应用计数
### 8 `CLEONOS_SYSCALL_KELF_RUNS`
- 参数:无
- 返回:内核态 ELF 累计运行次数
### 9 `CLEONOS_SYSCALL_FS_NODE_COUNT`
- 参数:无
- 返回VFS 节点总数
### 10 `CLEONOS_SYSCALL_FS_CHILD_COUNT`
- 参数:
- `arg0`: `const char *dir_path`
- 返回:子节点数量
- 说明:当 `dir_path=/proc` 时,返回 `2 + proc_count``self``list`、PID 子项)。
### 11 `CLEONOS_SYSCALL_FS_GET_CHILD_NAME`
- 参数:
- `arg0`: `const char *dir_path`
- `arg1`: `u64 index`
- 参数:
- `arg0`: `const char *dir_path`
- `arg1`: `u64 index`
- `arg2`: `char *out_name`
- 返回:成功 `1`,失败 `0`
- 说明:最多写入 96 字节(含终止符)。
- 说明:当 `dir_path=/proc` 时,`index=0/1` 分别为 `self/list`,后续索引为 PID 文本。
### 12 `CLEONOS_SYSCALL_FS_READ`
- 参数:
- `arg0`: `const char *path`
- `arg1`: `char *out_buffer`
- 参数:
- `arg0`: `const char *path`
- `arg1`: `char *out_buffer`
- `arg2`: `u64 buffer_size`
- 返回:实际读取字节数,失败/文件空返回 `0`
- 说明:不会自动追加 `\0`,调用方应自行处理文本终止。
- 说明:支持读取 `/proc/self``/proc/list``/proc/<pid>`
### 13 `CLEONOS_SYSCALL_EXEC_PATH`
- 参数:
- `arg0`: `const char *path`
- 返回:
- `-1`:请求失败
- 其他:由内核执行器返回状态(通常 `0` 表示 accepted
### 14 `CLEONOS_SYSCALL_EXEC_REQUESTS`
- 参数:无
- 返回:执行请求累计数
### 15 `CLEONOS_SYSCALL_EXEC_SUCCESS`
- 参数:无
- 返回:执行成功累计数
### 16 `CLEONOS_SYSCALL_USER_SHELL_READY`
- 参数:无
- 返回:用户 shell ready1/0
### 17 `CLEONOS_SYSCALL_USER_EXEC_REQUESTED`
- 参数:无
- 返回:是否发起过用户侧 exec 请求1/0
### 18 `CLEONOS_SYSCALL_USER_LAUNCH_TRIES`
- 参数:无
- 返回:用户态启动尝试次数
### 19 `CLEONOS_SYSCALL_USER_LAUNCH_OK`
- 参数:无
- 返回:用户态启动成功次数
### 20 `CLEONOS_SYSCALL_USER_LAUNCH_FAIL`
- 参数:无
- 返回:用户态启动失败次数
### 21 `CLEONOS_SYSCALL_TTY_COUNT`
- 参数:无
- 返回TTY 总数
### 22 `CLEONOS_SYSCALL_TTY_ACTIVE`
- 参数:无
- 返回:当前 active TTY 索引
### 23 `CLEONOS_SYSCALL_TTY_SWITCH`
- 参数:
- `arg0`: `u64 tty_index`
- 返回:切换后的 active TTY 索引
### 24 `CLEONOS_SYSCALL_TTY_WRITE`
- 参数:
- `arg0`: `const char *text`
- `arg1`: `u64 length`
- 返回:实际写入长度
- 说明:长度会被截断到 512。
### 25 `CLEONOS_SYSCALL_TTY_WRITE_CHAR`
- 参数:
- `arg0`: `u64 ch`(低 8 位有效)
- 返回:当前实现固定返回 `1`
### 26 `CLEONOS_SYSCALL_KBD_GET_CHAR`
- 参数:无
- 返回:
- 无输入时 `-1`
- 有输入时返回字符值(低 8 位;按当前进程/TTY 上下文读取)
### 13 `CLEONOS_SYSCALL_EXEC_PATH`
- 参数:
- `arg0`: `const char *path`
- 返回:
- `-1`:请求失败
- 其他:由内核执行器返回状态(通常 `0` 表示 accepted
### 14 `CLEONOS_SYSCALL_EXEC_REQUESTS`
- 参数:无
- 返回:执行请求累计数
### 15 `CLEONOS_SYSCALL_EXEC_SUCCESS`
- 参数:无
- 返回:执行成功累计数
### 16 `CLEONOS_SYSCALL_USER_SHELL_READY`
- 参数:无
- 返回:用户 shell ready1/0
### 17 `CLEONOS_SYSCALL_USER_EXEC_REQUESTED`
- 参数:无
- 返回:是否发起过用户侧 exec 请求1/0
### 18 `CLEONOS_SYSCALL_USER_LAUNCH_TRIES`
- 参数:无
- 返回:用户态启动尝试次数
### 19 `CLEONOS_SYSCALL_USER_LAUNCH_OK`
- 参数:无
- 返回:用户态启动成功次数
### 20 `CLEONOS_SYSCALL_USER_LAUNCH_FAIL`
- 参数:无
- 返回:用户态启动失败次数
### 21 `CLEONOS_SYSCALL_TTY_COUNT`
- 参数:无
- 返回TTY 总数
### 22 `CLEONOS_SYSCALL_TTY_ACTIVE`
- 参数:无
- 返回:当前 active TTY 索引
### 23 `CLEONOS_SYSCALL_TTY_SWITCH`
- 参数:
- `arg0`: `u64 tty_index`
- 返回:切换后的 active TTY 索引
### 24 `CLEONOS_SYSCALL_TTY_WRITE`
- 参数:
- `arg0`: `const char *text`
- `arg1`: `u64 length`
- 返回:实际写入长度
- 说明:长度会被截断到 512。
### 25 `CLEONOS_SYSCALL_TTY_WRITE_CHAR`
- 参数:
- `arg0`: `u64 ch`(低 8 位有效)
- 返回:当前实现固定返回 `1`
### 26 `CLEONOS_SYSCALL_KBD_GET_CHAR`
- 参数:无
- 返回:
- 无输入时 `-1`
- 有输入时返回字符值(低 8 位;按当前进程/TTY 上下文读取)
### 27 `CLEONOS_SYSCALL_FS_STAT_TYPE`
- 参数:
- `arg0`: `const char *path`
- 返回:`1=FILE``2=DIR`,失败 `-1`
- 说明:`/proc` 返回目录,`/proc/self``/proc/list``/proc/<pid>` 返回文件。
### 28 `CLEONOS_SYSCALL_FS_STAT_SIZE`
- 参数:
- `arg0`: `const char *path`
- 返回:文件大小;目录通常为 `0`;失败 `-1`
- 说明:`/proc/*` 文件大小按生成文本长度返回。
### 29 `CLEONOS_SYSCALL_FS_MKDIR`
- 参数:
- `arg0`: `const char *path`
- 返回:成功 `1`,失败 `0`
- 说明:仅允许 `/temp` 下创建目录。
### 30 `CLEONOS_SYSCALL_FS_WRITE`
- 参数:
- `arg0`: `const char *path`
- `arg1`: `const char *data`
- `arg2`: `u64 size`
- 返回:成功 `1`,失败 `0`
- 说明:覆盖写;仅允许 `/temp` 下文件。
### 31 `CLEONOS_SYSCALL_FS_APPEND`
- 参数:
- `arg0`: `const char *path`
- `arg1`: `const char *data`
- `arg2`: `u64 size`
- 返回:成功 `1`,失败 `0`
- 说明:追加写;仅允许 `/temp` 下文件。
### 32 `CLEONOS_SYSCALL_FS_REMOVE`
- 参数:
- `arg0`: `const char *path`
- 返回:成功 `1`,失败 `0`
- 说明:仅允许 `/temp` 下删除;目录需为空。
### 33 `CLEONOS_SYSCALL_LOG_JOURNAL_COUNT`
- 参数:无
- 返回:日志 journal 条目数量
### 34 `CLEONOS_SYSCALL_LOG_JOURNAL_READ`
- 参数:
- `arg0`: `u64 index_from_oldest`
- `arg1`: `char *out_line`
- `arg2`: `u64 out_size`
- 返回:成功 `1`,失败 `0`
- 说明:内核会保证输出字符串有 `\0` 终止。
### 35 `CLEONOS_SYSCALL_KBD_BUFFERED`
- 参数:无
- 返回:当前键盘队列中的字符数量
### 36 `CLEONOS_SYSCALL_KBD_PUSHED`
- 参数:无
- 返回:键盘累计入队计数
### 37 `CLEONOS_SYSCALL_KBD_POPPED`
- 参数:无
- 返回:键盘累计出队计数
### 38 `CLEONOS_SYSCALL_KBD_DROPPED`
- 参数:无
- 返回:键盘队列溢出丢弃计数
### 39 `CLEONOS_SYSCALL_KBD_HOTKEY_SWITCHES`
- 参数:无
- 返回ALT+F1..F4 热键切换计数
### 40 `CLEONOS_SYSCALL_GETPID`
- 参数:无
- 返回:当前进程 PID无活动进程时为 `0`
### 41 `CLEONOS_SYSCALL_SPAWN_PATH`
- 参数:
- `arg0`: `const char *path`
- 返回:
- 成功:子进程 PID
- 失败:`-1`
- 说明:当前实现为异步 spawn进入 pending 队列,后续由调度 tick 派发执行)。
### 29 `CLEONOS_SYSCALL_FS_MKDIR`
- 参数:
- `arg0`: `const char *path`
- 返回:成功 `1`,失败 `0`
- 说明:仅允许 `/temp` 下创建目录。
### 30 `CLEONOS_SYSCALL_FS_WRITE`
- 参数:
- `arg0`: `const char *path`
- `arg1`: `const char *data`
- `arg2`: `u64 size`
- 返回:成功 `1`,失败 `0`
- 说明:覆盖写;仅允许 `/temp` 下文件。
### 31 `CLEONOS_SYSCALL_FS_APPEND`
- 参数:
- `arg0`: `const char *path`
- `arg1`: `const char *data`
- `arg2`: `u64 size`
- 返回:成功 `1`,失败 `0`
- 说明:追加写;仅允许 `/temp` 下文件。
### 32 `CLEONOS_SYSCALL_FS_REMOVE`
- 参数:
- `arg0`: `const char *path`
- 返回:成功 `1`,失败 `0`
- 说明:仅允许 `/temp` 下删除;目录需为空。
### 33 `CLEONOS_SYSCALL_LOG_JOURNAL_COUNT`
- 参数:无
- 返回:日志 journal 条目数量
### 34 `CLEONOS_SYSCALL_LOG_JOURNAL_READ`
- 参数:
- `arg0`: `u64 index_from_oldest`
- `arg1`: `char *out_line`
- `arg2`: `u64 out_size`
- 返回:成功 `1`,失败 `0`
- 说明:内核会保证输出字符串有 `\0` 终止。
### 35 `CLEONOS_SYSCALL_KBD_BUFFERED`
- 参数:无
- 返回:当前键盘队列中的字符数量
### 36 `CLEONOS_SYSCALL_KBD_PUSHED`
- 参数:无
- 返回:键盘累计入队计数
### 37 `CLEONOS_SYSCALL_KBD_POPPED`
- 参数:无
- 返回:键盘累计出队计数
### 38 `CLEONOS_SYSCALL_KBD_DROPPED`
- 参数:无
- 返回:键盘队列溢出丢弃计数
### 39 `CLEONOS_SYSCALL_KBD_HOTKEY_SWITCHES`
- 参数:无
- 返回ALT+F1..F4 热键切换计数
### 40 `CLEONOS_SYSCALL_GETPID`
- 参数:无
- 返回:当前进程 PID无活动进程时为 `0`
### 41 `CLEONOS_SYSCALL_SPAWN_PATH`
- 参数:
- `arg0`: `const char *path`
- 返回:
- 成功:子进程 PID
- 失败:`-1`
- 说明:当前实现为异步 spawn进入 pending 队列,后续由调度 tick 派发执行)。
### 42 `CLEONOS_SYSCALL_WAITPID`
- 参数:
- `arg0`: `u64 pid`
- `arg1`: `u64 *out_status`(可为 `0`
- 参数:
- `arg0`: `u64 pid`
- `arg1`: `u64 *out_status`(可为 `0`
- 返回:
- `-1`PID 不存在
- `0`:目标进程仍未退出(`PENDING` / `RUNNING` / `STOPPED`
- `1`:目标进程已退出
- 说明:当返回 `1``arg1!=0` 时,会写入退出码。
### 43 `CLEONOS_SYSCALL_EXIT`
- 参数:
- `arg0`: `u64 status`
- 返回:
- `1`:已记录退出请求
- `0`:当前上下文不支持退出请求
### 44 `CLEONOS_SYSCALL_SLEEP_TICKS`
- 参数:
- `arg0`: `u64 ticks`
- 返回:实际休眠 tick 数
### 45 `CLEONOS_SYSCALL_YIELD`
- 参数:无
- 返回:当前 tick
### 46 `CLEONOS_SYSCALL_SHUTDOWN`
- 参数:无
- 返回:理论上不返回;成功路径会触发关机流程(当前 x86_64 走 QEMU/ACPI 关机端口)
- 说明:若关机流程未生效,内核会进入 halt 循环。
### 47 `CLEONOS_SYSCALL_RESTART`
- 参数:无
- 返回:理论上不返回;成功路径会触发重启流程(当前 x86_64 走 8042 reset
- 说明:若重启流程未生效,内核会进入 halt 循环。
### 48 `CLEONOS_SYSCALL_AUDIO_AVAILABLE`
- 参数:无
- 返回:
- `1`:音频输出可用
- `0`:当前平台无音频输出
### 49 `CLEONOS_SYSCALL_AUDIO_PLAY_TONE`
- 参数:
- `arg0`: `u64 hz`(频率,`0` 表示静音等待)
- `arg1`: `u64 ticks`(持续 tick
- 返回:成功 `1`,失败 `0`
- 说明:当前实现基于 PC Speakerx86_64用于最小音频链路。
### 43 `CLEONOS_SYSCALL_EXIT`
- 参数:
- `arg0`: `u64 status`
- 返回:
- `1`:已记录退出请求
- `0`:当前上下文不支持退出请求
### 44 `CLEONOS_SYSCALL_SLEEP_TICKS`
- 参数:
- `arg0`: `u64 ticks`
- 返回:实际休眠 tick 数
### 45 `CLEONOS_SYSCALL_YIELD`
- 参数:无
- 返回:当前 tick
### 46 `CLEONOS_SYSCALL_SHUTDOWN`
- 参数:无
- 返回:理论上不返回;成功路径会触发关机流程(当前 x86_64 走 QEMU/ACPI 关机端口)
- 说明:若关机流程未生效,内核会进入 halt 循环。
### 47 `CLEONOS_SYSCALL_RESTART`
- 参数:无
- 返回:理论上不返回;成功路径会触发重启流程(当前 x86_64 走 8042 reset
- 说明:若重启流程未生效,内核会进入 halt 循环。
### 48 `CLEONOS_SYSCALL_AUDIO_AVAILABLE`
- 参数:无
- 返回:
- `1`:音频输出可用
- `0`:当前平台无音频输出
### 49 `CLEONOS_SYSCALL_AUDIO_PLAY_TONE`
- 参数:
- `arg0`: `u64 hz`(频率,`0` 表示静音等待)
- `arg1`: `u64 ticks`(持续 tick
- 返回:成功 `1`,失败 `0`
- 说明:当前实现基于 PC Speakerx86_64用于最小音频链路。
### 50 `CLEONOS_SYSCALL_AUDIO_STOP`
- 参数:无
- 参数:无
- 返回:当前实现固定返回 `1`
- 说明:立即停止当前音频输出。
@@ -731,21 +731,53 @@ u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
- 返回:成功 `1`,失败 `0`
- 说明:按 LBA 写入单个扇区512B。该 syscall 在 USC 策略中默认视为高风险操作。
## 5. 用户态封装函数
### 95 `CLEONOS_SYSCALL_NET_AVAILABLE`
用户态封装位于:
- 参数:无
- 返回:`1` 表示网络栈可用e1000 初始化成功),`0` 表示不可用。
- `cleonos/c/src/syscall.c`
### 96 `CLEONOS_SYSCALL_NET_IPV4_ADDR`
常用封装示例:
- 参数:无
- 返回:当前 IPv4 地址(`u32`,以网络字节序放在返回值低 32 位)。
- 说明:当前默认静态地址为 `10.0.2.15`QEMU usernet 常见配置)。
- `cleonos_sys_fs_read()`
- `cleonos_sys_fs_write()` / `cleonos_sys_fs_append()` / `cleonos_sys_fs_remove()`
- `cleonos_sys_log_journal_count()` / `cleonos_sys_log_journal_read()`
### 97 `CLEONOS_SYSCALL_NET_PING`
- 参数:
- `arg0`: `u64 dst_ipv4_be`(目标 IPv4网络字节序
- `arg1`: `u64 poll_budget`(轮询预算;`0` 使用内核默认)
- 返回:成功收到 echo reply 返回 `1`,否则返回 `0`
### 98 `CLEONOS_SYSCALL_NET_UDP_SEND`
- 参数:
- `arg0`: `const struct { u64 dst_ipv4_be; u64 dst_port; u64 src_port; u64 payload_ptr; u64 payload_len; } *req`
- 返回:实际发送 payload 字节数;失败返回 `0`
- 说明:当前实现为最小 UDP 能力,`payload_len` 建议不超过 MTU 可承载范围。
### 99 `CLEONOS_SYSCALL_NET_UDP_RECV`
- 参数:
- `arg0`: `struct { u64 out_payload_ptr; u64 payload_capacity; u64 out_src_ipv4_ptr; u64 out_src_port_ptr; u64 out_dst_port_ptr; } *req`
- 返回:实际拷贝到 `out_payload_ptr` 的字节数;无数据/失败返回 `0`
- 说明:`out_src_*`/`out_dst_*` 指针可为 `0`(表示不关心该字段)。
## 5. 用户态封装函数
用户态封装位于:
- `cleonos/c/src/syscall.c`
常用封装示例:
- `cleonos_sys_fs_read()`
- `cleonos_sys_fs_write()` / `cleonos_sys_fs_append()` / `cleonos_sys_fs_remove()`
- `cleonos_sys_log_journal_count()` / `cleonos_sys_log_journal_read()`
- `cleonos_sys_exec_path()`
- `cleonos_sys_exec_pathv()`
- `cleonos_sys_tty_write()`
- `cleonos_sys_kbd_get_char()` / `cleonos_sys_kbd_buffered()`
- `cleonos_sys_kbd_get_char()` / `cleonos_sys_kbd_buffered()`
- `cleonos_sys_getpid()` / `cleonos_sys_spawn_path()` / `cleonos_sys_wait_pid()`
- `cleonos_sys_spawn_pathv()`
- `cleonos_sys_exit()` / `cleonos_sys_sleep_ticks()` / `cleonos_sys_yield()` / `cleonos_sys_shutdown()` / `cleonos_sys_restart()`
@@ -763,7 +795,9 @@ u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
- `cleonos_sys_disk_present()` / `cleonos_sys_disk_size_bytes()` / `cleonos_sys_disk_sector_count()`
- `cleonos_sys_disk_formatted()` / `cleonos_sys_disk_format_fat32()` / `cleonos_sys_disk_mount()` / `cleonos_sys_disk_mounted()` / `cleonos_sys_disk_mount_path()`
- `cleonos_sys_disk_read_sector()` / `cleonos_sys_disk_write_sector()`
- `cleonos_sys_net_available()` / `cleonos_sys_net_ipv4_addr()` / `cleonos_sys_net_ping()`
- `cleonos_sys_net_udp_send()` / `cleonos_sys_net_udp_recv()`
## 6. 开发注意事项
- 传入的字符串/缓冲指针目前按“同地址空间可直接访问”模型处理,后续若引入严格用户态地址隔离,需要补充用户内存校验。
@@ -773,7 +807,7 @@ u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
## 7. Wine 兼容说明
- `wine/cleonos_wine_lib/runner.py` 当前已覆盖到 `0..94`(含 `DL_*``FB_*``KERNEL_VERSION``DISK_*`)。
- `wine/cleonos_wine_lib/runner.py` 当前已覆盖到 `0..99`(含 `DL_*``FB_*``KERNEL_VERSION``DISK_*``NET_*`)。
- `DL_*``77..79`)在 Wine 中为“可运行兼容”实现:
- `DL_OPEN`:加载 guest ELF 到当前 Unicorn 地址空间,返回稳定 `handle`,并做引用计数。
- `DL_SYM`:解析 ELF `SYMTAB/DYNSYM` 并返回 guest 可调用地址。
@@ -790,6 +824,7 @@ u64 cleonos_syscall(u64 id, u64 arg0, u64 arg1, u64 arg2);
- `DISK_FORMAT_FAT32` 会初始化/重置 Wine rootfs 下的虚拟磁盘目录。
- `DISK_MOUNT`/`DISK_MOUNT_PATH` 支持挂载点管理,并与 `FS_MKDIR/WRITE/APPEND/REMOVE` 的路径规则联动。
- `DISK_READ_SECTOR`/`DISK_WRITE_SECTOR``93..94`)在 Wine 中已实现为 512B 原始扇区读写host 文件后端)。
- 网络 syscall`95..99`)在 Wine 当前为兼容占位实现(统一返回 `0`);即 Wine 运行模式下不会提供真实网络收发。
- Wine 在运行时崩溃场景下会生成与内核一致格式的“信号编码退出状态”,可通过 `WAITPID` 读取。
- Wine 当前音频 syscall 为占位实现:`AUDIO_AVAILABLE=0``AUDIO_PLAY_TONE=0``AUDIO_STOP=1`
- Wine 版本号策略固定为 `85.0.0-wine`(历史兼容号;不会随 syscall 扩展继续增长)。

2
kit

Submodule kit updated: a8dfe5c4eb...20dd7394ef

2
wine

Submodule wine updated: e83774f1b3...80586d676d