Compare commits
85 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
be26a5288e | ||
|
82c7e2a4c6 | ||
|
546cdbd77d | ||
|
c265508067 | ||
|
dd4e27d810 | ||
|
a41bc9af8f | ||
|
3bfd9da14f | ||
|
c573ff6752 | ||
|
060366c5ad | ||
|
6da41eafc4 | ||
|
0124311e00 | ||
|
f515528907 | ||
|
b453b70bd8 | ||
|
0ac4bd56a8 | ||
|
3811a291e2 | ||
|
3415a4ddb4 | ||
|
b7f0f463a5 | ||
|
8e682019e3 | ||
|
cf495bcf9f | ||
|
fb0eaffc6d | ||
|
07ad1b93a3 | ||
|
d36cd60e6c | ||
|
5e809a8095 | ||
|
791c2261d6 | ||
|
163a7cb620 | ||
|
6bb705711b | ||
|
4136f33c7e | ||
|
6dca2016fc | ||
|
678673089d | ||
|
28b6751f30 | ||
|
79aceca54a | ||
|
6a8c397deb | ||
|
9cdf757fd5 | ||
|
36bdbe5479 | ||
|
8004340674 | ||
|
a2cc3b2433 | ||
|
afa05eb15e | ||
|
de5eaa6452 | ||
|
7517502475 | ||
|
8f2b1fb008 | ||
|
891b38e446 | ||
|
7dea1da4ae | ||
|
4ce900b44c | ||
|
f3f2d9be03 | ||
|
77729c2445 | ||
|
d71b9a8b2f | ||
|
181f1558cd | ||
|
2750332396 | ||
|
f115e911d7 | ||
|
3ab493de4c | ||
|
3e25f9515a | ||
|
246d897f4c | ||
|
7e84c2498f | ||
|
e670b89e3b | ||
|
bd0d90b21d | ||
|
1a0636f8d7 | ||
|
2e134c9c55 | ||
|
5391d80669 | ||
|
36b486bb74 | ||
|
4ad06a29b2 | ||
|
e58143b355 | ||
|
1f5476fcce | ||
|
461c0471af | ||
|
9c3ad57432 | ||
|
e748ba4f53 | ||
|
b8ed223bfe | ||
|
c970a162e7 | ||
|
c321f67309 | ||
|
7f7f987341 | ||
|
aebcb60e55 | ||
|
1a18c71b50 | ||
|
03a6c5103d | ||
|
128b346e0a | ||
|
415fa2ea77 | ||
|
9951bf39f9 | ||
|
8948b5d613 | ||
|
5086347239 | ||
|
9d4520d0e0 | ||
|
5b9f457a89 | ||
|
3a4739d651 | ||
|
76b62fd001 | ||
|
b1f645758a | ||
|
bc1b050d85 | ||
|
03d5f74aee | ||
|
9f05cc34df |
17
Changelog
17
Changelog
@@ -1,3 +1,18 @@
|
||||
version 0.5.1:
|
||||
|
||||
- float access fixes when using soft mmu
|
||||
- PC emulation support on PowerPC
|
||||
- A20 support
|
||||
- IDE CD-ROM emulation
|
||||
- ARM fixes (Ulrich Hecht)
|
||||
- SB16 emulation (malc)
|
||||
- IRET and INT fixes in VM86 mode with IOPL=3
|
||||
- Port I/Os use TSS io map
|
||||
- Full task switching/task gate support
|
||||
- added verr, verw, arpl, fcmovxx
|
||||
- PowerPC target support (Jocelyn Mayer)
|
||||
- Major SPARC target fixes (dynamically linked programs begin to work)
|
||||
|
||||
version 0.5.0:
|
||||
|
||||
- full hardware level VGA emulation
|
||||
@@ -18,7 +33,7 @@ version 0.5.0:
|
||||
- automatic IDE geometry detection
|
||||
- renamed 'vl' to qemu[-fast] and user qemu to qemu-{cpu}.
|
||||
- added man page
|
||||
- added full soft mmy mode to launch unpatched OSes.
|
||||
- added full soft mmu mode to launch unpatched OSes.
|
||||
|
||||
version 0.4.3:
|
||||
|
||||
|
22
Makefile
22
Makefile
@@ -31,7 +31,7 @@ clean:
|
||||
distclean: clean
|
||||
rm -f config-host.mak config-host.h
|
||||
for d in $(TARGET_DIRS); do \
|
||||
rm -f $$d/config.h $$d/config.mak || exit 1 ; \
|
||||
rm -rf $$d || exit 1 ; \
|
||||
done
|
||||
|
||||
install: all
|
||||
@@ -46,7 +46,7 @@ install: all
|
||||
done
|
||||
|
||||
# various test targets
|
||||
test speed: all
|
||||
test speed test2: all
|
||||
make -C tests $@
|
||||
|
||||
TAGS:
|
||||
@@ -66,17 +66,19 @@ FILE=qemu-$(shell cat VERSION)
|
||||
tar:
|
||||
rm -rf /tmp/$(FILE)
|
||||
cp -r . /tmp/$(FILE)
|
||||
( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) )
|
||||
( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
|
||||
rm -rf /tmp/$(FILE)
|
||||
|
||||
# generate a binary distribution including the test binary environnment
|
||||
BINPATH=/usr/local/qemu-i386
|
||||
|
||||
# generate a binary distribution
|
||||
tarbin:
|
||||
tar zcvf /tmp/qemu-$(VERSION)-i386-glibc21.tar.gz \
|
||||
$(BINPATH)/etc $(BINPATH)/lib $(BINPATH)/bin $(BINPATH)/usr
|
||||
tar zcvf /tmp/qemu-$(VERSION)-i386-wine.tar.gz \
|
||||
$(BINPATH)/wine
|
||||
( cd / ; tar zcvf ~/qemu-$(VERSION)-i386.tar.gz \
|
||||
$(prefix)/bin/qemu $(prefix)/bin/qemu-fast \
|
||||
$(prefix)/bin/qemu-i386 \
|
||||
$(prefix)/bin/qemu-arm \
|
||||
$(prefix)/bin/qemu-sparc \
|
||||
$(sharedir)/bios.bin \
|
||||
$(sharedir)/vgabios.bin \
|
||||
$(mandir)/man1/qemu.1 )
|
||||
|
||||
ifneq ($(wildcard .depend),)
|
||||
include .depend
|
||||
|
@@ -20,10 +20,21 @@ endif
|
||||
ifdef CONFIG_USER_ONLY
|
||||
PROGS=$(QEMU_USER)
|
||||
else
|
||||
ifeq ($(ARCH),i386)
|
||||
ifeq ($(TARGET_ARCH), i386)
|
||||
|
||||
ifeq ($(ARCH), i386)
|
||||
PROGS+=$(QEMU_SYSTEM)
|
||||
ifndef CONFIG_SOFTMMU
|
||||
CONFIG_STATIC=y
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH), ppc)
|
||||
ifdef CONFIG_SOFTMMU
|
||||
PROGS+=$(QEMU_SYSTEM)
|
||||
endif
|
||||
endif
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -39,7 +50,14 @@ OP_CFLAGS+= -falign-functions=0
|
||||
else
|
||||
OP_CFLAGS+= -malign-functions=0
|
||||
endif
|
||||
|
||||
ifdef TARGET_GPROF
|
||||
USE_I386_LD=y
|
||||
endif
|
||||
ifdef CONFIG_STATIC
|
||||
USE_I386_LD=y
|
||||
endif
|
||||
ifdef USE_I386_LD
|
||||
LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386.ld
|
||||
else
|
||||
# WARNING: this LDFLAGS is _very_ tricky : qemu is an ELF shared object
|
||||
@@ -128,6 +146,10 @@ ifeq ($(TARGET_ARCH), i386)
|
||||
LIBOBJS+=helper.o helper2.o
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET_ARCH), ppc)
|
||||
LIBOBJS+=helper.o
|
||||
endif
|
||||
|
||||
# NOTE: the disassembler code is only needed for debugging
|
||||
LIBOBJS+=disas.o
|
||||
ifeq ($(findstring i386, $(TARGET_ARCH) $(ARCH)),i386)
|
||||
@@ -161,14 +183,25 @@ ifeq ($(ARCH),alpha)
|
||||
endif
|
||||
|
||||
# must use static linking to avoid leaving stuff in virtual address space
|
||||
VL_OBJS=vl.o block.o vga.o
|
||||
VL_OBJS=vl.o block.o ide.o vga.o sb16.o dma.o oss.o
|
||||
ifdef CONFIG_SDL
|
||||
VL_OBJS+=sdl.o
|
||||
SDL_LIBS+=-L/usr/X11R6/lib -lX11 -lXext -lXv -ldl -lm
|
||||
ifdef CONFIG_STATIC
|
||||
SDL_LIBS:=$(SDL_STATIC_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
VL_LDFLAGS=
|
||||
# specific flags are needed for non soft mmu emulator
|
||||
ifdef CONFIG_STATIC
|
||||
VL_LDFLAGS+=-static
|
||||
endif
|
||||
ifndef CONFIG_SOFTMMU
|
||||
VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld
|
||||
endif
|
||||
|
||||
$(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
|
||||
$(CC) -static -Wl,-T,$(SRC_PATH)/i386-vl.ld -o $@ $^ $(LIBS) $(SDL_LIBS)
|
||||
$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS)
|
||||
|
||||
sdl.o: sdl.c
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
|
||||
|
11
TODO
11
TODO
@@ -1,14 +1,17 @@
|
||||
- user/kernel PUSHL/POPL in helper.c
|
||||
- keyboard output buffer filling timing emulation
|
||||
- verify tb_flush() with a20 and TLBs
|
||||
|
||||
- cmos clock update and timers
|
||||
- test ldt limit < 7 ?
|
||||
- tests for each target CPU
|
||||
- ppc qemu test
|
||||
- optimize FPU operations (evaluate x87 stack pointer statically) and
|
||||
fix cr0.TS emulation
|
||||
- fix some 16 bit sp push/pop overflow
|
||||
- fix some 16 bit sp push/pop overflow (pusha/popa, lcall lret)
|
||||
- sysenter/sysexit emulation
|
||||
- finish segment ops (call far, ret far, load_seg suppressed)
|
||||
- fix CCOP optimisation
|
||||
- fix all remaining thread lock issues (must put TBs in a specific invalid
|
||||
state, find a solution for tb_flush()).
|
||||
- cpu loop optimisation (optimise ret case as the cpu state does not change)
|
||||
- fix arm fpu rounding (at least for float->integer conversions)
|
||||
|
||||
lower priority:
|
||||
|
9
configure
vendored
9
configure
vendored
@@ -27,7 +27,7 @@ ar="ar"
|
||||
make="make"
|
||||
strip="strip"
|
||||
cpu=`uname -m`
|
||||
target_list="i386-user i386 i386-softmmu arm-user sparc-user"
|
||||
target_list="i386-user i386 i386-softmmu arm-user sparc-user ppc-user"
|
||||
case "$cpu" in
|
||||
i386|i486|i586|i686|i86pc|BePC)
|
||||
cpu="i386"
|
||||
@@ -295,11 +295,13 @@ if test "$gprof" = "yes" ; then
|
||||
fi
|
||||
if test "$static" = "yes" ; then
|
||||
echo "CONFIG_STATIC=yes" >> $config_mak
|
||||
echo "#define CONFIG_STATIC 1" >> $config_h
|
||||
fi
|
||||
if test "$sdl" = "yes" ; then
|
||||
echo "CONFIG_SDL=yes" >> $config_mak
|
||||
echo "#define CONFIG_SDL 1" >> $config_h
|
||||
echo "SDL_LIBS=`sdl-config --libs`" >> $config_mak
|
||||
echo "SDL_STATIC_LIBS=`sdl-config --static-libs`" >> $config_mak
|
||||
echo "SDL_CFLAGS=`sdl-config --cflags`" >> $config_mak
|
||||
fi
|
||||
echo -n "VERSION=" >>$config_mak
|
||||
@@ -320,6 +322,7 @@ config_h=$target_dir/config.h
|
||||
target_cpu=`echo $target | cut -d '-' -f 1`
|
||||
target_bigendian="no"
|
||||
[ "$target_cpu" = "sparc" ] && target_bigendian=yes
|
||||
[ "$target_cpu" = "ppc" ] && target_bigendian=yes
|
||||
target_softmmu="no"
|
||||
if expr $target : '.*-softmmu' > /dev/null ; then
|
||||
target_softmmu="yes"
|
||||
@@ -356,6 +359,10 @@ elif test "$target_cpu" = "sparc" ; then
|
||||
echo "TARGET_ARCH=sparc" >> $config_mak
|
||||
echo "#define TARGET_ARCH \"sparc\"" >> $config_h
|
||||
echo "#define TARGET_SPARC 1" >> $config_h
|
||||
elif test "$target_cpu" = "ppc" ; then
|
||||
echo "TARGET_ARCH=ppc" >> $config_mak
|
||||
echo "#define TARGET_ARCH \"ppc\"" >> $config_h
|
||||
echo "#define TARGET_PPC 1" >> $config_h
|
||||
else
|
||||
echo "Unsupported target CPU"
|
||||
exit 1
|
||||
|
141
cpu-all.h
141
cpu-all.h
@@ -20,6 +20,40 @@
|
||||
#ifndef CPU_ALL_H
|
||||
#define CPU_ALL_H
|
||||
|
||||
#if defined(__arm__) || defined(__sparc__)
|
||||
#define WORDS_ALIGNED
|
||||
#endif
|
||||
|
||||
/* some important defines:
|
||||
*
|
||||
* WORDS_ALIGNED : if defined, the host cpu can only make word aligned
|
||||
* memory accesses.
|
||||
*
|
||||
* WORDS_BIGENDIAN : if defined, the host cpu is big endian and
|
||||
* otherwise little endian.
|
||||
*
|
||||
* (TARGET_WORDS_ALIGNED : same for target cpu (not supported yet))
|
||||
*
|
||||
* TARGET_WORDS_BIGENDIAN : same for target cpu
|
||||
*/
|
||||
|
||||
/* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
|
||||
typedef union {
|
||||
double d;
|
||||
#if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
|
||||
struct {
|
||||
uint32_t lower;
|
||||
uint32_t upper;
|
||||
} l;
|
||||
#else
|
||||
struct {
|
||||
uint32_t upper;
|
||||
uint32_t lower;
|
||||
} l;
|
||||
#endif
|
||||
uint64_t ll;
|
||||
} CPU_DoubleU;
|
||||
|
||||
/* CPU memory access without any memory or io remapping */
|
||||
|
||||
static inline int ldub_raw(void *ptr)
|
||||
@@ -40,7 +74,7 @@ static inline void stb_raw(void *ptr, int v)
|
||||
/* NOTE: on arm, putting 2 in /proc/sys/debug/alignment so that the
|
||||
kernel handles unaligned load/stores may give better results, but
|
||||
it is a system wide setting : bad */
|
||||
#if defined(WORDS_BIGENDIAN) || defined(__arm__)
|
||||
#if !defined(TARGET_WORDS_BIGENDIAN) && (defined(WORDS_BIGENDIAN) || defined(WORDS_ALIGNED))
|
||||
|
||||
/* conservative code for little endian unaligned accesses */
|
||||
static inline int lduw_raw(void *ptr)
|
||||
@@ -141,55 +175,23 @@ static inline void stfl_raw(void *ptr, float v)
|
||||
stl_raw(ptr, u.i);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__arm__) && !defined(WORDS_BIGENDIAN)
|
||||
|
||||
/* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
|
||||
static inline double ldfq_raw(void *ptr)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint32_t tab[2];
|
||||
} u;
|
||||
u.tab[1] = ldl_raw(ptr);
|
||||
u.tab[0] = ldl_raw(ptr + 4);
|
||||
CPU_DoubleU u;
|
||||
u.l.lower = ldl_raw(ptr);
|
||||
u.l.upper = ldl_raw(ptr + 4);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
static inline void stfq_raw(void *ptr, double v)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint32_t tab[2];
|
||||
} u;
|
||||
CPU_DoubleU u;
|
||||
u.d = v;
|
||||
stl_raw(ptr, u.tab[1]);
|
||||
stl_raw(ptr + 4, u.tab[0]);
|
||||
stl_raw(ptr, u.l.lower);
|
||||
stl_raw(ptr + 4, u.l.upper);
|
||||
}
|
||||
|
||||
#else
|
||||
static inline double ldfq_raw(void *ptr)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint64_t i;
|
||||
} u;
|
||||
u.i = ldq_raw(ptr);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
static inline void stfq_raw(void *ptr, double v)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint64_t i;
|
||||
} u;
|
||||
u.d = v;
|
||||
stq_raw(ptr, u.i);
|
||||
}
|
||||
#endif
|
||||
|
||||
#elif defined(TARGET_WORDS_BIGENDIAN) && !defined(WORDS_BIGENDIAN)
|
||||
#elif defined(TARGET_WORDS_BIGENDIAN) && (!defined(WORDS_BIGENDIAN) || defined(WORDS_ALIGNED))
|
||||
|
||||
static inline int lduw_raw(void *ptr)
|
||||
{
|
||||
@@ -212,8 +214,8 @@ static inline int ldl_raw(void *ptr)
|
||||
static inline uint64_t ldq_raw(void *ptr)
|
||||
{
|
||||
uint32_t a,b;
|
||||
a = ldl (ptr);
|
||||
b = ldl (ptr+4);
|
||||
a = ldl_raw(ptr);
|
||||
b = ldl_raw(ptr+4);
|
||||
return (((uint64_t)a<<32)|b);
|
||||
}
|
||||
|
||||
@@ -235,8 +237,46 @@ static inline void stl_raw(void *ptr, int v)
|
||||
|
||||
static inline void stq_raw(void *ptr, uint64_t v)
|
||||
{
|
||||
stl (ptr, v);
|
||||
stl (ptr+4, v >> 32);
|
||||
stl_raw(ptr, v >> 32);
|
||||
stl_raw(ptr + 4, v);
|
||||
}
|
||||
|
||||
/* float access */
|
||||
|
||||
static inline float ldfl_raw(void *ptr)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.i = ldl_raw(ptr);
|
||||
return u.f;
|
||||
}
|
||||
|
||||
static inline void stfl_raw(void *ptr, float v)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.f = v;
|
||||
stl_raw(ptr, u.i);
|
||||
}
|
||||
|
||||
static inline double ldfq_raw(void *ptr)
|
||||
{
|
||||
CPU_DoubleU u;
|
||||
u.l.upper = ldl_raw(ptr);
|
||||
u.l.lower = ldl_raw(ptr + 4);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
static inline void stfq_raw(void *ptr, double v)
|
||||
{
|
||||
CPU_DoubleU u;
|
||||
u.d = v;
|
||||
stl_raw(ptr, u.l.upper);
|
||||
stl_raw(ptr + 4, u.l.lower);
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -330,10 +370,14 @@ static inline void stfq_raw(void *ptr, double v)
|
||||
#define lduw_kernel(p) lduw_raw(p)
|
||||
#define ldsw_kernel(p) ldsw_raw(p)
|
||||
#define ldl_kernel(p) ldl_raw(p)
|
||||
#define ldfl_kernel(p) ldfl_raw(p)
|
||||
#define ldfq_kernel(p) ldfq_raw(p)
|
||||
#define stb_kernel(p, v) stb_raw(p, v)
|
||||
#define stw_kernel(p, v) stw_raw(p, v)
|
||||
#define stl_kernel(p, v) stl_raw(p, v)
|
||||
#define stq_kernel(p, v) stq_raw(p, v)
|
||||
#define stfl_kernel(p, v) stfl_raw(p, v)
|
||||
#define stfq_kernel(p, vt) stfq_raw(p, v)
|
||||
|
||||
#endif /* defined(CONFIG_USER_ONLY) */
|
||||
|
||||
@@ -395,6 +439,15 @@ void page_unprotect_range(uint8_t *data, unsigned long data_size);
|
||||
#define cpu_interrupt cpu_sparc_interrupt
|
||||
#define cpu_signal_handler cpu_sparc_signal_handler
|
||||
|
||||
#elif defined(TARGET_PPC)
|
||||
|
||||
#define CPUState CPUPPCState
|
||||
#define cpu_init cpu_ppc_init
|
||||
#define cpu_exec cpu_ppc_exec
|
||||
#define cpu_gen_code cpu_ppc_gen_code
|
||||
#define cpu_interrupt cpu_ppc_interrupt
|
||||
#define cpu_signal_handler cpu_ppc_signal_handler
|
||||
|
||||
#else
|
||||
|
||||
#error unsupported target CPU
|
||||
|
80
cpu-exec.c
80
cpu-exec.c
@@ -21,6 +21,8 @@
|
||||
#include "exec.h"
|
||||
#include "disas.h"
|
||||
|
||||
int tb_invalidated_flag;
|
||||
|
||||
//#define DEBUG_EXEC
|
||||
//#define DEBUG_SIGNAL
|
||||
|
||||
@@ -131,6 +133,7 @@ int cpu_exec(CPUState *env1)
|
||||
env->cpsr = psr & ~0xf0000000;
|
||||
}
|
||||
#elif defined(TARGET_SPARC)
|
||||
#elif defined(TARGET_PPC)
|
||||
#else
|
||||
#error unsupported target CPU
|
||||
#endif
|
||||
@@ -226,6 +229,8 @@ int cpu_exec(CPUState *env1)
|
||||
env->cpsr &= ~0xf0000000;
|
||||
#elif defined(TARGET_SPARC)
|
||||
cpu_sparc_dump_state (env, logfile, 0);
|
||||
#elif defined(TARGET_PPC)
|
||||
cpu_ppc_dump_state(env, logfile, 0);
|
||||
#else
|
||||
#error unsupported target CPU
|
||||
#endif
|
||||
@@ -244,13 +249,13 @@ int cpu_exec(CPUState *env1)
|
||||
cs_base = 0;
|
||||
pc = (uint8_t *)env->regs[15];
|
||||
#elif defined(TARGET_SPARC)
|
||||
flags = 0;
|
||||
cs_base = 0;
|
||||
if (env->npc) {
|
||||
env->pc = env->npc;
|
||||
env->npc = 0;
|
||||
}
|
||||
pc = (uint8_t *) env->pc;
|
||||
flags = 0;
|
||||
cs_base = env->npc;
|
||||
pc = (uint8_t *) env->pc;
|
||||
#elif defined(TARGET_PPC)
|
||||
flags = 0;
|
||||
cs_base = 0;
|
||||
pc = (uint8_t *)env->nip;
|
||||
#else
|
||||
#error unsupported CPU
|
||||
#endif
|
||||
@@ -262,7 +267,7 @@ int cpu_exec(CPUState *env1)
|
||||
tb = tb_alloc((unsigned long)pc);
|
||||
if (!tb) {
|
||||
/* flush must be done */
|
||||
tb_flush();
|
||||
tb_flush(env);
|
||||
/* cannot fail at this point */
|
||||
tb = tb_alloc((unsigned long)pc);
|
||||
/* don't forget to invalidate previous TB info */
|
||||
@@ -273,8 +278,17 @@ int cpu_exec(CPUState *env1)
|
||||
tb->tc_ptr = tc_ptr;
|
||||
tb->cs_base = (unsigned long)cs_base;
|
||||
tb->flags = flags;
|
||||
/* XXX: an MMU exception can occur here */
|
||||
tb_invalidated_flag = 0;
|
||||
cpu_gen_code(env, tb, CODE_GEN_MAX_SIZE, &code_gen_size);
|
||||
if (tb_invalidated_flag) {
|
||||
/* as some TB could have been invalidated because
|
||||
of memory exceptions while generating the code, we
|
||||
must recompute the hash index here */
|
||||
ptb = &tb_hash[tb_hash_func((unsigned long)pc)];
|
||||
while (*ptb != NULL)
|
||||
ptb = &(*ptb)->hash_next;
|
||||
T0 = 0;
|
||||
}
|
||||
*ptb = tb;
|
||||
tb->hash_next = NULL;
|
||||
tb_link(tb);
|
||||
@@ -365,6 +379,7 @@ int cpu_exec(CPUState *env1)
|
||||
#elif defined(TARGET_ARM)
|
||||
env->cpsr = compute_cpsr();
|
||||
#elif defined(TARGET_SPARC)
|
||||
#elif defined(TARGET_PPC)
|
||||
#else
|
||||
#error unsupported target CPU
|
||||
#endif
|
||||
@@ -378,7 +393,7 @@ int cpu_exec(CPUState *env1)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(TARGET_I386)
|
||||
#if defined(TARGET_I386) && defined(CONFIG_USER_ONLY)
|
||||
|
||||
void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector)
|
||||
{
|
||||
@@ -391,7 +406,7 @@ void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector)
|
||||
cpu_x86_load_seg_cache(env, seg_reg, selector,
|
||||
(uint8_t *)(selector << 4), 0xffff, 0);
|
||||
} else {
|
||||
load_seg(seg_reg, selector, 0);
|
||||
load_seg(seg_reg, selector);
|
||||
}
|
||||
env = saved_env;
|
||||
}
|
||||
@@ -500,7 +515,48 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
int is_write, sigset_t *old_set)
|
||||
{
|
||||
return 0;
|
||||
/* XXX: locking issue */
|
||||
if (is_write && page_unprotect(address)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#elif defined (TARGET_PPC)
|
||||
static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
int is_write, sigset_t *old_set)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
|
||||
#if 0
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#endif
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
if (is_write && page_unprotect(address)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* now we have a real cpu fault */
|
||||
tb = tb_find_pc(pc);
|
||||
if (tb) {
|
||||
/* the PC is inside the translated code. It means that we have
|
||||
a virtual CPU fault */
|
||||
cpu_restore_state(tb, env, pc);
|
||||
}
|
||||
#if 0
|
||||
printf("PF exception: EIP=0x%08x CR2=0x%08x error=0x%x\n",
|
||||
env->eip, env->cr[2], env->error_code);
|
||||
#endif
|
||||
/* we restore the process signal mask as the sigreturn should
|
||||
do it (XXX: use sigsetjmp) */
|
||||
sigprocmask(SIG_SETMASK, old_set, NULL);
|
||||
raise_exception_err(EXCP_PROGRAM, env->error_code);
|
||||
/* never comes here */
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
#error unsupported target CPU
|
||||
|
2
disas.c
2
disas.c
@@ -171,6 +171,8 @@ void disas(FILE *out, void *code, unsigned long size, int is_host, int flags)
|
||||
print_insn = print_insn_arm;
|
||||
#elif defined(TARGET_SPARC)
|
||||
print_insn = print_insn_sparc;
|
||||
#elif defined(TARGET_PPC)
|
||||
print_insn = print_insn_ppc;
|
||||
#else
|
||||
fprintf(out, "Asm output not supported on this arch\n");
|
||||
return;
|
||||
|
@@ -17,6 +17,9 @@
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#if !defined(__DYNGEN_EXEC_H__)
|
||||
#define __DYNGEN_EXEC_H__
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
@@ -27,6 +30,19 @@ typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed long long int64_t;
|
||||
|
||||
#define INT8_MIN (-128)
|
||||
#define INT16_MIN (-32767-1)
|
||||
#define INT32_MIN (-2147483647-1)
|
||||
#define INT64_MIN (-(int64_t)(9223372036854775807)-1)
|
||||
#define INT8_MAX (127)
|
||||
#define INT16_MAX (32767)
|
||||
#define INT32_MAX (2147483647)
|
||||
#define INT64_MAX ((int64_t)(9223372036854775807))
|
||||
#define UINT8_MAX (255)
|
||||
#define UINT16_MAX (65535)
|
||||
#define UINT32_MAX (4294967295U)
|
||||
#define UINT64_MAX ((uint64_t)(18446744073709551615))
|
||||
|
||||
#define bswap32(x) \
|
||||
({ \
|
||||
uint32_t __x = (x); \
|
||||
@@ -54,6 +70,8 @@ extern int printf(const char *, ...);
|
||||
#define AREG1 "r24"
|
||||
#define AREG2 "r25"
|
||||
#define AREG3 "r26"
|
||||
/* XXX: suppress this hack */
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
#define AREG4 "r16"
|
||||
#define AREG5 "r17"
|
||||
#define AREG6 "r18"
|
||||
@@ -62,6 +80,7 @@ extern int printf(const char *, ...);
|
||||
#define AREG9 "r21"
|
||||
#define AREG10 "r22"
|
||||
#define AREG11 "r23"
|
||||
#endif
|
||||
#define USE_INT_TO_FLOAT_HELPERS
|
||||
#define BUGGY_GCC_DIV64
|
||||
#endif
|
||||
@@ -188,3 +207,5 @@ extern int __op_jmp0, __op_jmp1, __op_jmp2, __op_jmp3;
|
||||
#ifdef __mc68000
|
||||
#define EXIT_TB() asm volatile ("rts")
|
||||
#endif
|
||||
|
||||
#endif /* !defined(__DYNGEN_EXEC_H__) */
|
||||
|
@@ -77,7 +77,7 @@ int cpu_restore_state(struct TranslationBlock *tb,
|
||||
CPUState *env, unsigned long searched_pc);
|
||||
void cpu_exec_init(void);
|
||||
int page_unprotect(unsigned long address);
|
||||
void page_unmap(void);
|
||||
void tb_invalidate_page(unsigned long address);
|
||||
void tlb_flush_page(CPUState *env, uint32_t addr);
|
||||
void tlb_flush_page_write(CPUState *env, uint32_t addr);
|
||||
void tlb_flush(CPUState *env);
|
||||
@@ -127,7 +127,7 @@ static inline unsigned int tb_hash_func(unsigned long pc)
|
||||
}
|
||||
|
||||
TranslationBlock *tb_alloc(unsigned long pc);
|
||||
void tb_flush(void);
|
||||
void tb_flush(CPUState *env);
|
||||
void tb_link(TranslationBlock *tb);
|
||||
|
||||
extern TranslationBlock *tb_hash[CODE_GEN_HASH_SIZE];
|
||||
@@ -384,7 +384,7 @@ typedef int spinlock_t;
|
||||
|
||||
#define SPIN_LOCK_UNLOCKED 0
|
||||
|
||||
#if 1
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
static inline void spin_lock(spinlock_t *lock)
|
||||
{
|
||||
while (testandset(lock));
|
||||
@@ -416,6 +416,7 @@ static inline int spin_trylock(spinlock_t *lock)
|
||||
|
||||
extern spinlock_t tb_lock;
|
||||
|
||||
extern int tb_invalidated_flag;
|
||||
|
||||
#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
|
||||
|
||||
|
70
exec.c
70
exec.c
@@ -62,7 +62,6 @@ typedef struct PageDesc {
|
||||
#define L1_SIZE (1 << L1_BITS)
|
||||
#define L2_SIZE (1 << L2_BITS)
|
||||
|
||||
static void tb_invalidate_page(unsigned long address);
|
||||
static void io_mem_init(void);
|
||||
|
||||
unsigned long real_host_page_size;
|
||||
@@ -229,15 +228,19 @@ static void page_flush_tb(void)
|
||||
|
||||
/* flush all the translation blocks */
|
||||
/* XXX: tb_flush is currently not thread safe */
|
||||
void tb_flush(void)
|
||||
void tb_flush(CPUState *env)
|
||||
{
|
||||
int i;
|
||||
#ifdef DEBUG_FLUSH
|
||||
#if defined(DEBUG_FLUSH)
|
||||
printf("qemu: flush code_size=%d nb_tbs=%d avg_tb_size=%d\n",
|
||||
code_gen_ptr - code_gen_buffer,
|
||||
nb_tbs,
|
||||
(code_gen_ptr - code_gen_buffer) / nb_tbs);
|
||||
nb_tbs > 0 ? (code_gen_ptr - code_gen_buffer) / nb_tbs : 0);
|
||||
#endif
|
||||
/* must reset current TB so that interrupts cannot modify the
|
||||
links while we are modifying them */
|
||||
env->current_tb = NULL;
|
||||
|
||||
nb_tbs = 0;
|
||||
for(i = 0;i < CODE_GEN_HASH_SIZE; i++)
|
||||
tb_hash[i] = NULL;
|
||||
@@ -362,6 +365,8 @@ static inline void tb_invalidate(TranslationBlock *tb, int parity)
|
||||
unsigned int h, n1;
|
||||
TranslationBlock *tb1, *tb2;
|
||||
|
||||
tb_invalidated_flag = 1;
|
||||
|
||||
/* remove the TB from the hash list */
|
||||
h = tb_hash_func(tb->pc);
|
||||
tb_remove(&tb_hash[h], tb,
|
||||
@@ -400,7 +405,7 @@ static inline void tb_invalidate(TranslationBlock *tb, int parity)
|
||||
}
|
||||
|
||||
/* invalidate all TBs which intersect with the target page starting at addr */
|
||||
static void tb_invalidate_page(unsigned long address)
|
||||
void tb_invalidate_page(unsigned long address)
|
||||
{
|
||||
TranslationBlock *tb_next, *tb;
|
||||
unsigned int page_index;
|
||||
@@ -624,7 +629,7 @@ static inline void tb_reset_jump_recursive2(TranslationBlock *tb, int n)
|
||||
/* suppress the jump to next tb in generated code */
|
||||
tb_reset_jump(tb, n);
|
||||
|
||||
/* suppress jumps in the tb on which we could have jump */
|
||||
/* suppress jumps in the tb on which we could have jumped */
|
||||
tb_reset_jump_recursive(tb_next);
|
||||
}
|
||||
}
|
||||
@@ -686,7 +691,7 @@ void cpu_single_step(CPUState *env, int enabled)
|
||||
if (env->singlestep_enabled != enabled) {
|
||||
env->singlestep_enabled = enabled;
|
||||
/* must flush all the translated code to avoid inconsistancies */
|
||||
tb_flush();
|
||||
tb_flush(env);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -710,7 +715,7 @@ void cpu_set_log_filename(const char *filename)
|
||||
logfilename = strdup(filename);
|
||||
}
|
||||
|
||||
/* mask must never be zero */
|
||||
/* mask must never be zero, except for A20 change call */
|
||||
void cpu_interrupt(CPUState *env, int mask)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
@@ -740,9 +745,10 @@ void cpu_abort(CPUState *env, const char *fmt, ...)
|
||||
abort();
|
||||
}
|
||||
|
||||
#ifdef TARGET_I386
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
/* unmap all maped pages and flush all associated code */
|
||||
void page_unmap(void)
|
||||
static void page_unmap(CPUState *env)
|
||||
{
|
||||
PageDesc *pmap;
|
||||
int i;
|
||||
@@ -782,21 +788,25 @@ void page_unmap(void)
|
||||
l1_map[i] = NULL;
|
||||
}
|
||||
}
|
||||
tb_flush();
|
||||
tb_flush(env);
|
||||
}
|
||||
#endif
|
||||
|
||||
void tlb_flush(CPUState *env)
|
||||
{
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
int i;
|
||||
|
||||
/* must reset current TB so that interrupts cannot modify the
|
||||
links while we are modifying them */
|
||||
env->current_tb = NULL;
|
||||
|
||||
for(i = 0; i < CPU_TLB_SIZE; i++) {
|
||||
env->tlb_read[0][i].address = -1;
|
||||
env->tlb_write[0][i].address = -1;
|
||||
env->tlb_read[1][i].address = -1;
|
||||
env->tlb_write[1][i].address = -1;
|
||||
}
|
||||
#endif
|
||||
/* XXX: avoid flushing the TBs */
|
||||
page_unmap(env);
|
||||
}
|
||||
|
||||
static inline void tlb_flush_entry(CPUTLBEntry *tlb_entry, uint32_t addr)
|
||||
@@ -808,8 +818,11 @@ static inline void tlb_flush_entry(CPUTLBEntry *tlb_entry, uint32_t addr)
|
||||
|
||||
void tlb_flush_page(CPUState *env, uint32_t addr)
|
||||
{
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
int i;
|
||||
int i, flags;
|
||||
|
||||
/* must reset current TB so that interrupts cannot modify the
|
||||
links while we are modifying them */
|
||||
env->current_tb = NULL;
|
||||
|
||||
addr &= TARGET_PAGE_MASK;
|
||||
i = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
||||
@@ -817,23 +830,44 @@ void tlb_flush_page(CPUState *env, uint32_t addr)
|
||||
tlb_flush_entry(&env->tlb_write[0][i], addr);
|
||||
tlb_flush_entry(&env->tlb_read[1][i], addr);
|
||||
tlb_flush_entry(&env->tlb_write[1][i], addr);
|
||||
|
||||
flags = page_get_flags(addr);
|
||||
if (flags & PAGE_VALID) {
|
||||
#if !defined(CONFIG_SOFTMMU)
|
||||
munmap((void *)addr, TARGET_PAGE_SIZE);
|
||||
#endif
|
||||
page_set_flags(addr, addr + TARGET_PAGE_SIZE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* make all write to page 'addr' trigger a TLB exception to detect
|
||||
self modifying code */
|
||||
void tlb_flush_page_write(CPUState *env, uint32_t addr)
|
||||
{
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
int i;
|
||||
|
||||
addr &= TARGET_PAGE_MASK;
|
||||
i = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
||||
tlb_flush_entry(&env->tlb_write[0][i], addr);
|
||||
tlb_flush_entry(&env->tlb_write[1][i], addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void tlb_flush(CPUState *env)
|
||||
{
|
||||
}
|
||||
|
||||
void tlb_flush_page(CPUState *env, uint32_t addr)
|
||||
{
|
||||
}
|
||||
|
||||
void tlb_flush_page_write(CPUState *env, uint32_t addr)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_USER_ONLY) */
|
||||
|
||||
static inline unsigned long *physpage_find_alloc(unsigned int page)
|
||||
{
|
||||
unsigned long **lp, *p;
|
||||
|
138
gdbstub.c
138
gdbstub.c
@@ -248,6 +248,23 @@ static int put_packet(char *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* better than nothing for SOFTMMU : we use physical addresses */
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
static int memory_rw(uint8_t *buf, uint32_t addr, int len, int is_write)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
|
||||
if (addr >= phys_ram_size ||
|
||||
((int64_t)addr + len > phys_ram_size))
|
||||
return -1;
|
||||
ptr = phys_ram_base + addr;
|
||||
if (is_write)
|
||||
memcpy(ptr, buf, len);
|
||||
else
|
||||
memcpy(buf, ptr, len);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
static int memory_rw(uint8_t *buf, uint32_t addr, int len, int is_write)
|
||||
{
|
||||
int l, flags;
|
||||
@@ -276,13 +293,91 @@ static int memory_rw(uint8_t *buf, uint32_t addr, int len, int is_write)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_I386)
|
||||
|
||||
static void to_le32(uint8_t *p, int v)
|
||||
{
|
||||
p[0] = v;
|
||||
p[1] = v >> 8;
|
||||
p[2] = v >> 16;
|
||||
p[3] = v >> 24;
|
||||
}
|
||||
|
||||
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
||||
{
|
||||
int i, fpus;
|
||||
|
||||
for(i = 0; i < 8; i++) {
|
||||
to_le32(mem_buf + i * 4, env->regs[i]);
|
||||
}
|
||||
to_le32(mem_buf + 8 * 4, env->eip);
|
||||
to_le32(mem_buf + 9 * 4, env->eflags);
|
||||
to_le32(mem_buf + 10 * 4, env->segs[R_CS].selector);
|
||||
to_le32(mem_buf + 11 * 4, env->segs[R_SS].selector);
|
||||
to_le32(mem_buf + 12 * 4, env->segs[R_DS].selector);
|
||||
to_le32(mem_buf + 13 * 4, env->segs[R_ES].selector);
|
||||
to_le32(mem_buf + 14 * 4, env->segs[R_FS].selector);
|
||||
to_le32(mem_buf + 15 * 4, env->segs[R_GS].selector);
|
||||
/* XXX: convert floats */
|
||||
for(i = 0; i < 8; i++) {
|
||||
memcpy(mem_buf + 16 * 4 + i * 10, &env->fpregs[i], 10);
|
||||
}
|
||||
to_le32(mem_buf + 36 * 4, env->fpuc);
|
||||
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
|
||||
to_le32(mem_buf + 37 * 4, fpus);
|
||||
to_le32(mem_buf + 38 * 4, 0); /* XXX: convert tags */
|
||||
to_le32(mem_buf + 39 * 4, 0); /* fiseg */
|
||||
to_le32(mem_buf + 40 * 4, 0); /* fioff */
|
||||
to_le32(mem_buf + 41 * 4, 0); /* foseg */
|
||||
to_le32(mem_buf + 42 * 4, 0); /* fooff */
|
||||
to_le32(mem_buf + 43 * 4, 0); /* fop */
|
||||
return 44 * 4;
|
||||
}
|
||||
|
||||
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
||||
{
|
||||
uint32_t *registers = (uint32_t *)mem_buf;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 8; i++) {
|
||||
env->regs[i] = tswapl(registers[i]);
|
||||
}
|
||||
env->eip = registers[8];
|
||||
env->eflags = registers[9];
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
#define LOAD_SEG(index, sreg)\
|
||||
if (tswapl(registers[index]) != env->segs[sreg].selector)\
|
||||
cpu_x86_load_seg(env, sreg, tswapl(registers[index]));
|
||||
LOAD_SEG(10, R_CS);
|
||||
LOAD_SEG(11, R_SS);
|
||||
LOAD_SEG(12, R_DS);
|
||||
LOAD_SEG(13, R_ES);
|
||||
LOAD_SEG(14, R_FS);
|
||||
LOAD_SEG(15, R_GS);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* port = 0 means default port */
|
||||
int cpu_gdbstub(void *opaque, int (*main_loop)(void *opaque), int port)
|
||||
{
|
||||
CPUState *env;
|
||||
const char *p;
|
||||
int ret, ch, nb_regs, i, type;
|
||||
int ret, ch, reg_size, type;
|
||||
char buf[4096];
|
||||
uint8_t mem_buf[2000];
|
||||
uint32_t *registers;
|
||||
@@ -339,45 +434,16 @@ int cpu_gdbstub(void *opaque, int (*main_loop)(void *opaque), int port)
|
||||
break;
|
||||
case 'g':
|
||||
env = cpu_gdbstub_get_env(opaque);
|
||||
registers = (void *)mem_buf;
|
||||
#if defined(TARGET_I386)
|
||||
for(i = 0; i < 8; i++) {
|
||||
registers[i] = tswapl(env->regs[i]);
|
||||
}
|
||||
registers[8] = env->eip;
|
||||
registers[9] = env->eflags;
|
||||
registers[10] = env->segs[R_CS].selector;
|
||||
registers[11] = env->segs[R_SS].selector;
|
||||
registers[12] = env->segs[R_DS].selector;
|
||||
registers[13] = env->segs[R_ES].selector;
|
||||
registers[14] = env->segs[R_FS].selector;
|
||||
registers[15] = env->segs[R_GS].selector;
|
||||
nb_regs = 16;
|
||||
#endif
|
||||
memtohex(buf, (const uint8_t *)registers,
|
||||
sizeof(registers[0]) * nb_regs);
|
||||
reg_size = cpu_gdb_read_registers(env, mem_buf);
|
||||
memtohex(buf, mem_buf, reg_size);
|
||||
put_packet(buf);
|
||||
break;
|
||||
case 'G':
|
||||
env = cpu_gdbstub_get_env(opaque);
|
||||
registers = (void *)mem_buf;
|
||||
#if defined(TARGET_I386)
|
||||
hextomem((uint8_t *)registers, p, 16 * 4);
|
||||
for(i = 0; i < 8; i++) {
|
||||
env->regs[i] = tswapl(registers[i]);
|
||||
}
|
||||
env->eip = registers[8];
|
||||
env->eflags = registers[9];
|
||||
#define LOAD_SEG(index, sreg)\
|
||||
if (tswapl(registers[index]) != env->segs[sreg].selector)\
|
||||
cpu_x86_load_seg(env, sreg, tswapl(registers[index]));
|
||||
LOAD_SEG(10, R_CS);
|
||||
LOAD_SEG(11, R_SS);
|
||||
LOAD_SEG(12, R_DS);
|
||||
LOAD_SEG(13, R_ES);
|
||||
LOAD_SEG(14, R_FS);
|
||||
LOAD_SEG(15, R_GS);
|
||||
#endif
|
||||
len = strlen(p) / 2;
|
||||
hextomem((uint8_t *)registers, p, len);
|
||||
cpu_gdb_write_registers(env, mem_buf, len);
|
||||
put_packet("OK");
|
||||
break;
|
||||
case 'm':
|
||||
@@ -443,6 +509,8 @@ int cpu_gdbstub(void *opaque, int (*main_loop)(void *opaque), int port)
|
||||
put_packet("OK");
|
||||
} else if (!strncmp(p, "TStart", 6)) {
|
||||
/* start log (gdb 'tstart' command) */
|
||||
env = cpu_gdbstub_get_env(opaque);
|
||||
tb_flush(env);
|
||||
cpu_set_log(CPU_LOG_ALL);
|
||||
put_packet("OK");
|
||||
} else if (!strncmp(p, "TStop", 5)) {
|
||||
|
395
hw/dma.c
Normal file
395
hw/dma.c
Normal file
@@ -0,0 +1,395 @@
|
||||
/*
|
||||
* QEMU DMA emulation
|
||||
*
|
||||
* Copyright (c) 2003 Vassili Karpov (malc)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "vl.h"
|
||||
#include "cpu.h"
|
||||
|
||||
#define log(...) fprintf (stderr, "dma: " __VA_ARGS__)
|
||||
#ifdef DEBUG_DMA
|
||||
#define lwarn(...) fprintf (stderr, "dma: " __VA_ARGS__)
|
||||
#define linfo(...) fprintf (stderr, "dma: " __VA_ARGS__)
|
||||
#define ldebug(...) fprintf (stderr, "dma: " __VA_ARGS__)
|
||||
#else
|
||||
#define lwarn(...)
|
||||
#define linfo(...)
|
||||
#define ldebug(...)
|
||||
#endif
|
||||
|
||||
#define MEM_REAL(addr) ((addr)+(uint32_t)(phys_ram_base))
|
||||
#define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0])))
|
||||
|
||||
struct dma_regs {
|
||||
int now[2];
|
||||
uint16_t base[2];
|
||||
uint8_t mode;
|
||||
uint8_t page;
|
||||
uint8_t dack;
|
||||
uint8_t eop;
|
||||
DMA_read_handler read_handler;
|
||||
DMA_misc_handler misc_handler;
|
||||
};
|
||||
|
||||
#define ADDR 0
|
||||
#define COUNT 1
|
||||
|
||||
static struct dma_cont {
|
||||
uint8_t status;
|
||||
uint8_t command;
|
||||
uint8_t mask;
|
||||
uint8_t flip_flop;
|
||||
struct dma_regs regs[4];
|
||||
} dma_controllers[2];
|
||||
|
||||
enum {
|
||||
CMD_MEMORY_TO_MEMORY = 0x01,
|
||||
CMD_FIXED_ADDRESS = 0x02,
|
||||
CMD_BLOCK_CONTROLLER = 0x04,
|
||||
CMD_COMPRESSED_TIME = 0x08,
|
||||
CMD_CYCLIC_PRIORITY = 0x10,
|
||||
CMD_EXTENDED_WRITE = 0x20,
|
||||
CMD_LOW_DREQ = 0x40,
|
||||
CMD_LOW_DACK = 0x80,
|
||||
CMD_NOT_SUPPORTED = CMD_MEMORY_TO_MEMORY | CMD_FIXED_ADDRESS
|
||||
| CMD_COMPRESSED_TIME | CMD_CYCLIC_PRIORITY | CMD_EXTENDED_WRITE
|
||||
| CMD_LOW_DREQ | CMD_LOW_DACK
|
||||
|
||||
};
|
||||
|
||||
static void write_page (struct CPUX86State *env, uint32_t nport, uint32_t data)
|
||||
{
|
||||
int ichan;
|
||||
int ncont;
|
||||
static int channels[8] = {-1, 2, 3, 1, -1, -1, -1, 0};
|
||||
|
||||
ncont = nport > 0x87;
|
||||
ichan = channels[nport - 0x80 - (ncont << 3)];
|
||||
|
||||
if (-1 == ichan) {
|
||||
log ("invalid channel %#x %#x\n", nport, data);
|
||||
return;
|
||||
}
|
||||
|
||||
dma_controllers[ncont].regs[ichan].page = data;
|
||||
}
|
||||
|
||||
static void init_chan (int ncont, int ichan)
|
||||
{
|
||||
struct dma_regs *r;
|
||||
|
||||
r = dma_controllers[ncont].regs + ichan;
|
||||
r->now[ADDR] = r->base[0] << ncont;
|
||||
r->now[COUNT] = 0;
|
||||
}
|
||||
|
||||
static inline int getff (int ncont)
|
||||
{
|
||||
int ff;
|
||||
|
||||
ff = dma_controllers[ncont].flip_flop;
|
||||
dma_controllers[ncont].flip_flop = !ff;
|
||||
return ff;
|
||||
}
|
||||
|
||||
static uint32_t read_chan (struct CPUX86State *env, uint32_t nport)
|
||||
{
|
||||
int ff;
|
||||
int ncont, ichan, nreg;
|
||||
struct dma_regs *r;
|
||||
int val;
|
||||
|
||||
ncont = nport > 7;
|
||||
ichan = (nport >> (1 + ncont)) & 3;
|
||||
nreg = (nport >> ncont) & 1;
|
||||
r = dma_controllers[ncont].regs + ichan;
|
||||
|
||||
ff = getff (ncont);
|
||||
|
||||
if (nreg)
|
||||
val = (r->base[COUNT] << ncont) - r->now[COUNT];
|
||||
else
|
||||
val = r->now[ADDR] + r->now[COUNT];
|
||||
|
||||
return (val >> (ncont + (ff << 3))) & 0xff;
|
||||
}
|
||||
|
||||
static void write_chan (uint32_t nport, int size, uint32_t data)
|
||||
{
|
||||
int ncont, ichan, nreg;
|
||||
struct dma_regs *r;
|
||||
|
||||
ncont = nport > 7;
|
||||
ichan = (nport >> (1 + ncont)) & 3;
|
||||
nreg = (nport >> ncont) & 1;
|
||||
r = dma_controllers[ncont].regs + ichan;
|
||||
|
||||
if (2 == size) {
|
||||
r->base[nreg] = data;
|
||||
init_chan (ncont, ichan);
|
||||
}
|
||||
else {
|
||||
if (getff (ncont)) {
|
||||
r->base[nreg] = (r->base[nreg] & 0xff) | ((data << 8) & 0xff00);
|
||||
init_chan (ncont, ichan);
|
||||
}
|
||||
else {
|
||||
r->base[nreg] = (r->base[nreg] & 0xff00) | (data & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void write_chanb (struct CPUX86State *env, uint32_t nport, uint32_t data)
|
||||
{
|
||||
write_chan (nport, 1, data);
|
||||
}
|
||||
|
||||
static void write_chanw (struct CPUX86State *env, uint32_t nport, uint32_t data)
|
||||
{
|
||||
write_chan (nport, 2, data);
|
||||
}
|
||||
|
||||
static void write_cont (struct CPUX86State *env, uint32_t nport, uint32_t data)
|
||||
{
|
||||
int iport, ichan, ncont;
|
||||
struct dma_cont *d;
|
||||
|
||||
ncont = nport > 0xf;
|
||||
ichan = -1;
|
||||
|
||||
d = dma_controllers + ncont;
|
||||
if (ncont) {
|
||||
iport = ((nport - 0xd0) >> 1) + 8;
|
||||
}
|
||||
else {
|
||||
iport = nport;
|
||||
}
|
||||
|
||||
switch (iport) {
|
||||
case 8: /* command */
|
||||
if (data && (data | CMD_NOT_SUPPORTED)) {
|
||||
log ("command %#x not supported\n", data);
|
||||
goto error;
|
||||
}
|
||||
d->command = data;
|
||||
break;
|
||||
|
||||
case 9:
|
||||
ichan = data & 3;
|
||||
if (data & 4) {
|
||||
d->status |= 1 << (ichan + 4);
|
||||
}
|
||||
else {
|
||||
d->status &= ~(1 << (ichan + 4));
|
||||
}
|
||||
d->status &= ~(1 << ichan);
|
||||
break;
|
||||
|
||||
case 0xa: /* single mask */
|
||||
if (data & 4)
|
||||
d->mask |= 1 << (data & 3);
|
||||
else
|
||||
d->mask &= ~(1 << (data & 3));
|
||||
break;
|
||||
|
||||
case 0xb: /* mode */
|
||||
{
|
||||
#ifdef DMA_DEBUG
|
||||
int op;
|
||||
int ai;
|
||||
int dir;
|
||||
int opmode;
|
||||
|
||||
ichan = val & 3;
|
||||
op = (val >> 2) & 3;
|
||||
ai = (val >> 4) & 1;
|
||||
dir = (val >> 5) & 1;
|
||||
opmode = (val >> 6) & 3;
|
||||
|
||||
linfo ("ichan %d, op %d, ai %d, dir %d, opmode %d\n",
|
||||
ichan, op, ai, dir, opmode);
|
||||
#endif
|
||||
|
||||
d->regs[ichan].mode = data;
|
||||
break;
|
||||
}
|
||||
|
||||
case 0xc: /* clear flip flop */
|
||||
d->flip_flop = 0;
|
||||
break;
|
||||
|
||||
case 0xd: /* reset */
|
||||
d->flip_flop = 0;
|
||||
d->mask = ~0;
|
||||
d->status = 0;
|
||||
d->command = 0;
|
||||
break;
|
||||
|
||||
case 0xe: /* clear mask for all channels */
|
||||
d->mask = 0;
|
||||
break;
|
||||
|
||||
case 0xf: /* write mask for all channels */
|
||||
d->mask = data;
|
||||
break;
|
||||
|
||||
default:
|
||||
log ("dma: unknown iport %#x\n", iport);
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifdef DMA_DEBUG
|
||||
if (0xc != iport) {
|
||||
linfo ("nport %#06x, ncont %d, ichan % 2d, val %#06x\n",
|
||||
nport, d != dma_controllers, ichan, data);
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
|
||||
error:
|
||||
abort ();
|
||||
}
|
||||
|
||||
int DMA_get_channel_mode (int nchan)
|
||||
{
|
||||
return dma_controllers[nchan > 3].regs[nchan & 3].mode;
|
||||
}
|
||||
|
||||
void DMA_hold_DREQ (int nchan)
|
||||
{
|
||||
int ncont, ichan;
|
||||
|
||||
ncont = nchan > 3;
|
||||
ichan = nchan & 3;
|
||||
linfo ("held cont=%d chan=%d\n", ncont, ichan);
|
||||
dma_controllers[ncont].status |= 1 << (ichan + 4);
|
||||
}
|
||||
|
||||
void DMA_release_DREQ (int nchan)
|
||||
{
|
||||
int ncont, ichan;
|
||||
|
||||
ncont = nchan > 3;
|
||||
ichan = nchan & 3;
|
||||
linfo ("released cont=%d chan=%d\n", ncont, ichan);
|
||||
dma_controllers[ncont].status &= ~(1 << (ichan + 4));
|
||||
}
|
||||
|
||||
static void channel_run (int ncont, int ichan)
|
||||
{
|
||||
struct dma_regs *r;
|
||||
int n;
|
||||
int irq;
|
||||
uint32_t addr;
|
||||
/* int ai, dir; */
|
||||
|
||||
r = dma_controllers[ncont].regs + ichan;
|
||||
/* ai = r->mode & 16; */
|
||||
/* dir = r->mode & 32 ? -1 : 1; */
|
||||
|
||||
addr = MEM_REAL ((r->page << 16) | r->now[ADDR]);
|
||||
|
||||
irq = -1;
|
||||
n = r->read_handler (addr, (r->base[COUNT] << ncont) + (1 << ncont), &irq);
|
||||
r->now[COUNT] = n;
|
||||
|
||||
ldebug ("dma_pos %d irq %d size %d\n",
|
||||
n, irq, (r->base[1] << ncont) + (1 << ncont));
|
||||
|
||||
if (-1 != irq) {
|
||||
pic_set_irq (irq, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void DMA_run (void)
|
||||
{
|
||||
static int in_dma;
|
||||
struct dma_cont *d;
|
||||
int icont, ichan;
|
||||
|
||||
if (in_dma) {
|
||||
log ("attempt to re-enter dma\n");
|
||||
return;
|
||||
}
|
||||
|
||||
in_dma = 1;
|
||||
d = dma_controllers;
|
||||
|
||||
for (icont = 0; icont < 2; icont++, d++) {
|
||||
for (ichan = 0; ichan < 4; ichan++) {
|
||||
int mask;
|
||||
|
||||
mask = 1 << ichan;
|
||||
|
||||
if ((0 == (d->mask & mask)) && (0 != (d->status & (mask << 4))))
|
||||
channel_run (icont, ichan);
|
||||
}
|
||||
}
|
||||
in_dma = 0;
|
||||
}
|
||||
|
||||
void DMA_register_channel (int nchan,
|
||||
DMA_read_handler read_handler,
|
||||
DMA_misc_handler misc_handler)
|
||||
{
|
||||
struct dma_regs *r;
|
||||
int ichan, ncont;
|
||||
|
||||
ncont = nchan > 3;
|
||||
ichan = nchan & 3;
|
||||
|
||||
r = dma_controllers[ncont].regs + ichan;
|
||||
r->read_handler = read_handler;
|
||||
r->misc_handler = misc_handler;
|
||||
}
|
||||
|
||||
void DMA_init (void)
|
||||
{
|
||||
int i;
|
||||
int page_port_list[] = { 0x1, 0x2, 0x3, 0x7 };
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
register_ioport_write (i, 1, write_chanb, 1);
|
||||
register_ioport_write (i, 1, write_chanw, 2);
|
||||
|
||||
register_ioport_write (0xc0 + (i << 1), 1, write_chanb, 1);
|
||||
register_ioport_write (0xc0 + (i << 1), 1, write_chanw, 2);
|
||||
|
||||
register_ioport_read (i, 1, read_chan, 1);
|
||||
register_ioport_read (0xc0 + (i << 1), 1, read_chan, 2);
|
||||
}
|
||||
|
||||
for (i = 0; i < LENOFA (page_port_list); i++) {
|
||||
register_ioport_write (page_port_list[i] + 0x80, 1, write_page, 1);
|
||||
register_ioport_write (page_port_list[i] + 0x88, 1, write_page, 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
register_ioport_write (i + 8, 1, write_cont, 1);
|
||||
register_ioport_write (0xd0 + (i << 1), 1, write_cont, 1);
|
||||
}
|
||||
|
||||
write_cont (NULL, 0xd, 0);
|
||||
write_cont (NULL, 0xdd, 0);
|
||||
}
|
723
hw/sb16.c
Normal file
723
hw/sb16.c
Normal file
@@ -0,0 +1,723 @@
|
||||
/*
|
||||
* QEMU Soundblaster 16 emulation
|
||||
*
|
||||
* Copyright (c) 2003 Vassili Karpov (malc)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "vl.h"
|
||||
|
||||
#define MIN(a, b) ((a)>(b)?(b):(a))
|
||||
#define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0])))
|
||||
|
||||
#define DEREF(x) (void)x
|
||||
#define log(...) fprintf (stderr, "sb16: " __VA_ARGS__)
|
||||
#define Fail(...) do { \
|
||||
fprintf (stderr, "sb16: " __VA_ARGS__); \
|
||||
abort (); \
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG_SB16
|
||||
#define lwarn(...) fprintf (stderr, "sb16: " __VA_ARGS__)
|
||||
#define linfo(...) fprintf (stderr, "sb16: " __VA_ARGS__)
|
||||
#define ldebug(...) fprintf (stderr, "sb16: " __VA_ARGS__)
|
||||
#else
|
||||
#define lwarn(...)
|
||||
#define linfo(...)
|
||||
#define ldebug(...)
|
||||
#endif
|
||||
|
||||
#define IO_READ_PROTO(name) \
|
||||
uint32_t name (struct CPUX86State *env, uint32_t nport)
|
||||
#define IO_WRITE_PROTO(name) \
|
||||
void name (struct CPUX86State *env, uint32_t nport, uint32_t val)
|
||||
|
||||
static struct {
|
||||
int ver_lo;
|
||||
int ver_hi;
|
||||
int irq;
|
||||
int dma;
|
||||
int hdma;
|
||||
int port;
|
||||
int mix_block;
|
||||
} sb = {4, 5, 5, 1, 5, 0x220, -1};
|
||||
|
||||
static int mix_block, noirq;
|
||||
|
||||
static struct mixer {
|
||||
int nreg;
|
||||
uint8_t regs[0x83];
|
||||
} mixer;
|
||||
|
||||
static struct dsp {
|
||||
int in_index;
|
||||
int out_data_len;
|
||||
int fmt_stereo;
|
||||
int fmt_signed;
|
||||
int fmt_bits;
|
||||
int dma_auto;
|
||||
int dma_buffer_size;
|
||||
int fifo;
|
||||
int freq;
|
||||
int time_const;
|
||||
int speaker;
|
||||
int needed_bytes;
|
||||
int cmd;
|
||||
int dma_pos;
|
||||
int use_hdma;
|
||||
|
||||
int v2x6;
|
||||
|
||||
uint8_t in_data[10];
|
||||
uint8_t out_data[10];
|
||||
|
||||
int left_till_irq;
|
||||
} dsp;
|
||||
|
||||
#define nocmd ~0
|
||||
|
||||
static void log_dsp (const char *cap)
|
||||
{
|
||||
DEREF (cap);
|
||||
|
||||
linfo ("%c:%c:%d:%c:dmabuf=%d:pos=%d:freq=%d:timeconst=%d:speaker=%d\n",
|
||||
dsp.fmt_stereo ? 'S' : 'M',
|
||||
dsp.fmt_signed ? 'S' : 'U',
|
||||
dsp.fmt_bits,
|
||||
dsp.dma_auto ? 'a' : 's',
|
||||
dsp.dma_buffer_size,
|
||||
dsp.dma_pos,
|
||||
dsp.freq,
|
||||
dsp.time_const,
|
||||
dsp.speaker);
|
||||
}
|
||||
|
||||
static void control (int hold)
|
||||
{
|
||||
linfo ("%d high %d\n", hold, dsp.use_hdma);
|
||||
if (hold) {
|
||||
if (dsp.use_hdma)
|
||||
DMA_hold_DREQ (sb.hdma);
|
||||
else
|
||||
DMA_hold_DREQ (sb.dma);
|
||||
}
|
||||
else {
|
||||
if (dsp.use_hdma)
|
||||
DMA_release_DREQ (sb.hdma);
|
||||
else
|
||||
DMA_release_DREQ (sb.dma);
|
||||
}
|
||||
}
|
||||
|
||||
static void dma_cmd (uint8_t cmd, uint8_t d0, int dma_len)
|
||||
{
|
||||
int bps;
|
||||
audfmt_e fmt;
|
||||
|
||||
dsp.use_hdma = cmd < 0xc0;
|
||||
dsp.fifo = (cmd >> 1) & 1;
|
||||
dsp.dma_auto = (cmd >> 2) & 1;
|
||||
|
||||
switch (cmd >> 4) {
|
||||
case 11:
|
||||
dsp.fmt_bits = 16;
|
||||
break;
|
||||
|
||||
case 12:
|
||||
dsp.fmt_bits = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
dsp.fmt_signed = (d0 >> 4) & 1;
|
||||
dsp.fmt_stereo = (d0 >> 5) & 1;
|
||||
|
||||
if (-1 != dsp.time_const) {
|
||||
int tmp;
|
||||
|
||||
tmp = 256 - dsp.time_const;
|
||||
dsp.freq = (1000000 + (tmp / 2)) / tmp;
|
||||
}
|
||||
bps = 1 << (16 == dsp.fmt_bits);
|
||||
|
||||
if (-1 != dma_len)
|
||||
dsp.dma_buffer_size = (dma_len + 1) * bps;
|
||||
|
||||
linfo ("frequency %d, stereo %d, signed %d, bits %d, size %d, auto %d\n",
|
||||
dsp.freq, dsp.fmt_stereo, dsp.fmt_signed, dsp.fmt_bits,
|
||||
dsp.dma_buffer_size, dsp.dma_auto);
|
||||
|
||||
if (16 == dsp.fmt_bits) {
|
||||
if (dsp.fmt_signed) {
|
||||
fmt = AUD_FMT_S16;
|
||||
}
|
||||
else {
|
||||
fmt = AUD_FMT_U16;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dsp.fmt_signed) {
|
||||
fmt = AUD_FMT_S8;
|
||||
}
|
||||
else {
|
||||
fmt = AUD_FMT_U8;
|
||||
}
|
||||
}
|
||||
|
||||
dsp.dma_pos = 0;
|
||||
dsp.left_till_irq = dsp.dma_buffer_size;
|
||||
|
||||
if (sb.mix_block) {
|
||||
mix_block = sb.mix_block;
|
||||
}
|
||||
else {
|
||||
int align;
|
||||
|
||||
align = bps << dsp.fmt_stereo;
|
||||
mix_block = ((dsp.freq * align) / 100) & ~(align - 1);
|
||||
}
|
||||
|
||||
AUD_reset (dsp.freq, 1 << dsp.fmt_stereo, fmt);
|
||||
control (1);
|
||||
dsp.speaker = 1;
|
||||
}
|
||||
|
||||
static void command (uint8_t cmd)
|
||||
{
|
||||
char *msg;
|
||||
|
||||
msg = (char *)-1;
|
||||
|
||||
linfo ("%#x\n", cmd);
|
||||
|
||||
if (cmd > 0xaf && cmd < 0xd0) {
|
||||
if (cmd & 8)
|
||||
goto error;
|
||||
|
||||
switch (cmd >> 4) {
|
||||
case 11:
|
||||
case 12:
|
||||
break;
|
||||
default:
|
||||
msg = "wrong bits";
|
||||
goto error;
|
||||
}
|
||||
dsp.needed_bytes = 3;
|
||||
}
|
||||
else {
|
||||
switch (cmd) {
|
||||
case 0x10:
|
||||
dsp.needed_bytes = 1;
|
||||
break;
|
||||
|
||||
case 0x14:
|
||||
dsp.needed_bytes = 2;
|
||||
dsp.dma_buffer_size = 0;
|
||||
break;
|
||||
|
||||
case 0x20:
|
||||
dsp.out_data[dsp.out_data_len++] = 0xff;
|
||||
break;
|
||||
|
||||
case 0x35:
|
||||
lwarn ("MIDI commands not implemented\n");
|
||||
break;
|
||||
|
||||
case 0x40:
|
||||
dsp.freq = -1;
|
||||
dsp.time_const = -1;
|
||||
dsp.needed_bytes = 1;
|
||||
break;
|
||||
|
||||
case 0x41:
|
||||
case 0x42:
|
||||
dsp.freq = -1;
|
||||
dsp.time_const = -1;
|
||||
dsp.needed_bytes = 2;
|
||||
break;
|
||||
|
||||
case 0x47: /* Continue Auto-Initialize DMA 16bit */
|
||||
break;
|
||||
|
||||
case 0x48:
|
||||
dsp.needed_bytes = 2;
|
||||
break;
|
||||
|
||||
case 0x27: /* ????????? */
|
||||
case 0x4e:
|
||||
return;
|
||||
|
||||
case 0x80:
|
||||
cmd = nocmd;
|
||||
break;
|
||||
|
||||
case 0x90:
|
||||
case 0x91:
|
||||
{
|
||||
uint8_t d0;
|
||||
|
||||
d0 = 4;
|
||||
if (dsp.fmt_signed) d0 |= 16;
|
||||
if (dsp.fmt_stereo) d0 |= 32;
|
||||
dma_cmd (cmd == 0x90 ? 0xc4 : 0xc0, d0, -1);
|
||||
cmd = nocmd;
|
||||
break;
|
||||
}
|
||||
|
||||
case 0xd0: /* XXX */
|
||||
control (0);
|
||||
return;
|
||||
|
||||
case 0xd1:
|
||||
dsp.speaker = 1;
|
||||
break;
|
||||
|
||||
case 0xd3:
|
||||
dsp.speaker = 0;
|
||||
return;
|
||||
|
||||
case 0xd4:
|
||||
control (1);
|
||||
break;
|
||||
|
||||
case 0xd5:
|
||||
control (0);
|
||||
break;
|
||||
|
||||
case 0xd6:
|
||||
control (1);
|
||||
break;
|
||||
|
||||
case 0xd9:
|
||||
control (0);
|
||||
dsp.dma_auto = 0;
|
||||
return;
|
||||
|
||||
case 0xda:
|
||||
control (0);
|
||||
dsp.dma_auto = 0;
|
||||
break;
|
||||
|
||||
case 0xe0:
|
||||
dsp.needed_bytes = 1;
|
||||
break;
|
||||
|
||||
case 0xe1:
|
||||
dsp.out_data[dsp.out_data_len++] = sb.ver_lo;
|
||||
dsp.out_data[dsp.out_data_len++] = sb.ver_hi;
|
||||
return;
|
||||
|
||||
case 0xf2:
|
||||
dsp.out_data[dsp.out_data_len++] = 0xaa;
|
||||
mixer.regs[0x82] |= 1;
|
||||
pic_set_irq (sb.irq, 1);
|
||||
return;
|
||||
|
||||
default:
|
||||
msg = "is unknown";
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
dsp.cmd = cmd;
|
||||
return;
|
||||
|
||||
error:
|
||||
Fail ("%#x %s", cmd, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
static void complete (void)
|
||||
{
|
||||
linfo ("complete command %#x, in_index %d, needed_bytes %d\n",
|
||||
dsp.cmd, dsp.in_index, dsp.needed_bytes);
|
||||
|
||||
if (dsp.cmd > 0xaf && dsp.cmd < 0xd0) {
|
||||
int d0, d1, d2;
|
||||
|
||||
d0 = dsp.in_data[0];
|
||||
d1 = dsp.in_data[1];
|
||||
d2 = dsp.in_data[2];
|
||||
|
||||
ldebug ("d0 = %d, d1 = %d, d2 = %d\n",
|
||||
d0, d1, d2);
|
||||
dma_cmd (dsp.cmd, d0, d1 + (d2 << 8));
|
||||
}
|
||||
else {
|
||||
switch (dsp.cmd) {
|
||||
|
||||
case 0x10:
|
||||
break;
|
||||
|
||||
case 0x14:
|
||||
{
|
||||
int d0, d1;
|
||||
int save_left;
|
||||
int save_pos;
|
||||
|
||||
d0 = dsp.in_data[0];
|
||||
d1 = dsp.in_data[1];
|
||||
|
||||
save_left = dsp.left_till_irq;
|
||||
save_pos = dsp.dma_pos;
|
||||
dma_cmd (0xc0, 0, d0 + (d1 << 8));
|
||||
dsp.left_till_irq = save_left;
|
||||
dsp.dma_pos = save_pos;
|
||||
|
||||
linfo ("set buffer size data[%d, %d] %d pos %d\n",
|
||||
d0, d1, dsp.dma_buffer_size, dsp.dma_pos);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x40:
|
||||
dsp.time_const = dsp.in_data[0];
|
||||
linfo ("set time const %d\n", dsp.time_const);
|
||||
break;
|
||||
|
||||
case 0x41:
|
||||
case 0x42:
|
||||
dsp.freq = dsp.in_data[1] + (dsp.in_data[0] << 8);
|
||||
linfo ("set freq %#x, %#x = %d\n",
|
||||
dsp.in_data[1], dsp.in_data[0], dsp.freq);
|
||||
break;
|
||||
|
||||
case 0x48:
|
||||
dsp.dma_buffer_size = dsp.in_data[1] + (dsp.in_data[0] << 8);
|
||||
linfo ("set dma len %#x, %#x = %d\n",
|
||||
dsp.in_data[1], dsp.in_data[0], dsp.dma_buffer_size);
|
||||
break;
|
||||
|
||||
case 0xe0:
|
||||
dsp.out_data_len = 1;
|
||||
linfo ("data = %#x\n", dsp.in_data[0]);
|
||||
dsp.out_data[0] = dsp.in_data[0] ^ 0xff;
|
||||
break;
|
||||
|
||||
default:
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
dsp.cmd = -1;
|
||||
return;
|
||||
|
||||
error:
|
||||
Fail ("unrecognized command %#x", dsp.cmd);
|
||||
}
|
||||
|
||||
static IO_WRITE_PROTO (dsp_write)
|
||||
{
|
||||
int iport;
|
||||
|
||||
iport = nport - sb.port;
|
||||
|
||||
switch (iport) {
|
||||
case 0x6:
|
||||
if (0 == val)
|
||||
dsp.v2x6 = 0;
|
||||
else if ((1 == val) && (0 == dsp.v2x6)) {
|
||||
dsp.v2x6 = 1;
|
||||
dsp.out_data[dsp.out_data_len++] = 0xaa;
|
||||
}
|
||||
else
|
||||
dsp.v2x6 = ~0;
|
||||
break;
|
||||
|
||||
case 0xc: /* write data or command | write status */
|
||||
if (0 == dsp.needed_bytes) {
|
||||
command (val);
|
||||
if (0 == dsp.needed_bytes) {
|
||||
log_dsp (__func__);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dsp.in_data[dsp.in_index++] = val;
|
||||
if (dsp.in_index == dsp.needed_bytes) {
|
||||
dsp.needed_bytes = 0;
|
||||
dsp.in_index = 0;
|
||||
complete ();
|
||||
log_dsp (__func__);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Fail ("(nport=%#x, val=%#x)", nport, val);
|
||||
}
|
||||
}
|
||||
|
||||
static IO_READ_PROTO (dsp_read)
|
||||
{
|
||||
char *msg;
|
||||
int iport, retval;
|
||||
|
||||
msg = (char *) -1;
|
||||
iport = nport - sb.port;
|
||||
|
||||
switch (iport) {
|
||||
|
||||
case 0x6: /* reset */
|
||||
return 0;
|
||||
|
||||
case 0xa: /* read data */
|
||||
if (dsp.out_data_len) {
|
||||
retval = dsp.out_data[--dsp.out_data_len];
|
||||
}
|
||||
else {
|
||||
#if 1
|
||||
lwarn ("empty output buffer\n");
|
||||
retval = 0;
|
||||
#else
|
||||
msg = "empty output buffer";
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case 0xc: /* 0 can write */
|
||||
retval = 0;
|
||||
break;
|
||||
|
||||
case 0xd: /* timer interrupt clear */
|
||||
goto error;
|
||||
|
||||
case 0xe: /* data available status | irq 8 ack */
|
||||
retval = (0 == dsp.out_data_len) ? 0 : 0x80;
|
||||
break;
|
||||
|
||||
case 0xf: /* irq 16 ack */
|
||||
retval = 0xff;
|
||||
mixer.regs[0x82] &= ~2;
|
||||
ldebug ("16 ack\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((0xc != iport) && (0xe != iport)) {
|
||||
ldebug ("(nport=%#x, size=%d) iport %#x = %#x\n",
|
||||
nport, size, iport, retval);
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
||||
error:
|
||||
Fail ("(nport=%#x) %s", nport, msg);
|
||||
}
|
||||
|
||||
static IO_WRITE_PROTO(mixer_write_indexb)
|
||||
{
|
||||
mixer.nreg = val & 0xff;
|
||||
}
|
||||
|
||||
static IO_WRITE_PROTO(mixer_write_datab)
|
||||
{
|
||||
mixer.regs[mixer.nreg] = val;
|
||||
}
|
||||
|
||||
static IO_WRITE_PROTO(mixer_write_indexw)
|
||||
{
|
||||
mixer_write_indexb (env, nport, val & 0xff);
|
||||
mixer_write_datab (env, nport, (val >> 8) & 0xff);
|
||||
}
|
||||
|
||||
static IO_READ_PROTO(mixer_read)
|
||||
{
|
||||
return mixer.regs[mixer.nreg];
|
||||
}
|
||||
|
||||
void SB16_run (void)
|
||||
{
|
||||
if (0 == dsp.speaker)
|
||||
return;
|
||||
|
||||
AUD_run ();
|
||||
}
|
||||
|
||||
static int write_audio (uint32_t addr, int len, int size)
|
||||
{
|
||||
int temp, net;
|
||||
|
||||
temp = size;
|
||||
|
||||
net = 0;
|
||||
|
||||
while (temp) {
|
||||
int left_till_end;
|
||||
int to_copy;
|
||||
int copied;
|
||||
|
||||
left_till_end = len - dsp.dma_pos;
|
||||
|
||||
to_copy = MIN (temp, left_till_end);
|
||||
|
||||
copied = AUD_write ((void *) (addr + dsp.dma_pos), to_copy);
|
||||
|
||||
temp -= copied;
|
||||
dsp.dma_pos += copied;
|
||||
|
||||
if (dsp.dma_pos == len) {
|
||||
dsp.dma_pos = 0;
|
||||
}
|
||||
|
||||
net += copied;
|
||||
|
||||
if (copied != to_copy)
|
||||
return net;
|
||||
}
|
||||
|
||||
return net;
|
||||
}
|
||||
|
||||
static int SB_read_DMA (uint32_t addr, int size, int *_irq)
|
||||
{
|
||||
int free, till, copy, written;
|
||||
|
||||
if (0 == dsp.speaker)
|
||||
return 0;
|
||||
|
||||
if (dsp.left_till_irq < 0) {
|
||||
dsp.left_till_irq += dsp.dma_buffer_size;
|
||||
return dsp.dma_pos;
|
||||
}
|
||||
|
||||
free = AUD_get_free ();
|
||||
|
||||
if ((free <= 0) || (0 == size)) {
|
||||
return dsp.dma_pos;
|
||||
}
|
||||
|
||||
if (mix_block > 0) {
|
||||
copy = MIN (free, mix_block);
|
||||
}
|
||||
else {
|
||||
copy = free;
|
||||
}
|
||||
|
||||
till = dsp.left_till_irq;
|
||||
|
||||
ldebug ("addr:%#010x free:%d till:%d size:%d\n",
|
||||
addr, free, till, size);
|
||||
/* linfo ("pos %d free %d size %d till %d copy %d auto %d noirq %d\n", */
|
||||
/* dsp.dma_pos, free, size, till, copy, dsp.dma_auto, noirq); */
|
||||
if (till <= copy) {
|
||||
if (0 == dsp.dma_auto) {
|
||||
copy = till;
|
||||
}
|
||||
}
|
||||
|
||||
written = write_audio (addr, size, copy);
|
||||
dsp.left_till_irq -= written;
|
||||
AUD_adjust_estimate (free - written);
|
||||
|
||||
if (dsp.left_till_irq <= 0) {
|
||||
mixer.regs[0x82] |= mixer.regs[0x80];
|
||||
if (0 == noirq)
|
||||
*_irq = sb.irq;
|
||||
|
||||
if (0 == dsp.dma_auto) {
|
||||
control (0);
|
||||
}
|
||||
}
|
||||
|
||||
ldebug ("pos %5d free %5d size %5d till % 5d copy %5d dma size %5d\n",
|
||||
dsp.dma_pos, free, size, dsp.left_till_irq, copy,
|
||||
dsp.dma_buffer_size);
|
||||
|
||||
if (dsp.left_till_irq <= 0) {
|
||||
dsp.left_till_irq += dsp.dma_buffer_size;
|
||||
}
|
||||
|
||||
return dsp.dma_pos;
|
||||
}
|
||||
|
||||
static int dma_misc_handler (int moo)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int magic_of_irq (int irq)
|
||||
{
|
||||
switch (irq) {
|
||||
case 2:
|
||||
return 1;
|
||||
case 5:
|
||||
return 2;
|
||||
case 7:
|
||||
return 4;
|
||||
case 10:
|
||||
return 8;
|
||||
default:
|
||||
log ("bad irq %d\n", irq);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
static int irq_of_magic (int magic)
|
||||
{
|
||||
switch (magic) {
|
||||
case 1:
|
||||
return 2;
|
||||
case 2:
|
||||
return 5;
|
||||
case 4:
|
||||
return 7;
|
||||
case 8:
|
||||
return 10;
|
||||
default:
|
||||
log ("bad irq magic %d\n", magic);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
void SB16_init (void)
|
||||
{
|
||||
int i;
|
||||
static const uint8_t dsp_write_ports[] = {0x6, 0xc};
|
||||
static const uint8_t dsp_read_ports[] = {0x6, 0xa, 0xc, 0xd, 0xe, 0xf};
|
||||
|
||||
mixer.regs[0x0e] = ~0;
|
||||
mixer.regs[0x80] = magic_of_irq (sb.irq);
|
||||
mixer.regs[0x81] = 0x20 | (sb.dma << 1);
|
||||
|
||||
DEREF (irq_of_magic);
|
||||
|
||||
for (i = 0x30; i < 0x48; i++) {
|
||||
mixer.regs[i] = 0x20;
|
||||
}
|
||||
|
||||
for (i = 0; i < LENOFA (dsp_write_ports); i++) {
|
||||
register_ioport_write (sb.port + dsp_write_ports[i], 1, dsp_write, 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < LENOFA (dsp_read_ports); i++) {
|
||||
register_ioport_read (sb.port + dsp_read_ports[i], 1, dsp_read, 1);
|
||||
}
|
||||
|
||||
register_ioport_write (sb.port + 0x4, 1, mixer_write_indexb, 1);
|
||||
register_ioport_write (sb.port + 0x4, 1, mixer_write_indexw, 2);
|
||||
register_ioport_read (sb.port + 0x5, 1, mixer_read, 1);
|
||||
register_ioport_write (sb.port + 0x5, 1, mixer_write_datab, 1);
|
||||
|
||||
DMA_register_channel (sb.hdma, SB_read_DMA, dma_misc_handler);
|
||||
DMA_register_channel (sb.dma, SB_read_DMA, dma_misc_handler);
|
||||
}
|
80
hw/vga.c
80
hw/vga.c
@@ -50,6 +50,10 @@
|
||||
|
||||
//#define DEBUG_VGA
|
||||
//#define DEBUG_VGA_MEM
|
||||
//#define DEBUG_VGA_REG
|
||||
|
||||
//#define DEBUG_S3
|
||||
#define CONFIG_S3VGA
|
||||
|
||||
#define MSR_COLOR_EMULATION 0x01
|
||||
#define MSR_PAGE_SELECT 0x20
|
||||
@@ -141,12 +145,24 @@ static const uint8_t gr_mask[16] = {
|
||||
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
|
||||
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) ))
|
||||
|
||||
#ifdef WORD_BIGENDIAN
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define PAT(x) cbswap_32(x)
|
||||
#else
|
||||
#define PAT(x) (x)
|
||||
#endif
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define BIG 1
|
||||
#else
|
||||
#define BIG 0
|
||||
#endif
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define GET_PLANE(data, p) (((data) >> (24 - (p) * 8)) & 0xff)
|
||||
#else
|
||||
#define GET_PLANE(data, p) (((data) >> ((p) * 8)) & 0xff)
|
||||
#endif
|
||||
|
||||
static const uint32_t mask16[16] = {
|
||||
PAT(0x00000000),
|
||||
PAT(0x000000ff),
|
||||
@@ -168,7 +184,7 @@ static const uint32_t mask16[16] = {
|
||||
|
||||
#undef PAT
|
||||
|
||||
#ifdef WORD_BIGENDIAN
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define PAT(x) (x)
|
||||
#else
|
||||
#define PAT(x) cbswap_32(x)
|
||||
@@ -240,6 +256,9 @@ static uint32_t vga_ioport_read(CPUX86State *env, uint32_t addr)
|
||||
break;
|
||||
case 0x3c5:
|
||||
val = s->sr[s->sr_index];
|
||||
#ifdef DEBUG_VGA_REG
|
||||
printf("vga: read SR%x = 0x%02x\n", s->sr_index, val);
|
||||
#endif
|
||||
break;
|
||||
case 0x3c7:
|
||||
val = s->dac_state;
|
||||
@@ -262,6 +281,9 @@ static uint32_t vga_ioport_read(CPUX86State *env, uint32_t addr)
|
||||
break;
|
||||
case 0x3cf:
|
||||
val = s->gr[s->gr_index];
|
||||
#ifdef DEBUG_VGA_REG
|
||||
printf("vga: read GR%x = 0x%02x\n", s->gr_index, val);
|
||||
#endif
|
||||
break;
|
||||
case 0x3b4:
|
||||
case 0x3d4:
|
||||
@@ -270,6 +292,14 @@ static uint32_t vga_ioport_read(CPUX86State *env, uint32_t addr)
|
||||
case 0x3b5:
|
||||
case 0x3d5:
|
||||
val = s->cr[s->cr_index];
|
||||
#ifdef DEBUG_VGA_REG
|
||||
printf("vga: read CR%x = 0x%02x\n", s->cr_index, val);
|
||||
#endif
|
||||
#ifdef DEBUG_S3
|
||||
if (s->cr_index >= 0x20)
|
||||
printf("S3: CR read index=0x%x val=0x%x\n",
|
||||
s->cr_index, val);
|
||||
#endif
|
||||
break;
|
||||
case 0x3ba:
|
||||
case 0x3da:
|
||||
@@ -342,6 +372,9 @@ static void vga_ioport_write(CPUX86State *env, uint32_t addr, uint32_t val)
|
||||
s->sr_index = val & 7;
|
||||
break;
|
||||
case 0x3c5:
|
||||
#ifdef DEBUG_VGA_REG
|
||||
printf("vga: write SR%x = 0x%02x\n", s->sr_index, val);
|
||||
#endif
|
||||
s->sr[s->sr_index] = val & sr_mask[s->sr_index];
|
||||
break;
|
||||
case 0x3c7:
|
||||
@@ -366,6 +399,9 @@ static void vga_ioport_write(CPUX86State *env, uint32_t addr, uint32_t val)
|
||||
s->gr_index = val & 0x0f;
|
||||
break;
|
||||
case 0x3cf:
|
||||
#ifdef DEBUG_VGA_REG
|
||||
printf("vga: write GR%x = 0x%02x\n", s->gr_index, val);
|
||||
#endif
|
||||
s->gr[s->gr_index] = val & gr_mask[s->gr_index];
|
||||
break;
|
||||
case 0x3b4:
|
||||
@@ -374,6 +410,9 @@ static void vga_ioport_write(CPUX86State *env, uint32_t addr, uint32_t val)
|
||||
break;
|
||||
case 0x3b5:
|
||||
case 0x3d5:
|
||||
#ifdef DEBUG_VGA_REG
|
||||
printf("vga: write CR%x = 0x%02x\n", s->cr_index, val);
|
||||
#endif
|
||||
/* handle CR0-7 protection */
|
||||
if ((s->cr[11] & 0x80) && s->cr_index <= 7) {
|
||||
/* can always write bit 4 of CR7 */
|
||||
@@ -391,6 +430,7 @@ static void vga_ioport_write(CPUX86State *env, uint32_t addr, uint32_t val)
|
||||
s->cr[s->cr_index] = val;
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_S3VGA
|
||||
/* S3 registers */
|
||||
case 0x2d:
|
||||
case 0x2e:
|
||||
@@ -410,10 +450,16 @@ static void vga_ioport_write(CPUX86State *env, uint32_t addr, uint32_t val)
|
||||
v = val & 3;
|
||||
s->cr[0x69] = (s->cr[69] & ~0x0c) | (v << 2);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
s->cr[s->cr_index] = val;
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG_S3
|
||||
if (s->cr_index >= 0x20)
|
||||
printf("S3: CR write index=0x%x val=0x%x\n",
|
||||
s->cr_index, val);
|
||||
#endif
|
||||
break;
|
||||
case 0x3ba:
|
||||
case 0x3da:
|
||||
@@ -465,11 +511,7 @@ static uint32_t vga_mem_readb(uint32_t addr)
|
||||
if (!(s->gr[5] & 0x08)) {
|
||||
/* read mode 0 */
|
||||
plane = s->gr[4];
|
||||
#ifdef WORD_BIGENDIAN
|
||||
ret = (s->latch >> (24 - (plane * 8))) & 0xff;
|
||||
#else
|
||||
ret = (s->latch >> (plane * 8)) & 0xff;
|
||||
#endif
|
||||
ret = GET_PLANE(s->latch, plane);
|
||||
} else {
|
||||
/* read mode 1 */
|
||||
ret = (s->latch ^ mask16[s->gr[2]]) & mask16[s->gr[7]];
|
||||
@@ -499,7 +541,6 @@ static uint32_t vga_mem_readl(uint32_t addr)
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
/* called for accesses between 0xa0000 and 0xc0000 */
|
||||
void vga_mem_writeb(uint32_t addr, uint32_t val)
|
||||
{
|
||||
@@ -580,7 +621,7 @@ void vga_mem_writeb(uint32_t addr, uint32_t val)
|
||||
case 3:
|
||||
/* rotate */
|
||||
b = s->gr[3] & 7;
|
||||
val = ((val >> b) | (val << (8 - b)));
|
||||
val = (val >> b) | (val << (8 - b));
|
||||
|
||||
bit_mask = s->gr[8] & val;
|
||||
val = mask16[s->gr[0]];
|
||||
@@ -641,18 +682,6 @@ void vga_mem_writel(uint32_t addr, uint32_t val)
|
||||
vga_mem_writeb(addr + 3, (val >> 24) & 0xff);
|
||||
}
|
||||
|
||||
#ifdef WORD_BIGENDIAN
|
||||
#define BIG 1
|
||||
#else
|
||||
#define BIG 0
|
||||
#endif
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define GET_PLANE(data, p) (((data) >> (24 - (p) * 8)) & 0xff)
|
||||
#else
|
||||
#define GET_PLANE(data, p) (((data) >> ((p) * 8)) & 0xff)
|
||||
#endif
|
||||
|
||||
typedef void vga_draw_glyph8_func(uint8_t *d, int linesize,
|
||||
const uint8_t *font_ptr, int h,
|
||||
uint32_t fgcol, uint32_t bgcol);
|
||||
@@ -791,15 +820,20 @@ static int update_basic_params(VGAState *s)
|
||||
|
||||
full_update = 0;
|
||||
/* compute line_offset in bytes */
|
||||
line_offset = s->cr[0x13];
|
||||
#ifdef CONFIG_S3VGA
|
||||
v = (s->cr[0x51] >> 4) & 3; /* S3 extension */
|
||||
if (v == 0)
|
||||
v = (s->cr[0x43] >> 2) & 1; /* S3 extension */
|
||||
line_offset = s->cr[0x13] | (v << 8);
|
||||
line_offset |= (v << 8);
|
||||
#endif
|
||||
line_offset <<= 3;
|
||||
|
||||
/* starting address */
|
||||
start_addr = s->cr[0x0d] | (s->cr[0x0c] << 8);
|
||||
#ifdef CONFIG_S3VGA
|
||||
start_addr |= (s->cr[0x69] & 0x1f) << 16; /* S3 extension */
|
||||
#endif
|
||||
|
||||
/* line compare */
|
||||
line_compare = s->cr[0x18] |
|
||||
@@ -1294,11 +1328,13 @@ void vga_update_display(void)
|
||||
void vga_reset(VGAState *s)
|
||||
{
|
||||
memset(s, 0, sizeof(VGAState));
|
||||
#ifdef CONFIG_S3VGA
|
||||
/* chip ID for 8c968 */
|
||||
s->cr[0x2d] = 0x88;
|
||||
s->cr[0x2e] = 0xb0;
|
||||
s->cr[0x2f] = 0x01; /* XXX: check revision code */
|
||||
s->cr[0x30] = 0xe1;
|
||||
#endif
|
||||
s->graphic_mode = -1; /* force full update */
|
||||
}
|
||||
|
||||
|
10
i386.ld
10
i386.ld
@@ -53,6 +53,16 @@ SECTIONS
|
||||
_etext = .;
|
||||
PROVIDE (etext = .);
|
||||
.fini : { *(.fini) } =0x47ff041f
|
||||
. = ALIGN(32 / 8);
|
||||
PROVIDE (__preinit_array_start = .);
|
||||
.preinit_array : { *(.preinit_array) }
|
||||
PROVIDE (__preinit_array_end = .);
|
||||
PROVIDE (__init_array_start = .);
|
||||
.init_array : { *(.init_array) }
|
||||
PROVIDE (__init_array_end = .);
|
||||
PROVIDE (__fini_array_start = .);
|
||||
.fini_array : { *(.fini_array) }
|
||||
PROVIDE (__fini_array_end = .);
|
||||
.rodata : { *(.rodata) *(.gnu.linkonce.r*) }
|
||||
.rodata1 : { *(.rodata1) }
|
||||
.reginfo : { *(.reginfo) }
|
||||
|
215
linux-user/arm/termbits.h
Normal file
215
linux-user/arm/termbits.h
Normal file
@@ -0,0 +1,215 @@
|
||||
/* from asm/termbits.h */
|
||||
/* NOTE: exactly the same as i386 */
|
||||
|
||||
#define TARGET_NCCS 19
|
||||
|
||||
struct target_termios {
|
||||
unsigned int c_iflag; /* input mode flags */
|
||||
unsigned int c_oflag; /* output mode flags */
|
||||
unsigned int c_cflag; /* control mode flags */
|
||||
unsigned int c_lflag; /* local mode flags */
|
||||
unsigned char c_line; /* line discipline */
|
||||
unsigned char c_cc[TARGET_NCCS]; /* control characters */
|
||||
};
|
||||
|
||||
/* c_iflag bits */
|
||||
#define TARGET_IGNBRK 0000001
|
||||
#define TARGET_BRKINT 0000002
|
||||
#define TARGET_IGNPAR 0000004
|
||||
#define TARGET_PARMRK 0000010
|
||||
#define TARGET_INPCK 0000020
|
||||
#define TARGET_ISTRIP 0000040
|
||||
#define TARGET_INLCR 0000100
|
||||
#define TARGET_IGNCR 0000200
|
||||
#define TARGET_ICRNL 0000400
|
||||
#define TARGET_IUCLC 0001000
|
||||
#define TARGET_IXON 0002000
|
||||
#define TARGET_IXANY 0004000
|
||||
#define TARGET_IXOFF 0010000
|
||||
#define TARGET_IMAXBEL 0020000
|
||||
|
||||
/* c_oflag bits */
|
||||
#define TARGET_OPOST 0000001
|
||||
#define TARGET_OLCUC 0000002
|
||||
#define TARGET_ONLCR 0000004
|
||||
#define TARGET_OCRNL 0000010
|
||||
#define TARGET_ONOCR 0000020
|
||||
#define TARGET_ONLRET 0000040
|
||||
#define TARGET_OFILL 0000100
|
||||
#define TARGET_OFDEL 0000200
|
||||
#define TARGET_NLDLY 0000400
|
||||
#define TARGET_NL0 0000000
|
||||
#define TARGET_NL1 0000400
|
||||
#define TARGET_CRDLY 0003000
|
||||
#define TARGET_CR0 0000000
|
||||
#define TARGET_CR1 0001000
|
||||
#define TARGET_CR2 0002000
|
||||
#define TARGET_CR3 0003000
|
||||
#define TARGET_TABDLY 0014000
|
||||
#define TARGET_TAB0 0000000
|
||||
#define TARGET_TAB1 0004000
|
||||
#define TARGET_TAB2 0010000
|
||||
#define TARGET_TAB3 0014000
|
||||
#define TARGET_XTABS 0014000
|
||||
#define TARGET_BSDLY 0020000
|
||||
#define TARGET_BS0 0000000
|
||||
#define TARGET_BS1 0020000
|
||||
#define TARGET_VTDLY 0040000
|
||||
#define TARGET_VT0 0000000
|
||||
#define TARGET_VT1 0040000
|
||||
#define TARGET_FFDLY 0100000
|
||||
#define TARGET_FF0 0000000
|
||||
#define TARGET_FF1 0100000
|
||||
|
||||
/* c_cflag bit meaning */
|
||||
#define TARGET_CBAUD 0010017
|
||||
#define TARGET_B0 0000000 /* hang up */
|
||||
#define TARGET_B50 0000001
|
||||
#define TARGET_B75 0000002
|
||||
#define TARGET_B110 0000003
|
||||
#define TARGET_B134 0000004
|
||||
#define TARGET_B150 0000005
|
||||
#define TARGET_B200 0000006
|
||||
#define TARGET_B300 0000007
|
||||
#define TARGET_B600 0000010
|
||||
#define TARGET_B1200 0000011
|
||||
#define TARGET_B1800 0000012
|
||||
#define TARGET_B2400 0000013
|
||||
#define TARGET_B4800 0000014
|
||||
#define TARGET_B9600 0000015
|
||||
#define TARGET_B19200 0000016
|
||||
#define TARGET_B38400 0000017
|
||||
#define TARGET_EXTA B19200
|
||||
#define TARGET_EXTB B38400
|
||||
#define TARGET_CSIZE 0000060
|
||||
#define TARGET_CS5 0000000
|
||||
#define TARGET_CS6 0000020
|
||||
#define TARGET_CS7 0000040
|
||||
#define TARGET_CS8 0000060
|
||||
#define TARGET_CSTOPB 0000100
|
||||
#define TARGET_CREAD 0000200
|
||||
#define TARGET_PARENB 0000400
|
||||
#define TARGET_PARODD 0001000
|
||||
#define TARGET_HUPCL 0002000
|
||||
#define TARGET_CLOCAL 0004000
|
||||
#define TARGET_CBAUDEX 0010000
|
||||
#define TARGET_B57600 0010001
|
||||
#define TARGET_B115200 0010002
|
||||
#define TARGET_B230400 0010003
|
||||
#define TARGET_B460800 0010004
|
||||
#define TARGET_CIBAUD 002003600000 /* input baud rate (not used) */
|
||||
#define TARGET_CRTSCTS 020000000000 /* flow control */
|
||||
|
||||
/* c_lflag bits */
|
||||
#define TARGET_ISIG 0000001
|
||||
#define TARGET_ICANON 0000002
|
||||
#define TARGET_XCASE 0000004
|
||||
#define TARGET_ECHO 0000010
|
||||
#define TARGET_ECHOE 0000020
|
||||
#define TARGET_ECHOK 0000040
|
||||
#define TARGET_ECHONL 0000100
|
||||
#define TARGET_NOFLSH 0000200
|
||||
#define TARGET_TOSTOP 0000400
|
||||
#define TARGET_ECHOCTL 0001000
|
||||
#define TARGET_ECHOPRT 0002000
|
||||
#define TARGET_ECHOKE 0004000
|
||||
#define TARGET_FLUSHO 0010000
|
||||
#define TARGET_PENDIN 0040000
|
||||
#define TARGET_IEXTEN 0100000
|
||||
|
||||
/* c_cc character offsets */
|
||||
#define TARGET_VINTR 0
|
||||
#define TARGET_VQUIT 1
|
||||
#define TARGET_VERASE 2
|
||||
#define TARGET_VKILL 3
|
||||
#define TARGET_VEOF 4
|
||||
#define TARGET_VTIME 5
|
||||
#define TARGET_VMIN 6
|
||||
#define TARGET_VSWTC 7
|
||||
#define TARGET_VSTART 8
|
||||
#define TARGET_VSTOP 9
|
||||
#define TARGET_VSUSP 10
|
||||
#define TARGET_VEOL 11
|
||||
#define TARGET_VREPRINT 12
|
||||
#define TARGET_VDISCARD 13
|
||||
#define TARGET_VWERASE 14
|
||||
#define TARGET_VLNEXT 15
|
||||
#define TARGET_VEOL2 16
|
||||
|
||||
/* ioctls */
|
||||
|
||||
#define TARGET_TCGETS 0x5401
|
||||
#define TARGET_TCSETS 0x5402
|
||||
#define TARGET_TCSETSW 0x5403
|
||||
#define TARGET_TCSETSF 0x5404
|
||||
#define TARGET_TCGETA 0x5405
|
||||
#define TARGET_TCSETA 0x5406
|
||||
#define TARGET_TCSETAW 0x5407
|
||||
#define TARGET_TCSETAF 0x5408
|
||||
#define TARGET_TCSBRK 0x5409
|
||||
#define TARGET_TCXONC 0x540A
|
||||
#define TARGET_TCFLSH 0x540B
|
||||
|
||||
#define TARGET_TIOCEXCL 0x540C
|
||||
#define TARGET_TIOCNXCL 0x540D
|
||||
#define TARGET_TIOCSCTTY 0x540E
|
||||
#define TARGET_TIOCGPGRP 0x540F
|
||||
#define TARGET_TIOCSPGRP 0x5410
|
||||
#define TARGET_TIOCOUTQ 0x5411
|
||||
#define TARGET_TIOCSTI 0x5412
|
||||
#define TARGET_TIOCGWINSZ 0x5413
|
||||
#define TARGET_TIOCSWINSZ 0x5414
|
||||
#define TARGET_TIOCMGET 0x5415
|
||||
#define TARGET_TIOCMBIS 0x5416
|
||||
#define TARGET_TIOCMBIC 0x5417
|
||||
#define TARGET_TIOCMSET 0x5418
|
||||
#define TARGET_TIOCGSOFTCAR 0x5419
|
||||
#define TARGET_TIOCSSOFTCAR 0x541A
|
||||
#define TARGET_FIONREAD 0x541B
|
||||
#define TARGET_TIOCINQ TARGET_FIONREAD
|
||||
#define TARGET_TIOCLINUX 0x541C
|
||||
#define TARGET_TIOCCONS 0x541D
|
||||
#define TARGET_TIOCGSERIAL 0x541E
|
||||
#define TARGET_TIOCSSERIAL 0x541F
|
||||
#define TARGET_TIOCPKT 0x5420
|
||||
#define TARGET_FIONBIO 0x5421
|
||||
#define TARGET_TIOCNOTTY 0x5422
|
||||
#define TARGET_TIOCSETD 0x5423
|
||||
#define TARGET_TIOCGETD 0x5424
|
||||
#define TARGET_TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */
|
||||
#define TARGET_TIOCTTYGSTRUCT 0x5426 /* For debugging only */
|
||||
#define TARGET_TIOCSBRK 0x5427 /* BSD compatibility */
|
||||
#define TARGET_TIOCCBRK 0x5428 /* BSD compatibility */
|
||||
#define TARGET_TIOCGSID 0x5429 /* Return the session ID of FD */
|
||||
#define TARGET_TIOCGPTN TARGET_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
|
||||
#define TARGET_TIOCSPTLCK TARGET_IOW('T',0x31, int) /* Lock/unlock Pty */
|
||||
|
||||
#define TARGET_FIONCLEX 0x5450 /* these numbers need to be adjusted. */
|
||||
#define TARGET_FIOCLEX 0x5451
|
||||
#define TARGET_FIOASYNC 0x5452
|
||||
#define TARGET_TIOCSERCONFIG 0x5453
|
||||
#define TARGET_TIOCSERGWILD 0x5454
|
||||
#define TARGET_TIOCSERSWILD 0x5455
|
||||
#define TARGET_TIOCGLCKTRMIOS 0x5456
|
||||
#define TARGET_TIOCSLCKTRMIOS 0x5457
|
||||
#define TARGET_TIOCSERGSTRUCT 0x5458 /* For debugging only */
|
||||
#define TARGET_TIOCSERGETLSR 0x5459 /* Get line status register */
|
||||
#define TARGET_TIOCSERGETMULTI 0x545A /* Get multiport config */
|
||||
#define TARGET_TIOCSERSETMULTI 0x545B /* Set multiport config */
|
||||
|
||||
#define TARGET_TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */
|
||||
#define TARGET_TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */
|
||||
#define TARGET_TIOCGHAYESESP 0x545E /* Get Hayes ESP configuration */
|
||||
#define TARGET_TIOCSHAYESESP 0x545F /* Set Hayes ESP configuration */
|
||||
|
||||
/* Used for packet mode */
|
||||
#define TARGET_TIOCPKT_DATA 0
|
||||
#define TARGET_TIOCPKT_FLUSHREAD 1
|
||||
#define TARGET_TIOCPKT_FLUSHWRITE 2
|
||||
#define TARGET_TIOCPKT_STOP 4
|
||||
#define TARGET_TIOCPKT_START 8
|
||||
#define TARGET_TIOCPKT_NOSTOP 16
|
||||
#define TARGET_TIOCPKT_DOSTOP 32
|
||||
|
||||
#define TARGET_TIOCSER_TEMT 0x01 /* Transmitter physically empty */
|
||||
|
@@ -98,12 +98,88 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
|
||||
|
||||
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
|
||||
{
|
||||
regs->u_regs[0] = infop->entry;
|
||||
regs->u_regs[1] = infop->start_stack;
|
||||
regs->psr = 0;
|
||||
regs->pc = infop->entry;
|
||||
regs->npc = regs->pc + 4;
|
||||
regs->y = 0;
|
||||
regs->u_regs[14] = infop->start_stack - 16 * 4;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_PPC
|
||||
|
||||
#define ELF_START_MMAP 0x80000000
|
||||
|
||||
#define elf_check_arch(x) ( (x) == EM_PPC )
|
||||
|
||||
#define ELF_CLASS ELFCLASS32
|
||||
#ifdef TARGET_WORDS_BIGENDIAN
|
||||
#define ELF_DATA ELFDATA2MSB
|
||||
#else
|
||||
#define ELF_DATA ELFDATA2LSB
|
||||
#endif
|
||||
#define ELF_ARCH EM_PPC
|
||||
|
||||
/* Note that isn't exactly what regular kernel does
|
||||
* but this is what the ABI wants and is needed to allow
|
||||
* execution of PPC BSD programs.
|
||||
*/
|
||||
#define ELF_PLAT_INIT(_r) \
|
||||
do { \
|
||||
unsigned long *pos = (unsigned long *)bprm->p, tmp = 1; \
|
||||
_r->gpr[3] = bprm->argc; \
|
||||
_r->gpr[4] = (unsigned long)++pos; \
|
||||
for (; tmp != 0; pos++) \
|
||||
tmp = *pos; \
|
||||
_r->gpr[5] = (unsigned long)pos; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* We need to put in some extra aux table entries to tell glibc what
|
||||
* the cache block size is, so it can use the dcbz instruction safely.
|
||||
*/
|
||||
#define AT_DCACHEBSIZE 19
|
||||
#define AT_ICACHEBSIZE 20
|
||||
#define AT_UCACHEBSIZE 21
|
||||
/* A special ignored type value for PPC, for glibc compatibility. */
|
||||
#define AT_IGNOREPPC 22
|
||||
/*
|
||||
* The requirements here are:
|
||||
* - keep the final alignment of sp (sp & 0xf)
|
||||
* - make sure the 32-bit value at the first 16 byte aligned position of
|
||||
* AUXV is greater than 16 for glibc compatibility.
|
||||
* AT_IGNOREPPC is used for that.
|
||||
* - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
|
||||
* even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
|
||||
*/
|
||||
#define DLINFO_ARCH_ITEMS 3
|
||||
#define ARCH_DLINFO \
|
||||
do { \
|
||||
sp -= DLINFO_ARCH_ITEMS * 2; \
|
||||
NEW_AUX_ENT(0, AT_DCACHEBSIZE, 0x20); \
|
||||
NEW_AUX_ENT(1, AT_ICACHEBSIZE, 0x20); \
|
||||
NEW_AUX_ENT(2, AT_UCACHEBSIZE, 0); \
|
||||
/* \
|
||||
* Now handle glibc compatibility. \
|
||||
*/ \
|
||||
sp -= 2*2; \
|
||||
NEW_AUX_ENT(0, AT_IGNOREPPC, AT_IGNOREPPC); \
|
||||
NEW_AUX_ENT(1, AT_IGNOREPPC, AT_IGNOREPPC); \
|
||||
} while (0)
|
||||
|
||||
static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
|
||||
{
|
||||
_regs->msr = 1 << MSR_PR; /* Set user mode */
|
||||
_regs->gpr[1] = infop->start_stack;
|
||||
_regs->nip = infop->entry;
|
||||
}
|
||||
|
||||
#define USE_ELF_CORE_DUMP
|
||||
#define ELF_EXEC_PAGESIZE 4096
|
||||
|
||||
#endif
|
||||
|
||||
#include "elf.h"
|
||||
|
||||
/*
|
||||
@@ -185,7 +261,7 @@ struct exec
|
||||
#define INTERPRETER_AOUT 1
|
||||
#define INTERPRETER_ELF 2
|
||||
|
||||
#define DLINFO_ITEMS 12
|
||||
#define DLINFO_ITEMS 11
|
||||
|
||||
#define put_user(x,ptr) (void)(*(ptr) = (typeof(*ptr))(x))
|
||||
#define get_user(ptr) (typeof(*ptr))(*(ptr))
|
||||
@@ -519,15 +595,51 @@ static unsigned int * create_elf_tables(char *p, int argc, int envc,
|
||||
unsigned long interp_load_addr, int ibcs,
|
||||
struct image_info *info)
|
||||
{
|
||||
target_ulong *argv, *envp, *dlinfo;
|
||||
target_ulong *sp;
|
||||
|
||||
/*
|
||||
* Force 16 byte alignment here for generality.
|
||||
*/
|
||||
target_ulong *argv, *envp;
|
||||
target_ulong *sp, *csp;
|
||||
|
||||
/*
|
||||
* Force 16 byte _final_ alignment here for generality.
|
||||
*/
|
||||
sp = (unsigned int *) (~15UL & (unsigned long) p);
|
||||
sp -= DLINFO_ITEMS*2;
|
||||
dlinfo = sp;
|
||||
csp = sp;
|
||||
csp -= (DLINFO_ITEMS + 1) * 2;
|
||||
#ifdef DLINFO_ARCH_ITEMS
|
||||
csp -= DLINFO_ARCH_ITEMS*2;
|
||||
#endif
|
||||
csp -= envc+1;
|
||||
csp -= argc+1;
|
||||
csp -= (!ibcs ? 3 : 1); /* argc itself */
|
||||
if ((unsigned long)csp & 15UL)
|
||||
sp -= ((unsigned long)csp & 15UL) / sizeof(*sp);
|
||||
|
||||
#define NEW_AUX_ENT(nr, id, val) \
|
||||
put_user (tswapl(id), sp + (nr * 2)); \
|
||||
put_user (tswapl(val), sp + (nr * 2 + 1))
|
||||
sp -= 2;
|
||||
NEW_AUX_ENT (0, AT_NULL, 0);
|
||||
|
||||
sp -= DLINFO_ITEMS*2;
|
||||
NEW_AUX_ENT( 0, AT_PHDR, (target_ulong)(load_addr + exec->e_phoff));
|
||||
NEW_AUX_ENT( 1, AT_PHENT, (target_ulong)(sizeof (struct elf_phdr)));
|
||||
NEW_AUX_ENT( 2, AT_PHNUM, (target_ulong)(exec->e_phnum));
|
||||
NEW_AUX_ENT( 3, AT_PAGESZ, (target_ulong)(TARGET_PAGE_SIZE));
|
||||
NEW_AUX_ENT( 4, AT_BASE, (target_ulong)(interp_load_addr));
|
||||
NEW_AUX_ENT( 5, AT_FLAGS, (target_ulong)0);
|
||||
NEW_AUX_ENT( 6, AT_ENTRY, load_bias + exec->e_entry);
|
||||
NEW_AUX_ENT( 7, AT_UID, (target_ulong) getuid());
|
||||
NEW_AUX_ENT( 8, AT_EUID, (target_ulong) geteuid());
|
||||
NEW_AUX_ENT( 9, AT_GID, (target_ulong) getgid());
|
||||
NEW_AUX_ENT(11, AT_EGID, (target_ulong) getegid());
|
||||
#ifdef ARCH_DLINFO
|
||||
/*
|
||||
* ARCH_DLINFO must come last so platform specific code can enforce
|
||||
* special alignment requirements on the AUXV if necessary (eg. PPC).
|
||||
*/
|
||||
ARCH_DLINFO;
|
||||
#endif
|
||||
#undef NEW_AUX_ENT
|
||||
|
||||
sp -= envc+1;
|
||||
envp = sp;
|
||||
sp -= argc+1;
|
||||
@@ -536,25 +648,6 @@ static unsigned int * create_elf_tables(char *p, int argc, int envc,
|
||||
put_user(tswapl((target_ulong)envp),--sp);
|
||||
put_user(tswapl((target_ulong)argv),--sp);
|
||||
}
|
||||
|
||||
#define NEW_AUX_ENT(id, val) \
|
||||
put_user (tswapl(id), dlinfo++); \
|
||||
put_user (tswapl(val), dlinfo++)
|
||||
|
||||
NEW_AUX_ENT (AT_PHDR, (target_ulong)(load_addr + exec->e_phoff));
|
||||
NEW_AUX_ENT (AT_PHENT, (target_ulong)(sizeof (struct elf_phdr)));
|
||||
NEW_AUX_ENT (AT_PHNUM, (target_ulong)(exec->e_phnum));
|
||||
NEW_AUX_ENT (AT_PAGESZ, (target_ulong)(TARGET_PAGE_SIZE));
|
||||
NEW_AUX_ENT (AT_BASE, (target_ulong)(interp_load_addr));
|
||||
NEW_AUX_ENT (AT_FLAGS, (target_ulong)0);
|
||||
NEW_AUX_ENT (AT_ENTRY, load_bias + exec->e_entry);
|
||||
NEW_AUX_ENT (AT_UID, (target_ulong) getuid());
|
||||
NEW_AUX_ENT (AT_EUID, (target_ulong) geteuid());
|
||||
NEW_AUX_ENT (AT_GID, (target_ulong) getgid());
|
||||
NEW_AUX_ENT (AT_EGID, (target_ulong) getegid());
|
||||
NEW_AUX_ENT (AT_NULL, 0);
|
||||
#undef NEW_AUX_ENT
|
||||
|
||||
put_user(tswapl(argc),--sp);
|
||||
info->arg_start = (unsigned int)((unsigned long)p & 0xffffffff);
|
||||
while (argc-->0) {
|
||||
|
214
linux-user/i386/termbits.h
Normal file
214
linux-user/i386/termbits.h
Normal file
@@ -0,0 +1,214 @@
|
||||
/* from asm/termbits.h */
|
||||
|
||||
#define TARGET_NCCS 19
|
||||
|
||||
struct target_termios {
|
||||
unsigned int c_iflag; /* input mode flags */
|
||||
unsigned int c_oflag; /* output mode flags */
|
||||
unsigned int c_cflag; /* control mode flags */
|
||||
unsigned int c_lflag; /* local mode flags */
|
||||
unsigned char c_line; /* line discipline */
|
||||
unsigned char c_cc[TARGET_NCCS]; /* control characters */
|
||||
};
|
||||
|
||||
/* c_iflag bits */
|
||||
#define TARGET_IGNBRK 0000001
|
||||
#define TARGET_BRKINT 0000002
|
||||
#define TARGET_IGNPAR 0000004
|
||||
#define TARGET_PARMRK 0000010
|
||||
#define TARGET_INPCK 0000020
|
||||
#define TARGET_ISTRIP 0000040
|
||||
#define TARGET_INLCR 0000100
|
||||
#define TARGET_IGNCR 0000200
|
||||
#define TARGET_ICRNL 0000400
|
||||
#define TARGET_IUCLC 0001000
|
||||
#define TARGET_IXON 0002000
|
||||
#define TARGET_IXANY 0004000
|
||||
#define TARGET_IXOFF 0010000
|
||||
#define TARGET_IMAXBEL 0020000
|
||||
|
||||
/* c_oflag bits */
|
||||
#define TARGET_OPOST 0000001
|
||||
#define TARGET_OLCUC 0000002
|
||||
#define TARGET_ONLCR 0000004
|
||||
#define TARGET_OCRNL 0000010
|
||||
#define TARGET_ONOCR 0000020
|
||||
#define TARGET_ONLRET 0000040
|
||||
#define TARGET_OFILL 0000100
|
||||
#define TARGET_OFDEL 0000200
|
||||
#define TARGET_NLDLY 0000400
|
||||
#define TARGET_NL0 0000000
|
||||
#define TARGET_NL1 0000400
|
||||
#define TARGET_CRDLY 0003000
|
||||
#define TARGET_CR0 0000000
|
||||
#define TARGET_CR1 0001000
|
||||
#define TARGET_CR2 0002000
|
||||
#define TARGET_CR3 0003000
|
||||
#define TARGET_TABDLY 0014000
|
||||
#define TARGET_TAB0 0000000
|
||||
#define TARGET_TAB1 0004000
|
||||
#define TARGET_TAB2 0010000
|
||||
#define TARGET_TAB3 0014000
|
||||
#define TARGET_XTABS 0014000
|
||||
#define TARGET_BSDLY 0020000
|
||||
#define TARGET_BS0 0000000
|
||||
#define TARGET_BS1 0020000
|
||||
#define TARGET_VTDLY 0040000
|
||||
#define TARGET_VT0 0000000
|
||||
#define TARGET_VT1 0040000
|
||||
#define TARGET_FFDLY 0100000
|
||||
#define TARGET_FF0 0000000
|
||||
#define TARGET_FF1 0100000
|
||||
|
||||
/* c_cflag bit meaning */
|
||||
#define TARGET_CBAUD 0010017
|
||||
#define TARGET_B0 0000000 /* hang up */
|
||||
#define TARGET_B50 0000001
|
||||
#define TARGET_B75 0000002
|
||||
#define TARGET_B110 0000003
|
||||
#define TARGET_B134 0000004
|
||||
#define TARGET_B150 0000005
|
||||
#define TARGET_B200 0000006
|
||||
#define TARGET_B300 0000007
|
||||
#define TARGET_B600 0000010
|
||||
#define TARGET_B1200 0000011
|
||||
#define TARGET_B1800 0000012
|
||||
#define TARGET_B2400 0000013
|
||||
#define TARGET_B4800 0000014
|
||||
#define TARGET_B9600 0000015
|
||||
#define TARGET_B19200 0000016
|
||||
#define TARGET_B38400 0000017
|
||||
#define TARGET_EXTA B19200
|
||||
#define TARGET_EXTB B38400
|
||||
#define TARGET_CSIZE 0000060
|
||||
#define TARGET_CS5 0000000
|
||||
#define TARGET_CS6 0000020
|
||||
#define TARGET_CS7 0000040
|
||||
#define TARGET_CS8 0000060
|
||||
#define TARGET_CSTOPB 0000100
|
||||
#define TARGET_CREAD 0000200
|
||||
#define TARGET_PARENB 0000400
|
||||
#define TARGET_PARODD 0001000
|
||||
#define TARGET_HUPCL 0002000
|
||||
#define TARGET_CLOCAL 0004000
|
||||
#define TARGET_CBAUDEX 0010000
|
||||
#define TARGET_B57600 0010001
|
||||
#define TARGET_B115200 0010002
|
||||
#define TARGET_B230400 0010003
|
||||
#define TARGET_B460800 0010004
|
||||
#define TARGET_CIBAUD 002003600000 /* input baud rate (not used) */
|
||||
#define TARGET_CRTSCTS 020000000000 /* flow control */
|
||||
|
||||
/* c_lflag bits */
|
||||
#define TARGET_ISIG 0000001
|
||||
#define TARGET_ICANON 0000002
|
||||
#define TARGET_XCASE 0000004
|
||||
#define TARGET_ECHO 0000010
|
||||
#define TARGET_ECHOE 0000020
|
||||
#define TARGET_ECHOK 0000040
|
||||
#define TARGET_ECHONL 0000100
|
||||
#define TARGET_NOFLSH 0000200
|
||||
#define TARGET_TOSTOP 0000400
|
||||
#define TARGET_ECHOCTL 0001000
|
||||
#define TARGET_ECHOPRT 0002000
|
||||
#define TARGET_ECHOKE 0004000
|
||||
#define TARGET_FLUSHO 0010000
|
||||
#define TARGET_PENDIN 0040000
|
||||
#define TARGET_IEXTEN 0100000
|
||||
|
||||
/* c_cc character offsets */
|
||||
#define TARGET_VINTR 0
|
||||
#define TARGET_VQUIT 1
|
||||
#define TARGET_VERASE 2
|
||||
#define TARGET_VKILL 3
|
||||
#define TARGET_VEOF 4
|
||||
#define TARGET_VTIME 5
|
||||
#define TARGET_VMIN 6
|
||||
#define TARGET_VSWTC 7
|
||||
#define TARGET_VSTART 8
|
||||
#define TARGET_VSTOP 9
|
||||
#define TARGET_VSUSP 10
|
||||
#define TARGET_VEOL 11
|
||||
#define TARGET_VREPRINT 12
|
||||
#define TARGET_VDISCARD 13
|
||||
#define TARGET_VWERASE 14
|
||||
#define TARGET_VLNEXT 15
|
||||
#define TARGET_VEOL2 16
|
||||
|
||||
/* ioctls */
|
||||
|
||||
#define TARGET_TCGETS 0x5401
|
||||
#define TARGET_TCSETS 0x5402
|
||||
#define TARGET_TCSETSW 0x5403
|
||||
#define TARGET_TCSETSF 0x5404
|
||||
#define TARGET_TCGETA 0x5405
|
||||
#define TARGET_TCSETA 0x5406
|
||||
#define TARGET_TCSETAW 0x5407
|
||||
#define TARGET_TCSETAF 0x5408
|
||||
#define TARGET_TCSBRK 0x5409
|
||||
#define TARGET_TCXONC 0x540A
|
||||
#define TARGET_TCFLSH 0x540B
|
||||
|
||||
#define TARGET_TIOCEXCL 0x540C
|
||||
#define TARGET_TIOCNXCL 0x540D
|
||||
#define TARGET_TIOCSCTTY 0x540E
|
||||
#define TARGET_TIOCGPGRP 0x540F
|
||||
#define TARGET_TIOCSPGRP 0x5410
|
||||
#define TARGET_TIOCOUTQ 0x5411
|
||||
#define TARGET_TIOCSTI 0x5412
|
||||
#define TARGET_TIOCGWINSZ 0x5413
|
||||
#define TARGET_TIOCSWINSZ 0x5414
|
||||
#define TARGET_TIOCMGET 0x5415
|
||||
#define TARGET_TIOCMBIS 0x5416
|
||||
#define TARGET_TIOCMBIC 0x5417
|
||||
#define TARGET_TIOCMSET 0x5418
|
||||
#define TARGET_TIOCGSOFTCAR 0x5419
|
||||
#define TARGET_TIOCSSOFTCAR 0x541A
|
||||
#define TARGET_FIONREAD 0x541B
|
||||
#define TARGET_TIOCINQ TARGET_FIONREAD
|
||||
#define TARGET_TIOCLINUX 0x541C
|
||||
#define TARGET_TIOCCONS 0x541D
|
||||
#define TARGET_TIOCGSERIAL 0x541E
|
||||
#define TARGET_TIOCSSERIAL 0x541F
|
||||
#define TARGET_TIOCPKT 0x5420
|
||||
#define TARGET_FIONBIO 0x5421
|
||||
#define TARGET_TIOCNOTTY 0x5422
|
||||
#define TARGET_TIOCSETD 0x5423
|
||||
#define TARGET_TIOCGETD 0x5424
|
||||
#define TARGET_TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */
|
||||
#define TARGET_TIOCTTYGSTRUCT 0x5426 /* For debugging only */
|
||||
#define TARGET_TIOCSBRK 0x5427 /* BSD compatibility */
|
||||
#define TARGET_TIOCCBRK 0x5428 /* BSD compatibility */
|
||||
#define TARGET_TIOCGSID 0x5429 /* Return the session ID of FD */
|
||||
#define TARGET_TIOCGPTN TARGET_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
|
||||
#define TARGET_TIOCSPTLCK TARGET_IOW('T',0x31, int) /* Lock/unlock Pty */
|
||||
|
||||
#define TARGET_FIONCLEX 0x5450 /* these numbers need to be adjusted. */
|
||||
#define TARGET_FIOCLEX 0x5451
|
||||
#define TARGET_FIOASYNC 0x5452
|
||||
#define TARGET_TIOCSERCONFIG 0x5453
|
||||
#define TARGET_TIOCSERGWILD 0x5454
|
||||
#define TARGET_TIOCSERSWILD 0x5455
|
||||
#define TARGET_TIOCGLCKTRMIOS 0x5456
|
||||
#define TARGET_TIOCSLCKTRMIOS 0x5457
|
||||
#define TARGET_TIOCSERGSTRUCT 0x5458 /* For debugging only */
|
||||
#define TARGET_TIOCSERGETLSR 0x5459 /* Get line status register */
|
||||
#define TARGET_TIOCSERGETMULTI 0x545A /* Get multiport config */
|
||||
#define TARGET_TIOCSERSETMULTI 0x545B /* Set multiport config */
|
||||
|
||||
#define TARGET_TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */
|
||||
#define TARGET_TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */
|
||||
#define TARGET_TIOCGHAYESESP 0x545E /* Get Hayes ESP configuration */
|
||||
#define TARGET_TIOCSHAYESESP 0x545F /* Set Hayes ESP configuration */
|
||||
|
||||
/* Used for packet mode */
|
||||
#define TARGET_TIOCPKT_DATA 0
|
||||
#define TARGET_TIOCPKT_FLUSHREAD 1
|
||||
#define TARGET_TIOCPKT_FLUSHWRITE 2
|
||||
#define TARGET_TIOCPKT_STOP 4
|
||||
#define TARGET_TIOCPKT_START 8
|
||||
#define TARGET_TIOCPKT_NOSTOP 16
|
||||
#define TARGET_TIOCPKT_DOSTOP 32
|
||||
|
||||
#define TARGET_TIOCSER_TEMT 0x01 /* Transmitter physically empty */
|
||||
|
@@ -30,7 +30,7 @@
|
||||
|
||||
static const char *interp_prefix = CONFIG_QEMU_PREFIX;
|
||||
|
||||
#ifdef __i386__
|
||||
#if defined(__i386__) && !defined(CONFIG_STATIC)
|
||||
/* Force usage of an ELF interpreter even if it is an ELF shared
|
||||
object ! */
|
||||
const char interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
|
||||
@@ -299,29 +299,250 @@ void cpu_loop(CPUARMState *env)
|
||||
|
||||
#ifdef TARGET_SPARC
|
||||
|
||||
void cpu_loop (CPUSPARCState *env)
|
||||
//#define DEBUG_WIN
|
||||
|
||||
/* WARNING: dealing with register windows _is_ complicated */
|
||||
static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
|
||||
{
|
||||
int trapnr;
|
||||
|
||||
while (1) {
|
||||
trapnr = cpu_sparc_exec (env);
|
||||
|
||||
switch (trapnr) {
|
||||
case 0x8: case 0x10:
|
||||
env->regwptr[0] = do_syscall (env, env->gregs[1],
|
||||
env->regwptr[0], env->regwptr[1], env->regwptr[2],
|
||||
env->regwptr[3], env->regwptr[4], env->regwptr[13]);
|
||||
if (env->regwptr[0] >= 0xffffffe0)
|
||||
env->psr |= PSR_CARRY;
|
||||
break;
|
||||
default:
|
||||
printf ("Invalid trap: %d\n", trapnr);
|
||||
exit (1);
|
||||
}
|
||||
process_pending_signals (env);
|
||||
}
|
||||
index = (index + cwp * 16) & (16 * NWINDOWS - 1);
|
||||
/* wrap handling : if cwp is on the last window, then we use the
|
||||
registers 'after' the end */
|
||||
if (index < 8 && env->cwp == (NWINDOWS - 1))
|
||||
index += (16 * NWINDOWS);
|
||||
return index;
|
||||
}
|
||||
|
||||
static inline void save_window_offset(CPUSPARCState *env, int offset)
|
||||
{
|
||||
unsigned int new_wim, i, cwp1;
|
||||
uint32_t *sp_ptr;
|
||||
|
||||
new_wim = ((env->wim >> 1) | (env->wim << (NWINDOWS - 1))) &
|
||||
((1LL << NWINDOWS) - 1);
|
||||
/* save the window */
|
||||
cwp1 = (env->cwp + offset) & (NWINDOWS - 1);
|
||||
sp_ptr = (uint32_t *)(env->regbase[get_reg_index(env, cwp1, 6)]);
|
||||
#if defined(DEBUG_WIN)
|
||||
printf("win_overflow: sp_ptr=0x%x save_cwp=%d\n",
|
||||
(int)sp_ptr, cwp1);
|
||||
#endif
|
||||
for(i = 0; i < 16; i++)
|
||||
stl_raw(sp_ptr + i, env->regbase[get_reg_index(env, cwp1, 8 + i)]);
|
||||
env->wim = new_wim;
|
||||
}
|
||||
|
||||
static void save_window(CPUSPARCState *env)
|
||||
{
|
||||
save_window_offset(env, 2);
|
||||
}
|
||||
|
||||
static void restore_window(CPUSPARCState *env)
|
||||
{
|
||||
unsigned int new_wim, i, cwp1;
|
||||
uint32_t *sp_ptr;
|
||||
|
||||
new_wim = ((env->wim << 1) | (env->wim >> (NWINDOWS - 1))) &
|
||||
((1LL << NWINDOWS) - 1);
|
||||
|
||||
/* restore the invalid window */
|
||||
cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
|
||||
sp_ptr = (uint32_t *)(env->regbase[get_reg_index(env, cwp1, 6)]);
|
||||
#if defined(DEBUG_WIN)
|
||||
printf("win_underflow: sp_ptr=0x%x load_cwp=%d\n",
|
||||
(int)sp_ptr, cwp1);
|
||||
#endif
|
||||
for(i = 0; i < 16; i++)
|
||||
env->regbase[get_reg_index(env, cwp1, 8 + i)] = ldl_raw(sp_ptr + i);
|
||||
env->wim = new_wim;
|
||||
}
|
||||
|
||||
static void flush_windows(CPUSPARCState *env)
|
||||
{
|
||||
int offset, cwp1;
|
||||
#if defined(DEBUG_WIN)
|
||||
printf("flush_windows:\n");
|
||||
#endif
|
||||
offset = 2;
|
||||
for(;;) {
|
||||
/* if restore would invoke restore_window(), then we can stop */
|
||||
cwp1 = (env->cwp + 1) & (NWINDOWS - 1);
|
||||
if (env->wim & (1 << cwp1))
|
||||
break;
|
||||
#if defined(DEBUG_WIN)
|
||||
printf("offset=%d: ", offset);
|
||||
#endif
|
||||
save_window_offset(env, offset);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
void cpu_loop (CPUSPARCState *env)
|
||||
{
|
||||
int trapnr, ret;
|
||||
|
||||
while (1) {
|
||||
trapnr = cpu_sparc_exec (env);
|
||||
|
||||
switch (trapnr) {
|
||||
case 0x88:
|
||||
case 0x90:
|
||||
ret = do_syscall (env, env->gregs[1],
|
||||
env->regwptr[0], env->regwptr[1],
|
||||
env->regwptr[2], env->regwptr[3],
|
||||
env->regwptr[4], env->regwptr[5]);
|
||||
if ((unsigned int)ret >= (unsigned int)(-515)) {
|
||||
env->psr |= PSR_CARRY;
|
||||
ret = -ret;
|
||||
} else {
|
||||
env->psr &= ~PSR_CARRY;
|
||||
}
|
||||
env->regwptr[0] = ret;
|
||||
/* next instruction */
|
||||
env->pc = env->npc;
|
||||
env->npc = env->npc + 4;
|
||||
break;
|
||||
case 0x83: /* flush windows */
|
||||
// flush_windows(env);
|
||||
/* next instruction */
|
||||
env->pc = env->npc;
|
||||
env->npc = env->npc + 4;
|
||||
break;
|
||||
case TT_WIN_OVF: /* window overflow */
|
||||
save_window(env);
|
||||
break;
|
||||
case TT_WIN_UNF: /* window underflow */
|
||||
restore_window(env);
|
||||
break;
|
||||
default:
|
||||
printf ("Unhandled trap: 0x%x\n", trapnr);
|
||||
cpu_sparc_dump_state(env, stderr, 0);
|
||||
exit (1);
|
||||
}
|
||||
process_pending_signals (env);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_PPC
|
||||
|
||||
void cpu_loop(CPUPPCState *env)
|
||||
{
|
||||
int trapnr;
|
||||
target_siginfo_t info;
|
||||
|
||||
for(;;) {
|
||||
trapnr = cpu_ppc_exec(env);
|
||||
switch(trapnr) {
|
||||
case EXCP_NONE:
|
||||
case EXCP_INTERRUPT:
|
||||
case EXCP_MTMSR: /* mtmsr instruction: */
|
||||
case EXCP_BRANCH: /* branch instruction */
|
||||
/* Single step mode */
|
||||
break;
|
||||
#if 0
|
||||
case EXCP_RESET: /* System reset */
|
||||
fprintf(stderr, "RESET asked... Stop emulation\n");
|
||||
cpu_ppc_dump_state(env, stderr, 0);
|
||||
abort();
|
||||
#endif
|
||||
case EXCP_MACHINE_CHECK: /* Machine check exception */
|
||||
fprintf(stderr, "Machine check exeption... "
|
||||
"See you in kernel code !\n");
|
||||
cpu_ppc_dump_state(env, stderr, 0);
|
||||
abort();
|
||||
case EXCP_DSI: /* Impossible memory access */
|
||||
fprintf(stderr, "Invalid memory access\n");
|
||||
info.si_signo = SIGSEGV;
|
||||
info.si_errno = 0;
|
||||
info.si_code = TARGET_ILL_ILLOPN;
|
||||
info._sifields._sigfault._addr = env->nip;
|
||||
queue_signal(info.si_signo, &info);
|
||||
break;
|
||||
case EXCP_ISI: /* Impossible instruction fetch */
|
||||
fprintf(stderr, "Invalid instruction fetch\n");
|
||||
info.si_signo = SIGBUS;
|
||||
info.si_errno = 0;
|
||||
info.si_code = TARGET_ILL_ILLOPN;
|
||||
info._sifields._sigfault._addr = env->nip;
|
||||
queue_signal(info.si_signo, &info);
|
||||
break;
|
||||
case EXCP_EXTERNAL: /* External interruption */
|
||||
fprintf(stderr, "External access exeption\n");
|
||||
cpu_ppc_dump_state(env, stderr, 0);
|
||||
abort();
|
||||
case EXCP_ALIGN: /* Alignment exception */
|
||||
fprintf(stderr, "Alignment exception\n");
|
||||
cpu_ppc_dump_state(env, stderr, 0);
|
||||
abort();
|
||||
case EXCP_PROGRAM: /* Program exception */
|
||||
fprintf(stderr, "Program exception\n");
|
||||
cpu_ppc_dump_state(env, stderr, 0);
|
||||
abort();
|
||||
break;
|
||||
/* Trap */
|
||||
case EXCP_TRAP: /* Trap */
|
||||
case EXCP_TRACE: /* Trace exception (optional) */
|
||||
info.si_signo = SIGTRAP;
|
||||
info.si_errno = 0;
|
||||
info.si_code = TARGET_ILL_ILLOPN;
|
||||
info._sifields._sigfault._addr = env->nip;
|
||||
queue_signal(info.si_signo, &info);
|
||||
break;
|
||||
/* Invalid instruction */
|
||||
case EXCP_INVAL:
|
||||
info.si_signo = SIGILL;
|
||||
info.si_errno = 0;
|
||||
info.si_code = TARGET_ILL_ILLOPN;
|
||||
info._sifields._sigfault._addr = env->nip;
|
||||
queue_signal(info.si_signo, &info);
|
||||
break;
|
||||
/* Privileged instruction */
|
||||
case EXCP_PRIV: /* Privileged instruction */
|
||||
info.si_signo = SIGILL;
|
||||
info.si_errno = 0;
|
||||
info.si_code = TARGET_ILL_ILLOPN;
|
||||
info._sifields._sigfault._addr = env->nip;
|
||||
queue_signal(info.si_signo, &info);
|
||||
break;
|
||||
case EXCP_NO_FP: /* No floating point */
|
||||
case EXCP_DECR: /* Decrementer exception */
|
||||
case EXCP_RESA: /* Implementation specific */
|
||||
case EXCP_RESB: /* Implementation specific */
|
||||
case EXCP_FP_ASSIST: /* Floating-point assist (optional) */
|
||||
fprintf(stderr, "Misc expt...\n");
|
||||
cpu_ppc_dump_state(env, stderr, 0);
|
||||
abort();
|
||||
|
||||
case EXCP_SYSCALL:
|
||||
{
|
||||
uint32_t ret;
|
||||
/* system call */
|
||||
/* WARNING:
|
||||
* PPC ABI uses overflow flag in cr0 to signal an error
|
||||
* in syscalls.
|
||||
*/
|
||||
env->crf[0] &= ~0x1;
|
||||
ret = do_syscall(env, env->gpr[0], env->gpr[3], env->gpr[4],
|
||||
env->gpr[5], env->gpr[6], env->gpr[7],
|
||||
env->gpr[8]);
|
||||
if (ret > (uint32_t)(-515)) {
|
||||
env->crf[0] |= 0x1;
|
||||
ret = -ret;
|
||||
}
|
||||
env->gpr[3] = ret;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// error:
|
||||
fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n",
|
||||
trapnr);
|
||||
cpu_ppc_dump_state(env, stderr, 0);
|
||||
abort();
|
||||
}
|
||||
process_pending_signals(env);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void usage(void)
|
||||
@@ -515,8 +736,26 @@ int main(int argc, char **argv)
|
||||
env->cpsr = regs->uregs[16];
|
||||
}
|
||||
#elif defined(TARGET_SPARC)
|
||||
env->pc = regs->u_regs[0];
|
||||
env->regwptr[6] = regs->u_regs[1]-0x40;
|
||||
{
|
||||
int i;
|
||||
env->pc = regs->pc;
|
||||
env->npc = regs->npc;
|
||||
env->y = regs->y;
|
||||
for(i = 0; i < 8; i++)
|
||||
env->gregs[i] = regs->u_regs[i];
|
||||
for(i = 0; i < 8; i++)
|
||||
env->regwptr[i] = regs->u_regs[i + 8];
|
||||
}
|
||||
#elif defined(TARGET_PPC)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 32; i++)
|
||||
env->msr[i] = (regs->msr >> i) & 1;
|
||||
env->nip = regs->nip;
|
||||
for(i = 0; i < 32; i++) {
|
||||
env->gpr[i] = regs->gpr[i];
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error unsupported target CPU
|
||||
#endif
|
||||
|
129
linux-user/ppc/syscall.h
Normal file
129
linux-user/ppc/syscall.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* PPC emulation for qemu: syscall definitions.
|
||||
*
|
||||
* Copyright (c) 2003 Jocelyn Mayer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* XXX: ABSOLUTELY BUGGY:
|
||||
* for now, this is quite just a cut-and-paste from i386 target...
|
||||
*/
|
||||
|
||||
/* default linux values for the selectors */
|
||||
#define __USER_DS (1)
|
||||
|
||||
struct target_pt_regs {
|
||||
unsigned long gpr[32];
|
||||
unsigned long nip;
|
||||
unsigned long msr;
|
||||
unsigned long orig_gpr3; /* Used for restarting system calls */
|
||||
unsigned long ctr;
|
||||
unsigned long link;
|
||||
unsigned long xer;
|
||||
unsigned long ccr;
|
||||
unsigned long mq; /* 601 only (not used at present) */
|
||||
/* Used on APUS to hold IPL value. */
|
||||
unsigned long trap; /* Reason for being here */
|
||||
unsigned long dar; /* Fault registers */
|
||||
unsigned long dsisr;
|
||||
unsigned long result; /* Result of a system call */
|
||||
};
|
||||
|
||||
/* ioctls */
|
||||
struct target_revectored_struct {
|
||||
target_ulong __map[8]; /* 256 bits */
|
||||
};
|
||||
|
||||
/*
|
||||
* flags masks
|
||||
*/
|
||||
|
||||
/* ipcs */
|
||||
|
||||
#define TARGET_SEMOP 1
|
||||
#define TARGET_SEMGET 2
|
||||
#define TARGET_SEMCTL 3
|
||||
#define TARGET_MSGSND 11
|
||||
#define TARGET_MSGRCV 12
|
||||
#define TARGET_MSGGET 13
|
||||
#define TARGET_MSGCTL 14
|
||||
#define TARGET_SHMAT 21
|
||||
#define TARGET_SHMDT 22
|
||||
#define TARGET_SHMGET 23
|
||||
#define TARGET_SHMCTL 24
|
||||
|
||||
struct target_msgbuf {
|
||||
int mtype;
|
||||
char mtext[1];
|
||||
};
|
||||
|
||||
struct target_ipc_kludge {
|
||||
unsigned int msgp; /* Really (struct msgbuf *) */
|
||||
int msgtyp;
|
||||
};
|
||||
|
||||
struct target_ipc_perm {
|
||||
int key;
|
||||
unsigned short uid;
|
||||
unsigned short gid;
|
||||
unsigned short cuid;
|
||||
unsigned short cgid;
|
||||
unsigned short mode;
|
||||
unsigned short seq;
|
||||
};
|
||||
|
||||
struct target_msqid_ds {
|
||||
struct target_ipc_perm msg_perm;
|
||||
unsigned int msg_first; /* really struct target_msg* */
|
||||
unsigned int msg_last; /* really struct target_msg* */
|
||||
unsigned int msg_stime; /* really target_time_t */
|
||||
unsigned int msg_rtime; /* really target_time_t */
|
||||
unsigned int msg_ctime; /* really target_time_t */
|
||||
unsigned int wwait; /* really struct wait_queue* */
|
||||
unsigned int rwait; /* really struct wait_queue* */
|
||||
unsigned short msg_cbytes;
|
||||
unsigned short msg_qnum;
|
||||
unsigned short msg_qbytes;
|
||||
unsigned short msg_lspid;
|
||||
unsigned short msg_lrpid;
|
||||
};
|
||||
|
||||
struct target_shmid_ds {
|
||||
struct target_ipc_perm shm_perm;
|
||||
int shm_segsz;
|
||||
unsigned int shm_atime; /* really target_time_t */
|
||||
unsigned int shm_dtime; /* really target_time_t */
|
||||
unsigned int shm_ctime; /* really target_time_t */
|
||||
unsigned short shm_cpid;
|
||||
unsigned short shm_lpid;
|
||||
short shm_nattch;
|
||||
unsigned short shm_npages;
|
||||
unsigned long *shm_pages;
|
||||
void *attaches; /* really struct shm_desc * */
|
||||
};
|
||||
|
||||
#define TARGET_IPC_RMID 0
|
||||
#define TARGET_IPC_SET 1
|
||||
#define TARGET_IPC_STAT 2
|
||||
|
||||
union target_semun {
|
||||
int val;
|
||||
unsigned int buf; /* really struct semid_ds * */
|
||||
unsigned int array; /* really unsigned short * */
|
||||
unsigned int __buf; /* really struct seminfo * */
|
||||
unsigned int __pad; /* really void* */
|
||||
};
|
||||
|
258
linux-user/ppc/syscall_nr.h
Normal file
258
linux-user/ppc/syscall_nr.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
* This file contains the system call numbers.
|
||||
*/
|
||||
#define TARGET_NR_restart_syscall 0
|
||||
#define TARGET_NR_exit 1
|
||||
#define TARGET_NR_fork 2
|
||||
#define TARGET_NR_read 3
|
||||
#define TARGET_NR_write 4
|
||||
#define TARGET_NR_open 5
|
||||
#define TARGET_NR_close 6
|
||||
#define TARGET_NR_waitpid 7
|
||||
#define TARGET_NR_creat 8
|
||||
#define TARGET_NR_link 9
|
||||
#define TARGET_NR_unlink 10
|
||||
#define TARGET_NR_execve 11
|
||||
#define TARGET_NR_chdir 12
|
||||
#define TARGET_NR_time 13
|
||||
#define TARGET_NR_mknod 14
|
||||
#define TARGET_NR_chmod 15
|
||||
#define TARGET_NR_lchown32 16
|
||||
#define TARGET_NR_break 17
|
||||
#define TARGET_NR_oldstat 18
|
||||
#define TARGET_NR_lseek 19
|
||||
#define TARGET_NR_getpid 20
|
||||
#define TARGET_NR_mount 21
|
||||
#define TARGET_NR_umount 22
|
||||
#define TARGET_NR_setuid32 23
|
||||
#define TARGET_NR_getuid32 24
|
||||
#define TARGET_NR_stime 25
|
||||
#define TARGET_NR_ptrace 26
|
||||
#define TARGET_NR_alarm 27
|
||||
#define TARGET_NR_oldfstat 28
|
||||
#define TARGET_NR_pause 29
|
||||
#define TARGET_NR_utime 30
|
||||
#define TARGET_NR_stty 31
|
||||
#define TARGET_NR_gtty 32
|
||||
#define TARGET_NR_access 33
|
||||
#define TARGET_NR_nice 34
|
||||
#define TARGET_NR_ftime 35
|
||||
#define TARGET_NR_sync 36
|
||||
#define TARGET_NR_kill 37
|
||||
#define TARGET_NR_rename 38
|
||||
#define TARGET_NR_mkdir 39
|
||||
#define TARGET_NR_rmdir 40
|
||||
#define TARGET_NR_dup 41
|
||||
#define TARGET_NR_pipe 42
|
||||
#define TARGET_NR_times 43
|
||||
#define TARGET_NR_prof 44
|
||||
#define TARGET_NR_brk 45
|
||||
#define TARGET_NR_setgid32 46
|
||||
#define TARGET_NR_getgid32 47
|
||||
#define TARGET_NR_signal 48
|
||||
#define TARGET_NR_geteuid32 49
|
||||
#define TARGET_NR_getegid32 50
|
||||
#define TARGET_NR_acct 51
|
||||
#define TARGET_NR_umount2 52
|
||||
#define TARGET_NR_lock 53
|
||||
#define TARGET_NR_ioctl 54
|
||||
#define TARGET_NR_fcntl 55
|
||||
#define TARGET_NR_mpx 56
|
||||
#define TARGET_NR_setpgid 57
|
||||
#define TARGET_NR_ulimit 58
|
||||
#define TARGET_NR_oldolduname 59
|
||||
#define TARGET_NR_umask 60
|
||||
#define TARGET_NR_chroot 61
|
||||
#define TARGET_NR_ustat 62
|
||||
#define TARGET_NR_dup2 63
|
||||
#define TARGET_NR_getppid 64
|
||||
#define TARGET_NR_getpgrp 65
|
||||
#define TARGET_NR_setsid 66
|
||||
#define TARGET_NR_sigaction 67
|
||||
#define TARGET_NR_sgetmask 68
|
||||
#define TARGET_NR_ssetmask 69
|
||||
#define TARGET_NR_setreuid32 70
|
||||
#define TARGET_NR_setregid32 71
|
||||
#define TARGET_NR_sigsuspend 72
|
||||
#define TARGET_NR_sigpending 73
|
||||
#define TARGET_NR_sethostname 74
|
||||
#define TARGET_NR_setrlimit 75
|
||||
#define TARGET_NR_getrlimit 76
|
||||
#define TARGET_NR_getrusage 77
|
||||
#define TARGET_NR_gettimeofday 78
|
||||
#define TARGET_NR_settimeofday 79
|
||||
#define TARGET_NR_getgroups32 80
|
||||
#define TARGET_NR_setgroups32 81
|
||||
#define TARGET_NR_select 82
|
||||
#define TARGET_NR_symlink 83
|
||||
#define TARGET_NR_oldlstat 84
|
||||
#define TARGET_NR_readlink 85
|
||||
#define TARGET_NR_uselib 86
|
||||
#define TARGET_NR_swapon 87
|
||||
#define TARGET_NR_reboot 88
|
||||
#define TARGET_NR_readdir 89
|
||||
#define TARGET_NR_mmap 90
|
||||
#define TARGET_NR_munmap 91
|
||||
#define TARGET_NR_truncate 92
|
||||
#define TARGET_NR_ftruncate 93
|
||||
#define TARGET_NR_fchmod 94
|
||||
#define TARGET_NR_fchown32 95
|
||||
#define TARGET_NR_getpriority 96
|
||||
#define TARGET_NR_setpriority 97
|
||||
#define TARGET_NR_profil 98
|
||||
#define TARGET_NR_statfs 99
|
||||
#define TARGET_NR_fstatfs 100
|
||||
#define TARGET_NR_ioperm 101
|
||||
#define TARGET_NR_socketcall 102
|
||||
#define TARGET_NR_syslog 103
|
||||
#define TARGET_NR_setitimer 104
|
||||
#define TARGET_NR_getitimer 105
|
||||
#define TARGET_NR_stat 106
|
||||
#define TARGET_NR_lstat 107
|
||||
#define TARGET_NR_fstat 108
|
||||
#define TARGET_NR_olduname 109
|
||||
#define TARGET_NR_iopl 110
|
||||
#define TARGET_NR_vhangup 111
|
||||
#define TARGET_NR_idle 112
|
||||
#define TARGET_NR_vm86 113
|
||||
#define TARGET_NR_wait4 114
|
||||
#define TARGET_NR_swapoff 115
|
||||
#define TARGET_NR_sysinfo 116
|
||||
#define TARGET_NR_ipc 117
|
||||
#define TARGET_NR_fsync 118
|
||||
#define TARGET_NR_sigreturn 119
|
||||
#define TARGET_NR_clone 120
|
||||
#define TARGET_NR_setdomainname 121
|
||||
#define TARGET_NR_uname 122
|
||||
#define TARGET_NR_modify_ldt 123
|
||||
#define TARGET_NR_adjtimex 124
|
||||
#define TARGET_NR_mprotect 125
|
||||
#define TARGET_NR_sigprocmask 126
|
||||
#define TARGET_NR_create_module 127
|
||||
#define TARGET_NR_init_module 128
|
||||
#define TARGET_NR_delete_module 129
|
||||
#define TARGET_NR_get_kernel_syms 130
|
||||
#define TARGET_NR_quotactl 131
|
||||
#define TARGET_NR_getpgid 132
|
||||
#define TARGET_NR_fchdir 133
|
||||
#define TARGET_NR_bdflush 134
|
||||
#define TARGET_NR_sysfs 135
|
||||
#define TARGET_NR_personality 136
|
||||
#define TARGET_NR_afs_syscall 137 /* Syscall for Andrew File System */
|
||||
#define TARGET_NR_setfsuid32 138
|
||||
#define TARGET_NR_setfsgid32 139
|
||||
#define TARGET_NR__llseek 140
|
||||
#define TARGET_NR_getdents 141
|
||||
#define TARGET_NR__newselect 142
|
||||
#define TARGET_NR_flock 143
|
||||
#define TARGET_NR_msync 144
|
||||
#define TARGET_NR_readv 145
|
||||
#define TARGET_NR_writev 146
|
||||
#define TARGET_NR_getsid 147
|
||||
#define TARGET_NR_fdatasync 148
|
||||
#define TARGET_NR__sysctl 149
|
||||
#define TARGET_NR_mlock 150
|
||||
#define TARGET_NR_munlock 151
|
||||
#define TARGET_NR_mlockall 152
|
||||
#define TARGET_NR_munlockall 153
|
||||
#define TARGET_NR_sched_setparam 154
|
||||
#define TARGET_NR_sched_getparam 155
|
||||
#define TARGET_NR_sched_setscheduler 156
|
||||
#define TARGET_NR_sched_getscheduler 157
|
||||
#define TARGET_NR_sched_yield 158
|
||||
#define TARGET_NR_sched_get_priority_max 159
|
||||
#define TARGET_NR_sched_get_priority_min 160
|
||||
#define TARGET_NR_sched_rr_get_interval 161
|
||||
#define TARGET_NR_nanosleep 162
|
||||
#define TARGET_NR_mremap 163
|
||||
#define TARGET_NR_setresuid32 164
|
||||
#define TARGET_NR_getresuid32 165
|
||||
#define TARGET_NR_query_module 166
|
||||
#define TARGET_NR_poll 167
|
||||
#define TARGET_NR_nfsservctl 168
|
||||
#define TARGET_NR_setresgid32 169
|
||||
#define TARGET_NR_getresgid32 170
|
||||
#define TARGET_NR_prctl 171
|
||||
#define TARGET_NR_rt_sigreturn 172
|
||||
#define TARGET_NR_rt_sigaction 173
|
||||
#define TARGET_NR_rt_sigprocmask 174
|
||||
#define TARGET_NR_rt_sigpending 175
|
||||
#define TARGET_NR_rt_sigtimedwait 176
|
||||
#define TARGET_NR_rt_sigqueueinfo 177
|
||||
#define TARGET_NR_rt_sigsuspend 178
|
||||
#define TARGET_NR_pread64 179
|
||||
#define TARGET_NR_pwrite64 180
|
||||
#define TARGET_NR_chown32 181
|
||||
#define TARGET_NR_getcwd 182
|
||||
#define TARGET_NR_capget 183
|
||||
#define TARGET_NR_capset 184
|
||||
#define TARGET_NR_sigaltstack 185
|
||||
#define TARGET_NR_sendfile 186
|
||||
#define TARGET_NR_getpmsg 187 /* some people actually want streams */
|
||||
#define TARGET_NR_putpmsg 188 /* some people actually want streams */
|
||||
#define TARGET_NR_vfork 189
|
||||
#define TARGET_NR_ugetrlimit 190 /* SuS compliant getrlimit */
|
||||
#define TARGET_NR_readahead 191
|
||||
#define TARGET_NR_mmap2 192
|
||||
#define TARGET_NR_truncate64 193
|
||||
#define TARGET_NR_ftruncate64 194
|
||||
#define TARGET_NR_stat64 195
|
||||
#define TARGET_NR_lstat64 196
|
||||
#define TARGET_NR_fstat64 197
|
||||
#define TARGET_NR_pciconfig_read 198
|
||||
#define TARGET_NR_pciconfig_write 199
|
||||
#define TARGET_NR_pciconfig_iobase 200
|
||||
#define TARGET_NR_multiplexer 201
|
||||
#define TARGET_NR_getdents64 202
|
||||
#define TARGET_NR_pivot_root 203
|
||||
#define TARGET_NR_fcntl64 204
|
||||
#define TARGET_NR_madvise 205
|
||||
#define TARGET_NR_mincore 206
|
||||
#define TARGET_NR_gettid 207
|
||||
#define TARGET_NR_tkill 208
|
||||
#define TARGET_NR_setxattr 209
|
||||
#define TARGET_NR_lsetxattr 210
|
||||
#define TARGET_NR_fsetxattr 211
|
||||
#define TARGET_NR_getxattr 212
|
||||
#define TARGET_NR_lgetxattr 213
|
||||
#define TARGET_NR_fgetxattr 214
|
||||
#define TARGET_NR_listxattr 215
|
||||
#define TARGET_NR_llistxattr 216
|
||||
#define TARGET_NR_flistxattr 217
|
||||
#define TARGET_NR_removexattr 218
|
||||
#define TARGET_NR_lremovexattr 219
|
||||
#define TARGET_NR_fremovexattr 220
|
||||
#define TARGET_NR_futex 221
|
||||
#define TARGET_NR_sched_setaffinity 222
|
||||
#define TARGET_NR_sched_getaffinity 223
|
||||
/* 224 currently unused */
|
||||
#define TARGET_NR_tuxcall 225
|
||||
#define TARGET_NR_sendfile64 226
|
||||
#define TARGET_NR_io_setup 227
|
||||
#define TARGET_NR_io_destroy 228
|
||||
#define TARGET_NR_io_getevents 229
|
||||
#define TARGET_NR_io_submit 230
|
||||
#define TARGET_NR_io_cancel 231
|
||||
#define TARGET_NR_set_tid_address 232
|
||||
#define TARGET_NR_fadvise64 233
|
||||
#define TARGET_NR_exit_group 234
|
||||
#define TARGET_NR_lookup_dcookie 235
|
||||
#define TARGET_NR_epoll_create 236
|
||||
#define TARGET_NR_epoll_ctl 237
|
||||
#define TARGET_NR_epoll_wait 238
|
||||
#define TARGET_NR_remap_file_pages 239
|
||||
#define TARGET_NR_timer_create 240
|
||||
#define TARGET_NR_timer_settime 241
|
||||
#define TARGET_NR_timer_gettime 242
|
||||
#define TARGET_NR_timer_getoverrun 243
|
||||
#define TARGET_NR_timer_delete 244
|
||||
#define TARGET_NR_clock_settime 245
|
||||
#define TARGET_NR_clock_gettime 246
|
||||
#define TARGET_NR_clock_getres 247
|
||||
#define TARGET_NR_clock_nanosleep 248
|
||||
#define TARGET_NR_swapcontext 249
|
||||
#define TARGET_NR_tgkill 250
|
||||
#define TARGET_NR_utimes 251
|
||||
#define TARGET_NR_statfs64 252
|
||||
#define TARGET_NR_fstatfs64 253
|
||||
#define TARGET_NR_fadvise64_64 254
|
235
linux-user/ppc/termbits.h
Normal file
235
linux-user/ppc/termbits.h
Normal file
@@ -0,0 +1,235 @@
|
||||
/* from asm/termbits.h */
|
||||
|
||||
#define TARGET_NCCS 19
|
||||
|
||||
struct target_termios {
|
||||
unsigned int c_iflag; /* input mode flags */
|
||||
unsigned int c_oflag; /* output mode flags */
|
||||
unsigned int c_cflag; /* control mode flags */
|
||||
unsigned int c_lflag; /* local mode flags */
|
||||
unsigned char c_line; /* line discipline */
|
||||
unsigned char c_cc[TARGET_NCCS]; /* control characters */
|
||||
unsigned int c_ispeed; /* input speed */
|
||||
unsigned int c_ospeed; /* output speed */
|
||||
};
|
||||
|
||||
/* c_cc character offsets */
|
||||
#define TARGET_VINTR 0
|
||||
#define TARGET_VQUIT 1
|
||||
#define TARGET_VERASE 2
|
||||
#define TARGET_VKILL 3
|
||||
#define TARGET_VEOF 4
|
||||
#define TARGET_VMIN 5
|
||||
#define TARGET_VEOL 6
|
||||
#define TARGET_VTIME 7
|
||||
#define TARGET_VEOL2 8
|
||||
#define TARGET_VSWTC 9
|
||||
|
||||
#define TARGET_VWERASE 10
|
||||
#define TARGET_VREPRINT 11
|
||||
#define TARGET_VSUSP 12
|
||||
#define TARGET_VSTART 13
|
||||
#define TARGET_VSTOP 14
|
||||
#define TARGET_VLNEXT 15
|
||||
#define TARGET_VDISCARD 16
|
||||
|
||||
#define TARGET_IGNBRK 0000001
|
||||
#define TARGET_BRKINT 0000002
|
||||
#define TARGET_IGNPAR 0000004
|
||||
#define TARGET_PARMRK 0000010
|
||||
#define TARGET_INPCK 0000020
|
||||
#define TARGET_ISTRIP 0000040
|
||||
#define TARGET_INLCR 0000100
|
||||
#define TARGET_IGNCR 0000200
|
||||
#define TARGET_ICRNL 0000400
|
||||
#define TARGET_IXON 0001000
|
||||
#define TARGET_IXOFF 0002000
|
||||
#define TARGET_IXANY 0004000
|
||||
#define TARGET_IUCLC 0010000
|
||||
#define TARGET_IMAXBEL 0020000
|
||||
|
||||
/* c_oflag bits */
|
||||
#define TARGET_OPOST 0000001
|
||||
#define TARGET_ONLCR 0000002
|
||||
#define TARGET_OLCUC 0000004
|
||||
|
||||
#define TARGET_OCRNL 0000010
|
||||
#define TARGET_ONOCR 0000020
|
||||
#define TARGET_ONLRET 0000040
|
||||
|
||||
#define TARGET_OFILL 00000100
|
||||
#define TARGET_OFDEL 00000200
|
||||
#define TARGET_NLDLY 00001400
|
||||
#define TARGET_NL0 00000000
|
||||
#define TARGET_NL1 00000400
|
||||
#define TARGET_NL2 00001000
|
||||
#define TARGET_NL3 00001400
|
||||
#define TARGET_TABDLY 00006000
|
||||
#define TARGET_TAB0 00000000
|
||||
#define TARGET_TAB1 00002000
|
||||
#define TARGET_TAB2 00004000
|
||||
#define TARGET_TAB3 00006000
|
||||
#define TARGET_CRDLY 00030000
|
||||
#define TARGET_CR0 00000000
|
||||
#define TARGET_CR1 00010000
|
||||
#define TARGET_CR2 00020000
|
||||
#define TARGET_CR3 00030000
|
||||
#define TARGET_FFDLY 00040000
|
||||
#define TARGET_FF0 00000000
|
||||
#define TARGET_FF1 00040000
|
||||
#define TARGET_BSDLY 00100000
|
||||
#define TARGET_BS0 00000000
|
||||
#define TARGET_BS1 00100000
|
||||
#define TARGET_VTDLY 00200000
|
||||
#define TARGET_VT0 00000000
|
||||
#define TARGET_VT1 00200000
|
||||
#define TARGET_XTABS 01000000 /* Hmm.. Linux/i386 considers this part of TABDLY.. */
|
||||
|
||||
/* c_cflag bit meaning */
|
||||
#define TARGET_CBAUD 0000377
|
||||
#define TARGET_B0 0000000 /* hang up */
|
||||
#define TARGET_B50 0000001
|
||||
#define TARGET_B75 0000002
|
||||
#define TARGET_B110 0000003
|
||||
#define TARGET_B134 0000004
|
||||
#define TARGET_B150 0000005
|
||||
#define TARGET_B200 0000006
|
||||
#define TARGET_B300 0000007
|
||||
#define TARGET_B600 0000010
|
||||
#define TARGET_B1200 0000011
|
||||
#define TARGET_B1800 0000012
|
||||
#define TARGET_B2400 0000013
|
||||
#define TARGET_B4800 0000014
|
||||
#define TARGET_B9600 0000015
|
||||
#define TARGET_B19200 0000016
|
||||
#define TARGET_B38400 0000017
|
||||
#define TARGET_EXTA B19200
|
||||
#define TARGET_EXTB B38400
|
||||
#define TARGET_CBAUDEX 0000000
|
||||
#define TARGET_B57600 00020
|
||||
#define TARGET_B115200 00021
|
||||
#define TARGET_B230400 00022
|
||||
#define TARGET_B460800 00023
|
||||
#define TARGET_B500000 00024
|
||||
#define TARGET_B576000 00025
|
||||
#define TARGET_B921600 00026
|
||||
#define TARGET_B1000000 00027
|
||||
#define TARGET_B1152000 00030
|
||||
#define TARGET_B1500000 00031
|
||||
#define TARGET_B2000000 00032
|
||||
#define TARGET_B2500000 00033
|
||||
#define TARGET_B3000000 00034
|
||||
#define TARGET_B3500000 00035
|
||||
#define TARGET_B4000000 00036
|
||||
|
||||
#define TARGET_CSIZE 00001400
|
||||
#define TARGET_CS5 00000000
|
||||
#define TARGET_CS6 00000400
|
||||
#define TARGET_CS7 00001000
|
||||
#define TARGET_CS8 00001400
|
||||
|
||||
#define TARGET_CSTOPB 00002000
|
||||
#define TARGET_CREAD 00004000
|
||||
#define TARGET_PARENB 00010000
|
||||
#define TARGET_PARODD 00020000
|
||||
#define TARGET_HUPCL 00040000
|
||||
|
||||
#define TARGET_CLOCAL 00100000
|
||||
#define TARGET_CRTSCTS 020000000000 /* flow control */
|
||||
|
||||
/* c_lflag bits */
|
||||
#define TARGET_ISIG 0x00000080
|
||||
#define TARGET_ICANON 0x00000100
|
||||
#define TARGET_XCASE 0x00004000
|
||||
#define TARGET_ECHO 0x00000008
|
||||
#define TARGET_ECHOE 0x00000002
|
||||
#define TARGET_ECHOK 0x00000004
|
||||
#define TARGET_ECHONL 0x00000010
|
||||
#define TARGET_NOFLSH 0x80000000
|
||||
#define TARGET_TOSTOP 0x00400000
|
||||
#define TARGET_ECHOCTL 0x00000040
|
||||
#define TARGET_ECHOPRT 0x00000020
|
||||
#define TARGET_ECHOKE 0x00000001
|
||||
#define TARGET_FLUSHO 0x00800000
|
||||
#define TARGET_PENDIN 0x20000000
|
||||
#define TARGET_IEXTEN 0x00000400
|
||||
|
||||
/* ioctls */
|
||||
|
||||
#define TARGET_FIOCLEX TARGET_IO('f', 1)
|
||||
#define TARGET_FIONCLEX TARGET_IO('f', 2)
|
||||
#define TARGET_FIOASYNC TARGET_IOW('f', 125, int)
|
||||
#define TARGET_FIONBIO TARGET_IOW('f', 126, int)
|
||||
#define TARGET_FIONREAD TARGET_IOR('f', 127, int)
|
||||
#define TARGET_TIOCINQ TARGET_FIONREAD
|
||||
//#define TARGET_FIOQSIZE TARGET_IOR('f', 128, loff_t)
|
||||
|
||||
#define TARGET_TCGETS TARGET_IOR('t', 19, struct target_termios)
|
||||
#define TARGET_TCSETS TARGET_IOW('t', 20, struct target_termios)
|
||||
#define TARGET_TCSETSW TARGET_IOW('t', 21, struct target_termios)
|
||||
#define TARGET_TCSETSF TARGET_IOW('t', 22, struct target_termios)
|
||||
|
||||
#define TARGET_TCGETA TARGET_IOR('t', 23, struct target_termio)
|
||||
#define TARGET_TCSETA TARGET_IOW('t', 24, struct target_termio)
|
||||
#define TARGET_TCSETAW TARGET_IOW('t', 25, struct target_termio)
|
||||
#define TARGET_TCSETAF TARGET_IOW('t', 28, struct target_termio)
|
||||
|
||||
#define TARGET_TCSBRK TARGET_IO('t', 29)
|
||||
#define TARGET_TCXONC TARGET_IO('t', 30)
|
||||
#define TARGET_TCFLSH TARGET_IO('t', 31)
|
||||
|
||||
#define TARGET_TIOCSWINSZ TARGET_IOW('t', 103, struct target_winsize)
|
||||
#define TARGET_TIOCGWINSZ TARGET_IOR('t', 104, struct target_winsize)
|
||||
#define TARGET_TIOCSTART TARGET_IO('t', 110) /* start output, like ^Q */
|
||||
#define TARGET_TIOCSTOP TARGET_IO('t', 111) /* stop output, like ^S */
|
||||
#define TARGET_TIOCOUTQ TARGET_IOR('t', 115, int) /* output queue size */
|
||||
|
||||
#define TARGET_TIOCGLTC TARGET_IOR('t', 116, struct target_ltchars)
|
||||
#define TARGET_TIOCSLTC TARGET_IOW('t', 117, struct target_ltchars)
|
||||
#define TARGET_TIOCSPGRP TARGET_IOW('t', 118, int)
|
||||
#define TARGET_TIOCGPGRP TARGET_IOR('t', 119, int)
|
||||
|
||||
#define TARGET_TIOCEXCL 0x540C
|
||||
#define TARGET_TIOCNXCL 0x540D
|
||||
#define TARGET_TIOCSCTTY 0x540E
|
||||
|
||||
#define TARGET_TIOCSTI 0x5412
|
||||
#define TARGET_TIOCMGET 0x5415
|
||||
#define TARGET_TIOCMBIS 0x5416
|
||||
#define TARGET_TIOCMBIC 0x5417
|
||||
#define TARGET_TIOCMSET 0x5418
|
||||
|
||||
#define TARGET_TIOCGSOFTCAR 0x5419
|
||||
#define TARGET_TIOCSSOFTCAR 0x541A
|
||||
#define TARGET_TIOCLINUX 0x541C
|
||||
#define TARGET_TIOCCONS 0x541D
|
||||
#define TARGET_TIOCGSERIAL 0x541E
|
||||
#define TARGET_TIOCSSERIAL 0x541F
|
||||
#define TARGET_TIOCPKT 0x5420
|
||||
|
||||
#define TARGET_TIOCNOTTY 0x5422
|
||||
#define TARGET_TIOCSETD 0x5423
|
||||
#define TARGET_TIOCGETD 0x5424
|
||||
#define TARGET_TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */
|
||||
#define TARGET_TIOCTTYGSTRUCT 0x5426 /* For debugging only */
|
||||
#define TARGET_TIOCSBRK 0x5427 /* BSD compatibility */
|
||||
#define TARGET_TIOCCBRK 0x5428 /* BSD compatibility */
|
||||
#define TARGET_TIOCGSID 0x5429 /* Return the session ID of FD */
|
||||
#define TARGET_TIOCGPTN TARGET_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
|
||||
#define TARGET_TIOCSPTLCK TARGET_IOW('T',0x31, int) /* Lock/unlock Pty */
|
||||
|
||||
#define TARGET_TIOCSERCONFIG 0x5453
|
||||
#define TARGET_TIOCSERGWILD 0x5454
|
||||
#define TARGET_TIOCSERSWILD 0x5455
|
||||
#define TARGET_TIOCGLCKTRMIOS 0x5456
|
||||
#define TARGET_TIOCSLCKTRMIOS 0x5457
|
||||
#define TARGET_TIOCSERGSTRUCT 0x5458 /* For debugging only */
|
||||
#define TARGET_TIOCSERGETLSR 0x5459 /* Get line status register */
|
||||
/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
|
||||
# define TARGET_TIOCSER_TEMT 0x01 /* Transmitter physically empty */
|
||||
#define TARGET_TIOCSERGETMULTI 0x545A /* Get multiport config */
|
||||
#define TARGET_TIOCSERSETMULTI 0x545B /* Set multiport config */
|
||||
|
||||
#define TARGET_TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */
|
||||
#define TARGET_TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */
|
||||
|
279
linux-user/sparc/termbits.h
Normal file
279
linux-user/sparc/termbits.h
Normal file
@@ -0,0 +1,279 @@
|
||||
/* from asm/termbits.h */
|
||||
|
||||
#define TARGET_NCCS 19
|
||||
|
||||
struct target_termios {
|
||||
unsigned int c_iflag; /* input mode flags */
|
||||
unsigned int c_oflag; /* output mode flags */
|
||||
unsigned int c_cflag; /* control mode flags */
|
||||
unsigned int c_lflag; /* local mode flags */
|
||||
unsigned char c_line; /* line discipline */
|
||||
unsigned char c_cc[TARGET_NCCS]; /* control characters */
|
||||
};
|
||||
|
||||
/* c_cc characters */
|
||||
#define TARGET_VINTR 0
|
||||
#define TARGET_VQUIT 1
|
||||
#define TARGET_VERASE 2
|
||||
#define TARGET_VKILL 3
|
||||
#define TARGET_VEOF 4
|
||||
#define TARGET_VEOL 5
|
||||
#define TARGET_VEOL2 6
|
||||
#define TARGET_VSWTC 7
|
||||
#define TARGET_VSTART 8
|
||||
#define TARGET_VSTOP 9
|
||||
|
||||
#define TARGET_VSUSP 10
|
||||
#define TARGET_VDSUSP 11 /* SunOS POSIX nicety I do believe... */
|
||||
#define TARGET_VREPRINT 12
|
||||
#define TARGET_VDISCARD 13
|
||||
#define TARGET_VWERASE 14
|
||||
#define TARGET_VLNEXT 15
|
||||
|
||||
/* Kernel keeps vmin/vtime separated, user apps assume vmin/vtime is
|
||||
* shared with eof/eol
|
||||
*/
|
||||
#define TARGET_VMIN TARGET_VEOF
|
||||
#define TARGET_VTIME TARGET_VEOL
|
||||
|
||||
/* c_iflag bits */
|
||||
#define TARGET_IGNBRK 0x00000001
|
||||
#define TARGET_BRKINT 0x00000002
|
||||
#define TARGET_IGNPAR 0x00000004
|
||||
#define TARGET_PARMRK 0x00000008
|
||||
#define TARGET_INPCK 0x00000010
|
||||
#define TARGET_ISTRIP 0x00000020
|
||||
#define TARGET_INLCR 0x00000040
|
||||
#define TARGET_IGNCR 0x00000080
|
||||
#define TARGET_ICRNL 0x00000100
|
||||
#define TARGET_IUCLC 0x00000200
|
||||
#define TARGET_IXON 0x00000400
|
||||
#define TARGET_IXANY 0x00000800
|
||||
#define TARGET_IXOFF 0x00001000
|
||||
#define TARGET_IMAXBEL 0x00002000
|
||||
|
||||
/* c_oflag bits */
|
||||
#define TARGET_OPOST 0x00000001
|
||||
#define TARGET_OLCUC 0x00000002
|
||||
#define TARGET_ONLCR 0x00000004
|
||||
#define TARGET_OCRNL 0x00000008
|
||||
#define TARGET_ONOCR 0x00000010
|
||||
#define TARGET_ONLRET 0x00000020
|
||||
#define TARGET_OFILL 0x00000040
|
||||
#define TARGET_OFDEL 0x00000080
|
||||
#define TARGET_NLDLY 0x00000100
|
||||
#define TARGET_NL0 0x00000000
|
||||
#define TARGET_NL1 0x00000100
|
||||
#define TARGET_CRDLY 0x00000600
|
||||
#define TARGET_CR0 0x00000000
|
||||
#define TARGET_CR1 0x00000200
|
||||
#define TARGET_CR2 0x00000400
|
||||
#define TARGET_CR3 0x00000600
|
||||
#define TARGET_TABDLY 0x00001800
|
||||
#define TARGET_TAB0 0x00000000
|
||||
#define TARGET_TAB1 0x00000800
|
||||
#define TARGET_TAB2 0x00001000
|
||||
#define TARGET_TAB3 0x00001800
|
||||
#define TARGET_XTABS 0x00001800
|
||||
#define TARGET_BSDLY 0x00002000
|
||||
#define TARGET_BS0 0x00000000
|
||||
#define TARGET_BS1 0x00002000
|
||||
#define TARGET_VTDLY 0x00004000
|
||||
#define TARGET_VT0 0x00000000
|
||||
#define TARGET_VT1 0x00004000
|
||||
#define TARGET_FFDLY 0x00008000
|
||||
#define TARGET_FF0 0x00000000
|
||||
#define TARGET_FF1 0x00008000
|
||||
#define TARGET_PAGEOUT 0x00010000 /* SUNOS specific */
|
||||
#define TARGET_WRAP 0x00020000 /* SUNOS specific */
|
||||
|
||||
/* c_cflag bit meaning */
|
||||
#define TARGET_CBAUD 0x0000100f
|
||||
#define TARGET_B0 0x00000000 /* hang up */
|
||||
#define TARGET_B50 0x00000001
|
||||
#define TARGET_B75 0x00000002
|
||||
#define TARGET_B110 0x00000003
|
||||
#define TARGET_B134 0x00000004
|
||||
#define TARGET_B150 0x00000005
|
||||
#define TARGET_B200 0x00000006
|
||||
#define TARGET_B300 0x00000007
|
||||
#define TARGET_B600 0x00000008
|
||||
#define TARGET_B1200 0x00000009
|
||||
#define TARGET_B1800 0x0000000a
|
||||
#define TARGET_B2400 0x0000000b
|
||||
#define TARGET_B4800 0x0000000c
|
||||
#define TARGET_B9600 0x0000000d
|
||||
#define TARGET_B19200 0x0000000e
|
||||
#define TARGET_B38400 0x0000000f
|
||||
#define TARGET_EXTA B19200
|
||||
#define TARGET_EXTB B38400
|
||||
#define TARGET_CSIZE 0x00000030
|
||||
#define TARGET_CS5 0x00000000
|
||||
#define TARGET_CS6 0x00000010
|
||||
#define TARGET_CS7 0x00000020
|
||||
#define TARGET_CS8 0x00000030
|
||||
#define TARGET_CSTOPB 0x00000040
|
||||
#define TARGET_CREAD 0x00000080
|
||||
#define TARGET_PARENB 0x00000100
|
||||
#define TARGET_PARODD 0x00000200
|
||||
#define TARGET_HUPCL 0x00000400
|
||||
#define TARGET_CLOCAL 0x00000800
|
||||
#define TARGET_CBAUDEX 0x00001000
|
||||
/* We'll never see these speeds with the Zilogs, but for completeness... */
|
||||
#define TARGET_B57600 0x00001001
|
||||
#define TARGET_B115200 0x00001002
|
||||
#define TARGET_B230400 0x00001003
|
||||
#define TARGET_B460800 0x00001004
|
||||
/* This is what we can do with the Zilogs. */
|
||||
#define TARGET_B76800 0x00001005
|
||||
/* This is what we can do with the SAB82532. */
|
||||
#define TARGET_B153600 0x00001006
|
||||
#define TARGET_B307200 0x00001007
|
||||
#define TARGET_B614400 0x00001008
|
||||
#define TARGET_B921600 0x00001009
|
||||
/* And these are the rest... */
|
||||
#define TARGET_B500000 0x0000100a
|
||||
#define TARGET_B576000 0x0000100b
|
||||
#define TARGET_B1000000 0x0000100c
|
||||
#define TARGET_B1152000 0x0000100d
|
||||
#define TARGET_B1500000 0x0000100e
|
||||
#define TARGET_B2000000 0x0000100f
|
||||
/* These have totally bogus values and nobody uses them
|
||||
so far. Later on we'd have to use say 0x10000x and
|
||||
adjust CBAUD constant and drivers accordingly.
|
||||
#define B2500000 0x00001010
|
||||
#define B3000000 0x00001011
|
||||
#define B3500000 0x00001012
|
||||
#define B4000000 0x00001013 */
|
||||
#define TARGET_CIBAUD 0x100f0000 /* input baud rate (not used) */
|
||||
#define TARGET_CMSPAR 0x40000000 /* mark or space (stick) parity */
|
||||
#define TARGET_CRTSCTS 0x80000000 /* flow control */
|
||||
|
||||
/* c_lflag bits */
|
||||
#define TARGET_ISIG 0x00000001
|
||||
#define TARGET_ICANON 0x00000002
|
||||
#define TARGET_XCASE 0x00000004
|
||||
#define TARGET_ECHO 0x00000008
|
||||
#define TARGET_ECHOE 0x00000010
|
||||
#define TARGET_ECHOK 0x00000020
|
||||
#define TARGET_ECHONL 0x00000040
|
||||
#define TARGET_NOFLSH 0x00000080
|
||||
#define TARGET_TOSTOP 0x00000100
|
||||
#define TARGET_ECHOCTL 0x00000200
|
||||
#define TARGET_ECHOPRT 0x00000400
|
||||
#define TARGET_ECHOKE 0x00000800
|
||||
#define TARGET_DEFECHO 0x00001000 /* SUNOS thing, what is it? */
|
||||
#define TARGET_FLUSHO 0x00002000
|
||||
#define TARGET_PENDIN 0x00004000
|
||||
#define TARGET_IEXTEN 0x00008000
|
||||
|
||||
/* ioctls */
|
||||
|
||||
/* Big T */
|
||||
#define TARGET_TCGETA TARGET_IOR('T', 1, struct target_termio)
|
||||
#define TARGET_TCSETA TARGET_IOW('T', 2, struct target_termio)
|
||||
#define TARGET_TCSETAW TARGET_IOW('T', 3, struct target_termio)
|
||||
#define TARGET_TCSETAF TARGET_IOW('T', 4, struct target_termio)
|
||||
#define TARGET_TCSBRK TARGET_IO('T', 5)
|
||||
#define TARGET_TCXONC TARGET_IO('T', 6)
|
||||
#define TARGET_TCFLSH TARGET_IO('T', 7)
|
||||
#define TARGET_TCGETS TARGET_IOR('T', 8, struct target_termios)
|
||||
#define TARGET_TCSETS TARGET_IOW('T', 9, struct target_termios)
|
||||
#define TARGET_TCSETSW TARGET_IOW('T', 10, struct target_termios)
|
||||
#define TARGET_TCSETSF TARGET_IOW('T', 11, struct target_termios)
|
||||
|
||||
/* Note that all the ioctls that are not available in Linux have a
|
||||
* double underscore on the front to: a) avoid some programs to
|
||||
* thing we support some ioctls under Linux (autoconfiguration stuff)
|
||||
*/
|
||||
/* Little t */
|
||||
#define TARGET_TIOCGETD TARGET_IOR('t', 0, int)
|
||||
#define TARGET_TIOCSETD TARGET_IOW('t', 1, int)
|
||||
//#define __TIOCHPCL _IO('t', 2) /* SunOS Specific */
|
||||
//#define __TIOCMODG _IOR('t', 3, int) /* SunOS Specific */
|
||||
//#define __TIOCMODS _IOW('t', 4, int) /* SunOS Specific */
|
||||
//#define __TIOCGETP _IOR('t', 8, struct sgttyb) /* SunOS Specific */
|
||||
//#define __TIOCSETP _IOW('t', 9, struct sgttyb) /* SunOS Specific */
|
||||
//#define __TIOCSETN _IOW('t', 10, struct sgttyb) /* SunOS Specific */
|
||||
#define TARGET_TIOCEXCL TARGET_IO('t', 13)
|
||||
#define TARGET_TIOCNXCL TARGET_IO('t', 14)
|
||||
//#define __TIOCFLUSH _IOW('t', 16, int) /* SunOS Specific */
|
||||
//#define __TIOCSETC _IOW('t', 17, struct tchars) /* SunOS Specific */
|
||||
//#define __TIOCGETC _IOR('t', 18, struct tchars) /* SunOS Specific */
|
||||
//#define __TIOCTCNTL _IOW('t', 32, int) /* SunOS Specific */
|
||||
//#define __TIOCSIGNAL _IOW('t', 33, int) /* SunOS Specific */
|
||||
//#define __TIOCSETX _IOW('t', 34, int) /* SunOS Specific */
|
||||
//#define __TIOCGETX _IOR('t', 35, int) /* SunOS Specific */
|
||||
#define TARGET_TIOCCONS TARGET_IO('t', 36)
|
||||
//#define __TIOCSSIZE _IOW('t', 37, struct sunos_ttysize) /* SunOS Specific */
|
||||
//#define __TIOCGSIZE _IOR('t', 38, struct sunos_ttysize) /* SunOS Specific */
|
||||
#define TARGET_TIOCGSOFTCAR TARGET_IOR('t', 100, int)
|
||||
#define TARGET_TIOCSSOFTCAR TARGET_IOW('t', 101, int)
|
||||
//#define __TIOCUCNTL _IOW('t', 102, int) /* SunOS Specific */
|
||||
#define TARGET_TIOCSWINSZ TARGET_IOW('t', 103, struct winsize)
|
||||
#define TARGET_TIOCGWINSZ TARGET_IOR('t', 104, struct winsize)
|
||||
//#define __TIOCREMOTE _IOW('t', 105, int) /* SunOS Specific */
|
||||
#define TARGET_TIOCMGET TARGET_IOR('t', 106, int)
|
||||
#define TARGET_TIOCMBIC TARGET_IOW('t', 107, int)
|
||||
#define TARGET_TIOCMBIS TARGET_IOW('t', 108, int)
|
||||
#define TARGET_TIOCMSET TARGET_IOW('t', 109, int)
|
||||
#define TARGET_TIOCSTART TARGET_IO('t', 110)
|
||||
#define TARGET_TIOCSTOP TARGET_IO('t', 111)
|
||||
#define TARGET_TIOCPKT TARGET_IOW('t', 112, int)
|
||||
#define TARGET_TIOCNOTTY TARGET_IO('t', 113)
|
||||
#define TARGET_TIOCSTI TARGET_IOW('t', 114, char)
|
||||
#define TARGET_TIOCOUTQ TARGET_IOR('t', 115, int)
|
||||
//#define __TIOCGLTC _IOR('t', 116, struct ltchars) /* SunOS Specific */
|
||||
//#define __TIOCSLTC _IOW('t', 117, struct ltchars) /* SunOS Specific */
|
||||
/* 118 is the non-posix setpgrp tty ioctl */
|
||||
/* 119 is the non-posix getpgrp tty ioctl */
|
||||
//#define __TIOCCDTR TARGET_IO('t', 120) /* SunOS Specific */
|
||||
//#define __TIOCSDTR TARGET_IO('t', 121) /* SunOS Specific */
|
||||
#define TARGET_TIOCCBRK TARGET_IO('t', 122)
|
||||
#define TARGET_TIOCSBRK TARGET_IO('t', 123)
|
||||
//#define __TIOCLGET TARGET_IOW('t', 124, int) /* SunOS Specific */
|
||||
//#define __TIOCLSET TARGET_IOW('t', 125, int) /* SunOS Specific */
|
||||
//#define __TIOCLBIC TARGET_IOW('t', 126, int) /* SunOS Specific */
|
||||
//#define __TIOCLBIS TARGET_IOW('t', 127, int) /* SunOS Specific */
|
||||
//#define __TIOCISPACE TARGET_IOR('t', 128, int) /* SunOS Specific */
|
||||
//#define __TIOCISIZE TARGET_IOR('t', 129, int) /* SunOS Specific */
|
||||
#define TARGET_TIOCSPGRP TARGET_IOW('t', 130, int)
|
||||
#define TARGET_TIOCGPGRP TARGET_IOR('t', 131, int)
|
||||
#define TARGET_TIOCSCTTY TARGET_IO('t', 132)
|
||||
#define TARGET_TIOCGSID TARGET_IOR('t', 133, int)
|
||||
/* Get minor device of a pty master's FD -- Solaris equiv is ISPTM */
|
||||
#define TARGET_TIOCGPTN TARGET_IOR('t', 134, unsigned int) /* Get Pty Number */
|
||||
#define TARGET_TIOCSPTLCK TARGET_IOW('t', 135, int) /* Lock/unlock PTY */
|
||||
|
||||
/* Little f */
|
||||
#define TARGET_FIOCLEX TARGET_IO('f', 1)
|
||||
#define TARGET_FIONCLEX TARGET_IO('f', 2)
|
||||
#define TARGET_FIOASYNC TARGET_IOW('f', 125, int)
|
||||
#define TARGET_FIONBIO TARGET_IOW('f', 126, int)
|
||||
#define TARGET_FIONREAD TARGET_IOR('f', 127, int)
|
||||
#define TARGET_TIOCINQ TARGET_FIONREAD
|
||||
|
||||
/* SCARY Rutgers local SunOS kernel hackery, perhaps I will support it
|
||||
* someday. This is completely bogus, I know...
|
||||
*/
|
||||
//#define __TCGETSTAT TARGET_IO('T', 200) /* Rutgers specific */
|
||||
//#define __TCSETSTAT TARGET_IO('T', 201) /* Rutgers specific */
|
||||
|
||||
/* Linux specific, no SunOS equivalent. */
|
||||
#define TARGET_TIOCLINUX 0x541C
|
||||
#define TARGET_TIOCGSERIAL 0x541E
|
||||
#define TARGET_TIOCSSERIAL 0x541F
|
||||
#define TARGET_TCSBRKP 0x5425
|
||||
#define TARGET_TIOCTTYGSTRUCT 0x5426
|
||||
#define TARGET_TIOCSERCONFIG 0x5453
|
||||
#define TARGET_TIOCSERGWILD 0x5454
|
||||
#define TARGET_TIOCSERSWILD 0x5455
|
||||
#define TARGET_TIOCGLCKTRMIOS 0x5456
|
||||
#define TARGET_TIOCSLCKTRMIOS 0x5457
|
||||
#define TARGET_TIOCSERGSTRUCT 0x5458 /* For debugging only */
|
||||
#define TARGET_TIOCSERGETLSR 0x5459 /* Get line status register */
|
||||
#define TARGET_TIOCSERGETMULTI 0x545A /* Get multiport config */
|
||||
#define TARGET_TIOCSERSETMULTI 0x545B /* Set multiport config */
|
||||
#define TARGET_TIOCMIWAIT 0x545C /* Wait input */
|
||||
#define TARGET_TIOCGICOUNT 0x545D /* Read serial port inline interrupt counts */
|
||||
|
@@ -65,6 +65,11 @@
|
||||
|
||||
//#define DEBUG
|
||||
|
||||
#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC)
|
||||
/* 16 bit uid wrappers emulation */
|
||||
#define USE_UID16
|
||||
#endif
|
||||
|
||||
//#include <linux/msdos_fs.h>
|
||||
#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
|
||||
#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
|
||||
@@ -234,6 +239,27 @@ extern int setresgid(gid_t, gid_t, gid_t);
|
||||
extern int getresgid(gid_t *, gid_t *, gid_t *);
|
||||
extern int setgroups(int, gid_t *);
|
||||
|
||||
#define put_user(x,ptr)\
|
||||
({\
|
||||
int size = sizeof(*ptr);\
|
||||
switch(size) {\
|
||||
case 1:\
|
||||
stb(ptr, (typeof(*ptr))(x));\
|
||||
break;\
|
||||
case 2:\
|
||||
stw(ptr, (typeof(*ptr))(x));\
|
||||
break;\
|
||||
case 4:\
|
||||
stl(ptr, (typeof(*ptr))(x));\
|
||||
break;\
|
||||
case 8:\
|
||||
stq(ptr, (typeof(*ptr))(x));\
|
||||
break;\
|
||||
default:\
|
||||
abort();\
|
||||
}\
|
||||
0;\
|
||||
})
|
||||
static inline long get_errno(long ret)
|
||||
{
|
||||
if (ret == -1)
|
||||
@@ -1264,7 +1290,16 @@ int do_fork(CPUState *env, unsigned int flags, unsigned long newsp)
|
||||
new_env->regs[13] = newsp;
|
||||
new_env->regs[0] = 0;
|
||||
#elif defined(TARGET_SPARC)
|
||||
printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
|
||||
printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
|
||||
#elif defined(TARGET_PPC)
|
||||
if (!newsp)
|
||||
newsp = env->gpr[1];
|
||||
new_env->gpr[1] = newsp;
|
||||
{
|
||||
int i;
|
||||
for (i = 7; i < 32; i++)
|
||||
new_env->gpr[i] = 0;
|
||||
}
|
||||
#else
|
||||
#error unsupported target CPU
|
||||
#endif
|
||||
@@ -1325,11 +1360,41 @@ static long do_fcntl(int fd, int cmd, unsigned long arg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef USE_UID16
|
||||
|
||||
#define high2lowuid(x) (x)
|
||||
#define high2lowgid(x) (x)
|
||||
#define low2highuid(x) (x)
|
||||
#define low2highgid(x) (x)
|
||||
static inline int high2lowuid(int uid)
|
||||
{
|
||||
if (uid > 65535)
|
||||
return 65534;
|
||||
else
|
||||
return uid;
|
||||
}
|
||||
|
||||
static inline int high2lowgid(int gid)
|
||||
{
|
||||
if (gid > 65535)
|
||||
return 65534;
|
||||
else
|
||||
return gid;
|
||||
}
|
||||
|
||||
static inline int low2highuid(int uid)
|
||||
{
|
||||
if ((int16_t)uid == -1)
|
||||
return -1;
|
||||
else
|
||||
return uid;
|
||||
}
|
||||
|
||||
static inline int low2highgid(int gid)
|
||||
{
|
||||
if ((int16_t)gid == -1)
|
||||
return -1;
|
||||
else
|
||||
return gid;
|
||||
}
|
||||
|
||||
#endif /* USE_UID16 */
|
||||
|
||||
void syscall_init(void)
|
||||
{
|
||||
@@ -1371,7 +1436,7 @@ void syscall_init(void)
|
||||
ie++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
long arg4, long arg5, long arg6)
|
||||
{
|
||||
@@ -1380,7 +1445,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
struct kernel_statfs *stfs;
|
||||
|
||||
#ifdef DEBUG
|
||||
gemu_log("syscall %d\n", num);
|
||||
gemu_log("syscall %d", num);
|
||||
#endif
|
||||
switch(num) {
|
||||
case TARGET_NR_exit:
|
||||
@@ -1472,9 +1537,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
case TARGET_NR_chmod:
|
||||
ret = get_errno(chmod((const char *)arg1, arg2));
|
||||
break;
|
||||
case TARGET_NR_lchown:
|
||||
ret = get_errno(chown((const char *)arg1, arg2, arg3));
|
||||
break;
|
||||
#ifdef TARGET_NR_break
|
||||
case TARGET_NR_break:
|
||||
goto unimplemented;
|
||||
@@ -1495,12 +1557,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
case TARGET_NR_umount:
|
||||
ret = get_errno(umount((const char *)arg1));
|
||||
break;
|
||||
case TARGET_NR_setuid:
|
||||
ret = get_errno(setuid(low2highuid(arg1)));
|
||||
break;
|
||||
case TARGET_NR_getuid:
|
||||
ret = get_errno(getuid());
|
||||
break;
|
||||
case TARGET_NR_stime:
|
||||
{
|
||||
int *time_ptr = (int *)arg1;
|
||||
@@ -1596,20 +1652,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
case TARGET_NR_prof:
|
||||
goto unimplemented;
|
||||
#endif
|
||||
case TARGET_NR_setgid:
|
||||
ret = get_errno(setgid(low2highgid(arg1)));
|
||||
break;
|
||||
case TARGET_NR_getgid:
|
||||
ret = get_errno(getgid());
|
||||
break;
|
||||
case TARGET_NR_signal:
|
||||
goto unimplemented;
|
||||
case TARGET_NR_geteuid:
|
||||
ret = get_errno(geteuid());
|
||||
break;
|
||||
case TARGET_NR_getegid:
|
||||
ret = get_errno(getegid());
|
||||
break;
|
||||
|
||||
case TARGET_NR_acct:
|
||||
goto unimplemented;
|
||||
case TARGET_NR_umount2:
|
||||
@@ -1844,12 +1889,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
/* NOTE: ret is eax, so not transcoding must be done */
|
||||
ret = do_rt_sigreturn(cpu_env);
|
||||
break;
|
||||
case TARGET_NR_setreuid:
|
||||
ret = get_errno(setreuid(arg1, arg2));
|
||||
break;
|
||||
case TARGET_NR_setregid:
|
||||
ret = get_errno(setregid(arg1, arg2));
|
||||
break;
|
||||
case TARGET_NR_sethostname:
|
||||
ret = get_errno(sethostname((const char *)arg1, arg2));
|
||||
break;
|
||||
@@ -1906,34 +1945,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
ret = get_errno(settimeofday(&tv, NULL));
|
||||
}
|
||||
break;
|
||||
case TARGET_NR_getgroups:
|
||||
{
|
||||
int gidsetsize = arg1;
|
||||
uint16_t *target_grouplist = (void *)arg2;
|
||||
gid_t *grouplist;
|
||||
int i;
|
||||
|
||||
grouplist = alloca(gidsetsize * sizeof(gid_t));
|
||||
ret = get_errno(getgroups(gidsetsize, grouplist));
|
||||
if (!is_error(ret)) {
|
||||
for(i = 0;i < gidsetsize; i++)
|
||||
target_grouplist[i] = tswap16(grouplist[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TARGET_NR_setgroups:
|
||||
{
|
||||
int gidsetsize = arg1;
|
||||
uint16_t *target_grouplist = (void *)arg2;
|
||||
gid_t *grouplist;
|
||||
int i;
|
||||
|
||||
grouplist = alloca(gidsetsize * sizeof(gid_t));
|
||||
for(i = 0;i < gidsetsize; i++)
|
||||
grouplist[i] = tswap16(target_grouplist[i]);
|
||||
ret = get_errno(setgroups(gidsetsize, grouplist));
|
||||
}
|
||||
break;
|
||||
case TARGET_NR_select:
|
||||
{
|
||||
struct target_sel_arg_struct *sel = (void *)arg1;
|
||||
@@ -1988,10 +1999,15 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
#endif
|
||||
break;
|
||||
case TARGET_NR_mmap2:
|
||||
#if defined(TARGET_SPARC)
|
||||
#define MMAP_SHIFT 12
|
||||
#else
|
||||
#define MMAP_SHIFT TARGET_PAGE_BITS
|
||||
#endif
|
||||
ret = get_errno(target_mmap(arg1, arg2, arg3,
|
||||
target_to_host_bitmask(arg4, mmap_flags_tbl),
|
||||
arg5,
|
||||
arg6 << TARGET_PAGE_BITS));
|
||||
arg6 << MMAP_SHIFT));
|
||||
break;
|
||||
case TARGET_NR_munmap:
|
||||
ret = get_errno(target_munmap(arg1, arg2));
|
||||
@@ -2026,9 +2042,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
case TARGET_NR_fchmod:
|
||||
ret = get_errno(fchmod(arg1, arg2));
|
||||
break;
|
||||
case TARGET_NR_fchown:
|
||||
ret = get_errno(fchown(arg1, arg2, arg3));
|
||||
break;
|
||||
case TARGET_NR_getpriority:
|
||||
ret = get_errno(getpriority(arg1, arg2));
|
||||
break;
|
||||
@@ -2121,10 +2134,16 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
struct target_stat *target_st = (void *)arg2;
|
||||
target_st->st_dev = tswap16(st.st_dev);
|
||||
target_st->st_ino = tswapl(st.st_ino);
|
||||
#if defined(TARGET_PPC)
|
||||
target_st->st_mode = tswapl(st.st_mode); /* XXX: check this */
|
||||
target_st->st_uid = tswap32(st.st_uid);
|
||||
target_st->st_gid = tswap32(st.st_gid);
|
||||
#else
|
||||
target_st->st_mode = tswap16(st.st_mode);
|
||||
target_st->st_nlink = tswap16(st.st_nlink);
|
||||
target_st->st_uid = tswap16(st.st_uid);
|
||||
target_st->st_gid = tswap16(st.st_gid);
|
||||
#endif
|
||||
target_st->st_nlink = tswap16(st.st_nlink);
|
||||
target_st->st_rdev = tswap16(st.st_rdev);
|
||||
target_st->st_size = tswapl(st.st_size);
|
||||
target_st->st_blksize = tswapl(st.st_blksize);
|
||||
@@ -2230,12 +2249,6 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
break;
|
||||
case TARGET_NR_afs_syscall:
|
||||
goto unimplemented;
|
||||
case TARGET_NR_setfsuid:
|
||||
ret = get_errno(setfsuid(arg1));
|
||||
break;
|
||||
case TARGET_NR_setfsgid:
|
||||
ret = get_errno(setfsgid(arg1));
|
||||
break;
|
||||
case TARGET_NR__llseek:
|
||||
{
|
||||
int64_t res;
|
||||
@@ -2465,52 +2478,13 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
}
|
||||
}
|
||||
break;
|
||||
#ifdef TARGET_NR_setresuid
|
||||
case TARGET_NR_setresuid:
|
||||
ret = get_errno(setresuid(low2highuid(arg1),
|
||||
low2highuid(arg2),
|
||||
low2highuid(arg3)));
|
||||
break;
|
||||
#endif
|
||||
#ifdef TARGET_NR_getresuid
|
||||
case TARGET_NR_getresuid:
|
||||
{
|
||||
int ruid, euid, suid;
|
||||
ret = get_errno(getresuid(&ruid, &euid, &suid));
|
||||
if (!is_error(ret)) {
|
||||
*(uint16_t *)arg1 = tswap16(high2lowuid(ruid));
|
||||
*(uint16_t *)arg2 = tswap16(high2lowuid(euid));
|
||||
*(uint16_t *)arg3 = tswap16(high2lowuid(suid));
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef TARGET_NR_getresgid
|
||||
case TARGET_NR_setresgid:
|
||||
ret = get_errno(setresgid(low2highgid(arg1),
|
||||
low2highgid(arg2),
|
||||
low2highgid(arg3)));
|
||||
break;
|
||||
#endif
|
||||
#ifdef TARGET_NR_getresgid
|
||||
case TARGET_NR_getresgid:
|
||||
{
|
||||
int rgid, egid, sgid;
|
||||
ret = get_errno(getresgid(&rgid, &egid, &sgid));
|
||||
if (!is_error(ret)) {
|
||||
*(uint16_t *)arg1 = high2lowgid(tswap16(rgid));
|
||||
*(uint16_t *)arg2 = high2lowgid(tswap16(egid));
|
||||
*(uint16_t *)arg3 = high2lowgid(tswap16(sgid));
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case TARGET_NR_query_module:
|
||||
goto unimplemented;
|
||||
case TARGET_NR_nfsservctl:
|
||||
goto unimplemented;
|
||||
case TARGET_NR_prctl:
|
||||
goto unimplemented;
|
||||
#ifdef TARGET_NR_pread
|
||||
case TARGET_NR_pread:
|
||||
page_unprotect_range((void *)arg2, arg3);
|
||||
ret = get_errno(pread(arg1, (void *)arg2, arg3, arg4));
|
||||
@@ -2518,9 +2492,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
case TARGET_NR_pwrite:
|
||||
ret = get_errno(pwrite(arg1, (void *)arg2, arg3, arg4));
|
||||
break;
|
||||
case TARGET_NR_chown:
|
||||
ret = get_errno(chown((const char *)arg1, arg2, arg3));
|
||||
break;
|
||||
#endif
|
||||
case TARGET_NR_getcwd:
|
||||
ret = get_errno(sys_getcwd1((char *)arg1, arg2));
|
||||
break;
|
||||
@@ -2573,27 +2545,137 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
if (!is_error(ret)) {
|
||||
struct target_stat64 *target_st = (void *)arg2;
|
||||
memset(target_st, 0, sizeof(struct target_stat64));
|
||||
target_st->st_dev = tswap16(st.st_dev);
|
||||
target_st->st_ino = tswap64(st.st_ino);
|
||||
put_user(st.st_dev, &target_st->st_dev);
|
||||
put_user(st.st_ino, &target_st->st_ino);
|
||||
#ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
|
||||
target_st->__st_ino = tswapl(st.st_ino);
|
||||
put_user(st.st_ino, &target_st->__st_ino);
|
||||
#endif
|
||||
target_st->st_mode = tswap32(st.st_mode);
|
||||
target_st->st_nlink = tswap32(st.st_nlink);
|
||||
target_st->st_uid = tswapl(st.st_uid);
|
||||
target_st->st_gid = tswapl(st.st_gid);
|
||||
target_st->st_rdev = tswap16(st.st_rdev);
|
||||
put_user(st.st_mode, &target_st->st_mode);
|
||||
put_user(st.st_nlink, &target_st->st_nlink);
|
||||
put_user(st.st_uid, &target_st->st_uid);
|
||||
put_user(st.st_gid, &target_st->st_gid);
|
||||
put_user(st.st_rdev, &target_st->st_rdev);
|
||||
/* XXX: better use of kernel struct */
|
||||
target_st->st_size = tswap64(st.st_size);
|
||||
target_st->st_blksize = tswapl(st.st_blksize);
|
||||
target_st->st_blocks = tswapl(st.st_blocks);
|
||||
target_st->target_st_atime = tswapl(st.st_atime);
|
||||
target_st->target_st_mtime = tswapl(st.st_mtime);
|
||||
target_st->target_st_ctime = tswapl(st.st_ctime);
|
||||
put_user(st.st_size, &target_st->st_size);
|
||||
put_user(st.st_blksize, &target_st->st_blksize);
|
||||
put_user(st.st_blocks, &target_st->st_blocks);
|
||||
put_user(st.st_atime, &target_st->target_st_atime);
|
||||
put_user(st.st_mtime, &target_st->target_st_mtime);
|
||||
put_user(st.st_ctime, &target_st->target_st_ctime);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef USE_UID16
|
||||
case TARGET_NR_lchown:
|
||||
ret = get_errno(lchown((const char *)arg1, low2highuid(arg2), low2highgid(arg3)));
|
||||
break;
|
||||
case TARGET_NR_getuid:
|
||||
ret = get_errno(high2lowuid(getuid()));
|
||||
break;
|
||||
case TARGET_NR_getgid:
|
||||
ret = get_errno(high2lowgid(getgid()));
|
||||
break;
|
||||
case TARGET_NR_geteuid:
|
||||
ret = get_errno(high2lowuid(geteuid()));
|
||||
break;
|
||||
case TARGET_NR_getegid:
|
||||
ret = get_errno(high2lowgid(getegid()));
|
||||
break;
|
||||
case TARGET_NR_setreuid:
|
||||
ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2)));
|
||||
break;
|
||||
case TARGET_NR_setregid:
|
||||
ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2)));
|
||||
break;
|
||||
case TARGET_NR_getgroups:
|
||||
{
|
||||
int gidsetsize = arg1;
|
||||
uint16_t *target_grouplist = (void *)arg2;
|
||||
gid_t *grouplist;
|
||||
int i;
|
||||
|
||||
grouplist = alloca(gidsetsize * sizeof(gid_t));
|
||||
ret = get_errno(getgroups(gidsetsize, grouplist));
|
||||
if (!is_error(ret)) {
|
||||
for(i = 0;i < gidsetsize; i++)
|
||||
target_grouplist[i] = tswap16(grouplist[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TARGET_NR_setgroups:
|
||||
{
|
||||
int gidsetsize = arg1;
|
||||
uint16_t *target_grouplist = (void *)arg2;
|
||||
gid_t *grouplist;
|
||||
int i;
|
||||
|
||||
grouplist = alloca(gidsetsize * sizeof(gid_t));
|
||||
for(i = 0;i < gidsetsize; i++)
|
||||
grouplist[i] = tswap16(target_grouplist[i]);
|
||||
ret = get_errno(setgroups(gidsetsize, grouplist));
|
||||
}
|
||||
break;
|
||||
case TARGET_NR_fchown:
|
||||
ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
|
||||
break;
|
||||
#ifdef TARGET_NR_setresuid
|
||||
case TARGET_NR_setresuid:
|
||||
ret = get_errno(setresuid(low2highuid(arg1),
|
||||
low2highuid(arg2),
|
||||
low2highuid(arg3)));
|
||||
break;
|
||||
#endif
|
||||
#ifdef TARGET_NR_getresuid
|
||||
case TARGET_NR_getresuid:
|
||||
{
|
||||
int ruid, euid, suid;
|
||||
ret = get_errno(getresuid(&ruid, &euid, &suid));
|
||||
if (!is_error(ret)) {
|
||||
*(uint16_t *)arg1 = tswap16(high2lowuid(ruid));
|
||||
*(uint16_t *)arg2 = tswap16(high2lowuid(euid));
|
||||
*(uint16_t *)arg3 = tswap16(high2lowuid(suid));
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef TARGET_NR_getresgid
|
||||
case TARGET_NR_setresgid:
|
||||
ret = get_errno(setresgid(low2highgid(arg1),
|
||||
low2highgid(arg2),
|
||||
low2highgid(arg3)));
|
||||
break;
|
||||
#endif
|
||||
#ifdef TARGET_NR_getresgid
|
||||
case TARGET_NR_getresgid:
|
||||
{
|
||||
int rgid, egid, sgid;
|
||||
ret = get_errno(getresgid(&rgid, &egid, &sgid));
|
||||
if (!is_error(ret)) {
|
||||
*(uint16_t *)arg1 = tswap16(high2lowgid(rgid));
|
||||
*(uint16_t *)arg2 = tswap16(high2lowgid(egid));
|
||||
*(uint16_t *)arg3 = tswap16(high2lowgid(sgid));
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case TARGET_NR_chown:
|
||||
ret = get_errno(chown((const char *)arg1, low2highuid(arg2), low2highgid(arg3)));
|
||||
break;
|
||||
case TARGET_NR_setuid:
|
||||
ret = get_errno(setuid(low2highuid(arg1)));
|
||||
break;
|
||||
case TARGET_NR_setgid:
|
||||
ret = get_errno(setgid(low2highgid(arg1)));
|
||||
break;
|
||||
case TARGET_NR_setfsuid:
|
||||
ret = get_errno(setfsuid(arg1));
|
||||
break;
|
||||
case TARGET_NR_setfsgid:
|
||||
ret = get_errno(setfsgid(arg1));
|
||||
break;
|
||||
#endif /* USE_UID16 */
|
||||
|
||||
case TARGET_NR_lchown32:
|
||||
ret = get_errno(lchown((const char *)arg1, arg2, arg3));
|
||||
break;
|
||||
@@ -2665,6 +2747,7 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
case TARGET_NR_setfsgid32:
|
||||
ret = get_errno(setfsgid(arg1));
|
||||
break;
|
||||
|
||||
case TARGET_NR_pivot_root:
|
||||
goto unimplemented;
|
||||
case TARGET_NR_mincore:
|
||||
@@ -2708,6 +2791,11 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
#ifdef TARGET_NR_security
|
||||
case TARGET_NR_security:
|
||||
goto unimplemented;
|
||||
#endif
|
||||
#ifdef TARGET_NR_getpagesize
|
||||
case TARGET_NR_getpagesize:
|
||||
ret = TARGET_PAGE_SIZE;
|
||||
break;
|
||||
#endif
|
||||
case TARGET_NR_gettid:
|
||||
ret = get_errno(gettid());
|
||||
@@ -2742,6 +2830,9 @@ long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3,
|
||||
break;
|
||||
}
|
||||
fail:
|
||||
#ifdef DEBUG
|
||||
gemu_log(" = %ld\n", ret);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -279,7 +279,7 @@ struct target_sigaction;
|
||||
int do_sigaction(int sig, const struct target_sigaction *act,
|
||||
struct target_sigaction *oact);
|
||||
|
||||
#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC)
|
||||
#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_PPC)
|
||||
|
||||
#define TARGET_SA_NOCLDSTOP 0x00000001
|
||||
#define TARGET_SA_NOCLDWAIT 0x00000002 /* not supported yet */
|
||||
@@ -664,220 +664,26 @@ struct target_pollfd {
|
||||
#define TARGET_HDIO_SET_PIO_MODE 0x0327 /* reconfig interface to new speed */
|
||||
|
||||
|
||||
#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC)
|
||||
|
||||
/* 0x54 is just a magic number to make these relatively unique ('T') */
|
||||
|
||||
#define TARGET_TCGETS 0x5401
|
||||
#define TARGET_TCSETS 0x5402
|
||||
#define TARGET_TCSETSW 0x5403
|
||||
#define TARGET_TCSETSF 0x5404
|
||||
#define TARGET_TCGETA 0x5405
|
||||
#define TARGET_TCSETA 0x5406
|
||||
#define TARGET_TCSETAW 0x5407
|
||||
#define TARGET_TCSETAF 0x5408
|
||||
#define TARGET_TCSBRK 0x5409
|
||||
#define TARGET_TCXONC 0x540A
|
||||
#define TARGET_TCFLSH 0x540B
|
||||
#define TARGET_TIOCEXCL 0x540C
|
||||
#define TARGET_TIOCNXCL 0x540D
|
||||
#define TARGET_TIOCSCTTY 0x540E
|
||||
#define TARGET_TIOCGPGRP 0x540F
|
||||
#define TARGET_TIOCSPGRP 0x5410
|
||||
#define TARGET_TIOCOUTQ 0x5411
|
||||
#define TARGET_TIOCSTI 0x5412
|
||||
#define TARGET_TIOCGWINSZ 0x5413
|
||||
#define TARGET_TIOCSWINSZ 0x5414
|
||||
#define TARGET_TIOCMGET 0x5415
|
||||
#define TARGET_TIOCMBIS 0x5416
|
||||
#define TARGET_TIOCMBIC 0x5417
|
||||
#define TARGET_TIOCMSET 0x5418
|
||||
#define TARGET_TIOCGSOFTCAR 0x5419
|
||||
#define TARGET_TIOCSSOFTCAR 0x541A
|
||||
#define TARGET_FIONREAD 0x541B
|
||||
#define TARGET_TIOCINQ FIONREAD
|
||||
#define TARGET_TIOCLINUX 0x541C
|
||||
#define TARGET_TIOCCONS 0x541D
|
||||
#define TARGET_TIOCGSERIAL 0x541E
|
||||
#define TARGET_TIOCSSERIAL 0x541F
|
||||
#define TARGET_TIOCPKT 0x5420
|
||||
#define TARGET_FIONBIO 0x5421
|
||||
#define TARGET_TIOCNOTTY 0x5422
|
||||
#define TARGET_TIOCSETD 0x5423
|
||||
#define TARGET_TIOCGETD 0x5424
|
||||
#define TARGET_TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */
|
||||
#define TARGET_TIOCTTYGSTRUCT 0x5426 /* For debugging only */
|
||||
#define TARGET_TIOCSBRK 0x5427 /* BSD compatibility */
|
||||
#define TARGET_TIOCCBRK 0x5428 /* BSD compatibility */
|
||||
#define TARGET_TIOCGSID 0x5429 /* Return the session ID of FD */
|
||||
#define TARGET_TIOCGPTN TARGET_IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
|
||||
#define TARGET_TIOCSPTLCK TARGET_IOW('T',0x31, int) /* Lock/unlock Pty */
|
||||
|
||||
#define TARGET_FIONCLEX 0x5450 /* these numbers need to be adjusted. */
|
||||
#define TARGET_FIOCLEX 0x5451
|
||||
#define TARGET_FIOASYNC 0x5452
|
||||
#define TARGET_TIOCSERCONFIG 0x5453
|
||||
#define TARGET_TIOCSERGWILD 0x5454
|
||||
#define TARGET_TIOCSERSWILD 0x5455
|
||||
#define TARGET_TIOCGLCKTRMIOS 0x5456
|
||||
#define TARGET_TIOCSLCKTRMIOS 0x5457
|
||||
#define TARGET_TIOCSERGSTRUCT 0x5458 /* For debugging only */
|
||||
#define TARGET_TIOCSERGETLSR 0x5459 /* Get line status register */
|
||||
#define TARGET_TIOCSERGETMULTI 0x545A /* Get multiport config */
|
||||
#define TARGET_TIOCSERSETMULTI 0x545B /* Set multiport config */
|
||||
|
||||
#define TARGET_TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */
|
||||
#define TARGET_TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */
|
||||
#define TARGET_TIOCGHAYESESP 0x545E /* Get Hayes ESP configuration */
|
||||
#define TARGET_TIOCSHAYESESP 0x545F /* Set Hayes ESP configuration */
|
||||
|
||||
/* Used for packet mode */
|
||||
#define TARGET_TIOCPKT_DATA 0
|
||||
#define TARGET_TIOCPKT_FLUSHREAD 1
|
||||
#define TARGET_TIOCPKT_FLUSHWRITE 2
|
||||
#define TARGET_TIOCPKT_STOP 4
|
||||
#define TARGET_TIOCPKT_START 8
|
||||
#define TARGET_TIOCPKT_NOSTOP 16
|
||||
#define TARGET_TIOCPKT_DOSTOP 32
|
||||
|
||||
#define TARGET_TIOCSER_TEMT 0x01 /* Transmitter physically empty */
|
||||
|
||||
/* from asm/termbits.h */
|
||||
|
||||
#define TARGET_NCCS 19
|
||||
|
||||
struct target_termios {
|
||||
unsigned int c_iflag; /* input mode flags */
|
||||
unsigned int c_oflag; /* output mode flags */
|
||||
unsigned int c_cflag; /* control mode flags */
|
||||
unsigned int c_lflag; /* local mode flags */
|
||||
unsigned char c_line; /* line discipline */
|
||||
unsigned char c_cc[TARGET_NCCS]; /* control characters */
|
||||
#define TARGET_NCC 8
|
||||
struct target_termio {
|
||||
unsigned short c_iflag; /* input mode flags */
|
||||
unsigned short c_oflag; /* output mode flags */
|
||||
unsigned short c_cflag; /* control mode flags */
|
||||
unsigned short c_lflag; /* local mode flags */
|
||||
unsigned char c_line; /* line discipline */
|
||||
unsigned char c_cc[TARGET_NCC]; /* control characters */
|
||||
};
|
||||
|
||||
/* c_iflag bits */
|
||||
#define TARGET_IGNBRK 0000001
|
||||
#define TARGET_BRKINT 0000002
|
||||
#define TARGET_IGNPAR 0000004
|
||||
#define TARGET_PARMRK 0000010
|
||||
#define TARGET_INPCK 0000020
|
||||
#define TARGET_ISTRIP 0000040
|
||||
#define TARGET_INLCR 0000100
|
||||
#define TARGET_IGNCR 0000200
|
||||
#define TARGET_ICRNL 0000400
|
||||
#define TARGET_IUCLC 0001000
|
||||
#define TARGET_IXON 0002000
|
||||
#define TARGET_IXANY 0004000
|
||||
#define TARGET_IXOFF 0010000
|
||||
#define TARGET_IMAXBEL 0020000
|
||||
struct target_winsize {
|
||||
unsigned short ws_row;
|
||||
unsigned short ws_col;
|
||||
unsigned short ws_xpixel;
|
||||
unsigned short ws_ypixel;
|
||||
};
|
||||
|
||||
/* c_oflag bits */
|
||||
#define TARGET_OPOST 0000001
|
||||
#define TARGET_OLCUC 0000002
|
||||
#define TARGET_ONLCR 0000004
|
||||
#define TARGET_OCRNL 0000010
|
||||
#define TARGET_ONOCR 0000020
|
||||
#define TARGET_ONLRET 0000040
|
||||
#define TARGET_OFILL 0000100
|
||||
#define TARGET_OFDEL 0000200
|
||||
#define TARGET_NLDLY 0000400
|
||||
#define TARGET_NL0 0000000
|
||||
#define TARGET_NL1 0000400
|
||||
#define TARGET_CRDLY 0003000
|
||||
#define TARGET_CR0 0000000
|
||||
#define TARGET_CR1 0001000
|
||||
#define TARGET_CR2 0002000
|
||||
#define TARGET_CR3 0003000
|
||||
#define TARGET_TABDLY 0014000
|
||||
#define TARGET_TAB0 0000000
|
||||
#define TARGET_TAB1 0004000
|
||||
#define TARGET_TAB2 0010000
|
||||
#define TARGET_TAB3 0014000
|
||||
#define TARGET_XTABS 0014000
|
||||
#define TARGET_BSDLY 0020000
|
||||
#define TARGET_BS0 0000000
|
||||
#define TARGET_BS1 0020000
|
||||
#define TARGET_VTDLY 0040000
|
||||
#define TARGET_VT0 0000000
|
||||
#define TARGET_VT1 0040000
|
||||
#define TARGET_FFDLY 0100000
|
||||
#define TARGET_FF0 0000000
|
||||
#define TARGET_FF1 0100000
|
||||
|
||||
/* c_cflag bit meaning */
|
||||
#define TARGET_CBAUD 0010017
|
||||
#define TARGET_B0 0000000 /* hang up */
|
||||
#define TARGET_B50 0000001
|
||||
#define TARGET_B75 0000002
|
||||
#define TARGET_B110 0000003
|
||||
#define TARGET_B134 0000004
|
||||
#define TARGET_B150 0000005
|
||||
#define TARGET_B200 0000006
|
||||
#define TARGET_B300 0000007
|
||||
#define TARGET_B600 0000010
|
||||
#define TARGET_B1200 0000011
|
||||
#define TARGET_B1800 0000012
|
||||
#define TARGET_B2400 0000013
|
||||
#define TARGET_B4800 0000014
|
||||
#define TARGET_B9600 0000015
|
||||
#define TARGET_B19200 0000016
|
||||
#define TARGET_B38400 0000017
|
||||
#define TARGET_EXTA B19200
|
||||
#define TARGET_EXTB B38400
|
||||
#define TARGET_CSIZE 0000060
|
||||
#define TARGET_CS5 0000000
|
||||
#define TARGET_CS6 0000020
|
||||
#define TARGET_CS7 0000040
|
||||
#define TARGET_CS8 0000060
|
||||
#define TARGET_CSTOPB 0000100
|
||||
#define TARGET_CREAD 0000200
|
||||
#define TARGET_PARENB 0000400
|
||||
#define TARGET_PARODD 0001000
|
||||
#define TARGET_HUPCL 0002000
|
||||
#define TARGET_CLOCAL 0004000
|
||||
#define TARGET_CBAUDEX 0010000
|
||||
#define TARGET_B57600 0010001
|
||||
#define TARGET_B115200 0010002
|
||||
#define TARGET_B230400 0010003
|
||||
#define TARGET_B460800 0010004
|
||||
#define TARGET_CIBAUD 002003600000 /* input baud rate (not used) */
|
||||
#define TARGET_CRTSCTS 020000000000 /* flow control */
|
||||
|
||||
/* c_lflag bits */
|
||||
#define TARGET_ISIG 0000001
|
||||
#define TARGET_ICANON 0000002
|
||||
#define TARGET_XCASE 0000004
|
||||
#define TARGET_ECHO 0000010
|
||||
#define TARGET_ECHOE 0000020
|
||||
#define TARGET_ECHOK 0000040
|
||||
#define TARGET_ECHONL 0000100
|
||||
#define TARGET_NOFLSH 0000200
|
||||
#define TARGET_TOSTOP 0000400
|
||||
#define TARGET_ECHOCTL 0001000
|
||||
#define TARGET_ECHOPRT 0002000
|
||||
#define TARGET_ECHOKE 0004000
|
||||
#define TARGET_FLUSHO 0010000
|
||||
#define TARGET_PENDIN 0040000
|
||||
#define TARGET_IEXTEN 0100000
|
||||
|
||||
/* c_cc character offsets */
|
||||
#define TARGET_VINTR 0
|
||||
#define TARGET_VQUIT 1
|
||||
#define TARGET_VERASE 2
|
||||
#define TARGET_VKILL 3
|
||||
#define TARGET_VEOF 4
|
||||
#define TARGET_VTIME 5
|
||||
#define TARGET_VMIN 6
|
||||
#define TARGET_VSWTC 7
|
||||
#define TARGET_VSTART 8
|
||||
#define TARGET_VSTOP 9
|
||||
#define TARGET_VSUSP 10
|
||||
#define TARGET_VEOL 11
|
||||
#define TARGET_VREPRINT 12
|
||||
#define TARGET_VDISCARD 13
|
||||
#define TARGET_VWERASE 14
|
||||
#define TARGET_VLNEXT 15
|
||||
#define TARGET_VEOL2 16
|
||||
#include "termbits.h"
|
||||
|
||||
#define TARGET_MAP_SHARED 0x01 /* Share changes */
|
||||
#define TARGET_MAP_PRIVATE 0x02 /* Changes are private */
|
||||
@@ -891,6 +697,7 @@ struct target_termios {
|
||||
#define TARGET_MAP_LOCKED 0x2000 /* pages are locked */
|
||||
#define TARGET_MAP_NORESERVE 0x4000 /* don't check for reservations */
|
||||
|
||||
#if defined(TARGET_I386) || defined(TARGET_ARM)
|
||||
struct target_stat {
|
||||
unsigned short st_dev;
|
||||
unsigned short __pad1;
|
||||
@@ -951,7 +758,111 @@ struct target_stat64 {
|
||||
unsigned long long st_ino;
|
||||
} __attribute__((packed));
|
||||
|
||||
#endif /* defined(TARGET_I386) || defined(TARGET_ARM) */
|
||||
#elif defined(TARGET_SPARC)
|
||||
|
||||
struct target_stat {
|
||||
unsigned short st_dev;
|
||||
target_ulong st_ino;
|
||||
unsigned short st_mode;
|
||||
short st_nlink;
|
||||
unsigned short st_uid;
|
||||
unsigned short st_gid;
|
||||
unsigned short st_rdev;
|
||||
target_long st_size;
|
||||
target_long target_st_atime;
|
||||
target_ulong __unused1;
|
||||
target_long target_st_mtime;
|
||||
target_ulong __unused2;
|
||||
target_long target_st_ctime;
|
||||
target_ulong __unused3;
|
||||
target_long st_blksize;
|
||||
target_long st_blocks;
|
||||
target_ulong __unused4[2];
|
||||
};
|
||||
|
||||
struct target_stat64 {
|
||||
unsigned char __pad0[6];
|
||||
unsigned short st_dev;
|
||||
|
||||
uint64_t st_ino;
|
||||
|
||||
unsigned int st_mode;
|
||||
unsigned int st_nlink;
|
||||
|
||||
unsigned int st_uid;
|
||||
unsigned int st_gid;
|
||||
|
||||
unsigned char __pad2[6];
|
||||
unsigned short st_rdev;
|
||||
|
||||
unsigned char __pad3[8];
|
||||
|
||||
int64_t st_size;
|
||||
unsigned int st_blksize;
|
||||
|
||||
unsigned char __pad4[8];
|
||||
unsigned int st_blocks;
|
||||
|
||||
unsigned int target_st_atime;
|
||||
unsigned int __unused1;
|
||||
|
||||
unsigned int target_st_mtime;
|
||||
unsigned int __unused2;
|
||||
|
||||
unsigned int target_st_ctime;
|
||||
unsigned int __unused3;
|
||||
|
||||
unsigned int __unused4;
|
||||
unsigned int __unused5;
|
||||
};
|
||||
|
||||
#elif defined(TARGET_PPC)
|
||||
|
||||
struct target_stat {
|
||||
unsigned short st_dev;
|
||||
target_ulong st_ino;
|
||||
unsigned int st_mode;
|
||||
unsigned short st_nlink;
|
||||
unsigned int st_uid;
|
||||
unsigned int st_gid;
|
||||
unsigned short st_rdev;
|
||||
target_ulong st_size;
|
||||
target_ulong st_blksize;
|
||||
target_ulong st_blocks;
|
||||
target_ulong target_st_atime;
|
||||
target_ulong __unused1;
|
||||
target_ulong target_st_mtime;
|
||||
target_ulong __unused2;
|
||||
target_ulong target_st_ctime;
|
||||
target_ulong __unused3;
|
||||
target_ulong __unused4;
|
||||
target_ulong __unused5;
|
||||
};
|
||||
|
||||
struct target_stat64 {
|
||||
unsigned long long st_dev;
|
||||
unsigned long long st_ino;
|
||||
unsigned int st_mode;
|
||||
unsigned int st_nlink;
|
||||
unsigned int st_uid;
|
||||
unsigned int st_gid;
|
||||
unsigned long long st_rdev;
|
||||
long long pad0;
|
||||
long long st_size;
|
||||
target_ulong st_blksize;
|
||||
target_ulong pad1;
|
||||
long long st_blocks; /* Number 512-byte blocks allocated. */
|
||||
target_ulong target_st_atime;
|
||||
target_ulong target_st_atime_nsec;
|
||||
target_ulong target_st_mtime;
|
||||
target_ulong target_st_mtime_nsec;
|
||||
target_ulong target_st_ctime;
|
||||
target_ulong target_st_ctime_nsec;
|
||||
target_ulong __unused4;
|
||||
target_ulong __unused5;
|
||||
};
|
||||
|
||||
#endif /* defined(TARGET_PPC) */
|
||||
|
||||
#define TARGET_F_DUPFD 0 /* dup */
|
||||
#define TARGET_F_GETFD 1 /* get close_on_exec */
|
||||
|
512
oss.c
Normal file
512
oss.c
Normal file
@@ -0,0 +1,512 @@
|
||||
/*
|
||||
* QEMU OSS Audio output driver
|
||||
*
|
||||
* Copyright (c) 2003 Vassili Karpov (malc)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/soundcard.h>
|
||||
|
||||
#include "vl.h"
|
||||
|
||||
/* http://www.df.lth.se/~john_e/gems/gem002d.html */
|
||||
/* http://www.multi-platforms.com/Tips/PopCount.htm */
|
||||
static inline uint32_t popcount (uint32_t u)
|
||||
{
|
||||
u = ((u&0x55555555) + ((u>>1)&0x55555555));
|
||||
u = ((u&0x33333333) + ((u>>2)&0x33333333));
|
||||
u = ((u&0x0f0f0f0f) + ((u>>4)&0x0f0f0f0f));
|
||||
u = ((u&0x00ff00ff) + ((u>>8)&0x00ff00ff));
|
||||
u = ( u&0x0000ffff) + (u>>16);
|
||||
return u;
|
||||
}
|
||||
|
||||
static inline uint32_t lsbindex (uint32_t u)
|
||||
{
|
||||
return popcount ((u&-u)-1);
|
||||
}
|
||||
|
||||
#define MIN(a, b) ((a)>(b)?(b):(a))
|
||||
#define MAX(a, b) ((a)<(b)?(b):(a))
|
||||
|
||||
#define DEREF(x) (void)x
|
||||
#define log(...) fprintf (stderr, "oss: " __VA_ARGS__)
|
||||
#define ERRFail(...) do { \
|
||||
int _errno = errno; \
|
||||
fprintf (stderr, "oss: " __VA_ARGS__); \
|
||||
fprintf (stderr, "system error: %s\n", strerror (_errno)); \
|
||||
abort (); \
|
||||
} while (0)
|
||||
#define Fail(...) do { \
|
||||
fprintf (stderr, "oss: " __VA_ARGS__); \
|
||||
fprintf (stderr, "\n"); \
|
||||
abort (); \
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG_OSS
|
||||
#define lwarn(...) fprintf (stderr, "oss: " __VA_ARGS__)
|
||||
#define linfo(...) fprintf (stderr, "oss: " __VA_ARGS__)
|
||||
#define ldebug(...) fprintf (stderr, "oss: " __VA_ARGS__)
|
||||
#else
|
||||
#define lwarn(...)
|
||||
#define linfo(...)
|
||||
#define ldebug(...)
|
||||
#endif
|
||||
|
||||
|
||||
#define IOCTL(args) do { \
|
||||
int ret = ioctl args; \
|
||||
if (-1 == ret) { \
|
||||
ERRFail (#args); \
|
||||
} \
|
||||
ldebug ("ioctl " #args " = %d\n", ret); \
|
||||
} while (0)
|
||||
|
||||
static int audio_fd = -1;
|
||||
static int freq;
|
||||
static int conf_nfrags = 4;
|
||||
static int conf_fragsize;
|
||||
static int nfrags;
|
||||
static int fragsize;
|
||||
static int bufsize;
|
||||
static int nchannels;
|
||||
static int fmt;
|
||||
static int rpos;
|
||||
static int wpos;
|
||||
static int atom;
|
||||
static int live;
|
||||
static int leftover;
|
||||
static int bytes_per_second;
|
||||
static void *buf;
|
||||
static enum {DONT, DSP, TID} estimate = TID;
|
||||
|
||||
static void (*copy_fn)(void *, void *, int);
|
||||
|
||||
static void copy_no_conversion (void *dst, void *src, int size)
|
||||
{
|
||||
memcpy (dst, src, size);
|
||||
}
|
||||
|
||||
static void copy_u16_to_s16 (void *dst, void *src, int size)
|
||||
{
|
||||
int i;
|
||||
uint16_t *out, *in;
|
||||
|
||||
out = dst;
|
||||
in = src;
|
||||
|
||||
for (i = 0; i < size / 2; i++) {
|
||||
out[i] = in[i] + 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
static void pab (struct audio_buf_info *abinfo)
|
||||
{
|
||||
DEREF (abinfo);
|
||||
|
||||
ldebug ("fragments %d, fragstotal %d, fragsize %d, bytes %d\n"
|
||||
"rpos %d, wpos %d, live %d\n",
|
||||
abinfo->fragments,
|
||||
abinfo->fragstotal,
|
||||
abinfo->fragsize,
|
||||
abinfo->bytes,
|
||||
rpos, wpos, live);
|
||||
}
|
||||
|
||||
void AUD_reset (int rfreq, int rnchannels, audfmt_e rfmt)
|
||||
{
|
||||
int fmt_;
|
||||
int bits16;
|
||||
|
||||
if (-1 == audio_fd) {
|
||||
AUD_open (rfreq, rnchannels, rfmt);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rfmt) {
|
||||
case AUD_FMT_U8:
|
||||
bits16 = 0;
|
||||
fmt_ = AFMT_U8;
|
||||
copy_fn = copy_no_conversion;
|
||||
atom = 1;
|
||||
break;
|
||||
|
||||
case AUD_FMT_S8:
|
||||
Fail ("can not play 8bit signed");
|
||||
|
||||
case AUD_FMT_S16:
|
||||
bits16 = 1;
|
||||
fmt_ = AFMT_S16_LE;
|
||||
copy_fn = copy_no_conversion;
|
||||
atom = 2;
|
||||
break;
|
||||
|
||||
case AUD_FMT_U16:
|
||||
bits16 = 1;
|
||||
fmt_ = AFMT_S16_LE;
|
||||
copy_fn = copy_u16_to_s16;
|
||||
atom = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
if ((fmt_ == fmt) && (bits16 + 1 == nchannels) && (rfreq == freq))
|
||||
return;
|
||||
else {
|
||||
AUD_open (rfreq, rnchannels, rfmt);
|
||||
}
|
||||
}
|
||||
|
||||
void AUD_open (int rfreq, int rnchannels, audfmt_e rfmt)
|
||||
{
|
||||
int fmt_;
|
||||
int mmmmssss;
|
||||
struct audio_buf_info abinfo;
|
||||
int _fmt;
|
||||
int _freq;
|
||||
int _nchannels;
|
||||
int bits16;
|
||||
|
||||
bits16 = 0;
|
||||
|
||||
switch (rfmt) {
|
||||
case AUD_FMT_U8:
|
||||
bits16 = 0;
|
||||
fmt_ = AFMT_U8;
|
||||
copy_fn = copy_no_conversion;
|
||||
atom = 1;
|
||||
break;
|
||||
|
||||
case AUD_FMT_S8:
|
||||
Fail ("can not play 8bit signed");
|
||||
|
||||
case AUD_FMT_S16:
|
||||
bits16 = 1;
|
||||
fmt_ = AFMT_S16_LE;
|
||||
copy_fn = copy_no_conversion;
|
||||
atom = 2;
|
||||
break;
|
||||
|
||||
case AUD_FMT_U16:
|
||||
bits16 = 1;
|
||||
fmt_ = AFMT_S16_LE;
|
||||
copy_fn = copy_u16_to_s16;
|
||||
atom = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
free (buf);
|
||||
buf = 0;
|
||||
}
|
||||
|
||||
if (-1 != audio_fd)
|
||||
close (audio_fd);
|
||||
|
||||
audio_fd = open ("/dev/dsp", O_WRONLY | O_NONBLOCK);
|
||||
if (-1 == audio_fd) {
|
||||
ERRFail ("can not open /dev/dsp");
|
||||
}
|
||||
|
||||
_fmt = fmt_;
|
||||
_freq = rfreq;
|
||||
_nchannels = rnchannels;
|
||||
|
||||
IOCTL ((audio_fd, SNDCTL_DSP_RESET, 1));
|
||||
IOCTL ((audio_fd, SNDCTL_DSP_SAMPLESIZE, &_fmt));
|
||||
IOCTL ((audio_fd, SNDCTL_DSP_CHANNELS, &_nchannels));
|
||||
IOCTL ((audio_fd, SNDCTL_DSP_SPEED, &_freq));
|
||||
IOCTL ((audio_fd, SNDCTL_DSP_NONBLOCK));
|
||||
|
||||
/* from oss.pdf:
|
||||
|
||||
The argument to this call is an integer encoded as 0xMMMMSSSS (in
|
||||
hex). The 16 least significant bits determine the fragment
|
||||
size. The size is 2^SSSS. For examp le SSSS=0008 gives fragment
|
||||
size of 256 bytes (2^8). The minimum is 16 bytes (SSSS=4) and the
|
||||
maximum is total_buffer_size/2. Some devices or processor
|
||||
architectures may require larger fragments - in this case the
|
||||
requested fragment size is automatically increased.
|
||||
|
||||
So ahem... 4096 = 2^12, and grand total 0x0004000c
|
||||
*/
|
||||
|
||||
mmmmssss = (conf_nfrags << 16) | conf_fragsize;
|
||||
IOCTL ((audio_fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss));
|
||||
|
||||
linfo ("_fmt = %d, fmt = %d\n"
|
||||
"_channels = %d, rnchannels = %d\n"
|
||||
"_freq = %d, freq = %d\n",
|
||||
_fmt, fmt_,
|
||||
_nchannels, rnchannels,
|
||||
_freq, rfreq);
|
||||
|
||||
if (_fmt != fmt_) {
|
||||
Fail ("format %d != %d", _fmt, fmt_);
|
||||
}
|
||||
|
||||
if (_nchannels != rnchannels) {
|
||||
Fail ("channels %d != %d", _nchannels, rnchannels);
|
||||
}
|
||||
|
||||
if (_freq != rfreq) {
|
||||
Fail ("freq %d != %d", _freq, rfreq);
|
||||
}
|
||||
|
||||
IOCTL ((audio_fd, SNDCTL_DSP_GETOSPACE, &abinfo));
|
||||
|
||||
nfrags = abinfo.fragstotal;
|
||||
fragsize = abinfo.fragsize;
|
||||
freq = _freq;
|
||||
fmt = _fmt;
|
||||
nchannels = rnchannels;
|
||||
atom <<= nchannels >> 1;
|
||||
bufsize = nfrags * fragsize;
|
||||
|
||||
bytes_per_second = (freq << (nchannels >> 1)) << bits16;
|
||||
|
||||
linfo ("bytes per second %d\n", bytes_per_second);
|
||||
|
||||
linfo ("fragments %d, fragstotal %d, fragsize %d, bytes %d, bufsize %d\n",
|
||||
abinfo.fragments,
|
||||
abinfo.fragstotal,
|
||||
abinfo.fragsize,
|
||||
abinfo.bytes,
|
||||
bufsize);
|
||||
|
||||
if (NULL == buf) {
|
||||
buf = malloc (bufsize);
|
||||
if (NULL == buf) {
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
rpos = 0;
|
||||
wpos = 0;
|
||||
live = 0;
|
||||
}
|
||||
|
||||
int AUD_write (void *in_buf, int size)
|
||||
{
|
||||
int to_copy, temp;
|
||||
uint8_t *in, *out;
|
||||
|
||||
to_copy = MIN (bufsize - live, size);
|
||||
|
||||
temp = to_copy;
|
||||
|
||||
in = in_buf;
|
||||
out = buf;
|
||||
|
||||
while (temp) {
|
||||
int copy;
|
||||
|
||||
copy = MIN (temp, bufsize - wpos);
|
||||
copy_fn (out + wpos, in, copy);
|
||||
|
||||
wpos += copy;
|
||||
if (wpos == bufsize) {
|
||||
wpos = 0;
|
||||
}
|
||||
|
||||
temp -= copy;
|
||||
in += copy;
|
||||
live += copy;
|
||||
}
|
||||
|
||||
return to_copy;
|
||||
}
|
||||
|
||||
void AUD_run (void)
|
||||
{
|
||||
int res;
|
||||
int bytes;
|
||||
struct audio_buf_info abinfo;
|
||||
|
||||
if (0 == live)
|
||||
return;
|
||||
|
||||
res = ioctl (audio_fd, SNDCTL_DSP_GETOSPACE, &abinfo);
|
||||
|
||||
if (-1 == res) {
|
||||
int err;
|
||||
|
||||
err = errno;
|
||||
lwarn ("SNDCTL_DSP_GETOSPACE failed with %s\n", strerror (err));
|
||||
}
|
||||
|
||||
bytes = abinfo.bytes;
|
||||
bytes = MIN (live, bytes);
|
||||
#if 0
|
||||
bytes = (bytes / fragsize) * fragsize;
|
||||
#endif
|
||||
|
||||
while (bytes) {
|
||||
int left, play, written;
|
||||
|
||||
left = bufsize - rpos;
|
||||
play = MIN (left, bytes);
|
||||
written = write (audio_fd, (void *) ((uint32_t) buf + rpos), play);
|
||||
|
||||
if (-1 == written) {
|
||||
if (EAGAIN == errno || EINTR == errno) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
ERRFail ("write audio");
|
||||
}
|
||||
}
|
||||
|
||||
play = written;
|
||||
live -= play;
|
||||
rpos += play;
|
||||
bytes -= play;
|
||||
|
||||
if (rpos == bufsize) {
|
||||
rpos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int get_dsp_bytes (void)
|
||||
{
|
||||
int res;
|
||||
struct count_info info;
|
||||
|
||||
res = ioctl (audio_fd, SNDCTL_DSP_GETOPTR, &info);
|
||||
if (-1 == res) {
|
||||
int err;
|
||||
|
||||
err = errno;
|
||||
lwarn ("SNDCTL_DSP_GETOPTR failed with %s\n", strerror (err));
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
ldebug ("bytes %d\n", info.bytes);
|
||||
return info.bytes;
|
||||
}
|
||||
}
|
||||
|
||||
void AUD_adjust_estimate (int _leftover)
|
||||
{
|
||||
leftover = _leftover;
|
||||
}
|
||||
|
||||
int AUD_get_free (void)
|
||||
{
|
||||
int free, elapsed;
|
||||
|
||||
free = bufsize - live;
|
||||
|
||||
if (0 == free)
|
||||
return 0;
|
||||
|
||||
elapsed = free;
|
||||
switch (estimate) {
|
||||
case DONT:
|
||||
break;
|
||||
|
||||
case DSP:
|
||||
{
|
||||
static int old_bytes;
|
||||
int bytes;
|
||||
|
||||
bytes = get_dsp_bytes ();
|
||||
if (bytes <= 0)
|
||||
return free;
|
||||
|
||||
elapsed = bytes - old_bytes;
|
||||
old_bytes = bytes;
|
||||
ldebug ("dsp elapsed %d bytes\n", elapsed);
|
||||
break;
|
||||
}
|
||||
|
||||
case TID:
|
||||
{
|
||||
static uint64_t old_ticks;
|
||||
uint64_t ticks, delta;
|
||||
uint64_t ua_elapsed;
|
||||
uint64_t al_elapsed;
|
||||
|
||||
ticks = cpu_get_ticks ();
|
||||
delta = ticks - old_ticks;
|
||||
old_ticks = ticks;
|
||||
|
||||
ua_elapsed = (delta * bytes_per_second) / ticks_per_sec;
|
||||
al_elapsed = ua_elapsed & ~3ULL;
|
||||
|
||||
ldebug ("tid elapsed %llu bytes\n", ua_elapsed);
|
||||
|
||||
if (al_elapsed > (uint64_t) INT_MAX)
|
||||
elapsed = INT_MAX;
|
||||
else
|
||||
elapsed = al_elapsed;
|
||||
|
||||
elapsed += leftover;
|
||||
}
|
||||
}
|
||||
|
||||
if (elapsed > free) {
|
||||
lwarn ("audio can not keep up elapsed %d free %d\n", elapsed, free);
|
||||
return free;
|
||||
}
|
||||
else {
|
||||
return elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
int AUD_get_live (void)
|
||||
{
|
||||
return live;
|
||||
}
|
||||
|
||||
int AUD_get_buffer_size (void)
|
||||
{
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
void AUD_init (void)
|
||||
{
|
||||
int fsp;
|
||||
int _fragsize = 4096;
|
||||
|
||||
DEREF (pab);
|
||||
|
||||
fsp = _fragsize;
|
||||
if (0 != (fsp & (fsp - 1))) {
|
||||
Fail ("fragment size %d is not power of 2", fsp);
|
||||
}
|
||||
|
||||
conf_fragsize = lsbindex (fsp);
|
||||
}
|
Binary file not shown.
3
qemu-binfmt-conf.sh
Normal file
3
qemu-binfmt-conf.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
# enable automatic i386 program execution by the kernel (must enable binfmt_misc)
|
||||
echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
|
||||
echo ':i486:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/usr/local/bin/qemu-i386:' > /proc/sys/fs/binfmt_misc/register
|
100
qemu-doc.texi
100
qemu-doc.texi
@@ -131,13 +131,23 @@ generic dynamic code generation architecture of QEMU.
|
||||
|
||||
The SPARC emulation is currently in development.
|
||||
|
||||
@chapter Installation
|
||||
|
||||
If you want to compile QEMU, please read the @file{README} which gives
|
||||
the related information. Otherwise just download the binary
|
||||
distribution (@file{qemu-XXX-i386.tar.gz}) and untar it as root in
|
||||
@file{/}:
|
||||
|
||||
@example
|
||||
su
|
||||
cd /
|
||||
tar zxvf /tmp/qemu-XXX-i386.tar.gz
|
||||
@end example
|
||||
|
||||
@chapter QEMU User space emulator invocation
|
||||
|
||||
@section Quick Start
|
||||
|
||||
If you need to compile QEMU, please read the @file{README} which gives
|
||||
the related information.
|
||||
|
||||
In order to launch a Linux process, QEMU needs the process executable
|
||||
itself and all the target (x86) dynamic libraries used by it.
|
||||
|
||||
@@ -153,14 +163,14 @@ qemu-i386 -L / /bin/ls
|
||||
@code{-L /} tells that the x86 dynamic linker must be searched with a
|
||||
@file{/} prefix.
|
||||
|
||||
@item Since QEMU is also a linux process, you can launch qemu with qemu:
|
||||
@item Since QEMU is also a linux process, you can launch qemu with qemu (NOTE: you can only do that if you compiled QEMU from the sources):
|
||||
|
||||
@example
|
||||
qemu-i386 -L / qemu-i386 -L / /bin/ls
|
||||
@end example
|
||||
|
||||
@item On non x86 CPUs, you need first to download at least an x86 glibc
|
||||
(@file{qemu-XXX-i386-glibc21.tar.gz} on the QEMU web page). Ensure that
|
||||
(@file{qemu-runtime-i386-XXX-.tar.gz} on the QEMU web page). Ensure that
|
||||
@code{LD_LIBRARY_PATH} is not set:
|
||||
|
||||
@example
|
||||
@@ -271,11 +281,13 @@ VGA (hardware level, including all non standard modes)
|
||||
@item
|
||||
PS/2 mouse and keyboard
|
||||
@item
|
||||
IDE disk interface (port=0x1f0, irq=14)
|
||||
2 IDE interfaces with hard disk and CD-ROM support
|
||||
@item
|
||||
NE2000 network adapter (port=0x300, irq=9)
|
||||
@item
|
||||
Serial port (port=0x3f8, irq=4)
|
||||
Serial port
|
||||
@item
|
||||
Soundblaster 16 card
|
||||
@item
|
||||
PIC (interrupt controler)
|
||||
@item
|
||||
@@ -323,9 +335,8 @@ seen from the emulated kernel at IP address 172.20.0.1.
|
||||
|
||||
@example
|
||||
> ./qemu.sh
|
||||
connected to host network interface: tun0
|
||||
Uncompressing Linux... Ok, booting the kernel.
|
||||
Linux version 2.4.20 (fabrice@localhost.localdomain) (gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)) #22 lun jui 7 13:37:41 CEST 2003
|
||||
Connected to host network interface: tun0
|
||||
Linux version 2.4.21 (bellard@voyager.localdomain) (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #5 Tue Nov 11 18:18:53 CET 2003
|
||||
BIOS-provided physical RAM map:
|
||||
BIOS-e801: 0000000000000000 - 000000000009f000 (usable)
|
||||
BIOS-e801: 0000000000100000 - 0000000002000000 (usable)
|
||||
@@ -334,19 +345,19 @@ On node 0 totalpages: 8192
|
||||
zone(0): 4096 pages.
|
||||
zone(1): 4096 pages.
|
||||
zone(2): 0 pages.
|
||||
Kernel command line: root=/dev/hda ide1=noprobe ide2=noprobe ide3=noprobe ide4=noprobe ide5=noprobe
|
||||
ide_setup: ide1=noprobe
|
||||
Kernel command line: root=/dev/hda sb=0x220,5,1,5 ide2=noprobe ide3=noprobe ide4=noprobe ide5=noprobe console=ttyS0
|
||||
ide_setup: ide2=noprobe
|
||||
ide_setup: ide3=noprobe
|
||||
ide_setup: ide4=noprobe
|
||||
ide_setup: ide5=noprobe
|
||||
Initializing CPU#0
|
||||
Detected 501.285 MHz processor.
|
||||
Calibrating delay loop... 989.59 BogoMIPS
|
||||
Memory: 29268k/32768k available (907k kernel code, 3112k reserved, 212k data, 52k init, 0k highmem)
|
||||
Detected 2399.621 MHz processor.
|
||||
Console: colour EGA 80x25
|
||||
Calibrating delay loop... 4744.80 BogoMIPS
|
||||
Memory: 28872k/32768k available (1210k kernel code, 3508k reserved, 266k data, 64k init, 0k highmem)
|
||||
Dentry cache hash table entries: 4096 (order: 3, 32768 bytes)
|
||||
Inode cache hash table entries: 2048 (order: 2, 16384 bytes)
|
||||
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
|
||||
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
|
||||
Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
|
||||
Page-cache hash table entries: 8192 (order: 3, 32768 bytes)
|
||||
CPU: Intel Pentium Pro stepping 03
|
||||
@@ -358,21 +369,24 @@ Initializing RT netlink socket
|
||||
apm: BIOS not found.
|
||||
Starting kswapd
|
||||
Journalled Block Device driver loaded
|
||||
Detected PS/2 Mouse Port.
|
||||
pty: 256 Unix98 ptys configured
|
||||
Serial driver version 5.05c (2001-07-08) with no serial options enabled
|
||||
ttyS00 at 0x03f8 (irq = 4) is a 16450
|
||||
Uniform Multi-Platform E-IDE driver Revision: 6.31
|
||||
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
|
||||
hda: QEMU HARDDISK, ATA DISK drive
|
||||
ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
|
||||
hda: 12288 sectors (6 MB) w/256KiB Cache, CHS=12/16/63
|
||||
Partition check:
|
||||
hda: unknown partition table
|
||||
ne.c:v1.10 9/23/94 Donald Becker (becker@scyld.com)
|
||||
Last modified Nov 1, 2000 by Paul Gortmaker
|
||||
NE*000 ethercard probe at 0x300: 52 54 00 12 34 56
|
||||
eth0: NE2000 found at 0x300, using IRQ 9.
|
||||
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
|
||||
Uniform Multi-Platform E-IDE driver Revision: 7.00beta4-2.4
|
||||
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
|
||||
hda: QEMU HARDDISK, ATA DISK drive
|
||||
ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
|
||||
hda: attached ide-disk driver.
|
||||
hda: 20480 sectors (10 MB) w/256KiB Cache, CHS=20/16/63
|
||||
Partition check:
|
||||
hda:
|
||||
Soundblaster audio driver Copyright (C) by Hannu Savolainen 1993-1996
|
||||
NET4: Linux TCP/IP 1.0 for NET4.0
|
||||
IP Protocols: ICMP, UDP, TCP, IGMP
|
||||
IP: routing cache hash table of 512 buckets, 4Kbytes
|
||||
@@ -380,9 +394,15 @@ TCP: Hash tables configured (established 2048 bind 4096)
|
||||
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
|
||||
EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended
|
||||
VFS: Mounted root (ext2 filesystem).
|
||||
Freeing unused kernel memory: 52k freed
|
||||
sh: can't access tty; job control turned off
|
||||
#
|
||||
Freeing unused kernel memory: 64k freed
|
||||
|
||||
Linux version 2.4.21 (bellard@voyager.localdomain) (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) #5 Tue Nov 11 18:18:53 CET 2003
|
||||
|
||||
QEMU Linux test distribution (based on Redhat 9)
|
||||
|
||||
Type 'exit' to halt the system
|
||||
|
||||
sh-2.05b#
|
||||
@end example
|
||||
|
||||
@item
|
||||
@@ -416,14 +436,14 @@ A 2.5.74 kernel is also included in the archive. Just
|
||||
replace the bzImage in qemu.sh to try it.
|
||||
|
||||
@item
|
||||
vl creates a temporary file in @var{$QEMU_TMPDIR} (@file{/tmp} is the
|
||||
qemu creates a temporary file in @var{$QEMU_TMPDIR} (@file{/tmp} is the
|
||||
default) containing all the simulated PC memory. If possible, try to use
|
||||
a temporary directory using the tmpfs filesystem to avoid too many
|
||||
unnecessary disk accesses.
|
||||
|
||||
@item
|
||||
In order to exit cleanly for vl, you can do a @emph{shutdown} inside
|
||||
vl. vl will automatically exit when the Linux shutdown is done.
|
||||
In order to exit cleanly from qemu, you can do a @emph{shutdown} inside
|
||||
qemu. qemu will automatically exit when the Linux shutdown is done.
|
||||
|
||||
@item
|
||||
You can boot slightly faster by disabling the probe of non present IDE
|
||||
@@ -448,16 +468,24 @@ usage: qemu [options] [disk_image]
|
||||
@end example
|
||||
|
||||
@c man begin OPTIONS
|
||||
@var{disk_image} is a raw hard image image for IDE hard disk 0.
|
||||
@var{disk_image} is a raw hard disk image for IDE hard disk 0.
|
||||
|
||||
General options:
|
||||
@table @option
|
||||
@item -hda file
|
||||
@item -hdb file
|
||||
Use @var{file} as hard disk 0 or 1 image (@xref{disk_images}).
|
||||
@item -hdc file
|
||||
@item -hdd file
|
||||
Use @var{file} as hard disk 0, 1, 2 or 3 image (@xref{disk_images}).
|
||||
|
||||
@item -cdrom file
|
||||
Use @var{file} as CD-ROM image (you cannot use @option{-hdc} and and
|
||||
@option{-cdrom} at the same time).
|
||||
|
||||
@item -boot [c|d]
|
||||
Boot on hard disk (c) or CD-ROM (d). Hard disk boot is the default.
|
||||
|
||||
@item -snapshot
|
||||
|
||||
Write to temporary files instead of disk image files. In this case,
|
||||
the raw disk image you use is not written back. You can however force
|
||||
the write back by pressing @key{C-a s} (@xref{disk_images}).
|
||||
@@ -466,7 +494,7 @@ the write back by pressing @key{C-a s} (@xref{disk_images}).
|
||||
Set virtual RAM size to @var{megs} megabytes.
|
||||
|
||||
@item -n script
|
||||
Set network init script [default=/etc/vl-ifup]. This script is
|
||||
Set network init script [default=/etc/qemu-ifup]. This script is
|
||||
launched to configure the host network interface (usually tun0)
|
||||
corresponding to the virtual NE2000 card.
|
||||
|
||||
@@ -509,7 +537,7 @@ Wait gdb connection to port 1234 (@xref{gdb_usage}).
|
||||
@item -p port
|
||||
Change gdb connection port.
|
||||
@item -d
|
||||
Output log in /tmp/vl.log
|
||||
Output log in /tmp/qemu.log
|
||||
@end table
|
||||
|
||||
During emulation, use @key{C-a h} to get terminal commands:
|
||||
@@ -694,10 +722,10 @@ exactly the same kernel as you would boot on your PC (in
|
||||
QEMU has a primitive support to work with gdb, so that you can do
|
||||
'Ctrl-C' while the virtual machine is running and inspect its state.
|
||||
|
||||
In order to use gdb, launch vl with the '-s' option. It will wait for a
|
||||
In order to use gdb, launch qemu with the '-s' option. It will wait for a
|
||||
gdb connection:
|
||||
@example
|
||||
> vl -s arch/i386/boot/bzImage -hda root-2.4.20.img root=/dev/hda
|
||||
> qemu -s arch/i386/boot/bzImage -hda root-2.4.20.img root=/dev/hda
|
||||
Connected to host network interface: tun0
|
||||
Waiting gdb connection on port 1234
|
||||
@end example
|
||||
|
@@ -74,7 +74,7 @@ DATA_TYPE REGPARM(1) glue(glue(__ld, SUFFIX), MMUSUFFIX)(unsigned long addr,
|
||||
int is_user);
|
||||
void REGPARM(2) glue(glue(__st, SUFFIX), MMUSUFFIX)(unsigned long addr, DATA_TYPE v, int is_user);
|
||||
|
||||
static inline int glue(glue(ld, USUFFIX), MEMSUFFIX)(void *ptr)
|
||||
static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(void *ptr)
|
||||
{
|
||||
int index;
|
||||
RES_TYPE res;
|
||||
|
@@ -187,7 +187,7 @@ void REGPARM(2) glue(glue(__st, SUFFIX), MMUSUFFIX)(unsigned long addr,
|
||||
redo:
|
||||
tlb_addr = env->tlb_write[is_user][index].address;
|
||||
if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
|
||||
physaddr = addr + env->tlb_read[is_user][index].addend;
|
||||
physaddr = addr + env->tlb_write[is_user][index].addend;
|
||||
if (tlb_addr & ~TARGET_PAGE_MASK) {
|
||||
/* IO access */
|
||||
if ((addr & (DATA_SIZE - 1)) != 0)
|
||||
@@ -223,7 +223,7 @@ static void glue(glue(slow_st, SUFFIX), MMUSUFFIX)(unsigned long addr,
|
||||
redo:
|
||||
tlb_addr = env->tlb_write[is_user][index].address;
|
||||
if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
|
||||
physaddr = addr + env->tlb_read[is_user][index].addend;
|
||||
physaddr = addr + env->tlb_write[is_user][index].addend;
|
||||
if (tlb_addr & ~TARGET_PAGE_MASK) {
|
||||
/* IO access */
|
||||
if ((addr & (DATA_SIZE - 1)) != 0)
|
||||
|
@@ -368,7 +368,7 @@ void OPPROTO op_mul_T0_T1(void)
|
||||
void OPPROTO op_mull_T0_T1(void)
|
||||
{
|
||||
uint64_t res;
|
||||
res = T0 * T1;
|
||||
res = (uint64_t)T0 * (uint64_t)T1;
|
||||
T1 = res >> 32;
|
||||
T0 = res;
|
||||
}
|
||||
@@ -377,7 +377,7 @@ void OPPROTO op_mull_T0_T1(void)
|
||||
void OPPROTO op_imull_T0_T1(void)
|
||||
{
|
||||
uint64_t res;
|
||||
res = (int32_t)T0 * (int32_t)T1;
|
||||
res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1);
|
||||
T1 = res >> 32;
|
||||
T0 = res;
|
||||
}
|
||||
|
@@ -516,9 +516,9 @@ static void disas_arm_insn(DisasContext *s)
|
||||
gen_movl_T0_reg(s, rs);
|
||||
gen_movl_T1_reg(s, rm);
|
||||
if (insn & (1 << 22))
|
||||
gen_op_mull_T0_T1();
|
||||
else
|
||||
gen_op_imull_T0_T1();
|
||||
else
|
||||
gen_op_mull_T0_T1();
|
||||
if (insn & (1 << 21))
|
||||
gen_op_addq_T0_T1(rn, rd);
|
||||
if (insn & (1 << 20))
|
||||
@@ -546,8 +546,7 @@ static void disas_arm_insn(DisasContext *s)
|
||||
rn = (insn >> 16) & 0xf;
|
||||
rd = (insn >> 12) & 0xf;
|
||||
gen_movl_T1_reg(s, rn);
|
||||
if (insn & (1 << 25))
|
||||
gen_add_datah_offset(s, insn);
|
||||
gen_add_datah_offset(s, insn);
|
||||
if (insn & (1 << 20)) {
|
||||
/* load */
|
||||
switch(sh) {
|
||||
@@ -562,8 +561,10 @@ static void disas_arm_insn(DisasContext *s)
|
||||
gen_op_ldsw_T0_T1();
|
||||
break;
|
||||
}
|
||||
gen_movl_reg_T0(s, rd);
|
||||
} else {
|
||||
/* store */
|
||||
gen_movl_T0_reg(s, rd);
|
||||
gen_op_stw_T0_T1();
|
||||
}
|
||||
if (!(insn & (1 << 24))) {
|
||||
|
@@ -58,12 +58,14 @@
|
||||
#define DESC_TYPE_SHIFT 8
|
||||
#define DESC_A_MASK (1 << 8)
|
||||
|
||||
#define DESC_CS_MASK (1 << 11)
|
||||
#define DESC_C_MASK (1 << 10)
|
||||
#define DESC_R_MASK (1 << 9)
|
||||
#define DESC_CS_MASK (1 << 11) /* 1=code segment 0=data segment */
|
||||
#define DESC_C_MASK (1 << 10) /* code: conforming */
|
||||
#define DESC_R_MASK (1 << 9) /* code: readable */
|
||||
|
||||
#define DESC_E_MASK (1 << 10)
|
||||
#define DESC_W_MASK (1 << 9)
|
||||
#define DESC_E_MASK (1 << 10) /* data: expansion direction */
|
||||
#define DESC_W_MASK (1 << 9) /* data: writable */
|
||||
|
||||
#define DESC_TSS_BUSY_MASK (1 << 9)
|
||||
|
||||
/* eflags masks */
|
||||
#define CC_C 0x0001
|
||||
@@ -182,7 +184,10 @@
|
||||
enum {
|
||||
CC_OP_DYNAMIC, /* must use dynamic code to get cc_op */
|
||||
CC_OP_EFLAGS, /* all cc are explicitely computed, CC_SRC = flags */
|
||||
CC_OP_MUL, /* modify all flags, C, O = (CC_SRC != 0) */
|
||||
|
||||
CC_OP_MULB, /* modify all flags, C, O = (CC_SRC != 0) */
|
||||
CC_OP_MULW,
|
||||
CC_OP_MULL,
|
||||
|
||||
CC_OP_ADDB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
|
||||
CC_OP_ADDW,
|
||||
@@ -389,6 +394,9 @@ void cpu_x86_init_mmu(CPUX86State *env);
|
||||
extern int phys_ram_size;
|
||||
extern int phys_ram_fd;
|
||||
extern uint8_t *phys_ram_base;
|
||||
extern int a20_enabled;
|
||||
|
||||
void cpu_x86_set_a20(CPUX86State *env, int a20_state);
|
||||
|
||||
/* used to debug */
|
||||
#define X86_DUMP_FPU 0x0001 /* dump FPU state too */
|
||||
|
@@ -122,7 +122,7 @@ typedef struct CCTable {
|
||||
|
||||
extern CCTable cc_table[];
|
||||
|
||||
void load_seg(int seg_reg, int selector, unsigned cur_eip);
|
||||
void load_seg(int seg_reg, int selector);
|
||||
void helper_ljmp_protected_T0_T1(void);
|
||||
void helper_lcall_real_T0_T1(int shift, int next_eip);
|
||||
void helper_lcall_protected_T0_T1(int shift, int next_eip);
|
||||
@@ -170,6 +170,124 @@ void helper_rdmsr(void);
|
||||
void helper_wrmsr(void);
|
||||
void helper_lsl(void);
|
||||
void helper_lar(void);
|
||||
void helper_verr(void);
|
||||
void helper_verw(void);
|
||||
|
||||
void check_iob_T0(void);
|
||||
void check_iow_T0(void);
|
||||
void check_iol_T0(void);
|
||||
void check_iob_DX(void);
|
||||
void check_iow_DX(void);
|
||||
void check_iol_DX(void);
|
||||
|
||||
/* XXX: move that to a generic header */
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
#define ldul_user ldl_user
|
||||
#define ldul_kernel ldl_kernel
|
||||
|
||||
#define ACCESS_TYPE 0
|
||||
#define MEMSUFFIX _kernel
|
||||
#define DATA_SIZE 1
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 2
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 8
|
||||
#include "softmmu_header.h"
|
||||
#undef ACCESS_TYPE
|
||||
#undef MEMSUFFIX
|
||||
|
||||
#define ACCESS_TYPE 1
|
||||
#define MEMSUFFIX _user
|
||||
#define DATA_SIZE 1
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 2
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 8
|
||||
#include "softmmu_header.h"
|
||||
#undef ACCESS_TYPE
|
||||
#undef MEMSUFFIX
|
||||
|
||||
/* these access are slower, they must be as rare as possible */
|
||||
#define ACCESS_TYPE 2
|
||||
#define MEMSUFFIX _data
|
||||
#define DATA_SIZE 1
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 2
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 8
|
||||
#include "softmmu_header.h"
|
||||
#undef ACCESS_TYPE
|
||||
#undef MEMSUFFIX
|
||||
|
||||
#define ldub(p) ldub_data(p)
|
||||
#define ldsb(p) ldsb_data(p)
|
||||
#define lduw(p) lduw_data(p)
|
||||
#define ldsw(p) ldsw_data(p)
|
||||
#define ldl(p) ldl_data(p)
|
||||
#define ldq(p) ldq_data(p)
|
||||
|
||||
#define stb(p, v) stb_data(p, v)
|
||||
#define stw(p, v) stw_data(p, v)
|
||||
#define stl(p, v) stl_data(p, v)
|
||||
#define stq(p, v) stq_data(p, v)
|
||||
|
||||
static inline double ldfq(void *ptr)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint64_t i;
|
||||
} u;
|
||||
u.i = ldq(ptr);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
static inline void stfq(void *ptr, double v)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint64_t i;
|
||||
} u;
|
||||
u.d = v;
|
||||
stq(ptr, u.i);
|
||||
}
|
||||
|
||||
static inline float ldfl(void *ptr)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.i = ldl(ptr);
|
||||
return u.f;
|
||||
}
|
||||
|
||||
static inline void stfl(void *ptr, float v)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.f = v;
|
||||
stl(ptr, u.i);
|
||||
}
|
||||
|
||||
#endif /* !defined(CONFIG_USER_ONLY) */
|
||||
|
||||
#ifdef USE_X86LDOUBLE
|
||||
/* use long double functions */
|
||||
@@ -317,7 +435,47 @@ static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr)
|
||||
e |= SIGND(temp) >> 16;
|
||||
stw(ptr + 8, e);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
|
||||
/* XXX: same endianness assumed */
|
||||
|
||||
#ifdef CONFIG_USER_ONLY
|
||||
|
||||
static inline CPU86_LDouble helper_fldt(uint8_t *ptr)
|
||||
{
|
||||
return *(CPU86_LDouble *)ptr;
|
||||
}
|
||||
|
||||
static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr)
|
||||
{
|
||||
*(CPU86_LDouble *)ptr = f;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* we use memory access macros */
|
||||
|
||||
static inline CPU86_LDouble helper_fldt(uint8_t *ptr)
|
||||
{
|
||||
CPU86_LDoubleU temp;
|
||||
|
||||
temp.l.lower = ldq(ptr);
|
||||
temp.l.upper = lduw(ptr + 8);
|
||||
return temp.d;
|
||||
}
|
||||
|
||||
static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr)
|
||||
{
|
||||
CPU86_LDoubleU temp;
|
||||
|
||||
temp.d = f;
|
||||
stq(ptr, temp.l.lower);
|
||||
stw(ptr + 8, temp.l.upper);
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_USER_ONLY */
|
||||
|
||||
#endif /* USE_X86LDOUBLE */
|
||||
|
||||
const CPU86_LDouble f15rk[7];
|
||||
|
||||
@@ -354,11 +512,6 @@ static inline uint32_t compute_eflags(void)
|
||||
return env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
|
||||
}
|
||||
|
||||
#define FL_UPDATE_MASK32 (TF_MASK | AC_MASK | ID_MASK)
|
||||
|
||||
#define FL_UPDATE_CPL0_MASK (TF_MASK | IF_MASK | IOPL_MASK | NT_MASK | \
|
||||
RF_MASK | AC_MASK | ID_MASK)
|
||||
|
||||
/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
|
||||
static inline void load_eflags(int eflags, int update_mask)
|
||||
{
|
||||
@@ -368,111 +521,3 @@ static inline void load_eflags(int eflags, int update_mask)
|
||||
(eflags & update_mask);
|
||||
}
|
||||
|
||||
/* XXX: move that to a generic header */
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
#define ldul_user ldl_user
|
||||
#define ldul_kernel ldl_kernel
|
||||
|
||||
#define ACCESS_TYPE 0
|
||||
#define MEMSUFFIX _kernel
|
||||
#define DATA_SIZE 1
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 2
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 8
|
||||
#include "softmmu_header.h"
|
||||
#undef ACCESS_TYPE
|
||||
#undef MEMSUFFIX
|
||||
|
||||
#define ACCESS_TYPE 1
|
||||
#define MEMSUFFIX _user
|
||||
#define DATA_SIZE 1
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 2
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 8
|
||||
#include "softmmu_header.h"
|
||||
#undef ACCESS_TYPE
|
||||
#undef MEMSUFFIX
|
||||
|
||||
/* these access are slower, they must be as rare as possible */
|
||||
#define ACCESS_TYPE 2
|
||||
#define MEMSUFFIX _data
|
||||
#define DATA_SIZE 1
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 2
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#include "softmmu_header.h"
|
||||
|
||||
#define DATA_SIZE 8
|
||||
#include "softmmu_header.h"
|
||||
#undef ACCESS_TYPE
|
||||
#undef MEMSUFFIX
|
||||
|
||||
#define ldub(p) ldub_data(p)
|
||||
#define ldsb(p) ldsb_data(p)
|
||||
#define lduw(p) lduw_data(p)
|
||||
#define ldsw(p) ldsw_data(p)
|
||||
#define ldl(p) ldl_data(p)
|
||||
#define ldq(p) ldq_data(p)
|
||||
|
||||
#define stb(p, v) stb_data(p, v)
|
||||
#define stw(p, v) stw_data(p, v)
|
||||
#define stl(p, v) stl_data(p, v)
|
||||
#define stq(p, v) stq_data(p, v)
|
||||
|
||||
static inline double ldfq(void *ptr)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint64_t i;
|
||||
} u;
|
||||
u.i = ldq(ptr);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
static inline void stfq(void *ptr, double v)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint64_t i;
|
||||
} u;
|
||||
u.d = v;
|
||||
stq(ptr, u.i);
|
||||
}
|
||||
|
||||
static inline float ldfl(void *ptr)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.i = ldl(ptr);
|
||||
return u.f;
|
||||
}
|
||||
|
||||
static inline void stfl(void *ptr, float v)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.f = v;
|
||||
stl(ptr, u.i);
|
||||
}
|
||||
|
||||
#endif /* !defined(CONFIG_USER_ONLY) */
|
||||
|
1299
target-i386/helper.c
1299
target-i386/helper.c
File diff suppressed because it is too large
Load Diff
@@ -73,7 +73,9 @@ void cpu_x86_close(CPUX86State *env)
|
||||
static const char *cc_op_str[] = {
|
||||
"DYNAMIC",
|
||||
"EFLAGS",
|
||||
"MUL",
|
||||
"MULB",
|
||||
"MULW",
|
||||
"MULL",
|
||||
"ADDB",
|
||||
"ADDW",
|
||||
"ADDL",
|
||||
@@ -105,13 +107,14 @@ static const char *cc_op_str[] = {
|
||||
|
||||
void cpu_x86_dump_state(CPUX86State *env, FILE *f, int flags)
|
||||
{
|
||||
int eflags;
|
||||
int eflags, i;
|
||||
char cc_op_name[32];
|
||||
static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
|
||||
|
||||
eflags = env->eflags;
|
||||
fprintf(f, "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
|
||||
"ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
|
||||
"EIP=%08x EFL=%08x [%c%c%c%c%c%c%c]\n",
|
||||
"EIP=%08x EFL=%08x [%c%c%c%c%c%c%c] CPL=%d II=%d\n",
|
||||
env->regs[R_EAX], env->regs[R_EBX], env->regs[R_ECX], env->regs[R_EDX],
|
||||
env->regs[R_ESI], env->regs[R_EDI], env->regs[R_EBP], env->regs[R_ESP],
|
||||
env->eip, eflags,
|
||||
@@ -121,14 +124,35 @@ void cpu_x86_dump_state(CPUX86State *env, FILE *f, int flags)
|
||||
eflags & CC_Z ? 'Z' : '-',
|
||||
eflags & CC_A ? 'A' : '-',
|
||||
eflags & CC_P ? 'P' : '-',
|
||||
eflags & CC_C ? 'C' : '-');
|
||||
fprintf(f, "CS=%04x SS=%04x DS=%04x ES=%04x FS=%04x GS=%04x\n",
|
||||
env->segs[R_CS].selector,
|
||||
env->segs[R_SS].selector,
|
||||
env->segs[R_DS].selector,
|
||||
env->segs[R_ES].selector,
|
||||
env->segs[R_FS].selector,
|
||||
env->segs[R_GS].selector);
|
||||
eflags & CC_C ? 'C' : '-',
|
||||
env->hflags & HF_CPL_MASK,
|
||||
(env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1);
|
||||
for(i = 0; i < 6; i++) {
|
||||
SegmentCache *sc = &env->segs[i];
|
||||
fprintf(f, "%s =%04x %08x %08x %08x\n",
|
||||
seg_name[i],
|
||||
sc->selector,
|
||||
(int)sc->base,
|
||||
sc->limit,
|
||||
sc->flags);
|
||||
}
|
||||
fprintf(f, "LDT=%04x %08x %08x %08x\n",
|
||||
env->ldt.selector,
|
||||
(int)env->ldt.base,
|
||||
env->ldt.limit,
|
||||
env->ldt.flags);
|
||||
fprintf(f, "TR =%04x %08x %08x %08x\n",
|
||||
env->tr.selector,
|
||||
(int)env->tr.base,
|
||||
env->tr.limit,
|
||||
env->tr.flags);
|
||||
fprintf(f, "GDT= %08x %08x\n",
|
||||
(int)env->gdt.base, env->gdt.limit);
|
||||
fprintf(f, "IDT= %08x %08x\n",
|
||||
(int)env->idt.base, env->idt.limit);
|
||||
fprintf(f, "CR0=%08x CR2=%08x CR3=%08x CR4=%08x\n",
|
||||
env->cr[0], env->cr[2], env->cr[3], env->cr[4]);
|
||||
|
||||
if (flags & X86_DUMP_CCOP) {
|
||||
if ((unsigned)env->cc_op < CC_OP_NB)
|
||||
strcpy(cc_op_name, cc_op_str[env->cc_op]);
|
||||
@@ -158,26 +182,50 @@ void cpu_x86_dump_state(CPUX86State *env, FILE *f, int flags)
|
||||
/* called when cr3 or PG bit are modified */
|
||||
static int last_pg_state = -1;
|
||||
static int last_pe_state = 0;
|
||||
static uint32_t a20_mask;
|
||||
int a20_enabled;
|
||||
|
||||
int phys_ram_size;
|
||||
int phys_ram_fd;
|
||||
uint8_t *phys_ram_base;
|
||||
|
||||
void cpu_x86_set_a20(CPUX86State *env, int a20_state)
|
||||
{
|
||||
a20_state = (a20_state != 0);
|
||||
if (a20_state != a20_enabled) {
|
||||
#if defined(DEBUG_MMU)
|
||||
printf("A20 update: a20=%d\n", a20_state);
|
||||
#endif
|
||||
/* if the cpu is currently executing code, we must unlink it and
|
||||
all the potentially executing TB */
|
||||
cpu_interrupt(env, 0);
|
||||
|
||||
/* when a20 is changed, all the MMU mappings are invalid, so
|
||||
we must flush everything */
|
||||
tlb_flush(env);
|
||||
a20_enabled = a20_state;
|
||||
if (a20_enabled)
|
||||
a20_mask = 0xffffffff;
|
||||
else
|
||||
a20_mask = 0xffefffff;
|
||||
}
|
||||
}
|
||||
|
||||
void cpu_x86_update_cr0(CPUX86State *env)
|
||||
{
|
||||
int pg_state, pe_state;
|
||||
|
||||
#ifdef DEBUG_MMU
|
||||
#if defined(DEBUG_MMU)
|
||||
printf("CR0 update: CR0=0x%08x\n", env->cr[0]);
|
||||
#endif
|
||||
pg_state = env->cr[0] & CR0_PG_MASK;
|
||||
if (pg_state != last_pg_state) {
|
||||
page_unmap();
|
||||
tlb_flush(env);
|
||||
last_pg_state = pg_state;
|
||||
}
|
||||
pe_state = env->cr[0] & CR0_PE_MASK;
|
||||
if (last_pe_state != pe_state) {
|
||||
tb_flush();
|
||||
tb_flush(env);
|
||||
last_pe_state = pe_state;
|
||||
}
|
||||
}
|
||||
@@ -188,13 +236,15 @@ void cpu_x86_update_cr3(CPUX86State *env)
|
||||
#if defined(DEBUG_MMU)
|
||||
printf("CR3 update: CR3=%08x\n", env->cr[3]);
|
||||
#endif
|
||||
page_unmap();
|
||||
tlb_flush(env);
|
||||
}
|
||||
}
|
||||
|
||||
void cpu_x86_init_mmu(CPUX86State *env)
|
||||
{
|
||||
a20_enabled = 1;
|
||||
a20_mask = 0xffffffff;
|
||||
|
||||
last_pg_state = -1;
|
||||
cpu_x86_update_cr0(env);
|
||||
}
|
||||
@@ -202,19 +252,7 @@ void cpu_x86_init_mmu(CPUX86State *env)
|
||||
/* XXX: also flush 4MB pages */
|
||||
void cpu_x86_flush_tlb(CPUX86State *env, uint32_t addr)
|
||||
{
|
||||
int flags;
|
||||
unsigned long virt_addr;
|
||||
|
||||
tlb_flush_page(env, addr);
|
||||
|
||||
flags = page_get_flags(addr);
|
||||
if (flags & PAGE_VALID) {
|
||||
virt_addr = addr & ~0xfff;
|
||||
#if !defined(CONFIG_SOFTMMU)
|
||||
munmap((void *)virt_addr, 4096);
|
||||
#endif
|
||||
page_set_flags(virt_addr, virt_addr + 4096, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* return value:
|
||||
@@ -244,14 +282,15 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr,
|
||||
|
||||
if (!(env->cr[0] & CR0_PG_MASK)) {
|
||||
pte = addr;
|
||||
virt_addr = addr & ~0xfff;
|
||||
virt_addr = addr & TARGET_PAGE_MASK;
|
||||
prot = PROT_READ | PROT_WRITE;
|
||||
page_size = 4096;
|
||||
goto do_mapping;
|
||||
}
|
||||
|
||||
/* page directory entry */
|
||||
pde_ptr = phys_ram_base + ((env->cr[3] & ~0xfff) + ((addr >> 20) & ~3));
|
||||
pde_ptr = phys_ram_base +
|
||||
(((env->cr[3] & ~0xfff) + ((addr >> 20) & ~3)) & a20_mask);
|
||||
pde = ldl_raw(pde_ptr);
|
||||
if (!(pde & PG_PRESENT_MASK)) {
|
||||
error_code = 0;
|
||||
@@ -287,7 +326,8 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr,
|
||||
}
|
||||
|
||||
/* page directory entry */
|
||||
pte_ptr = phys_ram_base + ((pde & ~0xfff) + ((addr >> 10) & 0xffc));
|
||||
pte_ptr = phys_ram_base +
|
||||
(((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & a20_mask);
|
||||
pte = ldl_raw(pte_ptr);
|
||||
if (!(pte & PG_PRESENT_MASK)) {
|
||||
error_code = 0;
|
||||
@@ -325,6 +365,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr,
|
||||
}
|
||||
|
||||
do_mapping:
|
||||
pte = pte & a20_mask;
|
||||
#if !defined(CONFIG_SOFTMMU)
|
||||
if (is_softmmu)
|
||||
#endif
|
||||
@@ -334,8 +375,8 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr,
|
||||
|
||||
/* software MMU case. Even if 4MB pages, we map only one 4KB
|
||||
page in the cache to avoid filling it too fast */
|
||||
page_offset = (addr & ~0xfff) & (page_size - 1);
|
||||
paddr = (pte & ~0xfff) + page_offset;
|
||||
page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1);
|
||||
paddr = (pte & TARGET_PAGE_MASK) + page_offset;
|
||||
vaddr = virt_addr + page_offset;
|
||||
index = (addr >> 12) & (CPU_TLB_SIZE - 1);
|
||||
pd = physpage_find(paddr);
|
||||
@@ -354,6 +395,9 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr,
|
||||
if (prot & PROT_WRITE) {
|
||||
env->tlb_write[is_user][index].address = address;
|
||||
env->tlb_write[is_user][index].addend = addend;
|
||||
} else {
|
||||
env->tlb_write[is_user][index].address = -1;
|
||||
env->tlb_write[is_user][index].addend = -1;
|
||||
}
|
||||
page_set_flags(vaddr, vaddr + TARGET_PAGE_SIZE,
|
||||
PAGE_VALID | PAGE_EXEC | prot);
|
||||
|
126
target-i386/op.c
126
target-i386/op.c
@@ -169,11 +169,16 @@ void OPPROTO op_bswapl_T0(void)
|
||||
}
|
||||
|
||||
/* multiply/divide */
|
||||
|
||||
/* XXX: add eflags optimizations */
|
||||
/* XXX: add non P4 style flags */
|
||||
|
||||
void OPPROTO op_mulb_AL_T0(void)
|
||||
{
|
||||
unsigned int res;
|
||||
res = (uint8_t)EAX * (uint8_t)T0;
|
||||
EAX = (EAX & 0xffff0000) | res;
|
||||
CC_DST = res;
|
||||
CC_SRC = (res & 0xff00);
|
||||
}
|
||||
|
||||
@@ -182,6 +187,7 @@ void OPPROTO op_imulb_AL_T0(void)
|
||||
int res;
|
||||
res = (int8_t)EAX * (int8_t)T0;
|
||||
EAX = (EAX & 0xffff0000) | (res & 0xffff);
|
||||
CC_DST = res;
|
||||
CC_SRC = (res != (int8_t)res);
|
||||
}
|
||||
|
||||
@@ -191,6 +197,7 @@ void OPPROTO op_mulw_AX_T0(void)
|
||||
res = (uint16_t)EAX * (uint16_t)T0;
|
||||
EAX = (EAX & 0xffff0000) | (res & 0xffff);
|
||||
EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff);
|
||||
CC_DST = res;
|
||||
CC_SRC = res >> 16;
|
||||
}
|
||||
|
||||
@@ -200,6 +207,7 @@ void OPPROTO op_imulw_AX_T0(void)
|
||||
res = (int16_t)EAX * (int16_t)T0;
|
||||
EAX = (EAX & 0xffff0000) | (res & 0xffff);
|
||||
EDX = (EDX & 0xffff0000) | ((res >> 16) & 0xffff);
|
||||
CC_DST = res;
|
||||
CC_SRC = (res != (int16_t)res);
|
||||
}
|
||||
|
||||
@@ -209,6 +217,7 @@ void OPPROTO op_mull_EAX_T0(void)
|
||||
res = (uint64_t)((uint32_t)EAX) * (uint64_t)((uint32_t)T0);
|
||||
EAX = res;
|
||||
EDX = res >> 32;
|
||||
CC_DST = res;
|
||||
CC_SRC = res >> 32;
|
||||
}
|
||||
|
||||
@@ -218,6 +227,7 @@ void OPPROTO op_imull_EAX_T0(void)
|
||||
res = (int64_t)((int32_t)EAX) * (int64_t)((int32_t)T0);
|
||||
EAX = res;
|
||||
EDX = res >> 32;
|
||||
CC_DST = res;
|
||||
CC_SRC = (res != (int32_t)res);
|
||||
}
|
||||
|
||||
@@ -226,6 +236,7 @@ void OPPROTO op_imulw_T0_T1(void)
|
||||
int res;
|
||||
res = (int16_t)T0 * (int16_t)T1;
|
||||
T0 = res;
|
||||
CC_DST = res;
|
||||
CC_SRC = (res != (int16_t)res);
|
||||
}
|
||||
|
||||
@@ -234,6 +245,7 @@ void OPPROTO op_imull_T0_T1(void)
|
||||
int64_t res;
|
||||
res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1);
|
||||
T0 = res;
|
||||
CC_DST = res;
|
||||
CC_SRC = (res != (int32_t)res);
|
||||
}
|
||||
|
||||
@@ -895,7 +907,7 @@ void OPPROTO op_das(void)
|
||||
/* never use it with R_CS */
|
||||
void OPPROTO op_movl_seg_T0(void)
|
||||
{
|
||||
load_seg(PARAM1, T0 & 0xffff, PARAM2);
|
||||
load_seg(PARAM1, T0);
|
||||
}
|
||||
|
||||
/* faster VM86 version */
|
||||
@@ -936,6 +948,35 @@ void OPPROTO op_lar(void)
|
||||
helper_lar();
|
||||
}
|
||||
|
||||
void OPPROTO op_verr(void)
|
||||
{
|
||||
helper_verr();
|
||||
}
|
||||
|
||||
void OPPROTO op_verw(void)
|
||||
{
|
||||
helper_verw();
|
||||
}
|
||||
|
||||
void OPPROTO op_arpl(void)
|
||||
{
|
||||
if ((T0 & 3) < (T1 & 3)) {
|
||||
/* XXX: emulate bug or 0xff3f0000 oring as in bochs ? */
|
||||
T0 = (T0 & ~3) | (T1 & 3);
|
||||
T1 = CC_Z;
|
||||
} else {
|
||||
T1 = 0;
|
||||
}
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_arpl_update(void)
|
||||
{
|
||||
int eflags;
|
||||
eflags = cc_table[CC_OP].compute_all();
|
||||
CC_SRC = (eflags & ~CC_Z) | T1;
|
||||
}
|
||||
|
||||
/* T0: segment, T1:eip */
|
||||
void OPPROTO op_ljmp_protected_T0_T1(void)
|
||||
{
|
||||
@@ -1109,38 +1150,36 @@ void OPPROTO op_set_cc_op(void)
|
||||
CC_OP = PARAM1;
|
||||
}
|
||||
|
||||
#define FL_UPDATE_MASK16 (FL_UPDATE_MASK32 & 0xffff)
|
||||
/* XXX: clear VIF/VIP in all ops ? */
|
||||
|
||||
void OPPROTO op_movl_eflags_T0(void)
|
||||
{
|
||||
int eflags;
|
||||
eflags = T0;
|
||||
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
||||
DF = 1 - (2 * ((eflags >> 10) & 1));
|
||||
/* we also update some system flags as in user mode */
|
||||
env->eflags = (env->eflags & ~FL_UPDATE_MASK32) |
|
||||
(eflags & FL_UPDATE_MASK32);
|
||||
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK));
|
||||
}
|
||||
|
||||
void OPPROTO op_movw_eflags_T0(void)
|
||||
{
|
||||
int eflags;
|
||||
eflags = T0;
|
||||
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
||||
DF = 1 - (2 * ((eflags >> 10) & 1));
|
||||
/* we also update some system flags as in user mode */
|
||||
env->eflags = (env->eflags & ~FL_UPDATE_MASK16) |
|
||||
(eflags & FL_UPDATE_MASK16);
|
||||
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK) & 0xffff);
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_eflags_T0_io(void)
|
||||
{
|
||||
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | IF_MASK));
|
||||
}
|
||||
|
||||
void OPPROTO op_movw_eflags_T0_io(void)
|
||||
{
|
||||
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | IF_MASK) & 0xffff);
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_eflags_T0_cpl0(void)
|
||||
{
|
||||
load_eflags(T0, FL_UPDATE_CPL0_MASK);
|
||||
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | IF_MASK | IOPL_MASK));
|
||||
}
|
||||
|
||||
void OPPROTO op_movw_eflags_T0_cpl0(void)
|
||||
{
|
||||
load_eflags(T0, FL_UPDATE_CPL0_MASK & 0xffff);
|
||||
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | IF_MASK | IOPL_MASK) & 0xffff);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -1266,31 +1305,14 @@ static int compute_c_eflags(void)
|
||||
return CC_SRC & CC_C;
|
||||
}
|
||||
|
||||
static int compute_c_mul(void)
|
||||
{
|
||||
int cf;
|
||||
cf = (CC_SRC != 0);
|
||||
return cf;
|
||||
}
|
||||
|
||||
static int compute_all_mul(void)
|
||||
{
|
||||
int cf, pf, af, zf, sf, of;
|
||||
cf = (CC_SRC != 0);
|
||||
pf = 0; /* undefined */
|
||||
af = 0; /* undefined */
|
||||
zf = 0; /* undefined */
|
||||
sf = 0; /* undefined */
|
||||
of = cf << 11;
|
||||
return cf | pf | af | zf | sf | of;
|
||||
}
|
||||
|
||||
CCTable cc_table[CC_OP_NB] = {
|
||||
[CC_OP_DYNAMIC] = { /* should never happen */ },
|
||||
|
||||
[CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags },
|
||||
|
||||
[CC_OP_MUL] = { compute_all_mul, compute_c_mul },
|
||||
[CC_OP_MULB] = { compute_all_mulb, compute_c_mull },
|
||||
[CC_OP_MULW] = { compute_all_mulw, compute_c_mull },
|
||||
[CC_OP_MULL] = { compute_all_mull, compute_c_mull },
|
||||
|
||||
[CC_OP_ADDB] = { compute_all_addb, compute_c_addb },
|
||||
[CC_OP_ADDW] = { compute_all_addw, compute_c_addw },
|
||||
@@ -1471,21 +1493,10 @@ void OPPROTO op_fldl_ST0_A0(void)
|
||||
env->fptags[new_fpstt] = 0; /* validate stack entry */
|
||||
}
|
||||
|
||||
#ifdef USE_X86LDOUBLE
|
||||
void OPPROTO op_fldt_ST0_A0(void)
|
||||
{
|
||||
int new_fpstt;
|
||||
new_fpstt = (env->fpstt - 1) & 7;
|
||||
env->fpregs[new_fpstt] = *(long double *)A0;
|
||||
env->fpstt = new_fpstt;
|
||||
env->fptags[new_fpstt] = 0; /* validate stack entry */
|
||||
}
|
||||
#else
|
||||
void OPPROTO op_fldt_ST0_A0(void)
|
||||
{
|
||||
helper_fldt_ST0_A0();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
||||
#ifdef USE_INT_TO_FLOAT_HELPERS
|
||||
@@ -1595,17 +1606,10 @@ void OPPROTO op_fstl_ST0_A0(void)
|
||||
stfq((void *)A0, (double)ST0);
|
||||
}
|
||||
|
||||
#ifdef USE_X86LDOUBLE
|
||||
void OPPROTO op_fstt_ST0_A0(void)
|
||||
{
|
||||
*(long double *)A0 = ST0;
|
||||
}
|
||||
#else
|
||||
void OPPROTO op_fstt_ST0_A0(void)
|
||||
{
|
||||
helper_fstt_ST0_A0();
|
||||
}
|
||||
#endif
|
||||
|
||||
void OPPROTO op_fist_ST0_A0(void)
|
||||
{
|
||||
@@ -1765,6 +1769,14 @@ void OPPROTO op_fucomi_ST0_FT0(void)
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_fcmov_ST0_STN_T0(void)
|
||||
{
|
||||
if (T0) {
|
||||
ST0 = ST(PARAM1);
|
||||
}
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_fadd_ST0_FT0(void)
|
||||
{
|
||||
ST0 += FT0;
|
||||
@@ -1884,7 +1896,7 @@ void OPPROTO op_fldz_ST0(void)
|
||||
|
||||
void OPPROTO op_fldz_FT0(void)
|
||||
{
|
||||
ST0 = f15rk[0];
|
||||
FT0 = f15rk[0];
|
||||
}
|
||||
|
||||
/* associated heplers to reduce generated code length and to simplify
|
||||
|
@@ -83,12 +83,14 @@ void OPPROTO glue(glue(op_cmovw,REGNAME),_T1_T0)(void)
|
||||
{
|
||||
if (T0)
|
||||
REG = (REG & 0xffff0000) | (T1 & 0xffff);
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO glue(glue(op_cmovl,REGNAME),_T1_T0)(void)
|
||||
{
|
||||
if (T0)
|
||||
REG = T1;
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
/* NOTE: T0 high order bits are ignored */
|
||||
|
@@ -229,6 +229,29 @@ static int glue(compute_all_sar, SUFFIX)(void)
|
||||
return cf | pf | af | zf | sf | of;
|
||||
}
|
||||
|
||||
#if DATA_BITS == 32
|
||||
static int glue(compute_c_mul, SUFFIX)(void)
|
||||
{
|
||||
int cf;
|
||||
cf = (CC_SRC != 0);
|
||||
return cf;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* NOTE: we compute the flags like the P4. On olders CPUs, only OF and
|
||||
CF are modified and it is slower to do that. */
|
||||
static int glue(compute_all_mul, SUFFIX)(void)
|
||||
{
|
||||
int cf, pf, af, zf, sf, of;
|
||||
cf = (CC_SRC != 0);
|
||||
pf = parity_table[(uint8_t)CC_DST];
|
||||
af = 0; /* undefined */
|
||||
zf = ((DATA_TYPE)CC_DST == 0) << 6;
|
||||
sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
|
||||
of = cf << 11;
|
||||
return cf | pf | af | zf | sf | of;
|
||||
}
|
||||
|
||||
/* various optimized jumps cases */
|
||||
|
||||
void OPPROTO glue(op_jb_sub, SUFFIX)(void)
|
||||
@@ -608,6 +631,16 @@ void OPPROTO glue(glue(op_out, SUFFIX), _DX_T0)(void)
|
||||
glue(cpu_x86_out, SUFFIX)(env, EDX & 0xffff, T0);
|
||||
}
|
||||
|
||||
void OPPROTO glue(glue(op_check_io, SUFFIX), _T0)(void)
|
||||
{
|
||||
glue(glue(check_io, SUFFIX), _T0)();
|
||||
}
|
||||
|
||||
void OPPROTO glue(glue(op_check_io, SUFFIX), _DX)(void)
|
||||
{
|
||||
glue(glue(check_io, SUFFIX), _DX)();
|
||||
}
|
||||
|
||||
#undef DATA_BITS
|
||||
#undef SHIFT_MASK
|
||||
#undef SIGN_MASK
|
||||
|
@@ -749,6 +749,43 @@ static GenOpFunc *gen_op_out_DX_T0[3] = {
|
||||
gen_op_outl_DX_T0,
|
||||
};
|
||||
|
||||
static GenOpFunc *gen_op_in[3] = {
|
||||
gen_op_inb_T0_T1,
|
||||
gen_op_inw_T0_T1,
|
||||
gen_op_inl_T0_T1,
|
||||
};
|
||||
|
||||
static GenOpFunc *gen_op_out[3] = {
|
||||
gen_op_outb_T0_T1,
|
||||
gen_op_outw_T0_T1,
|
||||
gen_op_outl_T0_T1,
|
||||
};
|
||||
|
||||
static GenOpFunc *gen_check_io_T0[3] = {
|
||||
gen_op_check_iob_T0,
|
||||
gen_op_check_iow_T0,
|
||||
gen_op_check_iol_T0,
|
||||
};
|
||||
|
||||
static GenOpFunc *gen_check_io_DX[3] = {
|
||||
gen_op_check_iob_DX,
|
||||
gen_op_check_iow_DX,
|
||||
gen_op_check_iol_DX,
|
||||
};
|
||||
|
||||
static void gen_check_io(DisasContext *s, int ot, int use_dx, int cur_eip)
|
||||
{
|
||||
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
||||
if (s->cc_op != CC_OP_DYNAMIC)
|
||||
gen_op_set_cc_op(s->cc_op);
|
||||
gen_op_jmp_im(cur_eip);
|
||||
if (use_dx)
|
||||
gen_check_io_DX[ot]();
|
||||
else
|
||||
gen_check_io_T0[ot]();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void gen_movs(DisasContext *s, int ot)
|
||||
{
|
||||
gen_string_movl_A0_ESI(s);
|
||||
@@ -912,18 +949,6 @@ GEN_REPZ(outs)
|
||||
GEN_REPZ2(scas)
|
||||
GEN_REPZ2(cmps)
|
||||
|
||||
static GenOpFunc *gen_op_in[3] = {
|
||||
gen_op_inb_T0_T1,
|
||||
gen_op_inw_T0_T1,
|
||||
gen_op_inl_T0_T1,
|
||||
};
|
||||
|
||||
static GenOpFunc *gen_op_out[3] = {
|
||||
gen_op_outb_T0_T1,
|
||||
gen_op_outw_T0_T1,
|
||||
gen_op_outl_T0_T1,
|
||||
};
|
||||
|
||||
enum {
|
||||
JCC_O,
|
||||
JCC_B,
|
||||
@@ -1513,10 +1538,15 @@ static void gen_setcc(DisasContext *s, int b)
|
||||
call this function with seg_reg == R_CS */
|
||||
static void gen_movl_seg_T0(DisasContext *s, int seg_reg, unsigned int cur_eip)
|
||||
{
|
||||
if (s->pe && !s->vm86)
|
||||
gen_op_movl_seg_T0(seg_reg, cur_eip);
|
||||
else
|
||||
if (s->pe && !s->vm86) {
|
||||
/* XXX: optimize by finding processor state dynamically */
|
||||
if (s->cc_op != CC_OP_DYNAMIC)
|
||||
gen_op_set_cc_op(s->cc_op);
|
||||
gen_op_jmp_im(cur_eip);
|
||||
gen_op_movl_seg_T0(seg_reg);
|
||||
} else {
|
||||
gen_op_movl_seg_T0_vm(offsetof(CPUX86State,segs[seg_reg]));
|
||||
}
|
||||
/* abort translation because the register may have a non zero base
|
||||
or because ss32 may change. For R_SS, translation must always
|
||||
stop as a special handling must be done to disable hardware
|
||||
@@ -1722,6 +1752,9 @@ static void gen_eob(DisasContext *s)
|
||||
{
|
||||
if (s->cc_op != CC_OP_DYNAMIC)
|
||||
gen_op_set_cc_op(s->cc_op);
|
||||
if (s->tb->flags & HF_INHIBIT_IRQ_MASK) {
|
||||
gen_op_reset_inhibit_irq();
|
||||
}
|
||||
if (s->singlestep_enabled) {
|
||||
gen_op_debug();
|
||||
} else if (s->tf) {
|
||||
@@ -1988,31 +2021,35 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
switch(ot) {
|
||||
case OT_BYTE:
|
||||
gen_op_mulb_AL_T0();
|
||||
s->cc_op = CC_OP_MULB;
|
||||
break;
|
||||
case OT_WORD:
|
||||
gen_op_mulw_AX_T0();
|
||||
s->cc_op = CC_OP_MULW;
|
||||
break;
|
||||
default:
|
||||
case OT_LONG:
|
||||
gen_op_mull_EAX_T0();
|
||||
s->cc_op = CC_OP_MULL;
|
||||
break;
|
||||
}
|
||||
s->cc_op = CC_OP_MUL;
|
||||
break;
|
||||
case 5: /* imul */
|
||||
switch(ot) {
|
||||
case OT_BYTE:
|
||||
gen_op_imulb_AL_T0();
|
||||
s->cc_op = CC_OP_MULB;
|
||||
break;
|
||||
case OT_WORD:
|
||||
gen_op_imulw_AX_T0();
|
||||
s->cc_op = CC_OP_MULW;
|
||||
break;
|
||||
default:
|
||||
case OT_LONG:
|
||||
gen_op_imull_EAX_T0();
|
||||
s->cc_op = CC_OP_MULL;
|
||||
break;
|
||||
}
|
||||
s->cc_op = CC_OP_MUL;
|
||||
break;
|
||||
case 6: /* div */
|
||||
switch(ot) {
|
||||
@@ -2207,7 +2244,7 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_op_imulw_T0_T1();
|
||||
}
|
||||
gen_op_mov_reg_T0[ot][reg]();
|
||||
s->cc_op = CC_OP_MUL;
|
||||
s->cc_op = CC_OP_MULB + ot;
|
||||
break;
|
||||
case 0x1c0:
|
||||
case 0x1c1: /* xadd Ev, Gv */
|
||||
@@ -2279,8 +2316,9 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
case 0x58 ... 0x5f: /* pop */
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
gen_pop_T0(s);
|
||||
gen_op_mov_reg_T0[ot][b & 7]();
|
||||
/* NOTE: order is important for pop %sp */
|
||||
gen_pop_update(s);
|
||||
gen_op_mov_reg_T0[ot][b & 7]();
|
||||
break;
|
||||
case 0x60: /* pusha */
|
||||
gen_pusha(s);
|
||||
@@ -2301,11 +2339,20 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
case 0x8f: /* pop Ev */
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
modrm = ldub_code(s->pc++);
|
||||
mod = (modrm >> 6) & 3;
|
||||
gen_pop_T0(s);
|
||||
s->popl_esp_hack = 2 << dflag;
|
||||
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
||||
s->popl_esp_hack = 0;
|
||||
gen_pop_update(s);
|
||||
if (mod == 3) {
|
||||
/* NOTE: order is important for pop %sp */
|
||||
gen_pop_update(s);
|
||||
rm = modrm & 7;
|
||||
gen_op_mov_reg_T0[ot][rm]();
|
||||
} else {
|
||||
/* NOTE: order is important too for MMU exceptions */
|
||||
s->popl_esp_hack = 2 << dflag;
|
||||
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
||||
s->popl_esp_hack = 0;
|
||||
gen_pop_update(s);
|
||||
}
|
||||
break;
|
||||
case 0xc8: /* enter */
|
||||
{
|
||||
@@ -2350,8 +2397,11 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_movl_seg_T0(s, reg, pc_start - s->cs_base);
|
||||
gen_pop_update(s);
|
||||
if (reg == R_SS) {
|
||||
/* if reg == SS, inhibit interrupts/trace */
|
||||
gen_op_set_inhibit_irq();
|
||||
/* if reg == SS, inhibit interrupts/trace. */
|
||||
/* If several instructions disable interrupts, only the
|
||||
_first_ does it */
|
||||
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
||||
gen_op_set_inhibit_irq();
|
||||
s->tf = 0;
|
||||
}
|
||||
if (s->is_jmp) {
|
||||
@@ -2422,7 +2472,10 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_movl_seg_T0(s, reg, pc_start - s->cs_base);
|
||||
if (reg == R_SS) {
|
||||
/* if reg == SS, inhibit interrupts/trace */
|
||||
gen_op_set_inhibit_irq();
|
||||
/* If several instructions disable interrupts, only the
|
||||
_first_ does it */
|
||||
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
||||
gen_op_set_inhibit_irq();
|
||||
s->tf = 0;
|
||||
}
|
||||
if (s->is_jmp) {
|
||||
@@ -3141,6 +3194,21 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_op_fpop();
|
||||
s->cc_op = CC_OP_EFLAGS;
|
||||
break;
|
||||
case 0x10 ... 0x13: /* fcmovxx */
|
||||
case 0x18 ... 0x1b:
|
||||
{
|
||||
int op1;
|
||||
const static uint8_t fcmov_cc[8] = {
|
||||
(JCC_B << 1),
|
||||
(JCC_Z << 1),
|
||||
(JCC_BE << 1),
|
||||
(JCC_P << 1),
|
||||
};
|
||||
op1 = fcmov_cc[op & 3] | ((op >> 3) & 1);
|
||||
gen_setcc(s, op1);
|
||||
gen_op_fcmov_ST0_STN_T0(opreg);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto illegal_op;
|
||||
}
|
||||
@@ -3221,36 +3289,28 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
break;
|
||||
case 0x6c: /* insS */
|
||||
case 0x6d:
|
||||
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
||||
/* NOTE: even for (E)CX = 0 the exception is raised */
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
gen_check_io(s, ot, 1, pc_start - s->cs_base);
|
||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||
gen_repz_ins(s, ot, pc_start - s->cs_base, s->pc - s->cs_base);
|
||||
} else {
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||
gen_repz_ins(s, ot, pc_start - s->cs_base, s->pc - s->cs_base);
|
||||
} else {
|
||||
gen_ins(s, ot);
|
||||
}
|
||||
gen_ins(s, ot);
|
||||
}
|
||||
break;
|
||||
case 0x6e: /* outsS */
|
||||
case 0x6f:
|
||||
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
||||
/* NOTE: even for (E)CX = 0 the exception is raised */
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
gen_check_io(s, ot, 1, pc_start - s->cs_base);
|
||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||
gen_repz_outs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base);
|
||||
} else {
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
||||
gen_repz_outs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base);
|
||||
} else {
|
||||
gen_outs(s, ot);
|
||||
}
|
||||
gen_outs(s, ot);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -3258,61 +3318,49 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
/* port I/O */
|
||||
case 0xe4:
|
||||
case 0xe5:
|
||||
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
val = ldub_code(s->pc++);
|
||||
gen_op_movl_T0_im(val);
|
||||
gen_op_in[ot]();
|
||||
gen_op_mov_reg_T1[ot][R_EAX]();
|
||||
}
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
val = ldub_code(s->pc++);
|
||||
gen_op_movl_T0_im(val);
|
||||
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
||||
gen_op_in[ot]();
|
||||
gen_op_mov_reg_T1[ot][R_EAX]();
|
||||
break;
|
||||
case 0xe6:
|
||||
case 0xe7:
|
||||
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
val = ldub_code(s->pc++);
|
||||
gen_op_movl_T0_im(val);
|
||||
gen_op_mov_TN_reg[ot][1][R_EAX]();
|
||||
gen_op_out[ot]();
|
||||
}
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
val = ldub_code(s->pc++);
|
||||
gen_op_movl_T0_im(val);
|
||||
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
||||
gen_op_mov_TN_reg[ot][1][R_EAX]();
|
||||
gen_op_out[ot]();
|
||||
break;
|
||||
case 0xec:
|
||||
case 0xed:
|
||||
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
gen_op_mov_TN_reg[OT_WORD][0][R_EDX]();
|
||||
gen_op_in[ot]();
|
||||
gen_op_mov_reg_T1[ot][R_EAX]();
|
||||
}
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
gen_op_mov_TN_reg[OT_WORD][0][R_EDX]();
|
||||
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
||||
gen_op_in[ot]();
|
||||
gen_op_mov_reg_T1[ot][R_EAX]();
|
||||
break;
|
||||
case 0xee:
|
||||
case 0xef:
|
||||
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
gen_op_mov_TN_reg[OT_WORD][0][R_EDX]();
|
||||
gen_op_mov_TN_reg[ot][1][R_EAX]();
|
||||
gen_op_out[ot]();
|
||||
}
|
||||
if ((b & 1) == 0)
|
||||
ot = OT_BYTE;
|
||||
else
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
gen_op_mov_TN_reg[OT_WORD][0][R_EDX]();
|
||||
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
||||
gen_op_mov_TN_reg[ot][1][R_EAX]();
|
||||
gen_op_out[ot]();
|
||||
break;
|
||||
|
||||
/************************/
|
||||
@@ -3370,8 +3418,13 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
/* real mode */
|
||||
gen_op_iret_real(s->dflag);
|
||||
s->cc_op = CC_OP_EFLAGS;
|
||||
} else if (s->vm86 && s->iopl != 3) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else if (s->vm86) {
|
||||
if (s->iopl != 3) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
gen_op_iret_real(s->dflag);
|
||||
s->cc_op = CC_OP_EFLAGS;
|
||||
}
|
||||
} else {
|
||||
if (s->cc_op != CC_OP_DYNAMIC)
|
||||
gen_op_set_cc_op(s->cc_op);
|
||||
@@ -3496,10 +3549,18 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_op_movw_eflags_T0_cpl0();
|
||||
}
|
||||
} else {
|
||||
if (s->dflag) {
|
||||
gen_op_movl_eflags_T0();
|
||||
if (s->cpl <= s->iopl) {
|
||||
if (s->dflag) {
|
||||
gen_op_movl_eflags_T0_io();
|
||||
} else {
|
||||
gen_op_movw_eflags_T0_io();
|
||||
}
|
||||
} else {
|
||||
gen_op_movw_eflags_T0();
|
||||
if (s->dflag) {
|
||||
gen_op_movl_eflags_T0();
|
||||
} else {
|
||||
gen_op_movw_eflags_T0();
|
||||
}
|
||||
}
|
||||
}
|
||||
gen_pop_update(s);
|
||||
@@ -3675,11 +3736,11 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
break;
|
||||
case 0xcd: /* int N */
|
||||
val = ldub_code(s->pc++);
|
||||
/* XXX: add error code for vm86 GPF */
|
||||
if (!s->vm86)
|
||||
gen_interrupt(s, val, pc_start - s->cs_base, s->pc - s->cs_base);
|
||||
else
|
||||
if (s->vm86 && s->iopl != 3) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
gen_interrupt(s, val, pc_start - s->cs_base, s->pc - s->cs_base);
|
||||
}
|
||||
break;
|
||||
case 0xce: /* into */
|
||||
if (s->cc_op != CC_OP_DYNAMIC)
|
||||
@@ -3710,7 +3771,10 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_sti:
|
||||
gen_op_sti();
|
||||
/* interruptions are enabled only the first insn after sti */
|
||||
gen_op_set_inhibit_irq();
|
||||
/* If several instructions disable interrupts, only the
|
||||
_first_ does it */
|
||||
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
||||
gen_op_set_inhibit_irq();
|
||||
/* give a chance to handle pending irqs */
|
||||
gen_op_jmp_im(s->pc - s->cs_base);
|
||||
gen_eob(s);
|
||||
@@ -3799,6 +3863,8 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
op = (modrm >> 3) & 7;
|
||||
switch(op) {
|
||||
case 0: /* sldt */
|
||||
if (!s->pe || s->vm86)
|
||||
goto illegal_op;
|
||||
gen_op_movl_T0_env(offsetof(CPUX86State,ldt.selector));
|
||||
ot = OT_WORD;
|
||||
if (mod == 3)
|
||||
@@ -3806,6 +3872,8 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
||||
break;
|
||||
case 2: /* lldt */
|
||||
if (!s->pe || s->vm86)
|
||||
goto illegal_op;
|
||||
if (s->cpl != 0) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
@@ -3815,6 +3883,8 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
}
|
||||
break;
|
||||
case 1: /* str */
|
||||
if (!s->pe || s->vm86)
|
||||
goto illegal_op;
|
||||
gen_op_movl_T0_env(offsetof(CPUX86State,tr.selector));
|
||||
ot = OT_WORD;
|
||||
if (mod == 3)
|
||||
@@ -3822,6 +3892,8 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
||||
break;
|
||||
case 3: /* ltr */
|
||||
if (!s->pe || s->vm86)
|
||||
goto illegal_op;
|
||||
if (s->cpl != 0) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
@@ -3832,6 +3904,17 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
break;
|
||||
case 4: /* verr */
|
||||
case 5: /* verw */
|
||||
if (!s->pe || s->vm86)
|
||||
goto illegal_op;
|
||||
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
||||
if (s->cc_op != CC_OP_DYNAMIC)
|
||||
gen_op_set_cc_op(s->cc_op);
|
||||
if (op == 4)
|
||||
gen_op_verr();
|
||||
else
|
||||
gen_op_verw();
|
||||
s->cc_op = CC_OP_EFLAGS;
|
||||
break;
|
||||
default:
|
||||
goto illegal_op;
|
||||
}
|
||||
@@ -3892,6 +3975,8 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
} else {
|
||||
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
||||
gen_op_lmsw_T0();
|
||||
gen_op_jmp_im(s->pc - s->cs_base);
|
||||
gen_eob(s);
|
||||
}
|
||||
break;
|
||||
case 7: /* invlpg */
|
||||
@@ -3902,12 +3987,47 @@ static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
||||
goto illegal_op;
|
||||
gen_lea_modrm(s, modrm, ®_addr, &offset_addr);
|
||||
gen_op_invlpg_A0();
|
||||
gen_op_jmp_im(s->pc - s->cs_base);
|
||||
gen_eob(s);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto illegal_op;
|
||||
}
|
||||
break;
|
||||
case 0x108: /* invd */
|
||||
case 0x109: /* wbinvd */
|
||||
if (s->cpl != 0) {
|
||||
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base);
|
||||
} else {
|
||||
/* nothing to do */
|
||||
}
|
||||
break;
|
||||
case 0x63: /* arpl */
|
||||
if (!s->pe || s->vm86)
|
||||
goto illegal_op;
|
||||
ot = dflag ? OT_LONG : OT_WORD;
|
||||
modrm = ldub_code(s->pc++);
|
||||
reg = (modrm >> 3) & 7;
|
||||
mod = (modrm >> 6) & 3;
|
||||
rm = modrm & 7;
|
||||
if (mod != 3) {
|
||||
gen_lea_modrm(s, modrm, ®_addr, &offset_addr);
|
||||
gen_op_ld_T0_A0[ot + s->mem_index]();
|
||||
} else {
|
||||
gen_op_mov_TN_reg[ot][0][rm]();
|
||||
}
|
||||
if (s->cc_op != CC_OP_DYNAMIC)
|
||||
gen_op_set_cc_op(s->cc_op);
|
||||
gen_op_arpl();
|
||||
s->cc_op = CC_OP_EFLAGS;
|
||||
if (mod != 3) {
|
||||
gen_op_st_T0_A0[ot + s->mem_index]();
|
||||
} else {
|
||||
gen_op_mov_reg_T0[ot][rm]();
|
||||
}
|
||||
gen_op_arpl_update();
|
||||
break;
|
||||
case 0x102: /* lar */
|
||||
case 0x103: /* lsl */
|
||||
if (!s->pe || s->vm86)
|
||||
@@ -4172,6 +4292,10 @@ static uint16_t opc_write_flags[NB_OPS] = {
|
||||
[INDEX_op_movb_eflags_T0] = CC_S | CC_Z | CC_A | CC_P | CC_C,
|
||||
[INDEX_op_movw_eflags_T0] = CC_OSZAPC,
|
||||
[INDEX_op_movl_eflags_T0] = CC_OSZAPC,
|
||||
[INDEX_op_movw_eflags_T0_io] = CC_OSZAPC,
|
||||
[INDEX_op_movl_eflags_T0_io] = CC_OSZAPC,
|
||||
[INDEX_op_movw_eflags_T0_cpl0] = CC_OSZAPC,
|
||||
[INDEX_op_movl_eflags_T0_cpl0] = CC_OSZAPC,
|
||||
[INDEX_op_clc] = CC_C,
|
||||
[INDEX_op_stc] = CC_C,
|
||||
[INDEX_op_cmc] = CC_C,
|
||||
@@ -4393,8 +4517,9 @@ static inline int gen_intermediate_code_internal(CPUState *env,
|
||||
else
|
||||
dc->mem_index = 3;
|
||||
}
|
||||
dc->jmp_opt = !(dc->tf || env->singlestep_enabled
|
||||
#ifndef CONFIG_SOFT_MMU
|
||||
dc->jmp_opt = !(dc->tf || env->singlestep_enabled ||
|
||||
(flags & HF_INHIBIT_IRQ_MASK)
|
||||
#ifndef CONFIG_SOFTMMU
|
||||
|| (flags & HF_SOFTMMU_MASK)
|
||||
#endif
|
||||
);
|
||||
@@ -4406,12 +4531,6 @@ static inline int gen_intermediate_code_internal(CPUState *env,
|
||||
pc_ptr = pc_start;
|
||||
lj = -1;
|
||||
|
||||
/* if irq were inhibited for the next instruction, we can disable
|
||||
them here as it is simpler (otherwise jumps would have to
|
||||
handled as special case) */
|
||||
if (flags & HF_INHIBIT_IRQ_MASK) {
|
||||
gen_op_reset_inhibit_irq();
|
||||
}
|
||||
for(;;) {
|
||||
if (env->nb_breakpoints > 0) {
|
||||
for(j = 0; j < env->nb_breakpoints; j++) {
|
||||
@@ -4438,7 +4557,11 @@ static inline int gen_intermediate_code_internal(CPUState *env,
|
||||
break;
|
||||
/* if single step mode, we generate only one instruction and
|
||||
generate an exception */
|
||||
if (dc->tf || dc->singlestep_enabled) {
|
||||
/* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
|
||||
the flag and abort the translation to give the irqs a
|
||||
change to be happen */
|
||||
if (dc->tf || dc->singlestep_enabled ||
|
||||
(flags & HF_INHIBIT_IRQ_MASK)) {
|
||||
gen_op_jmp_im(pc_ptr - dc->cs_base);
|
||||
gen_eob(dc);
|
||||
break;
|
||||
|
380
target-ppc/cpu.h
Normal file
380
target-ppc/cpu.h
Normal file
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
* PPC emulation cpu definitions for qemu.
|
||||
*
|
||||
* Copyright (c) 2003 Jocelyn Mayer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#if !defined (__CPU_PPC_H__)
|
||||
#define __CPU_PPC_H__
|
||||
|
||||
#include <endian.h>
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
#include "cpu-defs.h"
|
||||
|
||||
/*** Sign extend constants ***/
|
||||
/* 8 to 32 bits */
|
||||
static inline int32_t s_ext8 (uint8_t value)
|
||||
{
|
||||
int8_t *tmp = &value;
|
||||
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
/* 16 to 32 bits */
|
||||
static inline int32_t s_ext16 (uint16_t value)
|
||||
{
|
||||
int16_t *tmp = &value;
|
||||
|
||||
return *tmp;
|
||||
}
|
||||
|
||||
/* 24 to 32 bits */
|
||||
static inline int32_t s_ext24 (uint32_t value)
|
||||
{
|
||||
uint16_t utmp = (value >> 8) & 0xFFFF;
|
||||
int16_t *tmp = &utmp;
|
||||
|
||||
return (*tmp << 8) | (value & 0xFF);
|
||||
}
|
||||
|
||||
#include "config.h"
|
||||
#include <setjmp.h>
|
||||
|
||||
/* Floting point status and control register */
|
||||
#define FPSCR_FX 31
|
||||
#define FPSCR_FEX 30
|
||||
#define FPSCR_VX 29
|
||||
#define FPSCR_OX 28
|
||||
#define FPSCR_UX 27
|
||||
#define FPSCR_ZX 26
|
||||
#define FPSCR_XX 25
|
||||
#define FPSCR_VXSNAN 24
|
||||
#define FPSCR_VXISI 26
|
||||
#define FPSCR_VXIDI 25
|
||||
#define FPSCR_VXZDZ 21
|
||||
#define FPSCR_VXIMZ 20
|
||||
|
||||
#define FPSCR_VXVC 18
|
||||
#define FPSCR_FR 17
|
||||
#define FPSCR_FI 16
|
||||
#define FPSCR_FPRF 11
|
||||
#define FPSCR_VXSOFT 9
|
||||
#define FPSCR_VXSQRT 8
|
||||
#define FPSCR_VXCVI 7
|
||||
#define FPSCR_OE 6
|
||||
#define FPSCR_UE 5
|
||||
#define FPSCR_ZE 4
|
||||
#define FPSCR_XE 3
|
||||
#define FPSCR_NI 2
|
||||
#define FPSCR_RN 0
|
||||
#define fpscr_fx env->fpscr[FPSCR_FX]
|
||||
#define fpscr_fex env->fpscr[FPSCR_FEX]
|
||||
#define fpscr_vx env->fpscr[FPSCR_VX]
|
||||
#define fpscr_ox env->fpscr[FPSCR_OX]
|
||||
#define fpscr_ux env->fpscr[FPSCR_UX]
|
||||
#define fpscr_zx env->fpscr[FPSCR_ZX]
|
||||
#define fpscr_xx env->fpscr[FPSCR_XX]
|
||||
#define fpscr_vsxnan env->fpscr[FPSCR_VXSNAN]
|
||||
#define fpscr_vxisi env->fpscr[FPSCR_VXISI]
|
||||
#define fpscr_vxidi env->fpscr[FPSCR_VXIDI]
|
||||
#define fpscr_vxzdz env->fpscr[FPSCR_VXZDZ]
|
||||
#define fpscr_vximz env->fpscr[FPSCR_VXIMZ]
|
||||
#define fpscr_fr env->fpscr[FPSCR_FR]
|
||||
#define fpscr_fi env->fpscr[FPSCR_FI]
|
||||
#define fpscr_fprf env->fpscr[FPSCR_FPRF]
|
||||
#define fpscr_vxsoft env->fpscr[FPSCR_VXSOFT]
|
||||
#define fpscr_vxsqrt env->fpscr[FPSCR_VXSQRT]
|
||||
#define fpscr_oe env->fpscr[FPSCR_OE]
|
||||
#define fpscr_ue env->fpscr[FPSCR_UE]
|
||||
#define fpscr_ze env->fpscr[FPSCR_ZE]
|
||||
#define fpscr_xe env->fpscr[FPSCR_XE]
|
||||
#define fpscr_ni env->fpscr[FPSCR_NI]
|
||||
#define fpscr_rn env->fpscr[FPSCR_RN]
|
||||
|
||||
/* Supervisor mode registers */
|
||||
/* Machine state register */
|
||||
#define MSR_POW 18
|
||||
#define MSR_ILE 16
|
||||
#define MSR_EE 15
|
||||
#define MSR_PR 14
|
||||
#define MSR_FP 13
|
||||
#define MSR_ME 12
|
||||
#define MSR_FE0 11
|
||||
#define MSR_SE 10
|
||||
#define MSR_BE 9
|
||||
#define MSR_FE1 8
|
||||
#define MSR_IP 6
|
||||
#define MSR_IR 5
|
||||
#define MSR_DR 4
|
||||
#define MSR_RI 1
|
||||
#define MSR_LE 0
|
||||
#define msr_pow env->msr[MSR_POW]
|
||||
#define msr_ile env->msr[MSR_ILE]
|
||||
#define msr_ee env->msr[MSR_EE]
|
||||
#define msr_pr env->msr[MSR_PR]
|
||||
#define msr_fp env->msr[MSR_FP]
|
||||
#define msr_me env->msr[MSR_ME]
|
||||
#define msr_fe0 env->msr[MSR_FE0]
|
||||
#define msr_se env->msr[MSR_SE]
|
||||
#define msr_be env->msr[MSR_BE]
|
||||
#define msr_fe1 env->msr[MSR_FE1]
|
||||
#define msr_ip env->msr[MSR_IP]
|
||||
#define msr_ir env->msr[MSR_IR]
|
||||
#define msr_dr env->msr[MSR_DR]
|
||||
#define msr_ri env->msr[MSR_RI]
|
||||
#define msr_le env->msr[MSR_LE]
|
||||
|
||||
/* Segment registers */
|
||||
typedef struct ppc_sr_t {
|
||||
uint32_t t:1;
|
||||
uint32_t ks:1;
|
||||
uint32_t kp:1;
|
||||
uint32_t n:1;
|
||||
uint32_t res:4;
|
||||
uint32_t vsid:24;
|
||||
} ppc_sr_t;
|
||||
|
||||
typedef struct CPUPPCState {
|
||||
/* general purpose registers */
|
||||
uint32_t gpr[32];
|
||||
/* floating point registers */
|
||||
double fpr[32];
|
||||
/* segment registers */
|
||||
ppc_sr_t sr[16];
|
||||
/* special purpose registers */
|
||||
uint32_t spr[1024];
|
||||
/* XER */
|
||||
uint8_t xer[32];
|
||||
/* Reservation address */
|
||||
uint32_t reserve;
|
||||
/* machine state register */
|
||||
uint8_t msr[32];
|
||||
/* condition register */
|
||||
uint8_t crf[8];
|
||||
/* floating point status and control register */
|
||||
uint8_t fpscr[32];
|
||||
uint32_t nip;
|
||||
/* CPU exception code */
|
||||
uint32_t exception;
|
||||
|
||||
/* qemu dedicated */
|
||||
/* temporary float registers */
|
||||
double ft0;
|
||||
double ft1;
|
||||
double ft2;
|
||||
int interrupt_request;
|
||||
jmp_buf jmp_env;
|
||||
int exception_index;
|
||||
int error_code;
|
||||
int user_mode_only; /* user mode only simulation */
|
||||
struct TranslationBlock *current_tb; /* currently executing TB */
|
||||
|
||||
/* user data */
|
||||
void *opaque;
|
||||
} CPUPPCState;
|
||||
|
||||
CPUPPCState *cpu_ppc_init(void);
|
||||
int cpu_ppc_exec(CPUPPCState *s);
|
||||
void cpu_ppc_close(CPUPPCState *s);
|
||||
/* you can call this signal handler from your SIGBUS and SIGSEGV
|
||||
signal handlers to inform the virtual CPU of exceptions. non zero
|
||||
is returned if the signal was handled by the virtual CPU. */
|
||||
struct siginfo;
|
||||
int cpu_ppc_signal_handler(int host_signum, struct siginfo *info,
|
||||
void *puc);
|
||||
|
||||
void cpu_ppc_dump_state(CPUPPCState *env, FILE *f, int flags);
|
||||
|
||||
#define TARGET_PAGE_BITS 12
|
||||
#include "cpu-all.h"
|
||||
|
||||
#define ugpr(n) (env->gpr[n])
|
||||
#define fpr(n) (env->fpr[n])
|
||||
|
||||
#define SPR_ENCODE(sprn) \
|
||||
(((sprn) >> 5) | (((sprn) & 0x1F) << 5))
|
||||
|
||||
/* User mode SPR */
|
||||
#define spr(n) env->spr[n]
|
||||
//#define XER spr[1]
|
||||
#define XER env->xer
|
||||
#define XER_SO 31
|
||||
#define XER_OV 30
|
||||
#define XER_CA 29
|
||||
#define XER_BC 0
|
||||
#define xer_so env->xer[XER_SO]
|
||||
#define xer_ov env->xer[XER_OV]
|
||||
#define xer_ca env->xer[XER_CA]
|
||||
#define xer_bc env->xer[XER_BC]
|
||||
|
||||
#define LR spr[SPR_ENCODE(8)]
|
||||
#define CTR spr[SPR_ENCODE(9)]
|
||||
/* VEA mode SPR */
|
||||
#define V_TBL spr[SPR_ENCODE(268)]
|
||||
#define V_TBU spr[SPR_ENCODE(269)]
|
||||
/* supervisor mode SPR */
|
||||
#define DSISR spr[SPR_ENCODE(18)]
|
||||
#define DAR spr[SPR_ENCODE(19)]
|
||||
#define DEC spr[SPR_ENCODE(22)]
|
||||
#define SDR1 spr[SPR_ENCODE(25)]
|
||||
typedef struct ppc_sdr1_t {
|
||||
uint32_t htaborg:16;
|
||||
uint32_t res:7;
|
||||
uint32_t htabmask:9;
|
||||
} ppc_sdr1_t;
|
||||
#define SRR0 spr[SPR_ENCODE(26)]
|
||||
#define SRR0_MASK 0xFFFFFFFC
|
||||
#define SRR1 spr[SPR_ENCODE(27)]
|
||||
#define SPRG0 spr[SPR_ENCODE(272)]
|
||||
#define SPRG1 spr[SPR_ENCODE(273)]
|
||||
#define SPRG2 spr[SPR_ENCODE(274)]
|
||||
#define SPRG3 spr[SPR_ENCODE(275)]
|
||||
#define EAR spr[SPR_ENCODE(282)]
|
||||
typedef struct ppc_ear_t {
|
||||
uint32_t e:1;
|
||||
uint32_t res:25;
|
||||
uint32_t rid:6;
|
||||
} ppc_ear_t;
|
||||
#define TBL spr[SPR_ENCODE(284)]
|
||||
#define TBU spr[SPR_ENCODE(285)]
|
||||
#define PVR spr[SPR_ENCODE(287)]
|
||||
typedef struct ppc_pvr_t {
|
||||
uint32_t version:16;
|
||||
uint32_t revision:16;
|
||||
} ppc_pvr_t;
|
||||
#define IBAT0U spr[SPR_ENCODE(528)]
|
||||
#define IBAT0L spr[SPR_ENCODE(529)]
|
||||
#define IBAT1U spr[SPR_ENCODE(530)]
|
||||
#define IBAT1L spr[SPR_ENCODE(531)]
|
||||
#define IBAT2U spr[SPR_ENCODE(532)]
|
||||
#define IBAT2L spr[SPR_ENCODE(533)]
|
||||
#define IBAT3U spr[SPR_ENCODE(534)]
|
||||
#define IBAT3L spr[SPR_ENCODE(535)]
|
||||
#define DBAT0U spr[SPR_ENCODE(536)]
|
||||
#define DBAT0L spr[SPR_ENCODE(537)]
|
||||
#define DBAT1U spr[SPR_ENCODE(538)]
|
||||
#define DBAT1L spr[SPR_ENCODE(539)]
|
||||
#define DBAT2U spr[SPR_ENCODE(540)]
|
||||
#define DBAT2L spr[SPR_ENCODE(541)]
|
||||
#define DBAT3U spr[SPR_ENCODE(542)]
|
||||
#define DBAT3L spr[SPR_ENCODE(543)]
|
||||
typedef struct ppc_ubat_t {
|
||||
uint32_t bepi:15;
|
||||
uint32_t res:4;
|
||||
uint32_t bl:11;
|
||||
uint32_t vs:1;
|
||||
uint32_t vp:1;
|
||||
} ppc_ubat_t;
|
||||
typedef struct ppc_lbat_t {
|
||||
uint32_t brpn:15;
|
||||
uint32_t res0:10;
|
||||
uint32_t w:1;
|
||||
uint32_t i:1;
|
||||
uint32_t m:1;
|
||||
uint32_t g:1;
|
||||
uint32_t res1:1;
|
||||
uint32_t pp:2;
|
||||
} ppc_lbat_t;
|
||||
#define DABR spr[SPR_ENCODE(1013)]
|
||||
#define DABR_MASK 0xFFFFFFF8
|
||||
typedef struct ppc_dabr_t {
|
||||
uint32_t dab:29;
|
||||
uint32_t bt:1;
|
||||
uint32_t dw:1;
|
||||
uint32_t dr:1;
|
||||
} ppc_dabr_t;
|
||||
#define FPECR spr[SPR_ENCODE(1022)]
|
||||
#define PIR spr[SPR_ENCODE(1023)]
|
||||
|
||||
#define TARGET_PAGE_BITS 12
|
||||
#include "cpu-all.h"
|
||||
|
||||
CPUPPCState *cpu_ppc_init(void);
|
||||
int cpu_ppc_exec(CPUPPCState *s);
|
||||
void cpu_ppc_close(CPUPPCState *s);
|
||||
void cpu_ppc_dump_state(CPUPPCState *env, FILE *f, int flags);
|
||||
|
||||
/* Exeptions */
|
||||
enum {
|
||||
EXCP_NONE = 0x00,
|
||||
/* PPC hardware exceptions : exception vector / 0x100 */
|
||||
EXCP_RESET = 0x01, /* System reset */
|
||||
EXCP_MACHINE_CHECK = 0x02, /* Machine check exception */
|
||||
EXCP_DSI = 0x03, /* Impossible memory access */
|
||||
EXCP_ISI = 0x04, /* Impossible instruction fetch */
|
||||
EXCP_EXTERNAL = 0x05, /* External interruption */
|
||||
EXCP_ALIGN = 0x06, /* Alignment exception */
|
||||
EXCP_PROGRAM = 0x07, /* Program exception */
|
||||
EXCP_NO_FP = 0x08, /* No floating point */
|
||||
EXCP_DECR = 0x09, /* Decrementer exception */
|
||||
EXCP_RESA = 0x0A, /* Implementation specific */
|
||||
EXCP_RESB = 0x0B, /* Implementation specific */
|
||||
EXCP_SYSCALL = 0x0C, /* System call */
|
||||
EXCP_TRACE = 0x0D, /* Trace exception (optional) */
|
||||
EXCP_FP_ASSIST = 0x0E, /* Floating-point assist (optional) */
|
||||
#if 0
|
||||
/* Exeption subtypes for EXCP_DSI */
|
||||
EXCP_DSI_TRANSLATE = 0x10301, /* Data address can't be translated */
|
||||
EXCP_DSI_NOTSUP = 0x10302, /* Access type not supported */
|
||||
EXCP_DSI_PROT = 0x10303, /* Memory protection violation */
|
||||
EXCP_DSI_EXTERNAL = 0x10304, /* External access disabled */
|
||||
EXCP_DSI_DABR = 0x10305, /* Data address breakpoint */
|
||||
/* Exeption subtypes for EXCP_ISI */
|
||||
EXCP_ISI_TRANSLATE = 0x10401, /* Code address can't be translated */
|
||||
EXCP_ISI_NOTSUP = 0x10402, /* Access type not supported */
|
||||
EXCP_ISI_PROT = 0x10403, /* Memory protection violation */
|
||||
EXCP_ISI_GUARD = 0x10404, /* Fetch into guarded memory */
|
||||
/* Exeption subtypes for EXCP_ALIGN */
|
||||
EXCP_ALIGN_FP = 0x10601, /* FP alignment exception */
|
||||
EXCP_ALIGN_LST = 0x10602, /* Unaligned memory load/store */
|
||||
EXCP_ALIGN_LE = 0x10603, /* Unaligned little-endian access */
|
||||
EXCP_ALIGN_PROT = 0x10604, /* Access cross protection boundary */
|
||||
EXCP_ALIGN_BAT = 0x10605, /* Access cross a BAT/seg boundary */
|
||||
EXCP_ALIGN_CACHE = 0x10606, /* Impossible dcbz access */
|
||||
/* Exeption subtypes for EXCP_PROGRAM */
|
||||
/* FP exceptions */
|
||||
EXCP_FP_OX = 0x10701, /* FP overflow */
|
||||
EXCP_FP_UX = 0x10702, /* FP underflow */
|
||||
EXCP_FP_ZX = 0x10703, /* FP divide by zero */
|
||||
EXCP_FP_XX = 0x10704, /* FP inexact */
|
||||
EXCP_FP_VXNAN = 0x10705, /* FP invalid SNaN op */
|
||||
EXCP_FP_VXISI = 0x10706, /* FP invalid infinite substraction */
|
||||
EXCP_FP_VXIDI = 0x10707, /* FP invalid infinite divide */
|
||||
EXCP_FP_VXZDZ = 0x10708, /* FP invalid zero divide */
|
||||
EXCP_FP_VXIMZ = 0x10709, /* FP invalid infinite * zero */
|
||||
EXCP_FP_VXVC = 0x1070A, /* FP invalid compare */
|
||||
EXCP_FP_VXSOFT = 0x1070B, /* FP invalid operation */
|
||||
EXCP_FP_VXSQRT = 0x1070C, /* FP invalid square root */
|
||||
EXCP_FP_VXCVI = 0x1070D, /* FP invalid integer conversion */
|
||||
/* Invalid instruction */
|
||||
EXCP_INVAL_INVAL = 0x10711, /* Invalid instruction */
|
||||
EXCP_INVAL_LSWX = 0x10712, /* Invalid lswx instruction */
|
||||
EXCP_INVAL_SPR = 0x10713, /* Invalid SPR access */
|
||||
EXCP_INVAL_FP = 0x10714, /* Unimplemented mandatory fp instr */
|
||||
#endif
|
||||
EXCP_INVAL = 0x70, /* Invalid instruction */
|
||||
/* Privileged instruction */
|
||||
EXCP_PRIV = 0x71, /* Privileged instruction */
|
||||
/* Trap */
|
||||
EXCP_TRAP = 0x72, /* Trap */
|
||||
/* Special cases where we want to stop translation */
|
||||
EXCP_MTMSR = 0x103, /* mtmsr instruction: */
|
||||
/* may change privilege level */
|
||||
EXCP_BRANCH = 0x104, /* branch instruction */
|
||||
};
|
||||
|
||||
#endif /* !defined (__CPU_PPC_H__) */
|
166
target-ppc/exec.h
Normal file
166
target-ppc/exec.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* PPC emulation definitions for qemu.
|
||||
*
|
||||
* Copyright (c) 2003 Jocelyn Mayer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#if !defined (__PPC_H__)
|
||||
#define __PPC_H__
|
||||
|
||||
#include "dyngen-exec.h"
|
||||
|
||||
register struct CPUPPCState *env asm(AREG0);
|
||||
register uint32_t T0 asm(AREG1);
|
||||
register uint32_t T1 asm(AREG2);
|
||||
register uint32_t T2 asm(AREG3);
|
||||
|
||||
#define PARAM(n) ((uint32_t)PARAM##n)
|
||||
#define SPARAM(n) ((int32_t)PARAM##n)
|
||||
#define FT0 (env->ft0)
|
||||
#define FT1 (env->ft1)
|
||||
#define FT2 (env->ft2)
|
||||
#define FTS0 ((float)env->ft0)
|
||||
#define FTS1 ((float)env->ft1)
|
||||
#define FTS2 ((float)env->ft2)
|
||||
|
||||
#define RETURN() __asm__ __volatile__("");
|
||||
|
||||
#include "cpu.h"
|
||||
#include "exec-all.h"
|
||||
|
||||
static inline uint8_t ld8 (uint32_t EA)
|
||||
{
|
||||
return *((uint8_t *)EA);
|
||||
}
|
||||
|
||||
static inline uint16_t ld16 (uint32_t EA)
|
||||
{
|
||||
return __be16_to_cpu(*((uint16_t *)EA));
|
||||
}
|
||||
|
||||
static inline uint16_t ld16r (uint32_t EA)
|
||||
{
|
||||
return __le16_to_cpu(*((uint16_t *)EA));
|
||||
}
|
||||
|
||||
static inline uint32_t ld32 (uint32_t EA)
|
||||
{
|
||||
return __be32_to_cpu(*((uint32_t *)EA));
|
||||
}
|
||||
|
||||
static inline uint32_t ld32r (uint32_t EA)
|
||||
{
|
||||
return __le32_to_cpu(*((uint32_t *)EA));
|
||||
}
|
||||
|
||||
static inline uint64_t ld64 (uint32_t EA)
|
||||
{
|
||||
return __be64_to_cpu(*((uint64_t *)EA));
|
||||
}
|
||||
|
||||
static inline uint64_t ld64r (uint32_t EA)
|
||||
{
|
||||
return __le64_to_cpu(*((uint64_t *)EA));
|
||||
}
|
||||
|
||||
static inline void st8 (uint32_t EA, uint8_t data)
|
||||
{
|
||||
*((uint8_t *)EA) = data;
|
||||
}
|
||||
|
||||
static inline void st16 (uint32_t EA, uint16_t data)
|
||||
{
|
||||
*((uint16_t *)EA) = __cpu_to_be16(data);
|
||||
}
|
||||
|
||||
static inline void st16r (uint32_t EA, uint16_t data)
|
||||
{
|
||||
*((uint16_t *)EA) = __cpu_to_le16(data);
|
||||
}
|
||||
|
||||
static inline void st32 (uint32_t EA, uint32_t data)
|
||||
{
|
||||
*((uint32_t *)EA) = __cpu_to_be32(data);
|
||||
}
|
||||
|
||||
static inline void st32r (uint32_t EA, uint32_t data)
|
||||
{
|
||||
*((uint32_t *)EA) = __cpu_to_le32(data);
|
||||
}
|
||||
|
||||
static inline void st64 (uint32_t EA, uint64_t data)
|
||||
{
|
||||
*((uint64_t *)EA) = __cpu_to_be64(data);
|
||||
}
|
||||
|
||||
static inline void st64r (uint32_t EA, uint64_t data)
|
||||
{
|
||||
*((uint64_t *)EA) = __cpu_to_le64(data);
|
||||
}
|
||||
|
||||
static inline void set_CRn(int n, uint8_t value)
|
||||
{
|
||||
env->crf[n] = value;
|
||||
}
|
||||
|
||||
static inline void set_carry (void)
|
||||
{
|
||||
xer_ca = 1;
|
||||
}
|
||||
|
||||
static inline void reset_carry (void)
|
||||
{
|
||||
xer_ca = 0;
|
||||
}
|
||||
|
||||
static inline void set_overflow (void)
|
||||
{
|
||||
xer_so = 1;
|
||||
xer_ov = 1;
|
||||
}
|
||||
|
||||
static inline void reset_overflow (void)
|
||||
{
|
||||
xer_ov = 0;
|
||||
}
|
||||
|
||||
static inline uint32_t rotl (uint32_t i, int n)
|
||||
{
|
||||
return ((i << n) | (i >> (32 - n)));
|
||||
}
|
||||
|
||||
void raise_exception (int exception_index);
|
||||
void raise_exception_err (int exception_index, int error_code);
|
||||
|
||||
uint32_t do_load_cr (void);
|
||||
void do_store_cr (uint32_t crn, uint32_t value);
|
||||
uint32_t do_load_xer (void);
|
||||
void do_store_xer (uint32_t value);
|
||||
uint32_t do_load_msr (void);
|
||||
void do_store_msr (uint32_t msr_value);
|
||||
void do_load_fpscr (void);
|
||||
void do_store_fpscr (uint32_t mask);
|
||||
|
||||
int32_t do_sraw(int32_t Ta, uint32_t Tb);
|
||||
void do_lmw (int reg, uint32_t src);
|
||||
void do_stmw (int reg, uint32_t dest);
|
||||
void do_lsw (uint32_t reg, int count, uint32_t src);
|
||||
void do_stsw (uint32_t reg, int count, uint32_t dest);
|
||||
|
||||
void do_dcbz (void);
|
||||
void do_icbi (void);
|
||||
|
||||
#endif /* !defined (__PPC_H__) */
|
267
target-ppc/helper.c
Normal file
267
target-ppc/helper.c
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* PPC emulation helpers for qemu.
|
||||
*
|
||||
* Copyright (c) 2003 Jocelyn Mayer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "exec.h"
|
||||
|
||||
extern FILE *logfile;
|
||||
|
||||
void cpu_loop_exit(void)
|
||||
{
|
||||
longjmp(env->jmp_env, 1);
|
||||
}
|
||||
|
||||
/* shortcuts to generate exceptions */
|
||||
void raise_exception_err (int exception_index, int error_code)
|
||||
{
|
||||
env->exception_index = exception_index;
|
||||
env->error_code = error_code;
|
||||
|
||||
cpu_loop_exit();
|
||||
}
|
||||
|
||||
void raise_exception (int exception_index)
|
||||
{
|
||||
env->exception_index = exception_index;
|
||||
env->error_code = 0;
|
||||
|
||||
cpu_loop_exit();
|
||||
}
|
||||
|
||||
/* Helpers for "fat" micro operations */
|
||||
uint32_t do_load_cr (void)
|
||||
{
|
||||
return (env->crf[0] << 28) |
|
||||
(env->crf[1] << 24) |
|
||||
(env->crf[2] << 20) |
|
||||
(env->crf[3] << 16) |
|
||||
(env->crf[4] << 12) |
|
||||
(env->crf[5] << 8) |
|
||||
(env->crf[6] << 4) |
|
||||
(env->crf[7] << 0);
|
||||
}
|
||||
|
||||
void do_store_cr (uint32_t crn, uint32_t value)
|
||||
{
|
||||
int i, sh;
|
||||
|
||||
for (i = 0, sh = 7; i < 8; i++, sh --) {
|
||||
if (crn & (1 << sh))
|
||||
env->crf[i] = (value >> (sh * 4)) & 0xF;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t do_load_xer (void)
|
||||
{
|
||||
return (xer_so << XER_SO) |
|
||||
(xer_ov << XER_OV) |
|
||||
(xer_ca << XER_CA) |
|
||||
(xer_bc << XER_BC);
|
||||
}
|
||||
|
||||
void do_store_xer (uint32_t value)
|
||||
{
|
||||
xer_so = (value >> XER_SO) & 0x01;
|
||||
xer_ov = (value >> XER_OV) & 0x01;
|
||||
xer_ca = (value >> XER_CA) & 0x01;
|
||||
xer_bc = (value >> XER_BC) & 0x1f;
|
||||
}
|
||||
|
||||
uint32_t do_load_msr (void)
|
||||
{
|
||||
return (msr_pow << MSR_POW) |
|
||||
(msr_ile << MSR_ILE) |
|
||||
(msr_ee << MSR_EE) |
|
||||
(msr_pr << MSR_PR) |
|
||||
(msr_fp << MSR_FP) |
|
||||
(msr_me << MSR_ME) |
|
||||
(msr_fe0 << MSR_FE0) |
|
||||
(msr_se << MSR_SE) |
|
||||
(msr_be << MSR_BE) |
|
||||
(msr_fe1 << MSR_FE1) |
|
||||
(msr_ip << MSR_IP) |
|
||||
(msr_ir << MSR_IR) |
|
||||
(msr_dr << MSR_DR) |
|
||||
(msr_ri << MSR_RI) |
|
||||
(msr_le << MSR_LE);
|
||||
}
|
||||
|
||||
void do_store_msr (uint32_t msr_value)
|
||||
{
|
||||
msr_pow = (msr_value >> MSR_POW) & 0x03;
|
||||
msr_ile = (msr_value >> MSR_ILE) & 0x01;
|
||||
msr_ee = (msr_value >> MSR_EE) & 0x01;
|
||||
msr_pr = (msr_value >> MSR_PR) & 0x01;
|
||||
msr_fp = (msr_value >> MSR_FP) & 0x01;
|
||||
msr_me = (msr_value >> MSR_ME) & 0x01;
|
||||
msr_fe0 = (msr_value >> MSR_FE0) & 0x01;
|
||||
msr_se = (msr_value >> MSR_SE) & 0x01;
|
||||
msr_be = (msr_value >> MSR_BE) & 0x01;
|
||||
msr_fe1 = (msr_value >> MSR_FE1) & 0x01;
|
||||
msr_ip = (msr_value >> MSR_IP) & 0x01;
|
||||
msr_ir = (msr_value >> MSR_IR) & 0x01;
|
||||
msr_dr = (msr_value >> MSR_DR) & 0x01;
|
||||
msr_ri = (msr_value >> MSR_RI) & 0x01;
|
||||
msr_le = (msr_value >> MSR_LE) & 0x01;
|
||||
}
|
||||
|
||||
/* The 32 MSB of the target fpr are undefined. They'll be zero... */
|
||||
/* Floating point operations helpers */
|
||||
void do_load_fpscr (void)
|
||||
{
|
||||
/* The 32 MSB of the target fpr are undefined.
|
||||
* They'll be zero...
|
||||
*/
|
||||
union {
|
||||
double d;
|
||||
struct {
|
||||
uint32_t u[2];
|
||||
} s;
|
||||
} u;
|
||||
int i;
|
||||
|
||||
u.s.u[0] = 0;
|
||||
u.s.u[1] = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
u.s.u[1] |= env->fpscr[i] << (4 * i);
|
||||
FT0 = u.d;
|
||||
}
|
||||
|
||||
void do_store_fpscr (uint32_t mask)
|
||||
{
|
||||
/*
|
||||
* We use only the 32 LSB of the incoming fpr
|
||||
*/
|
||||
union {
|
||||
double d;
|
||||
struct {
|
||||
uint32_t u[2];
|
||||
} s;
|
||||
} u;
|
||||
int i;
|
||||
|
||||
u.d = FT0;
|
||||
if (mask & 0x80)
|
||||
env->fpscr[0] = (env->fpscr[0] & 0x9) | ((u.s.u[1] >> 28) & ~0x9);
|
||||
for (i = 1; i < 7; i++) {
|
||||
if (mask & (1 << (7 - i)))
|
||||
env->fpscr[i] = (u.s.u[1] >> (4 * (7 - i))) & 0xF;
|
||||
}
|
||||
/* TODO: update FEX & VX */
|
||||
/* Set rounding mode */
|
||||
switch (env->fpscr[0] & 0x3) {
|
||||
case 0:
|
||||
/* Best approximation (round to nearest) */
|
||||
fesetround(FE_TONEAREST);
|
||||
break;
|
||||
case 1:
|
||||
/* Smaller magnitude (round toward zero) */
|
||||
fesetround(FE_TOWARDZERO);
|
||||
break;
|
||||
case 2:
|
||||
/* Round toward +infinite */
|
||||
fesetround(FE_UPWARD);
|
||||
break;
|
||||
case 3:
|
||||
/* Round toward -infinite */
|
||||
fesetround(FE_DOWNWARD);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t do_sraw(int32_t value, uint32_t shift)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
xer_ca = 0;
|
||||
if (shift & 0x20) {
|
||||
ret = (-1) * ((uint32_t)value >> 31);
|
||||
if (ret < 0)
|
||||
xer_ca = 1;
|
||||
} else {
|
||||
ret = value >> (shift & 0x1f);
|
||||
if (ret < 0 && (value & ((1 << shift) - 1)) != 0)
|
||||
xer_ca = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void do_lmw (int reg, uint32_t src)
|
||||
{
|
||||
for (; reg <= 31; reg++, src += 4)
|
||||
ugpr(reg) = ld32(src);
|
||||
}
|
||||
|
||||
void do_stmw (int reg, uint32_t dest)
|
||||
{
|
||||
for (; reg <= 31; reg++, dest += 4)
|
||||
st32(dest, ugpr(reg));
|
||||
}
|
||||
|
||||
void do_lsw (uint32_t reg, int count, uint32_t src)
|
||||
{
|
||||
uint32_t tmp;
|
||||
int sh;
|
||||
|
||||
for (; count > 3; count -= 4, src += 4) {
|
||||
ugpr(reg++) = ld32(src);
|
||||
if (T2 == 32)
|
||||
T2 = 0;
|
||||
}
|
||||
if (count > 0) {
|
||||
tmp = 0;
|
||||
for (sh = 24; count > 0; count--, src++, sh -= 8) {
|
||||
tmp |= ld8(src) << sh;
|
||||
}
|
||||
ugpr(reg) = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void do_stsw (uint32_t reg, int count, uint32_t dest)
|
||||
{
|
||||
int sh;
|
||||
|
||||
for (; count > 3; count -= 4, dest += 4) {
|
||||
st32(dest, ugpr(reg++));
|
||||
if (reg == 32)
|
||||
reg = 0;
|
||||
}
|
||||
if (count > 0) {
|
||||
for (sh = 24; count > 0; count--, dest++, sh -= 8) {
|
||||
st8(dest, (ugpr(reg) >> sh) & 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void do_dcbz (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Assume cache line size is 32 */
|
||||
for (i = 0; i < 8; i++) {
|
||||
st32(T0, 0);
|
||||
T0 += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/* Instruction cache invalidation helper */
|
||||
void do_icbi (void)
|
||||
{
|
||||
tb_invalidate_page(T0);
|
||||
}
|
1418
target-ppc/op.c
Normal file
1418
target-ppc/op.c
Normal file
File diff suppressed because it is too large
Load Diff
159
target-ppc/op_template.h
Normal file
159
target-ppc/op_template.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* PPC emulation micro-operations for qemu.
|
||||
*
|
||||
* Copyright (c) 2003 Jocelyn Mayer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
void OPPROTO glue(op_load_gpr_T0_gpr, REG)(void)
|
||||
{
|
||||
T0 = regs->gpr[REG];
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_load_gpr_T1_gpr, REG)(void)
|
||||
{
|
||||
T1 = regs->gpr[REG];
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_load_gpr_T2_gpr, REG)(void)
|
||||
{
|
||||
T2 = regs->gpr[REG];
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_T0_gpr_gpr, REG)(void)
|
||||
{
|
||||
regs->gpr[REG] = T0;
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_T1_gpr_gpr, REG)(void)
|
||||
{
|
||||
regs->gpr[REG] = T1;
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_T2_gpr_gpr, REG)(void)
|
||||
{
|
||||
regs->gpr[REG] = T2;
|
||||
}
|
||||
|
||||
#if REG <= 7
|
||||
|
||||
void OPPROTO glue(op_load_crf_T0_crf, REG)(void)
|
||||
{
|
||||
T0 = regs->crf[REG];
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_load_crf_T1_crf, REG)(void)
|
||||
{
|
||||
T1 = regs->crf[REG];
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_T0_crf_crf, REG)(void)
|
||||
{
|
||||
regs->crf[REG] = T0;
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_T1_crf_crf, REG)(void)
|
||||
{
|
||||
regs->crf[REG] = T1;
|
||||
}
|
||||
|
||||
/* Floating point condition and status register moves */
|
||||
void OPPROTO glue(op_load_fpscr_T0_fpscr, REG)(void)
|
||||
{
|
||||
T0 = regs->fpscr[REG];
|
||||
RETURN();
|
||||
}
|
||||
|
||||
#if REG == 0
|
||||
void OPPROTO glue(op_store_T0_fpscr_fpscr, REG)(void)
|
||||
{
|
||||
regs->fpscr[REG] = (regs->fpscr[REG] & 0x9) | (T0 & ~0x9);
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_T0_fpscri_fpscr, REG)(void)
|
||||
{
|
||||
regs->fpscr[REG] = (regs->fpscr[REG] & ~0x9) | (PARAM(1) & 0x9);
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_clear_fpscr_fpscr, REG)(void)
|
||||
{
|
||||
regs->fpscr[REG] = (regs->fpscr[REG] & 0x9);
|
||||
RETURN();
|
||||
}
|
||||
#else
|
||||
void OPPROTO glue(op_store_T0_fpscr_fpscr, REG)(void)
|
||||
{
|
||||
regs->fpscr[REG] = T0;
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_T0_fpscri_fpscr, REG)(void)
|
||||
{
|
||||
regs->fpscr[REG] = PARAM(1);
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_clear_fpscr_fpscr, REG)(void)
|
||||
{
|
||||
regs->fpscr[REG] = 0x0;
|
||||
RETURN();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* REG <= 7 */
|
||||
|
||||
/* float moves */
|
||||
|
||||
/* floating point registers moves */
|
||||
void OPPROTO glue(op_load_fpr_FT0_fpr, REG)(void)
|
||||
{
|
||||
FT0 = env->fpr[REG];
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_FT0_fpr_fpr, REG)(void)
|
||||
{
|
||||
env->fpr[REG] = FT0;
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_load_fpr_FT1_fpr, REG)(void)
|
||||
{
|
||||
FT1 = env->fpr[REG];
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_FT1_fpr_fpr, REG)(void)
|
||||
{
|
||||
env->fpr[REG] = FT1;
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_load_fpr_FT2_fpr, REG)(void)
|
||||
{
|
||||
FT2 = env->fpr[REG];
|
||||
RETURN();
|
||||
}
|
||||
|
||||
void OPPROTO glue(op_store_FT2_fpr_fpr, REG)(void)
|
||||
{
|
||||
env->fpr[REG] = FT2;
|
||||
RETURN();
|
||||
}
|
||||
|
||||
#undef REG
|
2485
target-ppc/translate.c
Normal file
2485
target-ppc/translate.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,29 +7,42 @@
|
||||
|
||||
/*#define EXCP_INTERRUPT 0x100*/
|
||||
|
||||
/* trap definitions */
|
||||
#define TT_ILL_INSN 0x02
|
||||
#define TT_WIN_OVF 0x05
|
||||
#define TT_WIN_UNF 0x06
|
||||
#define TT_DIV_ZERO 0x2a
|
||||
#define TT_TRAP 0x80
|
||||
|
||||
#define PSR_NEG (1<<23)
|
||||
#define PSR_ZERO (1<<22)
|
||||
#define PSR_OVF (1<<21)
|
||||
#define PSR_CARRY (1<<20)
|
||||
|
||||
#define NWINDOWS 32
|
||||
|
||||
typedef struct CPUSPARCState {
|
||||
uint32_t gregs[8]; /* general registers */
|
||||
uint32_t *regwptr; /* pointer to current register window */
|
||||
double *regfptr; /* floating point registers */
|
||||
uint32_t pc; /* program counter */
|
||||
uint32_t npc; /* next program counter */
|
||||
uint32_t sp; /* stack pointer */
|
||||
uint32_t y; /* multiply/divide register */
|
||||
uint32_t psr; /* processor state register */
|
||||
uint32_t T2;
|
||||
jmp_buf jmp_env;
|
||||
int user_mode_only;
|
||||
int exception_index;
|
||||
int interrupt_index;
|
||||
int interrupt_request;
|
||||
struct TranslationBlock *current_tb;
|
||||
void *opaque;
|
||||
uint32_t gregs[8]; /* general registers */
|
||||
uint32_t *regwptr; /* pointer to current register window */
|
||||
double *regfptr; /* floating point registers */
|
||||
uint32_t pc; /* program counter */
|
||||
uint32_t npc; /* next program counter */
|
||||
uint32_t sp; /* stack pointer */
|
||||
uint32_t y; /* multiply/divide register */
|
||||
uint32_t psr; /* processor state register */
|
||||
uint32_t T2;
|
||||
uint32_t cwp; /* index of current register window (extracted
|
||||
from PSR) */
|
||||
uint32_t wim; /* window invalid mask */
|
||||
jmp_buf jmp_env;
|
||||
int user_mode_only;
|
||||
int exception_index;
|
||||
int interrupt_index;
|
||||
int interrupt_request;
|
||||
struct TranslationBlock *current_tb;
|
||||
void *opaque;
|
||||
/* NOTE: we allow 8 more registers to handle wrapping */
|
||||
uint32_t regbase[NWINDOWS * 16 + 8];
|
||||
} CPUSPARCState;
|
||||
|
||||
CPUSPARCState *cpu_sparc_init(void);
|
||||
|
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
/*XXX*/
|
||||
/*XXX*/
|
||||
#define REGNAME g0
|
||||
#define REG (env->gregs[0])
|
||||
#include "op_template.h"
|
||||
@@ -117,384 +117,545 @@
|
||||
#define REGNAME o7
|
||||
#define REG (env->regwptr[7])
|
||||
#include "op_template.h"
|
||||
|
||||
#define EIP (env->pc)
|
||||
|
||||
void OPPROTO op_movl_T0_0(void)
|
||||
{
|
||||
T0 = 0;
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_T0_1(void)
|
||||
{
|
||||
T0 = 1;
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_T0_im(void)
|
||||
{
|
||||
T0 = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_T1_im(void)
|
||||
{
|
||||
T1 = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_T2_im(void)
|
||||
{
|
||||
T2 = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_addl_T1_im(void)
|
||||
{
|
||||
T1 += PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_addl_T1_T2(void)
|
||||
{
|
||||
T1 += T2;
|
||||
}
|
||||
|
||||
void OPPROTO op_subl_T1_T2(void)
|
||||
{
|
||||
T1 -= T2;
|
||||
}
|
||||
|
||||
void OPPROTO op_add_T1_T0 (void)
|
||||
{
|
||||
T0 += T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_and_T1_T0 (void)
|
||||
{
|
||||
T0 &= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_or_T1_T0 (void)
|
||||
{
|
||||
T0 |= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_xor_T1_T0 (void)
|
||||
{
|
||||
T0 ^= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_sub_T1_T0 (void)
|
||||
{
|
||||
T0 -= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_andn_T1_T0 (void)
|
||||
{
|
||||
T0 &= ~T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_orn_T1_T0 (void)
|
||||
{
|
||||
T0 |= ~T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_xnor_T1_T0 (void)
|
||||
{
|
||||
T0 ^= ~T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_addx_T1_T0 (void)
|
||||
{
|
||||
T0 += T1+((env->psr & PSR_CARRY)?1:0);
|
||||
}
|
||||
|
||||
void OPPROTO op_umul_T1_T0 (void)
|
||||
{
|
||||
unsigned long long res = T0*T1;
|
||||
T0 = res & 0xffffffff;
|
||||
env->y = res >> 32;
|
||||
}
|
||||
|
||||
void OPPROTO op_smul_T1_T0 (void)
|
||||
{
|
||||
long long res = T0*T1;
|
||||
T0 = res & 0xffffffff;
|
||||
env->y = res >> 32;
|
||||
}
|
||||
|
||||
void OPPROTO op_udiv_T1_T0 (void)
|
||||
{
|
||||
unsigned long long x0 = T0 * env->y;
|
||||
unsigned int x1 = T1;
|
||||
T0 = x0 / x1;
|
||||
}
|
||||
|
||||
void OPPROTO op_sdiv_T1_T0 (void)
|
||||
{
|
||||
long long x0 = T0 * env->y;
|
||||
int x1 = T1;
|
||||
T0 = x0 / x1;
|
||||
}
|
||||
|
||||
void OPPROTO op_subx_T1_T0 (void)
|
||||
{
|
||||
T0 -= T1+((env->psr & PSR_CARRY)?1:0);
|
||||
}
|
||||
|
||||
void OPPROTO op_set_flags (void)
|
||||
{
|
||||
env->psr = 0;
|
||||
if (!T0) env->psr |= PSR_ZERO;
|
||||
if ((unsigned int) T0 < (unsigned int) T1) env->psr |= PSR_CARRY;
|
||||
if ((int) T0 < (int) T1) env->psr |= PSR_OVF;
|
||||
if ((int) T0 < 0) env->psr |= PSR_NEG;
|
||||
}
|
||||
|
||||
void OPPROTO op_sll (void)
|
||||
{
|
||||
T0 <<= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_srl (void)
|
||||
{
|
||||
T0 >>= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_sra (void)
|
||||
{
|
||||
int x = T0 >> T1;
|
||||
T0 = x;
|
||||
}
|
||||
|
||||
void OPPROTO op_st (void)
|
||||
{
|
||||
stl ((void *) T0, T1);
|
||||
}
|
||||
|
||||
void OPPROTO op_stb (void)
|
||||
{
|
||||
stb ((void *) T0, T1);
|
||||
}
|
||||
|
||||
void OPPROTO op_sth (void)
|
||||
{
|
||||
stw ((void *) T0, T1);
|
||||
}
|
||||
|
||||
void OPPROTO op_ld (void)
|
||||
{
|
||||
T1 = ldl ((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldub (void)
|
||||
{
|
||||
T1 = ldub ((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_lduh (void)
|
||||
{
|
||||
T1 = lduw ((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldsb (void)
|
||||
{
|
||||
T1 = ldsb ((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldsh (void)
|
||||
{
|
||||
T1 = ldsw ((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldstub (void)
|
||||
{
|
||||
T1 = ldub ((void *) T0);
|
||||
stb ((void *) T0, 0xff); /* XXX: Should be Atomically */
|
||||
}
|
||||
|
||||
void OPPROTO op_swap (void)
|
||||
{
|
||||
unsigned int tmp = ldl ((void *) T0);
|
||||
stl ((void *) T0, T1); /* XXX: Should be Atomically */
|
||||
T1 = tmp;
|
||||
}
|
||||
|
||||
void OPPROTO op_ldd (void)
|
||||
{
|
||||
T1 = ldl ((void *) T0);
|
||||
T0 = ldl ((void *) T0+4);
|
||||
}
|
||||
|
||||
void OPPROTO op_wry (void)
|
||||
{
|
||||
env->y = T0^T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_rdy (void)
|
||||
{
|
||||
T0 = env->y;
|
||||
}
|
||||
|
||||
#define regwptr (env->regwptr)
|
||||
|
||||
void OPPROTO op_save (void)
|
||||
{
|
||||
regwptr -= 16;
|
||||
}
|
||||
|
||||
void OPPROTO op_restore (void)
|
||||
{
|
||||
regwptr += 16;
|
||||
}
|
||||
|
||||
void OPPROTO op_trap (void)
|
||||
{
|
||||
env->exception_index = PARAM1;
|
||||
cpu_loop_exit ();
|
||||
}
|
||||
|
||||
void OPPROTO op_exit_tb (void)
|
||||
{
|
||||
EXIT_TB ();
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_be (void)
|
||||
{
|
||||
T0 = (env->psr & PSR_ZERO);
|
||||
}
|
||||
|
||||
#define FLAG_SET(x) (env->psr&x)?1:0
|
||||
#define GET_FLAGS unsigned int Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF), C = FLAG_SET(PSR_CARRY)
|
||||
|
||||
void OPPROTO op_eval_ble (void)
|
||||
void OPPROTO op_movl_T0_0(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T0 = Z | (N^V);
|
||||
T0 = 0;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bl (void)
|
||||
void OPPROTO op_movl_T0_1(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T0 = N^V;
|
||||
T0 = 1;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bleu (void)
|
||||
void OPPROTO op_movl_T0_im(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T0 = C|Z;
|
||||
T0 = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bcs (void)
|
||||
void OPPROTO op_movl_T1_im(void)
|
||||
{
|
||||
T0 = (env->psr & PSR_CARRY);
|
||||
T1 = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bvs (void)
|
||||
void OPPROTO op_movl_T2_im(void)
|
||||
{
|
||||
T0 = (env->psr & PSR_OVF);
|
||||
T2 = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bneg (void)
|
||||
void OPPROTO op_addl_T1_im(void)
|
||||
{
|
||||
T0 = (env->psr & PSR_NEG);
|
||||
T1 += PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bne (void)
|
||||
void OPPROTO op_addl_T1_T2(void)
|
||||
{
|
||||
T0 = !(env->psr & PSR_ZERO);
|
||||
T1 += T2;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bg (void)
|
||||
void OPPROTO op_subl_T1_T2(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T0 = !(Z | (N^V));
|
||||
T1 -= T2;
|
||||
}
|
||||
|
||||
/*XXX: This seems to be documented wrong in the SPARC V8 Manual
|
||||
The manual states: !(N^V)
|
||||
but I assume Z | !(N^V) to be correct */
|
||||
void OPPROTO op_eval_bge (void)
|
||||
void OPPROTO op_add_T1_T0(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T0 = Z | !(N^V);
|
||||
T0 += T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bgu (void)
|
||||
void OPPROTO op_add_T1_T0_cc(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T0 = !(C | Z);
|
||||
unsigned int src1;
|
||||
src1 = T0;
|
||||
T0 += T1;
|
||||
env->psr = 0;
|
||||
if (!T0)
|
||||
env->psr |= PSR_ZERO;
|
||||
if ((int) T0 < 0)
|
||||
env->psr |= PSR_NEG;
|
||||
if (T0 < src1)
|
||||
env->psr |= PSR_CARRY;
|
||||
if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
|
||||
env->psr |= PSR_OVF;
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bcc (void)
|
||||
void OPPROTO op_sub_T1_T0(void)
|
||||
{
|
||||
T0 = !(env->psr & PSR_CARRY);
|
||||
T0 -= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bpos (void)
|
||||
void OPPROTO op_sub_T1_T0_cc(void)
|
||||
{
|
||||
T0 = !(env->psr & PSR_NEG);
|
||||
unsigned int src1;
|
||||
|
||||
src1 = T0;
|
||||
T0 -= T1;
|
||||
env->psr = 0;
|
||||
if (!T0)
|
||||
env->psr |= PSR_ZERO;
|
||||
if ((int) T0 < 0)
|
||||
env->psr |= PSR_NEG;
|
||||
if (src1 < T1)
|
||||
env->psr |= PSR_CARRY;
|
||||
if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
|
||||
env->psr |= PSR_OVF;
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bvc (void)
|
||||
void OPPROTO op_and_T1_T0(void)
|
||||
{
|
||||
T0 = !(env->psr & PSR_OVF);
|
||||
T0 &= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_jmp_im (void)
|
||||
void OPPROTO op_or_T1_T0(void)
|
||||
{
|
||||
env->pc = PARAM1;
|
||||
T0 |= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_call (void)
|
||||
void OPPROTO op_xor_T1_T0(void)
|
||||
{
|
||||
regwptr[7] = PARAM1-4;
|
||||
env->pc = PARAM1+PARAM2;
|
||||
T0 ^= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_jmpl (void)
|
||||
void OPPROTO op_andn_T1_T0(void)
|
||||
{
|
||||
env->npc = T0;
|
||||
T0 &= ~T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_generic_jmp_1 (void)
|
||||
void OPPROTO op_orn_T1_T0(void)
|
||||
{
|
||||
T1 = PARAM1;
|
||||
env->pc = PARAM1+PARAM2;
|
||||
T0 |= ~T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_generic_jmp_2 (void)
|
||||
void OPPROTO op_xnor_T1_T0(void)
|
||||
{
|
||||
T1 = PARAM1;
|
||||
env->pc = env->npc;
|
||||
T0 ^= ~T1;
|
||||
}
|
||||
|
||||
unsigned long old_T0;
|
||||
|
||||
void OPPROTO op_save_T0 (void)
|
||||
void OPPROTO op_addx_T1_T0(void)
|
||||
{
|
||||
old_T0 = T0;
|
||||
T0 += T1 + ((env->psr & PSR_CARRY) ? 1 : 0);
|
||||
}
|
||||
|
||||
void OPPROTO op_restore_T0 (void)
|
||||
void OPPROTO op_umul_T1_T0(void)
|
||||
{
|
||||
T0 = old_T0;
|
||||
uint64_t res;
|
||||
res = (uint64_t) T0 *(uint64_t) T1;
|
||||
T0 = res & 0xffffffff;
|
||||
env->y = res >> 32;
|
||||
}
|
||||
|
||||
void OPPROTO op_generic_branch (void)
|
||||
void OPPROTO op_smul_T1_T0(void)
|
||||
{
|
||||
if (T0)
|
||||
JUMP_TB (__func__, PARAM1, 0, PARAM2);
|
||||
else
|
||||
JUMP_TB (__func__, PARAM1, 1, PARAM3);
|
||||
FORCE_RET ();
|
||||
uint64_t res;
|
||||
res = (int64_t) ((int32_t) T0) * (int64_t) ((int32_t) T1);
|
||||
T0 = res & 0xffffffff;
|
||||
env->y = res >> 32;
|
||||
}
|
||||
|
||||
void OPPROTO op_generic_branch_a (void)
|
||||
void OPPROTO op_mulscc_T1_T0(void)
|
||||
{
|
||||
if (T0)
|
||||
env->npc = PARAM3;
|
||||
else
|
||||
JUMP_TB (__func__, PARAM1, 0, PARAM2);
|
||||
FORCE_RET ();
|
||||
unsigned int b1, C, V, b2, src1;
|
||||
C = FLAG_SET(PSR_CARRY);
|
||||
V = FLAG_SET(PSR_OVF);
|
||||
b1 = C ^ V;
|
||||
b2 = T0 & 1;
|
||||
T0 = (b1 << 31) | (T0 >> 1);
|
||||
if (!(env->y & 1))
|
||||
T1 = 0;
|
||||
/* do addition and update flags */
|
||||
src1 = T0;
|
||||
T0 += T1;
|
||||
env->psr = 0;
|
||||
if (!T0)
|
||||
env->psr |= PSR_ZERO;
|
||||
if ((int) T0 < 0)
|
||||
env->psr |= PSR_NEG;
|
||||
if (T0 < src1)
|
||||
env->psr |= PSR_CARRY;
|
||||
if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
|
||||
env->psr |= PSR_OVF;
|
||||
env->y = (b2 << 31) | (env->y >> 1);
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_noop (void)
|
||||
void OPPROTO op_udiv_T1_T0(void)
|
||||
{
|
||||
uint64_t x0;
|
||||
uint32_t x1;
|
||||
|
||||
x0 = T0 | ((uint64_t) (env->y) << 32);
|
||||
x1 = T1;
|
||||
x0 = x0 / x1;
|
||||
if (x0 > 0xffffffff) {
|
||||
T0 = 0xffffffff;
|
||||
T1 = 1;
|
||||
} else {
|
||||
T0 = x0;
|
||||
T1 = 0;
|
||||
}
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_sdiv_T1_T0(void)
|
||||
{
|
||||
int64_t x0;
|
||||
int32_t x1;
|
||||
|
||||
x0 = T0 | ((uint64_t) (env->y) << 32);
|
||||
x1 = T1;
|
||||
x0 = x0 / x1;
|
||||
if ((int32_t) x0 != x0) {
|
||||
T0 = x0 >> 63;
|
||||
T1 = 1;
|
||||
} else {
|
||||
T0 = x0;
|
||||
T1 = 0;
|
||||
}
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_div_cc(void)
|
||||
{
|
||||
env->psr = 0;
|
||||
if (!T0)
|
||||
env->psr |= PSR_ZERO;
|
||||
if ((int) T0 < 0)
|
||||
env->psr |= PSR_NEG;
|
||||
if (T1)
|
||||
env->psr |= PSR_OVF;
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_subx_T1_T0(void)
|
||||
{
|
||||
T0 -= T1 + ((env->psr & PSR_CARRY) ? 1 : 0);
|
||||
}
|
||||
|
||||
void OPPROTO op_logic_T0_cc(void)
|
||||
{
|
||||
env->psr = 0;
|
||||
if (!T0)
|
||||
env->psr |= PSR_ZERO;
|
||||
if ((int) T0 < 0)
|
||||
env->psr |= PSR_NEG;
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_set_flags(void)
|
||||
{
|
||||
env->psr = 0;
|
||||
if (!T0)
|
||||
env->psr |= PSR_ZERO;
|
||||
if ((unsigned int) T0 < (unsigned int) T1)
|
||||
env->psr |= PSR_CARRY;
|
||||
if ((int) T0 < (int) T1)
|
||||
env->psr |= PSR_OVF;
|
||||
if ((int) T0 < 0)
|
||||
env->psr |= PSR_NEG;
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_sll(void)
|
||||
{
|
||||
T0 <<= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_srl(void)
|
||||
{
|
||||
T0 >>= T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_sra(void)
|
||||
{
|
||||
T0 = ((int32_t) T0) >> T1;
|
||||
}
|
||||
|
||||
void OPPROTO op_st(void)
|
||||
{
|
||||
stl((void *) T0, T1);
|
||||
}
|
||||
|
||||
void OPPROTO op_stb(void)
|
||||
{
|
||||
stb((void *) T0, T1);
|
||||
}
|
||||
|
||||
void OPPROTO op_sth(void)
|
||||
{
|
||||
stw((void *) T0, T1);
|
||||
}
|
||||
|
||||
void OPPROTO op_std(void)
|
||||
{
|
||||
stl((void *) T0, T1);
|
||||
stl((void *) (T0 + 4), T2);
|
||||
}
|
||||
|
||||
void OPPROTO op_ld(void)
|
||||
{
|
||||
T1 = ldl((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldub(void)
|
||||
{
|
||||
T1 = ldub((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_lduh(void)
|
||||
{
|
||||
T1 = lduw((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldsb(void)
|
||||
{
|
||||
T1 = ldsb((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldsh(void)
|
||||
{
|
||||
T1 = ldsw((void *) T0);
|
||||
}
|
||||
|
||||
void OPPROTO op_ldstub(void)
|
||||
{
|
||||
T1 = ldub((void *) T0);
|
||||
stb((void *) T0, 0xff); /* XXX: Should be Atomically */
|
||||
}
|
||||
|
||||
void OPPROTO op_swap(void)
|
||||
{
|
||||
unsigned int tmp = ldl((void *) T0);
|
||||
stl((void *) T0, T1); /* XXX: Should be Atomically */
|
||||
T1 = tmp;
|
||||
}
|
||||
|
||||
void OPPROTO op_ldd(void)
|
||||
{
|
||||
T1 = ldl((void *) T0);
|
||||
T0 = ldl((void *) (T0 + 4));
|
||||
}
|
||||
|
||||
void OPPROTO op_wry(void)
|
||||
{
|
||||
env->y = T0;
|
||||
}
|
||||
|
||||
void OPPROTO op_rdy(void)
|
||||
{
|
||||
T0 = env->y;
|
||||
}
|
||||
|
||||
void raise_exception(int tt)
|
||||
{
|
||||
env->exception_index = tt;
|
||||
cpu_loop_exit();
|
||||
}
|
||||
|
||||
void memcpy32(uint32_t *dst, const uint32_t *src)
|
||||
{
|
||||
dst[0] = src[0];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[2];
|
||||
dst[3] = src[3];
|
||||
dst[4] = src[4];
|
||||
dst[5] = src[5];
|
||||
dst[6] = src[6];
|
||||
dst[7] = src[7];
|
||||
}
|
||||
|
||||
static inline void set_cwp(int new_cwp)
|
||||
{
|
||||
/* put the modified wrap registers at their proper location */
|
||||
if (env->cwp == (NWINDOWS - 1))
|
||||
memcpy32(env->regbase, env->regbase + NWINDOWS * 16);
|
||||
env->cwp = new_cwp;
|
||||
/* put the wrap registers at their temporary location */
|
||||
if (new_cwp == (NWINDOWS - 1))
|
||||
memcpy32(env->regbase + NWINDOWS * 16, env->regbase);
|
||||
env->regwptr = env->regbase + (new_cwp * 16);
|
||||
}
|
||||
|
||||
/* XXX: use another pointer for %iN registers to avoid slow wrapping
|
||||
handling ? */
|
||||
void OPPROTO op_save(void)
|
||||
{
|
||||
int cwp;
|
||||
cwp = (env->cwp - 1) & (NWINDOWS - 1);
|
||||
if (env->wim & (1 << cwp)) {
|
||||
raise_exception(TT_WIN_OVF);
|
||||
}
|
||||
set_cwp(cwp);
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_restore(void)
|
||||
{
|
||||
int cwp;
|
||||
cwp = (env->cwp + 1) & (NWINDOWS - 1);
|
||||
if (env->wim & (1 << cwp)) {
|
||||
raise_exception(TT_WIN_UNF);
|
||||
}
|
||||
set_cwp(cwp);
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_exception(void)
|
||||
{
|
||||
env->exception_index = PARAM1;
|
||||
cpu_loop_exit();
|
||||
}
|
||||
|
||||
void OPPROTO op_trap_T0(void)
|
||||
{
|
||||
env->exception_index = TT_TRAP + (T0 & 0x7f);
|
||||
cpu_loop_exit();
|
||||
}
|
||||
|
||||
void OPPROTO op_trapcc_T0(void)
|
||||
{
|
||||
if (T2) {
|
||||
env->exception_index = TT_TRAP + (T0 & 0x7f);
|
||||
cpu_loop_exit();
|
||||
}
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_exit_tb(void)
|
||||
{
|
||||
EXIT_TB();
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_be(void)
|
||||
{
|
||||
T2 = (env->psr & PSR_ZERO);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_ble(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T2 = Z | (N ^ V);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bl(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T2 = N ^ V;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bleu(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T2 = C | Z;
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bcs(void)
|
||||
{
|
||||
T2 = (env->psr & PSR_CARRY);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bvs(void)
|
||||
{
|
||||
T2 = (env->psr & PSR_OVF);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bneg(void)
|
||||
{
|
||||
T2 = (env->psr & PSR_NEG);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bne(void)
|
||||
{
|
||||
T2 = !(env->psr & PSR_ZERO);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bg(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T2 = !(Z | (N ^ V));
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bge(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T2 = !(N ^ V);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bgu(void)
|
||||
{
|
||||
GET_FLAGS;
|
||||
T2 = !(C | Z);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bcc(void)
|
||||
{
|
||||
T2 = !(env->psr & PSR_CARRY);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bpos(void)
|
||||
{
|
||||
T2 = !(env->psr & PSR_NEG);
|
||||
}
|
||||
|
||||
void OPPROTO op_eval_bvc(void)
|
||||
{
|
||||
T2 = !(env->psr & PSR_OVF);
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_T2_0(void)
|
||||
{
|
||||
T2 = 0;
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_T2_1(void)
|
||||
{
|
||||
T2 = 1;
|
||||
}
|
||||
|
||||
void OPPROTO op_jmp_im(void)
|
||||
{
|
||||
env->pc = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_npc_im(void)
|
||||
{
|
||||
env->npc = PARAM1;
|
||||
}
|
||||
|
||||
void OPPROTO op_movl_npc_T0(void)
|
||||
{
|
||||
env->npc = T0;
|
||||
}
|
||||
|
||||
void OPPROTO op_next_insn(void)
|
||||
{
|
||||
env->pc = env->npc;
|
||||
env->npc = env->npc + 4;
|
||||
}
|
||||
|
||||
void OPPROTO op_generic_branch(void)
|
||||
{
|
||||
if (T2) {
|
||||
env->npc = PARAM1;
|
||||
} else {
|
||||
env->npc = PARAM2;
|
||||
}
|
||||
FORCE_RET();
|
||||
}
|
||||
|
||||
void OPPROTO op_generic_branch_a(void)
|
||||
{
|
||||
if (T2) {
|
||||
env->pc = PARAM2;
|
||||
env->npc = PARAM1;
|
||||
} else {
|
||||
env->pc = PARAM2 + 4;
|
||||
env->npc = PARAM2 + 8;
|
||||
}
|
||||
FORCE_RET();
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ endif
|
||||
TESTS+=sha1# test_path
|
||||
#TESTS+=test_path
|
||||
|
||||
QEMU=../i386/qemu-i386
|
||||
QEMU=../i386-user/qemu-i386
|
||||
|
||||
all: $(TESTS)
|
||||
|
||||
@@ -65,5 +65,11 @@ hello-arm: hello-arm.o
|
||||
hello-arm.o: hello-arm.c
|
||||
arm-linux-gcc -Wall -g -O2 -c -o $@ $<
|
||||
|
||||
# XXX: find a way to compile easily a test for each arch
|
||||
test2:
|
||||
@for arch in i386 arm sparc ppc; do \
|
||||
../$${arch}-user/qemu-$${arch} $${arch}/ls -l linux-test.c ; \
|
||||
done
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o $(TESTS)
|
||||
|
242
tests/sha1.c
Normal file
242
tests/sha1.c
Normal file
@@ -0,0 +1,242 @@
|
||||
|
||||
/* from valgrind tests */
|
||||
|
||||
/* ================ sha1.c ================ */
|
||||
/*
|
||||
SHA-1 in C
|
||||
By Steve Reid <steve@edmweb.com>
|
||||
100% Public Domain
|
||||
|
||||
Test Vectors (from FIPS PUB 180-1)
|
||||
"abc"
|
||||
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
A million repetitions of "a"
|
||||
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
*/
|
||||
|
||||
/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */
|
||||
/* #define SHA1HANDSOFF * Copies data before messing with it. */
|
||||
|
||||
#define SHA1HANDSOFF
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h> /* for u_int*_t */
|
||||
|
||||
/* ================ sha1.h ================ */
|
||||
/*
|
||||
SHA-1 in C
|
||||
By Steve Reid <steve@edmweb.com>
|
||||
100% Public Domain
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
u_int32_t state[5];
|
||||
u_int32_t count[2];
|
||||
unsigned char buffer[64];
|
||||
} SHA1_CTX;
|
||||
|
||||
void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]);
|
||||
void SHA1Init(SHA1_CTX* context);
|
||||
void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len);
|
||||
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
|
||||
/* ================ end of sha1.h ================ */
|
||||
#include <endian.h>
|
||||
|
||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||
|
||||
/* blk0() and blk() perform the initial expand. */
|
||||
/* I got the idea of expanding during the round function from SSLeay */
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|
||||
|(rol(block->l[i],8)&0x00FF00FF))
|
||||
#elif BYTE_ORDER == BIG_ENDIAN
|
||||
#define blk0(i) block->l[i]
|
||||
#else
|
||||
#error "Endianness not defined!"
|
||||
#endif
|
||||
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
||||
^block->l[(i+2)&15]^block->l[i&15],1))
|
||||
|
||||
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
||||
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
||||
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
|
||||
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
|
||||
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
|
||||
|
||||
|
||||
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
||||
|
||||
void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
|
||||
{
|
||||
u_int32_t a, b, c, d, e;
|
||||
typedef union {
|
||||
unsigned char c[64];
|
||||
u_int32_t l[16];
|
||||
} CHAR64LONG16;
|
||||
#ifdef SHA1HANDSOFF
|
||||
CHAR64LONG16 block[1]; /* use array to appear as a pointer */
|
||||
memcpy(block, buffer, 64);
|
||||
#else
|
||||
/* The following had better never be used because it causes the
|
||||
* pointer-to-const buffer to be cast into a pointer to non-const.
|
||||
* And the result is written through. I threw a "const" in, hoping
|
||||
* this will cause a diagnostic.
|
||||
*/
|
||||
CHAR64LONG16* block = (const CHAR64LONG16*)buffer;
|
||||
#endif
|
||||
/* Copy context->state[] to working vars */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
/* 4 rounds of 20 operations each. Loop unrolled. */
|
||||
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
|
||||
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
|
||||
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
|
||||
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
|
||||
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
||||
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
|
||||
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
|
||||
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
|
||||
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
|
||||
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
|
||||
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
|
||||
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
|
||||
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
|
||||
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
|
||||
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
|
||||
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
|
||||
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
|
||||
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
|
||||
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
|
||||
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
|
||||
/* Add the working vars back into context.state[] */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
/* Wipe variables */
|
||||
a = b = c = d = e = 0;
|
||||
#ifdef SHA1HANDSOFF
|
||||
memset(block, '\0', sizeof(block));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* SHA1Init - Initialize new context */
|
||||
|
||||
void SHA1Init(SHA1_CTX* context)
|
||||
{
|
||||
/* SHA1 initialization constants */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xEFCDAB89;
|
||||
context->state[2] = 0x98BADCFE;
|
||||
context->state[3] = 0x10325476;
|
||||
context->state[4] = 0xC3D2E1F0;
|
||||
context->count[0] = context->count[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Run your data through this. */
|
||||
|
||||
void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len)
|
||||
{
|
||||
u_int32_t i;
|
||||
u_int32_t j;
|
||||
|
||||
j = context->count[0];
|
||||
if ((context->count[0] += len << 3) < j)
|
||||
context->count[1]++;
|
||||
context->count[1] += (len>>29);
|
||||
j = (j >> 3) & 63;
|
||||
if ((j + len) > 63) {
|
||||
memcpy(&context->buffer[j], data, (i = 64-j));
|
||||
SHA1Transform(context->state, context->buffer);
|
||||
for ( ; i + 63 < len; i += 64) {
|
||||
SHA1Transform(context->state, &data[i]);
|
||||
}
|
||||
j = 0;
|
||||
}
|
||||
else i = 0;
|
||||
memcpy(&context->buffer[j], &data[i], len - i);
|
||||
}
|
||||
|
||||
|
||||
/* Add padding and return the message digest. */
|
||||
|
||||
void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned char finalcount[8];
|
||||
unsigned char c;
|
||||
|
||||
#if 0 /* untested "improvement" by DHR */
|
||||
/* Convert context->count to a sequence of bytes
|
||||
* in finalcount. Second element first, but
|
||||
* big-endian order within element.
|
||||
* But we do it all backwards.
|
||||
*/
|
||||
unsigned char *fcp = &finalcount[8];
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
u_int32_t t = context->count[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 4; t >>= 8, j++)
|
||||
*--fcp = (unsigned char) t
|
||||
}
|
||||
#else
|
||||
for (i = 0; i < 8; i++) {
|
||||
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
|
||||
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
||||
}
|
||||
#endif
|
||||
c = 0200;
|
||||
SHA1Update(context, &c, 1);
|
||||
while ((context->count[0] & 504) != 448) {
|
||||
c = 0000;
|
||||
SHA1Update(context, &c, 1);
|
||||
}
|
||||
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
|
||||
for (i = 0; i < 20; i++) {
|
||||
digest[i] = (unsigned char)
|
||||
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
||||
}
|
||||
/* Wipe variables */
|
||||
memset(context, '\0', sizeof(*context));
|
||||
memset(&finalcount, '\0', sizeof(finalcount));
|
||||
}
|
||||
/* ================ end of sha1.c ================ */
|
||||
|
||||
#define BUFSIZE 4096
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
SHA1_CTX ctx;
|
||||
unsigned char hash[20], buf[BUFSIZE];
|
||||
int i;
|
||||
|
||||
for(i=0;i<BUFSIZE;i++)
|
||||
buf[i] = i;
|
||||
|
||||
SHA1Init(&ctx);
|
||||
for(i=0;i<1000;i++)
|
||||
SHA1Update(&ctx, buf, BUFSIZE);
|
||||
SHA1Final(hash, &ctx);
|
||||
|
||||
printf("SHA1=");
|
||||
for(i=0;i<20;i++)
|
||||
printf("%02x", hash[i]);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#define TEST_CMOV 0
|
||||
#define TEST_FCOMI 0
|
||||
//#define LINUX_VM86_IOPL_FIX
|
||||
//#define TEST_P4_FLAGS
|
||||
|
||||
#define xglue(x, y) x ## y
|
||||
#define glue(x, y) xglue(x, y)
|
||||
@@ -352,7 +353,11 @@ void test_jcc(void)
|
||||
}
|
||||
|
||||
#undef CC_MASK
|
||||
#ifdef TEST_P4_FLAGS
|
||||
#define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
|
||||
#else
|
||||
#define CC_MASK (CC_O | CC_C)
|
||||
#endif
|
||||
|
||||
#define OP mul
|
||||
#include "test-i386-muldiv.h"
|
||||
@@ -360,15 +365,6 @@ void test_jcc(void)
|
||||
#define OP imul
|
||||
#include "test-i386-muldiv.h"
|
||||
|
||||
#undef CC_MASK
|
||||
#define CC_MASK (0)
|
||||
|
||||
#define OP div
|
||||
#include "test-i386-muldiv.h"
|
||||
|
||||
#define OP idiv
|
||||
#include "test-i386-muldiv.h"
|
||||
|
||||
void test_imulw2(int op0, int op1)
|
||||
{
|
||||
int res, s1, s0, flags;
|
||||
@@ -405,6 +401,15 @@ void test_imull2(int op0, int op1)
|
||||
"imull", s0, s1, res, flags & CC_MASK);
|
||||
}
|
||||
|
||||
#undef CC_MASK
|
||||
#define CC_MASK (0)
|
||||
|
||||
#define OP div
|
||||
#include "test-i386-muldiv.h"
|
||||
|
||||
#define OP idiv
|
||||
#include "test-i386-muldiv.h"
|
||||
|
||||
void test_mul(void)
|
||||
{
|
||||
test_imulb(0x1234561d, 4);
|
||||
@@ -658,6 +663,45 @@ void test_fenv(void)
|
||||
TEST_ENV(&float_env32, "");
|
||||
}
|
||||
|
||||
|
||||
#define TEST_FCMOV(a, b, eflags, CC)\
|
||||
{\
|
||||
double res;\
|
||||
asm("push %3\n"\
|
||||
"popf\n"\
|
||||
"fcmov" CC " %2, %0\n"\
|
||||
: "=t" (res)\
|
||||
: "0" (a), "u" (b), "g" (eflags));\
|
||||
printf("fcmov%s eflags=0x%04x-> %f\n", \
|
||||
CC, eflags, res);\
|
||||
}
|
||||
|
||||
void test_fcmov(void)
|
||||
{
|
||||
double a, b;
|
||||
int eflags, i;
|
||||
|
||||
a = 1.0;
|
||||
b = 2.0;
|
||||
for(i = 0; i < 4; i++) {
|
||||
eflags = 0;
|
||||
if (i & 1)
|
||||
eflags |= CC_C;
|
||||
if (i & 2)
|
||||
eflags |= CC_Z;
|
||||
TEST_FCMOV(a, b, eflags, "b");
|
||||
TEST_FCMOV(a, b, eflags, "e");
|
||||
TEST_FCMOV(a, b, eflags, "be");
|
||||
TEST_FCMOV(a, b, eflags, "nb");
|
||||
TEST_FCMOV(a, b, eflags, "ne");
|
||||
TEST_FCMOV(a, b, eflags, "nbe");
|
||||
}
|
||||
TEST_FCMOV(a, b, 0, "u");
|
||||
TEST_FCMOV(a, b, CC_P, "u");
|
||||
TEST_FCMOV(a, b, 0, "nu");
|
||||
TEST_FCMOV(a, b, CC_P, "nu");
|
||||
}
|
||||
|
||||
void test_floats(void)
|
||||
{
|
||||
test_fops(2, 3);
|
||||
@@ -675,6 +719,9 @@ void test_floats(void)
|
||||
test_fbcd(1234567890123456);
|
||||
test_fbcd(-123451234567890);
|
||||
test_fenv();
|
||||
if (TEST_CMOV) {
|
||||
test_fcmov();
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************/
|
||||
|
@@ -190,9 +190,9 @@ int cpu_restore_state(TranslationBlock *tb,
|
||||
#elif defined(TARGET_ARM)
|
||||
env->regs[15] = gen_opc_pc[j];
|
||||
#elif defined(TARGET_SPARC)
|
||||
env->pc = gen_opc_pc[j];
|
||||
env->pc = gen_opc_pc[j];
|
||||
#elif defined(TARGET_PPC)
|
||||
env->nip = gen_opc_pc[j];
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
47
vl.h
47
vl.h
@@ -27,6 +27,7 @@
|
||||
/* vl.c */
|
||||
struct CPUX86State;
|
||||
extern int reset_requested;
|
||||
extern int64_t ticks_per_sec;
|
||||
|
||||
typedef void (IOPortWriteFunc)(struct CPUX86State *env, uint32_t address, uint32_t data);
|
||||
typedef uint32_t (IOPortReadFunc)(struct CPUX86State *env, uint32_t address);
|
||||
@@ -34,6 +35,8 @@ typedef uint32_t (IOPortReadFunc)(struct CPUX86State *env, uint32_t address);
|
||||
void *get_mmap_addr(unsigned long size);
|
||||
int register_ioport_read(int start, int length, IOPortReadFunc *func, int size);
|
||||
int register_ioport_write(int start, int length, IOPortWriteFunc *func, int size);
|
||||
void pic_set_irq(int irq, int level);
|
||||
int64_t cpu_get_ticks(void);
|
||||
|
||||
void kbd_put_keycode(int keycode);
|
||||
|
||||
@@ -97,4 +100,48 @@ void vga_update_display(void);
|
||||
/* sdl.c */
|
||||
void sdl_display_init(DisplayState *ds);
|
||||
|
||||
/* ide.c */
|
||||
#define MAX_DISKS 4
|
||||
|
||||
extern BlockDriverState *bs_table[MAX_DISKS];
|
||||
|
||||
void ide_init(void);
|
||||
void ide_set_geometry(int n, int cyls, int heads, int secs);
|
||||
void ide_set_cdrom(int n, int is_cdrom);
|
||||
|
||||
/* oss.c */
|
||||
typedef enum {
|
||||
AUD_FMT_U8,
|
||||
AUD_FMT_S8,
|
||||
AUD_FMT_U16,
|
||||
AUD_FMT_S16
|
||||
} audfmt_e;
|
||||
|
||||
void AUD_open (int rfreq, int rnchannels, audfmt_e rfmt);
|
||||
void AUD_reset (int rfreq, int rnchannels, audfmt_e rfmt);
|
||||
int AUD_write (void *in_buf, int size);
|
||||
void AUD_run (void);
|
||||
void AUD_adjust_estimate (int _leftover);
|
||||
int AUD_get_free (void);
|
||||
int AUD_get_live (void);
|
||||
int AUD_get_buffer_size (void);
|
||||
void AUD_init (void);
|
||||
|
||||
/* dma.c */
|
||||
typedef int (*DMA_read_handler) (uint32_t addr, int size, int *irq);
|
||||
typedef int (*DMA_misc_handler) (int);
|
||||
|
||||
int DMA_get_channel_mode (int nchan);
|
||||
void DMA_hold_DREQ (int nchan);
|
||||
void DMA_release_DREQ (int nchan);
|
||||
void DMA_run (void);
|
||||
void DMA_init (void);
|
||||
void DMA_register_channel (int nchan,
|
||||
DMA_read_handler read_handler,
|
||||
DMA_misc_handler misc_handler);
|
||||
|
||||
/* sb16.c */
|
||||
void SB16_run (void);
|
||||
void SB16_init (void);
|
||||
|
||||
#endif /* VL_H */
|
||||
|
Reference in New Issue
Block a user