4 * 1. Save stack frames: EXC, VGPR, NVGPR and C
\r
5 * 2. Call IntCtrl_Entry(void *curr_stack)
\r
6 * 2.1 Check for exception
\r
7 * 2.2 If softint, clear it.
\r
8 * 2.3 If PROC_ISR1, then just call the function
\r
9 * 2.4 If PROC_ISR2 -> it's a PCB, let the OS handle it.
\r
13 #include "asm_ppc.h"
\r
14 #include "asm_offset.h"
\r
15 #include "asm_book_e.h"
\r
16 .extern os_intc_pcb_tbl
\r
17 .extern os_intc_types_tbl
\r
22 * Small assembler school
\r
23 * Compare imm(32-bit)
\r
25 * Extract bits and right adjust
\r
26 * > extrwi rA,rS,n,b ( n-number of bits, b- startbit )
\r
29 * The offset's (d or D)for SPE instructins are rediculously low.
\r
30 * Normally you have 16-bits offset, but when using spe load and store
\r
31 * you can use only 8-bit.
\r
34 #define LOCK() wrteei 0
\r
35 #define UNLOCK() wrteei 1
\r
38 .extern os_proc_start_extended
\r
40 //-------------------------------------------------------------------
\r
42 .global os_exception_IVOR8
\r
45 stwu sp,-(EXC_SIZE+VGPR_SIZE)(sp)
\r
46 stw r3,EXC_R3_OFF(r1)
\r
47 stw r4,EXC_R4_OFF(r1)
\r
48 SAVE_EXC_FRAME(3,1,0,SPR_SRR0,SPR_SRR1)
\r
49 SAVE_VGPR(1,EXC_SIZE);
\r
51 stw r3,EXC_VECTOR_OFF(r1)
\r
58 /*--------------------------------------------------------------------
\r
59 * void os_swap_context(pcb_t *old, pcb_t *new )
\r
61 * Saves a small context on current stack, pops a new one from new context
\r
63 * r3 - pcb for old process
\r
64 * r4 - pcb for new process
\r
66 *--------------------------------------------------------------------*/
\r
68 // TODO: this assumes that both are in user mode?.. can this happen under trusted functions?
\r
69 // When I get here we're ALWAYS in kernel mode
\r
71 .global os_arch_swap_context_to
\r
72 .global os_arch_swap_context
\r
74 os_arch_swap_context:
\r
75 // allocate space for context+nvgpr
\r
76 // (no need for proper stack-frame here)
\r
77 stwu r1,-(C_SIZE+NVGPR_SIZE)(r1)
\r
78 // save lr and cr */
\r
83 // Save small-context pattern
\r
85 stw r0,C_CONTEXT_OFF(sp)
\r
86 // Save registers preserved by function call
\r
87 SAVE_NVGPR(sp,(C_SIZE-14*GPR_SIZE))
\r
88 // Save stack ptr...
\r
89 stw sp,PCB_STACK_CURR_P(r3)
\r
92 // --------- bottom( high address )
\r
95 // --------- <- stack.curr
\r
97 // --------- top( low address )
\r
100 // TODO: If we change application we must change mmu setup
\r
101 os_arch_swap_context_to:
\r
102 // Get stack for new task
\r
103 lwz sp,PCB_STACK_CURR_P(r4)
\r
105 // Set new current process
\r
106 LOAD_ADDR_32(3,os_sys)
\r
107 stw r4,SYS_CURR_PCB_P(r3)
\r
109 // Restore C context
\r
110 lwz r0,C_CR_OFF(sp)
\r
112 lwz r0,C_LR_OFF (sp)
\r
115 // Get the context type
\r
116 lwz r0,C_CONTEXT_OFF(sp)
\r
117 cmpli 0,r0,SC_PATTERN
\r
119 cmpli 0,r0,LC_PATTERN
\r
125 // C_xxxx <- We point here
\r
128 RESTORE_NVGPR(sp,(C_SIZE-14*GPR_SIZE))
\r
129 addi sp,sp,(C_SIZE+NVGPR_SIZE)
\r
130 // TODO: The blr will not do the trick if swapping to a user land task.
\r
137 RESTORE_VGPR(1,C_SIZE)
\r
139 RESTORE_WORK_AND_MORE
\r
142 // When something really bad happens we end up here for the moment
\r
149 // ------------------------------------------------------------------
\r
152 * Trap interface !!!! See article http://www.linuxjournal.com/article/6516
\r
153 * http://www.osweekly.com/index.php?option=com_content&task=view&id=2229
\r
156 /* The T32 instruction sim can't handle trap's so we have to make something
\r
157 * - write SRR0, SRR1, MSR
\r
158 * - jump to there routines
\r
161 // ------------------------------------------------------------------
\r
164 // System call, use this for trusted function ???
\r
165 // TODO: The example in autosar is not neccesary.. sc here here instead??
\r
168 // Since the sc is a sync call, it should be enough to save NV regs(14->)
\r
169 // If I don't use the NV regs here I shouldn't need to save them
\r
170 // TODO: Inform compiler in SC_CALL() that I clobber volatile regs( r0, r3->
\r
171 // (since the compiler does not know it's a function call)
\r
172 // TODO: Could probably do this shorter....only NV regs that I use need saving
\r
173 // ( only cr2->cr4 according to e500 ABI )
\r