home *** CD-ROM | disk | FTP | other *** search
- ''
- '' $Id: HookEntryTask.bas,v 1.6 1994/05/12 14:21:29 alex Rel $
- ''
- '' BASIC task creation function
- ''
- '' (c) Copyright 1994 HiSoft
- ''
-
- 'REM $INCLUDE Exec.bh
- 'REM $INCLUDE Utility.bc
-
- 'REM $INCLUDE BLib/ExecSupport.bas
-
- ''
- '' CreateHookEntryTask
- ''
- '' Create task with given name, priority, stacksize
- ''
- '' NOTE: initPC _can_ be a BASIC entry point (VARPTRS(...))
- ''
- FUNCTION CreateHookEntryTask&(BYVAL tname&, BYVAL pri%, BYVAL initPC&, _
- BYVAL stackSize&)
- LOCAL tempmemlist%((Node_sizeof% + 3 + 3 * MemEntry_sizeof%) \ 2)
- LOCAL newTask&, fakememlist&, ml&, junk&, mlme&, h&, tcb&
- DIM TaskHookEntry&(6)
-
- CreateHookEntryTask& = NULL&
-
- ' The guts of TaskHookEntry.s translated to a TAGLIST via OToTagList:
- '
- ' movea.l (4).w,a6 ; connect to Exec
- ' suba.l a1,a1 ; find this task
- ' CALLSYS FindTask ; go find the task
- ' movea.l d0,a6 ; the task control block pointer
- ' lea TC_Userdata(a6),a6 ; where we stashed the Hook
- ' movea.l (a6),a0 ; pointer to the Hook
- ' move.l a2,(a6) ; clear out user data
- ' move.l h_Entry(a0),-(sp) ; the Hook entry point
- ' rts ; run the hook
- '
- IF TaskHookEntry&(0) = 0 THEN
- TAGLIST VARPTR(TaskHookEntry&(0)), _
- &H2C780004, &H93C94EAE, &HFEDA2C40, &H4DEE0058, &H20562C8A, &H2F280008, _
- &H4E750000
-
- IF PEEKW(LIBRARY("exec.library") + LibNode + lib_Version) >= 37 THEN
- ' CacheClearE is >= V37 only, without the flush this code will
- ' certainly not work on a 68040 (but does 1.3 work on an '040?)
-
- CacheClearE VARPTR(TaskHookEntry&(0)), 28, CACRF_ClearI& OR CACRF_ClearD&
- END IF
- END IF
-
- stackSize& = (stackSize& + 3) AND NOT 3
- fakememlist& = VARPTR(tempmemlist%(0))
-
- ' Allocate 3 entries in the Task MemList; the first is its Task structure, the
- ' second its stack, and the third the Hook used to retrieve the BASIC runtime
- ' context
-
- POKEW fakememlist& + Node_sizeof%, 3 ' number of entries
-
- POKEL fakememlist& + Node_sizeof% + 2 + meu_Reqs%, MEMF_PUBLIC& OR MEMF_CLEAR&
- POKEL fakememlist& + Node_sizeof% + 2 + me_Length%, Task_sizeof%
-
- POKEL fakememlist& + Node_sizeof% + 2 + MemEntry_sizeof% + meu_Reqs%, MEMF_CLEAR&
- POKEL fakememlist& + Node_sizeof% + 2 + MemEntry_sizeof% + me_Length%, stackSize&
-
- POKEL fakememlist& + Node_sizeof% + 2 + MemEntry_sizeof% * 2 + meu_Reqs%, MEMF_CLEAR&
- POKEL fakememlist& + Node_sizeof% + 2 + MemEntry_sizeof% * 2 + me_Length%, Hook_sizeof
-
- ml& = AllocEntry&(fakememlist&)
-
- IF ml& = NULL& THEN EXIT FUNCTION
-
- mlme& = ml& + MemList_sizeof% ' address of the first MemEntry
-
- newTask& = PEEKL(mlme& + meu_Addr%)
-
- ' set up the stack
- POKEL newTask& + tc_SPLower%, PEEKL(mlme& + MemEntry_sizeof% + meu_Addr%)
- POKEL newTask& + tc_SPUpper%, PEEKL(newTask& + tc_SPLower%) + stackSize&
- POKEL newTask& + tc_SPReg%, PEEKL(newTask& + tc_SPUpper%)
-
- ' set up the Hook
- h& = PEEKL(mlme& + MemEntry_sizeof% * 2 + meu_Addr%)
- InitHook h&, initPC&
- POKEL newTask& + tc_UserData, h&
-
- ' misc task structures
- POKEB newTask& + tc_Node% + ln_Type%, NT_TASK&
- POKEB newTask& + tc_Node% + ln_Pri%, pri%
- POKEL newTask& + tc_Node% + ln_Name%, tname&
-
- ' add the memory to the tasks memory list
- NewList newTask& + tc_MemEntry%
- AddHead newTask& + tc_MemEntry%, ml&
-
- ' add the task to the system, with the default PC
- tcb& = AddTask&(newTask&, VARPTR(TaskHookEntry&(0)), NULL&)
- IF PEEKW(LIBRARY("exec.library") + lib_Version%) >= 37 AND tcb& = NULL&
- FreeEntry ml&
- EXIT FUNCTION
- END IF
-
- CreateHookEntryTask& = newTask&
- END FUNCTION
-