WKern
Loading...
Searching...
No Matches
wexexec.c
Go to the documentation of this file.
1/*
2WKern - A Bare Metal OS / Kernel I am maKing (For Fun)
3Copyright (C) 2025 Wdboyes13
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#include <io/kio.h>
20#include <utils/util.h>
21#include <wex/stdwex.h>
22#ifdef VMQEMU
23#include <qemu/shutdown.h>
24#endif
25
29void Exec(unsigned char *exec) {
30 Kprintf("Interpreting executable before execution");
31 int entry = exec[0];
32 int symtbl_len = exec[1];
33 int pc = entry;
34 while (exec[pc] != 0xFF) {
35 unsigned char opcode = exec[pc++];
36
37 if (opcode == 0x00) { // CALL
38 unsigned char sym_id = exec[pc++];
39 if (sym_id >= symtbl_len) {
40 Kprintf("Invalid symbol ID");
41 break;
42 }
43
44 unsigned char op = smt[sym_id]; // LooK up actual opcode
45
46 switch (op) {
47 case 0x0A: { // Write (print)
48 while (exec[pc] != 0x00) {
49 Kputchar(exec[pc++]);
50 }
51 pc++; // SKip 0x00
52 break;
53 }
54 case 0x0B: {
55 // Optional: implement read
56 break;
57 }
58 case 0x0C: { // Shutdown
59#ifdef VMQEMU
61#endif
62 break;
63 }
64 case 0x0D: {
65 ZZZ(100);
66 break;
67 }
68 case 0x01: {
69 Kcfp();
70 break;
71 }
72 default: {
73 Kprintf("UnKnown opcode");
74 break;
75 }
76 }
77 } else {
78 Kprintf("Invalid instruction byte\n");
79 break;
80 }
81 }
82}
void Kprintf(const char *fmt,...)
Formatted output to the screen.
Definition printer.c:152
void Kcfp()
Clears the screen by filling the video memory with spaces.
Definition printer.c:28
void Kputchar(char c)
Outputs a single character to the screen at the current cursor position.
Definition printer.c:46
void ZZZ(int ms)
Sleeps for 10ms.
Definition ksleep.c:25
void QemuShutdown()
void Exec(unsigned char *exec)
Definition wexexec.c:29