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

Annotation of /trunk/experiments/new_test_x.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (hide annotations)
Mon Oct 8 16:18:27 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 3385 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.815 2005/06/27 23:04:35 debug Exp $
20050617	Experimenting some more with netbooting OpenBSD/sgi. Adding
		a hack which allows emulated ethernet networks to be
		distributed across multiple emulator processes.
20050618	Minor updates (documentation, dummy YAMON emulation, etc).
20050620	strcpy/strcat -> strlcpy/strlcat updates.
		Some more progress on evbmips (Malta).
20050621	Adding a section to doc/configfiles.html about ethernet
		emulation across multiple hosts.
		Beginning the work on the ARM translation engine (using the
		dynamic-but-not-binary translation method).
		Fixing a bintrans bug: 0x9fc00000 should always be treated as
		PROM area, just as 0xbfc00000 is.
		Minor progress on Malta emulation (the PCI-ISA bus).
20050622	NetBSD/evbmips can now be installed (using another emulated
		machine) and run (including userland and so on). :-)
		Spliting up the bintrans haddr_entry field into two (one for
		read, one for write). Probably not much of a speed increase,
		though.
		Updating some NetBSD 2.0 -> 2.0.2 in the documentation.
20050623	Minor updates (documentation, the TODO file, etc).
		gzipped kernels are now always automagically gunzipped when
		loaded.
20050624	Adding a dummy Playstation Portable (PSP) mode, just barely
		enough to run Hello World (in weird colors :-).
		Removing the -b command line option; old bintrans is enabled
		by default instead. It makes more sense.
		Trying to finally fix the non-working performance measurement
		thing (instr/second etc).
20050625	Continuing on the essential basics for ARM emulation. Two
		instructions seem to work, a branch and a simple "mov". (The
		mov arguments are not correct yet.) Performance is definitely
		reasonable.
		Various other minor updates.
		Adding the ARM "bl" instruction.
		Adding support for combining multiple ARM instructions into one
		function call. ("mov" + "mov" is the only one implemented so
		far, but it seems to work.)
		Cleaning up some IP32 interrupt things (crime/mace); disabling
		the PS/2 keyboard controller on IP32, so that NetBSD/sgimips
		boots into userland again.
20050626	Finally! NetBSD/sgimips netboots. Adding instructions to
		doc/guestoses.html on how to set up an nfs server etc.
		Various other minor fixes.
		Playstation Portable ".pbp" files can now be used directly.
		(The ELF part of the .pbp is extracted transparently.)
		Converting some sprintf -> snprintf.
		Adding some more instructions to the ARM disassembler.
20050627	More ARM updates. Adding some simple ldr(b), str(b),
		cmps, and conditional branch instructions, enough to run
		a simple Hello World program.
		All ARM instructions are now inlined/generated for all possible
		condition codes.
		Adding add and sub, and more load/store instructions.
		Removing dummy files: cpu_alpha.c, cpu_hppa.c, and cpu_sparc.c.
		Some minor documentation updates; preparing for a 0.3.4
		release. Updating some URLs.

==============  RELEASE 0.3.4  ==============


1 dpavlin 6 #include <stdio.h>
2     #include <stdlib.h>
3     #include <sys/types.h>
4     #include <sys/time.h>
5     #include <sys/resource.h>
6    
7 dpavlin 10 /* #define N_CALLS_PER_PAGE 1024 */
8     #define N_CALLS_PER_PAGE 128
9 dpavlin 6
10     #define MHZ 533
11    
12     struct cpu;
13    
14     struct instr_call {
15     void (*f)(struct cpu *cpu, struct instr_call *ic);
16 dpavlin 10 /* int instr_len; */
17 dpavlin 6 void *arg[3];
18     };
19    
20     struct cpu {
21     void *curpage;
22     int orig_nloops;
23     int nloops;
24    
25     struct instr_call *next_instr_call;
26     };
27    
28     void r(struct cpu *cpu)
29     {
30     struct instr_call *ic;
31    
32     for (;;) {
33     ic = cpu->next_instr_call++;
34     ic->f(cpu, ic);
35    
36     ic = cpu->next_instr_call++;
37     ic->f(cpu, ic);
38    
39     ic = cpu->next_instr_call++;
40     ic->f(cpu, ic);
41    
42     ic = cpu->next_instr_call++;
43     ic->f(cpu, ic);
44    
45     ic = cpu->next_instr_call++;
46     ic->f(cpu, ic);
47    
48     ic = cpu->next_instr_call++;
49     ic->f(cpu, ic);
50    
51     ic = cpu->next_instr_call++;
52     ic->f(cpu, ic);
53    
54     ic = cpu->next_instr_call++;
55     ic->f(cpu, ic);
56     }
57     }
58    
59    
60     void f_add(struct cpu *cpu, struct instr_call *ic)
61     {
62 dpavlin 10 #if 0
63     #if 0
64 dpavlin 6 int *a = (int *) ic->arg[0];
65     int *b = (int *) ic->arg[1];
66     int *c = (int *) ic->arg[2];
67    
68     *a = (*b) + (*c);
69 dpavlin 10 #else
70     int *a = (int *) ic->arg[0];
71     int *b = (int *) ic->arg[1];
72     int *c = (int *) ic->arg[2];
73     int *d, *e, *f;
74 dpavlin 6
75     ic = cpu->next_instr_call++;
76 dpavlin 10 d = (int *) ic->arg[0];
77     e = (int *) ic->arg[1];
78     f = (int *) ic->arg[2];
79 dpavlin 6
80     *a = (*b) + (*c);
81 dpavlin 10 *d = (*e) + (*f);
82 dpavlin 6 #endif
83 dpavlin 10 #endif
84 dpavlin 6 }
85    
86    
87     void f_sub(struct cpu *cpu, struct instr_call *ic)
88     {
89     int *a = (int *) ic->arg[0];
90     int *b = (int *) ic->arg[1];
91     int *c = (int *) ic->arg[2];
92     *a = (*b) - (*c);
93     }
94    
95    
96     void f_and(struct cpu *cpu, struct instr_call *ic)
97     {
98     int *a = (int *) ic->arg[0];
99     int *b = (int *) ic->arg[1];
100     int *c = (int *) ic->arg[2];
101     *a = (*b) & (*c);
102     }
103    
104    
105     void f_or(struct cpu *cpu, struct instr_call *ic)
106     {
107     int *a = (int *) ic->arg[0];
108     int *b = (int *) ic->arg[1];
109     int *c = (int *) ic->arg[2];
110     *a = (*b) | (*c);
111     }
112    
113    
114     void f_end(struct cpu *cpu, struct instr_call *ic)
115     {
116     struct rusage rusage;
117     double t, mips;
118    
119     cpu->nloops--;
120     if (cpu->nloops > 0) {
121     cpu->next_instr_call = cpu->curpage;
122     return;
123     }
124    
125     getrusage(RUSAGE_SELF, &rusage);
126     t = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec / 1000000.0;
127     mips = (float)(N_CALLS_PER_PAGE * cpu->orig_nloops) / t
128     / 1000000.0;
129    
130     printf("%.2f user seconds = %.1f MIPS. %.1f cycles/emulated "
131     "instruction on a %i MHz machine\n", (float)t, (float)mips,
132     (float)MHZ/mips, MHZ);
133     exit(1);
134     }
135    
136    
137     int main(int argc, char *argv[])
138     {
139     int32_t tmp_a, tmp_b, tmp_c;
140     struct instr_call *call_array;
141     int i, ncalls;
142     struct cpu *cpu = malloc(sizeof(struct cpu));
143    
144     if (argc <= 1) {
145     fprintf(stderr, "usage: %s n\n", argv[0]);
146     exit(1);
147     }
148    
149     cpu->orig_nloops = cpu->nloops = atoi(argv[1]);
150     ncalls = N_CALLS_PER_PAGE + 1;
151    
152     /* Fill a range of nonsense calls: */
153     call_array = malloc(sizeof(struct instr_call) * ncalls);
154     cpu->curpage = call_array;
155    
156     printf("ncalls = %i\n", ncalls);
157     for (i=0; i<ncalls; i++) {
158     if (i == ncalls-1) {
159     call_array[i].f = f_end;
160     } else {
161 dpavlin 10 #if 0
162 dpavlin 6 switch (i & 3) {
163     case 0: call_array[i].f = f_add;
164     case 1: call_array[i].f = f_sub;
165     case 2: call_array[i].f = f_and;
166     case 3: call_array[i].f = f_or;
167     }
168 dpavlin 10 #else
169     call_array[i].f = f_add;
170     #endif
171 dpavlin 6
172     call_array[i].arg[0] = &tmp_a;
173     call_array[i].arg[1] = &tmp_b;
174     call_array[i].arg[2] = &tmp_c;
175     }
176     }
177    
178     printf("running...\n");
179     cpu->next_instr_call = &call_array[0];
180     r(cpu);
181    
182     printf("ERROR!\n");
183     return 0;
184     }
185    

  ViewVC Help
Powered by ViewVC 1.1.26