Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arch arm cortex m vector table rework #24012

Conversation

ioannisg
Copy link
Member

@ioannisg ioannisg commented Apr 2, 2020

Ready for review.
This PR does the following changes

  • removes z_arm_reserved function pointer from the Cortex-M vector table entries that correspond to exceptions reserved for future use by the ARM specification. This should be a "no-op" as these addresses are not read/written/fetched by the code. The entries are set to 0x0.
  • renames z_arm_reserved to z_arm_exc_spurious and use the function pointer for vector entries that correspond to existing but not used exception
  • adds a test to verify the behavior of z_arm_exc_spurious

@ioannisg ioannisg requested a review from stephanosio April 2, 2020 10:52
@ioannisg ioannisg force-pushed the arch_arm_cortex_m_vector_table_rework branch 2 times, most recently from 8e1d73f to 6bd0b08 Compare April 2, 2020 10:57
@zephyrbot zephyrbot added the area: ARM ARM (32-bit) Architecture label Apr 2, 2020
@galak
Copy link
Collaborator

galak commented Apr 2, 2020

I wonder if we are going to make a change like this, if we should also move it out of asm code like arc has. Look at arch/arc/core/vector_table.c. I don't see any particular need for this to be asm and changing it to .c might make it be one less thing to deal with for other compilers in the future.

Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is z_arm_reserved used anymore after this change?

Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think setting the reserved vectors to 0 is okay; after all, we do not care about the reserved stuff and that is how reserved things are often handled (and expected to be, in case of #23972).

arch/arm/core/aarch32/cortex_m/vector_table.S Outdated Show resolved Hide resolved
arch/arm/core/aarch32/cortex_m/vector_table.S Outdated Show resolved Hide resolved
@ioannisg
Copy link
Member Author

ioannisg commented Apr 2, 2020

Is z_arm_reserved used anymore after this change?

Yes, it is used to trigger a CPU fault, see fault.S
This is needed in some cases. For example, if someone pends the SysTick IRQ without having it wired.

@ioannisg
Copy link
Member Author

ioannisg commented Apr 2, 2020

I wonder if we are going to make a change like this, if we should also move it out of asm code like arc has. Look at arch/arc/core/vector_table.c. I don't see any particular need for this to be asm and changing it to .c might make it be one less thing to deal with for other compilers in the future.

No objections to that, but I would prefer to do this once for all cortex- variants together, maybe a task for @stephanosio (?) :)

@stephanosio
Copy link
Member

stephanosio commented Apr 2, 2020

I wonder if we are going to make a change like this, if we should also move it out of asm code like arc has. Look at arch/arc/core/vector_table.c. I don't see any particular need for this to be asm and changing it to .c might make it be one less thing to deal with for other compilers in the future.

No objections to that, but I would prefer to do this once for all cortex- variants together, maybe a task for @stephanosio (?) :)

I believe that would be feasible for Cortex-M, though not for the rest (i.e. Cortex-A and Cortex-R).

There is one major difference between the vector tables for Cortex-M and the rest -- that the former consists of the pointers to the handlers, whereas the latter (usually) consists of the jump instructions to the handlers.

Moreover, in AArch64, the space allocated for each vector has increased so that you can actually put small handler implementations in the vector table itself.

@ioannisg ioannisg force-pushed the arch_arm_cortex_m_vector_table_rework branch 2 times, most recently from 541a889 to 27988ce Compare April 2, 2020 14:54
@ioannisg
Copy link
Member Author

ioannisg commented Apr 2, 2020

I believe that would be feasible for Cortex-M, though not for the rest (i.e. Cortex-A and Cortex-R).

In this case I am less eager to do this for Cortex-M now - I am not 100% happy with having the cortex-m in .c while cortex-r, a in .S format...

@MaureenHelm
Copy link
Member

I didn't go down this path before because it's a more intrusive change, but if you're ok with it then so am I. :)

I agree with @stephanosio that z_arm_reserved no longer makes sense. I think it should be renamed in this PR.

@ioannisg ioannisg force-pushed the arch_arm_cortex_m_vector_table_rework branch from 27988ce to fcf600e Compare April 3, 2020 08:20
Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me.

z_arm_reserved can be completely removed for Cortex-R too since it is currently not used by anything and the future Cortex-A support will use z_arm_exc_spurious as well for the hypervisor vector.

@ioannisg
Copy link
Member Author

ioannisg commented Apr 3, 2020

Looks ok to me.

z_arm_reserved can be completely removed for Cortex-R too since it is currently not used by anything and the future Cortex-A support will use z_arm_exc_spurious as well for the hypervisor vector.

Would you mind doing this in your clean up work for cortex-r?

@stephanosio
Copy link
Member

Looks ok to me.
z_arm_reserved can be completely removed for Cortex-R too since it is currently not used by anything and the future Cortex-A support will use z_arm_exc_spurious as well for the hypervisor vector.

Would you mind doing this in your clean up work for cortex-r?

Sure, that would work too.

@ioannisg ioannisg force-pushed the arch_arm_cortex_m_vector_table_rework branch from fcf600e to 49f28ca Compare April 3, 2020 11:57
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Apr 3, 2020
@zephyrbot
Copy link
Collaborator

zephyrbot commented Apr 3, 2020

All checks are passing now.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@ioannisg ioannisg force-pushed the arch_arm_cortex_m_vector_table_rework branch from 49f28ca to 697342f Compare April 3, 2020 12:03
@ioannisg ioannisg marked this pull request as ready for review April 3, 2020 12:06
@ioannisg ioannisg requested a review from MaureenHelm as a code owner April 3, 2020 12:06
@ioannisg ioannisg requested a review from stephanosio April 3, 2020 12:06
@ioannisg
Copy link
Member Author

ioannisg commented Apr 3, 2020

I didn't go down this path before because it's a more intrusive change, but if you're ok with it then so am I. :)

I agree with @stephanosio that z_arm_reserved no longer makes sense. I think it should be renamed in this PR.

@MaureenHelm so, i think this is a good cleanup and will solve the issue with the LPC image boot. I also did the rename of z_arm_reserved in this PR.

@ioannisg ioannisg added the Enhancement Changes/Updates/Additions to existing features label Apr 3, 2020
@ioannisg ioannisg self-assigned this Apr 3, 2020
Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me overall.

Just a minor comment about the #ifs; though, this is really not that important since I am splitting Cortex-M and Cortex-A/-R asm exception handling code into separate files in the upcoming PR.

arch/arm/core/aarch32/fault_s.S Outdated Show resolved Hide resolved
arch/arm/core/aarch32/fault_s.S Outdated Show resolved Hide resolved
@ioannisg ioannisg force-pushed the arch_arm_cortex_m_vector_table_rework branch from 697342f to e630b4a Compare April 3, 2020 13:32
@ioannisg ioannisg requested a review from stephanosio April 3, 2020 13:33
Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo in the test comment, but otherwise this looks great. Thanks @ioannisg

tests/arch/arm/arm_interrupt/src/arm_interrupt.c Outdated Show resolved Hide resolved
@ioannisg
Copy link
Member Author

ioannisg commented Apr 3, 2020

Minor typo in the test comment, but otherwise this looks great. Thanks @ioannisg

I'll fix the typo, thanks for catching. Have you tested that it works for the LPC SoC, @MaureenHelm ?

@MaureenHelm
Copy link
Member

Have you tested that it works for the LPC SoC, @MaureenHelm ?

yes

@ioannisg
Copy link
Member Author

ioannisg commented Apr 6, 2020

Is z_arm_reserved used anymore after this change?

Yes, it is used to trigger a CPU fault, see fault.S
This is needed in some cases. For example, if someone pends the SysTick IRQ without having it wired.

@galak this is now even unit-tested :)

ioannisg added 5 commits April 6, 2020 15:31
Write 0x0 instead of z_arm_reserved to vector exception
entries that are always reserved for future use by the
ARM architecture. These vector table entries cannot be
fetched to be executed by the Cortex-M exception entry,
so having z_arm_reserved gives a false impression, since
it is a function that may be invoked in the code. This
modification is safe since these vector entries are also
not supposed to be read / written by the code.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
If the Cortex-M core does not implement the SysTick peripheral,
we should not be adding z_arm_reserved in the corresponding
vector table entry. If we do have SysTick implemented but we
are not using it as the system timer, we shall install the
reserved interrupt at the vector table entry.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
If the Cortex-M core does not implement the Security Extension,
we should not be adding z_arm_reserved in the corresponding
vector table entry. That is because the entry is reserved by
the ARM architecture.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
In the Cortex-M exception table we rename z_arm_reserved()
function to z_arm_exc_spurious(), as it is invoked when
existing (that is, non-reserved) but un-installed exceptions
are triggered, accidentaly, by software, or hardware. This
currently applies to SysTick and SecureFault exceptions.

Since fault.S is shared between Cortex-M and other AARCH32
architectures, we keep z_arm_reserved as a defined symbol
there. This commit does some additional, minor, "no-op"
cleanup in #ifdef's for Cortex-M and Cortex-R.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
We add a simple test case to verify the behavior
of z_arm_exc_spurious handler. We use the SysTick
interrupt for that so the test is enabled for
platforms that have but do not use the SysTick.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
@ioannisg ioannisg force-pushed the arch_arm_cortex_m_vector_table_rework branch from d714131 to daa6348 Compare April 6, 2020 13:31
@MaureenHelm
Copy link
Member

@galak are you ok with this?

@galak galak merged commit 56a0942 into zephyrproject-rtos:master Apr 7, 2020
b0661 added a commit to b0661/zephyr that referenced this pull request Apr 14, 2020
The selection of the Cortex M systick driver to be used as a system
clock driver is controlled by CONFIG_CORTEX_M_SYSTICK.

To replace it by another driver CONFIG_CORTEX_M_SYSTICK must be set
to 'n'. Unfortunately this also controls the interrupt vector for
the systick interrupt. It is now routed to z_arm_exc_spurious.

Remove the dependecy on CONFIG_CORTEX_M_SYSTICK and route to
z_clock_isr as it was before zephyrproject-rtos#24012.

Fixes zephyrproject-rtos#24347

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
ioannisg pushed a commit that referenced this pull request Apr 15, 2020
The selection of the Cortex M systick driver to be used as a system
clock driver is controlled by CONFIG_CORTEX_M_SYSTICK.

To replace it by another driver CONFIG_CORTEX_M_SYSTICK must be set
to 'n'. Unfortunately this also controls the interrupt vector for
the systick interrupt. It is now routed to z_arm_exc_spurious.

Remove the dependecy on CONFIG_CORTEX_M_SYSTICK and route to
z_clock_isr as it was before #24012.

Fixes #24347

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
avisconti pushed a commit to avisconti/zephyr that referenced this pull request Apr 15, 2020
The selection of the Cortex M systick driver to be used as a system
clock driver is controlled by CONFIG_CORTEX_M_SYSTICK.

To replace it by another driver CONFIG_CORTEX_M_SYSTICK must be set
to 'n'. Unfortunately this also controls the interrupt vector for
the systick interrupt. It is now routed to z_arm_exc_spurious.

Remove the dependecy on CONFIG_CORTEX_M_SYSTICK and route to
z_clock_isr as it was before zephyrproject-rtos#24012.

Fixes zephyrproject-rtos#24347

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
hakehuang pushed a commit to hakehuang/zephyr that referenced this pull request Jun 20, 2020
The selection of the Cortex M systick driver to be used as a system
clock driver is controlled by CONFIG_CORTEX_M_SYSTICK.

To replace it by another driver CONFIG_CORTEX_M_SYSTICK must be set
to 'n'. Unfortunately this also controls the interrupt vector for
the systick interrupt. It is now routed to z_arm_exc_spurious.

Remove the dependecy on CONFIG_CORTEX_M_SYSTICK and route to
z_clock_isr as it was before zephyrproject-rtos#24012.

Fixes zephyrproject-rtos#24347

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture area: Tests Issues related to a particular existing or missing test Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants