aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/buildcommands.py4
-rw-r--r--src/ctr.h15
2 files changed, 11 insertions, 8 deletions
diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py
index b74581de..87bc297d 100644
--- a/scripts/buildcommands.py
+++ b/scripts/buildcommands.py
@@ -125,9 +125,9 @@ Handlers.append(HandlerEnumerations)
def decode_integer(value):
value = value.strip()
- if len(value) != 7 or value[0] not in '-+':
+ if len(value) != 11 or value[0] not in '-+' or value[1:3] != '0x':
error("Invalid encoded integer '%s'" % (value,))
- out = sum([(ord(c) - 48) << (i*6) for i, c in enumerate(value[1:])])
+ out = int(value[1:], 0)
if value[0] == '-':
out -= 1<<32
return out
diff --git a/src/ctr.h b/src/ctr.h
index b3c14ff1..36a7334c 100644
--- a/src/ctr.h
+++ b/src/ctr.h
@@ -14,17 +14,20 @@
static char __PASTE(_DECLS_, __LINE__)[] __attribute__((used)) \
__section(".compile_time_request") = (REQUEST)
-#define CTR_INT(V, S) ((((uint32_t)(V) >> S) & 0x3f) + 48)
+// Helper macros for encoding an integer
+#define CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0')
+#define CTR_INT(V, S) CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f)
// Declare a compile time request with an integer expression
#define DECL_CTR_INT(REQUEST, VALUE) \
- static struct { char _r[sizeof(REQUEST)]; char _v[8]; } \
+ static struct { char _r[sizeof(REQUEST)]; char _v[12]; } \
__PASTE(_DECLI_, __LINE__) __attribute__((used)) \
__section(".compile_time_request") = { \
REQUEST " ", { \
- (VALUE) < 0 ? '-' : '+', \
- CTR_INT((VALUE),0), CTR_INT((VALUE),6), \
- CTR_INT((VALUE),12), CTR_INT((VALUE),18), \
- CTR_INT((VALUE),24), CTR_INT((VALUE),30), 0 } }
+ (VALUE) < 0 ? '-' : '+', '0', 'x', \
+ CTR_INT((VALUE),28), CTR_INT((VALUE),24), \
+ CTR_INT((VALUE),20), CTR_INT((VALUE),16), \
+ CTR_INT((VALUE),12), CTR_INT((VALUE),8), \
+ CTR_INT((VALUE),4), CTR_INT((VALUE),0), 0 } }
#endif // ctr.h