Commit 1fa7dd3c authored by Kevin Bracey's avatar Kevin Bracey
Browse files

Added <bitstring.h>, a funky bitfield manipulation set of macros.

Added ffs() and sleep() to unixlib.
Added ALIGN() to <machine/param.h> - this allows CMSG_NXTHDR() to work.

Version 5.26. Tagged as 'TCPIPLibs-5_26'
parent e311a79f
Acorn TCP/IP libraries version 5.25
Acorn TCP/IP libraries version 5.26
-----------------------------------
These libraries are an update to the libraries described in chapter 123 of the PRM
......@@ -754,6 +754,90 @@ BIND
====
New prototype: int bind(int s, const struct sockaddr *name, int namelen);
BITSTRING
=========
Name
----
bit_alloc, bit_clear, bit_decl, bit_ffs, bit_nclear, bit_nset, bit_set,
bitstr_size, bit_test - bit-string manipulation macros
Synopsis
--------
#include <bitstring.h>
bitstr_t *bit_alloc(int nbits)
void bit_decl(bitstr_t *name, int nbits)
void bit_clear(bitstr_t *name, int bit)
void bit_ffc(bitstr_t *name, int nbits, int *value)
void bit_ffs(bitstr_t *name, int nbits, int *value)
void bit_nclear(bitstr_t *name, int start, int stop)
void bit_nset(bitstr_t *name, int start, int stop)
void bit_set(bitstr_t *name, int bit)
int bitstr_size(int nbits)
int bit_test(bitstr_t *name, int bit)
DESCRIPTION
These macros operate on strings of bits.
The macro bit_alloc() returns a pointer of type ``bitstr_t *'' to sufficient
space to store nbits bits, or NULL if no space is available.
The macro bit_decl() allocates sufficient space to store nbits bits on the
stack.
The macro bitstr_size() returns the number of elements of type bitstr_t
necessary to store nbits bits. This is useful for copying bit strings.
The macros bit_clear() and bit_set() clear or set the zero-based numbered bit
bit, in the bit string name.
The bit_nset() and bit_nclear() macros set or clear the zero-based numbered
bits from start to stop in the bit string name.
The bit_test() macro evaluates to non-zero if the zero-based numbered bit
of bit string name is set, and zero otherwise.
The bit_ffs() macro stores in the location referenced by value the zero-
based number of the first bit set in the array of nbits bits referenced by
name. If no bits are set, the location referenced by value is set to -1.
The macro bit_ffc() stores in the location referenced by value the zero-
based number of the first bit not set in the array of nbits bits referenced
by name. If all bits are set, the location referenced by value is set to -1.
The arguments to these macros are evaluated only once and may safely have
side effects.
Example
-------
#include <limits.h>
#include <bitstring.h>
#define LPR_BUSY_BIT 0
#define LPR_FORMAT_BIT 1
#define LPR_DOWNLOAD_BIT 2
#define LPR_AVAILABLE_BIT 9
#define LPR_MAX_BITS 10
make_lpr_available()
{
bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
...
bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
...
if (!bit_test(bitlist, LPR_BUSY_BIT)) {
bit_clear(bitlist, LPR_FORMAT_BIT);
bit_clear(bitlist, LPR_DOWNLOAD_BIT);
bit_set(bitlist, LPR_AVAILABLE_BIT);
}
}
See also
--------
malloc
BSTRING
=======
New prototypes: int bcmp(const void *s1, const void *s2, unsigned int length);
......@@ -882,6 +966,33 @@ in <errno.h>, stored in the shared C library stubs. (errno is #defined to __errn
<errno.h>). This prevents potential problems where source files that included
<errno.h> used to "see" the wrong errno variable.
FFS
===
Name
----
ffs - find first bit set in a bit string
Synopsis
--------
int ffs(int value)
Description
-----------
The ffs() function finds the first bit set in value and returns the index of
that bit. Bits are numbered starting from 1, starting at the right- most
bit. A return value of 0 means that the argument was zero.
See also
--------
bitstring
Exported by
-----------
Unixlib
FSTAT
=====
......@@ -1452,6 +1563,35 @@ New prototypes: int send(int s, const void *msg, size_t len, int flags);
int sendto(int s, const void *msg, size_t len, int flags,
const struct sockaddr *to, int tolen);
SLEEP
=====
Name
----
sleep - suspend process execution for an interval measured in seconds
Synopsis
--------
unsigned int sleep(unsigned int seconds);
Description
-----------
The sleep() function suspends execution of the calling process until either
seconds seconds have elapsed or an escape condition occurs. System activity
may lengthen the sleep by an indeterminate amount.
Return values
-------------
If the sleep() function returns because the requested time has elapsed,
the value returned will be zero. If the sleep() function returns due to
an escape condition, the value returned will be the unslept amount
(the requested time minus the time actually slept) in seconds.
Exported by
-----------
Unixlib
SOCKETIOCTL
===========
New prototype: int socketioctl(int s, unsigned long cmd, ...);
......
/* (5.25)
/* (5.26)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 5.25
#define Module_MajorVersion_CMHG 5.26
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 13 Jul 1999
#define Module_Date_CMHG 15 Jul 1999
#define Module_MajorVersion "5.25"
#define Module_Version 525
#define Module_MajorVersion "5.26"
#define Module_Version 526
#define Module_MinorVersion ""
#define Module_Date "13 Jul 1999"
#define Module_Date "15 Jul 1999"
#define Module_FullVersion "5.25"
#define Module_FullVersion "5.26"
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Vixie.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)bitstring.h 8.1 (Berkeley) 7/19/93
*/
#ifndef _BITSTRING_H_
#define _BITSTRING_H_
typedef unsigned char bitstr_t;
/* internal macros */
/* byte of the bitstring bit is in */
#define _bit_byte(bit) \
((bit) >> 3)
/* mask for the bit within its byte */
#define _bit_mask(bit) \
(1 << ((bit)&0x7))
/* external macros */
/* bytes in a bitstring of nbits bits */
#define bitstr_size(nbits) \
((((nbits) - 1) >> 3) + 1)
/* allocate a bitstring */
#define bit_alloc(nbits) \
(bitstr_t *)calloc(1, \
(unsigned int)bitstr_size(nbits) * sizeof(bitstr_t))
/* allocate a bitstring on the stack */
#define bit_decl(name, nbits) \
(name)[bitstr_size(nbits)]
/* is bit N of bitstring name set? */
#define bit_test(name, bit) \
((name)[_bit_byte(bit)] & _bit_mask(bit))
/* set bit N of bitstring name */
#define bit_set(name, bit) \
(name)[_bit_byte(bit)] |= _bit_mask(bit)
/* clear bit N of bitstring name */
#define bit_clear(name, bit) \
(name)[_bit_byte(bit)] &= ~_bit_mask(bit)
/* clear bits start ... stop in bitstring */
#define bit_nclear(name, start, stop) { \
register bitstr_t *_name = name; \
register int _start = start, _stop = stop; \
register int _startbyte = _bit_byte(_start); \
register int _stopbyte = _bit_byte(_stop); \
if (_startbyte == _stopbyte) { \
_name[_startbyte] &= ((0xff >> (8 - (_start&0x7))) | \
(0xff << ((_stop&0x7) + 1))); \
} else { \
_name[_startbyte] &= 0xff >> (8 - (_start&0x7)); \
while (++_startbyte < _stopbyte) \
_name[_startbyte] = 0; \
_name[_stopbyte] &= 0xff << ((_stop&0x7) + 1); \
} \
}
/* set bits start ... stop in bitstring */
#define bit_nset(name, start, stop) { \
register bitstr_t *_name = name; \
register int _start = start, _stop = stop; \
register int _startbyte = _bit_byte(_start); \
register int _stopbyte = _bit_byte(_stop); \
if (_startbyte == _stopbyte) { \
_name[_startbyte] |= ((0xff << (_start&0x7)) & \
(0xff >> (7 - (_stop&0x7)))); \
} else { \
_name[_startbyte] |= 0xff << ((_start)&0x7); \
while (++_startbyte < _stopbyte) \
_name[_startbyte] = 0xff; \
_name[_stopbyte] |= 0xff >> (7 - (_stop&0x7)); \
} \
}
/* find first bit clear in name */
#define bit_ffc(name, nbits, value) { \
register bitstr_t *_name = name; \
register int _byte, _nbits = nbits; \
register int _stopbyte = _bit_byte(_nbits), _value = -1; \
for (_byte = 0; _byte <= _stopbyte; ++_byte) \
if (_name[_byte] != 0xff) { \
_value = _byte << 3; \
for (_stopbyte = _name[_byte]; (_stopbyte&0x1); \
++_value, _stopbyte >>= 1); \
break; \
} \
*(value) = _value; \
}
/* find first bit set in name */
#define bit_ffs(name, nbits, value) { \
register bitstr_t *_name = name; \
register int _byte, _nbits = nbits; \
register int _stopbyte = _bit_byte(_nbits), _value = -1; \
for (_byte = 0; _byte <= _stopbyte; ++_byte) \
if (_name[_byte]) { \
_value = _byte << 3; \
for (_stopbyte = _name[_byte]; !(_stopbyte&0x1); \
++_value, _stopbyte >>= 1); \
break; \
} \
*(value) = _value; \
}
#endif /* !_BITSTRING_H_ */
......@@ -12,9 +12,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _MACHINE_PARAM_H_
#define _MACHINE_PARAM_H_
/*
* Machine dependent constants for ARM.
*/
#define ALIGNBYTES (sizeof(long) - 1)
#define ALIGN(p) (((unsigned long)(p) + ALIGNBYTES) & ~ALIGNBYTES)
#define KTLBASE 512 /* kernel text logical page base */
#define PMLBASE 1024 /* physical memory logical page base */
#define NBPG 32768 /* bytes/page */
......@@ -30,3 +36,5 @@
#define MAXPHYS ((256+2)*1024*1024)
#define PAGE_SIZE 4096
#endif /* !_MACHINE_PARAM_H_ */
......@@ -55,7 +55,7 @@ CFILES= access.c chdir.c chmod.c close.c filestat.c flushinput.c \
memops.c osreadc.c read.c readdir.c readv.c strcasecmp.c \
stubs.c write.c writev.c xgets.c xperror.c xputchar.c \
getopt.c strsep.c kvm.c err.c errlst.c xstrerror.c \
strdup.c
strdup.c sleep.c ffs.c
OFILES= access.o chdir.o chmod.o close.o filestat.o flushinput.o \
fstat.o getdtabsiz.o getegid.o geteuid.o getgroups.o \
......@@ -65,7 +65,7 @@ OFILES= access.o chdir.o chmod.o close.o filestat.o flushinput.o \
memops.o osreadc.o read.o readdir.o readv.o strcasecmp.o \
stubs.o write.o writev.o xgets.o xperror.o xputchar.o \
getopt.o strsep.o kvm.o err.o errlst.o xstrerror.o \
strdup.o
strdup.o sleep.o ffs.o
ZFILES= z.access z.chdir z.chmod z.close z.filestat z.flushinput \
z.fstat z.getdtabsiz z.getegid z.geteuid z.getgroups \
......@@ -75,7 +75,7 @@ ZFILES= z.access z.chdir z.chmod z.close z.filestat z.flushinput \
z.memops z.osreadc z.read z.readdir z.readv z.strcasecmp \
z.stubs z.write z.writev z.xgets z.xperror z.xputchar \
z.getopt z.strsep z.kvm z.err z.errlst z.xstrerror \
z.strdup
z.strdup z.sleep z.ffs
.SUFFIXES: .z .o .c .s
......
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)ffs.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#ifdef __riscos
#include "unixlib.h"
#else
#include <string.h>
#endif
/*
* ffs -- vax ffs instruction
*/
int
ffs(mask)
register int mask;
{
register int bit;
if (mask == 0)
return(0);
for (bit = 1; !(mask & 1); bit++)
mask >>= 1;
return(bit);
}
/* 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.
*/
#include <swis.h>
#include <unixlib.h>
unsigned int sleep(unsigned int n)
{
unsigned int t1, t, dt;
_swix(OS_ReadMonotonicTime, _OUT(0), &t1);
t = t1;
dt = t1 + n * 100;
do
{
int escape;
int wait = dt - t;
if (wait >= 0x8000) wait = 0x7FFF;
_swix(OS_Byte, _INR(0,2)|_OUT(2), 129, wait & 0xFF, wait >> 8, &escape);
_swix(OS_ReadMonotonicTime, _OUT(0), &t);
if (escape == 0x1B)
break;
} while (t - t1 < n * 100);
return (signed)(dt - t) <= 0 ? 0 : (dt - t) / 100;
}
......@@ -74,6 +74,7 @@ extern void err_set_exit(void (*ef)(int));
extern void err_set_file(void *fp);
extern void err_set_silent(int silent);
extern int ffs(int value);
extern int filestat(char *fname, char *type);
extern void flushinput(void);
extern int fstat(int s, struct stat *buf);
......@@ -120,6 +121,7 @@ extern int readv(int s, const struct iovec *iov, int iovcnt);
extern char *rindex(const char *s, int c);
extern int setpwent(void);
extern unsigned int sleep(unsigned int seconds);
extern int strcasecmp(const char *a, const char *b);
extern char *strdup(const char *s);
extern int strncasecmp(const char *a, const char *b, size_t n);
......
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