From b5ba5b63feac44e2580a5c143831e2f18e3a275e Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 3 Jun 2004 22:00:00 -0400 Subject: [PATCH] Import backup from 2004-06-03 --- kernel/Makefile | 3 ++- kernel/fs/Device.cpp | 10 +++++++++ kernel/fs/Device.h | 27 ++++++++++++++++++++++++ kernel/fs/DeviceFolder.cpp | 11 ++++++++++ kernel/fs/DeviceFolder.h | 22 +++++++++++++++++++ kernel/fs/devfs.cpp | 16 ++++++++++++++ kernel/fs/devfs.h | 15 +++++++++++++ kernel/fs/vfs.cpp | 8 ++++--- kernel/lang/LinkedList.h | 41 +++++++++++++++++++++++++++--------- kernel/lang/string.cpp | 32 +++++++++++++++++++++------- kernel/lang/string.h | 43 +++++++++++++++++++++++++++++++++++--- 11 files changed, 203 insertions(+), 25 deletions(-) create mode 100644 kernel/fs/Device.cpp create mode 100644 kernel/fs/Device.h create mode 100644 kernel/fs/DeviceFolder.cpp create mode 100644 kernel/fs/DeviceFolder.h create mode 100644 kernel/fs/devfs.cpp create mode 100644 kernel/fs/devfs.h diff --git a/kernel/Makefile b/kernel/Makefile index 00f824d..952df57 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 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 # @@ -65,6 +65,7 @@ C_Kernel: $(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 + $(CPP) $(CPP_FLAGS) -c fs/devfs.cpp -o devfs.o ################################################# # Clean up the source directory of any binaries # diff --git a/kernel/fs/Device.cpp b/kernel/fs/Device.cpp new file mode 100644 index 0000000..0d60793 --- /dev/null +++ b/kernel/fs/Device.cpp @@ -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" diff --git a/kernel/fs/Device.h b/kernel/fs/Device.h new file mode 100644 index 0000000..140c6ed --- /dev/null +++ b/kernel/fs/Device.h @@ -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 + diff --git a/kernel/fs/DeviceFolder.cpp b/kernel/fs/DeviceFolder.cpp new file mode 100644 index 0000000..1f7b780 --- /dev/null +++ b/kernel/fs/DeviceFolder.cpp @@ -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" + diff --git a/kernel/fs/DeviceFolder.h b/kernel/fs/DeviceFolder.h new file mode 100644 index 0000000..9e6771b --- /dev/null +++ b/kernel/fs/DeviceFolder.h @@ -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 devices; + LinkedList folders; + DeviceFolder(); +}; + +#endif + diff --git a/kernel/fs/devfs.cpp b/kernel/fs/devfs.cpp new file mode 100644 index 0000000..9083642 --- /dev/null +++ b/kernel/fs/devfs.cpp @@ -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() +{ + +} + + diff --git a/kernel/fs/devfs.h b/kernel/fs/devfs.h new file mode 100644 index 0000000..d03a4aa --- /dev/null +++ b/kernel/fs/devfs.h @@ -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 + diff --git a/kernel/fs/vfs.cpp b/kernel/fs/vfs.cpp index 74fab59..021c554 100644 --- a/kernel/fs/vfs.cpp +++ b/kernel/fs/vfs.cpp @@ -8,14 +8,16 @@ //#include "fs/vfat.h" //#include "block/rd.h" //#include "block/loop.h" -//#include "lang/LinkedList.h" +#include "lang/LinkedList.h" #include "lang/string.h" +#include "devfs.h" #include "kio.h" +//LinkedList mntList; + void vfs_init() { - string test1 = "hi there."; - printf("%s", test1.data()); + printf("%u\n", sizeof(string)); } diff --git a/kernel/lang/LinkedList.h b/kernel/lang/LinkedList.h index 5d7afa4..5a94a71 100644 --- a/kernel/lang/LinkedList.h +++ b/kernel/lang/LinkedList.h @@ -1,4 +1,10 @@ +// LinkedList.h +// implements a LinkedList container for HOS +// Author: Josh Holtrop +// Date: 05/22/04 +// Modified: 06/03/04 + template class LinkedList { @@ -42,12 +48,12 @@ public: { return theNode->data; } - Element & operator++() + Element & operator++() //prefix { theNode = theNode->next; return theNode->data; } - Element & operator++(int dum) + Element & operator++(int dum) //postfix { theNode = theNode->next; return theNode->prev->data; @@ -71,35 +77,50 @@ public: { return theNode->data; } - Element & operator++() + Element & operator++() //prefix { theNode = theNode->prev; return theNode->data; } - Element & operator++(int dum) + Element & operator++(int dum) //postfix { theNode = theNode->prev; return theNode->next->data; } }; + /* Basic constructor */ 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); } + + /* How many elements in the list */ + int size() { return count; } + + /* 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); + + /* Append an element to the end of the list */ LinkedList & push_back(Element e); + + /* Remove an element at position index */ LinkedList & remove(int index); + + /* Pop an element from the end of the list */ LinkedList & pop_back(); + + /* Direct access to an element in the list */ Element & operator[](int index); }; template LinkedList::LinkedList() { - firstNode = lastNode = new LinkedNode(); + firstNode = lastNode = new LinkedNode(); //head node count = 0; } diff --git a/kernel/lang/string.cpp b/kernel/lang/string.cpp index 3b92bba..9078f27 100644 --- a/kernel/lang/string.cpp +++ b/kernel/lang/string.cpp @@ -1,18 +1,17 @@ // string.cpp -// implements c++ string object +// implements c++ string object for HOS // Author: Josh Holtrop // Date: 06/01/04 // Modified: 06/01/04 -#include "string.h" -#include "asmfuncs.h" -#include "cstring.h" +#include "string.h" //string class declaration +#include "asmfuncs.h" //memcpy(void *dest, void *src, int n), strlen(char *str) string::string() { myLength = 0; - myChars = new char; + myChars = new char; //myChars must be a valid pointer at all times *myChars = 0; } @@ -94,6 +93,7 @@ string & string::operator+=(const string & str) memcpy(newStr + myLength, str.myChars, str.myLength + 1); delete[] myChars; myChars = newStr; + myLength += str.myLength; return *this; } @@ -104,6 +104,7 @@ string & string::operator+=(const char *cstring) memcpy(newStr + myLength, cstring, strlen(cstring) + 1); delete[] myChars; myChars = newStr; + myLength += strlen(cstring); return *this; } @@ -114,6 +115,7 @@ string & string::operator-=(const string & str) memcpy(newStr + str.myLength, myChars, myLength + 1); delete[] myChars; myChars = newStr; + myLength += str.myLength; return *this; } @@ -124,6 +126,7 @@ string & string::operator-=(const char *cstring) memcpy(newStr + strlen(cstring), myChars, myLength + 1); delete[] myChars; myChars = newStr; + myLength += strlen(cstring); return *this; } @@ -157,7 +160,7 @@ 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); + memcpy(myChars + str1.myLength, str2.myChars, str2.myLength + 1); } 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); myChars = new char[myLength + 1]; 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) @@ -173,7 +176,7 @@ 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); + memcpy(myChars + strlen(cstring), str.myChars, str.myLength + 1); } string::string(const string & str1, char chr) @@ -193,4 +196,17 @@ string::string(char chr, const string & str1) *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 +} diff --git a/kernel/lang/string.h b/kernel/lang/string.h index 0de67e1..a33a31b 100644 --- a/kernel/lang/string.h +++ b/kernel/lang/string.h @@ -1,37 +1,56 @@ // string.h -// implements c++ string object +// implements c++ string object for HOS // Author: Josh Holtrop // Date: 06/01/04 -// Modified: 06/01/04 +// Modified: 06/03/04 #ifndef __HOS_STRING__ #define __HOS_STRING__ __HOS_STRING__ - class string { 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; + + /* myLength holds how many characters are in the + * string, not including the trailing null value + * (ASCII 0 character) */ unsigned int myLength; public: + /* Basic constructors */ string(); ~string(); + + /* Copy constructor */ string(const string & orig); + + /* Construct strings from c-style strings: + * Allows declarations like string s = "data"; */ string(const char *cstring); + /* Assignment operators */ string & operator=(const string & orig); string & operator=(const char *cstring); + + /* Boolean equals operators */ bool operator==(const string & second) 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 char *cstring); string(const char *cstring, const string & str); string(const string & str1, char chr); string(char chr, const string & str1); + /* Append and prepend operators */ string & operator+=(const string & str); string & operator+=(const char *cstring); string & operator-=(const string & str); @@ -39,13 +58,26 @@ public: 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; + + /* 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; }; + static inline bool operator==(char *cstring, const string & str) { return str == cstring; } + + static inline string & operator+=(const char *cstring, string & str) { 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) { 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