/[gxemul]/trunk/src/cpus/cpu_mips16.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

Contents of /trunk/src/cpus/cpu_mips16.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 14 - (show annotations)
Mon Oct 8 16:18:51 2007 UTC (12 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 5030 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.982 2005/10/07 22:45:32 debug Exp $
20050816	Some success in decoding the way the SGI O2 PROM draws graphics
		during bootup; lines/rectangles and bitmaps work, enough to
		show the bootlogo etc. :-)
		Adding more PPC instructions, and (dummy) BAT registers.
20050817	Updating the pckbc to support scancode type 3 keyboards
		(required in order to interact with the SGI O2 PROM).
		Adding more PPC instructions.
20050818	Adding more ARM instructions; general register forms.
		Importing armreg.h from NetBSD (ARM cpu ids). Adding a (dummy)
		CATS machine mode (using SA110 as the default CPU).
		Continuing on general dyntrans related stuff.
20050819	Register forms for ARM load/stores. Gaah! The Compaq C Compiler
		bug is triggered for ARM loads as well, not just PPC :-(
		Adding full support for ARM PC-relative load/stores, and load/
		stores where the PC register is the destination register.
		Adding support for ARM a.out binaries.
20050820	Continuing to add more ARM instructions, and correcting some
		bugs. Continuing on CATS emulation.
		More work on the PPC stuff.
20050821	Minor PPC and ARM updates. Adding more machine types.
20050822	All ARM "data processing instructions" are now generated
		automatically.
20050824	Beginning the work on the ARM system control coprocessor.
		Adding support for ARM halfword load/stores, and signed loads.
20050825	Fixing an important bug related to the ARM condition codes.
		OpenBSD/zaurus and NetBSD/netwinder now print some boot
		messages. :)
		Adding a dummy SH (Hitachi SuperH) cpu family.
		Beginning to add some ARM virtual address translation.
		MIPS bugfixes: unaligned PC now cause an ADEL exception (at
		least for non-bintrans execution), and ADEL/ADES (not
		TLBL/TLBS) are used if userland tries to access kernel space.
		(Thanks to Joshua Wise for making me aware of these bugs.)
20050827	More work on the ARM emulation, and various other updates.
20050828	More ARM updates.
		Finally taking the time to work on translation invalidation
		(i.e. invalidating translated code mappings when memory is
		written to). Hopefully this doesn't break anything.
20050829	Moving CPU related files from src/ to a new subdir, src/cpus/.
		Moving PROM emulation stuff from src/ to src/promemul/.
		Better debug instruction trace for ARM loads and stores.
20050830	Various ARM updates (correcting CMP flag calculation, etc).
20050831	PPC instruction updates. (Flag fixes, etc.)
20050901	Various minor PPC and ARM instruction emulation updates.
		Minor OpenFirmware emulation updates.
20050903	Adding support for adding arbitrary ARM coprocessors (with
		the i80321 I/O coprocessor as a first test).
		Various other ARM and PPC updates.
20050904	Adding some SHcompact disassembly routines.
20050907	(Re)adding a dummy HPPA CPU module, and a dummy i960 module.
20050908	Began hacking on some Apple Partition Table support.
20050909	Adding support for loading Mach-O (Darwin PPC) binaries.
20050910	Fixing an ARM bug (Carry flag was incorrectly updated for some
		data processing instructions); OpenBSD/cats and NetBSD/
		netwinder get quite a bit further now.
		Applying a patch to dev_wdc, and a one-liner to dev_pcic, to
		make them work better when emulating new versions of OpenBSD.
		(Thanks to Alexander Yurchenko for the patches.)
		Also doing some other minor updates to dev_wdc. (Some cleanup,
		and finally converting to devinit, etc.)
20050912	IRIX doesn't have u_int64_t by default (noticed by Andreas
		<avr@gnulinux.nl>); configure updated to reflect this.
		Working on ARM register bank switching, CPSR vs SPSR issues,
		and beginning the work on interrupt/exception support.
20050913	Various minor ARM updates (speeding up load/store multiple,
		and fixing a ROR bug in R(); NetBSD/cats now boots as far as
		OpenBSD/cats).
20050917	Adding a dummy Atmel AVR (8-bit) cpu family skeleton.
20050918	Various minor updates.
20050919	Symbols are now loaded from Mach-O executables.
		Continuing the work on adding ARM exception support.
20050920	More work on ARM stuff: OpenBSD/cats and NetBSD/cats reach
		userland! :-)
20050921	Some more progress on ARM interrupt specifics.
20050923	Fixing linesize for VR4121 (patch by Yurchenko). Also fixing
		linesizes/cachesizes for some other VR4xxx.
		Adding a dummy Acer Labs M1543 PCI-ISA bridge (for CATS) and a
		dummy Symphony Labs 83C553 bridge (for Netwinder), usable by 
		dev_footbridge.
20050924	Some PPC progress.
20050925	More PPC progress.
20050926	PPC progress (fixing some bugs etc); Darwin's kernel gets
		slightly further than before.
20050928	Various updates: footbridge/ISA/pciide stuff, and finally
		fixing the VGA text scroll-by-changing-the-base-offset bug.
20050930	Adding a dummy S3 ViRGE pci card for CATS emulation, which
		both NetBSD and OpenBSD detects as VGA.
		Continuing on Footbridge (timers, ISA interrupt stuff).
20051001	Continuing... there are still bugs, probably interrupt-
		related.
20051002	More work on the Footbridge (interrupt stuff).
20051003	Various minor updates. (Trying to find the bug(s).)
20051004	Continuing on the ARM stuff.
20051005	More ARM-related fixes.
20051007	FINALLY! Found and fixed 2 ARM bugs: 1 memory related, and the
		other was because of an error in the ARM manual (load multiple
		with the S-bit set should _NOT_ load usermode registers, as the
		manual says, but it should load saved registers, which may or
		may not happen to be usermode registers).
		NetBSD/cats and OpenBSD/cats seem to install fine now :-)
		except for a minor bug at the end of the OpenBSD/cats install.
		Updating the documentation, preparing for the next release.
20051008	Continuing with release testing and cleanup.

1 /*
2 * Copyright (C) 2003-2005 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: cpu_mips16.c,v 1.1 2005/08/29 14:36:41 debug Exp $
29 *
30 * MIPS16 encoding support, 16-bit to 32-bit instruction translation.
31 *
32 * Included from cpu_mips.c.
33 */
34
35 #ifndef ENABLE_MIPS16
36
37 /* Dummy functions if MIPS16 support is not to be included: */
38 int mips16_to_32(struct cpu *cpu, unsigned char *instr16,
39 unsigned char *instr)
40 {
41 fatal("mips16_to_32(): internal error! this function shouldn't "
42 "be called if ENABLE_MIPS16 isn't defined!\n");
43 return 0;
44 }
45
46 #else
47
48
49 /* MIPS16 register numbers: */
50 static int mips16_reg8_to_reg32[8] = {
51 MIPS_GPR_S0, MIPS_GPR_S1, MIPS_GPR_V0, MIPS_GPR_V1,
52 MIPS_GPR_A0, MIPS_GPR_A1, MIPS_GPR_A2, MIPS_GPR_A3
53 };
54
55 static int mips16_sp = MIPS_GPR_SP;
56 /* static int mips16_t = MIPS_GPR_T8; */
57
58
59 /*
60 * mips16_to_32():
61 *
62 * Translate a 16-bit MIPS16 instruction word into a normal 32-bit instruction
63 * word. instr16[1..0] ==> instr[3..0].
64 *
65 * Returns 1 if there is a resulting 32-bit instruction, 0 if this is an
66 * "extend".
67 */
68 int mips16_to_32(struct cpu *cpu, unsigned char *instr16, unsigned char *instr)
69 {
70 int rs, rd, imm, wlen;
71 int x = (instr16[1] << 8) + instr16[0];
72 int y = 0x3e << 26; /* This should be something 'illegal',
73 so that execution stops */
74
75 /* Translate 16-bit x into 32-bit y: */
76
77 /* extend: */
78 if ((x & 0xf800) == 0xf000) {
79 /* TODO: what happens if an extend is interrupted? */
80 cpu->cd.mips.mips16_extend = x; /* save x until later */
81 return 0;
82 }
83
84 /* nop: */
85 if ((x & 0xffff) == 0x6500) {
86 y = 0x00000000; /* nop */
87 goto mips16_ret;
88 }
89
90 /* move y,X: 0x67 + 3 bits rd + 5 bits rs */
91 if ((x & 0xff00) == 0x6700) {
92 rd = (x >> 5) & 0x07;
93 rs = (x >> 0) & 0x1f;
94 /* addiu mips16_reg8_to_reg32[rd], reg32[rs], 0 */
95 y = (HI6_ADDIU << 26) + (rs << 21) +
96 (mips16_reg8_to_reg32[rd] << 16);
97 goto mips16_ret;
98 }
99
100 /* ld y,D(x) { ld "y,D(x)", 0x3800, 0xf800, WR_y|RD_x, I3 } */
101 if ((x & 0xf800) == 0x3800) {
102 wlen = 8; /* for ld */
103 rd = (x >> 5) & 0x07;
104 rs = (x >> 8) & 0x07;
105 if (cpu->cd.mips.mips16_extend)
106 imm = (cpu->cd.mips.mips16_extend & 0x7ff) +
107 ((x & 0x1f) << 11);
108 else {
109 imm = (x & 0x1f) * wlen;
110 if (imm >= 0x10)
111 imm |= 0xffe0; /* sign-extend */
112 }
113
114 y = (HI6_LD << 26) + (mips16_reg8_to_reg32[rd] << 16) +
115 (rs << 21) + imm;
116 goto mips16_ret;
117 }
118
119 /* sd y,D(S) 0xf900, 0xff00, RD_y|RD_PC, I3 */
120 if ((x & 0xff00) == 0xf900) {
121 wlen = 8; /* for sd */
122 rd = (x >> 5) & 0x07;
123 rs = (x >> 8) & 0x07;
124
125 /* TODO */
126
127 if (cpu->cd.mips.mips16_extend) {
128 imm = (cpu->cd.mips.mips16_extend & 0x7ff) +
129 ((x & 0x1f) << 11);
130 } else {
131 imm = (x & 0x1f) * wlen;
132 if (imm >= 0x10)
133 imm |= 0xffe0; /* sign-extend */
134 }
135
136 y = (HI6_SD << 26) + (mips16_reg8_to_reg32[rd] << 16) +
137 (rs << 21) + imm;
138 goto mips16_ret;
139 }
140
141 /* daddiu "S,K", 0xfb00, 0xff00, WR_SP|RD_SP, I3 */
142 if ((x & 0xff00) == 0xfb00) {
143
144 /* TODO: this is wrong */
145
146 if (cpu->cd.mips.mips16_extend) {
147 imm = ((cpu->cd.mips.mips16_extend & 0x7ff) << 5) +
148 (x & 0xff);
149 } else {
150 imm = (x & 0xff) << 3;
151 if (imm & (1 << 10))
152 imm |= 0xf800; /* sign-extend */
153 }
154
155 y = (HI6_DADDIU << 26) + (mips16_sp << 21) + (mips16_sp << 16)
156 + (imm & 0xffff);
157 goto mips16_ret;
158 }
159
160 /* fatal("WARNING: unimplemented MIPS16 instruction 0x%04x\n", x); */
161
162 mips16_ret:
163 instr[3] = y >> 24; instr[2] = y >> 16;
164 instr[1] = y >> 8; instr[0] = y;
165 return 1;
166 }
167
168
169 #endif /* ENABLE_MIPS16 */

  ViewVC Help
Powered by ViewVC 1.1.26