You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Macro to indicate a specific function to the linker as the first in the link order
88
+
#defineCODE_BEGIN code_seg(push, ".text")
89
+
90
+
// Macro to indicate the end of the specific function to the linker
91
+
#defineCODE_END code_seg(pop)
92
+
93
+
// Macro to disable all compiler optimizations for a specific function
94
+
#defineOPTIMIZATION_OFF optimize("", off)
95
+
96
+
// Macro to re-enable/reset compiler optimizations for a specific function
97
+
#defineOPTIMIZATION_ON optimize("", on)
98
+
99
+
// Macro to enable compiler optimizations for generating short sequences of machine code for a specific function
100
+
#if defined(_M_IX86)
101
+
#defineOPTIMIZATION_SIZE optimize("gsy", on)
102
+
#else
103
+
#defineOPTIMIZATION_SIZE optimize("gs", on)
104
+
#endif
105
+
106
+
// Macro to enable compiler optimizations for generating fast sequences of machine code for a specific function
107
+
#if defined(_M_IX86)
108
+
#defineOPTIMIZATION_SPEED optimize("gty", on)
109
+
#else
110
+
#defineOPTIMIZATION_SPEED optimize("gt", on)
111
+
#endif
112
+
113
+
// Macro to fill a block of memory with zeroes given it's address and length in bytes by generating store string instruction(rep stosb)
114
+
// Enhanced REP STOSB/MOVSB(ERMSB) are only available since Ivy Bridge Intel microarchitecture(2012/2013)
115
+
// Processors that provide support for enhanced MOVSB/STOSB operations are enumerated by the CPUID feature flag: CPUID:(EAX=7H, ECX=0H):EBX.ERMSB[bit 9] = 1
// Macro to copy a block of memory given it's source address, destination address and the number of bytes to copy by generating move string instruction(rep movsb)
- Sample code that demonstrates the usage of the `SMSW` instruction to fetch the the `Machine Status Word` (bits 0 through 15 of control register `CR0`) and check if the processor is running in `Protected` mode.
14
+
15
+
## Usage
16
+
- There aren't a lot of useful bits in the `MSW`
17
+
- One notable exception: `PE (Protection Enable)` bit (0)
18
+
- This flag enables Segmentation
19
+
- Under normal circumstances, the sample code will always inform that `CR0.PE` bit is set
20
+
- Only useful for low-level code such as `OS` and `Hypervisors`
21
+
- Another possible use might be for `VM` detection but more testing is needed
0 commit comments