Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Approach for exposing HTIF options to other tools #25

Merged
merged 4 commits into from
Dec 2, 2017

Conversation

seldridge
Copy link
Contributor

@seldridge seldridge commented Mar 20, 2017

This provides one strategy for exposing what options are supported by the host to other tools. This uses getopt_long for all argument parsing and exposes the data structures necessary for the parsing in htif_t.h.

As it's necessary to still provide backwards support for spike and elf2hex, two additional legacy constructors are provided for htif_t:

  • A no-argument constructor (for elf2hex)
  • A constructor taking std::vector<std::string> (for spike)

Summarily:

  • Add htif_t constructor that uses (int argc, char** argv) instead of (const std::vector<std::string>)
  • Use getopt_long for option parsing and add equivalent -- long options to all existing + options
  • Expose supported htif_t options to external programs via macros in htif_t.h (see Add option checks for HTIF chipsalliance/rocket-chip#597)
  • Trying to use the +disk option will throw a std::invalid_argument exception (as I'm still not aware of this being supported)
  • Add check on options that should be skipped -- currently limited to VCS' -cm XXX+YYY
  • Fix incorrect set_chroot error message

Fixes #24.

Due to the use of the legacy std::vector<std::string> this should, theoretically, not break anything. However, it may... I was unaware until trying to build riscv-torture that elf2hex wants to pass empty options into the htif_t constructor.

This is intended to be backed up by chipsalliance/rocket-chip#597.

This fixes the `syscall_t::set_chroot` method so that it will write
out the location that it failed to chroot to, `where,` as opposed to
the unset attribtue `chroot`.
This changes the `htif_t` constructor to use getopt for option parsing
adding support for POSIX-like `--` long options while preserving
support for "legacy" `+` args. The options supported by `htif_t` are
exposed to programs importing the `htif.h` header.

This results in a change of the `htif_t` and `dtm_t` constructor APIs
so that it can directly process command line arguments. Previously
the `htif_t` constructor was:
  htif_t::htif_t(const std::vector<std::string>& target_args)
Now it is:
  htif_t::htif_t(int argc, char** argv)

As `htif_t` is a secondary consumer of command line arguments (e.g.,
it is constructed after the rocket-chip emulator), the options
supported by `htif_t` are exposed via three new macros in `htif_t.h`:
  * HTIF_USAGE_OPTIONS -- usage string suitable to be appended to any
    program that will pass arguments to `htif_t`
  * HTIF_LONG_OPTIONS_OPTIND -- Base val for `htif_t` options
  * HTIF_LONG_OPTIONS -- `struct option` fragment for `htif_t`. All
    options index starting from `HTIF_LONG_OPTIONS_OPTIND`.

Support for the currently unsupported option `+disk` now raises an
exception.

Space is provided for non-standard options which may be exposed to
`htif_t`. Currently only the VCS options of the form `-cm XXX` are
ignored.
Does some minor cleanup of usage formatting.

Adds a htif_t() constructor that does not do argument parsing. This is
needed for something like `elf2hex` which wants to pass no arguments
to htif_t.

Note: `elf2hex` is currently non-working on master and not as a result
of this.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@gmail.com>
This retains the legacy htif_t constructor using a vector of string to
pass command line arguments.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@gmail.com>
@seldridge seldridge changed the title Issue 24 Approach for exposing HTIF options to other tools Nov 19, 2017
@aswaterman aswaterman self-requested a review November 21, 2017 05:32
@aswaterman
Copy link
Contributor

Is there a getopt_long that isn’t GPL? I thought it was infectious, but maybe I’m misremembering.

@seldridge
Copy link
Contributor Author

Yes, there's a BSD implementation
(https://github.com/freebsd/freebsd/blob/master/include/getopt.h).

Also, getopt/getopt_long are libc (which in my understanding is LGPL and avoids any problems here). Equivalently, I think this is the same territory as include <stdio.h>.

I defer to an expert here, as this isn't something that you want to get wrong...

Some earlier discussion of this here: chipsalliance/rocket-chip#484 (comment)

@aswaterman
Copy link
Contributor

Indeed, my memory is faulty. @palmer-dabbelt any objections?

@palmer-dabbelt
Copy link
Contributor

It looks like it's a GNU extension, but that's not a GPL thing -- we're in the same license territory as linking against anything else in libc. I'm OK with it.

@neelgala
Copy link

Hi,
There are zero argument commands in spike as well: spike --dump-dts. (A binary should not be needed to generate dts). However, htif fails on this and I believe this particular commit/pull-request is responsible for this.

should I be filing a new issue or would you prefer opening this again?

@seldridge
Copy link
Contributor Author

seldridge commented Apr 24, 2018

@neelgala: thanks, you are right about this. Spike should be able to handle a one-argument option. I think the fix is a lot simpler initially, however... spike creates a sim_t object before it knows if it's going to exit (https://github.com/riscv/riscv-isa-sim/blob/9d1e10a36e771bf8cfbf515e07e856e021c1007a/spike_main/spike.cc#L157).

For the time being, the binary doesn't appear to have to actually exist:

spike --dump-dts foo

This is a new issue on spike. I expect I can get a PR together that will fix this and a second that aligns spike's option parsing with fesvr.

Edit: Ignore my comment about moving the sim_t object. Totally wrong. I looked at this too quickly.

@seldridge
Copy link
Contributor Author

Digging into this more... the existing (though undocumented) way to specify a "no-binary htif" is by passing "none" as the program (see: https://github.com/riscv/riscv-fesvr/blob/master/fesvr/htif.cc#L79). This code path is never hit by spike --dump-dts none, but this appears to be the (ancient) kludge that's in there now. If this is the way that we want to go, then this "none" escape should be reflected in the option parsing.

This probably warrants a broader discussion related to whether or not htif should be mandating a program to load. @aswaterman: what do you think?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants