Commit 1d718164 authored by Russ Cox's avatar Russ Cox

cmd/prof, libmach: delete

We have never released cmd/prof and don't plan to.
Now that nm, addr2line, and objdump have been rewritten in Go,
cmd/prof is the only thing keeping us from deleting libmach.

Delete cmd/prof, and then since nothing is using libmach, delete libmach.

13,000 lines of C deleted.

LGTM=minux.ma
R=golang-codereviews, minux.ma
CC=golang-codereviews, iant, r
https://golang.org/cl/87020044
parent a8d90ec3
// Inferno libmach/bootexec.h
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/bootexec.h
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
struct coffsect
{
char name[8];
uint32 phys;
uint32 virt;
uint32 size;
uint32 fptr;
uint32 fptrreloc;
uint32 fptrlineno;
uint32 nrelocnlineno;
uint32 flags;
};
/*
* proprietary exec headers, needed to bootstrap various machines
*/
struct mipsexec
{
short mmagic; /* (0x160) mips magic number */
short nscns; /* (unused) number of sections */
int32 timdat; /* (unused) time & date stamp */
int32 symptr; /* offset to symbol table */
int32 nsyms; /* size of symbol table */
short opthdr; /* (0x38) sizeof(optional hdr) */
short pcszs; /* flags */
short amagic; /* see above */
short vstamp; /* version stamp */
int32 tsize; /* text size in bytes */
int32 dsize; /* initialized data */
int32 bsize; /* uninitialized data */
int32 mentry; /* entry pt. */
int32 text_start; /* base of text used for this file */
int32 data_start; /* base of data used for this file */
int32 bss_start; /* base of bss used for this file */
int32 gprmask; /* general purpose register mask */
union{
int32 cprmask[4]; /* co-processor register masks */
int32 pcsize;
};
int32 gp_value; /* the gp value used for this object */
};
struct mips4kexec
{
struct mipsexec h;
struct coffsect itexts;
struct coffsect idatas;
struct coffsect ibsss;
};
struct sparcexec
{
short sjunk; /* dynamic bit and version number */
short smagic; /* 0407 */
uint32 stext;
uint32 sdata;
uint32 sbss;
uint32 ssyms;
uint32 sentry;
uint32 strsize;
uint32 sdrsize;
};
struct nextexec
{
/* UNUSED
struct nexthdr{
uint32 nmagic;
uint32 ncputype;
uint32 ncpusubtype;
uint32 nfiletype;
uint32 ncmds;
uint32 nsizeofcmds;
uint32 nflags;
};
struct nextcmd{
uint32 cmd;
uint32 cmdsize;
uchar segname[16];
uint32 vmaddr;
uint32 vmsize;
uint32 fileoff;
uint32 filesize;
uint32 maxprot;
uint32 initprot;
uint32 nsects;
uint32 flags;
}textc;
struct nextsect{
char sectname[16];
char segname[16];
uint32 addr;
uint32 size;
uint32 offset;
uint32 align;
uint32 reloff;
uint32 nreloc;
uint32 flags;
uint32 reserved1;
uint32 reserved2;
}texts;
struct nextcmd datac;
struct nextsect datas;
struct nextsect bsss;
struct nextsym{
uint32 cmd;
uint32 cmdsize;
uint32 symoff;
uint32 nsyms;
uint32 spoff;
uint32 pcoff;
}symc;
*/
};
struct i386exec
{
/* UNUSED
struct i386coff{
uint32 isectmagic;
uint32 itime;
uint32 isyms;
uint32 insyms;
uint32 iflags;
};
struct i386hdr{
uint32 imagic;
uint32 itextsize;
uint32 idatasize;
uint32 ibsssize;
uint32 ientry;
uint32 itextstart;
uint32 idatastart;
};
struct coffsect itexts;
struct coffsect idatas;
struct coffsect ibsss;
struct coffsect icomments;
*/
};
This diff is collapsed.
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "../mach.h"
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "../ureg_amd64.h"
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "../ureg_arm.h"
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "../ureg_x86.h"
// Inferno utils/libmach/ureg6.h
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/ureg6.h
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
typedef struct UregAmd64 UregAmd64;
struct UregAmd64 {
u64int ax;
u64int bx;
u64int cx;
u64int dx;
u64int si;
u64int di;
u64int bp;
u64int r8;
u64int r9;
u64int r10;
u64int r11;
u64int r12;
u64int r13;
u64int r14;
u64int r15;
u16int ds;
u16int es;
u16int fs;
u16int gs;
u64int type;
u64int error; /* error code (or zero) */
u64int ip; /* pc */
u64int cs; /* old context */
u64int flags; /* old flags */
u64int sp; /* sp */
u64int ss; /* old stack segment */
};
// Inferno utils/libmach/ureg5.h
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/ureg5.h
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
typedef struct UregArm UregArm;
struct UregArm {
uint r0;
uint r1;
uint r2;
uint r3;
uint r4;
uint r5;
uint r6;
uint r7;
uint r8;
uint r9;
uint r10;
uint r11;
uint r12;
uint r13;
uint r14;
uint link;
uint type;
uint psr;
uint pc;
};
// Inferno utils/libmach/ureg8.h
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/ureg8.h
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
typedef struct Ureg386 Ureg386;
struct Ureg386
{
uint32 di; /* general registers */
uint32 si; /* ... */
uint32 bp; /* ... */
uint32 nsp;
uint32 bx; /* ... */
uint32 dx; /* ... */
uint32 cx; /* ... */
uint32 ax; /* ... */
uint32 gs; /* data segments */
uint32 fs; /* ... */
uint32 es; /* ... */
uint32 ds; /* ... */
uint32 trap; /* trap type */
uint32 ecode; /* error code (or zero) */
uint32 pc; /* pc */
uint32 cs; /* old context */
uint32 flags; /* old flags */
union {
uint32 usp;
uint32 sp;
};
uint32 ss; /* old stack segment */
};
......@@ -373,7 +373,6 @@ static char *oldtool[] = {
// Unreleased directories (relative to $GOROOT) that should
// not be in release branches.
static char *unreleased[] = {
"src/cmd/prof",
"src/pkg/old",
};
......@@ -517,19 +516,6 @@ static struct {
"$GOROOT/include/libc.h",
"$GOROOT/include/bio.h",
}},
{"libmach", {
"$GOROOT/include/u.h",
"$GOROOT/include/utf.h",
"$GOROOT/include/fmt.h",
"$GOROOT/include/libc.h",
"$GOROOT/include/bio.h",
"$GOROOT/include/ar.h",
"$GOROOT/include/bootexec.h",
"$GOROOT/include/mach.h",
"$GOROOT/include/ureg_amd64.h",
"$GOROOT/include/ureg_arm.h",
"$GOROOT/include/ureg_x86.h",
}},
{"liblink", {
"$GOROOT/include/u.h",
"$GOROOT/include/utf.h",
......@@ -607,7 +593,6 @@ static struct {
}},
{"cmd/", {
"$GOROOT/pkg/obj/$GOOS_$GOARCH/liblink.a",
"$GOROOT/pkg/obj/$GOOS_$GOARCH/libmach.a",
"$GOROOT/pkg/obj/$GOOS_$GOARCH/libbio.a",
"$GOROOT/pkg/obj/$GOOS_$GOARCH/lib9.a",
}},
......@@ -696,13 +681,6 @@ install(char *dir)
goto out;
}
// For release, cmd/prof is not included.
if((streq(dir, "cmd/prof")) && !isdir(bstr(&path))) {
if(vflag > 1)
errprintf("skipping %s - does not exist\n", dir);
goto out;
}
// set up gcc command line on first run.
if(gccargs.len == 0) {
bprintf(&b, "%s %s", defaultcc, defaultcflags);
......@@ -1327,13 +1305,10 @@ dopack(char *dst, char *src, char **extra, int nextra)
static char *buildorder[] = {
"lib9",
"libbio",
"libmach",
"liblink",
"misc/pprof",
"cmd/prof",
"cmd/cc", // must be before c
"cmd/gc", // must be before g
"cmd/%sl", // must be before a, c, g
......@@ -1408,10 +1383,8 @@ static char *cleantab[] = {
"cmd/cc",
"cmd/gc",
"cmd/go",
"cmd/prof",
"lib9",
"libbio",
"libmach",
"liblink",
"pkg/bufio",
"pkg/bytes",
......@@ -1467,8 +1440,6 @@ clean(void)
vinit(&dir);
for(i=0; i<nelem(cleantab); i++) {
if((streq(cleantab[i], "cmd/prof")) && !isdir(cleantab[i]))
continue;
bpathf(&path, "%s/src/%s", goroot, cleantab[i]);
xreaddir(&dir, bstr(&path));
// Remove generated files.
......
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../Make.dist
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
/*
Prof is a rudimentary real-time profiler.
Given a command to run or the process id (pid) of a command already
running, it samples the program's state at regular intervals and reports
on its behavior. With no options, it prints a histogram of the locations
in the code that were sampled during execution.
Since it is a real-time profiler, unlike a traditional profiler it samples
the program's state even when it is not running, such as when it is
asleep or waiting for I/O. Each thread contributes equally to the
statistics.
Usage:
go tool prof -p pid [-t total_secs] [-d delta_msec] [6.out args ...]
The output modes (default -h) are:
-P file.prof:
Write the profile information to file.prof, in the format used by pprof.
At the moment, this only works on Linux amd64 binaries and requires that the
binary be written using 6l -e to produce ELF debug info.
See http://code.google.com/p/google-perftools for details.
-h: histograms
How many times a sample occurred at each location.
-f: dynamic functions
At each sample period, print the name of the executing function.
-l: dynamic file and line numbers
At each sample period, print the file and line number of the executing instruction.
-r: dynamic registers
At each sample period, print the register contents.
-s: dynamic function stack traces
At each sample period, print the symbolic stack trace.
Flag -t sets the maximum real time to sample, in seconds, and -d
sets the sampling interval in milliseconds. The default is to sample
every 100ms until the program completes.
It is installed as go tool prof and is architecture-independent.
*/
package main
This diff is collapsed.
// Inferno libmach/5.c
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/5.c
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
* arm definition
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "ureg_arm.h"
#include <mach.h>
#define REGOFF(x) (uintptr) (&((struct UregArm *) 0)->x)
#define SP REGOFF(r13)
#define PC REGOFF(pc)
#define REGSIZE sizeof(struct UregArm)
Reglist armreglist[] =
{
{"LINK", REGOFF(link), RINT|RRDONLY, 'X'},
{"TYPE", REGOFF(type), RINT|RRDONLY, 'X'},
{"PSR", REGOFF(psr), RINT|RRDONLY, 'X'},
{"PC", PC, RINT, 'X'},
{"SP", SP, RINT, 'X'},
{"R15", PC, RINT, 'X'},
{"R14", REGOFF(r14), RINT, 'X'},
{"R13", REGOFF(r13), RINT, 'X'},
{"R12", REGOFF(r12), RINT, 'X'},
{"R11", REGOFF(r11), RINT, 'X'},
{"R10", REGOFF(r10), RINT, 'X'},
{"R9", REGOFF(r9), RINT, 'X'},
{"R8", REGOFF(r8), RINT, 'X'},
{"R7", REGOFF(r7), RINT, 'X'},
{"R6", REGOFF(r6), RINT, 'X'},
{"R5", REGOFF(r5), RINT, 'X'},
{"R4", REGOFF(r4), RINT, 'X'},
{"R3", REGOFF(r3), RINT, 'X'},
{"R2", REGOFF(r2), RINT, 'X'},
{"R1", REGOFF(r1), RINT, 'X'},
{"R0", REGOFF(r0), RINT, 'X'},
{ 0 }
};
/* the machine description */
Mach marm =
{
"arm",
MARM, /* machine type */
armreglist, /* register set */
REGSIZE, /* register set size */
0, /* fp register set size */
"PC", /* name of PC */
"SP", /* name of SP */
"R15", /* name of link register */
"setR12", /* static base register name */
0, /* static base register value */
0x1000, /* page size */
0xC0000000, /* kernel base */
0, /* kernel text mask */
4, /* quantization of pc */
4, /* szaddr */
4, /* szreg */
4, /* szfloat */
8, /* szdouble */
};
This diff is collapsed.
// Inferno libmach/6.c
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/6.c
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
* amd64 definition
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "ureg_amd64.h"
#include <mach.h>
#define REGOFF(x) offsetof(struct UregAmd64, x)
#define REGSIZE sizeof(struct UregAmd64)
#define FP_CTLS(x) (REGSIZE+2*(x))
#define FP_CTL(x) (REGSIZE+4*(x))
#define FP_REG(x) (FP_CTL(8)+16*(x))
#define XM_REG(x) (FP_CTL(8)+8*16+16*(x))
#define FPREGSIZE 512 /* TO DO? currently only 0x1A0 used */
Reglist amd64reglist[] = {
{"AX", REGOFF(ax), RINT, 'Y'},
{"BX", REGOFF(bx), RINT, 'Y'},
{"CX", REGOFF(cx), RINT, 'Y'},
{"DX", REGOFF(dx), RINT, 'Y'},
{"SI", REGOFF(si), RINT, 'Y'},
{"DI", REGOFF(di), RINT, 'Y'},
{"BP", REGOFF(bp), RINT, 'Y'},
{"R8", REGOFF(r8), RINT, 'Y'},
{"R9", REGOFF(r9), RINT, 'Y'},
{"R10", REGOFF(r10), RINT, 'Y'},
{"R11", REGOFF(r11), RINT, 'Y'},
{"R12", REGOFF(r12), RINT, 'Y'},
{"R13", REGOFF(r13), RINT, 'Y'},
{"R14", REGOFF(r14), RINT, 'Y'},
{"R15", REGOFF(r15), RINT, 'Y'},
{"DS", REGOFF(ds), RINT, 'x'},
{"ES", REGOFF(es), RINT, 'x'},
{"FS", REGOFF(fs), RINT, 'x'},
{"GS", REGOFF(gs), RINT, 'x'},
{"TYPE", REGOFF(type), RINT, 'Y'},
{"TRAP", REGOFF(type), RINT, 'Y'}, /* alias for acid */
{"ERROR", REGOFF(error), RINT, 'Y'},
{"IP", REGOFF(ip), RINT, 'Y'},
{"PC", REGOFF(ip), RINT, 'Y'}, /* alias for acid */
{"CS", REGOFF(cs), RINT, 'Y'},
{"FLAGS", REGOFF(flags), RINT, 'Y'},
{"SP", REGOFF(sp), RINT, 'Y'},
{"SS", REGOFF(ss), RINT, 'Y'},
{"FCW", FP_CTLS(0), RFLT, 'x'},
{"FSW", FP_CTLS(1), RFLT, 'x'},
{"FTW", FP_CTLS(2), RFLT, 'b'},
{"FOP", FP_CTLS(3), RFLT, 'x'},
{"RIP", FP_CTL(2), RFLT, 'Y'},
{"RDP", FP_CTL(4), RFLT, 'Y'},
{"MXCSR", FP_CTL(6), RFLT, 'X'},
{"MXCSRMASK", FP_CTL(7), RFLT, 'X'},
{"M0", FP_REG(0), RFLT, 'F'}, /* assumes double */
{"M1", FP_REG(1), RFLT, 'F'},
{"M2", FP_REG(2), RFLT, 'F'},
{"M3", FP_REG(3), RFLT, 'F'},
{"M4", FP_REG(4), RFLT, 'F'},
{"M5", FP_REG(5), RFLT, 'F'},
{"M6", FP_REG(6), RFLT, 'F'},
{"M7", FP_REG(7), RFLT, 'F'},
{"X0", XM_REG(0), RFLT, 'F'}, /* assumes double */
{"X1", XM_REG(1), RFLT, 'F'},
{"X2", XM_REG(2), RFLT, 'F'},
{"X3", XM_REG(3), RFLT, 'F'},
{"X4", XM_REG(4), RFLT, 'F'},
{"X5", XM_REG(5), RFLT, 'F'},
{"X6", XM_REG(6), RFLT, 'F'},
{"X7", XM_REG(7), RFLT, 'F'},
{"X8", XM_REG(8), RFLT, 'F'},
{"X9", XM_REG(9), RFLT, 'F'},
{"X10", XM_REG(10), RFLT, 'F'},
{"X11", XM_REG(11), RFLT, 'F'},
{"X12", XM_REG(12), RFLT, 'F'},
{"X13", XM_REG(13), RFLT, 'F'},
{"X14", XM_REG(14), RFLT, 'F'},
{"X15", XM_REG(15), RFLT, 'F'},
{"X16", XM_REG(16), RFLT, 'F'},
/*
{"F0", FP_REG(7), RFLT, '3'},
{"F1", FP_REG(6), RFLT, '3'},
{"F2", FP_REG(5), RFLT, '3'},
{"F3", FP_REG(4), RFLT, '3'},
{"F4", FP_REG(3), RFLT, '3'},
{"F5", FP_REG(2), RFLT, '3'},
{"F6", FP_REG(1), RFLT, '3'},
{"F7", FP_REG(0), RFLT, '3'},
*/
{ 0 }
};
Mach mamd64=
{
"amd64",
MAMD64, /* machine type */
amd64reglist, /* register list */
REGSIZE, /* size of registers in bytes */
FPREGSIZE, /* size of fp registers in bytes */
"PC", /* name of PC */
"SP", /* name of SP */
0, /* link register */
"setSB", /* static base register name (bogus anyways) */
0, /* static base register value */
0x1000, /* page size */
0xFFFFFFFF80110000ULL, /* kernel base */
0xFFFF800000000000ULL, /* kernel text mask */
0x00007FFFFFFFF000ULL, /* user stack top */
1, /* quantization of pc */
8, /* szaddr */
4, /* szreg */
4, /* szfloat */
8, /* szdouble */
};
// Inferno libmach/8.c
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/8.c
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
* 386 definition
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ureg_x86.h>
#include <mach.h>
#define REGOFF(x) (uintptr)(&((struct Ureg386 *) 0)->x)
#define PC REGOFF(pc)
#define SP REGOFF(sp)
#define AX REGOFF(ax)
#define REGSIZE sizeof(struct Ureg386)
#define FP_CTL(x) (REGSIZE+4*(x))
#define FP_REG(x) (FP_CTL(7)+10*(x))
#define FPREGSIZE (7*4+8*10)
Reglist i386reglist[] = {
{"DI", REGOFF(di), RINT, 'X'},
{"SI", REGOFF(si), RINT, 'X'},
{"BP", REGOFF(bp), RINT, 'X'},
{"BX", REGOFF(bx), RINT, 'X'},
{"DX", REGOFF(dx), RINT, 'X'},
{"CX", REGOFF(cx), RINT, 'X'},
{"AX", REGOFF(ax), RINT, 'X'},
{"GS", REGOFF(gs), RINT, 'X'},
{"FS", REGOFF(fs), RINT, 'X'},
{"ES", REGOFF(es), RINT, 'X'},
{"DS", REGOFF(ds), RINT, 'X'},
{"TRAP", REGOFF(trap), RINT, 'X'},
{"ECODE", REGOFF(ecode), RINT, 'X'},
{"PC", PC, RINT, 'X'},
{"CS", REGOFF(cs), RINT, 'X'},
{"EFLAGS", REGOFF(flags), RINT, 'X'},
{"SP", SP, RINT, 'X'},
{"SS", REGOFF(ss), RINT, 'X'},
{"E0", FP_CTL(0), RFLT, 'X'},
{"E1", FP_CTL(1), RFLT, 'X'},
{"E2", FP_CTL(2), RFLT, 'X'},
{"E3", FP_CTL(3), RFLT, 'X'},
{"E4", FP_CTL(4), RFLT, 'X'},
{"E5", FP_CTL(5), RFLT, 'X'},
{"E6", FP_CTL(6), RFLT, 'X'},
{"F0", FP_REG(0), RFLT, '3'},
{"F1", FP_REG(1), RFLT, '3'},
{"F2", FP_REG(2), RFLT, '3'},
{"F3", FP_REG(3), RFLT, '3'},
{"F4", FP_REG(4), RFLT, '3'},
{"F5", FP_REG(5), RFLT, '3'},
{"F6", FP_REG(6), RFLT, '3'},
{"F7", FP_REG(7), RFLT, '3'},
{ 0 }
};
Mach mi386 =
{
"386",
MI386, /* machine type */
i386reglist, /* register list */
REGSIZE, /* size of registers in bytes */
FPREGSIZE, /* size of fp registers in bytes */
"PC", /* name of PC */
"SP", /* name of SP */
0, /* link register */
"setSB", /* static base register name (bogus anyways) */
0, /* static base register value */
0x1000, /* page size */
0x80100000ULL, /* kernel base */
0xF0000000ULL, /* kernel text mask */
0xFFFFFFFFULL, /* user stack top */
1, /* quantization of pc */
4, /* szaddr */
4, /* szreg */
4, /* szfloat */
8, /* szdouble */
};
This diff is collapsed.
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../Make.dist
// Inferno libmach/access.c
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/access.c
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
* functions to read and write an executable or file image
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <mach.h>
static int mget(Map*, uvlong, void*, int);
static int mput(Map*, uvlong, void*, int);
static Seg* reloc(Map*, uvlong, vlong*);
/*
* routines to get/put various types
*/
int
geta(Map *map, uvlong addr, uvlong *x)
{
uint32 l;
uvlong vl;
if (mach->szaddr == 8){
if (get8(map, addr, &vl) < 0)
return -1;
*x = vl;
return 1;
}
if (get4(map, addr, &l) < 0)
return -1;
*x = l;
return 1;
}
int
get8(Map *map, uvlong addr, uvlong *x)
{
if (!map) {
werrstr("get8: invalid map");
return -1;
}
if (map->nsegs == 1 && map->seg[0].fd < 0) {
*x = addr;
return 1;
}
if (mget(map, addr, x, 8) < 0)
return -1;
*x = machdata->swav(*x);
return 1;
}
int
get4(Map *map, uvlong addr, uint32 *x)
{
if (!map) {
werrstr("get4: invalid map");
return -1;
}
if (map->nsegs == 1 && map->seg[0].fd < 0) {
*x = addr;
return 1;
}
if (mget(map, addr, x, 4) < 0)
return -1;
*x = machdata->swal(*x);
return 1;
}
int
get2(Map *map, uvlong addr, ushort *x)
{
if (!map) {
werrstr("get2: invalid map");
return -1;
}
if (map->nsegs == 1 && map->seg[0].fd < 0) {
*x = addr;
return 1;
}
if (mget(map, addr, x, 2) < 0)
return -1;
*x = machdata->swab(*x);
return 1;
}
int
get1(Map *map, uvlong addr, uchar *x, int size)
{
uchar *cp;
if (!map) {
werrstr("get1: invalid map");
return -1;
}
if (map->nsegs == 1 && map->seg[0].fd < 0) {
cp = (uchar*)&addr;
while (cp < (uchar*)(&addr+1) && size-- > 0)
*x++ = *cp++;
while (size-- > 0)
*x++ = 0;
} else
return mget(map, addr, x, size);
return 1;
}
int
puta(Map *map, uvlong addr, uvlong v)
{
if (mach->szaddr == 8)
return put8(map, addr, v);
return put4(map, addr, v);
}
int
put8(Map *map, uvlong addr, uvlong v)
{
if (!map) {
werrstr("put8: invalid map");
return -1;
}
v = machdata->swav(v);
return mput(map, addr, &v, 8);
}
int
put4(Map *map, uvlong addr, uint32 v)
{
if (!map) {
werrstr("put4: invalid map");
return -1;
}
v = machdata->swal(v);
return mput(map, addr, &v, 4);
}
int
put2(Map *map, uvlong addr, ushort v)
{
if (!map) {
werrstr("put2: invalid map");
return -1;
}
v = machdata->swab(v);
return mput(map, addr, &v, 2);
}
int
put1(Map *map, uvlong addr, uchar *v, int size)
{
if (!map) {
werrstr("put1: invalid map");
return -1;
}
return mput(map, addr, v, size);
}
static int
mget(Map *map, uvlong addr, void *buf, int size)
{
uvlong off;
Seg *s;
s = reloc(map, addr, (vlong*)&off);
if (!s)
return -1;
if (s->rw == nil) {
werrstr("unreadable map");
return -1;
}
return s->rw(map, s, off, buf, size, 1);
}
static int
mput(Map *map, uvlong addr, void *buf, int size)
{
vlong off;
Seg *s;
s = reloc(map, addr, &off);
if (!s)
return -1;
if (s->rw == nil) {
werrstr("unwritable map");
return -1;
}
return s->rw(map, s, off, buf, size, 0);
}
/*
* convert address to file offset; returns nonzero if ok
*/
static Seg*
reloc(Map *map, uvlong addr, vlong *offp)
{
int i;
for (i = 0; i < map->nsegs; i++) {
if (map->seg[i].inuse)
if (map->seg[i].b <= addr && addr < map->seg[i].e) {
*offp = addr + map->seg[i].f - map->seg[i].b;
return &map->seg[i];
}
}
werrstr("can't translate address %llux", addr);
return 0;
}
This diff is collapsed.
// This is stubbed out for the moment. Will revisit when the time comes.
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <mach.h>
int
ctlproc(int pid, char *msg)
{
USED(pid);
USED(msg);
sysfatal("ctlproc unimplemented in DragonFly");
return -1;
}
char*
proctextfile(int pid)
{
USED(pid);
sysfatal("proctextfile unimplemented in DragonFly");
return nil;
}
char*
procstatus(int pid)
{
USED(pid);
sysfatal("procstatus unimplemented in DragonFly");
return nil;
}
Map*
attachproc(int pid, Fhdr *fp)
{
USED(pid);
USED(fp);
sysfatal("attachproc unimplemented in DragonFly");
return nil;
}
void
detachproc(Map *m)
{
USED(m);
sysfatal("detachproc unimplemented in DragonFly");
}
int
procthreadpids(int pid, int *p, int np)
{
USED(pid);
USED(p);
USED(np);
sysfatal("procthreadpids unimplemented in DragonFly");
return -1;
}
// Inferno libmach/elf.h
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/elf.h
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
* Definitions needed for accessing ELF headers.
* 32-bit and 64-bit structs differ.
*/
typedef struct {
uchar ident[16]; /* ident bytes */
ushort type; /* file type */
ushort machine; /* target machine */
int version; /* file version */
uint32 elfentry; /* start address */
uint32 phoff; /* phdr file offset */
uint32 shoff; /* shdr file offset */
int flags; /* file flags */
ushort ehsize; /* sizeof ehdr */
ushort phentsize; /* sizeof phdr */
ushort phnum; /* number phdrs */
ushort shentsize; /* sizeof shdr */
ushort shnum; /* number shdrs */
ushort shstrndx; /* shdr string index */
} Ehdr32;
typedef struct {
uchar ident[16]; /* ident bytes */
ushort type; /* file type */
ushort machine; /* target machine */
int version; /* file version */
uvlong elfentry; /* start address */
uvlong phoff; /* phdr file offset */
uvlong shoff; /* shdr file offset */
int flags; /* file flags */
ushort ehsize; /* sizeof ehdr */
ushort phentsize; /* sizeof phdr */
ushort phnum; /* number phdrs */
ushort shentsize; /* sizeof shdr */
ushort shnum; /* number shdrs */
ushort shstrndx; /* shdr string index */
} Ehdr64;
typedef struct {
int type; /* entry type */
uint32 offset; /* file offset */
uint32 vaddr; /* virtual address */
uint32 paddr; /* physical address */
int filesz; /* file size */
uint32 memsz; /* memory size */
int flags; /* entry flags */
int align; /* memory/file alignment */
} Phdr32;
typedef struct {
int type; /* entry type */
int flags; /* entry flags */
uvlong offset; /* file offset */
uvlong vaddr; /* virtual address */
uvlong paddr; /* physical address */
uvlong filesz; /* file size */
uvlong memsz; /* memory size */
uvlong align; /* memory/file alignment */
} Phdr64;
typedef struct {
uint32 name; /* section name */
uint32 type; /* SHT_... */
uint32 flags; /* SHF_... */
uint32 addr; /* virtual address */
uint32 offset; /* file offset */
uint32 size; /* section size */
uint32 link; /* misc info */
uint32 info; /* misc info */
uint32 addralign; /* memory alignment */
uint32 entsize; /* entry size if table */
} Shdr32;
typedef struct {
uint32 name; /* section name */
uint32 type; /* SHT_... */
uvlong flags; /* SHF_... */
uvlong addr; /* virtual address */
uvlong offset; /* file offset */
uvlong size; /* section size */
uint32 link; /* misc info */
uint32 info; /* misc info */
uvlong addralign; /* memory alignment */
uvlong entsize; /* entry size if table */
} Shdr64;
enum {
/* Ehdr codes */
MAG0 = 0, /* ident[] indexes */
MAG1 = 1,
MAG2 = 2,
MAG3 = 3,
CLASS = 4,
DATA = 5,
VERSION = 6,
ELFCLASSNONE = 0, /* ident[CLASS] */
ELFCLASS32 = 1,
ELFCLASS64 = 2,
ELFCLASSNUM = 3,
ELFDATANONE = 0, /* ident[DATA] */
ELFDATA2LSB = 1,
ELFDATA2MSB = 2,
ELFDATANUM = 3,
NOETYPE = 0, /* type */
REL = 1,
EXEC = 2,
DYN = 3,
CORE = 4,
NONE = 0, /* machine */
M32 = 1, /* AT&T WE 32100 */
SPARC = 2, /* Sun SPARC */
I386 = 3, /* Intel 80386 */
M68K = 4, /* Motorola 68000 */
M88K = 5, /* Motorola 88000 */
I486 = 6, /* Intel 80486 */
I860 = 7, /* Intel i860 */
MIPS = 8, /* Mips R2000 */
S370 = 9, /* Amdhal */
SPARC64 = 18, /* Sun SPARC v9 */
POWER = 20, /* PowerPC */
ARM = 40, /* ARM */
AMD64 = 62, /* Amd64 */
NO_VERSION = 0, /* version, ident[VERSION] */
CURRENT = 1,
/* Phdr Codes */
NOPTYPE = 0, /* type */
LOAD = 1,
DYNAMIC = 2,
INTERP = 3,
NOTE = 4,
SHLIB = 5,
PHDR = 6,
R = 0x4, /* flags */
W = 0x2,
X = 0x1,
/* Shdr Codes */
Progbits = 1, /* section types */
Strtab = 3,
Nobits = 8,
Swrite = 1, /* section attributes */
Salloc = 2,
Sexec = 4,
};
#define ELF_MAG ((0x7f<<24) | ('E'<<16) | ('L'<<8) | 'F')
This diff is collapsed.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
* obj.c
* routines universal to all object files
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ar.h>
#include <mach.h>
#include "obj.h"
int _is2(char* x) { USED(x); return 0; }
int _is7(char* x) { USED(x); return 0; }
int _is9(char* x) { USED(x); return 0; }
int _isk(char* x) { USED(x); return 0; }
int _isq(char* x) { USED(x); return 0; }
int _isv(char* x) { USED(x); return 0; }
int _isu(char* x) { USED(x); return 0; }
int _read2(Biobuf* b, Prog* p) { USED(b); USED(p); return 0; }
int _read7(Biobuf* b, Prog* p) { USED(b); USED(p); return 0; }
int _read9(Biobuf* b, Prog* p) { USED(b); USED(p); return 0; }
int _readk(Biobuf* b, Prog* p) { USED(b); USED(p); return 0; }
int _readq(Biobuf* b, Prog* p) { USED(b); USED(p); return 0; }
int _readv(Biobuf* b, Prog* p) { USED(b); USED(p); return 0; }
int _readu(Biobuf* b, Prog* p) { USED(b); USED(p); return 0; }
// This is stubbed out for the moment. Will revisit when the time comes.
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <mach.h>
int
ctlproc(int pid, char *msg)
{
USED(pid);
USED(msg);
sysfatal("ctlproc unimplemented in FreeBSD");
return -1;
}
char*
proctextfile(int pid)
{
USED(pid);
sysfatal("proctextfile unimplemented in FreeBSD");
return nil;
}
char*
procstatus(int pid)
{
USED(pid);
sysfatal("procstatus unimplemented in FreeBSD");
return nil;
}
Map*
attachproc(int pid, Fhdr *fp)
{
USED(pid);
USED(fp);
sysfatal("attachproc unimplemented in FreeBSD");
return nil;
}
void
detachproc(Map *m)
{
USED(m);
sysfatal("detachproc unimplemented in FreeBSD");
}
int
procthreadpids(int pid, int *p, int np)
{
USED(pid);
USED(p);
USED(np);
sysfatal("procthreadpids unimplemented in FreeBSD");
return -1;
}
This diff is collapsed.
This diff is collapsed.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
* Definitions needed for accessing MACH object headers.
*/
typedef struct {
uint32 magic; /* mach magic number identifier */
uint32 cputype; /* cpu specifier */
uint32 cpusubtype; /* machine specifier */
uint32 filetype; /* type of file */
uint32 ncmds; /* number of load commands */
uint32 sizeofcmds; /* the size of all the load commands */
uint32 flags; /* flags */
uint32 reserved; /* reserved */
} Machhdr;
typedef struct {
uint32 type; /* type of load command */
uint32 size; /* total size in bytes */
} MachCmd;
typedef struct {
MachCmd cmd;
char segname[16]; /* segment name */
uint32 vmaddr; /* memory address of this segment */
uint32 vmsize; /* memory size of this segment */
uint32 fileoff; /* file offset of this segment */
uint32 filesize; /* amount to map from the file */
uint32 maxprot; /* maximum VM protection */
uint32 initprot; /* initial VM protection */
uint32 nsects; /* number of sections in segment */
uint32 flags; /* flags */
} MachSeg32; /* for 32-bit architectures */
typedef struct {
MachCmd cmd;
char segname[16]; /* segment name */
uvlong vmaddr; /* memory address of this segment */
uvlong vmsize; /* memory size of this segment */
uvlong fileoff; /* file offset of this segment */
uvlong filesize; /* amount to map from the file */
uint32 maxprot; /* maximum VM protection */
uint32 initprot; /* initial VM protection */
uint32 nsects; /* number of sections in segment */
uint32 flags; /* flags */
} MachSeg64; /* for 64-bit architectures */
typedef struct {
MachCmd cmd;
uint32 fileoff; /* file offset of this segment */
uint32 filesize; /* amount to map from the file */
} MachSymSeg;
typedef struct {
char sectname[16]; /* name of this section */
char segname[16]; /* segment this section goes in */
uint32 addr; /* memory address of this section */
uint32 size; /* size in bytes of this section */
uint32 offset; /* file offset of this section */
uint32 align; /* section alignment (power of 2) */
uint32 reloff; /* file offset of relocation entries */
uint32 nreloc; /* number of relocation entries */
uint32 flags; /* flags (section type and attributes)*/
uint32 reserved1; /* reserved (for offset or index) */
uint32 reserved2; /* reserved (for count or sizeof) */
} MachSect32; /* for 32-bit architectures */
typedef struct {
char sectname[16]; /* name of this section */
char segname[16]; /* segment this section goes in */
uvlong addr; /* memory address of this section */
uvlong size; /* size in bytes of this section */
uint32 offset; /* file offset of this section */
uint32 align; /* section alignment (power of 2) */
uint32 reloff; /* file offset of relocation entries */
uint32 nreloc; /* number of relocation entries */
uint32 flags; /* flags (section type and attributes)*/
uint32 reserved1; /* reserved (for offset or index) */
uint32 reserved2; /* reserved (for count or sizeof) */
uint32 reserved3; /* reserved */
} MachSect64; /* for 64-bit architectures */
enum {
MACH_CPU_TYPE_X86_64 = (1<<24)|7,
MACH_CPU_TYPE_X86 = 7,
MACH_CPU_SUBTYPE_X86 = 3,
MACH_CPU_SUBTYPE_X86_64 = (1<<31)|3,
MACH_EXECUTABLE_TYPE = 2,
MACH_SEGMENT_32 = 1, /* 32-bit mapped segment */
MACH_SEGMENT_64 = 0x19, /* 64-bit mapped segment */
MACH_SYMSEG = 3, /* obsolete gdb symtab, reused by go */
MACH_UNIXTHREAD = 0x5, /* thread (for stack) */
};
#define MACH64_MAG ((0xcf<<24) | (0xfa<<16) | (0xed<<8) | 0xfe)
#define MACH32_MAG ((0xce<<24) | (0xfa<<16) | (0xed<<8) | 0xfe)
// Derived from Inferno libmach/map.c and
// Plan 9 from User Space src/libmach/map.c
//
// http://code.swtch.com/plan9port/src/tip/src/libmach/map.c
// http://code.google.com/p/inferno-os/source/browse/utils/libmach/map.c
//
//
// Copyright © 1994-1999 Lucent Technologies Inc.
// Power PC support Copyright © 1995-2004 C H Forsyth (forsyth@terzarima.net).
// Portions Copyright © 1997-1999 Vita Nuova Limited.
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).
// Revisions Copyright © 2000-2004 Lucent Technologies Inc. and others.
// Portions Copyright © 2001-2007 Russ Cox.
// Portions Copyright © 2009 The Go Authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
* file map routines
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <mach.h>
Map *
newmap(Map *map, int n)
{
int size;
size = sizeof(Map)+(n-1)*sizeof(Seg);
if (map == 0)
map = malloc(size);
else
map = realloc(map, size);
if (map == 0) {
werrstr("out of memory: %r");
return 0;
}
memset(map, 0, size);
map->nsegs = n;
return map;
}
int
setmap(Map *map, int fd, uvlong b, uvlong e, vlong f, char *name, Maprw *rw)
{
int i;
if (map == 0)
return 0;
for (i = 0; i < map->nsegs; i++)
if (!map->seg[i].inuse)
break;
if (i >= map->nsegs)
return 0;
map->seg[i].b = b;
map->seg[i].e = e;
map->seg[i].f = f;
map->seg[i].inuse = 1;
map->seg[i].name = name;
map->seg[i].fd = fd;
map->seg[i].rw = rw;
return 1;
}
/*
static uvlong
stacktop(int pid)
{
char buf[64];
int fd;
int n;
char *cp;
snprint(buf, sizeof(buf), "/proc/%d/segment", pid);
fd = open(buf, 0);
if (fd < 0)
return 0;
n = read(fd, buf, sizeof(buf)-1);
close(fd);
buf[n] = 0;
if (strncmp(buf, "Stack", 5))
return 0;
for (cp = buf+5; *cp && *cp == ' '; cp++)
;
if (!*cp)
return 0;
cp = strchr(cp, ' ');
if (!cp)
return 0;
while (*cp && *cp == ' ')
cp++;
if (!*cp)
return 0;
return strtoull(cp, 0, 16);
}
*/
int
findseg(Map *map, char *name)
{
int i;
if (!map)
return -1;
for (i = 0; i < map->nsegs; i++)
if (map->seg[i].inuse && !strcmp(map->seg[i].name, name))
return i;
return -1;
}
void
unusemap(Map *map, int i)
{
if (map != 0 && 0 <= i && i < map->nsegs)
map->seg[i].inuse = 0;
}
int
fdrw(Map *map, Seg *s, uvlong addr, void *v, uint n, int isread)
{
int tot, m;
USED(map);
for(tot=0; tot<n; tot+=m){
if(isread)
m = pread(s->fd, (uchar*)v+tot, n-tot, addr+tot);
else
m = pwrite(s->fd, (uchar*)v+tot, n-tot, addr+tot);
if(m == 0){
werrstr("short %s", isread ? "read" : "write");
return -1;
}
if(m < 0){
werrstr("%s %d at %#llux (+%#llux): %r", isread ? "read" : "write", n, addr, s->f);
return -1;
}
}
return 0;
}
Map*
loadmap(Map *map, int fd, Fhdr *fp)
{
map = newmap(map, 2);
if (map == 0)
return 0;
map->seg[0].b = fp->txtaddr;
map->seg[0].e = fp->txtaddr+fp->txtsz;
map->seg[0].f = fp->txtoff;
map->seg[0].fd = fd;
map->seg[0].inuse = 1;
map->seg[0].name = "text";
map->seg[0].rw = fdrw;
map->seg[1].b = fp->dataddr;
map->seg[1].e = fp->dataddr+fp->datsz;
map->seg[1].f = fp->datoff;
map->seg[1].fd = fd;
map->seg[1].inuse = 1;
map->seg[1].name = "data";
map->seg[0].rw = fdrw;
return map;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment