2 * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
5 * This software was developed by the University of Cambridge Computer
6 * Laboratory as part of the CTSRD Project, with support from the UK Higher
7 * Education Innovation Fund (HEIF).
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
11 * met: redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer;
13 * redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution;
16 * neither the name of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "arch/arm/freebsd/process.hh"
36 #include <sys/param.h>
37 #include <sys/syscall.h>
38 #if !defined ( __GNU_LIBRARY__ )
39 #include <sys/sysctl.h>
41 #include <sys/types.h>
44 #include "arch/arm/freebsd/freebsd.hh"
45 #include "arch/arm/isa_traits.hh"
46 #include "base/loader/object_file.hh"
47 #include "base/trace.hh"
48 #include "cpu/thread_context.hh"
49 #include "kern/freebsd/freebsd.hh"
50 #include "sim/process.hh"
51 #include "sim/syscall_desc.hh"
52 #include "sim/syscall_emul.hh"
53 #include "sim/system.hh"
56 using namespace ArmISA
;
61 class ArmFreebsdObjectFileLoader
: public Process::Loader
65 load(ProcessParams
*params
, ::Loader::ObjectFile
*obj_file
) override
67 auto arch
= obj_file
->getArch();
68 auto opsys
= obj_file
->getOpSys();
70 if (arch
!= ::Loader::Arm
&& arch
!= ::Loader::Thumb
&&
71 arch
!= ::Loader::Arm64
) {
75 if (opsys
!= ::Loader::FreeBSD
)
78 if (arch
== ::Loader::Arm64
)
79 return new ArmFreebsdProcess64(params
, obj_file
, arch
);
81 return new ArmFreebsdProcess32(params
, obj_file
, arch
);
85 ArmFreebsdObjectFileLoader loader
;
87 } // anonymous namespace
90 issetugidFunc(SyscallDesc
*desc
, ThreadContext
*tc
)
95 #if !defined ( __GNU_LIBRARY__ )
97 sysctlFunc(SyscallDesc
*desc
, ThreadContext
*tc
, Addr namep
, size_t nameLen
,
98 Addr oldp
, Addr oldlenp
, Addr newp
, size_t newlen
)
102 BufferArg
buf(namep
, sizeof(size_t));
103 BufferArg
buf2(oldp
, sizeof(size_t));
104 BufferArg
buf3(oldlenp
, sizeof(size_t));
105 BufferArg
buf4(newp
, sizeof(size_t));
107 buf
.copyIn(tc
->getVirtProxy());
108 buf2
.copyIn(tc
->getVirtProxy());
109 buf3
.copyIn(tc
->getVirtProxy());
113 buf4
.copyIn(tc
->getVirtProxy());
114 hnewp
= (void *)buf4
.bufferPtr();
117 uint32_t *hnamep
= (uint32_t *)buf
.bufferPtr();
118 void *holdp
= (void *)buf2
.bufferPtr();
119 size_t *holdlenp
= (size_t *)buf3
.bufferPtr();
121 ret
= sysctl((int *)hnamep
, nameLen
, holdp
, holdlenp
, hnewp
, newlen
);
123 buf
.copyOut(tc
->getVirtProxy());
124 buf2
.copyOut(tc
->getVirtProxy());
125 buf3
.copyOut(tc
->getVirtProxy());
127 buf4
.copyOut(tc
->getVirtProxy());
133 static SyscallDescTable
<ArmFreebsdProcess32::SyscallABI
> syscallDescs32({});
135 static SyscallDescTable
<ArmFreebsdProcess64::SyscallABI
> syscallDescs64
= {
136 { 1, "exit", exitFunc
},
137 { 3, "read", readFunc
<ArmFreebsd64
> },
138 { 4, "write", writeFunc
<ArmFreebsd64
> },
139 { 17, "obreak", brkFunc
},
140 { 54, "ioctl", ioctlFunc
<ArmFreebsd64
> },
141 { 58, "readlink", readlinkFunc
},
142 { 117, "getrusage", getrusageFunc
<ArmFreebsd64
> },
143 { 189, "fstat", fstatFunc
<ArmFreebsd64
> },
144 #if !defined ( __GNU_LIBRARY__ )
145 { 202, "sysctl", sysctlFunc
},
149 { 253, "issetugid", issetugidFunc
},
150 { 477, "mmap", mmapFunc
<ArmFreebsd64
> }
153 ArmFreebsdProcess32::ArmFreebsdProcess32(ProcessParams
* params
,
154 ::Loader::ObjectFile
*objFile
, ::Loader::Arch _arch
) :
155 ArmProcess32(params
, objFile
, _arch
)
158 ArmFreebsdProcess64::ArmFreebsdProcess64(ProcessParams
* params
,
159 ::Loader::ObjectFile
*objFile
, ::Loader::Arch _arch
) :
160 ArmProcess64(params
, objFile
, _arch
)
164 ArmFreebsdProcess32::initState()
166 ArmProcess32::initState();
167 // The 32 bit equivalent of the comm page would be set up here.
171 ArmFreebsdProcess64::initState()
173 ArmProcess64::initState();
174 // The 64 bit equivalent of the comm page would be set up here.
178 ArmFreebsdProcess32::syscall(ThreadContext
*tc
)
180 ArmProcess32::syscall(tc
);
181 syscallDescs32
.get(tc
->readIntReg(INTREG_R7
))->doSyscall(tc
);
185 ArmFreebsdProcess64::syscall(ThreadContext
*tc
)
187 ArmProcess64::syscall(tc
);
188 syscallDescs64
.get(tc
->readIntReg(INTREG_X8
))->doSyscall(tc
);