📄 cpu_calls.c
字号:
/* *---------------------------------------------------------------------- * T-Kernel * * Copyright (C) 2004 by Ken Sakamura. All rights reserved. * T-Kernel is distributed under the T-License. *---------------------------------------------------------------------- * * Version: 1.01.00 * Released by T-Engine Forum(http://www.t-engine.org) at 2004/6/28. * *---------------------------------------------------------------------- *//* * cpu_calls.c (M32104) * CPU-Dependant System Call */#include "kernel.h"#include "task.h"#include "check.h"#include "cpu_task.h"#include <sys/sysinfo.h>#include <tk/sysdef.h>#include "cpu_insn.h"/* * Dispatch enable/disable */SYSCALL ER _tk_dis_dsp( void ){ CHECK_CTX(!in_loc()); dispatch_disabled = 1; return E_OK;}/* * Dispatch enable */SYSCALL ER _tk_ena_dsp( void ){ CHECK_CTX(!in_loc()); dispatch_disabled = 0; if ( ctxtsk != schedtsk ) { dispatch(); } return E_OK;}/* ------------------------------------------------------------------------ *//* For saving monitor exception handler */EXPORT MONHDR SaveMonHdr;/* * High level programming language *//* High level programming language interrupt handler entry */EXPORT FP hll_inthdr[N_INTVEC];/* High level programming language routine (General) */IMPORT void inthdr_startup();/* For default handler */IMPORT void defaulthdr_startup();/* * Interrupt handler definition */SYSCALL ER _tk_def_int( UINT dintno, T_DINT *pk_dint ){ FP inthdr; CHECK_PAR(dintno >= 0 && dintno < N_INTVEC); if ( pk_dint != NULL ) { /* Set interrupt handler */ CHECK_RSATR(pk_dint->intatr, TA_HLNG); inthdr = pk_dint->inthdr; BEGIN_CRITICAL_SECTION; if ( (pk_dint->intatr & TA_HLNG) != 0 ) { hll_inthdr[dintno] = inthdr; inthdr = ( dintno == VECNO_DEFAULT )? defaulthdr_startup: inthdr_startup; } define_inthdr(dintno, inthdr); END_CRITICAL_SECTION; } else { /* Clear interrupt handler */ switch ( dintno ) { case VECNO_DEFAULT: inthdr = SaveMonHdr.default_hdr; break; case VECNO_MONITOR: inthdr = SaveMonHdr.monitor_hdr; break; case VECNO_BREAK: inthdr = SaveMonHdr.break_hdr; break; case VECNO_ICU2: inthdr = SaveMonHdr.icu2_hdr; break; case VECNO_INT5: inthdr = SaveMonHdr.int5_hdr; break; default: inthdr = NULL; } BEGIN_CRITICAL_SECTION; define_inthdr(dintno, inthdr); hll_inthdr[dintno] = NULL; END_CRITICAL_SECTION; } return E_OK;}/* ------------------------------------------------------------------------ *//* * Get task space */SYSCALL ER _tk_get_tsp( ID tskid, T_TSKSPC *pk_tskspc ){ TCB *tcb; ER ercd = E_OK; CHECK_TSKID_SELF(tskid); CHECK_INTSK(); tcb = get_tcb_self(tskid); BEGIN_CRITICAL_SECTION; if ( tcb->state == TS_NONEXIST ) { ercd = E_NOEXS; } else { pk_tskspc->uatb = tcb->tskctxb.uatb; pk_tskspc->lsid = tcb->tskctxb.lsid; } END_CRITICAL_SECTION; return ercd;}/* * Set task space */SYSCALL ER _tk_set_tsp( ID tskid, T_TSKSPC *pk_tskspc ){ TCB *tcb; ER ercd = E_OK; CHECK_TSKID_SELF(tskid); CHECK_INTSK(); tcb = get_tcb_self(tskid); BEGIN_CRITICAL_SECTION; if ( tcb->state == TS_NONEXIST) { ercd = E_NOEXS; } else { tcb->tskctxb.uatb = pk_tskspc->uatb; tcb->tskctxb.lsid = pk_tskspc->lsid; /* In practice, task space switch doesn't happen because there is no MMU */ } END_CRITICAL_SECTION; return ercd;}/* ------------------------------------------------------------------------ *//* * Set task register contents */LOCAL void set_reg( TCB *tcb, T_REGS *regs, T_EIT *eit, T_CREGS *cregs ){ SStackFrame *ssp; INT i; ssp = ( cregs != NULL )? cregs->sp: tcb->tskctxb.ssp; if ( regs != NULL ) { for ( i = 0; i < 6; ++i ) ssp->r0_5[i] = regs->r[i]; ssp->r6 = regs->r[6]; ssp->r7 = regs->r[7]; for ( i = 0; i < 7; ++i ) ssp->r8_14[i] = regs->r[8+i]; ssp->acch = regs->acch; ssp->accl = regs->accl; } if ( eit != NULL ) { ssp->bpc = eit->pc; ssp->psw = ((eit->psw & 0xff) << 8) | PSW_SM; } if ( cregs != NULL ) { tcb->tskctxb.ssp = cregs->sp; }}/* * Set task register contents */SYSCALL ER _tk_set_reg( ID tskid, T_REGS *pk_regs, T_EIT *pk_eit, T_CREGS *pk_cregs ){ TCB *tcb; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); if ( pk_eit != NULL ) { if ( (pk_eit->psw & (PSW_IE|PSW_SM)) != (PSW_IE|PSW_SM) ) return E_PAR; } CHECK_INTSK(); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; if ( tcb->state == TS_NONEXIST ) { ercd = E_NOEXS; } else { set_reg(tcb, pk_regs, pk_eit, pk_cregs); } END_CRITICAL_SECTION; return ercd;}/* * Get task register contents. */LOCAL void get_reg( TCB *tcb, T_REGS *regs, T_EIT *eit, T_CREGS *cregs ){ SStackFrame *ssp; INT i; ssp = tcb->tskctxb.ssp; if ( regs != NULL ) { for ( i = 0; i < 6; ++i ) regs->r[i] = ssp->r0_5[i]; regs->r[6] = ssp->r6; regs->r[7] = ssp->r7; for ( i = 0; i < 7; ++i ) regs->r[8+i] = ssp->r8_14[i]; regs->acch = ssp->acch; regs->accl = ssp->accl; } if ( eit != NULL ) { eit->pc = ssp->bpc; eit->psw = (ssp->psw >> 8) & 0xff; } if ( cregs != NULL ) { cregs->sp = tcb->tskctxb.ssp; }}/* * Get task register contents. */SYSCALL ER _tk_get_reg( ID tskid, T_REGS *pk_regs, T_EIT *pk_eit, T_CREGS *pk_cregs ){ TCB *tcb; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); CHECK_INTSK(); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; if ( tcb->state == TS_NONEXIST ) { ercd = E_NOEXS; } else { get_reg(tcb, pk_regs, pk_eit, pk_cregs); } END_CRITICAL_SECTION; return ercd;}/* * Set task coprocessor register */SYSCALL ER _tk_set_cpr( ID tskid, INT copno, T_COPREGS *pk_copregs ){ ATR copatr = TA_COP0 << copno; TCB *tcb; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); CHECK_PAR((copatr & available_cop) != 0); CHECK_INTSK(); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; if ( tcb->state == TS_NONEXIST ) { ercd = E_NOEXS; } else if ( (tcb->tskatr & copatr) == 0 ) { ercd = E_PAR; } else { /* No coprocessor */ } END_CRITICAL_SECTION; return ercd;}/* * Get task coprocessor register */SYSCALL ER _tk_get_cpr( ID tskid, INT copno, T_COPREGS *pk_copregs ){ ATR copatr = TA_COP0 << copno; TCB *tcb; ER ercd = E_OK; CHECK_TSKID(tskid); CHECK_NONSELF(tskid); CHECK_PAR((copatr & available_cop) != 0); CHECK_INTSK(); tcb = get_tcb(tskid); BEGIN_CRITICAL_SECTION; if ( tcb->state == TS_NONEXIST ) { ercd = E_NOEXS; } else if ( (tcb->tskatr & copatr) == 0 ) { ercd = E_PAR; } else { /* No coprocessor */ } END_CRITICAL_SECTION; return ercd;}/* ------------------------------------------------------------------------ *//* * Debugger support function */#if USE_DBGSPT/* * Set task register */SYSCALL ER _td_set_reg( ID tskid, T_REGS *regs, T_EIT *eit, T_CREGS *cregs ){ TCB *tcb; ER ercd = E_OK; CHECK_TSKID(tskid); if ( eit != NULL ) { if ( (eit->psw & (PSW_IE|PSW_SM)) != (PSW_IE|PSW_SM) ) return E_PAR; } tcb = get_tcb(tskid); if ( tcb == ctxtsk ) return E_OBJ; BEGIN_DISABLE_INTERRUPT; if ( tcb->state == TS_NONEXIST ) { ercd = E_NOEXS; } else { set_reg(tcb, regs, eit, cregs); } END_DISABLE_INTERRUPT; return ercd;}/* * Get task register */SYSCALL ER _td_get_reg( ID tskid, T_REGS *regs, T_EIT *eit, T_CREGS *cregs ){ TCB *tcb; ER ercd = E_OK; CHECK_TSKID(tskid); tcb = get_tcb(tskid); if ( tcb == ctxtsk ) return E_OBJ; BEGIN_DISABLE_INTERRUPT; if ( tcb->state == TS_NONEXIST ) { ercd = E_NOEXS; } else { get_reg(tcb, regs, eit, cregs); } END_DISABLE_INTERRUPT; return ercd;}#endif /* USE_DBGSPT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -