Import backup from 2004-06-03

This commit is contained in:
Josh Holtrop 2004-06-03 22:00:00 -04:00
parent b4aca026d4
commit b5ba5b63fe
11 changed files with 203 additions and 25 deletions

View File

@ -30,7 +30,7 @@ LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
# Linking the kernel together # # Linking the kernel together #
############################### ###############################
all: Asm_Kernel Asm_Functions C_Kernel 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 cstring.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 devfs.o
########################## ##########################
# Assembly Kernel Loader # # Assembly Kernel Loader #
@ -65,6 +65,7 @@ C_Kernel:
$(CPP) $(CPP_FLAGS) -c mm/vmm.cpp -o vmm.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 hos_defines.cpp -o hos_defines.o
$(CPP) $(CPP_FLAGS) -c fs/vfs.cpp -o vfs.o $(CPP) $(CPP_FLAGS) -c fs/vfs.cpp -o vfs.o
$(CPP) $(CPP_FLAGS) -c fs/devfs.cpp -o devfs.o
################################################# #################################################
# Clean up the source directory of any binaries # # Clean up the source directory of any binaries #

10
kernel/fs/Device.cpp Normal file
View File

@ -0,0 +1,10 @@
// Device.cpp
// Device object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/03/04
#include "Device.h"
#include "hos_defines.h"
#include "lang/string.h"

27
kernel/fs/Device.h Normal file
View File

@ -0,0 +1,27 @@
// Device.h
// Device object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/03/04
#ifndef __HOS_DEVICE__
#define __HOS_DEVICE__ __HOS_DEVICE__
#include "hos_defines.h"
#include "lang/string.h"
class Device
{
private:
dword myMajor;
dword myMinor;
char myType; //'d'irectory,'l'ink,'b'lock,'c'har,'a'vail
string myName;
public:
Device();
Device(string name, dword major, dword minor, char type);
};
#endif

View File

@ -0,0 +1,11 @@
// DeviceFolder.cpp
// DeviceFolder object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/03/04
#include "DeviceFolder.h"
#include "Device.h"
#include "lang/LinkedList.h"

22
kernel/fs/DeviceFolder.h Normal file
View File

@ -0,0 +1,22 @@
// DeviceFolder.h
// DeviceFolder object for use in devfs
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/03/04
#ifndef __HOS_DEVICEFOLDER__
#define __HOS_DEVICEFOLDER__ __HOS_DEVICEFOLDER__
#include "lang/LinkedList.h"
class DeviceFolder
{
public:
LinkedList<Device> devices;
LinkedList<DeviceFolder> folders;
DeviceFolder();
};
#endif

16
kernel/fs/devfs.cpp Normal file
View File

@ -0,0 +1,16 @@
// devfs.cpp
// device filesystem for HOS
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/03/04
#include "devfs.h"
void devfs_init()
{
}

15
kernel/fs/devfs.h Normal file
View File

@ -0,0 +1,15 @@
// devfs.h
// device filesystem for HOS
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/03/04
#ifndef __HOS_DEVFS__
#define __HOS_DEVFS__ __HOS_DEVFS__
void devfs_init();
#endif

View File

@ -8,14 +8,16 @@
//#include "fs/vfat.h" //#include "fs/vfat.h"
//#include "block/rd.h" //#include "block/rd.h"
//#include "block/loop.h" //#include "block/loop.h"
//#include "lang/LinkedList.h" #include "lang/LinkedList.h"
#include "lang/string.h" #include "lang/string.h"
#include "devfs.h"
#include "kio.h" #include "kio.h"
//LinkedList<Mount> mntList;
void vfs_init() void vfs_init()
{ {
string test1 = "hi there."; printf("%u\n", sizeof(string));
printf("%s", test1.data());
} }

View File

@ -1,4 +1,10 @@
// LinkedList.h
// implements a LinkedList container for HOS
// Author: Josh Holtrop
// Date: 05/22/04
// Modified: 06/03/04
template <typename Element> template <typename Element>
class LinkedList class LinkedList
{ {
@ -42,12 +48,12 @@ public:
{ {
return theNode->data; return theNode->data;
} }
Element & operator++() Element & operator++() //prefix
{ {
theNode = theNode->next; theNode = theNode->next;
return theNode->data; return theNode->data;
} }
Element & operator++(int dum) Element & operator++(int dum) //postfix
{ {
theNode = theNode->next; theNode = theNode->next;
return theNode->prev->data; return theNode->prev->data;
@ -71,35 +77,50 @@ public:
{ {
return theNode->data; return theNode->data;
} }
Element & operator++() Element & operator++() //prefix
{ {
theNode = theNode->prev; theNode = theNode->prev;
return theNode->data; return theNode->data;
} }
Element & operator++(int dum) Element & operator++(int dum) //postfix
{ {
theNode = theNode->prev; theNode = theNode->prev;
return theNode->next->data; return theNode->next->data;
} }
}; };
/* Basic constructor */
LinkedList(); LinkedList();
int numElements() { return count; }
iterator begin() { return new iterator(firstNode); } /* How many elements in the list */
iterator end() { return new iterator(lastNode->next); } int size() { return count; }
reverse_iterator rbegin() { return new reverse_iterator(lastNode); }
reverse_iterator rend() { return new reverse_iterator(firstNode->prev); } /* Return some iterators for traversing the list */
iterator begin() { return iterator(firstNode); }
iterator end() { return iterator(lastNode->next); }
reverse_iterator rbegin() { return reverse_iterator(lastNode); }
reverse_iterator rend() { return reverse_iterator(firstNode->prev); }
/* Insert an element, its position will be index */
LinkedList & insert(int index, Element e); LinkedList & insert(int index, Element e);
/* Append an element to the end of the list */
LinkedList & push_back(Element e); LinkedList & push_back(Element e);
/* Remove an element at position index */
LinkedList & remove(int index); LinkedList & remove(int index);
/* Pop an element from the end of the list */
LinkedList & pop_back(); LinkedList & pop_back();
/* Direct access to an element in the list */
Element & operator[](int index); Element & operator[](int index);
}; };
template <typename T> template <typename T>
LinkedList<T>::LinkedList() LinkedList<T>::LinkedList()
{ {
firstNode = lastNode = new LinkedNode(); firstNode = lastNode = new LinkedNode(); //head node
count = 0; count = 0;
} }

View File

@ -1,18 +1,17 @@
// string.cpp // string.cpp
// implements c++ string object // implements c++ string object for HOS
// Author: Josh Holtrop // Author: Josh Holtrop
// Date: 06/01/04 // Date: 06/01/04
// Modified: 06/01/04 // Modified: 06/01/04
#include "string.h" #include "string.h" //string class declaration
#include "asmfuncs.h" #include "asmfuncs.h" //memcpy(void *dest, void *src, int n), strlen(char *str)
#include "cstring.h"
string::string() string::string()
{ {
myLength = 0; myLength = 0;
myChars = new char; myChars = new char; //myChars must be a valid pointer at all times
*myChars = 0; *myChars = 0;
} }
@ -94,6 +93,7 @@ string & string::operator+=(const string & str)
memcpy(newStr + myLength, str.myChars, str.myLength + 1); memcpy(newStr + myLength, str.myChars, str.myLength + 1);
delete[] myChars; delete[] myChars;
myChars = newStr; myChars = newStr;
myLength += str.myLength;
return *this; return *this;
} }
@ -104,6 +104,7 @@ string & string::operator+=(const char *cstring)
memcpy(newStr + myLength, cstring, strlen(cstring) + 1); memcpy(newStr + myLength, cstring, strlen(cstring) + 1);
delete[] myChars; delete[] myChars;
myChars = newStr; myChars = newStr;
myLength += strlen(cstring);
return *this; return *this;
} }
@ -114,6 +115,7 @@ string & string::operator-=(const string & str)
memcpy(newStr + str.myLength, myChars, myLength + 1); memcpy(newStr + str.myLength, myChars, myLength + 1);
delete[] myChars; delete[] myChars;
myChars = newStr; myChars = newStr;
myLength += str.myLength;
return *this; return *this;
} }
@ -124,6 +126,7 @@ string & string::operator-=(const char *cstring)
memcpy(newStr + strlen(cstring), myChars, myLength + 1); memcpy(newStr + strlen(cstring), myChars, myLength + 1);
delete[] myChars; delete[] myChars;
myChars = newStr; myChars = newStr;
myLength += strlen(cstring);
return *this; return *this;
} }
@ -157,7 +160,7 @@ string::string(const string & str1, const string & str2)
myLength = str1.myLength + str2.myLength; myLength = str1.myLength + str2.myLength;
myChars = new char[myLength + 1]; myChars = new char[myLength + 1];
memcpy(myChars, str1.myChars, str1.myLength); memcpy(myChars, str1.myChars, str1.myLength);
memcpy(myChars + myLength, str2.myChars, str2.myLength + 1); memcpy(myChars + str1.myLength, str2.myChars, str2.myLength + 1);
} }
string::string(const string & str1, const char *cstring) string::string(const string & str1, const char *cstring)
@ -165,7 +168,7 @@ string::string(const string & str1, const char *cstring)
myLength = str1.myLength + strlen(cstring); myLength = str1.myLength + strlen(cstring);
myChars = new char[myLength + 1]; myChars = new char[myLength + 1];
memcpy(myChars, str1.myChars, str1.myLength); memcpy(myChars, str1.myChars, str1.myLength);
memcpy(myChars + myLength, cstring, strlen(cstring) + 1); memcpy(myChars + str1.myLength, cstring, strlen(cstring) + 1);
} }
string::string(const char *cstring, const string & str) string::string(const char *cstring, const string & str)
@ -173,7 +176,7 @@ string::string(const char *cstring, const string & str)
myLength = str.myLength + strlen(cstring); myLength = str.myLength + strlen(cstring);
myChars = new char[myLength + 1]; myChars = new char[myLength + 1];
memcpy(myChars, cstring, strlen(cstring)); memcpy(myChars, cstring, strlen(cstring));
memcpy(myChars + myLength, str.myChars, str.myLength + 1); memcpy(myChars + strlen(cstring), str.myChars, str.myLength + 1);
} }
string::string(const string & str1, char chr) string::string(const string & str1, char chr)
@ -193,4 +196,17 @@ string::string(char chr, const string & str1)
*myChars = chr; *myChars = chr;
} }
const char & string::operator[](unsigned int index) const
{
if (index >= 0 && index < myLength)
return myChars[index];
return *myChars; //if index is invalid, return a pointer to the trailing 0
}
char & string::operator[](unsigned int index)
{
if (index >= 0 && index < myLength)
return myChars[index];
return *myChars; //if index is invalid, return a pointer to the trailing 0
}

View File

@ -1,37 +1,56 @@
// string.h // string.h
// implements c++ string object // implements c++ string object for HOS
// Author: Josh Holtrop // Author: Josh Holtrop
// Date: 06/01/04 // Date: 06/01/04
// Modified: 06/01/04 // Modified: 06/03/04
#ifndef __HOS_STRING__ #ifndef __HOS_STRING__
#define __HOS_STRING__ __HOS_STRING__ #define __HOS_STRING__ __HOS_STRING__
class string class string
{ {
private: private:
/* myChars is a pointer to a character array
* It will always be a valid pointer, not null.
* The constructor is responsible for initializing
* it to point to a 1-char array with myChars[0] == 0 */
char * myChars; char * myChars;
/* myLength holds how many characters are in the
* string, not including the trailing null value
* (ASCII 0 character) */
unsigned int myLength; unsigned int myLength;
public: public:
/* Basic constructors */
string(); string();
~string(); ~string();
/* Copy constructor */
string(const string & orig); string(const string & orig);
/* Construct strings from c-style strings:
* Allows declarations like string s = "data"; */
string(const char *cstring); string(const char *cstring);
/* Assignment operators */
string & operator=(const string & orig); string & operator=(const string & orig);
string & operator=(const char *cstring); string & operator=(const char *cstring);
/* Boolean equals operators */
bool operator==(const string & second) const; bool operator==(const string & second) const;
bool operator==(const char *cstring) const; bool operator==(const char *cstring) const;
/* Construct strings made up of combinations of other
* strings, c-style strings, and characters */
string(const string & str1, const string & str2); string(const string & str1, const string & str2);
string(const string & str1, const char *cstring); string(const string & str1, const char *cstring);
string(const char *cstring, const string & str); string(const char *cstring, const string & str);
string(const string & str1, char chr); string(const string & str1, char chr);
string(char chr, const string & str1); string(char chr, const string & str1);
/* Append and prepend operators */
string & operator+=(const string & str); string & operator+=(const string & str);
string & operator+=(const char *cstring); string & operator+=(const char *cstring);
string & operator-=(const string & str); string & operator-=(const string & str);
@ -39,13 +58,26 @@ public:
string & operator+=(char chr); string & operator+=(char chr);
string & operator-=(char chr); string & operator-=(char chr);
/* Direct character-access operators */
const char & operator[](unsigned int index) const;
char & operator[](unsigned int index);
/* Returns handle to actual character-array for programs
* that need raw data instead of a string object */
char * data() const; char * data() const;
/* Returns the size of the string. This is myLength
* and is the number of characters in the string
* not counting the trailing null (ASCII 0) character */
int size() const; int size() const;
}; };
static inline bool operator==(char *cstring, const string & str) static inline bool operator==(char *cstring, const string & str)
{ return str == cstring; } { return str == cstring; }
static inline string & operator+=(const char *cstring, string & str) static inline string & operator+=(const char *cstring, string & str)
{ return str -= cstring; } { return str -= cstring; }
@ -78,6 +110,11 @@ static inline string operator+(const string & str1, char chr)
static inline string operator-(const string & str1, char chr) static inline string operator-(const string & str1, char chr)
{ return string(chr, str1); } { return string(chr, str1); }
static inline string operator+(char chr, const string & str1)
{ return string(chr, str1); }
static inline string operator-(char chr, const string & str1)
{ return string(str1, chr); }
#endif #endif