1212#include "kernel.h"
1313#include "utils.h"
1414#include "../libc/stdio.h"
15+ #include "../libc/mem.h"
1516#include "../libc/string.h"
1617
1718void kmain () {
@@ -30,33 +31,52 @@ void kmain() {
3031 kprint ("Copyright (C) alexeev-prog\nRepository: https://github.com/alexeev-prog/KintsugiOS\n" );
3132
3233 // Уведомление о старте оболочки командной строки
33- kprint ("\nKeramika Busybox v0.1.0 "
34+ kprint ("\nKeramika Shell v0.1.0 "
3435 "Type END to halt the CPU\n"
3536 "Type HELP to view commands\n\n!#> " );
3637}
3738
39+ char * * get_args (char * input ) {
40+ char * token = strtok (input , " " );
41+ char * * args ;
42+ int arg_counter = 0 ;
43+
44+ while (token ) {
45+ token = strtok (NULL , " " );
46+
47+ args [arg_counter ] = token ;
48+ arg_counter ++ ;
49+ }
50+
51+ kfree (token );
52+
53+ return args ;
54+ }
55+
3856void user_input (char * input ) {
3957 // Массив структур команд, состоящий из самой команды, подсказки и указателя до void-функции
40- struct { char * text , * hint ; void (* command )(); } commands [] = {
58+ struct { char * text , * hint ; void (* command )(char * * ); } commands [] = {
4159 // Команда Подсказка для команды Указатель до функции
42- {.text = "END" , .hint = "HALT CPU" , .command = & halt_cpu },
43- {.text = "CLEAR" , .hint = "Clear screen" , .command = & clear_screen },
44- {.text = "KMALLOC" , .hint = "Kernel Page Malloc" , .command = & malloc_command_shell },
45- {.text = "QEMUSHUTDOWN" , .hint = "Shutdown QEMU" , .command = & shutdown_qemu },
46- {.text = "INFO" , .hint = "Get info" , .command = & info_command_shell },
47- {.text = "FREEMEMADDR" , .hint = "Get free mem addr" , .command = & print_freememaddr },
48- {.text = "TESTMEM" , .hint = "Test memory" , .command = & test_mem_command },
49- {.text = "KMEMDUMP" , .hint = "Dump memory" , .command = & mem_dump }
60+ {.text = "END" , .hint = "HALT CPU" , .command = & halt_cpu },
61+ {.text = "CLEAR" , .hint = "Clear screen" , .command = & clear_screen_command },
62+ {.text = "AMALLOC" , .hint = "Kernel Arena Malloc. Usage: AMALLOC <size>" , .command = & arena_malloc_command_shell },
63+ {.text = "QEMUSHUTDOWN" , .hint = "Shutdown QEMU" , .command = & shutdown_qemu },
64+ {.text = "INFO" , .hint = "Get info" , .command = & info_command_shell },
65+ {.text = "FREEMEMADDR" , .hint = "Get free mem addr" , .command = & print_freememaddr },
66+ {.text = "TESTMEM" , .hint = "Test memory" , .command = & test_mem_command },
67+ {.text = "KMEMDUMP" , .hint = "Dump memory" , .command = & mem_dump },
68+ {.text = "KMALLOC" , .hint = "Alloc memory. Usage: KMALLOC <size>" , .command = & kmalloc_command }
5069 };
51- // TODO: добавить поддержку аргументов
5270
5371 int executed = 0 ;
5472
73+ char * * args = get_args (input );
74+
5575 const int commands_length = sizeof (commands ) / sizeof (commands [0 ]);
5676
5777 for (int i = 0 ; i < commands_length ; ++ i ) {
5878 if (strcmp (input , commands [i ].text ) == 0 ) {
59- commands [i ].command ();
79+ commands [i ].command (args );
6080 executed = 1 ;
6181 break ;
6282 }
0 commit comments