Esempio n. 1
0
/* May need to disable updating of memory & condition codes */
static void update_state(bool_t update_mem, bool_t update_cc)
{
    /* Writeback(s):
       If either register is REG_NONE, write will have no effect .
       Order of two writes determines semantics of
       popl %esp.  According to ISA, %esp will get popped value
    */

    if (wb_destE != REG_NONE) {
	sim_log("Writeback: Wrote 0x%x to register %s\n",
		wb_valE, reg_name(wb_destE));
	set_reg_val(reg, wb_destE, wb_valE);
    }
    if (wb_destM != REG_NONE) {
	sim_log("Writeback: Wrote 0x%x to register %s\n",
		wb_valM, reg_name(wb_destM));
	set_reg_val(reg, wb_destM, wb_valM);
    }

    /* Memory write */
    if (mem_write && !update_mem) {
	sim_log("Disabled write of 0x%x to address 0x%x\n", mem_data, mem_addr);
    }
    if (update_mem && mem_write) {
	if (!set_word_val(mem, mem_addr, mem_data)) {
	    sim_log("Couldn't write to address 0x%x\n", mem_addr);
	} else {
	    sim_log("Wrote 0x%x to address 0x%x\n", mem_data, mem_addr);

#ifdef HAS_GUI
	    if (gui_mode) {
		if (mem_addr % 4 != 0) {
		    /* Just did a misaligned write.
		       Need to display both words */
		    word_t align_addr = mem_addr & ~0x3;
		    word_t val;
		    get_word_val(mem, align_addr, &val);
		    set_memory(align_addr, val);
		    align_addr+=4;
		    get_word_val(mem, align_addr, &val);
		    set_memory(align_addr, val);
		} else {
		    set_memory(mem_addr, mem_data);
		}
	    }
#endif

	}
    }
    if (update_cc)
	cc = cc_in;
}
Esempio n. 2
0
/* Update the processor state */
static exc_t update_state()
{
    exc_t status = EXC_NONE;
    if (plusmode) {
	prev_icode = prev_icode_in;
	prev_ifun  = prev_ifun_in;
	prev_valc  = prev_valc_in;
	prev_valm  = prev_valm_in;
	prev_valp  = prev_valp_in;
	prev_bcond = prev_bcond_in;
    } else {
	pc = pc_in;
    }
    cc = cc_in;
    /* Writeback */
    if (destE != REG_NONE)
	set_reg_val(reg, destE, vale);
    if (destM != REG_NONE)
	set_reg_val(reg, destM, valm);

    if (mem_write) {
	if (!set_word_val(mem, mem_addr, mem_data)) {
	    sim_log("Couldn't write to address 0x%x\n", mem_addr);
	    status = EXC_ADDR;
	} else {
	    sim_log("Wrote 0x%x to address 0x%x\n", mem_data, mem_addr);

#ifdef HAS_GUI
	    if (gui_mode) {
		if (mem_addr % 4 != 0) {
		    /* Just did a misaligned write.
		       Need to display both words */
		    word_t align_addr = mem_addr & ~0x3;
		    word_t val;
		    get_word_val(mem, align_addr, &val);
		    set_memory(align_addr, val);
		    align_addr+=4;
		    get_word_val(mem, align_addr, &val);
		    set_memory(align_addr, val);
		} else {
		    set_memory(mem_addr, mem_data);
		}
	    }
#endif// HAS_GUI

	}
    }
    return status;
}
Esempio n. 3
0
/* Please see header for specification */
Anvil::Buffer::Buffer(Anvil::Device*         device_ptr,
                      VkDeviceSize           size,
                      Anvil::QueueFamilyBits queue_families,
                      VkSharingMode          queue_sharing_mode,
                      VkBufferUsageFlags     usage_flags,
                      bool                   should_be_mappable,
                      bool                   should_be_coherent,
                      const void*            opt_client_data)
    :m_buffer           (VK_NULL_HANDLE),
     m_buffer_size      (size),
     m_device_ptr       (device_ptr),
     m_memory_block_ptr (nullptr),
     m_parent_buffer_ptr(0),
     m_start_offset     (0),
     m_usage_flags      (static_cast<VkBufferUsageFlagBits>(usage_flags) )
{
    /* Sanity checks */
    if (!should_be_mappable)
    {
        anvil_assert(!should_be_coherent);

        /* For host->gpu writes to work in this case, we will need the buffer to work as a target
         * for buffer->buffer copy operations.
         */
        m_usage_flags = static_cast<VkBufferUsageFlagBits>(m_usage_flags | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
    }

    /* Create the buffer object */
    create_buffer(queue_families,
                  queue_sharing_mode,
                  size);

    /* Create a memory object and preallocate as much space as we need */
    {
        Anvil::MemoryBlock* memory_block_ptr = nullptr;

        memory_block_ptr = new Anvil::MemoryBlock(m_device_ptr,
                                                  m_buffer_memory_reqs.memoryTypeBits,
                                                  m_buffer_memory_reqs.size,
                                                  should_be_mappable,
                                                  should_be_coherent);

        anvil_assert(memory_block_ptr != nullptr);

        set_memory(memory_block_ptr);

        if (opt_client_data != nullptr)
        {
            write(0,
                  size,
                  opt_client_data);
        }

        memory_block_ptr->release();
    }

    /* Register the object */
    Anvil::ObjectTracker::get()->register_object(Anvil::ObjectTracker::OBJECT_TYPE_BUFFER,
                                                  this);
}
	MultilinConfiguration(SolverConfiguration & solve_options,
					std::shared_ptr<SystemRandomizer> _random)
	{
		init();
		
		set_memory(solve_options);
		
		set_randomizer(_random);
	}
	MultilinConfiguration(SolverConfiguration & solve_options,
					const WitnessSet & W)
	{
		init();
		
		set_memory(solve_options);
		
		make_randomizer(solve_options, W);
	}
Esempio n. 6
0
File: ssim.c Progetto: Azard/icslabs
/* Update the processor state */
static void update_state()
{
    if (plusmode) {
	prev_icode = prev_icode_in;
	prev_ifun  = prev_ifun_in;
	prev_valc  = prev_valc_in;
	prev_valm  = prev_valm_in;
	prev_valp  = prev_valp_in;
	prev_bcond = prev_bcond_in;
    } else {
	pc = pc_in;
    }
    cc = cc_in;
    /* Writeback */
    if (destE != REG_NONE)
	set_reg_val(reg, destE, vale);
    if (destM != REG_NONE)
	set_reg_val(reg, destM, valm);

    if (mem_write) {
      /* Should have already tested this address */
      set_word_val(mem, mem_addr, mem_data);
	sim_log("Wrote 0x%x to address 0x%x\n", mem_data, mem_addr);
#ifdef HAS_GUI
	    if (gui_mode) {
		if (mem_addr % 4 != 0) {
		    /* Just did a misaligned write.
		       Need to display both words */
		    word_t align_addr = mem_addr & ~0x3;
		    word_t val;
		    get_word_val(mem, align_addr, &val);
		    set_memory(align_addr, val);
		    align_addr+=4;
		    get_word_val(mem, align_addr, &val);
		    set_memory(align_addr, val);
		} else {
		    set_memory(mem_addr, mem_data);
		}
	    }
#endif /* HAS_GUI */
    }
}
Esempio n. 7
0
/* Reduces the cycles_away of all changes by one and executes any changes
   that have a cycles_away of 0 */
Change* execute_changes(Change* changes, Change** last_change_ptr, Instruction** code_ptr)
{
    Change* first_change = changes;
    Change* prev_change = NULL;

    /* Iterate through all changes */
    while(changes)
    {
	changes->cycles_away -= 1;
	
	if (changes->cycles_away == 0)
	{
	    /* Perform effect */
	    switch(changes->type)
	    {
		case REGISTER:
		  set_register(changes->location,changes->value);
		  break;
		case MEMORY:
		  set_memory(changes->location,changes->value);
		  break;
		case BRANCH:
		  *code_ptr = changes->target;
		  break;
		case DISPLAY:
		  fprintf(stdout,"%d\n",changes->value);
		  break;
	      }

	    /* Delete change record */
	    if (prev_change)
	    {
		prev_change->next = changes->next;
		free(changes);
		changes = prev_change->next;
	    }
	    else
	    {
		first_change = changes->next;
		free(changes);
		changes = first_change;
	    }
	}
	else
	{
	    prev_change = changes;
	    changes = changes->next;
	}

    }

    *last_change_ptr = prev_change;
    return (first_change);
}
Esempio n. 8
0
void VFrame::set_memory(BC_Bitmap *bitmap)
{
	int shmid = 0;
	unsigned char *data = 0;
	if( bitmap->is_shared() )
		shmid = bitmap->get_shmid();
	else
		data = bitmap->get_data();
	set_memory(data, shmid,
		bitmap->get_y_offset(),
		bitmap->get_u_offset(),
		bitmap->get_v_offset());
}
int main(int argc, char *argv[])
{
  int i;

  if(argc==1)
    {
    printf("Argument required.  To use default memory, enter '0', to set\n your own memory, enter any other argument\n");
    return 0;
    }
  //if no argument is given in the command line, program prints error 
  //message and terminates

      if(strcmp(argv[1],"0") == 0)
    set_memory();
      //if argument given is 0, program calls set_memory() to run using
      //default memory settings

      else if(strcmp(argv[1],"0") != 0)
    read_memory();
      //if some nonzero argument is entered, program calls read_memory,
      //prompting the user to enter starting memory values
      //byte-by-byte

  while(pc<MEM_SIZE)
    {
  strcpy(ir, memory[pc]);
  pc++;
  execute();
  //loads memory next piece of memory into the IR, increments the PC, and 
  //executes the command found in the designated memory space.
  if(halt)
    break;
  //if the command executed in memory is the "halt" command, program stops
  //going through memory. 
    }

  printf("Memory:\n");
  print_memory();
  printf("Accumulator:\n");
  printf("%s\n",ac);
  //prints values in accumulator and memory
  return 0;
}
Esempio n. 10
0
void* get_memptr(const char* filename, size_t size, int* id_to_save)
{
	CHECK(filename,  "Argumented filename pointer is NULL");
	CHECK(id_to_save,"Argumented pointer is NULL" );
	WARN(size >= PAGESIZE, "Requested size of shared memory will be rounded up to PAGESIZE");

	int cond = creat(filename, 0660);
	if (cond == -1)
		printf("Failed to create file [%s]\n", filename);
	CHECK(cond != -1 || (cond == -1 && errno == EEXIST), "Unexpected error during sharing memory file creation");

	int shared_id = set_memory(filename, 
		    		   size);
	CHECK(shared_id != -1, "Failed to get shared memory");
	void* shm_ptr = shmat(shared_id, NULL, 0);
	CHECK(shm_ptr != (void*) -1, "Failed to get pointer from share memory id");
	memset(shm_ptr, size, 0);

	*id_to_save = shared_id;
	return shm_ptr;
}
Esempio n. 11
0
File: emu.c Progetto: aunali1/exopc
int emu_pushf(unsigned char *lina)
{
    Bit32u val;
    
    trace("pushf\n");
    ASSERT(!opa.pe);
    
    if (opa.opb==4) {
	val = REG(eflags);
    } else {
	val = LWORD(eflags);
    }

    LWORD(esp) -= opa.opb;
    val &= ~(VM_MASK | RF_MASK);
    if (set_memory(LWORD(ss), LWORD(esp), val, opa.opb))
	return -1;

    REG(eip) ++;
    return 0;
}
Esempio n. 12
0
int main(int argc, char* argv[])
{
    int mem_size = 0;
    int reg_size = 0;
    int current_argument = 1;
    int machine_initialized = 0;
    Instruction* code;

    /* Set default stall mode - branches, registers, and memory */
    set_stall_mode(3 /*2*/);

    while(current_argument < argc) 
    {
	if (strcmp(argv[current_argument],"-h") == 0)
	{
	    print_help();
	    return 0;
	}
	
	/* All of the following flags require at least one additional parameter,
	   so perform check here. */
	if (current_argument == argc - 1)
	{
	    fprintf(stderr,"Invalid flag sequence: make sure any required numbers are included.\n");
	    return(1);
	}


	if (strcmp(argv[current_argument],"-r") == 0)
	{
	    reg_size = (int) strtol(argv[current_argument+1],(char**)NULL,10);
	    current_argument += 2;
	}
	else
	{
	    if (strcmp(argv[current_argument],"-m") == 0)
	    {
		mem_size = (int) strtol(argv[current_argument+1],(char**)NULL,10);
		current_argument += 2;
	    }
	    else
	    {
		if (strcmp(argv[current_argument],"-s") == 0)
		{
		    set_stall_mode((int)strtol(argv[current_argument+1],(char**)NULL,10));
		    current_argument += 2;
		}
		else
		{
		    if (strcmp(argv[current_argument],"-i") == 0)
		    {
			int i;
			int start_location = (int)strtol(argv[current_argument+1],(char**)NULL,10);
			initialize_machine(reg_size,mem_size);
			machine_initialized = 1;
			for(i = 0; i < (argc - current_argument - 2); i++)
			    set_word(start_location + 4*i, (int)strtol(argv[current_argument+2+i],
								       (char**)NULL,10));
			current_argument = argc;
		    }
		    else
		    {
			if (strcmp(argv[current_argument],"-c") == 0)
			{
			    int i;
			    int start_location = (int)strtol(argv[current_argument+1],
							     (char**)NULL,10);
			    initialize_machine(reg_size,mem_size);
			    machine_initialized = 1;
			    for(i = 0; i < (argc - current_argument - 2); i++)
				set_memory(start_location + i, 
					 (char)strtol(argv[current_argument+2+i],
						     (char**)NULL,10));
			    current_argument = argc;
			}
			else
			{
			    fprintf(stderr,"Invalid flag specified\n");
			    return 0;
			}
		    }
		}
	    }
	}
	
    }
    
    if (!machine_initialized)
	initialize_machine(reg_size,mem_size);

    code = parse();

    if (!code)
    {
	fprintf(stderr,"Error reading input file, simulator not run.\n");
	return 1;
    }

    simulate(code);

    return 0;
};
Esempio n. 13
0
 void set_memory(Node* c, Node* adr) { set_memory(c,_gvn.type(adr)->is_ptr()); }
Esempio n. 14
0
 void set_memory(Node* c, const TypePtr *tp) { set_memory(c,C->get_alias_index(tp)); }
	MultilinConfiguration(SolverConfiguration & solve_options)
	{
		init();
		set_memory(solve_options);
	}