2 * m68k simulator syscall interface
4 * Copyright (c) 2005 CodeSourcery, LLC. Written by Paul Brook.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <sys/types.h>
42 struct m86k_sim_stat
{
46 uint16_t sim_st_nlink
;
51 uint32_t sim_st_atime
;
52 uint32_t sim_st_mtime
;
53 uint32_t sim_st_ctime
;
54 uint32_t sim_st_blksize
;
55 uint32_t sim_st_blocks
;
58 static inline uint32_t check_err(CPUM68KState
*env
, uint32_t code
)
61 if (code
== (uint32_t)-1) {
62 env
->dregs
[1] = errno
;
69 #define SIM_O_APPEND 0x0008
70 #define SIM_O_CREAT 0x0200
71 #define SIM_O_TRUNC 0x0400
72 #define SIM_O_EXCL 0x0800
73 #define SIM_O_NONBLOCK 0x4000
74 #define SIM_O_NOCTTY 0x8000
75 #define SIM_O_SYNC 0x2000
77 static int translate_openflags(int flags
)
82 case 0: hf
= O_RDONLY
; break;
83 case 1: hf
= O_WRONLY
; break;
84 case 2: hf
= O_RDWR
; break;
85 default: hf
= O_RDWR
; break;
88 if (flags
& SIM_O_APPEND
) hf
|= O_APPEND
;
89 if (flags
& SIM_O_CREAT
) hf
|= O_CREAT
;
90 if (flags
& SIM_O_TRUNC
) hf
|= O_TRUNC
;
91 if (flags
& SIM_O_EXCL
) hf
|= O_EXCL
;
92 if (flags
& SIM_O_NONBLOCK
) hf
|= O_NONBLOCK
;
93 if (flags
& SIM_O_NOCTTY
) hf
|= O_NOCTTY
;
94 if (flags
& SIM_O_SYNC
) hf
|= O_SYNC
;
99 #define ARG(x) tswap32(args[x])
100 void do_m68k_simcall(CPUM68KState
*env
, int nr
)
104 args
= (uint32_t *)(env
->aregs
[7] + 4);
109 check_err(env
, read(ARG(0), (void *)ARG(1), ARG(2)));
112 check_err(env
, write(ARG(0), (void *)ARG(1), ARG(2)));
115 check_err(env
, open((char *)ARG(0), translate_openflags(ARG(1)),
120 /* Ignore attempts to close stdin/out/err. */
123 check_err(env
, close(fd
));
132 ret
= do_brk((void *)ARG(0));
142 struct m86k_sim_stat
*p
;
143 rc
= check_err(env
, fstat(ARG(0), &s
));
145 p
= (struct m86k_sim_stat
*)ARG(1);
146 p
->sim_st_dev
= tswap16(s
.st_dev
);
147 p
->sim_st_ino
= tswap16(s
.st_ino
);
148 p
->sim_st_mode
= tswap32(s
.st_mode
);
149 p
->sim_st_nlink
= tswap16(s
.st_nlink
);
150 p
->sim_st_uid
= tswap16(s
.st_uid
);
151 p
->sim_st_gid
= tswap16(s
.st_gid
);
152 p
->sim_st_rdev
= tswap16(s
.st_rdev
);
153 p
->sim_st_size
= tswap32(s
.st_size
);
154 p
->sim_st_atime
= tswap32(s
.st_atime
);
155 p
->sim_st_mtime
= tswap32(s
.st_mtime
);
156 p
->sim_st_ctime
= tswap32(s
.st_ctime
);
157 p
->sim_st_blksize
= tswap32(s
.st_blksize
);
158 p
->sim_st_blocks
= tswap32(s
.st_blocks
);
163 check_err(env
, isatty(ARG(0)));
166 check_err(env
, lseek(ARG(0), (int32_t)ARG(1), ARG(2)));
169 cpu_abort(env
, "Unsupported m68k sim syscall %d\n", nr
);
173 * m68k simulator syscall interface
175 * Copyright (c) 2005 CodeSourcery, LLC. Written by Paul Brook.
177 * This program is free software; you can redistribute it and/or modify
178 * it under the terms of the GNU General Public License as published by
179 * the Free Software Foundation; either version 2 of the License, or
180 * (at your option) any later version.
182 * This program is distributed in the hope that it will be useful,
183 * but WITHOUT ANY WARRANTY; without even the implied warranty of
184 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185 * GNU General Public License for more details.
187 * You should have received a copy of the GNU General Public License
188 * along with this program; if not, write to the Free Software
189 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
192 #include <sys/types.h>
193 #include <sys/stat.h>
210 #define SYS_ISATTY 29
211 #define SYS_LSEEK 199
213 struct m86k_sim_stat
{
216 uint32_t sim_st_mode
;
217 uint16_t sim_st_nlink
;
220 uint16_t sim_st_rdev
;
221 uint32_t sim_st_size
;
222 uint32_t sim_st_atime
;
223 uint32_t sim_st_mtime
;
224 uint32_t sim_st_ctime
;
225 uint32_t sim_st_blksize
;
226 uint32_t sim_st_blocks
;
229 static inline uint32_t check_err(CPUM68KState
*env
, uint32_t code
)
231 env
->dregs
[0] = code
;
232 if (code
== (uint32_t)-1) {
233 env
->dregs
[1] = errno
;
240 #define SIM_O_APPEND 0x0008
241 #define SIM_O_CREAT 0x0200
242 #define SIM_O_TRUNC 0x0400
243 #define SIM_O_EXCL 0x0800
244 #define SIM_O_NONBLOCK 0x4000
245 #define SIM_O_NOCTTY 0x8000
246 #define SIM_O_SYNC 0x2000
248 static int translate_openflags(int flags
)
253 case 0: hf
= O_RDONLY
; break;
254 case 1: hf
= O_WRONLY
; break;
255 case 2: hf
= O_RDWR
; break;
256 default: hf
= O_RDWR
; break;
259 if (flags
& SIM_O_APPEND
) hf
|= O_APPEND
;
260 if (flags
& SIM_O_CREAT
) hf
|= O_CREAT
;
261 if (flags
& SIM_O_TRUNC
) hf
|= O_TRUNC
;
262 if (flags
& SIM_O_EXCL
) hf
|= O_EXCL
;
263 if (flags
& SIM_O_NONBLOCK
) hf
|= O_NONBLOCK
;
264 if (flags
& SIM_O_NOCTTY
) hf
|= O_NOCTTY
;
265 if (flags
& SIM_O_SYNC
) hf
|= O_SYNC
;
270 #define ARG(x) tswap32(args[x])
271 void do_m68k_simcall(CPUM68KState
*env
, int nr
)
275 args
= (uint32_t *)(env
->aregs
[7] + 4);
280 check_err(env
, read(ARG(0), (void *)ARG(1), ARG(2)));
283 check_err(env
, write(ARG(0), (void *)ARG(1), ARG(2)));
286 check_err(env
, open((char *)ARG(0), translate_openflags(ARG(1)),
291 /* Ignore attempts to close stdin/out/err. */
294 check_err(env
, close(fd
));
303 ret
= do_brk((void *)ARG(0));
313 struct m86k_sim_stat
*p
;
314 rc
= check_err(env
, fstat(ARG(0), &s
));
316 p
= (struct m86k_sim_stat
*)ARG(1);
317 p
->sim_st_dev
= tswap16(s
.st_dev
);
318 p
->sim_st_ino
= tswap16(s
.st_ino
);
319 p
->sim_st_mode
= tswap32(s
.st_mode
);
320 p
->sim_st_nlink
= tswap16(s
.st_nlink
);
321 p
->sim_st_uid
= tswap16(s
.st_uid
);
322 p
->sim_st_gid
= tswap16(s
.st_gid
);
323 p
->sim_st_rdev
= tswap16(s
.st_rdev
);
324 p
->sim_st_size
= tswap32(s
.st_size
);
325 p
->sim_st_atime
= tswap32(s
.st_atime
);
326 p
->sim_st_mtime
= tswap32(s
.st_mtime
);
327 p
->sim_st_ctime
= tswap32(s
.st_ctime
);
328 p
->sim_st_blksize
= tswap32(s
.st_blksize
);
329 p
->sim_st_blocks
= tswap32(s
.st_blocks
);
334 check_err(env
, isatty(ARG(0)));
337 check_err(env
, lseek(ARG(0), (int32_t)ARG(1), ARG(2)));
340 cpu_abort(env
, "Unsupported m68k sim syscall %d\n", nr
);