OSDev.org
https://forum.osdev.org/

Virtual/physical addresses
https://forum.osdev.org/viewtopic.php?f=1&t=26268
Page 1 of 1

Author:  BMW [ Sat Feb 02, 2013 1:48 am ]
Post subject:  Virtual/physical addresses

In James Molloy's tutorial (http://www.jamesmolloy.co.uk/tutorial_h ... aging.html), he has a function to allocate memory:
Code:
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;"?

Author:  thepowersgang [ Sat Feb 02, 2013 2:58 am ]
Post subject:  Re: Virtual/physical addresses

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/