Skip to content

Commit d271b86

Browse files
committed
- make non overridable symbols .global to cause link error if you have e.g. isr_irq11 and there aren't 11 vector table entries
- omit guts of __unhandler_user_irq if not needed, but keep label and separate breakpoint (since there is an alignment hole of 2 bytes anyway)
1 parent cf56ddd commit d271b86

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

src/rp2_common/hardware_exception/exception.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ static inline exception_handler_t *get_exception_table(void) {
3131
#endif
3232
}
3333

34+
#if !PICO_NO_RAM_VECTOR_TABLE
3435
static void set_raw_exception_handler_and_restore_interrupts(enum exception_number num, exception_handler_t handler, uint32_t save) {
3536
// update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness)
3637
get_exception_table()[num] = handler;
3738
__dmb();
3839
restore_interrupts_from_disabled(save);
3940
}
41+
#endif
4042

4143
static inline void check_exception_param(__unused enum exception_number num) {
4244
invalid_params_if(HARDWARE_EXCEPTION, num < MIN_EXCEPTION_NUM || num > MAX_EXCEPTION_NUM);
@@ -54,10 +56,12 @@ exception_handler_t exception_set_exclusive_handler(enum exception_number num, e
5456
exception_handler_t current = exception_get_vtable_handler(num);
5557
hard_assert(handler == current || exception_is_compile_time_default(current));
5658
set_raw_exception_handler_and_restore_interrupts(num, handler, save);
59+
return current;
5760
#else
61+
((void)num);
62+
((void)handler);
5863
panic_unsupported();
5964
#endif
60-
return current;
6165
}
6266

6367
void exception_restore_handler(enum exception_number num, exception_handler_t original_handler) {
@@ -66,6 +70,8 @@ void exception_restore_handler(enum exception_number num, exception_handler_t or
6670
uint32_t save = save_and_disable_interrupts();
6771
set_raw_exception_handler_and_restore_interrupts(num, original_handler, save);
6872
#else
73+
((void)num);
74+
((void)original_handler);
6975
panic_unsupported();
7076
#endif
7177
}

src/rp2_common/hardware_irq/irq.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ static inline void *remove_thumb_bit(void *addr) {
5151
#endif
5252
}
5353

54-
static void set_raw_irq_handler_and_unlock(uint num, irq_handler_t handler, uint32_t save) {
55-
// update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness)
56-
get_vtable()[VTABLE_FIRST_IRQ + num] = handler;
57-
__dmb();
58-
spin_unlock(spin_lock_instance(PICO_SPINLOCK_ID_IRQ), save);
59-
}
60-
6154
void irq_set_enabled(uint num, bool enabled) {
6255
check_irq_param(num);
6356
// really should update irq_set_mask_enabled?
@@ -129,7 +122,7 @@ void irq_set_pending(uint num) {
129122
#endif
130123
}
131124

132-
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS
125+
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE
133126
// limited by 8 bit relative links (and reality)
134127
static_assert(PICO_MAX_SHARED_IRQ_HANDLERS >= 1 && PICO_MAX_SHARED_IRQ_HANDLERS < 0x7f, "");
135128

@@ -203,9 +196,17 @@ bool irq_has_shared_handler(uint irq_num) {
203196
return handler && is_shared_irq_raw_handler(handler);
204197
}
205198

206-
#else // PICO_DISABLE_SHARED_IRQ_HANDLERS
199+
static void set_raw_irq_handler_and_unlock(uint num, irq_handler_t handler, uint32_t save) {
200+
// update vtable (vtable_handler may be same or updated depending on cases, but we do it anyway for compactness)
201+
get_vtable()[VTABLE_FIRST_IRQ + num] = handler;
202+
__dmb();
203+
spin_unlock(spin_lock_instance(PICO_SPINLOCK_ID_IRQ), save);
204+
}
205+
206+
#else // PICO_DISABLE_SHARED_IRQ_HANDLERS && PICO_NO_RAM_VECTOR_TABLE
207207
#define is_shared_irq_raw_handler(h) false
208208
bool irq_has_shared_handler(uint irq_num) {
209+
((void)irq_num);
209210
return false;
210211
}
211212
#endif
@@ -225,6 +226,7 @@ void irq_set_exclusive_handler(uint num, irq_handler_t handler) {
225226
hard_assert(current == __unhandled_user_irq || current == handler);
226227
set_raw_irq_handler_and_unlock(num, handler, save);
227228
#else
229+
((void)handler);
228230
panic_unsupported();
229231
#endif
230232
}
@@ -246,7 +248,7 @@ irq_handler_t irq_get_exclusive_handler(uint num) {
246248
}
247249

248250

249-
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS
251+
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE
250252

251253
#ifndef __riscv
252254

@@ -356,6 +358,8 @@ static inline int8_t get_slot_index(struct irq_handler_chain_slot *slot) {
356358
void irq_add_shared_handler(uint num, irq_handler_t handler, uint8_t order_priority) {
357359
check_irq_param(num);
358360
#if PICO_NO_RAM_VECTOR_TABLE
361+
((void)handler);
362+
((void)order_priority);
359363
panic_unsupported();
360364
#elif PICO_DISABLE_SHARED_IRQ_HANDLERS
361365
irq_set_exclusive_handler(num, handler);
@@ -449,7 +453,7 @@ void irq_add_shared_handler(uint num, irq_handler_t handler, uint8_t order_prior
449453
#endif // !PICO_NO_RAM_VECTOR_TABLE && !PICO_DISABLE_SHARED_IRQ_HANDLERS
450454
}
451455

452-
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS
456+
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE
453457
static inline irq_handler_t handler_from_slot(struct irq_handler_chain_slot *slot) {
454458
#ifndef __riscv
455459
return slot->handler;
@@ -574,6 +578,8 @@ void irq_remove_handler(uint num, irq_handler_t handler) {
574578
}
575579
set_raw_irq_handler_and_unlock(num, vtable_handler, save);
576580
#else
581+
((void)num);
582+
((void)handler);
577583
panic_unsupported();
578584
#endif
579585
}
@@ -614,7 +620,7 @@ uint irq_get_priority(uint num) {
614620
#endif
615621
}
616622

617-
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS
623+
#if !PICO_DISABLE_SHARED_IRQ_HANDLERS && !PICO_NO_RAM_VECTOR_TABLE
618624
// used by irq_handler_chain.S to remove the last link in a handler chain after it executes
619625
// note this must be called only with the last slot in a chain (and during the exception)
620626
void irq_add_tail_to_free_list(struct irq_handler_chain_slot *slot) {

src/rp2_common/pico_crt0/crt0.S

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,14 @@ __default_isrs_start:
168168
bkpt #0
169169
.endm
170170

171-
// these are separated out for clarity
172-
decl_isr_bkpt isr_invalid
173-
#if !PICO_MINIMAL_STORED_VECTOR_TABLE
174-
decl_isr_bkpt isr_nmi
175-
decl_isr_bkpt isr_hardfault
176-
decl_isr_bkpt isr_svcall
177-
decl_isr_bkpt isr_pendsv
178-
decl_isr_bkpt isr_systick
179-
180-
.global __default_isrs_end
181-
__default_isrs_end:
182-
183171
.altmacro
184172
.macro decl_isr name
185173
#if !PICO_MINIMAL_STORED_VECTOR_TABLE | PICO_NO_FLASH
186174
// We declare a weak label, so user can override
187175
.weak \name
188176
#else
189-
// We declare a strong label, so user can't override (their version would not automatically be used)
177+
// We declare a strong global label, so user can't override (their version would not automatically be used)
178+
.global \name
190179
#endif
191180
.type \name,%function
192181
.thumb_func
@@ -197,7 +186,8 @@ __default_isrs_end:
197186
.if \num < PICO_NUM_VTABLE_IRQS
198187
decl_isr \func
199188
.elseif \num < NUM_IRQS
200-
// We declare a strong label, so user can't override, since there is no vtable entry
189+
// We declare a strong global label, so user can't override (their version would not automatically be used)
190+
.global \func
201191
.type \func,%function
202192
.thumb_func
203193
\func:
@@ -288,17 +278,34 @@ if_irq_decl 79 isr_irq79
288278
#error more IRQ entries required
289279
#endif
290280

291-
#endif // #if !PICO_MINIMAL_STORED_VECTOR_TABLE
292281
// All unhandled USER IRQs fall through to here
293282
.global __unhandled_user_irq
294283
.thumb_func
295284
__unhandled_user_irq:
285+
// if we include the implementation if there could be a valid IRQ hanler in the vtable that uses it
286+
#if !(PICO_NO_RAM_VECTOR_TABLE && PICO_MINIMAL_STORED_VECTOR_TABLE)
296287
mrs r0, ipsr
297288
subs r0, #16
298289
.global unhandled_user_irq_num_in_r0
299290
unhandled_user_irq_num_in_r0:
291+
#endif
292+
// note the next instruction is a breakpoint too, however we have a 2 byte alignment hole
293+
// and it is preferrable to have distinct labels, to inform the user what has happened in the debugger.
300294
bkpt #0
301295

296+
decl_isr_bkpt isr_invalid
297+
#if !PICO_MINIMAL_STORED_VECTOR_TABLE
298+
// these are separated out for clarity
299+
decl_isr_bkpt isr_nmi
300+
decl_isr_bkpt isr_hardfault
301+
decl_isr_bkpt isr_svcall
302+
decl_isr_bkpt isr_pendsv
303+
decl_isr_bkpt isr_systick
304+
#endif
305+
306+
.global __default_isrs_end
307+
__default_isrs_end:
308+
302309
// ----------------------------------------------------------------------------
303310

304311
.section .binary_info_header, "a"

0 commit comments

Comments
 (0)