beautypg.com

8 self-modifying scripts code, Figure7.8 self-modifying code, Self-modifying scripts code – Avago Technologies LSI53C1010 User Manual

Page 177: Self-modifying code

background image

Patching

7-11

If the first Dword of an instruction is being accessed, a Read-Modify-
Write instruction may need to be done to maintain the opcode.

See

Chapter 5, “The NASM Output File,”

for more information on the

Ent_offsets

.

7.2.8 Self-Modifying SCRIPTS Code

It is sometimes necessary to create self-modifying SCRIPTS code. When
creating self-modifying SCRIPTS code it should be done in such a way
that external patching is only necessary at initialization time.
Self-modifying code can be accomplished by using either a Memory-to-
Memory Move instruction or a combination of LOAD and STORE
instructions. The SCRIPTS example in

Figure 7.8

shows a Memory-to-

Memory Move modifying a Move Register instruction such that an offset
can be added to a base address for jumping into a table.

Figure 7.8

Self-Modifying Code

Patches to the SCRIPTS Instruction may be needed. Patch the Labels in
the Memory-to-Memory Move instructions first:

for (i=0; i

SCRIPT[LABELPATCHES[i]] += VirttoPhys(SCRIPT);

}

Next patch Scratch register physical addresses:

ENTRY Patch_label1
ENTRY Patch_label2
EXTERN SCRATCHA1_addr
EXTERN SCRATCHB_addr
MOVE MEMORY 4, Patch_label2+4, SCRATCHB_addr
MOVE MEMORY 1, SCRATCHA1_addr, Patch_label1+1
Patch_label1:
MOVE SCRATCHB0 + 0 to SCRATCHB0
MOVE SCRATCHB1 + 0 to SCRATCHB1 WITH CARRY
MOVE SCRATCHB2 + 0 to SCRATCHB2 WITH CARRY
MOVE SCRATCHB3 + 0 to SCRATCHB3 WITH CARRY
MOVE MEMORY 4, SCRATCHB_addr, Patch_label2+4
Patch_label2:
JUMP REL(Jump_Table)

.
.

Jump_Table:

This manual is related to the following products: