Ejemplo n.º 1
0
static int
read_default_file (char* buffer, size_t buffer_size)
{
  int fid;

  buffer = expand_file_name (buffer, buffer_size);
  if (!buffer)
    {
      log_err ("read_default_file: filename too long. %s", buffer);
      return (-1);
    }

  fid = file_loaded (buffer);
  if (fid == -1)
    {                           /* Not correct file */
      printf ("Error reading %s\n", buffer);
      return (-1);
    }
  if (FILE_NOT_READ != fid)
    {                           /* already read */
      return (-1);
    }
  if ((fid = get_new_fid ()) == -1)
    {                           /* no more file */
      printf ("Error reading %s\n", buffer);
      return (-1);
    }

  files[fid].localf = LOCAL;
  strcpy (files[fid].name, buffer);
  printf ("Reading %s\t Fid = %d\n", buffer, fid);
  if (read_file (&files[fid]) == -1)
    {
      printf ("Error reading %s\n", buffer);
      files[fid].ref_count = -1;        /* fail */
      return (-1);
    }
  files[fid].ref_count = 1;
  return (fid);
}
Ejemplo n.º 2
0
/** DoLoadFile
  *
  * Handles loading an assembly file into the simulator
  */
void ComplxFrame::DoLoadFile(const LoadingOptions& opts)
{
    auto* config = wxConfigBase::Get();

    wxFileName filename(opts.file);
    bool randomize_registers = opts.registers == RANDOMIZE;
    bool randomize_memory = opts.memory == RANDOMIZE;
    short fill_registers = opts.registers;
    short fill_memory = opts.memory;

    lc3_init(state, randomize_registers, randomize_memory, fill_registers, fill_memory);
    state.pc = opts.pc;

    PostInit();

    // Now the actual loading
    if (opts.file.empty())
        return;

    lc3_state dummy_state;
    lc3_init(dummy_state);

    // Save the symbols
    std::map<std::string, unsigned short> symbol_table = state.symbols;
    std::map<unsigned short, std::string> rev_symbol_table = state.rev_symbols;

    state.symbols.clear();
    state.rev_symbols.clear();
    lc3_remove_plugins(state);

    bool tvt_modification = false;
    bool ivt_modification = false;
    bool subroutine_found = false;

    try
    {
        ///TODO should only make one call to lc3_assemble.
        std::vector<code_range> ranges;
        LC3AssembleOptions options;
        options.multiple_errors = false;
        lc3_assemble(dummy_state, filename.GetFullPath().ToStdString(), options);
        options.multiple_errors = true;
        options.warnings_as_errors = false;
        options.process_debug_comments = true;
        options.enable_warnings = false;
        options.disable_plugins = false;
        lc3_assemble(state, filename.GetFullPath().ToStdString(), ranges, options);

        // Update list of addresses modified for Show only Code/Data option.
        modified_addresses.clear();
        for (const auto& code_range : ranges)
            modified_addresses.push_back(ViewRange(code_range.location, code_range.location + code_range.size));
        /// TODO Automatically determine state of true traps and interrupts via the code ranges.
        // Dummy call to update hidden addresses.
        wxCommandEvent event;
        OnUpdateHideAddresses(event);
        // Check for TVT and IVT modification
        for (const auto& code_range : ranges)
        {
            if ((code_range.location >= 0 && code_range.location <= 0xFF) || (code_range.location + code_range.size >= 0 && code_range.location + code_range.size <= 0xFF))
                tvt_modification = true;
            if ((code_range.location >= 0x100 && code_range.location <= 0x1FF) || (code_range.location + code_range.size >= 0x100 && code_range.location + code_range.size <= 0x1FF))
                ivt_modification = true;
        }
        subroutine_found = DetectSubroutine(ranges);
    }
    catch (LC3AssembleException e)
    {
        wxMessageBox(wxString::Format("ERROR! %s", e.what()), wxString::Format("Loading %s failed", filename.GetFullName()));
        goto merge;
    }
    catch (std::vector<LC3AssembleException> e)
    {
        std::stringstream oss;
        for (unsigned int i = 0; i < e.size(); i++)
            oss << e[i].what() << std::endl;
        wxMessageBox(wxString::Format("ERROR! %s", oss.str()), wxString::Format("Loading %s failed", filename.GetFullName()));
        goto merge;
    }

    lc3_set_true_traps(state, opts.true_traps || tvt_modification);
    state.interrupt_enabled = opts.interrupts || ivt_modification;
    console->SetInput(opts.console_input);
    state.strict_execution = opts.strict_execution;
    // Update menus
    menuStateTrueTraps->Check(opts.true_traps || tvt_modification);
    menuStateInterrupts->Check(opts.interrupts || ivt_modification);
    menuStateStrictExecution->Check(opts.strict_execution);

    if (tvt_modification)
    {
        bool tvt_popup = config->Read("/firsttimetrap", "").IsEmpty();
        if (tvt_popup)
        {
            wxMessageBox("Pardon the interruption!\n"
                         "It appears you have loaded a file with a custom trap.\n"
                         "This will automatically enable true traps mode.\n"
                         "This will allow you to step into the code for the standard traps (IN,OUT,GETC,PUTS,HALT) and your own custom trap.\n"
                         "This notice to to remind you of the above, executing HALT will jump to some random code, but I assure you this random code is the code to HALT the LC-3.\n"
                         "If you'd rather stop the execution right at the HALT statement then put a breakpoint on your HALT statement.\n",
                         "Notice");
            config->Write("/firsttimetrap", "1");
        }
    }

    if (subroutine_found)
    {
        wxCommandEvent event;
        OnControlModeAdvanced(event);
        bool subroutine_popup = config->Read("/firsttimesubroutine", "").IsEmpty();
        if (subroutine_popup)
        {
            wxMessageBox("Pardon the interruption!\n"
                         "It appears you have loaded a file with a custom trap or subroutine.\n"
                         "You may notice 3 new buttons in the control area.\n"
                         "Next Line\n    Allows you to STEP OVER a subroutine or trap, meaning it will skip over it (but still execute it).\n"
                         "Prev Line\n    Allows you to BACK STEP OVER a subroutine or trap.\n"
                         "Finish\n    Allows you to STEP OUT of a subroutine, it finishes execution of it.\n\n"
                         "Another thing to note if you want to always step over/out a subroutine to select the subroutine label and select mark as blackbox.\n"
                         "If you use step on a JSR/JSRR/TRAP instruction that is blackboxed it will never step into it.\n"
                         "For more information Read The Manual :)\n"
                         , "Notice");
            config->Write("/firsttimesubroutine", "1");
        }
    }

    SetTitle(wxString::Format("%s - %s", base_title, filename.GetFullPath()));

merge:
    std::map<std::string, unsigned short>::const_iterator i;
    std::map<unsigned short, std::string>::const_iterator j;
    for (i = symbol_table.begin(); i != symbol_table.end(); ++i)
    {
        state.symbols[i->first] = i->second;
    }
    for (j = rev_symbol_table.begin(); j != rev_symbol_table.end(); ++j)
    {
        state.rev_symbols[j->first] = j->second;
    }

    UpdateStatus();
    UpdateRegisters();
    UpdateMemory();

    // Save in reload options
    reload_options = opts;

    // Update timestamps
    wxFileName file_loaded(reload_options.file);
    reload_options.file_modification_time = file_loaded.GetModificationTime();
}