revert between 56095 -> 55830 in arch
[AROS.git] / arch / .unmaintained / arm-all / exec / preparecontext.c
blobace68c77c0d0b2b0ab0a414dd06806bbeeb389b1
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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"
15 #define DEBUG 1
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 BOOL PrepareContext(struct Task *task, APTR entryPoint, APTR fallBack,
22 struct TagItem *tagList, struct ExecBase *SysBase)
24 struct pt_regs *regs;
26 ULONG *sp = (ULONG *)task->tc_SPReg;
27 ULONG * armregs;
28 ULONG i = 0;
30 if (!(task->tc_Flags & TF_ETASK)) {
31 return FALSE;
34 task->tc_UnionETask.tc_ETask->et_RegFrame = AllocTaskMem (task, SIZEOF_ALL_REGISTERS,
35 MEMF_PUBLIC|MEMF_CLEAR);
37 if (!(regs = (struct pt_regs *)task->tc_UnionETask.tc_ETask->et_RegFrame))
38 return FALSE;
41 * Fill the registers r0-r3 with the arguments on the stack -
42 * if there are any...
44 armregs = &regs->r0;
45 #if 0
46 D(bug("sp=%x, task->tc_SPUpper=%x, name=%s\n",
47 sp,
48 task->tc_SPUpper,
49 task->tc_Node.ln_Name));
50 #endif
51 if (sp < (ULONG *)task->tc_SPUpper) {
52 while (sp < (ULONG *)task->tc_SPUpper && i < 4) {
53 // D(bug("before: armregs=%x, sp=%x\n",armregs,sp));
54 *armregs = *sp;
55 armregs++;
56 sp++;
57 i++;
58 // D(bug("after: armregs=%x, sp=%x\n",armregs,sp));
60 sp--;
64 * Initialize initial registers. Only sp and lr_svc
65 * are important. lr_svc represents the entry point of
66 * the process plus 4. The 4 will be subtracted automatically
67 * when the process is started. It must be done that way
68 * due to how the ARM processor works when handling *interrupts*!
69 * Also set the processor for User Mode.
71 regs->sp = sp;
72 regs->lr_svc = (ULONG)entryPoint+4;
73 regs->cpsr = (ULONG)0x10;
76 * Now I am not sure whether this is going to work.
77 * In the *startup* code I will need to make sure
78 * that the fallback can be executed!
79 * Note that no '4' needs to be added in this case!
81 regs->lr = (ULONG)fallBack;
83 return TRUE;