Page 1 of 1

Is this a valid way of finding the end point of kernel

Posted: Wed Nov 23, 2011 12:07 pm
by eino
Hello. I actually didn't believe any of this would work but since I'm getting a some sort of reasonable output of 1075460 i think this may actually work... What do you think? The kernel_end address is probably correct but can I trust my printing methods?

Code: Select all

extern long kernel_end;
char c_kernel_end[64];
einos_itoa ( c_kernel_end, &kernel_end );	

print_string ( "Kernel ends at: \0" );
print_string ( c_kernel_end );
print_string ( "\n\0" );

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  kernel_end = .;
}

Re: Is this a valid way of finding the end point of kernel

Posted: Wed Nov 23, 2011 2:04 pm
by eino
Thanks!

Sort of added question/thought... Is this an ok way to page align page directory and first page table:

Code: Select all

unsigned int address = 0; 
	 
while ( address < &kernel_end ) {
	address = address + 4096;
}

page_directory = ( unsigned int* ) address;

unsigned int *first_page_table = page_directory + address;

Re: Is this a valid way of finding the end point of kernel

Posted: Wed Nov 23, 2011 7:13 pm
by Casm
eino wrote:Thanks!

Sort of added question/thought... Is this an ok way to page align page directory and first page table:
Assuming you have a 32 bit kernel, you need:

Code: Select all

address += 4095;       //or 0xfff
address &= 0xfffff000;
For example if address = 2794238 (=0x2aa2fe), adding 4095 to that will get you 2798333 = 0x2ab2fd, and ANDing that with 0xfffff000 gives you 2797568 = 0x2ab000.