Icarus verilog dump memory array ($dumpvars) - arrays

I try to dump an array (reg [31:0] data [31:0]) but I can't do it successfully.
I've tried the way that is in the iverilog wiki:
integer idx;
for (idx = 0; idx < 32; idx = idx + 1)
$dumpvars(0,cpu_tb.cpu0.cpu_dp.cpu_regs.data[idx]);
It works, but 2 things happen.
A warning shows up: VCD warning: array word cpu_tb.cpu0.cpu_dp.cpu_regs.data[0] will conflict with an escaped identifier.
In GTKWave I have something like this in SST window: \data[0][31:0]
Is there any solution about that?
Thanks in advance and sorry for my English.

I have e-mailed the mailing list of Icarus Verilog. Here are some answers:
To dump an array word Icarus needs to escape the name so it is
compatible with the VCD dump format. That's what \data[0][31:0] is. It
is the zeroth 32-bit word of the data array. Because an escaped name
and an array name could now conflict Icarus produces the warning. It
would be best if it could check for an escaped identifier conflict and
only print a message when there is a problem, but as I remember this
was not possible.
We chose to use escaped identifiers so that all the dumpers could
handle array words. The other common choice is to only support them
using a special dump command that only works with certain dump
formats.
I agree it would be nice if we could make the warning more accurate,
but we are usually busy working on other things so minor annoyances
that appear to be complicated to fix do not often get fixed. As I
remember, and it has been a number of years, the issue is if you
search for the escaped identifier it find the array element and there
is no way in the VPI to search for the next occurrence. It's possible
that finding the array element in the Icarus search by name
implementation is a bug.
Cary
"To dump an array word Icarus needs to escape the name so it is
compatible with the VCD dump format. That's what \data[0][31:0] is.
It is the zeroth? 32-bit word of the data array. Because an escaped
name and an array name could now conflict Icarus produces the
warning. It would be best if it could check for an escaped identifier
conflict and only print a message when there is a problem, but as I
remember this was not possible."
...I don't think that there's a need to escape the names. Both VCS
(followed by fsdb2vcd) and CVC emit the name directly with no
problems. Cut and paste example shown below:
$var wire 5 `' IC_DrAd0 [3][4:0] $end $var wire 5 a' IC_DrAd0 [2][4:0]
$end $var wire 5 b' IC_DrAd0 [1][4:0] $end $var wire 5 c' IC_DrAd0
[0][4:0] $end
I realize the VCD spec doesn't define this, but I've had to fold in a
lot of these kinds of extensions into gtkwave over the years as other
tools generate these constructs. The escapes can cause save file
incompatibilities (missing signals) when trying to simulate on
iverilog versus VCS.
Over time, SV constructs likely will cause further things added to the
VCD files. AFAIK, the VCD part of the 1364 spec hasn't updated at all
since Verilog-XL. CVC gets around possible incompatibilities by
adding a +dump_arrays plusarg (and no, you don't have to loop on each
array element either).
-Tony
I also sent a mail to GTKWave creator Tony Bybell:
Hello,
The problem is that the compiler is not emitting those values into the
dump file. You'll have to get in contact with the iverilog
developers. I see the same problem if I run sim and compare against
another simulator such as CVC with +dump_arrays turned on which does
dump the arrays and they are visible in gtkwave.
http://iverilog.wikia.com/wiki/Release_Notes_Icarus_Verilog_0_9_2 |
Allow $dumpvars to accept array members for dumping,
...it looks like during "initial" time you might need to add a
$dumpvars statement for each array element you want dumped. I don't
know if the array name by itself works. Assigning each element to a
"wire" might work too.
I have never tried this functionality in iverilog so I don't know if
it works. You might have to experiment or ask the developers.
-Tony

I had a similar issue recently:
When dumping vars with the for cycle like the question, this vcd error happens:
ERROR: $dumpvars cannot dump a vpiConstant.
My workaround is to generate n wires with assign statement assigning it the respective array word like this:
reg [31:0] registers [31:0];
generate
genvar idx;
for(idx = 0; idx < 32; idx = idx+1) begin: register
wire [31:0] tmp;
assign tmp = registers[idx];
end
endgenerate
Now in GTKWave I have the generate blocks dumped correctly.

Related

Support for compiling ASN1 file to C with CONTAINING keyword

I'm using ESNACC for compiling multiple ASN source files to C code. For ease of understanding, I will explain the scenario here as succintly as possible:-
FileA.asn1 contains the following:-
FileA DEFINITIONS ::=
BEGIN
A ::= SEQUENCE
{
AContent [0] OCTET STRING (CONTAINING FileB.B)
}
END
FileB.asn1 contains the following:-
FileB DEFINITIONS ::=
BEGIN
B ::= SEQUENCE
{
BElem1 [0] INTEGER,
BElem2 [1] INTEGER
}
END
I used ESNACC to compile both files in one command. Upon analysing the C source files generated, I observed that the AContent field will be decoded as a constructed OCTET STRING (the data being received in the application guarantees that the field will be specified as constructed) with its contents being filled into a simple string. This means that FileB does not come into the picture at all. I was hoping that AContent would be further decoded with a structure of FileB being filled, so that I can easily access the elements within. This does not seem to be the case.
I'm fairly new with ASN1, so please let me know if my understanding is wrong in any way.
Is ESNACC not capable of generating code for supporting CONTAINING keyword properly?
Are there other compilers that are able to do this?
Can this be done by using ESNACC in any way?
If this cannot be done using ESNACC, and I don't want to use any other compiler, how would I access the contents within AContent at runtime easily?
I am not sure of the capabilities of ESNACC, but there are many other compilers that support the CONTAINING keyword. An excellent list of compilers can be found at https://www.itu.int/en/ITU-T/asn1/Pages/Tools.aspx which is part of the ITU-T ASN.1 Project.
Heimdal's ASN.1 compiler (lib/asn1/) has support for the funky Information Object System syntax extensions that allow you to declare things like what all goes into Certificate Extensions (for example), and the generated code will decode everything recursively in one go.

Read file and find index of value in array in Fortran

I am making user subroutine file of Abaqus.
However, in reading a file I met with a difficulty.
Since, it is Fortran 77 based, it is so hard to find exact solution.
My intention is to read a file where an 1X1 array is include. Then, to find an index of a value in the array.
My code to read a file is :
open (unit=99,file='D:\SIMULATION\dist.txt',status='old')
read (99,*) dist
close (99)
And the code for finding index of value in array is:
loc=minloc(abs(dist-1),1)
I think minloc is for Fortran 90, right?
Is there any function in Fortran 77 similar to minloc?
The code you've shown should compile and run as expected. I'm assuming that you are actually reading a 1xN array and that when you said "1X1" it was a typo - otherwise, there's no point in using minloc.
However, the error message you reported in a comment (An array-valued argument is required in this context) only occurs if you use the minloc intrinsic on a scalar value. Thus, my guess is that you did not declare dist as an array. Here is a quick example of what I mean:
! The contents of 'values.txt' are: -3.1, 4.1, 5.9, 2.6, -5.4
! Values may be separated by commas or blanks.
program get_min_dist
implicit none
real :: x ! <-- Cannot be used to represent an array.
real, dimension(5) :: a ! <-- An array of 5 reals. Do this instead.
integer :: loc, funit1
open(newunit=funit1, file="values.txt", status="old")
read(funit1,*) x
rewind(funit1)
read(funit1,*) a
close(funit1)
loc = minloc(abs(a-1),1) ! <-- I'm assuming there is a reason to
! subtract 1 from all values in the array
! loc = minloc(abs(x-1),1) ! <-- Error 'An array-valued arg is required`
print*, "x=",x
print*, "a=",a
print*, "index=", loc
print*, "value=", a(loc)
end program get_min_dist
With read(funit1,*) x the first value will be assigned when the file is read, resulting in the error message you have seen. With the array a, however, you get the expected output.
Your confusion regarding the need to use F77 compatible code may be due to the fact that Abaqus continues to provide examples and docs with F77-style fixed-formatting, and requires Fortran source code to be given the .f or .for extension1. By default, this extension tells ifort to expect fixed-format code2. However, any Fortran features supported by the version of the compiler you use is still valid - even in fixed-format, if you must. For further information about the availability of features from different Fortran versions, see your (Intel Fortran) documentation.
1 I'd be glad to know if this can be changed somehow, e.g. to allow the .f90 extension.
2 This setting can be changed in the Abaqus environment file, at least for the versions I've used (6.9-6.14). I don't think that has changed with newer releases, but maybe. I don't recommend changing it if you share the environment with other users without their consent, especially for newbies.

GSSAPI: gss_export_name returns a blank

I am having a problem with exporting a name using gss_export_name, I though that once the name is exported I should be able to just print it but I am turning up a blank Literaly
EXPORTED NAME: , EXPORTED NAME LENGTH: 47
Here is my code
OM_uint32 major_status;
gss_cred_usage_t usage;
OM_uint32 lifetime;
gss_name_t inquired_name;
major_status = gss_inquire_cred(&minor_status, GSS_C_NO_CREDENTIAL, &inquired_name,
&lifetime, &usage, &oid_set);
gss_buffer_desc exported_name_buffer;
major_status = gss_export_name(&minor_status, inquired_name, &exported_name_buffer);
printf("EXPORTED NAME: %s, EXPORTED NAME LENGTH: %d\n",
exported_name_buffer.value, exported_name_buffer.length);
for clarity I decided not to include checks, but I also take care to make sure that major_status is always == GSS_S_COMPLETE
Appreciate any ideas
Unfortunately the buffer output by gss_export_name is an ASN.1 data structure not a human-readable string. Se section 3.2 of RFC 2743. You'd need to skip over the header of that structure and then parse the name in a mechanism-dependent manner.
Some of the GSS-API developers strongly recommend doing this. As an example, the gss-api patches to Openssh do this for parsing Kerberos names. This is the theoretically correct approach. In practice though, using gss_display_name and handling the output of that call produces more portable results in practice, even though it may produce strange results in a multi-mechanism application. You'll get significant arguments over how to handle this in the GSS-API community. Everyone will agree that you should use gss_display_name for producing output for debugging and logs. The question is what should you do if you want a name for searching on an access control list. If you can directly use the output of gss_export_name and do binary comparisons, do that. However if you need to compare against input entered by a human, I'd argue that using the output of gss_display_name is better, while others will argue that parsing the gss_export_name output is better.

Retrieving Global Variable Values from Command Line

In one particular project, we're trying to embed version information into shared object files. We'd like to be able to use some standard linux tool to parse the shared object to determine the version for automated testing.
Currently I have "const int plugin_version = 14;". I can use 'nm' and 'objdump' and verify that it's there:
00000000000dcfbc r plugin_version
I can't, however, seem to be able to get the value of that variable easily from command line. I figured there'd be a POSIX tool for showing the initialized values for globals. I have contemplated using a format for the variable as the information itself, ie, plugin_version_14, but that seems like a huge hack. Embedding the information in the filename unfortunately is NOT an option. Any other suggestions welcome.
You could embed it as a string
"MAGIC MARKER STRING VERSION: 4.56 END OF MAGIC" then just look for "MAGIC MARKER STRING" in the file and extract the version information that comes after it.
if you make it a standard, you could easily make command line tool to find these embeded strings on all your software.
if you require it also to be an int, a little macro magic will construct both the int and magic string to make sure they are never out of synch.
There's a couple of options I think.
My first instinct is to make sure the version information lives in its own section in the ELF file. You can use objdump -s -j name of section /bin/whatever.
This rather relies on objdump being available of course.
Alternatively you can do what Keith suggested, and just use 'strings', along with a magical marker string. This feels a little hackish, but should work quite well.
Finally, why don't you just add a --version command line option? You can then store the version information however you like, and trivially retrieve it using the one tool which is certain to be installed on any system which has your software.
A terrible hack that I've used in the past is to embed the version information in a variable name, so nm will show:
00000000000dcfbc r plugin_version_14
Why not writing your own tool to get that version in C/C++ ? You could Use dlopen, then dlsym to get the symbol and print its value to standard output. This way you also verify if the symbol is already there. It looks like 20 ~ 30 lines of code to me and about 20 minutes of your life :)
I know that the question is about command line, but writing such a tool yourself should be easy (especially if such a command line tool does not exist).
If the binary is not stripped, you could use gdb to print the variable. (I just tried to script gdb, but it seems to refuse work if stdin is not a tty, maybe expect will do the job ? )
If you can accept using python, this might help:
import struct
import sys
import subprocess
if __name__ == '__main__':
so = sys.argv[1]
sym = sys.argv[2]
addr = subprocess.check_output('nm %s | grep %s' % (so, sym), shell=True)
addr = int(addr.split()[0], 16)
so_file = open(so)
so_file.seek(addr)
data = so_file.read(4)
print struct.unpack('#i', data)[0]
Disclaimer: This script doesn't do any error checking (if you like it I'm sure you can come up with some ;)). It also assumes you're reading a 4-byte native int value.
$ cat global.c
const int plugin_version = 14;
$ python readsym.py global.so plugin_version
14

Which numerical values do the F-Keys ( F[1-12]) and the Arrow-keys have?

I'd like to write an application in C which uses arrow-keys to navigate and F-keys for other functions, such as saving to a file, language selection, etc.
Propably the values depend on the platform, so how could I find out which values the keys have?
If they don't, or if you know them, I don't have to know how to find out;)
Edit:
My platforms are Linux and M$ Windows.
Therefore, I'm looking for a solution as portable as possible.
(Propably something like
#ifdef __unix__
#define F1 'some number'
/* ... */
#define ARROW_UP 'some other number'
#elif __WIN32__ || MSDOS /*whatever*/
#define F1 'something'
/* ... */
#define ARROW_UP 'something different'
#endif
)
I think that depends on $TERM, but either way it's going to be a sequence of characters. I get this:
% read x; echo $x | od -c --
^[[15~
0000000 033 [ 1 5 ~ \n
0000006
That's my F5 key, and apologies for this being a *nix-centric answer, if that's not your platform.
This problem is a lot messier than anyone would like. In brief, each of these keys sends a sequence of characters, and the details depend on which terminal emulator is being used. On Unix, you have a couple of choices:
Write your app to use the curses library and use its interface to the terminfo database.
Parse the the terminfo database yourself to find the sequences. Or to use an API, look at the sources for tput to see how this is done.
Use the command-line program tput to help discover the sequences. For example, to learn the sequence for F10, run tput kf10 | od -a. Keep in mind this changes from terminal to terminal, so you should run tput each time you run your app.
Write your application using one of the X libraries and get access to 'key symbols' rather than a sequence of characters. the XLookupKeysym function is a good place to get started; you'll find names of the symbols in /usr/include/X11/keysymdef.h. If you are going to connect over the network from non-X systems (e.g., Windows) this option is not so good.
I have no idea how to do any of this on Windows.
If you're on a Unix or Linux machine, simply enter cntl-V and then the key while in vim*. You'll see the code.
HTH
cheers,
Rob
This handy site has lots of useful nuggets of info on the raw scancodes:
http://www.win.tue.nl/~aeb/linux/kbd/scancodes.html#toc1
Some of the keys generate 2 character key codes.
One technique I have successfully used on the pc, is to get the 2 characters, and set the 7th bit on the second character, and return that character as the answer. It lets the rest of the program treat each keystroke as a single character.
The solution to your problem with depend on what keys you need to support. Hiding the translation behind a function of some sort, is generally a good idea.

Resources