Commit 9081a0dc authored by Kevin Bracey's avatar Kevin Bracey
Browse files

Ursula branch merged.

StrongARMfudge flag removed.
StrongARM compatibility set according to AMBKernel flag in Hdr:RISCOS
strftime %U and %W specifiers fixed for week 0.

Version 4.89. Tagged as 'RISC_OSLib-4_89'
parent fbb4fb50
......@@ -80,6 +80,17 @@ DFLAGS =\
-DALLOW_OLD_PATTERNS\
-DSET_MISC_OPTIONS
# ANSILib flags
CLFLAGS =\
-DDEFAULT_TEXT
ALFLAGS =\
-PD "DEFAULT_TEXT SETL {TRUE}"
VLFLAGS =\
-DLIB_SHARED="\"\""\
-DLIB_APCS="\"R\""
# Shared C Library flags
CSFLAGS =\
-I@,^.clib\
......@@ -90,22 +101,18 @@ VSFLAGS =\
-DLIB_SHARED="\"Shared \""\
-DLIB_APCS="\"R\""
VLFLAGS =\
-DLIB_SHARED="\"\""\
-DLIB_APCS="\"R\""
VPATH = @ kernel clib rlib
.SUFFIXES: .o .o_rl .m_o_rl .rm_o .rm_o_rl
#
# Rule patterns
#
.c.o:; ${CC} ${CFLAGS} -fah -o $@ $<
.c.o:; ${CC} ${CFLAGS} -fah ${CLFLAGS} -o $@ $<
.c.o_rl:; ${CC} ${CFLAGS} ${DFLAGS} -o $@ $<
.c.m_o_rl:; ${CC} ${CFLAGS} -ffah ${DFLAGS} -zM -o $@ $<
.c.rm_o:; ${CC} ${CFLAGS} -ffah ${DFLAGS} -zm1 ${CSFLAGS} -o $@ $<
.c.rm_o_rl:; ${CC} ${CFLAGS} -ffah ${DFLAGS} -zm1 ${CSFLAGS} ${STK_EXTN} -o $@ $<
.s.o:; ${OBJASM} ${AFLAGS} $< $@
.s.o:; ${OBJASM} ${AFLAGS} ${ALFLAGS} $< $@
.s.o_rl:; ${OBJASM} ${AFLAGS} $< $@
.s.m_o_rl:; ${OBJASM} ${AFLAGS} $< $@
.s.rm_o:; ${OBJASM} ${AFLAGS} $< $@
......@@ -236,7 +243,7 @@ EXPORTS = ${MODWRAP} \
#
ANSI_OBJS =\
o.alloc o.armprof o.armsys o.clib o.ctype o.error o.fpprintf \
o.kernel o.locale o.math o.memcpy o.overmgr o.printf o.scanf \
o.kernel o.locale o.math o.memcpset o.overmgr o.printf o.scanf \
o.signal o.sort o.stdio o.stdlib o.string o.swiv o.time
RM_OBJS =\
......@@ -250,7 +257,7 @@ RM_OBJS =\
rm_o.fpprintf \
rm_o.locale \
rm_o.math \
rm_o.memcpy \
rm_o.memcpset \
rm_o.printf \
rm_o.scanf \
rm_o.signal \
......@@ -597,10 +604,10 @@ RISC_OSLib:s.modulewrap: s.modulewrap; ${CP} s.modulewrap $@ ${CPFLAGS}
# Objects whose name isn't the same as their source
#
o.clib: clib.s.cl_obj_r
${OBJASM} ${AFLAGS} -from clib.s.cl_obj_r -to $@
${OBJASM} ${AFLAGS} ${ALFLAGS} -from clib.s.cl_obj_r -to $@
o.kernel: kernel.s.k_obj_r
${OBJASM} ${AFLAGS} -from kernel.s.k_obj_r -to $@
${OBJASM} ${AFLAGS} ${ALFLAGS} -from kernel.s.k_obj_r -to $@
rm_o.bsearch_a: c.bsearch
${CC} ${CFLAGS} -ffah ${DFLAGS} -zm1 ${CSFLAGS} -zkA -o $@ c.bsearch
......@@ -630,19 +637,19 @@ rm_o_rl.initmodule: rlib.s.initmod_r
# Objects that require extra flags
#
o.armsys: c.armsys
${CC} ${CFLAGS} -fah ${VLFLAGS} -o $@ c.armsys
${CC} ${CFLAGS} -fah ${CLFLAGS} ${VLFLAGS} -o $@ c.armsys
o.armprof: c.armprof
${CC} ${CFLAGS} -fah ${VLFLAGS} -pcc -o $@ c.armprof
${CC} ${CFLAGS} -fah ${CLFLAGS} ${VLFLAGS} -pcc -o $@ c.armprof
o.string: c.string
${CC} ${CFLAGS} -fah -DSEPERATE_MEMCPY -o $@ c.string
${CC} ${CFLAGS} -fah ${CLFLAGS} -DSEPARATE_MEMCPY -DSEPARATE_MEMSET -o $@ c.string
rm_o.armsys: c.armsys
${CC} ${CFLAGS} -ffah ${DFLAGS} -zm1 ${CSFLAGS} ${VSFLAGS} -o $@ c.armsys
rm_o.string: c.string
${CC} ${CFLAGS} -ffah ${DFLAGS} -zm1 ${CSFLAGS} -DSEPERATE_MEMCPY -o $@ c.string
${CC} ${CFLAGS} -ffah ${DFLAGS} -zm1 ${CSFLAGS} -DSEPARATE_MEMCPY -DSEPARATE_MEMSET -o $@ c.string
#
# Special case: use "rom_defs" for ROM library (o_rm), "defs" for the others
......
......@@ -14,12 +14,6 @@
|
Dir <Obey$Dir>
wimpslot -min 1000k
echo amu_machine lib.stubs
|amu_machine lib.stubs
echo amu_machine lib.risc_oslib
amu_machine lib.risc_oslib
echo amu_machine lib.clib
|amu_machine lib.clib
echo amu_machine lib.ansilib
amu_machine lib.ansilib
echo amu_machine lib.stubs lib.risc_oslib lib.riscoslibm lib.clib lib.ansilib
amu_machine lib.stubs lib.risc_oslib lib.riscoslibm lib.clib lib.ansilib
echo MkLibs: all done
......@@ -5,8 +5,8 @@
GBLA Module_Version
GBLS Module_MinorVersion
GBLS Module_Date
Module_MajorVersion SETS "4.88"
Module_Version SETA 488
Module_MajorVersion SETS "4.89"
Module_Version SETA 489
Module_MinorVersion SETS ""
Module_Date SETS "11 Sep 1998"
Module_Date SETS "01 Oct 1998"
END
/* (4.88)
/* (4.89)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 4.88
#define Module_MajorVersion_CMHG 4.89
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 11 Sep 1998
#define Module_Date_CMHG 01 Oct 1998
#define Module_MajorVersion "4.88"
#define Module_Version 488
#define Module_MajorVersion "4.89"
#define Module_Version 489
#define Module_MinorVersion ""
#define Module_Date "11 Sep 1998"
#define Module_Date "01 Oct 1998"
......@@ -33,6 +33,7 @@
#include <ctype.h> /* isprint(), isspace() */
#include <string.h> /* for strlen() */
#include <time.h> /* for clock */
#include <errno.h>
/* IMPORTS */
extern int main(int argc, char **argv); /* the point of it all */
......@@ -179,6 +180,14 @@ default: /* a good a place as any for an unknown machine */
/* system dependent I/O routines ... */
/* Riscos has a second distinguished FILEHANDLE value, to indicate that */
/* a file is a keyboard and/or vdu, which can't be read or written using */
/* Riscos file operations (or at any rate, couldn't when the library was */
/* originally implemented). */
#define TTYHANDLE 0
#define istty(fh) ((fh) == TTYHANDLE)
static int _error_recursion;
void _sys_msg(const char *s)
{ /* write out s carefully for intimate system use. */
......@@ -208,9 +217,9 @@ static int isttyname(const char *s)
FILEHANDLE _sys_open(const char *filename, int openmode)
{ /* nasty magic number interface for openmode */
static const int modtab[6] = { /* r = */ 0x040, /* r+ = */ 0x0c0,
/* w = */ 0x4c0, /* w+ = */ 0x4c0,
/* a = */ 0x3c0, /* a+ = */ 0x3c0 };
static const int modtab[6] = { /* r = */ 0x04c, /* r+ = */ 0x0cc,
/* w = */ 0x4cc, /* w+ = */ 0x4cc,
/* a = */ 0x3cc, /* a+ = */ 0x3cc };
if (isttyname(filename)) return TTYHANDLE;
else {
char *name = (char *)filename; /* yuk yuk yuk yuk yuk */
......@@ -220,45 +229,119 @@ FILEHANDLE _sys_open(const char *filename, int openmode)
_kernel_osfile_block fb;
/* maybe stamp file with current datestamp */
if ((openmode & 16) || /* update timestamp requested */
(openmode >= 4 && openmode <= 9)) /* or mode = w, w+, or a */
{ if (_kernel_osfile(9, name, &fb) <0) /* (contents of fb irrelevant) */
if ((openmode & OPEN_T) || /* update timestamp requested */
(openmode & OPEN_W) ||
(openmode & ~OPEN_B) == OPEN_A) /* or mode = w, w+, or a */
{ if (_kernel_osfile(9, name, &fb) == _kernel_ERROR)
{ if (_kernel_last_oserror()->errnum == 0x108c9)
{ (void)_kernel_osfile(9, name, &fb); /* to restore the error */
errno = -1;
return NONHANDLE; /* (Protected disc) */
}
}
}
retry_open:
fh = _kernel_osfind(osmode & 0xff, name);
if (osmode <= 0x0c0) /* r or r+ */
if (osmode <= 0x0cc) { /* r or r+ */
if (fh == _kernel_ERROR) errno = -1;
return (fh <= 0) ? NONHANDLE : /* not found */
fh;
else if (fh > 0) {
if ((osmode == 0x4c0) || (size == 0))
} else if (fh > 0) {
if ((osmode == 0x4cc) || (size == 0))
if (_kernel_osargs(3, fh, 0) == _kernel_ERROR) {
_kernel_osfind(0, (char *)fh);
errno = -1;
return NONHANDLE;
}
return fh;
} else if (fh == 0) {
} else if (fh <= 0) {
/* _kernel_osfile(11) creates an empty file of size 'size', of type */
/* given by fb.load, stamped with the current date & time */
fb.load = (openmode & 1) ? 0xffd : 0xfff; /* data : text */
fb.start = 0;
for (; ; size >>= 1) {
if (size < 512) return NONHANDLE; /* probably Disc Full */
if (size < 512) { errno = -1; return NONHANDLE; }
fb.end = size;
if (_kernel_osfile(11, name, &fb) > 0) break;
}
size = 0;
goto retry_open;
}
if (fh == _kernel_ERROR) errno = -1;
return NONHANDLE;
}
}
int _ttywrite(unsigned char *buf, unsigned int len, int flag)
int _sys_istty(FILE *stream)
{
return istty(stream->__file);
}
int _sys_seek(FILEHANDLE fh, long pos)
{
if istty(fh) return 0;
{ int rc = _kernel_osargs(1, fh, (int)pos);
if (rc == _kernel_ERROR) errno = -1;
return rc;
}
}
long _sys_flen(FILEHANDLE fh)
{
int rc = _kernel_osargs(2, fh, 0);
if (rc == _kernel_ERROR) errno = -1;
return rc;
}
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{ if (istty(fh))
return _ttywrite(buf, len, mode);
else {
_kernel_osgbpb_block b;
b.dataptr = (void *)buf;
b.nbytes = (int)len;
if (_kernel_osgbpb(2, fh, &b) == _kernel_ERROR) {
errno = -1;
return _kernel_ERROR;
} else
return b.nbytes;
}
}
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
{
if (istty(fh))
return _ttyread(buf, (int)len, mode);
else {
_kernel_osgbpb_block b;
b.dataptr = (void *)buf;
b.nbytes = (int)len;
if (_kernel_osgbpb(4, fh, &b) == _kernel_ERROR) {
errno = -1;
return _kernel_ERROR;
} else
return b.nbytes;
}
}
int _sys_ensure(FILEHANDLE fh)
{
if (istty(fh)) return 0;
{ int rc = _kernel_osargs(0xFF, fh, 0);
if (rc == _kernel_ERROR) errno = -1;
return rc;
}
}
int _sys_close(FILEHANDLE fh)
{ if (istty(fh)) return 0;
{ int rc = _kernel_osfind(0, (char *)fh);
if (rc == _kernel_ERROR) errno = -1;
return rc;
}
}
int _ttywrite(const unsigned char *buf, unsigned int len, int flag)
/* behaves like Kgbpb, but outputs to console. */
/* if 'flag' has _IOBIN set then LF's ('\n's) do not have CR prefixed. */
{ while (len-- > 0)
......
......@@ -26,6 +26,7 @@
#include <assert.h> /* for __assert() */
#include <string.h> /* for strerror */
#include <errno.h>
#include "kernel.h"
extern int _fprintf_lf(FILE *fp, const char *fmt, ...);
extern int _sprintf_lf(char *buff, const char *fmt, ...);
......@@ -55,53 +56,14 @@ void __assert(char *expr, char *file, int line)
abort();
}
/* from <string.h> */
char *strerror(int n)
{
static char v[80];
char *s, *t;
switch (n)
{ case 0:
t = "C35";
#ifdef DEFAULT_TEXT
s = "No error (errno = 0)";
#endif
break;
case EDOM:
t = "C36";
#ifdef DEFAULT_TEXT
s = "EDOM - function argument out of range";
#endif
break;
case ERANGE:
t = "C37";
#ifdef DEFAULT_TEXT
s = "ERANGE - function result not representable";
#endif
break;
case ESIGNUM:
t = "C66";
#ifdef DEFAULT_TEXT
s = "ESIGNUM - illegal signal number to signal() or raise()";
#endif
break;
default:
t = "C38";
#ifdef DEFAULT_TEXT
s = "Error code (errno) %d has no associated message";
#endif
break;
extern char *_hostos_error_string(int no, char *buf) {
buf = buf; /* unused */
if (no == -1) {
_kernel_oserror *e = _kernel_last_oserror();
return (e == NULL) ? _kernel_getmessage("unspecified error", "C69") : e->errmess;
} else {
return _kernel_getmessage("unknown error", "C70");
}
s = _kernel_getmessage(s, t);
_sprintf_lf(v, s, n);
return v;
}
/* from <stdio.h> */
void perror(const char *s)
{ if (s != 0 && *s != 0) fprintf(stderr, "%s: ", s);
fprintf(stderr, "%s\n", strerror(errno));
}
/* end of error.c */
......@@ -223,7 +223,7 @@ static int findweek(int yday, int startday, int today)
int last_weekstart;
if (days_into_this_week < 0) days_into_this_week += 7;
last_weekstart = yday - days_into_this_week;
if (last_weekstart <= 0) return 1;
if (last_weekstart <= 0) return 0;
return last_weekstart/7 + 1;
}
......
......@@ -61,8 +61,10 @@ void *bsearch(const void *key, const void *base,
}
}
#ifndef UROM
/* must not use Shellsort - it is broken (subtracts potentially large
offsets from pointers before comparing with base, can wrap) */
/* #ifndef UROM */
#if 1
/* Qsort is implemented using an explicit stack rather than C recursion */
/* See Sedgewick (Algorithms, Addison Wesley, 1983) for discussion. */
......@@ -263,6 +265,8 @@ void qsort(void *base, size_t nmemb, size_t size,
}
}
#else
/* this is broken - see comments at top of #if */
/* For ROM version we use Shellsort instead of Quicksort for a saving of 880
* bytes. This Shellsort has proven worst case < N^1.5, empirically it is
* much better. Typical average case is either N(LOG(N)^2) or N^1.25.
......@@ -302,7 +306,7 @@ void qsort(void *base, size_t nmemb, size_t size,
pi += 4;
do {
*(int *)p1 = *(int *)p2;
p1 -= hsize;
p1 -= hsize; /* one of the broken bits */
p2 -= hsize;
} while (p2 >= pj);
*(int *)pj = t;
......
......@@ -41,6 +41,7 @@
#include <errno.h>
#include "kernel.h" /* debug */
#include "hostsys.h"
extern char *_kernel_getmessage(char *msg, char *tag);
extern int _fprintf_lf(FILE *fp, const char *fmt, ...);
......@@ -227,13 +228,13 @@ static int _writebuf(unsigned char *buf, int len, FILE *stream)
int flag = stream->__flag;
if (flag & _IOSHARED) /* this is really gross */
{ flag |= _IOSEEK;
stream->__pos = _sys_flen_(fh);
stream->__pos = _sys_flen(fh);
dbmsg("_IOSHARED so zoom to end %d\n", (int)stream->__pos);
}
if (flag & _IOSEEK+_IOBUFREAD)
{
dbmsg("_writebuf seeking to %d\n", (int)stream->__pos);
if (_sys_seek_(fh, (int)stream->__pos) < 0)
if (_sys_seek(fh, (int)stream->__pos) < 0)
{ seterr(stream);
return EOF;
}
......@@ -243,7 +244,7 @@ dbmsg_noNL("_writebuf pop goes the stoat %i, ", fh);
dbmsg_noNL("%X, ", buf);
dbmsg_noNL("%d, ", len);
dbmsg("%X\n", flag);
w = _sys_write_(fh, buf, len, flag);
w = _sys_write(fh, buf, len, flag);
stream->__flag |= _IOADFSBUG;
dbmsg("_sys_write_ returned %d\n", w);
stream->__pos += len - (w & 0x7fffffffL);
......@@ -251,7 +252,7 @@ dbmsg("_sys_write_ returned %d\n", w);
{ seterr(stream);
return(EOF);
}
dbmsg("filelen = %d\n",_sys_flen_(fh)); /* length of this file */
dbmsg("filelen = %d\n",_sys_flen(fh)); /* length of this file */
return 0;
}
......@@ -358,7 +359,7 @@ dbmsg("%s\n", "!= _IOWRITE");
dbmsg("%s\n", "set IODIRTIED");
stream->__flag = (flag |= (_IODIRTIED+_IONOREADS)); /* we are writing */
if (stream->__base == NULL)
{ if (_sys_istty_(stream->__file)) { /* terminal - unbuffered */
{ if (_sys_istty(stream)) { /* terminal - unbuffered */
stream->__ptr = stream->__base = stream->__extrap->__lilbuf;
stream->__bufsiz = 1;
stream->__flag = (flag |= _IONBF);
......@@ -446,10 +447,10 @@ dbmsg("fillbuf negative icnt = %d\n", stream->__icnt);
else {
dbmsg("fillbuf seeking to %d\n", (int)stream->__pos);
if (stream->__flag & _IOADFSBUG) {
_sys_ensure_(fh);
_sys_ensure(fh);
stream->__flag &= ~_IOADFSBUG;
}
if (_sys_seek_(fh, (int)stream->__pos) < 0)
if (_sys_seek(fh, (int)stream->__pos) < 0)
{ seterr(stream);
return EOF;
}
......@@ -469,10 +470,10 @@ dbmsg("fillbuf flag %X\n", stream->__flag);
if ((stream->__flag & (_IOBUFREAD+_IOSEEK)) == 0) {
dbmsg("fillbuf dirty buffer, read into end,seeking to %d\n",(int) stream->__pos+extent);
if (stream->__flag & _IOADFSBUG) {
_sys_ensure_(fh);
_sys_ensure(fh);
stream->__flag &= ~_IOADFSBUG;
}
if (_sys_seek_(fh, (int) stream->__pos + extent) < 0)
if (_sys_seek(fh, (int) stream->__pos + extent) < 0)
{ seterr(stream);
return EOF;
} else stream->__flag |= _IOBUFREAD;
......@@ -490,9 +491,9 @@ dbmsg("at buff %X\n", (int)buff);
dbmsg("READING FROM FILE REQUEST = %d\n", request);
dbmsg("filelen = %d\n",_sys_flen_(fh)); /* length of this file */
dbmsg("filelen = %d\n",_sys_flen(fh)); /* length of this file */
stream->__icnt = 0;
w = _sys_read_(fh, buff, request, stream->__flag);
w = _sys_read(fh, buff, request, stream->__flag);
stream->__flag &= ~_IOADFSBUG;
dbmsg("_sys_read_ returned %d\n", w);
if (w<0) {
......@@ -559,7 +560,7 @@ int fclose(FILE *stream)
}
/* Assert: fd != SYS_OPEN => fh is shared and mustn't be closed */
if (fd == _SYS_OPEN &&
_sys_close_(fh) < 0) res = EOF; /* close real file */
_sys_close(fh) < 0) res = EOF; /* close real file */
if (flag & _IOSBF) free(buff); /* free buffer if system */
if ((flag & _IODELMSK) == _IODEL)
{ char name[L_tmpnam];
......@@ -585,20 +586,20 @@ FILE *freopen(const char *name, const char *mode, FILE *iob)
fclose(iob);
switch (*mode++)
{ default: return(NULL); /* mode is incorrect */
case 'r': flag = _IOREAD; openmode = 0; break;
case 'w': flag = _IOWRITE; openmode = 4; break;
case 'r': flag = _IOREAD; openmode = OPEN_R; break;
case 'w': flag = _IOWRITE; openmode = OPEN_W; break;
case 'a': flag = _IOWRITE | _IOAPPEND;
openmode = 8; break;
openmode = OPEN_A; break;
}
for (;;)
{ switch (*mode++)
{
case '+': flag |= _IOREAD+_IOWRITE, openmode |= 2;
case '+': flag |= _IOREAD+_IOWRITE, openmode |= OPEN_PLUS;
continue;
case 'b': flag |= _IOBIN, openmode |= 1;
case 'b': flag |= _IOBIN, openmode |= OPEN_B;
continue;
}
if (*(mode-1) == 't') openmode |= 16;
if (*(mode-1) == 't') openmode |= OPEN_T;
break;
}
if ((fh = _sys_open(name, openmode)) == NONHANDLE) return NULL;
......@@ -606,7 +607,7 @@ FILE *freopen(const char *name, const char *mode, FILE *iob)
iob->__ptr = iob->__base = NULL; iob->__bufsiz = BUFSIZ;
iob->__flag = flag;
iob->__file = fh;
if (openmode & 8) fseek(iob, 0L, SEEK_END); /* a or a+ */
if (openmode & OPEN_A) fseek(iob, 0L, SEEK_END); /* a or a+ */
return iob;
}
......@@ -654,7 +655,7 @@ FILE *_fopen_string_file(const char *data, int length)
}
int _fisatty(FILE *stream) /* not in ANSI, but related needed for ML */
{ if ((stream->__flag & _IOREAD) && _sys_istty_(stream->__file)) return 1;
{ if ((stream->__flag & _IOREAD) && _sys_istty(stream)) return 1;
return 0;
}
......@@ -840,7 +841,7 @@ int fseek(FILE *stream, long int offset, int whence)
int flag = stream->__flag;
dbmsg_noNL("%s ", "SEEK ENTRY");
if (!(flag & _IOREAD+_IOWRITE+_IOSHARED) || _sys_istty_(fh))
if (!(flag & _IOREAD+_IOWRITE+_IOSHARED) || _sys_istty(stream))
return(2); /* fseek impossible */
switch(whence)
......@@ -852,7 +853,7 @@ case SEEK_CUR:
break;
case SEEK_END:
{ long int filelen, filepos;
filelen = _sys_flen_(fh); /* length of this file */
filelen = _sys_flen(fh); /* length of this file */
dbmsg("filelen in seek = %d\n", (int)filelen);
if (filelen<0) /* failed to read length */
{ seterr(stream);
......@@ -1000,4 +1001,10 @@ FILE *tmpfile()
return f;
}
void perror(const char *s)
{ char b[256];
if (s != 0 && *s != 0) fprintf(stderr, "%s: ", s);
fprintf(stderr, "%s\n", _strerror(errno, b));
}
/* end of stdio.c */
......@@ -12,9 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* string.c: ANSI draft (X3J11 Oct 86) library code, section 4.11 */
/* Copyright (C) A.C. Norman and A. Mycroft */
/* Copyright (C) Codemist Ltd., 1988 */
/* Copyright (C) Advanced Risc Machines Ltd., 1991 */
/* version 3a */
/* Also the routine 'strerror' is in 'perror.c' rather than here */
......@@ -57,7 +57,7 @@ extern void _set_strcoll(int territory);
/* copying functions */
#ifndef SEPERATE_MEMCPY
#ifndef SEPARATE_MEMCPY
void *memcpy(void *a, const void *b, size_t n)
/* copy memory (upwards) - it is an errof for args to overlap. */
......@@ -205,7 +205,8 @@ char *strncat(char *a, const char *b, size_t n)
/* comparison functions */
int memcmp(const void *a, const void *b, size_t n)
{ const unsigned char *ac = a, *bc = b;
{ const unsigned char *ac = (const unsigned char *)a,
*bc = (const unsigned char *)b;
#ifdef _copywords
if ((((int)ac | (int)bc) & 3) == 0)
{ while (n >= 4 && *(int *)ac == *(int *)bc)
......@@ -223,6 +224,36 @@ int memcmp(const void *a, const void *b, size_t n)
int strcmp(const char *a, const char *b) /* lexical comparison on strings */
{
#ifdef _copywords
#ifdef BYTESEX_EVEN
/* Improved little-endian ARM strcmp code by Ian Rickards, ARM Ltd. */
if ((((int)a | (int)b) & 3) == 0)
{ int w1, w2, res, rc;
nullbyte_prologue_();
do {
w1 = *(int *)a, a += 4;
w2 = *(int *)b, b += 4;
res = w1 - w2;
if (res != 0) goto strcmp_checkbytes;
} while (!word_has_nullbyte(w1));
return 0;
strcmp_checkbytes:
/* carry propagation in subtract means that no subtract-per-byte is needed */
rc = res << 24;
if (rc != 0) return rc;
if ((w1 & 0xff) == 0) return rc;
rc = res << 16;
if (rc != 0) return rc;
if ((w1 & 0xff00) == 0) return rc;
rc = res << 8;
if (rc != 0) return rc;
if ((w1 & 0xff0000) == 0) return rc;
return res;
#else
if ((((int)a | (int)b) & 3) == 0)
{ int w1, w2;
nullbyte_prologue_();
......@@ -230,15 +261,7 @@ int strcmp(const char *a, const char *b) /* lexical comparison on strings */
w1 = *(int *)a, a += 4;
w2 = *(int *)b, b += 4;
} while (w1 == w2 && !word_has_nullbyte(w1));
#ifdef BYTESEX_EVEN
for (;;)
{ char c1 = w1 & 0xff, c2 = w2 & 0xff;
int d = c1 - c2;
if (d != 0) return d;
if (c1 == 0) return 0;
w1 = w1 >> 8; w2 = w2 >> 8;
}
#else
for (;;)
{ char c1 = (w1 >> 24) & 0xff, c2 = (w2 >> 24) & 0xff;
int d = c1 - c2;
......@@ -249,11 +272,13 @@ int strcmp(const char *a, const char *b) /* lexical comparison on strings */
#endif
}
#endif
for (;;)
{ char c1 = *a++, c2 = *b++;
int d = c1 - c2;
if (d != 0) return d;
if (c1 == 0) return 0; /* no need to check c2 */
{ char const *ap = a; /* in order to move ap from reg a1 */
for (;;)
{ char c1 = *ap++, c2 = *b++;
int d = c1 - c2;
if (d != 0) return d;
if (c1 == 0) return d; /* no need to check c2 */
}
}
}
......@@ -303,14 +328,14 @@ size_t strxfrm(char *s1, const char *s2, size_t n)
int strcoll(const char *a, const char *b)
{
_kernel_swi_regs r;
int ret;
if (strcoll_territory == 0) return strcmp(a, b); /* C locale */
r.r[0] = strcoll_territory;
r.r[1] = (int)a;
r.r[2] = (int)b;
r.r[3] = 0;
if (_kernel_swi(Territory_Collate, &r, &r))
if (_swix(Territory_Collate, _INR(0,3)|_OUT(0),
strcoll_territory, a, b, 0,
&ret))
return 0;
return r.r[0];
}
......@@ -323,7 +348,7 @@ void _set_strcoll(int territory)
void *memchr(const void *s, _chararg ch, size_t n)
/* first instance of ch in s */
{ const unsigned char *t = s;
{ const unsigned char *t = (const unsigned char *)s;
unsigned char c1 = (unsigned char)ch;
while (n-- > 0) if (*t == c1) return (void *)t; else t++;
return 0;
......@@ -415,6 +440,8 @@ char *strtok(char *s1, const char *s2)
/* Miscellaneous functions */
#ifndef SEPARATE_MEMSET
void *memset(void *s, _chararg c, size_t n)
{
unsigned char *p = s;
......@@ -432,6 +459,13 @@ void *memset(void *s, _chararg c, size_t n)
return s;
}
#endif
char *strerror(int n)
{ static char v[80];
return _strerror(n, v);
}
size_t strlen(const char *a) /* find number of chars in a string */
{ const char *x = a + 1;
#ifdef _copywords
......@@ -466,4 +500,22 @@ size_t strlen(const char *a) /* find number of chars in a string */
return a - x;
}
/* End string processing library */
#include <errno.h>
char *_strerror(int n, char *v)
{
switch (n)
{ case 0:
return _kernel_getmessage("No error (errno = 0)", "C35");
case EDOM:
return _kernel_getmessage("EDOM - function argument out of range", "C36");
case ERANGE:
return _kernel_getmessage("ERANGE - function result not representable", "C37");
case ESIGNUM:
return _kernel_getmessage("ESIGNUM - illegal signal number to signal() or raise()", "C66");
default:
return _hostos_error_string(n, v);
}
}
/* End string.c */
......@@ -68,3 +68,5 @@ C66:ESIGNUM - ung
#{Default}
C67:Stub Daten Größe =
C68:Library Daten Größe =
C69:Nicht spezifizierter Fehler
C70:Unbekannter Fehler
......@@ -68,3 +68,5 @@ C66:ESIGNUM - incorrect signal number to signal() or raise()
#{Default}
C67:Stub data size =
C68:Library data size =
C69:unspecified error
C70:unknown error
......@@ -22,6 +22,8 @@
#ifndef __hostsys_h
#define __hostsys_h
#include <stdio.h>
#undef MACHINE
#ifdef __arm
# ifndef __ARM
......@@ -71,6 +73,11 @@
# endif
#endif
extern char *_strerror(int n, char *v);
/* The same as strerror, except that if an error message must be constructed
* this is done into the array v.
*/
extern int _interrupts_off;
extern void _raise_stacked_interrupts(void);
extern void _postmortem(char *msg, int mflag);
......@@ -98,7 +105,7 @@ extern void _exit(int n);
typedef int FILEHANDLE;
#define TTYFILENAME ":tt"
extern int _osgbpb(int op, int fh, void *base, int len, int extra);
extern int _ttywrite(unsigned char *buf, unsigned int len, int flag);
extern int _ttywrite(const unsigned char *buf, unsigned int len, int flag);
extern int _ttyread(unsigned char *buff, int size, int flag);
extern double _ldfp(void *x);
extern void _stfp(double d, void *p);
......@@ -151,26 +158,64 @@ extern struct _svcwto _io_emsg; /* beware only 64 bytes thereof */
extern FILEHANDLE _sys_open(const char *name, int openmode);
/* openmode is a bitmap, whose bits have the following significance ... */
/* most correspond directly to the ANSI mode specification - the */
/* exception is OPEN_T, an extension which requests timestamp update. */
/* This is really a sop to implementation laziness: what is intended is */
/* that the timestamp should be updated if the file is written to or */
/* otherwise modified. But that is known only when the file is closed */
/* and RISC OS has no 'set timestamp given filehandle' operation and the */
/* name by which the file was opened may no longer be valid at the time */
/* of its close. */
#define OPEN_R 0
#define OPEN_W 4
#define OPEN_A 8
#define OPEN_B 1
#define OPEN_PLUS 2
#define OPEN_T 16
extern int _sys_close(FILEHANDLE fh);
/* result is 0 or an error indication */
extern int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode);
/* result is number of characters not written (ie non-0 denotes a */
/* failure of some sort) or a negative error indicator. */
extern int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode);
/* result is number of characters not read (ie len - result _were_ read),*/
/* or negative to indicate error or EOF. */
/* _sys_iserror(result) distinguishes between the two possibilities. */
/* (Redundantly, since on EOF it is required that (result & ~0x80000000) */
/* is the number of characters unread). */
extern int _sys_istty(FILE *);
/* Return true if the argument file is connected to a terminal. */
/* Used to: provide default unbuffered behaviour (in the absence of a */
/* setbuf call). */
/* disallow seek */
extern int _sys_seek(FILEHANDLE fh, long pos);
/* Position the file at offset pos from its beginning. */
/* Result is >= 0 if OK, negative for an error. */
extern int _sys_ensure(FILEHANDLE fh);
/* Flush any OS buffers associated with fh, ensuring that the file is */
/* up to date on disc. (Only required if HOSTOS_NEEDSENSURE; see above) */
/* Result is >= 0 if OK, negative for an error. */
extern long _sys_flen(FILEHANDLE fh);
/* Return the current length of the file fh (or a negative error */
/* indicator). Required to convert fseek(, SEEK_END) into (, SEEK_START)*/
/* as required by _sys_seek. */
#ifdef __ARM
#define TTYHANDLE 0 /* maybe it is now time to switch these ... */
#define NONHANDLE (-1) /* ... two values */
#define _sys_istty_(fh) \
((fh) == TTYHANDLE)
#define _sys_seek_(fh, pos) \
((fh) == TTYHANDLE ? 0 : _kernel_osargs(1, fh, pos))
#define _sys_flen_(fh) \
_kernel_osargs(2, fh, 0)
#define _sys_write_(fh, buf, len, mode) \
((fh) == TTYHANDLE ? _ttywrite(buf,len,mode) : _osgbpb(2,fh,buf,len,0))
#define _sys_read_(fh, buf, len, mode) \
((fh) == TTYHANDLE ? _ttyread(buf,len,mode) : _osgbpb(4,fh,buf,len,0))
#define _sys_ensure_(fh) \
((fh) == TTYHANDLE ? 0 : _kernel_osargs(0xFF, fh, 0))
#define _sys_close_(fh) \
((fh) == TTYHANDLE ? 0 : _kernel_osfind(0, (char *)fh))
#define NONHANDLE (-1)
extern void _sys_tmpnam_(char *name, int sig);
/* Return the name for temporary file number sig in the buffer name. */
extern char *_hostos_error_string(int no, char *buf);
#endif
......
......@@ -491,8 +491,6 @@ CopyHandler
STR r6, [r4]
MOVS pc, r14
XOS_ReadVarVal EQU &20023
XOS_ReadDynamicArea EQU &2005c
|Sys$RCLimit|
DCB "Sys$RCLimit", 0
ALIGN
......@@ -1880,9 +1878,6 @@ duh_corrupt
ORR a1, a1, #&EF000000 ; SWI + Always
ORREQ a1, a1, #X
STMFD sp!, {a1, a4}
[ StrongARMfudge
SyncStackCode 2
]
LDMIA a2, {r0 - r9}
MOV pc, sp
AfterSWI
......@@ -1921,9 +1916,6 @@ swi_ret_inst
ORR a1, a1, #&ef000000
ORREQ a1, a1, #X
STMDB sp!, {a1, a4}
[ StrongARMfudge
SyncStackCode 2
]
LDMIA a2, {r0-r9}
MOV ip, pc
MOV pc, sp
......@@ -3082,8 +3074,6 @@ MessageTrans_Lookup EQU &41502
MessageTrans_CloseFile EQU &41504
MessageTrans_ErrorLookup EQU &41506
OS_Module EQU &1e
n_module_claim EQU 6
n_module_lookupname EQU 18
......
......@@ -238,10 +238,6 @@ swix0
ADD r6, r6, #&ea000000
STMDB sp!, {r0,r2,r3,r5,r6}
ADD r12, sp, #(5+8)*4 ; Point R12 at input regs on stack.
[ StrongARMfudge
; so that dynamic version would at least work
SyncStackCode 5
]
MOV pc, sp ; Call routine on stack
SWIReturn
......
......@@ -225,10 +225,6 @@ swix0
ADD r6, r6, #&ea000000
STMDB sp!, {r0,r2,r3,r5,r6}
ADD r12, sp, #(5+8)*4 ; Point R12 at input regs on stack.
[ StrongARMfudge
; so that dynamic version would at least work
SyncStackCode 5
]
MOV pc, sp ; Call routine on stack
SWIReturn
......
......@@ -36,6 +36,7 @@
* cannot be opened.
* 10-Dec-91 ECN Changed to use RISC_OSLibrary$Path again.
* 23-Mar-92 ECN Reverted to old messages lookup scheme.
* 16-Jun-97 KJB Close messages file on exit, for safety's sake.
*/
#include <stdlib.h>
......@@ -57,6 +58,14 @@ typedef struct msgs_block {
static msgs_block main_msgs_block;
static msgs_block default_msgs_block;
static void __msgs_closefiles(void)
{
if (main_msgs_block.lines)
_swix(MessageTrans_CloseFile, _IN(0), &main_msgs_block.cb);
if (default_msgs_block.lines)
_swix(MessageTrans_CloseFile, _IN(0), &default_msgs_block.cb);
}
static void __msgs_readfile(char *name, msgs_block *mb)
{
char *data;
......@@ -71,10 +80,10 @@ static void __msgs_readfile(char *name, msgs_block *mb)
size = _swi(MessageTrans_FileInfo, _IN(1)|_RETURN(2), name);
data = malloc(size);
if (!data) {
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _IN(0)|_IN(1)|_IN(2), "\0\0\0\0NoMem", 0, 0), 0);
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _INR(0,2), "\0\0\0\0NoMem", 0, 0), 0);
exit(1);
}
err = _swix(MessageTrans_OpenFile, _IN(0)|_IN(1)|_IN(2), &mb->cb, name, data);
err = _swix(MessageTrans_OpenFile, _INR(0,2), &mb->cb, name, data);
if (err) {
wimpt_reporterror(err, 0);
exit(1);
......@@ -90,7 +99,8 @@ static void __msgs_readfile(char *name, msgs_block *mb)
} while (p < e);
lines = malloc(n * 4);
if (!lines) {
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _IN(0)|_IN(1)|_IN(2), "\0\0\0\0NoMem", 0, 0), 0);
_swix(MessageTrans_CloseFile, _IN(0), &mb->cb);
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _INR(0,2), "\0\0\0\0NoMem", 0, 0), 0);
exit(1);
}
p = data + 4;
......@@ -188,4 +198,5 @@ void msgs_init(void)
res_findname("Messages", name);
__msgs_readfile(name, &main_msgs_block);
atexit(__msgs_closefiles);
}
......@@ -13,6 +13,6 @@
; limitations under the License.
;
GBLL UROM
UROM SETL {TRUE}
UROM SETL {FALSE}
END
......@@ -172,10 +172,6 @@ pc RN 15
GBLL StaticSWIVeneer
StaticSWIVeneer SETL StrongARM :LAND: {TRUE}
;fudge needed for StrongARM when dynamic code used
GBLL StrongARMfudge
StrongARMfudge SETL StrongARM :LAND: {TRUE}
[ :LNOT:UROM
EXPORT |bbc_get|
]
......@@ -260,9 +256,6 @@ os_swi_noregset
MOVS ip, a2
MOVEQ v2, #0
STMDB sp!, {a1, v2,v3} ; copy SWI and exit code onto stack
[ StrongARMfudge
SyncStackCode 3
]
LDMNEIA a2, {r0-r9} ; load up registers for SWI if wanted
MOV pc, sp ; and jump to the sequence
; SWI whatever ; <- sp
......@@ -303,9 +296,6 @@ os_swix_noregset
MOVS ip, a2
MOVEQ v2, #0
STMDB sp!, {a1, v2,v3,v4,v5} ; copy SWI and exit code onto stack
[ StrongARMfudge
SyncStackCode 5
]
LDMNEIA ip, {r0-r9} ; load up registers for SWI if wanted
MOV pc, sp ; and jump to the sequence
; SWI Xwhatever ; <- sp
......@@ -352,9 +342,6 @@ os_swi6
ADR ip, swi6_exit_sequence
LDMIA ip, {ip, lk}
STMDB sp!, {a1, ip, lk}
[ StrongARMfudge
SyncStackCode 3
]
MOV a1, a2
MOV a2, a3
MOV a3, a4
......@@ -387,9 +374,6 @@ os_swi1r
ORR a1, a1, #&ef000000
LDR a2, swi_ret_inst
STMDB sp!, {a1, a2, a3, v1-v6, lk}
[ StrongARMfudge
SyncStackCode 2
]
MOV a1, a2
MOV ip, pc
MOV pc, sp
......@@ -424,9 +408,6 @@ os_swi2r
ORR a1, a1, #&ef000000
LDR a2, swi_ret_inst
STMDB sp!, {a1, a2, a4, v1-v6, lk}
[ StrongARMfudge
SyncStackCode 2
]
MOV a1, ip
MOV a2, a3
MOV ip, pc
......@@ -468,9 +449,6 @@ os_swi3r
ORR a1, a1, #&ef000000
LDR a2, swi_ret_inst
STMDB sp!, {a1, a2, v1-v6, lk}
[ StrongARMfudge
SyncStackCode 2
]
MOV a1, ip
MOV a2, a3
MOV a3, a4
......@@ -518,9 +496,6 @@ os_swi4r
ORR a1, a1, #&ef000000
LDR a2, swi_ret_inst
STMDB sp!, {a1, a2, v1-v6, lk}
[ StrongARMfudge
SyncStackCode 2
]
MOV a1, ip
MOV a2, a3
MOV a3, a4
......@@ -574,9 +549,6 @@ os_swi5r
ORR a1, a1, #&ef000000
LDR a2, swi_ret_inst
STMDB sp!, {a1, a2, v1-v6, lk}
[ StrongARMfudge
SyncStackCode 2
]
MOV a1, ip
MOV a2, a3
MOV a3, a4
......@@ -635,9 +607,6 @@ os_swi6r
ORR a1, a1, #&ef000000
LDR a2, swi_ret_inst
STMDB sp!, {a1, a2, v1-v6, lk}
[ StrongARMfudge
SyncStackCode 2
]
MOV a1, ip
MOV a2, a3
MOV a3, a4
......
......@@ -15,19 +15,17 @@
GET Hdr:ListOpts
GET Hdr:Machine.<Machine>
GET Hdr:CPU.Generic26
GET Hdr:Macros
GET Hdr:SWIs
GET Hdr:RISCOS
GBLL StrongARM
GBLL StrongARMfudge
GBLL SASTMhatbroken
StrongARM SETL :LNOT:STB
StrongARMfudge SETL StrongARM
StrongARM SETL :DEF: AMBKernel
SASTMhatbroken SETL {TRUE} :LAND: StrongARM
XOS_SynchroniseCodeAreas * &2006e
XOS_CallASWIR12 * &20071
XOS_PlatformFeatures * &2006d
[ StrongARM
;macro to synchronise to $Ncodewords words of code on (FD) stack
MACRO
......
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