exception 0x11 in dosemu, with test case (fwd)

Alberto Vignani (alberto.vignani@torino.alpcom.it)
Sun, 21 Sep 1997 17:12:16 +0000 (GMT)


Hi.

My 80486 programming book says that to get exception 0x11

"The 80486 must be in user mode (CPL=3), the AC flag must be set, and the
AM (Alignment Mask, bit 18) bit in CR0 must be set".

And I suppose many DOS programs do not use AC to check for alignment, but
only to tell a 486 vs a 386 (Van Gilluwe, "The Undocumented PC", p.155,
says: "80386 test: bit 18...is changeable on the 486 and later CPUs").
Too bad sometimes they forget to restore the flag back, only because real
DOS doesn't care.

DPMI is just another linux process, but ill-behaved. I suppose no linux
process will ever set AC. Let's check what happens if it does, and
purposely accesses unaligned locations:

#include <stdio.h>

int fget(void)
{
int x;
__asm__ __volatile__ ("
pushfl
popl %0"
: "=g"(x) : :"memory");
return x;
}

int main(void)
{
int i, v;
char *p;
int *q;

/* set AC flag */
__asm__ __volatile__ ("
pushfl
pop %%eax
xor $0x40000,%%eax
pushl %%eax
popfl"
:
:
: "%eax");

i = 0;
p = (char *)&i;
for (;; i++) {
q = (int *)(p+(i&3));
/* expect a segfault here when i==1 */
v = *q;
printf("%08d %08lx\n",v,fget());
}
return 0;
}

I must conclude that bit 18 in CR0 is set. Nothing bad if the AC flag is
restricted to the DPMI task itself, but I fear it propagates to the dosemu
code too, which is not written with AC=1 in mind.

Alberto