annotate trans.c @ 1021:4a92889e2889 v0.4.0

Fix OS X build
author Michael Pavone <pavone@retrodev.com>
date Wed, 04 May 2016 00:50:20 -0700
parents 124a58fdcf3a
children 2ec5e6eaf81d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 440
diff changeset
1 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 440
diff changeset
2 Copyright 2013 Michael Pavone
567
8e395210f50f Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
3 This file is part of BlastEm.
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 440
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 440
diff changeset
5 */
18
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "68kinst.h"
569
9b7fcf748be0 Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents: 567
diff changeset
7 #include "m68k_core.h"
18
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "mem.h"
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 #include <stdio.h>
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 #include <stdlib.h>
440
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
11 #include <string.h>
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
12
836
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
13 int headless = 1;
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
14 void render_errorbox(char * title, char * buf)
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
15 {
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
16 }
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
17
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
18 void render_infobox(char * title, char * buf)
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
19 {
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
20 }
124a58fdcf3a Get trans program compiling again
Michael Pavone <pavone@retrodev.com>
parents: 709
diff changeset
21
440
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
22 m68k_context * sync_components(m68k_context * context, uint32_t address)
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
23 {
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
24 if (context->current_cycle > 0x80000000) {
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
25 context->current_cycle -= 0x80000000;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
26 }
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
27 return context;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
28 }
18
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 int main(int argc, char ** argv)
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 {
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 long filesize;
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 unsigned short *filebuf;
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 char disbuf[1024];
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 unsigned short * cur;
569
9b7fcf748be0 Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents: 567
diff changeset
36 m68k_options opts;
18
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 FILE * f = fopen(argv[1], "rb");
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 fseek(f, 0, SEEK_END);
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 filesize = ftell(f);
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 fseek(f, 0, SEEK_SET);
572
0f32f52fc98e Make some small changes in trans so that it is more likely to produce the same output as mustrans when given misbehaving programs. Add lea to testcases.txt. Improve the output of comparetest.py so that known issues can easily be separated from new ones.
Michael Pavone <pavone@retrodev.com>
parents: 570
diff changeset
41 filebuf = malloc(0x400000);
0f32f52fc98e Make some small changes in trans so that it is more likely to produce the same output as mustrans when given misbehaving programs. Add lea to testcases.txt. Improve the output of comparetest.py so that known issues can easily be separated from new ones.
Michael Pavone <pavone@retrodev.com>
parents: 570
diff changeset
42 memset(filebuf, 0, 0x400000);
0f32f52fc98e Make some small changes in trans so that it is more likely to produce the same output as mustrans when given misbehaving programs. Add lea to testcases.txt. Improve the output of comparetest.py so that known issues can easily be separated from new ones.
Michael Pavone <pavone@retrodev.com>
parents: 570
diff changeset
43 fread(filebuf, 2, filesize/2 > 0x200000 ? 0x200000 : filesize/2, f);
18
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 fclose(f);
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 for(cur = filebuf; cur - filebuf < (filesize/2); ++cur)
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
46 {
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 *cur = (*cur >> 8) | (*cur << 8);
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 }
440
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
49 memmap_chunk memmap[2];
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
50 memset(memmap, 0, sizeof(memmap_chunk)*2);
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
51 memmap[0].end = 0x400000;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
52 memmap[0].mask = 0xFFFFFF;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
53 memmap[0].flags = MMAP_READ;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
54 memmap[0].buffer = filebuf;
567
8e395210f50f Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents: 467
diff changeset
55
440
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
56 memmap[1].start = 0xE00000;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
57 memmap[1].end = 0x1000000;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
58 memmap[1].mask = 0xFFFF;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
59 memmap[1].flags = MMAP_READ | MMAP_WRITE | MMAP_CODE;
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
60 memmap[1].buffer = malloc(64 * 1024);
572
0f32f52fc98e Make some small changes in trans so that it is more likely to produce the same output as mustrans when given misbehaving programs. Add lea to testcases.txt. Improve the output of comparetest.py so that known issues can easily be separated from new ones.
Michael Pavone <pavone@retrodev.com>
parents: 570
diff changeset
61 memset(memmap[1].buffer, 0, 64 * 1024);
709
3f065c20423c Fix trans so it compiles again
Michael Pavone <pavone@retrodev.com>
parents: 572
diff changeset
62 init_m68k_opts(&opts, memmap, 2, 1);
3f065c20423c Fix trans so it compiles again
Michael Pavone <pavone@retrodev.com>
parents: 572
diff changeset
63 m68k_context * context = init_68k_context(&opts);
3f065c20423c Fix trans so it compiles again
Michael Pavone <pavone@retrodev.com>
parents: 572
diff changeset
64 context->mem_pointers[0] = memmap[0].buffer;
3f065c20423c Fix trans so it compiles again
Michael Pavone <pavone@retrodev.com>
parents: 572
diff changeset
65 context->mem_pointers[1] = memmap[1].buffer;
3f065c20423c Fix trans so it compiles again
Michael Pavone <pavone@retrodev.com>
parents: 572
diff changeset
66 context->target_cycle = context->sync_cycle = 0x80000000;
212
e657a99b5abf Fixed up trans for changes to translate_m68k_stream, but still need to deal with missing callbacks.
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
67 uint32_t address;
e657a99b5abf Fixed up trans for changes to translate_m68k_stream, but still need to deal with missing callbacks.
Mike Pavone <pavone@retrodev.com>
parents: 19
diff changeset
68 address = filebuf[2] << 16 | filebuf[3];
709
3f065c20423c Fix trans so it compiles again
Michael Pavone <pavone@retrodev.com>
parents: 572
diff changeset
69 translate_m68k_stream(address, context);
3f065c20423c Fix trans so it compiles again
Michael Pavone <pavone@retrodev.com>
parents: 572
diff changeset
70 m68k_reset(context);
18
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 return 0;
3e7bfde7606e M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 }
440
306986209cba Fix 68K test harness
Mike Pavone <pavone@retrodev.com>
parents: 212
diff changeset
73