diff --git a/kernel/Makefile b/kernel/Makefile index fef7f17..4e9dfe6 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -54,7 +54,6 @@ C_Kernel: $(CPP) $(CPP_FLAGS) -c sys/pic.cpp -o pic.o $(CPP) $(CPP_FLAGS) -c sys/io.cpp -o io.o $(CPP) $(CPP_FLAGS) -c sys/cmos.cpp -o cmos.o - $(CPP) $(CPP_FLAGS) -c lang/string.cpp -o string.o $(CPP) $(CPP_FLAGS) -c video/stdfont.cpp -o stdfont.o $(CPP) $(CPP_FLAGS) -c video/video.cpp -o video.o $(CPP) $(CPP_FLAGS) -c block/fdc.cpp -o fdc.o @@ -63,6 +62,7 @@ C_Kernel: $(CPP) $(CPP_FLAGS) -c mm/mm.cpp -o mm.o $(CPP) $(CPP_FLAGS) -c mm/vmm.cpp -o vmm.o $(CPP) $(CPP_FLAGS) -c hos_defines.cpp -o hos_defines.o + $(CPP) $(CPP_FLAGS) -c lang/string.cpp -o string.o $(CPP) $(CPP_FLAGS) -c fs/vfs.cpp -o vfs.o ################################################# diff --git a/kernel/char/mouse.cpp b/kernel/char/mouse.cpp index 82cff4c..f9db120 100644 --- a/kernel/char/mouse.cpp +++ b/kernel/char/mouse.cpp @@ -21,9 +21,9 @@ void mouse_init() outportb(0x64, 0x20); //tell keyboard controller we are going to read keyboard controller command byte byte temp = inportb(0x60); //read keyboard controller command byte outportb(0x64, 0x60); //tell keyboard controller we are going to write keyboard controller command byte - outportb(0x60, 0x03 | (temp&0x40)); //write keyboard controller command byte: enable mouse/keyboard ints, include original XLATE bit from temp (bit6) + outportb(0x60, 0x03 | (temp & 0x40)); //write keyboard controller command byte: enable mouse/keyboard ints, include original XLATE bit from temp (bit6) - outportb(0x64, 0xA8); //enable mouse port + outportb(0x64, 0xA8); //enable mouse port outportb(0x64, 0xD4); //send command to mouse, not kbd outportb(0x60, 0xF4); //enable data reporting diff --git a/kernel/fs/vfat.cpp b/kernel/fs/vfat.cpp index 78fd482..c374e69 100644 --- a/kernel/fs/vfat.cpp +++ b/kernel/fs/vfat.cpp @@ -7,7 +7,7 @@ #include "hos_defines.h" #include "fs/vfs.h" #include "mm/vmm.h" -#include "string/string.h" +#include "lang/string.h" //From Microsoft's FAT32 File System Specification DSKSZTOSECPERCLUS DskTableFAT16 [] = diff --git a/kernel/fs/vfs.cpp b/kernel/fs/vfs.cpp index a017943..667b8d0 100644 --- a/kernel/fs/vfs.cpp +++ b/kernel/fs/vfs.cpp @@ -3,9 +3,9 @@ // Date: 03/11/04 // Modified: 03/16/04 -#include "hos_defines.h" #include "vfs.h" //#include "fs/vfat.h" +#include "hos_defines.h" //#include "block/rd.h" //#include "block/loop.h" #include "lang/LinkedList.h" @@ -13,7 +13,27 @@ void vfs_init() { - + LinkedList test; + for (int i = 0; i < 100; i++) + test.insert(i/2, i); + printf("num: %d\t", test.numElements()); + for (int i = 0; i < test.numElements(); i++) + printf("%d\t", test[i]); + while (test.numElements()) + test.pop_back(); + printf("\n"); + for (int i = 0; i < 6; i++) + test.push_back(i << 1); + for (int i = 0; i < test.numElements(); i++) + printf("%d\t", test[i]); + printf("\nnum: %d\t", test.numElements()); + while (test.numElements()) + { + test.remove(0); + for (int i = 0; i < test.numElements(); i++) + printf("%d\t", test[i]); + printf("\n"); + } } diff --git a/kernel/functions.h b/kernel/functions.h index 568912e..66cf220 100644 --- a/kernel/functions.h +++ b/kernel/functions.h @@ -28,17 +28,22 @@ static inline void disable_ints() //Restarts the computer static inline void restart() { - enable_ints(); +/* enable_ints(); byte temp; do { temp = inportb(0x64); if (temp & 1) - inportb(0x60); + inportb(0x60); } while(temp & 2); + outportb(0x64, 0xD4); //send command to mouse, not kbd + outportb(0x60, 0xF5); //disable data reporting + + outportb(0x64, 0xA7); //disable mouse port +*/ + outportb(0x64, 0xfe); //restart - outportb (0x64, 0xfe); for (;;) {} } diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 2499d1a..2dbd652 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -2,7 +2,7 @@ // Author: Josh Holtrop // Date: 08/13/03 // Holtrop's Operating System - Version 0.13 -// Modified: 03/08/04 +// Modified: 05/21/04 #include "hos_defines.h" //#DEFINE's for kernel @@ -11,22 +11,22 @@ #include "kio.h" //kernel input/output functions #include "mm/mm.h" //physical memory management functions #include "mm/vmm.h" //virtual memory management & paging functions +#include "block/fdc.h" //Floppy Disk Controller #include "char/keyboard.h" //generic keyboard driver & functions #include "char/mouse.h" //generic ps/2 mouse driver & functions -#include "block/fdc.h" //Floppy Disk Controller functions #include "sys/cmos.h" //CMOS interface functions #include "sys/io.h" //port i/o functions #include "sys/pic.h" //Programmable Interrupt Controller functions #include "sys/rtc.h" //Real Time Clock functions #include "video/video.h" //video functions -#include "fs/vfs.h" +#include "fs/vfs.h" //Virtual File System extern "C" { void isr(dword num); void k_init(); -dword timer = 0; +dword timer; //Main kernel initialization method void k_init() @@ -43,8 +43,11 @@ void k_init() mouse_init(); pic_mask1(0); //unmask IRQ's 0-7 pic_mask2(0); //unmask IRQ's 8-15 + timer = 0; + enable_ints(); kbd_resetLEDs(); //after enabling interrupts!! +// vfs_init(); if (video_Mode()) { int w = video_getWidth(), h = video_getHeight(); @@ -68,8 +71,6 @@ void k_init() printf("Built on %s at %s\n", __DATE__, __TIME__); printf("%b/%b/%b %b:%b:%b\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond()); - vfs_init(); - dword key = 0; for (;;) { @@ -89,7 +90,7 @@ void isr(dword num) halt(); break; case 0x20: // IRQ0 - timer interrupt - timer++; + /*timer++; (*(byte *)(0xc00b8000))++; if (!(timer % 100)) { @@ -97,7 +98,7 @@ void isr(dword num) kio_writeCursorPosition(72); printf("%b:%b:%b\n", rtc_readHour(), rtc_readMinute(), rtc_readSecond()); kio_writeCursorPosition(curPos); - } + }*/ pic_eoi(); break; case 0x21: // IRQ1 - keyboard interrupt diff --git a/kernel/kio.cpp b/kernel/kio.cpp index 266baeb..e54d589 100644 --- a/kernel/kio.cpp +++ b/kernel/kio.cpp @@ -8,8 +8,7 @@ #include "asmfuncs.h" #include "video/video.h" -dword graphical; -dword cursorPosition; //Caches the current cursor position +dword cursorPosition; //Caches the current cursor position word console_memory[2000]; //holds a copy of the console's memory // This is the main output routine, it uses a format string and a variable @@ -18,9 +17,14 @@ extern "C" { void kio_init() { - graphical = video_Mode(); cursorPosition = 0; writeCursorPosition(0); + word *vidmem = (word *)0xC00B8000; + for (int i = 0; i < 2000; i++) + { + console_memory[i] = 0x0720; + vidmem[i] = 0x0720; + } } void printf(char *fmt, ...) @@ -86,7 +90,7 @@ void printf(char *fmt, ...) // This function draws a single character void putc(dword chr) { - char charac = (char)chr; + char charac = (char)chr; word *vidmem = (word *)0xC00B8000; if (charac == '\n') { @@ -104,7 +108,7 @@ void putc(dword chr) } else { - if (graphical) + if (video_Mode()) { console_memory[cursorPosition] = charac | 0x0700; kio_drawConsoleChar(cursorPosition); @@ -121,7 +125,7 @@ void putc(dword chr) kio_console_scroll(); cursorPosition = 2000-80; } - if (!graphical) + if (!video_Mode()) writeCursorPosition(cursorPosition); } @@ -158,7 +162,7 @@ void kio_console_scroll() { memcpyd(console_memory, console_memory + 80, 960); memsetw(console_memory + 1920, 0x0720, 80); - if (graphical) + if (video_Mode()) kio_drawConsole(); else memcpyd((void *)0xC00B8000, console_memory, 1000); @@ -168,7 +172,7 @@ void kio_console_scroll() void kio_console_cls() { memsetw(console_memory, 0x0720, 2000); - if (graphical) + if (video_Mode()) kio_drawConsole(); else memcpyd((void *)0xC00B8000, console_memory, 1000); @@ -219,9 +223,9 @@ dword kio_getCursorPosition() void kio_writeCursorPosition(dword position) { cursorPosition = position; - if (!graphical) - writeCursorPosition(position); + writeCursorPosition(position); } } + diff --git a/kernel/lang/LinkedList.cpp b/kernel/lang/LinkedList.cpp new file mode 100644 index 0000000..a061daf --- /dev/null +++ b/kernel/lang/LinkedList.cpp @@ -0,0 +1,3 @@ + +#include "LinkedList.h" + diff --git a/kernel/lang/LinkedList.h b/kernel/lang/LinkedList.h index 5d7afa4..29c06f1 100644 --- a/kernel/lang/LinkedList.h +++ b/kernel/lang/LinkedList.h @@ -106,7 +106,7 @@ LinkedList::LinkedList() template LinkedList & LinkedList::insert(int index, Element e) { - if (index == count) + if (index == count-1) push_back(e); else if (index >= 0 && index < count) { diff --git a/kernel/mm/mm.cpp b/kernel/mm/mm.cpp index 974ec71..16f3795 100644 --- a/kernel/mm/mm.cpp +++ b/kernel/mm/mm.cpp @@ -8,8 +8,8 @@ //The total amount of physical memory available (bytes, 1 bit per page) #define BITMAP_SIZE 0x20000 -dword mm_totalmem = 0; -dword mm_megabytes = 0; +dword mm_totalmem; +dword mm_megabytes; byte page_bitmap[BITMAP_SIZE]; //used to store a bit for each page that is used, 0 if available //0x20000*(8 bits/byte)=0x100000 pages in 4gb total @@ -17,6 +17,7 @@ byte page_bitmap[BITMAP_SIZE]; //used to store a bit for each page that is used, // memory areas returned by bios interrupt 0x8E20 void mm_init() { + mm_totalmem = mm_megabytes = 0; dword memmap_entries = *(dword *)BOOT_MEMMAP_ENTRIES; memmap_entry *maps = (memmap_entry *) BOOT_FIRST_MEMMAP; dword a; diff --git a/kernel/mm/vmm.cpp b/kernel/mm/vmm.cpp index cf648cf..4087c64 100644 --- a/kernel/mm/vmm.cpp +++ b/kernel/mm/vmm.cpp @@ -8,18 +8,18 @@ #include "vmm.h" #include "asmfuncs.h" #include "mm/mm.h" +#include "video/video.h" HeapEntry *firstHeapEntry = (HeapEntry *)0xD0000000; //this is where heap memory starts // This is the initialization procedure for the Virtual Memory Manager -// It sets up the final page directory/page table setup and maps video memory, if present +// It sets up the final page directory/page table setup void vmm_init() { unsigned int *pageTables = (unsigned int *)0xC0104000; //this is the location of the page directory pageTables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself pageTables[0] = 0; invlpg_(0); - unsigned int firstHeapEntryBlock = (unsigned int)mm_palloc(); vmm_map1((unsigned int)firstHeapEntry, firstHeapEntryBlock); HeapEntryBlock *heb = (HeapEntryBlock *)firstHeapEntry; @@ -30,6 +30,13 @@ void vmm_init() heb->entry[1].base = (unsigned int)firstHeapEntry+4096; //this is the start of the rest of the kernel's heap memory heb->entry[1].size = 0x10000000-4096; //the rest of the kernel's heap memory: 256mb - 4kb heb->entry[1].attributes = VMM_HE_HOLE; //this is a hole - an unmapped section of heap memory + + unsigned int vidPages = video_getWidth() * video_getHeight() * (video_getBitsPerPixel() >> 3); + if (vidPages % 4096) + vidPages = (vidPages >> 12) + 1; + else + vidPages = (vidPages >> 12); + vmm_mapn(0xF0000000, video_getPhysBasePtr(), vidPages); } @@ -122,7 +129,7 @@ void *malloc(unsigned int bytes) void *vmm_getFreeChunk(unsigned int bytes) { HeapEntry *he = firstHeapEntry; - for (;;) + while (he) { if (he->attributes == VMM_HE_FREE) { @@ -143,8 +150,6 @@ void *vmm_getFreeChunk(unsigned int bytes) } } he = (HeapEntry *)he->link; - if (!he) - break; } return 0; } @@ -161,7 +166,7 @@ void vmm_coalesceHeapEntry(HeapEntry *he) return; } HeapEntry *hec = firstHeapEntry; - for (;;) + while (hec) { if (hec->attributes == he->attributes) { @@ -178,8 +183,6 @@ void vmm_coalesceHeapEntry(HeapEntry *he) } } hec = (HeapEntry *)hec->link; - if (!hec) - break; } } @@ -259,12 +262,9 @@ void vmm_addHeapEntryBlock() HeapEntry *vmm_getLastHeapEntry() { HeapEntry *he = firstHeapEntry; - for (;;) - { - if (he->link == 0) - return he; + while (he) he = (HeapEntry *)he->link; - } + return he; } @@ -272,13 +272,11 @@ HeapEntry *vmm_getLastHeapEntry() HeapEntry *vmm_getFirstHoleHeapEntry(unsigned int minBytes) { HeapEntry *he = firstHeapEntry; - for (;;) + while (he) { if ((he->attributes == VMM_HE_HOLE) && (he->size >= minBytes)) return he; he = (HeapEntry *)he->link; - if (!he) - break; } return 0; } @@ -288,13 +286,11 @@ HeapEntry *vmm_getFirstHoleHeapEntry(unsigned int minBytes) HeapEntry *vmm_getFirstUnusedHeapEntry() { HeapEntry *he = firstHeapEntry; - for (;;) + while (he) { if (he->attributes == VMM_HE_UNUSED) return he; he = (HeapEntry *)he->link; - if (!he) - break; } return 0; } @@ -305,13 +301,11 @@ unsigned int vmm_heapEntriesLeft() { HeapEntry *he = firstHeapEntry; unsigned int entries = 0; - for (;;) + while (he) { if (he->attributes == VMM_HE_UNUSED) entries++; he = (HeapEntry *)he->link; - if (!he) - break; } return entries; } @@ -333,13 +327,11 @@ int free(void *ptr) HeapEntry *vmm_getHeapEntryByBase(unsigned int base) { HeapEntry *he = firstHeapEntry; - for (;;) + while (he) { if (he->base == base) return he; he = (HeapEntry *)he->link; - if (!he) - break; } return 0; } diff --git a/kernel/video/video.cpp b/kernel/video/video.cpp index 70e7bb8..c5cfcad 100644 --- a/kernel/video/video.cpp +++ b/kernel/video/video.cpp @@ -8,7 +8,7 @@ #include "mm/vmm.h" ModeInfoBlock video_mode; -dword videoMode = 0; //what video mode # we are in, 0 for console mode +dword videoMode; //what video mode # we are in, 0 for console mode word *vid_ptr16 = (word *)0xF0000000; byte *vid_ptr24 = (byte *)0xF0000000; dword *vid_ptr32 = (dword *)0xF0000000; @@ -35,14 +35,14 @@ void video_init() case 32: video_psetp = &video_psetp32; } - - unsigned int vidPages = video_mode.XResolution * video_mode.YResolution * (video_mode.BitsPerPixel >> 3); + +/* unsigned int vidPages = video_mode.XResolution * video_mode.YResolution * (video_mode.BitsPerPixel >> 3); if (vidPages % 4096) vidPages = (vidPages >> 12) + 1; else vidPages = (vidPages >> 12); vmm_mapn(0xF0000000, video_mode.PhysBasePtr, vidPages); - +*/ } //Renders a character using stdfont[] as a bitmask