How to jump to specific location.
How to jump to specific location.
At the end of my boot sector code, I want to jump to my kernel, located at 0x1000:0x0000. The code is currently executing at about 0x0000:0x7d00. I am stumped. I currently have jmp dword ptr es:0000h (es contains 0x1000). Bochs keeps giving me something about prefetch EIP xxxxxxxx > CS.limit xxxxxxxx. What does the prefetch thing mean, and how do I fix it? I'm using MASM BTW.
- DavidCooper
- Member
- Posts: 1150
- Joined: Wed Oct 27, 2010 4:53 pm
- Location: Scotland
Re: How to jump to specific location.
Why would you try to use ES for code? Try a more conventional jump.kendfrey wrote:I currently have jmp dword ptr es:0000h (es contains 0x1000).
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Re: How to jump to specific location.
Like what?
Re: How to jump to specific location.
like "jmp 0x1000:0x0000" ??? Nasm won't even let me compile jmp es:0x0000...
My hero, is Mel.
Re: How to jump to specific location.
MASM won't let me compile jmp 1000h:0000h. "error A2096: segment, group, or segment register expected"
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to jump to specific location.
JMP es:0x0000 does not exist as an instruction: you should not load a code segment with a data segment. The closest variant is jmp [es:0x0000] which is a simple indirect jump and does not do what you want. NASM is right in that regard in refusing assembly.
Why people keep trying to use jmp far ds, address as an instruction is beyond me. It's not anywhere in the manuals after all (mov cs, xxx is another one).
Why people keep trying to use jmp far ds, address as an instruction is beyond me. It's not anywhere in the manuals after all (mov cs, xxx is another one).
Re: How to jump to specific location.
As far as I know, mov cs, xx is not allowed by MASM either. There are workarounds (my bootloader makes use of one ). Anyway, I found something about segments in MASM, and I did this:
and then jmp kernel:start worked. I don't know why MASM is so persnickety.
Code: Select all
kernel segment at 1000h
org 0
start label far
kernel ends
Re: How to jump to specific location.
When the assembler refuses to cooperate, read up on the opcodes and use db, dw, dd instead
Re: How to jump to specific location.
Becuase that is not a valid way to set CS. Read the Manuals.kendfrey wrote:As far as I know, mov cs, xx is not allowed by MASM either.
A simple workaround can be:kendfrey wrote:There are workarounds (my bootloader makes use of one ). Anyway, I found something about segments in MASM, and I did this:and then jmp kernel:start worked. I don't know why MASM is so persnickety.Code: Select all
kernel segment at 1000h org 0 start label far kernel ends
Code: Select all
push word 0x1000
push word 0x0000
retf
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
- DavidCooper
- Member
- Posts: 1150
- Joined: Wed Oct 27, 2010 4:53 pm
- Location: Scotland
Re: How to jump to specific location.
Coty made a suggestion:-
Did you actually try that? Your reply was:-Coty wrote:like "jmp 0x1000:0x0000" ???
I don't know the right syntax for a far jump in different assemblers, so you need to look up the MASM manual to see how it should be done. [In machine code terms you should end up with a far jump instruction (the single byte 234, which I think is EA in hex), followed by two bytes of address (if you're in real mode) and two more bytes to be loaded into CS. Unfortunately, that doesn't help you work out how an assembler will require you to formulate the instruction.]kendfrey wrote:MASM won't let me compile jmp 1000h:0000h. "error A2096: segment, group, or segment register expected"
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Re: How to jump to specific location.
MASM does not have a way to specify a far jump with a numeric segment part. You have to define the instruction using db and dw.
Re: How to jump to specific location.
Not an easy way, but see my previous post. (Yes it generates the same opcode as jmp xxxx:xxxx)