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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [cpu/] [or32/] [dyngen-i386.c] - Blame information for rev 1748

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1748 jeremybenn
/* dyngen-i386.c -- i386 parts of dyngen
2
   Copyright (C) 2005 György `nog' Jeney, nog@sdf.lonestar.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
 
21
#include <stdio.h>
22
#include <stdint.h>
23
#include <stdlib.h>
24
 
25
#include <elf.h>
26
 
27
#include "dyngen.h"
28
 
29
#define RET_OPCODE 0xc3
30
 
31
unsigned int i386_get_real_func_len(void *f_start, unsigned int f_len, char *name)
32
{
33
  if(((uint8_t *)f_start)[f_len - 1] != RET_OPCODE) {
34
    fprintf(stderr, "`%s' does not have a ret at the end!\n", name);
35
    exit(1);
36
  }
37
 
38
  return f_len - 1;
39
}
40
 
41
void i386_gen_reloc(FILE *f, struct reloc *reloc, unsigned int param)
42
{
43
  switch(reloc->type) {
44
  case R_386_32:
45
    fprintf(f, "        *(uint32_t *)(host_page + %d) = *(ops_param + %u) + %d;\n",
46
            reloc->func_offset, param - 1, reloc->addend);
47
    break;
48
  default:
49
    fprintf(stderr, "Unknown i386 relocation: %i (%s)\n", reloc->type,
50
            reloc->name);
51
  }
52
}
53
 
54
void i386_gen_func_reloc(FILE *f, struct reloc *reloc)
55
{
56
  switch(reloc->type) {
57
  case R_386_32:
58
    /* This relocation is absolute.  There is nothing to relocate (The linker
59
     * handles this fine). */
60
    break;
61
  case R_386_PC32:
62
    fprintf(f, "        *(uint32_t *)(host_page + %d) = (uint32_t)((%s + %d) - (unsigned int)(host_page + %d));\n",
63
            reloc->func_offset, reloc->name, reloc->addend, reloc->func_offset);
64
    break;
65
  default:
66
    fprintf(stderr, "Unknown i386 relocation: %i (symbol: %s)\n", reloc->type,
67
            reloc->name);
68
  }
69
}
70
 
71
const struct archf archfs = {
72
  i386_get_real_func_len,
73
  i386_gen_reloc,
74
  i386_gen_func_reloc
75
};

powered by: WebSVN 2.1.0

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