Branch: Tag:

2001-07-20

2001-07-20 16:21:32 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added {EN,DE}CODE_PROGRAM() to the pikecode API.

Rev: src/code/README.txt:1.3
Rev: src/code/sparc.c:1.3
Rev: src/code/sparc.h:1.4
Rev: src/encode.c:1.115

1:   /* -  * $Id: sparc.c,v 1.2 2001/07/20 13:16:49 grubba Exp $ +  * $Id: sparc.c,v 1.3 2001/07/20 16:21:32 grubba Exp $    *    * Machine code generator for sparc.    *
64:    ins_f_byte(a);    return;   } +  + #define addstr(s, l) low_my_binary_strcat((s), (l), buf) + #define adddata2(s,l) addstr((char *)(s),(l) * sizeof((s)[0])); +  + void sparc_encode_program(struct program *p, struct dynamic_buffer_s *buf) + { +  size_t prev = 0, rel; +  /* De-relocate the program... */ +  for (rel = 0; rel < p->num_relocations; rel++) { +  size_t off = p->relocations[rel]; +  INT32 opcode; + #ifdef PIKE_DEBUG +  if (off < prev) { +  fatal("Relocations in bad order!\n"); +  } + #endif /* PIKE_DEBUG */ +  adddata2(p->program + prev, off - prev); +  + #ifdef PIKE_DEBUG +  if ((p->program[off] & 0xc0000000) != 0x40000000) { +  fatal("Bad relocation!\n"); +  } + #endif /* PIKE_DEBUG */ +  /* Relocate to being relative to NULL */ +  opcode = 0x40000000 | +  ((p->program[off] + (((INT32)(p->program)>>2))) & 0x3fffffff); +  adddata2(&opcode, 1); +  prev = off+1; +  } +  adddata2(p->program + prev, p->num_program - prev); + } +  + void sparc_decode_program(struct program *p) + { +  /* Relocate the program... */ +  PIKE_OPCODE_T *prog = p->program; +  INT32 delta = ((INT32)p->program)>>2; +  size_t rel = p->num_relocations; +  while (rel--) { + #ifdef PIKE_DEBUG +  if ((prog[p->relocations[rel]] & 0xc0000000) != 0x40000000) { +  Pike_error("Bad relocation: %d, off:%d, opcode: 0x%08x\n", +  rel, p->relocations[rel], +  prog[p->relocations[rel]]); +  } + #endif /* PIKE_DEBUG */ +  prog[p->relocations[rel]] = 0x40000000 | +  (((prog[p->relocations[rel]] & 0x3fffffff) - delta) & +  0x3fffffff); +  } + #endif /* sparc */ + }