1 /* This file is part of the program psim.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 Code to output system call traces Copyright (C) 1991 Gordon Irlam.
24 This tool is part of the Spa(7) package. The Spa(7) package
25 may be redistributed and/or modified under the terms of the
26 GNU General Public License Version 2 (GPL(7)) as published
27 by the Free Software Foundation.
32 #ifndef _EMUL_GENERIC_C_
33 #define _EMUL_GENERIC_C_
35 #include "emul_generic.h"
37 #ifndef STATIC_INLINE_EMUL_GENERIC
38 #define STATIC_INLINE_EMUL_GENERIC STATIC_INLINE
42 INLINE_EMUL_GENERIC void
43 emul_enter_call(emulation *emul,
49 printf_filtered("%d:0x%x:%s(",
50 cpu_nr(processor) + 1,
52 emul->call_descriptor[call].name);
56 INLINE_EMUL_GENERIC void
57 emul_exit_call(emulation *emul,
63 int status = cpu_registers(processor)->gpr[3];
64 int error = cpu_registers(processor)->gpr[0];
65 printf_filtered(")=%d", status);
66 if (error > 0 && error < emul->nr_error_names)
67 printf_filtered("[%s]",
68 emul->error_names[cpu_registers(processor)->gpr[0]]);
69 printf_filtered("\n");
73 INLINE_EMUL_GENERIC unsigned64
74 emul_read_gpr64(cpu *processor,
79 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
80 hi = cpu_registers(processor)->gpr[g];
81 lo = cpu_registers(processor)->gpr[g+1];
84 lo = cpu_registers(processor)->gpr[g];
85 hi = cpu_registers(processor)->gpr[g+1];
87 return (INSERTED64(hi, 0, 31) | INSERTED64(lo, 32, 63));
91 INLINE_EMUL_GENERIC void
92 emul_write_gpr64(cpu *processor,
96 unsigned32 hi = EXTRACTED64(val, 0, 31);
97 unsigned32 lo = EXTRACTED64(val, 32, 63);
98 if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN) {
99 cpu_registers(processor)->gpr[g] = hi;
100 cpu_registers(processor)->gpr[g+1] = lo;
103 cpu_registers(processor)->gpr[g] = lo;
104 cpu_registers(processor)->gpr[g+1] = hi;
109 INLINE_EMUL_GENERIC char *
110 emul_read_string(char *dest,
116 unsigned nr_moved = 0;
120 if (vm_data_map_read_buffer(cpu_data_map(processor),
123 sizeof(dest[nr_moved]))
124 != sizeof(dest[nr_moved]))
126 if (dest[nr_moved] == '\0' || nr_moved >= nr_bytes)
130 dest[nr_moved] = '\0';
135 INLINE_EMUL_GENERIC void
136 emul_write_status(cpu *processor,
140 cpu_registers(processor)->gpr[3] = status;
142 cpu_registers(processor)->gpr[0] = errno;
144 cpu_registers(processor)->gpr[0] = 0;
148 INLINE_EMUL_GENERIC void
149 emul_write_word(unsigned_word addr,
156 nr_moved = vm_data_map_write_buffer(cpu_data_map(processor),
161 if (nr_moved != sizeof(buf)) {
162 printf_filtered("emul_write_word() write failed, %d out of %d written\n",
163 nr_moved, sizeof(buf));
164 cpu_halt(processor, cia, was_exited, 14/*EFAULT*/);
169 INLINE_EMUL_GENERIC void
170 emul_write_buffer(const void *source,
176 int nr_moved = vm_data_map_write_buffer(cpu_data_map(processor),
181 if (nr_moved != nr_bytes) {
182 printf_filtered("emul_write_buffer() write failed %d out of %d written\n",
184 cpu_halt(processor, cia, was_exited, 14/*EFAULT*/);
189 INLINE_EMUL_GENERIC void
190 emul_read_buffer(void *dest,
196 int nr_moved = vm_data_map_read_buffer(cpu_data_map(processor),
200 if (nr_moved != nr_bytes) {
201 printf_filtered("emul_read_buffer() read failed %d out of %d read\n",
203 cpu_halt(processor, cia, was_exited, 14/*EFAULT*/);
208 INLINE_EMUL_GENERIC void
209 emul_do_call(emulation *emul,
215 emul_call_handler *handler = NULL;
216 if (call >= emul->nr_system_calls)
217 error("do_call() os_emul call %d out-of-range\n", call);
219 handler = emul->call_descriptor[call].handler;
221 error("do_call() unimplemented call %d\n", call);
224 cpu_registers(processor)->gpr[0] = 0; /* default success */
225 handler(emul, call, arg0, processor, cia);
230 #endif /* _SYSTEM_C_ */