コード例 #1
0
ファイル: pic16c5x.c プロジェクト: Ezio-PS/mame2003-libretro
static void call(void)
{
	PUSH_STACK(R.PC);
	R.PC = ((R.STATUS & PA_REG) << 4) | R.opcode.b.l;
	R.PC &= 0x6ff;
	R.PCL = R.PC & 0xff;
}
コード例 #2
0
ファイル: dt_get_count.c プロジェクト: aosm/openmpi
int32_t ompi_ddt_set_element_count( const ompi_datatype_t* datatype, uint32_t count, size_t* length )
{
    dt_stack_t* pStack;   /* pointer to the position on the stack */
    uint32_t pos_desc;    /* actual position in the description of the derived datatype */
    int32_t stack_pos = 0;
    uint32_t local_length = 0;
    dt_elem_desc_t* pElems;

    /**
     * Handle all complete multiple of the datatype.
     */
    for( pos_desc = 4; pos_desc < DT_MAX_PREDEFINED; pos_desc++ ) {
        local_length += datatype->btypes[pos_desc];
    }
    pos_desc = count / local_length;
    count = count % local_length;
    *length = datatype->size * pos_desc;
    if( 0 == count ) {
        return 0;
    }

    DUMP( "dt_set_element_count( %p, %d )\n", (void*)datatype, count );
    pStack = (dt_stack_t*)alloca( sizeof(dt_stack_t) * (datatype->btypes[DT_LOOP] + 2) );
    pStack->count    = 1;
    pStack->index    = -1;
    pStack->disp     = 0;
    pElems           = datatype->desc.desc;
    pos_desc         = 0;

    while( 1 ) {  /* loop forever the exit condition is on the last DT_END_LOOP */
        if( DT_END_LOOP == pElems[pos_desc].elem.common.type ) { /* end of the current loop */
            if( --(pStack->count) == 0 ) { /* end of loop */
                stack_pos--; pStack--;
                if( stack_pos == -1 ) return 0;
            }
            pos_desc = pStack->index + 1;
            continue;
        }
        if( DT_LOOP == pElems[pos_desc].elem.common.type ) {
            ddt_loop_desc_t* loop = &(pElems[pos_desc].loop);
            do {
                PUSH_STACK( pStack, stack_pos, pos_desc, DT_LOOP, loop->loops, 0 );
                pos_desc++;
            } while( DT_LOOP == pElems[pos_desc].elem.common.type ); /* let's start another loop */
            DDT_DUMP_STACK( pStack, stack_pos, pElems, "advance loops" );
        }
        while( pElems[pos_desc].elem.common.flags & DT_FLAG_DATA ) {
            /* now here we have a basic datatype */
            const ompi_datatype_t* basic_type = BASIC_DDT_FROM_ELEM(pElems[pos_desc]);
            local_length = pElems[pos_desc].elem.count;
            if( local_length >= count ) {
                *length += count * basic_type->size;
                return 0;
            }
            *length += local_length * basic_type->size;
            count -= local_length;
            pos_desc++;  /* advance to the next data */
        }
    }
}
コード例 #3
0
ファイル: pic16c62x.c プロジェクト: BrandoCommando/mame
void pic16c62x_device::call()
{
	PUSH_STACK(m_PC);
	m_PC = ((m_PCLATH & 0x18) << 8) | (m_opcode.w.l & 0x7ff);
	m_PC &= ADDR_MASK;
	PCL = m_PC & 0xff;
}
コード例 #4
0
ファイル: dt_get_count.c プロジェクト: aosm/openmpi
/* Get the number of elements from the data-type that can be
 * retrieved from a received buffer with the size iSize.
 * To speed-up this function you should use it with a iSize == to the modulo
 * of the original size and the size of the data.
 * Return value:
 *   positive = number of basic elements inside
 *   negative = some error occurs
 */
int32_t ompi_ddt_get_element_count( const ompi_datatype_t* datatype, size_t iSize )
{
    dt_stack_t* pStack;   /* pointer to the position on the stack */
    uint32_t pos_desc;    /* actual position in the description of the derived datatype */
    int32_t nbElems = 0, stack_pos = 0;
	size_t local_size;
    dt_elem_desc_t* pElems;

    /* Normally the size should be less or equal to the size of the datatype.
     * This function does not support a iSize bigger than the size of the datatype.
     */
    assert( (uint32_t)iSize <= datatype->size );
    DUMP( "dt_count_elements( %p, %d )\n", (void*)datatype, iSize );
    pStack = (dt_stack_t*)alloca( sizeof(dt_stack_t) * (datatype->btypes[DT_LOOP] + 2) );
    pStack->count    = 1;
    pStack->index    = -1;
    pStack->disp     = 0;
    pElems           = datatype->desc.desc;
    pos_desc         = 0;

    while( 1 ) {  /* loop forever the exit condition is on the last DT_END_LOOP */
        if( DT_END_LOOP == pElems[pos_desc].elem.common.type ) { /* end of the current loop */
            if( --(pStack->count) == 0 ) { /* end of loop */
                stack_pos--; pStack--;
                if( stack_pos == -1 ) return nbElems;  /* completed */
            }
            pos_desc = pStack->index + 1;
            continue;
        }
        if( DT_LOOP == pElems[pos_desc].elem.common.type ) {
            ddt_loop_desc_t* loop = &(pElems[pos_desc].loop);
            do {
                PUSH_STACK( pStack, stack_pos, pos_desc, DT_LOOP, loop->loops, 0 );
                pos_desc++;
            } while( DT_LOOP == pElems[pos_desc].elem.common.type ); /* let's start another loop */
            DDT_DUMP_STACK( pStack, stack_pos, pElems, "advance loops" );
        }
        while( pElems[pos_desc].elem.common.flags & DT_FLAG_DATA ) {
            /* now here we have a basic datatype */
            const ompi_datatype_t* basic_type = BASIC_DDT_FROM_ELEM(pElems[pos_desc]);
            local_size = pElems[pos_desc].elem.count * basic_type->size;
            if( local_size >= iSize ) {
                local_size = iSize / basic_type->size;
                nbElems += (int32_t)local_size;
                iSize -= local_size * basic_type->size;
                return (iSize == 0 ? nbElems : -1);
            }
            nbElems += pElems[pos_desc].elem.count;
            iSize -= local_size;
            pos_desc++;  /* advance to the next data */
        }
    }
}
コード例 #5
0
int kthSmallest(struct TreeNode *root,int k){
	int counter = 0;
	struct TreeNode *current = root;
	while (current || !EMPTY_STACK()){
		while (current) {
			PUSH_STACK(current);
			current = current->left;
		}
		current = TOP_STACK();
		counter++;
		if (counter == k)
			return current->val; 
		POP_STACK();
		current = current->right;
	}
	return -1;
}
コード例 #6
0
ファイル: tms32051.c プロジェクト: LeWoY/MAMEHub
static void check_interrupts(tms32051_state *cpustate)
{
	int i;

	if (cpustate->st0.intm == 0 && cpustate->ifr != 0)
	{
		for (i=0; i < 16; i++)
		{
			if (cpustate->ifr & (1 << i))
			{
				cpustate->st0.intm = 1;
				PUSH_STACK(cpustate, cpustate->pc);

				cpustate->pc = (cpustate->pmst.iptr << 11) | ((i+1) << 1);
				cpustate->ifr &= ~(1 << i);

				save_interrupt_context(cpustate);
				break;
			}
		}
	}
}
コード例 #7
0
ファイル: tms32051.c プロジェクト: cdenix/ps3-mame-0125
static void check_interrupts(void)
{
	int i;

	if (tms.st0.intm == 0 && tms.ifr != 0)
	{
		for (i=0; i < 16; i++)
		{
			if (tms.ifr & (1 << i))
			{
				tms.st0.intm = 1;
				PUSH_STACK(tms.pc);

				tms.pc = (tms.pmst.iptr << 11) | ((i+1) << 1);
				tms.ifr &= ~(1 << i);

				save_interrupt_context();
				break;
			}
		}
	}
}
コード例 #8
0
ファイル: objcftl.c プロジェクト: dimpase/gap
Obj CollectPolycyc (
    Obj pcp,
    Obj list,
    Obj word )
{
    Int    ngens   = INT_INTOBJ( CONST_ADDR_OBJ(pcp)[ PC_NUMBER_OF_GENERATORS ] );
    Obj    commute = CONST_ADDR_OBJ(pcp)[ PC_COMMUTE ];

    Obj    gens    = CONST_ADDR_OBJ(pcp)[ PC_GENERATORS ];
    Obj    igens   = CONST_ADDR_OBJ(pcp)[ PC_INVERSES ];

    Obj    pow     = CONST_ADDR_OBJ(pcp)[ PC_POWERS ];
    Obj    ipow    = CONST_ADDR_OBJ(pcp)[ PC_INVERSEPOWERS ];
    Obj    exp     = CONST_ADDR_OBJ(pcp)[ PC_EXPONENTS ];

    Obj    wst  = CFTLState()->WORD_STACK;
    Obj    west = CFTLState()->WORD_EXPONENT_STACK;
    Obj    sst  = CFTLState()->SYLLABLE_STACK;
    Obj    est  = CFTLState()->EXPONENT_STACK;

    Obj    conj=0, iconj=0;   /*QQ initialize to please compiler */

    Int    st;

    Int    g, syl, h, hh;

    Obj    e, ee, ge, mge, we, s, t;
    Obj    w, x = (Obj)0, y = (Obj)0;


    if( LEN_PLIST(word) == 0 ) return (Obj)0;

    if( LEN_PLIST(list) < ngens ) {
        ErrorQuit( "vector too short", 0L, 0L );
        return (Obj)0;
    }
    if( LEN_PLIST(word) % 2 != 0 ) {
        ErrorQuit( "Length of word odd", 0L, 0L );
        return (Obj)0;
    }

    st = 0;
    PUSH_STACK( word, INTOBJ_INT(1) );

    while( st > 0 ) {

      w   = ELM_PLIST( wst, st );
      syl = INT_INTOBJ( ELM_PLIST( sst, st ) );
      g   = INT_INTOBJ( ELM_PLIST( w, syl )  );

      if( st > 1 && syl==1 && g == GET_COMMUTE(g) ) {
        /* Collect word^exponent in one go. */

        e = ELM_PLIST( west, st );

        /* Add in. */
        AddIn( list, w, e );

        /* Reduce. */
        for( h = g; h <= ngens; h++ ) {
          s = ELM_PLIST( list, h );
          if( IS_INT_ZERO( s ) ) continue;

          y = (Obj)0;
          if( (e = GET_EXPONENT( h )) != (Obj)0 ) {
              if( !LtInt( s, e ) ) {
                  t = ModInt( s, e );
                  SET_ELM_PLIST( list, h, t ); CHANGED_BAG( list );
                  if( (y = GET_POWER( h )) ) e = QuoInt( s, e );
              }
              else if( LtInt( s, INTOBJ_INT(0) ) ) {
                  t = ModInt( s, e );
                  SET_ELM_PLIST( list, h, t ); CHANGED_BAG( list );
              
                  if( (y = GET_IPOWER( h )) ) {
                      e = QuoInt( s, e );
                      if( !IS_INT_ZERO( t ) ) e = DiffInt( e, INTOBJ_INT(1) );
                      e = AInvInt(e);
                  }
              }
          }
          if( y != (Obj)0 ) AddIn( list, y, e );

        }

        st--;

      }
      else {
        if( g == GET_COMMUTE( g ) ) {
          s = ELM_PLIST( list, g ); 
          t = ELM_PLIST( est, st ); 
          C_SUM_FIA( ge, s, t );
          SET_ELM_PLIST( est, st, INTOBJ_INT(0) );
        }
        else {
          /* Assume that the top of the exponent stack is non-zero. */
          e = ELM_PLIST( est, st );
          
          if( LtInt( INTOBJ_INT(0), e ) ) {
            C_DIFF_FIA( ee, e, INTOBJ_INT(1) );  e = ee;
            SET_ELM_PLIST( est, st, e ); CHANGED_BAG( est );
            conj  = CONST_ADDR_OBJ(pcp)[PC_CONJUGATES];
            iconj = CONST_ADDR_OBJ(pcp)[PC_INVERSECONJUGATES];
            
            C_SUM_FIA( ge, ELM_PLIST( list, g ), INTOBJ_INT(1) );
          }
          else {
            C_SUM_FIA( ee, e, INTOBJ_INT(1) );  e = ee;
            SET_ELM_PLIST( est, st, e ); CHANGED_BAG( est );
            conj  = CONST_ADDR_OBJ(pcp)[PC_CONJUGATESINVERSE];
            iconj = CONST_ADDR_OBJ(pcp)[PC_INVERSECONJUGATESINVERSE];
            
            C_DIFF_FIA( ge, ELM_PLIST( list, g ), INTOBJ_INT(1) );
          }
        }
        SET_ELM_PLIST( list, g, ge );  CHANGED_BAG( list );


        /* Reduce the exponent.  We delay putting the power onto the 
           stack until all the conjugates are on the stack.  The power is
           stored in  y, its exponent in ge.  */
        y = (Obj)0;
        if( (e = GET_EXPONENT( g )) ) {
            if( !LtInt( ge, e ) ) {
                mge = ModInt( ge, e );
                SET_ELM_PLIST( list, g, mge ); CHANGED_BAG( list );
            
                if( (y = GET_POWER( g )) ) ge = QuoInt( ge, e );
            }
            else if( LtInt( ge, INTOBJ_INT(0) ) ) {
                mge = ModInt( ge, e );
                SET_ELM_PLIST( list, g, mge ); CHANGED_BAG( list );
            
                if( (y = GET_IPOWER( g )) ) {
                    ge = QuoInt( ge, e );
                    if( !IS_INT_ZERO( mge ) ) 
                        ge = DiffInt( ge, INTOBJ_INT(1) );
                    ge = AInvInt(ge);
                }
            }
        }
        
        hh = h = GET_COMMUTE( g );
        
        /* Find the place where we start to collect. */
        for( ; h > g; h-- ) {
            e = ELM_PLIST( list, h );
            if( !IS_INT_ZERO(e) ) {
            
                if( LtInt( INTOBJ_INT(0), e ) ) {
                    if( GET_CONJ( h, g ) ) break;
                }
                else {
                    if( GET_ICONJ( h, g ) ) break;
                }
            }
        }

        /* Put those onto the stack, if necessary. */
        if( h > g || y != (Obj)0 ) 
          for( ; hh > h; hh-- ) {
            e = ELM_PLIST( list, hh );
            if( !IS_INT_ZERO(e) ) {
              SET_ELM_PLIST( list, hh, INTOBJ_INT(0) );
              
              if( LtInt( INTOBJ_INT(0), e ) ) {
                  x = ELM_PLIST(  gens, hh );
              }
              else {
                  x = ELM_PLIST( igens, hh );
                  C_PROD_FIA( ee, e, INTOBJ_INT(-1) );  e = ee;
              }
              
              PUSH_STACK( x, e );
            }
          }
        
        
        for( ; h > g; h-- ) {
          e = ELM_PLIST( list, h );
          if( !IS_INT_ZERO(e) ) {
            SET_ELM_PLIST( list, h, INTOBJ_INT(0) );
            
            x = (Obj)0;
            if( LtInt( INTOBJ_INT(0), e ) ) x = GET_CONJ( h, g );
            else                            x = GET_ICONJ( h, g );
            
            if( x == (Obj)0 )  {
              if( LtInt( INTOBJ_INT(0), e ) ) x = ELM_PLIST(  gens, h );
              else                            x = ELM_PLIST( igens, h );
            
            }
            if( LtInt( e, INTOBJ_INT(0) ) ) {
              C_PROD_FIA( ee, e, INTOBJ_INT(-1) );  e = ee;
            }
            PUSH_STACK( x, e );
          }
        }
        
        if( y != (Obj)0 ) PUSH_STACK( y, ge );
      }

      while( st > 0 && IS_INT_ZERO( ELM_PLIST( est, st ) ) ) {
        w   = ELM_PLIST( wst, st );
        syl = INT_INTOBJ( ELM_PLIST( sst, st ) ) + 2;
        if( syl > LEN_PLIST( w ) ) {
          we = DiffInt( ELM_PLIST( west, st ), INTOBJ_INT(1) );
          if( EqInt( we, INTOBJ_INT(0) ) ) { st--; }
          else {
            SET_ELM_PLIST( west, st, we );
            SET_ELM_PLIST( sst,  st, INTOBJ_INT(1) );
            SET_ELM_PLIST( est,  st, ELM_PLIST( w, 2 ) );
            CHANGED_BAG( west ); CHANGED_BAG( est );
          }
        }
        else {
          SET_ELM_PLIST( sst, st, INTOBJ_INT(syl) );
          SET_ELM_PLIST( est, st, ELM_PLIST( w, syl+1 ));
          CHANGED_BAG( est );
        }
      }
    }

    return (Obj)0;
}
コード例 #9
0
ファイル: tms32010.c プロジェクト: broftkd/historic-mess
static void call(void)
{
	R.PC++ ;
	PUSH_STACK(R.PC);
	R.PC = M_RDOP_ARG((R.PC - 1)) & addr_mask;
}
コード例 #10
0
ファイル: tms32010.c プロジェクト: broftkd/historic-mess
static void cala(void)
{
	PUSH_STACK(R.PC);
	R.PC = R.ACC.w.l & addr_mask;
}
コード例 #11
0
ファイル: tms32010.c プロジェクト: stuartcarnie/MAME-OS-X
static void call(tms32010_state *cpustate)
{
    cpustate->PC++ ;
    PUSH_STACK(cpustate, cpustate->PC);
    cpustate->PC = M_RDOP_ARG((cpustate->PC - 1));
}
コード例 #12
0
ファイル: tms32010.cpp プロジェクト: RalfVB/mame
void tms32010_device::cala()
{
	PUSH_STACK(m_PC);
	m_PC = m_ACC.w.l & m_addr_mask;
}
コード例 #13
0
/* Convert data from multiple input buffers (as received from the network layer)
 * to a contiguous output buffer with a predefined size.
 * return OPAL_SUCCESS if everything went OK and if there is still room before the complete
 *          conversion of the data (need additional call with others input buffers )
 *        1 if everything went fine and the data was completly converted
 *       -1 something wrong occurs.
 */
int32_t
opal_unpack_general_function( opal_convertor_t* pConvertor,
                              struct iovec* iov,
                              uint32_t* out_size,
                              size_t* max_data )
{
    dt_stack_t* pStack;              /* pointer to the position on the stack */
    uint32_t pos_desc;               /* actual position in the description of the derived datatype */
    int32_t count_desc;              /* the number of items already done in the actual pos_desc */
    int type = OPAL_DATATYPE_INT8;   /* type at current position */
    OPAL_PTRDIFF_TYPE advance;       /* number of bytes that we should advance the buffer */
    OPAL_PTRDIFF_TYPE disp_desc = 0; /* compute displacement for truncated data */
    size_t bConverted = 0;           /* number of bytes converted this time */
    const opal_convertor_master_t* master = pConvertor->master;
    dt_elem_desc_t* description;
    OPAL_PTRDIFF_TYPE extent = pConvertor->pDesc->ub - pConvertor->pDesc->lb;
    size_t oCount = extent * pConvertor->count;
    size_t iCount, total_bytes_converted = 0;
    char* pInput;
    int32_t rc;
    uint32_t iov_count;

    /* For the general case always use the user data description */
    description = pConvertor->use_desc->desc;

    pStack = pConvertor->pStack + pConvertor->stack_pos;
    pos_desc   = pStack->index;
    count_desc = (int32_t)pStack->count;
    disp_desc  = pStack->disp;
    pStack--;
    pConvertor->stack_pos--;

    DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, description, "starting" );

    for( iov_count = 0; iov_count < (*out_size); iov_count++ ) {
        bConverted = 0;
        pInput = iov[iov_count].iov_base;
        iCount = iov[iov_count].iov_len;
        while( 1 ) {
            if( OPAL_DATATYPE_END_LOOP == description[pos_desc].elem.common.type ) { /* end of the current loop */
                if( --(pStack->count) == 0 ) { /* end of loop */
                    if( pConvertor->stack_pos == 0 ) {
                        goto save_and_return;  /* completed */
                    }
                    pConvertor->stack_pos--;
                    pStack--;
                    pos_desc++;
                } else {
                    pos_desc = pStack->index + 1;
                    if( pStack->index == -1 ) {
                        pStack->disp += extent;
                    } else {
                        assert( OPAL_DATATYPE_LOOP == description[pStack->index].elem.common.type );
                        pStack->disp += description[pStack->index].loop.extent;
                    }
                }
                count_desc = description[pos_desc].elem.count;
                disp_desc = description[pos_desc].elem.disp;
            }
            if( OPAL_DATATYPE_LOOP == description[pos_desc].elem.common.type ) {
                do {
                    PUSH_STACK( pStack, pConvertor->stack_pos,
                                pos_desc, OPAL_DATATYPE_LOOP, description[pos_desc].loop.loops, pStack->disp );
                    pos_desc++;
                } while( OPAL_DATATYPE_LOOP == description[pos_desc].loop.common.type ); /* let's start another loop */
                DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos, description, "advance loops" );
                /* update the current state */
                count_desc = description[pos_desc].elem.count;
                disp_desc = description[pos_desc].elem.disp;
            }
            while( description[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) {
                /* now here we have a basic datatype */
                type = description[pos_desc].elem.common.type;
                rc = master->pFunctions[type]( pConvertor, count_desc,
                                               pInput, iCount, opal_datatype_basicDatatypes[type]->size,
                                               pConvertor->pBaseBuf + pStack->disp + disp_desc,
                                               oCount, description[pos_desc].elem.extent, &advance );
                iCount -= advance;      /* decrease the available space in the buffer */
                pInput += advance;      /* increase the pointer to the buffer */
                bConverted += advance;
                if( rc != count_desc ) {
                    /* not all data has been converted. Keep the state */
                    count_desc -= rc;
                    disp_desc += rc * description[pos_desc].elem.extent;
                    goto save_and_return;
                }
                pos_desc++;  /* advance to the next data */
                count_desc = description[pos_desc].elem.count;
                disp_desc = description[pos_desc].elem.disp;
                if( iCount == 0 )
                    goto save_and_return;  /* break if there is no more data in the buffer */
            }
        }
    save_and_return:
        pConvertor->bConverted += bConverted;  /* update the # of bytes already converted */
        iov[iov_count].iov_len = bConverted;           /* update the iovec length */
        total_bytes_converted += bConverted;
    }
    *max_data = total_bytes_converted;
    /* out of the loop: we have complete the data conversion or no more space
     * in the buffer.
     */
    if( pConvertor->remote_size == pConvertor->bConverted ) {
        pConvertor->flags |= CONVERTOR_COMPLETED;
        return 1;  /* I'm done */
    }

    /* I complete an element, next step I should go to the next one */
    PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, type,
                count_desc, disp_desc );

    return 0;
}
コード例 #14
0
int main(int argc, char **argv)
{
	/*
	 * VARIABLES
	 */

	/* simple counter */
	int i = 1;

	/* getopt_long-options */
	static struct option long_options[] = {
		{"dist", required_argument, 0, 'd'},
		{"in", required_argument, 0, 'i'},
		{"out", required_argument, 0, 'o'},
		{0, 0, 0, 0}
	};

	/* Filepointers to in and outfile */
	FILE *in;
	FILE *out = NULL;

	/* a string containing the name of the distro we are working on */
	const char *distro = NULL;

	/* filenames, of in and outfiles */
	const char *infile = NULL;
	const char *outfile = NULL;

	/* temporary data storage */
	const char *data;

	/* space to get the line we are parsing */
	char line[LINE_LEN];

	/* if parsing an #exec, fill this string with #exec data */
	char exec_buffer[EXEC_BUFFER_LEN];

	/* The maximum exec_buffer lengt we have left to fill */
	int exec_buffer_free = EXEC_BUFFER_LEN - 1;

	/* Current line number in input */
	int lineno = 0;

	/* Stack - please use the macros defined below, if possible */
	struct {
		enum_block block_type;
		int process_elses;
		int print_out;
		int lineno;
	} stack[16];

	int stack_top = 0;

#define POP_STACK --stack_top
#define PUSH_STACK(type) ( stack[stack_top].process_elses = BLOCK_PRINTS_OUT, \
                           stack[stack_top].print_out = BLOCK_PRINTS_OUT, \
                           stack[stack_top].lineno = lineno, \
                           stack[stack_top++].block_type = type)
#define BLOCK_PRINTS_OUT ( stack_top ? stack[stack_top-1].print_out : 1 )
#define STACK_EMPTY ( stack_top == 0 )
#define STACK_TOP ( stack[stack_top-1] )
#define IN_BLOCK (  stack_top ? stack[stack_top-1].block_type : 0 )

	/*
	 *  CODE
	 */

	/* parse and fill path struct */
	path = str_split(getenv("PATH"), ':');
	if (!path) {
		fprintf(stderr, "  **\tERROR: could not get $PATH\n");
		exit(1);
	}

	/* Parse initial arguments */
	while (-1 !=
	       (i = getopt_long(argc, argv, "hi:o:d:", long_options, NULL))) {
		switch (i) {
			/* set the distro manually */
		case 'd':
			distro = optarg;
			break;
			/* set the file to parse */
		case 'i':
			infile = optarg;
			break;
			/* set the outfile manually */
		case 'o':
			outfile = optarg;
			break;
		default:
			fprintf(stdout, "Ups, what's that? <0%o>\n", i);
		}
	}

	/* if not set, probe it */
	if (!distro)
		distro = probe_distribution();
	if (!distro) {
		fprintf(stderr, "  **\tUnknown DISTRIBUTION\n");
		exit(1);
	}
	fprintf(stderr, "  **\tDistribution set: \"%s\"\n", distro);

	/* load the overlay */
	{
		int j;
		char file[200];

		/* reset the ovelay */
		for (j = 0; j < 1000; j++) {
			overlay[j].opt = NULL;
			overlay[j].value = NULL;
		}

		/* and distro dependent overlay, found in workdir */
		sprintf(file, "%s.overlay", distro);
		load_overlay_file(file);

		/* a standard path for overlay */
		strcpy(file, INITNG_ROOT);
		strcat(file, "/initng.overlay");
		load_overlay_file(file);

		/*printf("Overlays found:\n");
		   for(j=0;j<1000 && overlay[j].opt;j++)
		   {
		   printf(" \"%s\" == \"%s\"\n", overlay[j].opt, overlay[j].value);
		   } */

	}

	/* open input for writing */
	if (!infile) {
		fprintf(stderr, "  **\tYou have to set input file with -i\n");
		exit(1);
	}
	if (!(in = fopen(infile, "r"))) {
		fprintf(stderr, "  **\tcould not open input file!\n");
		exit(1);
	}

	/* make sure input is service.s */
	if (!strstr(infile, ".s")) {
		printf("install_service_file only handles *.s files!\n");
		exit(1);
	}

	/* open output for writing */
	if (!outfile) {
		if (strstr(infile, ".s")) {
			outfile = strndup(infile, strlen(infile) - 2);
		} else {
			fprintf(stderr, "  **\tout with -o not set, "
				"defaulting to stdout.\n");
			out = stdout;
		}
	}
	if (!out && !(out = fopen(outfile, "w"))) {
		fprintf(stderr, "  **\tcould not open output file!\n");
		exit(1);
	}

	/* Print header */
	fprintf(out, "#!/sbin/runiscript\n"
		"# This is an init script file, used by initng.\n\n");

	/* Okay, go parse every line */
	while (fgets(line, LINE_LEN, in)) {
		lineno++;

		/*
		 * This is an internal set, to force an standard default path,
		 * please us an direct @/usr/sbin/gdm@ instead.
		 */
		if (match("#atdefpath", line)) {
			D_("found #atdefpath. updating at default path\n");

			/* get the data after #atdefpath data */
			data = skip_spaces(line + LEN("#atdefpath"));

			/* free previous fore path */
			if (at_default_path)
				free(at_default_path);

			/* allocate an new one */
			at_default_path = malloc(strlen(data) + 1);

			/* copy the data */
			i = 0;
			while (data[i] && data[i] != ' ' && data[i] != '\t'
			       && data[i] != '\n') {
				at_default_path[i] = data[i];
				i++;
			}
			at_default_path[i] = '\0';

			D_("at_default_path updated to %s\n", at_default_path);

			/* explain */
			at_default_paths = str_split(at_default_path, ':');
			continue;
		}

		/* If this is an ordinary line, not starting with an # */
		if (STACK_EMPTY && line[0] != '#') {
			/* youst print it to outfile */
			print_it(out, line);
			continue;	/* read next line */
		}

		/* either in_block != 0 or line started with '#' */
		if (IN_BLOCK == EXEC_BLOCK) {
			/* in_block == EXEC_BLOCK */
			if (match("#endexec", line)) {
				D_("found #endexec, line %i\n", lineno);
				/* Do the exec shit */
				if (BLOCK_PRINTS_OUT) {
					data =
					    do_exec(exec_buffer,
						    strlen(exec_buffer));
					if (data) {
						print_it(out, data);
						free((void *)data);
					}
				}
				POP_STACK;
				continue;
			} else {
				strncat(exec_buffer, line, exec_buffer_free);
				exec_buffer_free -= strlen(line);
				continue;
			}

		} else {

			/* #exec is an internal run, and output will be
			 * outputed to outfile */
			if (match("#exec", line)) {
				D_("found #exec, line %i\n", lineno);
				exec_buffer[0] = '\0';
				exec_buffer_free = EXEC_BUFFER_LEN - 1;
				PUSH_STACK(EXEC_BLOCK);
				continue;
			}

			else if (match("#endexec", line)) {
				fprintf(stderr, "ERROR: #endexec without "
					"#exec, line %i\n", lineno);
				fclose(out);
				if (outfile)
					unlink(outfile);
				exit(1);
			}

			/* #ifd debian, meens utput this to outfile if
			 * distro == debian */
			else if (match("#ifd", line)) {
				D_("found #ifd, line %i\n", lineno);
				PUSH_STACK(IF_BLOCK);
				STACK_TOP.print_out = 0;
				if (STACK_TOP.process_elses
				    && match_distro(line, distro)) {
					D_("actual distro %s matches line "
					   "%i: %s\n", distro, lineno, line);
					STACK_TOP.print_out = 1;
					STACK_TOP.process_elses = 0;
				}
				continue;
			}

			else if (match("#elsed", line)) {
				if (IN_BLOCK != IF_BLOCK) {
					fprintf(stderr, "ERROR: unexpected "
						"#elsed, line %i\n", lineno);
					fclose(out);
					if (outfile)
						unlink(outfile);
					exit(1);
				}
				if (STACK_TOP.process_elses) {
					if (empty_elsed(line) ||
					    match_distro(line, distro)) {
						STACK_TOP.print_out = 1;
						STACK_TOP.process_elses = 0;
					}
				} else {
					STACK_TOP.print_out = 0;
				}
			}

			else if (match("#endd", line)) {
				if (IN_BLOCK != IF_BLOCK) {
					fprintf(stderr, "ERROR: unexpected "
						"#endd, line %i\n", lineno);
					fclose(out);
					if (outfile)
						unlink(outfile);
					exit(1);
				}
				POP_STACK;
			} else {
				/* it's just an ordinary line */
				if (BLOCK_PRINTS_OUT)
					print_it(out, line);
				continue;	/* read next line */
			}
		}
	}

	if (!STACK_EMPTY) {
		while (!STACK_EMPTY) {
			if (IN_BLOCK == EXEC_BLOCK)
				fprintf(stderr, "ERROR: missing #endexec for "
					"#exec on line %i\n",
					STACK_TOP.lineno);
			else
				fprintf(stderr, "ERROR: missing #endd for "
					"#ifd on line %i\n", STACK_TOP.lineno);
			POP_STACK;
		}
		fclose(out);
		if (outfile)
			unlink(outfile);
		exit(1);
	}

#if 0 /* We don't really need to free anything, 'coz we will exit soon */
	/* free the overlay table */
	for (i = 0; i < 1000 && overlay[i].opt; i++) {
		free((char *)overlay[i].opt);	/* const-cast */
		overlay[i].opt = NULL;
		if (overlay[i].value) {
			free((char *)overlay[i].value);	/* const-cast */
			overlay[i].value = NULL;
		}
	}
#endif

	/* close bouth input and output file */
	fclose(in);
	fclose(out);

	if (outfile) {
		chmod(outfile, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
		      S_IXGRP | S_IROTH | S_IXOTH);
	}

	return 0;
}
コード例 #15
0
static int32_t
opal_datatype_optimize_short( opal_datatype_t* pData,
                         int32_t count,
                         dt_type_desc_t* pTypeDesc )
{
    dt_elem_desc_t* pElemDesc;
    ddt_elem_desc_t opt_elem;
    dt_stack_t* pStack;            /* pointer to the position on the stack */
    int32_t pos_desc = 0;          /* actual position in the description of the derived datatype */
    int32_t stack_pos = 0, last_type = OPAL_DATATYPE_UINT1, last_length = 0;
    int32_t type = OPAL_DATATYPE_LOOP, nbElems = 0, continuity;
    OPAL_PTRDIFF_TYPE total_disp = 0, last_extent = 1, last_disp = 0;
    uint16_t last_flags = 0xFFFF;  /* keep all for the first datatype */
    uint32_t i;

    pStack = (dt_stack_t*)alloca( sizeof(dt_stack_t) * (pData->btypes[OPAL_DATATYPE_LOOP]+2) );
    SAVE_STACK( pStack, -1, 0, count, 0 );

    pTypeDesc->length = 2 * pData->desc.used + 1 /* for the fake OPAL_DATATYPE_END_LOOP at the end */;
    pTypeDesc->desc = pElemDesc = (dt_elem_desc_t*)malloc( sizeof(dt_elem_desc_t) * pTypeDesc->length );
    pTypeDesc->used = 0;

    SET_EMPTY_ELEMENT( &opt_elem );
    assert( OPAL_DATATYPE_END_LOOP == pData->desc.desc[pData->desc.used].elem.common.type );
    opt_elem.common.type = OPAL_DATATYPE_LOOP;
    opt_elem.common.flags = 0xFFFF;  /* keep all for the first datatype */
    opt_elem.count = 0;
    opt_elem.disp = pData->desc.desc[pData->desc.used].end_loop.first_elem_disp;
    opt_elem.extent = 0;

    while( stack_pos >= 0 ) {
        if( OPAL_DATATYPE_END_LOOP == pData->desc.desc[pos_desc].elem.common.type ) { /* end of the current loop */
            ddt_endloop_desc_t* end_loop = &(pData->desc.desc[pos_desc].end_loop);
            if( last_length != 0 ) {
                CREATE_ELEM( pElemDesc, last_type, OPAL_DATATYPE_FLAG_BASIC, last_length, last_disp, last_extent );
                pElemDesc++; nbElems++;
                last_disp += last_length;
                last_length = 0;
            }
            CREATE_LOOP_END( pElemDesc, nbElems - pStack->index + 1,  /* # of elems in this loop */
                             end_loop->first_elem_disp, end_loop->size, end_loop->common.flags );
            pElemDesc++; nbElems++;
            if( --stack_pos >= 0 ) {  /* still something to do ? */
                ddt_loop_desc_t* pStartLoop = &(pTypeDesc->desc[pStack->index - 1].loop);
                pStartLoop->items = (pElemDesc - 1)->elem.count;
                total_disp = pStack->disp;  /* update the displacement position */
            }
            pStack--;  /* go down one position on the stack */
            pos_desc++;
            continue;
        }
        if( OPAL_DATATYPE_LOOP == pData->desc.desc[pos_desc].elem.common.type ) {
            ddt_loop_desc_t* loop = (ddt_loop_desc_t*)&(pData->desc.desc[pos_desc]);
            ddt_endloop_desc_t* end_loop = (ddt_endloop_desc_t*)&(pData->desc.desc[pos_desc + loop->items]);
            int index = GET_FIRST_NON_LOOP( &(pData->desc.desc[pos_desc]) );
            OPAL_PTRDIFF_TYPE loop_disp = pData->desc.desc[pos_desc + index].elem.disp;

            continuity = ((last_disp + last_length * (OPAL_PTRDIFF_TYPE)opal_datatype_basicDatatypes[last_type]->size)
                              == (total_disp + loop_disp));
            if( loop->common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS ) {
                /* the loop is contiguous or composed by contiguous elements with a gap */
                if( loop->extent == (OPAL_PTRDIFF_TYPE)end_loop->size ) {
                    /* the whole loop is contiguous */
                    if( !continuity ) {
                        if( 0 != last_length ) {
                            CREATE_ELEM( pElemDesc, last_type, OPAL_DATATYPE_FLAG_BASIC,
                                         last_length, last_disp, last_extent );
                            pElemDesc++; nbElems++;
                            last_length = 0;
                        }
                        last_disp = total_disp + loop_disp;
                    }
                    last_length = (last_length * opal_datatype_basicDatatypes[last_type]->size
                                   + loop->loops * end_loop->size);
                    last_type   = OPAL_DATATYPE_UINT1;
                    last_extent = 1;
                } else {
                    int counter = loop->loops;
                    OPAL_PTRDIFF_TYPE merged_disp = 0;
                    /* if the previous data is contiguous with this piece and it has a length not ZERO */
                    if( last_length != 0 ) {
                        if( continuity ) {
                            last_length *= opal_datatype_basicDatatypes[last_type]->size;
                            last_length += end_loop->size;
                            last_type    = OPAL_DATATYPE_UINT1;
                            last_extent  = 1;
                            counter--;
                            merged_disp = loop->extent;  /* merged loop, update the disp of the remaining elems */
                        }
                        CREATE_ELEM( pElemDesc, last_type, OPAL_DATATYPE_FLAG_BASIC,
                                     last_length, last_disp, last_extent );
                        pElemDesc++; nbElems++;
                        last_disp += last_length;
                        last_length = 0;
                        last_type = OPAL_DATATYPE_LOOP;
                    }
                    /**
                     * The content of the loop is contiguous (maybe with a gap before or after).
                     *
                     * If any of the loops have been merged with the previous element, then the
                     * displacement of the first element (or the displacement of all elements if the
                     * loop will be removed) must be updated accordingly.
                     */
                    if( counter <= 2 ) {
                        merged_disp += end_loop->first_elem_disp;
                        while( counter > 0 ) {
                            CREATE_ELEM( pElemDesc, OPAL_DATATYPE_UINT1, OPAL_DATATYPE_FLAG_BASIC,
                                         end_loop->size, merged_disp, 1);
                            pElemDesc++; nbElems++; counter--;
                            merged_disp += loop->extent;
                        }
                    } else {
                        CREATE_LOOP_START( pElemDesc, counter, 2, loop->extent, loop->common.flags );
                        pElemDesc++; nbElems++;
                        CREATE_ELEM( pElemDesc, OPAL_DATATYPE_UINT1, OPAL_DATATYPE_FLAG_BASIC,
                                     end_loop->size, loop_disp, 1);
                        pElemDesc++; nbElems++;
                        CREATE_LOOP_END( pElemDesc, 2, end_loop->first_elem_disp + merged_disp,
                                         end_loop->size, end_loop->common.flags );
                        pElemDesc++; nbElems++;
                    }
                }
                pos_desc += loop->items + 1;
            } else {
                ddt_elem_desc_t* elem = (ddt_elem_desc_t*)&(pData->desc.desc[pos_desc+1]);
                if( last_length != 0 ) {
                    CREATE_ELEM( pElemDesc, last_type, OPAL_DATATYPE_FLAG_BASIC, last_length, last_disp, last_extent );
                    pElemDesc++; nbElems++;
                    last_disp  += last_length;
                    last_length = 0;
                    last_type   = OPAL_DATATYPE_LOOP;
                }
                if( 2 == loop->items ) { /* small loop */
                    if( (1 == elem->count)
                        && (elem->extent == (OPAL_PTRDIFF_TYPE)opal_datatype_basicDatatypes[elem->common.type]->size) ) {
                        CREATE_ELEM( pElemDesc, elem->common.type, elem->common.flags & ~OPAL_DATATYPE_FLAG_CONTIGUOUS,
                                     loop->loops, elem->disp, loop->extent );
                        pElemDesc++; nbElems++;
                        pos_desc += loop->items + 1;
                        goto complete_loop;
                    } else if( loop->loops < 3 ) {
                        OPAL_PTRDIFF_TYPE elem_displ = elem->disp;
                        for( i = 0; i < loop->loops; i++ ) {
                            CREATE_ELEM( pElemDesc, elem->common.type, elem->common.flags,
                                         elem->count, elem_displ, elem->extent );
                            elem_displ += loop->extent;
                            pElemDesc++; nbElems++;
                        }
                        pos_desc += loop->items + 1;
                        goto complete_loop;
                    }
                }
                CREATE_LOOP_START( pElemDesc, loop->loops, loop->items, loop->extent, loop->common.flags );
                pElemDesc++; nbElems++;
                PUSH_STACK( pStack, stack_pos, nbElems, OPAL_DATATYPE_LOOP, loop->loops, total_disp );
                pos_desc++;
                DDT_DUMP_STACK( pStack, stack_pos, pData->desc.desc, "advance loops" );
            }
        complete_loop:
            total_disp = pStack->disp;  /* update the displacement */
            continue;
        }
        while( pData->desc.desc[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) {  /* keep doing it until we reach a non datatype element */
            /* now here we have a basic datatype */
            type = pData->desc.desc[pos_desc].elem.common.type;
            continuity = ((last_disp + last_length * (OPAL_PTRDIFF_TYPE)opal_datatype_basicDatatypes[last_type]->size)
                          == (total_disp + pData->desc.desc[pos_desc].elem.disp));

            if( (pData->desc.desc[pos_desc].elem.common.flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) && continuity &&
                (pData->desc.desc[pos_desc].elem.extent == (int32_t)opal_datatype_basicDatatypes[type]->size) ) {
                if( type == last_type ) {
                    last_length += pData->desc.desc[pos_desc].elem.count;
                    last_extent = pData->desc.desc[pos_desc].elem.extent;
                } else {
                    if( last_length == 0 ) {
                        last_type = type;
                        last_length = pData->desc.desc[pos_desc].elem.count;
                        last_extent = pData->desc.desc[pos_desc].elem.extent;
                    } else {
                        last_length = last_length * opal_datatype_basicDatatypes[last_type]->size +
                            pData->desc.desc[pos_desc].elem.count * opal_datatype_basicDatatypes[type]->size;
                        last_type = OPAL_DATATYPE_UINT1;
                        last_extent = 1;
                    }
                }
                last_flags &= pData->desc.desc[pos_desc].elem.common.flags;
            } else {
                if( last_length != 0 ) {
                    CREATE_ELEM( pElemDesc, last_type, OPAL_DATATYPE_FLAG_BASIC, last_length, last_disp, last_extent );
                    pElemDesc++; nbElems++;
                }
                last_disp = total_disp + pData->desc.desc[pos_desc].elem.disp;
                last_length = pData->desc.desc[pos_desc].elem.count;
                last_extent = pData->desc.desc[pos_desc].elem.extent;
                last_type = type;
            }
            pos_desc++;  /* advance to the next data */
        }
    }

    if( last_length != 0 ) {
        CREATE_ELEM( pElemDesc, last_type, OPAL_DATATYPE_FLAG_BASIC, last_length, last_disp, last_extent );
        pElemDesc++; nbElems++;
    }
    /* cleanup the stack */
    pTypeDesc->used = nbElems - 1;  /* except the last fake END_LOOP */
    return OPAL_SUCCESS;
}
コード例 #16
0
ファイル: tms32010.cpp プロジェクト: RalfVB/mame
void tms32010_device::call()
{
	m_PC++ ;
	PUSH_STACK(m_PC);
	m_PC = M_RDOP_ARG((m_PC - 1));
}
コード例 #17
0
ファイル: tms32010.c プロジェクト: stuartcarnie/MAME-OS-X
static void cala(tms32010_state *cpustate)
{
    PUSH_STACK(cpustate, cpustate->PC);
    cpustate->PC = cpustate->ACC.w.l & cpustate->addr_mask;
}