irq_add_shared_handler assertion fix #724 (#747)

This commit is contained in:
Graham Sanderson 2022-04-29 14:34:20 -05:00 committed by GitHub
parent bb5a2a3906
commit 5a427fbf1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -135,9 +135,9 @@ irq_handler_t irq_get_exclusive_handler(uint num) {
static uint16_t make_branch(uint16_t *from, void *to) { static uint16_t make_branch(uint16_t *from, void *to) {
uint32_t ui_from = (uint32_t)from; uint32_t ui_from = (uint32_t)from;
uint32_t ui_to = (uint32_t)to; uint32_t ui_to = (uint32_t)to;
uint32_t delta = (ui_to - ui_from - 4) / 2; int32_t delta = (int32_t)(ui_to - ui_from - 4);
assert(!(delta >> 11u)); assert(delta >= -2048 && delta <= 2046 && !(delta & 1));
return (uint16_t)(0xe000 | (delta & 0x7ff)); return (uint16_t)(0xe000 | ((delta >> 1) & 0x7ff));
} }
static void insert_branch_and_link(uint16_t *from, void *to) { static void insert_branch_and_link(uint16_t *from, void *to) {