tests/tcg/e2k: remove C tests, add simple assembler add test

This commit is contained in:
Alibek Omarov 2021-05-28 00:04:53 +03:00 committed by Denis Drakhnia
parent 71c53a3825
commit d48d9d62c6
5 changed files with 172 additions and 21 deletions

View File

@ -1,15 +1,23 @@
# -*- Mode: makefile -*-
#
# Elbrus 2000 tests
E2K_SRC=$(SRC_PATH)/tests/tcg/e2k
VPATH+=$(E2K_SRC)
E2K_TESTS=hello-e2k
TESTS+=$(E2K_TESTS)
# E2K tests
#
# hello-e2k is a barebones app
#
hello-e2k: CFLAGS+=-ffreestanding
hello-e2k: LDFLAGS+=-nostdlib
E2K_SRC = $(SRC_PATH)/tests/tcg/e2k
E2K_ALL = $(wildcard $(E2K_SRC)/*.s)
TESTS = $(patsubst $(E2K_SRC)/%.s, %, $(E2K_ALL))
VPATH = $(E2K_SRC)
CROSS = e2k-linux-
AS = $(CROSS)as
LD = $(CROSS)ld
ASFLAGS = -mcpu=elbrus-v4 -g -I$(E2K_SRC)
LDFLAGS =
%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
%: %.o
$(LD) $(LDFLAGS) $< -o $@

View File

@ -1,9 +0,0 @@
#include <asm/e2k_api.h>
#include <asm/unistd.h>
#define MSG "Hello, world!\n"
void _start(void) {
__E2K_SYSCALL_3(LINUX_SYSCALL64_TRAPNUM, __NR_write, 1, MSG, sizeof(MSG));
__E2K_SYSCALL_1(LINUX_SYSCALL64_TRAPNUM, __NR_exit, 0);
}

123
tests/tcg/e2k/macros.inc Normal file
View File

@ -0,0 +1,123 @@
.set SYSCALL32_TRAPNUM, 0x1
.set SYSCALL64_TRAPNUM, 0x3
.set __NR_exit, 0x1
.set __NR_write, 0x4
.macro e2k_syscall_1 trapnum sysnum v1
{
addd 0x0, \sysnum, %b[0]
addd 0x0, \v1, %b[1]
sdisp %ctpr1, \trapnum
}
{
call %ctpr1, wbs = 0x4
}
.endm
.macro e2k_syscall_2 trapnum sysnum v1 v2
{
sdisp %ctpr1, \trapnum
addd 0x0, \sysnum, %b[0]
addd 0x0, \v1, %b[1]
addd 0x0, \v2, %b[2]
}
{
call %ctpr1, wbs = 0x4
}
.endm
.macro e2k_syscall_3 trapnum sysnum v1 v2 v3
{
sdisp %ctpr1, \trapnum
addd 0x0, \sysnum, %b[0]
addd 0x0, \v1, %b[1]
addd 0x0, \v2, %b[2]
addd 0x0, \v3, %b[3]
}
{
call %ctpr1, wbs = 0x4
}
.endm
.macro e2k_syscall_4 trapnum sysnum v1 v2 v3 v4
{
sdisp %ctpr1, \trapnum
addd 0x0, \sysnum, %b[0]
addd 0x0, \v1, %b[1]
addd 0x0, \v2, %b[2]
addd 0x0, \v3, %b[3]
addd 0x0, \v4, %b[4]
}
{
call %ctpr1, wbs = 0x4
}
.endm
.macro e2k_syscall_5 trapnum sysnum v1 v2 v3 v4 v5
{
sdisp %ctpr1, \trapnum
addd 0x0, \sysnum, %b[0]
addd 0x0, \v1, %b[1]
addd 0x0, \v2, %b[2]
addd 0x0, \v3, %b[3]
addd 0x0, \v4, %b[4]
addd 0x0, \v5, %b[5]
}
{
call %ctpr1, wbs = 0x4
}
.endm
.macro e2k_syscall_6 trapnum sysnum v1 v2 v3 v4 v5 v6
{
sdisp %ctpr1, \trapnum
addd 0x0, \sysnum, %b[0]
addd 0x0, \v1, %b[1]
addd 0x0, \v2, %b[2]
addd 0x0, \v3, %b[3]
addd 0x0, \v4, %b[4]
addd 0x0, \v5, %b[5]
}
{
addd 0x0, \v6, %b[5]
call %ctpr1, wbs = 0x4
}
.endm
.macro e2k_syscall_7 trapnum sysnum v1 v2 v3 v4 v5 v6 v7
{
sdisp %ctpr1, \trapnum
addd 0x0, \sysnum, %b[0]
addd 0x0, \v1, %b[1]
addd 0x0, \v2, %b[2]
addd 0x0, \v3, %b[3]
addd 0x0, \v4, %b[4]
addd 0x0, \v5, %b[5]
}
{
addd 0x0, \v6, %b[6]
addd 0x0, \v7, %b[7]
call %ctpr1, wbs = 0x4
}
.endm
.macro assert op reg1 reg2 counter_reg
{
\op \reg1, \reg2, %pred0
addd 0x0, \counter_reg, %b[0]
disp %ctpr1, _test_fail
}
{
addd 0x1, \counter_reg, \counter_reg
call %ctpr1, wbs = 0x4 ? ~%pred0
}
.endm
_test_fail:
{
setwd wsz = 0x8, nfx = 0x0, dbl = 0x0
setbn rsz = 0x3, rbs = 0x4, rcur = 0x0
}
e2k_syscall_3 SYSCALL64_TRAPNUM, __NR_write, 0, [ _test_failed_str ], _test_failed_strlen
e2k_syscall_1 SYSCALL64_TRAPNUM, __NR_exit, %dr0

View File

@ -0,0 +1,6 @@
_stop:
e2k_syscall_1 SYSCALL64_TRAPNUM, __NR_exit, 0
_test_failed_str:
.ascii "TEST FAILED\n\0"
.set _test_failed_strlen, . - _test_failed_str

23
tests/tcg/e2k/test_addd.s Normal file
View File

@ -0,0 +1,23 @@
.global _start
.include "macros.inc"
_start:
{
setwd wsz=0x8, nfx=1
setbn rbs=0x4, rsz=0x3, rcur=0
}
{
addd 0x0, 0x0, %r0 ! counter
addd 0x2, 0xFFFFFFFFFFFFFFFF, %r1
}
{
addd 0x2, 0x2, %r2
adds 0x2, 0x2, %r3
adds 0x2, 0xFFFFFFFF, %r4
}
assert cmpedb, %r1, 0x1, %r0
assert cmpedb, %r2, 0x4, %r0
assert cmpesb, %r3, 0x4, %r0
assert cmpesb, %r4, 0x1, %r0
.include "macros_end.inc"