From 306d4c85933c77f4db19a5ee3aa00eb22c7857e2 Mon Sep 17 00:00:00 2001 From: Maxim Logaev Date: Sun, 31 Mar 2024 03:08:13 +0300 Subject: [PATCH] Fixed get os version in SHELL Signed-off-by: Maxim Logaev --- .../ktcc/trunk/libc.obj/include/sys/ksys.h | 28 +++++ programs/system/shell/cmd/cmd_kfetch.c | 21 ++-- programs/system/shell/cmd/cmd_ver.c | 59 ++++----- programs/system/shell/locale/eng/globals.h | 3 +- programs/system/shell/locale/rus/globals.h | 113 +++++++++--------- 5 files changed, 117 insertions(+), 107 deletions(-) diff --git a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h index 28971fc38b..36c039be42 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h @@ -759,6 +759,34 @@ KOSAPI void _ksys_shutdown(uint32_t shd_param) asm_inline("int $0x40" ::"a"(18), "b"(9), "c"(shd_param)); } +/*========= Function 18, subfunction 13 - get OS version. ========*/ + +#define KSYS_VER_HASH_LEN 9 + +typedef struct { + union { + struct { + uint8_t major; + uint8_t minor; + uint8_t patch; + uint8_t __reserved; + }; + uint32_t value; + } tag; + uint16_t offset; + char hash[KSYS_VER_HASH_LEN + 1]; +} ksys_os_ver_t; + +KOSAPI int _ksys_get_os_ver(ksys_os_ver_t *ver) +{ + int status; + asm_inline( + "int $0x40" + : "=a"(status) + : "a"(18), "b"(13), "c"(ver)); + return status; +} + /*========= Function 18, subfunction 16 - get size of free RAM. ========*/ KOSAPI size_t _ksys_get_ram_size(void) diff --git a/programs/system/shell/cmd/cmd_kfetch.c b/programs/system/shell/cmd/cmd_kfetch.c index 69eab45acc..4b6db5f2d2 100644 --- a/programs/system/shell/cmd/cmd_kfetch.c +++ b/programs/system/shell/cmd/cmd_kfetch.c @@ -6,16 +6,16 @@ void get_str_meminfo(char *str) { } int cmd_kfetch(char param[]) { - char *str_krnl_ver = malloc(64); - get_str_kernel_version(str_krnl_ver, "%d.%d.%d.%d. SVN-rev.: %d"); - char *str_uptime = malloc(64); + char str_krnl_ver[64]; + get_str_kernel_version(str_krnl_ver, "v%d.%d.%d-%d-g%s"); + char str_uptime[64]; get_str_uptime(str_uptime, "%d day(s), %d:%d:%d.%d"); - char *str_resolution = malloc(24); + char str_resolution[24]; ksys_pos_t resol = _ksys_screen_size(); sprintf(str_resolution, "%u x %u", resol.x + 1, resol.y + 1); - char *str_cpu_info = malloc(16); + char str_cpu_info[16]; get_str_cpu_info(str_cpu_info); - char *str_meminfo = malloc(24); + char str_meminfo[24]; get_str_meminfo(str_meminfo); printf(/*"\033[0;34;40m \033[0m\n\r"*/ @@ -42,12 +42,7 @@ int cmd_kfetch(char param[]) { "\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0;31;40m.\033[0;1;30;40m8\033[0;5;37;45m@\033[0;5;35;44m:\033[0;1;30;45m8\033[0;5;34;44m \033[0;5;35;45m \033[0;1;34;44m8\033[0;1;35;45m.\033[0;5;34;40mX\033[0;34;40m@\033[0;32;40mS\033[0;31;40m \033[0;34;40m \033[0m\n\r" "\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0;31;40m \033[0;34;40m.;\033[0;1;30;40m8\033[0;1;30;44m8\033[0;34;40m8\033[0;5;34;40m8\033[0;32;40m%%\033[0;34;40m8;\033[0;32;40m;\033[0;31;40m.\033[0;32;40m \033[0;31;40m \033[0;34;40m \033[0m\n\r" "\033[0;34;40m \033[0;31;40m \033[0;34;40m \033[0;32;40m .\033[0;31;40m .:\033[0;32;40m.\033[0;31;40m.\033[0;32;40m.\033[0;31;40m.\033[0;32;40m.\033[0;31;40m \033[0;32;40m \033[0;34;40m \033[0m\n\r", - "\033[0;36mOS\033[0m: KolibriOS", "\033[0;36mKernel\033[0m: ", str_krnl_ver, "\033[0;36mUptime\033[0m: ", str_uptime, "\033[0;36mResolution\033[0m: ", str_resolution, "\033[0;36mCPU\033[0m: ", str_cpu_info, "\033[0;36mMemory\033[0m: ", str_meminfo); + "\033[0;36mOS\033[0m: KolibriOS", "\033[0;36mVersion\033[0m: ", str_krnl_ver, "\033[0;36mUptime\033[0m: ", str_uptime, "\033[0;36mResolution\033[0m: ", str_resolution, "\033[0;36mCPU\033[0m: ", str_cpu_info, "\033[0;36mMemory\033[0m: ", str_meminfo); - free(str_krnl_ver); - free(str_uptime); - free(str_resolution); - free(str_cpu_info); - free(str_meminfo); return TRUE; -} \ No newline at end of file +} diff --git a/programs/system/shell/cmd/cmd_ver.c b/programs/system/shell/cmd/cmd_ver.c index a7c2c9a0d0..e193912dcd 100644 --- a/programs/system/shell/cmd/cmd_ver.c +++ b/programs/system/shell/cmd/cmd_ver.c @@ -1,52 +1,42 @@ void get_str_kernel_version(char *str, const char *fmt) { - char *kvbuf; - char *vA, *vB, *vC, *vD; - unsigned *Rev; - - kvbuf = malloc(16); - kol_get_kernel_ver(kvbuf); - vA = kvbuf+0; - vB = kvbuf+1; - vC = kvbuf+2; - vD = kvbuf+3; - Rev = (unsigned*)(kvbuf + 5); - - sprintf (str, fmt, *vA, *vB, *vC, *vD, *Rev); - - free(kvbuf); + ksys_os_ver_t ver; + _ksys_get_os_ver(&ver); + sprintf(str, fmt, ver.tag.major, ver.tag.minor, ver.tag.patch, ver.offset, ver.hash); } void get_str_cpu_info(char *str) { unsigned a, b, c, d; - asm ("cpuid" : - "=a" (a), - "=b" (b), - "=c" (c), - "=d" (d): - "a"(0)); + __asm__ __volatile__( + "cpuid" + :"=a" (a), + "=b" (b), + "=c" (c), + "=d" (d): + "a"(0) + ); - str[0] = (b&0x000000ff) >> 0; - str[1] = (b&0x0000ff00) >> 8; - str[2] = (b&0x00ff0000) >> 16; - str[3] = (b&0xff000000) >> 24; + str[0] = (b & 0x000000ff) >> 0; + str[1] = (b & 0x0000ff00) >> 8; + str[2] = (b & 0x00ff0000) >> 16; + str[3] = (b & 0xff000000) >> 24; - str[4] = (d&0x000000ff) >> 0; - str[5] = (d&0x0000ff00) >> 8; - str[6] = (d&0x00ff0000) >> 16; - str[7] = (d&0xff000000) >> 24; + str[4] = (d & 0x000000ff) >> 0; + str[5] = (d & 0x0000ff00) >> 8; + str[6] = (d & 0x00ff0000) >> 16; + str[7] = (d & 0xff000000) >> 24; - str[8] = (c&0x000000ff) >> 0; - str[9] = (c&0x0000ff00) >> 8; - str[10] = (c&0x00ff0000) >> 16; - str[11] = (c&0xff000000) >> 24; + str[8] = (c & 0x000000ff) >> 0; + str[9] = (c & 0x0000ff00) >> 8; + str[10] = (c & 0x00ff0000) >> 16; + str[11] = (c & 0xff000000) >> 24; str[12] = '\0'; } int cmd_ver(char param[]) { if (!strcmp(param, "kernel")) { - get_str_kernel_version(tmpstr, CMD_VER_FMT1); + get_str_kernel_version(tmpstr, " KolibriOS v%d.%d.%d-%d-g%s\n\r"); printf(tmpstr); return TRUE; } @@ -61,4 +51,3 @@ int cmd_ver(char param[]) { printf (" Shell v%s\n\r", SHELL_VERSION); return TRUE; } - diff --git a/programs/system/shell/locale/eng/globals.h b/programs/system/shell/locale/eng/globals.h index 2f6fe63448..e5625c6fec 100644 --- a/programs/system/shell/locale/eng/globals.h +++ b/programs/system/shell/locale/eng/globals.h @@ -58,8 +58,7 @@ const command_t COMMANDS[]= #define CMD_RMDIR_USAGE " rmdir \n\r" #define CMD_SLEEP_USAGE " sleep