root / linux-user / m68k-sim.c @ ed23fbd9
History | View | Annotate | Download (4.8 kB)
1 | e6e5906b | pbrook | /*
|
---|---|---|---|
2 | e6e5906b | pbrook | * m68k simulator syscall interface
|
3 | 5fafdf24 | ths | *
|
4 | e6e5906b | pbrook | * Copyright (c) 2005 CodeSourcery, LLC. Written by Paul Brook.
|
5 | e6e5906b | pbrook | *
|
6 | e6e5906b | pbrook | * This program is free software; you can redistribute it and/or modify
|
7 | e6e5906b | pbrook | * it under the terms of the GNU General Public License as published by
|
8 | e6e5906b | pbrook | * the Free Software Foundation; either version 2 of the License, or
|
9 | e6e5906b | pbrook | * (at your option) any later version.
|
10 | e6e5906b | pbrook | *
|
11 | e6e5906b | pbrook | * This program is distributed in the hope that it will be useful,
|
12 | e6e5906b | pbrook | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | e6e5906b | pbrook | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | e6e5906b | pbrook | * GNU General Public License for more details.
|
15 | e6e5906b | pbrook | *
|
16 | e6e5906b | pbrook | * You should have received a copy of the GNU General Public License
|
17 | e6e5906b | pbrook | * along with this program; if not, write to the Free Software
|
18 | e6e5906b | pbrook | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | e6e5906b | pbrook | */
|
20 | e6e5906b | pbrook | |
21 | e6e5906b | pbrook | #include <sys/types.h> |
22 | e6e5906b | pbrook | #include <sys/stat.h> |
23 | e6e5906b | pbrook | #include <errno.h> |
24 | e6e5906b | pbrook | #include <fcntl.h> |
25 | e6e5906b | pbrook | #include <unistd.h> |
26 | e6e5906b | pbrook | #include <stdlib.h> |
27 | e6e5906b | pbrook | #include <stdio.h> |
28 | e6e5906b | pbrook | #include <time.h> |
29 | e6e5906b | pbrook | |
30 | e6e5906b | pbrook | #include "qemu.h" |
31 | e6e5906b | pbrook | |
32 | e6e5906b | pbrook | #define SYS_EXIT 1 |
33 | e6e5906b | pbrook | #define SYS_READ 3 |
34 | e6e5906b | pbrook | #define SYS_WRITE 4 |
35 | e6e5906b | pbrook | #define SYS_OPEN 5 |
36 | e6e5906b | pbrook | #define SYS_CLOSE 6 |
37 | e6e5906b | pbrook | #define SYS_BRK 17 |
38 | e6e5906b | pbrook | #define SYS_FSTAT 28 |
39 | e6e5906b | pbrook | #define SYS_ISATTY 29 |
40 | e6e5906b | pbrook | #define SYS_LSEEK 199 |
41 | e6e5906b | pbrook | |
42 | e6e5906b | pbrook | struct m86k_sim_stat {
|
43 | e6e5906b | pbrook | uint16_t sim_st_dev; |
44 | e6e5906b | pbrook | uint16_t sim_st_ino; |
45 | e6e5906b | pbrook | uint32_t sim_st_mode; |
46 | e6e5906b | pbrook | uint16_t sim_st_nlink; |
47 | e6e5906b | pbrook | uint16_t sim_st_uid; |
48 | e6e5906b | pbrook | uint16_t sim_st_gid; |
49 | e6e5906b | pbrook | uint16_t sim_st_rdev; |
50 | e6e5906b | pbrook | uint32_t sim_st_size; |
51 | e6e5906b | pbrook | uint32_t sim_st_atime; |
52 | e6e5906b | pbrook | uint32_t sim_st_mtime; |
53 | e6e5906b | pbrook | uint32_t sim_st_ctime; |
54 | e6e5906b | pbrook | uint32_t sim_st_blksize; |
55 | e6e5906b | pbrook | uint32_t sim_st_blocks; |
56 | e6e5906b | pbrook | }; |
57 | e6e5906b | pbrook | |
58 | e6e5906b | pbrook | static inline uint32_t check_err(CPUM68KState *env, uint32_t code) |
59 | e6e5906b | pbrook | { |
60 | e6e5906b | pbrook | env->dregs[0] = code;
|
61 | e6e5906b | pbrook | if (code == (uint32_t)-1) { |
62 | e6e5906b | pbrook | env->dregs[1] = errno;
|
63 | e6e5906b | pbrook | } else {
|
64 | e6e5906b | pbrook | env->dregs[1] = 0; |
65 | e6e5906b | pbrook | } |
66 | e6e5906b | pbrook | return code;
|
67 | e6e5906b | pbrook | } |
68 | e6e5906b | pbrook | |
69 | e6e5906b | pbrook | #define SIM_O_APPEND 0x0008 |
70 | e6e5906b | pbrook | #define SIM_O_CREAT 0x0200 |
71 | e6e5906b | pbrook | #define SIM_O_TRUNC 0x0400 |
72 | e6e5906b | pbrook | #define SIM_O_EXCL 0x0800 |
73 | e6e5906b | pbrook | #define SIM_O_NONBLOCK 0x4000 |
74 | e6e5906b | pbrook | #define SIM_O_NOCTTY 0x8000 |
75 | e6e5906b | pbrook | #define SIM_O_SYNC 0x2000 |
76 | e6e5906b | pbrook | |
77 | e6e5906b | pbrook | static int translate_openflags(int flags) |
78 | e6e5906b | pbrook | { |
79 | e6e5906b | pbrook | int hf;
|
80 | e6e5906b | pbrook | |
81 | e6e5906b | pbrook | switch (flags & 3) { |
82 | e6e5906b | pbrook | case 0: hf = O_RDONLY; break; |
83 | e6e5906b | pbrook | case 1: hf = O_WRONLY; break; |
84 | e6e5906b | pbrook | case 2: hf = O_RDWR; break; |
85 | e6e5906b | pbrook | default: hf = O_RDWR; break; |
86 | e6e5906b | pbrook | } |
87 | e6e5906b | pbrook | |
88 | e6e5906b | pbrook | if (flags & SIM_O_APPEND) hf |= O_APPEND;
|
89 | e6e5906b | pbrook | if (flags & SIM_O_CREAT) hf |= O_CREAT;
|
90 | e6e5906b | pbrook | if (flags & SIM_O_TRUNC) hf |= O_TRUNC;
|
91 | e6e5906b | pbrook | if (flags & SIM_O_EXCL) hf |= O_EXCL;
|
92 | e6e5906b | pbrook | if (flags & SIM_O_NONBLOCK) hf |= O_NONBLOCK;
|
93 | e6e5906b | pbrook | if (flags & SIM_O_NOCTTY) hf |= O_NOCTTY;
|
94 | e6e5906b | pbrook | if (flags & SIM_O_SYNC) hf |= O_SYNC;
|
95 | e6e5906b | pbrook | |
96 | e6e5906b | pbrook | return hf;
|
97 | e6e5906b | pbrook | } |
98 | e6e5906b | pbrook | |
99 | e6e5906b | pbrook | #define ARG(x) tswap32(args[x])
|
100 | e6e5906b | pbrook | void do_m68k_simcall(CPUM68KState *env, int nr) |
101 | e6e5906b | pbrook | { |
102 | e6e5906b | pbrook | uint32_t *args; |
103 | e6e5906b | pbrook | |
104 | 526ccb7a | balrog | args = (uint32_t *)(unsigned long)(env->aregs[7] + 4); |
105 | e6e5906b | pbrook | switch (nr) {
|
106 | e6e5906b | pbrook | case SYS_EXIT:
|
107 | e6e5906b | pbrook | exit(ARG(0));
|
108 | e6e5906b | pbrook | case SYS_READ:
|
109 | 526ccb7a | balrog | check_err(env, read(ARG(0), (void *)(unsigned long)ARG(1), ARG(2))); |
110 | e6e5906b | pbrook | break;
|
111 | e6e5906b | pbrook | case SYS_WRITE:
|
112 | 526ccb7a | balrog | check_err(env, write(ARG(0), (void *)(unsigned long)ARG(1), ARG(2))); |
113 | e6e5906b | pbrook | break;
|
114 | e6e5906b | pbrook | case SYS_OPEN:
|
115 | 526ccb7a | balrog | check_err(env, open((char *)(unsigned long)ARG(0), |
116 | 526ccb7a | balrog | translate_openflags(ARG(1)), ARG(2))); |
117 | e6e5906b | pbrook | break;
|
118 | e6e5906b | pbrook | case SYS_CLOSE:
|
119 | e6e5906b | pbrook | { |
120 | e6e5906b | pbrook | /* Ignore attempts to close stdin/out/err. */
|
121 | e6e5906b | pbrook | int fd = ARG(0); |
122 | e6e5906b | pbrook | if (fd > 2) |
123 | e6e5906b | pbrook | check_err(env, close(fd)); |
124 | e6e5906b | pbrook | else
|
125 | e6e5906b | pbrook | check_err(env, 0);
|
126 | e6e5906b | pbrook | break;
|
127 | e6e5906b | pbrook | } |
128 | e6e5906b | pbrook | case SYS_BRK:
|
129 | e6e5906b | pbrook | { |
130 | e6e5906b | pbrook | int32_t ret; |
131 | e6e5906b | pbrook | |
132 | ac2567b5 | bellard | ret = do_brk((abi_ulong)ARG(0));
|
133 | e6e5906b | pbrook | if (ret == -ENOMEM)
|
134 | e6e5906b | pbrook | ret = -1;
|
135 | e6e5906b | pbrook | check_err(env, ret); |
136 | e6e5906b | pbrook | } |
137 | e6e5906b | pbrook | break;
|
138 | e6e5906b | pbrook | case SYS_FSTAT:
|
139 | e6e5906b | pbrook | { |
140 | e6e5906b | pbrook | struct stat s;
|
141 | e6e5906b | pbrook | int rc;
|
142 | e6e5906b | pbrook | struct m86k_sim_stat *p;
|
143 | e6e5906b | pbrook | rc = check_err(env, fstat(ARG(0), &s));
|
144 | e6e5906b | pbrook | if (rc == 0) { |
145 | 526ccb7a | balrog | p = (struct m86k_sim_stat *)(unsigned long)ARG(1); |
146 | e6e5906b | pbrook | p->sim_st_dev = tswap16(s.st_dev); |
147 | e6e5906b | pbrook | p->sim_st_ino = tswap16(s.st_ino); |
148 | e6e5906b | pbrook | p->sim_st_mode = tswap32(s.st_mode); |
149 | e6e5906b | pbrook | p->sim_st_nlink = tswap16(s.st_nlink); |
150 | e6e5906b | pbrook | p->sim_st_uid = tswap16(s.st_uid); |
151 | e6e5906b | pbrook | p->sim_st_gid = tswap16(s.st_gid); |
152 | e6e5906b | pbrook | p->sim_st_rdev = tswap16(s.st_rdev); |
153 | e6e5906b | pbrook | p->sim_st_size = tswap32(s.st_size); |
154 | e6e5906b | pbrook | p->sim_st_atime = tswap32(s.st_atime); |
155 | e6e5906b | pbrook | p->sim_st_mtime = tswap32(s.st_mtime); |
156 | e6e5906b | pbrook | p->sim_st_ctime = tswap32(s.st_ctime); |
157 | e6e5906b | pbrook | p->sim_st_blksize = tswap32(s.st_blksize); |
158 | e6e5906b | pbrook | p->sim_st_blocks = tswap32(s.st_blocks); |
159 | e6e5906b | pbrook | } |
160 | e6e5906b | pbrook | } |
161 | e6e5906b | pbrook | break;
|
162 | e6e5906b | pbrook | case SYS_ISATTY:
|
163 | e6e5906b | pbrook | check_err(env, isatty(ARG(0)));
|
164 | e6e5906b | pbrook | break;
|
165 | e6e5906b | pbrook | case SYS_LSEEK:
|
166 | e6e5906b | pbrook | check_err(env, lseek(ARG(0), (int32_t)ARG(1), ARG(2))); |
167 | e6e5906b | pbrook | break;
|
168 | e6e5906b | pbrook | default:
|
169 | e6e5906b | pbrook | cpu_abort(env, "Unsupported m68k sim syscall %d\n", nr);
|
170 | e6e5906b | pbrook | } |
171 | e6e5906b | pbrook | } |