Skip to content

Commit

Permalink
Or1k spec 1.4 user mode FPCSR R/W (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
stffrdhrn committed Aug 19, 2023
2 parents 84d285c + c6ff955 commit 495b917
Show file tree
Hide file tree
Showing 17 changed files with 846 additions and 19 deletions.
8 changes: 5 additions & 3 deletions cpu/or32/insnset.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,8 @@ INSTRUCTION (l_mtspr) {
uint16_t regno = PARAM0 | PARAM2;
uorreg_t value = PARAM1;

if (cpu_state.sprs[SPR_SR] & SPR_SR_SM)
if ((regno == SPR_FPCSR) ||
(cpu_state.sprs[SPR_SR] & SPR_SR_SM))
mtspr(regno, value);
else {
PRINTF("WARNING: trying to write SPR while SR[SUPV] is cleared.\n");
Expand All @@ -915,10 +916,11 @@ INSTRUCTION (l_mfspr) {
uint16_t regno = PARAM1 | PARAM2;
uorreg_t value = mfspr(regno);

if ((cpu_state.sprs[SPR_SR] & SPR_SR_SM) ||
if ((regno == SPR_FPCSR) ||
(cpu_state.sprs[SPR_SR] & SPR_SR_SM) ||
// TODO: Check if this SPR should actually be allowed to be read with
// SR's SM==0 and SUMRA==1
(!(cpu_state.sprs[SPR_SR] & SPR_SR_SM) &&
(!(cpu_state.sprs[SPR_SR] & SPR_SR_SM) &&
(cpu_state.sprs[SPR_SR] & SPR_SR_SUMRA)))
SET_PARAM0(value);
else
Expand Down
1 change: 1 addition & 0 deletions testsuite/or1ksim.tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ EXTRA_DIST = cfg/or1k/acv-gpio.cfg \
cfg/or1k/fp.cfg \
cfg/or1knd/fp.cfg \
fp.exp \
fpee.exp \
functest.exp \
int-test.exp \
cfg/or1k/inst-set-test.cfg \
Expand Down
1 change: 1 addition & 0 deletions testsuite/or1ksim.tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ EXTRA_DIST = cfg/or1k/acv-gpio.cfg \
cfg/or1k/fp.cfg \
cfg/or1knd/fp.cfg \
fp.exp \
fpee.exp \
functest.exp \
int-test.exp \
cfg/or1k/inst-set-test.cfg \
Expand Down
40 changes: 40 additions & 0 deletions testsuite/or1ksim.tests/fpee.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# fpee.exp. Floating point exception DejaGNU tests

# Copyright (C) 2023 OpenRISC Developers

# Contributor Stafford Horne <shorne@gmail.com>

# This file is part of OpenRISC 1000 Architectural Simulator.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.

# This program 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 General Public License for
# more details.

# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http:#www.gnu.org/licenses/>. */

# -----------------------------------------------------------------------------
# This code is commented throughout for use with Doxygen.
# -----------------------------------------------------------------------------


# Run the floating point test
run_or1ksim "fpee" \
[list "Switching to User Mode" \
"Enabling FPU Exceptions" \
"Exceptions enabled, now DIV 3.14 / 0" \
"Got fpe: " \
"report(0x7f800000);" \
"report(0x00000801);" \
"One more, now MUL 3.14 * MAX" \
"Got fpe: " \
"report(0x7f800000);" \
"report(0x00000109);" \
"exit(0)"] \
"fp.cfg" "fpee/fpee"
1 change: 1 addition & 0 deletions testsuite/test-code-or1k/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SUBDIRS = support \
ext \
fbtest \
fp \
fpee \
testfloat \
functest \
flag \
Expand Down
1 change: 1 addition & 0 deletions testsuite/test-code-or1k/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ SUBDIRS = support \
ext \
fbtest \
fp \
fpee \
testfloat \
functest \
flag \
Expand Down
3 changes: 2 additions & 1 deletion testsuite/test-code-or1k/configure
Original file line number Diff line number Diff line change
Expand Up @@ -13246,7 +13246,7 @@ printf "%s\n" "#define SIZEOF_INT 4" >>confdefs.h
printf "%s\n" "#define SIZEOF_LONG 4" >>confdefs.h


ac_config_files="$ac_config_files Makefile acv-gpio/Makefile acv-uart/Makefile atomic/Makefile basic/Makefile cache/Makefile cbasic/Makefile cfg/Makefile dhry/Makefile dmatest/Makefile eth/Makefile except/Makefile except-test/Makefile exit/Makefile ext/Makefile fbtest/Makefile fp/Makefile testfloat/Makefile functest/Makefile flag/Makefile int-test/Makefile int-logger/Makefile inst-set-test/Makefile kbdtest/Makefile local-global/Makefile loop/Makefile mc-async/Makefile mc-dram/Makefile mc-ssram/Makefile mc-sync/Makefile mc-common/Makefile mem-test/Makefile mmu/Makefile mul/Makefile mycompress/Makefile support/Makefile tick/Makefile uos/Makefile upcalls/Makefile pcu/Makefile"
ac_config_files="$ac_config_files Makefile acv-gpio/Makefile acv-uart/Makefile atomic/Makefile basic/Makefile cache/Makefile cbasic/Makefile cfg/Makefile dhry/Makefile dmatest/Makefile eth/Makefile except/Makefile except-test/Makefile exit/Makefile ext/Makefile fbtest/Makefile fp/Makefile fpee/Makefile testfloat/Makefile functest/Makefile flag/Makefile int-test/Makefile int-logger/Makefile inst-set-test/Makefile kbdtest/Makefile local-global/Makefile loop/Makefile mc-async/Makefile mc-dram/Makefile mc-ssram/Makefile mc-sync/Makefile mc-common/Makefile mem-test/Makefile mmu/Makefile mul/Makefile mycompress/Makefile support/Makefile tick/Makefile uos/Makefile upcalls/Makefile pcu/Makefile"


cat >confcache <<\_ACEOF
Expand Down Expand Up @@ -14282,6 +14282,7 @@ do
"ext/Makefile") CONFIG_FILES="$CONFIG_FILES ext/Makefile" ;;
"fbtest/Makefile") CONFIG_FILES="$CONFIG_FILES fbtest/Makefile" ;;
"fp/Makefile") CONFIG_FILES="$CONFIG_FILES fp/Makefile" ;;
"fpee/Makefile") CONFIG_FILES="$CONFIG_FILES fpee/Makefile" ;;
"testfloat/Makefile") CONFIG_FILES="$CONFIG_FILES testfloat/Makefile" ;;
"functest/Makefile") CONFIG_FILES="$CONFIG_FILES functest/Makefile" ;;
"flag/Makefile") CONFIG_FILES="$CONFIG_FILES flag/Makefile" ;;
Expand Down
1 change: 1 addition & 0 deletions testsuite/test-code-or1k/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ AC_CONFIG_FILES([Makefile \
ext/Makefile \
fbtest/Makefile \
fp/Makefile \
fpee/Makefile \
testfloat/Makefile \
functest/Makefile \
flag/Makefile \
Expand Down
8 changes: 4 additions & 4 deletions testsuite/test-code-or1k/except-test/except-test-s.S
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ stack:
.extern excpt_itlbmiss
.extern excpt_range
.extern excpt_syscall
.extern excpt_break
.extern excpt_fpu
.extern excpt_trap

/* Our special text section is used to guarantee this code goes first
Expand Down Expand Up @@ -334,14 +334,14 @@ syscall_vector:
l.addi r3,r3,8

.org 0xd00
break_vector:
fpu_vector:
l.addi r1,r1,-120
l.sw 0x1c(r1),r9
l.sw 0x20(r1),r10
l.movhi r9,hi(store_regs)
l.ori r9,r9,lo(store_regs)
l.movhi r10,hi(excpt_break)
l.ori r10,r10,lo(excpt_break)
l.movhi r10,hi(excpt_fpu)
l.ori r10,r10,lo(excpt_fpu)
l.jr r9
l.nop
l.nop
Expand Down
2 changes: 1 addition & 1 deletion testsuite/test-code-or1k/except-test/except-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extern unsigned long excpt_dtlbmiss;
extern unsigned long excpt_itlbmiss;
extern unsigned long excpt_range;
extern unsigned long excpt_syscall;
extern unsigned long excpt_break;
extern unsigned long excpt_fpu;
extern unsigned long excpt_trap;


Expand Down
8 changes: 4 additions & 4 deletions testsuite/test-code-or1k/except/except.S
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ stack:
.extern excpt_itlbmiss
.extern excpt_range
.extern excpt_syscall
.extern excpt_break
.extern excpt_fpu
.extern excpt_trap

.section .except,"ax"
Expand Down Expand Up @@ -235,15 +235,15 @@ syscall_vector:
OR1K_DELAYED_NOP(OR1K_INST(l.jr r10))

.org 0xd00
break_vector:
fpu_vector:
l.addi r1,r1,-EXCEPT_STACK_SIZE
l.sw 0x18(r1),r9
OR1K_DELAYED_NOP(OR1K_INST(l.jal store_regs))
l.nop
l.movhi r9,hi(end_except)
l.ori r9,r9,lo(end_except)
l.movhi r10,hi(excpt_break)
l.ori r10,r10,lo(excpt_break)
l.movhi r10,hi(excpt_fpu)
l.ori r10,r10,lo(excpt_fpu)
l.lwz r10,0(r10)
OR1K_DELAYED_NOP(OR1K_INST(l.jr r10))

Expand Down
34 changes: 34 additions & 0 deletions testsuite/test-code-or1k/fpee/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Makefile.am for or1ksim testsuite CPU test program: fpee

# Copyright (C) OpenRISC Developers, 2023

# Contributor Stafford Horne <shorne@gmail.com>

# This file is part of OpenRISC 1000 Architectural Simulator.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.

# This program 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 General Public License for
# more details.

# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http:#www.gnu.org/licenses/>. */

# -----------------------------------------------------------------------------
# This code is commented throughout for use with Doxygen.
# -----------------------------------------------------------------------------

# A test program of the floating point exceptions test
check_PROGRAMS = fpee

fpee_SOURCES = fpee.c

fpee_LDFLAGS = -T$(srcdir)/../default.ld

fpee_LDADD = ../except/except.lo \
../support/libsupport.la

0 comments on commit 495b917

Please sign in to comment.