Fixed get os version in SHELL

Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
This commit is contained in:
Maxim Logaev 2024-03-31 03:08:13 +03:00
parent fa4755138f
commit ec3af7f664
5 changed files with 64 additions and 54 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -1,31 +1,21 @@
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),
__asm__ __volatile__(
"cpuid"
:"=a" (a),
"=b" (b),
"=c" (c),
"=d" (d):
"a"(0));
"a"(0)
);
str[0] = (b & 0x000000ff) >> 0;
str[1] = (b & 0x0000ff00) >> 8;
@ -46,7 +36,7 @@ void get_str_cpu_info(char *str) {
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;
}

View File

@ -59,7 +59,6 @@ const command_t COMMANDS[]=
#define CMD_SLEEP_USAGE " sleep <time in the 1/100 of second>\n\r"
#define CMD_TOUCH_USAGE " touch <filename>\n\r"
#define CMD_UPTIME_FMT " Uptime: %d day(s), %d:%d:%d.%d\n\r"
#define CMD_VER_FMT1 " KolibriOS v%d.%d.%d.%d. Kernel SVN-rev.: %d\n\r"
#define CMD_WAITFOR_FMT " Awaing finish PID %d\n\r"
#define EXEC_STARTED_FMT " '%s' started. PID = %d\n\r"
#define EXEC_SCRIPT_ERROR_FMT "Error in '%s' : script must start with #SHS line\n\r"

View File

@ -59,7 +59,6 @@ const command_t COMMANDS[]=
#define CMD_SLEEP_USAGE " sleep <¨­â¥à¢ « ¢ á®âëå ¤®«ïx ᥪ㭤ë>\n\r"
#define CMD_TOUCH_USAGE " touch <¨¬ï ä ©« >\n\r"
#define CMD_UPTIME_FMT " Uptime: %d ¤­¥©, %d:%d:%d.%d\n\r"
#define CMD_VER_FMT1 " KolibriOS v%d.%d.%d.%d. SVN-ॢ. ï¤à : %d\n\r"
#define CMD_WAITFOR_FMT " Ž¦¨¤ ¥¬ § ¢¥à襭¨ï PID %d\n\r"
#define EXEC_STARTED_FMT " '%s' § ¯ã饭. PID = %d\n\r"
#define EXEC_SCRIPT_ERROR_FMT "Žè¨¡ª  ¢ '%s' : áªà¨¯â ¤®«¦¥­ ­ ç¨­ âìáï á® áâà®çª¨ #SHS\n\r"