Blame src/logic/mdso_asmgen_symentry.c

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[] = {
c74761
	"\t.section  " MDSO_STRS_SECTION ",\"r0\"\n\n",
ea45e3
	".symstr:\n",
efc615
	"\t.ascii\t\"%s\\0\"\n\n"
efc615
	"\t.section  " MDSO_SYMS_SECTION ",\"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;
efc615
	const char *		ptrsize;
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";
efc615
		ptrsize  = ".quad";
260511
		uscore   = "";
efc615
	} else {
efc615
		alignstr = "\t.balign   8\n\n";
efc615
		ptrsize  = ".long";
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
18a091
	if ((mdso_dprintf(fdout,"\t%s\t.symstr\n",ptrsize)) < 0)
7f20b2
		return MDSO_FILE_ERROR(dctx);
efc615
18a091
	if ((mdso_dprintf(fdout,"\t%s\t.dsometa_%s\n",ptrsize,dctx->cctx->libname)) < 0)
7f20b2
		return MDSO_FILE_ERROR(dctx);
efc615
efc615
	return 0;
efc615
}