flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > SMSW: deprecated or not ? privileged or not ? PG useful ???

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1904

SMSW: deprecated or not ? privileged or not ? PG useful ???

Well, it seems that SMSW and MOVing out from CR0 do exactly the same
thing ... but MOV is privileged and SMSW ist't Sad

Is this true ? Question

Seems to be a criminal design bug of 80386 Sad

I have seen cca 20 manuals and 10 of them imply SMWS is privileged and
the other 10 state the opposite Sad

Also, most of them consider SMSW as "highly deprecated", to be used on
80286 only ... but I found it in all DPMI kernels I've seen so far (+ MODES.INC) Confused

The thing returns always (mostly) $8000'0031 - "PG" bit is set, even if
no swapfile present - most manuals wrong again ? Is the bit useful at all ?
Is there a good way to test for presence of a swapfile except by
performance measure (swapping always has a horrrible one Laughing ) ?

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 02 Apr 2007, 06:08
View user's profile Send private message Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151

> but MOV is privileged and SMSW ist't

yes

> Seems to be a criminal design bug of 80386

yes

> The thing returns always (mostly) $8000'0031 - "PG" bit is set

SMSW copies a WORD only, the HiWord of the register is not affected.
use debug.com to verify! Smile)
Post 02 Apr 2007, 06:39
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 953
Location: Czechoslovakia

Re: SMSW: deprecated or not ? privileged or not ? PG useful


NTOSKRNL_VXE wrote:
Well, it seems that SMSW and MOVing out from CR0 do exactly the same
thing ... but MOV is privileged and SMSW ist't Sad


Probably do, but you can't never be 100% sure. Intel manual says "when the destination operand is a 32-bit register, the low-order 16 bits of register CR0 are copied into the low-order 16 bits of the register and the high-order 16 bits are undefined.", AMD says "SMSW reg32: Store the low 32 bits of CR0 to a 32-bit register." However, Intel probably copies whole CR0 in this case too.

NTOSKRNL_VXE wrote:
Seems to be a criminal design bug of 80386 Sad


Only in case you're sure it works...

NTOSKRNL_VXE wrote:

I have seen cca 20 manuals and 10 of them imply SMWS is privileged and
the other 10 state the opposite Sad
Also, most of them consider SMSW as "highly deprecated", to be used on
80286 only ... but I found it in all DPMI kernels I've seen so far (+ MODES.INC) Confused


Why don't you use the official manuals at the first place? Intel manual says "it is not a privileged instruction and can be used in application programs", AMD says "This instruction can be used at any privilege level".

NTOSKRNL_VXE wrote:
The thing returns always (mostly) $8000'0031 - "PG" bit is set, even if
no swapfile present - most manuals wrong again ? Is the bit useful at all ?
Is there a good way to test for presence of a swapfile except by
performance measure (swapping always has a horrrible one Laughing ) ?


Swap file (paging file) has nothing with the paging mechanism itself. For instance, I run win xp with no paging file.

Japheth wrote:

SMSW copies a WORD only, the HiWord of the register is not affected.
use debug.com to verify!


It works as described in the manuals for me - high word is always affected (OllyDbg always returns 8001003B, Turbo Debugger 80010031 for me).
Post 02 Apr 2007, 08:48
View user's profile Send private message Visit poster's website Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151

> It works as described in the manuals for me - high word is always affected
> (OllyDbg always returns 8001003B, Turbo Debugger 80010031 for me).

apparently it depends. In 16-bit code AX is affected, in 32-bit code it is EAX. With prefix 66h one may switch (refering to "SMSW AX". Some assemblers don't accept EAX or ignore the 'E').
Post 02 Apr 2007, 10:49
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904

SMSW

Thanks.


Quote:
In 16-bit code AX is affected, in 32-bit code it is EAX. With prefix 66h one may switch (refering to "SMSW AX". Some assemblers don't accept EAX or ignore the 'E').



Seems that FASM accepts SMSW EAX and returns the same as
MOV EAX,CR0 ... unsurprisingly, MOV works under HDPMI32 while
under CWSDPMI it runs into a GPF Laughing

Some texts imply SMSW EAX works on all CPU's except Cyrix
(again Embarassed ... UnrealMode, fool SB "emulation", ...) ... but since the upper
16 bits contain nothing except the PG bit which is always 1 in PM, there
is no need for SMSW EAX anyway Laughing


Quote:
Swap file (paging file) has nothing with the paging mechanism itself. For instance, I run win xp with no paging file.



Too many texts around spreading confusion or garbage Sad

It there any use of PM without paging at all ?

What does this paging mean instead ? That I can have holes in
RAM ? Can allocate and use RAM at $C0000000 (3 GB) although I have
only 64 MB installed ?

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 02 Apr 2007, 20:41
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6825
Location: Kraków, Poland

Re: SMSW


NTOSKRNL_VXE wrote:
Too many texts around spreading confusion or garbage Sad


Read directly from the source - Intel manuals; they do not spread too much confusion.
The paging mechanism is a mapping the linear addresses into physical ones. When paging is off, the linear address (the one you access, for example in "mov eax,[80000h]" you use linear address 80000h) is the same as physical address. With paging enabled you can map linear addresses into physical ones in various manners - each page (one page is 1000h byte with original 80386 paging) of linear address space can be mapped into any page in physical memory. You can also mark some pages as not present, so they will trigger an exception when some intruction tries to access that area - you can then handle that exception in order to make this area of memory available (useful for swap file, but also - for instance - to emulate linear framebuffer with banked VESA mode).

As for the SMSW - it's very useful because of being unprivileged and for this reason MODES.INC uses it instead of "mov eax,cr0" - this is done to avoid protection triggering in Win 3.x and Win95 (the last one would display a message box asking whether you want to execute the program in DOS mode when a privileged instruction like "mov eax,cr0" is executed) - with SMSW your check for protected mode can go unnoticed.
Post 03 Apr 2007, 07:02
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904

paging

Thanks.


Quote:
Read directly from the source - Intel manuals



OK, but where to find the good ones ?

- A manual for 80386
- A manual for P2 (simplest one with MMX/RDMSR/WRMSR/MTTRR)

The newest "source" manuals getting linked from here contain 80% 64-bit stuff Sad


Quote:
useful for swap file, but also - for instance - to emulate linear framebuffer with banked VESA mode



Interesting hack Laughing

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 04 Apr 2007, 00:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7109
Location: Slovakia


Quote:
OK, but where to find the good ones ?

Try writing PM to MazeGen, he may have them
Post 04 Apr 2007, 00:56
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 953
Location: Czechoslovakia

Well, I always use the newest Intel and AMD manuals... Don't know what are the "good" ones. And yes, I own an archive of them.

BTW, there's nothing like deprecated instruction. An instruction is either supported or not. There are only a few old system instructions which are signed obsolete and which don't work anymore (because of changes to the processor's internal architecture), but that's surely not the case of SMSW.
Post 04 Apr 2007, 07:23
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6825
Location: Kraków, Poland

Re: paging


NTOSKRNL_VXE wrote:
OK, but where to find the good ones ?


Here was posted the 80386 manual in a text file form - this is actually the one I learned protected mode from.


NTOSKRNL_VXE wrote:

Quote:
useful for swap file, but also - for instance - to emulate linear framebuffer with banked VESA mode



Interesting hack Laughing


DirectX was doing it on very old graphic cards, as I recall from Win95.
Post 04 Apr 2007, 07:30
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904

manuals

Tomasz wrote:


Quote:
Here was posted the 80386 manual in a text file form - this is actually the one I learned protected mode from



Thanks. TXT is ZIPped, but compressed with Deflate64, no standard ZIP Sad

Maybe recompress with KZIP and re-upload ?

MazeGen wrote:


Quote:
Well, I always use the newest Intel and AMD manuals... Don't know what are the "good" ones.



Well, as written above, one for 80386 (as Tomasz pointed), and one for
P1/P2, with MMX, MSR/MTRR, I/O debug, but without 64-bit and SSSSE stuff


Quote:
yes, I own an archive of them.



Could you upload such a P2 manual please ?

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 13 Apr 2007, 00:01
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2279
Location: Usono (aka, USA)

FYI, Info-ZIP has supported unpacking Deflate64 since a fairly long while, I think (just tried it on 5.52, worked correctly), and it's free, extremely portable, good, etc., so Razz ...

For a plain-text Pentium manual (XADD, CPUID, PACKUSWB, CMOVE, etc.), try ftp://ftp.sac.sk/pub/sac/text/pentium3.zip or search Alexei Frounze's page here (specifically under Optimization).
Post 24 May 2007, 07:32
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:  


< 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


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.