flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > RDTSCP instruction missing (and 64 bit problems)

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17338
Location: In your JS exploiting you and your system
revolution
Code:
        use64
        rdtscp                  ;<--_Error: illegal instruction (Encoding: 0F 01 F9)
        mov     rax,cr8         ;Ok
        mov     rax,cr9         ;<--_Error: undefined symbol
        mov     rax,cr10        ;<--_Error: undefined symbol
        mov     rax,cr11        ;<--_Error: undefined symbol
        mov     rax,cr12        ;<--_Error: undefined symbol
        mov     rax,cr13        ;<--_Error: undefined symbol
        mov     rax,cr14        ;<--_Error: undefined symbol
        mov     rax,cr15        ;<--_Error: undefined symbol
        mov     rax,dr8         ;Ok
        mov     rax,dr9         ;Ok
        mov     rax,dr10        ;Ok
        mov     rax,dr11        ;Ok
        mov     rax,dr12        ;Ok
        mov     rax,dr13        ;Ok
        mov     rax,dr14        ;Ok
        mov     rax,dr15        ;Ok
        mov     rax,[cs:rbx]    ;<--_generates unnecessary CS: override 2Eh
        mov     rax,[ds:rbx]    ;Ok
        mov     rax,[es:rbx]    ;<--_generates unnecessary ES: override 26h
        mov     rax,[ss:rbx]    ;<--_generates unnecessary SS: override 36h    
Post 05 Sep 2005, 03:27
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
I haven't included CR9-CR15, because I haven't found their existence documented, but I will include them for completness, OK. RDTSCP is perhaps something from the latest documentation updates? My old printed manuals don't mention it. As for the segment prefixes optimizations, I considered them while designing x86-64 support, however I decided they shouldn't be there - making assembler remove the ES: setting for you might make you think that it is the same as DS:, while the ES prefix is simply ignored, no matter what descriptor it points to. So I decided to leave it to programmer. The other solution might be to make usage of those prefixes illegal in long mode, but in such case I shouldn't also add the CR9-CR15 registers for example, since those opcodes are also illegal.
Post 05 Sep 2005, 09:16
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17338
Location: In your JS exploiting you and your system
revolution
The AMD manual "AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions" 24594 Rev. 3.10 February 2005 page 406 Table A-14 show all the CRx and DRx listed completely up to number 15.

Quote:
making assembler remove the ES: setting for you might make you think that it is the same as DS:
As for the prefixes: ES *IS* the same as DS (and CS, SS) in use64 mode. Sometimes a macro or EQUate will have a segment register that can be optimised out of the instruction stream at compile time in 64 bit mode and inserted in 32 bit mode. It just seems a little wastful to keep a redundant prefix in the code. Making the prefixes illegal is not necessary.
Post 05 Sep 2005, 09:36
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
ES prefix is ignored so you end up using standard addressing space. But the selectors and descriptors pointed to by DS and ES can be different (even though ignored), thus I felt it's better to leave it to programmer to realize what is he doing - he just shouldn't use any such segment overrides in long mode.

As for the manuals - yes, there have been some updates to the printed ones I have, including RDTSCP instruction, I had to download the new PDF version.
Post 05 Sep 2005, 09:57
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17338
Location: In your JS exploiting you and your system
revolution
I downloaded the latest version of 1.64 (5 September 2005). I'm having a problem with programming CR8. The REX prefix is missing from the generated code.
Code:
 use64
 mov cr8,rax  ; <-- Missing REX prefix
 mov cr9,rax  ; <-- Missing REX prefix
 mov cr10,rax ; <-- Missing REX prefix
 mov cr11,rax ; <-- Missing REX prefix
 mov cr12,rax ; <-- Missing REX prefix
 mov cr13,rax ; <-- Missing REX prefix
 mov cr14,rax ; <-- Missing REX prefix
 mov cr15,rax ; <-- Missing REX prefix
 mov dr8,rax  ; <-- Missing REX prefix
 mov dr9,rax  ; <-- Missing REX prefix
 mov dr10,rax ; <-- Missing REX prefix
 mov dr11,rax ; <-- Missing REX prefix
 mov dr12,rax ; <-- Missing REX prefix
 mov dr13,rax ; <-- Missing REX prefix
 mov dr14,rax ; <-- Missing REX prefix
 mov dr15,rax ; <-- Missing REX prefix    
Quote:
he just shouldn't use any such segment overrides in long mode
Okay, fair enough, then you might want to also include the DS override if it is specified. By not including DS but including the other ES, CS and SS makes the generated code little bit inconsistent. All four DS, ES, CS and SS have no special meaning on long mode but DS (and I am guessing SS when RBP is used) *IS* being treated specially.
Post 06 Sep 2005, 02:26
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
Sorry, I have not much time for assembly now and the updates were a bit in a hurry.

The code generation just retains the consistency of the compatibility modes (classic ones, note the SS:BP etc.), to keep it as much compatible and predictable as possible. The ignoring of some of the segment prefixes in long mode I treat more like an execution specifics of long mode rather than instruction encoding specifics - like the division by zero or something like that.
Post 06 Sep 2005, 08:47
View user's profile Send private message Visit poster's website Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
Tomasz Grysztar wrote:
Sorry, I have not much time for assembly now ....

Cool
Post 06 Sep 2005, 18:00
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.