Skip to content

Commit b607b35

Browse files
cbiffleadamgreig
authored andcommitted
Use assembly sequences to enable caches.
See #232, which this partially fixes -- there's still the question of taking an interrupt in the midst of these sequences.
1 parent 33f0318 commit b607b35

9 files changed

+55
-8
lines changed

asm-v7.s

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.syntax unified
12
.cfi_sections .debug_frame
23

34
.section .text.__basepri_max
@@ -39,3 +40,39 @@ __faultmask:
3940
bx lr
4041
.cfi_endproc
4142
.size __faultmask, . - __faultmask
43+
44+
.section .text.__enable_icache
45+
.global __enable_icache
46+
.thumb_func
47+
.cfi_startproc
48+
__enable_icache:
49+
ldr r0, =0xE000ED14 @ CCR
50+
mrs r2, PRIMASK @ save critical nesting info
51+
cpsid i @ mask interrupts
52+
ldr r1, [r0] @ read CCR
53+
orr.w r1, r1, #(1 << 17) @ Set bit 17, IC
54+
str r1, [r0] @ write it back
55+
dsb @ ensure store completes
56+
isb @ synchronize pipeline
57+
msr PRIMASK, r2 @ unnest critical section
58+
bx lr
59+
.cfi_endproc
60+
.size __enable_icache, . - __enable_icache
61+
62+
.section .text.__enable_dcache
63+
.global __enable_dcache
64+
.thumb_func
65+
.cfi_startproc
66+
__enable_dcache:
67+
ldr r0, =0xE000ED14 @ CCR
68+
mrs r2, PRIMASK @ save critical nesting info
69+
cpsid i @ mask interrupts
70+
ldr r1, [r0] @ read CCR
71+
orr.w r1, r1, #(1 << 16) @ Set bit 16, DC
72+
str r1, [r0] @ write it back
73+
dsb @ ensure store completes
74+
isb @ synchronize pipeline
75+
msr PRIMASK, r2 @ unnest critical section
76+
bx lr
77+
.cfi_endproc
78+
.size __enable_dcache, . - __enable_dcache

bin/thumbv6m-none-eabi.a

16 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi.a

688 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf.a

688 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi.a

680 Bytes
Binary file not shown.

bin/thumbv8m.base-none-eabi.a

32 Bytes
Binary file not shown.

bin/thumbv8m.main-none-eabi.a

712 Bytes
Binary file not shown.

bin/thumbv8m.main-none-eabihf.a

712 Bytes
Binary file not shown.

src/peripheral/scb.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,16 @@ impl SCB {
330330
// Invalidate I-Cache
331331
cbp.iciallu();
332332

333-
// Enable I-Cache
334-
unsafe { self.ccr.modify(|r| r | SCB_CCR_IC_MASK) };
333+
// Enable I-cache
334+
extern "C" {
335+
// see asm-v7m.s
336+
fn __enable_icache();
337+
}
335338

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

340345
/// Disables I-Cache if currently enabled
@@ -392,11 +397,16 @@ impl SCB {
392397
// Invalidate anything currently in the DCache
393398
self.invalidate_dcache(cpuid);
394399

395-
// Now turn on the DCache
396-
unsafe { self.ccr.modify(|r| r | SCB_CCR_DC_MASK) };
400+
// Now turn on the D-cache
401+
extern "C" {
402+
// see asm-v7m.s
403+
fn __enable_dcache();
404+
}
397405

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

402412
/// Disables D-cache if currently enabled

0 commit comments

Comments
 (0)