嵌入式操作系统T-Kernel
完整代码
源代码在线查看: setspc.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. * *---------------------------------------------------------------------- */ /* * @(#)setspc.c (libtk/SH7727) * * Address space control */ #include #include #include #include "getsvcenv.h" /* * Set task address space */ EXPORT ER SetTaskSpace( ID taskid ) { UW mdr; ER er; if ( taskid == TSK_SELF ) { /* Set current CPL in MDR.RPL */ mdr = getsvcenv(); mdr ^= (mdr ^ (mdr Asm("ldc %0, r2_bank" :: "r"(mdr)); } else { T_EIT r_eit; T_CREGS r_cregs; T_TSKSPC tskspc; /* Get logical space/MDR register for taskid tasks */ er = tk_get_reg(taskid, NULL, &r_eit, &r_cregs); if ( er < E_OK ) goto err_ret; /* Change to logical space for nominated tasks */ tskspc.uatb = r_cregs.uatb; tskspc.lsid = r_cregs.lsid; er = tk_set_tsp(TSK_SELF, &tskspc); if ( er < E_OK ) goto err_ret; /* Change to MDR.PPL for nominated tasks */ mdr = getsvcenv(); mdr ^= (mdr ^ r_eit.mdr) & MDR_PPL(3); Asm("ldc %0, r2_bank" :: "r"(mdr)); } return E_OK; err_ret: return er; }