From c735d1a6b2110b738ed1c3f01f10b5a2aaf45e6c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 8 Jun 2008 21:15:01 -0700 Subject: [PATCH] Replace the WSAA macros with functions Change the WSAA macros into functions; reducing the icache footprint. --- Makefile.in | 3 +- Mkfiles/msvc.mak | 3 +- Mkfiles/netware.mak | 3 +- Mkfiles/openwcom.mak | 3 +- Mkfiles/owlinux.mak | 3 +- output/outelf32.c | 218 +++++++++++++++++++++++++-------------------------- output/outelf64.c | 218 +++++++++++++++++++++++++-------------------------- wsaa.c | 64 +++++++++++++++ wsaa.h | 76 ++---------------- 9 files changed, 297 insertions(+), 294 deletions(-) create mode 100644 wsaa.c diff --git a/Makefile.in b/Makefile.in index c7d380b..6e510a9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -58,7 +58,8 @@ X = @EXEEXT@ .1.man: $(NROFF) -man $< > $@ -NASM = nasm.$(O) nasmlib.$(O) float.$(O) insnsa.$(O) insnsb.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) wsaa.$(O) \ + float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ output/outaout.$(O) output/outcoff.$(O) \ diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 6707f54..beb15cc 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -32,7 +32,8 @@ X = .exe .c.obj: $(CC) /c $(ALL_CFLAGS) /Fo$@ $< -NASM = nasm.$(O) nasmlib.$(O) float.$(O) insnsa.$(O) insnsb.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) wsaa.$(O) \ + float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ output/outaout.$(O) output/outcoff.$(O) \ diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 8b786a7..6de408b 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -28,7 +28,8 @@ LDFLAGS+=-s O = o -NASM = nasm.$(O) nasmlib.$(O) float.$(O) insnsa.$(O) insnsb.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) wsaa.$(O) \ + float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ output/outaout.$(O) output/outcoff.$(O) \ diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index eb9183c..bf51808 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -44,7 +44,8 @@ X = .exe $(CC) -c $(ALL_CFLAGS) -fo=$^@ $[@ # Note: wcl386 is broken if forward slashes are used as path separators. -NASM = nasm.$(O) nasmlib.$(O) float.$(O) insnsa.$(O) insnsb.$(O) & +NASM = nasm.$(O) nasmlib.$(O) wsaa.$(O) & + float.$(O) insnsa.$(O) insnsb.$(O) & assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) & outform.$(O) output\outbin.$(O) & output\outaout.$(O) output\outcoff.$(O) & diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index ab44fbb..f1d6f3f 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -55,7 +55,8 @@ X = .exe .c.$(O): $(CC) -c $(ALL_CFLAGS) -fo=$@ $< -NASM = nasm.$(O) nasmlib.$(O) float.$(O) insnsa.$(O) insnsb.$(O) \ +NASM = nasm.$(O) nasmlib.$(O) wsaa.$(O) \ + float.$(O) insnsa.$(O) insnsb.$(O) \ assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \ outform.$(O) output/outbin.$(O) \ output/outaout.$(O) output/outcoff.$(O) \ diff --git a/output/outelf32.c b/output/outelf32.c index cc97d04..fc507f8 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -1895,8 +1895,8 @@ void dwarf32_output(int type, void *param) /* check for file change */ if (!(inx == dwarf_csect->file)) { - WSAACHAR(plinep,DW_LNS_set_file); - WSAACHAR(plinep,inx); + saa_write8(plinep,DW_LNS_set_file); + saa_write8(plinep,inx); dwarf_csect->file = inx; } /* check for line change */ @@ -1907,18 +1907,18 @@ void dwarf32_output(int type, void *param) soc = (ln - line_base) + (line_range * aa) + opcode_base; if (ln >= line_base && ln < maxln && soc < 256) { - WSAACHAR(plinep,soc); + saa_write8(plinep,soc); } else { if (ln) { - WSAACHAR(plinep,DW_LNS_advance_line); + saa_write8(plinep,DW_LNS_advance_line); saa_wleb128s(plinep,ln); } if (aa) { - WSAACHAR(plinep,DW_LNS_advance_pc); + saa_write8(plinep,DW_LNS_advance_pc); saa_wleb128u(plinep,aa); } } @@ -1946,14 +1946,14 @@ void dwarf32_generate(void) /* and build aranges section */ paranges = saa_init(1L); parangesrel = saa_init(1L); - WSAASHORT(paranges,2); /* dwarf version */ - WSAALONG(parangesrel, paranges->datalen+4); - WSAALONG(parangesrel, (dwarf_infosym << 8) + R_386_32); /* reloc to info */ - WSAALONG(parangesrel, 0); - WSAALONG(paranges,0); /* offset into info */ - WSAACHAR(paranges,4); /* pointer size */ - WSAACHAR(paranges,0); /* not segmented */ - WSAALONG(paranges,0); /* padding */ + saa_write16(paranges,2); /* dwarf version */ + saa_write32(parangesrel, paranges->datalen+4); + saa_write32(parangesrel, (dwarf_infosym << 8) + R_386_32); /* reloc to info */ + saa_write32(parangesrel, 0); + saa_write32(paranges,0); /* offset into info */ + saa_write8(paranges,4); /* pointer size */ + saa_write8(paranges,0); /* not segmented */ + saa_write32(paranges,0); /* padding */ /* iterate though sectlist entries */ psect = dwarf_fsect; totlen = 0; @@ -1962,25 +1962,25 @@ void dwarf32_generate(void) { plinep = psect->psaa; /* Line Number Program Epilogue */ - WSAACHAR(plinep,2); /* std op 2 */ - WSAACHAR(plinep,(sects[psect->section]->len)-psect->offset); - WSAACHAR(plinep,DW_LNS_extended_op); - WSAACHAR(plinep,1); /* operand length */ - WSAACHAR(plinep,DW_LNE_end_sequence); + saa_write8(plinep,2); /* std op 2 */ + saa_write8(plinep,(sects[psect->section]->len)-psect->offset); + saa_write8(plinep,DW_LNS_extended_op); + saa_write8(plinep,1); /* operand length */ + saa_write8(plinep,DW_LNE_end_sequence); totlen += plinep->datalen; /* range table relocation entry */ - WSAALONG(parangesrel, paranges->datalen + 4); - WSAALONG(parangesrel, ((uint32_t) (psect->section + 2) << 8) + R_386_32); - WSAALONG(parangesrel, (uint32_t) 0); + saa_write32(parangesrel, paranges->datalen + 4); + saa_write32(parangesrel, ((uint32_t) (psect->section + 2) << 8) + R_386_32); + saa_write32(parangesrel, (uint32_t) 0); /* range table entry */ - WSAALONG(paranges,0x0000); /* range start */ - WSAALONG(paranges,sects[psect->section]->len); /* range length */ + saa_write32(paranges,0x0000); /* range start */ + saa_write32(paranges,sects[psect->section]->len); /* range length */ highaddr += sects[psect->section]->len; /* done with this entry */ psect = psect->next; } - WSAALONG(paranges,0); /* null address */ - WSAALONG(paranges,0); /* null length */ + saa_write32(paranges,0); /* null address */ + saa_write32(paranges,0); /* null length */ saalen = paranges->datalen; arangeslen = saalen + 4; arangesbuf = pbuf = nasm_malloc(arangeslen); @@ -1996,10 +1996,10 @@ void dwarf32_generate(void) /* build pubnames section */ ppubnames = saa_init(1L); - WSAASHORT(ppubnames,3); /* dwarf version */ - WSAALONG(ppubnames,0); /* offset into info */ - WSAALONG(ppubnames,0); /* space used in info */ - WSAALONG(ppubnames,0); /* end of list */ + saa_write16(ppubnames,3); /* dwarf version */ + saa_write32(ppubnames,0); /* offset into info */ + saa_write32(ppubnames,0); /* space used in info */ + saa_write32(ppubnames,0); /* end of list */ saalen = ppubnames->datalen; pubnameslen = saalen + 4; pubnamesbuf = pbuf = nasm_malloc(pubnameslen); @@ -2010,35 +2010,35 @@ void dwarf32_generate(void) /* build info section */ pinfo = saa_init(1L); pinforel = saa_init(1L); - WSAASHORT(pinfo,2); /* dwarf version */ - WSAALONG(pinforel, pinfo->datalen + 4); - WSAALONG(pinforel, (dwarf_abbrevsym << 8) + R_386_32); /* reloc to abbrev */ - WSAALONG(pinforel, 0); - WSAALONG(pinfo,0); /* offset into abbrev */ - WSAACHAR(pinfo,4); /* pointer size */ - WSAACHAR(pinfo,1); /* abbrviation number LEB128u */ - WSAALONG(pinforel, pinfo->datalen + 4); - WSAALONG(pinforel, ((dwarf_fsect->section + 2) << 8) + R_386_32); - WSAALONG(pinforel, 0); - WSAALONG(pinfo,0); /* DW_AT_low_pc */ - WSAALONG(pinforel, pinfo->datalen + 4); - WSAALONG(pinforel, ((dwarf_fsect->section + 2) << 8) + R_386_32); - WSAALONG(pinforel, 0); - WSAALONG(pinfo,highaddr); /* DW_AT_high_pc */ - WSAALONG(pinforel, pinfo->datalen + 4); - WSAALONG(pinforel, (dwarf_linesym << 8) + R_386_32); /* reloc to line */ - WSAALONG(pinforel, 0); - WSAALONG(pinfo,0); /* DW_AT_stmt_list */ + saa_write16(pinfo,2); /* dwarf version */ + saa_write32(pinforel, pinfo->datalen + 4); + saa_write32(pinforel, (dwarf_abbrevsym << 8) + R_386_32); /* reloc to abbrev */ + saa_write32(pinforel, 0); + saa_write32(pinfo,0); /* offset into abbrev */ + saa_write8(pinfo,4); /* pointer size */ + saa_write8(pinfo,1); /* abbrviation number LEB128u */ + saa_write32(pinforel, pinfo->datalen + 4); + saa_write32(pinforel, ((dwarf_fsect->section + 2) << 8) + R_386_32); + saa_write32(pinforel, 0); + saa_write32(pinfo,0); /* DW_AT_low_pc */ + saa_write32(pinforel, pinfo->datalen + 4); + saa_write32(pinforel, ((dwarf_fsect->section + 2) << 8) + R_386_32); + saa_write32(pinforel, 0); + saa_write32(pinfo,highaddr); /* DW_AT_high_pc */ + saa_write32(pinforel, pinfo->datalen + 4); + saa_write32(pinforel, (dwarf_linesym << 8) + R_386_32); /* reloc to line */ + saa_write32(pinforel, 0); + saa_write32(pinfo,0); /* DW_AT_stmt_list */ saa_wbytes(pinfo, elf_module, strlen(elf_module)+1); saa_wbytes(pinfo, nasm_signature, strlen(nasm_signature)+1); - WSAASHORT(pinfo,DW_LANG_Mips_Assembler); - WSAACHAR(pinfo,2); /* abbrviation number LEB128u */ - WSAALONG(pinforel, pinfo->datalen + 4); - WSAALONG(pinforel, ((dwarf_fsect->section + 2) << 8) + R_386_32); - WSAALONG(pinforel, 0); - WSAALONG(pinfo,0); /* DW_AT_low_pc */ - WSAALONG(pinfo,0); /* DW_AT_frame_base */ - WSAACHAR(pinfo,0); /* end of entries */ + saa_write16(pinfo,DW_LANG_Mips_Assembler); + saa_write8(pinfo,2); /* abbrviation number LEB128u */ + saa_write32(pinforel, pinfo->datalen + 4); + saa_write32(pinforel, ((dwarf_fsect->section + 2) << 8) + R_386_32); + saa_write32(pinforel, 0); + saa_write32(pinfo,0); /* DW_AT_low_pc */ + saa_write32(pinfo,0); /* DW_AT_frame_base */ + saa_write8(pinfo,0); /* end of entries */ saalen = pinfo->datalen; infolen = saalen + 4; infobuf = pbuf = nasm_malloc(infolen); @@ -2054,32 +2054,32 @@ void dwarf32_generate(void) /* build abbrev section */ pabbrev = saa_init(1L); - WSAACHAR(pabbrev,1); /* entry number LEB128u */ - WSAACHAR(pabbrev,DW_TAG_compile_unit); /* tag LEB128u */ - WSAACHAR(pabbrev,1); /* has children */ + saa_write8(pabbrev,1); /* entry number LEB128u */ + saa_write8(pabbrev,DW_TAG_compile_unit); /* tag LEB128u */ + saa_write8(pabbrev,1); /* has children */ /* the following attributes and forms are all LEB128u values */ - WSAACHAR(pabbrev,DW_AT_low_pc); - WSAACHAR(pabbrev,DW_FORM_addr); - WSAACHAR(pabbrev,DW_AT_high_pc); - WSAACHAR(pabbrev,DW_FORM_addr); - WSAACHAR(pabbrev,DW_AT_stmt_list); - WSAACHAR(pabbrev,DW_FORM_data4); - WSAACHAR(pabbrev,DW_AT_name); - WSAACHAR(pabbrev,DW_FORM_string); - WSAACHAR(pabbrev,DW_AT_producer); - WSAACHAR(pabbrev,DW_FORM_string); - WSAACHAR(pabbrev,DW_AT_language); - WSAACHAR(pabbrev,DW_FORM_data2); - WSAASHORT(pabbrev,0); /* end of entry */ + saa_write8(pabbrev,DW_AT_low_pc); + saa_write8(pabbrev,DW_FORM_addr); + saa_write8(pabbrev,DW_AT_high_pc); + saa_write8(pabbrev,DW_FORM_addr); + saa_write8(pabbrev,DW_AT_stmt_list); + saa_write8(pabbrev,DW_FORM_data4); + saa_write8(pabbrev,DW_AT_name); + saa_write8(pabbrev,DW_FORM_string); + saa_write8(pabbrev,DW_AT_producer); + saa_write8(pabbrev,DW_FORM_string); + saa_write8(pabbrev,DW_AT_language); + saa_write8(pabbrev,DW_FORM_data2); + saa_write16(pabbrev,0); /* end of entry */ /* LEB128u usage same as above */ - WSAACHAR(pabbrev,2); /* entry number */ - WSAACHAR(pabbrev,DW_TAG_subprogram); - WSAACHAR(pabbrev,0); /* no children */ - WSAACHAR(pabbrev,DW_AT_low_pc); - WSAACHAR(pabbrev,DW_FORM_addr); - WSAACHAR(pabbrev,DW_AT_frame_base); - WSAACHAR(pabbrev,DW_FORM_data4); - WSAASHORT(pabbrev,0); /* end of entry */ + saa_write8(pabbrev,2); /* entry number */ + saa_write8(pabbrev,DW_TAG_subprogram); + saa_write8(pabbrev,0); /* no children */ + saa_write8(pabbrev,DW_AT_low_pc); + saa_write8(pabbrev,DW_FORM_addr); + saa_write8(pabbrev,DW_AT_frame_base); + saa_write8(pabbrev,DW_FORM_data4); + saa_write16(pabbrev,0); /* end of entry */ abbrevlen = saalen = pabbrev->datalen; abbrevbuf = pbuf = nasm_malloc(saalen); saa_rnbytes(pabbrev, pbuf, saalen); @@ -2088,37 +2088,37 @@ void dwarf32_generate(void) /* build line section */ /* prolog */ plines = saa_init(1L); - WSAACHAR(plines,1); /* Minimum Instruction Length */ - WSAACHAR(plines,1); /* Initial value of 'is_stmt' */ - WSAACHAR(plines,line_base); /* Line Base */ - WSAACHAR(plines,line_range); /* Line Range */ - WSAACHAR(plines,opcode_base); /* Opcode Base */ + saa_write8(plines,1); /* Minimum Instruction Length */ + saa_write8(plines,1); /* Initial value of 'is_stmt' */ + saa_write8(plines,line_base); /* Line Base */ + saa_write8(plines,line_range); /* Line Range */ + saa_write8(plines,opcode_base); /* Opcode Base */ /* standard opcode lengths (# of LEB128u operands) */ - WSAACHAR(plines,0); /* Std opcode 1 length */ - WSAACHAR(plines,1); /* Std opcode 2 length */ - WSAACHAR(plines,1); /* Std opcode 3 length */ - WSAACHAR(plines,1); /* Std opcode 4 length */ - WSAACHAR(plines,1); /* Std opcode 5 length */ - WSAACHAR(plines,0); /* Std opcode 6 length */ - WSAACHAR(plines,0); /* Std opcode 7 length */ - WSAACHAR(plines,0); /* Std opcode 8 length */ - WSAACHAR(plines,1); /* Std opcode 9 length */ - WSAACHAR(plines,0); /* Std opcode 10 length */ - WSAACHAR(plines,0); /* Std opcode 11 length */ - WSAACHAR(plines,1); /* Std opcode 12 length */ + saa_write8(plines,0); /* Std opcode 1 length */ + saa_write8(plines,1); /* Std opcode 2 length */ + saa_write8(plines,1); /* Std opcode 3 length */ + saa_write8(plines,1); /* Std opcode 4 length */ + saa_write8(plines,1); /* Std opcode 5 length */ + saa_write8(plines,0); /* Std opcode 6 length */ + saa_write8(plines,0); /* Std opcode 7 length */ + saa_write8(plines,0); /* Std opcode 8 length */ + saa_write8(plines,1); /* Std opcode 9 length */ + saa_write8(plines,0); /* Std opcode 10 length */ + saa_write8(plines,0); /* Std opcode 11 length */ + saa_write8(plines,1); /* Std opcode 12 length */ /* Directory Table */ - WSAACHAR(plines,0); /* End of table */ + saa_write8(plines,0); /* End of table */ /* File Name Table */ ftentry = dwarf_flist; for (indx = 0;indxfilename, (int32_t)(strlen(ftentry->filename) + 1)); - WSAACHAR(plines,0); /* directory LEB128u */ - WSAACHAR(plines,0); /* time LEB128u */ - WSAACHAR(plines,0); /* size LEB128u */ + saa_write8(plines,0); /* directory LEB128u */ + saa_write8(plines,0); /* time LEB128u */ + saa_write8(plines,0); /* size LEB128u */ ftentry = ftentry->next; } - WSAACHAR(plines,0); /* End of table */ + saa_write8(plines,0); /* End of table */ linepoff = plines->datalen; linelen = linepoff + totlen + 10; linebuf = pbuf = nasm_malloc(linelen); @@ -2136,9 +2136,9 @@ void dwarf32_generate(void) psect = dwarf_fsect; for (indx = 0; indx < dwarf_nsections; indx++) { - WSAALONG(plinesrel, linepoff); - WSAALONG(plinesrel, ((uint32_t) (psect->section + 2) << 8) + R_386_32); - WSAALONG(plinesrel, (uint32_t) 0); + saa_write32(plinesrel, linepoff); + saa_write32(plinesrel, ((uint32_t) (psect->section + 2) << 8) + R_386_32); + saa_write32(plinesrel, (uint32_t) 0); plinep = psect->psaa; saalen = plinep->datalen; saa_rnbytes(plinep, pbuf, saalen); @@ -2273,10 +2273,10 @@ void dwarf32_findsect(const int index) dwarf_csect->section = index; dwarf_csect->next = 0; /* set relocatable address at start of line program */ - WSAACHAR(plinep,DW_LNS_extended_op); - WSAACHAR(plinep,5); /* operand length */ - WSAACHAR(plinep,DW_LNE_set_address); - WSAALONG(plinep,0); /* Start Address */ + saa_write8(plinep,DW_LNS_extended_op); + saa_write8(plinep,5); /* operand length */ + saa_write8(plinep,DW_LNE_set_address); + saa_write32(plinep,0); /* Start Address */ /* if first entry */ if (!dwarf_fsect) { diff --git a/output/outelf64.c b/output/outelf64.c index f4b6af5..7667293 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -1914,8 +1914,8 @@ void dwarf64_output(int type, void *param) /* check for file change */ if (!(inx == dwarf_csect->file)) { - WSAACHAR(plinep,DW_LNS_set_file); - WSAACHAR(plinep,inx); + saa_write8(plinep,DW_LNS_set_file); + saa_write8(plinep,inx); dwarf_csect->file = inx; } /* check for line change */ @@ -1926,18 +1926,18 @@ void dwarf64_output(int type, void *param) soc = (ln - line_base) + (line_range * aa) + opcode_base; if (ln >= line_base && ln < maxln && soc < 256) { - WSAACHAR(plinep,soc); + saa_write8(plinep,soc); } else { if (ln) { - WSAACHAR(plinep,DW_LNS_advance_line); + saa_write8(plinep,DW_LNS_advance_line); saa_wleb128s(plinep,ln); } if (aa) { - WSAACHAR(plinep,DW_LNS_advance_pc); + saa_write8(plinep,DW_LNS_advance_pc); saa_wleb128u(plinep,aa); } } @@ -1965,14 +1965,14 @@ void dwarf64_generate(void) /* and build aranges section */ paranges = saa_init(1L); parangesrel = saa_init(1L); - WSAASHORT(paranges,3); /* dwarf version */ - WSAADLONG(parangesrel, paranges->datalen+4); - WSAADLONG(parangesrel, (dwarf_infosym << 32) + R_X86_64_32); /* reloc to info */ - WSAADLONG(parangesrel, 0); - WSAALONG(paranges,0); /* offset into info */ - WSAACHAR(paranges,8); /* pointer size */ - WSAACHAR(paranges,0); /* not segmented */ - WSAALONG(paranges,0); /* padding */ + saa_write16(paranges,3); /* dwarf version */ + saa_write64(parangesrel, paranges->datalen+4); + saa_write64(parangesrel, (dwarf_infosym << 32) + R_X86_64_32); /* reloc to info */ + saa_write64(parangesrel, 0); + saa_write32(paranges,0); /* offset into info */ + saa_write8(paranges,8); /* pointer size */ + saa_write8(paranges,0); /* not segmented */ + saa_write32(paranges,0); /* padding */ /* iterate though sectlist entries */ psect = dwarf_fsect; totlen = 0; @@ -1981,25 +1981,25 @@ void dwarf64_generate(void) { plinep = psect->psaa; /* Line Number Program Epilogue */ - WSAACHAR(plinep,2); /* std op 2 */ - WSAACHAR(plinep,(sects[psect->section]->len)-psect->offset); - WSAACHAR(plinep,DW_LNS_extended_op); - WSAACHAR(plinep,1); /* operand length */ - WSAACHAR(plinep,DW_LNE_end_sequence); + saa_write8(plinep,2); /* std op 2 */ + saa_write8(plinep,(sects[psect->section]->len)-psect->offset); + saa_write8(plinep,DW_LNS_extended_op); + saa_write8(plinep,1); /* operand length */ + saa_write8(plinep,DW_LNE_end_sequence); totlen += plinep->datalen; /* range table relocation entry */ - WSAADLONG(parangesrel, paranges->datalen + 4); - WSAADLONG(parangesrel, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(parangesrel, (uint64_t) 0); + saa_write64(parangesrel, paranges->datalen + 4); + saa_write64(parangesrel, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); + saa_write64(parangesrel, (uint64_t) 0); /* range table entry */ - WSAADLONG(paranges,0x0000); /* range start */ - WSAADLONG(paranges,sects[psect->section]->len); /* range length */ + saa_write64(paranges,0x0000); /* range start */ + saa_write64(paranges,sects[psect->section]->len); /* range length */ highaddr += sects[psect->section]->len; /* done with this entry */ psect = psect->next; } - WSAADLONG(paranges,0); /* null address */ - WSAADLONG(paranges,0); /* null length */ + saa_write64(paranges,0); /* null address */ + saa_write64(paranges,0); /* null length */ saalen = paranges->datalen; arangeslen = saalen + 4; arangesbuf = pbuf = nasm_malloc(arangeslen); @@ -2015,10 +2015,10 @@ void dwarf64_generate(void) /* build pubnames section */ ppubnames = saa_init(1L); - WSAASHORT(ppubnames,3); /* dwarf version */ - WSAALONG(ppubnames,0); /* offset into info */ - WSAALONG(ppubnames,0); /* space used in info */ - WSAALONG(ppubnames,0); /* end of list */ + saa_write16(ppubnames,3); /* dwarf version */ + saa_write32(ppubnames,0); /* offset into info */ + saa_write32(ppubnames,0); /* space used in info */ + saa_write32(ppubnames,0); /* end of list */ saalen = ppubnames->datalen; pubnameslen = saalen + 4; pubnamesbuf = pbuf = nasm_malloc(pubnameslen); @@ -2029,35 +2029,35 @@ void dwarf64_generate(void) /* build info section */ pinfo = saa_init(1L); pinforel = saa_init(1L); - WSAASHORT(pinfo,3); /* dwarf version */ - WSAADLONG(pinforel, pinfo->datalen + 4); - WSAADLONG(pinforel, (dwarf_abbrevsym << 32) + R_X86_64_32); /* reloc to abbrev */ - WSAADLONG(pinforel, 0); - WSAALONG(pinfo,0); /* offset into abbrev */ - WSAACHAR(pinfo,8); /* pointer size */ - WSAACHAR(pinfo,1); /* abbrviation number LEB128u */ - WSAADLONG(pinforel, pinfo->datalen + 4); - WSAADLONG(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(pinforel, 0); - WSAADLONG(pinfo,0); /* DW_AT_low_pc */ - WSAADLONG(pinforel, pinfo->datalen + 4); - WSAADLONG(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(pinforel, 0); - WSAADLONG(pinfo,highaddr); /* DW_AT_high_pc */ - WSAADLONG(pinforel, pinfo->datalen + 4); - WSAADLONG(pinforel, (dwarf_linesym << 32) + R_X86_64_32); /* reloc to line */ - WSAADLONG(pinforel, 0); - WSAALONG(pinfo,0); /* DW_AT_stmt_list */ + saa_write16(pinfo,3); /* dwarf version */ + saa_write64(pinforel, pinfo->datalen + 4); + saa_write64(pinforel, (dwarf_abbrevsym << 32) + R_X86_64_32); /* reloc to abbrev */ + saa_write64(pinforel, 0); + saa_write32(pinfo,0); /* offset into abbrev */ + saa_write8(pinfo,8); /* pointer size */ + saa_write8(pinfo,1); /* abbrviation number LEB128u */ + saa_write64(pinforel, pinfo->datalen + 4); + saa_write64(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); + saa_write64(pinforel, 0); + saa_write64(pinfo,0); /* DW_AT_low_pc */ + saa_write64(pinforel, pinfo->datalen + 4); + saa_write64(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); + saa_write64(pinforel, 0); + saa_write64(pinfo,highaddr); /* DW_AT_high_pc */ + saa_write64(pinforel, pinfo->datalen + 4); + saa_write64(pinforel, (dwarf_linesym << 32) + R_X86_64_32); /* reloc to line */ + saa_write64(pinforel, 0); + saa_write32(pinfo,0); /* DW_AT_stmt_list */ saa_wbytes(pinfo, elf_module, strlen(elf_module)+1); saa_wbytes(pinfo, nasm_signature, strlen(nasm_signature)+1); - WSAASHORT(pinfo,DW_LANG_Mips_Assembler); - WSAACHAR(pinfo,2); /* abbrviation number LEB128u */ - WSAADLONG(pinforel, pinfo->datalen + 4); - WSAADLONG(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(pinforel, 0); - WSAADLONG(pinfo,0); /* DW_AT_low_pc */ - WSAADLONG(pinfo,0); /* DW_AT_frame_base */ - WSAACHAR(pinfo,0); /* end of entries */ + saa_write16(pinfo,DW_LANG_Mips_Assembler); + saa_write8(pinfo,2); /* abbrviation number LEB128u */ + saa_write64(pinforel, pinfo->datalen + 4); + saa_write64(pinforel, ((uint64_t)(dwarf_fsect->section + 2) << 32) + R_X86_64_64); + saa_write64(pinforel, 0); + saa_write64(pinfo,0); /* DW_AT_low_pc */ + saa_write64(pinfo,0); /* DW_AT_frame_base */ + saa_write8(pinfo,0); /* end of entries */ saalen = pinfo->datalen; infolen = saalen + 4; infobuf = pbuf = nasm_malloc(infolen); @@ -2073,32 +2073,32 @@ void dwarf64_generate(void) /* build abbrev section */ pabbrev = saa_init(1L); - WSAACHAR(pabbrev,1); /* entry number LEB128u */ - WSAACHAR(pabbrev,DW_TAG_compile_unit); /* tag LEB128u */ - WSAACHAR(pabbrev,1); /* has children */ + saa_write8(pabbrev,1); /* entry number LEB128u */ + saa_write8(pabbrev,DW_TAG_compile_unit); /* tag LEB128u */ + saa_write8(pabbrev,1); /* has children */ /* the following attributes and forms are all LEB128u values */ - WSAACHAR(pabbrev,DW_AT_low_pc); - WSAACHAR(pabbrev,DW_FORM_addr); - WSAACHAR(pabbrev,DW_AT_high_pc); - WSAACHAR(pabbrev,DW_FORM_addr); - WSAACHAR(pabbrev,DW_AT_stmt_list); - WSAACHAR(pabbrev,DW_FORM_data4); - WSAACHAR(pabbrev,DW_AT_name); - WSAACHAR(pabbrev,DW_FORM_string); - WSAACHAR(pabbrev,DW_AT_producer); - WSAACHAR(pabbrev,DW_FORM_string); - WSAACHAR(pabbrev,DW_AT_language); - WSAACHAR(pabbrev,DW_FORM_data2); - WSAASHORT(pabbrev,0); /* end of entry */ + saa_write8(pabbrev,DW_AT_low_pc); + saa_write8(pabbrev,DW_FORM_addr); + saa_write8(pabbrev,DW_AT_high_pc); + saa_write8(pabbrev,DW_FORM_addr); + saa_write8(pabbrev,DW_AT_stmt_list); + saa_write8(pabbrev,DW_FORM_data4); + saa_write8(pabbrev,DW_AT_name); + saa_write8(pabbrev,DW_FORM_string); + saa_write8(pabbrev,DW_AT_producer); + saa_write8(pabbrev,DW_FORM_string); + saa_write8(pabbrev,DW_AT_language); + saa_write8(pabbrev,DW_FORM_data2); + saa_write16(pabbrev,0); /* end of entry */ /* LEB128u usage same as above */ - WSAACHAR(pabbrev,2); /* entry number */ - WSAACHAR(pabbrev,DW_TAG_subprogram); - WSAACHAR(pabbrev,0); /* no children */ - WSAACHAR(pabbrev,DW_AT_low_pc); - WSAACHAR(pabbrev,DW_FORM_addr); - WSAACHAR(pabbrev,DW_AT_frame_base); - WSAACHAR(pabbrev,DW_FORM_data4); - WSAASHORT(pabbrev,0); /* end of entry */ + saa_write8(pabbrev,2); /* entry number */ + saa_write8(pabbrev,DW_TAG_subprogram); + saa_write8(pabbrev,0); /* no children */ + saa_write8(pabbrev,DW_AT_low_pc); + saa_write8(pabbrev,DW_FORM_addr); + saa_write8(pabbrev,DW_AT_frame_base); + saa_write8(pabbrev,DW_FORM_data4); + saa_write16(pabbrev,0); /* end of entry */ abbrevlen = saalen = pabbrev->datalen; abbrevbuf = pbuf = nasm_malloc(saalen); saa_rnbytes(pabbrev, pbuf, saalen); @@ -2107,37 +2107,37 @@ void dwarf64_generate(void) /* build line section */ /* prolog */ plines = saa_init(1L); - WSAACHAR(plines,1); /* Minimum Instruction Length */ - WSAACHAR(plines,1); /* Initial value of 'is_stmt' */ - WSAACHAR(plines,line_base); /* Line Base */ - WSAACHAR(plines,line_range); /* Line Range */ - WSAACHAR(plines,opcode_base); /* Opcode Base */ + saa_write8(plines,1); /* Minimum Instruction Length */ + saa_write8(plines,1); /* Initial value of 'is_stmt' */ + saa_write8(plines,line_base); /* Line Base */ + saa_write8(plines,line_range); /* Line Range */ + saa_write8(plines,opcode_base); /* Opcode Base */ /* standard opcode lengths (# of LEB128u operands) */ - WSAACHAR(plines,0); /* Std opcode 1 length */ - WSAACHAR(plines,1); /* Std opcode 2 length */ - WSAACHAR(plines,1); /* Std opcode 3 length */ - WSAACHAR(plines,1); /* Std opcode 4 length */ - WSAACHAR(plines,1); /* Std opcode 5 length */ - WSAACHAR(plines,0); /* Std opcode 6 length */ - WSAACHAR(plines,0); /* Std opcode 7 length */ - WSAACHAR(plines,0); /* Std opcode 8 length */ - WSAACHAR(plines,1); /* Std opcode 9 length */ - WSAACHAR(plines,0); /* Std opcode 10 length */ - WSAACHAR(plines,0); /* Std opcode 11 length */ - WSAACHAR(plines,1); /* Std opcode 12 length */ + saa_write8(plines,0); /* Std opcode 1 length */ + saa_write8(plines,1); /* Std opcode 2 length */ + saa_write8(plines,1); /* Std opcode 3 length */ + saa_write8(plines,1); /* Std opcode 4 length */ + saa_write8(plines,1); /* Std opcode 5 length */ + saa_write8(plines,0); /* Std opcode 6 length */ + saa_write8(plines,0); /* Std opcode 7 length */ + saa_write8(plines,0); /* Std opcode 8 length */ + saa_write8(plines,1); /* Std opcode 9 length */ + saa_write8(plines,0); /* Std opcode 10 length */ + saa_write8(plines,0); /* Std opcode 11 length */ + saa_write8(plines,1); /* Std opcode 12 length */ /* Directory Table */ - WSAACHAR(plines,0); /* End of table */ + saa_write8(plines,0); /* End of table */ /* File Name Table */ ftentry = dwarf_flist; for (indx = 0;indxfilename, (int32_t)(strlen(ftentry->filename) + 1)); - WSAACHAR(plines,0); /* directory LEB128u */ - WSAACHAR(plines,0); /* time LEB128u */ - WSAACHAR(plines,0); /* size LEB128u */ + saa_write8(plines,0); /* directory LEB128u */ + saa_write8(plines,0); /* time LEB128u */ + saa_write8(plines,0); /* size LEB128u */ ftentry = ftentry->next; } - WSAACHAR(plines,0); /* End of table */ + saa_write8(plines,0); /* End of table */ linepoff = plines->datalen; linelen = linepoff + totlen + 10; linebuf = pbuf = nasm_malloc(linelen); @@ -2155,9 +2155,9 @@ void dwarf64_generate(void) psect = dwarf_fsect; for (indx = 0; indx < dwarf_nsections; indx++) { - WSAADLONG(plinesrel, linepoff); - WSAADLONG(plinesrel, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); - WSAADLONG(plinesrel, (uint64_t) 0); + saa_write64(plinesrel, linepoff); + saa_write64(plinesrel, ((uint64_t) (psect->section + 2) << 32) + R_X86_64_64); + saa_write64(plinesrel, (uint64_t) 0); plinep = psect->psaa; saalen = plinep->datalen; saa_rnbytes(plinep, pbuf, saalen); @@ -2292,10 +2292,10 @@ void dwarf64_findsect(const int index) dwarf_csect->section = index; dwarf_csect->next = 0; /* set relocatable address at start of line program */ - WSAACHAR(plinep,DW_LNS_extended_op); - WSAACHAR(plinep,9); /* operand length */ - WSAACHAR(plinep,DW_LNE_set_address); - WSAADLONG(plinep,0); /* Start Address */ + saa_write8(plinep,DW_LNS_extended_op); + saa_write8(plinep,9); /* operand length */ + saa_write8(plinep,DW_LNE_set_address); + saa_write64(plinep,0); /* Start Address */ /* if first entry */ if (!dwarf_fsect) { diff --git a/wsaa.c b/wsaa.c new file mode 100644 index 0000000..a45df70 --- /dev/null +++ b/wsaa.c @@ -0,0 +1,64 @@ +#include "compiler.h" +#include "nasmlib.h" +#include "wsaa.h" + +void saa_write8(struct SAA *s, uint8_t v) +{ + saa_wbytes(s, &v, 1); +} + +#ifdef WORDS_LITTEENDIAN + +void saa_write16(struct SAA *s, uint16_t v) +{ + saa_wbytes(s, &v, 2); +} + +void saa_write32(struct SAA *s, uint32_t v) +{ + saa_wbytes(s, &v, 4); +} + +void saa_write64(struct SAA *s, uint64_t v) +{ + saa_wbytes(s, &v, 8); +} + +#else /* not WORDS_LITTLEENDIAN */ + +void saa_write16(struct SAA *s, uint16_t v) +{ + uint8_t b[2]; + + b[0] = v; + b[1] = v >> 8; + saa_wbytes(s, b, 2); +} + +void saa_write32(struct SAA *s, uint32_t v) +{ + uint8_t b[4]; + + b[0] = v; + b[1] = v >> 8; + b[2] = v >> 16; + b[3] = v >> 24; + saa_wbytes(s, b, 4); +} + +void saa_write64(struct SAA *s, uint64_t v) +{ + uint8_t b[8]; + + b[0] = v; + b[1] = v >> 8; + b[2] = v >> 16; + b[3] = v >> 24; + b[4] = v >> 32; + b[5] = v >> 40; + b[6] = v >> 48; + b[7] = v >> 56; + saa_wbytes(s, b, 8); +} + +#endif /* WORDS_LITTLEENDIAN */ diff --git a/wsaa.h b/wsaa.h index d70b64a..0980174 100644 --- a/wsaa.h +++ b/wsaa.h @@ -4,75 +4,9 @@ #include "compiler.h" #include "nasmlib.h" -#ifdef WORDS_LITTEENDIAN +void saa_write8(struct SAA *s, uint8_t v); +void saa_write16(struct SAA *s, uint16_t v); +void saa_write32(struct SAA *s, uint32_t v); +void saa_write64(struct SAA *s, uint64_t v); -#define WSAACHAR(s,v) \ - do { \ - uint8_t _wsb_v = (v); \ - saa_wbytes(s, &_wsb_v, 1); \ - } while (0) - -#define WSAASHORT(s,v) \ - do { \ - uint16_t _wss_v = (v); \ - saa_wbytes(s, &_wss_v, 2); \ - } while (0) - -#define WSAALONG(s,v) \ - do { \ - uint32_t _wsl_v = (v); \ - saa_wbytes(s, &_wsl_v, 4); \ - } while (0) - -#define WSAADLONG(s,v) \ - do { \ - uint64_t _wsq_v = (v); \ - saa_wbytes(s, &_wsq_v, 8); \ - } while (0) - -#else /* !X86_MEMORY */ - -#define WSAACHAR(s,v) \ - do { \ - uint8_t _wsb_v = (v); \ - saa_wbytes(s, &_wsb_v, 1); \ - } while (0) - -#define WSAASHORT(s,v) \ - do { \ - uint16_t _wss_v = (v); \ - uint8_t _wss_p[2]; \ - _wss_p[0] = _wss_v; \ - _wss_p[1] = _wss_v >> 8; \ - saa_wbytes(s, _wss_p, 2); \ - } while (0) - -#define WSAALONG(s,v) \ - do { \ - uint32_t _wsl_v = (v); \ - uint8_t _wsl_p[4]; \ - _wsl_p[0] = _wsl_v; \ - _wsl_p[1] = _wsl_v >> 8; \ - _wsl_p[2] = _wsl_v >> 16; \ - _wsl_p[3] = _wsl_v >> 24; \ - saa_wbytes(s, _wsl_p, 4); \ - } while (0) - -#define WSAADLONG(s,v) \ - do { \ - uint64_t _wsq_v = (v); \ - uint8_t _wsq_p[8]; \ - _wsq_p[0] = _wsq_v; \ - _wsq_p[1] = _wsq_v >> 8; \ - _wsq_p[2] = _wsq_v >> 16; \ - _wsq_p[3] = _wsq_v >> 24; \ - _wsq_p[4] = _wsq_v >> 32; \ - _wsq_p[5] = _wsq_v >> 40; \ - _wsq_p[6] = _wsq_v >> 48; \ - _wsq_p[7] = _wsq_v >> 56; \ - saa_wbytes(s, _wsq_p, 8); \ - } while (0) - -#endif - -#endif /* NASM_WSAA_H */ +#endif /* wsaa.h */ -- 2.7.4