Programs: loading, 1 fake syscall.. (bad) #12
@@ -42,6 +42,8 @@ sudo qemu-system-i386 -drive if=pflash,format=raw,readonly=on,file=/usr/share/OV
|
|||||||
|
|
||||||
Be warned, these are not actual programs in the sense you'd expect. These are indeed functions that are called from the shell, and embedded in the kernel ELF binary. Real programs apart from the kernel are not yet a thing here, but might be one day.
|
Be warned, these are not actual programs in the sense you'd expect. These are indeed functions that are called from the shell, and embedded in the kernel ELF binary. Real programs apart from the kernel are not yet a thing here, but might be one day.
|
||||||
|
|
||||||
|
(Now, there is a 'beginning' of something that we could call real programs, but I still suck at making the syscalls work. One day, one day...)
|
||||||
|
|
||||||
### Step 1 - Making the program and the entry point
|
### Step 1 - Making the program and the entry point
|
||||||
|
|
||||||
To make a program for the OS, first create the appropriate C source file and header file in the `src/programs` subfolder. Name it appropriately, for example `myprogram.c`.
|
To make a program for the OS, first create the appropriate C source file and header file in the `src/programs` subfolder. Name it appropriately, for example `myprogram.c`.
|
||||||
|
|||||||
@@ -143,3 +143,7 @@ Starts a simplified and buggy snake game. You can choose the speed by setting th
|
|||||||
Controls:
|
Controls:
|
||||||
- `q` to quit
|
- `q` to quit
|
||||||
- `wasd` to move
|
- `wasd` to move
|
||||||
|
|
||||||
|
#### `exec <binary>`
|
||||||
|
|
||||||
|
Executes a binary file. Warning: this is highly broken and syscalls aren't working. It's written in a childish manner. Help is always appreciated (lol).
|
||||||
|
|||||||
@@ -120,17 +120,6 @@ void kmain(multiboot2_info *mb_info)
|
|||||||
|
|
||||||
// usually the place where i do testing
|
// 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();
|
timer_install();
|
||||||
keyboard_install();
|
keyboard_install();
|
||||||
printf("[kernel] spawning shell...\n");
|
printf("[kernel] spawning shell...\n");
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ syscall_common_stub:
|
|||||||
|
|
||||||
mov eax, ds
|
mov eax, ds
|
||||||
push eax ; save 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 ds, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ void shell_install()
|
|||||||
register_command("lspci", program_lspci);
|
register_command("lspci", program_lspci);
|
||||||
register_command("naval", program_navalbattle);
|
register_command("naval", program_navalbattle);
|
||||||
register_command("snake", program_snake);
|
register_command("snake", program_snake);
|
||||||
|
register_command("exec", program_exec);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
|
||||||
void handle_syscall(int syscall_number, void* arg)
|
void handle_syscall(int syscall_number)
|
||||||
{
|
{
|
||||||
switch(syscall_number)
|
switch(syscall_number)
|
||||||
{
|
{
|
||||||
@@ -29,5 +29,5 @@ void syscall_handler()
|
|||||||
|
|
||||||
printf("[syscall] syscall_number=%d, arg=%p\n", syscall_number, arg);
|
printf("[syscall] syscall_number=%d, arg=%p\n", syscall_number, arg);
|
||||||
|
|
||||||
handle_syscall(syscall_number, arg);
|
handle_syscall(syscall_number);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#include "../drivers/rtc.h"
|
#include "../drivers/rtc.h"
|
||||||
#include "../kernel/io.h"
|
#include "../kernel/io.h"
|
||||||
#include "../drivers/pci.h"
|
#include "../drivers/pci.h"
|
||||||
|
#include "../kernel/initrd.h"
|
||||||
|
#include "../kernel/kmain.h"
|
||||||
|
|
||||||
// Print a rainbow colorful text for testing
|
// Print a rainbow colorful text for testing
|
||||||
|
|
||||||
@@ -74,7 +76,7 @@ void program_uptime()
|
|||||||
|
|
||||||
void program_help()
|
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
|
// 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()
|
void program_reboot()
|
||||||
{
|
{
|
||||||
@@ -151,3 +153,24 @@ void program_lspci()
|
|||||||
{
|
{
|
||||||
scan_pci_bus();
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,4 +45,7 @@ void program_navalbattle();
|
|||||||
void program_conway();
|
void program_conway();
|
||||||
void program_snake();
|
void program_snake();
|
||||||
|
|
||||||
|
// Binaries loading and execution
|
||||||
|
void program_exec();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user