Commit 66657bbd authored by Stewart Brodie's avatar Stewart Brodie
Browse files

Import of library providing assembler abstractions for C code.

Detail:
  Contains code for collecting callbacks, obtaining the base address
    of a module, 64-bit maths and the veneers to OS_Heap that pervade
    the source tree.
Admin:
  Requires kbracey_32bit:RiscOS/Sources/Programmer/HdrSrc
  Do not use (yet) on main trunk.

Tagged as AsmUtils-0_00_prerelease
 
parent bda014bf
| 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.
|
Dir <Obey$Dir>
amu_machine clean
stripdepnd Makefile
| 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.
|
Dir <Obey$Dir>
amu_machine export_libs
amu_machine export_hdrs
s/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true
# 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.
#
# Makefile for AsmUtils
#
# ***********************************
# *** C h a n g e L i s t ***
# ***********************************
# Date Name Description
# ---- ---- -----------
# 20-Nov-99 SNB Created.
#
#
# Paths
#
LIBDIR = <Lib$Dir>.AsmUtils
#
# Generic options:
#
MKDIR = do mkdir -p
AS = objasm
CP = copy
CC = cc
CM = cmhg
RM = remove
LD = link
LB = libfile
TOUCH = create
WIPE = -wipe
# Defining this macro has the effect of suppressing the warning
# about use of the UMULL instruction in s.sixtyfour in the case
# where No26bitCode is true.
OBJASMCPU = -CPU arm7m
CCFLAGS = -c -depend !Depend -ffaho ${INCLUDES} ${DFLAGS}
ASFLAGS = -depend !Depend -Stamp -quit ${OBJASMCPU}
CPFLAGS = ~cfr~v
LBFLAGS = -c
WFLAGS = ~CFR~V
#
# Libraries
#
CLIB = CLIB:o.stubs
RLIB = RISCOSLIB:o.risc_oslib
RSTUBS = RISCOSLIB:o.rstubs
ROMSTUBS = RISCOSLIB:o.romstubs
ROMCSTUBS = RISCOSLIB:o.romcstubs
ABSSYM = RISC_OSLib:o.AbsSym
#
# Include files
#
INCLUDES = -IC:
DFLAGS =
#
# Program specific options:
#
COMPONENT = AsmUtils
COMPONENTZ = AsmUtilszm
TARGET = alf.${COMPONENT}
TARGETZ = alf.${COMPONENTZ}
SOURCE =
EXPORTS =
OBJS= o.callbacks o.sixtyfour o.heapswis o.rminfo
OBJSZ= oz.callbacks oz.sixtyfour oz.heapswis oz.rminfo
HDRS= h.callbacks h.sixtyfour h.heapswis h.rminfo
LIBS = ${TARGET} ${TARGETZ}
#
# Rule patterns
#
.SUFFIXES: .oz
.s.o:; ${AS} ${ASFLAGS} -o $@ $< -PreDefine "ROM SETL {FALSE}"
.s.oz:; ${AS} ${ASFLAGS} -o $@ $< -PreDefine "ROM SETL {TRUE}"
#
# build a the library:
#
all: ${LIBS}
#
# RISC OS ROM build rules:
#
rom: ${TARGET}
@echo ${COMPONENT}: rom module built
export: export_${PHASE}
install_rom: ${TARGET}
@echo ${COMPONENT}: rom module installed
clean:
${WIPE} o ${WFLAGS}
${WIPE} oz ${WFLAGS}
${WIPE} alf ${WFLAGS}
@echo ${COMPONENT}: cleaned
export_hdrs: ${HDRS} export_dirs
${CP} h.callbacks ${LIBDIR}.h.callbacks ${CPFLAGS}
${CP} h.sixtyfour ${LIBDIR}.h.sixtyfour ${CPFLAGS}
${CP} h.rminfo ${LIBDIR}.h.rminfo ${CPFLAGS}
${CP} h.heapswis ${LIBDIR}.h.heapswis ${CPFLAGS}
${CP} VersionNum ${LIBDIR}.VersionNum ${CPFLAGS}
@echo ${COMPONENT}: export complete (hdrs)
export_libs: ${LIBS} export_dirs
${CP} alf ${LIBDIR}.o ${CPFLAGS}
@echo ${COMPONENT}: export complete (libs)
local_dirs:
${MKDIR} o
${MKDIR} oz
${MKDIR} alf
export_dirs:
${MKDIR} ${LIBDIR}.h
#
# Final link
#
${TARGET}: ${OBJS} local_dirs
${LB} ${LBFLAGS} -o $@ ${OBJS}
${TARGETZ}: ${OBJSZ} local_dirs
${LB} ${LBFLAGS} -o $@ ${OBJSZ}
# Dynamic dependencies:
/* 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 (callbacks.h)
*
* Copyright (C) Pace Micro Technology plc. 1999
*
*/
#ifndef asmutils_callbacks_h_inluded
#define asmutils_callbacks_h_inluded
#ifdef __cplusplus
extern "C" {
/* All of these calls do the same thing - the aliases are provided
* until all code can be modified to call the function the same
* thing.
*/
/* This function attempts to make the transient callback chain be processed.
* It does this in whatever manner is appropriate to the build in which it is
* exported
*/
extern void usermode_donothing(void);
extern void CollectCallbacks(void);
#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 (heapswis.h)
*
* Copyright (C) Pace Micro Technology plc. 1999
*
*/
#ifndef asmutils_heapswis_h_inluded
#define asmutils_heapswis_h_inluded
#ifdef __cplusplus
extern "C" {
/* Fast veneers to OS_Heap used by various components in the build.
* These functions correspond to the R0 sub-reason codes of OS_Heap,
* respectively: 0 (initialise), 2 (allocate), 3 (free), 4 (resize block),
* 5 (resize heap), 6 (read size of block).
*
* See PRM volume 1 for details.
*/
extern _kernel_oserror *xosheap_initialise(void *heap, size_t size);
extern _kernel_oserror *xosheap_alloc(void *heap, size_t size, void **p);
extern _kernel_oserror *xosheap_free(void *heap, void *p);
extern _kernel_oserror *xosheap_realloc(void *heap, void *p, int by, void **newp);
extern _kernel_oserror *xosheap_resize(void *heap, int by);
extern _kernel_oserror *xosheap_read_size(void *heap, void *p, size_t *size);
#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 (rminfo.h)
*
* Copyright (C) Pace Micro Technology plc. 1999
*
*/
#ifndef asmutils_rminfo_h_inluded
#define asmutils_rminfo_h_inluded
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned long Image_RO_Base;
#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 (sixtyfour.h)
*
* Copyright (C) Pace Micro Technology plc. 1999
*
*/
#ifndef asmutils_sixtyfour_h_inluded
#define asmutils_sixtyfour_h_inluded
#ifdef __cplusplus
extern "C" {
#endif
/* 64-bit arithmetic support. Note that not all of the support for signed
* 64-bit arithmetic has been added so far.
*/
#ifndef NO_SIXTYFOUR_TYPE_DECLS
/* Signed 64-bit integer representation */
typedef struct _int64_t {
unsigned long low;
signed long high;
} int64_t;
/* Unsigned 64-bit integer representation */
typedef struct {
unsigned long low;
unsigned long high;
} u_int64_t;
#endif /* !NO_SIXTYFOUR_TYPE_DECLS */
/* All functions with the exception of [su]i64_value return their first
* parameter as the function result.
*/
/* Constructors. First numeric parameter is the least-significant 32 bits,
* the second (where provided) is the most-significant 32 bits.
* Note: si64_create performs sign extension
*/
extern u_int64_t *ui64_create2(u_int64_t *, unsigned long, unsigned long);
extern u_int64_t *ui64_create(u_int64_t *, unsigned long);
extern int64_t *si64_create2(int64_t *, unsigned long, long);
extern int64_t *si64_create(int64_t *, unsigned long);
/* Add a 32-bit quantity to a 64-bit quantity */
extern u_int64_t *ui64_add(u_int64_t *, unsigned long);
extern int64_t *si64_add(int64_t *, unsigned long);
/* Add two 64-bit quantities */
extern u_int64_t *ui64_add_u64u64(u_int64_t *, const u_int64_t *, const u_int64_t *);
extern int64_t *si64_add_s64s64(int64_t *, const int64_t *, const int64_t *);
/* Subtract two 64-bit quantities */
extern u_int64_t *ui64_subtract_u64u64(u_int64_t *, const u_int64_t *, const u_int64_t *);
extern int64_t *si64_subtract_s64s64(int64_t *, const int64_t *, const int64_t *);
/* 32x32->64 unsigned multiplication. */
extern u_int64_t *ui64_multiply_uu(u_int64_t *, unsigned long, unsigned long);
/* 64x64->64 unsigned multiplication. */
extern u_int64_t *ui64_multiply_u64u64(u_int64_t *, u_int64_t *, u_int64_t *);
/* Right shifting of 64-bit quantities */
extern u_int64_t *ui64_shift_right(u_int64_t *, unsigned);
extern int64_t *si64_shift_right(int64_t *, unsigned);
/* Narrowing cast to 32 bits. */
extern unsigned long ui64_value(const u_int64_t *);
extern long si64_value(const int64_t *);
#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.
;
; Title: s.callbacks
; Purpose: 'Usermode do-nothing' function to enable callbacks to fire
;
; Enclosed is the source to the function usermode_donothing. This drops you
; into user mode, does an OS_Byte 0,1 and then returns to supervisor mode.
; As the OS returns from the OS_Byte call callbacks are collected.
; Pre-condition: processor is in SVC26 or SVC32 mode
; Post-condition: processor is in same mode as on entry
AREA |asmutils$callback$$Code|,CODE,READONLY,PIC
GET hdr:ListOpts
GET hdr:Macros
GET hdr:System
GET hdr:Machine.<Machine>
GET hdr:APCS.<APCS>
; This function is currently known under many different names.
; Until they all synchronise (on usermode_donothing), export the
; aliases too.
[ :LNOT: :DEF: DefineAliases
GBLL DefineAliases
DefineAliases SETL {TRUE}
]
EXPORT usermode_donothing
[ DefineAliases
EXPORT CollectCallbacks
]
[ No32bitCode :LAND: No26bitCode
! 1, "This code cannot be used in No26bitCode and No32bitCode!"
]
; extern void usermode_donothing(void);
[ DefineAliases
CollectCallbacks
]
usermode_donothing
FunctionEntry "r12"
[ :DEF: XOS_ProcessCallbacks
SWI XOS_ProcessCallbacks ; Have we got the nice SWI to do it?
Return "r12",,VC
]
[ No32bitCode
TEQP pc, #0 ; Set USR26 mode
|
MRS r3, CPSR ; Get current PSR
BIC r3, r3, #2_01111 ; r2_c now USR26 or USR32 mode
MSR CPSR_c, r3 ; change mode
]
MOV r0, #0
MOV r1, #1
SWI XOS_Byte ; make a SWI call from USR mode
SWI XOS_EnterOS ; re-enter SVC26/SVC32 mode
[ No32bitCode
NOP
]
Return "r12"
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.
;
; Title: s.heapswis
; Purpose: Assembler veneers onto OS_Heap for speed
; Author: KJB
; History: 23-Nov-96: KJB: Created
; 20-Nov-99: SNB: 32-bitness added and rewritten for library
;
GET Hdr:ListOpts
GET Hdr:Macros
GET Hdr:System
GET Hdr:Machine.<Machine>
GET Hdr:APCS.<APCS>
GET Hdr:Heap
EXPORT xosheap_initialise
EXPORT xosheap_alloc
EXPORT xosheap_free
EXPORT xosheap_resize
EXPORT xosheap_read_size
AREA |AsmUtils$MemSWIs1$$Code|,CODE,READONLY,PIC
xosheap_initialise
MOV R12,LR
MOV R3,R1
MOV R1,R0
MOV R0,#HeapReason_Init
SWI XOS_Heap
ASSERT HeapReason_Init = 0
; MOVVC R0,#0 ; OS_Heap preserves R0
Return ,LinkNotStacked,,R12
AREA |AsmUtils$MemSWIs2$$Code|,CODE,READONLY,PIC
xosheap_alloc
FunctionEntry
MOV R12,R2
MOV R3,R1
MOV R1,R0
MOV R0,#HeapReason_Get
SWI XOS_Heap
STRVC R2,[R12]
MOVVC R0,#0
Return ,LinkNotStacked,,R12
AREA |AsmUtils$MemSWIs3$$Code|,CODE,READONLY,PIC
xosheap_free
MOV R12,LR
MOV R2,R1
MOV R1,R0
MOV R0,#HeapReason_Free
SWI XOS_Heap
MOVVC R0,#0
Return ,LinkNotStacked,,R12
AREA |AsmUtils$MemSWIs4$$Code|,CODE,READONLY,PIC
xosheap_resize
MOV R12,LR
MOV R3,R1
MOV R1,R0
MOV R0,#HeapReason_ExtendHeap
SWI XOS_Heap
MOVVC R0,#0
Return ,LinkNotStacked,,R12
AREA |AsmUtils$MemSWIs5$$Code|,CODE,READONLY,PIC
xosheap_read_size
FunctionEntry
MOV R12,R2
MOV R2,R1
MOV R1,R0
MOV R0,#HeapReason_ReadBlockSize
SWI XOS_Heap
STRVC R3,[R12]
MOVVC R0,#0
Return
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.
;
; Assembler function to give RM base address to C program
IMPORT |Image$$RO$$Base|
EXPORT Image_RO_Base
AREA Code_Description, DATA, REL
Image_RO_Base DCD |Image$$RO$$Base|
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.
;
; sixtyfour.s
;
; Author: SBrodie
;
GET Hdr:ListOpts
GET Hdr:Macros
GET Hdr:System
GET Hdr:Machine.<Machine>
GET Hdr:APCS.<APCS>
No26bitCode SETL {TRUE}
; Long multiplier ----------------------------------------
; Taken from Acorn Assembler manual.
; extern u_int64_t *ui64_multiply_uu(u_int64_t *, unsigned, unsigned);
AREA |AsmUtils$$SixtyFour1$$Code|, CODE, READONLY, PIC
EXPORT ui64_multiply_uu
ui64_multiply_uu
[ No26bitCode
UMULL a3, a4, a2, a3
STMIA a1, {a3, a4}
MOV pc, lr
|
FunctionEntry
MOVS lr, a2, LSR #16
BIC a2, a2, lr, LSL #16
MOV ip, a3, LSR #16
BIC a3, a3, ip, LSL #16
MUL a4, a2, a3
MUL a3, lr, a3
MUL a2, ip, a2
MULNE lr, ip, lr
ADDS a2, a2, a3
ADDCS lr, lr, #&10000