Page 1 of 1

Virtual/physical addresses

Posted: Sat Feb 02, 2013 1:48 am
by BMW
In James Molloy's tutorial (http://www.jamesmolloy.co.uk/tutorial_h ... aging.html), he has a function to allocate memory:

Code: Select all

u32int kmalloc(u32int sz, int align, u32int *phys)
{
  if (align == 1 && (placement_address & 0xFFFFF000)) // If the address is not already page-aligned
  {
    // Align it.
    placement_address &= 0xFFFFF000;
    placement_address += 0x1000;
  }
  if (phys)
  {
    *phys = placement_address;
  }
  u32int tmp = placement_address;
  placement_address += sz;
  return tmp;
} 
If "*phys = placement_address;" gives a physical address, why doesn't "u32int tmp = placement_address; return tmp;"?

Re: Virtual/physical addresses

Posted: Sat Feb 02, 2013 2:58 am
by thepowersgang
Congratulations, you've found one of the places where JamesM's tutorial sucks.

I'd assume the code is designed for identity mappings, so phys=virtual, but the prototype is designed to be easily extended.