[ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

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.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by jal »

Hobbes wrote:I would like to know how you would call them.
I'm not sure. What I have against logical/physical is that in the normal sense of the words applied to addressing, you are talking about some kind of mapping (like paging), while the difference between 0000:7c00 and 07c0:0000 is purely one of representation of the address, not one of different addresses (they are not two different "logical" addresses in my opinion, they are the same address, as opposed to say, 0x1000000 and 0x2000000 being different logical addresses that could both point to physical address 0xf0000000 in a paging scheme).


JAL
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by AJ »

Hi,
jal wrote:(they are not two different "logical" addresses in my opinion, they are the same address, as opposed to say, 0x1000000 and 0x2000000 being different logical addresses that could both point to physical address 0xf0000000 in a paging scheme).
Think of it as an "Address Translation Scheme" rather than specifically a "Paging Scheme" and you can then feel more comfortable using the same terminology for all CPU modes.

Cheers,
Adam
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by qw »

Okay, this is how I call things.

The logical address is the address you feed to the CPU. It consists of a segment address (in real and V86 mode) or selector (in protected mode) and an offset.
The physical address is the address sent over the address bus in order to access memory.

In between, some calculation is necessary.

The base address of a segment is calculated by multiplying the segment address with 16 (in real and V86 mode) or by fetching it from the descriptor (in protected mode).
The linear address is calculated by adding the offset to the base address.

Without paging (in real mode and possibly in protected mode) the linear address is the same as the physical address and no additional calculation is needed. Otherwise, the physical address is calculated from the linear address by page translation.

P.S.: I agree that it is just a matter of representation, that is why I call it logical addresses.
P.P.S.: In long mode things are a little different, because selectors are not used, with the possible exception of FS or GS.
User avatar
edfed
Member
Member
Posts: 42
Joined: Wed Apr 09, 2008 5:44 pm
Location: Mars

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by edfed »

some others uses ORG 600h

in my case, i use org 7C00h because it is the only value garanteed on all PCs.
after, i set ds=cs=?? depend on the bios you have...
ss= 5000h (5 for S)
es=0a000h or 0b800h (screen memory)
fs=09000h (frame buffer)
gs=0 or not initialised
.
welcome in my dream.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by qw »

edfed wrote:in my case, i use org 7C00h because it is the only value garanteed on all PCs.
The physical address is guaranteed yes, not the value of CS.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by Love4Boobies »

Instead of talking about addressing types (which I'm sure the OP can find in the Intel manuals) I'll get back to the original problem. Yes, I agree that there are BIOSes out there that pass execution control to 07C0:0000h instead of 0000:7C00h (which is the address defined by the BDA standard). BIOSes that do this are borked but you shouldn't have much problems with that anyway since all your jumps will probably be relative.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
edfed
Member
Member
Posts: 42
Joined: Wed Apr 09, 2008 5:44 pm
Location: Mars

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by edfed »

Love4Boobies wrote:you shouldn't have much problems with that anyway since all your jumps will probably be relative.
what happens in this case:

Code: Select all

org 7c00h
push cs
pop ds
jmp 0:there
there:
mov ax,[data]
...
data dw 0
??

it appears CS should be set to 0, otherwise this code cannot be properlly executed.
welcome in my dream.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by Love4Boobies »

And you've only proven my point. No sane programmer would write "JMP 0:start", they'll use relative jumps.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by JohnnyTheDon »

Love4Boobies wrote:And you've only proven my point. No sane programmer would write "JMP 0:start", they'll use relative jumps.
I personally think its better to know what cs is instead of just hoping that it doesn't cause any issues. And it certainly isn't insane.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by Love4Boobies »

What do you mean hoping? It's not like you don't know what code you're writing...
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by JohnnyTheDon »

Love4Boobies wrote:What do you mean hoping? It's not like you don't know what code you're writing...
Yes, but you don't know what code the BIOS manufactures are writing and you don't if you might have to use absolute jumps in the future. The only disadvantage of setting CS is that it takes up a few extra bytes, and it helps make your code more bios bug and future proof. It also helps if you're going to copy the bootsector to somewhere other than 0x7C00, because you can load your CS value straight into DS.
Even if all of this isn't necessary, you can't call it insane. I have it in my bootloader, and I am pretty sure others do as well. Also, as Brendan mentioned, BIOSes might actually view your bootsector as unbootable if you don't do it.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by Love4Boobies »

Well it's not insane, okay. But it doesn't really matter what BIOS code manufacturers provide since that can't possibly affect the way you jump around in your code. Also, I think you misunderstood Brendan, he gave another BIOS bug as an example showing how manufacturers can interpret things the wrong way. There's no reason why BIOS would check to see whether you play with CS or not - and it doesn't.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by JohnnyTheDon »

Brendan wrote: some old computers (maybe just old Compaqs) check that the first bytes in the sector correspond to a JMP instruction
And funky bios interupt/SMM code can mess up your day at any time. I'm not saying that bios code is typically so broken that it can't deal with inconsistent CS values, I'm saying its a possibility and there is no reason to sit on the tracks just because you're pretty sure a train isn't coming.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by Love4Boobies »

Neither SMM nor IRQs can't mess up your code in that way. Can you think of any example?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: [ORG 0x7C00] vs mov ax, 0x07C0 vs jmp 0x07C0:start

Post by JohnnyTheDon »

Love4Boobies wrote:Neither SMM nor IRQs can't mess up your code in that way.
Both (especially SMM) can do whatever they want when triggered, and both can make stupid assumptions about CS when handing rarely used bios functions.
Post Reply