commit d24e1e0fdebe0607f2533ee88002a07ef1556f20 Author: Maxim Levitsky Date: Sat Sep 3 05:05:19 2011 +0300 Add demmio_replay. This tool allows to replay demmio traces. diff --git a/rnn/CMakeLists.txt b/rnn/CMakeLists.txt index 948c114..84dfc42 100644 --- a/rnn/CMakeLists.txt +++ b/rnn/CMakeLists.txt @@ -2,22 +2,25 @@ project(ENVYTOOLS C) cmake_minimum_required(VERSION 2.6) find_package(LibXml2 REQUIRED) +pkg_check_modules(PC_PCIACCESS pciaccess REQUIRED) include_directories(${LIBXML2_INCLUDE_DIR} ../include) add_library(rnn rnn.c rnndec.c) add_executable(demmio demmio.c) +add_executable(demmio_replay demmio_replay.c display.c) add_executable(headergen headergen.c) add_executable(dedma dedma.c dedma_cache.c dedma_back.c) add_executable(lookup lookup.c) target_link_libraries(demmio envy rnn ${LIBXML2_LIBRARIES}) +target_link_libraries(demmio_replay envy rnn nva ${LIBXML2_LIBRARIES} ${PC_PCIACCESS_LIBRARIES}) target_link_libraries(headergen rnn ${LIBXML2_LIBRARIES}) target_link_libraries(dedma rnn ${LIBXML2_LIBRARIES}) target_link_libraries(lookup rnn ${LIBXML2_LIBRARIES}) -install(TARGETS demmio headergen rnn dedma lookup +install(TARGETS demmio demmio_replay headergen rnn dedma lookup RUNTIME DESTINATION bin LIBRARY DESTINATION lib${LIB_SUFFIX} ARCHIVE DESTINATION lib${LIB_SUFFIX}) diff --git a/rnn/demmio_replay.c b/rnn/demmio_replay.c new file mode 100644 index 0000000..3d17a57 --- /dev/null +++ b/rnn/demmio_replay.c @@ -0,0 +1,134 @@ +#include "nva.h" +#include +#include +#include +#include +#include +#include "display.h" +#include "rnn.h" +#include "rnndec.h" + +struct rnndeccontext *vc; +struct rnndb *db; +struct rnndeccontext *vc; +struct rnndomain *dom; + + +bool init_rnn() +{ + rnn_init(); + db = rnn_newdb(); + + if (!db) + return false; + + rnn_parsefile (db, "nv_mmio.xml"); + rnn_prepdb (db); + + vc = rnndec_newcontext(db); + + if (!vc) + return false; + + rnndec_varadd(vc, "chipset", "NV86"); + + dom = rnn_finddomain (db, "NV_MMIO"); + + if (!dom) + return false; + + + return true; +} + + +int main(int argc, char **argv) { + int a = 0xCCCCCCCC, b = 0xCCCCCCCC; + char buf[1024]; + int arg = 1; + + bool ask = false, read = false; + + assert(!nva_init()); + + while (arg < argc) { + if (!strcmp(argv[arg] , "--ask")) { + ask = true; + } else + if (!strcmp(argv[arg] , "--read")) + read = true; + else + break; + arg++; + } + + FILE *f = arg == argc ? stdin : fopen(argv[arg], "r"); + if (!f) { + perror("fopen"); + return 0; + } + + if (!init_rnn()) + return 1; + + screen_init(); + + + while (1) { + if (!fgets(buf, sizeof(buf), f)) + break; + + if (buf[0] == '#' || buf[0] == '\n') + continue; + if (!strncmp(buf, "wait", 4)) { + printf("waiting\n"); + sleep(1); + continue; + } + + if (sscanf(buf, "[0] %*d.%*d MMIO32 W 0x%x 0x%x %*[^\n]\n", &a, &b) == 2 || + sscanf(buf, "MMIO32 W 0x%x 0x%x %*[^\n]\n", &a, &b) == 2 || + sscanf(buf, "[0] MMIO32 W 0x%x 0x%x %*[^\n]\n", &a, &b) == 2 || + sscanf(buf, "write: 0x%x = 0x%x", &a, &b) == 2) { + + struct rnndecaddrinfo *info = rnndec_decodeaddr(vc, dom, a, 0); + char *decoded_val =rnndec_decodeval(vc, info->typeinfo, b, info->width); + + if (read || ask) { + printf("0x%08x %s <= 0x%08x %s current: 0x%08x ", a, info->name, b, decoded_val, nva_rd32(0, a)); + + + if (ask) { + printf("N/Y? "); + fflush(stdout); + + if (get_user_input(0) != 'y') { + printf("\n"); + continue; + } + } + + nva_wr32(0, a, b); + + printf("result: 0x%08x)\n", nva_rd32(0, a)); + continue; + } else { + nva_wr32(0, a, b); + continue; + } + } + + //replay reads as well, as to replicate their side effects + if (sscanf(buf, "[0] %*d.%*d MMIO32 R 0x%x 0x%x %*[^\n]\n", &a, &b) == 2 || + sscanf(buf, "MMIO32 R 0x%x 0x%x %*[^\n]\n", &a, &b) == 2) + { + nva_rd32(0, a); + continue; + } + + printf("WARNING: mailformed input: %s\n", buf); + } + + screen_fini(); + return 0; +} diff --git a/rnn/display.c b/rnn/display.c new file mode 100644 index 0000000..edd8c01 --- /dev/null +++ b/rnn/display.c @@ -0,0 +1,87 @@ +/* + * + * Copyright (C) 2009 - Maxim Levitsky + * + * this 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 dumppage; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ +#include +#include +#include +#include +#include +#include + +/* Minimal terminal manipulation, Linux specific library */ + +void screen_init() +{ + /* And some users use ncurses for that!... */ + struct termios term_ops; + tcgetattr(STDIN_FILENO, &term_ops); + term_ops.c_iflag |= IGNCR; + term_ops.c_lflag &= ~(ECHO | ICANON); + tcsetattr(STDIN_FILENO, TCSANOW, &term_ops); +} + + +void screen_fini() +{ + struct termios term_ops; + tcgetattr(STDIN_FILENO, &term_ops); + term_ops.c_iflag &= ~IGNCR; + term_ops.c_lflag |= (ECHO | ICANON); + tcsetattr(STDIN_FILENO, TCSANOW, &term_ops); +} + +void screen_clear() +{ + printf("\e[2J"); +} + +void screen_set_00_pos() +{ + printf( "\e[0;0H"); +} + +void screen_set_inverse_mode(bool set) +{ + if (set) + printf("\e[7m"); + else + printf("\e[0m"); +} + + +unsigned char get_user_input(int timeout) +{ + fd_set readset; + FD_ZERO(&readset); + FD_SET(STDIN_FILENO, &readset); + + struct timeval tv_timeout; + tv_timeout.tv_sec = 0; + tv_timeout.tv_usec = 1000 * timeout; + + if (select(1, &readset, NULL, NULL, timeout ? &tv_timeout : NULL) <= 0) + return -1; + + char input_ch; + + if (read(STDIN_FILENO, &input_ch, 1) == 0) + return -1; + + return input_ch; +} diff --git a/rnn/display.h b/rnn/display.h new file mode 100644 index 0000000..c53678e --- /dev/null +++ b/rnn/display.h @@ -0,0 +1,36 @@ + /* + * Copyright (C) 2011 maxim + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ + +/* Minimal terminal manipulation, Linux specific library */ + + +#ifndef SCREEN_H_ + +void screen_init(); +void screen_fini(); +void screen_clear(); +void screen_set_00_pos(); +void screen_set_inverse_mode(bool set); +unsigned char get_user_input(int timeout); + + +#define SCREEN_H_ + + +#endif /* SCREEN_H_ */