whartung wrote:
BigDumbDinosaur wrote:
The main value in using COP for API calls is nothing special has to be done to call an API from another bank. All of that is handled for you due to COP being just another interrupt.
Is the problem that the caller simply doesn't have to distinguish between JSR and JSL?
That's part of it. The API backend also has to distinguish between the two, since the return from JSL (RTL) has to pull one more byte from the stack than does RTS. Also consider that JSL is a four-byte instruction, whereas COP is a two-byte instruction. Furthermore, if one has to JSL to an API then it is implied the kernel must be loaded to an immutable location.
Contrary to one might think, using JSL to call an API function confers no performance advantage over COP—both instructions require eight clock cycles to execute. Use of COP automatically pushes SR to the stack, which may be important in an API call from which some sort of "error" status is to be returned (usually via the carry bit). However, in native mode, RTL is one clock cycle faster than the RTI needed to return following an interrupt. On the other hand, since RTI automatically restores SR, the two cycles that would be required to "manually" pull SR as part of a JSL/RTL return are avoided.
COP also offers the possibility of a change in machine state when an OS API is called. During cycles 7 and 8 of COP, the 65C816's VPB output is driven low to indicate an interrupt vector is being fetched. This same signal could be used to switch the hardware protection, if present, from user to kernel mode. How would you do this if the API is called via JSL, especially when you consider the fact that the kernel address space should be protected from user-space accesses?