Accessing simulated hardware return stack

The stack on the PIC cannot be accessed via the program or data space. It behaves as though it has its own address space and can only be access via a dedicated register, the stack pointer. To complicate things further, the stack pointer is a special register that can only be modified by the call and return instructions (and hardware interrupts) and cannot be copied from or to any other rgister.

To access the simulated stack pointer use the special register reference [{RET_STK_PTR}]

To access data on the simulated stack (return addresses) use the special register reference [{RET_STK}]. Items on this stack are referenced as offsets from this special register.

	[{RET_STK}][0] referes to location 0 in the stack address space
	[{RET_STK}][1] referes to location 1 in the stack address space
	[{RET_STK}][N] referes to location N in the stack address space

	[{RET_STK}] is equivalent to [{RET_STK}][0]
to access the value on the top of the stack use:
	[{RET_STK}] [ [{RET_STK_PTR}] ]
(spaces are only used here for clarity they are not otherwise necessary)

The following section of embedded simulator code is an example of how an interrupt service routine can cause a simulator exception if it is invoked during the execution of a certain function. This section of code would be placed at the start of the ISR.


	.xcsim	local xpc

	.xcsim	xpc = [{RET_STK}][[{RET_STK_PTR}]]

	.xcsim	if  xpc >= {func_start}  &&  xpc < {func_end}  then
		    .breakpoint
	.xcsim	endif

NOTE: the func_start and func_end are enclosed in { and } baces not [{ and }] sequences. This is because we need the addresses of the symbols func_start and func_end, not the binary values of the instructions at these addresses.