Search in sources :

Example 1 with CPU

use of brunonova.drmips.simulator.CPU in project drmips by brunonova.

the class DrMIPSActivity method loadCPU.

/**
	 * Loads the CPU from the specified file.
	 * @param file File to load the CPU from.
	 */
public void loadCPU(File file) throws ArrayIndexOutOfBoundsException, NumberFormatException, IOException, JSONException, InvalidCPUException, InvalidInstructionSetException {
    setSimulationControlsEnabled(false);
    // load CPU from file
    CPU cpu = CPU.createFromJSONFile(file.getAbsolutePath());
    cpu.setPerformanceInstructionDependent(cmbDatapathPerformance.getSelectedItemPosition() == Util.INSTRUCTION_PERFORMANCE_TYPE_INDEX);
    DrMIPS.getApplication().setCPU(cpu);
    // display the CPU's register table
    refreshRegistersTable();
    // display datapath in the respective tab
    refreshDatapath();
    // display assembled code in the respective tab
    refreshAssembledCodeTable();
    // display data memory in the respective tab
    refreshDataMemoryTable();
    refreshExecTable();
    datapath.setControlPathVisible(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.SHOW_CONTROL_PATH_PREF, DrMIPS.DEFAULT_SHOW_CONTROL_PATH));
    datapath.setShowArrows(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.SHOW_ARROWS_PREF, DrMIPS.DEFAULT_SHOW_ARROWS));
    datapath.setPerformanceMode(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.PERFORMANCE_MODE_PREF, DrMIPS.DEFAULT_PERFORMANCE_MODE));
    datapath.setShowTips(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.OVERLAYED_DATA_PREF, DrMIPS.DEFAULT_OVERLAYED_DATA));
    datapath.setShowTipsNames(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.OVERLAYED_SHOW_NAMES_PREF, DrMIPS.DEFAULT_OVERLAYED_SHOW_NAMES));
    datapath.setShowTipsForAllComps(DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.OVERLAYED_SHOW_FOR_ALL_PREF, DrMIPS.DEFAULT_OVERLAYED_SHOW_FOR_ALL));
    lblCPUFilename.setText(cpu.getFile().getName());
    SharedPreferences.Editor editor = DrMIPS.getApplication().getPreferences().edit();
    editor.putString(DrMIPS.LAST_CPU_PREF, file.getName());
    editor.apply();
}
Also used : SharedPreferences(android.content.SharedPreferences) CPU(brunonova.drmips.simulator.CPU)

Example 2 with CPU

use of brunonova.drmips.simulator.CPU in project drmips by brunonova.

the class DlgStatistics method onCreateDialog.

@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    CPU cpu = ((DrMIPSActivity) getActivity()).getCPU();
    View layout = getActivity().getLayoutInflater().inflate(R.layout.statistics_dialog, null);
    ((TextView) layout.findViewById(R.id.lblClockPeriodVal)).setText(cpu.getClockPeriod() + " " + CPU.LATENCY_UNIT);
    ((TextView) layout.findViewById(R.id.lblClockFrequencyVal)).setText(cpu.getClockFrequencyInAdequateUnit());
    ((TextView) layout.findViewById(R.id.lblExecutedCyclesVal)).setText(cpu.getNumberOfExecutedCycles() + "");
    ((TextView) layout.findViewById(R.id.lblExecutionTimeVal)).setText(cpu.getExecutionTime() + " " + CPU.LATENCY_UNIT);
    ((TextView) layout.findViewById(R.id.lblExecutedInstructionsVal)).setText(cpu.getNumberOfExecutedInstructions() + "");
    ((TextView) layout.findViewById(R.id.lblCPIVal)).setText(cpu.getCPIAsString());
    ((TextView) layout.findViewById(R.id.lblForwardsVal)).setText(cpu.getNumberOfForwards() + "");
    ((TextView) layout.findViewById(R.id.lblStallsVal)).setText(cpu.getNumberOfStalls() + "");
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.statistics).setView(layout).setPositiveButton(android.R.string.ok, this).create();
}
Also used : CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 3 with CPU

use of brunonova.drmips.simulator.CPU in project drmips by brunonova.

the class DrMIPSActivity method refreshRegistersTable.

/**
	 * Refreshes both the rows and values of the registers table.
	 */
private void refreshRegistersTable() {
    while (// remove all rows except header
    tblRegisters.getChildCount() > 1) tblRegisters.removeViewAt(1);
    // Add registers
    CPU cpu = getCPU();
    int numRegs = cpu.getRegBank().getNumberOfRegisters();
    TableRow row;
    TextView register, value;
    String reg;
    for (int i = 0; i < numRegs; i++) {
        row = new TableRow(this);
        row.setOnLongClickListener(registersRowOnLongClickListener);
        register = new TextView(this);
        reg = i + ": " + cpu.getRegisterName(i);
        if (i < 10)
            reg = " " + reg;
        register.setText(reg);
        register.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        register.setTypeface(Typeface.MONOSPACE);
        value = new TextView(this);
        value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        value.setTypeface(Typeface.MONOSPACE);
        value.setGravity(Gravity.RIGHT);
        row.addView(register);
        row.addView(value);
        tblRegisters.addView(row);
    }
    // Add special "registers" (PC,...)
    row = new TableRow(this);
    row.setOnLongClickListener(registersRowOnLongClickListener);
    register = new TextView(this);
    register.setText("PC");
    register.setTextAppearance(this, android.R.style.TextAppearance_Medium);
    register.setTypeface(Typeface.MONOSPACE);
    value = new TextView(this);
    value.setTextAppearance(this, android.R.style.TextAppearance_Medium);
    value.setTypeface(Typeface.MONOSPACE);
    value.setGravity(Gravity.RIGHT);
    row.addView(register);
    row.addView(value);
    tblRegisters.addView(row);
    // refresh values
    refreshRegistersTableValues();
}
Also used : TableRow(android.widget.TableRow) CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView)

Example 4 with CPU

use of brunonova.drmips.simulator.CPU in project drmips by brunonova.

the class DrMIPSActivity method refreshRegistersTableValues.

/**
	 * Refreshes the values of the registers table.
	 */
public void refreshRegistersTableValues() {
    CPU cpu = getCPU();
    int numRegs = cpu.getRegBank().getNumberOfRegisters();
    TextView value;
    TableRow row;
    int reg1 = cpu.getRegBank().getReadReg1().getValue();
    int reg2 = cpu.getRegBank().getReadReg2().getValue();
    int regW = cpu.getRegBank().getWriteReg().getValue();
    boolean write = cpu.getRegBank().getRegWrite().getValue() == 1;
    for (int i = 0; i < numRegs; i++) {
        // registers
        row = (TableRow) tblRegisters.getChildAt(i + 1);
        value = (TextView) row.getChildAt(1);
        value.setText(Util.formatDataAccordingToFormat(cpu.getRegBank().getRegister(i), cmbRegistersFormat.getSelectedItemPosition()));
        // Highlight registers being accessed
        if (write && i == regW && !cpu.getRegBank().isRegisterConstant(regW)) {
            if (i == reg1 || i == reg2)
                row.setBackgroundColor(Util.getThemeColor(this, R.attr.rwColor));
            else
                row.setBackgroundColor(Util.getThemeColor(this, R.attr.writeColor));
        } else if (i == reg1 || i == reg2)
            row.setBackgroundColor(Util.getThemeColor(this, R.attr.readColor));
        else
            // remove background color
            row.setBackgroundResource(0);
    }
    // Special "registers"
    value = (TextView) ((TableRow) tblRegisters.getChildAt(numRegs + 1)).getChildAt(1);
    value.setText(Util.formatDataAccordingToFormat(cpu.getPC().getAddress(), cmbRegistersFormat.getSelectedItemPosition()));
    tblRegisters.requestLayout();
}
Also used : TableRow(android.widget.TableRow) CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView)

Example 5 with CPU

use of brunonova.drmips.simulator.CPU in project drmips by brunonova.

the class DlgCodeHelp method setContents.

private void setContents(View rootView) {
    DrMIPSActivity activity = (DrMIPSActivity) getActivity();
    TableLayout tblInstructions = (TableLayout) rootView.findViewById(R.id.tblInstructions);
    TableLayout tblPseudos = (TableLayout) rootView.findViewById(R.id.tblPseudos);
    TableRow row;
    TextView inst, desc;
    tblInstructions.removeAllViews();
    tblPseudos.removeAllViews();
    CPU cpu = activity.getCPU();
    for (Instruction i : cpu.getInstructionSet().getInstructions()) {
        row = new TableRow(activity);
        inst = new TextView(activity);
        inst.setText(i.getUsage() + " ");
        row.addView(inst);
        desc = new TextView(activity);
        desc.setText("# " + (i.hasDescription() ? i.getDescription() : "-"));
        row.addView(desc);
        tblInstructions.addView(row);
    }
    for (PseudoInstruction i : cpu.getInstructionSet().getPseudoInstructions()) {
        row = new TableRow(activity);
        inst = new TextView(activity);
        inst.setText(i.getUsage() + " ");
        row.addView(inst);
        desc = new TextView(activity);
        desc.setText("# " + (i.hasDescription() ? i.getDescription() : "-"));
        row.addView(desc);
        tblPseudos.addView(row);
    }
}
Also used : PseudoInstruction(brunonova.drmips.simulator.PseudoInstruction) TableRow(android.widget.TableRow) CPU(brunonova.drmips.simulator.CPU) TextView(android.widget.TextView) PseudoInstruction(brunonova.drmips.simulator.PseudoInstruction) Instruction(brunonova.drmips.simulator.Instruction) DrMIPSActivity(brunonova.drmips.android.DrMIPSActivity) TableLayout(android.widget.TableLayout)

Aggregations

CPU (brunonova.drmips.simulator.CPU)11 TextView (android.widget.TextView)8 TableRow (android.widget.TableRow)7 DrMIPSActivity (brunonova.drmips.android.DrMIPSActivity)2 Data (brunonova.drmips.simulator.Data)2 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 TableLayout (android.widget.TableLayout)1 AssembledInstruction (brunonova.drmips.simulator.AssembledInstruction)1 Instruction (brunonova.drmips.simulator.Instruction)1 PseudoInstruction (brunonova.drmips.simulator.PseudoInstruction)1