Exemplo n.º 1
0
tmpl(/**/)::VciBlockDevice(
    sc_module_name name,
    const MappingTable &mt,
    const IntTab &srcid,
    const IntTab &tgtid,
    const std::string &filename,
    const uint32_t block_size, 
    const uint32_t latency)
	: caba::BaseModule(name),
	  m_vci_target_fsm(p_vci_target, mt.getSegmentList(tgtid)),
	  m_vci_init_fsm(p_vci_initiator, mt.indexForId(srcid)),
      m_block_size(block_size),
      m_latency(latency),
      p_clk("clk"),
      p_resetn("resetn"),
      p_vci_target("vci_target"),
      p_vci_initiator("vci_initiator"),
      p_irq("irq")
{
	m_vci_target_fsm.on_read_write(on_read, on_write);

    m_fd = ::open(filename.c_str(), O_RDWR);
    if ( m_fd < 0 ) {
        std::cerr << "Unable to open block device image file " << filename << std::endl;
        m_device_size = 0;
    } else {
        m_device_size = lseek(m_fd, 0, SEEK_END) / m_block_size;
        if ( m_device_size > ((uint64_t)1<<(vci_param::B*8)) ) {
            std::cerr
                << "Warning: block device " << filename
                << " has more blocks than addressable with "
                << (8*vci_param::B) << "." << std::endl;
            m_device_size = ((uint64_t)1<<(vci_param::B*8));
        }
    }
#ifdef SOCLIB_MODULE_DEBUG
    std::cout 
        << name
        << " = Opened " 
        << filename
        << " which has "
        << m_device_size
        << " blocks of "
        << m_block_size
        << " bytes"
        << std::endl;
#endif

	SC_METHOD(transition);
	dont_initialize();
	sensitive << p_clk.pos();

	SC_METHOD(genMoore);
	dont_initialize();
	sensitive << p_clk.neg();
}
Exemplo n.º 2
0
UTF32String StringPrep::MapCharacter(unsigned c, MappingTable map)
{
	if(map.find(c) != map.end())
	{
		return map[c];
	}
	else
	{
		return UTF32String(1, c);
	}
}
Exemplo n.º 3
0
void Alcatraz::rmdir_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;

    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, false, tempname);
    switch(maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break ;
    case PATH_DELETED:{
	arch->abortCall(pid, -1, ENOENT);
	break ;
    }		   
    case PATH_CREATED: 
    case PATH_MODIFIED:{
	int retval = rmdir(buf) ;
	if (0 == retval) {
	    mt.delMapping(tempname) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("D", normpath, "N/A", "DE", pid, ppid) ;
#endif
	} else {
	    arch->abortCall(pid, -1, errno) ;
	}
	break ;
    }
    case PATH_NEW:{
	int retval = rmdir_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	} else {
	    mt.newDelete(TYPE_DIRECTORY, buf) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("D", buf, "N/A", "DE", pid, ppid) ;
#endif
	}
	break ;
    }
    default:
	break; 
    }

}
Exemplo n.º 4
0
tmpl(/**/)::VciTimer(
    sc_module_name name,
    const IntTab &index,
    const MappingTable &mt,
    size_t nirq)
	: caba::BaseModule(name),
	  m_vci_fsm(p_vci, mt.getSegmentList(index)),
      m_ntimer(nirq),
      r_value(soclib::common::alloc_elems<sc_signal<typename vci_param::data_t> >("value", m_ntimer)),
      r_period(soclib::common::alloc_elems<sc_signal<typename vci_param::data_t> >("period", m_ntimer)),
      r_counter(soclib::common::alloc_elems<sc_signal<typename vci_param::data_t> >("counter", m_ntimer)),
      r_mode(soclib::common::alloc_elems<sc_signal<int> >("mode", m_ntimer)),
      r_irq(soclib::common::alloc_elems<sc_signal<bool> >("saved_irq", m_ntimer)),
      p_clk("clk"),
      p_resetn("resetn"),
      p_vci("vci"),
      p_irq(soclib::common::alloc_elems<sc_out<bool> >("irq", m_ntimer))
{
	m_vci_fsm.on_read_write(on_read, on_write);

	SC_METHOD(transition);
	dont_initialize();
	sensitive << p_clk.pos();

	SC_METHOD(genMoore);
	dont_initialize();
	sensitive << p_clk.neg();
}
Exemplo n.º 5
0
void Alcatraz::unlink_exit()
{
    if (state != -1 && mp->currentRC() == 0) {
	switch (state) {
	case 0:
	    mt.delMapping(tempname) ;
	    break ;
	case 1:
	    mt.delMapping(tempname) ;
	    mt.newDelete(TYPE_FILE, tempname) ;
	    break ;
	default:
	    break ;
	}
    }
}
Exemplo n.º 6
0
MappingTable StringPrep::RangeTableToMappingTable(
	RangeTable rangeTable,
	UTF32String mapTo)
{
	typedef std::pair<unsigned, UTF32String> pair;
	MappingTable m;

	for(RangeTable::const_iterator i = rangeTable.begin();
		i != rangeTable.end(); i++)
	{
		for(unsigned j = i->first; j <= i->second; j++)
		{
			m.insert(pair(j,mapTo));
		}
	}
	return m;
}
Exemplo n.º 7
0
void Alcatraz::mknod_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;
	    
    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, false, tempname);
    switch (maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break; 
    case PATH_DELETED:{
	mt.delMapping(tempname) ;
	char tempfile[PATH_MAX] ;
	mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ;
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
	arg0.set(tempfile) ;
	break ;
    }		    
    case PATH_CREATED:
    case PATH_MODIFIED:
	arg0.set(buf) ;
	break ;
    case PATH_NEW :{
	int retval = mknod_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	} else {
	    char tempfile[PATH_MAX] ;
	    mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ;
	    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
	}
    }
    }
}
Exemplo n.º 8
0
tmpl(/**/)::VciXicu( sc_core::sc_module_name name,
                     const MappingTable      &mt,
                     const                   IntTab &index,
                     size_t                  pti_count,
                     size_t                  hwi_count,
                     size_t                  wti_count,
                     size_t                  irq_count )
           : caba::BaseModule(name),
           m_seglist( mt.getSegmentList(index) ),
           m_pti_count( pti_count ),
           m_hwi_count( hwi_count ),
           m_wti_count( wti_count ),
           m_irq_count( irq_count ),

           r_fsm( "r_fsm" ),
           r_data( "r_data" ),
           r_srcid( "r_srcid" ),
           r_trdid( "r_trdid" ),
           r_pktid( "r_pktid" ),
           r_msk_pti( alloc_elems<sc_signal<uint32_t> >("r_msk_pti" , irq_count) ),
           r_msk_wti( alloc_elems<sc_signal<uint32_t> >("r_msk_wti" , irq_count) ),
           r_msk_hwi( alloc_elems<sc_signal<uint32_t> >("r_msk_hwi" , irq_count) ),
           r_pti_pending( "r_pti_pending" ),
           r_wti_pending( "r_wti_pending" ),
           r_hwi_pending( "r_hwi_pending" ),
           r_pti_per( alloc_elems<sc_signal<uint32_t> >("r_pti_per" , pti_count) ),
           r_pti_val( alloc_elems<sc_signal<uint32_t> >("r_pti_val" , pti_count) ),
           r_wti_reg( alloc_elems<sc_signal<uint32_t> >("r_wti_reg" , wti_count) ),

           p_clk( "clk" ),
           p_resetn( "resetn" ),
           p_vci( "vci" ),
           p_irq( alloc_elems<sc_core::sc_out<bool> >("irq", irq_count) ),
           p_hwi( alloc_elems<sc_core::sc_in<bool> >("hwi", hwi_count) )
{
    std::cout << "  - Building VciXicu : " << name << std::endl;

    std::list<soclib::common::Segment>::iterator seg;
    for ( seg = m_seglist.begin() ; seg != m_seglist.end() ; seg++ )
    {
        std::cout << "    => segment " << seg->name()
                  << " / base = " << std::hex << seg->baseAddress()
                  << " / size = " << seg->size() << std::endl; 
    }
 
	SC_METHOD(transition);
	dont_initialize();
	sensitive << p_clk.pos();

	SC_METHOD(genMoore);
	dont_initialize();
	sensitive << p_clk.neg();
}
Exemplo n.º 9
0
MappingTable StringPrep::GenerateMappingTable(
	const unsigned* mappingArray,
	unsigned mappingArraySize,
	unsigned separator)
{
	typedef std::pair<unsigned, UTF32String> pair;
	MappingTable m;
	unsigned i = 0;

	while(i < mappingArraySize)
	{
		unsigned key = mappingArray[i];
		i += 2;

		UTF32String value;
		for(;mappingArray[i] != separator && i < mappingArraySize; i++)
			value.push_back(mappingArray[i]);

		m.insert(pair(key, value));
	}
	return m;
}
Exemplo n.º 10
0
VciVgsb<vci_param>::VciVgsb (	sc_module_name 		name,
                        	MappingTable 		&maptab,
                        	size_t 			nb_master,
                        	size_t 			nb_slave)
    : sc_core::sc_module(name),
      m_routing_table(maptab.getRoutingTable( IntTab() ) ),
      m_nb_initiator(nb_master),
      m_nb_target(nb_slave),
      p_clk("clk"),
      p_resetn("resetn"),
      p_to_initiator(soclib::common::alloc_elems<soclib::caba::VciTarget<vci_param> >("p_to_initiator", nb_master)),
      p_to_target(soclib::common::alloc_elems<soclib::caba::VciInitiator<vci_param> >("p_to_target", nb_slave)),
      r_fsm("r_fsm"),
      r_initiator_index("r_initiator_index"),
      r_target_index("r_target_index"),
      r_vci_counter(soclib::common::alloc_elems<sc_signal<uint32_t> >("r_vci_counter", nb_master, nb_slave))
{
	SC_METHOD(transition);
	dont_initialize();
	sensitive << p_clk.pos();

	SC_METHOD(genMealy_rspval);
	dont_initialize();
	sensitive << p_clk.neg();
	for ( size_t i=0 ; i<nb_slave  ; i++ ) sensitive << p_to_target[i];

	SC_METHOD(genMealy_rspack);
	dont_initialize();
	sensitive << p_clk.neg();
	for ( size_t i=0 ; i<nb_master ; i++ ) sensitive << p_to_initiator[i];

	SC_METHOD(genMealy_cmdval);
	dont_initialize();
	sensitive << p_clk.neg();
	for ( size_t i=0 ; i<nb_master ; i++ ) sensitive << p_to_initiator[i];

	SC_METHOD(genMealy_cmdack);
	dont_initialize();
	sensitive << p_clk.neg();
	for ( size_t i=0 ; i<nb_slave  ; i++ ) sensitive << p_to_target[i];

	if ( !m_routing_table.isAllBelow( nb_slave ) ) {
		std::cout << "error in vci_gsb component" << std::endl;
		std::cout << "one target index is larger than the number of targets" << std::endl;
		exit(0);
	}
} // end constructor
Exemplo n.º 11
0
void Alcatraz::truncate_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;
    /* first get the real path of the file */

    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, true);
    switch (maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT) ;
	break ;
    case PATH_DELETED:
	arch->abortCall(pid, -1, ENOENT) ;
	break ;
    case PATH_CREATED:
    case PATH_MODIFIED:{
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, buf, "MD", pid, ppid) ;
#endif
	arg0.set(buf) ;
	break ;
    }
    case PATH_NEW: {
	int retval = truncate_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	}
	else {
	    char tempfile[PATH_MAX] ;
	    mt.isolate(buf, tempfile, false) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", normpath, tempfile, "MD", pid, ppid) ;
#endif
	    arg0.set(tempfile) ;
	}
	break ;
    }
    }
}
Exemplo n.º 12
0
void Alcatraz::unlink_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    state = -1 ;

    char normpath[PATH_MAX], buf[PATH_MAX];

    if (strlen(arg0.get().c_str()) == 0)
	arch->abortCall(pid, 0, 0) ;

    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, false, tempname);
    switch (maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break;
    case PATH_DELETED:{
	arch->abortCall(pid, -1, ENOENT) ;
	break ;
    }		 
    case PATH_CREATED: {
	state = 0 ;
	arg0.set(buf) ;
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, "N/A", "DE", pid, ppid) ;
#endif
	break ;
    }
    case PATH_MODIFIED:{
	state = 1 ;
	arg0.set(buf) ;
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, "N/A", "DE", pid, ppid) ;
#endif
	break ;
    }
    case PATH_NEW:{
	int retval ;
	retval = unlink_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	} 
	else {
	    mt.newDelete(TYPE_FILE, buf) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", buf, "N/A", "DE", pid, ppid) ;
#endif
	}
	break ;
    }
    default:
	break; 
    }
}
Exemplo n.º 13
0
void Alcatraz::open_entry()
{
    CString arg0(getArgRep(0)) ;
    Integer arg1(getArgRep(1)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;
    int maptype ;

    if (strncmp("/.a_to_GUI", arg0.get().c_str(), 10) == 0) {
	mt.mapping.sendtoGUI(false) ;
	arch->abortCall(pid, -1, EPERM) ;
	return ;
    }

    if (strncmp("/.alcatraz", arg0.get().c_str(), 10) == 0) {
	arg0.set(arg0.get().c_str()+10) ;
	arg1.set(0) ;
	return ;
    }

    // check open modes
    int flag = arg1.get() ;
    bool readonly = true ;
    if (flag&O_WRONLY || flag&O_RDWR || flag&O_CREAT)
	readonly = false ;
    bool trunc = false ;
    if (!readonly && flag&O_TRUNC)
	trunc = true ;

    normalizePath(arg0.get().c_str(), normpath) ;
    maptype = translatePath(normpath, buf, true, tempname);
    // Remember the association between file descriptors and path names
    // It remembers the canonized name
    char *tmp ;
    if (PATH_NEW == maptype)
	tmp = buf ;
    else tmp = normpath ;
    size_t strsize = strlen(tmp) + 1 ;
    char *duppath = new char[strsize] ;
    if (0 != duppath) {
	memcpy(duppath, tmp, strsize) ;
    }
    ProcData *pData = processData.lookUp(pid) ;
    if (0 == pData) {
	pData = new ProcData() ;
	processData.insert(pid, pData) ;
    }
    pData->storeOpenName(duppath) ;

    switch(maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break; 
    case PATH_CREATED:
    case PATH_MODIFIED:
#ifdef INSTALL_SHIELD
	if (!readonly) {
	    pid_t ppid = mp->ppid() ;
	    mt.mapping.appendTime(normpath, pid, ppid) ;
	    if (access(buf, F_OK) == 0)
		mod_log("F", normpath, buf, "MD", pid, ppid) ;
	    else 
		mod_log("F", normpath, buf, "CR", pid, ppid) ;
	}
#endif
	arg0.set(buf) ;
	break ;
    case PATH_DELETED: {
	if (readonly)
	    arch->abortCall(pid, -1, ENOENT) ;
	else {
	    /* create a new file, delete previous entry and
	       generate a new temp file */
	    char tempfile[PATH_MAX] ;
	    mt.delMapping(tempname) ;
	    mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ;
	    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
	}
	break ;
    }
    case PATH_NEW: {
	if (!readonly){
	    if (access(buf, F_OK)==0) { /* File exists */
		struct stat statbuf ;
		if (stat(buf, &statbuf) == 0){/*success*/
		    if (!S_ISREG(statbuf.st_mode)) break ;
		}

		if (access(buf, W_OK) == 0) {
		    /* can write, isolate file */
		    char tempfile[PATH_MAX] ;
		    mt.isolate(buf, tempfile, trunc) ;
		    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	            pid_t ppid = mp->ppid() ;
		    mod_log("F", normpath, tempfile, "MD", pid, ppid) ;
#endif

		}
	    }
	    else { /* File Not Exists */
		if (parent_writable(buf)) {
		    char tempfile[PATH_MAX] ;
		    mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ;
		    //		    mt.getStatus(normpath, buf) ;
		    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	            pid_t ppid = mp->ppid() ;
		    mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
		}
	    }
	}
	else {
	    arg0.set(buf) ;
	}
	break ;
    }
    default:
	break ;
    }
    
}
Exemplo n.º 14
0
Arquivo: main.cpp Projeto: CCJY/coliru
int main()
{
    MappingTable runmap;
    MappingTable::iterator last = runmap.empty() ? runmap.end() : (runmap.end() - 1);
}