annotate doc/internals.txt @ 448:5cccf90bf838 3.0 tip

Fixed bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Fri, 05 Nov 2010 22:27:00 -0600
parents 656630007668
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
1 LWASM Internals
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
2 ===============
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
3
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
4 LWASM is a table-driven assembler that notionally uses two passes. However,
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
5 it implements its assembly in several passes as follows.
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
6
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
7 Pass 1
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
8 ------
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
9
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
10 This pass reads the entire source code and parses each line into an internal
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
11 representation. Macros, file inclusions, and conditional assembly
363
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
12 instructions are resolved at this point as well. Instructions with known
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
13 sizes will have their sizes resolved at this point.
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
14
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
15 Pass 2
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
16 ------
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
17
363
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
18 Check all exported symbols for validity and set them as imports if the
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
19 assembler state says so. Also resolve all symbol references in all
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
20 expressions to be direct references either to the symbol table or
d96c30e60ddf Added pass2 and various supporting logic including symbol lookups
lost@starbug
parents: 338
diff changeset
21 to the import list.
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
22
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
23 Pass 3
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
24 ------
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
25
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
26 This pass resolves all instruction sizes that can be resolved without
365
6a98cc90c14f Added resolve passes
lost@starbug
parents: 363
diff changeset
27 forcing any instruction sizes. This pass will run repeatedly until no
6a98cc90c14f Added resolve passes
lost@starbug
parents: 363
diff changeset
28 no new resolution occurs.
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
29
333
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
30 Pass 4
ebff3a3e8fa6 Updated internals to describe the multi-pass architecture
lost
parents: 331
diff changeset
31 ------
331
ed3553296580 Port manual forward with corrections from Jason Law
lost
parents:
diff changeset
32
365
6a98cc90c14f Added resolve passes
lost@starbug
parents: 363
diff changeset
33 Work through all un-resolved instructions and force sizes. After each size
6a98cc90c14f Added resolve passes
lost@starbug
parents: 363
diff changeset
34 is forced, try re-resolving all other instructions. This is done starting
6a98cc90c14f Added resolve passes
lost@starbug
parents: 363
diff changeset
35 at the beginning of the source and working forward. If any instruction does
6a98cc90c14f Added resolve passes
lost@starbug
parents: 363
diff changeset
36 not resolve when forced, an error will be thrown.
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
37
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
38 Pass 5
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
39 ------
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
40
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
41 Constantize all line addresses and throw errors if any cannot be. This
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
42 pass will repeat until no further lines addresses are reduced to constants
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
43 at which time all lines will be checked for constant-ness.
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
44
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
45 Pass 6
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
46 ------
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
47
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
48 Finalize all expressions related to instructions. Carp about any that
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
49 cannot be reduced to a usable form. That means, for the non-object target
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
50 all expressions must resolve to a constant. For the object form, all
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
51 expressions must resolve to symbol references and constants. Those symbol
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 365
diff changeset
52 references may be internal or external.
368
656630007668 Emit pass
lost@starbug
parents: 367
diff changeset
53
656630007668 Emit pass
lost@starbug
parents: 367
diff changeset
54 Pass 7
656630007668 Emit pass
lost@starbug
parents: 367
diff changeset
55 ------
656630007668 Emit pass
lost@starbug
parents: 367
diff changeset
56
656630007668 Emit pass
lost@starbug
parents: 367
diff changeset
57 Emit object code for each line for later output.