LogF("Backtrace: 0x%x", eip);
// else
// LogF("Backtrace: %s+0x%x", str, delta);
- if(!MM_GetPhysAddr(ebp))
+ if(!MM_GetPhysAddr((void*)ebp))
{
LogF("\nBacktrace: Invalid EBP %p, stopping\n", ebp);
return;
}
- while( MM_GetPhysAddr(ebp) && i < MAX_BACKTRACE )
+ while( MM_GetPhysAddr((void*)ebp) && i < MAX_BACKTRACE )
{
if( ebp >= MM_KERNEL_STACKS_END ) break;
//str = Debug_GetSymbol(*(Uint*)(ebp+4), &delta);
}
// Mark page used
- if( MM_GetPhysAddr( (tVAddr)&gaPageReferences[indx] ) )
+ if( MM_GetPhysAddr( &gaPageReferences[indx] ) )
gaPageReferences[indx] = 1;
gaPageBitmap[ indx>>5 ] |= 1 << (indx&31);
*/
tPAddr MM_AllocPhysRange(int Pages, int MaxBits)
{
- int a, b;
int i, idx, sidx;
tPAddr ret;
}
idx = sidx / 32;
sidx %= 32;
- b = idx % 32;
- a = idx / 32;
#if 0
LOG("a=%i, b=%i, idx=%i, sidx=%i", a, b, idx, sidx);
// Mark pages used
for( i = 0; i < Pages; i++ )
{
- if( MM_GetPhysAddr( (tVAddr)&gaPageReferences[idx*32+sidx] ) )
+ if( MM_GetPhysAddr( &gaPageReferences[idx*32+sidx] ) )
gaPageReferences[idx*32+sidx] = 1;
gaPageBitmap[ idx ] |= 1 << sidx;
sidx ++;
// Reference the page
if( gaPageReferences )
{
- if( MM_GetPhysAddr( (tVAddr)&gaPageReferences[PAddr] ) == 0 )
+ if( MM_GetPhysAddr( &gaPageReferences[PAddr] ) == 0 )
{
int i, base;
tVAddr addr = ((tVAddr)&gaPageReferences[PAddr]) & ~0xFFF;
giLastPossibleFree = PAddr;
// Dereference
- if( !MM_GetPhysAddr( (tVAddr)&gaPageReferences[PAddr] ) || (-- gaPageReferences[PAddr]) == 0 )
+ if( !MM_GetPhysAddr( &gaPageReferences[PAddr] ) || (-- gaPageReferences[PAddr]) == 0 )
{
#if TRACE_ALLOCS
Log_Debug("PMem", "MM_DerefPhys: Free'd %P (%i free)", PAddr<<12, giPageCount-giPhysAlloc);
if(gaPageBitmap[ PAddr / 32 ] == 0)
gaSuperBitmap[ PAddr >> 10 ] &= ~(1 << ((PAddr >> 5)&31));
- if( MM_GetPhysAddr( (tVAddr) &gaPageNodes[PAddr] ) )
+ if( MM_GetPhysAddr( &gaPageNodes[PAddr] ) )
{
gaPageNodes[PAddr] = NULL;
// TODO: Free Node Page when fully unused
// We don't care about non-ram pages
if(PAddr >= giPageCount) return -1;
- if( MM_GetPhysAddr( (tVAddr)&gaPageReferences[PAddr] ) == 0 )
+ if( MM_GetPhysAddr( &gaPageReferences[PAddr] ) == 0 )
return (gaPageBitmap[PAddr / 32] & (1 << PAddr%32)) ? 1 : 0;
// Check if it is freed
block_addr = (tVAddr) &gaPageNodes[PAddr];
block_addr &= ~(PAGE_SIZE-1);
- if( !MM_GetPhysAddr( block_addr ) )
+ if( !MM_GetPhysAddr( (void*)block_addr ) )
{
if( !MM_Allocate( block_addr ) ) {
Log_Warning("PMem", "Unable to allocate Node page");
if( MM_GetRefCount(PAddr) == 0 ) return 1;
PAddr /= PAGE_SIZE;
- if( !MM_GetPhysAddr( (tVAddr) &gaPageNodes[PAddr] ) ) {
+ if( !MM_GetPhysAddr( &gaPageNodes[PAddr] ) ) {
*Node = NULL;
return 0;
}
* \fn tPAddr MM_GetPhysAddr(tVAddr Addr)
* \brief Checks if the passed address is accesable
*/
-tPAddr MM_GetPhysAddr(tVAddr Addr)
+tPAddr MM_GetPhysAddr(const void *Addr)
{
- if( !(gaPageDir[Addr >> 22] & 1) )
+ tVAddr addr = (tVAddr)Addr;
+ if( !(gaPageDir[addr >> 22] & 1) )
return 0;
- if( !(gaPageTable[Addr >> 12] & 1) )
+ if( !(gaPageTable[addr >> 12] & 1) )
return 0;
- return (gaPageTable[Addr >> 12] & ~0xFFF) | (Addr & 0xFFF);
+ return (gaPageTable[addr >> 12] & ~0xFFF) | (addr & 0xFFF);
}
/**
for(base = MM_KERNEL_STACKS; base < MM_KERNEL_STACKS_END; base += MM_KERNEL_STACK_SIZE)
{
// Check if space is free
- if(MM_GetPhysAddr(base) != 0) continue;
+ if(MM_GetPhysAddr( (void*) base) != 0)
+ continue;
// Allocate
//for(i = MM_KERNEL_STACK_SIZE; i -= 0x1000 ; )
for(i = 0; i < MM_KERNEL_STACK_SIZE; i += 0x1000 )
*/
tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
{
- tPAddr maxCheck = (1 << MaxBits);
tPAddr phys;
tVAddr ret;
return 0;
}
- // Bound
- if(MaxBits >= PHYS_BITS) maxCheck = -1;
-
// Fast Allocate
if(Pages == 1 && MaxBits >= PHYS_BITS)
{
*/
void Proc_Start(void)
{
- int tid;
#if USE_MP
int i;
#endif
if(i) gaCPUs[i].Current = NULL;
// Create Idle Task
- tid = Proc_NewKThread(Proc_IdleThread, &gaCPUs[i]);
+ Proc_NewKThread(Proc_IdleThread, &gaCPUs[i]);
// Start the AP
if( i != giProc_BootProcessorID ) {
while( giNumInitingCPUs ) __asm__ __volatile__ ("hlt");
#else
// Create Idle Task
- tid = Proc_NewKThread(Proc_IdleThread, &gaCPUs[0]);
-// gaCPUs[0].IdleThread = Threads_GetThread(tid);
+ Proc_NewKThread(Proc_IdleThread, &gaCPUs[0]);
// Set current task
gaCPUs[0].Current = &gThreadZero;
tTID Proc_NewKThread(void (*Fcn)(void*), void *Data)
{
Uint esp;
- tThread *newThread, *cur;
+ tThread *newThread;
- cur = Proc_GetCurThread();
newThread = Threads_CloneTCB(0);
if(!newThread) return -1;
// Check Prospective Space
for( i = USER_STACK_SZ >> 12; i--; )
- if( MM_GetPhysAddr( base + (i<<12) ) != 0 )
+ if( MM_GetPhysAddr( (void*)(base + (i<<12)) ) != 0 )
break;
if(i != -1) return 0;
_start &= ~(PAGE_SIZE-1);
LOG("_start = %p, _len = 0x%x", _start, _len);
for( ; _len > PAGE_SIZE; _len -= PAGE_SIZE, _start += PAGE_SIZE ) {
- if( MM_GetPhysAddr(_start) != 0 ) {
+ if( MM_GetPhysAddr( (void*)_start ) != 0 ) {
LEAVE('i', 1);
return 1;
}
}
- if( _len == PAGE_SIZE && MM_GetPhysAddr(_start) != 0 ) {
+ if( _len == PAGE_SIZE && MM_GetPhysAddr( (void*)_start ) != 0 ) {
LEAVE('i', 1);
return 1;
}
foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) );
#if VERBOSE_DUMP
Log_Log("Heap", "%p (0x%P): 0x%08x (%i) %4C",
- head, MM_GetPhysAddr((tVAddr)head), head->Size, head->ValidSize, &head->Magic);
+ head, MM_GetPhysAddr(head), head->Size, head->ValidSize, &head->Magic);
Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
if(head->File) {
Log_Log("Heap", "%sowned by %s:%i",
#if !VERBOSE_DUMP
Log_Log("Heap", "%p (%P): 0x%08lx %i %4C",
- head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
+ head, MM_GetPhysAddr(head), head->Size, head->ValidSize, &head->Magic);
if(foot)
Log_Log("Heap", "Foot %p = {Head:%p,Magic:%4C}", foot, foot->Head, &foot->Magic);
if(head->File) {
while( (tVAddr)head >= (tVAddr)badHead )
{
Log_Log("Heap", "%p (%P): 0x%08lx %i %4C",
- head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
+ head, MM_GetPhysAddr(head), head->Size, head->ValidSize, &head->Magic);
Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
if(head->File)
Log_Log("Heap", "%sowned by %s:%i",
#if 1
if( head->Magic == MAGIC_FREE )
Log_Debug("Heap", "%p (%P) - 0x%x free",
- head->Data, MM_GetPhysAddr((tVAddr)&head->Data), head->Size);
+ head->Data, MM_GetPhysAddr(&head->Data), head->Size);
else
Log_Debug("Heap", "%p (%P) - 0x%x (%i) Owned by %s:%i (%lli ms old)",
- head->Data, MM_GetPhysAddr((tVAddr)&head->Data), head->Size, head->ValidSize, head->File, head->Line,
+ head->Data, MM_GetPhysAddr(&head->Data), head->Size, head->ValidSize, head->File, head->Line,
now() - head->AllocateTime
);
#endif
* \param Addr Address of the page to get the physical address of
* \return Physical page mapped at \a Addr
*/
-extern tPAddr MM_GetPhysAddr(tVAddr Addr);
+extern tPAddr MM_GetPhysAddr(const void *Addr);
/**
* \brief Set the access flags on a page
* \param VAddr Virtual address of the page
addr = (tVAddr)String;
- if( !MM_GetPhysAddr( addr ) )
+ if( !MM_GetPhysAddr( (void*)addr ) )
return 0;
// Check 1st page
{
if(bUser && !MM_IsUser(addr) )
return 0;
- if(!bUser && !MM_GetPhysAddr(addr) )
+ if(!bUser && !MM_GetPhysAddr((void*)addr) )
return 0;
}
addr ++;
// -- Get the physical address of a page
case SYS_GETPHYS:
- ret = MM_GetPhysAddr(Regs->Arg1);
+ ret = MM_GetPhysAddr( (void*)Regs->Arg1 );
break;
// -- Map an address
{
int max_handles = *Threads_GetMaxFD();
// Allocate Buffer
- if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
+ if( MM_GetPhysAddr( gaUserHandles ) == 0 )
{
Uint addr, size;
size = max_handles * sizeof(tVFS_Handle);
else
{
// Allocate space if not already
- if( MM_GetPhysAddr( (tVAddr)gaKernelHandles ) == 0 )
+ if( MM_GetPhysAddr( gaKernelHandles ) == 0 )
{
Uint addr, size;
size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
int max_handles = *Threads_GetMaxFD();
// Check if this process has any handles
- if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
+ if( MM_GetPhysAddr( gaUserHandles ) == 0 )
return ;
for( i = 0; i < max_handles; i ++ )
int max_handles = *Threads_GetMaxFD();
// Check if this process has any handles
- if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
+ if( MM_GetPhysAddr( gaUserHandles ) == 0 )
return ;
for( i = 0; i < max_handles; i ++ )
int max_handles = *Threads_GetMaxFD();
// Check if this process has any handles
- if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
+ if( MM_GetPhysAddr( gaUserHandles ) == 0 )
return NULL;
// Allocate
return ;
// Check if there is already a set of handles
- if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) != 0 )
+ if( MM_GetPhysAddr( gaUserHandles ) != 0 )
return ;
LOG("%i pages anonymous to %p", npages, mapping_dest);
for( ; npages --; mapping_dest += PAGE_SIZE, ofs += PAGE_SIZE )
{
- if( MM_GetPhysAddr(mapping_dest) ) {
+ if( MM_GetPhysAddr((void*)mapping_dest) ) {
// TODO: Set flags to COW if needed (well, if shared)
MM_SetFlags(mapping_dest, MM_PFLAG_COW, MM_PFLAG_COW);
LOG("clear from %p, %i bytes", (void*)(mapping_base + ofs),
// - Map (and allocate) pages
while( npages -- )
{
- if( MM_GetPhysAddr(mapping_dest) == 0 )
+ if( MM_GetPhysAddr( (void*)mapping_dest ) == 0 )
{
if( pb->PhysAddrs[pagenum - pb->BaseOffset] == 0 )
{
}
// TODO: Clip read length
read_len = nt->Read(h->Node, pagenum*PAGE_SIZE, PAGE_SIZE, (void*)mapping_dest);
-// if( read_len != PAGE_SIZE ) {
-// memset( (void*)(mapping_dest+read_len), 0, PAGE_SIZE-read_len );
-// }
+ // TODO: This was commented out, why?
+ if( read_len != PAGE_SIZE ) {
+ memset( (void*)(mapping_dest+read_len), 0, PAGE_SIZE-read_len );
+ }
}
- pb->PhysAddrs[pagenum - pb->BaseOffset] = MM_GetPhysAddr( mapping_dest );
+ pb->PhysAddrs[pagenum - pb->BaseOffset] = MM_GetPhysAddr( (void*)mapping_dest );
MM_SetPageNode( pb->PhysAddrs[pagenum - pb->BaseOffset], h->Node );
MM_RefPhys( pb->PhysAddrs[pagenum - pb->BaseOffset] );
LOG("Read and map %X to %p (%P)", pagenum*PAGE_SIZE, mapping_dest,
card->NextTX = (card->NextTX + nDescs) % N_TX_DESCS;
desc = card->TXDescs + first_desc_id;
- desc->TXBufferStart = MM_GetPhysAddr( (tVAddr)data );
+ desc->TXBufferStart = MM_GetPhysAddr( data );
desc->BufferSize = len | (1 << 15);
desc->TSR = 0;
desc->TCR = 0;
IRQ_AddHandler( gATA_IRQPri, ATA_IRQHandlerPri, NULL );
IRQ_AddHandler( gATA_IRQSec, ATA_IRQHandlerSec, NULL );
- gATA_PRDTs[0].PBufAddr = MM_GetPhysAddr( (tVAddr)&gATA_Buffers[0] );
- gATA_PRDTs[1].PBufAddr = MM_GetPhysAddr( (tVAddr)&gATA_Buffers[1] );
+ gATA_PRDTs[0].PBufAddr = MM_GetPhysAddr( &gATA_Buffers[0] );
+ gATA_PRDTs[1].PBufAddr = MM_GetPhysAddr( &gATA_Buffers[1] );
LOG("gATA_PRDTs = {PBufAddr: 0x%x, PBufAddr: 0x%x}", gATA_PRDTs[0].PBufAddr, gATA_PRDTs[1].PBufAddr);
- gaATA_PRDT_PAddrs[0] = MM_GetPhysAddr( (tVAddr)&gATA_PRDTs[0] );
+ gaATA_PRDT_PAddrs[0] = MM_GetPhysAddr( &gATA_PRDTs[0] );
LOG("gaATA_PRDT_PAddrs[0] = 0x%x", gaATA_PRDT_PAddrs[0]);
ATA_int_BusMasterWriteDWord(4, gaATA_PRDT_PAddrs[0]);
- gaATA_PRDT_PAddrs[1] = MM_GetPhysAddr( (tVAddr)&gATA_PRDTs[1] );
+ gaATA_PRDT_PAddrs[1] = MM_GetPhysAddr( &gATA_PRDTs[1] );
LOG("gaATA_PRDT_PAddrs[1] = 0x%x", gaATA_PRDT_PAddrs[1]);
ATA_int_BusMasterWriteDWord(12, gaATA_PRDT_PAddrs[1]);
1,17,9,25,5,21,13,29,3,19,11,27,7,23,15,31
};
for( int i = 0; i < 1024; i ++ ) {
- Uint32 addr = MM_GetPhysAddr( (tVAddr)&Host->TDQHPage->ControlQH );
+ Uint32 addr = MM_GetPhysAddr( &Host->TDQHPage->ControlQH );
Host->FrameList[i] = addr | 2;
}
for( int i = 0; i < 64; i ++ ) {
dest += _count; destphys += _count * sizeof(tUHCI_QH);
}
// Skip padding, and move to control QH
- dest->Next = MM_GetPhysAddr( (tVAddr)&Host->TDQHPage->BulkQH ) | 2;
+ dest->Next = MM_GetPhysAddr( &Host->TDQHPage->BulkQH ) | 2;
dest->Child = 1;
}
// Set up control and bulk queues
- Host->TDQHPage->ControlQH.Next = MM_GetPhysAddr( (tVAddr)&Host->TDQHPage->BulkQH ) | 2;
+ Host->TDQHPage->ControlQH.Next = MM_GetPhysAddr( &Host->TDQHPage->BulkQH ) | 2;
Host->TDQHPage->ControlQH.Child = 1;
Host->TDQHPage->BulkQH.Next = 1;
Host->TDQHPage->BulkQH.Child = 1;
// Add
TD->Link = 1;
if( QH->Child & 1 ) {
- QH->Child = MM_GetPhysAddr( (tVAddr)TD );
+ QH->Child = MM_GetPhysAddr( TD );
}
else {
// Depth first
- QH->_LastItem->Link = MM_GetPhysAddr( (tVAddr)TD ) | 4;
+ QH->_LastItem->Link = MM_GetPhysAddr( TD ) | 4;
}
QH->_LastItem = TD;
if(
((tVAddr)Data & (PAGE_SIZE-1)) + Length > PAGE_SIZE
#if PHYS_BITS > 32
- || MM_GetPhysAddr( (tVAddr)Data ) >> 32
+ || MM_GetPhysAddr( Data ) >> 32
#endif
)
{
LOG("Relocated IN");
info = calloc( sizeof(tUHCI_ExtraTDInfo), 1 );
info->Offset = ((tVAddr)Data & (PAGE_SIZE-1));
- info->FirstPage = MM_GetPhysAddr( (tVAddr)Data );
- info->SecondPage = MM_GetPhysAddr( (tVAddr)Data + Length - 1 );
+ info->FirstPage = MM_GetPhysAddr( Data );
+ info->SecondPage = MM_GetPhysAddr( (const char *)Data + Length - 1 );
}
else
{
}
else
{
- td->BufferPointer = MM_GetPhysAddr( (tVAddr)Data );
+ td->BufferPointer = MM_GetPhysAddr( Data );
td->_info.bFreePointer = 0;
}
}
- tPAddr global_pool = MM_GetPhysAddr( (tVAddr)gaUHCI_TDPool );
+ tPAddr global_pool = MM_GetPhysAddr( gaUHCI_TDPool );
if( PAddr < global_pool || PAddr >= global_pool + PAGE_SIZE ) return NULL;