2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 #include <exec/types.h>
7 #include <aros/libcall.h>
8 #include <exec/execbase.h>
9 #include <exec/tasks.h>
10 #include <exec/memory.h>
11 #include <exec/ptrace.h>
13 #include "exec_util.h"
16 #include <aros/debug.h>
18 #error "PrepareContext() has been changed. Additional tagList param, etc."
19 #error "This one here needs to be rewritten!"
21 /*****************************************************************************
25 AROS_LH3(BOOL
, PrepareContext
,
28 AROS_LHA(struct Task
*, task
, A0
),
29 AROS_LHA(APTR
, entryPoint
, A1
),
30 AROS_LHA(APTR
, fallBack
, A2
),
33 struct ExecBase
*, SysBase
, 6, Exec
)
36 Allocates the space required to hold a new set of registers on the
37 Stack given by stackPointer and clears the area except for pc which
38 is set to the address given by entryPoint.
41 task - Pointer to the new task
42 entryPoint - Address of the function to call when the new context
44 fallBack - Address to be called when the entryPoint function ended
48 The new Stackpointer with the underlying context.
51 This function is for internal use by exec only.
53 This function is processor dependant.
66 ******************************************************************************/
72 ULONG
*sp
= (ULONG
*)task
->tc_SPReg
;
76 if (!(task
->tc_Flags
& TF_ETASK
)) {
80 GetIntETask (task
)->iet_Context
= AllocTaskMem (task
81 , SIZEOF_ALL_REGISTERS
82 , MEMF_PUBLIC
|MEMF_CLEAR
85 if (!(regs
= (struct pt_regs
*)GetIntETask(task
)->iet_Context
)) {
90 * Fill the registers r0-r3 with the arguments on the stack -
95 D(bug("sp=%x, task->tc_SPUpper=%x, name=%s\n",
98 task
->tc_Node
.ln_Name
));
100 if (sp
< (ULONG
*)task
->tc_SPUpper
) {
101 while (sp
< (ULONG
*)task
->tc_SPUpper
&& i
< 4) {
102 // D(bug("before: armregs=%x, sp=%x\n",armregs,sp));
107 // D(bug("after: armregs=%x, sp=%x\n",armregs,sp));
113 * Initialize initial registers. Only sp and lr_svc
114 * are important. lr_svc represents the entry point of
115 * the process plus 4. The 4 will be subtracted automatically
116 * when the process is started. It must be done that way
117 * due to how the ARM processor works when handling *interrupts*!
118 * Also set the processor for User Mode.
121 regs
->lr_svc
= (ULONG
)entryPoint
+4;
122 regs
->cpsr
= (ULONG
)0x10;
125 * Now I am not sure whether this is going to work.
126 * In the *startup* code I will need to make sure
127 * that the fallback can be executed!
128 * Note that no '4' needs to be added in this case!
130 regs
->lr
= (ULONG
)fallBack
;