|
@@ -3,6 +3,8 @@
|
|
|
#include <stdint.h>
|
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
+
|
|
|
+static void* heap_end;
|
|
|
|
|
|
/* Check if the compiler thinks if we are targeting the wrong operating system. */
|
|
|
//#if defined(__linux__)
|
|
@@ -57,9 +59,9 @@ static const size_t VGA_HEIGHT = 25;
|
|
|
size_t terminal_row;
|
|
|
size_t terminal_column;
|
|
|
uint8_t terminal_color;
|
|
|
+uint16_t* terminal_buffer;
|
|
|
|
|
|
void terminal_initialize() {
|
|
|
- uint16_t* terminal_buffer;
|
|
|
terminal_row = 0;
|
|
|
terminal_column = 0;
|
|
|
terminal_color = make_color(COLOR_LIGHT_GREY, COLOR_BLACK);
|
|
@@ -77,12 +79,19 @@ void terminal_setcolor(uint8_t color) {
|
|
|
}
|
|
|
|
|
|
void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) {
|
|
|
- uint16_t* terminal_buffer;
|
|
|
const size_t index = y * VGA_WIDTH + x;
|
|
|
terminal_buffer[index] = make_vgaentry(c, color);
|
|
|
}
|
|
|
|
|
|
void terminal_putchar(char c) {
|
|
|
+ if (c==10) {
|
|
|
+ terminal_column=0;
|
|
|
+ terminal_row++;
|
|
|
+ if (terminal_row == VGA_HEIGHT) {
|
|
|
+ terminal_initialize();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
|
|
|
if (++terminal_column == VGA_WIDTH) {
|
|
|
terminal_column = 0;
|
|
@@ -91,36 +100,103 @@ void terminal_putchar(char c) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
void terminal_writestring(const char* data) {
|
|
|
size_t datalen = strlen(data);
|
|
|
for (size_t i = 0; i < datalen; i++)
|
|
|
terminal_putchar(data[i]);
|
|
|
}
|
|
|
|
|
|
-void kernel_main() {
|
|
|
- *((uint16_t*)0xB8000) = 0xf42;
|
|
|
- uint16_t* terminal_buffer;
|
|
|
+int bios_getc(void)
|
|
|
+{
|
|
|
+ uint16_t key_to_rune[] = {
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ '1','2','3','4','5','6','7','8','9','0','/','"',9,
|
|
|
+ '\t','q','w','e','r','t','z','u','i','o','p','-','+',10,
|
|
|
+ 0,'a','s','d','f','g','h','j','k','l','(',')',0,0,'*',
|
|
|
+ 'y','x','c','v','b','n','m',',','.','-',0,
|
|
|
+ 0,0,' ',
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0,
|
|
|
+ 0,0,0,0,0,0,0,0,0,0
|
|
|
+ };
|
|
|
+
|
|
|
+ int key;
|
|
|
+
|
|
|
+ __asm("WaitLoop: in $0x64, %al");
|
|
|
+ __asm( "and $1, %al");
|
|
|
+ __asm( "jz WaitLoop");
|
|
|
+ __asm( "in $0x60, %al");
|
|
|
|
|
|
- terminal_buffer = (uint16_t*)0xB8000;
|
|
|
- for (register int i=0; i<256; i++) {
|
|
|
- terminal_buffer[i]='X'|(COLOR_WHITE << 8);
|
|
|
+ __asm("mov %%al,%0" : "=m" (key));
|
|
|
+ if (key>0 && key<0x70) {
|
|
|
+ return(key_to_rune[key]);
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+void uart_puts(char* str) {
|
|
|
+ terminal_writestring(str);
|
|
|
+}
|
|
|
|
|
|
- *((uint16_t*)0xB8000) = 0xf43;
|
|
|
+void uart_putc(char c) {
|
|
|
+ terminal_putchar(c);
|
|
|
+}
|
|
|
+
|
|
|
+char uart_getc() {
|
|
|
+ return bios_getc();
|
|
|
+}
|
|
|
+
|
|
|
+#define GETLINE_MAX 256
|
|
|
+static char getline_buf[GETLINE_MAX];
|
|
|
+
|
|
|
+ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
|
|
+ printf("\r\n");
|
|
|
+ int i = 0;
|
|
|
+ int k = 0;
|
|
|
+ while (k!=10 && i<GETLINE_MAX) {
|
|
|
+ k = uart_getc();
|
|
|
+ if (k>0) {
|
|
|
+ uart_putc(k);
|
|
|
+ getline_buf[i] = k;
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ *n = i;
|
|
|
+ *lineptr = getline_buf;
|
|
|
|
|
|
- while(1) {};
|
|
|
+ return i;
|
|
|
+}
|
|
|
+
|
|
|
+#include "debug_util.c"
|
|
|
+#include "libc_glue.c"
|
|
|
+
|
|
|
+int main(int argc, char *argv[]);
|
|
|
+
|
|
|
+void kernel_main() {
|
|
|
+ terminal_buffer = (uint16_t*)0xB8000;
|
|
|
+ for (int i=0; i<80*23; i++) {
|
|
|
+ terminal_buffer[i]='*'|(COLOR_WHITE << 8);
|
|
|
+ }
|
|
|
|
|
|
/* Initialize terminal interface */
|
|
|
terminal_initialize();
|
|
|
-
|
|
|
- /* Since there is no support for newlines in terminal_putchar
|
|
|
- * yet, '\n' will produce some VGA specific character instead.
|
|
|
- * This is normal.
|
|
|
- */
|
|
|
- terminal_writestring("Hello, kernel World!\n");
|
|
|
+
|
|
|
+ heap_end = (void*)0x200000;
|
|
|
+
|
|
|
+ main(0,NULL);
|
|
|
}
|
|
|
|
|
|
-extern _IO_ssize_t getline(char **__restrict __lineptr, size_t *__restrict __n, FILE *__restrict __stream) {
|
|
|
+/*extern _IO_ssize_t getline(char **__restrict __lineptr, size_t *__restrict __n, FILE *__restrict __stream) {
|
|
|
return 0;
|
|
|
}
|
|
|
+*/
|