home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / f / forthmac / !Forthmacs / docs / html / RO_impleme < prev    next >
Encoding:
Text File  |  1997-05-01  |  25.4 KB  |  537 lines

  1. <!-- Forthmacs Formatter generated HTML V.2 output -->
  2. <html>
  3. <head>
  4. <title>Forthmacs Implementation</title>
  5. </head>
  6. <body>
  7. <h1>Forthmacs Implementation</h1>
  8. <hr>
  9. <p>
  10. This chapter describes how RISC OS Forthmacs implements the Forth virtual 
  11. machine on the ARM processors.  It assumes that you have a fairly good knowledge 
  12. of conventional Forth implementations; it does not attempt to be a tutorial on 
  13. how Forth works.  
  14. <p>
  15. <p>
  16. <h2>Dialect</h2>
  17. <p>
  18. RISC OS Forthmacs has been an implementation of the Forth-83 standard, with a 
  19. few exceptions.  It is now far on it's way to be an ANS compliant 
  20. implementation.  It is still rather compatible with the other implementations 
  21. for Sun-68k, Sparc, Atari, Macintosh and OS-9 computers.  
  22. <p>
  23. <p>
  24. <h2>Stack Width and Addressing</h2>
  25. <p>
  26. In RISC OS Forthmacs, all stack items as well as memory cells are 32-bit wide, 
  27. remember this when writing portable programs.  Use the portable ANS operators 
  28. like <code><A href="_smal_BP#177">cell+</A></code> <code><A href="_smal_BR#179">cells</A></code> 
  29. or the RISC OS Forthmacs specific words like <code><A href="_smal_BO#E6">/cell</A></code> <code><A href="_smal_BT#17B">cells+</A>.</code> 
  30. <p>
  31. The address could conceivably grow to 2 to the 32nd power (4 gigabytes), but 
  32. this is restricted by the current CPU/MMU versions to 16/256 MBytes.  16-bit or 
  33. 2-byte memory accesses are not supported any longer and must be emulated if 
  34. necessary.  
  35. <p>
  36. Note: word accesses are simulated by two byte accesses, take care about 
  37. interrupts occurring here! 
  38. <p>
  39. The current ARM MMUs don't support non-aligned memory accesses.  <strong>Note:</strong> 
  40. They don't abort or run any exception vector but just do something <strong>undefined</strong> 
  41. and CPU core dependent.  Take care of this, it took me hours to find a bug! 
  42. <p>
  43. All accesses must be one of: 
  44. <p>
  45. 1) byte-wide access to any address in the address area 
  46. <p>
  47. 2) cell-wide ( 32-bit ) access to any aligned address 
  48. <p>
  49. The word wide access possible at least on StrongARM and ARM8 cpus is <strong>not</strong> 
  50. supported by the RiscPC platforms.  Special source extensions are available for 
  51. single-board platforms.  
  52. <p>
  53. <p>
  54. Both stacks are pre-decrementing/post-incrementing.  The parameter stack holds 
  55. its top-of-stack in the top-register <code><A href="_smal_BE#1C">top</A></code> 
  56. - r10, this allows much faster code definitions because of the CPUs 
  57. load-and-store architecture.  
  58. <p>
  59. <p>
  60. <h2>Register Usage</h2>
  61. <p>
  62. <p>
  63. <p><pre>  r9      user area pointer       up</pre><p>
  64. <p><pre>  r10     top-of-stack register   top</pre><p>
  65. <p><pre>  r11     returnstack pointer     rp</pre><p>
  66. <p><pre>  r12     instruction pointer     ip</pre><p>
  67. <p><pre>  r13     stack pointer           sp</pre><p>
  68. <p><pre>  r14     link register           lk</pre><p>
  69. <p><pre>  r15     pc + status + flags     pc</pre><p>
  70. <p><pre>  r15     sr                      sr  hold the flags part of r15</pre><p>
  71. <p>
  72. Note: The internal structure of the pc and flags registers differs between cpus.  
  73. It seems to be better, to generally imagine pc and status register as two 
  74. registers.  The hardware-errors and the <code><A href="_smal_AT#43">.registers</A></code> 
  75. instruction know about this.  
  76. <p>
  77. r0, r1, r2, r3, r4, r5, and r6 are available for use within code definitions.  
  78. Don't try to use them for permanent storage, because they are used by many code 
  79. words with no attempt to preserve the previous contents.  
  80. <p>
  81. Registers r7-r14 can be used within code definitions with great care, but you 
  82. have to save and restore their values at the beginning/end of the definition.  
  83. <p>
  84. <p>
  85. <h2>Inner <address> Interpreter</h2>
  86. <p>
  87. The inner interpreter <code><A href="_smal_AG#36">next</A></code> is direct 
  88. threaded, post incrementing.  The compilation address of all definitions contain 
  89. machine code to be executed, not a pointer.  Each <code><A href="_smal_AC#182">code</A></code> 
  90. definition ends with the <code><A href="_smal_AG#36">next</A></code> code, 
  91. assembled in-line.  The <code><A href="_smal_AG#36">next</A></code> code is: 
  92. <p><pre>       pc      ip )+   ldr</pre><p>
  93. This means: Load the program-counter <code><A href="_smal_BI#50">pc</A></code> ( 
  94. don't affect the CPU status ) from the 4-byte cell pointed to by the instruction 
  95. pointer ip, postincrement the instruction-pointer.  So the <code><A href="_smal_AG#36">next</A></code> 
  96. is only one CPU instruction and very fast.  It is much faster than 
  97. <p><pre>       address  dolink branch</pre><p>
  98. <p><pre>       ...</pre><p>
  99. <p><pre>       pc link mov</pre><p>
  100. constructions because of only one pipeline reload per <code><A href="_smal_AG#36">next</A>.</code> 
  101. But on the other hand, there is definitely a larger overhead for calling 
  102. secondaries.  
  103. <p>
  104. RISC OS Forthmacs versions <code><A href="_smal_BN#115">>=</A></code> 
  105. 3.1/2.70 can switch to another <code><A href="_smal_AG#36">next</A></code> 
  106. scheme.  The first 8 <code><A href="_smal_BR#179">cells</A></code> in the user 
  107. area are free debugging purposes.  <strong>slow-next </strong> ( you find this 
  108. in lib.arm.debugm ) patches all <code><A href="_smal_AG#36">next</A></code> as 
  109. well as conditional <code><A href="_smal_AG#36">next</A></code> calls to 
  110. <p><pre>  pc up mov</pre><p>
  111. Normall there is a normal <code><A href="_smal_AG#36">next</A></code> 
  112. instruction at <code><A href="_smal_BE#31C">up@</A></code> but may install any 
  113. service routine there to do additional checking at run time.  The new debugger 
  114. uses this to branch into the debugger handler.  After 'debugging' you switch 
  115. back to the normal <code><A href="_smal_AG#36">next</A></code> with <strong>fast-next</strong> 
  116. <p>
  117. If you want to use this scheme, there is one thing to remember.  As <strong>slow-next</strong> 
  118. patches all instructions 
  119. <p><pre>  pc ip )+ condition ldr</pre><p>
  120. your handler might be patches as well.  In these cases you should use 
  121. <p><pre>  pc 1  ip ia!  ldm</pre><p>
  122. instead.  This does the same - at least from RISC OS Forthmacs point of view - 
  123. but isn't patched.  See lib.arm.debugm again for an example in the debugger.  
  124. <p>
  125. For discussions about subroutine threaded ( macro extended ) versus threaded 
  126. code implementations see the Forth literature.  Generally, macros do bring some 
  127. advantage in execution speed but give less information about the code itself, so 
  128. debuggers are less useful.  The penalty for direct threaded code is hard to 
  129. predict, it depends very much on the type of application.  Something like 50% 
  130. sounds reasonable, so optimising the bottlenecks could bring big advantages.  
  131. The <em>runtimer </em> utilities might help you doing this.  
  132. <p>
  133. The assembler macro <code><A href="_smal_BD#16B">c;</A></code> assembles the <code><A href="_smal_AG#36">next</A></code> 
  134. instruction and ends assembling by <code><A href="_smal_BT#1DB">end-code</A>.</code> 
  135. A fast conditional next can be done by 
  136. <p><pre>       ...</pre><p>
  137. <p><pre>       r2 0 cmp</pre><p>
  138. <p><pre>       eq next</pre><p>
  139. <p><pre>       ...</pre><p>
  140. <p>
  141. <p>
  142. <h2>Other Definitions</h2>
  143. <p>
  144. Any word that is not a code definition contains a branch+link instruction at the 
  145. code-field, this makes a relative branch to an inline-address and saves the 
  146. pc+sr to the lk register.  
  147. <p><pre>       runtime-addr    dolink branch</pre><p>
  148. The inline address points to a code fragment (headerless in most cases) that 
  149. implements the run-time action of the word.  The parameter field starts just 
  150. after this branch+link instruction and can be found by clearing the flags in the 
  151. link register like this: 
  152. <p><pre>       r0 lk    th fc000003 #   bic</pre><p>
  153. <p><pre>       r0  get-link</pre><p>
  154. <p>
  155. The run-time codes may have to push the top-register to the stack, save the 
  156. return pointer to the return-stack and set the instruction or stack pointer to 
  157. the parameter field address.  All standard runtime codes (those of variables, 
  158. constants, colon definitions, user variables ...) have been optimized for best 
  159. cache-hit rates.  
  160. <p>
  161. Note: <code><A href="_smal_AI#338">word-type</A></code> ( cfa -- addr ) finds 
  162. the address of the words runtime code in this implementation.  
  163. <p>
  164. <p>
  165. <h2>Colon definitions</h2>
  166. <p>
  167. The runtime code: 
  168. <p><pre>  mlabel docolon  assembler</pre><p>
  169. <p><pre>       ip      rp      push</pre><p>
  170. <p><pre>       ip      get-link c;</pre><p>
  171. The body of a Colon Definition starts 4 bytes after the compilation address.  
  172. The body contains a list of compilation addresses of other words.  Each such 
  173. compilation address is a 32-bit number which is an absolute address.  
  174. <p>
  175. <p>
  176. <h2>Variable</h2>
  177. <p>
  178. The Parameter Field of a <code><A href="_smal_BN#325">variable</A></code> 
  179. contains a 32-bit number which is the value of the variable.  The runtime code: 
  180. <p><pre>  mlabel dovariable  assembler</pre><p>
  181. <p><pre>       top     sp      push</pre><p>
  182. <p><pre>       top     get-link c;</pre><p>
  183. <p>
  184. <p>
  185. <h2>Constants</h2>
  186. <p>
  187. The Parameter Field of a <code><A href="_smal_AP#18F">constant</A></code> 
  188. contains the 32-bit value of the constant.  The runtime code: 
  189. <p><pre>  mlabel doconstant  assembler</pre><p>
  190. <p><pre>       top     sp      push</pre><p>
  191. <p><pre>       r0      get-link</pre><p>
  192. <p><pre>       top     r0 )    ldr c;</pre><p>
  193. <p>
  194. <p>
  195. <h2>User Variables</h2>
  196. <p>
  197. The value of a <code><A href="_smal_BK#322">user</A></code> variable is stored 
  198. in the <code><A href="_smal_BK#322">user</A></code> area as a 32-bit number.  
  199. The Parameter Field of a user variable contains a 32-bit offset into the user 
  200. area of the current task.  r8 contains the base address of the current user 
  201. area.  r8 is symbolically defined as <code><A href="_smal_BD#31B">up</A></code> 
  202. in the assembler.  The runtime code: 
  203. <p><pre>  mlabel douser  assembler</pre><p>
  204. <p><pre>       top     sp      push</pre><p>
  205. <p><pre>       r0      get-link</pre><p>
  206. <p><pre>       r0      r0 )    ldr</pre><p>
  207. <p><pre>       top     r0      up add c;</pre><p>
  208. <p>
  209. <p>
  210. <h2>Deferred words</h2>
  211. <p>
  212. The compilation address of the word to be executed by a <code><A href="_smal_AA#1B0">defer</A></code> 
  213. word is stored as a 32-bit absolute address in the <code><A href="_smal_BK#322">user</A></code> 
  214. area.  The Parameter Field of a deferred word contains a 32-bit number which is 
  215. an offset into the user area of the current task.  The runtime code: 
  216. <p><pre>  mlabel dodefer  assembler</pre><p>
  217. <p><pre>       r0      get-link</pre><p>
  218. <p><pre>       r0      r0 )    ldr</pre><p>
  219. <p><pre>       pc      r0      up  ib ldr end-code</pre><p>
  220. The last line holds a somewhat optimized <code><A href="_smal_AG#36">next</A></code> 
  221. instruction, it means: Load the pc from the address in the user area with the 
  222. offset r0.  
  223. <p>
  224. <p>
  225. <h2>;code</h2>
  226. <p>
  227. The compilation address of a word created by a <code><A href="_smal_AX#197">create</A></code> 
  228. ...  <code><A href="_smal_BE#10C">;code</A></code> data type construction 
  229. contains the standard branch+link instruction that branches to the runtime code.  
  230. <p>
  231. The runtime code is defined by the programmer in the <code><A href="_smal_BE#10C">;code</A></code> 
  232. part of the definition.  
  233. <p>
  234. In versions up to 3.1/2.62 <code><A href="_smal_BE#10C">;code</A></code> 
  235. assembled two instructions for your convenience 
  236. <p><pre>       top     sp      push</pre><p>
  237. <p><pre>       top     get-link</pre><p>
  238. this is not the case any more.  I changed this to be more portable with the 
  239. FirmWorks implementation and i feel that all Forth programmers using <code><A href="_smal_BE#10C">;code</A></code> 
  240. should be able to handle this.  
  241. <p>
  242. <p>
  243. <h2>does></h2>
  244. <p>
  245. <p>
  246. <p><pre>  mlabel dodoes  assembler</pre><p>
  247. <p><pre>       ip      rp      push</pre><p>
  248. <p><pre>       ip      get-link c;</pre><p>
  249. The runtime code is defined by the programmer in the <code><A href="_smal_BC#1CA">does></A></code> 
  250. part of the definition.  Before branching to the dodoes code, the does> 
  251. instruction assembles 
  252. <p><pre>       top     sp      push</pre><p>
  253. <p><pre>       top     lk      th fc000003 # bic</pre><p>
  254. to get the parameter field address.  
  255. <p>
  256. <p>
  257. <h2>local variables</h2>
  258. <p>
  259. RISC OS Forthmacs has built in ANS Forth conforming local variables spending 
  260. their lifetime on the return-stack in stack-frames.  The stack-frames are linked 
  261. via a <code><A href="_smal_BK#322">user</A></code> variable <strong>local-frame</strong> 
  262. which is also used to locate a local variables value.  The frame structure is 
  263. like: 
  264. <p><pre>  | cfa:frame>   | old-frame     | old-rs        | loc   | loc   | .........</pre><p>
  265. with cfa:pop-frame on top of the return-stack.  pop-frame removes the current 
  266. frame and switches to the last frame.  
  267. <p><pre>  headerless code pop-frame \ this routine is pushed on return stack by push-locals</pre><p>
  268. <p><pre>       here /cell+ token,</pre><p>
  269. <p><pre>      r0 rp 2    rp ia    ldm</pre><p>
  270. <p><pre>      r0    'user local-frame str</pre><p>
  271. <p><pre>      ip    rp    pop c;</pre><p>
  272. <p><pre>  </pre><p>
  273. The local variables are accessed using (loc) followed by an stack frame index.  
  274. <p><pre>  code (loc)    \ ( -- n )  runtime-code of any local</pre><p>
  275. <p><pre>      r0    'user local-frame ldr</pre><p>
  276. <p><pre>      r1    ip )+    ldr</pre><p>
  277. <p><pre>      top    sp    push</pre><p>
  278. <p><pre>      top    r0 r1 2 #asl db ldr c;</pre><p>
  279. <p>
  280. Note: The decompiler can <code><A href="_smal_AJ#279">not</A></code> know the 
  281. local variables names, so it assumes names like ( v0 v1 ...).  
  282. <p>
  283. <p>
  284. <h2>Tokens</h2>
  285. <p>
  286. Within the body of a colon definition, calls to other Forth words are compiled 
  287. as the 32-bit absolute compilation address of those words.  These tokens have a 
  288. corresponding bit in the relocation table.  
  289. <p>
  290. <p>
  291. <h2>Branching</h2>
  292. <p>
  293. Branch targets are offsets relative to the location that contains the branch 
  294. offset.  They are stored as 32-bit twos-complement numbers representing the 
  295. number of bytes between the offset location and the branch target.  For example, 
  296. a branch to the following location could be compiled with: 
  297. <p>
  298. <p><pre>       postpone branch   4 ,</pre><p>
  299. <p>
  300. <strong>Note:</strong> This is implemented different in version 3.1/2.00.  The 
  301. relative offset is replaced by an immediate absolute relocated address.  
  302. <p>
  303. <p>
  304. <h2>Doubles</h2>
  305. <p>
  306. RISC OS Forthmacs versions newer than 1.83 have full double number support, all 
  307. conversion tools <code><A href="_smal_AS#192">convert</A>,</code> <code><A href="_smal_AO#27E">number?</A>,</code> 
  308. <code><A href="_smal_BM#1A4">d.</A></code> use doubles, the 'scaling' words <code><A href="_smal_AA#C0">*/</A></code> 
  309. <code><A href="_smal_AB#C1">*/mod</A></code> <code><A href="_smal_AU#314">um/mod</A></code> 
  310. use double intermediate results.  
  311. <p>
  312. Also the text-interpreter and compiler accept literals as doubles when there is 
  313. a period at the end of it.  
  314. <p><pre>       : test 1234. d. ;</pre><p>
  315. 1234.  is a double number and <code><A href="_smal_BM#1A4">d.</A></code> 
  316. displays it.  
  317. <p>
  318. This could only be achieved with changing stack effects in a number of words.  
  319. So these new RISC OS Forthmacs versions are no longer compatible when these 
  320. words are used.  The lib.compatible tool does <code><A href="_smal_AJ#279">not</A></code> 
  321. cover these changes.  
  322. <p>
  323. The advantage of the new stack behaviour is it's ANS compliancy and the improved 
  324. arithmetic capabilities.  
  325. <p>
  326. <p>
  327. <h2>Floats</h2>
  328. <p>
  329. RISC OS Forthmacs versions newer than 3.1/2.13 have the ANS Floating and 
  330. Floating Extended wordsets included.  There isn't any further documentation 
  331. available so far, please use the ANS docs for this purpose.  
  332. <p>
  333. <p>
  334. <h2>StrongARM compatibility</h2>
  335. <p>
  336. Versions from 3.1/2.30 run on StronARM based machines but optimized code is 
  337. available from 3.1/2.40 onwards.  
  338. <p>
  339. <p>
  340. <h2>Cache</h2>
  341. <p>
  342. The newer ARM based cpus ( ARM8, StrongARM ) have a different cache structure 
  343. than the elder versions.  Separate instruction- and data caches are used and 
  344. code synchronizing has to be done after change of the code space.  
  345. <p>
  346. <code><A href="_smal_BO#206">flush-cache</A></code> and <code><A href="_smal_AV#2E5">sync-cache</A></code> 
  347. are both implemented in current RISC OS Forthmacs versions >3.1/2.40 in such 
  348. a way, that the compiler is not significantly slowed down, in fact a StrongARM 
  349. compilation is much faster than on the older ARM710.  
  350. <p>
  351. <p>
  352. <h2>Header format - # of bytes in parentheses</h2>
  353. <p>
  354. Source Field (4), Link Field (4), Name Field (n), Padding (0 to 3), Flags (1), 
  355. Code Field (4), Parameter Field (n).  
  356. <p>
  357. As all addresses need to be, the Link Field, Name Field, and Code Field are all 
  358. aligned.  
  359. <p>
  360. Links point to links ( <code><A href="_smal_AJ#279">not</A></code> to Name 
  361. Fields, as in FIG Forth! ) 
  362. <p>
  363. The name field is a normal Forth packed string.  (Many Forth implementations set 
  364. the high bit in the first and last characters of the name field; 
  365. RISC OS Forthmacs does not).  
  366. <p>
  367. Name Field: length-byte, 0-31 character name.  
  368. <p>
  369. <p>
  370. <p>
  371. <h2>Vocabularies</h2>
  372. <p>
  373. Vocabularies have <code><A href="_smal_BG#7E">#threads</A></code> - way hashing.  
  374. This means that each vocabulary has 16 separate linked lists of words.  The 
  375. threads are stored in the <code><A href="_smal_BK#322">user</A></code> area.  
  376. The Parameter Field of a <code><A href="_smal_BR#329">vocabulary</A></code> 
  377. contains the 32-bit offset of the threads in the <code><A href="_smal_BK#322">user</A></code> 
  378. area, followed by the vocabulary-link, a 32-bit pointer to the previous <code><A href="_smal_BR#329">vocabulary</A>.</code> 
  379. The runtime high-level code is: 
  380. <p><pre>       does> body> context token!</pre><p>
  381. <p>
  382. Before searching a vocabulary, a hashing function is applied to the name to be 
  383. located.  The hashing function selects one of the 16 linked lists to search.  
  384. <p>
  385. The hashing function is very simple.  The lower 4 bits of the first character in 
  386. the name (the first name character, not the length byte) are interpreted as a 
  387. number from 0 to 15, selecting a linked list.  
  388. <p>
  389. Vocabularies are not chained to one another.  Search order is implemented using 
  390. the <code><A href="_smal_BN#145">also</A></code> / <code><A href="_smal_AW#286">only</A></code> 
  391. scheme.  Each vocabulary thread is terminated with a special link field in the 
  392. final word.  The special link address is the address of the origin of the Forth 
  393. system (which may change from session to session due to the relocation that the 
  394. operating system applies when loading and executing the Forth system.  
  395. <p>
  396. The parameter field for a vocabulary looks like: 
  397. <p>
  398. User number (/cell), Voc-link (/cell) 
  399. <p>
  400. The user number selects the place in the user area where the head of list 
  401. pointers for the 16 vocabulary threads are stored.  Each vocabulary requires 16 <code><A href="_smal_BR#179">cells</A></code> 
  402. bytes of user area storage for these 16 threads.  The values stored in the user 
  403. area are the Link field Addresses for the top word in each thread.  
  404. <p>
  405. <p>
  406. <h2>Relocation</h2>
  407. <p>
  408. In the RISC OS environment all programs of the absolute type are loaded at $8000 
  409. and executed from there.  So on first sight the relocation table doesn't make 
  410. much sense in this version if you don't care about being portable to other 
  411. RISC OS Forthmacs implementations.  
  412. <p>
  413. But the relocation table can be used for target/meta-compiling or for relocating 
  414. code during run-time.  This is necessary for producing turnkey applications with 
  415. an 'Application Stripper', use of the application stripper requires strict 
  416. adherence to the rules of relocatability.  
  417. <p>
  418. If the program is not relocatable, then a file saved with <code><A href="_smal_BI#2C0">save-forth</A></code> 
  419. will work only if it is later executed at the same address where it was 
  420. executing when it was saved.  If saved with <code><A href="_smal_BI#2C0">save-forth</A>,</code> 
  421. a program that is not relocatable will not work at all, regardless of the 
  422. address where it is later executed.  Consequently, use of the application 
  423. stripper requires strict adherence to the rules of relocatability.  
  424. <p>
  425. In most cases, the relocation bitmap is maintained automatically, without 
  426. requiring any special effort on the part of the programmer.  However, there are 
  427. some cases where the programmer must take explicit actions to ensure that the 
  428. program is relocatable.  
  429. <p>
  430. The executable file contains a relocation list used to identify the locations in 
  431. the program's binary image which contain absolute addresses.  When the program 
  432. is loaded, each of these locations is modified by adding the starting address of 
  433. the program to the number contained in that location.  Only 32-bit numbers may 
  434. be so modified.  
  435. <p>
  436. While RISC OS Forthmacs is running, it maintains its own relocation table, 
  437. identifying those locations in the Forth dictionary which must be relocated 
  438. during <code><A href="_smal_AF#185">cold-code</A>.</code> Each bit in the map 
  439. represents the address of one aligned location.  This relocation table is 
  440. completely different from the standard RISC OS relocation tables, it is only 
  441. used from within RISC OS Forthmacs.  
  442. <p>
  443. In order for this to work properly, the programmer must be careful to use <code><A href="_smal_BX#2FF">token,</A></code> 
  444. A, <code><A href="_smal_AL#24B">link,</A></code> <code><A href="_smal_BW#2FE">token!</A>,</code> 
  445. A! or <code><A href="_smal_AK#24A">link!</A></code> to store an address or token 
  446. in the dictionary, all six set the relocation flags.  
  447. <p>
  448. Addresses may be stored into <code><A href="_smal_BN#325">variable</A>s</code> 
  449. with ! ( without requiring the use of <code><A href="_smal_BW#2FE">token!</A></code> 
  450. ) if the <code><A href="_smal_BN#325">variable</A></code> is re-initialized 
  451. every time that the application is started.  <code><A href="_smal_BW#2FE">token!</A></code> 
  452. is only necessary if the <code><A href="_smal_BN#325">variable</A>s</code> value 
  453. must be set before <code><A href="_smal_BI#2C0">save-forth</A></code> is 
  454. executed, and then is used when the saved application is later invoked, without 
  455. being re-initialized by the application's initialization code.  
  456. <p>
  457. If , or ! is used instead, the address will not be properly relocated if <code><A href="_smal_BI#2C0">save-forth</A></code> 
  458. has been used to write the dictionary image to an executable file.  
  459. <p>
  460. Note: The lib/checkrel.fth program can help you catch relocation problems in 
  461. your applications.  It should be loaded before you load your application, and 
  462. will warn you if your application does things that may not be relocatable.  
  463. After you have fixed the relocation problems, you can load your application 
  464. without lib/checkrel.fth .  
  465. <p>
  466.  
  467. See: <code><A href="_smal_AQ#D0">.buffers</A></code> <code><A href="_smal_BE#DC">.pointers</A></code> 
  468. <code><A href="_smal_BW#2FE">token!</A></code> <code><A href="_smal_BX#2FF">token,</A></code> 
  469. A! A, <code><A href="_smal_AK#24A">link!</A></code> <code><A href="_smal_AL#24B">link,</A></code> <code><A href="_smal_BT#2CB">set-relocation-bit</A></code> 
  470. <code><A href="_smal_AI#2A8">relocation-map</A></code> 
  471. <p>
  472. <p>
  473. <h2>Program header</h2>
  474. <p>
  475. The header of the executable binary image looks like this: 
  476. <p>
  477. <p><pre>
  478.  h_magic   (  0)    \ Magic Number
  479.  h_tlen    (  4)    \ length of text (code)
  480.  h_dlen    (  8)    \ length of initialised data
  481.  h_blen    (  c)    \ length of BSS unitialised data
  482.  h_slen    (  10)   \ length of symbol table
  483.  h_entry   (  14)   \ Entry address
  484.  h_trlen   (  18)   \ Text Relocation Table length
  485.  h_drlen   (  1c)   \ Data Relocation Table length
  486. </pre><p>
  487. <p>
  488. the magic number is the branch+link instruction just behind this header.  Note: 
  489. this header might be changed with future releases according to Acorns executable 
  490. binary code standard.  
  491. <p>
  492. <p>
  493. <h2>Heap memory</h2>
  494. <p>
  495. RISC OS Forthmacs is loaded to $8000 and will have as much memory available as 
  496. was defined by <em>WimpSlot</em> .  
  497. <p>
  498. The <code><A href="_smal_BJ#261">main-task</A>s</code> user area immediately 
  499. follows the first instructions and some permanent data at $8040.  
  500. <p>
  501. $600 byte will be allocated in the module-heap RMA, it will hold the <code><A href="_smal_AA#1E0">env-area</A>,</code> 
  502. the command-line area plus all handlers used by shelled programs.  
  503. <p>
  504. The implementation of the dynamic memory manager has changed in Version 
  505. 3.1-2.00.  From now on the dictionary and the heap share the same memory area, 
  506. the dictionary grows from lower addresses and the heap can be as large as the 
  507. area between the stacks and <code><A href="_smal_AP#21F">here</A>.</code> 
  508. <p>
  509. Note: Of course you may install another memory manager or add more heaps.  
  510. <p>
  511. <p>
  512. <h2>Dictionary memory</h2>
  513. <p>
  514. At the top of the dictionary are both stacks defined by <code><A href="_smal_AX#2B7">rp0</A></code> 
  515. - <code><A href="_smal_BB#2B9">rs-size</A></code> and <code><A href="_smal_AJ#2D9">sp0</A></code> 
  516. - <code><A href="_smal_BU#29C">ps-size</A></code> and the <code><A href="_smal_BM#2F4">tib</A>,</code> 
  517. below this are MBytes of free memory (well, hopefully).  <code><A href="_smal_AP#21F">here</A></code> 
  518. marks the end of the allocated dictionary, classically <code><A href="_smal_BH#28F">pad</A></code> 
  519. is <code><A href="_smal_AP#21F">here</A></code> plus something.  
  520. <p>
  521. RISC OS Forthmacs knows about two dictionary areas, the <code><A href="_smal_AL#2AB">resident</A></code> 
  522. (which is the dictionary you know in all implementations) and the <code><A href="_smal_AD#303">transient</A>.</code> 
  523. The transient dictionary is in the heap memory, definitions defined here won't 
  524. use dictionary space in the target application.  So it might be useful to do: 
  525. <p><pre>  transient</pre><p>
  526. <p><pre>    fload assembler</pre><p>
  527. <p><pre>    fload debugger</pre><p>
  528. <p><pre>  resident</pre><p>
  529. <p><pre>    fload myapplication</pre><p>
  530. Now the debugger and assembler will be in transient address space.  To remove 
  531. all links, pointers etc.  into the transient address space use <code><A href="_smal_AO#1BE">dispose</A>,</code> 
  532. it will do this for you.  <code><A href="_smal_AX#D7">.dispose</A></code> will 
  533. also give some informations what is removed while executing <code><A href="_smal_AO#1BE">dispose</A>.</code> 
  534. <p>
  535. </body>
  536. </html>
  537.