I am trying to write a kernel module in C to bring the system in the hypervisor mode. The module is for a router, which is running OpenWrt. The architecture is ARMv7.
When I load my module with insmod I get this error when the module comes to the hvc #0 instruction:
Internal Error: Oops - undefined instruction: 0 [#1] SMP ARM
I am new to ARM and virtualization but so far I have understood that I have to do the following things before calling hvc #0
I have to be in PL1(SVC) mode. Is this given when I load a kernel module instead of a normal C Program?
I have to set the SCR.NS bit to 1.
I have to set the SCR.HCE bit to 1.
I have not understood how to set these bits. I have read that the CPU needs to be in monitor mode for setting these bits, is this true? And how can I do this?
Can someone give me please an example in C or assembly how to prepare the system that I can execute hvc #0.
Yes - you must be in Secure state to write the SCR. Basically you can't do this from kernel code. It needs to be initialized in firmware (or some code with Secure privilege). The core will reset/boot in Secure state & firmware will generally run at the highest level of privilige