# RISC-V Compliance Test LB-01
#
#
# Copyright (c) 2019 Imperas Software Ltd., www.imperas.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#
# Specification: RV32I Base Integer Instruction Set, Version 2.1
# Description: Testing instruction 'LB'.

#include "compliance_test.h"
#include "compliance_model.h"

RVTEST_ISA("RV32I")

RVMODEL_BOOT
RVTEST_CODE_BEGIN


	RVMODEL_IO_INIT
	RVMODEL_IO_ASSERT_GPR_EQ(x31, x0, 0x00000000)
	RVMODEL_IO_WRITE_STR(x31, "Test Begin\n")

#ifdef TEST_CASE_1
  RVTEST_CASE(1,"// check ISA:=regex(.*32.*); check ISA:=regex(.*I.*); def TEST_CASE_1=True",lb-align)

	# ---------------------------------------------------------------------------------------------

	RVMODEL_IO_WRITE_STR(x31, "# Test number 1\n")


    # Addresses for test data and results
	la	x5, test_1_res

	TEST_CASE(x7, x0, 0x0, x5, 0, \
    la  x31, test_data; \
    lb x0, 0x0(x31); \
    )
	TEST_CASE(x7, x1, 0xffffffbb, x5, 4, \
    la  x30, test_data; \
    lb x1, -0x2(x30); \
    )
	TEST_CASE(x7, x2, 0xffffffdd, x5, 8, \
    la  x29, test_data; \
    lb x2, 0x3(x29); \
    )
	TEST_CASE(x7, x3, 0xc, x5, 12, \
    la  x28, test_data; \
    lb x3, -0x4(x28); \
    )
	TEST_CASE(x7, x4, 0xd, x5, 16, \
    la  x27, test_data; \
    lb x4, 0x2(x27); \
    )


	# ---------------------------------------------------------------------------------------------
	RVMODEL_IO_WRITE_STR(x31, "# Test number 2\n")


    # Addresses for test data and results
	la	x1, test_2_res

	TEST_CASE(x3, x5, 0xfffffff0, x1, 0, \
    la  x26, test_data; \
    lb x5, 0x4(x26); \
    )
	TEST_CASE(x3, x6, 0xb, x1, 4, \
    la  x25, test_data; \
    lb x6, -0x1(x25); \
    )
	TEST_CASE(x3, x7, 0xe, x1, 8, \
    la  x24, test_data; \
    lb x7, 0x1(x24); \
    )
	TEST_CASE(x3, x8, 0xffffffee, x1, 12, \
    la  x23, test_data; \
    lb x8, 0x0(x23); \
    )
	TEST_CASE(x3, x9, 0xffffffbb, x1, 16, \
    la  x22, test_data; \
    lb x9, -0x2(x22); \
    )


	# ---------------------------------------------------------------------------------------------
	RVMODEL_IO_WRITE_STR(x31, "# Test number 3\n")


    # Addresses for test data and results
	la	x1, test_3_res

	TEST_CASE(x8, x10, 0xffffffdd, x1, 0, \
    la  x21, test_data; \
    lb x10, 0x3(x21); \
    )
	TEST_CASE(x8, x11, 0xc, x1, 4, \
    la  x20, test_data; \
    lb x11, -0x4(x20); \
    )
	TEST_CASE(x8, x12, 0xd, x1, 8, \
    la  x19, test_data; \
    lb x12, 0x2(x19); \
    )
	TEST_CASE(x8, x13, 0xfffffff0, x1, 12, \
    la  x18, test_data; \
    lb x13, 0x4(x18); \
    )
	TEST_CASE(x8, x14, 0xb, x1, 16, \
    la  x17, test_data; \
    lb x14, -0x1(x17); \
    )


	# ---------------------------------------------------------------------------------------------
	RVMODEL_IO_WRITE_STR(x31, "# Test number 4\n")


    # Addresses for test data and results
	la	x2, test_4_res

	TEST_CASE(x4, x15, 0xe, x2, 0, \
    la  x16, test_data; \
    lb x15, 0x1(x16); \
    )
	TEST_CASE(x4, x16, 0xffffffee, x2, 4, \
    la  x15, test_data; \
    lb x16, 0x0(x15); \
    )
	TEST_CASE(x4, x17, 0xffffffbb, x2, 8, \
    la  x14, test_data; \
    lb x17, -0x2(x14); \
    )
	TEST_CASE(x4, x18, 0xffffffdd, x2, 12, \
    la  x13, test_data; \
    lb x18, 0x3(x13); \
    )
	TEST_CASE(x4, x19, 0xc, x2, 16, \
    la  x12, test_data; \
    lb x19, -0x4(x12); \
    )


	# ---------------------------------------------------------------------------------------------
	RVMODEL_IO_WRITE_STR(x31, "# Test number 5\n")


    # Addresses for test data and results
	la	x1, test_5_res

	TEST_CASE(x3, x20, 0xd, x1, 0, \
    la  x11, test_data; \
    lb x20, 0x2(x11); \
    )
	TEST_CASE(x3, x21, 0xfffffff0, x1, 4, \
    la  x10, test_data; \
    lb x21, 0x4(x10); \
    )
	TEST_CASE(x3, x22, 0xb, x1, 8, \
    la  x9, test_data; \
    lb x22, -0x1(x9); \
    )
	TEST_CASE(x3, x23, 0xe, x1, 12, \
    la  x8, test_data; \
    lb x23, 0x1(x8); \
    )
	TEST_CASE(x3, x24, 0xffffffee, x1, 16, \
    la  x7, test_data; \
    lb x24, 0x0(x7); \
    )


	# ---------------------------------------------------------------------------------------------
	RVMODEL_IO_WRITE_STR(x31, "# Test number 6\n")


    # Addresses for test data and results
	la	x1, test_6_res

	TEST_CASE(x8, x25, 0xffffffbb, x1, 0, \
    la  x6, test_data; \
    lb x25, -0x2(x6); \
    )
	TEST_CASE(x8, x26, 0xffffffdd, x1, 4, \
    la  x5, test_data; \
    lb x26, 0x3(x5); \
    )
	TEST_CASE(x8, x27, 0xc, x1, 8, \
    la  x4, test_data; \
    lb x27, -0x4(x4); \
    )
	TEST_CASE(x8, x28, 0xd, x1, 12, \
    la  x3, test_data; \
    lb x28, 0x2(x3); \
    )
	TEST_CASE(x8, x29, 0xfffffff0, x1, 16, \
    la  x2, test_data; \
    lb x29, 0x4(x2); \
    )


	# ---------------------------------------------------------------------------------------------
	RVMODEL_IO_WRITE_STR(x31, "# Test number 7\n")


    # Addresses for test data and results
	la	x2, test_7_res

	TEST_CASE(x4, x30, 0xb, x2, 0, \
    la  x1, test_data; \
    lb x30, -0x1(x1); \
    )
	TEST_CASE(x4, x31, 0xe, x2, 4, \
    la  x1, test_data; \
    lb x31, 0x1(x1); \
    )


	# ---------------------------------------------------------------------------------------------
	
	RVMODEL_IO_WRITE_STR(x31, "Test End\n")

#endif

	# ---------------------------------------------------------------------------------------------

	RVMODEL_HALT

RVTEST_CODE_END

# Input data section.
	.data
	.align 4
test_data_start:

	.word 0x11f1f222
	.word 0xf33344f4
	.word 0x55f5f666
	.word 0xf77788f8
	.word 0x99090aaa
	.word 0xbbbcc0c
test_data:
	.word 0xdd0d0eee
	.word 0xfff00f0
	.word 0x12345678
	.word 0x9abcdef0
	.word 0x76543210
	.word 0xfedcba98

# Output data section.
RVMODEL_DATA_BEGIN

test_1_res:
	.fill 5, 4, -1
test_2_res:
	.fill 5, 4, -1
test_3_res:
	.fill 5, 4, -1
test_4_res:
	.fill 5, 4, -1
test_5_res:
	.fill 5, 4, -1
test_6_res:
	.fill 5, 4, -1
test_7_res:
	.fill 5, 4, -1

RVMODEL_DATA_END

