OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [or1ksim/] [cpu/] [or32/] [dyn_rec_stubs.c] - Diff between revs 1572 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1572 Rev 1765
/* dyn_rec_stubs.c -- Stubs to allow the recompiler to be run standalone
/* dyn_rec_stubs.c -- Stubs to allow the recompiler to be run standalone
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
 
 
This file is part of OpenRISC 1000 Architectural Simulator.
This file is part of OpenRISC 1000 Architectural Simulator.
 
 
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
 
 
/* Stubs to test the recompiler */
/* Stubs to test the recompiler */
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <errno.h>
#include <errno.h>
#include <byteswap.h>
#include <byteswap.h>
#include <stdlib.h>
#include <stdlib.h>
#include <inttypes.h>
#include <inttypes.h>
 
 
#include "arch.h"
#include "arch.h"
#include "immu.h"
#include "immu.h"
#include "spr_defs.h"
#include "spr_defs.h"
#include "opcode/or32.h"
#include "opcode/or32.h"
#include "abstract.h"
#include "abstract.h"
#include "execute.h"
#include "execute.h"
#include "sim-config.h"
#include "sim-config.h"
#include "sched.h"
#include "sched.h"
 
 
#include "i386_regs.h"
#include "i386_regs.h"
#include "dyn_rec.h"
#include "dyn_rec.h"
 
 
#define PAGE_LEN 8192
#define PAGE_LEN 8192
 
 
int do_stats = 0;
int do_stats = 0;
 
 
/* NOTE: Directly copied from execute.c */
/* NOTE: Directly copied from execute.c */
uorreg_t eval_operand_val(uint32_t insn, struct insn_op_struct *opd)
uorreg_t eval_operand_val(uint32_t insn, struct insn_op_struct *opd)
{
{
  unsigned long operand = 0;
  unsigned long operand = 0;
  unsigned long sbit;
  unsigned long sbit;
  unsigned int nbits = 0;
  unsigned int nbits = 0;
 
 
  while(1) {
  while(1) {
    operand |= ((insn >> (opd->type & OPTYPE_SHR)) & ((1 << opd->data) - 1)) << nbits;
    operand |= ((insn >> (opd->type & OPTYPE_SHR)) & ((1 << opd->data) - 1)) << nbits;
    nbits += opd->data;
    nbits += opd->data;
 
 
    if(opd->type & OPTYPE_OP)
    if(opd->type & OPTYPE_OP)
      break;
      break;
    opd++;
    opd++;
  }
  }
 
 
  if(opd->type & OPTYPE_SIG) {
  if(opd->type & OPTYPE_SIG) {
    sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
    sbit = (opd->type & OPTYPE_SBIT) >> OPTYPE_SBIT_SHR;
    if(operand & (1 << sbit)) operand |= ~REG_C(0) << sbit;
    if(operand & (1 << sbit)) operand |= ~REG_C(0) << sbit;
  }
  }
 
 
  return operand;
  return operand;
}
}
 
 
oraddr_t immu_translate(oraddr_t virtaddr)
oraddr_t immu_translate(oraddr_t virtaddr)
{
{
  return virtaddr;
  return virtaddr;
}
}
 
 
oraddr_t peek_into_itlb(oraddr_t virtaddr)
oraddr_t peek_into_itlb(oraddr_t virtaddr)
{
{
  return virtaddr;
  return virtaddr;
}
}
 
 
void do_scheduler()
void do_scheduler()
{
{
  return;
  return;
}
}
 
 
static uint32_t page[PAGE_LEN / 4];
static uint32_t page[PAGE_LEN / 4];
 
 
uint32_t eval_insn(oraddr_t addr, int *brkp)
uint32_t eval_insn(oraddr_t addr, int *brkp)
{
{
  if(addr >= PAGE_LEN) {
  if(addr >= PAGE_LEN) {
    fprintf(stderr, "DR is trying to access memory outside the boundries of a page %08x\n", addr);
    fprintf(stderr, "DR is trying to access memory outside the boundries of a page %08x\n", addr);
    return 0;
    return 0;
  }
  }
 
 
  return bswap_32(page[addr / 4]);
  return bswap_32(page[addr / 4]);
}
}
 
 
int main(int argc, char **argv)
int main(int argc, char **argv)
{
{
  FILE *f;
  FILE *f;
  long len;
  long len;
  int i;
  int i;
  struct dyn_page *dp;
  struct dyn_page *dp;
  long off = 0;
  long off = 0;
 
 
  if((argc < 3) || (argc > 4)) {
  if((argc < 3) || (argc > 4)) {
    fprintf(stderr, "Usage: %s <binary file to recompile> <output code file> [offset into the file]\n",
    fprintf(stderr, "Usage: %s <binary file to recompile> <output code file> [offset into the file]\n",
            argv[0]);
            argv[0]);
    return 1;
    return 1;
  }
  }
 
 
  if(argc == 4)
  if(argc == 4)
    off = strtol(argv[3], NULL, 0);
    off = strtol(argv[3], NULL, 0);
 
 
  f = fopen(argv[1], "r");
  f = fopen(argv[1], "r");
  if(!f) {
  if(!f) {
    fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
    fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
    return 1;
    return 1;
  }
  }
 
 
  if(fseek(f, 0, SEEK_END)) {
  if(fseek(f, 0, SEEK_END)) {
    fprintf(stderr, "Uanble to seek to the end of the file %s: %s\n", argv[1],
    fprintf(stderr, "Uanble to seek to the end of the file %s: %s\n", argv[1],
            strerror(errno));
            strerror(errno));
    return 1;
    return 1;
  }
  }
 
 
  len = ftell(f);
  len = ftell(f);
 
 
  if(len == -1) {
  if(len == -1) {
    fprintf(stderr, "Unable to determine file length: %s\n", strerror(errno));
    fprintf(stderr, "Unable to determine file length: %s\n", strerror(errno));
    return 1;
    return 1;
  }
  }
 
 
  fseek(f, off, SEEK_SET);
  fseek(f, off, SEEK_SET);
 
 
  if((len - off) < PAGE_LEN) {
  if((len - off) < PAGE_LEN) {
    printf("File is less than 1 page long, padding with zeros.\n");
    printf("File is less than 1 page long, padding with zeros.\n");
    fread(page, len, 1, f);
    fread(page, len, 1, f);
    /* Pad the page with zeros */
    /* Pad the page with zeros */
    for(i = len; i < PAGE_LEN; i++)
    for(i = len; i < PAGE_LEN; i++)
      page[i] = 0;
      page[i] = 0;
  } else
  } else
    fread(page, PAGE_LEN, 1, f);
    fread(page, PAGE_LEN, 1, f);
 
 
  fclose(f);
  fclose(f);
 
 
  build_automata();
  build_automata();
  init_dyn_recomp();
  init_dyn_recomp();
 
 
  dp = new_dp(0);
  dp = new_dp(0);
 
 
  /* Cool, recompile the page */
  /* Cool, recompile the page */
  fprintf(stderr, "Hold on a sec, I'm recompileing the given page...\n");
  fprintf(stderr, "Hold on a sec, I'm recompileing the given page...\n");
 
 
  recompile_page(dp);
  recompile_page(dp);
 
 
  fprintf(stderr, "Recompiled page length: %i\n", dp->host_len);
  fprintf(stderr, "Recompiled page length: %i\n", dp->host_len);
  fprintf(stderr, "Recompiled to: %p\n", dp->host_page);
  fprintf(stderr, "Recompiled to: %p\n", dp->host_page);
  fprintf(stderr, "Dumping reced page to disk...\n");
  fprintf(stderr, "Dumping reced page to disk...\n");
 
 
  f = fopen(argv[2], "w");
  f = fopen(argv[2], "w");
  fwrite(dp->host_page, dp->host_len, 1, f);
  fwrite(dp->host_page, dp->host_len, 1, f);
  fclose(f);
  fclose(f);
 
 
/*
/*
  printf("--- Recompiled or disassembly ---\n");
  printf("--- Recompiled or disassembly ---\n");
  for(i = 0; i < 2048; i++) {
  for(i = 0; i < 2048; i++) {
    extern char *disassembled;
    extern char *disassembled;
    disassemble_insn(eval_insn(i * 4, NULL));
    disassemble_insn(eval_insn(i * 4, NULL));
    if(!eval_insn(i * 4, NULL)) continue;
    if(!eval_insn(i * 4, NULL)) continue;
    printf("%04x: %08x %s\n", i * 4, eval_insn(i * 4, NULL), disassembled);
    printf("%04x: %08x %s\n", i * 4, eval_insn(i * 4, NULL), disassembled);
  }
  }
  printf("--- Recompiled or disassembly end ---\n");
  printf("--- Recompiled or disassembly end ---\n");
*/
*/
 
 
  printf("--- Recompiled offsets ---\n");
  printf("--- Recompiled offsets ---\n");
  for(i = 0; i < (PAGE_LEN / 4); i++)
  for(i = 0; i < (PAGE_LEN / 4); i++)
    printf("%"PRIxADDR": %x\n", i * 4, dp->locs[i] - dp->host_page);
    printf("%"PRIxADDR": %x\n", i * 4, dp->locs[i] - dp->host_page);
  printf("--- Recompiled offsets end ---\n");
  printf("--- Recompiled offsets end ---\n");
  destruct_automata();
  destruct_automata();
 
 
  return 0;
  return 0;
}
}
 
 
/* Lame linker stubs.  These are only referenced in the recompiled code */
/* Lame linker stubs.  These are only referenced in the recompiled code */
struct cpu_state cpu_state;
struct cpu_state cpu_state;
struct runtime runtime;
struct runtime runtime;
struct scheduler_struct scheduler;
struct scheduler_struct scheduler;
struct config config;
struct config config;
int immu_ex_from_insn;
int immu_ex_from_insn;
 
 
/* FIXME: eval_insn should become this */
/* FIXME: eval_insn should become this */
uint32_t eval_insn_direct(oraddr_t memaddr, int through_mmu)
uint32_t eval_insn_direct(oraddr_t memaddr, int through_mmu)
{
{
  return 0;
  return 0;
}
}
 
 
uint32_t eval_direct32(oraddr_t memaddr, int through_mmu, int through_dc)
uint32_t eval_direct32(oraddr_t memaddr, int through_mmu, int through_dc)
{
{
  return 0;
  return 0;
}
}
 
 
uint32_t eval_mem32(oraddr_t addr, int *breakpoint)
uint32_t eval_mem32(oraddr_t addr, int *breakpoint)
{
{
  return 0;
  return 0;
}
}
 
 
uint16_t eval_mem16(oraddr_t addr, int *breakpoint)
uint16_t eval_mem16(oraddr_t addr, int *breakpoint)
{
{
  return 0;
  return 0;
}
}
 
 
uint8_t eval_mem8(oraddr_t addr, int *breakpoint)
uint8_t eval_mem8(oraddr_t addr, int *breakpoint)
{
{
  return 0;
  return 0;
}
}
 
 
void set_mem32(oraddr_t addr, uint32_t val, int *breakpoint)
void set_mem32(oraddr_t addr, uint32_t val, int *breakpoint)
{
{
}
}
 
 
void set_mem16(oraddr_t addr, uint16_t val, int *breakpoint)
void set_mem16(oraddr_t addr, uint16_t val, int *breakpoint)
{
{
}
}
 
 
void set_mem8(oraddr_t addr, uint8_t val, int *breakpoint)
void set_mem8(oraddr_t addr, uint8_t val, int *breakpoint)
{
{
}
}
 
 
void analysis(struct iqueue_entry *current)
void analysis(struct iqueue_entry *current)
{
{
}
}
 
 
void mtspr(uint16_t regno, const uorreg_t value)
void mtspr(uint16_t regno, const uorreg_t value)
{
{
}
}
 
 
unsigned long spr_read_ttcr(void)
unsigned long spr_read_ttcr(void)
{
{
  return 0;
  return 0;
}
}
 
 
void debug(int level, const char *format,...)
void debug(int level, const char *format,...)
{
{
}
}
 
 
void simprintf(oraddr_t stackaddr, unsigned long regparam)
void simprintf(oraddr_t stackaddr, unsigned long regparam)
{
{
}
}
 
 
const char *except_name(oraddr_t except)
const char *except_name(oraddr_t except)
{
{
  return NULL;
  return NULL;
}
}
 
 
uorreg_t mfspr(const uint16_t regno)
uorreg_t mfspr(const uint16_t regno)
{
{
  return 0;
  return 0;
}
}
 
 
static struct dev_memarea dummy_area = {
static struct dev_memarea dummy_area = {
 ops: { delayr: 1 },
 ops: { delayr: 1 },
};
};
 
 
struct dev_memarea *verify_memoryarea(oraddr_t addr)
struct dev_memarea *verify_memoryarea(oraddr_t addr)
{
{
  return &dummy_area;
  return &dummy_area;
}
}
 
 
void sim_done (void)
void sim_done (void)
{
{
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.