/* is-div-test.S. l.div and l.divu instruction test of Or1ksim
|
/* is-div-test.S. l.div and l.divu instruction test of Or1ksim
|
*
|
*
|
* Copyright (C) 1999-2006 OpenCores
|
* Copyright (C) 1999-2006 OpenCores
|
* Copyright (C) 2010 Embecosm Limited
|
* Copyright (C) 2010 Embecosm Limited
|
*
|
*
|
* Contributors various OpenCores participants
|
* Contributors various OpenCores participants
|
* Contributor Jeremy Bennett
|
* Contributor Jeremy Bennett
|
*
|
*
|
* This file is part of OpenRISC 1000 Architectural Simulator.
|
* This file is part of OpenRISC 1000 Architectural Simulator.
|
*
|
*
|
* This program is free software; you can redistribute it and/or modify it
|
* 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
|
* 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)
|
* Software Foundation; either version 3 of the License, or (at your option)
|
* any later version.
|
* any later version.
|
*
|
*
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
* more details.
|
* more details.
|
*
|
*
|
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
* with this program. If not, see .
|
* with this program. If not, see .
|
*/
|
*/
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
* Coding conventions
|
* Coding conventions are described in inst-set-test.S
|
*
|
|
* A simple rising stack is provided starting at _stack and pointed to by
|
|
* r1. r1 points to the next free word. Only 32-bit registers may be pushed
|
|
* onto the stack.
|
|
*
|
|
* Local labels up to 49 are reserved for macros. Each is used only once in
|
|
* all macros. You can get in a serious mess if you get local label clashing
|
|
* in macros.
|
|
*
|
|
* Arguments to functions are passed in r3 through r8.
|
|
* r9 is the link (return address)
|
|
* r11 is for returning results
|
|
*
|
|
* Only r1 and r2 are preserved across function calls. It is up to the callee
|
|
* to save any other registers required.
|
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
* Test coverage
|
* Test coverage
|
*
|
*
|
* The l.div and l.divu instructions should set the carry flag as well as
|
* The l.div and l.divu instructions should set the carry flag as well as
|
* triggering an event when divide by zero occurs.
|
* triggering an event when divide by zero occurs.
|
*
|
*
|
* Having fixed the problem, this is (in good software engineering style), a
|
* Having fixed the problem, this is (in good software engineering style), a
|
* regresison test to go with the fix.
|
* regresison test to go with the fix.
|
*
|
*
|
* This is not a comprehensive test of either instruction (yet).
|
* This is not a comprehensive test of either instruction (yet).
|
*
|
*
|
* Of course what is really needed is a comprehensive instruction test...
|
* Of course what is really needed is a comprehensive instruction test...
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
|
|
|
|
#include "inst-set-test.h"
|
#include "inst-set-test.h"
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
* Test of divide l.div
|
* Test of divide l.div
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
|
|
.section .text
|
.section .text
|
.global _start
|
.global _start
|
_start:
|
_start:
|
/* Signed divide by zero */
|
/* Signed divide by zero */
|
_div:
|
_div:
|
LOAD_STR (r3, "l.div\n")
|
LOAD_STR (r3, "l.div\n")
|
l.jal _puts
|
l.jal _puts
|
l.nop
|
l.nop
|
|
|
LOAD_CONST (r2, ~SPR_SR_CY) /* Clear the carry flag */
|
LOAD_CONST (r2, ~SPR_SR_CY) /* Clear the carry flag */
|
l.mfspr r3,r0,SPR_SR
|
l.mfspr r3,r0,SPR_SR
|
l.and r3,r3,r2
|
l.and r3,r3,r2
|
l.mtspr r0,r3,SPR_SR
|
l.mtspr r0,r3,SPR_SR
|
|
|
LOAD_CONST (r5,1) /* Set up args for division */
|
LOAD_CONST (r5,1) /* Set up args for division */
|
LOAD_CONST (r6,0)
|
LOAD_CONST (r6,0)
|
l.div r4,r5,r6
|
l.div r4,r5,r6
|
|
|
l.mfspr r2,r0,SPR_SR /* So we can examine the carry flag */
|
l.mfspr r2,r0,SPR_SR /* So we can examine the carry flag */
|
LOAD_CONST (r4, SPR_SR_CY) /* The carry bit */
|
LOAD_CONST (r4, SPR_SR_CY) /* The carry bit */
|
l.and r2,r2,r4
|
l.and r2,r2,r4
|
l.sfeq r2,r4
|
l.sfeq r2,r4
|
CHECK_FLAG ("1 / 0 (with error) carry flag set: ", TRUE)
|
CHECK_FLAG ("1 / 0 (with error) carry flag set: ", TRUE)
|
|
|
/* Signed divide by zero */
|
/* Signed divide by zero */
|
_divu:
|
_divu:
|
LOAD_STR (r3, "l.divu\n")
|
LOAD_STR (r3, "l.divu\n")
|
l.jal _puts
|
l.jal _puts
|
l.nop
|
l.nop
|
|
|
LOAD_CONST (r2, ~SPR_SR_CY) /* Clear the carry flag */
|
LOAD_CONST (r2, ~SPR_SR_CY) /* Clear the carry flag */
|
l.mfspr r3,r0,SPR_SR
|
l.mfspr r3,r0,SPR_SR
|
l.and r3,r3,r2
|
l.and r3,r3,r2
|
l.mtspr r0,r3,SPR_SR
|
l.mtspr r0,r3,SPR_SR
|
|
|
LOAD_CONST (r5,1) /* Set up args for division */
|
LOAD_CONST (r5,1) /* Set up args for division */
|
LOAD_CONST (r6,0)
|
LOAD_CONST (r6,0)
|
l.divu r4,r5,r6
|
l.divu r4,r5,r6
|
|
|
l.mfspr r2,r0,SPR_SR /* So we can examine the carry flag */
|
l.mfspr r2,r0,SPR_SR /* So we can examine the carry flag */
|
LOAD_CONST (r4, SPR_SR_CY) /* The carry bit */
|
LOAD_CONST (r4, SPR_SR_CY) /* The carry bit */
|
l.and r2,r2,r4
|
l.and r2,r2,r4
|
l.sfeq r2,r4
|
l.sfeq r2,r4
|
CHECK_FLAG ("1 / 0 (with error) carry flag set: ", TRUE)
|
CHECK_FLAG ("1 / 0 (with error) carry flag set: ", TRUE)
|
|
|
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
* All done
|
* All done
|
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
_exit:
|
_exit:
|
LOAD_STR (r3, "Test completed\n")
|
LOAD_STR (r3, "Test completed\n")
|
l.jal _puts
|
l.jal _puts
|
l.nop
|
l.nop
|
|
|
|
|