Skip to content

Commit 5764544

Browse files
bschommerxavierleroy
authored andcommitted
RISC-V Pbtbl pseudoinstruction: use x6 as temporary
The register `x5` can be used as an alternate link register for function calls, and thus we want to avoid using it for regular jumps. (This could confuse disassemblers and binary code analysis.)
1 parent 77ef757 commit 5764544

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎riscV/Asm.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ Definition exec_instr (f: function) (i: instruction) (rs: regset) (m: mem) : out
966966
| Vint n =>
967967
match list_nth_z tbl (Int.unsigned n) with
968968
| None => Stuck
969-
| Some lbl => goto_label f lbl (rs#X5 <- Vundef #X31 <- Vundef) m
969+
| Some lbl => goto_label f lbl (rs#X6 <- Vundef #X31 <- Vundef) m
970970
end
971971
| _ => Stuck
972972
end

‎riscV/Asmgenproof.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ Local Transparent destroyed_by_op.
881881
exploit functions_transl; eauto. intro FN.
882882
generalize (transf_function_no_overflow _ _ H5); intro NOOV.
883883
exploit find_label_goto_label. eauto. eauto.
884-
instantiate (2 := rs0#X5 <- Vundef #X31 <- Vundef).
884+
instantiate (2 := rs0#X6 <- Vundef #X31 <- Vundef).
885885
Simpl. eauto.
886886
eauto.
887887
intros [tc' [rs' [A [B C]]]].

‎riscV/Machregs.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Definition destroyed_by_store (chunk: memory_chunk) (addr: addressing): list mre
174174

175175
Definition destroyed_by_cond (cond: condition): list mreg := nil.
176176

177-
Definition destroyed_by_jumptable: list mreg := R5 :: nil.
177+
Definition destroyed_by_jumptable: list mreg := R6 :: nil.
178178

179179
Fixpoint destroyed_by_clobber (cl: list string): list mreg :=
180180
match cl with

‎riscV/TargetPrinter.ml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,12 @@ module Target : TARGET =
526526
fprintf oc "%s jumptable [ " comment;
527527
List.iter (fun l -> fprintf oc "%a " print_label l) tbl;
528528
fprintf oc "]\n";
529-
fprintf oc " sll x5, %a, 2\n" ireg r;
529+
fprintf oc " sll x6, %a, 2\n" ireg r;
530530
fprintf oc " lla x31, %a\n" label lbl;
531-
fprintf oc " add x5, x31, x5\n";
532-
fprintf oc " lw x5, 0(x5)\n";
533-
fprintf oc " add x5, x31, x5\n";
534-
fprintf oc " jr x5\n";
531+
fprintf oc " add x6, x31, x6\n";
532+
fprintf oc " lw x6, 0(x6)\n";
533+
fprintf oc " add x6, x31, x6\n";
534+
fprintf oc " jr x6\n";
535535
jumptables := (lbl, tbl) :: !jumptables;
536536
fprintf oc "%s end pseudoinstr btbl\n" comment
537537
| Pnop ->

0 commit comments

Comments
 (0)