
Wanted: Unaligned access exceptions
|> I am developping programs that are not only used on PCs, so I would
|> like to have unaligned accesses reported. The 486 can generate
|> exceptions for unaligned accesses if a certain bit in a status
|> register is set. Linux (at least 1.0 which I have) does not execute my
|> binary with these exceptions turned on. Is there a program that lets
|> me run binaries with these exceptions?
Thanks to Al Longyear and Alan Cox for their helpful comments.
The 486 has two bits: AC in the EFLAGS register turns alignment faults
on or off for privilege level 3 (i.e. user code). The AM flag in the
CR0 register controls whether the AC flag is working or is ignored
(i.e. no alignment faults, like on the 386).
Linux sets the AM flag on booting (i.e. the AC flag will be
heeded). The AC flag can be set by user code, which is the basis for
the solution. The line
__asm__("pushfl; popl %eax; orl $0x40000,%eax; pushl %eax; popfl;");
sets the AC bit. I put it at the start of the program I want to check,
i.e.,
#ifdef i386
__asm__("pushfl; popl %eax; orl $0x40000,%eax; pushl %eax; popfl;");
#endif
This should not have any adverse effect on the 386 (which does not
have an AC flag), but I have no 386 to check this.
Al Longyear also suggested changing kernel/fork.c to set the AC bit
(this would set it for all user processes) by changing
p->tss.eflags = regs.eflags & 0xffffcfff; /* iopl is always 0 for a new process */
to
p->tss.eflags = (regs.eflags & 0xffffcfff) | 0x40000; /* iopl is always 0 for a new process and send AC */
I tried this, but it did not have any noticable effect.
- anton
--
M. Anton Ertl Some things have to be seen to be believed
an...@mips.complang.tuwien.ac.at Most things have to be believed to be seen