Blame src/logic/mdso_asmgen_dsometa.c

f45584
/****************************************************************/
f45584
/*  mdso: midipix dso scavenger                                 */
78ab3c
/*  Copyright (C) 2015--2017  Z. Gilboa                         */
f45584
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
f45584
/****************************************************************/
f45584
f45584
#include <stdint.h>
f45584
#include <stdio.h>
6e477a
f45584
#include <mdso/mdso.h>
f45584
#include <mdso/mdso_specs.h>
18a091
#include "mdso_dprintf_impl.h"
6e477a
#include "mdso_errinfo_impl.h"
f45584
f45584
static const char * const asm_hdr_lines[] = {
22e75c
	"\t.file     \".dsometa_%s.s\"\n",
f45584
f45584
	"\t.section  " MDSO_META_SECTION ",\"r\"\n",
ea45e3
	"\t.globl    .dsometa_%s\n",
f45584
	0
f45584
};
f45584
f45584
static const char * const asm_meta_lines[] = {
a75141
	"\t.long\t0\t\t# priority\n",
a75141
	"\t.long\t0\t\t# nsyms\n",
a75141
	"\t.long\t0\t\t# padding\n",
a75141
	"\t%s\t0\t\t# hashtbl\n",
a75141
	"\t%s\t0\t\t# symtbl\n",
a75141
	"\t%s\t0\t\t# fncarg\n",
a75141
	"\t%s\t0\t\t# fncargarr\n",
a75141
	"\t%s\t0\t\t# fnr1\n",
a75141
	"\t%s\t0\t\t# fnr2\n",
f45584
	0
f45584
};
f45584
99263f
static const char * const asm_libname_fmt =
99263f
	"\n\n"
6d5860
	"\t.section  " MDSO_STRS_SECTION ",\"r0\"\n\n"
a75141
	".libname:\n"
99263f
	"\t.ascii\t\"%s\\0\"\n\n";
99263f
2c190d
int mdso_asmgen_dsometa(
6e477a
	const struct mdso_driver_ctx *	dctx,
18a091
	int				fdout)
f45584
{
f45584
	const char * const *	line;
f45584
	const char *		alignstr;
f45584
	const char *		ptrsize;
f45584
6e477a
	if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) {
f45584
		alignstr = "\t.balign   16\n\n";
f45584
		ptrsize  = ".quad";
f45584
	} else {
f45584
		alignstr = "\t.balign   8\n\n";
f45584
		ptrsize  = ".long";
f45584
	}
f45584
f45584
	for (line=asm_hdr_lines; *line; line++)
18a091
		if ((mdso_dprintf(fdout,*line,dctx->cctx->libname)) < 0)
6e477a
			return MDSO_FILE_ERROR(dctx);
f45584
18a091
	if (mdso_dprintf(fdout,alignstr) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
18a091
	if ((mdso_dprintf(fdout,".dsometa_%s:\n",dctx->cctx->libname)) < 0)
643252
		return MDSO_FILE_ERROR(dctx);
643252
18a091
	if ((mdso_dprintf(fdout,"\t%s\t%d\t\t# base\n",ptrsize,0)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
18a091
	if ((mdso_dprintf(fdout,"\t%s\t%s\t# name\n",ptrsize,".libname")) < 0)
99263f
		return MDSO_FILE_ERROR(dctx);
99263f
18a091
	if ((mdso_dprintf(fdout,"\t%s\t%u\t\t# flags\n",".long",dctx->cctx->dsoflags)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
f45584
	for (line=asm_meta_lines; *line; line++)
18a091
		if ((mdso_dprintf(fdout,*line,ptrsize)) < 0)
6e477a
			return MDSO_FILE_ERROR(dctx);
f45584
18a091
	if (mdso_dprintf(fdout,asm_libname_fmt,dctx->cctx->libname) < 0)
99263f
		return MDSO_FILE_ERROR(dctx);
99263f
f45584
	return 0;
f45584
}