flat assembler
Message board for the users of flat assembler.

Index > Main > 32bit/64bit

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 22 Apr 2009, 18:41
What's the instruction for switching between 32bit and 64bit mode?

I think my program can be faster by being able to work with 64bit registers/comparisons in some places, but I don't want to bloat it by making EVERYTHING use 64bit instructions. Confused





P.S. is there a way to do something like
Code:
cmp       dword[esi],("A","B","C","D")    
instead of
Code:
cmp        dword[esi],"A"+"B"shl 8+"C"shl 16+"D"shl 24    
?

It is very ugly the second way.. Sad
Post 22 Apr 2009, 18:41
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Apr 2009, 18:46
There is no such thing as an instruction to switch, there is a procedure required to do such a switch and in general no OS allows you to do it.

As for the PD: what about cmp dword [esi], "ABCD"?
Post 22 Apr 2009, 18:46
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 22 Apr 2009, 18:50
LocoDelAssembly wrote:
There is no such thing as an instruction to switch, there is a procedure required to do such a switch and in general no OS allows you to do it.
Why not?

LocoDelAssembly wrote:
As for the PD: what about cmp dword [esi], "dcba"?

Won't work for newline/carriage return/null/etc characters..
Post 22 Apr 2009, 18:50
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Apr 2009, 18:58
Quote:


Won't work for newline/carriage return/null/etc characters..

OK, no way then...

Quote:

Why not?


Because privileged instructions are required to do that and normally the OSes are protected mode, not real mode (like DOS).
Post 22 Apr 2009, 18:58
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 22 Apr 2009, 19:05
LocoDelAssembly wrote:
Azu wrote:
LocoDelAssembly wrote:
Azu wrote:
P.S. is there a way to do something like
Code:
cmp   dword[esi],("A","B","C","D")    
instead of
Code:
cmp        dword[esi],"A"+"B"shl 8+"C"shl 16+"D"shl 24    
?

It is very ugly the second way.. Sad
As for the PD: what about cmp dword [esi], "ABCD"?
Won't work for newline/carriage return/null/etc characters..
OK, no way then...
Drats!
Thanks anyways.

LocoDelAssembly wrote:
Azu wrote:
LocoDelAssembly wrote:
Azu wrote:
What's the instruction for switching between 32bit and 64bit mode?

I think my program can be faster by being able to work with 64bit registers/comparisons in some places, but I don't want to bloat it by making EVERYTHING use 64bit instructions. Confused
There is no such thing as an instruction to switch, there is a procedure required to do such a switch and in general no OS allows you to do it.
Why not?
Because privileged instructions are required to do that and normally the OSes are protected mode, not real mode (like DOS).
Why can't it be done in protected mode? Is there some kind of security/stablity problem in switching to 64bit execution?
Post 22 Apr 2009, 19:05
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 22 Apr 2009, 19:54
"64-bit execution" requires new 64-bit mode. Your question is similar to "why can't I use paging in real mode?". You can't because the feature is not there.
Post 22 Apr 2009, 19:54
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 22 Apr 2009, 19:57
So processes in protected mode can't be 64bit? They have to be real mode to?

Why?
Post 22 Apr 2009, 19:57
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20290
Location: In your JS exploiting you and your system
revolution 23 Apr 2009, 01:31
64bit is a whole different world from 32bit. Everything from the OS and drivers down to the apps have to know about it before you can start using 64bit code. The x86 architecture does not support on-the-fly instruction level selection of 64bit versions. It just doesn't work that way.
Post 23 Apr 2009, 01:31
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Apr 2009, 01:34
revolution wrote:
64bit is a whole different world from 32bit. Everything from the OS and drivers down to the apps have to know about it before you can start using 64bit code. The x86 architecture does not support on-the-fly instruction level selection of 64bit versions. It just doesn't work that way.
Isn't it just more/bigger registers and longer addressing?

Why would you need different drivers just to use it in some tight internal loop in your program for the extra registers?


From what the LocoDelAssembly said.. the instruction is there to do it? But user mode processes aren't allowed to use it? Why??? Confused


I don't want 100% 32bit program because the lack of registers makes it slow.. but I don't want 100% 64bit program because the 64bit addressing makes it big.. Question
I know the OS and drivers can handle either one.. so I really don't see what the problem is with switching between?
Post 23 Apr 2009, 01:34
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20290
Location: In your JS exploiting you and your system
revolution 23 Apr 2009, 01:44
Azu wrote:
Isn't it just more/bigger registers and longer addressing?
Kind of, but more than just that.
Azu wrote:
Why would you need different drivers just to use it in some tight internal loop in your program for the extra registers?
Drivers run in kernel mode, the kernel must run in 64bit mode, so everything needs to be 64bit.
Azu wrote:
From what the other guy said.. the instruction is there to do it? But user mode programs are blocked from this? Why??
There is no such instruction, and LocodelAssembly didn't say there was. There is a setting in the system control registers that needs to be changed and then you also have to set up to appropriate descriptor tables and a few other things. Anyhow, it is all explained in the Intel/AMD manuals. Download one of them and start reading. There is too much to say to explain it here in a forum.
Post 23 Apr 2009, 01:44
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Apr 2009, 01:47
revolution wrote:
Azu wrote:
Isn't it just more/bigger registers and longer addressing?
Kind of, but more than just that.
What else? o_o



revolution wrote:
Azu wrote:
Why would you need different drivers just to use it in some tight internal loop in your program for the extra registers?
Drivers run in kernel mode, the kernel must run in 64bit mode, so everything needs to be 64bit.
But.. I can make a 32bit OR a 64bit version of my program.. and either of them run right without changing anything else on my computer! I can even run both versions at the same time.


revolution wrote:
Azu wrote:
From what the other guy said.. the instruction is there to do it? But user mode programs are blocked from this? Why??
There is no such instruction, and LocodelAssembly didn't say there was. There is a setting in the system control registers that needs to be changed and then you also have to set up to appropriate descriptor tables and a few other things. Anyhow, it is all explained in the Intel/AMD manuals. Download one of them and start reading. There is too much to say to explain it here in a forum.
LocoDelAssembly wrote:
Because privileged instructions are required to do that and normally the OSes are protected mode, not real mode (like DOS).
I thought that meant there are instructions for it, but my program is just blocked from using them for some reason?

I understand switching from protected mode to real mode is blocked because you can do things in real mode you aren't supposed to.. but you can make your program be 32bit or 64bit using normal OS executable formats. You aren't gaining additional access by switching between them. So why is it restricted?
Post 23 Apr 2009, 01:47
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20290
Location: In your JS exploiting you and your system
revolution 23 Apr 2009, 01:54
Azu wrote:
What else? o_o
RTFM
Azu wrote:
But.. I can make a 32bit OR a 64bit version of my program.. and either of them run right without changing anything else on my computer! I can even run both versions at the same time.
So you are running a 64bit OS?
Azu wrote:
I thought that meant there are instructions for it, but my program is just blocked from using them for some reason?
No, there are instructions (mov cr0,reg etc.) for changing settings (and thus the mode) but your 32bit OS won't let you execute them. And even if you could execute them, then your 32bit OS would crash and burn.
Post 23 Apr 2009, 01:54
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Apr 2009, 01:59
revolution wrote:
Azu wrote:
What else? o_o
RTFM
I don't really care, was just trying to be polite and express curiosity since you said something about there being more to it.

revolution wrote:
Azu wrote:
But.. I can make a 32bit OR a 64bit version of my program.. and either of them run right without changing anything else on my computer! I can even run both versions at the same time.
Question Shocked You are a genius, no one else has been able to figure that out.
???
Lots have. Firefox for example. Go download the 32bit and 64bit versions and install them both. You can run them at the same time and visit the same website and nothing bad happens.


Quote:
Azu wrote:
I thought that meant there are instructions for it, but my program is just blocked from using them for some reason?
No, there are instructions (mov cr0,reg etc.) for changing settings (and thus the mode) but your 32bit OS won't let you execute them. And even if you could execute them, then your 32bit OS would crash and burn.
32bit operating systems still exist? Confused
I haven't used any in over half a decade...
Post 23 Apr 2009, 01:59
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20290
Location: In your JS exploiting you and your system
revolution 23 Apr 2009, 02:05
My mistake above, since most people are running 32bit OSes my natural assumption was that you are also. But never mind, since you are running a 64bit OS then you have noticed that you can run older 32bit apps. This is because in 64bit mode there are two sub modes, "native 64bit" and "compatibility". The OS will set everything up for 32bit apps to run in compatibility mode so that all the common apps still run. But you can't do that setup as a user space program.
Post 23 Apr 2009, 02:05
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Apr 2009, 02:21
revolution wrote:
My mistake above, since most people are running 32bit OSes my natural assumption was that you are also. But never mind, since you are running a 64bit OS then you have noticed that you can run older 32bit apps. This is because in 64bit mode there are two sub modes, "native 64bit" and "compatibility". The OS will set everything up for 32bit apps to run in compatibility mode so that all the common apps still run. But you can't do that setup as a user space program.
Thanks.

I'll go read through the 1000 page manual now and try to figure out how the OS does it. Maybe there is some trick to do it in user mode (even if for some reason I'm technically not supposed to) at least for raw ASM? Like if I change it back to 32bit mode before calling any APIs? Haven't found anything useful so far though ;/
Post 23 Apr 2009, 02:21
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20290
Location: In your JS exploiting you and your system
revolution 23 Apr 2009, 03:45
Code must be running in ring0 to change modes. It is not possible for a user space (ring3) program to do it. This is by design, not some arbitrary limitation. Your search for a "trick" will be in vain.
Post 23 Apr 2009, 03:45
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Apr 2009, 03:50
revolution wrote:
Code must be running in ring0 to change modes. It is not possible for a user space (ring3) program to do it. This is by design, not some arbitrary limitation. Your search for a "trick" will be in vain.
Why is changing between 32bit/64bit require ring0? If there is some kind of higher access that can be had in 64bit evil coders will just make it run 64bit to begin with, without changing..

If it's by design there IS a reason, right? And if not, there must be some way around it..
Post 23 Apr 2009, 03:50
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20290
Location: In your JS exploiting you and your system
revolution 23 Apr 2009, 04:04
Hmm, well the OS and drivers is supposed to be trusted code so we don't expect any "evil" code to be there. In a perfect world all "evil" code should be run in ring3 where no damage would be possible. Anyhow it is not really about "evil" code, it is more about reliability. Apps can crash and generally not run well and the OS can still survive without issue due to the ring0/ring3 separation mechanism. Changing modes is an OS function, user apps have no business in there due to the potential reliability issues.

Read some more about OSes in general and learn about kernels and drivers. When you add that knowledge to the x86 mode changing mechanism then you will see why this is necessary. But it is too much to explain here in a forum posting.
Post 23 Apr 2009, 04:04
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 23 Apr 2009, 04:07
revolution wrote:
Hmm, well the OS and drivers is supposed to be trusted code so we don't expect any "evil" code to be there. In a perfect world all "evil" code should be run in ring3 where no damage would be possible. Anyhow it is not really about "evil" code, it is more about reliability. Apps can crash and generally not run well and the OS can still survive without issue due to the ring0/ring3 separation mechanism. Changing modes is an OS function, user apps have no business in there due to the potential reliability issues.

Read some more about OSes in general and learn about kernels and drivers. When you add that knowledge to the x86 mode changing mechanism then you will see why this is necessary. But it is too much to explain here in a forum posting.
If the app can choose at startup which mode to run in, and this is safe to the OS, shouldn't it also be safe to set it in runtime? I think anything that is safe to be set at compile time should also be safe to set in runtime. Or am I misunderstanding something again (wouldn't be the first time lol)? Confused
Post 23 Apr 2009, 04:07
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20290
Location: In your JS exploiting you and your system
revolution 23 Apr 2009, 04:17
Azu wrote:
Or am I misunderstanding something again (wouldn't be the first time lol)? Confused
Yes, you are. Unfortunately you have not read about any of the things I suggested. They can answer your questions much better than I can. But, in short, changing modes is a major undertaking, the OS will do it only sparingly. It is not simply one instruction to change modes, it is a whole procedure that has to be followed.
Post 23 Apr 2009, 04:17
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.