Page 1 of 1

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

Posted: Fri Apr 16, 2010 8:53 am
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

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

Posted: Fri Apr 16, 2010 9:31 am
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

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

Posted: Fri Apr 16, 2010 9:49 am
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.

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

Posted: Fri Apr 16, 2010 10:10 am
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)

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

Posted: Fri Apr 16, 2010 10:14 am
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.

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

Posted: Fri Apr 16, 2010 10:24 am
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 :-)).

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

Posted: Fri Apr 16, 2010 2:33 pm
by Firestryke31
except that makes edi 0x0000B800, not 0x000B8000 (it's shifted down a nibble for those too lazy to count digits).

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

Posted: Fri Apr 16, 2010 6:02 pm
by Gigasoft
And mov edi,0b8000h is only 5 bytes anyway.

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

Posted: Fri Apr 16, 2010 6:31 pm
by Love4Boobies
Though that doesn't clear the high dword so it doesn't work.

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

Posted: Fri Apr 16, 2010 10:56 pm
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.

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

Posted: Fri Apr 16, 2010 10:59 pm
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

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

Posted: Sat Apr 17, 2010 12:06 am
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:

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

Posted: Sat Apr 17, 2010 1:57 pm
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

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

Posted: Sat Apr 17, 2010 3:02 pm
by Gigasoft
The high dword is always cleared.