New upstream version 2.0pre9.2
Some checks failed
Master / Scheduled (FULL) (push) Has been cancelled
Master / Triggered (push) Has been cancelled
Master / Triggered (ASAN) (push) Has been cancelled
Master / Triggered (FULL) (push) Has been cancelled

This commit is contained in:
geos_one
2025-08-10 12:35:43 +02:00
commit 91736529d5
1056 changed files with 370820 additions and 0 deletions

36
test/cpu/Makefile Normal file
View File

@@ -0,0 +1,36 @@
include ../../Makefile.conf
DJGPP = i586-pc-msdosdjgpp-gcc
DJFLAGS=-Wall -O2 -g -gdwarf-2 -fno-strict-aliasing -fno-pic -fno-pie -no-pie
# Force CC to gcc, as clang compiled binary segfaults
CC = gcc
CFLAGS := $(DJFLAGS)
ifeq ($(CC), clang)
CFLAGS += -fno-integrated-as -fverbose-asm
endif
LDFLAGS=
SOURCES = test-i386.c test-i386-code16.S test-i386-vm86.S
ALL_SRC = $(SOURCES) $(wildcard *.h)
all: dosbin.exe
reffile.log: native32
./native32 --common-tests > $@
# i386/x86_64 emulation test (test various opcodes) */
dosbin.exe: $(ALL_SRC)
$(DJGPP) $(DJFLAGS) $(LDFLAGS) -o $@ $(SOURCES) -lm
native32: $(ALL_SRC)
$(CC) -m32 $(CFLAGS) $(LDFLAGS) -o $@ $(SOURCES) -lm
native64: test-i386.c \
test-i386.h test-i386-shift.h test-i386-muldiv.h
$(CC) -m64 $(CFLAGS) $(LDFLAGS) -o $@ $(<D)/test-i386.c -lm
clean:
rm -f *~ *.o dosbin.exe native32 native64

4493
test/cpu/reffile.log Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,83 @@
.code16
.globl code16_start
.globl code16_end
CS_SEG = 0xf
code16_start:
.globl code16_func1
/* basic test */
code16_func1:
mov $1, %eax
data32 lret
/* test push/pop in 16 bit mode */
.globl code16_func2
code16_func2:
xor %eax, %eax
mov $0x12345678, %ebx
movl %esp, %ecx
push %bx
subl %esp, %ecx
pop %ax
data32 lret
/* test various jmp opcodes */
.globl code16_func3
code16_func3:
jmp 1f
nop
1:
mov $4, %eax
mov $0x12345678, %ebx
xor %bx, %bx
jz 2f
add $2, %ax
2:
call myfunc
lcall $CS_SEG, $(myfunc2 - code16_start)
ljmp $CS_SEG, $(myjmp1 - code16_start)
myjmp1_next:
cs lcall *myfunc2_addr - code16_start
cs ljmp *myjmp2_addr - code16_start
myjmp2_next:
data32 lret
myfunc2_addr:
.short myfunc2 - code16_start
.short CS_SEG
myjmp2_addr:
.short myjmp2 - code16_start
.short CS_SEG
myjmp1:
add $8, %ax
jmp myjmp1_next
myjmp2:
add $16, %ax
jmp myjmp2_next
myfunc:
add $1, %ax
ret
myfunc2:
add $4, %ax
lret
code16_end:
#ifdef __ELF__
.section .note.GNU-stack,"",%progbits
#endif

View File

@@ -0,0 +1,76 @@
void glue(glue(test_, OP), b)(long op0, long op1)
{
long res, s1, s0, flags;
s0 = op0;
s1 = op1;
res = s0;
flags = 0;
asm ("push %4\n\t"
"popf\n\t"
stringify(OP)"b %b2\n\t"
"pushf\n\t"
"pop %1\n\t"
: "=a" (res), "=g" (flags)
: "q" (s1), "0" (res), "1" (flags));
printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CC=%04lx\n",
stringify(OP) "b", s0, s1, res, flags & CC_MASK);
}
void glue(glue(test_, OP), w)(long op0h, long op0, long op1)
{
long res, s1, flags, resh;
s1 = op1;
resh = op0h;
res = op0;
flags = 0;
asm ("push %5\n\t"
"popf\n\t"
stringify(OP) "w %w3\n\t"
"pushf\n\t"
"pop %1\n\t"
: "=a" (res), "=g" (flags), "=d" (resh)
: "q" (s1), "0" (res), "1" (flags), "2" (resh));
printf("%-10s AH=" FMTLX " AL=" FMTLX " B=" FMTLX " RH=" FMTLX " RL=" FMTLX " CC=%04lx\n",
stringify(OP) "w", op0h, op0, s1, resh, res, flags & CC_MASK);
}
void glue(glue(test_, OP), l)(long op0h, long op0, long op1)
{
long res, s1, flags, resh;
s1 = op1;
resh = op0h;
res = op0;
flags = 0;
asm ("push %5\n\t"
"popf\n\t"
stringify(OP) "l %k3\n\t"
"pushf\n\t"
"pop %1\n\t"
: "=a" (res), "=g" (flags), "=d" (resh)
: "q" (s1), "0" (res), "1" (flags), "2" (resh));
printf("%-10s AH=" FMTLX " AL=" FMTLX " B=" FMTLX " RH=" FMTLX " RL=" FMTLX " CC=%04lx\n",
stringify(OP) "l", op0h, op0, s1, resh, res, flags & CC_MASK);
}
#if defined(__x86_64__)
void glue(glue(test_, OP), q)(long op0h, long op0, long op1)
{
long res, s1, flags, resh;
s1 = op1;
resh = op0h;
res = op0;
flags = 0;
asm ("push %5\n\t"
"popf\n\t"
stringify(OP) "q %3\n\t"
"pushf\n\t"
"pop %1\n\t"
: "=a" (res), "=g" (flags), "=d" (resh)
: "q" (s1), "0" (res), "1" (flags), "2" (resh));
printf("%-10s AH=" FMTLX " AL=" FMTLX " B=" FMTLX " RH=" FMTLX " RL=" FMTLX " CC=%04lx\n",
stringify(OP) "q", op0h, op0, s1, resh, res, flags & CC_MASK);
}
#endif
#undef OP

186
test/cpu/test-i386-shift.h Normal file
View File

@@ -0,0 +1,186 @@
#define exec_op glue(exec_, OP)
#define exec_opq glue(glue(exec_, OP), q)
#define exec_opl glue(glue(exec_, OP), l)
#define exec_opw glue(glue(exec_, OP), w)
#define exec_opb glue(glue(exec_, OP), b)
#ifndef OP_SHIFTD
#ifdef OP_NOBYTE
#define EXECSHIFT(size, rsize, res, s1, s2, flags) \
asm ("push %4\n\t"\
"popf\n\t"\
stringify(OP) size " %" rsize "2, %" rsize "0\n\t" \
"pushf\n\t"\
"pop %1\n\t"\
: "=g" (res), "=g" (flags)\
: "r" (s1), "0" (res), "1" (flags));
#else
#define EXECSHIFT(size, rsize, res, s1, s2, flags) \
asm ("push %4\n\t"\
"popf\n\t"\
stringify(OP) size " %%cl, %" rsize "0\n\t" \
"pushf\n\t"\
"pop %1\n\t"\
: "=q" (res), "=g" (flags)\
: "c" (s1), "0" (res), "1" (flags));
#endif
#if defined(__x86_64__)
void exec_opq(long s2, long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECSHIFT("q", "", res, s1, s2, flags);
/* overflow is undefined if count != 1 */
if (s1 != 1)
flags &= ~CC_O;
printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
stringify(OP) "q", s0, s1, res, iflags, flags & CC_MASK);
}
#endif
void exec_opl(long s2, long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECSHIFT("l", "k", res, s1, s2, flags);
/* overflow is undefined if count != 1 */
if (s1 != 1)
flags &= ~CC_O;
printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
}
void exec_opw(long s2, long s0, long s1, long iflags)
{
long res, flags;
if ((strcmp(stringify(OP), "shld") == 0 ||
strcmp(stringify(OP), "shrd") == 0) && s1 > 16)
return;
res = s0;
flags = iflags;
EXECSHIFT("w", "w", res, s1, s2, flags);
/* overflow is undefined if count != 1 */
if (s1 != 1)
flags &= ~CC_O;
printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
}
#else
#define EXECSHIFT(size, rsize, res, s1, s2, flags) \
asm ("push %4\n\t"\
"popf\n\t"\
stringify(OP) size " %%cl, %" rsize "5, %" rsize "0\n\t" \
"pushf\n\t"\
"pop %1\n\t"\
: "=g" (res), "=g" (flags)\
: "c" (s1), "0" (res), "1" (flags), "r" (s2));
#if defined(__x86_64__)
void exec_opq(long s2, long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECSHIFT("q", "", res, s1, s2, flags);
/* overflow is undefined if count != 1 */
if (s1 != 1)
flags &= ~CC_O;
printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
stringify(OP) "q", s0, s2, s1, res, iflags, flags & CC_MASK);
}
#endif
void exec_opl(long s2, long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECSHIFT("l", "k", res, s1, s2, flags);
/* overflow is undefined if count != 1 */
if (s1 != 1)
flags &= ~CC_O;
printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
stringify(OP) "l", s0, s2, s1, res, iflags, flags & CC_MASK);
}
void exec_opw(long s2, long s0, long s1, long iflags)
{
long res, flags;
if ((strcmp(stringify(OP), "shld") == 0 ||
strcmp(stringify(OP), "shrd") == 0) && s1 > 16)
return;
res = s0;
flags = iflags;
EXECSHIFT("w", "w", res, s1, s2, flags);
/* overflow is undefined if count != 1 */
if (s1 != 1)
flags &= ~CC_O;
printf("%-10s A=" FMTLX " B=" FMTLX " C=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
stringify(OP) "w", s0, s2, s1, res, iflags, flags & CC_MASK);
}
#endif
#ifndef OP_NOBYTE
void exec_opb(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECSHIFT("b", "b", res, s1, 0, flags);
/* overflow is undefined if count != 1 */
if (s1 != 1)
flags &= ~CC_O;
printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n",
stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
}
#endif
void exec_op(long s2, long s0, long s1)
{
s2 = i2l(s2);
s0 = i2l(s0);
#if defined(__x86_64__)
exec_opq(s2, s0, s1, 0);
#endif
exec_opl(s2, s0, s1, 0);
exec_opw(s2, s0, s1, 0);
#ifndef OP_NOBYTE
exec_opb(s0, s1, 0);
#endif
#ifdef OP_CC
#if defined(__x86_64__)
exec_opq(s2, s0, s1, CC_C);
#endif
exec_opl(s2, s0, s1, CC_C);
exec_opw(s2, s0, s1, CC_C);
exec_opb(s0, s1, CC_C);
#endif
}
void glue(test_, OP)(void)
{
int i, n;
#if defined(__x86_64__)
n = 64;
#else
n = 32;
#endif
for(i = 0; i < n; i++)
exec_op(0x21ad3d34, 0x12345678, i);
for(i = 0; i < n; i++)
exec_op(0x813f3421, 0x82345679, i);
}
#undef OP
#undef OP_CC
#undef OP_SHIFTD
#undef OP_NOBYTE
#undef EXECSHIFT

111
test/cpu/test-i386-vm86.S Normal file
View File

@@ -0,0 +1,111 @@
.code16
.globl vm86_code_start
.globl vm86_code_end
#define GET_OFFSET(x) ((x) - vm86_code_start + 0x100)
vm86_code_start:
movw $GET_OFFSET(hello_world), %dx
movb $0x09, %ah
int $0x21
/* prepare int 0x90 vector */
xorw %ax, %ax
movw %ax, %es
es movw $GET_OFFSET(int90_test), 0x90 * 4
es movw %cs, 0x90 * 4 + 2
/* launch int 0x90 */
int $0x90
/* test IF support */
movw $GET_OFFSET(IF_msg), %dx
movb $0x09, %ah
int $0x21
pushf
popw %dx
movb $0xff, %ah
int $0x21
cli
pushf
popw %dx
movb $0xff, %ah
int $0x21
sti
pushfl
popl %edx
movb $0xff, %ah
int $0x21
#if 0
movw $GET_OFFSET(IF_msg1), %dx
movb $0x09, %ah
int $0x21
pushf
movw %sp, %bx
andw $~0x200, (%bx)
popf
#else
cli
#endif
pushf
popw %dx
movb $0xff, %ah
int $0x21
pushfl
movw %sp, %bx
orw $0x200, (%bx)
popfl
pushfl
popl %edx
movb $0xff, %ah
int $0x21
movb $0x00, %ah
#ifdef __DJGPP__
lret
#else
int $0x21
#endif
int90_test:
pushf
pop %dx
movb $0xff, %ah
int $0x21
movw %sp, %bx
movw 4(%bx), %dx
movb $0xff, %ah
int $0x21
movw $GET_OFFSET(int90_msg), %dx
movb $0x09, %ah
int $0x21
iret
int90_msg:
.string "INT90 started\n$"
hello_world:
.string "Hello VM86 world\n$"
IF_msg:
.string "VM86 IF test\n$"
IF_msg1:
.string "If you see a diff here, your Linux kernel is buggy, please update to 2.4.20 kernel\n$"
vm86_code_end:
#ifdef __ELF__
.section .note.GNU-stack,"",%progbits
#endif

3107
test/cpu/test-i386.c Normal file

File diff suppressed because it is too large Load Diff

150
test/cpu/test-i386.h Normal file
View File

@@ -0,0 +1,150 @@
#define exec_op glue(exec_, OP)
#define exec_opq glue(glue(exec_, OP), q)
#define exec_opl glue(glue(exec_, OP), l)
#define exec_opw glue(glue(exec_, OP), w)
#define exec_opb glue(glue(exec_, OP), b)
#define EXECOP2(size, rsize, res, s1, flags) \
asm ("push %4\n\t"\
"popf\n\t"\
stringify(OP) size " %" rsize "2, %" rsize "0\n\t" \
"pushf\n\t"\
"pop %1\n\t"\
: "=q" (res), "=g" (flags)\
: "q" (s1), "0" (res), "1" (flags)); \
printf("%-10s A=" FMTLX " B=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", \
stringify(OP) size, s0, s1, res, iflags, flags & CC_MASK);
#define EXECOP1(size, rsize, res, flags) \
asm ("push %3\n\t"\
"popf\n\t"\
stringify(OP) size " %" rsize "0\n\t" \
"pushf\n\t"\
"pop %1\n\t"\
: "=q" (res), "=g" (flags)\
: "0" (res), "1" (flags)); \
printf("%-10s A=" FMTLX " R=" FMTLX " CCIN=%04lx CC=%04lx\n", \
stringify(OP) size, s0, res, iflags, flags & CC_MASK);
#ifdef OP1
#if defined(__x86_64__)
void exec_opq(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP1("q", "", res, flags);
}
#endif
void exec_opl(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP1("l", "k", res, flags);
}
void exec_opw(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP1("w", "w", res, flags);
}
void exec_opb(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP1("b", "b", res, flags);
}
#else
#if defined(__x86_64__)
void exec_opq(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP2("q", "", res, s1, flags);
}
#endif
void exec_opl(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP2("l", "k", res, s1, flags);
}
void exec_opw(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP2("w", "w", res, s1, flags);
}
void exec_opb(long s0, long s1, long iflags)
{
long res, flags;
res = s0;
flags = iflags;
EXECOP2("b", "b", res, s1, flags);
}
#endif
void exec_op(long s0, long s1)
{
s0 = i2l(s0);
s1 = i2l(s1);
#if defined(__x86_64__)
exec_opq(s0, s1, 0);
#endif
exec_opl(s0, s1, 0);
exec_opw(s0, s1, 0);
exec_opb(s0, s1, 0);
#ifdef OP_CC
#if defined(__x86_64__)
exec_opq(s0, s1, CC_C);
#endif
exec_opl(s0, s1, CC_C);
exec_opw(s0, s1, CC_C);
exec_opb(s0, s1, CC_C);
#endif
}
void glue(test_, OP)(void)
{
exec_op(0x12345678, 0x812FADA);
exec_op(0x12341, 0x12341);
exec_op(0x12341, -0x12341);
exec_op(0xffffffff, 0);
exec_op(0xffffffff, -1);
exec_op(0xffffffff, 1);
exec_op(0xffffffff, 2);
exec_op(0x7fffffff, 0);
exec_op(0x7fffffff, 1);
exec_op(0x7fffffff, -1);
exec_op(0x80000000, -1);
exec_op(0x80000000, 1);
exec_op(0x80000000, -2);
exec_op(0x12347fff, 0);
exec_op(0x12347fff, 1);
exec_op(0x12347fff, -1);
exec_op(0x12348000, -1);
exec_op(0x12348000, 1);
exec_op(0x12348000, -2);
exec_op(0x12347f7f, 0);
exec_op(0x12347f7f, 1);
exec_op(0x12347f7f, -1);
exec_op(0x12348080, -1);
exec_op(0x12348080, 1);
exec_op(0x12348080, -2);
}
#undef OP
#undef OP_CC