added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / arm-all / exec / preparecontext.c
blobb925c7254ad85270f062a620485e2c5bc631d084
1 /*
2 Copyright © 1995-2001, 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>
12 #include "etask.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 /*****************************************************************************
23 NAME */
25 AROS_LH3(BOOL, PrepareContext,
27 /* SYNOPSIS */
28 AROS_LHA(struct Task *, task, A0),
29 AROS_LHA(APTR, entryPoint, A1),
30 AROS_LHA(APTR, fallBack, A2),
32 /* LOCATION */
33 struct ExecBase *, SysBase, 6, Exec)
35 /* FUNCTION
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.
40 INPUTS
41 task - Pointer to the new task
42 entryPoint - Address of the function to call when the new context
43 becomes active.
44 fallBack - Address to be called when the entryPoint function ended
45 with an rts.
47 RESULT
48 The new Stackpointer with the underlying context.
50 NOTES
51 This function is for internal use by exec only.
53 This function is processor dependant.
55 EXAMPLE
57 BUGS
59 SEE ALSO
60 SwitchTasks()
62 INTERNALS
64 HISTORY
66 ******************************************************************************/
68 AROS_LIBFUNC_INIT
70 struct pt_regs *regs;
72 ULONG *sp = (ULONG *)task->tc_SPReg;
73 ULONG * armregs;
74 ULONG i = 0;
76 if (!(task->tc_Flags & TF_ETASK)) {
77 return FALSE;
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)) {
86 return FALSE;
90 * Fill the registers r0-r3 with the arguments on the stack -
91 * if there are any...
93 armregs = &regs->r0;
94 #if 0
95 D(bug("sp=%x, task->tc_SPUpper=%x, name=%s\n",
96 sp,
97 task->tc_SPUpper,
98 task->tc_Node.ln_Name));
99 #endif
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));
103 *armregs = *sp;
104 armregs++;
105 sp++;
106 i++;
107 // D(bug("after: armregs=%x, sp=%x\n",armregs,sp));
109 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.
120 regs->sp = sp;
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;
132 return TRUE;
133 AROS_LIBFUNC_EXIT