Open Teknomancer opened 4 years ago
Figure out if byteorder
must be deduced from arch
(when specified).
Is there a case we want to format something in big endian on the x86? For devices, arch
doesn't make sense anyway? Maybe it does for highly CPU-specific devices like the APIC. Not sure.
Rust apparently had some RFC for a BitSet (bit_set module) which is declared unstable and made as an external crate. May or may not be part of the core language/std anytime soon.
So I've renamed BitSet in sysprocalc to SysBitSet. It's annoying but what to do. I know 'namespaces' exists, but I'd rather not confuse the term if BitSet becomes part of the Rust language in the future.
Found a better name. Use "BitGroup". It's must nicer than "SysBitSet" and there doesn't appear to be conflicting Rust crates or in std.
Hmm. Is chunks
really a good idea? What if an id is used in the description bits vector? i.e. all bit descriptions that belong to a chunk will have the same id.
Got rid of chunks
.
funty should be used rather than num_traits.
Also should I bother going the whole distance with bitvec?
I honestly don't care at the moment about big-endian but extending it in the future can be a pain. Maybe if bitvec is easy enough, then use it now.
Update: As of c089df196a9c52b0ed3051fd51614e2fba768b0c updated to using bitvec and funty.
I'm considering if using external files is such a good idea or not. At least initially we probably want to have some stuff built-in.
The convenience of having a single binary outweighs the need for adding new registers without recompiling since I'm likely to be the sole user of this app anyway.
Due to this, I've decided to put all the existing registers as static data in the binary itself. 3573721abf07a24bcb26141e87d9346e8db330c1 works towards that end. However, vectors in BitGroup struct are a blocker right now because it's contains a vector of BitSpan structs. In Rust are always heap allocated and can't be static (BSS) data. Need to see if I can convert these to array (slices ?) and still in the future be able to construct them at run-time if needed...
I want to keep the register descriptions outside the code but I want the TOML parsed structs embedded in the binary (at compile time) i.e. for built-in data / registers, I want to:
With regard to the above goals - Here might be a good way of doing it. toml
, lazy_static
are required. The include_str
built-in Rust macro comes in handy.
Data file placed in root of the crate: data/efer.toml
# EFER
arch = "x86"
device = "cpu"
name = "EFER"
In Rust code:
lazy_static! {
let efer_toml = include_str!("data/efer.toml");
static CPU_X86_EFER: BitGroup::<u64> = toml::from_str(efer_toml).unwrap();
}
I'm not yet sure if this will work but worth trying. Also I don't think it would be possible to determine the size of the register (64, 32-bit) prior to opening the file...
Edit: Don't use lazy_static
. Consider using OnceCell
instead because there's a chance it gets included in Rust's standard library itself rfcs/pull/2788 and rust/issues/74465
Explore if it's possible to change Register::arch
, Register::device
into enums while being able to load them from TOML.
RFE for a register descriptor (a more generic x86-register formatter).
Proposal:
Sample register descriptor TOMLs:
File format specification
arch
x86
,arm
orn/a
.device
cpu
is special as registers undercpu
do not require a fully qualified name (e.g, no need to type "cpu.efer 0xd01"). If conflicting names are encountered for different CPUs e.g., "x86.cpu.efer" and "arm.cpu.efer" exists, the command will be rejected and the user would be asked to supply the fully qualified name.name
description
byteorder
little-endian
orbig-endian
.bitcount
bitspans
bitspans
field specification:first
last
attr
name
short
long
attr
field specification:rw
ro
wo
rw1c
ros
rw1cs
rsvdp
rsvdz
mbz
mb1
ign
und