root / linux-user / m68k-sim.c @ 0497d2f4
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 | 530e7615 | blueswir1 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
19 | 530e7615 | blueswir1 | * MA 02110-1301, USA.
|
20 | e6e5906b | pbrook | */
|
21 | e6e5906b | pbrook | |
22 | e6e5906b | pbrook | #include <sys/types.h> |
23 | e6e5906b | pbrook | #include <sys/stat.h> |
24 | e6e5906b | pbrook | #include <errno.h> |
25 | e6e5906b | pbrook | #include <fcntl.h> |
26 | e6e5906b | pbrook | #include <unistd.h> |
27 | e6e5906b | pbrook | #include <stdlib.h> |
28 | e6e5906b | pbrook | #include <stdio.h> |
29 | e6e5906b | pbrook | #include <time.h> |
30 | e6e5906b | pbrook | |
31 | e6e5906b | pbrook | #include "qemu.h" |
32 | e6e5906b | pbrook | |
33 | e6e5906b | pbrook | #define SYS_EXIT 1 |
34 | e6e5906b | pbrook | #define SYS_READ 3 |
35 | e6e5906b | pbrook | #define SYS_WRITE 4 |
36 | e6e5906b | pbrook | #define SYS_OPEN 5 |
37 | e6e5906b | pbrook | #define SYS_CLOSE 6 |
38 | e6e5906b | pbrook | #define SYS_BRK 17 |
39 | e6e5906b | pbrook | #define SYS_FSTAT 28 |
40 | e6e5906b | pbrook | #define SYS_ISATTY 29 |
41 | e6e5906b | pbrook | #define SYS_LSEEK 199 |
42 | e6e5906b | pbrook | |
43 | e6e5906b | pbrook | struct m86k_sim_stat {
|
44 | e6e5906b | pbrook | uint16_t sim_st_dev; |
45 | e6e5906b | pbrook | uint16_t sim_st_ino; |
46 | e6e5906b | pbrook | uint32_t sim_st_mode; |
47 | e6e5906b | pbrook | uint16_t sim_st_nlink; |
48 | e6e5906b | pbrook | uint16_t sim_st_uid; |
49 | e6e5906b | pbrook | uint16_t sim_st_gid; |
50 | e6e5906b | pbrook | uint16_t sim_st_rdev; |
51 | e6e5906b | pbrook | uint32_t sim_st_size; |
52 | e6e5906b | pbrook | uint32_t sim_st_atime; |
53 | e6e5906b | pbrook | uint32_t sim_st_mtime; |
54 | e6e5906b | pbrook | uint32_t sim_st_ctime; |
55 | e6e5906b | pbrook | uint32_t sim_st_blksize; |
56 | e6e5906b | pbrook | uint32_t sim_st_blocks; |
57 | e6e5906b | pbrook | }; |
58 | e6e5906b | pbrook | |
59 | e6e5906b | pbrook | static inline uint32_t check_err(CPUM68KState *env, uint32_t code) |
60 | e6e5906b | pbrook | { |
61 | e6e5906b | pbrook | env->dregs[0] = code;
|
62 | e6e5906b | pbrook | if (code == (uint32_t)-1) { |
63 | e6e5906b | pbrook | env->dregs[1] = errno;
|
64 | e6e5906b | pbrook | } else {
|
65 | e6e5906b | pbrook | env->dregs[1] = 0; |
66 | e6e5906b | pbrook | } |
67 | e6e5906b | pbrook | return code;
|
68 | e6e5906b | pbrook | } |
69 | e6e5906b | pbrook | |
70 | e6e5906b | pbrook | #define SIM_O_APPEND 0x0008 |
71 | e6e5906b | pbrook | #define SIM_O_CREAT 0x0200 |
72 | e6e5906b | pbrook | #define SIM_O_TRUNC 0x0400 |
73 | e6e5906b | pbrook | #define SIM_O_EXCL 0x0800 |
74 | e6e5906b | pbrook | #define SIM_O_NONBLOCK 0x4000 |
75 | e6e5906b | pbrook | #define SIM_O_NOCTTY 0x8000 |
76 | e6e5906b | pbrook | #define SIM_O_SYNC 0x2000 |
77 | e6e5906b | pbrook | |
78 | e6e5906b | pbrook | static int translate_openflags(int flags) |
79 | e6e5906b | pbrook | { |
80 | e6e5906b | pbrook | int hf;
|
81 | e6e5906b | pbrook | |
82 | e6e5906b | pbrook | switch (flags & 3) { |
83 | e6e5906b | pbrook | case 0: hf = O_RDONLY; break; |
84 | e6e5906b | pbrook | case 1: hf = O_WRONLY; break; |
85 | e6e5906b | pbrook | case 2: hf = O_RDWR; break; |
86 | e6e5906b | pbrook | default: hf = O_RDWR; break; |
87 | e6e5906b | pbrook | } |
88 | e6e5906b | pbrook | |
89 | e6e5906b | pbrook | if (flags & SIM_O_APPEND) hf |= O_APPEND;
|
90 | e6e5906b | pbrook | if (flags & SIM_O_CREAT) hf |= O_CREAT;
|
91 | e6e5906b | pbrook | if (flags & SIM_O_TRUNC) hf |= O_TRUNC;
|
92 | e6e5906b | pbrook | if (flags & SIM_O_EXCL) hf |= O_EXCL;
|
93 | e6e5906b | pbrook | if (flags & SIM_O_NONBLOCK) hf |= O_NONBLOCK;
|
94 | e6e5906b | pbrook | if (flags & SIM_O_NOCTTY) hf |= O_NOCTTY;
|
95 | e6e5906b | pbrook | if (flags & SIM_O_SYNC) hf |= O_SYNC;
|
96 | e6e5906b | pbrook | |
97 | e6e5906b | pbrook | return hf;
|
98 | e6e5906b | pbrook | } |
99 | e6e5906b | pbrook | |
100 | e6e5906b | pbrook | #define ARG(x) tswap32(args[x])
|
101 | e6e5906b | pbrook | void do_m68k_simcall(CPUM68KState *env, int nr) |
102 | e6e5906b | pbrook | { |
103 | e6e5906b | pbrook | uint32_t *args; |
104 | e6e5906b | pbrook | |
105 | 526ccb7a | balrog | args = (uint32_t *)(unsigned long)(env->aregs[7] + 4); |
106 | e6e5906b | pbrook | switch (nr) {
|
107 | e6e5906b | pbrook | case SYS_EXIT:
|
108 | e6e5906b | pbrook | exit(ARG(0));
|
109 | e6e5906b | pbrook | case SYS_READ:
|
110 | 526ccb7a | balrog | check_err(env, read(ARG(0), (void *)(unsigned long)ARG(1), ARG(2))); |
111 | e6e5906b | pbrook | break;
|
112 | e6e5906b | pbrook | case SYS_WRITE:
|
113 | 526ccb7a | balrog | check_err(env, write(ARG(0), (void *)(unsigned long)ARG(1), ARG(2))); |
114 | e6e5906b | pbrook | break;
|
115 | e6e5906b | pbrook | case SYS_OPEN:
|
116 | 526ccb7a | balrog | check_err(env, open((char *)(unsigned long)ARG(0), |
117 | 526ccb7a | balrog | translate_openflags(ARG(1)), ARG(2))); |
118 | e6e5906b | pbrook | break;
|
119 | e6e5906b | pbrook | case SYS_CLOSE:
|
120 | e6e5906b | pbrook | { |
121 | e6e5906b | pbrook | /* Ignore attempts to close stdin/out/err. */
|
122 | e6e5906b | pbrook | int fd = ARG(0); |
123 | e6e5906b | pbrook | if (fd > 2) |
124 | e6e5906b | pbrook | check_err(env, close(fd)); |
125 | e6e5906b | pbrook | else
|
126 | e6e5906b | pbrook | check_err(env, 0);
|
127 | e6e5906b | pbrook | break;
|
128 | e6e5906b | pbrook | } |
129 | e6e5906b | pbrook | case SYS_BRK:
|
130 | e6e5906b | pbrook | { |
131 | e6e5906b | pbrook | int32_t ret; |
132 | e6e5906b | pbrook | |
133 | ac2567b5 | bellard | ret = do_brk((abi_ulong)ARG(0));
|
134 | e6e5906b | pbrook | if (ret == -ENOMEM)
|
135 | e6e5906b | pbrook | ret = -1;
|
136 | e6e5906b | pbrook | check_err(env, ret); |
137 | e6e5906b | pbrook | } |
138 | e6e5906b | pbrook | break;
|
139 | e6e5906b | pbrook | case SYS_FSTAT:
|
140 | e6e5906b | pbrook | { |
141 | e6e5906b | pbrook | struct stat s;
|
142 | e6e5906b | pbrook | int rc;
|
143 | e6e5906b | pbrook | struct m86k_sim_stat *p;
|
144 | e6e5906b | pbrook | rc = check_err(env, fstat(ARG(0), &s));
|
145 | e6e5906b | pbrook | if (rc == 0) { |
146 | 526ccb7a | balrog | p = (struct m86k_sim_stat *)(unsigned long)ARG(1); |
147 | e6e5906b | pbrook | p->sim_st_dev = tswap16(s.st_dev); |
148 | e6e5906b | pbrook | p->sim_st_ino = tswap16(s.st_ino); |
149 | e6e5906b | pbrook | p->sim_st_mode = tswap32(s.st_mode); |
150 | e6e5906b | pbrook | p->sim_st_nlink = tswap16(s.st_nlink); |
151 | e6e5906b | pbrook | p->sim_st_uid = tswap16(s.st_uid); |
152 | e6e5906b | pbrook | p->sim_st_gid = tswap16(s.st_gid); |
153 | e6e5906b | pbrook | p->sim_st_rdev = tswap16(s.st_rdev); |
154 | e6e5906b | pbrook | p->sim_st_size = tswap32(s.st_size); |
155 | e6e5906b | pbrook | p->sim_st_atime = tswap32(s.st_atime); |
156 | e6e5906b | pbrook | p->sim_st_mtime = tswap32(s.st_mtime); |
157 | e6e5906b | pbrook | p->sim_st_ctime = tswap32(s.st_ctime); |
158 | e6e5906b | pbrook | p->sim_st_blksize = tswap32(s.st_blksize); |
159 | e6e5906b | pbrook | p->sim_st_blocks = tswap32(s.st_blocks); |
160 | e6e5906b | pbrook | } |
161 | e6e5906b | pbrook | } |
162 | e6e5906b | pbrook | break;
|
163 | e6e5906b | pbrook | case SYS_ISATTY:
|
164 | e6e5906b | pbrook | check_err(env, isatty(ARG(0)));
|
165 | e6e5906b | pbrook | break;
|
166 | e6e5906b | pbrook | case SYS_LSEEK:
|
167 | e6e5906b | pbrook | check_err(env, lseek(ARG(0), (int32_t)ARG(1), ARG(2))); |
168 | e6e5906b | pbrook | break;
|
169 | e6e5906b | pbrook | default:
|
170 | e6e5906b | pbrook | cpu_abort(env, "Unsupported m68k sim syscall %d\n", nr);
|
171 | e6e5906b | pbrook | } |
172 | e6e5906b | pbrook | } |