
https://svn.lrde.epita.fr/svn/nolimips/trunk ChangeLog | 11 +++ src/vm-tasks.cc | 4 - src/vm/Makefile.am | 2 src/vm/nolimips_system_library.cc | 115 +++++++++++++++++++++++++++++++++++++ src/vm/nolimips_system_library.hh | 57 ++++++++++++++++++ src/vm/nolimips_system_library.hxx | 36 +++++++++++ 6 files changed, 224 insertions(+), 1 deletion(-) Index: ChangeLog from BenoƮt Perrot <benoit@lrde.epita.fr> Introduce nolimips system library. * src/vm/nolimips_system_library.hh, * src/vm/nolimips_system_library.hxx, * src/vm/nolimips_system_library.cc: Provide a set of some libc functions as syscalls. * src/vm/Makefile.am: Distribute these new files. * src/vm-tasks.cc: Fix missing include. Index: src/vm/nolimips_system_library.hh --- src/vm/nolimips_system_library.hh (revision 0) +++ src/vm/nolimips_system_library.hh (revision 197) @@ -0,0 +1,57 @@ +// +// This file is part of Nolimips, a MIPS simulator with unlimited registers +// Copyright (C) 2005 Benoit Perrot <benoit@lrde.epita.fr> +// +// Nolimips 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. +// +// Nolimips 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 VM_NOLIMIPS_SYSTEM_LIBRARY_HH +# define VM_NOLIMIPS_SYSTEM_LIBRARY_HH + +# include <iostream> +# include <map> + +# include "vm/system_library.hh" + +namespace vm +{ + + class Mmu; + + class NolimipsSystemLibrary: public SystemLibrary + { + public: + NolimipsSystemLibrary(std::istream &istr, + std::ostream &ostr, + std::ostream &estr); + virtual ~NolimipsSystemLibrary(); + + public: + virtual void invoke(Cpu &cpu); + + protected: + int read(int fd, Mmu &mmu, int offset, int count); + int write(int fd, const Mmu &mmu, int offset, int count); + + protected: + std::istream &istr_; + std::ostream &ostr_; + std::ostream &estr_; + }; + +} // namespace vm + +# include "vm/nolimips_system_library.hxx" + +#endif // !VM_NOLIMIPS_SYSTEM_LIBRARY_HH Index: src/vm/nolimips_system_library.hxx --- src/vm/nolimips_system_library.hxx (revision 0) +++ src/vm/nolimips_system_library.hxx (revision 197) @@ -0,0 +1,36 @@ +// +// This file is part of Nolimips, a MIPS simulator with unlimited registers +// Copyright (C) 2005 Benoit Perrot <benoit@lrde.epita.fr> +// +// Nolimips 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. +// +// Nolimips 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 VM_NOLIMIPS_SYSTEM_LIBRARY_HXX +# define VM_NOLIMIPS_SYSTEM_LIBRARY_HXX + +# include "vm/nolimips_system_library.hh" + +namespace vm +{ + + inline + NolimipsSystemLibrary::NolimipsSystemLibrary(std::istream &istr, + std::ostream &ostr, + std::ostream &estr): + istr_(istr), ostr_(ostr), estr_(estr) + {} + +} // namespace vm + +#endif // !VM_NOLIMIPS_SYSTEM_LIBRARY_HXX Index: src/vm/nolimips_system_library.cc --- src/vm/nolimips_system_library.cc (revision 0) +++ src/vm/nolimips_system_library.cc (revision 197) @@ -0,0 +1,115 @@ +// +// This file is part of Nolimips, a MIPS simulator with unlimited registers +// Copyright (C) 2005 Benoit Perrot <benoit@lrde.epita.fr> +// +// Nolimips 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. +// +// Nolimips 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 "vm/nolimips_system_library.hh" +#include "vm/cpu.hh" +#include "vm/mmu.hh" + +namespace vm +{ + + NolimipsSystemLibrary::~NolimipsSystemLibrary() + {} + + int + NolimipsSystemLibrary::read(int fd, Mmu &mmu, int offset, int count) + { + std::istream *istr = 0; + + if (fd == 0) + istr = &istr_; + + int i = -1; + if (istr) + { + for (i = 0; i < count; ++i, ++offset) + { + int c = istr->get(); + if (istr->eof()) + break; + + mmu.data_store_byte(offset, c); + } + } + + return i; + } + + int + NolimipsSystemLibrary::write(int fd, const Mmu &mmu, int offset, int count) + { + std::ostream *ostr = 0; + + if (fd == 1) + ostr = &ostr_; + else if (fd == 2) + ostr = &estr_; + + int i = -1; + if (ostr) + { + for (i = 0; i < count; ++i, ++offset) + ostr->put(static_cast<char>(mmu.data_load_byte(offset))); + } + + return i; + } + + void + NolimipsSystemLibrary::invoke(Cpu &cpu) + { + switch (cpu.get_register(Cpu::v0)) + { + case 0x02: // read(fd: $a0, buf: $a1, count: $a2): $v0 + { + cpu.set_register(Cpu::v0, + read(cpu.get_register(Cpu::a0), + cpu.get_mmu(), cpu.get_register(Cpu::a1), + cpu.get_register(Cpu::a2))); + } + break; + + case 0x03: // write(fd: $a0, buf: $a1, count: $a2): $v0 + { + cpu.set_register(Cpu::v0, + write(cpu.get_register(Cpu::a0), + cpu.get_mmu(), cpu.get_register(Cpu::a1), + cpu.get_register(Cpu::a2))); + } + break; + + case 0x06: // exit(status: $a0) + cpu.get_cp0().set_fatal_exception(); + if (!exit_status) + exit_status = (exit_type) cpu.get_register(Cpu::a0); + break; + + case 0x33: // malloc(size: $a0) + cpu.set_register(Cpu::v0, + cpu.get_mmu().data_sbrk(cpu.get_register(Cpu::a0))); + break; + + default: + assertion(!"syscall: Not implemented yet"); + break; + } + } + +} // namespace vm Index: src/vm/Makefile.am --- src/vm/Makefile.am (revision 196) +++ src/vm/Makefile.am (revision 197) @@ -10,4 +10,6 @@ system_library.hh system_library.cc \ spim_system_library.hh spim_system_library.hxx \ spim_system_library.cc \ + nolimips_system_library.hh nolimips_system_library.hxx \ + nolimips_system_library.cc \ virtual_machine.hh virtual_machine.cc Index: src/vm-tasks.cc --- src/vm-tasks.cc (revision 196) +++ src/vm-tasks.cc (revision 197) @@ -1,6 +1,6 @@ // // This file is part of Nolimips, a MIPS simulator with unlimited registers -// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr> +// Copyright (C) 2003, 2004, 2005 Benoit Perrot <benoit@lrde.epita.fr> // // Nolimips is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,6 +18,8 @@ // #include "common.hh" +#include "inst/program.hh" + #include "vm/spim_system_library.hh" #include "vm/virtual_machine.hh"