summaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-01-23 10:41:10 +0800
committerWe-unite <3205135446@qq.com>2025-01-23 10:41:10 +0800
commite6f77b7ea3e38c9853bee60b275f3f89d252a5b3 (patch)
tree80bfbabed9d4cbcf9fa62677f78b34279d7e2f87 /src/include
downloadlinux-0.11-master.tar.gz
linux-0.11-master.zip
Initial commit, makee it usable on newest linuxHEADmaster
Diffstat (limited to 'src/include')
-rw-r--r--src/include/a.out.h220
-rw-r--r--src/include/asm/io.h24
-rw-r--r--src/include/asm/memory.h14
-rw-r--r--src/include/asm/segment.h65
-rw-r--r--src/include/asm/system.h67
-rw-r--r--src/include/const.h15
-rw-r--r--src/include/ctype.h34
-rw-r--r--src/include/errno.h60
-rw-r--r--src/include/fcntl.h55
-rw-r--r--src/include/linux/config.h48
-rw-r--r--src/include/linux/fdreg.h71
-rw-r--r--src/include/linux/fs.h202
-rw-r--r--src/include/linux/hdreg.h65
-rw-r--r--src/include/linux/head.h20
-rw-r--r--src/include/linux/kernel.h22
-rw-r--r--src/include/linux/mm.h10
-rw-r--r--src/include/linux/sched.h256
-rw-r--r--src/include/linux/sys.h86
-rw-r--r--src/include/linux/tty.h77
-rw-r--r--src/include/signal.h68
-rw-r--r--src/include/stdarg.h28
-rw-r--r--src/include/stddef.h19
-rw-r--r--src/include/string.h47
-rw-r--r--src/include/sys/stat.h58
-rw-r--r--src/include/sys/times.h15
-rw-r--r--src/include/sys/types.h46
-rw-r--r--src/include/sys/utsname.h16
-rw-r--r--src/include/sys/wait.h23
-rw-r--r--src/include/termios.h228
-rw-r--r--src/include/time.h42
-rw-r--r--src/include/unistd.h254
-rw-r--r--src/include/utime.h13
32 files changed, 2268 insertions, 0 deletions
diff --git a/src/include/a.out.h b/src/include/a.out.h
new file mode 100644
index 0000000..3e67974
--- /dev/null
+++ b/src/include/a.out.h
@@ -0,0 +1,220 @@
1#ifndef _A_OUT_H
2#define _A_OUT_H
3
4#define __GNU_EXEC_MACROS__
5
6struct exec {
7 unsigned long a_magic; /* Use macros N_MAGIC, etc for access */
8 unsigned a_text; /* length of text, in bytes */
9 unsigned a_data; /* length of data, in bytes */
10 unsigned a_bss; /* length of uninitialized data area for file, in bytes */
11 unsigned a_syms; /* length of symbol table data in file, in bytes */
12 unsigned a_entry; /* start address */
13 unsigned a_trsize; /* length of relocation info for text, in bytes */
14 unsigned a_drsize; /* length of relocation info for data, in bytes */
15};
16
17#ifndef N_MAGIC
18#define N_MAGIC(exec) ((exec).a_magic)
19#endif
20
21#ifndef OMAGIC
22/* Code indicating object file or impure executable. */
23#define OMAGIC 0407
24/* Code indicating pure executable. */
25#define NMAGIC 0410
26/* Code indicating demand-paged executable. */
27#define ZMAGIC 0413
28#endif /* not OMAGIC */
29
30#ifndef N_BADMAG
31#define N_BADMAG(x) \
32 (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
33 && N_MAGIC(x) != ZMAGIC)
34#endif
35
36#define _N_BADMAG(x) \
37 (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
38 && N_MAGIC(x) != ZMAGIC)
39
40#define _N_HDROFF(x) (SEGMENT_SIZE - sizeof (struct exec))
41
42#ifndef N_TXTOFF
43#define N_TXTOFF(x) \
44 (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec))
45#endif
46
47#ifndef N_DATOFF
48#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
49#endif
50
51#ifndef N_TRELOFF
52#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
53#endif
54
55#ifndef N_DRELOFF
56#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
57#endif
58
59#ifndef N_SYMOFF
60#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
61#endif
62
63#ifndef N_STROFF
64#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
65#endif
66
67/* Address of text segment in memory after it is loaded. */
68#ifndef N_TXTADDR
69#define N_TXTADDR(x) 0
70#endif
71
72/* Address of data segment in memory after it is loaded.
73 Note that it is up to you to define SEGMENT_SIZE
74 on machines not listed here. */
75#if defined(vax) || defined(hp300) || defined(pyr)
76#define SEGMENT_SIZE PAGE_SIZE
77#endif
78#ifdef hp300
79#define PAGE_SIZE 4096
80#endif
81#ifdef sony
82#define SEGMENT_SIZE 0x2000
83#endif /* Sony. */
84#ifdef is68k
85#define SEGMENT_SIZE 0x20000
86#endif
87#if defined(m68k) && defined(PORTAR)
88#define PAGE_SIZE 0x400
89#define SEGMENT_SIZE PAGE_SIZE
90#endif
91
92#define PAGE_SIZE 4096
93#define SEGMENT_SIZE 1024
94
95#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
96
97#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
98
99#ifndef N_DATADDR
100#define N_DATADDR(x) \
101 (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
102 : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
103#endif
104
105/* Address of bss segment in memory after it is loaded. */
106#ifndef N_BSSADDR
107#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
108#endif
109
110#ifndef N_NLIST_DECLARED
111struct nlist {
112 union {
113 char *n_name;
114 struct nlist *n_next;
115 long n_strx;
116 } n_un;
117 unsigned char n_type;
118 char n_other;
119 short n_desc;
120 unsigned long n_value;
121};
122#endif
123
124#ifndef N_UNDF
125#define N_UNDF 0
126#endif
127#ifndef N_ABS
128#define N_ABS 2
129#endif
130#ifndef N_TEXT
131#define N_TEXT 4
132#endif
133#ifndef N_DATA
134#define N_DATA 6
135#endif
136#ifndef N_BSS
137#define N_BSS 8
138#endif
139#ifndef N_COMM
140#define N_COMM 18
141#endif
142#ifndef N_FN
143#define N_FN 15
144#endif
145
146#ifndef N_EXT
147#define N_EXT 1
148#endif
149#ifndef N_TYPE
150#define N_TYPE 036
151#endif
152#ifndef N_STAB
153#define N_STAB 0340
154#endif
155
156/* The following type indicates the definition of a symbol as being
157 an indirect reference to another symbol. The other symbol
158 appears as an undefined reference, immediately following this symbol.
159
160 Indirection is asymmetrical. The other symbol's value will be used
161 to satisfy requests for the indirect symbol, but not vice versa.
162 If the other symbol does not have a definition, libraries will
163 be searched to find a definition. */
164#define N_INDR 0xa
165
166/* The following symbols refer to set elements.
167 All the N_SET[ATDB] symbols with the same name form one set.
168 Space is allocated for the set in the text section, and each set
169 element's value is stored into one word of the space.
170 The first word of the space is the length of the set (number of elements).
171
172 The address of the set is made into an N_SETV symbol
173 whose name is the same as the name of the set.
174 This symbol acts like a N_DATA global symbol
175 in that it can satisfy undefined external references. */
176
177/* These appear as input to LD, in a .o file. */
178#define N_SETA 0x14 /* Absolute set element symbol */
179#define N_SETT 0x16 /* Text set element symbol */
180#define N_SETD 0x18 /* Data set element symbol */
181#define N_SETB 0x1A /* Bss set element symbol */
182
183/* This is output from LD. */
184#define N_SETV 0x1C /* Pointer to set vector in data area. */
185
186#ifndef N_RELOCATION_INFO_DECLARED
187
188/* This structure describes a single relocation to be performed.
189 The text-relocation section of the file is a vector of these structures,
190 all of which apply to the text section.
191 Likewise, the data-relocation section applies to the data section. */
192
193struct relocation_info
194{
195 /* Address (within segment) to be relocated. */
196 int r_address;
197 /* The meaning of r_symbolnum depends on r_extern. */
198 unsigned int r_symbolnum:24;
199 /* Nonzero means value is a pc-relative offset
200 and it should be relocated for changes in its own address
201 as well as for changes in the symbol or section specified. */
202 unsigned int r_pcrel:1;
203 /* Length (as exponent of 2) of the field to be relocated.
204 Thus, a value of 2 indicates 1<<2 bytes. */
205 unsigned int r_length:2;
206 /* 1 => relocate with value of symbol.
207 r_symbolnum is the index of the symbol
208 in file's the symbol table.
209 0 => relocate with the address of a segment.
210 r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
211 (the N_EXT bit may be set also, but signifies nothing). */
212 unsigned int r_extern:1;
213 /* Four bits that aren't used, but when writing an object file
214 it is desirable to clear them. */
215 unsigned int r_pad:4;
216};
217#endif /* no N_RELOCATION_INFO_DECLARED. */
218
219
220#endif /* __A_OUT_GNU_H__ */
diff --git a/src/include/asm/io.h b/src/include/asm/io.h
new file mode 100644
index 0000000..d5cc42a
--- /dev/null
+++ b/src/include/asm/io.h
@@ -0,0 +1,24 @@
1#define outb(value,port) \
2__asm__ ("outb %%al,%%dx"::"a" (value),"d" (port))
3
4
5#define inb(port) ({ \
6unsigned char _v; \
7__asm__ volatile ("inb %%dx,%%al":"=a" (_v):"d" (port)); \
8_v; \
9})
10
11#define outb_p(value,port) \
12__asm__ ("outb %%al,%%dx\n" \
13 "\tjmp 1f\n" \
14 "1:\tjmp 1f\n" \
15 "1:"::"a" (value),"d" (port))
16
17#define inb_p(port) ({ \
18unsigned char _v; \
19__asm__ volatile ("inb %%dx,%%al\n" \
20 "\tjmp 1f\n" \
21 "1:\tjmp 1f\n" \
22 "1:":"=a" (_v):"d" (port)); \
23_v; \
24})
diff --git a/src/include/asm/memory.h b/src/include/asm/memory.h
new file mode 100644
index 0000000..8aa6d52
--- /dev/null
+++ b/src/include/asm/memory.h
@@ -0,0 +1,14 @@
1/*
2 * NOTE!!! memcpy(dest,src,n) assumes ds=es=normal data segment. This
3 * goes for all kernel functions (ds=es=kernel space, fs=local data,
4 * gs=null), as well as for all well-behaving user programs (ds=es=
5 * user data space). This is NOT a bug, as any user program that changes
6 * es deserves to die if it isn't careful.
7 */
8//#define memcpy(dest,src,n) ({ \
9//void * _res = dest; \
10//__asm__ __volatile__ ("cld;rep;movsb" \
11// ::"D" ((long)(_res)),"S" ((long)(src)),"c" ((long) (n)) \
12// ); \
13//_res; \
14//})
diff --git a/src/include/asm/segment.h b/src/include/asm/segment.h
new file mode 100644
index 0000000..94dd102
--- /dev/null
+++ b/src/include/asm/segment.h
@@ -0,0 +1,65 @@
1static inline unsigned char get_fs_byte(const char * addr)
2{
3 unsigned register char _v;
4
5 __asm__ ("movb %%fs:%1,%0":"=r" (_v):"m" (*addr));
6 return _v;
7}
8
9static inline unsigned short get_fs_word(const unsigned short *addr)
10{
11 unsigned short _v;
12
13 __asm__ ("movw %%fs:%1,%0":"=r" (_v):"m" (*addr));
14 return _v;
15}
16
17static inline unsigned long get_fs_long(const unsigned long *addr)
18{
19 unsigned long _v;
20
21 __asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); \
22 return _v;
23}
24
25static inline void put_fs_byte(char val,char *addr)
26{
27__asm__ ("movb %0,%%fs:%1"::"r" (val),"m" (*addr));
28}
29
30static inline void put_fs_word(short val,short * addr)
31{
32__asm__ ("movw %0,%%fs:%1"::"r" (val),"m" (*addr));
33}
34
35static inline void put_fs_long(unsigned long val,unsigned long * addr)
36{
37__asm__ ("movl %0,%%fs:%1"::"r" (val),"m" (*addr));
38}
39
40/*
41 * Someone who knows GNU asm better than I should double check the followig.
42 * It seems to work, but I don't know if I'm doing something subtly wrong.
43 * --- TYT, 11/24/91
44 * [ nothing wrong here, Linus ]
45 */
46
47static inline unsigned long get_fs()
48{
49 unsigned short _v;
50 __asm__("mov %%fs,%%ax":"=a" (_v):);
51 return _v;
52}
53
54static inline unsigned long get_ds()
55{
56 unsigned short _v;
57 __asm__("mov %%ds,%%ax":"=a" (_v):);
58 return _v;
59}
60
61static inline void set_fs(unsigned long val)
62{
63 __asm__("mov %0,%%fs"::"a" ((unsigned short) val));
64}
65
diff --git a/src/include/asm/system.h b/src/include/asm/system.h
new file mode 100644
index 0000000..9bc027a
--- /dev/null
+++ b/src/include/asm/system.h
@@ -0,0 +1,67 @@
1#define move_to_user_mode() \
2__asm__ ("movl %%esp,%%eax\n\t" \
3 "pushl $0x17\n\t" \
4 "pushl %%eax\n\t" \
5 "pushfl\n\t" \
6 "pushl $0x0f\n\t" \
7 "pushl $1f\n\t" \
8 "iret\n" \
9 "1:\tmovl $0x17,%%eax\n\t" \
10 "movw %%ax,%%ds\n\t" \
11 "movw %%ax,%%es\n\t" \
12 "movw %%ax,%%fs\n\t" \
13 "movw %%ax,%%gs" \
14 :::"ax")
15
16#define sti() __asm__ ("sti"::)
17#define cli() __asm__ ("cli"::)
18#define nop() __asm__ ("nop"::)
19
20#define iret() __asm__ ("iret"::)
21
22#define _set_gate(gate_addr,type,dpl,addr) \
23__asm__ ("movw %%dx,%%ax\n\t" \
24 "movw %0,%%dx\n\t" \
25 "movl %%eax,%1\n\t" \
26 "movl %%edx,%2" \
27 : \
28 : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
29 "o" (*((char *) (gate_addr))), \
30 "o" (*(4+(char *) (gate_addr))), \
31 "d" ((char *) (addr)),"a" (0x00080000))
32
33#define set_intr_gate(n,addr) \
34 _set_gate(&idt[n],14,0,addr)
35
36#define set_trap_gate(n,addr) \
37 _set_gate(&idt[n],15,0,addr)
38
39#define set_system_gate(n,addr) \
40 _set_gate(&idt[n],15,3,addr)
41
42#define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
43 *(gate_addr) = ((base) & 0xff000000) | \
44 (((base) & 0x00ff0000)>>16) | \
45 ((limit) & 0xf0000) | \
46 ((dpl)<<13) | \
47 (0x00408000) | \
48 ((type)<<8); \
49 *((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \
50 ((limit) & 0x0ffff); }
51
52#define _set_tssldt_desc(n,addr,type) \
53__asm__ ("movw $104,%1\n\t" \
54 "movw %%ax,%2\n\t" \
55 "rorl $16,%%eax\n\t" \
56 "movb %%al,%3\n\t" \
57 "movb $" type ",%4\n\t" \
58 "movb $0x00,%5\n\t" \
59 "movb %%ah,%6\n\t" \
60 "rorl $16,%%eax" \
61 ::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \
62 "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \
63 )
64
65#define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x89")
66#define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x82")
67
diff --git a/src/include/const.h b/src/include/const.h
new file mode 100644
index 0000000..7828e61
--- /dev/null
+++ b/src/include/const.h
@@ -0,0 +1,15 @@
1#ifndef _CONST_H
2#define _CONST_H
3
4#define BUFFER_END 0x200000
5
6#define I_TYPE 0170000
7#define I_DIRECTORY 0040000
8#define I_REGULAR 0100000
9#define I_BLOCK_SPECIAL 0060000
10#define I_CHAR_SPECIAL 0020000
11#define I_NAMED_PIPE 0010000
12#define I_SET_UID_BIT 0004000
13#define I_SET_GID_BIT 0002000
14
15#endif
diff --git a/src/include/ctype.h b/src/include/ctype.h
new file mode 100644
index 0000000..7acf55d
--- /dev/null
+++ b/src/include/ctype.h
@@ -0,0 +1,34 @@
1#ifndef _CTYPE_H
2#define _CTYPE_H
3
4#define _U 0x01 /* upper */
5#define _L 0x02 /* lower */
6#define _D 0x04 /* digit */
7#define _C 0x08 /* cntrl */
8#define _P 0x10 /* punct */
9#define _S 0x20 /* white space (space/lf/tab) */
10#define _X 0x40 /* hex digit */
11#define _SP 0x80 /* hard space (0x20) */
12
13extern unsigned char _ctype[];
14extern char _ctmp;
15
16#define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D))
17#define isalpha(c) ((_ctype+1)[c]&(_U|_L))
18#define iscntrl(c) ((_ctype+1)[c]&(_C))
19#define isdigit(c) ((_ctype+1)[c]&(_D))
20#define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D))
21#define islower(c) ((_ctype+1)[c]&(_L))
22#define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP))
23#define ispunct(c) ((_ctype+1)[c]&(_P))
24#define isspace(c) ((_ctype+1)[c]&(_S))
25#define isupper(c) ((_ctype+1)[c]&(_U))
26#define isxdigit(c) ((_ctype+1)[c]&(_D|_X))
27
28#define isascii(c) (((unsigned) c)<=0x7f)
29#define toascii(c) (((unsigned) c)&0x7f)
30
31#define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp)
32#define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp)
33
34#endif
diff --git a/src/include/errno.h b/src/include/errno.h
new file mode 100644
index 0000000..c282f69
--- /dev/null
+++ b/src/include/errno.h
@@ -0,0 +1,60 @@
1#ifndef _ERRNO_H
2#define _ERRNO_H
3
4/*
5 * ok, as I hadn't got any other source of information about
6 * possible error numbers, I was forced to use the same numbers
7 * as minix.
8 * Hopefully these are posix or something. I wouldn't know (and posix
9 * isn't telling me - they want $$$ for their f***ing standard).
10 *
11 * We don't use the _SIGN cludge of minix, so kernel returns must
12 * see to the sign by themselves.
13 *
14 * NOTE! Remember to change strerror() if you change this file!
15 */
16
17extern int errno;
18
19#define ERROR 99
20#define EPERM 1
21#define ENOENT 2
22#define ESRCH 3
23#define EINTR 4
24#define EIO 5
25#define ENXIO 6
26#define E2BIG 7
27#define ENOEXEC 8
28#define EBADF 9
29#define ECHILD 10
30#define EAGAIN 11
31#define ENOMEM 12
32#define EACCES 13
33#define EFAULT 14
34#define ENOTBLK 15
35#define EBUSY 16
36#define EEXIST 17
37#define EXDEV 18
38#define ENODEV 19
39#define ENOTDIR 20
40#define EISDIR 21
41#define EINVAL 22
42#define ENFILE 23
43#define EMFILE 24
44#define ENOTTY 25
45#define ETXTBSY 26
46#define EFBIG 27
47#define ENOSPC 28
48#define ESPIPE 29
49#define EROFS 30
50#define EMLINK 31
51#define EPIPE 32
52#define EDOM 33
53#define ERANGE 34
54#define EDEADLK 35
55#define ENAMETOOLONG 36
56#define ENOLCK 37
57#define ENOSYS 38
58#define ENOTEMPTY 39
59
60#endif
diff --git a/src/include/fcntl.h b/src/include/fcntl.h
new file mode 100644
index 0000000..a5bf9af
--- /dev/null
+++ b/src/include/fcntl.h
@@ -0,0 +1,55 @@
1#ifndef _FCNTL_H
2#define _FCNTL_H
3
4#include <sys/types.h>
5
6/* open/fcntl - NOCTTY, NDELAY isn't implemented yet */
7#define O_ACCMODE 00003
8#define O_RDONLY 00
9#define O_WRONLY 01
10#define O_RDWR 02
11#define O_CREAT 00100 /* not fcntl */
12#define O_EXCL 00200 /* not fcntl */
13#define O_NOCTTY 00400 /* not fcntl */
14#define O_TRUNC 01000 /* not fcntl */
15#define O_APPEND 02000
16#define O_NONBLOCK 04000 /* not fcntl */
17#define O_NDELAY O_NONBLOCK
18
19/* Defines for fcntl-commands. Note that currently
20 * locking isn't supported, and other things aren't really
21 * tested.
22 */
23#define F_DUPFD 0 /* dup */
24#define F_GETFD 1 /* get f_flags */
25#define F_SETFD 2 /* set f_flags */
26#define F_GETFL 3 /* more flags (cloexec) */
27#define F_SETFL 4
28#define F_GETLK 5 /* not implemented */
29#define F_SETLK 6
30#define F_SETLKW 7
31
32/* for F_[GET|SET]FL */
33#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
34
35/* Ok, these are locking features, and aren't implemented at any
36 * level. POSIX wants them.
37 */
38#define F_RDLCK 0
39#define F_WRLCK 1
40#define F_UNLCK 2
41
42/* Once again - not implemented, but ... */
43struct flock {
44 short l_type;
45 short l_whence;
46 off_t l_start;
47 off_t l_len;
48 pid_t l_pid;
49};
50
51extern int creat(const char * filename,mode_t mode);
52extern int fcntl(int fildes,int cmd, ...);
53extern int open(const char * filename, int flags, ...);
54
55#endif
diff --git a/src/include/linux/config.h b/src/include/linux/config.h
new file mode 100644
index 0000000..819b525
--- /dev/null
+++ b/src/include/linux/config.h
@@ -0,0 +1,48 @@
1#ifndef _CONFIG_H
2#define _CONFIG_H
3
4/*
5 * The root-device is no longer hard-coded. You can change the default
6 * root-device by changing the line ROOT_DEV = XXX in boot/bootsect.s
7 */
8
9/*
10 * define your keyboard here -
11 * KBD_FINNISH for Finnish keyboards
12 * KBD_US for US-type
13 * KBD_GR for German keyboards
14 * KBD_FR for Frech keyboard
15 */
16#define KBD_US
17/*#define KBD_GR */
18/*#define KBD_FR */
19/*#define KBD_FINNISH */
20
21/*
22 * Normally, Linux can get the drive parameters from the BIOS at
23 * startup, but if this for some unfathomable reason fails, you'd
24 * be left stranded. For this case, you can define HD_TYPE, which
25 * contains all necessary info on your harddisk.
26 *
27 * The HD_TYPE macro should look like this:
28 *
29 * #define HD_TYPE { head, sect, cyl, wpcom, lzone, ctl}
30 *
31 * In case of two harddisks, the info should be sepatated by
32 * commas:
33 *
34 * #define HD_TYPE { h,s,c,wpcom,lz,ctl },{ h,s,c,wpcom,lz,ctl }
35 */
36/*
37 This is an example, two drives, first is type 2, second is type 3:
38
39#define HD_TYPE { 4,17,615,300,615,8 }, { 6,17,615,300,615,0 }
40
41 NOTE: ctl is 0 for all drives with heads<=8, and ctl=8 for drives
42 with more than 8 heads.
43
44 If you want the BIOS to tell what kind of drive you have, just
45 leave HD_TYPE undefined. This is the normal thing to do.
46*/
47
48#endif
diff --git a/src/include/linux/fdreg.h b/src/include/linux/fdreg.h
new file mode 100644
index 0000000..01355af
--- /dev/null
+++ b/src/include/linux/fdreg.h
@@ -0,0 +1,71 @@
1/*
2 * This file contains some defines for the floppy disk controller.
3 * Various sources. Mostly "IBM Microcomputers: A Programmers
4 * Handbook", Sanches and Canton.
5 */
6#ifndef _FDREG_H
7#define _FDREG_H
8
9extern int ticks_to_floppy_on(unsigned int nr);
10extern void floppy_on(unsigned int nr);
11extern void floppy_off(unsigned int nr);
12extern void floppy_select(unsigned int nr);
13extern void floppy_deselect(unsigned int nr);
14
15/* Fd controller regs. S&C, about page 340 */
16#define FD_STATUS 0x3f4
17#define FD_DATA 0x3f5
18#define FD_DOR 0x3f2 /* Digital Output Register */
19#define FD_DIR 0x3f7 /* Digital Input Register (read) */
20#define FD_DCR 0x3f7 /* Diskette Control Register (write)*/
21
22/* Bits of main status register */
23#define STATUS_BUSYMASK 0x0F /* drive busy mask */
24#define STATUS_BUSY 0x10 /* FDC busy */
25#define STATUS_DMA 0x20 /* 0- DMA mode */
26#define STATUS_DIR 0x40 /* 0- cpu->fdc */
27#define STATUS_READY 0x80 /* Data reg ready */
28
29/* Bits of FD_ST0 */
30#define ST0_DS 0x03 /* drive select mask */
31#define ST0_HA 0x04 /* Head (Address) */
32#define ST0_NR 0x08 /* Not Ready */
33#define ST0_ECE 0x10 /* Equipment chech error */
34#define ST0_SE 0x20 /* Seek end */
35#define ST0_INTR 0xC0 /* Interrupt code mask */
36
37/* Bits of FD_ST1 */
38#define ST1_MAM 0x01 /* Missing Address Mark */
39#define ST1_WP 0x02 /* Write Protect */
40#define ST1_ND 0x04 /* No Data - unreadable */
41#define ST1_OR 0x10 /* OverRun */
42#define ST1_CRC 0x20 /* CRC error in data or addr */
43#define ST1_EOC 0x80 /* End Of Cylinder */
44
45/* Bits of FD_ST2 */
46#define ST2_MAM 0x01 /* Missing Addess Mark (again) */
47#define ST2_BC 0x02 /* Bad Cylinder */
48#define ST2_SNS 0x04 /* Scan Not Satisfied */
49#define ST2_SEH 0x08 /* Scan Equal Hit */
50#define ST2_WC 0x10 /* Wrong Cylinder */
51#define ST2_CRC 0x20 /* CRC error in data field */
52#define ST2_CM 0x40 /* Control Mark = deleted */
53
54/* Bits of FD_ST3 */
55#define ST3_HA 0x04 /* Head (Address) */
56#define ST3_TZ 0x10 /* Track Zero signal (1=track 0) */
57#define ST3_WP 0x40 /* Write Protect */
58
59/* Values for FD_COMMAND */
60#define FD_RECALIBRATE 0x07 /* move to track 0 */
61#define FD_SEEK 0x0F /* seek track */
62#define FD_READ 0xE6 /* read with MT, MFM, SKip deleted */
63#define FD_WRITE 0xC5 /* write with MT, MFM */
64#define FD_SENSEI 0x08 /* Sense Interrupt Status */
65#define FD_SPECIFY 0x03 /* specify HUT etc */
66
67/* DMA commands */
68#define DMA_READ 0x46
69#define DMA_WRITE 0x4A
70
71#endif
diff --git a/src/include/linux/fs.h b/src/include/linux/fs.h
new file mode 100644
index 0000000..7a90b10
--- /dev/null
+++ b/src/include/linux/fs.h
@@ -0,0 +1,202 @@
1/*
2 * This file has definitions for some important file table
3 * structures etc.
4 */
5
6#ifndef _FS_H
7#define _FS_H
8
9#include <sys/types.h>
10
11/* devices are as follows: (same as minix, so we can use the minix
12 * file system. These are major numbers.)
13 *
14 * 0 - unused (nodev)
15 * 1 - /dev/mem
16 * 2 - /dev/fd
17 * 3 - /dev/hd
18 * 4 - /dev/ttyx
19 * 5 - /dev/tty
20 * 6 - /dev/lp
21 * 7 - unnamed pipes
22 */
23
24#define IS_SEEKABLE(x) ((x)>=1 && (x)<=3)
25
26#define READ 0
27#define WRITE 1
28#define READA 2 /* read-ahead - don't pause */
29#define WRITEA 3 /* "write-ahead" - silly, but somewhat useful */
30
31void buffer_init(long buffer_end);
32
33#define MAJOR(a) (((unsigned)(a))>>8)
34#define MINOR(a) ((a)&0xff)
35
36#define NAME_LEN 14
37#define ROOT_INO 1
38
39#define I_MAP_SLOTS 8
40#define Z_MAP_SLOTS 8
41#define SUPER_MAGIC 0x137F
42
43#define NR_OPEN 20
44#define NR_INODE 32
45#define NR_FILE 64
46#define NR_SUPER 8
47#define NR_HASH 307
48#define NR_BUFFERS nr_buffers
49#define BLOCK_SIZE 1024
50#define BLOCK_SIZE_BITS 10
51#ifndef NULL
52#define NULL ((void *) 0)
53#endif
54
55#define INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct d_inode)))
56#define DIR_ENTRIES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct dir_entry)))
57
58#define PIPE_HEAD(inode) ((inode).i_zone[0])
59#define PIPE_TAIL(inode) ((inode).i_zone[1])
60#define PIPE_SIZE(inode) ((PIPE_HEAD(inode)-PIPE_TAIL(inode))&(PAGE_SIZE-1))
61#define PIPE_EMPTY(inode) (PIPE_HEAD(inode)==PIPE_TAIL(inode))
62#define PIPE_FULL(inode) (PIPE_SIZE(inode)==(PAGE_SIZE-1))
63#define INC_PIPE(head) \
64__asm__("incl %0\n\tandl $4095,%0"::"m" (head))
65
66typedef char buffer_block[BLOCK_SIZE];
67
68struct buffer_head {
69 char * b_data; /* pointer to data block (1024 bytes) */
70 unsigned long b_blocknr; /* block number */
71 unsigned short b_dev; /* device (0 = free) */
72 unsigned char b_uptodate;
73 unsigned char b_dirt; /* 0-clean,1-dirty */
74 unsigned char b_count; /* users using this block */
75 unsigned char b_lock; /* 0 - ok, 1 -locked */
76 struct task_struct * b_wait;
77 struct buffer_head * b_prev;
78 struct buffer_head * b_next;
79 struct buffer_head * b_prev_free;
80 struct buffer_head * b_next_free;
81};
82
83struct d_inode {
84 unsigned short i_mode;
85 unsigned short i_uid;
86 unsigned long i_size;
87 unsigned long i_time;
88 unsigned char i_gid;
89 unsigned char i_nlinks;
90 unsigned short i_zone[9];
91};
92
93struct m_inode {
94 unsigned short i_mode;
95 unsigned short i_uid;
96 unsigned long i_size;
97 unsigned long i_mtime;
98 unsigned char i_gid;
99 unsigned char i_nlinks;
100 unsigned short i_zone[9];
101/* these are in memory also */
102 struct task_struct * i_wait;
103 unsigned long i_atime;
104 unsigned long i_ctime;
105 unsigned short i_dev;
106 unsigned short i_num;
107 unsigned short i_count;
108 unsigned char i_lock;
109 unsigned char i_dirt;
110 unsigned char i_pipe;
111 unsigned char i_mount;
112 unsigned char i_seek;
113 unsigned char i_update;
114};
115
116struct file {
117 unsigned short f_mode;
118 unsigned short f_flags;
119 unsigned short f_count;
120 struct m_inode * f_inode;
121 off_t f_pos;
122};
123
124struct super_block {
125 unsigned short s_ninodes;
126 unsigned short s_nzones;
127 unsigned short s_imap_blocks;
128 unsigned short s_zmap_blocks;
129 unsigned short s_firstdatazone;
130 unsigned short s_log_zone_size;
131 unsigned long s_max_size;
132 unsigned short s_magic;
133/* These are only in memory */
134 struct buffer_head * s_imap[8];
135 struct buffer_head * s_zmap[8];
136 unsigned short s_dev;
137 struct m_inode * s_isup;
138 struct m_inode * s_imount;
139 unsigned long s_time;
140 struct task_struct * s_wait;
141 unsigned char s_lock;
142 unsigned char s_rd_only;
143 unsigned char s_dirt;
144};
145
146struct d_super_block {
147 unsigned short s_ninodes;
148 unsigned short s_nzones;
149 unsigned short s_imap_blocks;
150 unsigned short s_zmap_blocks;
151 unsigned short s_firstdatazone;
152 unsigned short s_log_zone_size;
153 unsigned long s_max_size;
154 unsigned short s_magic;
155};
156
157struct dir_entry {
158 unsigned short inode;
159 char name[NAME_LEN];
160};
161
162extern struct m_inode inode_table[NR_INODE];
163extern struct file file_table[NR_FILE];
164extern struct super_block super_block[NR_SUPER];
165extern struct buffer_head * start_buffer;
166extern int nr_buffers;
167
168extern void check_disk_change(int dev);
169extern int floppy_change(unsigned int nr);
170extern int ticks_to_floppy_on(unsigned int dev);
171extern void floppy_on(unsigned int dev);
172extern void floppy_off(unsigned int dev);
173extern void truncate(struct m_inode * inode);
174extern void sync_inodes(void);
175extern void wait_on(struct m_inode * inode);
176extern int bmap(struct m_inode * inode,int block);
177extern int create_block(struct m_inode * inode,int block);
178extern struct m_inode * namei(const char * pathname);
179extern int open_namei(const char * pathname, int flag, int mode,
180 struct m_inode ** res_inode);
181extern void iput(struct m_inode * inode);
182extern struct m_inode * iget(int dev,int nr);
183extern struct m_inode * get_empty_inode(void);
184extern struct m_inode * get_pipe_inode(void);
185extern struct buffer_head * get_hash_table(int dev, int block);
186extern struct buffer_head * getblk(int dev, int block);
187extern void ll_rw_block(int rw, struct buffer_head * bh);
188extern void brelse(struct buffer_head * buf);
189extern struct buffer_head * bread(int dev,int block);
190extern void bread_page(unsigned long addr,int dev,int b[4]);
191extern struct buffer_head * breada(int dev,int block,...);
192extern int new_block(int dev);
193extern void free_block(int dev, int block);
194extern struct m_inode * new_inode(int dev);
195extern void free_inode(struct m_inode * inode);
196extern int sync_dev(int dev);
197extern struct super_block * get_super(int dev);
198extern int ROOT_DEV;
199
200extern void mount_root(void);
201
202#endif
diff --git a/src/include/linux/hdreg.h b/src/include/linux/hdreg.h
new file mode 100644
index 0000000..e6c593f
--- /dev/null
+++ b/src/include/linux/hdreg.h
@@ -0,0 +1,65 @@
1/*
2 * This file contains some defines for the AT-hd-controller.
3 * Various sources. Check out some definitions (see comments with
4 * a ques).
5 */
6#ifndef _HDREG_H
7#define _HDREG_H
8
9/* Hd controller regs. Ref: IBM AT Bios-listing */
10#define HD_DATA 0x1f0 /* _CTL when writing */
11#define HD_ERROR 0x1f1 /* see err-bits */
12#define HD_NSECTOR 0x1f2 /* nr of sectors to read/write */
13#define HD_SECTOR 0x1f3 /* starting sector */
14#define HD_LCYL 0x1f4 /* starting cylinder */
15#define HD_HCYL 0x1f5 /* high byte of starting cyl */
16#define HD_CURRENT 0x1f6 /* 101dhhhh , d=drive, hhhh=head */
17#define HD_STATUS 0x1f7 /* see status-bits */
18#define HD_PRECOMP HD_ERROR /* same io address, read=error, write=precomp */
19#define HD_COMMAND HD_STATUS /* same io address, read=status, write=cmd */
20
21#define HD_CMD 0x3f6
22
23/* Bits of HD_STATUS */
24#define ERR_STAT 0x01
25#define INDEX_STAT 0x02
26#define ECC_STAT 0x04 /* Corrected error */
27#define DRQ_STAT 0x08
28#define SEEK_STAT 0x10
29#define WRERR_STAT 0x20
30#define READY_STAT 0x40
31#define BUSY_STAT 0x80
32
33/* Values for HD_COMMAND */
34#define WIN_RESTORE 0x10
35#define WIN_READ 0x20
36#define WIN_WRITE 0x30
37#define WIN_VERIFY 0x40
38#define WIN_FORMAT 0x50
39#define WIN_INIT 0x60
40#define WIN_SEEK 0x70
41#define WIN_DIAGNOSE 0x90
42#define WIN_SPECIFY 0x91
43
44/* Bits for HD_ERROR */
45#define MARK_ERR 0x01 /* Bad address mark ? */
46#define TRK0_ERR 0x02 /* couldn't find track 0 */
47#define ABRT_ERR 0x04 /* ? */
48#define ID_ERR 0x10 /* ? */
49#define ECC_ERR 0x40 /* ? */
50#define BBD_ERR 0x80 /* ? */
51
52struct partition {
53 unsigned char boot_ind; /* 0x80 - active (unused) */
54 unsigned char head; /* ? */
55 unsigned char sector; /* ? */
56 unsigned char cyl; /* ? */
57 unsigned char sys_ind; /* ? */
58 unsigned char end_head; /* ? */
59 unsigned char end_sector; /* ? */
60 unsigned char end_cyl; /* ? */
61 unsigned int start_sect; /* starting sector counting from 0 */
62 unsigned int nr_sects; /* nr of sectors in partition */
63};
64
65#endif
diff --git a/src/include/linux/head.h b/src/include/linux/head.h
new file mode 100644
index 0000000..db3dda2
--- /dev/null
+++ b/src/include/linux/head.h
@@ -0,0 +1,20 @@
1#ifndef _HEAD_H
2#define _HEAD_H
3
4typedef struct desc_struct {
5 unsigned long a,b;
6} desc_table[256];
7
8extern unsigned long pg_dir[1024];
9extern desc_table idt,gdt;
10
11#define GDT_NUL 0
12#define GDT_CODE 1
13#define GDT_DATA 2
14#define GDT_TMP 3
15
16#define LDT_NUL 0
17#define LDT_CODE 1
18#define LDT_DATA 2
19
20#endif
diff --git a/src/include/linux/kernel.h b/src/include/linux/kernel.h
new file mode 100644
index 0000000..2a0f916
--- /dev/null
+++ b/src/include/linux/kernel.h
@@ -0,0 +1,22 @@
1/*
2 * 'kernel.h' contains some often-used function prototypes etc
3 */
4void verify_area(void * addr,int count);
5void panic(const char * str);
6int printf(const char * fmt, ...);
7int printk(const char * fmt, ...);
8int tty_write(unsigned ch,char * buf,int count);
9void * malloc(unsigned int size);
10void free_s(void * obj, int size);
11
12#define free(x) free_s((x), 0)
13
14/*
15 * This is defined as a macro, but at some point this might become a
16 * real subroutine that sets a flag if it returns true (to do
17 * BSD-style accounting where the process is flagged if it uses root
18 * privs). The implication of this is that you should do normal
19 * permissions checks first, and check suser() last.
20 */
21#define suser() (current->euid == 0)
22
diff --git a/src/include/linux/mm.h b/src/include/linux/mm.h
new file mode 100644
index 0000000..5a160f3
--- /dev/null
+++ b/src/include/linux/mm.h
@@ -0,0 +1,10 @@
1#ifndef _MM_H
2#define _MM_H
3
4#define PAGE_SIZE 4096
5
6extern unsigned long get_free_page(void);
7extern unsigned long put_page(unsigned long page,unsigned long address);
8extern void free_page(unsigned long addr);
9
10#endif
diff --git a/src/include/linux/sched.h b/src/include/linux/sched.h
new file mode 100644
index 0000000..e1b35be
--- /dev/null
+++ b/src/include/linux/sched.h
@@ -0,0 +1,256 @@
1#ifndef _SCHED_H
2#define _SCHED_H
3
4#define NR_TASKS 64
5#define HZ 100
6
7#define FIRST_TASK task[0]
8#define LAST_TASK task[NR_TASKS-1]
9
10#include <linux/head.h>
11#include <linux/fs.h>
12#include <linux/mm.h>
13#include <signal.h>
14
15#if (NR_OPEN > 32)
16#error "Currently the close-on-exec-flags are in one word, max 32 files/proc"
17#endif
18
19#define TASK_RUNNING 0
20#define TASK_INTERRUPTIBLE 1
21#define TASK_UNINTERRUPTIBLE 2
22#define TASK_ZOMBIE 3
23#define TASK_STOPPED 4
24
25#ifndef NULL
26#define NULL ((void *) 0)
27#endif
28
29extern int copy_page_tables(unsigned long from, unsigned long to, long size);
30extern int free_page_tables(unsigned long from, unsigned long size);
31
32extern void sched_init(void);
33extern void schedule(void);
34extern void trap_init(void);
35#ifndef PANIC
36void panic(const char * str);
37#endif
38extern int tty_write(unsigned minor,char * buf,int count);
39
40typedef int (*fn_ptr)();
41
42struct i387_struct {
43 long cwd;
44 long swd;
45 long twd;
46 long fip;
47 long fcs;
48 long foo;
49 long fos;
50 long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
51};
52
53struct tss_struct {
54 long back_link; /* 16 high bits zero */
55 long esp0;
56 long ss0; /* 16 high bits zero */
57 long esp1;
58 long ss1; /* 16 high bits zero */
59 long esp2;
60 long ss2; /* 16 high bits zero */
61 long cr3;
62 long eip;
63 long eflags;
64 long eax,ecx,edx,ebx;
65 long esp;
66 long ebp;
67 long esi;
68 long edi;
69 long es; /* 16 high bits zero */
70 long cs; /* 16 high bits zero */
71 long ss; /* 16 high bits zero */
72 long ds; /* 16 high bits zero */
73 long fs; /* 16 high bits zero */
74 long gs; /* 16 high bits zero */
75 long ldt; /* 16 high bits zero */
76 long trace_bitmap; /* bits: trace 0, bitmap 16-31 */
77 struct i387_struct i387;
78};
79
80struct task_struct {
81/* these are hardcoded - don't touch */
82 long state; /* -1 unrunnable, 0 runnable, >0 stopped */
83 long counter;
84 long priority;
85 long signal;
86 struct sigaction sigaction[32];
87 long blocked; /* bitmap of masked signals */
88/* various fields */
89 int exit_code;
90 unsigned long start_code,end_code,end_data,brk,start_stack;
91 long pid,father,pgrp,session,leader;
92 unsigned short uid,euid,suid;
93 unsigned short gid,egid,sgid;
94 long alarm;
95 long utime,stime,cutime,cstime,start_time;
96 unsigned short used_math;
97/* file system info */
98 int tty; /* -1 if no tty, so it must be signed */
99 unsigned short umask;
100 struct m_inode * pwd;
101 struct m_inode * root;
102 struct m_inode * executable;
103 unsigned long close_on_exec;
104 struct file * filp[NR_OPEN];
105/* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
106 struct desc_struct ldt[3];
107/* tss for this task */
108 struct tss_struct tss;
109};
110
111/*
112 * INIT_TASK is used to set up the first task table, touch at
113 * your own risk!. Base=0, limit=0x9ffff (=640kB)
114 */
115#define INIT_TASK \
116/* state etc */ { 0,15,15, \
117/* signals */ 0,{{},},0, \
118/* ec,brk... */ 0,0,0,0,0,0, \
119/* pid etc.. */ 0,-1,0,0,0, \
120/* uid etc */ 0,0,0,0,0,0, \
121/* alarm */ 0,0,0,0,0,0, \
122/* math */ 0, \
123/* fs info */ -1,0022,NULL,NULL,NULL,0, \
124/* filp */ {NULL,}, \
125 { \
126 {0,0}, \
127/* ldt */ {0x9f,0xc0fa00}, \
128 {0x9f,0xc0f200}, \
129 }, \
130/*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\
131 0,0,0,0,0,0,0,0, \
132 0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
133 _LDT(0),0x80000000, \
134 {} \
135 }, \
136}
137
138extern struct task_struct *task[NR_TASKS];
139extern struct task_struct *last_task_used_math;
140extern struct task_struct *current;
141extern long volatile jiffies;
142extern long startup_time;
143
144#define CURRENT_TIME (startup_time+jiffies/HZ)
145
146extern void add_timer(long jiffies, void (*fn)(void));
147extern void sleep_on(struct task_struct ** p);
148extern void interruptible_sleep_on(struct task_struct ** p);
149extern void wake_up(struct task_struct ** p);
150
151/*
152 * Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall
153 * 4-TSS0, 5-LDT0, 6-TSS1 etc ...
154 */
155#define FIRST_TSS_ENTRY 4
156#define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
157#define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
158#define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
159#define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
160#define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
161#define str(n) \
162__asm__("str %%ax\n\t" \
163 "subl %2,%%eax\n\t" \
164 "shrl $4,%%eax" \
165 :"=a" (n) \
166 :"a" (0),"i" (FIRST_TSS_ENTRY<<3))
167/*
168 * switch_to(n) should switch tasks to task nr n, first
169 * checking that n isn't the current task, in which case it does nothing.
170 * This also clears the TS-flag if the task we switched to has used
171 * tha math co-processor latest.
172 */
173#define switch_to(n) {\
174struct {long a,b;} __tmp; \
175__asm__("cmpl %%ecx,current\n\t" \
176 "je 1f\n\t" \
177 "movw %%dx,%1\n\t" \
178 "xchgl %%ecx,current\n\t" \
179 "ljmp *%0\n\t" \
180 "cmpl %%ecx,last_task_used_math\n\t" \
181 "jne 1f\n\t" \
182 "clts\n" \
183 "1:" \
184 ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
185 "d" (_TSS(n)),"c" ((long) task[n])); \
186}
187
188#define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
189
190#define _set_base(addr,base) \
191__asm__ ("push %%edx\n\t" \
192 "movw %%dx,%0\n\t" \
193 "rorl $16,%%edx\n\t" \
194 "movb %%dl,%1\n\t" \
195 "movb %%dh,%2\n\t" \
196 "pop %%edx" \
197 ::"m" (*((addr)+2)), \
198 "m" (*((addr)+4)), \
199 "m" (*((addr)+7)), \
200 "d" (base) \
201 )
202
203#define _set_limit(addr,limit) \
204__asm__ ("push %%edx\n\t" \
205 "movw %%dx,%0\n\t" \
206 "rorl $16,%%edx\n\t" \
207 "movb %1,%%dh\n\t" \
208 "andb $0xf0,%%dh\n\t" \
209 "orb %%dh,%%dl\n\t" \
210 "movb %%dl,%1\n\t" \
211 "pop %%edx" \
212 ::"m" (*(addr)), \
213 "m" (*((addr)+6)), \
214 "d" (limit) \
215 )
216
217#define set_base(ldt,base) _set_base( ((char *)&(ldt)) , (base) )
218#define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
219
220/**
221#define _get_base(addr) ({\
222unsigned long __base; \
223__asm__("movb %3,%%dh\n\t" \
224 "movb %2,%%dl\n\t" \
225 "shll $16,%%edx\n\t" \
226 "movw %1,%%dx" \
227 :"=d" (__base) \
228 :"m" (*((addr)+2)), \
229 "m" (*((addr)+4)), \
230 "m" (*((addr)+7)) \
231 :"memory"); \
232__base;})
233**/
234
235static inline unsigned long _get_base(char * addr)
236{
237 unsigned long __base;
238 __asm__("movb %3,%%dh\n\t"
239 "movb %2,%%dl\n\t"
240 "shll $16,%%edx\n\t"
241 "movw %1,%%dx"
242 :"=&d" (__base)
243 :"m" (*((addr)+2)),
244 "m" (*((addr)+4)),
245 "m" (*((addr)+7)));
246 return __base;
247}
248
249#define get_base(ldt) _get_base( ((char *)&(ldt)) )
250
251#define get_limit(segment) ({ \
252unsigned long __limit; \
253__asm__("lsll %1,%0\n\tincl %0":"=r" (__limit):"r" (segment)); \
254__limit;})
255
256#endif
diff --git a/src/include/linux/sys.h b/src/include/linux/sys.h
new file mode 100644
index 0000000..c538fc1
--- /dev/null
+++ b/src/include/linux/sys.h
@@ -0,0 +1,86 @@
1extern int sys_setup();
2extern int sys_exit();
3extern int sys_fork();
4extern int sys_read();
5extern int sys_write();
6extern int sys_open();
7extern int sys_close();
8extern int sys_waitpid();
9extern int sys_creat();
10extern int sys_link();
11extern int sys_unlink();
12extern int sys_execve();
13extern int sys_chdir();
14extern int sys_time();
15extern int sys_mknod();
16extern int sys_chmod();
17extern int sys_chown();
18extern int sys_break();
19extern int sys_stat();
20extern int sys_lseek();
21extern int sys_getpid();
22extern int sys_mount();
23extern int sys_umount();
24extern int sys_setuid();
25extern int sys_getuid();
26extern int sys_stime();
27extern int sys_ptrace();
28extern int sys_alarm();
29extern int sys_fstat();
30extern int sys_pause();
31extern int sys_utime();
32extern int sys_stty();
33extern int sys_gtty();
34extern int sys_access();
35extern int sys_nice();
36extern int sys_ftime();
37extern int sys_sync();
38extern int sys_kill();
39extern int sys_rename();
40extern int sys_mkdir();
41extern int sys_rmdir();
42extern int sys_dup();
43extern int sys_pipe();
44extern int sys_times();
45extern int sys_prof();
46extern int sys_brk();
47extern int sys_setgid();
48extern int sys_getgid();
49extern int sys_signal();
50extern int sys_geteuid();
51extern int sys_getegid();
52extern int sys_acct();
53extern int sys_phys();
54extern int sys_lock();
55extern int sys_ioctl();
56extern int sys_fcntl();
57extern int sys_mpx();
58extern int sys_setpgid();
59extern int sys_ulimit();
60extern int sys_uname();
61extern int sys_umask();
62extern int sys_chroot();
63extern int sys_ustat();
64extern int sys_dup2();
65extern int sys_getppid();
66extern int sys_getpgrp();
67extern int sys_setsid();
68extern int sys_sigaction();
69extern int sys_sgetmask();
70extern int sys_ssetmask();
71extern int sys_setreuid();
72extern int sys_setregid();
73
74fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read,
75sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link,
76sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod,
77sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount,
78sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm,
79sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access,
80sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir,
81sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid,
82sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys,
83sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit,
84sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid,
85sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask,
86sys_setreuid,sys_setregid };
diff --git a/src/include/linux/tty.h b/src/include/linux/tty.h
new file mode 100644
index 0000000..ad846b3
--- /dev/null
+++ b/src/include/linux/tty.h
@@ -0,0 +1,77 @@
1/*
2 * 'tty.h' defines some structures used by tty_io.c and some defines.
3 *
4 * NOTE! Don't touch this without checking that nothing in rs_io.s or
5 * con_io.s breaks. Some constants are hardwired into the system (mainly
6 * offsets into 'tty_queue'
7 */
8
9#ifndef _TTY_H
10#define _TTY_H
11
12#include <termios.h>
13
14#define TTY_BUF_SIZE 1024
15
16struct tty_queue {
17 unsigned long data;
18 unsigned long head;
19 unsigned long tail;
20 struct task_struct * proc_list;
21 char buf[TTY_BUF_SIZE];
22};
23
24#define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
25#define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
26#define EMPTY(a) ((a).head == (a).tail)
27#define LEFT(a) (((a).tail-(a).head-1)&(TTY_BUF_SIZE-1))
28#define LAST(a) ((a).buf[(TTY_BUF_SIZE-1)&((a).head-1)])
29#define FULL(a) (!LEFT(a))
30#define CHARS(a) (((a).head-(a).tail)&(TTY_BUF_SIZE-1))
31#define GETCH(queue,c) \
32(void)({c=(queue).buf[(queue).tail];INC((queue).tail);})
33#define PUTCH(c,queue) \
34(void)({(queue).buf[(queue).head]=(c);INC((queue).head);})
35
36#define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR])
37#define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT])
38#define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE])
39#define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL])
40#define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF])
41#define START_CHAR(tty) ((tty)->termios.c_cc[VSTART])
42#define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP])
43#define SUSPEND_CHAR(tty) ((tty)->termios.c_cc[VSUSP])
44
45struct tty_struct {
46 struct termios termios;
47 int pgrp;
48 int stopped;
49 void (*write)(struct tty_struct * tty);
50 struct tty_queue read_q;
51 struct tty_queue write_q;
52 struct tty_queue secondary;
53 };
54
55extern struct tty_struct tty_table[];
56
57/* intr=^C quit=^| erase=del kill=^U
58 eof=^D vtime=\0 vmin=\1 sxtc=\0
59 start=^Q stop=^S susp=^Z eol=\0
60 reprint=^R discard=^U werase=^W lnext=^V
61 eol2=\0
62*/
63#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
64
65void rs_init(void);
66void con_init(void);
67void tty_init(void);
68
69int tty_read(unsigned c, char * buf, int n);
70int tty_write(unsigned c, char * buf, int n);
71
72void rs_write(struct tty_struct * tty);
73void con_write(struct tty_struct * tty);
74
75void copy_to_cooked(struct tty_struct * tty);
76
77#endif
diff --git a/src/include/signal.h b/src/include/signal.h
new file mode 100644
index 0000000..0eea9a3
--- /dev/null
+++ b/src/include/signal.h
@@ -0,0 +1,68 @@
1#ifndef _SIGNAL_H
2#define _SIGNAL_H
3
4#include <sys/types.h>
5
6typedef int sig_atomic_t;
7typedef unsigned int sigset_t; /* 32 bits */
8
9#define _NSIG 32
10#define NSIG _NSIG
11
12#define SIGHUP 1
13#define SIGINT 2
14#define SIGQUIT 3
15#define SIGILL 4
16#define SIGTRAP 5
17#define SIGABRT 6
18#define SIGIOT 6
19#define SIGUNUSED 7
20#define SIGFPE 8
21#define SIGKILL 9
22#define SIGUSR1 10
23#define SIGSEGV 11
24#define SIGUSR2 12
25#define SIGPIPE 13
26#define SIGALRM 14
27#define SIGTERM 15
28#define SIGSTKFLT 16
29#define SIGCHLD 17
30#define SIGCONT 18
31#define SIGSTOP 19
32#define SIGTSTP 20
33#define SIGTTIN 21
34#define SIGTTOU 22
35
36/* Ok, I haven't implemented sigactions, but trying to keep headers POSIX */
37#define SA_NOCLDSTOP 1
38#define SA_NOMASK 0x40000000
39#define SA_ONESHOT 0x80000000
40
41#define SIG_BLOCK 0 /* for blocking signals */
42#define SIG_UNBLOCK 1 /* for unblocking signals */
43#define SIG_SETMASK 2 /* for setting the signal mask */
44
45#define SIG_DFL ((void (*)(int))0) /* default signal handling */
46#define SIG_IGN ((void (*)(int))1) /* ignore signal */
47
48struct sigaction {
49 void (*sa_handler)(int);
50 sigset_t sa_mask;
51 int sa_flags;
52 void (*sa_restorer)(void);
53};
54
55void (*signal(int _sig, void (*_func)(int)))(int);
56int raise(int sig);
57int kill(pid_t pid, int sig);
58int sigaddset(sigset_t *mask, int signo);
59int sigdelset(sigset_t *mask, int signo);
60int sigemptyset(sigset_t *mask);
61int sigfillset(sigset_t *mask);
62int sigismember(sigset_t *mask, int signo); /* 1 - is, 0 - not, -1 error */
63int sigpending(sigset_t *set);
64int sigprocmask(int how, sigset_t *set, sigset_t *oldset);
65int sigsuspend(sigset_t *sigmask);
66int sigaction(int sig, struct sigaction *act, struct sigaction *oldact);
67
68#endif /* _SIGNAL_H */
diff --git a/src/include/stdarg.h b/src/include/stdarg.h
new file mode 100644
index 0000000..fd79ec0
--- /dev/null
+++ b/src/include/stdarg.h
@@ -0,0 +1,28 @@
1#ifndef _STDARG_H
2#define _STDARG_H
3
4typedef char *va_list;
5
6/* Amount of space required in an argument list for an arg of type TYPE.
7 TYPE may alternatively be an expression whose type is used. */
8
9#define __va_rounded_size(TYPE) \
10 (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
11
12#ifndef __sparc__
13#define va_start(AP, LASTARG) \
14 (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
15#else
16#define va_start(AP, LASTARG) \
17 (__builtin_saveregs (), \
18 AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
19#endif
20
21void va_end (va_list); /* Defined in gnulib */
22#define va_end(AP)
23
24#define va_arg(AP, TYPE) \
25 (AP += __va_rounded_size (TYPE), \
26 *((TYPE *) (AP - __va_rounded_size (TYPE))))
27
28#endif /* _STDARG_H */
diff --git a/src/include/stddef.h b/src/include/stddef.h
new file mode 100644
index 0000000..97f72ff
--- /dev/null
+++ b/src/include/stddef.h
@@ -0,0 +1,19 @@
1#ifndef _STDDEF_H
2#define _STDDEF_H
3
4#ifndef _PTRDIFF_T
5#define _PTRDIFF_T
6typedef long ptrdiff_t;
7#endif
8
9#ifndef _SIZE_T
10#define _SIZE_T
11typedef unsigned long size_t;
12#endif
13
14#undef NULL
15#define NULL ((void *)0)
16
17#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
18
19#endif
diff --git a/src/include/string.h b/src/include/string.h
new file mode 100644
index 0000000..be98568
--- /dev/null
+++ b/src/include/string.h
@@ -0,0 +1,47 @@
1#ifndef _STRING_H_
2#define _STRING_H_
3
4#ifndef NULL
5#define NULL ((void *) 0)
6#endif
7
8#ifndef _SIZE_T
9#define _SIZE_T
10typedef unsigned int size_t;
11#endif
12
13extern char * strerror(int errno);
14
15/*
16 * This string-include defines all string functions as inline
17 * functions. Use gcc. It also assumes ds=es=data space, this should be
18 * normal. Most of the string-functions are rather heavily hand-optimized,
19 * see especially strtok,strstr,str[c]spn. They should work, but are not
20 * very easy to understand. Everything is done entirely within the register
21 * set, making the functions fast and clean. String instructions have been
22 * used through-out, making for "slightly" unclear code :-)
23 *
24 * (C) 1991 Linus Torvalds
25 */
26
27extern inline char * strcpy(char * dest,const char *src);
28extern inline char * strcat(char * dest,const char * src);
29extern inline int strcmp(const char * cs,const char * ct);
30extern inline int strspn(const char * cs, const char * ct);
31extern inline int strcspn(const char * cs, const char * ct);
32extern inline char * strpbrk(const char * cs,const char * ct);
33extern inline char * strstr(const char * cs,const char * ct);
34extern inline int strlen(const char * s);
35extern char * ___strtok;
36
37extern inline char * strtok(char * s,const char * ct);
38
39/*
40 * Changes by falcon<zhangjinw@gmail.com>, the original return value is static
41 * inline ... it can not be called by other functions in another files.
42 */
43
44extern inline void * memcpy(void * dest,const void * src, int n);
45extern inline void * memmove(void * dest,const void * src, int n);
46extern inline void * memchr(const void * cs,char c,int count);
47#endif
diff --git a/src/include/sys/stat.h b/src/include/sys/stat.h
new file mode 100644
index 0000000..41c3840
--- /dev/null
+++ b/src/include/sys/stat.h
@@ -0,0 +1,58 @@
1#ifndef _SYS_STAT_H
2#define _SYS_STAT_H
3
4#include <sys/types.h>
5
6struct stat {
7 dev_t st_dev;
8 ino_t st_ino;
9 umode_t st_mode;
10 nlink_t st_nlink;
11 uid_t st_uid;
12 gid_t st_gid;
13 dev_t st_rdev;
14 off_t st_size;
15 time_t st_atime;
16 time_t st_mtime;
17 time_t st_ctime;
18};
19
20#define S_IFMT 00170000
21#define S_IFREG 0100000
22#define S_IFBLK 0060000
23#define S_IFDIR 0040000
24#define S_IFCHR 0020000
25#define S_IFIFO 0010000
26#define S_ISUID 0004000
27#define S_ISGID 0002000
28#define S_ISVTX 0001000
29
30#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
31#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
32#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
33#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
34#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
35
36#define S_IRWXU 00700
37#define S_IRUSR 00400
38#define S_IWUSR 00200
39#define S_IXUSR 00100
40
41#define S_IRWXG 00070
42#define S_IRGRP 00040
43#define S_IWGRP 00020
44#define S_IXGRP 00010
45
46#define S_IRWXO 00007
47#define S_IROTH 00004
48#define S_IWOTH 00002
49#define S_IXOTH 00001
50
51extern int chmod(const char *_path, mode_t mode);
52extern int fstat(int fildes, struct stat *stat_buf);
53extern int mkdir(const char *_path, mode_t mode);
54extern int mkfifo(const char *_path, mode_t mode);
55extern int stat(const char *filename, struct stat *stat_buf);
56extern mode_t umask(mode_t mask);
57
58#endif
diff --git a/src/include/sys/times.h b/src/include/sys/times.h
new file mode 100644
index 0000000..68d5bfb
--- /dev/null
+++ b/src/include/sys/times.h
@@ -0,0 +1,15 @@
1#ifndef _TIMES_H
2#define _TIMES_H
3
4#include <sys/types.h>
5
6struct tms {
7 time_t tms_utime;
8 time_t tms_stime;
9 time_t tms_cutime;
10 time_t tms_cstime;
11};
12
13extern time_t times(struct tms * tp);
14
15#endif
diff --git a/src/include/sys/types.h b/src/include/sys/types.h
new file mode 100644
index 0000000..557aa31
--- /dev/null
+++ b/src/include/sys/types.h
@@ -0,0 +1,46 @@
1#ifndef _SYS_TYPES_H
2#define _SYS_TYPES_H
3
4#ifndef _SIZE_T
5#define _SIZE_T
6typedef unsigned int size_t;
7#endif
8
9#ifndef _TIME_T
10#define _TIME_T
11typedef long time_t;
12#endif
13
14#ifndef _PTRDIFF_T
15#define _PTRDIFF_T
16typedef long ptrdiff_t;
17#endif
18
19#ifndef NULL
20#define NULL ((void *) 0)
21#endif
22
23typedef int pid_t;
24typedef unsigned short uid_t;
25typedef unsigned char gid_t;
26typedef unsigned short dev_t;
27typedef unsigned short ino_t;
28typedef unsigned short mode_t;
29typedef unsigned short umode_t;
30typedef unsigned char nlink_t;
31typedef int daddr_t;
32typedef long off_t;
33typedef unsigned char u_char;
34typedef unsigned short ushort;
35
36typedef struct { int quot,rem; } div_t;
37typedef struct { long quot,rem; } ldiv_t;
38
39struct ustat {
40 daddr_t f_tfree;
41 ino_t f_tinode;
42 char f_fname[6];
43 char f_fpack[6];
44};
45
46#endif
diff --git a/src/include/sys/utsname.h b/src/include/sys/utsname.h
new file mode 100644
index 0000000..0a1c5a0
--- /dev/null
+++ b/src/include/sys/utsname.h
@@ -0,0 +1,16 @@
1#ifndef _SYS_UTSNAME_H
2#define _SYS_UTSNAME_H
3
4#include <sys/types.h>
5
6struct utsname {
7 char sysname[9];
8 char nodename[9];
9 char release[9];
10 char version[9];
11 char machine[9];
12};
13
14extern int uname(struct utsname * utsbuf);
15
16#endif
diff --git a/src/include/sys/wait.h b/src/include/sys/wait.h
new file mode 100644
index 0000000..53190c2
--- /dev/null
+++ b/src/include/sys/wait.h
@@ -0,0 +1,23 @@
1#ifndef _SYS_WAIT_H
2#define _SYS_WAIT_H
3
4#include <sys/types.h>
5
6#define _LOW(v) ( (v) & 0377)
7#define _HIGH(v) ( ((v) >> 8) & 0377)
8
9/* options for waitpid, WUNTRACED not supported */
10#define WNOHANG 1
11#define WUNTRACED 2
12
13#define WIFEXITED(s) (!((s)&0xFF)
14#define WIFSTOPPED(s) (((s)&0xFF)==0x7F)
15#define WEXITSTATUS(s) (((s)>>8)&0xFF)
16#define WTERMSIG(s) ((s)&0x7F)
17#define WSTOPSIG(s) (((s)>>8)&0xFF)
18#define WIFSIGNALED(s) (((unsigned int)(s)-1 & 0xFFFF) < 0xFF)
19
20pid_t wait(int *stat_loc);
21pid_t waitpid(pid_t pid, int *stat_loc, int options);
22
23#endif
diff --git a/src/include/termios.h b/src/include/termios.h
new file mode 100644
index 0000000..2b7b913
--- /dev/null
+++ b/src/include/termios.h
@@ -0,0 +1,228 @@
1#ifndef _TERMIOS_H
2#define _TERMIOS_H
3
4#define TTY_BUF_SIZE 1024
5
6/* 0x54 is just a magic number to make these relatively uniqe ('T') */
7
8#define TCGETS 0x5401
9#define TCSETS 0x5402
10#define TCSETSW 0x5403
11#define TCSETSF 0x5404
12#define TCGETA 0x5405
13#define TCSETA 0x5406
14#define TCSETAW 0x5407
15#define TCSETAF 0x5408
16#define TCSBRK 0x5409
17#define TCXONC 0x540A
18#define TCFLSH 0x540B
19#define TIOCEXCL 0x540C
20#define TIOCNXCL 0x540D
21#define TIOCSCTTY 0x540E
22#define TIOCGPGRP 0x540F
23#define TIOCSPGRP 0x5410
24#define TIOCOUTQ 0x5411
25#define TIOCSTI 0x5412
26#define TIOCGWINSZ 0x5413
27#define TIOCSWINSZ 0x5414
28#define TIOCMGET 0x5415
29#define TIOCMBIS 0x5416
30#define TIOCMBIC 0x5417
31#define TIOCMSET 0x5418
32#define TIOCGSOFTCAR 0x5419
33#define TIOCSSOFTCAR 0x541A
34#define TIOCINQ 0x541B
35
36struct winsize {
37 unsigned short ws_row;
38 unsigned short ws_col;
39 unsigned short ws_xpixel;
40 unsigned short ws_ypixel;
41};
42
43#define NCC 8
44struct termio {
45 unsigned short c_iflag; /* input mode flags */
46 unsigned short c_oflag; /* output mode flags */
47 unsigned short c_cflag; /* control mode flags */
48 unsigned short c_lflag; /* local mode flags */
49 unsigned char c_line; /* line discipline */
50 unsigned char c_cc[NCC]; /* control characters */
51};
52
53#define NCCS 17
54struct termios {
55 unsigned long c_iflag; /* input mode flags */
56 unsigned long c_oflag; /* output mode flags */
57 unsigned long c_cflag; /* control mode flags */
58 unsigned long c_lflag; /* local mode flags */
59 unsigned char c_line; /* line discipline */
60 unsigned char c_cc[NCCS]; /* control characters */
61};
62
63/* c_cc characters */
64#define VINTR 0
65#define VQUIT 1
66#define VERASE 2
67#define VKILL 3
68#define VEOF 4
69#define VTIME 5
70#define VMIN 6
71#define VSWTC 7
72#define VSTART 8
73#define VSTOP 9
74#define VSUSP 10
75#define VEOL 11
76#define VREPRINT 12
77#define VDISCARD 13
78#define VWERASE 14
79#define VLNEXT 15
80#define VEOL2 16
81
82/* c_iflag bits */
83#define IGNBRK 0000001
84#define BRKINT 0000002
85#define IGNPAR 0000004
86#define PARMRK 0000010
87#define INPCK 0000020
88#define ISTRIP 0000040
89#define INLCR 0000100
90#define IGNCR 0000200
91#define ICRNL 0000400
92#define IUCLC 0001000
93#define IXON 0002000
94#define IXANY 0004000
95#define IXOFF 0010000
96#define IMAXBEL 0020000
97
98/* c_oflag bits */
99#define OPOST 0000001
100#define OLCUC 0000002
101#define ONLCR 0000004
102#define OCRNL 0000010
103#define ONOCR 0000020
104#define ONLRET 0000040
105#define OFILL 0000100
106#define OFDEL 0000200
107#define NLDLY 0000400
108#define NL0 0000000
109#define NL1 0000400
110#define CRDLY 0003000
111#define CR0 0000000
112#define CR1 0001000
113#define CR2 0002000
114#define CR3 0003000
115#define TABDLY 0014000
116#define TAB0 0000000
117#define TAB1 0004000
118#define TAB2 0010000
119#define TAB3 0014000
120#define XTABS 0014000
121#define BSDLY 0020000
122#define BS0 0000000
123#define BS1 0020000
124#define VTDLY 0040000
125#define VT0 0000000
126#define VT1 0040000
127#define FFDLY 0040000
128#define FF0 0000000
129#define FF1 0040000
130
131/* c_cflag bit meaning */
132#define CBAUD 0000017
133#define B0 0000000 /* hang up */
134#define B50 0000001
135#define B75 0000002
136#define B110 0000003
137#define B134 0000004
138#define B150 0000005
139#define B200 0000006
140#define B300 0000007
141#define B600 0000010
142#define B1200 0000011
143#define B1800 0000012
144#define B2400 0000013
145#define B4800 0000014
146#define B9600 0000015
147#define B19200 0000016
148#define B38400 0000017
149#define EXTA B19200
150#define EXTB B38400
151#define CSIZE 0000060
152#define CS5 0000000
153#define CS6 0000020
154#define CS7 0000040
155#define CS8 0000060
156#define CSTOPB 0000100
157#define CREAD 0000200
158#define CPARENB 0000400
159#define CPARODD 0001000
160#define HUPCL 0002000
161#define CLOCAL 0004000
162#define CIBAUD 03600000 /* input baud rate (not used) */
163#define CRTSCTS 020000000000 /* flow control */
164
165#define PARENB CPARENB
166#define PARODD CPARODD
167
168/* c_lflag bits */
169#define ISIG 0000001
170#define ICANON 0000002
171#define XCASE 0000004
172#define ECHO 0000010
173#define ECHOE 0000020
174#define ECHOK 0000040
175#define ECHONL 0000100
176#define NOFLSH 0000200
177#define TOSTOP 0000400
178#define ECHOCTL 0001000
179#define ECHOPRT 0002000
180#define ECHOKE 0004000
181#define FLUSHO 0010000
182#define PENDIN 0040000
183#define IEXTEN 0100000
184
185/* modem lines */
186#define TIOCM_LE 0x001
187#define TIOCM_DTR 0x002
188#define TIOCM_RTS 0x004
189#define TIOCM_ST 0x008
190#define TIOCM_SR 0x010
191#define TIOCM_CTS 0x020
192#define TIOCM_CAR 0x040
193#define TIOCM_RNG 0x080
194#define TIOCM_DSR 0x100
195#define TIOCM_CD TIOCM_CAR
196#define TIOCM_RI TIOCM_RNG
197
198/* tcflow() and TCXONC use these */
199#define TCOOFF 0
200#define TCOON 1
201#define TCIOFF 2
202#define TCION 3
203
204/* tcflush() and TCFLSH use these */
205#define TCIFLUSH 0
206#define TCOFLUSH 1
207#define TCIOFLUSH 2
208
209/* tcsetattr uses these */
210#define TCSANOW 0
211#define TCSADRAIN 1
212#define TCSAFLUSH 2
213
214typedef int speed_t;
215
216extern speed_t cfgetispeed(struct termios *termios_p);
217extern speed_t cfgetospeed(struct termios *termios_p);
218extern int cfsetispeed(struct termios *termios_p, speed_t speed);
219extern int cfsetospeed(struct termios *termios_p, speed_t speed);
220extern int tcdrain(int fildes);
221extern int tcflow(int fildes, int action);
222extern int tcflush(int fildes, int queue_selector);
223extern int tcgetattr(int fildes, struct termios *termios_p);
224extern int tcsendbreak(int fildes, int duration);
225extern int tcsetattr(int fildes, int optional_actions,
226 struct termios *termios_p);
227
228#endif
diff --git a/src/include/time.h b/src/include/time.h
new file mode 100644
index 0000000..d0a765d
--- /dev/null
+++ b/src/include/time.h
@@ -0,0 +1,42 @@
1#ifndef _TIME_H
2#define _TIME_H
3
4#ifndef _TIME_T
5#define _TIME_T
6typedef long time_t;
7#endif
8
9#ifndef _SIZE_T
10#define _SIZE_T
11typedef unsigned int size_t;
12#endif
13
14#define CLOCKS_PER_SEC 100
15
16typedef long clock_t;
17
18struct tm {
19 int tm_sec;
20 int tm_min;
21 int tm_hour;
22 int tm_mday;
23 int tm_mon;
24 int tm_year;
25 int tm_wday;
26 int tm_yday;
27 int tm_isdst;
28};
29
30clock_t clock(void);
31time_t time(time_t * tp);
32double difftime(time_t time2, time_t time1);
33time_t mktime(struct tm * tp);
34
35char * asctime(const struct tm * tp);
36char * ctime(const time_t * tp);
37struct tm * gmtime(const time_t *tp);
38struct tm *localtime(const time_t * tp);
39size_t strftime(char * s, size_t smax, const char * fmt, const struct tm * tp);
40void tzset(void);
41
42#endif
diff --git a/src/include/unistd.h b/src/include/unistd.h
new file mode 100644
index 0000000..956554a
--- /dev/null
+++ b/src/include/unistd.h
@@ -0,0 +1,254 @@
1#ifndef _UNISTD_H
2#define _UNISTD_H
3
4/* ok, this may be a joke, but I'm working on it */
5#define _POSIX_VERSION 198808L
6
7#define _POSIX_CHOWN_RESTRICTED /* only root can do a chown (I think..) */
8#define _POSIX_NO_TRUNC /* no pathname truncation (but see in kernel) */
9#define _POSIX_VDISABLE '\0' /* character to disable things like ^C */
10/*#define _POSIX_SAVED_IDS */ /* we'll get to this yet */
11/*#define _POSIX_JOB_CONTROL */ /* we aren't there quite yet. Soon hopefully */
12
13#define STDIN_FILENO 0
14#define STDOUT_FILENO 1
15#define STDERR_FILENO 2
16
17#ifndef NULL
18#define NULL ((void *)0)
19#endif
20
21/* access */
22#define F_OK 0
23#define X_OK 1
24#define W_OK 2
25#define R_OK 4
26
27/* lseek */
28#define SEEK_SET 0
29#define SEEK_CUR 1
30#define SEEK_END 2
31
32/* _SC stands for System Configuration. We don't use them much */
33#define _SC_ARG_MAX 1
34#define _SC_CHILD_MAX 2
35#define _SC_CLOCKS_PER_SEC 3
36#define _SC_NGROUPS_MAX 4
37#define _SC_OPEN_MAX 5
38#define _SC_JOB_CONTROL 6
39#define _SC_SAVED_IDS 7
40#define _SC_VERSION 8
41
42/* more (possibly) configurable things - now pathnames */
43#define _PC_LINK_MAX 1
44#define _PC_MAX_CANON 2
45#define _PC_MAX_INPUT 3
46#define _PC_NAME_MAX 4
47#define _PC_PATH_MAX 5
48#define _PC_PIPE_BUF 6
49#define _PC_NO_TRUNC 7
50#define _PC_VDISABLE 8
51#define _PC_CHOWN_RESTRICTED 9
52
53#include <sys/stat.h>
54#include <sys/times.h>
55#include <sys/utsname.h>
56#include <utime.h>
57
58#ifdef __LIBRARY__
59
60#define __NR_setup 0 /* used only by init, to get system going */
61#define __NR_exit 1
62#define __NR_fork 2
63#define __NR_read 3
64#define __NR_write 4
65#define __NR_open 5
66#define __NR_close 6
67#define __NR_waitpid 7
68#define __NR_creat 8
69#define __NR_link 9
70#define __NR_unlink 10
71#define __NR_execve 11
72#define __NR_chdir 12
73#define __NR_time 13
74#define __NR_mknod 14
75#define __NR_chmod 15
76#define __NR_chown 16
77#define __NR_break 17
78#define __NR_stat 18
79#define __NR_lseek 19
80#define __NR_getpid 20
81#define __NR_mount 21
82#define __NR_umount 22
83#define __NR_setuid 23
84#define __NR_getuid 24
85#define __NR_stime 25
86#define __NR_ptrace 26
87#define __NR_alarm 27
88#define __NR_fstat 28
89#define __NR_pause 29
90#define __NR_utime 30
91#define __NR_stty 31
92#define __NR_gtty 32
93#define __NR_access 33
94#define __NR_nice 34
95#define __NR_ftime 35
96#define __NR_sync 36
97#define __NR_kill 37
98#define __NR_rename 38
99#define __NR_mkdir 39
100#define __NR_rmdir 40
101#define __NR_dup 41
102#define __NR_pipe 42
103#define __NR_times 43
104#define __NR_prof 44
105#define __NR_brk 45
106#define __NR_setgid 46
107#define __NR_getgid 47
108#define __NR_signal 48
109#define __NR_geteuid 49
110#define __NR_getegid 50
111#define __NR_acct 51
112#define __NR_phys 52
113#define __NR_lock 53
114#define __NR_ioctl 54
115#define __NR_fcntl 55
116#define __NR_mpx 56
117#define __NR_setpgid 57
118#define __NR_ulimit 58
119#define __NR_uname 59
120#define __NR_umask 60
121#define __NR_chroot 61
122#define __NR_ustat 62
123#define __NR_dup2 63
124#define __NR_getppid 64
125#define __NR_getpgrp 65
126#define __NR_setsid 66
127#define __NR_sigaction 67
128#define __NR_sgetmask 68
129#define __NR_ssetmask 69
130#define __NR_setreuid 70
131#define __NR_setregid 71
132
133#define _syscall0(type,name) \
134 type name(void) \
135{ \
136long __res; \
137__asm__ volatile ("int $0x80" \
138 : "=a" (__res) \
139 : "0" (__NR_##name)); \
140if (__res >= 0) \
141 return (type) __res; \
142errno = -__res; \
143return -1; \
144}
145
146#define _syscall1(type,name,atype,a) \
147type name(atype a) \
148{ \
149long __res; \
150__asm__ volatile ("int $0x80" \
151 : "=a" (__res) \
152 : "0" (__NR_##name),"b" ((long)(a))); \
153if (__res >= 0) \
154 return (type) __res; \
155errno = -__res; \
156return -1; \
157}
158
159#define _syscall2(type,name,atype,a,btype,b) \
160type name(atype a,btype b) \
161{ \
162long __res; \
163__asm__ volatile ("int $0x80" \
164 : "=a" (__res) \
165 : "0" (__NR_##name),"b" ((long)(a)),"c" ((long)(b))); \
166if (__res >= 0) \
167 return (type) __res; \
168errno = -__res; \
169return -1; \
170}
171
172#define _syscall3(type,name,atype,a,btype,b,ctype,c) \
173type name(atype a,btype b,ctype c) \
174{ \
175long __res; \
176__asm__ volatile ("int $0x80" \
177 : "=a" (__res) \
178 : "0" (__NR_##name),"b" ((long)(a)),"c" ((long)(b)),"d" ((long)(c))); \
179if (__res>=0) \
180 return (type) __res; \
181errno=-__res; \
182return -1; \
183}
184
185#endif /* __LIBRARY__ */
186
187extern int errno;
188
189int access(const char * filename, mode_t mode);
190int acct(const char * filename);
191int alarm(int sec);
192int brk(void * end_data_segment);
193void * sbrk(ptrdiff_t increment);
194int chdir(const char * filename);
195int chmod(const char * filename, mode_t mode);
196int chown(const char * filename, uid_t owner, gid_t group);
197int chroot(const char * filename);
198int close(int fildes);
199int creat(const char * filename, mode_t mode);
200int dup(int fildes);
201int execve(const char * filename, char ** argv, char ** envp);
202int execv(const char * pathname, char ** argv);
203int execvp(const char * file, char ** argv);
204int execl(const char * pathname, char * arg0, ...);
205int execlp(const char * file, char * arg0, ...);
206int execle(const char * pathname, char * arg0, ...);
207//volatile void exit(int status);
208void _exit(int status);
209//volatile void _exit(int status);
210int fcntl(int fildes, int cmd, ...);
211static int fork(void);
212int getpid(void);
213int getuid(void);
214int geteuid(void);
215int getgid(void);
216int getegid(void);
217int ioctl(int fildes, int cmd, ...);
218int kill(pid_t pid, int signal);
219int link(const char * filename1, const char * filename2);
220int lseek(int fildes, off_t offset, int origin);
221int mknod(const char * filename, mode_t mode, dev_t dev);
222int mount(const char * specialfile, const char * dir, int rwflag);
223int nice(int val);
224int open(const char * filename, int flag, ...);
225static int pause(void);
226int pipe(int * fildes);
227int read(int fildes, char * buf, off_t count);
228int setpgrp(void);
229int setpgid(pid_t pid,pid_t pgid);
230int setuid(uid_t uid);
231int setgid(gid_t gid);
232void (*signal(int sig, void (*fn)(int)))(int);
233int stat(const char * filename, struct stat * stat_buf);
234int fstat(int fildes, struct stat * stat_buf);
235int stime(time_t * tptr);
236static int sync(void);
237time_t time(time_t * tloc);
238time_t times(struct tms * tbuf);
239int ulimit(int cmd, long limit);
240mode_t umask(mode_t mask);
241int umount(const char * specialfile);
242int uname(struct utsname * name);
243int unlink(const char * filename);
244int ustat(dev_t dev, struct ustat * ubuf);
245int utime(const char * filename, struct utimbuf * times);
246pid_t waitpid(pid_t pid,int * wait_stat,int options);
247pid_t wait(int * wait_stat);
248int write(int fildes, const char * buf, off_t count);
249int dup2(int oldfd, int newfd);
250int getppid(void);
251pid_t getpgrp(void);
252pid_t setsid(void);
253
254#endif
diff --git a/src/include/utime.h b/src/include/utime.h
new file mode 100644
index 0000000..83f07c7
--- /dev/null
+++ b/src/include/utime.h
@@ -0,0 +1,13 @@
1#ifndef _UTIME_H
2#define _UTIME_H
3
4#include <sys/types.h> /* I know - shouldn't do this, but .. */
5
6struct utimbuf {
7 time_t actime;
8 time_t modtime;
9};
10
11extern int utime(const char *filename, struct utimbuf *times);
12
13#endif