diff --git a/.bochsrc b/.bochsrc index d7b38b4..c3cac63 100644 --- a/.bochsrc +++ b/.bochsrc @@ -25,7 +25,7 @@ text_snapshot_check: 0 mouse: enabled=0 private_colormap: enabled=0 i440fxsupport: enabled=0 -clock: sync=none, time0=local +clock: sync=realtime, time0=local # no ne2k newharddrivesupport: enabled=1 # no loader diff --git a/kernel/Makefile b/kernel/Makefile index c6d4ded..3279a10 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -9,7 +9,7 @@ NASM_FLAGS=-f aout # C Information: CC=gcc -CC_FLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -I../include -Wall +CC_FLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall # Linker Information: LD=ld diff --git a/kernel/boot.asm b/kernel/boot.asm index 38a1a2f..8281ed4 100644 --- a/kernel/boot.asm +++ b/kernel/boot.asm @@ -157,7 +157,7 @@ newgdtcontinue: call _k_init ;C kernel initialization idle_loop: -; sti + sti hlt jmp idle_loop diff --git a/kernel/char/vconsole.c b/kernel/char/vconsole.c index 23017a9..c5edb37 100644 --- a/kernel/char/vconsole.c +++ b/kernel/char/vconsole.c @@ -9,10 +9,13 @@ #include "mm/vmm.h" #include "lang/asmfuncs.h" #include "console.h" +#include "functions.h" vconsole_t *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs extern int activeConsole; // console subsystem active virtual console number +char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7}; + void vconsole_put_char(minor_t id, int c); void vconsole_update_cursor(minor_t id, u16_t position); void vconsole_update_attribute(minor_t id); @@ -75,6 +78,7 @@ int vconsole_char_write(minor_t id, int c) return -1; int cursorY = vconsoles[id]->cursorPosition / vconsoles[id]->width; int cursorX = vconsoles[id]->cursorPosition % vconsoles[id]->width; + int evalEscapePosition = 0; switch (vconsoles[id]->escapeLevel) { case 2: @@ -96,29 +100,25 @@ int vconsole_char_write(minor_t id, int c) cursorY -= vconsoles[id]->escapeValue[0]; if (cursorY < 0) cursorY = 0; - vconsole_update_cursor(id, cursorY * vconsoles[id]->width + -cursorX); + vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX); break; case 'B': // move cursor down n rows cursorY += vconsoles[id]->escapeValue[0]; if (cursorY >= vconsoles[id]->height) cursorY = vconsoles[id]->height - 1; - vconsole_update_cursor(id, cursorY * vconsoles[id]->width + -cursorX); + vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX); break; case 'C': // move cursor right n columns cursorX -= vconsoles[id]->escapeValue[0]; if (cursorX < 0) cursorX = 0; - vconsole_update_cursor(id, cursorY * vconsoles[id]->width + -cursorX); + vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX); break; case 'D': // move cursor left n columns cursorX += vconsoles[id]->escapeValue[0]; if (cursorX >= vconsoles[id]->width) cursorX = vconsoles[id]->width - 1; - vconsole_update_cursor(id, cursorY * vconsoles[id]->width + -cursorX); + vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX); break; case 'H': case 'f': // move cursor to position (x,y) upper left is (1,1) @@ -132,7 +132,7 @@ cursorX); cursorX = 0; if (cursorX >= vconsoles[id]->width) cursorX = vconsoles[id]->width - 1; - vconsole_update_cursor(id, 0); + vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX); break; case 'J': // clear screen, home cursor memsetw(vconsoles[id]->buffer, 0x0720, vconsoles[id]->width * vconsoles[id]->height); @@ -140,8 +140,7 @@ cursorX); vconsole_update_cursor(id, 0); break; case 'K': // erase line from cursor position (including char. under cursor) to end of line - memsetw(vconsoles[id]->buffer + -vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX); + memsetw(vconsoles[id]->buffer + vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX); vconsole_draw(id); break; case 's': // push cursor position on an internal stack @@ -156,9 +155,9 @@ vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX); } break; case 'm': // set text attributes - for (; vconsoles[id]->escapePosition; vconsoles[id]->escapePosition--) + for (evalEscapePosition = 0; evalEscapePosition <= vconsoles[id]->escapePosition; evalEscapePosition++) { - switch (vconsoles[id]->escapeValue[vconsoles[id]->escapePosition]) + switch (vconsoles[id]->escapeValue[evalEscapePosition]) { case 0: vconsoles[id]->foreground = 0x07; @@ -170,17 +169,17 @@ vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX); vconsole_update_attribute(id); break; case 1: - vconsoles[id]->bold = 1; - vconsole_update_attribute(id); + vconsoles[id]->bold = 1; + vconsole_update_attribute(id); break; case 5: - vconsoles[id]->blink = 1; - vconsole_update_attribute(id); + vconsoles[id]->blink = 1; + vconsole_update_attribute(id); break; case 7: - vconsoles[id]->reverse = 1; - vconsole_update_attribute(id); - break; + vconsoles[id]->reverse = 1; + vconsole_update_attribute(id); + break; case 30: case 31: case 32: @@ -189,9 +188,9 @@ vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX); case 35: case 36: case 37: - vconsoles[id]->foreground = vconsoles[id]->escapeValue[vconsoles[id]->escapePosition] - 30; - vconsole_update_attribute(id); - break; + vconsoles[id]->foreground = ansi2vgaAttr[vconsoles[id]->escapeValue[evalEscapePosition] - 30]; + vconsole_update_attribute(id); + break; case 40: case 41: case 42: @@ -200,11 +199,12 @@ vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX); case 45: case 46: case 47: - vconsoles[id]->background = vconsoles[id]->escapeValue[vconsoles[id]->escapePosition] - 30; - vconsole_update_attribute(id); - break; + vconsoles[id]->background = ansi2vgaAttr[vconsoles[id]->escapeValue[evalEscapePosition] - 40]; + vconsole_update_attribute(id); + break; } } + vconsoles[id]->escapePosition = 0; break; } memsetd(vconsoles[id]->escapeValue, 0, 8); @@ -238,27 +238,21 @@ void vconsole_put_char(minor_t id, int c) { case '\t': if (vconsoles[id]->cursorPosition % 8) - vconsoles[id]->cursorPosition += (8 - (vconsoles[id]->cursorPosition % 8)); + vconsole_update_cursor(id, vconsoles[id]->cursorPosition + (8 - (vconsoles[id]->cursorPosition % 8))); else - vconsoles[id]->cursorPosition += 8; - if (id == activeConsole) - console_update_cursor(id, vconsoles[id]->cursorPosition); + vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 8); break; case '\n': if (vconsoles[id]->cursorPosition % (vconsoles[id]->width)) - vconsoles[id]->cursorPosition += (vconsoles[id]->width - (vconsoles[id]->cursorPosition % vconsoles[id]->width)); + vconsole_update_cursor(id, vconsoles[id]->cursorPosition + (vconsoles[id]->width - (vconsoles[id]->cursorPosition % vconsoles[id]->width))); else - vconsoles[id]->cursorPosition += vconsoles[id]->width; - if (id == activeConsole) - console_update_cursor(id, vconsoles[id]->cursorPosition); + vconsole_update_cursor(id, vconsoles[id]->cursorPosition + vconsoles[id]->width); break; default: - vconsoles[id]->buffer[vconsoles[id]->cursorPosition << 1] = c | (vconsoles[id]->attribute << 8); + vconsoles[id]->buffer[vconsoles[id]->cursorPosition] = c | (vconsoles[id]->attribute << 8); if (id == activeConsole) console_put_char(id, c | (vconsoles[id]->attribute << 8), vconsoles[id]->cursorPosition); - vconsoles[id]->cursorPosition++; - if (id == activeConsole) - console_update_cursor(id, vconsoles[id]->cursorPosition); + vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 1); } } } @@ -266,6 +260,17 @@ void vconsole_put_char(minor_t id, int c) void vconsole_update_cursor(minor_t id, u16_t position) { vconsoles[id]->cursorPosition = position; + if (position >= (vconsoles[id]->width * vconsoles[id]->height)) // time to scroll console + { + vconsoles[id]->cursorPosition -= vconsoles[id]->width; + memcpyw(vconsoles[id]->buffer, vconsoles[id]->buffer + vconsoles[id]->width, vconsoles[id]->width * (vconsoles[id]->height - 1)); + memsetw(vconsoles[id]->buffer + (vconsoles[id]->width * (vconsoles[id]->height - 1)), 0x0720, vconsoles[id]->width); + if (activeConsole == id) + { + vconsole_draw(id); + return; + } + } if (activeConsole == id) console_update_cursor(id, position); } @@ -275,18 +280,18 @@ void vconsole_update_attribute(minor_t id) if (vconsoles[id]->reverse) { vconsoles[id]->attribute = - vconsoles[id]->blink << 7 | - vconsoles[id]->foreground << 4 | - vconsoles[id]->bold << 3 | - vconsoles[id]->background; + vconsoles[id]->blink << 7 | + vconsoles[id]->foreground << 4 | + vconsoles[id]->bold << 3 | + vconsoles[id]->background; } else { vconsoles[id]->attribute = - vconsoles[id]->blink << 7 | - vconsoles[id]->background << 4 | - vconsoles[id]->bold << 3 | - vconsoles[id]->foreground; + vconsoles[id]->blink << 7 | + vconsoles[id]->background << 4 | + vconsoles[id]->bold << 3 | + vconsoles[id]->foreground; } } diff --git a/kernel/functions.h b/kernel/functions.h index 8eb4cad..a850ff6 100644 --- a/kernel/functions.h +++ b/kernel/functions.h @@ -55,8 +55,8 @@ static inline void timer_init(u32_t freq) { u32_t wait = 1193180 / freq; //how many ticks the PIT must wait before issuing an interrupt outportb(0x43, 0x34); - outportb(0x40, freq); //lsb - outportb(0x40, freq >> 8); //msb + outportb(0x40, wait); //lsb + outportb(0x40, wait >> 8); //msb } //Returns the size of the kernel (code & data) diff --git a/kernel/hos_defines.h b/kernel/hos_defines.h index ce24fbe..06a9e4d 100644 --- a/kernel/hos_defines.h +++ b/kernel/hos_defines.h @@ -8,6 +8,8 @@ #define PARALLEL_DEBUG +#define HOS_TIMER_FREQ 100 + #define VIRT_OFFSET 0xC0000000 #define PHYS_LOAD 0x00108000 #define HEAP_START 0xD0000000 diff --git a/kernel/kernel.c b/kernel/kernel.c index 1de8fcb..3392ffc 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -26,7 +26,8 @@ mb_module_t mb_modules[MAX_MODULES]; mb_apm_t mb_apm_table; byte real_mode_module; char mb_cmdline[256]; -int criticalCounter; +int criticalCounter; // semaphore for if interrupts are disabled +u32_t timer; extern u32_t mm_freepages; @@ -96,7 +97,7 @@ void k_init() pic_remap(0x20, 0x28); pic_mask1(0); //unmask IRQ's 0-7 pic_mask2(0); //unmask IRQ's 8-15 - timer_init(100); + timer_init(HOS_TIMER_FREQ); mm_init(); vmm_init(); // test the memory manager @@ -119,14 +120,8 @@ void k_init() devices_init(); console_init(6); console_activate(1); - kprintf("We can finally see text!\n"); - while (1) - (*(u16_t *)CONSOLE_MEMORY)++; - if (real_mode_module) - { - kprintf("Real mode module present\n"); - } - u16_t *vidMem = (u16_t *)CONSOLE_MEMORY; + kprintf(" \e[31mWe \e[1mcan \e[32mfinally \e[33;45msee\e[0;7m text\e[0m!\n"); + u16_t *vidMem = (u16_t *)(CONSOLE_MEMORY + 160); u16_t i; for (i = 0; i < 256; i++) { @@ -134,17 +129,30 @@ void k_init() if (((u32_t)vidMem % 32) == 0) vidMem += 64; } + if (real_mode_module) + { + kprintf("Real mode module present\n"); + } criticalCounter--; } void isr(u32_t num) { criticalCounter++; - kprintf("Interrupt #%d, CR2 = 0x%x!\n", num, read_cr2()); - halt(); switch (num) { - + case 0x20: // timer interrupt + (*(u16_t *)CONSOLE_MEMORY)++; + timer++; + if (!(timer % (HOS_TIMER_FREQ / 4))) + { + kprintf("Timer int "); + } + pic_eoi(); + break; + default: + kprintf("Unhandled interrupt #%d, CR2 = 0x%x!\n", num, read_cr2()); + halt(); } criticalCounter--; } diff --git a/readme.txt b/readme.txt index ccc2e71..068024b 100644 --- a/readme.txt +++ b/readme.txt @@ -14,14 +14,14 @@ Goals: (A = accomplished, P = in progress, T = todo) (A) PS/2 keyboard & mouse drivers (A) Utilize x86's paging architecture for virtual memory management +(P) Console Manager (P) VFS abstraction layer for a single file system (P) ram disk driver (P) devfs file system driver +(P) ext2 file system support -(T) ext2 file system support (T) vfat file system support (T) Multitasking support -(T) Console Manager (T) HASH command shell (T) Window Manager (T) Various other utilities/applications