summaryrefslogtreecommitdiffstats
path: root/system/kernel.c
diff options
context:
space:
mode:
Diffstat (limited to 'system/kernel.c')
-rw-r--r--system/kernel.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/system/kernel.c b/system/kernel.c
new file mode 100644
index 0000000..e8ad3a9
--- /dev/null
+++ b/system/kernel.c
@@ -0,0 +1,115 @@
+/* kernel.c - kernel functions */
+
+#include <system.h>
+#include <console.h>
+
+
+extern unsigned char console_std_attr;
+extern unsigned short console_cur_pos;
+extern unsigned char console_flags;
+
+unsigned char numprint = 0;
+
+#define PRINT_ON if(numprint == 0) { \
+ asm("cli");\
+ console_cursor_off();\
+ }\
+ numprint++
+
+#define PRINT_OFF numprint--;\
+ if(numprint == 0) {\
+ console_cursor_on();\
+ asm("sti");\
+ }
+
+
+void print(unsigned char * text) {
+ print_attr(text, console_std_attr);
+}
+
+void print_attr(unsigned char * text, unsigned char attr) {
+ PRINT_ON;
+ while(*text) {
+ print_char_attr(*text, attr);
+ text++;
+ }
+ PRINT_OFF;
+}
+
+void print_char(unsigned char text) {
+ print_char_attr(text, console_std_attr);
+}
+
+void print_char_attr(unsigned char text, unsigned char attr) {
+ PRINT_ON;
+ switch(text) {
+ case 0x08: // backspace
+ if(console_cur_pos) console_cur_pos--;
+ break;
+ case 0x09: // tab
+ console_cur_pos += (8 - (console_cur_pos % 8));
+ break;
+ case 0x0A: // new line
+ console_cur_pos += (80 - (console_cur_pos % 80));
+ break;
+ case 0x0B: // home
+ case 0x0C: // form feed
+ console_cur_pos = 0;
+ asm(
+ "cld\n"
+ "mov $32,%%ax\n"
+ "mov %%ax,%%es\n"
+ "xor %%edi,%%edi\n"
+ "mov %0,%%ah\n"
+ "mov $0x20,%%al\n"
+ "mov $2000,%%ecx\n"
+ "rep stosw"
+ : : "m" (attr)
+ );
+ break;
+ case 0x0D: // carriage return
+ console_cur_pos -= (console_cur_pos % 80);
+ break;
+ default:
+ ANSI2ASCII(text);
+ asm(
+ "cld\n"
+ "mov $32,%%ax\n"
+ "mov %%ax,%%es\n"
+ "xor %%eax,%%eax\n"
+ "mov %0,%%ax\n"
+ "shl $1,%%eax\n"
+ "mov %%eax,%%edi\n"
+ "mov %1,%%al\n"
+ "mov %2,%%ah\n"
+ "stosw"
+ : : "m" (console_cur_pos), "m" (text), "m" (attr)
+ );
+ console_cur_pos++;
+ }
+ // scroll
+ if(console_cur_pos >= 2000) {
+ console_cur_pos -= 80;
+ asm(
+ "cld\n"
+ "push %%ds\n"
+
+ "mov $32,%%ax\n"
+ "mov %%ax,%%ds\n"
+ "mov %%ax,%%es\n"
+ "mov $1920,%%ecx\n"
+ "mov $160,%%esi\n"
+ "xor %%edi,%%edi\n"
+ "rep movsw\n"
+
+ "mov $80,%%cx\n"
+ "mov %%cs:%0,%%ah\n"
+ "mov $0x20,%%al\n"
+ "rep stosw\n"
+
+ "pop %%ds"
+ : : "m" (console_std_attr)
+ );
+ }
+ PRINT_OFF;
+}