CPPFLAGS += -I./include -I./arch/$(ARCHDIR)/include -D_MODULE_NAME_=\"Kernel\"
CPPFLAGS += -DARCH=$(ARCH) -DARCHDIR=$(ARCHDIR) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM)
CFLAGS += -Wall -Werror -fno-stack-protector -fno-builtin -Wstrict-prototypes -g
+CFLAGS += -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wuninitialized
ASFLAGS += -D ARCH=\"$(ARCH)\" -D ARCHDIR=\"$(ARCHDIR)\"
LDFLAGS += -T arch/$(ARCHDIR)/link.ld -g
{
int endData = Buffer->Space - Buffer->Start;
memcpy(Dest, &Buffer->Data[Buffer->Start], endData);
- memcpy(Dest + endData, &Buffer->Data, Length - endData);
+ memcpy((Uint8*)Dest + endData, &Buffer->Data, Length - endData);
}
else
{
if(endSpace < Length)
{
memcpy( &Buffer->Data[bufEnd], Source, endSpace );
- memcpy( Buffer->Data, Source + endSpace, Length - endSpace );
+ memcpy( Buffer->Data, (Uint8*)Source + endSpace, Length - endSpace );
Buffer->Length = Length - endSpace;
}
else
// === MACROS ===
/**
- * \brief Halt the CPU
+ * \brief Halt the CPU (shorter version of yield)
*/
#define HALT() __asm__ __volatile__ ("hlt")
/**
#define _MM_PHYS_H
// === FUNCTIONS ===
-extern tPAddr MM_AllocPhys(void);
-extern tPAddr MM_AllocPhysRange(int Pages, int MaxBits);
-extern void MM_RefPhys(tPAddr PAddr);
-extern void MM_DerefPhys(tPAddr PAddr);
-extern int MM_GetRefCount(tPAddr Addr);
+//extern tPAddr MM_AllocPhys(void);
+//extern tPAddr MM_AllocPhysRange(int Pages, int MaxBits);
+//extern void MM_RefPhys(tPAddr PAddr);
+//extern void MM_DerefPhys(tPAddr PAddr);
+//extern int MM_GetRefCount(tPAddr Addr);
#endif
// === FUNCTIONS ===
extern void MM_FinishVirtualInit(void);
extern void MM_SetCR3(Uint CR3);
-extern tPAddr MM_Allocate(tVAddr VAddr) __attribute__ ((warn_unused_result));
-extern void MM_Deallocate(tVAddr VAddr);
-extern int MM_Map(tVAddr VAddr, tPAddr PAddr);
extern tPAddr MM_Clone(void);
extern tVAddr MM_NewKStack(void);
extern tVAddr MM_NewWorkerStack(void);
// === TYPES ===
typedef void (*tIRQ_Callback)(int);
+// === PROTOTYPES ===
+void IRQ_Handler(tRegs *Regs);
+
// === GLOBALS ===
tIRQ_Callback gIRQ_Handlers[16][MAX_CALLBACKS_PER_IRQ];
};
#define NUM_REGVALUES (sizeof(caRegValues)/sizeof(caRegValues[0]))
+// === PROTOTYPES ===
+void KernelPanic_SetMode(void);
+void KernelPanic_PutChar(char Ch);
+
+// === CODE ===
/**
* \brief Sets the screen mode for a kernel panic
*/
extern struct sShortSpinlock glDebug_Lock;
#endif
+// === IMPRORTS ===
extern int GetCPUNum(void);
+// === PROTOTYPES ==
+Uint64 __udivdi3(Uint64 Num, Uint64 Den);
+Uint64 __umoddi3(Uint64 Num, Uint64 Den);
+
// === CODE ===
/**
* \brief Determine if a short spinlock is locked
*/
int memcmp(const void *m1, const void *m2, size_t Num)
{
+ const Uint8 *d1 = m1;
+ const Uint8 *d2 = m2;
if( Num == 0 ) return 0; // No bytes are always identical
while(Num--)
{
- if(*(Uint8*)m1 != *(Uint8*)m2)
- return *(Uint8*)m1 - *(Uint8*)m2;
- m1 ++;
- m2 ++;
+ if(*d1 != *d2)
+ return *d1 - *d2;
+ d1 ++;
+ d2 ++;
}
return 0;
}
extern void Threads_Init(void);
extern int Time_Setup(void);
extern Uint Proc_Clone(Uint *Err, Uint Flags);
-extern void Threads_Sleep(void);
// --- Core ---
extern void System_Init(char *Commandline);
// === PROTOTYPES ===
+ int kmain(Uint MbMagic, void *MbInfoPtr);
void Arch_LoadBootModules(void);
// === GLOBALS ===
extern void gKernelEnd;
// === PROTOTYPES ===
-tPAddr MM_AllocPhys(void);
-tPAddr MM_AllocPhysRange(int Pages, int MaxBits);
-void MM_RefPhys(tPAddr PAddr);
-void MM_DerefPhys(tPAddr PAddr);
+void MM_Install(tMBoot_Info *MBoot);
+//tPAddr MM_AllocPhys(void);
+//tPAddr MM_AllocPhysRange(int Pages, int MaxBits);
+//void MM_RefPhys(tPAddr PAddr);
+//void MM_DerefPhys(tPAddr PAddr);
+// int MM_GetRefCount(tPAddr PAddr);
// === GLOBALS ===
tMutex glPhysAlloc;
/**
* \fn int MM_GetRefCount(tPAddr Addr)
*/
-int MM_GetRefCount(tPAddr Addr)
+int MM_GetRefCount(tPAddr PAddr)
{
// Get page number
- Addr >>= 12;
+ PAddr >>= 12;
// We don't care about non-ram pages
- if(Addr >= giPageCount) return -1;
+ if(PAddr >= giPageCount) return -1;
// Check if it is freed
- return gaPageReferences[ Addr ];
+ return gaPageReferences[ PAddr ];
}
void MM_InstallVirtual(void);
void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs);
void MM_DumpTables(tVAddr Start, tVAddr End);
+tVAddr MM_ClearUser(void);
tPAddr MM_DuplicatePage(tVAddr VAddr);
// === GLOBALS ===
void MP_StartAP(int CPU);
void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode);
#endif
-void Proc_Start(void);
-tThread *Proc_GetCurThread(void);
+//void Proc_Start(void);
+//tThread *Proc_GetCurThread(void);
void Proc_ChangeStack(void);
- int Proc_Clone(Uint *Err, Uint Flags);
+// int Proc_Clone(Uint *Err, Uint Flags);
+Uint Proc_MakeUserStack(void);
+void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize);
void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP);
+ int Proc_Demote(Uint *Err, int Dest, tRegs *Regs);
void Proc_CallFaultHandler(tThread *Thread);
void Proc_Scheduler(int CPU);
if(Proc_Clone(0, 0) == 0)
{
gpIdleThread = Proc_GetCurThread();
- gpIdleThread->ThreadName = "Idle Thread";
+ gpIdleThread->ThreadName = strdup("Idle Thread");
Threads_SetPriority( gpIdleThread, -1 ); // Never called randomly
gpIdleThread->Quantum = 1; // 1 slice quantum
for(;;) HALT(); // Just yeilds
volatile Uint64 giTime_TSCPerTick = 0;
// === PROTOTYPES ===
-Sint64 now(void);
+//Sint64 now(void);
int Time_Setup(void);
void Time_Interrupt(int);
Uint64 Time_ReadTSC(void);
// === PROTOTYPES ===
int VM8086_Install(char **Arguments);
void VM8086_GPF(tRegs *Regs);
-tVM8086 *VM8086_Init(void);
+//tVM8086 *VM8086_Init(void);
// === GLOBALS ===
MODULE_DEFINE(0, 0x100, VM8086, VM8086_Install, NULL, NULL);
MM_Map( i * 0x1000, i * 0x1000 ); MM_DerefPhys( i * 0x1000 );
}
MM_Map( 0x9F000, 0x9F000 ); // Stack / EBDA
- MM_Allocate( 0x100000 ); // System Stack / Stub
+ // System Stack / Stub
+ if( MM_Allocate( 0x100000 ) == 0 ) {
+ Log_Error("VM8086", "Unable to allocate memory for stack/stub");
+ gVM8086_WorkerPID = 0;
+ Threads_Exit(0, 1);
+ }
*(Uint8*)(0x100000) = VM8086_OP_IRET;
*(Uint8*)(0x100001) = 0x07; // POP ES
while( gpVM8086_State != NULL )
Threads_Yield(); // Yield to allow the child to initialise
+ // Worker killed itself
+ if( gVM8086_WorkerPID != pid ) {
+ return MODULE_ERR_MISC;
+ }
+
return MODULE_ERR_OK;
}
// === PROTOTYPES ===\r
tBinary *Elf_Load(int fp);\r
int Elf_Relocate(void *Base);\r
- int Elf_GetSymbol(void *Base, char *Name, Uint *ret);\r
+ int Elf_GetSymbol(void *Base, const char *Name, Uint *ret);\r
int Elf_Int_DoRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symtab, Uint base);\r
-Uint Elf_Int_HashString(char *str);\r
+Uint Elf_Int_HashString(const char *str);\r
\r
// === GLOBALS ===\r
tBinaryType gELF_Info = {\r
ENTER("pBase", Base);\r
\r
// Parse Program Header to get Dynamic Table\r
- phtab = Base + hdr->phoff;\r
+ phtab = (void *)( (tVAddr)Base + hdr->phoff );\r
iSegmentCount = hdr->phentcount;\r
for(i = 0; i < iSegmentCount; i ++ )\r
{\r
}\r
\r
/**\r
- * \fn int Elf_GetSymbol(void *Base, char *name, Uint *ret)\r
+ * \fn int Elf_GetSymbol(void *Base, const char *name, Uint *ret)\r
* \brief Get a symbol from the loaded binary\r
*/\r
-int Elf_GetSymbol(void *Base, char *Name, Uint *ret)\r
+int Elf_GetSymbol(void *Base, const char *Name, Uint *ret)\r
{\r
Elf32_Ehdr *hdr = (void*)Base;\r
Elf32_Sym *symtab;\r
* \param str String to hash\r
* \return Hash value\r
*/\r
-Uint Elf_Int_HashString(char *str)\r
+Uint Elf_Int_HashString(const char *str)\r
{\r
Uint h = 0, g;\r
while(*str)\r
tBinary *PE_Load(int fp);\r
tBinary *MZ_Open(int fp);\r
int PE_Relocate(void *Base);\r
- int PE_GetSymbol(void *Base, char *Name, Uint *Ret);\r
+ int PE_GetSymbol(void *Base, const char *Name, Uint *Ret);\r
\r
// === GLOBALS ===\r
MODULE_DEFINE(0, 0x0032, BinPE, PE_Install, NULL, NULL);\r
-char *gsPE_DefaultInterpreter = "/Acess/Libs/ld-acess.so";\r
+const char *gsPE_DefaultInterpreter = "/Acess/Libs/ld-acess.so";\r
tBinaryType gPE_Loader = {\r
NULL,\r
('M'|('Z'<<8)), 0xFFFF, // 'MZ'\r
return 0;\r
}\r
\r
-int PE_GetSymbol(void *Base, char *Name, Uint *Ret)\r
+int PE_GetSymbol(void *Base, const char *Name, Uint *Ret)\r
{\r
return 0;\r
}\r
// === IMPORTS ===
extern int Proc_Clone(Uint *Err, Uint Flags);
extern char *Threads_GetName(int ID);
-extern void Threads_Exit(int, int);
extern Uint MM_ClearUser(void);
extern void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize);
extern tKernelSymbol gKernelSymbols[];
extern tBinaryType gELF_Info;
// === PROTOTYPES ===
- int Proc_Execve(char *File, char **ArgV, char **EnvP);
-Uint Binary_Load(char *file, Uint *entryPoint);
-tBinary *Binary_GetInfo(char *truePath);
+ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP);
+Uint Binary_Load(const char *file, Uint *entryPoint);
+tBinary *Binary_GetInfo(const char *truePath);
Uint Binary_MapIn(tBinary *binary);
Uint Binary_IsMapped(tBinary *binary);
-tBinary *Binary_DoLoad(char *truePath);
+tBinary *Binary_DoLoad(const char *truePath);
void Binary_Dereference(tBinary *Info);
+#if 0
Uint Binary_Relocate(void *Base);
-Uint Binary_GetSymbolEx(char *Name, Uint *Value);
-Uint Binary_FindSymbol(void *Base, char *Name, Uint *Val);
+#endif
+Uint Binary_GetSymbolEx(const char *Name, Uint *Value);
+#if 0
+Uint Binary_FindSymbol(void *Base, const char *Name, Uint *Val);
+#endif
// === GLOBALS ===
tShortSpinlock glBinListLock;
if(Proc_Clone(NULL, CLONE_VM) == 0)
{
// CHILD
- char *args[2] = {stackPath, NULL};
+ const char *args[2] = {stackPath, NULL};
LOG("stackPath = '%s'\n", stackPath);
Proc_Execve(stackPath, args, &args[1]);
for(;;);
* \param EnvP User's environment
* \note Called Proc_ for historical reasons
*/
-int Proc_Execve(char *File, char **ArgV, char **EnvP)
+int Proc_Execve(const char *File, const char **ArgV, const char **EnvP)
{
int argc, envc, i;
int argenvBytes;
* \param file Path to binary to load
* \param entryPoint Pointer for exectuable entry point
*/
-Uint Binary_Load(char *file, Uint *entryPoint)
+Uint Binary_Load(const char *file, Uint *entryPoint)
{
char *sTruePath;
tBinary *pBinary;
* \brief Finds a matching binary entry
* \param TruePath File Identifier (True path name)
*/
-tBinary *Binary_GetInfo(char *TruePath)
+tBinary *Binary_GetInfo(const char *TruePath)
{
tBinary *pBinary;
pBinary = glLoadedBinaries;
* \brief Loads a binary file into memory
* \param truePath Absolute filename of binary
*/
-tBinary *Binary_DoLoad(char *truePath)
+tBinary *Binary_DoLoad(const char *truePath)
{
tBinary *pBinary;
int fp, i;
// Initialise Structure
pBinary->ReferenceCount = 0;
- pBinary->TruePath = malloc( strlen(truePath) + 1 );
- strcpy(pBinary->TruePath, truePath);
+ pBinary->TruePath = strdup(truePath);
// Debug Information
LOG("Interpreter: '%s'", pBinary->Interpreter);
// Kernel Binary Handling
// ============
/**
- * \fn void *Binary_LoadKernel(char *File)
+ * \fn void *Binary_LoadKernel(const char *File)
* \brief Load a binary into kernel space
* \note This function shares much with #Binary_Load, but does it's own mapping
* \param File File to load into the kernel
*/
-void *Binary_LoadKernel(char *File)
+void *Binary_LoadKernel(const char *File)
{
char *sTruePath;
tBinary *pBinary;
Uint addr;
int i;
- ENTER("sfile", File);
+ ENTER("sFile", File);
// Sanity Check Argument
if(File == NULL) {
* Gets the value of a symbol from either the currently loaded
* libraries or the kernel's exports.
*/
-int Binary_GetSymbol(char *Name, Uint *Val)
+int Binary_GetSymbol(const char *Name, Uint *Val)
{
if( Binary_GetSymbolEx(Name, Val) ) return 1;
return 0;
* Gets the value of a symbol from either the currently loaded
* libraries or the kernel's exports.
*/
-Uint Binary_GetSymbolEx(char *Name, Uint *Value)
+Uint Binary_GetSymbolEx(const char *Name, Uint *Value)
{
int i;
tKernelBin *pKBin;
* \param Name Name of symbol to find
* \param Val Pointer to place final value
*/
-Uint Binary_FindSymbol(void *Base, char *Name, Uint *Val)
+Uint Binary_FindSymbol(void *Base, const char *Name, Uint *Val)
{
Uint32 ident = *(Uint32*) Base;
tBinaryType *bt = gRegBinTypes;
int getDebugChar(void);
static void Debug_Putchar(char ch);
static void Debug_Puts(int DbgOnly, const char *Str);
+void Debug_DbgOnlyFmt(const char *format, va_list args);
+void Debug_FmtS(const char *format, ...);
void Debug_Fmt(const char *format, va_list args);
+void Debug_SetKTerminal(const char *File);
// === GLOBALS ===
int gDebug_Level = 0;
va_start(args, ArgTypes);
+ LogF("%012lli ", now());
while(i--) Debug_Putchar(' ');
Debug_Puts(1, FuncName);
va_start(args, Fmt);
+ LogF("%012lli ", now());
while(i--) Debug_Putchar(' ');
Debug_Puts(1, FuncName);
gDebug_Level = 0;
i = 0;
}
+ LogF("%012lli ", now());
// Indenting
while(i--) Debug_Putchar(' ');
int DMA_Install(char **Arguments);\r
void DMA_SetChannel(int Channel, int length, int read);\r
int DMA_ReadData(int channel, int count, void *buffer);\r
+ int DMA_WriteData(int channel, int count, const void *buffer);\r
\r
// === CONSTANTS ===\r
const Uint8 cMASKPORT [8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 };\r
* \fn void DMA_WriteData(int channel, int count, void *buffer)\r
* \brief Write data to a DMA buffer\r
*/\r
-int DMA_WriteData(int channel, int count, void *buffer)\r
+int DMA_WriteData(int channel, int count, const void *buffer)\r
{\r
if(channel < 0 || channel > 7)\r
return -1;\r
int FIFO_Relink(tVFS_Node *Node, const char *OldName, const char *NewName);
Uint64 FIFO_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
Uint64 FIFO_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
-tPipe *FIFO_Int_NewPipe(int Size, char *Name);
+tPipe *FIFO_Int_NewPipe(int Size, const char *Name);
// === GLOBALS ===
MODULE_DEFINE(0, 0x0032, FIFO, FIFO_Install, NULL, NULL);
while(remaining)
{
// Wait for buffer to fill
- if(pipe->Flags & PF_BLOCKING) {
+ if(pipe->Flags & PF_BLOCKING)
+ {
len = Semaphore_Wait( &pipe->Semaphore, remaining );
}
else
{
int ofs = pipe->BufSize - pipe->ReadPos;
memcpy(Buffer, &pipe->Buffer[pipe->ReadPos], ofs);
- memcpy(Buffer + ofs, &pipe->Buffer, len-ofs);
+ memcpy((Uint8*)Buffer + ofs, &pipe->Buffer, len-ofs);
}
else
{
// Decrement Remaining Bytes
remaining -= len;
// Increment Buffer address
- Buffer += len;
+ Buffer = (Uint8*)Buffer + len;
}
return Length;
{
int ofs = pipe->BufSize - pipe->WritePos;
memcpy(&pipe->Buffer[pipe->WritePos], Buffer, ofs);
- memcpy(&pipe->Buffer, Buffer + ofs, len-ofs);
+ memcpy(&pipe->Buffer, (Uint8*)Buffer + ofs, len-ofs);
}
else
{
// Decrement Remaining Bytes
remaining -= len;
// Increment Buffer address
- Buffer += len;
+ Buffer = (Uint8*)Buffer + len;
}
return Length;
// --- HELPERS ---
/**
- * \fn tPipe *FIFO_Int_NewPipe(int Size, char *Name)
+ * \fn tPipe *FIFO_Int_NewPipe(int Size, const char *Name)
* \brief Create a new pipe
*/
-tPipe *FIFO_Int_NewPipe(int Size, char *Name)
+tPipe *FIFO_Int_NewPipe(int Size, const char *Name)
{
tPipe *ret;
int namelen = strlen(Name) + 1;
// Remove from list
SHORTLOCK( &glIOCache_Caches );
{
- tIOCache *ent;
- tIOCache *prev = (tIOCache*)&gIOCache_Caches;
- for(ent = gIOCache_Caches;
- ent;
- prev = ent, ent = ent->Next )
+ tIOCache *cache;
+ tIOCache *prev_cache = (tIOCache*)&gIOCache_Caches;
+ for(cache = gIOCache_Caches;
+ cache;
+ prev_cache = cache, cache = cache->Next )
{
- if(ent == Cache) {
- prev->Next = ent->Next;
+ if(cache == Cache) {
+ prev_cache->Next = cache->Next;
break;
}
}
char *PCI_ReadDirRoot(tVFS_Node *node, int pos);\r
tVFS_Node *PCI_FindDirRoot(tVFS_Node *node, const char *filename);\r
Uint64 PCI_ReadDevice(tVFS_Node *node, Uint64 pos, Uint64 length, void *buffer);\r
- \r
+\r
+#if 0\r
int PCI_CountDevices(Uint16 vendor, Uint16 device, Uint16 fcn);\r
int PCI_GetDevice(Uint16 vendor, Uint16 device, Uint16 fcn, int idx);\r
int PCI_GetDeviceByClass(Uint16 class, Uint16 mask, int prev);\r
Uint8 PCI_GetIRQ(int id);\r
Uint32 PCI_GetBAR0(int id);\r
Uint32 PCI_GetBAR1(int id);\r
+Uint32 PCI_GetBAR2(int id);\r
Uint32 PCI_GetBAR3(int id);\r
Uint32 PCI_GetBAR4(int id);\r
Uint32 PCI_GetBAR5(int id);\r
Uint16 PCI_AssignPort(int id, int bar, int count);\r
+#endif\r
\r
int PCI_EnumDevice(Uint16 bus, Uint16 dev, Uint16 fcn, tPCIDevice *info);\r
Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
int SysFS_Install(char **Arguments);
int SysFS_IOCtl(tVFS_Node *Node, int Id, void *Data);
- int SysFS_RegisterFile(char *Path, char *Data, int Length);
- int SysFS_UpdateFile(int ID, char *Data, int Length);
+#if 0
+ int SysFS_RegisterFile(const char *Path, const char *Data, int Length);
+ int SysFS_UpdateFile(int ID, const char *Data, int Length);
int SysFS_RemoveFile(int ID);
+#endif
char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Id);
tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename);
&gSysFS_Version, // Parent
{
.Inode = 1, // File #1
- .ImplPtr = KERNEL_VERSION_STRING,
+ .ImplPtr = (void*)KERNEL_VERSION_STRING,
.ImplInt = (Uint)&gSysFS_Version_Kernel, // Self-Link
.Size = sizeof(KERNEL_VERSION_STRING)-1,
.NumACLs = 1,
* \param Length Length of the data buffer
* \return The file's identifier
*/
-int SysFS_RegisterFile(char *Path, char *Data, int Length)
+int SysFS_RegisterFile(const char *Path, const char *Data, int Length)
{
int start = 0;
int tmp;
child->Parent = ent;
child->Node.Inode = giSysFS_NextFileID++;
- child->Node.ImplPtr = Data;
+ child->Node.ImplPtr = (void*)Data;
child->Node.ImplInt = (Uint)child; // Uplink
child->Node.Size = Length;
child->Node.NumACLs = 1;
* \param Length Length of the data buffer
* \return Boolean Success
*/
-int SysFS_UpdateFile(int ID, char *Data, int Length)
+int SysFS_UpdateFile(int ID, const char *Data, int Length)
{
tSysFS_Ent *ent;
if(ent->Node.Inode < ID) return 0;
if(ent->Node.Inode == ID)
{
- ent->Node.ImplPtr = Data;
+ ent->Node.ImplPtr = (void*)Data;
ent->Node.Size = Length;
return 1;
}
int VGA_Install(char **Arguments);
Uint64 VGA_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
int VGA_IOCtl(tVFS_Node *Node, int Id, void *Data);
+Uint8 VGA_int_GetColourNibble(Uint16 col);
Uint16 VGA_int_GetWord(tVT_Char *Char);
void VGA_int_SetCursor(Sint16 x, Sint16 y);
#define VT_FLAG_HASFB 0x10 //!< Set if the VTerm has requested the Framebuffer
enum eVT_InModes {
- VT_INMODE_TEXT8, // UTF-8 Text Mode (VT100 Emulation)
+ VT_INMODE_TEXT8, // UTF-8 Text Mode (VT100/xterm Emulation)
VT_INMODE_TEXT32, // UTF-32 Text Mode (Acess Native)
NUM_VT_INMODES
};
} tVTerm;
// === IMPORTS ===
-extern void Debug_SetKTerminal(char *File);
+extern void Debug_SetKTerminal(const char *File);
// === PROTOTYPES ===
int VT_Install(char **Arguments);
void VT_SetTerminal(int ID);
void VT_KBCallBack(Uint32 Codepoint);
void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count);
+void VT_int_ClearLine(tVTerm *Term, int Num);
int VT_int_ParseEscape(tVTerm *Term, char *Buffer);
void VT_int_PutChar(tVTerm *Term, Uint32 Ch);
void VT_int_ScrollFramebuffer( tVTerm *Term );
Log_Debug("VTerm", "Argument '%s'", arg);
if( strcmp(opt, "Video") == 0 ) {
- gsVT_OutputDevice = val;
+ gsVT_OutputDevice = strdup(val);
}
else if( strcmp(opt, "Input") == 0 ) {
- gsVT_InputDevice = val;
+ gsVT_InputDevice = strdup(val);
}
else if( strcmp(opt, "Width") == 0 ) {
giVT_RealWidth = atoi( val );
if(gsVT_InputDevice) Modules_InitialiseBuiltin( gsVT_InputDevice );
// Apply Defaults
- if(!gsVT_OutputDevice) gsVT_OutputDevice = DEFAULT_OUTPUT;
- if(!gsVT_InputDevice) gsVT_InputDevice = DEFAULT_INPUT;
+ if(!gsVT_OutputDevice) gsVT_OutputDevice = strdup(DEFAULT_OUTPUT);
+ if(!gsVT_InputDevice) gsVT_InputDevice = strdup(DEFAULT_INPUT);
// Create paths
{
len = strlen(Data);
+ // TODO: Check if the string used is a heap string
+
free(gsVT_OutputDevice);
gsVT_OutputDevice = malloc(len+1);
void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
{
int i;
-
+
switch(Ch)
{
case '\0': return; // Ignore NULL byte
// - Check if we need to scroll the entire scrollback buffer
if(Term->WritePos >= Term->TextWidth*Term->TextHeight*(giVT_Scrollback+1))
{
- int base, i;
+ int base;
// Move back by one
Term->WritePos -= Term->TextWidth;
return leading;
}
- Buffer += leading;
+ Buffer = (Uint8*)Buffer + leading;
block ++;
num = ( Length - leading ) / BlockSize;
tailings = Length - num * BlockSize - leading;
{
LOG("Reading %i bytes from last block", tailings);
block += num;
- Buffer += num * BlockSize;
+ Buffer = (Uint8*)Buffer + num * BlockSize;
ret = ReadBlocks(block, 1, tmp, Argument);
if(ret != 1) {
LEAVE('X', leading + num * BlockSize);
return leading;
}
- Buffer += leading;
+ Buffer = (Uint8*)Buffer + leading;
block ++;
num = ( Length - leading ) / BlockSize;
tailings = Length - num * BlockSize - leading;
{
LOG("Writing %i bytes to last block", tailings);
block += num;
- Buffer += num * BlockSize;
+ Buffer = (Uint8*)Buffer + num * BlockSize;
// Read
ret = ReadBlocks(block, 1, tmp, Argument);
if(ret != 1) {
void Heap_Install(void);
void *Heap_Extend(int Bytes);
void *Heap_Merge(tHeapHead *Head);
-void *Heap_Allocate(const char *File, int Line, size_t Bytes);
-void *Heap_AllocateZero(const char *File, int Line, size_t Bytes);
-void *Heap_Reallocate(const char *File, int Line, void *Ptr, size_t Bytes);
-void Heap_Deallocate(void *Ptr);
+//void *Heap_Allocate(const char *File, int Line, size_t Bytes);
+//void *Heap_AllocateZero(const char *File, int Line, size_t Bytes);
+//void *Heap_Reallocate(const char *File, int Line, void *Ptr, size_t Bytes);
+//void Heap_Deallocate(void *Ptr);
void Heap_Dump(void);
void Heap_Stats(void);
}
// Increas heap end
- gHeapEnd += i << 12;
+ gHeapEnd = (Uint8*)gHeapEnd + (i << 12);
// Create Block
head->Size = (Bytes+0xFFF)&~0xFFF;
* \{
*/
typedef struct sKernelSymbol {
- char *Name;
+ const char *Name;
tVAddr Value;
} tKernelSymbol;
#define EXPORT(_name) tKernelSymbol _kexp_##_name __attribute__((section ("KEXPORT"),unused))={#_name, (tVAddr)_name}
extern int IRQ_AddHandler(int Num, void (*Callback)(int));
// --- Logging ---
-extern void Log_KernelPanic(char *Ident, char *Message, ...);
-extern void Log_Panic(char *Ident, char *Message, ...);
-extern void Log_Error(char *Ident, char *Message, ...);
-extern void Log_Warning(char *Ident, char *Message, ...);
-extern void Log_Notice(char *Ident, char *Message, ...);
-extern void Log_Log(char *Ident, char *Message, ...);
-extern void Log_Debug(char *Ident, char *Message, ...);
+extern void Log_KernelPanic(const char *Ident, const char *Message, ...);
+extern void Log_Panic(const char *Ident, const char *Message, ...);
+extern void Log_Error(const char *Ident, const char *Message, ...);
+extern void Log_Warning(const char *Ident, const char *Message, ...);
+extern void Log_Notice(const char *Ident, const char *Message, ...);
+extern void Log_Log(const char *Ident, const char *Message, ...);
+extern void Log_Debug(const char *Ident, const char *Message, ...);
// --- Debug ---
/**
* \param VAddr Virtual Address to allocate at
* \return Physical address allocated
*/
-extern tPAddr MM_Allocate(tVAddr VAddr);
+extern tPAddr MM_Allocate(tVAddr VAddr) __attribute__ ((warn_unused_result));
/**
* \brief Deallocate a page
* \param VAddr Virtual address to unmap
* \param PAddr Page to dereference
*/
extern void MM_DerefPhys(tPAddr PAddr);
+/**
+ * \brief Get the number of times a page has been referenced
+ * \param PAddr Address to check
+ * \return Reference count for the page
+ */
+extern int MM_GetRefCount(tPAddr PAddr);
/**
* \}
*/
* \name Memory Validation
* \{
*/
-extern int CheckString(char *String);
-extern int CheckMem(void *Mem, int Num);
+extern int CheckString(const char *String);
+extern int CheckMem(const void *Mem, int Num);
/**
* \}
*/
extern int strpos8(const char *str, Uint32 search);
extern void itoa(char *buf, Uint64 num, int base, int minLength, char pad);
extern int atoi(const char *string);
-extern int ReadUTF8(Uint8 *str, Uint32 *Val);
+extern int ReadUTF8(const Uint8 *str, Uint32 *Val);
extern int WriteUTF8(Uint8 *str, Uint32 Val);
-extern int ModUtil_SetIdent(char *Dest, char *Value);
-extern int ModUtil_LookupString(char **Array, char *Needle);
+extern int ModUtil_SetIdent(char *Dest, const char *Value);
+extern int ModUtil_LookupString(const char **Array, const char *Needle);
-extern Uint8 ByteSum(void *Ptr, int Size);
+extern Uint8 ByteSum(const void *Ptr, int Size);
extern int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
/**
* \}
* \name Modules
* \{
*/
-extern int Module_LoadMem(void *Buffer, Uint Length, char *ArgStr);
-extern int Module_LoadFile(char *Path, char *ArgStr);
+extern int Module_LoadMem(void *Buffer, Uint Length, const char *ArgStr);
+extern int Module_LoadFile(const char *Path, const char *ArgStr);
/**
* \}
*/
* \note Used to uniquely identify the loaded binary to reduce in-memory
* duplication.
*/
- char *TruePath;
+ const char *TruePath;
/**
* \brief Interpreter used to load the file
* \note This can be either requested by the individual file, or a per-driver option
*/
- char *Interpreter;
+ const char *Interpreter;
/**
* \brief Entrypoint of the binary (at requested base);
*/
*/
Uint32 Ident;
Uint32 Mask; //!< Mask value for tBinaryType.Ident
- char *Name; //!< Name of this executable type (for debug purpouses)
+ const char *Name; //!< Name of this executable type (for debug purpouses)
/**
* \brief Read a binary from a file
* \param FD VFS File handle to file to load
* tBinaryType.Relocate at this time, so the driver should
* accomodate this.
*/
- int (*GetSymbol)(void *Base, char *Name, Uint *Dest);
+ int (*GetSymbol)(void *Base, const char *Name, Uint *Dest);
} tBinaryType;
/**
#define _BINARY_EXT_H
// === FUNCTIONS ===
-extern void *Binary_LoadFile(char *Path);
-extern void *Binary_LoadKernel(char *Path);
+extern void *Binary_LoadFile(const char *Path);
+extern void *Binary_LoadKernel(const char *Path);
extern Uint Binary_Relocate(void *Mem);
extern void Binary_Unload(void *Base);
-extern int Binary_GetSymbol(char *Name, Uint *Dest);
-extern Uint Binary_FindSymbol(void *Base, char *Name, Uint *Val);
+extern int Binary_GetSymbol(const char *Name, Uint *Dest);
+extern Uint Binary_FindSymbol(void *Base, const char *Name, Uint *Val);
#endif
extern Uint8 PCI_GetIRQ(int id);\r
extern Uint32 PCI_GetBAR0(int id);\r
extern Uint32 PCI_GetBAR1(int id);\r
+extern Uint32 PCI_GetBAR2(int id);\r
extern Uint32 PCI_GetBAR3(int id);\r
extern Uint32 PCI_GetBAR4(int id);\r
extern Uint32 PCI_GetBAR5(int id);\r
typedef struct sDevFS_Driver
{
struct sDevFS_Driver *Next; //!< Set to NULL by drivers (used internally)
- char *Name; //!< Name of the driver file/folder (must be unique)
+ const char *Name; //!< Name of the driver file/folder (must be unique)
tVFS_Node RootNode; //!< Root node of driver
} tDevFS_Driver;
* \note \a Data must be maintained until ::SysFS_UpdateFile is called
* with a different buffer, or ::SysFS_RemoveFile is called.
*/
-extern int SysFS_RegisterFile(char *Path, char *Data, int Length);
+extern int SysFS_RegisterFile(const char *Path, const char *Data, int Length);
/**
* \brief Updates the size/pointer associated with a SysFD file
* \param Length New length of the file
* \return Boolean Success
*/
-extern int SysFS_UpdateFile(int ID, char *Data, int Length);
+extern int SysFS_UpdateFile(int ID, const char *Data, int Length);
/**
* \brief Removes a file from the SysFS tree
* Contains the identifiers of the required modules.
*/
#define MODULE_DEFINE(_flags,_ver,_ident,_entry,_deinit,_deps...) \
- char *EXPAND_CONCAT(_DriverDeps_,_ident)[]={_deps};\
+ const char *EXPAND_CONCAT(_DriverDeps_,_ident)[]={_deps};\
tModule __attribute__ ((section ("KMODULES"),unused))\
EXPAND_CONCAT(_DriverInfo_,_ident)=\
{MODULE_MAGIC,MODULE_ARCH_ID,_flags,_ver,NULL,EXPAND_STR(_ident),\
Uint8 Flags; //!< Module Flags
Uint16 Version; //!< Module Version in Major.Minor 8.8 form
struct sModule *Next; //!< Next module in list (not to be touched by the driver)
- char *Name; //!< Module Name/Identifier
+ const char *Name; //!< Module Name/Identifier
int (*Init)(char **Arguments); //!< Module initialiser / entrypoint
void (*Deinit)(void); //!< Cleanup Function
- char **Dependencies; //!< NULL terminated list of dependencies
+ const char **Dependencies; //!< NULL terminated list of dependencies
} PACKED tModule;
/**
extern int Threads_Wake(tThread *Thread);
extern void Threads_Kill(tThread *Thread, int Status);
extern void Threads_AddActive(tThread *Thread);
+extern tThread *Threads_RemActive(void);
extern tThread *Threads_GetNextToRun(int CPU, tThread *Last);
+extern void Threads_SetFaultHandler(Uint Handler);
+
+extern int Threads_SetUID(Uint *Errno, tUID ID);
+extern int Threads_SetGID(Uint *Errno, tUID ID);
+extern int Threads_WaitTID(int TID, int *Status);
+
extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags);
extern tThread *Threads_CloneThreadZero(void);
+extern int Proc_SendMessage(Uint *Err, Uint Dest, int Length, void *Data);
+extern int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer);
+
#endif
}\
case DRV_IOCTL_VERSION: LEAVE('x', (_version)); return (_version);\
case DRV_IOCTL_LOOKUP:{\
- int tmp = ModUtil_LookupString( (char**)(_ioctls), (char*)Data );\
+ int tmp = ModUtil_LookupString( _ioctls, (const char*)Data );\
LEAVE('i', tmp);\
return tmp;\
}
typedef struct sVFS_Driver
{
//! \brief Unique Identifier for this filesystem type
- char *Name;
+ const char *Name;
//! \brief Flags applying to this driver
Uint Flags;
#define UNIX_TO_2K ((30*365*3600*24) + (7*3600*24)) //Normal years + leap years
// === PROTOTYPES ===
+#if 0
int atoi(const char *string);
void itoa(char *buf, Uint64 num, int base, int minLength, char pad);
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args);
int sprintf(char *__s, const char *__format, ...);
+#endif
int tolower(int c);
+#if 0
int strucmp(const char *Str1, const char *Str2);
char *strchr(const char *__s, int __c);
int strpos(const char *Str, char Ch);
int strpos8(const char *str, Uint32 Search);
int ReadUTF8(Uint8 *str, Uint32 *Val);
int WriteUTF8(Uint8 *str, Uint32 Val);
-
int DivUp(int num, int dem);
Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year);
int rand(void);
int ModUtil_SetIdent(char *Dest, char *Value);
int UnHex(Uint8 *Dest, size_t DestSize, const char *SourceString);
+#endif
// === EXPORTS ===
EXPORT(atoi);
char c, pad = ' ';
int minSize = 0, len;
char tmpBuf[34]; // For Integers
- char *p = NULL;
+ const char *p = NULL;
int isLongLong = 0;
Uint64 val;
size_t pos = 0;
if(c == 'p') {
Uint ptr = va_arg(args, Uint);
PUTCH('*'); PUTCH('0'); PUTCH('x');
+ itoa(tmpBuf, ptr, 16, BITS/4, '0');
p = tmpBuf;
- itoa(p, ptr, 16, BITS/4, '0');
goto printString;
}
PUTCH('-');
val = -(Sint32)val;
}
- itoa(p, val, 10, minSize, pad);
+ itoa(tmpBuf, val, 10, minSize, pad);
goto printString;
case 'u':
GETVAL();
- itoa(p, val, 10, minSize, pad);
+ itoa(tmpBuf, val, 10, minSize, pad);
goto printString;
case 'X':
if(BITS == 64)
isLongLong = 1; // TODO: Handle non-x86 64-bit archs
GETVAL();
- itoa(p, val, 16, minSize, pad);
+ itoa(tmpBuf, val, 16, minSize, pad);
goto printString;
case 'x':
GETVAL();
- itoa(p, val, 16, minSize, pad);
+ itoa(tmpBuf, val, 16, minSize, pad);
goto printString;
case 'o':
GETVAL();
- itoa(p, val, 8, minSize, pad);
+ itoa(tmpBuf, val, 8, minSize, pad);
goto printString;
case 'b':
GETVAL();
- itoa(p, val, 2, minSize, pad);
+ itoa(tmpBuf, val, 2, minSize, pad);
goto printString;
case 'B': //Boolean
* \fn Uint8 ByteSum(void *Ptr, int Size)
* \brief Adds the bytes in a memory region and returns the sum
*/
-Uint8 ByteSum(void *Ptr, int Size)
+Uint8 ByteSum(const void *Ptr, int Size)
{
Uint8 sum = 0;
- while(Size--) sum += *(Uint8*)Ptr++;
+ const Uint8 *data = Ptr;
+ while(Size--) sum += *(data++);
return sum;
}
* \fn int ReadUTF8(Uint8 *str, Uint32 *Val)
* \brief Read a UTF-8 character from a string
*/
-int ReadUTF8(Uint8 *str, Uint32 *Val)
+int ReadUTF8(const Uint8 *str, Uint32 *Val)
{
*Val = 0xFFFD; // Assume invalid character
/**
* \brief Checks if a string resides fully in valid memory
*/
-int CheckString(char *String)
+int CheckString(const char *String)
{
if( !MM_GetPhysAddr( (tVAddr)String ) )
return 0;
/**
* \brief Check if a sized memory region is valid memory
*/
-int CheckMem(void *Mem, int NumBytes)
+int CheckMem(const void *Mem, int NumBytes)
{
tVAddr addr = (tVAddr)Mem;
* \brief Search a string array for \a Needle
* \note Helper function for eTplDrv_IOCtl::DRV_IOCTL_LOOKUP
*/
-int ModUtil_LookupString(char **Array, char *Needle)
+int ModUtil_LookupString(const char **Array, const char *Needle)
{
int i;
if( !CheckString(Needle) ) return -1;
return -1;
}
-int ModUtil_SetIdent(char *Dest, char *Value)
+int ModUtil_SetIdent(char *Dest, const char *Value)
{
if( !CheckMem(Dest, 32) ) return -1;
strncpy(Dest, Value, 32);
} tLogList;
// === PROTOTYPES ===
-void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args);
+void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args);
static void Log_Int_PrintMessage(tLogEntry *Entry);
-void Log_KernelPanic(char *Ident, char *Message, ...);
-void Log_Panic(char *Ident, char *Message, ...);
-void Log_Error(char *Ident, char *Message, ...);
-void Log_Warning(char *Ident, char *Message, ...);
-void Log_Notice(char *Ident, char *Message, ...);
-void Log_Log(char *Ident, char *Message, ...);
-void Log_Debug(char *Ident, char *Message, ...);
+//void Log_KernelPanic(const char *Ident, const char *Message, ...);
+//void Log_Panic(const char *Ident, const char *Message, ...);
+//void Log_Error(const char *Ident, const char *Message, ...);
+//void Log_Warning(const char *Ident, const char *Message, ...);
+//void Log_Notice(const char *Ident, const char *Message, ...);
+//void Log_Log(const char *Ident, const char *Message, ...);
+//void Log_Debug(const char *Ident, const char *Message, ...);
// === EXPORTS ===
EXPORT(Log_Panic);
/**
* \brief Adds an event to the log
*/
-void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args)
+void Log_AddEvent(const char *Ident, int Level, const char *Format, va_list Args)
{
int len;
tLogEntry *ent;
/**
* \brief KERNEL PANIC!!!!
*/
-void Log_KernelPanic(char *Ident, char *Message, ...)
+void Log_KernelPanic(const char *Ident, const char *Message, ...)
{
va_list args;
va_start(args, Message);
/**
* \brief Panic Message - Driver Unrecoverable error
*/
-void Log_Panic(char *Ident, char *Message, ...)
+void Log_Panic(const char *Ident, const char *Message, ...)
{
va_list args;
va_start(args, Message);
/**
* \brief Error Message - Recoverable Error
*/
-void Log_Error(char *Ident, char *Message, ...)
+void Log_Error(const char *Ident, const char *Message, ...)
{
va_list args;
va_start(args, Message);
/**
* \brief Warning Message - Something the user should know
*/
-void Log_Warning(char *Ident, char *Message, ...)
+void Log_Warning(const char *Ident, const char *Message, ...)
{
va_list args;
/**
* \brief Notice Message - Something the user might like to know
*/
-void Log_Notice(char *Ident, char *Message, ...)
+void Log_Notice(const char *Ident, const char *Message, ...)
{
va_list args;
va_start(args, Message);
/**
* \brief Log Message - Possibly useful information
*/
-void Log_Log(char *Ident, char *Message, ...)
+void Log_Log(const char *Ident, const char *Message, ...)
{
va_list args;
va_start(args, Message);
/**
* \brief Debug Message - Only a developer would want this info
*/
-void Log_Debug(char *Ident, char *Message, ...)
+void Log_Debug(const char *Ident, const char *Message, ...)
{
va_list args;
va_start(args, Message);
#define USE_UDI 0
// === PROTOTYPES ===
- int Module_int_Initialise(tModule *Module, char *ArgString);
+ int Module_int_Initialise(tModule *Module, const char *ArgString);
+void Modules_int_GetBuiltinArray(void);
void Modules_LoadBuiltins(void);
void Modules_SetBuiltinParams(char *Name, char *ArgString);
- int Module_RegisterLoader(tModuleLoader *Loader);
- int Module_LoadMem(void *Buffer, Uint Length, char *ArgString);
- int Module_LoadFile(char *Path, char *ArgString);
+// int Module_RegisterLoader(tModuleLoader *Loader);
+// int Module_LoadMem(void *Buffer, Uint Length, char *ArgString);
+// int Module_LoadFile(char *Path, char *ArgString);
int Module_int_ResolveDeps(tModule *Info);
int Module_IsLoaded(const char *Name);
#if USE_UDI
extern int UDI_LoadDriver(void *Base);
#endif
-extern void StartupPrint(char *Str);
+extern void StartupPrint(const char *Str);
extern void gKernelModules;
extern void gKernelModulesEnd;
* \retval 0 Returned on success
* \retval >0 Error code form the module's initialisation function
*/
-int Module_int_Initialise(tModule *Module, char *ArgString)
+int Module_int_Initialise(tModule *Module, const char *ArgString)
{
int i, j;
int ret;
- char **deps;
+ const char **deps;
char **args;
tModule *mod;
* \fn int Module_LoadMem(void *Buffer, Uint Length, char *ArgString)
* \brief Load a module from a memory location
*/
-int Module_LoadMem(void *Buffer, Uint Length, char *ArgString)
+int Module_LoadMem(void *Buffer, Uint Length, const char *ArgString)
{
char path[VFS_MEMPATH_SIZE];
}
/**
- * \fn int Module_LoadFile(char *Path, char *ArgString)
+ * \fn int Module_LoadFile(const char *Path, const char *ArgString)
* \brief Load a module from a file
*/
-int Module_LoadFile(char *Path, char *ArgString)
+int Module_LoadFile(const char *Path, const char *ArgString)
{
void *base;
tModule *info;
*/
int Module_int_ResolveDeps(tModule *Info)
{
- char **names = Info->Dependencies;
+ const char **names = Info->Dependencies;
// Walk dependencies array
for( ; *names; names++ )
if(!(v)||!Syscall_ValidString((Uint)(v))){ret=-1;err=-EINVAL;break;}
// === IMPORTS ===
-extern int Proc_Clone(Uint *Err, Uint Flags);
-extern int Threads_WaitTID(int TID, int *status);
-extern Uint Proc_SendMessage(Uint *Err, Uint Dest, Uint Length, void *Data);
-extern int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer);
extern int Proc_Execve(char *File, char **ArgV, char **EnvP);
extern Uint Binary_Load(char *file, Uint *entryPoint);
-extern int Threads_SetUID(Uint *errno, tUID ID);
-extern int Threads_SetGID(Uint *errno, tGID ID);
-extern int Threads_SetFaultHandler(Uint Handler);
// === PROTOTYPES ===
+void SyscallHandler(tSyscallRegs *Regs);
int Syscall_ValidString(Uint Addr);
int Syscall_Valid(int Size, Uint Addr);
} tConfigFile;
typedef struct
{
- char *Name; // Name
+ const char *Name; // Name
int MinArgs; // Minimum number of arguments
int MaxArgs; // Maximum number of arguments
Uint IntArgs; // Bitmap of arguments that should be treated as integers
extern void Arch_LoadBootModules(void);
extern int Modules_LoadBuiltins(void);
extern void Modules_SetBuiltinParams(char *Name, char *ArgString);
-extern void Debug_SetKTerminal(char *File);
+extern void Debug_SetKTerminal(const char *File);
// === PROTOTYPES ===
void System_Init(char *Commandline);
#define NUM_CONFIG_COMMANDS (sizeof(caConfigCommands)/sizeof(caConfigCommands[0]))
// === GLOBALS ===
-char *gsConfigScript = "/Acess/Conf/BootConf.cfg";
+const char *gsConfigScript = "/Acess/Conf/BootConf.cfg";
char *argv[32];
int argc;
// === IMPORTS ===
extern void ArchThreads_Init(void);
-extern void Proc_Start(void);
-extern tThread *Proc_GetCurThread(void);
-extern int Proc_Clone(Uint *Err, Uint Flags);
extern void Proc_CallFaultHandler(tThread *Thread);
extern int GetCPUNum(void);
// === PROTOTYPES ===
void Threads_Init(void);
+#if 0
int Threads_SetName(const char *NewName);
+#endif
char *Threads_GetName(int ID);
+#if 0
void Threads_SetPriority(tThread *Thread, int Pri);
tThread *Threads_CloneTCB(Uint *Err, Uint Flags);
int Threads_WaitTID(int TID, int *status);
tThread *Threads_GetThread(Uint TID);
+#endif
void Threads_AddToDelete(tThread *Thread);
tThread *Threads_int_DelFromQueue(tThread **List, tThread *Thread);
+#if 0
void Threads_Exit(int TID, int Status);
void Threads_Kill(tThread *Thread, int Status);
void Threads_Yield(void);
int Threads_Wake(tThread *Thread);
void Threads_AddActive(tThread *Thread);
tThread *Threads_RemActive(void);
+#endif
+void Threads_Fault(int Num);
+void Threads_SegFault(tVAddr Addr);
+#if 0
int Threads_GetPID(void);
int Threads_GetTID(void);
tUID Threads_GetUID(void);
- int Threads_SetUID(Uint *Errno, tUID ID);
tGID Threads_GetGID(void);
+ int Threads_SetUID(Uint *Errno, tUID ID);
int Threads_SetGID(Uint *Errno, tUID ID);
+#endif
void Threads_Dump(void);
void Threads_DumpActive(void);
+#if 0
int Mutex_Acquire(tMutex *Mutex);
void Mutex_Release(tMutex *Mutex);
int Mutex_IsLocked(tMutex *Mutex);
+#endif
// === GLOBALS ===
// -- Core Thread --
// Only used for the core kernel
tThread gThreadZero = {
Status: THREAD_STAT_ACTIVE, // Status
- ThreadName: "ThreadZero", // Name
+ ThreadName: (char*)"ThreadZero", // Name
Quantum: DEFAULT_QUANTUM, // Default Quantum
Remaining: DEFAULT_QUANTUM, // Current Quantum
Priority: DEFAULT_PRIORITY // Number of tickets
Proc_CallFaultHandler(thread);
}
+/**
+ * \fn void Threads_SegFault(tVAddr Addr)
+ * \brief Called when a Segment Fault occurs
+ */
+void Threads_SegFault(tVAddr Addr)
+{
+ Warning("Thread #%i committed a segfault at address %p", Proc_GetCurThread()->TID, Addr);
+ Threads_Fault( 1 );
+ //Threads_Exit( 0, -1 );
+}
+
// --- Process Structure Access Functions ---
tPID Threads_GetPID(void)
{
return thread;
}
-/**
- * \fn void Threads_SegFault(tVAddr Addr)
- * \brief Called when a Segment Fault occurs
- */
-void Threads_SegFault(tVAddr Addr)
-{
- Warning("Thread #%i committed a segfault at address %p", Proc_GetCurThread()->TID, Addr);
- Threads_Fault( 1 );
- //Threads_Exit( 0, -1 );
-}
-
/**
* \brief Acquire a heavy mutex
* \param Mutex Mutex to acquire
} tTimer;
// === PROTOTYPES ===
-Sint64 now(void);
void Timer_CallTimers(void);
// === GLOBALS ===
extern tVFS_Mount *gRootMount;
// === PROTOTYPES ===
+#if 0
int VFS_MkDir(const char *Path);
+#endif
int VFS_MkNod(const char *Path, Uint Flags);
// === CODE ===
#include <fs_devfs.h>
// === PROTOTYPES ===
+#if 0
int DevFS_AddDevice(tDevFS_Driver *Device);
void DevFS_DelDevice(tDevFS_Driver *Device);
+#endif
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);
#define MAX_KERNEL_FILES 128
// === PROTOTYPES ===
+#if 0
tVFS_Handle *VFS_GetHandle(int FD);
+#endif
int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
// === GLOBALS ===
extern tVFS_Driver gDevFS_Info;
// === PROTOTYPES ===
+#if 0
int VFS_Init(void);
char *VFS_GetTruePath(const char *Path);
void VFS_GetMemPath(char *Dest, void *Base, Uint Length);
tVFS_Driver *VFS_GetFSByName(const char *Name);
int VFS_AddDriver(tVFS_Driver *Info);
+#endif
void VFS_UpdateDriverFile(void);
// === EXPORTS ===
Length = Node->Size - Offset;
// Copy Data
- memcpy(Buffer, Node->ImplPtr+Offset, Length);
+ memcpy(Buffer, (Uint8*)Node->ImplPtr + Offset, Length);
return Length;
}
Length = Node->Size - Offset;
// Copy Data
- memcpy(Node->ImplPtr+Offset, Buffer, Length);
+ memcpy((Uint8*)Node->ImplPtr + Offset, Buffer, Length);
return Length;
}
extern char *gsVFS_MountFile;
// === PROTOTYPES ===
+#if 0
int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options);
+#endif
void VFS_UpdateMountFile(void);
// === GLOBALS ===
// === IMPORTS ===
extern tVFS_Node gVFS_MemRoot;
extern tVFS_Mount *gVFS_RootMount;
-
-extern tVFS_Handle *VFS_GetHandle(int FD);
extern int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode);
// === CODE ===
char *tmpStr;
int iPos = 0;
int iPos2 = 0;
- char *chroot = CFGPTR(CFG_VFS_CHROOT);
+ const char *chroot = CFGPTR(CFG_VFS_CHROOT);
int chrootLen;
- char *cwd = CFGPTR(CFG_VFS_CWD);
+ const char *cwd = CFGPTR(CFG_VFS_CWD);
int cwdLen;
ENTER("sPath", Path);
switch(ID)
{
// --- Standard IOCtls (0-3) ---
- case DRV_IOCTL_TYPE:
- LEAVE('i', DRV_TYPE_MISC);
- return DRV_TYPE_MISC;
-
- case DRV_IOCTL_IDENT:
- tmp = ModUtil_SetIdent(Data, "IPStack");
- LEAVE('i', 1);
- return 1;
-
- case DRV_IOCTL_VERSION:
- LEAVE('x', VERSION);
- return VERSION;
-
- case DRV_IOCTL_LOOKUP:
- tmp = ModUtil_LookupString( (char**)casIOCtls_Root, (char*)Data );
- LEAVE('i', tmp);
- return tmp;
+ BASE_IOCTLS(DRV_TYPE_MISC, "IPStack", VERSION, casIOCtls_Root)
- /*
- * add_interface
- * - Adds a new IP interface and binds it to a device
- */
+ /*
+ * add_interface
+ * - Adds a new IP interface and binds it to a device
+ */
case 4:
if( Threads_GetUID() != 0 ) LEAVE_RET('i', -1);
if( !CheckString( Data ) ) LEAVE_RET('i', -1);
switch(ID)
{
// --- Standard IOCtls (0-3) ---
- case DRV_IOCTL_TYPE:
- LEAVE('i', DRV_TYPE_MISC);
- return DRV_TYPE_MISC;
-
- case DRV_IOCTL_IDENT:
- tmp = ModUtil_SetIdent(Data, STR(IDENT));
- LEAVE('i', 1);
- return 1;
-
- case DRV_IOCTL_VERSION:
- LEAVE('x', VERSION);
- return VERSION;
-
- case DRV_IOCTL_LOOKUP:
- tmp = ModUtil_LookupString( (char**)casIOCtls_Iface, (char*)Data );
- LEAVE('i', tmp);
- return tmp;
+ BASE_IOCTLS(DRV_TYPE_MISC, "IPStack", VERSION, casIOCtls_Iface)
/*
* getset_type
switch(ID)
{
// --- Standard IOCtls (0-3) ---
- case DRV_IOCTL_TYPE:
- LEAVE('i', DRV_TYPE_MISC);
- return DRV_TYPE_MISC;
-
- case DRV_IOCTL_IDENT:
- tmp = ModUtil_SetIdent(Data, STR(IDENT));
- LEAVE('i', 1);
- return 1;
-
- case DRV_IOCTL_VERSION:
- LEAVE('x', VERSION);
- return VERSION;
-
- case DRV_IOCTL_LOOKUP:
- tmp = ModUtil_LookupString( (char**)casIOCtls_RouteDir, (char*)Data );
- LEAVE('i', tmp);
- return tmp;
+ BASE_IOCTLS(DRV_TYPE_MISC, STR(IDENT), VERSION, casIOCtls_RouteDir)
case 4: // Add Route
if( !CheckString(Data) ) LEAVE_RET('i', -1);
*/
int IPStack_Route_IOCtl(tVFS_Node *Node, int ID, void *Data)
{
- int tmp;
int *iData = Data;
tRoute *rt = Node->ImplPtr;
int addrSize = IPStack_GetAddressSize(rt->AddressType);
switch(ID)
{
// --- Standard IOCtls (0-3) ---
- case DRV_IOCTL_TYPE:
- LEAVE('i', DRV_TYPE_MISC);
- return DRV_TYPE_MISC;
-
- case DRV_IOCTL_IDENT:
- tmp = ModUtil_SetIdent(Data, STR(IDENT));
- LEAVE('i', 1);
- return 1;
-
- case DRV_IOCTL_VERSION:
- LEAVE('x', VERSION);
- return VERSION;
-
- case DRV_IOCTL_LOOKUP:
- tmp = ModUtil_LookupString( (char**)casIOCtls_Route, (char*)Data );
- LEAVE('i', tmp);
- return tmp;
+ BASE_IOCTLS(DRV_TYPE_MISC, STR(IDENT), VERSION, casIOCtls_Route)
// Get address type
case 4:
// Wait for transfer to complete
timeoutTime = now() + ATA_TIMEOUT;
while( gaATA_IRQs[cont] == 0 && now() < timeoutTime)
- Threads_Yield();
+ {
+ HALT();
+// Threads_Yield();
+ }
// Complete Transfer
ATA_int_BusMasterWriteByte( cont << 3, 8 ); // Read and stop
// Wait for transfer to complete
timeoutTime = now() + ATA_TIMEOUT;
while( gaATA_IRQs[cont] == 0 && now() < timeoutTime)
- Threads_Yield();
+ {
+// Threads_Yield();
+ HALT();
+ }
// Complete Transfer
ATA_int_BusMasterWriteByte( cont << 3, 0 ); // Write and stop
*/
void FDD_int_SendByte(int base, char byte)
{
- volatile int state;
- int timeout = 128;
- for( ; timeout--; )
+ int timeout = 128;
+
+ while( (inb(base + PORT_MAINSTATUS) & 0xC0) != 0x80 && timeout-- )
+ inb(0x80); //Delay
+
+ if( timeout >= 0 )
{
- state = inb(base + PORT_MAINSTATUS);
- if ((state & 0xC0) == 0x80)
- {
- outb(base + PORT_DATA, byte);
- return;
- }
- inb(0x80); //Delay
+ outb(base + PORT_DATA, byte);
+ }
+ else
+ {
+ Log_Warning("FDD", "FDD_int_SendByte: Timeout sending byte 0x%x to base 0x%x\n", byte, base);
}
-
- #if WARN
- Warning("FDD_int_SendByte - Timeout sending byte 0x%x to base 0x%x\n", byte, base);
- #endif
}
/**
*/
int FDD_int_GetByte(int base)
{
- volatile int state;
- int timeout;
- for( timeout = 128; timeout--; )
+ int timeout = 128;
+
+ while( (inb(base + PORT_MAINSTATUS) & 0xd0) != 0xd0 && timeout-- )
+ inb(0x80); //Delay
+
+ if( timeout >= 0 )
{
- state = inb((base + PORT_MAINSTATUS));
- if ((state & 0xd0) == 0xd0)
- return inb(base + PORT_DATA);
- inb(0x80);
+ return inb(base + PORT_DATA);
+ }
+ else
+ {
+ Log_Warning("FDD", "FDD_int_GetByte: Timeout reading byte from base 0x%x\n", base);
+ return -1;
}
- return -1;
}
/**