Closed KGrykiel closed 1 year ago
I don't think this will work, as currently, get_imm
resolves labels, so you won't be able to tell the difference between j main
and j 0x100
, one of which gives you the address of (not offset to) the label main
, and the other one gives you 0x100
as a constant...
ohh, right, back to the drawing board then
Maybe we should rethink what an immediate value really is, maybe we should add a new datatype Immediate
that can do the following:
as_offset_from(<some address>) : T_RelativeAddress
, resolves the contained value and returns it as an offset to <some address>
as_absolute_val(): T_AbsoluteAddress
, returns the absolute valueWe have three different kinds of things we need to take care of here:
Integer immediate | Symbolic label | Numeric label 1b /1f |
|
---|---|---|---|
as_offset_from(x) |
value |
resolve(value) - x |
resolve(value, x) - x |
as_absolute_val |
value |
resolve(value) |
impossible :boom: |
See https://docs.oracle.com/cd/E19120-01/open.solaris/817-5477/esqaq/index.html for more info on numeric labels. They are a real PITA.
Or maybe I'm just overthinking this, and we have add get_abs_imm
and get_rel_imm
? Idk tho.
we definetely need some sort of distinction between a label and an immediate that can be detected by the emulator. I'll have a go at those suggestions and see what seems most convenient. Do you reckon there's gonna be a lot of elements in the project directly affected by it as well?
FWIW I like Immediate
a lot and I'm not a big fan of get_rel_imm
, but I guess it's a matter of style, I think both should work. One other option that might be easier to implement is get_imm() -> tuple[int, ImmediateKind]
where the kind is an enum of string and int.
I am pretty sure that this is everything necessary to make it work as the riscv spec expetcs. It was tested by running some of the example programs with "j 0/ jal 0" added to prove that now those instructions should be effectively ommitted.