1 /* emulos.c -- Small OS emulation
2 Copyright 1999-2024 Free Software Foundation, Inc.
3 Written by Stephane Carrez (stcarrez@worldnet.fr)
5 This file is part of GDB, GAS, and the GNU binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This must come before any other includes. */
26 #include "m68hc11-sim.h"
31 #include <sys/types.h>
34 /* This file emulates some OS system calls.
35 It's basically used to give access to the host OS facilities
36 like: stdin, stdout, files, time of day. */
37 static int bench_mode
= -1;
38 static struct timeval bench_start
;
39 static struct timeval bench_stop
;
42 emul_bench (sim_cpu
*cpu
)
51 gettimeofday (&bench_start
, 0);
55 gettimeofday (&bench_stop
, 0);
57 printf ("bench start not called...\n");
64 int addr
= cpu_get_x (cpu
);
65 double t_start
, t_stop
, t
;
69 t_start
= (double) (bench_start
.tv_sec
) * 1.0e6
;
70 t_start
+= (double) (bench_start
.tv_usec
);
71 t_stop
= (double) (bench_stop
.tv_sec
) * 1.0e6
;
72 t_stop
+= (double) (bench_stop
.tv_usec
);
76 buf
[sz
] = memory_read8 (cpu
, addr
);
86 printf ("bench_stop not called");
90 printf ("%-40.40s [%6d] %3.3f us\n", buf
,
91 op
, t
/ (double) (op
));
99 emul_write (sim_cpu
*cpu
)
101 int addr
= cpu_get_x (cpu
) & 0x0FFFF;
102 int size
= cpu_get_d (cpu
) & 0x0FFFF;
104 if (addr
+ size
> 0x0FFFF) {
105 size
= 0x0FFFF - addr
;
107 M68HC11_SIM_CPU (cpu
)->cpu_running
= 0;
110 uint8_t val
= memory_read8 (cpu
, addr
);
112 if (write (0, &val
, 1) != 1)
113 printf ("write failed: %s\n", strerror (errno
));
119 /* emul_exit () is used by the default startup code of GCC to implement
120 the exit (). For a real target, this will create an ILLEGAL fault.
121 But doing an exit () on a real target is really a non-sense.
122 exit () is important for the validation of GCC. The exit status
123 is passed in 'D' register. */
125 emul_exit (sim_cpu
*cpu
)
127 sim_engine_halt (CPU_STATE (cpu
), cpu
,
128 NULL
, NULL_CIA
, sim_exited
,
133 emul_os (int code
, sim_cpu
*cpu
)
135 M68HC11_SIM_CPU (cpu
)->cpu_current_cycle
= 8;