forked from PoliEcho-holding-org/kern
Added temporary Gets() Syscall
This commit is contained in:
@@ -68,6 +68,7 @@ run:
|
||||
-m 256M\
|
||||
-accel tcg\
|
||||
-rtc base=localtime,clock=host,driftfix=slew
|
||||
# -machine pcspk-audiodev=test
|
||||
|
||||
# Clean all build files
|
||||
clean:
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
|
||||
#include <interrupt/pit.h>
|
||||
#include <screen/text.h>
|
||||
#include <keyboard/keyboard.h>
|
||||
|
||||
// System call count
|
||||
#define MAX_SYSCALLS 2
|
||||
#define MAX_SYSCALLS 3
|
||||
|
||||
// Args: ebx - number of miliseconds
|
||||
void sys_sleep() {
|
||||
@@ -19,7 +20,7 @@ void sys_sleep() {
|
||||
}
|
||||
|
||||
// TODO: Use a Write() syscall and write to stdout
|
||||
// Args: ebx - string pointer
|
||||
// Args: ebx - char* string
|
||||
void sys_puts() {
|
||||
char* s;
|
||||
__asm__ volatile ("movl %%ebx, %0" : "=r"(s));
|
||||
@@ -27,10 +28,18 @@ void sys_puts() {
|
||||
print(s);
|
||||
}
|
||||
|
||||
// TODO: Use a Read() sycall and read from stdin
|
||||
// Returns: ebx - char* string
|
||||
void sys_gets() {
|
||||
char* s = read();
|
||||
__asm__ volatile ("movl %0, %%ebx" :: "r"(s));
|
||||
}
|
||||
|
||||
// System call table
|
||||
void* syscalls[MAX_SYSCALLS] = {
|
||||
sys_sleep,
|
||||
sys_puts,
|
||||
sys_gets,
|
||||
};
|
||||
|
||||
// int 0x80 - Syscall interrupt, handled by this function
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef struct {
|
||||
keyboardState_t keyboard;
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void keyboardHandler(intFrame_t* iframe) {
|
||||
void keyboardHandler(intFrame_t* iframe) { // TODO: Make this better and be able to read multi-byte scancode
|
||||
uint8_t scancode = inb(0x60);
|
||||
char c = US_Keyboard[keyboard.shift][scancode];
|
||||
|
||||
@@ -38,13 +38,13 @@ void keyboardHandler(intFrame_t* iframe) {
|
||||
|
||||
char getc() {
|
||||
keyboard.character = '\0';
|
||||
while (keyboard.character == '\0') __asm__ volatile ("hlt");
|
||||
while (keyboard.character == '\0') { __asm__ volatile ("hlt"); }
|
||||
return keyboard.character;
|
||||
}
|
||||
|
||||
// Reads until a newline
|
||||
char inputBuffer[MAX_INPUT_LENGTH];
|
||||
char* read() {
|
||||
static char inputBuffer[MAX_INPUT_LENGTH];
|
||||
char c;
|
||||
uint8_t len = 0;
|
||||
|
||||
@@ -53,7 +53,7 @@ char* read() {
|
||||
if (len < 1) continue; // Can we backspace?
|
||||
len--;
|
||||
putc(c);
|
||||
} else if (len + 1 != MAX_INPUT_LENGTH) { // Check if we can add a new character
|
||||
} else if (len + 1 != MAX_INPUT_LENGTH) { // Check if we can add a new character (this method avoids overflow issues)
|
||||
inputBuffer[len++] = c;
|
||||
putc(c);
|
||||
}
|
||||
|
||||
+5
-9
@@ -1,16 +1,12 @@
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
__attribute__ ((section ("entry")))
|
||||
void main() {
|
||||
*(char*)(0x2000) = 'H';
|
||||
*(char*)(0x2001) = 'e';
|
||||
*(char*)(0x2002) = 'l';
|
||||
*(char*)(0x2003) = 'l';
|
||||
*(char*)(0x2004) = 'o';
|
||||
*(char*)(0x2005) = '!';
|
||||
*(char*)(0x2006) = '\0';
|
||||
__asm__ volatile ("int $0x80" : : "a"(1), "b"(0x2000));
|
||||
sleep(4500); // Wait 4.5 seconds
|
||||
char* msg = read();
|
||||
print(msg);
|
||||
|
||||
sleep(4500);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user