Can't get higher half bare bones working

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
Patrick
Posts: 2
Joined: Wed Jun 16, 2010 12:46 pm

Can't get higher half bare bones working

Post by Patrick »

Hi. I'm following the "Higher Half bare bones" tutorial, and it's not working. I'm trying to translate the NASM assembly in the tutorial to gas, which could be my problem. I know the basics of how assembly works, but I am mostly just learning as I go.

Here's the code:
http://pastebin.com/wL1AMbHs

When I run it in VirtualBox it hangs at line 64 but there is no error message. If I run it on my actual hardware it makes it to line 65 and just reboots.

Thanks.
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: Can't get higher half bare bones working

Post by thepowersgang »

I would suggest running in bochs to begin with, it's far easier to debug.

That said, have you checked the values of the symbols used, specifically the stack?
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Can't get higher half bare bones working

Post by gerryg400 »

Code: Select all

    # jump to higher half
    lea (higher_half), %ecx
    jmp *%ecx
 
higher_half:
What is the value of higher_half ?

You haven't shown your linker script. You need to link your code so that the load address is in low memory but the link (virtual) address in in higher memory. Did you do that ? Disassemble your binary and see what value if loaded into ecx.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Can't get higher half bare bones working

Post by Solar »

Patrick wrote:I'm trying to translate the NASM assembly in the tutorial to gas, which could be my problem.
Hint: Use NASM to assemble the tutorial code, then use objdump -d to disassemble the binary. Comparing the disassembly with your GAS source could give you pointers to where your translation didn't quite work out.
Every good solution is obvious once you've found it.
Patrick
Posts: 2
Joined: Wed Jun 16, 2010 12:46 pm

Re: Can't get higher half bare bones working

Post by Patrick »

gerryg400 wrote:

Code: Select all

    # jump to higher half
    lea (higher_half), %ecx
    jmp *%ecx
 
higher_half:
What is the value of higher_half ?

You haven't shown your linker script. You need to link your code so that the load address is in low memory but the link (virtual) address in in higher memory. Did you do that ? Disassemble your binary and see what value if loaded into ecx.
My linker script is basically the same as in the tutorial. That line assembles to

Code: Select all

lea 0xc0100031,%ecx
.
Solar wrote:
Patrick wrote:I'm trying to translate the NASM assembly in the tutorial to gas, which could be my problem.
Hint: Use NASM to assemble the tutorial code, then use objdump -d to disassemble the binary. Comparing the disassembly with your GAS source could give you pointers to where your translation didn't quite work out.
Thanks, I'll try that tomorrow.
Post Reply