Exemplo n.º 1
0
uint16_t read16(struct memory* m, uint16_t addr) {
  if (!valid_ptr(m, addr)) {
    fprintf(stderr, "mmu: warning: read16\'ing bad address: %04X\n", addr);
    return 0;
  }
  return m->read16(m, addr);
}
Exemplo n.º 2
0
void write16(struct memory* m, uint16_t addr, uint16_t data) {
  if (!valid_ptr(m, addr)) {
    fprintf(stderr, "mmu: warning: write16\'ing bad address: %04X = %04X\n",
        addr, data);
    return;
  }
  m->write16(m, addr, data);
}
Exemplo n.º 3
0
	/**
	 * Convert the variable name pointed to by ptr into an name index into the variable table.
	 */
	CARIBOU::CString CTokenizer::variable_name(void)
	{
		CARIBOU::CString name;
		while ( valid_ptr(m_ptr) && (CARIBOU::CString::isalpha(*m_ptr) || isnum(*m_ptr) ||  *m_ptr == '_'  || *m_ptr == '$' || *m_ptr == '@' || *m_ptr == '#' )  )
		{
			name += *m_ptr++;
		}
		return name;
	}
Exemplo n.º 4
0
/**
 * Decrease reference count on buffer, and free it when it reaches 0.
 */
void
pdata_unref(pdata_t *db)
{
	g_assert(valid_ptr(db));
	g_assert(db->d_refcnt > 0);

	if (db->d_refcnt-- == 1)
		pdata_free(db);
}
Exemplo n.º 5
0
uint8_t read8(struct memory* m, uint16_t addr) {
  if (!valid_ptr(m, addr)) {
    fprintf(stderr, "mmu: warning: read8\'ing bad address: %04X\n", addr);
    return 0;
  }
  if (addr >= 0xFF00 && addr < 0xFF80)
    return io_read8(m, addr & 0xFF);
  if (addr == 0xFFFF)
    return read_interrupt_enable((struct regs*)m->devices[DEVICE_CPU], addr);
  return m->read8(m, addr);
}
Exemplo n.º 6
0
/**
 * Create an external (arena not embedded) data buffer out of existing arena.
 *
 * The optional `freecb' structure supplies the free routine callback to be
 * used to free the arena, with freearg as additional argument.  If the free
 * routine is NULL, then the external arena will be freed with g_free() when
 * the data buffer is reclaimed.
 */
pdata_t *
pdata_allocb_ext(void *buf, int len, pdata_free_t freecb, void *freearg)
{
	pdata_t *db;

	g_assert(valid_ptr(buf));
	g_assert(implies(freecb, valid_ptr(freecb)));

	WALLOC(db);
	db->magic = PDATA_MAGIC;
	db->d_arena = buf;
	db->d_end = (char *) buf + len;
	db->d_refcnt = 0;
	db->d_free = freecb;
	db->d_arg = freearg;

	g_assert((size_t) len == pdata_len(db));
	g_assert(db->d_arena != db->d_embedded);

	return db;
}
Exemplo n.º 7
0
void write8(struct memory* m, uint16_t addr, uint8_t data) {
  if (!valid_ptr(m, addr)) {
    fprintf(stderr, "mmu: warning: write8\'ing bad address: %04X = %02X\n",
        addr, data);
    return;
  }
  if (addr >= 0xFF00 && addr < 0xFF80)
    io_write8(m, addr & 0xFF, data);
  else if (addr == 0xFFFF)
    write_interrupt_enable((struct regs*)m->devices[DEVICE_CPU], addr, data);
  else
    m->write8(m, addr, data);
}
Exemplo n.º 8
0
/**
 * Create an embedded data buffer out of existing arena.
 *
 * The optional `freecb' structure supplies the free routine callback to be
 * used to free the arena, with freearg as additional argument.
 * If no free routine is specified (i.e. NULL given as `freecb'), then the
 * arena will be freed with wfree(buf, len) when the data buffer is reclaimed.
 */
pdata_t *
pdata_allocb(void *buf, int len, pdata_free_t freecb, void *freearg)
{
	pdata_t *db;

	g_assert(valid_ptr(buf));
	g_assert(UNSIGNED(len) >= EMBEDDED_OFFSET);
	g_assert(implies(freecb, valid_ptr(freecb)));

	db = buf;

	db->magic = PDATA_MAGIC;
	db->d_arena = db->d_embedded;
	db->d_end = db->d_arena + (len - EMBEDDED_OFFSET);
	db->d_refcnt = 0;
	db->d_free = freecb;
	db->d_arg = freearg;

	g_assert((size_t) len - EMBEDDED_OFFSET == pdata_len(db));

	return db;
}
Exemplo n.º 9
0
/**
 * Create new message from user provided data, which are copied into the
 * allocated data block.  If no user buffer is provided, an empty message
 * is created and the length is used to size the data block.
 *
 * @return a message made of one message block referencing one new data block.
 */
pmsg_t *
pmsg_new(int prio, const void *buf, int len)
{
	pmsg_t *mb;
	pdata_t *db;

	g_assert(len > 0);
	g_assert(implies(buf, valid_ptr(buf)));

	WALLOC(mb);
	db = pdata_new(len);

	return pmsg_fill(mb, db, prio, FALSE, buf, len);
}
Exemplo n.º 10
0
/**
 * Allocate new message using existing data block `db'.
 * The `roff' and `woff' are used to delimit the start and the end (first
 * unwritten byte) of the message within the data buffer.
 *
 * @return new message.
 */
pmsg_t *
pmsg_alloc(int prio, pdata_t *db, int roff, int woff)
{
	pmsg_t *mb;

	g_assert(valid_ptr(db));
	g_assert(roff >= 0 && (size_t) roff <= pdata_len(db));
	g_assert(woff >= 0 && (size_t) woff <= pdata_len(db));
	g_assert(woff >= roff);

	WALLOC(mb);

	pmsg_fill(mb, db, prio, FALSE, NULL, 0);

	mb->m_rptr += roff;
	mb->m_wptr += woff;

	return mb;
}
Exemplo n.º 11
0
/**
 * Like pmsg_new() but returns an extended form with a free routine callback.
 */
pmsg_t *
pmsg_new_extend(int prio, const void *buf, int len,
	pmsg_free_t free_cb, void *arg)
{
	pmsg_ext_t *emb;
	pdata_t *db;

	g_assert(len > 0);
	g_assert(implies(buf, valid_ptr(buf)));

	WALLOC(emb);
	db = pdata_new(len);

	emb->m_free = free_cb;
	emb->m_arg = arg;

	(void) pmsg_fill(&emb->pmsg, db, prio, TRUE, buf, len);

	return cast_to_pmsg(emb);
}
Exemplo n.º 12
0
bool  SqMod::construct(CtxMod* pctx)
{
    _pctx = pctx;
    _header_sent=false;
    if(_penv) {
        _penv->acquire();

        Sqrat::Class<SqMod> module;
        module.Func(_SC("write"), &SqMod::swrite);
        Sqrat::RootTable().SetInstance(_SC("_this"), this);

        //
        // _context
        //
        Sqrat::Table context;
        //Sqrat::Class<CtxMod> context;
        context.SetValue(_SC("urldoc"), pctx->_url_doc)
        .SetValue(_SC("urldir"),  pctx->_url_path)
        .SetValue(_SC("home"),    pctx->_dir_home)
        .SetValue(_SC("index"),   pctx->_doc_index)
        .SetValue(_SC("ip"),      pctx->_cli_ip);
        Sqrat::RootTable().Bind(_SC("_context"), context);

        //
        // _REQ table with _ARGS, GET, COOKIE and so on
        //
        Sqrat::Table headers;
        const KeyValx* ps = _pctx->_hdrs;
        while((ps)->key) {
            if(ps->val && *ps->val) {
                headers.SetValue(_SC(ps->key), _SC(ps->val));
            }
            ++ps;
        }
        Sqrat::RootTable().Bind(_SC("_request"), headers);


        Sqrat::Table ckooks;
        const KeyValx* psc = _pctx->_cookies;
        while((psc)->key) {
            if(psc->val && *psc->val) {
                ckooks.SetValue(_SC(psc->key), _SC(psc->val));
            }
            ++psc;
        }
        Sqrat::RootTable().Bind(_SC("_cookies"), ckooks);

        Sqrat::Table get;
        const KeyValx* psv = _pctx->_get;
        while((psv)->key) {
            if(psv->val && *psv->val) {
                get.SetValue(_SC(psv->key), _SC(psv->val));
            }
            ++psv;
        }
        Sqrat::RootTable().Bind(_SC("_get"), get);
        //Sqrat::RootTable().SetInstance(_SC("_ctx"), pctx);

        Sqrat::Table post;

        if(pctx->_tempfile) {
            // parse the post
            /*
            Content-Type: application/x-www-form-urlencoded
            Content-Length: 53

            realname=ssssssss&email=ddddddddddd&comments=wwwwwwww
            */
            const char* astype = _getHdr("CONTENT-TYPE")->val;
            int64_t len = atoll(_getHdr("CONTENT-LENGTH")->val);
            if(!str_cmp(astype,"application/x-www-form-urlencoded") && len < 16384) {
                char* buff = new char[len + 1];
                if(buff) {
                    int bytes = fread(buff, 1, len, pctx->_tempfile);
                    char* pwalk = buff;
                    assert(bytes == len);
                    buff[bytes] = 0;
                    do {
                        const char* key = str_up2chr(&pwalk, '=');
                        const char* val = str_up2chr(&pwalk, '&');
                        if(!valid_ptr(key) ||  !valid_ptr(val))
                            break;
                        post.SetValue(_SC(key), _SC(val));
                    } while(1);
                    delete []buff;
                }
            }
        }
        Sqrat::RootTable().Bind(_SC("_post"), post);
        return true;
    }
    return false;
}
Exemplo n.º 13
0
	/**
	 * Get the next token.
	 */
	CTokenizer::token_t CTokenizer::get_next_token()
	{
		token_t token=TOKEN_ERROR;

        if( static_cast<uint8_t>(*m_ptr) & (uint8_t)0x80 )  // compiled instruction?....
        {
            m_nextptr = m_ptr;
            token = (token_t)static_cast<uint8_t>(*m_ptr);
            ++m_nextptr;
            return token;
        }

		if(*m_ptr == 0)
		{
			return TOKEN_EOF;
		}

		if(isdigit(*m_ptr))
		{
		    uint8_t decimal_point=0;
		    for( m_nextptr = m_ptr; (isdigit(*m_nextptr) || *m_nextptr == '.') && decimal_point<=1; ++m_nextptr)
		    {
		        if ( *m_nextptr == '.' )
		        {
		            ++decimal_point;
		        }
		    }
			return TOKEN_NUMBER;
		}
		else if((token=singlechar()) != TOKEN_ERROR )
		{
			m_nextptr = m_ptr + 1;
			switch(token)
			{
			    case TOKEN_GT:
                    if ( *m_nextptr == '=' )
                        { token = TOKEN_GE; ++m_nextptr; }
                    else if ( *m_nextptr == '>' )
                        { token = TOKEN_SHR; ++m_nextptr; }
                    break;
			    case TOKEN_LT:
                    if ( *m_nextptr == '=' )
                        { token = TOKEN_LE; ++m_nextptr; }
                    else if ( *m_nextptr == '>' )
                        { token = TOKEN_NE; ++m_nextptr; }
                    else if ( *m_nextptr == '<' )
                        { token = TOKEN_SHL; ++m_nextptr; }
                    break;
                case TOKEN_BITWISEAND:
                    if ( *m_nextptr == '&' )
                        { token = TOKEN_LOGICAND; ++m_nextptr; }
                    break;
                case TOKEN_BITWISEOR:
                    if ( *m_nextptr == '|' )
                        { token = TOKEN_LOGICAND; ++m_nextptr; }
                    break;
			}
			return token;
		}
		else if(*m_ptr == '"')
		{
			m_nextptr = m_ptr;
			do
			{
				++m_nextptr;
			} while(valid_ptr(m_nextptr) && *m_nextptr != '"');
			if (valid_ptr(m_nextptr))
			{
				++m_nextptr;
				return TOKEN_STRING;
			}
			else
			{
				set_runtime_error( RUNTIME_OPEN_QUOTE );
				return TOKEN_ERROR;
			}
		}
		else if ( (token=keywordtok()) != TOKEN_ERROR )
		{
			return token;
		}

		if ( CARIBOU::CString::isalpha(*m_ptr) || *m_ptr == '_' )
		{
			/// Handle the case where it could be a variable or function...
			m_nextptr = m_ptr;
			while( valid_ptr(m_nextptr) && ( CARIBOU::CString::isalpha(*m_nextptr) || isnum(*m_nextptr) || *m_nextptr == '_' || *m_nextptr == '$' || *m_nextptr == '@' || *m_nextptr == '#' ) )
			{
				m_nextptr++;
			}
			if ( *m_nextptr == '(' )
			{
				token = functiontok();
				if ( token == TOKEN_ERROR )
				{
					set_runtime_error( RUNTIME_NO_SUCH_FUNCTION );
				}
				return token;
			}
            return TOKEN_VARIABLE;
		}

	  return TOKEN_ERROR;
	}