aarch64-cloudabi64.c revision 294849
1254721Semaste/*-
2254721Semaste * Copyright (c) 2015 Nuxi, https://nuxi.nl/
3254721Semaste *
4254721Semaste * Redistribution and use in source and binary forms, with or without
5254721Semaste * modification, are permitted provided that the following conditions
6254721Semaste * are met:
7254721Semaste * 1. Redistributions of source code must retain the above copyright
8254721Semaste *    notice, this list of conditions and the following disclaimer.
9254721Semaste * 2. Redistributions in binary form must reproduce the above copyright
10254721Semaste *    notice, this list of conditions and the following disclaimer in the
11254721Semaste *    documentation and/or other materials provided with the distribution.
12254721Semaste *
13254721Semaste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14254721Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16254721Semaste * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17254721Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18254721Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19254721Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20254721Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21254721Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22269024Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23254721Semaste * SUCH DAMAGE.
24254721Semaste */
25254721Semaste
26254721Semaste#include <sys/cdefs.h>
27254721Semaste__FBSDID("$FreeBSD: head/usr.bin/truss/aarch64-cloudabi64.c 294849 2016-01-26 19:07:09Z jhb $");
28254721Semaste
29254721Semaste#include <sys/param.h>
30254721Semaste#include <sys/ptrace.h>
31254721Semaste
32254721Semaste#include <machine/armreg.h>
33254721Semaste
34254721Semaste#include <errno.h>
35254721Semaste#include <stdio.h>
36254721Semaste#include <sysdecode.h>
37254721Semaste
38254721Semaste#include "cloudabi.h"
39254721Semaste#include "truss.h"
40254721Semaste
41254721Semastestatic int
42254721Semasteaarch64_cloudabi64_fetch_args(struct trussinfo *trussinfo, unsigned int narg)
43254721Semaste{
44254721Semaste	struct current_syscall *cs;
45254721Semaste	struct reg regs;
46254721Semaste	lwpid_t tid;
47254721Semaste	unsigned int i;
48254721Semaste
49254721Semaste	tid = trussinfo->curthread->tid;
50254721Semaste	if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
51254721Semaste		fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
52254721Semaste		return (-1);
53254721Semaste	}
54254721Semaste
55254721Semaste	cs = &trussinfo->curthread->cs;
56254721Semaste	for (i = 0; i < narg && i < 8; i++)
57254721Semaste		cs->args[i] = regs.x[i];
58254721Semaste	return (0);
59254721Semaste}
60254721Semaste
61254721Semastestatic int
62254721Semasteaarch64_cloudabi64_fetch_retval(struct trussinfo *trussinfo, long *retval,
63254721Semaste    int *errorp)
64254721Semaste{
65254721Semaste	struct reg regs;
66254721Semaste	lwpid_t tid;
67254721Semaste
68254721Semaste	tid = trussinfo->curthread->tid;
69254721Semaste	if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) == -1) {
70254721Semaste		fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
71254721Semaste		return (-1);
72254721Semaste	}
73254721Semaste
74254721Semaste	retval[0] = regs.x[0];
75254721Semaste	retval[1] = regs.x[1];
76254721Semaste	*errorp = (regs.spsr & PSR_C) != 0;
77254721Semaste	if (*errorp)
78254721Semaste		retval[0] = cloudabi_convert_errno(retval[0]);
79254721Semaste	return (0);
80254721Semaste}
81254721Semaste
82254721Semastestatic struct procabi aarch64_cloudabi64 = {
83254721Semaste	"CloudABI ELF64",
84254721Semaste	CLOUDABI64,
85254721Semaste	aarch64_cloudabi64_fetch_args,
86254721Semaste	aarch64_cloudabi64_fetch_retval
87254721Semaste};
88254721Semaste
89254721SemastePROCABI(aarch64_cloudabi64);
90254721Semaste