Page 1 of 1

Memory management and kernel size

Posted: Thu Apr 17, 2014 8:45 am
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.

Re: Memory management and kernel size

Posted: Thu Apr 17, 2014 9:14 am
by bwat
If you're on unix, see if "man end" gives you anything interesting.

Re: Memory management and kernel size

Posted: Thu Apr 17, 2014 10:32 am
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);
}