summaryrefslogtreecommitdiff
path: root/nasmlib.c
diff options
context:
space:
mode:
authorCharles Crayne <chuck@thor.crayne.org>2008-02-24 19:14:17 -0800
committerCharles Crayne <chuck@thor.crayne.org>2008-02-24 19:14:17 -0800
commit225f82fa12851317161af58048039a001bf54a5e (patch)
tree7f9fb8a96593251cf7fa57fc79007fcc63eed005 /nasmlib.c
parent986312b17a5238695d774b446fd6096dc5839985 (diff)
downloadnasm-225f82fa12851317161af58048039a001bf54a5e.tar.gz
Dwarf3 support for ELF32
1. Port dwarf3 support from ELF64 to ELF32 2. Move common SAA extentions to nasmlib
Diffstat (limited to 'nasmlib.c')
-rw-r--r--nasmlib.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/nasmlib.c b/nasmlib.c
index 4fc9fc53..d5cf207f 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -652,6 +652,61 @@ void saa_wbytes(struct SAA *s, const void *data, size_t len)
}
}
+/* write unsigned LEB128 value to SAA */
+void saa_wleb128u(struct SAA *psaa, int value)
+{
+ char temp[64], *ptemp;
+ uint8_t byte;
+ int len;
+
+ ptemp = temp;
+ len = 0;
+ do
+ {
+ byte = value & 127;
+ value >>= 7;
+ if (value != 0) /* more bytes to come */
+ byte |= 0x80;
+ *ptemp = byte;
+ ptemp++;
+ len++;
+ } while (value != 0);
+ saa_wbytes(psaa, temp, len);
+}
+
+/* write signed LEB128 value to SAA */
+void saa_wleb128s(struct SAA *psaa, int value)
+{
+ char temp[64], *ptemp;
+ uint8_t byte;
+ bool more, negative;
+ int size, len;
+
+ ptemp = temp;
+ more = 1;
+ negative = (value < 0);
+ size = sizeof(int) * 8;
+ len = 0;
+ while(more)
+ {
+ byte = value & 0x7f;
+ value >>= 7;
+ if (negative)
+ /* sign extend */
+ value |= - (1 <<(size - 7));
+ /* sign bit of byte is second high order bit (0x40) */
+ if ((value == 0 && ! (byte & 0x40)) ||
+ ((value == -1) && (byte & 0x40)))
+ more = 0;
+ else
+ byte |= 0x80;
+ *ptemp = byte;
+ ptemp++;
+ len++;
+ }
+ saa_wbytes(psaa, temp, len);
+}
+
void saa_rewind(struct SAA *s)
{
s->rblk = s->blk_ptrs;