Programming in MINIX 3
This document covers some of the technical issues about using MINIX 3 and writing
code for it.
How can I learn to program in C?
The first edition of Andy Tanenbaum's Operating Systems Design
and Implementation included an Introduction to C. Alas, with a much bigger Minix 2.0 there was no room for this in the OSDI 2nd ed. It's also a bit out of date, as
it describes the original version of C (often referred to as "K&R C")
defined in the 1978 first edition of The C Programming
Language 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
OSDI 2nd ed. text, a copy of The C Programming
Language, 2nd ed. is the most useful book you can own to
understand or program in Minix.
In addition to C, what else do I need to know to program in the Minix environment?
A classic book is Brian Kernighan and Rob Pike's Unix
Programming Environment, 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 The
Practice of Programming (1999) is also of interest, although
probably not as useful to a beginning programmer. W. Richard Stevens'
Advanced Programming in the UNIX(R) Environment 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.
How about shell script programming?
The Minix shell, ash, is similar to bash, the standard
shell in most Linux distributions. A series of articles on
Bash by example
is well worth a look, although not everything is applicable to Minix.
If you are willing to buy a big book the Unix Power Tools
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
Unix Power Tools 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.
I hear a lot about security problems, any hints on secure programming?
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.
A useful reference is the Secure UNIX Programming FAQ maintained by Thamer Al-Herbish, and Secure Programming for Linux and Unix HOWTO by David A. Wheeler.
What programming languages and compilers are supported by Minix?
The Minix operating system itself and the various utilities and
programs that are part of the Minix distribution are written in
C, and the distribution includes a C compiler. In fact, Minix
also provides compilers for Pascal and Modula2; the
compilers were constructed using the Amsterdam Compiler Kit,
known as ACK. A "front end" for each language produces intermediate code which is
compiled to assembly language by the rest of the compiler system.
See the cc(1), pc(1), m2(1)
and the ACK(7) man pages for more information.
The
ACK license is similar to the
Minix license.
For more information about ACK see the
Amsterdam Compiler Kit Information Sheet which includes a link to the ftp site for download of the compiler source code.
There are other programming options in Minix:
[list][*]Other C compilers:[list][*]C386 is an alternative to the ACK compiler for 32-bit Minix available from Dave Walker here[*]Gccis the standard Minix-vmd compiler. A search of the net returns a lotof 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 gccto Minix, but I can't locate it. Gcc uses a lot of resources, and mayuse the floating point registers, which are not available in standardMinix. Source code is available for gcc. I think the interest in usinggcc was mostly because of the absence of an ANSI C compiler and supportfor 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-Ccompiler with 32-bit support was made available as part of the standardMinix distribution[/list][list][*]The TenDRA C/C++ Compiler has been ported to Minix by Jose Juan Mendoza Rodriguez <[email=josejuanmr@users.sourceforge.net]josejuanmr@users.sourceforge.net[/email]>. He has set up a SourceForge project here.[/list][/list]More information and downloads are available there. I have posted here a copy of the
README for TenDRA C/C++ compiler (version 4.1.2) for Minix 2.0.2. as posted to comp.os.minix in February 2004.
[list][*]Compilers and interpreters for other languages:[list][*]BASIC: The Brandy BASIC language interpreter, version 1.0.16, has been ported to Minix by Harald Arnesen <[email=harald@skogtun.org]harald@skogtun.org[/email]>. See the descriptive file or download b116m.tar.Z in the contributed software section.[*]FORTRAN: A FORTRAN to C converter has been ported to Minix and is available on this system. See the descriptive file or download f2c.tar.Z in the contributed software section.[/list][list][*]Perl: A port of Perl 5 is available on this system. See the descriptive file or download perl.tar.Z in the contributed software section.[*]Python -- new 1/2005:Python version 1.5.2 (not the latest version, but less resource hungrythan the latest version) has been ported to Minix by Michael Kennett.It is available on this system as either a binary or a sourcedistribution. See the py152-bin.txt or py152-src.txt descriptive files or download py152-bin.taz or py152-src.taz in the contributed software section.[*]Does anyone remember RATFOR? This is the "RATional FORtran" preprocessor for FORTRAN described in the original Software Toolsbook by Brian Kernighan and P. J. Plauger. This 1976 book is still inprint. RATFOR has been ported to Minix and is available on this system.See the ratfor.txt descriptive file or download ratfor.tar.Z in the contributed software section. This is a pre-processor, so you need FORTRAN, too, to use it.[/list][/list]
Is there a Minix assembly language programming manual?
No, not as such (* but see below). 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:
[list][*]Pc-ix-assem.txtis the closest thing we have to a manual. It describes 16-bit Minixassembly language. The 32-bit language has additional instructions, butthe description of syntax and pseudo-ops makes this a useful reference.[*]The page titled Minix assembly pseudo-ops, sections, and commentshas answers from Kees Bot to questions that were asked on thecomp.os.minix newsgroup about these aspects of Minix assemblyprogramming.[*]Pc-ack-assem.txt a brief discussion by Kees Bot of the evolution of Minix's assembly language through different versions of Minix.[*]Assm_example.txtis a simple assembly language "Hello World" illustrating how anassembly program can be assembled and linked. This demo was written forMinix 1.5, a Minix 2.0 version would be slightly different.[*]Mini-manual:Soon after I answered the question above, "Is there a Minix assemblylanguage programming manual?" in the negative, somebody posted apointer to a nice document entitled Introduction to Intel x86 Assembly Language in Minix on the comp.os.minix newsgroup. (The above link is to an html document, there is also a PDF versionavailable). The author is Carl Burch of St John's University(Minnesota, USA). This document describes the language recognized bythe open-source assembler NASM, which is very similar to the assembly language of Minix.[*]Intel and AMD Architecture and Programming Manualsare available on the web. These companies want people to program fortheir products, of course, and they provide lots of information.[*]There is a Protected Mode Tutorial here,a site maintained by Chris Giese. The page is oriented towardprogramming MS-DOS applications, but it offers a good brief overview ofhow protected mode works.[*]Wangzhi ([email=quakewang@mail.whut.edu.cn]quakewang@mail.whut.edu.cn[/email]) provided a translation into English of a Minix Assembly Language Manual,originally written in Chinese by Mao Yao and Yang Songhua. It includesa number of examples written by Wangzhi. The previous link is to anHTML version. He also provided a PDF version.[/list]
Do you know of any tutorials on assembly language programming?
Randall Hyde's [[http://webster.cs.ucr.edu/AoA.html | The Art of Assembly Language Programming website]}
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.
Why is OS support needed for MMX or floating point math?
This answer was extracted from a comment on comp.os.minix:
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
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.
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.
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.
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.
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.
Is there an assembly syntax inconsistency in MINIX?
A: Assembly language files for Minix sometimes use inconsistent syntax.
The question was discussed in this exchange on the comp.os.minix newsgroup
during May and June, 2004.
774964107 于 2009-08-08 21:13:22发表:
我来踩踩{:2_97:}