diff --git a/kernel/Makefile b/kernel/Makefile index 2739a72..fef7f17 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -30,7 +30,7 @@ LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld # Linking the kernel together # ############################### all: Asm_Kernel Asm_Functions C_Kernel - $(LD) $(LD_FLAGS) -o kernel.bin -Map ./lst/LDout.doc ks.o kernel.o asmfuncs.o fdc.o keyboard.o kio.o mm.o mouse.o stdfont.o video.o vmm.o rtc.o pic.o io.o string.o cmos.o hos_defines.o + $(LD) $(LD_FLAGS) -o kernel.bin -Map ./lst/LDout.doc ks.o kernel.o asmfuncs.o fdc.o keyboard.o kio.o mm.o mouse.o stdfont.o video.o vmm.o rtc.o pic.o io.o string.o cmos.o hos_defines.o vfs.o ########################## # Assembly Kernel Loader # @@ -54,7 +54,7 @@ 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 string/string.cpp -o string.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 +63,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 fs/vfs.cpp -o vfs.o ################################################# # Clean up the source directory of any binaries # diff --git a/kernel/fs/vfs.cpp b/kernel/fs/vfs.cpp index b9798be..a017943 100644 --- a/kernel/fs/vfs.cpp +++ b/kernel/fs/vfs.cpp @@ -3,112 +3,17 @@ // Date: 03/11/04 // Modified: 03/16/04 -#include "vfs.h" -#include "fs/vfat.h" #include "hos_defines.h" -#include "block/rd.h" -#include "block/loop.h" +#include "vfs.h" +//#include "fs/vfat.h" +//#include "block/rd.h" +//#include "block/loop.h" +#include "lang/LinkedList.h" +#include "kio.h" -Volume *firstVolume = 0; -Volume *rootVolume = 0; -MountPoint *firstMountPoint = 0; - -void vfs_init() +void vfs_init() { - if(*(byte *)BOOT_HASRD) //bootloader loaded an initial ram disk - { - Volume *initrd = vfs_newVolume(); - RamDisk *rd = rd_newDisk(0xC0200000, 1440*1024); - initrd->diskDevice = rd; - initrd->deviceType = VFS_RD; - strcpy(initrd->label, "rd0"); - initrd->link = 0; - rootVolume = initrd; - } -} - -Volume *vfs_newVolume() -{ - Volume *vol = malloc(sizeof(Volume)); - vfs_getLastVolume()->link = vol; - return vol; -} - - -Volume *vfs_getLastVolume() -{ - Volume *vol = firstVolume; - while (vol) - vol = vol->link; - return vol; -} - -int vfs_readSector(Volume *vol, dword sector, byte *buffer) -{ - switch(vol->deviceType) - { - case VFS_RD: - return rd_readSector(vol->diskDevice, sector, buffer); - case VFS_LOOP: - return loop_readSector(vol->diskDevice, sector, buffer); - default: - return -1; - } -} - -int vfs_writeSector(Volume *vol, dword sector, byte *buffer) -{ - switch(vol->deviceType) - { - case VFS_RD: - return rd_writeSector(vol->diskDevice, sector, buffer); - case VFS_LOOP: - return loop_writeSector(vol->diskDevice, sector, buffer); - default: - return -1; - } -} - -int vfs_readSectorn(Volume *vol, dword sector, byte *buffer, int n) -{ - int r; - for (; n > 0; --n, ++sector, buffer += 512) - { - r = vfs_readSector(vol, sector, buffer); - if (r) return r; - } - return 0; -} - -int vfs_writeSectorn(Volume *vol, dword sector, byte *buffer, int n) -{ - int r; - for (; n > 0; --n, ++sector, buffer += 512) - { - r = vfs_writeSector(vol, sector, buffer); - if (r) return r; - } - return 0; -} - -int vfs_readFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize) -{ - switch(vol->fsType) - { - default: - return -1; - } -} - - -int vfs_writeFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize) -{ - switch(vol->fsType) - { - default: - return -1; - } } diff --git a/kernel/fs/vfs.h b/kernel/fs/vfs.h index 45e1829..851afff 100644 --- a/kernel/fs/vfs.h +++ b/kernel/fs/vfs.h @@ -1,58 +1,14 @@ // vfs.h // Author: Josh Holtrop // Date: 03/11/04 -// Modified: 03/16/04 +// Modified: 05/21/04 #ifndef __HOS_VFS__ #define __HOS_VFS__ __HOS_VFS__ #include "hos_defines.h" -#define VFS_LABEL_LENGTH 8 - -typedef struct -{ - void *diskDevice; //pointer to device-dependent structure - int length; //size of the volume in bytes - int deviceType; //one of VFS_DISK_TYPES - int fsType; //one of VFS_FS_TYPES - char label[VFS_LABEL_LENGTH]; //descriptive volume label - void *link; //link to next volume in linked list -} Volume; - -typedef struct -{ - dword location; //location used by disk driver - dword dataLocation; //location used by disk driver - dword position; //read/write position in file - dword attributes; //read/write - dword fileSize; //number of bytes the file takes - Volume *vol; //what volume this file is on -} FILE; - -typedef struct -{ - char *device; - char *mount; - void *mp; -} MountPoint; - -#define FILE_READ 1 -#define FILE_WRITE 2 -#define FILE_READ_WRITE 3 - -enum VFS_DISK_TYPES {VFS_NODISK, VFS_RD, VFS_FD, VFS_HD, VFS_LOOP, VFS_NUM_DISK_TYPES}; -enum VFS_FS_TYPES {VFS_NOFS, VFS_VFAT, VFS_EXT2, VFS_NUM_FS_TYPES}; - -void vfs_init(); -Volume *vfs_newVolume(); -Volume *vfs_getLastVolume(); -int vfs_readSector(Volume *vol, dword sector, byte *buffer); -int vfs_writeSector(Volume *vol, dword sector, byte *buffer); -int vfs_readSectorn(Volume *vol, dword sector, byte *buffer, int n); -int vfs_writeSectorn(Volume *vol, dword sector, byte *buffer, int n); -int vfs_readFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize); -int vfs_writeFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize); +void vfs_init(); #endif diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 3b042c9..2499d1a 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -14,13 +14,12 @@ #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 "string/string.h" //string 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/stdfont.h" //Standard font bitmask array #include "video/video.h" //video functions +#include "fs/vfs.h" extern "C" { @@ -34,10 +33,11 @@ void k_init() { // ===== Initialization fdc_sendDOR(0x0C); //turn off floppy motor!! - kio_console_cls(); - video_init(); mm_init(); vmm_init(); + video_init(); + kio_init(); + kio_console_cls(); pic_remap(0x20, 0x28); timer_init(); mouse_init(); @@ -68,6 +68,8 @@ 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 (;;) { diff --git a/kernel/kio.cpp b/kernel/kio.cpp index e625dac..266baeb 100644 --- a/kernel/kio.cpp +++ b/kernel/kio.cpp @@ -8,12 +8,21 @@ #include "asmfuncs.h" #include "video/video.h" -dword cursorPosition = 0; //Caches the current cursor position +dword graphical; +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 // number of arguments to print formatted text extern "C" { + +void kio_init() +{ + graphical = video_Mode(); + cursorPosition = 0; + writeCursorPosition(0); +} + void printf(char *fmt, ...) { dword *params = ((dword *)(&fmt)) + 1; //points to the first paramater @@ -95,7 +104,7 @@ void putc(dword chr) } else { - if (video_Mode()) + if (graphical) { console_memory[cursorPosition] = charac | 0x0700; kio_drawConsoleChar(cursorPosition); @@ -112,7 +121,7 @@ void putc(dword chr) kio_console_scroll(); cursorPosition = 2000-80; } - if (!video_Mode()) + if (!graphical) writeCursorPosition(cursorPosition); } @@ -149,7 +158,7 @@ void kio_console_scroll() { memcpyd(console_memory, console_memory + 80, 960); memsetw(console_memory + 1920, 0x0720, 80); - if (video_Mode()) + if (graphical) kio_drawConsole(); else memcpyd((void *)0xC00B8000, console_memory, 1000); @@ -159,7 +168,7 @@ void kio_console_scroll() void kio_console_cls() { memsetw(console_memory, 0x0720, 2000); - if (video_Mode()) + if (graphical) kio_drawConsole(); else memcpyd((void *)0xC00B8000, console_memory, 1000); @@ -210,6 +219,8 @@ dword kio_getCursorPosition() void kio_writeCursorPosition(dword position) { cursorPosition = position; + if (!graphical) + writeCursorPosition(position); } diff --git a/kernel/kio.h b/kernel/kio.h index 8ba488c..5af2c92 100644 --- a/kernel/kio.h +++ b/kernel/kio.h @@ -10,6 +10,7 @@ extern "C" { + void kio_init(); void printf(char *fmt, ...); void putc(dword chr); void putHex(dword number); diff --git a/kernel/lang/LinkedList.h b/kernel/lang/LinkedList.h new file mode 100644 index 0000000..5d7afa4 --- /dev/null +++ b/kernel/lang/LinkedList.h @@ -0,0 +1,180 @@ + +template +class LinkedList +{ +private: + class LinkedNode + { + public: + LinkedNode() + { + prev = next = 0; + } + LinkedNode(Element dataElement) + { + data = dataElement; + prev = next = 0; + } + Element data; + LinkedNode *next; + LinkedNode *prev; + }; + + LinkedNode *firstNode; + LinkedNode *lastNode; + int count; + +public: + class iterator + { + private: + LinkedNode *theNode; + public: + iterator(LinkedNode & node) + { + theNode = &node; + } + iterator(LinkedNode *node) + { + theNode = node; + } + Element & operator*() + { + return theNode->data; + } + Element & operator++() + { + theNode = theNode->next; + return theNode->data; + } + Element & operator++(int dum) + { + theNode = theNode->next; + return theNode->prev->data; + } + }; + + class reverse_iterator + { + private: + LinkedNode *theNode; + public: + reverse_iterator(LinkedNode & node) + { + theNode = &node; + } + reverse_iterator(LinkedNode *node) + { + theNode = node; + } + Element & operator*() + { + return theNode->data; + } + Element & operator++() + { + theNode = theNode->prev; + return theNode->data; + } + Element & operator++(int dum) + { + theNode = theNode->prev; + return theNode->next->data; + } + }; + + LinkedList(); + int numElements() { return count; } + iterator begin() { return new iterator(firstNode); } + iterator end() { return new iterator(lastNode->next); } + reverse_iterator rbegin() { return new reverse_iterator(lastNode); } + reverse_iterator rend() { return new reverse_iterator(firstNode->prev); } + LinkedList & insert(int index, Element e); + LinkedList & push_back(Element e); + LinkedList & remove(int index); + LinkedList & pop_back(); + Element & operator[](int index); +}; + +template +LinkedList::LinkedList() +{ + firstNode = lastNode = new LinkedNode(); + count = 0; +} + +template +LinkedList & LinkedList::insert(int index, Element e) +{ + if (index == count) + push_back(e); + else if (index >= 0 && index < count) + { + LinkedNode *nptr = firstNode; + for (int i = 0; i <= index; i++) + nptr = nptr->next; + LinkedNode *newptr = new LinkedNode(e); + newptr->next = nptr; + newptr->prev = nptr->prev; + newptr->prev->next = newptr; + nptr->prev = newptr; + count++; + } + return *this; +} + +template +LinkedList & LinkedList::push_back(Element e) +{ + lastNode->next = new LinkedNode(e); + lastNode->next->prev = lastNode; + lastNode = lastNode->next; + count++; + return *this; +} + +template +LinkedList & LinkedList::remove(int index) +{ + if (index == count-1) + pop_back(); + else if (index >= 0 && index < count) + { + LinkedNode *nptr = firstNode; + for (int i = 0; i <= index; i++) + nptr = nptr->next; + nptr->prev->next = nptr->next; + nptr->next->prev = nptr->prev; + delete nptr; + count--; + } + return *this; +} + +template +LinkedList & LinkedList::pop_back() +{ + if (count) + { + lastNode = lastNode->prev; + delete lastNode->next; + lastNode->next = 0; + count--; + } + return *this; +} + +template +Element & LinkedList::operator[](int index) +{ + if (index >= 0 && index < count) + { + LinkedNode *nptr = firstNode; + for (int i = 0; i <= index; i++) + nptr = nptr->next; + return nptr->data; + } + return firstNode->data; +} + + diff --git a/kernel/string/string.cpp b/kernel/lang/string.cpp similarity index 100% rename from kernel/string/string.cpp rename to kernel/lang/string.cpp diff --git a/kernel/string/string.h b/kernel/lang/string.h similarity index 100% rename from kernel/string/string.h rename to kernel/lang/string.h diff --git a/kernel/mm/vmm.cpp b/kernel/mm/vmm.cpp index 16f6cad..cf648cf 100644 --- a/kernel/mm/vmm.cpp +++ b/kernel/mm/vmm.cpp @@ -6,10 +6,8 @@ #include "hos_defines.h" #include "vmm.h" -#include "video/video.h" #include "asmfuncs.h" #include "mm/mm.h" -#include "video/stdfont.h" HeapEntry *firstHeapEntry = (HeapEntry *)0xD0000000; //this is where heap memory starts @@ -21,15 +19,7 @@ void vmm_init() pageTables[0x3FF] = 0x104000|0x03; //the last page directory entry points to the page directory itself pageTables[0] = 0; invlpg_(0); - if (video_Mode()) //we are in a graphical mode - { - 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); - } + unsigned int firstHeapEntryBlock = (unsigned int)mm_palloc(); vmm_map1((unsigned int)firstHeapEntry, firstHeapEntryBlock); HeapEntryBlock *heb = (HeapEntryBlock *)firstHeapEntry; diff --git a/kernel/video/video.cpp b/kernel/video/video.cpp index 60154bf..70e7bb8 100644 --- a/kernel/video/video.cpp +++ b/kernel/video/video.cpp @@ -5,6 +5,7 @@ #include "hos_defines.h" #include "video.h" #include "video/stdfont.h" +#include "mm/vmm.h" ModeInfoBlock video_mode; dword videoMode = 0; //what video mode # we are in, 0 for console mode @@ -34,6 +35,14 @@ void video_init() case 32: video_psetp = &video_psetp32; } + + 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