View Single Post
Old 05-31-2012, 04:34 AM   #18
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default

i didn't check previously how nseel-compiler.c writes the immediates into the bytes. this will certainly reduce the jump overhead (the 32mb limit though...).

the encoding looks similar to ppc (sign extension etc).
here is the "b" encoding info:

http://simplemachines.it/doc/arm_inst.pdf
(page 17, actually its 24bits..)

so for example, if we want to branch to the current offset where the b instruction is (e.g. at 1000), this would mean.

by specs:
encoded = (target_offset - pc) >> 2
e.g. (1000 - 1008) >> 2 = -8 >> 2 = -2 = 0xfffffffe(32bit) = 0xfffffe(24bit)

note: pc is current offset + 8 only on ARM mode, was + 4 on THUMB mode i think.

0xea - this is the non-conditional b opcode (11101010)
0xfffffe - immediate
0xeafffffe - result

Code:
static const unsigned char GLUE_JMP_NC[] =
{
  0xea, 0x0, 0x0, 0x0
};

static const unsigned char GLUE_JMP_IF_P1_Z[] =
{
  0x0a, 0x0, 0x0, 0x0
};

static const unsigned char GLUE_JMP_IF_P1_NZ[] =
{
  0x1a, 0x0, 0x0, 0x0
};

// (edit: 24 bit and needs cmp for the cond.)
--

Last edited by liteon; 06-01-2012 at 02:19 PM.
liteon is offline   Reply With Quote