Import backup from 2004-06-01
This commit is contained in:
parent
6d941b7b16
commit
b4aca026d4
@ -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 vfs.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 cstring.o string.o cmos.o hos_defines.o vfs.o
|
||||
|
||||
##########################
|
||||
# Assembly Kernel Loader #
|
||||
@ -54,6 +54,8 @@ 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/cstring.cpp -o cstring.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
|
||||
@ -62,7 +64,6 @@ 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
|
||||
|
||||
#################################################
|
||||
|
@ -20,13 +20,13 @@ extern "C" {
|
||||
int puts(char *str);
|
||||
int putDec(int number);
|
||||
int putDecu(dword number);
|
||||
void strcpy(char *dest, char *src);
|
||||
void memcpy(void *dest, void *src, dword n);
|
||||
void memcpyd(void *dest, void *src, dword n);
|
||||
void strcpy(char *dest, const char *src);
|
||||
void memcpy(void *dest, const void *src, dword n);
|
||||
void memcpyd(void *dest, const void *src, dword n);
|
||||
void *memset(void *buffer, int c, int num);
|
||||
void *memsetw(void *buffer, int c, int num);
|
||||
void *memsetd(void *buffer, int c, int num);
|
||||
dword strlen(char *str);
|
||||
dword strlen(const char *str);
|
||||
void invlpg_(dword addr);
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "hos_defines.h"
|
||||
#include "fs/vfs.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "lang/string.h"
|
||||
#include "lang/cstring.h"
|
||||
|
||||
//From Microsoft's FAT32 File System Specification
|
||||
DSKSZTOSECPERCLUS DskTableFAT16 [] =
|
||||
|
@ -3,37 +3,19 @@
|
||||
// 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"
|
||||
//#include "lang/LinkedList.h"
|
||||
#include "lang/string.h"
|
||||
#include "kio.h"
|
||||
|
||||
void vfs_init()
|
||||
{
|
||||
LinkedList<int> 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");
|
||||
}
|
||||
string test1 = "hi there.";
|
||||
printf("%s", test1.data());
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,22 +28,17 @@ 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 (;;) {}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/13/03
|
||||
// Holtrop's Operating System - Version 0.13
|
||||
// Modified: 05/21/04
|
||||
// Modified: 03/08/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" //Virtual File System
|
||||
#include "fs/vfs.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
void isr(dword num);
|
||||
void k_init();
|
||||
|
||||
dword timer;
|
||||
dword timer = 0;
|
||||
|
||||
//Main kernel initialization method
|
||||
void k_init()
|
||||
@ -43,11 +43,8 @@ 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();
|
||||
@ -71,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 (;;)
|
||||
{
|
||||
@ -90,7 +89,7 @@ void isr(dword num)
|
||||
halt();
|
||||
break;
|
||||
case 0x20: // IRQ0 - timer interrupt
|
||||
/*timer++;
|
||||
timer++;
|
||||
(*(byte *)(0xc00b8000))++;
|
||||
if (!(timer % 100))
|
||||
{
|
||||
@ -98,7 +97,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
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include "asmfuncs.h"
|
||||
#include "video/video.h"
|
||||
|
||||
dword cursorPosition; //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
|
||||
@ -17,14 +18,9 @@ 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, ...)
|
||||
@ -90,7 +86,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')
|
||||
{
|
||||
@ -108,7 +104,7 @@ void putc(dword chr)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (video_Mode())
|
||||
if (graphical)
|
||||
{
|
||||
console_memory[cursorPosition] = charac | 0x0700;
|
||||
kio_drawConsoleChar(cursorPosition);
|
||||
@ -125,7 +121,7 @@ void putc(dword chr)
|
||||
kio_console_scroll();
|
||||
cursorPosition = 2000-80;
|
||||
}
|
||||
if (!video_Mode())
|
||||
if (!graphical)
|
||||
writeCursorPosition(cursorPosition);
|
||||
}
|
||||
|
||||
@ -162,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);
|
||||
@ -172,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);
|
||||
@ -223,9 +219,9 @@ dword kio_getCursorPosition()
|
||||
void kio_writeCursorPosition(dword position)
|
||||
{
|
||||
cursorPosition = position;
|
||||
writeCursorPosition(position);
|
||||
if (!graphical)
|
||||
writeCursorPosition(position);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
|
||||
#include "LinkedList.h"
|
||||
|
@ -106,7 +106,7 @@ LinkedList<T>::LinkedList()
|
||||
template <typename Element>
|
||||
LinkedList<Element> & LinkedList<Element>::insert(int index, Element e)
|
||||
{
|
||||
if (index == count-1)
|
||||
if (index == count)
|
||||
push_back(e);
|
||||
else if (index >= 0 && index < count)
|
||||
{
|
||||
|
91
kernel/lang/cstring.cpp
Normal file
91
kernel/lang/cstring.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
// cstring.c
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Modified: 06/01/04
|
||||
// Implements c string functions
|
||||
|
||||
#include "string.h"
|
||||
#include "asmfuncs.h"
|
||||
|
||||
char *strcat(char *dest, const char *src)
|
||||
{
|
||||
strcpy(dest+strlen(dest), src);
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
//Splits a string into multiple strings by turning all characters
|
||||
// equal to delim into null values (string termination character)
|
||||
//Returns the number of strings after the split, 1 if no delim chars
|
||||
int string_split(char *str, char delim)
|
||||
{
|
||||
if (strlen(str) < 1)
|
||||
return 0; //empty string
|
||||
int count = 1;
|
||||
for (; *str; str++)
|
||||
{
|
||||
if (*str == delim)
|
||||
{
|
||||
count++;
|
||||
*str = 0;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
//Advances a char pointer to the byte after the current string's
|
||||
// null-terminating character
|
||||
//Useful after calling string_split()
|
||||
//Returns a pointer to the following string
|
||||
char *string_advance(char *str)
|
||||
{
|
||||
for (; *str; str++);
|
||||
return str+1;
|
||||
}
|
||||
|
||||
|
||||
void rtrim(char *str)
|
||||
{
|
||||
str += strlen(str); //now points to the null character at the end of the string
|
||||
str--;
|
||||
for (;;)
|
||||
{
|
||||
if ((*str == ' ') || (*str == '\t') || (*str == '\n'))
|
||||
*str-- = 0;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *ucase(char *str)
|
||||
{
|
||||
char *ret = str;
|
||||
for (;;)
|
||||
{
|
||||
if (*str == 0)
|
||||
break;
|
||||
if ((*str >= 'a') && (*str <= 'z'))
|
||||
*str = (*str) - 32;
|
||||
str++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
char *lcase(char *str)
|
||||
{
|
||||
char *ret = str;
|
||||
for (;;)
|
||||
{
|
||||
if (*str == 0)
|
||||
break;
|
||||
if ((*str >= 'A') && (*str <= 'Z'))
|
||||
*str = (*str) + 32;
|
||||
str++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
19
kernel/lang/cstring.h
Normal file
19
kernel/lang/cstring.h
Normal file
@ -0,0 +1,19 @@
|
||||
// cstring.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Modified: 06/01/04
|
||||
// Implements c string functions
|
||||
|
||||
#ifndef __HOS_CSTRING__
|
||||
#define __HOS_CSTRING__ __HOS_CSTRING__
|
||||
|
||||
char *strcat(char *dest, const char *src);
|
||||
int string_split(char *str, char delim);
|
||||
char *string_advance(char *str);
|
||||
void rtrim(char *str);
|
||||
char *ucase(char *str);
|
||||
char *lcase(char *str);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,90 +1,196 @@
|
||||
// string.c
|
||||
|
||||
// string.cpp
|
||||
// implements c++ string object
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements string functions
|
||||
// Date: 06/01/04
|
||||
// Modified: 06/01/04
|
||||
|
||||
#include "string.h"
|
||||
#include "asmfuncs.h"
|
||||
#include "cstring.h"
|
||||
|
||||
char *strcat(char *dest, char *src)
|
||||
string::string()
|
||||
{
|
||||
strcpy(dest+strlen(dest), src);
|
||||
return dest;
|
||||
myLength = 0;
|
||||
myChars = new char;
|
||||
*myChars = 0;
|
||||
}
|
||||
|
||||
|
||||
//Splits a string into multiple strings by turning all characters
|
||||
// equal to delim into null values (string termination character)
|
||||
//Returns the number of strings after the split, 1 if no delim chars
|
||||
int string_split(char *str, char delim)
|
||||
string::~string()
|
||||
{
|
||||
if (strlen(str) < 1)
|
||||
return 0; //empty string
|
||||
int count = 1;
|
||||
for (; *str; str++)
|
||||
delete[] myChars;
|
||||
}
|
||||
|
||||
string::string(const string & orig)
|
||||
{
|
||||
myLength = orig.myLength;
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, orig.myChars, myLength + 1);
|
||||
}
|
||||
|
||||
string::string(const char *cstring)
|
||||
{
|
||||
myLength = strlen(cstring);
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, cstring, myLength + 1);
|
||||
}
|
||||
|
||||
string & string::operator=(const string & orig)
|
||||
{
|
||||
if (this != &orig)
|
||||
{
|
||||
if (*str == delim)
|
||||
{
|
||||
count++;
|
||||
*str = 0;
|
||||
}
|
||||
delete[] myChars;
|
||||
myLength = orig.myLength;
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, orig.myChars, myLength + 1);
|
||||
}
|
||||
return count;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//Advances a char pointer to the byte after the current string's
|
||||
// null-terminating character
|
||||
//Useful after calling string_split()
|
||||
//Returns a pointer to the following string
|
||||
char *string_advance(char *str)
|
||||
string & string::operator=(const char *cstring)
|
||||
{
|
||||
for (; *str; str++);
|
||||
return str+1;
|
||||
}
|
||||
|
||||
|
||||
void rtrim(char *str)
|
||||
{
|
||||
str += strlen(str); //now points to the null character at the end of the string
|
||||
str--;
|
||||
for (;;)
|
||||
if (myChars != cstring)
|
||||
{
|
||||
if ((*str == ' ') || (*str == '\t') || (*str == '\n'))
|
||||
*str-- = 0;
|
||||
else
|
||||
break;
|
||||
delete[] myChars;
|
||||
myLength = strlen(cstring);
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, cstring, myLength + 1);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
char * string::data() const { return myChars; }
|
||||
|
||||
char *ucase(char *str)
|
||||
int string::size() const { return myLength; }
|
||||
|
||||
bool string::operator==(const string & second) const
|
||||
{
|
||||
char *ret = str;
|
||||
for (;;)
|
||||
if (myLength != second.myLength)
|
||||
return false;
|
||||
for (unsigned int i = 0; i < myLength; i++)
|
||||
{
|
||||
if (*str == 0)
|
||||
break;
|
||||
if ((*str >= 'a') && (*str <= 'z'))
|
||||
*str = (*str) - 32;
|
||||
str++;
|
||||
if (myChars[i] != second.myChars[i])
|
||||
return false;
|
||||
}
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
char *lcase(char *str)
|
||||
bool string::operator==(const char *cstring) const
|
||||
{
|
||||
char *ret = str;
|
||||
for (;;)
|
||||
if (myLength != strlen(cstring))
|
||||
return false;
|
||||
for (unsigned int i = 0; i < myLength; i++)
|
||||
{
|
||||
if (*str == 0)
|
||||
break;
|
||||
if ((*str >= 'A') && (*str <= 'Z'))
|
||||
*str = (*str) + 32;
|
||||
str++;
|
||||
if (myChars[i] != cstring[i])
|
||||
return false;
|
||||
}
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
string & string::operator+=(const string & str)
|
||||
{
|
||||
char *newStr = new char[myLength + str.myLength + 1];
|
||||
memcpy(newStr, myChars, myLength);
|
||||
memcpy(newStr + myLength, str.myChars, str.myLength + 1);
|
||||
delete[] myChars;
|
||||
myChars = newStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
string & string::operator+=(const char *cstring)
|
||||
{
|
||||
char *newStr = new char[myLength + strlen(cstring) + 1];
|
||||
memcpy(newStr, myChars, myLength);
|
||||
memcpy(newStr + myLength, cstring, strlen(cstring) + 1);
|
||||
delete[] myChars;
|
||||
myChars = newStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
string & string::operator-=(const string & str)
|
||||
{
|
||||
char *newStr = new char[myLength + str.myLength + 1];
|
||||
memcpy(newStr, str.myChars, str.myLength);
|
||||
memcpy(newStr + str.myLength, myChars, myLength + 1);
|
||||
delete[] myChars;
|
||||
myChars = newStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
string & string::operator-=(const char *cstring)
|
||||
{
|
||||
char *newStr = new char[myLength + strlen(cstring) + 1];
|
||||
memcpy(newStr, cstring, strlen(cstring));
|
||||
memcpy(newStr + strlen(cstring), myChars, myLength + 1);
|
||||
delete[] myChars;
|
||||
myChars = newStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
string & string::operator+=(char chr)
|
||||
{
|
||||
myLength++;
|
||||
char *newStr = new char[myLength + 1];
|
||||
memcpy(newStr, myChars, myLength);
|
||||
newStr[myLength - 1] = chr;
|
||||
newStr[myLength] = 0;
|
||||
delete[] myChars;
|
||||
myChars = newStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
string & string::operator-=(char chr)
|
||||
{
|
||||
myLength++;
|
||||
char *newStr = new char[myLength + 1];
|
||||
memcpy(newStr + 1, myChars, myLength);
|
||||
*newStr = chr;
|
||||
delete[] myChars;
|
||||
myChars = newStr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
string::string(const string & str1, const string & str2)
|
||||
{
|
||||
myLength = str1.myLength + str2.myLength;
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, str1.myChars, str1.myLength);
|
||||
memcpy(myChars + myLength, str2.myChars, str2.myLength + 1);
|
||||
}
|
||||
|
||||
string::string(const string & str1, const char *cstring)
|
||||
{
|
||||
myLength = str1.myLength + strlen(cstring);
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, str1.myChars, str1.myLength);
|
||||
memcpy(myChars + myLength, cstring, strlen(cstring) + 1);
|
||||
}
|
||||
|
||||
string::string(const char *cstring, const string & str)
|
||||
{
|
||||
myLength = str.myLength + strlen(cstring);
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, cstring, strlen(cstring));
|
||||
memcpy(myChars + myLength, str.myChars, str.myLength + 1);
|
||||
}
|
||||
|
||||
string::string(const string & str1, char chr)
|
||||
{
|
||||
myLength = str1.myLength + 1;
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars, str1.myChars, myLength);
|
||||
myChars[myLength - 1] = chr;
|
||||
myChars[myLength] = 0;
|
||||
}
|
||||
|
||||
string::string(char chr, const string & str1)
|
||||
{
|
||||
myLength = str1.myLength + 1;
|
||||
myChars = new char[myLength + 1];
|
||||
memcpy(myChars + 1, str1.myChars, myLength + 1);
|
||||
*myChars = chr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,18 +1,83 @@
|
||||
// strings.h
|
||||
|
||||
// string.h
|
||||
// implements c++ string object
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements string functions
|
||||
// Date: 06/01/04
|
||||
// Modified: 06/01/04
|
||||
|
||||
|
||||
#ifndef __HOS_STRING__
|
||||
#define __HOS_STRING__ __HOS_STRING__
|
||||
|
||||
char *strcat(char *dest, char *src);
|
||||
int string_split(char *str, char delim);
|
||||
char *string_advance(char *str);
|
||||
void rtrim(char *str);
|
||||
char *ucase(char *str);
|
||||
char *lcase(char *str);
|
||||
|
||||
class string
|
||||
{
|
||||
private:
|
||||
char * myChars;
|
||||
unsigned int myLength;
|
||||
public:
|
||||
string();
|
||||
~string();
|
||||
string(const string & orig);
|
||||
string(const char *cstring);
|
||||
|
||||
string & operator=(const string & orig);
|
||||
string & operator=(const char *cstring);
|
||||
bool operator==(const string & second) const;
|
||||
bool operator==(const char *cstring) const;
|
||||
|
||||
string(const string & str1, const string & str2);
|
||||
string(const string & str1, const char *cstring);
|
||||
string(const char *cstring, const string & str);
|
||||
string(const string & str1, char chr);
|
||||
string(char chr, const string & str1);
|
||||
|
||||
string & operator+=(const string & str);
|
||||
string & operator+=(const char *cstring);
|
||||
string & operator-=(const string & str);
|
||||
string & operator-=(const char *cstring);
|
||||
string & operator+=(char chr);
|
||||
string & operator-=(char chr);
|
||||
|
||||
char * data() const;
|
||||
int size() const;
|
||||
};
|
||||
|
||||
static inline bool operator==(char *cstring, const string & str)
|
||||
{ return str == cstring; }
|
||||
|
||||
static inline string & operator+=(const char *cstring, string & str)
|
||||
{ return str -= cstring; }
|
||||
|
||||
static inline string & operator-=(const char *cstring, string & str)
|
||||
{ return str += cstring; }
|
||||
|
||||
static inline string & operator+=(char chr, string & str)
|
||||
{ return str -= chr; }
|
||||
|
||||
static inline string & operator-=(char chr, string & str)
|
||||
{ return str += chr; }
|
||||
|
||||
|
||||
|
||||
static inline string operator+(const string & str1, const string & str2)
|
||||
{ return string(str1, str2); }
|
||||
|
||||
static inline string operator+(const string & str1, const char *cstring)
|
||||
{ return string(str1, cstring); }
|
||||
|
||||
static inline string operator-(const string & str1, const string & str2)
|
||||
{ return string(str2, str1); }
|
||||
|
||||
static inline string operator-(const string & str1, const char *cstring)
|
||||
{ return string(cstring, str1); }
|
||||
|
||||
static inline string operator+(const string & str1, char chr)
|
||||
{ return string(str1, chr); }
|
||||
|
||||
static inline string operator-(const string & str1, char chr)
|
||||
{ return string(chr, str1); }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
//The total amount of physical memory available (bytes, 1 bit per page)
|
||||
#define BITMAP_SIZE 0x20000
|
||||
dword mm_totalmem;
|
||||
dword mm_megabytes;
|
||||
dword mm_totalmem = 0;
|
||||
dword mm_megabytes = 0;
|
||||
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,7 +17,6 @@ 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;
|
||||
|
@ -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
|
||||
// It sets up the final page directory/page table setup and maps video memory, if present
|
||||
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,13 +30,6 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +122,7 @@ void *malloc(unsigned int bytes)
|
||||
void *vmm_getFreeChunk(unsigned int bytes)
|
||||
{
|
||||
HeapEntry *he = firstHeapEntry;
|
||||
while (he)
|
||||
for (;;)
|
||||
{
|
||||
if (he->attributes == VMM_HE_FREE)
|
||||
{
|
||||
@ -150,6 +143,8 @@ void *vmm_getFreeChunk(unsigned int bytes)
|
||||
}
|
||||
}
|
||||
he = (HeapEntry *)he->link;
|
||||
if (!he)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -166,7 +161,7 @@ void vmm_coalesceHeapEntry(HeapEntry *he)
|
||||
return;
|
||||
}
|
||||
HeapEntry *hec = firstHeapEntry;
|
||||
while (hec)
|
||||
for (;;)
|
||||
{
|
||||
if (hec->attributes == he->attributes)
|
||||
{
|
||||
@ -183,6 +178,8 @@ void vmm_coalesceHeapEntry(HeapEntry *he)
|
||||
}
|
||||
}
|
||||
hec = (HeapEntry *)hec->link;
|
||||
if (!hec)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,9 +259,12 @@ void vmm_addHeapEntryBlock()
|
||||
HeapEntry *vmm_getLastHeapEntry()
|
||||
{
|
||||
HeapEntry *he = firstHeapEntry;
|
||||
while (he)
|
||||
for (;;)
|
||||
{
|
||||
if (he->link == 0)
|
||||
return he;
|
||||
he = (HeapEntry *)he->link;
|
||||
return he;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -272,11 +272,13 @@ HeapEntry *vmm_getLastHeapEntry()
|
||||
HeapEntry *vmm_getFirstHoleHeapEntry(unsigned int minBytes)
|
||||
{
|
||||
HeapEntry *he = firstHeapEntry;
|
||||
while (he)
|
||||
for (;;)
|
||||
{
|
||||
if ((he->attributes == VMM_HE_HOLE) && (he->size >= minBytes))
|
||||
return he;
|
||||
he = (HeapEntry *)he->link;
|
||||
if (!he)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -286,11 +288,13 @@ HeapEntry *vmm_getFirstHoleHeapEntry(unsigned int minBytes)
|
||||
HeapEntry *vmm_getFirstUnusedHeapEntry()
|
||||
{
|
||||
HeapEntry *he = firstHeapEntry;
|
||||
while (he)
|
||||
for (;;)
|
||||
{
|
||||
if (he->attributes == VMM_HE_UNUSED)
|
||||
return he;
|
||||
he = (HeapEntry *)he->link;
|
||||
if (!he)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -301,11 +305,13 @@ unsigned int vmm_heapEntriesLeft()
|
||||
{
|
||||
HeapEntry *he = firstHeapEntry;
|
||||
unsigned int entries = 0;
|
||||
while (he)
|
||||
for (;;)
|
||||
{
|
||||
if (he->attributes == VMM_HE_UNUSED)
|
||||
entries++;
|
||||
he = (HeapEntry *)he->link;
|
||||
if (!he)
|
||||
break;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
@ -327,11 +333,13 @@ int free(void *ptr)
|
||||
HeapEntry *vmm_getHeapEntryByBase(unsigned int base)
|
||||
{
|
||||
HeapEntry *he = firstHeapEntry;
|
||||
while (he)
|
||||
for (;;)
|
||||
{
|
||||
if (he->base == base)
|
||||
return he;
|
||||
he = (HeapEntry *)he->link;
|
||||
if (!he)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "mm/vmm.h"
|
||||
|
||||
ModeInfoBlock video_mode;
|
||||
dword videoMode; //what video mode # we are in, 0 for console mode
|
||||
dword videoMode = 0; //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
|
||||
|
Loading…
x
Reference in New Issue
Block a user