};
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)
{
}
{
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)
{
{
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)
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");
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;
}
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);
}
}
}
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);