Skip to content

Commit

Permalink
'eBat' as part of the OS
Browse files Browse the repository at this point in the history
  • Loading branch information
pimnik98 committed Sep 18, 2024
1 parent 73ebd91 commit d6f5823
Show file tree
Hide file tree
Showing 13 changed files with 1,302 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ WSL:
@$(MAKE) -f $(BUILD_PREFIX)/Makefile -C . geniso
@-mkdir /mnt/c/SayoriDev/
mv kernel.iso /mnt/c/SayoriDev/SayoriOS_DEV_WSL.iso
"/mnt/c/Program Files/qemu/qemu-system-i386.exe" -cdrom "C:\\SayoriDev\\SayoriOS_DEV_WSL.iso" -serial mon:stdio -m 128M -name "SayoriOS DEV WSL MODE" -d guest_errors -rtc base=localtime -netdev user,id=net1,net=192.168.222.0,dhcpstart=192.168.222.128 -device virtio-net-pci,netdev=net1,id=mydev1,mac=52:54:00:6a:40:f8 $(QEMU_FLAGS_WSL)
"/mnt/c/Program Files/qemu/qemu-system-i386.exe" -cdrom "C:\\SayoriDev\\SayoriOS_DEV_WSL.iso" -serial mon:stdio -m 128M -name "SayoriOS DEV WSL MODE" -d guest_errors -rtc base=localtime -netdev user,id=net1,net=192.168.222.0,dhcpstart=192.168.222.128 -device virtio-net-pci,netdev=net1,id=mydev1,mac=52:54:00:6a:40:f8

WSL_NAT:
@$(MAKE) -f $(BUILD_PREFIX)/Makefile -C .
Expand Down
4 changes: 3 additions & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include config.mk

KERNEL = iso/boot/kernel.elf
BUILD_PREFIX=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
CURRENT_USER := $(shell whoami)

COMPILER_DETECTOR_FLAGS = ""

Expand Down Expand Up @@ -188,6 +189,7 @@ SOURCES:=$(SOURCES:%.c=$(BUILD_PREFIX)/%.c) \
$(wildcard $(BUILD_PREFIX)/kernel/src/lib/libvector/src/*.c) \
$(wildcard $(BUILD_PREFIX)/kernel/src/lib/libstring/src/*.c) \
$(wildcard $(BUILD_PREFIX)/kernel/src/lib/elk/ext/*.c) \
$(wildcard $(BUILD_PREFIX)/kernel/src/ports/eBat/*.c) \

DIRECTORIES := $(addprefix $(OBJ_DIRECTORY)/,$(sort $(dir $(SOURCES) $(ASM_SRC))))

Expand All @@ -201,7 +203,7 @@ COMMON_FLAGS = -O$(OPTIMIZATION_LEVEL) -nostdlib -fno-stack-protector -fno-built
-mno-red-zone -MMD -MP -g

# Флаги компилятора языка C
CFLAGS=$(DEBUG) $(ADDCFLAGS) $(COMMON_FLAGS)
CFLAGS=$(DEBUG) $(ADDCFLAGS) $(COMMON_FLAGS) -DBUILDUSER=\"$(CURRENT_USER)\"
CPP_FLAGS=$(DEBUG) $(COMMON_FLAGS) -fno-use-cxa-atexit -fno-exceptions -fno-rtti -Werror -Ikernel/cpp/include

LD ?= ld.lld
Expand Down
6 changes: 6 additions & 0 deletions kernel/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
#endif
#define VERNAME "Soul" /// Имя версии (изменяется вместе с минорной части версии)
#define SUBVERSIONNAME "Aura" /// Вторичное имя версии (изменяется вместе с каждым глобальным релизом)


// Макрос для создания версии как строки
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH)
48 changes: 41 additions & 7 deletions kernel/src/extra/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "debug/hexview.h"
#include "lib/command_parser.h"

#include "../ports/eBat/eBat.h"
#include "../ports/eBat/eBatRuntime.h"

int G_CLI_CURINXA = 0;
int G_CLI_CURINXB = 0;
int G_CLI_H_KYB = 1;
Expand Down Expand Up @@ -652,6 +655,26 @@ CLI_CMD_ELEM G_CLI_CMD[] = {
{nullptr, nullptr, nullptr}
};

int cli_handler_ebat(int argc, char** argv){
qemu_note("[RUNTIME] [System] [EXEC] Count: %d\n", argc);
int ret = 0;
bool found = false;

for(size_t i = 0; G_CLI_CMD[i].name != nullptr; i++) {
if(strcmpn(G_CLI_CMD[i].name, argv[0]) || strcmpn(G_CLI_CMD[i].alias, argv[0])) {
ret = G_CLI_CMD[i].funcv(argc, argv);
found = true;
break;
}
}

if(!found) {
ret = CLI_CMD_RUN(argc, argv);
}

return ret;
}

void cli_handler(const char* ncmd){
set_cursor_enabled(0);

Expand All @@ -672,7 +695,7 @@ void cli_handler(const char* ncmd){
break;
}
}

if(!found) {
CLI_CMD_RUN(parser.argc, parser.argv);
}
Expand All @@ -687,11 +710,6 @@ void cli(){
tty_set_bgcolor(0xFF000000);
tty_setcolor(0xFFFFFF);

variable_write("HOSTNAME", "SAYORISOUL");
variable_write("SYSTEMROOT", "R:\\Sayori\\");
variable_write("TEMP", "T:\\");
variable_write("USERNAME", "OEM");

// T_CLI_KYB = RegTrigger(0x0001, &F_CLI_KYB);

// clean_tty_screen();
Expand Down Expand Up @@ -724,7 +742,23 @@ void cli(){
size_t current_time = timestamp();
qemu_log("cmd: %s", input_buffer);

cli_handler(input_buffer);
/////////////////////////////////////

int preprocessor = 0;

if (preprocessor == 0){
cli_handler(input_buffer);
} else {
BAT_T* token = bat_parse_string(input_buffer);
token->Debug = 0;
token->Echo = 1;
int ret = bat_runtime_exec(token);
qemu_warn("RETURN CODE: %d\n",ret);
bat_destroy(token);
}
////////////////////////////////////

//
tty_printf("\n");

ssize_t delta = (int)system_heap.used_memory - (int)memory_cur;
Expand Down
51 changes: 51 additions & 0 deletions kernel/src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include "drv/ps2.h"
#include "net/dhcp.h"
#include "gfx/intel.h"
#include "ports/eBat/eBat.h"
#include "ports/eBat/eBatRuntime.h"


#include <lib/pixel.h>

Expand All @@ -49,6 +52,52 @@ size_t ramdisk_size = INITRD_RW_SIZE;
void jse_file_getBuff(char* buf);
void kHandlerCMD(char*);

void autoexec(){

variable_write("HOSTNAME", "SAYORISOUL");
variable_write("SYSTEMROOT", "R:\\Sayori\\");
variable_write("TEMP", "T:\\");
variable_write("USERNAME", "OEM");
variable_write("BUILDUSER", BUILDUSER);
variable_write("BUILDDATA", __TIMESTAMP__);
variable_write("VERSION_MAJOR", TOSTRING(VERSION_MAJOR));
variable_write("VERSION_MINOR", TOSTRING(VERSION_MINOR));
variable_write("VERSION_PATCH", TOSTRING(VERSION_PATCH));
variable_write("ARCH_TYPE", ARCH_TYPE);
variable_write("VERNAME", VERNAME);
variable_write("SUBVERSIONNAME", SUBVERSIONNAME);
variable_write("VERSION", VERSION_STRING);


char* f = "R:\\autoexec.bat";
FILE* cat_file = fopen(f, "r");
if (!cat_file){
tty_setcolor(COLOR_ERROR);
tty_printf("[AutoExec] Не удалось найти файл `%s`.\n",f);
return;
}

size_t filesize = fsize(cat_file);

uint8_t* buffer = kcalloc(1,filesize + 1);

fread(cat_file, 1, filesize, buffer);

qemu_log("'%s'", buffer);

BAT_T* token = bat_parse_string(buffer);
token->Debug = 0;
token->Echo = 1;
int ret = bat_runtime_exec(token);
qemu_warn("RETURN CODE: %d\n",ret);
bat_destroy(token);


fclose(cat_file);

kfree(buffer);
}

void __createRamDisk(){
qemu_note("[INITRD] Create virtual read-write disk...");
void* disk_t = kmalloc(INITRD_RW_SIZE+1);
Expand Down Expand Up @@ -469,6 +518,8 @@ void __attribute__((noreturn)) kmain(multiboot_header_t* mboot, uint32_t initia
// sleep_ms(1500);
// create_process(k, "process3", false, true);

autoexec();

qemu_log("System initialized everything at: %f seconds.", (double) (getTicks() - kernel_start_time) / getFrequency());

// char* args[] = {};
Expand Down
21 changes: 21 additions & 0 deletions kernel/src/ports/eBat/FileIO.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "kernel.h"
#include "eBat.h"
#include "eBatRuntime.h"

/**
* Проверка наличии файла или папки
* @module FileIO.Exits
* @param path Путь к файлу
* @return 1 - Если файл найден или 0 - если нет
*/
int bat_runtime_fileio_exist(char* path){
/// Insert your code
bat_debug("[RUNTIME] [FileIO] [Exits] %s\n", path);
bool ret = file_exists(path);
return ret;
}

int bat_runtime_fileio_write(const char *filename, const char *text, int mode) {
/// Insert your code
return 0;
}
92 changes: 92 additions & 0 deletions kernel/src/ports/eBat/String.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "kernel.h"
#include "eBat.h"
#include "eBatRuntime.h"

int bat_strtol(char *string) {
int number = 0;
int sign = 1;
int i = 0;

// Пропускаем пробелы в начале строки
while (string[i] == ' ' && string[i] != '\0') {
i++;
}

// Обработка знака
if (string[i] == '-' || string[i] == '+') {
sign = (string[i] == '-' ? -1 : 1);
i++;
}

// Извлечение цифр
while (isdigit(string[i]) && string[i] != '\0') {
number = number * 10 + (string[i] - '0');
i++;
}

return number * sign;
}
void bat_trim(char* string){
int start = 0, end = strlen(string) - 1;
while (string[start] == ' ' || string[start] == '\t' || string[start] == '\n' || string[start] == 0xD){
start++;
}
while (string[end] == ' ' || string[end] == '\t' || string[end] == '\n' || string[end] == 0xD){
end--;
}
for (int i = 0; i <= end - start; i++){
string[i] = string[i + start];
}
string[end - start + 1] = '\0';
}

void bat_str_debug(char* string){
return;
bat_debug(" |--- String debug: '%s'\n", string);
int len = strlen(string);
for (int i = 0; i < len; i++){
bat_debug(" |--- [%d | %d] [0x%x] '%c'\n", i+1, len, string[i], string[i]);
}
}

char* bat_strdup(const char *str) {
// Проверяем, не является ли указатель NULL
if (str == NULL) {
return NULL;
}

// Получаем длину исходной строки
size_t len = strlen(str);

// Выделяем память для новой строки (включая один байт для нулевого терминатора)
char *copy = (char*)malloc(len + 1);
memset(copy, 0, len + 1);
if (copy == NULL) {
return NULL; // Проверка на успешное выделение памяти
}

// Копируем строку в новую память
strcpy(copy, str);

return copy; // Возвращаем указатель на новую строку
}

char* bat_toLower(char* str) {
int i;
for (i = 0; str[i] != '\0'; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') { // Проверяем, является ли символ заглавным
str[i] = str[i] + 32; // Преобразуем в строчную букву
}
}
return str; // Возвращаем изменённую строку
}

char* bat_toUpper(char *str) {
int i;
for (i = 0; str[i] != '\0'; i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
str[i] = str[i] - 32;
}
}
return str;
}
69 changes: 69 additions & 0 deletions kernel/src/ports/eBat/System.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "kernel.h"
#include "eBat.h"
#include "eBatRuntime.h"

int bar_runtime_system_exec(int argc, char** argv){
/// Insert your code to execute the "echo" command
bat_debug("[RUNTIME] [System] [EXEC] Count: %d\n", argc);
int ret = cli_handler_ebat(argc, argv);
return ret;
}

/**
* Вывод текста на экран
* @module System.Echo
* @param text - Строка для вывода текст
*/
void bat_runtime_system_echo(char* text, int newline, int endline){
/// Insert your code to execute the "echo" command
bat_debug("[RUNTIME] [System] [ECHO] %s\n", text);
if (text == NULL){
return;
}

//printf("%s%s%s", (newline == 1?"< ":""), text, (endline == 1?" \n":" "));
tty_printf("%s%s%s", (newline == 1?"< ":""), text, (endline == 1?" \n":" "));
}

/**
* Установка значения переменной
* @param key - Ключ
* @param val - Значение
*/
void bat_runtime_system_set(char* key, char* val){
/// Insert your code
//bat_debug("[RUNTIME] [System] [SET] '%s' => '%s'\n", key, val);
//printf("[RUNTIME] [System] [SET] '%s' => '%s'\n", key, val);
//bat_toUpper(key);
//char* get = bat_runtime_system_get(key);

int len_key = (key == NULL?0:strlen(key));
int len_val = (val == NULL?0:strlen(val));

if (key == NULL){
return;
}
if (val == NULL || len_val == 0){
variable_write(key,"");
}
}

/**
* Получение значения переменной
* @param key - Ключ
*/
char* bat_runtime_system_get(char* key){
/// Insert your code
bat_debug("[RUNTIME] [System] [GET] '%s'\n", key);
//bat_toUpper(key);
return variable_read(key);
}


void bat_runtime_system_pause(){
/// Insert your code
bat_debug("[RUNTIME] [System] [Pause]\n");
bat_runtime_system_echo("Please, press button", 1, 1);
getIntKeyboardWait();
///getchar(); - Функция которая ожидает ввода любой клавиши
}
Loading

0 comments on commit d6f5823

Please sign in to comment.