I'm getting quite confused by some of the terminology etc that comes with reading about a lot of new stuff
Also by some of the core principles too I guess.
1) What exactly is the stack used for? Is it only used for such things as function calls and other branches (such as interrupts) where the program needs to return afterwards?
2) When I call
To store the registers, where are they stored to?
3) If I want to change the stored PC before it is restored after an IRQ (and also read the stored PC) how can I do this?
I want to implement threading with a single, non-reentrant timer-based interrupt (getting good at the jargon, no?
). The actual interrupt handler is very small, and all it does (once inside the handler) is:
1) Read the stored PC (this should be the position of the PC
before the interrupt) and store it in the thread list against the currently running thread. Also copy the stored registers to the thread list for the current thread too.
2) Go to the next thread in the list, and copy the PC and register values from there to the stored registers.
3) Now exit the interrupt. If all goes right, the values that are restored to the registers and PC are those for the next thread to be run.
To add a new thread, simply disable interrupts, add the function pointer of the function to be run as a thread to the thread list as the PC, and set the registers of that thread in the thread list to some valid default values. re-enable interrupts.
I thought (for now) that for code I wasn't sure about (such as accessing the smc, or other critical data) I could simply disable interrupts before accessing them, and enable them again afterwards.
Does this all sound doable? Is is it the completely wrong way to go about it? Keep in mind that I am NOT an ARM or ASM guru - most of my programming experience is Delphi, c++ and lately, c (as well as some c64 assembly, Amos on the Amiga, and scripting such as PHP, SQL etc which hardly count
), and google lacks some good quality tutorials in these areas.
I realise that what I explain above is very similar to context switching, but I can't find any good info on context switching