[sim] various fixes to get the sim work with the fesvr
authorYunsup Lee <yunsup@cs.berkeley.edu>
Fri, 23 Jul 2010 01:38:01 +0000 (18:38 -0700)
committerYunsup Lee <yunsup@cs.berkeley.edu>
Fri, 23 Jul 2010 01:38:26 +0000 (18:38 -0700)
riscv/applink.cc
riscv/load_elf.cc
riscv/riscv-isa-run.cc
riscv/sim.cc

index fdd6cc737b53c923dc4fdced5c377591c053e8fa..0937067dfeec48b8935da83898283dbbc5ecd3d3 100644 (file)
@@ -39,7 +39,7 @@ public:
 };
 
 appserver_link_t::appserver_link_t(int _tohost_fd, int _fromhost_fd)
-  : sim(NULL), tohost_fd(_tohost_fd), fromhost_fd(_fromhost_fd)
+  : sim(NULL), tohost_fd(_tohost_fd), fromhost_fd(_fromhost_fd), seqno(1)
 {
 }
 
@@ -57,9 +57,10 @@ void appserver_link_t::send_packet(packet* p)
 {
   while(1) try
   {
-    int bytes = write(fromhost_fd,p,offsetof(packet,data)+p->data_size);
+    int bytes = write(tohost_fd,p,offsetof(packet,data)+p->data_size);
     if(bytes == -1 || (size_t)bytes != offsetof(packet,data)+p->data_size)
       throw io_error("write failed");
+    return;
   }
   catch(io_error e)
   {
@@ -79,7 +80,7 @@ int appserver_link_t::wait_for_packet()
   {
     packet p;
     int bytes = read(fromhost_fd,&p,sizeof(p));
-    if(bytes != offsetof(packet,data))
+    if(bytes < offsetof(packet,data))
       throw io_error("read failed");
   
     if(p.seqno != seqno)
@@ -95,6 +96,7 @@ int appserver_link_t::wait_for_packet()
       case APP_CMD_START:
         break;
       case APP_CMD_STOP:
+        send_packet(&ackpacket);
         exit(0);
       case APP_CMD_READ_MEM:
         demand(p.addr % APP_DATA_ALIGN == 0, "misaligned address");
@@ -121,7 +123,7 @@ int appserver_link_t::wait_for_packet()
         demand(p.addr == 17,"bad control reg");
         demand(p.data_size == sizeof(reg_t),"bad control reg size");
         sim->tohost = 0;
-        memcpy(&sim->fromhost,ackpacket.data,sizeof(reg_t));
+        memcpy(&sim->fromhost,p.data,sizeof(reg_t));
         break;
     }
 
index c4f56f394b9a0b3d129ff7fda853d646e013e9ae..0161e42dcc1e5573eb4b13582dee79d6bcd81c8c 100644 (file)
@@ -25,6 +25,8 @@ void load_elf(const char* buf, size_t size, loader_t* loader)
 
       loader->write(ph->p_vaddr, ph->p_filesz, buf + ph->p_offset);
       loader->write(ph->p_vaddr + ph->p_filesz, ph->p_memsz - ph->p_filesz);
+
+      printf("%d\n", ph->p_vaddr);
     }
   }
 }
index ced7913238eb144ff017d28485d62d2a8ca0fc7a..098e68b86a3a80fb36fdbbdf0df6c362aae467d8 100644 (file)
@@ -32,7 +32,7 @@ int main(int argc, char** argv)
   demand(fcntl(fromhost_fd,F_GETFD) >= 0, "fromhost file not open");
   demand(fcntl(tohost_fd,F_GETFD) >= 0, "tohost file not open");
 
-  appserver_link_t applink(fromhost_fd,tohost_fd);
+  appserver_link_t applink(tohost_fd,fromhost_fd);
 
   sim_t s(nprocs,MEMSIZE,&applink);
   s.run(debug);
index dede8de570b4d51f96e2daa716c42f994cefeacf..50fa899d42bbd3affe25ae7218285192c05394af 100644 (file)
@@ -35,6 +35,8 @@ sim_t::sim_t(int _nprocs, size_t _memsz, appserver_link_t* _applink)
 
   for(int i = 0; i < (int)procs.size(); i++)
     procs[i].init(i);
+
+  applink->init(this);
 }
 
 sim_t::~sim_t()