Skip to content

Use assembly sequences to enable caches. #234

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

Merged
merged 1 commit into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions asm-v7.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.syntax unified
.cfi_sections .debug_frame

.section .text.__basepri_max
Expand Down Expand Up @@ -39,3 +40,39 @@ __faultmask:
bx lr
.cfi_endproc
.size __faultmask, . - __faultmask

.section .text.__enable_icache
.global __enable_icache
.thumb_func
.cfi_startproc
__enable_icache:
ldr r0, =0xE000ED14 @ CCR
mrs r2, PRIMASK @ save critical nesting info
cpsid i @ mask interrupts
ldr r1, [r0] @ read CCR
orr.w r1, r1, #(1 << 17) @ Set bit 17, IC
str r1, [r0] @ write it back
dsb @ ensure store completes
isb @ synchronize pipeline
msr PRIMASK, r2 @ unnest critical section
bx lr
.cfi_endproc
.size __enable_icache, . - __enable_icache

.section .text.__enable_dcache
.global __enable_dcache
.thumb_func
.cfi_startproc
__enable_dcache:
ldr r0, =0xE000ED14 @ CCR
mrs r2, PRIMASK @ save critical nesting info
cpsid i @ mask interrupts
ldr r1, [r0] @ read CCR
orr.w r1, r1, #(1 << 16) @ Set bit 16, DC
str r1, [r0] @ write it back
dsb @ ensure store completes
isb @ synchronize pipeline
msr PRIMASK, r2 @ unnest critical section
bx lr
.cfi_endproc
.size __enable_dcache, . - __enable_dcache
Binary file modified bin/thumbv6m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv7em-none-eabihf.a
Binary file not shown.
Binary file modified bin/thumbv7m-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.base-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabi.a
Binary file not shown.
Binary file modified bin/thumbv8m.main-none-eabihf.a
Binary file not shown.
24 changes: 16 additions & 8 deletions src/peripheral/scb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,15 @@ impl SCB {
cbp.iciallu();

// Enable I-cache
// NOTE(unsafe): We have synchronised access by &mut self
unsafe { self.ccr.modify(|r| r | SCB_CCR_IC_MASK) };
extern "C" {
// see asm-v7m.s
fn __enable_icache();
}

crate::asm::dsb();
crate::asm::isb();
// NOTE(unsafe): The asm routine manages exclusive access to the SCB
// registers and applies the proper barriers; it is technically safe on
// its own, and is only `unsafe` here because it's `extern "C"`.
unsafe { __enable_icache(); }
}

/// Disables I-cache if currently enabled.
Expand Down Expand Up @@ -400,11 +404,15 @@ impl SCB {
unsafe { self.invalidate_dcache(cpuid) };

// Now turn on the D-cache
// NOTE(unsafe): We have synchronised access by &mut self
unsafe { self.ccr.modify(|r| r | SCB_CCR_DC_MASK) };
extern "C" {
// see asm-v7m.s
fn __enable_dcache();
}

crate::asm::dsb();
crate::asm::isb();
// NOTE(unsafe): The asm routine manages exclusive access to the SCB
// registers and applies the proper barriers; it is technically safe on
// its own, and is only `unsafe` here because it's `extern "C"`.
unsafe { __enable_dcache(); }
}

/// Disables D-cache if currently enabled.
Expand Down