forked from PoliEcho-holding-org/kern
Implemented a basic shell
This commit is contained in:
@@ -11,6 +11,12 @@ _start:
|
|||||||
pop ax
|
pop ax
|
||||||
mov [driveNum], al
|
mov [driveNum], al
|
||||||
call main
|
call main
|
||||||
|
|
||||||
|
; Exit QEMU
|
||||||
|
mov ax, 0x2000
|
||||||
|
mov dx, 0x0604
|
||||||
|
out dx, ax
|
||||||
|
|
||||||
jmp $ ;; If we used cli, hlt we wouldn't have interrupts :/
|
jmp $ ;; If we used cli, hlt we wouldn't have interrupts :/
|
||||||
|
|
||||||
[global driveNum]
|
[global driveNum]
|
||||||
|
|||||||
+36
-4
@@ -8,6 +8,8 @@
|
|||||||
#include "disk.h"
|
#include "disk.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
|
#define PROMPT "#> "
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Interrupts
|
// Interrupts
|
||||||
setupIdt();
|
setupIdt();
|
||||||
@@ -22,12 +24,42 @@ void main() {
|
|||||||
|
|
||||||
clear(0x0f);
|
clear(0x0f);
|
||||||
print("kern.\n\n", 0x0f);
|
print("kern.\n\n", 0x0f);
|
||||||
|
|
||||||
|
// Run Interactive Shell Program
|
||||||
|
// TODO: Make it in another file
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
print("> ", 0x0e);
|
print(PROMPT, 0x0a);
|
||||||
char* input = read('\n', 0x0f);
|
char* input = read('\n', 0x0f);
|
||||||
if (*input == '\n') continue;
|
|
||||||
print(input, 0x0b);
|
if (input[0] == '\n') continue;
|
||||||
|
|
||||||
|
char* args;
|
||||||
|
if ((args = strchr(input, ' ')) == NULL) {
|
||||||
|
args = strchr(input, '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
*args = '\0';
|
||||||
|
args++;
|
||||||
|
|
||||||
|
if (strcmp(input, "clear") == 0) {
|
||||||
|
clear(0x0f);
|
||||||
|
} else if (strcmp(input, "echo") == 0) {
|
||||||
|
print(args, 0x0f);
|
||||||
|
} else if (strcmp(input, "exit") == 0) {
|
||||||
|
break;
|
||||||
|
} else if (strcmp(input, "help") == 0) {
|
||||||
|
print("Available Commands:\n", 0x0f);
|
||||||
|
print(" clear | Clears the screen\n", 0x0f);
|
||||||
|
print(" echo | Prints a message to stdout\n", 0x0f);
|
||||||
|
print(" exit | Exits program\n", 0x0f);
|
||||||
|
print(" help | Prints this message\n", 0x0f);
|
||||||
|
// TODO: print(" ls | Lists all available files\n", 0x0f);
|
||||||
|
// TODO: print(" reboot | Reboots the system\n", 0x0f);
|
||||||
|
} else {
|
||||||
|
print("Command not found: ", 0x0c);
|
||||||
|
print(input, 0x0c);
|
||||||
|
putc('\n', 0x0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,6 @@ void outb(uint16_t port, uint8_t data) {
|
|||||||
asm volatile("out %0, %1" :: "a"(data), "Nd"(port));
|
asm volatile("out %0, %1" :: "a"(data), "Nd"(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t inw(uint16_t port) {
|
|
||||||
uint8_t result;
|
|
||||||
asm volatile("in %1, %0" : "=a"(result) : "Nd"(port));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void outw(uint16_t port, uint16_t data) {
|
|
||||||
asm volatile("out %0, %1" :: "a"(data), "Nd"(port));
|
|
||||||
}
|
|
||||||
|
|
||||||
char* memcopy(char* src, char* dst, uint16_t length) {
|
char* memcopy(char* src, char* dst, uint16_t length) {
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
*(dst + i) = *(src + i);
|
*(dst + i) = *(src + i);
|
||||||
@@ -47,7 +37,3 @@ void hlt() {
|
|||||||
asm volatile("hlt");
|
asm volatile("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit() {
|
|
||||||
outw(0x0604, 0x2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
// Port functions
|
// Port functions
|
||||||
uint8_t inb(uint16_t port);
|
uint8_t inb(uint16_t port);
|
||||||
void outb(uint16_t port, uint8_t data);
|
void outb(uint16_t port, uint8_t data);
|
||||||
uint16_t inw(uint16_t port);
|
|
||||||
void outw(uint16_t port, uint16_t data);
|
|
||||||
|
|
||||||
// Memory functions
|
// Memory functions
|
||||||
char* memcopy(char* src, char* dst, uint16_t length);
|
char* memcopy(char* src, char* dst, uint16_t length);
|
||||||
@@ -18,6 +16,4 @@ void cli();
|
|||||||
void sti();
|
void sti();
|
||||||
void hlt();
|
void hlt();
|
||||||
|
|
||||||
void exit();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user