aboutsummaryrefslogtreecommitdiff
path: root/py/asmthumb.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-05-10 18:07:08 +0100
committerDamien George <damien.p.george@gmail.com>2014-05-10 18:07:08 +0100
commit9597771fe4c0aa42f20514d7315e706bf6dc51cf (patch)
tree811bea0200ab4d3a2b35d244ff92251fbd83e299 /py/asmthumb.c
parent7db57bf6b227f33d66493ab3252621ed0895d995 (diff)
py, emitters: Fix dummy_data size for bytecode and thumb.
Thumb uses a bit less RAM, bytecode uses a tiny bit more, to avoid overflow of the dummy buffer in certain cases. Addresses issue #599.
Diffstat (limited to 'py/asmthumb.c')
-rw-r--r--py/asmthumb.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/py/asmthumb.c b/py/asmthumb.c
index 9e3a9abe2..891947567 100644
--- a/py/asmthumb.c
+++ b/py/asmthumb.c
@@ -46,7 +46,7 @@ struct _asm_thumb_t {
uint code_offset;
uint code_size;
byte *code_base;
- byte dummy_data[8];
+ byte dummy_data[4];
uint max_num_labels;
int *label_offsets;
@@ -113,6 +113,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) {
}
// all functions must go through this one to emit bytes
+// if as->pass < ASM_THUMB_PASS_EMIT, then this function only returns a buffer of 4 bytes length
STATIC byte *asm_thumb_get_cur_to_write_bytes(asm_thumb_t *as, int num_bytes_to_write) {
//printf("emit %d\n", num_bytes_to_write);
if (as->pass < ASM_THUMB_PASS_EMIT) {
@@ -251,10 +252,13 @@ void asm_thumb_align(asm_thumb_t* as, uint align) {
void asm_thumb_data(asm_thumb_t* as, uint bytesize, uint val) {
byte *c = asm_thumb_get_cur_to_write_bytes(as, bytesize);
- // little endian
- for (uint i = 0; i < bytesize; i++) {
- *c++ = val;
- val >>= 8;
+ // only write to the buffer in the emit pass (otherwise we overflow dummy_data)
+ if (as->pass == ASM_THUMB_PASS_EMIT) {
+ // little endian
+ for (uint i = 0; i < bytesize; i++) {
+ *c++ = val;
+ val >>= 8;
+ }
}
}