1 #include <exec/types.h>
2 #include <exec/execbase.h>
3 #include <exec/memory.h>
4 #include <utility/tagitem.h>
12 #include <aros/libcall.h>
13 #include <aros/debug.h>
14 #include <asm/segments.h>
16 #define Regs(t) ((struct regs_t *)(GetIntETask(t)->iet_Context))
18 static UQUAD
*PrepareContext_Common(struct Task
*task
, APTR entryPoint
, APTR fallBack
,
19 struct TagItem
*tagList
, struct ExecBase
*SysBase
)
22 IPTR
*sp
=(IPTR
*)task
->tc_SPReg
;
28 switch(tagList
->ti_Tag
)
31 tagList
= (struct TagItem
*)tagList
->ti_Data
;
35 tagList
+= tagList
->ti_Data
;
42 #define HANDLEARG(x) \
43 case TASKTAG_ARG ## x: \
44 args[x - 1] = (IPTR)tagList->ti_Data; \
45 if (x > numargs) numargs = x; \
60 if (tagList
) tagList
++;
63 if (!(task
->tc_Flags
& TF_ETASK
) )
66 GetIntETask (task
)->iet_Context
= AllocTaskMem (task
67 , SIZEOF_ALL_REGISTERS
68 , MEMF_PUBLIC
|MEMF_CLEAR
71 D(bug("[exec] PrepareContext: iet_Context = %012p\n", GetIntETask (task
)->iet_Context
));
73 if (!(regs
= (ULONG
*)GetIntETask (task
)->iet_Context
))
100 /* Push fallBack address */
104 regs
->return_rip
= (IPTR
)entryPoint
;
105 regs
->return_cs
= USER_CS
;
106 regs
->return_rflags
= 0x3202;
107 regs
->return_ss
= USER_DS
;
108 regs
->return_rsp
= (IPTR
)sp
;
112 UBYTE current_xmm
[512+16], *curr
= current_xmm
;
114 curr
= (UBYTE
*)(((IPTR
)curr
+ 15) & ~15);
115 IPTR sse_ctx
= ((IPTR
)regs
+ sizeof(regs_t
) + 15) & ~15;
117 asm volatile("fxsave (%0); fninit; fwait; fxsave (%1); fxrstor (%0);"::"r"(curr
),"r"(sse_ctx
));
124 AROS_LH4(BOOL
, PrepareContext
,
125 AROS_LHA(struct Task
*, task
, A0
),
126 AROS_LHA(APTR
, entryPoint
, A1
),
127 AROS_LHA(APTR
, fallBack
, A2
),
128 AROS_LHA(struct TagItem
*, tagList
, A3
),
129 struct ExecBase
*, SysBase
, 6, Exec
)
133 return PrepareContext_Common(task
, entryPoint
, fallBack
, tagList
, SysBase
) ? TRUE
: FALSE
;