Add: exec feature for binaries

This commit is contained in:
xamidev
2024-09-23 15:46:58 +02:00
parent 5ad32d3ee1
commit 1fa4b5c70a
8 changed files with 38 additions and 16 deletions

View File

@@ -120,17 +120,6 @@ void kmain(multiboot2_info *mb_info)
// usually the place where i do testing
void* binary_file = load_file_from_initrd((uint8_t*)initrd_addr, "./hello.bin");
if (binary_file == NULL)
{
printf("[debug] Failed to load test program!\n");
} else {
printf("[debug] Test program loaded!\n");
}
void (*program_entry)() = (void (*)())binary_file;
program_entry();
timer_install();
keyboard_install();
printf("[kernel] spawning shell...\n");

View File

@@ -225,7 +225,7 @@ syscall_common_stub:
mov eax, ds
push eax ; save ds
mov ax, 0x10 ; kernel segment
mov ax, 0x01 ; kernel segment YES I CHEATED I KNOW THIS SUCKS
mov ds, ax
mov es, ax

View File

@@ -146,6 +146,7 @@ void shell_install()
register_command("lspci", program_lspci);
register_command("naval", program_navalbattle);
register_command("snake", program_snake);
register_command("exec", program_exec);
for (;;)
{

View File

@@ -5,7 +5,7 @@
#include "../libc/stdio.h"
void handle_syscall(int syscall_number, void* arg)
void handle_syscall(int syscall_number)
{
switch(syscall_number)
{
@@ -29,5 +29,5 @@ void syscall_handler()
printf("[syscall] syscall_number=%d, arg=%p\n", syscall_number, arg);
handle_syscall(syscall_number, arg);
handle_syscall(syscall_number);
}

View File

@@ -11,6 +11,8 @@
#include "../drivers/rtc.h"
#include "../kernel/io.h"
#include "../drivers/pci.h"
#include "../kernel/initrd.h"
#include "../kernel/kmain.h"
// Print a rainbow colorful text for testing
@@ -74,7 +76,7 @@ void program_uptime()
void program_help()
{
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\t bmp\t lspci\t naval\nsnake\n");
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\t bmp\t lspci\t naval\nsnake exec\n");
}
// Panic
@@ -133,7 +135,7 @@ void program_read(int argc, char* argv[])
}
}
// Reboots the machine (might just shutdown)
// Reboots the machine (might just shutdown) (or do nothing if youre lucky)
void program_reboot()
{
@@ -151,3 +153,24 @@ void program_lspci()
{
scan_pci_bus();
}
// Executes binary file
void program_exec(int argc, char* argv[])
{
if (argc < 2)
{
puts("Usage: exec <binary>\n");
return;
}
void* binary_file = load_file_from_initrd((uint8_t*)initrd_addr, argv[1]);
if (binary_file == NULL)
{
printf("[exec] Failed to load program '%s'.\n", argv[1]);
return;
}
void (*program_entry)() = (void (*)())binary_file;
program_entry();
}

View File

@@ -45,4 +45,7 @@ void program_navalbattle();
void program_conway();
void program_snake();
// Binaries loading and execution
void program_exec();
#endif