Define get_physical() and make_resident()

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
Laurent Vivier 2009-06-18 22:24:51 +02:00
parent dd27d8c153
commit efcadd06c5
2 changed files with 45 additions and 0 deletions

View File

@ -11,6 +11,9 @@
#include "misc.h"
#include "console.h"
#include "enter_kernel.h" /* for PAGE_SIZE */
#include "macos/memory.h"
unsigned char *c2pstring(char* s)
{
@ -71,3 +74,42 @@ void memdump(unsigned char* addr, unsigned long size)
i += j;
}
}
/* from miBoot */
unsigned char *get_physical(void *ptr)
{
LogicalToPhysicalTable table;
unsigned long count;
OSErr err;
table.logical.address = ptr;
table.logical.count = 1024;
count = sizeof(table) / sizeof(MemoryBlock) - 1;
err = GetPhysical(&table, &count);
if (err != noErr)
return ptr;
return table.physical[0].address;
}
/* from miBoot */
unsigned int make_resident(void* ptr, unsigned long size, int contiguous)
{
OSErr err;
if (size % PAGE_SIZE)
size = size + PAGE_SIZE - (size % PAGE_SIZE);
if (contiguous)
err = LockMemoryContiguous(ptr, size);
else
err = LockMemory(ptr, size);
if (err)
return -1;
return 0;
}

View File

@ -11,5 +11,8 @@ extern unsigned char *c2pstring(char* s);
extern char *p2cstring(unsigned char* s);
extern void memdump(unsigned char* addr, unsigned long size);
extern void error(char *x) __attribute__ ((noreturn));
extern unsigned char *get_physical(void *ptr);
extern unsigned int make_resident(void* ptr, unsigned long size,
int contiguous);
#endif /* __MISC_H__ */