vsta

Check-in [b9beed8571]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Move main tree contents to top
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:b9beed85716615f06987996294c98e0ced78ad518773ddd016e700f724894612
User & Date: ajv-899-334-8894@vsta.org 2015-01-11 23:47:20
Context
2015-01-11
23:52
Remove DOS filesystem executable bit brain damange check-in: 4a5dd1f920 user: ajv-899-334-8894@vsta.org tags: master, trunk
23:47
Move main tree contents to top check-in: b9beed8571 user: ajv-899-334-8894@vsta.org tags: master, trunk
23:46
Remove old test stuff check-in: fa8ae72fc1 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to LICENSE.


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

GNU GENERAL PUBLIC LICENSE
                       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for


this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

                    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third

    parties under the terms of this License.



    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)


These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.




Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.


  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,


    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete

    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,


    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the

operating system on which the executable runs, unless that component
itself accompanies the executable.



If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under

this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

                            NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.


  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    {description}

    Copyright (C) {year}  {fullname}

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) year name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.


You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program

  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  {signature of Ty Coon}, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

>
|
|

|
<
>



|

|
|

|
|
|
<
<
|


<
<
>
>
|
|
|






|


|
<












<
<
<
<
<
<


|
|


|
|
|
|
|
<
|
<
|

<
<
<
<
<
<
<
|
|
|
|
|
|
|
<
|
<

|
<
|
|

|
|

|
|
<
>
|
>
>

|
|
|
|
|
|
|
<
<
<
>

<
<
<
<
<
<
<
<
<
>
>
>

<
<
<
<
<
|
<
|
<
>
|
|
|
|

|
|
<
>

|
|
<
>
|
<
<
>

|
|

|
<

|
|
|
<
<
<
<
<
>
|
<
>
>

<
<
<
<
<
<
|
|
|
|
|
>
|
|

<
<
<
<
|
|
|
<


|
|
|
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|





|



|


|







|

|









|









|
|
|


|
|
>

|
|
|
|

<
>
|



|
|






|
|
|






|




|
|
|
|
>



|

|
>
|

|


<
|
<
<
<
<
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





		    GNU GENERAL PUBLIC LICENSE
		     Version 1, February 1989

 Copyright (C) 1989 Free Software Foundation, Inc.

                    675 Mass Ave, Cambridge, MA 02139, USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The license agreements of most software companies try to keep users
at the mercy of those companies.  By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.


You can use it for your programs, too.

  When we speak of free software, we are referring to freedom, not


price.  Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must tell them their rights.


  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.







  The precise terms and conditions for copying, distribution and
modification follow.
 
		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License.  The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the

Program or a portion of it, either verbatim or with modifications.  Each

licensee is addressed as "you".








  1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program.  You may charge a fee for the physical act of

transferring a copy.


  2. You may modify your copy or copies of the Program or any portion of

it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:

    a) cause the modified files to carry prominent notices stating that
    you changed the files and the date of any change; and

    b) cause the whole of any work that you distribute or publish, that
    in whole or in part contains the Program or any part thereof, either

    with or without modifications, to be licensed at no charge to all
    third parties under the terms of this General Public License (except
    that you may choose to grant warranty protection to some or all
    third parties, at your option).

    c) If the modified program normally reads commands interactively when
    run, you must cause it, when started running for such interactive use
    in the simplest and most usual way, to print or display an
    announcement including an appropriate copyright notice and a notice
    that there is no warranty (or else, saying that you provide a
    warranty) and that users may redistribute the program under these
    conditions, and telling the user how to view a copy of this General



    Public License.










    d) You may charge a fee for the physical act of transferring a
    copy, and you may at your option offer warranty protection in
    exchange for a fee.






Mere aggregation of another independent work with the Program (or its

derivative) on a volume of a storage or distribution medium does not bring

the other work under the scope of these terms.
 
  3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:

    a) accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of

    Paragraphs 1 and 2 above; or,

    b) accompany it with a written offer, valid for at least three
    years, to give any third party free (except for a nominal charge

    for the cost of distribution) a complete machine-readable copy of the
    corresponding source code, to be distributed under the terms of


    Paragraphs 1 and 2 above; or,

    c) accompany it with the information you received as to where the
    corresponding source code may be obtained.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form alone.)


Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special





exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable

file runs, or for standard header files or definitions files that
accompany that operating system.







  4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License.  However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.





  5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.


  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions.  You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.


 








































  7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.

  8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS
 
	Appendix: How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.

  To do so, attach the following notices to the program.  It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.


    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 19yy  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 1, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) 19xx name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License.  Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  program `Gnomovision' (a program to direct compilers to make passes
  at assemblers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice


That's all there is to it!




Added README.































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
This is VSTA, the Valencia Simple TAsker.

Well, with VM, SMP, processes, threads, and messaging it isn't as
simple as I envisioned it when I made up the name, but there you
are.

This software was written from scratch entirely by:

	Andrew Valencia
	P.O. Box 2928
	Vashon, WA  98070
	vandys@vsta.org

and is copyright 1993-1998 and 2000-2002 by Andrew Valencia.  Use of
this software is permitted under the terms listed in the file
"license", which should accompany this file at the top level of
the software distribution.  If it is missing for any reason, you
may contact Andrew Valencia directly to receive a copy.

There are source files which are not original; they are identified
in their headers, and are used and available under the terms
expressed by the original author.

In addition to the requirements spelled out in the license, I also
specifically require that any distribution of this software include
this file, and the "license" file.  I have not placed those noisy
copyright headers into each and every file, so I am counting on
the Berne Convention and the presence of the "readme" and "license"
files.

To get started, see the file /vsta/doc/roadmap.txt.

Added boot/Makefile.























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
OUT=build
include ../src/makefile.all

build:

clean:

clobber:

install:
	cp menu.lst readme $(ROOT)/boot

Added boot/menu.lst.





































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#
# Sample boot menu configuration file
#

# Timeout here...
# timeout = 30

# For booting Mach (getting kernel from floppy)
# title=          Utah Mach4 multiboot
# root=   (hd0,2)
# pause=My test!!
# kernel= (fd0)/boot/kernel root=hd0s3
# module= (fd0)/boot/bootstrap

# For booting FreeBSD (getting kernel from floppy)
# title=          FreeBSD 2.2-SNAP
# root=   (hd0,2)
# kernel= (fd0)/kernel

# For booting the GNU HURD (getting kernel from floppy)
# title=          GNU HURD
# root=   (hd0,a)
# kernel= /boot/kernel root=hd0a
# module= /boot/serverboot

# For booting OS/2  (test, I have no OS/2 to test for!)
# title=          OS/2
# root=           (hd0,1)
# makeactive
# chainloader=    /boot/chain.os2
# This is similar to "chainload", but loads a specific file

# For booting Microdreck stuff
title=          Boot DOS
root=           (hd0,0)
makeactive
chainloader=    +1

#
# For booting VSTa
#  The "modules=" statements below configure the booting system
#
title=          VSTa boot
root=           (hd0,0)
kernel=         /vsta/boot/vsta

# The modules used to boot
# If you edit these, be sure to refer to "VSTa debug" below, where
#  you must edit them again.

# The console driver
# cons -color           (default)
# or cons -mono         - For MGA text screen location
module= /vsta/boot/cons

# The name to port # mapper
module= /vsta/boot/namer

# The WD (ST-506 & IDE) driver
#
# Very likely you will not have to change this.  The default here
# is "readp", which reads the parameters from the IDE interface.
#
module= /vsta/boot/wd d0:readp
# or wd d0:cmos         - For CMOS parameter setup
# wd d0:cmos d1:cmos    - For two drives
# wd d0:cmos d1:readp   -  ...any combination, as needed
#               - D0 from CMOS, D1 from controller
# wd d0:<cyls>:<heads>:<sec/track>
#               - Manual setup; hand-specify the parameters

# Adaptec 1542b/c SCSI disk support
# You will almost certainly also want to read ../src/srv/mach/scsi/readme
# module= /vsta/boot/cam

# The swap driver.  It handles management of multiple swap partitions.
# Uncomment this only if you have taken care of setting up the VSTa
# swapping feature.
#
# module= /vsta/boot/swap

# The first DOS filesystem
module= /vsta/boot/dos -d //disk/wd:wd0_dos0 -n fs/root -B 8192
# This mounts the first DOS partition on the first WD drive, and
#  advertises it (via namer) as the root filesystem for the system.
# "-B 8192" uses a 4 meg buffer cache; trim back to 4096 or 2048
#  if you have less than 16 megs of memory.

# A VSTa filesystem as root
# Use this only if you have previously set up a vstafs filesystem.
# module= /vsta/boot/vstafs -d //disk/wd:wd0_bfs0 -n fs/root -B 8192

# The only program not a server in this file
module= /vsta/boot/init
# This reads the /vsta/etc/inittab and fires off most of the usual cruft
#  needed to boot.

#
# For booting a freshly built VSTa
#
title=          VSTa debug
root=           (hd0,0)
kernel=         /vsta/src/os/make/vsta
#
# These are commented in the "VSTa boot" section above, and should be
#  identical to what you selected there.  You may, of course, edit
#  the paths to point at newly built modules in their vsta/src/...
#  location.
#
module= /vsta/boot/cons
module= /vsta/boot/namer
module= /vsta/boot/wd d0:readp
module= /vsta/boot/dos -d //disk/wd:wd0_dos0 -n fs/root -B 8192
module= /vsta/boot/init

Added boot/readme.





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
This directory previously held a boot loader "boot.exe" which ran from under
DOS and used the "boot.lst" configuration file.  VSTa is now Multiboot
compliant, and the preferred boot loader is "GRUB" (GRand Unified
Bootloader).  It now just contains the source controlled files which are
installed into /vsta/boot.  /vsta/boot also contains a kernel usable from
GRUB, as well as the other server executables needed to boot VSTa.  See
vsta/doc/roadmap.txt for more details on configuring GRUB with VSTa.

Once you have read about GRUB, the menu.lst file provided in this directory
provides some useful examples of how to set up GRUB to boot various
operating systems, including VSTa.

					Andy Valencia
					September, 1997

Added doc/Makefile.

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
OUT=build
include ../src/makefile.all

build:

clean:

clobber:

install:
	cp *.txt *.doc $(ROOT)/doc
	cd man ; make install ; cd ..

Added doc/coding.txt.











































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
The coding standards for VSTa.

Yes, we have coding standards.  The ones described here apply to
the kernel, C library, utility library, and "core servers"--the ones
you will generally use to boot.  A seperate coding standard
exists for the windowing system.  If another distinct subsystem
comes up, and you write it from scratch, then you can apply your
own coding standard to that part.

I've tried to hone it down to just 10 rules.  It seems like a lot,
but hopefully 5 of them will match your personal style anyway,
so it isn't as bad as it looks.

In case you're wondering, this wasn't my C style of choice either.
But I learned it at HP for their kernel, and had it heavily
reinforced at Sequent with their kernel gurus.  So now I stick with
it, accepting Henry's observation that "standard is better than
better", at least for C styles.

0. Henry Spencer's Rules of C

	Read this article.  Believe it.  The rest of this is just
some refinement of what he says.  This doesn't count as one of the
10, because you shouldn't be writing C until you have read this.
I have included it as "ten.doc" in vsta/doc.

1. Comments

/*
 * function_name()
 *	One-liner (only) for the function
 *
 * Further discussion.  This is a good place to mention success/failure
 * values and so forth.
 *
 * A distinct thought, or perhaps a note about assumptions or limitations.
 */
struct foobar *
function_name(void)
{
	int x;

	/*
	 * Describe a block of code, then write the block of code
	 */
	for (x = 0; x < FOOBLAT; ++x) {
		something(x);
		...
	}
}

Do NOT use pretty blocks of stars.  They make it hard to update
the comments.  We all know what happens when comments are a pain
to update....

2. Conditionals

	if (condition) {
		...
	}

	if (condition1 || condition2) {
	} else {
	}

	if (foo && !bar) {
	} else if (bletch) {
	}

3. Loops

	for (x = 0; x < 20; ++x) {
	}

Do NOT use the open version:
	for (x = 0; x < 20; ++x)
		bar();
If you aren't tripped by it, somebody else will be instead.

4. Indentation

	Do not use tabs in the actual data part.  You may use tabs
to space out to the following comments.  Trailing tabs before the
closing */ just make it hard to add further words.  Yes, making the
closing */'s on lines match up is pretty, but we have art and
museums for that.

int foob;		/* Will count instances of foob */
static char bar;	/*  ...the char matching foob */

5. Patching somebody's code

	Do not go fiddle somebody's organization just because
you think you can make it prettier.  It is especially bad form
to fiddle the indentation and layout, PLUS add some new stuff,
then hand them back the entire result.  Now they have to dig
through a bunch of indentation changes while trying to find
functional changes.

extern int x, y, z;

	VVV

extern int x;
extern int y;
extern int w;
extern int z;

	Such a change adds little, but fills our screens with
diffs.  If you take over the file AND you add comments to each
line, it might be worth it.  It sure would be easy to miss
that "w" in there at the same time, wouldn't it?

6. ANSI prototypes

	Use ANSI prototypes where possible.  The one major
pain is anonymous struct pointers.  Imagine a header
which uses an anonymous pointer (i.e., they know the name
of the struct they're pointing to, but they don't know
the definitions of the struct.)  gcc will complain about
such a prototype:

extern void my_func(struct foob *);

unless he has already seen "struct foob" at level 0 (global).

The workaround of choice is to use STRUCT_REF in <sys/types.h>.

7. ANSI void *

	Use ANSI void pointers when you're dealing with
a generic pointer value.  Do NOT do math with such a pointer.
Yes, GCC will happen to treat it as a char *.  If you're counting
on this, cast it to (char *) and then do the math.

8. C types

	Use the basic C types for most work.  If you have a
struct pointer, just name it as such.  I want:

struct foo {
	int field1;
	...
};
...
{
	struct foo *f;

	f = ...;
	f->field1 = bar;
}

And not:

typedef struct {
	int field1;
	...
} foo_t;
...

C has good basic ways for naming types, and typedef's should
not be used to hide them.  The exceptions are industry-recognized
types like "ushort" (unsigned short) and so forth.

9. #define's

	A short #define can help encapsulate a simple operation
or value into a useful name.  If you find that the number of
"#define"'s is becoming a large fraction of your header file
(or even your code!) then back off.  Make it a function.  Maybe
it'll go slower... maybe GCC will in-line it anyway.

10. Variable names

	Use short variable names.  A phone number is 7 digits
because that's the size of "name" the human mind can carry around
easily.  Keep your variables in the same class of length.  Long,
descriptive variables make code-reading cumbersome, as the mind
continually must re-parse the components of the variable name.
Globals used across source files will tend to be a little bit
longer.

Added doc/faq.txt.

































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688

v0.3 FAQ for VSTa:

	Frequently Asked Questions About VSTa

1. What is VSTa?

VSTa is a copylefted operating system created by Andy Valencia
(vandys@cisco.com) and later enhanced by numerous others.  It uses a
microkernel organization, in which the "kernel" code is very small (~40k)
and all filesystems and drivers reside in "user" mode processes.  At user
level it looks substantially like a POSIX-type system.

2. What does "VSTa" stand for

The "Valencia Simple Tasker".  Actually, the 40K in the kernel suports
kernel preemption, shared memory MIMD multiprocessors, and virtual memory.
It really isn't all that simple!

3. What does VSTa run on?

VSTa was originally written for the i386 PC.  It has since run on 2 meg
386sx processors and 16 meg Pentium processors.  The DMA system handles
memory for > 16 meg ISA bus access using a bounce buffer.

VSTa has driver support for ST-506, IDE, and Adaptec 1542[bc] disk
interfaces.  It supports floppy drives, MGA and CGA monitors, RS-232
interfaces, parallel interfaces, NE2000 LAN cards, and bus or serial mice.
Under SCSI, it also supports CDROM and tape.

VSTa has a port to the Amiga with 68030.  It supports the display,
keyboard, and SCSI disk.  While operational, it is not being actively
maintained.

The VSTa kernel has been ported to a MIPS R4000.

Someone once looked at a port to the SPARC.  No bootable code was ever
reported.

4. How do I get VSTa?

Its primary distribution site is:

	ftp://ftp.vsta.org/vsta

Other mirror sites exist; use a search engine.

5. How do I boot it?

VSTa uses the Multiboot standard, and can be loaded from any
bootloader which uses that standard.  The most common is GRUB
("GRand Unified Bootloader), which is available at:

	http://www.gnu.org/software/grub/

GRUB loads the kernel image and any "boot servers" (which are like any
program running under VSTa, except they exist as processes at boot
time, so they can provide disk I/O and such without having to build
this into the kernel).  DOS/FAT is your "boot filesystem"; you can
access many types of filesystems (including DOS) once VSTa is
running.

For the nuts and bolts of doing this, see the file vsta_*.readme on the
FTP site.  This will point you to the files "license" and "readme" in
the vsta.tz compressed archive.  These provide information on the terms
and conditions for use of VSTa.  Then it points you to doc/roadmap.txt
in the same archive, which tells you how to boot up the system.

6. Ok, I booted it, but how do I find out more about its design?

The FTP sites hold an aged introduction paper.  The mailing list archives
at the FTP sites contain several messages which describe the design of
various parts (booting, VM, scheduling, ...) of the system.  If you are
searching for a particular topic, a hypertext index:

	http://www.vsta.org/mail

will let you read through the mail archives.

The doc/ subdirectory of a VSTa distribution holds a skeletal amount of
documentation on the basic kernel interfaces.  More will be added
(time permitting :->).

Finally, the code itself has relatively consistent and numerous comments.

6. I boot up, and see the disk blink, but my screen doesn't show anything

The default in boot/boot.lst is for a CGA system.  MGA cards place text at a
different address; add the -mga flag to the "cons" server.

The kernel debugger also needs to be flagged this way; you need to edit
the file os/mach/dbg_ibm.c and then rebuild your kernel.

7. Does it network?

A port of KA9Q has been done.  It uses ne2000 or 3c509 cards and can be
used to telnet and FTP.  KA9Q provides a /inet filesystem interface,
which processes can open and use to receive and initiate TCP connections.
A telnetd has been implemented, permitting network logins to VSTa.
A proxy daemon can make the kernel IPC transparently accessiable from
any other IP node.  Since almost all services are built on top of kernel
IPC, in practice this means much of VSTa can be transparently accessed
from any network location.

8. What's being developed for VSTa?

VSTa has been ported to the 68030 and R4000.  MGR is the primary
windowing system, and runs pretty well.  Over time, more and newer
ports of various UNIX-ish software get ported.  select() support
was added recently.

9. Is there a mailing list?

We run a VSTa mailing list.  Send a subscription request to:

    vsta-request@zendo.com

There's no list server, so feel free to use English.  Once you're on the
list, send to:

    vsta@zendo.com

and the message will be distributed to all members.  There is a spam
filter, so be sure to send from your subscribed address.  Where this is
a problem, send a note to vsta-request and we can register more
addresses.

A digest format is available; specify this in your subscription request
if you prefer it.  Our digest algorithm is to wait up to three days to
collect three messages.

10. That's a lot of text to search!  Is there an archive?

Here's a collection of technical information culled form the list.  Thanks
to David Johnson for doing this!

==============================================================================
How did VSTa start?
==============================================================================

Real-time support: I wanted enough RT support to do com port drivers and
such in user mode.  I never really intended to add the RT support needed
to allow implementation of "hard" RT systems, that is a Phalanx system or
other scary thing where you *need* *guarantees* about which parts get
processed how.  Of course, VSTa has become more than my own interests; I
opened it up so it can benefit from other people's expertise.  If somebody
gives me patches to add better RT support, my only objective would be to
keep the microkernel "micro".

Threads/scheduling: I implemented the kind of thread which my own experience
indicated I would want.  The hierarchical scheduler lends itself well to
this organization--threads exist in common below a single node representing
the process.  POSIX yield() (or whatever they named it this week) would be
very gratifying to code up!

Distribution: I still don't think I want to put distributed messaging into
the kernel.  If a client writes a message to a server:

Client -> Server

I really don't see why we can't implement this as:

	SystemA		      |		System B
Client -> (TCP server -> LAN) -> (LAN -> TCP server) -> Server
			      |

The much more interesting question is what kind of smoke and mirrors are
needed to cause such a connection to come into existence without a lot
of explicit, networking-oriented commands on the part of a client.  My
current guess is that the namer process becomes a lot more complex, and
perhaps interacts with the kernel port_name->server mechanism.

VSTa development: I wrote the data structures, and then the messaging
interface.  I coded a server (BFS, I think), modifying the messaging
interface as needed to make writing the server reasonable.  I then wrote up
some messaging emulation routines, and could then run BFS under DOS with
myself typing in things to make it look like BFS had clients coming in over
VSTa.  I wrote the console, keyboard, and then I think I started in on the
kernel.  The first thing the kernel ever ran was a single process which put
a * out on the COM1 port.  Next was a process writing "Hello, world" to the
console server, which displayed it on the screen.  After that was a walking
*'s thing to run the messaging system at full speed.


==============================================================================
What is a port number?
==============================================================================

A port number (type port_name from <sys/types.h>) is indeed a unique
identifier for a server port on a machine running VSTa.  In general, a
server allows the kernel to allocate an identifier dynamically, and then
the server advertises itself by creating a file in /namer whose contents is
its port_name.  Thus, the "fd" server (floppy disk) might get the value
1027, and then he write "1027" onto /namer/disk/fd.  When somebody wants to
talk to the "fd" server, they open /namer/disk/fd, read the number 1027, and
then msg_connect() to port_name 1027.

A very few port_name's are "well known".  The /namer server is always 1,
This allows you to connect to /namer initially, otherwise there's the
"chicken and egg" problem of how to find the service which helps you find
services.


==============================================================================
Namer/mounttab/open description
==============================================================================

The VSTa microkernel does not have any filesystem code.  Not only does this
mean that the kernel does not know about inodes, directory entries, and so
forth.  It also means that he does not understand what an "open file" is,
nor "file position", nor "path name lookup".

Filesystems are an illusion created by cooperation between servers
and the C library.  By agreeing to certain message types and arguments,
they can talk about common file operations.  The file include/sys/fs.h
defines these messages; servers implement them from the main message
handling loop, and clients generally request them through the C library.

If you go into vsta/libc/open.c, you will see what is, in UNIX-ese, the
"namei" loop--the loop which maps string pathnames into open files.  It
does this by finding the longest initial match between the filename you
want to open, and a path in its mount table.  For example:

	fd = open("/usr/local/lib/table.txt", O_READ);

Mount table:	Path		Connection
		/		(DOS server)
		/dev/wd		(WD server)
		/env		(Environment variable server)
		/usr/local	(VstaFS server)
		/namer		(Name server)

The match would be against /usr/local, since this matches to more positions
than any other entry.  The matched part is stripped, and the path lookup
now walks through each remaining part.  So the filesystem server which happens
to be mounted under /usr/local for the current process will see successive
lookups for "lib", and then "table.txt".

All well and good, but the question occurs: how do you get your mount table
set up in the first place?  Since you start with your mount table empty,
you can't very well open a file!  If you happen to know some desirable
server is at port address 1234, you could:

	port = msg_connect(1234, ACC_READ);
	mountport("/path", port);

A small set of port addresses--just enough to boot--are at "well known
addresses".  This includes the keyboard, screen, and namer server.  It
does NOT include disk drivers or root filesystems.  In fact, there are
more well-known addresses assigned than are needed.  I should probably
fix this.

Anyway, the reason that all these vitally needed resources are not
given fixed addresses is that such a mechanism is too inflexible.
Instead, the "namer" server is started, and all future queries and
updates concerning who is using what port number are handled through
this single server.  Like most servers, namer presents a
filesystem-like view of the symbols it maps.  The content of each file
is an ASCII number, which is the port number registered for that
string.  Given the mount table above, where the namer server is under
/namer (and assuming we have sufficient privileges--sys.sys is needed),
we could "register" a number ourselves, simply by:

	cd /namer
	mkdir andy-devs
	cd andy-devs
	cat > dev1
	12345
	^D

In fact, this is how all servers register themselves, although a couple
library routines encapsulate all this tedium.  A server would do something
like:

	port_name n;
	port_t p;
	struct msg m;

	/* Get port, let system choose ID */
	p = msg_port(0, &n);

	/* Offer to the system as fs/root, the boot/default filesystem */
	namer_register("fs/root", n);
	...

	/* Start serving requests as this filesystem */
	while (msg_receive(p, &m) > 0) {
		...
	}

And a client could do:

	port_name n;
	port_t p;
	char buf[128];

	/* Look up fs/root, get its port address */
	n = namer_find("fs/root");

	/* Connect to server, with access for reading */
	p = msg_connect(n, ACC_READ);

	/* Open foobar on this filesystem connection */
	m.m_nseg = 1;
	m.m_buf = "foobar";
	m.m_buflen = strlen(m.m_buf)+1;	/* Include terminating '\0' in cnt */
	m.m_arg = ACC_READ;
	m.m_arg1 = 0;
	m.m_op = FS_OPEN;
	x = msg_send(p, &m);
	if (x > 0) { ... }

Although, frankly, it's much easier to put it in the mount table and
start using it through a more typical POSIX interfaces:

	mountport("/d", p);
	fd = open("/d/foobar", O_READ);
	while (read(fd, buf, sizeof(buf)) > 0) {
		...
	}

There was a subtle difference between the last two examples.  The
former, where we sent FS_OPEN messages ourselves, would walk the actual
connection down to the file which was to be opened.  Thus, the initial
connection would be to the root filesystem, and after a successful
FS_OPEN, the connection would instead correspond to the file "foobar".
In the latter, the mount table holds the open connection to the
server's root, and open() requests do a clone() to get a distinct copy of this
connection, and then walk *it* down to the requested file.  This leaves
the original connection at the root so further uses of the mount point
will work.

Setting up mount tables for yourself is tedious work.  That's why bin/login
will read /vsta/etc/fstab during your login, and put initial entries into
your mount table.  Hopefully, you can read this file, cd over to /namer,
look around, and start to get a feel for the links and interactions which
map names to ports, and organize a "filesystem" view on top of a collection
of open connections to various servers.


==============================================================================
How do capabilities work?
==============================================================================

It's very simple in practice, but difficult to describe.  Let me try
describing it from a POSIX perspective.

Recall that POSIX defines other/group/user, defining your increasingly close
relationship to an object.  In parallel with this, they also define some
bits which describe what you can do to an object based on how close your
relationship is to the object.  For instance, a mode of 0751 on a file owned
by group 9 user ID 11, means that user ID 11 gets all three bits (Read,
Write, Execute), group 9 gets Read/Execute, and others get just Execute.

Now, let's restate the exact same protection system in a different way.
First, the question of "closeness" is simply the question of how far a UID
matches a protection ID.  So if you are (in POSIX-ese) group 9, user ID 11,
then your ID would be:

	9.11

And when you look at a file, it has a protection which might look the same:

	9.11

Finally, in parallel with this file protection you get a matching set of
bits which tells you what to grant:

      1.5.7

Which, matching from the least specific to most, says "other" gets 1
(execute), group 9 gets 5 (read+execute), and user ID 11 gets 7
(read/write/execute).

Now, if you're still in group 9, but your user ID is 12, then your ID:

	9.12

Matches the file's protection ID up to 9, but not through 11 any more.
Thus, of the 1.5.7 bits, you get 1 (everybody does), and 5 (because you
matched through 9).  You don't get 7, because 12 doesn't match 11.

Thus, the VSTa protection scheme is a simple generalization of POSIX's
3-level scheme.  Instead of only allowing group.user, the dotted numbers can
be longer, describing a hierarchical ID space which can be organized as
needed.

Also, all the nasty special cases of group lists, saved UIDs, effective
UIDs, and so forth are mostly subsumed by the generalization that a user
(rather, his processes) can have an arbitrary number of IDs.  Access to an
object is the sum of access gained by each ID held.


==============================================================================
How does VSTa boot?
==============================================================================

This is an overview of the booting process for VSTa.  It covers the booting
process from boot.exe through the login: prompt.

1. Load kernel and server images

    VSTa is booted using a Multiboot-compliant loader.  The loader reads
in not only the kernel, but also any other additional programs you want.
The memory image ends up looking something like this:

| Loader | kernel | cons | keybd | wd | dos | ...
+--------------------------------------------
   0 ->

2. Switch to 32-bit mode

    Multiboot specifies that the loaded kernel is entered in flag
32-bit mode.

3. Initial VSTa instructions

    VSTa has a Multiboot data structure embedded in its low memory.
The loader has filled this in to indicate memory size, location of
the additional programs ("modules", in Multiboot parlance), and other
details of its loaded environment.  A private stack is set, and then
main() is called, which in turn calls a number of initialization routines.

    init_machdep() handles the grotty intial setup of memory.  It uses the
Multiboot-passed parameters, and sets up machine-independent descriptions of
the memory available.  It also scans the images of the boot servers which
were concatentated onto the end of the kernel image, and builds a machine-
independent description of them.  This description will be used soon to
create the initial processes which allow VSTa to boot.

    Finally, init_machdep() sets up its own level 1 and 2 page tables,
and switches to them.  At this point, VSTa is now able to manage its
own virtual memory.  It calls init_trap() to complete machine-dependent
initialization with the initialization of the interrupt system.

4. Further initialization

    init_trap() creates a GDT (and null LDT, as only the GDT is used).
It sets the PC interrupt controller to a mode compatible with protected
mode, and puts together an IDT (interrupt descriptor table).  By default,
each interrupt slot is hooked to a routine which will push the trap ID,
and call the common interrupt code.

    init_trap() then uses a table to override this default action with
calls to more appropriate routines.  For instance, the page fault vector
is rewired to call the page fault handler.  The system call vector is
hooked to the system call handler.

    Next, init_page() and init_malloc() are called to set up the
hardware-independent parts of the VM system.  After these, the general-
purpose memory routines can be used to allocate, free, and map memory.
init_qio() and init_sched() set up the queued I/O facility and the
scheduler.

    init_proc() now takes the list of boot servers found in init_machdep(),
and creates a new process for each server, with its state set to RUN.
After this routine, VSTa has a process for each boot server, with each
server flagged as waiting to run.

    init_msg(), init_swap(), init_wire() all initialize various other
machine-independent parts of the system.  start_clock() enables
the PC clock and also enables interrupts.  From here, the clock will
tick and system time will advance.  main() finishes by calling swtch(),
which will never return.

5. Running

    swtch() enters the scheduler.  The current "process" (which isn't
really, but it's close enough for the scheduler) releases the CPU,
and swtch() hunts for a new process to run.  It finds the first of
the boot servers, switches to its context, and "returns" to user mode
(which will be at the first instruction in the a.out).  VSTa is now
"up", and all further system activity will be handled by VSTa through
the usual services of memory management, message passing, scheduling,
and so forth.


==============================================================================
VM System
==============================================================================

The "root" of the memory system is the "vas" struct, which stands for
Virtual Address Space.  A vas hangs off the proc struct, as do thread
structs.  Thus, a proc has a 1:1 connection to a virtual address space, and
all threads under a proc share the same address space.

A vas is mostly just a place list one or more pviews.  It provides a mutex
(mutual exclusion mechanism) to coordinate changes made to the address
space, and it leaves room for the "hatvas", which is any hardware-specific
state which needs to be kept per address space.

"hat" stands for Hardware Address Translation.  It refers to
processor-dependent virtual memory system functions.

Each pview exists under a single vas, and one or more pviews are linked
together in a list.  Each pview describes a virtual address, and a length.
Thus, its name "Page View".  The sum of all pview's address/length ranges
describes the virtual addresses which are valid in a particular address
space.  The pview also describes protection (read-only, read-write, etc.).
Finally, the pview also points downward to a pset.

A pset is the first level which is not associated with a particular address
space.  In fact, pviews from many different address spaces can point down to
a pset.  The pset describes the state of a set of pages, and thus gets its
name "Page Set".  A pset describes a length but no virtual address; a set of
pages can be mapped at different addresses in different address spaces.  It
describes where initial page contents are accessed (from a server,
zero-filled, copy-on-write) and also maintains an array of per-page
information.

The "perpage" struct holds state for a particular page slot under a pset.
If the slot is valid, it names the physical page number.  It also records
the pviews which currently have a mapping to this page.  The "atl" ("Attach
List") is a linked list data structure which then enumerates each such
pview.  The ability to enumerate mappings of a physical page is required by
the two-handed clock algorithm used to age pages during memory pageout and
reclaim.

Finally, each physical page has a corresponding "struct core" entry.  This
entry records information needed to "wire" a page (keep it from being
reclaimed--needed during DMA access, for instance).  It also provides a back
pointer to the pset which is currently using this page.

The i386-specific portion of the VM data structures is minimal.  The
"hatvas" struct keep both the virtual and physical addresses for the root of
the page tables for a given address space.  It keeps a resource map to
tabulate what addresses are available for dynamic memory.  Finally, purely
as an optimization, it keeps a bitmap to indicate which slots in the root
page table have second level page tables.  This is used to speed cleanup
during exit().

Some brief notes on the mutex design.  The vas has a spinlock which protects
changes to the overall address space.  The pview does not; cases where it
needs to be protected are covered by acquiring the vas's spinlock.  The pset
has a of two mechanisms.  For simple changes like reference count updates it
has a straight spinlock "p_lock".  For changes to some particular position
under the pset, the effect of having a per-slot semaphore (sleeping mutex,
not spin-oriented) is gained using a combination of the pset's p_lockwait
semaphore and two bits in the pp_lock field of the perpage information.
PP_LOCK in this field indicates the the slot is held.  PP_WANT is an
optimization which indicates that on release of PP_LOCK, if PP_WANT is set
then sleepers on p_lockwait in the containing pset will be awaken.

Thus, pageins of multiple positions within a pset can be done in parallel.
Two threads racing to page in a single position will be serialized on the
PP_LOCK of the slot.  Removing a pview from a vas will be protected by the
vas's spinlock.  The fact that multiple threads can be changing a vas (and
structures below) asynchronously adds complications.  For instance, deleting
a pview from a vas requires great care so that threads already active down
in the pset are not hosed when a thread starts removing the pview form the
vas, and tries to tear it down.


==============================================================================
Where is a page transfered on page-out?
==============================================================================

The kernel queues the I/O to the swap server.  The swap server is
potentially connected to a number of underlying physical devices, looks up
the swap block number, finds out which device and which position that block
lives at, and forwards the request.

This allows the swap server to provide dynamic swap creation and deletion,
interleaved swap, and so forth without any of this complex code living in
the kernel.  The kernel just lives in a wonderland of a single swap
partition starting with block 0 and going up to block n-1 (for current swap
size available of n).


==============================================================================
VFS Description
==============================================================================

A file is structured as:

| File header | Extents | Data...

So the stuff UNIX would put in inode is actually just the first N bytes
of a file.  Each extent is merely <start,len> tuples.  The sizes are
chosen carefully, so that a 100-byte file occupies a single 512-byte
sector, including both file data as well as file ownership, protection,
and allocation information.  A directory is just a special file, so
smaller directories will also occupy a single sector.

As a file grows, its existing allocation is extended where possible.  So
if your file is currently {<3,1>} (i.e., sector three, one sector long),
and you write enough data to push out beyond the initial sector, the
filesystem will see how many blocks can be had starting at 4.  Up to 64K
is taken at once, in the hope that taking this much proactively will
spare you having to "piecemeal" your file together as you write.

Thus, your file could then be {<3,129>}.  The file's length is marked to
be the entire length of the whole allocation (129*512 = 66048).  If you
crash, the file thus correctly represents the storage it holds, without
fsck being required before filesystem operation is resumed.

As you write the file, the filesystem keeps track of the highest offset
you have written.  On last close, blocks beyond this point are freed, and
the file is "shrunk" down to the actual size written.  If you wrote
a K or so, then closed the file, the example file would end up as {<3,3>},
and 6..129 would return to the free list.

The free list uses a sorted linked list of free ranges, with coalescing.
Each range is held in a single sector; each sector has a next pointer
to another sector's worth of free list ranges.  A sector can hold 0 or
more entries; if it ever overflows, a global rebalance is done, resulting
in each sector being exactly half full (except the last in the list which
might hold less).  This allows contiguous ranges of free blocks to be easily
identified, and is very storage efficient, even with small allocation
units (such as sectors).  It is also easy to prove that your free list
can always represent the total of free blocks, because a block on the
free list can be consumed to provide another sector's worth of storage
for the free list.  Bitmaps are popular for free block management, but
their size grows as a function of increasing filesystem size and decreasing
allocation unit size.  Most implementations either take a larger allocation
size--say, 8K--and waste disk space for smaller files, or add tremendous
complexity to special-case sub-allocation-size units (i.e., "frags" in
the BSD filesystem).  VSTa is primarily an experimental platform, so I
decided to try something different.

The most complex part of the filesystem is the block cache.  This is
a misnomer; each entry in the buffering system is variably-sized.
For an extent of up to 64K, a buffer of the exact size is kept.  For
larger extents, the extent is buffered in 64K chunks.

Between the contiguous block allocation and the variable-size buffer,
I hope to provide very efficient filesystem services.  Consider a
file with allocation {<10,8>} (i.e., a file starting at sector 10 for 8
sectors--4K).  When this file is opened and read, a 4K buffer is allocated.
A single disk I/O fills the entire 4K.  Thus, most small files will have
their entire contents buffered in a single disk I/O.  Larger files will
have their contents buffered in chunks of 64K.  Once the file contents
are in the filesystem's buffer, it may be parcelled out to clients without
further I/O activity.

This scheme should work well for text files, objects, and some executables.
It will not work well for, say, databases.  They would do better to talk
directly to a disk partition, or through a similar, but non-buffered
version of this filesystem.  My initial prototype will also not protect
itself well against multiple, competing allocation requests.  I hope to
incrementally improve this as I learn more from actual use.

Further notes on how to manipulate filesystems:

To: vsta@cisco.com
Cc: vandys@cisco.com
Subject: vsta fs FAQ entry
Date: Sat, 24 Dec 1994 22:22:43 -0700
From: Gary Shea <shea@xmission.com>

I've been trying to get a working vfs fs.
I spent much of today reading fs & wd code;
on a whim I mounted wd in the root fs and lo
and behold, it had entries in it!  And they
were different than the one in the sample inittab line...
that simplified things lots.

Here's a possible FAQ entry for the next poor fool
who tries this:

Q: How do I make a vstafs filesystem?

A: For DOS 6.2, there are two possible partitions on a disk:
the main one, and a secondary one.  It is possible to create
logical partitions in the secondary partition to subdivide that
partition even further.  To see what partitions you have available,
add a line of the form:
disk/wd /wd
to the /vsta/etc/fstab file and reboot, or use the command
$ mount disk/wd /wd
to accomplish the same effect temporarily.  Look in the
/wd directory for the names of available partitions.
Supposing you wish to use the partition wd0_dos1, use the command
$ stat /wd/wd0_dos1
to find the exact size of the partition.  Divide that number by
512 to get the number of sectors, then the command
$ mkfs_vfs /wd/wd0_dos1 number_of_sectors
will initialize a vstafs file system on that partition.
Now you can run the filesystem server:
$ /vsta/boot/vstafs /wd/wd0_dos1 fs/vfs
Finally, you must map the namer pathname fs/vfs into the
root heirarchy with a mount command:
$ mount fs/vfs /vfs
If you want the filesystem mounted at boot time, find the
vstafs command in the /vsta/etc/inittab and correct it to
your device name (note the different syntax when portnames
are used); uncomment or introduce the necessary mount
line in the /vsta/etc/fstab file.

Added doc/features.txt.

























































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
Features by release:

v1.3.2:

Added TCP/IP networking with KA9Q package.
Added ne2000 ethernet interface server.
Added shared libraries.
Enhanced RS-232 so you can set parity, data bits, and so forth.
Added ps(1) command, via the pstat system call interface.
Added CDROM filesystems.
Converted all servers to use syslog.
Port of "vim" vi clone editor.
Floppy driver now works.
i387 FPU supported by kernel--library support still TBD.

v1.3.3:

/proc filesystem, ps(1) uses this, as does kill(1).
Canonical ("line") input mode has command line editing and history.
Stripped a.out format uses one less block, in general.
Fixed ld(1) bug which broke code living in the last 32 bytes of
	an a.out image.
Add cc(1) compiler, based on lcc compiler.  Fast, simple, lousy
	code generation.
More support of read-only files in dos filesystem.
Greatly improved stat(2) emulation.
Major fixes in permission calculations.  Now works pretty much like
	it was originally described.
Fixed namer to allow logins (actually, access to fs/root entry
	for shlib startup) from other than sys.sys capability.
Performance tweaks for vstafs.
Removed various dead code, added more pstat(2) support for kernel
	config values.
Added $s/$S to adb to allow incremental symbol table loading (so you
	can "$s /vsta/lib/libc.shl" and get shlib symbols).
Allow VM page stealing to be active before swap space is configured.
	Only stealing of unmodified pages is possible, but this can
	still be a help on smaller systems.
Port of "rh" find(1)-like tool using C syntax.
Add ~ and ~user processing for open()

v1.4.0:

Significant work by Dave Hudson on performance.  Also a new malloc()
	which allows fast inline allocation for most common cases.
Source reorganization; a src/ subdirectory now holds the source.  Long
	promised, finally delivered.
New syscall convention using registers
Add "include" directive to make
Organize source and makefiles to support multiple architectures
Added source for 68030 Amiga port
Per-page TLB flushing where available
DOS filesystem performance tweaks
tfork() passes argument now
Lots of new C library functions
/dev/null server now supports an "always full" switch--useful for testing
Added xargs, echo, strings
vstafs: fix up how directories are grown
Cleanup of pset data structure and routines
Cleanup of adb, add :n to step over procedure calls

1.4.1:
Speed up and bug fix event delivery code
Add support for "bt X" in kdb to backtrace an arbitrary thread
Make FDL memory file descriptors work as a FIFO ring
Fix a crash where a connect request is dropped due to server death
Protect against a debugged process clearing its debugger port_t
Networking.  /inet server, telnet daemon, remote console.
A speed/memory tweak for tmpfs; larger single I/O as a side effect
RCS is working (knock on wood)
chmod() maps onto VSTa permissions (was a no-op)
O_CHMOD supported for open() and friends
DOS server permits switching between RO and RW permissions now
Shadow password file
A couple more man pages
VSTa VM page stealing rework.  Actually seems to work! (YMMV :->)
SCSI Tape & autosense support from Mike Larson

1.5:
Fix case where "swapd -n" was still trying to push dirty pages
Add "core" kdb command
Performance: shaved a cycle off the shlib call path, deleted t_qsav
	and reaped a whole setjmp() of writes on each syscall
Kernel preemption
More man pages
Permit I/O interruption w/o server ack for still-queued messages
Add setsid(), and have login move each session to its own signal group
Permit client disconnects w/o server ack; along with I/O interruption,
	this should permit a client to interrupt out and disconnect
	from a moribund server.  It also solves an interesting deadly
	embrace in the exit of a server where a cache MMAP reference
	still exists.
Protect against buggy server operating against non-requesting client
Fix bug in explicit server port closing
Fix bug in fseek() from relative position
Revamp mouse handler
Add port of MGR windowing system

1.5.1:
Bug fixes for kernel preemption
Performance: remove unneeded entries from default namespace
First implementation of ABC, Asynchronous Buffer Cache library
Semaphore server
Kernel-level thread mutexes
More MGR cleanup (less memory, slightly faster)
vFAT entries don't kill DOS server any more
Floating point support
popen/pclose
funopen/fropen/fwopen
Ports of sc, bc, Tiny Smalltalk

1.5.2
vstafs fsck will now repair damage (not just find it)
vstafs now uses ABC
namer entries are cleared when the registering server exits
added "purge" command to clean up old entries in vstafs 
	versioning filesystem.
Prototype of proxyd for doing proxy VSTa messages over TCP/IP
A couple really painful MGR bugs fixed; it's now usable
Taught various commands about window sizing (ls, editors, less, termcap)
ar won't croak vstafs (edge case, renaming on top of active file)

1.6
Conversion to gcc 2.x.  Now requires an FPU to use gcc, sorry!
Port of gdb using a.out stabs.  Symbolic source debugging (both
	under gdb as well as dynamic attach) works.
Emulations of environ[], sys_errlist[], and sys_nerr.
Stubs for setrlimit stuff.
Proxy functions over KA9Q TCP/IP now working.
Ports of GNU awk, bison, flex, make, text utils, file utils.
VSTa is Multiboot compliant; boots from GRUB loader.  Boot from under
	DOS is no longer used.

1.6.1
Fix KA9Q so it doesn't lock up on "real" network interfaces.
Add packet buffering to srv/mach/ne.  TCP/IP is now actually
	usable.
Convert srv/dos to getopt().
Add -B flag to dos and vstafs to set buffer cache size.
Fix PATH inheritance bug in /bin/sh; shell scripts could otherwise
	fail pathname lookup for their commands.
Fix bug in environ[] emulation; garbage chars at end of some strings.
Help for kernel debugger.
PID's now start at 1 so even the first process can be notify()'ed.
Enable SIGINTR/SIGQUIT generation from console keyboard.  Fix login
	to mark process group to TTY, and TTY mode handling to permit
	updating of the TTY input signal state.  Said signals are
	generated with the assumed identity of the client who set
	the process group.
Add -k to rs232 server so it's easy to control whether ^Z puts you
	into the kernel debugger.

1.6.2
Add rcsdo/changed, my tools for working with RCS trees.
Fix docs on rawrite'ing, also more spots missed in the great
	filesystem server command line change fiasco.
Update sample boot/menu.lst to reflect file server command line syntax.
On usage() errors, have DOS and vstafs put out a message to syslog
	as well as stderr (which, DOS being a boot server, isn't active).
Fixed memory leak in ethernet driver
Added memory leak instrumentation to libc malloc.c
Added standard filesystem switch support to all filesystems
KA9Q and proxyd now work for open/close/read/write/stat.  So distributed
	kernel messaging is now working.  Mount remote filesystems.
	Even /proc!  Kill remote processes!  Wheee!
Implement support for ISA bus limitation "bounce buffers".
Use bounce buffers in our two ISA DMA drivers--SCSI and floppy disk.
Fix a nasty race condition in vstafs.

1.6.3
FAT-32 support.
Fix race condition in parallel threads faulting same vaddr.
Fix bug in execvp which would sometimes hose the last argument
M_TIME is gone.  RIP.
Add select() emulation.  select() is supported by ka9q/networking,
	MGR terminals, and the console(s).
Fix bug in grep(1), which used the wrong value of O_RDONLY.
Fix crash when fork()'ing while another thread is blocked in
	a msg_connect attempt.
Fix hang when quitting MGR (had to hit a key on the terminal to
	actually let it exit).
MGR's $HOME/mgr.rc file now works... example in /vsta/guest.
Port of ctags.
Cleaned up MGR's "resetwin" command.
Implemented ephemeral threads to support alarm(), SIGCHLD, ABC, etc.
	See sched_op().
Implemented ANSI C atexit().
Low-level VSTa event handler API, handle_event() from <event.h>
Fix crash when m_to_sm() fails, but a segment cleanup is attempted anyway.
DOS now maps ".<file>" to "_<file".  Renamed sh.profile to _shrc,
	rh.rc to _rhrc, mgr.rc to _mgrrc.  _exrc for vim remains the same.
Re-org of makefile structure; creation of global makefile.all.
Move a bunch of binary ports to a new vsta/src/bin/ports subdir.
Create a vsta/src/include, which holds the RCS-managed versions.
	The "make install" phase copies header files to their
	place in vsta/include.
POSIX signal emulation.  This is all the signal set handling stuff
	beyond the basic signal() API (which has existed for a while).
User and system CPU times of getrusage() are now filled in.
clock_t and clock() are now supported.
A <linux.h> has some stuff useful for porting Linux programs.
testsh wouldn't wait and retry to connect with the console.  In some
	scenarios, this would put it in an endless silent tight loop.
Added a fionread() to <fcntl.h> to provide the ioctl FIONREAD function.
Ported zmodem rz/sz.  Not working exactly right just yet....
Ported svgalib and jpeg6b.  Got some of the svgalib demo apps working.
Ported PD m4 from FreeBSD.
Ported the 8-bit color driver from mgr-0.69 into the VSTa MGR port.
	Adapted it to use svgalib.  Got high res working with MGR.
Added BSD's err/warn API's.
Added true/false/whoami commands.

1.6.4
Added -o to MGR's "startup" command.  Lets output be written to the
	named file.
Added VFAT (long filename) support to DOS filesystem.
Ported Plan 9's nroff/troff.
Generalized system shared library support; converted libm,
	libregex, and libtermcap.
Allow dumping of ranges of sectors in dumpsect.
Accomodate various flavors of RCS directory names for rcsdo.  Save quite a few
	cycles in its operation.
Port of PDP-11 emulator; runs V7 UNIX under VSTa!
Avoid gcc lame inline support; -O isn't needed any more to correctly get
	an inline compilation of getc/putc.
Auto-flush stdout when read from an interactive stdin happens.
Conversion of man pages to nroff -man format.
Ported BSD's "units" command.
vstafs, file/dir creation inherits protection of parent dir.
less's help ('H' command) fixed.

1.6.5
Added a little flexibility in use of MAP_FIXED.
Port of GNU Smalltalk.
Added realpath(), gettimeofday().
Added prototype for rename() to <stdio.h>.
Added rmap_grab() to the <rmap.h> library routines.
Fixed long-standing edge case bug when resource map is too fragmented.
Added alias remove() mapping to unlink().
Added two new partition types to disk partition support.
Added "xkeys" stat -w message to console server, so you can disable
	F<n> and arrow key escape sequence generation (if you want).
	Default is they still generate their escape sequences.
	(But I hate'em, so my personal config has them shut off!)
Fix memory leak in selfs server.
Fix "make distribution" to include new DLL's in distribution.  This
	manifested itself as any of your -ltermcap type programs dying
	when you tried to run them.  Sorry!
Implement inbuf/outbuf counts for console.  fionread() now works there.
Always let owner (UID) to chown operations on vstafs.  Otherwise you
	can paint yourself into a corner, where you remove all abilities
	of all users to touch the file!
Fix some more long-filename compilation errors.
Have DLL loader ld.shl try the truncated 8.3 filename in addition to
	the full DLL name.  This helps when the VSTa distribution was
	loaded via a utility which only supports 8.3 filenames.

1.6.6
Added FS_BLK{READ,WRITE} operations to support true sector-oriented
	I/O.  Offsets and counts are in units of 512-byte sectors, and
	thus the 4 gigabyte offset limit of byte-oriented I/O is
	avoided.  vsta/src/lib/abc.c uses this, and falls back to
	the old I/O primitives if it finds these not supported.
	For now, IDE supports it.
Filename completion is available in the shell.  TBD... right now it's
	a separate plug-in from libusr.a; should it be made a part of
	getline()?  When should it be active versus the regular tab
	expansion function?
TTY state (vsta/src/lib/tty.c) is now per-TTY.
Added "dev" FS_STAT parameter to the console server, also fixed a bug
	where interrupts didn't clear typeahead.
Fixed shift key rollover--if you hold one shift, then the other,
	then release the first, you'll still be shifted until you
	release the final key.
Converted current regexp package to use libregexp.a (note the new 'p').
	This is made possible by long filenames in VFAT, and makes
	room for...
Ported POSIX libregex.a package.
Ported BSD's expr.
Added lots more details on how to implement select() in a server.
	See /vsta/doc/select.txt
RS-232 server now supports select().
Fix output positioning so things like "make > make.log" now give you
	usable output.  Fixed some latent race conditions in port
	duplication messaging.
Made the shell use wait.h macros; non-zero exits don't get listed
	as signal terminations now.
Shell doesn't hang on pipe when doing some types of here documents.
Add some options to kill, and convert to getopt().
Create aliases for awk (=gawk), egrep/fgrep (=grep), [ (=test).
	We still have cc (=gcc).
hostname emulated in shell script using uname.
Fix long-standing latent bug in "fstab" with no arguments.
Ported vim-5.7... multiple edit buffers, filename completion,
	lotsa good stuff.  The new one is more than 3x the size
	of the old one, though, so I'm going to keep the old
	one available for now as "ovim".
access for W_OK doesn't change the file's mtime any more.
Since the output positioning fix spares us needing to do clone()
	operations on each fork(), I've decided to live it up and
	have /vsta/bin mounted as /bin as a standard configuration.
	This means standard shell scripts which start with #!/bin/sh
	will now work, too.
Ported file utility.
Fixed up libgcc.a so it holds all the functions needed for floats,
	doubles, and long longs.
Port of dosfsck... native filesystem checking of DOS filesystems
Fix DLL loader so short filename conversion always works (missing
	null termination)
Fix MGR's startup so it gives a clear message and exits when it can't
	attach to the mouse.

1.6.7
Ported unzip
Fixed output corruption problem in fmt(1)
Fixed race condition in aborting a kernel read request which completes just
	as you abort it.  Could leave the server hanging.
Fixed edge condition in signal generation from mach/cons2 which
	could keep future select() clients from working.
Fixed subtle bug where using the kernel debugger and then continuing
	could corrupt the first page of console server code.
Tweak kernel capability handling so that the default process label
	isn't ever changed to reflect a "root" capability (which, being
	zero-length, isn't a good label to use for ownership).
3c509 network driver added
KA9Q networking generic ether driver now takes driver path as argument
Tightened up some TLB treatment in the page allocator and
	debug memory examination code.
Fix edge condition where large reads from /tmp would complete with a
	short count--many apps interpret this as EOF, instead of reading
	further data.  tmpfs will now always return the full read request
	(assuming the data's there!).
Ported GNU chess 5.00
Added basic CPU profiling support--see vsta/src/lib/mcount.c.
Alias view->vi (for read-only viewing via vim)
Fix annoying behavior where some program exceptions either don't
	get caught by the debugger ("process exited normally") or
	the stack frame doesn't include the failing routine.
Fix environment variable inheritance between processes; in some cases,
	you wouldn't get variables you expected.  In others, variables
	would hang around in places which were not expected.
Nice facelift to "ls" courtesy of Erik Dalen.
Erik also contributed some section 1 man pages.
A port of Tim Budd's latest/greatest "Tiny Smalltalk".  Actually, this was
	 total revamp of his design, but he stopped working on it before
	 it was really shaken out.  Check the RCS logs to get an idea of
	 what I fixed. :->  The result is a pretty nice little language
	 environment.
Have fputc() honor unbuffered flag in IOB.  Fixes problem where things
	like fprintf to stderr or perror would misplace a trailing newline.
ash missing from "shells" package due to pathname mismatch... fixed.

1.6.8
Port CVS.  Found a bug in CVS. :->
Convert main source repository to CVS.
Fix regoff_t type to be a signed quantity... fixes bug in expr(1)
	where it would not correctly indicate match length
	in its colon operator.
Convert kernel build to use vsta/src/makefile.all.
Retool boot and doc subdirs to use "make install".
Add support for "a" mode of fopen() (I thought I had already done this...).
Make sscanf() family of API's declare their input string buffer "const".
More performance tuning on "ls", also do alpha sort on -l format.
Construct font/hfont/icon directories in MGR from latest MGR distro...
	these contents were munged by the old DOS 8.3 filenaming lossage.
With long filename support, ".foo" is now a legal filename, so remove
	the .foo -> _foo mapping hack from the DOS filesystem.
libmgr.a and libbitblit.a are moved under /vsta/mgr/lib.
Fix bug in KA9Q's generic ethernet driver... port_t versus file
	descriptor mixup.
vim.old removed.
Added some section 6 and section 3 man page entries.
Fix name length bug in RCS.
select() support for the mouse driver.
fd_rstat() added to permit access to rstat() stat strings via
	file descriptor.
Pseudo-TTY support via vsta/src/srv/pty server.
Various bugs fixed in select(), especially with respect to reads
	which do not consume all available data, and how this
	is reflected in a subsequent select() for readability.
Fix day-one bug in handling of file descriptors under execv[p]().
	Also related bug in setup of FD's in init.
stat(1) has some special syntax added so you can stat raw file
	descriptors or ports open within the stat(1) process.
	Probably not generally useful, but I needed this to debug
	the problem with file descriptors listed right above this
	entry.
Missing file for DOS fsck code.
Convert to vt100 as system terminal type.  Emulate quite a bit more
	of vt100 behavior.
Fix onlcr emulation (which was kinda sorta working for RS-232, but not
	otherwise used.  Now it's pretty much fixed, and used by console
	as well).
Add "reset" wstat message to reset console state.
ascii(1) command because I can never remember my ASCII table.
Port of teco(1) to VSTa.
A sample RAM disk server is available in the new vsta_contrib archive.
vsta/etc and vsta/lib text files put under source control (duh,
	should have happened a long time ago).
Port of old rolodex(1) utility.
"offset" field of mmap() for MAP_PHYS now lets you specify an attached
	virtual address.
Quietly cap memory at 768 megs, to avoid limits in our 1:1 mapping
	area in kernel virtual address space.
Port of ARC 5.2.1 (old PC/DOS archive format).
File preallocation in FAT-32 (see wstat contig= command).
Add dirname(1).
Fix segv in usage message of purge(1).
Support scanf family %n format for # chars read.
All /bin shell programs under source control in vsta/src/bin/cmds.
Added some symbol/string utilities in <symbol.h>.
A small stty(1) emulation.

Added doc/man/1/fstab.1.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
.TH "FSTAB" "1" "" "Dave Hudson" "Commands"
.SH "NAME"
fstab \- read the current mount table
.SH "SYNTAX"
fstab [\fIoption\fP][\-f | \-p]
.SH "DESCRIPTION"
Utility to read the current mount table.
Based on an idea from Andy Valencia's testsh builtin command "fstab".
.SH "OPTIONS"
.LP 
.TP 
\fB\-f\fR
List the mounted ports by file descriptor.
.TP 
\fB\-p\fR
List the mounted ports by "portname" number.
.SH "AUTHORS"
Dave Hudson <dave@humbug.demon.co.uk>
.SH "SEE ALSO"
.BR mount(1)

Added doc/man/1/kill.1.











































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH "KILL" "1" "" "" "Commands"
.SH "NAME"
kill \- kill processes
.SH "SYNTAX"
kill [\fI-e <event>\fR] [\fI-p <pid>\fR] [\fI-t <tid>\fR] [\fI-g\fR] [\fIPIDs...\fR]
.SH "DESCRIPTION"
\fBkill\fR is used to send events to processes and groups of processes.
.SH "OPTIONS"
.TP
\fB-e <event>\fR
The named event string (default: "kill") will be used as the
event to deliver.
.TP 
\fB\-g\fR
The signal is sent to the process group to which the given
PID belongs.
.TP
\fB-p <pid>\fR
The named process ID is the target.  The currently specified
event (either the default "kill" or a preceding \fI-e\fP
switch) is delivered to the process.  If a preceding \fI-t\fP
switch is active, only the specified thread within this
process is affected.
.TP
\fB-t <tid>\fR
A specific thread within the process (whose ID is specified
by a subsequent \fB-p\fR argument) is the target of the signal.
Without this, sending a signal to a PID will result in the
signal being delivered to each thread within that process.
.TP
\fB<pid>\fR
After the switches, further arguments are taken as process
ID's, and are treated each as if a \fB-p\fR switch had
been placed before them.
.LP 
.SH "SEE ALSO"
.BR ps(1)

Added doc/man/1/mv.1.

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.TH "MV" "1" "" "" "Commands"
.SH "NAME"
mv \- move files
.SH "SYNTAX"
mv \fIsrc\fR [\fIsrc\fR ...] \fIdest\fR
.SH "DESCRIPTION"
The mv command moves single or several files or directories from one location to another. If a single file or directory is moved and the last element of the destination isn't a directory, it is moved and renamed to that. So mv can be used to rename files.
.SH "EXAMPLES"
mv foo.c bar/ \- will move the file foo.c into the bar directory
.PP 
mv foo.c foo.h bar/ \- will move the files foo.c and foo.h into the bar directory
.PP 
mv foo.c bar.c \- this will rename foo.c to bar.c
.SH "SEE ALSO"
.BR cp(1),
.BR rm(1)

Added doc/man/1/ps.1.































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH "PS" "1" "" "" "Commands"
.SH "NAME"
ps \- list processes
.SH "SYNTAX"
ps
.SH "DESCRIPTION"
ps gives a snapshot of the current processes.
.LP 
The different columns are:
.TP 
PID:
The process ID of the process.
.TP 
CMD:
Command name of the process.
.TP 
STATE:
Either SLP, ONPROC or RUN. SLP means the process is sleeping,
ONPROC means it has threads on a CPU and RUN means it has runnable threads.
If a process has multiple threads, the state will be ONPROC if any of the
threads is on a CPU, otherwise RUN if any of the threads is waiting to
run on a CPU.
.TP 
NTHREAD:
Number of threads under process
.TP 
USR/SYS:
The first value is the total CPU time used in user mode. Then after the / is the total CPU time used in kernel.
.TP 
ID:
The ID the process is running as.

Added doc/man/1/pwd.1.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
.TH PWD 1
.SH NAME
pwd \- print the current working directory
.SH SYNOPSIS
pwd
.SH DESCRIPTION
Print the full filename of the current working directory.

Added doc/man/2/clone.2.





























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH CLONE 2
.SH NAME
clone \- create new distinct client connection copied from old
.SH SYNOPSIS
.B #include <sys/syscall.h>
.br
.B int clone(port_t port);
.SH DESCRIPTION
.I clone()
creates a new connection to the server currently serving
.I port.
After a successful
.I clone,
the client will have a new connection, whose initial
file position, access rights, etcetera, reflect those of
the original
.I port.
However, future changes to position and such will be unique
to each
.I port_t,
as no connection exists after the completion of the
.I clone.
.SH NOTES
The
.I clone()
system call resembles much more the POSIX treatment
of file descriptors in a
.I fork()
than the semantics of a POSIX
.I dup().

Added doc/man/2/enable_dma.2.































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH ENABLE_DMA 2
.SH NAME
enable_dma \- enable DMA abilities for current process
.SH SYNOPSIS
.B #include <sys/syscall.h>
.br
.B int enable_dma(int channel);
.SH DESCRIPTION
The
.I enable_dma()
system call
changes the behavior of the kernel to permit a server
to operate in a DMA mode.  In particular, the process
is permitted to use the
.I page_wire()
and
.I page_release()
system calls, and messages received using
.I msg_receive()
are mapped into a DMA server's address space
as writable pages, thus permitting programmed I/O
directly into a client's memory.
.SH NOTES
This call is generally useful only to DMA-based I/O servers,
although certain transaction-oriented direct I/O filesystems
might benefit.
.PP
The argument is the DMA channel to be used by a hardware
DMA server.  On architectures where there is no concept of
DMA channels, it may be passed as 0.  On the x86, this argument
is currently unused.

Added doc/man/2/enable_io.2.































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.TH ENABLE_IO 2
.SH NAME
enable_io \- (i386) enable access to I/O space
.SH SYNOPSIS
.B #include <sys/syscall.h>
.br
.B int enable_io(int low, int high);
.SH DESCRIPTION
The
.I enable_io()
system call enables access for a thread to use the i386 architecture
I/O instructions.  The process must have
.I sys
privileges.  Once granted, privileges remain for the life of the
thread.  Successive calls are cumulative.

Added doc/man/2/enable_isr.2.































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH ENABLE_ISR 2
.SH NAME
enable_isr \- (i386) connect an interrupt vector to a port
.SH SYNOPSIS
.B #include <sys/syscall.h>
.br
.B int enable_isr(port_t port, int irq);
.SH DESCRIPTION
The
.I enable_isr()
system call connects an interrupt level to the specified
port.  After this call, the
.I port
is no longer available to the process, although it remains open
to the corresponding server.  An occurence of an interrupt at
.I irq
level will send an
.I M_ISR.
message to the server.
If this message is not yet received by the server, the
.I m_arg1
field will be incremented by one instead.  Thus, at
most only one
message for the given
.I irq
will ever exist.
.PP
The process must have
.I sys
privileges.  Once granted, the IRQ handling remains until
the server closes the connection.

Added doc/man/2/exit.2.

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.TH EXIT 2
.SH NAME
exit \- terminate current thread
.SH SYNOPSIS
.B #include <std.h>
.br
.B int exit(int status);
.SH DESCRIPTION
The
.I exit()
system call causes the current thread to terminate.
If it is the last thread in the given process, the
process itself terminates.  Process termination generally
results in a status structure being queued to a
parent process; see
.I waits(2).

Added doc/man/2/fork.2.





























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH FORK 2
.SH NAME
fork \- create new process
.SH SYNOPSIS
.B #include <std.h>
.br
.B pid_t fork(void);
.SH DESCRIPTION
The
.I fork()
system call creates a new process, whose initial open
files and virtual address space are a copy of
.I fork()'s
calling process.  It is the single mechanism for creating a
new process under VSTa.
.PP
On return,
.I fork()
returns 0 in the child process, the child's PID in
the parent process, or -1 in the parent process
if the child could not be created.
.PP
It is legal to call
.I fork()
while more than one thread exists under the current
process.  Only a single thread, starting at the address
of the thread which invoked
.I fork(),
will exist in the new
process.

Added doc/man/2/mmap.2.





































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH MMAP 2
.SH NAME
mmap \- manipulate process virtual address space
.SH SYNOPSIS
.B #include <sys/mman.h>
.br
.B int mmap(void *vaddr, ulong len, int prot, int flags, int fd, ulong offset);
.SH DESCRIPTION
The
.I mmap()
system call manipulates the address space of a process.  In general,
.I len
bytes of mapped space is created, and is mapped in at the
specified
.I vaddr.
The
.I vaddr
can be (void *)0, and the OS will choose an address.
.I MAP_FIXED,
specified below, also affects address assignment.
.PP
The protection of the mapped space is controlled by
the
.I prot
parameters, with the following bits defined:
.RS
.nf
.B #define PROT_EXEC (0x01)
.B #define PROT_READ (0x02)
.B #define PROT_WRITE (0x04)
.fi
.RE
.PP
.I flags
controls the contents of the memory space created by
.I mmap(),
and may contain the following options:
.RS
.nf
.B #define MAP_ANON (0x01)
.B #define MAP_FILE (0x02)
.B #define MAP_FIXED (0x04)
.B #define MAP_PRIVATE (0x08)
.B #define MAP_SHARED (0x10)
.B #define MAP_PHYS (0x20)
.fi
.RE
.PP
.I MAP_ANON
specifies "anonymous" memory; this is memory which is filled on
demand with an initial contents of zero.
.PP
.I MAP_FILE
creates memory whose contents is initially filled from the
file specified by the
.I fd
parameter.  The contents is filled from
.I offset
bytes into the file.
.PP
.I MAP_FIXED
requires that the new memory object be mapped exactly at the
address specified by
.I vaddr;
otherwise, the request fails.
.PP
.I MAP_PRIVATE
creates a memory objects in which any changes to the initial
contents are not reflected in the object as viewed in any
other address space.
.PP
.I MAP_SHARED
is the opposite of
.I MAP_PRIVATE;
this option is not supported for writable memory segments in VSTa.
.PP
.I MAP_PHYS
creates a view into physical memory; it is generally used
by device drivers.  In this case,
.I vaddr
is instead the physical address to map.  The attached memory
is always mapped in at an OS-chosen address.

Added doc/man/2/msg_accept.2.















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
.TH MSG_ACCEPT 2
.SH NAME
msg_accept \- accept a connection from a client
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_accept(long handle);
.SH DESCRIPTION
The
.I msg_accept()
system service is used by a server to accept an
incoming connection from a client.  After this call,
the client will be able to exchange messages with
the server.
.PP
.I handle
is the value passed in
.I m_sender
field of the
.B MSG_CONNECT
message received by the server on its port
using
.I msg_receive().

Added doc/man/2/msg_connect.2.

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH MSG_CONNECT 2
.SH NAME
msg_connect \- connect to server
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_connect(port_name pn, int mode);
.SH DESCRIPTION
The
.I msg_connect()
system service connects a client to a server.
.I pn
specifies the server which passed this value
in its call to
.I msg_port().
.PP
.I mode
is passed to the server, and specifies the type
of access requested.  By convention, these bits
are defined in
.B <sys/fs.h>
and include:
.RS
.nf
.B ACC_READ     - Read access
.B ACC_WRITE    - Write access
.B ACC_EXEC     - Execute
.B ACC_CREATE   - Create/truncate
.B ACC_DIR      - Access directory
.B ACC_CHMOD    - Allow changes of mode and ownership
.fi
.RE
.PP
A connection attempt is synchronous; this call will not return
until the server has received the call, processed it, and
responded with either a
.I msg_accept(), msg_err(),
or terminated due to an explicit
.I exit()
or an unhandled event.

Added doc/man/2/msg_disconnect.2.







































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
.TH MSG_DISCONNECT 2
.SH NAME
msg_disconnect \- disconnect a port
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_disconnect(port_t port);
.SH DESCRIPTION
.I msg_disconnect()
causes a port to close.  When applied to a server's port, each client
will receive an I/O error on their next attempt to use the port.  If the
client already has an I/O outstanding, it will be completed in error
immediately.
.PP
When used by a client, a
.B M_DISCONNECT
message is queued to the server.  The server may clean up any
data structures, but does not need to reply.  The client has already
been disassociated from the port.

Added doc/man/2/msg_err.2.

















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.TH MSG_ERR 2
.SH NAME
msg_err \- send back an error
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_err(long sender, char *errstring);
.SH DESCRIPTION
.I msg_err()
is used to return an error from a server to a client.  Most
commonly, it is used to reply with error to a request
received via
.I msg_receive().
The client sees his
.I msg_send()
return a -1, and can access the
.I errstring
by calling
.I strerror().
.PP
The client's connection remains functional, and a new
request can be sent via a new
.I msg_send()
call.

Added doc/man/2/msg_port.2.















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
.TH MSG_PORT 2
.SH NAME
msg_port \- create a server port
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_port(port_name pn, port_name *pnp);
.SH DESCRIPTION
The
.I msg_port()
system service creates a new server port.  The
.I pn
parameter provides a system-wide name for the port, and
is passed to
.I msg_connect()
in clients wishing to connect to this server port.
It is an error to use a
.I pn
value already in use on the system.
If zero, a value is picked by the kernel.
.I pnp,
if non-NULL, will be assigned the port name assigned
to the new port.

Added doc/man/2/msg_portname.2.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.TH MSG_PORTNAME 2
.SH NAME
msg_portname \- get name associated with port
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B port_name msg_port(port_t p);
.SH DESCRIPTION
The
.I msg_portname()
system service returns the
.I port_name
associated with an open port, suitable for use in
a later call to
.I msg_connect().
It is most often used to find out if two open files
reside on the same "filesystem", that is, under
the same server.

Added doc/man/2/msg_receive.2.

























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH MSG_RECEIVE 2
.SH NAME
msg_receive \- receive messages on a server port
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_receive(port_t port, struct msg *msg);
.SH DESCRIPTION
.I msg_receive()
is used by a server to receive messages on a server's
port.  The received message may be either a regular
data message from one of the server's current clients,
or a system-generated notification of certain
exceptional events.  Messages with an
.I m_type
field below
.B M_RESVD
are guaranteed to be kernel-generated; they can not be spoofed.
.PP
Each message may contain one or more segments of data in a
scatter/gather format.  The field
.I m_nseg
indicates how many such segments were received; the actual
segments are described by the
.I m_seg[]
array of pointer/length structures.
.PP
The field
.I m_sender
indicates which client sent this message; in the case of an
.B M_CONNECT
message, it indicates the handle of the would-be connecter.  This
handle will be valid if the server
.I msg_accept()
's
the connection.
.PP
The fields
.I m_arg
and
.I m_arg1
are specified by the sender.  By convention,
.I m_arg
holds the number of bytes requested or sent in normal data
messages.
.PP
In the case of normal data messages, the request is completed
and a reply sent back by using
.I msg_reply().
.PP
Special messages (
.I m_op
less than
.B M_RESVD
)
are:
.RS
.B M_CONNECT
.br
A client has attempted connection with
.I msg_connect().
.I m_arg
holds the requested mode(s),
.I m_nseg
is always set to 1, and the segment holds an array
of
.I struct perm
elements, describing the abilities of the client.  Because
this is a kernel-generated message, the client may not spoof
it, and the permissions so described may be trusted by the
server.  This message must be completed by either a
.I msg_accept()
call (to accept the client) or a
.I msg_err()
call to reject the connection.
.PP
.bd 1
M_DISCONNECT
.br
This message indicates that a client has terminated, either
explicitly or due to an unhandled event.  The
.I m_sender
field identifies the client, who is no longer connected to
the server.
.PP
.B M_DUP
.br
This message is something of a misnomer.  A POSIX
.I dup()
causes two file descriptors to refer to the same connection; in contrast,
the
.B M_DUP
message causes the server to allocate a new distinct session, whose
state (i.e., file position, etc.) starts as a copy of the original
connection's, but is distinct.  It is caused by the
.I clone()
system call, as well as a part of the
.I fork()
operation.
.PP
.B M_ABORT
.br
When a pending operation is interrupted (i.e., a message
has been sent via
.I msg_send()
but a response has not yet been received, and the requesting
process receives an event), the kernel causes this message to
appear at the server.  It is expected that the server will
clear any state, and use a
.I msg_reply()
to indicate that it has reset the per-client state to a point
where the client may send a new request.
.PP
.B M_ISR
.br
This message is generated by the kernel for servers which have
registered for hardware interrupts.  The kernel clears the hardware
interrupt, and then queues this message for the server.  No
reply is needed for this message, which will never contain any
segments of data.  The
.I m_arg
field holds a count of the number of interrupts which have been
received since the message was queued, but before it was received.
.RE

Added doc/man/2/msg_reply.2.





























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH MSG_REPLY 2
.SH NAME
msg_reply \- answer a message
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_reply(long sender, struct msg *msg);
.SH DESCRIPTION
.I msg_reply()
is used by a server to answer a request made by a
client using
.I msg_send(),
and received in this server via
.I msg_receive().
.I sender
should be the value taken from the
.I m_sender
field of the received message.  Like
.I msg_send(),
a message with optional segments may be sent back.  Note
that if the client did not specify
.B M_READ,
the segments will be verified, but not actually transferred.
.I m_arg
should be the number of bytes in the reply.
.PP
The client is blocked until this reply is sent.  Thus, servers providing
access to "slow" I/O (keyboards, RS-232) will often record the
.I m_sender
field, and delay the sending of a reply for extended periods of time.

Added doc/man/2/msg_send.2.

























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH MSG_SEND 2
.SH NAME
msg_send \- send messages to a server's port
.SH SYNOPSIS
.B #include <sys/msg.h>
.br
.B int msg_send(port_t port, struct msg *msg);
.SH DESCRIPTION
.I msg_send()
queues a message containing zero or more message buffers to
the server connected to
.I port,
which must have previously been opened by a successful
call to
.I msg_connect().
By convention, the
.I m_arg
field of the
.I msg
contains the number of bytes contained in the message.
.I m_nseg
specifies how many segments of memory are being sent.  The
actual segments are filled into the
.I m_seg[]
array.
.PP
.I msg_send()
blocks until the server has received the message and
completed it via
.I msg_reply(), msg_err(),
or by terminating.
.PP
The treatment of the described segments of memory is determined by
the
.B M_READ
bit in the
.I m_op
field of the message.  If this bit is clear, the requested operation
is to send the described memory to the server.  If set, the server
does not receive the memory, and the server's reply will be filled
into the message segments.
.PP
The return value will either be -1, indicating an error, or the
number of bytes transferred.

Added doc/man/2/munmap.2.































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.TH MUNMAP 2
.SH NAME
munmap \- remove object from process address space
.SH SYNOPSIS
.B #include <sys/mman.h>
.br
.B int munmap(void *vaddr, ulong len);
.SH DESCRIPTION
.I munmap()
removes an object previously attached via
.I mmap().
The entire object existing at
.I vaddr
is removed; it is not possible to invalidate individual pages
of an address space object.

Added doc/man/2/notify.2.

































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH NOTIFY 2
.SH NAME
notify \- send VSTa event string to a target process or thread
.SH SYNOPSIS
.B #include <sys/syscall.h>
.B #include <sys/param.h>
.br
.B int notify(pid_t pid, pid_t thread, char *err);
.SH DESCRIPTION
.I notify()
delivers a VSTa event to the indicated target.  If
.I pid
is 0, the current process is affected.  If
.I thread
is 0, all threads in the target process are affected.
Finally, if
.I thread
is -1, all processes associated with the given
process group are affected.
.PP
The string specified, which can be up to EVLEN characters
in length, is sent to each target.  If the process has
an event handler, it will be invoked; see
.I notify_handler().
Otherwise, the target will terminate.  The unique string "kill"
can not be caught; it always causes termination.
.SH NOTES
The
.I notify()
system call wrapper actually counts up the length of
the event string, and passes this count in to the actual
kernel interface.

Added doc/man/2/page_release.2.



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.TH PAGE_RELEASE 2
.SH NAME
page_release \- unlock wired memory
.SH SYNOPSIS
.B #include <sys/syscall.h>
.br
.B int page_release(uint handle);
.SH DESCRIPTION
The
.I page_release()
system call
unlocks memory previously locked down by
.I page_wire().
The
.I handle
is the return value from such a previous call;
the corresponding page is made available for paging.

Added doc/man/2/page_wire.2.













































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
.TH PAGE_WIRE 2
.SH NAME
page_wire \- lock down pages to physical memory
.SH SYNOPSIS
.B #include <sys/syscall.h>
.br
.B int page_wire(void *vaddr, void **paddr);
.SH DESCRIPTION
The
.I page_wire()
system call
locks a virtual page's contents down to a physical page,
whose corresponding physical address is placed in the location
pointed to by
.I paddr.
.PP
The return value is either -1, indicating failure, or a
.I handle
used in a later call to
.I page_release().
.SH NOTES
This call is generally useful only to DMA-based I/O servers.

Added doc/man/2/strerror.2.

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.TH STRERROR 2
.SH NAME
strerror \- return VSTa error string
.SH SYNOPSIS
.B #include <sys/syscall.h>
.br
.B int strerror(char *err);
.SH DESCRIPTION
.I strerror()
returns the VSTa error strong associated with the most recent
failing system call.
.SH NOTES
.I strerror()
undertakes some magic before invoking the kernel interface
so that errors generated from C library functions will
also appear to be "kernel" errors.

Added doc/man/2/tfork.2.



























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH TFORK 2
.SH NAME
tfork \- create new thread under current process
.SH SYNOPSIS
.B #include <std.h>
.br
.B pid_t tfork(voidfun startfun, ulong arg);
.SH DESCRIPTION
.I tfork()
creates a new thread running under the current process.
A thread, unlike a process, shares the address space, permissions,
and open files with all other threads of the current process.
.PP
A thread starts running at the function pointed to by the
.I startfun
argument to
.I tfork();
this function is entered with the single argument
.I arg
available.  This function should not return to its "caller";
.I exit(2)
should be used when the thread wishes to complete.
.PP
.I tfork()'s
return value is the thread
process ID of the new thread.  Note that a thread process
ID is local to the PID of the containing process; see
.I notify(2)
for an example of selecting a thread within a process.

Added doc/man/2/waits.2.























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH WAITS 2
.SH NAME
waits \- retrieve status on exiting processes
.SH SYNOPSIS
.nf
.B #include <sys/wait.h>
.B int exit(struct exitst *w, int block_ok);
.PP
struct exitst {
	pid_t e_pid;		/* PID of exit() */
	int e_code;		/* Argument to exit() */
	ulong e_usr, e_sys;	/* CPU time in user and sys */
	struct exitst *e_next;	/* Next in list */
	char e_event[ERRLEN];	/* Name of event if killed */
};
.fi
.SH DESCRIPTION
.I waits()
retrieves status on children processes of the current
process.  Such status is queued during the process of
a child exiting, and includes information on PID,
any argument to
.I exit(),
CPU time used, and the name of the event which caused
process terminating (if any).
.SH SEE ALSO
.I exit(2)

Added doc/man/3/hash_alloc.3.













































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH HASH_ALLOC 3
.SH NAME
hash_alloc \- allocate a hash data structure
.SH SYNOPSIS
.B #include <hash.h>
.br
.B struct hash *hash_alloc(int hashsize);
.SH DESCRIPTION
The
.ul 1
hash_alloc()
function allocates a hash data structure of the size given by
.ul 1
hashsize. 
For purposes of efficiency,
.ul 1
hashsize
is rounded up to the next power of two.
.ul 1
hashsize
should be chosen with some idea of the number of entries to
be contained within the hash data structure; if a hash size
of 8 is chosen and 100 entries are stored in the hash table,
the average access time will involve one hash lookup and
a walk of length 6 on the collision chain for that hash value.
.PP
.SH RETURN VALUE
On success, a
.ul 1
struct hash
pointer is returned.  Otherwise NULL.
.SH SEE ALSO
.BR hash_dealloc (3),
.BR hash_insert (3),
.BR hash_delete (3),
.BR hash_lookup (3),
.BR hash_foreach (3),
.BR hash_size (3)

Added doc/man/3/hash_dealloc.3.





















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH HASH_DEALLOC 3
.SH NAME
hash_dealloc \- free up entire hash structure
.SH SYNOPSIS
.B #include <hash.h>
.br
.B void hash_dealloc(struct hash *h);
.SH DESCRIPTION
The
.ul 1
hash_dealloc()
function frees the memory of a hash data structure, including all
its internal state.  After calling
.ul 1
hash_dealloc(),
the pointer
.ul 1
h
should no longer be referenced.
.SH SEE ALSO
.BR hash_alloc (3),
.BR hash_insert (3),
.BR hash_delete (3),
.BR hash_lookup (3),
.BR hash_foreach (3),
.BR hash_size (3)

Added doc/man/3/hash_delete.3.



















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH HASH_DELETE 3
.SH NAME
hash_delete \- remove node from hash
.SH SYNOPSIS
.B #include <hash.h>
.br
.B int hash_delete(struct hash *h, long key);
.SH DESCRIPTION
.ul 1
hash_delete()
deletes the entry with the key
.ul 1
key
from the hash
.ul 1
h.
.SH RETURN VALUE
Returns 1 if the key is not found and 0 on success.
.SH SEE ALSO
.BR hash_alloc (3),
.BR hash_dealloc (3),
.BR hash_insert (3),
.BR hash_lookup (3),
.BR hash_foreach (3),
.BR hash_size (3)

Added doc/man/3/hash_foreach.3.

































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH HASH_FOREACH 3
.SH NAME
hash_foreach \- enumerate each entry in the hash, invoking a function
.SH SYNOPSIS
.B #include <hash.h>
.br
.B "f(long h_key, void *h_data, void *arg);"
.br
.B "void hash_foreach(struct hash *h, intfun f, void *arg);"
.SH DESCRIPTION
.ul 1
hash_foreach()
walks through the hash
.ul 1
h
and executes the function
.ul 1
f
for each entry. It is executed with the key and val pointer as
inserted by the previous call to
.ul 1
hash_insert,
along with the provided
.ul 1
arg.
.SH SEE ALSO
.BR hash_alloc (3),
.BR hash_dealloc (3),
.BR hash_insert (3),
.BR hash_delete (3),
.BR hash_lookup (3),
.BR hash_size (3)

Added doc/man/3/hash_insert.3.



































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH HASH_INSERT 3
.SH NAME
hash_insert \- insert a new key/value pair into the hash
.SH SYNOPSIS
.B #include <hash.h>
.br
.B int hash_insert(struct hash *h, long key, void *val);
.SH DESCRIPTION
.ul 1
hash_insert()
inserts a new key specified by
.ul 1
key
into the hash
.ul 1
h.
It key is mapped to the value
.ul 1
val.
It is illegal to insert a key when that key value
is already present in the hash table.
.SH RETURN VALUE
Returns 1 on error and 0 on success.
.SH BUGS
At least when compiled for DEBUG, the hash library should check
for duplicate insertions and abort().
.SH SEE ALSO
.BR hash_alloc (3),
.BR hash_dealloc (3),
.BR hash_delete (3),
.BR hash_lookup (3),
.BR hash_foreach (3),
.BR hash_size (3)

Added doc/man/3/hash_lookup.3.



















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH HASH_LOOKUP 3
.SH NAME
hash_lookup \- look up a node based on its key
.SH SYNOPSIS
.B #include <hash.h>
.br
.B void *hash_lookup(struct hash *h, long key);
.SH DESCRIPTION
.ul 1
hash_lookup()
is used to lookup the value of the h_data pointer of an entry with the key
.ul 1
key 
in the hash
.ul 1
h.
.SH RETURN VALUE
Returns the value of the h_data pointer on success. If the struct h doesn't exist or the key isn't found 0 is returned.
.SH SEE ALSO
.BR hash_alloc (3),
.BR hash_dealloc (3),
.BR hash_insert (3),
.BR hash_delete (3),
.BR hash_foreach (3),
.BR hash_size (3)

Added doc/man/3/hash_size.3.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.TH HASH_SIZE 3
.SH NAME
hash_size \- tell how many elements are stored in a hash
.SH SYNOPSIS
.B #include <hash.h>
.br
.B uint hash_size(struct hash *h);
.SH DESCRIPTION
.ul 1
hash_size()
returns the number of distinct key/value pairs stored
in this hash data structure.
.SH RETURN VALUE
The size of the hash.
.SH SEE ALSO
.BR hash_alloc (3),
.BR hash_dealloc (3),
.BR hash_insert (3),
.BR hash_delete (3),
.BR hash_lookup (3),
.BR hash_foreach (3)

Added doc/man/6/group.6.























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH "GROUP" "6" "" "" "File formats"
.SH "NAME"
group \- user group file
.SH "DESCRIPTION"
\fB/vsta/etc/group\fP is an ASCII file which defines the groups to which users
belong.  There is one entry per line, and each line has the format:
.sp
.RS
group_name:GID:capability[,capability...]
.RE
.sp
The field descriptions are:
.IP group_name
the name of the group.
.IP GID
the numerical group ID.
.IP capability
This is a list of capabilities granted to members of this group.
There can be one or more capabilities, separated by further colons.
A user can access any file that either has the capability of
the user or a capability granted from the group to which the user belongs.
.SH "FILES"
/vsta/etc/group
.SH "SEE ALSO"
.BR login (1),
.BR passwd (6),
.BR ids (6)

Added doc/man/6/ids.6.



















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH "IDS" "6" "" "" "File formats"
.SH "NAME"
ids \- ID mapping
.SH "DESCRIPTION"
ID's and capabilities are central to protection in VSTa.
This file describes ID's, mapping from symbolic names to numbers.
The portion of the file concerning the "vandys" account (usr.vandys) is:
.LP 
usr:3
.RS
vandys:1
.br 
jtk:2
.RE
.LP 
So if you're "usr.vandys", numerically this is actually "3.1",
whereas "usr.jtk" would be "3.2".
.SH "FILES"
/vsta/etc/ids

.SH "SEE ALSO"
.BR login (1),
.BR passwd (1),
.BR passwd (6),
.BR group (6)

Added doc/man/6/passwd.6.























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH "PASSWD" "6" "" "" "File formats"
.SH "NAME"
passwd \- password file
.SH "DESCRIPTION"
.B Passwd
is a text file containing a list of the system's accounts,
specifying for each account the user name, user ID, account
name,
group ID, home directory, shell, capabilities, and environment
variable path.
It should have general read permission (many utilities
use it to map user IDs to user names), but write access only for the
superuser.
.PP 
If you create a new login, put a star in the password field,
and then edit the corresponding entry in
I /vsta/etc/shadow
to establish the actual password.
.PP 
There is one entry per line, with the format:
.sp
.RS
username:password:UID:GID:name:capability:directory:environment:shell
.RE
.sp
The field descriptions are:
.sp
.RS
.TP 1.0in
.I username
.br
The name of the user on the system. This is what you enter to the login program.
.TP 
.I password
.br
The account's login password. Passwords are not actually stored in
.BR  passwd (6),
but rather in
.BR  shadow (6).
This field should be set to a star ("*").
.TP 
.I UID
.br
The numerical user ID. In UNIX, this would define what files you can access,
but not so in VSTa. Rather, in VSTa, the "UID" is simply that: an ID
related to one particular logged in user.
It is used to answer questions like "who created this file?",
but not "who can read this file?".
.TP 
.I GID
.br
The group ID indicates a specific group id
.BR  group (6).
By being a member of a particular group, you get capabilities.
So a set of capabilities suitable for some particular group of
accounts is described in
.BR  group (6)
for a given group ID. Then, each user account has the same group ID,
and they all
share those capabilities.
.TP 
.I name
.br
This field is only used for informational purposes.
It contains the real name of the account's owner.
.TP 
.I capability
.br
Capabilities granted to this account.
The capability name is hierarchical, and is a reference to the
numerical counterpart, looked up via
.BR  ids (6).
After you log in, your capabilities are the sum of this one,
plus any additional ones granted due to your group ID.
.TP 
.I directory
.br
the user's $HOME directory.
.TP 
.I environment
.br
Environment path.
Very much unlike UNIX, your environment is kept in an external server,
which is global to the system.
A given user's environment variables exist under /env with the given name.
Each variable shows up as a simple file within that directory.  Thus,
if you wish to know the $HOME of the "joe" account, "cat /env/joe/HOME"
would access this information, assuming you possess sufficient
capabilities to access the file.
.TP 
.I shell
.br
The program run at login (if empty,
.BR /bin/sh
is used).
If set to a non\-existing executable, the user will be unable to login
through
.BR login (1).
.RE
.SH "FILES"
.I /vsta/etc/passwd
.SH "SEE ALSO"
.BR passwd (1),
.BR login (1),
.BR group (6),
.BR ids (6),
.BR shadow (6)

Added doc/man/6/shadow.6.















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
.TH "SHADOW" "6" "" "" "File formats"
.SH "NAME"
shadow \- password file
.SH "DESCRIPTION"
The
.I shadow
file has the same format as the passwd file,
but most of the fields are left empty.
It exists so that the account password may be
stored in a file with restricted read access, and its
protection should be set so that only system
programs can access it.
The passwd file itself is left public so that programs like
.BR ls (1)
can convert user ID's to user names.
.TP 
An entry looks like:
user:password:::::::
.LP 
The fields are:
.TP 
user
.br
The username of the user.
.TP 
password
.br
The password of the user in plain text.
.LP 
The rest of the fields are left empty; they correspond to the actual
fields in /vsta/etc/passwd.
.SH "FILES"
/vsta/etc/passwd \- user account information
.br 
/vsta/etc/shadow \- user passwords
.SH "SEE ALSO"
.BR login (1),
.BR passwd (1),
.BR passwd (6)

Added doc/man/Makefile.

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
OUT=build
include ../../src/makefile.all
DIRS=1 2 6

build:

clean:

clobber:

install:
	sh ./install.sh $(ROOT)

Added doc/man/README.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
The files in this directory tree are nroff source using the -man macro
set.  During "make install", they are processed into text output and
this output is placed in the binary distribution.

Because there is not an acceptable open source nroff command (groff
is a bloated C++ program, and Plan 9's is not open source), this approach
was adopted so that the installed VSTa system could display man pages
without requiring the presence of an nroff.  If you want to process
man pages for yourself, you will need to go get access to the Plan 9
source (it's pretty easy to get), after which you may contact me
directly to get the patches I applied in porting to VSTa.

I would welcome pointers to a pure C, small and efficient implementation
of nroff which was available under a suitable open source license.

Andy Valencia
vandys@vsta.org
Thu Oct 25 19:22:21 2001 GMT

Added doc/man/install.sh.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
root=$1
dirs="1 2 3 6"

cp map $root/doc/man
for x in $dirs
do
	# Create the man dir for this section
	mkdir -p $root/doc/man/$x

	# Make sure no stale, old man pages are present
	rm -f $root/doc/man/$x/*.$x

	# Walk our man pages, converting from nroff source
	for y in $x/*.$x
	do
		nroff -man $y > $root/doc/man/$y
	done
done
exit 0

Added doc/passwd.txt.

































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
There are quite a number of files related to user accounts and
their associated attributes.  This document gives a quick summary
of what goes where, and does what.

/vsta/etc/passwd

The passwd file is the central database concerning user accounts.  A
typical line in the passwd file looks like:

vandys:*:1:0:Andy Valencia:usr.vandys:/vandys:vandys:/vsta/bin/sh

The first field, "vandys", is the username.  This is what you enter
to the login program.

The second field, "*", is the password field.  Passwords are not
actually stored in /vsta/etc/passwd, but rather in /vsta/etc/shadow.
More on this below.

The third field, "1", is the "user ID".  In UNIX, this would define
what files you can access, but not so in VSTa.  Rather, in VSTa,
the "UID" is simply that: an ID related to one particular logged
in user.  It is used to answer questions like "who created this
file?", but not "who can read this file?".

The fourth field, "0", is the "group ID".  This ID indicates a
specific group in /vsta/etc/group (documented below).  By being
a member of a particular group, you get capabilities.  So a set
of capabilities suitable for some particular group of accounts is
described in /vsta/etc/group for a given group ID.  Then, each user
account has the same group ID, and they all share those capabilities.

The fifth field, "Andy Valencia", is simply a textual description of
the person using the account.

The sixth field, "usr.vandys", lists your initial capability.  The
capability name is hierarchical, and is a reference to the numerical
counterpart, looked up via /vsta/etc/ids.  So after you log in, your
capabilities are the sum of this one, plus any additional ones granted
due to your group ID.

The seventh field, "/vandys", is your home directory.  $HOME gets set
to this.

The eighth field, "vandys", is your environment path.  Very much unlike
UNIX, your environment is kept in an external server, which is global
to the system.  A given user's environment variables exist under /env
with the given name--/env/vandys, in this case.  Each variable shows
up as a simple file within that directory.

The ninth field, "/vsta/bin/sh", is your default shell.  $SHELL will be
set to it, and after successful login this is what will be launched as
your command interpreter.

/vsta/etc/shadow

The shadow file has the same format as the passwd file, but most of the
fields are left empty.  The entry corresponding to passwd's example would
be:

vandys:glarfl:::::::

Which simply encodes that user account "vandys" has the password "glarfl".
The reason these two files exist is so that the shadow file can be
given file permissions such that the average user can not read it.  The
passwd file is left public so that programs like "ls" can convert user
ID's to user names.

/vsta/etc/ids

ID's and capabilities are very central to protection in VSTa.  This file
describes ID's, mapping from symbolic names to numbers.  The portion of
the file concerning the "vandys" account (usr.vandys) is:

usr:3
	vandys:1
	jtk:2

So if you're "usr.vandys", numerically you're actually "3.1".  How are
these used?  See the section "How do capabilities work?" in the file
/vsta/doc/faq.txt.

/vsta/etc/group

The group ID referenced in the passwd file picks a line from this
file.  The line for "vandys"'s group (0) is:

root:0:sys.sys

This gives a name ("root") to group 0, and then lists capabilities
which should be granted to any member of this group.  In this
case, the single capability "sys.sys" is granted.  So for account
"vandys", any file which could be accessed by either "usr.vandys"
*or* by "sys.sys" will be accessible.  There can be zero or more
capabilities (separated by further colons).  Note that "sys.sys"
is looked up in the /vsta/etc/ids file, and converted to actual
numbers.

Added doc/rel_todo.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(Notes to Andy on each release)

Things to do per release:

1. Make sure vsta/doc/features.txt is up to date
2. Check copyright year in /vsta/README and /vsta/etc/motd
3. Edit vsta/etc/banner
4. cvs -n update 2>&1 | more
5. "cd vsta/src" and "sh mkall.sh"
6. "cd vsta ; sh mkall.sh install"
7. Reboot and verify things still work
8. "cd vsta/src" and "sh mkall.sh clobber"
9. "cd vsta", mount something on /dist, and "make -f mkdist.mk"
10. Put the install packages on my test machine and do a scratch install
11. Push it out to the FTP server
12. See if there are any new packages, and put links in the WWW page
13. "cd vsta", and "cvs tag <rel>"
	<rel> is formatted as V1_6_4 (for 1.6.4, duh)
14. Update the release note page on the web site
15. Take latest release note entries and mail to list along with
	release announcement

Added doc/roadmap.txt.



























































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
This is a quick roadmap of where things are and how to get things done.
Please, please, PLEASE back up your disk before trying to run any of
this software!

0. Requirements

VSTa has a driver for the ST-506 "classic AT" hard disk interface.
This driver has also been verified with one and two disk IDE systems.
The disk geometry can be obtained via (1) the controller's "read
parameter" command, (2) the NVRAM/BIOS stored disk parameters, or
(3) by hand-entering the disk parameters.  Detailed instructions
are in the menu.lst file, discussed below.  The default is "read
parameter", which works fine in most cases.  Note that in pretty
much all modern IDE controllers, LBA addressing is used, which
skips much of the hassles previously associated with disk geometries.

Mike Larson has written a SCSI disk driver for the Adaptec 1542[bc]
interface.  IDE and SCSI appear to co-exist without problems.  Mike also
has provided support for CDROM filesystems and SCSI tape.

VSTa uses a FAT filesystem (FAT-12, FAT-16, and FAT-32 are supported,
along with VFAT "long filenames").  It is expected that you'll
already have set up such a filesystem, and you'll be expected to
load the VSTa files onto it using whatever OS got this filesystem
set up.  Examples below are for a DOS-like environment (DOS native,
or very likely a DOS window under Windows).  You should make sure that
your DOS/Windows extraction utilities support long filenames.

The console driver supports both MGA and CGA text screen locations.
It is not auto-detect.  The keyboard driver expects the AT scan
codes.  The floppy driver supports most common formats, although
I've only tested 1.2M/5.25" and 1.44M/3.5".  My smallest system
has 8M of RAM, and that seems to be plenty.  Systems with up to 768
Meg have been booted.  If you use the C compiler, you'll need a CPU
with a floating point unit.

The binaries distributed with VSTa include a port of the GNU C
compiler.  Self-hosted VSTa compiles are the method of choice.
But since you get precompiled versions of all the servers, commands,
and libraries you can skip self-hosted compiles if you just want
to play with the running system.  Or you can choose just to recompile
interesting parts.

Boot loading happens using the Multiboot standard.  The most common
Multiboot compliant boot loader is GRUB (GRand Unified Bootloader).
VSTa works with the Free Software Foundation's version of GRUB, which
is the recommended one.  You should go over to:

	http://www.gnu.org/software/grub/

and get the latest stable version.  GRUB can be written onto a floppy,
which can then be used to boot VSTa (i.e., boot GRUB off floppy, and then
use GRUB to bootload VSTa).  GRUB can also be installed onto hard disk,
but please note that this isn't necessary, and you can leave your hard
disk boot setup alone and still try VSTa.  More details follow below.

1. Loading the VSTa files onto your disk.

Create the directory /vsta on your FAT filesystem.  This should be
the first partition on whatever disk you happen to be using.  If
you don't have the DOS versions of gzip or tar, you can find them
in the same place you found vsta.tz and vsta_bin.tz.

	mkdir \vsta
	cd \vsta
	(Copy vsta.tz here)
	gzip -dv vsta.tz
	tar -xvf vsta.t
	del vsta.t

	You now have all the binaries and administrative files for VSTa.

Accounts are in /vsta/etc/passwd, with a parallel file /vsta/etc/shadow
holding the actual passwords, which are in the clear.  Feel free
to edit these files using a DOS editor; VSTa tries to accomodate
both DOS \r\n and UNIX \n conventions for line-oriented data.  The
format is described in src/lib/passwd.c, but should be familiar to
anyone who's messed with UN*X-like password files.  The group you
belong to in the passwd file causes you to get more abilities; see
/vsta/etc/group.  Finally, numeric format IDs are mapped to symbolic
courtesy of /vsta/etc/ids.  You can see how in vsta/src/lib/ids.c.

2. VSTa directory organization

The main VSTa source is under CVS; the CVS storage is available separately.
The binary directories are not kept under CVS.

	The VSTa tree is organized under /vsta as:

	bin		Commands
	lib		Libraries
	etc		System-oriented text files
	doc		Documentation, such as it is
	doc/man		Some initial man pages, in roff format
	src/os		Kernel source
	src/os/make	Where kernel objects are compiled into
	src/os/kern	Portable kernel C source
	src/os/mach	Kernel i386 C, as well as assembly
	src/srv		All portable servers (filesystems, etc.)
	src/srv/mach	i386/ISA servers (disk, keyboard, etc.)
	src/bin		Command source
	src/lib		Library source

3. Booting the kernel, the first time

If you're already using GRUB (or some other comparable Multiboot
compliant loader), you can skip this.

Create a GRUB boot floppy using the direction provided with the GRUB
distribution.

Reboot your machine with this floppy in drive A (and your BIOS configured
to attempt booting from floppy), and you should end up at a GRUB interactive
prompt.  For a default installation, you could now enter:

	root= (hd0,0)
	kernel= /vsta/boot/vsta
	module= /vsta/boot/cons
	module= /vsta/boot/namer
	module= /vsta/boot/wd d0:readp
	module= /vsta/boot/dos -d //disk/wd:wd0_dos0 -n fs/root
	module= /vsta/boot/init
	boot

You should watch GRUB's messages as you enter these lines; it'll complain
if things are amiss.  After "boot", you should see VSTa boot up and run
off of your hard disk.  These commands load the boot modules off the
first IDE hard drive, from the /vsta/boot directory.  You may need to
adjust these commands; the file /vsta/boot/menu.lst documents how, under
the "VSTa boot" section.  Common reasons to need to adjust these strings
are that your display card uses MGA text mode, that you need to specify
your IDE parameters manually, or that you're using a SCSI disk.

Assuming you have successfully booted, and you're up for converting
to GRUB as your boot loader (it supports DOS, Windows, FreeBSD,
NetBSD, Linux, Hurd, OS/2, and VSTa), you should now refer to the
full instructions for setting your PC up to use GRUB as your
bootloader.

A snapshot of a known working GRUB distribution is available at:

	ftp://ftp.vsta.org/grub/

Please use the FSF version if at all possible, since GRUB is under
active development, and is receiving many useful bug fixes and
enhancements.  For instance, it recently received support for VSTa's
experimental filesystem, vstafs.

4. Kernel debugger

You have two options for kernel debugging.  As shipped, the on-screen
kernel debugger is selected.  If you want to have the kernel debugger
talk out the serial port, see src/os/mach/dbg*.c.  You will also have to
change the compilation options if you're using a display card at the MGA
text address.

You will enter the debugger if VSTa crashes, or if a boot server
task dies.  You can also type ^Z (control-Z) and you'll drop into
it.  A "q" will continue.  Since the console driver handles this,
it'll try to restore your screen after you come back from the
debugger.

Use the "pr" command to see the proc table, the "bt" command to see a
stack backtrace of the current process.  "dv" will dump virtual
addresses, and "dp" will dump physical.  You can look at the current
user process' address space by OR'ing in 0x80000000 to the user address.
"dv" will complain if you try to look at a non-existent address.  "di"
will disassemble at an address; symbols were put in during the kernel
build, so the output should be fairly comprehensible (if you know i386
assembly!)  The "=" will take expressions and print them in hex,
decimal, and symbolically.

"pr <num>" will dump out a particular process with more detail.  "vas
<addr>" will dump out a virtual address space struct; similarly for
"pset", "pview", "port", "ref" (portref).  "tf" will dump out the
current trapframe (from the last trip through trap()), or "tf <addr>"
will assume there's a trap frame at the given address, and dump it out
instead.

5. Multi-screens

By default four logins are launched for four virtual screens.  Use
ALT-F1, ALT-F2, ..., to switch between the screens.  See the
file /vsta/etc/inittab to launch more or less screens.  The first
screen (ALT-F1) also receives syslog output.

6. Building from Source Code

The source to the main VSTa distribution is managed by CVS.  You'll
need to extract the vsta_cvs.tz file into /cvs, which will create
a tree of CVS files under /cvs/vsta.  Once these are extracted, you
need to check out a copy of the tree in some location:

	cd /home/me
	cvs -d /cvs co vsta

This will extract the main VSTa source (which does not include ports
of various utilities--just the kernel, libraries, and core commands like
the default shell).

Now you need to cd into the source, and edit the line near the top of
makefile.all to indicate the location of this source tree:

	cd vsta/src
	vi makefile.all

Change the line:
	SRC=/vandys/src/src
to:
	/home/me/vsta/src

(In the case of this example.)  With this set, you can now cd down into any
of the source directories and build from the source there.  You probably
want to cd into vsta/src/lib first, as the other source in the tree links
against the privately built version of the library files:

	cd lib
	make

After this, you could build, say, the DOS filesystem code by:
	cd ../srv/dos		(up out of lib, and into DOS source)
	make

In the top of vsta/src is a mkall.sh, which will enumerate all source,
invoking a "make" with any arguments provided to mkall.sh.  Thus, you
could build everything by:

	cd ../..		(up out of DOS, to top of source tree)
	sh mkall.sh

Or remove all object files by:

	sh mkall.sh clean

Or clean up all generated files by:

	sh mkall.sh clobber

NOTE: some binaries (emacs, rc, gcc & friends) are in their own distribution
tar files.  They are not present in your source tree unless you explicitly
loaded them.  The stuff in src/bin/ports is not part of the regular/formal
"VSTa system build" process.

7. Documentation

Regrettably, not much.  Use the "man" command to access the initial man
pages.  Hopefully more will show up, but at least the messaging
primitives are now documented.  You can list the available man entries
with "man 2 msg", and see msg_receive() documentation with "man
msg_receive" (or "man 2 msg_receive").

The /vsta/doc/man directory will show you which man pages exist.  There
are also some files in /vsta/doc (like this one), but nothing earth
shaking.  The C is pretty thoroughly commented, which'll help
programmers.  I'm not sure VSTa's ready for non-programmers, but you're
welcome to give it a try.

The file /vsta/doc/features.txt will tell you a bit about what's
being added from release to release.

8. More?

No doubt, but I can't think of what might help the most.  Stay in touch!
The best way to do that is to join the VSTa E-mail list.  Send to
vsta-request@zendo.com.

					Regards,
					Andy Valencia
					vandys@vsta.org

Added doc/select.txt.

















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
How to support select() in your server:

1. Initialize

Each select() client is going to need some state, which is defined
in the "struct selclient" from <selfs.h>.  Use sc_init on this
struct (usually a part of your per-client state) to set it up.

2. FS_WSTAT support

select() support is enabled by the client doing a wstat() of certain
entries in the open file.  The precise names are not important; what
is important is that the server in its handling of the FS_WSTAT
message calls sc_wstat() (implemented in src/lib/selfs.c in libusr.a)
to let the select support code decode the operation.

If sc_wstat() returns an error, then it didn't recognize the wstat()
fields, and you can go on to check them for your own purposes (or
return an EINVAL if you don't recognize them in your code, either).

If sc_wstat() returns success, then it took care of accepting the
message, so your client has already received a msg_reply() indicating
success.  What's left is for you to record that this client is using
select().  Generally, this will entail adding your per-client struct
to a linked list associated with whatever file/object they have open
on this connection.

3. Check select status

You will usually have a routine which takes an open file, and then
checks the list of select() users under that file.  For any user which
is selecting for something which is available (i.e., they've selected
for reading and there's data ready to be read), a call to sc_event()
is made with a pointer to the "struct selclient" state set up by
sc_wstat(), and also a mask of the event bits active (ACC_READ,
ACC_WRITE, and so forth).  sc_event will tell the select server about
this change, and the select server will take care of waking up any
appropriate clients.

This routine should be called whenever a new select() client is added.
It can also be called on event changes on the file (first readable
data arrives, so you need to see if anybody's selecting for readable
data).  For the latter, you might find the general routine sub-optimal,
but sufficient.

4. Finish

Use sc_done() on any client who's been activated by a successful
sc_wstat().  This will clean up the library's behind-the-scenes
state.

5. More Stuff

There are some fields of the selclient struct which you'll want to use.
sc_iocount is used to synchronize between the client app, the server, and
the selfs server.  The problem is that due to timing windows of the three
independent processes, it's possible for the server to tell the selfs
server about a select event, but the client in the meantime posts, say,
a read to the server, and thus has consumed the data before the selfs
server could tell the client about it.  Without any extra care, what would
happen is that the selfs server would subsequently tell the client, the
client would believe it, and post a read() for data which it already
had read--unexpectedly blocking the client, possibly.

To handle this, the sc_iocount field is used.  It is a monotonically
increasing count of the number of client-server I/O operations which have
happened.  Each select event is tagged with the current value of this
field, and this lets a client realize that it's been told about a stale
select state.  When the client gets such data from the selfs server, it
compares the sc_iocount value to the I/O count of its own connection to
the server (it's stored in the file descriptor layer state), and if they
don't match, it ignores the select event.

Thus, you need to bump sc_iocount each time an I/O completes from the
server for a particular client.  The I/O count of both the client and
the server thus goes up in lock step, and as select events stream between
client and server by way of the selfs server, this stamp lets the client
and server keep all the select events straight with respect to their
I/O activities.

sc_needsel

Another flag is needed to tell if a particular client needs further
sc_event notifications.  It's cleared when a client receives an
sc_event notification, and re-set when the client is subsequently seen
posting an I/O for the data.  The library correctly handles situations
like posting multiple select()'s for an event before doing an I/O to
act on the indicated data.

Added doc/ten.doc.























































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

   
   
                    THE TEN COMMANDMENTS FOR C PROGRAMMERS
                              (ANNOTATED EDITION)
                                       
by Henry Spencer

   
   
   
   
1

Thou shalt run lint frequently and study its pronouncements with care, for
verily its perception and judgement oft exceed thine.

   This is still wise counsel, although many modern compilers search out
   many of the same sins, and there are often problems with lint being
   aged and infirm, or unavailable in strange lands. There are other
   tools, such as Saber C, useful to similar ends.
   
   ``Frequently'' means thou shouldst draw thy daily guidance from it,
   rather than hoping thy code will achieve lint's blessing by a sudden
   act of repentance at the last minute. De-linting a program which has
   never been linted before is often a cleaning of the stables such as
   thou wouldst not wish on thy worst enemies. Some observe, also, that
   careful heed to the words of lint can be quite helpful in debugging.
   
   ``Study'' doth not mean mindless zeal to eradicate every byte of lint
   output-if for no other reason, because thou just canst not shut it up
   about some things-but that thou should know the cause of its
   unhappiness and understand what worrisome sign it tries to speak of.
   
2

Thou shalt not follow the NULL pointer, for chaos and madness await thee at its
end.

   Clearly the holy scriptures were mis-transcribed here, as the words
   should have been ``null pointer'', to minimize confusion between the
   concept of null pointers and the macro NULL (of which more anon).
   Otherwise, the meaning is plain. A null pointer points to regions
   filled with dragons, demons, core dumps, and numberless other foul
   creatures, all of which delight in frolicing in thy program if thou
   disturb their sleep. A null pointer doth not point to a 0 of any type,
   despite some blasphemous old code which impiously assumes this.
   
   
   
3

Thou shalt cast all function arguments to the expected type if they are not of
that type already, even when thou art convinced that this is unnecessary, lest
they take cruel vengeance upon thee when thou least expect it.

   A programmer should understand the type structure of his language,
   lest great misfortune befall him. Contrary to the heresies espoused by
   some of the dwellers on the Western Shore, `int' and `long' are not
   the same type. The moment of their equivalence in size and
   representation is short, and the agony that awaits believers in their
   interchangeability shall last forever and ever once 64-bit machines
   become common.
   
   Also, contrary to the beliefs common among the more backward
   inhabitants of the Polluted Eastern Marshes, `NULL' does not have a
   pointer type, and must be cast to the correct type whenever it is used
   as a function argument.
   
   (The words of the prophet Ansi, which permit NULL to be defined as
   having the type `void *', are oft taken out of context and
   misunderstood. The prophet was granting a special dispensation for use
   in cases of great hardship in wild lands. Verily, a righteous program
   must make its own way through the Thicket Of Types without lazily
   relying on this rarely-available dispensation to solve all its
   problems. In any event, the great deity Dmr who created C hath wisely
   endowed it with many types of pointers, not just one, and thus it
   would still be necessary to convert the prophet's NULL to the desired
   type.)
   
   It may be thought that the radical new blessing of ``prototypes''
   might eliminate the need for caution about argument types. Not so,
   brethren. Firstly, when confronted with the twisted strangeness of
   variable numbers of arguments, the problem returns... and he who has
   not kept his faith strong by repeated practice shall surely fall to
   this subtle trap. Secondly, the wise men have observed that reliance
   on prototypes doth open many doors to strange errors, and some indeed
   had hoped that prototypes would be decreed for purposes of error
   checking but would not cause implicit conversions. Lastly, reliance on
   prototypes causeth great difficulty in the Real World today, when many
   cling to the old ways and the old compilers out of desire or
   necessity, and no man knoweth what machine his code may be asked to
   run on tomorrow.
   
   
   
4

If thy header files fail to declare the return types of thy library functions,
thou shalt declare them thyself with the most meticulous care, lest grievous
harm befall thy program.

   The prophet Ansi, in her wisdom, hath added that thou shouldst also
   scourge thy Suppliers, and demand on pain of excommunication that they
   produce header files that declare their library functions. For truly,
   only they know the precise form of the incantation appropriate to
   invoking their magic in the optimal way.
   
   The prophet hath also commented that it is unwise, and leads one into
   the pits of damnation and subtle bugs, to attempt to declare such
   functions thyself when thy header files do the job right.
   
   
   
5

Thou shalt check the array bounds of all strings (indeed, all arrays), for
surely where thou typest ``foo'' someone someday shall type
``supercalifragilisticexpialidocious''.

   As demonstrated by the deeds of the Great Worm, a consequence of this
   commandment is that robust production software should never make use
   of gets(), for it is truly a tool of the Devil. Thy interfaces should
   always inform thy servants of the bounds of thy arrays, and servants
   who spurn such advice or quietly fail to follow it should be
   dispatched forthwith to the Land Of Rm, where they can do no further
   harm to thee.
   
6

If a function be advertised to return an error code in the event of
difficulties, thou shalt check for that code, yea, even though the checks
triple the size of thy code and produce aches in thy typing fingers, for if
thou thinkest ``it cannot happen to me'', the gods shall surely punish thee for
thy arrogance.

   All true believers doth wish for a better error-handling mechanism,
   for explicit checks of return codes are tiresome in the extreme and
   the temptation to omit them is great. But until the far-off day of
   deliverance cometh, one must walk the long and winding road with
   patience and care, for thy Vendor, thy Machine, and thy Software
   delight in surprises and think nothing of producing subtly meaningless
   results on the day before thy Thesis Oral or thy Big Pitch To The
   Client.
   
   Occasionally, as with the ferror() feature of stdio, it is possible to
   defer error checking until the end when a cumulative result can be
   tested, and this often produceth code which is shorter and clearer.
   Also, even the most zealous believer should exercise some judgement
   when dealing with functions whose failure is totally uninteresting...
   but beware, for the cast to void is a two-edged sword that sheddeth
   thine own blood without remorse.
   
7

Thou shalt study thy libraries and strive not to reinvent them without cause,
that thy code may be short and readable and thy days pleasant and productive.

   Numberless are the unwashed heathen who scorn their libraries on
   various silly and spurious grounds, such as blind worship of the
   Little Tin God (also known as ``Efficiency''). While it is true that
   some features of the C libraries were ill-advised, by and large it is
   better and cheaper to use the works of others than to persist in
   re-inventing the square wheel. But thou should take the greatest of
   care to understand what thy libraries promise, and what they do not,
   lest thou rely on facilities that may vanish from under thy feet in
   future.
   
8

Thou shalt make thy program's purpose and structure clear to thy fellow man by
using the One True Brace Style, even if thou likest it not, for thy creativity
is better used in solving problems than in creating beautiful new impediments
to understanding.

   These words, alas, have caused some uncertainty among the novices and
   the converts, who knoweth not the ancient wisdoms. The One True Brace
   Style referred to is that demonstrated in the writings of the First
   Prophets, Kernighan and Ritchie. Often and again it is criticized by
   the ignorant as hard to use, when in truth it is merely somewhat
   difficult to learn, and thereafter is wonderfully clear and obvious,
   if perhaps a bit sensitive to mistakes.
   
   While thou might think that thine own ideas of brace style lead to
   clearer programs, thy successors will not thank thee for it, but
   rather shall revile thy works and curse thy name, and word of this
   might get to thy next employer. Many customs in this life persist
   because they ease friction and promote productivity as a result of
   universal agreement, and whether they are precisely the optimal
   choices is much less important. So it is with brace style.
   
   As a lamentable side issue, there has been some unrest from the
   fanatics of the Pronoun Gestapo over the use of the word ``man'' in
   this Commandment, for they believe that great efforts and loud
   shouting devoted to the ritual purification of the language will
   somehow redound to the benefit of the downtrodden (whose real and
   grievous woes tendeth to get lost amidst all that thunder and fury).
   When preaching the gospel to the narrow of mind and short of temper,
   the word ``creature'' may be substituted as a suitable pseudoBiblical
   term free of the taint of Political Incorrectness.
   
9

Thy external identifiers shall be unique in the first six characters, though
this harsh discipline be irksome and the years of its necessity stretch before
thee seemingly without end, lest thou tear thy hair out and go mad on that
fateful day when thou desirest to make thy program run on an old system.

   Though some hasty zealots cry ``not so; the Millenium is come, and
   this saying is obsolete and no longer need be supported'', verily
   there be many, many ancient systems in the world, and it is the decree
   of the dreaded god Murphy that thy next employment just might be on
   one. While thou sleepest, he plotteth against thee. Awake and take
   care.
   
   It is, note carefully, not necessary that thy identifiers be limited
   to a length of six characters. The only requirement that the holy
   words place upon thee is uniqueness within the first six. This often
   is not so hard as the belittlers claimeth.
   
   
   
10

Thou shalt foreswear, renounce, and abjure the vile heresy which claimeth that
``All the world's a VAX'', and have no commerce with the benighted heathens who
cling to this barbarous belief, that the days of thy program may be long even
though the days of thy current machine be short.

   This particular heresy bids fair to be replaced by ``All the world's a
   Sun'' or ``All the world's a 386'' (this latter being a particularly
   revolting invention of Satan), but the words apply to all such without
   limitation. Beware, in particular, of the subtle and terrible ``All
   the world's a 32-bit machine'', which is almost true today but shall
   cease to be so before thy resume grows too much longer.

Added doc/todo.txt.





































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
copyin/copyout--put in locore.s, use user's segment
	-- Worse than I thought.  Bug in i386 allows ring 0 code to write
	to a read-only mapping.  So COW is a bust when one would expect
	it to work for a copyout.  Walk translations manually?  Bleh.
	Use copy-on-reference for i386.
	Nah, ignore it and use the new bits of the i486 and later.

X TLB staleness--how split HAT/portable?  Assume TLB shootdown is
X relatively cheap and if not assume HAT will do the gyrations
X necessary?
	-- Yes

X Should HAT update ref/mod bits in c_flags?
	-- Moved this to pp_flags.  It's done above the HAT.

X Make sure users can't send M_RESVD messages
	-- Done.  Allow M_TIME as I don't feel like renumbering it now.

X How hand msg_err() answers around?
	-- In the m_err field in a sysmsg, which is copied into
	 the thread's error field when in the thread's context.

X Make msg_send() and msg_connect() handle the case of the port dying
X with their stuff queued.  Does a lock on the port give a guarantee
X that any transition to state P_DEAD will guarantee an answer to their
X queued message first?
	-- client handles sysmsg; server handles segments received.
	 Server gets away from client by zeroing the p_port field.
	 Server enumerates clients through his circular linked list
	 of portrefs.

X Have to have server use portref's segref array--multiple outstanding
X requests on a server allows several requests worth of mapped data
X to be present.
	-- The segrefs which are currently attached is kept in a per-
	 *thread* variable.  A thread must either finish with its use
	 of the data before its next receipt, or must copy it to
	 someplace more permanent.

X Change the psop_writeslot so that the asynch flag is instead a pointer
X to a function--NULL means synchronous.  Then pageout pushes can use
X a routine to free/clean the page, exit pushes can simply free, and
X so forth.
	-- Done.  iodone_free() and iodone_unlock() will do free/unlock
	or unlock on completion.

X Add a FS_ABSWRITE and FS_ABSREAD to combine a seek and a write.  Needed
X for many things, including swap I/O's.
	-- Added for floppy driver.  Must ensure handled for disk drivers
	when they're written.  Still nice to add to all handlers that
	offer seek.

X Add the second argument to msg.c and msgcon.c handling.
	-- Done.

X Add optimization to add the cache translation *each time* someone faults
X a slot translation in.  Currently we only add when going from !PP_V->PP_V;
X this works, but will guarantee that the page must be brought in from
X its server if the cache view is ever paged out.  Should be done by keeping
X a flag with the perpage, and clearing it when these cache translations
X are deleted.
	-- Bogus concept.  We allow caching by letting pages reside under
	a pset with a ref count of 0.  The pageout daemon is reponsible
	for reaping these as memory situations demand.

X Add machinery to page stealer to raid cache pviews who are the last
X reference to the pset.  We need them as we don't tag the page otherwise,
X but we should clear them out over time.  Note that the pages can be
X stolen just fine; it's the pview itself that we need to reclaim at
X some point.
	-- There is no such thing, though I still need to add something
	to lazily keep psets around, even though they're not currently
	mapped.  Trick is that this has to be unified with a mechanism
	for mapping a pset to a given server and inode number.

X Add code to manage T_KERN bit of thread flags
	-- Skip it.  Not worth the trouble.

Add code to qio_msg_send to handle case of a "copyout".  A bcopy()
to ptov(pfn) should suffice?  Who would use it?

X Add handling for M_DUP messaging.  How correlate back to new portref
X being created?
	-- Done.  The p_msg field of the portref tells us that it's an
	M_DUP, and it tells us (in m_arg) what's being created.

Convert m_connect() (and others?) to use kernmsg_send().  I think I
can make the code quite a bit smaller.

X Add code to put a proc on the "cheated" queue.
	-- Done.  Also have to keep a CPU hog counter, as otherwise
	a CPU hog gets bumped once by a "cheated" process, and becomes
	a "cheated" process itself.

X Should "allprocs" be doubly-linked?
	-- Done.  Useful for at least one flavor of pstat() to keep
	marker for place in proc list.  Also gives the obvious benefit
	of an O(1) removal on exit().

Once up, should invalidate all vaddr's above heap

X Clean up scheduling node on exit
	-- Done.  "memleak" function of kdb is your friend....

X Implement mmap()
	-- Done.

X In fork() the portref array is mutexed across the entire dup_port()
X 	using p_sema from the proc structure.  This is at least overkill,
X 	perhaps worse.  The code should use find_portref(), scanning the
X 	old portref array and attempting to get portrefs through the
X 	usual interface.  This shares more code, and considerably narrows
X 	the time for which the proc sema must be held.
	-- Done.  Became acute with pstat() interlocking against such
	processes.  Now is released as we step along.

XAdd a flag for pviews to tell if they should be copied/inherited on
X	a fork().  Make sure transient pviews from msg_receive()'s
X	are *not* inherited.
	-- I think the SHARED flag (in the pset?) does the job.

XRethink struct core's c_long vs. c_atl fields.  They are mutually
X	exclusive in use except for cases of M_CONNECT messages,
X	where the user temporarily maps the permissions of the
X	connecting process.  Perhaps it would be worth adding some
X	code to handle this differently... would it be worth it
X	to regain 4 bytes per 4K (0.1%) overhead?
	-- Revamped.  The attach lists of pviews have moved up to
	the perpage struct--c_atl only indicates the primary pset.
	This keeps the temporary user mapping of a memory pset from
	trashing our malloc state.

Add check to enable_dma() for conflict in DMA channels

Check abort in wd/rw.c to see if we do the right thing when we're
	DMA'ing into the would-be-aborters address space.
	Definitely a problem... f_abort is set but not used.
	The code does not really flag queued versus active;
	aborting queued would be easy.  Active is going to require
	waiting for the completion interrupt... probably not worth
	hosing down the controller to try and speed that up.

XCheck whether the right nodes get flagged dirty when we create
X	a node within a dir.  Does the dir node need to be flagged?
X	(DOSFS)
	I believe this is all working OK now.

Xrmdir seems hosed.  We need to throw away the clusters under the file,
X	but we hash off this cluster number for the case of directories.
X	I also don't seem to be updating the node's length field before
X	letting deref_node() clear it.  (DOSFS)
	Fixed.  Fiddled with ordering of what gets cleared where.

Caching of executables is indefinite.  Need two things: first, a way
	for the page stealer to tear down & reclaim stuff which hasn't
	been used for a while.  Second, need a way for a server to
	get rid of a cache entry for a file being removed.
	-- 2nd part done; DOS initiates an unhash and returns EAGAIN.
	unlink() will try 2 times, with a 0.1 sec sleep in between.
	First part is nasty, since kernel would need to close connection
	with server.  Bum server could hang up the kernel.
	Is this true?  MSG_DISCONNECT doesn't require a server ack.

X Some problems with mutexing of semaphores and treatment of priorities.
X 	I don't think we're honoring PRIHI right now.  Also, I think
X 	p_sema needs to take the runq lock sooner, to provide mutexing
X 	between sleeping and being handed an event.
	-- PRIHI does the right thing now.  I think semaphores are taking
	lock at the right time.

Definitely a problem with free_proc() letting go of the root of our
	page table before we're off it.  idle_stack() needs to get onto
	its own root page table--the one we use to boot will suffice,
	I think.  idle_stack(), once fixed, needs to be called before
	we ever call free_proc().
	*** Hmm, further thoughts.  If we had an idle_vas(), we could
	safely abandon a per-process address space without hitting
	the tedium of losing the stack (and thus all local variables).
	The kernel view is stable, so we could idle_vas(), free_proc(),
	and proceed at our leisure.
	Definitely steal that initial root page table--it should be
	nearly right already.

X vm_fault.c's description of fault handling is out of date.
X	Done.

XDOSFS can't uncache an executable after it's been renamed.  Problem appears
X	to be that "inode number" changes after rename, and thus can't
X	hunt down the right node to clear.
	-- Fixed.  inode number can simply be node address; more efficient,
	and keeps inum from changing due to rename.

XVM can't reclaim cached pages which have no current attach list entry.
X	We currently allow valid pset slots with ref count of 0.  Should
X	probably have pset_fod type psets keep a cache pseudo-vas and then
X	free memory under a pset when ref count goes to 0.
	-- Fixed.  Caching is done by always leaving a reference around
	  to a pseudo-pview under the pset.  Pageout can flush this
	  reference out just like others, and a ->0 ref frees the page.

X There are a couple more pset operations which should be vectors instead
X	of special cases in a switch statement.
	-- Done.  I think all the appropriate ones are vectors now.

XSystem call interruption via t_qsav is screwed.  *Any* semaphore op--for
X	page fault, system call, whatever--can longjmp back out through
X	this.  Need to set it up so only system calls can have this
X	happen.
	-- Fixed.  Got rid of t_qsav entirely.  Sometimes you carry
	assumptions from past OS's even when it really doesn't make
	a whole lot of sense.

Need to set up message operation interruption so even a completely
	hosed server can't hang a client.  Client should be able to
	interrupt operation without blocking ; client should be able
	to disconnect without blocking.  DMA is a special case.
	For M_READ this should be OK, but what about writing?
	You can't make the buffer disappear.  Let the server continue
	to reference it?

X DOS file ID is OK for purposes of caching executables, but hoses things
X 	like "du" which want to know if a particular file is a link to
X 	one which has already been examined.  Well no, you can't have
X 	hard links under DOS, but you still need to return a unique
X 	per-file ID.  Blk # of first cluster would be OK, except that
X 	zero-length files don't have any blocks, so what ID do they
X 	get?  We used to use the cluster # of the containing dir OR'ed
X 	in with the directory slot, but this caused the ID to change
X 	on a rename.  It was then impossible to unhash a renamed a.out
X 	which was kernel cached.
	-- Fixed.  You're pretty much stuck with containing dir
	cluster #, plus dir entry.  To deal with caching, you simply
	have to uncache the executable before moving it (which the
	DOS server does for you).

Time to do a new level of path walk optimization.  chdir() should try
	to hold an open port_t on the cwd, to spare walking the prefix
	for each new file operation.  This is made tricky by things
	like chdir'ing to /vsta/foo, and holding "foo" open, but if
	the fstab has a /vsta/foo/bar mount point, you need to stop
	using the cached port_t when you walk from foo down into bar.
	This cwd port_t probably needs to be dropped on an exec().
	Further notes:
		Probably need to keep a pointer to the winning mnttab.
		If this is optimized correctly, you can use the cached
			cwd port even if they specify an absolute path
			(but its initial part matches the cwd)
		This implies a full mnttab scan, but you probably need
			to do this anyway just to see if there's a
			more-specific mnttab match than the cwd.  Keeping
			the cwd mntent lets you compare it to what falls
			out of the mnttab scan.

And for a *really* big change, FS_OPEN2 should be done; it takes the
	entire path string, and walks it down within the server, rather
	than feeding path elements one at a time.  Return should
	indicate success, or how far down before the error occurred (for
	ESYMLINK, for instance).

There's more than one race condition left in exit.  The "last" flag,
	when "false", doesn't give much protection.  Imagine a thread
	exit()'ing, and it isn't "last".  But it's preempted, and
	the last thread exits during this preemption.  So the process
	will be scrubbed before the "!last" thread finishes, which
	breaks at least the way the scheduling data structures are
	cleaned up.

Also, again in do_exit(), there are definite problems with free'ing
	memory during the exit path.  In cases where memory moves back
	into the system pool, the thread can block with its data
	structures partially destroyed.  Bad.

And since we're ragging on do_exit(), note that ephemeral threads
	should not determine the exit() status of the process.  The
	exit status should be determined by the exit value of the last
	non-ephemeral thread.

SIGCHLD emulation is done with a second (ephemeral) thread.  This is fine,
	except that this second thread needs to wait on the kernel
	for child completions, and then needs to feed them into the
	POSIX waitpid() emulation.  But this code isn't thread safe,
	so you might race with the main thread.  It also malloc()'s
	data for such completions, and malloc() isn't thread safe either.

On the issue of SIGCHLD, perhaps it really is time to make libc thread
	safe?

There needs (after all) to be a hook for voluntary shutdown.  DOS and
	VSTa filesystems don't need it, and I want to minimize the
	dependencies (OS's in general, and VSTa in particular, do
	tend to crash...).  But the "clean" flag if we ever do a BSD
	filesystem would need to use this hook.

wd disk driver seems to mis-handle large I/O's.  This is masked
	because it currently has a MAXIO parameter which defends
	it, but for DMA, there's no real reason to enforce such
	a cap.

X Need to add LBA support to wd; this is a fairly standard mechanism
X 	which is really quite nice.
	Done.  It was even easier than I expected!

I have a partially completed port of mgr-0.69.  We should eventually
	finish the port and upgrade VSTa's mgr to be current with
	everybody else's.

On the subject of partially completed ports, I also have a mostly
	complete gcc 2.8.1 port.  I'm not aware of any pressing need
	to upgrade, but I think 2.8.1 has some bug fixes in things
	like "long long" which we may eventually want.

X It's basically impossible to have more shared libraries, because almost
X 	any additional shared library will depend on the libc one.  This
X 	isn't too hard to fix; mmap() needs to be able to understand that
X 	when you try to mmap a file at a given position, and that same
X 	file is already mapped there, that it should just return success.
X 	Then subsequent shared libraries can just be linked against the
X 	stubs of earlier ones.  This means a shared library needs to
X 	declare which other libraries it needs, but I think that's OK.
	Done.  libm, libregex, and libtermcap use it.

The base shared library mechanism isn't flexible enough to handle an
	open ended collection of potential shared libraries.  We should
	use the current mechanism for a "core" set, and then support
	PIC style shared libraries for an arbitrary number of additional
	ones.

X Now that we have a palatable nroff, we should convert all man pages
X 	to the standard -man macro set.
	Done.

There's a long and mostly hidden bug which should be put to rest.  Dave
	Hudson found it and recommended the right fix many moons ago.
	The data and BSS segments are concatenated, so that if there's
	spare room at the end of data, BSS symbols are pulled back into
	some of this area.  The problem is that data and BSS are two
	distinct VM regions, with distinct attributes.  If a large data
	structure straddles them, and then is used as a kernel argument
	(i.e., do a msg_send/msg_receive across the whole data structure),
	you get an EFAULT, because to the kernel it looks like you're
	trying to violate the range check of a region.
	Fix is to change the link map to pad out data, and don't let
	BSS symbols be pulled back into it.  This wastes some memory,
	but it fixes the problem neatly, and it at worst wastes a
	single page of memory.

I think b_elem in "struct bucket" is unused.  Remove it.  Are there
	others?

b_pages counts up the # of pages used for a particular bucket size.
	We should think about free'ing some pages back to the main
	free list if that bucket appears to have enough resources
	anyway.

There's a deadlock which can happen when two threads in one process
	are used to implement a certain kind of server.  The problem
	is when one thread is a client of the server, which the
	other thread is running.  If the client has a request pending,
	and you kill the entire process, you may find that the server
	thread is gone, and the client thread--because a request
	was pending--is blocked trying to get an interrupted operation
	acknowledged from the (now dead) server.  If the server thread
	were not in the same process, then process cleanup would have
	cleared the server port automatically.  But since it is, the
	kernel doesn't know but that the other thread may be the next
	to take over handling of server actions.

	The fix is probably to keep count of the number of threads
	which are not blocked on a port served from the process of
	the threads.  When this count reaches 0, each server port
	in the process should be closed.

I've been trying to get a handle on a bug which hoses the first text
	page of the console server.  It looks like a couple 32-bit
	values scrozz a couple spots of text--in practice, always
	a bit of code needed when you switch virtual console screens.
	The interesting bit is that these values are stack pointer
	values for the kernel stack of the console server thread
	itself.  Some really funky condition, and very hard to
	reproduce.
	X Fixed.  __end was being set before common symbols were
	X folded in, resulting in GRUB being told to insert the boot
	X modules too low in memory (on top of kernel BSS, in fact)

X In a release or so, /bin/ovim should go away.
	X Done.

The pipe server should be made to buffer data rather than always
	lock a writer until there's a reader for his data.  It should
	still, of course, do a direct writer->reader I/O op for
	cases where the reader is present at the time of the write.

X There's a little tidying to be done with environment variable emulation.
X 	The /env server has a "fork" wstat which doesn't appear to be
X 	used.  With the change where fork() no longer even necessarily
X 	clone()'s open connections, there really needs to be a way for
X 	children /env/# entries to not propagate back to parents.  So
X 	this seems like a need for wstat("fork") to come back in the
X 	start.c code at a minimum, along with an explicit clone() of
X 	the /env/ mount point port.
X	Done.

We should go ahead and emulate the rest of symlinks.  This would require
	S_IFLNK and S_ISLINK, as well as lstat and perhaps others.

The mouse server should provide its dx/dy/button changes via the regular
	FS_READ interface, not via FS_STAT.  This becomes apparent when
	you use select(), and now FS_STAT has to become a recognized
	I/O source... which is wrong.  Right now FS_READ just blocks
	the process and completes the read with a length of zero; it should
	instead sprintf() a FS_STAT type buffer, and make that the
	return value.

fork_env() gets invoked on a new process startup.  Technically, it should
	happen right after a process successfully fork()'s--so that
	any environment variable manipulation is handled correctly,
	even if the new process never actually follows the fork() with
	an exec of any sort.

Added etc/Makefile.





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
OUT=build
include ../src/makefile.all
FILES=autoexec.net banner fstab ftpusers group \
	ids inittab less.help libvga.config motd passwd \
	profile rc shadow

build:

clean:

clobber:

install:
	cp $(FILES) $(ROOT)/etc

Added etc/autoexec.net.

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
#
# Bootup for ether attached system vsta.vsta.org
#
attach eth eth0 1500 //net/ne:0
# Or for 3c509 flavors: attach eth eth0 1500 //net/el3:0
ip addr 10.0.0.69
route add default eth0
host vsta
domain suffix vsta.org
domain addserver 10.0.0.2
password xyzzy
start vsta

Added etc/banner.







>
>
>
1
2
3

	Welcome to VSTa v1.6.8!

Added etc/fstab.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
fs/root /
# NAMER /namer
fs/tmp /tmp
# fs/pipe /pipe
null /dev/null
# fs/vfs /v
fs/root:vsta/bin /bin

Added etc/ftpusers.







>
>
>
1
2
3
ftp * /dist 1
anonymous * /dist 1
vandys boo / 1

Added etc/group.









>
>
>
>
1
2
3
4
root:0:sys.sys
users:1
guest:2
super:99:

Added etc/ids.































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sys:1
	sys:1
	io:2
	dos:3
	misc:4
bad:2
	bad:2
usr:3
	vandys:1
	jtk:2
	guest:3
	ken:4
	root:99
guest:4
	guest:1

Added etc/inittab.









































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#
# Table of programs launched by the init program
#
# Includes some examples of further servers to run if you
# have the appropriate hardware.
#
bg:/vsta/boot/pipe
bg:/vsta/boot/env
bg:/vsta/boot/tmpfs fs/tmp
bg:/vsta/boot/devnull
bg:/vsta/boot/proc
bg:/vsta/boot/selfs
#
# Enable this if you use MGR, or other apps using pseudo-tty's.
#
# bg:/vsta/boot/pty
#
# Serial port driver; device COM1, advertised as name tty/tty01
# bg:/vsta/boot/rs232 com1 tty/tty01
#
# vstafs entry runs a VSTa filesystem on the wd0_p1 partition
# of the WD driver.  It would be mounted globally from /vsta/etc/fstab.
# bg:/vsta/boot/vstafs -p disk/wd:wd0_p1 fs/vfs
#
# NE2000 ethernet driver; card at base I/O 0x300 with IRQ 5
# bg:/vsta/boot/ne 0x300,5
#
fg:/vsta/bin/setime
fg:/vsta/bin/runrc
again:/vsta/bin/login CONS:0
again:/vsta/bin/login CONS:1
again:/vsta/bin/login CONS:2
again:/vsta/bin/login CONS:3
#
# Enable this if you enable com1 (tty/tty01) above
# again:/vsta/bin/login tty/tty01

Added etc/less.help.











































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
      Commands marked with * may be preceeded by a number, N.

  H              Display this help.
  q              Exit.

  f, SPACE    *  Forward  N lines, default one screen.
  b           *  Backward N lines, default one screen.
  e, j, CR    *  Forward  N lines, default 1 line.
  y, k        *  Backward N lines, default 1 line.
  d           *  Forward  N lines, default half screen or last N to d/u.
  u           *  Backward N lines, default half screen or last N to d/u.
  r              Repaint screen.
  R              Repaint screen, discarding buffered input.

  /pattern    *  Search forward for N-th line containing the pattern.
  ?pattern    *  Search backward for N-th line containing the pattern.
  n           *  Repeat previous search (for N-th occurence).

  g           *  Go to line N, default 1.
  G           *  Like g, but default is last line in file.
  p, %        *  Position to N percent into the file.
  m<letter>      Mark the current position with <letter>.
  '<letter>      Return to a previously marked position.
  ''             Return to previous position.

  E [file]       Examine a new file.
  N           *  Examine the next file (from the command line).
  P           *  Examine the previous file (from the command line).
  =              Print current file name.
  V              Print version number of "less".

  -<flag>        Toggle a command line flag.
  _<flag>        Display the setting of a command line flag.
  +cmd           Execute the less cmd each time a new file is examined.

  !command       Passes the command to the system to be executed (by $SHELL).
  v              Edit the current file (with $EDITOR).

Added etc/libvga.config.

























































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# Configuration file for svgalib. Default location is /etc/vga.
# Other config file locations:	~/.svgalibrc
# 				where SVGALIB_CONFIG_FILE points
# Lines starting with '#' are ignored.

# If you have two vga cards with the same pci vendor id, svgalib will try
# to use the first one, even if the second one is active. In that case,
# use PCIStart to force starting the search for a vga card only at a
# specific bus and device numbers. For example, an AGP card is usually on
# bus 1, while pci is on bus 0, so to use the AGP card, uncomment:

# PCIStart 1 0

# Have a deep look at README.config to see what can do here (especially
# for mach32).

# Mouse type:

# mouse Microsoft	# Microsoft
# mouse MouseSystems	# Mouse Systems
# mouse MMSeries	# Logitech MM Series
# mouse Logitech	# Logitech protocol (old, newer mice use Microsoft protocol)
# mouse Busmouse	# Bus mouse
# mouse PS2		# PS/2 mouse
# mouse MouseMan	# Logitech MouseMan
# mouse Spaceball	# Spacetec Spaceball
# mouse IntelliMouse	# Microsoft IntelliMouse or Logitech MouseMan+ on serial port
# mouse IMPS2		# Microsoft IntelliMouse or Logitech MouseMan+ on PS/2 port
# mouse none		# None

mouse Microsoft

# Mouse/keyboard customisation by 101 (Attila Lendvai). If you have any good
# ideas you can reach me at 101@kempelen.inf.bme.hu

# mouse_accel_type	normal	# No acceleration while delta is less then
				# threshold but delta is multiplied by
				# mouse_accel_mult if more. Originally done by
				# Mike Chapman mike@paranoia.com

mouse_accel_type	power	# The acceleration factor is a power function
				# of delta until it reaches m_accel_mult. It
				# starts from the coordinate 
				# [1, 1 + m_accel_offset] and goes to
				# [m_accel_thresh, m_accel_mult]. If delta
				# is bigger then m_accel_thresh it is a plain
				# constant (m_accel_mult). It is the f(delta)
				# function with which the delta itself will be
				# multiplied. m_accel_offset is 1 by default,
				# so for delta = 1 the accelerated delta will
				# remain 1 (You don't lose resolution). The
				# starting point of the f(delta) function
				# might be moved along the Y axis up/down with
				# m_accel_offset thus defining the initial
				# minimum acceleration (for delta = 1).
				# Basically it's like the normal mode but the
				# acceleration factor grows as you move your
				# mouse faster and faster, not just turns in
				# and out. Threshold is the point from where
				# the f(delta) function gets linear.
				# This is the one I use for *uaking... =)

# mouse_accel_type	off	# No comment...


mouse_accel_mult	60	# This is the number with which delta will
				# be multiplied. Basically it's the number
				# that defines how big the acceleration will
				# be

mouse_accel_thresh	4	# This is the threshold. See description by
				# power

mouse_accel_power	0.8	# This is the second parameter of the power
				# function used in power mode. Used only by
				# the power mode

mouse_accel_offset	30	# This is the offset of the starting point
				# on the Y axis. With this you can define the
				# number that will multiply delta = 1 so it's
				# the initial acceleration.

# mouse_accel_maxdelta	600	# This is an upper limit for delta after
				# the acceleration was applied

# mouse_maxdelta	30	# This is an upper limit for the delta
				# before the acceleration. With this one you
				# can limit the biggest valid delta that
				# comes from the mouse.

# mouse_force			# Force parameters even if they seem strange
				# By default svgalib prints an error if any
				# of the numbers are somhow out of the
				# reasonable limit, (Like a negative mult :)
				# and uses the default that's in vgamouse.h

# Usually /dev/mouse will be a link to the mouse device.
# However, esp. with the Spacetec Spaceball you may
# want to specify a different device for svgalib to use

# mdev /dev/ttyS0 # mouse is at /dev/ttyS0

# Some multiprotocol mice will need one of the following:

# setRTS   # set the RTS wire.
# clearRTS # clear the RTS wire.
# leaveRTS # leave the RTS wire alone (default) (Wire is usually set)
# setDTR   # set the DTR wire.
# clearDTR # clear the DTR wire.
# leaveDTR # leave the DTR wire alone (default) (Wire is usually set)

# On mice such as the Microsoft IntelliMouse and Logitech MouseMan+, turning
# the wheel rotates the mouse around the X axis. mouse_wheel_steps controls
# how many steps make up a full 360-degree turn and thus how much rotation
# occurs with each step. The default is 18 steps (20 degrees per step), the
# real-world value for the IntelliMouse. Adjust it to match your mouse or to
# suit your preferences; a negative number reverses the direction and zero
# disables rotation.

mouse_wheel_steps 18		# For MS IntelliMouse (default)
# mouse_wheel_steps 24		# For Logitech FirstMouse+
# mouse_wheel_steps -18		# Reverses direction
# mouse_wheel_steps 0		# Disables rotation

# mouse_fake_kbd_event sends a fake keyboard event to the program when the
# wheel on a Microsoft IntelliMouse, Logitech MouseMan+, or similar wheel
# mouse is turned. This can be useful for programs that do not recognize the
# Z axis, but only works with some programs that use raw keyboard.
# The format is:
#
#   mouse_fake_kbd_event upscancode downscancode
#
# The up and down scancodes are the scancodes of the keys to simulate when
# the wheel is turned up and down, respectively.
#
# Scancodes can be specified numerically or symbolically; the symbolic names
# are determined by the keymap (see below), if no keymap is loaded the default
# is the standard US QWERTY keyboard with the following names available:
# letters (a-z), numbers (zero-nine), function keys (F1-F12), the keypad
# numbers (KP_0-KP_9) and other keys (KP_Multiply, KP_Subtract, KP_Add,
# KP_Period, KP_Enter, and KP_Divide), and the following - minus, equal,
# Delete, Tab, bracketleft, bracketright, Return, Control, semicolon,
# apostrophe, grave, Shift, backslash, comma, period, slash, Shift, Alt, space,
# Caps_Lock, Num_Lock, Scroll_Lock, Last_Console, less, Control_backslash,
# AltGr, Break, Find, Up, Prior, Left, Right, Select, Down, Next, Insert,
# and Remove.
#
# Note that this option has no effect unless the IntelliMouse or IMPS2 mouse
# type is used (see above). Also note that the simulated keypresses are
# instantaneous, so they cannot be used for functions that require a key to
# be held down for a certain length of time.

#  This example simulates a press of the left bracket ([) when the wheel is
#  turned up and a press of the right bracket (]) when the wheel is turned
#  down (good for selecting items in Quake II):
# mouse_fake_kbd_event bracketleft bracketright

# Keyboard config:

# kbd_keymap allows you to use an alternate keyboard layout with programs that
# use raw keyboard support by translating scancodes from the desired layout to
# their equivalents in the layout expected by the program. This option has no
# affect on programs that do not use raw keyboard.
#
# Keymap files to convert between any two arbitrary keyboard layouts can be
# generated with the svgakeymap utility, but there are limitations to the
# translations that can be performed. Read the file README.keymap in the
# svgalib documentation directory for more in-depth information.
#
# You must specify the full path to the keymap file; it is recommended that
# keymaps be kept in the same directory as libvga.config, normally /etc/vga.
# The keymap specified in the configuration file can be overriden by setting
# the environment variable SVGALIB_KEYMAP to point to another keymap file;
# this can be useful for setting keymaps on a per-program basis.
#
#  This example will use the provided US-Dvorak to US-QWERTY map to allow a
#  Dvorak keyboard layout to be used with a program that expects a standard US
#  QWERTY keyboard, for instance Quake:
# kbd_keymap /etc/vga/dvorak-us.keymap

# There is a potential security risk in allowing users to remap keyboard
# scancodes at will; with this option enabled only keymap files owned by
# root can be used. Normally you should leave this on, but if you have a
# single-user box or you really trust your users you may find it convenient
# to run without it and allow users to load arbitrary keymaps.

kbd_only_root_keymaps

# kbd_fake_mouse_event, as it says, sends a fake mouse event to the program.
# The format is: kbd_fake_mouse_event scancode [flag(s)] command [argument]
#   Scancode is a raw scancode or a descriptive name, the same as with fake
#   keyboard events (see above). If you use keymap conversion, specify
#   scancodes for the keyboard layout the program will receive.
#   Flags:   down   - trigger event when the key is pressed (default)
#	     up     - the opposite
#	     both   - trigger in both case, if pressed/released
#	     repeat - repeat events if the key is kept pressed (off by default)
#   commands: delta[xyz]  - send a fake delta event as if you have moved your
#	 		    mouse. If the parameter is 'off' / 'on' it will turn
#			    off/on the respective mouse axis (requires a
#			    parameter, of course)
#	      button[123] - send a fake event that the mouse button is pressed
#			    or released that's given by the parameter.
# 			    ('pressed' or 'released')
# Here are some examples:

#  This is one I use in *uake: it turns around, looks down a bit and when the
#  key is released it does the opposite, so it gets back to the starting state.
#  With this one and the help of a rocket you can fly though the whole map :)
#  (Scancode 28 is enter)
# kbd_fake_mouse_event 28 both deltax 8182 down deltay -1500 up deltay 1500

#  This one will switch off the y axis of the mouse while the key (right ctrl)
#  is kept pressed.
# kbd_fake_mouse_event 97 down deltay off  up deltay on

#  This one is the same as if you were pressing the left mouse button. (But
#  if you move your mouse then the button state will reset even if you keep
#  right ctrl down...)
# kbd_fake_mouse_event 97 down button1 pressed up button1 released

# Monitor type:

# Only one range can be specified for the moment.  Format:
# HorizSync min_kHz max_kHz
# VertRefresh min_Hz max_Hz

# Typical Horizontal sync ranges
# (Consult your monitor manual for Vertical sync ranges)
#
# 31.5 - 31.5 kHz (Standard VGA monitor, 640x480 @ 60 Hz)
# 31.5 - 35.1 kHz (Old SVGA monitor, 800x600 @ 56 Hz)
# 31.5 - 35.5 kHz (Low-end SVGA, 8514, 1024x768 @ 43 Hz interlaced)
# 31.5 - 37.9 kHz (SVGA monitor, 800x600 @ 60 Hz, 640x480 @ 72 Hz)
# 31.5 - 48.3 kHz (SVGA non-interlaced, 800x600 @ 72 Hz, 1024x768 @ 60 Hz)
# 31.5 - 56.0 kHz (high frequency, 1024x768 @ 70 Hz)
# 31.5 - ???? kHz (1024x768 @ 72 Hz)
# 31.5 - 64.3 kHz (1280x1024 @ 60 Hz)

HorizSync 31.5 35.5
VertRefresh 50 90

# Montitor timings
#
# These are prefered over the default timings (if monitor and chipset
# can handle them). Not all drivers use them at the moment, and Mach32
# has its own syntax (see below).
# The format is identical to the one used by XFree86, but the label
# following the modeline keyword is ignored by svgalib.
#
# Here some examples:

# modeline "640x480@100"  43  640  664  780  848   480  483  490  504
# modeline "800x600@73"   50  800  856  976 1024   600  637  643  666
# modeline "1024x768@75"  85 1024 1048 1376 1400   768  771  780  806

# It seems there is a need for a 512x384 mode, this timing was donated
# by Simon Hosie <gumboot@clear.net.nz>: (it is 39kHz horz by 79Hz vert)

# Modeline "512x384@79"     25.175 512  522  598  646   384  428  436  494

# Here's a 400x300 Modeline (created by svidtune). Note that for
# doublescan modes, the Vertical values are half the real one (so XFree86
# modelines can be used). 

# Modeline "400x300@72" 25.000 400 440 504 520 300 319 322 333 doublescan

# Here is a mode for a ZX Spectrum emulator:
# Modeline "256x192@73" 12.588 256 269 312 360 192 208 212 240 doublescan
# newmode 256 192 256 256 1

# the width must be divisible by 8. Some cards require even divisiblity by
# 16, so that's preferable, since there are no standard modes where the
# width is not divisible by 16.

# The following modes are defined in svgalib, but have no timings in
# timing.c, so you'll have to add a modeline in order to use them:
# 1280x720, 1360x768, 1800x1012, 1920x1080, 1920x1440, 2048x1152
# and 2048x1536   

# Mach32 timings:

# e.g. Setup a 320x200 mode for the mach32:

#define 320x200x32K 320x200x64K 320x200x16M 320x200x16M32
#                     16 320 392 464 552 200 245 265 310

# These are REQUIRED for above mode, please edit to suit your monitor.
# (No, I won't pay for a new one)
# HorizSync 29 65
# VertRefresh 42 93.5

# Chipset type:
#
# Use one of the following force chipset type.
# Autodetects if no chipset is specified.
#
# If you have a PCI or AGP card, don't use chipset type forcing.
# If the card is not autodetected, its a bug, and it will probably
# not work even with forcing. Try running vgatest (with no chipset 
# line), and send to me (matan@svgalib.org) the output, a copy of
# /proc/pci (or lspci -n -vv) and whatever info you have on the card. 
#
# If a chipset driver gives trouble, try forcing VGA.

# chipset VGA		# Standard VGA
# chipset EGA		# EGA
# chipset ET3000	# Tseng ET3000
# chipset ET4000	# Tseng ET4000
# chipset Cirrus	# Cirrus Logic GD542x
# chipset TVGA		# Trident TVGA8900/9000
# chipset Oak		# Oak Technologies 037/067/077
# chipset S3		# S3 chipsets
# chipset GVGA6400	# Genoa 6400
# chipset ARK		# ARK Logic
# chipset ATI		# old ATI VGA
# chipset Mach32	# ATI Mach32
# chipset ALI		# ALI2301
# chipset Mach64	# ATI Mach64 - deprecated
# chipset ET6000        # Tseng ET6000
# chipset APM	 	# Alliance Technology AT 24/25/3D
# chipset NV3		# nVidia Riva 128
# chipset VESA          # nicely behaved Vesa Bioses
# chipset MX		# MX86251 (some Voodoo Rush boards)
# chipset PARADISE 	# WD90C31
# chipset RAGE		# RagePro (and might work with some older mach64)
# chipset BANSHEE	# Banshee/V3.
# chipset SIS		# SiS 5597/6326/620/530 cards / integrated vga.
# chipset I740		# Intel i740 based cards.


# EGA Color/mono mode:
# Required if chipset is EGA.
#
# Use one of the following digits to force color/mono:

# monotext  # Card is in monochrome emulation mode
# colortext # Card is in color emulation mode
colortext

# RAMDAC support:
# Some chipsets (e.g. S3 and ARK) allows specifying a RAMDAC type.
# If your RAMDAC is not autodetected, you can try specifying it.
# Do NOT specify a RAMDAC if you card uses the S3 Trio chipset
# (the RAMDAC is built in).

# Ramdac Sierra32K
# Ramdac SC15025
# Ramdac SDAC         # S3 SDAC
# Ramdac GenDAC       # S3 GenDAC
# Ramdac ATT20C490    # AT&T 20C490, 491, 492 (and compatibles)
# Ramdac ATT20C498    # AT&T 20C498
# Ramdac IBMRGB52x    # IBM RGB524, 526, 528 (and compatibles)

# Dotclocks:
# Some chipsets needs a list of dot clocks for optimum operation.  Some
# includes or supports a programmable clock chip.  You'll need to specify
# them here.

# Fixed clocks example:
# (The following is just an example, get the values for your card from
#  you XF86Config)

# Clocks 25.175 28.3 40 70 50 75 36 44.9 0 118 77 31.5 110 65 72 93.5

# Programmable clockchip example:

# Clockchip ICD2061A  # The only one supported right now


# VesaText	      # Helps the VESA driver with text mode restoration
		      # problems.

# VesaSave 14	      # changing value might help text mode restoring
		      # problems with VESA driver. Legal values: 0-15

# NoVCControl	      # Disables svgalib's finding a new VC if run
		      # from X. Good fo using dumpreg under X, but
		      # probably bad for standard usage.

Added etc/motd.









>
>
>
>
1
2
3
4

VSTa operating system, Copyright (c) 1993-1997,2000-2002 by Andrew Valencia
This software is available under the "copyleft" software license.

Added etc/passwd.













>
>
>
>
>
>
1
2
3
4
5
6
root:*:99:99:Charlie Root:usr.root:/vsta/root:root:/vsta/bin/sh
vandys:*:1:0:Andy Valencia:usr.vandys:/vandys:vandys:/vsta/bin/sh
jtk:*:2:1:Jane Valencia:usr.jtk:/jtk:jtk:/vsta/bin/sh
guest:*:3:2:Sample account:guest.guest:/vsta/guest:guest:/vsta/bin/sh
ken:*:4:1:Ken Nicholson:usr.ken:/tmp:ken:/vsta/bin/sh
system:*:0:0:System Placeholder:usr.root:/:root:/vsta/bin/echo

Added etc/profile.









>
>
>
>
1
2
3
4
#
# Global .profile for sh users
#
cat /vsta/etc/motd

Added etc/rc.





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#
# Commands executed once during bootup
#

#
# Global environment variables
#	These are values likely to be the same among all users
#
echo -n vt100 > /env/TERM
echo -n "/vsta/bin:." > /env/PATH
echo -n 'vsta$ ' > /env/PS1
echo -n "-c" > /env/LESS
echo -n PST8PDT > /env/TZ
echo -n /tmp > /env/TMPDIR
echo -n /bin/sh > /env/SHELL

# All done
exit 0

Added etc/shadow.













>
>
>
>
>
>
1
2
3
4
5
6
root:charlie:::::::
vandys::::::::
jtk:test:::::::
guest:test:::::::
ken:*:::::::
system:*:::::::

Added lib/Makefile.

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
OUT=build
include ../src/makefile.all
FILES=bison.simple termcap bison.hairy magic units.lib    

build:

clean:

clobber:

install:
	cp $(FILES) $(ROOT)/lib

Added lib/bison.hairy.





























































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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

extern int timeclock;


int yyerror;		/*  Yyerror and yycost are set by guards.	*/
int yycost;		/*  If yyerror is set to a nonzero value by a	*/
			/*  guard, the reduction with which the guard	*/
			/*  is associated is not performed, and the	*/
			/*  error recovery mechanism is invoked.	*/
			/*  Yycost indicates the cost of performing	*/
			/*  the reduction given the attributes of the	*/
			/*  symbols.					*/


/*  YYMAXDEPTH indicates the size of the parser's state and value	*/
/*  stacks.								*/

#ifndef	YYMAXDEPTH
#define	YYMAXDEPTH	500
#endif

/*  YYMAXRULES must be at least as large as the number of rules that	*/
/*  could be placed in the rule queue.  That number could be determined	*/
/*  from the grammar and the size of the stack, but, as yet, it is not.	*/

#ifndef	YYMAXRULES
#define	YYMAXRULES	100
#endif

#ifndef	YYMAXBACKUP
#define YYMAXBACKUP	100
#endif


short	yyss[YYMAXDEPTH];	/*  the state stack			*/
YYSTYPE	yyvs[YYMAXDEPTH];	/*  the semantic value stack		*/
YYLTYPE yyls[YYMAXDEPTH];	/*  the location stack			*/
short	yyrq[YYMAXRULES];	/*  the rule queue			*/
int	yychar;			/*  the lookahead symbol		*/

YYSTYPE	yylval;			/*  the semantic value of the		*/
				/*  lookahead symbol			*/

YYSTYPE yytval;			/*  the semantic value for the state	*/
				/*  at the top of the state stack.	*/

YYSTYPE yyval;			/*  the variable used to return		*/
				/*  semantic values from the action	*/
				/*  routines				*/

YYLTYPE yylloc;		/*  location data for the lookahead	*/
				/*  symbol				*/

YYLTYPE yytloc;		/*  location data for the state at the	*/
				/*  top of the state stack		*/


int	yynunlexed;
short	yyunchar[YYMAXBACKUP];
YYSTYPE	yyunval[YYMAXBACKUP];
YYLTYPE yyunloc[YYMAXBACKUP];

short *yygssp;			/*  a pointer to the top of the state	*/
				/*  stack; only set during error	*/
				/*  recovery.				*/

YYSTYPE *yygvsp;		/*  a pointer to the top of the value	*/
				/*  stack; only set during error	*/
				/*  recovery.				*/

YYLTYPE *yyglsp;		/*  a pointer to the top of the		*/
				/*  location stack; only set during	*/
				/*  error recovery.			*/


/*  Yyget is an interface between the parser and the lexical analyzer.	*/
/*  It is costly to provide such an interface, but it avoids requiring	*/
/*  the lexical analyzer to be able to back up the scan.		*/

yyget()
{
  if (yynunlexed > 0)
    {
      yynunlexed--;
      yychar = yyunchar[yynunlexed];
      yylval = yyunval[yynunlexed];
      yylloc = yyunloc[yynunlexed];
    }
  else if (yychar <= 0)
    yychar = 0;
  else
    {
      yychar = yylex();
      if (yychar < 0)
	yychar = 0;
      else yychar = YYTRANSLATE(yychar);
    }
}



yyunlex(chr, val, loc)
int chr;
YYSTYPE val;
YYLTYPE loc;
{
  yyunchar[yynunlexed] = chr;
  yyunval[yynunlexed] = val;
  yyunloc[yynunlexed] = loc;
  yynunlexed++;
}



yyrestore(first, last)
register short *first;
register short *last;
{
  register short *ssp;
  register short *rp;
  register int symbol;
  register int state;
  register int tvalsaved;

  ssp = yygssp;
  yyunlex(yychar, yylval, yylloc);

  tvalsaved = 0;
  while (first != last)
    {
      symbol = yystos[*ssp];
      if (symbol < YYNTBASE)
	{
	  yyunlex(symbol, yytval, yytloc);
	  tvalsaved = 1;
	  ssp--;
	}

      ssp--;

      if (first == yyrq)
	first = yyrq + YYMAXRULES;

      first--;

      for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
	{
	  if (symbol < YYNTBASE)
	    state = yytable[yypact[*ssp] + symbol];
	  else
	    {
	      state = yypgoto[symbol - YYNTBASE] + *ssp;

	      if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
		state = yytable[state];
	      else
		state = yydefgoto[symbol - YYNTBASE];
	    }

	  *++ssp = state;
	}
    }

  if ( ! tvalsaved && ssp > yyss)
    {
      yyunlex(yystos[*ssp], yytval, yytloc);
      ssp--;
    }

  yygssp = ssp;
}



int
yyparse()
{
  register int yystate;
  register int yyn;
  register short *yyssp;
  register short *yyrq0;
  register short *yyptr;
  register YYSTYPE *yyvsp;

  int yylen;
  YYLTYPE *yylsp;
  short *yyrq1;
  short *yyrq2;

  yystate = 0;
  yyssp = yyss - 1;
  yyvsp = yyvs - 1;
  yylsp = yyls - 1;
  yyrq0 = yyrq;
  yyrq1 = yyrq0;
  yyrq2 = yyrq0;

  yychar = yylex();
  if (yychar < 0)
    yychar = 0;
  else yychar = YYTRANSLATE(yychar);

yynewstate:

  if (yyssp >= yyss + YYMAXDEPTH - 1)
    {
      yyabort("Parser Stack Overflow");
      YYABORT;
    }

  *++yyssp = yystate;

yyresume:

  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yydefault;

  yyn += yychar;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
    goto yydefault;

  yyn = yytable[yyn];
  if (yyn < 0)
    {
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrlab;

  yystate = yyn;

  yyptr = yyrq2;
  while (yyptr != yyrq1)
    {
      yyn = *yyptr++;
      yylen = yyr2[yyn];
      yyvsp -= yylen;
      yylsp -= yylen;

      yyguard(yyn, yyvsp, yylsp);
      if (yyerror)
	goto yysemerr;

      yyaction(yyn, yyvsp, yylsp);
      *++yyvsp = yyval;

      yylsp++;
      if (yylen == 0)
	{
	  yylsp->timestamp = timeclock;
	  yylsp->first_line = yytloc.first_line;
	  yylsp->first_column = yytloc.first_column;
	  yylsp->last_line = (yylsp-1)->last_line;
	  yylsp->last_column = (yylsp-1)->last_column;
	  yylsp->text = 0;
	}
      else
	{
	  yylsp->last_line = (yylsp+yylen-1)->last_line;
	  yylsp->last_column = (yylsp+yylen-1)->last_column;
	}
	  
      if (yyptr == yyrq + YYMAXRULES)
        yyptr = yyrq;
    }

  if (yystate == YYFINAL)
    YYACCEPT;

  yyrq2 = yyptr;
  yyrq1 = yyrq0;

  *++yyvsp = yytval;
  *++yylsp = yytloc;
  yytval = yylval;
  yytloc = yylloc;
  yyget();

  goto yynewstate;

yydefault:

  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;

yyreduce:

  *yyrq0++ = yyn;

  if (yyrq0 == yyrq + YYMAXRULES)
    yyrq0 = yyrq;

  if (yyrq0 == yyrq2)
    {
      yyabort("Parser Rule Queue Overflow");
      YYABORT;
    }

  yyssp -= yyr2[yyn];
  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTBASE];

  goto yynewstate;

yysemerr:
  *--yyptr = yyn;
  yyrq2 = yyptr;
  yyvsp += yyr2[yyn];

yyerrlab:

  yygssp = yyssp;
  yygvsp = yyvsp;
  yyglsp = yylsp;
  yyrestore(yyrq0, yyrq2);
  yyrecover();
  yystate = *yygssp;
  yyssp = yygssp;
  yyvsp = yygvsp;
  yyrq0 = yyrq;
  yyrq1 = yyrq0;
  yyrq2 = yyrq0;
  goto yyresume;
}

$

Added lib/bison.simple.







































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
#line 3 "/vsta/lib/bison/bison.simple"

/* Skeleton output parser for bison,
   Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 1, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */


#ifndef alloca
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not GNU C.  */
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
#include <alloca.h>
#else /* not sparc */
#if defined (MSDOS) && !defined (__TURBOC__)
#include <malloc.h>
#else /* not MSDOS, or __TURBOC__ */
#if defined(_AIX)
#include <malloc.h>
 #pragma alloca
#else /* not MSDOS, __TURBOC__, or _AIX */
#ifdef __hpux
#ifdef __cplusplus
extern "C" {
void *alloca (unsigned int);
};
#else /* not __cplusplus */
void *alloca ();
#endif /* not __cplusplus */
#endif /* __hpux */
#endif /* not _AIX */
#endif /* not MSDOS, or __TURBOC__ */
#endif /* not sparc.  */
#endif /* not GNU C.  */
#endif /* alloca not defined.  */

/* This is the parser code that is written into each bison parser
  when the %semantic_parser declaration is not specified in the grammar.
  It was written by Richard Stallman by simplifying the hairy parser
  used when %semantic_parser is specified.  */

/* Note: there must be only one dollar sign in this file.
   It is replaced by the list of actions, each action
   as one case of the switch.  */

#define yyerrok		(yyerrstatus = 0)
#define yyclearin	(yychar = YYEMPTY)
#define YYEMPTY		-2
#define YYEOF		0
#define YYACCEPT	return(0)
#define YYABORT 	return(1)
#define YYERROR		goto yyerrlab1
/* Like YYERROR except do call yyerror.
   This remains here temporarily to ease the
   transition to the new meaning of YYERROR, for GCC.
   Once GCC version 2 has supplanted version 1, this can go.  */
#define YYFAIL		goto yyerrlab
#define YYRECOVERING()  (!!yyerrstatus)
#define YYBACKUP(token, value) \
do								\
  if (yychar == YYEMPTY && yylen == 1)				\
    { yychar = (token), yylval = (value);			\
      yychar1 = YYTRANSLATE (yychar);				\
      YYPOPSTACK;						\
      goto yybackup;						\
    }								\
  else								\
    { yyerror ("syntax error: cannot back up"); YYERROR; }	\
while (0)

#define YYTERROR	1
#define YYERRCODE	256

#ifndef YYPURE
#define YYLEX		yylex()
#endif

#ifdef YYPURE
#ifdef YYLSP_NEEDED
#define YYLEX		yylex(&yylval, &yylloc)
#else
#define YYLEX		yylex(&yylval)
#endif
#endif

/* If nonreentrant, generate the variables here */

#ifndef YYPURE

int	yychar;			/*  the lookahead symbol		*/
YYSTYPE	yylval;			/*  the semantic value of the		*/
				/*  lookahead symbol			*/

#ifdef YYLSP_NEEDED
YYLTYPE yylloc;			/*  location data for the lookahead	*/
				/*  symbol				*/
#endif

int yynerrs;			/*  number of parse errors so far       */
#endif  /* not YYPURE */

#if YYDEBUG != 0
int yydebug;			/*  nonzero means print parse trace	*/
/* Since this is uninitialized, it does not stop multiple parsers
   from coexisting.  */
#endif

/*  YYINITDEPTH indicates the initial size of the parser's stacks	*/

#ifndef	YYINITDEPTH
#define YYINITDEPTH 200
#endif

/*  YYMAXDEPTH is the maximum size the stacks can grow to
    (effective only if the built-in stack extension method is used).  */

#if YYMAXDEPTH == 0
#undef YYMAXDEPTH
#endif

#ifndef YYMAXDEPTH
#define YYMAXDEPTH 10000
#endif

/* Prevent warning if -Wstrict-prototypes.  */
#ifdef __GNUC__
int yyparse (void);
#endif
 
#if __GNUC__ > 1		/* GNU C and GNU C++ define this.  */
#define __yy_bcopy(FROM,TO,COUNT)	__builtin_memcpy(TO,FROM,COUNT)
#else				/* not GNU C or C++ */
#ifndef __cplusplus

/* This is the most reliable way to avoid incompatibilities
   in available built-in functions on various systems.  */
static void
__yy_bcopy (from, to, count)
     char *from;
     char *to;
     int count;
{
  register char *f = from;
  register char *t = to;
  register int i = count;

  while (i-- > 0)
    *t++ = *f++;
}

#else /* __cplusplus */

/* This is the most reliable way to avoid incompatibilities
   in available built-in functions on various systems.  */
static void
__yy_bcopy (char *from, char *to, int count)
{
  register char *f = from;
  register char *t = to;
  register int i = count;

  while (i-- > 0)
    *t++ = *f++;
}

#endif
#endif
 
#line 184 "/vsta/lib/bison/bison.simple"
int
yyparse()
{
  register int yystate;
  register int yyn;
  register short *yyssp;
  register YYSTYPE *yyvsp;
  int yyerrstatus;	/*  number of tokens to shift before error messages enabled */
  int yychar1 = 0;		/*  lookahead token as an internal (translated) token number */

  short	yyssa[YYINITDEPTH];	/*  the state stack			*/
  YYSTYPE yyvsa[YYINITDEPTH];	/*  the semantic value stack		*/

  short *yyss = yyssa;		/*  refer to the stacks thru separate pointers */
  YYSTYPE *yyvs = yyvsa;	/*  to allow yyoverflow to reallocate them elsewhere */

#ifdef YYLSP_NEEDED
  YYLTYPE yylsa[YYINITDEPTH];	/*  the location stack			*/
  YYLTYPE *yyls = yylsa;
  YYLTYPE *yylsp;

#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
#else
#define YYPOPSTACK   (yyvsp--, yyssp--)
#endif

  int yystacksize = YYINITDEPTH;

#ifdef YYPURE
  int yychar;
  YYSTYPE yylval;
  int yynerrs;
#ifdef YYLSP_NEEDED
  YYLTYPE yylloc;
#endif
#endif

  YYSTYPE yyval;		/*  the variable used to return		*/
				/*  semantic values from the action	*/
				/*  routines				*/

  int yylen;

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Starting parse\n");
#endif

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY;		/* Cause a token to be read.  */

  /* Initialize stack pointers.
     Waste one element of value and location stack
     so that they stay on the same level as the state stack.
     The wasted elements are never initialized.  */

  yyssp = yyss - 1;
  yyvsp = yyvs;
#ifdef YYLSP_NEEDED
  yylsp = yyls;
#endif

/* Push a new state, which is found in  yystate  .  */
/* In all cases, when you get here, the value and location stacks
   have just been pushed. so pushing a state here evens the stacks.  */
yynewstate:

  *++yyssp = yystate;

  if (yyssp >= yyss + yystacksize - 1)
    {
      /* Give user a chance to reallocate the stack */
      /* Use copies of these so that the &'s don't force the real ones into memory. */
      YYSTYPE *yyvs1 = yyvs;
      short *yyss1 = yyss;
#ifdef YYLSP_NEEDED
      YYLTYPE *yyls1 = yyls;
#endif

      /* Get the current used size of the three stacks, in elements.  */
      int size = yyssp - yyss + 1;

#ifdef yyoverflow
      /* Each stack pointer address is followed by the size of
	 the data in use in that stack, in bytes.  */
#ifdef YYLSP_NEEDED
      /* This used to be a conditional around just the two extra args,
	 but that might be undefined if yyoverflow is a macro.  */
      yyoverflow("parser stack overflow",
		 &yyss1, size * sizeof (*yyssp),
		 &yyvs1, size * sizeof (*yyvsp),
		 &yyls1, size * sizeof (*yylsp),
		 &yystacksize);
#else
      yyoverflow("parser stack overflow",
		 &yyss1, size * sizeof (*yyssp),
		 &yyvs1, size * sizeof (*yyvsp),
		 &yystacksize);
#endif

      yyss = yyss1; yyvs = yyvs1;
#ifdef YYLSP_NEEDED
      yyls = yyls1;
#endif
#else /* no yyoverflow */
      /* Extend the stack our own way.  */
      if (yystacksize >= YYMAXDEPTH)
	{
	  yyerror("parser stack overflow");
	  return 2;
	}
      yystacksize *= 2;
      if (yystacksize > YYMAXDEPTH)
	yystacksize = YYMAXDEPTH;
      yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
      __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
      yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
      __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
#ifdef YYLSP_NEEDED
      yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
      __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
#endif
#endif /* no yyoverflow */

      yyssp = yyss + size - 1;
      yyvsp = yyvs + size - 1;
#ifdef YYLSP_NEEDED
      yylsp = yyls + size - 1;
#endif

#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Stack size increased to %d\n", yystacksize);
#endif

      if (yyssp >= yyss + yystacksize - 1)
	YYABORT;
    }

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Entering state %d\n", yystate);
#endif

  goto yybackup;
 yybackup:

/* Do appropriate processing given the current state.  */
/* Read a lookahead token if we need one and don't already have one.  */
/* yyresume: */

  /* First try to decide what to do without reference to lookahead token.  */

  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* yychar is either YYEMPTY or YYEOF
     or a valid token in external form.  */

  if (yychar == YYEMPTY)
    {
#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Reading a token: ");
#endif
      yychar = YYLEX;
    }

  /* Convert token to internal form (in yychar1) for indexing tables with */

  if (yychar <= 0)		/* This means end of input. */
    {
      yychar1 = 0;
      yychar = YYEOF;		/* Don't call YYLEX any more */

#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Now at end of input.\n");
#endif
    }
  else
    {
      yychar1 = YYTRANSLATE(yychar);

#if YYDEBUG != 0
      if (yydebug)
	{
	  fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
	  /* Give the individual parser a way to print the precise meaning
	     of a token, for further debugging info.  */
#ifdef YYPRINT
	  YYPRINT (stderr, yychar, yylval);
#endif
	  fprintf (stderr, ")\n");
	}
#endif
    }

  yyn += yychar1;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
    goto yydefault;

  yyn = yytable[yyn];

  /* yyn is what to do for this token type in this state.
     Negative => reduce, -yyn is rule number.
     Positive => shift, yyn is new state.
       New state is final state => don't bother to shift,
       just return success.
     0, or most negative number => error.  */

  if (yyn < 0)
    {
      if (yyn == YYFLAG)
	goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrlab;

  if (yyn == YYFINAL)
    YYACCEPT;

  /* Shift the lookahead token.  */

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
#endif

  /* Discard the token being shifted unless it is eof.  */
  if (yychar != YYEOF)
    yychar = YYEMPTY;

  *++yyvsp = yylval;
#ifdef YYLSP_NEEDED
  *++yylsp = yylloc;
#endif

  /* count tokens shifted since error; after three, turn off error status.  */
  if (yyerrstatus) yyerrstatus--;

  yystate = yyn;
  goto yynewstate;

/* Do the default action for the current state.  */
yydefault:

  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;

/* Do a reduction.  yyn is the number of a rule to reduce with.  */
yyreduce:
  yylen = yyr2[yyn];
  if (yylen > 0)
    yyval = yyvsp[1-yylen]; /* implement default value of the action */

#if YYDEBUG != 0
  if (yydebug)
    {
      int i;

      fprintf (stderr, "Reducing via rule %d (line %d), ",
	       yyn, yyrline[yyn]);

      /* Print the symbols being reduced, and their result.  */
      for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
	fprintf (stderr, "%s ", yytname[yyrhs[i]]);
      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
    }
#endif

$   /* the action file gets copied in in place of this dollarsign */
#line 465 "/vsta/lib/bison/bison.simple"
 
  yyvsp -= yylen;
  yyssp -= yylen;
#ifdef YYLSP_NEEDED
  yylsp -= yylen;
#endif

#if YYDEBUG != 0
  if (yydebug)
    {
      short *ssp1 = yyss - 1;
      fprintf (stderr, "state stack now");
      while (ssp1 != yyssp)
	fprintf (stderr, " %d", *++ssp1);
      fprintf (stderr, "\n");
    }
#endif

  *++yyvsp = yyval;

#ifdef YYLSP_NEEDED
  yylsp++;
  if (yylen == 0)
    {
      yylsp->first_line = yylloc.first_line;
      yylsp->first_column = yylloc.first_column;
      yylsp->last_line = (yylsp-1)->last_line;
      yylsp->last_column = (yylsp-1)->last_column;
      yylsp->text = 0;
    }
  else
    {
      yylsp->last_line = (yylsp+yylen-1)->last_line;
      yylsp->last_column = (yylsp+yylen-1)->last_column;
    }
#endif

  /* Now "shift" the result of the reduction.
     Determine what state that goes to,
     based on the state we popped back to
     and the rule number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTBASE];

  goto yynewstate;

yyerrlab:   /* here on detecting error */

  if (! yyerrstatus)
    /* If not already recovering from an error, report this error.  */
    {
      ++yynerrs;

#ifdef YYERROR_VERBOSE
      yyn = yypact[yystate];

      if (yyn > YYFLAG && yyn < YYLAST)
	{
	  int size = 0;
	  char *msg;
	  int x, count;

	  count = 0;
	  /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
	  for (x = (yyn < 0 ? -yyn : 0);
	       x < (sizeof(yytname) / sizeof(char *)); x++)
	    if (yycheck[x + yyn] == x)
	      size += strlen(yytname[x]) + 15, count++;
	  msg = (char *) malloc(size + 15);
	  if (msg != 0)
	    {
	      strcpy(msg, "parse error");

	      if (count < 5)
		{
		  count = 0;
		  for (x = (yyn < 0 ? -yyn : 0);
		       x < (sizeof(yytname) / sizeof(char *)); x++)
		    if (yycheck[x + yyn] == x)
		      {
			strcat(msg, count == 0 ? ", expecting `" : " or `");
			strcat(msg, yytname[x]);
			strcat(msg, "'");
			count++;
		      }
		}
	      yyerror(msg);
	      free(msg);
	    }
	  else
	    yyerror ("parse error; also virtual memory exceeded");
	}
      else
#endif /* YYERROR_VERBOSE */
	yyerror("parse error");
    }

  goto yyerrlab1;
yyerrlab1:   /* here on error raised explicitly by an action */

  if (yyerrstatus == 3)
    {
      /* if just tried and failed to reuse lookahead token after an error, discard it.  */

      /* return failure if at end of input */
      if (yychar == YYEOF)
	YYABORT;

#if YYDEBUG != 0
      if (yydebug)
	fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
#endif

      yychar = YYEMPTY;
    }

  /* Else will try to reuse lookahead token
     after shifting the error token.  */

  yyerrstatus = 3;		/* Each real token shifted decrements this */

  goto yyerrhandle;

yyerrdefault:  /* current state does not do anything special for the error token. */

#if 0
  /* This is wrong; only states that explicitly want error tokens
     should shift them.  */
  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  if (yyn) goto yydefault;
#endif

yyerrpop:   /* pop the current state because it cannot handle the error token */

  if (yyssp == yyss) YYABORT;
  yyvsp--;
  yystate = *--yyssp;
#ifdef YYLSP_NEEDED
  yylsp--;
#endif

#if YYDEBUG != 0
  if (yydebug)
    {
      short *ssp1 = yyss - 1;
      fprintf (stderr, "Error: state stack now");
      while (ssp1 != yyssp)
	fprintf (stderr, " %d", *++ssp1);
      fprintf (stderr, "\n");
    }
#endif

yyerrhandle:

  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    goto yyerrdefault;

  yyn += YYTERROR;
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
    goto yyerrdefault;

  yyn = yytable[yyn];
  if (yyn < 0)
    {
      if (yyn == YYFLAG)
	goto yyerrpop;
      yyn = -yyn;
      goto yyreduce;
    }
  else if (yyn == 0)
    goto yyerrpop;

  if (yyn == YYFINAL)
    YYACCEPT;

#if YYDEBUG != 0
  if (yydebug)
    fprintf(stderr, "Shifting error token, ");
#endif

  *++yyvsp = yylval;
#ifdef YYLSP_NEEDED
  *++yylsp = yylloc;
#endif

  yystate = yyn;
  goto yynewstate;
}

Added lib/magic.



































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
#! file
# Magic data for file(1) command.
# Machine-genererated from src/cmd/file/magdir/*; edit there only!
# Format is described in magic(files), where:
# files is 4 on V7 and BSD, 4 on SV, and ?? in the SVID.

#------------------------------------------------------------------------------
# Localstuff:  file(1) magic for locally observed files
#
# $Id$
# Add any locally observed files here.  Remember:
# text if readable, executable if runnable binary, data if unreadable.

#------------------------------------------------------------------------------
# adventure:  file(1) magic for Infocom (and other) adventure games
#
# Adventure game formats
#
# from Allen Garvin <earendil@faeryland.tamu-commerce.edu>
# Edited by Dave Chapeskie <dchapes@ddm.on.ca> Jun 28, 1998
#
# Contributed to FreeBSD by Lyndon Nerenberg <lyndon@orthanc.ab.ca>
# This file was taken from the Interactive Fiction archives at
# ftp://ftp.gmd.de/if-archive/ (*the* place for text based
# adventure games from a by-gone era). Please send me updates and
# I'll make sure they get back to the GMD archives. (1998 AUG 1)
#
# ALAN
# I assume there are other, lower versions, but these are the only ones I
# saw in the archive.
#
0	beshort	0x0206	ALAN text adventure code data
>2	byte	<10	version 2.6%d
#
# Infocom
#
# (Note: to avoid false matches Z-machine version 1 and 2 are not
# recognized since only the oldest Zork I and II used them.  Similarly
# there are 4 Infocom games that use verion 4 that are not recognized.)
#
0	byte	3	Infocom game data (Z-machine 3,
>2	beshort	<0x7fff	Release %3d,
#>26	beshort >0	Size %d*2
>18	string	>\0	Serial %.6s)
0	byte	5	Infocom game data (Z-machine 5,
>2	beshort	<0x7fff	Release %3d,
#>26	beshort >0	Size %d*4
>18	string	>\0	Serial %.6s)
0	byte	6	Infocom game data (Z-machine 6,
>2	beshort	<0x7fff	Release %3d,
#>26	beshort >0	Size %d*8
>18	string	>\0	Serial %.6s)
0	byte	8	Infocom game data (Z-machine 8,
>2	beshort	<0x7fff	Release %3d,
#>26	beshort >0	Size %d*8
>18	string	>\0	Serial %.6s)
#
# TADS (Text Adventure Development System)
#
0	string	TADS	TADS adventure game data
>13	string	>\0	(ver. %.6s,
>22	string	>\0	date %s)

#------------------------------------------------------------------------------
# alliant:  file(1) magic for Alliant FX series a.out files
#
# If the FX series is the one that had a processor with a 68K-derived
# instruction set, the "short" should probably become "beshort" and the
# "long" should probably become "belong".
# If it's the i860-based one, they should probably become either the
# big-endian or little-endian versions, depending on the mode they ran
# the 860 in....
#
0	short		0420		0420 Alliant virtual executable
>2	short		&0x0020		common library
>16	long		>0		not stripped
0	short		0421		0421 Alliant compact executable
>2	short		&0x0020		common library
>16	long		>0		not stripped
#------------------------------------------------------------------------------
# alpha architecture description
#

0	leshort		0603		COFF format alpha
>22	leshort&030000	!020000		executable
>24	leshort		0410		pure
>24	leshort		0413		paged
>22	leshort&020000	!0		dynamically linked
>16	lelong		!0		not stripped
>16	lelong		0		stripped
>22	leshort&030000	020000		shared library
>24	leshort		0407		object
>27	byte		x		- version %d
>26	byte		x		.%d
>28	byte		x		-%d

# Basic recognition of OSF/1 core dumps - Mike Bremford <mike@opac.bl.uk>
#
0	string		Core\001	COFF format core dump (OSF/1)
>24	string		>\0		generated by '%s'
#------------------------------------------------------------------------------
# amanda:  file(1) magic for amanda file format
#
0       string          AMANDA:\ TAPESTART\ DATE     AMANDA dump header file,
>23     string          X
>>25    string          >\                           Unused %s
>23     string          >\                           DATE %s
#------------------------------------------------------------------------------
# amigaos:  file(1) magic for AmigaOS binary formats:

#
# From ignatios@cs.uni-bonn.de (Ignatios Souvatzis)
# Some formats are still missing: AmigaOS special IFF's, e.g.: FORM....CTLG
# (the others should be seperate, anyway)
#
0	belong		0x000003f3	AmigaOS loadseg()ble executable/binary
0	belong		0x000003e7	AmigaOS object/library data

#------------------------------------------------------------------------------
# animation:  file(1) magic for animation/movie formats
#
# animation formats
# MPEG, FLI, DL originally from vax@ccwf.cc.utexas.edu (VaX#n8)
# FLC, SGI, Apple originally from Daniel Quinlan (quinlan@yggdrasil.com)

# MPEG animation format
0	belong		0x000001b3		Mpeg video stream data
#>4	beshort&0xfff0	x			(%d x
#>5	beshort&0x0fff  x			%d)
0	belong		0x000001ba		Mpeg system stream data
0	beshort&0xfff0	0xfff0			Mpeg audio stream data

# FLI animation format
4	leshort		0xAF11			FLI file
>6	leshort		x			- %d frames,
>8	leshort		x			width=%d pixels,
>10	leshort		x			height=%d pixels,
>12	leshort		x			depth=%d,
>16	leshort		x			ticks/frame=%d
# FLC animation format
4	leshort		0xAF12			FLC file
>6	leshort		x			- %d frames
>8	leshort		x			width=%d pixels,
>10	leshort		x			height=%d pixels,
>12	leshort		x			depth=%d,
>16	leshort		x			ticks/frame=%d

# DL animation format
# XXX - collision with most `mips' magic
#
# I couldn't find a real magic number for these, however, this
# -appears- to work.  Note that it might catch other files, too, so be
# careful!
#
# Note that title and author appear in the two 20-byte chunks
# at decimal offsets 2 and 22, respectively, but they are XOR'ed with
# 255 (hex FF)!  The DL format is really bad.
#
#0	byte	1	DL version 1, medium format (160x100, 4 images/screen)
#>42	byte	x	- %d screens,
#>43	byte	x	%d commands
#0	byte	2	DL version 2
#>1	byte	1	- large format (320x200,1 image/screen),
#>1	byte	2	- medium format (160x100,4 images/screen),
#>1	byte	>2	- unknown format,
#>42	byte	x	%d screens,
#>43	byte	x	%d commands
# Based on empirical evidence, DL version 3 have several nulls following the
# \003.  Most of them start with non-null values at hex offset 0x34 or so.
#0	string	\3\0\0\0\0\0\0\0\0\0\0\0	DL version 3

# SGI and Apple formats
0	string		MOVI		Silicon Graphics movie file
4	string		moov		Apple QuickTime movie file (moov)
4	string		mdat		Apple QuickTime movie file (mdat)

#------------------------------------------------------------------------------
# apl:  file(1) magic for APL (see also "pdp" and "vax" for other APL
#       workspaces)
#
0	long		0100554		APL workspace (Ken's original?)

#------------------------------------------------------------------------------
# apple:  file(1) magic for Apple II file formats
#
0	string		FiLeStArTfIlEsTaRt	binscii (apple ][) text
0	string		\x0aGL			Binary II (apple ][) data
0	string		\x76\xff		Squeezed (apple ][) data
0	string		SIT!			StuffIt (macintosh) text
0	string		NuFile			NuFile archive (apple ][) data
0	string		N\xf5F\xe9l\xe5		NuFile archive (apple ][) data
#
# "ar", for all kinds of archives.
#
# XXX - why are there multiple <ar> thingies?  Note that 0x213c6172 is
# "!<ar", so, for new-style (4.xBSD/SVR2andup) archives, we have:
#
# 0	string		!<arch>		current ar archive
# 0	long		0x213c6172	archive file
#
# and for SVR3.1 archives, we have:
#
# 0	string		\<ar>		System V Release 1 ar archive
# 0	string		=<ar>		archive
# 0	string		=<ar>		archive
#
# XXX - did Aegis really store shared libraries, breakpointed modules,
# and absolute code program modules in the same format as new-style
# "ar" archives?
#
0	string		!<arch>		current ar archive
>8	string		__.SYMDEF	random library
>0	belong		=65538		- pre SR9.5
>0	belong		=65539		- post SR9.5
>0	beshort		2		- object archive
>0	beshort		3		- shared library module
>0	beshort		4		- debug break-pointed module
>0	beshort		5		- absolute code program module
0	string		\<ar>		System V Release 1 ar archive
0	string		=<ar>		archive
#
# XXX - from "vax", which appears to collect a bunch of byte-swapped
# thingies, to help you recognize VAX files on big-endian machines;
# with "leshort", "lelong", and "string", that's no longer necessary....
#
# 0	long		0x3c61723e	VAX 5.0 archive
#
0	long		0x213c6172	archive file
0	lelong		0177555		very old VAX archive
0	leshort		0177555		very old PDP-11 archive
#
# XXX - "pdp" claims that 0177545 can have an __.SYMDEF member and thus
# be a random library (it said 0xff65 rather than 0177545).
#
0	lelong		0177545		old VAX archive
>8	string		__.SYMDEF	random library
0	leshort		0177545		old PDP-11 archive
>8	string		__.SYMDEF	random library
#
0	string		=<ar>		archive
#
# From "pdp":
#
0	lelong		0x39bed		PDP-11 old archive
0	lelong		0x39bee		PDP-11 4.0 archive
#
0	string		-h-		Software Tools format archive text
# "arc" archiver
0	byte		26		'arc' archive
>1	byte		0		(empty)
>1	byte		1		(old format)
# Rahul Dhesi's zoo archive format, from keith@cerberus.uchicago.edu.
20	long		0xdca7c4fd	Rahul Dhesi's "zoo" archive
# ZIP archiver
0	string		PK		zip archive file 
>4	byte		x		- version
>4	byte		10		1.0
>4	byte		20		2.0

2	string		-lh		LHarc archive data
>6	byte		x		type %c
>20	byte		x		- header level %d

# From: <u31b3hs@pool.informatik.rwth-aachen.de> (Michael Haardt)
2	string		-lh0-		Lharc 1.x archive
2	string		-lh1-		Lharc 1.x archive
2	string		-lz4-		Lharc 1.x archive
2	string		-lz5-		Lharc 1.x archive
2	string		-lzs-		LHa 2.x? archive [lzs]
2	string		-lh -		LHa 2.x? archive [lh ]
2	string		-lhd-		LHa 2.x? archive [lhd]
2	string		-lh2-		LHa 2.x? archive [lh2]
2	string		-lh3-		LHa 2.x? archive [lh3]
2	string		-lh4-		LHa 2.x? archive [lh4]
2	string		-lh5-		LHa (2.x) archive

# ARJ archive data from jason@jarthur.Claremont.EDU
0	leshort		0xea60		ARJ archive data
>5	byte		x		- version %d,
>8	byte		>0		flags:
>>8	byte		&0x04		multi-volume,
>>8	byte		&0x10		slash switched,
>>8	byte		&0x20		backup,
>34	string		x		original name: %s,
>7	byte		0		os: MS/DOS
>7	byte		1		os: PRIMOS
>7	byte		2		os: UNIX
>7	byte		3		os: Amiga
>7	byte		4		os: Macintosh
>7	byte		5		os: OS/2
>7	byte		6		os: Apple ][ GS
>7	byte		7		os: Atari ST
>7	byte		8		os: NeXT
>7	byte		9		os: VAX/VMS
>3	byte		>0		%d]
0	byte		26		'arc' archive
>1	byte		0		(empty)
>1	byte		1		(old format)

#------------------------------------------------------------------------------
# archive:  file(1) magic for archive formats (see also "msdos" for self-
#           extracting compressed archives)
#
# cpio, ar, arc, arj, hpack, lha/lharc, rar, squish, uc2, zip, zoo, etc.
# pre-POSIX "tar" archives are handled in the C code.

# POSIX tar archives
257	string		ustar\0		POSIX tar archive
257	string		ustar\040\040\0	GNU tar archive

# cpio archives
#
# Yes, the top two "cpio archive" formats *are* supposed to just be "short".
# The idea is to indicate archives produced on machines with the same
# byte order as the machine running "file" with "cpio archive", and
# to indicate archives produced on machines with the opposite byte order
# from the machine running "file" with "byte-swapped cpio archive".
#
# The SVR4 "cpio(4)" hints that there are additional formats, but they
# are defined as "short"s; I think all the new formats are
# character-header formats and thus are strings, not numbers.
0	short		070707		cpio archive
0	short		0143561		byte-swapped cpio archive
0	string		070707		ASCII cpio archive (pre-SVR4 or odc)
0	string		070701		ASCII cpio archive (SVR4 with no CRC)
0	string		070702		ASCII cpio archive (SVR4 with CRC)

# other archives
0	long		0177555		very old archive
0	short		0177555		very old PDP-11 archive
0	long		0177545		old archive
0	short		0177545		old PDP-11 archive
0	long		0100554		apl workspace
0	string		=<ar>		archive

# MIPS archive (needs to go first)
#
0	string	!<arch>\n__________E	MIPS archive
>20	string	U			with MIPS Ucode members
>21	string	L			with MIPSEL members
>21	string	B			with MIPSEB members
>19	string	L			and an EL hash table
>19	string	B			and an EB hash table
>22	string	X			-- out of date

0	string		-h-		Software Tools format archive text

#
# XXX - why are there multiple <ar> thingies?  Note that 0x213c6172 is
# "!<ar", so, for new-style (4.xBSD/SVR2andup) archives, we have:
#
# 0	string		!<arch>		current ar archive
# 0	long		0x213c6172	archive file
#
# and for SVR1 archives, we have:
#
# 0	string		\<ar>		System V Release 1 ar archive
# 0	string		=<ar>		archive
#
# XXX - did Aegis really store shared libraries, breakpointed modules,
# and absolute code program modules in the same format as new-style
# "ar" archives?
#
0	string		!<arch>		current ar archive
>8	string		__.SYMDEF	random library
>8	string		debian-split	part of multipart Debian package
>8	string		debian-binary	Debian binary package
>0	belong		=65538		- pre SR9.5
>0	belong		=65539		- post SR9.5
>0	beshort		2		- object archive
>0	beshort		3		- shared library module
>0	beshort		4		- debug break-pointed module
>0	beshort		5		- absolute code program module
0	string		\<ar>		System V Release 1 ar archive
0	string		=<ar>		archive
#
# XXX - from "vax", which appears to collect a bunch of byte-swapped
# thingies, to help you recognize VAX files on big-endian machines;
# with "leshort", "lelong", and "string", that's no longer necessary....
#
0	belong		0x65ff0000	VAX 3.0 archive
0	belong		0x3c61723e	VAX 5.0 archive
#
0	long		0x213c6172	archive file
0	lelong		0177555		very old VAX archive
0	leshort		0177555		very old PDP-11 archive
#
# XXX - "pdp" claims that 0177545 can have an __.SYMDEF member and thus
# be a random library (it said 0xff65 rather than 0177545).
#
0	lelong		0177545		old VAX archive
>8	string		__.SYMDEF	random library
0	leshort		0177545		old PDP-11 archive
>8	string		__.SYMDEF	random library
#
# From "pdp" (but why a 4-byte quantity?)
#
0	lelong		0x39bed		PDP-11 old archive
0	lelong		0x39bee		PDP-11 4.0 archive

# ARC archiver, from Daniel Quinlan (quinlan@yggdrasil.com)
#
# The first byte is the magic (0x1a), byte 2 is the compression type for
# the first file (0x01 through 0x09), and bytes 3 to 15 are the MS-DOS
# filename of the first file (null terminated).  Since some types collide
# we only test some types on basis of frequency: 0x08 (83%), 0x09 (5%),
# 0x02 (5%), 0x03 (3%), 0x04 (2%), 0x06 (2%).  0x01 collides with terminfo.
0	lelong&0x8080ffff	0x0000081a	ARC archive data, dynamic LZW
0	lelong&0x8080ffff	0x0000091a	ARC archive data, squashed
0	lelong&0x8080ffff	0x0000021a	ARC archive data, uncompressed
0	lelong&0x8080ffff	0x0000031a	ARC archive data, packed
0	lelong&0x8080ffff	0x0000041a	ARC archive data, squeezed
0	lelong&0x8080ffff	0x0000061a	ARC archive data, crunched

# Acorn archive formats (Disaster prone simpleton, m91dps@ecs.ox.ac.uk)
# I can't create either SPARK or ArcFS archives so I have not tested this stuff
# [GRR:  the original entries collide with ARC, above; replaced with combined
#  version (not tested)]
#0	byte		0x1a		RISC OS archive
#>1	string		archive		(ArcFS format)
0	string		\032archive	RISC OS archive (ArcFS format)

# ARJ archiver (jason@jarthur.Claremont.EDU)
0	leshort		0xea60		ARJ archive data
>5	byte		x		\b, v%d,
>8	byte		&0x04		multi-volume,
>8	byte		&0x10		slash-switched,
>8	byte		&0x20		backup,
>34	string		x		original name: %s,
>7	byte		0		os: MS-DOS
>7	byte		1		os: PRIMOS
>7	byte		2		os: Unix
>7	byte		3		os: Amiga
>7	byte		4		os: Macintosh
>7	byte		5		os: OS/2
>7	byte		6		os: Apple ][ GS
>7	byte		7		os: Atari ST
>7	byte		8		os: NeXT
>7	byte		9		os: VAX/VMS
>3	byte		>0		%d]

# HA archiver (Greg Roelofs, newt@uchicago.edu)
# This is a really bad format. A file containing HAWAII will match this...
#0	string		HA		HA archive data,
#>2	leshort		=1		1 file,
#>2	leshort		>1		%u files,
#>4	byte&0x0f	=0		first is type CPY
#>4	byte&0x0f	=1		first is type ASC
#>4	byte&0x0f	=2		first is type HSC
#>4	byte&0x0f	=0x0e		first is type DIR
#>4	byte&0x0f	=0x0f		first is type SPECIAL

# HPACK archiver (Peter Gutmann, pgut1@cs.aukuni.ac.nz)
0	string		HPAK		HPACK archive data

# JAM Archive volume format, by Dmitry.Kohmanyuk@UA.net
0	string		\351,\001JAM\		JAM archive,
>7	string		>\0			version %.4s
>0x26	byte		=0x27			-
>>0x2b	string          >\0			label %.11s,
>>0x27	lelong		x			serial %08x,
>>0x36	string		>\0			fstype %.8s

# LHARC/LHA archiver (Greg Roelofs, newt@uchicago.edu)
2	string		-lh0-		LHarc 1.x archive data [lh0]
2	string		-lh1-		LHarc 1.x archive data [lh1]
2	string		-lz4-		LHarc 1.x archive data [lz4]
2	string		-lz5-		LHarc 1.x archive data [lz5]
#	[never seen any but the last; -lh4- reported in comp.compression:]
2	string		-lzs-		LHa 2.x? archive data [lzs]
2	string		-lh -		LHa 2.x? archive data [lh ]
2	string		-lhd-		LHa 2.x? archive data [lhd]
2	string		-lh2-		LHa 2.x? archive data [lh2]
2	string		-lh3-		LHa 2.x? archive data [lh3]
2	string		-lh4-		LHa (2.x) archive data [lh4]
2	string		-lh5-		LHa (2.x) archive data [lh5]
>20	byte		x		- header level %d

# RAR archiver (Greg Roelofs, newt@uchicago.edu)
0	string		Rar!		RAR archive data

# SQUISH archiver (Greg Roelofs, newt@uchicago.edu)
0	string		SQSH		squished archive data (Acorn RISCOS)

# UC2 archiver (Greg Roelofs, newt@uchicago.edu)
# I can't figure out the self-extracting form of these buggers...
0	string		UC2\x1a		UC2 archive data

# ZIP archives (Greg Roelofs, c/o zip-bugs@wkuvx1.wku.edu)
0	string		PK\003\004	Zip archive data
>4	byte		0x09		\b, at least v0.9 to extract
>4	byte		0x0a		\b, at least v1.0 to extract
>4	byte		0x0b		\b, at least v1.1 to extract
>4	byte		0x14		\b, at least v2.0 to extract

# Zoo archiver
20	lelong		0xfdc4a7dc	Zoo archive data
>4	byte		>48		\b, v%c.
>>6	byte		>47		\b%c
>>>7	byte		>47		\b%c
>32	byte		>0		\b, modify: v%d
>>33	byte		x		\b.%d+
>42	lelong		0xfdc4a7dc	\b,
>>70	byte		>0		extract: v%d
>>>71	byte		x		\b.%d+

# Shell archives
10	string		#\ This\ is\ a\ shell\ archive	shell archive text

#------------------------------------------------------------------------------
# asterix:  file(1) magic for Aster*x; SunOS 5.5.1 gave the 4-character
# strings as "long" - we assume they're just strings:
# From: guy@netapp.com (Guy Harris)
#
0	string		*STA		Aster*x
>7	string		WORD			Words Document
>7	string		GRAP			Graphic
>7	string		SPRE			Spreadsheet
>7	string		MACR			Macro
0	string		2278		Aster*x Version 2
>29	byte		0x36			Words Document
>29	byte		0x35			Graphic
>29	byte		0x32			Spreadsheet
>29	byte		0x38			Macro


#------------------------------------------------------------------------------
# att3b:  file(1) magic for AT&T 3B machines
#
# The `versions' should be un-commented if they work for you.
# (Was the problem just one of endianness?)
#
# 3B20
#
0	beshort		0550		3b20 COFF executable
>12	belong		>0		not stripped
#>22	beshort		>0		- version %ld
0	beshort		0551		3b20 COFF executable (TV)
>12	belong		>0		not stripped
#>22	beshort		>0		- version %ld
#
# WE32K
#
0	beshort		0560		WE32000 COFF
>18	beshort		^00000020	object
>18	beshort		&00000020	executable
>12	belong		>0		not stripped
>18	beshort		^00010000	N/A on 3b2/300 w/paging
>18	beshort		&00020000	32100 required
>18	beshort		&00040000	and MAU hardware required
>20	beshort		0407		(impure)
>20	beshort		0410		(pure)
>20	beshort		0413		(demand paged)
>20	beshort		0443		(target shared library)
>22	beshort		>0		- version %ld
0	beshort		0561		WE32000 COFF executable (TV)
>12	belong		>0		not stripped
#>18	beshort		&00020000	- 32100 required
#>18	beshort		&00040000	and MAU hardware required
#>22	beshort		>0		- version %ld
#
# core file for 3b2 
0	string		\000\004\036\212\200	3b2 core file
>364	string		>\0		of '%s'

#------------------------------------------------------------------------------
# audio:  file(1) magic for sound formats (see also "iff")
#
# Jan Nicolai Langfeldt (janl@ifi.uio.no), Dan Quinlan (quinlan@yggdrasil.com),
# and others
#

# Sun/NeXT audio data
0	string		.snd		Sun/NeXT audio data:
>12	belong		1		8-bit ISDN u-law,
>12	belong		2		8-bit linear PCM [REF-PCM],
>12	belong		3		16-bit linear PCM,
>12	belong		4		24-bit linear PCM,
>12	belong		5		32-bit linear PCM,
>12	belong		6		32-bit IEEE floating point,
>12	belong		7		64-bit IEEE floating point,
>12	belong		23		8-bit ISDN u-law compressed (CCITT G.721 ADPCM voice data encoding),
>12	belong		24		compressed (8-bit G.722 ADPCM)
>12	belong		25		compressed (3-bit G.723 ADPCM),
>12	belong		26		compressed (5-bit G.723 ADPCM),
>12	belong		27		8-bit A-law,
>20	belong		1		mono,
>20	belong		2		stereo,
>20	belong		4		quad,
>16	belong		>0		%d Hz

# DEC systems (e.g. DECstation 5000) use a variant of the Sun/NeXT format
# that uses little-endian encoding and has a different magic number
0	lelong		0x0064732E	DEC audio data:
>12	lelong		1		8-bit ISDN u-law,
>12	lelong		2		8-bit linear PCM [REF-PCM],
>12	lelong		3		16-bit linear PCM,
>12	lelong		4		24-bit linear PCM,
>12	lelong		5		32-bit linear PCM,
>12	lelong		6		32-bit IEEE floating point,
>12	lelong		7		64-bit IEEE floating point,
>12	lelong		23		8-bit ISDN u-law compressed (CCITT G.721 ADPCM voice data encoding),
>20	lelong		1		mono,
>20	lelong		2		stereo,
>20	lelong		4		quad,
>16	lelong		>0		%d Hz

# Creative Labs AUDIO stuff
0	string	MThd			Standard MIDI data
>9 	byte	>0			(format %d)
>11	byte	>1			using %d channels
0	string	CTMF			Creative Music (CMF) data
0	string	SBI			SoundBlaster instrument data
0	string	Creative\ Voice\ File	Creative Labs voice data
# is this next line right?  it came this way...
>19	byte	0x1A
>23	byte	>0			- version %d
>22	byte	>0			\b.%d

# first entry is also the string "NTRK"
0	belong		0x4e54524b	MultiTrack sound data
>4	belong		x		- version %ld

# Microsoft WAVE format (*.wav)
0	string		RIFF		Microsoft RIFF
>8	string		WAVE		\b, WAVE audio data
>>34	leshort		>0		\b, %d bit
>>22	leshort		=1		\b, mono
>>22	leshort		=2		\b, stereo
>>22	leshort		>2		\b, %d channels
>>24	lelong		>0		%d Hz
# AVI == Audio Video Interleave
>8      string          AVI\            \b, AVI data

# Extended MOD format (*.emd) (Greg Roelofs, newt@uchicago.edu); NOT TESTED
# [based on posting 940824 by "Dirk/Elastik", husberg@lehtori.cc.tut.fi]
0	string		EMOD		Extended MOD sound data,
>4	byte&0xf0	x		version %d
>4	byte&0x0f	x		\b.%d,
>45	byte		x		%d instruments
>83	byte		0		(module)
>83	byte		1		(song)

# Real Audio (Magic .ra\0375)
0	belong		0x2e7261fd	realaudio sound file

# MTM/669/FAR/S3M/ULT/XM format checking [Aaron Eppert, aeppert@dialin.ind.net]
# Oct 31, 1995
0	string		MTM		MultiTracker Module sound file
0	string		if		Composer 669 Module sound data
0	string		FAR		Module sound data
0	string		MAS_U		ULT(imate) Module sound data
0x2c	string		SCRM		ScreamTracker III Module sound data
0	string		Extended Module	Extended Module sound data

# Gravis UltraSound patches
# From <ache@nagual.ru>

0	string		GF1PATCH110\0ID#000002\0	GUS patch
0	string		GF1PATCH100\0ID#000002\0	Old GUS	patch

#------------------------------------------------------------------------------
# blit:  file(1) magic for 68K Blit stuff as seen from 680x0 machine
#
# Note that this 0407 conflicts with several other a.out formats...
#
# XXX - should this be redone with "be" and "le", so that it works on
# little-endian machines as well?  If so, what's the deal with
# "VAX-order" and "VAX-order2"?
#
#0	long		0407		68K Blit (standalone) executable
#0	short		0407		VAX-order2 68K Blit (standalone) executable
0	short		03401		VAX-order 68K Blit (standalone) executable
0	long		0406		68k Blit mpx/mux executable
0	short		0406		VAX-order2 68k Blit mpx/mux executable
0	short		03001		VAX-order 68k Blit mpx/mux executable
# Need more values for WE32 DMD executables.
# Note that 0520 is the same as COFF
#0	short		0520		tty630 layers executable

#------------------------------------------------------------------------------
# bsdi:  file(1) magic for BSD/OS (from BSDI) objects
#
0	lelong			000000314	BSD/OS i386 compact demand paged executable
>16	lelong			>0		not stripped
>32	byte			0x6a		(uses shared libs)
# bzip	a block-sorting file compressor
#	by Julian Seward <sewardj@cs.man.ac.uk> and others
#
0	string		BZ		bzip compressed data
>2	byte		x		\b, version: %c
>3	string		=1		\b, compression block size 100k
>3	string		=2		\b, compression block size 200k
>3	string		=3		\b, compression block size 300k
>3	string		=4		\b, compression block size 400k
>3	string		=5		\b, compression block size 500k
>3	string		=6		\b, compression block size 600k
>3	string		=7		\b, compression block size 700k
>3	string		=8		\b, compression block size 800k
>3	string		=9		\b, compression block size 900k

#------------------------------------------------------------------------------
# c-lang:  file(1) magic for C programs (or REXX)
#

# XPM icons (Greg Roelofs, newt@uchicago.edu)
# if you uncomment "/*" for C/REXX below, also uncomment this entry
#0	string		/*\ XPM\ */	X pixmap image data

# this first will upset you if you're a PL/1 shop...
# in which case rm it; ascmagic will catch real C programs
#0	string		/*		C or REXX program text
0	string		//		C++ program text

#------------------------------------------------------------------------------
# chi:  file(1) magic for ChiWriter files
#
0       string          \\1cw\          ChiWriter file
>5      string          >\0             version %s
0       string          \\1cw           ChiWriter file

#------------------------------------------------------------------------------
# clipper:  file(1) magic for Intergraph (formerly Fairchild) Clipper.
#
# XXX - what byte order does the Clipper use?
#
# XXX - what's the "!" stuff:
#
# >18	short		!074000,000000	C1 R1 
# >18	short		!074000,004000	C2 R1
# >18	short		!074000,010000	C3 R1
# >18	short		!074000,074000	TEST
#
# I shall assume it's ANDing the field with the first value and
# comparing it with the second, and rewrite it as:
#
# >18	short&074000	000000		C1 R1 
# >18	short&074000	004000		C2 R1
# >18	short&074000	010000		C3 R1
# >18	short&074000	074000		TEST
#
# as SVR3.1's "file" doesn't support anything of the "!074000,000000"
# sort, nor does SunOS 4.x, so either it's something Intergraph added
# in CLIX, or something AT&T added in SVR3.2 or later, or something
# somebody else thought was a good idea; it's not documented in the
# man page for this version of "magic", nor does it appear to be
# implemented (at least not after I blew off the bogus code to turn
# old-style "&"s into new-style "&"s, which just didn't work at all).
#
0	short		0575		CLIPPER COFF executable (VAX #)
>20	short		0407		(impure)
>20	short		0410		(5.2 compatible)
>20	short		0411		(pure)
>20	short		0413		(demand paged)
>20	short		0443		(target shared library)
>12	long		>0		not stripped
>22	short		>0		- version %ld
0	short		0577		CLIPPER COFF executable
>18	short&074000	000000		C1 R1 
>18	short&074000	004000		C2 R1
>18	short&074000	010000		C3 R1
>18	short&074000	074000		TEST
>20	short		0407		(impure)
>20	short		0410		(pure)
>20	short		0411		(separate I&D)
>20	short		0413		(paged)
>20	short		0443		(target shared library)
>12	long		>0		not stripped
>22	short		>0		- version %ld
>48	long&01		01		alignment trap enabled
>52	byte		1		-Ctnc
>52	byte		2		-Ctsw
>52	byte		3		-Ctpw
>52	byte		4		-Ctcb
>53	byte		1		-Cdnc
>53	byte		2		-Cdsw
>53	byte		3		-Cdpw
>53	byte		4		-Cdcb
>54	byte		1		-Csnc
>54	byte		2		-Cssw
>54	byte		3		-Cspw
>54	byte		4		-Cscb
4	string		pipe		CLIPPER instruction trace
4	string		prof		CLIPPER instruction profile

#------------------------------------------------------------------------------
# commands:  file(1) magic for various shells and interpreters
#
0	string		:\ shell archive or commands for antique kernel text
0	string		#!/bin/sh		Bourne shell script text
0	string		#!\ /bin/sh		Bourne shell script text
0	string		#!/bin/csh		C shell script text
0	string		#!\ /bin/csh		C shell script text
# korn shell magic, sent by George Wu, gwu@clyde.att.com
0	string		#!/bin/ksh		Korn shell script text
0	string		#!\ /bin/ksh		Korn shell script text
0	string	 	#!/bin/tcsh		Tenex C shell script text
0	string	 	#!\ /bin/tcsh		Tenex C shell script text
0	string		#!/usr/local/tcsh	Tenex C shell script text
0	string	 	#!\ /usr/local/tcsh	Tenex C shell script text
0	string		#!/usr/local/bin/tcsh	Tenex C shell script text
0	string		#!\ /usr/local/bin/tcsh	Tenex C shell script text
#
# zsh/ash/ae/nawk/gawk magic from cameron@cs.unsw.oz.au (Cameron Simpson)
0	string		#!/usr/local/bin/zsh	Z shell script text
0	string		#!\ /usr/local/bin/zsh	Z shell script text
0	string		#!/usr/local/bin/ash	Neil Brown's ash
0	string		#!\ /usr/local/bin/ash	Neil Brown's ash
0	string		#!/usr/local/bin/ae	Neil Brown's ae
0	string		#!\ /usr/local/bin/ae	Neil Brown's ae
0	string		#!/bin/nawk		new awk script text
0	string		#!\ /bin/nawk		new awk script text
0	string		#!/usr/bin/nawk		new awk script text
0	string		#!\ /usr/bin/nawk	new awk script text
0	string		#!/usr/local/bin/nawk	new awk script text
0	string		#!\ /usr/local/bin/nawk	new awk script text
0	string		#!/bin/gawk		GNU awk script text
0	string		#!\ /bin/gawk		GNU awk script text
0	string		#!/usr/bin/gawk		GNU awk script text
0	string		#!\ /usr/bin/gawk	GNU awk script text
0	string		#!/usr/local/bin/gawk	GNU awk script text
0	string		#!\ /usr/local/bin/gawk	GNU awk script text
#
0	string		#!/bin/awk		awk commands text
0	string		#!\ /bin/awk		awk commands text
0	string		#!/usr/bin/awk		awk commands text
0	string		#!\ /usr/bin/awk	awk commands text
0	string		BEGIN			awk commands text

# For Larry Wall's perl language.  The ``eval'' line recognizes an
# outrageously clever hack for USG systems.
#				Keith Waclena <keith@cerberus.uchicago.edu>
0	string		#!/bin/perl			perl commands text
0	string		#!\ /bin/perl			perl commands text
0	string		eval\ "exec\ /bin/perl		perl commands text
0	string		#!/usr/bin/perl			perl commands text
0	string		#!\ /usr/bin/perl		perl commands text
0	string		eval\ "exec\ /usr/bin/perl	perl commands text
0	string		#!/usr/local/bin/perl		perl commands text
0	string		#!\ /usr/local/bin/perl		perl commands text
0	string		eval\ "exec\ /usr/local/bin/perl	perl commands text

# AT&T Bell Labs' Plan 9 shell
0	string		#!/bin/rc	Plan 9 rc shell script text
0	string		#!\ /bin/rc	Plan 9 rc shell script text

# bash shell magic, from Peter Tobias (tobias@server.et-inf.fho-emden.de)
0	string		#!/bin/bash	Bourne-Again shell script text
0	string		#!\ /bin/bash	Bourne-Again shell script text
0	string		#!/usr/local/bin/bash	Bourne-Again shell script text
0	string		#!\ /usr/local/bin/bash	Bourne-Again shell script text

# generic shell magic
0	string		#!\ /			a
>3	string		>\0			%s script text
0	string		#!/			a
>2	string		>\0			%s script text
0	string		#!\ 			commands text
>3	string		>\0			for %s

#------------------------------------------------------------------------------
# compress:  file(1) magic for pure-compression formats (no archives)
#
# compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc.
#
# Formats for various forms of compressed data
# Formats for "compress" proper have been moved into "compress.c",
# because it tries to uncompress it to figure out what's inside.

# standard unix compress
0	string		\037\235	compress'd data
>2	byte&0x80	>0		block compressed
>2	byte&0x1f	x		%d bits

# gzip (GNU zip, not to be confused with Info-ZIP or PKWARE zip archiver)
0       string          \037\213        gzip compressed data
>2      byte            <8              \b, reserved method,
>2      byte            8               \b, deflated,
>3	byte		&0x01		ASCII,
>3	byte		&0x02		continuation,
>3	byte		&0x04		extra field,
>3	byte		&0x08		original filename,
>3	byte		&0x10		comment,
>3	byte		&0x20		encrypted,
>4	ledate		x		last modified: %s,
>8	byte		2		max compression,
>8	byte		4		max speed,
>9	byte		=0x00		os: MS-DOS
>9	byte		=0x01		os: Amiga
>9	byte		=0x02		os: VMS
>9	byte		=0x03		os: Unix
>9	byte		=0x05		os: Atari
>9	byte		=0x06		os: OS/2
>9	byte		=0x07		os: MacOS
>9	byte		=0x0A		os: Tops/20
>9	byte		=0x0B		os: Win/32

# packed data, Huffman (minimum redundancy) codes on a byte-by-byte basis
0	string		\037\036	packed data
>2	belong		>1		\b, %d characters originally
>2	belong		=1		\b, %d character originally
#
# This magic number is byte-order-independent.  XXX - Does that mean this
# is big-endian, little-endian, either, or that you can't tell?
# this short is valid for SunOS
0	short		017437		old packed data

# XXX - why *two* entries for "compacted data", one of which is
# byte-order independent, and one of which is byte-order dependent?
#
0	short		0x1fff		compacted data
# This string is valid for SunOS (BE) and a matching "short" is listed
# in the Ultrix (LE) magic file.
0	string		\377\037	compacted data
0	short		0145405		huf output

# Squeeze and Crunch...
# These numbers were gleaned from the Unix versions of the programs to
# handle these formats.  Note that I can only uncrunch, not crunch, and
# I didn't have a crunched file handy, so the crunch number is untested.
#				Keith Waclena <keith@cerberus.uchicago.edu>
0	leshort		0x76FF		squeezed data (CP/M, DOS)
0	leshort		0x76FE		crunched data (CP/M, DOS)

# Freeze
0	string		\037\237	frozen file 2.1
0	string		\037\236	frozen file 1.0 (or gzip 0.5)

# SCO compress -H (LZH)
0	string		\037\240	SCO compress -H (LZH) data

# European GSM 06.10 is a provisional standard for full-rate speech
# transcoding, prI-ETS 300 036, which uses RPE/LTP (residual pulse
# excitation/long term prediction) coding at 13 kbit/s.
#
# There's only a magic nibble (4 bits); that nibble repeats every 33
# bytes.  This isn't suited for use, but maybe we can use it someday.
#
# This will cause very short GSM files to be declared as data and
# mismatches to be declared as data too!
#0	byte&0xF0	0xd0		data
#>33	byte&0xF0	0xd0
#>66	byte&0xF0	0xd0
#>99	byte&0xF0	0xd0
#>132	byte&0xF0	0xd0		GSM 06.10 compressed audio

# Bzip from ulmo@Q.Net
0	string		BZ		bzip compressed	data,
>2	byte		x		format v. %c,
>3	byte		x		block size indicator %c

#------------------------------------------------------------------------------
# convex:  file(1) magic for Convex boxes
#
# Convexes are big-endian.
#
# /*\
#  * Below are the magic numbers and tests added for Convex.
#  * Added at beginning, because they are expected to be used most.
# \*/
0	belong	0507	Convex old-style object
>16	belong	>0	not stripped
0	belong	0513	Convex old-style demand paged executable
>16	belong	>0	not stripped
0	belong	0515	Convex old-style pre-paged executable
>16	belong	>0	not stripped
0	belong	0517	Convex old-style pre-paged, non-swapped executable
>16	belong	>0	not stripped
0	belong	0x011257	Core file
#
# The following are a series of dump format magic numbers.  Each one
# corresponds to a drastically different dump format.  The first on is
# the original dump format on a 4.1 BSD or earlier file system.  The
# second marks the change between the 4.1 file system and the 4.2 file
# system.  The Third marks the changing of the block size from 1K
# to 2K to be compatible with an IDC file system.  The fourth indicates
# a dump that is dependent on Convex Storage Manager, because data in
# secondary storage is not physically contained within the dump.
# The restore program uses these number to determine how the data is
# to be extracted.
#
24	belong	=60011	dump format, 4.1 BSD or earlier
24	belong	=60012	dump format, 4.2 or 4.3 BSD without IDC
24	belong	=60013	dump format, 4.2 or 4.3 BSD (IDC compatible)
24	belong	=60014	dump format, Convex Storage Manager by-reference dump
#
# what follows is a bunch of bit-mask checks on the flags field of the opthdr.
# If there is no `=' sign, assume just checking for whether the bit is set?
#
0	belong	0601		Convex SOFF
>88	belong&0x000f0000	=0x00000000	c1
>88	belong			&0x00010000	c2
>88	belong			&0x00020000	c2mp
>88	belong			&0x00040000	parallel
>88	belong			&0x00080000	intrinsic
>88	belong			&0x00000001	demand paged
>88	belong			&0x00000002	pre-paged
>88	belong			&0x00000004	non-swapped
>88	belong			&0x00000008	POSIX
#
>84	belong			&0x80000000	executable
>84	belong			&0x40000000	object
>84	belong&0x20000000	=0		not stripped
>84	belong&0x18000000	=0x00000000	native fpmode
>84	belong&0x18000000	=0x10000000	ieee fpmode
>84	belong&0x18000000	=0x18000000	undefined fpmode
#
0	belong			0605		Convex SOFF core
#
0	belong			0607		Convex SOFF checkpoint
>88	belong&0x000f0000	=0x00000000	c1
>88	belong			&0x00010000	c2
>88	belong			&0x00020000	c2mp
>88	belong			&0x00040000	parallel
>88	belong			&0x00080000	intrinsic
>88	belong			&0x00000008	POSIX
#
>84	belong&0x18000000	=0x00000000	native fpmode
>84	belong&0x18000000	=0x10000000	ieee fpmode
>84	belong&0x18000000	=0x18000000	undefined fpmode
#
# Yes, the two "cpio archive" formats *are* supposed to just be "short".
# The idea is to indicate archives produced on machines with the same
# byte order as the machine running "file" with "cpio archive", and
# to indicate archives produced on machines with the opposite byte order
# from the machine running "file" with "byte-swapped cpio archive".
#
# The SVR4 "cpio(4)" hints that there are additional formats, but they
# are defined as "short"s; I think all the new formats are
# character-header formats, and thus are strings not numbers.
#
0	short		070707		cpio archive
0	short		0143561		byte-swapped cpio archive
0	string		070707		ASCII cpio archive (pre-SVR4 or odc)
0	string		070701		ASCII cpio archive (SVR4 with no CRC)
0	string		070702		ASCII cpio archive (SVR4 with CRC)

#------------------------------------------------------------------------------
# database:  file(1) magic for various databases
#
# extracted from header/code files by Graeme Wilford (eep2gw@ee.surrey.ac.uk)
#
#
# GDBM magic numbers
#  Will be maintained as part of the GDBM distribution in the future.
#  <downsj@teeny.org>
0	belong	0x13579ace	GNU dbm 1.x or ndbm database, big endian
0	lelong	0x13579ace	GNU dbm 1.x or ndbm database, little endian
0	string	GDBM		GNU dbm 2.x database
#
0	belong	0x061561	Berkeley DB Hash file
>4	belong	>0		(Version %d,
>8	belong	1234		Little Endian,
>8	belong	4321		Big Endian,
>12	belong	x		Bucket Size %d,
>16	belong	x		Bucket Shift %d,
>20	belong	x		Directory Size %d,
>24	belong	x		Segment Size %d,
>28	belong	x		Segment Shift %d,
>32	belong	x		Overflow Point %d,
>36	belong	x		Last Freed %d,
>40	belong	x		Max Bucket %d,
>44	belong	x		High Mask 0x%x,
>48	belong	x		Low Mask 0x%x,
>52	belong	x		Fill Factor %d,
>56	belong	x		Number of Keys %d)
#
#
0	belong	0x053162	Berkeley DB Btree file
>4	belong	>0		(Version %d,
>8	belong	x		Page Size %d,
>12	belong	x		Free Page %d,
>16	belong	x		Number of Records %d,
>20	belong	x		Flags 0x%x)

#------------------------------------------------------------------------------
# diamond:  file(1) magic for Diamond system
#
# ... diamond is a multi-media mail and electronic conferencing system....
#
# XXX - I think it was either renamed Slate, or replaced by Slate....
#
#	The full deal is too long...
#0	string	<list>\n<protocol\ bbn-multimedia-format>	Diamond Multimedia Document
0	string	=<list>\n<protocol\ bbn-m	Diamond Multimedia Document

#------------------------------------------------------------------------------
# diff:  file(1) magic for diff(1) output
#
0	string		diff\ 	'diff' output text
0	string		***\ 		'diff' output text
0	string		Only\ in\ 	'diff' output text
0	string		Common\ subdirectories:\ 	'diff' output text
#  Digital UNIX - Info
#
0	string	^!<arch>\n_______64E	Alpha archive
>22	string	X			-- out of date
#
# Alpha COFF Based Executables
# The stripped stuff really needs to be an 8 byte (64 bit) compare,
# but this works
0	leshort		0x183		COFF format alpha
>22	leshort&020000	&010000		sharable library,
>22	leshort&020000	^010000		dynamically linked,
>24	leshort		0410		pure
>24	leshort		0413		demand paged
>8	lelong		>0		executable or object module, not stripped
>8	lelong		0
>>12	lelong		0		executable or object module, stripped
>>12	lelong		>0		executable or object module, not stripped
>27     byte            >0              - version %d.
>26     byte            >0              %d-
>28     leshort         >0              %d
#
# The next is incomplete, we could tell more about this format,
# but its not worth it.
0	leshort		0x188	Alpha compressed COFF
0	leshort		0x18f	Alpha u-code object
#
#
# Some other interesting Digital formats,
0	string	\377\377\177		ddis/ddif
0	string	\377\377\174		ddis/dots archive
0	string	\377\377\176		ddis/dtif table data
0	string	\033c\033		LN03 output
0	long	04553207		X image
#
0	string	!<PDF>!\n		profiling data file
#
# Locale data tables (MIPS and Alpha).
#
0	short		0x0501		locale data table
>6	short		0x24		for MIPS
>6	short		0x40		for Alpha
# Magic numbers for ditroff intermediate language
0	string		x\ T\ cat	titroff output for the C/A/T text
0	string		x\ T\ ps	titroff output for PostScript
0	string		x\ T 		titroff output text

#------------------------------------------------------------------------------
# dump:  file(1) magic for dump file format--for new and old dump filesystems
#
# We specify both byte orders in order to recognize byte-swapped dumps.
#
24	belong	60012		new-fs dump file (big endian),
>4	bedate	x		Previous dump %s,
>8	bedate	x		This dump %s,
>12	belong	>0		Volume %ld,
>692	belong	0		Level zero, type:
>692	belong	>0		Level %d, type:
>0	belong	1		tape header,
>0	belong	2		beginning of file record,
>0	belong	3		map of inodes on tape,
>0	belong	4		continuation of file record,
>0	belong	5		end of volume,
>0	belong	6		map of inodes deleted,
>0	belong	7		end of medium (for floppy),
>676	string	>\0		Label %s,
>696	string	>\0		Filesystem %s,
>760	string	>\0		Device %s,
>824	string	>\0		Host %s,
>888	belong	>0		Flags %x

24	belong	60011		old-fs dump file (big endian),
#>4	bedate	x		Previous dump %s,
#>8	bedate	x		This dump %s,
>12	belong	>0		Volume %ld,
>692	belong	0		Level zero, type:
>692	belong	>0		Level %d, type:
>0	belong	1		tape header,
>0	belong	2		beginning of file record,
>0	belong	3		map of inodes on tape,
>0	belong	4		continuation of file record,
>0	belong	5		end of volume,
>0	belong	6		map of inodes deleted,
>0	belong	7		end of medium (for floppy),
>676	string	>\0		Label %s,
>696	string	>\0		Filesystem %s,
>760	string	>\0		Device %s,
>824	string	>\0		Host %s,
>888	belong	>0		Flags %x

24	lelong	60012		new-fs dump file (little endian),
>4	ledate	x		This dump %s,
>8	ledate	x		Previous dump %s,
>12	lelong	>0		Volume %ld,
>692	lelong	0		Level zero, type:
>692	lelong	>0		Level %d, type:
>0	lelong	1		tape header,
>0	lelong	2		beginning of file record,
>0	lelong	3		map of inodes on tape,
>0	lelong	4		continuation of file record,
>0	lelong	5		end of volume,
>0	lelong	6		map of inodes deleted,
>0	lelong	7		end of medium (for floppy),
>676	string	>\0		Label %s,
>696	string	>\0		Filesystem %s,
>760	string	>\0		Device %s,
>824	string	>\0		Host %s,
>888	lelong	>0		Flags %x

24	lelong	60011		old-fs dump file (little endian),
#>4	ledate	x		Previous dump %s,
#>8	ledate	x		This dump %s,
>12	lelong	>0		Volume %ld,
>692	lelong	0		Level zero, type:
>692	lelong	>0		Level %d, type:
>0	lelong	1		tape header,
>0	lelong	2		beginning of file record,
>0	lelong	3		map of inodes on tape,
>0	lelong	4		continuation of file record,
>0	lelong	5		end of volume,
>0	lelong	6		map of inodes deleted,
>0	lelong	7		end of medium (for floppy),
>676	string	>\0		Label %s,
>696	string	>\0		Filesystem %s,
>760	string	>\0		Device %s,
>824	string	>\0		Host %s,
>888	lelong	>0		Flags %x

#------------------------------------------------------------------------------
# elf:  file(1) magic for ELF executables
#
# We have to check the byte order flag to see what byte order all the
# other stuff in the header is in.
#
# MIPS RS3000 may also be for MIPS RS2000.
# What're the correct byte orders for the nCUBE and the Fujitsu VPP500?
#
# updated by Daniel Quinlan (quinlan@yggdrasil.com)
0	string		\177ELF		ELF
>4	byte		0		invalid class
>4	byte		1		32-bit
>4	byte		2		64-bit
>5	byte		0		invalid byte order
>5	byte		1		LSB
>>16	leshort		0		no file type,
>>16	leshort		1		relocatable,
>>16	leshort		2		executable,
>>16	leshort		3		shared object,
# Core handling from Peter Tobias <tobias@server.et-inf.fho-emden.de>
>>16	leshort		4		core file,
>>16	leshort		&0xff00		processor-specific,
>>18	leshort		0		no machine,
>>18	leshort		1		AT&T WE32100 - invalid byte order,
>>18	leshort		2		SPARC - invalid byte order,
>>18	leshort		3		Intel 80386,
>>18	leshort		4		Motorola 68000 - invalid byte order,
>>18	leshort		5		Motorola 88000 - invalid byte order,
>>18	leshort		6		Intel 80486,
>>18	leshort		7		Intel 80860,
>>18	leshort		8		MIPS RS3000_BE - invalid byte order,
>>18	leshort		9		Amdahl - invalid byte order,
>>18	leshort		10		MIPS RS3000_LE,
>>18	leshort		11		RS6000 - invalid byte order,
>>18	leshort		15		PA_RISC - invalid byte order,
>>18	leshort		16		nCUBE,
>>18	leshort		17		VPP500,
>>18	leshort		18		SPARC32PLUS,
>>18	leshort		20		PowerPC,
>>18	leshort		0x9026		Alpha,
>>20	lelong		0		invalid version
>>20	lelong		1		version 1
>>36	lelong		1		MathCoPro/FPU/MAU Required
>5	byte		2		MSB
>>16	beshort		0		no file type,
>>16	beshort		1		relocatable,
>>16	beshort		2		executable,
>>16	beshort		3		shared object,
>>16	beshort		4		core file,
>>16	beshort		&0xff00		processor-specific,
>>18	beshort		0		no machine,
>>18	beshort		1		AT&T WE32100,
>>18	beshort		2		SPARC,
>>18	beshort		3		Intel 80386 - invalid byte order,
>>18	beshort		4		Motorola 68000,
>>18	beshort		5		Motorola 88000,
>>18	beshort		6		Intel 80486 - invalid byte order,
>>18	beshort		7		Intel 80860,
>>18	beshort		8		MIPS RS3000_BE,
>>18	beshort		9		Amdahl,
>>18	beshort		10		MIPS RS3000_LE - invalid byte order,
>>18	beshort		11		RS6000,
>>18	beshort		15		PA_RISC,
>>18	beshort		16		nCUBE,
>>18	beshort		17		VPP500,
>>18	beshort		18		SPARC32PLUS,
>>18	beshort		20		PowerPC,
>>18	beshort		0x9026		Alpha,
>>20	belong		0		invalid version
>>20	belong		1		version 1
>>36	belong		1		MathCoPro/FPU/MAU Required
>8	string		>\0		(%s)

#------------------------------------------------------------------------------
# encore:  file(1) magic for Encore machines
#
# XXX - needs to have the byte order specified (NS32K was little-endian,
# dunno whether they run the 88K in little-endian mode or not).
#
0	short		0x154		Encore
>20	short		0x107		executable
>20	short		0x108		pure executable
>20	short		0x10b		demand-paged executable
>20	short		0x10f		unsupported executable
>12	long		>0		not stripped
>22	short		>0		- version %ld
>22	short		0		-
#>4	date		x		stamp %s
0	short		0x155		Encore unsupported executable
>12	long		>0		not stripped
>22	short		>0		- version %ld
>22	short		0		-
#>4	date		x		stamp %s

#------------------------------------------------------------------------------
# figlet:  file(1) magic for FIGlet fonts and controlfiles
# From figmagic supplied with Figlet version 2.2
#
0	string		flf		FIGlet font
>3	string		>2a		version %-2.2s
0	string		flc		FIGlet controlfile
>3	string		>2a		version %-2.2s

#------------------------------------------------------------------------------
# filesystems:  file(1) magic for different filesystems
#
0x438	leshort	0xEF53			Linux/i386 ext2 filesystem
0	string	\366\366\366\366	PC formatted floppy with no filesystem
0	string	\366\366\366\366	Formatted floppy w/ no filesystem data

#------------------------------------------------------------------------------
# fonts:  file(1) magic for font data
#
0	string		FONT		ASCII vfont text
0	short		0436		Berkeley vfont data
0	short		017001		byte-swapped Berkeley vfont data

# PostScript fonts (must precede "printer" entries), quinlan@yggdrasil.com
0	string		%!PS-AdobeFont-1.0	PostScript Type 1 font text
>20	string		>\0			(%s)
6	string		%!PS-AdobeFont-1.0	PostScript Type 1 font program data

# X11 font files in SNF (Server Natural Format) format
0	belong		00000004		X11 SNF font data, MSB first
0	lelong		00000004		X11 SNF font data, LSB first

# X11 Bitmap Distribution Format, from Daniel Quinlan (quinlan@yggdrasil.com)
0	string		STARTFONT\040		X11 BDF font text

# X11 fonts, from Daniel Quinlan (quinlan@yggdrasil.com)
# PCF must come before SGI additions ("MIPSEL MIPS-II COFF" collides)
0	string		\001fcp			X11 Portable Compiled Font data
>12	byte		0x02			\b, LSB first
>12	byte		0x0a			\b, MSB first
0	string		D1.0\015		X11 Speedo font data

#------------------------------------------------------------------------------
# frame:  file(1) magic for FrameMaker files
#
# This stuff came on a FrameMaker demo tape, most of which is
# copyright, but this file is "published" as witness the following:
#
0	string		\<MakerFile	FrameMaker document
>11	string		5.0		 (5.0
>11	string		4.0		 (4.0
>11	string		3.0		 (3.0
>11	string		2.0		 (2.0
>11	string		1.0		 (1.0
>14	byte		x		  %c)
0	string		\<MIFFile	FrameMaker MIF (ASCII) file
>9	string		4.0		 (4.0)
>9	string		3.0		 (3.0)
>9	string		2.0		 (2.0)
>9	string		1.0		 (1.x)
0	string		\<MakerDictionary	FrameMaker Dictionary text
>17	string		3.0		 (3.0)
>17	string		2.0		 (2.0)
>17	string		1.0		 (1.x)
0	string		\<MakerScreenFont	FrameMaker Font file
>17	string		1.01		 (%s)
0	string		\<MML		FrameMaker MML file
0	string		\<BookFile	FrameMaker Book file
>10	string		3.0		 (3.0
>10	string		2.0		 (2.0
>10	string		1.0		 (1.0
>13	byte		x		  %c)
# XXX - this book entry should be verified, if you find one, uncomment this
#0	string		\<Book\ 	FrameMaker Book (ASCII) file
#>6	string		3.0		 (3.0)
#>6	string		2.0		 (2.0)
#>6	string		1.0		 (1.0)
0	string		\<Maker	Intermediate Print File	FrameMaker IPL file

#------------------------------------------------------------------------------
# freebsd:  file(1) magic for FreeBSD objects
#
# All new-style FreeBSD magic numbers are in host byte order (i.e.,
# little-endian on x86).
#
# XXX - this comes from the file "freebsd" in a recent FreeBSD version of
# "file"; it, and the NetBSD stuff in "netbsd", appear to use different
# schemes for distinguishing between executable images, shared libraries,
# and object files.
#
# FreeBSD says:
#
#    Regardless of whether it's pure, demand-paged, or none of the
#    above:
#
#	if the entry point is < 4096, then it's a shared library if
#	the "has run-time loader information" bit is set, and is
#	position-independent if the "is position-independent" bit
#	is set;
#
#	if the entry point is >= 4096 (or >4095, same thing), then it's
#	an executable, and is dynamically-linked if the "has run-time
#	loader information" bit is set.
#
# On x86, NetBSD says:
#
#    If it's neither pure nor demand-paged:
#
#	if it has the "has run-time loader information" bit set, it's
#	a dynamically-linked executable;
#
#	if it doesn't have that bit set, then:
#
#	    if it has the "is position-independent" bit set, it's
#	    position-independent;
#
#	    if the entry point is non-zero, it's an executable, otherwise
#	    it's an object file.
#
#    If it's pure:
#
#	if it has the "has run-time loader information" bit set, it's
#	a dynamically-linked executable, otherwise it's just an
#	executable.
#
#    If it's demand-paged:
#
#	if it has the "has run-time loader information" bit set,
#	then:
#
#	    if the entry point is < 4096, it's a shared library;
#
#	    if the entry point is = 4096 or > 4096 (i.e., >= 4096),
#	    it's a dynamically-linked executable);
#
#	if it doesn't have the "has run-time loader information" bit
#	set, then it's just an executable.
#
# (On non-x86, NetBSD does much the same thing, except that it uses
# 8192 on 68K - except for "68k4k", which is presumably "68K with 4K
# pages - SPARC, and MIPS, presumably because Sun-3's and Sun-4's
# had 8K pages; dunno about MIPS.)
#
# I suspect the two will differ only in perverse and uninteresting cases
# ("shared" libraries that aren't demand-paged and whose pages probably
# won't actually be shared, executables with entry points <4096).
#
# I leave it to those more familiar with FreeBSD and NetBSD to figure out
# what the right answer is (although using ">4095", FreeBSD-style, is
# probably better than separately checking for "=4096" and ">4096",
# NetBSD-style).  (The old "netbsd" file analyzed FreeBSD demand paged
# executables using the NetBSD technique.)
#
0	lelong&0377777777	041400407	FreeBSD/i386
>20	lelong			<4096
>>3	byte&0xC0		&0x80		shared library
>>3	byte&0xC0		0x40		PIC object
>>3	byte&0xC0		0x00		object
>20	lelong			>4095
>>3	byte&0x80		0x80		dynamically linked executable
>>3	byte&0x80		0x00		executable
>16	lelong			>0		not stripped

0	lelong&0377777777	041400410	FreeBSD/i386 pure
>20	lelong			<4096
>>3	byte&0xC0		&0x80		shared library
>>3	byte&0xC0		0x40		PIC object
>>3	byte&0xC0		0x00		object
>20	lelong			>4095
>>3	byte&0x80		0x80		dynamically linked executable
>>3	byte&0x80		0x00		executable
>16	lelong			>0		not stripped

0	lelong&0377777777	041400413	FreeBSD/i386 demand paged
>20	lelong			<4096
>>3	byte&0xC0		&0x80		shared library
>>3	byte&0xC0		0x40		PIC object
>>3	byte&0xC0		0x00		object
>20	lelong			>4095
>>3	byte&0x80		0x80		dynamically linked executable
>>3	byte&0x80		0x00		executable
>16	lelong			>0		not stripped

0	lelong&0377777777	041400314	FreeBSD/i386 compact demand paged
>20	lelong			<4096
>>3	byte&0xC0		&0x80		shared library
>>3	byte&0xC0		0x40		PIC object
>>3	byte&0xC0		0x00		object
>20	lelong			>4095
>>3	byte&0x80		0x80		dynamically linked executable
>>3	byte&0x80		0x00		executable
>16	lelong			>0		not stripped

# XXX gross hack to identify core files
# cores start with a struct tss; we take advantage of the following:
# byte 7:     highest byte of the kernel stack pointer, always 0xfe
#      8/9:   kernel (ring 0) ss value, always 0x0010
#      10 - 27: ring 1 and 2 ss/esp, unused, thus always 0
#      28:    low order byte of the current PTD entry, always 0 since the
#             PTD is page-aligned
#
7	string	\357\020\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0	FreeBSD/i386 a.out core file
>1039	string	>\0	from '%s'

# /var/run/ld.so.hints
# What are you laughing about?
0	lelong			011421044151	ld.so hints file
>4	lelong			>0		(version %d)
0       string          \037\213        gzip compressed data
>2      byte            <8              - reserved method
>2      byte            8               - deflate method
>3	byte		&0x01		, ascii
>3	byte		&0x02		, continuation 
>3	byte		&0x04		, extra field
>3	byte		&0x08		, original file name
>3	byte		&0x10		, comment
>3	byte		&0x20		, encrypted
>4	ledate		x		, last modified: %s
>8	byte		2		, max compression
>8	byte		4		, max speed
>9	byte		=0x00		os: MS/DOS
>9	byte		=0x01		os: Amiga
>9	byte		=0x02		os: VMS
>9	byte		=0x03		os: Unix
>9	byte		=0x05		os: Atari
>9	byte		=0x06		os: OS/2
>9	byte		=0x07		os: MacOS
>9	byte		=0x0A		os: Tops/20
>9	byte		=0x0B		os: Win/32

#------------------------------------------------------------------------------
# hp:  file(1) magic for Hewlett Packard machines (see also "printer")
#
# XXX - somebody should figure out whether any byte order needs to be
# applied to the "TML" stuff; I'm assuming the Apollo stuff is
# big-endian as it was mostly 68K-based.
#
# I think the 500 series was the old stack-based machines, running a
# UNIX environment atop the "SUN kernel"; dunno whether it was
# big-endian or little-endian.
#
# Daniel Quinlan (quinlan@yggdrasil.com): hp200 machines are 68010 based;
# hp300 are 68020+68881 based; hp400 are also 68k.  The following basic
# HP magic is useful for reference, but using "long" magic is a better
# practice in order to avoid collisions.
#
# Guy Harris (guy@netapp.com): some additions to this list came from
# HP-UX 10.0's "/usr/include/sys/unistd.h" (68030, 68040, PA-RISC 1.1,
# 1.2, and 2.0).  The 1.2 and 2.0 stuff isn't in the HP-UX 10.0
# "/etc/magic", though, except for the "archive file relocatable library"
# stuff, and the 68030 and 68040 stuff isn't there at all - are they not
# used in executables, or have they just not yet updated "/etc/magic"
# completely?
#
# 0	beshort		200		hp200 (68010) BSD binary
# 0	beshort		300		hp300 (68020+68881) BSD binary
# 0	beshort		0x20c		hp200/300 HP-UX binary
# 0	beshort		0x20d		hp400 (68030) HP-UX binary
# 0	beshort		0x20e		hp400 (68040?) HP-UX binary
# 0	beshort		0x20b		PA-RISC1.0 HP-UX binary
# 0	beshort		0x210		PA-RISC1.1 HP-UX binary
# 0	beshort		0x211		PA-RISC1.2 HP-UX binary
# 0	beshort		0x214		PA-RISC2.0 HP-UX binary

#
# The "misc" stuff needs a byte order; the archives look suspiciously
# like the old 177545 archives (0xff65 = 0177545).
#
#### Old Apollo stuff
0	beshort		0627		Apollo m68k COFF executable
>18	beshort		^040000		not stripped
>22	beshort		>0		- version %ld
0	beshort		0624		apollo a88k COFF executable
>18	beshort		^040000		not stripped
>22	beshort		>0		- version %ld
0       long            01203604016     TML 0123 byte-order format
0       long            01702407010     TML 1032 byte-order format
0       long            01003405017     TML 2301 byte-order format
0       long            01602007412     TML 3210 byte-order format
#### PA-RISC
0	belong 		0x02100106	PA-RISC1.1 relocatable object
0	belong 		0x02100107	PA-RISC1.1 executable
>168	belong		&=0x00000004	dynamically linked
>(144)	belong		0x054ef630	dynamically linked
>96	belong		>0		- not stripped

0	belong 		0x02100108	PA-RISC1.1 shared executable
>168	belong&0x4	0x4		dynamically linked
>(144)	belong		0x054ef630	dynamically linked
>96	belong		>0		- not stripped

0	belong 		0x0210010b	PA-RISC1.1 demand-load executable
>168	belong&0x4	0x4		dynamically linked
>(144)	belong		0x054ef630	dynamically linked
>96	belong		>0		- not stripped

0	belong 		0x0210010e	PA-RISC1.1 shared library
>96	belong		>0		- not stripped

0	belong 		0x0210010d	PA-RISC1.1 dynamic load library
>96	belong		>0		- not stripped

#### 800
0	belong 		0x020b0106	PA-RISC1.0 relocatable object

0	belong 		0x020b0107	PA-RISC1.0 executable
>168	belong&0x4	0x4		dynamically linked
>(144)	belong		0x054ef630	dynamically linked
>96	belong		>0		- not stripped

0	belong 		0x020b0108	PA-RISC1.0 shared executable
>168	belong&0x4	0x4		dynamically linked
>(144)	belong		0x054ef630	dynamically linked
>96	belong		>0		- not stripped

0	belong 		0x020b010b	PA-RISC1.0 demand-load executable
>168	belong&0x4	0x4		dynamically linked
>(144)	belong		0x054ef630	dynamically linked
>96	belong		>0		- not stripped

0	belong 		0x020b010e	PA-RISC1.0 shared library
>96	belong		>0		- not stripped

0	belong 		0x020b010d	PA-RISC1.0 dynamic load library
>96	belong		>0		- not stripped

0	belong		0x213c6172	archive file
>68	belong 		0x020b0619	- PA-RISC1.0 relocatable library
>68	belong	 	0x02100619	- PA-RISC1.1 relocatable library
>68	belong 		0x02110619	- PA-RISC1.2 relocatable library
>68	belong 		0x02140619	- PA-RISC2.0 relocatable library

#### 500
0	long		0x02080106	HP s500 relocatable executable
>16	long		>0		- version %ld

0	long		0x02080107	HP s500 executable
>16	long		>0		- version %ld

0	long		0x02080108	HP s500 pure executable
>16	long		>0		- version %ld

#### 200
0	belong 		0x020c0108	HP s200 pure executable
>4	beshort		>0		- version %ld
>8	belong		&0x80000000	save fp regs
>8	belong		&0x40000000	dynamically linked
>8	belong		&0x20000000	debuggable
>36	belong		>0		not stripped

0	belong		0x020c0107	HP s200 executable
>4	beshort		>0		- version %ld
>8	belong		&0x80000000	save fp regs
>8	belong		&0x40000000	dynamically linked
>8	belong		&0x20000000	debuggable
>36	belong		>0		not stripped

0	belong		0x020c010b	HP s200 demand-load executable
>4	beshort		>0		- version %ld
>8	belong		&0x80000000	save fp regs
>8	belong		&0x40000000	dynamically linked
>8	belong		&0x20000000	debuggable
>36	belong		>0		not stripped

0	belong		0x020c0106	HP s200 relocatable executable
>4	beshort		>0		- version %ld
>6	beshort		>0		- highwater %d
>8	belong		&0x80000000	save fp regs
>8	belong		&0x20000000	debuggable
>8	belong		&0x10000000	PIC

0	belong 		0x020a0108	HP s200 (2.x release) pure executable
>4	beshort		>0		- version %ld
>36	belong		>0		not stripped

0	belong		0x020a0107	HP s200 (2.x release) executable
>4	beshort		>0		- version %ld
>36	belong		>0		not stripped

0	belong		0x020c010e	HP s200 shared library
>4	beshort		>0		- version %ld
>6	beshort		>0		- highwater %d
>36	belong		>0		not stripped

0	belong		0x020c010d	HP s200 dynamic load library
>4	beshort		>0		- version %ld
>6	beshort		>0		- highwater %d
>36	belong		>0		not stripped

#### MISC
0	long		0x0000ff65	HP old archive
0	long		0x020aff65	HP s200 old archive
0	long		0x020cff65	HP s200 old archive
0	long		0x0208ff65	HP s500 old archive

0	long		0x015821a6	HP core file

0	long		0x4da7eee8	HP-WINDOWS font
>8	byte		>0		- version %ld
0	string		Bitmapfile	HP Bitmapfile

0	string		IMGfile	CIS 	compimg HP Bitmapfile
# XXX - see "lif"
#0	short		0x8000		lif file
0	long		0x020c010c	compiled Lisp

0	string		msgcat01	HP NLS message catalog,
>8	long		>0		%d messages

# addendum to /etc/magic with HP-48sx file-types by phk@data.fls.dk 1jan92
0	string		HPHP48-		HP48 binary
>7	byte		>0		- Rev %c
>8	short		0x1129		(ADR)
>8	short		0x3329		(REAL)
>8	short		0x5529		(LREAL)
>8	short		0x7729		(COMPLX)
>8	short		0x9d29		(LCOMPLX)
>8	short		0xbf29		(CHAR)
>8	short		0xe829		(ARRAY)
>8	short		0x0a2a		(LNKARRAY)
>8	short		0x2c2a		(STRING)
>8	short		0x4e2a		(HXS)
>8	short		0x742a		(LIST)
>8	short		0x962a		(DIR)
>8	short		0xb82a		(ALG)
>8	short		0xda2a		(UNIT)
>8	short		0xfc2a		(TAGGED)
>8	short		0x1e2b		(GROB)
>8	short		0x402b		(LIB)
>8	short		0x622b		(BACKUP)
>8	short		0x882b		(LIBDATA)
>8	short		0x9d2d		(PROG)
>8	short		0xcc2d		(CODE)
>8	short		0x482e		(GNAME)
>8	short		0x6d2e		(LNAME)
>8	short		0x922e		(XLIB)
0	string		%%HP:		HP48 text
>6	string		T(0)		- T(0)
>6	string		T(1)		- T(1)
>6	string		T(2)		- T(2)
>6	string		T(3)		- T(3)
>10	string		A(D)		A(D)
>10	string		A(R)		A(R)
>10	string		A(G)		A(G)
>14	string		F(.)		F(.);
>14	string		F(,)		F(,);

# hpBSD magic numbers
0	beshort		200		hp200 (68010) BSD
>2	beshort		0407		impure binary
>2	beshort		0410		read-only binary
>2	beshort		0413		demand paged binary
0	beshort		300		hp300 (68020+68881) BSD
>2	beshort		0407		impure binary
>2	beshort		0410		read-only binary
>2	beshort		0413		demand paged binary


#------------------------------------------------------------------------------
# ibm370:  file(1) magic for IBM 370 and compatibles.
#
# "ibm370" said that 0x15d == 0535 was "ibm 370 pure executable".
# What the heck *is* "USS/370"?
# AIX 4.1's "/etc/magic" has
#
#	0	short		0535		370 sysV executable 
#	>12	long		>0		not stripped
#	>22	short		>0		- version %d
#	>30	long		>0		- 5.2 format
#	0	short		0530		370 sysV pure executable 
#	>12	long		>0		not stripped
#	>22	short		>0		- version %d
#	>30	long		>0		- 5.2 format
#
# instead of the "USS/370" versions of the same magic numbers.
#
0	beshort		0537		370 XA sysV executable 
>12	belong		>0		not stripped
>22	beshort		>0		- version %d
>30	belong		>0		- 5.2 format
0	beshort		0532		370 XA sysV pure executable 
>12	belong		>0		not stripped
>22	beshort		>0		- version %d
>30	belong		>0		- 5.2 format
0	beshort		054001		370 sysV pure executable
>12	belong		>0		not stripped
0	beshort		055001		370 XA sysV pure executable
>12	belong		>0		not stripped
0	beshort		056401		370 sysV executable
>12	belong		>0		not stripped
0	beshort		057401		370 XA sysV executable
>12	belong		>0		not stripped
0       beshort		0531		SVR2 executable (Amdahl-UTS)
>12	belong		>0		not stripped
>24     belong		>0		- version %ld
0	beshort		0534		SVR2 pure executable (Amdahl-UTS)
>12	belong		>0		not stripped
>24	belong		>0		- version %ld
0	beshort		0530		SVR2 pure executable (USS/370)
>12	belong		>0		not stripped
>24	belong		>0		- version %ld
0	beshort		0535		SVR2 executable (USS/370)
>12	belong		>0		not stripped
>24	belong		>0		- version %ld

#------------------------------------------------------------------------------
# ibm6000:  file(1) magic for RS/6000 and the RT PC.
#
0	beshort		0x01df		executable (RISC System/6000 V3.1) or obj module
>12	belong		>0		not stripped
# Breaks sun4 statically linked execs.
#0      beshort		0x0103		executable (RT Version 2) or obj module
#>2	byte		0x50		pure
#>28	belong		>0		not stripped
#>6	beshort		>0		- version %ld
0	beshort		0x0104		shared library
0	beshort		0x0105		ctab data
0	beshort		0xfe04		structured file
0	string		0xabcdef	AIX message catalog
0	belong		0x000001f9	AIX compiled message catalog
0	string		\<aiaff>	archive

#------------------------------------------------------------------------------
# iff:	file(1) magic for Interchange File Format (see also "audio" & "images")
#
# Daniel Quinlan (quinlan@yggdrasil.com) -- IFF was designed by Electronic
# Arts for file interchange.  It has also been used by Apple, SGI, and
# especially Commodore-Amiga.
#
# IFF files begin with an 8 byte FORM header, followed by a 4 character
# FORM type, which is followed by the first chunk in the FORM.

0	string		FORM		IFF data
#>4	belong		x		\b, FORM is %d bytes long
# audio formats
>8	string		AIFF		\b, AIFF audio
>8	string		AIFC		\b, AIFF-C compressed audio
>8	string		8SVX		\b, 8SVX 8-bit sampled sound voice
>8	string		SAMP		\b, SAMP sampled audio
# image formats
>8	string		ILBMBMHD	\b, ILBM interleaved image
>>20	beshort		x		\b, %d x
>>22	beshort		x		%d
>8	string		RGBN		\b, RGBN 12-bit RGB image
>8	string		RGB8		\b, RGB8 24-bit RGB image
>8	string		DR2D		\b, DR2D 2-D object
>8	string		TDDD		\b, TDDD 3-D rendering
# other formats
>8	string		FTXT		\b, FTXT formatted text
# Tell file about magic for IMAGEN printer-ready files:
0	string	@document(		Imagen printer
# this only works if "language xxx" is first item in Imagen header.
>10	string	language\ impress	(imPRESS data)
>10	string	language\ daisy		(daisywheel text)
>10	string	language\ diablo		(daisywheel text)
>10	string	language\ printer	(line printer emulation)
>10	string	language\ tektronix	(Tektronix 4014 emulation)
# Add any other languages that your Imagen uses - remember
# to keep the word `text' if the file is human-readable.
#
# Now magic for IMAGEN font files...
0	string		Rast		RST-format raster font data
>45	string		>0		face %

#------------------------------------------------------------------------------
# images:  file(1) magic for image formats (see also "iff")
#
# originally from jef@helios.ee.lbl.gov (Jef Poskanzer),
# additions by janl@ifi.uio.no as well as others. Jan also suggested
# merging several one- and two-line files into here.
#
# little magic: PCX (first byte is 0x0a)
# no magic: Targa

# PBMPLUS images
# The next byte following the magic is always whitespace.
0	string		P1		PBM image text
0	string		P2		PGM image text
0	string		P3		PPM image text
0	string		P4		PBM "rawbits" image data
0	string		P5		PGM "rawbits" image data
0	string		P6		PPM "rawbits" image data

# NIFF (Navy Interchange File Format, a modification of TIFF) images
0	string		IIN1		NIFF image data

# Tag Image File Format, from Daniel Quinlan (quinlan@yggdrasil.com)
# The second word of TIFF files is the TIFF version number, 42, which has
# never changed.  The TIFF specification recommends testing for it.
0	string		MM\x00\x2a	TIFF image data, big-endian
0	string		II\x2a\x00	TIFF image data, little-endian

# PNG [Portable Network Graphics, or "PNG's Not GIF"] images
# (Greg Roelofs, newt@uchicago.edu)
#
# 137 P N G \r \n ^Z \n [4-byte length] H E A D [HEAD data] [HEAD crc] ...
#
0	string		\x89PNG		PNG image data,
>4	belong		!0x0d0a1a0a	CORRUPTED,
>16	belong		x		%ld x
>20	belong		x		%ld,
>24	byte		x		%d-bit
>25	byte		0		grayscale,
>25	byte		2		\b/color RGB,
>25	byte		3		colormap,
>25	byte		4		gray+alpha,
>25	byte		6		\b/color RGBA,
#>26	byte		0		deflate/32K,
>28	byte		0		non-interlaced
>28	byte		1		interlaced

# GIF
0	string		GIF8		GIF image data
>4	string		7a		\b, version 8%s,
>4	string		9a		\b, version 8%s,
>6	leshort		>0		%hd x
>8	leshort		>0		%hd,
#>10	byte		&0x80		color mapped,
#>10	byte&0x07	=0x00		2 colors
#>10	byte&0x07	=0x01		4 colors
#>10	byte&0x07	=0x02		8 colors
#>10	byte&0x07	=0x03		16 colors
#>10	byte&0x07	=0x04		32 colors
#>10	byte&0x07	=0x05		64 colors
#>10	byte&0x07	=0x06		128 colors
#>10	byte&0x07	=0x07		256 colors

# ITC (CMU WM) raster files.  It is essentially a byte-reversed Sun raster,
# 1 plane, no encoding.
0	string		\361\0\100\273	CMU window manager raster image data
>4	lelong		>0		%d x
>8	lelong		>0		%d,
>12	lelong		>0		%d-bit

# Magick Image File Format
0	string		id=ImageMagick	MIFF image data

# Artisan
0	long		1123028772	Artisan image data
>4	long		1		\b, rectangular 24-bit
>4	long		2		\b, rectangular 8-bit with colormap
>4	long		3		\b, rectangular 32-bit (24-bit with matte)

# FIG (Facility for Interactive Generation of figures), an object-based format
0	string		#FIG		FIG image text
>5	string		x		\b, version %.3s

# PHIGS
0	string		ARF_BEGARF		PHIGS clear text archive
0	string		@(#)SunPHIGS		SunPHIGS
# version number follows, in the form m.n
>40	string		SunBin			binary
>32	string		archive			archive

# GKS (Graphics Kernel System)
0	string		GKSM		GKS Metafile
>24	string		SunGKS		\b, SunGKS

# CGM image files
0	string		BEGMF		clear text Computer Graphics Metafile
# XXX - questionable magic
0	beshort&0xffe0	0x0020		binary Computer Graphics Metafile
0	beshort		0x3020		character Computer Graphics Metafile

# MGR bitmaps  (Michael Haardt, u31b3hs@pool.informatik.rwth-aachen.de)
0	string	yz	MGR bitmap, modern format, 8-bit aligned
0	string	zz	MGR bitmap, old format, 1-bit deep, 16-bit aligned
0	string	xz	MGR bitmap, old format, 1-bit deep, 32-bit aligned
0	string	yx	MGR bitmap, modern format, squeezed

# Fuzzy Bitmap (FBM) images
0	string		%bitmap\0	FBM image data
>30	long		0x31		\b, mono
>30	long		0x33		\b, color

# facsimile data
1	string		PC\ Research,\ Inc	group 3 fax data
>29	byte		0		\b, normal resolution (204x98 DPI)
>29	byte		1		\b, fine resolution (204x196 DPI)

# JPEG images
# SunOS 5.5.1 had
#
#	0	string		\377\330\377\340	JPEG file
#	0	string		\377\330\377\356	JPG file
#
# both of which turn into "JPEG image data" here.
#
0	beshort		0xffd8		JPEG image data
>6	string		JFIF		\b, JFIF standard
# HSI is Handmade Software's proprietary JPEG encoding scheme
0	string		hsi1		JPEG image data, HSI proprietary

# PC bitmaps (OS/2, Windoze BMP files)  (Greg Roelofs, newt@uchicago.edu)
0	string		BM		PC bitmap data
>14	leshort		12		\b, OS/2 1.x format
>>18	leshort		x		\b, %d x
>>20	leshort		x		%d
>14	leshort		64		\b, OS/2 2.x format
>>18	leshort		x		\b, %d x
>>20	leshort		x		%d
>14	leshort		40		\b, Windows 3.x format
>>18	lelong		x		\b, %d x
>>22	lelong		x		%d x
>>28	leshort		x		%d
0	string		IC		PC icon data
0	string		PI		PC pointer image data
0	string		CI		PC color icon data
0	string		CP		PC color pointer image data
# Conflicts with other entries [BABYL]
#0	string		BA		PC bitmap array data

# XPM icons (Greg Roelofs, newt@uchicago.edu)
# note possible collision with C/REXX entry in c-lang; currently commented out
0	string		/*\ XPM\ */	X pixmap image text

# Utah Raster Toolkit RLE images (janl@ifi.uio.no)
0	leshort		0xcc52		RLE image data,
>6	leshort		x		%d x
>8	leshort		x		%d
>2	leshort		>0		\b, lower left corner: %d
>4	leshort		>0		\b, lower right corner: %d
>10	byte&0x1	=0x1		\b, clear first
>10	byte&0x2	=0x2		\b, no background
>10	byte&0x4	=0x4		\b, alpha channel
>10	byte&0x8	=0x8		\b, comment
>11	byte		>0		\b, %d color channels
>12	byte		>0		\b, %d bits per pixel
>13	byte		>0		\b, %d color map channels

# image file format (Robert Potter, potter@cs.rochester.edu)
0	string		Imagefile\ version-	iff image data
# this adds the whole header (inc. version number), informative but longish
>10	string		>\0		%s

# Sun raster images, from Daniel Quinlan (quinlan@yggdrasil.com)
0	belong		0x59a66a95	Sun raster image data
>4	belong		>0		\b, %d x
>8	belong		>0		%d,
>12	belong		>0		%d-bit,
#>16	belong		>0		%d bytes long,
>20	belong		0		old format,
#>20	belong		1		standard,
>20	belong		2		compressed,
>20	belong		3		RGB,
>20	belong		4		TIFF,
>20	belong		5		IFF,
>20	belong		0xffff		reserved for testing,
>24	belong		0		no colormap
>24	belong		1		RGB colormap
>24	belong		2		raw colormap
#>28	belong		>0		colormap is %d bytes long

# SGI image file format, from Daniel Quinlan (quinlan@yggdrasil.com)
# file://sgi.com/graphics/SGIIMAGESPEC
0	beshort		474		SGI image data
#>2	byte		0		\b, verbatim
>2	byte		1		\b, RLE
#>3	byte		1		\b, normal precision
>3	byte		2		\b, high precision
>4	beshort		x		\b, %d-D
>6	beshort		x		\b, %d x
>8	beshort		x		%d
>10	beshort		x		\b, %d channel
>10	beshort		!1		\bs
>80	string		>0		\b, "%s"

0	string		IT01		FIT image data
>4	belong		x		\b, %d x
>8	belong		x		%d x
>12	belong		x		%d
#
0	string		IT02		FIT image data
>4	belong		x		\b, %d x
>8	belong		x		%d x
>12	belong		x		%d
#
2048	string		PCD_IPI		Kodak Photo CD image pack file
0	string		PCD_OPA		Kodak Photo CD overview pack file

# FITS format.  Jeff Uphoff <juphoff@tarsier.cv.nrao.edu>
# FITS is the Flexible Image Transport System, the de facto standard for
# data and image transfer, storage, etc., for the astronomical community.
# (FITS floating point formats are big-endian.)
0	string	SIMPLE\ \ =	FITS image data
>109	string	8		\b, 8-bit, character or unsigned binary integer
>108	string	16		\b, 16-bit, two's complement binary integer
>107	string	\ 32		\b, 32-bit, two's complement binary integer
>107	string	-32		\b, 32-bit, floating point, single precision
>107	string	-64		\b, 64-bit, floating point, double precision

# other images
0	string	This\ is\ a\ BitMap\ file	Lisp Machine bit-array-file
0	string		!!		Bennet Yee's "face" format

# From SunOS 5.5.1 "/etc/magic" - appeared right before Sun raster image
# stuff.
#
0	beshort		0x1010		PEX Binary Archive

#------------------------------------------------------------------------------
# intel:  file(1) magic for x86 Unix
#
# Various flavors of x86 UNIX executable/object (other than Xenix, which
# is in "microsoft").  DOS is in "msdos"; the ambitious soul can do
# Windows as well.
#
# Windows NT belongs elsewhere, as you need x86 and MIPS and Alpha and
# whatever comes next (HP-PA Hummingbird?).  OS/2 may also go elsewhere
# as well, if, as, and when IBM makes it portable.
#
# The `versions' should be un-commented if they work for you.
# (Was the problem just one of endianness?)
#
0	leshort		0502		basic-16 executable
>12	lelong		>0		not stripped
#>22	leshort		>0		- version %ld
0	leshort		0503		basic-16 executable (TV)
>12	lelong		>0		not stripped
#>22	leshort		>0		- version %ld
0	leshort		0510		x86 executable
>12	lelong		>0		not stripped
0	leshort		0511		x86 executable (TV)
>12	lelong		>0		not stripped
0	leshort		=0512		iAPX 286 executable small model (COFF)
>12	lelong		>0		not stripped
#>22	leshort		>0		- version %ld
0	leshort		=0522		iAPX 286 executable large model (COFF)
>12	lelong		>0		not stripped
#>22	leshort		>0		- version %ld
# SGI labeled the next entry as "iAPX 386 executable" --Dan Quinlan
0	leshort		=0514		80386 COFF executable
>12	lelong		>0		not stripped
>22	leshort		>0		- version %ld

#------------------------------------------------------------------------------
# interleaf:  file(1) magic for InterLeaf TPS:
#
0	string		=\210OPS	Interleaf saved data
0	string		=<!OPS		Interleaf document text
>5	string		,\ Version\ =	\b, version
>>17	string		>\0		%.3s
#
# magic.iris: Magic for mips from an iris4d
#
# Dunno what byte-order munging is needed; all of SGI's *current*
# machines and OSes run in big-endian mode on the MIPS machines,
# as far as I know, but they do have the MIPSEB and MIPSEL stuff
# here....
#
0	short		0x0160		mipseb
>20	short		0407		executable
>20	short		0410		pure
>20	short		0413		demand paged
>8	long		>0		not stripped
>8	long		0		stripped
>22	byte		>0		- version %ld.
>23	byte		>0		%ld
0	short		0x0162		mipsel
>20	short		0407		executable
>20	short		0410		pure
>20	short		0413		demand paged
>8	long		>0		not stripped
>8	long		0		stripped
>23	byte		>0		- version %ld.
>22	byte		>0		%ld
0	short		0x6001		swapped mipseb
>20	short		03401		executable
>20	short		04001		pure
>20	short		05401		demand paged
>8	long		>0		not stripped
>8	long		0		stripped
>22	byte		>0		- version %ld.
>23	byte		>0		%ld
0	short		0x6201		swapped mipsel
>20	short		03401		executable
>20	short		04001		pure
>20	short		05401		demand paged
>8	long		>0		not stripped
>8	long		0		stripped
>22	byte		>0		- version %ld.
>23	byte		>0		%ld
0	short		0x180		mipseb ucode
0	short		0x182		mipsel ucode
#
# IRIX core format version 1 (from /usr/include/core.out.h)
0	long		0xdeadadb0	IRIX core dump
>4	long		1		of
>16	string		>\0		'%s'
#
# Archives - This handles archive subtypes
#
0	string		!<arch>\n__________E	MIPS archive
>20	string		U			with mipsucode members
>21	string		L			with mipsel members
>21	string		B			with mipseb members
>19	string		L			and a EL hash table
>19	string		B			and a EB hash table
>22	string		X			-- out of date

#------------------------------------------------------------------------------
# island:  file(1) magic for IslandWite/IslandDraw, from SunOS 5.5.1
# "/etc/magic":
# From: guy@netapp.com (Guy Harris)
#
4	string		pgscriptver	IslandWrite document
13	string		DrawFile	IslandDraw document


#------------------------------------------------------------------------------
# ispell:  file(1) magic for ispell
#
# Ispell 3.0 has a magic of 0x9601 and ispell 3.1 has 0x9602.  This magic
# will match 0x9600 through 0x9603 in *both* little endian and big endian.
# (No other current magic entries collide.)
#
# Updated by Daniel Quinlan (quinlan@yggdrasil.com)
#
0	leshort&0xFFFC	0x9600		little endian ispell
>0	byte		0		hash file (?),
>0	byte		1		3.0 hash file,
>0	byte		2		3.1 hash file,
>0	byte		3		hash file (?),
>2	leshort		0x00		8-bit, no capitalization, 26 flags
>2	leshort		0x01		7-bit, no capitalization, 26 flags
>2	leshort		0x02		8-bit, capitalization, 26 flags
>2	leshort		0x03		7-bit, capitalization, 26 flags
>2	leshort		0x04		8-bit, no capitalization, 52 flags
>2	leshort		0x05		7-bit, no capitalization, 52 flags
>2	leshort		0x06		8-bit, capitalization, 52 flags
>2	leshort		0x07		7-bit, capitalization, 52 flags
>2	leshort		0x08		8-bit, no capitalization, 128 flags
>2	leshort		0x09		7-bit, no capitalization, 128 flags
>2	leshort		0x0A		8-bit, capitalization, 128 flags
>2	leshort		0x0B		7-bit, capitalization, 128 flags
>2	leshort		0x0C		8-bit, no capitalization, 256 flags
>2	leshort		0x0D		7-bit, no capitalization, 256 flags
>2	leshort		0x0E		8-bit, capitalization, 256 flags
>2	leshort		0x0F		7-bit, capitalization, 256 flags
>4	leshort		>0		and %d string characters
0	beshort&0xFFFC	0x9600		big endian ispell
>1	byte		0		hash file (?),
>1	byte		1		3.0 hash file,
>1	byte		2		3.1 hash file,
>1	byte		3		hash file (?),
>2	beshort		0x00		8-bit, no capitalization, 26 flags
>2	beshort		0x01		7-bit, no capitalization, 26 flags
>2	beshort		0x02		8-bit, capitalization, 26 flags
>2	beshort		0x03		7-bit, capitalization, 26 flags
>2	beshort		0x04		8-bit, no capitalization, 52 flags
>2	beshort		0x05		7-bit, no capitalization, 52 flags
>2	beshort		0x06		8-bit, capitalization, 52 flags
>2	beshort		0x07		7-bit, capitalization, 52 flags
>2	beshort		0x08		8-bit, no capitalization, 128 flags
>2	beshort		0x09		7-bit, no capitalization, 128 flags
>2	beshort		0x0A		8-bit, capitalization, 128 flags
>2	beshort		0x0B		7-bit, capitalization, 128 flags
>2	beshort		0x0C		8-bit, no capitalization, 256 flags
>2	beshort		0x0D		7-bit, no capitalization, 256 flags
>2	beshort		0x0E		8-bit, capitalization, 256 flags
>2	beshort		0x0F		7-bit, capitalization, 256 flags
>4	beshort		>0		and %d string characters
#------------------------------------------------------------
# Java ByteCode
# From Larry Schwimmer (schwim@cs.stanford.edu)
0	belong		0xcafebabe
>4	belong		0x0003002d	Java bytecode
#
# java:  file(1) magic for java compiled classes
#

0	belong	0xCafeBabe		compiled java class data,
>4	beshort x			version %d.
>6	beshort x			\b%d


#------------------------------------------------------------------------------
# karma:  file(1) magic for Karma data files
#
# From <rgooch@atnf.csiro.au>

0	string		KarmaRHD Version	Karma Data Structure Version
>16	long		x		%lu

#------------------------------------------------------------------------------
# lex:  file(1) magic for lex
#
#	derived empirically, your offsets may vary!
53	string		yyprevious	C program text (from lex)
>3	string		>\0		 for %s
# C program text from GNU flex, from Daniel Quinlan <quinlan@yggdrasil.com>
21	string		generated\ by\ flex	C program text (from flex)
# lex description file, from Daniel Quinlan <quinlan@yggdrasil.com>
0	string		%{		lex description text

#------------------------------------------------------------------------------
# lif:  file(1) magic for lif
#
# XXX - byte order?  (Probably beshort, Daniel Quinlan <quinlan@yggdrasil.com>)
#
0	short		0x8000		lif file

#------------------------------------------------------------------------------
# linux:  file(1) magic for Linux files
#
# Values for Linux/i386 binaries, from Daniel Quinlan <quinlan@yggdrasil.com>
# The following basic Linux magic is useful for reference, but using
# "long" magic is a better practice in order to avoid collisions.
#
# 2	leshort		100		Linux/i386
# >0	leshort		0407		impure executable (OMAGIC)
# >0	leshort		0410		pure executable (NMAGIC)
# >0	leshort		0413		demand-paged executable (ZMAGIC)
# >0	leshort		0314		demand-paged executable (QMAGIC)
#
0	lelong		0x00640107	Linux/i386 impure executable (OMAGIC)
>16	lelong		0		\b, stripped
0	lelong		0x00640108	Linux/i386 pure executable (NMAGIC)
>16	lelong		0		\b, stripped
0	lelong		0x0064010b	Linux/i386 demand-paged executable (ZMAGIC)
>16	lelong		0		\b, stripped
0	lelong		0x006400cc	Linux/i386 demand-paged executable (QMAGIC)
>16	lelong		0		\b, stripped
#
0	string		\007\001\000	Linux/i386 object file
>20	lelong		>0x1020		\b, DLL library
# message catalogs, from Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
0	string		*nazgul*	Linux compiled message catalog
>8	lelong		>0		\b, version %ld
# core dump file, from Bill Reynolds <bill@goshawk.lanl.gov>
216	lelong		0421		Linux/i386 core file
>220	string		>\0		of '%s'
>200	lelong		>0		(signal %d)
#
# LILO boot/chain loaders, from Daniel Quinlan <quinlan@yggdrasil.com>
# this can be overridden by the DOS executable (COM) entry
2	string		LILO		Linux/i386 LILO boot/chain loader
#
# Debian Packages, from Peter Tobias <tobias@server.et-inf.fho-emden.de>
0	string		0.9
>8	byte		0x0a		Debian Binary Package
>>3	byte		>0		\b, created by dpkg 0.9%c
>>4	byte		>0		pl%c
# PSF fonts, from H. Peter Anvin <hpa@yggdrasil.com>
0	leshort		0x0436		Linux/i386 PC Screen Font data,
>2	byte		0		256 characters, no directory,
>2	byte		1		512 characters, no directory,
>2	byte		2		256 characters, Unicode directory,
>2	byte		3		512 characters, Unicode directory,
>3	byte		>0		8x%d
# Linux swap file, from Daniel Quinlan <quinlan@yggdrasil.com>
4086	string		SWAP-SPACE	Linux/i386 swap file
# ECOFF magic for OSF/1 and Linux (only tested under Linux though)
#
#	from Erik Troan (ewt@redhat.com) examining od dumps, so this
#		could be wrong
#      updated by David Mosberger (davidm@azstarnet.com) based on
#      GNU BFD and MIPS info found below.
#
0	leshort		0x0183		ECOFF alpha
>24	leshort		0407		executable
>24	leshort		0410		pure
>24	leshort		0413		demand paged
>8	long		>0		not stripped
>8	long		0		stripped
>23	leshort		>0		- version %ld.
# linux Kernel images version 1.3.80 - ?
# from Axel Kohlmeyer <akohlmey@rincewind.chemie.uni-ulm.de>
0       belong          0xb8c0078e      Linux/x86 kernel image,
>0x048c byte            0x31
>>0x048c string         x               version %s
>0x0493 byte            0x31
>>0x0493 string         x               version %s
#

#------------------------------------------------------------------------------
# lisp:  file(1) magic for lisp programs
#
# various lisp types, from Daniel Quinlan (quinlan@yggdrasil.com)
0	string	;;			Lisp/Scheme program text
# Emacs 18 - this is always correct, but not very magical.
0	string	\012(			byte-compiled Emacs-Lisp program data
# Emacs 19
0	string	;ELC\023\000\000\000	byte-compiled Emacs-Lisp program data
#------------------------------------------------------------------------------
# mach file description
#
0	belong		0xcafebabe	mach-o fat file
>4	belong		1		with 1 architecture
>4	belong		>1
>>4	belong		x		with %ld architectures		
#
0	belong		0xfeedface	mach-o
>12	belong		1		object
>12	belong		2		executable
>12	belong		3		shared library
>12	belong		4		core
>12	belong		5		preload executable
>12	belong		>5
>>12	belong		x		filetype=%ld
>4	belong		<0
>>4	belong		x		architecture=%ld
>4	belong		1		vax
>4	belong		2		romp
>4	belong		3		architecture=3
>4	belong		4		ns32032
>4	belong		5		ns32332
>4	belong		6		for m68k architecture
>4	belong		7		i386
>4	belong		8		mips
>4	belong		9		ns32532
>4	belong		10		architecture=10
>4	belong		11		hp pa-risc
>4	belong		12		acorn
>4	belong		13		m88k
>4	belong		14		sparc
>4	belong		15		i860-big
>4	belong		16		i860
>4	belong		17		rs6000
>4	belong		18		powerPC
>4	belong		>18
>>4	belong		x		architecture=%ld

#------------------------------------------------------------------------------
# mail.news:  file(1) magic for mail and news
#
# Unfortunately, saved netnews also has From line added in some news software.
#0	string		From 		mail text
# There are tests to ascmagic.c to cope with mail and news.
0	string		Relay-Version: 	old news text
0	string		#!\ rnews	batched news text
0	string		N#!\ rnews	mailed, batched news text
0	string		Forward\ to 	mail forwarding text
0	string		Pipe\ to 	mail piping text
0	string		Return-Path:	smtp mail text
0	string		Path:		news text
0	string		Xref:		news text
0	string		From:		news or mail text
0	string		Article 	saved news text
0	string		BABYL		Emacs RMAIL text
0	string		Received:	RFC 822 mail text
0	string		MIME-Version:	MIME entity text
0	string		Content-	MIME entity text

#------------------------------------------------------------------------------
# microsoft:  file(1) magic for Microsoft Xenix
#
# "Middle model" stuff, and "Xenix 8086 relocatable or 80286 small
# model" lifted from "magic.xenix", with comment "derived empirically;
# treat as folklore until proven"
#
# "small model", "large model", "huge model" stuff lifted from XXX
#
# XXX - "x.out" collides with PDP-11 archives
#
0	string		core		core file (Xenix)
0	byte		0x80		8086 relocatable (Microsoft)
0	leshort		0xff65		x.out
>2	string		__.SYMDEF	 randomized
>0	byte		x		archive
0	leshort		0x206		Microsoft a.out
>8	leshort		1		Middle model
>0x1e	leshort		&0x10		overlay
>0x1e	leshort		&0x2		separate
>0x1e	leshort		&0x4		pure
>0x1e	leshort		&0x800		segmented
>0x1e	leshort		&0x400		standalone
>0x1e	leshort		&0x8		fixed-stack
>0x1c	byte		&0x80		byte-swapped
>0x1c	byte		&0x40		word-swapped
>0x10	lelong		>0		not-stripped
>0x1e	leshort		^0xc000		pre-SysV
>0x1e	leshort		&0x4000		V2.3
>0x1e	leshort		&0x8000		V3.0
>0x1c	byte		&0x4		86
>0x1c	byte		&0xb		186
>0x1c	byte		&0x9		286
>0x1c	byte		&0xa		386
>0x1f	byte		<0x040		small model
>0x1f	byte		=0x048		large model	
>0x1f	byte		=0x049		huge model 
>0x1e	leshort		&0x1		executable
>0x1e	leshort		^0x1		object file
>0x1e	leshort		&0x40		Large Text
>0x1e	leshort		&0x20		Large Data
>0x1e	leshort		&0x120		Huge Objects Enabled
>0x10	lelong		>0		not stripped

0	leshort		0x140		old Microsoft 8086 x.out
>0x3	byte		&0x4		separate
>0x3	byte		&0x2		pure
>0	byte		&0x1		executable
>0	byte		^0x1		relocatable
>0x14	lelong		>0		not stripped

0	lelong		0x206		b.out
>0x1e	leshort		&0x10		overlay
>0x1e	leshort		&0x2		separate
>0x1e	leshort		&0x4		pure
>0x1e	leshort		&0x800		segmented
>0x1e	leshort		&0x400		standalone
>0x1e	leshort		&0x1		executable
>0x1e	leshort		^0x1		object file
>0x1e	leshort		&0x4000		V2.3
>0x1e	leshort		&0x8000		V3.0
>0x1c	byte		&0x4		86
>0x1c	byte		&0xb		186
>0x1c	byte		&0x9		286
>0x1c	byte		&0x29		286
>0x1c	byte		&0xa		386
>0x1e	leshort		&0x4		Large Text
>0x1e	leshort		&0x2		Large Data
>0x1e	leshort		&0x102		Huge Objects Enabled

0	leshort		0x580		XENIX 8086 relocatable or 80286 small model
#
# RISC MIPS decstation
# Should this be "leshort", given that DEC ran the DECstations in
# little-endian mode?
#
# Where is the non-SGI, non-DEC MIPS stuff?
#
0	short		0x6201		MIPS executable

#------------------------------------------------------------------------------
# mirage:  file(1) magic for Mirage executables
#
# XXX - byte order?
#
0	long	31415		Mirage Assembler m.out executable

#------------------------------------------------------------------------------
# mkid:  file(1) magic for mkid(1) databases
#
# ID is the binary tags database produced by mkid(1).
#
# XXX - byte order?
#
0	string		\311\304	ID tags data
>2	short		>0		version %d

#------------------------------------------------------------------------------
# mmdf:  file(1) magic for MMDF mail files
#
0	string	\001\001\001\001	MMDF mailbox

#------------------------------------------------------------------------------
# motorola:  file(1) magic for Motorola 68K and 88K binaries
#
# 68K
#
0	beshort		0520		mc68k COFF
>18	beshort		^00000020	object
>18	beshort		&00000020	executable
>12	belong		>0		not stripped
>168	string		.lowmem		Apple toolbox
>20	beshort		0407		(impure)
>20	beshort		0410		(pure)
>20	beshort		0413		(demand paged)
>20	beshort		0421		(standalone)
0	beshort		0521		mc68k executable (shared)
>12	belong		>0		not stripped
0	beshort		0522		mc68k executable (shared demand paged)
>12	belong		>0		not stripped
#
# Motorola/UniSoft 68K Binary Compatibility Standard (BCS)
#
0	beshort		0554		68K BCS executable
#
# 88K
#
# Motorola/88Open BCS
#
0	beshort		0555		88K BCS executable
#
# Motorola S-Records, from Gerd Truschinski <gt@freebsd.first.gmd.de>
0   string      S0          Motorola S-Record; binary data in text format

#------------------------------------------------------------------------------
# msdos:  file(1) magic for MS-DOS files
#

# .BAT files (Daniel Quinlan, quinlan@yggdrasil.com)
0	string	@echo\ off	MS-DOS batch file text

# .EXE formats (Greg Roelofs, newt@uchicago.edu)
#
0	string	MZ		MS-DOS executable (EXE)
>24	string	@		\b, OS/2 or Windows
>1638	string	-lh5-		\b, LHa SFX archive v2.13S
>7195	string	Rar!		\b, RAR self-extracting archive
#
# [GRR 950118:  file 3.15 has a buffer-size limitation; offsets bigger than
#   8161 bytes are ignored.  To make the following entries work, increase
#   HOWMANY in file.h to 32K at least, and maybe to 70K or more for OS/2,
#   NT/Win32 and VMS.]
# [GRR:  some company sells a self-extractor/displayer for image data(!)]
#
>11696	string	PK\003\004	\b, PKZIP SFX archive v1.1
>13297	string	PK\003\004	\b, PKZIP SFX archive v1.93a
>15588	string	PK\003\004	\b, PKZIP2 SFX archive v1.09
>15770	string	PK\003\004	\b, PKZIP SFX archive v2.04g
>28374	string	PK\003\004	\b, PKZIP2 SFX archive v1.02
#
# Info-ZIP self-extractors
#    these are the DOS versions:
>25115	string	PK\003\004	\b, Info-ZIP SFX archive v5.12
>26331	string	PK\003\004	\b, Info-ZIP SFX archive v5.12 w/decryption
#    these are the OS/2 versions (OS/2 is flagged above):
>47031	string	PK\003\004	\b, Info-ZIP SFX archive v5.12
>49845	string	PK\003\004	\b, Info-ZIP SFX archive v5.12 w/decryption
#    this is the NT/Win32 version:
>69120	string	PK\003\004	\b, Info-ZIP NT SFX archive v5.12 w/decryption
#
# TELVOX Teleinformatica CODEC self-extractor for OS/2:
>49801	string	\x79\xff\x80\xff\x76\xff	\b, CODEC archive v3.21
>>49824	leshort		=1			\b, 1 file
>>49824	leshort		>1			\b, %u files

# .COM formats (Daniel Quinlan, quinlan@yggdrasil.com)
# Uncommenting only the first two lines will cover about 2/3 of COM files,
# but it isn't feasible to match all COM files since there must be at least
# two dozen different one-byte "magics".
#0	byte		0xe9		MS-DOS executable (COM)
#0	byte		0x8c		MS-DOS executable (COM)
# 0xeb conflicts with "sequent" magic
#0	byte		0xeb		MS-DOS executable (COM)
#0	byte		0xb8		MS-DOS executable (COM)

# miscellaneous formats
0	string		LZ		MS-DOS executable (built-in)
#0	byte		0xf0		MS-DOS program library data
#

# Popular applications
2080	string	Microsoft\ Word\ 6.0\ Document	%s
#
0	belong	0x31be0000	Microsoft Word Document
#
2080	string	Microsoft\ Excel\ 5.0\ Worksheet	%s
#
0	belong	0x00001a00	Lotus 1-2-3
>4	belong	0x00100400	wk3 document
>4	belong	0x02100400	wk4 document
>4	belong	0x07800100	fm3 or fmb document
>4	belong	0x07800000	fm3 or fmb document
#
0	belong	0x00000200 	Lotus 1-2-3
>4	belong	0x06040600	wk1 document
>4	belong	0x06800200	fmt document

#------------------------------------------------------------------------------
# ncr:  file(1) magic for NCR Tower objects
#
# contributed by
# Michael R. Wayne  ***  TMC & Associates  ***  INTERNET: wayne@ford-vax.arpa
# uucp: {philabs | pyramid} !fmsrl7!wayne   OR   wayne@fmsrl7.UUCP
#
0	beshort		000610	Tower/XP rel 2 object
>12	   belong		>0	not stripped
>20	   beshort		0407	executable
>20	   beshort		0410	pure executable
>22	   beshort		>0	- version %ld
0	beshort		000615	Tower/XP rel 2 object
>12	   belong		>0	not stripped
>20	   beshort		0407	executable
>20	   beshort		0410	pure executable
>22	   beshort		>0	- version %ld
0	beshort		000620	Tower/XP rel 3 object
>12	   belong		>0	not stripped
>20	   beshort		0407	executable
>20	   beshort		0410	pure executable
>22	   beshort		>0	- version %ld
0	beshort		000625	Tower/XP rel 3 object
>12	   belong		>0	not stripped
>20	   beshort		0407	executable
>20	   beshort		0410	pure executable
>22	   beshort		>0	- version %ld
0	beshort		000630	Tower32/600/400 68020 object
>12	   belong		>0	not stripped
>20	   beshort		0407	executable
>20	   beshort		0410	pure executable
>22	   beshort		>0	- version %ld
0	beshort		000640	Tower32/800 68020
>18	   beshort		&020000	w/68881 object
>18	   beshort		&040000	compatible object
>18	   beshort		&~060000	object
>20	   beshort		0407	executable
>20	   beshort		0413	pure executable
>12	   belong		>0	not stripped
>22	   beshort		>0	- version %ld
0	beshort		000645	Tower32/800 68010
>18	   beshort		&040000	compatible object
>18	   beshort		&~060000 object
>20	   beshort		0407	executable
>20	   beshort		0413	pure executable
>12	   belong		>0	not stripped
>22	   beshort		>0	- version %ld

#------------------------------------------------------------------------------
# netbsd:  file(1) magic for NetBSD objects
#
# All new-style magic numbers are in network byte order.
#

0	lelong			000000407	NetBSD little-endian object file
>16	lelong			>0		not stripped
0	belong			000000407	NetBSD big-endian object file
>16	belong			>0		not stripped

0	belong&0377777777	041400413	NetBSD/i386 demand paged
>0	byte			&0x80		
>>20	lelong			<4096		shared library
>>20	lelong			=4096		dynamically linked executable
>>20	lelong			>4096		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	041400410	NetBSD/i386 pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	041400407	NetBSD/i386
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	lelong			!0		executable
>>20	lelong			=0		object file
>16	lelong			>0		not stripped
0	belong&0377777777	041400507	NetBSD/i386 core
>12	string			>\0		from '%s'

0	belong&0377777777	041600413	NetBSD/m68k demand paged
>0	byte			&0x80		
>>20	belong			<8192		shared library
>>20	belong			=8192		dynamically linked executable
>>20	belong			>8192		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	041600410	NetBSD/m68k pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	041600407	NetBSD/m68k
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	belong			!0		executable
>>20	belong			=0		object file
>16	belong			>0		not stripped
0	belong&0377777777	041600507	NetBSD/m68k core
>12	string			>\0		from '%s'

0	belong&0377777777	042000413	NetBSD/m68k4k demand paged
>0	byte			&0x80		
>>20	belong			<4096		shared library
>>20	belong			=4096		dynamically linked executable
>>20	belong			>4096		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	042000410	NetBSD/m68k4k pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	042000407	NetBSD/m68k4k
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	belong			!0		executable
>>20	belong			=0		object file
>16	belong			>0		not stripped
0	belong&0377777777	042000507	NetBSD/m68k4k core
>12	string			>\0		from '%s'

0	belong&0377777777	042200413	NetBSD/ns32532 demand paged
>0	byte			&0x80		
>>20	lelong			<4096		shared library
>>20	lelong			=4096		dynamically linked executable
>>20	lelong			>4096		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	042200410	NetBSD/ns32532 pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	042200407	NetBSD/ns32532
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	lelong			!0		executable
>>20	lelong			=0		object file
>16	lelong			>0		not stripped
0	belong&0377777777	042200507	NetBSD/ns32532 core
>12	string			>\0		from '%s'

0	belong&0377777777	042400413	NetBSD/sparc demand paged
>0	byte			&0x80		
>>20	belong			<8192		shared library
>>20	belong			=8192		dynamically linked executable
>>20	belong			>8192		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	042400410	NetBSD/sparc pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	042400407	NetBSD/sparc
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	belong			!0		executable
>>20	belong			=0		object file
>16	belong			>0		not stripped
0	belong&0377777777	042400507	NetBSD/sparc core
>12	string			>\0		from '%s'

0	belong&0377777777	042600413	NetBSD/pmax demand paged
>0	byte			&0x80		
>>20	lelong			<4096		shared library
>>20	lelong			=4096		dynamically linked executable
>>20	lelong			>4096		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	042600410	NetBSD/pmax pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	042600407	NetBSD/pmax
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	lelong			!0		executable
>>20	lelong			=0		object file
>16	lelong			>0		not stripped
0	belong&0377777777	042600507	NetBSD/pmax core
>12	string			>\0		from '%s'

0	belong&0377777777	043000413	NetBSD/vax demand paged
>0	byte			&0x80		
>>20	lelong			<4096		shared library
>>20	lelong			=4096		dynamically linked executable
>>20	lelong			>4096		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	043000410	NetBSD/vax pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	043000407	NetBSD/vax
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	lelong			!0		executable
>>20	lelong			=0		object file
>16	lelong			>0		not stripped
0	belong&0377777777	043000507	NetBSD/vax core
>12	string			>\0		from '%s'

# NetBSD/alpha does not support (and has never supported) a.out objects,
# so no rules are provided for them.  NetBSD/alpha ELF objects are 
# dealt with in "elf".
0	leshort		0x00070185		ECOFF NetBSD/alpha binary
>10	leshort		0x0001			not stripped
>10	leshort		0x0000			stripped
0	belong&0377777777	043200507	NetBSD/alpha core
>12	string			>\0		from '%s'

0	belong&0377777777	043400413	NetBSD/mips demand paged
>0	byte			&0x80		
>>20	belong			<8192		shared library
>>20	belong			=8192		dynamically linked executable
>>20	belong			>8192		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	043400410	NetBSD/mips pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	belong			>0		not stripped
0	belong&0377777777	043400407	NetBSD/mips
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	belong			!0		executable
>>20	belong			=0		object file
>16	belong			>0		not stripped
0	belong&0377777777	043400507	NetBSD/mips core
>12	string			>\0		from '%s'

0	belong&0377777777	043600413	NetBSD/arm32 demand paged
>0	byte			&0x80
>>20	lelong			<8192		shared library
>>20	lelong			=8192		dynamically linked executable
>>20	lelong			>8192		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	043600410	NetBSD/arm32 pure
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80		executable
>16	lelong			>0		not stripped
0	belong&0377777777	043600407	NetBSD/arm32
>0	byte			&0x80		dynamically linked executable
>0	byte			^0x80
>>0	byte			&0x40		position independent
>>20	lelong			!0		executable
>>20	lelong			=0		object file
>16	lelong			>0		not stripped
0	belong&0377777777	043600507	NetBSD/arm32 core
>12	string			>\0		from '%s'

#------------------------------------------------------------------------------
# news:  file(1) magic for SunOS NeWS fonts (not "news" as in "netnews")
#
0	string		StartFontMetrics	ASCII font metrics
0	string		StartFont	ASCII font bits
0	belong		0x137A2944	NeWS bitmap font
0	belong		0x137A2947	NeWS font family
0	belong		0x137A2950	scalable OpenFont binary
0	belong		0x137A2951	encrypted scalable OpenFont binary
8	belong		0x137A2B45	X11/NeWS bitmap font
8	belong		0x137A2B48	X11/NeWS font family
#
# Mach magic number info
#
0	long		0xefbe	OSF/Rose object
# I386 magic number info
#
0	short		0565	i386 COFF object
#
0	string		Core	Alpha Digital UNIX core file
>24	string		>\0	\b, generated from '%s'

#------------------------------------------------------------------------------
# pbm:  file(1) magic for Portable Bitmap files
#
# XXX - byte order?
#
0	short	0x2a17	"compact bitmap" format (Poskanzer)
#------------------------------------------------------------------------------
# pdf:  file(1) magic for Portable Document Format
#

0	string		%PDF-		PDF document
>5	byte		x		\b, version %c
>7	byte		x		\b.%c

#------------------------------------------------------------------------------
# pdp:  file(1) magic for PDP-11 executable/object and APL workspace
#
0	lelong		0101555		PDP-11 single precision APL workspace
0	lelong		0101554		PDP-11 double precision APL workspace
#
# PDP-11 a.out
#
0	leshort		0407		PDP-11 executable
>8	leshort		>0		not stripped
>15	byte		>0		- version %ld

0	leshort		0401		PDP-11 UNIX/RT ldp
0	leshort		0405		PDP-11 old overlay

0	leshort		0410		PDP-11 pure executable
>8	leshort		>0		not stripped
>15	byte		>0		- version %ld

0	leshort		0411		PDP-11 separate I&D executable
>8	leshort		>0		not stripped
>15	byte		>0		- version %ld

0	leshort		0437		PDP-11 kernel overlay

#------------------------------------------------------------------------------
# pgp:  file(1) magic for Pretty Good Privacy
#
0       beshort         0x9900                  PGP key public ring
0       beshort         0x9501                  PGP key security ring
0       beshort         0x9500                  PGP key security ring
0	beshort		0xa600			PGP encrypted data
0       string          -----BEGIN\040PGP       PGP armored data
>15     string          PUBLIC\040KEY\040BLOCK- public key block
>15     string          MESSAGE-                message
>15     string          SIGNED\040MESSAGE-      signed message
>15     string          PGP\040SIGNATURE-       signature
# 
# magic.pjl: HP Printer Job Language (PJL)
# 
0	string		%-12345X@PJL	HP PJL (printer job language) commands
0	string		@PJL		HP PJL (printer job language) commands

#------------------------------------------------------------------------------
# pkgadd:  file(1) magic for SysV R4 PKG Datastreams
#
0       string          #\ PaCkAgE\ DaTaStReAm  pkg Datastream (SVR4)

#------------------------------------------------------------------------------
# plus5:  file(1) magic for Plus Five's UNIX MUMPS
#
# XXX - byte order?  Paging Hokey....
#
0	short		0x259		mumps avl global
>2	byte		>0		(V%d)
>6	byte		>0		with %d byte name
>7	byte		>0		and %d byte data cells
0	short		0x25a		mumps blt global
>2	byte		>0		(V%d)
>8	short		>0		- %d byte blocks
>15	byte		0x00		- P/D format
>15	byte		0x01		- P/K/D format
>15	byte		0x02		- K/D format
>15	byte		>0x02		- Bad Flags
#
# magic.postscript: Magic for postscript files
#
# XXX - should we match only versions 1.0 and 2.0, or should we wildcard
# it?
#
0	string		%!		PostScript document
>2	string	PS-Adobe-		conforming
>>11	string	1.0			at level %s
>>11	string	2.0			at level %s
>>11	string	3.0			at level %s
# Some pc's have the annoying habit of adding a ^D
0	string		\004%!		PostScript document
>3	string	PS-Adobe-		conforming
>>12	string	1.0			at level %s
>>12	string	2.0			at level %s
>>12	string	3.0			at level %s
0	string		%PDF		Adobe Acrobat document
>5	string		x		at level %s


#------------------------------------------------------------------------------
# printer:  file(1) magic for printer-formatted files
#

# PostScript, updated by Daniel Quinlan (quinlan@yggdrasil.com)
0	string		%!		PostScript document text
>2	string		PS-Adobe-	conforming
>>11	string		>\0		at level %.3s
>>>15	string		EPS		- type %s
>>>15	string		Query		- type %s
>>>15	string		ExitServer	- type %s
# Some PCs have the annoying habit of adding a ^D as a document separator
0	string		\004%!		PostScript document text
>3	string		PS-Adobe-	conforming
>>12	string		>\0		at level %.3s
>>>16	string		EPS		- type %s
>>>16	string		Query		- type %s
>>>16	string		ExitServer	- type %s

# HP Printer Job Language
0	string		\033%-12345X@PJL	HP Printer Job Language data
>15	string		\ ENTER\ LANGUAGE\ =
>31	string		PostScript		PostScript

# HP Printer Control Language, Daniel Quinlan (quinlan@yggdrasil.com)
0	string		\033E\033	HP PCL printer data
>3	string		\&l0A		- default page size
>3	string		\&l1A		- US executive page size
>3	string		\&l2A		- US letter page size
>3	string		\&l3A		- US legal page size
>3	string		\&l26A		- A4 page size
>3	string		\&l80A		- Monarch envelope size
>3	string		\&l81A		- No. 10 envelope size
>3	string		\&l90A		- Intl. DL envelope size
>3	string		\&l91A		- Intl. C5 envelope size
>3	string		\&l100A		- Intl. B5 envelope size
>3	string		\&l-81A		- No. 10 envelope size (landscape)
>3	string		\&l-90A		- Intl. DL envelope size (landscape)

# IMAGEN printer-ready files:
0	string	@document(		Imagen printer
# this only works if "language xxx" is first item in Imagen header.
>10	string	language\ impress	(imPRESS data)
>10	string	language\ daisy		(daisywheel text)
>10	string	language\ diablo	(daisywheel text)
>10	string	language\ printer	(line printer emulation)
>10	string	language\ tektronix	(Tektronix 4014 emulation)
# Add any other languages that your Imagen uses - remember
# to keep the word `text' if the file is human-readable.
# [GRR 950115:  missing "postscript" or "ultrascript" (whatever it was called)]
#
# Now magic for IMAGEN font files...
0	string		Rast		RST-format raster font data
>45	string		>0		face %

#------------------------------------------------------------------------------
# psdbms:  file(1) magic for psdatabase
#
0	belong&0xff00ffff	0x56000000	ps database
>1	string	>\0	version %s
>4	string	>\0	from kernel %s

#------------------------------------------------------------------------------
# pyramid:  file(1) magic for Pyramids
#
# XXX - byte order?
#
0	long		0x50900107	Pyramid 90x family executable
0	long		0x50900108	Pyramid 90x family pure executable
>16	long		>0		not stripped
0	long		0x5090010b	Pyramid 90x family demand paged pure executable
>16	long		>0		not stripped
# From <janl@ifi.uio.no>
# I made this with the help of the man page for rle(5). Ihey missing
# from the magic numbers I have:

#
# rle
#
0       short           0xcc52          Utah Raster Toolkit RLE
>2      short           >0              lower left corner: %d
>4      short           >0              lower right corner: %d
>6      short           >0              %d x
>8      short           >0              %d
>10     byte&0x1        =0x1            CLEARFIRST
>10     byte&0x2        =0x2            NO_BACKGROUND
>10     byte&0x4        =0x4            ALPHA
>10     byte&0x8        =0x8            COMMENT
>11     byte            >0              %d colour channels
>12     byte            >0              %d bits pr. pixel
>13     byte            >0              %d colour map channels
#------------------------------------------------------------------------------
#
# RPM: file(1) magic for Red Hat Packages   Erik Troan (ewt@redhat.com)
#
0	beshort		0xedab    	
>2	beshort		0xeedb		RPM
>>4	byte		x		v%d
>>6	beshort		0		bin
>>6	beshort		1		src
>>8	beshort		1		i386
>>8	beshort		2		Alpha
>>8	beshort		3		Sparc
>>8	beshort		4		MIPS
>>8	beshort		5		PowerPC
>>8	beshort		6		68000
>>8     beshort         7               SGI
>>10	string		x		%s

#------------------------------------------------------------------------------
# rtf:	file(1) magic for Rich Text Format (RTF)
#
# Duncan P. Simpson, D.P.Simpson@dcs.warwick.ac.uk
#
0	string		{\\rtf		Rich Text Format data,
>5	byte		x		version %c,
>6	string		\\ansi		ANSI
>6	string		\\mac		Apple Macintosh
>6	string		\\pc		IBM PC, code page 437
>6	string		\\pca		IBM PS/2, code page 850

#------------------------------------------------------------------------------
# sc:  file(1) magic for "sc" spreadsheet
#
38	string		Spreadsheet	sc spreadsheet file

#------------------------------------------------------------------------------
# sccs:  file(1) magic for SCCS archives
#
# SCCS archive structure:
# \001h01207
# \001s 00276/00000/00000
# \001d D 1.1 87/09/23 08:09:20 ian 1 0
# \001c date and time created 87/09/23 08:09:20 by ian
# \001e
# \001u
# \001U
# ... etc.
# Now '\001h' happens to be the same as the 3B20's a.out magic number (0550).
# *Sigh*. And these both came from various parts of the USG.
# Maybe we should just switch everybody from SCCS to RCS!
# Further, you can't just say '\001h0', because the five-digit number
# is a checksum that could (presumably) have any leading digit,
# and we don't have regular expression matching yet. 
# Hence the following official kludge:
8	string		\001s\ 			SCCS archive data

#------------------------------------------------------------------------------
# sendmail:  file(1) magic for sendmail config files
#
# XXX - byte order?
#
0	byte	046	  Sendmail frozen configuration 
>16	string	>\0	  - version %s
0	short	0x271c	  Sendmail frozen configuration
>16	string	>\0	  - version %s

#------------------------------------------------------------------------------
# sequent:  file(1) magic for Sequent machines
#
# Sequent information updated by Don Dwiggins <atsun!dwiggins>.
# For Sequent's multiprocessor systems (incomplete).
0	lelong	0x00ea        	BALANCE NS32000 .o
>16	lelong	>0		not stripped
>124	lelong	>0		version %ld
0	lelong	0x10ea        	BALANCE NS32000 executable (0 @ 0)
>16	lelong  >0            	not stripped
>124	lelong	>0		version %ld
0	lelong	0x20ea        	BALANCE NS32000 executable (invalid @ 0)
>16	lelong  >0            	not stripped
>124	lelong	>0		version %ld
0	lelong	0x30ea        	BALANCE NS32000 standalone executable
>16	lelong  >0          	not stripped
>124	lelong	>0		version %ld
#
# Symmetry information added by Jason Merrill <jason@jarthur.claremont.edu>.
# Symmetry magic nums will not be reached if DOS COM comes before them;
# byte 0xeb is matched before these get a chance.
0	leshort	0x12eb		SYMMETRY i386 .o
>16	lelong	>0		not stripped
>124	lelong	>0		version %ld
0	leshort	0x22eb		SYMMETRY i386 executable (0 @ 0)
>16	lelong	>0		not stripped
>124	lelong	>0		version %ld
0	leshort	0x32eb		SYMMETRY i386 executable (invalid @ 0)
>16	lelong	>0		not stripped
>124	lelong	>0		version %ld
0	leshort	0x42eb		SYMMETRY i386 standalone executable
>16	lelong	>0		not stripped
>124	lelong	>0		version %ld

#------------------------------------------------------------------------------
# sgi:  file(1) magic for Silicon Graphics (MIPS, IRIS, IRIX, etc.)
#                         Dec Ultrix (MIPS)
# all of SGI's *current* machines and OSes run in big-endian mode on the
# MIPS machines, as far as I know.
#
# XXX - what is the blank "-" line?
#
# kbd file definitions
0	string	kbd!map		kbd map file
>8	byte	>0		Ver %d:
>10	short	>0		with %d table(s)
0	belong	0407		old SGI 68020 executable
0	belong	0410		old SGI 68020 pure executable
0	beshort	0x8765		disk quotas file
0	beshort	0x0506		IRIS Showcase file
>2	byte	0x49		-
>3	byte	x		- version %ld
0	beshort	0x0226		IRIS Showcase template
>2	byte	0x63		-
>3	byte	x		- version %ld
0	belong	0x5343464d	IRIS Showcase file
>4	byte	x		- version %ld
0	belong	0x5443464d	IRIS Showcase template
>4	byte	x		- version %ld
0	belong	0xdeadbabe	IRIX Parallel Arena
>8	belong	>0		- version %ld
#
0	beshort	0x0160		MIPSEB COFF executable
>20	beshort	0407		(impure)
>20	beshort	0410		(swapped)
>20	beshort	0413		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>22	byte	x		- version %ld
>23	byte	x		.%ld
#
0	beshort	0x0162		MIPSEL COFF executable
>20	beshort	0407		(impure)
>20	beshort	0410		(swapped)
>20	beshort	0413		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>23	byte	x		- version %d
>22	byte	x		.%ld
#
0	beshort	0x6001		MIPSEB-LE COFF executable
>20	beshort	03401		(impure)
>20	beshort	04001		(swapped)
>20	beshort	05401		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>23	byte	x		- version %d
>22	byte	x		.%ld
#
0	beshort	0x6201		MIPSEL-LE COFF executable
>20	beshort	03401		(impure)
>20	beshort	04001		(swapped)
>20	beshort	05401		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>23	byte	x		- version %ld
>22	byte	x		.%ld
#
# MIPS 2 additions
#
0	beshort	0x0163		MIPSEB MIPS-II COFF executable
>20	beshort	0407		(impure)
>20	beshort	0410		(swapped)
>20	beshort	0413		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>22	byte	x		- version %ld
>23	byte	x		.%ld
#
0	beshort	0x0166		MIPSEL MIPS-II COFF executable
>20	beshort	0407		(impure)
>20	beshort	0410		(swapped)
>20	beshort	0413		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>22	byte	x		- version %ld
>23	byte	x		.%ld
#
0	beshort	0x6301		MIPSEB-LE MIPS-II COFF executable
>20	beshort	03401		(impure)
>20	beshort	04001		(swapped)
>20	beshort	05401		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>23	byte	x		- version %ld
>22	byte	x		.%ld
#
0	beshort	0x6601		MIPSEL-LE MIPS-II COFF executable
>20	beshort	03401		(impure)
>20	beshort	04001		(swapped)
>20	beshort	05401		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>23	byte	x		- version %ld
>22	byte	x		.%ld
#
# MIPS 3 additions
#
0	beshort	0x0140		MIPSEB MIPS-III COFF executable
>20	beshort	0407		(impure)
>20	beshort	0410		(swapped)
>20	beshort	0413		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>22	byte	x		- version %ld
>23	byte	x		.%ld
#
0	beshort	0x0142		MIPSEL MIPS-III COFF executable
>20	beshort	0407		(impure)
>20	beshort	0410		(swapped)
>20	beshort	0413		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>22	byte	x		- version %ld
>23	byte	x		.%ld
#
0	beshort	0x4001		MIPSEB-LE MIPS-III COFF executable
>20	beshort	03401		(impure)
>20	beshort	04001		(swapped)
>20	beshort	05401		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>23	byte	x		- version %ld
>22	byte	x		.%ld
#
0	beshort	0x4201		MIPSEL-LE MIPS-III COFF executable
>20	beshort	03401		(impure)
>20	beshort	04001		(swapped)
>20	beshort	05401		(paged)
>8	belong	>0		not stripped
>8	belong	0		stripped
>23	byte	x		- version %ld
>22	byte	x		.%ld
#
0	beshort	0x180		MIPSEB Ucode
0	beshort	0x182		MIPSEL Ucode
# 32bit core file
0	belong	0xdeadadb0	IRIX core dump
>4	belong	1		of
>16	string	>\0		'%s'
# 64bit core file
0	belong	0xdeadad40	IRIX 64-bit core dump
>4	belong	1		of
>16	string	>\0		'%s'
# New style crash dump file
0	string	\x43\x72\x73\x68\x44\x75\x6d\x70	IRIX vmcore dump of
>36	string	>\0					'%s'
# Trusted IRIX info
0	string	SGIAUDIT	SGI Audit file
>8	byte	x		- version %d
>9	byte	x		.%ld
# Are these three SGI-based file types or general ones?
0	string	WNGZWZSC	Wingz compiled script
0	string	WNGZWZSS	Wingz spreadsheet
0	string	WNGZWZHP	Wingz help file
#
0	string	\#Inventor V	IRIS Inventor 1.0 file
0	string	\#Inventor V2	Open Inventor 2.0 file
# XXX - I don't know what next thing is!  It is likely to be an image
# (or movie) format
0	string	glfHeadMagic();		GLF_TEXT
4	belong	0x41010000		GLF_BINARY_LSB_FIRST
4	belong	0x00000141		GLF_BINARY_MSB_FIRST

#------------------------------------------------------------------------------
# sgml:  file(1) magic for Standard Generalized Markup Language

# HyperText Markup Language (HTML) is an SGML document type,
# from Daniel Quinlan (quinlan@yggdrasil.com)
0	string		\<!DOCTYPE\ HTML	HTML document text
0	string		\<!doctype\ html	HTML document text
0	string		\<HEAD		HTML document text
0	string		\<head		HTML document text
0	string		\<TITLE		HTML document text
0	string		\<title		HTML document text
0	string		\<html		HTML document text
0	string		\<HTML		HTML document text

# SGML, mostly from rph@sq
0	string		\<!DOCTYPE	exported SGML document text
0	string		\<!doctype	exported SGML document text
0	string		\<!SUBDOC	exported SGML subdocument text
0	string		\<!subdoc	exported SGML subdocument text
0	string		\<!--		exported SGML document text

#------------------------------------------------------------------------------
# sniffer:  file(1) magic for packet captured files
#
# From: guy@netapp.com (Guy Harris)
#
# Microsoft NetMon (packet capture/display program) capture files.
#
0	string		RTSS		NetMon capture file
>4	byte		x		- version %d
>5	byte		x		\b.%d
#
# Network General Sniffer capture files (the Sniffer software does,
# after all, run under MS-DOS...).
#
0	string		TRSNIFF\ data\ \ \ \ \032	Sniffer capture file
>23	leshort		x		- version %d
>25	leshort		x		\b.%d
>33	byte		x		(Format %d,
>32	byte		0		Token ring)
>32	byte		1		Ethernet)
>32	byte		2		ARCnet)
>32	byte		3		StarLAN)
>32	byte		4		PC Network broadband)
>32	byte		5		LocalTalk)
>32	byte		6		Znet)
#
# (We call them "tcpdump capture file(s)" for now, as "tcpdump" is
# the main program that uses that format, but there's also "tcpview",
# and there may be others in the future.)
#
0	ubelong		0xa1b2c3d4	tcpdump capture file (big-endian)
>4	beshort		x		- version %d
>6	beshort		x		\b.%d
>20	belong		0		(No link-layer encapsulation
>20	belong		1		(Ethernet
>20	belong		2		(3Mb Ethernet
>20	belong		3		(AX.25
>20	belong		4		(ProNet
>20	belong		5		(Chaos
>20	belong		6		(IEEE 802.x network
>20	belong		7		(ARCnet
>20	belong		8		(SLIP
>20	belong		9		(PPP
>20	belong		10		(FDDI
>20	belong		11		(RFC 1483 ATM
>16	belong		x		\b, capture length %d)
0	ulelong		0xa1b2c3d4	tcpdump capture file (little-endian)
>4	leshort		x		- version %d
>6	leshort		x		\b.%d
>20	lelong		0		(No link-layer encapsulation
>20	lelong		1		(Ethernet
>20	lelong		2		(3Mb Ethernet
>20	lelong		3		(AX.25
>20	lelong		4		(ProNet
>20	lelong		5		(Chaos
>20	lelong		6		(IEEE 802.x network
>20	lelong		7		(ARCnet
>20	lelong		8		(SLIP
>20	lelong		9		(PPP
>20	lelong		10		(FDDI
>20	lelong		11		(RFC 1483 ATM
>16	lelong		x		\b, capture length %d)

#------------------------------------------------------------------------------
# softquad:  file(1) magic for SoftQuad Publishing Software
#
# $Id$
# Author/Editor and RulesBuilder
#
# XXX - byte order?
#
0	string		\<!SQ\ DTD>	Compiled SGML rules file
>9	string		>\0		 Type %s
0	string		\<!SQ\ A/E>	A/E SGML Document binary
>9	string		>\0		 Type %s
0	string		\<!SQ\ STS>	A/E SGML binary styles file
>9	string		>\0		 Type %s
0	short		0xc0de		Compiled PSI (v1) data
0	short		0xc0da		Compiled PSI (v2) data
>3	string		>\0		(%s)
# Binary sqtroff font/desc files...
0	short		0125252		SoftQuad DESC or font file binary
>2	short		>0		- version %d
# Bitmaps...
0	string		SQ\ BITMAP1	SoftQuad Raster Format text
#0	string		SQ\ BITMAP2	SoftQuad Raster Format data
# sqtroff intermediate language (replacement for ditroff int. lang.)
0	string		X\ 		SoftQuad troff Context intermediate
>2	string		495		for AT&T 495 laser printer
>2	string		hp		for Hewlett-Packard LaserJet
>2	string		impr		for IMAGEN imPRESS
>2	string		ps		for PostScript

#------------------------------------------------------------------------------
# sun:  file(1) magic for Sun machines
#
# Values for big-endian Sun (MC680x0, SPARC) binaries on pre-5.x
# releases.  (5.x uses ELF.)
#
0	belong&077777777	0600413		sparc demand paged
>0	byte		&0x80
>>20	belong		<4096		shared library
>>20	belong		=4096		dynamically linked executable
>>20	belong		>4096		dynamically linked executable
>0	byte		^0x80		executable
>16	belong		>0		not stripped
0	belong&077777777	0600410		sparc pure
>0	byte		&0x80		dynamically linked executable
>0	byte		^0x80		executable
>16	belong		>0		not stripped
0	belong&077777777	0600407		sparc
>0	byte		&0x80		dynamically linked executable
>0	byte		^0x80		executable
>16	belong		>0		not stripped

0	belong&077777777	0400413		mc68020 demand paged
>0	byte		&0x80
>>20	belong		<4096		shared library
>>20	belong		=4096		dynamically linked executable
>>20	belong		>4096		dynamically linked executable
>16	belong		>0		not stripped
0	belong&077777777	0400410		mc68020 pure
>0	byte		&0x80		dynamically linked executable
>0	byte		^0x80		executable
>16	belong		>0		not stripped
0	belong&077777777	0400407		mc68020
>0	byte		&0x80		dynamically linked executable
>0	byte		^0x80		executable
>16	belong		>0		not stripped

0	belong&077777777	0200413		mc68010 demand paged
>0	byte		&0x80
>>20	belong		<4096		shared library
>>20	belong		=4096		dynamically linked executable
>>20	belong		>4096		dynamically linked executable
>16	belong		>0		not stripped
0	belong&077777777	0200410		mc68010 pure
>0	byte		&0x80		dynamically linked executable
>0	byte		^0x80		executable
>16	belong		>0		not stripped
0	belong&077777777	0200407		mc68010
>0	byte		&0x80		dynamically linked executable
>0	byte		^0x80		executable
>16	belong		>0		not stripped

# reworked these to avoid anything beginning with zero becoming "old sun-2"
0	belong		0407		old sun-2 executable
>16	belong		>0		not stripped
0	belong		0410		old sun-2 pure executable
>16	belong		>0		not stripped
0	belong		0413		old sun-2 demand paged executable
>16	belong		>0		not stripped

#
# Core files.  "SPARC 4.x BCP" means "core file from a SunOS 4.x SPARC
# binary executed in compatibility mode under SunOS 5.x".
#
0	belong		0x080456	SunOS core file
>4	belong		432		(SPARC)
>>132	string		>\0		from '%s'
>>116	belong		=3		(quit)
>>116	belong		=4		(illegal instruction)
>>116	belong		=5		(trace trap)
>>116	belong		=6		(abort)
>>116	belong		=7		(emulator trap)
>>116	belong		=8		(arithmetic exception)
>>116	belong		=9		(kill)
>>116	belong		=10		(bus error)
>>116	belong		=11		(segmentation violation)
>>116	belong		=12		(bad argument to system call)
>>116	belong		=29		(resource lost)
>>120	belong		x		(T=%dK,
>>124	belong		x		D=%dK,
>>128	belong		x		S=%dK)
>4	belong		826		(68K)
>>128	string		>\0		from '%s'
>4	belong		456		(SPARC 4.x BCP)
>>152	string		>\0		from '%s'
# Sun SunPC
0	long		0xfa33c08e	SunPC 4.0 Hard Disk
0	string		#SUNPC_CONFIG	SunPC 4.0 Properties Values
# Sun snoop
#
# XXX - are numbers stored in big-endian format, or in host byte order?
# They're the same on SPARC, but not the same on x86.
#
0	string		snoop		Snoop capture file
>8	long		>0		- version %ld
>12	long		0		(IEEE 802.3)
>12	long		1		(IEEE 802.4)
>12	long		2		(IEEE 802.5)
>12	long		3		(IEEE 802.6)
>12	long		4		(Ethernet)
>12	long		5		(HDLC)
>12	long		6		(Character synchronous)
>12	long		7		(IBM channel-to-channel adapter)
>12	long		8		(FDDI)
>12	long		9		(Unknown)
# Sun KCMS
36	string		acsp		Kodak Color Management System, ICC Profile


#
# Sun rasterfiles
#
# XXX - byte order?  What about the 386i?
#
0	string	\x59\xa6\x6a\x95	rasterfile
>4	belong	>0		%d
>8	belong	>0		x %d
>12	belong	>0		x %d
>20	belong	0		old format
>20	belong	2		compressed
>24	belong	1		with color map

#------------------------------------------------------------------------------
# terminfo:  file(1) magic for terminfo
#
# XXX - byte order for screen images?
#
0	string		\032\001	Compiled terminfo entry
0	short		0433		Curses screen image
0	short		0434		Curses screen image

#------------------------------------------------------------------------------
# tex:  file(1) magic for TeX files
#
# From <conklin@talisman.kaleida.com>

# Although we may know the offset of certain text fields in TeX DVI
# and font files, we can't use them reliably because they are not
# zero terminated. [but we do anyway, christos]
0	string		\367\002	TeX DVI file
>16	string		>\0		(%s)
0	string		\367\203	TeX generic font data
0	string		\367\131	TeX packed font data
>3	string		>\0		(%s)
0	string		\367\312	TeX virtual font data
0	string		This\ is\ TeX,	TeX transcript text
0	string		This\ is\ METAFONT,	METAFONT transcript text

# There is no way to detect TeX Font Metric (*.tfm) files without
# breaking them apart and reading the data.  The following patterns
# match most *.tfm files generated by METAFONT or afm2tfm.
2	string		\000\021	TeX font metric data
>33	string		>\0		(%s)
2	string		\000\022	TeX font metric data
>33	string		>\0		(%s)

# Texinfo and GNU Info, from Daniel Quinlan (quinlan@yggdrasil.com)
0	string		\\input\ texinfo	Texinfo source text
0	string		This\ is\ Info\ file	GNU Info text

# TeX documents, from Daniel Quinlan (quinlan@yggdrasil.com)
0	string		\\input		TeX document text
0	string		\\section	LaTeX document text
0	string		\\setlength	LaTeX document text
0	string		\\documentstyle	LaTeX document text
0	string		\\chapter	LaTeX document text

#------------------------------------------------------------------------------
# timezone:  file(1) magic for timezone data
#
# from Daniel Quinlan (quinlan@yggdrasil.com)
# this should work on Linux, SunOS, and maybe others
0	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0	timezone data
0	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\2\0	timezone data
0	string  \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\3\0	timezone data
0	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0	timezone data
0	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0	timezone data
0	string	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\6\0	timezone data

#------------------------------------------------------------------------------
# troff:  file(1) magic for *roff
#
# updated by Daniel Quinlan (quinlan@yggdrasil.com)

# troff input
0	string		.\\"		troff or preprocessor input text
0	string		'\\"		troff or preprocessor input text
0	string		'.\\"		troff or preprocessor input text
0	string		\\"		troff or preprocessor input text

# ditroff intermediate output text
0	string		x\ T		ditroff text
>4	string		cat		for the C/A/T phototypesetter
>4	string		ps		for PostScript
>4	string		dvi		for DVI
>4	string		ascii		for ASCII
>4	string		lj4		for LaserJet 4
>4	string		latin1		for ISO 8859-1 (Latin 1)
>4	string		X75		for xditview at 75dpi
>>7	string		-12		(12pt)
>4	string		X100		for xditview at 100dpi
>>8	string		-12		(12pt)

# output data formats
0	string		\100\357	very old (C/A/T) troff output data

#------------------------------------------------------------------------------
# typeset:  file(1) magic for other typesetting
#
0	string		Interpress/Xerox	Xerox InterPress data
>16	string		/			(version
>>17	string		>\0			%s)

#------------------------------------------------------------------------------
# unknown:  file(1) magic for unknown machines
#
# XXX - this probably should be pruned, as it'll match PDP-11 and
# VAX image formats.
#
# 0x107 is 0407; 0x108 is 0410; both are PDP-11 (executable and pure,
# respectively).
#
# 0x109 is 0411; that's PDP-11 split I&D, but the PDP-11 version doesn't
# have the "version %ld", which may be a bogus COFFism (I don't think
# there ever was COFF for the PDP-11).
#
# 0x10B is 0413; that's VAX demand-paged, but this is a short, not a
# long, as it would be on a VAX.
#
# 0x10C is 0414, 0x10D is 0415, and 0x10E is 416; those *are* unknown.
#
0	short		0x107		unknown machine executable
>8	short		>0		not stripped
>15	byte		>0		- version %ld
0	short		0x108		unknown pure executable
>8	short		>0		not stripped
>15	byte		>0		- version %ld
0	short		0x109		PDP-11 separate I&D
>8	short		>0		not stripped
>15	byte		>0		- version %ld
0	short		0x10b		unknown pure executable
>8	short		>0		not stripped
>15	byte		>0		- version %ld
0	long		0x10c		unknown demand paged pure executable
>16	long		>0		not stripped
0	long		0x10d		unknown demand paged pure executable
>16	long		>0		not stripped
0	long		0x10e		unknown readable demand paged pure executable

#------------------------------------------------------------------------------
# uuencode:  file(1) magic for ASCII-encoded files
#

# GRR:  the first line of xxencoded files is identical to that in uuencoded
# files, but the first character in most subsequent lines is 'h' instead of
# 'M'.  (xxencoding uses lowercase letters in place of most of uuencode's
# punctuation and survives BITNET gateways better.)  If regular expressions
# were supported, this entry could possibly be split into two with
# "begin\040\.\*\012M" or "begin\040\.\*\012h" (where \. and \* are REs).
0	string		begin\040	uuencoded or xxencoded text

# btoa(1) is an alternative to uuencode that requires less space.
0	string		xbtoa\ Begin	btoa'd text

# ship(1) is another, much cooler alternative to uuencode.
# Greg Roelofs, newt@uchicago.edu
0	string		$\012ship	ship'd binary text

# bencode(8) is used to encode compressed news batches (Bnews/Cnews only?)
# Greg Roelofs, newt@uchicago.edu
0	string	Decode\ the\ following\ with\ bdeco	bencoded News text

# BinHex is the Macintosh ASCII-encoded file format (see also "apple")
# Daniel Quinlan, quinlan@yggdrasil.com
11	string	must\ be\ converted\ with\ BinHex	BinHex binary text
>41	string	x					\b, version %.3s

# GRR:  is MIME BASE64 encoding handled somewhere?

#------------------------------------------------------------------------------
# varied.out:  file(1) magic for various USG systems
#
#	Herewith many of the object file formats used by USG systems.
#	Most have been moved to files for a particular processor,
#	and deleted if they duplicate other entries.
#
0	short		0610		Perkin-Elmer executable
# AMD 29K
0	beshort		0572		amd 29k coff noprebar executable
0	beshort		01572		amd 29k coff prebar executable
0	beshort		0160007		amd 29k coff archive
# Cray
6	beshort		0407		unicos (cray) executable
# Ultrix 4.3
596	string		\130\337\377\377	Ultrix core file
>600	string		>\0	'%s'

#------------------------------------------------------------------------------
# vax:  file(1) magic for VAX executable/object and APL workspace
#
0	lelong		0101557		VAX single precision APL workspace
0	lelong		0101556		VAX double precision APL workspace

#
# VAX a.out (32V, BSD)
#
0	lelong		0407		VAX executable
>16	lelong		>0		not stripped

0	lelong		0410		VAX pure executable
>16	lelong		>0		not stripped

0	lelong		0413		VAX demand paged pure executable
>16	lelong		>0		not stripped

0	lelong		0420		VAX demand paged (first page unmapped) pure executable
>16	lelong		>0		not stripped

#
# VAX COFF
#
# The `versions' should be un-commented if they work for you.
# (Was the problem just one of endianness?)
#
0	leshort		0570		VAX COFF executable
>12	lelong		>0		not stripped
>22	leshort		>0		- version %ld
0	leshort		0575		VAX COFF pure executable
>12	lelong		>0		not stripped
>22	leshort		>0		- version %ld

#------------------------------------------------------------------------------
# visx:  file(1) magic for Visx format files
#
0	short		0x5555		VISX image file
>2	byte		0		(zero)
>2	byte		1		(unsigned char)
>2	byte		2		(short integer)
>2	byte		3		(float 32)
>2	byte		4		(float 64)
>2	byte		5		(signed char)
>2	byte		6		(bit-plane)
>2	byte		7		(classes)
>2	byte		8		(statistics)
>2	byte		10		(ascii text)
>2	byte		15		(image segments)
>2	byte		100		(image set)
>2	byte		101		(unsigned char vector)
>2	byte		102		(short integer vector)
>2	byte		103		(float 32 vector)
>2	byte		104		(float 64 vector)
>2	byte		105		(signed char vector)
>2	byte		106		(bit plane vector)
>2	byte		121		(feature vector)
>2	byte		122		(feature vector library)
>2	byte		124		(chain code)
>2	byte		126		(bit vector)
>2	byte		130		(graph)
>2	byte		131		(adjacency graph)
>2	byte		132		(adjacency graph library)
>2	string		.VISIX		(ascii text)

#------------------------------------------------------------------------------
# vms:  file(1) magic for VMS executables (experimental)
#
# VMS .exe formats, both VAX and AXP (Greg Roelofs, newt@uchicago.edu)

# GRR 950122:  I'm just guessing on these, based on inspection of the headers
# of three executables each for Alpha and VAX architectures.  The VAX files
# all had headers similar to this:
#
#   00000  b0 00 30 00 44 00 60 00  00 00 00 00 30 32 30 35  ..0.D.`.....0205
#   00010  01 01 00 00 ff ff ff ff  ff ff ff ff 00 00 00 00  ................
#
0	string	\xb0\0\x30\0	VMS VAX executable
>44032	string	PK\003\004	\b, Info-ZIP SFX archive v5.12 w/decryption
#
# The AXP files all looked like this, except that the byte at offset 0x22
# was 06 in some of them and 07 in others:
#
#   00000  03 00 00 00 00 00 00 00  ec 02 00 00 10 01 00 00  ................
#   00010  68 00 00 00 98 00 00 00  b8 00 00 00 00 00 00 00  h...............
#   00020  00 00 07 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
#   00030  00 00 00 00 01 00 00 00  00 00 00 00 00 00 00 00  ................
#   00040  00 00 00 00 ff ff ff ff  ff ff ff ff 02 00 00 00  ................
#
0	belong	0x03000000	VMS Alpha executable
>75264	string	PK\003\004	\b, Info-ZIP SFX archive v5.12 w/decryption
#
# magic.x11
#
# I think this is byte-order-dependent; if so, it should become:
#
# 0	belong	00000004	X11 big-endian snf font
# 0	lelong	00000004	X11 little-endian snf font
#
0	long	00000004	X11 snf font
0	string	STARTFONT	X11 bdf font text
0	string	/*\040XPM\040*/	X11 XPM pixmap text

#------------------------------------------------------------------------------
# xenix:  file(1) magic for Microsoft Xenix
#
# "Middle model" stuff, and "Xenix 8086 relocatable or 80286 small
# model" lifted from "magic.xenix", with comment "derived empirically;
# treat as folklore until proven"
#
# "small model", "large model", "huge model" stuff lifted from XXX
#
# XXX - "x.out" collides with PDP-11 archives
#
0	string		core		core file (Xenix)
0	byte		0x80		8086 relocatable (Microsoft)
0	leshort		0xff65		x.out
>2	string		__.SYMDEF	 randomized
>0	byte		x		archive
0	leshort		0x206		Microsoft a.out
>8	leshort		1		Middle model
>0x1e	leshort		&0x10		overlay
>0x1e	leshort		&0x2		separate
>0x1e	leshort		&0x4		pure
>0x1e	leshort		&0x800		segmented
>0x1e	leshort		&0x400		standalone
>0x1e	leshort		&0x8		fixed-stack
>0x1c	byte		&0x80		byte-swapped
>0x1c	byte		&0x40		word-swapped
>0x10	lelong		>0		not-stripped
>0x1e	leshort		^0xc000		pre-SysV
>0x1e	leshort		&0x4000		V2.3
>0x1e	leshort		&0x8000		V3.0
>0x1c	byte		&0x4		86
>0x1c	byte		&0xb		186
>0x1c	byte		&0x9		286
>0x1c	byte		&0xa		386
>0x1f	byte		<0x040		small model
>0x1f	byte		=0x048		large model	
>0x1f	byte		=0x049		huge model 
>0x1e	leshort		&0x1		executable
>0x1e	leshort		^0x1		object file
>0x1e	leshort		&0x40		Large Text
>0x1e	leshort		&0x20		Large Data
>0x1e	leshort		&0x120		Huge Objects Enabled
>0x10	lelong		>0		not stripped

0	leshort		0x140		old Microsoft 8086 x.out
>0x3	byte		&0x4		separate
>0x3	byte		&0x2		pure
>0	byte		&0x1		executable
>0	byte		^0x1		relocatable
>0x14	lelong		>0		not stripped

0	lelong		0x206		b.out
>0x1e	leshort		&0x10		overlay
>0x1e	leshort		&0x2		separate
>0x1e	leshort		&0x4		pure
>0x1e	leshort		&0x800		segmented
>0x1e	leshort		&0x400		standalone
>0x1e	leshort		&0x1		executable
>0x1e	leshort		^0x1		object file
>0x1e	leshort		&0x4000		V2.3
>0x1e	leshort		&0x8000		V3.0
>0x1c	byte		&0x4		86
>0x1c	byte		&0xb		186
>0x1c	byte		&0x9		286
>0x1c	byte		&0x29		286
>0x1c	byte		&0xa		386
>0x1e	leshort		&0x4		Large Text
>0x1e	leshort		&0x2		Large Data
>0x1e	leshort		&0x102		Huge Objects Enabled

0	leshort		0x580		XENIX 8086 relocatable or 80286 small model

#------------------------------------------------------------------------------
# zilog:  file(1) magic for Zilog Z8000.
#
# Was it big-endian or little-endian?  My Product Specification doesn't
# say.
#
0	long		0xe807		object file (z8000 a.out)
0	long		0xe808		pure object file (z8000 a.out)
0	long		0xe809		separate object file (z8000 a.out)
0	long		0xe805		overlay object file (z8000 a.out)

#------------------------------------------------------------------------------
# zyxel:  file(1) magic for ZyXEL modems
#
# From <rob@pe1chl.ampr.org>
# These are the /etc/magic entries to decode datafiles as used for the
# ZyXEL U-1496E DATA/FAX/VOICE modems.  (This header conforms to a
# ZyXEL-defined standard)

0	string		ZyXEL\002	ZyXEL voice data
>10	byte		0		- CELP encoding
>10	byte&0x0B	1		- ADPCM2 encoding
>10	byte&0x0B	2		- ADPCM3 encoding
>10	byte&0x0B	3		- ADPCM4 encoding
>10	byte&0x0B	8		- New ADPCM3 encoding
>10	byte&0x04	4		with resync

Added lib/termcap.

























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#
# TERMCAP - Terminal Capabilities Database
#

#
# NANSI with insert/delete line
#
nansi|pcterm|NANSI enhanced ansi.sys driver:\
	:co#80:li#25:cl=\E[2J:am:bs:cm=\E[%i%2;%2H:nd=\E[C:up=\E[A:\
	:ce=\E[K:\
	:so=\E[7m:se=\E[m:\
	:do=\E[B:mi:ms:\
	:kd=\EP:kl=\EK:ku=\EH:kr=\EM:kh=\EG:\
	:AL=\E[%dL:al=\E[L:\
	:DL=\E[%dM:dl=\E[M:\
	:IC=\E[%d@:ic=\E[@:\
	:DC=\E[%dP:dc=\E[P:

#
# MGR Windowing system terminal emulation
#
mgr|MGR terminal:\
  :am:bs:im=:ta=^I:\
  :AL=\E%da:al=\Ea:\
  :cd=\EC:ce=\Ec:cl=^L:\
  :cm=\E%r%d,%dM:\
  :co#80:li#24:\
  :cs=\E%d,%dt:\
  :DC=\E%dE:dc=\EE:\
  :DL=\E%dd:dl=\Ed:\
  :do=\Ef:up=\Eu:nd=\Er:\
  :IC=\E%dA:ic=\EA:\
  :se=\En:so=\Ei:\
  :ve=\Ev:vs=\EV:

#
# Hersey Micro-Consulting's FANSI-CONSOLE
#
fc|fansi|Hersey Micro-Consultings Fast ANSI Console Driver:\
	:co#80:li#25:am:bs:cm=\E[%i%2;%2H:nd=\E[C:up=\E[A:\
	:cd=\E[J:cl=\E[;H\E[2J:ce=\E[K:\
	:al=\E[L:dl=\E[M:AL=\E[%2L:DL=\E[%2M:\
	:sc=\E[s:rc=\E[u:\
	:dc=\E[P:\
	:sf=\ED:sr=\EM:\
	:so=\E[7m:se=\E[m:\
	:do=\E[B:mi:ms:\
	:kd=\EP:kl=\EK:ku=\EH:kr=\EM:kh=\EG:\
	:k1=\E^A:k2=\E^B:k3=\E^D:k4=\E^E:k5=\E^F:\
	:ti=\E[0;72;27;72p\E[0;80;27;80p\E[0;77;27;77p\E[0;75;27;75p\E[0;73;2p\E[0;81;6p\E[0;71;27;71p\E[0;59;27;1p\E[0;60;27;2p\E[0;61;27;4p\E[0;62;27;5p:\
	:te=\E[0;72;0;72p\E[0;80;0;80p\E[0;77;0;77p\E[0;75;0;75p\E[0;73;0;73p\E[0;81;0;81p\E[0;71;0;71p\E[0;59;0;59p\E[0;60;0;60p\E[0;61;0;61p\E[0;62;0;62p:

#
# Digital Equipment Corporation (DEC) VT-100
#
vt100|vt-100|DEC vt100:\
	:am:co#80:li#24:bs:cm=5\E[%i%2;%2H:\
	:ce=3\E[K:cd=50\E[J:cl=50\E[;H\E[2J:\
	:if=/lib/vt100.tab:pt:\
	:so=2\E[7m:se=2\E[m:\
	:nd=2\E[C:up=2\E[A:\
	:is=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\
	:ks=\E[?1h\E=:ke=\E[?1l\E>:\
	:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kh=\E[H:\
	:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\EOT:\
	:k6=\EOU:k7=\EOV:k8=\EOW:k9=\EOX:\
	:sr=5\EM:

#
# American National Standard Institute (ANSI) Definition
#  of a "Standard Terminal" (note the similarity to VT-100 - guess
#  who was on the standards committee!).
#
ANSI|ansi|American National Standard Terminal:\
	:am:co#80:li#24:bs:cm=5\E[%i%2;%2H:\
	:ce=3\E[K:cd=5\E[J:cl=5\E[;H\E[2J:\
	:al=1\E[L:dl=1\E[M:\
	:AL=2\E[%2L:DL=2\E[%2M:\
	:pt:if=/lib/std.tab:\
	:so=2\E[7m:se=2\E[m:\
	:nd=2\E[C:up=2\E[A:do=\E[B\
	:is=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\
	:ks=\E[?1h\E=:ke=\E[?1l\E>:\
	:ku=\E[A:kd=\E[B:kr=\E[C:kl=\E[D:kh=\E[H:\
	:k1=\E[001z:k2=\E[002z:k3=\E[003z:k4=\E[004z:k5=\E[005z:\
	:k6=\E[006z:k7=\E[007z:k8=\E[007z:k9=\E[009z:\
	:sf=\ED:sr=\EM:

#
# Generic "dumb" terminal
#
dumb|unknown:co#80:os:am:

Added lib/units.lib.





































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/ $Id$

/ primitive units

m			!a!
kg			!b!
sec			!c!
coul			!d!
candela			!e!
dollar			!f!
bit			!h!
erlang			!i!
K			!j!

/ prefixes

yotta-			1e24
zetta-			1e21
exa-			1e18
peta-			1e15
tera-			1e12
giga-			1e9
mega-			1e6
myria-			1e4
kilo-			1e3
hecto-			1e2
deka-			1e1
deci-			1e-1
centi-			1e-2
milli-			1e-3
micro-			1e-6
nano-			1e-9
pico-			1e-12
femto-			1e-15
atto-			1e-18
zopto-			1e-21
yocto-			1e-24

semi-			.5
demi-			.5

Y-			yotta
Z-			zetta
E-			exa
P-			peta
T-			tera
G-			giga
M-			mega
k-			kilo
h-			hecto
da-			deka
d-			deci
c-			centi
m-			milli
p-			pico
f-			femto
a-			atto
z-			zopto
y-			yocto

/ constants

fuzz			1
pi			3.14159265358979323846
c			2.99792458e+8 m/sec fuzz
g			9.80665 m/sec2
au			1.49597871e+11 m fuzz
mole			6.022169e+23 fuzz
e			1.6021917e-19 coul fuzz
energy			c2
force			g
mercury			1.33322e+5 kg/m2-sec2
hg			mercury

/ dimensionless

radian			.5 / pi
degree			1|180 pi-radian
circle			2 pi-radian
turn			2 pi-radian
revolution			turn
rev			turn
grade			.9 degree
arcdeg			1 degree
arcmin			1|60 arcdeg
ccs			1|36 erlang
arcsec			1|60 arcmin

steradian		radian2
sphere			4 pi-steradian
sr			steradian

/ Time

second			sec
s			sec
minute			60 sec
min			minute
hour			60 min
hr			hour
day			24 hr
da			day
week			7 day
year			365.24219879 day fuzz
yr			year
month			1|12 year
ms			millisec
us			microsec

/ Mass

gram			millikg
gm			gram
mg			milligram
metricton		kilokg

/ Avoirdupois

lb			.45359237 kg
pound			lb
lbf			lb g
ounce			1|16 lb
oz			ounce
dram			1|16 oz
dr			dram
grain			1|7000 lb
gr			grain
shortton		2000 lb
ton			shortton
longton			2240 lb

/ Apothecary

scruple			20 grain
apdram			60 grain
apounce			480 grain
appound			5760 grain
troypound		appound

/ Length

meter			m
cm			centimeter
mm			millimeter
km			kilometer
nm			nanometer
micron			micrometer
angstrom		decinanometer

inch			2.54 cm
in			inch
foot			12 in
feet			foot
ft			foot
yard			3 ft
yd			yard
rod			5.5 yd
rd			rod
mile			5280 ft
mi			mile

british			1200|3937 m/ft
nmile			1852 m

acre			4840 yd2

cc			cm3
liter			kilocc
ml			milliliter

/ US Liquid

gallon			231 in3
imperial		1.20095
gal			gallon
quart			1|4 gal
qt			quart
pint			1|2 qt
pt			pint

floz			1|16 pt
fldr			1|8 floz

/ US Dry

dry			268.8025 in3/gallon fuzz
peck			8 dry-quart
pk			peck
bushel			4 peck
bu			bushel
chaldron		36 bushel

/ British

brgallon		277.420 in3 fuzz
brquart			1|4 brgallon
brpint			1|2 brquart
brfloz			1|20 brpint
brpeck			554.84 in3 fuzz
brbushel		4 brpeck

/ Energy Work

newton			kg-m/sec2
nt			newton
N			newton
joule			nt-m
cal			4.1868 joule

/ Electrical

coulomb			coul
C			coul
ampere			coul/sec
amp			ampere
watt			joule/sec
volt			watt/amp
ohm			volt/amp
mho			/ohm
farad			coul/volt
henry			sec2/farad
weber			volt-sec

/ Light

cd			candela
lumen			cd sr
lux			cd sr/m2

/ Wall Street Journal, July 2, 1993

$			dollar
argentinapeso		$
australiadollar		.66 $
austriaschilling	.83 $
bahraindinar		2.6522 $
belgiumfranc		.028 $
brazilcruzeiro		.000019 $
britainpound		1.49 $
canadadollar		.77 $
czechkoruna		.034 $
chilepeso		.0025 $
chinarenminbi		.174856 $
colombiapeso		.001495 $
denmarkkrone		.15 $
ecuadorsucre		.000539 $
finlandmarkka		.17 $
francefranc		.17 $
germanymark		.58 $
greatbritainpound	britainpound
greecedrachma		.0043 $
hongkongdollar		.13  $
hungaryforint		.011 $
indiarupee		.03211 $
indonesiarupiah		.0004782 $
irelandpunt		1.43 $
israelshekel		.3642 $
italylira		.00064 $
japanyen		.0093 $
jordandinar		1.4682 $
kuwaitdinar		3.3173 $
lebanonpound		.000578 $
malaysiaringgit		.338 $
maltalira		2.6042 $
mexicopeso		.3205128 $
netherlandguilder	.52 $
newzealanddollar	.539 $
norwaykrone		.139 $
pakistanrupee		.037 $
perunewsol		.5065 $
philippinespeso		.03738 $
polandzloty		.000059 $
portugalescudo		.00617 $
saudiarabiariyal	.26702 $
singaporedollar		.6157 $
slovakkoruna		.034 $
southamericarand	.21 $
southkoreawon		.001 $
spainpeseta		.007 $
swedenkrona		.13 $
switzerlandfranc	.66 $
taiwandollar		.038285 $
thailandbaht		.03962 $
turkeylira		.0000929 $
unitedarabdirham	.2723 $
uruguaynewpeso		.246852 $
venezuelabolivar	.011 $

mark			germanymark
bolivar			venezuelabolivar
peseta			spainpeseta
rand			southafricarand
escudo			portugalescudo
sol			perusol
guilder			netherlandsguilder
hollandguilder		netherlandsguilder
peso			mexicopeso
yen			japanyen
lira			italylira
rupee			indiarupee
drachma			greecedrachma
franc			francefranc
markka			finlandmarkka
sucre			ecuadorsucre
poundsterling		britainpound
cruzeiro		brazilcruzeiro

/ computer

baud			bit/sec
byte			8 bit
block			512 byte
kbyte			1024 byte
megabyte		1024 kbyte
gigabyte		1024 megabyte
meg			megabyte


/ Trivia

%			1|100
admiraltyknot		6080 ft/hr
apostilb		cd/pi-m2
are			1e+2 m2
arpentcan		27.52 mi
arpentlin		191.835 ft
astronomicalunit	au
atmosphere		1.01325e+5 nt/m2
atm			atmosphere
atomicmassunit		1.66044e-27 kg fuzz
amu			atomicmassunit
bag			94 lb
bakersdozen		13
bar			1e+5 nt/m2
barie			1e-1 nt/m2
barleycorn		1|3 in
barn			1e-28 m2
barrel			42 gal
barye			1e-1 nt/m2
bev			1e+9 e-volt
biot			10 amp
blondel			cd/pi-m2
boardfoot		144 in3
bolt			40 yd
bottommeasure		1|40 in
britishthermalunit	1.05506e+3 joule fuzz
btu			britishthermalunit
refrigeration		12000 btu/ton-hour
buck			dollar
cable			720 ft
caliber			1e-2 in
calorie			cal
carat			205 mg
caratgold		1|24
cent			centidollar
cental			100 lb
centesimalminute	1e-2 grade
centesimalsecond	1e-4 grade
century			100 year
cfs			ft3/sec
chain			66 ft
circularinch		1|4 pi-in2
circularmil		1e-6|4 pi-in2
clusec			1e-8 mm-hg m3/s
coomb			4 bu
cord			128 ft3
cordfoot		cord
crith			9.06e-2 gm
cubit			18 in
cup			1|2 pt
curie			3.7e+10 /sec
dalton			amu
decade			10 yr
dipotre			/m
displacementton		35 ft3
doppelzentner		100 kg
dozen			12
drop			.03 cm3
dyne			cm-gm/sec2
electronvolt		e-volt
ell			45 in
engineerschain		100 ft
engineerslink		100|100 ft
equivalentfootcandle	lumen/pi-ft2
equivalentlux		lumen/pi-m2
equivalentphot		cd/pi-cm2
erg			cm2-gm/sec2
ev			e-volt
faraday			9.652e+4 coul
fathom			6 ft
fermi			1e-15 m
fifth			4|5 qt
fin			5 dollar
finger			7|8 in
firkin			9 gal
footcandle		lumen/ft2
footlambert		cd/pi-ft2
fortnight		14 da
franklin		3.33564e-10 coul
frigorie		kilocal
furlong			220 yd
galileo			1e-2 m/sec2
gamma			1e-9 weber/m2
gauss			1e-4 weber/m2
geodeticfoot		british-ft
geographicalmile	1852 m
gilbert			7.95775e-1 amp
gill			1|4 pt
gross			144
gunterschain		22 yd
hand			4 in
hectare			1e+4 m2
hefnercandle		.92 cd
hertz			/sec
Hz			hertz
hogshead		2 barrel
hd			hogshead
homestead		1|4 mi2
horsepower		550 ft-lb-g/sec
hp			horsepower
hyl			gm force sec2/m
hz			/sec
imaginarycubicfoot	1.4 ft3
jeroboam		4|5 gal
karat			1|24
kcal			kilocal
kcalorie		kilocal
kev			1e+3 e-volt
key			kg
khz			1e+3 /sec
kilderkin		18 gal
knot			nmile/hr
lambert			cd/pi-cm2
langley			cal/cm2
last			80 bu
league			3 mi
lightyear		c-yr
line			1|12 in
link			66|100 ft
longhundredweight	112 lb
longquarter		28 lb
lusec			1e-6 mm-hg m3/s
mach			331.46 m/sec
magnum			2 qt
marineleague		3 nmile
maxwell			1e-8 weber
metriccarat		200 mg
mgd			megagal/day
mh			millihenry
mhz			1e+6 /sec
mil			1e-3 in
millenium		1000 year
minersinch		1.5 ft3/min
minim			1|60 fldr
mo			month
mpg			mile/gal
mph			mile/hr
nail			1|16 yd
nauticalmile		nmile
nit			cd/m2
noggin			1|8 qt
nox			1e-3 lux
ns			nanosec
oersted			2.5e+2 pi-amp/m
oe			oersted
pace			36 in
palm			3 in
parasang		3.5 mi
parsec			au-radian/arcsec
pascal			nt/m2
pc			parsec
pennyweight		1|20 oz
pwt			pennyweight
percent			%
perch			rd
pf			picofarad
phot			lumen/cm2
pica			1|6 in
pieze			1e+3 nt/m2
pipe			4 barrel
point			1|72 in
poise			gm/cm-sec
pole			rd
poundal			ft-lb/sec2
pdl			poundal
proof			1|200
psi			lb-g/in2
quarter			9 in
quartersection		1|4 mi2
quintal			100 kg
quire			25
rad			100 erg/gm
ream			500
registerton		100 ft3
rehoboam		156 floz
rhe			10 m2/nt-sec
rontgen			2.58e-4 curie/kg
rood			1.21e+3 yd
rope			20 ft
rutherford		1e+6 /sec
rydberg			1.36054e+1 ev
sabin			1 ft2
sack			3 bu
seam			8 bu
section			mi2
shippington		40 ft3
shorthundredweight	100 lb
shortquarter		25 lb
siemens			/ohm
sigma			microsec
skein			120 yd
skot			1e-3 apostilb
slug			lb-g-sec2/ft
span			9 in
spat			4 pi sr
spindle			14400 yd
square			100 ft2
stere			m3
sthene			1e+3 nt
stilb			cd/cm2
stoke			1e-4 m2/sec
stone			14 lb
strike			2 bu
surveyfoot		british-ft
surveyyard		3 surveyfoot
surveyorschain		66 ft
surveyorslink		66|100 ft
tablespoon		4 fldr
teaspoon		4|3 fldr
tesla			weber/m2
therm			1e+5 btu
thermie			1e+6 cal
timberfoot		ft3
tnt			4.6e+6 m2/sec2
tonne			1e+6 gm
torr			mm hg
township		36 mi2
tun			8 barrel
water			gram g / cc
wey			40 bu
weymass			252 lb
Xunit			1.00202e-13 m
k			1.38047e-16 erg/degC


degC			K
kelvin			K
brewster		1e-12 m2/newton
degF			5|9 degC
degreesrankine		degF
degrankine		degreesrankine
degreerankine		degF
degreaumur		10|8 degC
drachm			60 grain
poncelet		100 kg m g / sec
denier			.05|450 gram / m
tex			.001 gram / m
englishell		45 inch
scottishell		37.2 inch
flemishell		27 inch
planck			6.626e-34 joule-sec
hbar			1.055e-34 joule-sec
electronmass		9.1095e-31 kg
protonmass		1.6726e-27 kg
neutronmass		1.6606e-27 kg
V			volt
eV			e V
bohrradius		hbar2-C2/8.988e9 N m2-e2-electronmass
becquerel		1|3.7e10 curie
fresnel			1e12 hertz
statcoul		1|2.99792458e9 coul
statamp			1|2.99792458e9 amp
statvolt		2.99792458e2 volt
statcoulomb		statcoul
statampere		statamp
debye			3.336e-30 coul-m
pulsatance		2 pi/sec
rpm			rev/minute
rps			rev/sec
kilohm			kiloohm
megohm			megaohm
siderealyear		365.256360417 day
siderealday		23.934469444 hour
siderealhour		1|24 sidereal day
lunarmonth		29.5305555 day
synodicmonth		lunarmonth
siderealmonth		27.32152777 day
tropicalyear		year
solaryear		year
lunaryear		12 lunarmonth
cran			37.5 brgallon
kip			1000 lbf
frenchfoot		16|15 ft
frenchfeet		frenchfoot
toise			6 frenchfeet
sievert			8.4 rontgen
candle			1.02 candela
militarypace		2.5 feet
metre			meter
litre			liter
gramme			gram
iudiptheria		62.8 microgram
iupenicillin		.6 microgram
iuinsulin		41.67 microgram
cottonyarncount		2520 ft/pound
linenyarncount		900 ft/pound
worstedyarncount	1680 ft/pound
metricyarncount		meter/gram
jewlerspoint		2 milligram

Added mkall.sh.



























>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh
set -e
set -x
for x in doc boot lib etc
do
	cd $x
	make $*
	cd ..
done
cd src
sh mkall.sh $*
cd ..
exit 0

Added mkdist.mk.

























































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#
# mkdist
#	Shell script to build the distribution filesets
#

# Staging directory for binary distribution
ROOT=/vsta

# Non-CVS ports of stuff
PORTS=src/bin/ports

# Copyright/license files
LAW=README LICENSE

# Staging area mounted here
DEST=/dist

# Binary distribution
LIB=lib/bison.hairy lib/bison.simple lib/crt0.o lib/crt0srv.o \
	lib/ld.a lib/ld.shl lib/libc.a lib/libc.shl lib/libc_s.a \
	lib/libcurses.a lib/libdpart.a lib/libg.a lib/libgcc.a \
	lib/libm.a lib/libregexp.a lib/libsrv.a lib/libtermcap.a \
	lib/libusr.a lib/termcap lib/units.lib lib/libtermcap.shl \
	lib/libm.shl lib/libregexp.shl lib/libregex.a lib/magic \
	lib/libfl.a lib/libjpeg.a

BIN=$(LAW) bin boot doc etc include $(LIB)

# Make (a simple/fast one, and then GNU's)
MAKE=$(PORTS)/make $(PORTS)/gmake

# Text utilities
TXT=$(PORTS)/less $(PORTS)/grep $(PORTS)/rh $(PORTS)/sed $(PORTS)/tar \
	$(PORTS)/awk $(PORTS)/fileutl $(PORTS)/textutil $(PORTS)/find \
	$(PORTS)/patch $(PORTS)/ctags $(PORTS)/rcs5.11 $(PORTS)/m4 \
	$(PORTS)/roff

# Shells
SH=$(PORTS)/rc

# Editors
ED=$(PORTS)/emacs $(PORTS)/ed $(PORTS)/vim $(PORTS)/vim-5.7 $(PORTS)/teco

# Games
FUN=$(PORTS)/backgammon $(PORTS)/chess-5.00

# "bc" calculator
BC=$(PORTS)/bc

# GNU zip and friends
GZIP=$(PORTS)/gzip $(PORTS)/unzip $(PORTS)/arc521

# "sc" spreadsheet
SC=$(PORTS)/sc

# Smalltalk
SMALL=$(PORTS)/small $(PORTS)/smalltalk-1.8.3 $(PORTS)/tiny4.0

# GNU C, and related language tools
GCC=$(PORTS)/gcc2 $(PORTS)/binutl2 $(PORTS)/gdb

# MGR windowing system
MGR=mgr

# Compiler tools
LANG=$(PORTS)/flex $(PORTS)/bison $(PORTS)/yacc

# Python
PYTHON=$(PORTS)/python $(ROOT)/lib/python15

# Diff utilities
DIFF=$(PORTS)/diffutl

# Graphics
GRAPHICS=$(PORTS)/svgalib $(PORTS)/jpeg6b

# Simulators
SIM=$(PORTS)/sim_2.3d

# Miscellaneous
MISC=$(PORTS)/units $(PORTS)/expr $(PORTS)/file-3.22 $(PORTS)/rolodex

# Sample accounts
ACCOUNT=root guest

# Miscellaneous programming languages
MISCLANG=$(PORTS)/pfe

# Source distribution
SRC=make txt sh ed fun bc gzip sc small gcc \
	mgrdist lang net python diff account graphics sim misc \
	srccvs misclang

# Default: make a distribution
dist: bindist $(SRC)

# Create backup... leave off binary distribution, save the rest
backup: $(SRC)

#
# The following are targets which do the actual tarring up of
# files into archives.
#
bindist:
	cd $(ROOT); tar -cvf - $(BIN) | gzip -9 > $(DEST)/vsta.tz

make:
	tar -cvf - $(MAKE) | gzip -9 > $(DEST)/make.tz

txt:
	tar -cvf - $(TXT) | gzip -9 > $(DEST)/text.tz

sh:
	tar -cvf - $(SH) | gzip -9 > $(DEST)/shell.tz

ed:
	tar -cvf - $(ED) | gzip -9 > $(DEST)/editor.tz

fun:
	tar -cvf - $(FUN) | gzip -9 > $(DEST)/games.tz

bc:
	tar -cvf - $(BC) | gzip -9 > $(DEST)/bc.tz

gzip:
	tar -cvf - $(GZIP) | gzip -9 > $(DEST)/gzip.tz

sc:
	tar -cvf - $(SC) | gzip -9 > $(DEST)/sc.tz

small:
	tar -cvf - $(SMALL) | gzip -9 > $(DEST)/small.tz

gcc:
	tar -cvf - $(GCC) | gzip -9 > $(DEST)/gcc.tz

mgrdist:
	tar -cvf - $(MGR) | gzip -9 > $(DEST)/mgr.tz

lang:
	tar -cvf - $(LANG) | gzip -9 > $(DEST)/lang.tz

net:
	tar -cvf - $(NET) | gzip -9 > $(DEST)/ka9q.tz

python:
	tar -cvf - $(PYTHON) | gzip -9 > $(DEST)/python.tz

diff:
	tar -cvf - $(DIFF) | gzip -9 > $(DEST)/diff.tz

account:
	cd $(ROOT); tar -cvf - $(ACCOUNT) | gzip -9 > $(DEST)/account.tz

graphics:
	tar -cvf - $(GRAPHICS) | gzip -9 > $(DEST)/graphics.tz

sim:
	tar -cvf - $(SIM) | gzip -9 > $(DEST)/sim.tz

misc:
	tar -cvf - $(MISC) | gzip -9 > $(DEST)/misc.tz

misclang:
	tar -cvf - $(MISCLANG) | gzip -9 > $(DEST)/misclang.tz

#
# The CVS source control tree behind the main VSTa source tree
#
srccvs:
	cd /cvs ; tar -cvf - . | gzip -9 > $(DEST)/vsta_cvs.tz

Added src/bin/adb/adb.c.







































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * adb.c
 *	Main command handling for assembly debugger
 */
#include <stdio.h>
#include <ctype.h>
#include <std.h>
#include <fcntl.h>
#include <time.h>
#include <sys/syscall.h>
#include <sys/msg.h>
#include "adb.h"
#include "map.h"

pid_t corepid;		/* PID we debug, if any */
port_t dbg_port;	/*  ...port we talk to him via */

uint addr, count = 1;	/* Addr/count for each command */
static FILE *objfile;	/* Open FILE * to object file */
static char *objname;	/*  ...name of this file */
jmp_buf errjmp;		/* Recovery from parse errors */
static struct map	/* Mappings for a.out and core */
	textmap,
	coremap;
static struct map	/* Points to a map to use */
	*read_from;

/* Macro to skip whitespace */
#define SKIP(p) {while (isspace(*(p))) p += 1; }

/*
 * usage()
 *	Show how to invoke adb
 */
static void
usage(void)
{
	printf("Usage is: adb <prog> [ <pid> ]\n");
	exit(1);
}

/*
 * readloc()
 */
ulong
readloc(ulong addr, int size)
{
	ulong off;
	uchar c;
	ushort w;
	ulong l;

	if (read_from == &coremap) {
		return(read_procmem(addr, size));
	} else {
		/*
		 * vaddr 0x1000 maps to offset 0 in an a.out
		 */
		if (do_map(read_from, (void *)addr, &off)) {
			return(0);
		}
		fseek(objfile, off, 0);

		/*
		 * Read required amount of data at this location
		 */
		switch (size) {
		case 1:	fread(&c, sizeof(c), 1, objfile); return(c);
		case 2:	fread(&w, sizeof(w), 1, objfile); return(w);
		case 4:	fread(&l, sizeof(l), 1, objfile); return(l);
		}
	}
	return(0);
}

/*
 * dollar_cmds()
 *	Handle $ commands
 */
static void
dollar_cmds(char *p)
{
	extern void dump_regs(void), backtrace(void);

	switch (*p) {
	case 'q':		/* Quit */
		exit(0);
	case 'r':		/* Dump registers */
		dump_regs();
		break;
	case 'b':		/* List breakpoints */
		dump_breakpoints();
		break;
	case 'c':		/* Show C stack backtrace */
		read_from = &coremap;
		backtrace();
		break;
	case 's':		/* Load additional symbol file */
		p += 1;
		while (*p && isspace(*p)) {
			p += 1;
		}
		if (*p) {
			rdsym(p);
		}
		break;
	case 'S':		/* Dump symbol table */
		dump_syms();
		break;
	default:
		printf("Unknown command: $%s\n", p);
	}
}

/*
 * do_dump()
 *	Actual workhorse to do dumping of memory
 *
 * Some hard-coded knowledge of word size here, sorry.
 */
static void
do_dump(char *fmt, int size, int cols)
{
	int x, col = 0;
	unsigned char c;
	unsigned short w;
	unsigned long l;

	for (x = 0; x < count; ++x) {
		switch (size) {
		case 1:
			c = readloc(addr, 1);
			printf(fmt, c);
			break;
		case 2:
			w = readloc(addr, 2);
			printf(fmt, w);
			break;
		case 4:
			l = readloc(addr, 4);
			printf(fmt, l);
			break;
		}
		col += 1;
		addr += size;
		if (col > cols) {
			printf("\n");
			col = 0;
		}
	}
	if (col) {
		printf("\n");
	}
}

/*
 * dump_s()
 *	Dump strings, with or without de-escaping
 */
static void
dump_s(int quote)
{
	uchar c;

	for (;;) {
		c = readloc(addr, sizeof(c));
		if ((c == '\0') || (c == '\n')) {
			printf("\n");
			break;
		}
		if (quote) {
			if (c & 0x80) {
				printf("M-");
				c &= ~0x80;
			}
			if (c < ' ') {
				putchar('^');
				c += 'A';
			}
			if (c == 0x7F) {
				printf("DEL");
			} else {
				putchar(c);
			}
		} else {
			putchar(c);
		}
		addr += 1;
	}
}

/*
 * dump_mem()
 *	Dump memory in a variety of formats
 */
static void
dump_mem(char *p)
{
	char fmt;
	uint x, cnt, oldcnt;

	/*
	 * Optional count here as well.  The two interact in a way
	 * more complex than this in Sun's adb, but I can't figure
	 * it out.
	 */
	if (isdigit(*p)) {
		p = getnum(p, &cnt);
		SKIP(p);
		cnt *= count;
	} else {
		cnt = count;
	}
	oldcnt = count;
	count = cnt;

	/*
	 * Label location, start dumping
	 */
	printf("%s:\n", nameval(addr));
	fmt = *p++;
	switch (fmt) {
	case 'x': do_dump(" %4x", 2, 8); break;
	case 'X': do_dump(" %8X", 4, 4); break;
	case 'o': do_dump(" %8o", 2, 4); break;
	case 'O': do_dump(" %12O", 4, 4); break;
	case 'd': do_dump(" %5d", 2, 8); break;
	case 'D': do_dump(" %10d", 4, 4); break;
	case 'i':
		for (x = 0; x < count; ++x) {
			addr = db_disasm(addr, 0);
		}
		break;
	case 's': dump_s(0); break;
	case 'S': dump_s(1); break;
	case 'c': do_dump(" %02x", 1, 16); break;
	default:
		printf("Unknown format '%c'\n", fmt);
		return;
	}
	count = oldcnt;
}

/*
 * start()
 *	Run a process from the named object file
 */
static void
start(char *args)
{
	port_name pn;
	uint argc;
	char *argv[MAXARGS+1];

	/*
	 * Build arg list
	 */
	SKIP(args);
	argv[0] = objname;
	argc = 1;
	while (args && *args) {
		char *q;

		if (argc >= MAXARGS) {
			printf("Too many arguments\n");
			return;
		}
		argv[argc++] = args;
		q = strchr(args, ' ');
		if (q) {
			*q++ = '\0';
			SKIP(q);
		}
		args = q;
	}
	argv[argc] = 0;

	/*
	 * Launch a child.  We wait until our parent attaches.
	 */
	corepid = fork();
	if (corepid == 0) {
		uint cnt;

		/*
		 * Wait for parent to rendevous; bail if we haven't
		 * seen him in 60 seconds.
		 */
		cnt = 0;
		while (ptrace(0, 0) < 0) {
			__msleep(250);
			if (++cnt > 4*60) {
				_exit(1);
			}
		}

		/*
		 * Now run the named program
		 */
		execv(objname, argv);
		_exit(1);
	}

	/*
	 * Parent--attach to child, then let him sync to point of
	 * running new a.out.
	 */
	dbg_port = msg_port(0, &pn);
	if (dbg_port < 0) {
		perror("Debug port");
		exit(1);
	}
	if (ptrace(corepid, pn) < 0) {
		perror("ptrace attach");
		printf("Couldn't attach to %lu on 0x%x\n",
			(ulong)corepid, pn);
		exit(1);
	}
	wait_exec();
}

/*
 * colon_cmds()
 *	Do the ':' commands
 */
static void
colon_cmds(char *p)
{
	extern void run(void);

	switch (*p) {
	case 'c':
	case 's':
	case 'b':
	case 'd':
	case 'D':
		if (!corepid) {
			printf("No process\n");
			return;
		}
	}
	read_from = &coremap;
	switch (*p) {
	case 'c':
		run();
		break;
	case 's':
		step(0);
		break;
	case 'n':
		step(1);
		break;
	case 'b':
		set_breakpoint((void *)addr);
		break;
	case 'd':
		clear_breakpoint((void *)addr);
		break;
	case 'D':
		clear_breakpoints();
		break;
	case 'r':
		if (corepid) {
			printf("Already running\n");
			break;
		}
		start(p+1);
		break;
	default:
		printf("Unknown command: :%s\n", p);
		break;
	}
}

/*
 * print_val()
 *	Print value of dot
 */
static void
print_val(char *p)
{
	char fmt[8];
	uint val;
	ulong vall;

	if (!*p) {
		p = "X";
	}
	switch (*p) {
	case 'd':
	case 'D':
	case 'x':
	case 'X':
	case 'o':
	case 'O':
		sprintf(fmt, "%%%c\n", *p);
		if (islower(*p)) {
			val = addr & 0xFFFF;
			printf(fmt, val);
		} else {
			vall = addr;
			printf(fmt, vall);
		}
		break;
	default:
		printf("Unknown format: %s\n", p);
		break;
	}
}

/*
 * cmdloop()
 *	Process commands
 *
 * General format is:
 *	<addr>,<count> <operator> <modifiers>
 *	<addr>, <count> are numbers or symbols
 *	<operator> is '/', '?', ':', '$'
 *	<modifiers> are specific to the operator
 */
static void
cmdloop(void)
{
	char buf[128], *p, c;
	static char lastcmd[32];

	/*
	 * Get a line, skip over white space
	 */
	write(1, ">", 1);
	gets(buf);
	p = buf;
	SKIP(p);

	/*
	 * Repeat last command on empty line
	 */
	if (!*p) {
		p = lastcmd;
	}

	/*
	 * If first field present, parse it.  Otherwise we inherit
	 * the address from the previous command.
	 */
	if (isalnum(*p) || (*p == '_')) {
		p = getnum(p, &addr);
		count = 1;	/* Count gets reset on explicit addr */
	}
	SKIP(p);

	/*
	 * Similarly for count
	 */
	if (*p == ',') {
		++p;
		SKIP(p);
		p = getnum(p, &count);
		SKIP(p);
	}

	/*
	 * Record last command so we can repeat
	 */
	if (p != lastcmd) {
		strncpy(lastcmd, p, sizeof(lastcmd)-1);
	}

	/*
	 * Pick out operator
	 */
	c = *p++;
	SKIP(p);
	switch (c) {
	case '?':
		read_from = &textmap;
		dump_mem(p);
		break;
	case '/':
		if (!corepid) {
			printf("No process attached\n");
			break;
		}
		read_from = &coremap;
		dump_mem(p);
		break;
	case ':':
		colon_cmds(p);
		break;
	case '$':
		dollar_cmds(p);
		break;
	case '=':
		print_val(p);
		break;
	case '!':
		system(p);
		break;
	default:
		printf("Unknown modifier: '%c'\n", c);
		break;
	}
}

/*
 * main()
 *	Start up
 *
 * We handle:
 *	adb <prog>
 *	adb <prog> [ <pid> ]
 */
int
main(int argc, char **argv)
{
	/*
	 * Check out arguments
	 */
	if ((argc < 2) || (argc > 3)) {
		usage();
	}
	if (argc == 3) {
		corepid = atoi(argv[2]);
	}

	/*
	 * Read symbols from a.out, leave him open so we can
	 * do "?" examination of him.
	 */
	if ((objfile = fopen(objname = argv[1], "r")) == NULL) {
		perror(argv[1]);
		exit(1);
	}
	rdsym(argv[1]);

	/*
	 * Now ask Mr. a.out to fill in our offsets
	 */
	map_aout(&textmap);

	/*
	 * If there's a process, set up for debugging him
	 */
	if (corepid) {
		port_name pn;

		/*
		 * Create server port he will talk to us via
		 */
		dbg_port = msg_port(0, &pn);
		if (dbg_port < 0) {
			perror("Debug port");
			exit(1);
		}

		/*
		 * Tell ET to phone home.  He'll block until we start
		 * listening on our port.
		 */
		if (ptrace(corepid, pn) < 0) {
			perror("ptrace: attach");
			printf("Can't attach PID %ld to 0x%x\n",
				(ulong)corepid, (uint)pn);
			exit(1);
		}
	}

	/*
	 * For recovering from parse errors
	 */
	(void)setjmp(errjmp);

	/*
	 * Start processing commands
	 */
	for (;;) {
		cmdloop();
	}
}

Added src/bin/adb/adb.h.









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#ifndef ADB_H
#define ADB_H
/*
 * adb.h
 *	Global data defs
 */
#include <sys/types.h>
#include <mach/machreg.h>
#include <setjmp.h>

/*
 * Constants
 */
#define MAXARGS (16)	/* Max # args to :r command */
#define MAX_BPOINT (4)	/*  ... # breakpoints */

/*
 * Routines
 */
extern char *getnum(char *, uint *);
extern void set_breakpoint(void *),
	clear_breakpoint(void *),
	clear_breakpoints(void),
	dump_breakpoints(void),
	dump_syms(void);
extern ulong readloc(ulong, int);
extern ulong db_disasm(ulong, int);
extern char *nameval(ulong);
extern void getregs(struct trapframe *);
extern ulong regs_pc(struct trapframe *);
extern void dump_regs(void);
extern void show_here(void);
extern void backtrace(void);
extern ulong read_procmem(ulong, int);
extern void run(void), step(int);
extern void wait_exec(void);
extern void rdsym(char *);
extern char *nameval(ulong);
extern ulong symval(char *);

/*
 * Variables
 */
extern pid_t corepid;		/* PID we debug, if any */
extern port_t dbg_port;		/*  ...port we talk to him via */
extern uint addr, count;	/* Addr/count for each command */
extern jmp_buf errjmp;		/* Recovery from parse errors */
extern struct map coremap;	/* Map of core for a.out */
extern ulong why_stop;		/* Why proc isn't running */

#endif /* ADB_H */

Added src/bin/adb/disasm.c.

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
/* 
 * disasm.c
 *	Disassembly of i386 opcodes
 *
 * Derived from:
 * Mach Operating System
 * Copyright (c) 1991,1990 Carnegie Mellon University
 * All Rights Reserved.
 */
#include <stdio.h>
#include "adb.h"

#ifndef TRUE
#define TRUE 1		/* DUH */
#define FALSE 0
#endif

/*
 * Size attributes
 */
#define	BYTE	0
#define	WORD	1
#define	LONG	2
#define	QUAD	3
#define	SNGL	4
#define	DBLR	5
#define	EXTR	6
#define	SDEP	7
#define	NONE	8

/*
 * Addressing modes
 */
#define	E	1			/* general effective address */
#define	Eind	2			/* indirect address (jump, call) */
#define	Ew	3			/* address, word size */
#define	Eb	4			/* address, byte size */
#define	R	5			/* register, in 'reg' field */
#define	Rw	6			/* word register, in 'reg' field */
#define	Ri	7			/* register in instruction */
#define	S	8			/* segment reg, in 'reg' field */
#define	Si	9			/* segment reg, in instruction */
#define	A	10			/* accumulator */
#define	BX	11			/* (bx) */
#define	CL	12			/* cl, for shifts */
#define	DX	13			/* dx, for IO */
#define	SI	14			/* si */
#define	DI	15			/* di */
#define	CR	16			/* control register */
#define	DR	17			/* debug register */
#define	TR	18			/* test register */
#define	I	19			/* immediate, unsigned */
#define	Is	20			/* immediate, signed */
#define	Ib	21			/* byte immediate, unsigned */
#define	Ibs	22			/* byte immediate, signed */
#define	Iw	23			/* word immediate, unsigned */
#define	Il	24			/* long immediate */
#define	O	25			/* direct address */
#define	Db	26			/* byte displacement from EIP */
#define	Dl	27			/* long displacement from EIP */
#define	o1	28			/* constant 1 */
#define	o3	29			/* constant 3 */
#define	OS	30			/* immediate offset/segment */
#define	ST	31			/* FP stack top */
#define	STI	32			/* FP stack */
#define	X	33			/* extended FP op */
#define	XA	34			/* for 'fstcw %ax' */

struct inst {
	char *	i_name;			/* name */
	short	i_has_modrm;		/* has regmodrm byte */
	short	i_size;			/* operand size */
	int	i_mode;			/* addressing modes */
	char *	i_extra;		/* pointer to extra opcode table */
};

#define	op1(x)		(x)
#define	op2(x,y)	((x)|((y)<<8))
#define	op3(x,y,z)	((x)|((y)<<8)|((z)<<16))

struct finst {
	char *	f_name;			/* name for memory instruction */
	int	f_size;			/* size for memory instruction */
	int	f_rrmode;		/* mode for rr instruction */
	char *	f_rrname;		/* name for rr instruction
					   (or pointer to table) */
};

static char *db_Grp6[] = {
	"sldt",
	"str",
	"lldt",
	"ltr",
	"verr",
	"verw",
	"",
	""
};

static char *db_Grp7[] = {
	"sgdt",
	"sidt",
	"lgdt",
	"lidt",
	"smsw",
	"",
	"lmsw",
	"invlpg"
};

static char *db_Grp8[] = {
	"",
	"",
	"",
	"",
	"bt",
	"bts",
	"btr",
	"btc"
};

static struct inst db_inst_0f0x[] = {
/*00*/	{ "",	   TRUE,  NONE,  op1(Ew),     (char *)db_Grp6 },
/*01*/	{ "",	   TRUE,  NONE,  op1(Ew),     (char *)db_Grp7 },
/*02*/	{ "lar",   TRUE,  LONG,  op2(E,R),    0 },
/*03*/	{ "lsl",   TRUE,  LONG,  op2(E,R),    0 },
/*04*/	{ "",      FALSE, NONE,  0,	      0 },
/*05*/	{ "",      FALSE, NONE,  0,	      0 },
/*06*/	{ "clts",  FALSE, NONE,  0,	      0 },
/*07*/	{ "",      FALSE, NONE,  0,	      0 },

/*08*/	{ "invd",  FALSE, NONE,  0,	      0 },
/*09*/	{ "wbinvd",FALSE, NONE,  0,	      0 },
/*0a*/	{ "",      FALSE, NONE,  0,	      0 },
/*0b*/	{ "",      FALSE, NONE,  0,	      0 },
/*0c*/	{ "",      FALSE, NONE,  0,	      0 },
/*0d*/	{ "",      FALSE, NONE,  0,	      0 },
/*0e*/	{ "",      FALSE, NONE,  0,	      0 },
/*0f*/	{ "",      FALSE, NONE,  0,	      0 },
};

static struct inst db_inst_0f2x[] = {
/*20*/	{ "mov",   TRUE,  LONG,  op2(CR,E),   0 }, /* use E for reg */
/*21*/	{ "mov",   TRUE,  LONG,  op2(DR,E),   0 }, /* since mod == 11 */
/*22*/	{ "mov",   TRUE,  LONG,  op2(E,CR),   0 },
/*23*/	{ "mov",   TRUE,  LONG,  op2(E,DR),   0 },
/*24*/	{ "mov",   TRUE,  LONG,  op2(TR,E),   0 },
/*25*/	{ "",      FALSE, NONE,  0,	      0 },
/*26*/	{ "mov",   TRUE,  LONG,  op2(E,TR),   0 },
/*27*/	{ "",      FALSE, NONE,  0,	      0 },

/*28*/	{ "",      FALSE, NONE,  0,	      0 },
/*29*/	{ "",      FALSE, NONE,  0,	      0 },
/*2a*/	{ "",      FALSE, NONE,  0,	      0 },
/*2b*/	{ "",      FALSE, NONE,  0,	      0 },
/*2c*/	{ "",      FALSE, NONE,  0,	      0 },
/*2d*/	{ "",      FALSE, NONE,  0,	      0 },
/*2e*/	{ "",      FALSE, NONE,  0,	      0 },
/*2f*/	{ "",      FALSE, NONE,  0,	      0 },
};

static struct inst db_inst_0f8x[] = {
/*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
/*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
/*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
/*83*/	{ "jnb",   FALSE, NONE,  op1(Dl),     0 },
/*84*/	{ "jz",    FALSE, NONE,  op1(Dl),     0 },
/*85*/	{ "jnz",   FALSE, NONE,  op1(Dl),     0 },
/*86*/	{ "jbe",   FALSE, NONE,  op1(Dl),     0 },
/*87*/	{ "jnbe",  FALSE, NONE,  op1(Dl),     0 },

/*88*/	{ "js",    FALSE, NONE,  op1(Dl),     0 },
/*89*/	{ "jns",   FALSE, NONE,  op1(Dl),     0 },
/*8a*/	{ "jp",    FALSE, NONE,  op1(Dl),     0 },
/*8b*/	{ "jnp",   FALSE, NONE,  op1(Dl),     0 },
/*8c*/	{ "jl",    FALSE, NONE,  op1(Dl),     0 },
/*8d*/	{ "jnl",   FALSE, NONE,  op1(Dl),     0 },
/*8e*/	{ "jle",   FALSE, NONE,  op1(Dl),     0 },
/*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
};

static struct inst db_inst_0f9x[] = {
/*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
/*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
/*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
/*93*/	{ "setnb", TRUE,  NONE,  op1(Eb),     0 },
/*94*/	{ "setz",  TRUE,  NONE,  op1(Eb),     0 },
/*95*/	{ "setnz", TRUE,  NONE,  op1(Eb),     0 },
/*96*/	{ "setbe", TRUE,  NONE,  op1(Eb),     0 },
/*97*/	{ "setnbe",TRUE,  NONE,  op1(Eb),     0 },

/*98*/	{ "sets",  TRUE,  NONE,  op1(Eb),     0 },
/*99*/	{ "setns", TRUE,  NONE,  op1(Eb),     0 },
/*9a*/	{ "setp",  TRUE,  NONE,  op1(Eb),     0 },
/*9b*/	{ "setnp", TRUE,  NONE,  op1(Eb),     0 },
/*9c*/	{ "setl",  TRUE,  NONE,  op1(Eb),     0 },
/*9d*/	{ "setnl", TRUE,  NONE,  op1(Eb),     0 },
/*9e*/	{ "setle", TRUE,  NONE,  op1(Eb),     0 },
/*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
};

static struct inst db_inst_0fax[] = {
/*a0*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
/*a1*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
/*a2*/	{ "",      FALSE, NONE,  0,	      0 },
/*a3*/	{ "bt",    TRUE,  LONG,  op2(E,R),    0 },
/*a4*/	{ "shld",  TRUE,  LONG,  op3(Ib,E,R), 0 },
/*a5*/	{ "shld",  TRUE,  LONG,  op3(CL,E,R), 0 },
/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
/*a7*/	{ "",      FALSE, NONE,  0,	      0 },

/*a8*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
/*a9*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
/*aa*/	{ "",      FALSE, NONE,  0,	      0 },
/*ab*/	{ "bts",   TRUE,  LONG,  op2(E,R),    0 },
/*ac*/	{ "shrd",  TRUE,  LONG,  op3(Ib,E,R), 0 },
/*ad*/	{ "shrd",  TRUE,  LONG,  op3(CL,E,R), 0 },
/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
/*a7*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
};

static struct inst db_inst_0fbx[] = {
/*b0*/	{ "",      FALSE, NONE,  0,	      0 },
/*b1*/	{ "",      FALSE, NONE,  0,	      0 },
/*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
/*b3*/	{ "bts",   TRUE,  LONG,  op2(R, E),   0 },
/*b4*/	{ "lfs",   TRUE,  LONG,  op2(E, R),   0 },
/*b5*/	{ "lgs",   TRUE,  LONG,  op2(E, R),   0 },
/*b6*/	{ "movzb", TRUE,  LONG,  op2(E, R),   0 },
/*b7*/	{ "movzw", TRUE,  LONG,  op2(E, R),   0 },

/*b8*/	{ "",      FALSE, NONE,  0,	      0 },
/*b9*/	{ "",      FALSE, NONE,  0,	      0 },
/*ba*/	{ "",      TRUE,  LONG,  op2(Is, E),  (char *)db_Grp8 },
/*bb*/	{ "btc",   TRUE,  LONG,  op2(R, E),   0 },
/*bc*/	{ "bsf",   TRUE,  LONG,  op2(E, R),   0 },
/*bd*/	{ "bsr",   TRUE,  LONG,  op2(E, R),   0 },
/*be*/	{ "movsb", TRUE,  LONG,  op2(E, R),   0 },
/*bf*/	{ "movsw", TRUE,  LONG,  op2(E, R),   0 },
};

static struct inst db_inst_0fcx[] = {
/*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
/*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c7*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c8*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
/*c9*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
/*ca*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
/*cb*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
/*cc*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
/*cd*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
/*ce*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
/*cf*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
};

static struct inst db_inst_0fdx[] = {
/*c0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
/*c1*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c7*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c8*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*c9*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*ca*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*cb*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*cc*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*cd*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*ce*/	{ "",	   FALSE, NONE,	 0,	      0 },
/*cf*/	{ "",	   FALSE, NONE,	 0,	      0 },
};

static struct inst *db_inst_0f[] = {
	db_inst_0f0x,
	0,
	db_inst_0f2x,
	0,
	0,
	0,
	0,
	0,
	db_inst_0f8x,
	db_inst_0f9x,
	db_inst_0fax,
	db_inst_0fbx,
	db_inst_0fcx,
	db_inst_0fdx,
	0,
	0
};

static char *db_Esc92[] = {
	"fnop",	"",	"",	"",	"",	"",	"",	""
};
static char *db_Esc93[] = {
	"",	"",	"",	"",	"",	"",	"",	""
};
static char *db_Esc94[] = {
	"fchs",	"fabs",	"",	"",	"ftst",	"fxam",	"",	""
};
static char *db_Esc95[] = {
	"fld1",	"fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
};
static char *db_Esc96[] = {
	"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
	"fincstp"
};
static char *db_Esc97[] = {
	"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
};

static char *db_Esca4[] = {
	"",	"fucompp","",	"",	"",	"",	"",	""
};

static char *db_Escb4[] = {
	"",	"",	"fnclex","fninit","",	"",	"",	""
};

static char *db_Esce3[] = {
	"",	"fcompp","",	"",	"",	"",	"",	""
};

static char *db_Escf4[] = {
	"fnstsw","",	"",	"",	"",	"",	"",	""
};

static struct finst db_Esc8[] = {
/*0*/	{ "fadd",   SNGL,  op2(STI,ST),	0 },
/*1*/	{ "fmul",   SNGL,  op2(STI,ST),	0 },
/*2*/	{ "fcom",   SNGL,  op2(STI,ST),	0 },
/*3*/	{ "fcomp",  SNGL,  op2(STI,ST),	0 },
/*4*/	{ "fsub",   SNGL,  op2(STI,ST),	0 },
/*5*/	{ "fsubr",  SNGL,  op2(STI,ST),	0 },
/*6*/	{ "fdiv",   SNGL,  op2(STI,ST),	0 },
/*7*/	{ "fdivr",  SNGL,  op2(STI,ST),	0 },
};

static struct finst db_Esc9[] = {
/*0*/	{ "fld",    SNGL,  op1(STI),	0 },
/*1*/	{ "",       NONE,  op1(STI),	"fxch" },
/*2*/	{ "fst",    SNGL,  op1(X),	(char *)db_Esc92 },
/*3*/	{ "fstp",   SNGL,  op1(X),	(char *)db_Esc93 },
/*4*/	{ "fldenv", NONE,  op1(X),	(char *)db_Esc94 },
/*5*/	{ "fldcw",  NONE,  op1(X),	(char *)db_Esc95 },
/*6*/	{ "fnstenv",NONE,  op1(X),	(char *)db_Esc96 },
/*7*/	{ "fnstcw", NONE,  op1(X),	(char *)db_Esc97 },
};

static struct finst db_Esca[] = {
/*0*/	{ "fiadd",  WORD,  0,		0 },
/*1*/	{ "fimul",  WORD,  0,		0 },
/*2*/	{ "ficom",  WORD,  0,		0 },
/*3*/	{ "ficomp", WORD,  0,		0 },
/*4*/	{ "fisub",  WORD,  op1(X),	(char *)db_Esca4 },
/*5*/	{ "fisubr", WORD,  0,		0 },
/*6*/	{ "fidiv",  WORD,  0,		0 },
/*7*/	{ "fidivr", WORD,  0,		0 }
};

static struct finst db_Escb[] = {
/*0*/	{ "fild",   WORD,  0,		0 },
/*1*/	{ "",       NONE,  0,		0 },
/*2*/	{ "fist",   WORD,  0,		0 },
/*3*/	{ "fistp",  WORD,  0,		0 },
/*4*/	{ "",       WORD,  op1(X),	(char *)db_Escb4 },
/*5*/	{ "fld",    EXTR,  0,		0 },
/*6*/	{ "",       WORD,  0,		0 },
/*7*/	{ "fstp",   EXTR,  0,		0 },
};

static struct finst db_Escc[] = {
/*0*/	{ "fadd",   DBLR,  op2(ST,STI),	0 },
/*1*/	{ "fmul",   DBLR,  op2(ST,STI),	0 },
/*2*/	{ "fcom",   DBLR,  op2(ST,STI),	0 },
/*3*/	{ "fcomp",  DBLR,  op2(ST,STI),	0 },
/*4*/	{ "fsub",   DBLR,  op2(ST,STI),	"fsubr" },
/*5*/	{ "fsubr",  DBLR,  op2(ST,STI),	"fsub" },
/*6*/	{ "fdiv",   DBLR,  op2(ST,STI),	"fdivr" },
/*7*/	{ "fdivr",  DBLR,  op2(ST,STI),	"fdiv" },
};

static struct finst db_Escd[] = {
/*0*/	{ "fld",    DBLR,  op1(STI),	"ffree" },
/*1*/	{ "",       NONE,  0,		0 },
/*2*/	{ "fst",    DBLR,  op1(STI),	0 },
/*3*/	{ "fstp",   DBLR,  op1(STI),	0 },
/*4*/	{ "frstor", NONE,  op1(STI),	"fucom" },
/*5*/	{ "",       NONE,  op1(STI),	"fucomp" },
/*6*/	{ "fnsave", NONE,  0,		0 },
/*7*/	{ "fnstsw", NONE,  0,		0 },
};

static struct finst db_Esce[] = {
/*0*/	{ "fiadd",  LONG,  op2(ST,STI),	"faddp" },
/*1*/	{ "fimul",  LONG,  op2(ST,STI),	"fmulp" },
/*2*/	{ "ficom",  LONG,  0,		0 },
/*3*/	{ "ficomp", LONG,  op1(X),	(char *)db_Esce3 },
/*4*/	{ "fisub",  LONG,  op2(ST,STI),	"fsubrp" },
/*5*/	{ "fisubr", LONG,  op2(ST,STI),	"fsubp" },
/*6*/	{ "fidiv",  LONG,  op2(ST,STI),	"fdivrp" },
/*7*/	{ "fidivr", LONG,  op2(ST,STI),	"fdivp" },
};

static struct finst db_Escf[] = {
/*0*/	{ "fild",   LONG,  0,		0 },
/*1*/	{ "",       LONG,  0,		0 },
/*2*/	{ "fist",   LONG,  0,		0 },
/*3*/	{ "fistp",  LONG,  0,		0 },
/*4*/	{ "fbld",   NONE,  op1(XA),	(char *)db_Escf4 },
/*5*/	{ "fld",    QUAD,  0,		0 },
/*6*/	{ "fbstp",  NONE,  0,		0 },
/*7*/	{ "fstp",   QUAD,  0,		0 },
};

static struct finst *db_Esc_inst[] = {
	db_Esc8, db_Esc9, db_Esca, db_Escb,
	db_Escc, db_Escd, db_Esce, db_Escf
};

static char *db_Grp1[] = {
	"add",
	"or",
	"adc",
	"sbb",
	"and",
	"sub",
	"xor",
	"cmp"
};

static char *db_Grp2[] = {
	"rol",
	"ror",
	"rcl",
	"rcr",
	"shl",
	"shr",
	"shl",
	"sar"
};

static struct inst db_Grp3[] = {
	{ "test",  TRUE, NONE, op2(I,E), 0 },
	{ "test",  TRUE, NONE, op2(I,E), 0 },
	{ "not",   TRUE, NONE, op1(E),   0 },
	{ "neg",   TRUE, NONE, op1(E),   0 },
	{ "mul",   TRUE, NONE, op2(E,A), 0 },
	{ "imul",  TRUE, NONE, op2(E,A), 0 },
	{ "div",   TRUE, NONE, op2(E,A), 0 },
	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
};

static struct inst db_Grp4[] = {
	{ "inc",   TRUE, BYTE, op1(E),   0 },
	{ "dec",   TRUE, BYTE, op1(E),   0 },
	{ "",      TRUE, NONE, 0,	 0 },
	{ "",      TRUE, NONE, 0,	 0 },
	{ "",      TRUE, NONE, 0,	 0 },
	{ "",      TRUE, NONE, 0,	 0 },
	{ "",      TRUE, NONE, 0,	 0 },
	{ "",      TRUE, NONE, 0,	 0 }
};

static struct inst db_Grp5[] = {
	{ "inc",   TRUE, LONG, op1(E),   0 },
	{ "dec",   TRUE, LONG, op1(E),   0 },
	{ "call",  TRUE, NONE, op1(Eind),0 },
	{ "lcall", TRUE, NONE, op1(Eind),0 },
	{ "jmp",   TRUE, NONE, op1(Eind),0 },
	{ "ljmp",  TRUE, NONE, op1(Eind),0 },
	{ "push",  TRUE, LONG, op1(E),   0 },
	{ "",      TRUE, NONE, 0,	 0 }
};

static struct inst db_inst_table[256] = {
/*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
/*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
/*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
/*03*/	{ "add",   TRUE,  LONG,  op2(E, R),  0 },
/*04*/	{ "add",   FALSE, BYTE,  op2(Is, A), 0 },
/*05*/	{ "add",   FALSE, LONG,  op2(Is, A), 0 },
/*06*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
/*07*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },

/*08*/	{ "or",    TRUE,  BYTE,  op2(R, E),  0 },
/*09*/	{ "or",    TRUE,  LONG,  op2(R, E),  0 },
/*0a*/	{ "or",    TRUE,  BYTE,  op2(E, R),  0 },
/*0b*/	{ "or",    TRUE,  LONG,  op2(E, R),  0 },
/*0c*/	{ "or",    FALSE, BYTE,  op2(I, A),  0 },
/*0d*/	{ "or",    FALSE, LONG,  op2(I, A),  0 },
/*0e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
/*0f*/	{ "",      FALSE, NONE,  0,	     0 },

/*10*/	{ "adc",   TRUE,  BYTE,  op2(R, E),  0 },
/*11*/	{ "adc",   TRUE,  LONG,  op2(R, E),  0 },
/*12*/	{ "adc",   TRUE,  BYTE,  op2(E, R),  0 },
/*13*/	{ "adc",   TRUE,  LONG,  op2(E, R),  0 },
/*14*/	{ "adc",   FALSE, BYTE,  op2(Is, A), 0 },
/*15*/	{ "adc",   FALSE, LONG,  op2(Is, A), 0 },
/*16*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
/*17*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },

/*18*/	{ "sbb",   TRUE,  BYTE,  op2(R, E),  0 },
/*19*/	{ "sbb",   TRUE,  LONG,  op2(R, E),  0 },
/*1a*/	{ "sbb",   TRUE,  BYTE,  op2(E, R),  0 },
/*1b*/	{ "sbb",   TRUE,  LONG,  op2(E, R),  0 },
/*1c*/	{ "sbb",   FALSE, BYTE,  op2(Is, A), 0 },
/*1d*/	{ "sbb",   FALSE, LONG,  op2(Is, A), 0 },
/*1e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
/*1f*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },

/*20*/	{ "and",   TRUE,  BYTE,  op2(R, E),  0 },
/*21*/	{ "and",   TRUE,  LONG,  op2(R, E),  0 },
/*22*/	{ "and",   TRUE,  BYTE,  op2(E, R),  0 },
/*23*/	{ "and",   TRUE,  LONG,  op2(E, R),  0 },
/*24*/	{ "and",   FALSE, BYTE,  op2(I, A),  0 },
/*25*/	{ "and",   FALSE, LONG,  op2(I, A),  0 },
/*26*/	{ "",      FALSE, NONE,  0,	     0 },
/*27*/	{ "aaa",   FALSE, NONE,  0,	     0 },

/*28*/	{ "sub",   TRUE,  BYTE,  op2(R, E),  0 },
/*29*/	{ "sub",   TRUE,  LONG,  op2(R, E),  0 },
/*2a*/	{ "sub",   TRUE,  BYTE,  op2(E, R),  0 },
/*2b*/	{ "sub",   TRUE,  LONG,  op2(E, R),  0 },
/*2c*/	{ "sub",   FALSE, BYTE,  op2(Is, A), 0 },
/*2d*/	{ "sub",   FALSE, LONG,  op2(Is, A), 0 },
/*2e*/	{ "",      FALSE, NONE,  0,	     0 },
/*2f*/	{ "das",   FALSE, NONE,  0,	     0 },

/*30*/	{ "xor",   TRUE,  BYTE,  op2(R, E),  0 },
/*31*/	{ "xor",   TRUE,  LONG,  op2(R, E),  0 },
/*32*/	{ "xor",   TRUE,  BYTE,  op2(E, R),  0 },
/*33*/	{ "xor",   TRUE,  LONG,  op2(E, R),  0 },
/*34*/	{ "xor",   FALSE, BYTE,  op2(I, A),  0 },
/*35*/	{ "xor",   FALSE, LONG,  op2(I, A),  0 },
/*36*/	{ "",      FALSE, NONE,  0,	     0 },
/*37*/	{ "daa",   FALSE, NONE,  0,	     0 },

/*38*/	{ "cmp",   TRUE,  BYTE,  op2(R, E),  0 },
/*39*/	{ "cmp",   TRUE,  LONG,  op2(R, E),  0 },
/*3a*/	{ "cmp",   TRUE,  BYTE,  op2(E, R),  0 },
/*3b*/	{ "cmp",   TRUE,  LONG,  op2(E, R),  0 },
/*3c*/	{ "cmp",   FALSE, BYTE,  op2(Is, A), 0 },
/*3d*/	{ "cmp",   FALSE, LONG,  op2(Is, A), 0 },
/*3e*/	{ "",      FALSE, NONE,  0,	     0 },
/*3f*/	{ "aas",   FALSE, NONE,  0,	     0 },

/*40*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
/*41*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
/*42*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
/*43*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
/*44*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
/*45*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
/*46*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
/*47*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },

/*48*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
/*49*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
/*4a*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
/*4b*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
/*4c*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
/*4d*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
/*4e*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
/*4f*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },

/*50*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
/*51*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
/*52*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
/*53*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
/*54*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
/*55*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
/*56*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
/*57*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },

/*58*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
/*59*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
/*5a*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
/*5b*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
/*5c*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
/*5d*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
/*5e*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
/*5f*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },

/*60*/	{ "pusha", FALSE, LONG,  0,	     0 },
/*61*/	{ "popa",  FALSE, LONG,  0,	     0 },
/*62*/  { "bound", TRUE,  LONG,  op2(E, R),  0 },
/*63*/	{ "arpl",  TRUE,  NONE,  op2(Ew,Rw), 0 },

/*64*/	{ "",      FALSE, NONE,  0,	     0 },
/*65*/	{ "",      FALSE, NONE,  0,	     0 },
/*66*/	{ "",      FALSE, NONE,  0,	     0 },
/*67*/	{ "",      FALSE, NONE,  0,	     0 },

/*68*/	{ "push",  FALSE, LONG,  op1(I),     0 },
/*69*/  { "imul",  TRUE,  LONG,  op3(I,E,R), 0 },
/*6a*/	{ "push",  FALSE, LONG,  op1(Ib),    0 },
/*6b*/  { "imul",  TRUE,  LONG,  op3(Ibs,E,R),0 },
/*6c*/	{ "ins",   FALSE, BYTE,  op2(DX, DI), 0 },
/*6d*/	{ "ins",   FALSE, LONG,  op2(DX, DI), 0 },
/*6e*/	{ "outs",  FALSE, BYTE,  op2(SI, DX), 0 },
/*6f*/	{ "outs",  FALSE, LONG,  op2(SI, DX), 0 },

/*70*/	{ "jo",    FALSE, NONE,  op1(Db),     0 },
/*71*/	{ "jno",   FALSE, NONE,  op1(Db),     0 },
/*72*/	{ "jb",    FALSE, NONE,  op1(Db),     0 },
/*73*/	{ "jnb",   FALSE, NONE,  op1(Db),     0 },
/*74*/	{ "jz",    FALSE, NONE,  op1(Db),     0 },
/*75*/	{ "jnz",   FALSE, NONE,  op1(Db),     0 },
/*76*/	{ "jbe",   FALSE, NONE,  op1(Db),     0 },
/*77*/	{ "jnbe",  FALSE, NONE,  op1(Db),     0 },

/*78*/	{ "js",    FALSE, NONE,  op1(Db),     0 },
/*79*/	{ "jns",   FALSE, NONE,  op1(Db),     0 },
/*7a*/	{ "jp",    FALSE, NONE,  op1(Db),     0 },
/*7b*/	{ "jnp",   FALSE, NONE,  op1(Db),     0 },
/*7c*/	{ "jl",    FALSE, NONE,  op1(Db),     0 },
/*7d*/	{ "jnl",   FALSE, NONE,  op1(Db),     0 },
/*7e*/	{ "jle",   FALSE, NONE,  op1(Db),     0 },
/*7f*/	{ "jnle",  FALSE, NONE,  op1(Db),     0 },

/*80*/  { "",	   TRUE,  BYTE,  op2(I, E),   (char *)db_Grp1 },
/*81*/  { "",	   TRUE,  LONG,  op2(I, E),   (char *)db_Grp1 },
/*82*/  { "",	   TRUE,  BYTE,  op2(Is,E),   (char *)db_Grp1 },
/*83*/  { "",	   TRUE,  LONG,  op2(Ibs,E),  (char *)db_Grp1 },
/*84*/	{ "test",  TRUE,  BYTE,  op2(R, E),   0 },
/*85*/	{ "test",  TRUE,  LONG,  op2(R, E),   0 },
/*86*/	{ "xchg",  TRUE,  BYTE,  op2(R, E),   0 },
/*87*/	{ "xchg",  TRUE,  LONG,  op2(R, E),   0 },

/*88*/	{ "mov",   TRUE,  BYTE,  op2(R, E),   0 },
/*89*/	{ "mov",   TRUE,  LONG,  op2(R, E),   0 },
/*8a*/	{ "mov",   TRUE,  BYTE,  op2(E, R),   0 },
/*8b*/	{ "mov",   TRUE,  LONG,  op2(E, R),   0 },
/*8c*/  { "mov",   TRUE,  NONE,  op2(S, Ew),  0 },
/*8d*/	{ "lea",   TRUE,  LONG,  op2(E, R),   0 },
/*8e*/	{ "mov",   TRUE,  NONE,  op2(Ew, S),  0 },
/*8f*/	{ "pop",   TRUE,  LONG,  op1(E),      0 },

/*90*/	{ "nop",   FALSE, NONE,  0,	      0 },
/*91*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
/*92*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
/*93*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
/*94*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
/*95*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
/*96*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
/*97*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },

/*98*/	{ "cbw",   FALSE, SDEP,  0,	      "cwde" },	/* cbw/cwde */
/*99*/	{ "cwd",   FALSE, SDEP,  0,	      "cdq"  },	/* cwd/cdq */
/*9a*/	{ "lcall", FALSE, NONE,  op1(OS),     0 },
/*9b*/	{ "wait",  FALSE, NONE,  0,	      0 },
/*9c*/	{ "pushf", FALSE, LONG,  0,	      0 },
/*9d*/	{ "popf",  FALSE, LONG,  0,	      0 },
/*9e*/	{ "sahf",  FALSE, NONE,  0,	      0 },
/*9f*/	{ "lahf",  FALSE, NONE,  0,	      0 },

/*a0*/	{ "mov",   FALSE, BYTE,  op2(O, A),   0 },
/*a1*/	{ "mov",   FALSE, LONG,  op2(O, A),   0 },
/*a2*/	{ "mov",   FALSE, BYTE,  op2(A, O),   0 },
/*a3*/	{ "mov",   FALSE, LONG,  op2(A, O),   0 },
/*a4*/	{ "movs",  FALSE, BYTE,  op2(SI,DI),  0 },
/*a5*/	{ "movs",  FALSE, LONG,  op2(SI,DI),  0 },
/*a6*/	{ "cmps",  FALSE, BYTE,  op2(SI,DI),  0 },
/*a7*/	{ "cmps",  FALSE, LONG,  op2(SI,DI),  0 },

/*a8*/	{ "test",  FALSE, BYTE,  op2(I, A),   0 },
/*a9*/	{ "test",  FALSE, LONG,  op2(I, A),   0 },
/*aa*/	{ "stos",  FALSE, BYTE,  op1(DI),     0 },
/*ab*/	{ "stos",  FALSE, LONG,  op1(DI),     0 },
/*ac*/	{ "ldos",  FALSE, BYTE,  op1(SI),     0 },
/*ad*/	{ "ldos",  FALSE, LONG,  op1(SI),     0 },
/*ae*/	{ "scas",  FALSE, BYTE,  op1(SI),     0 },
/*af*/	{ "scas",  FALSE, LONG,  op1(SI),     0 },

/*b0*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
/*b1*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
/*b2*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
/*b3*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
/*b4*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
/*b5*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
/*b6*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
/*b7*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },

/*b8*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
/*b9*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
/*ba*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
/*bb*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
/*bc*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
/*bd*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
/*be*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
/*bf*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },

/*c0*/	{ "",	   TRUE,  BYTE,  op2(Ib, E),  (char *)db_Grp2 },
/*c1*/	{ "",	   TRUE,  LONG,  op2(Ib, E),  (char *)db_Grp2 },
/*c2*/	{ "ret",   FALSE, NONE,  op1(Iw),     0 },
/*c3*/	{ "ret",   FALSE, NONE,  0,	      0 },
/*c4*/	{ "les",   TRUE,  LONG,  op2(E, R),   0 },
/*c5*/	{ "lds",   TRUE,  LONG,  op2(E, R),   0 },
/*c6*/	{ "mov",   TRUE,  BYTE,  op2(I, E),   0 },
/*c7*/	{ "mov",   TRUE,  LONG,  op2(I, E),   0 },

/*c8*/	{ "enter", FALSE, NONE,  op2(Ib, Iw), 0 },
/*c9*/	{ "leave", FALSE, NONE,  0,           0 },
/*ca*/	{ "lret",  FALSE, NONE,  op1(Iw),     0 },
/*cb*/	{ "lret",  FALSE, NONE,  0,	      0 },
/*cc*/	{ "int",   FALSE, NONE,  op1(o3),     0 },
/*cd*/	{ "int",   FALSE, NONE,  op1(Ib),     0 },
/*ce*/	{ "into",  FALSE, NONE,  0,	      0 },
/*cf*/	{ "iret",  FALSE, NONE,  0,	      0 },

/*d0*/	{ "",	   TRUE,  BYTE,  op2(o1, E),  (char *)db_Grp2 },
/*d1*/	{ "",	   TRUE,  LONG,  op2(o1, E),  (char *)db_Grp2 },
/*d2*/	{ "",	   TRUE,  BYTE,  op2(CL, E),  (char *)db_Grp2 },
/*d3*/	{ "",	   TRUE,  LONG,  op2(CL, E),  (char *)db_Grp2 },
/*d4*/	{ "aam",   TRUE,  NONE,  0,	      0 },
/*d5*/	{ "aad",   TRUE,  NONE,  0,	      0 },
/*d6*/	{ "",      FALSE, NONE,  0,	      0 },
/*d7*/	{ "xlat",  FALSE, BYTE,  op1(BX),     0 },

/*d8*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esc8 },
/*d9*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esc9 },
/*da*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esca },
/*db*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escb },
/*dc*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escc },
/*dd*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escd },
/*de*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esce },
/*df*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escf },

/*e0*/	{ "loopne",FALSE, NONE,  op1(Db),     0 },
/*e1*/	{ "loope", FALSE, NONE,  op1(Db),     0 },
/*e2*/	{ "loop",  FALSE, NONE,  op1(Db),     0 },
/*e3*/	{ "jcxz",  FALSE, SDEP,  op1(Db),     "jecxz" },
/*e4*/	{ "in",    FALSE, BYTE,  op2(Ib, A),  0 },
/*e5*/	{ "in",    FALSE, LONG,  op2(Ib, A) , 0 },
/*e6*/	{ "out",   FALSE, BYTE,  op2(A, Ib),  0 },
/*e7*/	{ "out",   FALSE, LONG,  op2(A, Ib) , 0 },

/*e8*/	{ "call",  FALSE, NONE,  op1(Dl),     0 },
/*e9*/	{ "jmp",   FALSE, NONE,  op1(Dl),     0 },
/*ea*/	{ "ljmp",  FALSE, NONE,  op1(OS),     0 },
/*eb*/	{ "jmp",   FALSE, NONE,  op1(Db),     0 },
/*ec*/	{ "in",    FALSE, BYTE,  op2(DX, A),  0 },
/*ed*/	{ "in",    FALSE, LONG,  op2(DX, A) , 0 },
/*ee*/	{ "out",   FALSE, BYTE,  op2(A, DX),  0 },
/*ef*/	{ "out",   FALSE, LONG,  op2(A, DX) , 0 },

/*f0*/	{ "",      FALSE, NONE,  0,	     0 },
/*f1*/	{ "",      FALSE, NONE,  0,	     0 },
/*f2*/	{ "",      FALSE, NONE,  0,	     0 },
/*f3*/	{ "",      FALSE, NONE,  0,	     0 },
/*f4*/	{ "hlt",   FALSE, NONE,  0,	     0 },
/*f5*/	{ "cmc",   FALSE, NONE,  0,	     0 },
/*f6*/	{ "",      TRUE,  BYTE,  0,	     (char *)db_Grp3 },
/*f7*/	{ "",	   TRUE,  LONG,  0,	     (char *)db_Grp3 },

/*f8*/	{ "clc",   FALSE, NONE,  0,	     0 },
/*f9*/	{ "stc",   FALSE, NONE,  0,	     0 },
/*fa*/	{ "cli",   FALSE, NONE,  0,	     0 },
/*fb*/	{ "sti",   FALSE, NONE,  0,	     0 },
/*fc*/	{ "cld",   FALSE, NONE,  0,	     0 },
/*fd*/	{ "std",   FALSE, NONE,  0,	     0 },
/*fe*/	{ "",	   TRUE,  NONE,  0,	     (char *)db_Grp4 },
/*ff*/	{ "",	   TRUE,  NONE,  0,	     (char *)db_Grp5 },
};

static struct inst db_bad_inst =
	{ "???",   FALSE, NONE,  0,	      0 }
;

#define	f_mod(byte)	((byte)>>6)
#define	f_reg(byte)	(((byte)>>3)&0x7)
#define	f_rm(byte)	((byte)&0x7)

#define	sib_ss(byte)	((byte)>>6)
#define	sib_index(byte)	(((byte)>>3)&0x7)
#define	sib_base(byte)	((byte)&0x7)

struct i_addr {
	int		is_reg;	/* if reg, reg number is in 'disp' */
	int		disp;
	char *		base;
	char *		index;
	int		ss;
};

static char *db_index_reg_16[8] = {
	"%bx,%si",
	"%bx,%di",
	"%bp,%si",
	"%bp,%di",
	"%si",
	"%di",
	"%bp",
	"%bx"
};

static char *db_reg[3][8] = {
	{"%al",  "%cl",  "%dl",  "%bl",  "%ah",  "%ch",  "%dh",  "%bh"},
	{"%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di"},
	{"%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi"}
};

static char *db_seg_reg[8] = {
	"%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
};

/*
 * lengths for size attributes
 */
static int db_lengths[] = {
	1,	/* BYTE */
	2,	/* WORD */
	4,	/* LONG */
	8,	/* QUAD */
	4,	/* SNGL */
	8,	/* DBLR */
	10,	/* EXTR */
};

#define	get_value_inc(result, loc, size, is_signed) \
	result = readloc(loc, size); \
	(loc) += (size);

/*
 * Read address at location and return updated location.
 */
static ulong
db_read_address(loc, short_addr, regmodrm, addrp)
	ulong	loc;
	int		short_addr;
	int		regmodrm;
	struct i_addr	*addrp;		/* out */
{
	int		mod, rm, sib, index, disp;

	mod = f_mod(regmodrm);
	rm  = f_rm(regmodrm);

	if (mod == 3) {
	    addrp->is_reg = TRUE;
	    addrp->disp = rm;
	    return (loc);
	}
	addrp->is_reg = FALSE;
	addrp->index = 0;

	if (short_addr) {
	    addrp->index = 0;
	    addrp->ss = 0;
	    switch (mod) {
		case 0:
		    if (rm == 6) {
			get_value_inc(disp, loc, 2, TRUE);
			addrp->disp = disp;
			addrp->base = 0;
		    }
		    else {
			addrp->disp = 0;
			addrp->base = db_index_reg_16[rm];
		    }
		    break;
		case 1:
		    get_value_inc(disp, loc, 1, TRUE);
		    addrp->disp = disp;
		    addrp->base = db_index_reg_16[rm];
		    break;
		case 2:
		    get_value_inc(disp, loc, 2, TRUE);
		    addrp->disp = disp;
		    addrp->base = db_index_reg_16[rm];
		    break;
	    }
	}
	else {
	    if (mod != 3 && rm == 4) {
		get_value_inc(sib, loc, 1, FALSE);
		rm = sib_base(sib);
		index = sib_index(sib);
		if (index != 4)
		    addrp->index = db_reg[LONG][index];
		addrp->ss = sib_ss(sib);
	    }

	    switch (mod) {
		case 0:
		    if (rm == 5) {
			get_value_inc(addrp->disp, loc, 4, FALSE);
			addrp->base = 0;
		    }
		    else {
			addrp->disp = 0;
			addrp->base = db_reg[LONG][rm];
		    }
		    break;

		case 1:
		    get_value_inc(disp, loc, 1, TRUE);
		    addrp->disp = disp;
		    addrp->base = db_reg[LONG][rm];
		    break;

		case 2:
		    get_value_inc(disp, loc, 4, FALSE);
		    addrp->disp = disp;
		    addrp->base = db_reg[LONG][rm];
		    break;
	    }
	}
	return (loc);
}

static void
db_printsym(off)
	int off;
{
	char *p;

	p = nameval(off);
	if (p)
		printf("%s", p);
	else
		printf("%x", off);
}

static void
db_print_address(seg, size, addrp)
	char *		seg;
	int		size;
	struct i_addr	*addrp;
{
	if (addrp->is_reg) {
	    printf("%s", db_reg[size][addrp->disp]);
	    return;
	}

	if (seg) {
	    printf("%s:", seg);
	}
	db_printsym(addrp->disp);
	if (addrp->base != 0 || addrp->index != 0) {
	    printf("(");
	    if (addrp->base)
		printf("%s", addrp->base);
	    if (addrp->index)
		printf(",%s,%d", addrp->index, 1<<addrp->ss);
	    printf(")");
	}
}

/*
 * Disassemble floating-point ("escape") instruction
 * and return updated location.
 */
static ulong
db_disasm_esc(loc, inst, short_addr, size, seg)
	ulong	loc;
	int		inst;
	int		short_addr;
	int		size;
	char *		seg;
{
	int		regmodrm;
	struct finst	*fp;
	int		mod;
	struct i_addr	address;
	char *		name;

	get_value_inc(regmodrm, loc, 1, FALSE);
	fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
	mod = f_mod(regmodrm);
	if (mod != 3) {
	    /*
	     * Normal address modes.
	     */
	    loc = db_read_address(loc, short_addr, regmodrm, &address);
	    printf(fp->f_name);
	    switch(fp->f_size) {
		case SNGL:
		    printf("s");
		    break;
		case DBLR:
		    printf("l");
		    break;
		case EXTR:
		    printf("t");
		    break;
		case WORD:
		    printf("s");
		    break;
		case LONG:
		    printf("l");
		    break;
		case QUAD:
		    printf("q");
		    break;
		default:
		    break;
	    }
	    printf("\t");
	    db_print_address(seg, BYTE, &address);
	}
	else {
	    /*
	     * 'reg-reg' - special formats
	     */
	    switch (fp->f_rrmode) {
		case op2(ST,STI):
		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
		    printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
		    break;
		case op2(STI,ST):
		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
		    printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm));
		    break;
		case op1(STI):
		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
		    printf("%s\t%%st(%d)",name, f_rm(regmodrm));
		    break;
		case op1(X):
		    printf("%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
		    break;
		case op1(XA):
		    printf("%s\t%%ax",
				 ((char **)fp->f_rrname)[f_rm(regmodrm)]);
		    break;
		default:
		    printf("<bad instruction>");
		    break;
	    }
	}

	return (loc);
}

/*
 * Disassemble instruction at 'loc'.  'altfmt' specifies an
 * (optional) alternate format.  Return address of start of
 * next instruction.
 */
ulong
db_disasm(ulong loc, int altfmt)
{
	int inst, size, short_addr, i_size, i_mode, regmodrm,
		first, displ, prefix, imm, imm2, len;
	char *seg, *i_name;
	struct inst *ip;
	struct i_addr address;

	get_value_inc(inst, loc, 1, FALSE);
	short_addr = FALSE;
	size = LONG;
	seg = 0;
	regmodrm = 0;

	/*
	 * Get prefixes
	 */
	prefix = TRUE;
	do {
	    switch (inst) {
		case 0x66:		/* data16 */
		    size = WORD;
		    break;
		case 0x67:
		    short_addr = TRUE;
		    break;
		case 0x26:
		    seg = "%es";
		    break;
		case 0x36:
		    seg = "%ss";
		    break;
		case 0x2e:
		    seg = "%cs";
		    break;
		case 0x3e:
		    seg = "%ds";
		    break;
		case 0x64:
		    seg = "%fs";
		    break;
		case 0x65:
		    seg = "%gs";
		    break;
		case 0xf0:
		    printf("lock ");
		    break;
		case 0xf2:
		    printf("repne ");
		    break;
		case 0xf3:
		    printf("repe ");	/* XXX repe VS rep */
		    break;
		default:
		    prefix = FALSE;
		    break;
	    }
	    if (prefix) {
		get_value_inc(inst, loc, 1, FALSE);
	    }
	} while (prefix);

	if (inst >= 0xd8 && inst <= 0xdf) {
	    loc = db_disasm_esc(loc, inst, short_addr, size, seg);
	    printf("\n");
	    return (loc);
	}

	if (inst == 0x0f) {
	    get_value_inc(inst, loc, 1, FALSE);
	    ip = db_inst_0f[inst>>4];
	    if (ip == 0) {
		ip = &db_bad_inst;
	    }
	    else {
		ip = &ip[inst&0xf];
	    }
	}
	else
	    ip = &db_inst_table[inst];

	if (ip->i_has_modrm) {
	    get_value_inc(regmodrm, loc, 1, FALSE);
	    loc = db_read_address(loc, short_addr, regmodrm, &address);
	}

	i_name = ip->i_name;
	i_size = ip->i_size;
	i_mode = ip->i_mode;

	if (ip->i_extra == (char *)db_Grp1 ||
	    ip->i_extra == (char *)db_Grp2 ||
	    ip->i_extra == (char *)db_Grp6 ||
	    ip->i_extra == (char *)db_Grp7 ||
	    ip->i_extra == (char *)db_Grp8) {
	    i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
	}
	else if (ip->i_extra == (char *)db_Grp3) {
	    ip = (struct inst *)ip->i_extra;
	    ip = &ip[f_reg(regmodrm)];
	    i_name = ip->i_name;
	    i_mode = ip->i_mode;
	}
	else if (ip->i_extra == (char *)db_Grp4 ||
		 ip->i_extra == (char *)db_Grp5) {
	    ip = (struct inst *)ip->i_extra;
	    ip = &ip[f_reg(regmodrm)];
	    i_name = ip->i_name;
	    i_mode = ip->i_mode;
	    i_size = ip->i_size;
	}

	if (i_size == SDEP) {
	    if (size == WORD)
		printf(i_name);
	    else
		printf(ip->i_extra);
	}
	else {
	    printf(i_name);
	    if (i_size != NONE) {
		if (i_size == BYTE) {
		    printf("b");
		    size = BYTE;
		}
		else if (i_size == WORD) {
		    printf("w");
		    size = WORD;
		}
		else if (size == WORD)
		    printf("w");
		else
		    printf("l");
	    }
	}
	printf("\t");
	for (first = TRUE;
	     i_mode != 0;
	     i_mode >>= 8, first = FALSE)
	{
	    if (!first)
		printf(",");

	    switch (i_mode & 0xFF) {

		case E:
		    db_print_address(seg, size, &address);
		    break;

		case Eind:
		    printf("*");
		    db_print_address(seg, size, &address);
		    break;

		case Ew:
		    db_print_address(seg, WORD, &address);
		    break;

		case Eb:
		    db_print_address(seg, BYTE, &address);
		    break;

		case R:
		    printf("%s", db_reg[size][f_reg(regmodrm)]);
		    break;

		case Rw:
		    printf("%s", db_reg[WORD][f_reg(regmodrm)]);
		    break;

		case Ri:
		    printf("%s", db_reg[size][f_rm(inst)]);
		    break;

		case S:
		    printf("%s", db_seg_reg[f_reg(regmodrm)]);
		    break;

		case Si:
		    printf("%s", db_seg_reg[f_reg(inst)]);
		    break;

		case A:
		    printf("%s", db_reg[size][0]);	/* acc */
		    break;

		case BX:
		    if (seg)
			printf("%s:", seg);
		    printf("(%s)", short_addr ? "%bx" : "%ebx");
		    break;

		case CL:
		    printf("%%cl");
		    break;

		case DX:
		    printf("%%dx");
		    break;

		case SI:
		    if (seg)
			printf("%s:", seg);
		    printf("(%s)", short_addr ? "%si" : "%esi");
		    break;

		case DI:
		    printf("%%es:(%s)", short_addr ? "%di" : "%edi");
		    break;

		case CR:
		    printf("%%cr%d", f_reg(regmodrm));
		    break;

		case DR:
		    printf("%%dr%d", f_reg(regmodrm));
		    break;

		case TR:
		    printf("%%tr%d", f_reg(regmodrm));
		    break;

		case I:
		    len = db_lengths[size];
		    get_value_inc(imm, loc, len, FALSE);/* unsigned */
		    printf("$%x", imm);
		    break;

		case Is:
		    len = db_lengths[size];
		    get_value_inc(imm, loc, len, TRUE);	/* signed */
		    printf("$%x", imm);
		    break;

		case Ib:
		    get_value_inc(imm, loc, 1, FALSE);	/* unsigned */
		    printf("$%x", imm);
		    break;

		case Ibs:
		    get_value_inc(imm, loc, 1, TRUE);	/* signed */
		    printf("$%x", imm);
		    break;

		case Iw:
		    get_value_inc(imm, loc, 2, FALSE);	/* unsigned */
		    printf("$%x", imm);
		    break;

		case Il:
		    get_value_inc(imm, loc, 4, FALSE);
		    printf("$%x", imm);
		    break;

		case O:
		    if (short_addr) {
			get_value_inc(displ, loc, 2, TRUE);
		    }
		    else {
			get_value_inc(displ, loc, 4, TRUE);
		    }
		    if (seg)
			printf("%s:%x",seg, displ);
		    else
			db_printsym((ulong)displ);
		    break;

		case Db:
		    get_value_inc(displ, loc, 1, TRUE);
		    db_printsym((ulong)(displ + loc));
		    break;

		case Dl:
		    get_value_inc(displ, loc, 4, TRUE);
		    db_printsym((ulong)(displ + loc));
		    break;

		case o1:
		    printf("$1");
		    break;

		case o3:
		    printf("$3");
		    break;

		case OS:
		    get_value_inc(imm, loc, 4, FALSE);	/* offset */
		    get_value_inc(imm2, loc, 2, FALSE);	/* segment */
		    printf("$%x,%x", imm2, imm);
		    break;
	    }
	}

	if (altfmt == 0) {
	    if (inst == 0xe9 || inst == 0xeb) {
		/*
		 * GAS pads to longword boundary after unconditional jumps.
		 */
		loc = (loc + (4-1)) & ~(4-1);
	    }
	}
	printf("\n");
	return (loc);
}

Added src/bin/adb/expr.c.



























































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#define YYBYACC 1
#line 8 "expr.y"
#ifdef YYDEBUG
int yydebug = 1;
#endif
#line 10 "expr.c"
#include "expr.h"
#define YYERRCODE 256
short yylhs[] = {                                        -1,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,
};
short yylen[] = {                                         2,
    3,    3,    3,    3,    3,    3,    3,    3,    3,    2,
    2,    3,    1,    1,
};
short yydefred[] = {                                      0,
    0,   13,   14,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,   12,    0,
    0,    0,    0,    0,    0,    0,    0,    9,
};
short yydgoto[] = {                                       6,
};
short yysindex[] = {                                    -24,
  -24,    0,    0,  -24,  -24,  -32,  -18,  -18,  -38,  -24,
  -24,  -24,  -24,  -24,  -24,  -24,  -24,  -24,    0,  -26,
  -26,  -18,  -18,  -18,  -18,  -18,  -18,    0,
};
short yyrindex[] = {                                      0,
    0,    0,    0,    0,    0,    0,    1,    8,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,   62,
   64,   18,   25,   32,   39,   47,   54,    0,
};
short yygindex[] = {                                    109,
};
#define YYTABLESIZE 243
short yytable[] = {                                      18,
   11,    0,   19,   10,   12,   18,   13,   10,   11,   10,
   12,   18,   13,    0,   11,    5,   12,    1,   13,   18,
    1,    0,    0,    0,    2,    0,    0,    0,    0,    0,
    0,    5,    0,    0,    0,    0,    0,    0,    6,    0,
    0,   11,   11,   11,    0,   11,    7,   11,   10,   10,
   10,    0,   10,    8,   10,    0,    0,    0,    1,    1,
    1,    4,    1,    3,    1,    2,    2,    2,    0,    2,
    0,    2,    5,    5,    5,    0,    5,    0,    5,    6,
    6,    6,    0,    6,    0,    6,    0,    7,    7,    7,
    0,    7,    0,    7,    8,    8,    8,    0,    8,    0,
    8,    4,    4,    4,    3,    3,    0,    0,    4,    7,
    3,    0,    8,    9,    0,    0,    0,    0,   20,   21,
   22,   23,   24,   25,   26,   27,   28,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,   14,
   15,   16,   17,    0,    0,   14,   15,   16,   17,    0,
    0,   14,   15,   16,   17,    0,    0,    2,    3,   14,
   15,   16,   17,
};
short yycheck[] = {                                      38,
    0,   -1,   41,   42,   43,   38,   45,    0,   47,   42,
   43,   38,   45,   -1,   47,   40,   43,    0,   45,   38,
   45,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,
   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,
   -1,   41,   42,   43,   -1,   45,    0,   47,   41,   42,
   43,   -1,   45,    0,   47,   -1,   -1,   -1,   41,   42,
   43,    0,   45,    0,   47,   41,   42,   43,   -1,   45,
   -1,   47,   41,   42,   43,   -1,   45,   -1,   47,   41,
   42,   43,   -1,   45,   -1,   47,   -1,   41,   42,   43,
   -1,   45,   -1,   47,   41,   42,   43,   -1,   45,   -1,
   47,  126,   41,   42,   41,   42,   -1,   -1,   47,    1,
   47,   -1,    4,    5,   -1,   -1,   -1,   -1,   10,   11,
   12,   13,   14,   15,   16,   17,   18,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,
  259,  260,  261,   -1,   -1,  258,  259,  260,  261,   -1,
   -1,  258,  259,  260,  261,   -1,   -1,  262,  263,  258,
  259,  260,  261,
};
#define YYFINAL 6
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 263
#if YYDEBUG
char *yyname[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,"'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'~'",0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
"MINUS","LE","GE","EQ","NE","ID","INT",
};
char *yyrule[] = {
"$accept : expr",
"expr : expr '+' expr",
"expr : expr '-' expr",
"expr : expr '/' expr",
"expr : expr '*' expr",
"expr : expr LE expr",
"expr : expr GE expr",
"expr : expr EQ expr",
"expr : expr NE expr",
"expr : expr '&' expr",
"expr : '~' expr",
"expr : '-' expr",
"expr : '(' expr ')'",
"expr : ID",
"expr : INT",
};
#endif
#ifndef YYSTYPE
typedef int YYSTYPE;
#endif
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#ifdef YYSTACKSIZE
#ifndef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#endif
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 500
#define YYMAXDEPTH 500
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#define YYABORT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse(void)
{
    register int yym, yyn, yystate;
#if YYDEBUG
    register char *yys;
    extern char *getenv();

    yys = getenv("YYDEBUG");
    if (yys) {
        yyn = *yys;
        if (yyn >= '0' && yyn <= '9')
            yydebug = yyn - '0';
    }
#endif

    yynerrs = 0;
    yyerrflag = 0;
    yychar = (-1);

    yyssp = yyss;
    yyvsp = yyvs;
    *yyssp = yystate = 0;

yyloop:
    yyn = yydefred[yystate];
    if (yyn) goto yyreduce;
    if (yychar < 0)
    {
	yychar = yylex();
        if (yychar < 0) yychar = 0;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("yydebug: state %d, reading %d (%s)\n", yystate,
                    yychar, yys);
        }
#endif
    }
    yyn = yysindex[yystate];
    if (yyn && ((yyn += yychar) >= 0) &&
            (yyn <= YYTABLESIZE) && (yycheck[yyn] == yychar))
    {
#if YYDEBUG
        if (yydebug)
            printf("yydebug: state %d, shifting to state %d\n",
                    yystate, yytable[yyn]);
#endif
        if (yyssp >= yyss + yystacksize - 1)
        {
            goto yyoverflow;
        }
        *++yyssp = yystate = yytable[yyn];
        *++yyvsp = yylval;
        yychar = (-1);
        if (yyerrflag > 0)  --yyerrflag;
        goto yyloop;
    }
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
    {
        yyn = yytable[yyn];
        goto yyreduce;
    }
    if (yyerrflag) goto yyinrecovery;
#ifdef lint
    goto yynewerror;
#endif
    yyerror("syntax error");
#ifdef lint
    goto yyerrlab;
#endif
    ++yynerrs;
yyinrecovery:
    if (yyerrflag < 3)
    {
        yyerrflag = 3;
        for (;;)
        {
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
            {
#if YYDEBUG
                if (yydebug)
                    printf("yydebug: state %d, error recovery shifting\
 to state %d\n", *yyssp, yytable[yyn]);
#endif
                if (yyssp >= yyss + yystacksize - 1)
                {
                    goto yyoverflow;
                }
                *++yyssp = yystate = yytable[yyn];
                *++yyvsp = yylval;
                goto yyloop;
            }
            else
            {
#if YYDEBUG
                if (yydebug)
                    printf("yydebug: error recovery discarding state %d\n",
                            *yyssp);
#endif
                if (yyssp <= yyss) goto yyabort;
                --yyssp;
                --yyvsp;
            }
        }
    }
    else
    {
        if (yychar == 0) goto yyabort;
#if YYDEBUG
        if (yydebug)
        {
            yys = 0;
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
            if (!yys) yys = "illegal-symbol";
            printf("yydebug: state %d, error recovery discards token %d (%s)\n",
                    yystate, yychar, yys);
        }
#endif
        yychar = (-1);
        goto yyloop;
    }
yyreduce:
#if YYDEBUG
    if (yydebug)
        printf("yydebug: state %d, reducing by rule %d (%s)\n",
                yystate, yyn, yyrule[yyn]);
#endif
    yym = yylen[yyn];
    yyval = yyvsp[1-yym];
    switch (yyn)
    {
case 1:
#line 16 "expr.y"
{yyval = yyvsp[-2] + yyvsp[0];}
break;
case 2:
#line 18 "expr.y"
{yyval = yyvsp[-2] - yyvsp[0];}
break;
case 3:
#line 20 "expr.y"
{yyval = yyvsp[-2] / yyvsp[0];}
break;
case 4:
#line 22 "expr.y"
{yyval = yyvsp[-2] * yyvsp[0];}
break;
case 5:
#line 24 "expr.y"
{yyval = yyvsp[-2] <= yyvsp[0];}
break;
case 6:
#line 26 "expr.y"
{yyval = yyvsp[-2] >= yyvsp[0];}
break;
case 7:
#line 28 "expr.y"
{yyval = yyvsp[-2] == yyvsp[0];}
break;
case 8:
#line 30 "expr.y"
{yyval = yyvsp[-2] != yyvsp[0];}
break;
case 9:
#line 32 "expr.y"
{yyval = yyvsp[-2] & yyvsp[0];}
break;
case 10:
#line 34 "expr.y"
{yyval = ~yyvsp[0];}
break;
case 11:
#line 36 "expr.y"
{yyval = 0-yyvsp[0];}
break;
case 12:
#line 38 "expr.y"
{yyval = yyvsp[-1];}
break;
#line 350 "expr.c"
    }
    yyssp -= yym;
    yystate = *yyssp;
    yyvsp -= yym;
    yym = yylhs[yyn];
    if (yystate == 0 && yym == 0)
    {
#if YYDEBUG
        if (yydebug)
            printf("yydebug: after reduction, shifting from state 0 to\
 state %d\n", YYFINAL);
#endif
        yystate = YYFINAL;
        *++yyssp = YYFINAL;
        *++yyvsp = yyval;
        if (yychar < 0)
        {
            if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
            if (yydebug)
            {
                yys = 0;
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
                if (!yys) yys = "illegal-symbol";
                printf("yydebug: state %d, reading %d (%s)\n",
                        YYFINAL, yychar, yys);
            }
#endif
        }
        if (yychar == 0) goto yyaccept;
        goto yyloop;
    }
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
        yystate = yytable[yyn];
    else
        yystate = yydgoto[yym];
#if YYDEBUG
    if (yydebug)
        printf("yydebug: after reduction, shifting from state %d \
to state %d\n", *yyssp, yystate);
#endif
    if (yyssp >= yyss + yystacksize - 1)
    {
        goto yyoverflow;
    }
    *++yyssp = yystate;
    *++yyvsp = yyval;
    goto yyloop;
yyoverflow:
    yyerror("yacc stack overflow");
yyabort:
    return (1);
yyaccept:
    return (0);
}

Added src/bin/adb/expr.h.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef EXPR_H
#define EXPR_H
/*
 * expr.h
 *	Common definitions shared between lex and parser
 */

#define MINUS 257
#define LE 258
#define GE 259
#define EQ 260
#define NE 261
#define ID 262
#define INT 263

extern int yylex(void), yyparse(void);
extern void yyerror(char *);

extern int yylval;

#endif /* EXPR_H */

Added src/bin/adb/i386.c.























































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * i386.c
 *	Routines which know all the gore of the i386
 */
#include <stdio.h>
#include "adb.h"
#include <sys/param.h>
#include <std.h>

/*
 * flagnames()
 *	Return string describing flags
 */
static char *
flagnames(ulong eflags)
{
	static char buf[60];

	buf[0] = '\0';
	if (eflags & F_CF) strcat(buf, " carry");
	if (eflags & F_PF) strcat(buf, " parity");
	if (eflags & F_AF) strcat(buf, " bcd");
	if (eflags & F_ZF) strcat(buf, " zero");
	if (eflags & F_SF) strcat(buf, " sign");
	if (eflags & F_DF) strcat(buf, " dir");
	if (eflags & F_OF) strcat(buf, " overflow");
	return(buf);
}

/*
 * dump_regs()
 *	Print out registers
 */
void
dump_regs(void)
{
	struct trapframe t;

	getregs(&t);
	printf("eip 0x%lx (%s) eflags %s\n",
		t.eip, nameval(t.eip), flagnames(t.eflags));
	printf(" eax 0x%lx ebx 0x%lx ecx 0x%lx edx 0x%lx esi 0x%lx edi 0x%lx\n",
		t.eax, t.ebx, t.ecx, t.edx, t.esi, t.edi);
	printf(" esp 0x%lx ebp 0x%lx\n",
		t.esp, t.ebp);
}

/*
 * show_here()
 *	Pick up current EIP, and show location
 */
void
show_here(void)
{
	struct trapframe t;

	getregs(&t);
	printf("%s:\t", nameval(t.eip));
	(void)db_disasm(t.eip, 0);
}

/*
 * trace()
 *	Show backtrace of stack calls
 */
void
backtrace(void)
{
	ulong eip, ebp, oebp;
	struct trapframe t;
	struct stkframe {
		uint s_ebp;
		uint s_eip;
	} s;

	/*
	 * Get initial registers
	 */
	getregs(&t);
	eip = t.eip;
	ebp = t.ebp;

 	/*
 	 * Loop, reading pairs of frame pointers and return addresses
 	 */
#define INSTACK(v) (v <= 0x7FFFFFF8)
	while (INSTACK(ebp)) {
		uint narg, x;
		char *p, *loc;

 		/*
 		 * Read next stack frame, output called procedure name
 		 */
		s.s_ebp = readloc(ebp, sizeof(ulong));
		if (s.s_ebp == 0)
			break;
		s.s_eip = readloc(ebp+4, sizeof(ulong));
		if (s.s_eip == 0)
			break;
 		loc = nameval(eip);
 		if ((p = strchr(loc, '+'))) {
 			*p = '\0';
		}
 		printf("%s(", loc);

 		/*
 		 * Calculate number of arguments, default to 4.  We
 		 * figure it out by looking at the stack cleanup at
 		 * the return address.  If GNU C has optimized this
 		 * out (for instance, bunched several cleanups together),
 		 * we're out of luck.
 		 */
		if ((s.s_eip < NBPG) || (s.s_eip > 0x7FFFFFFF)) {
			x = 0;
		} else {
			x = readloc(s.s_eip, sizeof(ulong));
		}
		if (x == 0)
			break;
 		if ((x & 0xFF) == 0x59) {
 			narg = 1;
		} else if ((x & 0xFFFF) == 0xC483) {
			narg = ((x >> 18) & 0xF);
		} else {
			narg = 4;
		}

 		/*
 		 * Print arguments
 		 */
 		for (x = 0; x < narg; ++x) {
			uint idx;
			ulong val;

			idx = (x+2)*sizeof(ulong);
			if (INSTACK(ebp+idx)) {
				val = readloc(ebp + idx, sizeof(ulong));
			} else {
				val = 0;
			}
 			printf("%s0x%lx", x ? ", " : "", val);
		}

		/*
		 * Print where called from.  We just assume that there's
		 * a 5-byte long call.  Wrong for function pointers.
		 */
		printf(") called from %s\n", nameval(s.s_eip-5));
		oebp = ebp;
 		ebp = s.s_ebp;
 		eip = s.s_eip;

		/*
		 * Make sure stack frames go in the right direction,
		 * and isn't too big a jump.
		 */
		if ((ebp <= oebp) || (ebp > (oebp + 32768))) {
			break;
		}
 	}
}

/*
 * regs_pc()
 *	Return "program counter" value as extracted from machine state
 */
ulong
regs_pc(struct trapframe *tf)
{
	return(tf->eip);
}

Added src/bin/adb/lex.c.































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * A standard lexical analyzer
 */
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <std.h>
#include "adb.h"
#include "expr.h"

static char *expr_line, *expr_pos;

static char buf[80];
static int donum(int);

/*
 * Convert hex and decimal strings to integers
 */
static int
xtoi(char *p)
{
	unsigned int val = 0;
	char c;

	while ((c = *p++)) {
		if (isdigit(c)) {
			val = val*16 + (c - '0');
		} else if (isxdigit(c)) {
			if (c < 'a') {
				val = val*16 + (c - 'A') + 10;
			} else {
				val = val*16 + (c - 'a') + 10;
			}
		} else {
			break;
		}
	}
	return(val);
}

 /*
  * getchar() function for lexical analyzer.
  */
static int
nextc()
{
	register int c;

	/*
	 * Pop up a level of indirection on EOF
	 */
	c = *expr_pos;
	if (c == '\0') {
		return(-1);
	}
	expr_pos += 1;
	return (c);
}

/*
 * Push back a character
 */
static void inline
unget_c(int c)
{
	if ((expr_pos <= expr_line) || (c == -1) || !c) {
		return;
	}
	expr_pos -= 1;
	*expr_pos = c;
}

/*
 * Skip leading white space in current input stream
 */
static void
skipwhite(void)
{
	register c;

	/*
	 * Skip leading blank space
	 */
	while ((c = nextc()) != -1) {
		if (!isspace(c)) {
			break;
		}
	}
	unget_c(c);
}

/*
 * Lexical analyzer for YACC
 */
int
yylex(void)
{
	register char *p = buf;
	register c, c1;

	/*
	 * Skip over white space
	 */
	skipwhite();
	c = nextc();

	/*
	 * Return EOF
	 */
	if (c == -1) {
		return (c);
	}

	/*
	 * An "identifier"?
	 */
	if (isalpha(c) || (c == '_')) {
		/*
		 * Assemble a "word" out of the input stream, symbol table it
		 */
		*p++ = c;
		for (;;) {
			c = nextc();
			if (!isalnum(c) && (c != '_')) {
				break;
			}
			*p++ = c;
		}
		unget_c(c);
		*p = '\0';
		yylval = symval(buf);
		return (ID);
	}

	/*
	 * For numbers, call our number routine.
	 */
	if (isdigit(c)) {
		return (donum(c));
	}

	/*
	 * For certain C operators, need to look at following char to
	 *	assemble relationals.  Otherwise, just return the char.
	 */
	yylval = c;
	switch (c) {
	case '<':
		if ((c1 = nextc()) == '=') {
			return (LE);
		}
		unget_c(c1);
		return (c);
	case '>':
		if ((c1 = nextc()) == '=') {
			return (GE);
		}
		unget_c(c1);
		return (c);
	case '~':
		if ((c1 = nextc()) == '=') {
			return (NE);
		}
		unget_c(c1);
		return (c);
	default:
		return (c);
	}
}

/*
 * donum()
 *	Handle parsing of a number
 */
static int
donum(int startc)
{
	register char c, *p = buf;

	/*
	 * Hex numbers
	 */
	if (startc == '0') {
		c = nextc();
		if (c == 'x') {
			c = nextc();
			while (isxdigit(c)) {
				*p++ = c;
				c = nextc();
			}
			unget_c(c);
			*p = '\0';
			yylval = xtoi(buf);
			return (INT);
		}
		unget_c(c);
	}

	/*
	 * Otherwise assume decimal
	 */
	*p++ = startc;
	for (;;) {
		c = nextc();
		if (isdigit(c)) {
			*p++ = c;
			continue;
		}
		unget_c(c);
		break;
	}
	*p = '\0';
	yylval = atoi(buf);
	return (INT);
}

/*
 * getnum()
 *	Pull number from character stream
 *
 * We assume expression boundary is at first character which isn't
 * a legal digit, letter, or operator.
 */
char *
getnum(char *p, uint *valp)
{
	char *q, c, buf[128];
	extern uint yyval;

	expr_pos = expr_line = buf;
	buf[127] = '\0';
	strncpy(buf, p, 127);
	for (q = buf; (c = *q); ++q) {
		if (isalnum(c) || (c == '+') || (c == '-') ||
				(c == '_'))
			continue;
		break;
	}
	p += (q - buf);
	*q = '\0';
	(void)yyparse();
	*valp = yyval;
	return(p);
}

/*
 * yyerror()
 *	Report syntax error
 */
void
yyerror(char *msg)
{
	printf("Expression error: %s\n", msg);
	longjmp(errjmp, 1);
}

Added src/bin/adb/makefile.























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
COPTS=-Wall
OBJS=adb.o disasm.o expr.o lex.o sym.o map.o proc.o i386.o
OUT=adb
include ../../makefile.all

adb: $(OBJS)
	$(LD) $(LDFLAGS) -o adb $(CRT0) $(OBJS) -lc

install: adb
	strip adb
	cp adb $(ROOT)/bin

Added src/bin/adb/map.c.













































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * map.c
 *	Map data structure manipulation
 */
#include "map.h"
#include <std.h>

/*
 * alloc_map()
 *	Get a map
 */
struct map *
alloc_map(void)
{
	struct map *m;

	m = malloc(sizeof(struct map));
	if (m) {
		m->m_nmap = 0;
	}
	return(m);
}

/*
 * add_map()
 *	Add another mapping
 *
 * Returns 1 if it can't fit, 0 on success
 */
int
add_map(struct map *m, void *base, ulong len, ulong off)
{
	struct mslot *ms;

	if (m->m_nmap >= NMAP) {
		return(1);
	}
	ms = &m->m_map[m->m_nmap++];
	ms->m_addr = base;
	ms->m_len = len;
	ms->m_off = off;
	return(0);
}

/*
 * do_map()
 *	Given vaddr, return offset
 *
 * Offset is passed in *off; return 1 on illegal addr, 0 on success
 */
int
do_map(const struct map *m, const void *vaddr, ulong *off)
{
	uint x;

	for (x = 0; x < m->m_nmap; ++x) {
		struct mslot *ms;

		ms = (struct mslot *)&m->m_map[x];
		if (vaddr < ms->m_addr) {
			continue;
		}
		if ((char *)vaddr >= ((char *)ms->m_addr + ms->m_len)) {
			continue;
		}
		*off = ((char *)vaddr - (char *)ms->m_addr) + ms->m_off;
		return(0);
	}
	return(1);
}

Added src/bin/adb/map.h.

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#ifndef MAP_H
#define MAP_H
/*
 * map.h
 *	Data structures for defining ranges of a file
 *
 * Various virtual addresses map to different parts of a file (or
 * memory, for that matter).  A map structure describes a virtual
 * address, length, and corresponding offset.
 */
#include <sys/types.h>

#define NMAP (4)		/* # mapping ranges handled */

/*
 * An entry within a map
 */
struct mslot {
	void *m_addr;		/* Starting addr */
	ulong m_len,		/* Length (bytes) */
		m_off;		/* Offset (bytes) */
};

/*
 * A map
 */
struct map {
	uint m_nmap;
	struct mslot m_map[NMAP];
};

/*
 * Routines
 */
extern struct map *alloc_map(void);
extern int add_map(struct map *, void *, ulong, ulong),
	do_map(const struct map *, const void *, ulong *);
extern void map_aout(struct map *);

#endif MAP_H

Added src/bin/adb/proc.c.









































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * proc.c
 *	Handling of a running process
 */
#include <sys/msg.h>
#define PROC_DEBUG
#include <sys/proc.h>
#include <fcntl.h>
#include <stdio.h>
#include <std.h>
#include "adb.h"
#include "map.h"

static void
	*bpoints[MAX_BPOINT];	/* Breakpoints set */
static uint nbpoint = 0;	/*  ...how many in bpoints[] */
static int ever_ran = 0;	/* Tell if first run */
static int stepping = 0;	/* Stepping currently? */
ulong why_stop;			/* Copy of flags for why we stopped */

/*
 * sendhim()
 *	Handling for all the tedium of talking to our slave
 */
static int
sendhim(int op, ulong *args)
{
	static struct msg m;
	int x;
	static int connected = 0,	/* Have seen MSG_CONNECT */
		listening = 0;		/* Is currently listening to us */

	/*
	 * If we have never heard from him, wait for the connection
	 */
	if (!connected) {
		x = msg_receive(dbg_port, &m);
		if (x < 0) {
			perror("Listen for slave");
			exit(1);
		}
		m.m_op &= MSG_MASK;
		if (m.m_op != M_CONNECT) {
			printf("Unexpected message type %d\n", m.m_op);
			exit(1);
		}
		if (msg_accept(m.m_sender) < 0) {
			perror("Accept of slave");
			exit(1);
		}
		connected = 1;
	}

	/*
	 * Now wait for him to send us a request.  Our relationship with
	 * him is strange; we are the server, so we have to wait for him
	 * to make a request.
	 */
	while (!listening) {
		x = msg_receive(dbg_port, &m);
		if (x < 0) {
			perror("Listen for slave request");
			exit(1);
		}

		switch (m.m_op) {
		case M_DISCONNECT:
			/*
			 * He exited, or something like that
			 */
		 	printf("Lost connect to slave\n");
			exit(1);

		case M_DUP:
			/*
			 * He fork()'ed a child; ignore the child
			 */
			break;

		case PD_SLAVE:
			why_stop = m.m_arg;
			/* VVV fall into VVV */
		default:
			listening = 1;
			break;
		}
	}

	/*
	 * Formulate our request, and send it to him.  That is,
	 * reply to his "request" with our command.  His next
	 * "request" will have the answer.
	 */
	m.m_op = op;
	m.m_nseg = 0;
	m.m_arg = args[0];
	m.m_arg1 = args[1];
	if (msg_reply(m.m_sender, &m) < 0) {
		perror("Reply to slave");
		exit(1);
	}

	/*
	 * Now get his answer
	 */
	x = msg_receive(dbg_port, &m);
	if (x < 0) {
		perror("Response from slave");
		exit(1);
	}
	args[0] = m.m_arg;
	args[1] = m.m_arg1;
	return(0);
}

/*
 * read_procmem()
 *	Read some bytes from process memory
 */
ulong
read_procmem(ulong addr, int size)
{
	ulong args[2];
	uchar c;
	ushort w;
	ulong l;

	args[0] = addr;
	args[1] = 0;
	if ((sendhim(PD_RDMEM, args) < 0) || args[1]) {
		printf("Read error at addr 0x%lx\n", addr);
		return(0);
	}
	l = args[0];
	switch (size) {
	case 1: c = *(char *)&l; return(c);
	case 2: w = *(ushort *)&l; return(w);
	case 4: return(l);
	}
	return(0);
}

/*
 * eventstr()
 *	Return current event
 */
static char *
eventstr(void)
{
	static char evstr[ERRLEN+2];
	uint x;
	ulong args[2];

	for (x = 0; x < ERRLEN; ++x) {
		args[0] = x;
		args[1] = 0;
		if (sendhim(PD_MEVENT, args) < 0) {
			evstr[x] = '\0';
			break;
		}
		evstr[x] = args[1];
		if (evstr[x] == '\0') {
			break;
		}
	}
	if (evstr[0] == '\0') {
		return(0);
	}
	return(evstr);
}

/*
 * cur_event()
 *	Print out why we're stopped
 */
static void
cur_event(void)
{
	printf("pid %ld stopped", corepid);
	if (why_stop & PD_EVENT) {
		printf(" at event: %s", eventstr());
	} else if (why_stop & PD_BPOINT) {
		if (!stepping) {
			printf(" at breakpoint");
		}
	} else if (why_stop & PD_EXIT) {
		printf(" while exiting");
	}
	printf("\n");
}

/*
 * run()
 *	Tell slave to run
 */
void
run(void)
{
	ulong args[2];

	/*
	 * When we first attach to a process, his mask is set
	 * to trap him out ASAP.  Now drop the mask back to
	 * what we need.
	 */
	if (!ever_ran) {
		args[0] = PD_EVENT|PD_EXIT|PD_BPOINT;
		args[1] = 0;
		(void)sendhim(PD_MASK, args);
		ever_ran = 1;
	}

	/*
	 * Away he goes.  We don't return until he breaks.
	 */
	args[0] = args[1] = 0;
	if (sendhim(PD_RUN, args) < 0) {
		printf("Error telling child to run\n");
	}
	why_stop = args[0];

	/*
	 * Show where he popped up
	 */
	cur_event();
	show_here();
}

/*
 * step()
 *	Set single-step, and run one step
 *
 * If "over" is true, will "step" by figuring out address of
 * next instruction, and setting temporary breakpoint there.
 * This has the effect of stepping over function calls, if the
 * next instruction is a "call".
 */
void
step(int over)
{
	ulong args[2];
	int oldstdout, tempstdout;
	uint nextpc;
	struct trapframe cur_regs;

	/*
	 * Ask him to step, use run(), and then clear the step stuff
	 * so we can continue properly.
	 */
	if (!over) {
		args[0] = 1;
		args[1] = 0;
		(void)sendhim(PD_STEP, args);
		run();
		args[0] = 0;
		args[1] = 0;
		(void)sendhim(PD_STEP, args);
		return;
	}

	/*
	 * Arrange for disassembler to silently calculate
	 * next instruction address for us.  It does printf()'s,
	 * so we just channel stdout to nowhere for a second...
	 */
	getregs(&cur_regs);
	oldstdout = dup(1);
	close(1);
	tempstdout = open("/dev/null", O_WRITE);
	nextpc = db_disasm(regs_pc(&cur_regs), 0);
	close(tempstdout);
	dup2(oldstdout, 1);
	close(oldstdout);
	set_breakpoint((void *)nextpc);
	run();
	clear_breakpoint((void *)nextpc);
}

/*
 * getregs()
 *	Pull copy of register set
 */
void
getregs(struct trapframe *tf)
{
	uint x;
	ulong *t;

	t = (ulong *)tf;
	for (x = 0; x < sizeof(struct trapframe); x += sizeof(ulong)) {
		ulong args[2];

		args[0] = x/sizeof(ulong);
		args[1] = 0;
		if (sendhim(PD_RDREG, args) < 0) {
			*t++ = 0;
		} else {
			*t++ = args[0];
		}
	}
}

/*
 * set_breakpoint()
 *	Set a new breakpoint
 */
void
set_breakpoint(void *addr)
{
	uint x;
	ulong args[2];

	/*
	 * Check count and addr
	 */
	if (nbpoint >= MAX_BPOINT) {
		printf("No more breakpoints possible\n");
		return;
	}
	if (!addr) {
		printf("Invalid breakpoint address\n");
		return;
	}

	/*
	 * Find slot for operation
	 */
	for (x = 0; x < MAX_BPOINT; ++x) {
		if (!bpoints[x])
			break;
	}

	/*
	 * Update breakpoint table
	 */
	if (x >= MAX_BPOINT) {
		printf("Oops, breakpoint table out of synch\n");
		return;
	}
	nbpoint += 1;
	bpoints[x] = addr;

	/*
	 * Tell our humble slave
	 */
	args[1] = (ulong)addr;
	args[0] = 1;
	if (sendhim(PD_BREAK, args) < 0) {
		bpoints[x] = 0;
		nbpoint -= 1;
		printf("Breakpoint operation failed\n");
	}
}

/*
 * clear_breakpoint()
 *	Clear a breakpoint
 */
void
clear_breakpoint(void *addr)
{
	uint x;
	ulong args[2];

	/*
	 * Check count and addr
	 */
	if (!nbpoint) {
		printf("No breakpoints set\n");
		return;
	}

	/*
	 * Find slot for operation
	 */
	for (x = 0; x < MAX_BPOINT; ++x) {
		if (bpoints[x] == addr) {
			/*
			 * May as well clear it now
			 */
			bpoints[x] = 0;
			nbpoint -= 1;
			break;
		}
	}

	/*
	 * Complain on bogosity
	 */
	if (x >= MAX_BPOINT) {
		printf("No breakpoint at 0x%lx\n", (ulong)addr);
		return;
	}

	/*
	 * Tell our humble slave
	 */
	args[1] = (ulong)addr;
	args[0] = 0;
	if (sendhim(PD_BREAK, args) < 0) {
		printf("Breakpoint operation failed\n");
	}
}

/*
 * clear_breakpoints()
 *	Clear all current breakpoints
 */
void
clear_breakpoints(void)
{
	uint x;

	for (x = 0; x < MAX_BPOINT; ++x) {
		if (!bpoints[x])
			continue;
		clear_breakpoint(bpoints[x]);
	}
}

/*
 * dump_breakpoints()
 *	List out current breakpoints
 */
void
dump_breakpoints(void)
{
	uint x;

	printf("Current breakpoints:\n");
	for (x = 0; x < MAX_BPOINT; ++x) {
		if (bpoints[x]) {
			printf(" %s (0x%lx)\n",
				nameval((ulong)bpoints[x]),
				(ulong)bpoints[x]);
		}
	}
}

/*
 * wait_exec()
 *	Fiddle flags and wait for child process to finish exec()'iing
 */
void
wait_exec(void)
{
	ulong args[2];

	/*
	 * Tell him to break on exec completion
	 */
	args[0] = PD_EXEC;
	args[1] = 0;
	if (sendhim(PD_MASK, args) < 0) {
		printf("Failed to catch child exec\n");
		exit(1);
	}

	/*
	 * Run to that point.  We're in control, so short-circuit
	 * run()'s desire to choose a working mask for now.  Set it
	 * back so they can be set when we run him the first time
	 * "for real".
	 */
	ever_ran = 1;
	run();
	ever_ran = 0;
}

Added src/bin/adb/sym.c.











































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * sym.c
 *	Handle symbol table read-in
 *
 * From code:
 * Written by Pace Willisson (pace@blitz.com)
 * and placed in the public domain.
 * Hacked for VSTa by Andy Valencia (vandys@cisco.com).  This file is
 * still in the public domain.
 */
#include <stdio.h>
#include <mach/aout.h>
#include <mach/nlist.h>
#include <std.h>
#include <sys/param.h>
#include "adb.h"
#include "map.h"

/*
 * This is all that's really needed from the symbol table
 */
struct sym {
	char *s_name;
	ulong s_val;
};

static struct sym *symtab;	/* Name/val mappings */
static uint nsym = 0;		/*  ...size */
static struct aout main_hdr;	/* a.out header we loaded first */
static int hdr_loaded;		/*  ->1 when loaded */

/*
 * rdsym()
 *	Read symbols from a.out
 */
void
rdsym(char *name)
{
	FILE *f;
	uint i;
	int strtab_size, num_full_syms;
	struct nlist *sp;
	struct aout hdr;
	char *full_strtab;		/* All entries from all a.out's */
	struct nlist *full_syms;		/* All nlist entries */


	if ((f = fopen(name, "r")) == NULL) {
		fprintf(stderr, "can't open %s\n", name);
		exit(1);
	}

	if (fread((char *)&hdr, sizeof hdr, 1, f) != 1) {
		fprintf(stderr, "can't read header\n");
		exit(1);
	}

	if (N_BADMAG(hdr)) {
		fprintf(stderr, "bad magic number\n");
		exit(1);
	}

	if (hdr.a_syms == 0) {
		fprintf(stderr, "no symbols\n");
		fclose(f);
		return;
	}

	fseek (f, N_STROFF(hdr), 0);
	if (fread((char *)&strtab_size, sizeof(int), 1, f) != 1) {
		fprintf(stderr, "can't read old strtab size\n");
		exit(1);
	}

	full_strtab = malloc(strtab_size);
	full_syms = malloc(hdr.a_syms);
	if (!full_syms || !full_strtab) {
		perror(name);
		exit(1);
	}

	fseek(f, N_SYMOFF(hdr), 0);
	if (fread(full_syms, hdr.a_syms, 1, f) != 1) {
		fprintf (stderr, "can't read symbols\n");
		exit (1);
	}

	fseek(f, N_STROFF(hdr), 0);
	if (fread(full_strtab, strtab_size, 1, f) != 1) {
		fprintf (stderr, "can't read string table\n");
		exit (1);
	}

	/*
	 * All done with the file
	 */
	fclose(f);

	/*
	 * Index just those symbols which are useful
	 */
	sp = full_syms;
	num_full_syms = hdr.a_syms / sizeof (struct nlist);
	for (i = 0; sp && (i < num_full_syms); i++, sp++) {
		char *name;

		/*
		 * Skip useless entries
		 */
		if (sp->n_type & N_STAB)
			continue;
		if (sp->n_un.n_strx == 0)
			continue;
		if (sp->n_value >= 0x80000000)
			continue;
		name = full_strtab + sp->n_un.n_strx;
		if (strlen(name) == 0)
			continue;
		if (strchr(name, '.'))
			continue;
		if (!strncmp(name, "___gnu", 6))
			continue;

		/*
		 * Map everything to have one less leading '_'
		 */
		if (name[0] == '_') {
			name += 1;
		}

		/*
		 * Now add to our index
		 */
		symtab = realloc(symtab, ++nsym * sizeof(struct sym));
		if (symtab == 0) {
			perror("string table");
			exit(1);
		}
		name = strdup(name);
		if (name == NULL) {
			perror("string table");
		}
		symtab[nsym-1].s_name = name;
		symtab[nsym-1].s_val = sp->n_value;
	}

	/*
	 * Free temp storage
	 */
	free(full_strtab);
	free(full_syms);

	/*
	 * Snapshot header for first one loaded
	 */
	if (!hdr_loaded) {
		main_hdr = hdr;
		hdr_loaded = 1;
	}
}

/*
 * nameval()
 *	Map numeric offset to closest symbol plus offset
 */
char *
nameval(ulong val)
{
	uint i;
	struct sym *s;
	static char buf[128];
	ulong closest = 0;
	char *closename = 0;

	for (i = 0; i < nsym; ++i) {
		s = &symtab[i];

		/*
		 * Bound value
		 */
		if ((s->s_val < 0x1000) || (s->s_val > val))
			continue;

		/*
		 * If it's the closest fit, record it
		 */
		if (s->s_val > closest) {
			closest = s->s_val;
			closename = s->s_name;
		}
	}

	/*
	 * If did find anything, just return hex number
	 */
	if (!closename) {
		sprintf(buf, "0x%lx", val);
	} else {
		/*
		 * Otherwise give them name + offset
		 */
		if (closest == val) {
			strcpy(buf, closename);
		} else {
			sprintf(buf, "%s+0x%lx", closename,
				val - closest);
		}
	}
	return(buf);
}

/*
 * symval()
 *	Given symbol name, return its value
 */
ulong
symval(char *p)
{
	ui