typedef unsigned long long int Uint64;
#endif
+typedef Sint64 Sint;
typedef Uint64 Uint;
typedef Uint64 tPAddr;
typedef Uint64 tVAddr;
*(.initpd)
*(.rodata)
*(.rdata)
+
+ . = ALIGN(0x10);
gKernelModules = .;
*(KMODULES)
gKernelModulesEnd = .;
- . = ALIGN(4);
+ . = ALIGN(0x10);
gKernelSymbols = .;
*(KEXPORT)
gKernelSymbolsEnd = .;
}
- /*
- .debug_abbrev : { *(.debug_abbrev) }
- .debug_info : { *(.debug_info) }
- .debug_line : { *(.debug_line) }
- .debug_loc : { *(.debug_loc) }
- .debug_pubnames : { *(.debug_pubnames) }
- .debug_aranges : { *(.debug_aranges) }
- .debug_ranges : { *(.debug_ranges) }
- .debug_str : { *(.debug_str) }
- .debug_frame : { *(.debug_frame) }
- */
.padata ALIGN (0x1000) : AT(ADDR(.padata) - _kernel_base) {
*(.padata)
*
* Physical Memory Manager
*/
-#define DEBUG 1
+#define DEBUG 0
#include <acess.h>
#include <mboot.h>
#include <mm_virt.h>
*/
tPAddr MM_GetPhysAddr(tVAddr Addr)
{
- Log("MM_GetPhysAddr: (Addr=0x%x)", Addr);
if( !(PAGEMAPLVL4(Addr >> 39) & 1) )
return 0;
- Log(" MM_GetPhysAddr: PDP Valid");
if( !(PAGEDIRPTR(Addr >> 30) & 1) )
return 0;
- Log(" MM_GetPhysAddr: PD Valid");
if( !(PAGEDIR(Addr >> 21) & 1) )
return 0;
- Log(" MM_GetPhysAddr: PT Valid");
if( !(PAGETABLE(Addr >> PTAB_SHIFT) & 1) )
return 0;
- Log(" MM_GetPhysAddr: Page Valid");
return (PAGETABLE(Addr >> PTAB_SHIFT) & ~0xFFF) | (Addr & 0xFFF);
}
#define DEBUG_TO_SERIAL 1
#define SERIAL_PORT 0x3F8
#define GDB_SERIAL_PORT 0x2F8
-#define DEBUG_USE_VSNPRINTF 1
+#define DEBUG_USE_VSNPRINTF 0
#define DEBUG_MAX_LINE_LEN 256
// === IMPORTS ===
#if DEBUG_USE_VSNPRINTF
char buf[DEBUG_MAX_LINE_LEN];
int len;
+ buf[DEBUG_MAX_LINE_LEN-1] = 0;
len = vsnprintf(buf, DEBUG_MAX_LINE_LEN-1, format, args);
//if( len < DEBUG_MAX_LINE )
// do something
// Pointer
if(c == 'p') {
- Uint ptr = va_arg(*args, Uint);
+ Uint ptr = va_arg(args, Uint);
Debug_Putchar('*'); Debug_Putchar('0'); Debug_Putchar('x');
p = tmpBuf;
itoa(p, ptr, 16, BITS/4, '0');
}
// Get Argument
- arg = va_arg(*args, Uint);
+ arg = va_arg(args, Uint);
// - Padding Side Flag
if(c == '+') {
c = *format++;
if(c == 'l') {
#if BITS == 32
- arg |= va_arg(*args, Uint);
+ arg |= va_arg(args, Uint);
#endif
c = *format++;
isLongLong = 1;
case 'u': Debug_Fmt("%u", args); break;
case 'x': Debug_Fmt("0x%x", args); break;
case 'b': Debug_Fmt("0b%b", args); break;
- // Extended (64-Bit)
- case 'X': Debug_Fmt("0x%llx", args); break;
- case 'B': Debug_Fmt("0b%llb", args); break;
+ case 'X': Debug_Fmt("0x%llx", args); break; // Extended (64-Bit)
+ case 'B': Debug_Fmt("0b%llb", args); break; // Extended (64-Bit)
}
if(pos != -1) {
Debug_Putchar(','); Debug_Putchar(' ');
struct sSysFS_Ent *Next;
struct sSysFS_Ent *ListNext;
struct sSysFS_Ent *Parent;
- char *Name;
tVFS_Node Node;
+ char Name[];
} tSysFS_Ent;
// === PROTOTYPES ===
tSysFS_Ent gSysFS_Version_Kernel = {
NULL, NULL, // Nexts
&gSysFS_Version, // Parent
- "Kernel",
{
.Inode = 1, // File #1
.ImplPtr = KERNEL_VERSION_STRING,
.NumACLs = 1,
.ACLs = &gVFS_ACL_EveryoneRO,
.Read = SysFS_Comm_ReadFile
- }
+ },
+ "Kernel"
};
tSysFS_Ent gSysFS_Version = {
NULL, NULL,
&gSysFS_Root,
- "Version",
{
.Size = 1,
.ImplPtr = &gSysFS_Version_Kernel,
.Flags = VFS_FFLAG_DIRECTORY,
.ReadDir = SysFS_Comm_ReadDir,
.FindDir = SysFS_Comm_FindDir
- }
+ },
+ "Version"
};
// Root of the SysFS tree (just used to keep the code clean)
tSysFS_Ent gSysFS_Root = {
NULL, NULL,
NULL,
- "/",
{
.Size = 1,
.ImplPtr = &gSysFS_Version,
.ImplInt = (Uint)&gSysFS_Root // Self-Link
- }
+ },
+ "/"
};
tDevFS_Driver gSysFS_DriverInfo = {
NULL, "system",
// Need a new directory?
if( !child )
{
- child = calloc( 1, sizeof(tSysFS_Ent) );
+ child = calloc( 1, sizeof(tSysFS_Ent)+tmp+1 );
child->Next = NULL;
- child->Name = malloc(tmp+1);
memcpy(child->Name, &Path[start], tmp);
child->Name[tmp] = '\0';
child->Parent = ent;
}
// Create new node
- child = calloc( 1, sizeof(tSysFS_Ent) );
+ child = calloc( 1, sizeof(tSysFS_Ent)+strlen(&Path[start])+1 );
child->Next = NULL;
- child->Name = strdup(&Path[start]);
+ strcpy(child->Name, &Path[start]);
child->Parent = ent;
child->Node.Inode = giSysFS_NextFileID++;
// === CONSTANTS ===
#define HEAP_INIT_SIZE 0x8000 // 32 KiB
-#define BLOCK_SIZE (sizeof(void*)) // 8 Machine Words
+#define BLOCK_SIZE (sizeof(void*))*8 // 8 Machine Words
#define COMPACT_HEAP 0 // Use 4 byte header?
#define FIRST_FIT 0
if(nextHead->Magic == MAGIC_FREE && nextHead->Size+head->Size >= newSize)
{
Uint size = nextHead->Size + head->Size;
+ // Inexact fit, split things up
+ if(size > newSize)
+ {
+ // TODO
+ Warning("[Heap ] TODO: Space efficient realloc when new size is smaller");
+ }
+
// Exact fit
- if(size == newSize)
+ if(size >= newSize)
{
Uint oldDataSize;
// Set 1st (new/lower) header
// Clear old header
head->Size = 0;
head->Magic = 0;
+ // Copy data
memcpy(nextHead->Data, __ptr, oldDataSize);
+ // Return
+ return nextHead->Data;
}
+ // On to the expensive then
}
- return NULL;
+ // Well, darn
+ nextHead = malloc( __size );
+ nextHead -= 1;
+
+ memcpy(
+ nextHead->Data,
+ __ptr,
+ head->Size - sizeof(tHeapFoot) - sizeof(tHeapHead)
+ );
+
+ free(__ptr);
+
+ return nextHead->Data;
}
/**
while( (Uint)head < (Uint)gHeapEnd )
{
foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) );
- Log_Log("Heap", "%p (0x%x): 0x%08lx 0x%lx", head, MM_GetPhysAddr((Uint)head), head->Size, head->Magic);
+ Log_Log("Heap", "%p (0x%x): 0x%08lx 0x%lx",
+ head, MM_GetPhysAddr((Uint)head), head->Size, head->Magic);
Log_Log("Heap", "%p 0x%lx", foot->Head, foot->Magic);
Log_Log("Heap", "");
typedef struct {
Uint Magic;
tHeapHead *Head;
- tHeapHead NextHead[]; // Array to make it act like a pointer, but have no size
+ tHeapHead NextHead[]; // Array to make it act like a pointer, but have no size and refer to the next block
} tHeapFoot;
#endif
#if ARCHDIR == x86
# define MODULE_ARCH_ID 1
// IA64 - Architecture 2
-#elif ARCHDIR == x64
+#elif ARCHDIR == x86_64
# define MODULE_ARCH_ID 2
#else
# error "Unknown architecture when determining MODULE_ARCH_ID ('" #ARCHDIR "')"
MODULE_ERR_NOTNEEDED, //!< Module not needed
MODULE_ERR_MALLOC, //!< Error with malloc/realloc/calloc
+ MODULE_ERR_BADMODULE, //!< Bad module (only used by loader)
MODULE_ERR_MAX //!< Maximum defined error code
};
{
case 'd':
case 'i':
+ #if BITS == 32
if( (isLongLong && val >> 63) || (!isLongLong && val >> 31) ) {
+ #else
+ if( (Sint)val < 0 ) {
+ #endif
PUTCH('-');
val = -val;
}
case 'C': // Non-Null Terminated Character Array
p = (char*)(Uint)val;
if(!p) goto printString;
- //while(minSize--) PUTCH(*p++);
while(minSize--) PUTCH(*p++);
break;
{
int len;
tLogEntry *ent;
+ va_list args_tmp;
if( Level >= NUM_LOG_LEVELS ) return;
- len = vsnprintf(NULL, 256, Format, Args);
+ va_copy(args_tmp, Args);
+ len = vsnprintf(NULL, 256, Format, args_tmp);
//Log("len = %i", len);
* Acess2
* - Module Loader
*/
-#define DEBUG 0
+#define DEBUG 1
#include <acess.h>
#include <modules.h>
extern int UDI_LoadDriver(void *Base);
#endif
extern void StartupPrint(char *Str);
-extern tModule gKernelModules[];
+extern void gKernelModules;
extern void gKernelModulesEnd;
// === GLOBALS ===
tModule *gLoadedModules = NULL;
tModuleLoader *gModule_Loaders = NULL;
tModule *gLoadingModules = NULL;
+tModule **gapBuiltinModules = NULL;
char **gasBuiltinModuleArgs;
// === CODE ===
tModule *mod;
ENTER("pModule", Module);
+ LOG("Module->Magic = 0x%x", Module->Magic);
+ if(Module->Magic != MODULE_MAGIC) {
+ Log_Warning(
+ "Module",
+ "Module %p is no a valid Acess2 module (0x%08x != 0x%08x)",
+ Module, Module->Magic, MODULE_MAGIC
+ );
+ LEAVE('i', MODULE_ERR_BADMODULE);
+ return MODULE_ERR_BADMODULE;
+ }
+ LOG("Module->Name = %p \"%s\"", Module->Name, Module->Name);
+
+ if(Module->Arch != MODULE_ARCH_ID) {
+ Log_Warning(
+ "Module",
+ "Module %p (%s) is for another architecture (%i)",
+ Module, Module->Name, Module->Arch
+ );
+ }
deps = Module->Dependencies;
// So, if it's not loaded, we better load it then
for( i = 0; i < giNumBuiltinModules; i ++ )
{
- if( strcmp(deps[j], gKernelModules[i].Name) == 0 )
+ if( strcmp(deps[j], gapBuiltinModules[i]->Name) == 0 )
break;
}
if( i == giNumBuiltinModules ) {
// Dependency is not loaded, so load it
ret = Module_int_Initialise(
- &gKernelModules[i],
+ gapBuiltinModules[i],
gasBuiltinModuleArgs ? gasBuiltinModuleArgs[i] : NULL
);
if( ret )
LEAVE_RET('i', 0);
}
+/**
+ * \brief Scans the builtin modules and creates an array of them
+ */
+void Modules_int_GetBuiltinArray(void)
+{
+ int i;
+ tModule *module;
+
+ // Count
+ module = &gKernelModules;
+ i = 0;
+ while( (tVAddr)module < (tVAddr)&gKernelModulesEnd )
+ {
+ if(module->Magic == MODULE_MAGIC) {
+ i ++;
+ module ++;
+ }
+ else
+ module = (void*)( (tVAddr)module + 4 );
+ }
+
+ // Create
+ giNumBuiltinModules = i;
+ gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) );
+ gapBuiltinModules = malloc( giNumBuiltinModules * sizeof(tModule*) );
+
+
+ // Fill
+ module = &gKernelModules;
+ i = 0;
+ while( (tVAddr)module < (tVAddr)&gKernelModulesEnd )
+ {
+ if(module->Magic == MODULE_MAGIC) {
+ gapBuiltinModules[i] = module;
+ i ++;
+ module ++;
+ }
+ else
+ module = (void*)( (tVAddr)module + 4 );
+ }
+}
+
/**
* \brief Initialises builtin modules
*/
{
int i;
- // Count modules
- giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules;
- giNumBuiltinModules /= sizeof(tModule);
+ if( !gapBuiltinModules )
+ Modules_int_GetBuiltinArray();
for( i = 0; i < giNumBuiltinModules; i++ )
{
Module_int_Initialise(
- &gKernelModules[i],
+ gapBuiltinModules[i],
(gasBuiltinModuleArgs ? gasBuiltinModuleArgs[i] : NULL)
);
}
void Modules_SetBuiltinParams(char *Name, char *ArgString)
{
int i;
- if( gasBuiltinModuleArgs == NULL ) {
- giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules;
- giNumBuiltinModules /= sizeof(tModule);
- gasBuiltinModuleArgs = calloc( giNumBuiltinModules, sizeof(char*) );
+
+ if( gasBuiltinModuleArgs == NULL )
+ {
+ Modules_int_GetBuiltinArray();
}
- for( i = 0; i < giNumBuiltinModules; i ++ )
+ // I hate expensive scans
+ for( i = 0; i < giNumBuiltinModules; i++ )
{
- if(strcmp( gKernelModules[i].Name, Name ) == 0) {
+ if(strcmp( gapBuiltinModules[i]->Name, Name ) == 0) {
gasBuiltinModuleArgs[i] = ArgString;
return ;
}
} __attribute__((packed));
Uint8 FragOffHi; // Number of 8-byte blocks from the original start
- Uint8 TTL; // Max number of hops effectively
+ Uint8 TTL; // Max number of hops, effectively
Uint8 Protocol;
Uint16 HeaderChecksum; // One's Complement Sum of the entire header must equal zero
unsigned Version: 4;
unsigned TrafficClass: 8;
unsigned FlowLabel: 20;
- };
+ } __attribute__((packed));
#endif
Uint16 PayloadLength;
Uint8 NextHeader; // Type of payload data
{
tmp = realloc(gaRegisteredTypes, (giRegisteredTypes+1)*sizeof(*gaRegisteredTypes));
if(!tmp) {
- Log_Warning("NET", "Out of heap space!");
+ Log_Warning("NET",
+ "Out of heap space! (Attempted to allocate %i)",
+ (giRegisteredTypes+1)*sizeof(*gaRegisteredTypes)
+ );
return ;
}
i = giRegisteredTypes;
#include "usb.h"
// === IMPORTS ===
- int UHCI_Initialise();
+extern int UHCI_Initialise(void);
// === PROTOTYPES ===
int USB_Install(char **Arguments);
-void USB_Cleanup();
+void USB_Cleanup(void);
char *USB_ReadDir(tVFS_Node *Node, int Pos);
tVFS_Node *USB_FindDir(tVFS_Node *Node, char *Name);
int USB_IOCtl(tVFS_Node *Node, int Id, void *Data);
int USB_Install(char **Arguments)
{
UHCI_Initialise();
- Warning("[USB ] Not Complete - Devel Only");
+ Log_Warning("USB", "Not Complete - Devel Only");
return MODULE_ERR_OK;
}
/**
* \note 00101 - X^5+X^2+1
*/
-Uint8 USB_TokenCRC(void *Data, int len);
+extern Uint8 USB_TokenCRC(void *Data, int len);
/**
* \note X^16 + X15 + X^2 + 1
*/
-Uint16 USB_DataCRC(void *Data, int len);
+extern Uint16 USB_DataCRC(void *Data, int len);
// === STRUCTURES ===
/**