1 | /* |
---|
2 | * hosted & unhosted io support. |
---|
3 | * |
---|
4 | * Copyright (c) 2006 CodeSourcery Inc |
---|
5 | * |
---|
6 | * The authors hereby grant permission to use, copy, modify, distribute, |
---|
7 | * and license this software and its documentation for any purpose, provided |
---|
8 | * that existing copyright notices are retained in all copies and that this |
---|
9 | * notice is included verbatim in any distributions. No written agreement, |
---|
10 | * license, or royalty fee is required for any of the authorized uses. |
---|
11 | * Modifications to this software may be copyrighted by their authors |
---|
12 | * and need not follow the licensing terms described here, provided that |
---|
13 | * the new terms are clearly indicated on the first page of each file where |
---|
14 | * they apply. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HOSTED |
---|
18 | #include <stdint.h> |
---|
19 | #include <sys/types.h> |
---|
20 | #include <sys/time.h> |
---|
21 | #include <sys/stat.h> |
---|
22 | |
---|
23 | #define HOSTED_EXIT 0 |
---|
24 | #define HOSTED_INIT_SIM 1 |
---|
25 | #define HOSTED_OPEN 2 |
---|
26 | #define HOSTED_CLOSE 3 |
---|
27 | #define HOSTED_READ 4 |
---|
28 | #define HOSTED_WRITE 5 |
---|
29 | #define HOSTED_LSEEK 6 |
---|
30 | #define HOSTED_RENAME 7 |
---|
31 | #define HOSTED_UNLINK 8 |
---|
32 | #define HOSTED_STAT 9 |
---|
33 | #define HOSTED_FSTAT 10 |
---|
34 | #define HOSTED_GETTIMEOFDAY 11 |
---|
35 | #define HOSTED_ISATTY 12 |
---|
36 | #define HOSTED_SYSTEM 13 |
---|
37 | |
---|
38 | /* This function is provided by the board's BSP, because the precise |
---|
39 | mechanism of informing gdb is board specific. */ |
---|
40 | extern int __io_hosted (int func, void *args); |
---|
41 | |
---|
42 | /* Protocol specific representation of datatypes, as specified in D.9.11 |
---|
43 | * of the GDB manual. |
---|
44 | * Note that since the m68k is big-endian, we can use native |
---|
45 | * representations of integer datatypes in structured datatypes. */ |
---|
46 | |
---|
47 | typedef uint32_t gdb_mode_t; |
---|
48 | typedef uint32_t gdb_time_t; |
---|
49 | |
---|
50 | struct gdb_stat { |
---|
51 | uint32_t st_dev; /* device */ |
---|
52 | uint32_t st_ino; /* inode */ |
---|
53 | gdb_mode_t st_mode; /* protection */ |
---|
54 | uint32_t st_nlink; /* number of hard links */ |
---|
55 | uint32_t st_uid; /* user ID of owner */ |
---|
56 | uint32_t st_gid; /* group ID of owner */ |
---|
57 | uint32_t st_rdev; /* device type (if inode device) */ |
---|
58 | uint64_t st_size; /* total size, in bytes */ |
---|
59 | uint64_t st_blksize; /* blocksize for filesystem I/O */ |
---|
60 | uint64_t st_blocks; /* number of blocks allocated */ |
---|
61 | gdb_time_t st_atime; /* time of last access */ |
---|
62 | gdb_time_t st_mtime; /* time of last modification */ |
---|
63 | gdb_time_t st_ctime; /* time of last change */ |
---|
64 | }; |
---|
65 | |
---|
66 | struct gdb_timeval { |
---|
67 | gdb_time_t tv_sec; /* second */ |
---|
68 | uint64_t tv_usec; /* microsecond */ |
---|
69 | }; |
---|
70 | |
---|
71 | |
---|
72 | /* Parameters are passed between the library and the debugging stub |
---|
73 | * in a fixed-size buffer. |
---|
74 | */ |
---|
75 | |
---|
76 | typedef uint32_t gdb_parambuf_t[4]; |
---|
77 | |
---|
78 | /* open flags */ |
---|
79 | |
---|
80 | #define GDB_O_RDONLY 0x0 |
---|
81 | #define GDB_O_WRONLY 0x1 |
---|
82 | #define GDB_O_RDWR 0x2 |
---|
83 | #define GDB_O_APPEND 0x8 |
---|
84 | #define GDB_O_CREAT 0x200 |
---|
85 | #define GDB_O_TRUNC 0x400 |
---|
86 | #define GDB_O_EXCL 0x800 |
---|
87 | |
---|
88 | /* mode_t values */ |
---|
89 | |
---|
90 | #define GDB_S_IFREG 0100000 |
---|
91 | #define GDB_S_IFDIR 040000 |
---|
92 | #define GDB_S_IRUSR 0400 |
---|
93 | #define GDB_S_IWUSR 0200 |
---|
94 | #define GDB_S_IXUSR 0100 |
---|
95 | #define GDB_S_IRGRP 040 |
---|
96 | #define GDB_S_IWGRP 020 |
---|
97 | #define GDB_S_IXGRP 010 |
---|
98 | #define GDB_S_IROTH 04 |
---|
99 | #define GDB_S_IWOTH 02 |
---|
100 | #define GDB_S_IXOTH 01 |
---|
101 | |
---|
102 | /* errno values */ |
---|
103 | |
---|
104 | #define GDB_EPERM 1 |
---|
105 | #define GDB_ENOENT 2 |
---|
106 | #define GDB_EINTR 4 |
---|
107 | #define GDB_EBADF 9 |
---|
108 | #define GDB_EACCES 13 |
---|
109 | #define GDB_EFAULT 14 |
---|
110 | #define GDB_EBUSY 16 |
---|
111 | #define GDB_EEXIST 17 |
---|
112 | #define GDB_ENODEV 19 |
---|
113 | #define GDB_ENOTDIR 20 |
---|
114 | #define GDB_EISDIR 21 |
---|
115 | #define GDB_EINVAL 22 |
---|
116 | #define GDB_ENFILE 23 |
---|
117 | #define GDB_EMFILE 24 |
---|
118 | #define GDB_EFBIG 27 |
---|
119 | #define GDB_ENOSPC 28 |
---|
120 | #define GDB_ESPIPE 29 |
---|
121 | #define GDB_EROFS 30 |
---|
122 | #define GDB_ENAMETOOLONG 91 |
---|
123 | #define GDB_EUNKNOWN 9999 |
---|
124 | |
---|
125 | /* lseek flags */ |
---|
126 | |
---|
127 | #define GDB_SEEK_SET 0 |
---|
128 | #define GDB_SEEK_CUR 1 |
---|
129 | #define GDB_SEEK_END 2 |
---|
130 | |
---|
131 | |
---|
132 | /* conversion functions */ |
---|
133 | |
---|
134 | extern gdb_mode_t __hosted_to_gdb_mode_t (mode_t m); |
---|
135 | extern int32_t __hosted_to_gdb_open_flags (int f); |
---|
136 | extern int32_t __hosted_to_gdb_lseek_flags (int f); |
---|
137 | |
---|
138 | extern void __hosted_from_gdb_stat (const struct gdb_stat *gs, |
---|
139 | struct stat *s); |
---|
140 | extern void __hosted_from_gdb_timeval (const struct gdb_timeval *gt, |
---|
141 | struct timeval *t); |
---|
142 | extern int __hosted_from_gdb_errno (int32_t err); |
---|
143 | |
---|
144 | #else |
---|
145 | #ifdef IO |
---|
146 | #define IO_NAME_(IO) __hosted_##IO |
---|
147 | #define IO_NAME(IO) IO_NAME_(IO) |
---|
148 | #define IO_STRING_(IO) #IO |
---|
149 | #define IO_STRING(IO) IO_STRING_(IO) |
---|
150 | /* Emit an object that causes a gnu linker warning. */ |
---|
151 | static const char IO_NAME (IO) [] |
---|
152 | __attribute__ ((section (".gnu.warning"), used)) = |
---|
153 | "IO function '" IO_STRING (IO) "' used"; |
---|
154 | #endif |
---|
155 | #endif |
---|