开发者

Implement CPU extensions in a kernel module

I'm looking for information relating to implementing certain CPU extensions in a kernel module. I've found something related: http://www.mirrors.docunext.com/lxr/http/source/arch/mips/kernel/unaligned.c in fact, it's the only source code that I can find that is even close.

Basically, I have a binary only shared object built with certain CPU extensions, which I need to run on a slightly older CPU which ha开发者_运维问答s most of the instruction set, but not the fancy new stuff. Yeah, I know it'll be rather slow, but it's better than crashing with SIGILLs.


I think you can do this in userland. Install a handler for SIGILL with sigaction() and specify SA_SIGINFO. The field si_code in the siginfo_t allows distinguishing between several causes of SIGILL. For example, trying to emulate an instruction when the signal came from kill() does not make sense. The third argument to the handler points to a structure containing the CPU context at the time of the fault (see documentation). You can likely modify this and return from the signal handler, the changes taking effect; if that does not work, try setcontext().

Obviously, it will be a bit less efficient than doing it in the kernel, but cleaner and safer.


You can do this, but its slightly painful. The invalid opcodes need to be intercepted, so you either need to modify the existing illegal instruction handler, or wrap the handler, which is dirty and complicated.

If you want to avoid any kernel mods, but do as a pure kernel, the wrapped-exception approach is probably the only way to do it. If you can modify the kernel, the patched handler is better.


i don't think you can fix this problem using a kernel module. i think you either need to run this in a VM which allows the missing instructions (I would try using XEN) or recompile the object so that it doesn't use them.


Well, after reading the kernel source, it seems like there is already minor support for this. I really can't see how much it's actually used, but there exists a linked list to store the various emulated instructions. If I'm able to actually get this going, I'll probably change it to the kernel-header supplied tree.

If I'm understanding kernel modules right, there doesn't look like there would be an issue to support pluggable emulation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜