"mov rdi,0x000B8000" (was: What does your OS look like?)

Programming, for all ages and all languages.
Post Reply
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

"mov rdi,0x000B8000" (was: What does your OS look like?)

Post by jal »

ReturnInfinity wrote:It was later changed to this:

Code: Select all

	mov rdi, 0x00000000000B8000
	mov rax, 0x0720075507500743	; 'CPU '
	stosq
Wouldn't there be a shorter way (in bytes) to assign b8000 to rdi? Like first xor-ing rdi, then assigning it to edi? or to di, then shifting, or whatever?


JAL
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: What does your OS look like? (Screen Shots..)

Post by IanSeyler »

jal wrote:
ReturnInfinity wrote:It was later changed to this:

Code: Select all

	mov rdi, 0x00000000000B8000
	mov rax, 0x0720075507500743	; 'CPU '
	stosq
Wouldn't there be a shorter way (in bytes) to assign b8000 to rdi? Like first xor-ing rdi, then assigning it to edi? or to di, then shifting, or whatever?


JAL
Yes. The above code is 10 bytes. The below code is 7 bytes. DI with a shift is 9 bytes.

Code: Select all

	xor edi, edi			; Automatically clears the high 32 bits as well
	mov edi, 0x000B8000
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: What does your OS look like? (Screen Shots..)

Post by Firestryke31 »

For some reason I am under the impression that a simple mov edi, 0x000B8000 would also clear the high half of rdi. It's probably me misremembering something I read here, though.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Selenic
Member
Member
Posts: 123
Joined: Sat Jan 23, 2010 2:56 pm

Re: What does your OS look like? (Screen Shots..)

Post by Selenic »

Firestryke31 wrote:For some reason I am under the impression that a simple mov edi, 0x000B8000 would also clear the high half of rdi. It's probably me misremembering something I read here, though.
No, that's what happens. It was included by AMD when designing long mode in order to reduce partial register dependencies, I think (but 8- and 16-bit ones don't clear anything, for backwards-compatibility reasons)
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: What does your OS look like? (Screen Shots..)

Post by IanSeyler »

I verified it in the latest version of bochs. "mov edi, 0x000b8000" clears the higher 32-bits. I was unsure if the mov instruction did that but now I know.
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: What does your OS look like? (Screen Shots..)

Post by Love4Boobies »

At the price of using an extra register,

Code: Select all

xor ebx, ebx
mov bh, 0b8h
mov edi, ebx
results in 6 bytes (if you really must use RDI :-)).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: What does your OS look like? (Screen Shots..)

Post by Firestryke31 »

except that makes edi 0x0000B800, not 0x000B8000 (it's shifted down a nibble for those too lazy to count digits).
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: What does your OS look like? (Screen Shots..)

Post by Gigasoft »

And mov edi,0b8000h is only 5 bytes anyway.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: What does your OS look like? (Screen Shots..)

Post by Love4Boobies »

Though that doesn't clear the high dword so it doesn't work.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: "mov rdi,0x000B8000" (was: What does your OS look like?)

Post by Firestryke31 »

Love4Boobies wrote:Though that doesn't clear the high dword so it doesn't work.
ReturnInfinity wrote:I verified it in the latest version of bochs. "mov edi, 0x000b8000" clears the higher 32-bits.
It seems as though it actually does.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: What does your OS look like? (Screen Shots..)

Post by Brendan »

Hi,

The instruction "mov rdi, 0x00000000000B8000" should be assembled into whatever opcode the assembler thinks is best. Unfortunately the optimisers in most assemblers aren't very good, so...

"mov rdi, 0x00000000000B8000" = 10 bytes

"mov edi, 0x000B8000" = 5 bytes and does exactly the same thing (the CPU does clear the high dword)

"xor ebx, ebx; mov bh, 0b8h; mov edi, ebx" = wrong/buggy (0x0000B800 != 0x000B8000)

mov rdi,[address_of_video_memory] = 8 bytes for the instruction plus 8 bytes of data; and even though it's longer and slower it's the correct way of doing it (because it won't break later when you decide to use a double buffer, or when you start using VBE and LFB for setting a text mode, or when you're using graphics mode with a buffer in RAM for "legacy" stuff). ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: "mov rdi,0x000B8000" (was: What does your OS look like?)

Post by Love4Boobies »

Brendan wrote:"xor ebx, ebx; mov bh, 0b8h; mov edi, ebx" = wrong/buggy (0x0000B800 != 0x000B8000)
Yes, we've been through that, I didn't notice the address, sue me! :lol:
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: "mov rdi,0x000B8000" (was: What does your OS look like?)

Post by jal »

Just because I'm a lazy bum who's never dabbled in 64 bit before: is the high dword of rXX cleared or is it sign extended? I'd expect the latter.


JAL
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: "mov rdi,0x000B8000" (was: What does your OS look like?)

Post by Gigasoft »

The high dword is always cleared.
Post Reply