1 /* emulos.c -- Small OS emulation
2 Copyright 1999, 2000, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Written by Stephane Carrez (stcarrez@worldnet.fr)
6 This file is part of GDB, GAS, and the GNU binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include <sys/types.h>
30 /* This file emulates some OS system calls.
31 It's basically used to give access to the host OS facilities
32 like: stdin, stdout, files, time of day. */
33 static int bench_mode = -1;
34 static struct timeval bench_start;
35 static struct timeval bench_stop;
38 emul_bench (struct _sim_cpu* cpu)
47 gettimeofday (&bench_start, 0);
51 gettimeofday (&bench_stop, 0);
53 printf ("bench start not called...\n");
60 int addr = cpu_get_x (cpu);
61 double t_start, t_stop, t;
65 t_start = (double) (bench_start.tv_sec) * 1.0e6;
66 t_start += (double) (bench_start.tv_usec);
67 t_stop = (double) (bench_stop.tv_sec) * 1.0e6;
68 t_stop += (double) (bench_stop.tv_usec);
72 buf[sz] = memory_read8 (cpu, addr);
82 printf ("bench_stop not called");
86 printf ("%-40.40s [%6d] %3.3f us\n", buf,
87 op, t / (double) (op));
95 emul_write(struct _sim_cpu* state)
97 int addr = cpu_get_x (state) & 0x0FFFF;
98 int size = cpu_get_d (state) & 0x0FFFF;
100 if (addr + size > 0x0FFFF) {
101 size = 0x0FFFF - addr;
103 state->cpu_running = 0;
106 uint8 val = memory_read8 (state, addr);
114 /* emul_exit () is used by the default startup code of GCC to implement
115 the exit (). For a real target, this will create an ILLEGAL fault.
116 But doing an exit () on a real target is really a non-sense.
117 exit () is important for the validation of GCC. The exit status
118 is passed in 'D' register. */
120 emul_exit (sim_cpu *cpu)
122 sim_engine_halt (CPU_STATE (cpu), cpu,
123 NULL, NULL_CIA, sim_exited,
128 emul_os (int code, sim_cpu *proc)
130 proc->cpu_current_cycle = 8;