Improve log message for unaligned i/o
[qemu/ar7.git] / linux-user / m68k-sim.c
blob9aa4486a552fce8795fee8d14eb17f14864aa7ce
1 /*
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, see <http://www.gnu.org/licenses/>.
20 #include <sys/types.h>
21 #include <sys/stat.h>
23 #include "qemu-common.h"
24 #include "qemu.h"
26 #define SYS_EXIT 1
27 #define SYS_READ 3
28 #define SYS_WRITE 4
29 #define SYS_OPEN 5
30 #define SYS_CLOSE 6
31 #define SYS_BRK 17
32 #define SYS_FSTAT 28
33 #define SYS_ISATTY 29
34 #define SYS_LSEEK 199
36 struct m68k_sim_stat {
37 uint16_t sim_st_dev;
38 uint16_t sim_st_ino;
39 uint32_t sim_st_mode;
40 uint16_t sim_st_nlink;
41 uint16_t sim_st_uid;
42 uint16_t sim_st_gid;
43 uint16_t sim_st_rdev;
44 uint32_t sim_st_size;
45 uint32_t sim_st_atime;
46 uint32_t sim_st_mtime;
47 uint32_t sim_st_ctime;
48 uint32_t sim_st_blksize;
49 uint32_t sim_st_blocks;
52 static inline uint32_t check_err(CPUM68KState *env, uint32_t code)
54 env->dregs[0] = code;
55 if (code == (uint32_t)-1) {
56 env->dregs[1] = errno;
57 } else {
58 env->dregs[1] = 0;
60 return code;
63 #define SIM_O_APPEND 0x0008
64 #define SIM_O_CREAT 0x0200
65 #define SIM_O_TRUNC 0x0400
66 #define SIM_O_EXCL 0x0800
67 #define SIM_O_NONBLOCK 0x4000
68 #define SIM_O_NOCTTY 0x8000
69 #define SIM_O_SYNC 0x2000
71 static int translate_openflags(int flags)
73 int hf;
75 switch (flags & 3) {
76 case 0: hf = O_RDONLY; break;
77 case 1: hf = O_WRONLY; break;
78 case 2: hf = O_RDWR; break;
79 default: hf = O_RDWR; break;
82 if (flags & SIM_O_APPEND) hf |= O_APPEND;
83 if (flags & SIM_O_CREAT) hf |= O_CREAT;
84 if (flags & SIM_O_TRUNC) hf |= O_TRUNC;
85 if (flags & SIM_O_EXCL) hf |= O_EXCL;
86 if (flags & SIM_O_NONBLOCK) hf |= O_NONBLOCK;
87 if (flags & SIM_O_NOCTTY) hf |= O_NOCTTY;
88 if (flags & SIM_O_SYNC) hf |= O_SYNC;
90 return hf;
93 #define ARG(x) tswap32(args[x])
94 void do_m68k_simcall(CPUM68KState *env, int nr)
96 M68kCPU *cpu = m68k_env_get_cpu(env);
97 uint32_t *args;
99 args = (uint32_t *)(unsigned long)(env->aregs[7] + 4);
100 switch (nr) {
101 case SYS_EXIT:
102 exit(ARG(0));
103 case SYS_READ:
104 check_err(env, read(ARG(0), (void *)(unsigned long)ARG(1), ARG(2)));
105 break;
106 case SYS_WRITE:
107 check_err(env, write(ARG(0), (void *)(unsigned long)ARG(1), ARG(2)));
108 break;
109 case SYS_OPEN:
110 check_err(env, open((char *)(unsigned long)ARG(0),
111 translate_openflags(ARG(1)), ARG(2)));
112 break;
113 case SYS_CLOSE:
115 /* Ignore attempts to close stdin/out/err. */
116 int fd = ARG(0);
117 if (fd > 2)
118 check_err(env, close(fd));
119 else
120 check_err(env, 0);
121 break;
123 case SYS_BRK:
125 int32_t ret;
127 ret = do_brk((abi_ulong)ARG(0));
128 if (ret == -ENOMEM)
129 ret = -1;
130 check_err(env, ret);
132 break;
133 case SYS_FSTAT:
135 struct stat s;
136 int rc;
137 struct m68k_sim_stat *p;
138 rc = check_err(env, fstat(ARG(0), &s));
139 if (rc == 0) {
140 p = (struct m68k_sim_stat *)(unsigned long)ARG(1);
141 p->sim_st_dev = tswap16(s.st_dev);
142 p->sim_st_ino = tswap16(s.st_ino);
143 p->sim_st_mode = tswap32(s.st_mode);
144 p->sim_st_nlink = tswap16(s.st_nlink);
145 p->sim_st_uid = tswap16(s.st_uid);
146 p->sim_st_gid = tswap16(s.st_gid);
147 p->sim_st_rdev = tswap16(s.st_rdev);
148 p->sim_st_size = tswap32(s.st_size);
149 p->sim_st_atime = tswap32(s.st_atime);
150 p->sim_st_mtime = tswap32(s.st_mtime);
151 p->sim_st_ctime = tswap32(s.st_ctime);
152 p->sim_st_blksize = tswap32(s.st_blksize);
153 p->sim_st_blocks = tswap32(s.st_blocks);
156 break;
157 case SYS_ISATTY:
158 check_err(env, isatty(ARG(0)));
159 break;
160 case SYS_LSEEK:
161 check_err(env, lseek(ARG(0), (int32_t)ARG(1), ARG(2)));
162 break;
163 default:
164 cpu_abort(CPU(cpu), "Unsupported m68k sim syscall %d\n", nr);