Code: Select all
#define GET_PAGE_NUMBER( address ) ( address >> 12 )
void map_mem(unsigned int base, unsigned int length)
{
page_t *pg;
//create pd
kernel_directory = (page_directory_t*)kmalloc_a(sizeof(page_directory_t));
memset(kernel_directory, 0, sizeof(page_directory_t));
int i = 0;
//create pages
for (i = base; i < base+length; i += 0x1000)
get_page(i, 1, kernel_directory);
//identity map
i = 0;
while (i < base+0x1000)
{
// Kernel code is readable but not writeable from userspace.
alloc_frame( get_page(i, 1, kernel_directory), 0, 0);
i += 0x1000;
}
// Now allocate those pages we mapped earlier.
for (i = base; i < base+length; i += 0x1000)
alloc_frame( get_page(i, 1, kernel_directory), 0, 0);
//set frame to base addr
pg->frame=GET_PAGE_NUMBER(base);
}
Code: Select all
kprint("page_addr: 0x%x", map_mem(BAR5, BAR5Sze));
Helpful Info:
- The base address denotes a memory space address for a PCI device
- This was an honest attempt to map that address for access to the device registers
- My intent was to identity map a set of pages starting at phy_addr=base to base length, to set them for use, and then to set the frame address to the phy_addr (true base addr) for device register access
Please let me know if you need more information.