]> git.proxmox.com Git - mirror_qemu.git/blame - linux-user/m68k-sim.c
target/s390x: Use env_cpu, env_archcpu
[mirror_qemu.git] / linux-user / m68k-sim.c
CommitLineData
e6e5906b
PB
1/*
2 * m68k simulator syscall interface
5fafdf24 3 *
e6e5906b
PB
4 * Copyright (c) 2005 CodeSourcery, LLC. Written by Paul Brook.
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
8167ee88 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
e6e5906b
PB
18 */
19
d39594e9 20#include "qemu/osdep.h"
e6e5906b
PB
21
22#include "qemu.h"
23
24#define SYS_EXIT 1
25#define SYS_READ 3
26#define SYS_WRITE 4
27#define SYS_OPEN 5
28#define SYS_CLOSE 6
29#define SYS_BRK 17
30#define SYS_FSTAT 28
31#define SYS_ISATTY 29
32#define SYS_LSEEK 199
33
e0c8a796 34struct m68k_sim_stat {
e6e5906b
PB
35 uint16_t sim_st_dev;
36 uint16_t sim_st_ino;
37 uint32_t sim_st_mode;
38 uint16_t sim_st_nlink;
39 uint16_t sim_st_uid;
40 uint16_t sim_st_gid;
41 uint16_t sim_st_rdev;
42 uint32_t sim_st_size;
43 uint32_t sim_st_atime;
44 uint32_t sim_st_mtime;
45 uint32_t sim_st_ctime;
46 uint32_t sim_st_blksize;
47 uint32_t sim_st_blocks;
48};
49
50static inline uint32_t check_err(CPUM68KState *env, uint32_t code)
51{
52 env->dregs[0] = code;
53 if (code == (uint32_t)-1) {
54 env->dregs[1] = errno;
55 } else {
56 env->dregs[1] = 0;
57 }
58 return code;
59}
60
61#define SIM_O_APPEND 0x0008
62#define SIM_O_CREAT 0x0200
63#define SIM_O_TRUNC 0x0400
64#define SIM_O_EXCL 0x0800
65#define SIM_O_NONBLOCK 0x4000
66#define SIM_O_NOCTTY 0x8000
67#define SIM_O_SYNC 0x2000
68
69static int translate_openflags(int flags)
70{
71 int hf;
72
73 switch (flags & 3) {
74 case 0: hf = O_RDONLY; break;
75 case 1: hf = O_WRONLY; break;
76 case 2: hf = O_RDWR; break;
77 default: hf = O_RDWR; break;
78 }
79
80 if (flags & SIM_O_APPEND) hf |= O_APPEND;
81 if (flags & SIM_O_CREAT) hf |= O_CREAT;
82 if (flags & SIM_O_TRUNC) hf |= O_TRUNC;
83 if (flags & SIM_O_EXCL) hf |= O_EXCL;
84 if (flags & SIM_O_NONBLOCK) hf |= O_NONBLOCK;
85 if (flags & SIM_O_NOCTTY) hf |= O_NOCTTY;
86 if (flags & SIM_O_SYNC) hf |= O_SYNC;
87
88 return hf;
89}
90
91#define ARG(x) tswap32(args[x])
92void do_m68k_simcall(CPUM68KState *env, int nr)
93{
94 uint32_t *args;
95
526ccb7a 96 args = (uint32_t *)(unsigned long)(env->aregs[7] + 4);
e6e5906b
PB
97 switch (nr) {
98 case SYS_EXIT:
99 exit(ARG(0));
100 case SYS_READ:
526ccb7a 101 check_err(env, read(ARG(0), (void *)(unsigned long)ARG(1), ARG(2)));
e6e5906b
PB
102 break;
103 case SYS_WRITE:
526ccb7a 104 check_err(env, write(ARG(0), (void *)(unsigned long)ARG(1), ARG(2)));
e6e5906b
PB
105 break;
106 case SYS_OPEN:
526ccb7a
AZ
107 check_err(env, open((char *)(unsigned long)ARG(0),
108 translate_openflags(ARG(1)), ARG(2)));
e6e5906b
PB
109 break;
110 case SYS_CLOSE:
111 {
112 /* Ignore attempts to close stdin/out/err. */
113 int fd = ARG(0);
114 if (fd > 2)
115 check_err(env, close(fd));
116 else
117 check_err(env, 0);
118 break;
119 }
120 case SYS_BRK:
121 {
122 int32_t ret;
123
ac2567b5 124 ret = do_brk((abi_ulong)ARG(0));
e6e5906b
PB
125 if (ret == -ENOMEM)
126 ret = -1;
127 check_err(env, ret);
128 }
129 break;
130 case SYS_FSTAT:
131 {
132 struct stat s;
133 int rc;
e0c8a796 134 struct m68k_sim_stat *p;
e6e5906b
PB
135 rc = check_err(env, fstat(ARG(0), &s));
136 if (rc == 0) {
e0c8a796 137 p = (struct m68k_sim_stat *)(unsigned long)ARG(1);
e6e5906b
PB
138 p->sim_st_dev = tswap16(s.st_dev);
139 p->sim_st_ino = tswap16(s.st_ino);
140 p->sim_st_mode = tswap32(s.st_mode);
141 p->sim_st_nlink = tswap16(s.st_nlink);
142 p->sim_st_uid = tswap16(s.st_uid);
143 p->sim_st_gid = tswap16(s.st_gid);
144 p->sim_st_rdev = tswap16(s.st_rdev);
145 p->sim_st_size = tswap32(s.st_size);
146 p->sim_st_atime = tswap32(s.st_atime);
147 p->sim_st_mtime = tswap32(s.st_mtime);
148 p->sim_st_ctime = tswap32(s.st_ctime);
149 p->sim_st_blksize = tswap32(s.st_blksize);
150 p->sim_st_blocks = tswap32(s.st_blocks);
151 }
152 }
153 break;
154 case SYS_ISATTY:
155 check_err(env, isatty(ARG(0)));
156 break;
157 case SYS_LSEEK:
158 check_err(env, lseek(ARG(0), (int32_t)ARG(1), ARG(2)));
159 break;
160 default:
a8d92fd8 161 cpu_abort(env_cpu(env), "Unsupported m68k sim syscall %d\n", nr);
e6e5906b
PB
162 }
163}