Mail Archives: djgpp/1995/08/01/02:15:39
>>>>> "nverever" == nverever <nverever AT ee> writes:
nverever> Ok, I'm writting a tight inline assembler function that
nverever> takes 3 parameters so far. The thing is, that one of
nverever> those parameters is a pointer in memory that is
nverever> allocated when the program is loaded first, but stays
nverever> constant after that. I was thinking that I could save
nverever> the time of passing the parameter if I wrote an
nverever> initialisation routine that would modify an inline
nverever> instruction such as "movl $0, %edx" and replace the
nverever> constant $0 with whatever the pointer is. Sounds
nverever> great,but I hit a problem I could of guessed should be
nverever> there, I get an exception fault when I try to modify the
nverever> opcode.
But if you do "movl $0,%edx", the assembler will generate only a 1
byte constant for the zero! You'd need something like "movl
$0x12345678,%edx".
nverever> I figure this is probably because the selector
nverever> in cs is read-only. If that is indeed the problem, I
nverever> know that it's possible to change the selector to
nverever> read/write and then back to read only with some dpmi
nverever> functions, but I don't have a dpmi server on my system
nverever> and I assume that most people don't either. Help on this
nverever> solution if it could work would be appreciated.
I don't think you need to do this. You're modifying the memory via
%ds, which is read/write. I'm pretty sure I've done exactly what you
are saying (I stuck constants for %ds into an interrupt handler movw).
nverever> Also, I heard that it's possible to make an array of
nverever> bytes and make the program execute those
nverever> instructions. If this is really so I could simply copy
nverever> the function into an array, modify the desired
nverever> instructions and call that new function. The only
nverever> problem, is that I don't know how to call that new
nverever> function if this can be done at all since it's in the
nverever> data selector, not the code selector.
Addresses for %ds and %cs are equivalent, since they overlap. The
68040 emulator our commercial Mac emulator uses dynamically generates
code in the data segment and runs it. I wrote that emulator, and it
works fine under djgpp (much better under V2 beta).
You can call such code simply by making a C function pointer that
points to it and call it. If you do it this way make sure you save
and restore registers preserved by the C calling convention.
-Mat
- Raw text -