|
|
efc615 |
/****************************************************************/
|
|
|
efc615 |
/* mdso: midipix dso scavenger */
|
|
|
78ab3c |
/* Copyright (C) 2015--2017 Z. Gilboa */
|
|
|
efc615 |
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
|
|
|
efc615 |
/****************************************************************/
|
|
|
efc615 |
|
|
|
efc615 |
#include <stdint.h>
|
|
|
efc615 |
#include <stdio.h>
|
|
|
7f20b2 |
|
|
|
efc615 |
#include <mdso/mdso.h>
|
|
|
efc615 |
#include <mdso/mdso_specs.h>
|
|
|
18a091 |
#include "mdso_dprintf_impl.h"
|
|
|
7f20b2 |
#include "mdso_errinfo_impl.h"
|
|
|
efc615 |
|
|
|
efc615 |
static const char * const asm_lines[] = {
|
|
|
c26232 |
"\t.section " MDSO_STRS_SECTION "$%s,\"r0\"\n\n",
|
|
|
c26232 |
".symstr_%s:\n",
|
|
|
c26232 |
"\t.ascii\t\"%s\\0\"\n"
|
|
|
c26232 |
"\t.linkonce discard\n\n",
|
|
|
c26232 |
"\t.section " MDSO_SYMS_SECTION "$%s,\"r\"\n",
|
|
|
efc615 |
0
|
|
|
efc615 |
};
|
|
|
efc615 |
|
|
|
2c190d |
int mdso_asmgen_symentry(
|
|
|
7f20b2 |
const struct mdso_driver_ctx * dctx,
|
|
|
efc615 |
const char * sym,
|
|
|
18a091 |
int fdout)
|
|
|
efc615 |
{
|
|
|
efc615 |
const char * const * line;
|
|
|
efc615 |
const char * alignstr;
|
|
|
54e94f |
const char * rvapad;
|
|
|
260511 |
const char * uscore;
|
|
|
260511 |
|
|
|
18a091 |
if (mdso_dprintf(fdout,"\t.file \".%s_symentry.s\"\n",sym) < 0)
|
|
|
260511 |
return MDSO_FILE_ERROR(dctx);
|
|
|
efc615 |
|
|
|
7f20b2 |
if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) {
|
|
|
efc615 |
alignstr = "\t.balign 16\n\n";
|
|
|
54e94f |
rvapad = "\t.long 0\n";
|
|
|
260511 |
uscore = "";
|
|
|
efc615 |
} else {
|
|
|
efc615 |
alignstr = "\t.balign 8\n\n";
|
|
|
54e94f |
rvapad = "";
|
|
|
260511 |
uscore = "_";
|
|
|
efc615 |
}
|
|
|
efc615 |
|
|
|
efc615 |
for (line=asm_lines; *line; line++)
|
|
|
18a091 |
if ((mdso_dprintf(fdout,*line,sym)) < 0)
|
|
|
7f20b2 |
return MDSO_FILE_ERROR(dctx);
|
|
|
efc615 |
|
|
|
18a091 |
if (mdso_dprintf(fdout,"\t.globl __imp_%s%s\n",uscore,sym) < 0)
|
|
|
260511 |
return MDSO_FILE_ERROR(dctx);
|
|
|
260511 |
|
|
|
18a091 |
if (mdso_dprintf(fdout,alignstr) < 0)
|
|
|
7f20b2 |
return MDSO_FILE_ERROR(dctx);
|
|
|
efc615 |
|
|
|
18a091 |
if ((mdso_dprintf(fdout,"__imp_%s%s:\n",uscore,sym)) < 0)
|
|
|
7f20b2 |
return MDSO_FILE_ERROR(dctx);
|
|
|
efc615 |
|
|
|
54e94f |
if ((mdso_dprintf(fdout,"\t.rva\t.symstr_%s\n%s",
|
|
|
54e94f |
sym,rvapad)) < 0)
|
|
|
7f20b2 |
return MDSO_FILE_ERROR(dctx);
|
|
|
efc615 |
|
|
|
54e94f |
if ((mdso_dprintf(fdout,"\t.rva\t.dsometa_%s\n%s",
|
|
|
54e94f |
dctx->cctx->libname,rvapad)) < 0)
|
|
|
7f20b2 |
return MDSO_FILE_ERROR(dctx);
|
|
|
efc615 |
|
|
|
c26232 |
if ((mdso_dprintf(fdout,"\t.linkonce discard\n")) < 0)
|
|
|
c26232 |
return MDSO_FILE_ERROR(dctx);
|
|
|
c26232 |
|
|
|
efc615 |
return 0;
|
|
|
efc615 |
}
|