Commit 636b9f41 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

2004-04-20 Jérémy Demeule <demeul_j@epita.fr>

        Add an interactive shell.

        * src/vm/cpu.hh, src/vm/cpu.cc:
        Add a print operator.
        * src/vm/virtual_machine.hh:
        Add breakpoint suport and some shell entry points for step by step
        execution.

        * src/shell/cmd.hh,
        * src/shell/shell.cc, src/shell/shell.hh:
        Implement interactive shell, using readline.
        * src/shell/shell-tasks.cc, src/shell/shell-tasks.hh:
        Add shell's tasks.
        * src/shell/Makefile.am:
        Distribute shell.
        * src/modules.hh:
        Declare shell.

        * configure.ac:
        Check for readline library. Add shell directory.
        * src/Makefile.am:
        Add shell directory and link with readline.
parent 3b12f953
2004-04-20 Jrmy Demeule <demeul_j@epita.fr>
Add an interactive shell.
* src/vm/cpu.hh, src/vm/cpu.cc:
Add a print operator.
* src/vm/virtual_machine.hh:
Add breakpoint suport and some shell entry points for step by step
execution.
* src/shell/cmd.hh,
* src/shell/shell.cc, src/shell/shell.hh:
Implement interactive shell, using readline.
* src/shell/shell-tasks.cc, src/shell/shell-tasks.hh:
Add shell's tasks.
* src/shell/Makefile.am:
Distribute shell.
* src/modules.hh:
Declare shell.
* configure.ac:
Check for readline library. Add shell directory.
* src/Makefile.am:
Add shell directory and link with readline.
2004-04-05 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/cp0.hh:
......
......@@ -30,12 +30,21 @@ AC_PROG_YACC
# Look for a C++ compiler.
AC_PROG_CXX
# Look dor ran lib
# Look for ran lib
AC_PROG_RANLIB
# Look for readline header and lib
AC_CHECK_HEADER(readline/readline.h)
AC_CHECK_LIB(readline, readline)
AC_CHECK_LIB(curses, tputs)
## Development environment -------------
CXXFLAGS="${CXXFLAGS} -ansi -Wall -W"
READLINE_LIBS="-lreadline"
AC_SUBST(READLINE_LIBS)
## Epilogue ----------------------------
# Ask for the Makefile creations.
......@@ -46,6 +55,7 @@ AC_CONFIG_FILES([
src/inst/Makefile
src/parse/Makefile
src/vm/Makefile
src/shell/Makefile
src/task/Makefile
doc/Makefile
tests/Makefile
......
......@@ -2,30 +2,40 @@
(Created-By-Prcs-Version 1 3 2)
(Project-Description "")
(Project-Version mipsy 0 83)
(Parent-Version mipsy 0 82)
(Project-Version mipsy 0 84)
(Parent-Version mipsy 0 83)
(Version-Log
"Index: ChangeLog
from Benot Perrot <benoit@lrde.epita.fr>
* src/vm/cp0.hh:
Add control coprocessor.
* src/vm/Makefile.am:
Distribute it.
* src/vm/cpu.hh, src/vm/cpu.cc,
"2004-04-20 Jrmy Demeule <demeul_j@epita.fr>
Add an interactive shell.
* src/vm/cpu.hh, src/vm/cpu.cc:
Add a print operator.
* src/vm/virtual_machine.hh:
Use control coprocessor.
* dev/mipsy.py,
* dev/mipsy.xml:
Add instructions to move registers to/from control coprocessor.
* dev/inst-solver-gen.py,
Check register identifiers for control coprocessor instructions.
Add breakpoint suport and some shell entry points for step by step
execution.
* src/shell/cmd.hh,
* src/shell/shell.cc, src/shell/shell.hh:
Implement interactive shell, using readline.
* src/shell/shell-tasks.cc, src/shell/shell-tasks.hh:
Add shell's tasks.
* src/shell/Makefile.am:
Distribute shell.
* src/modules.hh:
Declare shell.
* configure.ac:
Check for readline library. Add shell directory.
* src/Makefile.am:
Add shell directory and link with readline.
")
(New-Version-Log
"")
(Checkin-Time "Sun, 04 Apr 2004 22:19:20 +0200")
(Checkin-Time "Sat, 24 Apr 2004 17:24:51 +0200")
(Checkin-Login benoit)
(Files
......@@ -33,14 +43,14 @@ from Beno
;; ./
(AUTHORS (mipsy/0_AUTHORS 1.1 644))
(COPYING (mipsy/1_COPYING 1.1 644))
(ChangeLog (mipsy/2_ChangeLog 1.77 604))
(ChangeLog (mipsy/2_ChangeLog 1.78 604))
(INSTALL (mipsy/b/12_INSTALL 1.1 604))
(Makefile.am (mipsy/3_Makefile.a 1.8 604))
(NEWS (mipsy/b/25_NEWS 1.8 604))
(README (mipsy/4_README 1.3 604))
(TODO (mipsy/5_TODO 1.3 604))
(bootstrap (mipsy/b/14_bootstrap 1.3 705))
(configure.ac (mipsy/6_configure. 1.7 604))
(configure.ac (mipsy/6_configure. 1.8 604))
(prj (mipsy.prj) :symlink)
;; ./config/
......@@ -64,12 +74,12 @@ from Beno
(doc/mipsy.texi (mipsy/b/10_mipsy.texi 1.5 604))
;; ./src/
(src/Makefile.am (mipsy/18_Makefile.a 1.2 644))
(src/Makefile.am (mipsy/18_Makefile.a 1.3 644))
(src/common.hh (mipsy/19_common.hh 1.5 644))
(src/mipsy-tasks.cc (mipsy/20_mipsy-task 1.3 644))
(src/mipsy-tasks.hh (mipsy/21_mipsy-task 1.3 644))
(src/mipsy.cc (mipsy/22_mipsy.cc 1.5 604))
(src/modules.hh (mipsy/23_modules.hh 1.3 644))
(src/modules.hh (mipsy/23_modules.hh 1.4 644))
;; ./src/inst/
(src/inst/data_section.hh (mipsy/24_data_secti 1.8 604))
......@@ -105,6 +115,14 @@ from Beno
(src/parse/parse-tasks.cc (mipsy/43_parse-task 1.7 644))
(src/parse/parse-tasks.hh (mipsy/44_parse-task 1.5 644))
;; ./src/shell/
(src/shell/Makefile.am (mipsy/b/17_Makefile.a 1.1 644))
(src/shell/cmd.hh (mipsy/b/18_cmd.hh 1.1 644))
(src/shell/shell-tasks.cc (mipsy/b/19_shell-task 1.1 644))
(src/shell/shell-tasks.hh (mipsy/c/22_shell-task 1.1 644))
(src/shell/shell.cc (mipsy/c/23_shell.cc 1.1 644))
(src/shell/shell.hh (mipsy/c/24_shell.hh 1.1 644))
;; ./src/task/
(src/task/Makefile.am (mipsy/45_Makefile.a 1.2 644))
(src/task/task-tasks.cc (mipsy/46_task-tasks 1.3 644))
......@@ -117,13 +135,13 @@ from Beno
;; ./src/vm/
(src/vm/Makefile.am (mipsy/b/0_Makefile.a 1.5 604))
(src/vm/cp0.hh (mipsy/b/16_cp0.hh 1.1 644))
(src/vm/cpu.hh (mipsy/b/1_cpu.hh 1.18 604))
(src/vm/cpu.cc (mipsy/b/5_virtual_ma 1.25 604))
(src/vm/cpu.hh (mipsy/b/1_cpu.hh 1.19 604))
(src/vm/cpu.cc (mipsy/b/5_virtual_ma 1.26 604))
(src/vm/memory.hh (mipsy/b/2_memory.hh 1.10 604))
(src/vm/mmu.hh (mipsy/c/15_mmu.hh 1.3 604))
(src/vm/segment.hh (mipsy/b/3_segment.hh 1.5 644))
(src/vm/table.hh (mipsy/b/4_table.hh 1.5 604))
(src/vm/virtual_machine.hh (mipsy/b/6_virtual_ma 1.17 604))
(src/vm/virtual_machine.hh (mipsy/b/6_virtual_ma 1.18 604))
(src/vm/vm-tasks.cc (mipsy/b/7_vm-tasks.c 1.7 604))
(src/vm/vm-tasks.hh (mipsy/b/8_vm-tasks.h 1.4 604))
......
......@@ -4,6 +4,7 @@ SUBDIRS = \
inst \
parse \
vm \
shell \
task
##
......@@ -21,4 +22,6 @@ mipsy_LDADD = \
parse/libparse.a \
vm/libvm.a \
inst/libinst.a \
task/libtask.a
shell/libshell.a \
task/libtask.a \
$(READLINE_LIBS)
......@@ -21,3 +21,4 @@
#include "parse/parse-tasks.hh"
#include "inst/inst-tasks.hh"
#include "vm/vm-tasks.hh"
#include "shell/shell-tasks.hh"
INCLUDES = -I $(top_srcdir)/src -I $(top_builddir)/src
noinst_LIBRARIES = libshell.a
libshell_a_SOURCES = \
cmd.hh \
shell.hh shell.cc \
shell-tasks.hh shell-tasks.cc
//
// This file is part of Mipsy, a tiny MIPS simulator
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Mipsy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Mipsy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
/** \file shell/cmd.hh
\brief Declare Command class. */
#ifndef SHELL_CMD_HH
# define SHELL_CMD_HH
# include <list>
# include <map>
# include <string>
# include <sstream>
# include <iostream>
# include <algorithm>
# include "common.hh"
# include "modules.hh"
# include "task/task_register.hh"
# include "parse/libparse.hh"
# include "vm/virtual_machine.hh"
# include "shell/shell.hh"
namespace shell
{
/// Cmd Class.
class Cmd
{
public:
/// Command Type.
enum cmd_type_type
{
cmd_unknown,
cmd_null,
cmd_load,
cmd_run,
cmd_quit,
cmd_continue,
cmd_break,
cmd_next,
cmd_print,
cmd_display,
cmd_undisplay,
cmd_dump,
cmd_mem,
cmd_fill_delay_slot,
cmd_help
};
typedef std::list<const std::string*> list_args_type;
/**\name Constructor and destructor
\{ */
public:
/// Construct a Cmd.
Cmd(const cmd_type_type cmd_type, Shell* sh):
cmd_type_(cmd_type),
sh_(sh),
list_args_()
{
}
/// Destroy a Cmd.
virtual ~Cmd()
{
for (list_args_type::iterator
i = list_args_.begin(); i != list_args_.end(); ++i)
delete *i;
list_args_.erase(list_args_.begin(), list_args_.end());
}
/** \} */
/// Add an argument
void push_arg(const std::string& arg)
{
list_args_.push_back(&arg);
}
/// Execute the Cmd.
int execute()
{
switch (cmd_type_)
{
case cmd_quit:
return 1;
case cmd_unknown:
e_error();
break;
case cmd_load:
e_load();
break;
case cmd_run:
e_run();
break;
case cmd_continue:
e_continue();
break;
case cmd_next:
e_next();
break;
case cmd_dump:
e_dump();
break;
case cmd_print:
e_print();
break;
case cmd_display:
e_display();
break;
case cmd_undisplay:
e_undisplay();
break;
case cmd_mem:
e_mem();
break;
case cmd_break:
e_break();
break;
case cmd_fill_delay_slot:
e_fill_delay_slot();
break;
case cmd_null:
break;
case cmd_help:
e_help();
}
return 0;
}
/// Return the Cmd type.
cmd_type_type get_cmd_type() const
{
return cmd_type_;
}
/** \name Function to execute.
\{ */
private:
void e_load()
{
const std::string* fileName = *(list_args_.begin());
char* tmpbuf = new char[fileName->length()];
strcpy(tmpbuf, fileName->c_str());
//filename = fileName->c_str();
filename = tmpbuf;
//std::cerr << "#DEBUG: _load: filename == " << filename << std::endl;
parse::tasks::parse();
inst::tasks::prg_solve();
sh_->vm_->load_program(* parse::tasks::program);
}
void e_run()
{
if (!parse::tasks::program)
{
std::cerr << "No program loaded." << std::endl;
return;
}
if (sh_->vm_->get_status() != vm::VirtualMachine::halt)
sh_->vm_->set_runnable();
else
{
sh_->vm_->reset();
sh_->vm_->set_runnable();
}
sh_->vm_->execute(false);
}
void e_continue()
{
if (!parse::tasks::program)
{
std::cerr << "No program loaded." << std::endl;
return;
}
if (sh_->vm_->get_status() != vm::VirtualMachine::halt)
{
sh_->vm_->set_runnable();
sh_->vm_->execute(false);
}
else
std::cerr << "The program is not being run." << std::endl;
}
void e_next()
{
if (!parse::tasks::program)
{
std::cerr << "No program loaded." << std::endl;
return;
}
if (sh_->vm_->get_status() != vm::VirtualMachine::halt)
{
sh_->vm_->set_run_next();
sh_->vm_->execute(true);
}
else
std::cerr << "The program is not being run." << std::endl;
}
void e_break()
{
if (!parse::tasks::program)
{
std::cerr << "No program loaded." << std::endl;
return;
}
const std::string* label = *(list_args_.begin());
//std::cerr <<"#DEBUG: label = " << *label << std::endl;
// sh_->vm_->add_break(*label);
sh_->vm_->add_breakpoint(*label);
}
void e_display()
{
const std::string* r = *(list_args_.begin());
const std::string* rr = new std::string(*r);
sh_->add_display(rr);
}
void e_undisplay()
{
sh_->remove_display(*(list_args_.begin()));
}
void e_dump()
{
std::cout << *(sh_->vm_) << std::endl;
}
void e_print()
{
const std::string* r = *(list_args_.begin());
std::cout << *r << " = " << sh_->get_register(*r) << std::endl;
}
void e_fill_delay_slot()
{
parse::tasks::fill_delay_slot();
}
void e_mem()
{
const std::string* addr = *(list_args_.begin());
//std::cout << "addr: " << *addr << " = " << sh_->vm_->get_memory_offset(atoi(addr->c_str())) << std::endl;
}
void e_error() const
{
std::cerr << "Command error" << std::endl;
}
void e_help() const
{
std::cout << "run <args>" << std::endl
<< "\trun the current loaded file with the specified arguments"
<< std::endl
<< "load <filename>" << std::endl
<< "\tload the specified filename" << std::endl
<< "break <label>" << std::endl
<< "\tenable a break point on a label" << std::endl
<< "quit" << std::endl
<< "\tquit the debugging session" << std::endl
<< "next" << std::endl
<< "\texecute the next asm line" << std::endl
<< "continue" << std::endl
<< "\tcontinue to the next breakpoint" << std::endl
<< "display <register>" << std::endl
<< "\tdisplay (and set displayable) a register value"
<< std::endl
<< "undisplay <register>" << std::endl
<< "\tundisplay a register" << std::endl
<< "print <register>" << std::endl
<< "\tprint a register value" << std::endl
<< "dump" << std::endl
<< "\tdump all the register value" << std::endl
<< "mem <addr>" << std::endl
<< "\tprint a the value of a memory region" << std::endl
<< "fill-delay-slot" << std::endl
<< "\tenable Fill delay slot of native branch instructions "
<< "with NOP" << std::endl;
}
/** \} */
private:
/// The command type.
cmd_type_type cmd_type_;
/// Link to shell class.
Shell* sh_;
/// List of arguments.
list_args_type list_args_;
};
} // namespace shell
#endif // !SHELL_CMD_HH
//
// This file is part of Mipsy, a tiny MIPS simulator
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Mipsy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Mipsy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "common.hh"
#include "shell/shell.hh"
// shell module related tasks' implementation.
namespace shell
{
namespace tasks
{
void
shell_exec()
{
shell::Shell sh;
sh.run();
}
} // namespace tasks
} // namespace shell
//
// This file is part of Mipsy, a tiny MIPS simulator
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Mipsy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Mipsy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#ifndef SHELL_SHELL_TASKS_HH
# define SHELL_SHELL_TASKS_HH
# include "task/task.hh"
namespace shell
{
namespace tasks
{
TASK_MODULE ("4. Shell");
TASK_DECLARE ("shell", "Enable shell interpreter",
shell_exec, "");
} // namespace tasks
} // namespace shell
#endif // !SHELL_SHELL_TASKS_HH
//
// This file is part of Mipsy, a tiny MIPS simulator
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Mipsy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Mipsy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "shell.hh"
#include "cmd.hh"
#include <readline/readline.h>
#include <readline/history.h>
namespace shell
{
Shell::Shell():
cmd_buf_(0),
pos_(0)
{
vm_ = new vm::VirtualMachine(true, false);