Issues in Migration of RISCV Test Harness from VCS to Questasim Simulator - simulation

I have been trying to simulate the RISCV rocket core but to no luck, I do not have a Synopsys VCS simulator and so the rocketTestHarness.v file cannot be used as is. The rocketTestHarness.v includes a vcs_main.cc file that has extern functions that use DirectC interface handles like vc_handle and vc_getScalar vc_putScalar vc_put4stVector vc_4stVectorRef. These do not work with non VCS simulators like Questasim (the one that I have been using). Is there any way which I can use to migrate the rocketTestHarness.v file from a VCS simulator to Questasim Simulator. Or is there any other way by which I can simulate the rocket core using Questasim.
I looked at this but I'am not sure how all that works. Is it not possible to simulate the rocketchip without using the riscv_fesrvr and simulate as it would work in a natural environment. I'am willing to use DPI calls if those functions in vcs_main.cc can be translated to DPI call logic.
I would really appreciate if someone could provide some assistance on this.
Thanks in advance!!

Rocket Chip is designed to run in a tethered fashion (with HTIF and FESVR). This is not a requirement for RISC-V, but a artifact of how Rocket Chip is used in prototypes for research. Work is currently underway to define a platform specification to set a standard for boot-up and such for those that want to run standalone.
As a short-term method to get started, we do recommend using the C++ emulation provided by Chisel. Porting to Questasim will involve modifying the harness. In addition to interfacing with memory, HTIF will need to be connected to FESVR. When you get this done, if you submit a clean pull request we can integrate it for others.

Related

Developing an Operating System using TDD/BDD

I just wonder. Is there anybody in the world, using TDD or BDD to write an OS? And is this even posible? I've tried to google it, but didn't find any kind of information.
So, guys. Is it possible to build an entire OS using TDD? And BDD?
It is possible to use TDD for most of OS development and for most of the code. It may get tricky at certain times/places due to limited testability of low-level, especially CPU/hardware-specific, code. These parts either may receive less direct test coverage (if that's OK) or can be tested in virtual machines or CPU/PC simulators.
It is definitely possible. I don't know anyone who is doing it.
As a proof point, I would point out what people are doing with test driven infrastructure with Chef and unit and behavioral testing there. For more info, see TestKitchen for Chef.

porting java code to contiki-os

i am using contiki-os to simulate some motes which would have semantic capabilities. As the contiki-os (erbium) is written in C but our semantic libraries are written in java.
can anyone here guide me if it is possible to exploit these libraries in erbium or contiki-os. or i have to rewrite everything from scratch ?
update
just a minor update to the question. is it possible to use java code on the cooja simulator?
Cooja is indeed written in Java.
You can extend or modify Cooja if you need.
You can find out more about Cooja on the Contiki wiki as well as in numerous papres by Fredrik Österlind. Perhaps you should also take a look at Fredrik's PhD thesis "Improving Low-Power Wireless Protocols with Timing-Accurate Simulation", which is mostly about Cooja.
You might be able to use something like this:
http://www.codemesh.com/products/junction/
It appears to have a code generator that takes a java bytecode and create C code from it... but it might also need a runtime library that's platform specific.
With all that in mind, I don't think you will be successful. Most of the platforms are nearly out of space and/or flash by the time you are working with Erbuim; I doubt you'll have resources to process java code somehow.
And if you did get some success from this approach it would probably take a lot of time and effort to do so. With that time and effort you probably could have written the C code to do what you need instead.

How to code sharing between Android and iOS

I'm moving away from strict Android development and wanting to create iPhone applications. My understanding is that I can code the backend of iOS applications in C/C++ and also that I can use the NDK to include C/C++ code in Android apps. My question however is how? I've googled quite a bit and I can't find any clear and concise answers.
When looking at sample code for the NDK, it seems that all the function names etc. are Android (or at least Java) specific and so I would not be able to use this C/C++ backend to develop an iPhone frontend?
I'd appreciate some clarification on this issue and if at all available some code to help me out? (even just a simple Hello World that reads a string from a C/C++ file and displays it in an iOS and Android app).
Thanks guys
Chris
Note that I almost exclusively work on "business/utility/productivity" applications; things that rely heavily on fairly standard UI elements and expect to integrate well with their platform. This answer reflects that. See Mitch Lindgren's comment to Shaggy Frog's answer for good comments for game developers, who have a completely different situation.
I believe #Shaggy Frog is incorrect here. If you have effective, tested code in C++, there is no reason not to share it between Android and iPhone, and I've worked on projects that do just that and it can be very successful. There are dangers that should be avoided, however.
Most critically, be careful of "lowest common denominator." Self-contained, algorithmic code, shares very well. Complex frameworks that manage threads, talk on the network, or otherwise interact with the OS are more challenging to do in a way that doesn't force you to break the paradigms of the platform and shoot for the LCD that works equally badly on all platforms. In particular, I recommend writing your networking code using the platform's frameworks. This often requires a "sandwich" approach where the top layer is platform-specific and the very bottom layer is platform-specific, and the middle is portable. This is a very good thing if designed carefully.
Thread management and timers should also be done using the platform's frameworks. In particular, Java uses threads heavily, while iOS typically relies on its runloop to avoid threads. When iOS does use threads, GCD is strongly preferred. Again, the solution here is to isolate the truly portable algorithms, and let platform-specific code manage how it gets called.
If you have a complex, existing framework that is heavily threaded and has a lot of network or UI code spread throughout it, then sharing it may be difficult, but my recommendation still would be to look for ways to refactor it rather than rewrite it.
As an iOS and Mac developer who works extensively with cross-platform code shared on Linux, Windows and Android, I can say that Android is by far the most annoying of the platforms to share with (Windows used to hold this distinction, but Android blew it away). Android has had the most cases where it is not wise to share code. But there are still many opportunities for code reuse and they should be pursued.
While the sentiment is sound (you are following the policy of Don't Repeat Yourself), it's only pragmatic if what you can share that code in an efficient manner. In this case, it's not really possible to have a "write once" approach to cross-platform development where the code for two platforms needs to be written in different languages (C/C++/Obj-C on iPhone, Java for Android).
You'll be better off writing two different codebases in this case (in two different languages). Word of advice: don't write your Java code like it's C++, or your C++ code like it's Java. I worked at a company a number of years ago who had a product they "ported" from Java to C++, and they didn't write the C++ code like it was C++, and it caused all sorts of problems, not to mention being hard to read.
Writing a shared code base is really practical in this situation. There is some overhead to setting up and keeping it organized, but the major benefits are these 1) reduce the amount of code by sharing common functionality 2) Sharing bug fixes to the common code base. I'm currently aware of two routes that I'm considering for a project - use the native c/c++ (gains in speed at the expense of losing garbage collection and setting targets per processor) or use monodroid/monotouch which provide c# bindings for each os's platform functionality (I'm uncertain of how mature this is.)
If I was writing a game using 3d I'd definitely use approach #1.
I posted this same answer to a similar question but I think it's relevant so...
I use BatteryTech for my platform-abstraction stuff and my project structure looks like this:
On my PC:
gamename - contains just the common code
gamename-android - holds mostly BatteryTech's android-specific code and Android config, builders point to gamename project for common code
gamename-win32 - Just for building out to Windows, uses code from gamename project
On my Mac:
gamename - contains just the common code
gamename-ios - The iPhone/iPad build, imports common code
gamename-osx - The OSX native build. imports common code.
And I use SVN to share between my PC and Mac. My only real problems are when I add classes to the common codebase in Windows and then update on the mac to pull them down from SVN. XCode doesn't have a way to automatically add them to the project without scripts, so I have to pull them in manually each time, which is a pain but isn't the end of the world.
All of this stuff comes with BatteryTech so it's easy to figure out once you get it.
Besides using C/C++ share so lib.
If to develop cross-platform apps like game, suggest use mono-based framework like Unity3D.
Else if to develop business apps which require native UI and want to share business logic code cross mobile platforms, I suggest use Lua embedded engine as client business logic center.
The client UI is still native and get best UI performance. i.e Java on Android and ObjectC on iOS etc.
The logic is shared with same Lua scripts for all platform.
So the Lua layer is similar as client services (compare to server side services).
-- Anderson Mao, 2013-03-28
Though I don't use these myself as most of the stuff I write won't port well, I would recommend using something like Appcelerator or Red Foundry to build basic applications that can then be created natively on either platform. In these cases, you're not writing objective-c or java, you use some kind of intermediary. Note that if you move outside the box they've confined you to, you'll need to write your own code closer to the metal.

How do you port a chess AI to iPhone

I would like to port a chess AI to iPhone, but I can't figure out how to do it. Apparently iPhone doesn't support multi threading so you can't just seperately compile the AI, but have to somehow merge it into the code.
I have a GPL copy of a implementation of the sjeng engine, but I can't figure out how they did it because it's written in c and c++ and all I know is apple objc.
Does anyone have any recommendations on how to do this? I need to make a wrapper of some kind for what is a standalone program.
file with code which I will leave up for as long as I can.
I have successfully ported a chess engine to iPhone. It's not difficult for the porting. Most of the popular chess engines adopt Universal Chess Interface Protocol or Chess Engine Communication Protocol. Read Wikipedia for more details on each protocol.
Now, say you take one of the open sources UCI chess engine and it compiles on C or C++. XCode supports C and C++ natively, so all you will need to do is copy the sources to XCode and they will compile.
The next phase would be connecting the engine to your interface. Again, this is not difficult. You will need to send protocol commands to the engine, the engine would give you back the results on standard output. You would need to pipe results using UNIX's pipe(). Read my other thread
Fork() on iPhone for more details.
Example:
Assume engine_loop is the game loop for your engine (all engines must have a loop).
engine_loop(int fd[])
{
dup2(fd[1], STANDARD_OUTPUT);
while(true)
{
printf("e4\n"); // This is dumb, we always make the same move, but you get the idea
}
}
my_objective_c_function()
{
int fd[2];
pipe(fd);
engine_loop(fd);
char buffer[1024];
read(fd[0], buffer, 1024);
// buffer == "e4"
// Send "e4" to the interface
}
The code fragment shows you how to send results from an engine to your interface. Now, you will need to do the other way around. This is very similar to the code above. In a real scenario, once your connection is established, you will need to send UCI commands, I will give you an example:
ucinew
isready
go infinite
stop
Please read the UCI chess engine protocol documentation carefully. You will need it.
Your question is actually more complicated than it needs to be, because I think the basic problem you have is unrelated to compiling specifically for the iPhone.
If you say you already have some chess AI code, then somewhere in there is a call to an evaluation function that takes a game state (board position and player to move) and will give back a move. That's what you need to drill down and find, because that essentially is the "engine" that will drive your app, regardless of what platform you're compiling for.
Now, my guess is that this chess AI assumes that move search is run in its own thread, likely a design decision to make it easy to "interrupt" the search at any time and have it play its own move. You can certainly run code in separate threads on the iPhone, so the problem for you is to figure out how to tease out that code from to free it from whatever existing platform dependencies it has.
It may help you to first approach this problem as if you were writing a command-line utility, in C, to run on Mac OS X. That will free you from a lot of dependencies and simplify the situation for you. My guess is once you've done that, you'll immediately have a good idea of how to make it work within a (Cocoa) iPhone environment.
Objective C is a superset of C, so if the library is written in C, you can just compile it with the rest of your Objective-C code without any wrappers.
iPhone OS does support multithreading; see NSThread class. You won't get any extra performance from it, though - the iPhone CPU is single-core and there's almost no multitasking.
And yes, from the Objective C code you can easily call into C and C++ code, and vice versa. For C++ interaction, rename your sources to .mm; then they're compiled as Objective C++.
I have ample experience porting C++ code to iPhone. Works like a charm.

Any good library or software for queue networks simulation?

I have been trying to make work EZSIM with no luck, which is a software to build discrete event simulators in a graphical DOS environment. In this software, my simulator and many others (of the other people in the course I'm taking) don't work, but teacher's simulator (and examples of the downloaded files) does work.
So, I began to distrust of the software.
Do you know any software that resolves the same kind of problems but really works? It will be good if it is free, or I can download an evaluation copy or something like that.
If you don't know any software, do you know any library which might work? Preferably in C#, Ansi C, Java or Delphi.
This may be more than what you're looking for, but check out NS2. It's the standard for open source network simulations, and will allow you to simulate all kinds of network layer behavior.
I've also used JUNG in the past. It's very flexible, although it also doesn't offer much out of the box.
I used Möbius in my computer systems analysis class. It is free for educational use (which sounds like what you're doing). It's a Java GUI which generates C++ code.
The R package queuecomputer. queuecomputer is a computationally efficient method for simulating queues with arbitrary arrival and service times. There is a submitted paper on arXiv describing the algorithm used in the package. Examples can be found within the arXiv paper and the vignette. A web app based on the package is available at https://ace-ebert.shinyapps.io/queue_simulator_mmk/ .