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 *
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. *
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. *
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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
#include "../recomp.h"
27
#include "../macros.h"
29
#include "../recomph.h"
31
extern int dynarec_stack_initialized; /* in gr4300.c */
41
if (PC->reg_cache_infos.need_map)
42
*return_address = (unsigned long) (PC->reg_cache_infos.jump_wrapper);
44
*return_address = (unsigned long) (actual->code + PC->local_addr);
47
static long save_rsp = 0;
48
static long save_rip = 0;
50
void dyna_start(void (*code)())
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 */
64
(" push %%rbx \n" /* we must push an even # of registers to keep stack 16-byte aligned */
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 */
76
" mov %%rax, _save_rip(%%rip) \n"
79
" mov _save_rsp(%%rip), %%rsp \n"
91
/* Linux and other unix variants do not use underscores */
93
(" push %%rbx \n" /* we must push an even # of registers to keep stack 16-byte aligned */
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 */
105
" mov %%rax, save_rip(%%rip) \n"
108
" mov save_rsp(%%rip), %%rsp \n"
121
/* for non-PIC binaries (this is normally not used, because the core is always compiled as a shared library) */
123
(" push %%rbx \n" /* we must push an even # of registers to keep stack 16-byte aligned */
129
" mov %%rsp, save_rsp \n"
130
" lea reg, %%r15 \n" /* store the base location of the r4300 registers in r15 for addressing */
135
" mov %%rax, save_rip \n"
138
" mov save_rsp, %%rsp \n"
152
/* clear flag; stack is back to normal */
153
dynarec_stack_initialized = 0;
155
/* clear the registers so we don't return here a second time; that would be a bug */
163
printf("Warning: instruction pointer is 0 at dyna_stop()\n");
166
*return_address = (unsigned long) save_rip;