From 7b7f134e27fdd1b8021a54a582e9bbb54d7e15e2 Mon Sep 17 00:00:00 2001 From: boreddevnl Date: Tue, 17 Mar 2026 16:06:00 +0100 Subject: [PATCH] feat: centralize OS version info in kernel syscall --- src/core/version.c | 33 ++++++++++++++++++++++++ src/sys/syscall.c | 6 +++++ src/sys/syscall.h | 12 +++++++++ src/userland/cli/sysfetch.c | 20 +++++++++++++-- src/userland/gui/about.c | 50 +++++++++++++++++++++++++++++-------- src/userland/libc/syscall.c | 4 +++ src/userland/libc/syscall.h | 14 +++++++++++ 7 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 src/core/version.c diff --git a/src/core/version.c b/src/core/version.c new file mode 100644 index 0000000..41d2ef8 --- /dev/null +++ b/src/core/version.c @@ -0,0 +1,33 @@ +// Copyright (c) 2023-2026 Chris (boreddevnl) +// This software is released under the GNU General Public License v3.0. See LICENSE file for details. +// This header needs to maintain in any file it is present in, as per the GPL license terms. +#include "syscall.h" +#include + +extern void mem_memcpy(void *dest, const void *src, size_t len); + +void get_os_info(os_info_t *info) { + if (!info) return; + + char *p = (char *)info; + for (size_t i = 0; i < sizeof(os_info_t); i++) p[i] = 0; + + const char *os_name = "BoredOS"; + const char *os_version = "1.72"; + const char *os_codename = "Retrowave"; + const char *kernel_name = "Boredkernel"; + const char *kernel_version = "3.1.2"; + const char *build_date = __DATE__; + const char *build_time = __TIME__; + const char *build_arch = "x86_64"; + + int j; + j = 0; while (os_name[j] && j < 63) { info->os_name[j] = os_name[j]; j++; } info->os_name[j] = '\0'; + j = 0; while (os_version[j] && j < 63) { info->os_version[j] = os_version[j]; j++; } info->os_version[j] = '\0'; + j = 0; while (os_codename[j] && j < 63) { info->os_codename[j] = os_codename[j]; j++; } info->os_codename[j] = '\0'; + j = 0; while (kernel_name[j] && j < 63) { info->kernel_name[j] = kernel_name[j]; j++; } info->kernel_name[j] = '\0'; + j = 0; while (kernel_version[j] && j < 63) { info->kernel_version[j] = kernel_version[j]; j++; } info->kernel_version[j] = '\0'; + j = 0; while (build_date[j] && j < 63) { info->build_date[j] = build_date[j]; j++; } info->build_date[j] = '\0'; + j = 0; while (build_time[j] && j < 63) { info->build_time[j] = build_time[j]; j++; } info->build_time[j] = '\0'; + j = 0; while (build_arch[j] && j < 63) { info->build_arch[j] = build_arch[j]; j++; } info->build_arch[j] = '\0'; +} diff --git a/src/sys/syscall.c b/src/sys/syscall.c index 8f6454e..f0208ea 100644 --- a/src/sys/syscall.c +++ b/src/sys/syscall.c @@ -1258,6 +1258,12 @@ static uint64_t syscall_handler_inner(registers_t *regs) { return 0; } return -1; + } else if (cmd == 49) { // SYSTEM_CMD_GET_OS_INFO + os_info_t *info = (os_info_t *)arg2; + if (!info) return -1; + extern void get_os_info(os_info_t *info); + get_os_info(info); + return 0; } return -1; } diff --git a/src/sys/syscall.h b/src/sys/syscall.h index 4f7f83b..2301165 100644 --- a/src/sys/syscall.h +++ b/src/sys/syscall.h @@ -10,6 +10,17 @@ typedef struct Window Window; typedef struct registers_t registers_t; +typedef struct { + char os_name[64]; + char os_version[64]; + char os_codename[64]; + char kernel_name[64]; + char kernel_version[64]; + char build_date[64]; + char build_time[64]; + char build_arch[64]; +} os_info_t; + // MSRs used for syscalls in x86_64 #define MSR_EFER 0xC0000080 #define MSR_STAR 0xC0000081 @@ -46,6 +57,7 @@ typedef struct registers_t registers_t; #define SYSTEM_CMD_GET_CPU_MODEL 45 #define SYSTEM_CMD_SLEEP 46 #define SYSTEM_CMD_SET_RESOLUTION 47 +#define SYSTEM_CMD_GET_OS_INFO 49 void syscall_init(void); uint64_t syscall_handler_c(registers_t *regs); diff --git a/src/userland/cli/sysfetch.c b/src/userland/cli/sysfetch.c index 5bf8721..2faf849 100644 --- a/src/userland/cli/sysfetch.c +++ b/src/userland/cli/sysfetch.c @@ -237,13 +237,29 @@ int main(int argc, char **argv) { if (config.separator[0]) { strcpy(info_lines[info_line_count++], config.separator); } + os_info_t os_info; + sys_get_os_info(&os_info); + if (config.os_label[0]) { strcpy(info_lines[info_line_count], config.os_label); - strcat(info_lines[info_line_count++], ": BoredOS V1.72 'Retrowave'"); + strcat(info_lines[info_line_count], ": "); + strcat(info_lines[info_line_count], os_info.os_name); + strcat(info_lines[info_line_count], " V"); + strcat(info_lines[info_line_count], os_info.os_version); + strcat(info_lines[info_line_count], " '"); + strcat(info_lines[info_line_count], os_info.os_codename); + strcat(info_lines[info_line_count], "'"); + info_line_count++; } if (config.kernel_label[0]) { strcpy(info_lines[info_line_count], config.kernel_label); - strcat(info_lines[info_line_count++], ": Boredkernel V3.1.2 x86_64"); + strcat(info_lines[info_line_count], ": "); + strcat(info_lines[info_line_count], os_info.kernel_name); + strcat(info_lines[info_line_count], " V"); + strcat(info_lines[info_line_count], os_info.kernel_version); + strcat(info_lines[info_line_count], " "); + strcat(info_lines[info_line_count], os_info.build_arch); + info_line_count++; } if (config.uptime_label[0]) { uint64_t ticks = sys_system(16, 0, 0, 0, 0); diff --git a/src/userland/gui/about.c b/src/userland/gui/about.c index 89a7280..34dbc5a 100644 --- a/src/userland/gui/about.c +++ b/src/userland/gui/about.c @@ -84,10 +84,9 @@ static void draw_ascii_logo(ui_window_t win, int x, int y) { } static void about_paint(ui_window_t win) { - int w = 340; - int h = 240; + int w = 380; + int h = 260; - // Clear background to prevent alpha-blended text from accumulating on repaints ui_draw_rect(win, 0, 0, w, h, 0xFF1E1E1E); int offset_x = 15; @@ -96,19 +95,51 @@ static void about_paint(ui_window_t win) { draw_ascii_logo(win, 14, offset_y); int fh = ui_get_font_height(); - ui_draw_string(win, offset_x, offset_y + 105, "BoredOS 'Retrowave'", 0xFFFFFFFF); - ui_draw_string(win, offset_x, offset_y + 105 + fh, "BoredOS Version 1.72", 0xFFFFFFFF); - ui_draw_string(win, offset_x, offset_y + 105 + fh*2, "Kernel Version 3.1.2", 0xFFFFFFFF); + os_info_t os_info; + sys_get_os_info(&os_info); + + char os_name_str[128]; + os_name_str[0] = 0; + strcat(os_name_str, os_info.os_name); + strcat(os_name_str, " '"); + strcat(os_name_str, os_info.os_codename); + strcat(os_name_str, "'"); + + char os_version_str[128]; + os_version_str[0] = 0; + strcat(os_version_str, os_info.os_name); + strcat(os_version_str, " Version "); + strcat(os_version_str, os_info.os_version); + + char kernel_version_str[128]; + kernel_version_str[0] = 0; + strcat(kernel_version_str, os_info.kernel_name); + strcat(kernel_version_str, " Version "); + strcat(kernel_version_str, os_info.kernel_version); + strcat(kernel_version_str, " "); + strcat(kernel_version_str, os_info.build_arch); + + char build_date_str[128]; + build_date_str[0] = 0; + strcat(build_date_str, "Build Date: "); + strcat(build_date_str, os_info.build_date); + strcat(build_date_str, " "); + strcat(build_date_str, os_info.build_time); + + ui_draw_string(win, offset_x, offset_y + 105, os_name_str, 0xFFFFFFFF); + ui_draw_string(win, offset_x, offset_y + 105 + fh, os_version_str, 0xFFFFFFFF); + ui_draw_string(win, offset_x, offset_y + 105 + fh*2, kernel_version_str, 0xFFFFFFFF); + ui_draw_string(win, offset_x, offset_y + 105 + fh*3, build_date_str, 0xFFFFFFFF); // Copyright - ui_draw_string(win, offset_x, offset_y + 105 + fh*3, "(C) 2026 boreddevnl.", 0xFFFFFFFF); - ui_draw_string(win, offset_x, offset_y + 105 + fh*4, "All rights reserved.", 0xFFFFFFFF); + ui_draw_string(win, offset_x, offset_y + 105 + fh*4, "(C) 2026 boreddevnl.", 0xFFFFFFFF); + ui_draw_string(win, offset_x, offset_y + 105 + fh*5, "All rights reserved.", 0xFFFFFFFF); ui_mark_dirty(win, 0, 0, w, h); } int main(void) { - ui_window_t win_about = ui_window_create("About BoredOS", 250, 180, 340, 240); + ui_window_t win_about = ui_window_create("About BoredOS", 250, 180, 380, 260); about_paint(win_about); @@ -121,7 +152,6 @@ int main(void) { sys_exit(0); } } else { - // Avoid high CPU usage sleep(10); } } diff --git a/src/userland/libc/syscall.c b/src/userland/libc/syscall.c index 9d51460..3eb8935 100644 --- a/src/userland/libc/syscall.c +++ b/src/userland/libc/syscall.c @@ -251,3 +251,7 @@ void sys_yield(void) { syscall1(SYS_SYSTEM, SYSTEM_CMD_YIELD); } +int sys_get_os_info(os_info_t *info) { + return (int)syscall5(SYS_SYSTEM, SYSTEM_CMD_GET_OS_INFO, (uint64_t)info, 0, 0, 0); +} + diff --git a/src/userland/libc/syscall.h b/src/userland/libc/syscall.h index f1a6204..595f952 100644 --- a/src/userland/libc/syscall.h +++ b/src/userland/libc/syscall.h @@ -75,6 +75,7 @@ #define SYSTEM_CMD_SET_RAW_MODE 41 #define SYSTEM_CMD_TCP_RECV_NB 42 #define SYSTEM_CMD_YIELD 43 +#define SYSTEM_CMD_GET_OS_INFO 49 // Internal assembly entry into Ring 0 extern uint64_t syscall0(uint64_t sys_num); @@ -91,6 +92,19 @@ void *sys_sbrk(int incr); void sys_kill(int pid); int sys_system(int cmd, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4); +typedef struct { + char os_name[64]; + char os_version[64]; + char os_codename[64]; + char kernel_name[64]; + char kernel_version[64]; + char build_date[64]; + char build_time[64]; + char build_arch[64]; +} os_info_t; + +int sys_get_os_info(os_info_t *info); + // FS API int sys_open(const char *path, const char *mode); int sys_read(int fd, void *buf, uint32_t len);