/[gxemul]/trunk/src/native/THOUGHTS_AND_IDEAS
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/src/native/THOUGHTS_AND_IDEAS

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (show annotations)
Mon Oct 8 16:21:53 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 3738 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1515 2007/04/14 05:39:46 debug Exp $
20070324	Adding a "--debug" option to the configure script, to disable
		optimizations in unstable development builds.
		Moving out SCSI-specific stuff from diskimage.c into a new
		diskimage_scsicmd.c.
		Applying Hĺvard Eidnes' patch for SCSICDROM_READ_DISKINFO and
		SCSICDROM_READ_TRACKINFO. (Not really tested yet.)
		Implementing disk image "overlays" (to allow simple roll-back
		to previous disk state). Adding a 'V' disk flag for this, and
		updating the man page and misc.html.
20070325	Stability fix to cpu_dyntrans.c, when multiple physical pages
		share the same initial table entry. (The ppp == NULL check
		should be physpage_ofs == 0.) Bug found by analysing GXemul
		against a version patched for Godson.
		Fixing a second occurance of the same problem (also in
		cpu_dyntrans.c).
		Fixing a MAJOR physical page leak in cpu_dyntrans.c; pages
		weren't _added_ to the set of translated pages, they _replaced_
		all previous pages. It's amazing that this bug has been able
		to live for this long. (Triggered when emulating >128MB RAM.)
20070326	Removing the GDB debugging stub support; it was too hackish
		and ugly.
20070328	Moving around some native code generation skeleton code.
20070329	The -lm check in the configure script now also checks for sin()
		in addition to sqrt(). (Thanks to Nigel Horne for noticing that
		sqrt was not enough on Fedora Core 6.) (Not verified yet.)
20070330	Fixing an indexing bug in dev_sh4.c, found by using gcc version
		4.3.0 20070323.
20070331	Some more experimentation with native code generation.
20070404	Attempting to fix some more SH4 SCIF interrupt bugs; rewriting
		the SH interrupt assertion/deassertion code somewhat.
20070410	Splitting src/file.c into separate files in src/file/.
		Cleanup: Removing the dummy TS7200, Walnut, PB1000, and
		Meshcube emulation modes, and dev_epcom and dev_au1x00.
		Removing the experimental CHIP8/RCA180x code; it wasn't really
		working much lately, anyway. It was fun while it lasted.
		Also removing the experimental Transputer CPU support.
20070412	Moving the section about how the dynamic translation system
		works from intro.html to a separate translation.html file.
		Minor SH fixes; attempting to get OpenBSD/landisk to run
		without randomly bugging out, but no success yet.
20070413	SH SCI (serial bit interface) should now work together with a
		(new) RS5C313 clock device (for Landisk emulation).
20070414	Moving Redhat/MIPS down from supported to experimental, in
		guestoses.html.
		Preparing for a new release; doing some regression testing etc.

==============  RELEASE 0.4.5  ==============


1 Random thoughts about native code generation, which will be compatible
2 with the already existing (non-host-specific) dyntrans core.
3
4
5 How to keep track of the number of times a basic block is executed?
6 (Perhaps needed, since unnecessary native code generation may slow things
7 down. Only the blocks that are really common need to be natively
8 translated.)
9
10 Perhaps having a small additional array per page is a solution?
11 unsigned char count[NR_OF_IC_ENTRIES_PER_PAGE];
12 For a typical MIPS cpu, that would be 1024 bytes extra per page.
13 The main loop could be changed to increase count, and if count goes beyond
14 a certain threshhold, the block is natively translated. Hm.
15
16 Or perhaps the overhead of implementing this counter check is more than it
17 is worth? After all, most of the time will be spent executing (some of)
18 the translated loops.
19
20 -------------------------------------
21
22 At most one [basic] block is ever translated at any given time.
23 A small array can hold the INR entries, and a small memory area can
24 hold a (double-linked list) of native instruction entries.
25
26 Simple instructions:
27
28 32-bit MIPS:
29 andi $5,$5,0xff00
30 ori $5,$5,0x0011
31
32 Intermediate native representation:
33 AND_REG32PTR_REG32PTR_IMM16 (offset to reg 5, offset to reg 5, 0xff00)
34 OR_REG32PTR_REG32PTR_IMM16 (offset to reg 5, offset to reg 5, 0x0011)
35
36 Non-peephole-optimized x86[_64] code: (esi = struct cpu *)
37 mov eax, [esi + offset_to_source_reg]
38 and eax, 0xff00
39 mov [esi + offset_to_destination_reg], eax (#1)
40 mov eax, [esi + offset_to_source_reg] (#2)
41 or eax, 0x0011
42 mov [esi + offset_to_destination_reg], eax
43
44 Peephole-optimized x86[_64] code:
45 (on the first pass, #2 is removed, since it loads back a value which was
46 previously written. the value is already in eax!)
47 (on the second pass, the store at #1 is removed, since another store
48 later on overwrites the same register)
49 mov eax, [esi + offset_to_source_reg]
50 and eax, 0xff00
51 or eax, 0x0011
52 mov [esi + offset_to_destination_reg], eax
53
54 Native code entry:
55 (none on x86_64)
56
57 Native code exit:
58 ret[q]
59
60 ---------------------------
61
62 Update of nr-of-executed-instructions and the IC pointer:
63
64 All possible return paths need to update the following:
65
66 x) The nr-of-executed-instructions count (one less than the
67 number of instructions in the translated block, since an
68 implicit count of 1 is already included).
69 x) The next_ic pointer, and also the cur_page if we have
70 switched page.
71
72 -----------------------------
73
74 Stages during translation:
75
76 Stage 1:
77 Emulated ISA (e.g. MIPS) to INR instructions.
78 Each emulated instruction may be turned into 0 or
79 more INR instructions.
80 This is done in e.g. src/cpus/cpu_mips_instr.c
81 using semi-magic macros.
82 The INR array is a fixed size small array, pointed
83 to by the cpu struct.
84
85 Stage 2:
86 INR -> native operations (e.g. x86).
87 This is done in src/native/native_x86.c.
88 Things to think about are round-robin use of
89 temporary registers.
90 native_inr_to_native_ops() takes a cpu as input,
91 translates the current INR entries into native
92 pseudo-opcodes.
93
94 Stage 3:
95 Optimization, native ops -> native ops.
96 This is done in src/native/native_x86_optim.c,
97 and is an optional step. It should be possible
98 to turn this step of, for debugging.
99 If e.g. a value is in a register, and it is stored
100 to memory, then the same memory position does not
101 have to be read back; the value is already in a
102 register.
103
104 Stage 4:
105 Code generation, native ops -> native machine code.
106 Done in src/native/native_x86_gen.c.
107
108 Stage 5:
109 Patch _older_ code chunks so that they can branch
110 directly to the new chunk, if possible.
111 An optional step.
112
113 Stage 6:
114 Enter the newly generated native code chunk into
115 the physpage' ic->f.

  ViewVC Help
Powered by ViewVC 1.1.26