arch/m68k-amiga: Native Amiga support
[AROS.git] / arch / m68k-amiga / exec / preparecontext.c
blob070bd5dbc186ff3533467e7cff04a6ef5ff2ab25
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 /*****************************************************************************
17 NAME */
19 AROS_LH4(BOOL, PrepareContext,
21 /* SYNOPSIS */
22 AROS_LHA(VOLATILE struct Task *, task, A0),
23 AROS_LHA(APTR, entryPoint, A1),
24 AROS_LHA(APTR, fallBack, A2),
25 AROS_LHA(struct TagItem *, tagList, A3),
27 /* LOCATION */
28 struct ExecBase *, SysBase, 6, Exec)
30 /* FUNCTION
31 Allocates the space required to hold a new set of registers on the
32 Stack given by stackPointer and clears the area except for pc which
33 is set to the address given by entryPoint.
35 INPUTS
36 task - Pointer to the new task
37 entryPoint - Address of the function to call when the new context
38 becomes active.
39 fallBack - Address to be called when the entryPoint function ended
40 with an rts.
41 tagList -
43 RESULT
44 The new Stackpointer with the underlying context.
46 NOTES
47 This function is for internal use by exec only.
49 This function is processor dependant.
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 SwitchTasks()
58 INTERNALS
60 HISTORY
62 ******************************************************************************/
64 AROS_LIBFUNC_INIT
66 struct pt_regs *regs;
68 UBYTE *sp = (UBYTE *)task->tc_SPReg;
70 /* Push fallBack address */
71 sp -= sizeof(APTR);
72 *(APTR *)sp = fallBack;
74 if (!(task->tc_Flags & TF_ETASK)) {
75 *(ULONG *)0x0bad0001=0;
76 return FALSE;
79 GetIntETask (task)->iet_Context = AllocTaskMem ((struct Task *)task
80 , SIZEOF_ALL_REGISTERS
81 , MEMF_PUBLIC|MEMF_CLEAR
84 if (!(regs = (struct pt_regs *)GetIntETask(task)->iet_Context)) {
85 *(ULONG *)0x0bad0003=0;
86 return FALSE;
89 regs->usp = (IPTR)sp;
90 regs->pc = (ULONG)entryPoint;
92 task->tc_SPReg = sp;
94 return TRUE;
95 AROS_LIBFUNC_EXIT