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

add set_vector_table_offset() #1579

Merged
merged 1 commit into from
Mar 5, 2020
Merged

add set_vector_table_offset() #1579

merged 1 commit into from
Mar 5, 2020

Conversation

xiongyihui
Copy link
Contributor

@xiongyihui xiongyihui commented Feb 4, 2020

when using a bootloader, tock os may need to relocate interrupt
vector table, then use this function to do that.

See the discussion at google/OpenSK#3

Pull Request Overview

This pull request adds add set_vector_table_offset function to relocate interrupt vector table.

Testing Strategy

TODO

TODO or Help Wanted

N/A

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make formatall.

@@ -54,3 +54,8 @@ pub unsafe fn reset() {
let reset = (0x5FA << 16) | (aircr & (0x7 << 8)) | (1 << 2);
SCB.aircr.set(reset);
}

/// relocate interrupt vector table
pub unsafe fn set_vector_table_offset(offset: u32) {
Copy link
Contributor

Choose a reason for hiding this comment

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

offset is really an address, correct? Should the argument be a pointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VTOR is Vector Table Offset Register

Not sure if the offset is an address or not

Copy link
Contributor

Choose a reason for hiding this comment

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

ARM specifies it as an offset, but that offset appears to always be from 0. I think it is more clear of an API if we take a pointer as an argument, which is the location the vector table is now at.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still new to Rust, not sure what pointer type should be used? *const c_void or *const u32?

Copy link
Member

@alevy alevy Mar 3, 2020

Choose a reason for hiding this comment

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

probably *const ().

@bradjc
Copy link
Contributor

bradjc commented Feb 5, 2020

Thanks, and this is a useful function. I checked how the tock bootloader works and it just uses assembly to set the new vector table, so it would not compile for non cortex-m boards currently. Along those lines, we eventually need some mechanism to expose this functionality outside of the arch/ crate so that a generic bootloader could use.

And then just as a side note, I ask that you do not truncate the PR template because sometimes there are documentation needs that are not immediately obvious. In this case we do not need to update documentation, however.

@ppannuto
Copy link
Member

One thing we'll need to think about at some point is that cortex-m0 does not have a VTOR -- or really more generally that the SCB surface among the M0 and M3/M4 varies:

image

image

Right now we just don't export the SCB to the m0 crate, but this is really the same problem that we're running into with nrf variants as well...

@xiongyihui
Copy link
Contributor Author

I thought Tock can not be run on a cortex-m0 microcontroller which doesn't have a MPU. Is this right?

@rajivr
Copy link
Contributor

rajivr commented Feb 13, 2020

I thought Tock can not be run on a cortex-m0 microcontroller which doesn't have a MPU. Is this right?

I have Tock running on M0 mostly for testing and experimentation purposes.

Yes, there is no MPU, so you won't get hardware memory protection for user processes. All that is needed is to do the following in chip.rs

    fn mpu(&self) -> &Self::MPU {
        &()
    }

The other (annoying) issue with M0 is the lack of atomics. I am glad to see OpenTitan including atomic support into its core.

@bradjc
Copy link
Contributor

bradjc commented Feb 13, 2020

Yeah I don't think we need to base any Tock design decisions on cortex-m0, it is just too constrained.

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

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

I think a pointer API makes more sense and is clearer for users. Let me know if you think it is better to expose the ARM interface.

@alevy
Copy link
Member

alevy commented Mar 3, 2020

I agree with @bradjc that the parameter should be a pointer. Otherwise, I think this is an easy merge once that's fixed.

when using a bootloader, tock os may need to relocate interrupt
vector table, then use this function to do that
@xiongyihui
Copy link
Contributor Author

as @alevy suggested, changed it to *const ()

An example to use it:

extern "C" {
    // _estack is the start of interrupt vector table
    fn _estack();
}

scb::set_vector_table_offset(_estack as *const ());

@alevy
Copy link
Member

alevy commented Mar 5, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 5, 2020

Build succeeded

@bors bors bot merged commit cf505cf into tock:master Mar 5, 2020
jmichelp added a commit to jmichelp/OpenSK that referenced this pull request Mar 11, 2020
Now the script supports more flashing methods:
- JLink (with tockloader)
- OpenOCD (with tockloader)
- pyOCD
- Nordic DFU
- none (will produce an IntelHex file)

Also merged the contributions from:
- Yihui Xiong to support the Makerdiary USB dongle board
- Dennis Geurts to support Nordic DFU

Doc updated accordingly.

Imported 2 patches for Tock kernel:
- 06-add-set_vector_table_offset.patch (upstream tock/tock#1579)
- 07-nrf52-bootloader.patch (upstream tock/tock#1681)
jmichelp added a commit to jmichelp/OpenSK that referenced this pull request Mar 11, 2020
Now the script supports more flashing methods:
- JLink (with tockloader)
- OpenOCD (with tockloader)
- pyOCD
- Nordic DFU
- none (will produce an IntelHex file)

Also merged the contributions from:
- Yihui Xiong to support the Makerdiary USB dongle board
- Dennis Geurts to support Nordic DFU

Doc updated accordingly.

Imported 2 patches for Tock kernel:
- 06-add-set_vector_table_offset.patch (upstream tock/tock#1579)
- 07-nrf52-bootloader.patch (upstream tock/tock#1681)
@jmichelp jmichelp mentioned this pull request Mar 11, 2020
2 tasks
jmichelp added a commit to jmichelp/OpenSK that referenced this pull request Mar 11, 2020
Now the script supports more flashing methods:
- JLink (with tockloader)
- OpenOCD (with tockloader)
- pyOCD
- Nordic DFU
- none (will produce an IntelHex file)

Also merged the contributions from:
- Yihui Xiong to support the Makerdiary USB dongle board
- Dennis Geurts to support Nordic DFU

Doc updated accordingly.

Imported 2 patches for Tock kernel:
- 06-add-set_vector_table_offset.patch (upstream tock/tock#1579)
- 07-nrf52-bootloader.patch (upstream tock/tock#1681)
kaczmarczyck pushed a commit to kaczmarczyck/OpenSK that referenced this pull request Mar 12, 2020
Now the script supports more flashing methods:
- JLink (with tockloader)
- OpenOCD (with tockloader)
- pyOCD
- Nordic DFU
- none (will produce an IntelHex file)

Also merged the contributions from:
- Yihui Xiong to support the Makerdiary USB dongle board
- Dennis Geurts to support Nordic DFU

Doc updated accordingly.

Imported 2 patches for Tock kernel:
- 06-add-set_vector_table_offset.patch (upstream tock/tock#1579)
- 07-nrf52-bootloader.patch (upstream tock/tock#1681)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants