Is it possible to make some privileged instructions (eg sti, cli) available via some Java's API?
Why not? (Or if it's is, could you give me some outline/basic idea of how this would be implemented?)
Thanks
Is it possible to make some privileged instructions (eg sti, cli) available via some Java's API?
Why not? (Or if it's is, could you give me some outline/basic idea of how this would be implemented?)
Thanks
STI and CLI are low-level platform dependent interrupts.
When you write source code in Java (the language), you are targeting the Java Virtual Machine, which executes Java bytecode. So your source code instructions are not directly translated to machine code for the physical machine. It is converted to bytecode that is then run (and also recompiled at runtime by the JIT compiler) to target your physical machine.
Therefore you don't have the option (as it wasn't really Java's design goal and it wouldn't make much sense to expose this) to easily use these privileged instructions. They are meant to be abstracted.
We use "higher-level" languages for a reason.
In a conventional Java implementation, your only option is to implement the code that executes the privileged instructions in a native method that you call using JNI or JNA. And it won't do you any good ... because the hardware / operating system will prevent the instructions from running. (You will get an illegal instruction trap ... and the program will be killed.)
Basically, if a regular Java application (or any other user-space application) could execute privileged instructions, it could trivially crash the operating system. That is a really bad idea.
In a bare-metal implementation of Java, it may be possible to execute privileged instructions via native code, or possibly by other means. (For instance, in JNode the native code compiler will replace certain "magic" method calls with privileged instructions ... under carefully controlled circumstances.)