
<h4>
Q: How can I learn to program in C?
</h4>
<p>
A: The first edition of Andy Tanenbaum's <b><i>Operating Systems Design
and Implementation</i></b> included an <i>Introduction to C</i>
appendix.  Alas, with a much bigger Minix 2.0 there was no room for
this in the <b><i>OSDI 2nd ed</i></b>.  It's also a bit out of date, as
it describes the original version of C (often referred to as "K&amp;R C")
defined in the 1978 first edition of <b><i>The C Programming
Language</i></b> by Brian Kernighan and Dennis Ritchie.  The 1988
second edition describes "ANSI C" or "Standard C" which is the
reference language for implementing POSIX, although the POSIX standard
allows "Common Usage C" using pre-standard features.  After the
<b><i>OSDI 2nd ed.</i></b> text, a copy of <b><i>The C Programming
Language, 2nd ed.</i></b> is the most useful book you can own to
understand or program in Minix.
</p>  

<h4>
Q: In addition to C, what else do I need to know to program in the Minix 
environment?
</h4>

<p>
A: A classic book is Brian Kernighan and Rob Pike's <b><i>Unix
Programming Environment</i></b>, unfortunately now out of print, but
check Amazon.com or other sources of used books.  This book emphasizes
the use of small programs that do parts of large jobs, and suggests
starting with shell scripts, replacing standard commands in the script
with custom C programs as needed until the overall system is able to
the job at hand well enough.  The same authors' newer book <b><i>The
Practice of Programming</i></b> (1999) is also of interest, although
probably not as useful to a beginning programmer. W. Richard Stevens' 
<b><i>Advanced Programming in the UNIX(R) Environment</i></b> is 
another book with a wealth of information about how to use the resources 
provided by a Unix-like environment, but it also is not a beginner's book.
</p>

<h4>
Q: I'm just beginning and I don't want to buy another expensive book, do
you have any other suggestions?
</h4>

<p>
I recommend looking at
<a href="http://hacking101.sourceforge.net/Hacking101/t1.html">
Hacking 101: Becoming Productive Quickly in the UNIX World</a>,
written by Philip Fong.
It was written with Linux users in mind, but much of it is relevant 
to the Minix world as well.
</p> 
<p>
Eric Raymond's
<a href="http://www.faqs.org/docs/artu/">The Art of Unix Programming</a>.
can be read on-line, or as 
<a href="http://www.amazon.com/gp/product/0131429019/sr=8-2/qid=1142189381/ref=pd_bbs_2/102-7109449-0951323?%5Fencoding=UTF8">
a paperback book from Addison-Wesley</a>. 
This is not a programming text,
there is no code in it. As one review on the Amazon site put it, "This book 
is as much about using Unix as it is about programming with Unix."

</p>

<h4>
Q: How about shell script programming?
</h4>
<p>
A: The Minix shell, <b>ash</b>, is similar to <b>bash</b>, the standard
shell in most Linux distributions.  A series of articles on 
<a href="http://www-106.ibm.com/developerworks/library/l-bash.html"> 
Bash by example</a> 
is well worth a look, although not everything is applicable to Minix.
If you are willing to buy a big book the <b><i>Unix Power Tools</i></b>
compendium (Shelley Powers, Jerry Peek, and numerous other authors and
contributors) gives lots of hints on using Unix shells and commands and
has several chapters on scripts.  Hint: the current edition of
<b><i>Unix Power Tools</i></b> is the 3rd.  If you find a discounted
2nd edition at 1/3rd of the price you may find this an attractive
bargain.  The information doesn't go stale, and for the Minix
text-based console environment an older reference may be good enough.
</p>



<h4>
Q: I hear a lot about security problems, any hints on secure programming?
</h4>

<p>
Even though at the start you may think that your programs on your
little non-networked Minix system will never be a security threat, it
is a good idea to learn a little bit about secure programming early in
your programming career.  Two useful references are the 
<a href="http://www.whitefang.com/sup/">
Secure UNIX Programming FAQ</a> 
maintained by Thamer Al-Herbish, and the 
<a href="http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/index.html">
Secure Programming for Linux and Unix HOWTO</a>
by David A. Wheeler
</p>

<h4>
Q: What programming languages and compilers are supported by Minix?
</h4>

<p>
The Minix operating system itself and the various utilities and
programs that are part of the Minix distribution are written in
<b>C</b>, and the distribution includes a C compiler.  In fact, Minix
also provides compilers for <b>Pascal</b> and <b>Modula2</b>; the
compilers were constructed using the <b>Amsterdam Compiler Kit</b>, 
known as <b>ACK[B</b>.  A
"front end" for each language produces intermediate code which is
compiled to assembly language by the rest of the compiler system. See the
<a href="/current/2.0.4/wwwman/man1/cc.1.html">
cc(1), pc(1), m2(1)</a>
and the 
<a href="/current/2.0.4/wwwman/man7/ACK.7.html">
ACK(7)</a>
man pages for more information.
</p>
<p>

The 
<a href="/ACKlicense.html">
ACK license</a> 
is similar to the 
<a href="/LICENSE.html">
Minix license</a>. 
For more information about ACK see the 
<a href="http://www.cs.vu.nl/ack/">
Amsterdam Compiler Kit Information Sheet</a>
which includes a link to the ftp site for download of the compiler source code.
</p>
<p>
The complete ACK is portable to many systems. If you just want to use it on 
Minix, source code for the Minix 32-bit version of ACK is available at 
<a href="http://www.laurasia.com.au/ack/">
Michael Kennet's website</a>.
</p>
<p>
There are other programming options in Minix:
</p>
<ul>
<li>


Other <b>C</b> compilers:
<ul>
<li>
<b>C386</b>
is an alternative to the ACK compiler for 32-bit Minix 
available from Dave Walker at
<!-- new URL 2004-10-02
<a href="http://www.itimpi.freeserve.co.uk/">
http://www.itimpi.freeserve.co.uk/</a>.
-->
<a href="http://homepage.ntlworld.com/itimpi/index.htm">
http://homepage.ntlworld.com/itimpi/index.htm</a>.

Source code is available, and there is also a C68 for Minix-68K version.
</li>

<li>
<b>Gcc</b>

is the standard Minix-vmd compiler.  A search of the net returns a lot
of old references to ports of gcc to pre-1.7 standard Minix versions.
As I started to write this I thought I recalled a current port of gcc
to Minix, but I can't locate it.  Gcc uses a lot of resources, and may
use the floating point registers, which are not available in standard
Minix.  Source code is available for gcc.  I think the interest in
using gcc was mostly because of the absence of an ANSI C compiler and
support for 32-bit instructions in the time of Minix 1.5 and earlier
versions.  Interest in using gcc on Minix diminished when the current
ACK ANSI-C compiler with 32-bit support was made available as part of
the standard Minix distribution.  
</li>

<li>

The <b>TenDRA C/C++ Compiler</b> has been ported to Minix by Jose Juan
Mendoza Rodriguez &lt;josejuanmr@users.sourceforge.net&gt;.  He has set up 
a SourceForge project at
<a href="http://tendra4minix.sourceforge.net">
http://tendra4minix.sourceforge.net</a>. 

More information and downloads are available there.  I have posted here
a copy of the 
<a href="/faq/TenDRA412a.htm"> 
README for TenDRA C/C++ compiler (version 4.1.2) for Minix 2.0.2</a>, 
as posted to comp.os.minix in February 2004.
</li>

</ul>
</li>
<li>
Compilers and interpreters for other languages:
<ul>
<li>
<b>BASIC</b>:
The Brandy BASIC language interpreter, version 1.0.16, has been 
ported to Minix by Harald Arnesen &lt;harald@skogtun.org&gt;. See the 
<a href="/pub/contrib/b116m.txt">
b116m.txt descriptive file</a>
or download 
<a href="/pub/contrib/b116m.tar.Z">
b116m.tar.Z</a>  
in the contributed software section.
</li>

<li>
<b>FORTRAN</b>:
A FORTRAN to C converter has been ported to Minix and is available on this 
system. See the 
<a href="/pub/contrib/f2c.txt">
f2c.txt descriptive file</a>
or download 
<a href="/pub/contrib/f2c.tar.Z">
f2c.tar.Z</a>  
in the contributed software section.
</li>

<li>
<b>Perl</b>: 
A port of Perl 5 is available on this system. See the 
<a href="/pub/contrib/perl.txt">
perl.txt descriptive file</a>
or download 
<a href="/pub/contrib/perl.tar.Z">
perl.tar.Z</a>  
in the contributed software section.
</li>

<li>
<b>Python -- new 1/2005</b>: 

Python version 1.5.2 (not the latest version, but less resource hungry
than the latest version) has been ported to Minix by Michael Kennett.
It is available on this system as either a binary or a source
distribution.  See the

<a href="/pub/contrib/py152-bin.txt">
py152-bin.txt</a>
or 
<a href="/pub/contrib/py152-src.txt">
py152-src.txt</a>
descriptive files or download 
<a href="/pub/contrib/py152-bin.taz">
py152-bin.taz</a>
or
<a href="/pub/contrib/py152-src.taz">
py152-src.taz</a>
in the contributed software section.
</li>


<li>
Does anyone remember 
<b>RATFOR</b>? 
This is the "RATional FORtran" preprocessor for FORTRAN described in the 
original 
<b><i>Software Tools</i></b>
book by Brian Kernighan and P. J. Plauger. This 1976 book is still in print. 
RATFOR has been ported to Minix and is available on this system. See the
<a href="/pub/contrib/ratfor.txt">
ratfor.txt descriptive file</a>
or download 
<a href="/pub/contrib/ratfor.tar.Z">
ratfor.tar.Z</a>
in the contributed software section. This is a pre-processor, so you need
FORTRAN, too, to use it.
</li>
</ul>
</li>
</ul>


<h4>
Q: Is there a Minix assembly language programming manual?
</h4>

<p>
A: No, not as such <b>(* but see below)</b>.  Minix assembly language
uses a syntax that is derived from the assembly language of other Unix
systems, and as such looks a little strange at first to those who are
used to Microsoft MASM and similar assemblers.  There are several
documents about Minix assembly language which may be helpful here:
</p>
<ul>
<li>
<a href="/pub/info/pc-ix-assem.txt">
Pc-ix-assem.txt</a>
is the closest thing we have to a manual. It describes 16-bit Minix assembly 
language. The 32-bit language has additional instructions, but the description
of syntax and pseudo-ops makes this a useful reference.
</li>

<li>
The page titled
<a href="/faq/pseudoops.html">
Minix assembly pseudo-ops, sections, and comments</a>
has answers from Kees Bot to questions that were asked on the comp.os.minix 
newsgroup about these aspects of Minix assembly programming.
</li>

<li>
<a href="/pub/info/pc-ack-assem.txt">
Pc-ack-assem.txt</a>:
a brief discussion by Kees Bot of the evolution of Minix's assembly language 
through different versions of Minix.
</li>

<li>
<a href="/pub/info/assm_example.txt">
Assm_example.txt</a>
is a simple assembly language "Hello World" illustrating how an assembly
program can be assembled and linked. This demo was written for Minix 1.5, 
a Minix 2.0 version would be slightly different.
</li>

<li>

<b>*Mini-manual:</b> Soon after I answered the question above, "Is
there a Minix assembly language programming manual?" in the negative, 
somebody posted a pointer to a nice document entitled
<!-- new URL for this added 2004-10-02
<a href="http://www.users.csbsju.edu/~cburch/cs/350/handouts/x86.html"> 
-->
<a href="http://ozark.hendrix.edu/~burch/csbsju/cs/350/handouts/x86.html">
<b><i>Introduction to Intel x86 Assembly Language in Minix</i></b></a>
on the comp.os.minix newsgroup. (The above link is to an html document, 
there is also a
<a href="http://www.users.csbsju.edu/~cburch/cs/portfolio/x86.pdf">
PDF version</a>
available). The author is Carl Burch of St John's University (Minnesota, USA).
This document describes the language recognized by the open-source assembler 
<a href="http://nasm.sourceforge.net/doc/html/nasmdoc0.html">
NASM</a>, 
which is very similar to the assembly language of Minix.
</li>

<li>
<a href="/faq/intelman.html"> 
<b><i>Intel and AMD Architecture and Programming Manuals</i></b></a>
are available on the web. These companies want people to program for their 
products, of course, and they provide lots of information. 
</li>

<li>
There is a 
<a href="http://my.execpc.com/~geezer/os/pm.htm">
Protected Mode Tutorial</a> 
at http://my.execpc.com/~geezer/os/pm.htm, a site maintained by Chris Giese.
The page is oriented toward programming MS-DOS applications, but it offers 
a good brief overview of how protected mode works.
</li>

<li>
Wangzhi (quakewang@mail.whut.edu.cn) provided a translation into English of a
<a href="/faq/MinixAsMn.html"> Minix Assembly Language Manual</a>, 
originally written in Chinese by Mao Yao and Yang Songhua. It includes a 
number of examples written by Wangzhi. The previous link is to an HTML 
version. He also provided a 
<a href="/faq/MinixAsMn.pdf">PDF version</a>.
</li>

<li>
Luiz Capitulino &lt;lcapitulino@terra.com.br&gt; maintains a website at  
<a href="http://brlivre.sytes.net/minix">
http://brlivre.sytes.net/minix</a>
(English and Portuguese pages available)   
with pointers to some of the above documents, and copies of other 
hardware-related documentation including specifications for the interfaces
for the uPD765 floppy disk controller, ATA disks, and VGA displays.
<b>(Note: 2 Oct 2004, link does not work)</b>.
</li>
</ul>


<h4>
Q: Do you know of any tutorials on assembly language programming?
</h4>

<p>
A: Randall Hyde's 
<a href="http://webster.cs.ucr.edu/AoA.html">
The Art of Assembly Language Programming website</a>
site offers downloads of versions of his assembly programming text in three 
flavors: for 16-bit DOS, for 32-bit Windows, and for 32-bit Linux. There's a 
lot of other interesting stuff on this site. 
</p>


<h4>
Q: Why is OS support needed for MMX or floating point math?
</h4>

<p>
A: This answer was extracted from a comment on comp.os.minix:
</p>
<pre>
From: kjb=733301@cs.vu.nl (Kees J Bot)
Subject: Re: MMX/3DNow support was RE: MINIX Development?
Date: Wed, 23 Jul 2003 20:15:03 +0200
</pre>
<p>
This is really a hardware floating point issue, because the MMX
registers share the FP registers.  This was done so that MMX unaware
OSen can still support MMX programs, because when they save and restore
the FP registers then the MMX state is also saved and restored if that
happens to be what the FP registers are used for.
</p>
<p>
This saving and restoring is what Minix doesn't do.  So if two processes
use FP/MMX then a context switch from one to the other will clobber the
FP state of both.
</p>
<p>
What is needed to make this work is a trap handler that reacts to the
use of FP, so that Minix can save the FP state of the process that
last used FP and load the FP state of the current process.  On a context
switch Minix merely sets the "don't use FP" bit in some register.
</p>
<p>
Costs?  One FP interrupt handler, some FP save/restore/setup code, some
memory per process to store the FP state into, and some memory to store
the FP state when a user process catches a signal.  (Not sure about the
signal business, much check with Philip.)  This isn't much work, we can
simply take Minix-vmd's code, but I haven't seen any need yet.  Minix
has to use software FP as distributed, or it won't run on your old 386,
so Minix itself doesn't need it.
</p>
<p>
Anyone here who wants to use Minix for some heavy number crunching?  If
so then I could be persuaded to add an ENABLE_FPU to the next release,
by default off.  I don't care about MMX, that's way too exotic for Minix.
</p>

<h4>
Q: Is there an assembly syntax inconsistency in MINIX?
</h4>

<p>
A: Assembly language files for Minix sometimes use inconsistent syntax. 
The question was discussed in
<a href="/faq/asysyn.html">
this exchange on the comp.os.minix newsgroup</a>
during May and June, 2004.
</p>
