~ubuntu-branches/ubuntu/wily/mupen64plus/wily

« back to all changes in this revision

Viewing changes to r4300/x86_64/rjump.c

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2011-07-24 14:23:26 UTC
  • mfrom: (10.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110724142326-x9z5qu8j9jecrmod
Tags: 1.99.4+2
* Upload to unstable
* Remove overrides for lintian warning about change to native package
* Update Vcs-* fields to new anonscm.debian.org URLs in debian/control
* Fix spelling of "Flexible" in debian/control (Closes: #633693)
* Mark all targets in debian/rules as phony
* Add some information about the mupen64plus 2.0 vision in debian/NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 
 *   Mupen64plus - rjump.c                                                 *
3
 
 *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
4
 
 *   Copyright (C) 2007 Richard Goedeken (Richard42)                       *
5
 
 *   Copyright (C) 2002 Hacktarux                                          *
6
 
 *                                                                         *
7
 
 *   This program is free software; you can redistribute it and/or modify  *
8
 
 *   it under the terms of the GNU General Public License as published by  *
9
 
 *   the Free Software Foundation; either version 2 of the License, or     *
10
 
 *   (at your option) any later version.                                   *
11
 
 *                                                                         *
12
 
 *   This program is distributed in the hope that it will be useful,       *
13
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 
 *   GNU General Public License for more details.                          *
16
 
 *                                                                         *
17
 
 *   You should have received a copy of the GNU General Public License     *
18
 
 *   along with this program; if not, write to the                         *
19
 
 *   Free Software Foundation, Inc.,                                       *
20
 
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
21
 
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22
 
 
23
 
#include <stdlib.h>
24
 
 
25
 
#include "../recomp.h"
26
 
#include "../r4300.h"
27
 
#include "../macros.h"
28
 
#include "../ops.h"
29
 
#include "../recomph.h"
30
 
 
31
 
extern int dynarec_stack_initialized;  /* in gr4300.c */
32
 
 
33
 
void dyna_jump()
34
 
{
35
 
    if (stop == 1)
36
 
    {
37
 
        dyna_stop();
38
 
        return;
39
 
    }
40
 
 
41
 
    if (PC->reg_cache_infos.need_map)
42
 
        *return_address = (unsigned long) (PC->reg_cache_infos.jump_wrapper);
43
 
    else
44
 
        *return_address = (unsigned long) (actual->code + PC->local_addr);
45
 
}
46
 
 
47
 
static long save_rsp = 0;
48
 
static long save_rip = 0;
49
 
 
50
 
void dyna_start(void (*code)())
51
 
{
52
 
  /* save the base and stack pointers */
53
 
  /* make a call and a pop to retrieve the instruction pointer and save it too */
54
 
  /* then call the code(), which should theoretically never return.  */
55
 
  /* When dyna_stop() sets the *return_address to the saved RIP, the emulator thread will come back here. */
56
 
  /* It will jump to label 2, restore the base and stack pointers, and exit this function */
57
 
  printf("R4300 core: starting 64-bit dynamic recompiler at: 0x%lx.\n", (unsigned long) code);
58
 
#if defined(__GNUC__) && defined(__x86_64__)
59
 
  #if defined(PIC) || defined(__PIE__) || defined(__pie__)
60
 
    /* for -fPIC (shared libraries) */
61
 
    #if defined(__APPLE__)
62
 
      /* OSX uses underscores before the symbols names in 64-bit PIC compilation */
63
 
      asm volatile
64
 
        (" push %%rbx           \n"  /* we must push an even # of registers to keep stack 16-byte aligned */
65
 
         " push %%r12           \n"
66
 
         " push %%r13           \n"
67
 
         " push %%r14           \n"
68
 
         " push %%r15           \n"
69
 
         " push %%rbp           \n"
70
 
         " mov  %%rsp, _save_rsp(%%rip) \n"
71
 
         " lea  _reg(%%rip), %%r15      \n" /* store the base location of the r4300 registers in r15 for addressing */
72
 
         " call 1f              \n"
73
 
         " jmp 2f               \n"
74
 
         "1:                    \n"
75
 
         " pop  %%rax           \n"
76
 
         " mov  %%rax, _save_rip(%%rip) \n"
77
 
         " call *%%rbx          \n"
78
 
         "2:                    \n"
79
 
         " mov  _save_rsp(%%rip), %%rsp \n"
80
 
         " pop  %%rbp           \n"
81
 
         " pop  %%r15           \n"
82
 
         " pop  %%r14           \n"
83
 
         " pop  %%r13           \n"
84
 
         " pop  %%r12           \n"
85
 
         " pop  %%rbx           \n"
86
 
         :
87
 
         : "b" (code)
88
 
         : "%rax", "memory"
89
 
         );
90
 
    #else
91
 
      /* Linux and other unix variants do not use underscores */
92
 
      asm volatile
93
 
        (" push %%rbx           \n"  /* we must push an even # of registers to keep stack 16-byte aligned */
94
 
         " push %%r12           \n"
95
 
         " push %%r13           \n"
96
 
         " push %%r14           \n"
97
 
         " push %%r15           \n"
98
 
         " push %%rbp           \n"
99
 
         " mov  %%rsp, save_rsp(%%rip) \n"
100
 
         " lea  reg(%%rip), %%r15      \n" /* store the base location of the r4300 registers in r15 for addressing */
101
 
         " call 1f              \n"
102
 
         " jmp 2f               \n"
103
 
         "1:                    \n"
104
 
         " pop  %%rax           \n"
105
 
         " mov  %%rax, save_rip(%%rip) \n"
106
 
         " call *%%rbx          \n"
107
 
         "2:                    \n"
108
 
         " mov  save_rsp(%%rip), %%rsp \n"
109
 
         " pop  %%rbp           \n"
110
 
         " pop  %%r15           \n"
111
 
         " pop  %%r14           \n"
112
 
         " pop  %%r13           \n"
113
 
         " pop  %%r12           \n"
114
 
         " pop  %%rbx           \n"
115
 
         :
116
 
         : "b" (code)
117
 
         : "%rax", "memory"
118
 
         );
119
 
      #endif
120
 
  #else
121
 
    /* for non-PIC binaries (this is normally not used, because the core is always compiled as a shared library) */
122
 
    asm volatile
123
 
      (" push %%rbx           \n"  /* we must push an even # of registers to keep stack 16-byte aligned */
124
 
       " push %%r12           \n"
125
 
       " push %%r13           \n"
126
 
       " push %%r14           \n"
127
 
       " push %%r15           \n"
128
 
       " push %%rbp           \n"
129
 
       " mov  %%rsp, save_rsp \n"
130
 
       " lea  reg, %%r15      \n" /* store the base location of the r4300 registers in r15 for addressing */
131
 
       " call 1f              \n"
132
 
       " jmp 2f               \n"
133
 
       "1:                    \n"
134
 
       " pop  %%rax           \n"
135
 
       " mov  %%rax, save_rip \n"
136
 
       " call *%%rbx          \n"
137
 
       "2:                    \n"
138
 
       " mov  save_rsp, %%rsp \n"
139
 
       " pop  %%rbp           \n"
140
 
       " pop  %%r15           \n"
141
 
       " pop  %%r14           \n"
142
 
       " pop  %%r13           \n"
143
 
       " pop  %%r12           \n"
144
 
       " pop  %%rbx           \n"
145
 
       :
146
 
       : "b" (code)
147
 
       : "%rax", "memory"
148
 
       );
149
 
  #endif
150
 
#endif
151
 
 
152
 
    /* clear flag; stack is back to normal */
153
 
    dynarec_stack_initialized = 0;
154
 
 
155
 
    /* clear the registers so we don't return here a second time; that would be a bug */
156
 
    save_rsp=0;
157
 
    save_rip=0;
158
 
}
159
 
 
160
 
void dyna_stop()
161
 
{
162
 
  if (save_rip == 0)
163
 
    printf("Warning: instruction pointer is 0 at dyna_stop()\n");
164
 
  else
165
 
  {
166
 
    *return_address = (unsigned long) save_rip;
167
 
  }
168
 
}
169