From ff7be3e0261e844c81ae1d4c3f016c0b9dd75b77 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 22 Aug 2019 13:06:15 -0400 Subject: [PATCH] ctr: Encode negative integers in normal hex notation Signed-off-by: Kevin O'Connor --- scripts/buildcommands.py | 18 ++++-------------- src/ctr.h | 3 ++- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py index 956554b2..ef438e0f 100644 --- a/scripts/buildcommands.py +++ b/scripts/buildcommands.py @@ -84,11 +84,10 @@ class HandleEnumerations: enums[name] = value def decl_enumeration(self, req): enum, name, value = req.split()[1:] - self.add_enumeration(enum, name, decode_integer(value)) + self.add_enumeration(enum, name, int(value, 0)) def decl_enumeration_range(self, req): enum, name, value, count = req.split()[1:] - vc = (decode_integer(value), decode_integer(count)) - self.add_enumeration(enum, name, vc) + self.add_enumeration(enum, name, (int(value, 0), int(count, 0))) def decl_static_str(self, req): msg = req.split(None, 1)[1] if msg not in self.static_strings: @@ -120,15 +119,6 @@ Handlers.append(HandlerEnumerations) # Constants ###################################################################### -def decode_integer(value): - value = value.strip() - if len(value) != 11 or value[0] not in '-+' or value[1:3] != '0x': - error("Invalid encoded integer '%s'" % (value,)) - out = int(value[1:], 0) - if value[0] == '-': - out -= 1<<32 - return out - # Allow adding build time constants to the data dictionary class HandleConstants: def __init__(self): @@ -143,7 +133,7 @@ class HandleConstants: self.constants[name] = value def decl_constant(self, req): name, value = req.split()[1:] - self.set_value(name, decode_integer(value)) + self.set_value(name, int(value, 0)) def decl_constant_str(self, req): name, value = req.split(None, 2)[1:] value = value.strip() @@ -217,7 +207,7 @@ class Handle_arm_irq: self.ctr_dispatch = { 'DECL_ARMCM_IRQ': self.decl_armcm_irq } def decl_armcm_irq(self, req): func, num = req.split()[1:] - num = decode_integer(num) + num = int(num, 0) if num in self.irqs and self.irqs[num] != func: error("Conflicting IRQ definition %d (old %s new %s)" % (num, self.irqs[num], func)) diff --git a/src/ctr.h b/src/ctr.h index b5b56ee2..4032e268 100644 --- a/src/ctr.h +++ b/src/ctr.h @@ -16,7 +16,8 @@ // Macro to encode an integer for use with DECL_CTR_INT() #define _CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0') -#define _CTR_INT(V, S) _CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f) +#define _CTR_SHIFT(V, S) _CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f) +#define _CTR_INT(V, S) ((V) < 0 ? _CTR_SHIFT(-(V), (S)) : _CTR_SHIFT((V), (S))) #define CTR_INT(VALUE) { \ ' ', (VALUE) < 0 ? '-' : '+', '0', 'x', \ _CTR_INT((VALUE),28), _CTR_INT((VALUE),24), \