URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
Compare Revisions
- This comparison shows the changes necessary to convert path
/or1k/tags/nog_patch_72/or1ksim/vapi
- from Rev 1470 to Rev 1765
- ↔ Reverse comparison
Rev 1470 → Rev 1765
/Makefile.in
0,0 → 1,331
# Makefile.in generated by automake 1.6.3 from Makefile.am. |
# @configure_input@ |
|
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
# Free Software Foundation, Inc. |
# This Makefile.in is free software; the Free Software Foundation |
# gives unlimited permission to copy and/or distribute it, |
# with or without modifications, as long as this notice is preserved. |
|
# This program is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without |
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
# PARTICULAR PURPOSE. |
|
@SET_MAKE@ |
|
# Makefile -- Makefile for peripherals simulation |
# Copyright (C) 1999 Damjan Lampret, lampret@opencores.org |
# |
# This file is part of OpenRISC 1000 Architectural Simulator. |
# |
# This program is free software; you can redistribute it and/or modify |
# it under the terms of the GNU General Public License as published by |
# the Free Software Foundation; either version 2 of the License, or |
# (at your option) any later version. |
# |
# This program is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# GNU General Public License for more details. |
# |
# You should have received a copy of the GNU General Public License |
# along with this program; if not, write to the Free Software |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
# |
SHELL = @SHELL@ |
|
srcdir = @srcdir@ |
top_srcdir = @top_srcdir@ |
VPATH = @srcdir@ |
prefix = @prefix@ |
exec_prefix = @exec_prefix@ |
|
bindir = @bindir@ |
sbindir = @sbindir@ |
libexecdir = @libexecdir@ |
datadir = @datadir@ |
sysconfdir = @sysconfdir@ |
sharedstatedir = @sharedstatedir@ |
localstatedir = @localstatedir@ |
libdir = @libdir@ |
infodir = @infodir@ |
mandir = @mandir@ |
includedir = @includedir@ |
oldincludedir = /usr/include |
pkgdatadir = $(datadir)/@PACKAGE@ |
pkglibdir = $(libdir)/@PACKAGE@ |
pkgincludedir = $(includedir)/@PACKAGE@ |
top_builddir = .. |
|
ACLOCAL = @ACLOCAL@ |
AUTOCONF = @AUTOCONF@ |
AUTOMAKE = @AUTOMAKE@ |
AUTOHEADER = @AUTOHEADER@ |
|
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd |
INSTALL = @INSTALL@ |
INSTALL_PROGRAM = @INSTALL_PROGRAM@ |
INSTALL_DATA = @INSTALL_DATA@ |
install_sh_DATA = $(install_sh) -c -m 644 |
install_sh_PROGRAM = $(install_sh) -c |
install_sh_SCRIPT = $(install_sh) -c |
INSTALL_SCRIPT = @INSTALL_SCRIPT@ |
INSTALL_HEADER = $(INSTALL_DATA) |
transform = @program_transform_name@ |
NORMAL_INSTALL = : |
PRE_INSTALL = : |
POST_INSTALL = : |
NORMAL_UNINSTALL = : |
PRE_UNINSTALL = : |
POST_UNINSTALL = : |
build_alias = @build_alias@ |
build_triplet = @build@ |
host_alias = @host_alias@ |
host_triplet = @host@ |
target_alias = @target_alias@ |
target_triplet = @target@ |
|
EXEEXT = @EXEEXT@ |
OBJEXT = @OBJEXT@ |
PATH_SEPARATOR = @PATH_SEPARATOR@ |
AMTAR = @AMTAR@ |
AR = @AR@ |
ARFLAGS = @ARFLAGS@ |
AWK = @AWK@ |
BUILD_DIR = @BUILD_DIR@ |
CC = @CC@ |
CFLAGS = @CFLAGS@ |
CPU_ARCH = @CPU_ARCH@ |
DEPDIR = @DEPDIR@ |
INCLUDES = @INCLUDES@ |
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ |
LOCAL_CFLAGS = @LOCAL_CFLAGS@ |
LOCAL_DEFS = @LOCAL_DEFS@ |
MAKE_SHELL = @MAKE_SHELL@ |
PACKAGE = @PACKAGE@ |
RANLIB = @RANLIB@ |
STRIP = @STRIP@ |
SUMVERSION = @SUMVERSION@ |
TERMCAP_LIB = @TERMCAP_LIB@ |
VERSION = @VERSION@ |
am__include = @am__include@ |
am__quote = @am__quote@ |
host = @host@ |
host_cpu = @host_cpu@ |
host_os = @host_os@ |
install_sh = @install_sh@ |
|
noinst_LIBRARIES = libvapi.a |
libvapi_a_SOURCES = vapi.c vapi.h |
subdir = vapi |
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs |
CONFIG_HEADER = $(top_builddir)/config.h |
CONFIG_CLEAN_FILES = |
LIBRARIES = $(noinst_LIBRARIES) |
|
libvapi_a_AR = $(AR) cru |
libvapi_a_LIBADD = |
am_libvapi_a_OBJECTS = vapi.$(OBJEXT) |
libvapi_a_OBJECTS = $(am_libvapi_a_OBJECTS) |
|
DEFS = @DEFS@ |
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) |
CPPFLAGS = @CPPFLAGS@ |
LDFLAGS = @LDFLAGS@ |
LIBS = @LIBS@ |
depcomp = $(SHELL) $(top_srcdir)/depcomp |
am__depfiles_maybe = depfiles |
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/vapi.Po |
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ |
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) |
CCLD = $(CC) |
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ |
DIST_SOURCES = $(libvapi_a_SOURCES) |
DIST_COMMON = Makefile.am Makefile.in |
SOURCES = $(libvapi_a_SOURCES) |
|
all: all-am |
|
.SUFFIXES: |
.SUFFIXES: .c .o .obj |
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) |
cd $(top_srcdir) && \ |
$(AUTOMAKE) --gnu vapi/Makefile |
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status |
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) |
|
clean-noinstLIBRARIES: |
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) |
libvapi.a: $(libvapi_a_OBJECTS) $(libvapi_a_DEPENDENCIES) |
-rm -f libvapi.a |
$(libvapi_a_AR) libvapi.a $(libvapi_a_OBJECTS) $(libvapi_a_LIBADD) |
$(RANLIB) libvapi.a |
|
mostlyclean-compile: |
-rm -f *.$(OBJEXT) core *.core |
|
distclean-compile: |
-rm -f *.tab.c |
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vapi.Po@am__quote@ |
|
distclean-depend: |
-rm -rf ./$(DEPDIR) |
|
.c.o: |
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ |
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ |
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$< |
|
.c.obj: |
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ |
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ |
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
$(COMPILE) -c `cygpath -w $<` |
CCDEPMODE = @CCDEPMODE@ |
uninstall-info-am: |
|
ETAGS = etags |
ETAGSFLAGS = |
|
tags: TAGS |
|
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) |
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ |
unique=`for i in $$list; do \ |
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ |
done | \ |
$(AWK) ' { files[$$0] = 1; } \ |
END { for (i in files) print i; }'`; \ |
mkid -fID $$unique |
|
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ |
$(TAGS_FILES) $(LISP) |
tags=; \ |
here=`pwd`; \ |
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ |
unique=`for i in $$list; do \ |
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ |
done | \ |
$(AWK) ' { files[$$0] = 1; } \ |
END { for (i in files) print i; }'`; \ |
test -z "$(ETAGS_ARGS)$$tags$$unique" \ |
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ |
$$tags $$unique |
|
GTAGS: |
here=`$(am__cd) $(top_builddir) && pwd` \ |
&& cd $(top_srcdir) \ |
&& gtags -i $(GTAGS_ARGS) $$here |
|
distclean-tags: |
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH |
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) |
|
top_distdir = .. |
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) |
|
distdir: $(DISTFILES) |
@list='$(DISTFILES)'; for file in $$list; do \ |
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ |
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ |
if test "$$dir" != "$$file" && test "$$dir" != "."; then \ |
dir="/$$dir"; \ |
$(mkinstalldirs) "$(distdir)$$dir"; \ |
else \ |
dir=''; \ |
fi; \ |
if test -d $$d/$$file; then \ |
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ |
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ |
fi; \ |
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ |
else \ |
test -f $(distdir)/$$file \ |
|| cp -p $$d/$$file $(distdir)/$$file \ |
|| exit 1; \ |
fi; \ |
done |
check-am: all-am |
check: check-am |
all-am: Makefile $(LIBRARIES) |
|
installdirs: |
|
install: install-am |
install-exec: install-exec-am |
install-data: install-data-am |
uninstall: uninstall-am |
|
install-am: all-am |
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am |
|
installcheck: installcheck-am |
install-strip: |
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ |
INSTALL_STRIP_FLAG=-s \ |
`test -z '$(STRIP)' || \ |
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install |
mostlyclean-generic: |
|
clean-generic: |
|
distclean-generic: |
-rm -f Makefile $(CONFIG_CLEAN_FILES) |
|
maintainer-clean-generic: |
@echo "This command is intended for maintainers to use" |
@echo "it deletes files that may require special tools to rebuild." |
clean: clean-am |
|
clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am |
|
distclean: distclean-am |
|
distclean-am: clean-am distclean-compile distclean-depend \ |
distclean-generic distclean-tags |
|
dvi: dvi-am |
|
dvi-am: |
|
info: info-am |
|
info-am: |
|
install-data-am: |
|
install-exec-am: |
|
install-info: install-info-am |
|
install-man: |
|
installcheck-am: |
|
maintainer-clean: maintainer-clean-am |
|
maintainer-clean-am: distclean-am maintainer-clean-generic |
|
mostlyclean: mostlyclean-am |
|
mostlyclean-am: mostlyclean-compile mostlyclean-generic |
|
uninstall-am: uninstall-info-am |
|
.PHONY: GTAGS all all-am check check-am clean clean-generic \ |
clean-noinstLIBRARIES distclean distclean-compile \ |
distclean-depend distclean-generic distclean-tags distdir dvi \ |
dvi-am info info-am install install-am install-data \ |
install-data-am install-exec install-exec-am install-info \ |
install-info-am install-man install-strip installcheck \ |
installcheck-am installdirs maintainer-clean \ |
maintainer-clean-generic mostlyclean mostlyclean-compile \ |
mostlyclean-generic tags uninstall uninstall-am \ |
uninstall-info-am |
|
# Tell versions [3.59,3.63) of GNU make to not export all variables. |
# Otherwise a system limit (for SysV at least) may be exceeded. |
.NOEXPORT: |
/vapi.c
0,0 → 1,656
/* vapi.c -- Verification API Interface |
Copyright (C) 2001, Marko Mlinar, markom@opencores.org |
|
This file is part of OpenRISC 1000 Architectural Simulator. |
|
This program is free software; you can redistribute it and/or modify |
it under the terms of the GNU General Public License as published by |
the Free Software Foundation; either version 2 of the License, or |
(at your option) any later version. |
|
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
|
You should have received a copy of the GNU General Public License |
along with this program; if not, write to the Free Software |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
|
#include "config.h" |
|
#include <stdio.h> |
#include <ctype.h> |
#include <string.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <stdarg.h> |
#include <signal.h> |
#include <errno.h> |
|
/* Added by CZ 24/05/01 */ |
#include <sys/stat.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <sys/select.h> |
#include <sys/poll.h> |
#include <fcntl.h> |
#include <netdb.h> |
#include <netinet/tcp.h> |
|
#include "config.h" |
|
#ifdef HAVE_INTTYPES_H |
#include <inttypes.h> |
#endif |
|
#include "port.h" |
#include "arch.h" |
#include "sim-config.h" |
#include "vapi.h" |
#include "debug.h" |
|
static unsigned int serverIP = 0; |
|
static unsigned int server_fd = 0; |
static unsigned int nhandlers = 0; |
|
static int tcp_level = 0; |
|
static struct vapi_handler { |
int fd; |
unsigned long base_id, num_ids; |
void (*read_func)(unsigned long, unsigned long, void *); |
void *priv_dat; |
struct vapi_handler *next; |
int temp; |
} *vapi_handler = NULL; |
|
/* Structure for polling, it is cached, that it doesn't have to be rebuilt each time */ |
static struct pollfd *fds = NULL; |
static int nfds = 0; |
|
/* Rebuilds the fds structures; see fds. */ |
void rebuild_fds () { |
struct vapi_handler *t; |
if (fds) |
free (fds); |
fds = (struct pollfd *) malloc (sizeof (struct pollfd) * (nhandlers + 1)); |
if (!fds) { |
fprintf (stderr, "FATAL: Out of memory.\n"); |
exit (1); |
} |
|
nfds = 0; |
fds[nfds].fd = server_fd; |
fds[nfds].events = POLLIN; |
fds[nfds++].revents = 0; |
|
for (t = vapi_handler; t; t = t->next) { |
if (t->fd) { |
t->temp = nfds; |
fds[nfds].fd = t->fd; |
fds[nfds].events = POLLIN; |
fds[nfds++].revents = 0; |
} else |
t->temp = -1; |
} |
} |
|
/* Determines whether a certain handler handles an ID */ |
static inline int handler_fits_id( const struct vapi_handler *t, unsigned long id ) { |
return ((id >= t->base_id) && (id < t->base_id + t->num_ids)); |
} |
|
/* Finds a handler with given ID, return it, NULL if not found. */ |
static struct vapi_handler *find_handler (unsigned long id) { |
struct vapi_handler *t = vapi_handler; |
while (t && !handler_fits_id (t, id)) |
t = t->next; |
return t; |
} |
|
/* Adds a handler with given id and returns it. */ |
static struct vapi_handler *add_handler (unsigned long base_id, unsigned long num_ids) { |
struct vapi_handler **t = &vapi_handler; |
struct vapi_handler *tt; |
while ((*t)) |
t = &(*t)->next; |
tt = (struct vapi_handler *)malloc (sizeof (struct vapi_handler)); |
tt->next = NULL; |
tt->base_id = base_id; |
tt->num_ids = num_ids; |
tt->read_func = NULL; |
tt->priv_dat = NULL; |
tt->fd = 0; |
(*t) = tt; |
free (fds); |
fds = NULL; |
nhandlers++; |
rebuild_fds (); |
return tt; |
} |
|
void vapi_write_log_file(VAPI_COMMAND command, unsigned long devid, unsigned long data) |
{ |
if (!runtime.vapi.vapi_file) |
return; |
if (!config.vapi.hide_device_id && devid <= VAPI_MAX_DEVID) |
fprintf (runtime.vapi.vapi_file, "%04lx", devid); |
fprintf (runtime.vapi.vapi_file, "%1x%08lx\n", command, data); |
} |
|
static int vapi_write_stream(int fd, void* buf, int len) |
{ |
int n; |
char* w_buf = (char*)buf; |
struct pollfd block; |
|
while(len) { |
if((n = write(fd, w_buf, len)) < 0) { |
switch(errno) { |
case EWOULDBLOCK: /* or EAGAIN */ |
/* We've been called on a descriptor marked |
for nonblocking I/O. We better simulate |
blocking behavior. */ |
block.fd = fd; |
block.events = POLLOUT; |
block.revents = 0; |
poll(&block,1,-1); |
continue; |
case EINTR: |
continue; |
case EPIPE: |
close(fd); |
fd = 0; |
return -1; |
default: |
return -1; |
} |
} else { |
len -= n; |
w_buf += n; |
} |
} |
return 0; |
} |
|
static int vapi_read_stream(int fd, void* buf, int len) |
{ |
int n; |
char* r_buf = (char*)buf; |
struct pollfd block; |
|
while(len) { |
if((n = read(fd,r_buf,len)) < 0) { |
switch(errno) { |
case EWOULDBLOCK: /* or EAGAIN */ |
/* We've been called on a descriptor marked |
for nonblocking I/O. We better simulate |
blocking behavior. */ |
block.fd = fd; |
block.events = POLLIN; |
block.revents = 0; |
poll(&block,1,-1); |
continue; |
case EINTR: |
continue; |
default: |
return -1; |
} |
} else if(n == 0) { |
close(fd); |
fd = 0; |
return -1; |
} else { |
len -= n; |
r_buf += n; |
} |
} |
return 0; |
} |
|
/* Added by CZ 24/05/01 */ |
int get_server_socket(const char* name,const char* proto,int port) |
{ |
struct servent *service; |
struct protoent *protocol; |
struct sockaddr_in sa; |
struct hostent *hp; |
int sockfd; |
char myname[256]; |
int flags; |
char sTemp[256]; |
|
/* First, get the protocol number of TCP */ |
if(!(protocol = getprotobyname(proto))) { |
sprintf(sTemp,"Unable to load protocol \"%s\"",proto); |
perror(sTemp); |
return 0; |
} |
tcp_level = protocol->p_proto; /* Save for later */ |
|
/* If we weren't passed a non standard port, get the port |
from the services directory. */ |
if(!port) { |
if((service = getservbyname(name,protocol->p_name))) |
port = ntohs(service->s_port); |
} |
|
/* Create the socket using the TCP protocol */ |
if((sockfd = socket(PF_INET,SOCK_STREAM,protocol->p_proto)) < 0) { |
perror("Unable to create socket"); |
return 0; |
} |
|
flags = 1; |
if(setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,(const char*)&flags,sizeof(int)) < 0) { |
sprintf(sTemp,"Can not set SO_REUSEADDR option on socket %d",sockfd); |
perror(sTemp); |
close(sockfd); |
return 0; |
} |
|
/* The server should also be non blocking. Get the current flags. */ |
if(fcntl(sockfd,F_GETFL,&flags) < 0) { |
sprintf(sTemp,"Unable to get flags for socket %d",sockfd); |
perror(sTemp); |
close(sockfd); |
return 0; |
} |
|
/* Set the nonblocking flag */ |
if(fcntl(sockfd,F_SETFL, flags | O_NONBLOCK) < 0) { |
sprintf(sTemp,"Unable to set flags for socket %d to value 0x%08x", |
sockfd,flags | O_NONBLOCK); |
perror(sTemp); |
close(sockfd); |
return 0; |
} |
|
/* Find out what our address is */ |
memset(&sa,0,sizeof(struct sockaddr_in)); |
gethostname(myname,sizeof(myname)); |
if(!(hp = gethostbyname(myname))) { |
perror("Unable to read hostname"); |
close(sockfd); |
return 0; |
} |
|
/* Bind our socket to the appropriate address */ |
sa.sin_family = hp->h_addrtype; |
sa.sin_port = htons(port); |
if(bind(sockfd,(struct sockaddr*)&sa,sizeof(struct sockaddr_in)) < 0) { |
sprintf(sTemp,"Unable to bind socket %d to port %d",sockfd,port); |
perror(sTemp); |
close(sockfd); |
return 0; |
} |
serverIP = sa.sin_addr.s_addr; |
flags = sizeof(struct sockaddr_in); |
if(getsockname(sockfd,(struct sockaddr*)&sa,&flags) < 0) { |
sprintf(sTemp,"Unable to get socket information for socket %d",sockfd); |
perror(sTemp); |
close(sockfd); |
return 0; |
} |
runtime.vapi.server_port = ntohs(sa.sin_port); |
|
/* Set the backlog to 1 connections */ |
if(listen(sockfd,1) < 0) { |
sprintf(sTemp,"Unable to set backlog on socket %d to %d",sockfd,1); |
perror(sTemp); |
close(sockfd); |
return 0; |
} |
|
return sockfd; |
} |
|
static void server_request() |
{ |
struct sockaddr_in sa; |
struct sockaddr* addr = (struct sockaddr*)&sa; |
int n = sizeof(struct sockaddr_in); |
int fd = accept(server_fd, addr, &n); |
int on_off = 0; /* Turn off Nagel's algorithm on the socket */ |
int flags; |
char sTemp[256]; |
|
if(fd < 0) { |
/* This is valid, because a connection could have started, |
and then terminated due to a protocol error or user |
initiation before the accept could take place. */ |
if(errno != EWOULDBLOCK && errno != EAGAIN) { |
perror("accept"); |
close(server_fd); |
server_fd = 0; |
runtime.vapi.enabled = 0; |
serverIP = 0; |
} |
return; |
} |
|
if(fcntl(fd,F_GETFL,&flags) < 0) { |
sprintf(sTemp,"Unable to get flags for vapi socket %d",fd); |
perror(sTemp); |
close(fd); |
return; |
} |
|
if(fcntl(fd,F_SETFL, flags | O_NONBLOCK) < 0) { |
sprintf(sTemp,"Unable to set flags for vapi socket %d to value 0x%08x", |
fd,flags | O_NONBLOCK); |
perror(sTemp); |
close(fd); |
return; |
} |
|
if(setsockopt(fd,tcp_level,TCP_NODELAY,&on_off,sizeof(int)) < 0) { |
sprintf(sTemp,"Unable to disable Nagel's algorithm for socket %d.\nsetsockopt",fd); |
perror(sTemp); |
close(fd); |
return; |
} |
|
/* Install new handler */ |
{ |
unsigned long id; |
struct vapi_handler *t; |
if (vapi_read_stream (fd, &id, sizeof (id))) { |
perror ("Cannot get id"); |
close (fd); |
return; |
} |
t = find_handler (id); |
if (t) { |
if (t->fd) { |
fprintf (stderr, "WARNING: Test with id %lx already connected. Ignoring.\n", id); |
close (fd); |
return; |
} else { |
t->fd = fd; |
rebuild_fds (); |
} |
} else { |
fprintf (stderr, "WARNING: Test with id %lx not registered. Ignoring.\n", id); |
close(fd); /* kill the connection */ |
return; |
} |
if(config.sim.verbose) |
PRINTF ("\nConnection with test (id %lx) established.\n", id); |
} |
} |
|
static int write_packet (unsigned long id, unsigned long data) { |
struct vapi_handler *t = find_handler (id); |
if (!t || !t->fd) |
return 1; |
id = htonl (id); |
if (vapi_write_stream(t->fd, &id, sizeof (id)) < 0) |
return 1; |
data = htonl (data); |
if (vapi_write_stream(t->fd, &data, sizeof (data)) < 0) |
return 1; |
return 0; |
} |
|
static int read_packet (int fd, unsigned long *id, unsigned long *data) |
{ |
if (fd <= 0) |
return 1; |
if (vapi_read_stream(fd, id, sizeof(unsigned long)) < 0) |
return 1; |
*id = ntohl (*id); |
if (vapi_read_stream(fd, data, sizeof(unsigned long)) < 0) |
return 1; |
*data = ntohl (*data); |
return 0; |
} |
|
static void vapi_request (struct vapi_handler *t) |
{ |
unsigned long id, data; |
|
if (read_packet(t->fd, &id, &data)) { |
if (t->fd > 0) { |
perror("vapi read"); |
close(t->fd); |
t->fd = 0; |
rebuild_fds (); |
} |
return; |
} |
|
vapi_write_log_file (VAPI_COMMAND_REQUEST, id, data); |
debug (4, "[%08lx, %08lx]\n", id, data); |
|
/* This packet may be for another handler */ |
if (!handler_fits_id (t, id)) |
t = find_handler (id); |
if (!t || !t->read_func) |
fprintf (stderr, "WARNING: Received packet for undefined id %08lx, data %08lx\n", id, data); |
else |
t->read_func(id, data, t->priv_dat); |
} |
|
void vapi_check () |
{ |
struct vapi_handler *t; |
|
if (!server_fd || !fds) { |
fprintf (stderr, "FATAL: Unable to maintain VAPI server.\n"); |
exit (1); |
} |
|
debug(5, "."); |
|
/* Handle everything in queue. */ |
while(1) { |
switch(poll(fds, nfds, 0)) { |
case -1: |
if(errno == EINTR) |
continue; |
perror("poll"); |
if (server_fd) |
close(server_fd); |
runtime.vapi.enabled = 0; |
serverIP = 0; |
return; |
case 0: /* Nothing interesting going on */ |
return; |
default: |
/* Handle the vapi ports first. */ |
for (t = vapi_handler; t; t = t->next) |
if (t->temp >= 0 && fds[t->temp].revents) |
vapi_request (t); |
|
if(fds[0].revents) { |
if(fds[0].revents & POLLIN) |
server_request(); |
else { /* Error Occurred */ |
fprintf(stderr,"Received flags 0x%08x on server. Shutting down.\n", fds[0].revents); |
if (server_fd) |
close(server_fd); |
server_fd = 0; |
runtime.vapi.enabled = 0; |
serverIP = 0; |
} |
} |
break; |
} /* End of switch statement */ |
} /* End of while statement */ |
} |
|
/* Inits the VAPI, according to sim-config */ |
int vapi_init () |
{ |
nhandlers = 0; |
vapi_handler = NULL; |
if (!runtime.vapi.enabled) |
return 0; /* Nothing to do */ |
|
runtime.vapi.server_port = config.vapi.server_port; |
if (!runtime.vapi.server_port) { |
fprintf (stderr, "WARNING: server_port = 0, shutting down VAPI\n"); |
runtime.vapi.enabled = 0; |
return 1; |
} |
if ((server_fd = get_server_socket("or1ksim", "tcp", runtime.vapi.server_port))) |
PRINTF("VAPI Server started on port %d\n", runtime.vapi.server_port); |
else { |
perror ("Connection"); |
return 1; |
} |
|
rebuild_fds (); |
|
if ((runtime.vapi.vapi_file = fopen (config.vapi.vapi_fn, "wt+")) == NULL) |
fprintf (stderr, "WARNING: cannot open VAPI log file\n"); |
|
return 0; |
} |
|
/* Closes the VAPI */ |
void vapi_done () |
{ |
int i; |
struct vapi_handler *t = vapi_handler; |
|
for (i = 0; i < nfds; i++) |
if (fds[i].fd) |
close (fds[i].fd); |
server_fd = 0; |
runtime.vapi.enabled = 0; |
serverIP = 0; |
free (fds); |
fds = 0; |
if (runtime.vapi.vapi_file) { |
/* Mark end of simulation */ |
vapi_write_log_file (VAPI_COMMAND_END, 0, 0); |
fclose (runtime.vapi.vapi_file); |
} |
|
while (vapi_handler) { |
t = vapi_handler; |
vapi_handler = vapi_handler->next; |
free (t); |
} |
} |
|
/* Installs a vapi handler for one VAPI id */ |
void vapi_install_handler (unsigned long id, void (*read_func) (unsigned long, unsigned long, void *), void *dat) |
{ |
vapi_install_multi_handler (id, 1, read_func, dat); |
} |
|
/* Installs a vapi handler for many VAPI id */ |
void vapi_install_multi_handler (unsigned long base_id, unsigned long num_ids, void (*read_func) (unsigned long, unsigned long, void *), void *dat) |
{ |
struct vapi_handler *tt; |
|
debug(4, "vapi_install_handler %08lx, %lu, %08p\n", base_id, num_ids, read_func); |
if (read_func == NULL) { |
struct vapi_handler **t = &vapi_handler; |
while ((*t) && !handler_fits_id (*t, base_id)) |
t = &(*t)->next; |
if (!t) { |
fprintf (stderr, "Cannot uninstall VAPI read handler from id %lx\n", |
base_id); |
exit (1); |
} |
tt = *t; |
(*t) = (*t)->next; |
free (tt); |
nhandlers--; |
} else { |
tt = find_handler (base_id); |
if (!tt) { |
tt = add_handler (base_id, num_ids); |
tt->read_func = read_func; |
tt->priv_dat = dat; |
} else { |
tt->read_func = read_func; |
tt->priv_dat = dat; |
rebuild_fds (); |
} |
} |
} |
|
/* Returns number of unconnected handles. */ |
int vapi_num_unconnected (int printout) |
{ |
struct vapi_handler *t = vapi_handler; |
int numu = 0; |
for (; t; t = t->next) { |
if (!t->fd) { |
numu++; |
if (printout) { |
if ( t->num_ids == 1 ) |
PRINTF (" 0x%lx", t->base_id); |
else |
PRINTF (" 0x%lx..0x%lx", t->base_id, t->base_id + t->num_ids - 1); |
} |
} |
} |
return numu; |
} |
|
/* Sends a packet to specified test */ |
int vapi_send (unsigned long id, unsigned long data) |
{ |
debug (4, "vapi_send [%08lx %08lx]\n", id, data); |
vapi_write_log_file (VAPI_COMMAND_SEND, id, data); |
write_packet (id, data); |
} |
|
/* |
int main () |
{ |
runtime.vapi.enabled = 1; |
config.vapi.server_port = 9999; |
vapi_init (); |
while (1) { |
vapi_check(); |
usleep(1); |
} |
vapi_done (); |
}*/ |
|
/*---------------------------------------------------[ VAPI configuration ]---*/ |
void vapi_enabled(union param_val val, void *dat) |
{ |
config.vapi.enabled = val.int_val; |
} |
|
void vapi_server_port(union param_val val, void *dat) |
{ |
config.vapi.server_port = val.int_val; |
} |
|
void vapi_log_enabled(union param_val val, void *dat) |
{ |
config.vapi.log_enabled = val.int_val; |
} |
|
void vapi_hide_device_id(union param_val val, void *dat) |
{ |
config.vapi.hide_device_id = val.int_val; |
} |
|
void vapi_log_fn(union param_val val, void *dat) |
{ |
strcpy(config.vapi.vapi_fn, val.str_val); |
} |
|
void reg_vapi_sec(void) |
{ |
struct config_section *sec = reg_config_sec("VAPI", NULL, NULL); |
|
reg_config_param(sec, "enabled", paramt_int, vapi_enabled); |
reg_config_param(sec, "server_port", paramt_int, vapi_server_port); |
reg_config_param(sec, "log_enabled", paramt_int, vapi_log_enabled); |
reg_config_param(sec, "hide_device_id", paramt_int, vapi_hide_device_id); |
reg_config_param(sec, "vapi_log_fn", paramt_str, vapi_log_fn); |
} |
vapi.c
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: vapi.h
===================================================================
--- vapi.h (nonexistent)
+++ vapi.h (revision 1765)
@@ -0,0 +1,59 @@
+/* vapi.h - Verification API Interface
+ Copyright (C) 2001, Marko Mlinar, markom@opencores.org
+
+This file is part of OpenRISC 1000 Architectural Simulator.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#ifndef _VAPI_H_
+#define _VAPI_H_
+
+/* Maximum value for VAPI device id */
+#define VAPI_MAX_DEVID 0xFFFF
+
+/* Inits the VAPI, according to sim-config */
+int vapi_init ();
+
+/* Closes the VAPI */
+void vapi_done ();
+
+/* Installs a vapi handler for one VAPI id */
+void vapi_install_handler (unsigned long id, void (*read_func) (unsigned long, unsigned long, void *), void *dat);
+
+/* Installs a vapi handler for multiple VAPI id */
+void vapi_install_multi_handler (unsigned long base_id, unsigned long num_ids, void (*read_func) (unsigned long, unsigned long, void *), void *dat);
+
+/* Checks for incoming packets */
+void vapi_check ();
+
+/* Returns number of unconnected handles. */
+int vapi_num_unconnected (int printout);
+
+/* Sends a packet to specified test */
+int vapi_send (unsigned long id, unsigned long data);
+
+#define VAPI_DEVICE_ID (0xff)
+
+/* Types of commands that can be written to the VAPI log file */
+typedef enum {
+ VAPI_COMMAND_REQUEST = 0, /* Data coming from outside world to device */
+ VAPI_COMMAND_SEND = 1, /* Device writing data to the outside world */
+ VAPI_COMMAND_END = 2 /* End of log for device */
+} VAPI_COMMAND;
+
+/* Writes a line directly to the log file (used by JTAG proxy) */
+void vapi_write_log_file(VAPI_COMMAND command, unsigned long device_id, unsigned long data);
+
+#endif /* _VAPI_H_ */
vapi.h
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: Makefile.am
===================================================================
--- Makefile.am (nonexistent)
+++ Makefile.am (revision 1765)
@@ -0,0 +1,22 @@
+# Makefile -- Makefile for peripherals simulation
+# Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
+#
+# This file is part of OpenRISC 1000 Architectural Simulator.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+
+noinst_LIBRARIES = libvapi.a
+libvapi_a_SOURCES = vapi.c vapi.h
Makefile.am
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: .
===================================================================
--- . (nonexistent)
+++ . (revision 1765)
.
Property changes :
Added: svn:ignore
## -0,0 +1,2 ##
+Makefile
+.deps