Commit 1fd5e72f authored by Benoit Perrot's avatar Benoit Perrot
Browse files

2005-10-01 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.
	
parent 5785ea3c
2005-10-01 Benot 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.
2005-09-35 Roland Levillain <roland@lrde.epita.fr> 2005-09-35 Roland Levillain <roland@lrde.epita.fr>
Work around Mac OS X ar's inability to produce an empty library. Work around Mac OS X ar's inability to produce an empty library.
......
// //
// This file is part of Nolimips, a MIPS simulator with unlimited registers // 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 // Nolimips is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
// //
#include "common.hh" #include "common.hh"
#include "inst/program.hh"
#include "vm/spim_system_library.hh" #include "vm/spim_system_library.hh"
#include "vm/virtual_machine.hh" #include "vm/virtual_machine.hh"
......
noinst_LIBRARIES = libvm.a noinst_LIBRARIES = libvm.a
libvm_a_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/src -I $(top_builddir)/src libvm_a_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/src -I $(top_builddir)/src
libvm_a_SOURCES = \ libvm_a_SOURCES = \
mmu.hh \ mmu.hh \
cp0.hh \ cp0.hh \
cpu.hh cpu.cc \ cpu.hh cpu.cc \
segment.hh \ segment.hh \
memory.hh \ memory.hh \
system_library.hh system_library.cc \ system_library.hh system_library.cc \
spim_system_library.hh spim_system_library.hxx \ spim_system_library.hh spim_system_library.hxx \
spim_system_library.cc \ spim_system_library.cc \
nolimips_system_library.hh nolimips_system_library.hxx \
nolimips_system_library.cc \
virtual_machine.hh virtual_machine.cc virtual_machine.hh virtual_machine.cc
//
// 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
//
// 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
//
// 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment