1
0
mirror of https://github.com/antonblanchard/microwatt.git synced 2026-01-11 23:43:15 +00:00

Consolidate VHPI code

We had many copies of the VHPI marshalling/unmarshalling code.

Signed-off-by: Anton Blanchard <anton@linux.ibm.com>
This commit is contained in:
Anton Blanchard 2020-01-22 14:50:45 +11:00 committed by Anton Blanchard
parent 6a9bc46fcb
commit 471c7e2197
6 changed files with 109 additions and 189 deletions

View File

@ -88,17 +88,17 @@ fpga/soc_reset_tb.o: fpga/soc_reset.o
soc_reset_tb: fpga/soc_reset_tb.o fpga/soc_reset.o
$(GHDL) -e $(GHDLFLAGS) --workdir=fpga soc_reset_tb
core_tb: core_tb.o sim_bram_helpers_c.o sim_console_c.o sim_jtag_socket_c.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_bram_helpers_c.o -Wl,sim_console_c.o -Wl,sim_jtag_socket_c.o $@
core_tb: core_tb.o sim_vhpi_c.o sim_bram_helpers_c.o sim_console_c.o sim_jtag_socket_c.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_vhpi_c.o -Wl,sim_bram_helpers_c.o -Wl,sim_console_c.o -Wl,sim_jtag_socket_c.o $@
fetch_tb: fetch_tb.o
$(GHDL) -e $(GHDLFLAGS) $@
icache_tb: icache_tb.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_bram_helpers_c.o $@
icache_tb: icache_tb.o sim_vhpi_c.o sim_bram_helpers_c.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_vhpi_c.o -Wl,sim_bram_helpers_c.o $@
dcache_tb: dcache_tb.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_bram_helpers_c.o $@
dcache_tb: dcache_tb.o sim_vhpi_c.o sim_bram_helpers_c.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_vhpi_c.o -Wl,sim_bram_helpers_c.o $@
plru_tb: plru_tb.o
$(GHDL) -e $(GHDLFLAGS) $@
@ -121,11 +121,11 @@ countzero_tb: countzero_tb.o
simple_ram_tb: simple_ram_tb.o
$(GHDL) -e $(GHDLFLAGS) $@
wishbone_bram_tb: sim_bram_helpers_c.o wishbone_bram_tb.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_bram_helpers_c.o $@
wishbone_bram_tb: sim_vhpi_c.o sim_bram_helpers_c.o wishbone_bram_tb.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_vhpi_c.o -Wl,sim_bram_helpers_c.o $@
dmi_dtm_tb: dmi_dtm_tb.o sim_bram_helpers_c.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_bram_helpers_c.o $@
dmi_dtm_tb: dmi_dtm_tb.o sim_vhpi_c.o sim_bram_helpers_c.o
$(GHDL) -e $(GHDLFLAGS) -Wl,sim_vhpi_c.o -Wl,sim_bram_helpers_c.o $@
tests = $(sort $(patsubst tests/%.out,%,$(wildcard tests/*.out)))

View File

@ -9,91 +9,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "sim_vhpi_c.h"
#undef DEBUG
#define ALIGN_UP(VAL, SIZE) (((VAL) + ((SIZE)-1)) & ~((SIZE)-1))
#define vhpi0 2 /* forcing 0 */
#define vhpi1 3 /* forcing 1 */
struct int_bounds
{
int left;
int right;
char dir;
unsigned int len;
};
struct fat_pointer
{
void *base;
struct int_bounds *bounds;
};
static char *from_string(void *__p)
{
struct fat_pointer *p = __p;
unsigned long len = p->bounds->len;
char *m;
m = malloc(len+1);
if (!m) {
perror("malloc");
exit(1);
}
memcpy(m, p->base, len);
m[len] = 0x0;
return m;
}
static uint64_t from_std_logic_vector(unsigned char *p, unsigned long len)
{
unsigned long ret = 0;
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
unsigned char bit;
if (*p == vhpi0) {
bit = 0;
} else if (*p == vhpi1) {
bit = 1;
} else {
fprintf(stderr, "%s: bad bit %d\n", __func__, *p);
bit = 0;
}
ret = (ret << 1) | bit;
p++;
}
return ret;
}
static void to_std_logic_vector(unsigned long val, unsigned char *p,
unsigned long len)
{
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
if ((val >> (len-1-i) & 1))
*p = vhpi1;
else
*p = vhpi0;
p++;
}
}
#define MAX_REGIONS 128
struct ram_behavioural {

View File

@ -6,59 +6,11 @@
#include <termios.h>
#include <unistd.h>
#include <poll.h>
#include "sim_vhpi_c.h"
/* Should we exit simulation on ctrl-c or pass it through? */
#define EXIT_ON_CTRL_C
#define vhpi0 2 /* forcing 0 */
#define vhpi1 3 /* forcing 1 */
static uint64_t from_std_logic_vector(unsigned char *p, unsigned long len)
{
unsigned long ret = 0;
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
unsigned char bit;
if (*p == vhpi0) {
bit = 0;
} else if (*p == vhpi1) {
bit = 1;
} else {
fprintf(stderr, "%s: bad bit %d\n", __func__, *p);
bit = 0;
}
ret = (ret << 1) | bit;
p++;
}
return ret;
}
static void to_std_logic_vector(unsigned long val, unsigned char *p,
unsigned long len)
{
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
if ((val >> (len-1-i) & 1))
*p = vhpi1;
else
*p = vhpi0;
p++;
}
}
static struct termios oldt;
static void disable_raw_mode(void)

View File

@ -9,60 +9,12 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "sim_vhpi_c.h"
/* XXX Make that some parameter */
#define TCP_PORT 13245
#define MAX_PACKET 32
#define vhpi0 2 /* forcing 0 */
#define vhpi1 3 /* forcing 1 */
static void to_std_logic_vector(unsigned long val, unsigned char *p,
unsigned long len)
{
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
if ((val >> (len-1-i) & 1))
*p = vhpi1;
else
*p = vhpi0;
p++;
}
}
static uint64_t from_std_logic_vector(unsigned char *p, unsigned long len)
{
unsigned long ret = 0;
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
unsigned char bit;
if (*p == vhpi0) {
bit = 0;
} else if (*p == vhpi1) {
bit = 1;
} else {
fprintf(stderr, "%s: bad bit %d\n", __func__, *p);
bit = 0;
}
ret = (ret << 1) | bit;
p++;
}
return ret;
}
static int fd = -1;
static int cfd = -1;

84
sim_vhpi_c.c Normal file
View File

@ -0,0 +1,84 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "sim_vhpi_c.h"
struct int_bounds
{
int left;
int right;
char dir;
unsigned int len;
};
struct fat_pointer
{
void *base;
struct int_bounds *bounds;
};
char *from_string(void *__p)
{
struct fat_pointer *p = __p;
unsigned long len = p->bounds->len;
char *m;
m = malloc(len+1);
if (!m) {
perror("malloc");
exit(1);
}
memcpy(m, p->base, len);
m[len] = 0x0;
return m;
}
uint64_t from_std_logic_vector(unsigned char *p, unsigned long len)
{
unsigned long ret = 0;
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
unsigned char bit;
if (*p == vhpi0) {
bit = 0;
} else if (*p == vhpi1) {
bit = 1;
} else {
fprintf(stderr, "%s: bad bit %d\n", __func__, *p);
bit = 0;
}
ret = (ret << 1) | bit;
p++;
}
return ret;
}
void to_std_logic_vector(unsigned long val, unsigned char *p,
unsigned long len)
{
if (len > 64) {
fprintf(stderr, "%s: invalid length %lu\n", __func__, len);
exit(1);
}
for (unsigned long i = 0; i < len; i++) {
if ((val >> (len-1-i) & 1))
*p = vhpi1;
else
*p = vhpi0;
p++;
}
}

11
sim_vhpi_c.h Normal file
View File

@ -0,0 +1,11 @@
#include <stdint.h>
#define vhpi0 2 /* forcing 0 */
#define vhpi1 3 /* forcing 1 */
char *from_string(void *__p);
uint64_t from_std_logic_vector(unsigned char *p, unsigned long len);
void to_std_logic_vector(unsigned long val, unsigned char *p,
unsigned long len);