home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / nasm_src / doc / hack.txt < prev    next >
Text File  |  1993-01-19  |  17KB  |  391 lines

  1. ----------------------------------------------------------------------
  2.                   Copyright (C) 1991 by Natürlich!
  3.                      This file is copyrighted!
  4.                Refer to the documentation for details.
  5. ----------------------------------------------------------------------
  6. ======================================================================
  7.                             Hacking NASM65
  8.          ***  READ THIS IF YOU WANT TO PORT OR IMPROVE NASM ***
  9.                            RANDOM THOUGHTS
  10.                            TABs @ 3, 6, 9 ...
  11. ======================================================================
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. STEP 1   L O O K   A T   Y O U R   M A C H I N E .   D O   
  23.          Y O U   T R U S T   I T   T O   C O M P I L E   
  24.          A N D   E X E C U T E   A   L A R G E   C   
  25.          P R O G R A M   P R O P E R L Y  ?
  26.          
  27.          H I N T :   I F   Y O U   A R E   A   M S - D O S   
  28.                      U S E R   Y O U   P R O B A B L Y   
  29.                      D O N ' T .  S K I P   T O   T H E   
  30.                      E N D   O F   T H I S   T E X T
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. STEP 2   E D I T   P O R T A B L E . C   A N D   T H E N
  45.          T R Y   T O   C O M P I L E   I T    F I R S T !
  46.          I F   Y O U   C A N ' T   G E T   P O R T A B L E
  47.          T O   R U N ,   F O R G E T   A B O U T
  48.          C O M P I L I N G   T H E   P A C K A G E !
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.     **** IMPORTANT **** IMPORTANT **** IMPORTANT **** IMPORTANT ****
  64.  
  65.     If you port this to another machine make sure that the object files
  66.     produced are compatible with the TOS version!! THIS IS THE MOST
  67.     IMPORTANT THING TO WATCH OUT FOR WHEN PORTING!!
  68.  
  69.     IF YOU CAN'T MAKE IT object file compatible, but you get it working
  70.     THEN YOU MUST SET #define INCOMPATIBLE 1. This will at least tell
  71.     other machinery with correct ports that they can't use your objects.
  72.     File compatible, does not mean file identical. If it looks different
  73.     but it still links with ST produced object files and produces the
  74.     same binary, then that's OK.
  75.  
  76.     **** IMPORTANT **** IMPORTANT **** IMPORTANT **** IMPORTANT ****
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. Use GCC, if you are running Unix. The HP cc compiler I know, doesn't
  85. compile anything, beyond "hello world".
  86. Compile and run portable.c on a new system, to see where the
  87. differences between Atari ST and the new machinery lie.
  88. Portable produces "localdef.h" for your defines.h file. If your
  89. system doesn't have <signal.h> set SIGNAL to 0 (it doesn't matter
  90. for NASM65, but you can only guess from crashes, whether WORDs
  91. have to lie on even boundaries). If you know that you don't have
  92. UNIX-like IO, set IOCHECK to 0 as well. If portable crashes set
  93. #define WORD_EVEN 1
  94. in the "localdef.h" file.
  95.  
  96. NASM65 puts heavy strain on the compiler and the preprocessor.
  97. If your preprocessor is apparently NOT up to standards you might
  98. want to use an ANSI cpp to preprocess all .c files and compile those
  99. on your lesser C-compiler.
  100.  
  101. Change the file xosbind.h, to fit your system. Check out the way lseek
  102. operates.
  103.  
  104. Files you may want to change are...
  105. defines.h
  106. xosbind.h
  107. nmalloc.h
  108.  
  109. If you can't set "byte" to 8 bit, "word" to 16 bit or "lword" to 32 bit,
  110. then you need to look into structs.h AND INTO OBJECT.H!!. Also most
  111. probably yylval will need retyping. (struct ??) Some programs like
  112. disasm65 expect 16bit datatypes and will produce unsightly results.
  113. Bottomline: If you don't have 8 and 16bit things FORGET IT!
  114.  
  115. Almost every pointer has a "huge" modifier, which is completely
  116. meaningless except if you are MS-DOS based.
  117.  
  118.  
  119. If you do mind the style this is written in, than go port/hack
  120. something else. I do not (repeat: do not) want any improvements in
  121. the visual style this is written in. I also don't think leaving out
  122. the various little jokes makes your port a good port. If you can hack
  123. up something better, GO AHEAD!  (WITHNOISY not required BTW). And
  124. please.. NO FUCKING PROTOTYPING!
  125.  
  126. I'd appreciate if you could #if around the code, that creates problems,
  127. so that the source will still be useable for the ST and other already
  128. ported machinery. (except if your code is definitely more correct, like
  129. f.i. a missing cast or so..) If you have successfully ported please send
  130. me your diffs so that I can update my sources with them. Indicate which
  131. version you hacked on BTW.
  132.  
  133. For development set VERSION to 0, and all revisons to 0 (at first).
  134. This makes things a  lot  easier, and enables debugging for those
  135. w/o a sourcelevel debugger.
  136.  
  137. Improving NASM to handle the C64 or AppleII, ought to involve 'just'
  138. changing the FF FF headers of the executables, and changing |MEMLO to
  139. the right value. If they can't take segmented binary files, it might
  140. be wise to disallow the '-r' flag.
  141.  
  142. Some files are compiled twice, once for the linker and once for
  143. the assembler. Try to keep those as short as possible.
  144.  
  145.  
  146. This is taken from NERD but it is valid nevertheless:
  147.      One more note to the comments, don't trust them if they don't make
  148.      sense to you. Most of them are there just for my entertainment and
  149.      as reminders of historic failures. (Some of them are plain wrong)
  150.      To understand the comments a complete CD-collection of bands mentioned
  151.      below and the books of R.A. Lafferty are essential.
  152.      (-zusammenfassend: Kommentare sind für mich, nicht für dich. Der
  153.      Sinn läßt sich manchmal nur mit einigem Hintergrundswissen er-
  154.      schliessen. Viel Glück trotzdem..)
  155.  
  156. Getting more speed out of NASM:
  157. This program has tought me something about what's really important in
  158. an assembler and what's not. All important is the character get routine!!
  159. Unfortunately due to my efforts in OO-designing the I/O system, this
  160. is one of the slower components. INPUTFST.H & FASTEXPR.H yielded a
  161. speed increase of 10% (difference to VERSION 0)). Needless to say this
  162. is less than satisfactory. (A further rewrite in v1.2 which had the looks
  163. that kill, didn't do anything...)
  164.  
  165. Yacc might be a bit overkill for an assembler. Some code has not seen
  166. any optimization although it should, like the stuff in MACRO.C and
  167. PROCESS.C. With the help of the generic nmalloc and some inline #defines,
  168. creation and handling of all the lists, should be quite speedy, but I
  169. suspect it isn't (More fun ahead).
  170. Strings could be aligned on odd addresses only, which would make hashing
  171. easier since, you'd just need to pick a LONG from &string + 3. This isn't
  172. that good though, cause that means that local labels only get 3 chars for
  173. hashing. The point of having 6 characters is that many labels differ only
  174. at the end (like f.i. COLPL0 COLPF1). On the other hand those aren't local
  175. labels and the hash routine, although written in assembler takes an
  176. estimated 300 cycles ~ 50 microsecs, so may be it WOULD be worthwhile.
  177. There is one thing bugging me still, no matter what find_label does
  178. at least one strcmp must be done, when a matching label is found. Since
  179. the hash values are spread over several characters using HASH alone for
  180. the first 6-7 characters is not conclusive. Maybe use 64 bit for hashing..
  181.  
  182. >version 1.2 has been successfully ported to MSDOS, (thanks to J.Richter
  183. >for lending me his machine for a week and helping me read the
  184. >80xxx ML code, he also pointed out some problems with prototyping).
  185. >One good thing about this affair was that I got access to a profiler.
  186. >The results have been quite pleasant so far, the bottle neck being the
  187. >parser and not my code, as was feared. The find_label routine is quite
  188. >speedy and doesn't warrant further optimization.
  189. v1.2 probably was never as successful port. It just looked that way.
  190.  
  191.  
  192.  
  193. (THIS IS VERY OUTDATED AND JUST KEPT IN HERE FOR HISTORICAL AND AMUSEMENT
  194. VALUE (nat/10/91))
  195. (SKIP UNTIL "<<<HERE>>>" AND IGNORE THIS)
  196.  
  197. Some comments start of with **, this means usually that at this point
  198. in the code some forseeable problems may arise when porting this code.
  199. **-PORT #1-** means:  casting was used just to get rid of warnings. They
  200.                       can be thrown out if needed.
  201.  
  202. **-PORT #2-** means:  Be very careful here. A structural change might
  203.                       lead to imcompatibilites. (This should have been
  204.                       put into more places)
  205.  
  206. **-PORT #3-** means:  Change this value according to your machine.
  207.  
  208. **-PORT #4-** means:  There could be problems here with BITwise BIGENDIAN
  209.                       machinery.
  210.  
  211. **-PORT #5-** means:  This shouldn't be a problem, since $0000 is $0000
  212.                       whether BIGENDIAN or LITTLEENDIAN
  213.  
  214. **-PORT #6-** means:  If this doesn't work, omit it. Note it in the run
  215.                       notice though.
  216.  
  217. **-PORT #7-** means:  This (probably) only works with two's complement.
  218.  
  219.  
  220. Some porting hints:
  221.  
  222. So you've got some bastard machinery that makes life miserable. I can
  223. anticipate some problems and point you into the right directions...
  224.  
  225. Case1:  Bytes are 7 Bit (or less ?). Jeeeeeesus. You really are some
  226.         diehard fanatic. You probably are on some sort of mainframe and
  227.         VERY bored with life. My advice: Forget it.
  228.         If you make it nevertheless PLEASE PLEASE send me the source.
  229.  
  230. Case2:  If you have a 68xxx or 80xxx machine, NASM should compile fine.
  231.         Only the I/O-calls might give you problems.
  232.  
  233. Case3:  Pointer trouble. If unsigned long is too small to pack any kind
  234.         of pointer into, you will have to use a union for yylval in lexer.c
  235.         asm65.y macro.c md_suck.c. I figured a compiler, which can't
  236.         implement unions as register variables (as I fathom some can't)
  237.         would compile better code this way. (Who knows...). The rest
  238.         should be OK, since I ought to have casted every pointer in sight.
  239.  
  240. Case4:  Portable tells you: NO 16-Bits around. This is BAD!! Look around,
  241.         maybe you can construe something out of two chars. If you take a
  242.         look at code.h, you will see that this code is VERY dependent, that
  243.         you can put 2 8-Bits together, calc with them as if they were
  244.         16-Bit (unsigned natch!) and then pull them apart again. If you
  245.         can't make 16-Bits somehow, try for 24 or 32 bit and rewrite
  246.         code.h to calc the new offsets (possibly + 2 bytes).
  247.  
  248. (<<<HERE>>> OK, HERE COMES SOME LESS CRUFTY ASCII)
  249.  
  250. Adding your own directives is EASY. First make up a name. It must
  251. start with a '.'. Check out the way I did it with .undef. First
  252. I put in a line in ASM65.Y in
  253.  
  254. nline:
  255.       ...
  256.       |  T_UNDEF  T_IDENT                 { undefine( $2);          }
  257.       ...
  258.  
  259. this basically means, when a line contains a .undef directive token, which
  260. must be followed by an identifier token, call undefine() with the identifier.
  261. Now register T_UNDEF as a token with
  262.  
  263. %token <u>  ... T_UNDEF     /* line 72 in ASM65.Y or so... */
  264.  
  265. <u> basically means, we don't care about the <value> of T_UNDEF, we DO
  266. care about the value of T_IDENT (--> $2) but T_IDENT is already handled
  267. so we don't need to do anything more in ASM65.Y. If you want to be neat
  268. do a little function definition in NASM.H. Make it:
  269.  
  270. void undefine();
  271.  
  272. Now we need to generate the T_UNDEF token, this is done in md_suck
  273. (M acro & D irective SUCK er). Since there aren't yet any other directives
  274. starting with U, we have to create a du_[] array for ourselves, that
  275. ends with a EOA (end of array) field. If there had been a du_[] array
  276. already we'd just needed to insert our bit { "UNDEF",  T_UNDEF, 0 } at
  277. the lexically correct position. Since du_[] didn't exist before we also
  278. need to update   *d_arr  and insert du_ inbetween  dt_, and  dv_.
  279. Then we also need to update (because we changed d_arr) d_starters.
  280. We locate the free entry for U
  281.    /* A B C D E F G H I J K L M  N  O  P Q  R  S  T U  V  W X Y  Z */
  282.       1,2,3,4,5,6,0,0,7,0,0,8,9,10,11,12,0,13,14,15,0,16,17,0,0,18,
  283. and update the table to
  284.    /* A B C D E F G H I J K L M  N  O  P Q  R  S  T  U  V  W X Y  Z */
  285.       1,2,3,4,5,6,0,0,7,0,0,8,9,10,11,12,0,13,14,15,16,17,18,0,0,19,
  286. (we could have done this a bit faster, by appending du_ to d_arr and
  287. putting a 19 into d_starters, but it would have looked ugly...)
  288. Now we need to update two more files, which are ndebug.c, we just insert
  289.       case T_UNDEF :    x = "T_UNDEF";    break;
  290. anywhere it looks OK (in the large switch statement),
  291. and errorasm.c we insert a
  292.       case T_UNDEF    : return( ".UNDEF");
  293. so that we can create somewhat more readable error messages.
  294.  
  295. And we are done! (Don't forget to write the C-routine.. (har har))
  296.  
  297.  
  298. PROBLEMS THAT I RUN INTO WHENEVER I AM TRYING TO PORT NASM
  299. ----------------------------------------------------------
  300.  
  301. o  Forgot to run portable, when copying over new files and
  302.    thereby clobbering LOCALDEF.H
  303.  
  304. o  Set TEST in nmalloc.h to 1 and expect big macros to be
  305.    swallowed.
  306.  
  307. ----------------------------------------------------------------------
  308. A little bonus for those who read thru this cruft till the end:
  309. (for seasoned readers this is v1.2) of course you never
  310. could put in an AUTO folder, cause GEM isn't running yet...
  311.  
  312. ;ABE ASCII-Binary-Encoding (by Brad Templeton)
  313. ;Use 'sort' and/or 'dabe' to decode
  314. T./z$$filecount=1
  315. T.0N##S1000,1000,1000,ABE1
  316. T.1N$$blocking=false
  317. T.2r$$uname=x.arc
  318. T.3a$$os=gemdos
  319. T.4c$$fname=x.arc
  320. T.55$$date=665419678
  321. T.6d$$perm=0
  322. T.7C$$size=1904
  323. T.8V""%0+_(&,zO=&=:'j(2\B)--<WF&^&AA3I/db%Z%a*0
  324. T.9O""&.]L?)J%&'%()*+0,-./q7123(4567/89v;'<=>?Z
  325. T.AT""'@ABC%DEFG%HIJK1LMNO'PQRS(TUVW;XYZ[V\]^_i
  326. T.Bg""(`abc1defgDhijkGlmno5pqrs,tuvw-xyzukXpGSu
  327. T.CM""))YR*&VDUN8OPl[WqlSZW5-U^3+_tcMx:g>Jfirj2
  328. T.Dp""*;n1v)[e342H`Nzk\FcKZ6s40G@baIZkLM`?9oihZ
  329. T.EH""+r>m8'10w@o?K.g6oxE7*X(EC>,M]mQhk:P>Qq;6W
  330. T.FJ"",TYCWlGV/HY8325Z'%y<oJB&RlTpnfNeDwsi9Qdtu
  331. T.GKd=NFNTL|OAD}.PRG0{D000A"AQu!wqZ+002`40)40|6@j+#F+{-3'xb}7.bk5+BLa
  332. T.HX-NmX:J{NMg1{hB0P{BO0+#*9Lvqm0=0+!mT|,i{=055#+J*f1)[\)0`=.#(()"M)a
  333. T.In0|z8:{1,Xd".>0"Q9q0:a+!ZS!J]|:t\WI{<.0="1))}_]p0-{YY4|12-Qf$QW{HJ
  334. T.JWg|[F{/0P!Mwc{)(0.P#evqwR=.{?g0`W!1K|?u"7FB0[~5wEn0~V,0|,A}kRe($Sj
  335. T.KKe#4,?Cv.h{9:COV{:7ih}+]C@+)]~a.M!y*d{dy3e@7"IC[H5r"y.X{IQb)!FLE}q,`
  336. T.LnmV}lj?N|H2T0d=NFNTL|OAD{.S000|;O00A"Aeu|9-|7\002..%}xSf2}i4o{Q)7|^
  337. T.MEU2/6e{G4P!6(DjHG&~V2C|/\{%4<A?0Y|/M{%9.fVn~FHB{>4cXV./{fod-.4R=_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y!5L{m8l!W4|3r|jF7!a]4Z"vz}3;F
  366. T.paV{.CK{PXB4I}&Q-@"s/Z}MDE|2<H#lnQ{ee5BvR!>x!h3[|5l!4c|&`{9^k"AaA5$%\
  367. T.q41::!(Q!AR'p_<{l`V.TY:TpY<f@zQ!pz|OUAI|R^0d0
  368. T.rL$$end_file=x.arc
  369. T.sd$$filecrc32=951575977
  370. T.tH##E54348
  371. ;End of ABE encoding
  372.  
  373.  
  374. MS-DOS users:
  375.  
  376. I just spent what was one of the most miserable weekends in my life 
  377. porting NASM to MS-DOS using TC2.0 and TC3.0 (thanks again to 
  378. J. Richter for borrowing me his machine). Well the port may be deemed 
  379. partly successful only since the linker crashes on occasion. The 
  380. TC3.0 problem was due to a definite compiler bug and the TC2.0 failure 
  381. is very much suspected to be a compiler failure too. In the directory 
  382. PCSTUFF I have left the various project files. If you have access to 
  383. a newer version you may give it a try. There's just one thing I must 
  384. get off my chest:
  385.  
  386.    Your PC is huge childraping kludge from hell. Do yourself a favor
  387.    buy a Motorola based product, support the sanity of programmers.
  388.    
  389. P.S. (weeks later) Maybe TC2.0 will do it, with the newest version.
  390.  
  391.