/ tk_util.s / / EMACS_MODES: !c !fill / / This file contains the assembly-language routines for dealing with / UNIX tasks. All the machine-dependent routines are contained here. / The following routines are included: / tk_frame build a new stack frame for a newly-created task / tk_swtch switch task contexts / .globl csv, cret tk_fp = 2 / frame ptr. in task ctl block / tk_frame (tk, base, entry) / / Build a stack frame for a newly created task, with entry point entry. / The base argument gives the base of the new task's stack. The frame / is constructed with an invalid previous frame at the base of the / stack, so that if the task ever attempts to return from its entry / procedure this will cause the process to core dump. This routine / sets up the saved frame pointer value in the task control block (pointed / to by tk) to point to the newly created stack frame. / / Arguments: / task *tk; task control block address / stack *base; base address of task's stack / int (*entry) (); entry point of task / .globl _tk_frame tk = 4 base = 6 entry = 8 _tk_frame: jsr r5,csv / save all registers mov base(r5),r0 / get stack base mov entry(r5),r1 / and entry address mov tk(r5),r2 / and task control block addr mov $-1,-(r0) / illegal pc in previous frame clr -(r0) / prev fp 0 for adb etc. mov r0,r3 / save addr of previous fp mov r1,-(r0) / return pc is entry point mov r3,-(r0) / previous fp mov r0,tk_fp(r2) / set tk->tk_fp to frame ptr jmp cret / that's it / tk_swtch (tk) / / Switch the currently running task to the specified task. Save the / current frame pointer in tk_cur->tk_fp for later task switch, then / set tk_cur to the new task control block. This is called only / from tk_sched, which doesn't need the registers any more, so it / doesn't bother to save them. Return is in the context of the / newly running task. / / Arguments: / task *tk; ptr to task ctl blk for new task / .globl _tk_swtch, _tk_cur tk = 4 _tk_swtch: mov r5, -(sp) / save stack frame for later return mov sp,r5 mov _tk_cur,r0 mov r5,tk_fp(r0) / save frame ptr. in current ctl block mov tk(r5),r0 / switch current task mov r0,_tk_cur mov tk_fp(r0),r5 / restore saved frame pointer jmp cret / return in new task's context