Page 1 of 1

After switching to higher half, kernel address is corrupted

Posted: Mon Aug 29, 2016 11:06 pm
by stdcall
Hi.
I recently enabled paging with higher half kernel.
Since then, accessing kernel start and end address variables I declared in the linker script returns wrong addresses.

This is my linker script

Code: Select all

  ENTRY(EntryPoint)
  OUTPUT_FORMAT(elf32-i386)
  
  ENTRY_BASE = 0x100000;
  CODE_VIRT  = 0xC0000000;
  
  SECTIONS {
     /* The kernel will live at 3GB + 1MB in the virtual
        address space, which will be mapped to 1MB in the
        physical address space. */
      
      . = ENTRY_BASE;
  
      .boot : {
      *(.multiboot)
_     *(.bootcode)
      *.(bootstack)
      }
  
      . += CODE_VIRT;
  
     .text : AT(ADDR(.text) - 0xC0000000) {
      kernel_start = .;
      *(.text)
      *(.rodata*)
     }
      kernel_end = .;
  
     .data ALIGN (0x1000) : AT(ADDR(.data) - 0xC0000000) {
         *(.data)
     }
  
     .bss : AT(ADDR(.bss) - 0xC0000000) {
         _sbss = .;
         *(COMMON)
         *(.bss)
         _ebss = .;
     }
  }
The correct start addresses should be: (according to readelf)

Code: Select all

[ 4] .text             PROGBITS        c0104820 005820 0020e8 00  AX  0   0 16
[ 5] .data             PROGBITS        c0107000 008000 002000 00  WA  0   0 4096
[ 6] .bss              NOBITS          c0109000 00a000 008030 00  WA  0   0 4096
[ 7] .debug_info       PROGBITS        00000000 00a000 0024ae 00      0   0  1
When I print the address I get wrong address:
Kernel start: 0x3fefb7e0, kernel end: 0x3fef96f8

The actual code to print it:

Code: Select all

extern uint32_t kernel_start;
extern uint32_t kernel_end;

printk("Kernel start: 0x%x, kernel end: 0x%x\r\n", (uint32_t) &kernel_start, (uint32_t) &kernel_end);
Before enabling paging, this code worked perfectly.
What am I missing ?

Re: After switching to higher half, kernel address is corrup

Posted: Mon Aug 29, 2016 11:55 pm
by Octocontrabass
You're missing a working printk function.

Re: After switching to higher half, kernel address is corrup

Posted: Mon Aug 29, 2016 11:57 pm
by stdcall
You're missing a working printk function.
Care to elaborate ?

Re: After switching to higher half, kernel address is corrup

Posted: Mon Aug 29, 2016 11:59 pm
by kzinti
Your printk function is obviously not working. The values you get make no sense. Not only are your start/end addresses not matching what we can see in your linker script, you have end < start!

Re: After switching to higher half, kernel address is corrup

Posted: Tue Aug 30, 2016 12:04 am
by Octocontrabass
mellowcandle wrote:Care to elaborate ?
You've never used your printk function to print a number bigger than 0x7FFFFFFF, so you've never noticed that it's treating the input as signed when it should be unsigned.

Re: After switching to higher half, kernel address is corrup

Posted: Tue Aug 30, 2016 12:17 am
by stdcall
Yes !!!

Turns out I have itoa and uitoa, and I called the wrong one for %x.

Thanks !!