PC Stack and PC Shadow Stack, PushPC Secret instruction???
dkemppai
Posts: 315
OK, I'm trying to sort out a few ideas.
Are·the PC Shadow Stack (accessed via the secret instructions) and normal PC stack different?·I find references·on·www.sxlist.com·that says the·PC Shadow·stack used by PushPC·is 2·levels deep, while the SK-Key·Manual makes reference to the PC Stack being 8 levels deep (with the stack extended).
If I·pushPC ($04B) the contents to M and W to the stack, is this the same stack as used by the interrupt call instructions? Are they different? Any implications of me using PushPC and possible gotcha's you guys are aware of.
Thanks,
Dan
Are·the PC Shadow Stack (accessed via the secret instructions) and normal PC stack different?·I find references·on·www.sxlist.com·that says the·PC Shadow·stack used by PushPC·is 2·levels deep, while the SK-Key·Manual makes reference to the PC Stack being 8 levels deep (with the stack extended).
If I·pushPC ($04B) the contents to M and W to the stack, is this the same stack as used by the interrupt call instructions? Are they different? Any implications of me using PushPC and possible gotcha's you guys are aware of.
Thanks,
Dan
Comments
Here is what I was up to.
I was trying to write a psudo call routine to be used in the upper half of a page of memory. I have a routine that needs to be called, and then calls additional routines multiple times (all residing in the upper half of the page). Because of the size of my program, the program overflows into the upper half of the page and will not work. The solution is to segregrate code into the upper half of the page.·The·standard call routines won't work. I can't use a jump table, because I need to call routines in the upper half of the page from other routines existing in the upper half of the page.
With a few extra instructions, one can effectivley use the 'Secret instructions' and RETI to 'call' and 'return' from sub routines in the upper half of a page. I'm certian that this could be expanded to include calls to and from anywhere, with a few extra bytes of memory/instructions per routine.·Another possibility is to not use the JMPLOC variable, by replacing it with a PushW, PopW...··
I'm sure macros could simplify this goobly gook...· ...but I just don't do marcos (Unless forced to!!!)
Finally, a way to usefully use the secret instructions!!! (grin)
Calls in the upper half of a page, to the upper half of the page are done in the format:· (JMPLOC is a byte or ram)
··MOV ·JMPLOC,#$+3
··JMP·RoutinetoCall
Returns are:
··PushW···;Load W into W Shadow Stack
··MOV·W,STATUS·;MOVE STAT to W
··PushSTAT··;Load W into STAT Shadow Stack
··MOV·W,FSR··;Move the FSR to W
··PushFSR···;Load W into FSR Shadow Stack
··MOV·M,#$>>8··;Load Current Page/Half Page into W
··MOV·W,JMPLOC·;Load W with "Next" Addr on this 1/2 Page2
··PushPC···;Push W and M to PC Stack·
··RETI···;Pop the All Registers back...
·Anyway, here's the file.
Post Edited (Paul Baker) : 7/13/2005 9:37:34 PM GMT
but using 3 words to call a subroutine in upper half of a page
from a subroutine in upper half of another page is unneccessary. It only requires
a single word per subroutine, by putting a jump to that
subroutine in the lower half of the page where the subroutine
resides. See the adapted attachement.
regards peter
Post Edited (Peter Verkaik) : 7/13/2005 10:51:10 PM GMT
Dan, the 8 level call stack is a totally different and separate animal from the 2 level shadow stacks used by the interrupt service. And yes, you can do what you are suggesting,·but as Peter Verkaik pointed out, there are simpler ways to accomplish·it,·provided you are prepared to have a jump table in some lower half segment.
There are some very complicated "gotcha" issues dealing with what appears to be a simple pre-loaded RETI. In particular when interrupts are active, and interrupts in the middle of a SKIP instruction. Too hard to explain in simple terms.
Paul; The call stack itself was not used, but the call instruction was. I have since made conceptual changes as well as corrections to the code.
Peter;·I agree with your approach in general, but for coding convenience I would put all the "called subroutine jumps" together at one low half segment of memory. Realizing of course that @ (page) instructions are likely required as part of the jumps in that table.
Cheers,
Peter (pjv)
I am using pjv's suggestion of calls @routine...
-Dan