1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: bintrans_i386.c,v 1.1 2005/08/29 14:36:41 debug Exp $ |
* $Id: bintrans_i386.c,v 1.3 2006/02/09 22:40:26 debug Exp $ |
29 |
* |
* |
30 |
* i386 specific code for dynamic binary translation. |
* i386 specific code for dynamic binary translation. |
31 |
* See bintrans.c for more information. Included from bintrans.c. |
* See bintrans.c for more information. Included from bintrans.c. |
64 |
#define ofs_tabl0 (((size_t)&dummy_cpu.cd.mips.vaddr_to_hostaddr_table0) - ((size_t)&dummy_cpu)) |
#define ofs_tabl0 (((size_t)&dummy_cpu.cd.mips.vaddr_to_hostaddr_table0) - ((size_t)&dummy_cpu)) |
65 |
#define ofs_chunks ((size_t)&dummy_vth32_table.bintrans_chunks[0] - (size_t)&dummy_vth32_table) |
#define ofs_chunks ((size_t)&dummy_vth32_table.bintrans_chunks[0] - (size_t)&dummy_vth32_table) |
66 |
#define ofs_chunkbase ((size_t)&dummy_cpu.cd.mips.chunk_base_address - (size_t)&dummy_cpu) |
#define ofs_chunkbase ((size_t)&dummy_cpu.cd.mips.chunk_base_address - (size_t)&dummy_cpu) |
67 |
#define ofs_h_l (((size_t)&dummy_cpu.cd.mips.host_load) - ((size_t)&dummy_cpu)) |
#define ofs_h_l (((size_t)&dummy_cpu.cd.mips.host_OLD_load) - ((size_t)&dummy_cpu)) |
68 |
#define ofs_h_s (((size_t)&dummy_cpu.cd.mips.host_store) - ((size_t)&dummy_cpu)) |
#define ofs_h_s (((size_t)&dummy_cpu.cd.mips.host_OLD_store) - ((size_t)&dummy_cpu)) |
69 |
|
|
70 |
|
|
71 |
static void (*bintrans_runchunk)(struct cpu *, unsigned char *); |
static void (*bintrans_runchunk)(struct cpu *, unsigned char *); |
1892 |
*a++ = 0xc1; *a++ = 0xeb; *a++ = 0x0c; /* shr $12, %ebx */ |
*a++ = 0xc1; *a++ = 0xeb; *a++ = 0x0c; /* shr $12, %ebx */ |
1893 |
|
|
1894 |
if (load) { |
if (load) { |
1895 |
/* ecx = cpu->cd.mips.host_load */ |
/* ecx = cpu->cd.mips.host_OLD_load */ |
1896 |
*a++ = 0x8b; *a++ = 0x8e; *a++ = ofs_h_l & 255; |
*a++ = 0x8b; *a++ = 0x8e; *a++ = ofs_h_l & 255; |
1897 |
*a++ = (ofs_h_l >> 8) & 255; |
*a++ = (ofs_h_l >> 8) & 255; |
1898 |
*a++ = (ofs_h_l >> 16) & 255; *a++ = (ofs_h_l >> 24) & 255; |
*a++ = (ofs_h_l >> 16) & 255; *a++ = (ofs_h_l >> 24) & 255; |
1899 |
} else { |
} else { |
1900 |
/* ecx = cpu->cd.mips.host_store */ |
/* ecx = cpu->cd.mips.host_OLD_store */ |
1901 |
*a++ = 0x8b; *a++ = 0x8e; *a++ = ofs_h_s & 255; |
*a++ = 0x8b; *a++ = 0x8e; *a++ = ofs_h_s & 255; |
1902 |
*a++ = (ofs_h_s >> 8) & 255; |
*a++ = (ofs_h_s >> 8) & 255; |
1903 |
*a++ = (ofs_h_s >> 16) & 255; *a++ = (ofs_h_s >> 24) & 255; |
*a++ = (ofs_h_s >> 16) & 255; *a++ = (ofs_h_s >> 24) & 255; |
1904 |
} |
} |
1905 |
|
|
1906 |
/* ecx = host_load[a] (or host_store[a]) */ |
/* ecx = host_OLD_load[a] (or host_OLD_store[a]) */ |
1907 |
*a++ = 0x8b; *a++ = 0x0c; *a++ = 0x99; /* mov (%ecx,%ebx,4),%ecx */ |
*a++ = 0x8b; *a++ = 0x0c; *a++ = 0x99; /* mov (%ecx,%ebx,4),%ecx */ |
1908 |
|
|
1909 |
/* |
/* |
2697 |
/* |
/* |
2698 |
* bintrans_backend_init(): |
* bintrans_backend_init(): |
2699 |
* |
* |
2700 |
* This is neccessary for broken GCC 2.x. (For GCC 3.x, this wouldn't be |
* This is necessary for broken GCC 2.x. (For GCC 3.x, this wouldn't be |
2701 |
* neccessary, and the old code would have worked.) |
* needed; the old code would have worked.) |
2702 |
*/ |
*/ |
2703 |
static void bintrans_backend_init(void) |
static void bintrans_backend_init(void) |
2704 |
{ |
{ |
2897 |
*p++ = 0x89; *p++ = 0xc3; /* mov %eax, %ebx */ |
*p++ = 0x89; *p++ = 0xc3; /* mov %eax, %ebx */ |
2898 |
*p++ = 0xc1; *p++ = 0xeb; *p++ = 0x0c; /* shr $12, %ebx */ |
*p++ = 0xc1; *p++ = 0xeb; *p++ = 0x0c; /* shr $12, %ebx */ |
2899 |
|
|
2900 |
/* ecx = cpu->cd.mips.host_load */ |
/* ecx = cpu->cd.mips.host_OLD_load */ |
2901 |
*p++ = 0x8b; *p++ = 0x8e; *p++ = ofs_h_l & 255; |
*p++ = 0x8b; *p++ = 0x8e; *p++ = ofs_h_l & 255; |
2902 |
*p++ = (ofs_h_l >> 8) & 255; |
*p++ = (ofs_h_l >> 8) & 255; |
2903 |
*p++ = (ofs_h_l >> 16) & 255; *p++ = (ofs_h_l >> 24) & 255; |
*p++ = (ofs_h_l >> 16) & 255; *p++ = (ofs_h_l >> 24) & 255; |
2904 |
|
|
2905 |
/* ecx = host_load[a] */ |
/* ecx = host_OLD_load[a] */ |
2906 |
*p++ = 0x8b; *p++ = 0x0c; *p++ = 0x99; /* mov (%ecx,%ebx,4),%ecx */ |
*p++ = 0x8b; *p++ = 0x0c; *p++ = 0x99; /* mov (%ecx,%ebx,4),%ecx */ |
2907 |
|
|
2908 |
/* ret */ |
/* ret */ |
2931 |
*p++ = 0x89; *p++ = 0xc3; /* mov %eax, %ebx */ |
*p++ = 0x89; *p++ = 0xc3; /* mov %eax, %ebx */ |
2932 |
*p++ = 0xc1; *p++ = 0xeb; *p++ = 0x0c; /* shr $12, %ebx */ |
*p++ = 0xc1; *p++ = 0xeb; *p++ = 0x0c; /* shr $12, %ebx */ |
2933 |
|
|
2934 |
/* ecx = cpu->cd.mips.host_store */ |
/* ecx = cpu->cd.mips.host_OLD_store */ |
2935 |
*p++ = 0x8b; *p++ = 0x8e; *p++ = ofs_h_s & 255; |
*p++ = 0x8b; *p++ = 0x8e; *p++ = ofs_h_s & 255; |
2936 |
*p++ = (ofs_h_s >> 8) & 255; |
*p++ = (ofs_h_s >> 8) & 255; |
2937 |
*p++ = (ofs_h_s >> 16) & 255; *p++ = (ofs_h_s >> 24) & 255; |
*p++ = (ofs_h_s >> 16) & 255; *p++ = (ofs_h_s >> 24) & 255; |
2938 |
|
|
2939 |
/* ecx = host_store[a] */ |
/* ecx = host_OLD_store[a] */ |
2940 |
*p++ = 0x8b; *p++ = 0x0c; *p++ = 0x99; /* mov (%ecx,%ebx,4),%ecx */ |
*p++ = 0x8b; *p++ = 0x0c; *p++ = 0x99; /* mov (%ecx,%ebx,4),%ecx */ |
2941 |
|
|
2942 |
/* ret */ |
/* ret */ |