Re: A86: Re: New operating system...
[Prev][Next][Index][Thread]
Re: A86: Re: New operating system...
David Phillips wrote:
> You can't patch programs upon load, it's not possible!!! How do you know
> what's an address and what's data? You can't!
>
> ZShell programs had to patch themselves by calling a bunch of slow routines
> in the shell that added the program's address to the address they wanted to
> ...
> use any self modifying code! Self modifying code is such an important tool
> I'd never program for a shell or OS that didn't support it.
I didn't understand all of it, but I've made a TI compiler
that compiles DLLs. The method I use is to have a table (RT
- Relocation Table) at the begining of the DLL will all the
addresses in the DLL body that contained absolute addresses.
Then, at startup the DLL loader code load the DLL body into
the exec area (TI-86) and scanned the contents of addresses
in the RT adding to each the DLL start address. The code to
do this is (in my opinion and I'm not a 'big' z80 assembly
coder) rather small (105 bytes but can be further squeezed).
The main disavantadge is the size of the RT (a word for each
address that needs relocation).
The instruction
0000h ld hl, myvar
would force an RT entry with value 0001h, the addres where
the myvar's address is stored. DLLs are assembled with
.org 0h.
The assembler/compiler just has to keep track of each
absolute address usage (which I don't see any problem).
This allows self-modifying code.
When calling a DLL routine from the main program I use
a backpatch technic. A small routine (called a stub) is
created for each DLL routine used in the main program.
The stub as a code similar to the technic used in zshell,
but with a diference: the first time the stub is called
it will get the DLL routine's address and backpath the
caller. This consists in modify the caller's call
instruction replacing the stub's address by the real
routine's address. This way, there's no speed loss. But
of course, there's the size of the stub (5 bytes each,
including one byte to tell which is the DLL used) and the
backpatch code (55 bytes; if this routine is at a fixed
address then it is enough to have one for the entire
system; and of course, 55 bytes subject to further optim.).
If anyone is interested I can send here the manual's
section about DLLs, there's a better explanation there.
The only thing this method can't do (I would like it to)
is to allow a DLL routine to call another DLL routine in
ANOTHER DLL. However, just for normal program relocation
this doesn't matter.
NSJ aka Viriato
l41324@alfa.ist.utl.pt
nmasj@camoes.rnl.ist.utl.pt
http://camoes.rnl.ist.utl.pt/~nmasj - DemoAdict/TaradoPorDemos
References: