2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: i386unix version of PrepareContext().
9 #include <exec/types.h>
10 #include <exec/execbase.h>
11 #include <exec/memory.h>
12 #include <utility/tagitem.h>
15 #include "exec_util.h"
17 #include <aros/libcall.h>
18 #include <asm/ptrace.h>
19 #include <asm/segments.h>
21 #define Regs(t) ((struct pt_regs *)(GetIntETask(t)->iet_Context))
23 static ULONG
*PrepareContext_Common(struct Task
*task
, APTR entryPoint
, APTR fallBack
,
24 struct TagItem
*tagList
, struct ExecBase
*SysBase
)
27 IPTR
*sp
=(IPTR
*)task
->tc_SPReg
;
33 switch(tagList
->ti_Tag
)
36 tagList
= (struct TagItem
*)tagList
->ti_Data
;
40 tagList
+= tagList
->ti_Data
;
47 #define HANDLEARG(x) \
48 case TASKTAG_ARG ## x: \
49 args[x - 1] = (IPTR)tagList->ti_Data; \
50 if (x > numargs) numargs = x; \
65 if (tagList
) tagList
++;
68 if (!(task
->tc_Flags
& TF_ETASK
) )
71 GetIntETask (task
)->iet_Context
= AllocTaskMem (task
72 , SIZEOF_ALL_REGISTERS
73 , MEMF_PUBLIC
|MEMF_CLEAR
76 if (!(regs
= (ULONG
*)GetIntETask (task
)->iet_Context
))
83 *--sp
= args
[numargs
];
87 /* Push fallBack address */
89 *--sp
= (IPTR
)fallBack
;
92 /* We have to prepare whole context right now so Dispatch()
93 * would work propertly */
95 *regs
++ = 0; /* ebx */
96 *regs
++ = 0; /* ecx */
97 *regs
++ = 0; /* edx */
98 *regs
++ = 0; /* esi */
99 *regs
++ = 0; /* edi */
100 *regs
++ = 0; /* ebp */
101 *regs
++ = 0; /* eax */
102 *regs
++ = USER_DS
; /* xds */
103 *regs
++ = USER_DS
; /* xes */
104 *regs
++ = (ULONG
)entryPoint
;/* eip */
105 *regs
++ = USER_CS
; /* xcs */
106 *regs
++ = 0x3202; /* eflags */
107 *regs
++ = (ULONG
)sp
; /* esp */
108 *regs
++ = USER_DS
; /* xss */
115 AROS_LH4(BOOL
, PrepareContext
,
116 AROS_LHA(struct Task
*, task
, A0
),
117 AROS_LHA(APTR
, entryPoint
, A1
),
118 AROS_LHA(APTR
, fallBack
, A2
),
119 AROS_LHA(struct TagItem
*, tagList
, A3
),
120 struct ExecBase
*, SysBase
, 6, Exec
)
124 return PrepareContext_Common(task
, entryPoint
, fallBack
, tagList
, SysBase
) ? TRUE
: FALSE
;
129 /* FIXME: This needs to be fixed/updated if the way library params are passed is changed */
130 AROS_LH4(BOOL
, PrepareContext_FPU
,
131 AROS_LHA(struct Task
*, task
, A0
),
132 AROS_LHA(APTR
, entryPoint
, A1
),
133 AROS_LHA(APTR
, fallBack
, A2
),
134 AROS_LHA(struct TagItem
*, tagList
, A3
),
135 struct ExecBase
*, SysBase
, 6, Exec
)
142 if ((regs
= PrepareContext_Common(task
, entryPoint
, fallBack
, tagList
, SysBase
)))
144 UBYTE this_fpustate
[SIZEOF_FPU_STATE
];
146 asm volatile("fnsave %1\n\t"
152 "fwait\n\t" : "=m" (*regs
), "=m" (this_fpustate
) : : "memory");
162 AROS_LH4(BOOL
, PrepareContext_SSE
,
163 AROS_LHA(struct Task
*, task
, A0
),
164 AROS_LHA(APTR
, entryPoint
, A1
),
165 AROS_LHA(APTR
, fallBack
, A2
),
166 AROS_LHA(struct TagItem
*, tagList
, A3
),
167 struct ExecBase
*, SysBase
, 6, Exec
)
174 if ((regs
= PrepareContext_Common(task
, entryPoint
, fallBack
, tagList
, SysBase
)))
176 UBYTE this_ssestate
[SIZEOF_FPU_STATE
+ 15], *ptr
= this_ssestate
;
177 regs
= (ULONG
*)(((IPTR
)regs
+15)&~15);
178 ptr
= (UBYTE
*)(((IPTR
)ptr
+15)&~15);
180 asm volatile("fxsave (%0)\n\t"
186 : "r" (ptr
), "r" (regs
)