Wrong addresses being pushed on the stack

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.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Wrong addresses being pushed on the stack

Post by Tosi »

Loading a single character can be hardcoded into the code, such as

Code: Select all

mov al, 'A'
If you want to use strings, include the section .rodata in your linker script.
Davidm44
Posts: 13
Joined: Sun Dec 26, 2010 10:52 am

Re: Wrong addresses being pushed on the stack

Post by Davidm44 »

Tosi wrote:Loading a single character can be hardcoded into the code, such as

Code: Select all

mov al, 'A'
If you want to use strings, include the section .rodata in your linker script.
I'm not using a linker script at the moment ( but I tried one ), I guess I should be.. I'll try it out and post results.

Edit: The linker script I was using already had the .rodata section defined. I'm not sure if it's correct though, I got this from the osdev wiki.

Code: Select all

ENTRY (main)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}

User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Wrong addresses being pushed on the stack

Post by Chandra »

Davidm44 wrote:
Tosi wrote:Loading a single character can be hardcoded into the code, such as

Code: Select all

mov al, 'A'
If you want to use strings, include the section .rodata in your linker script.
I'm not using a linker script at the moment ( but I tried one ), I guess I should be.. I'll try it out and post results.

Edit: The linker script I was using already had the .rodata section defined. I'm not sure if it's correct though, I got this from the osdev wiki.

Code: Select all

ENTRY (main)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}

You were loading your kernel @ 0x1000, right? So what is 0x100000 for?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Davidm44
Posts: 13
Joined: Sun Dec 26, 2010 10:52 am

Re: Wrong addresses being pushed on the stack

Post by Davidm44 »

Chandra wrote:
Davidm44 wrote:
Tosi wrote:Loading a single character can be hardcoded into the code, such as

Code: Select all

mov al, 'A'
If you want to use strings, include the section .rodata in your linker script.
I'm not using a linker script at the moment ( but I tried one ), I guess I should be.. I'll try it out and post results.

Edit: The linker script I was using already had the .rodata section defined. I'm not sure if it's correct though, I got this from the osdev wiki.

Code: Select all

ENTRY (main)

SECTIONS{
    . = 0x00100000;

    .text :{
        *(.text)
    }

    .rodata ALIGN (0x1000) : {
        *(.rodata)
    }

    .data ALIGN (0x1000) : {
        *(.data)
    }

    .bss : {
        sbss = .;
        *(COMMON)
        *(.bss)
        ebss = .;
    }
}

You were loading your kernel @ 0x1000, right? So what is 0x100000 for?
Sorry for bumping & late reply, but changing 100000 to 1000 didn't do anything. Same output..
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Wrong addresses being pushed on the stack

Post by thepowersgang »

A random stab in the dark points me to your GDT being slightly dodgy.
Have you tried the bochs debugger, and single stepping through the code to spot why it doesn't work.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Wrong addresses being pushed on the stack

Post by Chandra »

As far as I can hit stone in the darkness, there is some problem in the relocation. Since he is not using 'Cross Compiler', I guess one of the following might work out.
1. Change the entry point to kmain(which is your actual entry point as specified in your code) and not main(which you are using now).
2. Insert the output format "elf32-i386" in your linker script.
3. Since you are turning your kernel to flat binary anyway, you may tell the linker to do this job for you.This remove hassles for employing 'objcopy' to remove elf headers for you. And thus if the problem is relocation, this option might help.
4. Use the 'Cross Compiler'.

If none of this option helps in anyway, its time to do some debugging.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Davidm44
Posts: 13
Joined: Sun Dec 26, 2010 10:52 am

Re: Wrong addresses being pushed on the stack

Post by Davidm44 »

Chandra wrote:As far as I can hit stone in the darkness, there is some problem in the relocation. Since he is not using 'Cross Compiler', I guess one of the following might work out.
1. Change the entry point to kmain(which is your actual entry point as specified in your code) and not main(which you are using now).
2. Insert the output format "elf32-i386" in your linker script.
3. Since you are turning your kernel to flat binary anyway, you may tell the linker to do this job for you.This remove hassles for employing 'objcopy' to remove elf headers for you. And thus if the problem is relocation, this option might help.
4. Use the 'Cross Compiler'.

If none of this option helps in anyway, its time to do some debugging.
Sorry about that, I fixed it now. I changed 10000 to 1000 as someone mentioned above and changed align to 4 instead of 1000. It was a complete shot in the dark but its working now.

Do you have any links to tutorials or references that would help me understand linker scripts a bit more clearly? I checked the osdev wiki but it seems a little complicated.

Thanks.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Wrong addresses being pushed on the stack

Post by Tosi »

The wiki's description of linker scripts is vastly oversimplified and not really useful for everything. The best resource would be the documentation for whatever version of binutils you are using.
Post Reply