wiremod / wire-cpu

Legacy CPU/GPU/SPU as a separate addon.
Apache License 2.0
8 stars 6 forks source link

Privileged instructions can now be proxied by interrupt 13 #66

Closed DerelictDrone closed 1 week ago

DerelictDrone commented 3 weeks ago

Now upon executing a privileged instruction without being of the right runlevel, the interrupt will pass the privileged instruction's operands into PreqOperand1 and PreqOperand2, and certain instructions that needed to write to an operand can now retrieve a return value from PreqReturn.

Internal registers added: 71 = PreqOperand1 | in MOV R0,R1, this would hold R0 72 = PreqOperand2 | in MOV R0,R1, this would hold R1 73 = PreqReturn | The number to be returned, if the instruction needs one. 74 = PreqHandled | Whether or not this request was handled, is set to -1 on entering interrupt, if set to 1 then PreqReturn will be used if needed. As long as it's nonzero the privileged instruction is considered handled on return

Opcodes that will use PreqReturn: CPUGET RD GMAP (which I've also fixed in this PR)

Example use cases:

Overriding program's use of CPUGET, you could make a program that gets register 43(size of cpu internal memory) instead receive the size of the program's allotted memory(making it work without needing to recompile it to use a constant mem size)

Running previously privileged code without having to put it on runlevel 0, by handling specific instructions and ignoring others rather than flat out denying all.

Example code: (This divides the CPU's memory by 2 before returning it) image