home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 603b.lha / IXEmulLibrary_920202 / README.pp / README
Text File  |  1992-02-09  |  21KB  |  449 lines

  1. Markus M. Wild                           January 12, 1992
  2.  
  3. This  is  the  first  public release of my shared library, that should make
  4. porting  programs  originally  written to be run on a **IX/BSD system to be
  5. much easier on the Amiga computer running AmigaDOS.
  6.  
  7. ---------------------------------------------------------------------------
  8.             COPYRIGHT restrictions
  9.  
  10. The  source  code  shipped  with this library is subject to the GNU LIBRARY
  11. GENERAL PUBLIC LICENSE, please look at the file COPYING.LIB that comes with
  12. this distribution.  If not, write to the
  13.   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14.  
  15. NOTE:   
  16. There  are  lots  of  files  subject to  other Copyrights, especially those
  17. Copyright  by the Regents of the University of California.  In those cases,
  18. the  specified  Copyright restriction applies TO EACH SUCH SINGLE FILE, but
  19. not the arrangement of putting it in this library.  With this restriction I
  20. want to enforce consistency of this library.
  21.  
  22. After reading the COPYING.LIB file, you'll notice, that a program that just
  23. uses the library by using OpenLibrary(), and calling functions in it, is to
  24. be  considered  as  a  `work that uses the Library', and 5.  of COPYING.LIB
  25. says  for this case:  " Such a work, in isolation, is not a derivative work
  26. of the Library, and therefore falls outside the scope of this License."
  27.  
  28. Since  I  declare  the  glue  functions  created  by  compiling and running
  29. gen_glue.c  (in lib/) to be in the Public Domain (thus not to be covered by
  30. any  license),  and  since  the  stdio/  functions  are  all subject to the
  31. Berkeley  Copyright  restrictions, your compiled and linked executable will
  32. NOT  become  a  derivative  of the library, and will thus not be subject to
  33. this license.  Thus, you may use the compiled version of the glue files and
  34. the  stdio  functions,  libc.a  (except  alloca.c, please see the copyright
  35. notice  in  its header.  Use the builtin alloca() (__builtin_alloca() to be
  36. explicit)  in  all  situations  where  this  is  possible)  and crt0.o in a
  37. commercial  product  without making it a derivative of the library and thus
  38. make  it  subject  to  the  library  license.   However, you must tell your
  39. customers  that  ixemul.library is free software according to this license,
  40. and where they can get a copy of its source code.
  41.  
  42. ---------------------------------------------------------------------------
  43.  
  44. Now that the legal stuff is over, some comments to this library.
  45.  
  46.  
  47. 68000 users, take care!
  48. =======================
  49. I tried to be fully 68000 compatible (this is important in the signal code),
  50. but since I don't have a 68000 equipped Amiga anymore, I can't test whether
  51. the library really works under this environents. Please tell me, if you
  52. encounter problems!
  53.  
  54.  
  55. I always wanted a library, that would emulate as much as possible of a
  56. **IX/BSD environment on the Amiga, so that programs (usually programming
  57. tools) written for **IX/BSD could be ported quick and easy to the Amiga.
  58. I guess the library accomplishes this goal fairly well.
  59.  
  60. What it is and what it isn't
  61. ============================
  62. The design of the library was therefore guided towards **IX/BSD
  63. compatibility, and *not* :
  64.  o to be too conservative with resources 
  65.    (the malloc package is quite memory hungry...)
  66.  o to be particularly conformant to Amiga habits. Thus if I had to decide
  67.    whether I should make a function act more like an Amiga function or
  68.    more like a **IX/BSD one, I decided for the latter. As an example:
  69.    _cli_parse() does wildcard expansion, and tries to apply more or less
  70.    **IX/BSD shell semantics to an argument line, it doesn't call
  71.    ReadArgs().
  72.    The types used in my own source code are all from sys/types.h (except
  73.    BPTR). I don't think capitalized identifiers should be used for typedef'd
  74.    types. According to C-conventions, anything written in captials should
  75.    be `#undef'inable, which typedefs aren't. Thus if you write contributions
  76.    to be included into the official distribution of this library, code
  77.    according to this. Use `u_char' and not UBYTE, etc. I don't care that
  78.    this is against the Commodore coding standard, this is my code, and
  79.    I decide what I like and what not.
  80.  o to be particularly suited for inclusion into a shared library. Although
  81.    all of the system stuff IS included into the shared library, I didn't
  82.    bother to include the (current) stdio library. This simply because
  83.    transforming stdio into a form usable in a shared library would have
  84.    meant adding a significant portion of incompatibility to **IX/BSD
  85.    usage of stdio functions/macros. I'll perhaps reconsider this with the
  86.    new stdio library distributed in the 4.3BSD-net2 release later.
  87.    What I'd really want for the Amiga is the concept of a dynamic linker.
  88.  
  89. On the other hand, it should be:
  90.  o expandable. As an example, a file descriptor already can refer to `real'
  91.    files, directories, memory buffers treated as files. I plan to add 
  92.    sockets in some next release (Commodore: please get out some examples 
  93.    on how to use SANA-II stuff, so my sockets can be compatible!)
  94.  o patchable. If you want some function to behave differently, you can
  95.    SetFunction() it, and the rest of the library should use your new entry.
  96.    NOTE: I used this only for major functions, that may reasonably change. 
  97.      I didn't call functions like strcmp(), strlen(), bcopy() that way for
  98.          efficiency reasons (and my lazyness to change the whole string/
  99.          and other libraries;-)))
  100.  
  101.  
  102.  
  103. Difference to `usual' Amiga shared libraries
  104. ============================================
  105. The library is designed to be used by C, and not by assembly.  So
  106. parameters are passed on the stack rather than in registers.  This also
  107. means that there is no `fd' file, and you can't use any current library
  108. call pragmas to access its functions.  I will though soon publish an inline
  109. header file for use with GCC, so you'll be able to call all functions
  110. inline.  Recall though, that calling functions of ixemul.library inline
  111. will not result in an order of improvement as calling standard library
  112. functions inline.  The glue functions don't have to shuffle arguments from
  113. and to the stack, they just do a jump over the base table and are therefore
  114. very short and very fast.
  115.  
  116. I provided revision control in the startup code. Thus if you get a program
  117. written for a newer revision of the library than you currently have, a 
  118. warning requester tells you about this, you can still use the program though.
  119. I don't believe in bumping up the version counter because of every small 
  120. improvement. Bumping up the version means you can't use no older versions at
  121. all. Bumping up the revision just gives you an annoying requester (and
  122. perhaps an `illegal action' trap though..) that you should upgrade.
  123.  
  124. As some kind of replacement for an fd file, I use the <sys/syscall.def> file,
  125. which is a symbolic link to `library/syscall.def' in the source directory.
  126. It contains lines of the form
  127.   SYSTEM_CALL (name_of_call, entry_number)
  128. Where `name_of_call' is the name you'd use in a C program using the library
  129. (for example write, abort, unlink, etc), and `entry_number' gives the number
  130. of the system call used in syscall(). You can convert this number into
  131. a more common _LVO for the Amiga by doing:
  132.   _LVO = -6*(entry_number + 4)
  133.  
  134. For examples how <sys/syscall.def> can be used, look at <sys/syscall.h>,
  135. `library/start.s' and `lib/gen_glue.c'.
  136.  
  137.  
  138.  
  139. Where to use it
  140. ===============
  141. Libc.a should be the one and only C library you need to get most of your
  142. programs linked correctly with the GNU CC compiler.  For some math-
  143. oriented stuff you'll also need a math library.  Since Berkeley released a
  144. new release of their software, I don't want to include my older math
  145. library until I upgraded to the newer sources.  You may get the newer or
  146. older versions now, they are not particularly **IX/BSD dependant, and
  147. should compile fine with GCC.
  148.  
  149.  
  150.  
  151. If you want to recompile
  152. ========================
  153. I provided Makefiles for the most directories (all except lib/ in fact).
  154. Those Makefiles assume a decent Make tool, I'm currently using a version
  155. (hacked for the Amiga) of DMake (not the one from Matt Dillon, sources are
  156. on wuarchive.wustl.edu), I'll publish this version separatly, but I won't
  157. support it.
  158.  
  159. Sources are written for compilation by GCC. You might be able to compile
  160. 95% of them with any ordinary ANSI-C compiler, but there are cases where
  161. you have to change things for non-GCC environments (mostly asm() situations).
  162.  
  163. The Makefiles all use gcc2 as CC.  Release date of gcc2.0 depends on GNU,
  164. not on myself.  I can just say that Amiga versions keep up with releases
  165. from GNU, and there should be an Amiga gcc2 release ready as soon as GNU
  166. give their ok for distribution.
  167.  
  168. The subdirectories use `ar' and `ranlib', these are the tools from the
  169. 4.3BSD-net2 distribution.  I found them to be lots more stable then my
  170. earlier ports of GNU-ar from the GNU-binutils distribution.  For now, only
  171. the binaries are included, but you may get the sources at every site that
  172. has 4.3BSD-net2 sources, for example nic.funet.fi.
  173.  
  174. For recompilation, see also the following comments in `How complete are the
  175. headers'.
  176.  
  177. To generate libc.a, `ar' and `ranlib' all object files from
  178. static_library/, stdio/, lib/ and lib/glue/.  The latter you have to
  179. generate by compiling and running lib/gen_glue.c.  Don't include lib/crt0.o
  180. in libc.a though, this should stay separate.  Since there is no Makefile
  181. (yet), crt0.c (and only this) should be compiled with `-fwritable-strings',
  182. since you have to be sure that ENTRY() is the first thing in the generated
  183. object file.  If you don't specify `-fwritable-strings', you'll get string
  184. constants at the first executable address in your programs, and this will
  185. get you (and your computer) into meditation if you try to execute such
  186. programs ;-))
  187.  
  188. To generate ixemul.library, cd into string/,gen_library/, stdlib/, gnulib/,
  189. gnulib20 and at last library/, and type `make'. At the end, you should
  190. get a current version of ixemul.library.
  191.  
  192. Note: the library is currently compiled in a way that makes it easy for me
  193. to have a debugged version or not, ie. the debugging statements stay in
  194. the code, but the kprintf() function is either linked with the library
  195. to get a debugging version, or stubbed out to get a working version. When the
  196. library gets more stable, parts of it can be compiled by inlining code
  197. to the library, instead of going thru syscall().
  198.  
  199.  
  200.  
  201.  
  202. If you want to write code that uses the library
  203. ===============================================
  204. Code if you would on a **IX/BSD system, thus DON'T USE any information
  205. private to the library, especially don't use any information that
  206. tc_TrapData points to.  This data is subject to change in every release of
  207. the library, and you may only access its variables thru library access
  208. functions!  This restriction fully applies to applications as well that
  209. SetFunction() some functions of the library.  So if you for example write
  210. your own memory allocation functions, you may NOT use the space the library
  211. malloc() function uses for your own purpose.  I may decide in a later
  212. release of the library to use a different malloc() implementation that
  213. uses different data in the user area, and then your code almost certainly
  214. would trash innocent variables!
  215.  
  216.  
  217.  
  218. How complete are the headers
  219. ============================
  220. The header files distributed in `include/' are all you need - except the 
  221. Amiga specific header files copyright by Commodore-Amiga. You either have
  222. to get them from a commercial compiler, or order them from CATS.
  223. If you don't intend to compile Amiga specific programs, you don't need
  224. those headers at all.
  225.  
  226. You need to make one change to one of those Amiga headers to avoid
  227. duplicate definition of a datatype:
  228.  
  229. The <devices/timer.h> file includes the following definition:
  230.     struct    timeval    {
  231.         ULONG tv_secs;
  232.         ULONG tv_micro;
  233.     };
  234. Please comment this definition out, and add 
  235.     #include <sys/time.h>
  236. somewhere at the beginning of the file, and instead of the above definition,
  237. put
  238.     #define tv_secs  tv_sec
  239.     #define tv_micro tv_usec
  240. That way, you can use the timeval structure defined in <sys/time.h> as well
  241. as the one defined in <devices/timer.h>. The structures are identical, but
  242. the field names are not (sigh..).
  243.  
  244.  
  245. I included more or less all headers from 4.3BSD-net2, except those that 
  246. refer to really **IX/BSD specific material in the kernel. I included more
  247. headers that are currently used and supported, just to make life easier for
  248. people using **IX/BSD sources under AmigaDOS. Among the things not supported
  249. currently are networking (sockets) and process management (fork, wait, exec*).
  250. Signals on the other hand *are* implemented, see the special section for
  251. restrictions.
  252.  
  253.  
  254.  
  255. How BSD signals are implemented
  256. ===============================
  257. I tried to implement as much of Berkeley style signals as possible on the
  258. Amiga. This includes a trap handler as well as an asynchronous signal 
  259. facility. The one thing not implemented is interruptible signal calls.
  260. Since there are no `real' system calls on the Amiga (ie. no calls that are
  261. executed in Supervisor mode), those calls can not normally be interrupted,
  262. ie. forced to return to their caller. So all functions except sigpause()/
  263. sigsuspend() will return to where they were interrupted, if a signal 
  264. occurs.
  265.  
  266. These 32 new signals are 32 new signals, not tied to any of the 32 Amiga
  267. signals provided by Exec. The one exception is SIGBREAKB_CTRL_C, which is
  268. by default bound to generate a SIGINT.
  269.  
  270. Signal handlers are called with the following arguments:
  271.   void 
  272.   signal_handler (int signo, int code, void *address, struct sigcontext *sc)
  273.  
  274. Where
  275.   signo:  is the signal number that occured, see <signal.h>
  276.   code:   is a more specific characterization of signo available with some
  277.       signals. It is available with all signals that are generated
  278.       because of a processor exception, and then contains the format
  279.       identifier of the exception frame (this is correct even for the
  280.       68000, where such an identifier is faked, ie. it doesn't really
  281.       exist). Thus a `division by zero' exception would be invoked by
  282.         signal_handler (SIGFPE, 0x2014, address, sc)
  283.   address:address referrs to the instruction that caused the signal.
  284.   sc:     please don't use sc, as it may change in the future. It contains
  285.       the context to restore after the signal handler returns.
  286.  
  287. If you use signals in your own code, PLEASE make sure that you never
  288. generate a situation, that when interrupted, would leave resources allocated.
  289. That is, the following example is BAD :
  290.  
  291.     ..
  292.     fh = Open ("foobar", MODE_OLDFILE);
  293.     if (fh)
  294.       {
  295.         .. do something with it ..
  296.         Close (fh);
  297.       }
  298.  
  299. If your program is interrupted and terminated after you got your file handle,
  300. `fh' will never be closed! There are two sollution to get around this problem,
  301. either use library functions from ixemul.library, or explicitly mask signals
  302. while you have resources locked. Thus in this example, either do:
  303.     fd = open ("foobar", O_RDWR);
  304.     if (fd >= 0)
  305.       {
  306.         .. do something with it ..
  307.         close (fd);
  308.       }
  309.  
  310. in that case the library will do resource tracking on fd. Or explicitly mask
  311. the signals:
  312.     omask = sigsetmask (~0);    /* mask all signals */
  313.     fh = Open ("foobar", MODE_OLDFILE);
  314.     if (fh)
  315.       {
  316.         .. do something with it ..
  317.         Close (fh);
  318.       }
  319.     sigsetmask (omask);
  320.  
  321. Note that the last sollution is worse than the first one, because the user
  322. may send the process a non-maskable signal, that would terminate the process
  323. unconditionally (SIGKILL does this), and don't forget that the user isn't
  324. able to break your program as long as you have signals masked!
  325.  
  326. Ixemul.library does resource tracking on all file-related functions (create(),
  327. open(), dup(), pipe()) and on memory allocations thru malloc() and realloc().
  328. Thus if you use those functions instead of dos.library and exec.library 
  329. functions, you don't need any clever resource tracking stuff to do on your
  330. own, that's what the library is for ;-)
  331.  
  332. If you use Amiga specific resources like Windows and Screens from
  333. Intuition, make sure to add an atexit() handler to close those resources,
  334. if the user should decide to interrupt your program.  Before the program is
  335. left, the chain of registered atexit-handlers is called in exit().  So
  336. PLEASE NEVER EVER call _exit() if you have registered any custom atexit()
  337. handlers.  It is a bad habbit anyway, but normally you may call _exit()
  338. without resource lossage (stdio won't flush its buffers, but that's about
  339. all), as long as you close ixemul.library after use, and this IS A MUST, as
  340. for every Amiga shared library anyway.
  341.  
  342. I provided a new unique Amiga specific signal called SIGMSG. If you set up
  343. a handler for this signal, than
  344.  o  the default mapping from SIGBREAKB_CTRL_C into SIGINT will no longer
  345.     occur
  346.  o  your handler is called with the following arguments
  347.       signal_handler (SIGMSG, new_exec_signal_mask)
  348.  
  349. In this case, you have to deal with Exec signals yourself, so don't forget
  350. to clear those signals that you want to receive notification about again
  351. later. 
  352. Thus if you'd want to handle SIGBREAKB_CTRL_C yourself, don't forget to
  353.   SetSignal (0, SIGBREAKF_CTRL_C)
  354. at the end of the handler, or you'll never get notification about that
  355. signal again.
  356.  
  357.  
  358. If your program is interrupted by a signal and the default action of that
  359. signal is to terminate your program, and you didn't set up a handler to deal
  360. with that signal, your program is terminated by calling `exit (128 + signo)'.
  361. There are no core-dumps yet, I first have to think about a useful format
  362. for a debugger that takes care of the Amiga's memory architecture.
  363.  
  364.  
  365. The signal implementation uses some of the Berkeley kernel sources of the
  366. 4.3BSD-reno release for the hp300. I didn't disable everything that isn't
  367. implemented currently, so you might face strange behavior if you currently
  368. try to send a SIGSTOP to a process using the library, you better not ;-))
  369.  
  370. Currently supported are the following signals:
  371.   SIGINT:    bound to ^C (SIGBREAKB_CTRL_C) unless there is a SIGMSG handler
  372.   SIGILL:    generated by some hardware exceptions
  373.   SIGFPE:    generated by some hardware exceptions
  374.   SIGBUS:    generated by some hardware exceptions
  375.   SIGALRM:   if you use alarm() or the ITIMER_REAL interval timer
  376.   SIGVTALRM: if you use the ITIMER_VIRTUAL interval timer
  377.   SIGPROF:   if you use the ITIMER_PROF interval timer
  378.   SIGMSG:    if you provide a signal handler for it
  379.  
  380. more are to follow.  You may send any of the 32 signals to a process using
  381. the library with the `kill ()' function, the default behavior of a process
  382. is described in a **IX/BSD man page for signals.  As mentioned above,
  383. stopping a process isn't currently implemented, and may produce strange
  384. behavior...
  385.  
  386.  
  387.  
  388. Compatibility
  389. =============
  390. I tried to port some commonly used programs to the Amiga using this
  391. library. And the following programs were quite easy to port:
  392.  o patch
  393.  o GNU tar-1.10  (the first Amiga tar that knows about symlinks ;-))
  394.  o GNU emacs 18.57 (currently without subprocesses of course ;-))
  395.  o GNU find-2.2 (replace the fork,exec-stuff with a call to ssystem() )
  396.  o BSD ar, ranlib (with DMake even things like VPATH=../ar work ;-))
  397.  o GNU cc ;-))
  398.  o DMake 
  399.  o ...
  400. As a guideline, if you find stuff that uses fork,exec,wait stuff, try to
  401. replace it with a call to ssystem()/system().  System() corresponds to the
  402. usual **IX/BSD library function, it runs the argument thru the current
  403. shell.  ssystem() is some lower level execution function, that under 1.3
  404. uses ARPs SyncRun() function (that's where the name came from ;-)), and
  405. under 2.0 uses my own code to find the executable (searches the users
  406. PATH), and tries to do interpreter expansion on the file (the thing with #!
  407. rsp.  ;!  as the first two characters.  Please see the `library/__load_seg.c'
  408. file for more details;-)).
  409.  
  410.  
  411. Some final words
  412. ================
  413. I wish you good luck using this library, it isn't that thoroughly tested
  414. yet, but I did manage to recompile gcc with itself using the library, so
  415. some basic reliability should be granted. But keep in mind:
  416.  
  417.     This library is distributed in the hope that it will be useful,
  418.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  419.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  420.     Library General Public License for more details.
  421.  
  422. See the BUGS file for any currently known bugs.
  423.  
  424. New versions of the library will first be released on amiga.physik.unizh.ch
  425. in files/incoming/amiga/. This is my home site. Later there will also be
  426. copies on nic.funet.fi, which is the home site of the GCC port to the Amiga.
  427.  
  428. If you like to contribute new functions to the library, please reread
  429. the `What it is and what it isn't' section, and if you think that your
  430. code contributes to those goals, I'd be very happy to include it in
  431. the library in a later release. 
  432. Since indentation style is a great deal a thing of personal taste, 
  433. I make up the following rules:
  434.  o if you change one of the existing files, follow the style of the
  435.    file
  436.  o if you provide a completely new set of functions, you're at your own.
  437.  
  438. If you find bugs in the code (I'm absolutely sure there are some...), please
  439. tell me about them!
  440.  
  441. Send your bug reports, enhancement requests and constructive remarks to
  442.  
  443.    <wild@nessie.cs.id.ethz.ch>   or   <wild@amiga.physik.unizh.ch>
  444.  
  445. send flames to <bitbucket@nessie.cs.id.ethz.ch> ....
  446.  
  447.  
  448. Markus M. Wild
  449.