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

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
eino
Member
Member
Posts: 49
Joined: Fri Sep 16, 2011 10:00 am
Location: Finland

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

Post 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 = .;
}
I'm Eino Tuominen from Finland, a web software dev learning low level stuff and reading / trying out kernel dev
User avatar
eino
Member
Member
Posts: 49
Joined: Fri Sep 16, 2011 10:00 am
Location: Finland

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

Post 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;
I'm Eino Tuominen from Finland, a web software dev learning low level stuff and reading / trying out kernel dev
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

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

Post 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.
Post Reply