Commit a6edd929 authored by Stewart Brodie's avatar Stewart Brodie
Browse files

Added osvarlen and muldiv.

  Fixed major bug in heapswis.s
Detail:
  heapswis.s was using a bad return from one of the veneer functions
    which caused things like NFS to die horribly when they loaded.
  osvarlen replaces the files commonly known as riscosa - which find
    the length of a system variable.  A veneer is needed because _swix
    does not fill in the output registers on an error.  See PRM details
    on OS_ReadVarVal for more information.
  muldiv is another frequently used lump of code to do a*b/c where a*b
    is calculated first as a 64-bit product, and then the division
    applied.
  Header files exported containing comments on usage.
Admin:
  All No32bitCode assembler disassembled and re-examined by hand to
    verify no more cockups.

Version 0.03. Tagged as 'AsmUtils-0_03'
parent c8e135bc
......@@ -76,11 +76,14 @@ TARGETZ = alf.${COMPONENTZ}
SOURCE =
EXPORTS =
OBJS= o.callbacks o.sixtyfour o.heapswis o.rminfo o.irqs
OBJS= o.callbacks o.sixtyfour o.heapswis o.rminfo o.irqs \
o.osvarlen o.muldiv
OBJSZ= oz.callbacks oz.sixtyfour oz.heapswis oz.rminfo oz.irqs
OBJSZ= oz.callbacks oz.sixtyfour oz.heapswis oz.rminfo oz.irqs \
oz.osvarlen oz.muldiv
HDRS= h.callbacks h.sixtyfour h.heapswis h.rminfo h.irqs
HDRS= h.callbacks h.sixtyfour h.heapswis h.rminfo h.irqs \
h.osvarlen h.muldiv
LIBS = ${TARGET} ${TARGETZ}
......@@ -121,6 +124,8 @@ export_hdrs: ${HDRS} export_dirs
${CP} h.rminfo ${LIBDIR}.h.rminfo ${CPFLAGS}
${CP} h.heapswis ${LIBDIR}.h.heapswis ${CPFLAGS}
${CP} h.irqs ${LIBDIR}.h.irqs ${CPFLAGS}
${CP} h.osvarlen ${LIBDIR}.h.osvarlen ${CPFLAGS}
${CP} h.muldiv ${LIBDIR}.h.muldiv ${CPFLAGS}
${CP} VersionNum ${LIBDIR}.VersionNum ${CPFLAGS}
@echo ${COMPONENT}: export complete (hdrs)
......
/* (0.02)
/* (0.03)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 0.02
#define Module_MajorVersion_CMHG 0.03
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 29 Nov 1999
#define Module_Date_CMHG 30 Nov 1999
#define Module_MajorVersion "0.02"
#define Module_Version 2
#define Module_MinorVersion ""
#define Module_Date "29 Nov 1999"
#define Module_MajorVersion "0.03"
#define Module_Version 3
#define Module_MinorVersion ""
#define Module_Date "30 Nov 1999"
#define Module_FullVersion "0.02"
#define Module_FullVersion "0.03"
/* Copyright 1999 Pace Micro Technology plc
*
* 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.
*/
/*
* AsmUtils (muldiv.h)
*
* Copyright (C) Pace Micro Technology plc. 1999
*
*/
#ifndef asmutils_muldiv_h_inluded
#define asmutils_muldiv_h_inluded
#ifdef __cplusplus
extern "C" {
#endif
/* Routine multiplies m1 by m2 generating a 64-bit product, then
* divides that 64-bit product by d. Result is returned.
* Division by zero is not raised and is treated as divide by 1.
*/
extern int muldiv(int /*m1*/, int /*m2*/, int /*d*/);
#ifdef __cplusplus
}
#endif
#endif
/* Copyright 1999 Pace Micro Technology plc
*
* 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.
*/
/*
* AsmUtils (osvarlen.h)
*
* Copyright (C) Pace Micro Technology plc. 1999
*
*/
#ifndef asmutils_osvarlen_h_inluded
#define asmutils_osvarlen_h_inluded
#ifdef __cplusplus
extern "C" {
#endif
/* The standard _swi and _swix veneers cannot be used to determine the
* length of a system variable because they do not fill in the return
* parameters if the SWI returns an error - like it does when you make
* the recommended call to find the length of a system variable.
*
* This call replaces it.
*/
extern int osvarlen(const char * /*system_variable*/);
#ifdef __cplusplus
}
#endif
#endif
......@@ -53,7 +53,7 @@ xosheap_alloc
SWI XOS_Heap
STRVC R2,[R12]
MOVVC R0,#0
Return ,LinkNotStacked,,R12
Return
AREA |AsmUtils$MemSWIs3$$Code|,CODE,READONLY,PIC
xosheap_free
......
; Copyright 1999 Pace Micro Technology plc
;
; 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.
;
; Title: muldiv.s
; Purpose: muliplier and divider, with 64-bit intermediate products
; muldiv(a, b, c) -> a*b/c
GET hdr:ListOpts
GET hdr:Macros
GET hdr:System
GET hdr:Machine.<Machine>
GET hdr:APCS.<APCS>
AREA |muldiv$$code|, CODE, READONLY, PIC
EXPORT muldiv
muldiv
; the intermediate product is 64 bits long
; do everything using moduluses, and sort out signs later
FunctionEntry "a1-a4,v1-v2"
; first, the double-length product, returned in a3 & a4
; uses ip, a1 and a2 as workspace
MOV a3, #0
MOV a4, #0
MOV ip, #0
CMPS a2, #0
RSBLT a2, a2, #0 ; abs b
MOV v2, a2
CMPS a1, #0
RSBLT a1, a1, #0 ; abs a
muldiv0
MOVS a2, a2, LSR #1
BCC muldiv1
ADDS a4, a4, a1
ADC a3, a3, ip
muldiv1
MOVS a1, a1, ASL #1
ADC ip, ip, ip
CMPS a2, #0
BNE muldiv0
; now the 64*32 bit divide
; dividend in a3 and a4
; remainder ends up in a4; quotient in ip
; uses a1 and a2 to hold the (shifted) divisor;
; v1 for the current bit in the quotient
LDR a2, [sp, #8] ; recover divisor
CMPS a2, #0
Return "a1-a4,v1-v2",,EQ
RSBLT a2, a2, #0 ; abs c
MOV v2, a2
MOV ip, #0
MOV a1, #0
MOV v1, #0
MOV lr, #1
muldiv2
CMPS a1, #&80000000
BCS muldiv3
CMPS a1, a3
CMPEQS a2, a4 ; compare of [a1, a2] against [a3, a4]
BCS muldiv3
MOVS a2, a2, ASL #1
MOV a1, a1, ASL #1
ADC a1, a1, #0
ADD v1, v1, #1
B muldiv2
muldiv3
CMPS a1, a3
CMPEQS a2, a4
BHI muldiv4
CMPS v1, #31
ADDLE ip, ip, lr, ASL v1
SUBS a4, a4, a2
SBC a3, a3, a1
muldiv4
MOVS a1, a1, ASR #1
MOV a2, a2, RRX
SUBS v1, v1, #1
BGE muldiv3
; now all we need to do is sort out the signs.
LDMFD sp!, {a1, a2, a3, v1}
EOR a2, a2, a1 ; a2 has the sign of a*b: a3 is the sign of c
MOV a1, ip
TEQS a2, a3 ; if a*b and c have opposite signs,
RSBMI a1, a1, #0 ; negate the quotient
CMPS a2, #0 ; and if the dividend was negative,
RSBLT a4, a4, #0 ; negate the remainder
;;;; Now discard the remainder - J R C 19 March 1991
;;;; STR a4, [v1]
Return "v1-v2"
END
; Copyright 1999 Pace Micro Technology plc
;
; 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.
;
; osvarlen - length of a system variable variable
; originally written by Jonathan Coxhead, 15th Aug 1995
GET hdr:ListOpts
GET hdr:Macros
GET hdr:System
GET hdr:Machine.<Machine>
GET hdr:APCS.<APCS>
AREA |osvarlen$$code|, CODE, READONLY, PIC
EXPORT riscos_var_len
riscos_var_len ROUT
;Entry R0 -> name of a variable
; R1 = variable type (os_VARTYPE_EXPANDED or 0)
;Exit R0 = length of variable value, or -1 if not found
FunctionEntry "v1"
MOV R4, R1
MOV R3, #0
MOV R2, #1 << 31
MOV R1, #0
SWI XOS_ReadVarVal
;Ignore error
MVN R0, R2
Return "v1"
END
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment