Page MenuHomeFreeBSD

Shave off two instructions in save_registers_head
ClosedPublic

Authored by dg612_cam.ac.uk on Mar 22 2022, 11:18 AM.
Tags
None
Referenced Files
F103026065: D34631.id104078.diff
Tue, Nov 19, 11:47 PM
F103018222: D34631.id118127.diff
Tue, Nov 19, 9:32 PM
F103017636: D34631.id104178.diff
Tue, Nov 19, 9:21 PM
Unknown Object (File)
Oct 2 2024, 12:25 PM
Unknown Object (File)
Oct 2 2024, 10:22 AM
Unknown Object (File)
Oct 1 2024, 7:15 AM
Unknown Object (File)
Sep 17 2024, 5:54 PM
Unknown Object (File)
Sep 16 2024, 3:34 PM

Details

Summary

This patch shaves off up to two three instructions in save_registers_head in exception.S for arm64, which would make more space for instructions that could be added in CheriBSD. This is done by

  1. Combining pointer arithmetic with pre-incrementing STP instructions,
  2. Removing the instruction that sets the frame pointer (x29) as its content is unused after 05985a7f805f7ac4844c1a246a3822250d411655.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/arm64/arm64/exception.S
61

Was there a reason to switch the order of these stores?

68–70

If you move the store of sp & lr first you only need to use one store with write back.

dg612_cam.ac.uk added inline comments.
sys/arm64/arm64/exception.S
61

The reason is purely stylistic. Because we need to store x0 and x1 first, it's more natural to then start storing x2, x3, etc.

68–70

Storing sp requires first moving sp into some register, so we have to do it after all registers have already been saved.

sys/arm64/arm64/exception.S
68–70

I mean sp from when the exception was taken. It is already copied to x18.

sys/arm64/arm64/exception.S
68–70

But that only happens when \el == 1, if I understood you correctly?

sys/arm64/arm64/exception.S
68–70

For EL0 sp is loaded from the sp_el0 special register.

sys/arm64/arm64/exception.S
68–70

Yes, but if we put mrs x18, sp_el0 before all the stps, then we would clobber the value of x18 that's being saved?

I suppose another (perhaps better) way is to put -TF_SIZE + before all the st[p|r]s, except for the last one saving x18 and lr, where we use a store with write-back.

sys/arm64/arm64/exception.S
68–70

First in this group of 3 store instructions:

stp x18, lr, [sp, #(TF_SP - TF_X)]!
str x10, [sp, #(TF_ELR)]
stp w11, w12, [sp, #(TF_SPSR)]
dg612_cam.ac.uk added inline comments.
sys/arm64/arm64/exception.S
68–70

Oh I completely misunderstood your comment. Yes, it makes total sense to do this. Please see the updated patch.

There was a bug in R10:05985a7f805f for non-DDB users of the unwind code. I have a fix for it in D34711, however it may mean we obly save one instruction in save_registers_head as we will need to keep the update to x29 and bring back another stp to create an AAPCS frame.

There was a bug in R10:05985a7f805f for non-DDB users of the unwind code. I have a fix for it in D34711, however it may mean we obly save one instruction in save_registers_head as we will need to keep the update to x29 and bring back another stp to create an AAPCS frame.

That's fine. In fact, saving one instruction is enough to allow me to fit all the CheriBSD-specific instruction into save_registers_head.

Would you be happy to merge this soon?

Can you share a git commit with this change?

This revision is now accepted and ready to land.Feb 24 2023, 10:49 AM
This revision was automatically updated to reflect the committed changes.