home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / modula_3 / contrib / m3pc / m3 / readme next >
Encoding:
Text File  |  1992-12-10  |  12.2 KB  |  279 lines

  1.  
  2. Klagenfurt, Mon Dec  7 16:35:13 MET 1992
  3.  
  4. Hi,
  5.  
  6. This file gives a brief description of this (possibly the first) Modula-3 
  7. (M3) port to the i386 architecture with MS-DOS. I have used DEC-SRC M3 
  8. version 2.09 for the DECstation (DS3100). M3 is available via anonymous 
  9. ftp from gatekeeper.dec.com:pub/DEC/Modula-3. Sorry for my bad English 
  10. but it's not my native language. 
  11.  
  12. My goal was to bring a bootstrapable M3 version to the PC. PC-M3 has several 
  13. restrictions due to the limitations of MS-DOS and the lack of time to 
  14. make things perfect (i.e. Threads do not work and there is no m3make 
  15. available on PCs, floating point is not correct). The compiler is slow but 
  16. it works.
  17.  
  18. To run PC-M3 you need:
  19.     - a i386 (or upward)
  20.     - MS-DOS 5.0 (it should also work with MS-DOS 3.2)
  21.     - at least 2 MB RAM (I recommend 4 to 8 MB)
  22.     
  23. M3 V 2.09 produces C code. Therfore a C compiler is needed. The PC C 
  24. compilers (i.e. MS-C, Turbo-C) are written for the so called "real mode" 
  25. of the 80x86 processors. This mode has several limitations. I have therfore 
  26. used the GNU C compiler (gcc). To run gcc it is necessary to have DJ 
  27. Delorie's DOS Extender (go32 - it is available together with gcc via 
  28. anonymous ftp from barnacle.erc.clarkson.edu:pub/msdos/djgpp, login 
  29. name: ftp). Thanks DJ for doing the gcc port to MS-DOS! With go32 it is 
  30. possible to use the "protected mode" features of the i386 processor. 
  31. For further information about go32 and gcc read the README files in 
  32. \djgpp\docs.
  33.  
  34. A "minimal" version of go32 and gcc comes with PC-M3 so that it is possible
  35. to compile and link M3 programs. I have not included anything because it
  36. would blow up the size of the whole package. If you are interested
  37. in the rest please ftp it from the above mentioned host. 
  38.  
  39.  
  40. The main parts of PC-M3:
  41. ------------------------
  42. 1) The driver (m3)
  43. The driver is a program that invokes the M3 compiler (see below), the
  44. C compiler (gcc in our case), does "M3 linking" and builds the final
  45. program. 
  46.  
  47. 2) The compiler (m3compiler)
  48. This program is invoked with "system()" from m3 and translates a M3 program
  49. to C code.
  50.  
  51. 3) The library (libm3.a, libm3.ax)
  52. This is the SRC M3 library. It contains a lot of library functions and the
  53. M3 runtime system. 
  54.  
  55.  
  56. PC-M3 Directories:
  57. ------------------
  58. I have tried to preserve the SRC directory structure.
  59.  
  60. \djgpp                  directory for go32 and gcc (contains subdirs)
  61. \m3                     the M3 main directory
  62. \m3\include\m3          the M3 interfaces
  63. \m3\bin                 the M3 executeables (m3, m3compiler)
  64. \m3\lib\m3              the M3 library, header files, ...
  65. \m3\driver              the M3 driver sources (contains subdirs)
  66. \m3\compiler            the M3 compiler sources (contains subdirs)
  67. \m3\libm3               the M3 library sources (contains subdirs)
  68. \m3\doc                 documentation, copyright info, FAQ, ... 
  69. \m3\test                some tests, misc\sn.m3
  70.  
  71.  
  72. Using PC-M3:
  73. ------------
  74. Before you can use M3 you have to call \djgpp\setenv to setup your
  75. environment. Note: setenv.bat changes your PATH environment variable.
  76. setenv.bat makes just the changes required for go32 and gcc - you
  77. possibly want to include \m3\bin into your PATH. 
  78. To compile a M3 program (say "Hello.m3") type:
  79.  
  80. \m3\bin\m3 -w1 -make -why -o Hello Hello.m3
  81.  
  82. To execute "Hello" type: go32 Hello
  83. If you want a "Hello.exe" type: aout2exe Hello
  84.  
  85. For building a program with more than one module I would advise to
  86. use m3 with the -F option. See \m3\driver\DOS386\m3make.bat for an
  87. example.
  88.  
  89. Do not use names for Interfaces/Modules with more than 8 characters 
  90. (otherwise you have to use name maps - see below).
  91.  
  92. Note: In the library just the things used by the compiler and driver
  93. are guaranteed to work. I expect that many things in the library will
  94. not work on the PC. I have not tested this - just worked with the
  95. driver and compiler.
  96.  
  97.  
  98. Translating the driver, compiler or building the library:
  99. ---------------------------------------------------------
  100. PC-M3 comes with executeables for m3, m3compiler and with the build library.
  101. If you change something you want to recompile things. Make sure that you 
  102. have copies of the things you change in case something does not work.
  103.  
  104. To recompile the driver go to \m3\driver\DOS386 and call m3make.bat.
  105. This batch file will build a new driver. To install the driver type 
  106. "aout2exe m3" and "copy m3.exe \m3\bin". 
  107.  
  108. To recompile the compiler go to \m3\compiler\DOS386 and call m3make.bat.
  109. This batch file will build a new compiler. To install the compiler type
  110. "aout2exe m3compil" and "copy m3compil.exe \m3\bin".
  111.  
  112. Note: It is necessary to have the library to rebuild driver and compiler.
  113.  
  114. To build a new libm3.a go to \m3\libm3\DOS386 and call m3make.bat.
  115. This batch file will build a new libm3.a and libm3.ax. Copy libm3.a and
  116. libm3.ax to \m3\lib\m3. There is a file runtime.c. Compile this file
  117. with "gcc -c runtime.c". Include this file into the library with "ar -r
  118. libm3.a runtime.o" Do not forget to call "ranlib libm3.a". You have now
  119. a new library. 
  120.  
  121. The file runtime.c is a copy of /m3/libm3/Csupport/src/generic/M3Runtime2.c.
  122. This file should be included automatically during the build of the library.
  123. But this currently does not work - I guess it is a problem within m3 in
  124. connection with the name maps - I had not the time to correct this - Sorry. 
  125. Therefore it is necessary to insert this file by hand into the library.
  126.  
  127. Note: All this m3make batch files use a file PGMS with the path and filenames
  128. of the sources. You should change PGMS if you want to add or remove a file.
  129. I would recommend to start a full recompilation of the compiler or the 
  130. library over night, because it needs some time. 
  131.  
  132. If you change something in a interface do not forget to update it in 
  133. \m3\include\m3 also. Possibly you have to update a NAMES.MAP. 
  134.  
  135.  
  136. Brief Description of Problems and Changes:
  137. ------------------------------------------
  138. You can skip this section if you are not interested in changing things in 
  139. PC-M3. I have build a M3 cross compiler on a DECstation. I have installed 
  140. go32 and gcc on a PC (my system was a 486 with 16 MB memory). I have build 
  141. (several times) a boot-DOS386 (DOS386 is the name of the new target 
  142. architecture) for the driver and the compiler on the DECstation. I transfered 
  143. the C sources to the PC and compiled with gcc.
  144.  
  145. - jump buffer
  146.  
  147. M3 uses setjmp/longjmp. It is necessary to change the jmp_buf.
  148.  
  149. - problems during linking
  150.  
  151. I had problems with the following unresolved references during the first link
  152. phase:
  153.  
  154. _setjmp, _longjmp, scalb, logb, copysign, finite, isnan, sqrt, fp_class_d, 
  155. getpwuid, getpwnam, swapRM, get_fpc_csr, set_fpc_csr, sigvec, pipe, 
  156. setitimer, execvp, mprotect, select, fcntl
  157.  
  158. I have solved this problems in a way that it is possible to run the compiler
  159. (all of this functions not needed by the driver or compiler cause a runtime
  160. error). sigvec and fcntl simply return 0. Because there are no signals on a
  161. PC the M3 Threads do not work. 
  162.  
  163. - file name problems
  164.  
  165. I had problems with the length of the filenames. DOS allows just a 8 
  166. character name with a 3 character extension. I have solved this problem 
  167. with files called "name maps". With this maps I map a long Unix name to a 
  168. short DOS name - the extension is preserved (means just 3 characters are 
  169. allowed). The name of the file containing such a map is always "NAMES.MAP". 
  170. The structrure of this file is: 
  171.  
  172. number '\n' { long-Unix-name '\n' short-DOS-name '\n' }
  173.  
  174. Each directory has its own name map. I insert just files into the map (no
  175. subdirectories).
  176.  
  177. '\n':           newline - each item is seperated by a newline 
  178.         (\r\n is also allowed)
  179.  
  180. number:         the number (represented by ascii characters) is used to 
  181.         create a new unique file name; if the file is empty number 
  182.         is 0; in the current version number is alway increased if a
  183.         new name is inserted - it is not decremented if a file
  184.         is removed.
  185.  
  186. long-Unix-name: a Unix file name (i.e. Short.m3, ThisNameIsTooLongForDOS.m3)
  187.  
  188. short-DOS-name: a DOS file name (i.e. Short.m3, 123.m3); if the lenght of a
  189.         Unix name (excluding the extension) is less equal 8 characters
  190.         it is not changed; if the length of the name is greater it is
  191.         mapped to a number; Note: the extension is not changed 
  192.  
  193. To construct such NAMES.MAP files on a Unix system I have written sn.m3. It
  194. reads directories and also subdirs and converts the file names there to short
  195. DOS file names. The Module \m3\libm3\rw\src\NameMap implements the name maps.
  196. m3 consults this maps to find a file. 
  197.  
  198. - file problems
  199.  
  200. There are different file flags (i.e. for open()) on Unix and DOS systems
  201. (O_RDONLY, O_WRONLY, ... see \m3\libm3\unix\src\DOS386\Unix.i3, Ustat.i3).
  202. Furthermore DOS distinguishes between "text files" and "binary files". The
  203. M3 Rd'ers and Wr'ers use read(), write() and lseek() calls to work on
  204. file streams. The problem is that lseek() on a PC does not know something 
  205. about text files but repositioning is done based on values returned by read() 
  206. and write(). The last two system calls are able to distinguish between text 
  207. and binary files. Reading a file in text mode and positioning with lseek() 
  208. based on values returned by read() gives bad results. 
  209.  
  210. Therfore all files are opened in binary mode. To provide text files 
  211. transparent filters (DOSTextRd.T, DOSTextWr.T) are used (see their 
  212. interfaces for further info).
  213. The Module FileStream is used only for text files - for binary files use the
  214. Module FileIO (see \m3\libm3\rw\src). Note that FileStream knows about name
  215. maps - FileIO does not.
  216.  
  217. - argument length
  218.  
  219. The lenght of arguments given to a program from the command line is 
  220. restricted by MS-DOS. m3compiler is able to use a argument file. 
  221. The arguments in the file must be seperated by newlines. To call m3compiler 
  222. with the argument file "arguments" use: m3compiler @arguments
  223.  
  224.  
  225. Experiences with go32 and gcc:
  226. ------------------------------
  227. go32 and gcc are reliable most of the time. Sometimes I had crashes and it
  228. can happen that your disk is corrupted. It was always possible to correct
  229. this problems with "chkdsk /F". 
  230.  
  231. The M3 driver (m3) uses fork/exec to start the M3 compiler (m3compiler). 
  232. There is no working fork/exec available on the PC. Therefore I have used 
  233. system() instead. m3 usually calls m3compiler first and should then call gcc. 
  234. gcc calls (also with system()) cpp (preprocessor), cc1 (C compiler) and as 
  235. (assembler). It seems that there is just one level of calls with system() 
  236. possible. That means m3 is able to call gcc but gcc is not able to call cpp - 
  237. it simply hangs. I was therefore forced to go around gcc and call the C passes 
  238. (cpp, cc1, as) and ld "by hand" directly from m3.
  239.   
  240. The whole system communicates via files. Therfore I recommend to use a disk
  241. caching program. I have used "smartdrv" - don't make it too big - some people 
  242. reported problems with go32. The only option I used with smartdrv was to 
  243. enable write behind. 
  244.  
  245. You can interrupt a running program with Ctrl C - but sometimes the machine
  246. reboots if you do so. If your program hangs - i.e. because of a unhandled
  247. exception - try to type Ctrl C (and nothing else). You should return to the
  248. DOS prompt. If you type another key your machine enters Nirvana and will need
  249. a soft or hard reset. The reason for this is that I have not adjusted the M3
  250. runtime system. 
  251.  
  252.  
  253. Acknowledgements:
  254. -----------------
  255. I had this summer the opportunity to work as a summer intern for DEC-SRC.
  256. Thanks DEC-SRC. My host there was Bill Kalsow. Thanks Bill for your patience
  257. in explaining the M3 compiler to a M3 novice like me. I would also like to 
  258. thank Prof. Laszlo Boszormenyi (Universitaet  Klagenfurt, 
  259. Universitaetsstrasse 65-67, Institut fuer Informatik, A-9020 Klagenfurt, 
  260. AUSTRIA, e-mail: laszlo@ifi.uni-klu.ac.at) who has allowed me to work on 
  261. this project. 
  262.  
  263. If you have questions you can try to send them to the e-mail address *below*.
  264. Sorry, I do not know wether I will be able to support PC-M3 in the future - 
  265. therefore be ready to help yourself. I hope the sysops at the University
  266. will keep my account open. 
  267.  
  268. If you use PC-M3 please send a postcard to my address *below* !!! Thank you!
  269.  
  270.    - Klaus
  271.  
  272. Klaus Preschern
  273. 10. Oktoberstrasse 4
  274. A-9170  Ferlach
  275. AUSTRIA
  276.  
  277. e-mail: klaus@ifi.uni-klu.ac.at
  278.  
  279.