Re: Wrote a tutorial covering long mode
Posted: Mon Apr 19, 2010 9:53 am
Addendum: I updated the wiki article.
And in 32-bit:
Regards,
Godlord.
I read your reply twice and I didn't find any actual questions, perhaps suggestions or corrections, but no actual questions.GDTR wrote:Hi there, few question about tutorial here
The way I actually do it is:GDTR wrote:After this part di points to 4096+16384, so we need to set it one more time: mov di, 0x1000Code: Select all
mov di, 0x1000 xor ax, ax mov cx, 16384 rep stosb ; Clear the memory.
Code: Select all
mov di, 0x1000
mov cr3, di
xor ax, ax
mov cx, 16384
rep stosb
mov edi, cr3
Code: Select all
mov edi, 0x1000
mov cr3, edi
xor eax, eax
mov ecx, 4096
rep stosd
mov edi, cr3
Actually you do for the next part.GDTR wrote:...and we dont need last add di, 0x1000Code: Select all
; Set the word at the destination index to 0x2003. mov WORD [di], 0x2003 ; Add 0x1000 to the destination index. add di, 0x1000 ; Set the word at the destination index to 0x3003. mov WORD [di], 0x3003 ; Add 0x1000 to the destination index. add di, 0x1000 ; Set the word at the destination index to 0x4003. mov WORD [di], 0x4003 ; Add 0x1000 to the destination index. add di, 0x1000
And this is the next part, where add di, 0x4000 should actually be gone.GDTR wrote:Next, we need to set di to 0x4000, not add 0x4000 to current value: mov di,0x4000Code: Select all
; Set the destination index to 0x4000. add di, 0x4000 ; Set the B-register to 0x00000003. mov ebx, 0x00000003 ; Set the C-register to 512. mov cx, 512
Actually, I'm not even assuming that. The code I wrote in my tutorial is generally 16-bit code instead of 32-bit code. That means that rep stosb doesn't use ecx but cx, hence why I never bothered using the ecx register instead.GDTR wrote:Last note. We assume that ecx and edi (their high part) is zero, but it not always true.
mb use edi, ecx insted? (or zero them at begining)
They are ignored and aren't ignored. The x86-64 architecture doesn't deal with "real" segmentation any longer, but the segment registers are still being used actually.GDTR wrote:UPD
AMD64 APM vol. 2, page 357
"- Data-segment descriptors for software running in compatibility mode. The DS, ES, and SS
segments are ignored in 64-bit mode. See “Data-Segment Descriptors” on page 87 for more
information."
Regards,
Godlord.