*.dmp
*.kmd.*
Map*.txt
+map.txt
Doxylog*.txt
LineCounts.*.txt
bochs*.txt
serial.txt
*.gz
*.img
+SrcDoc/
+ApiDoc/
+Usermode/Output/
+gitstats/
\r
KERNEL_SRC = ../../Kernel/\r
\r
-KERNEL_OBJ := logging.o adt.o\r
-KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o vfs/nodecache.o vfs/mount.o\r
+KERNEL_OBJ := logging.o adt.o lib.o\r
+KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o vfs/nodecache.o vfs/mount.o vfs/memfile.o\r
KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o\r
-KERNEL_OBJ += drv/vterm.o drv/fifo.o\r
+KERNEL_OBJ += drv/vterm.o drv/fifo.o drv/proc.o\r
\r
-OBJ := main.o video.o keyboard.o mouse.o nativefs.o vfs_handle.o\r
+OBJ := main.o threads.o video.o keyboard.o mouse.o nativefs.o vfs_handle.o\r
OBJ += $(addprefix $(KERNEL_SRC),$(KERNEL_OBJ))\r
\r
OBJ := $(addsuffix .$(PLATFORM),$(OBJ))\r
*
* Kernel Main
*/
+#include <acess.h>
#include <stdio.h>
#include <stdlib.h>
-#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
printf("\n");
}
-int CheckMem(void *Mem, int Count)
+void *Heap_Allocate(int Count, const char *File, int Line)
{
- return 1;
+ return malloc(Count);
}
-int CheckString(const char *String)
+tPAddr MM_GetPhysAddr(tVAddr VAddr)
{
- return 1;
+ return VAddr; // HACK!
+}
+
+Uint MM_GetFlags(tVAddr VAddr)
+{
+ return 0;
}
--- /dev/null
+/*
+ * Acess2 Native Kernel
+ * - Acess kernel emulation on another OS using SDL and UDP
+ *
+ * threads.c
+ * - Thread and process handling
+ */
+#include <acess.h>
+
+// === STRUCTURES ===
+typedef struct sThread
+{
+ struct sThread *Next;
+ tTID TID, PID;
+ tUID UID, GID;
+
+ struct sThread *Parent;
+
+ char *ThreadName;
+
+ // Config?
+ Uint Config[NUM_CFG_ENTRIES];
+} tThread;
+
+// === GLOBALS ===
+tThread *gpThreads;
+__thread tThread *gpCurrentThread;
+
+// === CODE ===
+tUID Threads_GetUID() { return gpCurrentThread->UID; }
+tGID Threads_GetGID() { return gpCurrentThread->GID; }
+tTID Threads_GetTID() { return gpCurrentThread->TID; }
+tPID Threads_GetPID() { return gpCurrentThread->PID; }
+
+Uint *Threads_GetCfgPtr(int Index)
+{
+ return &gpCurrentThread->Config[Index];
+}
int putDebugChar(char ch);
int getDebugChar(void);
static void Debug_Putchar(char ch);
-static void Debug_Puts(int DbgOnly, char *Str);
+static void Debug_Puts(int DbgOnly, const char *Str);
void Debug_Fmt(const char *format, va_list args);
// === GLOBALS ===
KernelPanic_PutChar(ch);
}
-static void Debug_Puts(int UseKTerm, char *Str)
+static void Debug_Puts(int UseKTerm, const char *Str)
{
int len = 0;
while( *Str )
}
/**
- * \fn void LogF(char *Msg, ...)
+ * \fn void LogF(const char *Msg, ...)
+ * \brief Raw debug log (no new line, no prefix)
*/
-void LogF(char *Fmt, ...)
+void LogF(const char *Fmt, ...)
{
va_list args;
#endif
}
/**
- * \fn void Debug(char *Msg, ...)
+ * \fn void Debug(const char *Msg, ...)
* \brief Print only to the debug channel
*/
-void Debug(char *Fmt, ...)
+void Debug(const char *Fmt, ...)
{
va_list args;
#endif
}
/**
- * \fn void Log(char *Msg, ...)
+ * \fn void Log(const char *Msg, ...)
*/
-void Log(char *Fmt, ...)
+void Log(const char *Fmt, ...)
{
va_list args;
SHORTREL(&glDebug_Lock);
#endif
}
-void Warning(char *Fmt, ...)
+void Warning(const char *Fmt, ...)
{
va_list args;
SHORTREL(&glDebug_Lock);
#endif
}
-void Panic(char *Fmt, ...)
+void Panic(const char *Fmt, ...)
{
va_list args;
for(;;) __asm__ __volatile__ ("hlt");
}
-void Debug_SetKTerminal(char *File)
+void Debug_SetKTerminal(const char *File)
{
int tmp;
if(giDebug_KTerm != -1) {
Log_Log("Debug", "Returning to %p", __builtin_return_address(0));
}
-void Debug_Enter(char *FuncName, char *ArgTypes, ...)
+void Debug_Enter(const char *FuncName, const char *ArgTypes, ...)
{
va_list args;
int i;
while(*ArgTypes)
{
pos = strpos(ArgTypes, ' ');
- if(pos != -1) ArgTypes[pos] = '\0';
if(pos == -1 || pos > 1) {
- Debug_Puts(1, ArgTypes+1);
+ if(pos == -1)
+ Debug_Puts(1, ArgTypes+1);
+ else {
+ for( i = 1; i < pos; i ++ )
+ Debug_Putchar(ArgTypes[i]);
+ }
Debug_Putchar('=');
}
- if(pos != -1) ArgTypes[pos] = ' ';
switch(*ArgTypes)
{
case 'p': LogF("%p", va_arg(args, void*)); break;
#endif
}
-void Debug_Log(char *FuncName, char *Fmt, ...)
+void Debug_Log(const char *FuncName, const char *Fmt, ...)
{
va_list args;
int i = gDebug_Level;
#endif
}
-void Debug_Leave(char *FuncName, char RetType, ...)
+void Debug_Leave(const char *FuncName, char RetType, ...)
{
va_list args;
int i;
#endif
}
-void Debug_HexDump(char *Header, void *Data, Uint Length)
+void Debug_HexDump(const char *Header, const void *Data, Uint Length)
{
- Uint8 *cdat = Data;
+ const Uint8 *cdat = Data;
Uint pos = 0;
Debug_Puts(1, Header);
LogF(" (Hexdump of %p)\r\n", Data);
* \{
*/
extern void Debug_KernelPanic(void); //!< Initiate a kernel panic
-extern void Panic(char *Msg, ...); //!< Print a panic message (initiates a kernel panic)
-extern void Warning(char *Msg, ...); //!< Print a warning message
-extern void LogF(char *Fmt, ...); //!< Print a log message without a trailing newline
-extern void Log(char *Fmt, ...); //!< Print a log message
-extern void Debug(char *Fmt, ...); //!< Print a debug message (doesn't go to KTerm)
-extern void LogV(char *Fmt, va_list Args); //!< va_list Log message
-extern void Debug_Enter(char *FuncName, char *ArgTypes, ...);
-extern void Debug_Log(char *FuncName, char *Fmt, ...);
-extern void Debug_Leave(char *FuncName, char RetType, ...);
-extern void Debug_HexDump(char *Header, void *Data, Uint Length);
+extern void Panic(const char *Msg, ...); //!< Print a panic message (initiates a kernel panic)
+extern void Warning(const char *Msg, ...); //!< Print a warning message
+extern void LogF(const char *Fmt, ...); //!< Print a log message without a trailing newline
+extern void Log(const char *Fmt, ...); //!< Print a log message
+extern void Debug(const char *Fmt, ...); //!< Print a debug message (doesn't go to KTerm)
+extern void LogV(const char *Fmt, va_list Args); //!< va_list Log message
+extern void Debug_Enter(const char *FuncName, const char *ArgTypes, ...);
+extern void Debug_Log(const char *FuncName, const char *Fmt, ...);
+extern void Debug_Leave(const char *FuncName, char RetType, ...);
+extern void Debug_HexDump(const char *Header, const void *Data, Uint Length);
#define UNIMPLEMENTED() Warning("'%s' unimplemented", __func__)
#if DEBUG
# define ENTER(_types...) Debug_Enter((char*)__func__, _types)
Uint Flags;
//! \brief Callback to mount a device
- tVFS_Node *(*InitDevice)(char *Device, char **Options);
+ tVFS_Node *(*InitDevice)(const char *Device, const char **Options);
//! \brief Callback to unmount a device
void (*Unmount)(tVFS_Node *Node);
//! \brief Used internally (next driver in the chain)
* \brief Get the information structure of a driver given its name
* \param Name Name of filesystem driver to find
*/
-extern tVFS_Driver *VFS_GetFSByName(char *Name);
+extern tVFS_Driver *VFS_GetFSByName(const char *Name);
/**
* \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
* \brief Transforms Unix Permssions into Acess ACLs
* \param Mode Flags defining how to open the file
* \return VFS Handle (an integer) or -1 if an error occured
*/
-extern int VFS_Open(char *Path, Uint Mode);
+extern int VFS_Open(const char *Path, Uint Mode);
/**
* \brief Close a currently open file
* \param FD Handle returned by ::VFS_Open
* \param Buffer Source of written data
* \return Number of bytes written
*/
-extern Uint64 VFS_Write(int FD, Uint64 Length, void *Buffer);
+extern Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer);
/**
* \brief Reads from a specific offset in the file
* \param Buffer Source of written data
* \return Number of bytes written
*/
-extern Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer);
+extern Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer);
/**
* \brief Sends an IOCtl request to the driver
* \param Path File path (may contain symlinks, relative elements etc.)
* \return Absolute path with no symlinks
*/
-extern char *VFS_GetTruePath(char *Path);
+extern char *VFS_GetTruePath(const char *Path);
/**
* \brief Mounts a filesystem
* \param Options Options string to pass the driver
* \return 1 on succes, -1 on error
*/
-extern int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *Options);
+extern int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
/**
* \brief Create a new directory
* \param Path Path to new directory (absolute or relative)
* \return Boolean success
* \note The parent of the directory must exist
*/
-extern int VFS_MkDir(char *Path);
+extern int VFS_MkDir(const char *Path);
/**
* \brief Create a symbolic link
* \param Name Name of the symbolic link
* \param Link File the symlink points to
* \return Boolean success (\a Link is not tested for existence)
*/
-extern int VFS_Symlink(char *Name, char *Link);
+extern int VFS_Symlink(const char *Name, const char *Link);
/**
* \brief Read from a directory
* \param FD File handle returned by ::VFS_Open
* \param Mode Open mode
* \return File handle (same as returned from VFS_Open)
*/
-extern int VFS_OpenChild(Uint *Errno, int FD, char *Name, Uint Mode);
+extern int VFS_OpenChild(Uint *Errno, int FD, const char *Name, Uint Mode);
#endif
int DivUp(int num, int dem);
Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year);
-Uint rand(void);
+ int rand(void);
int CheckString(char *String);
int CheckMem(void *Mem, int NumBytes);
itoa(p, val, 10, minSize, pad);
goto printString;
case 'X':
- #if BITS == 64
- isLongLong = 1; // TODO: Handle non-x86 64-bit archs
- #endif
+ if(BITS == 64)
+ isLongLong = 1; // TODO: Handle non-x86 64-bit archs
GETVAL();
itoa(p, val, 16, minSize, pad);
goto printString;
}
/**
- * \fn Uint strlen(const char *__str)
+ * \fn size_t strlen(const char *__str)
* \brief Get the length of string
*/
-Uint strlen(const char *__str)
+size_t strlen(const char *__str)
{
- Uint ret = 0;
+ size_t ret = 0;
while(*__str++) ret++;
return ret;
}
}
/**
- * \fn Uint rand()
+ * \fn int rand()
* \brief Pseudo random number generator
- * \note Unknown effectiveness (made up on the spot)
*/
-Uint rand(void)
+int rand(void)
{
#if 0
static Uint state = RANDOM_SEED;
extern tVFS_Mount *gRootMount;
// === PROTOTYPES ===
- int VFS_MkDir(char *Path);
- int VFS_MkNod(char *Path, Uint Flags);
+ int VFS_MkDir(const char *Path);
+ int VFS_MkNod(const char *Path, Uint Flags);
// === CODE ===
/**
* \brief Create a new node
* \param Path Path of directory to create
*/
-int VFS_MkDir(char *Path)
+int VFS_MkDir(const char *Path)
{
return VFS_MkNod(Path, VFS_FFLAG_DIRECTORY);
}
* \param Path Path of new node
* \param Flags Flags to apply to the node
*/
-int VFS_MkNod(char *Path, Uint Flags)
+int VFS_MkNod(const char *Path, Uint Flags)
{
char *absPath, *name;
int pos = 0, oldpos = 0;
}
/**
- * \fn int VFS_Symlink(char *Name, char *Link)
+ * \fn int VFS_Symlink(const char *Name, const char *Link)
* \brief Creates a symlink called \a Name to \a Link
* \param Name Name of symbolic link
* \param Link Destination of symbolic link
*/
-int VFS_Symlink(char *Name, char *Link)
+int VFS_Symlink(const char *Name, const char *Link)
{
char *realLink;
int fp;
tVFS_Node *destNode;
+ char *_link;
//ENTER("sName sLink", Name, Link);
// Get absolue path name
- Link = VFS_GetAbsPath( Link );
- if(!Link) {
+ _link = VFS_GetAbsPath( Link );
+ if(!_link) {
Warning("Path '%s' is badly formed", Link);
return -1;
}
// Get true path and node
- destNode = VFS_ParsePath( Link, &realLink );
- free(Link);
+ destNode = VFS_ParsePath( _link, &realLink );
+ free(_link);
+ _link = NULL;
// Check if destination exists
if(!destNode) {
// === PROTOTYPES ===
int DevFS_AddDevice(tDevFS_Driver *Device);
void DevFS_DelDevice(tDevFS_Driver *Device);
-tVFS_Node *DevFS_InitDevice(char *Device, char **Options);
+tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options);
char *DevFS_ReadDir(tVFS_Node *Node, int Pos);
tVFS_Node *DevFS_FindDir(tVFS_Node *Node, const char *Name);
}
/**
- * \fn tVFS_Node *DevFS_InitDevice(char *Device, char **Options)
* \brief Initialise the DevFS and detect double-mounting, or just do nothing
* \note STUB
*/
-tVFS_Node *DevFS_InitDevice(char *Device, char **Options)
+tVFS_Node *DevFS_InitDevice(const char *Device, const char **Options)
{
return &gDevFS_RootNode;
}
#define MAX_FILES 64
// === PROTOTYPES ===
-tVFS_Node *Root_InitDevice(char *Device, char **Options);
+tVFS_Node *Root_InitDevice(const char *Device, const char **Options);
int Root_MkNod(tVFS_Node *Node, const char *Name, Uint Flags);
tVFS_Node *Root_FindDir(tVFS_Node *Node, const char *Name);
char *Root_ReadDir(tVFS_Node *Node, int Pos);
// === CODE ===
/**
- * \fn tVFS_Node *Root_InitDevice(char *Device, char **Options)
* \brief Initialise the root filesystem
*/
-tVFS_Node *Root_InitDevice(char *Device, char **Options)
+tVFS_Node *Root_InitDevice(const char *Device, const char **Options)
{
tRamFS_File *root;
if(strcmp(Device, "root") != 0) {
for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
{
if(gaUserHandles[i].Node) continue;
- gaUserHandles[i].Node = node;
+ gaUserHandles[i].Node = Node;
gaUserHandles[i].Position = 0;
gaUserHandles[i].Mode = Mode;
return i;
for(i=0;i<MAX_KERNEL_FILES;i++)
{
if(gaKernelHandles[i].Node) continue;
- gaKernelHandles[i].Node = node;
+ gaKernelHandles[i].Node = Node;
gaKernelHandles[i].Position = 0;
gaKernelHandles[i].Mode = Mode;
return i|VFS_KERNEL_FLAG;
}
/**
- * \fn Uint64 VFS_Write(int FD, Uint64 Length, void *Buffer)
+ * \fn Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
* \brief Read data from a node (file)
*/
-Uint64 VFS_Write(int FD, Uint64 Length, void *Buffer)
+Uint64 VFS_Write(int FD, Uint64 Length, const void *Buffer)
{
tVFS_Handle *h;
Uint64 ret;
if(!h->Node->Write) return 0;
- ret = h->Node->Write(h->Node, h->Position, Length, Buffer);
+ // TODO: This is a hack, I need to change VFS_Node to have "const void*"
+ ret = h->Node->Write(h->Node, h->Position, Length, (void*)Buffer);
if(ret == -1) return -1;
h->Position += ret;
return ret;
}
/**
- * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
+ * \fn Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
* \brief Write data to a file at a given offset
*/
-Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, void *Buffer)
+Uint64 VFS_WriteAt(int FD, Uint64 Offset, Uint64 Length, const void *Buffer)
{
tVFS_Handle *h;
Uint64 ret;
if( h->Node->Flags & VFS_FFLAG_DIRECTORY ) return -1;
if(!h->Node->Write) return 0;
- ret = h->Node->Write(h->Node, Offset, Length, Buffer);
+ // TODO: This is a hack, I need to change VFS_Node to have "const void*"
+ ret = h->Node->Write(h->Node, Offset, Length, (void*)Buffer);
if(ret == -1) return -1;
return ret;
}
// === PROTOTYPES ===
int VFS_Init(void);
-char *VFS_GetTruePath(char *Path);
+char *VFS_GetTruePath(const char *Path);
void VFS_GetMemPath(char *Dest, void *Base, Uint Length);
-tVFS_Driver *VFS_GetFSByName(char *Name);
+tVFS_Driver *VFS_GetFSByName(const char *Name);
int VFS_AddDriver(tVFS_Driver *Info);
void VFS_UpdateDriverFile(void);
}
/**
- * \fn char *VFS_GetTruePath(char *Path)
+ * \fn char *VFS_GetTruePath(const char *Path)
* \brief Gets the true path (non-symlink) of a file
*/
-char *VFS_GetTruePath(char *Path)
+char *VFS_GetTruePath(const char *Path)
{
tVFS_Node *node;
char *ret, *tmp;
}
/**
- * \fn tVFS_Driver *VFS_GetFSByName(char *Name)
+ * \fn tVFS_Driver *VFS_GetFSByName(const char *Name)
* \brief Gets a filesystem structure given a name
*/
-tVFS_Driver *VFS_GetFSByName(char *Name)
+tVFS_Driver *VFS_GetFSByName(const char *Name)
{
tVFS_Driver *drv = gVFS_Drivers;
extern char *gsVFS_MountFile;
// === PROTOTYPES ===
- int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *Options);
+ int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
void VFS_UpdateMountFile(void);
// === GLOBALS ===
* \a Filesystem. The options in the string \a Options is passed to the
* driver's mount.
*/
-int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *Options)
+int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options)
{
tVFS_Mount *mnt;
tVFS_Driver *fs;
}
/**
- * \fn int VFS_Open(char *Path, Uint Mode)
+ * \fn int VFS_Open(const char *Path, Uint Mode)
* \brief Open a file
*/
-int VFS_Open(char *Path, Uint Mode)
+int VFS_Open(const char *Path, Uint Mode)
{
tVFS_Node *node;
char *absPath;
/**
* \brief Open a file from an open directory
*/
-int VFS_OpenChild(Uint *Errno, int FD, char *Name, Uint Mode)
+int VFS_OpenChild(Uint *Errno, int FD, const char *Name, Uint Mode)
{
tVFS_Handle *h;
tVFS_Node *node;
// === PROTOTYPES ===\r
int Ext2_Install(char **Arguments);\r
// Interface Functions\r
-tVFS_Node *Ext2_InitDevice(char *Device, char **Options);\r
+tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options);\r
void Ext2_Unmount(tVFS_Node *Node);\r
void Ext2_CloseFile(tVFS_Node *Node);\r
// Internal Helpers\r
}\r
\r
/**\r
- \fn tVFS_Node *Ext2_InitDevice(char *Device, char **Options)\r
\brief Initializes a device to be read by by the driver\r
\param Device String - Device to read from\r
\param Options NULL Terminated array of option strings\r
\return Root Node\r
*/\r
-tVFS_Node *Ext2_InitDevice(char *Device, char **Options)\r
+tVFS_Node *Ext2_InitDevice(const char *Device, const char **Options)\r
{\r
tExt2_Disk *disk;\r
int fd;\r
// === PROTOTYPES ===\r
// --- Driver Core\r
int FAT_Install(char **Arguments);\r
-tVFS_Node *FAT_InitDevice(char *device, char **options);\r
+tVFS_Node *FAT_InitDevice(const char *device, const char **options);\r
void FAT_Unmount(tVFS_Node *Node);\r
// --- Helpers\r
int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Cluster);\r
}\r
\r
/**\r
- * \fn tVFS_Node *FAT_InitDevice(char *Device, char **Options)\r
* \brief Reads the boot sector of a disk and prepares the structures for it\r
*/\r
-tVFS_Node *FAT_InitDevice(char *Device, char **Options)\r
+tVFS_Node *FAT_InitDevice(const char *Device, const char **Options)\r
{\r
fat_bootsect *bs;\r
int i;\r
// === PROTOTYPES ===
int NTFS_Install(char **Arguments);
-tVFS_Node *NTFS_InitDevice(char *Devices, char **Options);
+tVFS_Node *NTFS_InitDevice(const char *Devices, const char **Options);
void NTFS_Unmount(tVFS_Node *Node);
void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry);
/**
* \brief Mount a NTFS volume
*/
-tVFS_Node *NTFS_InitDevice(char *Device, char **Options)
+tVFS_Node *NTFS_InitDevice(const char *Device, const char **Options)
{
tNTFS_Disk *disk;
tNTFS_BootSector bs;