I’ve a piece of driver code, i am trying to upgrade an exiting x86 WDM driver to a Windows x64 system using compiler intrinsic functions. I am using the WDK 7600.16385.0 for the build process. The 32 bit version of the driver had some inline assembly code to implement the saving the cpu state at a particular instance. i.e
saving cpu registers they are
- segment registers (cs,ds,es,fs, gs,ss), (mov instruction used to get register values)
- data registers (esi,edi), (mov instruction used to get register values)
- control registers(cro,cr2,cr3,cr4), (found intrinsic function)
- descriptor tables (sgdt, sldt, sidt, str), (sgdt sldt sidt str instructions used)
- flags register, (found intrinsic function)
- stack info (esp, ebp) (mov instruction used to get register values)etc.
I could write intrinsic function for some of them as I explained above.
Is there any way to store the cpu state using any intrinsic function?
Are there any equivalent intrinsic functions are there for following instructions
ltr, push,pop,pushad, popad, stgi opcode??
if anyone are having any idea regarding porting the inline assembly code to x64 system please help me out.
Here I am adding some code FYI
saveCPUState()
{
/* EFER */
myefer = (unsigned long)__readmsr(EFER_MSR);
/* eflags */
myeflags = __readeflags();
/* descriptor tables */
__asm {
sgdt mygdt_limit
sidt myidt_limit
sldt myldt
str mytr
}
/* segment registers */
__asm {
mov mycs, cs
mov myds, ds
mov myes, es
mov myfs, fs
mov mygs, gs
mov myss, ss
}
/* control registers */
mycr0 = __readcr0();
mycr2 = __readcr2();
mycr3 = __readcr3();
mycr4 = __readcr4();
/* data registers */
__asm {
mov myesi, esi
mov myedi, edi
}
/* stack info - not necessary here, but interesting to get rough idea of stack layout for this driver */
__asm {
mov myebp, ebp
mov myesp, esp
}
}
__asm {
ltr isk_state.tr
}
// STGI opcode: 0x0f01dc
__asm {
__emit 0x0f
__emit 0x01
__emit 0xdc
}
Thanks in advance…