diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT')
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/CONFIG.H | 74 | ||||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/DYNLINK.S | 72 | ||||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/INTERNS.H | 12 | ||||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAIN.S | 26 | ||||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAKEFILE | 101 | ||||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSHL | 34 | ||||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSTUB.APJ | bin | 0 -> 156 bytes | |||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.APJ | bin | 0 -> 103 bytes | |||
| -rw-r--r-- | Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.C | 18 |
9 files changed, 337 insertions, 0 deletions
diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/CONFIG.H b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/CONFIG.H new file mode 100644 index 0000000..18f6fbf --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/CONFIG.H @@ -0,0 +1,74 @@ +/* + * config.h - modified specially for reentrant strlib. + * Copyright (C) Advanced RISC Machines Limited 1994. All rights reserved. + */ + +#define BYTESEX_EVEN 1 /* little-endian */ +/*#define BYTESEX_ODD 1 -- BIG-endian */ + +/* + * Define this to get a shared library with an initialised data image in the + * library. Undefine it to get the data image in the library stub. Remember + * To modify strshl in step (the line containing + {}). + */ +#define DATA_IN_LIBRARY 1 /* needs +{} in strshl */ + +#include "interns.h" + +#define memcpy_c +#define memmove_c +#define memchr_c +#define memcmp_c +#define memset_c +#define strcat_c +#define strchr_c +#define strcmp_c +#define strcoll_c +#define strcpy_c +#define strcspn_c +#define strerror_c +#define strlen_c +#define strncat_c +#define strncmp_c +#define strncpy_c +#define strpbrk_c +#define strrchr_c +#define strspn_c +#define strstr_c +#ifndef DATA_IN_LIBRARY +#define strtok_c +#endif +#define strxfrm_c +#define _strerror_c + +#include <string.h> + +static char *_hostos_error_string(unsigned int n, char *v) +{ char *s = v; + int j; + strcpy(s, "unknown shared string-library error 0x"); + s += strlen(s); + for (j = 0; j < 8; ++ j) + { *s++ = "0123456789ABCDEF"[n >> 28]; + n <<= 4; + } + *s = 0; + return v; +} + + +#ifdef DATA_IN_LIBRARY + +static char *saves1 = NULL; + +char *strtok(char *s1, const char *s2) +{ char *s0; + if (s1 == 0) s1 = (saves1 == NULL) ? "" : saves1; /* use saved pointer */ + if (*(s1 += strspn(s1,s2)) == 0) s0 = 0; /* no tokens */ + else { s0 = s1; + if (*(s1 += strcspn(s1,s2)) != 0) *s1++ = 0; /* insert 0 if nec */ + } + return (saves1 = s1, s0); +} + +#endif diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/DYNLINK.S b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/DYNLINK.S new file mode 100644 index 0000000..571740a --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/DYNLINK.S @@ -0,0 +1,72 @@ + AREA |DynamicLinker|, CODE, READONLY, REENTRANT
+
+ EXPORT |__rt_dynlink|
+
+|__rt_dynlink|
+; Enter from a call through the stub vector with r0-r6, lr saved on sp...
+; ip (the 'new sb' value) is the index of the proxy function in the stub
+; vector which caused this entry to the dynamic linker and identifies
+; which call to resume after linking.
+; On entry r0 points to the 4-word dynamic linker entry veneer at the
+; end of the stub vector.
+
+ MOV r6, r0
+ LDR r5, [r6, #-8] ; # entries - 1
+ ADD r5, r5, #1 ; # entries
+ MOV r4, ip ; resume index
+
+; r6+24 points to the EFT parameter block; call the library location function
+; to return a pointer to the matching library... Here we assume it's loaded
+; at 0x40000...
+
+; In the following line, the Makefile relies on a space after '#' and on the
+; contents of the comment. DO NOT CHANGE THESE OR Makefile WILL FAIL.
+
+ MOV r0, # 0x40000 ; EFT Address (DO NOT ALTER THIS COMMENT)
+
+; r0 now points to the EFT
+ LDR ip, [r0] ; #entries
+ CMPS ip, r5
+ BLT Botched ; not enough entries to init the stub
+
+ LDR ip, [r6, #16] ; stub data len
+ BIC ip, ip, #3 ; word aligned, I insist...
+ ADD r3, r0, #4
+ LDR r3, [r3, r5, LSL #2] ; library data len...
+ CMPS r3, ip
+ BNE Botched
+
+ LDR r3, [r6, #20] ; stub data dest
+ SUB r2, r0, ip ; library data src - precedes EFT
+01 SUBS ip, ip, #4 ; word by word copy loop
+ LDRGE r1, [r2], #4
+ STRGE r1, [r3], #4
+ BGE %B01
+
+ LDR ip, [r6, #12] ; length of the inter-LU data area
+ ADD r3, r6, #24 ; end of the inter-LU data area...
+ SUB r3, r3, ip ; sb = start of inter-LU data area
+
+ LDR r2, [r6, #-8]! ; index of stub entry
+00 SUB ip, r5, #1 ; index of the lib entry
+ CMPS ip, r2 ; is this lib entry in the stub?
+ SUBGT r5, r5, #1 ; no, skip it
+ BGT %B00
+ CMPS r2, r4 ; found the retry index?
+ MOVEQ lr, r6 ; yes: remember it
+ LDR ip, [r0, r5, lsl #2] ; entry point offset
+ ADD ip, ip, r0 ; entry point address
+ STMIA r6, {r3, ip} ; save {sb, pc}
+ LDR r2, [r6, #-8]! ; load index and decrement r6...
+ TST r2, #&ff000000 ; ... or if loaded instruction?
+ LDRNE r2, [r6, #-8]! ; load index and decrement r6 if instr
+ SUBS r5, r5, #1
+ BGT %B00
+
+ MOV ip, lr ; retry address
+ LDMFD sp!, {r0-r6, lr} ; restore saved regs
+ LDMIA ip, {ip, pc} ; and retry the call
+
+Botched B Botched
+
+ END
diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/INTERNS.H b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/INTERNS.H new file mode 100644 index 0000000..3a3fd1a --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/INTERNS.H @@ -0,0 +1,12 @@ +/* + * Dummy interns.h sufficient to compile strlib. + * Copyright (C) Advanced RISC Machines Limited 1994. All rights reserved. + */ + +#ifndef __internals_h +#define __internals_h + +extern char *_strerror(int n, char *v); +extern void __set_strcoll_table(const unsigned char *table); + +#endif diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAIN.S b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAIN.S new file mode 100644 index 0000000..552f24d --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAIN.S @@ -0,0 +1,26 @@ + EXPORT __main
+ IMPORT main
+ IMPORT |sb$$interLUdata$$Base|
+
+SWI_GetEnv * &10
+SWI_Exit * &11
+
+ AREA |StartupCode|, CODE, READONLY, REENTRANT
+
+;
+; This is the initial entry point to the image.
+; (The compiler ensures it is linked in to the image by generating a reference
+; to __main from the object module generated from compiling a file containing
+; an extern main()).
+ ENTRY
+
+; We have to establish a stack for C, initialise the library, then call _main
+; (which will set up the arguments for main, then call it).
+|__main|
+ LDR r9, =|sb$$interLUdata$$Base|
+ SWI SWI_GetEnv ; to decide heap limit
+ MOV r13, r1 ; top of program workspace
+ BL |main|
+ SWI SWI_Exit
+
+ END
diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAKEFILE b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAKEFILE new file mode 100644 index 0000000..e51ed42 --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/MAKEFILE @@ -0,0 +1,101 @@ +# Copyright (C) Advanced RISC Machines Limited 1994. All rights reserved.
+# Makefile for shared string library (reentrant APCS) example.
+
+CLIBSRC=../../cl
+CC=armcc
+LD=armlink
+AS=armasm
+SD=armsd
+
+# If you change -li below and in the $(SD) command later, you MUST change
+# config.h to #define BYTESEX_ODD, not BYTESEX_EVEN. This Makefile and all
+# the sources it uses assume little-endian operation.
+
+RCFLAGS=-li -apcs 3/32bit/reent -zps1
+RAFLAGS=-li -apcs 3/32bit/reent
+
+.SILENT:
+
+all:
+ echo "Use 'make run' to run the test"
+ echo "Use 'make build' to build the test"
+ echo "Use 'make clean' to tidy up afterwards"
+
+# A armsd.ini file is used to load the shared string library so that its
+# EFT starts at 0x4000 (built in to dynlink.s - see below). You can alter
+# this provided you do so carefully...
+
+build: rstub.o strtest armsd.ini
+ echo "Now use 'make run' to run the test"
+
+run: strlib strtest armsd.ini
+ $(SD) -li strtest
+ echo "Now use 'make clean' to tidy up"
+
+clean:
+ rm -f armsd.ini map maplib strtest strlib *.o
+
+# Here we make a sharable library out of the ANSI C Library's string functions.
+# We make a reentrant stub for use with a reentrant client.
+
+rstub.o: string.o
+ echo Making strlib and rstub.o
+ echo "Please ignore (Warning) Attribute conflict"
+ echo ""
+ $(LD) -o rstub.o -reent -s - -shl strshl -map string.o > maplib
+ @echo Made strlib and a matching reentrant stub
+
+# The armsd.ini file instructs armsd to load the shared string library so its
+# EFT is located at the address assumed by dynlink.s. Here, we grep the
+# assumed address from dynlink.s and the EFT's offset from the library's
+# map file (maplib). We load the library at <address>-<EFT offset>.
+# eg.
+# armsd: getfile strlib 0x40000-0x0009c8
+# ^^^^^^^^ value of EFT$$Offset from maplib
+# armsd: go
+
+armsd.ini: dynlink.s maplib
+ echo Making $@
+ fgrep 'EFT Address' dynlink.s | \
+ awk '{printf "getfile strlib %s",$$4}' - > armsd.ini
+ fgrep 'EFT$$$$Offset' maplib | awk '{printf "-0x%s\n",$$2}' - >> armsd.ini
+
+# We use a local dummy copy of interns.h and a local copy of config.h which
+# patches around some deficiencies in the library sources prior to r1.6.2.
+
+string.o: $(CLIBSRC)/string.c interns.h config.h
+ echo Making $@
+ $(CC) $(RCFLAGS) -c -I. $(CLIBSRC)/string.c
+
+# Here we link the test program with:
+# - the dynamic linker (dynlink.o)
+# - the reentrant stub of the library
+# - a small piece of startup code which provides the same run-line
+# environment as a fully reentrant, shared C library kernel would provide.
+
+strtest: strtest.o dynlink.o main.o
+ echo Making $@
+ echo "Please ignore (Waring) Attribute conflict"
+ echo ""
+ $(LD) -d -o strtest strtest.o dynlink.o rstub.o main.o -map > map
+
+strtest.o: strtest.c
+ echo Making $@
+ $(CC) $(RCFLAGS) -c strtest.c
+
+dynlink.o: dynlink.s
+ echo Making $@
+ $(AS) $(RAFLAGS) dynlink.s dynlink.o
+
+main.o: main.s
+ echo Making $@
+ $(AS) $(RAFLAGS) main.s main.o
+
+# Null dependencies
+
+maplib: rstub.o
+
+strlib: rstub.o
+
+dynlink.s:
+
diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSHL b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSHL new file mode 100644 index 0000000..3eee490 --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSHL @@ -0,0 +1,34 @@ +> strlib \
+ 0x40000
+
+; Include an image of the initialised data in the library itself.
+; Dynlink will copy this at run time to a zero-initialised area
+; reserved by the stub.
+
++()
+
+; Functions exported from the sharable string library
+
+memcpy
+memmove
+memchr
+memcmp
+strcat
+strchr
+strcmp
+strcoll
+__set_strcoll_table
+strcpy
+strcspn
+strerror
+_strerror
+strlen
+strncat
+strncmp
+strncpy
+strpbrk
+strrchr
+strspn
+strstr
+strtok
+strxfrm
diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSTUB.APJ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSTUB.APJ Binary files differnew file mode 100644 index 0000000..95d64b1 --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRSTUB.APJ diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.APJ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.APJ Binary files differnew file mode 100644 index 0000000..93109e2 --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.APJ diff --git a/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.C b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.C new file mode 100644 index 0000000..a2ee0a3 --- /dev/null +++ b/Bachelor/Mikroprozessorsysteme2/ARM202U/EXAMPLES/REENT/STRTEST.C @@ -0,0 +1,18 @@ +extern char *strerror(int);
+
+__swi(0) void writec(int);
+
+
+static void puts(char *s)
+{ int ch;
+ for (ch = *s; ch != 0; ch = *++s) writec(ch);
+}
+
+int main()
+{
+ puts("\nstrerror(42) returns \"");
+ puts(strerror(42));
+ puts("\"\n\r\n");
+
+ return 0;
+}
|
