From: Yunsup Lee Date: Fri, 23 Jul 2010 01:38:01 +0000 (-0700) Subject: [sim] various fixes to get the sim work with the fesvr X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=133806b398a42da859a187eebf5792eeaed9e9d1;p=riscv-isa-sim.git [sim] various fixes to get the sim work with the fesvr --- diff --git a/riscv/applink.cc b/riscv/applink.cc index fdd6cc7..0937067 100644 --- a/riscv/applink.cc +++ b/riscv/applink.cc @@ -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; } diff --git a/riscv/load_elf.cc b/riscv/load_elf.cc index c4f56f3..0161e42 100644 --- a/riscv/load_elf.cc +++ b/riscv/load_elf.cc @@ -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); } } } diff --git a/riscv/riscv-isa-run.cc b/riscv/riscv-isa-run.cc index ced7913..098e68b 100644 --- a/riscv/riscv-isa-run.cc +++ b/riscv/riscv-isa-run.cc @@ -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); diff --git a/riscv/sim.cc b/riscv/sim.cc index dede8de..50fa899 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -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()