[SOLVED] Switching to x86 mode by iretq doesnt work

Status
Not open for further replies.

FGEOM

New member
Joined
Sep 13, 2023
Posts
4
Hello Exoerts!
I have some problem with switching to x86 mode in my driver.
I use command iretq to jump to another segment. Right after jump I get needed value fo CS and SS registers, but next instruction reverts back my segments to x64 mode (0x10 and 0x18).
What could be a reason?
Here is my code:
push 38h
push rdx
pushfq
push 8h
push rcx
iretq

Thanks in advance!
With respect, Eugene.
 
I need to call some function, which is in segment 0x20 (x86).

"The CS and SS registers are both restored to what they originally were when you use iretq" - but I CS and SS are overtaken from stack. So, you mean, these registers are overtaken from stack and after it they are overwritten by saved values before ISR?
 
Look at my code, please.
I prepared stack in a way, when iretq restores CS and SS from stack to defined values.

push 38h
push rdx
pushfq
push 8h
push rcx
iretq

SS = 38h
CS = 08h
 
You've just posted the exact same thing, what are you actually trying to do? You haven't mentioned what operating system you're writing this apparent ISR for, what processor you're intending to target nor why you're trying to manually set the CS and SS registers which is something you should not be doing. Segmentation is pretty much redundant on Windows, it sort of just exists in the background for legacy reasons.

I would strongly recommend that you create a thread on the OS Dev forums or Stack Overflow because you're likely to get a better answer there.
 
Hello BlueRobot,
It is Windows 10 x64, Intel CPU i3. My target is to call 32-bit compiled function from x64 bit environment. So, I need to switch CPU from Long mode to Compatibility mode. From manual of Intel, this switch is organized on segments based. Every segment has it's descriptor which contain several bits to configure the mode of CPU. So, I have to jump CS segment value.

If you have any other advice how to call 32bit function, except manual configure segments, you are welcome)

In any way, thank you a lot for response.

I have asked also this question on Stack Overflow and on community.osr.com .

With respect, Eugene.
 
Hello BlueRobot,
It is Windows 10 x64, Intel CPU i3. My target is to call 32-bit compiled function from x64 bit environment. So, I need to switch CPU from Long mode to Compatibility mode. From manual of Intel, this switch is organized on segments based. Every segment has it's descriptor which contain several bits to configure the mode of CPU. So, I have to jump CS segment value.

If you have any other advice how to call 32bit function, except manual configure segments, you are welcome)

In any way, thank you a lot for response.

I have asked also this question on Stack Overflow and on community.osr.com .

With respect, Eugene.
FGEOM try exetools and tutsforyou and maybe binrev and MDL. What you're trying to do is a little known method and works and should probably keep it in the community before it gets abused enough to make a heuristics trigger.
 
Status
Not open for further replies.

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top