simX openfile working
This commit is contained in:
@@ -12,7 +12,7 @@ COMP=--compiler gcc
|
||||
LIB=
|
||||
CF=-CFLAGS '-std=c++11 -fPIC -O3'
|
||||
|
||||
LIGHTW=-Wno-UNOPTFLAT -Wno-BLKLOOPINIT
|
||||
LIGHTW=-Wno-UNOPTFLAT
|
||||
DEB=--trace --prof-cfuncs -DVL_DEBUG=1
|
||||
EXE=--exe $(LIB_OBJS)
|
||||
|
||||
|
||||
@@ -579,20 +579,27 @@ void Core::writeback()
|
||||
// cout << "WRITEBACK SERVICED EXE\n";
|
||||
}
|
||||
|
||||
if ((inst_in_lsu.rd > 0) && (inst_in_lsu.mem_stall_cycles == 0))
|
||||
if (inst_in_lsu.is_sw)
|
||||
{
|
||||
if (serviced_exe)
|
||||
{
|
||||
cout << "$$$$$$$$$$$$$$$$$$$$ Stalling LSU because EXE is being used\n";
|
||||
inst_in_lsu.stalled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
serviced_mem = true;
|
||||
CPY_TRACE(inst_in_wb, inst_in_lsu);
|
||||
INIT_TRACE(inst_in_lsu);
|
||||
INIT_TRACE(inst_in_lsu);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((inst_in_lsu.rd > 0) && (inst_in_lsu.mem_stall_cycles == 0))
|
||||
{
|
||||
if (serviced_exe)
|
||||
{
|
||||
cout << "$$$$$$$$$$$$$$$$$$$$ Stalling LSU because EXE is being used\n";
|
||||
inst_in_lsu.stalled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
serviced_mem = true;
|
||||
CPY_TRACE(inst_in_wb, inst_in_lsu);
|
||||
INIT_TRACE(inst_in_lsu);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (!serviced_exe && !serviced_mem) INIT_TRACE(inst_in_wb);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <pthread.h>
|
||||
// #include <pthread.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
@@ -53,32 +53,32 @@ namespace Harp {
|
||||
};
|
||||
|
||||
class Core;
|
||||
class ConsoleMemDevice : public MemDevice {
|
||||
public:
|
||||
ConsoleMemDevice(Size wS, std::ostream &o, Core &core, bool batch = false);
|
||||
~ConsoleMemDevice() {}
|
||||
// class ConsoleMemDevice : public MemDevice {
|
||||
// public:
|
||||
// ConsoleMemDevice(Size wS, std::ostream &o, Core &core, bool batch = false);
|
||||
// ~ConsoleMemDevice() {}
|
||||
|
||||
//virtual Size wordSize() const { return wordSize; }
|
||||
virtual Size size() const { return wordSize; }
|
||||
virtual Word read(Addr) { pthread_mutex_lock(&cBufLock);
|
||||
char c = cBuf.front();
|
||||
cBuf.pop();
|
||||
pthread_mutex_unlock(&cBufLock);
|
||||
return Word(c); }
|
||||
virtual void write(Addr a, Word w) { output << char(w); }
|
||||
// //virtual Size wordSize() const { return wordSize; }
|
||||
// virtual Size size() const { return wordSize; }
|
||||
// virtual Word read(Addr) { pthread_mutex_lock(&cBufLock);
|
||||
// char c = cBuf.front();
|
||||
// cBuf.pop();
|
||||
// pthread_mutex_unlock(&cBufLock);
|
||||
// return Word(c); }
|
||||
// virtual void write(Addr a, Word w) { output << char(w); }
|
||||
|
||||
void poll();
|
||||
// void poll();
|
||||
|
||||
friend void *Harp::consoleInputThread(void *);
|
||||
// friend void *Harp::consoleInputThread(void *);
|
||||
|
||||
private:
|
||||
std::ostream &output;
|
||||
Size wordSize;
|
||||
Core &core;
|
||||
// private:
|
||||
// std::ostream &output;
|
||||
// Size wordSize;
|
||||
// Core &core;
|
||||
|
||||
std::queue<char> cBuf;
|
||||
pthread_mutex_t cBufLock;
|
||||
};
|
||||
// std::queue<char> cBuf;
|
||||
// pthread_mutex_t cBufLock;
|
||||
// };
|
||||
|
||||
class DiskControllerMemDevice : public MemDevice {
|
||||
public:
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#ifdef EMU_INSTRUMENTATION
|
||||
#include "include/qsim-harp.h"
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace Harp;
|
||||
@@ -83,7 +84,7 @@ Word signExt(Word w, Size bit, Word mask) {
|
||||
void upload(unsigned * addr, char * src, int size, Warp & c)
|
||||
{
|
||||
|
||||
cerr << "WRITING FINAL: " << *src << " size: " << size << "\n";
|
||||
// cerr << "WRITING FINAL: " << *src << " size: " << size << "\n";
|
||||
|
||||
unsigned current_addr = *addr;
|
||||
|
||||
@@ -94,11 +95,13 @@ void upload(unsigned * addr, char * src, int size, Warp & c)
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
unsigned value = src[i] & 0x000000FF;
|
||||
cerr << "UPLOAD: (" << hex << current_addr << dec << ") = " << hex << ( value) << dec << "\n";
|
||||
// cerr << "UPLOAD: (" << hex << current_addr << dec << ") = " << hex << ( value) << dec << "\n";
|
||||
c.core->mem.write(current_addr, value, c.supervisorMode, 1);
|
||||
current_addr += 1;
|
||||
}
|
||||
|
||||
current_addr += (current_addr % 4);
|
||||
|
||||
*addr = current_addr;
|
||||
}
|
||||
|
||||
@@ -120,6 +123,8 @@ void download(unsigned * addr, char * drain, Warp & c)
|
||||
current_addr += 1;
|
||||
}
|
||||
|
||||
current_addr += (current_addr % 4);
|
||||
|
||||
*addr = current_addr;
|
||||
}
|
||||
|
||||
@@ -151,6 +156,7 @@ void downloadAlloc(unsigned * addr, char ** drain_ptr, int & size, Warp & c)
|
||||
#define READ 4
|
||||
#define WRITE 5
|
||||
#define FSTAT 6
|
||||
#define OPEN 7
|
||||
|
||||
void trap_to_simulator(Warp & c)
|
||||
{
|
||||
@@ -173,7 +179,7 @@ void trap_to_simulator(Warp & c)
|
||||
int command;
|
||||
download(&read_buffer, (char *) &command, c);
|
||||
|
||||
cerr << "Command: " << hex << command << dec << '\n';
|
||||
// cerr << "Command: " << hex << command << dec << '\n';
|
||||
|
||||
switch (command)
|
||||
{
|
||||
@@ -197,7 +203,27 @@ void trap_to_simulator(Warp & c)
|
||||
case (READ):
|
||||
{
|
||||
|
||||
cerr << "trap_to_simulator: READ not supported yet\n";
|
||||
// cerr << "trap_to_simulator: READ not supported yet\n";
|
||||
int file;
|
||||
unsigned ptr;
|
||||
int len;
|
||||
|
||||
download(&read_buffer, (char *) &file , c);
|
||||
download(&read_buffer, (char *) &ptr , c);
|
||||
download(&read_buffer, (char *) &len , c);
|
||||
|
||||
char * buff = (char *) malloc(len);
|
||||
|
||||
int ret = read(file, buff, len);
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
c.core->mem.write(ptr, buff[i], c.supervisorMode, 1);
|
||||
ptr++;
|
||||
}
|
||||
// c.core->mem.write(ptr, 0, c.supervisorMode, 1);
|
||||
free(buff);
|
||||
|
||||
}
|
||||
break;
|
||||
case (WRITE):
|
||||
@@ -211,7 +237,7 @@ void trap_to_simulator(Warp & c)
|
||||
char * buf;
|
||||
downloadAlloc(&read_buffer, &buf, size, c);
|
||||
|
||||
write(file, buf, size);
|
||||
int e = write(file, buf, size);
|
||||
free(buf);
|
||||
}
|
||||
break;
|
||||
@@ -224,18 +250,18 @@ void trap_to_simulator(Warp & c)
|
||||
struct stat st;
|
||||
fstat(file, &st);
|
||||
|
||||
// fprintf(stderr, "------------------------\n");
|
||||
// fprintf(stderr, "Size of struct: %x\n", sizeof(struct stat));
|
||||
// fprintf(stderr, "st_mode: %x\n", st.st_mode);
|
||||
// fprintf(stderr, "st_dev: %x\n", st.st_dev);
|
||||
// fprintf(stderr, "st_ino: %x\n", st.st_ino);
|
||||
// fprintf(stderr, "st_uid: %x\n", st.st_uid);
|
||||
// fprintf(stderr, "st_gid: %x\n", st.st_gid);
|
||||
// fprintf(stderr, "st_rdev: %x\n", st.st_rdev);
|
||||
// fprintf(stderr, "st_size: %x\n", st.st_size);
|
||||
// fprintf(stderr, "st_blksize: %x\n", st.st_blksize);
|
||||
// fprintf(stderr, "st_blocks: %x\n", st.st_blocks);
|
||||
// fprintf(stderr, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
||||
fprintf(stderr, "------------------------\n");
|
||||
fprintf(stderr, "Size of struct: %x\n", sizeof(struct stat));
|
||||
fprintf(stderr, "st_mode: %x\n", st.st_mode);
|
||||
fprintf(stderr, "st_dev: %x\n", st.st_dev);
|
||||
fprintf(stderr, "st_ino: %x\n", st.st_ino);
|
||||
fprintf(stderr, "st_uid: %x\n", st.st_uid);
|
||||
fprintf(stderr, "st_gid: %x\n", st.st_gid);
|
||||
fprintf(stderr, "st_rdev: %x\n", st.st_rdev);
|
||||
fprintf(stderr, "st_size: %x\n", st.st_size);
|
||||
fprintf(stderr, "st_blksize: %x\n", st.st_blksize);
|
||||
fprintf(stderr, "st_blocks: %x\n", st.st_blocks);
|
||||
fprintf(stderr, "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
||||
|
||||
upload(&write_buffer, (char *) &st.st_mode , sizeof(st.st_mode), c);
|
||||
upload(&write_buffer, (char *) &st.st_dev , sizeof(st.st_dev), c);
|
||||
@@ -255,6 +281,46 @@ void trap_to_simulator(Warp & c)
|
||||
unsigned data_read = c.core->mem.read(new_addr, c.supervisorMode);
|
||||
cerr << hex << new_addr << ": " << data_read << "\n";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (OPEN):
|
||||
{
|
||||
// cerr << "$$$$$$$$$$$$$$$$$$$$$$$$$ OPEN FROM simX\n";
|
||||
unsigned name_ptr;
|
||||
unsigned flags;
|
||||
unsigned mode;
|
||||
|
||||
download(&read_buffer, (char *) &name_ptr, c);
|
||||
download(&read_buffer, (char *) &flags , c);
|
||||
download(&read_buffer, (char *) &mode , c);
|
||||
|
||||
char buffer[255];
|
||||
unsigned read_word;
|
||||
char read_byte;
|
||||
|
||||
int curr_ind = 0;
|
||||
|
||||
read_word = c.core->mem.read(name_ptr, c.supervisorMode);
|
||||
read_byte = (char) (read_word & 0x000000FF);
|
||||
while (read_byte != 0)
|
||||
{
|
||||
buffer[curr_ind] = read_byte;
|
||||
|
||||
name_ptr++;
|
||||
curr_ind++;
|
||||
read_word = c.core->mem.read(name_ptr, c.supervisorMode);
|
||||
read_byte = (char) (read_word & 0x000000FF);
|
||||
}
|
||||
buffer[curr_ind] = 0;
|
||||
|
||||
|
||||
int fd = open(buffer, flags, mode);
|
||||
|
||||
// fprintf(stderr, "Name: --%s-- and fd: %d\n", buffer, fd);
|
||||
|
||||
upload(&write_buffer, (char *) &fd, sizeof(int), c);
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
54
simX/mem.cpp
54
simX/mem.cpp
@@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
// #include <pthread.h>
|
||||
|
||||
#include "include/debug.h"
|
||||
#include "include/types.h"
|
||||
@@ -206,35 +206,35 @@ void MemoryUnit::tlbRm(Addr va) {
|
||||
}
|
||||
|
||||
void *Harp::consoleInputThread(void* arg_vp) {
|
||||
ConsoleMemDevice *arg = (ConsoleMemDevice *)arg_vp;
|
||||
char c;
|
||||
while (cin) {
|
||||
c = cin.get();
|
||||
pthread_mutex_lock(&arg->cBufLock);
|
||||
arg->cBuf.push(c);
|
||||
pthread_mutex_unlock(&arg->cBufLock);
|
||||
}
|
||||
cout << "Console input ended. Exiting.\n";
|
||||
exit(4);
|
||||
// ConsoleMemDevice *arg = (ConsoleMemDevice *)arg_vp;
|
||||
// char c;
|
||||
// while (cin) {
|
||||
// c = cin.get();
|
||||
// pthread_mutex_lock(&arg->cBufLock);
|
||||
// arg->cBuf.push(c);
|
||||
// pthread_mutex_unlock(&arg->cBufLock);
|
||||
// }
|
||||
// cout << "Console input ended. Exiting.\n";
|
||||
// exit(4);
|
||||
}
|
||||
|
||||
ConsoleMemDevice::ConsoleMemDevice(Size wS, std::ostream &o, Core &core,
|
||||
bool batch) :
|
||||
wordSize(wS), output(o), core(core), cBuf()
|
||||
{
|
||||
// Create a console input thread if we are running in interactive mode.
|
||||
if (!batch) {
|
||||
pthread_t *thread = new pthread_t;
|
||||
pthread_create(thread, NULL, consoleInputThread, (void*)this);
|
||||
}
|
||||
pthread_mutex_init(&cBufLock, NULL);
|
||||
}
|
||||
// ConsoleMemDevice::ConsoleMemDevice(Size wS, std::ostream &o, Core &core,
|
||||
// bool batch) :
|
||||
// wordSize(wS), output(o), core(core), cBuf()
|
||||
// {
|
||||
// // Create a console input thread if we are running in interactive mode.
|
||||
// if (!batch) {
|
||||
// pthread_t *thread = new pthread_t;
|
||||
// pthread_create(thread, NULL, consoleInputThread, (void*)this);
|
||||
// }
|
||||
// pthread_mutex_init(&cBufLock, NULL);
|
||||
// }
|
||||
|
||||
void ConsoleMemDevice::poll() {
|
||||
pthread_mutex_lock(&cBufLock);
|
||||
if (!cBuf.empty()) core.interrupt(8);
|
||||
pthread_mutex_unlock(&cBufLock);
|
||||
}
|
||||
// void ConsoleMemDevice::poll() {
|
||||
// pthread_mutex_lock(&cBufLock);
|
||||
// if (!cBuf.empty()) core.interrupt(8);
|
||||
// pthread_mutex_unlock(&cBufLock);
|
||||
// }
|
||||
|
||||
Word DiskControllerMemDevice::read(Addr a) {
|
||||
switch (a/8) {
|
||||
|
||||
1
simX/reading_data.txt
Normal file
1
simX/reading_data.txt
Normal file
@@ -0,0 +1 @@
|
||||
hello this is the data read from a file!
|
||||
@@ -98,9 +98,9 @@ int emu_main(int argc, char **argv) {
|
||||
// old_ram.loadHexImpl(tests[t]);
|
||||
// MemDevice * memory = &old_ram;
|
||||
|
||||
ConsoleMemDevice console(arch.getWordSize(), cout, core, batch);
|
||||
// ConsoleMemDevice console(arch.getWordSize(), cout, core, batch);
|
||||
mu.attach(old_ram, 0);
|
||||
mu.attach(console, 1ll<<(arch.getWordSize()*8 - 1));
|
||||
// mu.attach(console, 1ll<<(arch.getWordSize()*8 - 1));
|
||||
// mu.attach(console, 0xf0000000);
|
||||
|
||||
// core.w[0].pc = 0x8000007c; // If I want to start at a specific location
|
||||
@@ -127,7 +127,7 @@ int emu_main(int argc, char **argv) {
|
||||
struct stat hello;
|
||||
fstat(0, &hello);
|
||||
|
||||
while (core.running()) { console.poll(); core.step(); }
|
||||
while (core.running()) {core.step(); }
|
||||
|
||||
if (showStats) core.printStats();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user