Virtual/physical addresses

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Virtual/physical addresses

Post 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;"?
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Virtual/physical addresses

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply