View Single Post
Old 05-30-2012, 10:32 PM   #16
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default

Quote:
Originally Posted by Justin View Post
Very cool! I'm learning a lot reading this...

Unfortunately I think we'll need to do some more tweaks to the code calling the glue, to support storing the offset elsewhere (in a data block, perhaps), because this code:

...will try to execute the offset as an instruction (assuming the jump is not made), which would almost always be bad...
you are correct,
forgot about that - oops.

here is what can be done:

Code:
/* gas test program */

  .global  main
  .type  main, %function
main:
  stmfd  sp!, {lr}

  mov r0, #1
  /* check/set the zero flag */
  cmp r0, #0
  /* we call our conditional instruction
  offset #0 would mean the instruction at the pc (or in this case .word) */
  ldrne  pc, [pc, #0]
  /* but if we reach this point we simply update the pc
  which basically goes to ldmfd... or skips the .word */
  add pc, pc, #0
  .word 0xcafecafe

  ldmfd  sp!, {pc}
Code:
static const unsigned int GLUE_JMP_IF_P1_Z[]=
{
  0x059ff000,   // ldreq  pc, [pc, #0]
  0xe28ff000,   // add pc, pc, #0
  0x0           // offset goes here
};
static const unsigned int GLUE_JMP_IF_P1_NZ[]=
{
  0x159ff000,  // ldrne  pc, [pc, #0]
  0xe28ff000,  // add pc, pc, #0
  0x0          // offset goes here
};
https://github.com/neolit123/wdl/com...76905008557823

i'm hoping that it will be possible to write at GLUE_JMP_IF_P1_NZ[2], for example.
[edit] and also that the instruction after the "offset goes here" word will be callable ?

--

Last edited by liteon; 05-30-2012 at 10:57 PM.
liteon is offline   Reply With Quote