support multicore boot
This commit is contained in:
parent
4f583a0651
commit
7f245c929c
|
@ -23,7 +23,7 @@ int main(int argc, char** argv)
|
|||
bool pkrun = true;
|
||||
bool testrun = false;
|
||||
htif_t* htif = NULL;
|
||||
int coreid = 0, i;
|
||||
int ncores = 1, i;
|
||||
addr_t sig_addr = 0;
|
||||
int sig_len = -1;
|
||||
bool assume0init = false;
|
||||
|
@ -57,6 +57,11 @@ int main(int argc, char** argv)
|
|||
if (s.length() > 2)
|
||||
csim_name = argv[i]+2;
|
||||
}
|
||||
else if (s.substr(0,2) == "-p")
|
||||
{
|
||||
if (s.length() > 2)
|
||||
ncores = atoi(argv[i]+2);
|
||||
}
|
||||
else if (s == "-testsig")
|
||||
{
|
||||
testrun = true;
|
||||
|
@ -75,14 +80,13 @@ int main(int argc, char** argv)
|
|||
|
||||
switch (simtype) // instantiate appropriate HTIF
|
||||
{
|
||||
case SIMTYPE_ISA: htif = new htif_isasim_t(htif_args); break;
|
||||
case SIMTYPE_RS232: htif = new htif_rs232_t(htif_args); break;
|
||||
case SIMTYPE_ETH: htif = new htif_eth_t(htif_args); break;
|
||||
case SIMTYPE_CSIM: htif = new htif_csim_t(csim_name, htif_args); break;
|
||||
case SIMTYPE_ISA: htif = new htif_isasim_t(ncores, htif_args); break;
|
||||
case SIMTYPE_RS232: htif = new htif_rs232_t(ncores, htif_args); break;
|
||||
case SIMTYPE_ETH: htif = new htif_eth_t(ncores, htif_args); break;
|
||||
case SIMTYPE_CSIM: htif = new htif_csim_t(ncores, csim_name, htif_args); break;
|
||||
default: abort();
|
||||
}
|
||||
htif->assume0init(assume0init);
|
||||
memif_t memif(htif);
|
||||
|
||||
if (i == argc) // make sure the user specified a target program
|
||||
{
|
||||
|
@ -119,7 +123,7 @@ int main(int argc, char** argv)
|
|||
std::string test_path = std::string(p) + "/riscv-pk";
|
||||
if (access(test_path.c_str(), F_OK) == 0)
|
||||
{
|
||||
load_elf(test_path.c_str(), &memif);
|
||||
load_elf(test_path.c_str(), &htif->memif());
|
||||
found = true;
|
||||
}
|
||||
p = next_p + 1;
|
||||
|
@ -139,15 +143,15 @@ int main(int argc, char** argv)
|
|||
fprintf(stderr, "could not open %s\n", target_argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
load_elf(target_argv[0], &memif);
|
||||
load_elf(target_argv[0], &htif->memif());
|
||||
}
|
||||
|
||||
htif->start(coreid);
|
||||
htif->start(0);
|
||||
|
||||
if (testrun)
|
||||
{
|
||||
reg_t tohost;
|
||||
while ((tohost = htif->read_cr(coreid, 30)) == 0);
|
||||
while ((tohost = htif->read_cr(0, 30)) == 0);
|
||||
if (tohost == 1)
|
||||
{
|
||||
if (sig_len != -1)
|
||||
|
@ -157,7 +161,7 @@ int main(int argc, char** argv)
|
|||
int sig_len_aligned = (sig_len + chunk_size - 1)/chunk_size*chunk_size;
|
||||
|
||||
uint8_t* signature = new uint8_t[sig_len_aligned];
|
||||
memif.read(sig_addr, sig_len, signature);
|
||||
htif->memif().read(sig_addr, sig_len, signature);
|
||||
for (int i = sig_len; i < sig_len_aligned; i++)
|
||||
signature[i] = 0;
|
||||
|
||||
|
@ -193,20 +197,25 @@ int main(int argc, char** argv)
|
|||
assert(tcsetattr(0, TCSANOW, &new_tios) == 0);
|
||||
}
|
||||
|
||||
while (true)
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
for (int coreid = 0; coreid < ncores && !done; coreid++)
|
||||
{
|
||||
reg_t tohost;
|
||||
while ((tohost = htif->read_cr(coreid, 30)) == 0);
|
||||
if (dispatch_syscall(htif, &memif, tohost))
|
||||
break;
|
||||
if ((tohost = htif->read_cr(coreid, 30)) != 0)
|
||||
{
|
||||
done = dispatch_syscall(htif, &htif->memif(), tohost);
|
||||
htif->write_cr(coreid, 31, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reset_termios)
|
||||
tcsetattr(0, TCSANOW, &old_tios);
|
||||
}
|
||||
|
||||
htif->stop(coreid);
|
||||
htif->stop(0);
|
||||
delete htif;
|
||||
|
||||
return exit_code;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
htif_t::htif_t()
|
||||
: writezeros(true), seqno(1)
|
||||
htif_t::htif_t(int nc)
|
||||
: mem(this), ncores(nc), writezeros(true), seqno(1)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,15 @@ void htif_t::write_packet(const packet_t& p)
|
|||
void htif_t::start(int coreid)
|
||||
{
|
||||
writezeros = true;
|
||||
write_cr(coreid, 29, 1);
|
||||
|
||||
uint32_t buf[16] = {mem_mb(), ncores};
|
||||
write_chunk(0, sizeof(buf), (uint8_t *)buf);
|
||||
|
||||
for (int i = 0; i < ncores; i++)
|
||||
{
|
||||
write_cr(i, 29, 1);
|
||||
write_cr(i, 10, i);
|
||||
}
|
||||
write_cr(coreid, 29, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,20 +2,22 @@
|
|||
#define __HTIF_H
|
||||
|
||||
#include <string.h>
|
||||
#include "htif-packet.h"
|
||||
#include "memif.h"
|
||||
|
||||
class htif_t
|
||||
{
|
||||
public:
|
||||
htif_t();
|
||||
htif_t(int ncores);
|
||||
virtual ~htif_t();
|
||||
|
||||
virtual void start(int coreid);
|
||||
virtual void stop(int coreid);
|
||||
|
||||
virtual uint32_t mem_mb() = 0;
|
||||
virtual reg_t read_cr(int coreid, int regnum);
|
||||
virtual void write_cr(int coreid, int regnum, reg_t val);
|
||||
|
||||
virtual memif_t& memif() { return mem; }
|
||||
virtual void assume0init(bool val = true);
|
||||
|
||||
protected:
|
||||
|
@ -28,7 +30,10 @@ class htif_t
|
|||
virtual ssize_t read(void* buf, size_t max_size) = 0;
|
||||
virtual ssize_t write(const void* buf, size_t size) = 0;
|
||||
|
||||
int ncores;
|
||||
|
||||
private:
|
||||
memif_t mem;
|
||||
bool writezeros;
|
||||
seqno_t seqno;
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
htif_csim_t::htif_csim_t(const char* progname, std::vector<char*> args)
|
||||
htif_csim_t::htif_csim_t(int ncores, const char* progname, std::vector<char*> args)
|
||||
: htif_t(ncores)
|
||||
{
|
||||
int fromhost[2], tohost[2], flags;
|
||||
assert(pipe(fromhost) == 0);
|
||||
|
|
|
@ -7,17 +7,10 @@
|
|||
class htif_csim_t : public htif_t
|
||||
{
|
||||
public:
|
||||
htif_csim_t(const char* progname, std::vector<char*> args);
|
||||
htif_csim_t(int ncores, const char* progname, std::vector<char*> args);
|
||||
~htif_csim_t();
|
||||
|
||||
void start(int coreid)
|
||||
{
|
||||
// write memory size (in MB) and # cores in words 0, 1
|
||||
uint32_t buf[16] = {512,1};
|
||||
write_chunk(0, sizeof(buf), (uint8_t *)buf);
|
||||
|
||||
htif_t::start(coreid);
|
||||
}
|
||||
uint32_t mem_mb() { return 512; }
|
||||
|
||||
protected:
|
||||
ssize_t read(void* buf, size_t max_size)
|
||||
|
|
|
@ -32,8 +32,8 @@ struct eth_packet_t
|
|||
char htif_payload[ETH_MAX_DATA_SIZE];
|
||||
};
|
||||
|
||||
htif_eth_t::htif_eth_t(std::vector<char*> args)
|
||||
: rtlsim(false)
|
||||
htif_eth_t::htif_eth_t(int ncores, std::vector<char*> args)
|
||||
: htif_t(ncores), rtlsim(false)
|
||||
{
|
||||
const char* mac_str = "feedfacebeef";
|
||||
#ifdef __linux__
|
||||
|
|
|
@ -26,17 +26,10 @@ const unsigned short HTIF_ETHERTYPE = 0x8888;
|
|||
class htif_eth_t : public htif_t
|
||||
{
|
||||
public:
|
||||
htif_eth_t(std::vector<char*> args);
|
||||
htif_eth_t(int ncores, std::vector<char*> args);
|
||||
virtual ~htif_eth_t();
|
||||
|
||||
void start(int coreid)
|
||||
{
|
||||
// write memory size (in MB) and # cores in words 0, 1
|
||||
uint32_t buf[16] = {512,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
write_chunk(0, sizeof(buf), (uint8_t *)buf);
|
||||
|
||||
htif_t::start(coreid);
|
||||
}
|
||||
uint32_t mem_mb() { return 512; }
|
||||
|
||||
size_t chunk_align() { return ETH_DATA_ALIGN; }
|
||||
size_t chunk_max_size() { return ETH_MAX_DATA_SIZE; }
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
class htif_hexwriter_t : public htif_t
|
||||
{
|
||||
public:
|
||||
htif_hexwriter_t(size_t w, size_t d) : width(w),depth(d) {}
|
||||
htif_hexwriter_t(size_t w, size_t d) : htif_t(1), width(w), depth(d) {}
|
||||
|
||||
protected:
|
||||
size_t width;
|
||||
|
@ -24,6 +24,7 @@ protected:
|
|||
|
||||
ssize_t read(void* buf, size_t max_size) { abort(); }
|
||||
ssize_t write(const void* buf, size_t max_size) { abort(); }
|
||||
uint32_t mem_mb() { abort(); }
|
||||
|
||||
friend std::ostream& operator<< (std::ostream&, const htif_hexwriter_t&);
|
||||
};
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
htif_isasim_t::htif_isasim_t(std::vector<char*> args)
|
||||
htif_isasim_t::htif_isasim_t(int ncores, std::vector<char*> args)
|
||||
: htif_t(ncores)
|
||||
{
|
||||
int fromhost[2], tohost[2], flags;
|
||||
assert(pipe(fromhost) == 0);
|
||||
|
@ -22,13 +23,15 @@ htif_isasim_t::htif_isasim_t(std::vector<char*> args)
|
|||
|
||||
if (pid == 0)
|
||||
{
|
||||
char fromhost_arg[32], tohost_arg[32];
|
||||
char fromhost_arg[32], tohost_arg[32], ncores_arg[32];
|
||||
sprintf(fromhost_arg, "-f%d", fromhost[0]);
|
||||
sprintf(tohost_arg, "-t%d", tohost[1]);
|
||||
sprintf(ncores_arg, "-p%d", ncores);
|
||||
|
||||
args.insert(args.begin(), const_cast<char*>("riscv-isa-run"));
|
||||
args.push_back(fromhost_arg);
|
||||
args.push_back(tohost_arg);
|
||||
args.push_back(ncores_arg);
|
||||
|
||||
char* args_array[args.size()+1];
|
||||
memcpy(args_array, &args[0], args.size() * sizeof(char*));
|
||||
|
@ -42,6 +45,8 @@ htif_isasim_t::htif_isasim_t(std::vector<char*> args)
|
|||
|
||||
fdin = tohost[0];
|
||||
fdout = fromhost[1];
|
||||
|
||||
memsize_mb = memif().read_uint32(0);
|
||||
}
|
||||
|
||||
htif_isasim_t::~htif_isasim_t()
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
class htif_isasim_t : public htif_t
|
||||
{
|
||||
public:
|
||||
htif_isasim_t(std::vector<char*> args);
|
||||
htif_isasim_t(int ncores, std::vector<char*> args);
|
||||
~htif_isasim_t();
|
||||
|
||||
uint32_t mem_mb() { return memsize_mb; }
|
||||
|
||||
protected:
|
||||
ssize_t read(void* buf, size_t max_size)
|
||||
{
|
||||
|
@ -25,6 +27,7 @@ class htif_isasim_t : public htif_t
|
|||
size_t chunk_align() { return 16; }
|
||||
|
||||
private:
|
||||
uint32_t memsize_mb;
|
||||
int pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#define debug(...)
|
||||
//#define debug(...) fprintf(stderr,__VA_ARGS__)
|
||||
|
||||
htif_rs232_t::htif_rs232_t(std::vector<char*> args)
|
||||
htif_rs232_t::htif_rs232_t(int ncores, std::vector<char*> args)
|
||||
: htif_t(ncores)
|
||||
{
|
||||
char* tty = NULL;
|
||||
for (size_t i = 0; i < args.size(); i++)
|
||||
|
|
|
@ -7,17 +7,10 @@
|
|||
class htif_rs232_t : public htif_t
|
||||
{
|
||||
public:
|
||||
htif_rs232_t(std::vector<char*> args);
|
||||
htif_rs232_t(int ncores, std::vector<char*> args);
|
||||
~htif_rs232_t();
|
||||
|
||||
void start(int coreid)
|
||||
{
|
||||
// write memory size (in MB) and # cores in words 0, 1
|
||||
uint32_t buf[16] = {512,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||
write_chunk(0, sizeof(buf), (uint8_t *)buf);
|
||||
|
||||
htif_t::start(coreid);
|
||||
}
|
||||
uint32_t mem_mb() { return 512; }
|
||||
|
||||
protected:
|
||||
ssize_t read(void* buf, size_t max_size);
|
||||
|
|
|
@ -32,10 +32,11 @@
|
|||
#ifndef __MEMIF_H
|
||||
#define __MEMIF_H
|
||||
|
||||
#include "htif-packet.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "htif.h"
|
||||
|
||||
class htif_t;
|
||||
class memif_t
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue