SYSCALL ER _tk_get_mpl_u( ID mplid, INT blksz, void **p_blk, TMO_U tmout ) { MPLCB *mplcb; void *blk = NULL; ER ercd = E_OK; CHECK_MPLID(mplid); CHECK_PAR(blksz > 0 && blksz <= MAX_ALLOCATE); CHECK_TMOUT(tmout); CHECK_DISPATCH(); mplcb = get_mplcb(mplid); blksz = roundSize(blksz); BEGIN_CRITICAL_SECTION; if ( mplcb->mplid == 0 ) { ercd = E_NOEXS; goto error_exit; } #if CHK_PAR if ( blksz > mplcb->mplsz ) { ercd = E_PAR; goto error_exit; } #endif /* Check wait disable */ if ( is_diswai((GCB*)mplcb, ctxtsk, TTW_MPL) ) { ercd = E_DISWAI; goto error_exit; } if ( gcb_top_of_wait_queue((GCB*)mplcb, ctxtsk) == ctxtsk && (blk = get_blk(mplcb, blksz)) != NULL ) { /* Get memory block */ *p_blk = blk; } else { /* Ready for wait */ ctxtsk->wspec = ( (mplcb->mplatr & TA_TPRI) != 0 )? &wspec_mpl_tpri: &wspec_mpl_tfifo; ctxtsk->wercd = &ercd; ctxtsk->winfo.mpl.blksz = blksz; ctxtsk->winfo.mpl.p_blk = p_blk; gcb_make_wait_with_diswai((GCB*)mplcb, tmout); } error_exit: END_CRITICAL_SECTION; return ercd; }
/* * process declarations of the form: * * <type> <specifier>, <specifier>...; * * leaves the declarations in the symbol table pointed to by * table and returns the number of bytes declared. al is the * allocation type to assign, ilc is the initial location * counter. if al is sc_member then no initialization will * be processed. ztype should be bt_struct for normal and in * structure ParseSpecifierarations and sc_union for in union ParseSpecifierarations. */ int declare(TABLE *table,int al,int ilc,int ztype) { SYM *sp, *sp1, *sp2; TYP *dhead, *tp1, *tp2; ENODE *ep1, *ep2; char stnm[200]; int op; int fd; int fn_doneinit = 0; int bcnt; static long old_nbytes; int nbytes; nbytes = 0; if (ParseSpecifier(table)) return nbytes; dhead = head; for(;;) { declid = (char *)NULL; bit_width = -1; ParseDeclarationPrefix(ztype==bt_union); // If a function declaration is taking place and just the type is // specified without a parameter name, assign an internal compiler // generated name. if (funcdecl>0 && funcdecl != 10 && declid==(char *)NULL) { sprintf(lastid, "_p%d", nparms); declid = litlate(lastid); names[nparms++] = declid; missingArgumentName = TRUE; } if( declid != NULL) { /* otherwise just struct tag... */ sp = allocSYM(); sp->name = declid; sp->storage_class = al; sp->isConst = isConst; if (bit_width > 0 && bit_offset > 0) { // share the storage word with the previously defined field nbytes = old_nbytes - ilc; } old_nbytes = ilc + nbytes; if (al != sc_member) { // sp->isTypedef = isTypedef; if (isTypedef) sp->storage_class = sc_typedef; isTypedef = FALSE; } if ((ilc + nbytes) % roundAlignment(head)) { if (al==sc_thread) tseg(); else dseg(); } bcnt = 0; while( (ilc + nbytes) % roundAlignment(head)) { ++nbytes; bcnt++; } if( al != sc_member && al != sc_external && al != sc_auto) { if (bcnt > 0) genstorage(bcnt); } // Set the struct member storage offset. if( al == sc_static || al==sc_thread) { sp->value.i = nextlabel++; } else if( ztype == bt_union) sp->value.i = ilc; else if( al != sc_auto ) sp->value.i = ilc + nbytes; // Auto variables are referenced negative to the base pointer // Structs need to be aligned on the boundary of the largest // struct element. If a struct is all chars this will be 2. // If a struct contains a pointer this will be 8. It has to // be the worst case alignment. else { sp->value.i = -(ilc + nbytes + roundSize(head)); } if (bit_width == -1) sp->tp = head; else { sp->tp = allocTYP(); *(sp->tp) = *head; sp->tp->type = bt_bitfield; sp->tp->size = head->size;//tp_int.size; sp->tp->bit_width = bit_width; sp->tp->bit_offset = bit_offset; } if (isConst) sp->tp->isConst = TRUE; if((sp->tp->type == bt_func) && sp->storage_class == sc_global ) sp->storage_class = sc_external; // Increase the storage allocation by the type size. if(ztype == bt_union) nbytes = imax(nbytes,roundSize(sp->tp)); else if(al != sc_external) { // If a pointer to a function is defined in a struct. if (isStructDecl && (sp->tp->type==bt_func || sp->tp->type==bt_ifunc)) nbytes += 8; else nbytes += roundSize(sp->tp); } if (sp->tp->type == bt_ifunc && (sp1 = search(sp->name,table)) != 0 && sp1->tp->type == bt_func ) { sp1->tp = sp->tp; sp1->storage_class = sp->storage_class; sp1->value.i = sp->value.i; sp1->IsPrototype = sp->IsPrototype; sp = sp1; } else { sp2 = search(sp->name,table); if (sp2 == NULL) insert(sp,table); else { if (funcdecl==2) sp2->tp = sp->tp; //else if (!sp2->IsPrototype) // insert(sp,table); } } if (needParseFunction) { needParseFunction = FALSE; fn_doneinit = ParseFunction(sp); if (sp->tp->type != bt_pointer) return nbytes; } // if(sp->tp->type == bt_ifunc) { /* function body follows */ // ParseFunction(sp); // return nbytes; // } if( (al == sc_global || al == sc_static || al==sc_thread) && !fn_doneinit && sp->tp->type != bt_func && sp->tp->type != bt_ifunc && sp->storage_class!=sc_typedef) doinit(sp); } if (funcdecl>0) { if (lastst==comma || lastst==semicolon) break; if (lastst==closepa) goto xit1; } else if (catchdecl==TRUE) { if (lastst==closepa) goto xit1; } else if (lastst == semicolon) break; else if (lastst == assign) { tp1 = nameref(&ep1); op = en_assign; // NextToken(); tp2 = asnop(&ep2); if( tp2 == 0 || !IsLValue(ep1) ) error(ERR_LVALUE); else { tp1 = forcefit(&ep1,tp1,&ep2,tp2); ep1 = makenode(op,ep1,ep2); } sp->initexp = ep1; if (lastst==semicolon) break; } needpunc(comma); if(declbegin(lastst) == 0) break; head = dhead; } NextToken(); xit1: return nbytes; }
/* * Create variable size memory pool */ SYSCALL ID _tk_cre_mpl( CONST T_CMPL *pk_cmpl ) { #if CHK_RSATR const ATR VALID_MPLATR = { TA_TPRI |TA_RNG3 |TA_NODISWAI #if USE_OBJECT_NAME |TA_DSNAME #endif }; #endif MPLCB *mplcb; ID mplid; INT mplsz; void *mempool; ER ercd; CHECK_RSATR(pk_cmpl->mplatr, VALID_MPLATR); CHECK_PAR(pk_cmpl->mplsz > 0 && pk_cmpl->mplsz <= MAX_ALLOCATE); CHECK_DISPATCH(); mplsz = roundSize(pk_cmpl->mplsz); /* Allocate memory for memory pool */ mempool = IAmalloc((UINT)mplsz + sizeof(QUEUE)*2, pk_cmpl->mplatr); if ( mempool == NULL ) { return E_NOMEM; } BEGIN_CRITICAL_SECTION; /* Get control block from FreeQue */ mplcb = (MPLCB*)QueRemoveNext(&free_mplcb); if ( mplcb == NULL ) { ercd = E_LIMIT; } else { mplid = ID_MPL(mplcb - mplcb_table); /* Initialize control block */ QueInit(&mplcb->wait_queue); mplcb->mplid = mplid; mplcb->exinf = pk_cmpl->exinf; mplcb->mplatr = pk_cmpl->mplatr; mplcb->mplsz = mplsz; #if USE_OBJECT_NAME if ( (pk_cmpl->mplatr & TA_DSNAME) != 0 ) { strncpy((char*)mplcb->name, (char*)pk_cmpl->dsname, OBJECT_NAME_LENGTH); } #endif /* Initialize memory pool */ init_mempool(mplcb, mempool, mplsz + (INT)sizeof(QUEUE)*2); ercd = mplid; } END_CRITICAL_SECTION; if ( ercd < E_OK ) { IAfree(mempool, pk_cmpl->mplatr); } return ercd; }
void ClassDeclaration::ParseMembers(SYM *sym, int ztype) { int slc; TYP *tp = sym->tp; int ist; SYM *hsym; std::string *name; isPrivate = true; if (sym->tp->size) slc = roundSize(sym->tp); else slc = 0; // slc = 0; tp->val_flag = 1; // tp->val_flag = FALSE; ist = isTypedef; isTypedef = false; // First add a hidden member that indicates the class number. The type // number is used during virtual function calls to determine which // method to call. This is the first field in the class so it can be // refeerenced as 0[r25]. hsym = allocSYM(); name = new std::string("_typeno"); hsym->SetName(*name); hsym->storage_class = sc_member; hsym->value.i = sym->tp->typeno; hsym->tp = TYP::Make(bt_char,2); hsym->tp->sname = new std::string("_typeno"); hsym->tp->alignment = 2; tp->lst.insert(hsym); slc += 2; while( lastst != end) { if (lastst==kw_public) isPrivate = false; if (lastst==kw_private) isPrivate = true; if (lastst==kw_public || lastst==kw_private) { NextToken(); if (lastst==colon) NextToken(); } if (lastst==kw_unique || lastst==kw_static) { NextToken(); declare(sym,&(tp->lst),sc_static,slc,ztype); } else { if(ztype == bt_struct || ztype==bt_class) slc += declare(sym,&(tp->lst),sc_member,slc,ztype); else slc = imax(slc,declare(sym,&(tp->lst),sc_member,0,ztype)); } } bit_offset = 0; bit_next = 0; bit_width = -1; tp->size = tp->alignment ? tp->alignment : slc; NextToken(); isTypedef = ist; }