home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / extasm_1 / !extAOF / Manual < prev    next >
Text File  |  1995-07-08  |  14KB  |  426 lines

  1. ------------------------------------------------------------------------
  2. extAOF version 1.60
  3. ------------------------------------------------------------------------
  4.  
  5. This program is to be used with extASM to produce files in AOF format.
  6. It is Shareware (part of the extASM package).
  7.  
  8. © Terje Slettebø 1995
  9.  
  10.  
  11. This program takes an assembly source for the extASM assembler and
  12. translates it to a source which, when assembled, produces a file in the
  13. ARM Object Format (AOF). This can then be linked with e.g. AOF files
  14. from a C compiler.
  15.  
  16. The system is as follows:
  17.  
  18.  ____________      ___________
  19. | C compiler |    | Assembler |  ... (other possible code
  20. |____________|    |___________|       generators)
  21.       |                 |
  22.   ____|_____       _____|____
  23.  | AOF file |     | AOF file |
  24.  |__________|     |__________|
  25.       |                 |
  26.       |_________________|
  27.                |
  28.             ___|____
  29.            | Linker |
  30.            |________|
  31.                 |
  32.            _____|______
  33.           | Executable |
  34.           | file       |
  35.           |____________|
  36.  
  37.  
  38.  
  39. AOF files are also called object files. Since the linker doesn't care
  40. where an object file comes from, you can use the object file, and
  41. linker, system in different ways, e.g.
  42.  
  43. - You can just link object files from the C compiler. This is the normal
  44.   use when compiling a C program. The C compiler compiles the C program
  45.   and produces an AOF file in the 'O' directory. Then the linker links
  46.   together this AOF file and any other library files that are referenced,
  47.   e.g. RISC_OSLib, and makes an executable program.
  48.  
  49. - You can also link C and assembly by using extAOF to make an AOF file,
  50.   which can then be linked with one or more object files from the C
  51.   compiler.
  52.  
  53.   To do this, do the following:
  54.  
  55.   1. Convert the assembly source that you want to make into an AOF file,
  56.      with extAOF, and assemble the resulting source with extASM. You then
  57.      get an AOF file.
  58.  
  59.   2. Put this AOF file somewhere where it can be used for linking. You
  60.      can e.g. have it in a directory together with the other object file
  61.      directories, such as CLib and RISC_OSLib. The files in the 'O'
  62.      subdirectories of these directories are the object files. The
  63.      placement of the object file is not important though.
  64.  
  65.      You then have to inform the linker of the existence of the object
  66.      file. In ANSI C this can be done by appending the full pathname of
  67.      the AOF file in the 'Libraries' menu entry.
  68.  
  69.   3. You also have to make a header file for any procedure you define,
  70.      to be included with the other header files.
  71.  
  72.      E.g. for a procedure called 'testproc', which adds two numbers, and
  73.      returns the result, the header info could be as follows:
  74.      'extern int testproc(int,int);'
  75.  
  76.      This can also be put in the C source.
  77.  
  78.  
  79.   When you then compile a C program, the relevant assembler part will be
  80.   linked in, if it is referenced in the C program by calling one
  81.   of the assembler routines. If you have an assembler routine with the
  82.   name 'procedure', then calling 'procedure(<any parameters>);' from a C
  83.   program will link it with the program. How assembler routines are set
  84.   up so as to be referenceable and callable is explained after the next
  85.   paragraph.
  86.  
  87.  
  88. - Another way you can use the object file system is to perform a linking
  89.   just of assembler routines. This can be handy if you have a large
  90.   assembly source, and you only change a part of it. Then you can
  91.   pre-assemble the other parts as AOF files, and link them with the
  92.   routine you are working on. Then you don't have to assemble the whole
  93.   source every time. In this way, one source can call a routine or
  94.   reference a variable in another source, and the referencing is worked
  95.   out by the linker.
  96.  
  97.  
  98. Object assembler statements
  99. ------------------------------------------------------------------------
  100. There are some statements or keywords which can be included in the
  101. assembly source, to enable extAOF to generate the AOF file, and define
  102. any procedures or reference external procedures etc. These statements
  103. are of course removed in the converted version of the source. The
  104. statements used are based on studying the ObjAsm assembler output of
  105. ANSI C, and should be fairly close to the Acorn ObjAsm syntax. I am not
  106. sure that they are completely the same, though.
  107.  
  108. Some of the following information is obtained from the PRM's, in the
  109. chapters about the ARM Object File Format, and ARM Procedure Call
  110. Standard. If you want a more detailed description of the AOF format and
  111. how to use it, you are referred to those chapters. It shouldn't be
  112. necessary to know more than what is written in this file to be able to
  113. use this program. The assembler source statements are as follows.
  114.  
  115.  
  116. Statements
  117. ----------
  118. In this description, 'symbol' is used to mean both global variable
  119. (which can be referenced in other AOF files), and procedure.
  120.  
  121. Statements must be preceded by '#' (including the '%' statement)
  122. just like the other commands in extASM. Statements can be written in
  123. upper or lower case.
  124.  
  125. Mark an area
  126. ------------------------------------------------------------------------
  127. #area <areaname> [,code|,noinit] [,readonly]
  128. ... (code, data or zero-initialised data)
  129.  
  130. #end
  131.  
  132.  
  133. All code or data for an AOF file, as well as #import and #export statements,
  134. has to be in an area. If a symbol in an area is referenced, then that area
  135. is included in the final executable file. At the end of the area, you can
  136. also use a new #area statement, instead of #end.
  137.  
  138. code
  139. ----
  140. If 'code' is appended to the statement, it is a code-area, otherwise it
  141. will be a data-area.
  142.  
  143. noinit
  144. ------
  145. If you instead append 'noinit', then it will be treated as a non-
  146. initialized data area, which should be zero-initialised.
  147.  
  148. The linker will then either allocate a pre-defined zero-initialised area, or
  149. set up code to zero-initialise it at run time. This is up to the linker. It
  150. seems that the linker with ANSI C uses the latter method, although I am
  151. not sure about this.
  152.  
  153. The advantage of this 'noinit' option is that the object file can be much
  154. smaller, since you don't have to include the zero-initialised data, you just
  155. specify the size of the area, using the #% <size in bytes> statement in the
  156. area.
  157.  
  158. readonly
  159. --------
  160. If you use the 'readonly' parameter, the code or data will be specified
  161. as read-only, otherwise it will be read/write.
  162.  
  163. The linker will group all Read-Only areas together, and all Read/Write
  164. areas and all Zero-Initialised areas. The Read-Only areas will also be
  165. write-protected, if hardware permitted.
  166.  
  167. The linker will group the areas first by attribute (Read-Only etc.),
  168. then by the (case-significant) alphabetical order of area names. The
  169. Read-Only areas will preceed the Read/Write areas. Within Read-Only and
  170. Read/Write areas, Code preceeds Data, which preceeds Zero-Initialised
  171. data. Zero-Initialised data may not have the Read-Only attribute.
  172.  
  173.  
  174. #import <Symbolname>
  175. ------------------------------------------------------------------------
  176. Reference an external symbol. This symbol can then be used in the code
  177. in two different ways:
  178.  
  179. B[L][CC]   Symbol
  180.  
  181. This branch/branch with link will branch to the address of the routine
  182. given by the symbol. 'cc' is the (optional) condition code.
  183.  
  184. DCD   Symbol
  185.  
  186. This word will then contain the address of the symbol.
  187.  
  188.  
  189. Examples:
  190. ---------
  191.  
  192. Calling an external procedure
  193. -----------------------------
  194. #import printf          ; this is the name of the procedure to reference
  195.  
  196. BL    printf
  197.  
  198. Reading or writing an external global variable
  199. ----------------------------------------------
  200. #import SomeGlobalVar   ; this is the name of the global variable to
  201.                         ; reference
  202.  
  203. .SomeGlobalAdr
  204. DCD   SomeGlobalVar     ; this will contain the address of the global
  205. ...                     ; variable (e.g. one defined in a C program)
  206. ...
  207. LDR   R0,SomeGloalAdr   ; read the address of the variable
  208. LDR   R1,[R0]           ; read the value of the variable
  209.  
  210.  
  211.  
  212. #export <Symbolname>
  213. ------------------------------------------------------------------------
  214. Define a symbol. This can then be referenced in an external object file.
  215.  
  216. Examples:
  217. ---------
  218.  
  219. Defining a procedure
  220. --------------------
  221.  
  222. #export TestProc
  223.  
  224. .TestProc
  225. ADD   R0,R0,R1
  226. MOVS  R15,R14
  227.  
  228. Defining a global variable
  229. --------------------------
  230.  
  231. #export testglobalvar
  232.  
  233. .testglobalvar
  234. DCD   0              ; this is the initial value of the global variable.
  235.  
  236.  
  237. Both #import and #export, as well as other code, as mentioned, have to
  238. be in an area, defined with #area-#end.
  239.  
  240. #entry
  241. ------------------------------------------------------------------------
  242. One of the areas in an object file may be designated as containing the
  243. start address for the program, which is linked to include this file. If
  244. so, the entry address can be specified with the above statement.
  245.  
  246. #% <Size>
  247. ------------------------------------------------------------------------
  248. Set size of zero-initialised area in bytes.
  249.  
  250.  
  251. Program operation
  252. ------------------------------------------------------------------------
  253. To convert an assembly source to an AOF file, simply drag it to the
  254. extAOF icon on the iconbar. The program will then open a save box, and
  255. you can save the converted source again. This source then has to be
  256. assembled, and this will produce the AOF file.
  257.  
  258. The process is like this:
  259.  
  260.           Drag, or use        Drag from
  261.           s-F10 in            save box, or
  262.           StrongED            use Autostart
  263.  ________          _________          ___________          ___________
  264. | extASM |        |         |        | Converted |        | extASM    |
  265. | source | -----> | extAOF  | -----> | source    | -----> | assembler |-
  266. --
  267. |________|        |_________|        |___________|        |___________|
  268.      _______
  269.     | AOF   |
  270. --> | file  |
  271.     |_______|
  272.  
  273.  
  274. Menu items
  275. ----------
  276.  
  277. Autostart
  278. ---------
  279. When this is selected, extAOF will automatically send the converted
  280. source to extASM, if present. It will then produce the AOF file.
  281.  
  282. extAOF will save the converted source file as "ScrapFile", in the
  283. process, and this will then be loaded by extASM. For this reason, don't
  284. have any file called "ScrapFile" in the same directory as the assembly
  285. source.
  286.  
  287. It is necessary to have the scrap file in the same directory as the
  288. assembly source, as extASM uses the path of the file to determine the
  289. directory to save the object file to.
  290.  
  291.  
  292. Delete tempfile
  293. ---------------
  294. When this is selected, extAOF will delete the file "ScrapFile", which is
  295. made when using Autostart.
  296.  
  297.  
  298. Save setup
  299. ----------
  300. This will save the current setup, i.e. the Autostart and Delete tempfile
  301. state.
  302.  
  303.  
  304. You can also check the AOF files, by using the 'decaof' program, which
  305. is supplied with ANSI C.
  306.  
  307.  
  308. How to make linkable code
  309. ------------------------------------------------------------------------
  310.  
  311. When calling an external procedure, or when making a procedure that can
  312. be referenced from another file, the register usage is as follows:
  313.  
  314.  
  315. On entry to a procedure, the following statements should be true:
  316. -----------------------------------------------------------------
  317. Argument 1 is in R0
  318. Argument 2 is in R1
  319. Argument 3 is in R2
  320. Argument 4 is in R3
  321. Argument 5 and onwards are stored on the stack (R13).
  322.  
  323. All integer and pointer arguments are passed as 32-bit words. All
  324. floating point arguments are passed as 64-bit values, in two words (as
  325. stored by the 'STFD' instruction).
  326.  
  327.  
  328. On exit from a procedure, the following statements should be true:
  329. ------------------------------------------------------------------
  330. R4-R11, and F4-F7 should contain the same values that they did at the
  331. instant of the call. If the procedure returns a word-sized result, which
  332. is not a floating point value, then it should be in R0. If the procedure
  333. returns a floating point result, then it should be in F0.
  334.  
  335.  
  336. Examples of linkable code:
  337. --------------------------
  338.  
  339. C header
  340. --------
  341. extern int AddNum(int,int);  /* This just adds two numbers and returns
  342.                                 the result */
  343.  
  344. /*
  345. The AOF files contain no information about whether a symbol is a 
  346. procedure or a variable, so this has to be declared, either in the 
  347. C source, or in a header file.
  348. */
  349.  
  350.  
  351. Code for procedure
  352. ------------------
  353. #area AddNumArea,code
  354.  
  355. #export AddNum
  356.  
  357. .AddNum
  358. ADD   R0,R0,R1           ; Argument 1 and 2 are in registers R0 and R1.
  359.                          ; Return result in R0.
  360. MOVS  R15,R14            ; Return from procedure. Use the 'S' suffix to
  361.                          ; Preserve the flags.
  362.  
  363. #end
  364.  
  365. It is as easy as this!
  366.  
  367. If you use any other registers than R0-R3 or R12, or F0-F3, then these
  368. have to be preserved on the stack at the start of the procedure (the R13
  369. is set up as a stack), and restored when returning. Se the entry/exit
  370. conditions for a procedure described above.
  371.  
  372.  
  373. Code for procedure, which also calls an external procedure
  374. ----------------------------------------------------------
  375.  
  376. C header
  377. --------
  378. extern void TestProc(void);
  379.  
  380.  
  381. Code for procedure
  382. ------------------
  383. #area TestProcArea,code
  384.  
  385. #export TestProc
  386. #import printf
  387.  
  388. .TestProc
  389. STMFD R13!,{R4,R14}   ; R4 is used, so it has to be stored on the stack
  390. ADR   R0,TextStr
  391. MOV   R1,#1
  392. MOV   R2,#2
  393. MOV   R3,#3
  394. MOV   R4,#4
  395. BL    printf
  396. LDMFD R13!,{R4,R15}^  ; use the '^' suffix to preserve the flags.
  397. .textstr
  398. DCB   "This is a test, var1=%d, var2=%d, var3=%d, var4=%d\n",0
  399. ALIGN
  400.  
  401. #end
  402.  
  403.  
  404. Known bugs
  405. ----------
  406. #entry doesn't work yet.
  407.  
  408. Since extASM has its own DDEUtils-emulator module ("Sender"), to be able to
  409. support Throwback, then only ANSI C's !CC application or extASM can be run
  410. at one time, if making AOF files.
  411.  
  412. This is because the extASM's Sender module, and !CC's DDEUtils module
  413. clashes. I havn't found any fix for this at the moment.
  414.  
  415. To make AOF files, load extASM (if not loaded) and assemble the AOF file.
  416. Then quit extASM and load !CC, to use the AOF file for linking with C. To
  417. assemble the AOF file again, quit !CC and load extASM. This process is done
  418. relatively easy with two Obey files (e.g. "RunAsm" and "RunC").
  419.  
  420.  
  421. Any questions, suggestions, bugs etc. are welcome. I can be contacted as
  422. follows:
  423.  
  424. Programmers BBS (Norway), +22 71 41 07 / +22 71 51 07, or email:
  425. terje.slettebo@programmers.bbs.no
  426.