/* * Initialization sequence of device input/output-related */ EXPORT ER initDevIO( void ) { INT i; ER ercd; i = _tk_get_cfn(SCTAG_TMAXOPNDEV, &MaxOpnDev, 1); if ( i < 1 ) { ercd = E_SYS; goto err_ret; } i = _tk_get_cfn(SCTAG_TMAXREQDEV, &MaxReqDev, 1); if ( i < 1 ) { ercd = E_SYS; goto err_ret; } /* Generate open management information table */ OpnCBtbl = Imalloc((UINT)MaxOpnDev * sizeof(OpnCB)); if ( OpnCBtbl == NULL ) { ercd = E_NOMEM; goto err_ret; } QueInit(&FreeOpnCB); for ( i = 0; i < MaxOpnDev; ++i ) { OpnCBtbl[i].resid = 0; QueInsert(&OpnCBtbl[i].q, &FreeOpnCB); } /* Generate request management information table */ ReqCBtbl = Imalloc((UINT)MaxReqDev * sizeof(ReqCB)); if ( ReqCBtbl == NULL ) { ercd = E_NOMEM; goto err_ret; } QueInit(&FreeReqCB); for ( i = 0; i < MaxReqDev; ++i ) { ReqCBtbl[i].opncb = NULL; QueInsert(&ReqCBtbl[i].q, &FreeReqCB); } return E_OK; err_ret: DEBUG_PRINT(("initDevIO ercd = %d\n", ercd)); return ercd; }
/* * TCB Initialization */ EXPORT ER task_initialize( void ) { INT i; TCB *tcb; ID tskid; /* Get system information */ i = _tk_get_cfn(SCTAG_TMAXTSKID, &max_tskid, 1); if ( i < 1 || NUM_TSKID < 1 ) { return E_SYS; } i = _tk_get_cfn(SCTAG_TSYSSTKSZ, &default_sstksz, 1); if ( i < 1 || default_sstksz < MIN_SYS_STACK_SIZE ) { return E_SYS; } i = _tk_get_cfn(SCTAG_TSVCLIMIT, &svc_call_limit, 1); if ( i < 1 || svc_call_limit < 0 || svc_call_limit > 3 ) { return E_SYS; } /* Allocate TCB area */ tcb_table = Imalloc((UINT)NUM_TSKID * sizeof(TCB)); if ( tcb_table == NULL ) { return E_NOMEM; } /* Initialize task execution control information */ ctxtsk = schedtsk = NULL; ready_queue_initialize(&ready_queue); dispatch_disabled = DDS_ENABLE; /* Register all TCBs onto FreeQue */ QueInit(&free_tcb); for ( tcb = tcb_table, i = 0; i < NUM_TSKID; tcb++, i++ ) { tskid = ID_TSK(i); tcb->tskid = tskid; tcb->state = TS_NONEXIST; #ifdef NUM_PORID tcb->wrdvno = tskid; #endif InitSVCLOCK(&tcb->svclock); tcb->svclocked = NULL; QueInsert(&tcb->tskque, &free_tcb); } return E_OK; }
/* * Initialization of message buffer control block */ EXPORT ER messagebuffer_initialize( void ) { MBFCB *mbfcb, *end; W n; /* Get system information */ n = _tk_get_cfn(SCTAG_TMAXMBFID, &max_mbfid, 1); if ( n < 1 || NUM_MBFID < 1 ) { return E_SYS; } /* Create message buffer control block */ mbfcb_table = Imalloc((UINT)NUM_MBFID * sizeof(MBFCB)); if ( mbfcb_table == NULL ) { return E_NOMEM; } /* Register all control blocks onto FeeQue */ QueInit(&free_mbfcb); end = mbfcb_table + NUM_MBFID; for ( mbfcb = mbfcb_table; mbfcb < end; mbfcb++ ) { mbfcb->mbfid = 0; QueInsert(&mbfcb->send_queue, &free_mbfcb); } return E_OK; }
/* * Initialization of port control block */ EXPORT ER rendezvous_initialize( void ) { PORCB *porcb, *end; W n; /* Get system information */ n = _tk_get_cfn(SCTAG_TMAXPORID, &max_porid, 1); if ( n < 1 || NUM_PORID < 1 ) { return E_SYS; } /* Create port control block */ porcb_table = Imalloc((UINT)NUM_PORID * sizeof(PORCB)); if ( porcb_table == NULL ) { return E_NOMEM; } /* Register all control blocks onto FeeQue */ QueInit(&free_porcb); end = porcb_table + NUM_PORID; for ( porcb = porcb_table; porcb < end; porcb++ ) { porcb->porid = 0; QueInsert(&porcb->call_queue, &free_porcb); } return E_OK; }
/* * Initialization of mutex control block */ EXPORT ER mutex_initialize(void) { MTXCB *mtxcb, *end; W n; /* Get system information */ n = _tk_get_cfn(SCTAG_TMAXMTXID, &max_mtxid, 1); if ( n < 1 || NUM_MTXID < 1 ) { return E_SYS; } /* Create mutex control block */ mtxcb_table = Imalloc((UINT)NUM_MTXID * sizeof(MTXCB)); if ( mtxcb_table == NULL ) { return E_NOMEM; } /* Register all control blocks onto FeeQue */ QueInit(&free_mtxcb); end = mtxcb_table + NUM_MTXID; for( mtxcb = mtxcb_table; mtxcb < end; mtxcb++ ) { mtxcb->mtxid = 0; QueInsert(&mtxcb->wait_queue, &free_mtxcb); } return E_OK; }
/* * Initialization of variable size memory pool control block */ EXPORT ER memorypool_initialize( void ) { MPLCB *mplcb, *end; W n; /* Get system information */ n = _tk_get_cfn(SCTAG_TMAXMPLID, &max_mplid, 1); if ( n < 1 || NUM_MPLID < 1 ) { return E_SYS; } /* Create variable size memory pool control block */ mplcb_table = Imalloc((UINT)NUM_MPLID * sizeof(MPLCB)); if ( mplcb_table == NULL ) { return E_NOMEM; } /* Register all control blocks onto FeeQue */ QueInit(&free_mplcb); end = mplcb_table + NUM_MPLID; for ( mplcb = mplcb_table; mplcb < end; mplcb++ ) { mplcb->mplid = 0; QueInsert(&mplcb->wait_queue, &free_mplcb); } return E_OK; }
/* * Initialization of device initial setting information */ LOCAL ER initIDev( void ) { T_CMBF cmbf; INT val[2]; ER ercd; /* Get system information */ ercd = _tk_get_cfn(SCTAG_TDEVTMBFSZ, val, 2); if ( ercd < 2 ) { val[0] = -1; } if ( val[0] >= 0 ) { /* Generate message buffer for event notification */ SetOBJNAME(cmbf.exinf, OBJNAME_DMMBF); cmbf.mbfatr = TA_TFIFO; cmbf.bufsz = val[0]; cmbf.maxmsz = val[1]; ercd = tk_cre_mbf(&cmbf); if ( ercd < E_OK ) { DefaultIDev.evtmbfid = 0; goto err_ret; } DefaultIDev.evtmbfid = ercd; } else { /* Do not use message buffer for event notification */ DefaultIDev.evtmbfid = 0; } return E_OK; err_ret: DEBUG_PRINT(("initIDev ercd = %d\n", ercd)); return ercd; }
/* * Set Event */ EXPORT void setEvent(void) { INT n; Asm("sev"); _tk_get_cfn(SCTAG_TKERPRNUM, &n, 1); while ( sync != (n-1) ); sync = 0; mp_memory_barrier(); }