Memory management and kernel size

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
danielgatis
Posts: 4
Joined: Sat Apr 12, 2014 11:07 am

Memory management and kernel size

Post by danielgatis »

hi,
I'm implementing the memory management of my SO but how can I get the size of the kernel? (I'm using the multiboot spec).

my link.ld script

Code: Select all

ENTRY(_start)
SECTIONS
{
  . = 1M;

  .text BLOCK(4K) : ALIGN(4K)
  {
    *(.multiboot)
    *(.text)
  }

  .rodata BLOCK(4K) : ALIGN(4K)
  {
    *(.rodata)
  }

  .data BLOCK(4K) : ALIGN(4K)
  {
    *(.data)
  }

  .bss BLOCK(4K) : ALIGN(4K)
  {
    *(COMMON)
    *(.bss)
    *(.bootstrap_stack)
  }
}

Code: Select all

..................   -> 0xFFFFFF
|................|
|................|
|................|
|................|
 ==================   -> 0x?????? (kernel size)
|................|
|................|
 ==================   -> 0x100000 (lower memory - bootloader, video ...) 
|................|
|................|
..................   -> 0x000000
thanks.
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Memory management and kernel size

Post by bwat »

If you're on unix, see if "man end" gives you anything interesting.
Every universe of discourse has its logical structure --- S. K. Langer.
danielgatis
Posts: 4
Joined: Sat Apr 12, 2014 11:07 am

Re: Memory management and kernel size

Post by danielgatis »

bwat wrote:If you're on unix, see if "man end" gives you anything interesting.
So I init my bitmap with this values. Is this the way?

Code: Select all

// first param: end position of kernel
// second param: amount upper memory - (end kernel location - start kernel location)
k_init_pmm((uint32_t)&end, mboot_ptr->mem_upper - (uint32_t)&end - 0x10000);

#define K_PMM_BLOCKS_PER_BYTE 8
#define K_PMM_BLOCK_SIZE 4096

// size of physical memory
static  uint32_t  k_pmm_memory_size = 0;

// maximum number of available memory blocks
static  uint32_t  k_pmm_max_blocks = 0;

// memory map bit array. Each bit represents a memory block
static  uint32_t* k_pmm_memory_map = 0;

void k_init_pmm(uint32_t base, uint32_t size)
{
  k_pmm_memory_size  = size;
  k_pmm_memory_map = (uint32_t*) base;
  k_pmm_max_blocks = (k_pmm_memory_size * 1024) / K_PMM_BLOCK_SIZE;

  memset(k_pmm_memory_map, 0x0, k_pmm_max_blocks / K_PMM_BLOCKS_PER_BYTE);
}
Post Reply