CAMBIOS PRIMARIOS CAMBIOS SECUNDARIOS
1.2.4 Desarrollo psicológico del adolescente
A number of existing transputer C compilers were considered for DISTRIX. All compilers considered would have to be modified to do address transformation in programs running under DISTRIX. The best solution would have been to write a compiler for DISTRIX from
scratch, however, due to time and manpower constraints this was not possible. Instead, a C cross-compiler, assembler and linker including the programs source were obtained from Logical Systems [Logic88a].
The compiler was then modified to perform address transformation. This did, however, prove to be a fairly difficult task as the C compiler is a 20,000 line program for which no implementation details were available.
B.6.1 Adjustment Strategy
The address transformation mechanism used was the single segment, software segmenta-tion method described in the proceeding secsegmenta-tion. The start of code was defined as the base'. The actual value of base is obtained by loading a pointer to an instruction using the ldpi transputer instruction (as was seen in the code segments above).
A variable called __ base __ was defined in the compiler to represent base. The declara-tion of __ base __ is placed in the library1. The Logical Systems linker groups sections of code, in order, according to a segment number. To ensure that __ base __ is placed at the start of code it is placed in segment 0 and the rest of the code is grouped in segment 1 by the compiler.
As compilation occurs additional code is generated to do address transformation. Code is generated to add the value of __ base __ to all pointers before they are used to access memory. The value of __ base __ is also subtracted from all absolute addresses calculated and stored by the compiler.
B.6.2 The Abstract Syntax Tree
Most modifications done to the compiler were done at the abstract syntax tree level. This is mainly due to the fact that we had no documentation or description of the compiler ,code 'diversions' used by Logical Systems compiler during code generation.
The modifications took the form of a slight adjustment of the abstract syntax tree.
The first change involved an adjustment to an array pointer (see figure B.1). Since an array is an absolute address, the value of __ base __ is subtracted to convert it to a virtual address. In figure B.2, the second change is illustrated. The indirection operator indicates that a pointer is about to be used and as a result the value of __ base __ is added. In
1Note, __ base __ is an address and no data is specifically stored at that address.
100
0
Figure B.1: Conversion of arrays.
Figure B.2: Conversion of a virtual address to a physical address.
Figure B.3: Conversion of a physical address to virtual address.
the illustration x represents the operations that actually loads the address. In the third . . change (figure B.3) the address operator, &, loads an absolute address, so an adjustment
is made to convert this to a virtual address.
B.6.3 Procedure Calls
When a function is called, the transputer call instruction places the return address on the stack. The return address is, of course, absolute and must therefore be adjusted. The compiler was changed to add code to the start of every function to load the return address, subtract the value of __ base __ and store it. Later, when a function returns the value of __ base __ is added to the return address before it is used to return control to the calling code.
This may seem like a pointless exercise, but consider a child process that has just been created: if the return addresses on its stack have not been adjusted all of the return addresses refer to the parent's code! As a result, when a function returns, the child would suddenly start executing the parent's program.
B.6.4 Memory Allocation
One of the major problems with the Logical Systems compiler is that of memory usage.
The abstract syntax tree and code generation methods all use large amounts of computer memory. This is one reason why the Logical Systems compiler is still a
cross-compiler-it is too large to compile itself.
I
The Logical Systems compiler is compiled under DOS using the MSC (Microsoft C) compiler. A program compiled by MSC is allowed a maximum heap of 64K. The Logical Systems compiler allocates all the memory used to store the abstract syntax tree from the heap. The adjustments made to the compiler increased the size of the abstract syntax tree by a large amount. As a result, the new LSC compiler soon ran out of memory even when compiling small programs. To solve this problem additional memory was allocated from large statically declared buffers.