User Tools

Site Tools


developersguide:programmingminix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
developersguide:programmingminix [2014/11/17 07:25]
127.0.0.1 external edit
developersguide:programmingminix [2015/07/18 16:25] (current)
jeanbaptisteboric update programming languages section
Line 1: Line 1:
 +====== 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&​amp;​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 do
 +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 
 +[[http://​www.ibm.com/​developerworks/​library/​l-bash/​ | 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.
 +=====  How about those strange Makefile? ​ =====
 +
 +Since 3.1.7, MINIX3 switched to use the *BSD make system;
 +besides making the import of *BSD utilities and libraries easier,
 +it is also the same system as used under the hood in [[.:​testingpkgsrc|pkgsrc]].
 +
 +An advantage of this system are the individual Makefiles, which syntax is much simpler,
 +since all the complexity is moved into a centralized set of *.mk files
 +stored in ''/​usr/​share/​mk/''​. A typical Makefile looks like
 +<​code>​
 +# $OpenBSD: Makefile,v 1.3 2007/05/29 18:24:56 ray Exp $
 +
 +PROG= diff
 +SRCS= diff.c diffdir.c diffreg.c xmalloc.c
 +
 +.include <​bsd.prog.mk>​
 +</​code>​
 +
 +For an introduction to BSD make system, including advanced features,
 +you can read the "​tutorial"​ written by the author, Adam de Boor, for the 4.4BSD system here [[http://​ftp.freebsd.org/​pub/​FreeBSD/​doc/​en/​books/​pmake/​]].
 +
 +=====  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 [[http://​www.dwheeler.com/​secure-programs/​Secure-Programs-HOWTO/​index.html | 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.
 +
 +Here is a non-exhaustive list of languages and compilers available :
 +  * **C** : **clang** is the default
 +  * **Fortran** : **f2c** from pkgsrc
 +  * **Lua** : inherited from NetBSD
 +  * **Perl** : **perl** from pkgsrc
 +  * **Python** : **python27** from pkgsrc
 +  * **Shell** : Bourne Shell is the default
 +
 +=====  Why is OS support needed for MMX or floating point math?  =====
 +This answer was extracted from a comment on comp.os.minix:​
 +<​code>​
 +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
 +OSes 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.
 +</​code>​
 +
 +=====  Is there an assembly syntax inconsistency in MINIX? ​ =====
 +A: Assembly language files for Minix sometimes use inconsistent syntax. ​
 +The question was discussed in [[http://​minix1.woodhull.com/​faq/​asysyn.html | this exchange on the comp.os.minix newsgroup]]
 +during May and June, 2004.
  
developersguide/programmingminix.txt · Last modified: 2015/07/18 16:25 by jeanbaptisteboric