summaryrefslogtreecommitdiff
path: root/other/wrez/int80.h
blob: 0701ba7a31a178be3d5bd3745b7b6833f02e7c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#ifndef	INT80_H
#define	INT80_H

#include "unistd.h"

#ifndef _I386_FCNTL_H
#define O_RDONLY    00
#define O_WRONLY    01
#define O_RDWR      02
#define O_CREAT   0100
#define O_TRUNC  01000
#define O_APPEND 02000
#define F_DUPFD		0	/* Duplicate file descriptor.  */
#define F_GETFD		1	/* Get file descriptor flags.  */
#define F_SETFD		2	/* Set file descriptor flags.  */
#define F_GETFL		3	/* Get file status flags.  */
#define F_SETFL		4	/* Set file status flags.  */
#endif

/* from bits/termios.h */
#define	TCGETS		0x5401
#define	TCSETS		0x5402
#define	TCSETSW		0x5403
#define	TCSETSF		0x5404

#define	ISIG	0000001
#define	ECHO	0000010


/* wait bits
 */
#define	WNOHANG		0x01
#define	WUNTRACED	0x02

#define	WEXITSTATUS(status)	(((status) & 0xff00) >> 8)

/* If WIFSIGNALED(STATUS), the terminating signal.  */
#define	WTERMSIG(status)	((status) & 0x7f)

/* If WIFSTOPPED(STATUS), the signal that stopped the child.  */
#define	WSTOPSIG(status)	WEXITSTATUS(status)

/* Nonzero if STATUS indicates normal termination.  */
#define	WIFEXITED(status)	(WTERMSIG(status) == 0)

#define WIFSIGNALED(status)	(!WIFSTOPPED(status) && !WIFEXITED(status))

/* Nonzero if STATUS indicates the child is stopped.  */
#define	WIFSTOPPED(status)	(((status) & 0xff) == 0x7f)

/* Nonzero if STATUS indicates the child dumped core.  */
#define	WCOREDUMP(status)	((status) & WCOREFLAG)

/* Macros for constructing status values.  */
#define	W_EXITCODE(ret, sig)	((ret) << 8 | (sig))
#define	W_STOPCODE(sig)	((sig) << 8 | 0x7f)
#define	WCOREFLAG		0x80


typedef unsigned char	cc_t;
typedef unsigned int	speed_t;
typedef unsigned int	tcflag_t;

#define	NCCS	32

typedef struct {
	tcflag_t	c_iflag;	/* input mode flags */
	tcflag_t	c_oflag;	/* output mode flags */
	tcflag_t	c_cflag;	/* control mode flags */
	tcflag_t	c_lflag;	/* local mode flags */
	cc_t		c_line;		/* line discipline */
	cc_t		c_cc[NCCS];	/* control characters */
	speed_t		c_ispeed;	/* input speed */
	speed_t		c_ospeed;	/* output speed */
} termios;

/* from bits/utsname.h and sys/utsname.h */
#define _UTSNAME_LENGTH 65
#define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH
#define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH

struct utsname {
	char	sysname[_UTSNAME_LENGTH];
	char	nodename[_UTSNAME_NODENAME_LENGTH];
	char	release[_UTSNAME_LENGTH];
	char	version[_UTSNAME_LENGTH];
	char	machine[_UTSNAME_LENGTH];
	char	domainname[_UTSNAME_DOMAIN_LENGTH];
};


typedef struct {
	unsigned long	__val[2];
} __u_quad_t;

struct stat {
	unsigned char	space1[6 * 4];
	/* __uid_t */	unsigned int st_uid;	/* User ID of the file's owner. */
	/* __gid_t */	unsigned int st_gid;	/* Group ID of the file's group. */
	unsigned char	space2[8 * 4];
	/* __time_t */	long int st_atime;	/* Time of last access. */
	unsigned long int	 __unused1;
	/* __time_t */	long int st_mtime;	/* Time of last modification. */
	unsigned long int	__unused2;
	/* __time_t */	long int st_ctime;	/* Time of last status change. */
	unsigned long int	space3[8 * 4];	/* safety margin */
};

#if 0
struct stat {
	/* __dev_t */	__u_quad_t st_dev;	/* Device.  */
	unsigned short int	__pad1;
	/* __ino_t */	unsigned long st_ino;	/* File serial number. */
	/* __mode_t */	unsigned int st_mode;	/* File mode. */
	/* __nlink_t */	unsigned int st_nlink;	/* Link count. */
	/* __uid_t */	unsigned int st_uid;	/* User ID of the file's owner. */
	/* __gid_t */	unsigned int st_gid;	/* Group ID of the file's group. */
	/* __dev_t */	__u_quad_t st_rdev;	/* Device number, if device. */
	unsigned short int	__pad2;
	/* __off_t */	long int st_size;	/* Size of file, in bytes. */
	/* __blksize_t*/long int st_blksize;	/* Optimal block size for I/O. */

	/* __blkcnt_t */long int st_blocks;	/* Number 512-byte blocks allocated. */
	/* __time_t */	long int st_atime;	/* Time of last access. */
	unsigned long int	 __unused1;
	/* __time_t */	long int st_mtime;	/* Time of last modification. */
	unsigned long int	__unused2;
	/* __time_t */	long int st_ctime;	/* Time of last status change. */
	unsigned long int	__unused3;
	unsigned long int	__unused4;
	unsigned long int	__unused5;
};
#endif

struct utimbuf {
	/* time_t */	long int actime;	/* access time */
	/* time_t */	long int modtime;	/* modification time */
};

struct timeval {
	long int	tv_sec;		/* seconds */
	long int	tv_usec;	/* microseconds */
};

struct dirent {
	long		d_ino;
	int		d_off;
	unsigned short	d_reclen;
	char		d_name[256];
};

/* from bits/mman.h */
#define	PROT_READ	0x1
#define	PROT_WRITE	0x2
#define	PROT_EXEC	0x4
#define	PROT_NONE	0x0
#define	MAP_SHARED	0x01
#define	MAP_PRIVATE	0x02
#define	MAP_TYPE	0x0f
#define	MAP_FIXED	0x10
#define	MAP_ANONYMOUS	0x20

/* from unistd.h */
#define	SEEK_SET	0
#define	SEEK_CUR	1
#define	SEEK_END	2

extern int	errno;

static inline int getdents (int fd, struct dirent *dirp, unsigned int count)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_getdents), "b" ((long) fd),
			"c" ((long) dirp), "d" ((long) count));

	return ret;
}

static inline int settimeofday (struct timeval *tv, void *tz)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_settimeofday), "b" ((long) tv),
			"c" ((long) tz));

	return ret;
}

static inline int gettimeofday (struct timeval *tv, void *tz)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_gettimeofday), "b" ((long) tv),
			"c" ((long) tz));

	return ret;
}

static inline int stat (char *filename, struct stat *sst)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_stat64), "b" ((long) filename),
			"c" ((long) sst));

	return ret;
}

static inline int utime (char *filename, struct utimbuf *buf)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_utime), "b" ((long) filename),
			"c" ((long) buf));

	return ret;
}

static inline int munmap (char *start, int length)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_munmap), "b" ((long) start),
			"c" ((int) length));

	return ret;
}

#if 0
static inline int ioctl (int d, int request, int argp)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_ioctl), "S" ((long)d),
			      "c" ((long)request), "d" ((long)argp): "bx");
	return ret;
}

static inline int fcntl (int fd, int cmd, long arg)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_fcntl), "S" ((long)fd),
			      "c" ((long)cmd), "d" ((long)arg): "bx");
	return ret;
}
#endif

static inline int lseek (int fd, unsigned long int offset, int whence)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_lseek), "b" ((long) fd),
			"c" ((long) offset), "d" ((long) whence));

	return ret;
}

#if 0
static inline int mprotect(void *addr, long len, int prot)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_mprotect), "S" ((long)addr),
			      "c" ((long)len), "d" ((long)prot): "bx");
	return ret;
}
#endif


static inline int read(int fd, void *buf, long count)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_read), "b" ((long) fd),
			"c" ((long) buf), "d" ((long) count));

	return ret;
}


static inline int write(int fd, void *buf, long count)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_write), "b" ((long) fd),
			"c" ((long) buf), "d" ((long) count));

	return ret;
}

static inline int waitpid (int pid, int *status, int options)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_waitpid), "b" ((long) pid),
			"c" ((long) status), "d" ((long) options));

	return ret;
}

#define	wait(status) waitpid(-1,status,0)

static inline int unlink (char *pathname)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_unlink), "b" ((long)pathname));

	return ret;
}

static inline int uname(struct utsname *un)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_uname), "b" ((long) un));
	return ret;
}


static inline int execve(char *s, char **argv, char **envp)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
			     :"=a" (ret)
			     :"a" (__NR_execve), "b" ((long)s),
			      "c" ((long)argv), "d" ((long)envp));
	return ret;
}


#if 0

static inline int setreuid(int reuid, int euid)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_setreuid), "S" ((long)reuid),
			      "c" ((long)euid): "bx");
	return ret;
}

static inline int chroot(char *path)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_chroot), "S" ((long)path): "bx");
	return ret;
}

static inline int brk(void *addr)
{
	long	ret;

	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			      :"=a" (ret)
			      :"0" (__NR_brk), "S" (addr): "bx");
	return (ret);
}

static inline int dup(int fd)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_dup), "S" (fd): "bx");
	return ret;
}


#endif

static inline int _exit(int level)
{
	long	ret;

	__asm__ __volatile__ ("int $0x80"
			      :"=a" (ret)
			      :"a" (__NR_exit), "b" (level));
	return (ret);
}

static inline int dup2(int ofd, int nfd)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
			     :"=a" (ret)
			     :"a" (__NR_dup2), "b" (ofd), "c" (nfd));
	return ret;
}

static inline int open(char *path, int mode, int flags)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_open), "b" ((long) path),
			"c" ((int) mode), "d" ((int) flags));

	return ret;
}



#if 0
static inline int chdir(char *path)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_chdir), "S" ((long)path): "bx");
	return ret;
}
#endif

static inline int close(int fd)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
			     :"=a" (ret)
			     :"a" (__NR_close), "b" ((int)fd));
	return ret;
}


static inline int chown(char *path, int uid, int gid)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_chown), "b" ((long)path),
			"c" ((int)uid), "d" ((int)gid));

	return ret;
}

static inline int rename(char *oldpath, char *newpath)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
		: "=a" (ret)
		: "a" (__NR_rename), "b" ((long)oldpath),
			"c" ((int) newpath));
	return ret;
}

#if 0
static inline int chmod(char *path, int mode)
{
	long ret;
	
	__asm__ __volatile__ ("pushl %%ebx\n\t"
			      "movl %%esi, %%ebx\n\t"
			      "int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_chmod), "S" ((long)path),
			      "c" ((int)mode): "bx");
	return ret;
}

static inline int sync(void)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_sync));

	return (ret);
}

static inline int antistrace(void)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x03\n\t"
			     :"=a" (ret)
			     : );
	return (ret);
}
#endif

#define	SIG_DFL	0
#define	SIGHUP	1
#define	SIGINT	2
#define	SIGQUIT	3
#define	SIGILL	4
#define	SIGTRAP	5
#define	SIGABRT	6
#define	SIGFPE	8
#define	SIGKILL	9
#define	SIGUSR1	10
#define	SIGSEGV	11
#define	SIGUSR2	12
#define	SIGPIPE	13
#define	SIGALRM	14
#define	SIGTERM	15
#define	SIGCHLD	17
#define	SIGCONT	18
#define	SIGSTOP	19

static inline int signal(int signum, void *handler)
{
	long ret;
	
	__asm__ __volatile__ ("int $0x80"
			     :"=a" (ret)
			     :"a" (__NR_signal), "b" ((long)signum),
			      "c" ((int)handler));
	return ret;
}

static inline int fork(void)
{
	long ret;

	__asm__ __volatile__ ("int $0x80"
			     :"=a" (ret)
			     :"0" (__NR_fork));

	return (ret);
}


#endif