diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..d31d286 --- /dev/null +++ b/.cvsignore @@ -0,0 +1,7 @@ +ne2k-rx.log +ne2k-rxdump.txt +ne2k-tx.log +ne2k-txdump.txt +ne2k.raw +ne2k.txt +snapshot.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..07e78a8 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +all: kernel libc ubix objgfx40 libcpp libstdc++ views bin tools +# depend kernel tools + +libc: src + (cd src/lib/libc;make) + +objgfx40: src + (cd src/lib/objgfx40;make) + +views: src + (cd src/lib/views/sunlight;make) + +ubix: src + (cd src/lib/ubix;make) + +libcpp: src + (cd src/lib/libcpp;make) + +depend: src + (cd src/lib/ubix;make) + +bin: src + (cd src/bin;make) + +libstdc++: src + (cd src/lib/libstdc++;make) + +kernel: src + (cd src/sys;make) + +tools: src + (cd src/tools;make) + +install: + (cd src/sys;make install) + +clean: + (cd src/sys;make clean) + (cd src/lib/libc;make clean) + (cd src/bin;make clean) + (cd src/lib/ubix;make clean) + (cd src/lib/objgfx40;make clean) + (cd src/lib/libcpp;make clean) + (cd src/lib/views/sunlight;make clean) + (cd src/lib/libstdc++;make clean) diff --git a/README b/README new file mode 100644 index 0000000..a5653e9 --- /dev/null +++ b/README @@ -0,0 +1,9 @@ +Installation: + + make all install <- This will build the kernel and components and put them onto a floppy + To make a bootable floppy do the following: + 1) cd src/sys/boot/btx;make + 2) cd ../boot2;make + 3) cat boot1 boot2 > /dev/fd0 + 4) gcc -o test test.c;./test /dev/fd0 1;rm ./test + diff --git a/doc/doxygen/html/8259_8h-source.html b/doc/doxygen/html/8259_8h-source.html new file mode 100644 index 0000000..c7a38de --- /dev/null +++ b/doc/doxygen/html/8259_8h-source.html @@ -0,0 +1,58 @@ + + +Ubixos: 8259.h Source File + + + +

8259.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _8259_H
+00025 #define _8259_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #define mPic    0x20 // I/O for master PIC      
+00030 #define mImr    0x21 // I/O for master IMR      
+00031 #define sPic    0xA0 // I/O for slave PIC       
+00032 #define sImr    0xA1 // I/O for slace IMR       
+00033 #define eoi     0x20 // EOI command             
+00034 #define icw1    0x11 // Cascade, Edge triggered 
+00035 #define icw4    0x01 // 8088 mode               
+00036 #define mVec    0x68 // Vector for master       
+00037 #define sVec    0x70 // Vector for slave        
+00038 #define ocw3Irr 0x0A // Read IRR                
+00039 #define ocw3Isr 0x0B // Read ISR                
+00040 
+00041 int init8259();
+00042 void irqEnable(uInt16 irqNo);
+00043 void irqDisable(uInt16 irqNo);
+00044 
+00045 #endif
+00046 
+

Generated on Wed Apr 28 17:49:28 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/8259_8h.html b/doc/doxygen/html/8259_8h.html new file mode 100644 index 0000000..7bf76e3 --- /dev/null +++ b/doc/doxygen/html/8259_8h.html @@ -0,0 +1,378 @@ + + +Ubixos: 8259.h File Reference + + + +

8259.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define mPic   0x20
#define mImr   0x21
#define sPic   0xA0
#define sImr   0xA1
#define eoi   0x20
#define icw1   0x11
#define icw4   0x01
#define mVec   0x68
#define sVec   0x70
#define ocw3Irr   0x0A
#define ocw3Isr   0x0B

Functions

int init8259 ()
void irqEnable (uInt16 irqNo)
void irqDisable (uInt16 irqNo)
+


Define Documentation

+

+ + + + +
+ + +
#define eoi   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define icw1   0x11 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define icw4   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define mImr   0x21 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define mPic   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define mVec   0x68 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ocw3Irr   0x0A +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ocw3Isr   0x0B +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define sImr   0xA1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define sPic   0xA0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define sVec   0x70 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
int init8259  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void irqDisable uInt16  irqNo  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void irqEnable uInt16  irqNo  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/__types_8h-source.html b/doc/doxygen/html/__types_8h-source.html new file mode 100644 index 0000000..3445756 --- /dev/null +++ b/doc/doxygen/html/__types_8h-source.html @@ -0,0 +1,45 @@ + + +Ubixos: _types.h Source File + + + +

_types.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef __TYPES_H
+00025 #define __TYPES_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 typedef      unsigned long   __clock_t;
+00030 typedef      long            __time_t;
+00031 
+00032 #endif
+00033 
+

Generated on Wed Apr 28 17:49:29 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/__types_8h.html b/doc/doxygen/html/__types_8h.html new file mode 100644 index 0000000..3668178 --- /dev/null +++ b/doc/doxygen/html/__types_8h.html @@ -0,0 +1,68 @@ + + +Ubixos: _types.h File Reference + + + +

_types.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + +

Typedefs

typedef unsigned long __clock_t
typedef long __time_t
+


Typedef Documentation

+

+ + + + +
+ + +
typedef unsigned long __clock_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef long __time_t +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/annotated.html b/doc/doxygen/html/annotated.html new file mode 100644 index 0000000..53e0fae --- /dev/null +++ b/doc/doxygen/html/annotated.html @@ -0,0 +1,107 @@ + + +Ubixos: Annotated Index + + + +

Ubixos Data Structures

Here are the data structures with brief descriptions: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
api_msg
api_msg_msg
arpcom
blockAllocationTableEntry
bootSectBootsector structure
confadd
cpuinfo_t
descriptorTableUnion
devFsDevices
devFsInfo
device
deviceNode
devMethodType
directoryEntryUbixFS Directory Entry
dp_rcvhdr
driveInfo
driverType
DrvGeom
ei_device
elfDynamic
elfDynsym
elfHeader
elfPltInfo
elfProgramheader
elfSectionheader
eth_addr
eth_hdr
etheraddr
fileDescriptorStruct
fileSystem
gdtDescriptor
gdtGate
hostRingEntry
i387Struct
icmp_dur_hdr
icmp_echo_hdr
icmp_te_hdr
in_addr
initBlock
ip_addr
ip_hdr
lncInfo
mds
memDescriptor
mMap
mountPoints
net
netbuf
netconn
netif
nicBuffer
nicInfo
ogDisplay_UbixOS
ogDisplay_VESA
ogModeInfo
ogVESAInfo
osInfo
partitionInformation
pbuf
pciConfig
sdeWindows
sockaddr
sockaddr_in
sys_timeout
sys_timeouts
taskFileInfo
taskStruct
tcp_hdr
tcp_pcb
tcp_pcb_listen
tcp_seg
tcpip_msg
timespec
timeStruct
timeval
timezone
TMode_Rec
tms
tssStruct
TVESA_Rec
ubixDiskLabelPartition Information
ubixDiskLabel::drivePartitions
ubixFsInfo
ubthread
ubthread_cond
ubthread_cond_list
ubthread_list
ubthread_mutex
ubthread_mutex_list
udp_hdr
udp_pcb
userFileDescriptorStruct
vitalsStruct
+
Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/api_8h-source.html b/doc/doxygen/html/api_8h-source.html new file mode 100644 index 0000000..5123433 --- /dev/null +++ b/doc/doxygen/html/api_8h-source.html @@ -0,0 +1,154 @@ + + +Ubixos: api.h Source File + + + +

api.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_API_H__
+00036 #define __LWIP_API_H__
+00037 
+00038 #include "net/opt.h"
+00039 #include "net/pbuf.h"
+00040 #include "net/sys.h"
+00041 
+00042 #include "net/ipv4/ip.h"
+00043 
+00044 #include "net/udp.h"
+00045 #include "net/tcp.h"
+00046 
+00047 #include "net/err.h"
+00048 
+00049 #define NETCONN_NOCOPY 0x00
+00050 #define NETCONN_COPY   0x01
+00051 
+00052 enum netconn_type {
+00053   NETCONN_TCP,
+00054   NETCONN_UDP,
+00055   NETCONN_UDPLITE,
+00056   NETCONN_UDPNOCHKSUM
+00057 };
+00058 
+00059 enum netconn_state {
+00060   NETCONN_NONE,
+00061   NETCONN_WRITE,
+00062   NETCONN_ACCEPT,
+00063   NETCONN_RECV,
+00064   NETCONN_CONNECT,
+00065   NETCONN_CLOSE
+00066 };
+00067 
+00068 struct netbuf {
+00069   struct pbuf *p, *ptr;
+00070   struct ip_addr *fromaddr;
+00071   uInt16 fromport;
+00072   err_t err;
+00073 };
+00074 
+00075 struct netconn {
+00076   enum netconn_type type;
+00077   enum netconn_state state;
+00078   union {
+00079     struct tcp_pcb *tcp;
+00080     struct udp_pcb *udp;
+00081   } pcb;
+00082   err_t err;
+00083   sys_mbox_t mbox;
+00084   sys_mbox_t recvmbox;
+00085   sys_mbox_t acceptmbox;
+00086   sys_sem_t sem;
+00087 };
+00088 
+00089 /* Network buffer functions: */
+00090 struct netbuf *   netbuf_new      (void);
+00091 void              netbuf_delete   (struct netbuf *buf);
+00092 void *            netbuf_alloc    (struct netbuf *buf, uInt16 size);
+00093 void              netbuf_free     (struct netbuf *buf);
+00094 void              netbuf_ref      (struct netbuf *buf,
+00095                                    void *dataptr, uInt16 size);
+00096 void              netbuf_chain    (struct netbuf *head,
+00097                                    struct netbuf *tail);
+00098 
+00099 uInt16             netbuf_len      (struct netbuf *buf);
+00100 err_t             netbuf_data     (struct netbuf *buf,
+00101                                    void **dataptr, uInt16 *len);
+00102 Int8              netbuf_next     (struct netbuf *buf);
+00103 void              netbuf_first    (struct netbuf *buf);
+00104 
+00105 void              netbuf_copy     (struct netbuf *buf,
+00106                                    void *dataptr, uInt16 len);
+00107 struct ip_addr *  netbuf_fromaddr (struct netbuf *buf);
+00108 uInt16             netbuf_fromport (struct netbuf *buf);
+00109 
+00110 /* Network connection functions: */
+00111 struct netconn *  netconn_new     (enum netconn_type type);
+00112 err_t             netconn_delete  (struct netconn *conn);
+00113 enum netconn_type netconn_type    (struct netconn *conn);
+00114 err_t             netconn_peer    (struct netconn *conn,
+00115                                    struct ip_addr **addr,
+00116                                    uInt16 *port);
+00117 err_t             netconn_addr    (struct netconn *conn,
+00118                                    struct ip_addr **addr,
+00119                                    uInt16 *port);
+00120 err_t             netconn_bind    (struct netconn *conn,
+00121                                    struct ip_addr *addr,
+00122                                    uInt16 port);
+00123 err_t             netconn_connect (struct netconn *conn,
+00124                                    struct ip_addr *addr,
+00125                                    uInt16 port);
+00126 err_t             netconn_listen  (struct netconn *conn);
+00127 struct netconn *  netconn_accept  (struct netconn *conn);
+00128 struct netbuf *   netconn_recv    (struct netconn *conn);
+00129 err_t             netconn_send    (struct netconn *conn,
+00130                                    struct netbuf *buf);
+00131 err_t             netconn_write   (struct netconn *conn,
+00132                                    void *dataptr, uInt16 size,
+00133                                    uInt8 copy);
+00134 err_t             netconn_close   (struct netconn *conn);
+00135 
+00136 err_t             netconn_err     (struct netconn *conn);
+00137 
+00138 void netbuf_copy_partial(struct netbuf *buf, void *dataptr, uInt16 len, uInt16 offset);
+00139 
+00140 #endif /* __LWIP_API_H__ */
+00141 
+00142 
+

Generated on Wed Apr 28 17:49:29 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/api_8h.html b/doc/doxygen/html/api_8h.html new file mode 100644 index 0000000..3c1f0cf --- /dev/null +++ b/doc/doxygen/html/api_8h.html @@ -0,0 +1,1214 @@ + + +Ubixos: api.h File Reference + + + +

api.h File Reference

#include "net/opt.h"
+#include "net/pbuf.h"
+#include "net/sys.h"
+#include "net/ipv4/ip.h"
+#include "net/udp.h"
+#include "net/tcp.h"
+#include "net/err.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  netbuf
struct  netconn

Defines

#define NETCONN_NOCOPY   0x00
#define NETCONN_COPY   0x01

Enumerations

enum  netconn_type { NETCONN_TCP, +NETCONN_UDP, +NETCONN_UDPLITE, +NETCONN_UDPNOCHKSUM + }
enum  netconn_state {
+  NETCONN_NONE, +NETCONN_WRITE, +NETCONN_ACCEPT, +NETCONN_RECV, +
+  NETCONN_CONNECT, +NETCONN_CLOSE +
+ }

Functions

netbufnetbuf_new (void)
void netbuf_delete (struct netbuf *buf)
void * netbuf_alloc (struct netbuf *buf, uInt16 size)
void netbuf_free (struct netbuf *buf)
void netbuf_ref (struct netbuf *buf, void *dataptr, uInt16 size)
void netbuf_chain (struct netbuf *head, struct netbuf *tail)
uInt16 netbuf_len (struct netbuf *buf)
err_t netbuf_data (struct netbuf *buf, void **dataptr, uInt16 *len)
Int8 netbuf_next (struct netbuf *buf)
void netbuf_first (struct netbuf *buf)
void netbuf_copy (struct netbuf *buf, void *dataptr, uInt16 len)
ip_addrnetbuf_fromaddr (struct netbuf *buf)
uInt16 netbuf_fromport (struct netbuf *buf)
netconnnetconn_new (enum netconn_type type)
err_t netconn_delete (struct netconn *conn)
enum netconn_type netconn_type (struct netconn *conn)
err_t netconn_peer (struct netconn *conn, struct ip_addr **addr, uInt16 *port)
err_t netconn_addr (struct netconn *conn, struct ip_addr **addr, uInt16 *port)
err_t netconn_bind (struct netconn *conn, struct ip_addr *addr, uInt16 port)
err_t netconn_connect (struct netconn *conn, struct ip_addr *addr, uInt16 port)
err_t netconn_listen (struct netconn *conn)
netconnnetconn_accept (struct netconn *conn)
netbufnetconn_recv (struct netconn *conn)
err_t netconn_send (struct netconn *conn, struct netbuf *buf)
err_t netconn_write (struct netconn *conn, void *dataptr, uInt16 size, uInt8 copy)
err_t netconn_close (struct netconn *conn)
err_t netconn_err (struct netconn *conn)
void netbuf_copy_partial (struct netbuf *buf, void *dataptr, uInt16 len, uInt16 offset)
+


Define Documentation

+

+ + + + +
+ + +
#define NETCONN_COPY   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NETCONN_NOCOPY   0x00 +
+
+ + + + + +
+   + + +

+

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum netconn_state +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + + + +
NETCONN_NONE  +
NETCONN_WRITE  +
NETCONN_ACCEPT  +
NETCONN_RECV  +
NETCONN_CONNECT  +
NETCONN_CLOSE  +
+
+
+

+ + + + +
+ + +
enum netconn_type +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + +
NETCONN_TCP  +
NETCONN_UDP  +
NETCONN_UDPLITE  +
NETCONN_UDPNOCHKSUM  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void* netbuf_alloc struct netbuf buf,
uInt16  size
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void netbuf_chain struct netbuf head,
struct netbuf tail
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void netbuf_copy struct netbuf buf,
void *  dataptr,
uInt16  len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void netbuf_copy_partial struct netbuf buf,
void *  dataptr,
uInt16  len,
uInt16  offset
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t netbuf_data struct netbuf buf,
void **  dataptr,
uInt16 len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void netbuf_delete struct netbuf buf  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void netbuf_first struct netbuf buf  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void netbuf_free struct netbuf buf  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct ip_addr* netbuf_fromaddr struct netbuf buf  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 netbuf_fromport struct netbuf buf  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 netbuf_len struct netbuf buf  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct netbuf* netbuf_new void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
Int8 netbuf_next struct netbuf buf  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void netbuf_ref struct netbuf buf,
void *  dataptr,
uInt16  size
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct netconn* netconn_accept struct netconn conn  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t netconn_addr struct netconn conn,
struct ip_addr **  addr,
uInt16 port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t netconn_bind struct netconn conn,
struct ip_addr addr,
uInt16  port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
err_t netconn_close struct netconn conn  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t netconn_connect struct netconn conn,
struct ip_addr addr,
uInt16  port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
err_t netconn_delete struct netconn conn  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
err_t netconn_err struct netconn conn  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
err_t netconn_listen struct netconn conn  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct netconn* netconn_new enum netconn_type  type  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t netconn_peer struct netconn conn,
struct ip_addr **  addr,
uInt16 port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct netbuf* netconn_recv struct netconn conn  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
err_t netconn_send struct netconn conn,
struct netbuf buf
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
enum netconn_type netconn_type struct netconn conn  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t netconn_write struct netconn conn,
void *  dataptr,
uInt16  size,
uInt8  copy
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/api__msg_8h-source.html b/doc/doxygen/html/api__msg_8h-source.html new file mode 100644 index 0000000..2fd46f3 --- /dev/null +++ b/doc/doxygen/html/api__msg_8h-source.html @@ -0,0 +1,108 @@ + + +Ubixos: api_msg.h Source File + + + +

api_msg.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_API_MSG_H__
+00036 #define __LWIP_API_MSG_H__
+00037 
+00038 #include "net/opt.h"
+00039 #include "net/pbuf.h"
+00040 #include "net/sys.h"
+00041 
+00042 #include "net/ipv4/ip.h"
+00043 
+00044 #include "net/udp.h"
+00045 #include "net/tcp.h"
+00046 
+00047 #include "net/api.h"
+00048 
+00049 enum api_msg_type {
+00050   API_MSG_NEWCONN,
+00051   API_MSG_DELCONN,
+00052   
+00053   API_MSG_BIND,
+00054   API_MSG_CONNECT,
+00055 
+00056   API_MSG_LISTEN,
+00057   API_MSG_ACCEPT,
+00058 
+00059   API_MSG_SEND,
+00060   API_MSG_RECV,
+00061   API_MSG_WRITE,
+00062 
+00063   API_MSG_CLOSE,
+00064   
+00065   API_MSG_MAX
+00066 };
+00067 
+00068 struct api_msg_msg {
+00069   struct netconn *conn;
+00070   enum netconn_type conntype;
+00071   union {
+00072     struct pbuf *p;   
+00073     struct  {
+00074       struct ip_addr *ipaddr;
+00075       uInt16 port;
+00076     } bc;
+00077     struct {
+00078       void *dataptr;
+00079       uInt16 len;
+00080       unsigned char copy;
+00081     } w;    
+00082     sys_mbox_t mbox;
+00083     uInt16 len;
+00084   } msg;
+00085 };
+00086 
+00087 struct api_msg {
+00088   enum api_msg_type type;
+00089   struct api_msg_msg msg;
+00090 };
+00091 
+00092 void api_msg_input(struct api_msg *msg);
+00093 void api_msg_post(struct api_msg *msg);
+00094 
+00095 #endif /* __LWIP_API_MSG_H__ */
+00096 
+

Generated on Wed Apr 28 17:49:30 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/api__msg_8h.html b/doc/doxygen/html/api__msg_8h.html new file mode 100644 index 0000000..f290a3f --- /dev/null +++ b/doc/doxygen/html/api__msg_8h.html @@ -0,0 +1,160 @@ + + +Ubixos: api_msg.h File Reference + + + +

api_msg.h File Reference

#include "net/opt.h"
+#include "net/pbuf.h"
+#include "net/sys.h"
+#include "net/ipv4/ip.h"
+#include "net/udp.h"
+#include "net/tcp.h"
+#include "net/api.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + +

Data Structures

struct  api_msg
struct  api_msg_msg

Enumerations

enum  api_msg_type {
+  API_MSG_NEWCONN, +API_MSG_DELCONN, +API_MSG_BIND, +API_MSG_CONNECT, +
+  API_MSG_LISTEN, +API_MSG_ACCEPT, +API_MSG_SEND, +API_MSG_RECV, +
+  API_MSG_WRITE, +API_MSG_CLOSE, +API_MSG_MAX +
+ }

Functions

void api_msg_input (struct api_msg *msg)
void api_msg_post (struct api_msg *msg)
+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum api_msg_type +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + + + + + + + + +
API_MSG_NEWCONN  +
API_MSG_DELCONN  +
API_MSG_BIND  +
API_MSG_CONNECT  +
API_MSG_LISTEN  +
API_MSG_ACCEPT  +
API_MSG_SEND  +
API_MSG_RECV  +
API_MSG_WRITE  +
API_MSG_CLOSE  +
API_MSG_MAX  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void api_msg_input struct api_msg msg  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void api_msg_post struct api_msg msg  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/arch_8h-source.html b/doc/doxygen/html/arch_8h-source.html new file mode 100644 index 0000000..d9e9635 --- /dev/null +++ b/doc/doxygen/html/arch_8h-source.html @@ -0,0 +1,73 @@ + + +Ubixos: arch.h Source File + + + +

arch.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_ARCH_H__
+00036 #define __LWIP_ARCH_H__
+00037 
+00038 #ifndef LITTLE_ENDIAN
+00039 #define LITTLE_ENDIAN 1234
+00040 #endif
+00041 
+00042 #ifndef BIG_ENDIAN
+00043 #define BIG_ENDIAN 4321
+00044 #endif
+00045 
+00046 #include "arch/cpu.h"
+00047 #include "arch/cc.h"
+00048 
+00049 #ifndef PACK_STRUCT_BEGIN
+00050 #define PACK_STRUCT_BEGIN
+00051 #endif /* PACK_STRUCT_BEGIN */
+00052 
+00053 #ifndef PACK_STRUCT_END
+00054 #define PACK_STRUCT_END
+00055 #endif /* PACK_STRUCT_END */
+00056 
+00057 #ifndef PACK_STRUCT_FIELD
+00058 #define PACK_STRUCT_FIELD(x) x
+00059 #endif /* PACK_STRUCT_FIELD */
+00060 
+00061 #endif /* __LWIP_ARCH_H__ */
+

Generated on Wed Apr 28 17:49:30 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/arch_8h.html b/doc/doxygen/html/arch_8h.html new file mode 100644 index 0000000..3efe7a4 --- /dev/null +++ b/doc/doxygen/html/arch_8h.html @@ -0,0 +1,69 @@ + + +Ubixos: arch.h File Reference + + + +

arch.h File Reference

#include "arch/cpu.h"
+#include "arch/cc.h"
+ +

+Go to the source code of this file. + + + + + + +

Defines

#define LITTLE_ENDIAN   1234
#define BIG_ENDIAN   4321
+


Define Documentation

+

+ + + + +
+ + +
#define BIG_ENDIAN   4321 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LITTLE_ENDIAN   1234 +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/arp_8h-source.html b/doc/doxygen/html/arp_8h-source.html new file mode 100644 index 0000000..520b8b1 --- /dev/null +++ b/doc/doxygen/html/arp_8h-source.html @@ -0,0 +1,107 @@ + + +Ubixos: arp.h Source File + + + +

arp.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. All advertising materials mentioning features or use of this software
+00014  *    must display the following acknowledgement:
+00015  *      This product includes software developed by the Swedish Institute
+00016  *      of Computer Science and its contributors.
+00017  * 4. Neither the name of the Institute nor the names of its contributors 
+00018  *    may be used to endorse or promote products derived from this software 
+00019  *    without specific prior written permission. 
+00020  *
+00021  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00031  * SUCH DAMAGE. 
+00032  *
+00033  * This file is part of the lwIP TCP/IP stack.
+00034  * 
+00035  * Author: Adam Dunkels <adam@sics.se>
+00036  *
+00037  * $Id$
+00038  *
+00039  */
+00040 
+00041 #ifndef __NETIF_ARP_H__
+00042 #define __NETIF_ARP_H__
+00043 
+00044 #include "net/pbuf.h"
+00045 #include "net/ipv4/ip_addr.h"
+00046 #include "net/netif.h"
+00047 
+00048 struct eth_addr {
+00049   PACK_STRUCT_FIELD(uInt8 addr[6]);
+00050 } PACK_STRUCT_STRUCT;
+00051   
+00052 struct eth_hdr {
+00053   PACK_STRUCT_FIELD(struct eth_addr dest);
+00054   PACK_STRUCT_FIELD(struct eth_addr src);
+00055   PACK_STRUCT_FIELD(uInt16 type);
+00056 } PACK_STRUCT_STRUCT;
+00057 
+00058 #define ARP_TMR_INTERVAL 10000
+00059 
+00060 #define ETHTYPE_ARP 0x0806
+00061 #define ETHTYPE_IP  0x0800
+00062 
+00063 /* Initializes ARP. */
+00064 void arp_init(void);
+00065 
+00066 /* The arp_tmr() function should be called every ARP_TMR_INTERVAL
+00067    microseconds (10 seconds). This function is responsible for
+00068    expiring old entries in the ARP table. */
+00069 void arp_tmr(void);
+00070 
+00071 /* Should be called for all incoming packets of IP kind. The function
+00072    does not alter the packet in any way, it just updates the ARP
+00073    table. After this function has been called, the normal TCP/IP stack
+00074    input function should be called. */
+00075 void arp_ip_input(struct netif *netif, struct pbuf *p);
+00076 
+00077 /* Should be called for incoming ARP packets. The pbuf in the argument
+00078    is freed by this function. If the function returns a pbuf (i.e.,
+00079    returns non-NULL), that pbuf constitutes an ARP reply and should be
+00080    sent out on the Ethernet. */
+00081 struct pbuf *arp_arp_input(struct netif *netif, struct eth_addr *ethaddr,
+00082                            struct pbuf *p);
+00083 
+00084 /* arp_loopup() is called to do an IP address -> Ethernet address
+00085    translation. If the function returns NULL, there is no mapping and
+00086    the arp_query() function should be called. */
+00087 struct eth_addr *arp_lookup(struct ip_addr *ipaddr);
+00088 
+00089 /* Constructs an ARP query packet for the given IP address. The
+00090    function returns a pbuf that contains the reply and that should be
+00091    sent out on the Ethernet. */
+00092 struct pbuf *arp_query(struct netif *netif, struct eth_addr *ethaddr,
+00093                        struct ip_addr *ipaddr);
+00094 
+00095 #endif /* __NETIF_ARP_H__ */
+

Generated on Wed Apr 28 17:49:30 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/arp_8h.html b/doc/doxygen/html/arp_8h.html new file mode 100644 index 0000000..27e1972 --- /dev/null +++ b/doc/doxygen/html/arp_8h.html @@ -0,0 +1,352 @@ + + +Ubixos: arp.h File Reference + + + +

arp.h File Reference

#include "net/pbuf.h"
+#include "net/ipv4/ip_addr.h"
+#include "net/netif.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  eth_addr
struct  eth_hdr

Defines

#define ARP_TMR_INTERVAL   10000
#define ETHTYPE_ARP   0x0806
#define ETHTYPE_IP   0x0800

Functions

void arp_init (void)
void arp_tmr (void)
void arp_ip_input (struct netif *netif, struct pbuf *p)
pbufarp_arp_input (struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
eth_addrarp_lookup (struct ip_addr *ipaddr)
pbufarp_query (struct netif *netif, struct eth_addr *ethaddr, struct ip_addr *ipaddr)

Variables

eth_addr PACK_STRUCT_STRUCT
+


Define Documentation

+

+ + + + +
+ + +
#define ARP_TMR_INTERVAL   10000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ETHTYPE_ARP   0x0806 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ETHTYPE_IP   0x0800 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
struct pbuf* arp_arp_input struct netif netif,
struct eth_addr ethaddr,
struct pbuf p
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void arp_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void arp_ip_input struct netif netif,
struct pbuf p
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct eth_addr* arp_lookup struct ip_addr ipaddr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
struct pbuf* arp_query struct netif netif,
struct eth_addr ethaddr,
struct ip_addr ipaddr
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void arp_tmr void   ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct eth_hdr PACK_STRUCT_STRUCT +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/atkbd_8h-source.html b/doc/doxygen/html/atkbd_8h-source.html new file mode 100644 index 0000000..4f40ec2 --- /dev/null +++ b/doc/doxygen/html/atkbd_8h-source.html @@ -0,0 +1,52 @@ + + +Ubixos: atkbd.h Source File + + + +

atkbd.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _KEYBOARD_H
+00025 #define _KEYBOARD_H
+00026 
+00027 #define shiftKey      1
+00028 #define controlKey    2
+00029 #define altKey        4
+00030 #define ledNumlock    2
+00031 #define ledScrolllock 1
+00032 #define ledCapslock   4
+00033 
+00034 int keyboardInit();
+00035 void keyboardISR();
+00036 void keyboardHandler();
+00037 void setLED();
+00038 
+00039 #endif
+00040 
+

Generated on Wed Apr 28 17:49:30 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/atkbd_8h.html b/doc/doxygen/html/atkbd_8h.html new file mode 100644 index 0000000..e07cbe2 --- /dev/null +++ b/doc/doxygen/html/atkbd_8h.html @@ -0,0 +1,285 @@ + + +Ubixos: atkbd.h File Reference + + + +

atkbd.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define shiftKey   1
#define controlKey   2
#define altKey   4
#define ledNumlock   2
#define ledScrolllock   1
#define ledCapslock   4

Functions

int keyboardInit ()
void keyboardISR ()
void keyboardHandler ()
void setLED ()
+


Define Documentation

+

+ + + + +
+ + +
#define altKey   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define controlKey   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ledCapslock   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ledNumlock   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ledScrolllock   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define shiftKey   1 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void keyboardHandler  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int keyboardInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void keyboardISR  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void setLED  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/bioscall_8h-source.html b/doc/doxygen/html/bioscall_8h-source.html new file mode 100644 index 0000000..bb62757 --- /dev/null +++ b/doc/doxygen/html/bioscall_8h-source.html @@ -0,0 +1,21 @@ + + +Ubixos: bioscall.h Source File + + + +

bioscall.h

00001 #include <ubixos/types.h>
+00002 
+00003 #define EFLAG_TF         0x100
+00004 #define EFLAG_IF         0x200
+00005 #define EFLAG_IOPL3      0x3000
+00006 #define EFLAG_VM         0x20000
+00007 
+00008 void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds);
+00009 void bios16Code();
+

Generated on Wed Apr 28 17:49:30 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/bioscall_8h.html b/doc/doxygen/html/bioscall_8h.html new file mode 100644 index 0000000..2e1689e --- /dev/null +++ b/doc/doxygen/html/bioscall_8h.html @@ -0,0 +1,230 @@ + + +Ubixos: bioscall.h File Reference + + + +

bioscall.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + +

Defines

#define EFLAG_TF   0x100
#define EFLAG_IF   0x200
#define EFLAG_IOPL3   0x3000
#define EFLAG_VM   0x20000

Functions

void biosCall (int biosInt, int eax, int ebx, int ecx, int edx, int esi, int edi, int es, int ds)
void bios16Code ()
+


Define Documentation

+

+ + + + +
+ + +
#define EFLAG_IF   0x200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EFLAG_IOPL3   0x3000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EFLAG_TF   0x100 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EFLAG_VM   0x20000 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void bios16Code  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void biosCall int  biosInt,
int  eax,
int  ebx,
int  ecx,
int  edx,
int  esi,
int  edi,
int  es,
int  ds
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/boot_2boot2_2lib_8h-source.html b/doc/doxygen/html/boot_2boot2_2lib_8h-source.html new file mode 100644 index 0000000..a3a2535 --- /dev/null +++ b/doc/doxygen/html/boot_2boot2_2lib_8h-source.html @@ -0,0 +1,36 @@ + + +Ubixos: lib.h Source File + + + +

lib.h

00001 /*
+00002  * Copyright (c) 1998 Robert Nordier
+00003  * All rights reserved.
+00004  *
+00005  * Redistribution and use in source and binary forms are freely
+00006  * permitted provided that the above copyright notice and this
+00007  * paragraph and the following disclaimer are duplicated in all
+00008  * such forms.
+00009  *
+00010  * This software is provided "AS IS" and without any express or
+00011  * implied warranties, including, without limitation, the implied
+00012  * warranties of merchantability and fitness for a particular
+00013  * purpose.
+00014  */
+00015 
+00016 /*
+00017  * $FreeBSD: src/sys/boot/i386/boot2/lib.h,v 1.2 1999/08/28 00:40:02 peter Exp $
+00018  */
+00019 
+00020 void sio_init(void);
+00021 void sio_flush(void);
+00022 void sio_putc(int);
+00023 int sio_getc(void);
+00024 int sio_ischar(void);
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/boot_2boot2_2ubixfs_8h-source.html b/doc/doxygen/html/boot_2boot2_2ubixfs_8h-source.html new file mode 100644 index 0000000..63883a6 --- /dev/null +++ b/doc/doxygen/html/boot_2boot2_2ubixfs_8h-source.html @@ -0,0 +1,56 @@ + + +Ubixos: ubixfs.h Source File + + + +

ubixfs.h

00001 #define DOSPTYP_UBX      0x2A   /* UbixFS partition type */
+00002 #define UBIXDISKMAGIC    ((u_int32_t)0x45) /* The disk magic number */
+00003 #define MAXUBIXPARTITIONS 16
+00004 #define UBIXFSMAGIC      ((u_int32_t)0x69) /* The File System Magic Number */
+00005 
+00006 typedef unsigned long uLong;
+00007 typedef unsigned short uShort;
+00008 
+00009 
+00010 struct ubixDiskLabel {
+00011   u_int32_t magicNum;
+00012   u_int32_t magicNum2;
+00013   u_int16_t driveType;
+00014   u_int16_t numPartitions;
+00015   struct  ubixPartitions {             /* the partition table */
+00016     u_int32_t p_size;       /* number of sectors in partition */
+00017     u_int32_t p_offset;     /* starting sector */
+00018     u_int32_t p_fsize;      /* filesystem basic fragment size */
+00019     u_int32_t p_bsize;      /* BAT size */
+00020     u_int8_t p_fstype;      /* filesystem type, see below */
+00021     u_int8_t p_frag;        /* filesystem fragments per block */
+00022         } partitions[MAXUBIXPARTITIONS];
+00023   };
+00024 
+00025 //Block Allocation Table Entry
+00026 struct blockAllocationTableEntry {
+00027   long attributes; //Block Attributes
+00028   long realSector; //Real Sector  
+00029   long nextBlock;  //Sector Of Next Block
+00030   long reserved;   //Reserved
+00031   };
+00032 
+00033 
+00034 struct directoryEntry {
+00035   uLong  startCluster;   //Starting Cluster Of File
+00036   uLong  size;           //Size Of File
+00037   uLong  creationDate;  //Date Created
+00038   uLong  lastModified;  //Date Last Modified
+00039   uLong  uid;           //UID Of Owner
+00040   uLong  gid;           //GID Of Owner
+00041   uShort attributes;    //Files Attributes
+00042   uShort permissions;   //Files Permissions
+00043   char   fileName[256]; //File Name
+00044   };
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/btxv86_8h-source.html b/doc/doxygen/html/btxv86_8h-source.html new file mode 100644 index 0000000..6771ad5 --- /dev/null +++ b/doc/doxygen/html/btxv86_8h-source.html @@ -0,0 +1,75 @@ + + +Ubixos: btxv86.h Source File + + + +

btxv86.h

00001 /*
+00002  * Copyright (c) 1998 Robert Nordier
+00003  * All rights reserved.
+00004  *
+00005  * Redistribution and use in source and binary forms are freely
+00006  * permitted provided that the above copyright notice and this
+00007  * paragraph and the following disclaimer are duplicated in all
+00008  * such forms.
+00009  *
+00010  * This software is provided "AS IS" and without any express or
+00011  * implied warranties, including, without limitation, the implied
+00012  * warranties of merchantability and fitness for a particular
+00013  * purpose.
+00014  */
+00015 
+00016 /*
+00017  * $FreeBSD: src/sys/boot/i386/btx/lib/btxv86.h,v 1.5 1999/08/28 00:40:08 peter Exp $
+00018  */
+00019 
+00020 #ifndef _BTXV86_H_
+00021 #define _BTXV86_H_
+00022 
+00023 #include <sys/types.h>
+00024 
+00025 #define V86_ADDR   0x10000      /* Segment:offset address */
+00026 #define V86_CALLF  0x20000      /* Emulate far call */
+00027 #define V86_FLAGS  0x40000      /* Return flags */
+00028 
+00029 struct __v86 {
+00030     uint32_t ctl;               /* Control flags */
+00031     uint32_t addr;              /* Interrupt number or address */
+00032     uint32_t es;                /* V86 ES register */
+00033     uint32_t ds;                /* V86 DS register */
+00034     uint32_t fs;                /* V86 FS register */
+00035     uint32_t gs;                /* V86 GS register */
+00036     uint32_t eax;               /* V86 EAX register */
+00037     uint32_t ecx;               /* V86 ECX register */
+00038     uint32_t edx;               /* V86 EDX register */
+00039     uint32_t ebx;               /* V86 EBX register */
+00040     uint32_t efl;               /* V86 eflags register */
+00041     uint32_t ebp;               /* V86 EBP register */
+00042     uint32_t esi;               /* V86 ESI register */
+00043     uint32_t edi;               /* V86 EDI register */
+00044 };
+00045 
+00046 extern struct __v86 __v86;      /* V86 interface structure */
+00047 void __v86int(void);
+00048 
+00049 #define v86     __v86
+00050 #define v86int  __v86int
+00051 
+00052 extern u_int32_t        __base;
+00053 extern u_int32_t        __args;
+00054 
+00055 #define PTOV(pa)        ((caddr_t)(pa) - __base)
+00056 #define VTOP(va)        ((vm_offset_t)(va) + __base)
+00057 #define VTOPSEG(va)     (u_int16_t)(VTOP((caddr_t)va) >> 4)
+00058 #define VTOPOFF(va)     (u_int16_t)(VTOP((caddr_t)va) & 0xf)
+00059 
+00060 void __exit(int) __attribute__((__noreturn__));
+00061 void __exec(caddr_t, ...);
+00062 
+00063 #endif /* !_BTXV86_H_ */
+

Generated on Wed Apr 28 17:49:31 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/cc_8h-source.html b/doc/doxygen/html/cc_8h-source.html new file mode 100644 index 0000000..ff81a9a --- /dev/null +++ b/doc/doxygen/html/cc_8h-source.html @@ -0,0 +1,55 @@ + + +Ubixos: cc.h Source File + + + +

cc.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __ARCH_CC_H__
+00036 #define __ARCH_CC_H__
+00037 
+00038 #define PACK_STRUCT_FIELD(x) x __attribute__((packed))
+00039 #define PACK_STRUCT_STRUCT __attribute__((packed))
+00040 #define PACK_STRUCT_BEGIN
+00041 #define PACK_STRUCT_END
+00042 
+00043 #endif /* __ARCH_CC_H__ */
+

Generated on Wed Apr 28 17:49:31 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/cc_8h.html b/doc/doxygen/html/cc_8h.html new file mode 100644 index 0000000..3a47fd5 --- /dev/null +++ b/doc/doxygen/html/cc_8h.html @@ -0,0 +1,120 @@ + + +Ubixos: cc.h File Reference + + + +

cc.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + +

Defines

#define PACK_STRUCT_FIELD(x)   x __attribute__((packed))
#define PACK_STRUCT_STRUCT   __attribute__((packed))
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
+


Define Documentation

+

+ + + + +
+ + +
#define PACK_STRUCT_BEGIN +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PACK_STRUCT_END +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define PACK_STRUCT_FIELD  )    x __attribute__((packed)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct eth_hdr PACK_STRUCT_STRUCT   __attribute__((packed)) +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/cdefs_8h-source.html b/doc/doxygen/html/cdefs_8h-source.html new file mode 100644 index 0000000..4568f6f --- /dev/null +++ b/doc/doxygen/html/cdefs_8h-source.html @@ -0,0 +1,49 @@ + + +Ubixos: cdefs.h Source File + + + +

cdefs.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _CDEFS_H
+00025 #define _CDRES_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #define __dead2         __attribute__((__noreturn__))
+00030 
+00031 
+00032 #endif
+00033 
+00034 /***
+00035  END
+00036  ***/
+00037 
+

Generated on Wed Apr 28 17:49:31 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/cdefs_8h.html b/doc/doxygen/html/cdefs_8h.html new file mode 100644 index 0000000..fdd1dda --- /dev/null +++ b/doc/doxygen/html/cdefs_8h.html @@ -0,0 +1,68 @@ + + +Ubixos: cdefs.h File Reference + + + +

cdefs.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + +

Defines

#define _CDRES_H
#define __dead2   __attribute__((__noreturn__))
+


Define Documentation

+

+ + + + +
+ + +
#define __dead2   __attribute__((__noreturn__)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define _CDRES_H +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/classog_display___ubix_o_s.html b/doc/doxygen/html/classog_display___ubix_o_s.html new file mode 100644 index 0000000..b297b69 --- /dev/null +++ b/doc/doxygen/html/classog_display___ubix_o_s.html @@ -0,0 +1,715 @@ + + +Ubixos: ogDisplay_UbixOS class Reference + + + +

ogDisplay_UbixOS Class Reference

#include <ogDisplay_UbixOS.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 ogDisplay_UbixOS (void)
virtual bool Alias (ogSurface &, uInt32, uInt32, uInt32, uInt32)
virtual bool Clone (ogSurface &)
virtual void CopyPalette (ogSurface &)
virtual bool Create (uInt32, uInt32, ogPixelFmt)
virtual bool LoadPalette (const char *)
virtual void SetPalette (const ogRGBA8[])
virtual void SetPalette (uInt8, uInt8, uInt8, uInt8)
virtual void SetPalette (uInt8, uInt8, uInt8, uInt8, uInt8)
virtual ~ogDisplay_UbixOS (void)

Protected Member Functions

uInt16 FindMode (uInt32, uInt32, uInt32)
void GetModeInfo (uInt16)
void GetVESAInfo (void)
void SetMode (uInt16)
void SetPal (void)

Protected Attributes

void * pages [2]
uInt32 activePage
uInt32 visualPage
ogVESAInfoVESAInfo
ogModeInfomodeInfo
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + + +
ogDisplay_UbixOS::ogDisplay_UbixOS void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual ogDisplay_UbixOS::~ogDisplay_UbixOS void   )  [virtual]
+
+ + + + + +
+   + + +

+

+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual bool ogDisplay_UbixOS::Alias ogSurface & ,
uInt32 ,
uInt32 ,
uInt32 ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual bool ogDisplay_UbixOS::Clone ogSurface &   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual void ogDisplay_UbixOS::CopyPalette ogSurface &   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
virtual bool ogDisplay_UbixOS::Create uInt32 ,
uInt32 ,
ogPixelFmt 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
uInt16 ogDisplay_UbixOS::FindMode uInt32 ,
uInt32 ,
uInt32 
[protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_UbixOS::GetModeInfo uInt16   )  [protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_UbixOS::GetVESAInfo void   )  [protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual bool ogDisplay_UbixOS::LoadPalette const char *   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_UbixOS::SetMode uInt16   )  [protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_UbixOS::SetPal void   )  [protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_UbixOS::SetPalette uInt8 ,
uInt8 ,
uInt8 ,
uInt8 ,
uInt8 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_UbixOS::SetPalette uInt8 ,
uInt8 ,
uInt8 ,
uInt8 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual void ogDisplay_UbixOS::SetPalette const  ogRGBA8[]  )  [virtual]
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
uInt32 ogDisplay_UbixOS::activePage [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
ogModeInfo* ogDisplay_UbixOS::modeInfo [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* ogDisplay_UbixOS::pages[2] [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
ogVESAInfo* ogDisplay_UbixOS::VESAInfo [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 ogDisplay_UbixOS::visualPage [protected] +
+
+ + + + + +
+   + + +

+

+


The documentation for this class was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/classog_display___v_e_s_a.html b/doc/doxygen/html/classog_display___v_e_s_a.html new file mode 100644 index 0000000..5d8a946 --- /dev/null +++ b/doc/doxygen/html/classog_display___v_e_s_a.html @@ -0,0 +1,1173 @@ + + +Ubixos: ogDisplay_VESA class Reference + + + +

ogDisplay_VESA Class Reference

#include <ogDisplay_VESA.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 ogDisplay_VESA (void)
virtual bool ogAvail (void)
virtual bool ogAlias (ogSurface &, uInt32, uInt32, uInt32, uInt32)
virtual void ogClear (uInt32)
virtual bool ogClone (ogSurface &)
virtual void ogCopyLineTo (uInt32, uInt32, const void *, uInt32)
virtual void ogCopyLineFrom (uInt32, uInt32, void *, uInt32)
virtual void ogCopyPal (ogSurface &)
virtual bool ogCreate (uInt32, uInt32, ogPixelFmt)
virtual uInt32 ogGetPixel (int32, int32)
virtual void * ogGetPtr (uInt32, uInt32)
virtual void ogHLine (int32, int32, int32, uInt32)
virtual bool ogLoadPal (const char *)
virtual void ogSetPixel (int32, int32, uInt32)
virtual void ogSetRGBPalette (uInt8, uInt8, uInt8, uInt8)
virtual void ogVFlip (void)
virtual void ogVLine (int32, int32, int32, uInt32)
virtual ~ogDisplay_VESA (void)

Protected Member Functions

uInt16 findMode (uInt32, uInt32, uInt32)
void getModeInfo (uInt16)
void getVESAInfo (void)
void setMode (uInt16)
virtual uInt32 rawGetPixel (uInt32, uInt32)
virtual void rawSetPixel (uInt32, uInt32, uInt32)
virtual void rawLine (uInt32, uInt32, uInt32, uInt32, uInt32)
void setPal (void)

Protected Attributes

uInt16 ScreenSelector
TVESA_RecVESARec
TMode_RecModeRec
bool InGraphics
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + + +
ogDisplay_VESA::ogDisplay_VESA void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual ogDisplay_VESA::~ogDisplay_VESA void   )  [virtual]
+
+ + + + + +
+   + + +

+

+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
uInt16 ogDisplay_VESA::findMode uInt32 ,
uInt32 ,
uInt32 
[protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_VESA::getModeInfo uInt16   )  [protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_VESA::getVESAInfo void   )  [protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual bool ogDisplay_VESA::ogAlias ogSurface & ,
uInt32 ,
uInt32 ,
uInt32 ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual bool ogDisplay_VESA::ogAvail void   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual void ogDisplay_VESA::ogClear uInt32   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual bool ogDisplay_VESA::ogClone ogSurface &   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::ogCopyLineFrom uInt32 ,
uInt32 ,
void * ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::ogCopyLineTo uInt32 ,
uInt32 ,
const void * ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual void ogDisplay_VESA::ogCopyPal ogSurface &   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
virtual bool ogDisplay_VESA::ogCreate uInt32 ,
uInt32 ,
ogPixelFmt 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
virtual uInt32 ogDisplay_VESA::ogGetPixel int32 ,
int32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
virtual void* ogDisplay_VESA::ogGetPtr uInt32 ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::ogHLine int32 ,
int32 ,
int32 ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual bool ogDisplay_VESA::ogLoadPal const char *   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::ogSetPixel int32 ,
int32 ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::ogSetRGBPalette uInt8 ,
uInt8 ,
uInt8 ,
uInt8 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
virtual void ogDisplay_VESA::ogVFlip void   )  [virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::ogVLine int32 ,
int32 ,
int32 ,
uInt32 
[virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
virtual uInt32 ogDisplay_VESA::rawGetPixel uInt32 ,
uInt32 
[protected, virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::rawLine uInt32 ,
uInt32 ,
uInt32 ,
uInt32 ,
uInt32 
[protected, virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void ogDisplay_VESA::rawSetPixel uInt32 ,
uInt32 ,
uInt32 
[protected, virtual]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_VESA::setMode uInt16   )  [protected]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ogDisplay_VESA::setPal void   )  [protected]
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
bool ogDisplay_VESA::InGraphics [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
TMode_Rec* ogDisplay_VESA::ModeRec [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 ogDisplay_VESA::ScreenSelector [protected] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
TVESA_Rec* ogDisplay_VESA::VESARec [protected] +
+
+ + + + + +
+   + + +

+

+


The documentation for this class was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/cpu_8h-source.html b/doc/doxygen/html/cpu_8h-source.html new file mode 100644 index 0000000..c169488 --- /dev/null +++ b/doc/doxygen/html/cpu_8h-source.html @@ -0,0 +1,54 @@ + + +Ubixos: cpu.h Source File + + + +

cpu.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __ARCH_CPU_H__
+00036 #define __ARCH_CPU_H__
+00037 
+00038 #ifndef BYTE_ORDER
+00039 #define BYTE_ORDER LITTLE_ENDIAN
+00040 #endif /* BYTE_ORDER */
+00041 
+00042 #endif /* __ARCH_CPU_H__ */
+

Generated on Wed Apr 28 17:49:32 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/cpu_8h.html b/doc/doxygen/html/cpu_8h.html new file mode 100644 index 0000000..9c1afc7 --- /dev/null +++ b/doc/doxygen/html/cpu_8h.html @@ -0,0 +1,43 @@ + + +Ubixos: cpu.h File Reference + + + +

cpu.h File Reference

+

+Go to the source code of this file. + + + + +

Defines

#define BYTE_ORDER   LITTLE_ENDIAN
+


Define Documentation

+

+ + + + +
+ + +
#define BYTE_ORDER   LITTLE_ENDIAN +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/debug_8h-source.html b/doc/doxygen/html/debug_8h-source.html new file mode 100644 index 0000000..42ebb27 --- /dev/null +++ b/doc/doxygen/html/debug_8h-source.html @@ -0,0 +1,151 @@ + + +Ubixos: debug.h Source File + + + +

debug.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_DEBUG_H__
+00036 #define __LWIP_DEBUG_H__
+00037 
+00038 #ifdef LWIP_DEBUG
+00039 
+00040 #define ASSERT(x,y) if(!(y)) {printf("Assertion \"%s\" failed at line %d in %s\n", \
+00041                                      x, __LINE__, __FILE__); fflush(NULL); abort();}
+00042 
+00043 /* These defines control the amount of debugging output: */
+00044 #define MEM_TRACKING
+00045 
+00046 #define DEMO_DEBUG       1
+00047 
+00048 #define ARP_DEBUG        0
+00049 
+00050 #define NETIF_DEBUG      1
+00051 #define PBUF_DEBUG       0
+00052 #define DELIF_DEBUG      0
+00053 #define DROPIF_DEBUG     0
+00054 #define TUNIF_DEBUG      0
+00055 #define UNIXIF_DEBUG     0
+00056 #define TAPIF_DEBUG      0
+00057 
+00058 #define API_LIB_DEBUG    0
+00059 #define API_MSG_DEBUG    0
+00060 #define SOCKETS_DEBUG    1
+00061 #define ICMP_DEBUG       0
+00062 #define INET_DEBUG       0
+00063 #define IP_DEBUG         0
+00064 #define IP_REASS_DEBUG   1
+00065 #define MEM_DEBUG        0
+00066 #define MEMP_DEBUG       0
+00067 #define SYS_DEBUG        0
+00068 #define TCP_DEBUG        0
+00069 #define TCP_INPUT_DEBUG  0
+00070 #define TCP_FR_DEBUG     0
+00071 #define TCP_RTO_DEBUG    0
+00072 #define TCP_REXMIT_DEBUG 0
+00073 #define TCP_CWND_DEBUG   0
+00074 #define TCP_WND_DEBUG    0
+00075 #define TCP_OUTPUT_DEBUG 0
+00076 #define TCP_RST_DEBUG    0
+00077 #define TCP_QLEN_DEBUG   0
+00078 #define UDP_DEBUG        0
+00079 #define TCPIP_DEBUG      0
+00080 #define TCPDUMP_DEBUG    0
+00081 #define DHCP_DEBUG       1
+00082 
+00083 #include <stdio.h>
+00084 #define DEBUGF(debug, x) do { if(debug){ printf x; } } while(0)
+00085 
+00086 
+00087 #else /* LWIP_DEBUG */
+00088 
+00089 /* DEBUG is not defined, so we define null macros for ASSERT and DEBUGF */
+00090 
+00091 #define ASSERT(x,y)
+00092 #define DEBUGF(debug, x)
+00093 
+00094 /* And we define those to be zero: */
+00095 
+00096 #define DEMO_DEBUG       0
+00097 #define ARP_DEBUG        0
+00098 #define NETIF_DEBUG      0
+00099 #define PBUF_DEBUG       0
+00100 #define DELIF_DEBUG      0
+00101 #define DROPIF_DEBUG     0
+00102 #define TUNIF_DEBUG      0
+00103 #define UNIXIF_DEBUG     0
+00104 #define TAPIF_DEBUG      0
+00105 #define API_LIB_DEBUG    0
+00106 #define API_MSG_DEBUG    0
+00107 #define SOCKETS_DEBUG    0
+00108 #define ICMP_DEBUG       0
+00109 #define INET_DEBUG       0
+00110 #define IP_DEBUG         0
+00111 #define IP_REASS_DEBUG   0
+00112 #define MEM_DEBUG        0
+00113 #define MEMP_DEBUG       0
+00114 #define SYS_DEBUG        0
+00115 #define TCP_DEBUG        0
+00116 #define TCP_INPUT_DEBUG  0
+00117 #define TCP_FR_DEBUG     0
+00118 #define TCP_RTO_DEBUG    0
+00119 #define TCP_REXMIT_DEBUG 0
+00120 #define TCP_CWND_DEBUG   0
+00121 #define TCP_WND_DEBUG    0
+00122 #define TCP_OUTPUT_DEBUG 0
+00123 #define TCP_RST_DEBUG    0
+00124 #define TCP_QLEN_DEBUG   0
+00125 #define UDP_DEBUG        0
+00126 #define TCPIP_DEBUG      0
+00127 #define TCPDUMP_DEBUG    0
+00128 #define DHCP_DEBUG       0
+00129 
+00130 #endif /* LWIP_DEBUG */
+00131 
+00132 
+00133 #endif /* __LWIP_DEBUG_H__ */
+00134 
+00135 
+00136 
+00137 
+00138 
+00139 
+

Generated on Wed Apr 28 17:49:32 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/debug_8h.html b/doc/doxygen/html/debug_8h.html new file mode 100644 index 0000000..69765e3 --- /dev/null +++ b/doc/doxygen/html/debug_8h.html @@ -0,0 +1,875 @@ + + +Ubixos: debug.h File Reference + + + +

debug.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define ASSERT(x, y)
#define DEBUGF(debug, x)
#define DEMO_DEBUG   0
#define ARP_DEBUG   0
#define NETIF_DEBUG   0
#define PBUF_DEBUG   0
#define DELIF_DEBUG   0
#define DROPIF_DEBUG   0
#define TUNIF_DEBUG   0
#define UNIXIF_DEBUG   0
#define TAPIF_DEBUG   0
#define API_LIB_DEBUG   0
#define API_MSG_DEBUG   0
#define SOCKETS_DEBUG   0
#define ICMP_DEBUG   0
#define INET_DEBUG   0
#define IP_DEBUG   0
#define IP_REASS_DEBUG   0
#define MEM_DEBUG   0
#define MEMP_DEBUG   0
#define SYS_DEBUG   0
#define TCP_DEBUG   0
#define TCP_INPUT_DEBUG   0
#define TCP_FR_DEBUG   0
#define TCP_RTO_DEBUG   0
#define TCP_REXMIT_DEBUG   0
#define TCP_CWND_DEBUG   0
#define TCP_WND_DEBUG   0
#define TCP_OUTPUT_DEBUG   0
#define TCP_RST_DEBUG   0
#define TCP_QLEN_DEBUG   0
#define UDP_DEBUG   0
#define TCPIP_DEBUG   0
#define TCPDUMP_DEBUG   0
#define DHCP_DEBUG   0
+


Define Documentation

+

+ + + + +
+ + +
#define API_LIB_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define API_MSG_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ARP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define ASSERTx,
 )  +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define DEBUGFdebug,
 )  +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DELIF_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DEMO_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DHCP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DROPIF_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define INET_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_REASS_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEM_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NETIF_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define SOCKETS_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define SYS_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TAPIF_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_CWND_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_FR_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_INPUT_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_OUTPUT_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_QLEN_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_REXMIT_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_RST_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_RTO_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_WND_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCPDUMP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCPIP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TUNIF_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UDP_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UNIXIF_DEBUG   0 +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/def_8h-source.html b/doc/doxygen/html/def_8h-source.html new file mode 100644 index 0000000..178a10b --- /dev/null +++ b/doc/doxygen/html/def_8h-source.html @@ -0,0 +1,59 @@ + + +Ubixos: def.h Source File + + + +

def.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_DEF_H__
+00036 #define __LWIP_DEF_H__
+00037 
+00038 #define UMAX(a, b)      ((a) > (b) ? (a) : (b))
+00039 
+00040 #ifndef NULL
+00041 #define NULL ((void *)0)
+00042 #endif
+00043 
+00044 #include "arch/lib.h"
+00045 
+00046 #endif /* __LWIP_DEF_H__ */
+00047 
+

Generated on Wed Apr 28 17:49:32 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/def_8h.html b/doc/doxygen/html/def_8h.html new file mode 100644 index 0000000..b4dad4a --- /dev/null +++ b/doc/doxygen/html/def_8h.html @@ -0,0 +1,76 @@ + + +Ubixos: def.h File Reference + + + +

def.h File Reference

#include "arch/lib.h"
+ +

+Go to the source code of this file. + + + + + + +

Defines

#define UMAX(a, b)   ((a) > (b) ? (a) : (b))
#define NULL   ((void *)0)
+


Define Documentation

+

+ + + + +
+ + +
#define NULL   ((void *)0) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define UMAXa,
 )    ((a) > (b) ? (a) : (b)) +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/devfs_8h-source.html b/doc/doxygen/html/devfs_8h-source.html new file mode 100644 index 0000000..2f3b740 --- /dev/null +++ b/doc/doxygen/html/devfs_8h-source.html @@ -0,0 +1,62 @@ + + +Ubixos: devfs.h Source File + + + +

devfs.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The DevOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the DevOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _DEVFS_H
+00025 #define _DEVFS_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <vfs/file.h>
+00029 
+00030 struct devFsDevices {
+00031   struct devFsDevices *next;
+00032   struct devFsDevices *prev;
+00033   uInt8  devType;
+00034   uInt16 devMajor;
+00035   uInt16 devMinor;
+00036   char   devName[32];
+00037   };
+00038 
+00039 struct devFsInfo {
+00040   struct devFsDevices *deviceList;
+00041   };
+00042 
+00043 int devFSOpen(char *file,fileDescriptor *fd);
+00044 void devFSInit(struct mountPoints *mp);
+00045 int devFSEnable();
+00046 int devFSRead(fileDescriptor *fd,char *data,long offset,long size);
+00047 int devFSWrite(fileDescriptor *fd,char *data,long offset,long size);
+00048 int devFsMkNod(char *name,uInt8 type,uInt16 major,uInt16 minor);
+00049 
+00050 #endif
+

Generated on Wed Apr 28 17:49:32 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/devfs_8h.html b/doc/doxygen/html/devfs_8h.html new file mode 100644 index 0000000..75f476a --- /dev/null +++ b/doc/doxygen/html/devfs_8h.html @@ -0,0 +1,283 @@ + + +Ubixos: devfs.h File Reference + + + +

devfs.h File Reference

#include <ubixos/types.h>
+#include <vfs/file.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  devFsDevices
struct  devFsInfo

Functions

int devFSOpen (char *file, fileDescriptor *fd)
void devFSInit (struct mountPoints *mp)
int devFSEnable ()
int devFSRead (fileDescriptor *fd, char *data, long offset, long size)
int devFSWrite (fileDescriptor *fd, char *data, long offset, long size)
int devFsMkNod (char *name, uInt8 type, uInt16 major, uInt16 minor)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
int devFSEnable  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void devFSInit struct mountPoints mp  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int devFsMkNod char *  name,
uInt8  type,
uInt16  major,
uInt16  minor
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int devFSOpen char *  file,
fileDescriptor fd
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int devFSRead fileDescriptor fd,
char *  data,
long  offset,
long  size
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int devFSWrite fileDescriptor fd,
char *  data,
long  offset,
long  size
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/device_8h-source.html b/doc/doxygen/html/device_8h-source.html new file mode 100644 index 0000000..5bfe312 --- /dev/null +++ b/doc/doxygen/html/device_8h-source.html @@ -0,0 +1,68 @@ + + +Ubixos: device.h Source File + + + +

device.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _DEVICE_H
+00025 #define _DEVICE_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 struct deviceNode {
+00030   struct deviceNode    *prev;
+00031   struct deviceNode    *next;
+00032   char type;
+00033   int major;
+00034   int minor;
+00035   uInt32 size;
+00036   void *info;
+00037   void (*read)(void *,void *,uInt32,uInt32);
+00038   void (*write)(void *,void *,uInt32,uInt32);
+00039   void (*reset)(void *);
+00040   void (*init)(void *);
+00041   void (*ioctl)(void *);
+00042   void (*stop)(void *);
+00043   void (*start)(void *);
+00044   void (*standby)(void *);
+00045   };
+00046 
+00047 
+00048 void deviceAdd(int major,int minor,char type,void *read,void *write,void *reset,void *init,void *ioctl,void *stop,void *start,void *standby,void *info);
+00049 struct deviceNode *deviceFind(int major,int minor);
+00050 
+00051 #endif
+00052 
+00053 /***
+00054  END
+00055  ***/
+00056 
+

Generated on Wed Apr 28 17:49:32 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/device_8h.html b/doc/doxygen/html/device_8h.html new file mode 100644 index 0000000..e53427e --- /dev/null +++ b/doc/doxygen/html/device_8h.html @@ -0,0 +1,163 @@ + + +Ubixos: device.h File Reference + + + +

device.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + +

Data Structures

struct  deviceNode

Functions

void deviceAdd (int major, int minor, char type, void *read, void *write, void *reset, void *init, void *ioctl, void *stop, void *start, void *standby, void *info)
deviceNodedeviceFind (int major, int minor)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void deviceAdd int  major,
int  minor,
char  type,
void *  read,
void *  write,
void *  reset,
void *  init,
void *  ioctl,
void *  stop,
void *  start,
void *  standby,
void *  info
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
struct deviceNode* deviceFind int  major,
int  minor
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/device_8old_8h-source.html b/doc/doxygen/html/device_8old_8h-source.html new file mode 100644 index 0000000..3d0438e --- /dev/null +++ b/doc/doxygen/html/device_8old_8h-source.html @@ -0,0 +1,70 @@ + + +Ubixos: device.old.h Source File + + + +

device.old.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _DEVICE_H
+00025 #define _DEVICE_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 struct device {
+00030   struct net *net;
+00031   uInt16 ioAddr;
+00032   uInt32 irq;
+00033   struct ei_device *priv;
+00034   uInt32 mtu;
+00035   };
+00036 
+00037 struct net {
+00038   char mac[6];
+00039   char broadcast[6];
+00040   };
+00041 
+00042 struct ei_device {
+00043   int txStartPage;
+00044   int rxStartPage;
+00045   int stopPage;
+00046   int currentPage;
+00047   uInt16 word16;
+00048   uInt32 pingPong;
+00049   int tx1;
+00050   int tx2;
+00051   };
+00052 
+00053 #endif
+00054 
+00055 /***
+00056  END
+00057  ***/
+00058 
+

Generated on Wed Apr 28 17:49:32 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/device_8old_8h.html b/doc/doxygen/html/device_8old_8h.html new file mode 100644 index 0000000..ce321ee --- /dev/null +++ b/doc/doxygen/html/device_8old_8h.html @@ -0,0 +1,25 @@ + + +Ubixos: device.old.h File Reference + + + +

device.old.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + +

Data Structures

struct  device
struct  ei_device
struct  net
+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/disklabel_8h-source.html b/doc/doxygen/html/disklabel_8h-source.html new file mode 100644 index 0000000..8754933 --- /dev/null +++ b/doc/doxygen/html/disklabel_8h-source.html @@ -0,0 +1,501 @@ + + +Ubixos: disklabel.h Source File + + + +

disklabel.h

00001 /*
+00002  * Copyright (c) 1987, 1988, 1993
+00003  *      The Regents of the University of California.  All rights reserved.
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without
+00006  * modification, are permitted provided that the following conditions
+00007  * are met:
+00008  * 1. Redistributions of source code must retain the above copyright
+00009  *    notice, this list of conditions and the following disclaimer.
+00010  * 2. Redistributions in binary form must reproduce the above copyright
+00011  *    notice, this list of conditions and the following disclaimer in the
+00012  *    documentation and/or other materials provided with the distribution.
+00013  * 3. All advertising materials mentioning features or use of this software
+00014  *    must display the following acknowledgement:
+00015  *      This product includes software developed by the University of
+00016  *      California, Berkeley and its contributors.
+00017  * 4. Neither the name of the University nor the names of its contributors
+00018  *    may be used to endorse or promote products derived from this software
+00019  *    without specific prior written permission.
+00020  *
+00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+00031  * SUCH DAMAGE.
+00032  *
+00033  *      @(#)disklabel.h 8.2 (Berkeley) 7/10/94
+00034  * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $
+00035  */
+00036 
+00037 #ifndef _SYS_DISKLABEL_H_
+00038 #define _SYS_DISKLABEL_H_
+00039 
+00040 #ifndef _KERNEL
+00041 #include <sys/types.h>
+00042 #endif
+00043 #include <sys/ioccom.h>
+00044 
+00045 /*
+00046  * Disk description table, see disktab(5)
+00047  */
+00048 #define _PATH_DISKTAB   "/etc/disktab"
+00049 #define DISKTAB         "/etc/disktab"          /* deprecated */
+00050 
+00051 /*
+00052  * Each disk has a label which includes information about the hardware
+00053  * disk geometry, filesystem partitions, and drive specific information.
+00054  * The label is in block 0 or 1, possibly offset from the beginning
+00055  * to leave room for a bootstrap, etc.
+00056  */
+00057 
+00058 /* XXX these should be defined per controller (or drive) elsewhere, not here! */
+00059 #ifdef __i386__
+00060 #define LABELSECTOR     1                       /* sector containing label */
+00061 #define LABELOFFSET     0                       /* offset of label in sector */
+00062 #endif
+00063 
+00064 #ifdef __alpha__
+00065 #define LABELSECTOR     0
+00066 #define LABELOFFSET     64
+00067 #endif
+00068 
+00069 #ifndef LABELSECTOR
+00070 #define LABELSECTOR     0                       /* sector containing label */
+00071 #endif
+00072 
+00073 #ifndef LABELOFFSET
+00074 #define LABELOFFSET     64                      /* offset of label in sector */
+00075 #endif
+00076 
+00077 #define DISKMAGIC       ((u_int32_t)0x82564557) /* The disk magic number */
+00078 #ifndef MAXPARTITIONS
+00079 #define MAXPARTITIONS   8
+00080 #endif
+00081 
+00082 #define LABEL_PART      2               /* partition containing label */
+00083 #define RAW_PART        2               /* partition containing whole disk */
+00084 #define SWAP_PART       1               /* partition normally containing swap */
+00085 
+00086 #ifndef LOCORE
+00087 struct disklabel {
+00088         u_int32_t d_magic;              /* the magic number */
+00089         u_int16_t d_type;               /* drive type */
+00090         u_int16_t d_subtype;            /* controller/d_type specific */
+00091         char      d_typename[16];       /* type name, e.g. "eagle" */
+00092 
+00093         /* 
+00094          * d_packname contains the pack identifier and is returned when
+00095          * the disklabel is read off the disk or in-core copy.
+00096          * d_boot0 and d_boot1 are the (optional) names of the
+00097          * primary (block 0) and secondary (block 1-15) bootstraps
+00098          * as found in /boot.  These are returned when using
+00099          * getdiskbyname(3) to retrieve the values from /etc/disktab.
+00100          */
+00101         union {
+00102                 char    un_d_packname[16];      /* pack identifier */
+00103                 struct {
+00104                         char *un_d_boot0;       /* primary bootstrap name */
+00105                         char *un_d_boot1;       /* secondary bootstrap name */
+00106                 } un_b;
+00107         } d_un;
+00108 #define d_packname      d_un.un_d_packname
+00109 #define d_boot0         d_un.un_b.un_d_boot0
+00110 #define d_boot1         d_un.un_b.un_d_boot1
+00111 
+00112                         /* disk geometry: */
+00113         u_int32_t d_secsize;            /* # of bytes per sector */
+00114         u_int32_t d_nsectors;           /* # of data sectors per track */
+00115         u_int32_t d_ntracks;            /* # of tracks per cylinder */
+00116         u_int32_t d_ncylinders;         /* # of data cylinders per unit */
+00117         u_int32_t d_secpercyl;          /* # of data sectors per cylinder */
+00118         u_int32_t d_secperunit;         /* # of data sectors per unit */
+00119 
+00120         /*
+00121          * Spares (bad sector replacements) below are not counted in
+00122          * d_nsectors or d_secpercyl.  Spare sectors are assumed to
+00123          * be physical sectors which occupy space at the end of each
+00124          * track and/or cylinder.
+00125          */
+00126         u_int16_t d_sparespertrack;     /* # of spare sectors per track */
+00127         u_int16_t d_sparespercyl;       /* # of spare sectors per cylinder */
+00128         /*
+00129          * Alternate cylinders include maintenance, replacement, configuration
+00130          * description areas, etc.
+00131          */
+00132         u_int32_t d_acylinders;         /* # of alt. cylinders per unit */
+00133 
+00134                         /* hardware characteristics: */
+00135         /*
+00136          * d_interleave, d_trackskew and d_cylskew describe perturbations
+00137          * in the media format used to compensate for a slow controller.
+00138          * Interleave is physical sector interleave, set up by the
+00139          * formatter or controller when formatting.  When interleaving is
+00140          * in use, logically adjacent sectors are not physically
+00141          * contiguous, but instead are separated by some number of
+00142          * sectors.  It is specified as the ratio of physical sectors
+00143          * traversed per logical sector.  Thus an interleave of 1:1
+00144          * implies contiguous layout, while 2:1 implies that logical
+00145          * sector 0 is separated by one sector from logical sector 1.
+00146          * d_trackskew is the offset of sector 0 on track N relative to
+00147          * sector 0 on track N-1 on the same cylinder.  Finally, d_cylskew
+00148          * is the offset of sector 0 on cylinder N relative to sector 0
+00149          * on cylinder N-1.
+00150          */
+00151         u_int16_t d_rpm;                /* rotational speed */
+00152         u_int16_t d_interleave;         /* hardware sector interleave */
+00153         u_int16_t d_trackskew;          /* sector 0 skew, per track */
+00154         u_int16_t d_cylskew;            /* sector 0 skew, per cylinder */
+00155         u_int32_t d_headswitch;         /* head switch time, usec */
+00156         u_int32_t d_trkseek;            /* track-to-track seek, usec */
+00157         u_int32_t d_flags;              /* generic flags */
+00158 #define NDDATA 5
+00159         u_int32_t d_drivedata[NDDATA];  /* drive-type specific information */
+00160 #define NSPARE 5
+00161         u_int32_t d_spare[NSPARE];      /* reserved for future use */
+00162         u_int32_t d_magic2;             /* the magic number (again) */
+00163         u_int16_t d_checksum;           /* xor of data incl. partitions */
+00164 
+00165                         /* filesystem and partition information: */
+00166         u_int16_t d_npartitions;        /* number of partitions in following */
+00167         u_int32_t d_bbsize;             /* size of boot area at sn0, bytes */
+00168         u_int32_t d_sbsize;             /* max size of fs superblock, bytes */
+00169         struct  partition {             /* the partition table */
+00170                 u_int32_t p_size;       /* number of sectors in partition */
+00171                 u_int32_t p_offset;     /* starting sector */
+00172                 u_int32_t p_fsize;      /* filesystem basic fragment size */
+00173                 u_int8_t p_fstype;      /* filesystem type, see below */
+00174                 u_int8_t p_frag;        /* filesystem fragments per block */
+00175                 union {
+00176                         u_int16_t cpg;  /* UFS: FS cylinders per group */
+00177                         u_int16_t sgs;  /* LFS: FS segment shift */
+00178                 } __partition_u1;
+00179 #define p_cpg   __partition_u1.cpg
+00180 #define p_sgs   __partition_u1.sgs
+00181         } d_partitions[MAXPARTITIONS];  /* actually may be more */
+00182 };
+00183 
+00184 static u_int16_t dkcksum(struct disklabel *lp);
+00185 
+00186 static __inline u_int16_t
+00187 dkcksum(struct disklabel *lp)
+00188 {
+00189         u_int16_t *start, *end;
+00190         u_int16_t sum = 0;
+00191 
+00192         start = (u_int16_t *)lp;
+00193         end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions];
+00194         while (start < end)
+00195                 sum ^= *start++;
+00196         return (sum);
+00197 }
+00198 
+00199 #else /* LOCORE */
+00200         /*
+00201          * offsets for asm boot files.
+00202          */
+00203         .set    d_secsize,40
+00204         .set    d_nsectors,44
+00205         .set    d_ntracks,48
+00206         .set    d_ncylinders,52
+00207         .set    d_secpercyl,56
+00208         .set    d_secperunit,60
+00209         .set    d_end_,276              /* size of disk label */
+00210 #endif /* LOCORE */
+00211 
+00212 /* d_type values: */
+00213 #define DTYPE_SMD               1               /* SMD, XSMD; VAX hp/up */
+00214 #define DTYPE_MSCP              2               /* MSCP */
+00215 #define DTYPE_DEC               3               /* other DEC (rk, rl) */
+00216 #define DTYPE_SCSI              4               /* SCSI */
+00217 #define DTYPE_ESDI              5               /* ESDI interface */
+00218 #define DTYPE_ST506             6               /* ST506 etc. */
+00219 #define DTYPE_HPIB              7               /* CS/80 on HP-IB */
+00220 #define DTYPE_HPFL              8               /* HP Fiber-link */
+00221 #define DTYPE_FLOPPY            10              /* floppy */
+00222 #define DTYPE_CCD               11              /* concatenated disk */
+00223 #define DTYPE_VINUM             12              /* vinum volume */
+00224 #define DTYPE_DOC2K             13              /* Msys DiskOnChip */
+00225 
+00226 #if defined(PC98) && !defined(PC98_ATCOMPAT)
+00227 #define DSTYPE_SEC256           0x80            /* physical sector size=256 */
+00228 #endif
+00229 
+00230 #ifdef DKTYPENAMES
+00231 static char *dktypenames[] = {
+00232         "unknown",
+00233         "SMD",
+00234         "MSCP",
+00235         "old DEC",
+00236         "SCSI",
+00237         "ESDI",
+00238         "ST506",
+00239         "HP-IB",
+00240         "HP-FL",
+00241         "type 9",
+00242         "floppy",
+00243         "CCD",
+00244         "Vinum",
+00245         "DOC2K",
+00246         NULL
+00247 };
+00248 #define DKMAXTYPES      (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
+00249 #endif
+00250 
+00251 /*
+00252  * Filesystem type and version.
+00253  * Used to interpret other filesystem-specific
+00254  * per-partition information.
+00255  */
+00256 #define FS_UNUSED       0               /* unused */
+00257 #define FS_SWAP         1               /* swap */
+00258 #define FS_V6           2               /* Sixth Edition */
+00259 #define FS_V7           3               /* Seventh Edition */
+00260 #define FS_SYSV         4               /* System V */
+00261 #define FS_V71K         5               /* V7 with 1K blocks (4.1, 2.9) */
+00262 #define FS_V8           6               /* Eighth Edition, 4K blocks */
+00263 #define FS_BSDFFS       7               /* 4.2BSD fast file system */
+00264 #define FS_MSDOS        8               /* MSDOS file system */
+00265 #define FS_BSDLFS       9               /* 4.4BSD log-structured file system */
+00266 #define FS_OTHER        10              /* in use, but unknown/unsupported */
+00267 #define FS_HPFS         11              /* OS/2 high-performance file system */
+00268 #define FS_ISO9660      12              /* ISO 9660, normally CD-ROM */
+00269 #define FS_BOOT         13              /* partition contains bootstrap */
+00270 #define FS_VINUM        14              /* Vinum drive */
+00271 
+00272 #ifdef  DKTYPENAMES
+00273 static char *fstypenames[] = {
+00274         "unused",
+00275         "swap",
+00276         "Version 6",
+00277         "Version 7",
+00278         "System V",
+00279         "4.1BSD",
+00280         "Eighth Edition",
+00281         "4.2BSD",
+00282         "MSDOS",
+00283         "4.4LFS",
+00284         "unknown",
+00285         "HPFS",
+00286         "ISO9660",
+00287         "boot",
+00288         "vinum",
+00289         NULL
+00290 };
+00291 #define FSMAXTYPES      (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
+00292 #endif
+00293 
+00294 /*
+00295  * flags shared by various drives:
+00296  */
+00297 #define         D_REMOVABLE     0x01            /* removable media */
+00298 #define         D_ECC           0x02            /* supports ECC */
+00299 #define         D_BADSECT       0x04            /* supports bad sector forw. */
+00300 #define         D_RAMDISK       0x08            /* disk emulator */
+00301 #define         D_CHAIN         0x10            /* can do back-back transfers */
+00302 
+00303 /*
+00304  * Drive data for SMD.
+00305  */
+00306 #define d_smdflags      d_drivedata[0]
+00307 #define         D_SSE           0x1             /* supports skip sectoring */
+00308 #define d_mindist       d_drivedata[1]
+00309 #define d_maxdist       d_drivedata[2]
+00310 #define d_sdist         d_drivedata[3]
+00311 
+00312 /*
+00313  * Drive data for ST506.
+00314  */
+00315 #define d_precompcyl    d_drivedata[0]
+00316 #define d_gap3          d_drivedata[1]          /* used only when formatting */
+00317 
+00318 /*
+00319  * Drive data for SCSI.
+00320  */
+00321 #define d_blind         d_drivedata[0]
+00322 
+00323 #ifndef LOCORE
+00324 /*
+00325  * Structure used to perform a format or other raw operation, returning
+00326  * data and/or register values.  Register identification and format
+00327  * are device- and driver-dependent.
+00328  */
+00329 struct format_op {
+00330         char    *df_buf;
+00331         int      df_count;              /* value-result */
+00332         daddr_t  df_startblk;
+00333         int      df_reg[8];             /* result */
+00334 };
+00335 
+00336 /*
+00337  * Structure used internally to retrieve information about a partition
+00338  * on a disk.
+00339  */
+00340 struct partinfo {
+00341         struct disklabel *disklab;
+00342         struct partition *part;
+00343 };
+00344 
+00345 /* DOS partition table -- located in boot block */
+00346 
+00347 #if defined(PC98) && !defined(PC98_ATCOMPAT)
+00348 #define DOSBBSECTOR     0       /* DOS boot block relative sector number */
+00349 #define DOSLABELSECTOR  1       /* 0: 256b/s, 1: 512b/s */
+00350 #define DOSPARTOFF      0
+00351 #define NDOSPART        16
+00352 #define DOSPTYP_386BSD  0x94    /* 386BSD partition type */
+00353 #define MBR_PTYPE_FreeBSD 0x94  /* FreeBSD partition type */
+00354 
+00355 struct dos_partition {
+00356         unsigned char   dp_mid;
+00357 #define DOSMID_386BSD           (0x14|0x80) /* 386bsd|bootable */
+00358         unsigned char   dp_sid;
+00359 #define DOSSID_386BSD           (0x44|0x80) /* 386bsd|active */ 
+00360         unsigned char   dp_dum1;
+00361         unsigned char   dp_dum2;
+00362         unsigned char   dp_ipl_sct;
+00363         unsigned char   dp_ipl_head;
+00364         unsigned short  dp_ipl_cyl;
+00365         unsigned char   dp_ssect;       /* starting sector */
+00366         unsigned char   dp_shd;         /* starting head */
+00367         unsigned short  dp_scyl;        /* starting cylinder */
+00368         unsigned char   dp_esect;       /* end sector */
+00369         unsigned char   dp_ehd;         /* end head */
+00370         unsigned short  dp_ecyl;        /* end cylinder */
+00371         unsigned char   dp_name[16];
+00372 };
+00373 
+00374 #else /* IBMPC */
+00375 #define DOSBBSECTOR     0       /* DOS boot block relative sector number */
+00376 #define DOSPARTOFF      446
+00377 #define NDOSPART        4
+00378 #define DOSPTYP_386BSD  0xa5    /* 386BSD partition type */
+00379 #define DOSPTYP_LINSWP  0x82    /* Linux swap partition */
+00380 #define DOSPTYP_LINUX   0x83    /* Linux partition */
+00381 #define DOSPTYP_EXT     5       /* DOS extended partition */
+00382 
+00383 struct dos_partition {
+00384         unsigned char   dp_flag;        /* bootstrap flags */
+00385         unsigned char   dp_shd;         /* starting head */
+00386         unsigned char   dp_ssect;       /* starting sector */
+00387         unsigned char   dp_scyl;        /* starting cylinder */
+00388         unsigned char   dp_typ;         /* partition type */
+00389         unsigned char   dp_ehd;         /* end head */
+00390         unsigned char   dp_esect;       /* end sector */
+00391         unsigned char   dp_ecyl;        /* end cylinder */
+00392         u_int32_t       dp_start;       /* absolute starting sector number */
+00393         u_int32_t       dp_size;        /* partition size in sectors */
+00394 };
+00395 #endif
+00396 
+00397 #define DPSECT(s) ((s) & 0x3f)          /* isolate relevant bits of sector */
+00398 #define DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */
+00399 
+00400 /*
+00401  * Disk-specific ioctls.
+00402  */
+00403                 /* get and set disklabel; DIOCGPART used internally */
+00404 #define DIOCGDINFO      _IOR('d', 101, struct disklabel)/* get */
+00405 #define DIOCSDINFO      _IOW('d', 102, struct disklabel)/* set */
+00406 #define DIOCWDINFO      _IOW('d', 103, struct disklabel)/* set, update disk */
+00407 #define DIOCGPART       _IOW('d', 104, struct partinfo) /* get partition */
+00408 #define DIOCGDVIRGIN    _IOR('d', 105, struct disklabel) /* get virgin label */
+00409 
+00410 #define DIOCWLABEL      _IOW('d', 109, int)     /* write en/disable label */
+00411 
+00412 #ifdef _KERNEL
+00413 
+00414 /*
+00415  * XXX encoding of disk minor numbers, should be elsewhere.
+00416  *
+00417  * See <sys/reboot.h> for a possibly better encoding.
+00418  *
+00419  * "cpio -H newc" can be used to back up device files with large minor
+00420  * numbers (but not ones >= 2^31).  Old cpio formats and all tar formats
+00421  * don't have enough bits, and cpio and tar don't notice the lossage.
+00422  * There are also some sign extension bugs.
+00423  */
+00424 
+00425 /*
+00426        3                   2                   1                   0
+00427      1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+00428     _________________________________________________________________
+00429     | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+00430     -----------------------------------------------------------------
+00431     |    TYPE     |UNIT_2 | SLICE   |  MAJOR?       |  UNIT   |PART |
+00432     -----------------------------------------------------------------
+00433 */
+00434 
+00435 #define DKMAXUNIT 0x1ff         /* Highest disk unit number */
+00436 
+00437 #define dkmakeminor(unit, slice, part) \
+00438                                 (((slice) << 16) | (((unit) & 0x1e0) << 16) | \
+00439                                 (((unit) & 0x1f) << 3) | (part))
+00440 static __inline dev_t
+00441 dkmodpart(dev_t dev, int part)
+00442 {
+00443         return (makedev(major(dev), (minor(dev) & ~7) | part));
+00444 }
+00445 
+00446 static __inline dev_t
+00447 dkmodslice(dev_t dev, int slice)
+00448 {
+00449         return (makedev(major(dev), (minor(dev) & ~0x1f0000) | (slice << 16)));
+00450 }
+00451 
+00452 #define dkpart(dev)             (minor(dev) & 7)
+00453 #define dkslice(dev)            ((minor(dev) >> 16) & 0x1f)
+00454 #define dktype(dev)             ((minor(dev) >> 25) & 0x7f)
+00455 
+00456 static __inline u_int
+00457 dkunit(dev_t dev)
+00458 {
+00459         return (((minor(dev) >> 16) & 0x1e0) | ((minor(dev) >> 3) & 0x1f));
+00460 }
+00461 
+00462 struct  buf;
+00463 struct  buf_queue_head;
+00464 
+00465 int     bounds_check_with_label __P((struct buf *bp, struct disklabel *lp,
+00466                                      int wlabel));
+00467 void    diskerr __P((struct buf *bp, char *what, int pri, int blkdone,
+00468                      struct disklabel *lp));
+00469 void    disksort __P((struct buf *ap, struct buf *bp));
+00470 char    *readdisklabel __P((dev_t dev, struct disklabel *lp));
+00471 void    bufqdisksort __P((struct buf_queue_head *ap, struct buf *bp));
+00472 int     setdisklabel __P((struct disklabel *olp, struct disklabel *nlp,
+00473                           u_long openmask));
+00474 int     writedisklabel __P((dev_t dev, struct disklabel *lp));
+00475 #ifdef __alpha__
+00476 void    alpha_fix_srm_checksum __P((struct buf *bp));
+00477 #endif
+00478 
+00479 #endif /* _KERNEL */
+00480 
+00481 #endif /* LOCORE */
+00482 
+00483 #ifndef _KERNEL
+00484 __BEGIN_DECLS
+00485 struct disklabel *getdiskbyname __P((const char *));
+00486 __END_DECLS
+00487 #endif
+00488 
+00489 #endif /* !_SYS_DISKLABEL_H_ */
+

Generated on Wed Apr 28 17:49:33 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/diskslice_8h-source.html b/doc/doxygen/html/diskslice_8h-source.html new file mode 100644 index 0000000..af4adaa --- /dev/null +++ b/doc/doxygen/html/diskslice_8h-source.html @@ -0,0 +1,119 @@ + + +Ubixos: diskslice.h Source File + + + +

diskslice.h

00001 /*-
+00002  * Copyright (c) 1994 Bruce D. Evans.
+00003  * All rights reserved.
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without
+00006  * modification, are permitted provided that the following conditions
+00007  * are met:
+00008  * 1. Redistributions of source code must retain the above copyright
+00009  *    notice, this list of conditions and the following disclaimer.
+00010  * 2. Redistributions in binary form must reproduce the above copyright
+00011  *    notice, this list of conditions and the following disclaimer in the
+00012  *    documentation and/or other materials provided with the distribution.
+00013  *
+00014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+00015  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+00016  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+00017  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+00018  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+00019  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+00020  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+00021  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+00022  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00023  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+00024  * SUCH DAMAGE.
+00025  *
+00026  * $FreeBSD: src/sys/sys/diskslice.h,v 1.36.2.1 2001/01/29 01:50:50 ken Exp $
+00027  */
+00028 
+00029 #ifndef _SYS_DISKSLICE_H_
+00030 #define _SYS_DISKSLICE_H_
+00031 
+00032 #ifndef _KERNEL
+00033 #include <sys/types.h>
+00034 #endif
+00035 #include <sys/ioccom.h>
+00036 
+00037 #define BASE_SLICE              2
+00038 #define COMPATIBILITY_SLICE     0
+00039 #define DIOCGSLICEINFO          _IOR('d', 111, struct diskslices)
+00040 #define DIOCSYNCSLICEINFO       _IOW('d', 112, int)
+00041 #define MAX_SLICES              32
+00042 #define WHOLE_DISK_SLICE        1
+00043 
+00044 struct  diskslice {
+00045         u_long  ds_offset;              /* starting sector */
+00046         u_long  ds_size;                /* number of sectors */
+00047         int     ds_type;                /* (foreign) slice type */
+00048 #ifdef PC98
+00049         int     ds_subtype;             /* sub slice type */
+00050         u_char  ds_name[16];            /* slice name */
+00051 #endif
+00052         struct disklabel *ds_label;     /* BSD label, if any */
+00053         void    *ds_dev;                /* devfs token for raw whole slice */
+00054 #ifdef MAXPARTITIONS                    /* XXX don't depend on disklabel.h */
+00055 #if MAXPARTITIONS !=    8               /* but check consistency if possible */
+00056 #error "inconsistent MAXPARTITIONS"
+00057 #endif
+00058 #else
+00059 #define MAXPARTITIONS   8
+00060 #endif
+00061         void    *ds_devs[MAXPARTITIONS];        /* XXX s.b. in label */
+00062         u_char  ds_openmask;            /* devs open */
+00063         u_char  ds_wlabel;              /* nonzero if label is writable */
+00064 };
+00065 
+00066 struct diskslices {
+00067         struct cdevsw *dss_cdevsw;      /* for containing device */
+00068         int     dss_first_bsd_slice;    /* COMPATIBILITY_SLICE is mapped here */
+00069         u_int   dss_nslices;            /* actual dimension of dss_slices[] */
+00070         u_int   dss_oflags;             /* copy of flags for "first" open */
+00071         int     dss_secmult;            /* block to sector multiplier */
+00072         int     dss_secshift;           /* block to sector shift (or -1) */
+00073         int     dss_secsize;            /* sector size */
+00074         struct diskslice
+00075                 dss_slices[MAX_SLICES]; /* actually usually less */
+00076 };
+00077 
+00078 #ifdef _KERNEL
+00079 
+00080 /* Flags for dsopen(). */
+00081 #define DSO_NOLABELS    1
+00082 #define DSO_ONESLICE    2
+00083 #define DSO_COMPATLABEL 4
+00084 
+00085 #define dsgetlabel(dev, ssp)    (ssp->dss_slices[dkslice(dev)].ds_label)
+00086 
+00087 struct buf;
+00088 struct disklabel;
+00089 
+00090 int     dscheck __P((struct buf *bp, struct diskslices *ssp));
+00091 void    dsclose __P((dev_t dev, int mode, struct diskslices *ssp));
+00092 void    dsgone __P((struct diskslices **sspp));
+00093 int     dsinit __P((dev_t dev, struct disklabel *lp,
+00094                      struct diskslices **sspp));
+00095 int     dsioctl __P((dev_t dev, u_long cmd, caddr_t data,
+00096                      int flags, struct diskslices **sspp));
+00097 int     dsisopen __P((struct diskslices *ssp));
+00098 struct diskslices *dsmakeslicestruct __P((int nslices, struct disklabel *lp));
+00099 char    *dsname __P((dev_t dev, int unit, int slice, int part,
+00100                      char *partname));
+00101 int     dsopen __P((dev_t dev, int mode, u_int flags,
+00102                     struct diskslices **sspp, struct disklabel *lp));
+00103 int     dssize __P((dev_t dev, struct diskslices **sspp));
+00104 
+00105 #endif /* _KERNEL */
+00106 
+00107 #endif /* !_SYS_DISKSLICE_H_ */
+

Generated on Wed Apr 28 17:49:33 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/dma_8h-source.html b/doc/doxygen/html/dma_8h-source.html new file mode 100644 index 0000000..8064903 --- /dev/null +++ b/doc/doxygen/html/dma_8h-source.html @@ -0,0 +1,45 @@ + + +Ubixos: dma.h Source File + + + +

dma.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _DMA_H
+00025 #define _DMA_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 void dmaXfer(uChar channel,uLong address,uInt length,uChar read);
+00030 void _dmaXfer(uChar dmaChannel,uChar page,uInt offset,uInt length,uChar mode);
+00031 
+00032 #endif
+00033 
+

Generated on Wed Apr 28 17:49:33 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/dma_8h.html b/doc/doxygen/html/dma_8h.html new file mode 100644 index 0000000..24a593a --- /dev/null +++ b/doc/doxygen/html/dma_8h.html @@ -0,0 +1,130 @@ + + +Ubixos: dma.h File Reference + + + +

dma.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + +

Functions

void dmaXfer (uInt8 channel, uInt32 address, uInt length, uInt8 read)
void _dmaXfer (uInt8 dmaChannel, uInt8 page, uInt offset, uInt length, uInt8 mode)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void _dmaXfer uInt8  dmaChannel,
uInt8  page,
uInt  offset,
uInt  length,
uInt8  mode
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void dmaXfer uInt8  channel,
uInt32  address,
uInt  length,
uInt8  read
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/doxygen.css b/doc/doxygen/html/doxygen.css new file mode 100644 index 0000000..0564e82 --- /dev/null +++ b/doc/doxygen/html/doxygen.css @@ -0,0 +1,160 @@ +H1 { + text-align: center; + font-family: Arial, Helvetica, sans-serif; +} +H2 { + font-family: Geneva, Arial, Helvetica, sans-serif; +} +CAPTION { font-weight: bold } +DIV.qindex { width: 100%; + background-color: #eeeeff; + border: 4px solid #eeeeff; + text-align: center; + margin-bottom: 2px +} +A.qindex { text-decoration: none; font-weight: bold; } +A.qindex:hover { text-decoration: none; background-color: #ddddff } +A.qindexHL { text-decoration: none; font-weight: bold; + background-color: #6666cc; + color: #ffffff + } +A.qindexHL:hover { text-decoration: none; background-color: #6666cc } +A.qindexRef { text-decoration: none; font-weight: bold; } +A.qindexRef:hover { text-decoration: none; background-color: #ddddff } +A.qindexRefHL { text-decoration: none; font-weight: bold; + background-color: #6666cc; + color: #ffffff + } +A.qindexRefHL:hover { text-decoration: none; background-color: #6666cc } +A.el { text-decoration: none; font-weight: bold } +A.elRef { font-weight: bold } +A.code { text-decoration: none; font-weight: normal; color: #4444ee } +A.codeRef { font-weight: normal; color: #4444ee } +A:hover { text-decoration: none; background-color: #f2f2ff } +DL.el { margin-left: -1cm } +DIV.fragment { + width: 98%; + border: 1px solid #CCCCCC; + background-color: #f5f5f5; + padding-left: 4px; + margin: 4px; +} +DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px } +TD.md { background-color: #f2f2ff; font-weight: bold; } +TD.mdname1 { background-color: #f2f2ff; font-weight: bold; color: #602020; } +TD.mdname { background-color: #f2f2ff; font-weight: bold; color: #602020; width: 600px; } +DIV.groupHeader { margin-left: 16px; margin-top: 12px; margin-bottom: 6px; font-weight: bold } +DIV.groupText { margin-left: 16px; font-style: italic; font-size: smaller } +BODY { + background: white; + color: black; + margin-right: 20px; + margin-left: 20px; +} +TD.indexkey { + background-color: #eeeeff; + font-weight: bold; + padding-right : 10px; + padding-top : 2px; + padding-left : 10px; + padding-bottom : 2px; + margin-left : 0px; + margin-right : 0px; + margin-top : 2px; + margin-bottom : 2px +} +TD.indexvalue { + background-color: #eeeeff; + font-style: italic; + padding-right : 10px; + padding-top : 2px; + padding-left : 10px; + padding-bottom : 2px; + margin-left : 0px; + margin-right : 0px; + margin-top : 2px; + margin-bottom : 2px +} +TR.memlist { + background-color: #f0f0f0; +} +P.formulaDsp { text-align: center; } +IMG.formulaDsp { } +IMG.formulaInl { vertical-align: middle; } +SPAN.keyword { color: #008000 } +SPAN.keywordtype { color: #604020 } +SPAN.keywordflow { color: #e08000 } +SPAN.comment { color: #800000 } +SPAN.preprocessor { color: #806020 } +SPAN.stringliteral { color: #002080 } +SPAN.charliteral { color: #008080 } +.mdTable { + border: 1px solid #868686; + background-color: #f2f2ff; +} +.mdRow { + padding: 8px 20px; +} +.mdescLeft { + font-size: smaller; + font-family: Arial, Helvetica, sans-serif; + background-color: #FAFAFA; + padding-left: 8px; + border-top: 1px none #E0E0E0; + border-right: 1px none #E0E0E0; + border-bottom: 1px none #E0E0E0; + border-left: 1px none #E0E0E0; + margin: 0px; +} +.mdescRight { + font-size: smaller; + font-family: Arial, Helvetica, sans-serif; + font-style: italic; + background-color: #FAFAFA; + padding-left: 4px; + border-top: 1px none #E0E0E0; + border-right: 1px none #E0E0E0; + border-bottom: 1px none #E0E0E0; + border-left: 1px none #E0E0E0; + margin: 0px; + padding-bottom: 0px; + padding-right: 8px; +} +.memItemLeft { + padding: 1px 0px 0px 8px; + margin: 4px; + border-top-width: 1px; + border-right-width: 1px; + border-bottom-width: 1px; + border-left-width: 1px; + border-top-style: solid; + border-top-color: #E0E0E0; + border-right-color: #E0E0E0; + border-bottom-color: #E0E0E0; + border-left-color: #E0E0E0; + border-right-style: none; + border-bottom-style: none; + border-left-style: none; + background-color: #FAFAFA; + font-family: Geneva, Arial, Helvetica, sans-serif; + font-size: 12px; +} +.memItemRight { + padding: 1px 0px 0px 8px; + margin: 4px; + border-top-width: 1px; + border-right-width: 1px; + border-bottom-width: 1px; + border-left-width: 1px; + border-top-style: solid; + border-top-color: #E0E0E0; + border-right-color: #E0E0E0; + border-bottom-color: #E0E0E0; + border-left-color: #E0E0E0; + border-right-style: none; + border-bottom-style: none; + border-left-style: none; + background-color: #FAFAFA; + font-family: Geneva, Arial, Helvetica, sans-serif; + font-size: 13px; +} diff --git a/doc/doxygen/html/doxygen.png b/doc/doxygen/html/doxygen.png new file mode 100644 index 0000000..96ae72c --- /dev/null +++ b/doc/doxygen/html/doxygen.png Binary files differ diff --git a/doc/doxygen/html/driver_8h-source.html b/doc/doxygen/html/driver_8h-source.html new file mode 100644 index 0000000..26168c5 --- /dev/null +++ b/doc/doxygen/html/driver_8h-source.html @@ -0,0 +1,60 @@ + + +Ubixos: driver.h Source File + + + +

driver.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _DRIVER_H
+00025 #define _DRIVER_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 
+00030 typedef struct devMethodType devMethod;
+00031 
+00032 struct devMethodType {
+00033   };
+00034 
+00035 struct driverType {
+00036   const char *devName;
+00037   devMethod *methods;
+00038   }
+00039 
+00040 
+00041 
+00042 
+00043 #endif
+00044 
+00045 /***
+00046  END
+00047  ***/
+00048 
+

Generated on Wed Apr 28 17:49:33 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/driver_8h.html b/doc/doxygen/html/driver_8h.html new file mode 100644 index 0000000..b7dfa8a --- /dev/null +++ b/doc/doxygen/html/driver_8h.html @@ -0,0 +1,49 @@ + + +Ubixos: driver.h File Reference + + + +

driver.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + +

Data Structures

struct  devMethodType
struct  driverType

Typedefs

typedef devMethodType devMethod
+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct devMethodType devMethod +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/elf_8h-source.html b/doc/doxygen/html/elf_8h-source.html new file mode 100644 index 0000000..b08108d --- /dev/null +++ b/doc/doxygen/html/elf_8h-source.html @@ -0,0 +1,139 @@ + + +Ubixos: elf.h Source File + + + +

elf.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _ELF_H
+00025 #define _ELF_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #define elfExecutable 0x002
+00030 #define elfLibrary    0x003
+00031 
+00032 
+00033 /* Elf Types */
+00034 #define ET_NONE         0  // No file type
+00035 #define ET_REL          1  // Relocatable file
+00036 #define ET_EXEC         2  // Executable file
+00037 #define ET_DYN          3  // Shared object file
+00038 #define ET_CORE         4  // Core file
+00039 #define ET_LOPROC  0xff00  // Processor-specific
+00040 #define ET_HIPROC  0xffff
+00041 /* End Elf Types */
+00042 
+00043 /* Elf Machine Types */
+00044 #define EM_NONE       0  // No machine
+00045 #define EM_M32        1  // AT&T WE 32100
+00046 #define EM_SPARC      2  // SPARC
+00047 #define EM_386        3  // Intel 80386
+00048 #define EM_68K        4  // Motorola 68000
+00049 #define EM_88K        5  // Motorola 88000
+00050 #define EM_860        7  // Intel 80860
+00051 #define EM_MIPS       8  // MIPS RS3000
+00052 /* End Elf Machines Types */
+00053 
+00054 /* Elf Version */
+00055 #define EV_NONE          0  // Invalid version
+00056 #define EV_CURRENT       1  // Current version
+00057 /* End Elf Version */
+00058 
+00059 /* Elf Program Header Types */
+00060 #define PT_NULL          0
+00061 #define PT_LOAD          1
+00062 #define PT_DYNAMIC       2
+00063 /* End Elf Program Header Types */
+00064 
+00065 typedef struct {
+00066   uChar  eIdent[16]; /* File identification. */
+00067   uShort eType;      /* File type. */
+00068   uShort eMachine;   /* Machine architecture. */
+00069   uLong  eVersion;   /* ELF format version. */
+00070   uLong  eEntry;     /* Entry point. */
+00071   uLong  ePhoff;     /* Program header file offset. */
+00072   uLong  eShoff;     /* Section header file offset. */
+00073   uLong  eFlags;     /* Architecture-specific flags. */
+00074   uShort eEhsize;    /* Size of ELF header in bytes. */
+00075   uShort ePhentsize; /* Size of program header entry. */
+00076   uShort ePhnum;     /* Number of program header entries. */
+00077   uShort eShentsize; /* Size of section header entry. */
+00078   uShort eShnum;     /* Number of section header entries. */
+00079   uShort eShstrndx;  /* Section name strings section. */
+00080   } elfHeader;
+00081 
+00082 typedef struct {
+00083   uLong phType;         /* Entry type. */
+00084   uLong phOffset;       /* File offset of contents. */
+00085   uLong phVaddr;        /* Virtual address in memory image. */
+00086   uLong phPaddr;        /* Physical address (not used). */
+00087   uLong phFilesz;       /* Size of contents in file. */
+00088   uLong phMemsz;        /* Size of contents in memory. */
+00089   uLong phFlags;        /* Access permission flags. */
+00090   uLong phAlign;        /* Alignment in memory and file. */
+00091   } elfProgramheader;
+00092 
+00093 typedef struct {
+00094   uLong shName;        /* Section name (index into the section header string table). */
+00095   uLong shType;        /* Section type. */
+00096   uLong shFlags;       /* Section flags. */
+00097   uLong shAddr;        /* Address in memory image. */
+00098   uLong shOffset;      /* Offset in file. */
+00099   uLong shSize;        /* Size in bytes. */
+00100   uLong shLink;        /* Index of a related section. */
+00101   uLong shInfo;        /* Depends on section type. */
+00102   uLong shAddralign;   /* Alignment in bytes. */
+00103   uLong shEntsize;     /* Size of each entry in section. */
+00104   } elfSectionheader;
+00105 
+00106 typedef struct {
+00107   uLong pltOffset;
+00108   uLong pltInfo;
+00109   } elfPltInfo;
+00110 
+00111 typedef struct {
+00112   uLong dynName;
+00113   uLong dynValue;
+00114   uLong dynSize;
+00115   uLong dynInfo;
+00116   } elfDynsym;
+00117 
+00118 typedef struct {
+00119   uInt32 dynVal;
+00120   uInt32 dynPtr;
+00121   } elfDynamic;
+00122 
+00123 char *elfGetShType(int);
+00124 char *elfGetPhType(int);
+00125 
+00126 #endif
+00127 
+

Generated on Wed Apr 28 17:49:33 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/elf_8h.html b/doc/doxygen/html/elf_8h.html new file mode 100644 index 0000000..abab82a --- /dev/null +++ b/doc/doxygen/html/elf_8h.html @@ -0,0 +1,673 @@ + + +Ubixos: elf.h File Reference + + + +

elf.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  elfDynamic
struct  elfDynsym
struct  elfHeader
struct  elfPltInfo
struct  elfProgramheader
struct  elfSectionheader

Defines

#define elfExecutable   0x002
#define elfLibrary   0x003
#define ET_NONE   0
 No file type.

#define ET_REL   1
 Relocatable file.

#define ET_EXEC   2
 Executable file.

#define ET_DYN   3
 Shared object file.

#define ET_CORE   4
 Core file.

#define ET_LOPROC   0xff00
 Processor-specific.

#define ET_HIPROC   0xffff
#define EM_NONE   0
 No machine.

#define EM_M32   1
 AT&T WE 32100.

#define EM_SPARC   2
 SPARC.

#define EM_386   3
 Intel 80386.

#define EM_68K   4
 Motorola 68000.

#define EM_88K   5
 Motorola 88000.

#define EM_860   7
 Intel 80860.

#define EM_MIPS   8
 MIPS RS3000.

#define EV_NONE   0
 Invalid version.

#define EV_CURRENT   1
 Current version.

#define PT_NULL   0
#define PT_LOAD   1
#define PT_DYNAMIC   2

Functions

char * elfGetShType (int)
char * elfGetPhType (int)
+


Define Documentation

+

+ + + + +
+ + +
#define elfExecutable   0x002 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define elfLibrary   0x003 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EM_386   3 +
+
+ + + + + +
+   + + +

+Intel 80386. +

+

+

+ + + + +
+ + +
#define EM_68K   4 +
+
+ + + + + +
+   + + +

+Motorola 68000. +

+

+

+ + + + +
+ + +
#define EM_860   7 +
+
+ + + + + +
+   + + +

+Intel 80860. +

+

+

+ + + + +
+ + +
#define EM_88K   5 +
+
+ + + + + +
+   + + +

+Motorola 88000. +

+

+

+ + + + +
+ + +
#define EM_M32   1 +
+
+ + + + + +
+   + + +

+AT&T WE 32100. +

+

+

+ + + + +
+ + +
#define EM_MIPS   8 +
+
+ + + + + +
+   + + +

+MIPS RS3000. +

+

+

+ + + + +
+ + +
#define EM_NONE   0 +
+
+ + + + + +
+   + + +

+No machine. +

+Elf Machine Types

+

+ + + + +
+ + +
#define EM_SPARC   2 +
+
+ + + + + +
+   + + +

+SPARC. +

+

+

+ + + + +
+ + +
#define ET_CORE   4 +
+
+ + + + + +
+   + + +

+Core file. +

+

+

+ + + + +
+ + +
#define ET_DYN   3 +
+
+ + + + + +
+   + + +

+Shared object file. +

+

+

+ + + + +
+ + +
#define ET_EXEC   2 +
+
+ + + + + +
+   + + +

+Executable file. +

+

+

+ + + + +
+ + +
#define ET_HIPROC   0xffff +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ET_LOPROC   0xff00 +
+
+ + + + + +
+   + + +

+Processor-specific. +

+

+

+ + + + +
+ + +
#define ET_NONE   0 +
+
+ + + + + +
+   + + +

+No file type. +

+

+

+ + + + +
+ + +
#define ET_REL   1 +
+
+ + + + + +
+   + + +

+Relocatable file. +

+

+

+ + + + +
+ + +
#define EV_CURRENT   1 +
+
+ + + + + +
+   + + +

+Current version. +

+

+

+ + + + +
+ + +
#define EV_NONE   0 +
+
+ + + + + +
+   + + +

+Invalid version. +

+Elf Version

+

+ + + + +
+ + +
#define PT_DYNAMIC   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PT_LOAD   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PT_NULL   0 +
+
+ + + + + +
+   + + +

+Elf Program Header Types

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
char* elfGetPhType int   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
char* elfGetShType int   ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/err_8h-source.html b/doc/doxygen/html/err_8h-source.html new file mode 100644 index 0000000..912fcea --- /dev/null +++ b/doc/doxygen/html/err_8h-source.html @@ -0,0 +1,85 @@ + + +Ubixos: err.h Source File + + + +

err.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_ERR_H__
+00036 #define __LWIP_ERR_H__
+00037 
+00038 #include <ubixos/types.h>
+00039 
+00040 #include "net/debug.h"
+00041 
+00042 #include "net/arch/cc.h"
+00043 
+00044 typedef Int8 err_t;
+00045 
+00046 /* Definitions for error constants. */
+00047 
+00048 #define ERR_OK    0      /* No error, everything OK. */
+00049 #define ERR_MEM  -1      /* Out of memory error.     */
+00050 #define ERR_BUF  -2      /* Buffer error.            */
+00051 
+00052 
+00053 #define ERR_ABRT -3      /* Connection aborted.      */
+00054 #define ERR_RST  -4      /* Connection reset.        */
+00055 #define ERR_CLSD -5      /* Connection closed.       */
+00056 #define ERR_CONN -6      /* Not connected.           */
+00057 
+00058 #define ERR_VAL  -7      /* Illegal value.           */
+00059 
+00060 #define ERR_ARG  -8      /* Illegal argument.        */
+00061 
+00062 #define ERR_RTE  -9      /* Routing problem.         */
+00063 
+00064 #define ERR_USE  -10     /* Address in use.          */
+00065 
+00066 
+00067 
+00068 #ifdef LWIP_DEBUG
+00069 extern char *lwip_strerr(err_t err);
+00070 #else
+00071 #define lwip_strerr(x) ""
+00072 #endif /* LWIP_DEBUG */
+00073 #endif /* __LWIP_ERR_H__ */
+

Generated on Wed Apr 28 17:49:33 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/err_8h.html b/doc/doxygen/html/err_8h.html new file mode 100644 index 0000000..b8166cc --- /dev/null +++ b/doc/doxygen/html/err_8h.html @@ -0,0 +1,341 @@ + + +Ubixos: err.h File Reference + + + +

err.h File Reference

#include <ubixos/types.h>
+#include "net/debug.h"
+#include "net/arch/cc.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define ERR_OK   0
#define ERR_MEM   -1
#define ERR_BUF   -2
#define ERR_ABRT   -3
#define ERR_RST   -4
#define ERR_CLSD   -5
#define ERR_CONN   -6
#define ERR_VAL   -7
#define ERR_ARG   -8
#define ERR_RTE   -9
#define ERR_USE   -10
#define lwip_strerr(x)   ""

Typedefs

typedef Int8 err_t
+


Define Documentation

+

+ + + + +
+ + +
#define ERR_ABRT   -3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_ARG   -8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_BUF   -2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_CLSD   -5 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_CONN   -6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_MEM   -1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_OK   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_RST   -4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_RTE   -9 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_USE   -10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR_VAL   -7 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define lwip_strerr  )    "" +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef Int8 err_t +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ethernetif_8h-source.html b/doc/doxygen/html/ethernetif_8h-source.html new file mode 100644 index 0000000..2748005 --- /dev/null +++ b/doc/doxygen/html/ethernetif_8h-source.html @@ -0,0 +1,54 @@ + + +Ubixos: ethernetif.h Source File + + + +

ethernetif.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __NETIF_ETHERNETIF_H__
+00036 #define __NETIF_ETHERNETIF_H__
+00037 
+00038 #include "net/netif.h"
+00039 
+00040 void ethernetif_init(struct netif *netif);
+00041 
+00042 #endif /* __NETIF_ETHERNETIF_H__ */
+

Generated on Wed Apr 28 17:49:33 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ethernetif_8h.html b/doc/doxygen/html/ethernetif_8h.html new file mode 100644 index 0000000..ca1de6a --- /dev/null +++ b/doc/doxygen/html/ethernetif_8h.html @@ -0,0 +1,51 @@ + + +Ubixos: ethernetif.h File Reference + + + +

ethernetif.h File Reference

#include "net/netif.h"
+ +

+Go to the source code of this file. + + + + +

Functions

void ethernetif_init (struct netif *netif)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void ethernetif_init struct netif netif  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/exec_8h-source.html b/doc/doxygen/html/exec_8h-source.html new file mode 100644 index 0000000..c781d3d --- /dev/null +++ b/doc/doxygen/html/exec_8h-source.html @@ -0,0 +1,45 @@ + + +Ubixos: exec.h Source File + + + +

exec.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _EXEC_H
+00025 #define _EXEC_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <ubixos/sched.h>
+00029 
+00030 uInt32 execThread(void (* tproc)(void),int stack,char *arg,char *descr);
+00031 void execFile(char *file,int argc,char **argv,int console);
+00032 
+00033 #endif
+

Generated on Wed Apr 28 17:49:34 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/exec_8h.html b/doc/doxygen/html/exec_8h.html new file mode 100644 index 0000000..eed44f8 --- /dev/null +++ b/doc/doxygen/html/exec_8h.html @@ -0,0 +1,125 @@ + + +Ubixos: exec.h File Reference + + + +

exec.h File Reference

#include <ubixos/types.h>
+#include <ubixos/sched.h>
+ +

+Go to the source code of this file. + + + + + + +

Functions

uInt32 execThread (void(*tproc)(void), int stack, char *arg, char *descr)
void execFile (char *file, int argc, char **argv, int console)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void execFile char *  file,
int  argc,
char **  argv,
int  console
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
uInt32 execThread void(*  tproc)(void),
int  stack,
char *  arg,
char *  descr
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/fdc_8h-source.html b/doc/doxygen/html/fdc_8h-source.html new file mode 100644 index 0000000..950285b --- /dev/null +++ b/doc/doxygen/html/fdc_8h-source.html @@ -0,0 +1,91 @@ + + +Ubixos: fdc.h Source File + + + +

fdc.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _FDC_H
+00025 #define _FDC_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 typedef struct DrvGeom {
+00030    byte heads;
+00031    byte tracks;
+00032    byte spt;
+00033 } drvGeom;
+00034 
+00035 
+00036 #define fdcMsr  (0x3f4)
+00037 #define fdcData (0x3f5)
+00038 #define fdcDir  (0x3f7)
+00039 #define fdcCcr  (0x3f7)
+00040 #define fdcDor  (0x3f2)
+00041 #define fdcDrs  (0x3f4)
+00042 
+00043 #define cmdWrite   (0xc5)
+00044 #define cmdRead    (0xe6)
+00045 #define cmdSeek    (0x0f)
+00046 #define cmdSensei  (0x08)
+00047 #define cmdRecal   (0x07)
+00048 #define cmdSpecify (0x03)
+00049 
+00050 #define dg144Heads  2     /* heads per drive (1.44M) */
+00051 #define dg144Tracks 80
+00052 #define dg144Spt    18
+00053 #define dg144Gap3rw 0x1b
+00054 #define dg168Gap3rw 0x1c
+00055 
+00056 
+00057 
+00058 void fdcInit();
+00059 void floppyIsr();
+00060 void floppyIsrhndlr();
+00061 void sendByte(int byte);
+00062 int getByte();
+00063 bool fdcRw(int block,byte *blockBuffer,bool read,unsigned long numSectors);
+00064 void block2Hts(int block,int *head,int *track,int *sector);
+00065 void motorOn(void);
+00066 void motorOff(void);
+00067 bool seek(int track);
+00068 bool waitFdc(bool sensei);
+00069 int getByte();
+00070 void sendByte(int byte);
+00071 void recalibrate(void);
+00072 void reset(void);
+00073 bool writeBlock(int block,byte *blockBuffer, unsigned long numSectors);
+00074 bool readBlock(int block,byte *blockBuffer, unsigned long numSectors);
+00075 void fdcWrite(void *info,void *,uInt32 startSector,uInt32 sectorCount);
+00076 void fdcRead(void *info,void *,uInt32 startSector,uInt32 sectorCount);
+00077 
+00078 #endif
+00079 
+

Generated on Wed Apr 28 17:49:34 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/fdc_8h.html b/doc/doxygen/html/fdc_8h.html new file mode 100644 index 0000000..20157ed --- /dev/null +++ b/doc/doxygen/html/fdc_8h.html @@ -0,0 +1,1096 @@ + + +Ubixos: fdc.h File Reference + + + +

fdc.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  DrvGeom

Defines

#define fdcMsr   (0x3f4)
#define fdcData   (0x3f5)
#define fdcDir   (0x3f7)
#define fdcCcr   (0x3f7)
#define fdcDor   (0x3f2)
#define fdcDrs   (0x3f4)
#define cmdWrite   (0xc5)
#define cmdRead   (0xe6)
#define cmdSeek   (0x0f)
#define cmdSensei   (0x08)
#define cmdRecal   (0x07)
#define cmdSpecify   (0x03)
#define dg144Heads   2
#define dg144Tracks   80
#define dg144Spt   18
#define dg144Gap3rw   0x1b
#define dg168Gap3rw   0x1c

Typedefs

typedef DrvGeom drvGeom

Functions

void fdcInit ()
void floppyIsr ()
void floppyIsrhndlr ()
void sendByte (int Int8)
int getByte ()
bool fdcRw (int block, Int8 *blockBuffer, bool read, unsigned long numSectors)
void block2Hts (int block, int *head, int *track, int *sector)
void motorOn (void)
void motorOff (void)
bool seek (int track)
bool waitFdc (bool sensei)
void recalibrate (void)
void reset (void)
bool writeBlock (int block, Int8 *blockBuffer, unsigned long numSectors)
bool readBlock (int block, Int8 *blockBuffer, unsigned long numSectors)
void fdcWrite (void *info, void *, uInt32 startSector, uInt32 sectorCount)
void fdcRead (void *info, void *, uInt32 startSector, uInt32 sectorCount)
+


Define Documentation

+

+ + + + +
+ + +
#define cmdRead   (0xe6) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define cmdRecal   (0x07) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define cmdSeek   (0x0f) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define cmdSensei   (0x08) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define cmdSpecify   (0x03) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define cmdWrite   (0xc5) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dg144Gap3rw   0x1b +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dg144Heads   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dg144Spt   18 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dg144Tracks   80 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dg168Gap3rw   0x1c +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdcCcr   (0x3f7) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdcData   (0x3f5) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdcDir   (0x3f7) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdcDor   (0x3f2) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdcDrs   (0x3f4) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdcMsr   (0x3f4) +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct DrvGeom drvGeom +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void block2Hts int  block,
int *  head,
int *  track,
int *  sector
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void fdcInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void fdcRead void *  info,
void * ,
uInt32  startSector,
uInt32  sectorCount
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool fdcRw int  block,
Int8 blockBuffer,
bool  read,
unsigned long  numSectors
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void fdcWrite void *  info,
void * ,
uInt32  startSector,
uInt32  sectorCount
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void floppyIsr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void floppyIsrhndlr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int getByte  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void motorOff void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void motorOn void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
bool readBlock int  block,
Int8 blockBuffer,
unsigned long  numSectors
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void recalibrate void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void reset void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
bool seek int  track  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void sendByte int  Int8  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
bool waitFdc bool  sensei  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
bool writeBlock int  block,
Int8 blockBuffer,
unsigned long  numSectors
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:19 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/file_8h-source.html b/doc/doxygen/html/file_8h-source.html new file mode 100644 index 0000000..0ee484a --- /dev/null +++ b/doc/doxygen/html/file_8h-source.html @@ -0,0 +1,72 @@ + + +Ubixos: file.h Source File + + + +

file.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _FILE_H
+00025 #define _FILE_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <vfs/vfs.h>
+00029 
+00030 #define SEEK_SET 0x0
+00031 
+00032 struct taskFileInfo {
+00033   char *cwd;
+00034   };
+00035 
+00036 typedef struct userFileDescriptorStruct {
+00037   struct fileDescriptorStruct *fd;
+00038   uInt32 fdSize;
+00039   } userFileDescriptor;
+00040 
+00041 extern fileDescriptor *fdTable;
+00042 extern fileDescriptor *lastFd;
+00043 
+00044 fileDescriptor *fopen(const char *file,const char *flags);
+00045 int unlink(const char *path);
+00046 int fclose(fileDescriptor *fd);
+00047 int feof(fileDescriptor *fd);
+00048 int fgetc(fileDescriptor *fd);
+00049 size_t fread(void *ptr, size_t size, size_t nmemb,fileDescriptor *fd);
+00050 size_t fwrite(void *ptr,int size,int nmemb,fileDescriptor *fd);
+00051 int fseek(fileDescriptor *,long,int);
+00052 
+00053 void sysFseek(userFileDescriptor *,long,int);
+00054 
+00055 //Good
+00056 void sysChDir(const char *path);
+00057 void chDir(const char *path);
+00058 char *verifyDir(const char *path);
+00059 
+00060 #endif
+

Generated on Wed Apr 28 17:49:34 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/file_8h.html b/doc/doxygen/html/file_8h.html new file mode 100644 index 0000000..9cf7ad1 --- /dev/null +++ b/doc/doxygen/html/file_8h.html @@ -0,0 +1,581 @@ + + +Ubixos: file.h File Reference + + + +

file.h File Reference

#include <ubixos/types.h>
+#include <vfs/vfs.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  taskFileInfo
struct  userFileDescriptorStruct

Defines

#define SEEK_SET   0x0

Typedefs

typedef userFileDescriptorStruct userFileDescriptor

Functions

fileDescriptorfopen (const char *file, const char *flags)
int unlink (const char *path)
int fclose (fileDescriptor *fd)
int feof (fileDescriptor *fd)
int fgetc (fileDescriptor *fd)
size_t fread (void *ptr, size_t size, size_t nmemb, fileDescriptor *fd)
size_t fwrite (void *ptr, int size, int nmemb, fileDescriptor *fd)
int fseek (fileDescriptor *, long, int)
void sysFseek (userFileDescriptor *, long, int)
void sysChDir (const char *path)
void chDir (const char *path)
char * verifyDir (const char *path)

Variables

fileDescriptorfdTable
fileDescriptorlastFd
+


Define Documentation

+

+ + + + +
+ + +
#define SEEK_SET   0x0 +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct userFileDescriptorStruct userFileDescriptor +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void chDir const char *  path  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int fclose fileDescriptor fd  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int feof fileDescriptor fd  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int fgetc fileDescriptor fd  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
fileDescriptor* fopen const char *  file,
const char *  flags
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
size_t fread void *  ptr,
size_t  size,
size_t  nmemb,
fileDescriptor fd
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int fseek fileDescriptor,
long ,
int 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
size_t fwrite void *  ptr,
int  size,
int  nmemb,
fileDescriptor fd
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void sysChDir const char *  path  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void sysFseek userFileDescriptor,
long ,
int 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int unlink const char *  path  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
char* verifyDir const char *  path  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
fileDescriptor* fdTable +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
fileDescriptor* lastFd +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/files.html b/doc/doxygen/html/files.html new file mode 100644 index 0000000..d118a33 --- /dev/null +++ b/doc/doxygen/html/files.html @@ -0,0 +1,111 @@ + + +Ubixos: File Index + + + +

Ubixos File List

Here is a list of all documented files with brief descriptions: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
8259.h [code]
_types.h [code]
api.h [code]
api_msg.h [code]
arch.h [code]
arp.h [code]
atkbd.h [code]
bioscall.h [code]
btxv86.h [code]
cc.h [code]
cdefs.h [code]
cpu.h [code]
debug.h [code]
def.h [code]
devfs.h [code]
device.h [code]
device.old.h [code]
disklabel.h [code]
diskslice.h [code]
dma.h [code]
driver.h [code]
elf.h [code]
err.h [code]
ethernetif.h [code]
exec.h [code]
fdc.h [code]
file.h [code]
fork.h [code]
gdt.h [code]
hd.h [code]
ipv4/icmp.h [code]
ipv6/icmp.h [code]
idletask.h [code]
idt.h [code]
ipv4/inet.h [code]
ipv6/inet.h [code]
init.h [code]
io.h [code]
ipv4/ip.h [code]
ipv6/ip.h [code]
ipv4/ip_addr.h [code]
ipv6/ip_addr.h [code]
kmalloc.h [code]
kpanic.h [code]
kprint.h [code]
kprintf.h [code]
ld.h [code]
boot/boot2/lib.h [code]
include/net/arch/lib.h [code]
libcpp.h [code]
list.h [code]
lnc.h [code]
loopif.h [code]
lwipopts.h [code]
math.h [code]
mem.h [code]
memp.h [code]
mount.h [code]
ne2k.h [code]
net.h [code]
netif.h [code]
ogDisplay_UbixOS.h [code]
ogDisplay_VESA.h [code]
opt.h [code]
paging.h [code]
pbuf.h [code]
pci.h [code]
perf.h [code]
pit.h [code]
sched.h [code]
sde.h [code]
shell.h [code]
sockets.h [code]
stats.h [code]
stdarg.h [code]
lib/string.h [code]
string.h [code]
sys.h [code]
sys_arch.h [code]
syscall.h [code]
syscalls.h [code]
tcp.h [code]
tcpdump.h [code]
tcpip.h [code]
time.h [code]
times.h [code]
tss.h [code]
types.h [code]
boot/boot2/ubixfs.h [code]
include/ubixfs/ubixfs.h [code]
ubthread.h [code]
udp.h [code]
udpecho.h [code]
vfs.h [code]
video.h [code]
vitals.h [code]
vmm.h [code]
+
Generated on Wed Apr 28 17:49:27 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/fork_8h-source.html b/doc/doxygen/html/fork_8h-source.html new file mode 100644 index 0000000..0a52ad3 --- /dev/null +++ b/doc/doxygen/html/fork_8h-source.html @@ -0,0 +1,47 @@ + + +Ubixos: fork.h Source File + + + +

fork.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _FORK_H
+00025 #define _FORK_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <ubixos/sched.h>
+00029 
+00030 void sysFork();
+00031 
+00032 int forkCopyProcess(struct taskStruct *newProcess,long ebp,long edi,long esi,long none,long ebx,long ecx,long edx,long eip,long cs,long eflags,long esp,long ss);
+00033 
+00034 #endif
+00035 
+

Generated on Wed Apr 28 17:49:34 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/fork_8h.html b/doc/doxygen/html/fork_8h.html new file mode 100644 index 0000000..b1eb4d5 --- /dev/null +++ b/doc/doxygen/html/fork_8h.html @@ -0,0 +1,157 @@ + + +Ubixos: fork.h File Reference + + + +

fork.h File Reference

#include <ubixos/types.h>
+#include <ubixos/sched.h>
+ +

+Go to the source code of this file. + + + + + + +

Functions

void sysFork ()
int forkCopyProcess (struct taskStruct *newProcess, long ebp, long edi, long esi, long none, long ebx, long ecx, long edx, long eip, long cs, long eflags, long esp, long ss)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int forkCopyProcess struct taskStruct newProcess,
long  ebp,
long  edi,
long  esi,
long  none,
long  ebx,
long  ecx,
long  edx,
long  eip,
long  cs,
long  eflags,
long  esp,
long  ss
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFork  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/functions.html b/doc/doxygen/html/functions.html new file mode 100644 index 0000000..a308daa --- /dev/null +++ b/doc/doxygen/html/functions.html @@ -0,0 +1,579 @@ + + +Ubixos: Compound Member Index + + + +
All | Functions | Variables
+
_ | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | r | s | t | u | v | w | y | ~
+ +

+ +

+Here is a list of all struct and union fields with links to the structures/unions they belong to:

- _ - +

+

- a - +

+

- b - +

+

- c - +

+

- d - +

+

- e - +

+

- f - +

+

- g - +

+

- h - +

+

- i - +

+

- j - +

+

- k - +

+

- l - +

+

- m - +

+

- n - +

+

- o - +

+

- p - +

+

- r - +

+

- s - +

+

- t - +

+

- u - +

+

- v - +

+

- w - +

+

- y - +

+

- ~ - +

+
Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/functions_func.html b/doc/doxygen/html/functions_func.html new file mode 100644 index 0000000..602e3bc --- /dev/null +++ b/doc/doxygen/html/functions_func.html @@ -0,0 +1,92 @@ + + +Ubixos: Compound Member Index + + + +
All | Functions | Variables
+
_ | a | c | f | g | l | o | p | r | s | ~
+ +

+ +

+

- _ - +

+

- a - +

+

- c - +

+

- f - +

+

- g - +

+

- l - +

+

- o - +

+

- p - +

+

- r - +

+

- s - +

+

- ~ - +

+
Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/functions_vars.html b/doc/doxygen/html/functions_vars.html new file mode 100644 index 0000000..9949359 --- /dev/null +++ b/doc/doxygen/html/functions_vars.html @@ -0,0 +1,532 @@ + + +Ubixos: Compound Member Index + + + +
All | Functions | Variables
+
a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | r | s | t | u | v | w | y
+ +

+ +

+

- a - +

+

- b - +

+

- c - +

+

- d - +

+

- e - +

+

- f - +

+

- g - +

+

- h - +

+

- i - +

+

- j - +

+

- k - +

+

- l - +

+

- m - +

+

- n - +

+

- o - +

+

- p - +

+

- r - +

+

- s - +

+

- t - +

+

- u - +

+

- v - +

+

- w - +

+

- y - +

+
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/gdt_8h-source.html b/doc/doxygen/html/gdt_8h-source.html new file mode 100644 index 0000000..10bc52d --- /dev/null +++ b/doc/doxygen/html/gdt_8h-source.html @@ -0,0 +1,100 @@ + + +Ubixos: gdt.h Source File + + + +

gdt.h

00001 
+00002 
+00003 
+00004 /**************************************************************************************
+00005  Copyright (c) 2002 The UbixOS Project
+00006  All rights reserved.
+00007 
+00008 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00009 
+00010 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00011 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00012 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00013 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00014 
+00015 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00016 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00017 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00018 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00019 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00020 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00021 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00022 
+00023  $Id$
+00024 
+00025 **************************************************************************************/
+00026 
+00027 #ifndef _GDT_H
+00028 #define _GDT_H
+00029 
+00030 /* Descriptor Definitions */
+00031 #define dCall 0x0C00 /* 386 Call Gate                */
+00032 #define dCode 0x1800 /* Code Segment                 */
+00033 #define dData 0x1000 /* Data Segment                 */
+00034 #define dInt  0x0E00 /* 386 Interrupt Gate           */
+00035 #define dLdt  0x200  /* Local Descriptor Table (LDT) */
+00036 #define dTask 0x500  /* Task gate                    */
+00037 #define dTrap 0x0F00 /* 386 Trap Gate                */
+00038 #define dTss  0x900  /* Task State Segment (TSS)     */
+00039 
+00040 /* Descriptor Options */
+00041 #define dDpl3     0x6000 /* DPL3 or mask for DPL             */
+00042 #define dDpl2     0x4000 /* DPL2 or mask for DPL             */
+00043 #define dDpl1     0x2000 /* DPL1 or mask for DPL             */
+00044 #define dPresent  0x8000 /* Present                          */
+00045 #define dNpresent 0x8000 /* Not Present                      */
+00046 #define dAcc      0x100  /* Accessed (Data or Code)          */
+00047 #define dWrite    0x200  /* Writable (Data segments only)    */
+00048 #define dRead     0x200  /* Readable (Code segments only)    */
+00049 #define dBusy     0xB00  /* Busy (TSS only)    was 200       */
+00050 #define dEexdown  0x400  /* Expand down (Data segments only) */
+00051 #define dConform  0x400  /* Conforming (Code segments only)  */
+00052 #define dBig      0x40   /* Default to 32 bit mode           */
+00053 #define dBiglim   0x80   /* Limit is in 4K units             */
+00054 
+00055 /* GDT Descriptor */
+00056 struct gdtDescriptor {
+00057   unsigned short limitLow;      /* Limit 0..15    */
+00058   unsigned short baseLow;       /* Base  0..15    */
+00059   unsigned char  baseMed;       /* Base  16..23   */
+00060   unsigned char  access;        /* Access Byte    */
+00061   unsigned int   limitHigh:4;   /* Limit 16..19   */
+00062   unsigned int   granularity:4; /* Granularity    */
+00063   unsigned char  baseHigh;      /* Base 24..31    */
+00064   } __attribute__ ((packed));
+00065 
+00066 struct gdtGate {
+00067   unsigned short offsetLow;  /* Offset 0..15  */
+00068   unsigned short selector;   /* Selector      */
+00069   unsigned short access;     /* Access Flags  */
+00070   unsigned short offsetHigh; /* Offset 16..31 */
+00071   } __attribute__ ((packed));
+00072 
+00073 union descriptorTableunion {
+00074   struct gdtDescriptor descriptor; /* Normal descriptor */
+00075   struct gdtGate gate;             /* Gate descriptor   */
+00076   unsigned long dummy;             /* Any other info    */
+00077   };
+00078 
+00079 
+00080 #define descriptorTable(name,length) union descriptorTableunion name[length] =
+00081 #define standardDescriptor(base, limit, control) {descriptor: {(limit & 0xffff), (base & 0xffff), ((base >> 16) & 0xff), \
+00082                                                ((control+dPresent) >> 8), (limit >> 16), \
+00083                                                ((control & 0xff) >> 4), (base >> 24)}}
+00084 #define gateDescriptor(offset, selector, control) {gate: {(offset & 0xffff), selector, \
+00085                                                      (control+dPresent), (offset >> 16) }}
+00086 
+00087 #endif
+00088 
+

Generated on Wed Apr 28 17:49:34 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/gdt_8h.html b/doc/doxygen/html/gdt_8h.html new file mode 100644 index 0000000..aa50482 --- /dev/null +++ b/doc/doxygen/html/gdt_8h.html @@ -0,0 +1,668 @@ + + +Ubixos: gdt.h File Reference + + + +

gdt.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

union  descriptorTableUnion
struct  gdtDescriptor
struct  gdtGate

Defines

#define dCall   0x0C00
#define dCode   0x1800
#define dData   0x1000
#define dInt   0x0E00
#define dLdt   0x200
#define dTask   0x500
#define dTrap   0x0F00
#define dTss   0x900
#define dDpl3   0x6000
#define dDpl2   0x4000
#define dDpl1   0x2000
#define dPresent   0x8000
#define dNpresent   0x8000
#define dAcc   0x100
#define dWrite   0x200
#define dRead   0x200
#define dBusy   0xB00
#define dEexdown   0x400
#define dConform   0x400
#define dBig   0x40
#define dBiglim   0x80
#define ubixDescriptorTable(name, length)   union descriptorTableUnion name[length] =
#define ubixStandardDescriptor(base, limit, control)
#define ubixGateDescriptor(offset, selector, control)

Variables

gdtDescriptor packed
+


Define Documentation

+

+ + + + +
+ + +
#define dAcc   0x100 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dBig   0x40 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dBiglim   0x80 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dBusy   0xB00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dCall   0x0C00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dCode   0x1800 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dConform   0x400 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dData   0x1000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dDpl1   0x2000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dDpl2   0x4000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dDpl3   0x6000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dEexdown   0x400 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dInt   0x0E00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dLdt   0x200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dNpresent   0x8000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dPresent   0x8000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dRead   0x200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dTask   0x500 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dTrap   0x0F00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dTss   0x900 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define dWrite   0x200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define ubixDescriptorTablename,
length   )    union descriptorTableUnion name[length] = +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + +
#define ubixGateDescriptoroffset,
selector,
control   )  +
+
+ + + + + +
+   + + +

+Value:

{gate: {(offset & 0xffff), selector, \
+                                                     (control+dPresent), (offset >> 16) }}
+
+

+ + + + +
+ + + + + + + + + + + + + +
#define ubixStandardDescriptorbase,
limit,
control   )  +
+
+ + + + + +
+   + + +

+Value:

{descriptor: \
+                                               {(limit & 0xffff), \
+                                               (base & 0xffff), \
+                                               ((base >> 16) & 0xff), \
+                                               ((control+dPresent) >> 8), \
+                                               (limit >> 16), \
+                                               ((control & 0xff) >> 4), \
+                                               (base >> 24)}}
+
+


Variable Documentation

+

+ + + + +
+ + +
struct gdtGate packed +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/globals.html b/doc/doxygen/html/globals.html new file mode 100644 index 0000000..2082413 --- /dev/null +++ b/doc/doxygen/html/globals.html @@ -0,0 +1,1187 @@ + + +Ubixos: File Member Index + + + +
All | Functions | Variables | Typedefs | Enumerations | Enumeration values | Defines
+
_ | a | b | c | d | e | f | g | h | i | k | l | m | n | o | p | q | r | s | t | u | v | w | y
+ +

+ +

+Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- _ - +

+

- a - +

+

- b - +

+

- c - +

+

- d - +

+

- e - +

+

- f - +

+

- g - +

+

- h - +

+

- i - +

+

- k - +

+

- l - +

+

- m - +

+

- n - +

+

- o - +

+

- p - +

+

- q - +

+

- r - +

+

- s - +

+

- t - +

+

- u - +

+

- v - +

+

- w - +

+

- y - +

+
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/globals_defs.html b/doc/doxygen/html/globals_defs.html new file mode 100644 index 0000000..7bbcdc7 --- /dev/null +++ b/doc/doxygen/html/globals_defs.html @@ -0,0 +1,610 @@ + + +Ubixos: File Member Index + + + +
All | Functions | Variables | Typedefs | Enumerations | Enumeration values | Defines
+
_ | a | b | c | d | e | f | h | i | k | l | m | n | o | p | r | s | t | u | v | w | y
+ +

+ +

+

- _ - +

+

- a - +

+

- b - +

+

- c - +

+

- d - +

+

- e - +

+

- f - +

+

- h - +

+

- i - +

+

- k - +

+

- l - +

+

- m - +

+

- n - +

+

- o - +

+

- p - +

+

- r - +

+

- s - +

+

- t - +

+

- u - +

+

- v - +

+

- w - +

+

- y - +

+
Generated on Sat May 8 09:28:27 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/globals_enum.html b/doc/doxygen/html/globals_enum.html new file mode 100644 index 0000000..16f3a5e --- /dev/null +++ b/doc/doxygen/html/globals_enum.html @@ -0,0 +1,29 @@ + + +Ubixos: File Member Index + + + +
All | Functions | Variables | Typedefs | Enumerations | Enumeration values | Defines
+ +

+

+
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/globals_eval.html b/doc/doxygen/html/globals_eval.html new file mode 100644 index 0000000..9d00962 --- /dev/null +++ b/doc/doxygen/html/globals_eval.html @@ -0,0 +1,124 @@ + + +Ubixos: File Member Index + + + +
All | Functions | Variables | Typedefs | Enumerations | Enumeration values | Defines
+
a | c | d | e | f | i | l | m | n | p | r | s | t
+ +

+ +

+

- a - +

+

- c - +

+

- d - +

+

- e - +

+

- f - +

+

- i - +

+

- l - +

+

- m - +

+

- n - +

+

- p - +

+

- r - +

+

- s - +

+

- t - +

+
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/globals_func.html b/doc/doxygen/html/globals_func.html new file mode 100644 index 0000000..1066fd2 --- /dev/null +++ b/doc/doxygen/html/globals_func.html @@ -0,0 +1,512 @@ + + +Ubixos: File Member Index + + + +
All | Functions | Variables | Typedefs | Enumerations | Enumeration values | Defines
+
_ | a | b | c | d | e | f | g | h | i | k | l | m | n | o | p | r | s | t | u | v | w
+ +

+ +

+

- _ - +

+

- a - +

+

- b - +

+

- c - +

+

- d - +

+

- e - +

+

- f - +

+

- g - +

+

- h - +

+

- i - +

+

- k - +

+

- l - +

+

- m - +

+

- n - +

+

- o - +

+

- p - +

+

- r - +

+

- s - +

+

- t - +

+

- u - +

+

- v - +

+

- w - +

+
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/globals_type.html b/doc/doxygen/html/globals_type.html new file mode 100644 index 0000000..1cb544b --- /dev/null +++ b/doc/doxygen/html/globals_type.html @@ -0,0 +1,97 @@ + + +Ubixos: File Member Index + + + +
All | Functions | Variables | Typedefs | Enumerations | Enumeration values | Defines
+
_ | c | d | e | f | i | k | m | p | q | s | t | u | v
+ +

+ +

+

- _ - +

+

- c - +

+

- d - +

+

- e - +

+

- f - +

+

- i - +

+

- k - +

+

- m - +

+

- p - +

+

- q - +

+

- s - +

+

- t - +

+

- u - +

+

- v - +

+
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/globals_vars.html b/doc/doxygen/html/globals_vars.html new file mode 100644 index 0000000..bb7cd53 --- /dev/null +++ b/doc/doxygen/html/globals_vars.html @@ -0,0 +1,101 @@ + + +Ubixos: File Member Index + + + +
All | Functions | Variables | Typedefs | Enumerations | Enumeration values | Defines
+
_ | e | f | h | i | k | l | m | n | o | p | s | t | v | w
+ +

+ +

+

- _ - +

+

- e - +

+

- f - +

+

- h - +

+

- i - +

+

- k - +

+

- l - +

+

- m - +

+

- n - +

+

- o - +

+

- p - +

+

- s - +

+

- t - +

+

- v - +

+

- w - +

+
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/hd_8h-source.html b/doc/doxygen/html/hd_8h-source.html new file mode 100644 index 0000000..f08c333 --- /dev/null +++ b/doc/doxygen/html/hd_8h-source.html @@ -0,0 +1,59 @@ + + +Ubixos: hd.h Source File + + + +

hd.h

00001 #include <ubixfs/ubixfs.h>
+00002 
+00003 #ifndef _HD_H
+00004 #define _HD_H
+00005 
+00006 #define hdData     0x0
+00007 #define hdError    0x1
+00008 #define hdSecCount 0x2
+00009 #define hdSecNum   0x3
+00010 #define hdCylLow   0x4
+00011 #define hdCylHi    0x5
+00012 #define hdHead     0x6
+00013 #define hdStat     0x7
+00014 #define hdCmd      0x7
+00015 
+00016 
+00017 struct driveInfo {
+00018   struct driveDiskLabel *diskLabel;
+00019   char hdSector[512];
+00020   char hdEnable;
+00021   char hdDev;
+00022   char hdFlags;
+00023   char hdShift;
+00024   long hdMask;
+00025   long hdMulti;
+00026   long hdPort;
+00027   long hdSize;
+00028   long hdCalc;
+00029   };
+00030 
+00031 void initHardDisk();
+00032 void hdWrite(struct driveInfo *hdd,void *,uInt32,uInt32);
+00033 void hdRead(struct driveInfo *hdd,void *,uInt32,uInt32);
+00034 int hdReset();
+00035 int hdIoctl();
+00036 int hdStart();
+00037 int hdStop();
+00038 int hdStandby();
+00039 int hdInit(struct deviceNode *dev);
+00040 
+00041 extern struct driveInfo *hdd0;
+00042 extern struct driveInfo *hdd1;
+00043 extern struct driveInfo *hdd2;
+00044 extern struct driveInfo *hdd3;
+00045 
+00046 #endif
+00047 
+

Generated on Wed Apr 28 17:49:34 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/hd_8h.html b/doc/doxygen/html/hd_8h.html new file mode 100644 index 0000000..9517590 --- /dev/null +++ b/doc/doxygen/html/hd_8h.html @@ -0,0 +1,654 @@ + + +Ubixos: hd.h File Reference + + + +

hd.h File Reference

#include <ubixfs/ubixfs.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  driveInfo

Defines

#define hdData   0x0
#define hdError   0x1
#define hdSecCount   0x2
#define hdSecNum   0x3
#define hdCylLow   0x4
#define hdCylHi   0x5
#define hdHead   0x6
#define hdStat   0x7
#define hdCmd   0x7

Functions

void initHardDisk ()
void hdWrite (struct driveInfo *hdd, void *, uInt32, uInt32)
void hdRead (struct driveInfo *hdd, void *, uInt32, uInt32)
int hdReset ()
int hdIoctl ()
int hdStart ()
int hdStop ()
int hdStandby ()
int hdInit (struct deviceNode *dev)

Variables

driveInfohdd0
driveInfohdd1
driveInfohdd2
driveInfohdd3
+


Define Documentation

+

+ + + + +
+ + +
#define hdCmd   0x7 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdCylHi   0x5 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdCylLow   0x4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdData   0x0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdError   0x1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdHead   0x6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdSecCount   0x2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdSecNum   0x3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define hdStat   0x7 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
int hdInit struct deviceNode dev  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int hdIoctl  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void hdRead struct driveInfo hdd,
void * ,
uInt32 ,
uInt32 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int hdReset  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int hdStandby  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int hdStart  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int hdStop  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void hdWrite struct driveInfo hdd,
void * ,
uInt32 ,
uInt32 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void initHardDisk  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct driveInfo* hdd0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct driveInfo* hdd1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct driveInfo* hdd2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct driveInfo* hdd3 +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/idletask_8h-source.html b/doc/doxygen/html/idletask_8h-source.html new file mode 100644 index 0000000..aa4b856 --- /dev/null +++ b/doc/doxygen/html/idletask_8h-source.html @@ -0,0 +1,44 @@ + + +Ubixos: idletask.h Source File + + + +

idletask.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _IDLETASK_H
+00025 #define _IDLETASK_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 void idleTask();
+00030 
+00031 #endif
+00032 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/idletask_8h.html b/doc/doxygen/html/idletask_8h.html new file mode 100644 index 0000000..70e683c --- /dev/null +++ b/doc/doxygen/html/idletask_8h.html @@ -0,0 +1,50 @@ + + +Ubixos: idletask.h File Reference + + + +

idletask.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + +

Functions

void idleTask ()
+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void idleTask  ) 
+
+ + + + + +
+   + + +

+Function for thread that performs idle task

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/idt_8h-source.html b/doc/doxygen/html/idt_8h-source.html new file mode 100644 index 0000000..958900c --- /dev/null +++ b/doc/doxygen/html/idt_8h-source.html @@ -0,0 +1,69 @@ + + +Ubixos: idt.h Source File + + + +

idt.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _IDT_H
+00025 #define _IDT_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <sys/gdt.h>
+00029 
+00030 #define EFLAG_TF         0x100
+00031 #define EFLAG_IF         0x200
+00032 #define EFLAG_IOPL3      0x3000
+00033 #define EFLAG_VM         0x20000
+00034 
+00035 int idtInit();
+00036 void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor);
+00037 void setTaskVector(uInt8 interrupt,uInt16 controlMajor,uInt8 selector);
+00038 void intNull();
+00039 
+00040 void _int0();
+00041 void _int1();
+00042 void _int2();
+00043 void _int3();
+00044 void _int4();
+00045 void _int5();
+00046 void _int6();
+00047 void _int7();
+00048 void _int8();
+00049 void _int9();
+00050 void _int10();
+00051 void _int11();
+00052 void _int12();
+00053 void _int13();
+00054 void timerInt();
+00055 
+00056 #endif
+00057 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/idt_8h.html b/doc/doxygen/html/idt_8h.html new file mode 100644 index 0000000..a05fcbb --- /dev/null +++ b/doc/doxygen/html/idt_8h.html @@ -0,0 +1,721 @@ + + +Ubixos: idt.h File Reference + + + +

idt.h File Reference

#include <ubixos/types.h>
+#include <sys/gdt.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define EFLAG_TF   0x100
#define EFLAG_IF   0x200
#define EFLAG_IOPL3   0x3000
#define EFLAG_VM   0x20000

Functions

int idtInit ()
void setVector (void *handler, unsigned char interrupt, unsigned short controlMajor)
void setTaskVector (uInt8 interrupt, uInt16 controlMajor, uInt8 selector)
void intNull ()
void _int0 ()
void _int1 ()
void _int2 ()
void _int3 ()
void _int4 ()
void _int5 ()
void _int6 ()
void _int7 ()
void _int8 ()
void _int9 ()
void _int10 ()
void _int11 ()
void _int12 ()
void _int13 ()
void timerInt ()
+


Define Documentation

+

+ + + + +
+ + +
#define EFLAG_IF   0x200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EFLAG_IOPL3   0x3000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EFLAG_TF   0x100 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EFLAG_VM   0x20000 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void _int0  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int1  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int10  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int11  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int12  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int13  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int2  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int3  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int4  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int5  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int6  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int7  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int8  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void _int9  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int idtInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void intNull  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void setTaskVector uInt8  interrupt,
uInt16  controlMajor,
uInt8  selector
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void setVector void *  handler,
unsigned char  interrupt,
unsigned short  controlMajor
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void timerInt  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/include_2net_2arch_2lib_8h-source.html b/doc/doxygen/html/include_2net_2arch_2lib_8h-source.html new file mode 100644 index 0000000..b78c219 --- /dev/null +++ b/doc/doxygen/html/include_2net_2arch_2lib_8h-source.html @@ -0,0 +1,59 @@ + + +Ubixos: lib.h Source File + + + +

lib.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __ARCH_LIB_H__
+00036 #define __ARCH_LIB_H__
+00037 
+00038 #ifndef _STRING_H_
+00039 #ifndef _STRING_H
+00040 int strlen(const char *str);
+00041 int strncmp(const char *str1, const char *str2, int len);
+00042 void bcopy(const void *src, void *dest, int len);
+00043 void bzero(void *data, int n);
+00044 #endif /* _STRING_H */
+00045 #endif /* _STRING_H_ */
+00046 
+00047 #endif /* __ARCH_LIB_H__ */
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/include_2ubixfs_2ubixfs_8h-source.html b/doc/doxygen/html/include_2ubixfs_2ubixfs_8h-source.html new file mode 100644 index 0000000..10ce25f --- /dev/null +++ b/doc/doxygen/html/include_2ubixfs_2ubixfs_8h-source.html @@ -0,0 +1,137 @@ + + +Ubixos: ubixfs.h Source File + + + +

ubixfs.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _UBIXFS_H
+00025 #define _UBIXFS_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <sys/device.h>
+00029 #include <vfs/file.h>
+00030 
+00031 #define UBIXDISKMAGIC     ((uInt32)0x45) /* The disk magic number */
+00032 #define MAXPARTITIONS     4
+00033 #define blockSize         8
+00034 #define blockByteSize     blockSize*512
+00035 
+00036 #define EOBC              -1
+00037 
+00038 
+00039 #define typeFile      1
+00040 #define typeContainer 2
+00041 #define typeDirectory 4
+00042 #define typeDeleted   8
+00043 
+00044 //Partition Information
+00045 struct ubixDiskLabel {
+00046   uInt32 magicNum;
+00047   uInt32 magicNum2;
+00048   uInt16 driveType;
+00049   uInt16 numPartitions;
+00050   struct  drivePartitions {  //the partition table
+00051     uInt32 pSize;            //number of sectors in partition
+00052     uInt32 pOffset;          //starting sector
+00053     uInt32 pFsSize;          //filesystem basic fragment size
+00054     uInt32 pBatSize;         //BAT size
+00055     uInt8  pFsType;          //filesystem type, see below
+00056     uInt8 pFrag;            //filesystem fragments per block
+00057     } partitions[MAXPARTITIONS];
+00058   };
+00059 
+00060 struct partitionInformation {
+00061   uInt32 size;                 //Size In Sectors
+00062   uInt32 startSector;          //Base Sector Of Partition
+00063   uInt32 blockAllocationTable; //Base Sector Of BAT
+00064   uInt32 rootDirectory;        //Base Sector Of Root Directory
+00065   };
+00066 
+00067 //Block Allocation Table Entry
+00068 struct blockAllocationTableEntry {
+00069   long attributes; //Block Attributes
+00070   long realSector; //Real Sector  
+00071   long nextBlock;  //Sector Of Next Block
+00072   long reserved;   //Reserved
+00073   };
+00074 
+00075 //UbixFS Directory Entry
+00076 struct directoryEntry {
+00077   uInt32  startCluster;   //Starting Cluster Of File
+00078   uInt32  size;           //Size Of File
+00079   uInt32  creationDate;  //Date Created
+00080   uInt32  lastModified;  //Date Last Modified
+00081   uInt32  uid;           //UID Of Owner
+00082   uInt32  gid;           //GID Of Owner
+00083   uShort attributes;    //Files Attributes
+00084   uShort permissions;   //Files Permissions
+00085   char   fileName[256]; //File Name
+00086   };
+00087 
+00088 struct bootSect {
+00089   uChar jmp[4];
+00090   uChar id[6];
+00091   uShort version;
+00092   uShort tmp;
+00093   uShort fsStart;
+00094   uShort tmp2;
+00095   uInt32 krnl_start;
+00096   uInt BytesPerSector;
+00097   uInt SectersPerTrack;
+00098   uInt TotalHeads;
+00099   uInt32 TotalSectors;
+00100   uChar code[479];
+00101   };  
+00102 
+00103 struct ubixFsInfo {
+00104   struct blockAllocationTableEntry *blockAllocationTable;
+00105   uInt32 batEntries;
+00106   };
+00107 
+00108 int readFile(char *file);
+00109 int writeFileByte(int ch,fileDescriptor *fd,long offset);
+00110 int openFileUbixFS(char *file,fileDescriptor *fd);
+00111 int mkDirUbixFS(char *dir,fileDescriptor *fd);
+00112 int getFreeBlocks(int count,fileDescriptor *fd);
+00113 //extern struct ubixDiskLabel *diskLabel;
+00114 
+00115 //Good Functions
+00116 void initUbixFS(struct mountPoints *mp);
+00117 int enableUbixFS();
+00118 int readUbixFS(fileDescriptor *fd,char *data,long offset,long size);
+00119 int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size);
+00120 void syncBat(struct mountPoints *mp);
+00121 int freeBlocks(int block,fileDescriptor *fd);
+00122 int addDirEntry(struct directoryEntry *dir,fileDescriptor *fd);
+00123 void ubixFSUnlink(char *path,struct mountPoints *mp);
+00124 
+00125 #endif
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/index.html b/doc/doxygen/html/index.html new file mode 100644 index 0000000..e05dc4a --- /dev/null +++ b/doc/doxygen/html/index.html @@ -0,0 +1,16 @@ + + +Ubixos: Main Page + + + +

Ubixos Documentation

+

+

+
Generated on Wed Apr 28 17:49:27 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/init_8h-source.html b/doc/doxygen/html/init_8h-source.html new file mode 100644 index 0000000..321a851 --- /dev/null +++ b/doc/doxygen/html/init_8h-source.html @@ -0,0 +1,56 @@ + + +Ubixos: init.h Source File + + + +

init.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __ARCH_INIT_H__
+00036 #define __ARCH_INIT_H__
+00037 
+00038 #define TCPIP_INIT_DONE(arg) sys_sem_signal(*(sys_sem_t *)arg)
+00039 
+00040 #endif /* __ARCH_INIT_H__ */
+00041 
+00042 
+00043 
+00044 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/init_8h.html b/doc/doxygen/html/init_8h.html new file mode 100644 index 0000000..b3adff2 --- /dev/null +++ b/doc/doxygen/html/init_8h.html @@ -0,0 +1,48 @@ + + +Ubixos: init.h File Reference + + + +

init.h File Reference

+

+Go to the source code of this file. + + + + +

Defines

#define TCPIP_INIT_DONE(arg)   sys_sem_signal(*(sys_sem_t *)arg)
+


Define Documentation

+

+ + + + +
+ + + + + + + +
#define TCPIP_INIT_DONEarg   )    sys_sem_signal(*(sys_sem_t *)arg) +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/io_8h-source.html b/doc/doxygen/html/io_8h-source.html new file mode 100644 index 0000000..f5dc2f6 --- /dev/null +++ b/doc/doxygen/html/io_8h-source.html @@ -0,0 +1,48 @@ + + +Ubixos: io.h Source File + + + +

io.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _IO_H
+00025 #define _IO_H
+00026 
+00027 inline unsigned char inportByte(unsigned int);
+00028 inline unsigned short inportWord(unsigned int);
+00029 inline unsigned long  inportDWord(unsigned int);
+00030 inline void outportByte(unsigned int,unsigned char);
+00031 inline void outportByteP(unsigned int port,unsigned char value);
+00032 inline void outportWord(unsigned int,unsigned short);
+00033 inline void outportDWord(unsigned int port,unsigned long value);
+00034 
+00035 #endif
+00036 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/io_8h.html b/doc/doxygen/html/io_8h.html new file mode 100644 index 0000000..a11053b --- /dev/null +++ b/doc/doxygen/html/io_8h.html @@ -0,0 +1,272 @@ + + +Ubixos: io.h File Reference + + + +

io.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + + + +

Functions

unsigned char inportByte (unsigned int)
unsigned short inportWord (unsigned int)
unsigned long inportDWord (unsigned int)
void outportByte (unsigned int, unsigned char)
void outportByteP (unsigned int port, unsigned char value)
void outportWord (unsigned int, unsigned short)
void outportDWord (unsigned int port, unsigned long value)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
unsigned char inportByte unsigned  int  )  [inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
unsigned long inportDWord unsigned  int  )  [inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
unsigned short inportWord unsigned  int  )  [inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void outportByte unsigned  int,
unsigned  char
[inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void outportByteP unsigned int  port,
unsigned char  value
[inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void outportDWord unsigned int  port,
unsigned long  value
[inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void outportWord unsigned  int,
unsigned  short
[inline]
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2icmp_8h-source.html b/doc/doxygen/html/ipv4_2icmp_8h-source.html new file mode 100644 index 0000000..94e52e0 --- /dev/null +++ b/doc/doxygen/html/ipv4_2icmp_8h-source.html @@ -0,0 +1,116 @@ + + +Ubixos: icmp.h Source File + + + +

icmp.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_ICMP_H__
+00036 #define __LWIP_ICMP_H__
+00037 
+00038 #include "net/arch.h"
+00039 
+00040 #include "net/opt.h"
+00041 #include "net/pbuf.h"
+00042 
+00043 #include "net/netif.h"
+00044 
+00045 #define ICMP_ER 0      /* echo reply */
+00046 #define ICMP_DUR 3     /* destination unreachable */
+00047 #define ICMP_SQ 4      /* source quench */
+00048 #define ICMP_RD 5      /* redirect */
+00049 #define ICMP_ECHO 8    /* echo */
+00050 #define ICMP_TE 11     /* time exceeded */
+00051 #define ICMP_PP 12     /* parameter problem */
+00052 #define ICMP_TS 13     /* timestamp */
+00053 #define ICMP_TSR 14    /* timestamp reply */
+00054 #define ICMP_IRQ 15    /* information request */
+00055 #define ICMP_IR 16     /* information reply */
+00056 
+00057 enum icmp_dur_type {
+00058   ICMP_DUR_NET = 0,    /* net unreachable */
+00059   ICMP_DUR_HOST = 1,   /* host unreachable */
+00060   ICMP_DUR_PROTO = 2,  /* protocol unreachable */
+00061   ICMP_DUR_PORT = 3,   /* port unreachable */
+00062   ICMP_DUR_FRAG = 4,   /* fragmentation needed and DF set */
+00063   ICMP_DUR_SR = 5      /* source route failed */
+00064 };
+00065 
+00066 enum icmp_te_type {
+00067   ICMP_TE_TTL = 0,     /* time to live exceeded in transit */
+00068   ICMP_TE_FRAG = 1     /* fragment reassembly time exceeded */
+00069 };
+00070 
+00071 void icmp_input(struct pbuf *p, struct netif *inp);
+00072 
+00073 void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
+00074 void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
+00075 
+00076 struct icmp_echo_hdr {
+00077   PACK_STRUCT_FIELD(uInt16 _type_code);
+00078   PACK_STRUCT_FIELD(uInt16 chksum);
+00079   PACK_STRUCT_FIELD(uInt16 id);
+00080   PACK_STRUCT_FIELD(uInt16 seqno);
+00081 } PACK_STRUCT_STRUCT;
+00082 
+00083 
+00084 
+00085 struct icmp_dur_hdr {
+00086   PACK_STRUCT_FIELD(uInt16 _type_code);
+00087   PACK_STRUCT_FIELD(uInt16 chksum);
+00088   PACK_STRUCT_FIELD(uInt32 unused);
+00089 } PACK_STRUCT_STRUCT;
+00090 
+00091 struct icmp_te_hdr {
+00092   PACK_STRUCT_FIELD(uInt16 _type_code);
+00093   PACK_STRUCT_FIELD(uInt16 chksum);
+00094   PACK_STRUCT_FIELD(uInt32 unused);
+00095 } PACK_STRUCT_STRUCT;
+00096 
+00097 #define ICMPH_TYPE(hdr) (NTOHS((hdr)->_type_code) >> 8)
+00098 #define ICMPH_CODE(hdr) (NTOHS((hdr)->_type_code) & 0xff)
+00099 
+00100 #define ICMPH_TYPE_SET(hdr, type) ((hdr)->_type_code = HTONS(ICMPH_CODE(hdr) | ((type) << 8)))
+00101 #define ICMPH_CODE_SET(hdr, code) ((hdr)->_type_code = HTONS((code) | (ICMPH_TYPE(hdr) << 8)))
+00102 
+00103 #endif /* __LWIP_ICMP_H__ */
+00104           
+

Generated on Wed Apr 28 17:49:34 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2icmp_8h.html b/doc/doxygen/html/ipv4_2icmp_8h.html new file mode 100644 index 0000000..0513269 --- /dev/null +++ b/doc/doxygen/html/ipv4_2icmp_8h.html @@ -0,0 +1,649 @@ + + +Ubixos: ipv4/icmp.h File Reference + + + +

icmp.h File Reference

#include "net/arch.h"
+#include "net/opt.h"
+#include "net/pbuf.h"
+#include "net/netif.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  icmp_dur_hdr
struct  icmp_echo_hdr
struct  icmp_te_hdr

Defines

#define ICMP_ER   0
#define ICMP_DUR   3
#define ICMP_SQ   4
#define ICMP_RD   5
#define ICMP_ECHO   8
#define ICMP_TE   11
#define ICMP_PP   12
#define ICMP_TS   13
#define ICMP_TSR   14
#define ICMP_IRQ   15
#define ICMP_IR   16
#define ICMPH_TYPE(hdr)   (NTOHS((hdr)->_type_code) >> 8)
#define ICMPH_CODE(hdr)   (NTOHS((hdr)->_type_code) & 0xff)
#define ICMPH_TYPE_SET(hdr, type)   ((hdr)->_type_code = HTONS(ICMPH_CODE(hdr) | ((type) << 8)))
#define ICMPH_CODE_SET(hdr, code)   ((hdr)->_type_code = HTONS((code) | (ICMPH_TYPE(hdr) << 8)))

Enumerations

enum  icmp_dur_type {
+  ICMP_DUR_NET = 0, +ICMP_DUR_HOST = 1, +ICMP_DUR_PROTO = 2, +ICMP_DUR_PORT = 3, +
+  ICMP_DUR_FRAG = 4, +ICMP_DUR_SR = 5 +
+ }
enum  icmp_te_type { ICMP_TE_TTL = 0, +ICMP_TE_FRAG = 1 + }

Functions

void icmp_input (struct pbuf *p, struct netif *inp)
void icmp_dest_unreach (struct pbuf *p, enum icmp_dur_type t)
void icmp_time_exceeded (struct pbuf *p, enum icmp_te_type t)

Variables

icmp_echo_hdr PACK_STRUCT_STRUCT
+


Define Documentation

+

+ + + + +
+ + +
#define ICMP_DUR   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_ECHO   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_ER   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_IR   16 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_IRQ   15 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_PP   12 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_RD   5 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_SQ   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_TE   11 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_TS   13 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_TSR   14 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define ICMPH_CODEhdr   )    (NTOHS((hdr)->_type_code) & 0xff) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define ICMPH_CODE_SEThdr,
code   )    ((hdr)->_type_code = HTONS((code) | (ICMPH_TYPE(hdr) << 8))) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define ICMPH_TYPEhdr   )    (NTOHS((hdr)->_type_code) >> 8) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define ICMPH_TYPE_SEThdr,
type   )    ((hdr)->_type_code = HTONS(ICMPH_CODE(hdr) | ((type) << 8))) +
+
+ + + + + +
+   + + +

+

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum icmp_dur_type +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + + + +
ICMP_DUR_NET  +
ICMP_DUR_HOST  +
ICMP_DUR_PROTO  +
ICMP_DUR_PORT  +
ICMP_DUR_FRAG  +
ICMP_DUR_SR  +
+
+
+

+ + + + +
+ + +
enum icmp_te_type +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + +
ICMP_TE_TTL  +
ICMP_TE_FRAG  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void icmp_dest_unreach struct pbuf p,
enum icmp_dur_type  t
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void icmp_input struct pbuf p,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void icmp_time_exceeded struct pbuf p,
enum icmp_te_type  t
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct icmp_te_hdr PACK_STRUCT_STRUCT +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2inet_8h-source.html b/doc/doxygen/html/ipv4_2inet_8h-source.html new file mode 100644 index 0000000..02bde92 --- /dev/null +++ b/doc/doxygen/html/ipv4_2inet_8h-source.html @@ -0,0 +1,134 @@ + + +Ubixos: inet.h Source File + + + +

inet.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_INET_H__
+00036 #define __LWIP_INET_H__
+00037 
+00038 #include "net/arch.h"
+00039 
+00040 #include "net/opt.h"
+00041 #include "net/pbuf.h"
+00042 #include "net/ipv4/ip_addr.h"
+00043 
+00044 uInt16 inet_chksum(void *dataptr, uInt16 len);
+00045 uInt16 inet_chksum_pbuf(struct pbuf *p);
+00046 uInt16 inet_chksum_pseudo(struct pbuf *p,
+00047                          struct ip_addr *src, struct ip_addr *dest,
+00048                          uInt8 proto, uInt16 proto_len);
+00049 
+00050 #ifdef HTONS
+00051 #undef HTONS
+00052 #endif /* HTONS */
+00053 #ifdef NTOHS
+00054 #undef NTOHS
+00055 #endif /* NTOHS */
+00056 #ifdef HTONL
+00057 #undef HTONL
+00058 #endif /* HTONL */
+00059 #ifdef NTOHL
+00060 #undef NTOHL
+00061 #endif /* NTOHL */
+00062 
+00063 #ifndef HTONS
+00064 #   if BYTE_ORDER == BIG_ENDIAN
+00065 #      define HTONS(n) (n)
+00066 #      define htons(n) HTONS(n)
+00067 #   else /* BYTE_ORDER == BIG_ENDIAN */
+00068 #      define HTONS(n) (((((uInt16)(n) & 0xff)) << 8) | (((uInt16)(n) & 0xff00) >> 8))
+00069 #   endif /* BYTE_ORDER == BIG_ENDIAN */
+00070 #endif /* HTONS */
+00071 
+00072 #ifdef NTOHS
+00073 #undef NTOHS
+00074 #endif /* NTOHS */
+00075 
+00076 #ifdef ntohs
+00077 #undef ntohs
+00078 #endif /* ntohs */
+00079 
+00080 #define NTOHS HTONS
+00081 #define ntohs htons
+00082 
+00083 
+00084 #ifndef HTONL
+00085 #   if BYTE_ORDER == BIG_ENDIAN
+00086 #      define HTONL(n) (n)
+00087 #      define htonl(n) HTONL(n)
+00088 #   else /* BYTE_ORDER == BIG_ENDIAN */
+00089 #      define HTONL(n) (((((uInt32)(n) & 0xff)) << 24) | \
+00090                         ((((uInt32)(n) & 0xff00)) << 8) | \
+00091                         ((((uInt32)(n) & 0xff0000)) >> 8) | \
+00092                         ((((uInt32)(n) & 0xff000000)) >> 24))
+00093 #   endif /* BYTE_ORDER == BIG_ENDIAN */
+00094 #endif /* HTONL */
+00095 
+00096 #ifdef ntohl
+00097 #undef ntohl
+00098 #endif /* ntohl */
+00099 
+00100 #ifdef NTOHL
+00101 #undef NTOHL
+00102 #endif /* NTOHL */
+00103 
+00104 #define NTOHL HTONL
+00105 #define ntohl htonl
+00106 
+00107 #ifndef _MACHINE_ENDIAN_H_
+00108 #ifndef _NETINET_IN_H
+00109 #ifndef _LINUX_BYTEORDER_GENERIC_H
+00110 
+00111 #if BYTE_ORDER == LITTLE_ENDIAN
+00112 uInt16 htons(uInt16 n);
+00113 uInt32 htonl(uInt32 n);
+00114 #else
+00115 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
+00116 
+00117 #endif /* _LINUX_BYTEORDER_GENERIC_H */
+00118 #endif /* _NETINET_IN_H */
+00119 #endif /* _MACHINE_ENDIAN_H_ */
+00120 
+00121 #endif /* __LWIP_INET_H__ */
+00122 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2inet_8h.html b/doc/doxygen/html/ipv4_2inet_8h.html new file mode 100644 index 0000000..7ec1ef9 --- /dev/null +++ b/doc/doxygen/html/ipv4_2inet_8h.html @@ -0,0 +1,428 @@ + + +Ubixos: ipv4/inet.h File Reference + + + +

inet.h File Reference

#include "net/arch.h"
+#include "net/opt.h"
+#include "net/pbuf.h"
+#include "net/ipv4/ip_addr.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define HTONS(n)   (n)
#define htons(n)   HTONS(n)
#define NTOHS   HTONS
#define ntohs   htons
#define HTONL(n)   (n)
#define htonl(n)   HTONL(n)
#define NTOHL   HTONL
#define ntohl   htonl

Functions

uInt16 inet_chksum (void *dataptr, uInt16 len)
uInt16 inet_chksum_pbuf (struct pbuf *p)
uInt16 inet_chksum_pseudo (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, uInt8 proto, uInt16 proto_len)
uInt16 htons (uInt16 n)
uInt32 htonl (uInt32 n)
+


Define Documentation

+

+ + + + +
+ + + + + + + +
#define htonl  )    HTONL(n) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define HTONL  )    (n) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define htons  )    HTONS(n) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define HTONS  )    (n) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ntohl   htonl +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NTOHL   HTONL +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ntohs   htons +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NTOHS   HTONS +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
uInt32 htonl uInt32  n  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 htons uInt16  n  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uInt16 inet_chksum void *  dataptr,
uInt16  len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 inet_chksum_pbuf struct pbuf p  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
uInt16 inet_chksum_pseudo struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
uInt8  proto,
uInt16  proto_len
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2ip_8h-source.html b/doc/doxygen/html/ipv4_2ip_8h-source.html new file mode 100644 index 0000000..6668cdb --- /dev/null +++ b/doc/doxygen/html/ipv4_2ip_8h-source.html @@ -0,0 +1,132 @@ + + +Ubixos: ip.h Source File + + + +

ip.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_IP_H__
+00036 #define __LWIP_IP_H__
+00037 
+00038 #include "net/arch.h"
+00039 
+00040 #include "net/def.h"
+00041 #include "net/pbuf.h"
+00042 #include "net/ipv4/ip_addr.h"
+00043 #include "net/netif.h"
+00044 
+00045 #include "net/err.h"
+00046 
+00047 void ip_init(void);
+00048 uInt8 ip_lookup(void *header, struct netif *inp);
+00049 struct netif *ip_route(struct ip_addr *dest);
+00050 err_t ip_input(struct pbuf *p, struct netif *inp);
+00051 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
+00052                 uInt8 ttl, uInt8 proto);
+00053 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
+00054                    uInt8 ttl, uInt8 proto,
+00055                    struct netif *netif);
+00056 
+00057 #define IP_HLEN 20
+00058 
+00059 #define IP_PROTO_ICMP 1
+00060 #define IP_PROTO_UDP 17
+00061 #define IP_PROTO_UDPLITE 170
+00062 #define IP_PROTO_TCP 6
+00063 
+00064 /* This is passed as the destination address to ip_output_if (not
+00065    to ip_output), meaning that an IP header already is constructed
+00066    in the pbuf. This is used when TCP retransmits. */
+00067 #ifdef IP_HDRINCL
+00068 #undef IP_HDRINCL
+00069 #endif /* IP_HDRINCL */
+00070 #define IP_HDRINCL  NULL
+00071 
+00072 struct ip_hdr {
+00073   /* version / header length / type of service */
+00074   PACK_STRUCT_FIELD(uInt16 _v_hl_tos);
+00075   /* total length */
+00076   PACK_STRUCT_FIELD(uInt16 _len);
+00077   /* identification */
+00078   PACK_STRUCT_FIELD(uInt16 _id);
+00079   /* fragment offset field */
+00080   PACK_STRUCT_FIELD(uInt16 _offset);
+00081 #define IP_RF 0x8000        /* reserved fragment flag */
+00082 #define IP_DF 0x4000        /* dont fragment flag */
+00083 #define IP_MF 0x2000        /* more fragments flag */
+00084 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
+00085   /* time to live / protocol*/
+00086   PACK_STRUCT_FIELD(uInt16 _ttl_proto);
+00087   /* checksum */
+00088   PACK_STRUCT_FIELD(uInt16 _chksum);
+00089   /* source and destination IP addresses */
+00090   PACK_STRUCT_FIELD(struct ip_addr src);
+00091   PACK_STRUCT_FIELD(struct ip_addr dest); 
+00092 } PACK_STRUCT_STRUCT;
+00093 
+00094 #define IPH_V(hdr)  (NTOHS((hdr)->_v_hl_tos) >> 12)
+00095 #define IPH_HL(hdr) ((NTOHS((hdr)->_v_hl_tos) >> 8) & 0x0f)
+00096 #define IPH_TOS(hdr) HTONS((NTOHS((hdr)->_v_hl_tos) & 0xff))
+00097 #define IPH_LEN(hdr) ((hdr)->_len)
+00098 #define IPH_ID(hdr) ((hdr)->_id)
+00099 #define IPH_OFFSET(hdr) ((hdr)->_offset)
+00100 #define IPH_TTL(hdr) (NTOHS((hdr)->_ttl_proto) >> 8)
+00101 #define IPH_PROTO(hdr) (NTOHS((hdr)->_ttl_proto) & 0xff)
+00102 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
+00103 
+00104 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = HTONS(((v) << 12) | ((hl) << 8) | (tos))
+00105 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
+00106 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
+00107 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
+00108 #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = HTONS(IPH_PROTO(hdr) | ((ttl) << 8))
+00109 #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = HTONS((proto) | (IPH_TTL(hdr) << 8))
+00110 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
+00111 
+00112 
+00113 
+00114 #if IP_DEBUG
+00115 void ip_debug_print(struct pbuf *p);
+00116 #endif /* IP_DEBUG */
+00117 
+00118 #endif /* __LWIP_IP_H__ */
+00119 
+00120 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2ip_8h.html b/doc/doxygen/html/ipv4_2ip_8h.html new file mode 100644 index 0000000..b540787 --- /dev/null +++ b/doc/doxygen/html/ipv4_2ip_8h.html @@ -0,0 +1,1051 @@ + + +Ubixos: ipv4/ip.h File Reference + + + +

ip.h File Reference

#include "net/arch.h"
+#include "net/def.h"
+#include "net/pbuf.h"
+#include "net/ipv4/ip_addr.h"
+#include "net/netif.h"
+#include "net/err.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  ip_hdr

Defines

#define IP_HLEN   20
#define IP_PROTO_ICMP   1
#define IP_PROTO_UDP   17
#define IP_PROTO_UDPLITE   170
#define IP_PROTO_TCP   6
#define IP_HDRINCL   NULL
#define IP_RF   0x8000
#define IP_DF   0x4000
#define IP_MF   0x2000
#define IP_OFFMASK   0x1fff
#define IPH_V(hdr)   (NTOHS((hdr)->_v_hl_tos) >> 12)
#define IPH_HL(hdr)   ((NTOHS((hdr)->_v_hl_tos) >> 8) & 0x0f)
#define IPH_TOS(hdr)   HTONS((NTOHS((hdr)->_v_hl_tos) & 0xff))
#define IPH_LEN(hdr)   ((hdr)->_len)
#define IPH_ID(hdr)   ((hdr)->_id)
#define IPH_OFFSET(hdr)   ((hdr)->_offset)
#define IPH_TTL(hdr)   (NTOHS((hdr)->_ttl_proto) >> 8)
#define IPH_PROTO(hdr)   (NTOHS((hdr)->_ttl_proto) & 0xff)
#define IPH_CHKSUM(hdr)   ((hdr)->_chksum)
#define IPH_VHLTOS_SET(hdr, v, hl, tos)   (hdr)->_v_hl_tos = HTONS(((v) << 12) | ((hl) << 8) | (tos))
#define IPH_LEN_SET(hdr, len)   (hdr)->_len = (len)
#define IPH_ID_SET(hdr, id)   (hdr)->_id = (id)
#define IPH_OFFSET_SET(hdr, off)   (hdr)->_offset = (off)
#define IPH_TTL_SET(hdr, ttl)   (hdr)->_ttl_proto = HTONS(IPH_PROTO(hdr) | ((ttl) << 8))
#define IPH_PROTO_SET(hdr, proto)   (hdr)->_ttl_proto = HTONS((proto) | (IPH_TTL(hdr) << 8))
#define IPH_CHKSUM_SET(hdr, chksum)   (hdr)->_chksum = (chksum)

Functions

void ip_init (void)
uInt8 ip_lookup (void *header, struct netif *inp)
netifip_route (struct ip_addr *dest)
err_t ip_input (struct pbuf *p, struct netif *inp)
err_t ip_output (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, uInt8 ttl, uInt8 proto)
err_t ip_output_if (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, uInt8 ttl, uInt8 proto, struct netif *netif)

Variables

ip_hdr PACK_STRUCT_STRUCT
+


Define Documentation

+

+ + + + +
+ + +
#define IP_DF   0x4000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_HDRINCL   NULL +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_HLEN   20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_MF   0x2000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_OFFMASK   0x1fff +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_ICMP   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_TCP   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_UDP   17 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_UDPLITE   170 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_RF   0x8000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_CHKSUMhdr   )    ((hdr)->_chksum) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define IPH_CHKSUM_SEThdr,
chksum   )    (hdr)->_chksum = (chksum) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_HLhdr   )    ((NTOHS((hdr)->_v_hl_tos) >> 8) & 0x0f) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_IDhdr   )    ((hdr)->_id) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define IPH_ID_SEThdr,
id   )    (hdr)->_id = (id) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_LENhdr   )    ((hdr)->_len) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define IPH_LEN_SEThdr,
len   )    (hdr)->_len = (len) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_OFFSEThdr   )    ((hdr)->_offset) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define IPH_OFFSET_SEThdr,
off   )    (hdr)->_offset = (off) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_PROTOhdr   )    (NTOHS((hdr)->_ttl_proto) & 0xff) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define IPH_PROTO_SEThdr,
proto   )    (hdr)->_ttl_proto = HTONS((proto) | (IPH_TTL(hdr) << 8)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_TOShdr   )    HTONS((NTOHS((hdr)->_v_hl_tos) & 0xff)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_TTLhdr   )    (NTOHS((hdr)->_ttl_proto) >> 8) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define IPH_TTL_SEThdr,
ttl   )    (hdr)->_ttl_proto = HTONS(IPH_PROTO(hdr) | ((ttl) << 8)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define IPH_Vhdr   )    (NTOHS((hdr)->_v_hl_tos) >> 12) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + +
#define IPH_VHLTOS_SEThdr,
v,
hl,
tos   )    (hdr)->_v_hl_tos = HTONS(((v) << 12) | ((hl) << 8) | (tos)) +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void ip_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
err_t ip_input struct pbuf p,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uInt8 ip_lookup void *  header,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t ip_output struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
uInt8  ttl,
uInt8  proto
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t ip_output_if struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
uInt8  ttl,
uInt8  proto,
struct netif netif
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct netif* ip_route struct ip_addr dest  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct ip_hdr PACK_STRUCT_STRUCT +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2ip__addr_8h-source.html b/doc/doxygen/html/ipv4_2ip__addr_8h-source.html new file mode 100644 index 0000000..03b3cdb --- /dev/null +++ b/doc/doxygen/html/ipv4_2ip__addr_8h-source.html @@ -0,0 +1,104 @@ + + +Ubixos: ip_addr.h Source File + + + +

ip_addr.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_IP_ADDR_H__
+00036 #define __LWIP_IP_ADDR_H__
+00037 
+00038 #include "net/arch.h"
+00039 
+00040 #define IP_ADDR_ANY 0
+00041 
+00042 #define IP_ADDR_BROADCAST (&ip_addr_broadcast)
+00043 
+00044 PACK_STRUCT_BEGIN
+00045 struct ip_addr {
+00046   PACK_STRUCT_FIELD(uInt32 addr);
+00047 } PACK_STRUCT_STRUCT;
+00048 PACK_STRUCT_END
+00049 
+00050 extern struct ip_addr ip_addr_broadcast;
+00051 
+00052 #define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = htonl(((uInt32)(a & 0xff) << 24) | ((uInt32)(b & 0xff) << 16) | \
+00053                                                          ((uInt32)(c & 0xff) << 8) | (uInt32)(d & 0xff))
+00054 
+00055 #define ip_addr_set(dest, src) (dest)->addr = \
+00056                                ((src) == IP_ADDR_ANY? IP_ADDR_ANY:\
+00057                                 ((struct ip_addr *)src)->addr)
+00058 #define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \
+00059                                               (mask)->addr) == \
+00060                                              ((addr2)->addr & \
+00061                                               (mask)->addr))
+00062 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
+00063 
+00064 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
+00065 
+00066 #define ip_addr_isbroadcast(addr1, mask) (((((addr1)->addr) & ~((mask)->addr)) == \
+00067                                          (0xffffffff & ~((mask)->addr))) || \
+00068                                          ((addr1)->addr == 0xffffffff) || \
+00069                                          ((addr1)->addr == 0x00000000))
+00070 
+00071 
+00072 #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000))
+00073                                    
+00074 
+00075 #define ip_addr_debug_print(ipaddr) kprintf("%d.%d.%d.%d", \
+00076                     (uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff, \
+00077                     (uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff, \
+00078                     (uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff, \
+00079                     (uInt8)ntohl((ipaddr)->addr) & 0xff)
+00080 
+00081 
+00082 #define ip4_addr1(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff)
+00083 #define ip4_addr2(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff)
+00084 #define ip4_addr3(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff)
+00085 #define ip4_addr4(ipaddr) ((uInt8)(ntohl((ipaddr)->addr)) & 0xff)
+00086 #endif /* __LWIP_IP_ADDR_H__ */
+00087 
+00088 
+00089 
+00090 
+00091 
+00092 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv4_2ip__addr_8h.html b/doc/doxygen/html/ipv4_2ip__addr_8h.html new file mode 100644 index 0000000..3d84a59 --- /dev/null +++ b/doc/doxygen/html/ipv4_2ip__addr_8h.html @@ -0,0 +1,514 @@ + + +Ubixos: ipv4/ip_addr.h File Reference + + + +

ip_addr.h File Reference

#include "net/arch.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  ip_addr

Defines

#define IP_ADDR_ANY   0
#define IP_ADDR_BROADCAST   (&ip_addr_broadcast)
#define IP4_ADDR(ipaddr, a, b, c, d)
#define ip_addr_set(dest, src)
#define ip_addr_maskcmp(addr1, addr2, mask)
#define ip_addr_cmp(addr1, addr2)   ((addr1)->addr == (addr2)->addr)
#define ip_addr_isany(addr1)   ((addr1) == NULL || (addr1)->addr == 0)
#define ip_addr_isbroadcast(addr1, mask)
#define ip_addr_ismulticast(addr1)   (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000))
#define ip_addr_debug_print(ipaddr)
#define ip4_addr1(ipaddr)   ((uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff)
#define ip4_addr2(ipaddr)   ((uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff)
#define ip4_addr3(ipaddr)   ((uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff)
#define ip4_addr4(ipaddr)   ((uInt8)(ntohl((ipaddr)->addr)) & 0xff)

Variables

PACK_STRUCT_BEGIN struct ip_addr PACK_STRUCT_STRUCT
PACK_STRUCT_END struct ip_addr ip_addr_broadcast
+


Define Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
#define IP4_ADDRipaddr,
a,
b,
c,
 )  +
+
+ + + + + +
+   + + +

+Value:

(ipaddr)->addr = htonl(((uInt32)(a & 0xff) << 24) | ((uInt32)(b & 0xff) << 16) | \
+                                                         ((uInt32)(c & 0xff) << 8) | (uInt32)(d & 0xff))
+
+

+ + + + +
+ + + + + + + +
#define ip4_addr1ipaddr   )    ((uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define ip4_addr2ipaddr   )    ((uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define ip4_addr3ipaddr   )    ((uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define ip4_addr4ipaddr   )    ((uInt8)(ntohl((ipaddr)->addr)) & 0xff) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_ADDR_ANY   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_ADDR_BROADCAST   (&ip_addr_broadcast) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define ip_addr_cmpaddr1,
addr2   )    ((addr1)->addr == (addr2)->addr) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define ip_addr_debug_printipaddr   )  +
+
+ + + + + +
+   + + +

+Value:

kprintf("%d.%d.%d.%d", \
+                    (uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff, \
+                    (uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff, \
+                    (uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff, \
+                    (uInt8)ntohl((ipaddr)->addr) & 0xff)
+
+

+ + + + +
+ + + + + + + +
#define ip_addr_isanyaddr1   )    ((addr1) == NULL || (addr1)->addr == 0) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define ip_addr_isbroadcastaddr1,
mask   )  +
+
+ + + + + +
+   + + +

+Value:

(((((addr1)->addr) & ~((mask)->addr)) == \
+                                         (0xffffffff & ~((mask)->addr))) || \
+                                         ((addr1)->addr == 0xffffffff) || \
+                                         ((addr1)->addr == 0x00000000))
+
+

+ + + + +
+ + + + + + + +
#define ip_addr_ismulticastaddr1   )    (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + +
#define ip_addr_maskcmpaddr1,
addr2,
mask   )  +
+
+ + + + + +
+   + + +

+Value:

(((addr1)->addr & \
+                                              (mask)->addr) == \
+                                             ((addr2)->addr & \
+                                              (mask)->addr))
+
+

+ + + + +
+ + + + + + + + + + +
#define ip_addr_setdest,
src   )  +
+
+ + + + + +
+   + + +

+Value:

(dest)->addr = \
+                               ((src) == IP_ADDR_ANY? IP_ADDR_ANY:\
+                                ((struct ip_addr *)src)->addr)
+
+


Variable Documentation

+

+ + + + +
+ + +
PACK_STRUCT_END struct ip_addr ip_addr_broadcast +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
PACK_STRUCT_BEGIN struct ip_addr PACK_STRUCT_STRUCT +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2icmp_8h-source.html b/doc/doxygen/html/ipv6_2icmp_8h-source.html new file mode 100644 index 0000000..6c7ff97 --- /dev/null +++ b/doc/doxygen/html/ipv6_2icmp_8h-source.html @@ -0,0 +1,105 @@ + + +Ubixos: icmp.h Source File + + + +

icmp.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_ICMP_H__
+00036 #define __LWIP_ICMP_H__
+00037 
+00038 #include "lwip/arch.h"
+00039 
+00040 #include "lwip/opt.h"
+00041 #include "lwip/pbuf.h"
+00042 
+00043 #include "lwip/netif.h"
+00044 
+00045 #define ICMP6_DUR  1
+00046 #define ICMP6_TE   3
+00047 #define ICMP6_ECHO 128    /* echo */
+00048 #define ICMP6_ER   129      /* echo reply */
+00049 
+00050 
+00051 enum icmp_dur_type {
+00052   ICMP_DUR_NET = 0,    /* net unreachable */
+00053   ICMP_DUR_HOST = 1,   /* host unreachable */
+00054   ICMP_DUR_PROTO = 2,  /* protocol unreachable */
+00055   ICMP_DUR_PORT = 3,   /* port unreachable */
+00056   ICMP_DUR_FRAG = 4,   /* fragmentation needed and DF set */
+00057   ICMP_DUR_SR = 5      /* source route failed */
+00058 };
+00059 
+00060 enum icmp_te_type {
+00061   ICMP_TE_TTL = 0,     /* time to live exceeded in transit */
+00062   ICMP_TE_FRAG = 1     /* fragment reassembly time exceeded */
+00063 };
+00064 
+00065 void icmp_input(struct pbuf *p, struct netif *inp);
+00066 
+00067 void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
+00068 void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
+00069 
+00070 struct icmp_echo_hdr {
+00071   u8_t type;
+00072   u8_t icode;
+00073   u16_t chksum;
+00074   u16_t id;
+00075   u16_t seqno;
+00076 };
+00077 
+00078 struct icmp_dur_hdr {
+00079   u8_t type;
+00080   u8_t icode;
+00081   u16_t chksum;
+00082   u32_t unused;
+00083 };
+00084 
+00085 struct icmp_te_hdr {
+00086   u8_t type;
+00087   u8_t icode;
+00088   u16_t chksum;
+00089   u32_t unused;
+00090 };
+00091 
+00092 #endif /* __LWIP_ICMP_H__ */
+00093           
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2icmp_8h.html b/doc/doxygen/html/ipv6_2icmp_8h.html new file mode 100644 index 0000000..ea353b8 --- /dev/null +++ b/doc/doxygen/html/ipv6_2icmp_8h.html @@ -0,0 +1,333 @@ + + +Ubixos: ipv6/icmp.h File Reference + + + +

icmp.h File Reference

#include "lwip/arch.h"
+#include "lwip/opt.h"
+#include "lwip/pbuf.h"
+#include "lwip/netif.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  icmp_dur_hdr
struct  icmp_echo_hdr
struct  icmp_te_hdr

Defines

#define ICMP6_DUR   1
#define ICMP6_TE   3
#define ICMP6_ECHO   128
#define ICMP6_ER   129

Enumerations

enum  icmp_dur_type {
+  ICMP_DUR_NET = 0, +ICMP_DUR_HOST = 1, +ICMP_DUR_PROTO = 2, +ICMP_DUR_PORT = 3, +
+  ICMP_DUR_FRAG = 4, +ICMP_DUR_SR = 5 +
+ }
enum  icmp_te_type { ICMP_TE_TTL = 0, +ICMP_TE_FRAG = 1 + }

Functions

void icmp_input (struct pbuf *p, struct netif *inp)
void icmp_dest_unreach (struct pbuf *p, enum icmp_dur_type t)
void icmp_time_exceeded (struct pbuf *p, enum icmp_te_type t)
+


Define Documentation

+

+ + + + +
+ + +
#define ICMP6_DUR   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP6_ECHO   128 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP6_ER   129 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP6_TE   3 +
+
+ + + + + +
+   + + +

+

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum icmp_dur_type +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + + + +
ICMP_DUR_NET  +
ICMP_DUR_HOST  +
ICMP_DUR_PROTO  +
ICMP_DUR_PORT  +
ICMP_DUR_FRAG  +
ICMP_DUR_SR  +
+
+
+

+ + + + +
+ + +
enum icmp_te_type +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + +
ICMP_TE_TTL  +
ICMP_TE_FRAG  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void icmp_dest_unreach struct pbuf p,
enum icmp_dur_type  t
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void icmp_input struct pbuf p,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void icmp_time_exceeded struct pbuf p,
enum icmp_te_type  t
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2inet_8h-source.html b/doc/doxygen/html/ipv6_2inet_8h-source.html new file mode 100644 index 0000000..4685890 --- /dev/null +++ b/doc/doxygen/html/ipv6_2inet_8h-source.html @@ -0,0 +1,75 @@ + + +Ubixos: inet.h Source File + + + +

inet.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_INET_H__
+00036 #define __LWIP_INET_H__
+00037 
+00038 #include "net/arch.h"
+00039 
+00040 #include "net/opt.h"
+00041 #include "net/pbuf.h"
+00042 #include "net/ipv6/ip_addr.h"
+00043 
+00044 u16_t inet_chksum(void *data, u16_t len);
+00045 u16_t inet_chksum_pbuf(struct pbuf *p);
+00046 u16_t inet_chksum_pseudo(struct pbuf *p,
+00047                          struct ip_addr *src, struct ip_addr *dest,
+00048                          u8_t proto, u32_t proto_len);
+00049 
+00050 
+00051 #ifndef _MACHINE_ENDIAN_H_
+00052 #ifndef _NETINET_IN_H
+00053 #ifndef _LINUX_BYTEORDER_GENERIC_H
+00054 u16_t htons(u16_t n);
+00055 u16_t ntohs(u16_t n);
+00056 u32_t htonl(u32_t n);
+00057 u32_t ntohl(u32_t n);
+00058 #endif /* _LINUX_BYTEORDER_GENERIC_H */
+00059 #endif /* _NETINET_IN_H */
+00060 #endif /* _MACHINE_ENDIAN_H_ */
+00061 
+00062 #endif /* __LWIP_INET_H__ */
+00063 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2inet_8h.html b/doc/doxygen/html/ipv6_2inet_8h.html new file mode 100644 index 0000000..ee219dd --- /dev/null +++ b/doc/doxygen/html/ipv6_2inet_8h.html @@ -0,0 +1,276 @@ + + +Ubixos: ipv6/inet.h File Reference + + + +

inet.h File Reference

#include "net/arch.h"
+#include "net/opt.h"
+#include "net/pbuf.h"
+#include "net/ipv6/ip_addr.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + +

Functions

u16_t inet_chksum (void *data, u16_t len)
u16_t inet_chksum_pbuf (struct pbuf *p)
u16_t inet_chksum_pseudo (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t proto, u32_t proto_len)
u16_t htons (u16_t n)
u16_t ntohs (u16_t n)
u32_t htonl (u32_t n)
u32_t ntohl (u32_t n)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
u32_t htonl u32_t  n  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
u16_t htons u16_t  n  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
u16_t inet_chksum void *  data,
u16_t  len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
u16_t inet_chksum_pbuf struct pbuf p  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
u16_t inet_chksum_pseudo struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
u8_t  proto,
u32_t  proto_len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
u32_t ntohl u32_t  n  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
u16_t ntohs u16_t  n  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2ip_8h-source.html b/doc/doxygen/html/ipv6_2ip_8h-source.html new file mode 100644 index 0000000..1a24140 --- /dev/null +++ b/doc/doxygen/html/ipv6_2ip_8h-source.html @@ -0,0 +1,111 @@ + + +Ubixos: ip.h Source File + + + +

ip.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_IP_H__
+00036 #define __LWIP_IP_H__
+00037 
+00038 #include "lwip/debug.h"
+00039 #include "lwip/def.h"
+00040 #include "lwip/pbuf.h"
+00041 #include "lwip/ip_addr.h"
+00042 
+00043 #include "lwip/err.h"
+00044 
+00045 #define IP_HLEN 40
+00046 
+00047 #define IP_PROTO_ICMP 58
+00048 #define IP_PROTO_UDP 17
+00049 #define IP_PROTO_UDPLITE 170
+00050 #define IP_PROTO_TCP 6
+00051 
+00052 /* This is passed as the destination address to ip_output_if (not
+00053    to ip_output), meaning that an IP header already is constructed
+00054    in the pbuf. This is used when TCP retransmits. */
+00055 #ifdef IP_HDRINCL
+00056 #undef IP_HDRINCL
+00057 #endif /* IP_HDRINCL */
+00058 #define IP_HDRINCL  NULL
+00059 
+00060 
+00061 /* The IPv6 header. */
+00062 struct ip_hdr {
+00063 #if BYTE_ORDER == LITTLE_ENDIAN
+00064   u8_t tclass1:4, v:4;
+00065   u8_t flow1:4, tclass2:4;  
+00066 #else
+00067   u8_t v:4, tclass1:4;
+00068   u8_t tclass2:8, flow1:4;
+00069 #endif
+00070   u16_t flow2;
+00071   u16_t len;                /* payload length */
+00072   u8_t nexthdr;             /* next header */
+00073   u8_t hoplim;              /* hop limit (TTL) */
+00074   struct ip_addr src, dest;          /* source and destination IP addresses */
+00075 };
+00076 
+00077 void ip_init(void);
+00078 
+00079 #include "lwip/netif.h"
+00080 
+00081 struct netif *ip_route(struct ip_addr *dest);
+00082 
+00083 void ip_input(struct pbuf *p, struct netif *inp);
+00084 
+00085 /* source and destination addresses in network byte order, please */
+00086 err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
+00087                unsigned char ttl, unsigned char proto);
+00088 
+00089 err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
+00090                   unsigned char ttl, unsigned char proto,
+00091                   struct netif *netif);
+00092 
+00093 #if IP_DEBUG
+00094 void ip_debug_print(struct pbuf *p);
+00095 #endif /* IP_DEBUG */
+00096 
+00097 #endif /* __LWIP_IP_H__ */
+00098 
+00099 
+

Generated on Wed Apr 28 17:49:35 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2ip_8h.html b/doc/doxygen/html/ipv6_2ip_8h.html new file mode 100644 index 0000000..f7e03a0 --- /dev/null +++ b/doc/doxygen/html/ipv6_2ip_8h.html @@ -0,0 +1,398 @@ + + +Ubixos: ipv6/ip.h File Reference + + + +

ip.h File Reference

#include "lwip/debug.h"
+#include "lwip/def.h"
+#include "lwip/pbuf.h"
+#include "lwip/ip_addr.h"
+#include "lwip/err.h"
+#include "lwip/netif.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  ip_hdr

Defines

#define IP_HLEN   40
#define IP_PROTO_ICMP   58
#define IP_PROTO_UDP   17
#define IP_PROTO_UDPLITE   170
#define IP_PROTO_TCP   6
#define IP_HDRINCL   NULL

Functions

void ip_init (void)
netifip_route (struct ip_addr *dest)
void ip_input (struct pbuf *p, struct netif *inp)
err_t ip_output (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, unsigned char ttl, unsigned char proto)
err_t ip_output_if (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, unsigned char ttl, unsigned char proto, struct netif *netif)
+


Define Documentation

+

+ + + + +
+ + +
#define IP_HDRINCL   NULL +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_HLEN   40 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_ICMP   58 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_TCP   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_UDP   17 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_PROTO_UDPLITE   170 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void ip_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void ip_input struct pbuf p,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t ip_output struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
unsigned char  ttl,
unsigned char  proto
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t ip_output_if struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
unsigned char  ttl,
unsigned char  proto,
struct netif netif
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct netif* ip_route struct ip_addr dest  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2ip__addr_8h-source.html b/doc/doxygen/html/ipv6_2ip__addr_8h-source.html new file mode 100644 index 0000000..99ed6e8 --- /dev/null +++ b/doc/doxygen/html/ipv6_2ip__addr_8h-source.html @@ -0,0 +1,74 @@ + + +Ubixos: ip_addr.h Source File + + + +

ip_addr.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_IP_ADDR_H__
+00036 #define __LWIP_IP_ADDR_H__
+00037 
+00038 #include "net/arch.h"
+00039 
+00040 #define IP_ADDR_ANY 0
+00041 
+00042 struct ip_addr {
+00043   u32_t addr[4];
+00044 };
+00045 
+00046 #define IP6_ADDR(ipaddr, a,b,c,d,e,f,g,h) do { (ipaddr)->addr[0] = htonl((u32_t)((a & 0xffff) << 16) | (b & 0xffff)); \
+00047                                                (ipaddr)->addr[1] = htonl(((c & 0xffff) << 16) | (d & 0xffff)); \
+00048                                                (ipaddr)->addr[2] = htonl(((e & 0xffff) << 16) | (f & 0xffff)); \
+00049                                                (ipaddr)->addr[3] = htonl(((g & 0xffff) << 16) | (h & 0xffff)); } while(0)
+00050 
+00051 int ip_addr_maskcmp(struct ip_addr *addr1, struct ip_addr *addr2,
+00052                     struct ip_addr *mask);
+00053 int ip_addr_cmp(struct ip_addr *addr1, struct ip_addr *addr2);
+00054 void ip_addr_set(struct ip_addr *dest, struct ip_addr *src);
+00055 int ip_addr_isany(struct ip_addr *addr);
+00056 
+00057 
+00058 #if IP_DEBUG
+00059 void ip_addr_debug_print(struct ip_addr *addr);
+00060 #endif /* IP_DEBUG */
+00061 
+00062 #endif /* __LWIP_IP_ADDR_H__ */
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ipv6_2ip__addr_8h.html b/doc/doxygen/html/ipv6_2ip__addr_8h.html new file mode 100644 index 0000000..5a50602 --- /dev/null +++ b/doc/doxygen/html/ipv6_2ip__addr_8h.html @@ -0,0 +1,263 @@ + + +Ubixos: ipv6/ip_addr.h File Reference + + + +

ip_addr.h File Reference

#include "net/arch.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + +

Data Structures

struct  ip_addr

Defines

#define IP_ADDR_ANY   0
#define IP6_ADDR(ipaddr, a, b, c, d, e, f, g, h)

Functions

int ip_addr_maskcmp (struct ip_addr *addr1, struct ip_addr *addr2, struct ip_addr *mask)
int ip_addr_cmp (struct ip_addr *addr1, struct ip_addr *addr2)
void ip_addr_set (struct ip_addr *dest, struct ip_addr *src)
int ip_addr_isany (struct ip_addr *addr)
+


Define Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#define IP6_ADDRipaddr,
a,
b,
c,
d,
e,
f,
g,
 )  +
+
+ + + + + +
+   + + +

+Value:

do { (ipaddr)->addr[0] = htonl((u32_t)((a & 0xffff) << 16) | (b & 0xffff)); \
+                                               (ipaddr)->addr[1] = htonl(((c & 0xffff) << 16) | (d & 0xffff)); \
+                                               (ipaddr)->addr[2] = htonl(((e & 0xffff) << 16) | (f & 0xffff)); \
+                                               (ipaddr)->addr[3] = htonl(((g & 0xffff) << 16) | (h & 0xffff)); } while(0)
+
+

+ + + + +
+ + +
#define IP_ADDR_ANY   0 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int ip_addr_cmp struct ip_addr addr1,
struct ip_addr addr2
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ip_addr_isany struct ip_addr addr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int ip_addr_maskcmp struct ip_addr addr1,
struct ip_addr addr2,
struct ip_addr mask
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void ip_addr_set struct ip_addr dest,
struct ip_addr src
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kmalloc_8h-source.html b/doc/doxygen/html/kmalloc_8h-source.html new file mode 100644 index 0000000..488c6af --- /dev/null +++ b/doc/doxygen/html/kmalloc_8h-source.html @@ -0,0 +1,77 @@ + + +Ubixos: kmalloc.h Source File + + + +

kmalloc.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _KMALLOC_H
+00025 #define _KMALLOC_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #ifdef __cplusplus
+00030 extern "C" {
+00031 #endif
+00032 
+00033 #define sysMalloc  -2
+00034 #define sysID      -2
+00035 
+00036 struct memDescriptor {
+00037   struct memDescriptor *prev;        //4
+00038   struct memDescriptor *next;        //4
+00039   void                 *baseAddr;    //4
+00040   uInt32               limit;        //4
+00041   uInt8                status;       //1
+00042   pidType              pid;          //4
+00043   char                 reserved[11]; //11
+00044   };
+00045 
+00046 void kfree(void *baseAddr);
+00047 void *kmalloc(uInt32 len,pidType pid);
+00048 void initMalloc(pidType pid);
+00049 void *getEmptyDesc();
+00050 void insertFreeDesc(struct memDescriptor *freeDesc);
+00051 void mergeMemBlocks();
+00052 void kfreeProcess(pidType pid);
+00053 
+00054 extern struct memDescriptor *kernDesc;
+00055 extern struct memDescriptor *freeKernDesc;
+00056 extern struct memDescriptor *emptyKernDesc;
+00057 
+00058 extern int mallocLock;
+00059 
+00060 #ifdef __cplusplus
+00061 }
+00062 #endif
+00063 
+00064 #endif
+00065 
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kmalloc_8h.html b/doc/doxygen/html/kmalloc_8h.html new file mode 100644 index 0000000..1164d89 --- /dev/null +++ b/doc/doxygen/html/kmalloc_8h.html @@ -0,0 +1,395 @@ + + +Ubixos: kmalloc.h File Reference + + + +

kmalloc.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  memDescriptor

Defines

#define sysMalloc   -2
#define sysID   -2

Functions

void kfree (void *baseAddr)
void * kmalloc (uInt32 len, pidType pid)
void initMalloc (pidType pid)
void * getEmptyDesc ()
void insertFreeDesc (struct memDescriptor *freeDesc)
void mergeMemBlocks ()
void kfreeProcess (pidType pid)

Variables

memDescriptorkernDesc
memDescriptorfreeKernDesc
memDescriptoremptyKernDesc
int mallocLock
+


Define Documentation

+

+ + + + +
+ + +
#define sysID   -2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define sysMalloc   -2 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void* getEmptyDesc  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void initMalloc pidType  pid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void insertFreeDesc struct memDescriptor freeDesc  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void kfree void *  baseAddr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void kfreeProcess pidType  pid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void* kmalloc uInt32  len,
pidType  pid
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void mergeMemBlocks  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct memDescriptor* emptyKernDesc +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct memDescriptor* freeKernDesc +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct memDescriptor* kernDesc +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int mallocLock +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kpanic_8h-source.html b/doc/doxygen/html/kpanic_8h-source.html new file mode 100644 index 0000000..f80e2d2 --- /dev/null +++ b/doc/doxygen/html/kpanic_8h-source.html @@ -0,0 +1,46 @@ + + +Ubixos: kpanic.h Source File + + + +

kpanic.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _KPANIC_H
+00025 #define _KPANIC_H
+00026 
+00027 void kpanic(const char *fmt, ...);
+00028 
+00029 #endif
+00030 
+00031 /***
+00032  END
+00033  ***/
+00034 
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kpanic_8h.html b/doc/doxygen/html/kpanic_8h.html new file mode 100644 index 0000000..1cc0d7b --- /dev/null +++ b/doc/doxygen/html/kpanic_8h.html @@ -0,0 +1,59 @@ + + +Ubixos: kpanic.h File Reference + + + +

kpanic.h File Reference

+

+Go to the source code of this file. + + + + +

Functions

void kpanic (const char *fmt,...)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void kpanic const char *  fmt,
... 
+
+ + + + + +
+   + + +

+Prints message and halts the system until another interrupt is fired

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kprint_8h-source.html b/doc/doxygen/html/kprint_8h-source.html new file mode 100644 index 0000000..176b0c6 --- /dev/null +++ b/doc/doxygen/html/kprint_8h-source.html @@ -0,0 +1,43 @@ + + +Ubixos: kprint.h Source File + + + +

kprint.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _KPRINT_H
+00025 #define _KPRINT_H
+00026 
+00027 int kprintf(const char *fmt, ...);
+00028 
+00029 extern int printOff;
+00030 
+00031 #endif
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kprint_8h.html b/doc/doxygen/html/kprint_8h.html new file mode 100644 index 0000000..592044d --- /dev/null +++ b/doc/doxygen/html/kprint_8h.html @@ -0,0 +1,85 @@ + + +Ubixos: kprint.h File Reference + + + +

kprint.h File Reference

+

+Go to the source code of this file. + + + + + + + +

Functions

int kprintf (const char *fmt,...)

Variables

int printOff
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int kprintf const char *  fmt,
... 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
int printOff +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kprintf_8h-source.html b/doc/doxygen/html/kprintf_8h-source.html new file mode 100644 index 0000000..ef5e096 --- /dev/null +++ b/doc/doxygen/html/kprintf_8h-source.html @@ -0,0 +1,46 @@ + + +Ubixos: kprintf.h Source File + + + +

kprintf.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _KPRINTF_H
+00025 #define _KPRINTF_H
+00026 
+00027 int kprintf(const char *fmt, ...);
+00028 int ogPrintf(char *);
+00029 
+00030 extern int printOff;
+00031 extern int ogprintOff;
+00032 
+00033 #endif
+00034 
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/kprintf_8h.html b/doc/doxygen/html/kprintf_8h.html new file mode 100644 index 0000000..27fdfc6 --- /dev/null +++ b/doc/doxygen/html/kprintf_8h.html @@ -0,0 +1,140 @@ + + +Ubixos: kprintf.h File Reference + + + +

kprintf.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + +

Functions

int kprintf (const char *fmt,...)
int ogPrintf (char *)

Variables

int printOff
int ogprintOff
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int kprintf const char *  fmt,
... 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ogPrintf char *   ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
int ogprintOff +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int printOff +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ld_8h-source.html b/doc/doxygen/html/ld_8h-source.html new file mode 100644 index 0000000..b82088e --- /dev/null +++ b/doc/doxygen/html/ld_8h-source.html @@ -0,0 +1,48 @@ + + +Ubixos: ld.h Source File + + + +

ld.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _LD_H
+00025 #define _LD_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 void ld(int,int);
+00030 
+00031 #endif
+00032 
+00033 /***
+00034  END
+00035  ***/
+00036 
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ld_8h.html b/doc/doxygen/html/ld_8h.html new file mode 100644 index 0000000..37be488 --- /dev/null +++ b/doc/doxygen/html/ld_8h.html @@ -0,0 +1,60 @@ + + +Ubixos: ld.h File Reference + + + +

ld.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + +

Functions

void ld (int, int)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void ld int ,
int 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lib_2string_8h-source.html b/doc/doxygen/html/lib_2string_8h-source.html new file mode 100644 index 0000000..a880131 --- /dev/null +++ b/doc/doxygen/html/lib_2string_8h-source.html @@ -0,0 +1,61 @@ + + +Ubixos: string.h Source File + + + +

string.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _STRING_H
+00025 #define _STRING_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #ifdef __cplusplus
+00030 extern "C" {
+00031 #endif
+00032 
+00033 int kstrcmp(char *str1, char *str2);
+00034 int kstrncmp(const char * a, const char * b, size_t c);
+00035 void *kmemcpy(const void *dst, const void * src, size_t length);
+00036 void *kmemset(void * dst, int c, size_t length);
+00037 int kstrlen(const char * string);
+00038 int kmemcmp(const void * dst, const void * src, size_t length);
+00039 void kstrncpy(char * dest, const char * src, size_t size);
+00040 char *strtok(char *str, const char *sep);
+00041 char *strtok_r(char *str, const char *sep, char **last);
+00042 
+00043 int sprintf(char *buf,const char *fmt, ...);
+00044 
+00045 #ifdef __cplusplus
+00046 }
+00047 #endif
+00048   
+00049 #endif
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lib_2string_8h.html b/doc/doxygen/html/lib_2string_8h.html new file mode 100644 index 0000000..749521f --- /dev/null +++ b/doc/doxygen/html/lib_2string_8h.html @@ -0,0 +1,453 @@ + + +Ubixos: lib/string.h File Reference + + + +

string.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + +

Functions

int kstrcmp (char *str1, char *str2)
int kstrncmp (const char *a, const char *b, size_t c)
void * kmemcpy (const void *dst, const void *src, size_t length)
void * kmemset (void *dst, int c, size_t length)
int kstrlen (const char *string)
int kmemcmp (const void *dst, const void *src, size_t length)
void kstrncpy (char *dest, const char *src, size_t size)
char * strtok (char *str, const char *sep)
char * strtok_r (char *str, const char *sep, char **last)
int sprintf (char *buf, const char *fmt,...)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int kmemcmp const void *  dst,
const void *  src,
size_t  length
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void* kmemcpy const void *  dst,
const void *  src,
size_t  length
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void* kmemset void *  dst,
int  c,
size_t  length
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int kstrcmp char *  str1,
char *  str2
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int kstrlen const char *  string  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int kstrncmp const char *  a,
const char *  b,
size_t  c
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void kstrncpy char *  dest,
const char *  src,
size_t  size
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int sprintf char *  buf,
const char *  fmt,
... 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
char* strtok char *  str,
const char *  sep
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
char* strtok_r char *  str,
const char *  sep,
char **  last
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lib_8h-source.html b/doc/doxygen/html/lib_8h-source.html new file mode 100644 index 0000000..6aa75a6 --- /dev/null +++ b/doc/doxygen/html/lib_8h-source.html @@ -0,0 +1,59 @@ + + +Ubixos: lib.h Source File + + + +

lib.h

Go to the documentation of this file.
00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __ARCH_LIB_H__
+00036 #define __ARCH_LIB_H__
+00037 
+00038 #ifndef _STRING_H_
+00039 #ifndef _STRING_H
+00040 int strlen(const char *str);
+00041 int strncmp(const char *str1, const char *str2, int len);
+00042 void bcopy(const void *src, void *dest, int len);
+00043 void bzero(void *data, int n);
+00044 #endif /* _STRING_H */
+00045 #endif /* _STRING_H_ */
+00046 
+00047 #endif /* __ARCH_LIB_H__ */
+

Generated on Sat May 8 09:28:17 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lib_8h.html b/doc/doxygen/html/lib_8h.html new file mode 100644 index 0000000..2a9d2fb --- /dev/null +++ b/doc/doxygen/html/lib_8h.html @@ -0,0 +1,182 @@ + + +Ubixos: lib.h File Reference + + + +

lib.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + +

Functions

int strlen (const char *str)
int strncmp (const char *str1, const char *str2, int len)
void bcopy (const void *src, void *dest, int len)
void bzero (void *data, int n)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void bcopy const void *  src,
void *  dest,
int  len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void bzero void *  data,
int  n
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int strlen const char *  str  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int strncmp const char *  str1,
const char *  str2,
int  len
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:20 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/libcpp_8h-source.html b/doc/doxygen/html/libcpp_8h-source.html new file mode 100644 index 0000000..bbe2621 --- /dev/null +++ b/doc/doxygen/html/libcpp_8h-source.html @@ -0,0 +1,21 @@ + + +Ubixos: libcpp.h Source File + + + +

libcpp.h

00001 #ifndef __LIBCPP_H
+00002 #define __LIBCPP_H
+00003 
+00004 void * operator new(unsigned size);
+00005 void   operator delete(void * ptr);
+00006 void * operator new[](unsigned size);
+00007 void   operator delete[](void * ptr);
+00008 
+00009 #endif
+

Generated on Wed Apr 28 17:49:36 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/libcpp_8h.html b/doc/doxygen/html/libcpp_8h.html new file mode 100644 index 0000000..9df01d0 --- /dev/null +++ b/doc/doxygen/html/libcpp_8h.html @@ -0,0 +1,143 @@ + + +Ubixos: libcpp.h File Reference + + + +

libcpp.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + +

Functions

void * operator new (unsigned size)
void operator delete (void *ptr)
void * operator new[] (unsigned size)
void operator delete[] (void *ptr)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void operator delete void *  ptr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void operator delete[] void *  ptr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* operator new unsigned  size  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* operator new[] unsigned  size  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:21 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/list_8h-source.html b/doc/doxygen/html/list_8h-source.html new file mode 100644 index 0000000..602e9db --- /dev/null +++ b/doc/doxygen/html/list_8h-source.html @@ -0,0 +1,62 @@ + + +Ubixos: list.h Source File + + + +

list.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_LIST_H__
+00036 #define __LWIP_LIST_H__
+00037 
+00038 struct list;
+00039 
+00040 struct list *list_new(int size);
+00041 int list_push(struct list *list, void *elem);
+00042 void *list_pop(struct list *list);
+00043 int list_remove(struct list *list, void *elem);
+00044 void *list_first(struct list *list);
+00045 int list_elems(struct list *list);
+00046 void list_delete(struct list *list);
+00047 
+00048 void list_map(struct list *list, void (* func)(void *arg));
+00049 
+00050 #endif /* __LWIP_LIST_H__ */
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/list_8h.html b/doc/doxygen/html/list_8h.html new file mode 100644 index 0000000..d543a92 --- /dev/null +++ b/doc/doxygen/html/list_8h.html @@ -0,0 +1,294 @@ + + +Ubixos: list.h File Reference + + + +

list.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + +

Functions

list * list_new (int size)
int list_push (struct list *list, void *elem)
void * list_pop (struct list *list)
int list_remove (struct list *list, void *elem)
void * list_first (struct list *list)
int list_elems (struct list *list)
void list_delete (struct list *list)
void list_map (struct list *list, void(*func)(void *arg))
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void list_delete struct list *  list  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int list_elems struct list *  list  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* list_first struct list *  list  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void list_map struct list *  list,
void(*  func)(void *arg)
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct list* list_new int  size  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* list_pop struct list *  list  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int list_push struct list *  list,
void *  elem
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int list_remove struct list *  list,
void *  elem
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:21 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lnc_8h-source.html b/doc/doxygen/html/lnc_8h-source.html new file mode 100644 index 0000000..36f4961 --- /dev/null +++ b/doc/doxygen/html/lnc_8h-source.html @@ -0,0 +1,169 @@ + + +Ubixos: lnc.h Source File + + + +

lnc.h

00001 #ifndef _LNC_H
+00002 #define _LNC_H
+00003 
+00004 #include <ubixos/types.h>
+00005 
+00006 #define NDESC(len2) (1 << len2)
+00007 #define NORMAL 0
+00008 #define MEM_SLEW 8
+00009 #define TRANSBUFSIZE 1518
+00010 #define RECVBUFSIZE 1518
+00011 #define NRDRE 3
+00012 #define NTDRE 3
+00013 #define    ETHER_ADDR_LEN          6
+00014 #define NE2100_IOSIZE  24
+00015 #define PCNET_RDP    0x10        /* Register Data Port */
+00016 #define PCNET_RAP    0x12        /* Register Address Port */
+00017 #define PCNET_RESET  0x14
+00018 #define PCNET_BDP    0x16
+00019 #define PCNET_VSW    0x18
+00020 #define NE2100          2
+00021 
+00022 /* mem_mode values */
+00023 #define DMA_FIXED       1
+00024 #define DMA_MBUF        2
+00025 #define SHMEM           4
+00026 
+00027 
+00028 /********** Chip Types **********/
+00029 #define UNKNOWN         0        /* Unknown  */
+00030 #define LANCE           1        /* Am7990   */
+00031 #define C_LANCE         2        /* Am79C90  */
+00032 #define PCnet_ISA       3        /* Am79C960 */
+00033 #define PCnet_ISAplus   4        /* Am79C961 */
+00034 #define PCnet_ISA_II    5        /* Am79C961A */
+00035 #define PCnet_32        6        /* Am79C965 */
+00036 #define PCnet_PCI       7        /* Am79C970 */
+00037 #define PCnet_PCI_II    8        /* Am79C970A */
+00038 #define PCnet_FAST      9        /* Am79C971 */
+00039 #define PCnet_FASTplus  10       /* Am79C972 */
+00040 #define PCnet_Home      11       /* Am79C978 */
+00041 
+00042 /******** AM7990 Specifics **************/
+00043 #define CSR0    0x0000
+00044 #define CSR1    1
+00045 #define CSR2    2
+00046 #define CSR3    3
+00047 #define CSR88   88
+00048 #define CSR89   89
+00049 
+00050 #define ERR     0x8000
+00051 #define BABL    0x4000
+00052 #define CERR    0x2000
+00053 #define MISS    0x1000
+00054 #define MERR    0x0800
+00055 #define RINT    0x0400
+00056 #define TINT    0x0200
+00057 #define IDON    0x0100
+00058 #define INTR    0x0080
+00059 #define INEA    0x0040
+00060 #define RXON    0x0020
+00061 #define TXON    0x0010
+00062 #define TDMD    0x0008
+00063 #define STOP    0x0004
+00064 #define STRT    0x0002
+00065 #define INIT    0x0001
+00066 
+00067 
+00068 /* CSR88-89: Chip ID masks */
+00069 #define AMD_MASK  0x003
+00070 #define PART_MASK 0xffff
+00071 #define Am79C960  0x0003
+00072 #define Am79C961  0x2260
+00073 #define Am79C961A 0x2261
+00074 #define Am79C965  0x2430
+00075 #define Am79C970  0x0242
+00076 #define Am79C970A 0x2621
+00077 #define Am79C971  0x2623
+00078 #define Am79C972  0x2624
+00079 #define Am79C973  0x2625
+00080 #define Am79C978  0x2626
+00081 
+00082 /********** Structs **********/
+00083 
+00084 
+00085 
+00086 
+00087 struct initBlock {
+00088   uInt16 mode;           /* Mode register                        */
+00089   uInt8  padr[6];        /* Ethernet address                     */
+00090   uInt8  ladrf[8];       /* Logical address filter (multicast)   */
+00091   uInt16 rdra;           /* Low order pointer to receive ring    */
+00092   uInt16 rlen;           /* High order pointer and no. rings     */
+00093   uInt16 tdra;           /* Low order pointer to transmit ring   */
+00094   uInt16 tlen;           /* High order pointer and no rings      */
+00095   };
+00096 
+00097 struct mds {
+00098   uInt16 md0;
+00099   uInt16 md1;
+00100   short  md2;
+00101   uInt16 md3;
+00102   };
+00103 
+00104 struct hostRingEntry {
+00105   struct mds *md;
+00106   union {
+00107     //struct mbuf *mbuf;
+00108     char *data;
+00109     }buff;
+00110   };
+00111 
+00112 struct arpcom {
+00113   //struct  ifnet ac_if;            /* network-visible interface */
+00114   uInt8  ac_enaddr[6];           /* ethernet hardware address */
+00115   int    ac_multicnt;            /* length of ac_multiaddrs list */
+00116   void   *ac_netgraph;           /* ng_ether(4) netgraph node info */
+00117   };
+00118 
+00119 struct nicInfo {
+00120   int ident;         /* Type of card */
+00121   int ic;            /* Type of ic, Am7990, Am79C960 etc. */
+00122   int memMode;
+00123   int iobase;
+00124   int mode;          /* Mode setting at initialization */
+00125   };
+00126 
+00127 struct lncInfo {
+00128   struct arpcom        arpcom;
+00129   struct nicInfo       nic;
+00130   struct hostRingEntry *recvRing;
+00131   struct hostRingEntry *transRings;
+00132   struct initBlock     *initBloack;
+00133   int                  rap;
+00134   int                  rdp;
+00135   int                  bdp;
+00136   int                  nrdre;
+00137   int                  ntdre;
+00138   };
+00139 
+00140 extern struct lncInfo *lnc;
+00141 
+00142 void writeCsr(struct lncInfo *lnc, uInt16 port, uInt16 val);
+00143 uInt16 readCsr(struct lncInfo *lnc, uInt16 port);
+00144 void writeBcr(struct lncInfo *lnc, uInt16 port, uInt16 val);
+00145 uInt16 readBcr(struct lncInfo *lnc, uInt16 port);
+00146 
+00147 void initLNC();
+00148 int probe(struct lncInfo *lnc);
+00149 int lanceProbe(struct lncInfo *lnc);
+00150 int lncAttach(struct lncInfo *lnc,int unit);
+00151 
+00152 
+00153 void lncInt();
+00154 void _lncInt();
+00155 
+00156 #endif
+00157 
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lnc_8h.html b/doc/doxygen/html/lnc_8h.html new file mode 100644 index 0000000..120db7c --- /dev/null +++ b/doc/doxygen/html/lnc_8h.html @@ -0,0 +1,1966 @@ + + +Ubixos: lnc.h File Reference + + + +

lnc.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  arpcom
struct  hostRingEntry
struct  initBlock
struct  lncInfo
struct  mds
struct  nicInfo

Defines

#define NDESC(len2)   (1 << len2)
#define NORMAL   0
#define MEM_SLEW   8
#define TRANSBUFSIZE   1518
#define RECVBUFSIZE   1518
#define NRDRE   3
#define NTDRE   3
#define ETHER_ADDR_LEN   6
#define NE2100_IOSIZE   24
#define PCNET_RDP   0x10
#define PCNET_RAP   0x12
#define PCNET_RESET   0x14
#define PCNET_BDP   0x16
#define PCNET_VSW   0x18
#define NE2100   2
#define DMA_FIXED   1
#define DMA_MBUF   2
#define SHMEM   4
#define UNKNOWN   0
#define LANCE   1
#define C_LANCE   2
#define PCnet_ISA   3
#define PCnet_ISAplus   4
#define PCnet_ISA_II   5
#define PCnet_32   6
#define PCnet_PCI   7
#define PCnet_PCI_II   8
#define PCnet_FAST   9
#define PCnet_FASTplus   10
#define PCnet_Home   11
#define CSR0   0x0000
#define CSR1   1
#define CSR2   2
#define CSR3   3
#define CSR88   88
#define CSR89   89
#define ERR   0x8000
#define BABL   0x4000
#define CERR   0x2000
#define MISS   0x1000
#define MERR   0x0800
#define RINT   0x0400
#define TINT   0x0200
#define IDON   0x0100
#define INTR   0x0080
#define INEA   0x0040
#define RXON   0x0020
#define TXON   0x0010
#define TDMD   0x0008
#define STOP   0x0004
#define STRT   0x0002
#define INIT   0x0001
#define AMD_MASK   0x003
#define PART_MASK   0xffff
#define Am79C960   0x0003
#define Am79C961   0x2260
#define Am79C961A   0x2261
#define Am79C965   0x2430
#define Am79C970   0x0242
#define Am79C970A   0x2621
#define Am79C971   0x2623
#define Am79C972   0x2624
#define Am79C973   0x2625
#define Am79C978   0x2626

Functions

void writeCsr (struct lncInfo *lnc, uInt16 port, uInt16 val)
uInt16 readCsr (struct lncInfo *lnc, uInt16 port)
void writeBcr (struct lncInfo *lnc, uInt16 port, uInt16 val)
uInt16 readBcr (struct lncInfo *lnc, uInt16 port)
void initLNC ()
int probe (struct lncInfo *lnc)
int lanceProbe (struct lncInfo *lnc)
int lncAttach (struct lncInfo *lnc, int unit)
void lncInt ()
void _lncInt ()

Variables

lncInfolnc
+


Define Documentation

+

+ + + + +
+ + +
#define Am79C960   0x0003 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C961   0x2260 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C961A   0x2261 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C965   0x2430 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C970   0x0242 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C970A   0x2621 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C971   0x2623 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C972   0x2624 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C973   0x2625 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define Am79C978   0x2626 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define AMD_MASK   0x003 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define BABL   0x4000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define C_LANCE   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define CERR   0x2000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define CSR0   0x0000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define CSR1   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define CSR2   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define CSR3   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define CSR88   88 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define CSR89   89 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DMA_FIXED   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DMA_MBUF   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ERR   0x8000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ETHER_ADDR_LEN   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IDON   0x0100 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define INEA   0x0040 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define INIT   0x0001 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define INTR   0x0080 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LANCE   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEM_SLEW   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MERR   0x0800 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MISS   0x1000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define NDESClen2   )    (1 << len2) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE2100   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE2100_IOSIZE   24 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NORMAL   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NRDRE   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NTDRE   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PART_MASK   0xffff +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_32   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCNET_BDP   0x16 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_FAST   9 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_FASTplus   10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_Home   11 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_ISA   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_ISA_II   5 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_ISAplus   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_PCI   7 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCnet_PCI_II   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCNET_RAP   0x12 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCNET_RDP   0x10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCNET_RESET   0x14 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PCNET_VSW   0x18 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define RECVBUFSIZE   1518 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define RINT   0x0400 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define RXON   0x0020 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define SHMEM   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define STOP   0x0004 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define STRT   0x0002 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TDMD   0x0008 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TINT   0x0200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TRANSBUFSIZE   1518 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TXON   0x0010 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UNKNOWN   0 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void _lncInt  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void initLNC  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int lanceProbe struct lncInfo lnc  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int lncAttach struct lncInfo lnc,
int  unit
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void lncInt  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int probe struct lncInfo lnc  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uInt16 readBcr struct lncInfo lnc,
uInt16  port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uInt16 readCsr struct lncInfo lnc,
uInt16  port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void writeBcr struct lncInfo lnc,
uInt16  port,
uInt16  val
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void writeCsr struct lncInfo lnc,
uInt16  port,
uInt16  val
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct lncInfo* lnc +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:21 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/loopif_8h-source.html b/doc/doxygen/html/loopif_8h-source.html new file mode 100644 index 0000000..7e2deb1 --- /dev/null +++ b/doc/doxygen/html/loopif_8h-source.html @@ -0,0 +1,54 @@ + + +Ubixos: loopif.h Source File + + + +

loopif.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __NETIF_LOOPIF_H__
+00036 #define __NETIF_LOOPIF_H__
+00037 
+00038 #include "net/netif.h"
+00039 
+00040 void loopif_init(struct netif *netif);
+00041 
+00042 #endif /* __NETIF_LOOPIF_H__ */
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/loopif_8h.html b/doc/doxygen/html/loopif_8h.html new file mode 100644 index 0000000..161239a --- /dev/null +++ b/doc/doxygen/html/loopif_8h.html @@ -0,0 +1,51 @@ + + +Ubixos: loopif.h File Reference + + + +

loopif.h File Reference

#include "net/netif.h"
+ +

+Go to the source code of this file. + + + + +

Functions

void loopif_init (struct netif *netif)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void loopif_init struct netif netif  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:21 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lwipopts_8h-source.html b/doc/doxygen/html/lwipopts_8h-source.html new file mode 100644 index 0000000..e17c177 --- /dev/null +++ b/doc/doxygen/html/lwipopts_8h-source.html @@ -0,0 +1,186 @@ + + +Ubixos: lwipopts.h Source File + + + +

lwipopts.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIPOPTS_H__
+00036 #define __LWIPOPTS_H__
+00037 
+00038 /* ---------- Memory options ---------- */
+00039 /* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
+00040    lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
+00041    byte alignment -> define MEM_ALIGNMENT to 2. */
+00042 #define MEM_ALIGNMENT           2
+00043 
+00044 /* MEM_SIZE: the size of the heap memory. If the application will send
+00045 a lot of data that needs to be copied, this should be set high. */
+00046 #define MEM_SIZE                1000
+00047 
+00048 /* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
+00049    sends a lot of data out of ROM (or other static memory), this
+00050    should be set high. */
+00051 #define MEMP_NUM_PBUF           8
+00052 /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
+00053    per active UDP "connection". */
+00054 #define MEMP_NUM_UDP_PCB        4
+00055 /* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
+00056    connections. */
+00057 #define MEMP_NUM_TCP_PCB        5
+00058 /* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
+00059    connections. */
+00060 #define MEMP_NUM_TCP_PCB_LISTEN 8
+00061 /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
+00062    segments. */
+00063 #define MEMP_NUM_TCP_SEG        8
+00064 /* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
+00065    timeouts. */
+00066 #define MEMP_NUM_SYS_TIMEOUT    3
+00067 
+00068 
+00069 /* The following four are used only with the sequential API and can be
+00070    set to 0 if the application only will use the raw API. */
+00071 /* MEMP_NUM_NETBUF: the number of struct netbufs. */
+00072 #define MEMP_NUM_NETBUF         2
+00073 /* MEMP_NUM_NETCONN: the number of struct netconns. */
+00074 #define MEMP_NUM_NETCONN        4
+00075 /* MEMP_NUM_APIMSG: the number of struct api_msg, used for
+00076    communication between the TCP/IP stack and the sequential
+00077    programs. */
+00078 #define MEMP_NUM_API_MSG        8
+00079 /* MEMP_NUM_TCPIPMSG: the number of struct tcpip_msg, which is used
+00080    for sequential API communication and incoming packets. Used in
+00081    src/api/tcpip.c. */
+00082 #define MEMP_NUM_TCPIP_MSG      8
+00083 
+00084 /* These two control is reclaimer functions should be compiled
+00085    in. Should always be turned on (1). */
+00086 #define MEM_RECLAIM             1
+00087 #define MEMP_RECLAIM            1
+00088 
+00089 /* ---------- Pbuf options ---------- */
+00090 /* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
+00091 #define PBUF_POOL_SIZE          6
+00092 
+00093 /* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
+00094 #define PBUF_POOL_BUFSIZE       128
+00095 
+00096 /* PBUF_LINK_HLEN: the number of bytes that should be allocated for a
+00097    link level header. */
+00098 #define PBUF_LINK_HLEN          16
+00099 
+00100 /* ---------- TCP options ---------- */
+00101 #define LWIP_TCP                1
+00102 #define TCP_TTL                 255
+00103 
+00104 /* Controls if TCP should queue segments that arrive out of
+00105    order. Define to 0 if your device is low on memory. */
+00106 #define TCP_QUEUE_OOSEQ         1
+00107 
+00108 /* TCP Maximum segment size. */
+00109 #define TCP_MSS                 128
+00110 
+00111 /* TCP sender buffer space (bytes). */
+00112 #define TCP_SND_BUF             256
+00113 
+00114 /* TCP sender buffer space (pbufs). This must be at least = 2 *
+00115    TCP_SND_BUF/TCP_MSS for things to work. */
+00116 #define TCP_SND_QUEUELEN        4 * TCP_SND_BUF/TCP_MSS
+00117 
+00118 /* TCP receive window. */
+00119 #define TCP_WND                 1024
+00120 
+00121 /* Maximum number of retransmissions of data segments. */
+00122 #define TCP_MAXRTX              12
+00123 
+00124 /* Maximum number of retransmissions of SYN segments. */
+00125 #define TCP_SYNMAXRTX           4
+00126 
+00127 /* ---------- ARP options ---------- */
+00128 #define ARP_TABLE_SIZE 10
+00129 
+00130 /* ---------- IP options ---------- */
+00131 /* Define IP_FORWARD to 1 if you wish to have the ability to forward
+00132    IP packets across network interfaces. If you are going to run lwIP
+00133    on a device with only one network interface, define this to 0. */
+00134 #define IP_FORWARD              1
+00135 
+00136 /* If defined to 1, IP options are allowed (but not parsed). If
+00137    defined to 0, all packets with IP options are dropped. */
+00138 #define IP_OPTIONS              1
+00139 
+00140 /* ---------- ICMP options ---------- */
+00141 #define ICMP_TTL                255
+00142 
+00143 
+00144 /* ---------- DHCP options ---------- */
+00145 /* Define LWIP_DHCP to 1 if you want DHCP configuration of
+00146    interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
+00147    turning this on does currently not work. */
+00148 #define LWIP_DHCP               0
+00149 
+00150 /* 1 if you want to do an ARP check on the offered address
+00151    (recommended). */
+00152 #define DHCP_DOES_ARP_CHECK     1
+00153 
+00154 /* ---------- UDP options ---------- */
+00155 #define LWIP_UDP                1
+00156 #define UDP_TTL                 255
+00157 
+00158 
+00159 /* ---------- Statistics options ---------- */
+00160 #define STATS
+00161 
+00162 #ifdef STATS
+00163 #define LINK_STATS
+00164 #define IP_STATS
+00165 #define ICMP_STATS
+00166 #define UDP_STATS
+00167 #define TCP_STATS
+00168 #define MEM_STATS
+00169 #define MEMP_STATS
+00170 #define PBUF_STATS
+00171 #define SYS_STATS
+00172 #endif /* STATS */
+00173 
+00174 #endif /* __LWIPOPTS_H__ */
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/lwipopts_8h.html b/doc/doxygen/html/lwipopts_8h.html new file mode 100644 index 0000000..a9b48c0 --- /dev/null +++ b/doc/doxygen/html/lwipopts_8h.html @@ -0,0 +1,1075 @@ + + +Ubixos: lwipopts.h File Reference + + + +

lwipopts.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define MEM_ALIGNMENT   2
#define MEM_SIZE   1000
#define MEMP_NUM_PBUF   8
#define MEMP_NUM_UDP_PCB   4
#define MEMP_NUM_TCP_PCB   5
#define MEMP_NUM_TCP_PCB_LISTEN   8
#define MEMP_NUM_TCP_SEG   8
#define MEMP_NUM_SYS_TIMEOUT   3
#define MEMP_NUM_NETBUF   2
#define MEMP_NUM_NETCONN   4
#define MEMP_NUM_API_MSG   8
#define MEMP_NUM_TCPIP_MSG   8
#define MEM_RECLAIM   1
#define MEMP_RECLAIM   1
#define PBUF_POOL_SIZE   6
#define PBUF_POOL_BUFSIZE   128
#define PBUF_LINK_HLEN   16
#define LWIP_TCP   1
#define TCP_TTL   255
#define TCP_QUEUE_OOSEQ   1
#define TCP_MSS   128
#define TCP_SND_BUF   256
#define TCP_SND_QUEUELEN   4 * TCP_SND_BUF/TCP_MSS
#define TCP_WND   1024
#define TCP_MAXRTX   12
#define TCP_SYNMAXRTX   4
#define ARP_TABLE_SIZE   10
#define IP_FORWARD   1
#define IP_OPTIONS   1
#define ICMP_TTL   255
#define LWIP_DHCP   0
#define DHCP_DOES_ARP_CHECK   1
#define LWIP_UDP   1
#define UDP_TTL   255
#define STATS
#define LINK_STATS
#define IP_STATS
#define ICMP_STATS
#define UDP_STATS
#define TCP_STATS
#define MEM_STATS
#define MEMP_STATS
#define PBUF_STATS
#define SYS_STATS
+


Define Documentation

+

+ + + + +
+ + +
#define ARP_TABLE_SIZE   10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DHCP_DOES_ARP_CHECK   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ICMP_TTL   255 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_FORWARD   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_OPTIONS   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IP_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LINK_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LWIP_DHCP   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LWIP_TCP   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LWIP_UDP   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEM_ALIGNMENT   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEM_RECLAIM   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEM_SIZE   1000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEM_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_API_MSG   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_NETBUF   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_NETCONN   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_PBUF   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_SYS_TIMEOUT   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_TCP_PCB   5 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_TCP_PCB_LISTEN   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_TCP_SEG   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_TCPIP_MSG   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_NUM_UDP_PCB   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_RECLAIM   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEMP_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_LINK_HLEN   16 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_POOL_BUFSIZE   128 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_POOL_SIZE   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define SYS_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_MAXRTX   12 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_MSS   128 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_QUEUE_OOSEQ   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_SND_BUF   256 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_SND_QUEUELEN   4 * TCP_SND_BUF/TCP_MSS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_SYNMAXRTX   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_TTL   255 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_WND   1024 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UDP_STATS +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UDP_TTL   255 +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:21 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/math_8h-source.html b/doc/doxygen/html/math_8h-source.html new file mode 100644 index 0000000..5d38d6c --- /dev/null +++ b/doc/doxygen/html/math_8h-source.html @@ -0,0 +1,24 @@ + + +Ubixos: math.h Source File + + + +

math.h

00001 #ifndef __MATH_H
+00002 #define __MATH_H
+00003 
+00004 typedef long long int quad_t;
+00005 typedef unsigned long long int u_quad_t;
+00006 
+00007 double atan(double x);
+00008 double sqrt(double x);
+00009 u_quad_t __udivdi3(u_quad_t a,u_quad_t b);
+00010 quad_t __divdi3(quad_t a,quad_t b);
+00011 
+00012 #endif
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/math_8h.html b/doc/doxygen/html/math_8h.html new file mode 100644 index 0000000..ad23f77 --- /dev/null +++ b/doc/doxygen/html/math_8h.html @@ -0,0 +1,211 @@ + + +Ubixos: math.h File Reference + + + +

math.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + + +

Typedefs

typedef long long int quad_t
typedef unsigned long long int u_quad_t

Functions

double atan (double x)
double sqrt (double x)
u_quad_t __udivdi3 (u_quad_t a, u_quad_t b)
quad_t __divdi3 (quad_t a, quad_t b)
+


Typedef Documentation

+

+ + + + +
+ + +
typedef long long int quad_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef unsigned long long int u_quad_t +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
quad_t __divdi3 quad_t  a,
quad_t  b
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
u_quad_t __udivdi3 u_quad_t  a,
u_quad_t  b
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
double atan double  x  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
double sqrt double  x  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/mem_8h-source.html b/doc/doxygen/html/mem_8h-source.html new file mode 100644 index 0000000..cef72d1 --- /dev/null +++ b/doc/doxygen/html/mem_8h-source.html @@ -0,0 +1,92 @@ + + +Ubixos: mem.h Source File + + + +

mem.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_MEM_H__
+00036 #define __LWIP_MEM_H__
+00037 
+00038 #include <ubixos/types.h>
+00039 
+00040 #include "net/debug.h"
+00041 #include "net/opt.h"
+00042 #include "net/arch.h"
+00043 
+00044 #if MEM_SIZE > 64000l
+00045 typedef uInt32 mem_size_t;
+00046 #else
+00047 typedef uInt16 mem_size_t;
+00048 #endif /* MEM_SIZE > 64000 */
+00049 
+00050 
+00051 void mem_init(void);
+00052 
+00053 void *mem_malloc(mem_size_t size);
+00054 void *mem_malloc2(mem_size_t size);
+00055 void mem_free(void *mem);
+00056 void *mem_realloc(void *mem, mem_size_t size);
+00057 void *mem_reallocm(void *mem, mem_size_t size);
+00058 
+00059 #ifdef MEM_PERF
+00060 void mem_perf_start(void);
+00061 void mem_perf_init(char *fname);
+00062 #endif /* MEM_PERF */
+00063 
+00064 #ifdef MEM_RECLAIM
+00065 typedef mem_size_t (*mem_reclaim_func)(void *arg, mem_size_t size);
+00066 void mem_register_reclaim(mem_reclaim_func f, void *arg);
+00067 void mem_reclaim(unsigned int size);
+00068 #else
+00069 #define mem_register_reclaim(f, arg)
+00070 #endif /* MEM_RECLAIM */
+00071 
+00072 
+00073 #define MEM_ALIGN_SIZE(size) (size + \
+00074                              ((((size) % MEM_ALIGNMENT) == 0)? 0 : \
+00075                              (MEM_ALIGNMENT - ((size) % MEM_ALIGNMENT))))
+00076 
+00077 #define MEM_ALIGN(addr) (void *)MEM_ALIGN_SIZE((uInt32)addr)
+00078 
+00079 #endif /* __LWIP_MEM_H__ */
+00080 
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/mem_8h.html b/doc/doxygen/html/mem_8h.html new file mode 100644 index 0000000..44feb75 --- /dev/null +++ b/doc/doxygen/html/mem_8h.html @@ -0,0 +1,348 @@ + + +Ubixos: mem.h File Reference + + + +

mem.h File Reference

#include <ubixos/types.h>
+#include "net/debug.h"
+#include "net/opt.h"
+#include "net/arch.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define mem_register_reclaim(f, arg)
#define MEM_ALIGN_SIZE(size)
#define MEM_ALIGN(addr)   (void *)MEM_ALIGN_SIZE((uInt32)addr)

Typedefs

typedef uInt16 mem_size_t

Functions

void mem_init (void)
void * mem_malloc (mem_size_t size)
void * mem_malloc2 (mem_size_t size)
void mem_free (void *mem)
void * mem_realloc (void *mem, mem_size_t size)
void * mem_reallocm (void *mem, mem_size_t size)
+


Define Documentation

+

+ + + + +
+ + + + + + + +
#define MEM_ALIGNaddr   )    (void *)MEM_ALIGN_SIZE((uInt32)addr) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define MEM_ALIGN_SIZEsize   )  +
+
+ + + + + +
+   + + +

+Value:

(size + \
+                             ((((size) % MEM_ALIGNMENT) == 0)? 0 : \
+                             (MEM_ALIGNMENT - ((size) % MEM_ALIGNMENT))))
+
+

+ + + + +
+ + + + + + + + + + +
#define mem_register_reclaimf,
arg   )  +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef uInt16 mem_size_t +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void mem_free void *  mem  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void mem_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* mem_malloc mem_size_t  size  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* mem_malloc2 mem_size_t  size  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void* mem_realloc void *  mem,
mem_size_t  size
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void* mem_reallocm void *  mem,
mem_size_t  size
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/memp_8h-source.html b/doc/doxygen/html/memp_8h-source.html new file mode 100644 index 0000000..96c969e --- /dev/null +++ b/doc/doxygen/html/memp_8h-source.html @@ -0,0 +1,91 @@ + + +Ubixos: memp.h Source File + + + +

memp.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 
+00036 #ifndef __LWIP_MEMP_H__
+00037 #define __LWIP_MEMP_H__
+00038 
+00039 #include <ubixos/types.h>
+00040 
+00041 #include "net/debug.h"
+00042 #include "net/arch/cc.h"
+00043 #include "net/lwipopts.h"
+00044 
+00045 typedef enum {
+00046   MEMP_PBUF,
+00047   MEMP_UDP_PCB,
+00048   MEMP_TCP_PCB,
+00049   MEMP_TCP_PCB_LISTEN,
+00050   MEMP_TCP_SEG,
+00051 
+00052   MEMP_NETBUF,
+00053   MEMP_NETCONN,
+00054   MEMP_API_MSG,
+00055   MEMP_TCPIP_MSG,
+00056 
+00057   MEMP_SYS_TIMEOUT,
+00058   
+00059   MEMP_MAX
+00060 } memp_t;
+00061 
+00062 void memp_init(void);
+00063 
+00064 void *memp_malloc(memp_t type);
+00065 void *memp_mallocp(memp_t type);
+00066 void *memp_malloc2(memp_t type);
+00067 void *memp_realloc(memp_t fromtype, memp_t totype, void *mem);
+00068 void memp_free(memp_t type, void *mem);
+00069 void memp_freep(memp_t type, void *mem);
+00070 
+00071 #if MEMP_RECLAIM
+00072 typedef uInt8 (*memp_reclaim_func)(void *arg, memp_t type);
+00073 void memp_register_reclaim(memp_t type, memp_reclaim_func f, void *arg);
+00074 #else 
+00075 #define memp_register_reclaim(t, f, arg)
+00076 #endif /* MEMP_RECLAIM */
+00077 
+00078 #endif /* __LWIP_MEMP_H__  */
+00079           
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/memp_8h.html b/doc/doxygen/html/memp_8h.html new file mode 100644 index 0000000..aa83e86 --- /dev/null +++ b/doc/doxygen/html/memp_8h.html @@ -0,0 +1,377 @@ + + +Ubixos: memp.h File Reference + + + +

memp.h File Reference

#include <ubixos/types.h>
+#include "net/debug.h"
+#include "net/arch/cc.h"
+#include "net/lwipopts.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define memp_register_reclaim(t, f, arg)

Enumerations

enum  memp_t {
+  MEMP_PBUF, +MEMP_UDP_PCB, +MEMP_TCP_PCB, +MEMP_TCP_PCB_LISTEN, +
+  MEMP_TCP_SEG, +MEMP_NETBUF, +MEMP_NETCONN, +MEMP_API_MSG, +
+  MEMP_TCPIP_MSG, +MEMP_SYS_TIMEOUT, +MEMP_MAX +
+ }

Functions

void memp_init (void)
void * memp_malloc (memp_t type)
void * memp_mallocp (memp_t type)
void * memp_malloc2 (memp_t type)
void * memp_realloc (memp_t fromtype, memp_t totype, void *mem)
void memp_free (memp_t type, void *mem)
void memp_freep (memp_t type, void *mem)
+


Define Documentation

+

+ + + + +
+ + + + + + + + + + + + + +
#define memp_register_reclaimt,
f,
arg   )  +
+
+ + + + + +
+   + + +

+

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum memp_t +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + + + + + + + + +
MEMP_PBUF  +
MEMP_UDP_PCB  +
MEMP_TCP_PCB  +
MEMP_TCP_PCB_LISTEN  +
MEMP_TCP_SEG  +
MEMP_NETBUF  +
MEMP_NETCONN  +
MEMP_API_MSG  +
MEMP_TCPIP_MSG  +
MEMP_SYS_TIMEOUT  +
MEMP_MAX  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void memp_free memp_t  type,
void *  mem
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void memp_freep memp_t  type,
void *  mem
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void memp_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* memp_malloc memp_t  type  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* memp_malloc2 memp_t  type  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* memp_mallocp memp_t  type  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void* memp_realloc memp_t  fromtype,
memp_t  totype,
void *  mem
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/mount_8h-source.html b/doc/doxygen/html/mount_8h-source.html new file mode 100644 index 0000000..edbd31e --- /dev/null +++ b/doc/doxygen/html/mount_8h-source.html @@ -0,0 +1,58 @@ + + +Ubixos: mount.h Source File + + + +

mount.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _MOUNT_H
+00025 #define _MOUNT_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 struct mountPoints {
+00030   struct mountPoints *prev;
+00031   struct mountPoints *next;
+00032   struct fileSystem  *fs;
+00033   struct deviceNode  *device;
+00034   struct ubixDiskLabel   *diskLabel;
+00035   void               *fsInfo;
+00036   int                partition;
+00037   char               mountPoint[1024];
+00038   char               perms;
+00039   };
+00040 
+00041 int mount(int driveId,int partition,int fsType,char *mountPoint,char *perms);
+00042 int addMount(struct mountPoints *mp);
+00043 struct mountPoints *findMount(char *mountPoint);
+00044 
+00045 #endif
+00046 
+

Generated on Wed Apr 28 17:49:37 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/mount_8h.html b/doc/doxygen/html/mount_8h.html new file mode 100644 index 0000000..5fc618a --- /dev/null +++ b/doc/doxygen/html/mount_8h.html @@ -0,0 +1,149 @@ + + +Ubixos: mount.h File Reference + + + +

mount.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + +

Data Structures

struct  mountPoints

Functions

int mount (int major, int minor, int partition, int fsType, char *mountPoint, char *perms)
int addMount (struct mountPoints *mp)
mountPointsfindMount (char *mountPoint)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
int addMount struct mountPoints mp  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct mountPoints* findMount char *  mountPoint  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int mount int  major,
int  minor,
int  partition,
int  fsType,
char *  mountPoint,
char *  perms
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ne2k_8h-source.html b/doc/doxygen/html/ne2k_8h-source.html new file mode 100644 index 0000000..6249596 --- /dev/null +++ b/doc/doxygen/html/ne2k_8h-source.html @@ -0,0 +1,186 @@ + + +Ubixos: ne2k.h Source File + + + +

ne2k.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _NE2K_H
+00025 #define _NE2K_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <sys/device.old.h>
+00029 
+00030 #define ether_addr  ether_addr_t
+00031 typedef struct dp_rcvhdr
+00032 {
+00033         uInt8 dr_status;                 /* Copy of rsr                       */
+00034         uInt8 dr_next;                   /* Pointer to next packet            */
+00035         uInt8 dr_rbcl;                   /* Receive Byte Count Low            */
+00036         uInt8 dr_rbch;                   /* Receive Byte Count High           */
+00037 } dp_rcvhdr_t;
+00038 
+00039 typedef union etheraddr {
+00040     unsigned char bytes[6];             /* byteorder safe initialization */
+00041     unsigned short shorts[3];           /* force 2-byte alignment */
+00042 } ether_addr;
+00043 
+00044 
+00045 struct nicBuffer {
+00046   struct nicBuffer *next;
+00047   int               length;
+00048   char             *buffer;
+00049   };
+00050 
+00051 #define RSR_FO         0x08
+00052 #define RSR_PRX                0x01
+00053 #define DEF_ENABLED    0x200
+00054 
+00055 #define OK      0
+00056 
+00057 
+00058 #define startPage 0x4C
+00059 #define stopPage  0x80
+00060 
+00061 
+00062 #define NE_CMD       0x00
+00063 #define NE_PSTART    0x01
+00064 #define NE_PSTOP     0x02
+00065 #define NE_BNRY      0x03
+00066 #define NE_TPSR      0x04
+00067 #define NE_ISR       0x07
+00068 #define NE_CURRENT   0x07
+00069 #define NE_RBCR0     0x0A
+00070 #define NE_RBCR1     0x0B
+00071 #define NE_RCR       0x0C
+00072 #define NE_TCR       0x0D
+00073 #define NE_DCR       0x0E
+00074 #define NE_IMR       0x0F
+00075 
+00076 
+00077 #define NE_DCR_WTS   0x01
+00078 #define NE_DCR_LS    0x08
+00079 #define NE_DCR_AR    0x10
+00080 #define NE_DCR_FT1   0x40
+00081 #define NE_DCR_FT0   0x20
+00082 
+00083 
+00084 
+00085 #define E8390_STOP   0x01
+00086 #define E8390_NODMA  0x20
+00087 #define E8390_PAGE0  0x00
+00088 #define E8390_PAGE1  0x40
+00089 #define E8390_CMD    0x00
+00090 #define E8390_START  0x02
+00091 #define E8390_RREAD  0x08
+00092 #define E8390_RWRITE 0x10
+00093 #define E8390_RXOFF  0x20
+00094 #define E8390_TXOFF  0x00
+00095 #define E8390_RXCONFIG 0x04
+00096 #define E8390_TXCONFIG 0x00
+00097 
+00098 #define EN0_COUNTER0 0x0d
+00099 #define EN0_DCFG     0x0e
+00100 #define EN0_RCNTLO   0x0a
+00101 #define EN0_RCNTHI   0x0b
+00102 #define EN0_ISR      0x07
+00103 #define EN0_IMR      0x0f
+00104 #define EN0_RSARLO   0x08
+00105 #define EN0_RSARHI   0x09
+00106 #define EN0_TPSR     0x04
+00107 #define EN0_RXCR     0x0c
+00108 #define EN0_TXCR     0x0D
+00109 #define EN0_STARTPG  0x01
+00110 #define EN0_STOPPG   0x02
+00111 #define EN0_BOUNDARY 0x03
+00112 
+00113 #define EN1_PHYS     0x01
+00114 #define EN1_CURPAG   0x07
+00115 #define EN1_MULT     0x08
+00116 
+00117 #define NE1SM_START_PG 0x20
+00118 #define NE1SM_STOP_PG 0x40
+00119 #define NESM_START_PG 0x40
+00120 #define NESM_STOP_PG  0x80
+00121 
+00122 #define ENISR_ALL    0x3f
+00123 
+00124 #define ENDCFG_WTS   0x01
+00125 
+00126 #define NE_DATAPORT  0x10
+00127 
+00128 #define TX_2X_PAGES 12
+00129 #define TX_1X_PAGES 6
+00130 #define TX_PAGES (dev->priv->pingPong ? TX_2X_PAGES : TX_1X_PAGES)
+00131 
+00132 
+00133 #define DP_CURR         0x7     /* Current Page Register             */
+00134 #define DP_MAR0         0x8     /* Multicast Address Register 0      */
+00135 #define DP_MAR1         0x9     /* Multicast Address Register 1      */
+00136 #define DP_MAR2         0xA     /* Multicast Address Register 2      */
+00137 #define DP_MAR3         0xB     /* Multicast Address Register 3      */
+00138 #define DP_MAR4         0xC     /* Multicast Address Register 4      */
+00139 #define DP_MAR5         0xD     /* Multicast Address Register 5      */
+00140 #define DP_MAR6         0xE     /* Multicast Address Register 6      */
+00141 #define DP_MAR7         0xF     /* Multicast Address Register 7      */
+00142 
+00143 #define DP_CNTR0        0xD     /* Tally Counter 0                   */
+00144 #define DP_CNTR1        0xE     /* Tally Counter 1                   */
+00145 #define DP_CNTR2        0xF     /* Tally Counter 2                   */
+00146 
+00147 
+00148 #define DP_PAGESIZE     256
+00149 
+00150 extern char *nicPacket;
+00151 extern uInt32 packetLength;
+00152 
+00153 
+00154 int ne2kInit(uInt32);
+00155 int ne2kProbe(int,struct device *);
+00156 int ne2kDevInit(struct device *);
+00157 void NS8390_init(struct device *dev,int startp);
+00158 
+00159 void ne2kISR();
+00160 void ne2kHandler();
+00161 
+00162 int NICtoPC(struct device *dev,void *packet,int length,int nic_addr);
+00163 int PCtoNIC(struct device *dev,void *packet,int length);
+00164 
+00165 struct nicBuffer *ne2kAllocBuffer(int);
+00166 struct nicBuffer *ne2kGetBuffer();
+00167 void ne2kFreeBuffer(struct nicBuffer *);
+00168 
+00169 #endif
+00170 
+00171 /***
+00172  END
+00173  ***/
+00174 
+

Generated on Wed Apr 28 17:49:38 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ne2k_8h.html b/doc/doxygen/html/ne2k_8h.html new file mode 100644 index 0000000..c5f89b3 --- /dev/null +++ b/doc/doxygen/html/ne2k_8h.html @@ -0,0 +1,2370 @@ + + +Ubixos: ne2k.h File Reference + + + +

ne2k.h File Reference

#include <ubixos/types.h>
+#include <sys/device.old.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  dp_rcvhdr
union  etheraddr
struct  nicBuffer

Defines

#define ether_addr   ether_addr_t
#define RSR_FO   0x08
#define RSR_PRX   0x01
#define DEF_ENABLED   0x200
#define OK   0
#define startPage   0x4C
#define stopPage   0x80
#define NE_CMD   0x00
#define NE_PSTART   0x01
#define NE_PSTOP   0x02
#define NE_BNRY   0x03
#define NE_TPSR   0x04
#define NE_ISR   0x07
#define NE_CURRENT   0x07
#define NE_RBCR0   0x0A
#define NE_RBCR1   0x0B
#define NE_RCR   0x0C
#define NE_TCR   0x0D
#define NE_DCR   0x0E
#define NE_IMR   0x0F
#define NE_DCR_WTS   0x01
#define NE_DCR_LS   0x08
#define NE_DCR_AR   0x10
#define NE_DCR_FT1   0x40
#define NE_DCR_FT0   0x20
#define E8390_STOP   0x01
#define E8390_NODMA   0x20
#define E8390_PAGE0   0x00
#define E8390_PAGE1   0x40
#define E8390_CMD   0x00
#define E8390_START   0x02
#define E8390_RREAD   0x08
#define E8390_RWRITE   0x10
#define E8390_RXOFF   0x20
#define E8390_TXOFF   0x00
#define E8390_RXCONFIG   0x04
#define E8390_TXCONFIG   0x00
#define EN0_COUNTER0   0x0d
#define EN0_DCFG   0x0e
#define EN0_RCNTLO   0x0a
#define EN0_RCNTHI   0x0b
#define EN0_ISR   0x07
#define EN0_IMR   0x0f
#define EN0_RSARLO   0x08
#define EN0_RSARHI   0x09
#define EN0_TPSR   0x04
#define EN0_RXCR   0x0c
#define EN0_TXCR   0x0D
#define EN0_STARTPG   0x01
#define EN0_STOPPG   0x02
#define EN0_BOUNDARY   0x03
#define EN1_PHYS   0x01
#define EN1_CURPAG   0x07
#define EN1_MULT   0x08
#define NE1SM_START_PG   0x20
#define NE1SM_STOP_PG   0x40
#define NESM_START_PG   0x40
#define NESM_STOP_PG   0x80
#define ENISR_ALL   0x3f
#define ENDCFG_WTS   0x01
#define NE_DATAPORT   0x10
#define TX_2X_PAGES   12
#define TX_1X_PAGES   6
#define TX_PAGES   (dev->priv->pingPong ? TX_2X_PAGES : TX_1X_PAGES)
#define DP_CURR   0x7
#define DP_MAR0   0x8
#define DP_MAR1   0x9
#define DP_MAR2   0xA
#define DP_MAR3   0xB
#define DP_MAR4   0xC
#define DP_MAR5   0xD
#define DP_MAR6   0xE
#define DP_MAR7   0xF
#define DP_CNTR0   0xD
#define DP_CNTR1   0xE
#define DP_CNTR2   0xF
#define DP_PAGESIZE   256

Typedefs

typedef dp_rcvhdr dp_rcvhdr_t
typedef etheraddr ether_addr

Functions

int ne2kInit (uInt32)
int ne2kProbe (int, struct device *)
int ne2kDevInit (struct device *)
void NS8390_init (struct device *dev, int startp)
void ne2kISR ()
void ne2kHandler ()
int NICtoPC (struct device *dev, void *packet, int length, int nic_addr)
int PCtoNIC (struct device *dev, void *packet, int length)
nicBufferne2kAllocBuffer (int)
nicBufferne2kGetBuffer ()
void ne2kFreeBuffer (struct nicBuffer *)

Variables

char * nicPacket
uInt32 packetLength
+


Define Documentation

+

+ + + + +
+ + +
#define DEF_ENABLED   0x200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_CNTR0   0xD +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_CNTR1   0xE +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_CNTR2   0xF +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_CURR   0x7 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR0   0x8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR1   0x9 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR2   0xA +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR3   0xB +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR4   0xC +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR5   0xD +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR6   0xE +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_MAR7   0xF +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DP_PAGESIZE   256 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_CMD   0x00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_NODMA   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_PAGE0   0x00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_PAGE1   0x40 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_RREAD   0x08 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_RWRITE   0x10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_RXCONFIG   0x04 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_RXOFF   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_START   0x02 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_STOP   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_TXCONFIG   0x00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define E8390_TXOFF   0x00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_BOUNDARY   0x03 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_COUNTER0   0x0d +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_DCFG   0x0e +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_IMR   0x0f +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_ISR   0x07 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_RCNTHI   0x0b +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_RCNTLO   0x0a +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_RSARHI   0x09 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_RSARLO   0x08 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_RXCR   0x0c +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_STARTPG   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_STOPPG   0x02 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_TPSR   0x04 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN0_TXCR   0x0D +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN1_CURPAG   0x07 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN1_MULT   0x08 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EN1_PHYS   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ENDCFG_WTS   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ENISR_ALL   0x3f +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define ether_addr   ether_addr_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE1SM_START_PG   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE1SM_STOP_PG   0x40 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_BNRY   0x03 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_CMD   0x00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_CURRENT   0x07 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_DATAPORT   0x10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_DCR   0x0E +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_DCR_AR   0x10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_DCR_FT0   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_DCR_FT1   0x40 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_DCR_LS   0x08 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_DCR_WTS   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_IMR   0x0F +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_ISR   0x07 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_PSTART   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_PSTOP   0x02 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_RBCR0   0x0A +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_RBCR1   0x0B +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_RCR   0x0C +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_TCR   0x0D +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NE_TPSR   0x04 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NESM_START_PG   0x40 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define NESM_STOP_PG   0x80 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define OK   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define RSR_FO   0x08 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define RSR_PRX   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define startPage   0x4C +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define stopPage   0x80 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TX_1X_PAGES   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TX_2X_PAGES   12 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TX_PAGES   (dev->priv->pingPong ? TX_2X_PAGES : TX_1X_PAGES) +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct dp_rcvhdr dp_rcvhdr_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef union etheraddr ether_addr +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
struct nicBuffer* ne2kAllocBuffer int   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ne2kDevInit struct device  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void ne2kFreeBuffer struct nicBuffer  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
struct nicBuffer* ne2kGetBuffer  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void ne2kHandler  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ne2kInit uInt32   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void ne2kISR  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int ne2kProbe int ,
struct device
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int NICtoPC struct device dev,
void *  packet,
int  length,
int  nic_addr
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NS8390_init struct device dev,
int  startp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int PCtoNIC struct device dev,
void *  packet,
int  length
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
char* nicPacket +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 packetLength +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/net_8h-source.html b/doc/doxygen/html/net_8h-source.html new file mode 100644 index 0000000..99e551e --- /dev/null +++ b/doc/doxygen/html/net_8h-source.html @@ -0,0 +1,48 @@ + + +Ubixos: net.h Source File + + + +

net.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _NET_H
+00025 #define _NET_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 void netInit();
+00030 
+00031 #endif
+00032 
+00033 /***
+00034  END
+00035  ***/
+00036 
+

Generated on Wed Apr 28 17:49:38 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/net_8h.html b/doc/doxygen/html/net_8h.html new file mode 100644 index 0000000..84fbf21 --- /dev/null +++ b/doc/doxygen/html/net_8h.html @@ -0,0 +1,50 @@ + + +Ubixos: net.h File Reference + + + +

net.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + +

Functions

void netInit ()
+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void netInit  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/netif_8h-source.html b/doc/doxygen/html/netif_8h-source.html new file mode 100644 index 0000000..70c42d4 --- /dev/null +++ b/doc/doxygen/html/netif_8h-source.html @@ -0,0 +1,111 @@ + + +Ubixos: netif.h Source File + + + +

netif.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_NETIF_H__
+00036 #define __LWIP_NETIF_H__
+00037 
+00038 #include "net/opt.h"
+00039 
+00040 #include "net/err.h"
+00041 
+00042 #include "net/ipv4/ip_addr.h"
+00043 #include "net/ipv4/inet.h"
+00044 
+00045 #include "net/pbuf.h"
+00046 
+00047 
+00048 struct netif {
+00049   struct netif *next;
+00050   uInt8 num;
+00051   struct ip_addr ip_addr;
+00052   struct ip_addr netmask;  /* netmask in network byte order */
+00053   struct ip_addr gw;
+00054   char hwaddr[6];
+00055 
+00056   /* This function is called by the network device driver
+00057      when it wants to pass a packet to the TCP/IP stack. */
+00058   err_t (* input)(struct pbuf *p, struct netif *inp);
+00059 
+00060   /* The following two fields should be filled in by the
+00061      initialization function for the device driver. */
+00062 
+00063   char name[2];
+00064   /* This function is called by the IP module when it wants
+00065      to send a packet on the interface. */
+00066   err_t (* output)(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr);
+00067   err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
+00068 
+00069   /* This field can be set bu the device driver and could point
+00070      to state information for the device. */
+00071   void *state;
+00072 };
+00073 
+00074 /* The list of network interfaces. */
+00075 extern struct netif *netif_list;
+00076 extern struct netif *netif_default;
+00077 
+00078 
+00079 /* netif_init() must be called first. */
+00080 void netif_init();
+00081 
+00082 struct netif *netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask,
+00083                         struct ip_addr *gw,
+00084                         void (* init)(struct netif *netif),
+00085                         err_t (* input)(struct pbuf *p, struct netif *netif));
+00086 
+00087 /* Returns a network interface given its name. The name is of the form
+00088    "et0", where the first two letters are the "name" field in the
+00089    netif structure, and the digit is in the num field in the same
+00090    structure. */
+00091 struct netif *netif_find(char *name);
+00092 
+00093 void netif_set_default(struct netif *netif);
+00094 
+00095 void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
+00096 void netif_set_netmask(struct netif *netif, struct ip_addr *netmast);
+00097 void netif_set_gw(struct netif *netif, struct ip_addr *gw);
+00098 
+00099 #endif /* __LWIP_NETIF_H__ */
+

Generated on Wed Apr 28 17:49:38 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/netif_8h.html b/doc/doxygen/html/netif_8h.html new file mode 100644 index 0000000..5be388a --- /dev/null +++ b/doc/doxygen/html/netif_8h.html @@ -0,0 +1,347 @@ + + +Ubixos: netif.h File Reference + + + +

netif.h File Reference

#include "net/opt.h"
+#include "net/err.h"
+#include "net/ipv4/ip_addr.h"
+#include "net/ipv4/inet.h"
+#include "net/pbuf.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  netif

Functions

void netif_init ()
netifnetif_add (struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void(*init)(struct netif *netif), err_t(*input)(struct pbuf *p, struct netif *netif))
netifnetif_find (char *name)
void netif_set_default (struct netif *netif)
void netif_set_ipaddr (struct netif *netif, struct ip_addr *ipaddr)
void netif_set_netmask (struct netif *netif, struct ip_addr *netmast)
void netif_set_gw (struct netif *netif, struct ip_addr *gw)

Variables

netifnetif_list
netifnetif_default
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
struct netif* netif_add struct ip_addr ipaddr,
struct ip_addr netmask,
struct ip_addr gw,
void(*  init)(struct netif *netif),
err_t(*  input)(struct pbuf *p, struct netif *netif)
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct netif* netif_find char *  name  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void netif_init  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void netif_set_default struct netif netif  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void netif_set_gw struct netif netif,
struct ip_addr gw
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void netif_set_ipaddr struct netif netif,
struct ip_addr ipaddr
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void netif_set_netmask struct netif netif,
struct ip_addr netmast
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct netif* netif_default +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct netif* netif_list +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ogDisplay__UbixOS_8h-source.html b/doc/doxygen/html/ogDisplay__UbixOS_8h-source.html new file mode 100644 index 0000000..1d088a8 --- /dev/null +++ b/doc/doxygen/html/ogDisplay__UbixOS_8h-source.html @@ -0,0 +1,99 @@ + + +Ubixos: ogDisplay_UbixOS.h Source File + + + +

ogDisplay_UbixOS.h

00001 #ifndef OGDISPLAY_UBIXOS_H
+00002 #define OGDISPLAY_UBIXOS_H
+00003 
+00004 #include <objgfx40/objgfx40.h>
+00005 
+00006 struct ogModeInfo {
+00007     uInt16 modeAttributes     __attribute__((packed));
+00008     uInt8  windowAFlags       __attribute__((packed));
+00009     uInt8  windowBFlags       __attribute__((packed));
+00010     uInt16 granularity        __attribute__((packed));
+00011     uInt16 windowSize         __attribute__((packed));
+00012     uInt16 windowASeg         __attribute__((packed));
+00013     uInt16 windowBSeg         __attribute__((packed));
+00014     void*  bankSwitch         __attribute__((packed));
+00015     uInt16 bytesPerLine       __attribute__((packed));
+00016     uInt16 xRes               __attribute__((packed));
+00017     uInt16 yRes               __attribute__((packed));
+00018     uInt8  charWidth          __attribute__((packed));
+00019     uInt8  charHeight         __attribute__((packed));
+00020     uInt8  numBitPlanes       __attribute__((packed));
+00021     uInt8  bitsPerPixel       __attribute__((packed));
+00022     uInt8  numberOfBanks      __attribute__((packed));
+00023     uInt8  memoryModel        __attribute__((packed));
+00024     uInt8  bankSize           __attribute__((packed));
+00025     uInt8  numOfImagePages    __attribute__((packed));
+00026     uInt8  reserved           __attribute__((packed));
+00027     // Direct colour fields (required for Direct/6 and YUV/7 memory models
+00028     uInt8  redMaskSize        __attribute__((packed));
+00029     uInt8  redFieldPosition   __attribute__((packed));
+00030     uInt8  greenMaskSize      __attribute__((packed));
+00031     uInt8  greenFieldPosition __attribute__((packed));
+00032     uInt8  blueMaskSize       __attribute__((packed));
+00033     uInt8  blueFieldPosition  __attribute__((packed));
+00034     uInt8  alphaMaskSize      __attribute__((packed));
+00035     uInt8  alphaFieldPosition __attribute__((packed));
+00036     uInt8  directColourMode   __attribute__((packed));
+00037     // VESA 2.0 specific fields
+00038     uInt32 physBasePtr        __attribute__((packed));
+00039     void*  offScreenMemOffset __attribute__((packed));
+00040     uInt16 offScreenMemSize   __attribute__((packed));
+00041     uInt8  paddington[461]    __attribute__((packed));
+00042 };
+00043 
+00044 struct ogVESAInfo {
+00045     char    VBESignature[4]   __attribute__((packed));
+00046     uInt8   minVersion        __attribute__((packed));
+00047     uInt8   majVersion        __attribute__((packed));
+00048     uInt32  OEMStringPtr      __attribute__((packed));
+00049     uInt32  capabilities      __attribute__((packed));
+00050     uInt32  videoModePtr      __attribute__((packed));
+00051     uInt16  totalMemory       __attribute__((packed));
+00052     // VESA 2.0 specific fields
+00053     uInt16  OEMSoftwareRev    __attribute__((packed));
+00054     uInt32  OEMVendorNamePtr  __attribute__((packed));
+00055     uInt32  OEMProductNamePtr __attribute__((packed));
+00056     uInt32  OEMProductRevPtr  __attribute__((packed));
+00057     uInt8   paddington[474]   __attribute__((packed));
+00058 };
+00059 
+00060 
+00061 class ogDisplay_UbixOS : public ogSurface {
+00062  protected:
+00063   void *         pages[2];
+00064   uInt32         activePage;
+00065   uInt32         visualPage;
+00066   ogVESAInfo *   VESAInfo;
+00067   ogModeInfo *   modeInfo;
+00068 
+00069   uInt16         FindMode(uInt32, uInt32, uInt32);
+00070   void           GetModeInfo(uInt16);
+00071   void           GetVESAInfo(void);
+00072   void           SetMode(uInt16);
+00073   void           SetPal(void);
+00074  public:
+00075                  ogDisplay_UbixOS(void);
+00076   virtual bool   Alias(ogSurface&, uInt32, uInt32, uInt32, uInt32);
+00077   virtual bool   Clone(ogSurface&);
+00078   virtual void   CopyPalette(ogSurface&);
+00079   virtual bool   Create(uInt32, uInt32, ogPixelFmt);
+00080   virtual bool   LoadPalette(const char *);
+00081   virtual void   SetPalette(const ogRGBA8[]);
+00082   virtual void   SetPalette(uInt8, uInt8, uInt8, uInt8);
+00083   virtual void   SetPalette(uInt8, uInt8, uInt8, uInt8, uInt8);
+00084   virtual        ~ogDisplay_UbixOS(void);
+00085 }; // ogDisplay_UbixOS
+00086 
+00087 #endif
+

Generated on Wed Apr 28 17:49:38 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ogDisplay__VESA_8h-source.html b/doc/doxygen/html/ogDisplay__VESA_8h-source.html new file mode 100644 index 0000000..f21b7d8 --- /dev/null +++ b/doc/doxygen/html/ogDisplay__VESA_8h-source.html @@ -0,0 +1,202 @@ + + +Ubixos: ogDisplay_VESA.h Source File + + + +

ogDisplay_VESA.h

00001 #ifndef OGDISPLAY_VESA_H
+00002 
+00003 #define OGDISPLAY_VESA_H
+00004 
+00005 
+00006 
+00007 #include "objgfx30.h"
+00008 
+00009 
+00010 
+00011 struct TMode_Rec {
+00012 
+00013     uInt16 ModeAttributes     __attribute__((packed));
+00014 
+00015     uInt8  WindowAFlags       __attribute__((packed));
+00016 
+00017     uInt8  WindowBFlags       __attribute__((packed));
+00018 
+00019     uInt16 Granularity        __attribute__((packed));
+00020 
+00021     uInt16 WindowSize         __attribute__((packed));
+00022 
+00023     uInt16 WindowASeg         __attribute__((packed));
+00024 
+00025     uInt16 WindowBSeg         __attribute__((packed));
+00026 
+00027     void*  BankSwitch         __attribute__((packed));
+00028 
+00029     uInt16 BytesPerLine       __attribute__((packed));
+00030 
+00031     uInt16 xRes               __attribute__((packed));
+00032 
+00033     uInt16 yRes               __attribute__((packed));
+00034 
+00035     uInt8  CharWidth          __attribute__((packed));
+00036 
+00037     uInt8  CharHeight         __attribute__((packed));
+00038 
+00039     uInt8  NumBitPlanes       __attribute__((packed));
+00040 
+00041     uInt8  BitsPerPixel       __attribute__((packed));
+00042 
+00043     uInt8  NumberOfBanks      __attribute__((packed));
+00044 
+00045     uInt8  MemoryModel        __attribute__((packed));
+00046 
+00047     uInt8  BankSize           __attribute__((packed));
+00048 
+00049     uInt8  NumOfImagePages    __attribute__((packed));
+00050 
+00051     uInt8  Reserved           __attribute__((packed));
+00052 
+00053     // Direct colour fields (required for Direct/6 and YUV/7 memory models
+00054 
+00055     uInt8  RedMaskSize        __attribute__((packed));
+00056 
+00057     uInt8  RedFieldPosition   __attribute__((packed));
+00058 
+00059     uInt8  GreenMaskSize      __attribute__((packed));
+00060 
+00061     uInt8  GreenFieldPosition __attribute__((packed));
+00062 
+00063     uInt8  BlueMaskSize       __attribute__((packed));
+00064 
+00065     uInt8  BlueFieldPosition  __attribute__((packed));
+00066 
+00067     uInt8  AlphaMaskSize      __attribute__((packed));
+00068 
+00069     uInt8  AlphaFieldPosition __attribute__((packed));
+00070 
+00071     uInt8  DirectColourMode   __attribute__((packed));
+00072 
+00073     // VESA 2.0 specific fields
+00074 
+00075     uInt32 physBasePtr        __attribute__((packed));
+00076 
+00077     void*  OffScreenMemOffset __attribute__((packed));
+00078 
+00079     uInt16 OffScreenMemSize   __attribute__((packed));
+00080 
+00081     uInt8  paddington[461]    __attribute__((packed));
+00082 
+00083 };
+00084 
+00085 
+00086 
+00087 struct TVESA_Rec {
+00088 
+00089     char    VBESignature[4]   __attribute__((packed));
+00090 
+00091     uInt8   minVersion        __attribute__((packed));
+00092 
+00093     uInt8   majVersion        __attribute__((packed));
+00094 
+00095     uInt32  OEMStringPtr      __attribute__((packed));
+00096 
+00097     uInt32  Capabilities      __attribute__((packed));
+00098 
+00099     uInt32  VideoModePtr      __attribute__((packed));
+00100 
+00101     uInt16  TotalMemory       __attribute__((packed));
+00102 
+00103     // VESA 2.0 specific fields
+00104 
+00105     uInt16  OEMSoftwareRev    __attribute__((packed));
+00106 
+00107     uInt32  OEMVendorNamePtr  __attribute__((packed));
+00108 
+00109     uInt32  OEMProductNamePtr __attribute__((packed));
+00110 
+00111     uInt32  OEMProductRevPtr  __attribute__((packed));
+00112 
+00113     uInt8   paddington[474]   __attribute__((packed));
+00114 
+00115 };
+00116 
+00117 
+00118 
+00119 class ogDisplay_VESA : public ogSurface {
+00120 
+00121  protected:
+00122 
+00123   uInt16       ScreenSelector;
+00124 
+00125   TVESA_Rec*   VESARec;
+00126 
+00127   TMode_Rec*   ModeRec;
+00128 
+00129   bool         InGraphics;
+00130 
+00131   uInt16       findMode(uInt32, uInt32, uInt32);
+00132 
+00133   void         getModeInfo(uInt16);
+00134 
+00135   void         getVESAInfo(void);
+00136 
+00137   void         setMode(uInt16);
+00138 
+00139   virtual uInt32 rawGetPixel(uInt32, uInt32);  
+00140 
+00141   virtual void rawSetPixel(uInt32, uInt32, uInt32);
+00142 
+00143   virtual void rawLine(uInt32, uInt32, uInt32, uInt32, uInt32);
+00144 
+00145   void         setPal(void);
+00146 
+00147  public:
+00148 
+00149                ogDisplay_VESA(void);
+00150 
+00151   virtual bool ogAvail(void);
+00152 
+00153   virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32);
+00154 
+00155   virtual void ogClear(uInt32);
+00156 
+00157   virtual bool ogClone(ogSurface&);
+00158 
+00159   virtual void ogCopyLineTo(uInt32, uInt32, const void *, uInt32);
+00160 
+00161   virtual void ogCopyLineFrom(uInt32, uInt32, void *, uInt32);
+00162 
+00163   virtual void ogCopyPal(ogSurface&);
+00164 
+00165   virtual bool ogCreate(uInt32, uInt32, ogPixelFmt);
+00166 
+00167   virtual uInt32 ogGetPixel(int32, int32);
+00168 
+00169   virtual void * ogGetPtr(uInt32, uInt32);
+00170 
+00171   virtual void ogHLine(int32, int32, int32, uInt32);
+00172 
+00173   virtual bool ogLoadPal(const char *);  
+00174 
+00175   virtual void ogSetPixel(int32, int32, uInt32);
+00176 
+00177   virtual void ogSetRGBPalette(uInt8, uInt8, uInt8, uInt8);  
+00178 
+00179   virtual void ogVFlip(void);
+00180 
+00181   virtual void ogVLine(int32, int32, int32, uInt32);
+00182 
+00183   virtual      ~ogDisplay_VESA(void);
+00184 
+00185 }; // ogDisplay_VESA
+00186 
+00187 
+00188 
+00189 #endif
+00190 
+

Generated on Wed Apr 28 17:49:38 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/og_display___ubix_o_s_8h-source.html b/doc/doxygen/html/og_display___ubix_o_s_8h-source.html new file mode 100644 index 0000000..357336c --- /dev/null +++ b/doc/doxygen/html/og_display___ubix_o_s_8h-source.html @@ -0,0 +1,99 @@ + + +Ubixos: ogDisplay_UbixOS.h Source File + + + +

ogDisplay_UbixOS.h

Go to the documentation of this file.
00001 #ifndef OGDISPLAY_UBIXOS_H
+00002 #define OGDISPLAY_UBIXOS_H
+00003 
+00004 #include <objgfx40/objgfx40.h>
+00005 
+00006 struct ogModeInfo {
+00007     uInt16 modeAttributes     __attribute__((packed));
+00008     uInt8  windowAFlags       __attribute__((packed));
+00009     uInt8  windowBFlags       __attribute__((packed));
+00010     uInt16 granularity        __attribute__((packed));
+00011     uInt16 windowSize         __attribute__((packed));
+00012     uInt16 windowASeg         __attribute__((packed));
+00013     uInt16 windowBSeg         __attribute__((packed));
+00014     void*  bankSwitch         __attribute__((packed));
+00015     uInt16 bytesPerLine       __attribute__((packed));
+00016     uInt16 xRes               __attribute__((packed));
+00017     uInt16 yRes               __attribute__((packed));
+00018     uInt8  charWidth          __attribute__((packed));
+00019     uInt8  charHeight         __attribute__((packed));
+00020     uInt8  numBitPlanes       __attribute__((packed));
+00021     uInt8  bitsPerPixel       __attribute__((packed));
+00022     uInt8  numberOfBanks      __attribute__((packed));
+00023     uInt8  memoryModel        __attribute__((packed));
+00024     uInt8  bankSize           __attribute__((packed));
+00025     uInt8  numOfImagePages    __attribute__((packed));
+00026     uInt8  reserved           __attribute__((packed));
+00027     // Direct colour fields (required for Direct/6 and YUV/7 memory models
+00028     uInt8  redMaskSize        __attribute__((packed));
+00029     uInt8  redFieldPosition   __attribute__((packed));
+00030     uInt8  greenMaskSize      __attribute__((packed));
+00031     uInt8  greenFieldPosition __attribute__((packed));
+00032     uInt8  blueMaskSize       __attribute__((packed));
+00033     uInt8  blueFieldPosition  __attribute__((packed));
+00034     uInt8  alphaMaskSize      __attribute__((packed));
+00035     uInt8  alphaFieldPosition __attribute__((packed));
+00036     uInt8  directColourMode   __attribute__((packed));
+00037     // VESA 2.0 specific fields
+00038     uInt32 physBasePtr        __attribute__((packed));
+00039     void*  offScreenMemOffset __attribute__((packed));
+00040     uInt16 offScreenMemSize   __attribute__((packed));
+00041     uInt8  paddington[461]    __attribute__((packed));
+00042 };
+00043 
+00044 struct ogVESAInfo {
+00045     char    VBESignature[4]   __attribute__((packed));
+00046     uInt8   minVersion        __attribute__((packed));
+00047     uInt8   majVersion        __attribute__((packed));
+00048     uInt32  OEMStringPtr      __attribute__((packed));
+00049     uInt32  capabilities      __attribute__((packed));
+00050     uInt32  videoModePtr      __attribute__((packed));
+00051     uInt16  totalMemory       __attribute__((packed));
+00052     // VESA 2.0 specific fields
+00053     uInt16  OEMSoftwareRev    __attribute__((packed));
+00054     uInt32  OEMVendorNamePtr  __attribute__((packed));
+00055     uInt32  OEMProductNamePtr __attribute__((packed));
+00056     uInt32  OEMProductRevPtr  __attribute__((packed));
+00057     uInt8   paddington[474]   __attribute__((packed));
+00058 };
+00059 
+00060 
+00061 class ogDisplay_UbixOS : public ogSurface {
+00062  protected:
+00063   void *         pages[2];
+00064   uInt32         activePage;
+00065   uInt32         visualPage;
+00066   ogVESAInfo *   VESAInfo;
+00067   ogModeInfo *   modeInfo;
+00068 
+00069   uInt16         FindMode(uInt32, uInt32, uInt32);
+00070   void           GetModeInfo(uInt16);
+00071   void           GetVESAInfo(void);
+00072   void           SetMode(uInt16);
+00073   void           SetPal(void);
+00074  public:
+00075                  ogDisplay_UbixOS(void);
+00076   virtual bool   Alias(ogSurface&, uInt32, uInt32, uInt32, uInt32);
+00077   virtual bool   Clone(ogSurface&);
+00078   virtual void   CopyPalette(ogSurface&);
+00079   virtual bool   Create(uInt32, uInt32, ogPixelFmt);
+00080   virtual bool   LoadPalette(const char *);
+00081   virtual void   SetPalette(const ogRGBA8[]);
+00082   virtual void   SetPalette(uInt8, uInt8, uInt8, uInt8);
+00083   virtual void   SetPalette(uInt8, uInt8, uInt8, uInt8, uInt8);
+00084   virtual        ~ogDisplay_UbixOS(void);
+00085 }; // ogDisplay_UbixOS
+00086 
+00087 #endif
+

Generated on Sat May 8 09:28:17 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/og_display___ubix_o_s_8h.html b/doc/doxygen/html/og_display___ubix_o_s_8h.html new file mode 100644 index 0000000..30446ee --- /dev/null +++ b/doc/doxygen/html/og_display___ubix_o_s_8h.html @@ -0,0 +1,25 @@ + + +Ubixos: ogDisplay_UbixOS.h File Reference + + + +

ogDisplay_UbixOS.h File Reference

#include <objgfx40/objgfx40.h>
+ +

+Go to the source code of this file. + + + + + + + + +

Data Structures

class  ogDisplay_UbixOS
struct  ogModeInfo
struct  ogVESAInfo
+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/og_display___v_e_s_a_8h-source.html b/doc/doxygen/html/og_display___v_e_s_a_8h-source.html new file mode 100644 index 0000000..7f95763 --- /dev/null +++ b/doc/doxygen/html/og_display___v_e_s_a_8h-source.html @@ -0,0 +1,202 @@ + + +Ubixos: ogDisplay_VESA.h Source File + + + +

ogDisplay_VESA.h

Go to the documentation of this file.
00001 #ifndef OGDISPLAY_VESA_H
+00002 
+00003 #define OGDISPLAY_VESA_H
+00004 
+00005 
+00006 
+00007 #include "objgfx30.h"
+00008 
+00009 
+00010 
+00011 struct TMode_Rec {
+00012 
+00013     uInt16 ModeAttributes     __attribute__((packed));
+00014 
+00015     uInt8  WindowAFlags       __attribute__((packed));
+00016 
+00017     uInt8  WindowBFlags       __attribute__((packed));
+00018 
+00019     uInt16 Granularity        __attribute__((packed));
+00020 
+00021     uInt16 WindowSize         __attribute__((packed));
+00022 
+00023     uInt16 WindowASeg         __attribute__((packed));
+00024 
+00025     uInt16 WindowBSeg         __attribute__((packed));
+00026 
+00027     void*  BankSwitch         __attribute__((packed));
+00028 
+00029     uInt16 BytesPerLine       __attribute__((packed));
+00030 
+00031     uInt16 xRes               __attribute__((packed));
+00032 
+00033     uInt16 yRes               __attribute__((packed));
+00034 
+00035     uInt8  CharWidth          __attribute__((packed));
+00036 
+00037     uInt8  CharHeight         __attribute__((packed));
+00038 
+00039     uInt8  NumBitPlanes       __attribute__((packed));
+00040 
+00041     uInt8  BitsPerPixel       __attribute__((packed));
+00042 
+00043     uInt8  NumberOfBanks      __attribute__((packed));
+00044 
+00045     uInt8  MemoryModel        __attribute__((packed));
+00046 
+00047     uInt8  BankSize           __attribute__((packed));
+00048 
+00049     uInt8  NumOfImagePages    __attribute__((packed));
+00050 
+00051     uInt8  Reserved           __attribute__((packed));
+00052 
+00053     // Direct colour fields (required for Direct/6 and YUV/7 memory models
+00054 
+00055     uInt8  RedMaskSize        __attribute__((packed));
+00056 
+00057     uInt8  RedFieldPosition   __attribute__((packed));
+00058 
+00059     uInt8  GreenMaskSize      __attribute__((packed));
+00060 
+00061     uInt8  GreenFieldPosition __attribute__((packed));
+00062 
+00063     uInt8  BlueMaskSize       __attribute__((packed));
+00064 
+00065     uInt8  BlueFieldPosition  __attribute__((packed));
+00066 
+00067     uInt8  AlphaMaskSize      __attribute__((packed));
+00068 
+00069     uInt8  AlphaFieldPosition __attribute__((packed));
+00070 
+00071     uInt8  DirectColourMode   __attribute__((packed));
+00072 
+00073     // VESA 2.0 specific fields
+00074 
+00075     uInt32 physBasePtr        __attribute__((packed));
+00076 
+00077     void*  OffScreenMemOffset __attribute__((packed));
+00078 
+00079     uInt16 OffScreenMemSize   __attribute__((packed));
+00080 
+00081     uInt8  paddington[461]    __attribute__((packed));
+00082 
+00083 };
+00084 
+00085 
+00086 
+00087 struct TVESA_Rec {
+00088 
+00089     char    VBESignature[4]   __attribute__((packed));
+00090 
+00091     uInt8   minVersion        __attribute__((packed));
+00092 
+00093     uInt8   majVersion        __attribute__((packed));
+00094 
+00095     uInt32  OEMStringPtr      __attribute__((packed));
+00096 
+00097     uInt32  Capabilities      __attribute__((packed));
+00098 
+00099     uInt32  VideoModePtr      __attribute__((packed));
+00100 
+00101     uInt16  TotalMemory       __attribute__((packed));
+00102 
+00103     // VESA 2.0 specific fields
+00104 
+00105     uInt16  OEMSoftwareRev    __attribute__((packed));
+00106 
+00107     uInt32  OEMVendorNamePtr  __attribute__((packed));
+00108 
+00109     uInt32  OEMProductNamePtr __attribute__((packed));
+00110 
+00111     uInt32  OEMProductRevPtr  __attribute__((packed));
+00112 
+00113     uInt8   paddington[474]   __attribute__((packed));
+00114 
+00115 };
+00116 
+00117 
+00118 
+00119 class ogDisplay_VESA : public ogSurface {
+00120 
+00121  protected:
+00122 
+00123   uInt16       ScreenSelector;
+00124 
+00125   TVESA_Rec*   VESARec;
+00126 
+00127   TMode_Rec*   ModeRec;
+00128 
+00129   bool         InGraphics;
+00130 
+00131   uInt16       findMode(uInt32, uInt32, uInt32);
+00132 
+00133   void         getModeInfo(uInt16);
+00134 
+00135   void         getVESAInfo(void);
+00136 
+00137   void         setMode(uInt16);
+00138 
+00139   virtual uInt32 rawGetPixel(uInt32, uInt32);  
+00140 
+00141   virtual void rawSetPixel(uInt32, uInt32, uInt32);
+00142 
+00143   virtual void rawLine(uInt32, uInt32, uInt32, uInt32, uInt32);
+00144 
+00145   void         setPal(void);
+00146 
+00147  public:
+00148 
+00149                ogDisplay_VESA(void);
+00150 
+00151   virtual bool ogAvail(void);
+00152 
+00153   virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32);
+00154 
+00155   virtual void ogClear(uInt32);
+00156 
+00157   virtual bool ogClone(ogSurface&);
+00158 
+00159   virtual void ogCopyLineTo(uInt32, uInt32, const void *, uInt32);
+00160 
+00161   virtual void ogCopyLineFrom(uInt32, uInt32, void *, uInt32);
+00162 
+00163   virtual void ogCopyPal(ogSurface&);
+00164 
+00165   virtual bool ogCreate(uInt32, uInt32, ogPixelFmt);
+00166 
+00167   virtual uInt32 ogGetPixel(int32, int32);
+00168 
+00169   virtual void * ogGetPtr(uInt32, uInt32);
+00170 
+00171   virtual void ogHLine(int32, int32, int32, uInt32);
+00172 
+00173   virtual bool ogLoadPal(const char *);  
+00174 
+00175   virtual void ogSetPixel(int32, int32, uInt32);
+00176 
+00177   virtual void ogSetRGBPalette(uInt8, uInt8, uInt8, uInt8);  
+00178 
+00179   virtual void ogVFlip(void);
+00180 
+00181   virtual void ogVLine(int32, int32, int32, uInt32);
+00182 
+00183   virtual      ~ogDisplay_VESA(void);
+00184 
+00185 }; // ogDisplay_VESA
+00186 
+00187 
+00188 
+00189 #endif
+00190 
+

Generated on Sat May 8 09:28:17 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/og_display___v_e_s_a_8h.html b/doc/doxygen/html/og_display___v_e_s_a_8h.html new file mode 100644 index 0000000..f7a2988 --- /dev/null +++ b/doc/doxygen/html/og_display___v_e_s_a_8h.html @@ -0,0 +1,25 @@ + + +Ubixos: ogDisplay_VESA.h File Reference + + + +

ogDisplay_VESA.h File Reference

#include "objgfx30.h"
+ +

+Go to the source code of this file. + + + + + + + + +

Data Structures

class  ogDisplay_VESA
struct  TMode_Rec
struct  TVESA_Rec
+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/opt_8h-source.html b/doc/doxygen/html/opt_8h-source.html new file mode 100644 index 0000000..20227d0 --- /dev/null +++ b/doc/doxygen/html/opt_8h-source.html @@ -0,0 +1,109 @@ + + +Ubixos: opt.h Source File + + + +

opt.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_OPT_H__
+00036 #define __LWIP_OPT_H__
+00037 
+00038 #include "net/lwipopts.h"
+00039 
+00040 /* Define some handy default values for configuration parameters. */
+00041 
+00042 #ifndef ICMP_TTL
+00043 #define ICMP_TTL                255
+00044 #endif
+00045 
+00046 #ifndef UDP_TTL
+00047 #define UDP_TTL                 255
+00048 #endif
+00049 
+00050 #ifndef TCP_TTL
+00051 #define TCP_TTL                 255
+00052 #endif
+00053 
+00054 #ifndef TCP_MSS
+00055 #define TCP_MSS                 128 /* A *very* conservative default. */
+00056 #endif
+00057 
+00058 #ifndef TCP_WND
+00059 #define TCP_WND                 2048
+00060 #endif 
+00061 
+00062 #ifndef TCP_MAXRTX
+00063 #define TCP_MAXRTX              12
+00064 #endif
+00065 
+00066 #ifndef TCP_SYNMAXRTX
+00067 #define TCP_SYNMAXRTX           6
+00068 #endif
+00069 
+00070 #ifndef MEM_ALIGNMENT
+00071 #define MEM_ALIGNMENT           1
+00072 #endif
+00073 
+00074 #ifndef PBUF_POOL_SIZE
+00075 #define PBUF_POOL_SIZE          16
+00076 #endif
+00077 
+00078 #ifndef PBUF_POOL_BUFSIZE
+00079 #define PBUF_POOL_BUFSIZE       128
+00080 #endif
+00081 
+00082 #ifndef PBUF_LINK_HLEN
+00083 #define PBUF_LINK_HLEN          0
+00084 #endif
+00085 
+00086 #ifndef LWIP_UDP
+00087 #define LWIP_UDP                1
+00088 #endif
+00089 
+00090 #ifndef LWIP_TCP
+00091 #define LWIP_TCP                1
+00092 #endif
+00093 
+00094 #endif /* __LWIP_OPT_H__ */
+00095 
+00096 
+00097 
+

Generated on Wed Apr 28 17:49:38 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/opt_8h.html b/doc/doxygen/html/opt_8h.html new file mode 100644 index 0000000..20e95ec --- /dev/null +++ b/doc/doxygen/html/opt_8h.html @@ -0,0 +1,332 @@ + + +Ubixos: opt.h File Reference + + + +

opt.h File Reference

#include "net/lwipopts.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define ICMP_TTL   255
#define UDP_TTL   255
#define TCP_TTL   255
#define TCP_MSS   128
#define TCP_WND   2048
#define TCP_MAXRTX   12
#define TCP_SYNMAXRTX   6
#define MEM_ALIGNMENT   1
#define PBUF_POOL_SIZE   16
#define PBUF_POOL_BUFSIZE   128
#define PBUF_LINK_HLEN   0
#define LWIP_UDP   1
#define LWIP_TCP   1
+


Define Documentation

+

+ + + + +
+ + +
#define ICMP_TTL   255 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LWIP_TCP   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LWIP_UDP   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MEM_ALIGNMENT   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_LINK_HLEN   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_POOL_BUFSIZE   128 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_POOL_SIZE   16 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_MAXRTX   12 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_MSS   128 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_SYNMAXRTX   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_TTL   255 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_WND   2048 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UDP_TTL   255 +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/paging_8h-source.html b/doc/doxygen/html/paging_8h-source.html new file mode 100644 index 0000000..76bd175 --- /dev/null +++ b/doc/doxygen/html/paging_8h-source.html @@ -0,0 +1,73 @@ + + +Ubixos: paging.h Source File + + + +

paging.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _PAGING_H
+00025 #define _PAGING_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #define pageLength        0x00000400
+00030 #define pageSize          4096
+00031 #define pageEntries       (pageSize/4)
+00032 #define pagePresent       0x00000001
+00033 #define pageWrite         0x00000002
+00034 #define pageUser          0x00000004
+00035 #define pageCow           0x00000200
+00036 #define pageStack         0x00000400
+00037 #define pageDefault       (pagePresent|pageWrite|pageUser)
+00038 #define kernelPageDefault (pagePresent|pageWrite)
+00039 #define tablesBaseAddress 0xBFC00000
+00040 #define parentPageDirAddr 0x100000
+00041 
+00042 int vmmPagingInit();
+00043 int vmmClearVirtualPage(uInt32 pageAddr);
+00044 int vmmRemapPage(uInt32,uInt32);
+00045 void vmmUnmapPage(uInt32,int);
+00046 void vmmUnmapPages(void *,uInt32);
+00047 void vmmSetPageAttribute(uInt32,int);
+00048 void *vmmMapFromTask(pidType,void *,uInt32);
+00049 void *vmmCopyVirtualSpace(pidType);
+00050 void *vmmGetFreePage(pidType);
+00051 void *vmmGetFreeKernelPage(pidType pid,uInt16 count);
+00052 void *vmmGetPhysicalAddr(uInt32);
+00053 void *vmmCreateVirtualSpace(pidType);
+00054 void *vmmGetFreeVirtualPage(pidType,int);
+00055 void vmmPageFault();
+00056 void _vmmPageFault();
+00057 
+00058 extern uInt32 *kernelPageDirectory;
+00059 
+00060 #endif
+00061 
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/paging_8h.html b/doc/doxygen/html/paging_8h.html new file mode 100644 index 0000000..cf51e83 --- /dev/null +++ b/doc/doxygen/html/paging_8h.html @@ -0,0 +1,867 @@ + + +Ubixos: paging.h File Reference + + + +

paging.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define pageLength   0x00000400
#define pageSize   4096
#define pageEntries   (pageSize/4)
#define pagePresent   0x00000001
#define pageWrite   0x00000002
#define pageUser   0x00000004
#define pageCow   0x00000200
#define pageStack   0x00000400
#define pageDefault   (pagePresent|pageWrite|pageUser)
#define kernelPageDefault   (pagePresent|pageWrite)
#define tablesBaseAddress   0xBFC00000
#define parentPageDirAddr   0x100000

Functions

int vmmPagingInit ()
int vmmClearVirtualPage (uInt32 pageAddr)
int vmmRemapPage (uInt32, uInt32)
void vmmUnmapPage (uInt32, int)
void vmmUnmapPages (void *, uInt32)
void vmmSetPageAttribute (uInt32, int)
void * vmmMapFromTask (pidType, void *, uInt32)
void * vmmCopyVirtualSpace (pidType)
void * vmmGetFreePage (pidType)
void * vmmGetFreeKernelPage (pidType pid, uInt16 count)
void * vmmGetPhysicalAddr (uInt32)
void * vmmCreateVirtualSpace (pidType)
void * vmmGetFreeVirtualPage (pidType, int)
void vmmPageFault ()
void _vmmPageFault ()

Variables

uInt32kernelPageDirectory
+


Define Documentation

+

+ + + + +
+ + +
#define kernelPageDefault   (pagePresent|pageWrite) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageCow   0x00000200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageDefault   (pagePresent|pageWrite|pageUser) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageEntries   (pageSize/4) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageLength   0x00000400 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pagePresent   0x00000001 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageSize   4096 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageStack   0x00000400 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageUser   0x00000004 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define pageWrite   0x00000002 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define parentPageDirAddr   0x100000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define tablesBaseAddress   0xBFC00000 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void _vmmPageFault  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int vmmClearVirtualPage uInt32  pageAddr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* vmmCopyVirtualSpace pidType   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* vmmCreateVirtualSpace pidType   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void* vmmGetFreeKernelPage pidType  pid,
uInt16  count
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* vmmGetFreePage pidType   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void* vmmGetFreeVirtualPage pidType ,
int 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* vmmGetPhysicalAddr uInt32   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void* vmmMapFromTask pidType ,
void * ,
uInt32 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void vmmPageFault  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int vmmPagingInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int vmmRemapPage uInt32 ,
uInt32 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void vmmSetPageAttribute uInt32 ,
int 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void vmmUnmapPage uInt32 ,
int 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void vmmUnmapPages void * ,
uInt32 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
uInt32* kernelPageDirectory +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/pbuf_8h-source.html b/doc/doxygen/html/pbuf_8h-source.html new file mode 100644 index 0000000..17e3a62 --- /dev/null +++ b/doc/doxygen/html/pbuf_8h-source.html @@ -0,0 +1,164 @@ + + +Ubixos: pbuf.h Source File + + + +

pbuf.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 /*-----------------------------------------------------------------------------------*/
+00036 #ifndef __LWIP_PBUF_H__
+00037 #define __LWIP_PBUF_H__
+00038 
+00039 #include "net/debug.h"
+00040 #include "net/arch.h"
+00041 
+00042 
+00043 #define PBUF_TRANSPORT_HLEN 20
+00044 #define PBUF_IP_HLEN        20
+00045 
+00046 typedef enum {
+00047   PBUF_TRANSPORT,
+00048   PBUF_IP,
+00049   PBUF_LINK,
+00050   PBUF_RAW
+00051 } pbuf_layer;
+00052 
+00053 typedef enum {
+00054   PBUF_RAM,
+00055   PBUF_ROM,
+00056   PBUF_POOL
+00057 } pbuf_flag;
+00058 
+00059 /* Definitions for the pbuf flag field (these are not the flags that
+00060    are passed to pbuf_alloc()). */
+00061 #define PBUF_FLAG_RAM   0x00    /* Flags that pbuf data is stored in RAM. */
+00062 #define PBUF_FLAG_ROM   0x01    /* Flags that pbuf data is stored in ROM. */
+00063 #define PBUF_FLAG_POOL  0x02    /* Flags that the pbuf comes from the
+00064                                    pbuf pool. */
+00065 
+00066 struct pbuf {
+00067   struct pbuf *next;
+00068   
+00069   /* high 4 bits, flags, low 4 bits reference count */
+00070   uInt8 flags, ref;
+00071   void *payload;
+00072   
+00073   /* Total length of buffer + additionally chained buffers. */
+00074   uInt16 tot_len;
+00075   /* Length of this buffer. */
+00076   uInt16 len;  
+00077   
+00078 };
+00079 
+00080 /* pbuf_init():
+00081 
+00082    Initializes the pbuf module. The num parameter determines how many
+00083    pbufs that should be allocated to the pbuf pool, and the size
+00084    parameter specifies the size of the data allocated to those.  */
+00085 void pbuf_init(void);
+00086 
+00087 /* pbuf_alloc():
+00088    
+00089    Allocates a pbuf at protocol layer l. The actual memory allocated
+00090    for the pbuf is determined by the layer at which the pbuf is
+00091    allocated and the requested size (from the size parameter). The
+00092    flag parameter decides how and where the pbuf should be allocated
+00093    as follows:
+00094  
+00095    * PBUF_RAM: buffer memory for pbuf is allocated as one large
+00096                chunk. This includesprotocol headers as well.
+00097    
+00098    * RBUF_ROM: no buffer memory is allocated for the pbuf, even for
+00099                 protocol headers.  Additional headers must be
+00100                 prepended by allocating another pbuf and chain in to
+00101                 the front of the ROM pbuf.
+00102 
+00103    * PBUF_ROOL: the pbuf is allocated as a pbuf chain, with pbufs from
+00104                 the pbuf pool that is allocated during pbuf_init().  */
+00105 struct pbuf *pbuf_alloc(pbuf_layer l, uInt16 size, pbuf_flag flag);
+00106 
+00107 /* pbuf_realloc():
+00108 
+00109    Shrinks the pbuf to the size given by the size parameter. 
+00110  */
+00111 void pbuf_realloc(struct pbuf *p, uInt16 size); 
+00112 
+00113 /* pbuf_header():
+00114 
+00115    Tries to move the p->payload pointer header_size number of bytes
+00116    upward within the pbuf. The return value is non-zero if it
+00117    fails. If so, an additional pbuf should be allocated for the header
+00118    and it should be chained to the front. */
+00119 uInt8 pbuf_header(struct pbuf *p, Int16 header_size);
+00120 
+00121 /* pbuf_ref():
+00122 
+00123    Increments the reference count of the pbuf p.
+00124  */
+00125 void pbuf_ref(struct pbuf *p);
+00126 
+00127 /* pbuf_free():
+00128 
+00129    Decrements the reference count and deallocates the pbuf if the
+00130    reference count is zero. If the pbuf is a chain all pbufs in the
+00131    chain are deallocated.  */
+00132 uInt8 pbuf_free(struct pbuf *p);
+00133 
+00134 /* pbuf_clen():
+00135 
+00136    Returns the length of the pbuf chain. */
+00137 uInt8 pbuf_clen(struct pbuf *p);  
+00138 
+00139 /* pbuf_chain():
+00140 
+00141    Chains pbuf t on the end of pbuf h. Pbuf h will have it's tot_len
+00142    field adjusted accordingly. Pbuf t should no be used any more after
+00143    a call to this function, since pbuf t is now a part of pbuf h.  */
+00144 void pbuf_chain(struct pbuf *h, struct pbuf *t);
+00145 
+00146 /* pbuf_dechain():
+00147 
+00148    Picks off the first pbuf from the pbuf chain p. Returns the tail of
+00149    the pbuf chain or NULL if the pbuf p was not chained. */
+00150 struct pbuf *pbuf_dechain(struct pbuf *p);
+00151 
+00152 #endif /* __LWIP_PBUF_H__ */
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/pbuf_8h.html b/doc/doxygen/html/pbuf_8h.html new file mode 100644 index 0000000..391e14f --- /dev/null +++ b/doc/doxygen/html/pbuf_8h.html @@ -0,0 +1,546 @@ + + +Ubixos: pbuf.h File Reference + + + +

pbuf.h File Reference

#include "net/debug.h"
+#include "net/arch.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  pbuf

Defines

#define PBUF_TRANSPORT_HLEN   20
#define PBUF_IP_HLEN   20
#define PBUF_FLAG_RAM   0x00
#define PBUF_FLAG_ROM   0x01
#define PBUF_FLAG_POOL   0x02

Enumerations

enum  pbuf_layer { PBUF_TRANSPORT, +PBUF_IP, +PBUF_LINK, +PBUF_RAW + }
enum  pbuf_flag { PBUF_RAM, +PBUF_ROM, +PBUF_POOL + }

Functions

void pbuf_init (void)
pbufpbuf_alloc (pbuf_layer l, uInt16 size, pbuf_flag flag)
void pbuf_realloc (struct pbuf *p, uInt16 size)
uInt8 pbuf_header (struct pbuf *p, Int16 header_size)
void pbuf_ref (struct pbuf *p)
uInt8 pbuf_free (struct pbuf *p)
uInt8 pbuf_clen (struct pbuf *p)
void pbuf_chain (struct pbuf *h, struct pbuf *t)
pbufpbuf_dechain (struct pbuf *p)
+


Define Documentation

+

+ + + + +
+ + +
#define PBUF_FLAG_POOL   0x02 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_FLAG_RAM   0x00 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_FLAG_ROM   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_IP_HLEN   20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PBUF_TRANSPORT_HLEN   20 +
+
+ + + + + +
+   + + +

+

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum pbuf_flag +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + +
PBUF_RAM  +
PBUF_ROM  +
PBUF_POOL  +
+
+
+

+ + + + +
+ + +
enum pbuf_layer +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + +
PBUF_TRANSPORT  +
PBUF_IP  +
PBUF_LINK  +
PBUF_RAW  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
struct pbuf* pbuf_alloc pbuf_layer  l,
uInt16  size,
pbuf_flag  flag
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void pbuf_chain struct pbuf h,
struct pbuf t
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 pbuf_clen struct pbuf p  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct pbuf* pbuf_dechain struct pbuf p  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 pbuf_free struct pbuf p  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uInt8 pbuf_header struct pbuf p,
Int16  header_size
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void pbuf_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void pbuf_realloc struct pbuf p,
uInt16  size
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void pbuf_ref struct pbuf p  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/pci_8h-source.html b/doc/doxygen/html/pci_8h-source.html new file mode 100644 index 0000000..4101085 --- /dev/null +++ b/doc/doxygen/html/pci_8h-source.html @@ -0,0 +1,91 @@ + + +Ubixos: pci.h Source File + + + +

pci.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _PCI_H
+00025 #define _PCI_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 
+00030 struct pciConfig {
+00031   uInt16 vendorId;
+00032   uInt16 deviceId;
+00033 
+00034   uInt16 command;
+00035   uInt16 status;
+00036 
+00037   uInt8  revisionId;
+00038   uInt8  interface;
+00039   uInt8  subClass;
+00040   uInt8  baseClass;
+00041 
+00042   uInt8  cacheLineSize;
+00043   uInt8  latencyTimer;
+00044   uInt8  headerType;
+00045   uInt8  bist;
+00046 
+00047   /* device info */
+00048   uInt8  bus;
+00049   uInt8  dev;
+00050   uInt8  func;
+00051   uInt8  irq;
+00052 
+00053   /* base registers */
+00054   uInt32 base[6];
+00055   uInt32 size[6];
+00056 
+00057   uInt16 subsysVendor;
+00058   uInt16 subsys;
+00059   
+00060   };
+00061 
+00062 struct confadd {
+00063   uInt8 reg:8;
+00064   uInt8 func:3;
+00065   uInt8 dev:5;
+00066   uInt8 bus:8;
+00067   uInt8 rsvd:7;
+00068   uInt8 enable:1;
+00069   };
+00070 
+00071 #define countof(a)     (sizeof(a) / sizeof(a[0]))
+00072   
+00073 int pciInit();
+00074 bool pciProbe(int bus,int dev,int func,struct pciConfig *cfg);
+00075 uInt32 pciRead(int bus, int dev, int func, int reg, int bytes);
+00076 void pciWrite(int bus,int dev,int func,int reg,uInt32 v,int bytes);
+00077 
+00078 #endif
+00079 
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/pci_8h.html b/doc/doxygen/html/pci_8h.html new file mode 100644 index 0000000..45def42 --- /dev/null +++ b/doc/doxygen/html/pci_8h.html @@ -0,0 +1,260 @@ + + +Ubixos: pci.h File Reference + + + +

pci.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + +

Data Structures

struct  confadd
struct  pciConfig

Defines

#define countof(a)   (sizeof(a) / sizeof(a[0]))

Functions

int pciInit ()
bool pciProbe (int bus, int dev, int func, struct pciConfig *cfg)
uInt32 pciRead (int bus, int dev, int func, int reg, int bytes)
void pciWrite (int bus, int dev, int func, int reg, uInt32 v, int bytes)
+


Define Documentation

+

+ + + + +
+ + + + + + + +
#define countof  )    (sizeof(a) / sizeof(a[0])) +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
int pciInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bool pciProbe int  bus,
int  dev,
int  func,
struct pciConfig cfg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
uInt32 pciRead int  bus,
int  dev,
int  func,
int  reg,
int  bytes
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void pciWrite int  bus,
int  dev,
int  func,
int  reg,
uInt32  v,
int  bytes
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/perf_8h-source.html b/doc/doxygen/html/perf_8h-source.html new file mode 100644 index 0000000..dc3685e --- /dev/null +++ b/doc/doxygen/html/perf_8h-source.html @@ -0,0 +1,78 @@ + + +Ubixos: perf.h Source File + + + +

perf.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __ARCH_PERF_H__
+00036 #define __ARCH_PERF_H__
+00037 
+00038 #include <ubixos/times.h>
+00039 
+00040 #ifdef PERF
+00041 #define PERF_START  { \
+00042                          unsigned long __c1l, __c1h, __c2l, __c2h; \
+00043                          __asm__(".byte 0x0f, 0x31" : "=a" (__c1l), "=d" (__c1h))
+00044 #define PERF_STOP(x)   __asm__(".byte 0x0f, 0x31" : "=a" (__c2l), "=d" (__c2h)); \
+00045                        perf_print(__c1l, __c1h, __c2l, __c2h, x);}
+00046 
+00047 /*#define PERF_START do { \
+00048                      struct tms __perf_start, __perf_end; \
+00049                      times(&__perf_start)
+00050 #define PERF_STOP(x) times(&__perf_end); \
+00051                      perf_print_times(&__perf_start, &__perf_end, x);\
+00052                      } while(0)*/
+00053 #else /* PERF */
+00054 #define PERF_START    /* null definition */
+00055 #define PERF_STOP(x)  /* null definition */
+00056 #endif /* PERF */
+00057 
+00058 void perf_print(unsigned long c1l, unsigned long c1h,
+00059                 unsigned long c2l, unsigned long c2h,
+00060                 char *key);
+00061 
+00062 void perf_print_times(struct tms *start, struct tms *end, char *key);
+00063 
+00064 void perf_init(char *fname);
+00065 
+00066 #endif /* __ARCH_PERF_H__ */
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/perf_8h.html b/doc/doxygen/html/perf_8h.html new file mode 100644 index 0000000..7e2c327 --- /dev/null +++ b/doc/doxygen/html/perf_8h.html @@ -0,0 +1,210 @@ + + +Ubixos: perf.h File Reference + + + +

perf.h File Reference

#include <ubixos/times.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + +

Defines

#define PERF_START
#define PERF_STOP(x)

Functions

void perf_print (unsigned long c1l, unsigned long c1h, unsigned long c2l, unsigned long c2h, char *key)
void perf_print_times (struct tms *start, struct tms *end, char *key)
void perf_init (char *fname)
+


Define Documentation

+

+ + + + +
+ + +
#define PERF_START +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define PERF_STOP  )  +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void perf_init char *  fname  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void perf_print unsigned long  c1l,
unsigned long  c1h,
unsigned long  c2l,
unsigned long  c2h,
char *  key
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void perf_print_times struct tms start,
struct tms end,
char *  key
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/pit_8h-source.html b/doc/doxygen/html/pit_8h-source.html new file mode 100644 index 0000000..ac6950d --- /dev/null +++ b/doc/doxygen/html/pit_8h-source.html @@ -0,0 +1,13 @@ + + +Ubixos: pit.h Source File + + + +

pit.h

00001 int pitInit(int);
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/pit_8h.html b/doc/doxygen/html/pit_8h.html new file mode 100644 index 0000000..d9b9b41 --- /dev/null +++ b/doc/doxygen/html/pit_8h.html @@ -0,0 +1,50 @@ + + +Ubixos: pit.h File Reference + + + +

pit.h File Reference

+

+Go to the source code of this file. + + + + +

Functions

int pitInit (int)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
int pitInit int   ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sched_8h-source.html b/doc/doxygen/html/sched_8h-source.html new file mode 100644 index 0000000..f626332 --- /dev/null +++ b/doc/doxygen/html/sched_8h-source.html @@ -0,0 +1,102 @@ + + +Ubixos: sched.h Source File + + + +

sched.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _SCHED_H
+00025 #define _SCHED_H
+00026 
+00027 #ifdef __cplusplus
+00028 extern "C" {
+00029 #endif
+00030 
+00031 #include <ubixos/types.h>
+00032 #include <ubixos/elf.h>
+00033 #include <vfs/file.h>
+00034 #include <sys/tss.h>
+00035 
+00036 
+00037 typedef enum { DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3 } tState;
+00038 
+00039 struct osInfo {
+00040   struct mountPoints   *container;
+00041   elfSectionheader     *sectionHeader;
+00042   struct taskFileInfo   fileInfo;
+00043   struct consoleStruct *terminal;
+00044   uInt16                sectionCount;
+00045   uInt16                stringSection;
+00046   uInt8                 timer;
+00047   uInt8                 v86Task;
+00048   bool                  v86If;
+00049   uInt32                curDir;
+00050   uInt32                vmStart;
+00051   uInt32                stdinSize;
+00052   uInt32                controlKeys;
+00053   char                 *stdin;
+00054   char                 *shstrtab;
+00055   char                 *cwd;
+00056   };
+00057 
+00058 typedef struct taskStruct {
+00059   pidType           id;
+00060   struct taskStruct *prev;
+00061   struct taskStruct *next;
+00062   struct tssStruct  tss;
+00063   struct i387Struct i387;
+00064   struct osInfo     oInfo;
+00065   tState            state;
+00066   uInt32            gid;
+00067   uInt32            uid;
+00068   uInt16            usedMath;
+00069   } kTask_t;
+00070 
+00071 
+00072 int schedInit();
+00073 void sched();
+00074 void schedYield();
+00075 int schedEndTask(pidType pid);
+00076 kTask_t *schedNewTask();
+00077 kTask_t *schedFindTask(uInt32 id);
+00078 int deleteTask(uInt32);
+00079 
+00080 extern kTask_t *taskList;
+00081 extern uInt32  nextID;
+00082 extern kTask_t *_current;
+00083 extern kTask_t *_usedMath;
+00084 
+00085 #ifdef __cplusplus
+00086 }
+00087 #endif
+00088 
+00089 #endif
+00090 
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sched_8h.html b/doc/doxygen/html/sched_8h.html new file mode 100644 index 0000000..312c573 --- /dev/null +++ b/doc/doxygen/html/sched_8h.html @@ -0,0 +1,413 @@ + + +Ubixos: sched.h File Reference + + + +

sched.h File Reference

#include <ubixos/types.h>
+#include <ubixos/elf.h>
+#include <vfs/file.h>
+#include <sys/tss.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  osInfo
struct  taskStruct

Typedefs

typedef taskStruct kTask_t

Enumerations

enum  tState {
+  DEAD = -1, +NEW = 0, +READY = 1, +RUNNING = 2, +
+  IDLE = 3 +
+ }

Functions

int schedInit ()
void sched ()
void schedYield ()
int schedEndTask (pidType pid)
kTask_tschedNewTask ()
kTask_tschedFindTask (uInt32 id)
int deleteTask (uInt32)

Variables

kTask_ttaskList
uInt32 nextID
kTask_t_current
kTask_t_usedMath
+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct taskStruct kTask_t +
+
+ + + + + +
+   + + +

+Structure containing information about a class

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum tState +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + + +
DEAD  +
NEW  +
READY  +
RUNNING  +
IDLE  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
int deleteTask uInt32   ) 
+
+ + + + + +
+   + + +

+Removes task from list

+

+ + + + +
+ + + + + + + + + +
void sched  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int schedEndTask pidType  pid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
kTask_t* schedFindTask uInt32  id  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int schedInit  ) 
+
+ + + + + +
+   + + +

+Allocates memory for task list and sets up default task

+

+ + + + +
+ + + + + + + + + +
kTask_t* schedNewTask  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void schedYield  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
kTask_t* _current +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
kTask_t* _usedMath +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 nextID +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
kTask_t* taskList +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sde_8h-source.html b/doc/doxygen/html/sde_8h-source.html new file mode 100644 index 0000000..3b46610 --- /dev/null +++ b/doc/doxygen/html/sde_8h-source.html @@ -0,0 +1,67 @@ + + +Ubixos: sde.h Source File + + + +

sde.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _SDE_H
+00025 #define _SDE_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #define registerWindow   1
+00030 #define windowReady      2
+00031 #define drawWindow       3
+00032 #define killWindow       4
+00033 
+00034 #ifdef __cplusplus
+00035 extern "C"
+00036 #endif
+00037 void sdeThread();
+00038 
+00039 #ifdef __cplusplus
+00040 extern "C"
+00041 #endif
+00042 void sysSDE(uInt32 cmd,void *ptr);
+00043 
+00044 struct sdeWindows {
+00045   struct sdeWindows *next;
+00046   struct sdeWindows *prev;
+00047   void              *buf;
+00048   pidType            pid;
+00049   uInt8              status;
+00050   };
+00051 
+00052 extern struct sdeWindows *windows;  
+00053   
+00054 #endif
+00055 
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sde_8h.html b/doc/doxygen/html/sde_8h.html new file mode 100644 index 0000000..985dbb9 --- /dev/null +++ b/doc/doxygen/html/sde_8h.html @@ -0,0 +1,217 @@ + + +Ubixos: sde.h File Reference + + + +

sde.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  sdeWindows

Defines

#define registerWindow   1
#define windowReady   2
#define drawWindow   3
#define killWindow   4

Functions

void sdeThread ()
void sysSDE (uInt32 cmd, void *ptr)

Variables

sdeWindowswindows
+


Define Documentation

+

+ + + + +
+ + +
#define drawWindow   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define killWindow   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define registerWindow   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define windowReady   2 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void sdeThread  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void sysSDE uInt32  cmd,
void *  ptr
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct sdeWindows* windows +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/shell_8h-source.html b/doc/doxygen/html/shell_8h-source.html new file mode 100644 index 0000000..34e5310 --- /dev/null +++ b/doc/doxygen/html/shell_8h-source.html @@ -0,0 +1,52 @@ + + +Ubixos: shell.h Source File + + + +

shell.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __SHELL_H__
+00036 #define __SHELL_H__
+00037 
+00038 void shell_init(void);
+00039 
+00040 #endif /* __SHELL_H__ */
+

Generated on Wed Apr 28 17:49:39 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/smp_8h-source.html b/doc/doxygen/html/smp_8h-source.html new file mode 100644 index 0000000..abee3d5 --- /dev/null +++ b/doc/doxygen/html/smp_8h-source.html @@ -0,0 +1,71 @@ + + +Ubixos: smp.h Source File + + + +

smp.h

Go to the documentation of this file.
00001 /*****************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are
+00006 permitted provided that the following conditions are met:
+00007 
+00008 Redistributions of source code must retain the above copyright notice, this list of
+00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
+00010 form must reproduce the above copyright notice, this list of conditions, the following
+00011 disclaimer and the list of authors in the documentation and/or other materials provided
+00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
+00013 contributors may be used to endorse or promote products derived from this software
+00014 without specific prior written permission.
+00015 
+00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00025 
+00026  $Id$
+00027 
+00028 *****************************************************************************************/
+00029 
+00030 #ifndef _SMP_H
+00031 #define _SMP_H
+00032 
+00033 #include <ubixos/types.h>
+00034 
+00036 struct cpuinfo_t {
+00037   uInt8  id;
+00038   uInt8  ok;  
+00039   uInt8  apic_id,apic_ver;
+00040   uInt32 signature; 
+00041   uInt32 feature;
+00042   uInt32 max;
+00043   char   brand[49];  
+00044   char   ident[17];
+00045   };
+00046 
+00048 void smpInit();
+00050 void cpuidDetect();
+00051 uInt8 cpuInfo();
+00053 uInt32 getEflags();
+00055 void setEflags(uInt32);
+00057 void cpuid(uInt32,uInt32 *);
+00058 void apicMagic();
+00059 
+00060 #endif
+00061 
+00062 /***
+00063  END
+00064  ***/
+00065 
+

Generated on Sat May 8 09:28:18 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/smp_8h.html b/doc/doxygen/html/smp_8h.html new file mode 100644 index 0000000..03115fb --- /dev/null +++ b/doc/doxygen/html/smp_8h.html @@ -0,0 +1,244 @@ + + +Ubixos: smp.h File Reference + + + +

smp.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  cpuinfo_t

Functions

void smpInit ()
void cpuidDetect ()
uInt8 cpuInfo ()
uInt32 getEflags ()
void setEflags (uInt32)
void cpuid (uInt32, uInt32 *)
void apicMagic ()
+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void apicMagic  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void cpuid uInt32 ,
uInt32
+
+ + + + + +
+   + + +

+Calls the processor instruction CPUID

+

+ + + + +
+ + + + + + + + + +
void cpuidDetect  ) 
+
+ + + + + +
+   + + +

+Detects for the processor instruction CPUID

+

+ + + + +
+ + + + + + + + + +
uInt8 cpuInfo  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
uInt32 getEflags  ) 
+
+ + + + + +
+   + + +

+Gets the extended flags from the CPU

+

+ + + + +
+ + + + + + + + + + +
void setEflags uInt32   ) 
+
+ + + + + +
+   + + +

+Sets the extended flags in the CPU

+

+ + + + +
+ + + + + + + + + +
void smpInit  ) 
+
+ + + + + +
+   + + +

+Inits multi-processor system and calls cpuiddetect and cpuid

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sockets_8h-source.html b/doc/doxygen/html/sockets_8h-source.html new file mode 100644 index 0000000..fd18db7 --- /dev/null +++ b/doc/doxygen/html/sockets_8h-source.html @@ -0,0 +1,116 @@ + + +Ubixos: sockets.h Source File + + + +

sockets.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 
+00036 
+00037 #ifndef __LWIP_SOCKETS_H__
+00038 #define __LWIP_SOCKETS_H__
+00039 
+00040 #include <ubixos/types.h>
+00041 
+00042 struct in_addr {
+00043   uInt32 s_addr;
+00044 };
+00045 
+00046 
+00047 struct sockaddr_in {
+00048   uInt8 sin_len;
+00049   uInt8 sin_family;
+00050   uInt16 sin_port;
+00051   struct in_addr sin_addr;
+00052   char sin_zero[8];
+00053 };
+00054 
+00055 struct sockaddr {
+00056   uInt8 sa_len;
+00057   uInt8 sa_family;
+00058   char sa_data[14];
+00059 };
+00060 
+00061 #define SOCK_STREAM     1
+00062 #define SOCK_DGRAM      2
+00063 
+00064 #define AF_INET         2
+00065 #define PF_INET         AF_INET
+00066 
+00067 #define IPPROTO_TCP     6
+00068 #define IPPROTO_UDP     17
+00069 
+00070 #define INADDR_ANY      0
+00071 #define INADDR_BROADCAST 0xffffffff
+00072 
+00073 int lwip_accept(int s, struct sockaddr *addr, int *addrlen);
+00074 int lwip_bind(int s, struct sockaddr *name, int namelen);
+00075 int lwip_close(int s);
+00076 int lwip_connect(int s, struct sockaddr *name, int namelen);
+00077 int lwip_listen(int s, int backlog);
+00078 int lwip_recv(int s, void *mem, int len, unsigned int flags);
+00079 int lwip_read(int s, void *mem, int len);
+00080 int lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
+00081                   struct sockaddr *from, int *fromlen);
+00082 int lwip_send(int s, void *dataptr, int size, unsigned int flags);
+00083 int lwip_sendto(int s, void *dataptr, int size, unsigned int flags,
+00084                 struct sockaddr *to, int tolen);
+00085 int lwip_socket(int domain, int type, int protocol);
+00086 int lwip_write(int s, void *dataptr, int size);
+00087 
+00088 #ifdef LWIP_COMPAT_SOCKETS
+00089 #define accept(a,b,c)         lwip_accept(a,b,c)
+00090 #define bind(a,b,c)           lwip_bind(a,b,c)
+00091 #define close(s)              lwip_close(s)
+00092 #define connect(a,b,c)        lwip_connect(a,b,c)
+00093 #define listen(a,b)           lwip_listen(a,b)
+00094 #define recv(a,b,c,d)         lwip_recv(a,b,c,d)
+00095 #define read(a,b,c)           lwip_read(a,b,c)
+00096 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
+00097 #define send(a,b,c,d)         lwip_send(a,b,c,d)
+00098 #define sendto(a,b,c,d,e,f)   lwip_sendto(a,b,c,d,e,f)
+00099 #define socket(a,b,c)         lwip_socket(a,b,c)
+00100 #define write(a,b,c)          lwip_write(a,b,c)
+00101 #endif /* LWIP_NO_COMPAT_SOCKETS */
+00102 
+00103 #endif /* __LWIP_SOCKETS_H__ */
+00104 
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sockets_8h.html b/doc/doxygen/html/sockets_8h.html new file mode 100644 index 0000000..6f6612f --- /dev/null +++ b/doc/doxygen/html/sockets_8h.html @@ -0,0 +1,800 @@ + + +Ubixos: sockets.h File Reference + + + +

sockets.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  in_addr
struct  sockaddr
struct  sockaddr_in

Defines

#define SOCK_STREAM   1
#define SOCK_DGRAM   2
#define AF_INET   2
#define PF_INET   AF_INET
#define IPPROTO_TCP   6
#define IPPROTO_UDP   17
#define INADDR_ANY   0
#define INADDR_BROADCAST   0xffffffff

Functions

int lwip_accept (int s, struct sockaddr *addr, int *addrlen)
int lwip_bind (int s, struct sockaddr *name, int namelen)
int lwip_close (int s)
int lwip_connect (int s, struct sockaddr *name, int namelen)
int lwip_listen (int s, int backlog)
int lwip_recv (int s, void *mem, int len, unsigned int flags)
int lwip_read (int s, void *mem, int len)
int lwip_recvfrom (int s, void *mem, int len, unsigned int flags, struct sockaddr *from, int *fromlen)
int lwip_send (int s, void *dataptr, int size, unsigned int flags)
int lwip_sendto (int s, void *dataptr, int size, unsigned int flags, struct sockaddr *to, int tolen)
int lwip_socket (int domain, int type, int protocol)
int lwip_write (int s, void *dataptr, int size)
+


Define Documentation

+

+ + + + +
+ + +
#define AF_INET   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define INADDR_ANY   0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define INADDR_BROADCAST   0xffffffff +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IPPROTO_TCP   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define IPPROTO_UDP   17 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define PF_INET   AF_INET +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define SOCK_DGRAM   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define SOCK_STREAM   1 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_accept int  s,
struct sockaddr addr,
int *  addrlen
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_bind int  s,
struct sockaddr name,
int  namelen
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int lwip_close int  s  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_connect int  s,
struct sockaddr name,
int  namelen
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int lwip_listen int  s,
int  backlog
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_read int  s,
void *  mem,
int  len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_recv int  s,
void *  mem,
int  len,
unsigned int  flags
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_recvfrom int  s,
void *  mem,
int  len,
unsigned int  flags,
struct sockaddr from,
int *  fromlen
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_send int  s,
void *  dataptr,
int  size,
unsigned int  flags
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_sendto int  s,
void *  dataptr,
int  size,
unsigned int  flags,
struct sockaddr to,
int  tolen
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_socket int  domain,
int  type,
int  protocol
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int lwip_write int  s,
void *  dataptr,
int  size
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/spinlock_8h-source.html b/doc/doxygen/html/spinlock_8h-source.html new file mode 100644 index 0000000..cf5d943 --- /dev/null +++ b/doc/doxygen/html/spinlock_8h-source.html @@ -0,0 +1,62 @@ + + +Ubixos: spinlock.h Source File + + + +

spinlock.h

Go to the documentation of this file.
00001 /*****************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are
+00006 permitted provided that the following conditions are met:
+00007 
+00008 Redistributions of source code must retain the above copyright notice, this list of
+00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
+00010 form must reproduce the above copyright notice, this list of conditions, the following
+00011 disclaimer and the list of authors in the documentation and/or other materials provided
+00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
+00013 contributors may be used to endorse or promote products derived from this software
+00014 without specific prior written permission.
+00015 
+00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00025 
+00026  $Id$
+00027 
+00028 *****************************************************************************************/
+00029 
+00030 #ifndef _SPINLOCK_H
+00031 #define _SPINLOCK_H
+00032 
+00033 #include <ubixos/types.h>
+00034 
+00035 #define SPIN_LOCK_INITIALIZER   0
+00036 
+00037 typedef volatile int spinLock_t;
+00038 
+00039 extern inline void spinLockInit(spinLock_t *);
+00040 extern inline void spinUnlock(spinLock_t *);
+00041 extern inline int spinTryLock(spinLock_t *);
+00042 extern inline void spinLock(spinLock_t *);
+00043 extern inline int spinLockLocked(spinLock_t *);
+00044 
+00045 #endif
+00046 
+00047 /***
+00048  END
+00049  ***/
+00050 
+

Generated on Sat May 8 09:28:18 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/spinlock_8h.html b/doc/doxygen/html/spinlock_8h.html new file mode 100644 index 0000000..d5e3878 --- /dev/null +++ b/doc/doxygen/html/spinlock_8h.html @@ -0,0 +1,227 @@ + + +Ubixos: spinlock.h File Reference + + + +

spinlock.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + +

Defines

#define SPIN_LOCK_INITIALIZER   0

Typedefs

typedef volatile int spinLock_t

Functions

void spinLockInit (spinLock_t *)
void spinUnlock (spinLock_t *)
int spinTryLock (spinLock_t *)
void spinLock (spinLock_t *)
int spinLockLocked (spinLock_t *)
+


Define Documentation

+

+ + + + +
+ + +
#define SPIN_LOCK_INITIALIZER   0 +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef volatile int spinLock_t +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void spinLock spinLock_t  )  [inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void spinLockInit spinLock_t  )  [inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int spinLockLocked spinLock_t  )  [inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int spinTryLock spinLock_t  )  [inline]
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void spinUnlock spinLock_t  )  [inline]
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/stats_8h-source.html b/doc/doxygen/html/stats_8h-source.html new file mode 100644 index 0000000..56aceca --- /dev/null +++ b/doc/doxygen/html/stats_8h-source.html @@ -0,0 +1,124 @@ + + +Ubixos: stats.h Source File + + + +

stats.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_STATS_H__
+00036 #define __LWIP_STATS_H__
+00037 
+00038 #include "net/opt.h"
+00039 #include "net/arch/cc.h"
+00040 
+00041 #include "net/memp.h"
+00042 
+00043 #ifdef STATS
+00044 
+00045 struct stats_proto {
+00046   uInt16 xmit;    /* Transmitted packets. */
+00047   uInt16 rexmit;  /* Retransmitted packets. */
+00048   uInt16 recv;    /* Received packets. */
+00049   uInt16 fw;      /* Forwarded packets. */
+00050   uInt16 drop;    /* Dropped packets. */
+00051   uInt16 chkerr;  /* Checksum error. */
+00052   uInt16 lenerr;  /* Invalid length error. */
+00053   uInt16 memerr;  /* Out of memory error. */
+00054   uInt16 rterr;   /* Routing error. */
+00055   uInt16 proterr; /* Protocol error. */
+00056   uInt16 opterr;  /* Error in options. */
+00057   uInt16 err;     /* Misc error. */
+00058   uInt16 cachehit;
+00059 };
+00060 
+00061 struct stats_mem {
+00062   uInt16 avail;
+00063   uInt16 used;
+00064   uInt16 max;  
+00065   uInt16 err;
+00066   uInt16 reclaimed;
+00067 };
+00068 
+00069 struct stats_pbuf {
+00070   uInt16 avail;
+00071   uInt16 used;
+00072   uInt16 max;  
+00073   uInt16 err;
+00074   uInt16 reclaimed;
+00075 
+00076   uInt16 alloc_locked;
+00077   uInt16 refresh_locked;
+00078 };
+00079 
+00080 struct stats_syselem {
+00081   uInt16 used;
+00082   uInt16 max;
+00083   uInt16 err;
+00084 };
+00085 
+00086 struct stats_sys {
+00087   struct stats_syselem sem;
+00088   struct stats_syselem mbox;
+00089 };
+00090 
+00091 struct stats_ {
+00092   struct stats_proto link;
+00093   struct stats_proto ip;
+00094   struct stats_proto icmp;
+00095   struct stats_proto udp;
+00096   struct stats_proto tcp;
+00097   struct stats_pbuf pbuf;
+00098   struct stats_mem mem;
+00099   struct stats_mem memp[MEMP_MAX];
+00100   struct stats_sys sys;
+00101 };
+00102 
+00103 extern struct stats_ stats;
+00104 
+00105 #endif /* STATS */
+00106 
+00107 void stats_init(void);
+00108 #endif /* __LWIP_STATS_H__ */
+00109 
+00110 
+00111 
+00112 
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/stats_8h.html b/doc/doxygen/html/stats_8h.html new file mode 100644 index 0000000..3ac2521 --- /dev/null +++ b/doc/doxygen/html/stats_8h.html @@ -0,0 +1,53 @@ + + +Ubixos: stats.h File Reference + + + +

stats.h File Reference

#include "net/opt.h"
+#include "net/arch/cc.h"
+#include "net/memp.h"
+ +

+Go to the source code of this file. + + + + +

Functions

void stats_init (void)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void stats_init void   ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/stdarg_8h-source.html b/doc/doxygen/html/stdarg_8h-source.html new file mode 100644 index 0000000..666d2bf --- /dev/null +++ b/doc/doxygen/html/stdarg_8h-source.html @@ -0,0 +1,55 @@ + + +Ubixos: stdarg.h Source File + + + +

stdarg.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _STDARG_H
+00025 #define _STDARG_H
+00026 
+00027 typedef char *vaList[1];
+00028 
+00029 #define vaStart(ap, parm)  ((ap)[0] = (char *) &parm \
+00030          + ((sizeof(parm) + sizeof(int) - 1) & ~(sizeof(int) - 1)), (void) 0)
+00031 
+00032 #define vaArg(ap, type)  ((ap)[0] += \
+00033          ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)), \
+00034         (*(type *) ((ap)[0] \
+00035          - ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)) )))
+00036 
+00037 #define vaEnd(ap)   ((ap)[0] = 0, (void) 0)
+00038 
+00039 
+00040 int vsprintf(char *buf, const char *fmt, vaList args);
+00041 
+00042 #endif
+00043 
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/stdarg_8h.html b/doc/doxygen/html/stdarg_8h.html new file mode 100644 index 0000000..04a07ea --- /dev/null +++ b/doc/doxygen/html/stdarg_8h.html @@ -0,0 +1,192 @@ + + +Ubixos: stdarg.h File Reference + + + +

stdarg.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + + +

Defines

#define vaStart(ap, parm)
#define vaArg(ap, type)
#define vaEnd(ap)   ((ap)[0] = 0, (void) 0)

Typedefs

typedef char * vaList [1]

Functions

int vsprintf (char *buf, const char *fmt, vaList args)
+


Define Documentation

+

+ + + + +
+ + + + + + + + + + +
#define vaArgap,
type   )  +
+
+ + + + + +
+   + + +

+Value:

((ap)[0] += \
+         ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)), \
+        (*(type *) ((ap)[0] \
+         - ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)) )))
+
+

+ + + + +
+ + + + + + + +
#define vaEndap   )    ((ap)[0] = 0, (void) 0) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define vaStartap,
parm   )  +
+
+ + + + + +
+   + + +

+Value:

((ap)[0] = (char *) &parm \
+         + ((sizeof(parm) + sizeof(int) - 1) & ~(sizeof(int) - 1)), (void) 0)
+
+


Typedef Documentation

+

+ + + + +
+ + +
typedef char* vaList[1] +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int vsprintf char *  buf,
const char *  fmt,
vaList  args
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/string_8h-source.html b/doc/doxygen/html/string_8h-source.html new file mode 100644 index 0000000..1989989 --- /dev/null +++ b/doc/doxygen/html/string_8h-source.html @@ -0,0 +1,48 @@ + + +Ubixos: string.h Source File + + + +

string.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _STRING_H
+00025 #define _STRING_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 void * kmemcpy(void * dst, const void * src, size_t length);
+00030 void *kmemset(void * dst, int c, size_t length);
+00031 int kstrlen(const char * string);
+00032 
+00033 int sprintf(char * str, const char * format, ...);
+00034 
+00035 #endif
+00036 
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/string_8h.html b/doc/doxygen/html/string_8h.html new file mode 100644 index 0000000..2f58cf6 --- /dev/null +++ b/doc/doxygen/html/string_8h.html @@ -0,0 +1,189 @@ + + +Ubixos: string.h File Reference + + + +

string.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + +

Functions

void * kmemcpy (void *dst, const void *src, size_t length)
void * kmemset (void *dst, int c, size_t length)
int kstrlen (const char *string)
int sprintf (char *str, const char *format,...)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void* kmemcpy void *  dst,
const void *  src,
size_t  length
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void* kmemset void *  dst,
int  c,
size_t  length
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int kstrlen const char *  string  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int sprintf char *  str,
const char *  format,
... 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:22 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/struct_drv_geom.html b/doc/doxygen/html/struct_drv_geom.html new file mode 100644 index 0000000..213c04b --- /dev/null +++ b/doc/doxygen/html/struct_drv_geom.html @@ -0,0 +1,93 @@ + + +Ubixos: DrvGeom struct Reference + + + +

DrvGeom Struct Reference

#include <fdc.h> +

+ + + + + + + + + +

Data Fields

Int8 heads
Int8 tracks
Int8 spt
+


Field Documentation

+

+ + + + +
+ + +
Int8 DrvGeom::heads +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
Int8 DrvGeom::spt +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
Int8 DrvGeom::tracks +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/struct_t_mode___rec.html b/doc/doxygen/html/struct_t_mode___rec.html new file mode 100644 index 0000000..172ae96 --- /dev/null +++ b/doc/doxygen/html/struct_t_mode___rec.html @@ -0,0 +1,1044 @@ + + +Ubixos: TMode_Rec struct Reference + + + +

TMode_Rec Struct Reference

#include <ogDisplay_VESA.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

uInt16 ModeAttributes __attribute__ ((packed))
uInt8 WindowAFlags __attribute__ ((packed))
uInt8 WindowBFlags __attribute__ ((packed))
uInt16 Granularity __attribute__ ((packed))
uInt16 WindowSize __attribute__ ((packed))
uInt16 WindowASeg __attribute__ ((packed))
uInt16 WindowBSeg __attribute__ ((packed))
void *BankSwitch __attribute__ ((packed))
uInt16 BytesPerLine __attribute__ ((packed))
uInt16 xRes __attribute__ ((packed))
uInt16 yRes __attribute__ ((packed))
uInt8 CharWidth __attribute__ ((packed))
uInt8 CharHeight __attribute__ ((packed))
uInt8 NumBitPlanes __attribute__ ((packed))
uInt8 BitsPerPixel __attribute__ ((packed))
uInt8 NumberOfBanks __attribute__ ((packed))
uInt8 MemoryModel __attribute__ ((packed))
uInt8 BankSize __attribute__ ((packed))
uInt8 NumOfImagePages __attribute__ ((packed))
uInt8 Reserved __attribute__ ((packed))
uInt8 RedMaskSize __attribute__ ((packed))
uInt8 RedFieldPosition __attribute__ ((packed))
uInt8 GreenMaskSize __attribute__ ((packed))
uInt8 GreenFieldPosition __attribute__ ((packed))
uInt8 BlueMaskSize __attribute__ ((packed))
uInt8 BlueFieldPosition __attribute__ ((packed))
uInt8 AlphaMaskSize __attribute__ ((packed))
uInt8 AlphaFieldPosition __attribute__ ((packed))
uInt8 DirectColourMode __attribute__ ((packed))
uInt32 physBasePtr __attribute__ ((packed))
void *OffScreenMemOffset __attribute__ ((packed))
uInt16 OffScreenMemSize __attribute__ ((packed))
uInt8 paddington[461] __attribute__ ((packed))
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
uInt8 paddington [461] TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 OffScreenMemSize TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* OffScreenMemOffset TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 physBasePtr TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 DirectColourMode TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 AlphaFieldPosition TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 AlphaMaskSize TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 BlueFieldPosition TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 BlueMaskSize TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 GreenFieldPosition TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 GreenMaskSize TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 RedFieldPosition TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 RedMaskSize TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 Reserved TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 NumOfImagePages TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 BankSize TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 MemoryModel TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 NumberOfBanks TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 BitsPerPixel TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 NumBitPlanes TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 CharHeight TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 CharWidth TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 yRes TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 xRes TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 BytesPerLine TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* BankSwitch TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 WindowBSeg TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 WindowASeg TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 WindowSize TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 Granularity TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 WindowBFlags TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 WindowAFlags TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 ModeAttributes TMode_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/struct_t_v_e_s_a___rec.html b/doc/doxygen/html/struct_t_v_e_s_a___rec.html new file mode 100644 index 0000000..93343f6 --- /dev/null +++ b/doc/doxygen/html/struct_t_v_e_s_a___rec.html @@ -0,0 +1,393 @@ + + +Ubixos: TVESA_Rec struct Reference + + + +

TVESA_Rec Struct Reference

#include <ogDisplay_VESA.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

char VBESignature[4] __attribute__ ((packed))
uInt8 minVersion __attribute__ ((packed))
uInt8 majVersion __attribute__ ((packed))
uInt32 OEMStringPtr __attribute__ ((packed))
uInt32 Capabilities __attribute__ ((packed))
uInt32 VideoModePtr __attribute__ ((packed))
uInt16 TotalMemory __attribute__ ((packed))
uInt16 OEMSoftwareRev __attribute__ ((packed))
uInt32 OEMVendorNamePtr __attribute__ ((packed))
uInt32 OEMProductNamePtr __attribute__ ((packed))
uInt32 OEMProductRevPtr __attribute__ ((packed))
uInt8 paddington[474] __attribute__ ((packed))
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
uInt8 paddington [474] TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMProductRevPtr TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMProductNamePtr TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMVendorNamePtr TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 OEMSoftwareRev TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 TotalMemory TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 VideoModePtr TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 Capabilities TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMStringPtr TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 majVersion TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 minVersion TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
char VBESignature [4] TVESA_Rec::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structapi__msg.html b/doc/doxygen/html/structapi__msg.html new file mode 100644 index 0000000..bca0262 --- /dev/null +++ b/doc/doxygen/html/structapi__msg.html @@ -0,0 +1,69 @@ + + +Ubixos: api_msg struct Reference + + + +

api_msg Struct Reference

#include <api_msg.h> +

+ + + + + + + +

Data Fields

enum api_msg_type type
api_msg_msg msg
+


Field Documentation

+

+ + + + +
+ + +
struct api_msg_msg api_msg::msg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
enum api_msg_type api_msg::type +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structapi__msg__msg.html b/doc/doxygen/html/structapi__msg__msg.html new file mode 100644 index 0000000..c934ab6 --- /dev/null +++ b/doc/doxygen/html/structapi__msg__msg.html @@ -0,0 +1,317 @@ + + +Ubixos: api_msg_msg struct Reference + + + +

api_msg_msg Struct Reference

#include <api_msg.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

netconnconn
enum netconn_type conntype
union {
   pbuf *   p
   struct {
      ip_addr *   ipaddr
      uInt16   port
   }   bc
   struct {
      void *   dataptr
      uInt16   len
      unsigned char   copy
   }   w
   sys_mbox_t   mbox
   uInt16   len
msg
+


Field Documentation

+

+ + + + +
+ + +
struct { ... } api_msg_msg::bc +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct netconn* api_msg_msg::conn +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
enum netconn_type api_msg_msg::conntype +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned char api_msg_msg::copy +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* api_msg_msg::dataptr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr* api_msg_msg::ipaddr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 api_msg_msg::len +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
sys_mbox_t api_msg_msg::mbox +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
union { ... } api_msg_msg::msg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct pbuf* api_msg_msg::p +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 api_msg_msg::port +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct { ... } api_msg_msg::w +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structarpcom.html b/doc/doxygen/html/structarpcom.html new file mode 100644 index 0000000..604fa94 --- /dev/null +++ b/doc/doxygen/html/structarpcom.html @@ -0,0 +1,93 @@ + + +Ubixos: arpcom struct Reference + + + +

arpcom Struct Reference

#include <lnc.h> +

+ + + + + + + + + +

Data Fields

uInt8 ac_enaddr [6]
int ac_multicnt
void * ac_netgraph
+


Field Documentation

+

+ + + + +
+ + +
uInt8 arpcom::ac_enaddr[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int arpcom::ac_multicnt +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* arpcom::ac_netgraph +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structblock_allocation_table_entry.html b/doc/doxygen/html/structblock_allocation_table_entry.html new file mode 100644 index 0000000..2f2d31b --- /dev/null +++ b/doc/doxygen/html/structblock_allocation_table_entry.html @@ -0,0 +1,120 @@ + + +Ubixos: blockAllocationTableEntry struct Reference + + + +

blockAllocationTableEntry Struct Reference

#include <ubixfs.h> +

+ + + + + + + + + + + +

Data Fields

long attributes
long realSector
long nextBlock
long reserved
+


Detailed Description

+Block Allocation Table Entry +

+


Field Documentation

+

+ + + + +
+ + +
long blockAllocationTableEntry::attributes +
+
+ + + + + +
+   + + +

+Block Attributes

+

+ + + + +
+ + +
long blockAllocationTableEntry::nextBlock +
+
+ + + + + +
+   + + +

+Sector Of Next Block

+

+ + + + +
+ + +
long blockAllocationTableEntry::realSector +
+
+ + + + + +
+   + + +

+Real Sector

+

+ + + + +
+ + +
long blockAllocationTableEntry::reserved +
+
+ + + + + +
+   + + +

+Reserved

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structboot_sect.html b/doc/doxygen/html/structboot_sect.html new file mode 100644 index 0000000..0aac35e --- /dev/null +++ b/doc/doxygen/html/structboot_sect.html @@ -0,0 +1,315 @@ + + +Ubixos: bootSect struct Reference + + + +

bootSect Struct Reference

Bootsector structure. +More... +

+#include <ubixfs.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

uInt8 jmp [4]
uInt8 id [6]
uInt16 version
uInt16 tmp
uInt16 fsStart
uInt16 tmp2
uInt32 krnl_start
uInt BytesPerSector
uInt SectersPerTrack
uInt TotalHeads
uInt32 TotalSectors
uInt8 code [479]
+


Detailed Description

+Bootsector structure. +

+


Field Documentation

+

+ + + + +
+ + +
uInt bootSect::BytesPerSector +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 bootSect::code[479] +
+
+ + + + + +
+   + + +

+Rest of code

+

+ + + + +
+ + +
uInt16 bootSect::fsStart +
+
+ + + + + +
+   + + +

+Start of filesystem

+

+ + + + +
+ + +
uInt8 bootSect::id[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 bootSect::jmp[4] +
+
+ + + + + +
+   + + +

+Jump code

+

+ + + + +
+ + +
uInt32 bootSect::krnl_start +
+
+ + + + + +
+   + + +

+Start of kernel

+

+ + + + +
+ + +
uInt bootSect::SectersPerTrack +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 bootSect::tmp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 bootSect::tmp2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt bootSect::TotalHeads +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 bootSect::TotalSectors +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 bootSect::version +
+
+ + + + + +
+   + + +

+Version of UbixFS

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structconfadd.html b/doc/doxygen/html/structconfadd.html new file mode 100644 index 0000000..ac50e09 --- /dev/null +++ b/doc/doxygen/html/structconfadd.html @@ -0,0 +1,165 @@ + + +Ubixos: confadd struct Reference + + + +

confadd Struct Reference

#include <pci.h> +

+ + + + + + + + + + + + + + + +

Data Fields

uInt8 reg:8
uInt8 func:3
uInt8 dev:5
uInt8 bus:8
uInt8 rsvd:7
uInt8 enable:1
+


Field Documentation

+

+ + + + +
+ + +
uInt8 confadd::bus +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 confadd::dev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 confadd::enable +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 confadd::func +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 confadd::reg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 confadd::rsvd +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structcpuinfo__t.html b/doc/doxygen/html/structcpuinfo__t.html new file mode 100644 index 0000000..552a912 --- /dev/null +++ b/doc/doxygen/html/structcpuinfo__t.html @@ -0,0 +1,249 @@ + + +Ubixos: cpuinfo_t struct Reference + + + +

cpuinfo_t Struct Reference

#include <smp.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

uInt8 id
uInt8 ok
 1=Ok, 0=Bad

uInt8 apic_id
uInt8 apic_ver
uInt32 signature
 Family, Model, Stepping.

uInt32 feature
uInt32 max
char brand [49]
 Brand name.

char ident [17]
+


Detailed Description

+Structure containing informtaion about the CPU +

+


Field Documentation

+

+ + + + +
+ + +
uInt8 cpuinfo_t::apic_id +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 cpuinfo_t::apic_ver +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char cpuinfo_t::brand[49] +
+
+ + + + + +
+   + + +

+Brand name. +

+

+

+ + + + +
+ + +
uInt32 cpuinfo_t::feature +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 cpuinfo_t::id +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char cpuinfo_t::ident[17] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 cpuinfo_t::max +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 cpuinfo_t::ok +
+
+ + + + + +
+   + + +

+1=Ok, 0=Bad +

+

+

+ + + + +
+ + +
uInt32 cpuinfo_t::signature +
+
+ + + + + +
+   + + +

+Family, Model, Stepping. +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdev_fs_devices.html b/doc/doxygen/html/structdev_fs_devices.html new file mode 100644 index 0000000..d0598bb --- /dev/null +++ b/doc/doxygen/html/structdev_fs_devices.html @@ -0,0 +1,165 @@ + + +Ubixos: devFsDevices struct Reference + + + +

devFsDevices Struct Reference

#include <devfs.h> +

+ + + + + + + + + + + + + + + +

Data Fields

devFsDevicesnext
devFsDevicesprev
uInt8 devType
uInt16 devMajor
uInt16 devMinor
char devName [32]
+


Field Documentation

+

+ + + + +
+ + +
uInt16 devFsDevices::devMajor +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 devFsDevices::devMinor +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char devFsDevices::devName[32] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 devFsDevices::devType +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct devFsDevices* devFsDevices::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct devFsDevices* devFsDevices::prev +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdev_fs_info.html b/doc/doxygen/html/structdev_fs_info.html new file mode 100644 index 0000000..8e4c1d9 --- /dev/null +++ b/doc/doxygen/html/structdev_fs_info.html @@ -0,0 +1,45 @@ + + +Ubixos: devFsInfo struct Reference + + + +

devFsInfo Struct Reference

#include <devfs.h> +

+ + + + + +

Data Fields

devFsDevicesdeviceList
+


Field Documentation

+

+ + + + +
+ + +
struct devFsDevices* devFsInfo::deviceList +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdev_method_type.html b/doc/doxygen/html/structdev_method_type.html new file mode 100644 index 0000000..3d01a34 --- /dev/null +++ b/doc/doxygen/html/structdev_method_type.html @@ -0,0 +1,19 @@ + + +Ubixos: devMethodType struct Reference + + + +

devMethodType Struct Reference

#include <driver.h> +

+ + +
+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdevice.html b/doc/doxygen/html/structdevice.html new file mode 100644 index 0000000..e10b980 --- /dev/null +++ b/doc/doxygen/html/structdevice.html @@ -0,0 +1,141 @@ + + +Ubixos: device struct Reference + + + +

device Struct Reference

#include <device.old.h> +

+ + + + + + + + + + + + + +

Data Fields

netnet
uInt16 ioAddr
uInt32 irq
ei_devicepriv
uInt32 mtu
+


Field Documentation

+

+ + + + +
+ + +
uInt16 device::ioAddr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 device::irq +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 device::mtu +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct net* device::net +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ei_device* device::priv +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdevice_node.html b/doc/doxygen/html/structdevice_node.html new file mode 100644 index 0000000..6423670 --- /dev/null +++ b/doc/doxygen/html/structdevice_node.html @@ -0,0 +1,381 @@ + + +Ubixos: deviceNode struct Reference + + + +

deviceNode Struct Reference

#include <device.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

deviceNodeprev
deviceNodenext
char type
int major
int minor
uInt32 size
void * info
void(* read )(void *, void *, uInt32, uInt32)
void(* write )(void *, void *, uInt32, uInt32)
void(* reset )(void *)
void(* init )(void *)
void(* ioctl )(void *)
void(* stop )(void *)
void(* start )(void *)
void(* standby )(void *)
+


Field Documentation

+

+ + + + +
+ + +
void* deviceNode::info +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::init)(void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::ioctl)(void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int deviceNode::major +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int deviceNode::minor +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct deviceNode* deviceNode::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct deviceNode* deviceNode::prev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::read)(void *,void *,uInt32,uInt32) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::reset)(void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 deviceNode::size +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::standby)(void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::start)(void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::stop)(void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char deviceNode::type +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* deviceNode::write)(void *,void *,uInt32,uInt32) +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdirectory_entry.html b/doc/doxygen/html/structdirectory_entry.html new file mode 100644 index 0000000..50e5db5 --- /dev/null +++ b/doc/doxygen/html/structdirectory_entry.html @@ -0,0 +1,243 @@ + + +Ubixos: directoryEntry struct Reference + + + +

directoryEntry Struct Reference

UbixFS Directory Entry. +More... +

+#include <ubixfs.h> +

+ + + + + + + + + + + + + + + + + + + + + +

Data Fields

uInt32 startCluster
uInt32 size
uInt32 creationDate
uInt32 lastModified
uInt32 uid
uInt32 gid
uInt16 attributes
uInt16 permissions
char fileName [256]
+


Detailed Description

+UbixFS Directory Entry. +

+


Field Documentation

+

+ + + + +
+ + +
uInt16 directoryEntry::attributes +
+
+ + + + + +
+   + + +

+Files Attributes

+

+ + + + +
+ + +
uInt32 directoryEntry::creationDate +
+
+ + + + + +
+   + + +

+Date Created

+

+ + + + +
+ + +
char directoryEntry::fileName[256] +
+
+ + + + + +
+   + + +

+File Name

+

+ + + + +
+ + +
uInt32 directoryEntry::gid +
+
+ + + + + +
+   + + +

+GID Of Owner

+

+ + + + +
+ + +
uInt32 directoryEntry::lastModified +
+
+ + + + + +
+   + + +

+Date Last Modified

+

+ + + + +
+ + +
uInt16 directoryEntry::permissions +
+
+ + + + + +
+   + + +

+Files Permissions

+

+ + + + +
+ + +
uInt32 directoryEntry::size +
+
+ + + + + +
+   + + +

+Size Of File

+

+ + + + +
+ + +
uInt32 directoryEntry::startCluster +
+
+ + + + + +
+   + + +

+Starting Cluster Of File

+

+ + + + +
+ + +
uInt32 directoryEntry::uid +
+
+ + + + + +
+   + + +

+UID Of Owner

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdp__rcvhdr.html b/doc/doxygen/html/structdp__rcvhdr.html new file mode 100644 index 0000000..730c66d --- /dev/null +++ b/doc/doxygen/html/structdp__rcvhdr.html @@ -0,0 +1,117 @@ + + +Ubixos: dp_rcvhdr struct Reference + + + +

dp_rcvhdr Struct Reference

#include <ne2k.h> +

+ + + + + + + + + + + +

Data Fields

uInt8 dr_status
uInt8 dr_next
uInt8 dr_rbcl
uInt8 dr_rbch
+


Field Documentation

+

+ + + + +
+ + +
uInt8 dp_rcvhdr::dr_next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 dp_rcvhdr::dr_rbch +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 dp_rcvhdr::dr_rbcl +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 dp_rcvhdr::dr_status +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdrive_info.html b/doc/doxygen/html/structdrive_info.html new file mode 100644 index 0000000..83aa9ec --- /dev/null +++ b/doc/doxygen/html/structdrive_info.html @@ -0,0 +1,309 @@ + + +Ubixos: driveInfo struct Reference + + + +

driveInfo Struct Reference

#include <hd.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

driveDiskLabel * diskLabel
char hdSector [512]
char hdEnable
char hdDev
char hdFlags
char hdShift
long hdMask
long hdMulti
long hdPort
long hdSize
long hdCalc
long parOffset
+


Field Documentation

+

+ + + + +
+ + +
struct driveDiskLabel* driveInfo::diskLabel +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long driveInfo::hdCalc +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char driveInfo::hdDev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char driveInfo::hdEnable +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char driveInfo::hdFlags +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long driveInfo::hdMask +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long driveInfo::hdMulti +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long driveInfo::hdPort +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char driveInfo::hdSector[512] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char driveInfo::hdShift +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long driveInfo::hdSize +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long driveInfo::parOffset +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structdriver_type.html b/doc/doxygen/html/structdriver_type.html new file mode 100644 index 0000000..8b53849 --- /dev/null +++ b/doc/doxygen/html/structdriver_type.html @@ -0,0 +1,69 @@ + + +Ubixos: driverType struct Reference + + + +

driverType Struct Reference

#include <driver.h> +

+ + + + + + + +

Data Fields

const char * devName
devMethodmethods
+


Field Documentation

+

+ + + + +
+ + +
const char* driverType::devName +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
devMethod* driverType::methods +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structei__device.html b/doc/doxygen/html/structei__device.html new file mode 100644 index 0000000..7d6ea03 --- /dev/null +++ b/doc/doxygen/html/structei__device.html @@ -0,0 +1,213 @@ + + +Ubixos: ei_device struct Reference + + + +

ei_device Struct Reference

#include <device.old.h> +

+ + + + + + + + + + + + + + + + + + + +

Data Fields

int txStartPage
int rxStartPage
int stopPage
int currentPage
uInt16 word16
uInt32 pingPong
int tx1
int tx2
+


Field Documentation

+

+ + + + +
+ + +
int ei_device::currentPage +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 ei_device::pingPong +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int ei_device::rxStartPage +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int ei_device::stopPage +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int ei_device::tx1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int ei_device::tx2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int ei_device::txStartPage +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 ei_device::word16 +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structelf_dynamic.html b/doc/doxygen/html/structelf_dynamic.html new file mode 100644 index 0000000..7711f21 --- /dev/null +++ b/doc/doxygen/html/structelf_dynamic.html @@ -0,0 +1,69 @@ + + +Ubixos: elfDynamic struct Reference + + + +

elfDynamic Struct Reference

#include <elf.h> +

+ + + + + + + +

Data Fields

uInt32 dynVal
uInt32 dynPtr
+


Field Documentation

+

+ + + + +
+ + +
uInt32 elfDynamic::dynPtr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 elfDynamic::dynVal +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structelf_dynsym.html b/doc/doxygen/html/structelf_dynsym.html new file mode 100644 index 0000000..c6bb7fb --- /dev/null +++ b/doc/doxygen/html/structelf_dynsym.html @@ -0,0 +1,117 @@ + + +Ubixos: elfDynsym struct Reference + + + +

elfDynsym Struct Reference

#include <elf.h> +

+ + + + + + + + + + + +

Data Fields

uInt32 dynName
uInt32 dynValue
uInt32 dynSize
uInt32 dynInfo
+


Field Documentation

+

+ + + + +
+ + +
uInt32 elfDynsym::dynInfo +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 elfDynsym::dynName +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 elfDynsym::dynSize +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 elfDynsym::dynValue +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structelf_header.html b/doc/doxygen/html/structelf_header.html new file mode 100644 index 0000000..e65f0ff --- /dev/null +++ b/doc/doxygen/html/structelf_header.html @@ -0,0 +1,357 @@ + + +Ubixos: elfHeader struct Reference + + + +

elfHeader Struct Reference

#include <elf.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

uInt8 eIdent [16]
uInt16 eType
uInt16 eMachine
uInt32 eVersion
uInt32 eEntry
uInt32 ePhoff
uInt32 eShoff
uInt32 eFlags
uInt16 eEhsize
uInt16 ePhentsize
uInt16 ePhnum
uInt16 eShentsize
uInt16 eShnum
uInt16 eShstrndx
+


Field Documentation

+

+ + + + +
+ + +
uInt16 elfHeader::eEhsize +
+
+ + + + + +
+   + + +

+Size of ELF header in bytes.

+

+ + + + +
+ + +
uInt32 elfHeader::eEntry +
+
+ + + + + +
+   + + +

+Entry point.

+

+ + + + +
+ + +
uInt32 elfHeader::eFlags +
+
+ + + + + +
+   + + +

+Architecture-specific flags.

+

+ + + + +
+ + +
uInt8 elfHeader::eIdent[16] +
+
+ + + + + +
+   + + +

+File identification.

+

+ + + + +
+ + +
uInt16 elfHeader::eMachine +
+
+ + + + + +
+   + + +

+Machine architecture.

+

+ + + + +
+ + +
uInt16 elfHeader::ePhentsize +
+
+ + + + + +
+   + + +

+Size of program header entry.

+

+ + + + +
+ + +
uInt16 elfHeader::ePhnum +
+
+ + + + + +
+   + + +

+Number of program header entries.

+

+ + + + +
+ + +
uInt32 elfHeader::ePhoff +
+
+ + + + + +
+   + + +

+Program header file offset.

+

+ + + + +
+ + +
uInt16 elfHeader::eShentsize +
+
+ + + + + +
+   + + +

+Size of section header entry.

+

+ + + + +
+ + +
uInt16 elfHeader::eShnum +
+
+ + + + + +
+   + + +

+Number of section header entries.

+

+ + + + +
+ + +
uInt32 elfHeader::eShoff +
+
+ + + + + +
+   + + +

+Section header file offset.

+

+ + + + +
+ + +
uInt16 elfHeader::eShstrndx +
+
+ + + + + +
+   + + +

+Section name strings section.

+

+ + + + +
+ + +
uInt16 elfHeader::eType +
+
+ + + + + +
+   + + +

+File type.

+

+ + + + +
+ + +
uInt32 elfHeader::eVersion +
+
+ + + + + +
+   + + +

+ELF format version.

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structelf_plt_info.html b/doc/doxygen/html/structelf_plt_info.html new file mode 100644 index 0000000..dc4844b --- /dev/null +++ b/doc/doxygen/html/structelf_plt_info.html @@ -0,0 +1,69 @@ + + +Ubixos: elfPltInfo struct Reference + + + +

elfPltInfo Struct Reference

#include <elf.h> +

+ + + + + + + +

Data Fields

uInt32 pltOffset
uInt32 pltInfo
+


Field Documentation

+

+ + + + +
+ + +
uInt32 elfPltInfo::pltInfo +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 elfPltInfo::pltOffset +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structelf_programheader.html b/doc/doxygen/html/structelf_programheader.html new file mode 100644 index 0000000..0485c5c --- /dev/null +++ b/doc/doxygen/html/structelf_programheader.html @@ -0,0 +1,213 @@ + + +Ubixos: elfProgramheader struct Reference + + + +

elfProgramheader Struct Reference

#include <elf.h> +

+ + + + + + + + + + + + + + + + + + + +

Data Fields

uInt32 phType
uInt32 phOffset
uInt32 phVaddr
uInt32 phPaddr
uInt32 phFilesz
uInt32 phMemsz
uInt32 phFlags
uInt32 phAlign
+


Field Documentation

+

+ + + + +
+ + +
uInt32 elfProgramheader::phAlign +
+
+ + + + + +
+   + + +

+Alignment in memory and file.

+

+ + + + +
+ + +
uInt32 elfProgramheader::phFilesz +
+
+ + + + + +
+   + + +

+Size of contents in file.

+

+ + + + +
+ + +
uInt32 elfProgramheader::phFlags +
+
+ + + + + +
+   + + +

+Access permission flags.

+

+ + + + +
+ + +
uInt32 elfProgramheader::phMemsz +
+
+ + + + + +
+   + + +

+Size of contents in memory.

+

+ + + + +
+ + +
uInt32 elfProgramheader::phOffset +
+
+ + + + + +
+   + + +

+File offset of contents.

+

+ + + + +
+ + +
uInt32 elfProgramheader::phPaddr +
+
+ + + + + +
+   + + +

+Physical address (not used).

+

+ + + + +
+ + +
uInt32 elfProgramheader::phType +
+
+ + + + + +
+   + + +

+Entry type.

+

+ + + + +
+ + +
uInt32 elfProgramheader::phVaddr +
+
+ + + + + +
+   + + +

+Virtual address in memory image.

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structelf_sectionheader.html b/doc/doxygen/html/structelf_sectionheader.html new file mode 100644 index 0000000..1f679da --- /dev/null +++ b/doc/doxygen/html/structelf_sectionheader.html @@ -0,0 +1,261 @@ + + +Ubixos: elfSectionheader struct Reference + + + +

elfSectionheader Struct Reference

#include <elf.h> +

+ + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

uInt32 shName
uInt32 shType
uInt32 shFlags
uInt32 shAddr
uInt32 shOffset
uInt32 shSize
uInt32 shLink
uInt32 shInfo
uInt32 shAddralign
uInt32 shEntsize
+


Field Documentation

+

+ + + + +
+ + +
uInt32 elfSectionheader::shAddr +
+
+ + + + + +
+   + + +

+Address in memory image.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shAddralign +
+
+ + + + + +
+   + + +

+Alignment in bytes.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shEntsize +
+
+ + + + + +
+   + + +

+Size of each entry in section.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shFlags +
+
+ + + + + +
+   + + +

+Section flags.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shInfo +
+
+ + + + + +
+   + + +

+Depends on section type.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shLink +
+
+ + + + + +
+   + + +

+Index of a related section.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shName +
+
+ + + + + +
+   + + +

+Section name (index into the section header string table).

+

+ + + + +
+ + +
uInt32 elfSectionheader::shOffset +
+
+ + + + + +
+   + + +

+Offset in file.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shSize +
+
+ + + + + +
+   + + +

+Size in bytes.

+

+ + + + +
+ + +
uInt32 elfSectionheader::shType +
+
+ + + + + +
+   + + +

+Section type.

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structeth__addr.html b/doc/doxygen/html/structeth__addr.html new file mode 100644 index 0000000..f653cf0 --- /dev/null +++ b/doc/doxygen/html/structeth__addr.html @@ -0,0 +1,52 @@ + + +Ubixos: eth_addr struct Reference + + + +

eth_addr Struct Reference

#include <arp.h> +

+ + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt8 addr[6])
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
eth_addr::PACK_STRUCT_FIELD uInt8  addr[6]  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structeth__hdr.html b/doc/doxygen/html/structeth__hdr.html new file mode 100644 index 0000000..5bfdedb --- /dev/null +++ b/doc/doxygen/html/structeth__hdr.html @@ -0,0 +1,114 @@ + + +Ubixos: eth_hdr struct Reference + + + +

eth_hdr Struct Reference

#include <arp.h> +

+ + + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (struct eth_addr dest)
 PACK_STRUCT_FIELD (struct eth_addr src)
 PACK_STRUCT_FIELD (uInt16 type)
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
eth_hdr::PACK_STRUCT_FIELD uInt16  type  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
eth_hdr::PACK_STRUCT_FIELD struct eth_addr  src  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
eth_hdr::PACK_STRUCT_FIELD struct eth_addr  dest  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structfile_descriptor_struct.html b/doc/doxygen/html/structfile_descriptor_struct.html new file mode 100644 index 0000000..808d8bc --- /dev/null +++ b/doc/doxygen/html/structfile_descriptor_struct.html @@ -0,0 +1,333 @@ + + +Ubixos: fileDescriptorStruct struct Reference + + + +

fileDescriptorStruct Struct Reference

#include <vfs.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

fileDescriptorStructprev
fileDescriptorStructnext
mountPointsmp
uInt16 status
uInt16 mode
uInt32 offset
uInt32 size
uInt16 length
uInt32 start
uInt8 fileName [22]
char * buffer
uInt32 dirBlock
uInt32 perms
+


Field Documentation

+

+ + + + +
+ + +
char* fileDescriptorStruct::buffer +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 fileDescriptorStruct::dirBlock +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 fileDescriptorStruct::fileName[22] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 fileDescriptorStruct::length +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 fileDescriptorStruct::mode +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct mountPoints* fileDescriptorStruct::mp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct fileDescriptorStruct* fileDescriptorStruct::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 fileDescriptorStruct::offset +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 fileDescriptorStruct::perms +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct fileDescriptorStruct* fileDescriptorStruct::prev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 fileDescriptorStruct::size +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 fileDescriptorStruct::start +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 fileDescriptorStruct::status +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structfile_system.html b/doc/doxygen/html/structfile_system.html new file mode 100644 index 0000000..2b48f1c --- /dev/null +++ b/doc/doxygen/html/structfile_system.html @@ -0,0 +1,285 @@ + + +Ubixos: fileSystem struct Reference + + + +

fileSystem Struct Reference

#include <vfs.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

fileSystemprev
fileSystemnext
int(* vfsInitFS )(void *)
int(* vfsRead )(void *, char *, long, long)
int(* vfsWrite )(void *, char *, long, long)
int(* vfsOpenFile )(void *, void *)
int(* vfsUnlink )(char *, void *)
int(* vfsMakeDir )(char *, void *)
int(* vfsRemDir )(char *)
int(* vfsSync )(void)
int vfsType
+


Field Documentation

+

+ + + + +
+ + +
struct fileSystem* fileSystem::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct fileSystem* fileSystem::prev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsInitFS)(void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsMakeDir)(char *,void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsOpenFile)(void *,void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsRead)(void *,char *,long,long) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsRemDir)(char *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsSync)(void) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int fileSystem::vfsType +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsUnlink)(char *,void *) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int(* fileSystem::vfsWrite)(void *,char *,long,long) +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structgdt_descriptor.html b/doc/doxygen/html/structgdt_descriptor.html new file mode 100644 index 0000000..d3d6437 --- /dev/null +++ b/doc/doxygen/html/structgdt_descriptor.html @@ -0,0 +1,189 @@ + + +Ubixos: gdtDescriptor struct Reference + + + +

gdtDescriptor Struct Reference

#include <gdt.h> +

+ + + + + + + + + + + + + + + + + +

Data Fields

unsigned short limitLow
unsigned short baseLow
unsigned char baseMed
unsigned char access
unsigned int limitHigh:4
unsigned int granularity:4
unsigned char baseHigh
+


Field Documentation

+

+ + + + +
+ + +
unsigned char gdtDescriptor::access +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned char gdtDescriptor::baseHigh +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned short gdtDescriptor::baseLow +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned char gdtDescriptor::baseMed +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned int gdtDescriptor::granularity +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned int gdtDescriptor::limitHigh +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned short gdtDescriptor::limitLow +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structgdt_gate.html b/doc/doxygen/html/structgdt_gate.html new file mode 100644 index 0000000..3d2a546 --- /dev/null +++ b/doc/doxygen/html/structgdt_gate.html @@ -0,0 +1,117 @@ + + +Ubixos: gdtGate struct Reference + + + +

gdtGate Struct Reference

#include <gdt.h> +

+ + + + + + + + + + + +

Data Fields

unsigned short offsetLow
unsigned short selector
unsigned short access
unsigned short offsetHigh
+


Field Documentation

+

+ + + + +
+ + +
unsigned short gdtGate::access +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned short gdtGate::offsetHigh +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned short gdtGate::offsetLow +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned short gdtGate::selector +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structhost_ring_entry.html b/doc/doxygen/html/structhost_ring_entry.html new file mode 100644 index 0000000..e0360bb --- /dev/null +++ b/doc/doxygen/html/structhost_ring_entry.html @@ -0,0 +1,95 @@ + + +Ubixos: hostRingEntry struct Reference + + + +

hostRingEntry Struct Reference

#include <lnc.h> +

+ + + + + + + + + + + +

Data Fields

mdsmd
union {
   char *   data
buff
+


Field Documentation

+

+ + + + +
+ + +
union { ... } hostRingEntry::buff +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char* hostRingEntry::data +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct mds* hostRingEntry::md +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structi387_struct.html b/doc/doxygen/html/structi387_struct.html new file mode 100644 index 0000000..b43a3f7 --- /dev/null +++ b/doc/doxygen/html/structi387_struct.html @@ -0,0 +1,213 @@ + + +Ubixos: i387Struct struct Reference + + + +

i387Struct Struct Reference

#include <tss.h> +

+ + + + + + + + + + + + + + + + + + + +

Data Fields

long cwd
long swd
long twd
long fip
long fcs
long foo
long fos
long st_space [20]
+


Field Documentation

+

+ + + + +
+ + +
long i387Struct::cwd +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long i387Struct::fcs +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long i387Struct::fip +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long i387Struct::foo +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long i387Struct::fos +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long i387Struct::st_space[20] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long i387Struct::swd +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long i387Struct::twd +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structicmp__dur__hdr.html b/doc/doxygen/html/structicmp__dur__hdr.html new file mode 100644 index 0000000..54318d8 --- /dev/null +++ b/doc/doxygen/html/structicmp__dur__hdr.html @@ -0,0 +1,212 @@ + + +Ubixos: icmp_dur_hdr struct Reference + + + +

icmp_dur_hdr Struct Reference

#include <icmp.h> +

+ + + + + + + + + + + + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt16 _type_code)
 PACK_STRUCT_FIELD (uInt16 chksum)
 PACK_STRUCT_FIELD (uInt32 unused)

Data Fields

u8_t type
u8_t icode
u16_t chksum
u32_t unused
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
icmp_dur_hdr::PACK_STRUCT_FIELD uInt32  unused  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
icmp_dur_hdr::PACK_STRUCT_FIELD uInt16  chksum  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
icmp_dur_hdr::PACK_STRUCT_FIELD uInt16  _type_code  ) 
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
u16_t icmp_dur_hdr::chksum +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t icmp_dur_hdr::icode +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t icmp_dur_hdr::type +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u32_t icmp_dur_hdr::unused +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following files: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structicmp__echo__hdr.html b/doc/doxygen/html/structicmp__echo__hdr.html new file mode 100644 index 0000000..7c9b9e4 --- /dev/null +++ b/doc/doxygen/html/structicmp__echo__hdr.html @@ -0,0 +1,267 @@ + + +Ubixos: icmp_echo_hdr struct Reference + + + +

icmp_echo_hdr Struct Reference

#include <icmp.h> +

+ + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt16 _type_code)
 PACK_STRUCT_FIELD (uInt16 chksum)
 PACK_STRUCT_FIELD (uInt16 id)
 PACK_STRUCT_FIELD (uInt16 seqno)

Data Fields

u8_t type
u8_t icode
u16_t chksum
u16_t id
u16_t seqno
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
icmp_echo_hdr::PACK_STRUCT_FIELD uInt16  seqno  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
icmp_echo_hdr::PACK_STRUCT_FIELD uInt16  id  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
icmp_echo_hdr::PACK_STRUCT_FIELD uInt16  chksum  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
icmp_echo_hdr::PACK_STRUCT_FIELD uInt16  _type_code  ) 
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
u16_t icmp_echo_hdr::chksum +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t icmp_echo_hdr::icode +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u16_t icmp_echo_hdr::id +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u16_t icmp_echo_hdr::seqno +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t icmp_echo_hdr::type +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following files: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structicmp__te__hdr.html b/doc/doxygen/html/structicmp__te__hdr.html new file mode 100644 index 0000000..173439c --- /dev/null +++ b/doc/doxygen/html/structicmp__te__hdr.html @@ -0,0 +1,212 @@ + + +Ubixos: icmp_te_hdr struct Reference + + + +

icmp_te_hdr Struct Reference

#include <icmp.h> +

+ + + + + + + + + + + + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt16 _type_code)
 PACK_STRUCT_FIELD (uInt16 chksum)
 PACK_STRUCT_FIELD (uInt32 unused)

Data Fields

u8_t type
u8_t icode
u16_t chksum
u32_t unused
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
icmp_te_hdr::PACK_STRUCT_FIELD uInt32  unused  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
icmp_te_hdr::PACK_STRUCT_FIELD uInt16  chksum  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
icmp_te_hdr::PACK_STRUCT_FIELD uInt16  _type_code  ) 
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
u16_t icmp_te_hdr::chksum +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t icmp_te_hdr::icode +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t icmp_te_hdr::type +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u32_t icmp_te_hdr::unused +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following files: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structin__addr.html b/doc/doxygen/html/structin__addr.html new file mode 100644 index 0000000..66516ad --- /dev/null +++ b/doc/doxygen/html/structin__addr.html @@ -0,0 +1,45 @@ + + +Ubixos: in_addr struct Reference + + + +

in_addr Struct Reference

#include <sockets.h> +

+ + + + + +

Data Fields

uInt32 s_addr
+


Field Documentation

+

+ + + + +
+ + +
uInt32 in_addr::s_addr +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structinit_block.html b/doc/doxygen/html/structinit_block.html new file mode 100644 index 0000000..5e9f933 --- /dev/null +++ b/doc/doxygen/html/structinit_block.html @@ -0,0 +1,189 @@ + + +Ubixos: initBlock struct Reference + + + +

initBlock Struct Reference

#include <lnc.h> +

+ + + + + + + + + + + + + + + + + +

Data Fields

uInt16 mode
uInt8 padr [6]
uInt8 ladrf [8]
uInt16 rdra
uInt16 rlen
uInt16 tdra
uInt16 tlen
+


Field Documentation

+

+ + + + +
+ + +
uInt8 initBlock::ladrf[8] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 initBlock::mode +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 initBlock::padr[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 initBlock::rdra +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 initBlock::rlen +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 initBlock::tdra +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 initBlock::tlen +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structip__addr.html b/doc/doxygen/html/structip__addr.html new file mode 100644 index 0000000..3ad41ec --- /dev/null +++ b/doc/doxygen/html/structip__addr.html @@ -0,0 +1,78 @@ + + +Ubixos: ip_addr struct Reference + + + +

ip_addr Struct Reference

#include <ip_addr.h> +

+ + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt32 addr)

Data Fields

u32_t addr [4]
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
ip_addr::PACK_STRUCT_FIELD uInt32  addr  ) 
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
u32_t ip_addr::addr[4] +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following files: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structip__hdr.html b/doc/doxygen/html/structip__hdr.html new file mode 100644 index 0000000..a80e1ed --- /dev/null +++ b/doc/doxygen/html/structip__hdr.html @@ -0,0 +1,487 @@ + + +Ubixos: ip_hdr struct Reference + + + +

ip_hdr Struct Reference

#include <ip.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt16 _v_hl_tos)
 PACK_STRUCT_FIELD (uInt16 _len)
 PACK_STRUCT_FIELD (uInt16 _id)
 PACK_STRUCT_FIELD (uInt16 _offset)
 PACK_STRUCT_FIELD (uInt16 _ttl_proto)
 PACK_STRUCT_FIELD (uInt16 _chksum)
 PACK_STRUCT_FIELD (struct ip_addr src)
 PACK_STRUCT_FIELD (struct ip_addr dest)

Data Fields

u8_t tclass1:4
u8_t v:4
u8_t flow1:4
u8_t tclass2:4
u16_t flow2
u16_t len
u8_t nexthdr
u8_t hoplim
ip_addr src dest
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD struct ip_addr  dest  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD struct ip_addr  src  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD uInt16  _chksum  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD uInt16  _ttl_proto  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD uInt16  _offset  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD uInt16  _id  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD uInt16  _len  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
ip_hdr::PACK_STRUCT_FIELD uInt16  _v_hl_tos  ) 
+
+ + + + + +
+   + + +

+

+


Field Documentation

+

+ + + + +
+ + +
struct ip_addr src ip_hdr::dest +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t ip_hdr::flow1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u16_t ip_hdr::flow2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t ip_hdr::hoplim +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u16_t ip_hdr::len +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t ip_hdr::nexthdr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t ip_hdr::tclass1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t ip_hdr::tclass2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
u8_t ip_hdr::v +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following files: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structlnc_info.html b/doc/doxygen/html/structlnc_info.html new file mode 100644 index 0000000..5934ff3 --- /dev/null +++ b/doc/doxygen/html/structlnc_info.html @@ -0,0 +1,261 @@ + + +Ubixos: lncInfo struct Reference + + + +

lncInfo Struct Reference

#include <lnc.h> +

+ + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

arpcom arpcom
nicInfo nic
hostRingEntryrecvRing
hostRingEntrytransRings
initBlockinitBloack
int rap
int rdp
int bdp
int nrdre
int ntdre
+


Field Documentation

+

+ + + + +
+ + +
struct arpcom lncInfo::arpcom +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int lncInfo::bdp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct initBlock* lncInfo::initBloack +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct nicInfo lncInfo::nic +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int lncInfo::nrdre +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int lncInfo::ntdre +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int lncInfo::rap +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int lncInfo::rdp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct hostRingEntry* lncInfo::recvRing +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct hostRingEntry* lncInfo::transRings +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structm_map.html b/doc/doxygen/html/structm_map.html new file mode 100644 index 0000000..7f65df3 --- /dev/null +++ b/doc/doxygen/html/structm_map.html @@ -0,0 +1,117 @@ + + +Ubixos: mMap struct Reference + + + +

mMap Struct Reference

#include <vmm.h> +

+ + + + + + + + + + + +

Data Fields

uInt32 pageAddr
uInt16 status
pid_t pid
int cowCounter
+


Field Documentation

+

+ + + + +
+ + +
int mMap::cowCounter +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 mMap::pageAddr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
pid_t mMap::pid +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 mMap::status +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structmds.html b/doc/doxygen/html/structmds.html new file mode 100644 index 0000000..4eb896e --- /dev/null +++ b/doc/doxygen/html/structmds.html @@ -0,0 +1,117 @@ + + +Ubixos: mds struct Reference + + + +

mds Struct Reference

#include <lnc.h> +

+ + + + + + + + + + + +

Data Fields

uInt16 md0
uInt16 md1
short md2
uInt16 md3
+


Field Documentation

+

+ + + + +
+ + +
uInt16 mds::md0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 mds::md1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short mds::md2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 mds::md3 +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structmem_descriptor.html b/doc/doxygen/html/structmem_descriptor.html new file mode 100644 index 0000000..3f3c812 --- /dev/null +++ b/doc/doxygen/html/structmem_descriptor.html @@ -0,0 +1,189 @@ + + +Ubixos: memDescriptor struct Reference + + + +

memDescriptor Struct Reference

#include <kmalloc.h> +

+ + + + + + + + + + + + + + + + + +

Data Fields

memDescriptorprev
memDescriptornext
void * baseAddr
uInt32 limit
uInt8 status
pidType pid
char reserved [11]
+


Field Documentation

+

+ + + + +
+ + +
void* memDescriptor::baseAddr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 memDescriptor::limit +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct memDescriptor* memDescriptor::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
pidType memDescriptor::pid +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct memDescriptor* memDescriptor::prev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char memDescriptor::reserved[11] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 memDescriptor::status +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structmount_points.html b/doc/doxygen/html/structmount_points.html new file mode 100644 index 0000000..6a5125d --- /dev/null +++ b/doc/doxygen/html/structmount_points.html @@ -0,0 +1,237 @@ + + +Ubixos: mountPoints struct Reference + + + +

mountPoints Struct Reference

#include <mount.h> +

+ + + + + + + + + + + + + + + + + + + + + +

Data Fields

mountPointsprev
mountPointsnext
fileSystemfs
deviceNodedevice
ubixDiskLabeldiskLabel
void * fsInfo
int partition
char mountPoint [1024]
char perms
+


Field Documentation

+

+ + + + +
+ + +
struct deviceNode* mountPoints::device +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ubixDiskLabel* mountPoints::diskLabel +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct fileSystem* mountPoints::fs +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* mountPoints::fsInfo +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char mountPoints::mountPoint[1024] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct mountPoints* mountPoints::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int mountPoints::partition +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char mountPoints::perms +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct mountPoints* mountPoints::prev +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structnet.html b/doc/doxygen/html/structnet.html new file mode 100644 index 0000000..175a091 --- /dev/null +++ b/doc/doxygen/html/structnet.html @@ -0,0 +1,69 @@ + + +Ubixos: net struct Reference + + + +

net Struct Reference

#include <device.old.h> +

+ + + + + + + +

Data Fields

char mac [6]
char broadcast [6]
+


Field Documentation

+

+ + + + +
+ + +
char net::broadcast[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char net::mac[6] +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structnetbuf.html b/doc/doxygen/html/structnetbuf.html new file mode 100644 index 0000000..15aab1e --- /dev/null +++ b/doc/doxygen/html/structnetbuf.html @@ -0,0 +1,141 @@ + + +Ubixos: netbuf struct Reference + + + +

netbuf Struct Reference

#include <api.h> +

+ + + + + + + + + + + + + +

Data Fields

pbufp
pbufptr
ip_addrfromaddr
uInt16 fromport
err_t err
+


Field Documentation

+

+ + + + +
+ + +
err_t netbuf::err +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr* netbuf::fromaddr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 netbuf::fromport +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct pbuf* netbuf::p +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct pbuf * netbuf::ptr +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structnetconn.html b/doc/doxygen/html/structnetconn.html new file mode 100644 index 0000000..e713a10 --- /dev/null +++ b/doc/doxygen/html/structnetconn.html @@ -0,0 +1,263 @@ + + +Ubixos: netconn struct Reference + + + +

netconn Struct Reference

#include <api.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

enum netconn_type type
enum netconn_state state
union {
   tcp_pcb *   tcp
   udp_pcb *   udp
pcb
err_t err
sys_mbox_t mbox
sys_mbox_t recvmbox
sys_mbox_t acceptmbox
sys_sem_t sem
+


Field Documentation

+

+ + + + +
+ + +
sys_mbox_t netconn::acceptmbox +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t netconn::err +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
sys_mbox_t netconn::mbox +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
union { ... } netconn::pcb +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
sys_mbox_t netconn::recvmbox +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
sys_sem_t netconn::sem +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
enum netconn_state netconn::state +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_pcb* netconn::tcp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
enum netconn_type netconn::type +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct udp_pcb* netconn::udp +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structnetif.html b/doc/doxygen/html/structnetif.html new file mode 100644 index 0000000..8c4f1d2 --- /dev/null +++ b/doc/doxygen/html/structnetif.html @@ -0,0 +1,285 @@ + + +Ubixos: netif struct Reference + + + +

netif Struct Reference

#include <netif.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

netifnext
uInt8 num
ip_addr ip_addr
ip_addr netmask
ip_addr gw
char hwaddr [6]
err_t(* input )(struct pbuf *p, struct netif *inp)
char name [2]
err_t(* output )(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr)
err_t(* linkoutput )(struct netif *netif, struct pbuf *p)
void * state
+


Field Documentation

+

+ + + + +
+ + +
struct ip_addr netif::gw +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char netif::hwaddr[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t(* netif::input)(struct pbuf *p, struct netif *inp) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr netif::ip_addr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t(* netif::linkoutput)(struct netif *netif, struct pbuf *p) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char netif::name[2] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr netif::netmask +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct netif* netif::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 netif::num +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t(* netif::output)(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* netif::state +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structnic_buffer.html b/doc/doxygen/html/structnic_buffer.html new file mode 100644 index 0000000..ef48e8d --- /dev/null +++ b/doc/doxygen/html/structnic_buffer.html @@ -0,0 +1,93 @@ + + +Ubixos: nicBuffer struct Reference + + + +

nicBuffer Struct Reference

#include <ne2k.h> +

+ + + + + + + + + +

Data Fields

nicBuffernext
int length
char * buffer
+


Field Documentation

+

+ + + + +
+ + +
char* nicBuffer::buffer +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int nicBuffer::length +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct nicBuffer* nicBuffer::next +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structnic_info.html b/doc/doxygen/html/structnic_info.html new file mode 100644 index 0000000..2c800c8 --- /dev/null +++ b/doc/doxygen/html/structnic_info.html @@ -0,0 +1,141 @@ + + +Ubixos: nicInfo struct Reference + + + +

nicInfo Struct Reference

#include <lnc.h> +

+ + + + + + + + + + + + + +

Data Fields

int ident
int ic
int memMode
int iobase
int mode
+


Field Documentation

+

+ + + + +
+ + +
int nicInfo::ic +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int nicInfo::ident +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int nicInfo::iobase +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int nicInfo::memMode +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int nicInfo::mode +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structog_mode_info.html b/doc/doxygen/html/structog_mode_info.html new file mode 100644 index 0000000..71f44ad --- /dev/null +++ b/doc/doxygen/html/structog_mode_info.html @@ -0,0 +1,1044 @@ + + +Ubixos: ogModeInfo struct Reference + + + +

ogModeInfo Struct Reference

#include <ogDisplay_UbixOS.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

uInt16 modeAttributes __attribute__ ((packed))
uInt8 windowAFlags __attribute__ ((packed))
uInt8 windowBFlags __attribute__ ((packed))
uInt16 granularity __attribute__ ((packed))
uInt16 windowSize __attribute__ ((packed))
uInt16 windowASeg __attribute__ ((packed))
uInt16 windowBSeg __attribute__ ((packed))
void *bankSwitch __attribute__ ((packed))
uInt16 bytesPerLine __attribute__ ((packed))
uInt16 xRes __attribute__ ((packed))
uInt16 yRes __attribute__ ((packed))
uInt8 charWidth __attribute__ ((packed))
uInt8 charHeight __attribute__ ((packed))
uInt8 numBitPlanes __attribute__ ((packed))
uInt8 bitsPerPixel __attribute__ ((packed))
uInt8 numberOfBanks __attribute__ ((packed))
uInt8 memoryModel __attribute__ ((packed))
uInt8 bankSize __attribute__ ((packed))
uInt8 numOfImagePages __attribute__ ((packed))
uInt8 reserved __attribute__ ((packed))
uInt8 redMaskSize __attribute__ ((packed))
uInt8 redFieldPosition __attribute__ ((packed))
uInt8 greenMaskSize __attribute__ ((packed))
uInt8 greenFieldPosition __attribute__ ((packed))
uInt8 blueMaskSize __attribute__ ((packed))
uInt8 blueFieldPosition __attribute__ ((packed))
uInt8 alphaMaskSize __attribute__ ((packed))
uInt8 alphaFieldPosition __attribute__ ((packed))
uInt8 directColourMode __attribute__ ((packed))
uInt32 physBasePtr __attribute__ ((packed))
void *offScreenMemOffset __attribute__ ((packed))
uInt16 offScreenMemSize __attribute__ ((packed))
uInt8 paddington[461] __attribute__ ((packed))
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
uInt8 paddington [461] ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 offScreenMemSize ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* offScreenMemOffset ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 physBasePtr ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 directColourMode ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 alphaFieldPosition ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 alphaMaskSize ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 blueFieldPosition ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 blueMaskSize ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 greenFieldPosition ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 greenMaskSize ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 redFieldPosition ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 redMaskSize ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 reserved ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 numOfImagePages ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 bankSize ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 memoryModel ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 numberOfBanks ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 bitsPerPixel ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 numBitPlanes ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 charHeight ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 charWidth ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 yRes ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 xRes ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 bytesPerLine ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void* bankSwitch ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 windowBSeg ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 windowASeg ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 windowSize ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 granularity ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 windowBFlags ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 windowAFlags ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 modeAttributes ogModeInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structog_v_e_s_a_info.html b/doc/doxygen/html/structog_v_e_s_a_info.html new file mode 100644 index 0000000..82ce818 --- /dev/null +++ b/doc/doxygen/html/structog_v_e_s_a_info.html @@ -0,0 +1,393 @@ + + +Ubixos: ogVESAInfo struct Reference + + + +

ogVESAInfo Struct Reference

#include <ogDisplay_UbixOS.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

char VBESignature[4] __attribute__ ((packed))
uInt8 minVersion __attribute__ ((packed))
uInt8 majVersion __attribute__ ((packed))
uInt32 OEMStringPtr __attribute__ ((packed))
uInt32 capabilities __attribute__ ((packed))
uInt32 videoModePtr __attribute__ ((packed))
uInt16 totalMemory __attribute__ ((packed))
uInt16 OEMSoftwareRev __attribute__ ((packed))
uInt32 OEMVendorNamePtr __attribute__ ((packed))
uInt32 OEMProductNamePtr __attribute__ ((packed))
uInt32 OEMProductRevPtr __attribute__ ((packed))
uInt8 paddington[474] __attribute__ ((packed))
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
uInt8 paddington [474] ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMProductRevPtr ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMProductNamePtr ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMVendorNamePtr ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 OEMSoftwareRev ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt16 totalMemory ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 videoModePtr ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 capabilities ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 OEMStringPtr ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 majVersion ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 minVersion ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
char VBESignature [4] ogVESAInfo::__attribute__ (packed  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structos_info.html b/doc/doxygen/html/structos_info.html new file mode 100644 index 0000000..4db1db1 --- /dev/null +++ b/doc/doxygen/html/structos_info.html @@ -0,0 +1,405 @@ + + +Ubixos: osInfo struct Reference + + + +

osInfo Struct Reference

#include <sched.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

mountPointscontainer
elfSectionheadersectionHeader
taskFileInfo fileInfo
consoleStruct * terminal
uInt16 sectionCount
uInt16 stringSection
uInt8 timer
uInt8 v86Task
bool v86If
uInt32 curDir
uInt32 vmStart
uInt32 stdinSize
uInt32 controlKeys
char * stdin
char * shstrtab
char * cwd
+


Field Documentation

+

+ + + + +
+ + +
struct mountPoints* osInfo::container +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 osInfo::controlKeys +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 osInfo::curDir +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char* osInfo::cwd +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct taskFileInfo osInfo::fileInfo +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 osInfo::sectionCount +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
elfSectionheader* osInfo::sectionHeader +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char* osInfo::shstrtab +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char* osInfo::stdin +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 osInfo::stdinSize +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 osInfo::stringSection +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct consoleStruct* osInfo::terminal +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 osInfo::timer +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
bool osInfo::v86If +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 osInfo::v86Task +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 osInfo::vmStart +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structpartition_information.html b/doc/doxygen/html/structpartition_information.html new file mode 100644 index 0000000..2b35899 --- /dev/null +++ b/doc/doxygen/html/structpartition_information.html @@ -0,0 +1,117 @@ + + +Ubixos: partitionInformation struct Reference + + + +

partitionInformation Struct Reference

#include <ubixfs.h> +

+ + + + + + + + + + + +

Data Fields

uInt32 size
uInt32 startSector
uInt32 blockAllocationTable
uInt32 rootDirectory
+


Field Documentation

+

+ + + + +
+ + +
uInt32 partitionInformation::blockAllocationTable +
+
+ + + + + +
+   + + +

+Base Sector Of BAT

+

+ + + + +
+ + +
uInt32 partitionInformation::rootDirectory +
+
+ + + + + +
+   + + +

+Base Sector Of Root Directory

+

+ + + + +
+ + +
uInt32 partitionInformation::size +
+
+ + + + + +
+   + + +

+Size In Sectors

+

+ + + + +
+ + +
uInt32 partitionInformation::startSector +
+
+ + + + + +
+   + + +

+Base Sector Of Partition

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structpbuf.html b/doc/doxygen/html/structpbuf.html new file mode 100644 index 0000000..79a5668 --- /dev/null +++ b/doc/doxygen/html/structpbuf.html @@ -0,0 +1,165 @@ + + +Ubixos: pbuf struct Reference + + + +

pbuf Struct Reference

#include <pbuf.h> +

+ + + + + + + + + + + + + + + +

Data Fields

pbufnext
uInt8 flags
uInt8 ref
void * payload
uInt16 tot_len
uInt16 len
+


Field Documentation

+

+ + + + +
+ + +
uInt8 pbuf::flags +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pbuf::len +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct pbuf* pbuf::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* pbuf::payload +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pbuf::ref +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pbuf::tot_len +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structpci_config.html b/doc/doxygen/html/structpci_config.html new file mode 100644 index 0000000..c181701 --- /dev/null +++ b/doc/doxygen/html/structpci_config.html @@ -0,0 +1,501 @@ + + +Ubixos: pciConfig struct Reference + + + +

pciConfig Struct Reference

#include <pci.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

uInt16 vendorId
uInt16 deviceId
uInt16 command
uInt16 status
uInt8 revisionId
uInt8 interface
uInt8 subClass
uInt8 baseClass
uInt8 cacheLineSize
uInt8 latencyTimer
uInt8 headerType
uInt8 bist
uInt8 bus
uInt8 dev
uInt8 func
uInt8 irq
uInt32 base [6]
uInt32 size [6]
uInt16 subsysVendor
uInt16 subsys
+


Field Documentation

+

+ + + + +
+ + +
uInt32 pciConfig::base[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::baseClass +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::bist +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::bus +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::cacheLineSize +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pciConfig::command +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::dev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pciConfig::deviceId +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::func +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::headerType +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::interface +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::irq +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::latencyTimer +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::revisionId +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 pciConfig::size[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pciConfig::status +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 pciConfig::subClass +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pciConfig::subsys +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pciConfig::subsysVendor +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 pciConfig::vendorId +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structsde_windows.html b/doc/doxygen/html/structsde_windows.html new file mode 100644 index 0000000..127003e --- /dev/null +++ b/doc/doxygen/html/structsde_windows.html @@ -0,0 +1,141 @@ + + +Ubixos: sdeWindows struct Reference + + + +

sdeWindows Struct Reference

#include <sde.h> +

+ + + + + + + + + + + + + +

Data Fields

sdeWindowsnext
sdeWindowsprev
void * buf
pidType pid
uInt8 status
+


Field Documentation

+

+ + + + +
+ + +
void* sdeWindows::buf +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct sdeWindows* sdeWindows::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
pidType sdeWindows::pid +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct sdeWindows* sdeWindows::prev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 sdeWindows::status +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structsockaddr.html b/doc/doxygen/html/structsockaddr.html new file mode 100644 index 0000000..26a8191 --- /dev/null +++ b/doc/doxygen/html/structsockaddr.html @@ -0,0 +1,93 @@ + + +Ubixos: sockaddr struct Reference + + + +

sockaddr Struct Reference

#include <sockets.h> +

+ + + + + + + + + +

Data Fields

uInt8 sa_len
uInt8 sa_family
char sa_data [14]
+


Field Documentation

+

+ + + + +
+ + +
char sockaddr::sa_data[14] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 sockaddr::sa_family +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 sockaddr::sa_len +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structsockaddr__in.html b/doc/doxygen/html/structsockaddr__in.html new file mode 100644 index 0000000..58961f0 --- /dev/null +++ b/doc/doxygen/html/structsockaddr__in.html @@ -0,0 +1,141 @@ + + +Ubixos: sockaddr_in struct Reference + + + +

sockaddr_in Struct Reference

#include <sockets.h> +

+ + + + + + + + + + + + + +

Data Fields

uInt8 sin_len
uInt8 sin_family
uInt16 sin_port
in_addr sin_addr
char sin_zero [8]
+


Field Documentation

+

+ + + + +
+ + +
struct in_addr sockaddr_in::sin_addr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 sockaddr_in::sin_family +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 sockaddr_in::sin_len +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 sockaddr_in::sin_port +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char sockaddr_in::sin_zero[8] +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structsys__timeout.html b/doc/doxygen/html/structsys__timeout.html new file mode 100644 index 0000000..fe7549f --- /dev/null +++ b/doc/doxygen/html/structsys__timeout.html @@ -0,0 +1,117 @@ + + +Ubixos: sys_timeout struct Reference + + + +

sys_timeout Struct Reference

#include <sys.h> +

+ + + + + + + + + + + +

Data Fields

sys_timeoutnext
uInt16 time
sys_timeout_handler h
void * arg
+


Field Documentation

+

+ + + + +
+ + +
void* sys_timeout::arg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
sys_timeout_handler sys_timeout::h +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct sys_timeout* sys_timeout::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 sys_timeout::time +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structsys__timeouts.html b/doc/doxygen/html/structsys__timeouts.html new file mode 100644 index 0000000..fcb5802 --- /dev/null +++ b/doc/doxygen/html/structsys__timeouts.html @@ -0,0 +1,45 @@ + + +Ubixos: sys_timeouts struct Reference + + + +

sys_timeouts Struct Reference

#include <sys.h> +

+ + + + + +

Data Fields

sys_timeoutnext
+


Field Documentation

+

+ + + + +
+ + +
struct sys_timeout* sys_timeouts::next +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtask_file_info.html b/doc/doxygen/html/structtask_file_info.html new file mode 100644 index 0000000..6dc1940 --- /dev/null +++ b/doc/doxygen/html/structtask_file_info.html @@ -0,0 +1,45 @@ + + +Ubixos: taskFileInfo struct Reference + + + +

taskFileInfo Struct Reference

#include <file.h> +

+ + + + + +

Data Fields

char * cwd
+


Field Documentation

+

+ + + + +
+ + +
char* taskFileInfo::cwd +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtask_struct.html b/doc/doxygen/html/structtask_struct.html new file mode 100644 index 0000000..3d8838a --- /dev/null +++ b/doc/doxygen/html/structtask_struct.html @@ -0,0 +1,264 @@ + + +Ubixos: taskStruct struct Reference + + + +

taskStruct Struct Reference

#include <sched.h> +

+ + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

pidType id
taskStructprev
taskStructnext
tssStruct tss
i387Struct i387
osInfo oInfo
tState state
uInt32 gid
uInt32 uid
uInt16 usedMath
+


Detailed Description

+Structure containing information about a class +

+


Field Documentation

+

+ + + + +
+ + +
uInt32 taskStruct::gid +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct i387Struct taskStruct::i387 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
pidType taskStruct::id +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct taskStruct* taskStruct::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct osInfo taskStruct::oInfo +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct taskStruct* taskStruct::prev +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
tState taskStruct::state +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tssStruct taskStruct::tss +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 taskStruct::uid +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 taskStruct::usedMath +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtcp__hdr.html b/doc/doxygen/html/structtcp__hdr.html new file mode 100644 index 0000000..346b9eb --- /dev/null +++ b/doc/doxygen/html/structtcp__hdr.html @@ -0,0 +1,269 @@ + + +Ubixos: tcp_hdr struct Reference + + + +

tcp_hdr Struct Reference

#include <tcp.h> +

+ + + + + + + + + + + + + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt16 src)
 PACK_STRUCT_FIELD (uInt16 dest)
 PACK_STRUCT_FIELD (uInt32 seqno)
 PACK_STRUCT_FIELD (uInt32 ackno)
 PACK_STRUCT_FIELD (uInt16 _offset_flags)
 PACK_STRUCT_FIELD (uInt16 wnd)
 PACK_STRUCT_FIELD (uInt16 chksum)
 PACK_STRUCT_FIELD (uInt16 urgp)
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt16  urgp  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt16  chksum  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt16  wnd  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt16  _offset_flags  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt32  ackno  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt32  seqno  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt16  dest  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
tcp_hdr::PACK_STRUCT_FIELD uInt16  src  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtcp__pcb.html b/doc/doxygen/html/structtcp__pcb.html new file mode 100644 index 0000000..da4544c --- /dev/null +++ b/doc/doxygen/html/structtcp__pcb.html @@ -0,0 +1,1053 @@ + + +Ubixos: tcp_pcb struct Reference + + + +

tcp_pcb Struct Reference

#include <tcp.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

tcp_pcbnext
enum tcp_state state
void * callback_arg
err_t(* accept )(void *arg, struct tcp_pcb *newpcb, err_t err)
ip_addr local_ip
uInt16 local_port
ip_addr remote_ip
uInt16 remote_port
uInt32 rcv_nxt
uInt16 rcv_wnd
uInt16 tmr
uInt8 rtime
uInt16 mss
uInt8 flags
uInt16 rttest
uInt32 rtseq
Int32 sa
Int32 sv
uInt16 rto
uInt8 nrtx
uInt32 lastack
uInt8 dupacks
uInt16 cwnd
uInt16 ssthresh
uInt32 snd_nxt
uInt32 snd_max
uInt32 snd_wnd
uInt32 snd_wl1
uInt32 snd_wl2
uInt32 snd_lbb
uInt16 snd_buf
uInt8 snd_queuelen
err_t(* sent )(void *arg, struct tcp_pcb *pcb, uInt16 space)
uInt16 acked
err_t(* recv )(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
pbufrecv_data
err_t(* connected )(void *arg, struct tcp_pcb *pcb, err_t err)
err_t(* poll )(void *arg, struct tcp_pcb *pcb)
void(* errf )(void *arg, err_t err)
uInt8 polltmr
uInt8 pollinterval
tcp_segunsent
tcp_segunacked
+


Field Documentation

+

+ + + + +
+ + +
err_t(* tcp_pcb::accept)(void *arg, struct tcp_pcb *newpcb, err_t err) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::acked +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* tcp_pcb::callback_arg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t(* tcp_pcb::connected)(void *arg, struct tcp_pcb *pcb, err_t err) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::cwnd +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 tcp_pcb::dupacks +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* tcp_pcb::errf)(void *arg, err_t err) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 tcp_pcb::flags +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::lastack +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr tcp_pcb::local_ip +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::local_port +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::mss +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_pcb* tcp_pcb::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 tcp_pcb::nrtx +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t(* tcp_pcb::poll)(void *arg, struct tcp_pcb *pcb) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 tcp_pcb::pollinterval +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 tcp_pcb::polltmr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::rcv_nxt +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::rcv_wnd +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t(* tcp_pcb::recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct pbuf* tcp_pcb::recv_data +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr tcp_pcb::remote_ip +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::remote_port +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 tcp_pcb::rtime +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::rto +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::rtseq +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::rttest +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
Int32 tcp_pcb::sa +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
err_t(* tcp_pcb::sent)(void *arg, struct tcp_pcb *pcb, uInt16 space) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::snd_buf +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::snd_lbb +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::snd_max +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::snd_nxt +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 tcp_pcb::snd_queuelen +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::snd_wl1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::snd_wl2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_pcb::snd_wnd +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::ssthresh +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
enum tcp_state tcp_pcb::state +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
Int32 tcp_pcb::sv +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb::tmr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_seg* tcp_pcb::unacked +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_seg* tcp_pcb::unsent +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtcp__pcb__listen.html b/doc/doxygen/html/structtcp__pcb__listen.html new file mode 100644 index 0000000..439cf90 --- /dev/null +++ b/doc/doxygen/html/structtcp__pcb__listen.html @@ -0,0 +1,165 @@ + + +Ubixos: tcp_pcb_listen struct Reference + + + +

tcp_pcb_listen Struct Reference

#include <tcp.h> +

+ + + + + + + + + + + + + + + +

Data Fields

tcp_pcb_listennext
enum tcp_state state
void * callback_arg
void(* accept )(void *arg, struct tcp_pcb *newpcb)
ip_addr local_ip
uInt16 local_port
+


Field Documentation

+

+ + + + +
+ + +
void(* tcp_pcb_listen::accept)(void *arg, struct tcp_pcb *newpcb) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* tcp_pcb_listen::callback_arg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr tcp_pcb_listen::local_ip +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_pcb_listen::local_port +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_pcb_listen* tcp_pcb_listen::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
enum tcp_state tcp_pcb_listen::state +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtcp__seg.html b/doc/doxygen/html/structtcp__seg.html new file mode 100644 index 0000000..897299c --- /dev/null +++ b/doc/doxygen/html/structtcp__seg.html @@ -0,0 +1,141 @@ + + +Ubixos: tcp_seg struct Reference + + + +

tcp_seg Struct Reference

#include <tcp.h> +

+ + + + + + + + + + + + + +

Data Fields

tcp_segnext
pbufp
void * dataptr
uInt16 len
tcp_hdrtcphdr
+


Field Documentation

+

+ + + + +
+ + +
void* tcp_seg::dataptr +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 tcp_seg::len +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_seg* tcp_seg::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct pbuf* tcp_seg::p +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_hdr* tcp_seg::tcphdr +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtcpip__msg.html b/doc/doxygen/html/structtcpip__msg.html new file mode 100644 index 0000000..6cc3c9f --- /dev/null +++ b/doc/doxygen/html/structtcpip__msg.html @@ -0,0 +1,193 @@ + + +Ubixos: tcpip_msg struct Reference + + + +

tcpip_msg Struct Reference

#include <tcpip.h> +

+ + + + + + + + + + + + + + + + + + + + + +

Data Fields

enum tcpip_msg_type type
sys_sem_tsem
union {
   api_msg *   apimsg
   struct {
      pbuf *   p
      netif *   netif
   }   inp
msg
+


Field Documentation

+

+ + + + +
+ + +
struct api_msg* tcpip_msg::apimsg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct { ... } tcpip_msg::inp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
union { ... } tcpip_msg::msg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct netif* tcpip_msg::netif +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct pbuf* tcpip_msg::p +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
sys_sem_t* tcpip_msg::sem +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
enum tcpip_msg_type tcpip_msg::type +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtime_struct.html b/doc/doxygen/html/structtime_struct.html new file mode 100644 index 0000000..eb49b1d --- /dev/null +++ b/doc/doxygen/html/structtime_struct.html @@ -0,0 +1,165 @@ + + +Ubixos: timeStruct struct Reference + + + +

timeStruct Struct Reference

#include <time.h> +

+ + + + + + + + + + + + + + + +

Data Fields

int sec
int min
int hour
int day
int mon
int year
+


Field Documentation

+

+ + + + +
+ + +
int timeStruct::day +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int timeStruct::hour +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int timeStruct::min +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int timeStruct::mon +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int timeStruct::sec +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int timeStruct::year +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtimespec.html b/doc/doxygen/html/structtimespec.html new file mode 100644 index 0000000..1e51783 --- /dev/null +++ b/doc/doxygen/html/structtimespec.html @@ -0,0 +1,69 @@ + + +Ubixos: timespec struct Reference + + + +

timespec Struct Reference

#include <time.h> +

+ + + + + + + +

Data Fields

time_t tv_sec
long tv_nsec
+


Field Documentation

+

+ + + + +
+ + +
long timespec::tv_nsec +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
time_t timespec::tv_sec +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:25 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtimeval.html b/doc/doxygen/html/structtimeval.html new file mode 100644 index 0000000..c22b123 --- /dev/null +++ b/doc/doxygen/html/structtimeval.html @@ -0,0 +1,69 @@ + + +Ubixos: timeval struct Reference + + + +

timeval Struct Reference

#include <time.h> +

+ + + + + + + +

Data Fields

long tv_sec
suseconds_t tv_usec
+


Field Documentation

+

+ + + + +
+ + +
long timeval::tv_sec +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
suseconds_t timeval::tv_usec +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtimezone.html b/doc/doxygen/html/structtimezone.html new file mode 100644 index 0000000..28e99d5 --- /dev/null +++ b/doc/doxygen/html/structtimezone.html @@ -0,0 +1,69 @@ + + +Ubixos: timezone struct Reference + + + +

timezone Struct Reference

#include <time.h> +

+ + + + + + + +

Data Fields

int tz_minuteswest
int tz_dsttime
+


Field Documentation

+

+ + + + +
+ + +
int timezone::tz_dsttime +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int timezone::tz_minuteswest +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtms.html b/doc/doxygen/html/structtms.html new file mode 100644 index 0000000..23bc364 --- /dev/null +++ b/doc/doxygen/html/structtms.html @@ -0,0 +1,117 @@ + + +Ubixos: tms struct Reference + + + +

tms Struct Reference

#include <times.h> +

+ + + + + + + + + + + +

Data Fields

clock_t tms_utime
clock_t tms_stime
clock_t tms_cutime
clock_t tms_cstime
+


Field Documentation

+

+ + + + +
+ + +
clock_t tms::tms_cstime +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
clock_t tms::tms_cutime +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
clock_t tms::tms_stime +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
clock_t tms::tms_utime +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structtss_struct.html b/doc/doxygen/html/structtss_struct.html new file mode 100644 index 0000000..c0728ed --- /dev/null +++ b/doc/doxygen/html/structtss_struct.html @@ -0,0 +1,957 @@ + + +Ubixos: tssStruct struct Reference + + + +

tssStruct Struct Reference

#include <tss.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

short back_link
short back_link_reserved
long esp0
short ss0
short ss0_reserved
long esp1
short ss1
short ss1_reserved
long esp2
short ss2
short ss2_reserved
long cr3
long eip
long eflags
long eax
long ecx
long edx
long ebx
long esp
long ebp
long esi
long edi
short es
short es_reserved
short cs
short cs_reserved
short ss
short ss_reserved
short ds
short ds_reserved
short fs
short fs_reserved
short gs
short gs_reserved
short ldt
short ldt_reserved
short trace_bitmap
short io_map
char io_space [8192]
+


Field Documentation

+

+ + + + +
+ + +
short tssStruct::back_link +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::back_link_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::cr3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::cs +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::cs_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ds +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ds_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::eax +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::ebp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::ebx +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::ecx +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::edi +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::edx +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::eflags +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::eip +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::es +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::es_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::esi +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::esp +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::esp0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::esp1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
long tssStruct::esp2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::fs +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::fs_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::gs +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::gs_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::io_map +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char tssStruct::io_space[8192] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ldt +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ldt_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss0 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss0_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss1_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss2_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::ss_reserved +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
short tssStruct::trace_bitmap +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubix_disk_label.html b/doc/doxygen/html/structubix_disk_label.html new file mode 100644 index 0000000..48acd67 --- /dev/null +++ b/doc/doxygen/html/structubix_disk_label.html @@ -0,0 +1,99 @@ + + +Ubixos: ubixDiskLabel struct Reference + + + +

ubixDiskLabel Struct Reference

Partition Information. +More... +

+#include <ubixfs.h> +

+ + + + + + + + + +

Data Fields

uInt32 magicNum
uInt16 numPartitions
ubixDiskLabel::drivePartitions partitions [MAXPARTITIONS]
+


Detailed Description

+Partition Information. +

+


Field Documentation

+

+ + + + +
+ + +
uInt32 ubixDiskLabel::magicNum +
+
+ + + + + +
+   + + +

+Should be UBIXDISKMAGIC uInt32 magicNum2; uInt16 driveType; /*!< Type of drive

+

+ + + + +
+ + +
uInt16 ubixDiskLabel::numPartitions +
+
+ + + + + +
+   + + +

+Number of partitions in the drive

+

+ + + + +
+ + +
struct ubixDiskLabel::drivePartitions ubixDiskLabel::partitions[MAXPARTITIONS] +
+
+ + + + + +
+   + + +

+the partition table

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubix_disk_label_1_1drive_partitions.html b/doc/doxygen/html/structubix_disk_label_1_1drive_partitions.html new file mode 100644 index 0000000..188a449 --- /dev/null +++ b/doc/doxygen/html/structubix_disk_label_1_1drive_partitions.html @@ -0,0 +1,168 @@ + + +Ubixos: ubixDiskLabel::drivePartitions struct Reference + + + +

ubixDiskLabel::drivePartitions Struct Reference

#include <ubixfs.h> +

+ + + + + + + + + + + + + + + +

Data Fields

uInt32 pSize
uInt32 pOffset
uInt32 pFsSize
uInt32 pBatSize
uInt8 pFsType
uInt8 pFrag
+


Detailed Description

+the partition table +

+


Field Documentation

+

+ + + + +
+ + +
uInt32 ubixDiskLabel::drivePartitions::pBatSize +
+
+ + + + + +
+   + + +

+BAT size

+

+ + + + +
+ + +
uInt8 ubixDiskLabel::drivePartitions::pFrag +
+
+ + + + + +
+   + + +

+filesystem fragments per block

+

+ + + + +
+ + +
uInt32 ubixDiskLabel::drivePartitions::pFsSize +
+
+ + + + + +
+   + + +

+filesystem basic fragment size

+

+ + + + +
+ + +
uInt8 ubixDiskLabel::drivePartitions::pFsType +
+
+ + + + + +
+   + + +

+filesystem type, see below

+

+ + + + +
+ + +
uInt32 ubixDiskLabel::drivePartitions::pOffset +
+
+ + + + + +
+   + + +

+starting sector

+

+ + + + +
+ + +
uInt32 ubixDiskLabel::drivePartitions::pSize +
+
+ + + + + +
+   + + +

+number of sectors in partition

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubix_fs_info.html b/doc/doxygen/html/structubix_fs_info.html new file mode 100644 index 0000000..67efb1a --- /dev/null +++ b/doc/doxygen/html/structubix_fs_info.html @@ -0,0 +1,69 @@ + + +Ubixos: ubixFsInfo struct Reference + + + +

ubixFsInfo Struct Reference

#include <ubixfs.h> +

+ + + + + + + +

Data Fields

blockAllocationTableEntryblockAllocationTable
uInt32 batEntries
+


Field Documentation

+

+ + + + +
+ + +
uInt32 ubixFsInfo::batEntries +
+
+ + + + + +
+   + + +

+Number of block allocation table entries

+

+ + + + +
+ + +
struct blockAllocationTableEntry* ubixFsInfo::blockAllocationTable +
+
+ + + + + +
+   + + +

+Dynamically allocated array of block allocation tables

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubthread.html b/doc/doxygen/html/structubthread.html new file mode 100644 index 0000000..6931d5b --- /dev/null +++ b/doc/doxygen/html/structubthread.html @@ -0,0 +1,45 @@ + + +Ubixos: ubthread struct Reference + + + +

ubthread Struct Reference

#include <ubthread.h> +

+ + + + + +

Data Fields

kTask_ttask
+


Field Documentation

+

+ + + + +
+ + +
kTask_t* ubthread::task +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubthread__cond.html b/doc/doxygen/html/structubthread__cond.html new file mode 100644 index 0000000..f63fa48 --- /dev/null +++ b/doc/doxygen/html/structubthread__cond.html @@ -0,0 +1,69 @@ + + +Ubixos: ubthread_cond struct Reference + + + +

ubthread_cond Struct Reference

#include <ubthread.h> +

+ + + + + + + +

Data Fields

int id
uInt8 locked
+


Field Documentation

+

+ + + + +
+ + +
int ubthread_cond::id +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 ubthread_cond::locked +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubthread__cond__list.html b/doc/doxygen/html/structubthread__cond__list.html new file mode 100644 index 0000000..8faeb63 --- /dev/null +++ b/doc/doxygen/html/structubthread__cond__list.html @@ -0,0 +1,69 @@ + + +Ubixos: ubthread_cond_list struct Reference + + + +

ubthread_cond_list Struct Reference

#include <ubthread.h> +

+ + + + + + + +

Data Fields

ubthread_cond_listnext
ubthread_cond_tcond
+


Field Documentation

+

+ + + + +
+ + +
ubthread_cond_t* ubthread_cond_list::cond +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ubthread_cond_list* ubthread_cond_list::next +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubthread__list.html b/doc/doxygen/html/structubthread__list.html new file mode 100644 index 0000000..e583651 --- /dev/null +++ b/doc/doxygen/html/structubthread__list.html @@ -0,0 +1,69 @@ + + +Ubixos: ubthread_list struct Reference + + + +

ubthread_list Struct Reference

#include <ubthread.h> +

+ + + + + + + +

Data Fields

ubthread_listnext
ubthread_t thread
+


Field Documentation

+

+ + + + +
+ + +
struct ubthread_list* ubthread_list::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
ubthread_t ubthread_list::thread +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubthread__mutex.html b/doc/doxygen/html/structubthread__mutex.html new file mode 100644 index 0000000..a65038e --- /dev/null +++ b/doc/doxygen/html/structubthread__mutex.html @@ -0,0 +1,93 @@ + + +Ubixos: ubthread_mutex struct Reference + + + +

ubthread_mutex Struct Reference

#include <ubthread.h> +

+ + + + + + + + + +

Data Fields

int id
uInt8 locked
pidType pid
+


Field Documentation

+

+ + + + +
+ + +
int ubthread_mutex::id +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 ubthread_mutex::locked +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
pidType ubthread_mutex::pid +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structubthread__mutex__list.html b/doc/doxygen/html/structubthread__mutex__list.html new file mode 100644 index 0000000..1236e5c --- /dev/null +++ b/doc/doxygen/html/structubthread__mutex__list.html @@ -0,0 +1,69 @@ + + +Ubixos: ubthread_mutex_list struct Reference + + + +

ubthread_mutex_list Struct Reference

#include <ubthread.h> +

+ + + + + + + +

Data Fields

ubthread_mutex_listnext
ubthread_mutex_tmutex
+


Field Documentation

+

+ + + + +
+ + +
ubthread_mutex_t* ubthread_mutex_list::mutex +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ubthread_mutex_list* ubthread_mutex_list::next +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structudp__hdr.html b/doc/doxygen/html/structudp__hdr.html new file mode 100644 index 0000000..e3a2a6e --- /dev/null +++ b/doc/doxygen/html/structudp__hdr.html @@ -0,0 +1,145 @@ + + +Ubixos: udp_hdr struct Reference + + + +

udp_hdr Struct Reference

#include <udp.h> +

+ + + + + + + + + + + +

Public Member Functions

 PACK_STRUCT_FIELD (uInt16 src)
 PACK_STRUCT_FIELD (uInt16 dest)
 PACK_STRUCT_FIELD (uInt16 len)
 PACK_STRUCT_FIELD (uInt16 chksum)
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + +
udp_hdr::PACK_STRUCT_FIELD uInt16  chksum  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
udp_hdr::PACK_STRUCT_FIELD uInt16  len  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
udp_hdr::PACK_STRUCT_FIELD uInt16  dest  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
udp_hdr::PACK_STRUCT_FIELD uInt16  src  ) 
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structudp__pcb.html b/doc/doxygen/html/structudp__pcb.html new file mode 100644 index 0000000..ba4f16c --- /dev/null +++ b/doc/doxygen/html/structudp__pcb.html @@ -0,0 +1,213 @@ + + +Ubixos: udp_pcb struct Reference + + + +

udp_pcb Struct Reference

#include <udp.h> +

+ + + + + + + + + + + + + + + + + + + +

Data Fields

udp_pcbnext
ip_addr local_ip remote_ip
uInt16 local_port
uInt16 remote_port
uInt8 flags
uInt16 chksum_len
void(* recv )(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, uInt16 port)
void * recv_arg
+


Field Documentation

+

+ + + + +
+ + +
uInt16 udp_pcb::chksum_len +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt8 udp_pcb::flags +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 udp_pcb::local_port +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct udp_pcb* udp_pcb::next +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void(* udp_pcb::recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, uInt16 port) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* udp_pcb::recv_arg +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct ip_addr local_ip udp_pcb::remote_ip +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt16 udp_pcb::remote_port +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structuser_file_descriptor_struct.html b/doc/doxygen/html/structuser_file_descriptor_struct.html new file mode 100644 index 0000000..0ede511 --- /dev/null +++ b/doc/doxygen/html/structuser_file_descriptor_struct.html @@ -0,0 +1,69 @@ + + +Ubixos: userFileDescriptorStruct struct Reference + + + +

userFileDescriptorStruct Struct Reference

#include <file.h> +

+ + + + + + + +

Data Fields

fileDescriptorStructfd
uInt32 fdSize
+


Field Documentation

+

+ + + + +
+ + +
struct fileDescriptorStruct* userFileDescriptorStruct::fd +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 userFileDescriptorStruct::fdSize +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/structvitals_struct.html b/doc/doxygen/html/structvitals_struct.html new file mode 100644 index 0000000..7bad9e3 --- /dev/null +++ b/doc/doxygen/html/structvitals_struct.html @@ -0,0 +1,285 @@ + + +Ubixos: vitalsStruct struct Reference + + + +

vitalsStruct Struct Reference

#include <vitals.h> +

+ + + + + + + + + + + + + + + + + + + + + + + + + +

Data Fields

uInt32 openFiles
uInt32 sysTicks
uInt32 sysUptime
uInt32 freePages
fileSystemfileSystems
mountPointsmountPoints
uInt32 timeStart
void * screen
void * font
char * packet
uInt32 packetLength
+


Field Documentation

+

+ + + + +
+ + +
struct fileSystem* vitalsStruct::fileSystems +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* vitalsStruct::font +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 vitalsStruct::freePages +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct mountPoints* vitalsStruct::mountPoints +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 vitalsStruct::openFiles +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
char* vitalsStruct::packet +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 vitalsStruct::packetLength +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
void* vitalsStruct::screen +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 vitalsStruct::sysTicks +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 vitalsStruct::sysUptime +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 vitalsStruct::timeStart +
+
+ + + + + +
+   + + +

+

+


The documentation for this struct was generated from the following file: +
Generated on Sat May 8 09:28:26 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sys_8h-source.html b/doc/doxygen/html/sys_8h-source.html new file mode 100644 index 0000000..252ebe6 --- /dev/null +++ b/doc/doxygen/html/sys_8h-source.html @@ -0,0 +1,105 @@ + + +Ubixos: sys.h Source File + + + +

sys.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_SYS_H__
+00036 #define __LWIP_SYS_H__
+00037 
+00038 #include "arch/cc.h"
+00039 #include "arch/sys_arch.h"
+00040 
+00041 typedef void (* sys_timeout_handler)(void *arg);
+00042 
+00043 struct sys_timeout {
+00044   struct sys_timeout *next;
+00045   uInt16 time;
+00046   sys_timeout_handler h;
+00047   void *arg;
+00048 };
+00049 
+00050 struct sys_timeouts {
+00051   struct sys_timeout *next;
+00052 };
+00053 
+00054 /* sys_init() must be called before anthing else. */
+00055 void sys_init(void);
+00056 
+00057 /*
+00058  * sys_timeout():
+00059  *
+00060  * Schedule a timeout a specified amount of milliseconds in the
+00061  * future. When the timeout occurs, the specified timeout handler will
+00062  * be called. The handler will be passed the "arg" argument when
+00063  * called.
+00064  *
+00065  */
+00066 void sys_timeout(uInt16 msecs, sys_timeout_handler h, void *arg);
+00067 struct sys_timeouts *sys_arch_timeouts(void);
+00068 
+00069 /* Semaphore functions. */
+00070 sys_sem_t sys_sem_new(uInt8 count);
+00071 void sys_sem_signal(sys_sem_t sem);
+00072 uInt16 sys_arch_sem_wait(sys_sem_t sem, uInt16 timeout);
+00073 void sys_sem_free(sys_sem_t sem);
+00074 
+00075 void sys_sem_wait(sys_sem_t sem);
+00076 
+00077 /* Mailbox functions. */
+00078 sys_mbox_t sys_mbox_new(void);
+00079 void sys_mbox_post(sys_mbox_t mbox, void *msg);
+00080 uInt16 sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, uInt16 timeout);
+00081 void sys_mbox_free(sys_mbox_t mbox);
+00082 
+00083 void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
+00084 
+00085 /* Thread functions. */
+00086 void sys_thread_new(void (* thread)(void *arg), void *arg);
+00087 
+00088 /* The following functions are used only in Unix code, and
+00089    can be omitted when porting the stack. */
+00090 /* Returns the current time in microseconds. */
+00091 unsigned long sys_now(void);
+00092 
+00093 #endif /* __LWIP_SYS_H__ */
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sys_8h.html b/doc/doxygen/html/sys_8h.html new file mode 100644 index 0000000..2df0695 --- /dev/null +++ b/doc/doxygen/html/sys_8h.html @@ -0,0 +1,583 @@ + + +Ubixos: sys.h File Reference + + + +

sys.h File Reference

#include "arch/cc.h"
+#include "arch/sys_arch.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  sys_timeout
struct  sys_timeouts

Typedefs

typedef void(* sys_timeout_handler )(void *arg)

Functions

void sys_init (void)
void sys_timeout (uInt16 msecs, sys_timeout_handler h, void *arg)
sys_timeoutssys_arch_timeouts (void)
sys_sem_t sys_sem_new (uInt8 count)
void sys_sem_signal (sys_sem_t sem)
uInt16 sys_arch_sem_wait (sys_sem_t sem, uInt16 timeout)
void sys_sem_free (sys_sem_t sem)
void sys_sem_wait (sys_sem_t sem)
sys_mbox_t sys_mbox_new (void)
void sys_mbox_post (sys_mbox_t mbox, void *msg)
uInt16 sys_arch_mbox_fetch (sys_mbox_t mbox, void **msg, uInt16 timeout)
void sys_mbox_free (sys_mbox_t mbox)
void sys_mbox_fetch (sys_mbox_t mbox, void **msg)
void sys_thread_new (void(*thread)(void *arg), void *arg)
unsigned long sys_now (void)
+


Typedef Documentation

+

+ + + + +
+ + +
typedef void(* sys_timeout_handler)(void *arg) +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
uInt16 sys_arch_mbox_fetch sys_mbox_t  mbox,
void **  msg,
uInt16  timeout
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uInt16 sys_arch_sem_wait sys_sem_t  sem,
uInt16  timeout
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct sys_timeouts* sys_arch_timeouts void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void sys_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void sys_mbox_fetch sys_mbox_t  mbox,
void **  msg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void sys_mbox_free sys_mbox_t  mbox  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
sys_mbox_t sys_mbox_new void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void sys_mbox_post sys_mbox_t  mbox,
void *  msg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
unsigned long sys_now void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void sys_sem_free sys_sem_t  sem  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
sys_sem_t sys_sem_new uInt8  count  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void sys_sem_signal sys_sem_t  sem  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void sys_sem_wait sys_sem_t  sem  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void sys_thread_new void(*  thread)(void *arg),
void *  arg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void sys_timeout uInt16  msecs,
sys_timeout_handler  h,
void *  arg
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sys__arch_8h-source.html b/doc/doxygen/html/sys__arch_8h-source.html new file mode 100644 index 0000000..144ec81 --- /dev/null +++ b/doc/doxygen/html/sys__arch_8h-source.html @@ -0,0 +1,63 @@ + + +Ubixos: sys_arch.h Source File + + + +

sys_arch.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __ARCH_SYS_ARCH_H__
+00036 #define __ARCH_SYS_ARCH_H__
+00037 
+00038 #define SYS_MBOX_NULL NULL
+00039 #define SYS_SEM_NULL  NULL
+00040 
+00041 struct sys_sem;
+00042 typedef struct sys_sem * sys_sem_t;
+00043 
+00044 struct sys_mbox;
+00045 typedef struct sys_mbox *sys_mbox_t;
+00046 
+00047 struct sys_thread;
+00048 typedef struct sys_thread * sys_thread_t;
+00049 
+00050 #endif /* __ARCH_SYS_ARCH_H__ */
+00051 
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/sys__arch_8h.html b/doc/doxygen/html/sys__arch_8h.html new file mode 100644 index 0000000..0510b3c --- /dev/null +++ b/doc/doxygen/html/sys__arch_8h.html @@ -0,0 +1,141 @@ + + +Ubixos: sys_arch.h File Reference + + + +

sys_arch.h File Reference

+

+Go to the source code of this file. + + + + + + + + + + + + + +

Defines

#define SYS_MBOX_NULL   NULL
#define SYS_SEM_NULL   NULL

Typedefs

typedef sys_sem * sys_sem_t
typedef sys_mbox * sys_mbox_t
typedef sys_thread * sys_thread_t
+


Define Documentation

+

+ + + + +
+ + +
#define SYS_MBOX_NULL   NULL +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define SYS_SEM_NULL   NULL +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct sys_mbox* sys_mbox_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef struct sys_sem* sys_sem_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef struct sys_thread* sys_thread_t +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/syscall_8h-source.html b/doc/doxygen/html/syscall_8h-source.html new file mode 100644 index 0000000..5d51c54 --- /dev/null +++ b/doc/doxygen/html/syscall_8h-source.html @@ -0,0 +1,43 @@ + + +Ubixos: syscall.h Source File + + + +

syscall.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _SYSCALL_H
+00025 #define _SYSCALL_H
+00026 
+00027 void _sysCall();
+00028 void invalidCall();
+00029 
+00030 #endif
+00031 
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/syscall_8h.html b/doc/doxygen/html/syscall_8h.html new file mode 100644 index 0000000..8779c2a --- /dev/null +++ b/doc/doxygen/html/syscall_8h.html @@ -0,0 +1,79 @@ + + +Ubixos: syscall.h File Reference + + + +

syscall.h File Reference

+

+Go to the source code of this file. + + + + + + +

Functions

void _sysCall ()
void invalidCall ()
+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void _sysCall  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void invalidCall  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/syscalls_8h-source.html b/doc/doxygen/html/syscalls_8h-source.html new file mode 100644 index 0000000..f6043da --- /dev/null +++ b/doc/doxygen/html/syscalls_8h-source.html @@ -0,0 +1,128 @@ + + +Ubixos: syscalls.h Source File + + + +

syscalls.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _SYSCALLS_H
+00025 #define _SYSCALLS_H
+00026 
+00027 #include <ubixos/sched.h>
+00028 #include <vfs/file.h>
+00029 
+00030 void sysGetpid();
+00031 void sysExit();
+00032 void sysExec();
+00033 void sysFork();
+00034 void sysCheckPid();
+00035 void sysGetFreePage();
+00036 
+00037 void sysFwrite();
+00038 void sysFgetc();
+00039 void sysFopen();
+00040 void sysFread();
+00041 void sysFclose();
+00042 void sysSchedYield();
+00043 void sysFseek();
+00044 void sysMkDir();
+00045 void sysRmDir();
+00046 void sysGetUid();
+00047 void sysGetGid();
+00048 void sysSetUid();
+00049 void sysSetGid();
+00050 void sysSDE();
+00051 void sysGetDrives();
+00052 void sysGetCwd();
+00053 void sysChDir();
+00054 void sysGetUptime();
+00055 void sysGetTime();
+00056 void sysStartSDE();
+00057 void sysUnlink();
+00058 
+00059 typedef void (*functionPTR)();
+00060 
+00061 functionPTR systemCalls[] = {
+00062   invalidCall,      
+00063   sysGetpid,        
+00064   sysExit,          
+00065   sysExec,          
+00066   sysFork,          
+00067   sysFgetc,         
+00068   sysCheckPid,      
+00069   sysGetFreePage,   
+00070   sysFopen,         
+00071   invalidCall,      
+00072   sysFclose,        
+00073   sysSchedYield,    
+00074   invalidCall,      
+00075   invalidCall,      
+00076   invalidCall,      
+00077   invalidCall,      
+00078   invalidCall,      
+00079   invalidCall,      
+00080   invalidCall,      
+00081   invalidCall,      
+00082   sysFopen,         
+00083   sysFclose,        
+00084   sysFread,         
+00085   sysFwrite,        
+00086   sysMkDir,         
+00087   sysRmDir,         
+00088   sysGetCwd,        
+00089   sysFseek,         
+00090   sysChDir,         
+00091   sysMkDir,         
+00092   sysUnlink,        
+00093   sysGetUid,        
+00094   sysGetGid,        
+00095   sysSetUid,        
+00096   sysSetGid,        
+00097   invalidCall,      
+00098   invalidCall,      
+00099   invalidCall,      
+00100   invalidCall,      
+00101   invalidCall,      
+00102   sysSDE,           
+00103   invalidCall,      
+00104   invalidCall,      
+00105   invalidCall,      
+00106   invalidCall,      
+00107   sysGetDrives,     
+00108   sysGetUptime,     
+00109   sysGetTime,       
+00110   sysStartSDE,      
+00111   };
+00112 
+00113 int totalCalls = sizeof(systemCalls)/sizeof(functionPTR);
+00114 
+00115 #endif
+00116 
+

Generated on Wed Apr 28 17:49:40 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/syscalls_8h.html b/doc/doxygen/html/syscalls_8h.html new file mode 100644 index 0000000..1d6a926 --- /dev/null +++ b/doc/doxygen/html/syscalls_8h.html @@ -0,0 +1,907 @@ + + +Ubixos: syscalls.h File Reference + + + +

syscalls.h File Reference

#include <ubixos/sched.h>
+#include <vfs/file.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Typedefs

typedef void(* functionPTR )()

Functions

void sysGetpid ()
void sysExit ()
void sysExec ()
void sysFork ()
void sysCheckPid ()
void sysGetFreePage ()
void sysFwrite ()
void sysFgetc ()
void sysFopen ()
void sysFread ()
void sysFclose ()
void sysSchedYield ()
void sysFseek ()
void sysMkDir ()
void sysRmDir ()
void sysGetUid ()
void sysGetGid ()
void sysSetUid ()
void sysSetGid ()
void sysSDE ()
void sysGetDrives ()
void sysGetCwd ()
void sysChDir ()
void sysGetUptime ()
void sysGetTime ()
void sysStartSDE ()
void sysUnlink ()

Variables

functionPTR systemCalls []
int totalCalls = sizeof(systemCalls)/sizeof(functionPTR)
+


Typedef Documentation

+

+ + + + +
+ + +
typedef void(* functionPTR)() +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void sysChDir  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysCheckPid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysExec  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysExit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFclose  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFgetc  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFopen  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFork  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFread  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFseek  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysFwrite  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetCwd  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetDrives  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetFreePage  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetGid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetpid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetTime  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetUid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysGetUptime  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysMkDir  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysRmDir  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysSchedYield  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysSDE  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysSetGid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysSetUid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysStartSDE  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void sysUnlink  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
functionPTR systemCalls[] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int totalCalls = sizeof(systemCalls)/sizeof(functionPTR) +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tcp_8h-source.html b/doc/doxygen/html/tcp_8h-source.html new file mode 100644 index 0000000..c28d817 --- /dev/null +++ b/doc/doxygen/html/tcp_8h-source.html @@ -0,0 +1,413 @@ + + +Ubixos: tcp.h Source File + + + +

tcp.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_TCP_H__
+00036 #define __LWIP_TCP_H__
+00037 
+00038 #include "net/sys.h"
+00039 #include "net/mem.h"
+00040 
+00041 #include "net/pbuf.h"
+00042 #include "net/opt.h"
+00043 //UBU
+00044 #include "net/ipv4/ip.h"
+00045 //UBU
+00046 #include "net/ipv4/icmp.h"
+00047 
+00048 #include "net/sys.h"
+00049 
+00050 #include "net/err.h"
+00051 
+00052 struct tcp_pcb;
+00053 
+00054 /* Functions for interfacing with TCP: */
+00055 
+00056 /* Lower layer interface to TCP: */
+00057 void             tcp_init    (void);  /* Must be called first to
+00058                                          initialize TCP. */
+00059 void             tcp_tmr     (void);  /* Must be called every
+00060                                          TCP_TMR_INTERVAL
+00061                                          ms. (Typically 100 ms). */
+00062 /* Application program's interface: */
+00063 struct tcp_pcb * tcp_new     (void);
+00064 
+00065 void             tcp_arg     (struct tcp_pcb *pcb, void *arg);
+00066 void             tcp_accept  (struct tcp_pcb *pcb,
+00067                               err_t (* accept)(void *arg, struct tcp_pcb *newpcb,
+00068                                                err_t err));
+00069 void             tcp_recv    (struct tcp_pcb *pcb,
+00070                               err_t (* recv)(void *arg, struct tcp_pcb *tpcb,
+00071                                   struct pbuf *p, err_t err));
+00072 void             tcp_sent    (struct tcp_pcb *pcb,
+00073                               err_t (* sent)(void *arg, struct tcp_pcb *tpcb,
+00074                                              uInt16 len));
+00075 void             tcp_poll    (struct tcp_pcb *pcb,
+00076                               err_t (* poll)(void *arg, struct tcp_pcb *tpcb),
+00077                               uInt8 interval);
+00078 void             tcp_err     (struct tcp_pcb *pcb,
+00079                               void (* err)(void *arg, err_t err));
+00080 
+00081 #define          tcp_sndbuf(pcb)   ((pcb)->snd_buf)
+00082 
+00083 void             tcp_recved  (struct tcp_pcb *pcb, uInt16 len);
+00084 err_t            tcp_bind    (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
+00085                               uInt16 port);
+00086 err_t            tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr,
+00087                               uInt16 port, err_t (* connected)(void *arg,
+00088                                                               struct tcp_pcb *tpcb,
+00089                                                               err_t err));
+00090 struct tcp_pcb * tcp_listen  (struct tcp_pcb *pcb);
+00091 void             tcp_abort   (struct tcp_pcb *pcb);
+00092 err_t            tcp_close   (struct tcp_pcb *pcb);
+00093 err_t            tcp_write   (struct tcp_pcb *pcb, const void *dataptr, uInt16 len,
+00094                               uInt8 copy);
+00095 
+00096 /* It is also possible to call these two functions at the right
+00097    intervals (instead of calling tcp_tmr()). */
+00098 void             tcp_slowtmr (void);
+00099 void             tcp_fasttmr (void);
+00100 
+00101 
+00102 /* Only used by IP to pass a TCP segment to TCP: */
+00103 void             tcp_input   (struct pbuf *p, struct netif *inp);
+00104 /* Used within the TCP code only: */
+00105 err_t            tcp_output  (struct tcp_pcb *pcb);
+00106 
+00107 
+00108 
+00109 
+00110 #define TCP_SEQ_LT(a,b)     ((Int32)((a)-(b)) < 0)
+00111 #define TCP_SEQ_LEQ(a,b)    ((Int32)((a)-(b)) <= 0)
+00112 #define TCP_SEQ_GT(a,b)     ((Int32)((a)-(b)) > 0)
+00113 #define TCP_SEQ_GEQ(a,b)    ((Int32)((a)-(b)) >= 0)
+00114 
+00115 #define TCP_FIN 0x01
+00116 #define TCP_SYN 0x02
+00117 #define TCP_RST 0x04
+00118 #define TCP_PSH 0x08
+00119 #define TCP_ACK 0x10
+00120 #define TCP_URG 0x20
+00121 
+00122 /* Length of the TCP header, excluding options. */
+00123 #define TCP_HLEN 20
+00124 
+00125 #define TCP_TMR_INTERVAL       100  /* The TCP timer interval in
+00126                                        milliseconds. */
+00127 
+00128 #define TCP_FAST_INTERVAL      200  /* the fine grained timeout in
+00129                                        milliseconds */
+00130 #define TCP_SLOW_INTERVAL      500  /* the coarse grained timeout in
+00131                                        milliseconds */
+00132 #define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */
+00133 #define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */
+00134 
+00135 #define TCP_OOSEQ_TIMEOUT        6 /* x RTO */
+00136 
+00137 #define TCP_MSL 60000  /* The maximum segment lifetime in microseconds */
+00138 
+00139 struct tcp_hdr {
+00140   PACK_STRUCT_FIELD(uInt16 src);
+00141   PACK_STRUCT_FIELD(uInt16 dest);
+00142   PACK_STRUCT_FIELD(uInt32 seqno);
+00143   PACK_STRUCT_FIELD(uInt32 ackno);
+00144   PACK_STRUCT_FIELD(uInt16 _offset_flags);
+00145   PACK_STRUCT_FIELD(uInt16 wnd);
+00146   PACK_STRUCT_FIELD(uInt16 chksum);
+00147   PACK_STRUCT_FIELD(uInt16 urgp);
+00148 } PACK_STRUCT_STRUCT;
+00149 
+00150 #define TCPH_OFFSET(hdr) (NTOHS((hdr)->_offset_flags) >> 8)
+00151 #define TCPH_FLAGS(hdr) (NTOHS((hdr)->_offset_flags) & 0xff)
+00152 
+00153 #define TCPH_OFFSET_SET(hdr, offset) (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr))
+00154 #define TCPH_FLAGS_SET(hdr, flags) (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags))
+00155 
+00156 #define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \
+00157                                         TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0))
+00158 
+00159 enum tcp_state {
+00160   CLOSED      = 0,
+00161   LISTEN      = 1,
+00162   SYN_SENT    = 2,
+00163   SYN_RCVD    = 3,
+00164   ESTABLISHED = 4,
+00165   FIN_WAIT_1  = 5,
+00166   FIN_WAIT_2  = 6,
+00167   CLOSE_WAIT  = 7,
+00168   CLOSING     = 8,
+00169   LAST_ACK    = 9,
+00170   TIME_WAIT   = 10
+00171 };
+00172 
+00173 
+00174 /* the TCP protocol control block */
+00175 struct tcp_pcb {
+00176   struct tcp_pcb *next;   /* for the linked list */
+00177 
+00178   enum tcp_state state;   /* TCP state */
+00179 
+00180   void *callback_arg;
+00181   
+00182   /* Function to call when a listener has been connected. */
+00183   err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err);
+00184 
+00185   struct ip_addr local_ip;
+00186   uInt16 local_port;
+00187   
+00188   struct ip_addr remote_ip;
+00189   uInt16 remote_port;
+00190   
+00191   /* receiver varables */
+00192   uInt32 rcv_nxt;   /* next seqno expected */
+00193   uInt16 rcv_wnd;   /* receiver window */
+00194 
+00195   /* Timers */
+00196   uInt16 tmr;
+00197 
+00198   /* Retransmission timer. */
+00199   uInt8 rtime;
+00200   
+00201   uInt16 mss;   /* maximum segment size */
+00202 
+00203   uInt8 flags;
+00204 #define TF_ACK_DELAY 0x01   /* Delayed ACK. */
+00205 #define TF_ACK_NOW   0x02   /* Immediate ACK. */
+00206 #define TF_INFR      0x04   /* In fast recovery. */
+00207 #define TF_RESET     0x08   /* Connection was reset. */
+00208 #define TF_CLOSED    0x10   /* Connection was sucessfully closed. */
+00209 #define TF_GOT_FIN   0x20   /* Connection was closed by the remote end. */
+00210   
+00211   /* RTT estimation variables. */
+00212   uInt16 rttest; /* RTT estimate in 500ms ticks */
+00213   uInt32 rtseq;  /* sequence number being timed */
+00214   Int32 sa, sv;
+00215 
+00216   uInt16 rto;    /* retransmission time-out */
+00217   uInt8 nrtx;    /* number of retransmissions */
+00218 
+00219   /* fast retransmit/recovery */
+00220   uInt32 lastack; /* Highest acknowledged seqno. */
+00221   uInt8 dupacks;
+00222   
+00223   /* congestion avoidance/control variables */
+00224   uInt16 cwnd;  
+00225   uInt16 ssthresh;
+00226 
+00227   /* sender variables */
+00228   uInt32 snd_nxt,       /* next seqno to be sent */
+00229     snd_max,       /* Highest seqno sent. */
+00230     snd_wnd,       /* sender window */
+00231     snd_wl1, snd_wl2,
+00232     snd_lbb;      
+00233 
+00234   uInt16 snd_buf;   /* Avaliable buffer space for sending. */
+00235   uInt8 snd_queuelen;
+00236 
+00237   /* Function to be called when more send buffer space is avaliable. */
+00238   err_t (* sent)(void *arg, struct tcp_pcb *pcb, uInt16 space);
+00239   uInt16 acked;
+00240   
+00241   /* Function to be called when (in-sequence) data has arrived. */
+00242   err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
+00243   struct pbuf *recv_data;
+00244 
+00245   /* Function to be called when a connection has been set up. */
+00246   err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err);
+00247 
+00248   /* Function which is called periodically. */
+00249   err_t (* poll)(void *arg, struct tcp_pcb *pcb);
+00250 
+00251   /* Function to be called whenever a fatal error occurs. */
+00252   void (* errf)(void *arg, err_t err);
+00253   
+00254   uInt8 polltmr, pollinterval;
+00255   
+00256   /* These are ordered by sequence number: */
+00257   struct tcp_seg *unsent;   /* Unsent (queued) segments. */
+00258   struct tcp_seg *unacked;  /* Sent but unacknowledged segments. */
+00259 #if TCP_QUEUE_OOSEQ  
+00260   struct tcp_seg *ooseq;    /* Received out of sequence segments. */
+00261 #endif /* TCP_QUEUE_OOSEQ */
+00262 
+00263 };
+00264 
+00265 struct tcp_pcb_listen {  
+00266   struct tcp_pcb_listen *next;   /* for the linked list */
+00267   
+00268   enum tcp_state state;   /* TCP state */
+00269 
+00270   void *callback_arg;
+00271   
+00272   /* Function to call when a listener has been connected. */
+00273   void (* accept)(void *arg, struct tcp_pcb *newpcb);
+00274 
+00275   struct ip_addr local_ip;
+00276   uInt16 local_port;
+00277 };
+00278 
+00279 /* This structure is used to repressent TCP segments. */
+00280 struct tcp_seg {
+00281   struct tcp_seg *next;    /* used when putting segements on a queue */
+00282   struct pbuf *p;          /* buffer containing data + TCP header */
+00283   void *dataptr;           /* pointer to the TCP data in the pbuf */
+00284   uInt16 len;               /* the TCP length of this segment */
+00285   struct tcp_hdr *tcphdr;  /* the TCP header */
+00286 };
+00287 
+00288 /* Internal functions and global variables: */
+00289 struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);
+00290 void tcp_pcb_purge(struct tcp_pcb *pcb);
+00291 void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);
+00292 
+00293 uInt8 tcp_segs_free(struct tcp_seg *seg);
+00294 uInt8 tcp_seg_free(struct tcp_seg *seg);
+00295 struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
+00296 
+00297 #define tcp_ack(pcb)     if((pcb)->flags & TF_ACK_DELAY) { \
+00298                             (pcb)->flags |= TF_ACK_NOW; \
+00299                             tcp_output(pcb); \
+00300                          } else { \
+00301                             (pcb)->flags |= TF_ACK_DELAY; \
+00302                          }
+00303 
+00304 #define tcp_ack_now(pcb) (pcb)->flags |= TF_ACK_NOW; \
+00305                          tcp_output(pcb)
+00306 
+00307 err_t tcp_send_ctrl(struct tcp_pcb *pcb, uInt8 flags);
+00308 err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, uInt16 len,
+00309                 uInt8 flags, uInt8 copy,
+00310                 uInt8 *optdata, uInt8 optlen);
+00311 
+00312 void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
+00313 
+00314 void tcp_rst(uInt32 seqno, uInt32 ackno,
+00315              struct ip_addr *local_ip, struct ip_addr *remote_ip,
+00316              uInt16 local_port, uInt16 remote_port);
+00317 
+00318 uInt32 tcp_next_iss(void);
+00319 
+00320 extern uInt32 tcp_ticks;
+00321 
+00322 #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
+00323 void tcp_debug_print(struct tcp_hdr *tcphdr);
+00324 void tcp_debug_print_flags(uInt8 flags);
+00325 void tcp_debug_print_state(enum tcp_state s);
+00326 void tcp_debug_print_pcbs(void);
+00327 int tcp_pcbs_sane(void);
+00328 #else
+00329 #define tcp_pcbs_sane() 1
+00330 #endif /* TCP_DEBUG */
+00331 
+00332 
+00333 /* The TCP PCB lists. */
+00334 extern struct tcp_pcb_listen *tcp_listen_pcbs;  /* List of all TCP PCBs in LISTEN state. */
+00335 extern struct tcp_pcb *tcp_active_pcbs;  /* List of all TCP PCBs that are in a
+00336                                             state in which they accept or send
+00337                                             data. */
+00338 extern struct tcp_pcb *tcp_tw_pcbs;      /* List of all TCP PCBs in TIME-WAIT. */
+00339 
+00340 extern struct tcp_pcb *tcp_tmp_pcb;      /* Only used for temporary storage. */
+00341 
+00342 /* Axoims about the above lists:   
+00343    1) Every TCP PCB that is not CLOSED is in one of the lists.
+00344    2) A PCB is only in one of the lists.
+00345    3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
+00346    4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.
+00347 */
+00348 
+00349 /* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB
+00350    with a PCB list or removes a PCB from a list, respectively. */
+00351 #ifdef LWIP_DEBUG
+00352 #define TCP_REG(pcbs, npcb) do {\
+00353                             DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \
+00354                             for(tcp_tmp_pcb = *pcbs; \
+00355                                   tcp_tmp_pcb != NULL; \
+00356                                 tcp_tmp_pcb = tcp_tmp_pcb->next) { \
+00357                                 ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \
+00358                             } \
+00359                             ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \
+00360                             npcb->next = *pcbs; \
+00361                             ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \
+00362                             *pcbs = npcb; \
+00363                             ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
+00364                             } while(0)
+00365 #define TCP_RMV(pcbs, npcb) do { \
+00366                             ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \
+00367                             DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \
+00368                             if(*pcbs == npcb) { \
+00369                                *pcbs = (*pcbs)->next; \
+00370                             } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
+00371                                if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \
+00372                                   tcp_tmp_pcb->next = npcb->next; \
+00373                                   break; \
+00374                                } \
+00375                             } \
+00376                             npcb->next = NULL; \
+00377                             ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \
+00378                             DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \
+00379                             } while(0)
+00380 
+00381 #else /* LWIP_DEBUG */
+00382 #define TCP_REG(pcbs, npcb) do { \
+00383                             npcb->next = *pcbs; \
+00384                             *pcbs = npcb; \
+00385                             } while(0)
+00386 #define TCP_RMV(pcbs, npcb) do { \
+00387                             if(*pcbs == npcb) { \
+00388                                *pcbs = (*pcbs)->next; \
+00389                             } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
+00390                                if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \
+00391                                   tcp_tmp_pcb->next = npcb->next; \
+00392                                   break; \
+00393                                } \
+00394                             } \
+00395                             npcb->next = NULL; \
+00396                             } while(0)
+00397 #endif /* LWIP_DEBUG */
+00398 #endif /* __LWIP_TCP_H__ */
+00399 
+00400 
+00401 
+

Generated on Wed Apr 28 17:49:41 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tcp_8h.html b/doc/doxygen/html/tcp_8h.html new file mode 100644 index 0000000..28186ad --- /dev/null +++ b/doc/doxygen/html/tcp_8h.html @@ -0,0 +1,2409 @@ + + +Ubixos: tcp.h File Reference + + + +

tcp.h File Reference

#include "net/sys.h"
+#include "net/mem.h"
+#include "net/pbuf.h"
+#include "net/opt.h"
+#include "net/ipv4/ip.h"
+#include "net/ipv4/icmp.h"
+#include "net/err.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  tcp_hdr
struct  tcp_pcb
struct  tcp_pcb_listen
struct  tcp_seg

Defines

#define tcp_sndbuf(pcb)   ((pcb)->snd_buf)
#define TCP_SEQ_LT(a, b)   ((Int32)((a)-(b)) < 0)
#define TCP_SEQ_LEQ(a, b)   ((Int32)((a)-(b)) <= 0)
#define TCP_SEQ_GT(a, b)   ((Int32)((a)-(b)) > 0)
#define TCP_SEQ_GEQ(a, b)   ((Int32)((a)-(b)) >= 0)
#define TCP_FIN   0x01
#define TCP_SYN   0x02
#define TCP_RST   0x04
#define TCP_PSH   0x08
#define TCP_ACK   0x10
#define TCP_URG   0x20
#define TCP_HLEN   20
#define TCP_TMR_INTERVAL   100
#define TCP_FAST_INTERVAL   200
#define TCP_SLOW_INTERVAL   500
#define TCP_FIN_WAIT_TIMEOUT   20000
#define TCP_SYN_RCVD_TIMEOUT   20000
#define TCP_OOSEQ_TIMEOUT   6
#define TCP_MSL   60000
#define TCPH_OFFSET(hdr)   (NTOHS((hdr)->_offset_flags) >> 8)
#define TCPH_FLAGS(hdr)   (NTOHS((hdr)->_offset_flags) & 0xff)
#define TCPH_OFFSET_SET(hdr, offset)   (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr))
#define TCPH_FLAGS_SET(hdr, flags)   (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags))
#define TCP_TCPLEN(seg)
#define TF_ACK_DELAY   0x01
#define TF_ACK_NOW   0x02
#define TF_INFR   0x04
#define TF_RESET   0x08
#define TF_CLOSED   0x10
#define TF_GOT_FIN   0x20
#define tcp_ack(pcb)
#define tcp_ack_now(pcb)
#define tcp_pcbs_sane()   1
#define TCP_REG(pcbs, npcb)
#define TCP_RMV(pcbs, npcb)

Enumerations

enum  tcp_state {
+  CLOSED = 0, +LISTEN = 1, +SYN_SENT = 2, +SYN_RCVD = 3, +
+  ESTABLISHED = 4, +FIN_WAIT_1 = 5, +FIN_WAIT_2 = 6, +CLOSE_WAIT = 7, +
+  CLOSING = 8, +LAST_ACK = 9, +TIME_WAIT = 10 +
+ }

Functions

void tcp_init (void)
void tcp_tmr (void)
tcp_pcbtcp_new (void)
void tcp_arg (struct tcp_pcb *pcb, void *arg)
void tcp_accept (struct tcp_pcb *pcb, err_t(*accept)(void *arg, struct tcp_pcb *newpcb, err_t err))
void tcp_recv (struct tcp_pcb *pcb, err_t(*recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err))
void tcp_sent (struct tcp_pcb *pcb, err_t(*sent)(void *arg, struct tcp_pcb *tpcb, uInt16 len))
void tcp_poll (struct tcp_pcb *pcb, err_t(*poll)(void *arg, struct tcp_pcb *tpcb), uInt8 interval)
void tcp_err (struct tcp_pcb *pcb, void(*err)(void *arg, err_t err))
void tcp_recved (struct tcp_pcb *pcb, uInt16 len)
err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port)
err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port, err_t(*connected)(void *arg, struct tcp_pcb *tpcb, err_t err))
tcp_pcbtcp_listen (struct tcp_pcb *pcb)
void tcp_abort (struct tcp_pcb *pcb)
err_t tcp_close (struct tcp_pcb *pcb)
err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, uInt16 len, uInt8 copy)
void tcp_slowtmr (void)
void tcp_fasttmr (void)
void tcp_input (struct pbuf *p, struct netif *inp)
err_t tcp_output (struct tcp_pcb *pcb)
tcp_pcbtcp_pcb_copy (struct tcp_pcb *pcb)
void tcp_pcb_purge (struct tcp_pcb *pcb)
void tcp_pcb_remove (struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
uInt8 tcp_segs_free (struct tcp_seg *seg)
uInt8 tcp_seg_free (struct tcp_seg *seg)
tcp_segtcp_seg_copy (struct tcp_seg *seg)
err_t tcp_send_ctrl (struct tcp_pcb *pcb, uInt8 flags)
err_t tcp_enqueue (struct tcp_pcb *pcb, void *dataptr, uInt16 len, uInt8 flags, uInt8 copy, uInt8 *optdata, uInt8 optlen)
void tcp_rexmit_seg (struct tcp_pcb *pcb, struct tcp_seg *seg)
void tcp_rst (uInt32 seqno, uInt32 ackno, struct ip_addr *local_ip, struct ip_addr *remote_ip, uInt16 local_port, uInt16 remote_port)
uInt32 tcp_next_iss (void)

Variables

tcp_hdr PACK_STRUCT_STRUCT
uInt32 tcp_ticks
tcp_pcb_listentcp_listen_pcbs
tcp_pcbtcp_active_pcbs
tcp_pcbtcp_tw_pcbs
tcp_pcbtcp_tmp_pcb
+


Define Documentation

+

+ + + + +
+ + + + + + + +
#define tcp_ackpcb   )  +
+
+ + + + + +
+   + + +

+Value:

if((pcb)->flags & TF_ACK_DELAY) { \
+                            (pcb)->flags |= TF_ACK_NOW; \
+                            tcp_output(pcb); \
+                         } else { \
+                            (pcb)->flags |= TF_ACK_DELAY; \
+                         }
+
+

+ + + + +
+ + +
#define TCP_ACK   0x10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define tcp_ack_nowpcb   )  +
+
+ + + + + +
+   + + +

+Value:

(pcb)->flags |= TF_ACK_NOW; \
+                         tcp_output(pcb)
+
+

+ + + + +
+ + +
#define TCP_FAST_INTERVAL   200 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_FIN   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_FIN_WAIT_TIMEOUT   20000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_HLEN   20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_MSL   60000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_OOSEQ_TIMEOUT   6 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + +  + + +
#define tcp_pcbs_sane  )    1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_PSH   0x08 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define TCP_REGpcbs,
npcb   )  +
+
+ + + + + +
+   + + +

+Value:

do { \
+                            npcb->next = *pcbs; \
+                            *pcbs = npcb; \
+                            } while(0)
+
+

+ + + + +
+ + + + + + + + + + +
#define TCP_RMVpcbs,
npcb   )  +
+
+ + + + + +
+   + + +

+Value:

do { \
+                            if(*pcbs == npcb) { \
+                               *pcbs = (*pcbs)->next; \
+                            } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \
+                               if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \
+                                  tcp_tmp_pcb->next = npcb->next; \
+                                  break; \
+                               } \
+                            } \
+                            npcb->next = NULL; \
+                            } while(0)
+
+

+ + + + +
+ + +
#define TCP_RST   0x04 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define TCP_SEQ_GEQa,
 )    ((Int32)((a)-(b)) >= 0) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define TCP_SEQ_GTa,
 )    ((Int32)((a)-(b)) > 0) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define TCP_SEQ_LEQa,
 )    ((Int32)((a)-(b)) <= 0) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define TCP_SEQ_LTa,
 )    ((Int32)((a)-(b)) < 0) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_SLOW_INTERVAL   500 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define tcp_sndbufpcb   )    ((pcb)->snd_buf) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_SYN   0x02 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_SYN_RCVD_TIMEOUT   20000 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define TCP_TCPLENseg   )  +
+
+ + + + + +
+   + + +

+Value:

((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \
+                                        TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0))
+
+

+ + + + +
+ + +
#define TCP_TMR_INTERVAL   100 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TCP_URG   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define TCPH_FLAGShdr   )    (NTOHS((hdr)->_offset_flags) & 0xff) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define TCPH_FLAGS_SEThdr,
flags   )    (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + +
#define TCPH_OFFSEThdr   )    (NTOHS((hdr)->_offset_flags) >> 8) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define TCPH_OFFSET_SEThdr,
offset   )    (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr)) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TF_ACK_DELAY   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TF_ACK_NOW   0x02 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TF_CLOSED   0x10 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TF_GOT_FIN   0x20 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TF_INFR   0x04 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define TF_RESET   0x08 +
+
+ + + + + +
+   + + +

+

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum tcp_state +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + + + + + + + + + +
CLOSED  +
LISTEN  +
SYN_SENT  +
SYN_RCVD  +
ESTABLISHED  +
FIN_WAIT_1  +
FIN_WAIT_2  +
CLOSE_WAIT  +
CLOSING  +
LAST_ACK  +
TIME_WAIT  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void tcp_abort struct tcp_pcb pcb  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_accept struct tcp_pcb pcb,
err_t(*  accept)(void *arg, struct tcp_pcb *newpcb, err_t err)
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_arg struct tcp_pcb pcb,
void *  arg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t tcp_bind struct tcp_pcb pcb,
struct ip_addr ipaddr,
uInt16  port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
err_t tcp_close struct tcp_pcb pcb  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t tcp_connect struct tcp_pcb pcb,
struct ip_addr ipaddr,
uInt16  port,
err_t(*  connected)(void *arg, struct tcp_pcb *tpcb, err_t err)
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t tcp_enqueue struct tcp_pcb pcb,
void *  dataptr,
uInt16  len,
uInt8  flags,
uInt8  copy,
uInt8 optdata,
uInt8  optlen
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_err struct tcp_pcb pcb,
void(*  err)(void *arg, err_t err)
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void tcp_fasttmr void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void tcp_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_input struct pbuf p,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct tcp_pcb* tcp_listen struct tcp_pcb pcb  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct tcp_pcb* tcp_new void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 tcp_next_iss void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
err_t tcp_output struct tcp_pcb pcb  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct tcp_pcb* tcp_pcb_copy struct tcp_pcb pcb  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void tcp_pcb_purge struct tcp_pcb pcb  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_pcb_remove struct tcp_pcb **  pcblist,
struct tcp_pcb pcb
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void tcp_poll struct tcp_pcb pcb,
err_t(*  poll)(void *arg, struct tcp_pcb *tpcb),
uInt8  interval
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_recv struct tcp_pcb pcb,
err_t(*  recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_recved struct tcp_pcb pcb,
uInt16  len
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_rexmit_seg struct tcp_pcb pcb,
struct tcp_seg seg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void tcp_rst uInt32  seqno,
uInt32  ackno,
struct ip_addr local_ip,
struct ip_addr remote_ip,
uInt16  local_port,
uInt16  remote_port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct tcp_seg* tcp_seg_copy struct tcp_seg seg  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 tcp_seg_free struct tcp_seg seg  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt8 tcp_segs_free struct tcp_seg seg  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
err_t tcp_send_ctrl struct tcp_pcb pcb,
uInt8  flags
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcp_sent struct tcp_pcb pcb,
err_t(*  sent)(void *arg, struct tcp_pcb *tpcb, uInt16 len)
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void tcp_slowtmr void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void tcp_tmr void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
err_t tcp_write struct tcp_pcb pcb,
const void *  dataptr,
uInt16  len,
uInt8  copy
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct tcp_hdr PACK_STRUCT_STRUCT +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_pcb* tcp_active_pcbs +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_pcb_listen* tcp_listen_pcbs +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
uInt32 tcp_ticks +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_pcb* tcp_tmp_pcb +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct tcp_pcb* tcp_tw_pcbs +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tcpdump_8h-source.html b/doc/doxygen/html/tcpdump_8h-source.html new file mode 100644 index 0000000..21ad790 --- /dev/null +++ b/doc/doxygen/html/tcpdump_8h-source.html @@ -0,0 +1,55 @@ + + +Ubixos: tcpdump.h Source File + + + +

tcpdump.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __NETIF_TCPDUMP_H__
+00036 #define __NETIF_TCPDUMP_H__
+00037 
+00038 #include "net/pbuf.h"
+00039 
+00040 void tcpdump_init(void);
+00041 void tcpdump(struct pbuf *p);
+00042 
+00043 #endif /* __NETIF_TCPDUMP_H__ */
+

Generated on Wed Apr 28 17:49:41 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tcpdump_8h.html b/doc/doxygen/html/tcpdump_8h.html new file mode 100644 index 0000000..ae7ffc0 --- /dev/null +++ b/doc/doxygen/html/tcpdump_8h.html @@ -0,0 +1,82 @@ + + +Ubixos: tcpdump.h File Reference + + + +

tcpdump.h File Reference

#include "net/pbuf.h"
+ +

+Go to the source code of this file. + + + + + + +

Functions

void tcpdump_init (void)
void tcpdump (struct pbuf *p)
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void tcpdump struct pbuf p  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void tcpdump_init void   ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tcpip_8h-source.html b/doc/doxygen/html/tcpip_8h-source.html new file mode 100644 index 0000000..6fc450e --- /dev/null +++ b/doc/doxygen/html/tcpip_8h-source.html @@ -0,0 +1,75 @@ + + +Ubixos: tcpip.h Source File + + + +

tcpip.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_TCPIP_H__
+00036 #define __LWIP_TCPIP_H__
+00037 
+00038 #include "net/api_msg.h"
+00039 #include "net/pbuf.h"
+00040 
+00041 void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
+00042 void tcpip_apimsg(struct api_msg *apimsg);
+00043 err_t tcpip_input(struct pbuf *p, struct netif *inp);
+00044 
+00045 enum tcpip_msg_type {
+00046   TCPIP_MSG_API,
+00047   TCPIP_MSG_INPUT
+00048 };
+00049 
+00050 struct tcpip_msg {
+00051   enum tcpip_msg_type type;
+00052   sys_sem_t *sem;
+00053   union {
+00054     struct api_msg *apimsg;
+00055     struct {
+00056       struct pbuf *p;
+00057       struct netif *netif;
+00058     } inp;
+00059   } msg;
+00060 };
+00061 
+00062 
+00063 #endif /* __LWIP_TCPIP_H__ */
+

Generated on Wed Apr 28 17:49:41 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tcpip_8h.html b/doc/doxygen/html/tcpip_8h.html new file mode 100644 index 0000000..dcb8890 --- /dev/null +++ b/doc/doxygen/html/tcpip_8h.html @@ -0,0 +1,171 @@ + + +Ubixos: tcpip.h File Reference + + + +

tcpip.h File Reference

#include "net/api_msg.h"
+#include "net/pbuf.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + +

Data Structures

struct  tcpip_msg

Enumerations

enum  tcpip_msg_type { TCPIP_MSG_API, +TCPIP_MSG_INPUT + }

Functions

void tcpip_init (void(*tcpip_init_done)(void *), void *arg)
void tcpip_apimsg (struct api_msg *apimsg)
err_t tcpip_input (struct pbuf *p, struct netif *inp)
+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum tcpip_msg_type +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + +
TCPIP_MSG_API  +
TCPIP_MSG_INPUT  +
+
+
+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
void tcpip_apimsg struct api_msg apimsg  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void tcpip_init void(*  tcpip_init_done)(void *),
void *  arg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
err_t tcpip_input struct pbuf p,
struct netif inp
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/time_8h-source.html b/doc/doxygen/html/time_8h-source.html new file mode 100644 index 0000000..5307902 --- /dev/null +++ b/doc/doxygen/html/time_8h-source.html @@ -0,0 +1,96 @@ + + +Ubixos: time.h Source File + + + +

time.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _TIME_H
+00025 #define _TIME_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <sys/io.h>
+00029 
+00030 typedef long suseconds_t;
+00031 
+00032 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
+00033 
+00034 #define MINUTE 60
+00035 #define HOUR (60*MINUTE)
+00036 #define DAY (24*HOUR)
+00037 #define YEAR (365*DAY)
+00038 
+00039 #ifndef _TIME_T_DECLARED
+00040 typedef __time_t        time_t;
+00041 #define _TIME_T_DECLARED
+00042 #endif
+00043 
+00044 struct timespec {
+00045         time_t  tv_sec;         /* seconds */
+00046         long    tv_nsec;        /* and nanoseconds */
+00047 };
+00048 
+00049 
+00050 
+00051 struct timeStruct {
+00052   int sec;
+00053   int min;
+00054   int hour;
+00055   int day;
+00056   int mon;
+00057   int year;
+00058   };
+00059 
+00060 
+00061 struct timezone {
+00062   int     tz_minuteswest; /* minutes west of Greenwich */
+00063   int     tz_dsttime;     /* type of dst correction */
+00064   };
+00065 
+00066 struct timeval {
+00067   long            tv_sec;         /* seconds (XXX should be time_t) */
+00068   suseconds_t     tv_usec;        /* and microseconds */
+00069   };
+00070 
+00071 int gettimeofday(struct timeval *tp,struct timezone *tzp);
+00072 
+00073 
+00074 
+00075 int timeInit();
+00076 int timeCmosRead(int);
+00077 uInt32 timeMake(struct timeStruct *time);
+00078 
+00079 #endif
+00080 
+00081 /***
+00082  END
+00083  ***/
+00084 
+

Generated on Wed Apr 28 17:49:41 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/time_8h.html b/doc/doxygen/html/time_8h.html new file mode 100644 index 0000000..a59158f --- /dev/null +++ b/doc/doxygen/html/time_8h.html @@ -0,0 +1,339 @@ + + +Ubixos: time.h File Reference + + + +

time.h File Reference

#include <ubixos/types.h>
+#include <sys/io.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  timespec
struct  timeStruct
struct  timeval
struct  timezone

Defines

#define BCD_TO_BIN(val)   ((val)=((val)&15) + ((val)>>4)*10)
#define MINUTE   60
#define HOUR   (60*MINUTE)
#define DAY   (24*HOUR)
#define YEAR   (365*DAY)

Typedefs

typedef long suseconds_t
typedef __time_t time_t

Functions

int gettimeofday (struct timeval *tp, struct timezone *tzp)
int timeInit ()
int timeCmosRead (int)
uInt32 timeMake (struct timeStruct *time)
+


Define Documentation

+

+ + + + +
+ + + + + + + +
#define BCD_TO_BINval   )    ((val)=((val)&15) + ((val)>>4)*10) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define DAY   (24*HOUR) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define HOUR   (60*MINUTE) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MINUTE   60 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define YEAR   (365*DAY) +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef long suseconds_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef __time_t time_t +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int gettimeofday struct timeval tp,
struct timezone tzp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int timeCmosRead int   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int timeInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 timeMake struct timeStruct time  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/times_8h-source.html b/doc/doxygen/html/times_8h-source.html new file mode 100644 index 0000000..14ae5c8 --- /dev/null +++ b/doc/doxygen/html/times_8h-source.html @@ -0,0 +1,59 @@ + + +Ubixos: times.h Source File + + + +

times.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _TIMES_H
+00025 #define _TIMES_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <sys/_types.h>
+00029 
+00030 #ifndef _CLOCK_T_DECLARED
+00031 typedef __clock_t       clock_t;
+00032 #define _CLOCK_T_DECLARED
+00033 #endif
+00034 
+00035 struct tms {
+00036         clock_t tms_utime;      /* User CPU time */
+00037         clock_t tms_stime;      /* System CPU time */
+00038         clock_t tms_cutime;     /* User CPU time of terminated child procs */
+00039         clock_t tms_cstime;     /* System CPU time of terminated child procs */
+00040 };
+00041 
+00042 #endif
+00043 
+00044 /***
+00045  END
+00046  ***/
+00047 
+

Generated on Wed Apr 28 17:49:41 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/times_8h.html b/doc/doxygen/html/times_8h.html new file mode 100644 index 0000000..7170506 --- /dev/null +++ b/doc/doxygen/html/times_8h.html @@ -0,0 +1,48 @@ + + +Ubixos: times.h File Reference + + + +

times.h File Reference

#include <ubixos/types.h>
+#include <sys/_types.h>
+ +

+Go to the source code of this file. + + + + + + + +

Data Structures

struct  tms

Typedefs

typedef __clock_t clock_t
+


Typedef Documentation

+

+ + + + +
+ + +
typedef __clock_t clock_t +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tss_8h-source.html b/doc/doxygen/html/tss_8h-source.html new file mode 100644 index 0000000..431c9cc --- /dev/null +++ b/doc/doxygen/html/tss_8h-source.html @@ -0,0 +1,91 @@ + + +Ubixos: tss.h Source File + + + +

tss.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _TSS_H
+00025 #define _TSS_H
+00026 
+00027 struct tssStruct {
+00028   short back_link;
+00029   short back_link_reserved;
+00030   long  esp0;
+00031   short ss0;
+00032   short ss0_reserved;
+00033   long  esp1;
+00034   short ss1;
+00035   short ss1_reserved;
+00036   long  esp2;
+00037   short ss2;
+00038   short ss2_reserved;
+00039   long  cr3;
+00040   long  eip;
+00041   long  eflags;
+00042   long  eax,ecx,edx,ebx;
+00043   long  esp;
+00044   long  ebp;
+00045   long  esi;
+00046   long  edi;
+00047   short es;
+00048   short es_reserved;
+00049   short cs;
+00050   short cs_reserved;
+00051   short ss;
+00052   short ss_reserved;
+00053   short ds;
+00054   short ds_reserved;
+00055   short fs;
+00056   short fs_reserved;
+00057   short gs;
+00058   short gs_reserved;
+00059   short ldt;
+00060   short ldt_reserved;
+00061   //long  trace_bitmap;   /* bits: trace 0, bitmap 16-31 */
+00062   short trace_bitmap;
+00063   short io_map;
+00064   char  io_space[8192];
+00065   };
+00066 
+00067 struct i387Struct {
+00068   long cwd;
+00069   long swd;
+00070   long twd;
+00071   long fip;
+00072   long fcs;
+00073   long foo;
+00074   long fos;
+00075   long st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
+00076   };
+00077 
+00078 #endif
+00079 
+

Generated on Wed Apr 28 17:49:41 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/tss_8h.html b/doc/doxygen/html/tss_8h.html new file mode 100644 index 0000000..a7a93bc --- /dev/null +++ b/doc/doxygen/html/tss_8h.html @@ -0,0 +1,22 @@ + + +Ubixos: tss.h File Reference + + + +

tss.h File Reference

+

+Go to the source code of this file. + + + + + + +

Data Structures

struct  i387Struct
struct  tssStruct
+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/types_8h-source.html b/doc/doxygen/html/types_8h-source.html new file mode 100644 index 0000000..37c7736 --- /dev/null +++ b/doc/doxygen/html/types_8h-source.html @@ -0,0 +1,73 @@ + + +Ubixos: types.h Source File + + + +

types.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _TYPES_H
+00025 #define _TYPES_H
+00026 
+00027 #include <sys/_types.h>
+00028 
+00029 #ifndef NULL
+00030 #define NULL 0x0
+00031 #endif
+00032 
+00033 typedef unsigned char byte;           /* 8-bit byte */
+00034 typedef unsigned short word;          /* 16-bit word */
+00035 typedef unsigned long dWord;          /* 32-bit dword */
+00036 
+00037 typedef unsigned char uChar;
+00038 typedef unsigned long uLong;
+00039 typedef unsigned short uShort;
+00040 typedef unsigned int uInt;
+00041 
+00042 typedef unsigned char  uInt8;
+00043 typedef unsigned short uInt16;
+00044 typedef unsigned long  uInt32;
+00045 typedef char Int8;
+00046 typedef short Int16;
+00047 typedef long Int32;
+00048 
+00049 typedef unsigned char uint8_t;
+00050 typedef unsigned short uint16_t;
+00051 typedef unsigned int uint32_t;
+00052 
+00053 typedef int pidType;
+00054 
+00055 typedef int  pid_t;
+00056 typedef int size_t; /* standart */
+00057 #ifndef NOBOOL
+00058 typedef enum { FALSE=0,TRUE=1 } bool;
+00059 #endif
+00060 
+00061 #endif
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/types_8h.html b/doc/doxygen/html/types_8h.html new file mode 100644 index 0000000..ee5b7ab --- /dev/null +++ b/doc/doxygen/html/types_8h.html @@ -0,0 +1,322 @@ + + +Ubixos: types.h File Reference + + + +

types.h File Reference

#include <sys/_types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define NULL   0x0

Typedefs

typedef unsigned char uInt8
typedef unsigned short uInt16
typedef unsigned long uInt32
typedef unsigned int uInt
typedef char Int8
typedef short Int16
typedef long Int32
typedef int pidType
typedef int pid_t
typedef int size_t

Enumerations

enum  bool { FALSE = 0, +TRUE = 1 + }
+


Define Documentation

+

+ + + + +
+ + +
#define NULL   0x0 +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef short Int16 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef long Int32 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef char Int8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef int pid_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef int pidType +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef int size_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef unsigned int uInt +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef unsigned short uInt16 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef unsigned long uInt32 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef unsigned char uInt8 +
+
+ + + + + +
+   + + +

+

+


Enumeration Type Documentation

+

+ + + + +
+ + +
enum bool +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + +
FALSE  +
TRUE  +
+
+
+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ubixfs_8h-source.html b/doc/doxygen/html/ubixfs_8h-source.html new file mode 100644 index 0000000..e1a193a --- /dev/null +++ b/doc/doxygen/html/ubixfs_8h-source.html @@ -0,0 +1,132 @@ + + +Ubixos: ubixfs.h Source File + + + +

ubixfs.h

Go to the documentation of this file.
00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _UBIXFS_H
+00025 #define _UBIXFS_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <sys/device.h>
+00029 #include <vfs/file.h>
+00030 
+00031 #define UBIXDISKMAGIC     ((uInt32)0x45) 
+00032 #define MAXPARTITIONS     4
+00033 #define blockSize         8
+00034 #define blockByteSize     blockSize*512
+00035 
+00036 #define EOBC              -1
+00037 
+00038 
+00039 #define typeFile      1
+00040 #define typeContainer 2
+00041 #define typeDirectory 4
+00042 #define typeDeleted   8
+00043 
+00045 struct ubixDiskLabel {
+00046   uInt32 magicNum; 
+00049   uInt16 numPartitions; 
+00051   struct  drivePartitions {
+00052     uInt32 pSize; 
+00053     uInt32 pOffset; 
+00054     uInt32 pFsSize; 
+00055     uInt32 pBatSize; 
+00056     uInt8  pFsType; 
+00057     uInt8 pFrag; 
+00058     } partitions[MAXPARTITIONS];
+00059   };
+00060 
+00061 struct partitionInformation {
+00062   uInt32 size;                 
+00063   uInt32 startSector;          
+00064   uInt32 blockAllocationTable; 
+00065   uInt32 rootDirectory;        
+00066   };
+00067 
+00069 struct blockAllocationTableEntry {
+00070   long attributes; 
+00071   long realSector; 
+00072   long nextBlock;  
+00073   long reserved;   
+00074   };
+00075 
+00077 struct directoryEntry {
+00078   uInt32  startCluster;   
+00079   uInt32  size;           
+00080   uInt32  creationDate;  
+00081   uInt32  lastModified;  
+00082   uInt32  uid;           
+00083   uInt32  gid;           
+00084   uInt16 attributes;    
+00085   uInt16 permissions;   
+00086   char   fileName[256]; 
+00087 };
+00088 
+00090 struct bootSect {
+00091   uInt8 jmp[4]; 
+00092   uInt8 id[6]; 
+00093   uInt16 version; 
+00094   uInt16 tmp;
+00095   uInt16 fsStart; 
+00096   uInt16 tmp2;
+00097   uInt32 krnl_start; 
+00098   uInt BytesPerSector;
+00099   uInt SectersPerTrack;
+00100   uInt TotalHeads;
+00101   uInt32 TotalSectors;
+00102   uInt8 code[479]; 
+00103   };  
+00104 
+00106 struct ubixFsInfo {
+00107   struct blockAllocationTableEntry *blockAllocationTable; 
+00108   uInt32 batEntries; 
+00109   };
+00110 
+00111 int readFile(char *file);
+00112 int writeFileByte(int ch,fileDescriptor *fd,long offset);
+00116 int openFileUbixFS(char *file,fileDescriptor *fd);
+00118 int mkDirUbixFS(char *dir,fileDescriptor *fd);
+00119 int getFreeBlocks(int count,fileDescriptor *fd);
+00120 
+00121 //Good Functions
+00124 int enableUbixFS();
+00127 void initUbixFS(struct mountPoints *mp);
+00130 int readUbixFS(fileDescriptor *fd,char *data,long offset,long size);
+00133 int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size);
+00134 void syncBat(struct mountPoints *mp);
+00135 int freeBlocks(int block,fileDescriptor *fd);
+00136 /* Adds a file to a directory. Returns 0 */
+00137 int addDirEntry(struct directoryEntry *dir,fileDescriptor *fd);
+00139 void ubixFSUnlink(char *path,struct mountPoints *mp);
+00140 
+00141 #endif
+

Generated on Sat May 8 09:28:18 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ubixfs_8h.html b/doc/doxygen/html/ubixfs_8h.html new file mode 100644 index 0000000..bc38e00 --- /dev/null +++ b/doc/doxygen/html/ubixfs_8h.html @@ -0,0 +1,771 @@ + + +Ubixos: ubixfs.h File Reference + + + +

ubixfs.h File Reference

#include <ubixos/types.h>
+#include <sys/device.h>
+#include <vfs/file.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  blockAllocationTableEntry
struct  bootSect
 Bootsector structure. More...

struct  directoryEntry
 UbixFS Directory Entry. More...

struct  partitionInformation
struct  ubixDiskLabel
 Partition Information. More...

struct  ubixDiskLabel.drivePartitions
struct  ubixFsInfo

Defines

#define UBIXDISKMAGIC   ((uInt32)0x45)
#define MAXPARTITIONS   4
#define blockSize   8
#define blockByteSize   blockSize*512
#define EOBC   -1
#define typeFile   1
#define typeContainer   2
#define typeDirectory   4
#define typeDeleted   8

Functions

int readFile (char *file)
int writeFileByte (int ch, fileDescriptor *fd, long offset)
int openFileUbixFS (char *file, fileDescriptor *fd)
int mkDirUbixFS (char *dir, fileDescriptor *fd)
int getFreeBlocks (int count, fileDescriptor *fd)
int enableUbixFS ()
void initUbixFS (struct mountPoints *mp)
int readUbixFS (fileDescriptor *fd, char *data, long offset, long size)
int writeUbixFS (fileDescriptor *fd, char *data, long offset, long size)
void syncBat (struct mountPoints *mp)
int freeBlocks (int block, fileDescriptor *fd)
int addDirEntry (struct directoryEntry *dir, fileDescriptor *fd)
void ubixFSUnlink (char *path, struct mountPoints *mp)
+


Define Documentation

+

+ + + + +
+ + +
#define blockByteSize   blockSize*512 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define blockSize   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define EOBC   -1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define MAXPARTITIONS   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define typeContainer   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define typeDeleted   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define typeDirectory   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define typeFile   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UBIXDISKMAGIC   ((uInt32)0x45) +
+
+ + + + + +
+   + + +

+The disk magic number

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int addDirEntry struct directoryEntry dir,
fileDescriptor fd
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int enableUbixFS  ) 
+
+ + + + + +
+   + + +

+Registers UbixFS functions with the virtual file-system (using vfsRegisterFS). Returns 1 if a failure happened, and 0 if success.

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int freeBlocks int  block,
fileDescriptor fd
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int getFreeBlocks int  count,
fileDescriptor fd
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void initUbixFS struct mountPoints mp  ) 
+
+ + + + + +
+   + + +

+Sets up the Ubix filesystem with appropriate data. If the medium is a hard-drive (or any medium?), it looks in the partition table.

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int mkDirUbixFS char *  dir,
fileDescriptor fd
+
+ + + + + +
+   + + +

+Makes a directory with the name directory. Returns 0

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int openFileUbixFS char *  file,
fileDescriptor fd
+
+ + + + + +
+   + + +

+Depending on fd->mode, it fills fd with data about the file (start, size, permissions etc.), if the string file is matched with a filename in the current directory. Returns 1 on success, and 0 on failure. The fileDescriptor struct definition can be found in VFS

+

+ + + + +
+ + + + + + + + + + +
int readFile char *  file  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int readUbixFS fileDescriptor fd,
char *  data,
long  offset,
long  size
+
+ + + + + +
+   + + +

+Reads part (or can be whole) of a file into the memory pointed to by data. Returns size if successful, and 0 on failure.

+

+ + + + +
+ + + + + + + + + + +
void syncBat struct mountPoints mp  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void ubixFSUnlink char *  path,
struct mountPoints mp
+
+ + + + + +
+   + + +

+Effectively erases the file or directory from the filesystem

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int writeFileByte int  ch,
fileDescriptor fd,
long  offset
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int writeUbixFS fileDescriptor fd,
char *  data,
long  offset,
long  size
+
+ + + + + +
+   + + +

+Writes part (or can be whole) of a file from the memory pointed to by data. Extends file if necessary. Returns size.

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ubthread_8h-source.html b/doc/doxygen/html/ubthread_8h-source.html new file mode 100644 index 0000000..e22128b --- /dev/null +++ b/doc/doxygen/html/ubthread_8h-source.html @@ -0,0 +1,95 @@ + + +Ubixos: ubthread.h Source File + + + +

ubthread.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _UBTHREAD_H
+00025 #define _UBTHREAD_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <ubixos/sched.h>
+00029 #include <ubixos/time.h>
+00030 
+00031 #define ETIMEDOUT -1
+00032 
+00033 #define LOCKED     1
+00034 #define UNLOCKED   0
+00035 
+00036 typedef struct ubthread       *ubthread_t;
+00037 typedef struct ubthread_cond  *ubthread_cond_t;
+00038 typedef struct ubthread_mutex *ubthread_mutex_t;
+00039 
+00040 struct ubthread {
+00041   kTask_t *task;
+00042   };
+00043 
+00044 struct ubthread_cond {
+00045   int   id;
+00046   uInt8 locked;
+00047   };
+00048 
+00049 struct ubthread_mutex {
+00050   int     id;
+00051   uInt8   locked;
+00052   pidType pid;
+00053   };
+00054 
+00055 struct ubthread_list {
+00056   struct ubthread_list *next;
+00057   ubthread_t           thread;
+00058   };
+00059 
+00060 struct ubthread_cond_list {
+00061   struct ubthread_cond_list *next;
+00062   ubthread_cond_t           *cond;
+00063   };
+00064 
+00065 struct ubthread_mutex_list {
+00066   struct ubthread_mutex_list *next;
+00067   ubthread_mutex_t           *mutex;
+00068   };
+00069 
+00070 
+00071 kTask_t *ubthread_self();
+00072 int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr);
+00073 int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr);
+00074 int ubthread_cond_destroy(ubthread_cond_t *cond);
+00075 int ubthread_mutex_destroy(ubthread_mutex_t *mutex);
+00076 int ubthread_create(kTask_t **thread,const uInt32 *attr,void *start_routine, void *arg);
+00077 int ubthread_mutex_lock(ubthread_mutex_t *mutex);
+00078 int ubthread_mutex_unlock(ubthread_mutex_t *mutex);
+00079 int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime);
+00080 int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex);
+00081 int ubthread_cond_signal(ubthread_cond_t *cond);
+00082 
+00083 #endif
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/ubthread_8h.html b/doc/doxygen/html/ubthread_8h.html new file mode 100644 index 0000000..127fdd0 --- /dev/null +++ b/doc/doxygen/html/ubthread_8h.html @@ -0,0 +1,586 @@ + + +Ubixos: ubthread.h File Reference + + + +

ubthread.h File Reference

#include <ubixos/types.h>
+#include <ubixos/sched.h>
+#include <ubixos/time.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  ubthread
struct  ubthread_cond
struct  ubthread_cond_list
struct  ubthread_list
struct  ubthread_mutex
struct  ubthread_mutex_list

Defines

#define ETIMEDOUT   -1
#define LOCKED   1
#define UNLOCKED   0

Typedefs

typedef ubthreadubthread_t
typedef ubthread_condubthread_cond_t
typedef ubthread_mutexubthread_mutex_t

Functions

kTask_tubthread_self ()
int ubthread_cond_init (ubthread_cond_t *cond, const uInt32 attr)
int ubthread_mutex_init (ubthread_mutex_t *mutex, const uInt32 attr)
int ubthread_cond_destroy (ubthread_cond_t *cond)
int ubthread_mutex_destroy (ubthread_mutex_t *mutex)
int ubthread_create (kTask_t **thread, const uInt32 *attr, void *start_routine, void *arg)
int ubthread_mutex_lock (ubthread_mutex_t *mutex)
int ubthread_mutex_unlock (ubthread_mutex_t *mutex)
int ubthread_cond_timedwait (ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime)
int ubthread_cond_wait (ubthread_cond_t *cond, ubthread_mutex_t *mutex)
int ubthread_cond_signal (ubthread_cond_t *cond)
+


Define Documentation

+

+ + + + +
+ + +
#define ETIMEDOUT   -1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define LOCKED   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UNLOCKED   0 +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct ubthread_cond* ubthread_cond_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef struct ubthread_mutex* ubthread_mutex_t +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
typedef struct ubthread* ubthread_t +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + +
int ubthread_cond_destroy ubthread_cond_t cond  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int ubthread_cond_init ubthread_cond_t cond,
const uInt32  attr
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ubthread_cond_signal ubthread_cond_t cond  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
int ubthread_cond_timedwait ubthread_cond_t cond,
ubthread_mutex_t mutex,
const struct timespec abstime
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int ubthread_cond_wait ubthread_cond_t cond,
ubthread_mutex_t mutex
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int ubthread_create kTask_t **  thread,
const uInt32 attr,
void *  start_routine,
void *  arg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ubthread_mutex_destroy ubthread_mutex_t mutex  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int ubthread_mutex_init ubthread_mutex_t mutex,
const uInt32  attr
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ubthread_mutex_lock ubthread_mutex_t mutex  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int ubthread_mutex_unlock ubthread_mutex_t mutex  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
kTask_t* ubthread_self  ) 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/udp_8h-source.html b/doc/doxygen/html/udp_8h-source.html new file mode 100644 index 0000000..2a14338 --- /dev/null +++ b/doc/doxygen/html/udp_8h-source.html @@ -0,0 +1,114 @@ + + +Ubixos: udp.h Source File + + + +

udp.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __LWIP_UDP_H__
+00036 #define __LWIP_UDP_H__
+00037 
+00038 #include "net/arch.h"
+00039 
+00040 #include "net/pbuf.h"
+00041 //UBU 
+00042 #include "net/ipv4/inet.h"
+00043 //UBU
+00044 #include "net/ipv4/ip.h"
+00045 
+00046 #include "net/err.h"
+00047 
+00048 #define UDP_HLEN 8
+00049 
+00050 struct udp_hdr {
+00051   PACK_STRUCT_FIELD(uInt16 src);
+00052   PACK_STRUCT_FIELD(uInt16 dest);  /* src/dest UDP ports */
+00053   PACK_STRUCT_FIELD(uInt16 len);
+00054   PACK_STRUCT_FIELD(uInt16 chksum);
+00055 } PACK_STRUCT_STRUCT;
+00056 
+00057 #define UDP_FLAGS_NOCHKSUM 0x01
+00058 #define UDP_FLAGS_UDPLITE  0x02
+00059 
+00060 struct udp_pcb {
+00061   struct udp_pcb *next;
+00062 
+00063   struct ip_addr local_ip, remote_ip;
+00064   uInt16 local_port, remote_port;
+00065   
+00066   uInt8 flags;
+00067   uInt16 chksum_len;
+00068   
+00069   void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
+00070                 struct ip_addr *addr, uInt16 port);
+00071   void *recv_arg;  
+00072 };
+00073 
+00074 /* The following functions is the application layer interface to the
+00075    UDP code. */
+00076 struct udp_pcb * udp_new        (void);
+00077 void             udp_remove     (struct udp_pcb *pcb);
+00078 err_t            udp_bind       (struct udp_pcb *pcb, struct ip_addr *ipaddr,
+00079                                  uInt16 port);
+00080 err_t            udp_connect    (struct udp_pcb *pcb, struct ip_addr *ipaddr,
+00081                                  uInt16 port);
+00082 void             udp_recv       (struct udp_pcb *pcb,
+00083                                  void (* recv)(void *arg, struct udp_pcb *upcb,
+00084                                                struct pbuf *p,
+00085                                                struct ip_addr *addr,
+00086                                                uInt16 port),
+00087                                  void *recv_arg);
+00088 err_t            udp_send       (struct udp_pcb *pcb, struct pbuf *p);
+00089 
+00090 #define          udp_flags(pcb)  ((pcb)->flags)
+00091 #define          udp_setflags(pcb, f)  ((pcb)->flags = (f))
+00092 
+00093 
+00094 /* The following functions is the lower layer interface to UDP. */
+00095 uInt8             udp_lookup     (struct ip_hdr *iphdr, struct netif *inp);
+00096 void             udp_input      (struct pbuf *p, struct netif *inp);
+00097 void             udp_init       (void);
+00098 
+00099 
+00100 #endif /* __LWIP_UDP_H__ */
+00101 
+00102 
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/udp_8h.html b/doc/doxygen/html/udp_8h.html new file mode 100644 index 0000000..7840362 --- /dev/null +++ b/doc/doxygen/html/udp_8h.html @@ -0,0 +1,541 @@ + + +Ubixos: udp.h File Reference + + + +

udp.h File Reference

#include "net/arch.h"
+#include "net/pbuf.h"
+#include "net/ipv4/inet.h"
+#include "net/ipv4/ip.h"
+#include "net/err.h"
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  udp_hdr
struct  udp_pcb

Defines

#define UDP_HLEN   8
#define UDP_FLAGS_NOCHKSUM   0x01
#define UDP_FLAGS_UDPLITE   0x02
#define udp_flags(pcb)   ((pcb)->flags)
#define udp_setflags(pcb, f)   ((pcb)->flags = (f))

Functions

udp_pcbudp_new (void)
void udp_remove (struct udp_pcb *pcb)
err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port)
err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr, uInt16 port)
void udp_recv (struct udp_pcb *pcb, void(*recv)(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, uInt16 port), void *recv_arg)
err_t udp_send (struct udp_pcb *pcb, struct pbuf *p)
uInt8 udp_lookup (struct ip_hdr *iphdr, struct netif *inp)
void udp_input (struct pbuf *p, struct netif *inp)
void udp_init (void)

Variables

udp_hdr PACK_STRUCT_STRUCT
+


Define Documentation

+

+ + + + +
+ + + + + + + +
#define udp_flagspcb   )    ((pcb)->flags) +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UDP_FLAGS_NOCHKSUM   0x01 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UDP_FLAGS_UDPLITE   0x02 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define UDP_HLEN   8 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
#define udp_setflagspcb,
 )    ((pcb)->flags = (f)) +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t udp_bind struct udp_pcb pcb,
struct ip_addr ipaddr,
uInt16  port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
err_t udp_connect struct udp_pcb pcb,
struct ip_addr ipaddr,
uInt16  port
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void udp_init void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void udp_input struct pbuf p,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
uInt8 udp_lookup struct ip_hdr iphdr,
struct netif inp
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct udp_pcb* udp_new void   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void udp_recv struct udp_pcb pcb,
void(*  recv)(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, uInt16 port),
void *  recv_arg
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void udp_remove struct udp_pcb pcb  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
err_t udp_send struct udp_pcb pcb,
struct pbuf p
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
struct udp_hdr PACK_STRUCT_STRUCT +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/udpecho_8h-source.html b/doc/doxygen/html/udpecho_8h-source.html new file mode 100644 index 0000000..e882238 --- /dev/null +++ b/doc/doxygen/html/udpecho_8h-source.html @@ -0,0 +1,52 @@ + + +Ubixos: udpecho.h Source File + + + +

udpecho.h

00001 /*
+00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
+00003  * All rights reserved. 
+00004  *
+00005  * Redistribution and use in source and binary forms, with or without 
+00006  * modification, are permitted provided that the following conditions 
+00007  * are met: 
+00008  * 1. Redistributions of source code must retain the above copyright 
+00009  *    notice, this list of conditions and the following disclaimer. 
+00010  * 2. Redistributions in binary form must reproduce the above copyright 
+00011  *    notice, this list of conditions and the following disclaimer in the 
+00012  *    documentation and/or other materials provided with the distribution. 
+00013  * 3. Neither the name of the Institute nor the names of its contributors 
+00014  *    may be used to endorse or promote products derived from this software 
+00015  *    without specific prior written permission. 
+00016  *
+00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
+00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
+00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
+00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
+00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
+00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
+00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
+00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+00027  * SUCH DAMAGE. 
+00028  *
+00029  * This file is part of the lwIP TCP/IP stack.
+00030  * 
+00031  * Author: Adam Dunkels <adam@sics.se>
+00032  *
+00033  * $Id$
+00034  */
+00035 #ifndef __UDPECHO_H__
+00036 #define __UDPECHO_H__
+00037 
+00038 void udpecho_init(void);
+00039 
+00040 #endif /* __UDPECHO_H__ */
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/uniondescriptor_table_union.html b/doc/doxygen/html/uniondescriptor_table_union.html new file mode 100644 index 0000000..f10ae49 --- /dev/null +++ b/doc/doxygen/html/uniondescriptor_table_union.html @@ -0,0 +1,93 @@ + + +Ubixos: descriptorTableUnion union Reference + + + +

descriptorTableUnion Union Reference

#include <gdt.h> +

+ + + + + + + + + +

Data Fields

gdtDescriptor descriptor
gdtGate gate
unsigned long dummy
+


Field Documentation

+

+ + + + +
+ + +
struct gdtDescriptor descriptorTableUnion::descriptor +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned long descriptorTableUnion::dummy +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
struct gdtGate descriptorTableUnion::gate +
+
+ + + + + +
+   + + +

+

+


The documentation for this union was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/unionetheraddr.html b/doc/doxygen/html/unionetheraddr.html new file mode 100644 index 0000000..7c04b6a --- /dev/null +++ b/doc/doxygen/html/unionetheraddr.html @@ -0,0 +1,69 @@ + + +Ubixos: etheraddr union Reference + + + +

etheraddr Union Reference

#include <ne2k.h> +

+ + + + + + + +

Data Fields

unsigned char bytes [6]
unsigned short shorts [3]
+


Field Documentation

+

+ + + + +
+ + +
unsigned char etheraddr::bytes[6] +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
unsigned short etheraddr::shorts[3] +
+
+ + + + + +
+   + + +

+

+


The documentation for this union was generated from the following file: +
Generated on Sat May 8 09:28:24 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/vfs_8h-source.html b/doc/doxygen/html/vfs_8h-source.html new file mode 100644 index 0000000..9650575 --- /dev/null +++ b/doc/doxygen/html/vfs_8h-source.html @@ -0,0 +1,96 @@ + + +Ubixos: vfs.h Source File + + + +

vfs.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _VFS_H
+00025 #define _VFS_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #define maxFd   32
+00030 #define fdAvail 1
+00031 #define fdOpen  2
+00032 #define fdRead  3
+00033 #define fdEof   4
+00034 
+00035 
+00036 #define fileRead    0x0001
+00037 #define fileWrite   0x0002
+00038 #define fileBinary  0x0004
+00039 #define fileAppend  0x0008
+00040 
+00041 typedef struct fileDescriptorStruct {
+00042   struct fileDescriptorStruct *prev;
+00043   struct fileDescriptorStruct *next;
+00044   struct mountPoints          *mp;
+00045   uInt16         status;
+00046   uInt16         mode;
+00047   uInt32         offset;
+00048   uInt32         size;
+00049   uInt16         length;
+00050   uInt32         start;
+00051   uInt8          fileName[22];
+00052   char           *buffer;
+00053   uInt32         dirBlock;
+00054   uInt32         perms;
+00055   } fileDescriptor;
+00056 
+00057 struct fileSystem {
+00058   struct fileSystem *prev;
+00059   struct fileSystem *next;
+00060   int               (*vfsInitFS)(void *);
+00061   int               (*vfsRead)(void *,char *,long,long);
+00062   int               (*vfsWrite)(void *,char *,long,long);
+00063   int               (*vfsOpenFile)(void *,void *);
+00064   int               (*vfsUnlink)(char *,void *);
+00065   int               (*vfsMakeDir)(char *,void *);
+00066   int               (*vfsRemDir)(char *);
+00067   int               (*vfsSync)(void);
+00068   int               vfsType;
+00069   };
+00070 
+00071 
+00072 /* VFS Functions */
+00073 int vfsInit();
+00074 int vfsRegisterFS(int,void *,void *,void *,void *,void *,void *,void *,void *);
+00075 struct fileSystem *vfsFindFS(int);
+00076 
+00077 
+00078 
+00079 //File IO
+00080 fileDescriptor *fopen(const char *file,const char *flags);
+00081 
+00082 
+00083 #endif
+00084 
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/vfs_8h.html b/doc/doxygen/html/vfs_8h.html new file mode 100644 index 0000000..7300dbc --- /dev/null +++ b/doc/doxygen/html/vfs_8h.html @@ -0,0 +1,452 @@ + + +Ubixos: vfs.h File Reference + + + +

vfs.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  fileDescriptorStruct
struct  fileSystem

Defines

#define maxFd   32
#define fdAvail   1
#define fdOpen   2
#define fdRead   3
#define fdEof   4
#define fileRead   0x0001
#define fileWrite   0x0002
#define fileBinary   0x0004
#define fileAppend   0x0008

Typedefs

typedef fileDescriptorStruct fileDescriptor

Functions

int vfsInit ()
int vfsRegisterFS (int, void *, void *, void *, void *, void *, void *, void *, void *)
fileSystemvfsFindFS (int)
fileDescriptorfopen (const char *file, const char *flags)
+


Define Documentation

+

+ + + + +
+ + +
#define fdAvail   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdEof   4 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdOpen   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fdRead   3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fileAppend   0x0008 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fileBinary   0x0004 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fileRead   0x0001 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define fileWrite   0x0002 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define maxFd   32 +
+
+ + + + + +
+   + + +

+

+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct fileDescriptorStruct fileDescriptor +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
fileDescriptor* fopen const char *  file,
const char *  flags
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
struct fileSystem* vfsFindFS int   ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int vfsInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
int vfsRegisterFS int ,
void * ,
void * ,
void * ,
void * ,
void * ,
void * ,
void * ,
void * 
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/video_8h-source.html b/doc/doxygen/html/video_8h-source.html new file mode 100644 index 0000000..5f32d57 --- /dev/null +++ b/doc/doxygen/html/video_8h-source.html @@ -0,0 +1,50 @@ + + +Ubixos: video.h Source File + + + +

video.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _VIDEO_H
+00025 #define _VIDEO_H
+00026 
+00027 #include <ubixos/types.h>
+00028 
+00029 #define defaultColor 0x0F
+00030 
+00031 extern int printColor;
+00032 
+00033 void clearScreen();
+00034 void kprint(char *string);
+00035 void backSpace();
+00036 
+00037 #endif
+00038 
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/video_8h.html b/doc/doxygen/html/video_8h.html new file mode 100644 index 0000000..a9777a4 --- /dev/null +++ b/doc/doxygen/html/video_8h.html @@ -0,0 +1,163 @@ + + +Ubixos: video.h File Reference + + + +

video.h File Reference

#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + +

Defines

#define defaultColor   0x0F

Functions

void clearScreen ()
void kprint (char *string)
void backSpace ()

Variables

int printColor
+


Define Documentation

+

+ + + + +
+ + +
#define defaultColor   0x0F +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void backSpace  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
void clearScreen  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void kprint char *  string  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
int printColor +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/vitals_8h-source.html b/doc/doxygen/html/vitals_8h-source.html new file mode 100644 index 0000000..0868c4f --- /dev/null +++ b/doc/doxygen/html/vitals_8h-source.html @@ -0,0 +1,63 @@ + + +Ubixos: vitals.h Source File + + + +

vitals.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _VITALS_H
+00025 #define _VITALS_H
+00026 
+00027 #include <ubixos/types.h>
+00028 #include <ubixos/ubthread.h>
+00029 #include <vfs/mount.h>
+00030 #include <vfs/vfs.h>
+00031 
+00032 typedef struct vitalsStruct {
+00033   uInt32                openFiles;
+00034   uInt32                sysTicks;
+00035   uInt32                sysUptime;
+00036   uInt32                freePages;
+00037   struct fileSystem    *fileSystems;
+00038   struct mountPoints   *mountPoints;
+00039   uInt32                timeStart;
+00040   void                 *screen;
+00041   void                 *font;
+00042   char                 *packet;
+00043   uInt32               packetLength;
+00044   } vitalsNode;
+00045 
+00046 extern vitalsNode *systemVitals;
+00047 
+00048 int initVitals();
+00049 
+00050 #endif
+00051 
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/vitals_8h.html b/doc/doxygen/html/vitals_8h.html new file mode 100644 index 0000000..24f4a06 --- /dev/null +++ b/doc/doxygen/html/vitals_8h.html @@ -0,0 +1,108 @@ + + +Ubixos: vitals.h File Reference + + + +

vitals.h File Reference

#include <ubixos/types.h>
+#include <ubixos/ubthread.h>
+#include <vfs/mount.h>
+#include <vfs/vfs.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + +

Data Structures

struct  vitalsStruct

Typedefs

typedef vitalsStruct vitalsNode

Functions

int initVitals ()

Variables

vitalsNodesystemVitals
+


Typedef Documentation

+

+ + + + +
+ + +
typedef struct vitalsStruct vitalsNode +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
int initVitals  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
vitalsNode* systemVitals +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/vmm_8h-source.html b/doc/doxygen/html/vmm_8h-source.html new file mode 100644 index 0000000..de393ca --- /dev/null +++ b/doc/doxygen/html/vmm_8h-source.html @@ -0,0 +1,67 @@ + + +Ubixos: vmm.h Source File + + + +

vmm.h

00001 /**************************************************************************************
+00002  Copyright (c) 2002 The UbixOS Project
+00003  All rights reserved.
+00004 
+00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+00006 
+00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+00011 
+00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+00019 
+00020  $Id$
+00021 
+00022 **************************************************************************************/
+00023 
+00024 #ifndef _VMM_H
+00025 #define _VMM_H
+00026 
+00027 #include <vmm/paging.h>
+00028 #include <ubixos/types.h>
+00029 
+00030 #define memAvail     1
+00031 #define memNotavail  2
+00032 #define vmmID       -3
+00033 #define vmmMemoryMapAddr 0xE6667000
+00034 
+00035 typedef struct {
+00036   uLong  pageAddr;
+00037   uShort status;
+00038   pid_t  pid;
+00039   int    cowCounter;
+00040   } mMap;
+00041 
+00042 extern mMap *vmmMemoryMap;
+00043 extern int numPages;
+00044 extern uInt32 freePages;
+00045 
+00046 int vmmInit();
+00047 int vmmMemMapInit();
+00048 int countMemory();
+00049 uInt32 vmmFindFreePage(pidType pid);
+00050 int freePage(uInt32 pageAddr);
+00051 int adjustCowCounter(uInt32 baseAddr,int adjustment);
+00052 void vmmFreeProcessPages(pidType pid);
+00053 
+00054 #endif
+00055 
+

Generated on Wed Apr 28 17:49:42 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/doxygen/html/vmm_8h.html b/doc/doxygen/html/vmm_8h.html new file mode 100644 index 0000000..59002bb --- /dev/null +++ b/doc/doxygen/html/vmm_8h.html @@ -0,0 +1,419 @@ + + +Ubixos: vmm.h File Reference + + + +

vmm.h File Reference

#include <vmm/paging.h>
+#include <ubixos/types.h>
+ +

+Go to the source code of this file. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Data Structures

struct  mMap

Defines

#define memAvail   1
#define memNotavail   2
#define vmmID   -3
#define vmmMemoryMapAddr   0xE6667000

Functions

int vmmInit ()
int vmmMemMapInit ()
int countMemory ()
uInt32 vmmFindFreePage (pidType pid)
int freePage (uInt32 pageAddr)
int adjustCowCounter (uInt32 baseAddr, int adjustment)
void vmmFreeProcessPages (pidType pid)

Variables

mMapvmmMemoryMap
int numPages
uInt32 freePages
+


Define Documentation

+

+ + + + +
+ + +
#define memAvail   1 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define memNotavail   2 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define vmmID   -3 +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
#define vmmMemoryMapAddr   0xE6667000 +
+
+ + + + + +
+   + + +

+

+


Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
int adjustCowCounter uInt32  baseAddr,
int  adjustment
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int countMemory  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
int freePage uInt32  pageAddr  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
uInt32 vmmFindFreePage pidType  pid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + + +
void vmmFreeProcessPages pidType  pid  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int vmmInit  ) 
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + + + + + + + + +
int vmmMemMapInit  ) 
+
+ + + + + +
+   + + +

+

+


Variable Documentation

+

+ + + + +
+ + +
uInt32 freePages +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
int numPages +
+
+ + + + + +
+   + + +

+

+

+ + + + +
+ + +
mMap* vmmMemoryMap +
+
+ + + + + +
+   + + +

+

+


Generated on Sat May 8 09:28:23 2004 for Ubixos by + +doxygen +1.3.3
+ + diff --git a/doc/sample_driver.c b/doc/sample_driver.c new file mode 100644 index 0000000..6c5052c --- /dev/null +++ b/doc/sample_driver.c @@ -0,0 +1,101 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/04/27 20:49:22 reddawg + Update Sample Driver + + Revision 1.1 2004/04/27 12:04:24 reddawg + Sample driver for isa interface + + + + $Id$ + +*****************************************************************************************/ + +/******************************************************** + This sample driver is good for an ISA device you can + either probe or hand set irq and ioAddr information if + ********************************************************/ + +#include + +struct devInfo { + int irq; + int ioAddr; + } + +static struct devInfo sampleInfo; + +void sampleRegister() { + int sampleMajor = 0; /* Major ID */ + int sampleMinor = 0; /* Minor ID */ + + deviceAdd(sampleMajor,sampleMinor,"c",sampleRead,sampleWrite,sampleReset,sampleInit,sampleIoctl,sampleStop,sampleStart,sampleStandby,sampleInfo) + } + + +int sampleRead(struct deviceNode *dev,void *ptr,uInt32 offset,uInt32 length) { + /* Read From Device */ + return(0); + } + +int sampleWrite(struct deviceNode *dev,void *ptr,uInt32 offset,uInt32 length) { + /* WritE to Device */ + return(0); + } + +int sampleReset(struct deviceNode *dev) { + /* Device Reset */ + return(0); + } + +int sampleInit(struct deviceNode *dev) { + /* Device Initialization */ + /* Also Set Device Size If IT Is A Character Device */ + dev->size = 1024; + return(0); + } + +int sampleIoctl(struct deviceNode *dev) { + /* Device IO Control */ + return(0); + } + +int sampleStop(struct deviceNode *dev) { + /* Stop this device */ + return(0); + } + +int sampleStart(struct deviceNode *dev) { + /* Start This Device */ + return(0); + } + +int sampleStandby(struct deviceNode *dev) { + /* Do all things needed to allow this device to go into standby mode */ + return(0); + } diff --git a/doc/vmm.txt b/doc/vmm.txt new file mode 100644 index 0000000..debb245 --- /dev/null +++ b/doc/vmm.txt @@ -0,0 +1,34 @@ +This document goes over the UbixOS VMM + + +1. Memory Layout - + + Each application has its own private 4gb memory area the first 1mb is mapped 1:1 against the systems memory and is shared between all of the proccess + on the system it include bios information video buffers and the kernel code. + + From 0x100000 - 3gb this memory region is available for the task itself for its code data and anything else it may need it for + + The top 1gb is reserved and shared across every application this is the os memory region not readable by the application unless it is in a syscall + + at 0x100000 the applications page directory is stored and page 0x768 is all the pagetable listed in the page dir specified at 0x100000 + +2. Functions - + + vmmInit: + This function initializes our memory map and paging system if either fail this returns a failure. + + vmmMemMapInit: + This initializes our memory map, it is a linked list of available pages it keeps track of COW (copy on write) as well as ownership and status + + vmmPagingInit: + This initializes our paging system sets up default memory area for kernel and remaps the memory map into the top 1GB this builds the memory foundation + for each application to follow + + vmmCreateVirtualSpace: + This creates a new virtual space for a process it takes on arg pidType pid and returns the base address of the new page directory + This has the shared lower 1 mb and top 1GB everything inbetween is available for the process + + vmmCopyVirtualSpace: + This copies the current virtual space for the process specified by the arg pidType pid passed in. This copy sets all the pages for 2mb -3gb COW and no + memory is physically copied when the program attempts to write to this region a page fault happens then the memory is physically copied + diff --git a/src/Makefile.inc b/src/Makefile.inc new file mode 100644 index 0000000..8a14d34 --- /dev/null +++ b/src/Makefile.inc @@ -0,0 +1,10 @@ +# $Id$ +# Global 'Source' Options + +# allow you to change your default compiler without affecting your other work +CC = gcc295 +CXX = g++295 +LD = ld +AR = ar +REMOVE = rm -rf + diff --git a/src/README b/src/README new file mode 100644 index 0000000..ed58e06 --- /dev/null +++ b/src/README @@ -0,0 +1,7 @@ +Directory Structure: + + bin - Applications for UbixOS + include - Include files to build anything userland + lib - Userland libraries + sys - Kernel code + tools - Tool kit required to build and install UbixOS \ No newline at end of file diff --git a/src/bin/Makefile b/src/bin/Makefile new file mode 100644 index 0000000..e279384 --- /dev/null +++ b/src/bin/Makefile @@ -0,0 +1,77 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +all: init-bin login-bin shell-bin ls-bin clock-bin cp-bin fdisk-bin format-bin disklabel-bin ubistry-bin edit-bin ld-bin +# test-bin pwd-bin cat-bin de-bin goofball-bin + +init-bin: init + (cd init;make) + +login-bin: login + (cd login;make) + +shell-bin: shell + (cd shell;make) + +test-bin: test + (cd test;make) + +ls-bin: ls + (cd ls;make) + +pwd-bin: pwd + (cd pwd;make) + +cat-bin: cat + (cd cat;make) + +ld-bin: ld + (cd ld;make) + +de-bin: de + (cd de;make) + +muffin-bin: muffin + (cd muffin;make) + +goofball-bin: goofball + (cd goofball;make) + +clock-bin: clock + (cd clock;make) + +fdisk-bin: fdisk + (cd fdisk;make) + +cp-bin: cp + (cd cp;make) + +format-bin: format + (cd format;make) + +disklabel-bin: disklabel + (cd disklabel;make) + +launcher-bin: launcher + (cd launcher;make) + +ubistry-bin: ubistry + (cd ubistry;make) + +edit-bin: edit + (cd edit;make) + +clean: + (cd cp;make clean) + (cd fdisk;make clean) + (cd init;make clean) + (cd shell;make clean) + (cd ls;make clean) + (cd login;make clean) + (cd clock;make clean) + (cd muffin;make clean) + (cd format;make clean) + (cd disklabel;make clean) + (cd ubistry;make clean) + (cd ld;make clean) + (cd edit;make clean) diff --git a/src/bin/Makefile.inc b/src/bin/Makefile.inc new file mode 100644 index 0000000..23cac6f --- /dev/null +++ b/src/bin/Makefile.inc @@ -0,0 +1,7 @@ +# 'bin' options + +CFLAGS = -nostdlib -nostdinc -fomit-frame-pointer + +INCLUDES = -I../../include + +LIBRARIES = ../../lib/libc/math/*.o ../../lib/libc/quad/*.o ../../lib/libc/stdio/*.o ../../lib/libc/stdlib/*.o ../../lib/libc/sys/*.o ../../lib/libc/string/*.o ../../lib/libc/locale/*.o ../../lib/libc/gen/*.o ../../lib/libc/generic/*.o diff --git a/src/bin/clock/Makefile b/src/bin/clock/Makefile new file mode 100644 index 0000000..411bc55 --- /dev/null +++ b/src/bin/clock/Makefile @@ -0,0 +1,51 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = clock + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/clock/main.c b/src/bin/clock/main.c new file mode 100644 index 0000000..5cacd66 --- /dev/null +++ b/src/bin/clock/main.c @@ -0,0 +1,116 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +void print2(char *string,int,int); + +#define MINUTE 60 +#define HOUR (60*MINUTE) +#define DAY (24*HOUR) +#define YEAR (365*DAY) + + +static int monthSecs[12] = { + 0, + DAY*(31), + DAY*(31+29), + DAY*(31+29+31), + DAY*(31+29+31+30), + DAY*(31+29+31+30+31), + DAY*(31+29+31+30+31+30), + DAY*(31+29+31+30+31+30+31), + DAY*(31+29+31+30+31+30+31+31), + DAY*(31+29+31+30+31+30+31+31+30), + DAY*(31+29+31+30+31+30+31+31+30+31), + DAY*(31+29+31+30+31+30+31+31+30+31+30) +}; + +int main(int argc,char **argv) { + int sysTime = 0x0; + int i = 0x0; + + int year = 0x0; + int month = 0x0; + int day = 0x0; + int hour = 0x0; + int min = 0x0; + int sec = 0x0; + + sysTime = gettime(); + + year = (sysTime/YEAR) + 1970; + sysTime -= (YEAR * (year-1970)); + sysTime -= DAY*(((year-1970)+1)/4); + for (i = 11;i >= 0;i--) { + if ((sysTime - monthSecs[i]) > 0) { + month = i; + break; + } + } + sysTime -= monthSecs[i]; + if (((month > 1) && (((year-1970)+2)%4)) == 0x0) { + sysTime += DAY; + } + + day = (sysTime/DAY); + sysTime -= (day*DAY); + hour = (sysTime/HOUR); + sysTime -= (hour*HOUR); + min = (sysTime/MINUTE); + sysTime -= (min*MINUTE); + sec = sysTime; + + printf("[%02d/%02d/%i, %02d:%02d.%02d]\n",month,day,year,hour,min,sec); + return(0); + } + +/*** + $Log$ + Revision 1.6 2004/06/13 03:05:15 reddawg + we now have a dynamic linker + + Revision 1.5 2004/06/12 01:32:03 reddawg + clock: first so test program + + Revision 1.4 2004/06/04 16:15:14 reddawg + shell: fixed a segfault bug comparing a null pointer + clock: prints correct time now + login: fixed a pointer conversion + + Revision 1.3 2004/05/21 15:45:36 reddawg + Fixed our clock to print the time instead of forcing it into the video buffer + + + END + ***/ + diff --git a/src/bin/cp/Makefile b/src/bin/cp/Makefile new file mode 100644 index 0000000..8f6dc57 --- /dev/null +++ b/src/bin/cp/Makefile @@ -0,0 +1,48 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = cp + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/cp/main.c b/src/bin/cp/main.c new file mode 100644 index 0000000..240292d --- /dev/null +++ b/src/bin/cp/main.c @@ -0,0 +1,59 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +int main(int argc,char **argv) { + int i = 0x0; + char *buffer = (char *)malloc(0x2000); + FILE *in = 0x0; + FILE *out = 0x0; + in = fopen(argv[1],"rb"); + out = fopen(argv[2],"wb"); + /* + while (!feof(in)) { + */ + for (i=0;i<21;i++) { + fread(buffer,0x1000,1,in); + fwrite(buffer,0x1000,1,out); + } + fclose(in); + fclose(out); + return(0x0); + } + +/*** + $Log$ + Revision 1.3 2004/05/24 13:40:35 reddawg + Clean Up + + + END + ***/ diff --git a/src/bin/disklabel/Makefile b/src/bin/disklabel/Makefile new file mode 100644 index 0000000..41d3422 --- /dev/null +++ b/src/bin/disklabel/Makefile @@ -0,0 +1,49 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = disklabel + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/disklabel/main.c b/src/bin/disklabel/main.c new file mode 100644 index 0000000..b9c58cc --- /dev/null +++ b/src/bin/disklabel/main.c @@ -0,0 +1,111 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +#include "ubixfs.h" + + +int main(int argc,char **argv) { + FILE *fd; + struct ubixDiskLabel *d = (struct ubixDiskLabel *)malloc(512); + int i = 0x0; + char buf[256]; + + printf("Ubix Disk Label Editor Version 1.0\n"); + printf("(c) 2004 Ubix Corp \n\n"); + + if (argc >= 2) { + printf("Drive Info (%s):\n",argv[1]); + fd = fopen(argv[1],"rb"); + } + else { + printf("Drive Info (hd0):\n"); + fd = fopen("hd0@devfs","rb"); + } + fseek(fd,512,0); + fread(d,512,1,fd); + + if (argc >= 3) { + i = atoi(argv[2]); + printf("d->partitions[%i].p_size = %i, ",i,d->partitions[i].p_size); + printf("New Value: "); + gets((char *)&buf); + d->partitions[i].p_size = atoi(buf); + printf("d->partitions[%i].p_offset = %i, ",i,d->partitions[i].p_offset); + printf("New Value: "); + gets((char *)&buf); + d->partitions[i].p_offset = atoi(buf); + printf("d->partitions[%i].p_fstype = %i, ",i,d->partitions[i].p_fstype); + printf("New Value: "); + gets((char *)&buf); + d->partitions[i].p_fstype = atoi(buf); + printf("d->partitions[%i].p_bsize = %i, ",i,d->partitions[i].p_bsize); + printf("New Value: "); + gets((char *)&buf); + d->partitions[i].p_bsize = atoi(buf); + printf("\n"); + printf("d->partitions[%i].p_size = %i\n",i,d->partitions[i].p_size); + printf("d->partitions[%i].p_offset = %i\n",i,d->partitions[i].p_offset); + printf("d->partitions[%i].p_fstype = %i\n",i,d->partitions[i].p_fstype); + printf("d->partitions[%i].p_bsize = %i\n",i,d->partitions[i].p_bsize); + fseek(fd,512,0); + fwrite(d,512,1,fd); + } + else { + for (i=0;i<4;i++) { + if (d->partitions[i].p_fstype != 0x0) { + printf("d->partitions[%i].p_size = %i\n",i,d->partitions[i].p_size); + printf("d->partitions[%i].p_offset = %i\n",i,d->partitions[i].p_offset); + printf("d->partitions[%i].p_fstype = 0x%X\n",i,d->partitions[i].p_fstype); + printf("d->partitions[%i].p_bsize = 0x%X\n",i,d->partitions[i].p_bsize); + } + } + } + + fclose(fd); + + return(0); + } + +/*** + $Log$ + Revision 1.3 2004/06/01 01:30:43 reddawg + No more warnings and organized make files + + Revision 1.2 2004/05/24 13:42:29 reddawg + Clean Up + + + END + ***/ diff --git a/src/bin/disklabel/ubixfs.h b/src/bin/disklabel/ubixfs.h new file mode 100644 index 0000000..d0525bf --- /dev/null +++ b/src/bin/disklabel/ubixfs.h @@ -0,0 +1,80 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +#define DOSPTYP_UBX 0x2A /* UbixFS partition type */ +#define UBIXDISKMAGIC ((uInt32)0x45) /* The disk magic number */ +#define MAXUBIXPARTITIONS 16 +#define UBIXFSMAGIC ((uInt32)0x69) /* The File System Magic Number */ + +struct ubixDiskLabel { + uInt32 magicNum; + uInt32 magicNum2; + uInt16 driveType; + uInt16 numPartitions; + struct ubixPartitions { /* the partition table */ + uInt32 p_size; /* number of sectors in partition */ + uInt32 p_offset; /* starting sector */ + uInt32 p_fsize; /* filesystem basic fragment size */ + uInt32 p_bsize; /* BAT size */ + uInt8 p_fstype; /* filesystem type, see below */ + uInt8 p_frag; /* filesystem fragments per block */ + } partitions[MAXUBIXPARTITIONS]; + }; + +//Block Allocation Table Entry +struct blockAllocationTableEntry { + long attributes; //Block Attributes + long realSector; //Real Sector + long nextBlock; //Sector Of Next Block + long reserved; //Reserved + }; + + +struct directoryEntry { + uLong startCluster; //Starting Cluster Of File + uLong size; //Size Of File + uLong creationDate; //Date Created + uLong lastModified; //Date Last Modified + uLong uid; //UID Of Owner + uLong gid; //GID Of Owner + uShort attributes; //Files Attributes + uShort permissions; //Files Permissions + char fileName[256]; //File Name + }; + +/*** + $Log$ + Revision 1.2 2004/05/24 13:42:29 reddawg + Clean Up + + + END + ***/ diff --git a/src/bin/edit/Makefile b/src/bin/edit/Makefile new file mode 100644 index 0000000..319a799 --- /dev/null +++ b/src/bin/edit/Makefile @@ -0,0 +1,48 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = init + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/edit/main.c b/src/bin/edit/main.c new file mode 100644 index 0000000..be72071 --- /dev/null +++ b/src/bin/edit/main.c @@ -0,0 +1,43 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +int main(int argc,char **argv) { + printf("UbixOS Text Editor\n"); + return(0); + } + +/*** + $Log$ + Revision 1.1 2004/06/04 17:58:03 reddawg + Start of a text editor if i can pull this off there is no holding us back + + END + ***/ diff --git a/src/bin/fdisk/Makefile b/src/bin/fdisk/Makefile new file mode 100644 index 0000000..4a890bc --- /dev/null +++ b/src/bin/fdisk/Makefile @@ -0,0 +1,48 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = fdisk + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/fdisk/main.c b/src/bin/fdisk/main.c new file mode 100644 index 0000000..de8f123 --- /dev/null +++ b/src/bin/fdisk/main.c @@ -0,0 +1,130 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +#include "ubixfs.h" + +struct dos_partition { + unsigned char dp_flag; /* bootstrap flags */ + unsigned char dp_shd; /* starting head */ + unsigned char dp_ssect; /* starting sector */ + unsigned char dp_scyl; /* starting cylinder */ + unsigned char dp_type; /* partition type */ + unsigned char dp_ehd; /* end head */ + unsigned char dp_esect; /* end sector */ + unsigned char dp_ecyl; /* end cylinder */ + uInt32 dp_start; /* absolute starting sector number */ + uInt32 dp_size; /* partition size in sectors */ +}; + + +int main(int argc,char **argv) { + FILE *fd; + FILE *mbr; + struct dos_partition *d = 0x0; + char *data = (char *)malloc(512); + int i = 0x0; + char buf[256]; + + d = (struct dos_partition *)(data + 0x1BE); + + printf("Ubix Disk Editor Version 1.0\n"); + printf("(c) 2004 Ubix Corp \n\n"); + + if (argc >= 2) { + printf("Drive Info (%s):\n",argv[1]); + fd = fopen(argv[1],"rb"); + } + else { + printf("Drive Info (ad0):\n"); + fd = fopen("ad0@devfs","rb"); + } + fseek(fd,0,0); + fread(data,512,1,fd); + + if (argc >= 3) { + i = atoi(argv[2]); + if (i == 0) { + mbr = fopen("mbr@sys","rb"); + fseek(mbr,0,0); + fread(data,512,1,mbr); + printf("Installing Ubix MBR\n"); + } + else { + i--; + printf("d[%i].dp_type = %i, ",i,d[i].dp_type); + printf("New Value: "); + gets((char *)&buf); + d[i].dp_type = atoi(buf); + printf("d[%i].dp_start: %i, ",i,d[i].dp_start); + printf("New Value: "); + gets((char *)&buf); + d[i].dp_start = atoi(buf); + printf("d[%i].dp_size: %i, ",i,d[i].dp_size); + printf("New Value: "); + gets((char *)&buf); + d[i].dp_size = atoi(buf); + printf("d[%i].dp_type: 0x%X\n",i,d[i].dp_type); + printf("d[%i].dp_start: %i\n",i,d[i].dp_start); + printf("d[%i].dp_size: %i\n",i,d[i].dp_size); + } + fseek(fd,0,0); + fwrite(data,512,1,fd); + } + else { + for (i=0;i<4;i++) { + if (d[i].dp_type != 0x0) { + printf("d[%i].dp_type: 0x%X\n",i,d[i].dp_type); + printf("d[%i].dp_start: %i\n",i,d[i].dp_start); + printf("d[%i].dp_size: %i\n",i,d[i].dp_size); + } + } + } + + fclose(fd); + + return(0); + } + +/*** + $Log$ + Revision 1.8 2004/06/01 01:30:43 reddawg + No more warnings and organized make files + + Revision 1.7 2004/05/24 13:54:52 reddawg + Clean Up + + + END + ***/ diff --git a/src/bin/fdisk/ubixfs.h b/src/bin/fdisk/ubixfs.h new file mode 100644 index 0000000..e6554ae --- /dev/null +++ b/src/bin/fdisk/ubixfs.h @@ -0,0 +1,80 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +#define DOSPTYP_UBX 0x2A /* UbixFS partition type */ +#define UBIXDISKMAGIC ((uInt32)0x45) /* The disk magic number */ +#define MAXUBIXPARTITIONS 16 +#define UBIXFSMAGIC ((uInt32)0x69) /* The File System Magic Number */ + +struct ubixDiskLabel { + uInt32 magicNum; + uInt32 magicNum2; + uInt16 driveType; + uInt16 numPartitions; + struct ubixPartitions { /* the partition table */ + uInt32 p_size; /* number of sectors in partition */ + uInt32 p_offset; /* starting sector */ + uInt32 p_fsize; /* filesystem basic fragment size */ + uInt32 p_bsize; /* BAT size */ + uInt8 p_fstype; /* filesystem type, see below */ + uInt8 p_frag; /* filesystem fragments per block */ + } partitions[MAXUBIXPARTITIONS]; + }; + +//Block Allocation Table Entry +struct blockAllocationTableEntry { + long attributes; //Block Attributes + long realSector; //Real Sector + long nextBlock; //Sector Of Next Block + long reserved; //Reserved + }; + + +struct directoryEntry { + uLong startCluster; //Starting Cluster Of File + uLong size; //Size Of File + uLong creationDate; //Date Created + uLong lastModified; //Date Last Modified + uLong uid; //UID Of Owner + uLong gid; //GID Of Owner + uShort attributes; //Files Attributes + uShort permissions; //Files Permissions + char fileName[256]; //File Name + }; + +/*** + $Log$ + Revision 1.2 2004/05/24 13:54:52 reddawg + Clean Up + + + END + ***/ diff --git a/src/bin/format/Makefile b/src/bin/format/Makefile new file mode 100644 index 0000000..d7e4329 --- /dev/null +++ b/src/bin/format/Makefile @@ -0,0 +1,48 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = format + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/format/main.c b/src/bin/format/main.c new file mode 100644 index 0000000..657d78e --- /dev/null +++ b/src/bin/format/main.c @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + + +int main(int argc,char **argv) { + printf("UbixOS Format V1.0\n"); + return(0); + } + +/*** + $Log$ + Revision 1.4 2004/06/01 01:30:43 reddawg + No more warnings and organized make files + + Revision 1.3 2004/05/24 14:09:20 reddawg + Clean Up + + + END + ***/ diff --git a/src/bin/init/Makefile b/src/bin/init/Makefile new file mode 100644 index 0000000..c7b32a8 --- /dev/null +++ b/src/bin/init/Makefile @@ -0,0 +1,48 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = init + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +#LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/init/main.c b/src/bin/init/main.c new file mode 100644 index 0000000..e905e3c --- /dev/null +++ b/src/bin/init/main.c @@ -0,0 +1,134 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +int main(int argc,char **argv) { + int i=0; + mpiMessage_t myMsg; + + /* Create a mailbox for this task */ + if (mpiCreateMbox("init") != 0x0) { + printf("Error: Error Creating Mail Box\n"); + exit(-1); + } + + /* Make sure we have superuser permissions if not exit */ + if ((getuid() != 0) && (getgid() != 0)) { + printf("Error: This program must be run by root.\n"); + exit(-1); + } + + /* Start the SDE(SCreen Drawing Engine) */ + //startSDE(); + + printf("Initializing System.\n"); + + i = fork(); + if (0 == i) { + printf("Starting Ubix Registry (ubistry)\n"); + exec("ubistry@sys",0x0,0x0); + printf("Error: Error Starting ubistry\n"); + exit(-1); + } + while (pidStatus(i) > 0x0) { + sched_yield(); + } + + startup: + i = fork(); + if (0 == i) { + printf("Starting Login Daemon.\n"); + exec("login@sys",0x0,0x0); + printf("Error Starting System\n"); + exit(-1); + } + else { + while (pidStatus(i) > 0x0) { + fetchAgain: + if (mpiFetchMessage("init",&myMsg) == 0x0) { + switch (myMsg.type) { + case 10: + printf("Exec: (%s)\n",myMsg.data); + break; + default: + printf("MailBox: init Received Message %i:%s\n",myMsg.type,myMsg.data); + break; + } + goto fetchAgain; + } + sched_yield(); + } + goto startup; + } + return(0); + } + +/*** + $Log$ + Revision 1.11 2004/06/04 13:29:56 reddawg + libc: modified mkdir(); interface + kpanic: kPanic(); now says kPanic: %s + system: now reboots when receives message for reboot + also when command start sde is received by system the STD is started + + Revision 1.10 2004/05/26 13:11:41 reddawg + Makefile: adjust all the Makefile to strip binaries to conserve floppy space + + Revision 1.9 2004/05/26 12:19:19 reddawg + init: init now starts the ubix registry system + + Revision 1.8 2004/05/25 22:44:59 reddawg + Test code + + Revision 1.7 2004/05/25 22:32:58 reddawg + We turned back on GUI + + Revision 1.6 2004/05/25 18:38:00 reddawg + The system INIT task now responds to messages it is the root process for the OS + + Revision 1.5 2004/05/25 15:43:44 reddawg + Tests for MPI + + Revision 1.4 2004/05/23 23:40:37 reddawg + Cleanup + + Revision 1.3 2004/05/21 21:15:56 reddawg + Cleaned up initialized program + + Revision 1.2 2004/05/21 15:43:58 reddawg + Fixed the the bootup ordering in userland initialization + + END + ***/ diff --git a/src/bin/launcher/Makefile b/src/bin/launcher/Makefile new file mode 100644 index 0000000..78193bd --- /dev/null +++ b/src/bin/launcher/Makefile @@ -0,0 +1,53 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +INCLUDES += -I./include -I../../lib/views/sunlight/include -I../../lib/libcpp/include -I../../lib/objgfx40/objgfx40 +CFLAGS = -nostdlib -fno-exceptions -frtti +LIBRARIES += ../../lib/libstdc++/*.o + +#Linker +LD = ld + +#Binary File Name +BINARY = launcher + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = launcher.o ubixButton.o ubixDesktop.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/launcher/include/ubixButton.h b/src/bin/launcher/include/ubixButton.h new file mode 100644 index 0000000..34ee379 --- /dev/null +++ b/src/bin/launcher/include/ubixButton.h @@ -0,0 +1,13 @@ +#ifndef UBIXBUTTON_H +#define UBIXBUTTON_H + +#include + +class ubixButton : public vButton { + public: + ubixButton(vContext *); +// virtual bool vCreate(void); + virtual void vDraw(void); + virtual ~ubixButton(void); +}; // ubixButton +#endif diff --git a/src/bin/launcher/include/ubixDesktop.h b/src/bin/launcher/include/ubixDesktop.h new file mode 100644 index 0000000..61a1a38 --- /dev/null +++ b/src/bin/launcher/include/ubixDesktop.h @@ -0,0 +1,14 @@ +#ifndef UBIXDESKTOP_H +#define UBIXDESKTOP_H + +#include + +class ubixDesktop : public vContext { + protected: + public: + ubixDesktop(vContext *); + virtual bool vCreate(void); + virtual void vDraw(void); + virtual ~ubixDesktop(void); +}; // ubixDesktop +#endif diff --git a/src/bin/launcher/launcher.cpp b/src/bin/launcher/launcher.cpp new file mode 100644 index 0000000..db6cd82 --- /dev/null +++ b/src/bin/launcher/launcher.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +int +main(void) { + ubixDesktop * desktop = new ubixDesktop(NULL); + ubixButton * daButton = new ubixButton(desktop); + desktop->vCreate(); + daButton->vCreate(); + delete daButton; + delete desktop; + + return 0; +} diff --git a/src/bin/launcher/ubixButton.cpp b/src/bin/launcher/ubixButton.cpp new file mode 100644 index 0000000..f74f65c --- /dev/null +++ b/src/bin/launcher/ubixButton.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +ubixButton::ubixButton(vContext * parent) : vButton(parent) { + vSetSize(48, 48); + vSetPos(0, 600-vGetHeight()); + vSetStyle("default.button.border.size", new sSize(0)); + return; +} // ubixButton::ubixButton() + +void +ubixButton::vDraw(void) { + return; +} // ubixButton::vDraw() + +ubixButton::~ubixButton(void) { + return; +} // ubixButton::~ubixButton() diff --git a/src/bin/launcher/ubixDesktop.cpp b/src/bin/launcher/ubixDesktop.cpp new file mode 100644 index 0000000..c9afad0 --- /dev/null +++ b/src/bin/launcher/ubixDesktop.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +ubixDesktop::ubixDesktop(vContext * parent) : vContext(parent) { + vSetStyle("default.button.border.size", new sSize(2)); + vSetStyle("default.font.filename", new sString("ROM8X14.DPF")); + vSetStyle("default.font.color.foreground", + new sRGBA8Color(255, 255, 255, 255)); + vSetStyle("default.font.color.background", + new sRGBA8Color(0, 0, 0, 255)); + vSetStyle("default.desktop.pixelformat", + new sPixelFormat(16, 11,5,0,0, 5,6,5,0)); + return; +} // ubixDesktop::ubixDesktop + +bool +ubixDesktop::vCreate(void) { + return true; +} // ubixDesktop::vCreate + +void +ubixDesktop::vDraw(void) { + return; +} // ubixDesktop::vDraw + +ubixDesktop::~ubixDesktop(void) { + return; +} diff --git a/src/bin/ld/Makefile b/src/bin/ld/Makefile new file mode 100644 index 0000000..fbb3395 --- /dev/null +++ b/src/bin/ld/Makefile @@ -0,0 +1,49 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +OUTPUT = ld.so + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o findlibrary.o findfunc.o addlibrary.o entry.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +# Link The Binary +$(OUTPUT) : $(OBJS) + $(CC) -nostdlib -shared -Wl,-soname,$(OUTPUT) -e _ld -o $(OUTPUT) $(OBJS) $(LIBRARIES) $(SUBS) + strip $(OUTPUT) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/bin/ld/addlibrary.c b/src/bin/ld/addlibrary.c new file mode 100644 index 0000000..698fd55 --- /dev/null +++ b/src/bin/ld/addlibrary.c @@ -0,0 +1,121 @@ +#include +#include +#include "ld.h" + +ldLibrary *ldAddLibrary(const char *lib) { + int i = 0x0; + int x = 0x0; + int rel = 0x0; + uInt32 *reMap = 0x0; + char *newLoc = 0x0; + FILE *linkerFd = 0x0; + ldLibrary *tmpLib = 0x0; + + tmpLib = (ldLibrary *)malloc(sizeof(ldLibrary)); + + if (tmpLib->output == 0x0) { + linkerFd = fopen(lib,"rb"); + if (linkerFd == 0x0) { + printf("Cant Open Library: %s\n",lib); + exit(-1); + } + tmpLib->output = (char *)malloc((linkerFd->size+0x4000)); + sprintf(tmpLib->name,lib); + } + + if (tmpLib->linkerHeader == 0x0) { + fseek(linkerFd,0x0,0x0); + tmpLib->linkerHeader = (elfHeader *)malloc(sizeof(elfHeader)); + fread(tmpLib->linkerHeader,sizeof(elfHeader),1,linkerFd); + } + + if (tmpLib->linkerProgramHeader == 0x0) { + tmpLib->linkerProgramHeader = (elfProgramHeader *)malloc(sizeof(elfProgramHeader)*tmpLib->linkerHeader->ePhnum); + fseek(linkerFd,tmpLib->linkerHeader->ePhoff,0); + fread(tmpLib->linkerProgramHeader,sizeof(elfProgramHeader),tmpLib->linkerHeader->ePhnum,linkerFd); + + for (i=0;ilinkerHeader->ePhnum;i++) { + switch (tmpLib->linkerProgramHeader[i].phType) { + case 1: + case 2: + newLoc = (char *)tmpLib->linkerProgramHeader[i].phVaddr + (uInt32)tmpLib->output; + fseek(linkerFd,tmpLib->linkerProgramHeader[i].phOffset,0); + fread(newLoc,tmpLib->linkerProgramHeader[i].phFilesz,1,linkerFd); + break; + default: + printf("Unhandled Header\n"); + break; + } + } + } + + if (tmpLib->linkerSectionHeader == 0x0) { + tmpLib->linkerSectionHeader = (elfSectionHeader *)malloc(sizeof(elfSectionHeader)*tmpLib->linkerHeader->eShnum); + fseek(linkerFd,tmpLib->linkerHeader->eShoff,0); + fread(tmpLib->linkerSectionHeader,sizeof(elfSectionHeader),tmpLib->linkerHeader->eShnum,linkerFd); + + if (tmpLib->linkerShStr == 0x0) { + tmpLib->linkerShStr = (char *)malloc(tmpLib->linkerSectionHeader[tmpLib->linkerHeader->eShstrndx].shSize); + fseek(linkerFd,tmpLib->linkerSectionHeader[tmpLib->linkerHeader->eShstrndx].shOffset,0); + fread(tmpLib->linkerShStr,tmpLib->linkerSectionHeader[tmpLib->linkerHeader->eShstrndx].shSize,1,linkerFd); + } + + for (i=0x0;ilinkerHeader->eShnum;i++) { + switch (tmpLib->linkerSectionHeader[i].shType) { + case 3: + if (!strcmp((tmpLib->linkerShStr + tmpLib->linkerSectionHeader[i].shName),".dynstr")) { + if (tmpLib->linkerDynStr == 0x0) { + tmpLib->linkerDynStr = (char *)malloc(tmpLib->linkerSectionHeader[i].shSize); + fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0); + fread(tmpLib->linkerDynStr,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); + } + } + break; + case 9: + tmpLib->linkerElfRel = (elfPltInfo *)malloc(tmpLib->linkerSectionHeader[i].shSize); + fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0x0); + fread(tmpLib->linkerElfRel,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); + + for (x=0x0;xlinkerSectionHeader[i].shSize/sizeof(elfPltInfo);x++) { + rel = ELF32_R_SYM(tmpLib->linkerElfRel[x].pltInfo); + reMap = (uInt32 *)((uInt32)tmpLib->output + tmpLib->linkerElfRel[x].pltOffset); + switch (ELF32_R_TYPE(tmpLib->linkerElfRel[x].pltInfo)) { + case R_386_32: + *reMap += ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue); + break; + case R_386_PC32: + *reMap += ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue) - (uInt32)reMap; + break; + case R_386_RELATIVE: + *reMap += (uInt32)tmpLib->output; + break; + default: + printf("Unhandled sym\n"); + break; + } + } + free(tmpLib->linkerElfRel); + break; + case 11: + if (tmpLib->linkerRelSymTab == 0x0) { + tmpLib->linkerRelSymTab = (elfDynSym *)malloc(tmpLib->linkerSectionHeader[i].shSize); + fseek(linkerFd,tmpLib->linkerSectionHeader[i].shOffset,0); + fread(tmpLib->linkerRelSymTab,tmpLib->linkerSectionHeader[i].shSize,1,linkerFd); + tmpLib->sym = i; + } + break; + } + } + } + + libs->prev = tmpLib; + tmpLib->prev = 0x0; + tmpLib->next = libs; + libs = tmpLib; + + if (linkerFd) { + fclose(linkerFd); + } + + return(tmpLib); + } diff --git a/src/bin/ld/elf.h b/src/bin/ld/elf.h new file mode 100644 index 0000000..0d2c17b --- /dev/null +++ b/src/bin/ld/elf.h @@ -0,0 +1,146 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _ELF_H +#define _ELF_H + +#include + +#define elfExecutable 0x002 +#define elfLibrary 0x003 + +#define R_386_NONE 0 /* none none */ +#define R_386_32 1 /* word32 S + A */ +#define R_386_PC32 2 /* word32 S + A - P */ +#define R_386_GOT32 3 /* word32 G + A - P */ +#define R_386_PLT32 4 /* word32 L + A - P */ +#define R_386_COPY 5 /* none none */ +#define R_386_GLOB_DAT 6 /* word32 S */ +#define R_386_JMP_SLOT 7 /* word32 S */ +#define R_386_RELATIVE 8 /* word32 B + A */ +#define R_386_GOTOFF 9 /* word32 S + A - GOT */ +#define R_386_GOTPC 10 /* word32 GOT + A - P */ + + +/* Elf Types */ +#define ET_NONE 0 // No file type +#define ET_REL 1 // Relocatable file +#define ET_EXEC 2 // Executable file +#define ET_DYN 3 // Shared object file +#define ET_CORE 4 // Core file +#define ET_LOPROC 0xff00 // Processor-specific +#define ET_HIPROC 0xffff +/* End Elf Types */ + +/* Elf Machine Types */ +#define EM_NONE 0 // No machine +#define EM_M32 1 // AT&T WE 32100 +#define EM_SPARC 2 // SPARC +#define EM_386 3 // Intel 80386 +#define EM_68K 4 // Motorola 68000 +#define EM_88K 5 // Motorola 88000 +#define EM_860 7 // Intel 80860 +#define EM_MIPS 8 // MIPS RS3000 +/* End Elf Machines Types */ + +/* Elf Version */ +#define EV_NONE 0 // Invalid version +#define EV_CURRENT 1 // Current version +/* End Elf Version */ + +/* Elf Program Header Types */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +/* End Elf Program Header Types */ + +typedef struct { + uInt8 eIdent[16]; /* File identification. */ + uInt16 eType; /* File type. */ + uInt16 eMachine; /* Machine architecture. */ + uInt32 eVersion; /* ELF format version. */ + uInt32 eEntry; /* Entry point. */ + uInt32 ePhoff; /* Program Header file offset. */ + uInt32 eShoff; /* Section header file offset. */ + uInt32 eFlags; /* Architecture-specific flags. */ + uInt16 eEhsize; /* Size of ELF header in bytes. */ + uInt16 ePhentsize; /* Size of program header entry. */ + uInt16 ePhnum; /* Number of program header entries. */ + uInt16 eShentsize; /* Size of section header entry. */ + uInt16 eShnum; /* Number of section header entries. */ + uInt16 eShstrndx; /* Section name strings section. */ + } elfHeader; + +typedef struct { + uInt32 phType; /* Entry type. */ + uInt32 phOffset; /* File offset of contents. */ + uInt32 phVaddr; /* Virtual address in memory image. */ + uInt32 phPaddr; /* Physical address (not used). */ + uInt32 phFilesz; /* Size of contents in file. */ + uInt32 phMemsz; /* Size of contents in memory. */ + uInt32 phFlags; /* Access permission flags. */ + uInt32 phAlign; /* Alignment in memory and file. */ + } elfProgramHeader; + +typedef struct { + uInt32 shName; /* Section name (index into the section header string table). */ + uInt32 shType; /* Section type. */ + uInt32 shFlags; /* Section flags. */ + uInt32 shAddr; /* Address in memory image. */ + uInt32 shOffset; /* Offset in file. */ + uInt32 shSize; /* Size in bytes. */ + uInt32 shLink; /* Index of a related section. */ + uInt32 shInfo; /* Depends on section type. */ + uInt32 shAddralign; /* Alignment in bytes. */ + uInt32 shEntsize; /* Size of each entry in section. */ + } elfSectionHeader; + +typedef struct { + uInt32 pltOffset; + uInt32 pltInfo; + } elfPltInfo; + +typedef struct { + uInt32 dynName; + uInt32 dynValue; + uInt32 dynSize; + uInt8 dynInfo; + uInt8 dynOther; + uInt16 dynShndx; + } elfDynSym; + +typedef struct { + uInt32 dynVal; + uInt32 dynPtr; + } elfDynamic; + +char *elfGetShType(int); +char *elfGetPhType(int); +char *elfGetRelType(int); + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s, t) ((s)<<8+(unsigned char)(t)) + +#endif + diff --git a/src/bin/ld/entry.S b/src/bin/ld/entry.S new file mode 100644 index 0000000..435ba55 --- /dev/null +++ b/src/bin/ld/entry.S @@ -0,0 +1,48 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +.globl _ld +.text +.code32 + +_ld: + call ld + add $8,%esp + push %eax + ret + +/*** + $Log$ + Revision 1.1 2004/06/17 11:58:10 reddawg + ld.so: Made a few changes to the way it functions hopefully it will + improve some of its performance. + + END + ***/ + diff --git a/src/bin/ld/findfunc.c b/src/bin/ld/findfunc.c new file mode 100644 index 0000000..74794ee --- /dev/null +++ b/src/bin/ld/findfunc.c @@ -0,0 +1,24 @@ +#include +#include +#include "ld.h" + +uInt32 ldFindFunc(const char *func,const char *lib) { + int i = 0x0; + uInt32 *funcPtr = 0x0; + ldLibrary *libPtr = 0x0; + + libPtr = ldFindLibrary(lib); + if (libPtr == 0x0) { + libPtr = ldAddLibrary(lib); + } + + for (i=0x0;ilinkerSectionHeader[libPtr->sym].shSize/sizeof(elfDynSym);i++) { + if (!strcmp(func,(libPtr->linkerDynStr + libPtr->linkerRelSymTab[i].dynName))) { + funcPtr = (uInt32 *)((uInt32)(libPtr->linkerRelSymTab[i].dynValue) + (uInt32)libPtr->output); + break; + } + } + + return((uInt32)funcPtr); + } + diff --git a/src/bin/ld/findlibrary.c b/src/bin/ld/findlibrary.c new file mode 100644 index 0000000..f071e7d --- /dev/null +++ b/src/bin/ld/findlibrary.c @@ -0,0 +1,13 @@ +#include +#include "ld.h" + +ldLibrary *ldFindLibrary(const char *lib) { + ldLibrary *tmpLibs = 0x0; + + for (tmpLibs = libs;tmpLibs != 0x0;tmpLibs = tmpLibs->next) { + if (!strcmp(tmpLibs->name,lib)) { + return(tmpLibs); + } + } + return(0x0); + } diff --git a/src/bin/ld/ld.h b/src/bin/ld/ld.h new file mode 100644 index 0000000..4822e68 --- /dev/null +++ b/src/bin/ld/ld.h @@ -0,0 +1,42 @@ +#include +#include +#include "elf.h" + +typedef struct ldLibrary_s { + struct ldLibrary_s *next; + struct ldLibrary_s *prev; + char name[256]; + elfHeader *linkerHeader; + elfSectionHeader *linkerSectionHeader; + elfProgramHeader *linkerProgramHeader; + elfDynSym *linkerRelSymTab; + elfPltInfo *linkerElfRel; + char *linkerShStr; + char *linkerDynStr; + char *output; + int sym; + } ldLibrary; + +extern ldLibrary *libs; + +uInt32 ldFindFunc(const char *,const char *); +ldLibrary *ldFindLibrary(const char *); +ldLibrary *ldAddLibrary(const char *); + +/*** + $Log$ + Revision 1.4 2004/06/17 14:10:34 reddawg + Fixed some potential problems + + Revision 1.3 2004/06/17 02:58:49 reddawg + Cleaned Out Dead Code + + Revision 1.2 2004/06/17 01:52:54 reddawg + Maybe? + + Revision 1.1 2004/06/16 23:11:34 reddawg + ld.so: now adds librarys it is a little more efficient does the lazy binding + + END + ***/ + diff --git a/src/bin/ld/main.c b/src/bin/ld/main.c new file mode 100644 index 0000000..d7eabcc --- /dev/null +++ b/src/bin/ld/main.c @@ -0,0 +1,163 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include "ld.h" + +ldLibrary *libs = 0x0; + +static elfHeader *binaryHeader = 0x0; +static elfSectionHeader *binarySectionHeader = 0x0; +static char *binaryShStr = 0x0; +static char *binaryDynStr = 0x0; +static elfDynSym *binaryRelSymTab = 0x0; +static elfPltInfo *binaryElfRel = 0x0; + +uInt32 ld(uInt32 got2,uInt32 entry) { + int i = 0x0; + int x = 0x0; + int rel = 0x0; + uInt32 *reMap = 0x0; + FILE *binaryFd = 0x0; + + if (binaryHeader == 0x0) { + binaryFd = malloc(sizeof(FILE)); + binaryFd->fd = (uInt32)got2; + fseek(binaryFd,0x0,0x0); + binaryHeader = (elfHeader *)malloc(sizeof(elfHeader)); + fread(binaryHeader,sizeof(elfHeader),1,binaryFd); + } + + if (binarySectionHeader == 0x0) { + binarySectionHeader = (elfSectionHeader *)malloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); + fseek(binaryFd,binaryHeader->eShoff,0); + fread(binarySectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,binaryFd); + + if (binaryShStr == 0x0) { + binaryShStr = (char *)malloc(binarySectionHeader[binaryHeader->eShstrndx].shSize); + fseek(binaryFd,binarySectionHeader[binaryHeader->eShstrndx].shOffset,0); + fread(binaryShStr,binarySectionHeader[binaryHeader->eShstrndx].shSize,1,binaryFd); + } + + for (i=0x0;ieShnum;i++) { + switch (binarySectionHeader[i].shType) { + case 3: + if (!strcmp((binaryShStr + binarySectionHeader[i].shName),".dynstr")) { + if (binaryDynStr == 0x0) { + binaryDynStr = (char *)malloc(binarySectionHeader[i].shSize); + fseek(binaryFd,binarySectionHeader[i].shOffset,0); + fread(binaryDynStr,binarySectionHeader[i].shSize,1,binaryFd); + } + } + break; + case 9: + rel = i; + break; + case 11: + if (binaryRelSymTab == 0x0) { + binaryRelSymTab = (elfDynSym *)malloc(binarySectionHeader[i].shSize); + fseek(binaryFd,binarySectionHeader[i].shOffset,0); + fread(binaryRelSymTab,binarySectionHeader[i].shSize,1,binaryFd); + } + break; + } + } + } + + if (binaryElfRel == 0x0) { + fseek(binaryFd,binarySectionHeader[rel].shOffset,0x0); + binaryElfRel = (elfPltInfo *)malloc(binarySectionHeader[rel].shSize); + fread(binaryElfRel,binarySectionHeader[rel].shSize,1,binaryFd); + } + + i = (entry/sizeof(elfPltInfo)); + x = ELF32_R_SYM(binaryElfRel[i].pltInfo); + reMap = (uInt32 *)binaryElfRel[i].pltOffset; + *reMap = ldFindFunc(binaryDynStr + binaryRelSymTab[x].dynName,(char *)(binaryDynStr + 1)); + + if (binaryFd) { + fclose(binaryFd); + } + + return(*reMap); + } + +/*** + $Log$ + Revision 1.13 2004/06/18 15:18:04 reddawg + bug fixes: did some double checking on pointers and 0x0 out memory + + Revision 1.12 2004/06/17 14:14:44 reddawg + Fixed some potential problems + + Revision 1.11 2004/06/17 13:05:14 reddawg + dynamic linking: fixed int6 issue problem was multiple rel's + + Revision 1.10 2004/06/17 12:32:11 reddawg + the machine should just hlt + + Revision 1.9 2004/06/17 11:58:10 reddawg + ld.so: Made a few changes to the way it functions hopefully it will + improve some of its performance. + + Revision 1.8 2004/06/17 02:58:49 reddawg + Cleaned Out Dead Code + + Revision 1.7 2004/06/17 01:09:24 reddawg + TCA: cvs update make and give me output + + Revision 1.6 2004/06/16 23:11:34 reddawg + ld.so: now adds librarys it is a little more efficient does the lazy binding + + Revision 1.5 2004/06/16 18:04:15 reddawg + Fixed typo printf <--> kprintf + + Revision 1.4 2004/06/16 16:31:58 reddawg + ld.so: the dynamic linker works and has been tested + + Revision 1.3 2004/06/16 13:52:51 reddawg + Start of userland LD + + Revision 1.2 2004/06/01 01:30:43 reddawg + No more warnings and organized make files + + Revision 1.1 2004/04/26 21:16:03 reddawg + Initial addition of the ubix LD + + Revision 1.2 2004/04/26 13:20:42 reddawg + Turn off muffin + + Revision 1.1 2004/04/26 13:13:25 reddawg + Initial Introduction of the UbixOS Format Utility into the source tree + + END + ***/ + diff --git a/src/bin/login/Makefile b/src/bin/login/Makefile new file mode 100644 index 0000000..205f68f --- /dev/null +++ b/src/bin/login/Makefile @@ -0,0 +1,51 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = login + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +#LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/login/main.c b/src/bin/login/main.c new file mode 100644 index 0000000..2859677 --- /dev/null +++ b/src/bin/login/main.c @@ -0,0 +1,125 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +struct passwd { + char username[32]; + char password[32]; + int uid; + int gid; + char shell[128]; + char realname[256]; + char path[256]; + }; + +static char *pgets(char *string) { + int count=0,ch=0; + while (1) { + ch = fgetc(stdin); + if(ch == 10) { + printf("\n"); + break; + } + else if(ch == 8 && count > 0) count-=2; + else if(ch == 0) count--; + else string[count] = ch; + if (ch != 8) printf("*"); + count++; + } + string[count] = '\0'; + return(string); + } + +int main() { + FILE *fd; + int shellPid = 0,i = 0x0; + char userName[32]; + char passWord[32]; + char *data2 = 0x0; + struct passwd *data = 0x0; + if ((getuid() != 0) && (getgid() != 0)) { + printf("This Application Must Be Run As Root.\n"); + exit(-1); + } + data = (struct passwd *)malloc(4096); + if (!(fd = fopen("userdb@sys","r"))) { + printf("Error Opening File"); + memcpy(data[0].username,"root",4); + memcpy(data[0].password,"user",4); + memcpy(data[0].shell,"shell@sys", 10); + } + else { + fread(data,4096,1,fd); + fclose(fd); + } + data2 = (char *)malloc(384); + login: + printf("\nUbixOS/IA-32 (devel.ubixos.com) (console)"); + printf("\n\nLogin: "); + gets((char *)&userName); + printf("Password: "); + pgets((char *)&passWord); + for (i=0x0;i<(4096/sizeof(struct passwd));i++) { + if (0x0 == strcmp(userName,data[i].username)) { + if (0x0 == strcmp(passWord,data[i].password)) { + shellPid = fork(); + if (!shellPid) { + if (setuid(data[i].uid) != 0x0) { + printf("Set UID Failed\n"); + } + if (setgid(data[i].gid) != 0x0) { + printf("Set GID Failed\n"); + } + if ((fd = fopen("motd@sys","r")) == 0x0) { + printf("No MOTD"); + } + else { + fread(data2,384,1,fd); + printf("%s\n",data2); + } + fclose(fd); + chdir(data[i].path); + exec(data[i].shell,0x0,0x0); + printf("Error: Problem Starting Shell\n"); + exit(-1); + } + else { + while (pidStatus(shellPid) > 0) { + sched_yield(); + } + goto login; + } + } + } + } + printf("Login Incorrect!\n"); + goto login; + return(0x0); + } + diff --git a/src/bin/ls/Makefile b/src/bin/ls/Makefile new file mode 100644 index 0000000..154fbe4 --- /dev/null +++ b/src/bin/ls/Makefile @@ -0,0 +1,51 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = ls + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/ls/main.c b/src/bin/ls/main.c new file mode 100644 index 0000000..d743265 --- /dev/null +++ b/src/bin/ls/main.c @@ -0,0 +1,121 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include + +#define permRead 0x8 +#define permWrite 0x4 +#define permExecute 0x2 +#define permHidden 0x1 + + +//UbixFS Directory Entry +struct directoryEntry { + uInt32 startCluster; //Starting Cluster Of File + uInt32 size; //Size Of File + uInt32 creationDate; //Date Created + uInt32 lastModified; //Date Last Modified + uInt32 uid; //UID Of Owner + uInt32 gid; //GID Of Owner + uInt16 attributes; //Files Attributes + uInt16 permissions; //Files Permissions + char fileName[256]; //File Name + }; + +#define typeFile 1 +#define typeContainer 2 +#define typeDirectory 4 +#define typeDeleted 8 + +int main(int argc,char **argv) { + int i = 0x0,x = 0x0,tmpPerms = 0x0; + char *pwd = 0x0; + char *permsData = 0x0; + FILE *fd; + struct directoryEntry *dirEntry = 0x0; + + pwd = (char *)malloc(256); + permsData = (char *)malloc(13); + + if (argv[1] == 0x0) { + if ((fd = fopen(":","rb")) == 0x0) { + printf("Error: Reading Directory\n"); + exit(1); + } + } + else { + fd = fopen(argv[1],"rb"); + if (fd->fd == 0x0) { + printf("Error: Reading Directory\n"); + exit(1); + } + } + dirEntry = (struct directoryEntry *)malloc(fd->size); + fread(dirEntry,fd->size,1,fd); + pwd[0] = '/'; + for (i=0;i<(fd->size/sizeof(struct directoryEntry));i++) { + if ((dirEntry[i].fileName[0] > 0) && (dirEntry[i].fileName[0] != ':')) { + for (x=0;x<12;x++) { + permsData[x] = '-'; + } + if ((dirEntry[i].attributes & typeDeleted) == typeDeleted) { + permsData[0] = 'd'; + goto next; + } + else if ((dirEntry[i].attributes & typeFile) == typeFile) { + permsData[0] = 'F'; + } + else if ((dirEntry[i].attributes & typeDirectory) == typeDirectory) { + permsData[0] = 'D'; + } + else if ((dirEntry[i].attributes & typeContainer) == typeContainer) { + permsData[0] = '@'; + } + else { + permsData[0] = 'U'; + } + tmpPerms = ((dirEntry[i].permissions & 0xF00) >> 8); + if ((tmpPerms & permRead) == permRead) permsData[1] = 'R'; + if ((tmpPerms & permWrite) == permWrite) permsData[2] = 'W'; + if ((tmpPerms & permExecute) == permExecute) permsData[3] = 'E'; + if ((tmpPerms & permHidden) == permHidden) permsData[4] = 'H'; + tmpPerms = ((dirEntry[i].permissions & 0x0F0) >> 4); + if ((tmpPerms & permRead) == permRead) permsData[5] = 'R'; + if ((tmpPerms & permWrite) == permWrite) permsData[6] = 'W'; + if ((tmpPerms & permExecute) == permExecute) permsData[7] = 'E'; + if ((tmpPerms & permHidden) == permHidden) permsData[8] = 'H'; + tmpPerms = ((dirEntry[i].permissions & 0x00F) >> 0); + if ((tmpPerms & permRead) == permRead) permsData[9] = 'R'; + if ((tmpPerms & permWrite) == permWrite) permsData[10] = 'W'; + if ((tmpPerms & permExecute) == permExecute) permsData[11] = 'E'; + if ((tmpPerms & permHidden) == permHidden) permsData[12] = 'H'; + printf("%s %i %i %i %s\n",permsData,(int)dirEntry[i].uid,(int)dirEntry[i].gid,(int)dirEntry[i].size,dirEntry[i].fileName); + next: + } + } + if (!fclose(fd)) { + printf("Error Closing Directory\n"); + } + return(0); + } diff --git a/src/bin/muffin/Makefile b/src/bin/muffin/Makefile new file mode 100644 index 0000000..5e18ab5 --- /dev/null +++ b/src/bin/muffin/Makefile @@ -0,0 +1,55 @@ +# $Id$ +# Application Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Compiler Flags +CFLAGS = -DNOBOOL -fno-builtin -fno-exceptions -nostdlib -nostdinc + +#Linker +LD = ld + +#Binary File Name +BINARY = muffin + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Libraries +LIBRARIES2 = ../../lib/objgfx40/*.o ../../lib/libcpp/*.o + +#Include +INCLUDE = -I../../lib/libc/include -I../../lib/libcpp/include -I../../lib/objgfx40 + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(LIBRARIES2) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -fomit-frame-pointer -O $(CFLAGS) $(INCLUDE) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -fomit-frame-pointer -O $(CFLAGS) $(INCLUDE) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDE) -c -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O $(CFLAGS) $(INCLUDE) -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer $(INCLUDE) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/muffin/main.cc b/src/bin/muffin/main.cc new file mode 100644 index 0000000..30868da --- /dev/null +++ b/src/bin/muffin/main.cc @@ -0,0 +1,35 @@ +#include +extern "C" { + #include + #include + #include + } + +int main() { + vWindow *window = new vWindow(); + uInt16 i = 0x0; + uInt16 ii = 0x0; + uInt16 iii = 0x0; + if (fork() == 0x0) { + window->vCreate(); + window->vSDECommand(1); + while (1) { + for (i=0x2;i<0xFF;i += 16) { + for (ii=0x0;ii<0xFF;ii+= 16) { + for (iii= 0x0;iii< 0xFF;iii+= 16) { + window->Clear(window->Pack(i,ii,iii)); + window->FillRect(50, 50, 100, 100, window->Pack(255, 0, 0)); + window->FillRect(50, 50, 100, 100, window->Pack(255, 0, 0)); + window->FillRect(100, 50, 150, 100, window->Pack(0, 255, 0)); + window->FillRect(150, 50, 200, 100, window->Pack(0, 0, 255)); + window->FillRect(200, 50, 250, 100, window->Pack(0, 0, 0)); + window->FillRect(250, 50, 300, 100, window->Pack(255, 255, 255)); + window->vSDECommand(3); + } + } + } + } + window->vSDECommand(4); + } + return(0); + } diff --git a/src/bin/shell/Makefile b/src/bin/shell/Makefile new file mode 100644 index 0000000..9cfa222 --- /dev/null +++ b/src/bin/shell/Makefile @@ -0,0 +1,51 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = shell + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o error.o commands.o exec.o input.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/shell/commands.c b/src/bin/shell/commands.c new file mode 100644 index 0000000..f2f4dfb --- /dev/null +++ b/src/bin/shell/commands.c @@ -0,0 +1,103 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "shell.h" + +int commands(inputBuffer *data) { + int cPid = 0x0,i = 0x0; + if (0 == memcmp(data->args->arg, "uname", 5)) { + printf("UbixOS v0.87 " __DATE__" " __TIME__ " \n"); + return(1); + } + else if (0 == memcmp(data->args->arg, "exit", 4)) { + exit(1); + } + else if (0 == memcmp(data->args->arg, "mypid", 5)) { + printf("My Pid: [%i]\n",getpid()); + return(1); + } + else if (memcmp(data->args->arg,"stress", 6) == 0) { + while (1) { + cPid = fork(); + if (!cPid) { + printf("Pid: [%i]\n",cPid); + exec("clock",0x0,0x0); + exit(-1); + } + else { + while (pidStatus(cPid)) + sched_yield(); + } + } + } + else if (memcmp(data->args->arg,"echo",4) == 0) { + for (i=1;iargc;i++) { + printf("%s ",data->argv[i]); + } + printf("\n"); + } + else if (memcmp(data->args->arg,"about",5) == 0) { + printf("UbixOS Shell v0.99 (C) 2002\n"); + printf("Base Command Line Interface\n"); + } + else if (memcmp(data->args->arg,"cd",2) == 0) { + if (data->argv[1]) { + chdir(data->argv[1]); + getcwd(cwd,1024); + } + } + else if (memcmp(data->args->arg,"unlink",6) == 0) { + if (data->argv[1]) { + unlink(data->argv[1]); + } + } + else if (memcmp(data->args->arg,"msg",3) == 0x0) { + mpiPostMessage(data->argv[1],atoi(data->argv[2]),data->argv[3]); + for (i=0;i<10;i++) { + sched_yield(); + } + } + else if (memcmp(data->args->arg,"mkdir",5) == 0x0) { + if (data->argv[1]) { + mkdir(data->argv[1],0xEAA); + } + } + else if (memcmp(data->args->arg,"id",2) == 0x0) { + printf("UID: %i, GID: %i\n",getuid(),getgid()); + } + else if (!strcmp(data->argv[0],"reboot")) { + mpiPostMessage("system",1000,0x0); + } + else { + return(0); + } + return(1); + } diff --git a/src/bin/shell/error.c b/src/bin/shell/error.c new file mode 100644 index 0000000..adf30a6 --- /dev/null +++ b/src/bin/shell/error.c @@ -0,0 +1,30 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include + +void error(int errorCode,const char *errorMsg) { + printf("ERROR: #%i Message: %s\n", errorCode, errorMsg); + exit(errorCode); + } diff --git a/src/bin/shell/exec.c b/src/bin/shell/exec.c new file mode 100644 index 0000000..1a34679 --- /dev/null +++ b/src/bin/shell/exec.c @@ -0,0 +1,45 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include +#include +#include +#include "shell.h" + +void execProgram(inputBuffer *data) { + int cPid = 0x0; + cPid = fork(); + if (!cPid) { + exec(data->argv[0],data->argc,data->argv); + printf("%s: Command Not Found.\n",data->argv[0]); + exit(-1); + } + else { + if (data->bg == 0x0) { + while (pidStatus(cPid) > 0) + sched_yield(); + } + } + } diff --git a/src/bin/shell/input.c b/src/bin/shell/input.c new file mode 100644 index 0000000..7b57d7f --- /dev/null +++ b/src/bin/shell/input.c @@ -0,0 +1,70 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include +#include "shell.h" + +void parseInput(inputBuffer *buffer,char *data) { + int i = 0x0; + char *arg = 0x0; + struct argsStruct *tmpArgs = 0x0; + + while (data[0] == ' ') { + data++; + } + + if (*data == '\0') return; + + buffer->args = (struct argsStruct *)malloc(sizeof(struct argsStruct)); + tmpArgs = buffer->args; + + while(data != 0x0) { + arg = strtok(data," "); + data = strtok(NULL,"\n"); + if (arg[0] == '&') { + buffer->bg = 0x1; + } + else { + buffer->argc++; + tmpArgs->arg = arg; + if (data != 0x0) { + tmpArgs->next = (struct argsStruct *)malloc(sizeof(struct argsStruct)); + } + tmpArgs = tmpArgs->next; + } + } + + buffer->argv = (char **)malloc(4*buffer->argc); + tmpArgs = buffer->args; + for (i=0;iargc;i++) { + buffer->argv[i] = tmpArgs->arg; + tmpArgs = tmpArgs->next; + } + } + +void freeArgs(inputBuffer *ptr) { + free(ptr->args); + //free(tmpArgs->argv); + } diff --git a/src/bin/shell/main.c b/src/bin/shell/main.c new file mode 100644 index 0000000..76fa278 --- /dev/null +++ b/src/bin/shell/main.c @@ -0,0 +1,62 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include +#include +#include +#include +#include "shell.h" + +char *machine = 0x0; +char *cwd = 0x0; +char *cwc = 0x0; + +int main() { + char *data = 0x0; + char *buffer = (char *)malloc(512); + inputBuffer *inBuf = (inputBuffer *)malloc(sizeof(inputBuffer)); + + machine = (char *)malloc(32); + cwd = (char *)malloc(1024); + cwc = (char *)malloc(32); + + sprintf(machine,"uBixCube"); + getcwd(cwd,1024); + sprintf(cwc,"sys"); + + while (1) { + printf("%s:%s@%s> ",machine,cwd,cwc); + gets((char *)buffer); + data = (uInt8 *)buffer; + parseInput(inBuf,data); + if (inBuf->args->arg != 0x0) { + if (!commands(inBuf)) execProgram(inBuf); + } + freeArgs(inBuf); + inBuf->argc = 0x0; + inBuf->args = 0x0; + inBuf->bg = 0x0; + } + return(0x0); + } diff --git a/src/bin/shell/shell.h b/src/bin/shell/shell.h new file mode 100644 index 0000000..4d0f59f --- /dev/null +++ b/src/bin/shell/shell.h @@ -0,0 +1,21 @@ +#include + +extern char *cwd; + +struct argsStruct { + struct argsStruct *next; + char *arg; + }; + +typedef struct { + int argc; + char **argv; + uInt8 bg; + struct argsStruct *args; + } inputBuffer; + +void parseInput(inputBuffer *,char *); +int commands(inputBuffer *); +void execProgram(inputBuffer *); +void freeArgs(inputBuffer *ptr); +void error(int errorCode,const char *errorMsg); diff --git a/src/bin/test/Makefile b/src/bin/test/Makefile new file mode 100644 index 0000000..021df1a --- /dev/null +++ b/src/bin/test/Makefile @@ -0,0 +1,53 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +INCLUDES += -I./include -I../../lib/views/sunlight/include -I../../lib/libcpp/include -I../../lib/objgfx40 +CFLAGS = -fno-builtin -nostdlib -nostdinc -nostdlib -fno-builtin -fno-exceptions -frtti +LIBRARIES = ../../lib/libc/libc.so ../../lib/libstdc++/*.o ../../lib/objgfx40/objgfx40.so + +#Linker +LD = ld + +#Binary File Name +BINARY = test + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +# Link The Binary +$(BINARY) : $(OBJS) + $(CXX) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O -DNOBOOL $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/test/include/ubixButton.h b/src/bin/test/include/ubixButton.h new file mode 100644 index 0000000..34ee379 --- /dev/null +++ b/src/bin/test/include/ubixButton.h @@ -0,0 +1,13 @@ +#ifndef UBIXBUTTON_H +#define UBIXBUTTON_H + +#include + +class ubixButton : public vButton { + public: + ubixButton(vContext *); +// virtual bool vCreate(void); + virtual void vDraw(void); + virtual ~ubixButton(void); +}; // ubixButton +#endif diff --git a/src/bin/test/include/ubixDesktop.h b/src/bin/test/include/ubixDesktop.h new file mode 100644 index 0000000..61a1a38 --- /dev/null +++ b/src/bin/test/include/ubixDesktop.h @@ -0,0 +1,14 @@ +#ifndef UBIXDESKTOP_H +#define UBIXDESKTOP_H + +#include + +class ubixDesktop : public vContext { + protected: + public: + ubixDesktop(vContext *); + virtual bool vCreate(void); + virtual void vDraw(void); + virtual ~ubixDesktop(void); +}; // ubixDesktop +#endif diff --git a/src/bin/test/main.cpp b/src/bin/test/main.cpp new file mode 100644 index 0000000..cfe12f4 --- /dev/null +++ b/src/bin/test/main.cpp @@ -0,0 +1,10 @@ +#include + +extern "C" { + #include + } + +int main(void) { + printf("Test"); + return 0; + } diff --git a/src/bin/test/test b/src/bin/test/test new file mode 100755 index 0000000..a7f2d9b --- /dev/null +++ b/src/bin/test/test Binary files differ diff --git a/src/bin/ubistry/Makefile b/src/bin/ubistry/Makefile new file mode 100644 index 0000000..46bea2a --- /dev/null +++ b/src/bin/ubistry/Makefile @@ -0,0 +1,51 @@ +# $Id$ +# Application Makefile (C) 2002-2004 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Linker +LD = ld + +#Binary File Name +BINARY = ubistry + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = db.o message.o main.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +LIBRARIES = ../../lib/libc/libc.so + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/ubistry/db.c b/src/bin/ubistry/db.c new file mode 100644 index 0000000..d495e29 --- /dev/null +++ b/src/bin/ubistry/db.c @@ -0,0 +1,80 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include "./include/ubistry.h" + +static struct ubistryKey *keys = 0x0; + + +struct ubistryKey * ubistryFindKey(char *name) { + struct ubistryKey *tmpKey = keys; + + for (;tmpKey;tmpKey=tmpKey->next) { + if (!strcmp(name,tmpKey->name)) { + return(tmpKey); + } + } + return(0x0); + } + +int ubistryAddKey(char *name,char *value) { + struct ubistryKey *tmpKey = (struct ubistryKey *)malloc(sizeof(struct ubistryKey)); + + sprintf(tmpKey->name,name); + sprintf(tmpKey->value,value); + + if (keys == 0x0) { + keys = tmpKey; + keys->prev = 0x0; + keys->next = 0x0; + } + else { + tmpKey->next = keys; + tmpKey->prev = 0x0; + keys->prev = tmpKey; + keys = tmpKey; + } + + return(0x0); + } + +/*** + $Log$ + Revision 1.2 2004/06/17 15:10:55 reddawg + Fixed Some Global Variables + + Revision 1.1 2004/05/26 15:41:20 reddawg + ubistry: added command 666 which will restart the registry server also added + command 51 to add a key format key,value + + END + ***/ diff --git a/src/bin/ubistry/include/ubistry.h b/src/bin/ubistry/include/ubistry.h new file mode 100644 index 0000000..231acea --- /dev/null +++ b/src/bin/ubistry/include/ubistry.h @@ -0,0 +1,15 @@ +#include + +#define MBOX_NAME "ubistry" + +struct ubistryKey { + struct ubistryKey *prev; + struct ubistryKey *next; + char name[128]; + char value[512]; + }; + +struct ubistryKey * ubistryFindKey(char *); +int ubistryAddKey(char *,char *); +int ubistryInitMbox(char *); +void ubistryProcessMessages(); diff --git a/src/bin/ubistry/main.c b/src/bin/ubistry/main.c new file mode 100644 index 0000000..88d0eed --- /dev/null +++ b/src/bin/ubistry/main.c @@ -0,0 +1,87 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include "./include/ubistry.h" + +int main(int argc,char **argv) { + //FILE *pidFile; + + if (fork() != 0x0) { + //sched_yield(); + exit(0x0); + } + + ubistryInitMbox(MBOX_NAME); + + ubistryAddKey("Ubu","Creator Of UbixOS"); + ubistryAddKey("TCA","The GUI GUY!!!"); + + while (1) { + ubistryProcessMessages(); + sched_yield(); + } + + exit(0x0); + } + +/*** + $Log$ + Revision 1.7 2004/06/17 15:10:55 reddawg + Fixed Some Global Variables + + Revision 1.6 2004/06/10 13:08:00 reddawg + Minor Bug Fixes + + Revision 1.5 2004/06/01 01:30:43 reddawg + No more warnings and organized make files + + Revision 1.4 2004/05/26 15:41:20 reddawg + ubistry: added command 666 which will restart the registry server also added + command 51 to add a key format key,value + + Revision 1.3 2004/05/26 13:10:39 reddawg + ubistry: added two functions + ubistryFindKey(char *name) <- Will find key with specified name + ubistryAddKey(char *name,char *value) <-> Will add key with specified + name and value + + Revision 1.2 2004/05/26 12:16:02 reddawg + ubistry: now runs as a deamon + + Revision 1.1 2004/05/26 12:09:12 reddawg + ubistry: this is the frame work for the ubix registry system more to come + over the next few days + + END + ***/ diff --git a/src/bin/ubistry/message.c b/src/bin/ubistry/message.c new file mode 100644 index 0000000..1d5f9d6 --- /dev/null +++ b/src/bin/ubistry/message.c @@ -0,0 +1,95 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "./include/ubistry.h" + +int ubistryInitMbox(char *name) { + + if (mpiCreateMbox(name) != 0x0) { + printf("Error: Error Creating Mail Box: [%s]\n",name); + return(-1); + } + + return(0x0); + } + +void ubistryProcessMessages() { + mpiMessage_t msg; + struct ubistryKey *tmpKey = 0x0; + char *key,*value; + + mfmStart: + if (mpiFetchMessage("ubistry",&msg) == 0x0) { + switch (msg.type) { + case 50: + tmpKey = ubistryFindKey(msg.data); + if (tmpKey == 0x0) + printf("ubistry: Key (%s) Not Found\n",msg.data); + else + printf("ubistry: Key (%s) Found Has Value (%s)\n",tmpKey->name,tmpKey->value); + break; + case 51: + key = strtok(msg.data,","); + value = strtok(NULL,"\n"); + printf("ubistry: Adding key (%s) with value (%s)\n",key,value); + ubistryAddKey(key,value); + break; + case 666: + mpiDestroyMbox("ubistry"); + if (fork() == 0x0) { + printf("ubistry: Restarting\n"); + exec("ubistry@sys",0x0,0x0); + } + else { + exit(0x0); + } + break; + default: + printf("ubistry: Command (%i) With Data (%s) Not Valid\n",msg.type,msg.data); + break; + } + goto mfmStart; + } + return; + } + +/*** + $Log$ + Revision 1.1 2004/05/26 15:41:20 reddawg + ubistry: added command 666 which will restart the registry server also added + command 51 to add a key format key,value + + END + ***/ diff --git a/src/bin/views/Makefile b/src/bin/views/Makefile new file mode 100644 index 0000000..363704c --- /dev/null +++ b/src/bin/views/Makefile @@ -0,0 +1,52 @@ +# $Id$ +# Application Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc + +#Compiler Flags +CFLAGS = -I../../lib/libc/include -fno-builtin -nostdlib -nostdinc + +#Linker +LD = ld + +#Binary File Name +BINARY = views + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = main.o + +#Libraries +#LIBRARIES = ../../lib/libc/libc.so +LIBRARIES = ../../lib/libc/locale/*.o ../../lib/libc/stdio/*.o ../../lib/libc/stdlib/*.o ../../lib/libc/sys/*.o ../../lib/libc/string/*.o + +#Startup File +STARTUP = ../../lib/ubix/startup.o + +# Link The Binary +$(BINARY) : $(OBJS) + $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) + strip $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -fomit-frame-pointer -O $(CFLAGS) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -fomit-frame-pointer -O $(CFLAGS) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) -c -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O $(CFLAGS) -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/bin/views/main.c b/src/bin/views/main.c new file mode 100644 index 0000000..e86deaa --- /dev/null +++ b/src/bin/views/main.c @@ -0,0 +1,34 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include + +int main(int argc,char **argv) { + return(0); + } + +/*** + END + ***/ + diff --git a/src/include/_semaphore.h b/src/include/_semaphore.h new file mode 100644 index 0000000..e65181f --- /dev/null +++ b/src/include/_semaphore.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2002 Alfred Perlstein + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/posix4/_semaphore.h,v 1.3 2004/02/03 22:27:03 deischen Exp $ + */ +#ifndef __SEMAPHORE_H_ +#define __SEMAPHORE_H_ + +typedef intptr_t semid_t; +struct timespec; + +#ifndef _KERNEL + +#include + +/* + * Semaphore definitions. + */ +struct sem { +#define SEM_MAGIC ((u_int32_t) 0x09fa4012) + u_int32_t magic; + pthread_mutex_t lock; + pthread_cond_t gtzero; + u_int32_t count; + u_int32_t nwaiters; +#define SEM_USER (NULL) + semid_t semid; /* semaphore id if kernel (shared) semaphore */ + int syssem; /* 1 if kernel (shared) semaphore */ + LIST_ENTRY(sem) entry; + struct sem **backpointer; +}; + +__BEGIN_DECLS + +int ksem_close(semid_t id); +int ksem_post(semid_t id); +int ksem_wait(semid_t id); +int ksem_trywait(semid_t id); +int ksem_timedwait(semid_t id, struct timespec *abstime); +int ksem_init(semid_t *idp, unsigned int value); +int ksem_open(semid_t *idp, const char *name, int oflag, mode_t mode, + unsigned int value); +int ksem_unlink(const char *name); +int ksem_getvalue(semid_t id, int *val); +int ksem_destroy(semid_t id); + +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* __SEMAPHORE_H_ */ diff --git a/src/include/a.out.h b/src/include/a.out.h new file mode 100644 index 0000000..176b39c --- /dev/null +++ b/src/include/a.out.h @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 1991, 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. + * + * @(#)a.out.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _AOUT_H_ +#define _AOUT_H_ + +#include +#include +#include +#include + +#define _AOUT_INCLUDE_ +#include + +#endif /* !_AOUT_H_ */ diff --git a/src/include/aio.h b/src/include/aio.h new file mode 100644 index 0000000..f311e3c --- /dev/null +++ b/src/include/aio.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 1997 John S. Dyson. 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. John S. Dyson's name may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * DISCLAIMER: This code isn't warranted to do anything useful. Anything + * bad that happens because of using this software isn't the responsibility + * of the author. This software is distributed AS-IS. + * + * $FreeBSD: src/sys/sys/aio.h,v 1.29 2002/01/06 21:03:39 alc Exp $ + */ + +#ifndef _SYS_AIO_H_ +#define _SYS_AIO_H_ + +#include +#include +#include + +/* + * Returned by aio_cancel: + */ +#define AIO_CANCELED 0x1 +#define AIO_NOTCANCELED 0x2 +#define AIO_ALLDONE 0x3 + +/* + * LIO opcodes + */ +#define LIO_NOP 0x0 +#define LIO_WRITE 0x1 +#define LIO_READ 0x2 + +/* + * LIO modes + */ +#define LIO_NOWAIT 0x0 +#define LIO_WAIT 0x1 + +/* + * Maximum number of allowed LIO operations + */ +#define AIO_LISTIO_MAX 16 + +/* + * Private members for aiocb -- don't access + * directly. + */ +struct __aiocb_private { + long status; + long error; + void *kernelinfo; +}; + +/* + * I/O control block + */ +typedef struct aiocb { + int aio_fildes; /* File descriptor */ + off_t aio_offset; /* File offset for I/O */ + volatile void *aio_buf; /* I/O buffer in process space */ + size_t aio_nbytes; /* Number of bytes for I/O */ + struct sigevent aio_sigevent; /* Signal to deliver */ + int aio_lio_opcode; /* LIO opcode */ + int aio_reqprio; /* Request priority -- ignored */ + struct __aiocb_private _aiocb_private; +} aiocb_t; + +#ifndef _KERNEL + +__BEGIN_DECLS +/* + * Asynchronously read from a file + */ +int aio_read(struct aiocb *); + +/* + * Asynchronously write to file + */ +int aio_write(struct aiocb *); + +/* + * List I/O Asynchronously/synchronously read/write to/from file + * "lio_mode" specifies whether or not the I/O is synchronous. + * "acb_list" is an array of "nacb_listent" I/O control blocks. + * when all I/Os are complete, the optional signal "sig" is sent. + */ +int lio_listio(int, struct aiocb * const [], int, struct sigevent *); + +/* + * Get completion status + * returns EINPROGRESS until I/O is complete. + * this routine does not block. + */ +int aio_error(const struct aiocb *); + +/* + * Finish up I/O, releasing I/O resources and returns the value + * that would have been associated with a synchronous I/O request. + * This routine must be called once and only once for each + * I/O control block who has had I/O associated with it. + */ +ssize_t aio_return(struct aiocb *); + +/* + * Cancel I/O + */ +int aio_cancel(int, struct aiocb *); + +/* + * Suspend until all specified I/O or timeout is complete. + */ +int aio_suspend(const struct aiocb * const[], int, const struct timespec *); + +int aio_waitcomplete(struct aiocb **, struct timespec *); + +__END_DECLS + +#else + +/* Forward declarations for prototypes below. */ +struct socket; +struct sockbuf; + +extern void (*aio_swake)(struct socket *, struct sockbuf *); + +#endif + +#endif diff --git a/src/include/alias.h b/src/include/alias.h new file mode 100644 index 0000000..a3cccab --- /dev/null +++ b/src/include/alias.h @@ -0,0 +1,264 @@ +/* lint -save -library Flexelint comment for external headers */ + +/*- + * Copyright (c) 2001 Charles Mott + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libalias/alias.h,v 1.27 2004/03/16 21:30:41 des Exp $ + */ + +/*- + * Alias.h defines the outside world interfaces for the packet aliasing + * software. + * + * This software is placed into the public domain with no restrictions on its + * distribution. + */ + +#ifndef _ALIAS_H_ +#define _ALIAS_H_ + +/* + * The external interface to libalias, the packet aliasing engine. + * + * There are two sets of functions: + * + * PacketAlias*() the old API which doesn't take an instance pointer + * and therefore can only have one packet engine at a time. + * + * LibAlias*() the new API which takes as first argument a pointer to + * the instance of the packet aliasing engine. + * + * The functions otherwise correspond to each other one for one, except + * for the LibAliasUnaliasOut()/PacketUnaliasOut() function which were + * were misnamed in the old API. + */ + +/* + * The instance structure + */ +struct libalias; + +/* + * An anonymous structure, a pointer to which is returned from + * PacketAliasRedirectAddr(), PacketAliasRedirectPort() or + * PacketAliasRedirectProto(), passed to PacketAliasAddServer(), + * and freed by PacketAliasRedirectDelete(). + */ +struct alias_link; + + +/* OLD API */ + +/* Initialization and control functions. */ +void PacketAliasInit(void); +void PacketAliasSetAddress(struct in_addr _addr); +void PacketAliasSetFWBase(unsigned int _base, unsigned int _num); +void PacketAliasSetSkinnyPort(unsigned int _port); +unsigned int + PacketAliasSetMode(unsigned int _flags, unsigned int _mask); +void PacketAliasUninit(void); + +/* Packet Handling functions. */ +int PacketAliasIn(char *_ptr, int _maxpacketsize); +int PacketAliasOut(char *_ptr, int _maxpacketsize); +int PacketUnaliasOut(char *_ptr, int _maxpacketsize); + +/* Port and address redirection functions. */ + + +int +PacketAliasAddServer(struct alias_link *_link, + struct in_addr _addr, unsigned short _port); +struct alias_link * +PacketAliasRedirectAddr(struct in_addr _src_addr, + struct in_addr _alias_addr); +int PacketAliasRedirectDynamic(struct alias_link *_link); +void PacketAliasRedirectDelete(struct alias_link *_link); +struct alias_link * +PacketAliasRedirectPort(struct in_addr _src_addr, + unsigned short _src_port, struct in_addr _dst_addr, + unsigned short _dst_port, struct in_addr _alias_addr, + unsigned short _alias_port, unsigned char _proto); +struct alias_link * +PacketAliasRedirectProto(struct in_addr _src_addr, + struct in_addr _dst_addr, struct in_addr _alias_addr, + unsigned char _proto); + +/* Fragment Handling functions. */ +void PacketAliasFragmentIn(char *_ptr, char *_ptr_fragment); +char *PacketAliasGetFragment(char *_ptr); +int PacketAliasSaveFragment(char *_ptr); + +/* Miscellaneous functions. */ +int PacketAliasCheckNewLink(void); +unsigned short + PacketAliasInternetChecksum(unsigned short *_ptr, int _nbytes); +void PacketAliasSetTarget(struct in_addr _target_addr); + +/* Transparent proxying routines. */ +int PacketAliasProxyRule(const char *_cmd); + +/* NEW API */ + +/* Initialization and control functions. */ +struct libalias *LibAliasInit(struct libalias *); +void LibAliasSetAddress(struct libalias *, struct in_addr _addr); +void LibAliasSetFWBase(struct libalias *, unsigned int _base, unsigned int _num); +void LibAliasSetSkinnyPort(struct libalias *, unsigned int _port); +unsigned int + LibAliasSetMode(struct libalias *, unsigned int _flags, unsigned int _mask); +void LibAliasUninit(struct libalias *); + +/* Packet Handling functions. */ +int LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize); +int LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize); +int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize); + +/* Port and address redirection functions. */ + +int +LibAliasAddServer(struct libalias *, struct alias_link *_link, + struct in_addr _addr, unsigned short _port); +struct alias_link * +LibAliasRedirectAddr(struct libalias *, struct in_addr _src_addr, + struct in_addr _alias_addr); +int LibAliasRedirectDynamic(struct libalias *, struct alias_link *_link); +void LibAliasRedirectDelete(struct libalias *, struct alias_link *_link); +struct alias_link * +LibAliasRedirectPort(struct libalias *, struct in_addr _src_addr, + unsigned short _src_port, struct in_addr _dst_addr, + unsigned short _dst_port, struct in_addr _alias_addr, + unsigned short _alias_port, unsigned char _proto); +struct alias_link * +LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr, + struct in_addr _dst_addr, struct in_addr _alias_addr, + unsigned char _proto); + +/* Fragment Handling functions. */ +void LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment); +char *LibAliasGetFragment(struct libalias *, char *_ptr); +int LibAliasSaveFragment(struct libalias *, char *_ptr); + +/* Miscellaneous functions. */ +int LibAliasCheckNewLink(struct libalias *); +unsigned short + LibAliasInternetChecksum(struct libalias *, unsigned short *_ptr, int _nbytes); +void LibAliasSetTarget(struct libalias *, struct in_addr _target_addr); + +/* Transparent proxying routines. */ +int LibAliasProxyRule(struct libalias *, const char *_cmd); + + +/* + * Mode flags and other constants. + */ + + +/* Mode flags, set using PacketAliasSetMode() */ + +/* + * If PKT_ALIAS_LOG is set, a message will be printed to /var/log/alias.log + * every time a link is created or deleted. This is useful for debugging. + */ +#define PKT_ALIAS_LOG 0x01 + +/* + * If PKT_ALIAS_DENY_INCOMING is set, then incoming connections (e.g. to ftp, + * telnet or web servers will be prevented by the aliasing mechanism. + */ +#define PKT_ALIAS_DENY_INCOMING 0x02 + +/* + * If PKT_ALIAS_SAME_PORTS is set, packets will be attempted sent from the + * same port as they originated on. This allows e.g. rsh to work *99% of the + * time*, but _not_ 100% (it will be slightly flakey instead of not working + * at all). This mode bit is set by PacketAliasInit(), so it is a default + * mode of operation. + */ +#define PKT_ALIAS_SAME_PORTS 0x04 + +/* + * If PKT_ALIAS_USE_SOCKETS is set, then when partially specified links (e.g. + * destination port and/or address is zero), the packet aliasing engine will + * attempt to allocate a socket for the aliasing port it chooses. This will + * avoid interference with the host machine. Fully specified links do not + * require this. This bit is set after a call to PacketAliasInit(), so it is + * a default mode of operation. + */ +#define PKT_ALIAS_USE_SOCKETS 0x08 + +/*- + * If PKT_ALIAS_UNREGISTERED_ONLY is set, then only packets with + * unregistered source addresses will be aliased. Private + * addresses are those in the following ranges: + * + * 10.0.0.0 -> 10.255.255.255 + * 172.16.0.0 -> 172.31.255.255 + * 192.168.0.0 -> 192.168.255.255 + */ +#define PKT_ALIAS_UNREGISTERED_ONLY 0x10 + +/* + * If PKT_ALIAS_RESET_ON_ADDR_CHANGE is set, then the table of dynamic + * aliasing links will be reset whenever PacketAliasSetAddress() changes the + * default aliasing address. If the default aliasing address is left + * unchanged by this function call, then the table of dynamic aliasing links + * will be left intact. This bit is set after a call to PacketAliasInit(). + */ +#define PKT_ALIAS_RESET_ON_ADDR_CHANGE 0x20 + +#ifndef NO_FW_PUNCH +/* + * If PKT_ALIAS_PUNCH_FW is set, active FTP and IRC DCC connections will + * create a 'hole' in the firewall to allow the transfers to work. The + * ipfw rule number that the hole is created with is controlled by + * PacketAliasSetFWBase(). The hole will be attached to that + * particular alias_link, so when the link goes away the hole is deleted. + */ +#define PKT_ALIAS_PUNCH_FW 0x100 +#endif + +/* + * If PKT_ALIAS_PROXY_ONLY is set, then NAT will be disabled and only + * transparent proxying is performed. + */ +#define PKT_ALIAS_PROXY_ONLY 0x40 + +/* + * If PKT_ALIAS_REVERSE is set, the actions of PacketAliasIn() and + * PacketAliasOut() are reversed. + */ +#define PKT_ALIAS_REVERSE 0x80 + +/* Function return codes. */ +#define PKT_ALIAS_ERROR -1 +#define PKT_ALIAS_OK 1 +#define PKT_ALIAS_IGNORED 2 +#define PKT_ALIAS_UNRESOLVED_FRAGMENT 3 +#define PKT_ALIAS_FOUND_HEADER_FRAGMENT 4 + +#endif /* !_ALIAS_H_ */ + +/* lint -restore */ diff --git a/src/include/ar.h b/src/include/ar.h new file mode 100644 index 0000000..e04874f --- /dev/null +++ b/src/include/ar.h @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Hugh Smith at The University of Guelph. + * + * 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. + * + * @(#)ar.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _AR_H_ +#define _AR_H_ + +/* Pre-4BSD archives had these magic numbers in them. */ +#define OARMAG1 0177555 +#define OARMAG2 0177545 + +#define ARMAG "!\n" /* ar "magic number" */ +#define SARMAG 8 /* strlen(ARMAG); */ + +#define AR_EFMT1 "#1/" /* extended format #1 */ + +struct ar_hdr { + char ar_name[16]; /* name */ + char ar_date[12]; /* modification time */ + char ar_uid[6]; /* user id */ + char ar_gid[6]; /* group id */ + char ar_mode[8]; /* octal file permissions */ + char ar_size[10]; /* size in bytes */ +#define ARFMAG "`\n" + char ar_fmag[2]; /* consistency check */ +}; + +#endif /* !_AR_H_ */ diff --git a/src/include/archive.h b/src/include/archive.h new file mode 100644 index 0000000..070c0c0 --- /dev/null +++ b/src/include/archive.h @@ -0,0 +1,278 @@ +/*- + * Copyright (c) 2003-2004 Tim Kientzle + * 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 + * in this position and unchanged. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR(S) 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. + * + * $FreeBSD: src/lib/libarchive/archive.h,v 1.9 2004/05/13 06:01:14 kientzle Exp $ + */ + +#ifndef ARCHIVE_H_INCLUDED +#define ARCHIVE_H_INCLUDED + +#include /* For int64_t */ +#include /* For ssize_t and size_t */ + +#define ARCHIVE_BYTES_PER_RECORD 512 +#define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240 + +/* Declare our basic types. */ +struct archive; +struct archive_entry; + +/* + * Error codes: Use archive_errno() and archive_error_string() + * to retrieve details. Unless specified otherwise, all functions + * that return 'int' use these codes. + */ +#define ARCHIVE_EOF 1 /* Found end of archive. */ +#define ARCHIVE_OK 0 /* Operation was successful. */ +#define ARCHIVE_WARN (-1) /* Sucess, but minor problem. */ +#define ARCHIVE_RETRY (-2) /* Retry might succeed. */ +#define ARCHIVE_FATAL (-3) /* No more operations are possible. */ + +/* + * As far as possible, archive_errno returns standard platform errno codes. + * Of course, the details vary by platform, so the actual definitions + * here are stored in "archive_platform.h". The symbols are listed here + * for reference; as a rule, clients should not need to know the exact + * platform-dependent error code. + */ +/* Unrecognized or invalid file format. */ +/* #define ARCHIVE_ERRNO_FILE_FORMAT */ +/* Illegal usage of the library. */ +/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ +/* Unknown or unclassified error. */ +/* #define ARCHIVE_ERRNO_MISC */ + +/* + * Callbacks are invoked to automatically read/write/open/close the archive. + * You can provide your own for complex tasks (like breaking archives + * across multiple tapes) or use standard ones built into the library. + */ + +/* Returns pointer and size of next block of data from archive. */ +typedef ssize_t archive_read_callback(struct archive *, void *_client_data, + const void **_buffer); +/* Returns size actually written, zero on EOF, -1 on error. */ +typedef ssize_t archive_write_callback(struct archive *, void *_client_data, + void *_buffer, size_t _length); +typedef int archive_open_callback(struct archive *, void *_client_data); +typedef int archive_close_callback(struct archive *, void *_client_data); + +/* + * Codes for archive_compression. + */ +#define ARCHIVE_COMPRESSION_NONE 0 +#define ARCHIVE_COMPRESSION_GZIP 1 +#define ARCHIVE_COMPRESSION_BZIP2 2 + +/* + * Codes returned by archive_format. + * + * Top 16 bits identifies the format family (e.g., "tar"); lower + * 16 bits indicate the variant. This is updated by read_next_header. + * Note that the lower 16 bits will often vary from entry to entry. + */ +#define ARCHIVE_FORMAT_BASE_MASK 0xff0000U +#define ARCHIVE_FORMAT_CPIO 0x10000 +#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) +#define ARCHIVE_FORMAT_SHAR 0x20000 +#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) +#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) +#define ARCHIVE_FORMAT_TAR 0x30000 +#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) +#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) +#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) +#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) + +/*- + * Basic outline for reading an archive: + * 1) Ask archive_read_new for an archive reader object. + * 2) Update any global properties as appropriate. + * In particular, you'll certainly want to call appropriate + * archive_read_support_XXX functions. + * 3) Call archive_read_open_XXX to open the archive + * 4) Repeatedly call archive_read_next_header to get information about + * successive archive entries. Call archive_read_data to extract + * data for entries of interest. + * 5) Call archive_read_finish to destroy the object. + */ +struct archive *archive_read_new(void); + +/* + * The archive_read_support_XXX calls enable auto-detect for this + * archive handle. They also link in the necessary support code. + * For example, if you don't want bzlib linked in, don't invoke + * support_compression_bzip2(). The "all" functions provide the + * obvious shorthand. + */ +int archive_read_support_compression_all(struct archive *); +int archive_read_support_compression_bzip2(struct archive *); +int archive_read_support_compression_gzip(struct archive *); +int archive_read_support_compression_none(struct archive *); + +int archive_read_support_format_all(struct archive *); +int archive_read_support_format_cpio(struct archive *); +int archive_read_support_format_gnutar(struct archive *); +int archive_read_support_format_tar(struct archive *); + + +/* Open the archive using callbacks for archive I/O. */ +int archive_read_open(struct archive *, void *_client_data, + archive_open_callback *, archive_read_callback *, + archive_close_callback *); + +/* + * The archive_read_open_file function is a convenience function built + * on archive_read_open that uses a canned callback suitable for + * common situations. Note that a NULL filename indicates stdin. + */ +int archive_read_open_file(struct archive *, const char *_file, + size_t _block_size); +int archive_read_open_fd(struct archive *, int _fd, + size_t _block_size); + +/* Parses and returns next entry header. */ +int archive_read_next_header(struct archive *, + struct archive_entry **); + +/* + * Retrieve the byte offset in UNCOMPRESSED data where last-read + * header started. + */ +int64_t archive_read_header_position(struct archive *); + +/* Read data from the body of an entry. Similar to read(2). */ +ssize_t archive_read_data(struct archive *, void *, size_t); + +/*- + * Some convenience functions that are built on archive_read_data: + * 'skip': skips entire entry + * 'into_buffer': writes data into memory buffer that you provide + * 'into_file': writes data to specified filedes + */ +int archive_read_data_skip(struct archive *); +ssize_t archive_read_data_into_buffer(struct archive *, void *buffer, + ssize_t len); +ssize_t archive_read_data_into_fd(struct archive *, int fd); + +/*- + * Convenience function to recreate the current entry (whose header + * has just been read) on disk. + * + * This does quite a bit more than just copy data to disk. It also: + * - Creates intermediate directories as required. + * - Manages directory permissions: non-writable directories will + * be initially created with write permission enabled; when the + * archive is closed, dir permissions are edited to the values specified + * in the archive. + * - Checks hardlinks: hardlinks will not be extracted unless the + * linked-to file was also extracted within the same session. (TODO) + */ + +/* The "flags" argument selects optional behavior, 'OR' the flags you want. */ +/* TODO: The 'Default' comments here are not quite correct; clean this up. */ +#define ARCHIVE_EXTRACT_OWNER (1) /* Default: owner/group not restored */ +#define ARCHIVE_EXTRACT_PERM (2) /* Default: restore perm only for reg file*/ +#define ARCHIVE_EXTRACT_TIME (4) /* Default: mod time not restored */ +#define ARCHIVE_EXTRACT_NO_OVERWRITE (8) /* Default: Replace files on disk */ +#define ARCHIVE_EXTRACT_UNLINK (16) /* Default: don't unlink existing files */ + +int archive_read_extract(struct archive *, struct archive_entry *, + int flags); +void archive_read_extract_set_progress_callback(struct archive *, + void (*_progress_func)(void *), void *_user_data); + +/* Close the file, release any resources, and destroy the object. */ +void archive_read_finish(struct archive *); + +/*- + * To create an archive: + * 1) Ask archive_write_new for a archive writer object. + * 2) Set any global properties. In particular, you should register + * open/write/close callbacks. + * 3) Call archive_write_open to open the file + * 4) For each entry: + * - construct an appropriate struct archive_entry structure + * - archive_write_header to write the header + * - archive_write_data to write the entry data + * 5) archive_write_finish to close the output and cleanup the writer + */ +struct archive *archive_write_new(void); +int archive_write_set_bytes_per_block(struct archive *, + int bytes_per_block); +/* XXX This is badly misnamed; suggestions appreciated. XXX */ +int archive_write_set_bytes_in_last_block(struct archive *, + int bytes_in_last_block); + +int archive_write_set_compression_bzip2(struct archive *); +int archive_write_set_compression_gzip(struct archive *); +int archive_write_set_compression_none(struct archive *); +/* A convenience function to set the format based on the code or name. */ +int archive_write_set_format(struct archive *, int format_code); +int archive_write_set_format_by_name(struct archive *, + const char *name); +/* To minimize link pollution, use one or more of the following. */ +int archive_write_set_format_cpio(struct archive *); +/* TODO: int archive_write_set_format_old_tar(struct archive *); */ +int archive_write_set_format_pax(struct archive *); +int archive_write_set_format_pax_restricted(struct archive *); +int archive_write_set_format_shar(struct archive *); +int archive_write_set_format_shar_dump(struct archive *); +int archive_write_set_format_ustar(struct archive *); +int archive_write_open(struct archive *, void *, + archive_open_callback *, archive_write_callback *, + archive_close_callback *); +int archive_write_open_fd(struct archive *, int _fd); +int archive_write_open_file(struct archive *, const char *_file); + +/* + * Note that the library will truncate writes beyond the size provided + * to archive_write_header or pad if the provided data is short. + */ +int archive_write_header(struct archive *, + struct archive_entry *); +int archive_write_data(struct archive *, const void *, size_t); +void archive_write_finish(struct archive *); + +/* + * Accessor functions to read/set various information in + * the struct archive object: + */ +/* Bytes written after compression or read before decompression. */ +int64_t archive_position_compressed(struct archive *); +/* Bytes written to compressor or read from decompressor. */ +int64_t archive_position_uncompressed(struct archive *); + +const char *archive_compression_name(struct archive *); +int archive_compression(struct archive *); +int archive_errno(struct archive *); +const char *archive_error_string(struct archive *); +const char *archive_format_name(struct archive *); +int archive_format(struct archive *); +/* void archive_set_errno(struct archive *, int); */ +/* void archive_error_printf(struct archive *, const char *fmt, ...); */ + +void archive_set_error(struct archive *, int _err, const char *fmt, ...); + +#endif /* !ARCHIVE_H_INCLUDED */ diff --git a/src/include/archive_entry.h b/src/include/archive_entry.h new file mode 100644 index 0000000..d77e255 --- /dev/null +++ b/src/include/archive_entry.h @@ -0,0 +1,207 @@ +/*- + * Copyright (c) 2003-2004 Tim Kientzle + * 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 + * in this position and unchanged. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR(S) 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. + * + * $FreeBSD: src/lib/libarchive/archive_entry.h,v 1.8 2004/05/03 01:40:34 kientzle Exp $ + */ + +#ifndef ARCHIVE_ENTRY_H_INCLUDED +#define ARCHIVE_ENTRY_H_INCLUDED + +#include +#include + +/* + * Description of an archive entry. + * + * Basically, a "struct stat" with a few text fields added in. + * + * TODO: Add "comment", "charset", and possibly other entries that are + * supported by "pax interchange" format. However, GNU, ustar, cpio, + * and other variants don't support these features, so they're not an + * excruciatingly high priority right now. + * + * TODO: "pax interchange" format allows essentially arbitrary + * key/value attributes to be attached to any entry. Supporting + * such extensions may make this library useful for special + * applications (e.g., a package manager could attach special + * package-management attributes to each entry). + * + * TODO: Design a good API for handling sparse files. + */ +struct archive_entry; + +/* + * Basic object manipulation + */ + +struct archive_entry *archive_entry_clear(struct archive_entry *); +/* The 'clone' function does a deep copy; all of the strings are copied too. */ +struct archive_entry *archive_entry_clone(struct archive_entry *); +void archive_entry_free(struct archive_entry *); +struct archive_entry *archive_entry_new(void); + +/* + * Retrieve fields from an archive_entry. + */ + +dev_t archive_entry_devmajor(struct archive_entry *); +dev_t archive_entry_devminor(struct archive_entry *); +const char *archive_entry_fflags_text(struct archive_entry *); +void archive_entry_fflags(struct archive_entry *, + unsigned long *set, unsigned long *clear); +const char *archive_entry_gname(struct archive_entry *); +const char *archive_entry_hardlink(struct archive_entry *); +mode_t archive_entry_mode(struct archive_entry *); +time_t archive_entry_mtime(struct archive_entry *); +long archive_entry_mtime_nsec(struct archive_entry *); +const char *archive_entry_pathname(struct archive_entry *); +const wchar_t *archive_entry_pathname_w(struct archive_entry *); +int64_t archive_entry_size(struct archive_entry *); +const struct stat *archive_entry_stat(struct archive_entry *); +const char *archive_entry_symlink(struct archive_entry *); +const char *archive_entry_uname(struct archive_entry *); + +/* + * Set fields in an archive_entry. + * + * Note that string 'set' functions do not copy the string, only the pointer. + * In contrast, 'copy' functions do copy the object pointed to. + */ + +void archive_entry_copy_stat(struct archive_entry *, const struct stat *); +void archive_entry_set_devmajor(struct archive_entry *, dev_t); +void archive_entry_set_devminor(struct archive_entry *, dev_t); +void archive_entry_set_fflags(struct archive_entry *, + unsigned long set, unsigned long clear); +/* Returns pointer to start of first invalid token, or NULL if none. */ +/* Note that all recognized tokens are processed, regardless. */ +const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *, + const wchar_t *); +void archive_entry_set_gid(struct archive_entry *, gid_t); +void archive_entry_set_gname(struct archive_entry *, const char *); +void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); +void archive_entry_set_hardlink(struct archive_entry *, const char *); +void archive_entry_copy_hardlink(struct archive_entry *, const char *); +void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *); +void archive_entry_set_link(struct archive_entry *, const char *); +void archive_entry_set_mode(struct archive_entry *, mode_t); +void archive_entry_set_pathname(struct archive_entry *, const char *); +void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *); +void archive_entry_set_size(struct archive_entry *, int64_t); +void archive_entry_set_symlink(struct archive_entry *, const char *); +void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); +void archive_entry_set_uid(struct archive_entry *, uid_t); +void archive_entry_set_uname(struct archive_entry *, const char *); +void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); + +/* + * ACL routines. This used to simply store and return text-format ACL + * strings, but that proved insufficient for a number of reasons: + * = clients need control over uname/uid and gname/gid mappings + * = there are many different ACL text formats + * = would like to be able to read/convert archives containing ACLs + * on platforms that lack ACL libraries + */ + +/* + * Permission bits mimic POSIX.1e. Note that I've not followed POSIX.1e's + * "permset"/"perm" abstract type nonsense. A permset is just a simple + * bitmap, following long-standing Unix tradition. + */ +#define ARCHIVE_ENTRY_ACL_EXECUTE 1 +#define ARCHIVE_ENTRY_ACL_WRITE 2 +#define ARCHIVE_ENTRY_ACL_READ 4 + +/* We need to be able to specify either or both of these. */ +#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256 +#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512 + +/* Tag values mimic POSIX.1e */ +#define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */ +#define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */ +#define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */ +#define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */ +#define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access. */ +#define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public. */ + +/* + * Set the ACL by clearing it and adding entries one at a time. + * Unlike the POSIX.1e ACL routines, you must specify the type + * (access/default) for each entry. Internally, the ACL data is just + * a soup of entries. API calls here allow you to retrieve just the + * entries of interest. This design (which goes against the spirit of + * POSIX.1e) is useful for handling archive formats that combine + * default and access information in a single ACL list. + */ +void archive_entry_acl_clear(struct archive_entry *); +void archive_entry_acl_add_entry(struct archive_entry *, + int type, int permset, int tag, int qual, const char *name); +void archive_entry_acl_add_entry_w(struct archive_entry *, + int type, int permset, int tag, int qual, const wchar_t *name); + +/* + * To retrieve the ACL, first "reset", then repeatedly ask for the + * "next" entry. The want_type parameter allows you to request only + * access entries or only default entries. + */ +int archive_entry_acl_reset(struct archive_entry *, int want_type); +int archive_entry_acl_next(struct archive_entry *, int want_type, + int *type, int *permset, int *tag, int *qual, const char **name); +int archive_entry_acl_next_w(struct archive_entry *, int want_type, + int *type, int *permset, int *tag, int *qual, + const wchar_t **name); + +/* + * Construct a text-format ACL. The flags argument is a bitmask that + * can include any of the following: + * + * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries. + * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries. + * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in + * each ACL entry. (As used by 'star'.) + * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each + * default ACL entry. + */ +#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024 +#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048 +const wchar_t *archive_entry_acl_text_w(struct archive_entry *, int flags); + +/* Return a count of entries matching 'want_type' */ +int archive_entry_acl_count(struct archive_entry *, int want_type); + +/* + * Private ACL parser. This is private because it handles some + * very weird formats that clients should not be messing with. + * Clients should only deal with their platform-native formats. + * Because of the need to support many formats cleanly, new arguments + * are likely to get added on a regular basis. Clients who try to use + * this interface are likely to be surprised when it changes. + * + * You were warned! + */ +int __archive_entry_acl_parse_w(struct archive_entry *, + const wchar_t *, int type); + +#endif /* !ARCHIVE_ENTRY_H_INCLUDED */ diff --git a/src/include/arpa/ftp.h b/src/include/arpa/ftp.h new file mode 100644 index 0000000..9a36488 --- /dev/null +++ b/src/include/arpa/ftp.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 1983, 1989, 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. + * + * @(#)ftp.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _ARPA_FTP_H_ +#define _ARPA_FTP_H_ + +/* Definitions for FTP; see RFC-765. */ + +/* + * Reply codes. + */ +#define PRELIM 1 /* positive preliminary */ +#define COMPLETE 2 /* positive completion */ +#define CONTINUE 3 /* positive intermediate */ +#define TRANSIENT 4 /* transient negative completion */ +#define ERROR 5 /* permanent negative completion */ + +/* + * Type codes + */ +#define TYPE_A 1 /* ASCII */ +#define TYPE_E 2 /* EBCDIC */ +#define TYPE_I 3 /* image */ +#define TYPE_L 4 /* local byte size */ + +#ifdef FTP_NAMES +char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; +#endif + +/* + * Form codes + */ +#define FORM_N 1 /* non-print */ +#define FORM_T 2 /* telnet format effectors */ +#define FORM_C 3 /* carriage control (ASA) */ +#ifdef FTP_NAMES +char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; +#endif + +/* + * Structure codes + */ +#define STRU_F 1 /* file (no record structure) */ +#define STRU_R 2 /* record structure */ +#define STRU_P 3 /* page structure */ +#ifdef FTP_NAMES +char *strunames[] = {"0", "File", "Record", "Page" }; +#endif + +/* + * Mode types + */ +#define MODE_S 1 /* stream */ +#define MODE_B 2 /* block */ +#define MODE_C 3 /* compressed */ +#ifdef FTP_NAMES +char *modenames[] = {"0", "Stream", "Block", "Compressed" }; +#endif + +/* + * Record Tokens + */ +#define REC_ESC '\377' /* Record-mode Escape */ +#define REC_EOR '\001' /* Record-mode End-of-Record */ +#define REC_EOF '\002' /* Record-mode End-of-File */ + +/* + * Block Header + */ +#define BLK_EOR 0x80 /* Block is End-of-Record */ +#define BLK_EOF 0x40 /* Block is End-of-File */ +#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */ +#define BLK_RESTART 0x10 /* Block is Restart Marker */ + +#define BLK_BYTECOUNT 2 /* Bytes in this block */ + +#endif /* !_FTP_H_ */ diff --git a/src/include/arpa/inet.h b/src/include/arpa/inet.h new file mode 100644 index 0000000..d50e466 --- /dev/null +++ b/src/include/arpa/inet.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) 1983, 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. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * @(#)inet.h 8.1 (Berkeley) 6/2/93 + * From: Id: inet.h,v 8.5 1997/01/29 08:48:09 vixie Exp $ + * $FreeBSD: src/include/arpa/inet.h,v 1.25 2002/08/21 16:19:56 mike Exp $ + */ + +#ifndef _ARPA_INET_H_ +#define _ARPA_INET_H_ + +/* External definitions for functions in inet(3), addr2ascii(3) */ + +#include +#include + +/* Required for byteorder(3) functions. */ +#include + +#define INET_ADDRSTRLEN 16 +#define INET6_ADDRSTRLEN 46 + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _IN_ADDR_T_DECLARED +typedef uint32_t in_addr_t; +#define _IN_ADDR_T_DECLARED +#endif + +#ifndef _IN_PORT_T_DECLARED +typedef uint16_t in_port_t; +#define _IN_PORT_T_DECLARED +#endif + +#if __BSD_VISIBLE +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif +#endif + +/* + * XXX socklen_t is used by a POSIX.1-2001 interface, but not required by + * POSIX.1-2001. + */ +#ifndef _SOCKLEN_T_DECLARED +typedef __socklen_t socklen_t; +#define _SOCKLEN_T_DECLARED +#endif + +#ifndef _STRUCT_IN_ADDR_DECLARED +struct in_addr { + in_addr_t s_addr; +}; +#define _STRUCT_IN_ADDR_DECLARED +#endif + +/* XXX all new diversions!! argh!! */ +#if __BSD_VISIBLE +#define inet_addr __inet_addr +#define inet_aton __inet_aton +#define inet_lnaof __inet_lnaof +#define inet_makeaddr __inet_makeaddr +#define inet_neta __inet_neta +#define inet_netof __inet_netof +#define inet_network __inet_network +#define inet_net_ntop __inet_net_ntop +#define inet_net_pton __inet_net_pton +#define inet_ntoa __inet_ntoa +#define inet_pton __inet_pton +#define inet_ntop __inet_ntop +#define inet_nsap_addr __inet_nsap_addr +#define inet_nsap_ntoa __inet_nsap_ntoa +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +uint32_t htonl(uint32_t); +uint16_t htons(uint16_t); +uint32_t ntohl(uint32_t); +uint16_t ntohs(uint16_t); +#endif + +in_addr_t inet_addr(const char *); +char *inet_ntoa(struct in_addr); +const char *inet_ntop(int, const void * __restrict, char * __restrict, + socklen_t); +int inet_pton(int, const char * __restrict, void * __restrict); + +#if __BSD_VISIBLE +int ascii2addr(int, const char *, void *); +char *addr2ascii(int, const void *, int, char *); +int inet_aton(const char *, struct in_addr *); +in_addr_t inet_lnaof(struct in_addr); +struct in_addr inet_makeaddr(in_addr_t, in_addr_t); +char * inet_neta(in_addr_t, char *, size_t); +in_addr_t inet_netof(struct in_addr); +in_addr_t inet_network(const char *); +char *inet_net_ntop(int, const void *, int, char *, size_t); +int inet_net_pton(int, const char *, void *, size_t); +unsigned inet_nsap_addr(const char *, unsigned char *, int); +char *inet_nsap_ntoa(int, const unsigned char *, char *); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif + +#endif /* !_ARPA_INET_H_ */ diff --git a/src/include/arpa/nameser.h b/src/include/arpa/nameser.h new file mode 100644 index 0000000..8735b8b --- /dev/null +++ b/src/include/arpa/nameser.h @@ -0,0 +1,449 @@ +/* + * Copyright (c) 1983, 1989, 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. + */ + +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * From: Id: nameser.h,v 8.16 1998/02/06 00:35:58 halley Exp + * $FreeBSD: src/include/arpa/nameser.h,v 1.16 2002/03/23 17:24:55 imp Exp $ + */ + +#ifndef _ARPA_NAMESER_H_ +#define _ARPA_NAMESER_H_ + +#define BIND_4_COMPAT + +#include +#include + +/* + * revision information. this is the release date in YYYYMMDD format. + * it can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__NAMESER > 19931104)". do not + * compare for equality; rather, use it to determine whether your libnameser.a + * is new enough to contain a certain feature. + */ + +/* XXXRTH I made this bigger than __BIND in 4.9.5 T6B */ +#define __NAMESER 19961001 /* New interface version stamp. */ + +/* + * Define constants based on RFC 883, RFC 1034, RFC 1035 + */ +#define NS_PACKETSZ 512 /* maximum packet size */ +#define NS_MAXDNAME 1025 /* maximum domain name */ +#define NS_MAXCDNAME 255 /* maximum compressed domain name */ +#define NS_MAXLABEL 63 /* maximum length of domain label */ +#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ +#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ +#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ +#define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */ +#define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */ +#define NS_INT8SZ 1 /* #/bytes of data in a u_int8_t */ +#define NS_INADDRSZ 4 /* IPv4 T_A */ +#define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */ +#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ +#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ + +/* + * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord() + * in synch with it. + */ +typedef enum __ns_sect { + ns_s_qd = 0, /* Query: Question. */ + ns_s_zn = 0, /* Update: Zone. */ + ns_s_an = 1, /* Query: Answer. */ + ns_s_pr = 1, /* Update: Prerequisites. */ + ns_s_ns = 2, /* Query: Name servers. */ + ns_s_ud = 2, /* Update: Update. */ + ns_s_ar = 3, /* Query|Update: Additional records. */ + ns_s_max = 4 +} ns_sect; + +/* + * This is a message handle. It is caller allocated and has no dynamic data. + * This structure is intended to be opaque to all but ns_parse.c, thus the + * leading _'s on the member names. Use the accessor functions, not the _'s. + */ +typedef struct __ns_msg { + const u_char *_msg, *_eom; + u_int16_t _id, _flags, _counts[ns_s_max]; + const u_char *_sections[ns_s_max]; + ns_sect _sect; + int _rrnum; + const u_char *_ptr; +} ns_msg; + +/* Private data structure - do not use from outside library. */ +struct _ns_flagdata { int mask, shift; }; +extern struct _ns_flagdata _ns_flagdata[]; + +/* Accessor macros - this is part of the public interface. */ +#define ns_msg_getflag(handle, flag) ( \ + ((handle)._flags & _ns_flagdata[flag].mask) \ + >> _ns_flagdata[flag].shift \ + ) +#define ns_msg_id(handle) ((handle)._id + 0) +#define ns_msg_base(handle) ((handle)._msg + 0) +#define ns_msg_end(handle) ((handle)._eom + 0) +#define ns_msg_size(handle) ((handle)._eom - (handle)._msg) +#define ns_msg_count(handle, section) ((handle)._counts[section] + 0) + +/* + * This is a parsed record. It is caller allocated and has no dynamic data. + */ +typedef struct __ns_rr { + char name[NS_MAXDNAME]; /* XXX need to malloc */ + u_int16_t type; + u_int16_t rr_class; + u_int32_t ttl; + u_int16_t rdlength; + const u_char *rdata; +} ns_rr; + +/* Accessor macros - this is part of the public interface. */ +#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") +#define ns_rr_type(rr) ((rr).type + 0) +#define ns_rr_class(rr) ((rr).rr_class + 0) +#define ns_rr_ttl(rr) ((rr).ttl + 0) +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_rdata(rr) ((rr).rdata + 0) + +/* + * These don't have to be in the same order as in the packet flags word, + * and they can even overlap in some cases, but they will need to be kept + * in synch with ns_parse.c:ns_flagdata[]. + */ +typedef enum __ns_flag { + ns_f_qr, /* Question/Response. */ + ns_f_opcode, /* Operation code. */ + ns_f_aa, /* Authoritative Answer. */ + ns_f_tc, /* Truncation occurred. */ + ns_f_rd, /* Recursion Desired. */ + ns_f_ra, /* Recursion Available. */ + ns_f_z, /* MBZ. */ + ns_f_ad, /* Authentic Data (DNSSEC). */ + ns_f_cd, /* Checking Disabled (DNSSEC). */ + ns_f_rcode, /* Response code. */ + ns_f_max +} ns_flag; + +/* + * Currently defined opcodes. + */ +typedef enum __ns_opcode { + ns_o_query = 0, /* Standard query. */ + ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ + ns_o_status = 2, /* Name server status query (unsupported). */ + /* Opcode 3 is undefined/reserved. */ + ns_o_notify = 4, /* Zone change notification. */ + ns_o_update = 5, /* Zone update message. */ + ns_o_max = 6 +} ns_opcode; + +/* + * Currently defined response codes. + */ +typedef enum __ns_rcode { + ns_r_noerror = 0, /* No error occurred. */ + ns_r_formerr = 1, /* Format error. */ + ns_r_servfail = 2, /* Server failure. */ + ns_r_nxdomain = 3, /* Name error. */ + ns_r_notimpl = 4, /* Unimplemented. */ + ns_r_refused = 5, /* Operation refused. */ + /* these are for BIND_UPDATE */ + ns_r_yxdomain = 6, /* Name exists */ + ns_r_yxrrset = 7, /* RRset exists */ + ns_r_nxrrset = 8, /* RRset does not exist */ + ns_r_notauth = 9, /* Not authoritative for zone */ + ns_r_notzone = 10, /* Zone of record different from zone section */ + ns_r_max = 11 +} ns_rcode; + +/* BIND_UPDATE */ +typedef enum __ns_update_operation { + ns_uop_delete = 0, + ns_uop_add = 1, + ns_uop_max = 2 +} ns_update_operation; + +/* + * This RR-like structure is particular to UPDATE. + */ +struct ns_updrec { + struct ns_updrec *r_prev; /* prev record */ + struct ns_updrec *r_next; /* next record */ + u_int8_t r_section; /* ZONE/PREREQUISITE/UPDATE */ + char * r_dname; /* owner of the RR */ + u_int16_t r_class; /* class number */ + u_int16_t r_type; /* type number */ + u_int32_t r_ttl; /* time to live */ + u_char * r_data; /* rdata fields as text string */ + u_int16_t r_size; /* size of r_data field */ + int r_opcode; /* type of operation */ + /* following fields for private use by the resolver/server routines */ + struct ns_updrec *r_grpnext; /* next record when grouped */ + struct databuf *r_dp; /* databuf to process */ + struct databuf *r_deldp; /* databuf's deleted/overwritten */ + u_int16_t r_zone; /* zone number on server */ +}; +typedef struct ns_updrec ns_updrec; + +/* + * Currently defined type values for resources and queries. + */ +typedef enum __ns_type { + ns_t_a = 1, /* Host address. */ + ns_t_ns = 2, /* Authoritative server. */ + ns_t_md = 3, /* Mail destination. */ + ns_t_mf = 4, /* Mail forwarder. */ + ns_t_cname = 5, /* Canonical name. */ + ns_t_soa = 6, /* Start of authority zone. */ + ns_t_mb = 7, /* Mailbox domain name. */ + ns_t_mg = 8, /* Mail group member. */ + ns_t_mr = 9, /* Mail rename name. */ + ns_t_null = 10, /* Null resource record. */ + ns_t_wks = 11, /* Well known service. */ + ns_t_ptr = 12, /* Domain name pointer. */ + ns_t_hinfo = 13, /* Host information. */ + ns_t_minfo = 14, /* Mailbox information. */ + ns_t_mx = 15, /* Mail routing information. */ + ns_t_txt = 16, /* Text strings. */ + ns_t_rp = 17, /* Responsible person. */ + ns_t_afsdb = 18, /* AFS cell database. */ + ns_t_x25 = 19, /* X_25 calling address. */ + ns_t_isdn = 20, /* ISDN calling address. */ + ns_t_rt = 21, /* Router. */ + ns_t_nsap = 22, /* NSAP address. */ + ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ + ns_t_sig = 24, /* Security signature. */ + ns_t_key = 25, /* Security key. */ + ns_t_px = 26, /* X.400 mail mapping. */ + ns_t_gpos = 27, /* Geographical position (withdrawn). */ + ns_t_aaaa = 28, /* Ip6 Address. */ + ns_t_loc = 29, /* Location Information. */ + ns_t_nxt = 30, /* Next domain (security). */ + ns_t_eid = 31, /* Endpoint identifier. */ + ns_t_nimloc = 32, /* Nimrod Locator. */ + ns_t_srv = 33, /* Server Selection. */ + ns_t_atma = 34, /* ATM Address */ + ns_t_naptr = 35, /* Naming Authority PoinTeR */ + ns_t_opt = 41, /* OPT pseudo-RR, RFC2761 */ + /* Query type values which do not appear in resource records. */ + ns_t_ixfr = 251, /* Incremental zone transfer. */ + ns_t_axfr = 252, /* Transfer zone of authority. */ + ns_t_mailb = 253, /* Transfer mailbox records. */ + ns_t_maila = 254, /* Transfer mail agent records. */ + ns_t_any = 255, /* Wildcard match. */ + ns_t_max = 65536 +} ns_type; + +/* + * Values for class field + */ +typedef enum __ns_class { + ns_c_in = 1, /* Internet. */ + /* Class 2 unallocated/unsupported. */ + ns_c_chaos = 3, /* MIT Chaos-net. */ + ns_c_hs = 4, /* MIT Hesiod. */ + /* Query class values which do not appear in resource records */ + ns_c_none = 254, /* for prereq. sections in update requests */ + ns_c_any = 255, /* Wildcard match. */ + ns_c_max = 65536 +} ns_class; + +/* + * Flags field of the KEY RR rdata + */ +#define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */ +#define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ +#define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ +#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */ +#define NS_KEY_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */ +/* The type bits can also be interpreted independently, as single bits: */ +#define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */ +#define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */ +#define NS_KEY_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */ +#define NS_KEY_RESERVED3 0x1000 /* reserved - must be zero */ +#define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */ +#define NS_KEY_USERACCOUNT 0x0400 /* key is assoc. with a user acct */ +#define NS_KEY_ENTITY 0x0200 /* key is assoc. with entity eg host */ +#define NS_KEY_ZONEKEY 0x0100 /* key is zone key */ +#define NS_KEY_IPSEC 0x0080 /* key is for IPSEC (host or user)*/ +#define NS_KEY_EMAIL 0x0040 /* key is for email (MIME security) */ +#define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */ +#define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */ +#define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */ + +#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED3 | \ + NS_KEY_RESERVED4 | \ + NS_KEY_RESERVED10 | \ + NS_KEY_RESERVED11 ) + +/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ +#define NS_ALG_MD5RSA 1 /* MD5 with RSA */ +#define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */ +#define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */ + +/* Signatures */ +#define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */ +#define NS_MD5RSA_MAX_BITS 2552 + /* Total of binary mod and exp */ +#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) + /* Max length of text sig block */ +#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) + +/* Offsets into SIG record rdata to find various values */ +#define NS_SIG_TYPE 0 /* Type flags */ +#define NS_SIG_ALG 2 /* Algorithm */ +#define NS_SIG_LABELS 3 /* How many labels in name */ +#define NS_SIG_OTTL 4 /* Original TTL */ +#define NS_SIG_EXPIR 8 /* Expiration time */ +#define NS_SIG_SIGNED 12 /* Signature time */ +#define NS_SIG_FOOT 16 /* Key footprint */ +#define NS_SIG_SIGNER 18 /* Domain name of who signed it */ + +/* How RR types are represented as bit-flags in NXT records */ +#define NS_NXT_BITS 8 +#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) + + +/* + * Inline versions of get/put short/long. Pointer is advanced. + */ +#define NS_GET16(s, cp) { \ + register u_char *t_cp = (u_char *)(cp); \ + (s) = ((u_int16_t)t_cp[0] << 8) \ + | ((u_int16_t)t_cp[1]) \ + ; \ + (cp) += NS_INT16SZ; \ +} + +#define NS_GET32(l, cp) { \ + register u_char *t_cp = (u_char *)(cp); \ + (l) = ((u_int32_t)t_cp[0] << 24) \ + | ((u_int32_t)t_cp[1] << 16) \ + | ((u_int32_t)t_cp[2] << 8) \ + | ((u_int32_t)t_cp[3]) \ + ; \ + (cp) += NS_INT32SZ; \ +} + +#define NS_PUT16(s, cp) { \ + register u_int16_t t_s = (u_int16_t)(s); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += NS_INT16SZ; \ +} + +#define NS_PUT32(l, cp) { \ + register u_int32_t t_l = (u_int32_t)(l); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += NS_INT32SZ; \ +} + +/* + * ANSI C identifier hiding. + */ +#define ns_get16 __ns_get16 +#define ns_get32 __ns_get32 +#define ns_put16 __ns_put16 +#define ns_put32 __ns_put32 +#define ns_initparse __ns_initparse +#define ns_parserr __ns_parserr +#define ns_sprintrr __ns_sprintrr +#define ns_sprintrrf __ns_sprintrrf +#define ns_format_ttl __ns_format_ttl +#define ns_parse_ttl __ns_parse_ttl +#define ns_name_ntop __ns_name_ntop +#define ns_name_pton __ns_name_pton +#define ns_name_unpack __ns_name_unpack +#define ns_name_pack __ns_name_pack +#define ns_name_compress __ns_name_compress +#define ns_name_uncompress __ns_name_uncompress + +__BEGIN_DECLS +u_int ns_get16(const u_char *); +u_long ns_get32(const u_char *); +void ns_put16(u_int, u_char *); +void ns_put32(u_long, u_char *); +int ns_initparse(const u_char *, int, ns_msg *); +int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); +int ns_sprintrr(const ns_msg *, const ns_rr *, + const char *, const char *, char *, size_t); +int ns_sprintrrf(const u_char *, size_t, const char *, + ns_class, ns_type, u_long, const u_char *, + size_t, const char *, const char *, + char *, size_t); +int ns_format_ttl(u_long, char *, size_t); +int ns_parse_ttl(const char *, u_long *); +int ns_name_ntop(const u_char *, char *, size_t); +int ns_name_pton(const char *, u_char *, size_t); +int ns_name_unpack(const u_char *, const u_char *, + const u_char *, u_char *, size_t); +int ns_name_pack(const u_char *, u_char *, int, + const u_char **, const u_char **); +int ns_name_uncompress(const u_char *, const u_char *, + const u_char *, char *, size_t); +int ns_name_compress(const char *, u_char *, size_t, + const u_char **, const u_char **); +int ns_name_skip(const u_char **, const u_char *); +__END_DECLS + +#ifdef BIND_4_COMPAT +#include +#endif + +#endif /* !_ARPA_NAMESER_H_ */ diff --git a/src/include/arpa/nameser_compat.h b/src/include/arpa/nameser_compat.h new file mode 100644 index 0000000..5f3e833 --- /dev/null +++ b/src/include/arpa/nameser_compat.h @@ -0,0 +1,195 @@ +/* Copyright (c) 1983, 1989 + * 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. + */ + +/* + * from nameser.h 8.1 (Berkeley) 6/2/93 + * From: Id: nameser_compat.h,v 8.9 1998/03/20 23:25:10 halley Exp + * $FreeBSD: src/include/arpa/nameser_compat.h,v 1.4 2002/05/28 04:32:25 mike Exp $ + */ + +#ifndef _ARPA_NAMESER_COMPAT_ +#define _ARPA_NAMESER_COMPAT_ + +#define __BIND 19950621 /* (DEAD) interface version stamp. */ + +#include + +#if !defined(_BYTE_ORDER) || \ + (_BYTE_ORDER != _BIG_ENDIAN && _BYTE_ORDER != _LITTLE_ENDIAN && \ + _BYTE_ORDER != _PDP_ENDIAN) + /* you must determine what the correct bit order is for + * your compiler - the next line is an intentional error + * which will force your compiles to bomb until you fix + * the above macros. + */ +#error "Undefined or invalid _BYTE_ORDER"; +#endif + +/* + * Structure for query header. The order of the fields is machine- and + * compiler-dependent, depending on the byte/bit order and the layout + * of bit fields. We use bit fields only in int variables, as this + * is all ANSI requires. This requires a somewhat confusing rearrangement. + */ + +typedef struct { + unsigned id :16; /* query identification number */ +#if _BYTE_ORDER == _BIG_ENDIAN + /* fields in third byte */ + unsigned qr: 1; /* response flag */ + unsigned opcode: 4; /* purpose of message */ + unsigned aa: 1; /* authoritive answer */ + unsigned tc: 1; /* truncated message */ + unsigned rd: 1; /* recursion desired */ + /* fields in fourth byte */ + unsigned ra: 1; /* recursion available */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /* authentic data from named */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned rcode :4; /* response code */ +#endif +#if _BYTE_ORDER == _LITTLE_ENDIAN || _BYTE_ORDER == _PDP_ENDIAN + /* fields in third byte */ + unsigned rd :1; /* recursion desired */ + unsigned tc :1; /* truncated message */ + unsigned aa :1; /* authoritive answer */ + unsigned opcode :4; /* purpose of message */ + unsigned qr :1; /* response flag */ + /* fields in fourth byte */ + unsigned rcode :4; /* response code */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /* recursion available */ +#endif + /* remaining bytes */ + unsigned qdcount :16; /* number of question entries */ + unsigned ancount :16; /* number of answer entries */ + unsigned nscount :16; /* number of authority entries */ + unsigned arcount :16; /* number of resource entries */ +} HEADER; + +#define PACKETSZ NS_PACKETSZ +#define MAXDNAME NS_MAXDNAME +#define MAXCDNAME NS_MAXCDNAME +#define MAXLABEL NS_MAXLABEL +#define HFIXEDSZ NS_HFIXEDSZ +#define QFIXEDSZ NS_QFIXEDSZ +#define RRFIXEDSZ NS_RRFIXEDSZ +#define INT32SZ NS_INT32SZ +#define INT16SZ NS_INT16SZ +#define INADDRSZ NS_INADDRSZ +#define IN6ADDRSZ NS_IN6ADDRSZ +#define INDIR_MASK NS_CMPRSFLGS +#define NAMESERVER_PORT NS_DEFAULTPORT + +#define S_ZONE ns_s_zn +#define S_PREREQ ns_s_pr +#define S_UPDATE ns_s_ud +#define S_ADDT ns_s_ar + +#define QUERY ns_o_query +#define IQUERY ns_o_iquery +#define STATUS ns_o_status +#define NS_NOTIFY_OP ns_o_notify +#define NS_UPDATE_OP ns_o_update + +#define NOERROR ns_r_noerror +#define FORMERR ns_r_formerr +#define SERVFAIL ns_r_servfail +#define NXDOMAIN ns_r_nxdomain +#define NOTIMP ns_r_notimpl +#define REFUSED ns_r_refused +#define YXDOMAIN ns_r_yxdomain +#define YXRRSET ns_r_yxrrset +#define NXRRSET ns_r_nxrrset +#define NOTAUTH ns_r_notauth +#define NOTZONE ns_r_notzone + +#define DELETE ns_uop_delete +#define ADD ns_uop_add + +#define T_A ns_t_a +#define T_NS ns_t_ns +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_CNAME ns_t_cname +#define T_SOA ns_t_soa +#define T_MB ns_t_mb +#define T_MG ns_t_mg +#define T_MR ns_t_mr +#define T_NULL ns_t_null +#define T_WKS ns_t_wks +#define T_PTR ns_t_ptr +#define T_HINFO ns_t_hinfo +#define T_MINFO ns_t_minfo +#define T_MX ns_t_mx +#define T_TXT ns_t_txt +#define T_RP ns_t_rp +#define T_AFSDB ns_t_afsdb +#define T_X25 ns_t_x25 +#define T_ISDN ns_t_isdn +#define T_RT ns_t_rt +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_SIG ns_t_sig +#define T_KEY ns_t_key +#define T_PX ns_t_px +#define T_GPOS ns_t_gpos +#define T_AAAA ns_t_aaaa +#define T_LOC ns_t_loc +#define T_NXT ns_t_nxt +#define T_EID ns_t_eid +#define T_NIMLOC ns_t_nimloc +#define T_SRV ns_t_srv +#define T_ATMA ns_t_atma +#define T_NAPTR ns_t_naptr +#define T_OPT ns_t_opt +#define T_IXFR ns_t_ixfr +#define T_AXFR ns_t_axfr +#define T_MAILB ns_t_mailb +#define T_MAILA ns_t_maila +#define T_ANY ns_t_any + +#define C_IN ns_c_in +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs +/* BIND_UPDATE */ +#define C_NONE ns_c_none +#define C_ANY ns_c_any + +#define GETSHORT NS_GET16 +#define GETLONG NS_GET32 +#define PUTSHORT NS_PUT16 +#define PUTLONG NS_PUT32 + +#endif /* _ARPA_NAMESER_COMPAT_ */ diff --git a/src/include/arpa/telnet.h b/src/include/arpa/telnet.h new file mode 100644 index 0000000..b152601 --- /dev/null +++ b/src/include/arpa/telnet.h @@ -0,0 +1,347 @@ +/* + * Copyright (c) 1983, 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. + * + * @(#)telnet.h 8.2 (Berkeley) 12/15/93 + * $FreeBSD: src/contrib/telnet/arpa/telnet.h,v 1.9 2003/01/18 06:10:21 billf Exp $ + */ + +#ifndef _ARPA_TELNET_H_ +#define _ARPA_TELNET_H_ + +/* + * Definitions for the TELNET protocol. + */ +#define IAC 255 /* interpret as command: */ +#define DONT 254 /* you are not to use option */ +#define DO 253 /* please, you use option */ +#define WONT 252 /* I won't use option */ +#define WILL 251 /* I will use option */ +#define SB 250 /* interpret as subnegotiation */ +#define GA 249 /* you may reverse the line */ +#define EL 248 /* erase the current line */ +#define EC 247 /* erase the current character */ +#define AYT 246 /* are you there */ +#define AO 245 /* abort output--but let prog finish */ +#define IP 244 /* interrupt process--permanently */ +#define BREAK 243 /* break */ +#define DM 242 /* data mark--for connect. cleaning */ +#define NOP 241 /* nop */ +#define SE 240 /* end sub negotiation */ +#define EOR 239 /* end of record (transparent mode) */ +#define ABORT 238 /* Abort process */ +#define SUSP 237 /* Suspend process */ +#define xEOF 236 /* End of file: EOF is already used... */ + +#define SYNCH 242 /* for telfunc calls */ + +#ifdef TELCMDS +const char *telcmds[] = { + "EOF", "SUSP", "ABORT", "EOR", + "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", + "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", + 0 +}; +#else +extern char *telcmds[]; +#endif + +#define TELCMD_FIRST xEOF +#define TELCMD_LAST IAC +#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ + (unsigned int)(x) >= TELCMD_FIRST) +#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] + +/* telnet options */ +#define TELOPT_BINARY 0 /* 8-bit data path */ +#define TELOPT_ECHO 1 /* echo */ +#define TELOPT_RCP 2 /* prepare to reconnect */ +#define TELOPT_SGA 3 /* suppress go ahead */ +#define TELOPT_NAMS 4 /* approximate message size */ +#define TELOPT_STATUS 5 /* give status */ +#define TELOPT_TM 6 /* timing mark */ +#define TELOPT_RCTE 7 /* remote controlled transmission and echo */ +#define TELOPT_NAOL 8 /* negotiate about output line width */ +#define TELOPT_NAOP 9 /* negotiate about output page size */ +#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */ +#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */ +#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */ +#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */ +#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */ +#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */ +#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */ +#define TELOPT_XASCII 17 /* extended ascic character set */ +#define TELOPT_LOGOUT 18 /* force logout */ +#define TELOPT_BM 19 /* byte macro */ +#define TELOPT_DET 20 /* data entry terminal */ +#define TELOPT_SUPDUP 21 /* supdup protocol */ +#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */ +#define TELOPT_SNDLOC 23 /* send location */ +#define TELOPT_TTYPE 24 /* terminal type */ +#define TELOPT_EOR 25 /* end or record */ +#define TELOPT_TUID 26 /* TACACS user identification */ +#define TELOPT_OUTMRK 27 /* output marking */ +#define TELOPT_TTYLOC 28 /* terminal location number */ +#define TELOPT_3270REGIME 29 /* 3270 regime */ +#define TELOPT_X3PAD 30 /* X.3 PAD */ +#define TELOPT_NAWS 31 /* window size */ +#define TELOPT_TSPEED 32 /* terminal speed */ +#define TELOPT_LFLOW 33 /* remote flow control */ +#define TELOPT_LINEMODE 34 /* Linemode option */ +#define TELOPT_XDISPLOC 35 /* X Display Location */ +#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */ +#define TELOPT_AUTHENTICATION 37/* Authenticate */ +#define TELOPT_ENCRYPT 38 /* Encryption option */ +#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */ +#define TELOPT_TN3270E 40 /* RFC2355 - TN3270 Enhancements */ +#define TELOPT_CHARSET 42 /* RFC2066 - Charset */ +#define TELOPT_COMPORT 44 /* RFC2217 - Com Port Control */ +#define TELOPT_KERMIT 47 /* RFC2840 - Kermit */ +#define TELOPT_EXOPL 255 /* extended-options-list */ + + +#define NTELOPTS (1+TELOPT_KERMIT) +#ifdef TELOPTS +const char *telopts[NTELOPTS+1] = { + "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", + "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", + "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", + "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", + "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", + "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", + "TACACS UID", "OUTPUT MARKING", "TTYLOC", + "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", + "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", + "ENCRYPT", "NEW-ENVIRON", "TN3270E", "CHARSET", "COM-PORT", + "KERMIT", + 0 +}; +#define TELOPT_FIRST TELOPT_BINARY +#define TELOPT_LAST TELOPT_KERMIT +#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) +#define TELOPT(x) telopts[(x)-TELOPT_FIRST] +#endif + +/* sub-option qualifiers */ +#define TELQUAL_IS 0 /* option is... */ +#define TELQUAL_SEND 1 /* send option */ +#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */ +#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */ +#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */ + +#define LFLOW_OFF 0 /* Disable remote flow control */ +#define LFLOW_ON 1 /* Enable remote flow control */ +#define LFLOW_RESTART_ANY 2 /* Restart output on any char */ +#define LFLOW_RESTART_XON 3 /* Restart output only on XON */ + +/* + * LINEMODE suboptions + */ + +#define LM_MODE 1 +#define LM_FORWARDMASK 2 +#define LM_SLC 3 + +#define MODE_EDIT 0x01 +#define MODE_TRAPSIG 0x02 +#define MODE_ACK 0x04 +#define MODE_SOFT_TAB 0x08 +#define MODE_LIT_ECHO 0x10 + +#define MODE_MASK 0x1f + +/* Not part of protocol, but needed to simplify things... */ +#define MODE_FLOW 0x0100 +#define MODE_ECHO 0x0200 +#define MODE_INBIN 0x0400 +#define MODE_OUTBIN 0x0800 +#define MODE_FORCE 0x1000 + +#define SLC_SYNCH 1 +#define SLC_BRK 2 +#define SLC_IP 3 +#define SLC_AO 4 +#define SLC_AYT 5 +#define SLC_EOR 6 +#define SLC_ABORT 7 +#define SLC_EOF 8 +#define SLC_SUSP 9 +#define SLC_EC 10 +#define SLC_EL 11 +#define SLC_EW 12 +#define SLC_RP 13 +#define SLC_LNEXT 14 +#define SLC_XON 15 +#define SLC_XOFF 16 +#define SLC_FORW1 17 +#define SLC_FORW2 18 +#define SLC_MCL 19 +#define SLC_MCR 20 +#define SLC_MCWL 21 +#define SLC_MCWR 22 +#define SLC_MCBOL 23 +#define SLC_MCEOL 24 +#define SLC_INSRT 25 +#define SLC_OVER 26 +#define SLC_ECR 27 +#define SLC_EWR 28 +#define SLC_EBOL 29 +#define SLC_EEOL 30 + +#define NSLC 30 + +/* + * For backwards compatibility, we define SLC_NAMES to be the + * list of names if SLC_NAMES is not defined. + */ +#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ + "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ + "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \ + "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \ + "MCEOL", "INSRT", "OVER", "ECR", "EWR", \ + "EBOL", "EEOL", \ + 0 + +#ifdef SLC_NAMES +const char *slc_names[] = { + SLC_NAMELIST +}; +#else +extern char *slc_names[]; +#define SLC_NAMES SLC_NAMELIST +#endif + +#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) +#define SLC_NAME(x) slc_names[x] + +#define SLC_NOSUPPORT 0 +#define SLC_CANTCHANGE 1 +#define SLC_VARIABLE 2 +#define SLC_DEFAULT 3 +#define SLC_LEVELBITS 0x03 + +#define SLC_FUNC 0 +#define SLC_FLAGS 1 +#define SLC_VALUE 2 + +#define SLC_ACK 0x80 +#define SLC_FLUSHIN 0x40 +#define SLC_FLUSHOUT 0x20 + +#define OLD_ENV_VAR 1 +#define OLD_ENV_VALUE 0 +#define NEW_ENV_VAR 0 +#define NEW_ENV_VALUE 1 +#define ENV_ESC 2 +#define ENV_USERVAR 3 + +/* + * AUTHENTICATION suboptions + */ + +/* + * Who is authenticating who ... + */ +#define AUTH_WHO_CLIENT 0 /* Client authenticating server */ +#define AUTH_WHO_SERVER 1 /* Server authenticating client */ +#define AUTH_WHO_MASK 1 + +/* + * amount of authentication done + */ +#define AUTH_HOW_ONE_WAY 0 +#define AUTH_HOW_MUTUAL 2 +#define AUTH_HOW_MASK 2 + +#define AUTHTYPE_NULL 0 +#define AUTHTYPE_KERBEROS_V4 1 +#define AUTHTYPE_KERBEROS_V5 2 +#define AUTHTYPE_SPX 3 +#define AUTHTYPE_MINK 4 +#define AUTHTYPE_SRA 6 +#define AUTHTYPE_CNT 7 + +#define AUTHTYPE_TEST 99 + +#ifdef AUTH_NAMES +const char *authtype_names[] = { + "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", NULL, "SRA", + 0 +}; +#else +extern char *authtype_names[]; +#endif + +#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) +#define AUTHTYPE_NAME(x) authtype_names[x] + +/* + * ENCRYPTion suboptions + */ +#define ENCRYPT_IS 0 /* I pick encryption type ... */ +#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */ +#define ENCRYPT_REPLY 2 /* Initial setup response */ +#define ENCRYPT_START 3 /* Am starting to send encrypted */ +#define ENCRYPT_END 4 /* Am ending encrypted */ +#define ENCRYPT_REQSTART 5 /* Request you start encrypting */ +#define ENCRYPT_REQEND 6 /* Request you end encrypting */ +#define ENCRYPT_ENC_KEYID 7 +#define ENCRYPT_DEC_KEYID 8 +#define ENCRYPT_CNT 9 + +#define ENCTYPE_ANY 0 +#define ENCTYPE_DES_CFB64 1 +#define ENCTYPE_DES_OFB64 2 +#define ENCTYPE_CNT 3 + +#ifdef ENCRYPT_NAMES +const char *encrypt_names[] = { + "IS", "SUPPORT", "REPLY", "START", "END", + "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", + 0 +}; +const char *enctype_names[] = { + "ANY", "DES_CFB64", "DES_OFB64", + 0 +}; +#else +extern char *encrypt_names[]; +extern char *enctype_names[]; +#endif + + +#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) +#define ENCRYPT_NAME(x) encrypt_names[x] + +#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) +#define ENCTYPE_NAME(x) enctype_names[x] + +#endif /* !_TELNET_H_ */ diff --git a/src/include/arpa/tftp.h b/src/include/arpa/tftp.h new file mode 100644 index 0000000..1de4dd4 --- /dev/null +++ b/src/include/arpa/tftp.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1983, 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. + * + * @(#)tftp.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/arpa/tftp.h,v 1.5 2001/09/27 20:50:14 obrien Exp $ + */ + +#ifndef _ARPA_TFTP_H_ +#define _ARPA_TFTP_H_ + +/* + * Trivial File Transfer Protocol (IEN-133) + */ +#define SEGSIZE 512 /* data segment size */ + +/* + * Packet types. + */ +#define RRQ 01 /* read request */ +#define WRQ 02 /* write request */ +#define DATA 03 /* data packet */ +#define ACK 04 /* acknowledgement */ +#define ERROR 05 /* error code */ +#define OACK 06 /* option acknowledgement */ + +struct tftphdr { + unsigned short th_opcode; /* packet type */ + union { + unsigned short tu_block; /* block # */ + unsigned short tu_code; /* error code */ + char tu_stuff[1]; /* request packet stuff */ + } th_u; + char th_data[1]; /* data or error string */ +}; + +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_stuff th_u.tu_stuff +#define th_msg th_data + +/* + * Error codes. + */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ +#define EOPTNEG 8 /* option negotiation failed */ + +#endif /* !_TFTP_H_ */ diff --git a/src/include/asn1_err.h b/src/include/asn1_err.h new file mode 100644 index 0000000..0604cbf --- /dev/null +++ b/src/include/asn1_err.h @@ -0,0 +1,29 @@ +/* Generated from /usr/src/kerberos5/lib/libasn1/../../../crypto/heimdal/lib/asn1/asn1_err.et */ +/* $Id$ */ + +#ifndef __asn1_err_h__ +#define __asn1_err_h__ + +struct et_list; + +void initialize_asn1_error_table_r(struct et_list **); + +void initialize_asn1_error_table(void); +#define init_asn1_err_tbl initialize_asn1_error_table + +typedef enum asn1_error_number{ + ASN1_BAD_TIMEFORMAT = 1859794432, + ASN1_MISSING_FIELD = 1859794433, + ASN1_MISPLACED_FIELD = 1859794434, + ASN1_TYPE_MISMATCH = 1859794435, + ASN1_OVERFLOW = 1859794436, + ASN1_OVERRUN = 1859794437, + ASN1_BAD_ID = 1859794438, + ASN1_BAD_LENGTH = 1859794439, + ASN1_BAD_FORMAT = 1859794440, + ASN1_PARSE_ERROR = 1859794441 +} asn1_error_number; + +#define ERROR_TABLE_BASE_asn1 1859794432 + +#endif /* __asn1_err_h__ */ diff --git a/src/include/assert.h b/src/include/assert.h new file mode 100644 index 0000000..5ad0135 --- /dev/null +++ b/src/include/assert.h @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)assert.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/include/assert.h,v 1.4 2002/03/23 17:24:53 imp Exp $ + */ + +#include + +/* + * Unlike other ANSI header files, may usefully be included + * multiple times, with and without NDEBUG defined. + */ + +#undef assert +#undef _assert + +#ifdef NDEBUG +#define assert(e) ((void)0) +#define _assert(e) ((void)0) +#else +#define _assert(e) assert(e) + +#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \ + __LINE__, #e)) +#endif /* NDEBUG */ + +__BEGIN_DECLS +void __assert(const char *, const char *, int, const char *); +__END_DECLS diff --git a/src/include/bitstring.h b/src/include/bitstring.h new file mode 100644 index 0000000..3dfb955 --- /dev/null +++ b/src/include/bitstring.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/bitstring.h,v 1.3 2003/06/13 19:40:13 phk Exp $ + */ + +#ifndef _BITSTRING_H_ +#define _BITSTRING_H_ + +#include + +#endif /* _BITSTRING_H_ */ + diff --git a/src/include/bluetooth.h b/src/include/bluetooth.h new file mode 100644 index 0000000..9c84cc6 --- /dev/null +++ b/src/include/bluetooth.h @@ -0,0 +1,78 @@ +/* + * bluetooth.h + * + * Copyright (c) 2001-2003 Maksim Yevmenkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $Id$ + * $FreeBSD: src/lib/libbluetooth/bluetooth.h,v 1.1 2003/10/12 22:04:18 emax Exp $ + */ + +#ifndef _BLUETOOTH_H_ +#define _BLUETOOTH_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +__BEGIN_DECLS + +/* + * Lunux BlueZ compatibility + */ + +#define bacmp(ba1, ba2) memcmp((ba1), (ba2), sizeof(bdaddr_t)) +#define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t)) +#define ba2str(ba, str) bt_ntoa((ba), (str)) +#define str2ba(str, ba) (bt_aton((str), (ba)) == 1? 0 : -1) + +/* + * Interface to the outside world + */ + +struct hostent * bt_gethostbyname (char const *name); +struct hostent * bt_gethostbyaddr (char const *addr, int len, int type); +struct hostent * bt_gethostent (void); +void bt_sethostent (int stayopen); +void bt_endhostent (void); + +struct protoent * bt_getprotobyname (char const *name); +struct protoent * bt_getprotobynumber (int proto); +struct protoent * bt_getprotoent (void); +void bt_setprotoent (int stayopen); +void bt_endprotoent (void); + +char const * bt_ntoa (bdaddr_t const *ba, char *str); +int bt_aton (char const *str, bdaddr_t *ba); + +__END_DECLS + +#endif /* ndef _BLUETOOTH_H_ */ + diff --git a/src/include/bsdxml.h b/src/include/bsdxml.h new file mode 100644 index 0000000..2694dbd --- /dev/null +++ b/src/include/bsdxml.h @@ -0,0 +1,901 @@ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file src/contrib/expat/COPYING for copying permission. +*/ + +#ifndef _BSD_XML_H_ +#define _BSD_XML_H_ 1 + + +#include + +#ifndef XMLPARSEAPI +#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__) +#ifdef _STATIC +#define XMLPARSEAPI(type) type __cdecl +#else +#define XMLPARSEAPI(type) __declspec(dllimport) type __cdecl +#endif +#else +#define XMLPARSEAPI(type) type +#endif +#endif /* not defined XMLPARSEAPI */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef XML_UNICODE_WCHAR_T +#define XML_UNICODE +#endif + +struct XML_ParserStruct; +typedef struct XML_ParserStruct *XML_Parser; + +#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ +#ifdef XML_UNICODE_WCHAR_T +typedef wchar_t XML_Char; +typedef wchar_t XML_LChar; +#else +typedef unsigned short XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE_WCHAR_T */ +#else /* Information is UTF-8 encoded. */ +typedef char XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE */ + +/* Should this be defined using stdbool.h when C99 is available? */ +typedef unsigned char XML_Bool; +#define XML_TRUE ((XML_Bool) 1) +#define XML_FALSE ((XML_Bool) 0) + +enum XML_Error { + XML_ERROR_NONE, + XML_ERROR_NO_MEMORY, + XML_ERROR_SYNTAX, + XML_ERROR_NO_ELEMENTS, + XML_ERROR_INVALID_TOKEN, + XML_ERROR_UNCLOSED_TOKEN, + XML_ERROR_PARTIAL_CHAR, + XML_ERROR_TAG_MISMATCH, + XML_ERROR_DUPLICATE_ATTRIBUTE, + XML_ERROR_JUNK_AFTER_DOC_ELEMENT, + XML_ERROR_PARAM_ENTITY_REF, + XML_ERROR_UNDEFINED_ENTITY, + XML_ERROR_RECURSIVE_ENTITY_REF, + XML_ERROR_ASYNC_ENTITY, + XML_ERROR_BAD_CHAR_REF, + XML_ERROR_BINARY_ENTITY_REF, + XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, + XML_ERROR_MISPLACED_XML_PI, + XML_ERROR_UNKNOWN_ENCODING, + XML_ERROR_INCORRECT_ENCODING, + XML_ERROR_UNCLOSED_CDATA_SECTION, + XML_ERROR_EXTERNAL_ENTITY_HANDLING, + XML_ERROR_NOT_STANDALONE, + XML_ERROR_UNEXPECTED_STATE, + XML_ERROR_ENTITY_DECLARED_IN_PE, + XML_ERROR_FEATURE_REQUIRES_XML_DTD, + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING +}; + +enum XML_Content_Type { + XML_CTYPE_EMPTY = 1, + XML_CTYPE_ANY, + XML_CTYPE_MIXED, + XML_CTYPE_NAME, + XML_CTYPE_CHOICE, + XML_CTYPE_SEQ +}; + +enum XML_Content_Quant { + XML_CQUANT_NONE, + XML_CQUANT_OPT, + XML_CQUANT_REP, + XML_CQUANT_PLUS +}; + +/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be + XML_CQUANT_NONE, and the other fields will be zero or NULL. + If type == XML_CTYPE_MIXED, then quant will be NONE or REP and + numchildren will contain number of elements that may be mixed in + and children point to an array of XML_Content cells that will be + all of XML_CTYPE_NAME type with no quantification. + + If type == XML_CTYPE_NAME, then the name points to the name, and + the numchildren field will be zero and children will be NULL. The + quant fields indicates any quantifiers placed on the name. + + CHOICE and SEQ will have name NULL, the number of children in + numchildren and children will point, recursively, to an array + of XML_Content cells. + + The EMPTY, ANY, and MIXED types will only occur at top level. +*/ + +typedef struct XML_cp XML_Content; + +struct XML_cp { + enum XML_Content_Type type; + enum XML_Content_Quant quant; + XML_Char * name; + unsigned int numchildren; + XML_Content * children; +}; + + +/* This is called for an element declaration. See above for + description of the model argument. It's the caller's responsibility + to free model when finished with it. +*/ +typedef void (*XML_ElementDeclHandler) (void *userData, + const XML_Char *name, + XML_Content *model); + +XMLPARSEAPI(void) +XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl); + +/* The Attlist declaration handler is called for *each* attribute. So + a single Attlist declaration with multiple attributes declared will + generate multiple calls to this handler. The "default" parameter + may be NULL in the case of the "#IMPLIED" or "#REQUIRED" + keyword. The "isrequired" parameter will be true and the default + value will be NULL in the case of "#REQUIRED". If "isrequired" is + true and default is non-NULL, then this is a "#FIXED" default. +*/ +typedef void (*XML_AttlistDeclHandler) (void *userData, + const XML_Char *elname, + const XML_Char *attname, + const XML_Char *att_type, + const XML_Char *dflt, + int isrequired); + +XMLPARSEAPI(void) +XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl); + +/* The XML declaration handler is called for *both* XML declarations + and text declarations. The way to distinguish is that the version + parameter will be NULL for text declarations. The encoding + parameter may be NULL for XML declarations. The standalone + parameter will be -1, 0, or 1 indicating respectively that there + was no standalone parameter in the declaration, that it was given + as no, or that it was given as yes. +*/ +typedef void (*XML_XmlDeclHandler) (void *userData, + const XML_Char *version, + const XML_Char *encoding, + int standalone); + +XMLPARSEAPI(void) +XML_SetXmlDeclHandler(XML_Parser parser, + XML_XmlDeclHandler xmldecl); + + +typedef struct { + void *(*malloc_fcn)(size_t size); + void *(*realloc_fcn)(void *ptr, size_t size); + void (*free_fcn)(void *ptr); +} XML_Memory_Handling_Suite; + +/* Constructs a new parser; encoding is the encoding specified by the + external protocol or NULL if there is none specified. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate(const XML_Char *encoding); + +/* Constructs a new parser and namespace processor. Element type + names and attribute names that belong to a namespace will be + expanded; unprefixed attribute names are never expanded; unprefixed + element type names are expanded only if there is a default + namespace. The expanded name is the concatenation of the namespace + URI, the namespace separator character, and the local part of the + name. If the namespace separator is '\0' then the namespace URI + and the local part will be concatenated without any separator. + When a namespace is not declared, the name and prefix will be + passed through without expansion. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); + + +/* Constructs a new parser using the memory management suit referred to + by memsuite. If memsuite is NULL, then use the standard library memory + suite. If namespaceSeparator is non-NULL it creates a parser with + namespace processing as described above. The character pointed at + will serve as the namespace separator. + + All further memory operations used for the created parser will come from + the given suite. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate_MM(const XML_Char *encoding, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *namespaceSeparator); + +/* Prepare a parser object to be re-used. This is particularly + valuable when memory allocation overhead is disproportionatly high, + such as when a large number of small documnents need to be parsed. + All handlers are cleared from the parser, except for the + unknownEncodingHandler. The parser's external state is re-initialized + except for the values of ns and ns_triplets. + + Added in Expat 1.95.3. +*/ +XMLPARSEAPI(XML_Bool) +XML_ParserReset(XML_Parser parser, const XML_Char *encoding); + +/* atts is array of name/value pairs, terminated by 0; + names and values are 0 terminated. +*/ +typedef void (*XML_StartElementHandler)(void *userData, + const XML_Char *name, + const XML_Char **atts); + +typedef void (*XML_EndElementHandler)(void *userData, + const XML_Char *name); + + +/* s is not 0 terminated. */ +typedef void (*XML_CharacterDataHandler)(void *userData, + const XML_Char *s, + int len); + +/* target and data are 0 terminated */ +typedef void (*XML_ProcessingInstructionHandler)(void *userData, + const XML_Char *target, + const XML_Char *data); + +/* data is 0 terminated */ +typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data); + +typedef void (*XML_StartCdataSectionHandler)(void *userData); +typedef void (*XML_EndCdataSectionHandler)(void *userData); + +/* This is called for any characters in the XML document for which + there is no applicable handler. This includes both characters that + are part of markup which is of a kind that is not reported + (comments, markup declarations), or characters that are part of a + construct which could be reported but for which no handler has been + supplied. The characters are passed exactly as they were in the XML + document except that they will be encoded in UTF-8 or UTF-16. + Line boundaries are not normalized. Note that a byte order mark + character is not passed to the default handler. There are no + guarantees about how characters are divided between calls to the + default handler: for example, a comment might be split between + multiple calls. +*/ +typedef void (*XML_DefaultHandler)(void *userData, + const XML_Char *s, + int len); + +/* This is called for the start of the DOCTYPE declaration, before + any DTD or internal subset is parsed. +*/ +typedef void (*XML_StartDoctypeDeclHandler)(void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset); + +/* This is called for the start of the DOCTYPE declaration when the + closing > is encountered, but after processing any external + subset. +*/ +typedef void (*XML_EndDoctypeDeclHandler)(void *userData); + +/* This is called for entity declarations. The is_parameter_entity + argument will be non-zero if the entity is a parameter entity, zero + otherwise. + + For internal entities (), value will + be non-NULL and systemId, publicID, and notationName will be NULL. + The value string is NOT nul-terminated; the length is provided in + the value_length argument. Since it is legal to have zero-length + values, do not use this argument to test for internal entities. + + For external entities, value will be NULL and systemId will be + non-NULL. The publicId argument will be NULL unless a public + identifier was provided. The notationName argument will have a + non-NULL value only for unparsed entity declarations. + + Note that is_parameter_entity can't be changed to XML_Bool, since + that would break binary compatibility. +*/ +typedef void (*XML_EntityDeclHandler) (void *userData, + const XML_Char *entityName, + int is_parameter_entity, + const XML_Char *value, + int value_length, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +XMLPARSEAPI(void) +XML_SetEntityDeclHandler(XML_Parser parser, + XML_EntityDeclHandler handler); + +/* OBSOLETE -- OBSOLETE -- OBSOLETE + This handler has been superceded by the EntityDeclHandler above. + It is provided here for backward compatibility. + + This is called for a declaration of an unparsed (NDATA) entity. + The base argument is whatever was set by XML_SetBase. The + entityName, systemId and notationName arguments will never be + NULL. The other arguments may be. +*/ +typedef void (*XML_UnparsedEntityDeclHandler)(void *userData, + const XML_Char *entityName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +/* This is called for a declaration of notation. The base argument is + whatever was set by XML_SetBase. The notationName will never be + NULL. The other arguments can be. +*/ +typedef void (*XML_NotationDeclHandler)(void *userData, + const XML_Char *notationName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* When namespace processing is enabled, these are called once for + each namespace declaration. The call to the start and end element + handlers occur between the calls to the start and end namespace + declaration handlers. For an xmlns attribute, prefix will be + NULL. For an xmlns="" attribute, uri will be NULL. +*/ +typedef void (*XML_StartNamespaceDeclHandler)(void *userData, + const XML_Char *prefix, + const XML_Char *uri); + +typedef void (*XML_EndNamespaceDeclHandler)(void *userData, + const XML_Char *prefix); + +/* This is called if the document is not standalone, that is, it has an + external subset or a reference to a parameter entity, but does not + have standalone="yes". If this handler returns 0, then processing + will not continue, and the parser will return a + XML_ERROR_NOT_STANDALONE error. + If parameter entity parsing is enabled, then in addition to the + conditions above this handler will only be called if the referenced + entity was actually read. +*/ +typedef int (*XML_NotStandaloneHandler)(void *userData); + +/* This is called for a reference to an external parsed general + entity. The referenced entity is not automatically parsed. The + application can parse it immediately or later using + XML_ExternalEntityParserCreate. + + The parser argument is the parser parsing the entity containing the + reference; it can be passed as the parser argument to + XML_ExternalEntityParserCreate. The systemId argument is the + system identifier as specified in the entity declaration; it will + not be NULL. + + The base argument is the system identifier that should be used as + the base for resolving systemId if systemId was relative; this is + set by XML_SetBase; it may be NULL. + + The publicId argument is the public identifier as specified in the + entity declaration, or NULL if none was specified; the whitespace + in the public identifier will have been normalized as required by + the XML spec. + + The context argument specifies the parsing context in the format + expected by the context argument to XML_ExternalEntityParserCreate; + context is valid only until the handler returns, so if the + referenced entity is to be parsed later, it must be copied. + + The handler should return 0 if processing should not continue + because of a fatal error in the handling of the external entity. + In this case the calling parser will return an + XML_ERROR_EXTERNAL_ENTITY_HANDLING error. + + Note that unlike other handlers the first argument is the parser, + not userData. +*/ +typedef int (*XML_ExternalEntityRefHandler)(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* This is called in two situations: + 1) An entity reference is encountered for which no declaration + has been read *and* this is not an error. + 2) An internal entity reference is read, but not expanded, because + XML_SetDefaultHandler has been called. + Note: skipped parameter entities in declarations and skipped general + entities in attribute values cannot be reported, because + the event would be out of sync with the reporting of the + declarations or attribute values +*/ +typedef void (*XML_SkippedEntityHandler)(void *userData, + const XML_Char *entityName, + int is_parameter_entity); + +/* This structure is filled in by the XML_UnknownEncodingHandler to + provide information to the parser about encodings that are unknown + to the parser. + + The map[b] member gives information about byte sequences whose + first byte is b. + + If map[b] is c where c is >= 0, then b by itself encodes the + Unicode scalar value c. + + If map[b] is -1, then the byte sequence is malformed. + + If map[b] is -n, where n >= 2, then b is the first byte of an + n-byte sequence that encodes a single Unicode scalar value. + + The data member will be passed as the first argument to the convert + function. + + The convert function is used to convert multibyte sequences; s will + point to a n-byte sequence where map[(unsigned char)*s] == -n. The + convert function must return the Unicode scalar value represented + by this byte sequence or -1 if the byte sequence is malformed. + + The convert function may be NULL if the encoding is a single-byte + encoding, that is if map[b] >= -1 for all bytes b. + + When the parser is finished with the encoding, then if release is + not NULL, it will call release passing it the data member; once + release has been called, the convert function will not be called + again. + + Expat places certain restrictions on the encodings that are supported + using this mechanism. + + 1. Every ASCII character that can appear in a well-formed XML document, + other than the characters + + $@\^`{}~ + + must be represented by a single byte, and that byte must be the + same byte that represents that character in ASCII. + + 2. No character may require more than 4 bytes to encode. + + 3. All characters encoded must have Unicode scalar values <= + 0xFFFF, (i.e., characters that would be encoded by surrogates in + UTF-16 are not allowed). Note that this restriction doesn't + apply to the built-in support for UTF-8 and UTF-16. + + 4. No Unicode character may be encoded by more than one distinct + sequence of bytes. +*/ +typedef struct { + int map[256]; + void *data; + int (*convert)(void *data, const char *s); + void (*release)(void *data); +} XML_Encoding; + +/* This is called for an encoding that is unknown to the parser. + + The encodingHandlerData argument is that which was passed as the + second argument to XML_SetUnknownEncodingHandler. + + The name argument gives the name of the encoding as specified in + the encoding declaration. + + If the callback can provide information about the encoding, it must + fill in the XML_Encoding structure, and return 1. Otherwise it + must return 0. + + If info does not describe a suitable encoding, then the parser will + return an XML_UNKNOWN_ENCODING error. +*/ +typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData, + const XML_Char *name, + XML_Encoding *info); + +XMLPARSEAPI(void) +XML_SetElementHandler(XML_Parser parser, + XML_StartElementHandler start, + XML_EndElementHandler end); + +XMLPARSEAPI(void) +XML_SetStartElementHandler(XML_Parser, XML_StartElementHandler); + +XMLPARSEAPI(void) +XML_SetEndElementHandler(XML_Parser, XML_EndElementHandler); + +XMLPARSEAPI(void) +XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler); + +XMLPARSEAPI(void) +XML_SetProcessingInstructionHandler(XML_Parser parser, + XML_ProcessingInstructionHandler handler); +XMLPARSEAPI(void) +XML_SetCommentHandler(XML_Parser parser, + XML_CommentHandler handler); + +XMLPARSEAPI(void) +XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end); + +XMLPARSEAPI(void) +XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start); + +XMLPARSEAPI(void) +XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end); + +/* This sets the default handler and also inhibits expansion of + internal entities. These entity references will be passed to the + default handler, or to the skipped entity handler, if one is set. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandler(XML_Parser parser, + XML_DefaultHandler handler); + +/* This sets the default handler but does not inhibit expansion of + internal entities. The entity reference will not be passed to the + default handler. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandlerExpand(XML_Parser parser, + XML_DefaultHandler handler); + +XMLPARSEAPI(void) +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler); + +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler); + +/* If a non-NULL value for arg is specified here, then it will be + passed as the first argument to the external entity ref handler + instead of the parser object. +*/ +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandlerArg(XML_Parser, void *arg); + +XMLPARSEAPI(void) +XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler); + +XMLPARSEAPI(void) +XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *encodingHandlerData); + +/* This can be called within a handler for a start element, end + element, processing instruction or character data. It causes the + corresponding markup to be passed to the default handler. +*/ +XMLPARSEAPI(void) +XML_DefaultCurrent(XML_Parser parser); + +/* If do_nst is non-zero, and namespace processing is in effect, and + a name has a prefix (i.e. an explicit namespace qualifier) then + that name is returned as a triplet in a single string separated by + the separator character specified when the parser was created: URI + + sep + local_name + sep + prefix. + + If do_nst is zero, then namespace information is returned in the + default manner (URI + sep + local_name) whether or not the name + has a prefix. + + Note: Calling XML_SetReturnNSTriplet after XML_Parse or + XML_ParseBuffer has no effect. +*/ + +XMLPARSEAPI(void) +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); + +/* This value is passed as the userData argument to callbacks. */ +XMLPARSEAPI(void) +XML_SetUserData(XML_Parser parser, void *userData); + +/* Returns the last value set by XML_SetUserData or NULL. */ +#define XML_GetUserData(parser) (*(void **)(parser)) + +/* This is equivalent to supplying an encoding argument to + XML_ParserCreate. On success XML_SetEncoding returns non-zero, + zero otherwise. + Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer + has no effect and returns zero. +*/ +XMLPARSEAPI(int) +XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); + +/* If this function is called, then the parser will be passed as the + first argument to callbacks instead of userData. The userData will + still be accessible using XML_GetUserData. +*/ +XMLPARSEAPI(void) +XML_UseParserAsHandlerArg(XML_Parser parser); + +/* If useDTD == XML_TRUE is passed to this function, then the parser + will assume that there is an external subset, even if none is + specified in the document. In such a case the parser will call the + externalEntityRefHandler with a value of NULL for the systemId + argument (the publicId and context arguments will be NULL as well). + Note: If this function is called, then this must be done before + the first call to XML_Parse or XML_ParseBuffer, since it will + have no effect after that. Returns + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. + Note: If the document does not have a DOCTYPE declaration at all, + then startDoctypeDeclHandler and endDoctypeDeclHandler will not + be called, despite an external subset being parsed. + Note: If XML_DTD is not defined when Expat is compiled, returns + XML_ERROR_FEATURE_REQUIRES_XML_DTD. +*/ +XMLPARSEAPI(enum XML_Error) +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); + + +/* Sets the base to be used for resolving relative URIs in system + identifiers in declarations. Resolving relative identifiers is + left to the application: this value will be passed through as the + base argument to the XML_ExternalEntityRefHandler, + XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base + argument will be copied. Returns zero if out of memory, non-zero + otherwise. +*/ +XMLPARSEAPI(int) +XML_SetBase(XML_Parser parser, const XML_Char *base); + +XMLPARSEAPI(const XML_Char *) +XML_GetBase(XML_Parser parser); + +/* Returns the number of the attribute/value pairs passed in last call + to the XML_StartElementHandler that were specified in the start-tag + rather than defaulted. Each attribute/value pair counts as 2; thus + this correspondds to an index into the atts array passed to the + XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetSpecifiedAttributeCount(XML_Parser parser); + +/* Returns the index of the ID attribute passed in the last call to + XML_StartElementHandler, or -1 if there is no ID attribute. Each + attribute/value pair counts as 2; thus this correspondds to an + index into the atts array passed to the XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetIdAttributeIndex(XML_Parser parser); + +/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is + detected. The last call to XML_Parse must have isFinal true; len + may be zero for this call (or any other). + + The XML_Status enum gives the possible return values for the + XML_Parse and XML_ParseBuffer functions. Though the return values + for these functions has always been described as a Boolean value, + the implementation, at least for the 1.95.x series, has always + returned exactly one of these values. The preprocessor #defines + are included so this stanza can be added to code that still needs + to support older versions of Expat 1.95.x: + + #ifndef XML_STATUS_OK + #define XML_STATUS_OK 1 + #define XML_STATUS_ERROR 0 + #endif + + Otherwise, the #define hackery is quite ugly and would have been dropped. +*/ +enum XML_Status { + XML_STATUS_ERROR = 0, +#define XML_STATUS_ERROR XML_STATUS_ERROR + XML_STATUS_OK = 1 +#define XML_STATUS_OK XML_STATUS_OK +}; + +XMLPARSEAPI(enum XML_Status) +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); + +XMLPARSEAPI(void *) +XML_GetBuffer(XML_Parser parser, int len); + +XMLPARSEAPI(enum XML_Status) +XML_ParseBuffer(XML_Parser parser, int len, int isFinal); + +/* Creates an XML_Parser object that can parse an external general + entity; context is a '\0'-terminated string specifying the parse + context; encoding is a '\0'-terminated string giving the name of + the externally specified encoding, or NULL if there is no + externally specified encoding. The context string consists of a + sequence of tokens separated by formfeeds (\f); a token consisting + of a name specifies that the general entity of the name is open; a + token of the form prefix=uri specifies the namespace for a + particular prefix; a token of the form =uri specifies the default + namespace. This can be called at any point after the first call to + an ExternalEntityRefHandler so longer as the parser has not yet + been freed. The new parser is completely independent and may + safely be used in a separate thread. The handlers and userData are + initialized from the parser argument. Returns 0 if out of memory. + Otherwise returns a new XML_Parser object. +*/ +XMLPARSEAPI(XML_Parser) +XML_ExternalEntityParserCreate(XML_Parser parser, + const XML_Char *context, + const XML_Char *encoding); + +enum XML_ParamEntityParsing { + XML_PARAM_ENTITY_PARSING_NEVER, + XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, + XML_PARAM_ENTITY_PARSING_ALWAYS +}; + +/* Controls parsing of parameter entities (including the external DTD + subset). If parsing of parameter entities is enabled, then + references to external parameter entities (including the external + DTD subset) will be passed to the handler set with + XML_SetExternalEntityRefHandler. The context passed will be 0. + + Unlike external general entities, external parameter entities can + only be parsed synchronously. If the external parameter entity is + to be parsed, it must be parsed during the call to the external + entity ref handler: the complete sequence of + XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and + XML_ParserFree calls must be made during this call. After + XML_ExternalEntityParserCreate has been called to create the parser + for the external parameter entity (context must be 0 for this + call), it is illegal to make any calls on the old parser until + XML_ParserFree has been called on the newly created parser. + If the library has been compiled without support for parameter + entity parsing (ie without XML_DTD being defined), then + XML_SetParamEntityParsing will return 0 if parsing of parameter + entities is requested; otherwise it will return non-zero. + Note: If XML_SetParamEntityParsing is called after XML_Parse or + XML_ParseBuffer, then it has no effect and will always return 0. +*/ +XMLPARSEAPI(int) +XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing parsing); + +/* If XML_Parse or XML_ParseBuffer have returned 0, then + XML_GetErrorCode returns information about the error. +*/ +XMLPARSEAPI(enum XML_Error) +XML_GetErrorCode(XML_Parser parser); + +/* These functions return information about the current parse + location. They may be called when XML_Parse or XML_ParseBuffer + return 0; in this case the location is the location of the + character at which the error was detected. + + They may also be called from any other callback called to report + some parse event; in this the location is the location of the first + of the sequence of characters that generated the event. +*/ +XMLPARSEAPI(int) XML_GetCurrentLineNumber(XML_Parser parser); +XMLPARSEAPI(int) XML_GetCurrentColumnNumber(XML_Parser parser); +XMLPARSEAPI(long) XML_GetCurrentByteIndex(XML_Parser parser); + +/* Return the number of bytes in the current event. + Returns 0 if the event is in an internal entity. +*/ +XMLPARSEAPI(int) +XML_GetCurrentByteCount(XML_Parser parser); + +/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets + the integer pointed to by offset to the offset within this buffer + of the current parse position, and sets the integer pointed to by size + to the size of this buffer (the number of input bytes). Otherwise + returns a NULL pointer. Also returns a NULL pointer if a parse isn't + active. + + NOTE: The character pointer returned should not be used outside + the handler that makes the call. +*/ +XMLPARSEAPI(const char *) +XML_GetInputContext(XML_Parser parser, + int *offset, + int *size); + +/* For backwards compatibility with previous versions. */ +#define XML_GetErrorLineNumber XML_GetCurrentLineNumber +#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber +#define XML_GetErrorByteIndex XML_GetCurrentByteIndex + +/* Frees memory used by the parser. */ +XMLPARSEAPI(void) +XML_ParserFree(XML_Parser parser); + +/* Returns a string describing the error. */ +XMLPARSEAPI(const XML_LChar *) +XML_ErrorString(enum XML_Error code); + +/* Return a string containing the version number of this expat */ +XMLPARSEAPI(const XML_LChar *) +XML_ExpatVersion(void); + +typedef struct { + int major; + int minor; + int micro; +} XML_Expat_Version; + +/* Return an XML_Expat_Version structure containing numeric version + number information for this version of expat. +*/ +XMLPARSEAPI(XML_Expat_Version) +XML_ExpatVersionInfo(void); + +/* Added in Expat 1.95.5. */ +enum XML_FeatureEnum { + XML_FEATURE_END = 0, + XML_FEATURE_UNICODE, + XML_FEATURE_UNICODE_WCHAR_T, + XML_FEATURE_DTD, + XML_FEATURE_CONTEXT_BYTES, + XML_FEATURE_MIN_SIZE, + XML_FEATURE_SIZEOF_XML_CHAR, + XML_FEATURE_SIZEOF_XML_LCHAR + /* Additional features must be added to the end of this enum. */ +}; + +typedef struct { + enum XML_FeatureEnum feature; + XML_LChar *name; + long int value; +} XML_Feature; + +XMLPARSEAPI(const XML_Feature *) +XML_GetFeatureList(void); + + +/* Expat follows the GNU/Linux convention of odd number minor version for + beta/development releases and even number minor version for stable + releases. Micro is bumped with each release, and set to 0 with each + change to major or minor version. +*/ +#define XML_MAJOR_VERSION 1 +#define XML_MINOR_VERSION 95 +#define XML_MICRO_VERSION 5 + +#ifdef __cplusplus +} +#endif + +#endif /* not _BSD_XML_H_ */ diff --git a/src/include/bzlib.h b/src/include/bzlib.h new file mode 100644 index 0000000..9ac43a1 --- /dev/null +++ b/src/include/bzlib.h @@ -0,0 +1,321 @@ + +/*-------------------------------------------------------------*/ +/*--- Public header file for the library. ---*/ +/*--- bzlib.h ---*/ +/*-------------------------------------------------------------*/ + +/*-- + This file is a part of bzip2 and/or libbzip2, a program and + library for lossless, block-sorting data compression. + + Copyright (C) 1996-2002 Julian R Seward. 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. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + + 3. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + + 4. The name of the author may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + + Julian Seward, Cambridge, UK. + jseward@acm.org + bzip2/libbzip2 version 1.0 of 21 March 2000 + + This program is based on (at least) the work of: + Mike Burrows + David Wheeler + Peter Fenwick + Alistair Moffat + Radford Neal + Ian H. Witten + Robert Sedgewick + Jon L. Bentley + + For more information on these sources, see the manual. +--*/ + + +#ifndef _BZLIB_H +#define _BZLIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define BZ_RUN 0 +#define BZ_FLUSH 1 +#define BZ_FINISH 2 + +#define BZ_OK 0 +#define BZ_RUN_OK 1 +#define BZ_FLUSH_OK 2 +#define BZ_FINISH_OK 3 +#define BZ_STREAM_END 4 +#define BZ_SEQUENCE_ERROR (-1) +#define BZ_PARAM_ERROR (-2) +#define BZ_MEM_ERROR (-3) +#define BZ_DATA_ERROR (-4) +#define BZ_DATA_ERROR_MAGIC (-5) +#define BZ_IO_ERROR (-6) +#define BZ_UNEXPECTED_EOF (-7) +#define BZ_OUTBUFF_FULL (-8) +#define BZ_CONFIG_ERROR (-9) + +typedef + struct { + char *next_in; + unsigned int avail_in; + unsigned int total_in_lo32; + unsigned int total_in_hi32; + + char *next_out; + unsigned int avail_out; + unsigned int total_out_lo32; + unsigned int total_out_hi32; + + void *state; + + void *(*bzalloc)(void *,int,int); + void (*bzfree)(void *,void *); + void *opaque; + } + bz_stream; + + +#ifndef BZ_IMPORT +#define BZ_EXPORT +#endif + +/* Need a definitition for FILE */ +#include + +#ifdef _WIN32 +# include +# ifdef small + /* windows.h define small to char */ +# undef small +# endif +# ifdef BZ_EXPORT +# define BZ_API(func) WINAPI func +# define BZ_EXTERN extern +# else + /* import windows dll dynamically */ +# define BZ_API(func) (WINAPI * func) +# define BZ_EXTERN +# endif +#else +# define BZ_API(func) func +# define BZ_EXTERN extern +#endif + + +/*-- Core (low-level) library functions --*/ + +BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( + bz_stream* strm, + int blockSize100k, + int verbosity, + int workFactor + ); + +BZ_EXTERN int BZ_API(BZ2_bzCompress) ( + bz_stream* strm, + int action + ); + +BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( + bz_stream* strm + ); + +BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( + bz_stream *strm, + int verbosity, + int small + ); + +BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( + bz_stream* strm + ); + +BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( + bz_stream *strm + ); + + + +/*-- High(er) level library functions --*/ + +#ifndef BZ_NO_STDIO +#define BZ_MAX_UNUSED 5000 + +typedef void BZFILE; + +BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( + int* bzerror, + FILE* f, + int verbosity, + int small, + void* unused, + int nUnused + ); + +BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( + int* bzerror, + BZFILE* b + ); + +BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( + int* bzerror, + BZFILE* b, + void** unused, + int* nUnused + ); + +BZ_EXTERN int BZ_API(BZ2_bzRead) ( + int* bzerror, + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( + int* bzerror, + FILE* f, + int blockSize100k, + int verbosity, + int workFactor + ); + +BZ_EXTERN void BZ_API(BZ2_bzWrite) ( + int* bzerror, + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( + int* bzerror, + BZFILE* b, + int abandon, + unsigned int* nbytes_in, + unsigned int* nbytes_out + ); + +BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( + int* bzerror, + BZFILE* b, + int abandon, + unsigned int* nbytes_in_lo32, + unsigned int* nbytes_in_hi32, + unsigned int* nbytes_out_lo32, + unsigned int* nbytes_out_hi32 + ); +#endif + + +/*-- Utility functions --*/ + +BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( + char* dest, + unsigned int* destLen, + char* source, + unsigned int sourceLen, + int blockSize100k, + int verbosity, + int workFactor + ); + +BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( + char* dest, + unsigned int* destLen, + char* source, + unsigned int sourceLen, + int small, + int verbosity + ); + + +/*-- + Code contributed by Yoshioka Tsuneo + (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp), + to support better zlib compatibility. + This code is not _officially_ part of libbzip2 (yet); + I haven't tested it, documented it, or considered the + threading-safeness of it. + If this code breaks, please contact both Yoshioka and me. +--*/ + +BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( + void + ); + +#ifndef BZ_NO_STDIO +BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( + const char *path, + const char *mode + ); + +BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( + int fd, + const char *mode + ); + +BZ_EXTERN int BZ_API(BZ2_bzread) ( + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN int BZ_API(BZ2_bzwrite) ( + BZFILE* b, + void* buf, + int len + ); + +BZ_EXTERN int BZ_API(BZ2_bzflush) ( + BZFILE* b + ); + +BZ_EXTERN void BZ_API(BZ2_bzclose) ( + BZFILE* b + ); + +BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( + BZFILE *b, + int *errnum + ); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/*-------------------------------------------------------------*/ +/*--- end bzlib.h ---*/ +/*-------------------------------------------------------------*/ diff --git a/src/include/calendar.h b/src/include/calendar.h new file mode 100644 index 0000000..378382a --- /dev/null +++ b/src/include/calendar.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 1997 Wolfgang Helbig + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libcalendar/calendar.h,v 1.4 1999/08/28 00:04:04 peter Exp $ + */ +struct date { + int y; /* year */ + int m; /* month */ + int d; /* day */ +}; + +struct date *easterg(int _year, struct date *_dt); +struct date *easterog(int _year, struct date *_dt); +struct date *easteroj(int _year, struct date *_dt); +struct date *gdate(int _nd, struct date *_dt); +struct date *jdate(int _nd, struct date *_dt); +int ndaysg(struct date *_dt); +int ndaysj(struct date *_dt); +int week(int _nd, int *_year); +int weekday(int _nd); diff --git a/src/include/camlib.h b/src/include/camlib.h new file mode 100644 index 0000000..a0d1817 --- /dev/null +++ b/src/include/camlib.h @@ -0,0 +1,181 @@ +/* + * Copyright (c) 1997, 1998 Kenneth D. Merry. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libcam/camlib.h,v 1.5 2002/04/23 23:58:20 obrien Exp $ + */ +/* + * Buffer encoding/decoding routines taken from the original FreeBSD SCSI + * library and slightly modified. The original header file had the following + * copyright: + */ +/* Copyright (c) 1994 HD Associates (hd@world.std.com) + * 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 HD Associates + * 4. Neither the name of the HD Associaates 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 HD ASSOCIATES``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 HD ASSOCIATES 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. + */ + + +#ifndef _CAMLIB_H +#define _CAMLIB_H + +#include +#include + +#include +#include + +#define CAM_ERRBUF_SIZE 2048 /* sizeof the CAM libarary error string */ + +/* + * Right now we hard code the transport layer device, but this will change + * if we ever get more than one transport layer. + */ +#define XPT_DEVICE "/dev/xpt0" + + +extern char cam_errbuf[]; + +struct cam_device { + char device_path[MAXPATHLEN];/* + * Pathname of the device + * given by the user. This + * may be null if the + * user states the device + * name and unit number + * separately. + */ + char given_dev_name[DEV_IDLEN+1];/* + * Device name given by + * the user. + */ + u_int32_t given_unit_number; /* + * Unit number given by + * the user. + */ + char device_name[DEV_IDLEN+1];/* + * Name of the device, + * e.g. 'pass' + */ + u_int32_t dev_unit_num; /* Unit number of the passthrough + * device associated with this + * particular device. + */ + + char sim_name[SIM_IDLEN+1]; /* Controller name, e.g. 'ahc' */ + u_int32_t sim_unit_number; /* Controller unit number */ + u_int32_t bus_id; /* Controller bus number */ + lun_id_t target_lun; /* Logical Unit Number */ + target_id_t target_id; /* Target ID */ + path_id_t path_id; /* System SCSI bus number */ + u_int16_t pd_type; /* type of peripheral device */ + struct scsi_inquiry_data inq_data; /* SCSI Inquiry data */ + u_int8_t serial_num[252]; /* device serial number */ + u_int8_t serial_num_len; /* length of the serial number */ + u_int8_t sync_period; /* Negotiated sync period */ + u_int8_t sync_offset; /* Negotiated sync offset */ + u_int8_t bus_width; /* Negotiated bus width */ + int fd; /* file descriptor for device */ +}; + +__BEGIN_DECLS +/* Basic utility commands */ +struct cam_device * cam_open_device(const char *path, int flags); +void cam_close_device(struct cam_device *dev); +void cam_close_spec_device(struct cam_device *dev); +struct cam_device * cam_open_spec_device(const char *dev_name, + int unit, int flags, + struct cam_device *device); +struct cam_device * cam_open_btl(path_id_t path_id, target_id_t target_id, + lun_id_t target_lun, int flags, + struct cam_device *device); +struct cam_device * cam_open_pass(const char *path, int flags, + struct cam_device *device); +union ccb * cam_getccb(struct cam_device *dev); +void cam_freeccb(union ccb *ccb); +int cam_send_ccb(struct cam_device *device, union ccb *ccb); +char * cam_path_string(struct cam_device *dev, char *str, + int len); +struct cam_device * cam_device_dup(struct cam_device *device); +void cam_device_copy(struct cam_device *src, + struct cam_device *dst); +int cam_get_device(const char *path, char *dev_name, + int devnamelen, int *unit); + +/* + * Buffer encoding/decoding routines, from the old SCSI library. + */ +int csio_decode(struct ccb_scsiio *csio, const char *fmt, ...) + __printflike(2, 3); +int csio_decode_visit(struct ccb_scsiio *csio, const char *fmt, + void (*arg_put)(void *, int, void *, int, char *), + void *puthook); +int buff_decode(u_int8_t *buff, size_t len, const char *fmt, ...) + __printflike(3, 4); +int buff_decode_visit(u_int8_t *buff, size_t len, const char *fmt, + void (*arg_put)(void *, int, void *, int, char *), + void *puthook); +int csio_build(struct ccb_scsiio *csio, u_int8_t *data_ptr, + u_int32_t dxfer_len, u_int32_t flags, int retry_count, + int timeout, const char *cmd_spec, ...); +int csio_build_visit(struct ccb_scsiio *csio, u_int8_t *data_ptr, + u_int32_t dxfer_len, u_int32_t flags, int retry_count, + int timeout, const char *cmd_spec, + int (*arg_get)(void *hook, char *field_name), + void *gethook); +int csio_encode(struct ccb_scsiio *csio, const char *fmt, ...) + __printflike(2, 3); +int buff_encode_visit(u_int8_t *buff, size_t len, const char *fmt, + int (*arg_get)(void *hook, char *field_name), + void *gethook); +int csio_encode_visit(struct ccb_scsiio *csio, const char *fmt, + int (*arg_get)(void *hook, char *field_name), + void *gethook); +__END_DECLS + +#endif /* _CAMLIB_H */ diff --git a/src/include/com_err.h b/src/include/com_err.h new file mode 100644 index 0000000..8979ffc --- /dev/null +++ b/src/include/com_err.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1997 - 2001 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $FreeBSD: src/contrib/com_err/com_err.h,v 1.3 2004/04/03 21:17:01 nectar Exp $ */ +/* $Id$ */ + +/* MIT compatible com_err library */ + +#ifndef __COM_ERR_H__ +#define __COM_ERR_H__ + +#include +#include + +#include + +typedef void (*errf) __P((const char *, long, const char *, va_list)); + +const char * error_message __P((long)); +int init_error_table __P((const char**, long, int)); + +void com_err_va __P((const char *, long, const char *, va_list)) + __printflike(3, 0); + +void com_err __P((const char *, long, const char *, ...)) + __printflike(3, 4); + +errf set_com_err_hook __P((errf)); +errf reset_com_err_hook __P((void)); + +const char *error_table_name __P((int num)); + +void add_to_error_table __P((struct et_list *new_table)); + +#endif /* __COM_ERR_H__ */ diff --git a/src/include/com_right.h b/src/include/com_right.h new file mode 100644 index 0000000..8d453bd --- /dev/null +++ b/src/include/com_right.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1997 - 2000 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $Id$ */ +/* $FreeBSD: src/contrib/com_err/com_right.h,v 1.3 2004/04/03 21:17:01 nectar Exp $ */ + +#ifndef __COM_RIGHT_H__ +#define __COM_RIGHT_H__ + +#include +#include + +struct error_table { + char const * const * msgs; + long base; + int n_msgs; +}; +struct et_list { + struct et_list *next; + struct error_table *table; +}; +extern struct et_list *_et_list; + +const char *com_right __P((struct et_list *list, long code)); +void initialize_error_table_r __P((struct et_list **, const char **, int, long)); +void free_error_table __P((struct et_list *)); + +#endif /* __COM_RIGHT_H__ */ diff --git a/src/include/complex.h b/src/include/complex.h new file mode 100644 index 0000000..8995280 --- /dev/null +++ b/src/include/complex.h @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2001 The FreeBSD Project. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/complex.h,v 1.2 2002/03/23 17:24:53 imp Exp $ + */ + +#ifndef _COMPLEX_H +#define _COMPLEX_H + +#ifdef __GNUC__ +#define _Complex __complex__ +#define _Complex_I 1.0fi +#endif + +#define complex _Complex +#define I _Complex_I + +#include + +__BEGIN_DECLS + +double cabs(double complex); +float cabsf(float complex); +double cimag(double complex); +float cimagf(float complex); +double creal(double complex); +float crealf(float complex); + +__END_DECLS + +#ifdef __GNUC__ +#define cimag(z) (__imag__ (z)) +#define cimagf(z) (__imag__ (z)) +#define creal(z) (__real__ (z)) +#define crealf(z) (__real__ (z)) +#endif + +#endif /* _COMPLEX_H */ diff --git a/src/include/cpio.h b/src/include/cpio.h new file mode 100644 index 0000000..d287af6 --- /dev/null +++ b/src/include/cpio.h @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/cpio.h,v 1.1 2002/08/01 07:18:38 mike Exp $ + */ + +#ifndef _CPIO_H_ +#define _CPIO_H_ + +#define C_ISSOCK 0140000 /* Socket. */ +#define C_ISLNK 0120000 /* Symbolic link. */ +#define C_ISCTG 0110000 /* Reserved. */ +#define C_ISREG 0100000 /* Regular file. */ +#define C_ISBLK 0060000 /* Block special. */ +#define C_ISDIR 0040000 /* Directory. */ +#define C_ISCHR 0020000 /* Character special. */ +#define C_ISFIFO 0010000 /* FIFO. */ +#define C_ISUID 0004000 /* Set user ID. */ +#define C_ISGID 0002000 /* Set group ID. */ +#define C_ISVTX 0001000 /* On directories, restricted deletion flag. */ +#define C_IRUSR 0000400 /* Read by owner. */ +#define C_IWUSR 0000200 /* Write by owner. */ +#define C_IXUSR 0000100 /* Execute by owner. */ +#define C_IRGRP 0000040 /* Read by group. */ +#define C_IWGRP 0000020 /* Write by group. */ +#define C_IXGRP 0000010 /* Execute by group. */ +#define C_IROTH 0000004 /* Read by others. */ +#define C_IWOTH 0000002 /* Write by others. */ +#define C_IXOTH 0000001 /* Execute by others. */ + +#define MAGIC "070707" + +#endif /* _CPIO_H_ */ diff --git a/src/include/ctype.h b/src/include/ctype.h new file mode 100644 index 0000000..c2e576e --- /dev/null +++ b/src/include/ctype.h @@ -0,0 +1,234 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + * + * @(#)ctype.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD: src/include/ctype.h,v 1.25 2004/04/21 13:25:55 tjr Exp $ + */ + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#include +#include + +#define _CTYPE_A 0x00000100L /* Alpha */ +#define _CTYPE_C 0x00000200L /* Control */ +#define _CTYPE_D 0x00000400L /* Digit */ +#define _CTYPE_G 0x00000800L /* Graph */ +#define _CTYPE_L 0x00001000L /* Lower */ +#define _CTYPE_P 0x00002000L /* Punct */ +#define _CTYPE_S 0x00004000L /* Space */ +#define _CTYPE_U 0x00008000L /* Upper */ +#define _CTYPE_X 0x00010000L /* X digit */ +#define _CTYPE_B 0x00020000L /* Blank */ +#define _CTYPE_R 0x00040000L /* Print */ +#define _CTYPE_I 0x00080000L /* Ideogram */ +#define _CTYPE_T 0x00100000L /* Special */ +#define _CTYPE_Q 0x00200000L /* Phonogram */ +#define _CTYPE_SW0 0x20000000L /* 0 width character */ +#define _CTYPE_SW1 0x40000000L /* 1 width character */ +#define _CTYPE_SW2 0x80000000L /* 2 width character */ +#define _CTYPE_SW3 0xc0000000L /* 3 width character */ + +__BEGIN_DECLS +int isalnum(int); +int isalpha(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); + +#if __XSI_VISIBLE +int _tolower(int); +int _toupper(int); +int isascii(int); +int toascii(int); +#endif + +#if __ISO_C_VISIBLE >= 1999 +int isblank(int); +#endif + +#if __BSD_VISIBLE +int digittoint(int); +int ishexnumber(int); +int isideogram(int); +int isnumber(int); +int isphonogram(int); +int isrune(int); +int isspecial(int); +#endif +__END_DECLS + +#define isalnum(c) __istype((c), _CTYPE_A|_CTYPE_D) +#define isalpha(c) __istype((c), _CTYPE_A) +#define iscntrl(c) __istype((c), _CTYPE_C) +#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */ +#define isgraph(c) __istype((c), _CTYPE_G) +#define islower(c) __istype((c), _CTYPE_L) +#define isprint(c) __istype((c), _CTYPE_R) +#define ispunct(c) __istype((c), _CTYPE_P) +#define isspace(c) __istype((c), _CTYPE_S) +#define isupper(c) __istype((c), _CTYPE_U) +#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */ +#define tolower(c) __tolower(c) +#define toupper(c) __toupper(c) + +#if __XSI_VISIBLE +/* + * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to + * tolower() and toupper() respectively, minus extra checking to ensure that + * the argument is a lower or uppercase letter respectively. We've chosen to + * implement these macros with the same error checking as tolower() and + * toupper() since this doesn't violate the specification itself, only its + * intent. We purposely leave _tolower() and _toupper() undocumented to + * discourage their use. + * + * XXX isascii() and toascii() should similarly be undocumented. + */ +#define _tolower(c) __tolower(c) +#define _toupper(c) __toupper(c) +#define isascii(c) (((c) & ~0x7F) == 0) +#define toascii(c) ((c) & 0x7F) +#endif + +#if __ISO_C_VISIBLE >= 1999 +#define isblank(c) __istype((c), _CTYPE_B) +#endif + +#if __BSD_VISIBLE +#define digittoint(c) __maskrune((c), 0xFF) +#define ishexnumber(c) __istype((c), _CTYPE_X) +#define isideogram(c) __istype((c), _CTYPE_I) +#define isnumber(c) __istype((c), _CTYPE_D) +#define isphonogram(c) __istype((c), _CTYPE_Q) +#define isrune(c) __istype((c), 0xFFFFFF00L) +#define isspecial(c) __istype((c), _CTYPE_T) +#endif + +/* See comments in about __ct_rune_t. */ +__BEGIN_DECLS +unsigned long ___runetype(__ct_rune_t); +__ct_rune_t ___tolower(__ct_rune_t); +__ct_rune_t ___toupper(__ct_rune_t); +__END_DECLS + +/* + * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us + * to generate code for extern versions of all our inline functions. + */ +#ifdef _EXTERNALIZE_CTYPE_INLINES_ +#define _USE_CTYPE_INLINE_ +#define static +#define __inline +#endif + +/* + * brings namespace pollution (struct member names). This prevents + * us from using the inline optimizations in the more strict __POSIX_VISIBLE and + * __XSI_VISIBLE namespaces. To fix this properly would require that we rename + * member names of long-standing structs, or something equally evil. + */ +#if !__BSD_VISIBLE && !defined(_USE_CTYPE_INLINE_) && \ + !defined(_DONT_USE_CTYPE_INLINE_) +#define _DONT_USE_CTYPE_INLINE_ +#endif + +/* + * Use inline functions if we are allowed to and the compiler supports them. + */ +#if !defined(_DONT_USE_CTYPE_INLINE_) && \ + (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) + +#include + +static __inline int +__maskrune(__ct_rune_t _c, unsigned long _f) +{ + return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : + _CurrentRuneLocale->runetype[_c]) & _f; +} + +static __inline int +__istype(__ct_rune_t _c, unsigned long _f) +{ + return (!!__maskrune(_c, _f)); +} + +static __inline int +__isctype(__ct_rune_t _c, unsigned long _f) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : + !!(_DefaultRuneLocale.runetype[_c] & _f); +} + +static __inline __ct_rune_t +__toupper(__ct_rune_t _c) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : + _CurrentRuneLocale->mapupper[_c]; +} + +static __inline __ct_rune_t +__tolower(__ct_rune_t _c) +{ + return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : + _CurrentRuneLocale->maplower[_c]; +} + +#else /* not using inlines */ + +__BEGIN_DECLS +int __maskrune(__ct_rune_t, unsigned long); +int __istype(__ct_rune_t, unsigned long); +int __isctype(__ct_rune_t, unsigned long); +__ct_rune_t __toupper(__ct_rune_t); +__ct_rune_t __tolower(__ct_rune_t); +__END_DECLS +#endif /* using inlines */ + +#endif /* !_CTYPE_H_ */ diff --git a/src/include/ctypes.h b/src/include/ctypes.h new file mode 100644 index 0000000..b817f43 --- /dev/null +++ b/src/include/ctypes.h @@ -0,0 +1,25 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +int toupper(int c); +int tolower(int c); \ No newline at end of file diff --git a/src/include/curses.h b/src/include/curses.h new file mode 100644 index 0000000..059fc5f --- /dev/null +++ b/src/include/curses.h @@ -0,0 +1,1194 @@ +/**************************************************************************** + * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim 1992,1995 * + * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * + ****************************************************************************/ + +/* $Id$ */ + +#ifndef __NCURSES_H +#define __NCURSES_H + +#define CURSES 1 +#define CURSES_H 1 + +/* This should be defined for the enhanced functionality to be visible. + * However, none of the wide-character (enhanced) functionality is implemented. + * So we do not define it (yet). +#define _XOPEN_CURSES 1 + */ + +/* These are defined only in curses.h, and are used for conditional compiles */ +#define NCURSES_VERSION_MAJOR 5 +#define NCURSES_VERSION_MINOR 2 +#define NCURSES_VERSION_PATCH 20020615 + +/* This is defined in more than one ncurses header, for identification */ +#undef NCURSES_VERSION +#define NCURSES_VERSION "5.2" + +#include + +#ifdef NCURSES_NOMACROS +#define NCURSES_ATTR_T attr_t +#endif + +#ifndef NCURSES_ATTR_T +#define NCURSES_ATTR_T int +#endif + +#undef NCURSES_CONST +#define NCURSES_CONST const + +#undef NCURSES_COLOR_T +#define NCURSES_COLOR_T short + +#undef NCURSES_SIZE_T +#define NCURSES_SIZE_T short + +#undef NCURSES_CH_T +#define NCURSES_CH_T chtype + +typedef unsigned long chtype; + +#include +#include +#include /* we need va_list */ +#ifdef _XOPEN_SOURCE_EXTENDED +#include /* we want wchar_t */ +#endif /* _XOPEN_SOURCE_EXTENDED */ + +/* XSI and SVr4 specify that curses implements 'bool'. However, C++ may also + * implement it. If so, we must use the C++ compiler's type to avoid conflict + * with other interfaces. + * + * A further complication is that may declare 'bool' to be a + * different type, such as an enum which is not necessarily compatible with + * C++. If we have , make 'bool' a macro, so users may #undef it. + * Otherwise, let it remain a typedef to avoid conflicts with other #define's. + * In either case, make a typedef for NCURSES_BOOL which can be used if needed + * from either C or C++. + */ + +#undef TRUE +#define TRUE 1 + +#undef FALSE +#define FALSE 0 + +typedef unsigned char NCURSES_BOOL; + +#if (!defined(__cplusplus) || !1) && (!0) + +#if 1 +#include +#endif + +#undef bool + +#if 1 +#define bool NCURSES_BOOL +#else +typedef unsigned char bool; +#endif + +#endif /* !__cplusplus, etc. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * XSI attributes. In the ncurses implementation, they are identical to the + * A_ attributes. + */ +#define WA_ATTRIBUTES A_ATTRIBUTES +#define WA_NORMAL A_NORMAL +#define WA_STANDOUT A_STANDOUT +#define WA_UNDERLINE A_UNDERLINE +#define WA_REVERSE A_REVERSE +#define WA_BLINK A_BLINK +#define WA_DIM A_DIM +#define WA_BOLD A_BOLD +#define WA_ALTCHARSET A_ALTCHARSET +#define WA_INVIS A_INVIS +#define WA_PROTECT A_PROTECT +#define WA_HORIZONTAL A_HORIZONTAL +#define WA_LEFT A_LEFT +#define WA_LOW A_LOW +#define WA_RIGHT A_RIGHT +#define WA_TOP A_TOP +#define WA_VERTICAL A_VERTICAL + +/* colors */ +extern NCURSES_EXPORT_VAR(int) COLORS; +extern NCURSES_EXPORT_VAR(int) COLOR_PAIRS; + +#define COLOR_BLACK 0 +#define COLOR_RED 1 +#define COLOR_GREEN 2 +#define COLOR_YELLOW 3 +#define COLOR_BLUE 4 +#define COLOR_MAGENTA 5 +#define COLOR_CYAN 6 +#define COLOR_WHITE 7 + +/* line graphics */ + +#if 0 +extern NCURSES_EXPORT_VAR(chtype*) _nc_acs_map(void); +#define acs_map (_nc_acs_map()) +#else +extern NCURSES_EXPORT_VAR(chtype) acs_map[]; +#endif + +/* VT100 symbols begin here */ +#define ACS_ULCORNER (acs_map['l']) /* upper left corner */ +#define ACS_LLCORNER (acs_map['m']) /* lower left corner */ +#define ACS_URCORNER (acs_map['k']) /* upper right corner */ +#define ACS_LRCORNER (acs_map['j']) /* lower right corner */ +#define ACS_LTEE (acs_map['t']) /* tee pointing right */ +#define ACS_RTEE (acs_map['u']) /* tee pointing left */ +#define ACS_BTEE (acs_map['v']) /* tee pointing up */ +#define ACS_TTEE (acs_map['w']) /* tee pointing down */ +#define ACS_HLINE (acs_map['q']) /* horizontal line */ +#define ACS_VLINE (acs_map['x']) /* vertical line */ +#define ACS_PLUS (acs_map['n']) /* large plus or crossover */ +#define ACS_S1 (acs_map['o']) /* scan line 1 */ +#define ACS_S9 (acs_map['s']) /* scan line 9 */ +#define ACS_DIAMOND (acs_map['`']) /* diamond */ +#define ACS_CKBOARD (acs_map['a']) /* checker board (stipple) */ +#define ACS_DEGREE (acs_map['f']) /* degree symbol */ +#define ACS_PLMINUS (acs_map['g']) /* plus/minus */ +#define ACS_BULLET (acs_map['~']) /* bullet */ +/* Teletype 5410v1 symbols begin here */ +#define ACS_LARROW (acs_map[',']) /* arrow pointing left */ +#define ACS_RARROW (acs_map['+']) /* arrow pointing right */ +#define ACS_DARROW (acs_map['.']) /* arrow pointing down */ +#define ACS_UARROW (acs_map['-']) /* arrow pointing up */ +#define ACS_BOARD (acs_map['h']) /* board of squares */ +#define ACS_LANTERN (acs_map['i']) /* lantern symbol */ +#define ACS_BLOCK (acs_map['0']) /* solid square block */ +/* + * These aren't documented, but a lot of System Vs have them anyway + * (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings). + * The ACS_names may not match AT&T's, our source didn't know them. + */ +#define ACS_S3 (acs_map['p']) /* scan line 3 */ +#define ACS_S7 (acs_map['r']) /* scan line 7 */ +#define ACS_LEQUAL (acs_map['y']) /* less/equal */ +#define ACS_GEQUAL (acs_map['z']) /* greater/equal */ +#define ACS_PI (acs_map['{']) /* Pi */ +#define ACS_NEQUAL (acs_map['|']) /* not equal */ +#define ACS_STERLING (acs_map['}']) /* UK pound sign */ + +/* + * Line drawing ACS names are of the form ACS_trbl, where t is the top, r + * is the right, b is the bottom, and l is the left. t, r, b, and l might + * be B (blank), S (single), D (double), or T (thick). The subset defined + * here only uses B and S. + */ +#define ACS_BSSB ACS_ULCORNER +#define ACS_SSBB ACS_LLCORNER +#define ACS_BBSS ACS_URCORNER +#define ACS_SBBS ACS_LRCORNER +#define ACS_SBSS ACS_RTEE +#define ACS_SSSB ACS_LTEE +#define ACS_SSBS ACS_BTEE +#define ACS_BSSS ACS_TTEE +#define ACS_BSBS ACS_HLINE +#define ACS_SBSB ACS_VLINE +#define ACS_SSSS ACS_PLUS + +#if defined(ERR) && ((ERR) != -1) +#undef ERR +#endif + +#if !defined(ERR) +#define ERR (-1) +#endif + +#if defined(OK) && ((OK) != 0) +#undef OK +#endif + +#if !defined(OK) +#define OK (0) +#endif + +/* values for the _flags member */ +#define _SUBWIN 0x01 /* is this a sub-window? */ +#define _ENDLINE 0x02 /* is the window flush right? */ +#define _FULLWIN 0x04 /* is the window full-screen? */ +#define _SCROLLWIN 0x08 /* bottom edge is at screen bottom? */ +#define _ISPAD 0x10 /* is this window a pad? */ +#define _HASMOVED 0x20 /* has cursor moved since last refresh? */ +#define _WRAPPED 0x40 /* cursor was just wrappped */ + +/* + * this value is used in the firstchar and lastchar fields to mark + * unchanged lines + */ +#define _NOCHANGE -1 + +/* + * this value is used in the oldindex field to mark lines created by insertions + * and scrolls. + */ +#define _NEWINDEX -1 + +typedef struct screen SCREEN; +typedef struct _win_st WINDOW; + +typedef chtype attr_t; /* ...must be at least as wide as chtype */ + +#ifdef _XOPEN_SOURCE_EXTENDED + +#if 0 +#ifdef mblen /* libutf8.h defines it w/o undefining first */ +#undef mblen +#endif +#include +#define __wchar_t +#define __wint_t +#endif + +#if 0 +#include /* ...to get mbstate_t, etc. */ +#endif + +#ifndef __wchar_t +typedef unsigned long wchar_t; +#endif /* __wchar_t */ +#ifndef __wint_t +typedef long int wint_t; +#endif /* __wint_t */ + +#define CCHARW_MAX 5 +typedef struct +{ + attr_t attr; + wchar_t chars[CCHARW_MAX]; +} +cchar_t; + +#endif /* _XOPEN_SOURCE_EXTENDED */ + +struct ldat; + +struct _win_st +{ + NCURSES_SIZE_T _cury, _curx; /* current cursor position */ + + /* window location and size */ + NCURSES_SIZE_T _maxy, _maxx; /* maximums of x and y, NOT window size */ + NCURSES_SIZE_T _begy, _begx; /* screen coords of upper-left-hand corner */ + + short _flags; /* window state flags */ + + /* attribute tracking */ + attr_t _attrs; /* current attribute for non-space character */ + chtype _bkgd; /* current background char/attribute pair */ + + /* option values set by user */ + bool _notimeout; /* no time out on function-key entry? */ + bool _clear; /* consider all data in the window invalid? */ + bool _leaveok; /* OK to not reset cursor on exit? */ + bool _scroll; /* OK to scroll this window? */ + bool _idlok; /* OK to use insert/delete line? */ + bool _idcok; /* OK to use insert/delete char? */ + bool _immed; /* window in immed mode? (not yet used) */ + bool _sync; /* window in sync mode? */ + bool _use_keypad; /* process function keys into KEY_ symbols? */ + int _delay; /* 0 = nodelay, <0 = blocking, >0 = delay */ + + struct ldat *_line; /* the actual line data */ + + /* global screen state */ + NCURSES_SIZE_T _regtop; /* top line of scrolling region */ + NCURSES_SIZE_T _regbottom; /* bottom line of scrolling region */ + + /* these are used only if this is a sub-window */ + int _parx; /* x coordinate of this window in parent */ + int _pary; /* y coordinate of this window in parent */ + WINDOW *_parent; /* pointer to parent if a sub-window */ + + /* these are used only if this is a pad */ + struct pdat + { + NCURSES_SIZE_T _pad_y, _pad_x; + NCURSES_SIZE_T _pad_top, _pad_left; + NCURSES_SIZE_T _pad_bottom, _pad_right; + } _pad; + + NCURSES_SIZE_T _yoffset; /* real begy is _begy + _yoffset */ + +#ifdef _XOPEN_SOURCE_EXTENDED + cchar_t _bkgrnd; /* current background char/attribute pair */ +#endif +}; + +extern NCURSES_EXPORT_VAR(WINDOW *) stdscr; +extern NCURSES_EXPORT_VAR(WINDOW *) curscr; +extern NCURSES_EXPORT_VAR(WINDOW *) newscr; + +extern NCURSES_EXPORT_VAR(int) LINES; +extern NCURSES_EXPORT_VAR(int) COLS; +extern NCURSES_EXPORT_VAR(int) TABSIZE; + +/* + * This global was an undocumented feature under AIX curses. + */ +extern NCURSES_EXPORT_VAR(int) ESCDELAY; /* ESC expire time in milliseconds */ + +extern NCURSES_EXPORT_VAR(char) ttytype[]; /* needed for backward compatibility */ + +/* + * These functions are extensions - not in XSI Curses. + */ +#if 1 +extern NCURSES_EXPORT(bool) is_term_resized (int, int); +extern NCURSES_EXPORT(char *) keybound (int, int); +extern NCURSES_EXPORT(const char *) curses_version (void); +extern NCURSES_EXPORT(int) assume_default_colors (int, int); +extern NCURSES_EXPORT(int) define_key (char *, int); +extern NCURSES_EXPORT(int) keyok (int, bool); +extern NCURSES_EXPORT(int) resize_term (int, int); +extern NCURSES_EXPORT(int) resizeterm (int, int); +extern NCURSES_EXPORT(int) use_default_colors (void); +extern NCURSES_EXPORT(int) use_extended_names (bool); +extern NCURSES_EXPORT(int) wresize (WINDOW *, int, int); +#else +#define curses_version() NCURSES_VERSION +#endif + +/* + * GCC (and some other compilers) define '__attribute__'; we're using this + * macro to alert the compiler to flag inconsistencies in printf/scanf-like + * function calls. Just in case '__attribute__' isn't defined, make a dummy. + * G++ doesn't accept it anyway. + */ +#if !defined(__GNUC__) && !defined(__attribute__) +#define __attribute__(p) /* nothing */ +#endif + +/* + * For g++, turn off our macros that use __attribute__ (g++ recognizes some + * of them, but not at the same version levels as gcc). + */ +#ifdef __cplusplus +#undef GCC_NORETURN +#undef GCC_PRINTF +#undef GCC_SCANF +#undef GCC_UNUSED +#endif + +/* + * We cannot define these in ncurses_cfg.h, since they require parameters to be + * passed (that's non-portable). + */ +#ifndef GCC_PRINTFLIKE +#if defined(GCC_PRINTF) && !defined(printf) +#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) +#else +#define GCC_PRINTFLIKE(fmt,var) /*nothing*/ +#endif +#endif + +#ifndef GCC_SCANFLIKE +#if defined(GCC_SCANF) && !defined(scanf) +#define GCC_SCANFLIKE(fmt,var) __attribute__((format(scanf,fmt,var))) +#else +#define GCC_SCANFLIKE(fmt,var) /*nothing*/ +#endif +#endif + +#ifndef GCC_NORETURN +#define GCC_NORETURN /* nothing */ +#endif + +#ifndef GCC_UNUSED +#define GCC_UNUSED /* nothing */ +#endif + +/* + * Function prototypes. This is the complete XSI Curses list of required + * functions. Those marked `generated' will have sources generated from the + * macro definitions later in this file, in order to satisfy XPG4.2 + * requirements. + */ + +extern NCURSES_EXPORT(int) addch (const chtype); /* generated */ +extern NCURSES_EXPORT(int) addchnstr (const chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) addchstr (const chtype *); /* generated */ +extern NCURSES_EXPORT(int) addnstr (const char *, int); /* generated */ +extern NCURSES_EXPORT(int) addstr (const char *); /* generated */ +extern NCURSES_EXPORT(int) attroff (NCURSES_ATTR_T); /* generated */ +extern NCURSES_EXPORT(int) attron (NCURSES_ATTR_T); /* generated */ +extern NCURSES_EXPORT(int) attrset (NCURSES_ATTR_T); /* generated */ +extern NCURSES_EXPORT(int) attr_get (attr_t *, short *, void *); /* generated */ +extern NCURSES_EXPORT(int) attr_off (attr_t, void *); /* generated */ +extern NCURSES_EXPORT(int) attr_on (attr_t, void *); /* generated */ +extern NCURSES_EXPORT(int) attr_set (attr_t, short, void *); /* generated */ +extern NCURSES_EXPORT(int) baudrate (void); /* implemented */ +extern NCURSES_EXPORT(int) beep (void); /* implemented */ +extern NCURSES_EXPORT(int) bkgd (chtype); /* generated */ +extern NCURSES_EXPORT(void) bkgdset (chtype); /* generated */ +extern NCURSES_EXPORT(int) border (chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* generated */ +extern NCURSES_EXPORT(int) box (WINDOW *, chtype, chtype); /* generated */ +extern NCURSES_EXPORT(bool) can_change_color (void); /* implemented */ +extern NCURSES_EXPORT(int) cbreak (void); /* implemented */ +extern NCURSES_EXPORT(int) chgat (int, attr_t, short, const void *); /* generated */ +extern NCURSES_EXPORT(int) clear (void); /* generated */ +extern NCURSES_EXPORT(int) clearok (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) clrtobot (void); /* generated */ +extern NCURSES_EXPORT(int) clrtoeol (void); /* generated */ +extern NCURSES_EXPORT(int) color_content (short,short*,short*,short*); /* implemented */ +extern NCURSES_EXPORT(int) color_set (short,void*); /* generated */ +extern NCURSES_EXPORT(int) COLOR_PAIR (int); /* generated */ +extern NCURSES_EXPORT(int) copywin (const WINDOW*,WINDOW*,int,int,int,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) curs_set (int); /* implemented */ +extern NCURSES_EXPORT(int) def_prog_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) def_shell_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) delay_output (int); /* implemented */ +extern NCURSES_EXPORT(int) delch (void); /* generated */ +extern NCURSES_EXPORT(void) delscreen (SCREEN *); /* implemented */ +extern NCURSES_EXPORT(int) delwin (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) deleteln (void); /* generated */ +extern NCURSES_EXPORT(WINDOW *) derwin (WINDOW *,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) doupdate (void); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) dupwin (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) echo (void); /* implemented */ +extern NCURSES_EXPORT(int) echochar (const chtype); /* generated */ +extern NCURSES_EXPORT(int) erase (void); /* generated */ +extern NCURSES_EXPORT(int) endwin (void); /* implemented */ +extern NCURSES_EXPORT(char) erasechar (void); /* implemented */ +extern NCURSES_EXPORT(void) filter (void); /* implemented */ +extern NCURSES_EXPORT(int) flash (void); /* implemented */ +extern NCURSES_EXPORT(int) flushinp (void); /* implemented */ +extern NCURSES_EXPORT(chtype) getbkgd (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getch (void); /* generated */ +extern NCURSES_EXPORT(int) getnstr (char *, int); /* generated */ +extern NCURSES_EXPORT(int) getstr (char *); /* generated */ +extern NCURSES_EXPORT(WINDOW *) getwin (FILE *); /* implemented */ +extern NCURSES_EXPORT(int) halfdelay (int); /* implemented */ +extern NCURSES_EXPORT(bool) has_colors (void); /* implemented */ +extern NCURSES_EXPORT(bool) has_ic (void); /* implemented */ +extern NCURSES_EXPORT(bool) has_il (void); /* implemented */ +extern NCURSES_EXPORT(int) hline (chtype, int); /* generated */ +extern NCURSES_EXPORT(void) idcok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(int) idlok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(void) immedok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(chtype) inch (void); /* generated */ +extern NCURSES_EXPORT(int) inchnstr (chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) inchstr (chtype *); /* generated */ +extern NCURSES_EXPORT(WINDOW *) initscr (void); /* implemented */ +extern NCURSES_EXPORT(int) init_color (short,short,short,short); /* implemented */ +extern NCURSES_EXPORT(int) init_pair (short,short,short); /* implemented */ +extern NCURSES_EXPORT(int) innstr (char *, int); /* generated */ +extern NCURSES_EXPORT(int) insch (chtype); /* generated */ +extern NCURSES_EXPORT(int) insdelln (int); /* generated */ +extern NCURSES_EXPORT(int) insertln (void); /* generated */ +extern NCURSES_EXPORT(int) insnstr (const char *, int); /* generated */ +extern NCURSES_EXPORT(int) insstr (const char *); /* generated */ +extern NCURSES_EXPORT(int) instr (char *); /* generated */ +extern NCURSES_EXPORT(int) intrflush (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(bool) isendwin (void); /* implemented */ +extern NCURSES_EXPORT(bool) is_linetouched (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(bool) is_wintouched (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(NCURSES_CONST char *) keyname (int); /* implemented */ +extern NCURSES_EXPORT(int) keypad (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(char) killchar (void); /* implemented */ +extern NCURSES_EXPORT(int) leaveok (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(char *) longname (void); /* implemented */ +extern NCURSES_EXPORT(int) meta (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) move (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvaddch (int, int, const chtype); /* generated */ +extern NCURSES_EXPORT(int) mvaddchnstr (int, int, const chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) mvaddchstr (int, int, const chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvaddnstr (int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvaddstr (int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvchgat (int, int, int, attr_t, short, const void *); /* generated */ +extern NCURSES_EXPORT(int) mvcur (int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) mvdelch (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvderwin (WINDOW *, int, int); /* implemented */ +extern NCURSES_EXPORT(int) mvgetch (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvgetnstr (int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvgetstr (int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvhline (int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(chtype) mvinch (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvinchnstr (int, int, chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) mvinchstr (int, int, chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvinnstr (int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvinsch (int, int, chtype); /* generated */ +extern NCURSES_EXPORT(int) mvinsnstr (int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvinsstr (int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvinstr (int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvprintw (int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(3,4); +extern NCURSES_EXPORT(int) mvscanw (int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(3,4); +extern NCURSES_EXPORT(int) mvvline (int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(int) mvwaddch (WINDOW *, int, int, const chtype); /* generated */ +extern NCURSES_EXPORT(int) mvwaddchnstr (WINDOW *, int, int, const chtype *, int);/* generated */ +extern NCURSES_EXPORT(int) mvwaddchstr (WINDOW *, int, int, const chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvwaddnstr (WINDOW *, int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwaddstr (WINDOW *, int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvwchgat (WINDOW *, int, int, int, attr_t, short, const void *);/* generated */ +extern NCURSES_EXPORT(int) mvwdelch (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) mvwgetch (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) mvwgetnstr (WINDOW *, int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwgetstr (WINDOW *, int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvwhline (WINDOW *, int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(int) mvwin (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(chtype) mvwinch (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinchnstr (WINDOW *, int, int, chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinchstr (WINDOW *, int, int, chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvwinnstr (WINDOW *, int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinsch (WINDOW *, int, int, chtype); /* generated */ +extern NCURSES_EXPORT(int) mvwinsnstr (WINDOW *, int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinsstr (WINDOW *, int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvwinstr (WINDOW *, int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvwprintw (WINDOW*,int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(4,5); +extern NCURSES_EXPORT(int) mvwscanw (WINDOW *,int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(4,5); +extern NCURSES_EXPORT(int) mvwvline (WINDOW *,int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(int) napms (int); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) newpad (int,int); /* implemented */ +extern NCURSES_EXPORT(SCREEN *) newterm (NCURSES_CONST char *,FILE *,FILE *); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) newwin (int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) nl (void); /* implemented */ +extern NCURSES_EXPORT(int) nocbreak (void); /* implemented */ +extern NCURSES_EXPORT(int) nodelay (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) noecho (void); /* implemented */ +extern NCURSES_EXPORT(int) nonl (void); /* implemented */ +extern NCURSES_EXPORT(void) noqiflush (void); /* implemented */ +extern NCURSES_EXPORT(int) noraw (void); /* implemented */ +extern NCURSES_EXPORT(int) notimeout (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) overlay (const WINDOW*,WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) overwrite (const WINDOW*,WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) pair_content (short,short*,short*); /* implemented */ +extern NCURSES_EXPORT(int) PAIR_NUMBER (int); /* generated */ +extern NCURSES_EXPORT(int) pechochar (WINDOW *, const chtype); /* implemented */ +extern NCURSES_EXPORT(int) pnoutrefresh (WINDOW*,int,int,int,int,int,int);/* implemented */ +extern NCURSES_EXPORT(int) prefresh (WINDOW *,int,int,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) printw (NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(1,2); +extern NCURSES_EXPORT(int) putp (const char *); /* implemented */ +extern NCURSES_EXPORT(int) putwin (WINDOW *, FILE *); /* implemented */ +extern NCURSES_EXPORT(void) qiflush (void); /* implemented */ +extern NCURSES_EXPORT(int) raw (void); /* implemented */ +extern NCURSES_EXPORT(int) redrawwin (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) refresh (void); /* generated */ +extern NCURSES_EXPORT(int) resetty (void); /* implemented */ +extern NCURSES_EXPORT(int) reset_prog_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) reset_shell_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) ripoffline (int, int (*)(WINDOW *, int)); /* implemented */ +extern NCURSES_EXPORT(int) savetty (void); /* implemented */ +extern NCURSES_EXPORT(int) scanw (NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(1,2); +extern NCURSES_EXPORT(int) scr_dump (const char *); /* implemented */ +extern NCURSES_EXPORT(int) scr_init (const char *); /* implemented */ +extern NCURSES_EXPORT(int) scrl (int); /* generated */ +extern NCURSES_EXPORT(int) scroll (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) scrollok (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) scr_restore (const char *); /* implemented */ +extern NCURSES_EXPORT(int) scr_set (const char *); /* implemented */ +extern NCURSES_EXPORT(int) setscrreg (int,int); /* generated */ +extern NCURSES_EXPORT(SCREEN *) set_term (SCREEN *); /* implemented */ +extern NCURSES_EXPORT(int) slk_attroff (const chtype); /* implemented */ +extern NCURSES_EXPORT(int) slk_attr_off (const attr_t, void *); /* generated:WIDEC */ +extern NCURSES_EXPORT(int) slk_attron (const chtype); /* implemented */ +extern NCURSES_EXPORT(int) slk_attr_on (attr_t,void*); /* generated:WIDEC */ +extern NCURSES_EXPORT(int) slk_attrset (const chtype); /* implemented */ +extern NCURSES_EXPORT(attr_t) slk_attr (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_attr_set (const attr_t,short,void*); /* implemented */ +extern NCURSES_EXPORT(int) slk_clear (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_color (short); /* implemented */ +extern NCURSES_EXPORT(int) slk_init (int); /* implemented */ +extern NCURSES_EXPORT(char *) slk_label (int); /* implemented */ +extern NCURSES_EXPORT(int) slk_noutrefresh (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_refresh (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_restore (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_set (int,const char *,int); /* implemented */ +extern NCURSES_EXPORT(int) slk_touch (void); /* implemented */ +extern NCURSES_EXPORT(int) standout (void); /* generated */ +extern NCURSES_EXPORT(int) standend (void); /* generated */ +extern NCURSES_EXPORT(int) start_color (void); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) subpad (WINDOW *, int, int, int, int); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) subwin (WINDOW *,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) syncok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(chtype) termattrs (void); /* implemented */ +extern NCURSES_EXPORT(char *) termname (void); /* implemented */ +extern NCURSES_EXPORT(int) tigetflag (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(char *) tigetstr (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(void) timeout (int); /* generated */ +extern NCURSES_EXPORT(int) touchline (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) touchwin (WINDOW *); /* generated */ +extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, ...); /* implemented */ +extern NCURSES_EXPORT(int) typeahead (int); /* implemented */ +extern NCURSES_EXPORT(int) ungetch (int); /* implemented */ +extern NCURSES_EXPORT(int) untouchwin (WINDOW *); /* generated */ +extern NCURSES_EXPORT(void) use_env (bool); /* implemented */ +extern NCURSES_EXPORT(int) vidattr (chtype); /* implemented */ +extern NCURSES_EXPORT(int) vidputs (chtype, int (*)(int)); /* implemented */ +extern NCURSES_EXPORT(int) vline (chtype, int); /* generated */ +extern NCURSES_EXPORT(int) vwprintw (WINDOW *, NCURSES_CONST char *,va_list); /* implemented */ +extern NCURSES_EXPORT(int) vw_printw (WINDOW *, NCURSES_CONST char *,va_list); /* generated */ +extern NCURSES_EXPORT(int) vwscanw (WINDOW *, NCURSES_CONST char *,va_list); /* implemented */ +extern NCURSES_EXPORT(int) vw_scanw (WINDOW *, NCURSES_CONST char *,va_list); /* generated */ +extern NCURSES_EXPORT(int) waddch (WINDOW *, const chtype); /* implemented */ +extern NCURSES_EXPORT(int) waddchnstr (WINDOW *,const chtype *const,int); /* implemented */ +extern NCURSES_EXPORT(int) waddchstr (WINDOW *,const chtype *); /* generated */ +extern NCURSES_EXPORT(int) waddnstr (WINDOW *,const char *const,int); /* implemented */ +extern NCURSES_EXPORT(int) waddstr (WINDOW *,const char *); /* generated */ +extern NCURSES_EXPORT(int) wattron (WINDOW *, int); /* generated */ +extern NCURSES_EXPORT(int) wattroff (WINDOW *, int); /* generated */ +extern NCURSES_EXPORT(int) wattrset (WINDOW *, int); /* generated */ +extern NCURSES_EXPORT(int) wattr_get (WINDOW *, attr_t *, short *, void *); /* generated */ +extern NCURSES_EXPORT(int) wattr_on (WINDOW *, NCURSES_CONST attr_t, void *); /* implemented */ +extern NCURSES_EXPORT(int) wattr_off (WINDOW *, NCURSES_CONST attr_t, void *); /* implemented */ +extern NCURSES_EXPORT(int) wattr_set (WINDOW *, attr_t, short, void *); /* generated */ +extern NCURSES_EXPORT(int) wbkgd (WINDOW *,const chtype); /* implemented */ +extern NCURSES_EXPORT(void) wbkgdset (WINDOW *,chtype); /* implemented */ +extern NCURSES_EXPORT(int) wborder (WINDOW *,chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* implemented */ +extern NCURSES_EXPORT(int) wchgat (WINDOW *, int, attr_t, short, const void *);/* implemented */ +extern NCURSES_EXPORT(int) wclear (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wclrtobot (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wclrtoeol (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wcolor_set (WINDOW*,short,void*); /* implemented */ +extern NCURSES_EXPORT(void) wcursyncup (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wdelch (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wdeleteln (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) wechochar (WINDOW *, const chtype); /* implemented */ +extern NCURSES_EXPORT(int) werase (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wgetch (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wgetnstr (WINDOW *,char *,int); /* implemented */ +extern NCURSES_EXPORT(int) wgetstr (WINDOW *, char *); /* generated */ +extern NCURSES_EXPORT(int) whline (WINDOW *, chtype, int); /* implemented */ +extern NCURSES_EXPORT(chtype) winch (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) winchnstr (WINDOW *, chtype *, int); /* implemented */ +extern NCURSES_EXPORT(int) winchstr (WINDOW *, chtype *); /* generated */ +extern NCURSES_EXPORT(int) winnstr (WINDOW *, char *, int); /* implemented */ +extern NCURSES_EXPORT(int) winsch (WINDOW *, chtype); /* implemented */ +extern NCURSES_EXPORT(int) winsdelln (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(int) winsertln (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) winsnstr (WINDOW *, const char *,int); /* implemented */ +extern NCURSES_EXPORT(int) winsstr (WINDOW *, const char *); /* generated */ +extern NCURSES_EXPORT(int) winstr (WINDOW *, char *); /* generated */ +extern NCURSES_EXPORT(int) wmove (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wnoutrefresh (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wprintw (WINDOW *, NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(2,3); +extern NCURSES_EXPORT(int) wredrawln (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wrefresh (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wscanw (WINDOW *, NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(2,3); +extern NCURSES_EXPORT(int) wscrl (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(int) wsetscrreg (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wstandout (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) wstandend (WINDOW *); /* generated */ +extern NCURSES_EXPORT(void) wsyncdown (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(void) wsyncup (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(void) wtimeout (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(int) wtouchln (WINDOW *,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wvline (WINDOW *,chtype,int); /* implemented */ + +/* + * vid_attr() was implemented originally based on the draft of XSI curses. + */ +#ifndef _XOPEN_SOURCE_EXTENDED +#define vid_attr(a,pair,opts) vidattr(a) +#endif + +/* attributes */ + +#define NCURSES_ATTR_SHIFT 8 +#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) + +#define A_NORMAL 0L +#define A_ATTRIBUTES NCURSES_BITS(~(1UL - 1UL),0) +#define A_CHARTEXT (NCURSES_BITS(1UL,0) - 1UL) +#define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) +#define A_STANDOUT NCURSES_BITS(1UL,8) +#define A_UNDERLINE NCURSES_BITS(1UL,9) +#define A_REVERSE NCURSES_BITS(1UL,10) +#define A_BLINK NCURSES_BITS(1UL,11) +#define A_DIM NCURSES_BITS(1UL,12) +#define A_BOLD NCURSES_BITS(1UL,13) +#define A_ALTCHARSET NCURSES_BITS(1UL,14) +#define A_INVIS NCURSES_BITS(1UL,15) +#define A_PROTECT NCURSES_BITS(1UL,16) +#define A_HORIZONTAL NCURSES_BITS(1UL,17) +#define A_LEFT NCURSES_BITS(1UL,18) +#define A_LOW NCURSES_BITS(1UL,19) +#define A_RIGHT NCURSES_BITS(1UL,20) +#define A_TOP NCURSES_BITS(1UL,21) +#define A_VERTICAL NCURSES_BITS(1UL,22) + +#define COLOR_PAIR(n) NCURSES_BITS(n, 0) +#define PAIR_NUMBER(a) (((a) & A_COLOR) >> NCURSES_ATTR_SHIFT) + +/* + * pseudo functions + */ +#define wgetstr(w, s) wgetnstr(w, s, -1) +#define getnstr(s, n) wgetnstr(stdscr, s, n) + +#define setterm(term) setupterm(term, 1, (int *)0) + +#define fixterm() reset_prog_mode() +#define resetterm() reset_shell_mode() +#define saveterm() def_prog_mode() +#define crmode() cbreak() +#define nocrmode() nocbreak() +#define gettmode() + +#define getyx(win,y,x) (y = (win)?(win)->_cury:ERR, x = (win)?(win)->_curx:ERR) +#define getbegyx(win,y,x) (y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR) +#define getmaxyx(win,y,x) (y = (win)?((win)->_maxy + 1):ERR, x = (win)?((win)->_maxx + 1):ERR) +#define getparyx(win,y,x) (y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR) +#define getsyx(y,x) do { if(newscr->_leaveok) (y)=(x)=-1; \ + else getyx(newscr,(y),(x)); \ + } while(0) +#define setsyx(y,x) do { if((y)==-1 && (x)==-1) newscr->_leaveok=TRUE; \ + else {newscr->_leaveok=FALSE;wmove(newscr,(y),(x));} \ + } while(0) + +/* It seems older SYSV curses versions define these */ +#define getattrs(win) ((win)?(win)->_attrs:A_NORMAL) +#define getcurx(win) ((win)?(win)->_curx:ERR) +#define getcury(win) ((win)?(win)->_cury:ERR) +#define getbegx(win) ((win)?(win)->_begx:ERR) +#define getbegy(win) ((win)?(win)->_begy:ERR) +#define getmaxx(win) ((win)?((win)->_maxx + 1):ERR) +#define getmaxy(win) ((win)?((win)->_maxy + 1):ERR) +#define getparx(win) ((win)?(win)->_parx:ERR) +#define getpary(win) ((win)?(win)->_pary:ERR) + +#define wstandout(win) (wattrset(win,A_STANDOUT)) +#define wstandend(win) (wattrset(win,A_NORMAL)) +#define wattr_set(win,a,p,opts) ((win)->_attrs = (((a) & ~A_COLOR) | COLOR_PAIR(p)), OK) + +#define wattron(win,at) wattr_on(win, at, (void *)0) +#define wattroff(win,at) wattr_off(win, at, (void *)0) +#define wattrset(win,at) ((win)->_attrs = (at)) + +#define scroll(win) wscrl(win,1) + +#define touchwin(win) wtouchln((win), 0, getmaxy(win), 1) +#define touchline(win, s, c) wtouchln((win), s, c, 1) +#define untouchwin(win) wtouchln((win), 0, getmaxy(win), 0) + +#define box(win, v, h) wborder(win, v, v, h, h, 0, 0, 0, 0) +#define border(ls, rs, ts, bs, tl, tr, bl, br) wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br) +#define hline(ch, n) whline(stdscr, ch, n) +#define vline(ch, n) wvline(stdscr, ch, n) + +#define winstr(w, s) winnstr(w, s, -1) +#define winchstr(w, s) winchnstr(w, s, -1) +#define winsstr(w, s) winsnstr(w, s, -1) + +#define redrawwin(win) wredrawln(win, 0, (win)->_maxy+1) +#define waddstr(win,str) waddnstr(win,str,-1) +#define waddchstr(win,str) waddchnstr(win,str,-1) + +/* + * pseudo functions for standard screen + */ + +#define addch(ch) waddch(stdscr,ch) +#define addchnstr(str,n) waddchnstr(stdscr,str,n) +#define addchstr(str) waddchstr(stdscr,str) +#define addnstr(str,n) waddnstr(stdscr,str,n) +#define addstr(str) waddnstr(stdscr,str,-1) +#define attroff(at) wattroff(stdscr,at) +#define attron(at) wattron(stdscr,at) +#define attrset(at) wattrset(stdscr,at) +#define attr_get(ap,cp,o) wattr_get(stdscr,ap,cp,o) +#define attr_off(a,o) wattr_off(stdscr,a,o) +#define attr_on(a,o) wattr_on(stdscr,a,o) +#define attr_set(a,c,o) wattr_set(stdscr,a,c,o) +#define bkgd(ch) wbkgd(stdscr,ch) +#define bkgdset(ch) wbkgdset(stdscr,ch) +#define chgat(n,a,c,o) wchgat(stdscr,n,a,c,o) +#define clear() wclear(stdscr) +#define clrtobot() wclrtobot(stdscr) +#define clrtoeol() wclrtoeol(stdscr) +#define color_set(c,o) wcolor_set(stdscr,c,o) +#define delch() wdelch(stdscr) +#define deleteln() winsdelln(stdscr,-1) +#define echochar(c) wechochar(stdscr,c) +#define erase() werase(stdscr) +#define getch() wgetch(stdscr) +#define getstr(str) wgetstr(stdscr,str) +#define inch() winch(stdscr) +#define inchnstr(s,n) winchnstr(stdscr,s,n) +#define inchstr(s) winchstr(stdscr,s) +#define innstr(s,n) winnstr(stdscr,s,n) +#define insch(c) winsch(stdscr,c) +#define insdelln(n) winsdelln(stdscr,n) +#define insertln() winsdelln(stdscr,1) +#define insnstr(s,n) winsnstr(stdscr,s,n) +#define insstr(s) winsstr(stdscr,s) +#define instr(s) winstr(stdscr,s) +#define move(y,x) wmove(stdscr,y,x) +#define refresh() wrefresh(stdscr) +#define scrl(n) wscrl(stdscr,n) +#define setscrreg(t,b) wsetscrreg(stdscr,t,b) +#define standend() wstandend(stdscr) +#define standout() wstandout(stdscr) +#define timeout(delay) wtimeout(stdscr,delay) +#define wdeleteln(win) winsdelln(win,-1) +#define winsertln(win) winsdelln(win,1) + +/* + * mv functions + */ + +#define mvwaddch(win,y,x,ch) (wmove(win,y,x) == ERR ? ERR : waddch(win,ch)) +#define mvwaddchnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,n)) +#define mvwaddchstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,-1)) +#define mvwaddnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,n)) +#define mvwaddstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,-1)) +#define mvwdelch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wdelch(win)) +#define mvwchgat(win,y,x,n,a,c,o) (wmove(win,y,x) == ERR ? ERR : wchgat(win,n,a,c,o)) +#define mvwgetch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wgetch(win)) +#define mvwgetnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : wgetnstr(win,str,n)) +#define mvwgetstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : wgetstr(win,str)) +#define mvwhline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : whline(win,c,n)) +#define mvwinch(win,y,x) (wmove(win,y,x) == ERR ? (chtype)ERR : winch(win)) +#define mvwinchnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winchnstr(win,s,n)) +#define mvwinchstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winchstr(win,s)) +#define mvwinnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winnstr(win,s,n)) +#define mvwinsch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : winsch(win,c)) +#define mvwinsnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winsnstr(win,s,n)) +#define mvwinsstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winsstr(win,s)) +#define mvwinstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winstr(win,s)) +#define mvwvline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : wvline(win,c,n)) + +#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch) +#define mvaddchnstr(y,x,str,n) mvwaddchnstr(stdscr,y,x,str,n) +#define mvaddchstr(y,x,str) mvwaddchstr(stdscr,y,x,str) +#define mvaddnstr(y,x,str,n) mvwaddnstr(stdscr,y,x,str,n) +#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str) +#define mvchgat(y,x,n,a,c,o) mvwchgat(stdscr,y,x,n,a,c,o) +#define mvdelch(y,x) mvwdelch(stdscr,y,x) +#define mvgetch(y,x) mvwgetch(stdscr,y,x) +#define mvgetnstr(y,x,str,n) mvwgetnstr(stdscr,y,x,str,n) +#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str) +#define mvhline(y,x,c,n) mvwhline(stdscr,y,x,c,n) +#define mvinch(y,x) mvwinch(stdscr,y,x) +#define mvinchnstr(y,x,s,n) mvwinchnstr(stdscr,y,x,s,n) +#define mvinchstr(y,x,s) mvwinchstr(stdscr,y,x,s) +#define mvinnstr(y,x,s,n) mvwinnstr(stdscr,y,x,s,n) +#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c) +#define mvinsnstr(y,x,s,n) mvwinsnstr(stdscr,y,x,s,n) +#define mvinsstr(y,x,s) mvwinsstr(stdscr,y,x,s) +#define mvinstr(y,x,s) mvwinstr(stdscr,y,x,s) +#define mvvline(y,x,c,n) mvwvline(stdscr,y,x,c,n) + +/* + * Some wide-character functions do not depend on the extensions. + */ +#define getbkgd(win) ((win)->_bkgd) + +#define slk_attr_off(a,v) ((v) ? ERR : slk_attroff(a)) +#define slk_attr_on(a,v) ((v) ? ERR : slk_attron(a)) + +#define wattr_get(win,a,p,opts) ((void)((a) != 0 && (*(a) = (win)->_attrs)), \ + (void)((p) != 0 && (*(p) = PAIR_NUMBER((win)->_attrs))), \ + OK) + +/* + * XSI curses deprecates SVr4 vwprintw/vwscanw, which are supposed to use + * varargs.h. It adds new calls vw_printw/vw_scanw, which are supposed to + * use POSIX stdarg.h. The ncurses versions of vwprintw/vwscanw already + * use stdarg.h, so... + */ +#define vw_printw vwprintw +#define vw_scanw vwscanw + +/* + * Export fallback function for use in C++ binding. + */ +#if !1 +#define vsscanf(a,b,c) _nc_vsscanf(a,b,c) +NCURSES_EXPORT(int) vsscanf(const char *, const char *, va_list); +#endif + +/* + * Pseudo-character tokens outside ASCII range. The curses wgetch() function + * will return any given one of these only if the corresponding k- capability + * is defined in your terminal's terminfo entry. + * + * Some keys (KEY_A1, etc) are arranged like this: + * a1 up a3 + * left b2 right + * c1 down c3 + * + * A few key codes do not depend upon the terminfo entry. + */ +#define KEY_CODE_YES 0400 /* A wchar_t contains a key code */ +#define KEY_MIN 0401 /* Minimum curses key */ +#define KEY_BREAK 0401 /* Break key (unreliable) */ +#define KEY_SRESET 0530 /* Soft (partial) reset (unreliable) */ +#define KEY_RESET 0531 /* Reset or hard reset (unreliable) */ +/* + * These definitions were generated by /usr/src/lib/libncurses/../../contrib/ncurses/include/MKkey_defs.sh /usr/src/lib/libncurses/../../contrib/ncurses/include/Caps + */ +#define KEY_DOWN 0402 /* down-arrow key */ +#define KEY_UP 0403 /* up-arrow key */ +#define KEY_LEFT 0404 /* left-arrow key */ +#define KEY_RIGHT 0405 /* right-arrow key */ +#define KEY_HOME 0406 /* home key */ +#define KEY_BACKSPACE 0407 /* backspace key */ +#define KEY_F0 0410 /* Function keys. Space for 64 */ +#define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */ +#define KEY_DL 0510 /* delete-line key */ +#define KEY_IL 0511 /* insert-line key */ +#define KEY_DC 0512 /* delete-character key */ +#define KEY_IC 0513 /* insert-character key */ +#define KEY_EIC 0514 /* sent by rmir or smir in insert mode */ +#define KEY_CLEAR 0515 /* clear-screen or erase key */ +#define KEY_EOS 0516 /* clear-to-end-of-screen key */ +#define KEY_EOL 0517 /* clear-to-end-of-line key */ +#define KEY_SF 0520 /* scroll-forward key */ +#define KEY_SR 0521 /* scroll-backward key */ +#define KEY_NPAGE 0522 /* next-page key */ +#define KEY_PPAGE 0523 /* previous-page key */ +#define KEY_STAB 0524 /* set-tab key */ +#define KEY_CTAB 0525 /* clear-tab key */ +#define KEY_CATAB 0526 /* clear-all-tabs key */ +#define KEY_ENTER 0527 /* enter/send key */ +#define KEY_PRINT 0532 /* print key */ +#define KEY_LL 0533 /* lower-left key (home down) */ +#define KEY_A1 0534 /* upper left of keypad */ +#define KEY_A3 0535 /* upper right of keypad */ +#define KEY_B2 0536 /* center of keypad */ +#define KEY_C1 0537 /* lower left of keypad */ +#define KEY_C3 0540 /* lower right of keypad */ +#define KEY_BTAB 0541 /* back-tab key */ +#define KEY_BEG 0542 /* begin key */ +#define KEY_CANCEL 0543 /* cancel key */ +#define KEY_CLOSE 0544 /* close key */ +#define KEY_COMMAND 0545 /* command key */ +#define KEY_COPY 0546 /* copy key */ +#define KEY_CREATE 0547 /* create key */ +#define KEY_END 0550 /* end key */ +#define KEY_EXIT 0551 /* exit key */ +#define KEY_FIND 0552 /* find key */ +#define KEY_HELP 0553 /* help key */ +#define KEY_MARK 0554 /* mark key */ +#define KEY_MESSAGE 0555 /* message key */ +#define KEY_MOVE 0556 /* move key */ +#define KEY_NEXT 0557 /* next key */ +#define KEY_OPEN 0560 /* open key */ +#define KEY_OPTIONS 0561 /* options key */ +#define KEY_PREVIOUS 0562 /* previous key */ +#define KEY_REDO 0563 /* redo key */ +#define KEY_REFERENCE 0564 /* reference key */ +#define KEY_REFRESH 0565 /* refresh key */ +#define KEY_REPLACE 0566 /* replace key */ +#define KEY_RESTART 0567 /* restart key */ +#define KEY_RESUME 0570 /* resume key */ +#define KEY_SAVE 0571 /* save key */ +#define KEY_SBEG 0572 /* shifted begin key */ +#define KEY_SCANCEL 0573 /* shifted cancel key */ +#define KEY_SCOMMAND 0574 /* shifted command key */ +#define KEY_SCOPY 0575 /* shifted copy key */ +#define KEY_SCREATE 0576 /* shifted create key */ +#define KEY_SDC 0577 /* shifted delete-character key */ +#define KEY_SDL 0600 /* shifted delete-line key */ +#define KEY_SELECT 0601 /* select key */ +#define KEY_SEND 0602 /* shifted end key */ +#define KEY_SEOL 0603 /* shifted clear-to-end-of-line key */ +#define KEY_SEXIT 0604 /* shifted exit key */ +#define KEY_SFIND 0605 /* shifted find key */ +#define KEY_SHELP 0606 /* shifted help key */ +#define KEY_SHOME 0607 /* shifted home key */ +#define KEY_SIC 0610 /* shifted insert-character key */ +#define KEY_SLEFT 0611 /* shifted left-arrow key */ +#define KEY_SMESSAGE 0612 /* shifted message key */ +#define KEY_SMOVE 0613 /* shifted move key */ +#define KEY_SNEXT 0614 /* shifted next key */ +#define KEY_SOPTIONS 0615 /* shifted options key */ +#define KEY_SPREVIOUS 0616 /* shifted previous key */ +#define KEY_SPRINT 0617 /* shifted print key */ +#define KEY_SREDO 0620 /* shifted redo key */ +#define KEY_SREPLACE 0621 /* shifted replace key */ +#define KEY_SRIGHT 0622 /* shifted right-arrow key */ +#define KEY_SRSUME 0623 /* shifted resume key */ +#define KEY_SSAVE 0624 /* shifted save key */ +#define KEY_SSUSPEND 0625 /* shifted suspend key */ +#define KEY_SUNDO 0626 /* shifted undo key */ +#define KEY_SUSPEND 0627 /* suspend key */ +#define KEY_UNDO 0630 /* undo key */ +#define KEY_MOUSE 0631 /* Mouse event has occurred */ +#define KEY_RESIZE 0632 /* Terminal resize event */ + +#define KEY_MAX 0777 /* Maximum key value is 0632 */ +/* $Id$ */ + +/* mouse interface */ +#define NCURSES_MOUSE_VERSION 1 + +/* event masks */ +#define BUTTON1_RELEASED 000000000001L +#define BUTTON1_PRESSED 000000000002L +#define BUTTON1_CLICKED 000000000004L +#define BUTTON1_DOUBLE_CLICKED 000000000010L +#define BUTTON1_TRIPLE_CLICKED 000000000020L +#define BUTTON1_RESERVED_EVENT 000000000040L +#define BUTTON2_RELEASED 000000000100L +#define BUTTON2_PRESSED 000000000200L +#define BUTTON2_CLICKED 000000000400L +#define BUTTON2_DOUBLE_CLICKED 000000001000L +#define BUTTON2_TRIPLE_CLICKED 000000002000L +#define BUTTON2_RESERVED_EVENT 000000004000L +#define BUTTON3_RELEASED 000000010000L +#define BUTTON3_PRESSED 000000020000L +#define BUTTON3_CLICKED 000000040000L +#define BUTTON3_DOUBLE_CLICKED 000000100000L +#define BUTTON3_TRIPLE_CLICKED 000000200000L +#define BUTTON3_RESERVED_EVENT 000000400000L +#define BUTTON4_RELEASED 000001000000L +#define BUTTON4_PRESSED 000002000000L +#define BUTTON4_CLICKED 000004000000L +#define BUTTON4_DOUBLE_CLICKED 000010000000L +#define BUTTON4_TRIPLE_CLICKED 000020000000L +#define BUTTON4_RESERVED_EVENT 000040000000L +#define BUTTON_CTRL 000100000000L +#define BUTTON_SHIFT 000200000000L +#define BUTTON_ALT 000400000000L +#define ALL_MOUSE_EVENTS 000777777777L +#define REPORT_MOUSE_POSITION 001000000000L + +/* macros to extract single event-bits from masks */ +#define BUTTON_RELEASE(e, x) ((e) & (001 << (6 * ((x) - 1)))) +#define BUTTON_PRESS(e, x) ((e) & (002 << (6 * ((x) - 1)))) +#define BUTTON_CLICK(e, x) ((e) & (004 << (6 * ((x) - 1)))) +#define BUTTON_DOUBLE_CLICK(e, x) ((e) & (010 << (6 * ((x) - 1)))) +#define BUTTON_TRIPLE_CLICK(e, x) ((e) & (020 << (6 * ((x) - 1)))) +#define BUTTON_RESERVED_EVENT(e, x) ((e) & (040 << (6 * ((x) - 1)))) + +typedef unsigned long mmask_t; + +typedef struct +{ + short id; /* ID to distinguish multiple devices */ + int x, y, z; /* event coordinates (character-cell) */ + mmask_t bstate; /* button state bits */ +} +MEVENT; + +extern NCURSES_EXPORT(int) getmouse (MEVENT *); +extern NCURSES_EXPORT(int) ungetmouse (MEVENT *); +extern NCURSES_EXPORT(mmask_t) mousemask (mmask_t, mmask_t *); +extern NCURSES_EXPORT(bool) wenclose (const WINDOW *, int, int); +extern NCURSES_EXPORT(int) mouseinterval (int); +extern NCURSES_EXPORT(bool) wmouse_trafo (const WINDOW* win,int* y, int* x, bool to_screen); +extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated */ + +#define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen) + +/* other non-XSI functions */ + +extern NCURSES_EXPORT(int) mcprint (char *, int); /* direct data to printer */ +extern NCURSES_EXPORT(int) has_key (int); /* do we have given key? */ + +/* Debugging : use with libncurses_g.a */ + +extern NCURSES_EXPORT(void) _tracef (const char *, ...) GCC_PRINTFLIKE(1,2); +extern NCURSES_EXPORT(void) _tracedump (const char *, WINDOW *); +extern NCURSES_EXPORT(char *) _traceattr (attr_t); +extern NCURSES_EXPORT(char *) _traceattr2 (int, chtype); +extern NCURSES_EXPORT(char *) _nc_tracebits (void); +extern NCURSES_EXPORT(char *) _tracechar (int); +extern NCURSES_EXPORT(char *) _tracechtype (chtype); +extern NCURSES_EXPORT(char *) _tracechtype2 (int, chtype); +#ifdef _XOPEN_SOURCE_EXTENDED +#define _tracech_t _tracecchar_t +extern NCURSES_EXPORT(char *) _tracecchar_t (const cchar_t *); +#define _tracech_t2 _tracecchar_t2 +extern NCURSES_EXPORT(char *) _tracecchar_t2 (int, const cchar_t *); +#else +#define _tracech_t _tracechtype +#define _tracech_t2 _tracechtype2 +#endif +extern NCURSES_EXPORT(char *) _tracemouse (const MEVENT *); +extern NCURSES_EXPORT(void) trace (const unsigned int); + +/* trace masks */ +#define TRACE_DISABLE 0x0000 /* turn off tracing */ +#define TRACE_TIMES 0x0001 /* trace user and system times of updates */ +#define TRACE_TPUTS 0x0002 /* trace tputs calls */ +#define TRACE_UPDATE 0x0004 /* trace update actions, old & new screens */ +#define TRACE_MOVE 0x0008 /* trace cursor moves and scrolls */ +#define TRACE_CHARPUT 0x0010 /* trace all character outputs */ +#define TRACE_ORDINARY 0x001F /* trace all update actions */ +#define TRACE_CALLS 0x0020 /* trace all curses calls */ +#define TRACE_VIRTPUT 0x0040 /* trace virtual character puts */ +#define TRACE_IEVENT 0x0080 /* trace low-level input processing */ +#define TRACE_BITS 0x0100 /* trace state of TTY control bits */ +#define TRACE_ICALLS 0x0200 /* trace internal/nested calls */ +#define TRACE_CCALLS 0x0400 /* trace per-character calls */ +#define TRACE_DATABASE 0x0800 /* trace read/write of terminfo/termcap data */ +#define TRACE_ATTRS 0x1000 /* trace attribute updates */ +#define TRACE_MAXIMUM 0xffff /* maximum trace level */ + +#if defined(TRACE) || defined(NCURSES_TEST) +extern NCURSES_EXPORT_VAR(int) _nc_optimize_enable; /* enable optimizations */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern NCURSES_EXPORT(const char *) _nc_viswbuf(const wchar_t *); +#endif +extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *); +#define OPTIMIZE_MVCUR 0x01 /* cursor movement optimization */ +#define OPTIMIZE_HASHMAP 0x02 /* diff hashing to detect scrolls */ +#define OPTIMIZE_SCROLL 0x04 /* scroll optimization */ +#define OPTIMIZE_ALL 0xff /* enable all optimizations (dflt) */ +#endif + +#ifdef __cplusplus + +/* these names conflict with STL */ +#undef box +#undef clear +#undef erase +#undef move +#undef refresh + +} +#endif + +#endif /* __NCURSES_H */ diff --git a/src/include/db.h b/src/include/db.h new file mode 100644 index 0000000..a3975f0 --- /dev/null +++ b/src/include/db.h @@ -0,0 +1,219 @@ +/*- + * Copyright (c) 1990, 1993, 1994 + * 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. + * + * @(#)db.h 8.7 (Berkeley) 6/16/94 + * $FreeBSD: src/include/db.h,v 1.5 2002/03/26 01:35:05 bde Exp $ + */ + +#ifndef _DB_H_ +#define _DB_H_ + +#include +#include + +#include + +#define RET_ERROR -1 /* Return values. */ +#define RET_SUCCESS 0 +#define RET_SPECIAL 1 + +#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ +typedef u_int32_t pgno_t; +#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ +typedef u_int16_t indx_t; +#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ +typedef u_int32_t recno_t; + +/* Key/data structure -- a Data-Base Thang. */ +typedef struct { + void *data; /* data */ + size_t size; /* data length */ +} DBT; + +/* Routine flags. */ +#define R_CURSOR 1 /* del, put, seq */ +#define __R_UNUSED 2 /* UNUSED */ +#define R_FIRST 3 /* seq */ +#define R_IAFTER 4 /* put (RECNO) */ +#define R_IBEFORE 5 /* put (RECNO) */ +#define R_LAST 6 /* seq (BTREE, RECNO) */ +#define R_NEXT 7 /* seq */ +#define R_NOOVERWRITE 8 /* put */ +#define R_PREV 9 /* seq (BTREE, RECNO) */ +#define R_SETCURSOR 10 /* put (RECNO) */ +#define R_RECNOSYNC 11 /* sync (RECNO) */ + +typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; + +/* + * !!! + * The following flags are included in the dbopen(3) call as part of the + * open(2) flags. In order to avoid conflicts with the open flags, start + * at the top of the 16 or 32-bit number space and work our way down. If + * the open flags were significantly expanded in the future, it could be + * a problem. Wish I'd left another flags word in the dbopen call. + * + * !!! + * None of this stuff is implemented yet. The only reason that it's here + * is so that the access methods can skip copying the key/data pair when + * the DB_LOCK flag isn't set. + */ +#if UINT_MAX > 65535 +#define DB_LOCK 0x20000000 /* Do locking. */ +#define DB_SHMEM 0x40000000 /* Use shared memory. */ +#define DB_TXN 0x80000000 /* Do transactions. */ +#else +#define DB_LOCK 0x2000 /* Do locking. */ +#define DB_SHMEM 0x4000 /* Use shared memory. */ +#define DB_TXN 0x8000 /* Do transactions. */ +#endif + +/* Access method description structure. */ +typedef struct __db { + DBTYPE type; /* Underlying db type. */ + int (*close)(struct __db *); + int (*del)(const struct __db *, const DBT *, u_int); + int (*get)(const struct __db *, const DBT *, DBT *, u_int); + int (*put)(const struct __db *, DBT *, const DBT *, u_int); + int (*seq)(const struct __db *, DBT *, DBT *, u_int); + int (*sync)(const struct __db *, u_int); + void *internal; /* Access method private. */ + int (*fd)(const struct __db *); +} DB; + +#define BTREEMAGIC 0x053162 +#define BTREEVERSION 3 + +/* Structure used to pass parameters to the btree routines. */ +typedef struct { +#define R_DUP 0x01 /* duplicate keys */ + u_long flags; + u_int cachesize; /* bytes to cache */ + int maxkeypage; /* maximum keys per page */ + int minkeypage; /* minimum keys per page */ + u_int psize; /* page size */ + int (*compare) /* comparison function */ + (const DBT *, const DBT *); + size_t (*prefix) /* prefix function */ + (const DBT *, const DBT *); + int lorder; /* byte order */ +} BTREEINFO; + +#define HASHMAGIC 0x061561 +#define HASHVERSION 2 + +/* Structure used to pass parameters to the hashing routines. */ +typedef struct { + u_int bsize; /* bucket size */ + u_int ffactor; /* fill factor */ + u_int nelem; /* number of elements */ + u_int cachesize; /* bytes to cache */ + u_int32_t /* hash function */ + (*hash)(const void *, size_t); + int lorder; /* byte order */ +} HASHINFO; + +/* Structure used to pass parameters to the record routines. */ +typedef struct { +#define R_FIXEDLEN 0x01 /* fixed-length records */ +#define R_NOKEY 0x02 /* key not required */ +#define R_SNAPSHOT 0x04 /* snapshot the input */ + u_long flags; + u_int cachesize; /* bytes to cache */ + u_int psize; /* page size */ + int lorder; /* byte order */ + size_t reclen; /* record length (fixed-length records) */ + u_char bval; /* delimiting byte (variable-length records */ + char *bfname; /* btree file name */ +} RECNOINFO; + +#ifdef __DBINTERFACE_PRIVATE +/* + * Little endian <==> big endian 32-bit swap macros. + * M_32_SWAP swap a memory location + * P_32_SWAP swap a referenced memory location + * P_32_COPY swap from one location to another + */ +#define M_32_SWAP(a) { \ + u_int32_t _tmp = a; \ + ((char *)&a)[0] = ((char *)&_tmp)[3]; \ + ((char *)&a)[1] = ((char *)&_tmp)[2]; \ + ((char *)&a)[2] = ((char *)&_tmp)[1]; \ + ((char *)&a)[3] = ((char *)&_tmp)[0]; \ +} +#define P_32_SWAP(a) { \ + u_int32_t _tmp = *(u_int32_t *)a; \ + ((char *)a)[0] = ((char *)&_tmp)[3]; \ + ((char *)a)[1] = ((char *)&_tmp)[2]; \ + ((char *)a)[2] = ((char *)&_tmp)[1]; \ + ((char *)a)[3] = ((char *)&_tmp)[0]; \ +} +#define P_32_COPY(a, b) { \ + ((char *)&(b))[0] = ((char *)&(a))[3]; \ + ((char *)&(b))[1] = ((char *)&(a))[2]; \ + ((char *)&(b))[2] = ((char *)&(a))[1]; \ + ((char *)&(b))[3] = ((char *)&(a))[0]; \ +} + +/* + * Little endian <==> big endian 16-bit swap macros. + * M_16_SWAP swap a memory location + * P_16_SWAP swap a referenced memory location + * P_16_COPY swap from one location to another + */ +#define M_16_SWAP(a) { \ + u_int16_t _tmp = a; \ + ((char *)&a)[0] = ((char *)&_tmp)[1]; \ + ((char *)&a)[1] = ((char *)&_tmp)[0]; \ +} +#define P_16_SWAP(a) { \ + u_int16_t _tmp = *(u_int16_t *)a; \ + ((char *)a)[0] = ((char *)&_tmp)[1]; \ + ((char *)a)[1] = ((char *)&_tmp)[0]; \ +} +#define P_16_COPY(a, b) { \ + ((char *)&(b))[0] = ((char *)&(a))[1]; \ + ((char *)&(b))[1] = ((char *)&(a))[0]; \ +} +#endif + +__BEGIN_DECLS +DB *dbopen(const char *, int, int, DBTYPE, const void *); + +#ifdef __DBINTERFACE_PRIVATE +DB *__bt_open(const char *, int, int, const BTREEINFO *, int); +DB *__hash_open(const char *, int, int, const HASHINFO *, int); +DB *__rec_open(const char *, int, int, const RECNOINFO *, int); +void __dbpanic(DB *dbp); +#endif +__END_DECLS +#endif /* !_DB_H_ */ diff --git a/src/include/devinfo.h b/src/include/devinfo.h new file mode 100644 index 0000000..06339fe --- /dev/null +++ b/src/include/devinfo.h @@ -0,0 +1,138 @@ +/*- + * Copyright (c) 2000 Michael Smith + * Copyright (c) 2000 BSDi + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libdevinfo/devinfo.h,v 1.4 2002/09/20 02:16:33 imp Exp $ + */ + +#include +#include + +typedef __uintptr_t devinfo_handle_t; +#define DEVINFO_ROOT_DEVICE ((devinfo_handle_t)0) + +/* + * State of the device. + */ +/* XXX not sure if I want a copy here, or expose sys/bus.h */ +typedef enum devinfo_state { + DIS_NOTPRESENT, /* not probed or probe failed */ + DIS_ALIVE, /* probe succeeded */ + DIS_ATTACHED, /* attach method called */ + DIS_BUSY /* device is open */ +} devinfo_state_t; + +struct devinfo_dev { + devinfo_handle_t dd_handle; /* device handle */ + devinfo_handle_t dd_parent; /* parent handle */ + + char *dd_name; /* name of device */ + char *dd_desc; /* device description */ + char *dd_drivername; /* name of attached driver*/ + char *dd_pnpinfo; /* pnp info from parent bus */ + char *dd_location; /* Where bus thinks dev at */ + uint32_t dd_devflags; /* API flags */ + uint16_t dd_flags; /* internal dev flags */ + devinfo_state_t dd_state; /* attacement state of dev */ +}; + +struct devinfo_rman { + devinfo_handle_t dm_handle; /* resource manager handle */ + + unsigned long dm_start; /* resource start */ + unsigned long dm_size; /* resource size */ + + char *dm_desc; /* resource description */ +}; + +struct devinfo_res { + devinfo_handle_t dr_handle; /* resource handle */ + devinfo_handle_t dr_rman; /* resource manager handle */ + devinfo_handle_t dr_device; /* owning device */ + + unsigned long dr_start; /* region start */ + unsigned long dr_size; /* region size */ + /* XXX add flags */ +}; + +/* + * Acquire a coherent copy of the kernel's device and resource tables. + * This must return success (zero) before any other interfaces will + * function. Sets errno on failure. + */ +extern int devinfo_init(void); + +/* + * Release the storage associated with the internal copy of the device + * and resource tables. devinfo_init must be called before any attempt + * is made to use any other interfaces. + */ +extern void devinfo_free(void); + +/* + * Find a device/resource/resource manager by its handle. + */ +extern struct devinfo_dev + *devinfo_handle_to_device(devinfo_handle_t handle); +extern struct devinfo_res + *devinfo_handle_to_resource(devinfo_handle_t handle); +extern struct devinfo_rman + *devinfo_handle_to_rman(devinfo_handle_t handle); + +/* + * Iterate over the children of a device, calling (fn) on each. If + * (fn) returns nonzero, abort the scan and return. + */ +extern int + devinfo_foreach_device_child(struct devinfo_dev *parent, + int (* fn)(struct devinfo_dev *child, void *arg), + void *arg); + +/* + * Iterate over all the resources owned by a device, calling (fn) on each. + * If (fn) returns nonzero, abort the scan and return. + */ +extern int + devinfo_foreach_device_resource(struct devinfo_dev *dev, + int (* fn)(struct devinfo_dev *dev, + struct devinfo_res *res, void *arg), + void *arg); + +/* + * Iterate over all the resources owned by a resource manager, calling (fn) + * on each. If (fn) returns nonzero, abort the scan and return. + */ +extern int + devinfo_foreach_rman_resource(struct devinfo_rman *rman, + int (* fn)(struct devinfo_res *res, void *arg), + void *arg); + +/* + * Iterate over all the resource managers, calling (fn) on each. If (fn) + * returns nonzero, abort the scan and return. + */ +extern int + devinfo_foreach_rman(int (* fn)(struct devinfo_rman *rman, void *arg), + void *arg); diff --git a/src/include/devstat.h b/src/include/devstat.h new file mode 100644 index 0000000..5d3ae8e --- /dev/null +++ b/src/include/devstat.h @@ -0,0 +1,168 @@ +/* + * Copyright (c) 1997, 1998 Kenneth D. Merry. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libdevstat/devstat.h,v 1.10 2003/03/18 17:05:27 phk Exp $ + */ + +#ifndef _DEVSTAT_H +#define _DEVSTAT_H +#include +#include + +#include + +/* + * Bumped every time we change the userland API. Hopefully this doesn't + * happen very often! This should be bumped every time we have to + * increment SHLIB_MAJOR in the libdevstat Makefile (for non-backwards + * compatible API changes) and should also be bumped every time we make + * backwards-compatible API changes, so application writers have a way to + * determine when a particular feature is available. + */ +#define DEVSTAT_USER_API_VER 5 + +#define DEVSTAT_ERRBUF_SIZE 2048 /* size of the devstat library error string */ + +extern char devstat_errbuf[]; + +typedef enum { + DEVSTAT_MATCH_NONE = 0x00, + DEVSTAT_MATCH_TYPE = 0x01, + DEVSTAT_MATCH_IF = 0x02, + DEVSTAT_MATCH_PASS = 0x04 +} devstat_match_flags; + +typedef enum { + DSM_NONE, + DSM_TOTAL_BYTES, + DSM_TOTAL_BYTES_READ, + DSM_TOTAL_BYTES_WRITE, + DSM_TOTAL_TRANSFERS, + DSM_TOTAL_TRANSFERS_READ, + DSM_TOTAL_TRANSFERS_WRITE, + DSM_TOTAL_TRANSFERS_OTHER, + DSM_TOTAL_BLOCKS, + DSM_TOTAL_BLOCKS_READ, + DSM_TOTAL_BLOCKS_WRITE, + DSM_KB_PER_TRANSFER, + DSM_KB_PER_TRANSFER_READ, + DSM_KB_PER_TRANSFER_WRITE, + DSM_TRANSFERS_PER_SECOND, + DSM_TRANSFERS_PER_SECOND_READ, + DSM_TRANSFERS_PER_SECOND_WRITE, + DSM_TRANSFERS_PER_SECOND_OTHER, + DSM_MB_PER_SECOND, + DSM_MB_PER_SECOND_READ, + DSM_MB_PER_SECOND_WRITE, + DSM_BLOCKS_PER_SECOND, + DSM_BLOCKS_PER_SECOND_READ, + DSM_BLOCKS_PER_SECOND_WRITE, + DSM_MS_PER_TRANSACTION, + DSM_MS_PER_TRANSACTION_READ, + DSM_MS_PER_TRANSACTION_WRITE, + DSM_SKIP, + DSM_TOTAL_BYTES_FREE, + DSM_TOTAL_TRANSFERS_FREE, + DSM_TOTAL_BLOCKS_FREE, + DSM_KB_PER_TRANSFER_FREE, + DSM_MB_PER_SECOND_FREE, + DSM_TRANSFERS_PER_SECOND_FREE, + DSM_BLOCKS_PER_SECOND_FREE, + DSM_MS_PER_TRANSACTION_OTHER, + DSM_MS_PER_TRANSACTION_FREE, + DSM_BUSY_PCT, + DSM_QUEUE_LENGTH, + DSM_MAX +} devstat_metric; + +struct devstat_match { + devstat_match_flags match_fields; + devstat_type_flags device_type; + int num_match_categories; +}; + +struct devstat_match_table { + const char * match_str; + devstat_type_flags type; + devstat_match_flags match_field; +}; + +struct device_selection { + u_int32_t device_number; + char device_name[DEVSTAT_NAME_LEN]; + int unit_number; + int selected; + u_int64_t bytes; + int position; +}; + +struct devinfo { + struct devstat *devices; + u_int8_t *mem_ptr; + long generation; + int numdevs; +}; + +struct statinfo { + long cp_time[CPUSTATES]; + long tk_nin; + long tk_nout; + struct devinfo *dinfo; + long double snap_time; +}; + +typedef enum { + DS_SELECT_ADD, + DS_SELECT_ONLY, + DS_SELECT_REMOVE, + DS_SELECT_ADDONLY +} devstat_select_mode; + +__BEGIN_DECLS + +int devstat_getnumdevs(kvm_t *kd); +long devstat_getgeneration(kvm_t *kd); +int devstat_getversion(kvm_t *kd); +int devstat_checkversion(kvm_t *kd); +int devstat_getdevs(kvm_t *kd, struct statinfo *stats); +int devstat_selectdevs(struct device_selection **dev_select, int *num_selected, + int *num_selections, long *select_generation, + long current_generation, struct devstat *devices, + int numdevs, struct devstat_match *matches, + int num_matches, char **dev_selections, + int num_dev_selections, devstat_select_mode select_mode, + int maxshowdevs, int perf_select); +int devstat_buildmatch(char *match_str, struct devstat_match **matches, + int *num_matches); +int devstat_compute_statistics(struct devstat *current, + struct devstat *previous, + long double etime, ...); +long double devstat_compute_etime(struct bintime *cur_time, + struct bintime *prev_time); +__END_DECLS + +#endif /* _DEVSTAT_H */ diff --git a/src/include/dialog.h b/src/include/dialog.h new file mode 100644 index 0000000..2153431 --- /dev/null +++ b/src/include/dialog.h @@ -0,0 +1,211 @@ +#ifndef _DIALOG_H_INCLUDE +#define _DIALOG_H_INCLUDE + +/* + * dialog.h -- common declarations for all dialog modules + * + * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) + * + * Substantial rennovation: 12/18/95, Jordan K. Hubbard + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $FreeBSD: src/gnu/lib/libdialog/dialog.h,v 1.22 2000/12/14 02:35:22 jkh Exp $ + * + */ + +#define HAVE_NCURSES + +#ifdef HAVE_NCURSES +#include + +#else + +#ifdef ultrix +#include +#else +#include +#endif + +#endif + +/* special return codes for `fire' actions */ +#define DITEM_STATUS(flag) ((flag) & 0x0000FFFF) +#define DITEM_SUCCESS 0 +#define DITEM_FAILURE 1 + +/* Flags - returned in upper 16 bits of return status */ +#define DITEM_LEAVE_MENU (1 << 16) +#define DITEM_REDRAW (1 << 17) +#define DITEM_RECREATE (1 << 18) +#define DITEM_RESTORE (1 << 19) +#define DITEM_CONTINUE (1 << 20) + +/* Attributes as used by entry fields right now */ +#define DITEM_NO_ECHO 0x0001 + + +/* negative offsets for buttons in item lists, if specified */ +#define OK_BUTTON -2 +#define CANCEL_BUTTON -1 + +/* for use in describing more exotic behaviors */ +typedef struct _dmenu_item { + char *prompt; + char *title; + int (*checked)(struct _dmenu_item *self); + int (*fire)(struct _dmenu_item *self); + void (*selected)(struct _dmenu_item *self, int is_selected); + void *data; + char lbra, mark, rbra; + long aux; +} dialogMenuItem; + +#define VERSION "0.4" +#define MAX_LEN 2048 + +#ifndef TRUE +#define TRUE (1) +#endif +#ifndef FALSE +#define FALSE (0) +#endif + +extern int DialogX, DialogY, DialogInputAttrs; + +/* + * Attribute names + */ +#define screen_attr attributes[0] +#define shadow_attr attributes[1] +#define dialog_attr attributes[2] +#define title_attr attributes[3] +#define border_attr attributes[4] +#define button_active_attr attributes[5] +#define button_inactive_attr attributes[6] +#define button_key_active_attr attributes[7] +#define button_key_inactive_attr attributes[8] +#define button_label_active_attr attributes[9] +#define button_label_inactive_attr attributes[10] +#define inputbox_attr attributes[11] +#define inputbox_border_attr attributes[12] +#define searchbox_attr attributes[13] +#define searchbox_title_attr attributes[14] +#define searchbox_border_attr attributes[15] +#define position_indicator_attr attributes[16] +#define menubox_attr attributes[17] +#define menubox_border_attr attributes[18] +#define item_attr attributes[19] +#define item_selected_attr attributes[20] +#define tag_attr attributes[21] +#define tag_selected_attr attributes[22] +#define tag_key_attr attributes[23] +#define tag_key_selected_attr attributes[24] +#define check_attr attributes[25] +#define check_selected_attr attributes[26] +#define uarrow_attr attributes[27] +#define darrow_attr attributes[28] + +/* number of attributes */ +#define ATTRIBUTE_COUNT 29 + +extern chtype attributes[]; + +#ifdef HAVE_NCURSES +extern bool use_shadow; +void draw_shadow(WINDOW *win, int y, int x, int height, int width); +#endif +void draw_box(WINDOW *win, int y, int x, int height, int width, chtype box, chtype border); +int line_edit(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, chtype attrs, int first, unsigned char *result, int attr_mask); +int strheight(const char *p); +int strwidth(const char *p); + +void dialog_create_rc(unsigned char *filename); +int dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width); +int dialog_noyes(unsigned char *title, unsigned char *prompt, int height, int width); +int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell); +int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int width, int pause); +int dialog_textbox(unsigned char *title, unsigned char *file, int height, int width); +int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height, + int item_no, void *itptr, unsigned char *result, int *ch, int *sc); +int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, + int item_no, void *itptr, unsigned char *result); +int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, + int item_no, void *itptr, unsigned char *result); +int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int width, unsigned char *result); +void dialog_clear_norefresh(void); +void dialog_clear(void); +void dialog_update(void); +void init_dialog(void); +void end_dialog(void); + +/* Additions to libdialog */ +char *dialog_fselect(char *dir, char *fmask); +int dialog_dselect(char *dir, char *fmask); +void dialog_notify(char *msg); +int dialog_mesgbox(unsigned char *title, unsigned char *prompt, int height, int width); +void use_helpfile(char *helpfile); +void use_helpline(char *helpline); +char *get_helpline(void); +void restore_helpline(char *helpline); +void dialog_gauge(char *title, char *prompt, int y, int x, int height, int width, int perc); + +/* + * Display a tree menu from file + * + * filename - file with like find(1) output + * FS - fields separator + * title - title of dialog box + * prompt - prompt text into dialog box + * height - height of dialog box + * width - width of dialog box + * menu_height - height of menu box + * result - pointer to char array + * + * return values: + * -1 - ESC pressed + * 0 - Ok, result set (must be freed later) + * 1 - Cancel + */ +int dialog_ftree(unsigned char *filename, unsigned char FS, + unsigned char *title, unsigned char *prompt, + int height, int width, int menu_height, + unsigned char **result); + +/* + * Display a tree menu from array + * + * names - array with like find(1) output + * size - size of array + * FS - fields separator + * title - title of dialog box + * prompt - prompt text into dialog box + * height - height of dialog box + * width - width of dialog box + * menu_height - height of menu box + * result - pointer to char array + * + * return values: + * -1 - ESC pressed + * 0 - Ok, result set + * 1 - Cancel + */ + +int dialog_tree(unsigned char **names, int size, unsigned char FS, + unsigned char *title, unsigned char *prompt, + int height, int width, int menu_height, + unsigned char **result); + +#endif /* _DIALOG_H_INCLUDE */ diff --git a/src/include/dirent.h b/src/include/dirent.h new file mode 100644 index 0000000..1d0e1e0 --- /dev/null +++ b/src/include/dirent.h @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 1989, 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. + * + * @(#)dirent.h 8.2 (Berkeley) 7/28/94 + * $FreeBSD: src/include/dirent.h,v 1.14 2003/12/07 21:10:06 marcel Exp $ + */ + +#ifndef _DIRENT_H_ +#define _DIRENT_H_ + +/* + * The kernel defines the format of directory entries returned by + * the getdirentries(2) system call. + */ +#include +#include + +#if __BSD_VISIBLE || __XSI_VISIBLE +/* + * XXX this is probably illegal in the __XSI_VISIBLE case, but brings us closer + * to the specification. + */ +#define d_ino d_fileno /* backward and XSI compatibility */ +#endif + +#if __BSD_VISIBLE + +#include + +/* definitions for library routines operating on directories. */ +#define DIRBLKSIZ 1024 + +struct _telldir; /* see telldir.h */ + +/* structure describing an open directory. */ +typedef struct _dirdesc { + int dd_fd; /* file descriptor associated with directory */ + long dd_loc; /* offset in current buffer */ + long dd_size; /* amount of data returned by getdirentries */ + char *dd_buf; /* data buffer */ + int dd_len; /* size of data buffer */ + long dd_seek; /* magic cookie returned by getdirentries */ + long dd_rewind; /* magic cookie for rewinding */ + int dd_flags; /* flags for readdir */ + void *dd_lock; /* hack to avoid including */ + struct _telldir *dd_td; /* telldir position recording */ +} DIR; + +#define dirfd(dirp) ((dirp)->dd_fd) + +/* flags for opendir2 */ +#define DTF_HIDEW 0x0001 /* hide whiteout entries */ +#define DTF_NODUP 0x0002 /* don't return duplicate names */ +#define DTF_REWIND 0x0004 /* rewind after reading union stack */ +#define __DTF_READALL 0x0008 /* everything has been read */ + +#else /* !__BSD_VISIBLE */ + +typedef void * DIR; + +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL + +__BEGIN_DECLS +#if __BSD_VISIBLE +DIR *__opendir2(const char *, int); +int alphasort(const void *, const void *); +int getdents(int, char *, int); +int getdirentries(int, char *, int, long *); +#endif +DIR *opendir(const char *); +struct dirent * + readdir(DIR *); +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 +int readdir_r(DIR *, struct dirent *, struct dirent **); +#endif +void rewinddir(DIR *); +#if __BSD_VISIBLE +int scandir(const char *, struct dirent ***, + int (*)(struct dirent *), int (*)(const void *, const void *)); +#endif +#if __XSI_VISIBLE +void seekdir(DIR *, long); +long telldir(DIR *); +#endif +int closedir(DIR *); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_DIRENT_H_ */ diff --git a/src/include/dlfcn.h b/src/include/dlfcn.h new file mode 100644 index 0000000..581ffcf --- /dev/null +++ b/src/include/dlfcn.h @@ -0,0 +1,137 @@ +/*- + * Copyright (c) 1994 + * 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. + * + * $FreeBSD: src/include/dlfcn.h,v 1.19 2003/02/13 17:47:43 kan Exp $ + */ + +#ifndef _DLFCN_H_ +#define _DLFCN_H_ + +#include + +/* + * Modes and flags for dlopen(). + */ +#define RTLD_LAZY 1 /* Bind function calls lazily. */ +#define RTLD_NOW 2 /* Bind function calls immediately. */ +#define RTLD_MODEMASK 0x3 +#define RTLD_GLOBAL 0x100 /* Make symbols globally available. */ +#define RTLD_LOCAL 0 /* Opposite of RTLD_GLOBAL, and the default. */ +#define RTLD_TRACE 0x200 /* Trace loaded objects and exit. */ + +/* + * Request arguments for dlinfo(). + */ +#define RTLD_DI_LINKMAP 2 /* Obtain link map. */ +#define RTLD_DI_SERINFO 4 /* Obtain search path info. */ +#define RTLD_DI_SERINFOSIZE 5 /* ... query for required space. */ +#define RTLD_DI_ORIGIN 6 /* Obtain object origin */ +#define RTLD_DI_MAX RTLD_DI_ORIGIN + +/* + * Special handle arguments for dlsym()/dlinfo(). + */ +#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */ +#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ +#define RTLD_SELF ((void *) -3) /* Search the caller itself. */ + +#if __BSD_VISIBLE + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +/* + * Structure filled in by dladdr(). + */ +typedef struct dl_info { + const char *dli_fname; /* Pathname of shared object. */ + void *dli_fbase; /* Base address of shared object. */ + const char *dli_sname; /* Name of nearest symbol. */ + void *dli_saddr; /* Address of nearest symbol. */ +} Dl_info; + +/*- + * The actual type declared by this typedef is immaterial, provided that + * it is a function pointer. Its purpose is to provide a return type for + * dlfunc() which can be cast to a function pointer type without depending + * on behavior undefined by the C standard, which might trigger a compiler + * diagnostic. We intentionally declare a unique type signature to force + * a diagnostic should the application not cast the return value of dlfunc() + * appropriately. + */ +struct __dlfunc_arg { + int __dlfunc_dummy; +}; + +typedef void (*dlfunc_t)(struct __dlfunc_arg); + +/* + * Structures, returned by the RTLD_DI_SERINFO dlinfo() request. + */ +typedef struct dl_serpath { + char * dls_name; /* single search path entry */ + unsigned int dls_flags; /* path information */ +} Dl_serpath; + +typedef struct dl_serinfo { + size_t dls_size; /* total buffer size */ + unsigned int dls_cnt; /* number of path entries */ + Dl_serpath dls_serpath[1]; /* there may be more than one */ +} Dl_serinfo; + +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +/* XSI functions first. */ +int dlclose(void *); +const char * + dlerror(void); +void *dlopen(const char *, int); +void *dlsym(void * __restrict, const char * __restrict); + +#if __BSD_VISIBLE +int dladdr(const void * __restrict, Dl_info * __restrict); +dlfunc_t dlfunc(void * __restrict, const char * __restrict); +int dlinfo(void * __restrict, int, void * __restrict); +void dllockinit(void *_context, + void *(*_lock_create)(void *_context), + void (*_rlock_acquire)(void *_lock), + void (*_wlock_acquire)(void *_lock), + void (*_lock_release)(void *_lock), + void (*_lock_destroy)(void *_lock), + void (*_context_destroy)(void *_context)); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_DLFCN_H_ */ diff --git a/src/include/elf-hints.h b/src/include/elf-hints.h new file mode 100644 index 0000000..d572a4f --- /dev/null +++ b/src/include/elf-hints.h @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1997 John D. Polstra. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/elf-hints.h,v 1.4 2001/05/02 23:56:17 obrien Exp $ + */ + +#ifndef _ELF_HINTS_H_ +#define _ELF_HINTS_H_ + +/* + * Hints file produced by ldconfig. + */ +struct elfhints_hdr { + u_int32_t magic; /* Magic number */ + u_int32_t version; /* File version (1) */ + u_int32_t strtab; /* Offset of string table in file */ + u_int32_t strsize; /* Size of string table */ + u_int32_t dirlist; /* Offset of directory list in + string table */ + u_int32_t dirlistlen; /* strlen(dirlist) */ + u_int32_t spare[26]; /* Room for expansion */ +}; + +#define ELFHINTS_MAGIC 0x746e6845 + +#define _PATH_ELF_HINTS "/var/run/ld-elf.so.hints" + +#endif /* !_ELF_HINTS_H_ */ diff --git a/src/include/elf.h b/src/include/elf.h new file mode 100644 index 0000000..b673187 --- /dev/null +++ b/src/include/elf.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2001 David E. O'Brien. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/elf.h,v 1.8 2002/07/04 11:05:39 markm Exp $ + */ + +/* + * This is a Solaris compatibility header + */ + +#ifndef _ELF_H_ +#define _ELF_H_ + +#include +#include +#include +#include + +#endif /* !_ELF_H_ */ diff --git a/src/include/emmintrin.h b/src/include/emmintrin.h new file mode 100644 index 0000000..7007fc5 --- /dev/null +++ b/src/include/emmintrin.h @@ -0,0 +1,1499 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + + This file is part of GNU CC. + + GNU CC is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU CC is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU CC; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, if you include this header file into source + files compiled by GCC, this header file does not by itself cause + the resulting executable to be covered by the GNU General Public + License. This exception does not however invalidate any other + reasons why the executable file might be covered by the GNU General + Public License. */ + +/* Implemented from the specification included in the Intel C++ Compiler + User Guide and Reference, version 8.0. */ + +#ifndef _EMMINTRIN_H_INCLUDED +#define _EMMINTRIN_H_INCLUDED + +#ifdef __SSE2__ +#include + +/* SSE2 */ +typedef int __v2df __attribute__ ((mode (V2DF))); +typedef int __v2di __attribute__ ((mode (V2DI))); +typedef int __v4si __attribute__ ((mode (V4SI))); +typedef int __v8hi __attribute__ ((mode (V8HI))); +typedef int __v16qi __attribute__ ((mode (V16QI))); + +/* Create a selector for use with the SHUFPD instruction. */ +#define _MM_SHUFFLE2(fp1,fp0) \ + (((fp1) << 1) | (fp0)) + +#define __m128i __v2di +#define __m128d __v2df + +/* Create a vector with element 0 as *P and the rest zero. */ +static __inline __m128d +_mm_load_sd (double const *__P) +{ + return (__m128d) __builtin_ia32_loadsd (__P); +} + +/* Create a vector with all two elements equal to *P. */ +static __inline __m128d +_mm_load1_pd (double const *__P) +{ + __v2df __tmp = __builtin_ia32_loadsd (__P); + return (__m128d) __builtin_ia32_shufpd (__tmp, __tmp, _MM_SHUFFLE2 (0,0)); +} + +static __inline __m128d +_mm_load_pd1 (double const *__P) +{ + return _mm_load1_pd (__P); +} + +/* Load two DPFP values from P. The address must be 16-byte aligned. */ +static __inline __m128d +_mm_load_pd (double const *__P) +{ + return (__m128d) __builtin_ia32_loadapd (__P); +} + +/* Load two DPFP values from P. The address need not be 16-byte aligned. */ +static __inline __m128d +_mm_loadu_pd (double const *__P) +{ + return (__m128d) __builtin_ia32_loadupd (__P); +} + +/* Load two DPFP values in reverse order. The address must be aligned. */ +static __inline __m128d +_mm_loadr_pd (double const *__P) +{ + __v2df __tmp = __builtin_ia32_loadapd (__P); + return (__m128d) __builtin_ia32_shufpd (__tmp, __tmp, _MM_SHUFFLE2 (0,1)); +} + +/* Create a vector with element 0 as F and the rest zero. */ +static __inline __m128d +_mm_set_sd (double __F) +{ + return (__m128d) __builtin_ia32_loadsd (&__F); +} + +/* Create a vector with all two elements equal to F. */ +static __inline __m128d +_mm_set1_pd (double __F) +{ + __v2df __tmp = __builtin_ia32_loadsd (&__F); + return (__m128d) __builtin_ia32_shufpd (__tmp, __tmp, _MM_SHUFFLE2 (0,0)); +} + +static __inline __m128d +_mm_set_pd1 (double __F) +{ + return _mm_set1_pd (__F); +} + +/* Create the vector [Z Y]. */ +static __inline __m128d +_mm_set_pd (double __Z, double __Y) +{ + union { + double __a[2]; + __m128d __v; + } __u; + + __u.__a[0] = __Y; + __u.__a[1] = __Z; + + return __u.__v; +} + +/* Create the vector [Y Z]. */ +static __inline __m128d +_mm_setr_pd (double __Z, double __Y) +{ + return _mm_set_pd (__Y, __Z); +} + +/* Create a vector of zeros. */ +static __inline __m128d +_mm_setzero_pd (void) +{ + return (__m128d) __builtin_ia32_setzeropd (); +} + +/* Stores the lower DPFP value. */ +static __inline void +_mm_store_sd (double *__P, __m128d __A) +{ + __builtin_ia32_storesd (__P, (__v2df)__A); +} + +/* Store the lower DPFP value acrosd two words. */ +static __inline void +_mm_store1_pd (double *__P, __m128d __A) +{ + __v2df __va = (__v2df)__A; + __v2df __tmp = __builtin_ia32_shufpd (__va, __va, _MM_SHUFFLE2 (0,0)); + __builtin_ia32_storeapd (__P, __tmp); +} + +static __inline void +_mm_store_pd1 (double *__P, __m128d __A) +{ + _mm_store1_pd (__P, __A); +} + +/* Store two DPFP values. The address must be 16-byte aligned. */ +static __inline void +_mm_store_pd (double *__P, __m128d __A) +{ + __builtin_ia32_storeapd (__P, (__v2df)__A); +} + +/* Store two DPFP values. The address need not be 16-byte aligned. */ +static __inline void +_mm_storeu_pd (double *__P, __m128d __A) +{ + __builtin_ia32_storeupd (__P, (__v2df)__A); +} + +/* Store two DPFP values in reverse order. The address must be aligned. */ +static __inline void +_mm_storer_pd (double *__P, __m128d __A) +{ + __v2df __va = (__v2df)__A; + __v2df __tmp = __builtin_ia32_shufpd (__va, __va, _MM_SHUFFLE2 (0,1)); + __builtin_ia32_storeapd (__P, __tmp); +} + +/* Sets the low DPFP value of A from the low value of B. */ +static __inline __m128d +_mm_move_sd (__m128d __A, __m128d __B) +{ + return (__m128d) __builtin_ia32_movsd ((__v2df)__A, (__v2df)__B); +} + + +static __inline __m128d +_mm_add_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_addpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_add_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_addsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_sub_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_subpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_sub_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_subsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_mul_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_mulpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_mul_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_mulsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_div_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_divpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_div_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_divsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_sqrt_pd (__m128d __A) +{ + return (__m128d)__builtin_ia32_sqrtpd ((__v2df)__A); +} + +/* Return pair {sqrt (A[0), B[1]}. */ +static __inline __m128d +_mm_sqrt_sd (__m128d __A, __m128d __B) +{ + __v2df __tmp = __builtin_ia32_movsd ((__v2df)__A, (__v2df)__B); + return (__m128d)__builtin_ia32_sqrtsd ((__v2df)__tmp); +} + +static __inline __m128d +_mm_min_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_minpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_min_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_minsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_max_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_maxpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_max_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_maxsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_and_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_andpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_andnot_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_andnpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_or_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_orpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_xor_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_xorpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpeq_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpeqpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmplt_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpltpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmple_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmplepd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpgt_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpgtpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpge_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpgepd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpneq_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpneqpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpnlt_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpnltpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpnle_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpnlepd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpngt_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpngtpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpnge_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpngepd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpord_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpordpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpunord_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpunordpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpeq_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpeqsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmplt_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpltsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmple_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmplesd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpgt_sd (__m128d __A, __m128d __B) +{ + return (__m128d) __builtin_ia32_movsd ((__v2df) __A, + (__v2df) + __builtin_ia32_cmpltsd ((__v2df) __B, + (__v2df) + __A)); +} + +static __inline __m128d +_mm_cmpge_sd (__m128d __A, __m128d __B) +{ + return (__m128d) __builtin_ia32_movsd ((__v2df) __A, + (__v2df) + __builtin_ia32_cmplesd ((__v2df) __B, + (__v2df) + __A)); +} + +static __inline __m128d +_mm_cmpneq_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpneqsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpnlt_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpnltsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpnle_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpnlesd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpngt_sd (__m128d __A, __m128d __B) +{ + return (__m128d) __builtin_ia32_movsd ((__v2df) __A, + (__v2df) + __builtin_ia32_cmpnltsd ((__v2df) __B, + (__v2df) + __A)); +} + +static __inline __m128d +_mm_cmpnge_sd (__m128d __A, __m128d __B) +{ + return (__m128d) __builtin_ia32_movsd ((__v2df) __A, + (__v2df) + __builtin_ia32_cmpnlesd ((__v2df) __B, + (__v2df) + __A)); +} + +static __inline __m128d +_mm_cmpord_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpordsd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_cmpunord_sd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_cmpunordsd ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_comieq_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_comisdeq ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_comilt_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_comisdlt ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_comile_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_comisdle ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_comigt_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_comisdgt ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_comige_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_comisdge ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_comineq_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_comisdneq ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_ucomieq_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_ucomisdeq ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_ucomilt_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_ucomisdlt ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_ucomile_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_ucomisdle ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_ucomigt_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_ucomisdgt ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_ucomige_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_ucomisdge ((__v2df)__A, (__v2df)__B); +} + +static __inline int +_mm_ucomineq_sd (__m128d __A, __m128d __B) +{ + return __builtin_ia32_ucomisdneq ((__v2df)__A, (__v2df)__B); +} + +/* Create a vector with element 0 as *P and the rest zero. */ + +static __inline __m128i +_mm_load_si128 (__m128i const *__P) +{ + return (__m128i) __builtin_ia32_loaddqa ((char const *)__P); +} + +static __inline __m128i +_mm_loadu_si128 (__m128i const *__P) +{ + return (__m128i) __builtin_ia32_loaddqu ((char const *)__P); +} + +static __inline __m128i +_mm_loadl_epi64 (__m128i const *__P) +{ + return (__m128i) __builtin_ia32_movq2dq (*(unsigned long long *)__P); +} + +static __inline void +_mm_store_si128 (__m128i *__P, __m128i __B) +{ + __builtin_ia32_storedqa ((char *)__P, (__v16qi)__B); +} + +static __inline void +_mm_storeu_si128 (__m128i *__P, __m128i __B) +{ + __builtin_ia32_storedqu ((char *)__P, (__v16qi)__B); +} + +static __inline void +_mm_storel_epi64 (__m128i *__P, __m128i __B) +{ + *(long long *)__P = __builtin_ia32_movdq2q ((__v2di)__B); +} + +static __inline __m64 +_mm_movepi64_pi64 (__m128i __B) +{ + return (__m64) __builtin_ia32_movdq2q ((__v2di)__B); +} + +static __inline __m128i +_mm_move_epi64 (__m128i __A) +{ + return (__m128i) __builtin_ia32_movq ((__v2di)__A); +} + +/* Create a vector of zeros. */ +static __inline __m128i +_mm_setzero_si128 (void) +{ + return (__m128i) __builtin_ia32_setzero128 (); +} + +static __inline __m128i +_mm_set_epi64 (__m64 __A, __m64 __B) +{ + __v2di __tmp = (__v2di)__builtin_ia32_movq2dq ((unsigned long long)__A); + __v2di __tmp2 = (__v2di)__builtin_ia32_movq2dq ((unsigned long long)__B); + return (__m128i)__builtin_ia32_punpcklqdq128 (__tmp2, __tmp); +} + +/* Create the vector [Z Y X W]. */ +static __inline __m128i +_mm_set_epi32 (int __Z, int __Y, int __X, int __W) +{ + union { + int __a[4]; + __m128i __v; + } __u; + + __u.__a[0] = __W; + __u.__a[1] = __X; + __u.__a[2] = __Y; + __u.__a[3] = __Z; + + return __u.__v; +} + +#ifdef __x86_64__ +/* Create the vector [Z Y]. */ +static __inline __m128i +_mm_set_epi64x (long long __Z, long long __Y) +{ + union { + long __a[2]; + __m128i __v; + } __u; + + __u.__a[0] = __Y; + __u.__a[1] = __Z; + + return __u.__v; +} +#endif + +/* Create the vector [S T U V Z Y X W]. */ +static __inline __m128i +_mm_set_epi16 (short __Z, short __Y, short __X, short __W, + short __V, short __U, short __T, short __S) +{ + union { + short __a[8]; + __m128i __v; + } __u; + + __u.__a[0] = __S; + __u.__a[1] = __T; + __u.__a[2] = __U; + __u.__a[3] = __V; + __u.__a[4] = __W; + __u.__a[5] = __X; + __u.__a[6] = __Y; + __u.__a[7] = __Z; + + return __u.__v; +} + +/* Create the vector [S T U V Z Y X W]. */ +static __inline __m128i +_mm_set_epi8 (char __Z, char __Y, char __X, char __W, + char __V, char __U, char __T, char __S, + char __Z1, char __Y1, char __X1, char __W1, + char __V1, char __U1, char __T1, char __S1) +{ + union { + char __a[16]; + __m128i __v; + } __u; + + __u.__a[0] = __S1; + __u.__a[1] = __T1; + __u.__a[2] = __U1; + __u.__a[3] = __V1; + __u.__a[4] = __W1; + __u.__a[5] = __X1; + __u.__a[6] = __Y1; + __u.__a[7] = __Z1; + __u.__a[8] = __S; + __u.__a[9] = __T; + __u.__a[10] = __U; + __u.__a[11] = __V; + __u.__a[12] = __W; + __u.__a[13] = __X; + __u.__a[14] = __Y; + __u.__a[15] = __Z; + + return __u.__v; +} + +static __inline __m128i +_mm_set1_epi64 (__m64 __A) +{ + __v2di __tmp = (__v2di)__builtin_ia32_movq2dq ((unsigned long long)__A); + return (__m128i)__builtin_ia32_punpcklqdq128 (__tmp, __tmp); +} + +static __inline __m128i +_mm_set1_epi32 (int __A) +{ + __v4si __tmp = (__v4si)__builtin_ia32_loadd (&__A); + return (__m128i) __builtin_ia32_pshufd ((__v4si)__tmp, _MM_SHUFFLE (0,0,0,0)); +} + +#ifdef __x86_64__ +static __inline __m128i +_mm_set1_epi64x (long long __A) +{ + __v2di __tmp = (__v2di)__builtin_ia32_movq2dq ((unsigned long long)__A); + return (__m128i) __builtin_ia32_shufpd ((__v2df)__tmp, (__v2df)__tmp, _MM_SHUFFLE2 (0,0)); +} +#endif + +static __inline __m128i +_mm_set1_epi16 (short __A) +{ + int __Acopy = (unsigned short)__A; + __v4si __tmp = (__v4si)__builtin_ia32_loadd (&__Acopy); + __tmp = (__v4si)__builtin_ia32_punpcklwd128 ((__v8hi)__tmp, (__v8hi)__tmp); + return (__m128i) __builtin_ia32_pshufd ((__v4si)__tmp, _MM_SHUFFLE (0,0,0,0)); +} + +static __inline __m128i +_mm_set1_epi8 (char __A) +{ + int __Acopy = (unsigned char)__A; + __v4si __tmp = (__v4si)__builtin_ia32_loadd (&__Acopy); + __tmp = (__v4si)__builtin_ia32_punpcklbw128 ((__v16qi)__tmp, (__v16qi)__tmp); + __tmp = (__v4si)__builtin_ia32_punpcklbw128 ((__v16qi)__tmp, (__v16qi)__tmp); + return (__m128i) __builtin_ia32_pshufd ((__v4si)__tmp, _MM_SHUFFLE (0,0,0,0)); +} + +static __inline __m128i +_mm_setr_epi64 (__m64 __A, __m64 __B) +{ + __v2di __tmp = (__v2di)__builtin_ia32_movq2dq ((unsigned long long)__A); + __v2di __tmp2 = (__v2di)__builtin_ia32_movq2dq ((unsigned long long)__B); + return (__m128i)__builtin_ia32_punpcklqdq128 (__tmp, __tmp2); +} + +/* Create the vector [Z Y X W]. */ +static __inline __m128i +_mm_setr_epi32 (int __W, int __X, int __Y, int __Z) +{ + union { + int __a[4]; + __m128i __v; + } __u; + + __u.__a[0] = __W; + __u.__a[1] = __X; + __u.__a[2] = __Y; + __u.__a[3] = __Z; + + return __u.__v; +} +/* Create the vector [S T U V Z Y X W]. */ +static __inline __m128i +_mm_setr_epi16 (short __S, short __T, short __U, short __V, + short __W, short __X, short __Y, short __Z) +{ + union { + short __a[8]; + __m128i __v; + } __u; + + __u.__a[0] = __S; + __u.__a[1] = __T; + __u.__a[2] = __U; + __u.__a[3] = __V; + __u.__a[4] = __W; + __u.__a[5] = __X; + __u.__a[6] = __Y; + __u.__a[7] = __Z; + + return __u.__v; +} + +/* Create the vector [S T U V Z Y X W]. */ +static __inline __m128i +_mm_setr_epi8 (char __S1, char __T1, char __U1, char __V1, + char __W1, char __X1, char __Y1, char __Z1, + char __S, char __T, char __U, char __V, + char __W, char __X, char __Y, char __Z) +{ + union { + char __a[16]; + __m128i __v; + } __u; + + __u.__a[0] = __S1; + __u.__a[1] = __T1; + __u.__a[2] = __U1; + __u.__a[3] = __V1; + __u.__a[4] = __W1; + __u.__a[5] = __X1; + __u.__a[6] = __Y1; + __u.__a[7] = __Z1; + __u.__a[8] = __S; + __u.__a[9] = __T; + __u.__a[10] = __U; + __u.__a[11] = __V; + __u.__a[12] = __W; + __u.__a[13] = __X; + __u.__a[14] = __Y; + __u.__a[15] = __Z; + + return __u.__v; +} + +static __inline __m128d +_mm_cvtepi32_pd (__m128i __A) +{ + return (__m128d)__builtin_ia32_cvtdq2pd ((__v4si) __A); +} + +static __inline __m128 +_mm_cvtepi32_ps (__m128i __A) +{ + return (__m128)__builtin_ia32_cvtdq2ps ((__v4si) __A); +} + +static __inline __m128i +_mm_cvtpd_epi32 (__m128d __A) +{ + return (__m128i)__builtin_ia32_cvtpd2dq ((__v2df) __A); +} + +static __inline __m64 +_mm_cvtpd_pi32 (__m128d __A) +{ + return (__m64)__builtin_ia32_cvtpd2pi ((__v2df) __A); +} + +static __inline __m128 +_mm_cvtpd_ps (__m128d __A) +{ + return (__m128)__builtin_ia32_cvtpd2ps ((__v2df) __A); +} + +static __inline __m128i +_mm_cvttpd_epi32 (__m128d __A) +{ + return (__m128i)__builtin_ia32_cvttpd2dq ((__v2df) __A); +} + +static __inline __m64 +_mm_cvttpd_pi32 (__m128d __A) +{ + return (__m64)__builtin_ia32_cvttpd2pi ((__v2df) __A); +} + +static __inline __m128d +_mm_cvtpi32_pd (__m64 __A) +{ + return (__m128d)__builtin_ia32_cvtpi2pd ((__v2si) __A); +} + +static __inline __m128i +_mm_cvtps_epi32 (__m128 __A) +{ + return (__m128i)__builtin_ia32_cvtps2dq ((__v4sf) __A); +} + +static __inline __m128i +_mm_cvttps_epi32 (__m128 __A) +{ + return (__m128i)__builtin_ia32_cvttps2dq ((__v4sf) __A); +} + +static __inline __m128d +_mm_cvtps_pd (__m128 __A) +{ + return (__m128d)__builtin_ia32_cvtps2pd ((__v4sf) __A); +} + +static __inline int +_mm_cvtsd_si32 (__m128d __A) +{ + return __builtin_ia32_cvtsd2si ((__v2df) __A); +} + +#ifdef __x86_64__ +static __inline long long +_mm_cvtsd_si64x (__m128d __A) +{ + return __builtin_ia32_cvtsd2si64 ((__v2df) __A); +} +#endif + +static __inline int +_mm_cvttsd_si32 (__m128d __A) +{ + return __builtin_ia32_cvttsd2si ((__v2df) __A); +} + +#ifdef __x86_64__ +static __inline long long +_mm_cvttsd_si64x (__m128d __A) +{ + return __builtin_ia32_cvttsd2si64 ((__v2df) __A); +} +#endif + +static __inline __m128 +_mm_cvtsd_ss (__m128 __A, __m128d __B) +{ + return (__m128)__builtin_ia32_cvtsd2ss ((__v4sf) __A, (__v2df) __B); +} + +static __inline __m128d +_mm_cvtsi32_sd (__m128d __A, int __B) +{ + return (__m128d)__builtin_ia32_cvtsi2sd ((__v2df) __A, __B); +} + +#ifdef __x86_64__ +static __inline __m128d +_mm_cvtsi64x_sd (__m128d __A, long long __B) +{ + return (__m128d)__builtin_ia32_cvtsi642sd ((__v2df) __A, __B); +} +#endif + +static __inline __m128d +_mm_cvtss_sd (__m128d __A, __m128 __B) +{ + return (__m128d)__builtin_ia32_cvtss2sd ((__v2df) __A, (__v4sf)__B); +} + +#define _mm_shuffle_pd(__A, __B, __C) ((__m128d)__builtin_ia32_shufpd ((__v2df)__A, (__v2df)__B, (__C))) + +static __inline __m128d +_mm_unpackhi_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_unpckhpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_unpacklo_pd (__m128d __A, __m128d __B) +{ + return (__m128d)__builtin_ia32_unpcklpd ((__v2df)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_loadh_pd (__m128d __A, double const *__B) +{ + return (__m128d)__builtin_ia32_loadhpd ((__v2df)__A, (__v2si *)__B); +} + +static __inline void +_mm_storeh_pd (double *__A, __m128d __B) +{ + __builtin_ia32_storehpd ((__v2si *)__A, (__v2df)__B); +} + +static __inline __m128d +_mm_loadl_pd (__m128d __A, double const *__B) +{ + return (__m128d)__builtin_ia32_loadlpd ((__v2df)__A, (__v2si *)__B); +} + +static __inline void +_mm_storel_pd (double *__A, __m128d __B) +{ + __builtin_ia32_storelpd ((__v2si *)__A, (__v2df)__B); +} + +static __inline int +_mm_movemask_pd (__m128d __A) +{ + return __builtin_ia32_movmskpd ((__v2df)__A); +} + +static __inline __m128i +_mm_packs_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_packsswb128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_packs_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_packssdw128 ((__v4si)__A, (__v4si)__B); +} + +static __inline __m128i +_mm_packus_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_packuswb128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_unpackhi_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpckhbw128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_unpackhi_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpckhwd128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_unpackhi_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpckhdq128 ((__v4si)__A, (__v4si)__B); +} + +static __inline __m128i +_mm_unpackhi_epi64 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpckhqdq128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_unpacklo_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpcklbw128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_unpacklo_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpcklwd128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_unpacklo_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpckldq128 ((__v4si)__A, (__v4si)__B); +} + +static __inline __m128i +_mm_unpacklo_epi64 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_punpcklqdq128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_add_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_add_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_add_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddd128 ((__v4si)__A, (__v4si)__B); +} + +static __inline __m128i +_mm_add_epi64 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddq128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_adds_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddsb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_adds_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddsw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_adds_epu8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddusb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_adds_epu16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_paddusw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_sub_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_sub_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_sub_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubd128 ((__v4si)__A, (__v4si)__B); +} + +static __inline __m128i +_mm_sub_epi64 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubq128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_subs_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubsb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_subs_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubsw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_subs_epu8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubusb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_subs_epu16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psubusw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_madd_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pmaddwd128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_mulhi_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pmulhw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_mullo_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pmullw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m64 +_mm_mul_su32 (__m64 __A, __m64 __B) +{ + return (__m64)__builtin_ia32_pmuludq ((__v2si)__A, (__v2si)__B); +} + +static __inline __m128i +_mm_mul_epu32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pmuludq128 ((__v4si)__A, (__v4si)__B); +} + +static __inline __m128i +_mm_sll_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psllw128 ((__v8hi)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_sll_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pslld128 ((__v4si)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_sll_epi64 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psllq128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_sra_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psraw128 ((__v8hi)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_sra_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psrad128 ((__v4si)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_srl_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psrlw128 ((__v8hi)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_srl_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psrld128 ((__v4si)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_srl_epi64 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psrlq128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_slli_epi16 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_psllwi128 ((__v8hi)__A, __B); +} + +static __inline __m128i +_mm_slli_epi32 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_pslldi128 ((__v4si)__A, __B); +} + +static __inline __m128i +_mm_slli_epi64 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_psllqi128 ((__v2di)__A, __B); +} + +static __inline __m128i +_mm_srai_epi16 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_psrawi128 ((__v8hi)__A, __B); +} + +static __inline __m128i +_mm_srai_epi32 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_psradi128 ((__v4si)__A, __B); +} + +#if 0 +static __m128i __attribute__((__always_inline__)) +_mm_srli_si128 (__m128i __A, const int __B) +{ + return ((__m128i)__builtin_ia32_psrldqi128 (__A, __B)) +} + +static __m128i __attribute__((__always_inline__)) +_mm_srli_si128 (__m128i __A, const int __B) +{ + return ((__m128i)__builtin_ia32_pslldqi128 (__A, __B)) +} +#endif +#define _mm_srli_si128(__A, __B) ((__m128i)__builtin_ia32_psrldqi128 (__A, __B)) +#define _mm_slli_si128(__A, __B) ((__m128i)__builtin_ia32_pslldqi128 (__A, __B)) + +static __inline __m128i +_mm_srli_epi16 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_psrlwi128 ((__v8hi)__A, __B); +} + +static __inline __m128i +_mm_srli_epi32 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_psrldi128 ((__v4si)__A, __B); +} + +static __inline __m128i +_mm_srli_epi64 (__m128i __A, int __B) +{ + return (__m128i)__builtin_ia32_psrlqi128 ((__v2di)__A, __B); +} + +static __inline __m128i +_mm_and_si128 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pand128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_andnot_si128 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pandn128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_or_si128 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_por128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_xor_si128 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pxor128 ((__v2di)__A, (__v2di)__B); +} + +static __inline __m128i +_mm_cmpeq_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpeqb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_cmpeq_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpeqw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_cmpeq_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpeqd128 ((__v4si)__A, (__v4si)__B); +} + +static __inline __m128i +_mm_cmplt_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpgtb128 ((__v16qi)__B, (__v16qi)__A); +} + +static __inline __m128i +_mm_cmplt_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpgtw128 ((__v8hi)__B, (__v8hi)__A); +} + +static __inline __m128i +_mm_cmplt_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpgtd128 ((__v4si)__B, (__v4si)__A); +} + +static __inline __m128i +_mm_cmpgt_epi8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpgtb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_cmpgt_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpgtw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_cmpgt_epi32 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pcmpgtd128 ((__v4si)__A, (__v4si)__B); +} + +#define _mm_extract_epi16(__A, __B) __builtin_ia32_pextrw128 ((__v8hi)__A, __B) + +#define _mm_insert_epi16(__A, __B, __C) ((__m128i)__builtin_ia32_pinsrw128 ((__v8hi)__A, __B, __C)) + +static __inline __m128i +_mm_max_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pmaxsw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_max_epu8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pmaxub128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_min_epi16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pminsw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_min_epu8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pminub128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline int +_mm_movemask_epi8 (__m128i __A) +{ + return __builtin_ia32_pmovmskb128 ((__v16qi)__A); +} + +static __inline __m128i +_mm_mulhi_epu16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pmulhuw128 ((__v8hi)__A, (__v8hi)__B); +} + +#define _mm_shufflehi_epi16(__A, __B) ((__m128i)__builtin_ia32_pshufhw ((__v8hi)__A, __B)) +#define _mm_shufflelo_epi16(__A, __B) ((__m128i)__builtin_ia32_pshuflw ((__v8hi)__A, __B)) +#define _mm_shuffle_epi32(__A, __B) ((__m128i)__builtin_ia32_pshufd ((__v4si)__A, __B)) + +static __inline void +_mm_maskmoveu_si128 (__m128i __A, __m128i __B, char *__C) +{ + __builtin_ia32_maskmovdqu ((__v16qi)__A, (__v16qi)__B, __C); +} + +static __inline __m128i +_mm_avg_epu8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pavgb128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline __m128i +_mm_avg_epu16 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_pavgw128 ((__v8hi)__A, (__v8hi)__B); +} + +static __inline __m128i +_mm_sad_epu8 (__m128i __A, __m128i __B) +{ + return (__m128i)__builtin_ia32_psadbw128 ((__v16qi)__A, (__v16qi)__B); +} + +static __inline void +_mm_stream_si32 (int *__A, int __B) +{ + __builtin_ia32_movnti (__A, __B); +} + +static __inline void +_mm_stream_si128 (__m128i *__A, __m128i __B) +{ + __builtin_ia32_movntdq ((__v2di *)__A, (__v2di)__B); +} + +static __inline void +_mm_stream_pd (double *__A, __m128d __B) +{ + __builtin_ia32_movntpd (__A, (__v2df)__B); +} + +static __inline __m128i +_mm_movpi64_epi64 (__m64 __A) +{ + return (__m128i)__builtin_ia32_movq2dq ((unsigned long long)__A); +} + +static __inline void +_mm_clflush (void const *__A) +{ + return __builtin_ia32_clflush (__A); +} + +static __inline void +_mm_lfence (void) +{ + __builtin_ia32_lfence (); +} + +static __inline void +_mm_mfence (void) +{ + __builtin_ia32_mfence (); +} + +static __inline __m128i +_mm_cvtsi32_si128 (int __A) +{ + return (__m128i) __builtin_ia32_loadd (&__A); +} + +#ifdef __x86_64__ +static __inline __m128i +_mm_cvtsi64x_si128 (long long __A) +{ + return (__m128i) __builtin_ia32_movq2dq (__A); +} +#endif + +static __inline int +_mm_cvtsi128_si32 (__m128i __A) +{ + int __tmp; + __builtin_ia32_stored (&__tmp, (__v4si)__A); + return __tmp; +} + +#ifdef __x86_64__ +static __inline long long +_mm_cvtsi128_si64x (__m128i __A) +{ + return __builtin_ia32_movdq2q ((__v2di)__A); +} +#endif + +#endif /* __SSE2__ */ + +#endif /* _EMMINTRIN_H_INCLUDED */ diff --git a/src/include/err.h b/src/include/err.h new file mode 100644 index 0000000..a3c04cf --- /dev/null +++ b/src/include/err.h @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 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. + * + * @(#)err.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/err.h,v 1.11 2002/08/21 16:19:55 mike Exp $ + */ + +#ifndef _ERR_H_ +#define _ERR_H_ + +/* + * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two + * places ( and ), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include err.h, so we get + * __va_list from and use it. + */ +#include +#include + +__BEGIN_DECLS +void err(int, const char *, ...) __dead2 __printf0like(2, 3); +void verr(int, const char *, __va_list) __dead2 __printf0like(2, 0); +void errc(int, int, const char *, ...) __dead2 __printf0like(3, 4); +void verrc(int, int, const char *, __va_list) __dead2 + __printf0like(3, 0); +void errx(int, const char *, ...) __dead2 __printf0like(2, 3); +void verrx(int, const char *, __va_list) __dead2 __printf0like(2, 0); +void warn(const char *, ...) __printf0like(1, 2); +void vwarn(const char *, __va_list) __printf0like(1, 0); +void warnc(int, const char *, ...) __printf0like(2, 3); +void vwarnc(int, const char *, __va_list) __printf0like(2, 0); +void warnx(const char *, ...) __printflike(1, 2); +void vwarnx(const char *, __va_list) __printflike(1, 0); +void err_set_file(void *); +void err_set_exit(void (*)(int)); +__END_DECLS + +#endif /* !_ERR_H_ */ diff --git a/src/include/errno.h b/src/include/errno.h new file mode 100644 index 0000000..d775e98 --- /dev/null +++ b/src/include/errno.h @@ -0,0 +1,182 @@ +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)errno.h 8.5 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/errno.h,v 1.26 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_ERRNO_H_ +#define _SYS_ERRNO_H_ + +#ifndef _KERNEL +#include +__BEGIN_DECLS +int * __error(void); +__END_DECLS +#define errno (* __error()) +#endif + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* Device not configured */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EDEADLK 11 /* Resource deadlock avoided */ + /* 11 was EAGAIN */ +#define ENOMEM 12 /* Cannot allocate memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#ifndef _POSIX_SOURCE +#define ENOTBLK 15 /* Block device required */ +#endif +#define EBUSY 16 /* Device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* Operation not supported by device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate ioctl for device */ +#ifndef _POSIX_SOURCE +#define ETXTBSY 26 /* Text file busy */ +#endif +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only filesystem */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ + +/* math software */ +#define EDOM 33 /* Numerical argument out of domain */ +#define ERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define EAGAIN 35 /* Resource temporarily unavailable */ +#ifndef _POSIX_SOURCE +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ + +/* ipc/network software -- argument errors */ +#define ENOTSOCK 38 /* Socket operation on non-socket */ +#define EDESTADDRREQ 39 /* Destination address required */ +#define EMSGSIZE 40 /* Message too long */ +#define EPROTOTYPE 41 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 42 /* Protocol not available */ +#define EPROTONOSUPPORT 43 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ +#define EOPNOTSUPP 45 /* Operation not supported */ +#define ENOTSUP EOPNOTSUPP /* Operation not supported */ +#define EPFNOSUPPORT 46 /* Protocol family not supported */ +#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define EADDRINUSE 48 /* Address already in use */ +#define EADDRNOTAVAIL 49 /* Can't assign requested address */ + +/* ipc/network software -- operational errors */ +#define ENETDOWN 50 /* Network is down */ +#define ENETUNREACH 51 /* Network is unreachable */ +#define ENETRESET 52 /* Network dropped connection on reset */ +#define ECONNABORTED 53 /* Software caused connection abort */ +#define ECONNRESET 54 /* Connection reset by peer */ +#define ENOBUFS 55 /* No buffer space available */ +#define EISCONN 56 /* Socket is already connected */ +#define ENOTCONN 57 /* Socket is not connected */ +#define ESHUTDOWN 58 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 59 /* Too many references: can't splice */ +#define ETIMEDOUT 60 /* Operation timed out */ +#define ECONNREFUSED 61 /* Connection refused */ + +#define ELOOP 62 /* Too many levels of symbolic links */ +#endif /* _POSIX_SOURCE */ +#define ENAMETOOLONG 63 /* File name too long */ + +/* should be rearranged */ +#ifndef _POSIX_SOURCE +#define EHOSTDOWN 64 /* Host is down */ +#define EHOSTUNREACH 65 /* No route to host */ +#endif /* _POSIX_SOURCE */ +#define ENOTEMPTY 66 /* Directory not empty */ + +/* quotas & mush */ +#ifndef _POSIX_SOURCE +#define EPROCLIM 67 /* Too many processes */ +#define EUSERS 68 /* Too many users */ +#define EDQUOT 69 /* Disc quota exceeded */ + +/* Network File System */ +#define ESTALE 70 /* Stale NFS file handle */ +#define EREMOTE 71 /* Too many levels of remote in path */ +#define EBADRPC 72 /* RPC struct is bad */ +#define ERPCMISMATCH 73 /* RPC version wrong */ +#define EPROGUNAVAIL 74 /* RPC prog. not avail */ +#define EPROGMISMATCH 75 /* Program version wrong */ +#define EPROCUNAVAIL 76 /* Bad procedure for program */ +#endif /* _POSIX_SOURCE */ + +#define ENOLCK 77 /* No locks available */ +#define ENOSYS 78 /* Function not implemented */ + +#ifndef _POSIX_SOURCE +#define EFTYPE 79 /* Inappropriate file type or format */ +#define EAUTH 80 /* Authentication error */ +#define ENEEDAUTH 81 /* Need authenticator */ +#define EIDRM 82 /* Identifier removed */ +#define ENOMSG 83 /* No message of desired type */ +#define EOVERFLOW 84 /* Value too large to be stored in data type */ +#define ECANCELED 85 /* Operation canceled */ +#define EILSEQ 86 /* Illegal byte sequence */ +#define ENOATTR 87 /* Attribute not found */ + +#define EDOOFUS 88 /* Programming error */ + +#define ELAST 88 /* Must be equal largest errno */ + +#endif /* _POSIX_SOURCE */ + +#ifdef _KERNEL +/* pseudo-errors returned inside kernel to modify return to process */ +#define ERESTART (-1) /* restart syscall */ +#define EJUSTRETURN (-2) /* don't modify regs, just return */ +#define ENOIOCTL (-3) /* ioctl not handled by this layer */ +#define EDIRIOCTL (-4) /* do direct ioctl in GEOM */ +#endif + +#endif diff --git a/src/include/eti.h b/src/include/eti.h new file mode 100644 index 0000000..4561fa4 --- /dev/null +++ b/src/include/eti.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer 1995,1997 * + ****************************************************************************/ + +#ifndef NCURSES_ETI_H_incl +#define NCURSES_ETI_H_incl 1 + +#define E_OK (0) +#define E_SYSTEM_ERROR (-1) +#define E_BAD_ARGUMENT (-2) +#define E_POSTED (-3) +#define E_CONNECTED (-4) +#define E_BAD_STATE (-5) +#define E_NO_ROOM (-6) +#define E_NOT_POSTED (-7) +#define E_UNKNOWN_COMMAND (-8) +#define E_NO_MATCH (-9) +#define E_NOT_SELECTABLE (-10) +#define E_NOT_CONNECTED (-11) +#define E_REQUEST_DENIED (-12) +#define E_INVALID_FIELD (-13) +#define E_CURRENT (-14) + +#endif diff --git a/src/include/fcntl.h b/src/include/fcntl.h new file mode 100644 index 0000000..2fb656e --- /dev/null +++ b/src/include/fcntl.h @@ -0,0 +1,229 @@ +/*- + * Copyright (c) 1983, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)fcntl.h 8.3 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/fcntl.h,v 1.16 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_FCNTL_H_ +#define _SYS_FCNTL_H_ + +/* + * This file includes the definitions for open and fcntl + * described by POSIX for ; it also includes + * related kernel definitions. + */ + +#include +#include + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +/* + * File status flags: these are used by open(2), fcntl(2). + * They are also used (indirectly) in the kernel file structure f_flags, + * which is a superset of the open/fcntl flags. Open flags and f_flags + * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). + * Open/fcntl flags begin with O_; kernel-internal flags begin with F. + */ +/* open-only flags */ +#define O_RDONLY 0x0000 /* open for reading only */ +#define O_WRONLY 0x0001 /* open for writing only */ +#define O_RDWR 0x0002 /* open for reading and writing */ +#define O_ACCMODE 0x0003 /* mask for above modes */ + +/* + * Kernel encoding of open mode; separate read and write bits that are + * independently testable: 1 greater than the above. + * + * XXX + * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH, + * which was documented to use FREAD/FWRITE, continues to work. + */ +#if __BSD_VISIBLE +#define FREAD 0x0001 +#define FWRITE 0x0002 +#endif +#define O_NONBLOCK 0x0004 /* no delay */ +#define O_APPEND 0x0008 /* set append mode */ +#if __BSD_VISIBLE +#define O_SHLOCK 0x0010 /* open with shared file lock */ +#define O_EXLOCK 0x0020 /* open with exclusive file lock */ +#define O_ASYNC 0x0040 /* signal pgrp when data ready */ +#define O_FSYNC 0x0080 /* synchronous writes */ +#endif +#define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */ +#if __BSD_VISIBLE +#define O_NOFOLLOW 0x0100 /* don't follow symlinks */ +#endif +#define O_CREAT 0x0200 /* create if nonexistent */ +#define O_TRUNC 0x0400 /* truncate to zero length */ +#define O_EXCL 0x0800 /* error if already exists */ +#ifdef _KERNEL +#define FHASLOCK 0x4000 /* descriptor holds advisory lock */ +#endif + +/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */ +#define O_NOCTTY 0x8000 /* don't assign controlling terminal */ + +#if __BSD_VISIBLE +/* Attempt to bypass buffer cache */ +#define O_DIRECT 0x00010000 +#endif + +/* + * XXX missing O_DSYNC, O_RSYNC. + */ + +#ifdef _KERNEL +/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ +#define FFLAGS(oflags) ((oflags) + 1) +#define OFLAGS(fflags) ((fflags) - 1) + +/* bits to save after open */ +#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT) +/* bits settable by fcntl(F_SETFL, ...) */ +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT) +#endif + +/* + * The O_* flags used to have only F* names, which were used in the kernel + * and by fcntl. We retain the F* names for the kernel f_flag field + * and for backward compatibility for fcntl. These flags are deprecated. + */ +#if __BSD_VISIBLE +#define FAPPEND O_APPEND /* kernel/compat */ +#define FASYNC O_ASYNC /* kernel/compat */ +#define FFSYNC O_FSYNC /* kernel */ +#define FNONBLOCK O_NONBLOCK /* kernel */ +#define FNDELAY O_NONBLOCK /* compat */ +#define O_NDELAY O_NONBLOCK /* compat */ +#endif + +/* + * We are out of bits in f_flag (which is a short). However, + * the flag bits not set in FMASK are only meaningful in the + * initial open syscall. Those bits can thus be given a + * different meaning for fcntl(2). + */ +#if __BSD_VISIBLE + +/* + * Set by shm_open(3) to get automatic MAP_ASYNC behavior + * for POSIX shared memory objects (which are otherwise + * implemented as plain files). + */ +#define FPOSIXSHM O_NOFOLLOW +#endif + +/* + * Constants used for fcntl(2) + */ + +/* command values */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ +#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ +#endif +#define F_GETLK 7 /* get record locking information */ +#define F_SETLK 8 /* set record locking information */ +#define F_SETLKW 9 /* F_SETLK; wait if blocked */ + +/* file descriptor flags (F_GETFD, F_SETFD) */ +#define FD_CLOEXEC 1 /* close-on-exec flag */ + +/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ +#define F_RDLCK 1 /* shared or read lock */ +#define F_UNLCK 2 /* unlock */ +#define F_WRLCK 3 /* exclusive or write lock */ +#ifdef _KERNEL +#define F_WAIT 0x010 /* Wait until lock is granted */ +#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ +#define F_POSIX 0x040 /* Use POSIX semantics for lock */ +#endif + +/* + * Advisory file segment locking data type - + * information passed to system by user + */ +struct flock { + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ +}; + + +#if __BSD_VISIBLE +/* lock operations for flock(2) */ +#define LOCK_SH 0x01 /* shared file lock */ +#define LOCK_EX 0x02 /* exclusive file lock */ +#define LOCK_NB 0x04 /* don't block when locking */ +#define LOCK_UN 0x08 /* unlock file */ +#endif + +/* + * XXX missing posix_fadvise() and posix_fallocate(), and POSIX_FADV_* macros. + */ + +#ifndef _KERNEL +__BEGIN_DECLS +int open(const char *, int, ...); +int creat(const char *, mode_t); +int fcntl(int, int, ...); +#if __BSD_VISIBLE +int flock(int, int); +#endif +__END_DECLS +#endif + +#endif /* !_SYS_FCNTL_H_ */ diff --git a/src/include/fetch.h b/src/include/fetch.h new file mode 100644 index 0000000..17472e5 --- /dev/null +++ b/src/include/fetch.h @@ -0,0 +1,150 @@ +/*- + * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/lib/libfetch/fetch.h,v 1.25 2002/07/22 16:11:39 des Exp $ + */ + +#ifndef _FETCH_H_INCLUDED +#define _FETCH_H_INCLUDED + +#define _LIBFETCH_VER "libfetch/2.0" + +#define URL_SCHEMELEN 16 +#define URL_USERLEN 256 +#define URL_PWDLEN 256 + +struct url { + char scheme[URL_SCHEMELEN+1]; + char user[URL_USERLEN+1]; + char pwd[URL_PWDLEN+1]; + char host[MAXHOSTNAMELEN+1]; + int port; + char *doc; + off_t offset; + size_t length; +}; + +struct url_stat { + off_t size; + time_t atime; + time_t mtime; +}; + +struct url_ent { + char name[PATH_MAX]; + struct url_stat stat; +}; + +/* Recognized schemes */ +#define SCHEME_FTP "ftp" +#define SCHEME_HTTP "http" +#define SCHEME_HTTPS "https" +#define SCHEME_FILE "file" + +/* Error codes */ +#define FETCH_ABORT 1 +#define FETCH_AUTH 2 +#define FETCH_DOWN 3 +#define FETCH_EXISTS 4 +#define FETCH_FULL 5 +#define FETCH_INFO 6 +#define FETCH_MEMORY 7 +#define FETCH_MOVED 8 +#define FETCH_NETWORK 9 +#define FETCH_OK 10 +#define FETCH_PROTO 11 +#define FETCH_RESOLV 12 +#define FETCH_SERVER 13 +#define FETCH_TEMP 14 +#define FETCH_TIMEOUT 15 +#define FETCH_UNAVAIL 16 +#define FETCH_UNKNOWN 17 +#define FETCH_URL 18 +#define FETCH_VERBOSE 19 + +__BEGIN_DECLS + +/* FILE-specific functions */ +FILE *fetchXGetFile(struct url *, struct url_stat *, const char *); +FILE *fetchGetFile(struct url *, const char *); +FILE *fetchPutFile(struct url *, const char *); +int fetchStatFile(struct url *, struct url_stat *, const char *); +struct url_ent *fetchListFile(struct url *, const char *); + +/* HTTP-specific functions */ +FILE *fetchXGetHTTP(struct url *, struct url_stat *, const char *); +FILE *fetchGetHTTP(struct url *, const char *); +FILE *fetchPutHTTP(struct url *, const char *); +int fetchStatHTTP(struct url *, struct url_stat *, const char *); +struct url_ent *fetchListHTTP(struct url *, const char *); + +/* FTP-specific functions */ +FILE *fetchXGetFTP(struct url *, struct url_stat *, const char *); +FILE *fetchGetFTP(struct url *, const char *); +FILE *fetchPutFTP(struct url *, const char *); +int fetchStatFTP(struct url *, struct url_stat *, const char *); +struct url_ent *fetchListFTP(struct url *, const char *); + +/* Generic functions */ +FILE *fetchXGetURL(const char *, struct url_stat *, const char *); +FILE *fetchGetURL(const char *, const char *); +FILE *fetchPutURL(const char *, const char *); +int fetchStatURL(const char *, struct url_stat *, const char *); +struct url_ent *fetchListURL(const char *, const char *); +FILE *fetchXGet(struct url *, struct url_stat *, const char *); +FILE *fetchGet(struct url *, const char *); +FILE *fetchPut(struct url *, const char *); +int fetchStat(struct url *, struct url_stat *, const char *); +struct url_ent *fetchList(struct url *, const char *); + +/* URL parsing */ +struct url *fetchMakeURL(const char *, const char *, int, + const char *, const char *, const char *); +struct url *fetchParseURL(const char *); +void fetchFreeURL(struct url *); + +__END_DECLS + +/* Authentication */ +typedef int (*auth_t)(struct url *); +extern auth_t fetchAuthMethod; + +/* Last error code */ +extern int fetchLastErrCode; +#define MAXERRSTRING 256 +extern char fetchLastErrString[MAXERRSTRING]; + +/* I/O timeout */ +extern int fetchTimeout; + +/* Restart interrupted syscalls */ +extern int fetchRestartCalls; + +/* Extra verbosity */ +extern int fetchDebug; + +#endif diff --git a/src/include/float.h b/src/include/float.h new file mode 100644 index 0000000..7fd7e8d --- /dev/null +++ b/src/include/float.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1989 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. + * 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. + * + * from: @(#)float.h 7.1 (Berkeley) 5/8/90 + * $FreeBSD: src/sys/i386/include/float.h,v 1.12 2004/04/25 02:36:28 das Exp $ + */ + +#ifndef _MACHINE_FLOAT_H_ +#define _MACHINE_FLOAT_H_ 1 + +#include + +#define FLT_RADIX 2 /* b */ +#define FLT_ROUNDS 1 /* FP addition rounds to nearest */ +#if __ISO_C_VISIBLE >= 1999 +#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */ +#define DECIMAL_DIG 21 /* max precision in decimal digits */ +#endif + +#define FLT_MANT_DIG 24 /* p */ +#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define FLT_MIN_EXP (-125) /* emin */ +#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define FLT_MAX_EXP 128 /* emax */ +#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define DBL_MANT_DIG 53 +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_EXP 1024 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MAX_10_EXP 308 + + +#define LDBL_MANT_DIG 64 +#define LDBL_EPSILON 1.0842021724855044340E-19L +#define LDBL_DIG 18 +#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN 3.3621031431120935063E-4932L +#define LDBL_MIN_10_EXP (-4931) +#define LDBL_MAX_EXP 16384 +#define LDBL_MAX 1.1897314953572317650E+4932L +#define LDBL_MAX_10_EXP 4932 +#endif /* _MACHINE_FLOAT_H_ */ diff --git a/src/include/floatingpoint.h b/src/include/floatingpoint.h new file mode 100644 index 0000000..65cb4a3 --- /dev/null +++ b/src/include/floatingpoint.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 1993 Andrew Moore, Talke Studio + * 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. + * + * from: @(#) floatingpoint.h 1.0 (Berkeley) 9/23/93 + * $FreeBSD: src/sys/i386/include/floatingpoint.h,v 1.13 2003/01/19 06:01:33 marcel Exp $ + */ + +#ifndef _FLOATINGPOINT_H_ +#define _FLOATINGPOINT_H_ + +#include + +#endif /* !_FLOATINGPOINT_H_ */ diff --git a/src/include/fmtmsg.h b/src/include/fmtmsg.h new file mode 100644 index 0000000..256cf33 --- /dev/null +++ b/src/include/fmtmsg.h @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/fmtmsg.h,v 1.2 2002/08/05 16:37:05 mike Exp $ + */ + +#ifndef _FMTMSG_H_ +#define _FMTMSG_H_ + +/* Source of condition is... */ +#define MM_HARD 0x0001 /* ...hardware. */ +#define MM_SOFT 0x0002 /* ...software. */ +#define MM_FIRM 0x0004 /* ...fireware. */ + +/* Condition detected by... */ +#define MM_APPL 0x0010 /* ...application. */ +#define MM_UTIL 0x0020 /* ...utility. */ +#define MM_OPSYS 0x0040 /* ...operating system. */ + +/* Display on... */ +#define MM_PRINT 0x0100 /* ...standard error. */ +#define MM_CONSOLE 0x0200 /* ...system console. */ + +#define MM_RECOVER 0x1000 /* Recoverable error. */ +#define MM_NRECOV 0x2000 /* Non-recoverable error. */ + +/* Severity levels. */ +#define MM_NOSEV 0 /* No severity level provided. */ +#define MM_HALT 1 /* Error causing application to halt. */ +#define MM_ERROR 2 /* Non-fault fault. */ +#define MM_WARNING 3 /* Unusual non-error condition. */ +#define MM_INFO 4 /* Informative message. */ + +/* Null options. */ +#define MM_NULLLBL (char *)0 +#define MM_NULLSEV 0 +#define MM_NULLMC 0L +#define MM_NULLTXT (char *)0 +#define MM_NULLACT (char *)0 +#define MM_NULLTAG (char *)0 + +/* Return values. */ +#define MM_OK 0 /* Success. */ +#define MM_NOMSG 1 /* Failed to output to stderr. */ +#define MM_NOCON 2 /* Failed to output to console. */ +#define MM_NOTOK 3 /* Failed to output anything. */ + +int fmtmsg(long, const char *, int, const char *, const char *, + const char *); + +#endif /* !_FMTMSG_H_ */ diff --git a/src/include/fnmatch.h b/src/include/fnmatch.h new file mode 100644 index 0000000..d1cc03a --- /dev/null +++ b/src/include/fnmatch.h @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 1992, 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. + * + * $FreeBSD: src/include/fnmatch.h,v 1.15 2003/12/18 10:41:39 jkh Exp $ + * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _FNMATCH_H_ +#define _FNMATCH_H_ + +#include + +#define FNM_NOMATCH 1 /* Match failed. */ + +#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ +#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ +#define FNM_PERIOD 0x04 /* Period must be matched by period. */ + +#if __XSI_VISIBLE +#define FNM_NOSYS (-1) /* Reserved. */ +#endif + +#if __BSD_VISIBLE +#define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME +#endif + +__BEGIN_DECLS +int fnmatch(const char *, const char *, int); +__END_DECLS + +#endif /* !_FNMATCH_H_ */ diff --git a/src/include/form.h b/src/include/form.h new file mode 100644 index 0000000..140b25f --- /dev/null +++ b/src/include/form.h @@ -0,0 +1,383 @@ +/**************************************************************************** + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer 1995,1997 * + ****************************************************************************/ + +#ifndef FORM_H +#define FORM_H + +#include +#include + +#ifdef __cplusplus + extern "C" { +#endif + +typedef int Form_Options; +typedef int Field_Options; + + /********** + * _PAGE * + **********/ + +typedef struct { + short pmin; /* index of first field on page */ + short pmax; /* index of last field on page */ + short smin; /* index of top leftmost field on page */ + short smax; /* index of bottom rightmost field on page */ +} _PAGE; + + /********** + * FIELD * + **********/ + +typedef struct fieldnode { + unsigned short status; /* flags */ + short rows; /* size in rows */ + short cols; /* size in cols */ + short frow; /* first row */ + short fcol; /* first col */ + int drows; /* dynamic rows */ + int dcols; /* dynamic cols */ + int maxgrow; /* maximum field growth */ + int nrow; /* offscreen rows */ + short nbuf; /* additional buffers */ + short just; /* justification */ + short page; /* page on form */ + short index; /* into form -> field */ + int pad; /* pad character */ + chtype fore; /* foreground attribute */ + chtype back; /* background attribute */ + Field_Options opts; /* options */ + struct fieldnode * snext; /* sorted order pointer */ + struct fieldnode * sprev; /* sorted order pointer */ + struct fieldnode * link; /* linked field chain */ + struct formnode * form; /* containing form */ + struct typenode * type; /* field type */ + void * arg; /* argument for type */ + char * buf; /* field buffers */ + void * usrptr; /* user pointer */ +} FIELD; + + /************** + * FIELDTYPE * + **************/ + +typedef struct typenode { + unsigned short status; /* flags */ + long ref; /* reference count */ + struct typenode * left; /* ptr to operand for | */ + struct typenode * right; /* ptr to operand for | */ + + void* (*makearg)(va_list *); /* make fieldtype arg */ + void* (*copyarg)(const void *); /* copy fieldtype arg */ + void (*freearg)(void *); /* free fieldtype arg */ + + bool (*fcheck)(FIELD *,const void *); /* field validation */ + bool (*ccheck)(int,const void *); /* character validation */ + + bool (*next)(FIELD *,const void *); /* enumerate next value */ + bool (*prev)(FIELD *,const void *); /* enumerate prev value */ + +} FIELDTYPE; + + /********* + * FORM * + *********/ + +typedef struct formnode { + unsigned short status; /* flags */ + short rows; /* size in rows */ + short cols; /* size in cols */ + int currow; /* current row in field window*/ + int curcol; /* current col in field window*/ + int toprow; /* in scrollable field window */ + int begincol; /* in horiz. scrollable field */ + short maxfield; /* number of fields */ + short maxpage; /* number of pages */ + short curpage; /* index into page */ + Form_Options opts; /* options */ + WINDOW * win; /* window */ + WINDOW * sub; /* subwindow */ + WINDOW * w; /* window for current field */ + FIELD ** field; /* field [maxfield] */ + FIELD * current; /* current field */ + _PAGE * page; /* page [maxpage] */ + void * usrptr; /* user pointer */ + + void (*forminit)(struct formnode *); + void (*formterm)(struct formnode *); + void (*fieldinit)(struct formnode *); + void (*fieldterm)(struct formnode *); + +} FORM; + +typedef void (*Form_Hook)(FORM *); + + /*************************** + * miscellaneous #defines * + ***************************/ + +/* field justification */ +#define NO_JUSTIFICATION (0) +#define JUSTIFY_LEFT (1) +#define JUSTIFY_CENTER (2) +#define JUSTIFY_RIGHT (3) + +/* field options */ +#define O_VISIBLE (0x0001) +#define O_ACTIVE (0x0002) +#define O_PUBLIC (0x0004) +#define O_EDIT (0x0008) +#define O_WRAP (0x0010) +#define O_BLANK (0x0020) +#define O_AUTOSKIP (0x0040) +#define O_NULLOK (0x0080) +#define O_PASSOK (0x0100) +#define O_STATIC (0x0200) + +/* form options */ +#define O_NL_OVERLOAD (0x0001) +#define O_BS_OVERLOAD (0x0002) + +/* form driver commands */ +#define REQ_NEXT_PAGE (KEY_MAX + 1) /* move to next page */ +#define REQ_PREV_PAGE (KEY_MAX + 2) /* move to previous page */ +#define REQ_FIRST_PAGE (KEY_MAX + 3) /* move to first page */ +#define REQ_LAST_PAGE (KEY_MAX + 4) /* move to last page */ + +#define REQ_NEXT_FIELD (KEY_MAX + 5) /* move to next field */ +#define REQ_PREV_FIELD (KEY_MAX + 6) /* move to previous field */ +#define REQ_FIRST_FIELD (KEY_MAX + 7) /* move to first field */ +#define REQ_LAST_FIELD (KEY_MAX + 8) /* move to last field */ +#define REQ_SNEXT_FIELD (KEY_MAX + 9) /* move to sorted next field */ +#define REQ_SPREV_FIELD (KEY_MAX + 10) /* move to sorted prev field */ +#define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field */ +#define REQ_SLAST_FIELD (KEY_MAX + 12) /* move to sorted last field */ +#define REQ_LEFT_FIELD (KEY_MAX + 13) /* move to left to field */ +#define REQ_RIGHT_FIELD (KEY_MAX + 14) /* move to right to field */ +#define REQ_UP_FIELD (KEY_MAX + 15) /* move to up to field */ +#define REQ_DOWN_FIELD (KEY_MAX + 16) /* move to down to field */ + +#define REQ_NEXT_CHAR (KEY_MAX + 17) /* move to next char in field */ +#define REQ_PREV_CHAR (KEY_MAX + 18) /* move to prev char in field */ +#define REQ_NEXT_LINE (KEY_MAX + 19) /* move to next line in field */ +#define REQ_PREV_LINE (KEY_MAX + 20) /* move to prev line in field */ +#define REQ_NEXT_WORD (KEY_MAX + 21) /* move to next word in field */ +#define REQ_PREV_WORD (KEY_MAX + 22) /* move to prev word in field */ +#define REQ_BEG_FIELD (KEY_MAX + 23) /* move to first char in field */ +#define REQ_END_FIELD (KEY_MAX + 24) /* move after last char in fld */ +#define REQ_BEG_LINE (KEY_MAX + 25) /* move to beginning of line */ +#define REQ_END_LINE (KEY_MAX + 26) /* move after last char in line */ +#define REQ_LEFT_CHAR (KEY_MAX + 27) /* move left in field */ +#define REQ_RIGHT_CHAR (KEY_MAX + 28) /* move right in field */ +#define REQ_UP_CHAR (KEY_MAX + 29) /* move up in field */ +#define REQ_DOWN_CHAR (KEY_MAX + 30) /* move down in field */ + +#define REQ_NEW_LINE (KEY_MAX + 31) /* insert/overlay new line */ +#define REQ_INS_CHAR (KEY_MAX + 32) /* insert blank char at cursor */ +#define REQ_INS_LINE (KEY_MAX + 33) /* insert blank line at cursor */ +#define REQ_DEL_CHAR (KEY_MAX + 34) /* delete char at cursor */ +#define REQ_DEL_PREV (KEY_MAX + 35) /* delete char before cursor */ +#define REQ_DEL_LINE (KEY_MAX + 36) /* delete line at cursor */ +#define REQ_DEL_WORD (KEY_MAX + 37) /* delete line at cursor */ +#define REQ_CLR_EOL (KEY_MAX + 38) /* clear to end of line */ +#define REQ_CLR_EOF (KEY_MAX + 39) /* clear to end of field */ +#define REQ_CLR_FIELD (KEY_MAX + 40) /* clear entire field */ +#define REQ_OVL_MODE (KEY_MAX + 41) /* begin overlay mode */ +#define REQ_INS_MODE (KEY_MAX + 42) /* begin insert mode */ +#define REQ_SCR_FLINE (KEY_MAX + 43) /* scroll field forward a line */ +#define REQ_SCR_BLINE (KEY_MAX + 44) /* scroll field backward a line */ +#define REQ_SCR_FPAGE (KEY_MAX + 45) /* scroll field forward a page */ +#define REQ_SCR_BPAGE (KEY_MAX + 46) /* scroll field backward a page */ +#define REQ_SCR_FHPAGE (KEY_MAX + 47) /* scroll field forward half page */ +#define REQ_SCR_BHPAGE (KEY_MAX + 48) /* scroll field backward half page */ +#define REQ_SCR_FCHAR (KEY_MAX + 49) /* horizontal scroll char */ +#define REQ_SCR_BCHAR (KEY_MAX + 50) /* horizontal scroll char */ +#define REQ_SCR_HFLINE (KEY_MAX + 51) /* horizontal scroll line */ +#define REQ_SCR_HBLINE (KEY_MAX + 52) /* horizontal scroll line */ +#define REQ_SCR_HFHALF (KEY_MAX + 53) /* horizontal scroll half line */ +#define REQ_SCR_HBHALF (KEY_MAX + 54) /* horizontal scroll half line */ + +#define REQ_VALIDATION (KEY_MAX + 55) /* validate field */ +#define REQ_NEXT_CHOICE (KEY_MAX + 56) /* display next field choice */ +#define REQ_PREV_CHOICE (KEY_MAX + 57) /* display prev field choice */ + +#define MIN_FORM_COMMAND (KEY_MAX + 1) /* used by form_driver */ +#define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver */ + +#if defined(MAX_COMMAND) +# if (MAX_FORM_COMMAND > MAX_COMMAND) +# error Something is wrong -- MAX_FORM_COMMAND is greater than MAX_COMMAND +# elif (MAX_COMMAND != (KEY_MAX + 128)) +# error Something is wrong -- MAX_COMMAND is already inconsistently defined. +# endif +#else +# define MAX_COMMAND (KEY_MAX + 128) +#endif + + /************************* + * standard field types * + *************************/ +extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ALPHA; +extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ALNUM; +extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ENUM; +extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_INTEGER; +extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_NUMERIC; +extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_REGEXP; + + /************************************ + * built-in additional field types * + * They are not defined in SVr4 * + ************************************/ +extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_IPV4; /* Internet IP Version 4 address */ + + /*********************** + * Default objects * + ***********************/ +extern NCURSES_EXPORT_VAR(FORM *) _nc_Default_Form; +extern NCURSES_EXPORT_VAR(FIELD *) _nc_Default_Field; + + + /*********************** + * FIELDTYPE routines * + ***********************/ +extern NCURSES_EXPORT(FIELDTYPE *) new_fieldtype ( + bool (* const field_check)(FIELD *,const void *), + bool (* const char_check)(int,const void *)), + *link_fieldtype(FIELDTYPE *,FIELDTYPE *); + +extern NCURSES_EXPORT(int) free_fieldtype (FIELDTYPE *); +extern NCURSES_EXPORT(int) set_fieldtype_arg (FIELDTYPE *, + void * (* const make_arg)(va_list *), + void * (* const copy_arg)(const void *), + void (* const free_arg)(void *)); +extern NCURSES_EXPORT(int) set_fieldtype_choice (FIELDTYPE *, + bool (* const next_choice)(FIELD *,const void *), + bool (* const prev_choice)(FIELD *,const void *)); + + /******************* + * FIELD routines * + *******************/ +extern NCURSES_EXPORT(FIELD *) new_field (int,int,int,int,int,int); +extern NCURSES_EXPORT(FIELD *) dup_field (FIELD *,int,int); +extern NCURSES_EXPORT(FIELD *) link_field (FIELD *,int,int); + +extern NCURSES_EXPORT(int) free_field (FIELD *); +extern NCURSES_EXPORT(int) field_info (const FIELD *,int *,int *,int *,int *,int *,int *); +extern NCURSES_EXPORT(int) dynamic_field_info (const FIELD *,int *,int *,int *); +extern NCURSES_EXPORT(int) set_max_field ( FIELD *,int); +extern NCURSES_EXPORT(int) move_field (FIELD *,int,int); +extern NCURSES_EXPORT(int) set_field_type (FIELD *,FIELDTYPE *,...); +extern NCURSES_EXPORT(int) set_new_page (FIELD *,bool); +extern NCURSES_EXPORT(int) set_field_just (FIELD *,int); +extern NCURSES_EXPORT(int) field_just (const FIELD *); +extern NCURSES_EXPORT(int) set_field_fore (FIELD *,chtype); +extern NCURSES_EXPORT(int) set_field_back (FIELD *,chtype); +extern NCURSES_EXPORT(int) set_field_pad (FIELD *,int); +extern NCURSES_EXPORT(int) field_pad (const FIELD *); +extern NCURSES_EXPORT(int) set_field_buffer (FIELD *,int,const char *); +extern NCURSES_EXPORT(int) set_field_status (FIELD *,bool); +extern NCURSES_EXPORT(int) set_field_userptr (FIELD *, void *); +extern NCURSES_EXPORT(int) set_field_opts (FIELD *,Field_Options); +extern NCURSES_EXPORT(int) field_opts_on (FIELD *,Field_Options); +extern NCURSES_EXPORT(int) field_opts_off (FIELD *,Field_Options); + +extern NCURSES_EXPORT(chtype) field_fore (const FIELD *); +extern NCURSES_EXPORT(chtype) field_back (const FIELD *); + +extern NCURSES_EXPORT(bool) new_page (const FIELD *); +extern NCURSES_EXPORT(bool) field_status (const FIELD *); + +extern NCURSES_EXPORT(void *) field_arg (const FIELD *); + +extern NCURSES_EXPORT(void *) field_userptr (const FIELD *); + +extern NCURSES_EXPORT(FIELDTYPE *) field_type (const FIELD *); + +extern NCURSES_EXPORT(char *) field_buffer (const FIELD *,int); + +extern NCURSES_EXPORT(Field_Options) field_opts (const FIELD *); + + /****************** + * FORM routines * + ******************/ + +extern NCURSES_EXPORT(FORM *) new_form (FIELD **); + +extern NCURSES_EXPORT(FIELD **) form_fields (const FORM *); +extern NCURSES_EXPORT(FIELD *) current_field (const FORM *); + +extern NCURSES_EXPORT(WINDOW *) form_win (const FORM *); +extern NCURSES_EXPORT(WINDOW *) form_sub (const FORM *); + +extern NCURSES_EXPORT(Form_Hook) form_init (const FORM *); +extern NCURSES_EXPORT(Form_Hook) form_term (const FORM *); +extern NCURSES_EXPORT(Form_Hook) field_init (const FORM *); +extern NCURSES_EXPORT(Form_Hook) field_term (const FORM *); + +extern NCURSES_EXPORT(int) free_form (FORM *); +extern NCURSES_EXPORT(int) set_form_fields (FORM *,FIELD **); +extern NCURSES_EXPORT(int) field_count (const FORM *); +extern NCURSES_EXPORT(int) set_form_win (FORM *,WINDOW *); +extern NCURSES_EXPORT(int) set_form_sub (FORM *,WINDOW *); +extern NCURSES_EXPORT(int) set_current_field (FORM *,FIELD *); +extern NCURSES_EXPORT(int) field_index (const FIELD *); +extern NCURSES_EXPORT(int) set_form_page (FORM *,int); +extern NCURSES_EXPORT(int) form_page (const FORM *); +extern NCURSES_EXPORT(int) scale_form (const FORM *,int *,int *); +extern NCURSES_EXPORT(int) set_form_init (FORM *,Form_Hook); +extern NCURSES_EXPORT(int) set_form_term (FORM *,Form_Hook); +extern NCURSES_EXPORT(int) set_field_init (FORM *,Form_Hook); +extern NCURSES_EXPORT(int) set_field_term (FORM *,Form_Hook); +extern NCURSES_EXPORT(int) post_form (FORM *); +extern NCURSES_EXPORT(int) unpost_form (FORM *); +extern NCURSES_EXPORT(int) pos_form_cursor (FORM *); +extern NCURSES_EXPORT(int) form_driver (FORM *,int); +extern NCURSES_EXPORT(int) set_form_userptr (FORM *,void *); +extern NCURSES_EXPORT(int) set_form_opts (FORM *,Form_Options); +extern NCURSES_EXPORT(int) form_opts_on (FORM *,Form_Options); +extern NCURSES_EXPORT(int) form_opts_off (FORM *,Form_Options); +extern NCURSES_EXPORT(int) form_request_by_name (const char *); + +extern NCURSES_EXPORT(const char *) form_request_name (int); + +extern NCURSES_EXPORT(void *) form_userptr (const FORM *); + +extern NCURSES_EXPORT(Form_Options) form_opts (const FORM *); + +extern NCURSES_EXPORT(bool) data_ahead (const FORM *); +extern NCURSES_EXPORT(bool) data_behind (const FORM *); + +#ifdef __cplusplus + } +#endif + +#endif /* FORM_H */ diff --git a/src/include/fpmath.h b/src/include/fpmath.h new file mode 100644 index 0000000..f52a6bd --- /dev/null +++ b/src/include/fpmath.h @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2003 Mike Barcroft + * Copyright (c) 2002 David Schultz + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/include/fpmath.h,v 1.2 2004/01/18 08:05:21 das Exp $ + */ + +#include +#include "_fpmath.h" + +union IEEEf2bits { + float f; + struct { +#if _BYTE_ORDER == _LITTLE_ENDIAN + unsigned int man :23; + unsigned int exp :8; + unsigned int sign :1; +#else /* _BIG_ENDIAN */ + unsigned int sign :1; + unsigned int exp :8; + unsigned int man :23; +#endif + } bits; +}; + +#define DBL_MANH_SIZE 20 +#define DBL_MANL_SIZE 32 + +union IEEEd2bits { + double d; + struct { +#if _BYTE_ORDER == _LITTLE_ENDIAN + unsigned int manl :32; + unsigned int manh :20; + unsigned int exp :11; + unsigned int sign :1; +#else /* _BIG_ENDIAN */ + unsigned int sign :1; + unsigned int exp :11; + unsigned int manh :20; + unsigned int manl :32; +#endif + } bits; +}; diff --git a/src/include/fstab.h b/src/include/fstab.h new file mode 100644 index 0000000..22d807c --- /dev/null +++ b/src/include/fstab.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1980, 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. + * + * @(#)fstab.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/fstab.h,v 1.4 2003/04/07 12:54:59 mdodd Exp $ + */ + +#ifndef _FSTAB_H_ +#define _FSTAB_H_ + +/* + * File system table, see fstab(5). + * + * Used by dump, mount, umount, swapon, fsck, df, ... + * + * For ufs fs_spec field is the block special name. Programs that want to + * use the character special name must create that name by prepending a 'r' + * after the right most slash. Quota files are always named "quotas", so + * if type is "rq", then use concatenation of fs_file and "quotas" to locate + * quota file. + */ +#define _PATH_FSTAB "/etc/fstab" +#define FSTAB "/etc/fstab" /* deprecated */ + +#define FSTAB_RW "rw" /* read/write device */ +#define FSTAB_RQ "rq" /* read/write with quotas */ +#define FSTAB_RO "ro" /* read-only device */ +#define FSTAB_SW "sw" /* swap device */ +#define FSTAB_XX "xx" /* ignore totally */ + +struct fstab { + char *fs_spec; /* block special device name */ + char *fs_file; /* file system path prefix */ + char *fs_vfstype; /* File system type, ufs, nfs */ + char *fs_mntops; /* Mount options ala -o */ + char *fs_type; /* FSTAB_* from fs_mntops */ + int fs_freq; /* dump frequency, in days */ + int fs_passno; /* pass number on parallel fsck */ +}; + +#include + +__BEGIN_DECLS +struct fstab *getfsent(void); +struct fstab *getfsspec(const char *); +struct fstab *getfsfile(const char *); +int setfsent(void); +void endfsent(void); +void setfstab(const char *); +const char *getfstab(void); +__END_DECLS + +#endif /* !_FSTAB_H_ */ diff --git a/src/include/ftpio.h b/src/include/ftpio.h new file mode 100644 index 0000000..5799d6a --- /dev/null +++ b/src/include/ftpio.h @@ -0,0 +1,71 @@ +#ifndef _FTP_H_INCLUDE +#define _FTP_H_INCLUDE + +#include +#include +#include +#include + +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * Major Changelog: + * + * Jordan K. Hubbard + * 17 Jan 1996 + * + * Turned inside out. Now returns xfers as new file ids, not as a special + * `state' of FTP_t + * + * $FreeBSD: src/lib/libftpio/ftpio.h,v 1.17 2002/03/25 13:49:48 phk Exp $ + */ + +/* Internal housekeeping data structure for FTP sessions */ +typedef struct { + enum { init, isopen, quit } con_state; + int fd_ctrl; + int addrtype; + char *host; + char *file; + int error; + int is_binary; + int is_passive; + int is_verbose; +} *FTP_t; + +/* Structure we use to match FTP error codes with readable strings */ +struct ftperr { + const int num; + const char *string; +}; + +__BEGIN_DECLS +extern struct ftperr ftpErrList[]; +extern int const ftpErrListLength; + +/* Exported routines - deal only with FILE* type */ +extern FILE *ftpLogin(char *host, char *user, char *passwd, int port, int verbose, int *retcode); +extern int ftpChdir(FILE *fp, char *dir); +extern int ftpErrno(FILE *fp); +extern off_t ftpGetSize(FILE *fp, char *file); +extern FILE *ftpGet(FILE *fp, char *file, off_t *seekto); +extern FILE *ftpPut(FILE *fp, char *file); +extern int ftpAscii(FILE *fp); +extern int ftpBinary(FILE *fp); +extern int ftpPassive(FILE *fp, int status); +extern void ftpVerbose(FILE *fp, int status); +extern FILE *ftpGetURL(char *url, char *user, char *passwd, int *retcode); +extern FILE *ftpPutURL(char *url, char *user, char *passwd, int *retcode); +extern time_t ftpGetModtime(FILE *fp, char *s); +extern const char *ftpErrString(int error); +extern FILE *ftpLoginAf(char *host, int af, char *user, char *passwd, int port, int verbose, int *retcode); +extern FILE *ftpGetURLAf(char *url, int af, char *user, char *passwd, int *retcode); +extern FILE *ftpPutURLAf(char *url, int af, char *user, char *passwd, int *retcode); +__END_DECLS + +#endif /* _FTP_H_INCLUDE */ diff --git a/src/include/fts.h b/src/include/fts.h new file mode 100644 index 0000000..f44d4c1 --- /dev/null +++ b/src/include/fts.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 1989, 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. + * + * @(#)fts.h 8.3 (Berkeley) 8/14/94 + * $FreeBSD: src/include/fts.h,v 1.10 2004/05/12 21:38:39 peadar Exp $ + */ + +#ifndef _FTS_H_ +#define _FTS_H_ + +typedef struct { + struct _ftsent *fts_cur; /* current node */ + struct _ftsent *fts_child; /* linked list of children */ + struct _ftsent **fts_array; /* sort array */ + dev_t fts_dev; /* starting device # */ + char *fts_path; /* path for this descent */ + int fts_rfd; /* fd for root */ + int fts_pathlen; /* sizeof(path) */ + int fts_nitems; /* elements in the sort array */ + int (*fts_compar) /* compare function */ + (const struct _ftsent * const *, const struct _ftsent * const *); + +#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */ +#define FTS_LOGICAL 0x002 /* logical walk */ +#define FTS_NOCHDIR 0x004 /* don't change directories */ +#define FTS_NOSTAT 0x008 /* don't get stat info */ +#define FTS_PHYSICAL 0x010 /* physical walk */ +#define FTS_SEEDOT 0x020 /* return dot and dot-dot */ +#define FTS_XDEV 0x040 /* don't cross devices */ +#define FTS_WHITEOUT 0x080 /* return whiteout information */ +#define FTS_OPTIONMASK 0x0ff /* valid user option mask */ + +#define FTS_NAMEONLY 0x100 /* (private) child names only */ +#define FTS_STOP 0x200 /* (private) unrecoverable error */ + int fts_options; /* fts_open options, global flags */ + void *fts_clientptr; /* thunk for sort function */ +} FTS; + +typedef struct _ftsent { + struct _ftsent *fts_cycle; /* cycle node */ + struct _ftsent *fts_parent; /* parent directory */ + struct _ftsent *fts_link; /* next file in directory */ + long fts_number; /* local numeric value */ + void *fts_pointer; /* local address value */ + char *fts_accpath; /* access path */ + char *fts_path; /* root path */ + int fts_errno; /* errno for this node */ + int fts_symfd; /* fd for symlink */ + u_short fts_pathlen; /* strlen(fts_path) */ + u_short fts_namelen; /* strlen(fts_name) */ + + ino_t fts_ino; /* inode */ + dev_t fts_dev; /* device */ + nlink_t fts_nlink; /* link count */ + +#define FTS_ROOTPARENTLEVEL -1 +#define FTS_ROOTLEVEL 0 + short fts_level; /* depth (-1 to N) */ + +#define FTS_D 1 /* preorder directory */ +#define FTS_DC 2 /* directory that causes cycles */ +#define FTS_DEFAULT 3 /* none of the above */ +#define FTS_DNR 4 /* unreadable directory */ +#define FTS_DOT 5 /* dot or dot-dot */ +#define FTS_DP 6 /* postorder directory */ +#define FTS_ERR 7 /* error; errno is set */ +#define FTS_F 8 /* regular file */ +#define FTS_INIT 9 /* initialized only */ +#define FTS_NS 10 /* stat(2) failed */ +#define FTS_NSOK 11 /* no stat(2) requested */ +#define FTS_SL 12 /* symbolic link */ +#define FTS_SLNONE 13 /* symbolic link without target */ +#define FTS_W 14 /* whiteout object */ + u_short fts_info; /* user flags for FTSENT structure */ + +#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ +#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ +#define FTS_ISW 0x04 /* this is a whiteout object */ + u_short fts_flags; /* private flags for FTSENT structure */ + +#define FTS_AGAIN 1 /* read node again */ +#define FTS_FOLLOW 2 /* follow symbolic link */ +#define FTS_NOINSTR 3 /* no instructions */ +#define FTS_SKIP 4 /* discard node */ + u_short fts_instr; /* fts_set() instructions */ + + struct stat *fts_statp; /* stat(2) information */ + char *fts_name; /* file name */ + FTS *fts_fts; /* back pointer to main FTS */ +} FTSENT; + +#include + +__BEGIN_DECLS +FTSENT *fts_children(FTS *, int); +int fts_close(FTS *); +void *fts_get_clientptr(FTS *); +#define fts_get_clientptr(fts) ((fts)->fts_clientptr) +FTS *fts_get_stream(FTSENT *); +#define fts_get_stream(ftsent) ((ftsent)->fts_fts) +FTS *fts_open(char * const *, int, + int (*)(const FTSENT * const *, const FTSENT * const *)); +FTSENT *fts_read(FTS *); +int fts_set(FTS *, FTSENT *, int); +void fts_set_clientptr(FTS *, void *); +__END_DECLS + +#endif /* !_FTS_H_ */ diff --git a/src/include/g2c.h b/src/include/g2c.h new file mode 100644 index 0000000..71e021d --- /dev/null +++ b/src/include/g2c.h @@ -0,0 +1,236 @@ +/* g2c.h -- g77 version of f2c (Standard Fortran to C header file) */ + +/* This file is generated by the g77 libg2c configuration process from a + file named g2c.hin. This process sets up the appropriate types, + defines the appropriate macros, and so on. The resulting g2c.h file + is used to build g77's copy of libf2c, named libg2c, and also can + be used when compiling C code produced by f2c to link the resulting + object file(s) with those produced by the same version of g77 that + produced this file, allowing inter-operability of f2c-compiled and + g77-compiled code. */ + +/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." + + - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ + +#ifndef F2C_INCLUDE +#define F2C_INCLUDE + +/* F2C_INTEGER will normally be `int' but would be `long' on 16-bit systems */ +/* we assume short, float are OK */ +typedef int /* long int */ integer; +typedef unsigned long int /* long */ uinteger; +typedef char *address; +typedef short int shortint; +typedef float real; +typedef double doublereal; +typedef struct { real r, i; } complex; +typedef struct { doublereal r, i; } doublecomplex; +typedef int /* long int */ logical; +typedef short int shortlogical; +typedef char logical1; +typedef char integer1; +typedef long long int /* long long */ longint; /* system-dependent */ +typedef unsigned long long int /* long long */ ulongint; /* system-dependent */ +#define qbit_clear(a,b) ((a) & ~((ulongint)1 << (b))) +#define qbit_set(a,b) ((a) | ((ulongint)1 << (b))) + +#define TRUE_ (1) +#define FALSE_ (0) + +/* Extern is for use with -E */ +#ifndef Extern +#define Extern extern +#endif + +/* I/O stuff */ + +#ifdef f2c_i2 +#error "f2c_i2 will not work with g77!!!!" +/* for -i2 */ +typedef short flag; +typedef short ftnlen; +typedef short ftnint; +#else +typedef int /* long int */ flag; +typedef int /* long int */ ftnlen; +typedef int /* long int */ ftnint; +#endif + +/*external read, write*/ +typedef struct +{ flag cierr; + ftnint ciunit; + flag ciend; + char *cifmt; + ftnint cirec; +} cilist; + +/*internal read, write*/ +typedef struct +{ flag icierr; + char *iciunit; + flag iciend; + char *icifmt; + ftnint icirlen; + ftnint icirnum; +} icilist; + +/*open*/ +typedef struct +{ flag oerr; + ftnint ounit; + char *ofnm; + ftnlen ofnmlen; + char *osta; + char *oacc; + char *ofm; + ftnint orl; + char *oblnk; +} olist; + +/*close*/ +typedef struct +{ flag cerr; + ftnint cunit; + char *csta; +} cllist; + +/*rewind, backspace, endfile*/ +typedef struct +{ flag aerr; + ftnint aunit; +} alist; + +/* inquire */ +typedef struct +{ flag inerr; + ftnint inunit; + char *infile; + ftnlen infilen; + ftnint *inex; /*parameters in standard's order*/ + ftnint *inopen; + ftnint *innum; + ftnint *innamed; + char *inname; + ftnlen innamlen; + char *inacc; + ftnlen inacclen; + char *inseq; + ftnlen inseqlen; + char *indir; + ftnlen indirlen; + char *infmt; + ftnlen infmtlen; + char *inform; + ftnint informlen; + char *inunf; + ftnlen inunflen; + ftnint *inrecl; + ftnint *innrec; + char *inblank; + ftnlen inblanklen; +} inlist; + +#define VOID void + +union Multitype { /* for multiple entry points */ + integer1 g; + shortint h; + integer i; + /* longint j; */ + real r; + doublereal d; + complex c; + doublecomplex z; + }; + +typedef union Multitype Multitype; + +/*typedef long int Long;*/ /* No longer used; formerly in Namelist */ + +struct Vardesc { /* for Namelist */ + char *name; + char *addr; + ftnlen *dims; + int type; + }; +typedef struct Vardesc Vardesc; + +struct Namelist { + char *name; + Vardesc **vars; + int nvars; + }; +typedef struct Namelist Namelist; + +#define abs(x) ((x) >= 0 ? (x) : -(x)) +#define dabs(x) (doublereal)abs(x) +#define min(a,b) ((a) <= (b) ? (a) : (b)) +#define max(a,b) ((a) >= (b) ? (a) : (b)) +#define dmin(a,b) (doublereal)min(a,b) +#define dmax(a,b) (doublereal)max(a,b) +#define bit_test(a,b) ((a) >> (b) & 1) +#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) +#define bit_set(a,b) ((a) | ((uinteger)1 << (b))) + +/* procedure parameter types for -A and -C++ */ + +#define F2C_proc_par_types 1 +#ifdef __cplusplus +typedef int /* Unknown procedure type */ (*U_fp)(...); +typedef shortint (*J_fp)(...); +typedef integer (*I_fp)(...); +typedef real (*R_fp)(...); +typedef doublereal (*D_fp)(...), (*E_fp)(...); +typedef /* Complex */ VOID (*C_fp)(...); +typedef /* Double Complex */ VOID (*Z_fp)(...); +typedef logical (*L_fp)(...); +typedef shortlogical (*K_fp)(...); +typedef /* Character */ VOID (*H_fp)(...); +typedef /* Subroutine */ int (*S_fp)(...); +#else +typedef int /* Unknown procedure type */ (*U_fp)(); +typedef shortint (*J_fp)(); +typedef integer (*I_fp)(); +typedef real (*R_fp)(); +typedef doublereal (*D_fp)(), (*E_fp)(); +typedef /* Complex */ VOID (*C_fp)(); +typedef /* Double Complex */ VOID (*Z_fp)(); +typedef logical (*L_fp)(); +typedef shortlogical (*K_fp)(); +typedef /* Character */ VOID (*H_fp)(); +typedef /* Subroutine */ int (*S_fp)(); +#endif +/* E_fp is for real functions when -R is not specified */ +typedef VOID C_f; /* complex function */ +typedef VOID H_f; /* character function */ +typedef VOID Z_f; /* double complex function */ +typedef doublereal E_f; /* real function with -R not specified */ + +/* undef any lower-case symbols that your C compiler predefines, e.g.: */ + +#ifndef Skip_f2c_Undefs +/* (No such symbols should be defined in a strict ANSI C compiler. + We can avoid trouble with f2c-translated code by using + gcc -ansi [-traditional].) */ +#undef cray +#undef gcos +#undef mc68010 +#undef mc68020 +#undef mips +#undef pdp11 +#undef sgi +#undef sparc +#undef sun +#undef sun2 +#undef sun3 +#undef sun4 +#undef u370 +#undef u3b +#undef u3b2 +#undef u3b5 +#undef unix +#undef vax +#endif +#endif diff --git a/src/include/getopt.h b/src/include/getopt.h new file mode 100644 index 0000000..ddacd89 --- /dev/null +++ b/src/include/getopt.h @@ -0,0 +1,85 @@ +/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ +/* $FreeBSD: src/include/getopt.h,v 1.6 2004/02/24 08:09:20 ache Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +#include + +/* + * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension. + * getopt() is declared here too for GNU programs. + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +__BEGIN_DECLS +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +int getopt_long_only(int, char * const *, const char *, + const struct option *, int *); +#ifndef _GETOPT_DECLARED +#define _GETOPT_DECLARED +int getopt(int, char * const [], const char *); + +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt; +#endif +#ifndef _OPTRESET_DECLARED +#define _OPTRESET_DECLARED +extern int optreset; /* getopt(3) external variable */ +#endif +__END_DECLS + +#endif /* !_GETOPT_H_ */ diff --git a/src/include/glob.h b/src/include/glob.h new file mode 100644 index 0000000..8a8d2aa --- /dev/null +++ b/src/include/glob.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * 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. + * + * @(#)glob.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/glob.h,v 1.7 2002/07/17 04:58:09 mikeh Exp $ + */ + +#ifndef _GLOB_H_ +#define _GLOB_H_ + +#include + +struct stat; +typedef struct { + int gl_pathc; /* Count of total paths so far. */ + int gl_matchc; /* Count of paths matching pattern. */ + int gl_offs; /* Reserved at beginning of gl_pathv. */ + int gl_flags; /* Copy of flags parameter to glob. */ + char **gl_pathv; /* List of paths matching pattern. */ + /* Copy of errfunc parameter to glob. */ + int (*gl_errfunc)(const char *, int); + + /* + * Alternate filesystem access methods for glob; replacement + * versions of closedir(3), readdir(3), opendir(3), stat(2) + * and lstat(2). + */ + void (*gl_closedir)(void *); + struct dirent *(*gl_readdir)(void *); + void *(*gl_opendir)(const char *); + int (*gl_lstat)(const char *, struct stat *); + int (*gl_stat)(const char *, struct stat *); +} glob_t; + +#if __POSIX_VISIBLE >= 199209 +/* Believed to have been introduced in 1003.2-1992 */ +#define GLOB_APPEND 0x0001 /* Append to output from previous call. */ +#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ +#define GLOB_ERR 0x0004 /* Return on error. */ +#define GLOB_MARK 0x0008 /* Append / to matching directories. */ +#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ +#define GLOB_NOSORT 0x0020 /* Don't sort. */ +#define GLOB_NOESCAPE 0x2000 /* Disable backslash escaping. */ + +/* Error values returned by glob(3) */ +#define GLOB_NOSPACE (-1) /* Malloc call failed. */ +#define GLOB_ABORTED (-2) /* Unignored error. */ +#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK was not set. */ +#define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */ +#endif /* __POSIX_VISIBLE >= 199209 */ + +#if __BSD_VISIBLE +#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ +#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ +#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ +#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ +#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ +#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ +#define GLOB_LIMIT 0x1000 /* limit number of returned paths */ + +/* source compatibility, these are the old names */ +#define GLOB_MAXPATH GLOB_LIMIT +#define GLOB_ABEND GLOB_ABORTED +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +int glob(const char *, int, int (*)(const char *, int), glob_t *); +void globfree(glob_t *); +__END_DECLS + +#endif /* !_GLOB_H_ */ diff --git a/src/include/gnuregex.h b/src/include/gnuregex.h new file mode 100644 index 0000000..6767df4 --- /dev/null +++ b/src/include/gnuregex.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2004 David E. O'Brien + * Copyright (c) 2004 Andrey A. Chernov + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/gnu/lib/libregex/gnuregex.h,v 1.3 2004/02/25 10:56:54 ache Exp $ + */ + +#ifdef __GNUC__ +#warning "Use -I/usr/include/gnu and instead of " +#endif +#include diff --git a/src/include/grp.h b/src/include/grp.h new file mode 100644 index 0000000..55a57a7 --- /dev/null +++ b/src/include/grp.h @@ -0,0 +1,91 @@ +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)grp.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/include/grp.h,v 1.18 2003/04/17 14:15:25 nectar Exp $ + */ + +#ifndef _GRP_H_ +#define _GRP_H_ + +#include +#include + +#define _PATH_GROUP "/etc/group" + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +struct group { + char *gr_name; /* group name */ + char *gr_passwd; /* group password */ + gid_t gr_gid; /* group id */ + char **gr_mem; /* group members */ +}; + +__BEGIN_DECLS +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +void endgrent(void); +struct group *getgrent(void); +#endif +struct group *getgrgid(gid_t); +struct group *getgrnam(const char *); +#if __BSD_VISIBLE +const char *group_from_gid(gid_t, int); +#endif +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +/* XXX IEEE Std 1003.1, 2003 specifies `void setgrent(void)' */ +int setgrent(void); +int getgrgid_r(gid_t, struct group *, char *, size_t, + struct group **); +int getgrnam_r(const char *, struct group *, char *, size_t, + struct group **); +#endif +#if __BSD_VISIBLE +int getgrent_r(struct group *, char *, size_t, struct group **); +int setgroupent(int); +#endif +__END_DECLS + +#endif /* !_GRP_H_ */ diff --git a/src/include/gssapi.h b/src/include/gssapi.h new file mode 100644 index 0000000..4935651 --- /dev/null +++ b/src/include/gssapi.h @@ -0,0 +1,788 @@ +/* + * Copyright (c) 1997 - 2003 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $Id$ */ + +#ifndef GSSAPI_H_ +#define GSSAPI_H_ + +/* + * First, include stddef.h to get size_t defined. + */ +#include + +#include + +/* + * Now define the three implementation-dependent types. + */ + +typedef u_int32_t OM_uint32; + +typedef u_int32_t gss_uint32; + +/* + * This is to avoid having to include + */ + +struct krb5_auth_context_data; + +struct Principal; + +/* typedef void *gss_name_t; */ + +typedef struct Principal *gss_name_t; + +typedef struct gss_ctx_id_t_desc_struct { + struct krb5_auth_context_data *auth_context; + gss_name_t source, target; + OM_uint32 flags; + enum { LOCAL = 1, OPEN = 2, + COMPAT_OLD_DES3 = 4, COMPAT_OLD_DES3_SELECTED = 8 } more_flags; + struct krb5_ticket *ticket; + time_t lifetime; +} gss_ctx_id_t_desc; + +typedef gss_ctx_id_t_desc *gss_ctx_id_t; + +typedef struct gss_OID_desc_struct { + OM_uint32 length; + void *elements; +} gss_OID_desc, *gss_OID; + +typedef struct gss_OID_set_desc_struct { + size_t count; + gss_OID elements; +} gss_OID_set_desc, *gss_OID_set; + +struct krb5_keytab_data; + +struct krb5_ccache_data; + +typedef int gss_cred_usage_t; + +typedef struct gss_cred_id_t_desc_struct { + gss_name_t principal; + struct krb5_keytab_data *keytab; + OM_uint32 lifetime; + gss_cred_usage_t usage; + gss_OID_set mechanisms; + struct krb5_ccache_data *ccache; +} gss_cred_id_t_desc; + +typedef gss_cred_id_t_desc *gss_cred_id_t; + +typedef struct gss_buffer_desc_struct { + size_t length; + void *value; +} gss_buffer_desc, *gss_buffer_t; + +typedef struct gss_channel_bindings_struct { + OM_uint32 initiator_addrtype; + gss_buffer_desc initiator_address; + OM_uint32 acceptor_addrtype; + gss_buffer_desc acceptor_address; + gss_buffer_desc application_data; +} *gss_channel_bindings_t; + +/* + * For now, define a QOP-type as an OM_uint32 + */ +typedef OM_uint32 gss_qop_t; + +/* + * Flag bits for context-level services. + */ +#define GSS_C_DELEG_FLAG 1 +#define GSS_C_MUTUAL_FLAG 2 +#define GSS_C_REPLAY_FLAG 4 +#define GSS_C_SEQUENCE_FLAG 8 +#define GSS_C_CONF_FLAG 16 +#define GSS_C_INTEG_FLAG 32 +#define GSS_C_ANON_FLAG 64 +#define GSS_C_PROT_READY_FLAG 128 +#define GSS_C_TRANS_FLAG 256 + +/* + * Credential usage options + */ +#define GSS_C_BOTH 0 +#define GSS_C_INITIATE 1 +#define GSS_C_ACCEPT 2 + +/* + * Status code types for gss_display_status + */ +#define GSS_C_GSS_CODE 1 +#define GSS_C_MECH_CODE 2 + +/* + * The constant definitions for channel-bindings address families + */ +#define GSS_C_AF_UNSPEC 0 +#define GSS_C_AF_LOCAL 1 +#define GSS_C_AF_INET 2 +#define GSS_C_AF_IMPLINK 3 +#define GSS_C_AF_PUP 4 +#define GSS_C_AF_CHAOS 5 +#define GSS_C_AF_NS 6 +#define GSS_C_AF_NBS 7 +#define GSS_C_AF_ECMA 8 +#define GSS_C_AF_DATAKIT 9 +#define GSS_C_AF_CCITT 10 +#define GSS_C_AF_SNA 11 +#define GSS_C_AF_DECnet 12 +#define GSS_C_AF_DLI 13 +#define GSS_C_AF_LAT 14 +#define GSS_C_AF_HYLINK 15 +#define GSS_C_AF_APPLETALK 16 +#define GSS_C_AF_BSC 17 +#define GSS_C_AF_DSS 18 +#define GSS_C_AF_OSI 19 +#define GSS_C_AF_X25 21 +#define GSS_C_AF_INET6 24 + +#define GSS_C_AF_NULLADDR 255 + +/* + * Various Null values + */ +#define GSS_C_NO_NAME ((gss_name_t) 0) +#define GSS_C_NO_BUFFER ((gss_buffer_t) 0) +#define GSS_C_NO_OID ((gss_OID) 0) +#define GSS_C_NO_OID_SET ((gss_OID_set) 0) +#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0) +#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0) +#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0) +#define GSS_C_EMPTY_BUFFER {0, NULL} + +/* + * Some alternate names for a couple of the above + * values. These are defined for V1 compatibility. + */ +#define GSS_C_NULL_OID GSS_C_NO_OID +#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET + +/* + * Define the default Quality of Protection for per-message + * services. Note that an implementation that offers multiple + * levels of QOP may define GSS_C_QOP_DEFAULT to be either zero + * (as done here) to mean "default protection", or to a specific + * explicit QOP value. However, a value of 0 should always be + * interpreted by a GSSAPI implementation as a request for the + * default protection level. + */ +#define GSS_C_QOP_DEFAULT 0 + +#define GSS_KRB5_CONF_C_QOP_DES 0x0100 +#define GSS_KRB5_CONF_C_QOP_DES3_KD 0x0200 + +/* + * Expiration time of 2^32-1 seconds means infinite lifetime for a + * credential or security context + */ +#define GSS_C_INDEFINITE 0xfffffffful + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x01"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant + * GSS_C_NT_USER_NAME should be initialized to point + * to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_USER_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x02"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}. + * The constant GSS_C_NT_MACHINE_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_MACHINE_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x03"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) string_uid_name(3)}. + * The constant GSS_C_NT_STRING_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_STRING_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x02"}, + * corresponding to an object-identifier value of + * {iso(1) org(3) dod(6) internet(1) security(5) + * nametypes(6) gss-host-based-services(2)). The constant + * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point + * to that gss_OID_desc. This is a deprecated OID value, and + * implementations wishing to support hostbased-service names + * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID, + * defined below, to identify such names; + * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym + * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input + * parameter, but should not be emitted by GSS-API + * implementations + */ +extern gss_OID GSS_C_NT_HOSTBASED_SERVICE_X; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x04"}, corresponding to an + * object-identifier value of {iso(1) member-body(2) + * Unites States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The constant + * GSS_C_NT_HOSTBASED_SERVICE should be initialized + * to point to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_HOSTBASED_SERVICE; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\01\x05\x06\x03"}, + * corresponding to an object identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 3(gss-anonymous-name)}. The constant + * and GSS_C_NT_ANONYMOUS should be initialized to point + * to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_ANONYMOUS; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x04"}, + * corresponding to an object-identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 4(gss-api-exported-name)}. The constant + * GSS_C_NT_EXPORT_NAME should be initialized to point + * to that gss_OID_desc. + */ +extern gss_OID GSS_C_NT_EXPORT_NAME; + +/* + * This if for kerberos5 names. + */ + +extern gss_OID GSS_KRB5_NT_PRINCIPAL_NAME; +extern gss_OID GSS_KRB5_NT_USER_NAME; +extern gss_OID GSS_KRB5_NT_MACHINE_UID_NAME; +extern gss_OID GSS_KRB5_NT_STRING_UID_NAME; + +extern gss_OID GSS_KRB5_MECHANISM; + +/* for compatibility with MIT api */ + +#define gss_mech_krb5 GSS_KRB5_MECHANISM + +/* Major status codes */ + +#define GSS_S_COMPLETE 0 + +/* + * Some "helper" definitions to make the status code macros obvious. + */ +#define GSS_C_CALLING_ERROR_OFFSET 24 +#define GSS_C_ROUTINE_ERROR_OFFSET 16 +#define GSS_C_SUPPLEMENTARY_OFFSET 0 +#define GSS_C_CALLING_ERROR_MASK 0377ul +#define GSS_C_ROUTINE_ERROR_MASK 0377ul +#define GSS_C_SUPPLEMENTARY_MASK 0177777ul + +/* + * The macros that test status codes for error conditions. + * Note that the GSS_ERROR() macro has changed slightly from + * the V1 GSSAPI so that it now evaluates its argument + * only once. + */ +#define GSS_CALLING_ERROR(x) \ + (x & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET)) +#define GSS_ROUTINE_ERROR(x) \ + (x & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)) +#define GSS_SUPPLEMENTARY_INFO(x) \ + (x & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET)) +#define GSS_ERROR(x) \ + (x & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \ + (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))) + +/* + * Now the actual status code definitions + */ + +/* + * Calling errors: + */ +#define GSS_S_CALL_INACCESSIBLE_READ \ + (1ul << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_INACCESSIBLE_WRITE \ + (2ul << GSS_C_CALLING_ERROR_OFFSET) +#define GSS_S_CALL_BAD_STRUCTURE \ + (3ul << GSS_C_CALLING_ERROR_OFFSET) + +/* + * Routine errors: + */ +#define GSS_S_BAD_MECH (1ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAME (2ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_NAMETYPE (3ul << GSS_C_ROUTINE_ERROR_OFFSET) + +#define GSS_S_BAD_BINDINGS (4ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_STATUS (5ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_SIG (6ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_MIC GSS_S_BAD_SIG +#define GSS_S_NO_CRED (7ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NO_CONTEXT (8ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_TOKEN (9ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DEFECTIVE_CREDENTIAL (10ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CREDENTIALS_EXPIRED (11ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_CONTEXT_EXPIRED (12ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_FAILURE (13ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_BAD_QOP (14ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAUTHORIZED (15ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_UNAVAILABLE (16ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_DUPLICATE_ELEMENT (17ul << GSS_C_ROUTINE_ERROR_OFFSET) +#define GSS_S_NAME_NOT_MN (18ul << GSS_C_ROUTINE_ERROR_OFFSET) + +/* + * Supplementary info bits: + */ +#define GSS_S_CONTINUE_NEEDED (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 0)) +#define GSS_S_DUPLICATE_TOKEN (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 1)) +#define GSS_S_OLD_TOKEN (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 2)) +#define GSS_S_UNSEQ_TOKEN (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 3)) +#define GSS_S_GAP_TOKEN (1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 4)) + +/* + * From RFC1964: + * + * 4.1.1. Non-Kerberos-specific codes + */ + +#define GSS_KRB5_S_G_BAD_SERVICE_NAME 1 + /* "No @ in SERVICE-NAME name string" */ +#define GSS_KRB5_S_G_BAD_STRING_UID 2 + /* "STRING-UID-NAME contains nondigits" */ +#define GSS_KRB5_S_G_NOUSER 3 + /* "UID does not resolve to username" */ +#define GSS_KRB5_S_G_VALIDATE_FAILED 4 + /* "Validation error" */ +#define GSS_KRB5_S_G_BUFFER_ALLOC 5 + /* "Couldn't allocate gss_buffer_t data" */ +#define GSS_KRB5_S_G_BAD_MSG_CTX 6 + /* "Message context invalid" */ +#define GSS_KRB5_S_G_WRONG_SIZE 7 + /* "Buffer is the wrong size" */ +#define GSS_KRB5_S_G_BAD_USAGE 8 + /* "Credential usage type is unknown" */ +#define GSS_KRB5_S_G_UNKNOWN_QOP 9 + /* "Unknown quality of protection specified" */ + + /* + * 4.1.2. Kerberos-specific-codes + */ + +#define GSS_KRB5_S_KG_CCACHE_NOMATCH 10 + /* "Principal in credential cache does not match desired name" */ +#define GSS_KRB5_S_KG_KEYTAB_NOMATCH 11 + /* "No principal in keytab matches desired name" */ +#define GSS_KRB5_S_KG_TGT_MISSING 12 + /* "Credential cache has no TGT" */ +#define GSS_KRB5_S_KG_NO_SUBKEY 13 + /* "Authenticator has no subkey" */ +#define GSS_KRB5_S_KG_CONTEXT_ESTABLISHED 14 + /* "Context is already fully established" */ +#define GSS_KRB5_S_KG_BAD_SIGN_TYPE 15 + /* "Unknown signature type in token" */ +#define GSS_KRB5_S_KG_BAD_LENGTH 16 + /* "Invalid field length in token" */ +#define GSS_KRB5_S_KG_CTX_INCOMPLETE 17 + /* "Attempt to use incomplete security context" */ + +/* + * Finally, function prototypes for the GSS-API routines. + */ + +OM_uint32 gss_acquire_cred + (OM_uint32 * /*minor_status*/, + const gss_name_t /*desired_name*/, + OM_uint32 /*time_req*/, + const gss_OID_set /*desired_mechs*/, + gss_cred_usage_t /*cred_usage*/, + gss_cred_id_t * /*output_cred_handle*/, + gss_OID_set * /*actual_mechs*/, + OM_uint32 * /*time_rec*/ + ); + +OM_uint32 gss_release_cred + (OM_uint32 * /*minor_status*/, + gss_cred_id_t * /*cred_handle*/ + ); + +OM_uint32 gss_init_sec_context + (OM_uint32 * /*minor_status*/, + const gss_cred_id_t /*initiator_cred_handle*/, + gss_ctx_id_t * /*context_handle*/, + const gss_name_t /*target_name*/, + const gss_OID /*mech_type*/, + OM_uint32 /*req_flags*/, + OM_uint32 /*time_req*/, + const gss_channel_bindings_t /*input_chan_bindings*/, + const gss_buffer_t /*input_token*/, + gss_OID * /*actual_mech_type*/, + gss_buffer_t /*output_token*/, + OM_uint32 * /*ret_flags*/, + OM_uint32 * /*time_rec*/ + ); + +OM_uint32 gss_accept_sec_context + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t * /*context_handle*/, + const gss_cred_id_t /*acceptor_cred_handle*/, + const gss_buffer_t /*input_token_buffer*/, + const gss_channel_bindings_t /*input_chan_bindings*/, + gss_name_t * /*src_name*/, + gss_OID * /*mech_type*/, + gss_buffer_t /*output_token*/, + OM_uint32 * /*ret_flags*/, + OM_uint32 * /*time_rec*/, + gss_cred_id_t * /*delegated_cred_handle*/ + ); + +OM_uint32 gss_process_context_token + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + const gss_buffer_t /*token_buffer*/ + ); + +OM_uint32 gss_delete_sec_context + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t * /*context_handle*/, + gss_buffer_t /*output_token*/ + ); + +OM_uint32 gss_context_time + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + OM_uint32 * /*time_rec*/ + ); + +OM_uint32 gss_get_mic + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + gss_qop_t /*qop_req*/, + const gss_buffer_t /*message_buffer*/, + gss_buffer_t /*message_token*/ + ); + +OM_uint32 gss_verify_mic + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + const gss_buffer_t /*message_buffer*/, + const gss_buffer_t /*token_buffer*/, + gss_qop_t * /*qop_state*/ + ); + +OM_uint32 gss_wrap + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + int /*conf_req_flag*/, + gss_qop_t /*qop_req*/, + const gss_buffer_t /*input_message_buffer*/, + int * /*conf_state*/, + gss_buffer_t /*output_message_buffer*/ + ); + +OM_uint32 gss_unwrap + (OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + const gss_buffer_t /*input_message_buffer*/, + gss_buffer_t /*output_message_buffer*/, + int * /*conf_state*/, + gss_qop_t * /*qop_state*/ + ); + +OM_uint32 gss_display_status + (OM_uint32 * /*minor_status*/, + OM_uint32 /*status_value*/, + int /*status_type*/, + const gss_OID /*mech_type*/, + OM_uint32 * /*message_context*/, + gss_buffer_t /*status_string*/ + ); + +OM_uint32 gss_indicate_mechs + (OM_uint32 * /*minor_status*/, + gss_OID_set * /*mech_set*/ + ); + +OM_uint32 gss_compare_name + (OM_uint32 * /*minor_status*/, + const gss_name_t /*name1*/, + const gss_name_t /*name2*/, + int * /*name_equal*/ + ); + +OM_uint32 gss_display_name + (OM_uint32 * /*minor_status*/, + const gss_name_t /*input_name*/, + gss_buffer_t /*output_name_buffer*/, + gss_OID * /*output_name_type*/ + ); + +OM_uint32 gss_import_name + (OM_uint32 * /*minor_status*/, + const gss_buffer_t /*input_name_buffer*/, + const gss_OID /*input_name_type*/, + gss_name_t * /*output_name*/ + ); + +OM_uint32 gss_export_name + (OM_uint32 * /*minor_status*/, + const gss_name_t /*input_name*/, + gss_buffer_t /*exported_name*/ + ); + +OM_uint32 gss_release_name + (OM_uint32 * /*minor_status*/, + gss_name_t * /*input_name*/ + ); + +OM_uint32 gss_release_buffer + (OM_uint32 * /*minor_status*/, + gss_buffer_t /*buffer*/ + ); + +OM_uint32 gss_release_oid_set + (OM_uint32 * /*minor_status*/, + gss_OID_set * /*set*/ + ); + +OM_uint32 gss_inquire_cred + (OM_uint32 * /*minor_status*/, + const gss_cred_id_t /*cred_handle*/, + gss_name_t * /*name*/, + OM_uint32 * /*lifetime*/, + gss_cred_usage_t * /*cred_usage*/, + gss_OID_set * /*mechanisms*/ + ); + +OM_uint32 gss_inquire_context ( + OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + gss_name_t * /*src_name*/, + gss_name_t * /*targ_name*/, + OM_uint32 * /*lifetime_rec*/, + gss_OID * /*mech_type*/, + OM_uint32 * /*ctx_flags*/, + int * /*locally_initiated*/, + int * /*open_context*/ + ); + +OM_uint32 gss_wrap_size_limit ( + OM_uint32 * /*minor_status*/, + const gss_ctx_id_t /*context_handle*/, + int /*conf_req_flag*/, + gss_qop_t /*qop_req*/, + OM_uint32 /*req_output_size*/, + OM_uint32 * /*max_input_size*/ + ); + +OM_uint32 gss_add_cred ( + OM_uint32 * /*minor_status*/, + const gss_cred_id_t /*input_cred_handle*/, + const gss_name_t /*desired_name*/, + const gss_OID /*desired_mech*/, + gss_cred_usage_t /*cred_usage*/, + OM_uint32 /*initiator_time_req*/, + OM_uint32 /*acceptor_time_req*/, + gss_cred_id_t * /*output_cred_handle*/, + gss_OID_set * /*actual_mechs*/, + OM_uint32 * /*initiator_time_rec*/, + OM_uint32 * /*acceptor_time_rec*/ + ); + +OM_uint32 gss_inquire_cred_by_mech ( + OM_uint32 * /*minor_status*/, + const gss_cred_id_t /*cred_handle*/, + const gss_OID /*mech_type*/, + gss_name_t * /*name*/, + OM_uint32 * /*initiator_lifetime*/, + OM_uint32 * /*acceptor_lifetime*/, + gss_cred_usage_t * /*cred_usage*/ + ); + +OM_uint32 gss_export_sec_context ( + OM_uint32 * /*minor_status*/, + gss_ctx_id_t * /*context_handle*/, + gss_buffer_t /*interprocess_token*/ + ); + +OM_uint32 gss_import_sec_context ( + OM_uint32 * /*minor_status*/, + const gss_buffer_t /*interprocess_token*/, + gss_ctx_id_t * /*context_handle*/ + ); + +OM_uint32 gss_create_empty_oid_set ( + OM_uint32 * /*minor_status*/, + gss_OID_set * /*oid_set*/ + ); + +OM_uint32 gss_add_oid_set_member ( + OM_uint32 * /*minor_status*/, + const gss_OID /*member_oid*/, + gss_OID_set * /*oid_set*/ + ); + +OM_uint32 gss_test_oid_set_member ( + OM_uint32 * /*minor_status*/, + const gss_OID /*member*/, + const gss_OID_set /*set*/, + int * /*present*/ + ); + +OM_uint32 gss_inquire_names_for_mech ( + OM_uint32 * /*minor_status*/, + const gss_OID /*mechanism*/, + gss_OID_set * /*name_types*/ + ); + +OM_uint32 gss_inquire_mechs_for_name ( + OM_uint32 * /*minor_status*/, + const gss_name_t /*input_name*/, + gss_OID_set * /*mech_types*/ + ); + +OM_uint32 gss_canonicalize_name ( + OM_uint32 * /*minor_status*/, + const gss_name_t /*input_name*/, + const gss_OID /*mech_type*/, + gss_name_t * /*output_name*/ + ); + +OM_uint32 gss_duplicate_name ( + OM_uint32 * /*minor_status*/, + const gss_name_t /*src_name*/, + gss_name_t * /*dest_name*/ + ); + +/* + * The following routines are obsolete variants of gss_get_mic, + * gss_verify_mic, gss_wrap and gss_unwrap. They should be + * provided by GSSAPI V2 implementations for backwards + * compatibility with V1 applications. Distinct entrypoints + * (as opposed to #defines) should be provided, both to allow + * GSSAPI V1 applications to link against GSSAPI V2 implementations, + * and to retain the slight parameter type differences between the + * obsolete versions of these routines and their current forms. + */ + +OM_uint32 gss_sign + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + int /*qop_req*/, + gss_buffer_t /*message_buffer*/, + gss_buffer_t /*message_token*/ + ); + +OM_uint32 gss_verify + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + gss_buffer_t /*message_buffer*/, + gss_buffer_t /*token_buffer*/, + int * /*qop_state*/ + ); + +OM_uint32 gss_seal + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + int /*conf_req_flag*/, + int /*qop_req*/, + gss_buffer_t /*input_message_buffer*/, + int * /*conf_state*/, + gss_buffer_t /*output_message_buffer*/ + ); + +OM_uint32 gss_unseal + (OM_uint32 * /*minor_status*/, + gss_ctx_id_t /*context_handle*/, + gss_buffer_t /*input_message_buffer*/, + gss_buffer_t /*output_message_buffer*/, + int * /*conf_state*/, + int * /*qop_state*/ + ); + +/* + * kerberos mechanism specific functions + */ + +OM_uint32 gsskrb5_register_acceptor_identity + (const char */*identity*/); + +OM_uint32 gss_krb5_copy_ccache + (OM_uint32 */*minor*/, + gss_cred_id_t /*cred*/, + struct krb5_ccache_data */*out*/); + +#define GSS_C_KRB5_COMPAT_DES3_MIC 1 + +OM_uint32 +gss_krb5_compat_des3_mic(OM_uint32 *, gss_ctx_id_t, int); + +#ifdef __cplusplus +} +#endif + +#endif /* GSSAPI_H_ */ diff --git a/src/include/hdb-private.h b/src/include/hdb-private.h new file mode 100644 index 0000000..a47de70 --- /dev/null +++ b/src/include/hdb-private.h @@ -0,0 +1,27 @@ +/* This is a generated file */ +#ifndef __hdb_private_h__ +#define __hdb_private_h__ + +#include + +krb5_error_code +_hdb_fetch ( + krb5_context /*context*/, + HDB */*db*/, + unsigned /*flags*/, + hdb_entry */*entry*/); + +krb5_error_code +_hdb_remove ( + krb5_context /*context*/, + HDB */*db*/, + hdb_entry */*entry*/); + +krb5_error_code +_hdb_store ( + krb5_context /*context*/, + HDB */*db*/, + unsigned /*flags*/, + hdb_entry */*entry*/); + +#endif /* __hdb_private_h__ */ diff --git a/src/include/hdb-protos.h b/src/include/hdb-protos.h new file mode 100644 index 0000000..ce85fcb --- /dev/null +++ b/src/include/hdb-protos.h @@ -0,0 +1,188 @@ +/* This is a generated file */ +#ifndef __hdb_protos_h__ +#define __hdb_protos_h__ + +#include + +krb5_error_code +hdb_add_master_key ( + krb5_context /*context*/, + krb5_keyblock */*key*/, + hdb_master_key */*inout*/); + +krb5_error_code +hdb_check_db_format ( + krb5_context /*context*/, + HDB */*db*/); + +krb5_error_code +hdb_clear_master_key ( + krb5_context /*context*/, + HDB */*db*/); + +krb5_error_code +hdb_create ( + krb5_context /*context*/, + HDB **/*db*/, + const char */*filename*/); + +krb5_error_code +hdb_db_create ( + krb5_context /*context*/, + HDB **/*db*/, + const char */*filename*/); + +krb5_error_code +hdb_enctype2key ( + krb5_context /*context*/, + hdb_entry */*e*/, + krb5_enctype /*enctype*/, + Key **/*key*/); + +krb5_error_code +hdb_entry2string ( + krb5_context /*context*/, + hdb_entry */*ent*/, + char **/*str*/); + +int +hdb_entry2value ( + krb5_context /*context*/, + hdb_entry */*ent*/, + krb5_data */*value*/); + +krb5_error_code +hdb_foreach ( + krb5_context /*context*/, + HDB */*db*/, + unsigned /*flags*/, + hdb_foreach_func_t /*func*/, + void */*data*/); + +void +hdb_free_entry ( + krb5_context /*context*/, + hdb_entry */*ent*/); + +void +hdb_free_key (Key */*key*/); + +void +hdb_free_master_key ( + krb5_context /*context*/, + hdb_master_key /*mkey*/); + +krb5_error_code +hdb_init_db ( + krb5_context /*context*/, + HDB */*db*/); + +int +hdb_key2principal ( + krb5_context /*context*/, + krb5_data */*key*/, + krb5_principal /*p*/); + +krb5_error_code +hdb_ldap_create ( + krb5_context /*context*/, + HDB ** /*db*/, + const char */*arg*/); + +krb5_error_code +hdb_lock ( + int /*fd*/, + int /*operation*/); + +krb5_error_code +hdb_ndbm_create ( + krb5_context /*context*/, + HDB **/*db*/, + const char */*filename*/); + +krb5_error_code +hdb_next_enctype2key ( + krb5_context /*context*/, + const hdb_entry */*e*/, + krb5_enctype /*enctype*/, + Key **/*key*/); + +int +hdb_principal2key ( + krb5_context /*context*/, + krb5_principal /*p*/, + krb5_data */*key*/); + +krb5_error_code +hdb_print_entry ( + krb5_context /*context*/, + HDB */*db*/, + hdb_entry */*entry*/, + void */*data*/); + +krb5_error_code +hdb_process_master_key ( + krb5_context /*context*/, + int /*kvno*/, + krb5_keyblock */*key*/, + krb5_enctype /*etype*/, + hdb_master_key */*mkey*/); + +krb5_error_code +hdb_read_master_key ( + krb5_context /*context*/, + const char */*filename*/, + hdb_master_key */*mkey*/); + +krb5_error_code +hdb_seal_keys ( + krb5_context /*context*/, + HDB */*db*/, + hdb_entry */*ent*/); + +krb5_error_code +hdb_seal_keys_mkey ( + krb5_context /*context*/, + hdb_entry */*ent*/, + hdb_master_key /*mkey*/); + +krb5_error_code +hdb_set_master_key ( + krb5_context /*context*/, + HDB */*db*/, + krb5_keyblock */*key*/); + +krb5_error_code +hdb_set_master_keyfile ( + krb5_context /*context*/, + HDB */*db*/, + const char */*keyfile*/); + +krb5_error_code +hdb_unlock (int /*fd*/); + +krb5_error_code +hdb_unseal_keys ( + krb5_context /*context*/, + HDB */*db*/, + hdb_entry */*ent*/); + +krb5_error_code +hdb_unseal_keys_mkey ( + krb5_context /*context*/, + hdb_entry */*ent*/, + hdb_master_key /*mkey*/); + +int +hdb_value2entry ( + krb5_context /*context*/, + krb5_data */*value*/, + hdb_entry */*ent*/); + +krb5_error_code +hdb_write_master_key ( + krb5_context /*context*/, + const char */*filename*/, + hdb_master_key /*mkey*/); + +#endif /* __hdb_protos_h__ */ diff --git a/src/include/hdb.h b/src/include/hdb.h new file mode 100644 index 0000000..ed836fa --- /dev/null +++ b/src/include/hdb.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 1997 - 2000 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $Id$ */ + +#ifndef __HDB_H__ +#define __HDB_H__ + +#include + +#include + +enum hdb_lockop{ HDB_RLOCK, HDB_WLOCK }; + +/* flags for various functions */ +#define HDB_F_DECRYPT 1 /* decrypt keys */ +#define HDB_F_REPLACE 2 /* replace entry */ + +/* key usage for master key */ +#define HDB_KU_MKEY 0x484442 + +typedef struct hdb_master_key_data *hdb_master_key; + +typedef struct HDB{ + void *db; + void *dbc; + char *name; + int master_key_set; + hdb_master_key master_key; + int openp; + + krb5_error_code (*open)(krb5_context, struct HDB*, int, mode_t); + krb5_error_code (*close)(krb5_context, struct HDB*); + krb5_error_code (*fetch)(krb5_context, struct HDB*, unsigned, hdb_entry*); + krb5_error_code (*store)(krb5_context, struct HDB*, unsigned, hdb_entry*); + krb5_error_code (*remove)(krb5_context, struct HDB*, hdb_entry*); + krb5_error_code (*firstkey)(krb5_context, struct HDB*, + unsigned, hdb_entry*); + krb5_error_code (*nextkey)(krb5_context, struct HDB*, + unsigned, hdb_entry*); + krb5_error_code (*lock)(krb5_context, struct HDB*, int operation); + krb5_error_code (*unlock)(krb5_context, struct HDB*); + krb5_error_code (*rename)(krb5_context, struct HDB*, const char*); + krb5_error_code (*_get)(krb5_context, struct HDB*, krb5_data, krb5_data*); + krb5_error_code (*_put)(krb5_context, struct HDB*, int, + krb5_data, krb5_data); + krb5_error_code (*_del)(krb5_context, struct HDB*, krb5_data); + krb5_error_code (*destroy)(krb5_context, struct HDB*); +}HDB; + +#define HDB_DB_DIR "/var/heimdal" +#define HDB_DEFAULT_DB HDB_DB_DIR "/heimdal" +#define HDB_DB_FORMAT_ENTRY "hdb/db-format" + +typedef krb5_error_code (*hdb_foreach_func_t)(krb5_context, HDB*, + hdb_entry*, void*); +extern krb5_kt_ops hdb_kt_ops; + +#include + +#endif /* __HDB_H__ */ diff --git a/src/include/hdb_asn1.h b/src/include/hdb_asn1.h new file mode 100644 index 0000000..37e13d0 --- /dev/null +++ b/src/include/hdb_asn1.h @@ -0,0 +1,222 @@ +/* Generated from /usr/src/kerberos5/lib/libhdb/../../../crypto/heimdal/lib/hdb/hdb.asn1 */ +/* Do not edit */ + +#ifndef __hdb_asn1_h__ +#define __hdb_asn1_h__ + +#include +#include + +#ifndef __asn1_common_definitions__ +#define __asn1_common_definitions__ + +typedef struct octet_string { + size_t length; + void *data; +} octet_string; + +typedef char *general_string; + +typedef struct oid { + size_t length; + unsigned *components; +} oid; + +#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \ + do { \ + (BL) = length_##T((S)); \ + (B) = malloc((BL)); \ + if((B) == NULL) { \ + (R) = ENOMEM; \ + } else { \ + (R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \ + (S), (L)); \ + if((R) != 0) { \ + free((B)); \ + (B) = NULL; \ + } \ + } \ + } while (0) + +#endif + +enum { HDB_DB_FORMAT = 2 }; + +enum { hdb_pw_salt = 3 }; + +enum { hdb_afs3_salt = 10 }; + +/* +Salt ::= SEQUENCE { + type[0] INTEGER, + salt[1] OCTET STRING +} +*/ + +typedef struct Salt { + int type; + octet_string salt; +} Salt; + +int encode_Salt(unsigned char *, size_t, const Salt *, size_t *); +int decode_Salt(const unsigned char *, size_t, Salt *, size_t *); +void free_Salt (Salt *); +size_t length_Salt(const Salt *); +int copy_Salt (const Salt *, Salt *); + + +/* +Key ::= SEQUENCE { + mkvno[0] INTEGER OPTIONAL, + key[1] EncryptionKey, + salt[2] Salt OPTIONAL +} +*/ + +typedef struct Key { + int *mkvno; + EncryptionKey key; + Salt *salt; +} Key; + +int encode_Key(unsigned char *, size_t, const Key *, size_t *); +int decode_Key(const unsigned char *, size_t, Key *, size_t *); +void free_Key (Key *); +size_t length_Key(const Key *); +int copy_Key (const Key *, Key *); + + +/* +Event ::= SEQUENCE { + time[0] KerberosTime, + principal[1] Principal OPTIONAL +} +*/ + +typedef struct Event { + KerberosTime time; + Principal *principal; +} Event; + +int encode_Event(unsigned char *, size_t, const Event *, size_t *); +int decode_Event(const unsigned char *, size_t, Event *, size_t *); +void free_Event (Event *); +size_t length_Event(const Event *); +int copy_Event (const Event *, Event *); + + +/* +HDBFlags ::= BIT STRING { + initial(0), + forwardable(1), + proxiable(2), + renewable(3), + postdate(4), + server(5), + client(6), + invalid(7), + require-preauth(8), + change-pw(9), + require-hwauth(10), + ok-as-delegate(11), + user-to-user(12), + immutable(13) +} +*/ + +typedef struct HDBFlags { + unsigned int initial:1; + unsigned int forwardable:1; + unsigned int proxiable:1; + unsigned int renewable:1; + unsigned int postdate:1; + unsigned int server:1; + unsigned int client:1; + unsigned int invalid:1; + unsigned int require_preauth:1; + unsigned int change_pw:1; + unsigned int require_hwauth:1; + unsigned int ok_as_delegate:1; + unsigned int user_to_user:1; + unsigned int immutable:1; +} HDBFlags; + + +int encode_HDBFlags(unsigned char *, size_t, const HDBFlags *, size_t *); +int decode_HDBFlags(const unsigned char *, size_t, HDBFlags *, size_t *); +void free_HDBFlags (HDBFlags *); +size_t length_HDBFlags(const HDBFlags *); +int copy_HDBFlags (const HDBFlags *, HDBFlags *); +unsigned HDBFlags2int(HDBFlags); +HDBFlags int2HDBFlags(unsigned); +extern struct units HDBFlags_units[]; + +/* +GENERATION ::= SEQUENCE { + time[0] KerberosTime, + usec[1] INTEGER, + gen[2] INTEGER +} +*/ + +typedef struct GENERATION { + KerberosTime time; + int usec; + int gen; +} GENERATION; + +int encode_GENERATION(unsigned char *, size_t, const GENERATION *, size_t *); +int decode_GENERATION(const unsigned char *, size_t, GENERATION *, size_t *); +void free_GENERATION (GENERATION *); +size_t length_GENERATION(const GENERATION *); +int copy_GENERATION (const GENERATION *, GENERATION *); + + +/* +hdb_entry ::= SEQUENCE { + principal[0] Principal OPTIONAL, + kvno[1] INTEGER, + keys[2] SEQUENCE OF Key, + created-by[3] Event, + modified-by[4] Event OPTIONAL, + valid-start[5] KerberosTime OPTIONAL, + valid-end[6] KerberosTime OPTIONAL, + pw-end[7] KerberosTime OPTIONAL, + max-life[8] INTEGER OPTIONAL, + max-renew[9] INTEGER OPTIONAL, + flags[10] HDBFlags, + etypes[11] SEQUENCE OF INTEGER OPTIONAL, + generation[12] GENERATION OPTIONAL +} +*/ + +typedef struct hdb_entry { + Principal *principal; + int kvno; + struct { + unsigned int len; + Key *val; + } keys; + Event created_by; + Event *modified_by; + KerberosTime *valid_start; + KerberosTime *valid_end; + KerberosTime *pw_end; + int *max_life; + int *max_renew; + HDBFlags flags; + struct { + unsigned int len; + int *val; + } *etypes; + GENERATION *generation; +} hdb_entry; + +int encode_hdb_entry(unsigned char *, size_t, const hdb_entry *, size_t *); +int decode_hdb_entry(const unsigned char *, size_t, hdb_entry *, size_t *); +void free_hdb_entry (hdb_entry *); +size_t length_hdb_entry(const hdb_entry *); +int copy_hdb_entry (const hdb_entry *, hdb_entry *); + + +#endif /* __hdb_asn1_h__ */ diff --git a/src/include/hdb_err.h b/src/include/hdb_err.h new file mode 100644 index 0000000..2304404 --- /dev/null +++ b/src/include/hdb_err.h @@ -0,0 +1,31 @@ +/* Generated from /usr/src/kerberos5/lib/libhdb/../../../crypto/heimdal/lib/hdb/hdb_err.et */ +/* $Id$ */ + +#ifndef __hdb_err_h__ +#define __hdb_err_h__ + +struct et_list; + +void initialize_hdb_error_table_r(struct et_list **); + +void initialize_hdb_error_table(void); +#define init_hdb_err_tbl initialize_hdb_error_table + +typedef enum hdb_error_number{ + HDB_ERR_UK_SERROR = 36150273, + HDB_ERR_UK_RERROR = 36150274, + HDB_ERR_NOENTRY = 36150275, + HDB_ERR_DB_INUSE = 36150276, + HDB_ERR_DB_CHANGED = 36150277, + HDB_ERR_RECURSIVELOCK = 36150278, + HDB_ERR_NOTLOCKED = 36150279, + HDB_ERR_BADLOCKMODE = 36150280, + HDB_ERR_CANT_LOCK_DB = 36150281, + HDB_ERR_EXISTS = 36150282, + HDB_ERR_BADVERSION = 36150283, + HDB_ERR_NO_MKEY = 36150284 +} hdb_error_number; + +#define ERROR_TABLE_BASE_hdb 36150272 + +#endif /* __hdb_err_h__ */ diff --git a/src/include/heim_err.h b/src/include/heim_err.h new file mode 100644 index 0000000..ad57e61 --- /dev/null +++ b/src/include/heim_err.h @@ -0,0 +1,39 @@ +/* Generated from /usr/src/kerberos5/lib/libkrb5/../../../crypto/heimdal/lib/krb5/heim_err.et */ +/* $Id$ */ + +#ifndef __heim_err_h__ +#define __heim_err_h__ + +struct et_list; + +void initialize_heim_error_table_r(struct et_list **); + +void initialize_heim_error_table(void); +#define init_heim_err_tbl initialize_heim_error_table + +typedef enum heim_error_number{ + HEIM_ERR_LOG_PARSE = -1980176640, + HEIM_ERR_V4_PRINC_NO_CONV = -1980176639, + HEIM_ERR_SALTTYPE_NOSUPP = -1980176638, + HEIM_ERR_NOHOST = -1980176637, + HEIM_ERR_OPNOTSUPP = -1980176636, + HEIM_ERR_EOF = -1980176635, + HEIM_ERR_BAD_MKEY = -1980176634, + HEIM_ERR_SERVICE_NOMATCH = -1980176633, + HEIM_EAI_UNKNOWN = -1980176512, + HEIM_EAI_ADDRFAMILY = -1980176511, + HEIM_EAI_AGAIN = -1980176510, + HEIM_EAI_BADFLAGS = -1980176509, + HEIM_EAI_FAIL = -1980176508, + HEIM_EAI_FAMILY = -1980176507, + HEIM_EAI_MEMORY = -1980176506, + HEIM_EAI_NODATA = -1980176505, + HEIM_EAI_NONAME = -1980176504, + HEIM_EAI_SERVICE = -1980176503, + HEIM_EAI_SOCKTYPE = -1980176502, + HEIM_EAI_SYSTEM = -1980176501 +} heim_error_number; + +#define ERROR_TABLE_BASE_heim -1980176640 + +#endif /* __heim_err_h__ */ diff --git a/src/include/hesiod.h b/src/include/hesiod.h new file mode 100644 index 0000000..c7dbeee --- /dev/null +++ b/src/include/hesiod.h @@ -0,0 +1,98 @@ +/* $NetBSD: hesiod.h,v 1.3 1999/01/24 23:53:18 lukem Exp $ */ +/* $FreeBSD: src/include/hesiod.h,v 1.2 2002/03/23 17:24:53 imp Exp $ */ + + +/*- + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#ifndef _HESIOD_H_ +#define _HESIOD_H_ + + /* Application-visible indication that we have the new interfaces */ + +#define HESIOD_INTERFACES + + /* Configuration information. */ + +#ifndef _PATH_HESIOD_CONF /* Configuration file. */ +#define _PATH_HESIOD_CONF "/etc/hesiod.conf" +#endif + +#define DEF_RHS "" /* Defaults if HESIOD_CONF */ +#define DEF_LHS "" /* file is not present. */ + + /* Error codes (for backwards compatibility) */ + +#define HES_ER_UNINIT -1 /* uninitialized */ +#define HES_ER_OK 0 /* no error */ +#define HES_ER_NOTFOUND 1 /* Hesiod name not found by server */ +#define HES_ER_CONFIG 2 /* local problem (no config file?) */ +#define HES_ER_NET 3 /* network problem */ + + /* Declaration of routines */ + +#include + +__BEGIN_DECLS +int hesiod_init(void **); +char **hesiod_resolve(void *, const char *, const char *); +void hesiod_free_list(void *, char **); +char *hesiod_to_bind(void *, const char *, const char *); +void hesiod_end(void *); + + /* backwards compatibility */ +int hes_init(void); +char *hes_to_bind(const char *, const char *); +char **hes_resolve(const char *, const char *); +int hes_error(void); +void hes_free(char **); +__END_DECLS + +#endif /* ! _HESIOD_H_ */ diff --git a/src/include/histedit.h b/src/include/histedit.h new file mode 100644 index 0000000..a7373ef --- /dev/null +++ b/src/include/histedit.h @@ -0,0 +1,201 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Christos Zoulas of Cornell University. + * + * 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. + * + * @(#)histedit.h 8.2 (Berkeley) 1/3/94 + * $NetBSD: histedit.h,v 1.15 2000/02/28 17:41:05 chopps Exp $ + * $FreeBSD: src/include/histedit.h,v 1.9 2003/07/14 16:31:20 imp Exp $ + */ + +/* + * histedit.h: Line editor and history interface. + */ +#ifndef _HISTEDIT_H_ +#define _HISTEDIT_H_ + +#include +#include + +__BEGIN_DECLS + +/* + * ==== Editing ==== + */ +typedef struct editline EditLine; + +/* + * For user-defined function interface + */ +typedef struct lineinfo { + const char *buffer; + const char *cursor; + const char *lastchar; +} LineInfo; + + +/* + * EditLine editor function return codes. + * For user-defined function interface + */ +#define CC_NORM 0 +#define CC_NEWLINE 1 +#define CC_EOF 2 +#define CC_ARGHACK 3 +#define CC_REFRESH 4 +#define CC_CURSOR 5 +#define CC_ERROR 6 +#define CC_FATAL 7 +#define CC_REDISPLAY 8 +#define CC_REFRESH_BEEP 9 + +/* + * Initialization, cleanup, and resetting + */ +EditLine *el_init(const char *, FILE *, FILE *, FILE *); +void el_reset(EditLine *); +void el_end(EditLine *); + + +/* + * Get a line, a character or push a string back in the input queue + */ +const char *el_gets(EditLine *, int *); +int el_getc(EditLine *, char *); +void el_push(EditLine *, const char *); + +/* + * Beep! + */ +void el_beep(EditLine *); + +/* + * High level function internals control + * Parses argc, argv array and executes builtin editline commands + */ +int el_parse(EditLine *, int, char **); + +/* + * Low level editline access functions + */ +int el_set(EditLine *, int, ...); +int el_get(EditLine *, int, void *); + +/* + * el_set/el_get parameters + */ +#define EL_PROMPT 0 /* , el_pfunc_t); */ +#define EL_TERMINAL 1 /* , const char *); */ +#define EL_EDITOR 2 /* , const char *); */ +#define EL_SIGNAL 3 /* , int); */ +#define EL_BIND 4 /* , const char *, ..., NULL); */ +#define EL_TELLTC 5 /* , const char *, ..., NULL); */ +#define EL_SETTC 6 /* , const char *, ..., NULL); */ +#define EL_ECHOTC 7 /* , const char *, ..., NULL); */ +#define EL_SETTY 8 /* , const char *, ..., NULL); */ +#define EL_ADDFN 9 /* , const char *, const char * */ + /* , el_func_t); */ +#define EL_HIST 10 /* , hist_fun_t, const char *); */ +#define EL_EDITMODE 11 /* , int); */ +#define EL_RPROMPT 12 /* , el_pfunc_t); */ + +/* + * Source named file or $PWD/.editrc or $HOME/.editrc + */ +int el_source(EditLine *, const char *); + +/* + * Must be called when the terminal changes size; If EL_SIGNAL + * is set this is done automatically otherwise it is the responsibility + * of the application + */ +void el_resize(EditLine *); + + +/* + * Set user private data. + */ +void el_data_set __P((EditLine *, void *)); +void * el_data_get __P((EditLine *)); + +/* + * User-defined function interface. + */ +const LineInfo *el_line(EditLine *); +int el_insertstr(EditLine *, const char *); +void el_deletestr(EditLine *, int); + +/* + * ==== History ==== + */ + +typedef struct history History; + +typedef struct HistEvent { + int num; + const char *str; +} HistEvent; + +/* + * History access functions. + */ +History * history_init(void); +void history_end(History *); + +int history(History *, HistEvent *, int, ...); + +#define H_FUNC 0 /* , UTSL */ +#define H_SETSIZE 1 /* , const int); */ +#define H_EVENT 1 /* , const int); */ +#define H_GETSIZE 2 /* , void); */ +#define H_FIRST 3 /* , void); */ +#define H_LAST 4 /* , void); */ +#define H_PREV 5 /* , void); */ +#define H_NEXT 6 /* , void); */ +#define H_CURR 8 /* , const int); */ +#define H_SET 7 /* , void); */ +#define H_ADD 9 /* , const char *); */ +#define H_ENTER 10 /* , const char *); */ +#define H_APPEND 11 /* , const char *); */ +#define H_END 12 /* , void); */ +#define H_NEXT_STR 13 /* , const char *); */ +#define H_PREV_STR 14 /* , const char *); */ +#define H_NEXT_EVENT 15 /* , const int); */ +#define H_PREV_EVENT 16 /* , const int); */ +#define H_LOAD 17 /* , const char *); */ +#define H_SAVE 18 /* , const char *); */ +#define H_CLEAR 19 /* , void); */ + +__END_DECLS + +#endif /* _HISTEDIT_H_ */ diff --git a/src/include/ieeefp.h b/src/include/ieeefp.h new file mode 100644 index 0000000..981deea --- /dev/null +++ b/src/include/ieeefp.h @@ -0,0 +1,26 @@ +/* $NetBSD: ieeefp.h,v 1.4 1998/01/09 08:03:43 perry Exp $ */ +/* $FreeBSD: src/include/ieeefp.h,v 1.7 2003/01/19 06:01:32 marcel Exp $ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _IEEEFP_H_ +#define _IEEEFP_H_ + +#include +#include + +#if !defined(_IEEEFP_INLINED_) +__BEGIN_DECLS +extern fp_rnd_t fpgetround(void); +extern fp_rnd_t fpsetround(fp_rnd_t); +extern fp_except_t fpgetmask(void); +extern fp_except_t fpsetmask(fp_except_t); +extern fp_except_t fpgetsticky(void); +extern fp_except_t fpsetsticky(fp_except_t); +__END_DECLS +#endif /* !_IEEEFP_INLINED_ */ + +#endif /* _IEEEFP_H_ */ diff --git a/src/include/ifaddrs.h b/src/include/ifaddrs.h new file mode 100644 index 0000000..4de13c5 --- /dev/null +++ b/src/include/ifaddrs.h @@ -0,0 +1,65 @@ +/* $FreeBSD: src/include/ifaddrs.h,v 1.3 2003/11/14 18:53:22 bms Exp $ */ + +/* + * Copyright (c) 1995, 1999 + * Berkeley Software Design, Inc. 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. + * + * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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. + * + * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp + */ + +#ifndef _IFADDRS_H_ +#define _IFADDRS_H_ + +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + u_int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_dstaddr; + void *ifa_data; +}; + +/* + * This may have been defined in . Note that if is + * to be included it must be included before this header file. + */ +#ifndef ifa_broadaddr +#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ +#endif + +struct ifmaddrs { + struct ifmaddrs *ifma_next; + struct sockaddr *ifma_name; + struct sockaddr *ifma_addr; + struct sockaddr *ifma_lladdr; +}; + +#include + +__BEGIN_DECLS +extern int getifaddrs(struct ifaddrs **); +extern void freeifaddrs(struct ifaddrs *); +extern int getifmaddrs(struct ifmaddrs **); +extern void freeifmaddrs(struct ifmaddrs *); +__END_DECLS + +#endif diff --git a/src/include/inttypes.h b/src/include/inttypes.h new file mode 100644 index 0000000..ae537a5 --- /dev/null +++ b/src/include/inttypes.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/inttypes.h,v 1.8 2002/09/22 08:06:45 tjr Exp $ + */ + +#ifndef _INTTYPES_H_ +#define _INTTYPES_H_ + +#include +#include + +typedef struct { + intmax_t quot; /* Quotient. */ + intmax_t rem; /* Remainder. */ +} imaxdiv_t; + +__BEGIN_DECLS +intmax_t imaxabs(intmax_t) __pure2; +imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2; + +intmax_t strtoimax(const char * __restrict, char ** __restrict, int); +uintmax_t strtoumax(const char * __restrict, char ** __restrict, int); +intmax_t wcstoimax(const __wchar_t * __restrict, + __wchar_t ** __restrict, int); +uintmax_t wcstoumax(const __wchar_t * __restrict, + __wchar_t ** __restrict, int); +__END_DECLS + +#endif /* !_INTTYPES_H_ */ diff --git a/src/include/iso646.h b/src/include/iso646.h new file mode 100644 index 0000000..392b19f --- /dev/null +++ b/src/include/iso646.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 1998 Alex Nash + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/iso646.h,v 1.4 2002/09/18 22:23:59 mike Exp $ + */ + +#ifndef _ISO646_H_ +#define _ISO646_H_ + +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= + +#endif /* !_ISO646_H_ */ diff --git a/src/include/k524_err.h b/src/include/k524_err.h new file mode 100644 index 0000000..c46ad67 --- /dev/null +++ b/src/include/k524_err.h @@ -0,0 +1,27 @@ +/* Generated from /usr/src/kerberos5/lib/libkrb5/../../../crypto/heimdal/lib/krb5/k524_err.et */ +/* $Id$ */ + +#ifndef __k524_err_h__ +#define __k524_err_h__ + +struct et_list; + +void initialize_k524_error_table_r(struct et_list **); + +void initialize_k524_error_table(void); +#define init_k524_err_tbl initialize_k524_error_table + +typedef enum k524_error_number{ + KRB524_BADKEY = -1750206208, + KRB524_BADADDR = -1750206207, + KRB524_BADPRINC = -1750206206, + KRB524_BADREALM = -1750206205, + KRB524_V4ERR = -1750206204, + KRB524_ENCFULL = -1750206203, + KRB524_DECEMPTY = -1750206202, + KRB524_NOTRESP = -1750206201 +} k524_error_number; + +#define ERROR_TABLE_BASE_k524 -1750206208 + +#endif /* __k524_err_h__ */ diff --git a/src/include/kafs.h b/src/include/kafs.h new file mode 100644 index 0000000..b475a1b --- /dev/null +++ b/src/include/kafs.h @@ -0,0 +1,208 @@ +/* + * Copyright (c) 1995 - 2001, 2003 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $Id$ */ + +#ifndef __KAFS_H +#define __KAFS_H + +/* XXX must include krb5.h or krb.h */ + +/* sys/ioctl.h must be included manually before kafs.h */ + +/* + */ +#define AFSCALL_PIOCTL 20 +#define AFSCALL_SETPAG 21 + +#ifndef _VICEIOCTL +#define _VICEIOCTL(id) ((unsigned int ) _IOW('V', id, struct ViceIoctl)) +#endif /* _VICEIOCTL */ + +#define VIOCSETAL _VICEIOCTL(1) +#define VIOCGETAL _VICEIOCTL(2) +#define VIOCSETTOK _VICEIOCTL(3) +#define VIOCGETVOLSTAT _VICEIOCTL(4) +#define VIOCSETVOLSTAT _VICEIOCTL(5) +#define VIOCFLUSH _VICEIOCTL(6) +#define VIOCGETTOK _VICEIOCTL(8) +#define VIOCUNLOG _VICEIOCTL(9) +#define VIOCCKSERV _VICEIOCTL(10) +#define VIOCCKBACK _VICEIOCTL(11) +#define VIOCCKCONN _VICEIOCTL(12) +#define VIOCWHEREIS _VICEIOCTL(14) +#define VIOCACCESS _VICEIOCTL(20) +#define VIOCUNPAG _VICEIOCTL(21) +#define VIOCGETFID _VICEIOCTL(22) +#define VIOCSETCACHESIZE _VICEIOCTL(24) +#define VIOCFLUSHCB _VICEIOCTL(25) +#define VIOCNEWCELL _VICEIOCTL(26) +#define VIOCGETCELL _VICEIOCTL(27) +#define VIOC_AFS_DELETE_MT_PT _VICEIOCTL(28) +#define VIOC_AFS_STAT_MT_PT _VICEIOCTL(29) +#define VIOC_FILE_CELL_NAME _VICEIOCTL(30) +#define VIOC_GET_WS_CELL _VICEIOCTL(31) +#define VIOC_AFS_MARINER_HOST _VICEIOCTL(32) +#define VIOC_GET_PRIMARY_CELL _VICEIOCTL(33) +#define VIOC_VENUSLOG _VICEIOCTL(34) +#define VIOC_GETCELLSTATUS _VICEIOCTL(35) +#define VIOC_SETCELLSTATUS _VICEIOCTL(36) +#define VIOC_FLUSHVOLUME _VICEIOCTL(37) +#define VIOC_AFS_SYSNAME _VICEIOCTL(38) +#define VIOC_EXPORTAFS _VICEIOCTL(39) +#define VIOCGETCACHEPARAMS _VICEIOCTL(40) +#define VIOC_GCPAGS _VICEIOCTL(48) + +struct ViceIoctl { + caddr_t in, out; + short in_size; + short out_size; +}; + +struct ClearToken { + int32_t AuthHandle; + char HandShakeKey[8]; + int32_t ViceId; + int32_t BeginTimestamp; + int32_t EndTimestamp; +}; + +#ifdef __STDC__ +#ifndef __P +#define __P(x) x +#endif +#else +#ifndef __P +#define __P(x) () +#endif +#endif + +/* Use k_hasafs() to probe if the machine supports AFS syscalls. + The other functions will generate a SIGSYS if AFS is not supported */ + +int k_hasafs __P((void)); + +int krb_afslog __P((const char *cell, const char *realm)); +int krb_afslog_uid __P((const char *cell, const char *realm, uid_t uid)); +int krb_afslog_home __P((const char *cell, const char *realm, + const char *homedir)); +int krb_afslog_uid_home __P((const char *cell, const char *realm, uid_t uid, + const char *homedir)); + +int krb_realm_of_cell __P((const char *cell, char **realm)); + +/* compat */ +#define k_afsklog krb_afslog +#define k_afsklog_uid krb_afslog_uid + +int k_pioctl __P((char *a_path, + int o_opcode, + struct ViceIoctl *a_paramsP, + int a_followSymlinks)); +int k_unlog __P((void)); +int k_setpag __P((void)); +int k_afs_cell_of_file __P((const char *path, char *cell, int len)); + + + +/* XXX */ +#ifdef KFAILURE +#define KRB_H_INCLUDED +#endif + +#ifdef KRB5_RECVAUTH_IGNORE_VERSION +#define KRB5_H_INCLUDED +#endif + +void kafs_set_verbose __P((void (*kafs_verbose)(void *, const char *), void *)); +int kafs_settoken_rxkad __P((const char *, struct ClearToken *, + void *ticket, size_t ticket_len)); +#ifdef KRB_H_INCLUDED +int kafs_settoken __P((const char*, uid_t, CREDENTIALS*)); +#endif +#ifdef KRB5_H_INCLUDED +int kafs_settoken5 __P((krb5_context, const char*, uid_t, krb5_creds*)); +#endif + + +#ifdef KRB5_H_INCLUDED +krb5_error_code krb5_afslog_uid __P((krb5_context context, + krb5_ccache id, + const char *cell, + krb5_const_realm realm, + uid_t uid)); +krb5_error_code krb5_afslog __P((krb5_context context, + krb5_ccache id, + const char *cell, + krb5_const_realm realm)); +krb5_error_code krb5_afslog_uid_home __P((krb5_context context, + krb5_ccache id, + const char *cell, + krb5_const_realm realm, + uid_t uid, + const char *homedir)); + +krb5_error_code krb5_afslog_home __P((krb5_context context, + krb5_ccache id, + const char *cell, + krb5_const_realm realm, + const char *homedir)); + +krb5_error_code krb5_realm_of_cell __P((const char *cell, char **realm)); + +#endif + + +#define _PATH_VICE "/usr/vice/etc/" +#define _PATH_THISCELL _PATH_VICE "ThisCell" +#define _PATH_CELLSERVDB _PATH_VICE "CellServDB" +#define _PATH_THESECELLS _PATH_VICE "TheseCells" + +#define _PATH_ARLA_VICE "/usr/arla/etc/" +#define _PATH_ARLA_THISCELL _PATH_ARLA_VICE "ThisCell" +#define _PATH_ARLA_CELLSERVDB _PATH_ARLA_VICE "CellServDB" +#define _PATH_ARLA_THESECELLS _PATH_ARLA_VICE "TheseCells" + +#define _PATH_OPENAFS_DEBIAN_VICE "/etc/openafs/" +#define _PATH_OPENAFS_DEBIAN_THISCELL _PATH_OPENAFS_DEBIAN_VICE "ThisCell" +#define _PATH_OPENAFS_DEBIAN_CELLSERVDB _PATH_OPENAFS_DEBIAN_VICE "CellServDB" +#define _PATH_OPENAFS_DEBIAN_THESECELLS _PATH_OPENAFS_DEBIAN_VICE "TheseCells" + +#define _PATH_ARLA_DEBIAN_VICE "/etc/arla/" +#define _PATH_ARLA_DEBIAN_THISCELL _PATH_ARLA_DEBIAN_VICE "ThisCell" +#define _PATH_ARLA_DEBIAN_CELLSERVDB _PATH_ARLA_DEBIAN_VICE "CellServDB" +#define _PATH_ARLA_DEBIAN_THESECELLS _PATH_ARLA_DEBIAN_VICE "TheseCells" + +extern int _kafs_debug; + +#endif /* __KAFS_H */ diff --git a/src/include/kenv.h b/src/include/kenv.h new file mode 100644 index 0000000..e41bb59 --- /dev/null +++ b/src/include/kenv.h @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2002 Maxime Henrion + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/kenv.h,v 1.1 2002/04/17 13:06:32 mux Exp $ + */ + +#ifndef _KENV_H_ +#define _KENV_H_ + +#include +#include + +__BEGIN_DECLS +int kenv(int, char *, char *, int); +__END_DECLS + +#endif /* !_KENV_H_ */ diff --git a/src/include/krb5-protos.h b/src/include/krb5-protos.h new file mode 100644 index 0000000..4023744 --- /dev/null +++ b/src/include/krb5-protos.h @@ -0,0 +1,2966 @@ +/* This is a generated file */ +#ifndef __krb5_protos_h__ +#define __krb5_protos_h__ + +#include + +#if !defined(__GNUC__) && !defined(__attribute__) +#define __attribute__(x) +#endif + +krb5_error_code +krb524_convert_creds_kdc ( + krb5_context /*context*/, + krb5_creds */*in_cred*/, + struct credentials */*v4creds*/); + +krb5_error_code +krb524_convert_creds_kdc_ccache ( + krb5_context /*context*/, + krb5_ccache /*ccache*/, + krb5_creds */*in_cred*/, + struct credentials */*v4creds*/); + +krb5_error_code +krb5_425_conv_principal ( + krb5_context /*context*/, + const char */*name*/, + const char */*instance*/, + const char */*realm*/, + krb5_principal */*princ*/); + +krb5_error_code +krb5_425_conv_principal_ext ( + krb5_context /*context*/, + const char */*name*/, + const char */*instance*/, + const char */*realm*/, + krb5_boolean (*/*func*/)(krb5_context, krb5_principal), + krb5_boolean /*resolve*/, + krb5_principal */*princ*/); + +krb5_error_code +krb5_524_conv_principal ( + krb5_context /*context*/, + const krb5_principal /*principal*/, + char */*name*/, + char */*instance*/, + char */*realm*/); + +krb5_error_code +krb5_PKCS5_PBKDF2 ( + krb5_context /*context*/, + krb5_cksumtype /*cktype*/, + krb5_data /*password*/, + krb5_salt /*salt*/, + u_int32_t /*iter*/, + krb5_keytype /*type*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_abort ( + krb5_context /*context*/, + krb5_error_code /*code*/, + const char */*fmt*/, + ...) + __attribute__ ((noreturn, format (printf, 3, 4))); + +krb5_error_code +krb5_abortx ( + krb5_context /*context*/, + const char */*fmt*/, + ...) + __attribute__ ((noreturn, format (printf, 2, 3))); + +krb5_error_code +krb5_acl_match_file ( + krb5_context /*context*/, + const char */*file*/, + const char */*format*/, + ...); + +krb5_error_code +krb5_acl_match_string ( + krb5_context /*context*/, + const char */*string*/, + const char */*format*/, + ...); + +krb5_error_code +krb5_add_et_list ( + krb5_context /*context*/, + void (*/*func*/)(struct et_list **)); + +krb5_error_code +krb5_add_extra_addresses ( + krb5_context /*context*/, + krb5_addresses */*addresses*/); + +krb5_error_code +krb5_add_ignore_addresses ( + krb5_context /*context*/, + krb5_addresses */*addresses*/); + +krb5_error_code +krb5_addlog_dest ( + krb5_context /*context*/, + krb5_log_facility */*f*/, + const char */*orig*/); + +krb5_error_code +krb5_addlog_func ( + krb5_context /*context*/, + krb5_log_facility */*fac*/, + int /*min*/, + int /*max*/, + krb5_log_log_func_t /*log*/, + krb5_log_close_func_t /*close*/, + void */*data*/); + +krb5_error_code +krb5_addr2sockaddr ( + krb5_context /*context*/, + const krb5_address */*addr*/, + struct sockaddr */*sa*/, + krb5_socklen_t */*sa_size*/, + int /*port*/); + +krb5_boolean +krb5_address_compare ( + krb5_context /*context*/, + const krb5_address */*addr1*/, + const krb5_address */*addr2*/); + +int +krb5_address_order ( + krb5_context /*context*/, + const krb5_address */*addr1*/, + const krb5_address */*addr2*/); + +krb5_boolean +krb5_address_search ( + krb5_context /*context*/, + const krb5_address */*addr*/, + const krb5_addresses */*addrlist*/); + +krb5_error_code +krb5_aname_to_localname ( + krb5_context /*context*/, + krb5_const_principal /*aname*/, + size_t /*lnsize*/, + char */*lname*/); + +krb5_error_code +krb5_anyaddr ( + krb5_context /*context*/, + int /*af*/, + struct sockaddr */*sa*/, + krb5_socklen_t */*sa_size*/, + int /*port*/); + +void +krb5_appdefault_boolean ( + krb5_context /*context*/, + const char */*appname*/, + krb5_const_realm /*realm*/, + const char */*option*/, + krb5_boolean /*def_val*/, + krb5_boolean */*ret_val*/); + +void +krb5_appdefault_string ( + krb5_context /*context*/, + const char */*appname*/, + krb5_const_realm /*realm*/, + const char */*option*/, + const char */*def_val*/, + char **/*ret_val*/); + +void +krb5_appdefault_time ( + krb5_context /*context*/, + const char */*appname*/, + krb5_const_realm /*realm*/, + const char */*option*/, + time_t /*def_val*/, + time_t */*ret_val*/); + +krb5_error_code +krb5_append_addresses ( + krb5_context /*context*/, + krb5_addresses */*dest*/, + const krb5_addresses */*source*/); + +krb5_error_code +krb5_auth_con_free ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/); + +krb5_error_code +krb5_auth_con_genaddrs ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + int /*fd*/, + int /*flags*/); + +krb5_error_code +krb5_auth_con_generatelocalsubkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_auth_con_getaddrs ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_address **/*local_addr*/, + krb5_address **/*remote_addr*/); + +krb5_error_code +krb5_auth_con_getauthenticator ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_authenticator */*authenticator*/); + +krb5_error_code +krb5_auth_con_getcksumtype ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_cksumtype */*cksumtype*/); + +krb5_error_code +krb5_auth_con_getflags ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + int32_t */*flags*/); + +krb5_error_code +krb5_auth_con_getkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock **/*keyblock*/); + +krb5_error_code +krb5_auth_con_getkeytype ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keytype */*keytype*/); + +krb5_error_code +krb5_auth_con_getlocalseqnumber ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + int32_t */*seqnumber*/); + +krb5_error_code +krb5_auth_con_getlocalsubkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock **/*keyblock*/); + +krb5_error_code +krb5_auth_con_getrcache ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_rcache */*rcache*/); + +krb5_error_code +krb5_auth_con_getremotesubkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock **/*keyblock*/); + +krb5_error_code +krb5_auth_con_init ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/); + +krb5_error_code +krb5_auth_con_setaddrs ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_address */*local_addr*/, + krb5_address */*remote_addr*/); + +krb5_error_code +krb5_auth_con_setaddrs_from_fd ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + void */*p_fd*/); + +krb5_error_code +krb5_auth_con_setcksumtype ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_cksumtype /*cksumtype*/); + +krb5_error_code +krb5_auth_con_setflags ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + int32_t /*flags*/); + +krb5_error_code +krb5_auth_con_setkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock */*keyblock*/); + +krb5_error_code +krb5_auth_con_setkeytype ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keytype /*keytype*/); + +krb5_error_code +krb5_auth_con_setlocalseqnumber ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + int32_t /*seqnumber*/); + +krb5_error_code +krb5_auth_con_setlocalsubkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock */*keyblock*/); + +krb5_error_code +krb5_auth_con_setrcache ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_rcache /*rcache*/); + +krb5_error_code +krb5_auth_con_setremoteseqnumber ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + int32_t /*seqnumber*/); + +krb5_error_code +krb5_auth_con_setremotesubkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock */*keyblock*/); + +krb5_error_code +krb5_auth_con_setuserkey ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_keyblock */*keyblock*/); + +krb5_error_code +krb5_auth_getremoteseqnumber ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + int32_t */*seqnumber*/); + +krb5_error_code +krb5_build_ap_req ( + krb5_context /*context*/, + krb5_enctype /*enctype*/, + krb5_creds */*cred*/, + krb5_flags /*ap_options*/, + krb5_data /*authenticator*/, + krb5_data */*retdata*/); + +krb5_error_code +krb5_build_authenticator ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_enctype /*enctype*/, + krb5_creds */*cred*/, + Checksum */*cksum*/, + Authenticator **/*auth_result*/, + krb5_data */*result*/, + krb5_key_usage /*usage*/); + +krb5_error_code +krb5_build_principal ( + krb5_context /*context*/, + krb5_principal */*principal*/, + int /*rlen*/, + krb5_const_realm /*realm*/, + ...); + +krb5_error_code +krb5_build_principal_ext ( + krb5_context /*context*/, + krb5_principal */*principal*/, + int /*rlen*/, + krb5_const_realm /*realm*/, + ...); + +krb5_error_code +krb5_build_principal_va ( + krb5_context /*context*/, + krb5_principal */*principal*/, + int /*rlen*/, + krb5_const_realm /*realm*/, + va_list /*ap*/); + +krb5_error_code +krb5_build_principal_va_ext ( + krb5_context /*context*/, + krb5_principal */*principal*/, + int /*rlen*/, + krb5_const_realm /*realm*/, + va_list /*ap*/); + +krb5_error_code +krb5_cc_close ( + krb5_context /*context*/, + krb5_ccache /*id*/); + +krb5_error_code +krb5_cc_copy_cache ( + krb5_context /*context*/, + const krb5_ccache /*from*/, + krb5_ccache /*to*/); + +krb5_error_code +krb5_cc_default ( + krb5_context /*context*/, + krb5_ccache */*id*/); + +const char* +krb5_cc_default_name (krb5_context /*context*/); + +krb5_error_code +krb5_cc_destroy ( + krb5_context /*context*/, + krb5_ccache /*id*/); + +krb5_error_code +krb5_cc_end_seq_get ( + krb5_context /*context*/, + const krb5_ccache /*id*/, + krb5_cc_cursor */*cursor*/); + +krb5_error_code +krb5_cc_gen_new ( + krb5_context /*context*/, + const krb5_cc_ops */*ops*/, + krb5_ccache */*id*/); + +const char* +krb5_cc_get_name ( + krb5_context /*context*/, + krb5_ccache /*id*/); + +const krb5_cc_ops * +krb5_cc_get_ops ( + krb5_context /*context*/, + krb5_ccache /*id*/); + +krb5_error_code +krb5_cc_get_principal ( + krb5_context /*context*/, + krb5_ccache /*id*/, + krb5_principal */*principal*/); + +const char* +krb5_cc_get_type ( + krb5_context /*context*/, + krb5_ccache /*id*/); + +krb5_error_code +krb5_cc_get_version ( + krb5_context /*context*/, + const krb5_ccache /*id*/); + +krb5_error_code +krb5_cc_initialize ( + krb5_context /*context*/, + krb5_ccache /*id*/, + krb5_principal /*primary_principal*/); + +krb5_error_code +krb5_cc_next_cred ( + krb5_context /*context*/, + const krb5_ccache /*id*/, + krb5_cc_cursor */*cursor*/, + krb5_creds */*creds*/); + +krb5_error_code +krb5_cc_register ( + krb5_context /*context*/, + const krb5_cc_ops */*ops*/, + krb5_boolean /*override*/); + +krb5_error_code +krb5_cc_remove_cred ( + krb5_context /*context*/, + krb5_ccache /*id*/, + krb5_flags /*which*/, + krb5_creds */*cred*/); + +krb5_error_code +krb5_cc_resolve ( + krb5_context /*context*/, + const char */*name*/, + krb5_ccache */*id*/); + +krb5_error_code +krb5_cc_retrieve_cred ( + krb5_context /*context*/, + krb5_ccache /*id*/, + krb5_flags /*whichfields*/, + const krb5_creds */*mcreds*/, + krb5_creds */*creds*/); + +krb5_error_code +krb5_cc_set_default_name ( + krb5_context /*context*/, + const char */*name*/); + +krb5_error_code +krb5_cc_set_flags ( + krb5_context /*context*/, + krb5_ccache /*id*/, + krb5_flags /*flags*/); + +krb5_error_code +krb5_cc_start_seq_get ( + krb5_context /*context*/, + const krb5_ccache /*id*/, + krb5_cc_cursor */*cursor*/); + +krb5_error_code +krb5_cc_store_cred ( + krb5_context /*context*/, + krb5_ccache /*id*/, + krb5_creds */*creds*/); + +krb5_error_code +krb5_change_password ( + krb5_context /*context*/, + krb5_creds */*creds*/, + char */*newpw*/, + int */*result_code*/, + krb5_data */*result_code_string*/, + krb5_data */*result_string*/); + +krb5_error_code +krb5_check_transited ( + krb5_context /*context*/, + krb5_const_realm /*client_realm*/, + krb5_const_realm /*server_realm*/, + krb5_realm */*realms*/, + int /*num_realms*/, + int */*bad_realm*/); + +krb5_error_code +krb5_check_transited_realms ( + krb5_context /*context*/, + const char *const */*realms*/, + int /*num_realms*/, + int */*bad_realm*/); + +krb5_boolean +krb5_checksum_is_collision_proof ( + krb5_context /*context*/, + krb5_cksumtype /*type*/); + +krb5_boolean +krb5_checksum_is_keyed ( + krb5_context /*context*/, + krb5_cksumtype /*type*/); + +krb5_error_code +krb5_checksumsize ( + krb5_context /*context*/, + krb5_cksumtype /*type*/, + size_t */*size*/); + +void +krb5_clear_error_string (krb5_context /*context*/); + +krb5_error_code +krb5_closelog ( + krb5_context /*context*/, + krb5_log_facility */*fac*/); + +krb5_boolean +krb5_compare_creds ( + krb5_context /*context*/, + krb5_flags /*whichfields*/, + const krb5_creds */*mcreds*/, + const krb5_creds */*creds*/); + +krb5_error_code +krb5_config_file_free ( + krb5_context /*context*/, + krb5_config_section */*s*/); + +void +krb5_config_free_strings (char **/*strings*/); + +const void * +krb5_config_get ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + int /*type*/, + ...); + +krb5_boolean +krb5_config_get_bool ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + ...); + +krb5_boolean +krb5_config_get_bool_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + krb5_boolean /*def_value*/, + ...); + +int +krb5_config_get_int ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + ...); + +int +krb5_config_get_int_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + int /*def_value*/, + ...); + +const krb5_config_binding * +krb5_config_get_list ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + ...); + +const void * +krb5_config_get_next ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + const krb5_config_binding **/*pointer*/, + int /*type*/, + ...); + +const char * +krb5_config_get_string ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + ...); + +const char * +krb5_config_get_string_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + const char */*def_value*/, + ...); + +char** +krb5_config_get_strings ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + ...); + +int +krb5_config_get_time ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + ...); + +int +krb5_config_get_time_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + int /*def_value*/, + ...); + +krb5_error_code +krb5_config_parse_file ( + krb5_context /*context*/, + const char */*fname*/, + krb5_config_section **/*res*/); + +krb5_error_code +krb5_config_parse_file_multi ( + krb5_context /*context*/, + const char */*fname*/, + krb5_config_section **/*res*/); + +const void * +krb5_config_vget ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + int /*type*/, + va_list /*args*/); + +krb5_boolean +krb5_config_vget_bool ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + va_list /*args*/); + +krb5_boolean +krb5_config_vget_bool_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + krb5_boolean /*def_value*/, + va_list /*args*/); + +int +krb5_config_vget_int ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + va_list /*args*/); + +int +krb5_config_vget_int_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + int /*def_value*/, + va_list /*args*/); + +const krb5_config_binding * +krb5_config_vget_list ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + va_list /*args*/); + +const void * +krb5_config_vget_next ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + const krb5_config_binding **/*pointer*/, + int /*type*/, + va_list /*args*/); + +const char * +krb5_config_vget_string ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + va_list /*args*/); + +const char * +krb5_config_vget_string_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + const char */*def_value*/, + va_list /*args*/); + +char ** +krb5_config_vget_strings ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + va_list /*args*/); + +int +krb5_config_vget_time ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + va_list /*args*/); + +int +krb5_config_vget_time_default ( + krb5_context /*context*/, + const krb5_config_section */*c*/, + int /*def_value*/, + va_list /*args*/); + +krb5_error_code +krb5_copy_address ( + krb5_context /*context*/, + const krb5_address */*inaddr*/, + krb5_address */*outaddr*/); + +krb5_error_code +krb5_copy_addresses ( + krb5_context /*context*/, + const krb5_addresses */*inaddr*/, + krb5_addresses */*outaddr*/); + +krb5_error_code +krb5_copy_creds ( + krb5_context /*context*/, + const krb5_creds */*incred*/, + krb5_creds **/*outcred*/); + +krb5_error_code +krb5_copy_creds_contents ( + krb5_context /*context*/, + const krb5_creds */*incred*/, + krb5_creds */*c*/); + +krb5_error_code +krb5_copy_data ( + krb5_context /*context*/, + const krb5_data */*indata*/, + krb5_data **/*outdata*/); + +krb5_error_code +krb5_copy_host_realm ( + krb5_context /*context*/, + const krb5_realm */*from*/, + krb5_realm **/*to*/); + +krb5_error_code +krb5_copy_keyblock ( + krb5_context /*context*/, + const krb5_keyblock */*inblock*/, + krb5_keyblock **/*to*/); + +krb5_error_code +krb5_copy_keyblock_contents ( + krb5_context /*context*/, + const krb5_keyblock */*inblock*/, + krb5_keyblock */*to*/); + +krb5_error_code +krb5_copy_principal ( + krb5_context /*context*/, + krb5_const_principal /*inprinc*/, + krb5_principal */*outprinc*/); + +krb5_error_code +krb5_copy_ticket ( + krb5_context /*context*/, + const krb5_ticket */*from*/, + krb5_ticket **/*to*/); + +krb5_error_code +krb5_create_checksum ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + krb5_key_usage /*usage*/, + int /*type*/, + void */*data*/, + size_t /*len*/, + Checksum */*result*/); + +krb5_error_code +krb5_crypto_destroy ( + krb5_context /*context*/, + krb5_crypto /*crypto*/); + +krb5_error_code +krb5_crypto_getblocksize ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + size_t */*blocksize*/); + +krb5_error_code +krb5_crypto_init ( + krb5_context /*context*/, + const krb5_keyblock */*key*/, + krb5_enctype /*etype*/, + krb5_crypto */*crypto*/); + +krb5_error_code +krb5_data_alloc ( + krb5_data */*p*/, + int /*len*/); + +krb5_error_code +krb5_data_copy ( + krb5_data */*p*/, + const void */*data*/, + size_t /*len*/); + +void +krb5_data_free (krb5_data */*p*/); + +krb5_error_code +krb5_data_realloc ( + krb5_data */*p*/, + int /*len*/); + +void +krb5_data_zero (krb5_data */*p*/); + +krb5_error_code +krb5_decode_Authenticator ( + krb5_context /*context*/, + const void */*data*/, + size_t /*length*/, + Authenticator */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_decode_ETYPE_INFO ( + krb5_context /*context*/, + const void */*data*/, + size_t /*length*/, + ETYPE_INFO */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_decode_EncAPRepPart ( + krb5_context /*context*/, + const void */*data*/, + size_t /*length*/, + EncAPRepPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_decode_EncASRepPart ( + krb5_context /*context*/, + const void */*data*/, + size_t /*length*/, + EncASRepPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_decode_EncKrbCredPart ( + krb5_context /*context*/, + const void */*data*/, + size_t /*length*/, + EncKrbCredPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_decode_EncTGSRepPart ( + krb5_context /*context*/, + const void */*data*/, + size_t /*length*/, + EncTGSRepPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_decode_EncTicketPart ( + krb5_context /*context*/, + const void */*data*/, + size_t /*length*/, + EncTicketPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_decode_ap_req ( + krb5_context /*context*/, + const krb5_data */*inbuf*/, + krb5_ap_req */*ap_req*/); + +krb5_error_code +krb5_decrypt ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + unsigned /*usage*/, + void */*data*/, + size_t /*len*/, + krb5_data */*result*/); + +krb5_error_code +krb5_decrypt_EncryptedData ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + unsigned /*usage*/, + const EncryptedData */*e*/, + krb5_data */*result*/); + +krb5_error_code +krb5_decrypt_ivec ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + unsigned /*usage*/, + void */*data*/, + size_t /*len*/, + krb5_data */*result*/, + void */*ivec*/); + +krb5_error_code +krb5_decrypt_ticket ( + krb5_context /*context*/, + Ticket */*ticket*/, + krb5_keyblock */*key*/, + EncTicketPart */*out*/, + krb5_flags /*flags*/); + +krb5_error_code +krb5_derive_key ( + krb5_context /*context*/, + const krb5_keyblock */*key*/, + krb5_enctype /*etype*/, + const void */*constant*/, + size_t /*constant_len*/, + krb5_keyblock **/*derived_key*/); + +krb5_error_code +krb5_domain_x500_decode ( + krb5_context /*context*/, + krb5_data /*tr*/, + char ***/*realms*/, + int */*num_realms*/, + const char */*client_realm*/, + const char */*server_realm*/); + +krb5_error_code +krb5_domain_x500_encode ( + char **/*realms*/, + int /*num_realms*/, + krb5_data */*encoding*/); + +krb5_error_code +krb5_eai_to_heim_errno ( + int /*eai_errno*/, + int /*system_error*/); + +krb5_error_code +krb5_encode_Authenticator ( + krb5_context /*context*/, + void */*data*/, + size_t /*length*/, + Authenticator */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_encode_ETYPE_INFO ( + krb5_context /*context*/, + void */*data*/, + size_t /*length*/, + ETYPE_INFO */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_encode_EncAPRepPart ( + krb5_context /*context*/, + void */*data*/, + size_t /*length*/, + EncAPRepPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_encode_EncASRepPart ( + krb5_context /*context*/, + void */*data*/, + size_t /*length*/, + EncASRepPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_encode_EncKrbCredPart ( + krb5_context /*context*/, + void */*data*/, + size_t /*length*/, + EncKrbCredPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_encode_EncTGSRepPart ( + krb5_context /*context*/, + void */*data*/, + size_t /*length*/, + EncTGSRepPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_encode_EncTicketPart ( + krb5_context /*context*/, + void */*data*/, + size_t /*length*/, + EncTicketPart */*t*/, + size_t */*len*/); + +krb5_error_code +krb5_encrypt ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + unsigned /*usage*/, + void */*data*/, + size_t /*len*/, + krb5_data */*result*/); + +krb5_error_code +krb5_encrypt_EncryptedData ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + unsigned /*usage*/, + void */*data*/, + size_t /*len*/, + int /*kvno*/, + EncryptedData */*result*/); + +krb5_error_code +krb5_encrypt_ivec ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + unsigned /*usage*/, + void */*data*/, + size_t /*len*/, + krb5_data */*result*/, + void */*ivec*/); + +krb5_error_code +krb5_enctype_keysize ( + krb5_context /*context*/, + krb5_enctype /*type*/, + size_t */*keysize*/); + +krb5_error_code +krb5_enctype_to_keytype ( + krb5_context /*context*/, + krb5_enctype /*etype*/, + krb5_keytype */*keytype*/); + +krb5_error_code +krb5_enctype_to_string ( + krb5_context /*context*/, + krb5_enctype /*etype*/, + char **/*string*/); + +krb5_error_code +krb5_enctype_valid ( + krb5_context /*context*/, + krb5_enctype /*etype*/); + +krb5_boolean +krb5_enctypes_compatible_keys ( + krb5_context /*context*/, + krb5_enctype /*etype1*/, + krb5_enctype /*etype2*/); + +krb5_error_code +krb5_err ( + krb5_context /*context*/, + int /*eval*/, + krb5_error_code /*code*/, + const char */*fmt*/, + ...) + __attribute__ ((noreturn, format (printf, 4, 5))); + +krb5_error_code +krb5_error_from_rd_error ( + krb5_context /*context*/, + const krb5_error */*error*/, + const krb5_creds */*creds*/); + +krb5_error_code +krb5_errx ( + krb5_context /*context*/, + int /*eval*/, + const char */*fmt*/, + ...) + __attribute__ ((noreturn, format (printf, 3, 4))); + +krb5_error_code +krb5_expand_hostname ( + krb5_context /*context*/, + const char */*orig_hostname*/, + char **/*new_hostname*/); + +krb5_error_code +krb5_expand_hostname_realms ( + krb5_context /*context*/, + const char */*orig_hostname*/, + char **/*new_hostname*/, + char ***/*realms*/); + +PA_DATA * +krb5_find_padata ( + PA_DATA */*val*/, + unsigned /*len*/, + int /*type*/, + int */*index*/); + +krb5_error_code +krb5_format_time ( + krb5_context /*context*/, + time_t /*t*/, + char */*s*/, + size_t /*len*/, + krb5_boolean /*include_time*/); + +krb5_error_code +krb5_free_address ( + krb5_context /*context*/, + krb5_address */*address*/); + +krb5_error_code +krb5_free_addresses ( + krb5_context /*context*/, + krb5_addresses */*addresses*/); + +void +krb5_free_ap_rep_enc_part ( + krb5_context /*context*/, + krb5_ap_rep_enc_part */*val*/); + +void +krb5_free_authenticator ( + krb5_context /*context*/, + krb5_authenticator */*authenticator*/); + +void +krb5_free_config_files (char **/*filenames*/); + +void +krb5_free_context (krb5_context /*context*/); + +krb5_error_code +krb5_free_cred_contents ( + krb5_context /*context*/, + krb5_creds */*c*/); + +krb5_error_code +krb5_free_creds ( + krb5_context /*context*/, + krb5_creds */*c*/); + +krb5_error_code +krb5_free_creds_contents ( + krb5_context /*context*/, + krb5_creds */*c*/); + +void +krb5_free_data ( + krb5_context /*context*/, + krb5_data */*p*/); + +void +krb5_free_data_contents ( + krb5_context /*context*/, + krb5_data */*data*/); + +void +krb5_free_error ( + krb5_context /*context*/, + krb5_error */*error*/); + +void +krb5_free_error_contents ( + krb5_context /*context*/, + krb5_error */*error*/); + +void +krb5_free_error_string ( + krb5_context /*context*/, + char */*str*/); + +krb5_error_code +krb5_free_host_realm ( + krb5_context /*context*/, + krb5_realm */*realmlist*/); + +krb5_error_code +krb5_free_kdc_rep ( + krb5_context /*context*/, + krb5_kdc_rep */*rep*/); + +void +krb5_free_keyblock ( + krb5_context /*context*/, + krb5_keyblock */*keyblock*/); + +void +krb5_free_keyblock_contents ( + krb5_context /*context*/, + krb5_keyblock */*keyblock*/); + +krb5_error_code +krb5_free_krbhst ( + krb5_context /*context*/, + char **/*hostlist*/); + +void +krb5_free_principal ( + krb5_context /*context*/, + krb5_principal /*p*/); + +krb5_error_code +krb5_free_salt ( + krb5_context /*context*/, + krb5_salt /*salt*/); + +krb5_error_code +krb5_free_ticket ( + krb5_context /*context*/, + krb5_ticket */*ticket*/); + +krb5_error_code +krb5_fwd_tgt_creds ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + const char */*hostname*/, + krb5_principal /*client*/, + krb5_principal /*server*/, + krb5_ccache /*ccache*/, + int /*forwardable*/, + krb5_data */*out_data*/); + +void +krb5_generate_random_block ( + void */*buf*/, + size_t /*len*/); + +krb5_error_code +krb5_generate_random_keyblock ( + krb5_context /*context*/, + krb5_enctype /*type*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_generate_seq_number ( + krb5_context /*context*/, + const krb5_keyblock */*key*/, + u_int32_t */*seqno*/); + +krb5_error_code +krb5_generate_subkey ( + krb5_context /*context*/, + const krb5_keyblock */*key*/, + krb5_keyblock **/*subkey*/); + +krb5_error_code +krb5_get_all_client_addrs ( + krb5_context /*context*/, + krb5_addresses */*res*/); + +krb5_error_code +krb5_get_all_server_addrs ( + krb5_context /*context*/, + krb5_addresses */*res*/); + +krb5_error_code +krb5_get_cred_from_kdc ( + krb5_context /*context*/, + krb5_ccache /*ccache*/, + krb5_creds */*in_creds*/, + krb5_creds **/*out_creds*/, + krb5_creds ***/*ret_tgts*/); + +krb5_error_code +krb5_get_cred_from_kdc_opt ( + krb5_context /*context*/, + krb5_ccache /*ccache*/, + krb5_creds */*in_creds*/, + krb5_creds **/*out_creds*/, + krb5_creds ***/*ret_tgts*/, + krb5_flags /*flags*/); + +krb5_error_code +krb5_get_credentials ( + krb5_context /*context*/, + krb5_flags /*options*/, + krb5_ccache /*ccache*/, + krb5_creds */*in_creds*/, + krb5_creds **/*out_creds*/); + +krb5_error_code +krb5_get_credentials_with_flags ( + krb5_context /*context*/, + krb5_flags /*options*/, + krb5_kdc_flags /*flags*/, + krb5_ccache /*ccache*/, + krb5_creds */*in_creds*/, + krb5_creds **/*out_creds*/); + +krb5_error_code +krb5_get_default_config_files (char ***/*pfilenames*/); + +krb5_error_code +krb5_get_default_in_tkt_etypes ( + krb5_context /*context*/, + krb5_enctype **/*etypes*/); + +krb5_error_code +krb5_get_default_principal ( + krb5_context /*context*/, + krb5_principal */*princ*/); + +krb5_error_code +krb5_get_default_realm ( + krb5_context /*context*/, + krb5_realm */*realm*/); + +krb5_error_code +krb5_get_default_realms ( + krb5_context /*context*/, + krb5_realm **/*realms*/); + +const char * +krb5_get_err_text ( + krb5_context /*context*/, + krb5_error_code /*code*/); + +char* +krb5_get_error_string (krb5_context /*context*/); + +krb5_error_code +krb5_get_extra_addresses ( + krb5_context /*context*/, + krb5_addresses */*addresses*/); + +krb5_error_code +krb5_get_fcache_version ( + krb5_context /*context*/, + int */*version*/); + +krb5_error_code +krb5_get_forwarded_creds ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_ccache /*ccache*/, + krb5_flags /*flags*/, + const char */*hostname*/, + krb5_creds */*in_creds*/, + krb5_data */*out_data*/); + +krb5_error_code +krb5_get_host_realm ( + krb5_context /*context*/, + const char */*host*/, + krb5_realm **/*realms*/); + +krb5_error_code +krb5_get_host_realm_int ( + krb5_context /*context*/, + const char */*host*/, + krb5_boolean /*use_dns*/, + krb5_realm **/*realms*/); + +krb5_error_code +krb5_get_ignore_addresses ( + krb5_context /*context*/, + krb5_addresses */*addresses*/); + +krb5_error_code +krb5_get_in_cred ( + krb5_context /*context*/, + krb5_flags /*options*/, + const krb5_addresses */*addrs*/, + const krb5_enctype */*etypes*/, + const krb5_preauthtype */*ptypes*/, + const krb5_preauthdata */*preauth*/, + krb5_key_proc /*key_proc*/, + krb5_const_pointer /*keyseed*/, + krb5_decrypt_proc /*decrypt_proc*/, + krb5_const_pointer /*decryptarg*/, + krb5_creds */*creds*/, + krb5_kdc_rep */*ret_as_reply*/); + +krb5_error_code +krb5_get_in_tkt ( + krb5_context /*context*/, + krb5_flags /*options*/, + const krb5_addresses */*addrs*/, + const krb5_enctype */*etypes*/, + const krb5_preauthtype */*ptypes*/, + krb5_key_proc /*key_proc*/, + krb5_const_pointer /*keyseed*/, + krb5_decrypt_proc /*decrypt_proc*/, + krb5_const_pointer /*decryptarg*/, + krb5_creds */*creds*/, + krb5_ccache /*ccache*/, + krb5_kdc_rep */*ret_as_reply*/); + +krb5_error_code +krb5_get_in_tkt_with_keytab ( + krb5_context /*context*/, + krb5_flags /*options*/, + krb5_addresses */*addrs*/, + const krb5_enctype */*etypes*/, + const krb5_preauthtype */*pre_auth_types*/, + krb5_keytab /*keytab*/, + krb5_ccache /*ccache*/, + krb5_creds */*creds*/, + krb5_kdc_rep */*ret_as_reply*/); + +krb5_error_code +krb5_get_in_tkt_with_password ( + krb5_context /*context*/, + krb5_flags /*options*/, + krb5_addresses */*addrs*/, + const krb5_enctype */*etypes*/, + const krb5_preauthtype */*pre_auth_types*/, + const char */*password*/, + krb5_ccache /*ccache*/, + krb5_creds */*creds*/, + krb5_kdc_rep */*ret_as_reply*/); + +krb5_error_code +krb5_get_in_tkt_with_skey ( + krb5_context /*context*/, + krb5_flags /*options*/, + krb5_addresses */*addrs*/, + const krb5_enctype */*etypes*/, + const krb5_preauthtype */*pre_auth_types*/, + const krb5_keyblock */*key*/, + krb5_ccache /*ccache*/, + krb5_creds */*creds*/, + krb5_kdc_rep */*ret_as_reply*/); + +krb5_error_code +krb5_get_init_creds_keytab ( + krb5_context /*context*/, + krb5_creds */*creds*/, + krb5_principal /*client*/, + krb5_keytab /*keytab*/, + krb5_deltat /*start_time*/, + const char */*in_tkt_service*/, + krb5_get_init_creds_opt */*options*/); + +void +krb5_get_init_creds_opt_init (krb5_get_init_creds_opt */*opt*/); + +void +krb5_get_init_creds_opt_set_address_list ( + krb5_get_init_creds_opt */*opt*/, + krb5_addresses */*addresses*/); + +void +krb5_get_init_creds_opt_set_anonymous ( + krb5_get_init_creds_opt */*opt*/, + int /*anonymous*/); + +void +krb5_get_init_creds_opt_set_default_flags ( + krb5_context /*context*/, + const char */*appname*/, + krb5_const_realm /*realm*/, + krb5_get_init_creds_opt */*opt*/); + +void +krb5_get_init_creds_opt_set_etype_list ( + krb5_get_init_creds_opt */*opt*/, + krb5_enctype */*etype_list*/, + int /*etype_list_length*/); + +void +krb5_get_init_creds_opt_set_forwardable ( + krb5_get_init_creds_opt */*opt*/, + int /*forwardable*/); + +void +krb5_get_init_creds_opt_set_preauth_list ( + krb5_get_init_creds_opt */*opt*/, + krb5_preauthtype */*preauth_list*/, + int /*preauth_list_length*/); + +void +krb5_get_init_creds_opt_set_proxiable ( + krb5_get_init_creds_opt */*opt*/, + int /*proxiable*/); + +void +krb5_get_init_creds_opt_set_renew_life ( + krb5_get_init_creds_opt */*opt*/, + krb5_deltat /*renew_life*/); + +void +krb5_get_init_creds_opt_set_salt ( + krb5_get_init_creds_opt */*opt*/, + krb5_data */*salt*/); + +void +krb5_get_init_creds_opt_set_tkt_life ( + krb5_get_init_creds_opt */*opt*/, + krb5_deltat /*tkt_life*/); + +krb5_error_code +krb5_get_init_creds_password ( + krb5_context /*context*/, + krb5_creds */*creds*/, + krb5_principal /*client*/, + const char */*password*/, + krb5_prompter_fct /*prompter*/, + void */*data*/, + krb5_deltat /*start_time*/, + const char */*in_tkt_service*/, + krb5_get_init_creds_opt */*options*/); + +krb5_error_code +krb5_get_kdc_cred ( + krb5_context /*context*/, + krb5_ccache /*id*/, + krb5_kdc_flags /*flags*/, + krb5_addresses */*addresses*/, + Ticket */*second_ticket*/, + krb5_creds */*in_creds*/, + krb5_creds **out_creds ); + +krb5_error_code +krb5_get_krb524hst ( + krb5_context /*context*/, + const krb5_realm */*realm*/, + char ***/*hostlist*/); + +krb5_error_code +krb5_get_krb_admin_hst ( + krb5_context /*context*/, + const krb5_realm */*realm*/, + char ***/*hostlist*/); + +krb5_error_code +krb5_get_krb_changepw_hst ( + krb5_context /*context*/, + const krb5_realm */*realm*/, + char ***/*hostlist*/); + +krb5_error_code +krb5_get_krbhst ( + krb5_context /*context*/, + const krb5_realm */*realm*/, + char ***/*hostlist*/); + +krb5_error_code +krb5_get_pw_salt ( + krb5_context /*context*/, + krb5_const_principal /*principal*/, + krb5_salt */*salt*/); + +krb5_error_code +krb5_get_server_rcache ( + krb5_context /*context*/, + const krb5_data */*piece*/, + krb5_rcache */*id*/); + +krb5_boolean +krb5_get_use_admin_kdc (krb5_context /*context*/); + +size_t +krb5_get_wrapped_length ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + size_t /*data_len*/); + +int +krb5_getportbyname ( + krb5_context /*context*/, + const char */*service*/, + const char */*proto*/, + int /*default_port*/); + +krb5_error_code +krb5_h_addr2addr ( + krb5_context /*context*/, + int /*af*/, + const char */*haddr*/, + krb5_address */*addr*/); + +krb5_error_code +krb5_h_addr2sockaddr ( + krb5_context /*context*/, + int /*af*/, + const char */*addr*/, + struct sockaddr */*sa*/, + krb5_socklen_t */*sa_size*/, + int /*port*/); + +krb5_error_code +krb5_h_errno_to_heim_errno (int /*eai_errno*/); + +krb5_boolean +krb5_have_error_string (krb5_context /*context*/); + +krb5_error_code +krb5_hmac ( + krb5_context /*context*/, + krb5_cksumtype /*cktype*/, + const void */*data*/, + size_t /*len*/, + unsigned /*usage*/, + krb5_keyblock */*key*/, + Checksum */*result*/); + +krb5_error_code +krb5_init_context (krb5_context */*context*/); + +void +krb5_init_ets (krb5_context /*context*/); + +krb5_error_code +krb5_init_etype ( + krb5_context /*context*/, + unsigned */*len*/, + krb5_enctype **/*val*/, + const krb5_enctype */*etypes*/); + +krb5_error_code +krb5_initlog ( + krb5_context /*context*/, + const char */*program*/, + krb5_log_facility **/*fac*/); + +krb5_error_code +krb5_keyblock_key_proc ( + krb5_context /*context*/, + krb5_keytype /*type*/, + krb5_data */*salt*/, + krb5_const_pointer /*keyseed*/, + krb5_keyblock **/*key*/); + +krb5_error_code +krb5_keytab_key_proc ( + krb5_context /*context*/, + krb5_enctype /*enctype*/, + krb5_salt /*salt*/, + krb5_const_pointer /*keyseed*/, + krb5_keyblock **/*key*/); + +krb5_error_code +krb5_keytype_to_enctypes ( + krb5_context /*context*/, + krb5_keytype /*keytype*/, + unsigned */*len*/, + krb5_enctype **/*val*/); + +krb5_error_code +krb5_keytype_to_enctypes_default ( + krb5_context /*context*/, + krb5_keytype /*keytype*/, + unsigned */*len*/, + krb5_enctype **/*val*/); + +krb5_error_code +krb5_keytype_to_string ( + krb5_context /*context*/, + krb5_keytype /*keytype*/, + char **/*string*/); + +krb5_error_code +krb5_krbhst_format_string ( + krb5_context /*context*/, + const krb5_krbhst_info */*host*/, + char */*hostname*/, + size_t /*hostlen*/); + +void +krb5_krbhst_free ( + krb5_context /*context*/, + krb5_krbhst_handle /*handle*/); + +krb5_error_code +krb5_krbhst_get_addrinfo ( + krb5_context /*context*/, + krb5_krbhst_info */*host*/, + struct addrinfo **/*ai*/); + +krb5_error_code +krb5_krbhst_init ( + krb5_context /*context*/, + const char */*realm*/, + unsigned int /*type*/, + krb5_krbhst_handle */*handle*/); + +krb5_error_code +krb5_krbhst_next ( + krb5_context /*context*/, + krb5_krbhst_handle /*handle*/, + krb5_krbhst_info **/*host*/); + +krb5_error_code +krb5_krbhst_next_as_string ( + krb5_context /*context*/, + krb5_krbhst_handle /*handle*/, + char */*hostname*/, + size_t /*hostlen*/); + +void +krb5_krbhst_reset ( + krb5_context /*context*/, + krb5_krbhst_handle /*handle*/); + +krb5_error_code +krb5_kt_add_entry ( + krb5_context /*context*/, + krb5_keytab /*id*/, + krb5_keytab_entry */*entry*/); + +krb5_error_code +krb5_kt_close ( + krb5_context /*context*/, + krb5_keytab /*id*/); + +krb5_boolean +krb5_kt_compare ( + krb5_context /*context*/, + krb5_keytab_entry */*entry*/, + krb5_const_principal /*principal*/, + krb5_kvno /*vno*/, + krb5_enctype /*enctype*/); + +krb5_error_code +krb5_kt_copy_entry_contents ( + krb5_context /*context*/, + const krb5_keytab_entry */*in*/, + krb5_keytab_entry */*out*/); + +krb5_error_code +krb5_kt_default ( + krb5_context /*context*/, + krb5_keytab */*id*/); + +krb5_error_code +krb5_kt_default_modify_name ( + krb5_context /*context*/, + char */*name*/, + size_t /*namesize*/); + +krb5_error_code +krb5_kt_default_name ( + krb5_context /*context*/, + char */*name*/, + size_t /*namesize*/); + +krb5_error_code +krb5_kt_end_seq_get ( + krb5_context /*context*/, + krb5_keytab /*id*/, + krb5_kt_cursor */*cursor*/); + +krb5_error_code +krb5_kt_free_entry ( + krb5_context /*context*/, + krb5_keytab_entry */*entry*/); + +krb5_error_code +krb5_kt_get_entry ( + krb5_context /*context*/, + krb5_keytab /*id*/, + krb5_const_principal /*principal*/, + krb5_kvno /*kvno*/, + krb5_enctype /*enctype*/, + krb5_keytab_entry */*entry*/); + +krb5_error_code +krb5_kt_get_name ( + krb5_context /*context*/, + krb5_keytab /*keytab*/, + char */*name*/, + size_t /*namesize*/); + +krb5_error_code +krb5_kt_get_type ( + krb5_context /*context*/, + krb5_keytab /*keytab*/, + char */*prefix*/, + size_t /*prefixsize*/); + +krb5_error_code +krb5_kt_next_entry ( + krb5_context /*context*/, + krb5_keytab /*id*/, + krb5_keytab_entry */*entry*/, + krb5_kt_cursor */*cursor*/); + +krb5_error_code +krb5_kt_read_service_key ( + krb5_context /*context*/, + krb5_pointer /*keyprocarg*/, + krb5_principal /*principal*/, + krb5_kvno /*vno*/, + krb5_enctype /*enctype*/, + krb5_keyblock **/*key*/); + +krb5_error_code +krb5_kt_register ( + krb5_context /*context*/, + const krb5_kt_ops */*ops*/); + +krb5_error_code +krb5_kt_remove_entry ( + krb5_context /*context*/, + krb5_keytab /*id*/, + krb5_keytab_entry */*entry*/); + +krb5_error_code +krb5_kt_resolve ( + krb5_context /*context*/, + const char */*name*/, + krb5_keytab */*id*/); + +krb5_error_code +krb5_kt_start_seq_get ( + krb5_context /*context*/, + krb5_keytab /*id*/, + krb5_kt_cursor */*cursor*/); + +krb5_boolean +krb5_kuserok ( + krb5_context /*context*/, + krb5_principal /*principal*/, + const char */*luser*/); + +krb5_error_code +krb5_log ( + krb5_context /*context*/, + krb5_log_facility */*fac*/, + int /*level*/, + const char */*fmt*/, + ...) + __attribute__((format (printf, 4, 5))); + +krb5_error_code +krb5_log_msg ( + krb5_context /*context*/, + krb5_log_facility */*fac*/, + int /*level*/, + char **/*reply*/, + const char */*fmt*/, + ...) + __attribute__((format (printf, 5, 6))); + +krb5_error_code +krb5_make_addrport ( + krb5_context /*context*/, + krb5_address **/*res*/, + const krb5_address */*addr*/, + int16_t /*port*/); + +krb5_error_code +krb5_make_principal ( + krb5_context /*context*/, + krb5_principal */*principal*/, + krb5_const_realm /*realm*/, + ...); + +size_t +krb5_max_sockaddr_size (void); + +krb5_error_code +krb5_mk_error ( + krb5_context /*context*/, + krb5_error_code /*error_code*/, + const char */*e_text*/, + const krb5_data */*e_data*/, + const krb5_principal /*client*/, + const krb5_principal /*server*/, + time_t */*client_time*/, + int */*client_usec*/, + krb5_data */*reply*/); + +krb5_error_code +krb5_mk_priv ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + const krb5_data */*userdata*/, + krb5_data */*outbuf*/, + void */*outdata*/); + +krb5_error_code +krb5_mk_rep ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_data */*outbuf*/); + +krb5_error_code +krb5_mk_req ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + const krb5_flags /*ap_req_options*/, + const char */*service*/, + const char */*hostname*/, + krb5_data */*in_data*/, + krb5_ccache /*ccache*/, + krb5_data */*outbuf*/); + +krb5_error_code +krb5_mk_req_exact ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + const krb5_flags /*ap_req_options*/, + const krb5_principal /*server*/, + krb5_data */*in_data*/, + krb5_ccache /*ccache*/, + krb5_data */*outbuf*/); + +krb5_error_code +krb5_mk_req_extended ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + const krb5_flags /*ap_req_options*/, + krb5_data */*in_data*/, + krb5_creds */*in_creds*/, + krb5_data */*outbuf*/); + +krb5_error_code +krb5_mk_req_internal ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + const krb5_flags /*ap_req_options*/, + krb5_data */*in_data*/, + krb5_creds */*in_creds*/, + krb5_data */*outbuf*/, + krb5_key_usage /*checksum_usage*/, + krb5_key_usage /*encrypt_usage*/); + +krb5_error_code +krb5_mk_safe ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + const krb5_data */*userdata*/, + krb5_data */*outbuf*/, + void */*outdata*/); + +krb5_ssize_t +krb5_net_read ( + krb5_context /*context*/, + void */*p_fd*/, + void */*buf*/, + size_t /*len*/); + +krb5_ssize_t +krb5_net_write ( + krb5_context /*context*/, + void */*p_fd*/, + const void */*buf*/, + size_t /*len*/); + +krb5_error_code +krb5_openlog ( + krb5_context /*context*/, + const char */*program*/, + krb5_log_facility **/*fac*/); + +krb5_error_code +krb5_parse_address ( + krb5_context /*context*/, + const char */*string*/, + krb5_addresses */*addresses*/); + +krb5_error_code +krb5_parse_name ( + krb5_context /*context*/, + const char */*name*/, + krb5_principal */*principal*/); + +const char * +krb5_passwd_result_to_string ( + krb5_context /*context*/, + int /*result*/); + +krb5_error_code +krb5_password_key_proc ( + krb5_context /*context*/, + krb5_enctype /*type*/, + krb5_salt /*salt*/, + krb5_const_pointer /*keyseed*/, + krb5_keyblock **/*key*/); + +krb5_realm* +krb5_princ_realm ( + krb5_context /*context*/, + krb5_principal /*principal*/); + +void +krb5_princ_set_realm ( + krb5_context /*context*/, + krb5_principal /*principal*/, + krb5_realm */*realm*/); + +krb5_error_code +krb5_principal2principalname ( + PrincipalName */*p*/, + const krb5_principal /*from*/); + +krb5_boolean +krb5_principal_compare ( + krb5_context /*context*/, + krb5_const_principal /*princ1*/, + krb5_const_principal /*princ2*/); + +krb5_boolean +krb5_principal_compare_any_realm ( + krb5_context /*context*/, + krb5_const_principal /*princ1*/, + krb5_const_principal /*princ2*/); + +const char * +krb5_principal_get_comp_string ( + krb5_context /*context*/, + krb5_principal /*principal*/, + unsigned int /*component*/); + +const char * +krb5_principal_get_realm ( + krb5_context /*context*/, + krb5_principal /*principal*/); + +int +krb5_principal_get_type ( + krb5_context /*context*/, + krb5_principal /*principal*/); + +krb5_boolean +krb5_principal_match ( + krb5_context /*context*/, + krb5_const_principal /*princ*/, + krb5_const_principal /*pattern*/); + +krb5_error_code +krb5_print_address ( + const krb5_address */*addr*/, + char */*str*/, + size_t /*len*/, + size_t */*ret_len*/); + +int +krb5_program_setup ( + krb5_context */*context*/, + int /*argc*/, + char **/*argv*/, + struct getargs */*args*/, + int /*num_args*/, + void (*/*usage*/)(int, struct getargs*, int)); + +int +krb5_prompter_posix ( + krb5_context /*context*/, + void */*data*/, + const char */*name*/, + const char */*banner*/, + int /*num_prompts*/, + krb5_prompt prompts[]); + +krb5_error_code +krb5_rc_close ( + krb5_context /*context*/, + krb5_rcache /*id*/); + +krb5_error_code +krb5_rc_default ( + krb5_context /*context*/, + krb5_rcache */*id*/); + +const char * +krb5_rc_default_name (krb5_context /*context*/); + +const char * +krb5_rc_default_type (krb5_context /*context*/); + +krb5_error_code +krb5_rc_destroy ( + krb5_context /*context*/, + krb5_rcache /*id*/); + +krb5_error_code +krb5_rc_expunge ( + krb5_context /*context*/, + krb5_rcache /*id*/); + +krb5_error_code +krb5_rc_get_lifespan ( + krb5_context /*context*/, + krb5_rcache /*id*/, + krb5_deltat */*auth_lifespan*/); + +const char* +krb5_rc_get_name ( + krb5_context /*context*/, + krb5_rcache /*id*/); + +const char* +krb5_rc_get_type ( + krb5_context /*context*/, + krb5_rcache /*id*/); + +krb5_error_code +krb5_rc_initialize ( + krb5_context /*context*/, + krb5_rcache /*id*/, + krb5_deltat /*auth_lifespan*/); + +krb5_error_code +krb5_rc_recover ( + krb5_context /*context*/, + krb5_rcache /*id*/); + +krb5_error_code +krb5_rc_resolve ( + krb5_context /*context*/, + krb5_rcache /*id*/, + const char */*name*/); + +krb5_error_code +krb5_rc_resolve_full ( + krb5_context /*context*/, + krb5_rcache */*id*/, + const char */*string_name*/); + +krb5_error_code +krb5_rc_resolve_type ( + krb5_context /*context*/, + krb5_rcache */*id*/, + const char */*type*/); + +krb5_error_code +krb5_rc_store ( + krb5_context /*context*/, + krb5_rcache /*id*/, + krb5_donot_replay */*rep*/); + +krb5_error_code +krb5_rd_cred ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_data */*in_data*/, + krb5_creds ***/*ret_creds*/, + krb5_replay_data */*out_data*/); + +krb5_error_code +krb5_rd_cred2 ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + krb5_ccache /*ccache*/, + krb5_data */*in_data*/); + +krb5_error_code +krb5_rd_error ( + krb5_context /*context*/, + krb5_data */*msg*/, + KRB_ERROR */*result*/); + +krb5_error_code +krb5_rd_priv ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + const krb5_data */*inbuf*/, + krb5_data */*outbuf*/, + void */*outdata*/); + +krb5_error_code +krb5_rd_rep ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + const krb5_data */*inbuf*/, + krb5_ap_rep_enc_part **/*repl*/); + +krb5_error_code +krb5_rd_req ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + const krb5_data */*inbuf*/, + krb5_const_principal /*server*/, + krb5_keytab /*keytab*/, + krb5_flags */*ap_req_options*/, + krb5_ticket **/*ticket*/); + +krb5_error_code +krb5_rd_req_with_keyblock ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + const krb5_data */*inbuf*/, + krb5_const_principal /*server*/, + krb5_keyblock */*keyblock*/, + krb5_flags */*ap_req_options*/, + krb5_ticket **/*ticket*/); + +krb5_error_code +krb5_rd_safe ( + krb5_context /*context*/, + krb5_auth_context /*auth_context*/, + const krb5_data */*inbuf*/, + krb5_data */*outbuf*/, + void */*outdata*/); + +krb5_error_code +krb5_read_message ( + krb5_context /*context*/, + krb5_pointer /*p_fd*/, + krb5_data */*data*/); + +krb5_error_code +krb5_read_priv_message ( + krb5_context /*context*/, + krb5_auth_context /*ac*/, + krb5_pointer /*p_fd*/, + krb5_data */*data*/); + +krb5_error_code +krb5_read_safe_message ( + krb5_context /*context*/, + krb5_auth_context /*ac*/, + krb5_pointer /*p_fd*/, + krb5_data */*data*/); + +krb5_boolean +krb5_realm_compare ( + krb5_context /*context*/, + krb5_const_principal /*princ1*/, + krb5_const_principal /*princ2*/); + +krb5_error_code +krb5_recvauth ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + krb5_pointer /*p_fd*/, + const char */*appl_version*/, + krb5_principal /*server*/, + int32_t /*flags*/, + krb5_keytab /*keytab*/, + krb5_ticket **/*ticket*/); + +krb5_error_code +krb5_recvauth_match_version ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + krb5_pointer /*p_fd*/, + krb5_boolean (*/*match_appl_version*/)(const void *, const char*), + const void */*match_data*/, + krb5_principal /*server*/, + int32_t /*flags*/, + krb5_keytab /*keytab*/, + krb5_ticket **/*ticket*/); + +krb5_error_code +krb5_ret_address ( + krb5_storage */*sp*/, + krb5_address */*adr*/); + +krb5_error_code +krb5_ret_addrs ( + krb5_storage */*sp*/, + krb5_addresses */*adr*/); + +krb5_error_code +krb5_ret_authdata ( + krb5_storage */*sp*/, + krb5_authdata */*auth*/); + +krb5_error_code +krb5_ret_creds ( + krb5_storage */*sp*/, + krb5_creds */*creds*/); + +krb5_error_code +krb5_ret_data ( + krb5_storage */*sp*/, + krb5_data */*data*/); + +krb5_error_code +krb5_ret_int16 ( + krb5_storage */*sp*/, + int16_t */*value*/); + +krb5_error_code +krb5_ret_int32 ( + krb5_storage */*sp*/, + int32_t */*value*/); + +krb5_error_code +krb5_ret_int8 ( + krb5_storage */*sp*/, + int8_t */*value*/); + +krb5_error_code +krb5_ret_keyblock ( + krb5_storage */*sp*/, + krb5_keyblock */*p*/); + +krb5_error_code +krb5_ret_principal ( + krb5_storage */*sp*/, + krb5_principal */*princ*/); + +krb5_error_code +krb5_ret_string ( + krb5_storage */*sp*/, + char **/*string*/); + +krb5_error_code +krb5_ret_stringz ( + krb5_storage */*sp*/, + char **/*string*/); + +krb5_error_code +krb5_ret_times ( + krb5_storage */*sp*/, + krb5_times */*times*/); + +krb5_error_code +krb5_salttype_to_string ( + krb5_context /*context*/, + krb5_enctype /*etype*/, + krb5_salttype /*stype*/, + char **/*string*/); + +krb5_error_code +krb5_sendauth ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + krb5_pointer /*p_fd*/, + const char */*appl_version*/, + krb5_principal /*client*/, + krb5_principal /*server*/, + krb5_flags /*ap_req_options*/, + krb5_data */*in_data*/, + krb5_creds */*in_creds*/, + krb5_ccache /*ccache*/, + krb5_error **/*ret_error*/, + krb5_ap_rep_enc_part **/*rep_result*/, + krb5_creds **/*out_creds*/); + +krb5_error_code +krb5_sendto ( + krb5_context /*context*/, + const krb5_data */*send_data*/, + krb5_krbhst_handle /*handle*/, + krb5_data */*receive*/); + +krb5_error_code +krb5_sendto_kdc ( + krb5_context /*context*/, + const krb5_data */*send_data*/, + const krb5_realm */*realm*/, + krb5_data */*receive*/); + +krb5_error_code +krb5_sendto_kdc2 ( + krb5_context /*context*/, + const krb5_data */*send_data*/, + const krb5_realm */*realm*/, + krb5_data */*receive*/, + krb5_boolean /*master*/); + +krb5_error_code +krb5_set_config_files ( + krb5_context /*context*/, + char **/*filenames*/); + +krb5_error_code +krb5_set_default_in_tkt_etypes ( + krb5_context /*context*/, + const krb5_enctype */*etypes*/); + +krb5_error_code +krb5_set_default_realm ( + krb5_context /*context*/, + const char */*realm*/); + +krb5_error_code +krb5_set_error_string ( + krb5_context /*context*/, + const char */*fmt*/, + ...) + __attribute__((format (printf, 2, 3))); + +krb5_error_code +krb5_set_extra_addresses ( + krb5_context /*context*/, + const krb5_addresses */*addresses*/); + +krb5_error_code +krb5_set_fcache_version ( + krb5_context /*context*/, + int /*version*/); + +krb5_error_code +krb5_set_ignore_addresses ( + krb5_context /*context*/, + const krb5_addresses */*addresses*/); + +void +krb5_set_use_admin_kdc ( + krb5_context /*context*/, + krb5_boolean /*flag*/); + +krb5_error_code +krb5_set_warn_dest ( + krb5_context /*context*/, + krb5_log_facility */*fac*/); + +krb5_error_code +krb5_sname_to_principal ( + krb5_context /*context*/, + const char */*hostname*/, + const char */*sname*/, + int32_t /*type*/, + krb5_principal */*ret_princ*/); + +krb5_error_code +krb5_sock_to_principal ( + krb5_context /*context*/, + int /*sock*/, + const char */*sname*/, + int32_t /*type*/, + krb5_principal */*ret_princ*/); + +krb5_error_code +krb5_sockaddr2address ( + krb5_context /*context*/, + const struct sockaddr */*sa*/, + krb5_address */*addr*/); + +krb5_error_code +krb5_sockaddr2port ( + krb5_context /*context*/, + const struct sockaddr */*sa*/, + int16_t */*port*/); + +krb5_boolean +krb5_sockaddr_uninteresting (const struct sockaddr */*sa*/); + +void +krb5_std_usage ( + int /*code*/, + struct getargs */*args*/, + int /*num_args*/); + +void +krb5_storage_clear_flags ( + krb5_storage */*sp*/, + krb5_flags /*flags*/); + +krb5_storage * +krb5_storage_emem (void); + +krb5_error_code +krb5_storage_free (krb5_storage */*sp*/); + +krb5_storage * +krb5_storage_from_data (krb5_data */*data*/); + +krb5_storage * +krb5_storage_from_fd (int /*fd*/); + +krb5_storage * +krb5_storage_from_mem ( + void */*buf*/, + size_t /*len*/); + +krb5_flags +krb5_storage_get_byteorder ( + krb5_storage */*sp*/, + krb5_flags /*byteorder*/); + +krb5_boolean +krb5_storage_is_flags ( + krb5_storage */*sp*/, + krb5_flags /*flags*/); + +krb5_ssize_t +krb5_storage_read ( + krb5_storage */*sp*/, + void */*buf*/, + size_t /*len*/); + +off_t +krb5_storage_seek ( + krb5_storage */*sp*/, + off_t /*offset*/, + int /*whence*/); + +void +krb5_storage_set_byteorder ( + krb5_storage */*sp*/, + krb5_flags /*byteorder*/); + +void +krb5_storage_set_eof_code ( + krb5_storage */*sp*/, + int /*code*/); + +void +krb5_storage_set_flags ( + krb5_storage */*sp*/, + krb5_flags /*flags*/); + +krb5_error_code +krb5_storage_to_data ( + krb5_storage */*sp*/, + krb5_data */*data*/); + +krb5_ssize_t +krb5_storage_write ( + krb5_storage */*sp*/, + const void */*buf*/, + size_t /*len*/); + +krb5_error_code +krb5_store_address ( + krb5_storage */*sp*/, + krb5_address /*p*/); + +krb5_error_code +krb5_store_addrs ( + krb5_storage */*sp*/, + krb5_addresses /*p*/); + +krb5_error_code +krb5_store_authdata ( + krb5_storage */*sp*/, + krb5_authdata /*auth*/); + +krb5_error_code +krb5_store_creds ( + krb5_storage */*sp*/, + krb5_creds */*creds*/); + +krb5_error_code +krb5_store_data ( + krb5_storage */*sp*/, + krb5_data /*data*/); + +krb5_error_code +krb5_store_int16 ( + krb5_storage */*sp*/, + int16_t /*value*/); + +krb5_error_code +krb5_store_int32 ( + krb5_storage */*sp*/, + int32_t /*value*/); + +krb5_error_code +krb5_store_int8 ( + krb5_storage */*sp*/, + int8_t /*value*/); + +krb5_error_code +krb5_store_keyblock ( + krb5_storage */*sp*/, + krb5_keyblock /*p*/); + +krb5_error_code +krb5_store_principal ( + krb5_storage */*sp*/, + krb5_principal /*p*/); + +krb5_error_code +krb5_store_string ( + krb5_storage */*sp*/, + const char */*s*/); + +krb5_error_code +krb5_store_stringz ( + krb5_storage */*sp*/, + const char */*s*/); + +krb5_error_code +krb5_store_times ( + krb5_storage */*sp*/, + krb5_times /*times*/); + +krb5_error_code +krb5_string_to_deltat ( + const char */*string*/, + krb5_deltat */*deltat*/); + +krb5_error_code +krb5_string_to_enctype ( + krb5_context /*context*/, + const char */*string*/, + krb5_enctype */*etype*/); + +krb5_error_code +krb5_string_to_key ( + krb5_context /*context*/, + krb5_enctype /*enctype*/, + const char */*password*/, + krb5_principal /*principal*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_string_to_key_data ( + krb5_context /*context*/, + krb5_enctype /*enctype*/, + krb5_data /*password*/, + krb5_principal /*principal*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_string_to_key_data_salt ( + krb5_context /*context*/, + krb5_enctype /*enctype*/, + krb5_data /*password*/, + krb5_salt /*salt*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_string_to_key_data_salt_opaque ( + krb5_context /*context*/, + krb5_enctype /*enctype*/, + krb5_data /*password*/, + krb5_salt /*salt*/, + krb5_data /*opaque*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_string_to_key_derived ( + krb5_context /*context*/, + const void */*str*/, + size_t /*len*/, + krb5_enctype /*etype*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_string_to_key_salt ( + krb5_context /*context*/, + krb5_enctype /*enctype*/, + const char */*password*/, + krb5_salt /*salt*/, + krb5_keyblock */*key*/); + +krb5_error_code +krb5_string_to_keytype ( + krb5_context /*context*/, + const char */*string*/, + krb5_keytype */*keytype*/); + +krb5_error_code +krb5_string_to_salttype ( + krb5_context /*context*/, + krb5_enctype /*etype*/, + const char */*string*/, + krb5_salttype */*salttype*/); + +krb5_error_code +krb5_timeofday ( + krb5_context /*context*/, + krb5_timestamp */*timeret*/); + +krb5_error_code +krb5_unparse_name ( + krb5_context /*context*/, + krb5_const_principal /*principal*/, + char **/*name*/); + +krb5_error_code +krb5_unparse_name_fixed ( + krb5_context /*context*/, + krb5_const_principal /*principal*/, + char */*name*/, + size_t /*len*/); + +krb5_error_code +krb5_unparse_name_fixed_short ( + krb5_context /*context*/, + krb5_const_principal /*principal*/, + char */*name*/, + size_t /*len*/); + +krb5_error_code +krb5_unparse_name_short ( + krb5_context /*context*/, + krb5_const_principal /*principal*/, + char **/*name*/); + +krb5_error_code +krb5_us_timeofday ( + krb5_context /*context*/, + int32_t */*sec*/, + int32_t */*usec*/); + +krb5_error_code +krb5_vabort ( + krb5_context /*context*/, + krb5_error_code /*code*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__ ((noreturn, format (printf, 3, 0))); + +krb5_error_code +krb5_vabortx ( + krb5_context /*context*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__ ((noreturn, format (printf, 2, 0))); + +krb5_error_code +krb5_verify_ap_req ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + krb5_ap_req */*ap_req*/, + krb5_const_principal /*server*/, + krb5_keyblock */*keyblock*/, + krb5_flags /*flags*/, + krb5_flags */*ap_req_options*/, + krb5_ticket **/*ticket*/); + +krb5_error_code +krb5_verify_ap_req2 ( + krb5_context /*context*/, + krb5_auth_context */*auth_context*/, + krb5_ap_req */*ap_req*/, + krb5_const_principal /*server*/, + krb5_keyblock */*keyblock*/, + krb5_flags /*flags*/, + krb5_flags */*ap_req_options*/, + krb5_ticket **/*ticket*/, + krb5_key_usage /*usage*/); + +krb5_error_code +krb5_verify_authenticator_checksum ( + krb5_context /*context*/, + krb5_auth_context /*ac*/, + void */*data*/, + size_t /*len*/); + +krb5_error_code +krb5_verify_checksum ( + krb5_context /*context*/, + krb5_crypto /*crypto*/, + krb5_key_usage /*usage*/, + void */*data*/, + size_t /*len*/, + Checksum */*cksum*/); + +krb5_error_code +krb5_verify_init_creds ( + krb5_context /*context*/, + krb5_creds */*creds*/, + krb5_principal /*ap_req_server*/, + krb5_keytab /*ap_req_keytab*/, + krb5_ccache */*ccache*/, + krb5_verify_init_creds_opt */*options*/); + +void +krb5_verify_init_creds_opt_init (krb5_verify_init_creds_opt */*options*/); + +void +krb5_verify_init_creds_opt_set_ap_req_nofail ( + krb5_verify_init_creds_opt */*options*/, + int /*ap_req_nofail*/); + +void +krb5_verify_opt_init (krb5_verify_opt */*opt*/); + +void +krb5_verify_opt_set_ccache ( + krb5_verify_opt */*opt*/, + krb5_ccache /*ccache*/); + +void +krb5_verify_opt_set_flags ( + krb5_verify_opt */*opt*/, + unsigned int /*flags*/); + +void +krb5_verify_opt_set_keytab ( + krb5_verify_opt */*opt*/, + krb5_keytab /*keytab*/); + +void +krb5_verify_opt_set_secure ( + krb5_verify_opt */*opt*/, + krb5_boolean /*secure*/); + +void +krb5_verify_opt_set_service ( + krb5_verify_opt */*opt*/, + const char */*service*/); + +krb5_error_code +krb5_verify_user ( + krb5_context /*context*/, + krb5_principal /*principal*/, + krb5_ccache /*ccache*/, + const char */*password*/, + krb5_boolean /*secure*/, + const char */*service*/); + +krb5_error_code +krb5_verify_user_lrealm ( + krb5_context /*context*/, + krb5_principal /*principal*/, + krb5_ccache /*ccache*/, + const char */*password*/, + krb5_boolean /*secure*/, + const char */*service*/); + +krb5_error_code +krb5_verify_user_opt ( + krb5_context /*context*/, + krb5_principal /*principal*/, + const char */*password*/, + krb5_verify_opt */*opt*/); + +krb5_error_code +krb5_verr ( + krb5_context /*context*/, + int /*eval*/, + krb5_error_code /*code*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__ ((noreturn, format (printf, 4, 0))); + +krb5_error_code +krb5_verrx ( + krb5_context /*context*/, + int /*eval*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__ ((noreturn, format (printf, 3, 0))); + +krb5_error_code +krb5_vlog ( + krb5_context /*context*/, + krb5_log_facility */*fac*/, + int /*level*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__((format (printf, 4, 0))); + +krb5_error_code +krb5_vlog_msg ( + krb5_context /*context*/, + krb5_log_facility */*fac*/, + char **/*reply*/, + int /*level*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__((format (printf, 5, 0))); + +krb5_error_code +krb5_vset_error_string ( + krb5_context /*context*/, + const char */*fmt*/, + va_list /*args*/) + __attribute__ ((format (printf, 2, 0))); + +krb5_error_code +krb5_vwarn ( + krb5_context /*context*/, + krb5_error_code /*code*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__ ((format (printf, 3, 0))); + +krb5_error_code +krb5_vwarnx ( + krb5_context /*context*/, + const char */*fmt*/, + va_list /*ap*/) + __attribute__ ((format (printf, 2, 0))); + +krb5_error_code +krb5_warn ( + krb5_context /*context*/, + krb5_error_code /*code*/, + const char */*fmt*/, + ...) + __attribute__ ((format (printf, 3, 4))); + +krb5_error_code +krb5_warnx ( + krb5_context /*context*/, + const char */*fmt*/, + ...) + __attribute__ ((format (printf, 2, 3))); + +krb5_error_code +krb5_write_message ( + krb5_context /*context*/, + krb5_pointer /*p_fd*/, + krb5_data */*data*/); + +krb5_error_code +krb5_write_priv_message ( + krb5_context /*context*/, + krb5_auth_context /*ac*/, + krb5_pointer /*p_fd*/, + krb5_data */*data*/); + +krb5_error_code +krb5_write_safe_message ( + krb5_context /*context*/, + krb5_auth_context /*ac*/, + krb5_pointer /*p_fd*/, + krb5_data */*data*/); + +krb5_error_code +krb5_xfree (void */*ptr*/); + +krb5_error_code +principalname2krb5_principal ( + krb5_principal */*principal*/, + const PrincipalName /*from*/, + const Realm /*realm*/); + +#endif /* __krb5_protos_h__ */ diff --git a/src/include/krb5-types.h b/src/include/krb5-types.h new file mode 100644 index 0000000..16047f8 --- /dev/null +++ b/src/include/krb5-types.h @@ -0,0 +1,17 @@ +/* krb5-types.h -- this file was generated for i386-unknown-freebsd5.0 by + $Id$ */ + +/* $FreeBSD: src/kerberos5/include/krb5-types.h,v 1.3 2002/08/30 21:33:16 nectar Exp $ */ + +#ifndef __krb5_types_h__ +#define __krb5_types_h__ + +#include +#include +#include + +typedef socklen_t krb5_socklen_t; +#include +typedef ssize_t krb5_ssize_t; + +#endif /* __krb5_types_h__ */ diff --git a/src/include/krb5.h b/src/include/krb5.h new file mode 100644 index 0000000..6a78c7b --- /dev/null +++ b/src/include/krb5.h @@ -0,0 +1,677 @@ +/* + * Copyright (c) 1997 - 2002 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $Id$ */ + +#ifndef __KRB5_H__ +#define __KRB5_H__ + +#include +#include + +#include +#include +#include +#include + +#include + +/* name confusion with MIT */ +#ifndef KRB5KDC_ERR_KEY_EXP +#define KRB5KDC_ERR_KEY_EXP KRB5KDC_ERR_KEY_EXPIRED +#endif + +/* simple constants */ + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +typedef int krb5_boolean; + +typedef int32_t krb5_error_code; + +typedef int krb5_kvno; + +typedef u_int32_t krb5_flags; + +typedef void *krb5_pointer; +typedef const void *krb5_const_pointer; + +typedef octet_string krb5_data; + +struct krb5_crypto_data; +typedef struct krb5_crypto_data *krb5_crypto; + +typedef CKSUMTYPE krb5_cksumtype; + +typedef Checksum krb5_checksum; + +typedef ENCTYPE krb5_enctype; + +/* alternative names */ +enum { + ENCTYPE_NULL = ETYPE_NULL, + ENCTYPE_DES_CBC_CRC = ETYPE_DES_CBC_CRC, + ENCTYPE_DES_CBC_MD4 = ETYPE_DES_CBC_MD4, + ENCTYPE_DES_CBC_MD5 = ETYPE_DES_CBC_MD5, + ENCTYPE_DES3_CBC_MD5 = ETYPE_DES3_CBC_MD5, + ENCTYPE_OLD_DES3_CBC_SHA1 = ETYPE_OLD_DES3_CBC_SHA1, + ENCTYPE_SIGN_DSA_GENERATE = ETYPE_SIGN_DSA_GENERATE, + ENCTYPE_ENCRYPT_RSA_PRIV = ETYPE_ENCRYPT_RSA_PRIV, + ENCTYPE_ENCRYPT_RSA_PUB = ETYPE_ENCRYPT_RSA_PUB, + ENCTYPE_DES3_CBC_SHA1 = ETYPE_DES3_CBC_SHA1, + ENCTYPE_ARCFOUR_HMAC_MD5 = ETYPE_ARCFOUR_HMAC_MD5, + ENCTYPE_ARCFOUR_HMAC_MD5_56 = ETYPE_ARCFOUR_HMAC_MD5_56, + ENCTYPE_ENCTYPE_PK_CROSS = ETYPE_ENCTYPE_PK_CROSS, + ENCTYPE_DES_CBC_NONE = ETYPE_DES_CBC_NONE, + ENCTYPE_DES3_CBC_NONE = ETYPE_DES3_CBC_NONE, + ENCTYPE_DES_CFB64_NONE = ETYPE_DES_CFB64_NONE, + ENCTYPE_DES_PCBC_NONE = ETYPE_DES_PCBC_NONE +}; + +typedef PADATA_TYPE krb5_preauthtype; + +typedef enum krb5_key_usage { + KRB5_KU_PA_ENC_TIMESTAMP = 1, + /* AS-REQ PA-ENC-TIMESTAMP padata timestamp, encrypted with the + client key (section 5.4.1) */ + KRB5_KU_TICKET = 2, + /* AS-REP Ticket and TGS-REP Ticket (includes tgs session key or + application session key), encrypted with the service key + (section 5.4.2) */ + KRB5_KU_AS_REP_ENC_PART = 3, + /* AS-REP encrypted part (includes tgs session key or application + session key), encrypted with the client key (section 5.4.2) */ + KRB5_KU_TGS_REQ_AUTH_DAT_SESSION = 4, + /* TGS-REQ KDC-REQ-BODY AuthorizationData, encrypted with the tgs + session key (section 5.4.1) */ + KRB5_KU_TGS_REQ_AUTH_DAT_SUBKEY = 5, + /* TGS-REQ KDC-REQ-BODY AuthorizationData, encrypted with the tgs + authenticator subkey (section 5.4.1) */ + KRB5_KU_TGS_REQ_AUTH_CKSUM = 6, + /* TGS-REQ PA-TGS-REQ padata AP-REQ Authenticator cksum, keyed + with the tgs session key (sections 5.3.2, 5.4.1) */ + KRB5_KU_TGS_REQ_AUTH = 7, + /* TGS-REQ PA-TGS-REQ padata AP-REQ Authenticator (includes tgs + authenticator subkey), encrypted with the tgs session key + (section 5.3.2) */ + KRB5_KU_TGS_REP_ENC_PART_SESSION = 8, + /* TGS-REP encrypted part (includes application session key), + encrypted with the tgs session key (section 5.4.2) */ + KRB5_KU_TGS_REP_ENC_PART_SUB_KEY = 9, + /* TGS-REP encrypted part (includes application session key), + encrypted with the tgs authenticator subkey (section 5.4.2) */ + KRB5_KU_AP_REQ_AUTH_CKSUM = 10, + /* AP-REQ Authenticator cksum, keyed with the application session + key (section 5.3.2) */ + KRB5_KU_AP_REQ_AUTH = 11, + /* AP-REQ Authenticator (includes application authenticator + subkey), encrypted with the application session key (section + 5.3.2) */ + KRB5_KU_AP_REQ_ENC_PART = 12, + /* AP-REP encrypted part (includes application session subkey), + encrypted with the application session key (section 5.5.2) */ + KRB5_KU_KRB_PRIV = 13, + /* KRB-PRIV encrypted part, encrypted with a key chosen by the + application (section 5.7.1) */ + KRB5_KU_KRB_CRED = 14, + /* KRB-CRED encrypted part, encrypted with a key chosen by the + application (section 5.8.1) */ + KRB5_KU_KRB_SAFE_CKSUM = 15, + /* KRB-SAFE cksum, keyed with a key chosen by the application + (section 5.6.1) */ + KRB5_KU_OTHER_ENCRYPTED = 16, + /* Data which is defined in some specification outside of + Kerberos to be encrypted using an RFC1510 encryption type. */ + KRB5_KU_OTHER_CKSUM = 17, + /* Data which is defined in some specification outside of + Kerberos to be checksummed using an RFC1510 checksum type. */ + KRB5_KU_KRB_ERROR = 18, + /* Krb-error checksum */ + KRB5_KU_AD_KDC_ISSUED = 19, + /* AD-KDCIssued checksum */ + KRB5_KU_MANDATORY_TICKET_EXTENSION = 20, + /* Checksum for Mandatory Ticket Extensions */ + KRB5_KU_AUTH_DATA_TICKET_EXTENSION = 21, + /* Checksum in Authorization Data in Ticket Extensions */ + KRB5_KU_USAGE_SEAL = 22, + /* seal in GSSAPI krb5 mechanism */ + KRB5_KU_USAGE_SIGN = 23, + /* sign in GSSAPI krb5 mechanism */ + KRB5_KU_USAGE_SEQ = 24 + /* SEQ in GSSAPI krb5 mechanism */ +} krb5_key_usage; + +typedef krb5_key_usage krb5_keyusage; + +typedef enum krb5_salttype { + KRB5_PW_SALT = KRB5_PADATA_PW_SALT, + KRB5_AFS3_SALT = KRB5_PADATA_AFS3_SALT +}krb5_salttype; + +typedef struct krb5_salt { + krb5_salttype salttype; + krb5_data saltvalue; +} krb5_salt; + +typedef ETYPE_INFO krb5_preauthinfo; + +typedef struct { + krb5_preauthtype type; + krb5_preauthinfo info; /* list of preauthinfo for this type */ +} krb5_preauthdata_entry; + +typedef struct krb5_preauthdata { + unsigned len; + krb5_preauthdata_entry *val; +}krb5_preauthdata; + +typedef enum krb5_address_type { + KRB5_ADDRESS_INET = 2, + KRB5_ADDRESS_INET6 = 24, + KRB5_ADDRESS_ADDRPORT = 256, + KRB5_ADDRESS_IPPORT = 257 +} krb5_address_type; + +enum { + AP_OPTS_USE_SESSION_KEY = 1, + AP_OPTS_MUTUAL_REQUIRED = 2, + AP_OPTS_USE_SUBKEY = 4 /* library internal */ +}; + +typedef HostAddress krb5_address; + +typedef HostAddresses krb5_addresses; + +typedef enum krb5_keytype { + KEYTYPE_NULL = 0, + KEYTYPE_DES = 1, + KEYTYPE_DES3 = 7, + KEYTYPE_AES128 = 17, + KEYTYPE_AES256 = 18, + KEYTYPE_ARCFOUR = 23, + KEYTYPE_ARCFOUR_56 = 24 +} krb5_keytype; + +typedef EncryptionKey krb5_keyblock; + +typedef AP_REQ krb5_ap_req; + +struct krb5_cc_ops; + +#define KRB5_DEFAULT_CCFILE_ROOT "/tmp/krb5cc_" + +#define KRB5_DEFAULT_CCROOT "FILE:" KRB5_DEFAULT_CCFILE_ROOT + +#define KRB5_ACCEPT_NULL_ADDRESSES(C) \ + krb5_config_get_bool_default((C), NULL, TRUE, \ + "libdefaults", "accept_null_addresses", \ + NULL) + +typedef void *krb5_cc_cursor; + +typedef struct krb5_ccache_data { + const struct krb5_cc_ops *ops; + krb5_data data; +}krb5_ccache_data; + +typedef struct krb5_ccache_data *krb5_ccache; + +typedef struct krb5_context_data *krb5_context; + +typedef Realm krb5_realm; +typedef const char *krb5_const_realm; /* stupid language */ + +#define krb5_realm_length(r) strlen(r) +#define krb5_realm_data(r) (r) + +typedef Principal krb5_principal_data; +typedef struct Principal *krb5_principal; +typedef const struct Principal *krb5_const_principal; + +typedef time_t krb5_deltat; +typedef time_t krb5_timestamp; + +typedef struct krb5_times { + krb5_timestamp authtime; + krb5_timestamp starttime; + krb5_timestamp endtime; + krb5_timestamp renew_till; +} krb5_times; + +typedef union { + TicketFlags b; + krb5_flags i; +} krb5_ticket_flags; + +/* options for krb5_get_in_tkt() */ +#define KDC_OPT_FORWARDABLE (1 << 1) +#define KDC_OPT_FORWARDED (1 << 2) +#define KDC_OPT_PROXIABLE (1 << 3) +#define KDC_OPT_PROXY (1 << 4) +#define KDC_OPT_ALLOW_POSTDATE (1 << 5) +#define KDC_OPT_POSTDATED (1 << 6) +#define KDC_OPT_RENEWABLE (1 << 8) +#define KDC_OPT_REQUEST_ANONYMOUS (1 << 14) +#define KDC_OPT_DISABLE_TRANSITED_CHECK (1 << 26) +#define KDC_OPT_RENEWABLE_OK (1 << 27) +#define KDC_OPT_ENC_TKT_IN_SKEY (1 << 28) +#define KDC_OPT_RENEW (1 << 30) +#define KDC_OPT_VALIDATE (1 << 31) + +typedef union { + KDCOptions b; + krb5_flags i; +} krb5_kdc_flags; + +/* flags for krb5_verify_ap_req */ + +#define KRB5_VERIFY_AP_REQ_IGNORE_INVALID (1 << 0) + +#define KRB5_GC_CACHED (1U << 0) +#define KRB5_GC_USER_USER (1U << 1) + +/* constants for compare_creds (and cc_retrieve_cred) */ +#define KRB5_TC_DONT_MATCH_REALM (1U << 31) +#define KRB5_TC_MATCH_KEYTYPE (1U << 30) + +typedef AuthorizationData krb5_authdata; + +typedef KRB_ERROR krb5_error; + +typedef struct krb5_creds { + krb5_principal client; + krb5_principal server; + krb5_keyblock session; + krb5_times times; + krb5_data ticket; + krb5_data second_ticket; + krb5_authdata authdata; + krb5_addresses addresses; + krb5_ticket_flags flags; +} krb5_creds; + +typedef struct krb5_cc_ops { + const char *prefix; + const char* (*get_name)(krb5_context, krb5_ccache); + krb5_error_code (*resolve)(krb5_context, krb5_ccache *, const char *); + krb5_error_code (*gen_new)(krb5_context, krb5_ccache *); + krb5_error_code (*init)(krb5_context, krb5_ccache, krb5_principal); + krb5_error_code (*destroy)(krb5_context, krb5_ccache); + krb5_error_code (*close)(krb5_context, krb5_ccache); + krb5_error_code (*store)(krb5_context, krb5_ccache, krb5_creds*); + krb5_error_code (*retrieve)(krb5_context, krb5_ccache, + krb5_flags, krb5_creds*, krb5_creds); + krb5_error_code (*get_princ)(krb5_context, krb5_ccache, krb5_principal*); + krb5_error_code (*get_first)(krb5_context, krb5_ccache, krb5_cc_cursor *); + krb5_error_code (*get_next)(krb5_context, krb5_ccache, + krb5_cc_cursor*, krb5_creds*); + krb5_error_code (*end_get)(krb5_context, krb5_ccache, krb5_cc_cursor*); + krb5_error_code (*remove_cred)(krb5_context, krb5_ccache, + krb5_flags, krb5_creds*); + krb5_error_code (*set_flags)(krb5_context, krb5_ccache, krb5_flags); + int (*get_version)(krb5_context, krb5_ccache); +} krb5_cc_ops; + +struct krb5_log_facility; + +struct krb5_config_binding { + enum { krb5_config_string, krb5_config_list } type; + char *name; + struct krb5_config_binding *next; + union { + char *string; + struct krb5_config_binding *list; + void *generic; + } u; +}; + +typedef struct krb5_config_binding krb5_config_binding; + +typedef krb5_config_binding krb5_config_section; + +typedef struct krb5_context_data { + krb5_enctype *etypes; + krb5_enctype *etypes_des; + char **default_realms; + time_t max_skew; + time_t kdc_timeout; + unsigned max_retries; + int32_t kdc_sec_offset; + int32_t kdc_usec_offset; + krb5_config_section *cf; + struct et_list *et_list; + struct krb5_log_facility *warn_dest; + krb5_cc_ops *cc_ops; + int num_cc_ops; + const char *http_proxy; + const char *time_fmt; + krb5_boolean log_utc; + const char *default_keytab; + const char *default_keytab_modify; + krb5_boolean use_admin_kdc; + krb5_addresses *extra_addresses; + krb5_boolean scan_interfaces; /* `ifconfig -a' */ + krb5_boolean srv_lookup; /* do SRV lookups */ + krb5_boolean srv_try_txt; /* try TXT records also */ + int32_t fcache_vno; /* create cache files w/ this + version */ + int num_kt_types; /* # of registered keytab types */ + struct krb5_keytab_data *kt_types; /* registered keytab types */ + const char *date_fmt; + char *error_string; + char error_buf[256]; + krb5_addresses *ignore_addresses; + char *default_cc_name; +} krb5_context_data; + +typedef struct krb5_ticket { + EncTicketPart ticket; + krb5_principal client; + krb5_principal server; +} krb5_ticket; + +typedef Authenticator krb5_authenticator_data; + +typedef krb5_authenticator_data *krb5_authenticator; + +struct krb5_rcache_data; +typedef struct krb5_rcache_data *krb5_rcache; +typedef Authenticator krb5_donot_replay; + +#define KRB5_STORAGE_HOST_BYTEORDER 0x01 /* old */ +#define KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS 0x02 +#define KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE 0x04 +#define KRB5_STORAGE_KEYBLOCK_KEYTYPE_TWICE 0x08 +#define KRB5_STORAGE_BYTEORDER_MASK 0x60 +#define KRB5_STORAGE_BYTEORDER_BE 0x00 /* default */ +#define KRB5_STORAGE_BYTEORDER_LE 0x20 +#define KRB5_STORAGE_BYTEORDER_HOST 0x40 + +struct krb5_storage_data; +typedef struct krb5_storage_data krb5_storage; + +typedef struct krb5_keytab_entry { + krb5_principal principal; + krb5_kvno vno; + krb5_keyblock keyblock; + u_int32_t timestamp; +} krb5_keytab_entry; + +typedef struct krb5_kt_cursor { + int fd; + krb5_storage *sp; + void *data; +} krb5_kt_cursor; + +struct krb5_keytab_data; + +typedef struct krb5_keytab_data *krb5_keytab; + +#define KRB5_KT_PREFIX_MAX_LEN 30 + +struct krb5_keytab_data { + const char *prefix; + krb5_error_code (*resolve)(krb5_context, const char*, krb5_keytab); + krb5_error_code (*get_name)(krb5_context, krb5_keytab, char*, size_t); + krb5_error_code (*close)(krb5_context, krb5_keytab); + krb5_error_code (*get)(krb5_context, krb5_keytab, krb5_const_principal, + krb5_kvno, krb5_enctype, krb5_keytab_entry*); + krb5_error_code (*start_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*); + krb5_error_code (*next_entry)(krb5_context, krb5_keytab, + krb5_keytab_entry*, krb5_kt_cursor*); + krb5_error_code (*end_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*); + krb5_error_code (*add)(krb5_context, krb5_keytab, krb5_keytab_entry*); + krb5_error_code (*remove)(krb5_context, krb5_keytab, krb5_keytab_entry*); + void *data; + int32_t version; +}; + +typedef struct krb5_keytab_data krb5_kt_ops; + +struct krb5_keytab_key_proc_args { + krb5_keytab keytab; + krb5_principal principal; +}; + +typedef struct krb5_keytab_key_proc_args krb5_keytab_key_proc_args; + +typedef struct krb5_replay_data { + krb5_timestamp timestamp; + u_int32_t usec; + u_int32_t seq; +} krb5_replay_data; + +/* flags for krb5_auth_con_setflags */ +enum { + KRB5_AUTH_CONTEXT_DO_TIME = 1, + KRB5_AUTH_CONTEXT_RET_TIME = 2, + KRB5_AUTH_CONTEXT_DO_SEQUENCE = 4, + KRB5_AUTH_CONTEXT_RET_SEQUENCE = 8, + KRB5_AUTH_CONTEXT_PERMIT_ALL = 16 +}; + +/* flags for krb5_auth_con_genaddrs */ +enum { + KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR = 1, + KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR = 3, + KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR = 4, + KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR = 12 +}; + +typedef struct krb5_auth_context_data { + unsigned int flags; + + krb5_address *local_address; + krb5_address *remote_address; + int16_t local_port; + int16_t remote_port; + krb5_keyblock *keyblock; + krb5_keyblock *local_subkey; + krb5_keyblock *remote_subkey; + + u_int32_t local_seqnumber; + u_int32_t remote_seqnumber; + + krb5_authenticator authenticator; + + krb5_pointer i_vector; + + krb5_rcache rcache; + + krb5_keytype keytype; /* �requested key type ? */ + krb5_cksumtype cksumtype; /* �requested checksum type! */ + +}krb5_auth_context_data, *krb5_auth_context; + +typedef struct { + KDC_REP kdc_rep; + EncKDCRepPart enc_part; + KRB_ERROR error; +} krb5_kdc_rep; + +extern const char *heimdal_version, *heimdal_long_version; + +typedef void (*krb5_log_log_func_t)(const char*, const char*, void*); +typedef void (*krb5_log_close_func_t)(void*); + +typedef struct krb5_log_facility { + const char *program; + int len; + struct facility *val; +} krb5_log_facility; + +typedef EncAPRepPart krb5_ap_rep_enc_part; + +#define KRB5_RECVAUTH_IGNORE_VERSION 1 + +#define KRB5_SENDAUTH_VERSION "KRB5_SENDAUTH_V1.0" + +#define KRB5_TGS_NAME_SIZE (6) +#define KRB5_TGS_NAME ("krbtgt") + +/* variables */ + +extern const char *krb5_config_file; +extern const char *krb5_defkeyname; + +typedef enum { + KRB5_PROMPT_TYPE_PASSWORD = 0x1, + KRB5_PROMPT_TYPE_NEW_PASSWORD = 0x2, + KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN = 0x3, + KRB5_PROMPT_TYPE_PREAUTH = 0x4 +} krb5_prompt_type; + +typedef struct _krb5_prompt { + const char *prompt; + int hidden; + krb5_data *reply; + krb5_prompt_type type; +} krb5_prompt; + +typedef int (*krb5_prompter_fct)(krb5_context context, + void *data, + const char *name, + const char *banner, + int num_prompts, + krb5_prompt prompts[]); + +typedef krb5_error_code (*krb5_key_proc)(krb5_context context, + krb5_enctype type, + krb5_salt salt, + krb5_const_pointer keyseed, + krb5_keyblock **key); +typedef krb5_error_code (*krb5_decrypt_proc)(krb5_context context, + krb5_keyblock *key, + krb5_key_usage usage, + krb5_const_pointer decrypt_arg, + krb5_kdc_rep *dec_rep); + + +typedef struct _krb5_get_init_creds_opt { + krb5_flags flags; + krb5_deltat tkt_life; + krb5_deltat renew_life; + int forwardable; + int proxiable; + int anonymous; + krb5_enctype *etype_list; + int etype_list_length; + krb5_addresses *address_list; +#if 0 /* this is the MIT-way */ + krb5_address **address_list; +#endif + /* XXX the next three should not be used, as they may be + removed later */ + krb5_preauthtype *preauth_list; + int preauth_list_length; + krb5_data *salt; +} krb5_get_init_creds_opt; + +#define KRB5_GET_INIT_CREDS_OPT_TKT_LIFE 0x0001 +#define KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE 0x0002 +#define KRB5_GET_INIT_CREDS_OPT_FORWARDABLE 0x0004 +#define KRB5_GET_INIT_CREDS_OPT_PROXIABLE 0x0008 +#define KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST 0x0010 +#define KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST 0x0020 +#define KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST 0x0040 +#define KRB5_GET_INIT_CREDS_OPT_SALT 0x0080 +#define KRB5_GET_INIT_CREDS_OPT_ANONYMOUS 0x0100 + +typedef struct _krb5_verify_init_creds_opt { + krb5_flags flags; + int ap_req_nofail; +} krb5_verify_init_creds_opt; + +#define KRB5_VERIFY_INIT_CREDS_OPT_AP_REQ_NOFAIL 0x0001 + +typedef struct krb5_verify_opt { + unsigned int flags; + krb5_ccache ccache; + krb5_keytab keytab; + krb5_boolean secure; + const char *service; +} krb5_verify_opt; + +#define KRB5_VERIFY_LREALMS 1 +#define KRB5_VERIFY_NO_ADDRESSES 2 + +extern const krb5_cc_ops krb5_fcc_ops; +extern const krb5_cc_ops krb5_mcc_ops; + +extern const krb5_kt_ops krb5_fkt_ops; +extern const krb5_kt_ops krb5_mkt_ops; +extern const krb5_kt_ops krb5_akf_ops; +extern const krb5_kt_ops krb4_fkt_ops; +extern const krb5_kt_ops krb5_srvtab_fkt_ops; +extern const krb5_kt_ops krb5_any_ops; + +#define KRB5_KPASSWD_SUCCESS 0 +#define KRB5_KPASSWD_MALFORMED 1 +#define KRB5_KPASSWD_HARDERROR 2 +#define KRB5_KPASSWD_AUTHERROR 3 +#define KRB5_KPASSWD_SOFTERROR 4 + +#define KPASSWD_PORT 464 + +/* types for the new krbhst interface */ +struct krb5_krbhst_data; +typedef struct krb5_krbhst_data *krb5_krbhst_handle; + +#define KRB5_KRBHST_KDC 1 +#define KRB5_KRBHST_ADMIN 2 +#define KRB5_KRBHST_CHANGEPW 3 +#define KRB5_KRBHST_KRB524 4 + +typedef struct krb5_krbhst_info { + enum { KRB5_KRBHST_UDP, + KRB5_KRBHST_TCP, + KRB5_KRBHST_HTTP } proto; + unsigned short port; + unsigned short def_port; + struct addrinfo *ai; + struct krb5_krbhst_info *next; + char hostname[1]; /* has to come last */ +} krb5_krbhst_info; + + +struct credentials; /* this is to keep the compiler happy */ +struct getargs; +struct sockaddr; + +#include + +#endif /* __KRB5_H__ */ + diff --git a/src/include/krb5_asn1.h b/src/include/krb5_asn1.h new file mode 100644 index 0000000..f660269 --- /dev/null +++ b/src/include/krb5_asn1.h @@ -0,0 +1,1279 @@ +/* Generated from /usr/src/kerberos5/lib/libasn1/../../../crypto/heimdal/lib/asn1/k5.asn1 */ +/* Do not edit */ + +#ifndef __krb5_asn1_h__ +#define __krb5_asn1_h__ + +#include +#include + +#ifndef __asn1_common_definitions__ +#define __asn1_common_definitions__ + +typedef struct octet_string { + size_t length; + void *data; +} octet_string; + +typedef char *general_string; + +typedef struct oid { + size_t length; + unsigned *components; +} oid; + +#define ASN1_MALLOC_ENCODE(T, B, BL, S, L, R) \ + do { \ + (BL) = length_##T((S)); \ + (B) = malloc((BL)); \ + if((B) == NULL) { \ + (R) = ENOMEM; \ + } else { \ + (R) = encode_##T(((unsigned char*)(B)) + (BL) - 1, (BL), \ + (S), (L)); \ + if((R) != 0) { \ + free((B)); \ + (B) = NULL; \ + } \ + } \ + } while (0) + +#endif + +/* +NAME-TYPE ::= INTEGER +*/ + +typedef enum NAME_TYPE { + KRB5_NT_UNKNOWN = 0, + KRB5_NT_PRINCIPAL = 1, + KRB5_NT_SRV_INST = 2, + KRB5_NT_SRV_HST = 3, + KRB5_NT_SRV_XHST = 4, + KRB5_NT_UID = 5, + KRB5_NT_X500_PRINCIPAL = 6 +} NAME_TYPE; + +int encode_NAME_TYPE(unsigned char *, size_t, const NAME_TYPE *, size_t *); +int decode_NAME_TYPE(const unsigned char *, size_t, NAME_TYPE *, size_t *); +void free_NAME_TYPE (NAME_TYPE *); +size_t length_NAME_TYPE(const NAME_TYPE *); +int copy_NAME_TYPE (const NAME_TYPE *, NAME_TYPE *); + + +/* +MESSAGE-TYPE ::= INTEGER +*/ + +typedef enum MESSAGE_TYPE { + krb_as_req = 10, + krb_as_rep = 11, + krb_tgs_req = 12, + krb_tgs_rep = 13, + krb_ap_req = 14, + krb_ap_rep = 15, + krb_safe = 20, + krb_priv = 21, + krb_cred = 22, + krb_error = 30 +} MESSAGE_TYPE; + +int encode_MESSAGE_TYPE(unsigned char *, size_t, const MESSAGE_TYPE *, size_t *); +int decode_MESSAGE_TYPE(const unsigned char *, size_t, MESSAGE_TYPE *, size_t *); +void free_MESSAGE_TYPE (MESSAGE_TYPE *); +size_t length_MESSAGE_TYPE(const MESSAGE_TYPE *); +int copy_MESSAGE_TYPE (const MESSAGE_TYPE *, MESSAGE_TYPE *); + + +/* +PADATA-TYPE ::= INTEGER +*/ + +typedef enum PADATA_TYPE { + KRB5_PADATA_NONE = 0, + KRB5_PADATA_TGS_REQ = 1, + KRB5_PADATA_AP_REQ = 1, + KRB5_PADATA_ENC_TIMESTAMP = 2, + KRB5_PADATA_PW_SALT = 3, + KRB5_PADATA_ENC_UNIX_TIME = 5, + KRB5_PADATA_SANDIA_SECUREID = 6, + KRB5_PADATA_SESAME = 7, + KRB5_PADATA_OSF_DCE = 8, + KRB5_PADATA_CYBERSAFE_SECUREID = 9, + KRB5_PADATA_AFS3_SALT = 10, + KRB5_PADATA_ETYPE_INFO = 11, + KRB5_PADATA_SAM_CHALLENGE = 12, + KRB5_PADATA_SAM_RESPONSE = 13, + KRB5_PADATA_PK_AS_REQ = 14, + KRB5_PADATA_PK_AS_REP = 15, + KRB5_PADATA_PK_AS_SIGN = 16, + KRB5_PADATA_PK_KEY_REQ = 17, + KRB5_PADATA_PK_KEY_REP = 18, + KRB5_PADATA_USE_SPECIFIED_KVNO = 20, + KRB5_PADATA_SAM_REDIRECT = 21, + KRB5_PADATA_GET_FROM_TYPED_DATA = 22, + KRB5_PADATA_SAM_ETYPE_INFO = 23 +} PADATA_TYPE; + +int encode_PADATA_TYPE(unsigned char *, size_t, const PADATA_TYPE *, size_t *); +int decode_PADATA_TYPE(const unsigned char *, size_t, PADATA_TYPE *, size_t *); +void free_PADATA_TYPE (PADATA_TYPE *); +size_t length_PADATA_TYPE(const PADATA_TYPE *); +int copy_PADATA_TYPE (const PADATA_TYPE *, PADATA_TYPE *); + + +/* +CKSUMTYPE ::= INTEGER +*/ + +typedef enum CKSUMTYPE { + CKSUMTYPE_NONE = 0, + CKSUMTYPE_CRC32 = 1, + CKSUMTYPE_RSA_MD4 = 2, + CKSUMTYPE_RSA_MD4_DES = 3, + CKSUMTYPE_DES_MAC = 4, + CKSUMTYPE_DES_MAC_K = 5, + CKSUMTYPE_RSA_MD4_DES_K = 6, + CKSUMTYPE_RSA_MD5 = 7, + CKSUMTYPE_RSA_MD5_DES = 8, + CKSUMTYPE_RSA_MD5_DES3 = 9, + CKSUMTYPE_HMAC_SHA1_96_AES_128 = 10, + CKSUMTYPE_HMAC_SHA1_96_AES_256 = 11, + CKSUMTYPE_HMAC_SHA1_DES3 = 12, + CKSUMTYPE_SHA1 = 1000, + CKSUMTYPE_GSSAPI = 32771, + CKSUMTYPE_HMAC_MD5 = -138, + CKSUMTYPE_HMAC_MD5_ENC = -1138 +} CKSUMTYPE; + +int encode_CKSUMTYPE(unsigned char *, size_t, const CKSUMTYPE *, size_t *); +int decode_CKSUMTYPE(const unsigned char *, size_t, CKSUMTYPE *, size_t *); +void free_CKSUMTYPE (CKSUMTYPE *); +size_t length_CKSUMTYPE(const CKSUMTYPE *); +int copy_CKSUMTYPE (const CKSUMTYPE *, CKSUMTYPE *); + + +/* +ENCTYPE ::= INTEGER +*/ + +typedef enum ENCTYPE { + ETYPE_NULL = 0, + ETYPE_DES_CBC_CRC = 1, + ETYPE_DES_CBC_MD4 = 2, + ETYPE_DES_CBC_MD5 = 3, + ETYPE_DES3_CBC_MD5 = 5, + ETYPE_OLD_DES3_CBC_SHA1 = 7, + ETYPE_SIGN_DSA_GENERATE = 8, + ETYPE_ENCRYPT_RSA_PRIV = 9, + ETYPE_ENCRYPT_RSA_PUB = 10, + ETYPE_DES3_CBC_SHA1 = 16, + ETYPE_AES128_CTS_HMAC_SHA1_96 = 17, + ETYPE_AES256_CTS_HMAC_SHA1_96 = 18, + ETYPE_ARCFOUR_HMAC_MD5 = 23, + ETYPE_ARCFOUR_HMAC_MD5_56 = 24, + ETYPE_ENCTYPE_PK_CROSS = 48, + ETYPE_DES_CBC_NONE = -4096, + ETYPE_DES3_CBC_NONE = -4097, + ETYPE_DES_CFB64_NONE = -4098, + ETYPE_DES_PCBC_NONE = -4099 +} ENCTYPE; + +int encode_ENCTYPE(unsigned char *, size_t, const ENCTYPE *, size_t *); +int decode_ENCTYPE(const unsigned char *, size_t, ENCTYPE *, size_t *); +void free_ENCTYPE (ENCTYPE *); +size_t length_ENCTYPE(const ENCTYPE *); +int copy_ENCTYPE (const ENCTYPE *, ENCTYPE *); + + +/* +UNSIGNED ::= UNSIGNED INTEGER +*/ + +typedef unsigned int UNSIGNED; + +int encode_UNSIGNED(unsigned char *, size_t, const UNSIGNED *, size_t *); +int decode_UNSIGNED(const unsigned char *, size_t, UNSIGNED *, size_t *); +void free_UNSIGNED (UNSIGNED *); +size_t length_UNSIGNED(const UNSIGNED *); +int copy_UNSIGNED (const UNSIGNED *, UNSIGNED *); + + +/* +Realm ::= GeneralString +*/ + +typedef general_string Realm; + +int encode_Realm(unsigned char *, size_t, const Realm *, size_t *); +int decode_Realm(const unsigned char *, size_t, Realm *, size_t *); +void free_Realm (Realm *); +size_t length_Realm(const Realm *); +int copy_Realm (const Realm *, Realm *); + + +/* +PrincipalName ::= SEQUENCE { + name-type[0] NAME-TYPE, + name-string[1] SEQUENCE OF GeneralString +} +*/ + +typedef struct PrincipalName { + NAME_TYPE name_type; + struct { + unsigned int len; + general_string *val; + } name_string; +} PrincipalName; + +int encode_PrincipalName(unsigned char *, size_t, const PrincipalName *, size_t *); +int decode_PrincipalName(const unsigned char *, size_t, PrincipalName *, size_t *); +void free_PrincipalName (PrincipalName *); +size_t length_PrincipalName(const PrincipalName *); +int copy_PrincipalName (const PrincipalName *, PrincipalName *); + + +/* +Principal ::= SEQUENCE { + name[0] PrincipalName, + realm[1] Realm +} +*/ + +typedef struct Principal { + PrincipalName name; + Realm realm; +} Principal; + +int encode_Principal(unsigned char *, size_t, const Principal *, size_t *); +int decode_Principal(const unsigned char *, size_t, Principal *, size_t *); +void free_Principal (Principal *); +size_t length_Principal(const Principal *); +int copy_Principal (const Principal *, Principal *); + + +/* +HostAddress ::= SEQUENCE { + addr-type[0] INTEGER, + address[1] OCTET STRING +} +*/ + +typedef struct HostAddress { + int addr_type; + octet_string address; +} HostAddress; + +int encode_HostAddress(unsigned char *, size_t, const HostAddress *, size_t *); +int decode_HostAddress(const unsigned char *, size_t, HostAddress *, size_t *); +void free_HostAddress (HostAddress *); +size_t length_HostAddress(const HostAddress *); +int copy_HostAddress (const HostAddress *, HostAddress *); + + +/* +HostAddresses ::= SEQUENCE OF HostAddress +*/ + +typedef struct HostAddresses { + unsigned int len; + HostAddress *val; +} HostAddresses; + +int encode_HostAddresses(unsigned char *, size_t, const HostAddresses *, size_t *); +int decode_HostAddresses(const unsigned char *, size_t, HostAddresses *, size_t *); +void free_HostAddresses (HostAddresses *); +size_t length_HostAddresses(const HostAddresses *); +int copy_HostAddresses (const HostAddresses *, HostAddresses *); + + +/* +KerberosTime ::= GeneralizedTime +*/ + +typedef time_t KerberosTime; + +int encode_KerberosTime(unsigned char *, size_t, const KerberosTime *, size_t *); +int decode_KerberosTime(const unsigned char *, size_t, KerberosTime *, size_t *); +void free_KerberosTime (KerberosTime *); +size_t length_KerberosTime(const KerberosTime *); +int copy_KerberosTime (const KerberosTime *, KerberosTime *); + + +/* +AuthorizationData ::= SEQUENCE OF SEQUENCE { + ad-type[0] INTEGER, + ad-data[1] OCTET STRING +} +*/ + +typedef struct AuthorizationData { + unsigned int len; + struct { + int ad_type; + octet_string ad_data; + } *val; +} AuthorizationData; + +int encode_AuthorizationData(unsigned char *, size_t, const AuthorizationData *, size_t *); +int decode_AuthorizationData(const unsigned char *, size_t, AuthorizationData *, size_t *); +void free_AuthorizationData (AuthorizationData *); +size_t length_AuthorizationData(const AuthorizationData *); +int copy_AuthorizationData (const AuthorizationData *, AuthorizationData *); + + +/* +APOptions ::= BIT STRING { + reserved(0), + use-session-key(1), + mutual-required(2) +} +*/ + +typedef struct APOptions { + unsigned int reserved:1; + unsigned int use_session_key:1; + unsigned int mutual_required:1; +} APOptions; + + +int encode_APOptions(unsigned char *, size_t, const APOptions *, size_t *); +int decode_APOptions(const unsigned char *, size_t, APOptions *, size_t *); +void free_APOptions (APOptions *); +size_t length_APOptions(const APOptions *); +int copy_APOptions (const APOptions *, APOptions *); +unsigned APOptions2int(APOptions); +APOptions int2APOptions(unsigned); +extern struct units APOptions_units[]; + +/* +TicketFlags ::= BIT STRING { + reserved(0), + forwardable(1), + forwarded(2), + proxiable(3), + proxy(4), + may-postdate(5), + postdated(6), + invalid(7), + renewable(8), + initial(9), + pre-authent(10), + hw-authent(11), + transited-policy-checked(12), + ok-as-delegate(13), + anonymous(14) +} +*/ + +typedef struct TicketFlags { + unsigned int reserved:1; + unsigned int forwardable:1; + unsigned int forwarded:1; + unsigned int proxiable:1; + unsigned int proxy:1; + unsigned int may_postdate:1; + unsigned int postdated:1; + unsigned int invalid:1; + unsigned int renewable:1; + unsigned int initial:1; + unsigned int pre_authent:1; + unsigned int hw_authent:1; + unsigned int transited_policy_checked:1; + unsigned int ok_as_delegate:1; + unsigned int anonymous:1; +} TicketFlags; + + +int encode_TicketFlags(unsigned char *, size_t, const TicketFlags *, size_t *); +int decode_TicketFlags(const unsigned char *, size_t, TicketFlags *, size_t *); +void free_TicketFlags (TicketFlags *); +size_t length_TicketFlags(const TicketFlags *); +int copy_TicketFlags (const TicketFlags *, TicketFlags *); +unsigned TicketFlags2int(TicketFlags); +TicketFlags int2TicketFlags(unsigned); +extern struct units TicketFlags_units[]; + +/* +KDCOptions ::= BIT STRING { + reserved(0), + forwardable(1), + forwarded(2), + proxiable(3), + proxy(4), + allow-postdate(5), + postdated(6), + unused7(7), + renewable(8), + unused9(9), + unused10(10), + unused11(11), + request-anonymous(14), + canonicalize(15), + disable-transited-check(26), + renewable-ok(27), + enc-tkt-in-skey(28), + renew(30), + validate(31) +} +*/ + +typedef struct KDCOptions { + unsigned int reserved:1; + unsigned int forwardable:1; + unsigned int forwarded:1; + unsigned int proxiable:1; + unsigned int proxy:1; + unsigned int allow_postdate:1; + unsigned int postdated:1; + unsigned int unused7:1; + unsigned int renewable:1; + unsigned int unused9:1; + unsigned int unused10:1; + unsigned int unused11:1; + unsigned int request_anonymous:1; + unsigned int canonicalize:1; + unsigned int disable_transited_check:1; + unsigned int renewable_ok:1; + unsigned int enc_tkt_in_skey:1; + unsigned int renew:1; + unsigned int validate:1; +} KDCOptions; + + +int encode_KDCOptions(unsigned char *, size_t, const KDCOptions *, size_t *); +int decode_KDCOptions(const unsigned char *, size_t, KDCOptions *, size_t *); +void free_KDCOptions (KDCOptions *); +size_t length_KDCOptions(const KDCOptions *); +int copy_KDCOptions (const KDCOptions *, KDCOptions *); +unsigned KDCOptions2int(KDCOptions); +KDCOptions int2KDCOptions(unsigned); +extern struct units KDCOptions_units[]; + +/* +LR-TYPE ::= INTEGER +*/ + +typedef enum LR_TYPE { + LR_NONE = 0, + LR_INITIAL_TGT = 1, + LR_INITIAL = 2, + LR_ISSUE_USE_TGT = 3, + LR_RENEWAL = 4, + LR_REQUEST = 5, + LR_PW_EXPTIME = 6, + LR_ACCT_EXPTIME = 7 +} LR_TYPE; + +int encode_LR_TYPE(unsigned char *, size_t, const LR_TYPE *, size_t *); +int decode_LR_TYPE(const unsigned char *, size_t, LR_TYPE *, size_t *); +void free_LR_TYPE (LR_TYPE *); +size_t length_LR_TYPE(const LR_TYPE *); +int copy_LR_TYPE (const LR_TYPE *, LR_TYPE *); + + +/* +LastReq ::= SEQUENCE OF SEQUENCE { + lr-type[0] LR-TYPE, + lr-value[1] KerberosTime +} +*/ + +typedef struct LastReq { + unsigned int len; + struct { + LR_TYPE lr_type; + KerberosTime lr_value; + } *val; +} LastReq; + +int encode_LastReq(unsigned char *, size_t, const LastReq *, size_t *); +int decode_LastReq(const unsigned char *, size_t, LastReq *, size_t *); +void free_LastReq (LastReq *); +size_t length_LastReq(const LastReq *); +int copy_LastReq (const LastReq *, LastReq *); + + +/* +EncryptedData ::= SEQUENCE { + etype[0] ENCTYPE, + kvno[1] INTEGER OPTIONAL, + cipher[2] OCTET STRING +} +*/ + +typedef struct EncryptedData { + ENCTYPE etype; + int *kvno; + octet_string cipher; +} EncryptedData; + +int encode_EncryptedData(unsigned char *, size_t, const EncryptedData *, size_t *); +int decode_EncryptedData(const unsigned char *, size_t, EncryptedData *, size_t *); +void free_EncryptedData (EncryptedData *); +size_t length_EncryptedData(const EncryptedData *); +int copy_EncryptedData (const EncryptedData *, EncryptedData *); + + +/* +EncryptionKey ::= SEQUENCE { + keytype[0] INTEGER, + keyvalue[1] OCTET STRING +} +*/ + +typedef struct EncryptionKey { + int keytype; + octet_string keyvalue; +} EncryptionKey; + +int encode_EncryptionKey(unsigned char *, size_t, const EncryptionKey *, size_t *); +int decode_EncryptionKey(const unsigned char *, size_t, EncryptionKey *, size_t *); +void free_EncryptionKey (EncryptionKey *); +size_t length_EncryptionKey(const EncryptionKey *); +int copy_EncryptionKey (const EncryptionKey *, EncryptionKey *); + + +/* +TransitedEncoding ::= SEQUENCE { + tr-type[0] INTEGER, + contents[1] OCTET STRING +} +*/ + +typedef struct TransitedEncoding { + int tr_type; + octet_string contents; +} TransitedEncoding; + +int encode_TransitedEncoding(unsigned char *, size_t, const TransitedEncoding *, size_t *); +int decode_TransitedEncoding(const unsigned char *, size_t, TransitedEncoding *, size_t *); +void free_TransitedEncoding (TransitedEncoding *); +size_t length_TransitedEncoding(const TransitedEncoding *); +int copy_TransitedEncoding (const TransitedEncoding *, TransitedEncoding *); + + +/* +Ticket ::= [APPLICATION 1] SEQUENCE { + tkt-vno[0] INTEGER, + realm[1] Realm, + sname[2] PrincipalName, + enc-part[3] EncryptedData +} +*/ + +typedef struct { + int tkt_vno; + Realm realm; + PrincipalName sname; + EncryptedData enc_part; +} Ticket; + +int encode_Ticket(unsigned char *, size_t, const Ticket *, size_t *); +int decode_Ticket(const unsigned char *, size_t, Ticket *, size_t *); +void free_Ticket (Ticket *); +size_t length_Ticket(const Ticket *); +int copy_Ticket (const Ticket *, Ticket *); + + +/* +EncTicketPart ::= [APPLICATION 3] SEQUENCE { + flags[0] TicketFlags, + key[1] EncryptionKey, + crealm[2] Realm, + cname[3] PrincipalName, + transited[4] TransitedEncoding, + authtime[5] KerberosTime, + starttime[6] KerberosTime OPTIONAL, + endtime[7] KerberosTime, + renew-till[8] KerberosTime OPTIONAL, + caddr[9] HostAddresses OPTIONAL, + authorization-data[10] AuthorizationData OPTIONAL +} +*/ + +typedef struct { + TicketFlags flags; + EncryptionKey key; + Realm crealm; + PrincipalName cname; + TransitedEncoding transited; + KerberosTime authtime; + KerberosTime *starttime; + KerberosTime endtime; + KerberosTime *renew_till; + HostAddresses *caddr; + AuthorizationData *authorization_data; +} EncTicketPart; + +int encode_EncTicketPart(unsigned char *, size_t, const EncTicketPart *, size_t *); +int decode_EncTicketPart(const unsigned char *, size_t, EncTicketPart *, size_t *); +void free_EncTicketPart (EncTicketPart *); +size_t length_EncTicketPart(const EncTicketPart *); +int copy_EncTicketPart (const EncTicketPart *, EncTicketPart *); + + +/* +Checksum ::= SEQUENCE { + cksumtype[0] CKSUMTYPE, + checksum[1] OCTET STRING +} +*/ + +typedef struct Checksum { + CKSUMTYPE cksumtype; + octet_string checksum; +} Checksum; + +int encode_Checksum(unsigned char *, size_t, const Checksum *, size_t *); +int decode_Checksum(const unsigned char *, size_t, Checksum *, size_t *); +void free_Checksum (Checksum *); +size_t length_Checksum(const Checksum *); +int copy_Checksum (const Checksum *, Checksum *); + + +/* +Authenticator ::= [APPLICATION 2] SEQUENCE { + authenticator-vno[0] INTEGER, + crealm[1] Realm, + cname[2] PrincipalName, + cksum[3] Checksum OPTIONAL, + cusec[4] INTEGER, + ctime[5] KerberosTime, + subkey[6] EncryptionKey OPTIONAL, + seq-number[7] UNSIGNED OPTIONAL, + authorization-data[8] AuthorizationData OPTIONAL +} +*/ + +typedef struct { + int authenticator_vno; + Realm crealm; + PrincipalName cname; + Checksum *cksum; + int cusec; + KerberosTime ctime; + EncryptionKey *subkey; + UNSIGNED *seq_number; + AuthorizationData *authorization_data; +} Authenticator; + +int encode_Authenticator(unsigned char *, size_t, const Authenticator *, size_t *); +int decode_Authenticator(const unsigned char *, size_t, Authenticator *, size_t *); +void free_Authenticator (Authenticator *); +size_t length_Authenticator(const Authenticator *); +int copy_Authenticator (const Authenticator *, Authenticator *); + + +/* +PA-DATA ::= SEQUENCE { + padata-type[1] PADATA-TYPE, + padata-value[2] OCTET STRING +} +*/ + +typedef struct PA_DATA { + PADATA_TYPE padata_type; + octet_string padata_value; +} PA_DATA; + +int encode_PA_DATA(unsigned char *, size_t, const PA_DATA *, size_t *); +int decode_PA_DATA(const unsigned char *, size_t, PA_DATA *, size_t *); +void free_PA_DATA (PA_DATA *); +size_t length_PA_DATA(const PA_DATA *); +int copy_PA_DATA (const PA_DATA *, PA_DATA *); + + +/* +ETYPE-INFO-ENTRY ::= SEQUENCE { + etype[0] ENCTYPE, + salt[1] OCTET STRING OPTIONAL, + salttype[2] INTEGER OPTIONAL +} +*/ + +typedef struct ETYPE_INFO_ENTRY { + ENCTYPE etype; + octet_string *salt; + int *salttype; +} ETYPE_INFO_ENTRY; + +int encode_ETYPE_INFO_ENTRY(unsigned char *, size_t, const ETYPE_INFO_ENTRY *, size_t *); +int decode_ETYPE_INFO_ENTRY(const unsigned char *, size_t, ETYPE_INFO_ENTRY *, size_t *); +void free_ETYPE_INFO_ENTRY (ETYPE_INFO_ENTRY *); +size_t length_ETYPE_INFO_ENTRY(const ETYPE_INFO_ENTRY *); +int copy_ETYPE_INFO_ENTRY (const ETYPE_INFO_ENTRY *, ETYPE_INFO_ENTRY *); + + +/* +ETYPE-INFO ::= SEQUENCE OF ETYPE-INFO-ENTRY +*/ + +typedef struct ETYPE_INFO { + unsigned int len; + ETYPE_INFO_ENTRY *val; +} ETYPE_INFO; + +int encode_ETYPE_INFO(unsigned char *, size_t, const ETYPE_INFO *, size_t *); +int decode_ETYPE_INFO(const unsigned char *, size_t, ETYPE_INFO *, size_t *); +void free_ETYPE_INFO (ETYPE_INFO *); +size_t length_ETYPE_INFO(const ETYPE_INFO *); +int copy_ETYPE_INFO (const ETYPE_INFO *, ETYPE_INFO *); + + +/* +METHOD-DATA ::= SEQUENCE OF PA-DATA +*/ + +typedef struct METHOD_DATA { + unsigned int len; + PA_DATA *val; +} METHOD_DATA; + +int encode_METHOD_DATA(unsigned char *, size_t, const METHOD_DATA *, size_t *); +int decode_METHOD_DATA(const unsigned char *, size_t, METHOD_DATA *, size_t *); +void free_METHOD_DATA (METHOD_DATA *); +size_t length_METHOD_DATA(const METHOD_DATA *); +int copy_METHOD_DATA (const METHOD_DATA *, METHOD_DATA *); + + +/* +KDC-REQ-BODY ::= SEQUENCE { + kdc-options[0] KDCOptions, + cname[1] PrincipalName OPTIONAL, + realm[2] Realm, + sname[3] PrincipalName OPTIONAL, + from[4] KerberosTime OPTIONAL, + till[5] KerberosTime OPTIONAL, + rtime[6] KerberosTime OPTIONAL, + nonce[7] INTEGER, + etype[8] SEQUENCE OF ENCTYPE, + addresses[9] HostAddresses OPTIONAL, + enc-authorization-data[10] EncryptedData OPTIONAL, + additional-tickets[11] SEQUENCE OF Ticket OPTIONAL +} +*/ + +typedef struct KDC_REQ_BODY { + KDCOptions kdc_options; + PrincipalName *cname; + Realm realm; + PrincipalName *sname; + KerberosTime *from; + KerberosTime *till; + KerberosTime *rtime; + int nonce; + struct { + unsigned int len; + ENCTYPE *val; + } etype; + HostAddresses *addresses; + EncryptedData *enc_authorization_data; + struct { + unsigned int len; + Ticket *val; + } *additional_tickets; +} KDC_REQ_BODY; + +int encode_KDC_REQ_BODY(unsigned char *, size_t, const KDC_REQ_BODY *, size_t *); +int decode_KDC_REQ_BODY(const unsigned char *, size_t, KDC_REQ_BODY *, size_t *); +void free_KDC_REQ_BODY (KDC_REQ_BODY *); +size_t length_KDC_REQ_BODY(const KDC_REQ_BODY *); +int copy_KDC_REQ_BODY (const KDC_REQ_BODY *, KDC_REQ_BODY *); + + +/* +KDC-REQ ::= SEQUENCE { + pvno[1] INTEGER, + msg-type[2] MESSAGE-TYPE, + padata[3] METHOD-DATA OPTIONAL, + req-body[4] KDC-REQ-BODY +} +*/ + +typedef struct KDC_REQ { + int pvno; + MESSAGE_TYPE msg_type; + METHOD_DATA *padata; + KDC_REQ_BODY req_body; +} KDC_REQ; + +int encode_KDC_REQ(unsigned char *, size_t, const KDC_REQ *, size_t *); +int decode_KDC_REQ(const unsigned char *, size_t, KDC_REQ *, size_t *); +void free_KDC_REQ (KDC_REQ *); +size_t length_KDC_REQ(const KDC_REQ *); +int copy_KDC_REQ (const KDC_REQ *, KDC_REQ *); + + +/* +AS-REQ ::= [APPLICATION 10] KDC-REQ +*/ + +typedef KDC_REQ AS_REQ; + +int encode_AS_REQ(unsigned char *, size_t, const AS_REQ *, size_t *); +int decode_AS_REQ(const unsigned char *, size_t, AS_REQ *, size_t *); +void free_AS_REQ (AS_REQ *); +size_t length_AS_REQ(const AS_REQ *); +int copy_AS_REQ (const AS_REQ *, AS_REQ *); + + +/* +TGS-REQ ::= [APPLICATION 12] KDC-REQ +*/ + +typedef KDC_REQ TGS_REQ; + +int encode_TGS_REQ(unsigned char *, size_t, const TGS_REQ *, size_t *); +int decode_TGS_REQ(const unsigned char *, size_t, TGS_REQ *, size_t *); +void free_TGS_REQ (TGS_REQ *); +size_t length_TGS_REQ(const TGS_REQ *); +int copy_TGS_REQ (const TGS_REQ *, TGS_REQ *); + + +/* +PA-ENC-TS-ENC ::= SEQUENCE { + patimestamp[0] KerberosTime, + pausec[1] INTEGER OPTIONAL +} +*/ + +typedef struct PA_ENC_TS_ENC { + KerberosTime patimestamp; + int *pausec; +} PA_ENC_TS_ENC; + +int encode_PA_ENC_TS_ENC(unsigned char *, size_t, const PA_ENC_TS_ENC *, size_t *); +int decode_PA_ENC_TS_ENC(const unsigned char *, size_t, PA_ENC_TS_ENC *, size_t *); +void free_PA_ENC_TS_ENC (PA_ENC_TS_ENC *); +size_t length_PA_ENC_TS_ENC(const PA_ENC_TS_ENC *); +int copy_PA_ENC_TS_ENC (const PA_ENC_TS_ENC *, PA_ENC_TS_ENC *); + + +/* +KDC-REP ::= SEQUENCE { + pvno[0] INTEGER, + msg-type[1] MESSAGE-TYPE, + padata[2] METHOD-DATA OPTIONAL, + crealm[3] Realm, + cname[4] PrincipalName, + ticket[5] Ticket, + enc-part[6] EncryptedData +} +*/ + +typedef struct KDC_REP { + int pvno; + MESSAGE_TYPE msg_type; + METHOD_DATA *padata; + Realm crealm; + PrincipalName cname; + Ticket ticket; + EncryptedData enc_part; +} KDC_REP; + +int encode_KDC_REP(unsigned char *, size_t, const KDC_REP *, size_t *); +int decode_KDC_REP(const unsigned char *, size_t, KDC_REP *, size_t *); +void free_KDC_REP (KDC_REP *); +size_t length_KDC_REP(const KDC_REP *); +int copy_KDC_REP (const KDC_REP *, KDC_REP *); + + +/* +AS-REP ::= [APPLICATION 11] KDC-REP +*/ + +typedef KDC_REP AS_REP; + +int encode_AS_REP(unsigned char *, size_t, const AS_REP *, size_t *); +int decode_AS_REP(const unsigned char *, size_t, AS_REP *, size_t *); +void free_AS_REP (AS_REP *); +size_t length_AS_REP(const AS_REP *); +int copy_AS_REP (const AS_REP *, AS_REP *); + + +/* +TGS-REP ::= [APPLICATION 13] KDC-REP +*/ + +typedef KDC_REP TGS_REP; + +int encode_TGS_REP(unsigned char *, size_t, const TGS_REP *, size_t *); +int decode_TGS_REP(const unsigned char *, size_t, TGS_REP *, size_t *); +void free_TGS_REP (TGS_REP *); +size_t length_TGS_REP(const TGS_REP *); +int copy_TGS_REP (const TGS_REP *, TGS_REP *); + + +/* +EncKDCRepPart ::= SEQUENCE { + key[0] EncryptionKey, + last-req[1] LastReq, + nonce[2] INTEGER, + key-expiration[3] KerberosTime OPTIONAL, + flags[4] TicketFlags, + authtime[5] KerberosTime, + starttime[6] KerberosTime OPTIONAL, + endtime[7] KerberosTime, + renew-till[8] KerberosTime OPTIONAL, + srealm[9] Realm, + sname[10] PrincipalName, + caddr[11] HostAddresses OPTIONAL +} +*/ + +typedef struct EncKDCRepPart { + EncryptionKey key; + LastReq last_req; + int nonce; + KerberosTime *key_expiration; + TicketFlags flags; + KerberosTime authtime; + KerberosTime *starttime; + KerberosTime endtime; + KerberosTime *renew_till; + Realm srealm; + PrincipalName sname; + HostAddresses *caddr; +} EncKDCRepPart; + +int encode_EncKDCRepPart(unsigned char *, size_t, const EncKDCRepPart *, size_t *); +int decode_EncKDCRepPart(const unsigned char *, size_t, EncKDCRepPart *, size_t *); +void free_EncKDCRepPart (EncKDCRepPart *); +size_t length_EncKDCRepPart(const EncKDCRepPart *); +int copy_EncKDCRepPart (const EncKDCRepPart *, EncKDCRepPart *); + + +/* +EncASRepPart ::= [APPLICATION 25] EncKDCRepPart +*/ + +typedef EncKDCRepPart EncASRepPart; + +int encode_EncASRepPart(unsigned char *, size_t, const EncASRepPart *, size_t *); +int decode_EncASRepPart(const unsigned char *, size_t, EncASRepPart *, size_t *); +void free_EncASRepPart (EncASRepPart *); +size_t length_EncASRepPart(const EncASRepPart *); +int copy_EncASRepPart (const EncASRepPart *, EncASRepPart *); + + +/* +EncTGSRepPart ::= [APPLICATION 26] EncKDCRepPart +*/ + +typedef EncKDCRepPart EncTGSRepPart; + +int encode_EncTGSRepPart(unsigned char *, size_t, const EncTGSRepPart *, size_t *); +int decode_EncTGSRepPart(const unsigned char *, size_t, EncTGSRepPart *, size_t *); +void free_EncTGSRepPart (EncTGSRepPart *); +size_t length_EncTGSRepPart(const EncTGSRepPart *); +int copy_EncTGSRepPart (const EncTGSRepPart *, EncTGSRepPart *); + + +/* +AP-REQ ::= [APPLICATION 14] SEQUENCE { + pvno[0] INTEGER, + msg-type[1] MESSAGE-TYPE, + ap-options[2] APOptions, + ticket[3] Ticket, + authenticator[4] EncryptedData +} +*/ + +typedef struct { + int pvno; + MESSAGE_TYPE msg_type; + APOptions ap_options; + Ticket ticket; + EncryptedData authenticator; +} AP_REQ; + +int encode_AP_REQ(unsigned char *, size_t, const AP_REQ *, size_t *); +int decode_AP_REQ(const unsigned char *, size_t, AP_REQ *, size_t *); +void free_AP_REQ (AP_REQ *); +size_t length_AP_REQ(const AP_REQ *); +int copy_AP_REQ (const AP_REQ *, AP_REQ *); + + +/* +AP-REP ::= [APPLICATION 15] SEQUENCE { + pvno[0] INTEGER, + msg-type[1] MESSAGE-TYPE, + enc-part[2] EncryptedData +} +*/ + +typedef struct { + int pvno; + MESSAGE_TYPE msg_type; + EncryptedData enc_part; +} AP_REP; + +int encode_AP_REP(unsigned char *, size_t, const AP_REP *, size_t *); +int decode_AP_REP(const unsigned char *, size_t, AP_REP *, size_t *); +void free_AP_REP (AP_REP *); +size_t length_AP_REP(const AP_REP *); +int copy_AP_REP (const AP_REP *, AP_REP *); + + +/* +EncAPRepPart ::= [APPLICATION 27] SEQUENCE { + ctime[0] KerberosTime, + cusec[1] INTEGER, + subkey[2] EncryptionKey OPTIONAL, + seq-number[3] UNSIGNED OPTIONAL +} +*/ + +typedef struct { + KerberosTime ctime; + int cusec; + EncryptionKey *subkey; + UNSIGNED *seq_number; +} EncAPRepPart; + +int encode_EncAPRepPart(unsigned char *, size_t, const EncAPRepPart *, size_t *); +int decode_EncAPRepPart(const unsigned char *, size_t, EncAPRepPart *, size_t *); +void free_EncAPRepPart (EncAPRepPart *); +size_t length_EncAPRepPart(const EncAPRepPart *); +int copy_EncAPRepPart (const EncAPRepPart *, EncAPRepPart *); + + +/* +KRB-SAFE-BODY ::= SEQUENCE { + user-data[0] OCTET STRING, + timestamp[1] KerberosTime OPTIONAL, + usec[2] INTEGER OPTIONAL, + seq-number[3] UNSIGNED OPTIONAL, + s-address[4] HostAddress OPTIONAL, + r-address[5] HostAddress OPTIONAL +} +*/ + +typedef struct KRB_SAFE_BODY { + octet_string user_data; + KerberosTime *timestamp; + int *usec; + UNSIGNED *seq_number; + HostAddress *s_address; + HostAddress *r_address; +} KRB_SAFE_BODY; + +int encode_KRB_SAFE_BODY(unsigned char *, size_t, const KRB_SAFE_BODY *, size_t *); +int decode_KRB_SAFE_BODY(const unsigned char *, size_t, KRB_SAFE_BODY *, size_t *); +void free_KRB_SAFE_BODY (KRB_SAFE_BODY *); +size_t length_KRB_SAFE_BODY(const KRB_SAFE_BODY *); +int copy_KRB_SAFE_BODY (const KRB_SAFE_BODY *, KRB_SAFE_BODY *); + + +/* +KRB-SAFE ::= [APPLICATION 20] SEQUENCE { + pvno[0] INTEGER, + msg-type[1] MESSAGE-TYPE, + safe-body[2] KRB-SAFE-BODY, + cksum[3] Checksum +} +*/ + +typedef struct { + int pvno; + MESSAGE_TYPE msg_type; + KRB_SAFE_BODY safe_body; + Checksum cksum; +} KRB_SAFE; + +int encode_KRB_SAFE(unsigned char *, size_t, const KRB_SAFE *, size_t *); +int decode_KRB_SAFE(const unsigned char *, size_t, KRB_SAFE *, size_t *); +void free_KRB_SAFE (KRB_SAFE *); +size_t length_KRB_SAFE(const KRB_SAFE *); +int copy_KRB_SAFE (const KRB_SAFE *, KRB_SAFE *); + + +/* +KRB-PRIV ::= [APPLICATION 21] SEQUENCE { + pvno[0] INTEGER, + msg-type[1] MESSAGE-TYPE, + enc-part[3] EncryptedData +} +*/ + +typedef struct { + int pvno; + MESSAGE_TYPE msg_type; + EncryptedData enc_part; +} KRB_PRIV; + +int encode_KRB_PRIV(unsigned char *, size_t, const KRB_PRIV *, size_t *); +int decode_KRB_PRIV(const unsigned char *, size_t, KRB_PRIV *, size_t *); +void free_KRB_PRIV (KRB_PRIV *); +size_t length_KRB_PRIV(const KRB_PRIV *); +int copy_KRB_PRIV (const KRB_PRIV *, KRB_PRIV *); + + +/* +EncKrbPrivPart ::= [APPLICATION 28] SEQUENCE { + user-data[0] OCTET STRING, + timestamp[1] KerberosTime OPTIONAL, + usec[2] INTEGER OPTIONAL, + seq-number[3] UNSIGNED OPTIONAL, + s-address[4] HostAddress OPTIONAL, + r-address[5] HostAddress OPTIONAL +} +*/ + +typedef struct { + octet_string user_data; + KerberosTime *timestamp; + int *usec; + UNSIGNED *seq_number; + HostAddress *s_address; + HostAddress *r_address; +} EncKrbPrivPart; + +int encode_EncKrbPrivPart(unsigned char *, size_t, const EncKrbPrivPart *, size_t *); +int decode_EncKrbPrivPart(const unsigned char *, size_t, EncKrbPrivPart *, size_t *); +void free_EncKrbPrivPart (EncKrbPrivPart *); +size_t length_EncKrbPrivPart(const EncKrbPrivPart *); +int copy_EncKrbPrivPart (const EncKrbPrivPart *, EncKrbPrivPart *); + + +/* +KRB-CRED ::= [APPLICATION 22] SEQUENCE { + pvno[0] INTEGER, + msg-type[1] MESSAGE-TYPE, + tickets[2] SEQUENCE OF Ticket, + enc-part[3] EncryptedData +} +*/ + +typedef struct { + int pvno; + MESSAGE_TYPE msg_type; + struct { + unsigned int len; + Ticket *val; + } tickets; + EncryptedData enc_part; +} KRB_CRED; + +int encode_KRB_CRED(unsigned char *, size_t, const KRB_CRED *, size_t *); +int decode_KRB_CRED(const unsigned char *, size_t, KRB_CRED *, size_t *); +void free_KRB_CRED (KRB_CRED *); +size_t length_KRB_CRED(const KRB_CRED *); +int copy_KRB_CRED (const KRB_CRED *, KRB_CRED *); + + +/* +KrbCredInfo ::= SEQUENCE { + key[0] EncryptionKey, + prealm[1] Realm OPTIONAL, + pname[2] PrincipalName OPTIONAL, + flags[3] TicketFlags OPTIONAL, + authtime[4] KerberosTime OPTIONAL, + starttime[5] KerberosTime OPTIONAL, + endtime[6] KerberosTime OPTIONAL, + renew-till[7] KerberosTime OPTIONAL, + srealm[8] Realm OPTIONAL, + sname[9] PrincipalName OPTIONAL, + caddr[10] HostAddresses OPTIONAL +} +*/ + +typedef struct KrbCredInfo { + EncryptionKey key; + Realm *prealm; + PrincipalName *pname; + TicketFlags *flags; + KerberosTime *authtime; + KerberosTime *starttime; + KerberosTime *endtime; + KerberosTime *renew_till; + Realm *srealm; + PrincipalName *sname; + HostAddresses *caddr; +} KrbCredInfo; + +int encode_KrbCredInfo(unsigned char *, size_t, const KrbCredInfo *, size_t *); +int decode_KrbCredInfo(const unsigned char *, size_t, KrbCredInfo *, size_t *); +void free_KrbCredInfo (KrbCredInfo *); +size_t length_KrbCredInfo(const KrbCredInfo *); +int copy_KrbCredInfo (const KrbCredInfo *, KrbCredInfo *); + + +/* +EncKrbCredPart ::= [APPLICATION 29] SEQUENCE { + ticket-info[0] SEQUENCE OF KrbCredInfo, + nonce[1] INTEGER OPTIONAL, + timestamp[2] KerberosTime OPTIONAL, + usec[3] INTEGER OPTIONAL, + s-address[4] HostAddress OPTIONAL, + r-address[5] HostAddress OPTIONAL +} +*/ + +typedef struct { + struct { + unsigned int len; + KrbCredInfo *val; + } ticket_info; + int *nonce; + KerberosTime *timestamp; + int *usec; + HostAddress *s_address; + HostAddress *r_address; +} EncKrbCredPart; + +int encode_EncKrbCredPart(unsigned char *, size_t, const EncKrbCredPart *, size_t *); +int decode_EncKrbCredPart(const unsigned char *, size_t, EncKrbCredPart *, size_t *); +void free_EncKrbCredPart (EncKrbCredPart *); +size_t length_EncKrbCredPart(const EncKrbCredPart *); +int copy_EncKrbCredPart (const EncKrbCredPart *, EncKrbCredPart *); + + +/* +KRB-ERROR ::= [APPLICATION 30] SEQUENCE { + pvno[0] INTEGER, + msg-type[1] MESSAGE-TYPE, + ctime[2] KerberosTime OPTIONAL, + cusec[3] INTEGER OPTIONAL, + stime[4] KerberosTime, + susec[5] INTEGER, + error-code[6] INTEGER, + crealm[7] Realm OPTIONAL, + cname[8] PrincipalName OPTIONAL, + realm[9] Realm, + sname[10] PrincipalName, + e-text[11] GeneralString OPTIONAL, + e-data[12] OCTET STRING OPTIONAL +} +*/ + +typedef struct { + int pvno; + MESSAGE_TYPE msg_type; + KerberosTime *ctime; + int *cusec; + KerberosTime stime; + int susec; + int error_code; + Realm *crealm; + PrincipalName *cname; + Realm realm; + PrincipalName sname; + general_string *e_text; + octet_string *e_data; +} KRB_ERROR; + +int encode_KRB_ERROR(unsigned char *, size_t, const KRB_ERROR *, size_t *); +int decode_KRB_ERROR(const unsigned char *, size_t, KRB_ERROR *, size_t *); +void free_KRB_ERROR (KRB_ERROR *); +size_t length_KRB_ERROR(const KRB_ERROR *); +int copy_KRB_ERROR (const KRB_ERROR *, KRB_ERROR *); + + +enum { pvno = 5 }; + +enum { DOMAIN_X500_COMPRESS = 1 }; + +#endif /* __krb5_asn1_h__ */ diff --git a/src/include/krb5_err.h b/src/include/krb5_err.h new file mode 100644 index 0000000..4c0f542 --- /dev/null +++ b/src/include/krb5_err.h @@ -0,0 +1,181 @@ +/* Generated from /usr/src/kerberos5/lib/libkrb5/../../../crypto/heimdal/lib/krb5/krb5_err.et */ +/* $Id$ */ + +#ifndef __krb5_err_h__ +#define __krb5_err_h__ + +struct et_list; + +void initialize_krb5_error_table_r(struct et_list **); + +void initialize_krb5_error_table(void); +#define init_krb5_err_tbl initialize_krb5_error_table + +typedef enum krb5_error_number{ + KRB5KDC_ERR_NONE = -1765328384, + KRB5KDC_ERR_NAME_EXP = -1765328383, + KRB5KDC_ERR_SERVICE_EXP = -1765328382, + KRB5KDC_ERR_BAD_PVNO = -1765328381, + KRB5KDC_ERR_C_OLD_MAST_KVNO = -1765328380, + KRB5KDC_ERR_S_OLD_MAST_KVNO = -1765328379, + KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN = -1765328378, + KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN = -1765328377, + KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE = -1765328376, + KRB5KDC_ERR_NULL_KEY = -1765328375, + KRB5KDC_ERR_CANNOT_POSTDATE = -1765328374, + KRB5KDC_ERR_NEVER_VALID = -1765328373, + KRB5KDC_ERR_POLICY = -1765328372, + KRB5KDC_ERR_BADOPTION = -1765328371, + KRB5KDC_ERR_ETYPE_NOSUPP = -1765328370, + KRB5KDC_ERR_SUMTYPE_NOSUPP = -1765328369, + KRB5KDC_ERR_PADATA_TYPE_NOSUPP = -1765328368, + KRB5KDC_ERR_TRTYPE_NOSUPP = -1765328367, + KRB5KDC_ERR_CLIENT_REVOKED = -1765328366, + KRB5KDC_ERR_SERVICE_REVOKED = -1765328365, + KRB5KDC_ERR_TGT_REVOKED = -1765328364, + KRB5KDC_ERR_CLIENT_NOTYET = -1765328363, + KRB5KDC_ERR_SERVICE_NOTYET = -1765328362, + KRB5KDC_ERR_KEY_EXPIRED = -1765328361, + KRB5KDC_ERR_PREAUTH_FAILED = -1765328360, + KRB5KDC_ERR_PREAUTH_REQUIRED = -1765328359, + KRB5KDC_ERR_SERVER_NOMATCH = -1765328358, + KRB5KRB_AP_ERR_BAD_INTEGRITY = -1765328353, + KRB5KRB_AP_ERR_TKT_EXPIRED = -1765328352, + KRB5KRB_AP_ERR_TKT_NYV = -1765328351, + KRB5KRB_AP_ERR_REPEAT = -1765328350, + KRB5KRB_AP_ERR_NOT_US = -1765328349, + KRB5KRB_AP_ERR_BADMATCH = -1765328348, + KRB5KRB_AP_ERR_SKEW = -1765328347, + KRB5KRB_AP_ERR_BADADDR = -1765328346, + KRB5KRB_AP_ERR_BADVERSION = -1765328345, + KRB5KRB_AP_ERR_MSG_TYPE = -1765328344, + KRB5KRB_AP_ERR_MODIFIED = -1765328343, + KRB5KRB_AP_ERR_BADORDER = -1765328342, + KRB5KRB_AP_ERR_ILL_CR_TKT = -1765328341, + KRB5KRB_AP_ERR_BADKEYVER = -1765328340, + KRB5KRB_AP_ERR_NOKEY = -1765328339, + KRB5KRB_AP_ERR_MUT_FAIL = -1765328338, + KRB5KRB_AP_ERR_BADDIRECTION = -1765328337, + KRB5KRB_AP_ERR_METHOD = -1765328336, + KRB5KRB_AP_ERR_BADSEQ = -1765328335, + KRB5KRB_AP_ERR_INAPP_CKSUM = -1765328334, + KRB5KRB_AP_PATH_NOT_ACCEPTED = -1765328333, + KRB5KRB_ERR_RESPONSE_TOO_BIG = -1765328332, + KRB5KRB_ERR_GENERIC = -1765328324, + KRB5KRB_ERR_FIELD_TOOLONG = -1765328323, + KDC_ERROR_CLIENT_NOT_TRUSTED = -1765328322, + KDC_ERROR_KDC_NOT_TRUSTED = -1765328321, + KDC_ERROR_INVALID_SIG = -1765328320, + KDC_ERROR_KEY_TOO_WEAK = -1765328319, + KDC_ERROR_CERTIFICATE_MISMATCH = -1765328318, + KRB5_AP_ERR_USER_TO_USER_REQUIRED = -1765328317, + KDC_ERROR_CANT_VERIFY_CERTIFICATE = -1765328316, + KDC_ERROR_INVALID_CERTIFICATE = -1765328315, + KDC_ERROR_REVOKED_CERTIFICATE = -1765328314, + KDC_ERROR_REVOCATION_STATUS_UNKNOWN = -1765328313, + KDC_ERROR_REVOCATION_STATUS_UNAVAILABLE = -1765328312, + KDC_ERROR_CLIENT_NAME_MISMATCH = -1765328311, + KDC_ERROR_KDC_NAME_MISMATCH = -1765328310, + KRB5_ERR_RCSID = -1765328256, + KRB5_LIBOS_BADLOCKFLAG = -1765328255, + KRB5_LIBOS_CANTREADPWD = -1765328254, + KRB5_LIBOS_BADPWDMATCH = -1765328253, + KRB5_LIBOS_PWDINTR = -1765328252, + KRB5_PARSE_ILLCHAR = -1765328251, + KRB5_PARSE_MALFORMED = -1765328250, + KRB5_CONFIG_CANTOPEN = -1765328249, + KRB5_CONFIG_BADFORMAT = -1765328248, + KRB5_CONFIG_NOTENUFSPACE = -1765328247, + KRB5_BADMSGTYPE = -1765328246, + KRB5_CC_BADNAME = -1765328245, + KRB5_CC_UNKNOWN_TYPE = -1765328244, + KRB5_CC_NOTFOUND = -1765328243, + KRB5_CC_END = -1765328242, + KRB5_NO_TKT_SUPPLIED = -1765328241, + KRB5KRB_AP_WRONG_PRINC = -1765328240, + KRB5KRB_AP_ERR_TKT_INVALID = -1765328239, + KRB5_PRINC_NOMATCH = -1765328238, + KRB5_KDCREP_MODIFIED = -1765328237, + KRB5_KDCREP_SKEW = -1765328236, + KRB5_IN_TKT_REALM_MISMATCH = -1765328235, + KRB5_PROG_ETYPE_NOSUPP = -1765328234, + KRB5_PROG_KEYTYPE_NOSUPP = -1765328233, + KRB5_WRONG_ETYPE = -1765328232, + KRB5_PROG_SUMTYPE_NOSUPP = -1765328231, + KRB5_REALM_UNKNOWN = -1765328230, + KRB5_SERVICE_UNKNOWN = -1765328229, + KRB5_KDC_UNREACH = -1765328228, + KRB5_NO_LOCALNAME = -1765328227, + KRB5_MUTUAL_FAILED = -1765328226, + KRB5_RC_TYPE_EXISTS = -1765328225, + KRB5_RC_MALLOC = -1765328224, + KRB5_RC_TYPE_NOTFOUND = -1765328223, + KRB5_RC_UNKNOWN = -1765328222, + KRB5_RC_REPLAY = -1765328221, + KRB5_RC_IO = -1765328220, + KRB5_RC_NOIO = -1765328219, + KRB5_RC_PARSE = -1765328218, + KRB5_RC_IO_EOF = -1765328217, + KRB5_RC_IO_MALLOC = -1765328216, + KRB5_RC_IO_PERM = -1765328215, + KRB5_RC_IO_IO = -1765328214, + KRB5_RC_IO_UNKNOWN = -1765328213, + KRB5_RC_IO_SPACE = -1765328212, + KRB5_TRANS_CANTOPEN = -1765328211, + KRB5_TRANS_BADFORMAT = -1765328210, + KRB5_LNAME_CANTOPEN = -1765328209, + KRB5_LNAME_NOTRANS = -1765328208, + KRB5_LNAME_BADFORMAT = -1765328207, + KRB5_CRYPTO_INTERNAL = -1765328206, + KRB5_KT_BADNAME = -1765328205, + KRB5_KT_UNKNOWN_TYPE = -1765328204, + KRB5_KT_NOTFOUND = -1765328203, + KRB5_KT_END = -1765328202, + KRB5_KT_NOWRITE = -1765328201, + KRB5_KT_IOERR = -1765328200, + KRB5_NO_TKT_IN_RLM = -1765328199, + KRB5DES_BAD_KEYPAR = -1765328198, + KRB5DES_WEAK_KEY = -1765328197, + KRB5_BAD_ENCTYPE = -1765328196, + KRB5_BAD_KEYSIZE = -1765328195, + KRB5_BAD_MSIZE = -1765328194, + KRB5_CC_TYPE_EXISTS = -1765328193, + KRB5_KT_TYPE_EXISTS = -1765328192, + KRB5_CC_IO = -1765328191, + KRB5_FCC_PERM = -1765328190, + KRB5_FCC_NOFILE = -1765328189, + KRB5_FCC_INTERNAL = -1765328188, + KRB5_CC_WRITE = -1765328187, + KRB5_CC_NOMEM = -1765328186, + KRB5_CC_FORMAT = -1765328185, + KRB5_INVALID_FLAGS = -1765328184, + KRB5_NO_2ND_TKT = -1765328183, + KRB5_NOCREDS_SUPPLIED = -1765328182, + KRB5_SENDAUTH_BADAUTHVERS = -1765328181, + KRB5_SENDAUTH_BADAPPLVERS = -1765328180, + KRB5_SENDAUTH_BADRESPONSE = -1765328179, + KRB5_SENDAUTH_REJECTED = -1765328178, + KRB5_PREAUTH_BAD_TYPE = -1765328177, + KRB5_PREAUTH_NO_KEY = -1765328176, + KRB5_PREAUTH_FAILED = -1765328175, + KRB5_RCACHE_BADVNO = -1765328174, + KRB5_CCACHE_BADVNO = -1765328173, + KRB5_KEYTAB_BADVNO = -1765328172, + KRB5_PROG_ATYPE_NOSUPP = -1765328171, + KRB5_RC_REQUIRED = -1765328170, + KRB5_ERR_BAD_HOSTNAME = -1765328169, + KRB5_ERR_HOST_REALM_UNKNOWN = -1765328168, + KRB5_SNAME_UNSUPP_NAMETYPE = -1765328167, + KRB5KRB_AP_ERR_V4_REPLY = -1765328166, + KRB5_REALM_CANT_RESOLVE = -1765328165, + KRB5_TKT_NOT_FORWARDABLE = -1765328164, + KRB5_FWD_BAD_PRINCIPAL = -1765328163, + KRB5_GET_IN_TKT_LOOP = -1765328162, + KRB5_CONFIG_NODEFREALM = -1765328161, + KRB5_SAM_UNSUPPORTED = -1765328160, + KRB5_KT_NAME_TOOLONG = -1765328159 +} krb5_error_number; + +#define ERROR_TABLE_BASE_krb5 -1765328384 + +#endif /* __krb5_err_h__ */ diff --git a/src/include/kvm.h b/src/include/kvm.h new file mode 100644 index 0000000..35aeff5 --- /dev/null +++ b/src/include/kvm.h @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 1989, 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. + * + * @(#)kvm.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/lib/libkvm/kvm.h,v 1.16 2003/10/13 04:44:55 bde Exp $ + */ + +#ifndef _KVM_H_ +#define _KVM_H_ + +#include +#include +#include + +/* Default version symbol. */ +#define VRS_SYM "_version" +#define VRS_KEY "VERSION" + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +typedef struct __kvm kvm_t; + +struct kinfo_proc; +struct proc; + +struct kvm_swap { + char ksw_devname[32]; + int ksw_used; + int ksw_total; + int ksw_flags; + int ksw_reserved1; + int ksw_reserved2; +}; + +#define SWIF_DEV_PREFIX 0x0002 + +__BEGIN_DECLS +int kvm_close(kvm_t *); +char **kvm_getargv(kvm_t *, const struct kinfo_proc *, int); +char **kvm_getenvv(kvm_t *, const struct kinfo_proc *, int); +char *kvm_geterr(kvm_t *); +char *kvm_getfiles(kvm_t *, int, int, int *); +int kvm_getloadavg(kvm_t *, double [], int); +struct kinfo_proc * + kvm_getprocs(kvm_t *, int, int, int *); +int kvm_getswapinfo(kvm_t *, struct kvm_swap *, int, int); +int kvm_nlist(kvm_t *, struct nlist *); +kvm_t *kvm_open + (const char *, const char *, const char *, int, const char *); +kvm_t *kvm_openfiles + (const char *, const char *, const char *, int, char *); +ssize_t kvm_read(kvm_t *, unsigned long, void *, size_t); +ssize_t kvm_uread + (kvm_t *, struct kinfo_proc *, unsigned long, char *, size_t); +ssize_t kvm_write(kvm_t *, unsigned long, const void *, size_t); +__END_DECLS + +#endif /* !_KVM_H_ */ diff --git a/src/include/langinfo.h b/src/include/langinfo.h new file mode 100644 index 0000000..4a1375c --- /dev/null +++ b/src/include/langinfo.h @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/langinfo.h,v 1.6 2002/09/18 05:54:25 mike Exp $ + */ + +#ifndef _LANGINFO_H_ +#define _LANGINFO_H_ + +#include +#include + +#ifndef _NL_ITEM_DECLARED +typedef __nl_item nl_item; +#define _NL_ITEM_DECLARED +#endif + +#define CODESET 0 /* codeset name */ +#define D_T_FMT 1 /* string for formatting date and time */ +#define D_FMT 2 /* date format string */ +#define T_FMT 3 /* time format string */ +#define T_FMT_AMPM 4 /* a.m. or p.m. time formatting string */ +#define AM_STR 5 /* Ante Meridian affix */ +#define PM_STR 6 /* Post Meridian affix */ + +/* week day names */ +#define DAY_1 7 +#define DAY_2 8 +#define DAY_3 9 +#define DAY_4 10 +#define DAY_5 11 +#define DAY_6 12 +#define DAY_7 13 + +/* abbreviated week day names */ +#define ABDAY_1 14 +#define ABDAY_2 15 +#define ABDAY_3 16 +#define ABDAY_4 17 +#define ABDAY_5 18 +#define ABDAY_6 19 +#define ABDAY_7 20 + +/* month names */ +#define MON_1 21 +#define MON_2 22 +#define MON_3 23 +#define MON_4 24 +#define MON_5 25 +#define MON_6 26 +#define MON_7 27 +#define MON_8 28 +#define MON_9 29 +#define MON_10 30 +#define MON_11 31 +#define MON_12 32 + +/* abbreviated month names */ +#define ABMON_1 33 +#define ABMON_2 34 +#define ABMON_3 35 +#define ABMON_4 36 +#define ABMON_5 37 +#define ABMON_6 38 +#define ABMON_7 39 +#define ABMON_8 40 +#define ABMON_9 41 +#define ABMON_10 42 +#define ABMON_11 43 +#define ABMON_12 44 + +#define ERA 45 /* era description segments */ +#define ERA_D_FMT 46 /* era date format string */ +#define ERA_D_T_FMT 47 /* era date and time format string */ +#define ERA_T_FMT 48 /* era time format string */ +#define ALT_DIGITS 49 /* alternative symbols for digits */ + +#define RADIXCHAR 50 /* radix char */ +#define THOUSEP 51 /* separator for thousands */ + +#define YESEXPR 52 /* affirmative response expression */ +#define NOEXPR 53 /* negative response expression */ + +#if __BSD_VISIBLE || __XSI_VISIBLE <= 500 +#define YESSTR 54 /* affirmative response for yes/no queries */ +#define NOSTR 55 /* negative response for yes/no queries */ +#endif + +#define CRNCYSTR 56 /* currency symbol */ + +#if __BSD_VISIBLE +#define D_MD_ORDER 57 /* month/day order (local extension) */ +#endif + +__BEGIN_DECLS +char *nl_langinfo(nl_item); +__END_DECLS + +#endif /* !_LANGINFO_H_ */ diff --git a/src/include/libatm.h b/src/include/libatm.h new file mode 100644 index 0000000..bbd7b5d --- /dev/null +++ b/src/include/libatm.h @@ -0,0 +1,117 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $FreeBSD: src/lib/libatm/libatm.h,v 1.7 2003/07/29 13:35:03 harti Exp $ + * + */ + +/* + * User Space Library Functions + * ---------------------------- + * + * Library functions + * + */ + +#ifndef _HARP_LIBHARP_H +#define _HARP_LIBHARP_H + +/* + * Start a HARP user-space timer + * + * tp pointer to timer control block + * time number of seconds for timer to run + * fp pointer to function to call at expiration + */ +#define HARP_TIMER(tp, time, fp) \ +{ \ + (tp)->ht_ticks = (time); \ + (tp)->ht_mark = 0; \ + (tp)->ht_func = (fp); \ + LINK2HEAD((tp), Harp_timer, harp_timer_head, ht_next); \ +} + +/* + * Cancel a HARP user-space timer + * + * tp pointer to timer control block + */ +#define HARP_CANCEL(tp) \ +{ \ + UNLINK((tp), Harp_timer, harp_timer_head, ht_next); \ +} + + +/* + * HARP user-space timer control block + */ +struct harp_timer { + struct harp_timer *ht_next; /* Timer chain */ + int ht_ticks; /* Seconds till exp */ + int ht_mark; /* Processing flag */ + void (*ht_func)(struct harp_timer *); /* Function to call */ +}; +typedef struct harp_timer Harp_timer; + + +/* + * Externally-visible variables and functions + */ + +/* atm_addr.c */ +extern int get_hex_atm_addr(const char *, u_char *, int); +extern char *format_atm_addr(const Atm_addr *); + +/* cache_key.c */ +extern void scsp_cache_key(const Atm_addr *, + const struct in_addr *, int, char *); + +/* ioctl_subr.c */ +extern ssize_t do_info_ioctl(struct atminfreq *, size_t); +extern ssize_t get_vcc_info(const char *, struct air_vcc_rsp **); +extern int get_subnet_mask(const char *, struct sockaddr_in *); +extern int get_mtu(const char *); +extern int verify_nif_name(const char *); +extern ssize_t get_cfg_info(const char *, struct air_cfg_rsp **); +extern ssize_t get_intf_info(const char *, struct air_int_rsp **); +extern ssize_t get_netif_info(const char *, struct air_netif_rsp **); + +/* ip_addr.c */ +extern struct sockaddr_in *get_ip_addr(const char *); +extern const char *format_ip_addr(const struct in_addr *); + +/* ip_checksum.c */ +extern short ip_checksum(const char *, int); + +/* timer.c */ +extern Harp_timer *harp_timer_head; +extern int harp_timer_exec; +extern void timer_proc(void); +extern int init_timer(void); +extern int block_timer(void); +extern void enable_timer(int); + + +#endif /* _HARP_LIBHARP_H */ diff --git a/src/include/libc_private.h b/src/include/libc_private.h new file mode 100644 index 0000000..63f8610 --- /dev/null +++ b/src/include/libc_private.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 1998 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. + * + * $FreeBSD: src/lib/libc/include/libc_private.h,v 1.11 2003/11/05 18:17:30 deischen Exp $ + * + * Private definitions for libc, libc_r and libpthread. + * + */ + +#ifndef _LIBC_PRIVATE_H_ +#define _LIBC_PRIVATE_H_ + +/* + * This global flag is non-zero when a process has created one + * or more threads. It is used to avoid calling locking functions + * when they are not required. + */ +extern int __isthreaded; + +/* + * File lock contention is difficult to diagnose without knowing + * where locks were set. Allow a debug library to be built which + * records the source file and line number of each lock call. + */ +#ifdef _FLOCK_DEBUG +#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) +#else +#define _FLOCKFILE(x) _flockfile(x) +#endif + +/* + * Macros for locking and unlocking FILEs. These test if the + * process is threaded to avoid locking when not required. + */ +#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) +#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) + +/* + * Indexes into the pthread jump table. + * + * Warning! If you change this type, you must also change the threads + * libraries that reference it (libc_r, libpthread). + */ +typedef enum { + PJT_COND_BROADCAST, + PJT_COND_DESTROY, + PJT_COND_INIT, + PJT_COND_SIGNAL, + PJT_COND_WAIT, + PJT_GETSPECIFIC, + PJT_KEY_CREATE, + PJT_KEY_DELETE, + PJT_MAIN_NP, + PJT_MUTEX_DESTROY, + PJT_MUTEX_INIT, + PJT_MUTEX_LOCK, + PJT_MUTEX_TRYLOCK, + PJT_MUTEX_UNLOCK, + PJT_MUTEXATTR_DESTROY, + PJT_MUTEXATTR_INIT, + PJT_MUTEXATTR_SETTYPE, + PJT_ONCE, + PJT_RWLOCK_DESTROY, + PJT_RWLOCK_INIT, + PJT_RWLOCK_RDLOCK, + PJT_RWLOCK_TRYRDLOCK, + PJT_RWLOCK_TRYWRLOCK, + PJT_RWLOCK_UNLOCK, + PJT_RWLOCK_WRLOCK, + PJT_SELF, + PJT_SETSPECIFIC, + PJT_SIGMASK, + PJT_MAX +} pjt_index_t; + +typedef int (*pthread_func_t)(void); +typedef pthread_func_t pthread_func_entry_t[2]; + +extern pthread_func_entry_t __thr_jtable[]; + +/* + * yplib internal interfaces + */ +#ifdef YP +int _yp_check(char **); +#endif + + +/* + * This is a pointer in the C run-time startup code. It is used + * by getprogname() and setprogname(). + */ +extern const char *__progname; + +/* + * This is the lock to make malloc() thread-safe. It is externalized + * so that thread libraries can protect malloc across fork(). + */ +extern struct _spinlock *__malloc_lock; + +#endif /* _LIBC_PRIVATE_H_ */ diff --git a/src/include/libdisk.h b/src/include/libdisk.h new file mode 100644 index 0000000..5c0734f --- /dev/null +++ b/src/include/libdisk.h @@ -0,0 +1,363 @@ +/* +* ---------------------------------------------------------------------------- +* "THE BEER-WARE LICENSE" (Revision 42): +* wrote this file. As long as you retain this notice you +* can do whatever you want with this stuff. If we meet some day, and you think +* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp +* ---------------------------------------------------------------------------- +* +* $FreeBSD: src/lib/libdisk/libdisk.h,v 1.62 2004/04/21 23:21:13 grehan Exp $ +* +*/ + +/* #define DEBUG 1 */ +/* You can define a particular architecture here if you are debugging. */ +/* #define P_DEBUG p_sparc64 */ + +#define MAX_NO_DISKS 32 +/* Max # of disks Disk_Names() will return */ + +#define MAX_SEC_SIZE 2048 /* maximum sector size that is supported */ +#define MIN_SEC_SIZE 512 /* the sector size to end sensing at */ + +enum platform { + p_any, /* for debugging ! */ + p_alpha, + p_i386, + p_pc98, + p_sparc64, + p_ia64, + p_ppc, + p_amd64 +}; +extern const enum platform platform; + +typedef enum { + whole, + unknown, + + sun, + pc98, + mbr, + gpt, + + efi, + fat, + freebsd, + extended, + part, + spare, + unused, + + apple +} chunk_e; + +__BEGIN_DECLS +#ifndef __ia64__ +struct disk { + char *name; + u_long bios_cyl; + u_long bios_hd; + u_long bios_sect; +#ifdef PC98 + u_char *bootipl; + size_t bootipl_size; + u_char *bootmenu; + size_t bootmenu_size; +#else + u_char *bootmgr; + size_t bootmgr_size; +#endif + u_char *boot1; +#if defined(__i386__) || defined(__amd64__) /* the i386 needs extra help... */ + u_char *boot2; +#endif + struct chunk *chunks; + u_long sector_size; /* media sector size, a power of 2 */ +}; +#else /* !__ia64__ */ +struct disk { + char *name; + struct chunk *chunks; + u_long media_size; + u_long sector_size; + u_long lba_start; + u_long lba_end; + u_int gpt_size; /* Number of entries */ +}; +#endif + +struct chunk { + struct chunk *next; + struct chunk *part; + struct disk *disk; + daddr_t offset; + daddr_t size; + daddr_t end; + char *sname; /* PC98 field */ + char *name; + char *oname; + /* Used during Fixup_Names() to avoid renaming more than + * absolutely needed. + */ + chunk_e type; + int subtype; + u_long flags; + void (*private_free)(void*); + void *(*private_clone)(void*); + void *private_data; + /* For data private to the application, and the management + * thereof. If the functions are not provided, no storage + * management is done, Cloning will just copy the pointer + * and freeing will just forget it. + */ +}; + +/* + * flags: + * + * ALIGN - This chunk should be aligned + * IS_ROOT - This 'part' is a rootfs, allocate 'a' + * ACTIVE - This is the active slice in the MBR + * FORCE_ALL - Force a dedicated disk for FreeBSD, bypassing + * all BIOS geometry considerations + * AUTO_SIZE - This chunk was auto-sized and can fill-out a + * following chunk if the following chunk is deleted. + * NEWFS - newfs pending, used to enable auto-resizing on + * delete (along with AUTO_SIZE). + */ + +#define CHUNK_ALIGN 0x0008 +#define CHUNK_IS_ROOT 0x0010 +#define CHUNK_ACTIVE 0x0020 +#define CHUNK_FORCE_ALL 0x0040 +#define CHUNK_AUTO_SIZE 0x0080 +#define CHUNK_NEWFS 0x0100 +#define CHUNK_HAS_INDEX 0x0200 +#define CHUNK_ITOF(i) ((i & 0xFFFF) << 16) +#define CHUNK_FTOI(f) ((f >> 16) & 0xFFFF) + +#define DELCHUNK_NORMAL 0x0000 +#define DELCHUNK_RECOVER 0x0001 + +const char *chunk_name(chunk_e); + +const char * +slice_type_name(int, int); +/* "chunk_n" for subtypes too */ + +struct disk * +Open_Disk(const char *); +/* Will open the named disk, and return populated tree. */ + +void +Free_Disk(struct disk *); +/* Free a tree made with Open_Disk() or Clone_Disk() */ + +void +Debug_Disk(struct disk *); +/* Print the content of the tree to stdout */ + +void +Set_Bios_Geom(struct disk *, u_long, u_long, u_long); +/* Set the geometry the bios uses. */ + +void +Sanitize_Bios_Geom(struct disk *); +/* Set the bios geometry to something sane */ + +int +Insert_Chunk(struct chunk *, daddr_t, daddr_t, const char *, chunk_e, int, + u_long, const char *); + +int +Delete_Chunk2(struct disk *, struct chunk *, int); +/* Free a chunk of disk_space modified by the passed flags. */ + +int +Delete_Chunk(struct disk *, struct chunk *); +/* Free a chunk of disk_space */ + +void +Collapse_Disk(struct disk *); +/* Experimental, do not use. */ + +int +Collapse_Chunk(struct disk *, struct chunk *); +/* Experimental, do not use. */ + +int +Create_Chunk(struct disk *, daddr_t, daddr_t, chunk_e, int, u_long, const char *); +/* Create a chunk with the specified paramters */ + +void +All_FreeBSD(struct disk *, int); +/* + * Make one FreeBSD chunk covering the entire disk; + * if force_all is set, bypass all BIOS geometry + * considerations. + */ + +char * +CheckRules(const struct disk *); +/* Return char* to warnings about broken design rules in this disklayout */ + +char ** +Disk_Names(void); +/* + * Return char** with all disk's names (wd0, wd1 ...). You must free + * each pointer, as well as the array by hand + */ + +#ifdef PC98 +void +Set_Boot_Mgr(struct disk *, const u_char *, const size_t, const u_char *, + const size_t); +#else +void +Set_Boot_Mgr(struct disk *, const u_char *, const size_t); +#endif +/* + * Use this boot-manager on this disk. Gets written when Write_Disk() + * is called + */ + +int +Set_Boot_Blocks(struct disk *, const u_char *, const u_char *); +/* + * Use these boot-blocks on this disk. Gets written when Write_Disk() + * is called. Returns nonzero upon failure. + */ + +int +Write_Disk(const struct disk *); +/* Write all the MBRs, disklabels, bootblocks and boot managers */ + +daddr_t +Next_Cyl_Aligned(const struct disk *, daddr_t); +/* Round offset up to next cylinder according to the bios-geometry */ + +daddr_t +Prev_Cyl_Aligned(const struct disk *, daddr_t); +/* Round offset down to previous cylinder according to the bios-geometry */ + +int +Track_Aligned(const struct disk *, daddr_t); +/* Check if offset is aligned on a track according to the bios geometry */ + +daddr_t +Next_Track_Aligned(const struct disk *, daddr_t); +/* Round offset up to next track according to the bios-geometry */ + +daddr_t +Prev_Track_Aligned(const struct disk *, daddr_t); +/* Check if offset is aligned on a track according to the bios geometry */ + +struct chunk * +Create_Chunk_DWIM(struct disk *, struct chunk *, daddr_t, chunk_e, int, + u_long); +/* + * This one creates a partition inside the given parent of the given + * size, and returns a pointer to it. The first unused chunk big + * enough is used. + */ + +char * +ShowChunkFlags(struct chunk *); +/* Return string to show flags. */ + +/* + * Implementation details >>> DO NOT USE <<< + */ + +struct disklabel; + +void Fill_Disklabel(struct disklabel *, const struct disk *, + const struct chunk *); +void Debug_Chunk(struct chunk *); +struct chunk *New_Chunk(void); +void Free_Chunk(struct chunk *); +struct chunk *Clone_Chunk(const struct chunk *); +int Add_Chunk(struct disk *, daddr_t, daddr_t, const char *, chunk_e, int, + u_long, const char *); +void *read_block(int, daddr_t, u_long); +int write_block(int, daddr_t, const void *, u_long); +struct disklabel *read_disklabel(int, daddr_t, u_long); +struct disk *Int_Open_Disk(const char *, char *); +int Fixup_Names(struct disk *); +int MakeDevChunk(const struct chunk *, const char *); +__END_DECLS + +#define dprintf printf + +/* TODO + * + * Need an error string mechanism from the functions instead of warn() + * + * Make sure only FreeBSD start at offset==0 + * + * Collapse must align. + * + * Make Write_Disk(struct disk*) + * + * Consider booting from OnTrack'ed disks. + * + * Get Bios-geom, ST506 & OnTrack from driver (or otherwise) + * + * Make Create_DWIM(). + * + * Make Is_Unchanged(struct disk *d1, struct chunk *c1) + * + * don't rename slices unless we have to + * + *Sample output from tst01: + * + * Debug_Disk(wd0) flags=0 bios_geom=0/0/0 + * >> 0x3d040 0 1411200 1411199 wd0 0 whole 0 0 + * >>>> 0x3d080 0 960120 960119 wd0s1 3 freebsd 0 8 + * >>>>>> 0x3d100 0 40960 40959 wd0s1a 5 part 0 0 + * >>>>>> 0x3d180 40960 131072 172031 wd0s1b 5 part 0 0 + * >>>>>> 0x3d1c0 172032 409600 581631 wd0s1e 5 part 0 0 + * >>>>>> 0x3d200 581632 378488 960119 wd0s1f 5 part 0 0 + * >>>> 0x3d140 960120 5670 965789 wd0s2 4 extended 0 8 + * >>>>>> 0x3d2c0 960120 63 960182 - 6 unused 0 0 + * >>>>>> 0x3d0c0 960183 5607 965789 wd0s5 2 fat 0 8 + * >>>> 0x3d280 965790 1890 967679 wd0s3 1 foo -2 8 + * >>>> 0x3d300 967680 443520 1411199 wd0s4 3 freebsd 0 8 + * >>>>>> 0x3d340 967680 443520 1411199 wd0s4a 5 part 0 0 + * + * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ + * level chunkptr start size end name type subtype flags + * + * Underlying data structure: + * + * Legend: + * --> part + * | + * v next + * + * --> --> + * | | + * | v + * | + * | | + * | v + * | + * | | + * | v + * | + * | + * v + * --> + * | | + * | v + * | + * | + * v + * + * | + * v + * --> + * + * + */ diff --git a/src/include/libgen.h b/src/include/libgen.h new file mode 100644 index 0000000..df21c66 --- /dev/null +++ b/src/include/libgen.h @@ -0,0 +1,49 @@ +/* $OpenBSD: libgen.h,v 1.4 1999/05/28 22:00:22 espie Exp $ */ +/* $FreeBSD: src/include/libgen.h,v 1.2 2002/03/23 17:24:53 imp Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. + */ + +#ifndef _LIBGEN_H_ +#define _LIBGEN_H_ + +#include + +__BEGIN_DECLS + +char *basename(const char *); +char *dirname(const char *); +#if 0 +char *regcmp(const char *, ...); +char *regex(const char *, const char *, ...); + +extern char *__loc1; +#endif + +__END_DECLS + +#endif /* _LIBGEN_H_ */ diff --git a/src/include/libgeom.h b/src/include/libgeom.h new file mode 100644 index 0000000..17b410b --- /dev/null +++ b/src/include/libgeom.h @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * 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. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libgeom/libgeom.h,v 1.10 2004/03/09 21:14:18 jhb Exp $ + */ +#ifndef _LIBGEOM_H_ +#define _LIBGEOM_H_ + +#include + +#include +#include + +#include + +__BEGIN_DECLS + +void geom_stats_close(void); +void geom_stats_resync(void); +int geom_stats_open(void); +void *geom_stats_snapshot_get(void); +void geom_stats_snapshot_free(void *arg); +void geom_stats_snapshot_timestamp(void *arg, struct timespec *tp); +void geom_stats_snapshot_reset(void *arg); +struct devstat *geom_stats_snapshot_next(void *arg); + +char *geom_getxml(void); + +/* geom_xml2tree.c */ + +/* + * These structs are used to build the tree based on the XML. + * they're named as the kernel variant without the first '_'. + */ + +struct gclass; +struct ggeom; +struct gconsumer; +struct gprovider; + +LIST_HEAD(gconf, gconfig); + +struct gident { + void *lg_id; + void *lg_ptr; + enum { ISCLASS, + ISGEOM, + ISPROVIDER, + ISCONSUMER } lg_what; +}; + +struct gmesh { + LIST_HEAD(, gclass) lg_class; + struct gident *lg_ident; +}; + +struct gconfig { + LIST_ENTRY(gconfig) lg_config; + char *lg_name; + char *lg_val; +}; + +struct gclass { + void *lg_id; + char *lg_name; + LIST_ENTRY(gclass) lg_class; + LIST_HEAD(, ggeom) lg_geom; + struct gconf lg_config; +}; + +struct ggeom { + void *lg_id; + struct gclass *lg_class; + char *lg_name; + u_int lg_rank; + LIST_ENTRY(ggeom) lg_geom; + LIST_HEAD(, gconsumer) lg_consumer; + LIST_HEAD(, gprovider) lg_provider; + struct gconf lg_config; +}; + +struct gconsumer { + void *lg_id; + struct ggeom *lg_geom; + LIST_ENTRY(gconsumer) lg_consumer; + struct gprovider *lg_provider; + LIST_ENTRY(gconsumer) lg_consumers; + char *lg_mode; + struct gconf lg_config; +}; + +struct gprovider { + void *lg_id; + char *lg_name; + struct ggeom *lg_geom; + LIST_ENTRY(gprovider) lg_provider; + LIST_HEAD(, gconsumer) lg_consumers; + char *lg_mode; + off_t lg_mediasize; + u_int lg_sectorsize; + struct gconf lg_config; +}; + +struct gident * geom_lookupid(struct gmesh *gmp, const void *id); +int geom_xml2tree(struct gmesh *gmp, char *p); +int geom_gettree(struct gmesh *gmp); +void geom_deletetree(struct gmesh *gmp); + +/* geom_ctl.c */ + +struct gctl_req; + +#ifdef _STDIO_H_ /* limit #include pollution */ +void gctl_dump(struct gctl_req *req, FILE *f); +#endif +void gctl_free(struct gctl_req *req); +struct gctl_req *gctl_get_handle(void); +const char *gctl_issue(struct gctl_req *req); +void gctl_ro_param(struct gctl_req *req, const char *name, int len, const void* val); +void gctl_rw_param(struct gctl_req *req, const char *name, int len, void* val); + +__END_DECLS + +#endif /* _LIBGEOM_H_ */ diff --git a/src/include/libufs.h b/src/include/libufs.h new file mode 100644 index 0000000..102477d --- /dev/null +++ b/src/include/libufs.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2002 Juli Mallett. All rights reserved. + * + * This software was written by Juli Mallett for the + * FreeBSD project. Redistribution and use in source and binary forms, with + * or without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistribution 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/lib/libufs/libufs.h,v 1.11 2003/06/09 09:47:38 jmallett Exp $ + */ + +#ifndef __LIBUFS_H__ +#define __LIBUFS_H__ + +/* + * libufs macros (internal, non-exported). + */ +#ifdef _LIBUFS +#ifdef _LIBUFS_DEBUGGING +/* + * Trace steps through libufs, to be used at entry and erroneous return. + */ +#define ERROR(uufsd, str) \ +do { \ + fprintf(stderr, "libufs in %s", __func__); \ + if (str != NULL) \ + fprintf(stderr, ": %s", str); \ + if (errno) \ + fprintf(stderr, ": %s", strerror(errno)); \ + fprintf(stderr, "\n"); \ + if ((uufsd) != NULL) \ + (uufsd)->d_error = str; \ +} while (0) +#else /* _LIBUFS_DEBUGGING */ +#define ERROR(uufsd, str) \ +do { \ + if ((uufsd) != NULL) \ + (uufsd)->d_error = str; \ +} while (0) +#endif /* _LIBUFS_DEBUGGING */ +#endif /* _LIBUFS */ + +/* + * libufs structures. + */ + +/* + * userland ufs disk. + */ +struct uufsd { + const char *d_name; /* disk name */ + int d_ufs; /* decimal UFS version */ + int d_fd; /* raw device file descriptor */ + long d_bsize; /* device bsize */ + ufs2_daddr_t d_sblock; /* superblock location */ + caddr_t d_inoblock; /* inode block */ + ino_t d_inomin; /* low inode */ + ino_t d_inomax; /* high inode */ + union { + struct fs d_fs; /* filesystem information */ + char d_sb[MAXBSIZE]; + /* superblock as buffer */ + } d_sbunion; + union { + struct cg d_cg; /* cylinder group */ + char d_buf[MAXBSIZE]; + /* cylinder group storage */ + } d_cgunion; + int d_ccg; /* current cylinder group */ + int d_lcg; /* last cylinder group (in d_cg) */ + const char *d_error; /* human readable disk error */ + int d_mine; /* internal flags */ +#define d_fs d_sbunion.d_fs +#define d_sb d_sbunion.d_sb +#define d_cg d_cgunion.d_cg +}; + +__BEGIN_DECLS + +/* + * libufs prototypes. + */ + +/* + * block.c + */ +ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t); +ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t); + +/* + * cgroup.c + */ +int cgread(struct uufsd *); +int cgread1(struct uufsd *, int); + +/* + * inode.c + */ +int getino(struct uufsd *, void **, ino_t, int *); + +/* + * sblock.c + */ +int sbread(struct uufsd *); +int sbwrite(struct uufsd *, int); + +/* + * type.c + */ +int ufs_disk_close(struct uufsd *); +int ufs_disk_fillout(struct uufsd *, const char *); +int ufs_disk_fillout_blank(struct uufsd *, const char *); +int ufs_disk_write(struct uufsd *); + +__END_DECLS + +#endif /* __LIBUFS_H__ */ diff --git a/src/include/libutil.h b/src/include/libutil.h new file mode 100644 index 0000000..de32ac7 --- /dev/null +++ b/src/include/libutil.h @@ -0,0 +1,132 @@ +/* + * Copyright (c) 1996 Peter Wemm . + * All rights reserved. + * Copyright (c) 2002 Networks Associates Technology, Inc. + * All rights reserved. + * + * Portions of this software were developed for the FreeBSD Project by + * ThinkSec AS and NAI Labs, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * Redistribution and use in source and binary forms, with or without + * modification, is 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libutil/libutil.h,v 1.39 2004/02/26 22:44:11 kientzle Exp $ + */ + +#ifndef _LIBUTIL_H_ +#define _LIBUTIL_H_ + +#define PROPERTY_MAX_NAME 64 +#define PROPERTY_MAX_VALUE 512 + +/* for properties.c */ +typedef struct _property { + struct _property *next; + char *name; + char *value; +} *properties; + +/* Avoid pulling in all the include files for no need */ +struct termios; +struct winsize; +struct utmp; +struct in_addr; + +__BEGIN_DECLS +void clean_environment(const char * const *_white, + const char * const *_more_white); +int extattr_namespace_to_string(int _attrnamespace, char **_string); +int extattr_string_to_namespace(const char *_string, int *_attrnamespace); +void login(struct utmp *_ut); +int login_tty(int _fd); +int logout(const char *_line); +void logwtmp(const char *_line, const char *_name, const char *_host); +void trimdomain(char *_fullhost, int _hostsize); +int openpty(int *_amaster, int *_aslave, char *_name, + struct termios *_termp, struct winsize *_winp); +int forkpty(int *_amaster, char *_name, + struct termios *_termp, struct winsize *_winp); +const char *uu_lockerr(int _uu_lockresult); +int uu_lock(const char *_ttyname); +int uu_unlock(const char *_ttyname); +int uu_lock_txfr(const char *_ttyname, pid_t _pid); +int _secure_path(const char *_path, uid_t _uid, gid_t _gid); +properties properties_read(int fd); +void properties_free(properties list); +char *property_find(properties list, const char *name); +char *auth_getval(const char *name); +int realhostname(char *host, size_t hsize, const struct in_addr *ip); +struct sockaddr; +int realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, + int addrlen); +#ifdef _STDIO_H_ /* avoid adding new includes */ +char *fparseln(FILE *, size_t *, size_t *, const char[3], int); +#endif + +#ifdef _PWD_H_ +int pw_copy(int _ffd, int _tfd, const struct passwd *_pw, struct passwd *_old_pw); +struct passwd *pw_dup(const struct passwd *_pw); +int pw_edit(int _notsetuid); +int pw_equal(const struct passwd *_pw1, const struct passwd *_pw2); +void pw_fini(void); +int pw_init(const char *_dir, const char *_master); +char *pw_make(const struct passwd *_pw); +int pw_mkdb(const char *_user); +int pw_lock(void); +struct passwd *pw_scan(const char *_line, int _flags); +const char *pw_tempname(void); +int pw_tmp(int _mfd); +#endif +__END_DECLS + +#define UU_LOCK_INUSE (1) +#define UU_LOCK_OK (0) +#define UU_LOCK_OPEN_ERR (-1) +#define UU_LOCK_READ_ERR (-2) +#define UU_LOCK_CREAT_ERR (-3) +#define UU_LOCK_WRITE_ERR (-4) +#define UU_LOCK_LINK_ERR (-5) +#define UU_LOCK_TRY_ERR (-6) +#define UU_LOCK_OWNER_ERR (-7) + +/* return values from realhostname() */ +#define HOSTNAME_FOUND (0) +#define HOSTNAME_INCORRECTNAME (1) +#define HOSTNAME_INVALIDADDR (2) +#define HOSTNAME_INVALIDNAME (3) + +/* fparseln(3) */ +#define FPARSELN_UNESCESC 0x01 +#define FPARSELN_UNESCCONT 0x02 +#define FPARSELN_UNESCCOMM 0x04 +#define FPARSELN_UNESCREST 0x08 +#define FPARSELN_UNESCALL 0x0f + +/* pw_scan() */ +#define PWSCAN_MASTER 0x01 +#define PWSCAN_WARN 0x02 + +#endif /* !_LIBUTIL_H_ */ diff --git a/src/include/limits.h b/src/include/limits.h new file mode 100644 index 0000000..587f01f --- /dev/null +++ b/src/include/limits.h @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 1988, 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. + * + * @(#)limits.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD: src/include/limits.h,v 1.16 2003/04/29 13:35:58 kan Exp $ + */ + +#ifndef _LIMITS_H_ +#define _LIMITS_H_ + +#include + +#if __POSIX_VISIBLE +#define _POSIX_ARG_MAX 4096 +#define _POSIX_CHILD_MAX 25 +#define _POSIX_LINK_MAX 8 +#define _POSIX_MAX_CANON 255 +#define _POSIX_MAX_INPUT 255 +#define _POSIX_NAME_MAX 14 +#define _POSIX_NGROUPS_MAX 8 +#define _POSIX_OPEN_MAX 20 +#define _POSIX_PATH_MAX 256 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_SSIZE_MAX 32767 +#define _POSIX_STREAM_MAX 8 +#define _POSIX_TZNAME_MAX 6 + +#define BC_BASE_MAX 99 /* max ibase/obase values in bc(1) */ +#define BC_DIM_MAX 2048 /* max array elements in bc(1) */ +#define BC_SCALE_MAX 99 /* max scale value in bc(1) */ +#define BC_STRING_MAX 1000 /* max const string length in bc(1) */ +#define COLL_WEIGHTS_MAX 0 /* max weights for order keyword */ +#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ +#define LINE_MAX 2048 /* max bytes in an input line */ +#define RE_DUP_MAX 255 /* max RE's in interval notation */ + +#define _POSIX2_BC_BASE_MAX 99 +#define _POSIX2_BC_DIM_MAX 2048 +#define _POSIX2_BC_SCALE_MAX 99 +#define _POSIX2_BC_STRING_MAX 1000 +#define _POSIX2_EQUIV_CLASS_MAX 2 +#define _POSIX2_EXPR_NEST_MAX 32 +#define _POSIX2_LINE_MAX 2048 +#define _POSIX2_RE_DUP_MAX 255 +#endif + +#if __POSIX_VISIBLE >= 199309 +#define _POSIX_AIO_LISTIO_MAX 16 +#define _POSIX_AIO_MAX 1 +#define _POSIX_DELAYTIMER_MAX 32 +#define _POSIX_MQ_OPEN_MAX 8 +#define _POSIX_MQ_PRIO_MAX 32 +#define _POSIX_RTSIG_MAX 8 +#define _POSIX_SEM_NSEMS_MAX 256 +#define _POSIX_SEM_VALUE_MAX 32767 +#define _POSIX_SIGQUEUE_MAX 32 +#define _POSIX_TIMER_MAX 32 +#endif + +#if __POSIX_VISIBLE >= 199506 +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_THREADS_MAX 64 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _POSIX_HOST_NAME_MAX 255 +#define _POSIX_LOGIN_NAME_MAX 9 +#define _POSIX_SS_REPL_MAX 4 +#define _POSIX_SYMLINK_MAX 255 +#define _POSIX_SYMLOOP_MAX 8 +#define _POSIX_TRACE_EVENT_NAME_MAX 30 +#define _POSIX_TRACE_NAME_MAX 8 +#define _POSIX_TRACE_SYS_MAX 8 +#define _POSIX_TRACE_USER_EVENT_MAX 32 +#define _POSIX_TTY_NAME_MAX 9 +#define _POSIX2_CHARCLASS_NAME_MAX 14 +#define _POSIX2_COLL_WEIGHTS_MAX 2 + +#define _POSIX_RE_DUP_MAX _POSIX2_RE_DUP_MAX +#endif + +#if __XSI_VISIBLE +#define _XOPEN_IOV_MAX 16 +#define _XOPEN_NAME_MAX 255 +#define _XOPEN_PATH_MAX 1024 +#define PASS_MAX 128 /* _PASSWORD_LEN from */ + +#define NL_ARGMAX 99 /* max # of position args for printf */ +#define NL_LANGMAX 31 /* max LANG name length */ +#define NL_MSGMAX 32767 +#define NL_NMAX 1 +#define NL_SETMAX 255 +#define NL_TEXTMAX 2048 +#endif + +#define MB_LEN_MAX 6 /* 31-bit UTF-8 */ + +#include + +#if __POSIX_VISIBLE +#include +#endif + +#endif /* !_LIMITS_H_ */ diff --git a/src/include/link.h b/src/include/link.h new file mode 100644 index 0000000..bb1c737 --- /dev/null +++ b/src/include/link.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/include/link.h,v 1.25 2002/09/17 01:48:50 peter Exp $ + */ + +#include diff --git a/src/include/linker_set.h b/src/include/linker_set.h new file mode 100644 index 0000000..08bc93d --- /dev/null +++ b/src/include/linker_set.h @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 1999 John D. Polstra + * Copyright (c) 1999,2001 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/linker_set.h,v 1.14 2004/03/12 21:45:32 trhodes Exp $ + */ + +#ifndef _SYS_LINKER_SET_H_ +#define _SYS_LINKER_SET_H_ + +/* + * The following macros are used to declare global sets of objects, which + * are collected by the linker into a `linker_set' as defined below. + * For ELF, this is done by constructing a separate segment for each set. + */ + +/* + * Private macros, not to be used outside this header file. + */ +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#define __MAKE_SET(set, sym) \ + static void const * const __set_##set##_sym_##sym \ + __section("set_" #set) __unused = &sym +#else /* !(__GNUC__ || __INTEL_COMPILER) */ +#ifndef lint +#error "This file needs to be compiled by GCC, an Intel compiler or lint" +#endif /* lint */ +#define __MAKE_SET(set, sym) extern void const * const (__set_##set##_sym_##sym) +#endif /* __GNUC__ || __INTEL_COMPILER */ + +/* + * Public macros. + */ +#define TEXT_SET(set, sym) __MAKE_SET(set, sym) +#define DATA_SET(set, sym) __MAKE_SET(set, sym) +#define BSS_SET(set, sym) __MAKE_SET(set, sym) +#define ABS_SET(set, sym) __MAKE_SET(set, sym) +#define SET_ENTRY(set, sym) __MAKE_SET(set, sym) + +/* + * Initialize before referring to a give linker set + */ +#define SET_DECLARE(set, ptype) \ + extern ptype *__CONCAT(__start_set_,set); \ + extern ptype *__CONCAT(__stop_set_,set) + +#define SET_BEGIN(set) \ + (&__CONCAT(__start_set_,set)) +#define SET_LIMIT(set) \ + (&__CONCAT(__stop_set_,set)) + +/* + * Iterate over all the elements of a set. + * + * Sets always contain addresses of things, and "pvar" points to words + * containing those addresses. Thus is must be declared as "type **pvar", + * and the address of each set item is obtained inside the loop by "*pvar". + */ +#define SET_FOREACH(pvar, set) \ + for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) + +#define SET_ITEM(set, i) \ + ((SET_BEGIN(set))[i]) + +/* + * Provide a count of the items in a set. + */ +#define SET_COUNT(set) \ + (SET_LIMIT(set) - SET_BEGIN(set)) + +#endif /* _SYS_LINKER_SET_H_ */ diff --git a/src/include/locale.h b/src/include/locale.h new file mode 100644 index 0000000..b5a48ea --- /dev/null +++ b/src/include/locale.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1991, 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. + * + * @(#)locale.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/locale.h,v 1.8 2003/12/07 21:10:06 marcel Exp $ + */ + +#ifndef _LOCALE_H_ +#define _LOCALE_H_ + +#include + +struct lconv { + char *decimal_point; + char *thousands_sep; + char *grouping; + char *int_curr_symbol; + char *currency_symbol; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +}; + +#define LC_ALL 0 +#define LC_COLLATE 1 +#define LC_CTYPE 2 +#define LC_MONETARY 3 +#define LC_NUMERIC 4 +#define LC_TIME 5 +#define LC_MESSAGES 6 + +#define _LC_LAST 7 /* marks end */ + +#include + +__BEGIN_DECLS +struct lconv *localeconv(void); +char *setlocale(int, const char *); +__END_DECLS + +#endif /* _LOCALE_H_ */ diff --git a/src/include/login_cap.h b/src/include/login_cap.h new file mode 100644 index 0000000..7860c99 --- /dev/null +++ b/src/include/login_cap.h @@ -0,0 +1,158 @@ +/*- + * Copyright (c) 1996 by + * Sean Eric Fagan + * David Nugent + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice immediately at the beginning of the file, without modification, + * 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. This work was done expressly for inclusion into FreeBSD. Other use + * is permitted provided this notation is included. + * 4. Absolutely no warranty of function or purpose is made by the authors. + * 5. Modifications may be freely made to this file providing the above + * conditions are met. + * + * Low-level routines relating to the user capabilities database + * + * Was login_cap.h,v 1.9 1997/05/07 20:00:01 eivind Exp + * $FreeBSD: src/lib/libutil/login_cap.h,v 1.9 2003/10/18 10:04:16 markm Exp $ + */ + +#ifndef _LOGIN_CAP_H_ +#define _LOGIN_CAP_H_ + +#define LOGIN_DEFCLASS "default" +#define LOGIN_DEFROOTCLASS "root" +#define LOGIN_MECLASS "me" +#define LOGIN_DEFSTYLE "passwd" +#define LOGIN_DEFSERVICE "login" +#define LOGIN_DEFUMASK 022 +#define LOGIN_DEFPRI 0 +#define _PATH_LOGIN_CONF "/etc/login.conf" +#define _FILE_LOGIN_CONF ".login_conf" +#define _PATH_AUTHPROG "/usr/libexec/login_" + +#define LOGIN_SETGROUP 0x0001 /* set group */ +#define LOGIN_SETLOGIN 0x0002 /* set login (via setlogin) */ +#define LOGIN_SETPATH 0x0004 /* set path */ +#define LOGIN_SETPRIORITY 0x0008 /* set priority */ +#define LOGIN_SETRESOURCES 0x0010 /* set resources (cputime, etc.) */ +#define LOGIN_SETUMASK 0x0020 /* set umask, obviously */ +#define LOGIN_SETUSER 0x0040 /* set user (via setuid) */ +#define LOGIN_SETENV 0x0080 /* set user environment */ +#define LOGIN_SETMAC 0x0100 /* set user default MAC label */ +#define LOGIN_SETALL 0x01ff /* set everything */ + +#define BI_AUTH "authorize" /* accepted authentication */ +#define BI_REJECT "reject" /* rejected authentication */ +#define BI_CHALLENG "reject challenge" /* reject with a challenge */ +#define BI_SILENT "reject silent" /* reject silently */ +#define BI_REMOVE "remove" /* remove file on error */ +#define BI_ROOTOKAY "authorize root" /* root authenticated */ +#define BI_SECURE "authorize secure" /* okay on non-secure line */ +#define BI_SETENV "setenv" /* set environment variable */ +#define BI_VALUE "value" /* set local variable */ + +#define AUTH_OKAY 0x01 /* user authenticated */ +#define AUTH_ROOTOKAY 0x02 /* root login okay */ +#define AUTH_SECURE 0x04 /* secure login */ +#define AUTH_SILENT 0x08 /* silent rejection */ +#define AUTH_CHALLENGE 0x10 /* a chellenge was given */ + +#define AUTH_ALLOW (AUTH_OKAY | AUTH_ROOTOKAY | AUTH_SECURE) + +typedef struct login_cap { + char *lc_class; + char *lc_cap; + char *lc_style; +} login_cap_t; + +typedef struct login_time { + u_short lt_start; /* Start time */ + u_short lt_end; /* End time */ +#define LTM_NONE 0x00 +#define LTM_SUN 0x01 +#define LTM_MON 0x02 +#define LTM_TUE 0x04 +#define LTM_WED 0x08 +#define LTM_THU 0x10 +#define LTM_FRI 0x20 +#define LTM_SAT 0x40 +#define LTM_ANY 0x7F +#define LTM_WK 0x3E +#define LTM_WD 0x41 + u_char lt_dow; /* Days of week */ +} login_time_t; + +#define LC_MAXTIMES 64 + +#include +__BEGIN_DECLS +struct passwd; + +void login_close(login_cap_t *); +login_cap_t *login_getclassbyname(const char *, const struct passwd *); +login_cap_t *login_getclass(const char *); +login_cap_t *login_getpwclass(const struct passwd *); +login_cap_t *login_getuserclass(const struct passwd *); + +const char *login_getcapstr(login_cap_t*, const char *, const char *, const char *); +const char **login_getcaplist(login_cap_t *, const char *, const char *); +const char *login_getstyle(login_cap_t *, const char *, const char *); +rlim_t login_getcaptime(login_cap_t *, const char *, rlim_t, rlim_t); +rlim_t login_getcapnum(login_cap_t *, const char *, rlim_t, rlim_t); +rlim_t login_getcapsize(login_cap_t *, const char *, rlim_t, rlim_t); +const char *login_getpath(login_cap_t *, const char *, const char *); +int login_getcapbool(login_cap_t *, const char *, int); +const char *login_setcryptfmt(login_cap_t *, const char *, const char *); + +int setclasscontext(const char*, unsigned int); +int setusercontext(login_cap_t*, const struct passwd*, uid_t, unsigned int); +void setclassresources(login_cap_t *); +void setclassenvironment(login_cap_t *, const struct passwd *, int); + +/* Most of these functions are deprecated */ +int auth_approve(login_cap_t*, const char*, const char*); +int auth_check(const char *, const char *, const char *, const char *, int *); +void auth_env(void); +char *auth_mkvalue(const char *n); +int auth_response(const char *, const char *, const char *, const char *, int *, const char *, const char *); +void auth_rmfiles(void); +int auth_scan(int); +int auth_script(const char*, ...); +int auth_script_data(const char *, int, const char *, ...); +char *auth_valud(const char *); +int auth_setopt(const char *, const char *); +void auth_clropts(void); + +void auth_checknologin(login_cap_t*); +int auth_cat(const char*); + +int auth_ttyok(login_cap_t*, const char *); +int auth_hostok(login_cap_t*, const char *, char const *); +int auth_timeok(login_cap_t*, time_t); + +struct tm; + +login_time_t parse_lt(const char *); +int in_ltm(const login_time_t *, struct tm *, time_t *); +int in_ltms(const login_time_t *, struct tm *, time_t *); + +/* helper functions */ + +int login_strinlist(const char **, char const *, int); +int login_str2inlist(const char **, const char *, const char *, int); +login_time_t * login_timelist(login_cap_t *, char const *, int *, login_time_t **); +int login_ttyok(login_cap_t *, const char *, const char *, const char *); +int login_hostok(login_cap_t *, const char *, const char *, const char *, const char *); + +__END_DECLS + +#endif /* _LOGIN_CAP_H_ */ diff --git a/src/include/machine/_inttypes.h b/src/include/machine/_inttypes.h new file mode 100644 index 0000000..ccc41f2 --- /dev/null +++ b/src/include/machine/_inttypes.h @@ -0,0 +1,220 @@ +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + * + * From: $NetBSD: int_fmtio.h,v 1.2 2001/04/26 16:25:21 kleink Exp $ + * $FreeBSD: src/sys/i386/include/_inttypes.h,v 1.2 2002/06/30 05:48:02 mike Exp $ + */ + +#ifndef _MACHINE_INTTYPES_H_ +#define _MACHINE_INTTYPES_H_ + +/* + * Macros for format specifiers. + */ + +/* fprintf(3) macros for signed integers. */ + +#define PRId8 "d" /* int8_t */ +#define PRId16 "d" /* int16_t */ +#define PRId32 "d" /* int32_t */ +#define PRId64 "lld" /* int64_t */ +#define PRIdLEAST8 "d" /* int_least8_t */ +#define PRIdLEAST16 "d" /* int_least16_t */ +#define PRIdLEAST32 "d" /* int_least32_t */ +#define PRIdLEAST64 "lld" /* int_least64_t */ +#define PRIdFAST8 "d" /* int_fast8_t */ +#define PRIdFAST16 "d" /* int_fast16_t */ +#define PRIdFAST32 "d" /* int_fast32_t */ +#define PRIdFAST64 "lld" /* int_fast64_t */ +#define PRIdMAX "jd" /* intmax_t */ +#define PRIdPTR "d" /* intptr_t */ + +#define PRIi8 "i" /* int8_t */ +#define PRIi16 "i" /* int16_t */ +#define PRIi32 "i" /* int32_t */ +#define PRIi64 "lli" /* int64_t */ +#define PRIiLEAST8 "i" /* int_least8_t */ +#define PRIiLEAST16 "i" /* int_least16_t */ +#define PRIiLEAST32 "i" /* int_least32_t */ +#define PRIiLEAST64 "lli" /* int_least64_t */ +#define PRIiFAST8 "i" /* int_fast8_t */ +#define PRIiFAST16 "i" /* int_fast16_t */ +#define PRIiFAST32 "i" /* int_fast32_t */ +#define PRIiFAST64 "lli" /* int_fast64_t */ +#define PRIiMAX "ji" /* intmax_t */ +#define PRIiPTR "i" /* intptr_t */ + +/* fprintf(3) macros for unsigned integers. */ + +#define PRIo8 "o" /* uint8_t */ +#define PRIo16 "o" /* uint16_t */ +#define PRIo32 "o" /* uint32_t */ +#define PRIo64 "llo" /* uint64_t */ +#define PRIoLEAST8 "o" /* uint_least8_t */ +#define PRIoLEAST16 "o" /* uint_least16_t */ +#define PRIoLEAST32 "o" /* uint_least32_t */ +#define PRIoLEAST64 "llo" /* uint_least64_t */ +#define PRIoFAST8 "o" /* uint_fast8_t */ +#define PRIoFAST16 "o" /* uint_fast16_t */ +#define PRIoFAST32 "o" /* uint_fast32_t */ +#define PRIoFAST64 "llo" /* uint_fast64_t */ +#define PRIoMAX "jo" /* uintmax_t */ +#define PRIoPTR "o" /* uintptr_t */ + +#define PRIu8 "u" /* uint8_t */ +#define PRIu16 "u" /* uint16_t */ +#define PRIu32 "u" /* uint32_t */ +#define PRIu64 "llu" /* uint64_t */ +#define PRIuLEAST8 "u" /* uint_least8_t */ +#define PRIuLEAST16 "u" /* uint_least16_t */ +#define PRIuLEAST32 "u" /* uint_least32_t */ +#define PRIuLEAST64 "llu" /* uint_least64_t */ +#define PRIuFAST8 "u" /* uint_fast8_t */ +#define PRIuFAST16 "u" /* uint_fast16_t */ +#define PRIuFAST32 "u" /* uint_fast32_t */ +#define PRIuFAST64 "llu" /* uint_fast64_t */ +#define PRIuMAX "ju" /* uintmax_t */ +#define PRIuPTR "u" /* uintptr_t */ + +#define PRIx8 "x" /* uint8_t */ +#define PRIx16 "x" /* uint16_t */ +#define PRIx32 "x" /* uint32_t */ +#define PRIx64 "llx" /* uint64_t */ +#define PRIxLEAST8 "x" /* uint_least8_t */ +#define PRIxLEAST16 "x" /* uint_least16_t */ +#define PRIxLEAST32 "x" /* uint_least32_t */ +#define PRIxLEAST64 "llx" /* uint_least64_t */ +#define PRIxFAST8 "x" /* uint_fast8_t */ +#define PRIxFAST16 "x" /* uint_fast16_t */ +#define PRIxFAST32 "x" /* uint_fast32_t */ +#define PRIxFAST64 "llx" /* uint_fast64_t */ +#define PRIxMAX "jx" /* uintmax_t */ +#define PRIxPTR "x" /* uintptr_t */ + +#define PRIX8 "X" /* uint8_t */ +#define PRIX16 "X" /* uint16_t */ +#define PRIX32 "X" /* uint32_t */ +#define PRIX64 "llX" /* uint64_t */ +#define PRIXLEAST8 "X" /* uint_least8_t */ +#define PRIXLEAST16 "X" /* uint_least16_t */ +#define PRIXLEAST32 "X" /* uint_least32_t */ +#define PRIXLEAST64 "llX" /* uint_least64_t */ +#define PRIXFAST8 "X" /* uint_fast8_t */ +#define PRIXFAST16 "X" /* uint_fast16_t */ +#define PRIXFAST32 "X" /* uint_fast32_t */ +#define PRIXFAST64 "llX" /* uint_fast64_t */ +#define PRIXMAX "jX" /* uintmax_t */ +#define PRIXPTR "X" /* uintptr_t */ + +/* fscanf(3) macros for signed integers. */ + +#define SCNd8 "hhd" /* int8_t */ +#define SCNd16 "hd" /* int16_t */ +#define SCNd32 "d" /* int32_t */ +#define SCNd64 "lld" /* int64_t */ +#define SCNdLEAST8 "hhd" /* int_least8_t */ +#define SCNdLEAST16 "hd" /* int_least16_t */ +#define SCNdLEAST32 "d" /* int_least32_t */ +#define SCNdLEAST64 "lld" /* int_least64_t */ +#define SCNdFAST8 "d" /* int_fast8_t */ +#define SCNdFAST16 "d" /* int_fast16_t */ +#define SCNdFAST32 "d" /* int_fast32_t */ +#define SCNdFAST64 "lld" /* int_fast64_t */ +#define SCNdMAX "jd" /* intmax_t */ +#define SCNdPTR "d" /* intptr_t */ + +#define SCNi8 "hhi" /* int8_t */ +#define SCNi16 "hi" /* int16_t */ +#define SCNi32 "i" /* int32_t */ +#define SCNi64 "lli" /* int64_t */ +#define SCNiLEAST8 "hhi" /* int_least8_t */ +#define SCNiLEAST16 "hi" /* int_least16_t */ +#define SCNiLEAST32 "i" /* int_least32_t */ +#define SCNiLEAST64 "lli" /* int_least64_t */ +#define SCNiFAST8 "i" /* int_fast8_t */ +#define SCNiFAST16 "i" /* int_fast16_t */ +#define SCNiFAST32 "i" /* int_fast32_t */ +#define SCNiFAST64 "lli" /* int_fast64_t */ +#define SCNiMAX "ji" /* intmax_t */ +#define SCNiPTR "i" /* intptr_t */ + +/* fscanf(3) macros for unsigned integers. */ + +#define SCNo8 "hho" /* uint8_t */ +#define SCNo16 "ho" /* uint16_t */ +#define SCNo32 "o" /* uint32_t */ +#define SCNo64 "llo" /* uint64_t */ +#define SCNoLEAST8 "hho" /* uint_least8_t */ +#define SCNoLEAST16 "ho" /* uint_least16_t */ +#define SCNoLEAST32 "o" /* uint_least32_t */ +#define SCNoLEAST64 "llo" /* uint_least64_t */ +#define SCNoFAST8 "o" /* uint_fast8_t */ +#define SCNoFAST16 "o" /* uint_fast16_t */ +#define SCNoFAST32 "o" /* uint_fast32_t */ +#define SCNoFAST64 "llo" /* uint_fast64_t */ +#define SCNoMAX "jo" /* uintmax_t */ +#define SCNoPTR "o" /* uintptr_t */ + +#define SCNu8 "hhu" /* uint8_t */ +#define SCNu16 "hu" /* uint16_t */ +#define SCNu32 "u" /* uint32_t */ +#define SCNu64 "llu" /* uint64_t */ +#define SCNuLEAST8 "hhu" /* uint_least8_t */ +#define SCNuLEAST16 "hu" /* uint_least16_t */ +#define SCNuLEAST32 "u" /* uint_least32_t */ +#define SCNuLEAST64 "llu" /* uint_least64_t */ +#define SCNuFAST8 "u" /* uint_fast8_t */ +#define SCNuFAST16 "u" /* uint_fast16_t */ +#define SCNuFAST32 "u" /* uint_fast32_t */ +#define SCNuFAST64 "llu" /* uint_fast64_t */ +#define SCNuMAX "ju" /* uintmax_t */ +#define SCNuPTR "u" /* uintptr_t */ + +#define SCNx8 "hhx" /* uint8_t */ +#define SCNx16 "hx" /* uint16_t */ +#define SCNx32 "x" /* uint32_t */ +#define SCNx64 "llx" /* uint64_t */ +#define SCNxLEAST8 "hhx" /* uint_least8_t */ +#define SCNxLEAST16 "hx" /* uint_least16_t */ +#define SCNxLEAST32 "x" /* uint_least32_t */ +#define SCNxLEAST64 "llx" /* uint_least64_t */ +#define SCNxFAST8 "x" /* uint_fast8_t */ +#define SCNxFAST16 "x" /* uint_fast16_t */ +#define SCNxFAST32 "x" /* uint_fast32_t */ +#define SCNxFAST64 "llx" /* uint_fast64_t */ +#define SCNxMAX "jx" /* uintmax_t */ +#define SCNxPTR "x" /* uintptr_t */ + +#endif /* !_MACHINE_INTTYPES_H_ */ diff --git a/src/include/machine/_limits.h b/src/include/machine/_limits.h new file mode 100644 index 0000000..fcc7516 --- /dev/null +++ b/src/include/machine/_limits.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1988, 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. + * 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. + * + * @(#)limits.h 8.3 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/i386/include/_limits.h,v 1.26 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE__LIMITS_H_ +#define _MACHINE__LIMITS_H_ + +/* + * According to ANSI (section 2.2.4.2), the values below must be usable by + * #if preprocessing directives. Additionally, the expression must have the + * same type as would an expression that is an object of the corresponding + * type converted according to the integral promotions. The subtraction for + * INT_MIN, etc., is so the value is not unsigned; e.g., 0x80000000 is an + * unsigned int for 32-bit two's complement ANSI compilers (section 3.1.3.2). + * These numbers are for the default configuration of gcc. They work for + * some other compilers as well, but this should not be depended on. + */ + +#define __CHAR_BIT 8 /* number of bits in a char */ + +#define __SCHAR_MAX 0x7f /* max value for a signed char */ +#define __SCHAR_MIN (-0x7f - 1) /* min value for a signed char */ + +#define __UCHAR_MAX 0xff /* max value for an unsigned char */ + +#define __USHRT_MAX 0xffff /* max value for an unsigned short */ +#define __SHRT_MAX 0x7fff /* max value for a short */ +#define __SHRT_MIN (-0x7fff - 1) /* min value for a short */ + +#define __UINT_MAX 0xffffffffU /* max value for an unsigned int */ +#define __INT_MAX 0x7fffffff /* max value for an int */ +#define __INT_MIN (-0x7fffffff - 1) /* min value for an int */ + +/* Bad hack for gcc configured to give 64-bit longs. */ +#ifdef _LARGE_LONG +#define __ULONG_MAX 0xffffffffffffffffUL +#define __LONG_MAX 0x7fffffffffffffffL +#define __LONG_MIN (-0x7fffffffffffffffL - 1) +#else +#define __ULONG_MAX 0xffffffffUL /* max value for an unsigned long */ +#define __LONG_MAX 0x7fffffffL /* max value for a long */ +#define __LONG_MIN (-0x7fffffffL - 1) /* min value for a long */ +#endif + + /* max value for an unsigned long long */ +#define __ULLONG_MAX 0xffffffffffffffffULL +#define __LLONG_MAX 0x7fffffffffffffffLL /* max value for a long long */ +#define __LLONG_MIN (-0x7fffffffffffffffLL - 1) /* min for a long long */ + +#define __SSIZE_MAX __INT_MAX /* max value for a ssize_t */ + +#define __SIZE_T_MAX __UINT_MAX /* max value for a size_t */ + +#define __OFF_MAX __LLONG_MAX /* max value for an off_t */ +#define __OFF_MIN __LLONG_MIN /* min value for an off_t */ + +/* Quads and long longs are the same size. Ensure they stay in sync. */ +#define __UQUAD_MAX __ULLONG_MAX /* max value for a uquad_t */ +#define __QUAD_MAX __LLONG_MAX /* max value for a quad_t */ +#define __QUAD_MIN __LLONG_MIN /* min value for a quad_t */ + +#ifdef _LARGE_LONG +#define __LONG_BIT 64 +#else +#define __LONG_BIT 32 +#endif +#define __WORD_BIT 32 + +#endif /* !_MACHINE__LIMITS_H_ */ diff --git a/src/include/machine/_stdint.h b/src/include/machine/_stdint.h new file mode 100644 index 0000000..fbd3ced --- /dev/null +++ b/src/include/machine/_stdint.h @@ -0,0 +1,171 @@ +/*- + * Copyright (c) 2001, 2002 Mike Barcroft + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + * + * $FreeBSD: src/sys/i386/include/_stdint.h,v 1.1 2002/07/29 17:41:07 mike Exp $ + */ + +#ifndef _MACHINE__STDINT_H_ +#define _MACHINE__STDINT_H_ + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) + +#define INT8_C(c) (c) +#define INT16_C(c) (c) +#define INT32_C(c) (c) +#define INT64_C(c) (c ## LL) + +#define UINT8_C(c) (c) +#define UINT16_C(c) (c) +#define UINT32_C(c) (c ## U) +#define UINT64_C(c) (c ## ULL) + +#define INTMAX_C(c) (c ## LL) +#define UINTMAX_C(c) (c ## ULL) + +#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */ + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) + +/* + * ISO/IEC 9899:1999 + * 7.18.2.1 Limits of exact-width integer types + */ +/* Minimum values of exact-width signed integer types. */ +#define INT8_MIN (-0x7f-1) +#define INT16_MIN (-0x7fff-1) +#define INT32_MIN (-0x7fffffff-1) +#define INT64_MIN (-0x7fffffffffffffffLL-1) + +/* Maximum values of exact-width signed integer types. */ +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff +#define INT64_MAX 0x7fffffffffffffffLL + +/* Maximum values of exact-width unsigned integer types. */ +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffffU +#define UINT64_MAX 0xffffffffffffffffULL + +/* + * ISO/IEC 9899:1999 + * 7.18.2.2 Limits of minimum-width integer types + */ +/* Minimum values of minimum-width signed integer types. */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +/* Maximum values of minimum-width signed integer types. */ +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +/* Maximum values of minimum-width unsigned integer types. */ +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* + * ISO/IEC 9899:1999 + * 7.18.2.3 Limits of fastest minimum-width integer types + */ +/* Minimum values of fastest minimum-width signed integer types. */ +#define INT_FAST8_MIN INT32_MIN +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST64_MIN INT64_MIN + +/* Maximum values of fastest minimum-width signed integer types. */ +#define INT_FAST8_MAX INT32_MAX +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MAX INT64_MAX + +/* Maximum values of fastest minimum-width unsigned integer types. */ +#define UINT_FAST8_MAX UINT32_MAX +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +/* + * ISO/IEC 9899:1999 + * 7.18.2.4 Limits of integer types capable of holding object pointers + */ +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX + +/* + * ISO/IEC 9899:1999 + * 7.18.2.5 Limits of greatest-width integer types + */ +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* + * ISO/IEC 9899:1999 + * 7.18.3 Limits of other integer types + */ +/* Limits of ptrdiff_t. */ +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX + +/* Limits of sig_atomic_t. */ +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +/* Limit of size_t. */ +#define SIZE_MAX UINT32_MAX + +#ifndef WCHAR_MIN /* Also possibly defined in */ +/* Limits of wchar_t. */ +#define WCHAR_MIN INT32_MIN +#define WCHAR_MAX INT32_MAX + +/* Limits of wint_t. */ +#define WINT_MIN INT32_MIN +#define WINT_MAX INT32_MAX +#endif + +#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */ + +#endif /* !_MACHINE__STDINT_H_ */ diff --git a/src/include/machine/_types.h b/src/include/machine/_types.h new file mode 100644 index 0000000..03ffa0c --- /dev/null +++ b/src/include/machine/_types.h @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * From: @(#)ansi.h 8.2 (Berkeley) 1/4/94 + * From: @(#)types.h 8.3 (Berkeley) 1/5/94 + * $FreeBSD: src/sys/i386/include/_types.h,v 1.9 2004/03/20 20:41:40 marcel Exp $ + */ + +#ifndef _MACHINE__TYPES_H_ +#define _MACHINE__TYPES_H_ + +/* + * Basic types upon which most other types are built. + */ +typedef __signed char __int8_t; +typedef unsigned char __uint8_t; +typedef short __int16_t; +typedef unsigned short __uint16_t; +typedef int __int32_t; +typedef unsigned int __uint32_t; + +#if defined(lint) +/* LONGLONG */ +typedef long long __int64_t; +/* LONGLONG */ +typedef unsigned long long __uint64_t; +#elif defined(__GNUC__) || defined(__INTEL_COMPILER) +typedef int __attribute__((__mode__(__DI__))) __int64_t; +typedef unsigned int __attribute__((__mode__(__DI__))) __uint64_t; +#else +/* LONGLONG */ +typedef long long __int64_t; +/* LONGLONG */ +typedef unsigned long long __uint64_t; +#endif + +/* + * Standard type definitions. + */ +typedef unsigned long __clock_t; /* clock()... */ +typedef unsigned int __cpumask_t; +typedef __int32_t __critical_t; +typedef double __double_t; +typedef double __float_t; +typedef __int32_t __intfptr_t; +typedef __int64_t __intmax_t; +typedef __int32_t __intptr_t; +typedef __int32_t __int_fast8_t; +typedef __int32_t __int_fast16_t; +typedef __int32_t __int_fast32_t; +typedef __int64_t __int_fast64_t; +typedef __int8_t __int_least8_t; +typedef __int16_t __int_least16_t; +typedef __int32_t __int_least32_t; +typedef __int64_t __int_least64_t; +typedef __int32_t __ptrdiff_t; /* ptr1 - ptr2 */ +typedef __int32_t __register_t; +typedef __int32_t __segsz_t; /* segment size (in pages) */ +typedef __uint32_t __size_t; /* sizeof() */ +typedef __int32_t __ssize_t; /* byte count or error */ +typedef __int32_t __time_t; /* time()... */ +typedef __uint32_t __uintfptr_t; +typedef __uint64_t __uintmax_t; +typedef __uint32_t __uintptr_t; +typedef __uint32_t __uint_fast8_t; +typedef __uint32_t __uint_fast16_t; +typedef __uint32_t __uint_fast32_t; +typedef __uint64_t __uint_fast64_t; +typedef __uint8_t __uint_least8_t; +typedef __uint16_t __uint_least16_t; +typedef __uint32_t __uint_least32_t; +typedef __uint64_t __uint_least64_t; +typedef __uint32_t __u_register_t; +typedef __uint32_t __vm_offset_t; +typedef __int64_t __vm_ooffset_t; +#ifdef PAE +typedef __uint64_t __vm_paddr_t; +#else +typedef __uint32_t __vm_paddr_t; +#endif +typedef __uint64_t __vm_pindex_t; +typedef __uint32_t __vm_size_t; + +/* + * Unusual type definitions. + */ +#if (defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)) +typedef __builtin_va_list __va_list; /* internally known to gcc */ +#else +typedef char * __va_list; +#endif /* ! (__GNUC__ post 2.95 || __INTEL_COMPILER) */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__GNUC_VA_LIST) && !defined(__NO_GNUC_VA_LIST) +#define __GNUC_VA_LIST +typedef __va_list __gnuc_va_list; /* compatibility w/GNU headers*/ +#endif + +#endif /* !_MACHINE__TYPES_H_ */ diff --git a/src/include/machine/acpica_machdep.h b/src/include/machine/acpica_machdep.h new file mode 100644 index 0000000..2d70c0a --- /dev/null +++ b/src/include/machine/acpica_machdep.h @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2002 Mitsuru IWASAKI + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/acpica_machdep.h,v 1.6 2004/05/05 20:04:14 njl Exp $ + */ + +/****************************************************************************** + * + * Name: acpica_machdep.h - arch-specific defines, etc. + * $Revision$ + * + *****************************************************************************/ + +#ifndef __ACPICA_MACHDEP_H__ +#define __ACPICA_MACHDEP_H__ + +#ifdef _KERNEL +/* + * Calling conventions: + * + * ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads) + * ACPI_EXTERNAL_XFACE - External ACPI interfaces + * ACPI_INTERNAL_XFACE - Internal ACPI interfaces + * ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces + */ +#define ACPI_SYSTEM_XFACE +#define ACPI_EXTERNAL_XFACE +#define ACPI_INTERNAL_XFACE +#define ACPI_INTERNAL_VAR_XFACE + +/* Asm macros */ + +#define ACPI_ASM_MACROS +#define BREAKPOINT3 +#define ACPI_DISABLE_IRQS() disable_intr() +#define ACPI_ENABLE_IRQS() enable_intr() + +#define ACPI_FLUSH_CPU_CACHE() wbinvd() + +/* Section 5.2.9.1: global lock acquire/release functions */ +extern int acpi_acquire_global_lock(uint32_t *lock); +extern int acpi_release_global_lock(uint32_t *lock); +#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \ + ((Acq) = acpi_acquire_global_lock(GLptr)) +#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \ + ((Acq) = acpi_release_global_lock(GLptr)) + +/*! [Begin] no source code translation + * + * Math helper asm macros + */ +#define asm __asm +#define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \ + asm("divl %2;" \ + :"=a"(q32), "=d"(r32) \ + :"r"(d32), \ + "0"(n_lo), "1"(n_hi)) + + +#define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \ + asm("shrl $1,%2;" \ + "rcrl $1,%3;" \ + :"=r"(n_hi), "=r"(n_lo) \ + :"0"(n_hi), "1"(n_lo)) + +/*! [End] no source code translation !*/ +#endif /* _KERNEL */ + +#define ACPI_MACHINE_WIDTH 32 +#define COMPILER_DEPENDENT_INT64 long long +#define COMPILER_DEPENDENT_UINT64 unsigned long long +#define ACPI_USE_NATIVE_DIVIDE + +void acpi_SetDefaultIntrModel(int model); + +#endif /* __ACPICA_MACHDEP_H__ */ diff --git a/src/include/machine/apicreg.h b/src/include/machine/apicreg.h new file mode 100644 index 0000000..4b7d0be --- /dev/null +++ b/src/include/machine/apicreg.h @@ -0,0 +1,429 @@ +/* + * Copyright (c) 1996, by Peter Wemm and Steve Passe + * 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. The name of the developer may NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/apicreg.h,v 1.26 2003/12/10 21:33:07 jhb Exp $ + */ + +#ifndef _MACHINE_APICREG_H_ +#define _MACHINE_APICREG_H_ + +/* + * Local && I/O APIC definitions. + */ + +/* + * Pentium P54C+ Built-in APIC + * (Advanced programmable Interrupt Controller) + * + * Base Address of Built-in APIC in memory location + * is 0xfee00000. + * + * Map of APIC Registers: + * + * Offset (hex) Description Read/Write state + * 000 Reserved + * 010 Reserved + * 020 ID Local APIC ID R/W + * 030 VER Local APIC Version R + * 040 Reserved + * 050 Reserved + * 060 Reserved + * 070 Reserved + * 080 Task Priority Register R/W + * 090 Arbitration Priority Register R + * 0A0 Processor Priority Register R + * 0B0 EOI Register W + * 0C0 RRR Remote read R + * 0D0 Logical Destination R/W + * 0E0 Destination Format Register 0..27 R; 28..31 R/W + * 0F0 SVR Spurious Interrupt Vector Reg. 0..3 R; 4..9 R/W + * 100 ISR 000-031 R + * 110 ISR 032-063 R + * 120 ISR 064-095 R + * 130 ISR 095-128 R + * 140 ISR 128-159 R + * 150 ISR 160-191 R + * 160 ISR 192-223 R + * 170 ISR 224-255 R + * 180 TMR 000-031 R + * 190 TMR 032-063 R + * 1A0 TMR 064-095 R + * 1B0 TMR 095-128 R + * 1C0 TMR 128-159 R + * 1D0 TMR 160-191 R + * 1E0 TMR 192-223 R + * 1F0 TMR 224-255 R + * 200 IRR 000-031 R + * 210 IRR 032-063 R + * 220 IRR 064-095 R + * 230 IRR 095-128 R + * 240 IRR 128-159 R + * 250 IRR 160-191 R + * 260 IRR 192-223 R + * 270 IRR 224-255 R + * 280 Error Status Register R + * 290 Reserved + * 2A0 Reserved + * 2B0 Reserved + * 2C0 Reserved + * 2D0 Reserved + * 2E0 Reserved + * 2F0 Reserved + * 300 ICR_LOW Interrupt Command Reg. (0-31) R/W + * 310 ICR_HI Interrupt Command Reg. (32-63) R/W + * 320 Local Vector Table (Timer) R/W + * 330 Local Vector Table (Thermal) R/W (PIV+) + * 340 Local Vector Table (Performance) R/W (P6+) + * 350 LVT1 Local Vector Table (LINT0) R/W + * 360 LVT2 Local Vector Table (LINT1) R/W + * 370 LVT3 Local Vector Table (ERROR) R/W + * 380 Initial Count Reg. for Timer R/W + * 390 Current Count of Timer R + * 3A0 Reserved + * 3B0 Reserved + * 3C0 Reserved + * 3D0 Reserved + * 3E0 Timer Divide Configuration Reg. R/W + * 3F0 Reserved + */ + + +/****************************************************************************** + * global defines, etc. + */ + + +/****************************************************************************** + * LOCAL APIC structure + */ + +#ifndef LOCORE +#include + +#define PAD3 int : 32; int : 32; int : 32 +#define PAD4 int : 32; int : 32; int : 32; int : 32 + +struct LAPIC { + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t id; PAD3; + u_int32_t version; PAD3; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t tpr; PAD3; + u_int32_t apr; PAD3; + u_int32_t ppr; PAD3; + u_int32_t eoi; PAD3; + /* reserved */ PAD4; + u_int32_t ldr; PAD3; + u_int32_t dfr; PAD3; + u_int32_t svr; PAD3; + u_int32_t isr0; PAD3; + u_int32_t isr1; PAD3; + u_int32_t isr2; PAD3; + u_int32_t isr3; PAD3; + u_int32_t isr4; PAD3; + u_int32_t isr5; PAD3; + u_int32_t isr6; PAD3; + u_int32_t isr7; PAD3; + u_int32_t tmr0; PAD3; + u_int32_t tmr1; PAD3; + u_int32_t tmr2; PAD3; + u_int32_t tmr3; PAD3; + u_int32_t tmr4; PAD3; + u_int32_t tmr5; PAD3; + u_int32_t tmr6; PAD3; + u_int32_t tmr7; PAD3; + u_int32_t irr0; PAD3; + u_int32_t irr1; PAD3; + u_int32_t irr2; PAD3; + u_int32_t irr3; PAD3; + u_int32_t irr4; PAD3; + u_int32_t irr5; PAD3; + u_int32_t irr6; PAD3; + u_int32_t irr7; PAD3; + u_int32_t esr; PAD3; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t icr_lo; PAD3; + u_int32_t icr_hi; PAD3; + u_int32_t lvt_timer; PAD3; + u_int32_t lvt_thermal; PAD3; + u_int32_t lvt_pcint; PAD3; + u_int32_t lvt_lint0; PAD3; + u_int32_t lvt_lint1; PAD3; + u_int32_t lvt_error; PAD3; + u_int32_t icr_timer; PAD3; + u_int32_t ccr_timer; PAD3; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + /* reserved */ PAD4; + u_int32_t dcr_timer; PAD3; + /* reserved */ PAD4; +}; + +typedef struct LAPIC lapic_t; + +/****************************************************************************** + * I/O APIC structure + */ + +struct IOAPIC { + u_int32_t ioregsel; PAD3; + u_int32_t iowin; PAD3; +}; + +typedef struct IOAPIC ioapic_t; + +#undef PAD4 +#undef PAD3 + +#endif /* !LOCORE */ + + +/****************************************************************************** + * various code 'logical' values + */ + +/****************************************************************************** + * LOCAL APIC defines + */ + +/* default physical locations of LOCAL (CPU) APICs */ +#define DEFAULT_APIC_BASE 0xfee00000 + +/* constants relating to APIC ID registers */ +#define APIC_ID_MASK 0xff000000 +#define APIC_ID_SHIFT 24 +#define APIC_ID_CLUSTER 0xf0 +#define APIC_ID_CLUSTER_ID 0x0f +#define APIC_MAX_CLUSTER 0xe +#define APIC_MAX_INTRACLUSTER_ID 3 +#define APIC_ID_CLUSTER_SHIFT 4 + +/* fields in VER */ +#define APIC_VER_VERSION 0x000000ff +#define APIC_VER_MAXLVT 0x00ff0000 +#define MAXLVTSHIFT 16 + +/* fields in LDR */ +#define APIC_LDR_RESERVED 0x00ffffff + +/* fields in DFR */ +#define APIC_DFR_RESERVED 0x0fffffff +#define APIC_DFR_MODEL_MASK 0xf0000000 +#define APIC_DFR_MODEL_FLAT 0xf0000000 +#define APIC_DFR_MODEL_CLUSTER 0x00000000 + +/* fields in SVR */ +#define APIC_SVR_VECTOR 0x000000ff +#define APIC_SVR_VEC_PROG 0x000000f0 +#define APIC_SVR_VEC_FIX 0x0000000f +#define APIC_SVR_ENABLE 0x00000100 +# define APIC_SVR_SWDIS 0x00000000 +# define APIC_SVR_SWEN 0x00000100 +#define APIC_SVR_FOCUS 0x00000200 +# define APIC_SVR_FEN 0x00000000 +# define APIC_SVR_FDIS 0x00000200 + +/* fields in TPR */ +#define APIC_TPR_PRIO 0x000000ff +# define APIC_TPR_INT 0x000000f0 +# define APIC_TPR_SUB 0x0000000f + + +/* fields in ICR_LOW */ +#define APIC_VECTOR_MASK 0x000000ff + +#define APIC_DELMODE_MASK 0x00000700 +# define APIC_DELMODE_FIXED 0x00000000 +# define APIC_DELMODE_LOWPRIO 0x00000100 +# define APIC_DELMODE_SMI 0x00000200 +# define APIC_DELMODE_RR 0x00000300 +# define APIC_DELMODE_NMI 0x00000400 +# define APIC_DELMODE_INIT 0x00000500 +# define APIC_DELMODE_STARTUP 0x00000600 +# define APIC_DELMODE_RESV 0x00000700 + +#define APIC_DESTMODE_MASK 0x00000800 +# define APIC_DESTMODE_PHY 0x00000000 +# define APIC_DESTMODE_LOG 0x00000800 + +#define APIC_DELSTAT_MASK 0x00001000 +# define APIC_DELSTAT_IDLE 0x00000000 +# define APIC_DELSTAT_PEND 0x00001000 + +#define APIC_RESV1_MASK 0x00002000 + +#define APIC_LEVEL_MASK 0x00004000 +# define APIC_LEVEL_DEASSERT 0x00000000 +# define APIC_LEVEL_ASSERT 0x00004000 + +#define APIC_TRIGMOD_MASK 0x00008000 +# define APIC_TRIGMOD_EDGE 0x00000000 +# define APIC_TRIGMOD_LEVEL 0x00008000 + +#define APIC_RRSTAT_MASK 0x00030000 +# define APIC_RRSTAT_INVALID 0x00000000 +# define APIC_RRSTAT_INPROG 0x00010000 +# define APIC_RRSTAT_VALID 0x00020000 +# define APIC_RRSTAT_RESV 0x00030000 + +#define APIC_DEST_MASK 0x000c0000 +# define APIC_DEST_DESTFLD 0x00000000 +# define APIC_DEST_SELF 0x00040000 +# define APIC_DEST_ALLISELF 0x00080000 +# define APIC_DEST_ALLESELF 0x000c0000 + +#define APIC_RESV2_MASK 0xfff00000 + +#define APIC_ICRLO_RESV_MASK (APIC_RESV1_MASK | APIC_RESV2_MASK) + +/* fields in LVT1/2 */ +#define APIC_LVT_VECTOR 0x000000ff +#define APIC_LVT_DM 0x00000700 +# define APIC_LVT_DM_FIXED 0x00000000 +# define APIC_LVT_DM_SMI 0x00000200 +# define APIC_LVT_DM_NMI 0x00000400 +# define APIC_LVT_DM_INIT 0x00000500 +# define APIC_LVT_DM_EXTINT 0x00000700 +#define APIC_LVT_DS 0x00001000 +#define APIC_LVT_IIPP 0x00002000 +#define APIC_LVT_IIPP_INTALO 0x00002000 +#define APIC_LVT_IIPP_INTAHI 0x00000000 +#define APIC_LVT_RIRR 0x00004000 +#define APIC_LVT_TM 0x00008000 +#define APIC_LVT_M 0x00010000 + + +/* fields in LVT Timer */ +#define APIC_LVTT_VECTOR 0x000000ff +#define APIC_LVTT_DS 0x00001000 +#define APIC_LVTT_M 0x00010000 +#define APIC_LVTT_TM 0x00020000 + + +/* fields in TDCR */ +#define APIC_TDCR_2 0x00 +#define APIC_TDCR_4 0x01 +#define APIC_TDCR_8 0x02 +#define APIC_TDCR_16 0x03 +#define APIC_TDCR_32 0x08 +#define APIC_TDCR_64 0x09 +#define APIC_TDCR_128 0x0a +#define APIC_TDCR_1 0x0b + +/****************************************************************************** + * I/O APIC defines + */ + +/* default physical locations of an IO APIC */ +#define DEFAULT_IO_APIC_BASE 0xfec00000 + +/* window register offset */ +#define IOAPIC_WINDOW 0x10 + +/* indexes into IO APIC */ +#define IOAPIC_ID 0x00 +#define IOAPIC_VER 0x01 +#define IOAPIC_ARB 0x02 +#define IOAPIC_REDTBL 0x10 +#define IOAPIC_REDTBL0 IOAPIC_REDTBL +#define IOAPIC_REDTBL1 (IOAPIC_REDTBL+0x02) +#define IOAPIC_REDTBL2 (IOAPIC_REDTBL+0x04) +#define IOAPIC_REDTBL3 (IOAPIC_REDTBL+0x06) +#define IOAPIC_REDTBL4 (IOAPIC_REDTBL+0x08) +#define IOAPIC_REDTBL5 (IOAPIC_REDTBL+0x0a) +#define IOAPIC_REDTBL6 (IOAPIC_REDTBL+0x0c) +#define IOAPIC_REDTBL7 (IOAPIC_REDTBL+0x0e) +#define IOAPIC_REDTBL8 (IOAPIC_REDTBL+0x10) +#define IOAPIC_REDTBL9 (IOAPIC_REDTBL+0x12) +#define IOAPIC_REDTBL10 (IOAPIC_REDTBL+0x14) +#define IOAPIC_REDTBL11 (IOAPIC_REDTBL+0x16) +#define IOAPIC_REDTBL12 (IOAPIC_REDTBL+0x18) +#define IOAPIC_REDTBL13 (IOAPIC_REDTBL+0x1a) +#define IOAPIC_REDTBL14 (IOAPIC_REDTBL+0x1c) +#define IOAPIC_REDTBL15 (IOAPIC_REDTBL+0x1e) +#define IOAPIC_REDTBL16 (IOAPIC_REDTBL+0x20) +#define IOAPIC_REDTBL17 (IOAPIC_REDTBL+0x22) +#define IOAPIC_REDTBL18 (IOAPIC_REDTBL+0x24) +#define IOAPIC_REDTBL19 (IOAPIC_REDTBL+0x26) +#define IOAPIC_REDTBL20 (IOAPIC_REDTBL+0x28) +#define IOAPIC_REDTBL21 (IOAPIC_REDTBL+0x2a) +#define IOAPIC_REDTBL22 (IOAPIC_REDTBL+0x2c) +#define IOAPIC_REDTBL23 (IOAPIC_REDTBL+0x2e) + +/* fields in VER */ +#define IOART_VER_VERSION 0x000000ff +#define IOART_VER_MAXREDIR 0x00ff0000 +#define MAXREDIRSHIFT 16 + +/* + * fields in the IO APIC's redirection table entries + */ +#define IOART_DEST APIC_ID_MASK /* broadcast addr: all APICs */ + +#define IOART_RESV 0x00fe0000 /* reserved */ + +#define IOART_INTMASK 0x00010000 /* R/W: INTerrupt mask */ +# define IOART_INTMCLR 0x00000000 /* clear, allow INTs */ +# define IOART_INTMSET 0x00010000 /* set, inhibit INTs */ + +#define IOART_TRGRMOD 0x00008000 /* R/W: trigger mode */ +# define IOART_TRGREDG 0x00000000 /* edge */ +# define IOART_TRGRLVL 0x00008000 /* level */ + +#define IOART_REM_IRR 0x00004000 /* RO: remote IRR */ + +#define IOART_INTPOL 0x00002000 /* R/W: INT input pin polarity */ +# define IOART_INTAHI 0x00000000 /* active high */ +# define IOART_INTALO 0x00002000 /* active low */ + +#define IOART_DELIVS 0x00001000 /* RO: delivery status */ + +#define IOART_DESTMOD 0x00000800 /* R/W: destination mode */ +# define IOART_DESTPHY 0x00000000 /* physical */ +# define IOART_DESTLOG 0x00000800 /* logical */ + +#define IOART_DELMOD 0x00000700 /* R/W: delivery mode */ +# define IOART_DELFIXED 0x00000000 /* fixed */ +# define IOART_DELLOPRI 0x00000100 /* lowest priority */ +# define IOART_DELSMI 0x00000200 /* System Management INT */ +# define IOART_DELRSV1 0x00000300 /* reserved */ +# define IOART_DELNMI 0x00000400 /* NMI signal */ +# define IOART_DELINIT 0x00000500 /* INIT signal */ +# define IOART_DELRSV2 0x00000600 /* reserved */ +# define IOART_DELEXINT 0x00000700 /* External INTerrupt */ + +#define IOART_INTVEC 0x000000ff /* R/W: INTerrupt vector field */ + +#endif /* _MACHINE_APICREG_H_ */ diff --git a/src/include/machine/apicvar.h b/src/include/machine/apicvar.h new file mode 100644 index 0000000..553a958 --- /dev/null +++ b/src/include/machine/apicvar.h @@ -0,0 +1,172 @@ +/*- + * Copyright (c) 2003 John Baldwin + * 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. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/apicvar.h,v 1.7 2004/05/10 18:49:58 jhb Exp $ + */ + +#ifndef _MACHINE_APICVAR_H_ +#define _MACHINE_APICVAR_H_ + +/* + * Local && I/O APIC variable definitions. + */ + +/* + * Layout of local APIC interrupt vectors: + * + * 0xff (255) +-------------+ + * | | 15 (Spurious / IPIs / Local Interrupts) + * 0xf0 (240) +-------------+ + * | | 14 (I/O Interrupts) + * 0xe0 (224) +-------------+ + * | | 13 (I/O Interrupts) + * 0xd0 (208) +-------------+ + * | | 12 (I/O Interrupts) + * 0xc0 (192) +-------------+ + * | | 11 (I/O Interrupts) + * 0xb0 (176) +-------------+ + * | | 10 (I/O Interrupts) + * 0xa0 (160) +-------------+ + * | | 9 (I/O Interrupts) + * 0x90 (144) +-------------+ + * | | 8 (I/O Interrupts / System Calls) + * 0x80 (128) +-------------+ + * | | 7 (I/O Interrupts) + * 0x70 (112) +-------------+ + * | | 6 (I/O Interrupts) + * 0x60 (96) +-------------+ + * | | 5 (I/O Interrupts) + * 0x50 (80) +-------------+ + * | | 4 (I/O Interrupts) + * 0x40 (64) +-------------+ + * | | 3 (I/O Interrupts) + * 0x30 (48) +-------------+ + * | | 2 (ATPIC Interrupts) + * 0x20 (32) +-------------+ + * | | 1 (Exceptions, traps, faults, etc.) + * 0x10 (16) +-------------+ + * | | 0 (Exceptions, traps, faults, etc.) + * 0x00 (0) +-------------+ + * + * Note: 0x80 needs to be handled specially and not allocated to an + * I/O device! + */ + +#define APIC_ID_ALL 0xff +#define APIC_IO_INTS (IDT_IO_INTS + 16) +#define APIC_NUM_IOINTS 192 + +#define APIC_LOCAL_INTS 240 +#define APIC_TIMER_INT APIC_LOCAL_INTS +#define APIC_ERROR_INT (APIC_LOCAL_INTS + 1) +#define APIC_THERMAL_INT (APIC_LOCAL_INTS + 2) + +#define APIC_IPI_INTS (APIC_LOCAL_INTS + 3) +#define IPI_AST APIC_IPI_INTS /* Generate software trap. */ +#define IPI_INVLTLB (APIC_IPI_INTS + 1) /* TLB Shootdown IPIs */ +#define IPI_INVLPG (APIC_IPI_INTS + 2) +#define IPI_INVLRNG (APIC_IPI_INTS + 3) +#define IPI_LAZYPMAP (APIC_IPI_INTS + 4) /* Lazy pmap release. */ +#define IPI_HARDCLOCK (APIC_IPI_INTS + 8) /* Inter-CPU clock handling. */ +#define IPI_STATCLOCK (APIC_IPI_INTS + 9) +#define IPI_RENDEZVOUS (APIC_IPI_INTS + 10) /* Inter-CPU rendezvous. */ +#define IPI_STOP (APIC_IPI_INTS + 11) /* Stop CPU until restarted. */ + +#define APIC_SPURIOUS_INT 255 + +#define LVT_LINT0 0 +#define LVT_LINT1 1 +#define LVT_TIMER 2 +#define LVT_ERROR 3 +#define LVT_PMC 4 +#define LVT_THERMAL 5 +#define LVT_MAX LVT_THERMAL + +#ifndef LOCORE + +#define APIC_IPI_DEST_SELF -1 +#define APIC_IPI_DEST_ALL -2 +#define APIC_IPI_DEST_OTHERS -3 + +/* + * An APIC enumerator is a psuedo bus driver that enumerates APIC's including + * CPU's and I/O APIC's. + */ +struct apic_enumerator { + const char *apic_name; + int (*apic_probe)(void); + int (*apic_probe_cpus)(void); + int (*apic_setup_local)(void); + int (*apic_setup_io)(void); + SLIST_ENTRY(apic_enumerator) apic_next; +}; + +inthand_t + IDTVEC(apic_isr1), IDTVEC(apic_isr2), IDTVEC(apic_isr3), + IDTVEC(apic_isr4), IDTVEC(apic_isr5), IDTVEC(apic_isr6), + IDTVEC(apic_isr7), IDTVEC(spuriousint); + +u_int apic_irq_to_idt(u_int irq); +u_int apic_idt_to_irq(u_int vector); +void apic_register_enumerator(struct apic_enumerator *enumerator); +void *ioapic_create(uintptr_t addr, int32_t id, int intbase); +int ioapic_disable_pin(void *cookie, u_int pin); +void ioapic_enable_mixed_mode(void); +int ioapic_get_vector(void *cookie, u_int pin); +int ioapic_next_logical_cluster(void); +void ioapic_register(void *cookie); +int ioapic_remap_vector(void *cookie, u_int pin, int vector); +int ioapic_set_extint(void *cookie, u_int pin); +int ioapic_set_nmi(void *cookie, u_int pin); +int ioapic_set_polarity(void *cookie, u_int pin, enum intr_polarity pol); +int ioapic_set_triggermode(void *cookie, u_int pin, + enum intr_trigger trigger); +int ioapic_set_smi(void *cookie, u_int pin); +void lapic_create(u_int apic_id, int boot_cpu); +void lapic_disable(void); +void lapic_dump(const char *str); +void lapic_enable_intr(u_int vector); +void lapic_eoi(void); +int lapic_id(void); +void lapic_init(uintptr_t addr); +int lapic_intr_pending(u_int vector); +void lapic_ipi_raw(register_t icrlo, u_int dest); +void lapic_ipi_vectored(u_int vector, int dest); +int lapic_ipi_wait(int delay); +void lapic_handle_intr(struct intrframe frame); +void lapic_set_logical_id(u_int apic_id, u_int cluster, u_int cluster_id); +int lapic_set_lvt_mask(u_int apic_id, u_int lvt, u_char masked); +int lapic_set_lvt_mode(u_int apic_id, u_int lvt, u_int32_t mode); +int lapic_set_lvt_polarity(u_int apic_id, u_int lvt, + enum intr_polarity pol); +int lapic_set_lvt_triggermode(u_int apic_id, u_int lvt, + enum intr_trigger trigger); +void lapic_setup(void); + +#endif /* !LOCORE */ +#endif /* _MACHINE_APICVAR_H_ */ diff --git a/src/include/machine/apm_bios.h b/src/include/machine/apm_bios.h new file mode 100644 index 0000000..9fb0240 --- /dev/null +++ b/src/include/machine/apm_bios.h @@ -0,0 +1,277 @@ +/* + * APM (Advanced Power Management) BIOS Device Driver + * + * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * + * $FreeBSD: src/sys/i386/include/apm_bios.h,v 1.30 2002/03/20 05:48:58 alfred Exp $ + */ + +#ifndef _MACHINE_APM_BIOS_H_ +#define _MACHINE_APM_BIOS_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* BIOS id */ +#ifdef PC98 +#define APM_BIOS 0x9a +#define APM_INT 0x1f +#else +#define APM_BIOS 0x53 +#define APM_INT 0x15 +#endif + +/* APM flags */ +#define APM_16BIT_SUPPORT 0x01 +#define APM_32BIT_SUPPORT 0x02 +#define APM_CPUIDLE_SLOW 0x04 +#define APM_DISABLED 0x08 +#define APM_DISENGAGED 0x10 + +/* APM initializer physical address */ +#define APM_OURADDR 0x00080000 + +/* APM functions */ +#define APM_INSTCHECK 0x00 +#define APM_REALCONNECT 0x01 +#define APM_PROT16CONNECT 0x02 +#define APM_PROT32CONNECT 0x03 +#define APM_DISCONNECT 0x04 +#define APM_CPUIDLE 0x05 +#define APM_CPUBUSY 0x06 +#define APM_SETPWSTATE 0x07 +#define APM_ENABLEDISABLEPM 0x08 +#define APM_RESTOREDEFAULT 0x09 +#ifdef PC98 +#define APM_GETPWSTATUS 0x3a +#else +#define APM_GETPWSTATUS 0x0a +#endif +#define APM_GETPMEVENT 0x0b +#define APM_GETPWSTATE 0x0c +#define APM_ENABLEDISABLEDPM 0x0d +#ifdef PC98 +#define APM_DRVVERSION 0x3e +#else +#define APM_DRVVERSION 0x0e +#endif +#define APM_ENGAGEDISENGAGEPM 0x0f +#define APM_GETCAPABILITIES 0x10 +#define APM_RESUMETIMER 0x11 +#define APM_RESUMEONRING 0x12 +#define APM_TIMERREQUESTS 0x13 +#define APM_OEMFUNC 0x80 + +/* error code */ +#define APME_OK 0x00 +#define APME_PMDISABLED 0x01 +#define APME_REALESTABLISHED 0x02 +#define APME_NOTCONNECTED 0x03 +#define APME_PROT16ESTABLISHED 0x05 +#define APME_PROT16NOTSUPPORTED 0x06 +#define APME_PROT32ESTABLISHED 0x07 +#define APME_PROT32NOTDUPPORTED 0x08 +#define APME_UNKNOWNDEVICEID 0x09 +#define APME_OUTOFRANGE 0x0a +#define APME_NOTENGAGED 0x0b +#define APME_CANTENTERSTATE 0x60 +#define APME_NOPMEVENT 0x80 +#define APME_NOAPMPRESENT 0x86 + + +/* device code */ +#define PMDV_APMBIOS 0x0000 +#define PMDV_ALLDEV 0x0001 +#define PMDV_DISP0 0x0100 +#define PMDV_DISP1 0x0101 +#define PMDV_DISPALL 0x01ff +#define PMDV_2NDSTORAGE0 0x0200 +#define PMDV_2NDSTORAGE1 0x0201 +#define PMDV_2NDSTORAGE2 0x0202 +#define PMDV_2NDSTORAGE3 0x0203 +#define PMDV_PARALLEL0 0x0300 +#define PMDV_PARALLEL1 0x0301 +#define PMDV_SERIAL0 0x0400 +#define PMDV_SERIAL1 0x0401 +#define PMDV_SERIAL2 0x0402 +#define PMDV_SERIAL3 0x0403 +#define PMDV_SERIAL4 0x0404 +#define PMDV_SERIAL5 0x0405 +#define PMDV_SERIAL6 0x0406 +#define PMDV_SERIAL7 0x0407 +#define PMDV_NET0 0x0500 +#define PMDV_NET1 0x0501 +#define PMDV_NET2 0x0502 +#define PMDV_NET3 0x0503 +#define PMDV_PCMCIA0 0x0600 +#define PMDV_PCMCIA1 0x0601 +#define PMDV_PCMCIA2 0x0602 +#define PMDV_PCMCIA3 0x0603 +/* 0x0700 - 0x7fff Reserved */ +#define PMDV_BATT_BASE 0x8000 +#define PMDV_BATT0 0x8001 +#define PMDV_BATT1 0x8002 +#define PMDV_BATT_ALL 0x80ff +/* 0x8100 - 0xdfff Reserved */ +/* 0xe000 - 0xefff OEM-defined power device IDs */ +/* 0xf000 - 0xffff Reserved */ + +/* Power state */ +#define PMST_APMENABLED 0x0000 +#define PMST_STANDBY 0x0001 +#define PMST_SUSPEND 0x0002 +#define PMST_OFF 0x0003 +#define PMST_LASTREQNOTIFY 0x0004 +#define PMST_LASTREQREJECT 0x0005 +/* 0x0006 - 0x001f Reserved system states */ +/* 0x0020 - 0x003f OEM-defined system states */ +/* 0x0040 - 0x007f OEM-defined device states */ +/* 0x0080 - 0xffff Reserved device states */ + +#if !defined(ASSEMBLER) && !defined(INITIALIZER) + +/* C definitions */ +struct apmhook { + struct apmhook *ah_next; + int (*ah_fun)(void *ah_arg); + void *ah_arg; + const char *ah_name; + int ah_order; +}; +#define APM_HOOK_NONE (-1) +#define APM_HOOK_SUSPEND 0 +#define APM_HOOK_RESUME 1 +#define NAPM_HOOK 2 + +#ifdef _KERNEL + +void apm_suspend(int state); +struct apmhook *apm_hook_establish (int apmh, struct apmhook *); +void apm_hook_disestablish (int apmh, struct apmhook *); +void apm_cpu_idle(void); +void apm_cpu_busy(void); + +#endif + +#endif /* !ASSEMBLER && !INITIALIZER */ + +#define APM_MIN_ORDER 0x00 +#define APM_MID_ORDER 0x80 +#define APM_MAX_ORDER 0xff + +/* power management event code */ +#define PMEV_NOEVENT 0x0000 +#define PMEV_STANDBYREQ 0x0001 +#define PMEV_SUSPENDREQ 0x0002 +#define PMEV_NORMRESUME 0x0003 +#define PMEV_CRITRESUME 0x0004 +#define PMEV_BATTERYLOW 0x0005 +#define PMEV_POWERSTATECHANGE 0x0006 +#define PMEV_UPDATETIME 0x0007 +#define PMEV_CRITSUSPEND 0x0008 +#define PMEV_USERSTANDBYREQ 0x0009 +#define PMEV_USERSUSPENDREQ 0x000a +#define PMEV_STANDBYRESUME 0x000b +#define PMEV_CAPABILITIESCHANGE 0x000c +/* 0x000d - 0x00ff Reserved system events */ +/* 0x0100 - 0x01ff Reserved device events */ +/* 0x0200 - 0x02ff OEM-defined APM events */ +/* 0x0300 - 0xffff Reserved */ +#define PMEV_DEFAULT 0xffffffff /* used for customization */ + +#if !defined(ASSEMBLER) && !defined(INITIALIZER) + +/* + * Old apm_info structure, returned by the APMIO_GETINFO_OLD ioctl. This + * is for backward compatibility with old executables. + */ +typedef struct apm_info_old { + u_int ai_major; /* APM major version */ + u_int ai_minor; /* APM minor version */ + u_int ai_acline; /* AC line status */ + u_int ai_batt_stat; /* Battery status */ + u_int ai_batt_life; /* Remaining battery life */ + u_int ai_status; /* Status of APM support (enabled/disabled) */ +} *apm_info_old_t; + +/* + * Structure returned by the APMIO_GETINFO ioctl. + * + * In the comments below, the parenthesized numbers indicate the minimum + * value of ai_infoversion for which each field is valid. + */ +typedef struct apm_info { + u_int ai_infoversion; /* Indicates which fields are valid */ + u_int ai_major; /* APM major version (0) */ + u_int ai_minor; /* APM minor version (0) */ + u_int ai_acline; /* AC line status (0) */ + u_int ai_batt_stat; /* Battery status (0) */ + u_int ai_batt_life; /* Remaining battery life in percent (0) */ + int ai_batt_time; /* Remaining battery time in seconds (0) */ + u_int ai_status; /* True if enabled (0) */ + u_int ai_batteries; /* Number of batteries (1) */ + u_int ai_capabilities;/* APM Capabilities (1) */ + u_int ai_spare[6]; /* For future expansion */ +} *apm_info_t; + +/* Battery flag */ +#define APM_BATT_HIGH 0x01 +#define APM_BATT_LOW 0x02 +#define APM_BATT_CRITICAL 0x04 +#define APM_BATT_CHARGING 0x08 +#define APM_BATT_NOT_PRESENT 0x10 +#define APM_BATT_NO_SYSTEM 0x80 + +typedef struct apm_pwstatus { + u_int ap_device; /* Device code of battery */ + u_int ap_acline; /* AC line status (0) */ + u_int ap_batt_stat; /* Battery status (0) */ + u_int ap_batt_flag; /* Battery flag (0) */ + u_int ap_batt_life; /* Remaining battery life in percent (0) */ + int ap_batt_time; /* Remaining battery time in seconds (0) */ +} *apm_pwstatus_t; + +struct apm_bios_arg { + u_long eax; + u_long ebx; + u_long ecx; + u_long edx; + u_long esi; + u_long edi; +}; + +struct apm_event_info { + u_int type; + u_int index; + u_int spare[8]; +}; + +#define APMIO_SUSPEND _IO('P', 1) +#define APMIO_GETINFO_OLD _IOR('P', 2, struct apm_info_old) +#define APMIO_ENABLE _IO('P', 5) +#define APMIO_DISABLE _IO('P', 6) +#define APMIO_HALTCPU _IO('P', 7) +#define APMIO_NOTHALTCPU _IO('P', 8) +#define APMIO_DISPLAY _IOW('P', 9, int) +#define APMIO_BIOS _IOWR('P', 10, struct apm_bios_arg) +#define APMIO_GETINFO _IOR('P', 11, struct apm_info) +#define APMIO_STANDBY _IO('P', 12) +#define APMIO_GETPWSTATUS _IOWR('P', 13, struct apm_pwstatus) +/* for /dev/apmctl */ +#define APMIO_NEXTEVENT _IOR('A', 100, struct apm_event_info) +#define APMIO_REJECTLASTREQ _IO('P', 101) + +#endif /* !ASSEMBLER && !INITIALIZER */ + +#endif /* !_MACHINE_APM_BIOS_H_ */ diff --git a/src/include/machine/apm_segments.h b/src/include/machine/apm_segments.h new file mode 100644 index 0000000..35b14a5 --- /dev/null +++ b/src/include/machine/apm_segments.h @@ -0,0 +1,38 @@ +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + * + * $FreeBSD: src/sys/i386/include/apm_segments.h,v 1.8 1999/08/28 00:44:05 peter Exp $ + */ + +#ifndef _MACHINE_APM_SEGMENTS_H +#define _MACHINE_APM_SEGMENTS_H + +#define SIZEOF_GDT 8 +#define BOOTSTRAP_GDT_NUM 32 + +#define APM_INIT_CS_INDEX (BOOTSTRAP_GDT_NUM - 4) +#define APM_INIT_DS_INDEX (BOOTSTRAP_GDT_NUM - 3) +#define APM_INIT_CS16_INDEX (BOOTSTRAP_GDT_NUM - 2) +#define APM_INIT_DS16_INDEX (BOOTSTRAP_GDT_NUM - 1) +#define APM_INIT_CS_SEL (APM_INIT_CS_INDEX << 3) +#define APM_INIT_DS_SEL (APM_INIT_DS_INDEX << 3) +#define APM_INIT_CS16_SEL (APM_INIT_CS16_INDEX << 3) +#define APM_INIT_DS16_SEL (APM_INIT_DS16_INDEX << 3) + +#define CS32_ATTRIB 0x409e +#define DS32_ATTRIB 0x4092 +#define CS16_ATTRIB 0x009e +#define DS16_ATTRIB 0x0092 + +#endif diff --git a/src/include/machine/asc_ioctl.h b/src/include/machine/asc_ioctl.h new file mode 100644 index 0000000..b98b7c3 --- /dev/null +++ b/src/include/machine/asc_ioctl.h @@ -0,0 +1,53 @@ +/* asc.h - programming interface to the scanner device driver `asc' + * + * + * Copyright (c) 1995 Gunther Schadow. 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 Gunther Schadow. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/asc_ioctl.h,v 1.3 2000/05/01 20:04:08 peter Exp $ + */ + +#ifndef _MACHINE_ASC_IOCTL_H_ +#define _MACHINE_ASC_IOCTL_H_ + +#include + +#define ASC_GRES _IOR('S', 1, int) /* get resolution / dpi */ +#define ASC_SRES _IOW('S', 2, int) /* set resolution / dpi */ +#define ASC_GWIDTH _IOR('S', 3, int) /* get width / pixels */ +#define ASC_SWIDTH _IOW('S', 4, int) /* set width / pixels */ +#define ASC_GHEIGHT _IOR('S', 5, int) /* get height / pixels */ +#define ASC_SHEIGHT _IOW('S', 6, int) /* set height / pixels */ + +#define ASC_GBLEN _IOR('S', 7, int) /* get buffer length / lines */ +#define ASC_SBLEN _IOW('S', 8, int) /* set buffer length / lines */ +#define ASC_GBTIME _IOR('S', 9, int) /* get buffer timeout / s */ +#define ASC_SBTIME _IOW('S', 10, int) /* set buffer timeout / s */ + +#define ASC_SRESSW _IO('S', 11) /* set resolution by switch */ + +#endif /* !_MACHINE_ASC_IOCTL_H_ */ diff --git a/src/include/machine/asm.h b/src/include/machine/asm.h new file mode 100644 index 0000000..f007c8a --- /dev/null +++ b/src/include/machine/asm.h @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)DEFS.h 5.1 (Berkeley) 4/23/90 + * $FreeBSD: src/sys/i386/include/asm.h,v 1.13 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#include + +#ifdef PIC +#define PIC_PROLOGUE \ + pushl %ebx; \ + call 1f; \ +1: \ + popl %ebx; \ + addl $_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx +#define PIC_EPILOGUE \ + popl %ebx +#define PIC_PLT(x) x@PLT +#define PIC_GOT(x) x@GOT(%ebx) +#else +#define PIC_PROLOGUE +#define PIC_EPILOGUE +#define PIC_PLT(x) x +#define PIC_GOT(x) x +#endif + +/* + * CNAME and HIDENAME manage the relationship between symbol names in C + * and the equivalent assembly language names. CNAME is given a name as + * it would be used in a C program. It expands to the equivalent assembly + * language name. HIDENAME is given an assembly-language name, and expands + * to a possibly-modified form that will be invisible to C programs. + */ +#define CNAME(csym) csym +#define HIDENAME(asmsym) .asmsym + +/* XXX should use .p2align 4,0x90 for -m486. */ +#define _START_ENTRY .text; .p2align 2,0x90 + +#define _ENTRY(x) _START_ENTRY; \ + .globl CNAME(x); .type CNAME(x),@function; CNAME(x): + +#ifdef PROF +#define ALTENTRY(x) _ENTRY(x); \ + pushl %ebp; movl %esp,%ebp; \ + call PIC_PLT(HIDENAME(mcount)); \ + popl %ebp; \ + jmp 9f +#define ENTRY(x) _ENTRY(x); \ + pushl %ebp; movl %esp,%ebp; \ + call PIC_PLT(HIDENAME(mcount)); \ + popl %ebp; \ + 9: +#else +#define ALTENTRY(x) _ENTRY(x) +#define ENTRY(x) _ENTRY(x) +#endif + +#define RCSID(x) .text; .asciz x + +#undef __FBSDID +#if !defined(lint) && !defined(STRIP_FBSDID) +#define __FBSDID(s) .ident s +#else +#define __FBSDID(s) /* nothing */ +#endif /* not lint and not STRIP_FBSDID */ + +#endif /* !_MACHINE_ASM_H_ */ diff --git a/src/include/machine/asmacros.h b/src/include/machine/asmacros.h new file mode 100644 index 0000000..f5493e8 --- /dev/null +++ b/src/include/machine/asmacros.h @@ -0,0 +1,148 @@ +/*- + * Copyright (c) 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. + * 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. + * + * $FreeBSD: src/sys/i386/include/asmacros.h,v 1.26 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_ASMACROS_H_ +#define _MACHINE_ASMACROS_H_ + +#include + +/* XXX too much duplication in various asm*.h's. */ + +/* + * CNAME and HIDENAME manage the relationship between symbol names in C + * and the equivalent assembly language names. CNAME is given a name as + * it would be used in a C program. It expands to the equivalent assembly + * language name. HIDENAME is given an assembly-language name, and expands + * to a possibly-modified form that will be invisible to C programs. + */ +#define CNAME(csym) csym +#define HIDENAME(asmsym) .asmsym + +#define ALIGN_DATA .p2align 2 /* 4 byte alignment, zero filled */ +#ifdef GPROF +#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ +#else +#define ALIGN_TEXT .p2align 2,0x90 /* 4-byte alignment, nop filled */ +#endif +#define SUPERALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ + +#define GEN_ENTRY(name) ALIGN_TEXT; .globl CNAME(name); \ + .type CNAME(name),@function; CNAME(name): +#define NON_GPROF_ENTRY(name) GEN_ENTRY(name) +#define NON_GPROF_RET .byte 0xc3 /* opcode for `ret' */ + +#ifdef LOCORE +#define PCPU(member) %fs:PC_ ## member +#define PCPU_ADDR(member, reg) movl %fs:PC_PRVSPACE,reg; \ + addl $PC_ ## member,reg +#endif + +#ifdef GPROF +/* + * __mcount is like [.]mcount except that doesn't require its caller to set + * up a frame pointer. It must be called before pushing anything onto the + * stack. gcc should eventually generate code to call __mcount in most + * cases. This would make -pg in combination with -fomit-frame-pointer + * useful. gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to + * allow profiling before setting up the frame pointer, but this is + * inadequate for good handling of special cases, e.g., -fpic works best + * with profiling after the prologue. + * + * [.]mexitcount is a new function to support non-statistical profiling if an + * accurate clock is available. For C sources, calls to it are generated + * by the FreeBSD extension `-mprofiler-epilogue' to gcc. It is best to + * call [.]mexitcount at the end of a function like the MEXITCOUNT macro does, + * but gcc currently generates calls to it at the start of the epilogue to + * avoid problems with -fpic. + * + * [.]mcount and __mcount may clobber the call-used registers and %ef. + * [.]mexitcount may clobber %ecx and %ef. + * + * Cross-jumping makes non-statistical profiling timing more complicated. + * It is handled in many cases by calling [.]mexitcount before jumping. It + * is handled for conditional jumps using CROSSJUMP() and CROSSJUMP_LABEL(). + * It is handled for some fault-handling jumps by not sharing the exit + * routine. + * + * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to + * the main entry point. Note that alt entries are counted twice. They + * have to be counted as ordinary entries for gprof to get the call times + * right for the ordinary entries. + * + * High local labels are used in macros to avoid clashes with local labels + * in functions. + * + * Ordinary `ret' is used instead of a macro `RET' because there are a lot + * of `ret's. 0xc3 is the opcode for `ret' (`#define ret ... ret' can't + * be used because this file is sometimes preprocessed in traditional mode). + * `ret' clobbers eflags but this doesn't matter. + */ +#define ALTENTRY(name) GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f +#define CROSSJUMP(jtrue, label, jfalse) \ + jfalse 8f; MEXITCOUNT; jmp __CONCAT(to,label); 8: +#define CROSSJUMPTARGET(label) \ + ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label +#define ENTRY(name) GEN_ENTRY(name) ; 9: ; MCOUNT +#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx +#define MCOUNT call __mcount +#define MCOUNT_LABEL(name) GEN_ENTRY(name) ; nop ; ALIGN_TEXT +#define MEXITCOUNT call HIDENAME(mexitcount) +#define ret MEXITCOUNT ; NON_GPROF_RET + +#else /* !GPROF */ +/* + * ALTENTRY() has to align because it is before a corresponding ENTRY(). + * ENTRY() has to align to because there may be no ALTENTRY() before it. + * If there is a previous ALTENTRY() then the alignment code for ENTRY() + * is empty. + */ +#define ALTENTRY(name) GEN_ENTRY(name) +#define CROSSJUMP(jtrue, label, jfalse) jtrue label +#define CROSSJUMPTARGET(label) +#define ENTRY(name) GEN_ENTRY(name) +#define FAKE_MCOUNT(caller) +#define MCOUNT +#define MCOUNT_LABEL(name) +#define MEXITCOUNT +#endif /* GPROF */ + +#ifdef LOCORE +/* + * Convenience macros for declaring interrupt entry points and trap + * stubs. + */ +#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \ + .type __CONCAT(X,name),@function; __CONCAT(X,name): +#define TRAP(a) pushl $(a) ; jmp alltraps + +#endif /* LOCORE */ + +#endif /* !_MACHINE_ASMACROS_H_ */ diff --git a/src/include/machine/atomic.h b/src/include/machine/atomic.h new file mode 100644 index 0000000..6c0401f --- /dev/null +++ b/src/include/machine/atomic.h @@ -0,0 +1,453 @@ +/*- + * Copyright (c) 1998 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/atomic.h,v 1.32 2004/03/12 21:45:29 trhodes Exp $ + */ +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +/* + * Various simple arithmetic on memory which is atomic in the presence + * of interrupts and multiple processors. + * + * atomic_set_char(P, V) (*(u_char*)(P) |= (V)) + * atomic_clear_char(P, V) (*(u_char*)(P) &= ~(V)) + * atomic_add_char(P, V) (*(u_char*)(P) += (V)) + * atomic_subtract_char(P, V) (*(u_char*)(P) -= (V)) + * + * atomic_set_short(P, V) (*(u_short*)(P) |= (V)) + * atomic_clear_short(P, V) (*(u_short*)(P) &= ~(V)) + * atomic_add_short(P, V) (*(u_short*)(P) += (V)) + * atomic_subtract_short(P, V) (*(u_short*)(P) -= (V)) + * + * atomic_set_int(P, V) (*(u_int*)(P) |= (V)) + * atomic_clear_int(P, V) (*(u_int*)(P) &= ~(V)) + * atomic_add_int(P, V) (*(u_int*)(P) += (V)) + * atomic_subtract_int(P, V) (*(u_int*)(P) -= (V)) + * atomic_readandclear_int(P) (return *(u_int*)P; *(u_int*)P = 0;) + * + * atomic_set_long(P, V) (*(u_long*)(P) |= (V)) + * atomic_clear_long(P, V) (*(u_long*)(P) &= ~(V)) + * atomic_add_long(P, V) (*(u_long*)(P) += (V)) + * atomic_subtract_long(P, V) (*(u_long*)(P) -= (V)) + * atomic_readandclear_long(P) (return *(u_long*)P; *(u_long*)P = 0;) + */ + +/* + * The above functions are expanded inline in the statically-linked + * kernel. Lock prefixes are generated if an SMP kernel is being + * built. + * + * Kernel modules call real functions which are built into the kernel. + * This allows kernel modules to be portable between UP and SMP systems. + */ +#if defined(KLD_MODULE) +#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ +void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v) + +int atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src); + +#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ +u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p); \ +void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v) + +#else /* !KLD_MODULE */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +/* + * For userland, assume the SMP case and use lock prefixes so that + * the binaries will run on both types of systems. + */ +#if defined(SMP) || !defined(_KERNEL) +#define MPLOCKED lock ; +#else +#define MPLOCKED +#endif + +/* + * The assembly is volatilized to demark potential before-and-after side + * effects if an interrupt or SMP collision were to occur. + */ +#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ +static __inline void \ +atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ +{ \ + __asm __volatile(__XSTRING(MPLOCKED) OP \ + : "+m" (*p) \ + : CONS (V)); \ +} \ +struct __hack + +#else /* !(__GNUC__ || __INTEL_COMPILER) */ + +#define ATOMIC_ASM(NAME, TYPE, OP, CONS, V) \ +extern void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v) + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +/* + * Atomic compare and set, used by the mutex functions + * + * if (*dst == exp) *dst = src (all 32 bit words) + * + * Returns 0 on failure, non-zero on success + */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +#if defined(I386_CPU) || defined(CPU_DISABLE_CMPXCHG) + +static __inline int +atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src) +{ + int res = exp; + + __asm __volatile( + " pushfl ; " + " cli ; " + " cmpl %0,%2 ; " + " jne 1f ; " + " movl %1,%2 ; " + "1: " + " sete %%al; " + " movzbl %%al,%0 ; " + " popfl ; " + "# atomic_cmpset_int" + : "+a" (res) /* 0 (result) */ + : "r" (src), /* 1 */ + "m" (*(dst)) /* 2 */ + : "memory"); + + return (res); +} + +#else /* defined(I386_CPU) */ + +static __inline int +atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src) +{ + int res = exp; + + __asm __volatile ( + " " __XSTRING(MPLOCKED) " " + " cmpxchgl %1,%2 ; " + " setz %%al ; " + " movzbl %%al,%0 ; " + "1: " + "# atomic_cmpset_int" + : "+a" (res) /* 0 (result) */ + : "r" (src), /* 1 */ + "m" (*(dst)) /* 2 */ + : "memory"); + + return (res); +} + +#endif /* defined(I386_CPU) */ + +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +#if defined(I386_CPU) + +/* + * We assume that a = b will do atomic loads and stores. + * + * XXX: This is _NOT_ safe on a P6 or higher because it does not guarantee + * memory ordering. These should only be used on a 386. + */ +#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ +static __inline u_##TYPE \ +atomic_load_acq_##TYPE(volatile u_##TYPE *p) \ +{ \ + return (*p); \ +} \ + \ +static __inline void \ +atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ +{ \ + *p = v; \ + __asm __volatile("" : : : "memory"); \ +} \ +struct __hack + +#else /* !defined(I386_CPU) */ + +#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ +static __inline u_##TYPE \ +atomic_load_acq_##TYPE(volatile u_##TYPE *p) \ +{ \ + u_##TYPE res; \ + \ + __asm __volatile(__XSTRING(MPLOCKED) LOP \ + : "=a" (res), /* 0 (result) */\ + "+m" (*p) /* 1 */ \ + : : "memory"); \ + \ + return (res); \ +} \ + \ +/* \ + * The XCHG instruction asserts LOCK automagically. \ + */ \ +static __inline void \ +atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ +{ \ + __asm __volatile(SOP \ + : "+m" (*p), /* 0 */ \ + "+r" (v) /* 1 */ \ + : : "memory"); \ +} \ +struct __hack + +#endif /* defined(I386_CPU) */ + +#else /* !(defined(__GNUC__) || defined(__INTEL_COMPILER)) */ + +extern int atomic_cmpset_int(volatile u_int *, u_int, u_int); + +#define ATOMIC_STORE_LOAD(TYPE, LOP, SOP) \ +extern u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p); \ +extern void atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v) + +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ + +#endif /* KLD_MODULE */ + +ATOMIC_ASM(set, char, "orb %b1,%0", "iq", v); +ATOMIC_ASM(clear, char, "andb %b1,%0", "iq", ~v); +ATOMIC_ASM(add, char, "addb %b1,%0", "iq", v); +ATOMIC_ASM(subtract, char, "subb %b1,%0", "iq", v); + +ATOMIC_ASM(set, short, "orw %w1,%0", "ir", v); +ATOMIC_ASM(clear, short, "andw %w1,%0", "ir", ~v); +ATOMIC_ASM(add, short, "addw %w1,%0", "ir", v); +ATOMIC_ASM(subtract, short, "subw %w1,%0", "ir", v); + +ATOMIC_ASM(set, int, "orl %1,%0", "ir", v); +ATOMIC_ASM(clear, int, "andl %1,%0", "ir", ~v); +ATOMIC_ASM(add, int, "addl %1,%0", "ir", v); +ATOMIC_ASM(subtract, int, "subl %1,%0", "ir", v); + +ATOMIC_ASM(set, long, "orl %1,%0", "ir", v); +ATOMIC_ASM(clear, long, "andl %1,%0", "ir", ~v); +ATOMIC_ASM(add, long, "addl %1,%0", "ir", v); +ATOMIC_ASM(subtract, long, "subl %1,%0", "ir", v); + +ATOMIC_STORE_LOAD(char, "cmpxchgb %b0,%1", "xchgb %b1,%0"); +ATOMIC_STORE_LOAD(short,"cmpxchgw %w0,%1", "xchgw %w1,%0"); +ATOMIC_STORE_LOAD(int, "cmpxchgl %0,%1", "xchgl %1,%0"); +ATOMIC_STORE_LOAD(long, "cmpxchgl %0,%1", "xchgl %1,%0"); + +#undef ATOMIC_ASM +#undef ATOMIC_STORE_LOAD + +#define atomic_set_acq_char atomic_set_char +#define atomic_set_rel_char atomic_set_char +#define atomic_clear_acq_char atomic_clear_char +#define atomic_clear_rel_char atomic_clear_char +#define atomic_add_acq_char atomic_add_char +#define atomic_add_rel_char atomic_add_char +#define atomic_subtract_acq_char atomic_subtract_char +#define atomic_subtract_rel_char atomic_subtract_char + +#define atomic_set_acq_short atomic_set_short +#define atomic_set_rel_short atomic_set_short +#define atomic_clear_acq_short atomic_clear_short +#define atomic_clear_rel_short atomic_clear_short +#define atomic_add_acq_short atomic_add_short +#define atomic_add_rel_short atomic_add_short +#define atomic_subtract_acq_short atomic_subtract_short +#define atomic_subtract_rel_short atomic_subtract_short + +#define atomic_set_acq_int atomic_set_int +#define atomic_set_rel_int atomic_set_int +#define atomic_clear_acq_int atomic_clear_int +#define atomic_clear_rel_int atomic_clear_int +#define atomic_add_acq_int atomic_add_int +#define atomic_add_rel_int atomic_add_int +#define atomic_subtract_acq_int atomic_subtract_int +#define atomic_subtract_rel_int atomic_subtract_int +#define atomic_cmpset_acq_int atomic_cmpset_int +#define atomic_cmpset_rel_int atomic_cmpset_int + +#define atomic_set_acq_long atomic_set_long +#define atomic_set_rel_long atomic_set_long +#define atomic_clear_acq_long atomic_clear_long +#define atomic_clear_rel_long atomic_clear_long +#define atomic_add_acq_long atomic_add_long +#define atomic_add_rel_long atomic_add_long +#define atomic_subtract_acq_long atomic_subtract_long +#define atomic_subtract_rel_long atomic_subtract_long +#define atomic_cmpset_long atomic_cmpset_int +#define atomic_cmpset_acq_long atomic_cmpset_acq_int +#define atomic_cmpset_rel_long atomic_cmpset_rel_int + +#define atomic_cmpset_acq_ptr atomic_cmpset_ptr +#define atomic_cmpset_rel_ptr atomic_cmpset_ptr + +#define atomic_set_8 atomic_set_char +#define atomic_set_acq_8 atomic_set_acq_char +#define atomic_set_rel_8 atomic_set_rel_char +#define atomic_clear_8 atomic_clear_char +#define atomic_clear_acq_8 atomic_clear_acq_char +#define atomic_clear_rel_8 atomic_clear_rel_char +#define atomic_add_8 atomic_add_char +#define atomic_add_acq_8 atomic_add_acq_char +#define atomic_add_rel_8 atomic_add_rel_char +#define atomic_subtract_8 atomic_subtract_char +#define atomic_subtract_acq_8 atomic_subtract_acq_char +#define atomic_subtract_rel_8 atomic_subtract_rel_char +#define atomic_load_acq_8 atomic_load_acq_char +#define atomic_store_rel_8 atomic_store_rel_char + +#define atomic_set_16 atomic_set_short +#define atomic_set_acq_16 atomic_set_acq_short +#define atomic_set_rel_16 atomic_set_rel_short +#define atomic_clear_16 atomic_clear_short +#define atomic_clear_acq_16 atomic_clear_acq_short +#define atomic_clear_rel_16 atomic_clear_rel_short +#define atomic_add_16 atomic_add_short +#define atomic_add_acq_16 atomic_add_acq_short +#define atomic_add_rel_16 atomic_add_rel_short +#define atomic_subtract_16 atomic_subtract_short +#define atomic_subtract_acq_16 atomic_subtract_acq_short +#define atomic_subtract_rel_16 atomic_subtract_rel_short +#define atomic_load_acq_16 atomic_load_acq_short +#define atomic_store_rel_16 atomic_store_rel_short + +#define atomic_set_32 atomic_set_int +#define atomic_set_acq_32 atomic_set_acq_int +#define atomic_set_rel_32 atomic_set_rel_int +#define atomic_clear_32 atomic_clear_int +#define atomic_clear_acq_32 atomic_clear_acq_int +#define atomic_clear_rel_32 atomic_clear_rel_int +#define atomic_add_32 atomic_add_int +#define atomic_add_acq_32 atomic_add_acq_int +#define atomic_add_rel_32 atomic_add_rel_int +#define atomic_subtract_32 atomic_subtract_int +#define atomic_subtract_acq_32 atomic_subtract_acq_int +#define atomic_subtract_rel_32 atomic_subtract_rel_int +#define atomic_load_acq_32 atomic_load_acq_int +#define atomic_store_rel_32 atomic_store_rel_int +#define atomic_cmpset_32 atomic_cmpset_int +#define atomic_cmpset_acq_32 atomic_cmpset_acq_int +#define atomic_cmpset_rel_32 atomic_cmpset_rel_int +#define atomic_readandclear_32 atomic_readandclear_int + +#if !defined(WANT_FUNCTIONS) +static __inline int +atomic_cmpset_ptr(volatile void *dst, void *exp, void *src) +{ + + return (atomic_cmpset_int((volatile u_int *)dst, (u_int)exp, + (u_int)src)); +} + +static __inline void * +atomic_load_acq_ptr(volatile void *p) +{ + /* + * The apparently-bogus cast to intptr_t in the following is to + * avoid a warning from "gcc -Wbad-function-cast". + */ + return ((void *)(intptr_t)atomic_load_acq_int((volatile u_int *)p)); +} + +static __inline void +atomic_store_rel_ptr(volatile void *p, void *v) +{ + atomic_store_rel_int((volatile u_int *)p, (u_int)v); +} + +#define ATOMIC_PTR(NAME) \ +static __inline void \ +atomic_##NAME##_ptr(volatile void *p, uintptr_t v) \ +{ \ + atomic_##NAME##_int((volatile u_int *)p, v); \ +} \ + \ +static __inline void \ +atomic_##NAME##_acq_ptr(volatile void *p, uintptr_t v) \ +{ \ + atomic_##NAME##_acq_int((volatile u_int *)p, v);\ +} \ + \ +static __inline void \ +atomic_##NAME##_rel_ptr(volatile void *p, uintptr_t v) \ +{ \ + atomic_##NAME##_rel_int((volatile u_int *)p, v);\ +} + +ATOMIC_PTR(set) +ATOMIC_PTR(clear) +ATOMIC_PTR(add) +ATOMIC_PTR(subtract) + +#undef ATOMIC_PTR + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +static __inline u_int +atomic_readandclear_int(volatile u_int *addr) +{ + u_int result; + + __asm __volatile ( + " xorl %0,%0 ; " + " xchgl %1,%0 ; " + "# atomic_readandclear_int" + : "=&r" (result) /* 0 (result) */ + : "m" (*addr)); /* 1 (addr) */ + + return (result); +} + +static __inline u_long +atomic_readandclear_long(volatile u_long *addr) +{ + u_long result; + + __asm __volatile ( + " xorl %0,%0 ; " + " xchgl %1,%0 ; " + "# atomic_readandclear_int" + : "=&r" (result) /* 0 (result) */ + : "m" (*addr)); /* 1 (addr) */ + + return (result); +} + +#else /* !(defined(__GNUC__) || defined(__INTEL_COMPILER)) */ + +extern u_long atomic_readandclear_long(volatile u_long *); +extern u_int atomic_readandclear_int(volatile u_int *); + +#endif /* defined(__GNUC__) || defined(__INTEL_COMPILER) */ + +#endif /* !defined(WANT_FUNCTIONS) */ +#endif /* ! _MACHINE_ATOMIC_H_ */ diff --git a/src/include/machine/bootinfo.h b/src/include/machine/bootinfo.h new file mode 100644 index 0000000..9a8e894 --- /dev/null +++ b/src/include/machine/bootinfo.h @@ -0,0 +1,118 @@ +/*- + * Copyright (C) 1994 by Rodney W. Grimes, Milwaukie, Oregon 97222 + * 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 as + * the first lines of this file unmodified. + * 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 Rodney W. Grimes. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RODNEY W. GRIMES ``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 RODNEY W. GRIMES 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. + * + * $FreeBSD: src/sys/i386/include/bootinfo.h,v 1.15 2003/04/04 16:35:15 phk Exp $ + */ + +#ifndef _MACHINE_BOOTINFO_H_ +#define _MACHINE_BOOTINFO_H_ + +/* Only change the version number if you break compatibility. */ +#define BOOTINFO_VERSION 1 + +#define N_BIOS_GEOM 8 + +/* + * A zero bootinfo field often means that there is no info available. + * Flags are used to indicate the validity of fields where zero is a + * normal value. + */ +struct bootinfo { + u_int32_t bi_version; + u_int32_t bi_kernelname; /* represents a char * */ + u_int32_t bi_nfs_diskless; /* struct nfs_diskless * */ + /* End of fields that are always present. */ +#define bi_endcommon bi_n_bios_used + u_int32_t bi_n_bios_used; + u_int32_t bi_bios_geom[N_BIOS_GEOM]; + u_int32_t bi_size; + u_int8_t bi_memsizes_valid; + u_int8_t bi_bios_dev; /* bootdev BIOS unit number */ + u_int8_t bi_pad[2]; + u_int32_t bi_basemem; + u_int32_t bi_extmem; + u_int32_t bi_symtab; /* struct symtab * */ + u_int32_t bi_esymtab; /* struct symtab * */ + /* Items below only from advanced bootloader */ + u_int32_t bi_kernend; /* end of kernel space */ + u_int32_t bi_envp; /* environment */ + u_int32_t bi_modulep; /* preloaded modules */ +}; + +#ifdef _KERNEL +extern struct bootinfo bootinfo; +#endif + +/* + * Constants for converting boot-style device number to type, + * adaptor (uba, mba, etc), unit number and partition number. + * Type (== major device number) is in the low byte + * for backward compatibility. Except for that of the "magic + * number", each mask applies to the shifted value. + * Format: + * (4) (4) (4) (4) (8) (8) + * -------------------------------- + * |MA | AD| CT| UN| PART | TYPE | + * -------------------------------- + */ +#define B_ADAPTORSHIFT 24 +#define B_ADAPTORMASK 0x0f +#define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK) +#define B_CONTROLLERSHIFT 20 +#define B_CONTROLLERMASK 0xf +#define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK) +#define B_SLICESHIFT 20 +#define B_SLICEMASK 0xff +#define B_SLICE(val) (((val)>>B_SLICESHIFT) & B_SLICEMASK) +#define B_UNITSHIFT 16 +#define B_UNITMASK 0xf +#define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK) +#define B_PARTITIONSHIFT 8 +#define B_PARTITIONMASK 0xff +#define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK) +#define B_TYPESHIFT 0 +#define B_TYPEMASK 0xff +#define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK) + +#define B_MAGICMASK 0xf0000000 +#define B_DEVMAGIC 0xa0000000 + +#define MAKEBOOTDEV(type, adaptor, controller, unit, partition) \ + (((type) << B_TYPESHIFT) | ((adaptor) << B_ADAPTORSHIFT) | \ + ((controller) << B_CONTROLLERSHIFT) | ((unit) << B_UNITSHIFT) | \ + ((partition) << B_PARTITIONSHIFT) | B_DEVMAGIC) + +#define BASE_SLICE 2 +#define COMPATIBILITY_SLICE 0 +#define MAX_SLICES 32 +#define WHOLE_DISK_SLICE 1 + +#endif /* !_MACHINE_BOOTINFO_H_ */ diff --git a/src/include/machine/bus.h b/src/include/machine/bus.h new file mode 100644 index 0000000..200af7f --- /dev/null +++ b/src/include/machine/bus.h @@ -0,0 +1,110 @@ +/*- + * Copyright (c) KATO Takenori, 1999. + * + * All rights reserved. Unpublished rights reserved under the copyright + * laws of Japan. + * + * 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 as + * the first lines of this file unmodified. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/bus.h,v 1.10 2002/02/27 17:15:45 tmm Exp $ + */ + +#ifndef _I386_BUS_H_ +#define _I386_BUS_H_ + +#ifdef PC98 +/* NEC PC-98 */ +#include +#else +/* IBM-PC */ +#include +#endif +#include + +/* + * Stream accesses are the same as normal accesses on i386/pc98; there are no + * supported bus systems with an endianess different from the host one. + */ +#define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o)) +#define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o)) +#define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o)) + +#define bus_space_read_multi_stream_1(t, h, o, a, c) \ + bus_space_read_multi_1((t), (h), (o), (a), (c)) +#define bus_space_read_multi_stream_2(t, h, o, a, c) \ + bus_space_read_multi_2((t), (h), (o), (a), (c)) +#define bus_space_read_multi_stream_4(t, h, o, a, c) \ + bus_space_read_multi_4((t), (h), (o), (a), (c)) + +#define bus_space_write_stream_1(t, h, o, v) \ + bus_space_write_1((t), (h), (o), (v)) +#define bus_space_write_stream_2(t, h, o, v) \ + bus_space_write_2((t), (h), (o), (v)) +#define bus_space_write_stream_4(t, h, o, v) \ + bus_space_write_4((t), (h), (o), (v)) + +#define bus_space_write_multi_stream_1(t, h, o, a, c) \ + bus_space_write_multi_1((t), (h), (o), (a), (c)) +#define bus_space_write_multi_stream_2(t, h, o, a, c) \ + bus_space_write_multi_2((t), (h), (o), (a), (c)) +#define bus_space_write_multi_stream_4(t, h, o, a, c) \ + bus_space_write_multi_4((t), (h), (o), (a), (c)) + +#define bus_space_set_multi_stream_1(t, h, o, v, c) \ + bus_space_set_multi_1((t), (h), (o), (v), (c)) +#define bus_space_set_multi_stream_2(t, h, o, v, c) \ + bus_space_set_multi_2((t), (h), (o), (v), (c)) +#define bus_space_set_multi_stream_4(t, h, o, v, c) \ + bus_space_set_multi_4((t), (h), (o), (v), (c)) + +#define bus_space_read_region_stream_1(t, h, o, a, c) \ + bus_space_read_region_1((t), (h), (o), (a), (c)) +#define bus_space_read_region_stream_2(t, h, o, a, c) \ + bus_space_read_region_2((t), (h), (o), (a), (c)) +#define bus_space_read_region_stream_4(t, h, o, a, c) \ + bus_space_read_region_4((t), (h), (o), (a), (c)) + +#define bus_space_write_region_stream_1(t, h, o, a, c) \ + bus_space_write_region_1((t), (h), (o), (a), (c)) +#define bus_space_write_region_stream_2(t, h, o, a, c) \ + bus_space_write_region_2((t), (h), (o), (a), (c)) +#define bus_space_write_region_stream_4(t, h, o, a, c) \ + bus_space_write_region_4((t), (h), (o), (a), (c)) + +#define bus_space_set_region_stream_1(t, h, o, v, c) \ + bus_space_set_region_1((t), (h), (o), (v), (c)) +#define bus_space_set_region_stream_2(t, h, o, v, c) \ + bus_space_set_region_2((t), (h), (o), (v), (c)) +#define bus_space_set_region_stream_4(t, h, o, v, c) \ + bus_space_set_region_4((t), (h), (o), (v), (c)) + +#define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \ + bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c)) +#define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \ + bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c)) +#define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \ + bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c)) + +#endif /* _I386_BUS_H_ */ diff --git a/src/include/machine/bus_at386.h b/src/include/machine/bus_at386.h new file mode 100644 index 0000000..157d396 --- /dev/null +++ b/src/include/machine/bus_at386.h @@ -0,0 +1,1308 @@ +/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. 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 Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ +/* $FreeBSD: src/sys/i386/include/bus_at386.h,v 1.24 2004/03/12 21:45:29 trhodes Exp $ */ + +#ifndef _I386_BUS_AT386_H_ +#define _I386_BUS_AT386_H_ + +#include + +/* + * To remain compatible with NetBSD's interface, default to both memio and + * pio when neither of them is defined. + */ +#if !defined(_I386_BUS_PIO_H_) && !defined(_I386_BUS_MEMIO_H_) +#define _I386_BUS_PIO_H_ +#define _I386_BUS_MEMIO_H_ +#endif + +/* + * Values for the i386 bus space tag, not to be used directly by MI code. + */ +#define I386_BUS_SPACE_IO 0 /* space is i/o space */ +#define I386_BUS_SPACE_MEM 1 /* space is mem space */ + +/* + * Bus address and size types + */ +#ifdef PAE +typedef uint64_t bus_addr_t; +#else +typedef uint32_t bus_addr_t; +#endif +typedef uint32_t bus_size_t; + +#define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF +#define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF +#define BUS_SPACE_MAXSIZE 0xFFFFFFFF +#define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF +#define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF +#ifdef PAE +#define BUS_SPACE_MAXADDR 0xFFFFFFFFFFFFFFFFULL +#else +#define BUS_SPACE_MAXADDR 0xFFFFFFFF +#endif + +#define BUS_SPACE_UNRESTRICTED (~0) + +/* + * Access methods for bus resources and address space. + */ +typedef int bus_space_tag_t; +typedef u_int bus_space_handle_t; + +/* + * Map a region of device bus space into CPU virtual address space. + */ + +static __inline int bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, + bus_space_handle_t *bshp); + +static __inline int +bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr, + bus_size_t size __unused, int flags __unused, + bus_space_handle_t *bshp) +{ + + *bshp = addr; + return (0); +} + +/* + * Unmap a region of device bus space. + */ + +static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +static __inline void +bus_space_unmap(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused, + bus_size_t size __unused) +{ +} + +/* + * Get a new handle for a subregion of an already-mapped area of bus space. + */ + +static __inline int bus_space_subregion(bus_space_tag_t t, + bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, + bus_space_handle_t *nbshp); + +static __inline int +bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size __unused, + bus_space_handle_t *nbshp) +{ + + *nbshp = bsh + offset; + return (0); +} + +/* + * Allocate a region of memory that is accessible to devices in bus space. + */ + +int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t align, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *bshp); + +/* + * Free a region of bus space accessible memory. + */ + +static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +static __inline void +bus_space_free(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused, + bus_size_t size __unused) +{ +} + + +#if defined(_I386_BUS_PIO_H_) || defined(_I386_BUS_MEMIO_H_) + +/* + * Read a 1, 2, 4, or 8 byte quantity from bus space + * described by tag/handle/offset. + */ +static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag, + bus_space_handle_t handle, + bus_size_t offset); + +static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag, + bus_space_handle_t handle, + bus_size_t offset); + +static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag, + bus_space_handle_t handle, + bus_size_t offset); + +static __inline u_int8_t +bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ +#if defined (_I386_BUS_PIO_H_) +#if defined (_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + return (inb(handle + offset)); +#endif +#if defined (_I386_BUS_MEMIO_H_) + return (*(volatile u_int8_t *)(handle + offset)); +#endif +} + +static __inline u_int16_t +bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + return (inw(handle + offset)); +#endif +#if defined(_I386_BUS_MEMIO_H_) + return (*(volatile u_int16_t *)(handle + offset)); +#endif +} + +static __inline u_int32_t +bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t offset) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + return (inl(handle + offset)); +#endif +#if defined(_I386_BUS_MEMIO_H_) + return (*(volatile u_int32_t *)(handle + offset)); +#endif +} + +#if 0 /* Cause a link error for bus_space_read_8 */ +#define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!! +#endif + +/* + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle/offset and copy into buffer provided. + */ +static __inline void bus_space_read_multi_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, + size_t count); + +static __inline void bus_space_read_multi_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, + size_t count); + +static __inline void bus_space_read_multi_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, + size_t count); + +static __inline void +bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + insb(bsh + offset, addr, count); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: movb (%2),%%al \n\ + stosb \n\ + loop 1b" : + "=D" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + insw(bsh + offset, addr, count); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: movw (%2),%%ax \n\ + stosw \n\ + loop 1b" : + "=D" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + insl(bsh + offset, addr, count); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: movl (%2),%%eax \n\ + stosl \n\ + loop 1b" : + "=D" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +#if 0 /* Cause a link error for bus_space_read_multi_8 */ +#define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!! +#endif + +/* + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ +static __inline void bus_space_read_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, + size_t count); + +static __inline void bus_space_read_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, + size_t count); + +static __inline void bus_space_read_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, + size_t count); + + +static __inline void +bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: inb %w2,%%al \n\ + stosb \n\ + incl %2 \n\ + loop 1b" : + "=D" (addr), "=c" (count), "=d" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsb" : + "=D" (addr), "=c" (count), "=S" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: inw %w2,%%ax \n\ + stosw \n\ + addl $2,%2 \n\ + loop 1b" : + "=D" (addr), "=c" (count), "=d" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsw" : + "=D" (addr), "=c" (count), "=S" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: inl %w2,%%eax \n\ + stosl \n\ + addl $4,%2 \n\ + loop 1b" : + "=D" (addr), "=c" (count), "=d" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsl" : + "=D" (addr), "=c" (count), "=S" (_port_) : + "0" (addr), "1" (count), "2" (_port_) : + "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +#if 0 /* Cause a link error for bus_space_read_region_8 */ +#define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!! +#endif + +/* + * Write the 1, 2, 4, or 8 byte value `value' to bus space + * described by tag/handle/offset. + */ + +static __inline void bus_space_write_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value); + +static __inline void bus_space_write_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value); + +static __inline void bus_space_write_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value); + +static __inline void +bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + outb(bsh + offset, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + *(volatile u_int8_t *)(bsh + offset) = value; +#endif +} + +static __inline void +bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + outw(bsh + offset, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + *(volatile u_int16_t *)(bsh + offset) = value; +#endif +} + +static __inline void +bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + outl(bsh + offset, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + *(volatile u_int32_t *)(bsh + offset) = value; +#endif +} + +#if 0 /* Cause a link error for bus_space_write_8 */ +#define bus_space_write_8 !!! bus_space_write_8 not implemented !!! +#endif + +/* + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer + * provided to bus space described by tag/handle/offset. + */ + +static __inline void bus_space_write_multi_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int8_t *addr, + size_t count); +static __inline void bus_space_write_multi_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int16_t *addr, + size_t count); + +static __inline void bus_space_write_multi_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int32_t *addr, + size_t count); + +static __inline void +bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + outsb(bsh + offset, addr, count); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: lodsb \n\ + movb %%al,(%2) \n\ + loop 1b" : + "=S" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int16_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + outsw(bsh + offset, addr, count); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: lodsw \n\ + movw %%ax,(%2) \n\ + loop 1b" : + "=S" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int32_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + outsl(bsh + offset, addr, count); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: lodsl \n\ + movl %%eax,(%2) \n\ + loop 1b" : + "=S" (addr), "=c" (count) : + "r" (bsh + offset), "0" (addr), "1" (count) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +#if 0 /* Cause a link error for bus_space_write_multi_8 */ +#define bus_space_write_multi_8(t, h, o, a, c) \ + !!! bus_space_write_multi_8 unimplemented !!! +#endif + +/* + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + +static __inline void bus_space_write_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int8_t *addr, + size_t count); +static __inline void bus_space_write_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int16_t *addr, + size_t count); +static __inline void bus_space_write_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + const u_int32_t *addr, + size_t count); + +static __inline void +bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: lodsb \n\ + outb %%al,%w0 \n\ + incl %0 \n\ + loop 1b" : + "=d" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsb" : + "=D" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int16_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: lodsw \n\ + outw %%ax,%w0 \n\ + addl $2,%0 \n\ + loop 1b" : + "=d" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsw" : + "=D" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +static __inline void +bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int32_t *addr, size_t count) +{ +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + 1: lodsl \n\ + outl %%eax,%w0 \n\ + addl $4,%0 \n\ + loop 1b" : + "=d" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "%eax", "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + int _port_ = bsh + offset; +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + __asm __volatile(" \n\ + cld \n\ + repne \n\ + movsl" : + "=D" (_port_), "=S" (addr), "=c" (count) : + "0" (_port_), "1" (addr), "2" (count) : + "memory", "cc"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif + } +#endif +} + +#if 0 /* Cause a link error for bus_space_write_region_8 */ +#define bus_space_write_region_8 \ + !!! bus_space_write_region_8 unimplemented !!! +#endif + +/* + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ + +static __inline void bus_space_set_multi_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + u_int8_t value, size_t count); +static __inline void bus_space_set_multi_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + u_int16_t value, size_t count); +static __inline void bus_space_set_multi_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, + u_int32_t value, size_t count); + +static __inline void +bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + while (count--) + outb(addr, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + while (count--) + *(volatile u_int8_t *)(addr) = value; +#endif +} + +static __inline void +bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + while (count--) + outw(addr, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + while (count--) + *(volatile u_int16_t *)(addr) = value; +#endif +} + +static __inline void +bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + while (count--) + outl(addr, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + while (count--) + *(volatile u_int32_t *)(addr) = value; +#endif +} + +#if 0 /* Cause a link error for bus_space_set_multi_8 */ +#define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!! +#endif + +/* + * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle starting at `offset'. + */ + +static __inline void bus_space_set_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value, + size_t count); +static __inline void bus_space_set_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value, + size_t count); +static __inline void bus_space_set_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value, + size_t count); + +static __inline void +bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + for (; count != 0; count--, addr++) + outb(addr, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + for (; count != 0; count--, addr++) + *(volatile u_int8_t *)(addr) = value; +#endif +} + +static __inline void +bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + for (; count != 0; count--, addr += 2) + outw(addr, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + for (; count != 0; count--, addr += 2) + *(volatile u_int16_t *)(addr) = value; +#endif +} + +static __inline void +bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t value, size_t count) +{ + bus_space_handle_t addr = bsh + offset; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + for (; count != 0; count--, addr += 4) + outl(addr, value); +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + for (; count != 0; count--, addr += 4) + *(volatile u_int32_t *)(addr) = value; +#endif +} + +#if 0 /* Cause a link error for bus_space_set_region_8 */ +#define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!! +#endif + +/* + * Copy `count' 1, 2, 4, or 8 byte values from bus space starting + * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. + */ + +static __inline void bus_space_copy_region_1(bus_space_tag_t tag, + bus_space_handle_t bsh1, + bus_size_t off1, + bus_space_handle_t bsh2, + bus_size_t off2, size_t count); + +static __inline void bus_space_copy_region_2(bus_space_tag_t tag, + bus_space_handle_t bsh1, + bus_size_t off1, + bus_space_handle_t bsh2, + bus_size_t off2, size_t count); + +static __inline void bus_space_copy_region_4(bus_space_tag_t tag, + bus_space_handle_t bsh1, + bus_size_t off1, + bus_space_handle_t bsh2, + bus_size_t off2, size_t count); + +static __inline void +bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1, + bus_size_t off1, bus_space_handle_t bsh2, + bus_size_t off2, size_t count) +{ + bus_space_handle_t addr1 = bsh1 + off1; + bus_space_handle_t addr2 = bsh2 + off2; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1++, addr2++) + outb(addr2, inb(addr1)); + } else { + /* dest after src: copy backwards */ + for (addr1 += (count - 1), addr2 += (count - 1); + count != 0; count--, addr1--, addr2--) + outb(addr2, inb(addr1)); + } + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1++, addr2++) + *(volatile u_int8_t *)(addr2) = + *(volatile u_int8_t *)(addr1); + } else { + /* dest after src: copy backwards */ + for (addr1 += (count - 1), addr2 += (count - 1); + count != 0; count--, addr1--, addr2--) + *(volatile u_int8_t *)(addr2) = + *(volatile u_int8_t *)(addr1); + } + } +#endif +} + +static __inline void +bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1, + bus_size_t off1, bus_space_handle_t bsh2, + bus_size_t off2, size_t count) +{ + bus_space_handle_t addr1 = bsh1 + off1; + bus_space_handle_t addr2 = bsh2 + off2; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 2, addr2 += 2) + outw(addr2, inw(addr1)); + } else { + /* dest after src: copy backwards */ + for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1); + count != 0; count--, addr1 -= 2, addr2 -= 2) + outw(addr2, inw(addr1)); + } + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 2, addr2 += 2) + *(volatile u_int16_t *)(addr2) = + *(volatile u_int16_t *)(addr1); + } else { + /* dest after src: copy backwards */ + for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1); + count != 0; count--, addr1 -= 2, addr2 -= 2) + *(volatile u_int16_t *)(addr2) = + *(volatile u_int16_t *)(addr1); + } + } +#endif +} + +static __inline void +bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1, + bus_size_t off1, bus_space_handle_t bsh2, + bus_size_t off2, size_t count) +{ + bus_space_handle_t addr1 = bsh1 + off1; + bus_space_handle_t addr2 = bsh2 + off2; + +#if defined(_I386_BUS_PIO_H_) +#if defined(_I386_BUS_MEMIO_H_) + if (tag == I386_BUS_SPACE_IO) +#endif + { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 4, addr2 += 4) + outl(addr2, inl(addr1)); + } else { + /* dest after src: copy backwards */ + for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1); + count != 0; count--, addr1 -= 4, addr2 -= 4) + outl(addr2, inl(addr1)); + } + } +#endif +#if defined(_I386_BUS_MEMIO_H_) +#if defined(_I386_BUS_PIO_H_) + else +#endif + { + if (addr1 >= addr2) { + /* src after dest: copy forward */ + for (; count != 0; count--, addr1 += 4, addr2 += 4) + *(volatile u_int32_t *)(addr2) = + *(volatile u_int32_t *)(addr1); + } else { + /* dest after src: copy backwards */ + for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1); + count != 0; count--, addr1 -= 4, addr2 -= 4) + *(volatile u_int32_t *)(addr2) = + *(volatile u_int32_t *)(addr1); + } + } +#endif +} + +#endif /* defined(_I386_BUS_PIO_H_) || defined(_I386_MEM_IO_H_) */ + +#if 0 /* Cause a link error for bus_space_copy_8 */ +#define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!! +#endif + +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh, + * bus_size_t offset, bus_size_t len, int flags); + * + * + * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than + * prevent reordering by the compiler; all Intel x86 processors currently + * retire operations outside the CPU in program order. + */ +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +static __inline void +bus_space_barrier(bus_space_tag_t tag __unused, bus_space_handle_t bsh __unused, + bus_size_t offset __unused, bus_size_t len __unused, int flags) +{ +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + if (flags & BUS_SPACE_BARRIER_READ) + __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); + else + __asm __volatile("" : : : "memory"); +#else +# ifndef lint +# error "no assembler code for your compiler" +# endif +#endif +} + +#endif /* _I386_BUS_AT386_H_ */ diff --git a/src/include/machine/bus_dma.h b/src/include/machine/bus_dma.h new file mode 100644 index 0000000..4875f6b --- /dev/null +++ b/src/include/machine/bus_dma.h @@ -0,0 +1,262 @@ +/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. 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 Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ +/* $FreeBSD: src/sys/i386/include/bus_dma.h,v 1.25 2003/11/07 23:29:41 scottl Exp $ */ + +#ifndef _I386_BUS_DMA_H_ +#define _I386_BUS_DMA_H_ + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ +#define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x20 +#define BUS_DMA_BUS3 0x40 +#define BUS_DMA_BUS4 0x80 + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +typedef int bus_dmasync_op_t; +#define BUS_DMASYNC_PREREAD 1 +#define BUS_DMASYNC_POSTREAD 2 +#define BUS_DMASYNC_PREWRITE 4 +#define BUS_DMASYNC_POSTWRITE 8 + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the characteristics + * of how to perform DMA mappings. This structure encapsultes + * information concerning address and alignment restrictions, number + * of S/G segments, amount of data per S/G segment, etc. + */ +typedef struct bus_dma_tag *bus_dma_tag_t; + +/* + * bus_dmamap_t + * + * DMA mapping instance information. + */ +typedef struct bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +typedef struct bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ +} bus_dma_segment_t; + +/* + * A function that returns 1 if the address cannot be accessed by + * a device and 0 if it can be. + */ +typedef int bus_dma_filter_t(void *, bus_addr_t); + +/* + * A function that performs driver-specific synchronization on behalf of + * busdma. + */ +typedef enum { + BUS_DMA_LOCK = 0x01, + BUS_DMA_UNLOCK = 0x02, +} bus_dma_lock_op_t; + +typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); + +/* + * Allocate a device specific dma_tag encapsulating the constraints of + * the parent tag in addition to other restrictions specified: + * + * alignment: Alignment for segments. + * boundary: Boundary that segments cannot cross. + * lowaddr: Low restricted address that cannot appear in a mapping. + * highaddr: High restricted address that cannot appear in a mapping. + * filtfunc: An optional function to further test if an address + * within the range of lowaddr and highaddr cannot appear + * in a mapping. + * filtfuncarg: An argument that will be passed to filtfunc in addition + * to the address to test. + * maxsize: Maximum mapping size supported by this tag. + * nsegments: Number of discontinuities allowed in maps. + * maxsegsz: Maximum size of a segment in the map. + * flags: Bus DMA flags. + * lockfunc: An optional function to handle driver-defined lock + * operations. + * lockfuncarg: An argument that will be passed to lockfunc in addition + * to the lock operation. + * dmat: A pointer to set to a valid dma tag should the return + * value of this function indicate success. + */ +/* XXX Should probably allow specification of alignment */ +int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, + bus_size_t boundary, bus_addr_t lowaddr, + bus_addr_t highaddr, bus_dma_filter_t *filtfunc, + void *filtfuncarg, bus_size_t maxsize, int nsegments, + bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, bus_dma_tag_t *dmat); + +int bus_dma_tag_destroy(bus_dma_tag_t dmat); + +/* + * Allocate a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); + +/* + * Destroy a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map); + +/* + * Allocate a piece of memory that can be efficiently mapped into + * bus device space based on the constraints listed in the dma tag. + * A dmamap to for use with dmamap_load is also allocated. + */ +int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, + bus_dmamap_t *mapp); + +/* + * Free a piece of memory and its allocated dmamap, that was allocated + * via bus_dmamem_alloc. + */ +void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); + +/* + * A function that processes a successfully loaded dma map or an error + * from a delayed load map. + */ +typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); + +/* + * Map the buffer buf into bus space using the dmamap map. + */ +int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, + bus_size_t buflen, bus_dmamap_callback_t *callback, + void *callback_arg, int flags); + +/* + * Like bus_dmamap_callback but includes map size in bytes. This is + * defined as a separate interface to maintain compatibility for users + * of bus_dmamap_callback_t--at some point these interfaces should be merged. + */ +typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); +/* + * Like bus_dmamap_load but for mbufs. Note the use of the + * bus_dmamap_callback2_t interface. + */ +int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, + struct mbuf *mbuf, + bus_dmamap_callback2_t *callback, void *callback_arg, + int flags); +/* + * Like bus_dmamap_load but for uios. Note the use of the + * bus_dmamap_callback2_t interface. + */ +int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map, + struct uio *ui, + bus_dmamap_callback2_t *callback, void *callback_arg, + int flags); + +/* + * Perform a synchronization operation on the given map. + */ +void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t); +#define bus_dmamap_sync(dmat, dmamap, op) \ + if ((dmamap) != NULL) \ + _bus_dmamap_sync(dmat, dmamap, op) + +/* + * Release the mapping held by map. + */ +void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map); +#define bus_dmamap_unload(dmat, dmamap) \ + if ((dmamap) != NULL) \ + _bus_dmamap_unload(dmat, dmamap) + +/* + * Generic helper function for manipulating mutexes. + */ +void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); +#endif /* _I386_BUS_DMA_H_ */ diff --git a/src/include/machine/bus_memio.h b/src/include/machine/bus_memio.h new file mode 100644 index 0000000..a4e6b2f --- /dev/null +++ b/src/include/machine/bus_memio.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 1997 Justin Gibbs. + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/bus_memio.h,v 1.2 1999/08/28 00:44:08 peter Exp $ + */ + +#ifndef _I386_BUS_MEMIO_H_ +#define _I386_BUS_MEMIO_H_ +#endif /* _I386_BUS_MEMIO_H_ */ diff --git a/src/include/machine/bus_pc98.h b/src/include/machine/bus_pc98.h new file mode 100644 index 0000000..2b77abf --- /dev/null +++ b/src/include/machine/bus_pc98.h @@ -0,0 +1,540 @@ +/* $FreeBSD: src/sys/i386/include/bus_pc98.h,v 1.27 2004/05/04 06:38:13 nyan Exp $ */ +/* $NecBSD: busio.h,v 3.25.4.2.2.1 2000/06/12 03:53:08 honda Exp $ */ +/* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */ + +/* + * [NetBSD for NEC PC-98 series] + * Copyright (c) 1997, 1998 + * NetBSD/pc98 porting staff. All rights reserved. + * + * [Ported for FreeBSD] + * Copyright (c) 2001 + * TAKAHASHI Yoshihiro. 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +/* + * Copyright (c) 1997, 1998 + * Naofumi HONDA. All rights reserved. + * + * This module support generic bus address relocation mechanism. + * To reduce a function call overhead, we employ pascal call methods. + */ + +#ifndef _I386_BUS_PC98_H_ +#define _I386_BUS_PC98_H_ + +#include + +#include + +/* + * Bus address and size types + */ +typedef u_int bus_addr_t; +typedef u_int bus_size_t; + +#define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF +#define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF +#define BUS_SPACE_MAXSIZE 0xFFFFFFFF +#define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF +#define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF +#define BUS_SPACE_MAXADDR 0xFFFFFFFF + +#define BUS_SPACE_UNRESTRICTED (~0) + +#define BUS_SPACE_IAT_MAXSIZE 33 + +/* + * Access methods for bus resources and address space. + */ +struct resource; + +/* + * bus space tag + */ +#define _PASCAL_CALL (void) + +#define _BUS_SPACE_CALL_FUNCS_TAB(NAME,TYPE,BWN) \ + NAME##_space_read_##BWN, \ + NAME##_space_read_multi_##BWN, \ + NAME##_space_read_region_##BWN, \ + NAME##_space_write_##BWN, \ + NAME##_space_write_multi_##BWN, \ + NAME##_space_write_region_##BWN, \ + NAME##_space_set_multi_##BWN, \ + NAME##_space_set_region_##BWN, \ + NAME##_space_copy_region_##BWN + +#define _BUS_SPACE_CALL_FUNCS_PROTO(NAME,TYPE,BWN) \ + TYPE NAME##_space_read_##BWN _PASCAL_CALL; \ + void NAME##_space_read_multi_##BWN _PASCAL_CALL; \ + void NAME##_space_read_region_##BWN _PASCAL_CALL; \ + void NAME##_space_write_##BWN _PASCAL_CALL; \ + void NAME##_space_write_multi_##BWN _PASCAL_CALL; \ + void NAME##_space_write_region_##BWN _PASCAL_CALL; \ + void NAME##_space_set_multi_##BWN _PASCAL_CALL; \ + void NAME##_space_set_region_##BWN _PASCAL_CALL; \ + void NAME##_space_copy_region_##BWN _PASCAL_CALL; + +#define _BUS_SPACE_CALL_FUNCS(NAME,TYPE,BWN) \ + TYPE (* NAME##_read_##BWN) _PASCAL_CALL; \ + void (* NAME##_read_multi_##BWN) _PASCAL_CALL; \ + void (* NAME##_read_region_##BWN) _PASCAL_CALL; \ + void (* NAME##_write_##BWN) _PASCAL_CALL; \ + void (* NAME##_write_multi_##BWN) _PASCAL_CALL; \ + void (* NAME##_write_region_##BWN) _PASCAL_CALL; \ + void (* NAME##_set_multi_##BWN) _PASCAL_CALL; \ + void (* NAME##_set_region_##BWN) _PASCAL_CALL; \ + void (* NAME##_copy_region_##BWN) _PASCAL_CALL; + +struct bus_space_access_methods { + /* 8 bits access methods */ + _BUS_SPACE_CALL_FUNCS(bs,u_int8_t,1) + + /* 16 bits access methods */ + _BUS_SPACE_CALL_FUNCS(bs,u_int16_t,2) + + /* 32 bits access methods */ + _BUS_SPACE_CALL_FUNCS(bs,u_int32_t,4) +}; + +struct bus_space_tag { +#define BUS_SPACE_IO 0 +#define BUS_SPACE_MEM 1 + u_int bs_tag; /* bus space flags */ + + struct bus_space_access_methods bs_da; /* direct access */ + struct bus_space_access_methods bs_ra; /* relocate access */ +#if 0 + struct bus_space_access_methods bs_ida; /* indexed direct access */ +#endif +}; +typedef struct bus_space_tag *bus_space_tag_t; + +/* + * Values for the i386 bus space tag, not to be used directly by MI code. + */ +extern struct bus_space_tag SBUS_io_space_tag; +extern struct bus_space_tag SBUS_mem_space_tag; + +#define I386_BUS_SPACE_IO (&SBUS_io_space_tag) +#define I386_BUS_SPACE_MEM (&SBUS_mem_space_tag) + +/* + * bus space handle + */ +struct bus_space_handle { + bus_addr_t bsh_base; + size_t bsh_sz; + + bus_addr_t bsh_iat[BUS_SPACE_IAT_MAXSIZE]; + size_t bsh_maxiatsz; + size_t bsh_iatsz; + + struct resource **bsh_res; + size_t bsh_ressz; + + struct bus_space_access_methods bsh_bam; +}; +typedef struct bus_space_handle *bus_space_handle_t; + +/* + * Allocate/Free bus_space_handle + */ +int i386_bus_space_handle_alloc(bus_space_tag_t t, bus_addr_t bpa, + bus_size_t size, bus_space_handle_t *bshp); +void i386_bus_space_handle_free(bus_space_tag_t t, bus_space_handle_t bsh, + size_t size); + +/* + * int bus_space_map (bus_space_tag_t t, bus_addr_t addr, + * bus_size_t size, int flag, bus_space_handle_t *bshp); + * + * Map a region of bus space. + */ + +int i386_memio_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size, + int flag, bus_space_handle_t *bshp); + +#define bus_space_map(t, a, s, f, hp) \ + i386_memio_map((t), (a), (s), (f), (hp)) + +/* + * int bus_space_unmap (bus_space_tag_t t, + * bus_space_handle_t bsh, bus_size_t size); + * + * Unmap a region of bus space. + */ + +void i386_memio_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +#define bus_space_unmap(t, h, s) \ + i386_memio_unmap((t), (h), (s)) + +/* + * int bus_space_subregion (bus_space_tag_t t, + * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, + * bus_space_handle_t *nbshp); + * + * Get a new handle for a subregion of an already-mapped area of bus space. + */ + +int i386_memio_subregion(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, + bus_space_handle_t *nbshp); + +#define bus_space_subregion(t, h, o, s, nhp) \ + i386_memio_subregion((t), (h), (o), (s), (nhp)) + +/* + * int bus_space_free (bus_space_tag_t t, + * bus_space_handle_t bsh, bus_size_t size); + * + * Free a region of bus space. + */ + +void i386_memio_free(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +#define bus_space_free(t, h, s) \ + i386_memio_free((t), (h), (s)) + +/* + * Access methods for bus resources and address space. + */ +#define _BUS_ACCESS_METHODS_PROTO(TYPE,BWN) \ + static __inline TYPE bus_space_read_##BWN \ + (bus_space_tag_t, bus_space_handle_t, bus_size_t offset); \ + static __inline void bus_space_read_multi_##BWN \ + (bus_space_tag_t, bus_space_handle_t, \ + bus_size_t, TYPE *, size_t); \ + static __inline void bus_space_read_region_##BWN \ + (bus_space_tag_t, bus_space_handle_t, \ + bus_size_t, TYPE *, size_t); \ + static __inline void bus_space_write_##BWN \ + (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE); \ + static __inline void bus_space_write_multi_##BWN \ + (bus_space_tag_t, bus_space_handle_t, \ + bus_size_t, const TYPE *, size_t); \ + static __inline void bus_space_write_region_##BWN \ + (bus_space_tag_t, bus_space_handle_t, \ + bus_size_t, const TYPE *, size_t); \ + static __inline void bus_space_set_multi_##BWN \ + (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE, size_t);\ + static __inline void bus_space_set_region_##BWN \ + (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE, size_t);\ + static __inline void bus_space_copy_region_##BWN \ + (bus_space_tag_t, bus_space_handle_t, bus_size_t, \ + bus_space_handle_t, bus_size_t, size_t); + +_BUS_ACCESS_METHODS_PROTO(u_int8_t,1) +_BUS_ACCESS_METHODS_PROTO(u_int16_t,2) +_BUS_ACCESS_METHODS_PROTO(u_int32_t,4) + +/* + * read methods + */ +#define _BUS_SPACE_READ(TYPE,BWN) \ +static __inline TYPE \ +bus_space_read_##BWN (tag, bsh, offset) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ +{ \ + register TYPE result; \ + \ + __asm __volatile("call *%2" \ + :"=a" (result), \ + "=d" (offset) \ + :"o" (bsh->bsh_bam.bs_read_##BWN), \ + "b" (bsh), \ + "1" (offset) \ + ); \ + \ + return result; \ +} + +_BUS_SPACE_READ(u_int8_t,1) +_BUS_SPACE_READ(u_int16_t,2) +_BUS_SPACE_READ(u_int32_t,4) + +/* + * write methods + */ +#define _BUS_SPACE_WRITE(TYPE,BWN) \ +static __inline void \ +bus_space_write_##BWN (tag, bsh, offset, val) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ + TYPE val; \ +{ \ + \ + __asm __volatile("call *%1" \ + :"=d" (offset) \ + :"o" (bsh->bsh_bam.bs_write_##BWN), \ + "a" (val), \ + "b" (bsh), \ + "0" (offset) \ + ); \ +} + +_BUS_SPACE_WRITE(u_int8_t,1) +_BUS_SPACE_WRITE(u_int16_t,2) +_BUS_SPACE_WRITE(u_int32_t,4) + +/* + * multi read + */ +#define _BUS_SPACE_READ_MULTI(TYPE,BWN) \ +static __inline void \ +bus_space_read_multi_##BWN (tag, bsh, offset, buf, cnt) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ + TYPE *buf; \ + size_t cnt; \ +{ \ + \ + __asm __volatile("call *%3" \ + :"=c" (cnt), \ + "=d" (offset), \ + "=D" (buf) \ + :"o" (bsh->bsh_bam.bs_read_multi_##BWN), \ + "b" (bsh), \ + "0" (cnt), \ + "1" (offset), \ + "2" (buf) \ + :"memory"); \ +} + +_BUS_SPACE_READ_MULTI(u_int8_t,1) +_BUS_SPACE_READ_MULTI(u_int16_t,2) +_BUS_SPACE_READ_MULTI(u_int32_t,4) + +/* + * multi write + */ +#define _BUS_SPACE_WRITE_MULTI(TYPE,BWN) \ +static __inline void \ +bus_space_write_multi_##BWN (tag, bsh, offset, buf, cnt) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ + const TYPE *buf; \ + size_t cnt; \ +{ \ + \ + __asm __volatile("call *%3" \ + :"=c" (cnt), \ + "=d" (offset), \ + "=S" (buf) \ + :"o" (bsh->bsh_bam.bs_write_multi_##BWN), \ + "b" (bsh), \ + "0" (cnt), \ + "1" (offset), \ + "2" (buf) \ + ); \ +} + +_BUS_SPACE_WRITE_MULTI(u_int8_t,1) +_BUS_SPACE_WRITE_MULTI(u_int16_t,2) +_BUS_SPACE_WRITE_MULTI(u_int32_t,4) + +/* + * region read + */ +#define _BUS_SPACE_READ_REGION(TYPE,BWN) \ +static __inline void \ +bus_space_read_region_##BWN (tag, bsh, offset, buf, cnt) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ + TYPE *buf; \ + size_t cnt; \ +{ \ + \ + __asm __volatile("call *%3" \ + :"=c" (cnt), \ + "=d" (offset), \ + "=D" (buf) \ + :"o" (bsh->bsh_bam.bs_read_region_##BWN), \ + "b" (bsh), \ + "0" (cnt), \ + "1" (offset), \ + "2" (buf) \ + :"memory"); \ +} + +_BUS_SPACE_READ_REGION(u_int8_t,1) +_BUS_SPACE_READ_REGION(u_int16_t,2) +_BUS_SPACE_READ_REGION(u_int32_t,4) + +/* + * region write + */ +#define _BUS_SPACE_WRITE_REGION(TYPE,BWN) \ +static __inline void \ +bus_space_write_region_##BWN (tag, bsh, offset, buf, cnt) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ + const TYPE *buf; \ + size_t cnt; \ +{ \ + \ + __asm __volatile("call *%3" \ + :"=c" (cnt), \ + "=d" (offset), \ + "=S" (buf) \ + :"o" (bsh->bsh_bam.bs_write_region_##BWN), \ + "b" (bsh), \ + "0" (cnt), \ + "1" (offset), \ + "2" (buf) \ + ); \ +} + +_BUS_SPACE_WRITE_REGION(u_int8_t,1) +_BUS_SPACE_WRITE_REGION(u_int16_t,2) +_BUS_SPACE_WRITE_REGION(u_int32_t,4) + +/* + * multi set + */ +#define _BUS_SPACE_SET_MULTI(TYPE,BWN) \ +static __inline void \ +bus_space_set_multi_##BWN (tag, bsh, offset, val, cnt) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ + TYPE val; \ + size_t cnt; \ +{ \ + \ + __asm __volatile("call *%2" \ + :"=c" (cnt), \ + "=d" (offset) \ + :"o" (bsh->bsh_bam.bs_set_multi_##BWN), \ + "a" (val), \ + "b" (bsh), \ + "0" (cnt), \ + "1" (offset) \ + ); \ +} + +_BUS_SPACE_SET_MULTI(u_int8_t,1) +_BUS_SPACE_SET_MULTI(u_int16_t,2) +_BUS_SPACE_SET_MULTI(u_int32_t,4) + +/* + * region set + */ +#define _BUS_SPACE_SET_REGION(TYPE,BWN) \ +static __inline void \ +bus_space_set_region_##BWN (tag, bsh, offset, val, cnt) \ + bus_space_tag_t tag; \ + bus_space_handle_t bsh; \ + bus_size_t offset; \ + TYPE val; \ + size_t cnt; \ +{ \ + \ + __asm __volatile("call *%2" \ + :"=c" (cnt), \ + "=d" (offset) \ + :"o" (bsh->bsh_bam.bs_set_region_##BWN), \ + "a" (val), \ + "b" (bsh), \ + "0" (cnt), \ + "1" (offset) \ + ); \ +} + +_BUS_SPACE_SET_REGION(u_int8_t,1) +_BUS_SPACE_SET_REGION(u_int16_t,2) +_BUS_SPACE_SET_REGION(u_int32_t,4) + +/* + * copy + */ +#define _BUS_SPACE_COPY_REGION(BWN) \ +static __inline void \ +bus_space_copy_region_##BWN (tag, sbsh, src, dbsh, dst, cnt) \ + bus_space_tag_t tag; \ + bus_space_handle_t sbsh; \ + bus_size_t src; \ + bus_space_handle_t dbsh; \ + bus_size_t dst; \ + size_t cnt; \ +{ \ + \ + if (dbsh->bsh_bam.bs_copy_region_1 != sbsh->bsh_bam.bs_copy_region_1) \ + panic("bus_space_copy_region: funcs mismatch (ENOSUPPORT)");\ + \ + __asm __volatile("call *%3" \ + :"=c" (cnt), \ + "=S" (src), \ + "=D" (dst) \ + :"o" (dbsh->bsh_bam.bs_copy_region_##BWN), \ + "a" (sbsh), \ + "b" (dbsh), \ + "0" (cnt), \ + "1" (src), \ + "2" (dst) \ + ); \ +} + +_BUS_SPACE_COPY_REGION(1) +_BUS_SPACE_COPY_REGION(2) +_BUS_SPACE_COPY_REGION(4) + +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh, + * bus_size_t offset, bus_size_t len, int flags); + * + * + * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than + * prevent reordering by the compiler; all Intel x86 processors currently + * retire operations outside the CPU in program order. + */ +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +static __inline void +bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t len, int flags) +{ + if (flags & BUS_SPACE_BARRIER_READ) + __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); + else + __asm __volatile("" : : : "memory"); +} + +#endif /* _I386_BUS_PC98_H_ */ diff --git a/src/include/machine/bus_pio.h b/src/include/machine/bus_pio.h new file mode 100644 index 0000000..a3c8775 --- /dev/null +++ b/src/include/machine/bus_pio.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 1997 Justin Gibbs. + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/bus_pio.h,v 1.2 1999/08/28 00:44:08 peter Exp $ + */ + +#ifndef _I386_BUS_PIO_H_ +#define _I386_BUS_PIO_H_ +#endif /* _I386_BUS_PIO_H_ */ diff --git a/src/include/machine/cdk.h b/src/include/machine/cdk.h new file mode 100644 index 0000000..6893b37 --- /dev/null +++ b/src/include/machine/cdk.h @@ -0,0 +1,495 @@ +/*****************************************************************************/ + +/* + * cdk.h -- CDK interface definitions. + * + * Copyright (c) 1994-1996 Greg Ungerer (gerg@stallion.oz.au). + * 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 Greg Ungerer. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/cdk.h,v 1.5 1999/08/28 00:44:08 peter Exp $ + */ + +/*****************************************************************************/ +#ifndef _CDK_H +#define _CDK_H +/*****************************************************************************/ + +#pragma pack(2) + +/* + * The following set of definitions is used to communicate with the + * shared memory interface of the Stallion intelligent multiport serial + * boards. The definitions in this file are taken directly from the + * document titled "Generic Stackable Interface, Downloader and + * Communications Development Kit". + */ + +/* + * Define the set of importrant shared memory addresses. These are + * required to intialize the board and get things started. All of these + * addresses are relative to the start of the shared memory. + */ +#define CDK_SIGADDR 0x200 +#define CDK_FEATADDR 0x280 +#define CDK_CDKADDR 0x300 +#define CDK_RDYADDR 0x262 + +#define CDK_ALIVEMARKER 13 + +/* + * On hardware power up the ROMs located on the EasyConnection 8/64 will + * fill out the following signature information into shared memory. This + * way the host system can quickly determine that the board is present + * and is operational. + */ +typedef struct cdkecpsig { + unsigned long magic; + unsigned short romver; + unsigned short cputype; + unsigned char panelid[8]; +} cdkecpsig_t; + +#define ECP_MAGIC 0x21504345 + +/* + * On hardware power up the ROMs located on the ONboard, Stallion and + * Brumbys will fill out the following signature information into shared + * memory. This way the host system can quickly determine that the board + * is present and is operational. + */ +typedef struct cdkonbsig { + unsigned short magic0; + unsigned short magic1; + unsigned short magic2; + unsigned short magic3; + unsigned short romver; + unsigned short memoff; + unsigned short memseg; + unsigned short amask0; + unsigned short pic; + unsigned short status; + unsigned short btype; + unsigned short clkticks; + unsigned short clkspeed; + unsigned short amask1; + unsigned short amask2; +} cdkonbsig_t; + +#define ONB_MAGIC0 0xf2a7 +#define ONB_MAGIC1 0xa149 +#define ONB_MAGIC2 0x6352 +#define ONB_MAGIC3 0xf121 + +/* + * Define the feature area structure. The feature area is the set of + * startup parameters used by the slave image when it starts executing. + * They allow for the specification of buffer sizes, debug trace, etc. + */ +typedef struct cdkfeature { + unsigned long debug; + unsigned long banner; + unsigned long etype; + unsigned long nrdevs; + unsigned long brdspec; + unsigned long txrqsize; + unsigned long rxrqsize; + unsigned long flags; +} cdkfeature_t; + +#define ETYP_DDK 0 +#define ETYP_CDK 1 + +/* + * Define the CDK header structure. This is the info that the slave + * environment sets up after it has been downloaded and started. It + * essentially provides a memory map for the shared memory interface. + */ +typedef struct cdkhdr { + unsigned short command; + unsigned short status; + unsigned short port; + unsigned short mode; + unsigned long cmd_buf[14]; + unsigned short alive_cnt; + unsigned short intrpt_mode; + unsigned char intrpt_id[8]; + unsigned char ver_release; + unsigned char ver_modification; + unsigned char ver_fix; + unsigned char deadman_restart; + unsigned short deadman; + unsigned short nrdevs; + unsigned long memp; + unsigned long hostp; + unsigned long slavep; + unsigned char hostreq; + unsigned char slavereq; + unsigned char cmd_reserved[30]; +} cdkhdr_t; + +#define MODE_DDK 0 +#define MODE_CDK 1 + +#define IMD_INTR 0x0 +#define IMD_PPINTR 0x1 +#define IMD_POLL 0xff + +/* + * Define the memory mapping structure. This structure is pointed to by + * the memp field in the stlcdkhdr struct. As many as these structures + * as required are layed out in shared memory to define how the rest of + * shared memory is divided up. There will be one for each port. + */ +typedef struct cdkmem { + unsigned short dtype; + unsigned long offset; +} cdkmem_t; + +#define TYP_UNDEFINED 0x0 +#define TYP_ASYNCTRL 0x1 +#define TYP_ASYNC 0x20 +#define TYP_PARALLEL 0x40 +#define TYP_SYNCX21 0x60 + +/*****************************************************************************/ + +/* + * Following is a set of defines and structures used to actually deal + * with the serial ports on the board. Firstly is the set of commands + * that can be applied to ports. + */ +#define ASYCMD (((unsigned long) 'a') << 8) + +#define A_NULL (ASYCMD | 0) +#define A_FLUSH (ASYCMD | 1) +#define A_BREAK (ASYCMD | 2) +#define A_GETPORT (ASYCMD | 3) +#define A_SETPORT (ASYCMD | 4) +#define A_SETPORTF (ASYCMD | 5) +#define A_SETPORTFTX (ASYCMD | 6) +#define A_SETPORTFRX (ASYCMD | 7) +#define A_GETSIGNALS (ASYCMD | 8) +#define A_SETSIGNALS (ASYCMD | 9) +#define A_SETSIGNALSF (ASYCMD | 10) +#define A_SETSIGNALSFTX (ASYCMD | 11) +#define A_SETSIGNALSFRX (ASYCMD | 12) +#define A_GETNOTIFY (ASYCMD | 13) +#define A_SETNOTIFY (ASYCMD | 14) +#define A_NOTIFY (ASYCMD | 15) +#define A_PORTCTRL (ASYCMD | 16) +#define A_GETSTATS (ASYCMD | 17) +#define A_RQSTATE (ASYCMD | 18) +#define A_FLOWSTATE (ASYCMD | 19) +#define A_CLEARSTATS (ASYCMD | 20) + +/* + * Define those arguments used for simple commands. + */ +#define FLUSHRX 0x1 +#define FLUSHTX 0x2 + +#define BREAKON -1 +#define BREAKOFF -2 + +/* + * Define the port setting structure, and all those defines that go along + * with it. Basically this structure defines the charcateristics of this + * port: baud rate, chars, parity, input/output char cooking etc. + */ +typedef struct asyport { + unsigned long baudout; + unsigned long baudin; + unsigned long iflag; + unsigned long oflag; + unsigned long lflag; + unsigned long pflag; + unsigned long flow; + unsigned long spare1; + unsigned short vtime; + unsigned short vmin; + unsigned short txlo; + unsigned short txhi; + unsigned short rxlo; + unsigned short rxhi; + unsigned short rxhog; + unsigned short spare2; + unsigned char csize; + unsigned char stopbs; + unsigned char parity; + unsigned char stopin; + unsigned char startin; + unsigned char stopout; + unsigned char startout; + unsigned char parmark; + unsigned char brkmark; + unsigned char cc[11]; +} asyport_t; + +#define PT_STOP1 0x0 +#define PT_STOP15 0x1 +#define PT_STOP2 0x2 + +#define PT_NOPARITY 0x0 +#define PT_ODDPARITY 0x1 +#define PT_EVENPARITY 0x2 +#define PT_MARKPARITY 0x3 +#define PT_SPACEPARITY 0x4 + +#define F_NONE 0x0 +#define F_IXON 0x1 +#define F_IXOFF 0x2 +#define F_IXANY 0x4 +#define F_IOXANY 0x8 +#define F_RTSFLOW 0x10 +#define F_CTSFLOW 0x20 +#define F_DTRFLOW 0x40 +#define F_DCDFLOW 0x80 +#define F_DSROFLOW 0x100 +#define F_DSRIFLOW 0x200 + +#define FI_NORX 0x1 +#define FI_RAW 0x2 +#define FI_ISTRIP 0x4 +#define FI_UCLC 0x8 +#define FI_INLCR 0x10 +#define FI_ICRNL 0x20 +#define FI_IGNCR 0x40 +#define FI_IGNBREAK 0x80 +#define FI_DSCRDBREAK 0x100 +#define FI_1MARKBREAK 0x200 +#define FI_2MARKBREAK 0x400 +#define FI_XCHNGBREAK 0x800 +#define FI_IGNRXERRS 0x1000 +#define FI_DSCDRXERRS 0x2000 +#define FI_1MARKRXERRS 0x4000 +#define FI_2MARKRXERRS 0x8000 +#define FI_XCHNGRXERRS 0x10000 +#define FI_DSCRDNULL 0x20000 + +#define FO_OLCUC 0x1 +#define FO_ONLCR 0x2 +#define FO_OOCRNL 0x4 +#define FO_ONOCR 0x8 +#define FO_ONLRET 0x10 +#define FO_ONL 0x20 +#define FO_OBS 0x40 +#define FO_OVT 0x80 +#define FO_OFF 0x100 +#define FO_OTAB1 0x200 +#define FO_OTAB2 0x400 +#define FO_OTAB3 0x800 +#define FO_OCR1 0x1000 +#define FO_OCR2 0x2000 +#define FO_OCR3 0x4000 +#define FO_OFILL 0x8000 +#define FO_ODELL 0x10000 + +#define P_RTSLOCK 0x1 +#define P_CTSLOCK 0x2 +#define P_MAPRTS 0x4 +#define P_MAPCTS 0x8 +#define P_LOOPBACK 0x10 +#define P_DTRFOLLOW 0x20 +#define P_FAKEDCD 0x40 + +/* + * Define a structure to communicate serial port signal and data state + * information. + */ +typedef struct asysigs { + unsigned long data; + unsigned long signal; + unsigned long sigvalue; +} asysigs_t; + +#define DT_TXBUSY 0x1 +#define DT_TXEMPTY 0x2 +#define DT_TXLOW 0x4 +#define DT_TXHIGH 0x8 +#define DT_TXFULL 0x10 +#define DT_TXHOG 0x20 +#define DT_TXFLOWED 0x40 +#define DT_TXBREAK 0x80 + +#define DT_RXBUSY 0x100 +#define DT_RXEMPTY 0x200 +#define DT_RXLOW 0x400 +#define DT_RXHIGH 0x800 +#define DT_RXFULL 0x1000 +#define DT_RXHOG 0x2000 +#define DT_RXFLOWED 0x4000 +#define DT_RXBREAK 0x8000 + +#define SG_DTR 0x1 +#define SG_DCD 0x2 +#define SG_RTS 0x4 +#define SG_CTS 0x8 +#define SG_DSR 0x10 +#define SG_RI 0x20 + +/* + * Define the notification setting structure. This is used to tell the + * port what events we want to be informed about. Fields here use the + * same defines as for the asysigs structure above. + */ +typedef struct asynotify { + unsigned long ctrl; + unsigned long data; + unsigned long signal; + unsigned long sigvalue; +} asynotify_t; + +/* + * Define the port control structure. It is used to do fine grain + * control operations on the port. + */ +typedef struct { + unsigned long rxctrl; + unsigned long txctrl; + char rximdch; + char tximdch; + char spare1; + char spare2; +} asyctrl_t; + +#define CT_ENABLE 0x1 +#define CT_DISABLE 0x2 +#define CT_STOP 0x4 +#define CT_START 0x8 +#define CT_STARTFLOW 0x10 +#define CT_STOPFLOW 0x20 +#define CT_SENDCHR 0x40 + +/* + * Define the stats structure kept for each port. This is a useful set + * of data collected for each port on the slave. The A_GETSTATS command + * is used to retrive this data from the slave. + */ +typedef struct asystats { + unsigned long opens; + unsigned long txchars; + unsigned long rxchars; + unsigned long txringq; + unsigned long rxringq; + unsigned long txmsgs; + unsigned long rxmsgs; + unsigned long txflushes; + unsigned long rxflushes; + unsigned long overruns; + unsigned long framing; + unsigned long parity; + unsigned long ringover; + unsigned long lost; + unsigned long rxstart; + unsigned long rxstop; + unsigned long txstart; + unsigned long txstop; + unsigned long dcdcnt; + unsigned long dtrcnt; + unsigned long ctscnt; + unsigned long rtscnt; + unsigned long dsrcnt; + unsigned long ricnt; + unsigned long txbreaks; + unsigned long rxbreaks; + unsigned long signals; + unsigned long state; + unsigned long hwid; +} asystats_t; + +/*****************************************************************************/ + +/* + * All command and control communication with a device on the slave is + * via a control block in shared memory. Each device has its own control + * block, defined by the following structure. The control block allows + * the host to open, close and control the device on the slave. + */ +typedef struct cdkctrl { + unsigned char open; + unsigned char close; + unsigned long openarg; + unsigned long closearg; + unsigned long cmd; + unsigned long status; + unsigned long args[32]; +} cdkctrl_t; + +/* + * Each device on the slave passes data to and from the host via a ring + * queue in shared memory. Define a ring queue structure to hold the + * vital information about each ring queue. Two ring queues will be + * allocated for each port, one for reveice data and one for transmit + * data. + */ +typedef struct cdkasyrq { + unsigned long offset; + unsigned short size; + unsigned short head; + unsigned short tail; +} cdkasyrq_t; + +/* + * Each asynchronous port is defined in shared memory by the following + * structure. It contains a control block to command a device, and also + * the neccessary data channel information as well. + */ +typedef struct cdkasy { + cdkctrl_t ctrl; + unsigned short notify; + asynotify_t changed; + unsigned short receive; + cdkasyrq_t rxq; + unsigned short transmit; + cdkasyrq_t txq; +} cdkasy_t; + +#pragma pack() + +/*****************************************************************************/ + +/* + * Define the set of ioctls used by the driver to do special things + * to the board. These include interrupting it, and initializeing + * the driver after board startup and shutdown. + */ +#define STL_BINTR _IO('s', 20) +#define STL_BSTART _IO('s', 21) +#define STL_BSTOP _IO('s', 22) +#define STL_BRESET _IO('s', 23) + +/* + * Define a set of ioctl extensions, used to get at special stuff. + */ +#define STL_GETPFLAG _IOR('s', 80, unsigned long) +#define STL_SETPFLAG _IOW('s', 81, unsigned long) + +/*****************************************************************************/ +#endif diff --git a/src/include/machine/clock.h b/src/include/machine/clock.h new file mode 100644 index 0000000..a60681c --- /dev/null +++ b/src/include/machine/clock.h @@ -0,0 +1,53 @@ +/* + * Kernel interface to machine-dependent clock driver. + * Garrett Wollman, September 1994. + * This file is in the public domain. + * + * $FreeBSD: src/sys/i386/include/clock.h,v 1.49 2003/11/12 18:13:57 jhb Exp $ + */ + +#ifndef _MACHINE_CLOCK_H_ +#define _MACHINE_CLOCK_H_ + +#ifdef _KERNEL +/* + * i386 to clock driver interface. + * XXX large parts of the driver and its interface are misplaced. + */ +extern int adjkerntz; +extern int clkintr_pending; +extern int disable_rtc_set; +extern int pscnt; +extern int psdiv; +extern int statclock_disable; +extern u_int timer_freq; +extern int timer0_max_count; +extern uint64_t tsc_freq; +extern int tsc_is_broken; +extern int wall_cmos_clock; + +/* + * Driver to clock driver interface. + */ +struct clockframe; + +int acquire_timer2(int mode); +int release_timer2(void); +#ifndef PC98 +int rtcin(int val); +#else +int acquire_timer1(int mode); +int release_timer1(void); +#endif +#ifndef BURN_BRIDGES +int acquire_timer0(int rate, void (*function)(struct clockframe *frame)); +int release_timer0(void); +#endif +int sysbeep(int pitch, int period); +void timer_restore(void); +void init_TSC(void); +void init_TSC_tc(void); + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_CLOCK_H_ */ diff --git a/src/include/machine/comstats.h b/src/include/machine/comstats.h new file mode 100644 index 0000000..95b06df --- /dev/null +++ b/src/include/machine/comstats.h @@ -0,0 +1,122 @@ +/*****************************************************************************/ + +/* + * comstats.h -- Serial Port Stats. + * + * Copyright (c) 1994-1996 Greg Ungerer (gerg@stallion.oz.au). + * 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 Greg Ungerer. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/comstats.h,v 1.5 1999/08/28 00:44:09 peter Exp $ + */ + +/*****************************************************************************/ +#ifndef _COMSTATS_H +#define _COMSTATS_H +/*****************************************************************************/ + +/* + * Serial port stats structure. The structure itself is UART + * independent, but some fields may be UART/driver specific (for + * example state). + */ + +typedef struct { + unsigned long brd; + unsigned long panel; + unsigned long port; + unsigned long hwid; + unsigned long type; + unsigned long txtotal; + unsigned long rxtotal; + unsigned long txbuffered; + unsigned long rxbuffered; + unsigned long rxoverrun; + unsigned long rxparity; + unsigned long rxframing; + unsigned long rxlost; + unsigned long txbreaks; + unsigned long rxbreaks; + unsigned long txxon; + unsigned long txxoff; + unsigned long rxxon; + unsigned long rxxoff; + unsigned long txctson; + unsigned long txctsoff; + unsigned long rxrtson; + unsigned long rxrtsoff; + unsigned long modem; + unsigned long state; + unsigned long flags; + unsigned long ttystate; + unsigned long cflags; + unsigned long iflags; + unsigned long oflags; + unsigned long lflags; + unsigned long signals; +} comstats_t; + + +/* + * Board stats structure. Returns usefull info about the board. + */ + +#define COM_MAXPANELS 8 + +typedef struct { + unsigned long panel; + unsigned long type; + unsigned long hwid; + unsigned long nrports; +} companel_t; + +typedef struct { + unsigned long brd; + unsigned long type; + unsigned long hwid; + unsigned long state; + unsigned long ioaddr; + unsigned long ioaddr2; + unsigned long memaddr; + unsigned long irq; + unsigned long nrpanels; + unsigned long nrports; + companel_t panels[COM_MAXPANELS]; +} combrd_t; + + +/* + * Define the ioctl operations for stats stuff. + */ +#define COM_GETPORTSTATS _IOWR('c', 30, comstats_t) +#define COM_CLRPORTSTATS _IOWR('c', 31, comstats_t) +#define COM_GETBRDSTATS _IOWR('c', 32, combrd_t) + +/*****************************************************************************/ +#endif diff --git a/src/include/machine/cpu.h b/src/include/machine/cpu.h new file mode 100644 index 0000000..3825822 --- /dev/null +++ b/src/include/machine/cpu.h @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)cpu.h 5.4 (Berkeley) 5/9/91 + * $FreeBSD: src/sys/i386/include/cpu.h,v 1.70 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * Definitions unique to i386 cpu support. + */ +#include +#include +#include + +/* + * definitions of cpu-dependent requirements + * referenced in generic code + */ +#undef COPY_SIGCODE /* don't copy sigcode above user stack in exec */ + +#define cpu_exec(p) /* nothing */ +#define cpu_swapin(p) /* nothing */ +#define cpu_getstack(td) ((td)->td_frame->tf_esp) +#define cpu_setstack(td, ap) ((td)->td_frame->tf_esp = (ap)) + +#define TRAPF_USERMODE(framep) \ + ((ISPL((framep)->tf_cs) == SEL_UPL) || ((framep)->tf_eflags & PSL_VM)) +#define TRAPF_PC(framep) ((framep)->tf_eip) + +#define CLKF_USERMODE(framep) \ + ((ISPL((framep)->cf_cs) == SEL_UPL) || ((framep)->cf_eflags & PSL_VM)) +#define CLKF_PC(framep) ((framep)->cf_eip) + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_CONSDEV 1 /* dev_t: console terminal device */ +#define CPU_ADJKERNTZ 2 /* int: timezone offset (seconds) */ +#define CPU_DISRTCSET 3 /* int: disable resettodr() call */ +#define CPU_BOOTINFO 4 /* struct: bootinfo */ +#define CPU_WALLCLOCK 5 /* int: indicates wall CMOS clock */ +#define CPU_MAXID 6 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "console_device", CTLTYPE_STRUCT }, \ + { "adjkerntz", CTLTYPE_INT }, \ + { "disable_rtc_set", CTLTYPE_INT }, \ + { "bootinfo", CTLTYPE_STRUCT }, \ + { "wall_cmos_clock", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL +extern char btext[]; +extern char etext[]; +extern u_int tsc_present; + +void cpu_halt(void); +void cpu_reset(void); +void fork_trampoline(void); +void swi_vm(void *); + +/* + * Return contents of in-cpu fast counter as a sort of "bogo-time" + * for random-harvesting purposes. + */ +static __inline u_int64_t +get_cyclecount(void) +{ +#if defined(I386_CPU) || defined(I486_CPU) || defined(KLD_MODULE) + struct bintime bt; + + if (!tsc_present) { + binuptime(&bt); + return (bt.frac ^ bt.sec); + } +#endif + return (rdtsc()); +} + +#endif + +#endif /* !_MACHINE_CPU_H_ */ diff --git a/src/include/machine/cpufunc.h b/src/include/machine/cpufunc.h new file mode 100644 index 0000000..67e733d --- /dev/null +++ b/src/include/machine/cpufunc.h @@ -0,0 +1,690 @@ +/*- + * Copyright (c) 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. + * 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. + * + * $FreeBSD: src/sys/i386/include/cpufunc.h,v 1.142 2004/04/07 20:46:05 imp Exp $ + */ + +/* + * Functions to provide access to special i386 instructions. + * This in included in sys/systm.h, and that file should be + * used in preference to this. + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +struct region_descriptor; + +#define readb(va) (*(volatile u_int8_t *) (va)) +#define readw(va) (*(volatile u_int16_t *) (va)) +#define readl(va) (*(volatile u_int32_t *) (va)) + +#define writeb(va, d) (*(volatile u_int8_t *) (va) = (d)) +#define writew(va, d) (*(volatile u_int16_t *) (va) = (d)) +#define writel(va, d) (*(volatile u_int32_t *) (va) = (d)) + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +static __inline void +breakpoint(void) +{ + __asm __volatile("int $3"); +} + +static __inline u_int +bsfl(u_int mask) +{ + u_int result; + + __asm __volatile("bsfl %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + +static __inline u_int +bsrl(u_int mask) +{ + u_int result; + + __asm __volatile("bsrl %1,%0" : "=r" (result) : "rm" (mask)); + return (result); +} + +static __inline void +disable_intr(void) +{ + __asm __volatile("cli" : : : "memory"); +} + +static __inline void +do_cpuid(u_int ax, u_int *p) +{ + __asm __volatile("cpuid" + : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) + : "0" (ax)); +} + +static __inline void +enable_intr(void) +{ + __asm __volatile("sti"); +} + +#ifdef _KERNEL + +#define HAVE_INLINE_FFS + +static __inline int +ffs(int mask) +{ + /* + * Note that gcc-2's builtin ffs would be used if we didn't declare + * this inline or turn off the builtin. The builtin is faster but + * broken in gcc-2.4.5 and slower but working in gcc-2.5 and later + * versions. + */ + return (mask == 0 ? mask : (int)bsfl((u_int)mask) + 1); +} + +#define HAVE_INLINE_FLS + +static __inline int +fls(int mask) +{ + return (mask == 0 ? mask : (int)bsrl((u_int)mask) + 1); +} + +#endif /* _KERNEL */ + +static __inline void +halt(void) +{ + __asm __volatile("hlt"); +} + +#if __GNUC__ < 2 + +#define inb(port) inbv(port) +#define outb(port, data) outbv(port, data) + +#else /* __GNUC >= 2 */ + +/* + * The following complications are to get around gcc not having a + * constraint letter for the range 0..255. We still put "d" in the + * constraint because "i" isn't a valid constraint when the port + * isn't constant. This only matters for -O0 because otherwise + * the non-working version gets optimized away. + * + * Use an expression-statement instead of a conditional expression + * because gcc-2.6.0 would promote the operands of the conditional + * and produce poor code for "if ((inb(var) & const1) == const2)". + * + * The unnecessary test `(port) < 0x10000' is to generate a warning if + * the `port' has type u_short or smaller. Such types are pessimal. + * This actually only works for signed types. The range check is + * careful to avoid generating warnings. + */ +#define inb(port) __extension__ ({ \ + u_char _data; \ + if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000) \ + _data = inbc(port); \ + else \ + _data = inbv(port); \ + _data; }) + +#define outb(port, data) ( \ + __builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000 \ + ? outbc(port, data) : outbv(port, data)) + +static __inline u_char +inbc(u_int port) +{ + u_char data; + + __asm __volatile("inb %1,%0" : "=a" (data) : "id" ((u_short)(port))); + return (data); +} + +static __inline void +outbc(u_int port, u_char data) +{ + __asm __volatile("outb %0,%1" : : "a" (data), "id" ((u_short)(port))); +} + +#endif /* __GNUC <= 2 */ + +static __inline u_char +inbv(u_int port) +{ + u_char data; + /* + * We use %%dx and not %1 here because i/o is done at %dx and not at + * %edx, while gcc generates inferior code (movw instead of movl) + * if we tell it to load (u_short) port. + */ + __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port)); + return (data); +} + +static __inline u_int +inl(u_int port) +{ + u_int data; + + __asm __volatile("inl %%dx,%0" : "=a" (data) : "d" (port)); + return (data); +} + +static __inline void +insb(u_int port, void *addr, size_t cnt) +{ + __asm __volatile("cld; rep; insb" + : "+D" (addr), "+c" (cnt) + : "d" (port) + : "memory"); +} + +static __inline void +insw(u_int port, void *addr, size_t cnt) +{ + __asm __volatile("cld; rep; insw" + : "+D" (addr), "+c" (cnt) + : "d" (port) + : "memory"); +} + +static __inline void +insl(u_int port, void *addr, size_t cnt) +{ + __asm __volatile("cld; rep; insl" + : "+D" (addr), "+c" (cnt) + : "d" (port) + : "memory"); +} + +static __inline void +invd(void) +{ + __asm __volatile("invd"); +} + +static __inline u_short +inw(u_int port) +{ + u_short data; + + __asm __volatile("inw %%dx,%0" : "=a" (data) : "d" (port)); + return (data); +} + +static __inline void +outbv(u_int port, u_char data) +{ + u_char al; + /* + * Use an unnecessary assignment to help gcc's register allocator. + * This make a large difference for gcc-1.40 and a tiny difference + * for gcc-2.6.0. For gcc-1.40, al had to be ``asm("ax")'' for + * best results. gcc-2.6.0 can't handle this. + */ + al = data; + __asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port)); +} + +static __inline void +outl(u_int port, u_int data) +{ + /* + * outl() and outw() aren't used much so we haven't looked at + * possible micro-optimizations such as the unnecessary + * assignment for them. + */ + __asm __volatile("outl %0,%%dx" : : "a" (data), "d" (port)); +} + +static __inline void +outsb(u_int port, const void *addr, size_t cnt) +{ + __asm __volatile("cld; rep; outsb" + : "+S" (addr), "+c" (cnt) + : "d" (port)); +} + +static __inline void +outsw(u_int port, const void *addr, size_t cnt) +{ + __asm __volatile("cld; rep; outsw" + : "+S" (addr), "+c" (cnt) + : "d" (port)); +} + +static __inline void +outsl(u_int port, const void *addr, size_t cnt) +{ + __asm __volatile("cld; rep; outsl" + : "+S" (addr), "+c" (cnt) + : "d" (port)); +} + +static __inline void +outw(u_int port, u_short data) +{ + __asm __volatile("outw %0,%%dx" : : "a" (data), "d" (port)); +} + +static __inline void +ia32_pause(void) +{ + __asm __volatile("pause"); +} + +static __inline u_int +read_eflags(void) +{ + u_int ef; + + __asm __volatile("pushfl; popl %0" : "=r" (ef)); + return (ef); +} + +static __inline u_int64_t +rdmsr(u_int msr) +{ + u_int64_t rv; + + __asm __volatile("rdmsr" : "=A" (rv) : "c" (msr)); + return (rv); +} + +static __inline u_int64_t +rdpmc(u_int pmc) +{ + u_int64_t rv; + + __asm __volatile("rdpmc" : "=A" (rv) : "c" (pmc)); + return (rv); +} + +static __inline u_int64_t +rdtsc(void) +{ + u_int64_t rv; + + __asm __volatile("rdtsc" : "=A" (rv)); + return (rv); +} + +static __inline void +wbinvd(void) +{ + __asm __volatile("wbinvd"); +} + +static __inline void +write_eflags(u_int ef) +{ + __asm __volatile("pushl %0; popfl" : : "r" (ef)); +} + +static __inline void +wrmsr(u_int msr, u_int64_t newval) +{ + __asm __volatile("wrmsr" : : "A" (newval), "c" (msr)); +} + +static __inline void +load_cr0(u_int data) +{ + + __asm __volatile("movl %0,%%cr0" : : "r" (data)); +} + +static __inline u_int +rcr0(void) +{ + u_int data; + + __asm __volatile("movl %%cr0,%0" : "=r" (data)); + return (data); +} + +static __inline u_int +rcr2(void) +{ + u_int data; + + __asm __volatile("movl %%cr2,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_cr3(u_int data) +{ + + __asm __volatile("movl %0,%%cr3" : : "r" (data) : "memory"); +} + +static __inline u_int +rcr3(void) +{ + u_int data; + + __asm __volatile("movl %%cr3,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_cr4(u_int data) +{ + __asm __volatile("movl %0,%%cr4" : : "r" (data)); +} + +static __inline u_int +rcr4(void) +{ + u_int data; + + __asm __volatile("movl %%cr4,%0" : "=r" (data)); + return (data); +} + +/* + * Global TLB flush (except for thise for pages marked PG_G) + */ +static __inline void +invltlb(void) +{ + + load_cr3(rcr3()); +} + +/* + * TLB flush for an individual page (even if it has PG_G). + * Only works on 486+ CPUs (i386 does not have PG_G). + */ +static __inline void +invlpg(u_int addr) +{ + + __asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory"); +} + +static __inline u_int +rfs(void) +{ + u_int sel; + __asm __volatile("movl %%fs,%0" : "=rm" (sel)); + return (sel); +} + +static __inline u_int +rgs(void) +{ + u_int sel; + __asm __volatile("movl %%gs,%0" : "=rm" (sel)); + return (sel); +} + +static __inline u_int +rss(void) +{ + u_int sel; + __asm __volatile("movl %%ss,%0" : "=rm" (sel)); + return (sel); +} + +static __inline void +load_fs(u_int sel) +{ + __asm __volatile("movl %0,%%fs" : : "rm" (sel)); +} + +static __inline void +load_gs(u_int sel) +{ + __asm __volatile("movl %0,%%gs" : : "rm" (sel)); +} + +static __inline void +lidt(struct region_descriptor *addr) +{ + __asm __volatile("lidt (%0)" : : "r" (addr)); +} + +static __inline void +lldt(u_short sel) +{ + __asm __volatile("lldt %0" : : "r" (sel)); +} + +static __inline void +ltr(u_short sel) +{ + __asm __volatile("ltr %0" : : "r" (sel)); +} + +static __inline u_int +rdr0(void) +{ + u_int data; + __asm __volatile("movl %%dr0,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr0(u_int dr0) +{ + __asm __volatile("movl %0,%%dr0" : : "r" (dr0)); +} + +static __inline u_int +rdr1(void) +{ + u_int data; + __asm __volatile("movl %%dr1,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr1(u_int dr1) +{ + __asm __volatile("movl %0,%%dr1" : : "r" (dr1)); +} + +static __inline u_int +rdr2(void) +{ + u_int data; + __asm __volatile("movl %%dr2,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr2(u_int dr2) +{ + __asm __volatile("movl %0,%%dr2" : : "r" (dr2)); +} + +static __inline u_int +rdr3(void) +{ + u_int data; + __asm __volatile("movl %%dr3,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr3(u_int dr3) +{ + __asm __volatile("movl %0,%%dr3" : : "r" (dr3)); +} + +static __inline u_int +rdr4(void) +{ + u_int data; + __asm __volatile("movl %%dr4,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr4(u_int dr4) +{ + __asm __volatile("movl %0,%%dr4" : : "r" (dr4)); +} + +static __inline u_int +rdr5(void) +{ + u_int data; + __asm __volatile("movl %%dr5,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr5(u_int dr5) +{ + __asm __volatile("movl %0,%%dr5" : : "r" (dr5)); +} + +static __inline u_int +rdr6(void) +{ + u_int data; + __asm __volatile("movl %%dr6,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr6(u_int dr6) +{ + __asm __volatile("movl %0,%%dr6" : : "r" (dr6)); +} + +static __inline u_int +rdr7(void) +{ + u_int data; + __asm __volatile("movl %%dr7,%0" : "=r" (data)); + return (data); +} + +static __inline void +load_dr7(u_int dr7) +{ + __asm __volatile("movl %0,%%dr7" : : "r" (dr7)); +} + +static __inline register_t +intr_disable(void) +{ + register_t eflags; + + eflags = read_eflags(); + disable_intr(); + return (eflags); +} + +static __inline void +intr_restore(register_t eflags) +{ + write_eflags(eflags); +} + +#else /* !(__GNUC__ || __INTEL_COMPILER) */ + +int breakpoint(void); +u_int bsfl(u_int mask); +u_int bsrl(u_int mask); +void disable_intr(void); +void do_cpuid(u_int ax, u_int *p); +void enable_intr(void); +void halt(void); +void ia32_pause(void); +u_char inb(u_int port); +u_int inl(u_int port); +void insb(u_int port, void *addr, size_t cnt); +void insl(u_int port, void *addr, size_t cnt); +void insw(u_int port, void *addr, size_t cnt); +register_t intr_disable(void); +void intr_restore(register_t ef); +void invd(void); +void invlpg(u_int addr); +void invltlb(void); +u_short inw(u_int port); +void lidt(struct region_descriptor *addr); +void lldt(u_short sel); +void load_cr0(u_int cr0); +void load_cr3(u_int cr3); +void load_cr4(u_int cr4); +void load_dr0(u_int dr0); +void load_dr1(u_int dr1); +void load_dr2(u_int dr2); +void load_dr3(u_int dr3); +void load_dr4(u_int dr4); +void load_dr5(u_int dr5); +void load_dr6(u_int dr6); +void load_dr7(u_int dr7); +void load_fs(u_int sel); +void load_gs(u_int sel); +void ltr(u_short sel); +void outb(u_int port, u_char data); +void outl(u_int port, u_int data); +void outsb(u_int port, const void *addr, size_t cnt); +void outsl(u_int port, const void *addr, size_t cnt); +void outsw(u_int port, const void *addr, size_t cnt); +void outw(u_int port, u_short data); +u_int rcr0(void); +u_int rcr2(void); +u_int rcr3(void); +u_int rcr4(void); +u_int64_t rdmsr(u_int msr); +u_int64_t rdpmc(u_int pmc); +u_int rdr0(void); +u_int rdr1(void); +u_int rdr2(void); +u_int rdr3(void); +u_int rdr4(void); +u_int rdr5(void); +u_int rdr6(void); +u_int rdr7(void); +u_int64_t rdtsc(void); +u_int read_eflags(void); +u_int rfs(void); +u_int rgs(void); +void wbinvd(void); +void write_eflags(u_int ef); +void wrmsr(u_int msr, u_int64_t newval); + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +void reset_dbregs(void); + +#endif /* !_MACHINE_CPUFUNC_H_ */ diff --git a/src/include/machine/cputypes.h b/src/include/machine/cputypes.h new file mode 100644 index 0000000..f92e8c9 --- /dev/null +++ b/src/include/machine/cputypes.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 1993 Christopher G. Demetriou + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/cputypes.h,v 1.16 2002/08/02 18:45:39 phk Exp $ + */ + +#ifndef _MACHINE_CPUTYPES_H_ +#define _MACHINE_CPUTYPES_H_ + +/* + * Classes of processor. + */ +#define CPUCLASS_286 0 +#define CPUCLASS_386 1 +#define CPUCLASS_486 2 +#define CPUCLASS_586 3 +#define CPUCLASS_686 4 + +/* + * Kinds of processor. + */ +#define CPU_286 0 /* Intel 80286 */ +#define CPU_386SX 1 /* Intel 80386SX */ +#define CPU_386 2 /* Intel 80386DX */ +#define CPU_486SX 3 /* Intel 80486SX */ +#define CPU_486 4 /* Intel 80486DX */ +#define CPU_586 5 /* Intel P.....m (I hate lawyers; it's TM) */ +#define CPU_486DLC 6 /* Cyrix 486DLC */ +#define CPU_686 7 /* Pentium Pro */ +#define CPU_M1SC 8 /* Cyrix M1sc (aka 5x86) */ +#define CPU_M1 9 /* Cyrix M1 (aka 6x86) */ +#define CPU_BLUE 10 /* IBM BlueLighting CPU */ +#define CPU_M2 11 /* Cyrix M2 (aka enhanced 6x86 with MMX */ +#define CPU_NX586 12 /* NexGen (now AMD) 586 */ +#define CPU_CY486DX 13 /* Cyrix 486S/DX/DX2/DX4 */ +#define CPU_PII 14 /* Intel Pentium II */ +#define CPU_PIII 15 /* Intel Pentium III */ +#define CPU_P4 16 /* Intel Pentium 4 */ + +#ifndef LOCORE +struct cpu_nameclass { + char *cpu_name; + int cpu_class; +}; + +extern int cpu; +extern int cpu_class; +#endif + +#endif /* !_MACHINE_CPUTYPES_H_ */ diff --git a/src/include/machine/critical.h b/src/include/machine/critical.h new file mode 100644 index 0000000..48de7b3 --- /dev/null +++ b/src/include/machine/critical.h @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2002 Matthew Dillon. 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. + * 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 AUTHOR ``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 AUTHOR 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. + * + * This file contains prototypes and high-level inlines related to + * machine-level critical function support: + * + * cpu_critical_enter() - inlined + * cpu_critical_exit() - inlined + * cpu_critical_fork_exit() - prototyped + * related support functions residing + * in //critical.c - prototyped + * + * $FreeBSD: src/sys/i386/include/critical.h,v 1.7 2004/03/12 21:45:30 trhodes Exp $ + */ + +#ifndef _MACHINE_CRITICAL_H_ +#define _MACHINE_CRITICAL_H_ + +__BEGIN_DECLS + +/* + * Prototypes - see //critical.c + */ +void cpu_critical_fork_exit(void); + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +/* + * cpu_critical_enter: + * + * This routine is called from critical_enter() on the 0->1 transition + * of td_critnest, prior to it being incremented to 1. + * + * If new-style critical section handling we do not have to do anything. + * However, as a side effect any interrupts occuring while td_critnest + * is non-zero will be deferred. + */ +static __inline void +cpu_critical_enter(void) +{ + curthread->td_md.md_savecrit = intr_disable(); +} + +/* + * cpu_critical_exit: + * + * This routine is called from critical_exit() on a 1->0 transition + * of td_critnest, after it has been decremented to 0. We are + * exiting the last critical section. + * + * Note that the td->critnest (1->0) transition interrupt race against + * our int_pending/unpend() check below is handled by the interrupt + * code for us, so we do not have to do anything fancy. + */ +static __inline void +cpu_critical_exit(void) +{ + intr_restore(curthread->td_md.md_savecrit); +} + +#else /* !(__GNUC__ || __INTEL_COMPILER) */ + +void cpu_critical_enter(void); +void cpu_critical_exit(void); + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +__END_DECLS + +#endif /* !_MACHINE_CRITICAL_H_ */ + diff --git a/src/include/machine/cserial.h b/src/include/machine/cserial.h new file mode 100644 index 0000000..f72ae98 --- /dev/null +++ b/src/include/machine/cserial.h @@ -0,0 +1,449 @@ +/* + * Ioctl interface to Cronyx serial drivers. + * + * Copyright (C) 1997-2002 Cronyx Engineering. + * Author: Serge Vakulenko, + * + * Copyright (C) 2001-2003 Cronyx Engineering. + * Author: Roman Kurakin, + * + * This software is distributed with NO WARRANTIES, not even the implied + * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Authors grant any other persons or organisations permission to use + * or modify this software as long as this message is kept with the software, + * all derivative works or modified versions. + * + * Cronyx Id: cserial.h,v 1.1.2.4 2003/11/12 17:11:08 rik Exp $ + * $FreeBSD: src/sys/i386/include/cserial.h,v 1.1 2003/12/03 07:29:38 imp Exp $ + */ + +/* + * General channel statistics. + */ +struct serial_statistics { + unsigned long rintr; /* receive interrupts */ + unsigned long tintr; /* transmit interrupts */ + unsigned long mintr; /* modem interrupts */ + unsigned long ibytes; /* input bytes */ + unsigned long ipkts; /* input packets */ + unsigned long ierrs; /* input errors */ + unsigned long obytes; /* output bytes */ + unsigned long opkts; /* output packets */ + unsigned long oerrs; /* output errors */ +}; + +/* + * Statistics for E1/G703 channels. + */ +struct e1_counters { + unsigned long bpv; /* bipolar violations */ + unsigned long fse; /* frame sync errors */ + unsigned long crce; /* CRC errors */ + unsigned long rcrce; /* remote CRC errors (E-bit) */ + unsigned long uas; /* unavailable seconds */ + unsigned long les; /* line errored seconds */ + unsigned long es; /* errored seconds */ + unsigned long bes; /* bursty errored seconds */ + unsigned long ses; /* severely errored seconds */ + unsigned long oofs; /* out of frame seconds */ + unsigned long css; /* controlled slip seconds */ + unsigned long dm; /* degraded minutes */ +}; + +struct e1_statistics { + unsigned long status; /* line status bit mask */ + unsigned long cursec; /* seconds in current interval */ + unsigned long totsec; /* total seconds elapsed */ + struct e1_counters currnt; /* current 15-min interval data */ + struct e1_counters total; /* total statistics data */ + struct e1_counters interval [48]; /* 12 hour period data */ +}; + +struct e3_statistics { + unsigned long status; + unsigned long cursec; + unsigned long totsec; + unsigned long ccv; + unsigned long tcv; + unsigned long icv[48]; +}; + +#define M_ASYNC 0 /* asynchronous mode */ +#define M_HDLC 1 /* bit-sync mode (HDLC) */ +#define M_G703 2 +#define M_E1 3 + +/* + * Receive error codes. + */ +#define ER_FRAMING 1 /* framing error */ +#define ER_CHECKSUM 2 /* parity/CRC error */ +#define ER_BREAK 3 /* break state */ +#define ER_OVERFLOW 4 /* receive buffer overflow */ +#define ER_OVERRUN 5 /* receive fifo overrun */ +#define ER_UNDERRUN 6 /* transmit fifo underrun */ +#define ER_SCC_FRAMING 7 /* subchannel framing error */ +#define ER_SCC_OVERFLOW 8 /* subchannel receive buffer overflow */ +#define ER_SCC_OVERRUN 9 /* subchannel receiver overrun */ + +/* + * E1 channel status. + */ +#define E1_NOALARM 0x0001 /* no alarm present */ +#define E1_FARLOF 0x0002 /* receiving far loss of framing */ +#define E1_AIS 0x0008 /* receiving all ones */ +#define E1_LOF 0x0020 /* loss of framing */ +#define E1_LOS 0x0040 /* loss of signal */ +#define E1_AIS16 0x0100 /* receiving all ones in timeslot 16 */ +#define E1_FARLOMF 0x0200 /* receiving alarm in timeslot 16 */ +#define E1_LOMF 0x0400 /* loss of multiframe sync */ +#define E1_TSTREQ 0x0800 /* test code detected */ +#define E1_TSTERR 0x1000 /* test error */ + +#define E3_LOS 0x00000002 /* Lost of synchronization */ +#define E3_TXE 0x00000004 /* Transmit error */ + +/* + * Query the mask of all registered channels, max 128. + */ +#define SERIAL_GETREGISTERED _IOR ('x', 0, char[16]) + +/* + * Attach/detach the protocol to the channel. + * The protocol is given by it's name, char[8]. + * For example "async", "hdlc", "cisco", "fr", "ppp". + */ +#define SERIAL_GETPROTO _IOR ('x', 1, char [8]) +#define SERIAL_SETPROTO _IOW ('x', 1, char [8]) + +/* + * Query/set the hardware mode for the channel. + */ +#define SERIAL_GETMODE _IOR ('x', 2, int) +#define SERIAL_SETMODE _IOW ('x', 2, int) + +#define SERIAL_ASYNC 1 +#define SERIAL_HDLC 2 + +/* + * Get/clear the channel statistics. + */ +#define SERIAL_GETSTAT _IOR ('x', 3, struct serial_statistics) +#define SERIAL_GETESTAT _IOR ('x', 3, struct e1_statistics) +#define SERIAL_GETE3STAT _IOR ('x', 3, struct e3_statistics) +#define SERIAL_CLRSTAT _IO ('x', 3) + +/* + * Query/set the synchronization mode and baud rate. + * If baud==0 then the external clock is used. + */ +#define SERIAL_GETBAUD _IOR ('x', 4, long) +#define SERIAL_SETBAUD _IOW ('x', 4, long) + +/* + * Query/set the internal loopback mode, + * useful for debugging purposes. + */ +#define SERIAL_GETLOOP _IOR ('x', 5, int) +#define SERIAL_SETLOOP _IOW ('x', 5, int) + +/* + * Query/set the DPLL mode, commonly used with NRZI + * for channels lacking synchro signals. + */ +#define SERIAL_GETDPLL _IOR ('x', 6, int) +#define SERIAL_SETDPLL _IOW ('x', 6, int) + +/* + * Query/set the NRZI encoding (default is NRZ). + */ +#define SERIAL_GETNRZI _IOR ('x', 7, int) +#define SERIAL_SETNRZI _IOW ('x', 7, int) + +/* + * Invert receive and transmit clock. + */ +#define SERIAL_GETINVCLK _IOR ('x', 8, int) +#define SERIAL_SETINVCLK _IOW ('x', 8, int) + +/* + * Query/set the E1/G703 synchronization mode. + */ +#define SERIAL_GETCLK _IOR ('x', 9, int) +#define SERIAL_SETCLK _IOW ('x', 9, int) + +#define E1CLK_INTERNAL 0 +#define E1CLK_RECEIVE 1 +#define E1CLK_RECEIVE_CHAN0 2 +#define E1CLK_RECEIVE_CHAN1 3 +#define E1CLK_RECEIVE_CHAN2 4 +#define E1CLK_RECEIVE_CHAN3 5 + +/* + * Query/set the E1 timeslot mask. + */ +#define SERIAL_GETTIMESLOTS _IOR ('x', 10, long) +#define SERIAL_SETTIMESLOTS _IOW ('x', 10, long) + +/* + * Query/set the E1 subchannel timeslot mask. + */ +#define SERIAL_GETSUBCHAN _IOR ('x', 11, long) +#define SERIAL_SETSUBCHAN _IOW ('x', 11, long) + +/* + * Query/set the high input sensitivity mode (E1). + */ +#define SERIAL_GETHIGAIN _IOR ('x', 12, int) +#define SERIAL_SETHIGAIN _IOW ('x', 12, int) + +/* + * Query the input signal level in santibells. + */ +#define SERIAL_GETLEVEL _IOR ('x', 13, int) + +/* + * Get the channel name. + */ +#define SERIAL_GETNAME _IOR ('x', 14, char [32]) + +/* + * Get version string. + */ +#define SERIAL_GETVERSIONSTRING _IOR ('x', 15, char [256]) + +/* + * Query/set master channel. + */ +#define SERIAL_GETMASTER _IOR ('x', 16, char [16]) +#define SERIAL_SETMASTER _IOW ('x', 16, char [16]) + +/* + * Query/set keepalive. + */ +#define SERIAL_GETKEEPALIVE _IOR ('x', 17, int) +#define SERIAL_SETKEEPALIVE _IOW ('x', 17, int) + +/* + * Query/set E1 configuration. + */ +#define SERIAL_GETCFG _IOR ('x', 18, char) +#define SERIAL_SETCFG _IOW ('x', 18, char) + +/* + * Query/set debug. + */ +#define SERIAL_GETDEBUG _IOR ('x', 19, int) +#define SERIAL_SETDEBUG _IOW ('x', 19, int) + +/* + * Query/set phony mode (E1). + */ +#define SERIAL_GETPHONY _IOR ('x', 20, int) +#define SERIAL_SETPHONY _IOW ('x', 20, int) + +/* + * Query/set timeslot 16 usage mode (E1). + */ +#define SERIAL_GETUSE16 _IOR ('x', 21, int) +#define SERIAL_SETUSE16 _IOW ('x', 21, int) + +/* + * Query/set crc4 mode (E1). + */ +#define SERIAL_GETCRC4 _IOR ('x', 22, int) +#define SERIAL_SETCRC4 _IOW ('x', 22, int) + +/* + * Query/set the timeout to recover after transmit interrupt loss. + * If timo==0 recover will be disabled. + */ +#define SERIAL_GETTIMO _IOR ('x', 23, long) +#define SERIAL_SETTIMO _IOW ('x', 23, long) + +/* + * Query/set port type for old models of Sigma + * -1 Fixed or cable select + * 0 RS-232 + * 1 V35 + * 2 RS-449 + * 3 E1 (only for Windows 2000) + * 4 G.703 (only for Windows 2000) + * 5 DATA (only for Windows 2000) + * 6 E3 (only for Windows 2000) + * 7 T3 (only for Windows 2000) + * 8 STS1 (only for Windows 2000) + */ +#define SERIAL_GETPORT _IOR ('x', 25, int) +#define SERIAL_SETPORT _IOW ('x', 25, int) + +/* + * Add the virtual channel DLCI (Frame Relay). + */ +#define SERIAL_ADDDLCI _IOW ('x', 26, int) + +/* + * Invert receive clock. + */ +#define SERIAL_GETINVRCLK _IOR ('x', 27, int) +#define SERIAL_SETINVRCLK _IOW ('x', 27, int) + +/* + * Invert transmit clock. + */ +#define SERIAL_GETINVTCLK _IOR ('x', 28, int) +#define SERIAL_SETINVTCLK _IOW ('x', 28, int) + +/* + * Unframed E1 mode. + */ +#define SERIAL_GETUNFRAM _IOR ('x', 29, int) +#define SERIAL_SETUNFRAM _IOW ('x', 29, int) + +/* + * E1 monitoring mode. + */ +#define SERIAL_GETMONITOR _IOR ('x', 30, int) +#define SERIAL_SETMONITOR _IOW ('x', 30, int) + +/* + * Interrupt number. + */ +#define SERIAL_GETIRQ _IOR ('x', 31, int) + +/* + * Reset. + */ +#define SERIAL_RESET _IO ('x', 32) + +/* + * Hard reset. + */ +#define SERIAL_HARDRESET _IO ('x', 33) + +/* + * Query cable type. + */ +#define SERIAL_GETCABLE _IOR ('x', 34, int) + +/* + * Assignment of HDLC ports to E1 channels. + */ +#define SERIAL_GETDIR _IOR ('x', 35, int) +#define SERIAL_SETDIR _IOW ('x', 35, int) + +struct dxc_table { /* cross-connector parameters */ + unsigned char ts [32]; /* timeslot number */ + unsigned char link [32]; /* E1 link number */ +}; + +/* + * DXC cross-connector settings for E1 channels. + */ +#define SERIAL_GETDXC _IOR ('x', 36, struct dxc_table) +#define SERIAL_SETDXC _IOW ('x', 36, struct dxc_table) + +/* + * Scrambler for G.703. + */ +#define SERIAL_GETSCRAMBLER _IOR ('x', 37, int) +#define SERIAL_SETSCRAMBLER _IOW ('x', 37, int) + +/* + * Length of cable for T3 and STS-1. + */ +#define SERIAL_GETCABLEN _IOR ('x', 38, int) +#define SERIAL_SETCABLEN _IOW ('x', 38, int) + +/* + * Remote loopback for E3, T3 and STS-1. + */ +#define SERIAL_GETRLOOP _IOR ('x', 39, int) +#define SERIAL_SETRLOOP _IOW ('x', 39, int) + +/* + * Dynamic binder interface. + */ +#ifdef __KERNEL__ +typedef struct _chan_t chan_t; +typedef struct _proto_t proto_t; + +void binder_register_protocol (proto_t *p); +void binder_unregister_protocol (proto_t *p); + +int binder_register_channel (chan_t *h, char *prefix, int minor); +void binder_unregister_channel (chan_t *h); + +/* + * Hardware channel driver structure. + */ +struct sk_buff; + +struct _chan_t { + char name [16]; + int mtu; /* max packet size */ + int fifosz; /* total hardware i/o buffer size */ + int port; /* hardware base i/o port */ + int irq; /* hardware interrupt line */ + int minor; /* minor number 0..127, assigned by binder */ + int debug; /* debug level, 0..2 */ + int running; /* running, 0..1 */ + struct _proto_t *proto; /* protocol interface data */ + void *sw; /* protocol private data */ + void *hw; /* hardware layer private data */ + + /* Interface to protocol */ + int (*up) (chan_t *h); + void (*down) (chan_t *h); + int (*transmit) (chan_t *h, struct sk_buff *skb); + void (*set_dtr) (chan_t *h, int val); + void (*set_rts) (chan_t *h, int val); + int (*query_dtr) (chan_t *h); + int (*query_rts) (chan_t *h); + int (*query_dsr) (chan_t *h); + int (*query_cts) (chan_t *h); + int (*query_dcd) (chan_t *h); + + /* Interface to async protocol */ + void (*set_async_param) (chan_t *h, int baud, int bits, int parity, + int stop2, int ignpar, int rtscts, + int ixon, int ixany, int symstart, int symstop); + void (*send_break) (chan_t *h, int msec); + void (*send_xon) (chan_t *h); + void (*send_xoff) (chan_t *h); + void (*start_transmitter) (chan_t *h); + void (*stop_transmitter) (chan_t *h); + void (*flush_transmit_buffer) (chan_t *h); + + /* Control interface */ + int (*control) (chan_t *h, unsigned int cmd, unsigned long arg); +}; + +/* + * Protocol driver structure. + */ +struct _proto_t { + char *name; + struct _proto_t *next; + + /* Interface to channel */ + void (*receive) (chan_t *h, struct sk_buff *skb); + void (*receive_error) (chan_t *h, int errcode); + void (*transmit) (chan_t *h); + void (*modem_event) (chan_t *h); + + /* Interface to binder */ + int (*open) (chan_t *h); + void (*close) (chan_t *h); + int (*read) (chan_t *h, unsigned short flg, char *buf, int len); + int (*write) (chan_t *h, unsigned short flg, const char *buf, int len); + int (*select) (chan_t *h, int type, void *st, struct file *filp); + struct fasync_struct *fasync; + + /* Control interface */ + int (*attach) (chan_t *h); + int (*detach) (chan_t *h); + int (*control) (chan_t *h, unsigned int cmd, unsigned long arg); +}; +#endif /* KERNEL */ diff --git a/src/include/machine/db_machdep.h b/src/include/machine/db_machdep.h new file mode 100644 index 0000000..f98db9a --- /dev/null +++ b/src/include/machine/db_machdep.h @@ -0,0 +1,93 @@ +/* + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * $FreeBSD: src/sys/i386/include/db_machdep.h,v 1.17 2001/09/15 11:06:07 dfr Exp $ + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +#include +#include +#include + +#define i386_saved_state trapframe + +typedef vm_offset_t db_addr_t; /* address - unsigned */ +typedef int db_expr_t; /* expression - signed */ + +typedef struct i386_saved_state db_regs_t; +extern db_regs_t ddb_regs; /* register state */ +#define DDB_REGS (&ddb_regs) + +#define PC_REGS(regs) ((db_addr_t)(regs)->tf_eip) + +#define BKPT_INST 0xcc /* breakpoint instruction */ +#define BKPT_SIZE (1) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define BKPT_SKIP ddb_regs.tf_eip += 1 + +#define FIXUP_PC_AFTER_BREAK ddb_regs.tf_eip -= 1; + +#define db_clear_single_step(regs) ((regs)->tf_eflags &= ~PSL_T) +#define db_set_single_step(regs) ((regs)->tf_eflags |= PSL_T) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) +/* + * Watchpoints are not supported. The debug exception type is in %dr6 + * and not yet in the args to this macro. + */ +#define IS_WATCHPOINT_TRAP(type, code) 0 + +#define I_CALL 0xe8 +#define I_CALLI 0xff +#define I_RET 0xc3 +#define I_IRET 0xcf + +#define inst_trap_return(ins) (((ins)&0xff) == I_IRET) +#define inst_return(ins) (((ins)&0xff) == I_RET) +#define inst_call(ins) (((ins)&0xff) == I_CALL || \ + (((ins)&0xff) == I_CALLI && \ + ((ins)&0x3800) == 0x1000)) +#define inst_load(ins) 0 +#define inst_store(ins) 0 + +/* + * There no interesting addresses below _kstack = 0xefbfe000. There + * are small absolute values for GUPROF, but we don't want to see them. + * Treat "negative" addresses below _kstack as non-small to allow for + * future reductions of _kstack and to avoid sign extension problems. + * + * There is one interesting symbol above -db_maxoff = 0xffff0000, + * namely _APTD = 0xfffff000. Accepting this would mess up the + * printing of small negative offsets. The next largest symbol is + * _APTmap = 0xffc00000. Accepting this is OK (unless db_maxoff is + * set to >= 0x400000 - (max stack offset)). + */ +#define DB_SMALL_VALUE_MAX 0x7fffffff +#define DB_SMALL_VALUE_MIN (-0x400001) + +#endif /* !_MACHINE_DB_MACHDEP_H_ */ diff --git a/src/include/machine/dvcfg.h b/src/include/machine/dvcfg.h new file mode 100644 index 0000000..ca60826 --- /dev/null +++ b/src/include/machine/dvcfg.h @@ -0,0 +1,65 @@ +/* $FreeBSD: src/sys/i386/include/dvcfg.h,v 1.4 2002/03/20 05:48:58 alfred Exp $ */ +/* $NetBSD$ */ +/* + * [NetBSD for NEC PC98 series] + * Copyright (c) 1996 NetBSD/pc98 porting staff. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ +/* + * Copyright (c) 1996 Naofumi HONDA. All rights reserved. + */ + +#ifndef _I386_DVCFG_H_ +#define _I386_DVCFG_H_ + +typedef void *dvcfg_hw_t; + +struct dvcfg_hwsel { + int cfg_max; + + dvcfg_hw_t *cfg_sel; +}; + +#define DVCFG_MAJOR(dvcfg) (((u_int)(dvcfg)) >> 16) +#define DVCFG_MINOR(dvcfg) (((u_int)(dvcfg)) & 0xffff) + +#define DVCFG_MKCFG(major, minor) ((((u_int)(major)) << 16) | ((minor) & 0xffff)) + +#define DVCFG_HWSEL_SZ(array) (sizeof(array) / sizeof(dvcfg_hw_t)) + +static __inline dvcfg_hw_t dvcfg_hw(struct dvcfg_hwsel *, u_int); + +static __inline dvcfg_hw_t +dvcfg_hw(selp, num) + struct dvcfg_hwsel *selp; + u_int num; +{ + + return ((num >= selp->cfg_max) ? 0 : selp->cfg_sel[num]); +} + +#define DVCFG_HW(SELP, NUM) dvcfg_hw((SELP), (NUM)) +#endif /* _I386_DVCFG_H_ */ diff --git a/src/include/machine/elan_mmcr.h b/src/include/machine/elan_mmcr.h new file mode 100644 index 0000000..7ac97e2 --- /dev/null +++ b/src/include/machine/elan_mmcr.h @@ -0,0 +1,280 @@ +/*- + * Copyright (c) 2004 John Birrell + * All rights reserved. + * + * Please see src/share/examples/etc/bsd-style-copyright. + * + * AMD Elan SC520 Memory Mapped Configuration Region (MMCR). + * + * The layout of this structure is documented by AMD in the Elan SC520 + * Microcontroller Register Set Manual. The field names match those + * described in that document. The overall structure size must be 4096 + * bytes. Ignore fields with the 'pad' prefix - they are only present for + * alignment purposes. + * + * $FreeBSD: src/sys/i386/include/elan_mmcr.h,v 1.1 2004/01/05 12:00:59 phk Exp $ + */ + +#ifndef _MACHINE_ELAN_MMCR_H_ +#define _MACHINE_ELAN_MMCR_H_ 1 + +struct elan_mmcr { + /* CPU */ + u_int16_t REVID; + u_int8_t CPUCTL; + u_int8_t pad_0x003[0xd]; + + /* SDRAM Controller */ + u_int16_t DRCCTL; + u_int16_t DRCTMCTL; + u_int16_t DRCCFG; + u_int16_t DRCBENDADR; + u_int8_t pad_0x01a[0x6]; + u_int8_t ECCCTL; + u_int8_t ECCSTA; + u_int8_t ECCCKBPOS; + u_int8_t ECCCKTEST; + u_int32_t ECCSBADD; + u_int32_t ECCMBADD; + u_int8_t pad_0x02c[0x14]; + + /* SDRAM Buffer */ + u_int8_t DBCTL; + u_int8_t pad_0x041[0xf]; + + /* ROM/Flash Controller */ + u_int16_t BOOTCSCTL; + u_int8_t pad_0x052[0x2]; + u_int16_t ROMCS1CTL; + u_int16_t ROMCS2CTL; + u_int8_t pad_0x058[0x8]; + + /* PCI Bus Host Bridge */ + u_int16_t HBCTL; + u_int16_t HBTGTIRQCTL; + u_int16_t HBTGTIRQSTA; + u_int16_t HBMSTIRQCTL; + u_int16_t HBMSTIRQSTA; + u_int8_t pad_0x06a[0x2]; + u_int32_t MSTINTADD; + + /* System Arbitration */ + u_int8_t SYSARBCTL; + u_int8_t PCIARBSTA; + u_int16_t SYSARBMENB; + u_int32_t ARBPRICTL; + u_int8_t pad_0x078[0x8]; + + /* System Address Mapping */ + u_int32_t ADDDECCTL; + u_int32_t WPVSTA; + u_int32_t PAR0; + u_int32_t PAR1; + u_int32_t PAR2; + u_int32_t PAR3; + u_int32_t PAR4; + u_int32_t PAR5; + u_int32_t PAR6; + u_int32_t PAR7; + u_int32_t PAR8; + u_int32_t PAR9; + u_int32_t PAR10; + u_int32_t PAR11; + u_int32_t PAR12; + u_int32_t PAR13; + u_int32_t PAR14; + u_int32_t PAR15; + u_int8_t pad_0x0c8[0xb38]; + + /* GP Bus Controller */ + u_int8_t GPECHO; + u_int8_t GPCSDW; + u_int16_t GPCSQUAL; + u_int8_t pad_0xc04[0x4]; + u_int8_t GPCSRT; + u_int8_t GPCSPW; + u_int8_t GPCSOFF; + u_int8_t GPRDW; + u_int8_t GPRDOFF; + u_int8_t GPWRW; + u_int8_t GPWROFF; + u_int8_t GPALEW; + u_int8_t GPALEOFF; + u_int8_t pad_0xc11[0xf]; + + /* Programmable Input/Output */ + u_int16_t PIOPFS15_0; + u_int16_t PIOPFS31_16; + u_int8_t CSPFS; + u_int8_t pad_0xc25; + u_int8_t CLKSEL; + u_int8_t pad_0xc27; + u_int16_t DSCTL; + u_int16_t PIODIR15_0; + u_int16_t PIODIR31_16; + u_int8_t pad_0xc2e[0x2]; + u_int16_t PIODATA15_0; + u_int16_t PIODATA31_16; + u_int16_t PIOSET15_0; + u_int16_t PIOSET31_16; + u_int16_t PIOCLR15_0; + u_int16_t PIOCLR31_16; + u_int8_t pad_0xc3c[0x24]; + + /* Software Timer */ + u_int16_t SWTMRMILLI; + u_int16_t SWTMRMICRO; + u_int8_t SWTMRCFG; + u_int8_t pad_0xc65[0xb]; + + /* General-Purpose Timers */ + u_int8_t GPTMRSTA; + u_int8_t pad_0xc71; + u_int16_t GPTMR0CTL; + u_int16_t GPTMR0CNT; + u_int16_t GPTMR0MAXCMPA; + u_int16_t GPTMR0MAXCMPB; + u_int16_t GPTMR1CTL; + u_int16_t GPTMR1CNT; + u_int16_t GPTMR1MAXCMPA; + u_int16_t GPTMR1MAXCMPB; + u_int16_t GPTMR2CTL; + u_int16_t GPTMR2CNT; + u_int8_t pad_0xc86[0x8]; + u_int16_t GPTMR2MAXCMPA; + u_int8_t pad_0xc90[0x20]; + + /* Watchdog Timer */ + u_int16_t WDTMRCTL; + u_int16_t WDTMRCNTL; + u_int16_t WDTMRCNTH; + u_int8_t pad_0xcb6[0xa]; + + /* UART Serial Ports */ + u_int8_t UART1CTL; + u_int8_t UART1STA; + u_int8_t UART1FCRSHAD; + u_int8_t pad_0xcc3; + u_int8_t UART2CTL; + u_int8_t UART2STA; + u_int8_t UART2FCRSHAD; + u_int8_t pad_0xcc7[0x9]; + + /* Synchronous Serial Interface */ + u_int8_t SSICTL; + u_int8_t SSIXMIT; + u_int8_t SSICMD; + u_int8_t SSISTA; + u_int8_t SSIRCV; + u_int8_t pad_0xcd5[0x2b]; + + /* Programmable Interrupt Controller */ + u_int8_t PICICR; + u_int8_t pad_0xd01; + u_int8_t MPICMODE; + u_int8_t SL1PICMODE; + u_int8_t SL2PICMODE; + u_int8_t pad_0xd05[0x3]; + u_int16_t SWINT16_1; + u_int8_t SWINT22_17; + u_int8_t pad_0xd0b[0x5]; + u_int16_t INTPINPOL; + u_int8_t pad_0xd12[0x2]; + u_int16_t PCIHOSTMAP; + u_int8_t pad_0xd16[0x2]; + u_int16_t ECCMAP; + u_int8_t GPTMR0MAP; + u_int8_t GPTMR1MAP; + u_int8_t GPTMR2MAP; + u_int8_t pad_0xd1d[0x3]; + u_int8_t PIT0MAP; + u_int8_t PIT1MAP; + u_int8_t PIT2MAP; + u_int8_t pad_0xd23[0x5]; + u_int8_t UART1MAP; + u_int8_t UART2MAP; + u_int8_t pad_0xd2a[0x6]; + u_int8_t PCIINTAMAP; + u_int8_t PCIINTBMAP; + u_int8_t PCIINTCMAP; + u_int8_t PCIINTDMAP; + u_int8_t pad_0xd34[0xc]; + u_int8_t DMABCINTMAP; + u_int8_t SSIMAP; + u_int8_t WDTMAP; + u_int8_t RTCMAP; + u_int8_t WPVMAP; + u_int8_t ICEMAP; + u_int8_t FERRMAP; + u_int8_t pad_0xd47[0x9]; + u_int8_t GP0IMAP; + u_int8_t GP1IMAP; + u_int8_t GP2IMAP; + u_int8_t GP3IMAP; + u_int8_t GP4IMAP; + u_int8_t GP5IMAP; + u_int8_t GP6IMAP; + u_int8_t GP7IMAP; + u_int8_t GP8IMAP; + u_int8_t GP9IMAP; + u_int8_t GP10IMAP; + u_int8_t pad_0xd5b[0x15]; + + /* Reset Generation */ + u_int8_t SYSINFO; + u_int8_t pad_0xd71; + u_int8_t RESCFG; + u_int8_t pad_0xd73; + u_int8_t RESSTA; + u_int8_t pad_0xd75[0xb]; + + /* GP DMA Controller */ + u_int8_t GPDMACTL; + u_int8_t GPDMAMMIO; + u_int16_t GPDMAEXTCHMAPA; + u_int16_t GPDMAEXTCHMAPB; + u_int8_t GPDMAEXTPG0; + u_int8_t GPDMAEXTPG1; + u_int8_t GPDMAEXTPG2; + u_int8_t GPDMAEXTPG3; + u_int8_t GPDMAEXTPG5; + u_int8_t GPDMAEXTPG6; + u_int8_t GPDMAEXTPG7; + u_int8_t pad_0xd8d[0x3]; + u_int8_t GPDMAEXTTC3; + u_int8_t GPDMAEXTTC5; + u_int8_t GPDMAEXTTC6; + u_int8_t GPDMAEXTTC7; + u_int8_t pad_0xd94[0x4]; + u_int8_t GPDMABCCTL; + u_int8_t GPDMABCSTA; + u_int8_t GPDMABSINTENB; + u_int8_t GPDMABCVAL; + u_int8_t pad_0xd9c[0x4]; + u_int16_t GPDMANXTADDL3; + u_int16_t GPDMANXTADDH3; + u_int16_t GPDMANXTADDL5; + u_int16_t GPDMANXTADDH5; + u_int16_t GPDMANXTADDL6; + u_int16_t GPDMANXTADDH6; + u_int16_t GPDMANXTADDL7; + u_int16_t GPDMANXTADDH7; + u_int16_t GPDMANXTTCL3; + u_int8_t GPDMANXTTCH3; + u_int8_t pad_0xdb3; + u_int16_t GPDMANXTTCL5; + u_int8_t GPDMANXTTCH5; + u_int8_t pad_0xdb7; + u_int16_t GPDMANXTTCL6; + u_int8_t GPDMANXTTCH6; + u_int8_t pad_0xdbb; + u_int16_t GPDMANXTTCL7; + u_int8_t GPDMANXTTCH7; + u_int8_t pad_0xdc0[0x240]; + }; + +CTASSERT(sizeof(struct elan_mmcr) == 4096); + +extern volatile struct elan_mmcr * elan_mmcr; + +#endif /* _MACHINE_ELAN_MMCR_H_ */ diff --git a/src/include/machine/elf.h b/src/include/machine/elf.h new file mode 100644 index 0000000..4c4b930 --- /dev/null +++ b/src/include/machine/elf.h @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 1996-1997 John D. Polstra. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/elf.h,v 1.15 2003/09/25 01:10:24 peter Exp $ + */ + +#ifndef _MACHINE_ELF_H_ +#define _MACHINE_ELF_H_ 1 + +/* + * ELF definitions for the i386 architecture. + */ + +#include /* Definitions common to all 32 bit architectures. */ +#if defined(__ELF_WORD_SIZE) && __ELF_WORD_SIZE == 64 +#include /* Definitions common to all 64 bit architectures. */ +#endif + +#ifndef __ELF_WORD_SIZE +#define __ELF_WORD_SIZE 32 /* Used by */ +#endif + +#include + +#define ELF_ARCH EM_386 + +#define ELF_MACHINE_OK(x) ((x) == EM_386 || (x) == EM_486) + +/* + * Auxiliary vector entries for passing information to the interpreter. + * + * The i386 supplement to the SVR4 ABI specification names this "auxv_t", + * but POSIX lays claim to all symbols ending with "_t". + */ + +typedef struct { /* Auxiliary vector entry on initial stack */ + int a_type; /* Entry type. */ + union { + long a_val; /* Integer value. */ + void *a_ptr; /* Address. */ + void (*a_fcn)(void); /* Function pointer (not used). */ + } a_un; +} Elf32_Auxinfo; + +#if __ELF_WORD_SIZE == 64 +/* Fake for amd64 loader support */ +typedef struct { + int fake; +} Elf64_Auxinfo; +#endif + +__ElfType(Auxinfo); + +/* Values for a_type. */ +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_EXECFD 2 /* File descriptor of program to load. */ +#define AT_PHDR 3 /* Program header of program already loaded. */ +#define AT_PHENT 4 /* Size of each program header entry. */ +#define AT_PHNUM 5 /* Number of program header entries. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_BASE 7 /* Interpreter's base address. */ +#define AT_FLAGS 8 /* Flags (unused for i386). */ +#define AT_ENTRY 9 /* Where interpreter should transfer control. */ + +/* + * The following non-standard values are used for passing information + * from John Polstra's testbed program to the dynamic linker. These + * are expected to go away soon. + * + * Unfortunately, these overlap the Linux non-standard values, so they + * must not be used in the same context. + */ +#define AT_BRK 10 /* Starting point for sbrk and brk. */ +#define AT_DEBUG 11 /* Debugging level. */ + +/* + * The following non-standard values are used in Linux ELF binaries. + */ +#define AT_NOTELF 10 /* Program is not ELF ?? */ +#define AT_UID 11 /* Real uid. */ +#define AT_EUID 12 /* Effective uid. */ +#define AT_GID 13 /* Real gid. */ +#define AT_EGID 14 /* Effective gid. */ + +#define AT_COUNT 15 /* Count of defined aux entry types. */ + +/* + * Relocation types. + */ + +#define R_386_NONE 0 /* No relocation. */ +#define R_386_32 1 /* Add symbol value. */ +#define R_386_PC32 2 /* Add PC-relative symbol value. */ +#define R_386_GOT32 3 /* Add PC-relative GOT offset. */ +#define R_386_PLT32 4 /* Add PC-relative PLT offset. */ +#define R_386_COPY 5 /* Copy data from shared object. */ +#define R_386_GLOB_DAT 6 /* Set GOT entry to data address. */ +#define R_386_JMP_SLOT 7 /* Set GOT entry to code address. */ +#define R_386_RELATIVE 8 /* Add load address of shared object. */ +#define R_386_GOTOFF 9 /* Add GOT-relative symbol address. */ +#define R_386_GOTPC 10 /* Add PC-relative GOT table address. */ + +#define R_386_COUNT 11 /* Count of defined relocation types. */ + +/* Define "machine" characteristics */ +#define ELF_TARG_CLASS ELFCLASS32 +#define ELF_TARG_DATA ELFDATA2LSB +#define ELF_TARG_MACH EM_386 +#define ELF_TARG_VER 1 + +#endif /* !_MACHINE_ELF_H_ */ diff --git a/src/include/machine/endian.h b/src/include/machine/endian.h new file mode 100644 index 0000000..42f7ea8 --- /dev/null +++ b/src/include/machine/endian.h @@ -0,0 +1,196 @@ +/*- + * Copyright (c) 1987, 1991 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. + * 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. + * + * @(#)endian.h 7.8 (Berkeley) 4/3/91 + * $FreeBSD: src/sys/i386/include/endian.h,v 1.39 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Define the order of 32-bit words in 64-bit words. + */ +#define _QUAD_HIGHWORD 1 +#define _QUAD_LOWWORD 0 + +/* + * Definitions for byte order, according to byte significance from low + * address to high. + */ +#define _LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ +#define _BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ +#define _PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ + +#define _BYTE_ORDER _LITTLE_ENDIAN + +/* + * Deprecated variants that don't have enough underscores to be useful in more + * strict namespaces. + */ +#if __BSD_VISIBLE +#define LITTLE_ENDIAN _LITTLE_ENDIAN +#define BIG_ENDIAN _BIG_ENDIAN +#define PDP_ENDIAN _PDP_ENDIAN +#define BYTE_ORDER _BYTE_ORDER +#endif + +#if defined(__INTEL_COMPILER) +#if defined(__cplusplus) +#if __INTEL_COMPILER >= 800 +#define __INTEL_COMPILER_with_FreeBSD_endian 1 +#endif +#else +#define __INTEL_COMPILER_with_FreeBSD_endian 1 +#endif +#endif + +#if defined(__GNUC__) || defined(__INTEL_COMPILER_with_FreeBSD_endian) + +#define __word_swap_int_var(x) \ +__extension__ ({ register __uint32_t __X = (x); \ + __asm ("rorl $16, %0" : "+r" (__X)); \ + __X; }) + +#ifdef __OPTIMIZE__ + +#define __word_swap_int_const(x) \ + ((((x) & 0xffff0000) >> 16) | \ + (((x) & 0x0000ffff) << 16)) +#define __word_swap_int(x) (__builtin_constant_p(x) ? \ + __word_swap_int_const(x) : __word_swap_int_var(x)) + +#else /* __OPTIMIZE__ */ + +#define __word_swap_int(x) __word_swap_int_var(x) + +#endif /* __OPTIMIZE__ */ + +#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU) + +#define __byte_swap_int_var(x) \ +__extension__ ({ register __uint32_t __X = (x); \ + __asm ("bswap %0" : "+r" (__X)); \ + __X; }) +#else + +#define __byte_swap_int_var(x) \ +__extension__ ({ register __uint32_t __X = (x); \ + __asm ("xchgb %h0, %b0\n\trorl $16, %0\n\txchgb %h0, %b0" \ + : "+q" (__X)); \ + __X; }) +#endif + +#ifdef __OPTIMIZE__ + +#define __byte_swap_int_const(x) \ + ((((x) & 0xff000000) >> 24) | \ + (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | \ + (((x) & 0x000000ff) << 24)) +#define __byte_swap_int(x) (__builtin_constant_p(x) ? \ + __byte_swap_int_const(x) : __byte_swap_int_var(x)) + +#else /* __OPTIMIZE__ */ + +#define __byte_swap_int(x) __byte_swap_int_var(x) + +#endif /* __OPTIMIZE__ */ + +#define __byte_swap_word_var(x) \ +__extension__ ({ register __uint16_t __X = (x); \ + __asm ("xchgb %h0, %b0" : "+q" (__X)); \ + __X; }) + +#ifdef __OPTIMIZE__ + +#define __byte_swap_word_const(x) \ + ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8)) + +#define __byte_swap_word(x) (__builtin_constant_p(x) ? \ + __byte_swap_word_const(x) : __byte_swap_word_var(x)) + +#else /* __OPTIMIZE__ */ + +#define __byte_swap_word(x) __byte_swap_word_var(x) + +#endif /* __OPTIMIZE__ */ + +static __inline __uint64_t +__bswap64(__uint64_t _x) +{ + + return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | + ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | + ((_x << 24) & ((__uint64_t)0xff << 40)) | + ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); +} + +static __inline __uint32_t +__bswap32(__uint32_t _x) +{ + + return (__byte_swap_int(_x)); +} + +static __inline __uint16_t +__bswap16(__uint16_t _x) +{ + + return (__byte_swap_word(_x)); +} + +#define __htonl(x) __bswap32(x) +#define __htons(x) __bswap16(x) +#define __ntohl(x) __bswap32(x) +#define __ntohs(x) __bswap16(x) + +#else /* !(__GNUC__ || __INTEL_COMPILER_with_FreeBSD_endian) */ + +/* + * No optimizations are available for this compiler. Fall back to + * non-optimized functions by defining the constant usually used to prevent + * redefinition. + */ +#define _BYTEORDER_FUNC_DEFINED + +#endif /* __GNUC__ || __INTEL_COMPILER_with_FreeBSD_endian */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/src/include/machine/exec.h b/src/include/machine/exec.h new file mode 100644 index 0000000..2bf2465 --- /dev/null +++ b/src/include/machine/exec.h @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 1992, 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. + * 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. + * + * @(#)exec.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD: src/sys/i386/include/exec.h,v 1.9 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _EXEC_H_ +#define _EXEC_H_ + +#define __LDPGSZ 4096 + +#endif /* !_EXEC_H_ */ diff --git a/src/include/machine/float.h b/src/include/machine/float.h new file mode 100644 index 0000000..7fd7e8d --- /dev/null +++ b/src/include/machine/float.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1989 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. + * 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. + * + * from: @(#)float.h 7.1 (Berkeley) 5/8/90 + * $FreeBSD: src/sys/i386/include/float.h,v 1.12 2004/04/25 02:36:28 das Exp $ + */ + +#ifndef _MACHINE_FLOAT_H_ +#define _MACHINE_FLOAT_H_ 1 + +#include + +#define FLT_RADIX 2 /* b */ +#define FLT_ROUNDS 1 /* FP addition rounds to nearest */ +#if __ISO_C_VISIBLE >= 1999 +#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */ +#define DECIMAL_DIG 21 /* max precision in decimal digits */ +#endif + +#define FLT_MANT_DIG 24 /* p */ +#define FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define FLT_MIN_EXP (-125) /* emin */ +#define FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define FLT_MAX_EXP 128 /* emax */ +#define FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define DBL_MANT_DIG 53 +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_DIG 15 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_EXP 1024 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MAX_10_EXP 308 + + +#define LDBL_MANT_DIG 64 +#define LDBL_EPSILON 1.0842021724855044340E-19L +#define LDBL_DIG 18 +#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN 3.3621031431120935063E-4932L +#define LDBL_MIN_10_EXP (-4931) +#define LDBL_MAX_EXP 16384 +#define LDBL_MAX 1.1897314953572317650E+4932L +#define LDBL_MAX_10_EXP 4932 +#endif /* _MACHINE_FLOAT_H_ */ diff --git a/src/include/machine/floatingpoint.h b/src/include/machine/floatingpoint.h new file mode 100644 index 0000000..65cb4a3 --- /dev/null +++ b/src/include/machine/floatingpoint.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 1993 Andrew Moore, Talke Studio + * 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. + * + * from: @(#) floatingpoint.h 1.0 (Berkeley) 9/23/93 + * $FreeBSD: src/sys/i386/include/floatingpoint.h,v 1.13 2003/01/19 06:01:33 marcel Exp $ + */ + +#ifndef _FLOATINGPOINT_H_ +#define _FLOATINGPOINT_H_ + +#include + +#endif /* !_FLOATINGPOINT_H_ */ diff --git a/src/include/machine/frame.h b/src/include/machine/frame.h new file mode 100644 index 0000000..2715483 --- /dev/null +++ b/src/include/machine/frame.h @@ -0,0 +1,156 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)frame.h 5.2 (Berkeley) 1/18/91 + * $FreeBSD: src/sys/i386/include/frame.h,v 1.24 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ 1 + +/* + * System stack frames. + */ + +/* + * Exception/Trap Stack Frame + */ + +struct trapframe { + int tf_fs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_ebp; + int tf_isp; + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_err; + int tf_eip; + int tf_cs; + int tf_eflags; + /* below only when crossing rings (e.g. user to kernel) */ + int tf_esp; + int tf_ss; +}; + +/* Superset of trap frame, for traps from virtual-8086 mode */ + +struct trapframe_vm86 { + int tf_fs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_ebp; + int tf_isp; + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_err; + int tf_eip; + int tf_cs; + int tf_eflags; + /* below only when crossing rings (e.g. user to kernel) */ + int tf_esp; + int tf_ss; + /* below only when switching out of VM86 mode */ + int tf_vm86_es; + int tf_vm86_ds; + int tf_vm86_fs; + int tf_vm86_gs; +}; + +/* Interrupt stack frame */ + +struct intrframe { + int if_vec; + int if_fs; + int if_es; + int if_ds; + int if_edi; + int if_esi; + int if_ebp; + int :32; + int if_ebx; + int if_edx; + int if_ecx; + int if_eax; + int :32; /* for compat with trap frame - trapno */ + int :32; /* for compat with trap frame - err */ + /* below portion defined in 386 hardware */ + int if_eip; + int if_cs; + int if_eflags; + /* below only when crossing rings (e.g. user to kernel) */ + int if_esp; + int if_ss; +}; + +/* frame of clock (same as interrupt frame) */ + +struct clockframe { + int cf_vec; + int cf_fs; + int cf_es; + int cf_ds; + int cf_edi; + int cf_esi; + int cf_ebp; + int :32; + int cf_ebx; + int cf_edx; + int cf_ecx; + int cf_eax; + int :32; /* for compat with trap frame - trapno */ + int :32; /* for compat with trap frame - err */ + /* below portion defined in 386 hardware */ + int cf_eip; + int cf_cs; + int cf_eflags; + /* below only when crossing rings (e.g. user to kernel) */ + int cf_esp; + int cf_ss; +}; + +int kdb_trap(int, int, struct trapframe *); + +#define INTR_TO_TRAPFRAME(frame) ((struct trapframe *)&(frame)->if_fs) + +#endif /* _MACHINE_FRAME_H_ */ diff --git a/src/include/machine/gsc.h b/src/include/machine/gsc.h new file mode 100644 index 0000000..226b2a9 --- /dev/null +++ b/src/include/machine/gsc.h @@ -0,0 +1,53 @@ +/* gsc.h - programming interface to the scanner device driver `gsc' + * + * + * Copyright (c) 1995 Gunther Schadow. 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 Gunther Schadow. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/gsc.h,v 1.3 2000/05/01 20:04:09 peter Exp $ + */ + +#ifndef _MACHINE_GSC_H_ +#define _MACHINE_GSC_H_ + +#include + +#define GSC_GRES _IOR('S', 1, int) /* get resolution / dpi */ +#define GSC_SRES _IOW('S', 2, int) /* set resolution / dpi */ +#define GSC_GWIDTH _IOR('S', 3, int) /* get width / pixels */ +#define GSC_SWIDTH _IOW('S', 4, int) /* set width / pixels */ +#define GSC_GHEIGHT _IOR('S', 5, int) /* get height / pixels */ +#define GSC_SHEIGHT _IOW('S', 6, int) /* set height / pixels */ + +#define GSC_GBLEN _IOR('S', 7, int) /* get buffer length / lines */ +#define GSC_SBLEN _IOW('S', 8, int) /* set buffer length / lines */ +#define GSC_GBTIME _IOR('S', 9, int) /* get buffer timeout / s */ +#define GSC_SBTIME _IOW('S', 10, int) /* set buffer timeout / s */ + +#define GSC_SRESSW _IO('S', 11) /* set resolution by switch */ + +#endif /* !_MACHINE_GSC_H_ */ diff --git a/src/include/machine/i4b_cause.h b/src/include/machine/i4b_cause.h new file mode 100644 index 0000000..ff3226c --- /dev/null +++ b/src/include/machine/i4b_cause.h @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + *--------------------------------------------------------------------------- + * + * i4b_cause.h - causes and cause handling for i4b + * ----------------------------------------------- + * + * $FreeBSD: src/sys/i386/include/i4b_cause.h,v 1.8 2002/03/17 09:33:12 hm Exp $ + * + * last edit-date: [Sun Mar 17 10:08:21 2002] + * + *---------------------------------------------------------------------------*/ + +#ifndef _I4B_CAUSE_H_ +#define _I4B_CAUSE_H_ + +/*---------------------------------------------------------------------------* + * ISDN4BSD internal causes specification + *---------------------------------------------------------------------------*/ + +#define CAUSE_VAL 0x000000ff /* cause value */ +#define CAUSE_TYPE 0x0000ff00 /* cause type */ +#define CAUSET_Q850 0 /* value coded according to Q.850 */ +#define CAUSET_I4B 1 /* i4b protocol independent causes*/ + +#define GET_CAUSE_VAL(cause) ((cause) & 0xff) +#define SET_CAUSE_VAL(dest, val) ((dest) = ((dest & 0xffffff00) | \ + (val & 0x000000ff))) + +#define GET_CAUSE_TYPE(cause) (((cause) >> 8) & 0xff) +#define SET_CAUSE_TYPE(dest, type) ((dest) = ((dest & 0xffff00ff) | \ + ((type << 8) & 0x0000ff00))) + +#define SET_CAUSE_TV(dest, type, val) ((dest) = ((val & 0x000000ff) | \ + ((type << 8) & 0x0000ff00))) + +/* CAUSET_I4B - protocol independent cause values */ + +#define CAUSE_I4B_NORMAL 0 /* normal call clearing */ +#define CAUSE_I4B_BUSY 1 /* user busy */ +#define CAUSE_I4B_NOCHAN 2 /* circuit/channel not available*/ +#define CAUSE_I4B_INCOMP 3 /* incompatible source/dest */ +#define CAUSE_I4B_REJECT 4 /* call rejected */ +#define CAUSE_I4B_OOO 5 /* destination out of order */ +#define CAUSE_I4B_TMPFAIL 6 /* temporary failure */ +#define CAUSE_I4B_L1ERROR 7 /* L1 error / persistent deact */ +#define CAUSE_I4B_LLDIAL 8 /* no dialout on leased line */ +#define CAUSE_I4B_MAX 9 + /* NOTE: update isdnd/pcause.c when adding causes !!!!! */ + /* NOTE: update layer3/i4b_q931.c when adding causes !!!!! */ + +/* CAUSET_Q850 - causes defined in Q.850 */ + +#define CAUSE_Q850_SHUTDN 0x00 /* normal D-channel shutdown */ +#define CAUSE_Q850_NUNALLC 0x01 /* Unallocated (unassigned) number */ +#define CAUSE_Q850_NRTTN 0x02 /* No route to specified transit network */ +#define CAUSE_Q850_NRTDST 0x03 /* No route to destination */ +#define CAUSE_Q850_SSINFTN 0x04 /* Send special information tone */ +#define CAUSE_Q850_MDIALTP 0x05 /* Misdialled trunk prefix */ +#define CAUSE_Q850_CHUNACC 0x06 /* Channel unacceptable */ +#define CAUSE_Q850_CALLAWD 0x07 /* Call awarded and being delivered in an established channel */ +#define CAUSE_Q850_PREEMPT 0x08 /* Preemption */ +#define CAUSE_Q850_PREECRR 0x09 /* Preemption - circuit reserved for reuse */ +#define CAUSE_Q850_NCCLR 0x10 /* Normal call clearing */ +#define CAUSE_Q850_USRBSY 0x11 /* User busy */ +#define CAUSE_Q850_NOUSRRSP 0x12 /* No user responding */ +#define CAUSE_Q850_NOANSWR 0x13 /* No answer from user (user alerted) */ +#define CAUSE_Q850_SUBSABS 0x14 /* Subscriber absent */ +#define CAUSE_Q850_CALLREJ 0x15 /* Call rejected */ +#define CAUSE_Q850_NUCHNG 0x16 /* Number changed */ +#define CAUSE_Q850_NONSELUC 0x1A /* Non-selected user clearing */ +#define CAUSE_Q850_DSTOOORDR 0x1B /* Destination out of order */ +#define CAUSE_Q850_INVNUFMT 0x1C /* Invalid number format */ +#define CAUSE_Q850_FACREJ 0x1D /* Facility rejected */ +#define CAUSE_Q850_STENQRSP 0x1E /* Response to STATUS ENQUIRY */ +#define CAUSE_Q850_NORMUNSP 0x1F /* Normal, unspecified */ +#define CAUSE_Q850_NOCAVAIL 0x22 /* No circuit / channel available */ +#define CAUSE_Q850_NETOOORDR 0x26 /* Network out of order */ +#define CAUSE_Q850_PFMCDOOSERV 0x27 /* Permanent frame mode connection out of service */ +#define CAUSE_Q850_PFMCOPER 0x28 /* Permanent frame mode connection operational */ +#define CAUSE_Q850_TMPFAIL 0x29 /* Temporary failure */ +#define CAUSE_Q850_SWEQCONG 0x2A /* Switching equipment congestion */ +#define CAUSE_Q850_ACCINFDIS 0x2B /* Access information discarded */ +#define CAUSE_Q850_REQCNOTAV 0x2C /* Requested circuit/channel not available */ +#define CAUSE_Q850_PRECALBLK 0x2E /* Precedence call blocked */ +#define CAUSE_Q850_RESUNAVAIL 0x2F /* Resources unavailable, unspecified */ +#define CAUSE_Q850_QOSUNAVAIL 0x31 /* Quality of service unavailable */ +#define CAUSE_Q850_REQSERVNS 0x32 /* Requested facility not subscribed */ +#define CAUSE_Q850_OCBARRCUG 0x35 /* Outgoing calls barred within CUG */ +#define CAUSE_Q850_ICBARRCUG 0x36 /* Incoming calls barred within CUG */ +#define CAUSE_Q850_BCAPNAUTH 0x39 /* Bearer capability not authorized */ +#define CAUSE_Q850_BCAPNAVAIL 0x3A /* Bearer capability not presently available */ +#define CAUSE_Q850_INCSTOACISC 0x3E /* Inconsistenciy in designated outgoing access information and subscriber class */ +#define CAUSE_Q850_SOONOTAVAIL 0x3F /* Service or option not available, unspecified */ +#define CAUSE_Q850_BCAPNOTIMPL 0x41 /* Bearer capability not implemented */ +#define CAUSE_Q850_CHTYPNIMPL 0x42 /* Channel type not implemented */ +#define CAUSE_Q850_REQFACNIMPL 0x45 /* Requested facility not implemented */ +#define CAUSE_Q850_ORDINBCAVL 0x46 /* Only restricted digital information bearer capability is available */ +#define CAUSE_Q850_SOONOTIMPL 0x4F /* Service or option not implemented, unspecified */ +#define CAUSE_Q850_INVCLRFVAL 0x51 /* Invalid call reference value */ +#define CAUSE_Q850_IDCHDNOEX 0x52 /* Identified channel does not exist */ +#define CAUSE_Q850_SUSCAEXIN 0x53 /* A suspended call exists, but this call identity does not */ +#define CAUSE_Q850_CLIDINUSE 0x54 /* Call identity in use */ +#define CAUSE_Q850_NOCLSUSP 0x55 /* No call suspended */ +#define CAUSE_Q850_CLIDCLRD 0x56 /* Call having the requested call identity has been cleared */ +#define CAUSE_Q850_UNOTMEMCUG 0x57 /* User not member of CUG */ +#define CAUSE_Q850_INCDEST 0x58 /* Incompatible destination */ +#define CAUSE_Q850_NONEXCUG 0x5A /* Non-existent CUG */ +#define CAUSE_Q850_INVNTWSEL 0x5B /* Invalid transit network selection */ +#define CAUSE_Q850_INVMSG 0x5F /* Invalid message, unspecified */ +#define CAUSE_Q850_MIEMISS 0x60 /* Mandatory information element is missing */ +#define CAUSE_Q850_MSGTNI 0x61 /* Message type non-existent or not implemented */ +#define CAUSE_Q850_MSGNCMPT 0x62 /* Message not compatible with call state or message type non-existent or not implemented */ +#define CAUSE_Q850_IENENI 0x63 /* Information element/parameter non-existent or not implemented */ +#define CAUSE_Q850_INVIEC 0x64 /* Invalid information element contents */ +#define CAUSE_Q850_MSGNCWCS 0x65 /* Message not compatible with call state */ +#define CAUSE_Q850_RECOTIMEXP 0x66 /* Recovery on timer expiry */ +#define CAUSE_Q850_PARMNENIPO 0x67 /* Parameter non-existent or not implemented, passed on */ +#define CAUSE_Q850_MSGUNRDPRM 0x6E /* Message with unrecognized parameter, discarded */ +#define CAUSE_Q850_PROTERR 0x6F /* Protocol error, unspecified */ +#define CAUSE_Q850_INTWRKU 0x7F /* Interworking, unspecified */ + +#define CAUSE_Q850_MAX 128 + +#endif /* _I4B_CAUSE_H_ */ diff --git a/src/include/machine/i4b_debug.h b/src/include/machine/i4b_debug.h new file mode 100644 index 0000000..745eab2 --- /dev/null +++ b/src/include/machine/i4b_debug.h @@ -0,0 +1,301 @@ +/* + * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + *--------------------------------------------------------------------------- + * + * i4b_debug.h - i4b debug header file + * ----------------------------------- + * + * $FreeBSD: src/sys/i386/include/i4b_debug.h,v 1.11 2002/03/17 09:33:12 hm Exp $ + * + * last edit-date: [Sun Mar 17 10:08:41 2002] + * + *---------------------------------------------------------------------------*/ + +#if !defined DO_I4B_DEBUG +# define DO_I4B_DEBUG 1 /* default = include debugging code */ +#elif DO_I4B_DEBUG != 0 +# undef DO_I4B_DEBUG +# define DO_I4B_DEBUG 1 +#endif + +#undef DO_I4B_MAXDEBUG /* default = disable ALL debug messages */ + +#if DO_I4B_DEBUG + +extern unsigned int i4b_l1_debug; +extern unsigned int i4b_l2_debug; +extern unsigned int i4b_l3_debug; +extern unsigned int i4b_l4_debug; + +#define NDBGL1(bits, fmt, args...) \ + if(bits & i4b_l1_debug) \ + { printf("i4b-L1 %s: " fmt "\n", __func__ , ##args ); } + +#define NDBGL2(bits, fmt, args...) \ + if(bits & i4b_l2_debug) \ + { printf("i4b-L2 %s: " fmt "\n", __func__ , ##args ); } + +#define NDBGL3(bits, fmt, args...) \ + if(bits & i4b_l3_debug) \ + { printf("i4b-L3 %s: " fmt "\n", __func__ , ##args ); } + +#define NDBGL4(bits, fmt, args...) \ + if(bits & i4b_l4_debug) \ + { printf("i4b-L4 %s: " fmt "\n", __func__ , ##args ); } + +#else /* !DO_I4B_DEBUG */ + +#define NDBGL1(bits, fmt, args...); +#define NDBGL2(bits, fmt, args...); +#define NDBGL3(bits, fmt, args...); +#define NDBGL4(bits, fmt, args...); + +#endif /* DO_I4B_DEBUG */ + +/* Layer 1 */ + +#define L1_ERROR 0x000001 /* general error message*/ +#define L1_PRIM 0x000002 /* interlayer primitives*/ +#define L1_BCHAN 0x000004 /* B channel action */ +#define L1_H_ERR 0x000008 /* HSCX errors */ +#define L1_H_IRQ 0x000010 /* HSCX IRQ messages */ +#define L1_I_ERR 0x000020 /* ISAC errors */ +#define L1_I_MSG 0x000040 /* ISAC messages */ +#define L1_I_SETUP 0x000080 /* ISAC setup messages */ +#define L1_F_MSG 0x000100 /* FSM messages */ +#define L1_F_ERR 0x000200 /* FSM error messages */ +#define L1_T_MSG 0x000400 /* Timer messages */ +#define L1_T_ERR 0x000800 /* Timer error messages */ +#define L1_H_XFRERR 0x001000 /* HSCX data xfer error */ +#define L1_I_CICO 0x002000 /* ISAC command in/out */ +#define L1_S_MSG 0x004000 /* silent messages (soft-HDLC) */ +#define L1_S_ERR 0x008000 /* error messages (soft-HDLC) */ +#define L1_HFC_DBG 0x010000 /* HFC-S PCI messages */ +#define L1_DEBUG_MAX 0x01ffef /* all messages on except IRQ! */ +#define L1_DEBUG_ERR (L1_S_ERR | L1_H_ERR | L1_I_ERR | L1_F_ERR | L1_T_ERR | L1_ERROR) + +#ifndef L1_DEBUG_DEFAULT +#ifdef DO_I4B_MAXDEBUG +#define L1_DEBUG_DEFAULT L1_DEBUG_MAX +#else +#define L1_DEBUG_DEFAULT L1_DEBUG_ERR +#endif +#endif + +/* Layer 2 */ + +#define L2_ERROR 0x0001 /* general error message */ +#define L2_PRIM 0x0002 /* interlayer primitives */ +#define L2_U_MSG 0x0004 /* U frame messages */ +#define L2_U_ERR 0x0008 /* U frame error messages */ +#define L2_S_MSG 0x0010 /* S frame messages */ +#define L2_S_ERR 0x0020 /* S frame error messages */ +#define L2_I_MSG 0x0040 /* I frame messages */ +#define L2_I_ERR 0x0080 /* I frame error messages */ +#define L2_F_MSG 0x0100 /* FSM messages */ +#define L2_F_ERR 0x0200 /* FSM error messages */ +#define L2_T_MSG 0x0400 /* timer messages */ +#define L2_T_ERR 0x0800 /* timer error messages */ +#define L2_TEI_MSG 0x1000 /* TEI messages */ +#define L2_TEI_ERR 0x2000 /* TEI error messages */ + +#define L2_DEBUG_MAX 0x3fff /* all messages on */ +#define L2_DEBUG_ERR (L2_ERROR | L2_I_ERR | L2_F_ERR | L2_T_ERR | L2_S_ERR | L2_TEI_ERR | L2_U_ERR ) + +#ifndef L2_DEBUG_DEFAULT +#ifdef DO_I4B_MAXDEBUG +#define L2_DEBUG_DEFAULT L2_DEBUG_MAX +#else +#define L2_DEBUG_DEFAULT L2_DEBUG_ERR +#endif +#endif + +/* Layer 3 */ + +#define L3_ERR 0x0001 /* general error message */ +#define L3_MSG 0x0002 /* general message */ +#define L3_F_MSG 0x0004 /* FSM messages */ +#define L3_F_ERR 0x0008 /* FSM error messages */ +#define L3_T_MSG 0x0010 /* timer messages */ +#define L3_T_ERR 0x0020 /* timer error messages */ +#define L3_P_MSG 0x0040 /* protocol messages */ +#define L3_P_ERR 0x0080 /* protocol error messages */ +#define L3_A_MSG 0x0100 /* AOC messages */ +#define L3_A_ERR 0x0200 /* AOC error messages */ +#define L3_PRIM 0x0400 /* messages exchanged */ + +#define L3_DEBUG_MAX 0x07ff /* all messages on */ +#define L3_DEBUG_ERR (L3_ERR | L3_F_ERR | L3_T_ERR | L3_P_ERR | L3_A_ERR) + +#ifndef L3_DEBUG_DEFAULT +#ifdef DO_I4B_MAXDEBUG +#define L3_DEBUG_DEFAULT L3_DEBUG_MAX +#else +#define L3_DEBUG_DEFAULT L3_DEBUG_ERR +#endif +#endif + +/* Layer 4 */ + +#define L4_ERR 0x0001 /* general error message */ +#define L4_MSG 0x0002 /* general message */ +#define L4_TIMO 0x0004 /* b channel idle timeout msgs */ +#define L4_DIALST 0x0008 /* network driver dial states */ +#define L4_IPRDBG 0x0010 /* ipr driver debug messages */ +#define L4_RBCHDBG 0x0020 /* rbch driver debug messages */ +#define L4_ISPDBG 0x0040 /* isp driver debug messages */ +#define L4_TELDBG 0x0080 /* tel driver debug messages */ +#define L4_INGDBG 0x0100 /* ing driver debug messages */ +#define L4_IAVCDBG 0x0200 /* AVM B1 driver debug messages */ +#define L4_CAPIDBG 0x0400 /* CAPI driver debug messages */ + +#define L4_DEBUG_MAX 0x0fff /* all messages on */ +#define L4_DEBUG_ERR L4_ERR + +#ifndef L4_DEBUG_DEFAULT +#ifdef DO_I4B_MAXDEBUG +#define L4_DEBUG_DEFAULT L4_DEBUG_MAX +#else +#define L4_DEBUG_DEFAULT L4_DEBUG_ERR +#endif +#endif + +/*---------------------------------------------------------------------------* + * ioctl via /dev/i4bctl: + * get/set current debug bits settings + *---------------------------------------------------------------------------*/ + +typedef struct { + unsigned int l1; + unsigned int l2; + unsigned int l3; + unsigned int l4; +} ctl_debug_t; + +#define I4B_CTL_GET_DEBUG _IOR('C', 0, ctl_debug_t) + +#define I4B_CTL_SET_DEBUG _IOW('C', 1, ctl_debug_t) + +/*---------------------------------------------------------------------------* + * generic get chipset statistics + *---------------------------------------------------------------------------*/ + +/* for the ihfc-driver: structure for HFC-1/S/SP statistics */ + +typedef struct { + int txframes; + int rxframes; + int xdu; + int rdo; + int crc; + int rab; +} hfcstat_t; + + +/* for the isic-driver: structure for HSCX statistics */ + +typedef struct { + int unit; /* controller number */ + int chan; /* channel number */ + int vfr; + int rdo; + int crc; + int rab; + int xdu; + int rfo; +} hscxstat_t; + +/* generic statistics structure */ + +struct chipstat { + int driver_type; /* type, L1DRVR_XXXX */ + int driver_unit; /* the unit number */ + int driver_bchannel; /* the B-channel */ + union stats { /* union for all drivers */ + hfcstat_t hfcstat; /* for ihfc driver, L1DRVR_IHFC */ + hscxstat_t hscxstat; /* for isic driver, L1DRVR_ISIC */ + } stats; +}; + +/* get statistics */ + +#define I4B_CTL_GET_CHIPSTAT _IOWR('C', 2, struct chipstat) + +/* clear statistics */ + +#define I4B_CTL_CLR_CHIPSTAT _IOW('C', 3, struct chipstat) + +/*---------------------------------------------------------------------------* + * get LAPD/Q.921 statistics + *---------------------------------------------------------------------------*/ +typedef struct { + + /* transmit */ + + u_long tx_i; /* I */ + u_long tx_rr; /* RR */ + u_long tx_rnr; /* RNR */ + u_long tx_rej; /* REJ */ + u_long tx_sabme; /* SABME*/ + u_long tx_dm; /* DM */ + u_long tx_disc; /* DISC */ + u_long tx_ua; /* UA */ + u_long tx_frmr; /* FRMR */ + u_long tx_tei; /* TEI */ + + /* receive */ + + u_long rx_i; /* I */ + u_long rx_rr; /* RR */ + u_long rx_rnr; /* RNR */ + u_long rx_rej; /* REJ */ + u_long rx_sabme; /* SABME*/ + u_long rx_tei; /* TEI */ + u_long rx_ui; /* UI */ + u_long rx_disc; /* DISC */ + u_long rx_xid; /* XID */ + u_long rx_dm; /* DM */ + u_long rx_ua; /* UA */ + u_long rx_frmr; /* FRMR */ + + /* errors */ + + u_long err_rx_len; /* incorrect length */ + u_long err_rx_badf; /* bad frame type */ + u_long err_rx_bads; /* bad s frame */ + u_long err_rx_badu; /* bad u frame */ + u_long err_rx_badui; /* bad ui frame */ +} lapdstat_t; + +typedef struct { + int unit; + lapdstat_t lapdstat; +} l2stat_t; + +#define I4B_CTL_GET_LAPDSTAT _IOWR('C', 4, l2stat_t) + +#define I4B_CTL_CLR_LAPDSTAT _IOW('C', 5, int) + +/* EOF */ diff --git a/src/include/machine/i4b_ioctl.h b/src/include/machine/i4b_ioctl.h new file mode 100644 index 0000000..11375a1 --- /dev/null +++ b/src/include/machine/i4b_ioctl.h @@ -0,0 +1,742 @@ +/* + * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + *--------------------------------------------------------------------------- + * + * i4b_ioctl.h - messages kernel <--> userland + * ------------------------------------------- + * + * $FreeBSD: src/sys/i386/include/i4b_ioctl.h,v 1.21 2002/08/12 07:51:57 hm Exp $ + * + * last edit-date: [Sun Aug 11 19:19:08 2002] + * + *---------------------------------------------------------------------------*/ + +#ifndef _I4B_IOCTL_H_ +#define _I4B_IOCTL_H_ + +/*---------------------------------------------------------------------------* + * version and release number for isdn4bsd package + *---------------------------------------------------------------------------*/ +#define VERSION 1 /* version number */ +#define REL 4 /* release number */ +#define STEP 0 /* release step */ + +/*---------------------------------------------------------------------------* + * date/time format in i4b log messages + * ------------------------------------ + * Being year 2000 clean is not easy with the current state of the + * ANSI C library standard and it's implementation for some locales. + * You might like to use the "%c" format of "strftime" sometimes, + * but this breaks Y2K in some locales. Also the old standard logfile + * format "%d.%m.%y %H:%M:%S" is non compliant. + * NetBSD's current toolset warns about this problems, and we compile + * with -Werror, so this problems need to be resolved. + *---------------------------------------------------------------------------*/ +#define I4B_TIME_FORMAT "%d.%m.%Y %H:%M:%S" + +/*---------------------------------------------------------------------------* + * max number of controllers in system + *---------------------------------------------------------------------------*/ +#define MAX_CONTROLLERS 8 /* max number of controllers */ + +/*---------------------------------------------------------------------------* + * ISDN D-channel protocols + *---------------------------------------------------------------------------*/ +#define PROTOCOL_DSS1 0 /* default, Euro-ISDN/DSS1 */ +#define PROTOCOL_D64S 1 /* 64k leased line, no protocol */ + +/*---------------------------------------------------------------------------* + * controller types + *---------------------------------------------------------------------------*/ +#define CTRL_INVALID (-1) /* invalid, error */ +#define CTRL_UNKNOWN 0 /* unknown controller type */ +#define CTRL_PASSIVE 1 /* passive ISDN controller cards*/ +#define CTRL_DAIC 2 /* Diehl active controller cards*/ +#define CTRL_TINADD 3 /* Stollmann Tina-dd active card*/ +#define CTRL_AVMB1 4 /* AVM B1 active card */ +#define CTRL_CAPI 5 /* cards seen via the CAPI layer*/ +#define CTRL_NUMTYPES 6 /* number of controller types */ + +/*---------------------------------------------------------------------------* + * CTRL_PASSIVE: driver types + *---------------------------------------------------------------------------*/ +#define MAXL1UNITS 8 /* max number of units */ + +#define L1DRVR_ISIC 0 /* isic - driver */ +#define L1DRVR_IWIC 1 /* iwic - driver */ +#define L1DRVR_IFPI 2 /* ifpi - driver */ +#define L1DRVR_IHFC 3 /* ihfc - driver */ +#define L1DRVR_IFPNP 4 /* ifpnp - driver */ +#define L1DRVR_ICCHP 5 /* icchp - driver */ +#define L1DRVR_ITJC 6 /* itjc - driver */ +#define L1DRVR_IFPI2 7 /* ifpi2 - driver */ + +/* MAXL1DRVR MUST be updated when more passive drivers are added !!! */ +#define MAXL1DRVR (L1DRVR_IFPI2 + 1) + +/*---------------------------------------------------------------------------* + * card types for CTRL_PASSIVE + *---------------------------------------------------------------------------*/ +#define CARD_TYPEP_INVAL (-1) /* invalid, error */ +#define CARD_TYPEP_UNK 0 /* unknown */ +#define CARD_TYPEP_8 1 /* Teles, S0/8 */ +#define CARD_TYPEP_16 2 /* Teles, S0/16 */ +#define CARD_TYPEP_16_3 3 /* Teles, S0/16.3 */ +#define CARD_TYPEP_AVMA1 4 /* AVM A1 or AVM Fritz!Card */ +#define CARD_TYPEP_163P 5 /* Teles, S0/16.3 PnP */ +#define CARD_TYPEP_CS0P 6 /* Creatix, S0 PnP */ +#define CARD_TYPEP_USRTA 7 /* US Robotics ISDN TA internal */ +#define CARD_TYPEP_DRNNGO 8 /* Dr. Neuhaus Niccy GO@ */ +#define CARD_TYPEP_SWS 9 /* Sedlbauer Win Speed */ +#define CARD_TYPEP_DYNALINK 10 /* Dynalink IS64PH */ +#define CARD_TYPEP_BLMASTER 11 /* ISDN Blaster / ISDN Master */ +#define CARD_TYPEP_PCFRITZ 12 /* AVM PCMCIA Fritz!Card */ +#define CARD_TYPEP_ELSAQS1ISA 13 /* ELSA QuickStep 1000pro ISA */ +#define CARD_TYPEP_ELSAQS1PCI 14 /* ELSA QuickStep 1000pro PCI */ +#define CARD_TYPEP_SIEMENSITALK 15 /* Siemens I-Talk */ +#define CARD_TYPEP_ELSAMLIMC 16 /* ELSA MicroLink ISDN/MC */ +#define CARD_TYPEP_ELSAMLMCALL 17 /* ELSA MicroLink MCall */ +#define CARD_TYPEP_ITKIX1 18 /* ITK ix1 micro */ +#define CARD_TYPEP_AVMA1PCI 19 /* AVM FRITZ!CARD PCI */ +#define CARD_TYPEP_PCC16 20 /* ELSA PCC-16 */ +#define CARD_TYPEP_AVM_PNP 21 /* AVM FRITZ!CARD PnP */ +#define CARD_TYPEP_SIE_ISURF2 22 /* Siemens I-Surf 2 PnP */ +#define CARD_TYPEP_ASUSCOMIPAC 23 /* Asuscom ISDNlink 128 K PnP */ +#define CARD_TYPEP_WINB6692 24 /* Winbond W6692 based */ +#define CARD_TYPEP_16_3C 25 /* Teles S0/16.3c PnP (HFC-S/SP */ +#define CARD_TYPEP_ACERP10 26 /* Acer ISDN P10 (HFC-S) */ +#define CARD_TYPEP_TELEINT_NO_1 27 /* TELEINT ISDN SPEED No. 1 (HFC-1) */ +#define CARD_TYPEP_CCD_HFCS_PCI 28 /* Cologne Chip HFC-S PCI based */ +#define CARD_TYPEP_NETJET_S 29 /* Traverse NetJet-S (Tiger300) */ +#define CARD_TYPEP_DIVA_ISA 30 /* Eicon DIVA ISA PnP 2.0 or 2.02 */ +#define CARD_TYPEP_COMPAQ_M610 31 /* Compaq Microcom 610 */ +#define CARD_TYPEP_AVMA1PCI_V2 32 /* AVM FRITZ!CARD PCI Ver. 2 */ +/* + * in case you add support for more cards, please update: + * + * isdnd: controller.c, name_of_controller() + * + * and adjust CARD_TYPEP_MAX below. + */ + +#define CARD_TYPEP_MAX 32 /* max type */ + +/*---------------------------------------------------------------------------* + * card types for CTRL_DAIC + *---------------------------------------------------------------------------*/ +#define CARD_TYPEA_DAIC_UNK 0 +#define CARD_TYPEA_DAIC_S 1 +#define CARD_TYPEA_DAIC_SX 2 +#define CARD_TYPEA_DAIC_SCOM 3 +#define CARD_TYPEA_DAIC_QUAD 4 + +/*---------------------------------------------------------------------------* + * card types for CTRL_CAPI + *---------------------------------------------------------------------------*/ +#define CARD_TYPEC_CAPI_UNK 0 +#define CARD_TYPEC_AVM_T1_PCI 1 +#define CARD_TYPEC_AVM_B1_PCI 2 +#define CARD_TYPEC_AVM_B1_ISA 3 + +/*---------------------------------------------------------------------------* + * max length of some strings + *---------------------------------------------------------------------------*/ +#define TELNO_MAX 41 /* max length of a telephone number (+ '\0') */ +#define SUBADDR_MAX 21 /* max length of a subaddress (+ '\0') */ +#define DISPLAY_MAX 91 /* max length of display information (+ '\0') */ +#define DATETIME_MAX 21 /* max length of datetime information (+ '\0')*/ +#define KEYPAD_MAX 35 /* max length of a keypad string (+ '\0') */ + +/*---------------------------------------------------------------------------* + * in case the src or dst telephone number is empty + *---------------------------------------------------------------------------*/ +#define TELNO_EMPTY "NotAvailable" + +/*---------------------------------------------------------------------------* + * B channel parameters + *---------------------------------------------------------------------------*/ +#define BCH_MAX_DATALEN 2048 /* max length of a B channel frame */ + +/*---------------------------------------------------------------------------* + * userland driver types + * --------------------- + * a "driver" is defined here as a piece of software interfacing an + * ISDN B channel with a userland service, such as IP, Telephony etc. + *---------------------------------------------------------------------------*/ +#define BDRV_RBCH 0 /* raw b-channel interface driver */ +#define BDRV_TEL 1 /* telephone (speech) interface driver */ +#define BDRV_IPR 2 /* IP over raw HDLC interface driver */ +#define BDRV_ISPPP 3 /* sync Kernel PPP interface driver */ +#define BDRV_IBC 4 /* BSD/OS point to point driver */ +#define BDRV_ING 5 /* NetGraph ing driver */ + +/*---------------------------------------------------------------------------* + * B channel protocol + *---------------------------------------------------------------------------*/ +#define BPROT_NONE 0 /* no protocol at all, raw data */ +#define BPROT_RHDLC 1 /* raw HDLC: flag, data, crc, flag */ + +/*---------------------------------------------------------------------------* + * special bearer capability settings (i.e. Data over Voice) + *---------------------------------------------------------------------------*/ +#define BCAP_NONE 0 /* no special bearer capability */ +#define BCAP_DOV 1 /* Data over Voice */ + +/*---------------------------------------------------------------------------* + * causes data type + *---------------------------------------------------------------------------*/ +typedef unsigned int cause_t; /* 32 bit unsigned int */ + +/*---------------------------------------------------------------------------* + * call descriptor id (cdid) definitions + *---------------------------------------------------------------------------*/ +#define CDID_UNUSED 0 /* cdid is invalid and unused */ +#define CDID_MAX 99999 /* highest valid cdid, wraparound to 1 */ + +/*---------------------------------------------------------------------------* + * The shorthold algorithm to use + *---------------------------------------------------------------------------*/ +#define SHA_FIXU 0 /* timeout algorithm for fix unit charging */ +#define SHA_VARU 1 /* timeout algorithm for variable unit charging */ + +/*---------------------------------------------------------------------------* + * The shorthold data struct + *---------------------------------------------------------------------------*/ +typedef struct { + int shorthold_algorithm; /* shorthold algorithm to use */ + int unitlen_time; /* length of a charging unit */ + int idle_time; /* time without activity on b ch*/ + int earlyhup_time; /* safety area at end of unit */ +} msg_shorthold_t; + + +/**************************************************************************** + + outgoing call: + -------------- + + userland kernel + -------- ------ + + CDID_REQ -----------------> + + <------------------ cdid + + CONNECT_REQ --------------> + + <------------------ PROCEEDING_IND (if connect req ok) + + <------------------ CONNECT_ACTIVE_IND (if connection ok) + + or + + <------------------ DISCONNECT_IND (if connection failed) + + + + incoming call: + -------------- + + userland kernel + -------- ------ + + <------------------ CONNECT_IND + + CONNECT_RESP -------------> + + <------------------ CONNECT_ACTIVE_IND (if accepted) + + + + active disconnect: + ------------------ + + userland kernel + -------- ------ + + DISCONNECT_REQ ------------> + + <------------------ DISCONNECT_IND + + + passive disconnect: + ------------------- + + userland kernel + -------- ------ + + <------------------ DISCONNECT_IND + + +****************************************************************************/ + + +/*===========================================================================* + *===========================================================================* + * "read" messages from kernel -> userland + *===========================================================================* + *===========================================================================*/ + + +/*---------------------------------------------------------------------------* + * message header, included in every message + *---------------------------------------------------------------------------*/ +typedef struct { + char type; /* message identifier */ +#define MSG_CONNECT_IND 'a' +#define MSG_CONNECT_ACTIVE_IND 'b' +#define MSG_DISCONNECT_IND 'c' +#define MSG_DIALOUT_IND 'd' +#define MSG_IDLE_TIMEOUT_IND 'e' +#define MSG_ACCT_IND 'f' +#define MSG_CHARGING_IND 'g' +#define MSG_PROCEEDING_IND 'h' +#define MSG_ALERT_IND 'i' +#define MSG_DRVRDISC_REQ 'j' +#define MSG_L12STAT_IND 'k' +#define MSG_TEIASG_IND 'l' +#define MSG_PDEACT_IND 'm' +#define MSG_NEGCOMP_IND 'n' +#define MSG_IFSTATE_CHANGED_IND 'o' +#define MSG_DIALOUTNUMBER_IND 'p' +#define MSG_PACKET_IND 'q' +#define MSG_KEYPAD_IND 'r' + int cdid; /* call descriptor id */ +} msg_hdr_t; + +/*---------------------------------------------------------------------------* + * connect indication + * indicates incoming connection + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int controller; /* controller number */ + int channel; /* channel number */ +#define CHAN_B1 0 /* this _must_ be 0, HSCX B1 is also 0 */ +#define CHAN_B2 1 /* this _must_ be 1, HSCX B2 is also 1 */ +#define CHAN_ANY (-1) /* outgoing, not possible for incoming */ +#define CHAN_NO (-2) /* call waiting (CW) for incoming */ + int bprot; /* b channel protocot, see BPROT_XXX */ + int bcap; /* special bearer capability, see BCAP_XXX */ + char dst_telno[TELNO_MAX]; /* destination telno */ + char dst_subaddr[SUBADDR_MAX]; /* dest subaddr */ + char src_telno[TELNO_MAX]; /* source telno */ + char src_subaddr[SUBADDR_MAX]; /* src subaddr */ + int dst_ton; /* dest. type of number */ + int src_ton; /* src. type of number */ +#define TON_OTHER 0 /* other type of number */ +#define TON_INTERNAT 1 /* international number */ +#define TON_NATIONAL 2 /* national number */ + int scr_ind;/* screening indicator */ +#define SCR_NONE 0 /* no screening indicator transmitted */ +#define SCR_USR_NOSC 1 /* screening user provided, not screened*/ +#define SCR_USR_PASS 2 /* screening user provided, verified & passed */ +#define SCR_USR_FAIL 3 /* screening user provided, verified & failed */ +#define SCR_NET 4 /* screening network provided */ + int prs_ind;/* presentation indicator */ +#define PRS_NONE 0 /* no presentation indicator transmitted*/ +#define PRS_ALLOWED 1 /* presentation allowed */ +#define PRS_RESTRICT 2 /* presentation restricted */ +#define PRS_NNINTERW 3 /* number not available due to interworking */ +#define PRS_RESERVED 4 /* reserved */ + char display[DISPLAY_MAX]; /* content of display IE*/ +} msg_connect_ind_t; + +/*---------------------------------------------------------------------------* + * connect active indication + * indicates active connection + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int controller; /* controller number actually used */ + int channel; /* channel number actually used */ + char datetime[DATETIME_MAX]; /* content of date/time IE */ +} msg_connect_active_ind_t; + +/*---------------------------------------------------------------------------* + * disconnect indication + * indicates a disconnect + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + cause_t cause; /* cause code */ +} msg_disconnect_ind_t; + +/*---------------------------------------------------------------------------* + * negotiation complete + * indicates an interface is completely up & running + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ +} msg_negcomplete_ind_t; + +/*---------------------------------------------------------------------------* + * interface changes internal state + * indicates an interface has somehow switched its FSM + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int state; /* new interface state */ +} msg_ifstatechg_ind_t; + +/*---------------------------------------------------------------------------* + * initiate a call to a remote site + * i.e. the IP driver got a packet and wants a connection + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int driver; /* driver type */ + int driver_unit; /* driver unit number */ +} msg_dialout_ind_t; + +/*---------------------------------------------------------------------------* + * dial a number + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int driver; /* driver type */ + int driver_unit; /* driver unit number */ + int cmdlen; /* length of string */ + int subaddrlen; /* length of subaddr */ + char cmd[TELNO_MAX]; /* the number to dial */ + char subaddr[SUBADDR_MAX]; /* dest subaddr */ +} msg_dialoutnumber_ind_t; + +/*---------------------------------------------------------------------------* + * send keypad string + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int driver; /* driver type */ + int driver_unit; /* driver unit number */ + int cmdlen; /* length of string */ + char cmd[KEYPAD_MAX];/* keypad string */ +} msg_keypad_ind_t; + +/*---------------------------------------------------------------------------* + * idle timeout disconnect sent indication + * kernel has sent disconnect request because of b-ch idle + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ +} msg_idle_timeout_ind_t; + +/*---------------------------------------------------------------------------* + * accounting information from userland interface driver to daemon + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int accttype; /* accounting type */ +#define ACCT_DURING 0 +#define ACCT_FINAL 1 + int driver; /* driver type */ + int driver_unit; /* driver unit number */ + int ioutbytes; /* ISDN # of bytes sent */ + int iinbytes; /* ISDN # of bytes received */ + int outbps; /* bytes per sec out */ + int inbps; /* bytes per sec in */ + int outbytes; /* driver # of bytes sent */ + int inbytes; /* driver # of bytes received */ +} msg_accounting_ind_t; + +/*---------------------------------------------------------------------------* + * charging information from isdn driver to daemon + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int units; /* number of units */ + int units_type; /* type of units info */ +#define CHARGE_INVALID 0 /* invalid, unknown */ +#define CHARGE_AOCD 1 /* advice of charge during call */ +#define CHARGE_AOCE 2 /* advice of charge at end of call */ +#define CHARGE_CALC 3 /* locally calculated from rates information */ +} msg_charging_ind_t; + +/*---------------------------------------------------------------------------* + * call proceeding indication + * indicates outgoing SETUP has been acknowleged + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int controller; /* controller number actually used */ + int channel; /* channel number actually used */ +} msg_proceeding_ind_t; + +/*---------------------------------------------------------------------------* + * alert indication + * indicates remote user side "rings" + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ +} msg_alert_ind_t; + +/*---------------------------------------------------------------------------* + * driver requests to disconnect line + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int driver; /* driver type */ + int driver_unit; /* driver unit number */ +} msg_drvrdisc_req_t; + +/*---------------------------------------------------------------------------* + * connect packet logging + *---------------------------------------------------------------------------*/ + +typedef struct { + msg_hdr_t header; /* common header */ + int driver; /* driver type */ + int driver_unit; /* driver unit number */ + int direction; /* 0=in 1=out */ +#define DIRECTION_IN 0 /* sending packet to remote */ +#define DIRECTION_OUT 1 /* received packet from remote */ +#define MAX_PACKET_LOG 40 /* space for IP and TCP header */ + u_int8_t pktdata[MAX_PACKET_LOG]; +} msg_packet_ind_t; + +/*---------------------------------------------------------------------------* + * state of layer 1/2 + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int controller; /* controller unit */ + int layer; /* layer number (1/2) */ +#define LAYER_ONE 1 +#define LAYER_TWO 2 + int state; /* state info */ +#define LAYER_IDLE 0 +#define LAYER_ACTIVE 1 +} msg_l12stat_ind_t; + +/*---------------------------------------------------------------------------* + * TEI assignment messages + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int controller; /* controller unit */ + int tei; /* TEI or -1 if invalid */ +} msg_teiasg_ind_t; + +/*---------------------------------------------------------------------------* + * persistent deactivation state of stack + *---------------------------------------------------------------------------*/ +typedef struct { + msg_hdr_t header; /* common header */ + int controller; /* controller unit */ + int numactive; /* number of active connections */ +} msg_pdeact_ind_t; + + +/*===========================================================================* + *===========================================================================* + * "ioctl" messages from userland -> kernel + *===========================================================================* + *===========================================================================*/ + +/*---------------------------------------------------------------------------* + * request a unique cdid (to setup an outgoing call) + *---------------------------------------------------------------------------*/ +typedef struct { + int cdid; /* call descriptor id */ +} msg_cdid_req_t; + +#define I4B_CDID_REQ _IOWR('4', 0, int) + +/*---------------------------------------------------------------------------* + * connect request + * requests an outgoing connection + *---------------------------------------------------------------------------*/ +typedef struct { + int cdid; /* call descriptor id */ + int controller; /* controller to use */ + int channel; /* channel to use */ + int txdelay; /* tx delay after connect */ + int bprot; /* b channel protocol */ + int bcap; /* special bearer capability */ + int driver; /* driver to route b channel data to */ + int driver_unit; /* unit number for above driver */ + msg_shorthold_t shorthold_data; /* the shorthold data */ + int unitlen_method; /* how to calculate the unitlength */ +#define ULEN_METHOD_STATIC 0 /* use unitlen_time value (see above) */ +#define ULEN_METHOD_DYNAMIC 1 /* use AOCD */ + char dst_telno[TELNO_MAX]; /* destination telephone no */ + char dst_subaddr[SUBADDR_MAX]; /* dest subaddr */ + char src_telno[TELNO_MAX]; /* source telephone number */ + char src_subaddr[SUBADDR_MAX]; /* source subaddr */ + char keypad[KEYPAD_MAX]; /* keypad string */ +} msg_connect_req_t; + +#define I4B_CONNECT_REQ _IOW('4', 1, msg_connect_req_t) + +/*---------------------------------------------------------------------------* + * connect response + * this is the answer to an incoming connect indication + *---------------------------------------------------------------------------*/ +typedef struct { + int cdid; /* call descriptor id */ + int response; /* what to do with incoming call */ +#define SETUP_RESP_DNTCRE 0 /* dont care, call is not for me */ +#define SETUP_RESP_REJECT 1 /* reject call */ +#define SETUP_RESP_ACCEPT 2 /* accept call */ + cause_t cause; /* cause for case SETUP_RESP_REJECT */ + /* the following are only used for SETUP_RESP_ACCEPT !! */ + int txdelay; /* tx delay after connect */ + int bprot; /* B chan protocol */ + int bcap; /* special bearer capability */ + int driver; /* driver to route b channel data to */ + int driver_unit; /* unit number for above driver */ + int max_idle_time; /* max time without activity on b ch */ +} msg_connect_resp_t; + +#define I4B_CONNECT_RESP _IOW('4', 2, msg_connect_resp_t) + +/*---------------------------------------------------------------------------* + * disconnect request + * active disconnect request + *---------------------------------------------------------------------------*/ +typedef struct { + int cdid; /* call descriptor id */ + cause_t cause; /* protocol independent cause */ +} msg_discon_req_t; + +#define I4B_DISCONNECT_REQ _IOW('4', 3, msg_discon_req_t) + +/*---------------------------------------------------------------------------* + * controller info request + *---------------------------------------------------------------------------*/ +typedef struct { + int controller; /* controller number */ + int ncontroller; /* number of controllers in system */ + int ctrl_type; /* controller type passive/active */ + int card_type; /* brand / version */ + int tei; /* tei controller probably has */ + int nbch; /* number of b channels provided */ +} msg_ctrl_info_req_t; + +#define I4B_CTRL_INFO_REQ _IOWR('4', 4, msg_ctrl_info_req_t) + +/*---------------------------------------------------------------------------* + * dialout response + * status report to driver who requested a dialout + *---------------------------------------------------------------------------*/ +typedef struct { + int driver; /* driver to route b channel data to */ + int driver_unit; /* unit number for above driver */ + int stat; /* state of dialout request */ +#define DSTAT_NONE 0 +#define DSTAT_TFAIL 1 /* transient failure */ +#define DSTAT_PFAIL 2 /* permanent failure */ +#define DSTAT_INONLY 3 /* no outgoing dials allowed */ + cause_t cause; /* exact i4b cause */ +} msg_dialout_resp_t; + +#define I4B_DIALOUT_RESP _IOW('4', 5, msg_dialout_resp_t) + +/*---------------------------------------------------------------------------* + * timeout value update + *---------------------------------------------------------------------------*/ +typedef struct { + int cdid; /* call descriptor id */ + msg_shorthold_t shorthold_data; +} msg_timeout_upd_t; + +#define I4B_TIMEOUT_UPD _IOW('4', 6, msg_timeout_upd_t) + +/*---------------------------------------------------------------------------* + * soft enable/disable + *---------------------------------------------------------------------------*/ +typedef struct { + int driver; /* driver to route b channel data to */ + int driver_unit; /* unit number for above driver */ + int updown; /* what to do */ +#define SOFT_ENA 0 /* enable interface */ +#define SOFT_DIS 1 /* disable interface */ +} msg_updown_ind_t; + +#define I4B_UPDOWN_IND _IOW('4', 7, msg_updown_ind_t) + +/*---------------------------------------------------------------------------* + * send alert request + *---------------------------------------------------------------------------*/ +typedef struct { + int cdid; /* call descriptor id */ +} msg_alert_req_t; + +#define I4B_ALERT_REQ _IOW('4', 8, msg_alert_req_t) + +/*---------------------------------------------------------------------------* + * request version and release info from kernel part + * (msg_vr_req_t is also used by tel & rbch drivers) + *---------------------------------------------------------------------------*/ +typedef struct { + int version; /* version number */ + int release; /* release number */ + int step; /* release step number */ +} msg_vr_req_t; + +#define I4B_VR_REQ _IOR('4', 9, msg_vr_req_t) + +/*---------------------------------------------------------------------------* + * set ISDN protocol used by a controller + *---------------------------------------------------------------------------*/ +typedef struct { + int controller; /* controller number */ + int protocol; /* ISDN D-channel protocol type */ +} msg_prot_ind_t; + +#define I4B_PROT_IND _IOW('4', 10, msg_prot_ind_t) + +/*---------------------------------------------------------------------------* + * Protocol download to active cards + *---------------------------------------------------------------------------*/ +struct isdn_dr_prot { + size_t bytecount; /* length of code */ + u_int8_t *microcode; /* pointer to microcode */ +}; + +struct isdn_download_request { + int controller; /* controller number */ + int numprotos; /* number of protocols in 'protocols' */ + struct isdn_dr_prot *protocols; +}; + +#define I4B_CTRL_DOWNLOAD _IOW('4', 100, struct isdn_download_request) + +/*---------------------------------------------------------------------------* + * Generic diagnostic interface for active cards + *---------------------------------------------------------------------------*/ +struct isdn_diagnostic_request { + int controller; /* controller number */ + u_int32_t cmd; /* diagnostic command to execute */ + size_t in_param_len; /* length of additional input parameter */ +#define I4B_ACTIVE_DIAGNOSTIC_MAXPARAMLEN 65536 + void *in_param; /* optional input parameter */ + size_t out_param_len; /* available output space */ + void *out_param; /* output data goes here */ +}; + +#define I4B_ACTIVE_DIAGNOSTIC _IOW('4', 102, struct isdn_diagnostic_request) + +#endif /* _I4B_IOCTL_H_ */ diff --git a/src/include/machine/i4b_rbch_ioctl.h b/src/include/machine/i4b_rbch_ioctl.h new file mode 100644 index 0000000..51bab05 --- /dev/null +++ b/src/include/machine/i4b_rbch_ioctl.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1999, 2002 Hellmuth Michaelis. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + *--------------------------------------------------------------------------- + * + * i4b_rbch_ioctl.h raw B-channel driver interface ioctls + * ------------------------------------------------------ + * + * $FreeBSD: src/sys/i386/include/i4b_rbch_ioctl.h,v 1.5 2002/03/17 09:33:13 hm Exp $ + * + * last edit-date: [Sun Mar 17 10:10:25 2002] + * + *---------------------------------------------------------------------------*/ + +#ifndef _I4B_RBCH_IOCTL_H_ +#define _I4B_RBCH_IOCTL_H_ + +/*---------------------------------------------------------------------------* + * instruct the rbch device to dial the given number + *---------------------------------------------------------------------------*/ + +typedef char telno_t[TELNO_MAX]; + +#define I4B_RBCH_DIALOUT _IOW('R', 1, telno_t) + +/*---------------------------------------------------------------------------* + * request version and release info from kernel part + *---------------------------------------------------------------------------*/ + +#define I4B_RBCH_VR_REQ _IOR('R', 2, msg_vr_req_t) + +#endif /* _I4B_RBCH_IOCTL_H_ */ diff --git a/src/include/machine/i4b_tel_ioctl.h b/src/include/machine/i4b_tel_ioctl.h new file mode 100644 index 0000000..6b08949 --- /dev/null +++ b/src/include/machine/i4b_tel_ioctl.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + *--------------------------------------------------------------------------- + * + * i4b_tel_ioctl.h telephony interface ioctls + * ------------------------------------------ + * + * $FreeBSD: src/sys/i386/include/i4b_tel_ioctl.h,v 1.9 2002/03/17 09:33:13 hm Exp $ + * + * last edit-date: [Sun Mar 17 10:10:39 2002] + * + *---------------------------------------------------------------------------*/ + +#ifndef _I4B_TEL_IOCTL_H_ +#define _I4B_TEL_IOCTL_H_ + +/*===========================================================================* + * /dev/i4btel devices (audio data) + *===========================================================================*/ + +/* supported audio format conversions */ + +#define CVT_NONE 0 /* no A-law/u-law conversion */ +#define CVT_ALAW2ULAW 1 /* ISDN line: A-law, user: u-law */ +#define CVT_ULAW2ALAW 2 /* ISDN line: u-law, user: A-law */ + +/*---------------------------------------------------------------------------* + * get / set audio format + *---------------------------------------------------------------------------*/ + +#define I4B_TEL_GETAUDIOFMT _IOR('A', 0, int) +#define I4B_TEL_SETAUDIOFMT _IOW('A', 1, int) +#define I4B_TEL_EMPTYINPUTQUEUE _IOW('A', 2, int) + +/*---------------------------------------------------------------------------* + * request version and release info from kernel part + *---------------------------------------------------------------------------*/ + +#define I4B_TEL_VR_REQ _IOR('A', 3, msg_vr_req_t) + +/*---------------------------------------------------------------------------* + * send tones out of the tel interface + *---------------------------------------------------------------------------*/ + +#define I4B_TEL_MAXTONES 32 + +struct i4b_tel_tones { + int frequency[I4B_TEL_MAXTONES]; + int duration[I4B_TEL_MAXTONES]; +}; + +#define I4B_TEL_TONES _IOR('A', 4, struct i4b_tel_tones) + +/*===========================================================================* + * /dev/i4bteld devices (dialer interface) + *===========================================================================*/ + +/* dialer commands */ + +#define CMD_DIAL 'D' /* dial the following number string */ +#define CMD_HUP 'H' /* hangup */ +#define CMD_KEYP 'K' /* send keypad string */ + +/* dialer responses */ + +#define RSP_CONN '0' /* connect */ +#define RSP_BUSY '1' /* busy */ +#define RSP_HUP '2' /* hangup */ +#define RSP_NOA '3' /* no answer */ + +#endif /* _I4B_TEL_IOCTL_H_ */ diff --git a/src/include/machine/i4b_trace.h b/src/include/machine/i4b_trace.h new file mode 100644 index 0000000..2f431d2 --- /dev/null +++ b/src/include/machine/i4b_trace.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 1997, 2002 Hellmuth Michaelis. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + *--------------------------------------------------------------------------- + * + * i4b_trace.h - header file for trace data read device + * ---------------------------------------------------- + * + * $FreeBSD: src/sys/i386/include/i4b_trace.h,v 1.8 2002/03/17 09:33:13 hm Exp $ + * + * last edit-date: [Sun Mar 17 10:10:52 2002] + * + *---------------------------------------------------------------------------*/ + +#ifndef _I4B_TRACE_H_ +#define _I4B_TRACE_H_ + +/*---------------------------------------------------------------------------* + * structure of the header at the beginning of every trace mbuf + *---------------------------------------------------------------------------*/ +typedef struct { + int length; /* length of the following mbuf */ + int unit; /* controller unit number */ + int type; /* type of channel */ +#define TRC_CH_I 0 /* Layer 1 INFO's */ +#define TRC_CH_D 1 /* D channel */ +#define TRC_CH_B1 2 /* B1 channel */ +#define TRC_CH_B2 3 /* B2 channel */ + int dir; /* direction */ +#define FROM_TE 0 /* user -> network */ +#define FROM_NT 1 /* network -> user */ + int trunc; /* # of truncated bytes (frame > MCLBYTES) */ + unsigned int count; /* frame count for this unit/type */ + struct timeval time; /* timestamp for this frame */ +} i4b_trace_hdr_t; + +#define INFO0 0 /* layer 1 */ +#define INFO1_8 1 +#define INFO1_10 2 +#define INFO2 3 +#define INFO3 4 +#define INFO4_8 5 +#define INFO4_10 6 + +/*---------------------------------------------------------------------------* + * ioctl via /dev/i4btrc device(s): + * get/set current trace flag settings + *---------------------------------------------------------------------------*/ + +#define I4B_TRC_SET _IOW('T', 0, int) /* set trace settings */ + +#define TRACE_OFF 0x00 /* tracing off */ +#define TRACE_I 0x01 /* trace L1 INFO's on */ +#define TRACE_D_TX 0x02 /* trace D channel on */ +#define TRACE_D_RX 0x04 /* trace D channel on */ +#define TRACE_B_TX 0x08 /* trace B channel on */ +#define TRACE_B_RX 0x10 /* trace B channel on */ + +typedef struct { + int rxunit; /* unit # for rx frames */ + int rxflags; /* d and/or b channel */ + int txunit; /* unit # for tx frames */ + int txflags; /* d and/or b channel */ +} i4b_trace_setupa_t; + +#define I4B_TRC_SETA _IOW('T', 1, i4b_trace_setupa_t) /* set analyze mode */ +#define I4B_TRC_RESETA _IOW('T', 2, int) /* reset analyze mode */ + +#endif /* _I4B_TRACE_H_ */ diff --git a/src/include/machine/ieeefp.h b/src/include/machine/ieeefp.h new file mode 100644 index 0000000..a21ae67 --- /dev/null +++ b/src/include/machine/ieeefp.h @@ -0,0 +1,181 @@ +/*- + * Copyright (c) 1990 Andrew Moore, Talke Studio + * 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. + * + * from: @(#) ieeefp.h 1.0 (Berkeley) 9/23/93 + * $FreeBSD: src/sys/i386/include/ieeefp.h,v 1.9 2004/03/12 21:45:30 trhodes Exp $ + */ + +/* + * IEEE floating point type and constant definitions. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +/* + * FP rounding modes + */ +typedef enum { + FP_RN=0, /* round to nearest */ + FP_RM, /* round down to minus infinity */ + FP_RP, /* round up to plus infinity */ + FP_RZ /* truncate */ +} fp_rnd_t; + +/* + * FP precision modes + */ +typedef enum { + FP_PS=0, /* 24 bit (single-precision) */ + FP_PRS, /* reserved */ + FP_PD, /* 53 bit (double-precision) */ + FP_PE /* 64 bit (extended-precision) */ +} fp_prec_t; + +#define fp_except_t int + +/* + * FP exception masks + */ +#define FP_X_INV 0x01 /* invalid operation */ +#define FP_X_DNML 0x02 /* denormal */ +#define FP_X_DZ 0x04 /* zero divide */ +#define FP_X_OFL 0x08 /* overflow */ +#define FP_X_UFL 0x10 /* underflow */ +#define FP_X_IMP 0x20 /* (im)precision */ +#define FP_X_STK 0x40 /* stack fault */ + +/* + * FP registers + */ +#define FP_MSKS_REG 0 /* exception masks */ +#define FP_PRC_REG 0 /* precision */ +#define FP_RND_REG 0 /* direction */ +#define FP_STKY_REG 1 /* sticky flags */ + +/* + * FP register bit field masks + */ +#define FP_MSKS_FLD 0x3f /* exception masks field */ +#define FP_PRC_FLD 0x300 /* precision control field */ +#define FP_RND_FLD 0xc00 /* round control field */ +#define FP_STKY_FLD 0x3f /* sticky flags field */ + +/* + * FP register bit field offsets + */ +#define FP_MSKS_OFF 0 /* exception masks offset */ +#define FP_PRC_OFF 8 /* precision control offset */ +#define FP_RND_OFF 10 /* round control offset */ +#define FP_STKY_OFF 0 /* sticky flags offset */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +#define __fldenv(addr) __asm __volatile("fldenv %0" : : "m" (*(addr))) +#define __fnstenv(addr) __asm __volatile("fnstenv %0" : "=m" (*(addr))) +#define __fnstcw(addr) __asm __volatile("fnstcw %0" : "=m" (*(addr))) +#define __fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) + +/* + * return the contents of a FP register + */ +static __inline__ int +__fpgetreg(int _reg) +{ + unsigned short _mem; + + /*- + * This is more efficient than it looks. The switch gets optimized + * away if _reg is constant. + * + * The default case only supports _reg == 0. We could handle more + * registers (e.g., tags) using fnstenv, but the interface doesn't + * support more. + */ + switch(_reg) { + default: + __fnstcw(&_mem); + break; + case FP_STKY_REG: + __fnstsw(&_mem); + break; + } + return _mem; +} + +/* + * set a FP mode; return previous mode + */ +static __inline__ int +__fpsetreg(int _m, int _reg, int _fld, int _off) +{ + unsigned _env[7]; + unsigned _p; + + /* + * _reg == 0 could be handled better using fnstcw/fldcw. + */ + __fnstenv(_env); + _p = (_env[_reg] & _fld) >> _off; + _env[_reg] = (_env[_reg] & ~_fld) | (_m << _off & _fld); + __fldenv(_env); + return _p; +} + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +/* + * SysV/386 FP control interface + */ +#define fpgetround() ((fp_rnd_t) \ + ((__fpgetreg(FP_RND_REG) & FP_RND_FLD) >> FP_RND_OFF)) +#define fpsetround(m) ((fp_rnd_t) \ + __fpsetreg((m), FP_RND_REG, FP_RND_FLD, FP_RND_OFF)) +#define fpgetprec() ((fp_prec_t) \ + ((__fpgetreg(FP_PRC_REG) & FP_PRC_FLD) >> FP_PRC_OFF)) +#define fpsetprec(m) ((fp_prec_t) \ + __fpsetreg((m), FP_PRC_REG, FP_PRC_FLD, FP_PRC_OFF)) +#define fpgetmask() ((fp_except_t) \ + ((~__fpgetreg(FP_MSKS_REG) & FP_MSKS_FLD) >> FP_MSKS_OFF)) +#define fpsetmask(m) ((fp_except_t) \ + (~__fpsetreg(~(m), FP_MSKS_REG, FP_MSKS_FLD, FP_MSKS_OFF)) & \ + (FP_MSKS_FLD >> FP_MSKS_OFF)) +#define fpgetsticky() ((fp_except_t) \ + ((__fpgetreg(FP_STKY_REG) & FP_STKY_FLD) >> FP_STKY_OFF)) +#define fpresetsticky(m) ((fp_except_t) \ + __fpsetreg(0, FP_STKY_REG, (m), FP_STKY_OFF)) +#define fpsetsticky(m) fpresetsticky(m) + +/* Suppress prototypes in the MI header. */ +#define _IEEEFP_INLINED_ 1 + +#endif /* !_MACHINE_IEEEFP_H_ */ diff --git a/src/include/machine/if_wl_wavelan.h b/src/include/machine/if_wl_wavelan.h new file mode 100644 index 0000000..9a79571 --- /dev/null +++ b/src/include/machine/if_wl_wavelan.h @@ -0,0 +1,167 @@ +/* $FreeBSD: src/sys/i386/include/if_wl_wavelan.h,v 1.6 2002/06/02 20:05:49 schweikh Exp $ */ +/* + * 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 all copyright + * notices, this list of conditions and the following disclaimer. + * 2. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. + * + */ +#ifndef _CHIPS_WAVELAN_H +#define _CHIPS_WAVELAN_H + +/* This file contains definitions that are common for all versions of + * the NCR WaveLAN + */ + +#define WAVELAN_ADDR_SIZE 6 /* Size of a MAC address */ +#define WAVELAN_MTU 1500 /* Maximum size of Wavelan packet */ + +/* Modem Management Controler write commands */ +#define MMC_ENCR_KEY 0x00 /* to 0x07 */ +#define MMC_ENCR_ENABLE 0x08 +#define MMC_DES_IO_INVERT 0x0a +#define MMC_LOOPT_SEL 0x10 +#define MMC_JABBER_ENABLE 0x11 +#define MMC_FREEZE 0x12 +#define MMC_ANTEN_SEL 0x13 +#define MMC_IFS 0x14 +#define MMC_MOD_DELAY 0x15 +#define MMC_JAM_TIME 0x16 +#define MMC_THR_PRE_SET 0x18 +#define MMC_DECAY_PRM 0x19 +#define MMC_DECAY_UPDAT_PRM 0x1a +#define MMC_QUALITY_THR 0x1b +#define MMC_NETW_ID_L 0x1c +#define MMC_NETW_ID_H 0x1d +#define MMC_MODE_SEL 0x1e +#define MMC_EECTRL 0x20 /* 2.4 Gz */ +#define MMC_EEADDR 0x21 /* 2.4 Gz */ +#define MMC_EEDATAL 0x22 /* 2.4 Gz */ +#define MMC_EEDATAH 0x23 /* 2.4 Gz */ +#define MMC_ANALCTRL 0x24 /* 2.4 Gz */ + +/* fields in MMC registers that relate to EEPROM in WaveMODEM daughtercard */ +#define MMC_EECTRL_EEPRE 0x10 /* 2.4 Gz EEPROM Protect Reg Enable */ +#define MMC_EECTRL_DWLD 0x08 /* 2.4 Gz EEPROM Download Synths */ +#define MMC_EECTRL_EEOP 0x07 /* 2.4 Gz EEPROM Opcode mask */ +#define MMC_EECTRL_EEOP_READ 0x06 /* 2.4 Gz EEPROM Read Opcode */ +#define MMC_EEADDR_CHAN 0xf0 /* 2.4 Gz EEPROM Channel # mask */ +#define MMC_EEADDR_WDCNT 0x0f /* 2.4 Gz EEPROM DNLD WordCount-1 */ +#define MMC_ANALCTRL_ANTPOL 0x02 /* 2.4 Gz Antenna Polarity mask */ +#define MMC_ANALCTRL_EXTANT 0x01 /* 2.4 Gz External Antenna mask */ + +/* MMC read register names */ +#define MMC_DCE_STATUS 0x10 +#define MMC_CORRECT_NWID_L 0x14 +#define MMC_CORRECT_NWID_H 0x15 +#define MMC_WRONG_NWID_L 0x16 +#define MMC_WRONG_NWID_H 0x17 +#define MMC_THR_PRE_SET 0x18 +#define MMC_SIGNAL_LVL 0x19 +#define MMC_SILENCE_LVL 0x1a +#define MMC_SIGN_QUAL 0x1b +#define MMC_DES_AVAIL 0x09 +#define MMC_EECTRLstat 0x20 /* 2.4 Gz EEPROM r/w/dwld status */ +#define MMC_EEDATALrv 0x22 /* 2.4 Gz EEPROM read value */ +#define MMC_EEDATAHrv 0x23 /* 2.4 Gz EEPROM read value */ + +/* fields in MMC registers that relate to EEPROM in WaveMODEM daughtercard */ +#define MMC_EECTRLstat_ID24 0xf0 /* 2.4 Gz =A0 rev-A, =B0 rev-B */ +#define MMC_EECTRLstat_DWLD 0x08 /* 2.4 Gz Synth/Tx-Pwr DWLD busy */ +#define MMC_EECTRLstat_EEBUSY 0x04 /* 2.4 Gz EEPROM busy */ + +/* additional socket ioctl params for wl card + * see sys/sockio.h for numbers. The 2nd params here + * must be greater than any values in sockio.h + */ + +#define SIOCGWLCNWID _IOWR('i', 60, struct ifreq) /* get wlan current nwid */ +#define SIOCSWLCNWID _IOWR('i', 61, struct ifreq) /* set wlan current nwid */ +#define SIOCGWLPSA _IOWR('i', 62, struct ifreq) /* get wlan PSA (all) */ +#define SIOCSWLPSA _IOWR('i', 63, struct ifreq) /* set wlan PSA (all) */ +#define SIOCDWLCACHE _IOW('i', 64, struct ifreq) /* clear SNR cache */ +#define SIOCSWLTHR _IOW('i', 65, struct ifreq) /* set new quality threshold */ +#define SIOCGWLEEPROM _IOWR('i', 66, struct ifreq) /* get modem EEPROM */ +#define SIOCGWLCACHE _IOWR('i', 67, struct ifreq) /* get SNR cache */ +#define SIOCGWLCITEM _IOWR('i', 68, struct ifreq) /* get cache element count */ + +/* PSA address definitions */ +#define WLPSA_ID 0x0 /* ID byte (0 for ISA, 0x14 for MCA) */ +#define WLPSA_IO1 0x1 /* I/O address 1 */ +#define WLPSA_IO2 0x2 /* I/O address 2 */ +#define WLPSA_IO3 0x3 /* I/O address 3 */ +#define WLPSA_BR1 0x4 /* Bootrom address 1 */ +#define WLPSA_BR2 0x5 /* Bootrom address 2 */ +#define WLPSA_BR3 0x6 /* Bootrom address 3 */ +#define WLPSA_HWCONF 0x7 /* HW config bits */ +#define WLPSA_IRQNO 0x8 /* IRQ value */ +#define WLPSA_UNIMAC 0x10 /* Universal MAC address */ +#define WLPSA_LOCALMAC 0x16 /* Locally configured MAC address */ +#define WLPSA_MACSEL 0x1c /* MAC selector */ +#define WLPSA_COMPATNO 0x1d /* compatibility number */ +#define WLPSA_THRESH 0x1e /* RF modem threshold preset */ +#define WLPSA_FEATSEL 0x1f /* feature select */ +#define WLPSA_SUBBAND 0x20 /* subband selector */ +#define WLPSA_QUALTHRESH 0x21 /* RF modem quality threshold preset */ +#define WLPSA_HWVERSION 0x22 /* hardware version indicator */ +#define WLPSA_NWID 0x23 /* network ID */ +#define WLPSA_NWIDENABLE 0x24 /* network ID enable */ +#define WLPSA_SECURITY 0x25 /* datalink security enable */ +#define WLPSA_DESKEY 0x26 /* datalink security DES key */ +#define WLPSA_DBWIDTH 0x2f /* databus width select */ +#define WLPSA_CALLCODE 0x30 /* call code (japan only) */ +#define WLPSA_CONFIGURED 0x3c /* configuration status */ +#define WLPSA_CRCLOW 0x3d /* CRC-16 (lowbyte) */ +#define WLPSA_CRCHIGH 0x3e /* (highbyte) */ +#define WLPSA_CRCOK 0x3f /* CRC OK flag */ + +#define WLPSA_COMPATNO_WL24B 0x04 /* 2.4 Gz WaveMODEM ISA rev-B */ + +/* + * signal strength cache + * + * driver (wlp only at the moment) keeps cache of last + * IP (only) packets to arrive including signal strength info. + * daemons may read this with kvm. See if_wlp.c for globals + * that may be accessed through kvm. + * + * Each entry in the w_sigcache has a unique macsrc and age. + * Each entry is identified by its macsrc field. + * Age of the packet is identified by its age field. + */ + +#define MAXCACHEITEMS 10 +#ifndef INT_MAX +#define INT_MAX 2147483647 +#endif +#define MAX_AGE (INT_MAX - MAXCACHEITEMS) + +/* signal is 7 bits, 0..63, although it doesn't seem to get to 63. + * silence is 7 bits, 0..63 + * quality is 4 bits, 0..15 + */ +struct w_sigcache { + char macsrc[6]; /* unique MAC address for entry */ + int ipsrc; /* ip address associated with packet */ + int signal; /* signal strength of the packet */ + int silence; /* silence of the packet */ + int quality; /* quality of the packet */ + int snr; /* packet has unique age between 1 to MAX_AGE - 1 */ +}; + +#endif /* _CHIPS_WAVELAN_H */ + diff --git a/src/include/machine/in_cksum.h b/src/include/machine/in_cksum.h new file mode 100644 index 0000000..4830963 --- /dev/null +++ b/src/include/machine/in_cksum.h @@ -0,0 +1,132 @@ +/*- + * Copyright (c) 1990 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. + * 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. + * + * from tahoe: in_cksum.c 1.2 86/01/05 + * from: @(#)in_cksum.c 1.3 (Berkeley) 1/19/91 + * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp + * $FreeBSD: src/sys/i386/include/in_cksum.h,v 1.15 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_IN_CKSUM_H_ +#define _MACHINE_IN_CKSUM_H_ 1 + +/* + * MP safe (alfred) + */ + +#include + +#define in_cksum(m, len) in_cksum_skip(m, len, 0) + +/* + * It it useful to have an Internet checksum routine which is inlineable + * and optimized specifically for the task of computing IP header checksums + * in the normal case (where there are no options and the header length is + * therefore always exactly five 32-bit words. + */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +static __inline u_int +in_cksum_hdr(const struct ip *ip) +{ + register u_int sum = 0; + +/* __volatile is necessary here because the condition codes are used. */ +#define ADD(n) __asm __volatile ("addl %1, %0" : "+r" (sum) : \ + "g" (((const u_int32_t *)ip)[n / 4])) +#define ADDC(n) __asm __volatile ("adcl %1, %0" : "+r" (sum) : \ + "g" (((const u_int32_t *)ip)[n / 4])) +#define MOP __asm __volatile ("adcl $0, %0" : "+r" (sum)) + + ADD(0); + ADDC(4); + ADDC(8); + ADDC(12); + ADDC(16); + MOP; +#undef ADD +#undef ADDC +#undef MOP + sum = (sum & 0xffff) + (sum >> 16); + if (sum > 0xffff) + sum -= 0xffff; + + return ~sum & 0xffff; +} + +static __inline void +in_cksum_update(struct ip *ip) +{ + int __tmpsum; + __tmpsum = (int)ntohs(ip->ip_sum) + 256; + ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); +} + +static __inline u_short +in_addword(u_short sum, u_short b) +{ + /* __volatile is necessary because the condition codes are used. */ + __asm __volatile ("addw %1, %0" : "+r" (sum) : "r" (b)); + __asm __volatile ("adcw $0, %0" : "+r" (sum)); + + return (sum); +} + +static __inline u_short +in_pseudo(u_int sum, u_int b, u_int c) +{ + /* __volatile is necessary because the condition codes are used. */ + __asm __volatile ("addl %1, %0" : "+r" (sum) : "g" (b)); + __asm __volatile ("adcl %1, %0" : "+r" (sum) : "g" (c)); + __asm __volatile ("adcl $0, %0" : "+r" (sum)); + + sum = (sum & 0xffff) + (sum >> 16); + if (sum > 0xffff) + sum -= 0xffff; + return (sum); +} + +#else +#define in_cksum_update(ip) \ + do { \ + int __tmpsum; \ + __tmpsum = (int)ntohs(ip->ip_sum) + 256; \ + ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \ + } while(0) + +#endif + +#ifdef _KERNEL +#if !defined(__GNUC__) || defined(__INTEL_COMPILER) +u_int in_cksum_hdr(const struct ip *ip); +u_short in_addword(u_short sum, u_short b); +u_short in_pseudo(u_int sum, u_int b, u_int c); +#endif +u_short in_cksum_skip(struct mbuf *m, int len, int skip); +#endif /* _KERNEL */ + +#endif /* _MACHINE_IN_CKSUM_H_ */ diff --git a/src/include/machine/intr_machdep.h b/src/include/machine/intr_machdep.h new file mode 100644 index 0000000..b0682da --- /dev/null +++ b/src/include/machine/intr_machdep.h @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2003 John Baldwin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/intr_machdep.h,v 1.4 2004/05/04 21:02:56 jhb Exp $ + */ + +#ifndef __MACHINE_INTR_MACHDEP_H__ +#define __MACHINE_INTR_MACHDEP_H__ + +#ifdef _KERNEL + +/* With I/O APIC's we can have up to 191 interrupts. */ +#define NUM_IO_INTS 191 +#define INTRCNT_COUNT (1 + NUM_IO_INTS * 2) + +#ifndef LOCORE + +typedef void inthand_t(u_int cs, u_int ef, u_int esp, u_int ss); + +#define IDTVEC(name) __CONCAT(X,name) + +struct intsrc; + +/* + * Methods that a PIC provides to mask/unmask a given interrupt source, + * "turn on" the interrupt on the CPU side by setting up an IDT entry, and + * return the vector associated with this source. + */ +struct pic { + void (*pic_enable_source)(struct intsrc *); + void (*pic_disable_source)(struct intsrc *); + void (*pic_eoi_source)(struct intsrc *); + void (*pic_enable_intr)(struct intsrc *); + int (*pic_vector)(struct intsrc *); + int (*pic_source_pending)(struct intsrc *); + void (*pic_suspend)(struct intsrc *); + void (*pic_resume)(struct intsrc *); + int (*pic_config_intr)(struct intsrc *, enum intr_trigger, + enum intr_polarity); +}; + +/* + * An interrupt source. The upper-layer code uses the PIC methods to + * control a given source. The lower-layer PIC drivers can store additional + * private data in a given interrupt source such as an interrupt pin number + * or an I/O APIC pointer. + */ +struct intsrc { + struct pic *is_pic; + struct ithd *is_ithread; + u_long *is_count; + u_long *is_straycount; + u_int is_index; +}; + +struct intrframe; + +extern struct mtx icu_lock; + +/* XXX: The elcr_* prototypes probably belong somewhere else. */ +int elcr_probe(void); +enum intr_trigger elcr_read_trigger(u_int irq); +void elcr_resume(void); +void elcr_write_trigger(u_int irq, enum intr_trigger trigger); +int intr_add_handler(const char *name, int vector, driver_intr_t handler, + void *arg, enum intr_type flags, void **cookiep); +int intr_config_intr(int vector, enum intr_trigger trig, + enum intr_polarity pol); +void intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe); +struct intsrc *intr_lookup_source(int vector); +int intr_register_source(struct intsrc *isrc); +int intr_remove_handler(void *cookie); +void intr_resume(void); +void intr_suspend(void); + +#endif /* !LOCORE */ +#endif /* _KERNEL */ +#endif /* !__MACHINE_INTR_MACHDEP_H__ */ diff --git a/src/include/machine/ioctl_bt848.h b/src/include/machine/ioctl_bt848.h new file mode 100644 index 0000000..d69d8de --- /dev/null +++ b/src/include/machine/ioctl_bt848.h @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2003 David O'Brien + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/ioctl_bt848.h,v 1.30 2004/03/12 21:45:30 trhodes Exp $ + */ + +#ifndef _MACHINE_IOCTL_BT848_H_ +#define _MACHINE_IOCTL_BT848_H_ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#warning Include dev/bktr/ioctl_bt848.h instead of this header. +#endif + +#include + +#endif /* _MACHINE_IOCTL_BT848_H_ */ diff --git a/src/include/machine/ioctl_ctx.h b/src/include/machine/ioctl_ctx.h new file mode 100644 index 0000000..2c6c879 --- /dev/null +++ b/src/include/machine/ioctl_ctx.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (C) 1994, Paul S. LaFollette, Jr. This software may be used, + * modified, copied, distributed, and sold, in both source and binary form + * provided that the above copyright and these terms are retained. Under + * no circumstances is the author responsible for the proper functioning + * of this software, nor does the author assume any responsibility + * for damages incurred with its use + * + * $FreeBSD: src/sys/i386/include/ioctl_ctx.h,v 1.6 1999/08/28 00:44:17 peter Exp $ + */ + +/* + * ioctl constants for Cortex-I frame grabber + */ + +#ifndef _MACHINE_IOCTL_CTX_H_ +#define _MACHINE_IOCTL_CTX_H_ + +#include + +typedef char _CTX_LUTBUF[256]; /* look up table buffer */ + +#define CTX_LIVE _IO('x', 1) /* live video */ +#define CTX_GRAB _IO('x', 2) /* frame grab */ +#define CTX_H_ORGANIZE _IO('x', 3) /* file goes across screen (horiz. read) */ +#define CTX_V_ORGANIZE _IO('x', 4) /* file goes down screen (vert. read) */ +#define CTX_SET_LUT _IOW('x', 5, _CTX_LUTBUF) /* set lookup table */ +#define CTX_GET_LUT _IOR('x', 6, _CTX_LUTBUF) /* get lookup table */ + +#endif /* !_MACHINE_IOCTL_CTX_H_ */ diff --git a/src/include/machine/ioctl_meteor.h b/src/include/machine/ioctl_meteor.h new file mode 100644 index 0000000..d8bceec --- /dev/null +++ b/src/include/machine/ioctl_meteor.h @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2003 David O'Brien + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/ioctl_meteor.h,v 1.15 2004/03/12 21:45:30 trhodes Exp $ + */ + +#ifndef _MACHINE_IOCTL_METEOR_H_ +#define _MACHINE_IOCTL_METEOR_H_ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#warning Include dev/bktr/ioctl_meteor.h instead of this header. +#endif + +#include + +#endif /* _MACHINE_IOCTL_METEOR_H_ */ diff --git a/src/include/machine/kse.h b/src/include/machine/kse.h new file mode 100644 index 0000000..a72067b --- /dev/null +++ b/src/include/machine/kse.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2002 Julian Elischer . + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD: src/sys/i386/include/kse.h,v 1.2 2002/06/29 17:26:16 julian Exp $ + */ + +#ifndef MACHINE_KSE_H +#define MACHINE_KSE_H +#ifdef _KERNEL +#include +#endif +#include + +union kse_td_ctx { +#ifdef _KERNEL + struct { + int tf_onstack; + int tf_gs; + struct trapframe tf_tf; + } tfrm; +#endif + mcontext_t mcontext; +}; + +#endif /* MACHINE_KSE_H */ diff --git a/src/include/machine/legacyvar.h b/src/include/machine/legacyvar.h new file mode 100644 index 0000000..4992da4 --- /dev/null +++ b/src/include/machine/legacyvar.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2000 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/legacyvar.h,v 1.5 2004/05/03 14:49:43 jhb Exp $ + */ + +#ifndef _MACHINE_LEGACYVAR_H_ +#define _MACHINE_LEGACYVAR_H_ + +enum legacy_device_ivars { + LEGACY_IVAR_PCIBUS +}; + +#define LEGACY_ACCESSOR(var, ivar, type) \ + __BUS_ACCESSOR(legacy, var, LEGACY, ivar, type) + +LEGACY_ACCESSOR(pcibus, PCIBUS, u_int32_t) + +#undef LEGACY_ACCESSOR + +int legacy_pcib_maxslots(device_t dev); +u_int32_t legacy_pcib_read_config(device_t dev, int bus, int slot, int func, + int reg, int bytes); +int legacy_pcib_read_ivar(device_t dev, device_t child, int which, + uintptr_t *result); +void legacy_pcib_write_config(device_t dev, int bus, int slot, int func, + int reg, u_int32_t data, int bytes); +int legacy_pcib_write_ivar(device_t dev, device_t child, int which, + uintptr_t value); + +#endif /* !_MACHINE_LEGACYVAR_H_ */ diff --git a/src/include/machine/limits.h b/src/include/machine/limits.h new file mode 100644 index 0000000..169f134 --- /dev/null +++ b/src/include/machine/limits.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 1988, 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. + * 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. + * + * @(#)limits.h 8.3 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/i386/include/limits.h,v 1.25 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#if __GNUC__ +#warning "machine/limits.h is deprecated. Include sys/limits.h instead." +#endif + +#include + +#endif /* !_MACHINE_LIMITS_H_ */ diff --git a/src/include/machine/md_var.h b/src/include/machine/md_var.h new file mode 100644 index 0000000..8680330 --- /dev/null +++ b/src/include/machine/md_var.h @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 1995 Bruce D. Evans. + * 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. Neither the name of the author nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/md_var.h,v 1.68 2004/04/11 04:26:58 alc Exp $ + */ + +#ifndef _MACHINE_MD_VAR_H_ +#define _MACHINE_MD_VAR_H_ + +/* + * Miscellaneous machine-dependent declarations. + */ + +extern void (*bcopy_vector)(const void *from, void *to, size_t len); +extern void (*bzero_vector)(void *buf, size_t len); +extern int (*copyin_vector)(const void *udaddr, void *kaddr, size_t len); +extern int (*copyout_vector)(const void *kaddr, void *udaddr, size_t len); + +extern long Maxmem; +extern u_int atdevbase; /* offset in virtual memory of ISA io mem */ +extern u_int basemem; /* PA of original top of base memory */ +extern int busdma_swi_pending; +extern u_int cpu_exthigh; +extern u_int cpu_feature; +extern u_int cpu_fxsr; +extern u_int cpu_high; +extern u_int cpu_id; +extern u_int cpu_procinfo; +extern char cpu_vendor[]; +extern u_int cyrix_did; +extern char kstack[]; +#ifdef PC98 +extern int need_pre_dma_flush; +extern int need_post_dma_flush; +#endif +extern char sigcode[]; +extern int szsigcode; +#ifdef COMPAT_FREEBSD4 +extern int szfreebsd4_sigcode; +#endif +#ifdef COMPAT_43 +extern int szosigcode; +#endif + +typedef void alias_for_inthand_t(u_int cs, u_int ef, u_int esp, u_int ss); +struct thread; +struct reg; +struct fpreg; +struct dbreg; + +void bcopyb(const void *from, void *to, size_t len); +void busdma_swi(void); +void cpu_setregs(void); +void cpu_switch_load_gs(void) __asm(__STRING(cpu_switch_load_gs)); +void doreti_iret(void) __asm(__STRING(doreti_iret)); +void doreti_iret_fault(void) __asm(__STRING(doreti_iret_fault)); +void doreti_popl_ds(void) __asm(__STRING(doreti_popl_ds)); +void doreti_popl_ds_fault(void) __asm(__STRING(doreti_popl_ds_fault)); +void doreti_popl_es(void) __asm(__STRING(doreti_popl_es)); +void doreti_popl_es_fault(void) __asm(__STRING(doreti_popl_es_fault)); +void doreti_popl_fs(void) __asm(__STRING(doreti_popl_fs)); +void doreti_popl_fs_fault(void) __asm(__STRING(doreti_popl_fs_fault)); +void enable_sse(void); +void fillw(int /*u_short*/ pat, void *base, size_t cnt); +void i486_bzero(void *buf, size_t len); +void i586_bcopy(const void *from, void *to, size_t len); +void i586_bzero(void *buf, size_t len); +int i586_copyin(const void *udaddr, void *kaddr, size_t len); +int i586_copyout(const void *kaddr, void *udaddr, size_t len); +void i686_pagezero(void *addr); +void sse2_pagezero(void *addr); +void init_AMD_Elan_sc520(void); +int is_physical_memory(vm_paddr_t addr); +int isa_nmi(int cd); +vm_paddr_t kvtop(void *addr); +void setidt(int idx, alias_for_inthand_t *func, int typ, int dpl, int selec); +int user_dbreg_trap(void); + +#endif /* !_MACHINE_MD_VAR_H_ */ diff --git a/src/include/machine/metadata.h b/src/include/machine/metadata.h new file mode 100644 index 0000000..ccad5f3 --- /dev/null +++ b/src/include/machine/metadata.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2003 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/metadata.h,v 1.1 2003/05/01 03:31:17 peter Exp $ + */ + +#ifndef _MACHINE_METADATA_H_ +#define _MACHINE_METADATA_H_ + +#define MODINFOMD_SMAP 0x1001 + +#endif /* !_MACHINE_METADATA_H_ */ diff --git a/src/include/machine/mpapic.h b/src/include/machine/mpapic.h new file mode 100644 index 0000000..f7f9d63 --- /dev/null +++ b/src/include/machine/mpapic.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1996, by Steve Passe + * 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. The name of the developer may NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/mpapic.h,v 1.17 2001/04/10 22:18:20 jhb Exp $ + */ + +#ifndef _MACHINE_MPAPIC_H_ +#define _MACHINE_MPAPIC_H_ + +/* + * Size of APIC ID list. + * Also used a MAX size of various other arrays. + */ +#define NAPICID 16 + +/* these don't really belong in here... */ +enum busTypes { + CBUS = 1, + CBUSII = 2, + EISA = 3, + MCA = 4, + ISA = 6, + PCI = 13, + XPRESS = 18, + MAX_BUSTYPE = 18, + UNKNOWN_BUSTYPE = 0xff +}; + + +/* + * the physical/logical APIC ID management macors + */ +#define CPU_TO_ID(CPU) (cpu_num_to_apic_id[CPU]) +#define ID_TO_CPU(ID) (apic_id_to_logical[ID]) +#define IO_TO_ID(IO) (io_num_to_apic_id[IO]) +#define ID_TO_IO(ID) (apic_id_to_logical[ID]) + +#endif /* _MACHINE_MPAPIC_H */ diff --git a/src/include/machine/mptable.h b/src/include/machine/mptable.h new file mode 100644 index 0000000..389ea23 --- /dev/null +++ b/src/include/machine/mptable.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 1996, by Steve Passe + * 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. The name of the developer may NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/mptable.h,v 1.221 2003/11/14 22:23:30 peter Exp $ + */ + +#ifndef __MACHINE_MPTABLE_H__ +#define __MACHINE_MPTABLE_H__ + +enum busTypes { + NOBUS = 0, + EISA = 3, + ISA = 6, + MCA = 9, + PCI = 13, + MAX_BUSTYPE = 18, + UNKNOWN_BUSTYPE = 0xff +}; + +/* MP Floating Pointer Structure */ +typedef struct MPFPS { + char signature[4]; + u_int32_t pap; + u_char length; + u_char spec_rev; + u_char checksum; + u_char config_type; + u_char mpfb2; + u_char mpfb3; + u_char mpfb4; + u_char mpfb5; +} *mpfps_t; + +#define MPFB2_IMCR_PRESENT 0x80 +#define MPFB2_MUL_CLK_SRCS 0x40 + +/* MP Configuration Table Header */ +typedef struct MPCTH { + char signature[4]; + u_short base_table_length; + u_char spec_rev; + u_char checksum; + u_char oem_id[8]; + u_char product_id[12]; + u_int32_t oem_table_pointer; + u_short oem_table_size; + u_short entry_count; + u_int32_t apic_address; + u_short extended_table_length; + u_char extended_table_checksum; + u_char reserved; +} *mpcth_t; + +#define MPCT_ENTRY_PROCESSOR 0 +#define MPCT_ENTRY_BUS 1 +#define MPCT_ENTRY_IOAPIC 2 +#define MPCT_ENTRY_INT 3 +#define MPCT_ENTRY_LOCAL_INT 4 + +typedef struct PROCENTRY { + u_char type; + u_char apic_id; + u_char apic_version; + u_char cpu_flags; + u_long cpu_signature; + u_long feature_flags; + u_long reserved1; + u_long reserved2; +} *proc_entry_ptr; + +#define PROCENTRY_FLAG_EN 0x01 +#define PROCENTRY_FLAG_BP 0x02 + +typedef struct BUSENTRY { + u_char type; + u_char bus_id; + char bus_type[6]; +} *bus_entry_ptr; + +typedef struct IOAPICENTRY { + u_char type; + u_char apic_id; + u_char apic_version; + u_char apic_flags; + u_int32_t apic_address; +} *io_apic_entry_ptr; + +#define IOAPICENTRY_FLAG_EN 0x01 + +typedef struct INTENTRY { + u_char type; + u_char int_type; + u_short int_flags; + u_char src_bus_id; + u_char src_bus_irq; + u_char dst_apic_id; + u_char dst_apic_int; +} *int_entry_ptr; + +#define INTENTRY_TYPE_INT 0 +#define INTENTRY_TYPE_NMI 1 +#define INTENTRY_TYPE_SMI 2 +#define INTENTRY_TYPE_EXTINT 3 + +#define INTENTRY_FLAGS_POLARITY 0x3 +#define INTENTRY_FLAGS_POLARITY_CONFORM 0x0 +#define INTENTRY_FLAGS_POLARITY_ACTIVEHI 0x1 +#define INTENTRY_FLAGS_POLARITY_ACTIVELO 0x3 +#define INTENTRY_FLAGS_TRIGGER 0xc +#define INTENTRY_FLAGS_TRIGGER_CONFORM 0x0 +#define INTENTRY_FLAGS_TRIGGER_EDGE 0x4 +#define INTENTRY_FLAGS_TRIGGER_LEVEL 0xc + +/* descriptions of MP basetable entries */ +typedef struct BASETABLE_ENTRY { + u_char type; + u_char length; + char name[16]; +} basetable_entry; + +int mptable_pci_probe_table(int bus); +int mptable_pci_route_interrupt(device_t pcib, device_t dev, int pin); + +#endif /* !__MACHINE_MPTABLE_H__ */ diff --git a/src/include/machine/mtpr.h b/src/include/machine/mtpr.h new file mode 100644 index 0000000..e6b2572 --- /dev/null +++ b/src/include/machine/mtpr.h @@ -0,0 +1,4 @@ +/* + * Unused in 386BSD port + * $FreeBSD: src/sys/i386/include/mtpr.h,v 1.5 1999/08/28 00:44:19 peter Exp $ + */ diff --git a/src/include/machine/mutex.h b/src/include/machine/mutex.h new file mode 100644 index 0000000..169afb6 --- /dev/null +++ b/src/include/machine/mutex.h @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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. + * + * from BSDI $Id$ + * $FreeBSD: src/sys/i386/include/mutex.h,v 1.36 2002/03/28 15:14:23 jhb Exp $ + */ + +#ifndef _MACHINE_MUTEX_H_ +#define _MACHINE_MUTEX_H_ + +#ifndef LOCORE + +#ifdef _KERNEL + +/* Global locks */ +extern struct mtx clock_lock; + +#endif /* _KERNEL */ + +#else /* !LOCORE */ + +/* + * Simple assembly macros to get and release mutexes. + * + * Note: All of these macros accept a "flags" argument and are analoguous + * to the mtx_lock_flags and mtx_unlock_flags general macros. If one + * desires to not pass a flag, the value 0 may be passed as second + * argument. + * + * XXX: We only have MTX_LOCK_SPIN and MTX_UNLOCK_SPIN for now, since that's + * all we use right now. We should add MTX_LOCK and MTX_UNLOCK (for sleep + * locks) in the near future, however. + */ +#define MTX_LOCK_SPIN(lck, flags) \ + pushl $0 ; \ + pushl $0 ; \ + pushl $flags ; \ + pushl $lck ; \ + call _mtx_lock_spin_flags ; \ + addl $0x10, %esp ; \ + +#define MTX_UNLOCK_SPIN(lck) \ + pushl $0 ; \ + pushl $0 ; \ + pushl $0 ; \ + pushl $lck ; \ + call _mtx_unlock_spin_flags ; \ + addl $0x10, %esp ; \ + +#endif /* !LOCORE */ +#endif /* __MACHINE_MUTEX_H */ diff --git a/src/include/machine/npx.h b/src/include/machine/npx.h new file mode 100644 index 0000000..aad0bd0 --- /dev/null +++ b/src/include/machine/npx.h @@ -0,0 +1,150 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)npx.h 5.3 (Berkeley) 1/18/91 + * $FreeBSD: src/sys/i386/include/npx.h,v 1.27 2004/04/07 20:46:05 imp Exp $ + */ + +/* + * 287/387 NPX Coprocessor Data Structures and Constants + * W. Jolitz 1/90 + */ + +#ifndef _MACHINE_NPX_H_ +#define _MACHINE_NPX_H_ + +/* Environment information of floating point unit */ +struct env87 { + long en_cw; /* control word (16bits) */ + long en_sw; /* status word (16bits) */ + long en_tw; /* tag word (16bits) */ + long en_fip; /* floating point instruction pointer */ + u_short en_fcs; /* floating code segment selector */ + u_short en_opcode; /* opcode last executed (11 bits ) */ + long en_foo; /* floating operand offset */ + long en_fos; /* floating operand segment selector */ +}; + +/* Contents of each floating point accumulator */ +struct fpacc87 { +#ifdef dontdef /* too unportable */ + u_long fp_mantlo; /* mantissa low (31:0) */ + u_long fp_manthi; /* mantissa high (63:32) */ + int fp_exp:15; /* exponent */ + int fp_sgn:1; /* mantissa sign */ +#else + u_char fp_bytes[10]; +#endif +}; + +/* Floating point context */ +struct save87 { + struct env87 sv_env; /* floating point control/status */ + struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ + u_char sv_pad0[4]; /* padding for (now unused) saved status word */ + /* + * Bogus padding for emulators. Emulators should use their own + * struct and arrange to store into this struct (ending here) + * before it is inspected for ptracing or for core dumps. Some + * emulators overwrite the whole struct. We have no good way of + * knowing how much padding to leave. Leave just enough for the + * GPL emulator's i387_union (176 bytes total). + */ + u_char sv_pad[64]; /* padding; used by emulators */ +}; + +struct envxmm { + u_int16_t en_cw; /* control word (16bits) */ + u_int16_t en_sw; /* status word (16bits) */ + u_int16_t en_tw; /* tag word (16bits) */ + u_int16_t en_opcode; /* opcode last executed (11 bits ) */ + u_int32_t en_fip; /* floating point instruction pointer */ + u_int16_t en_fcs; /* floating code segment selector */ + u_int16_t en_pad0; /* padding */ + u_int32_t en_foo; /* floating operand offset */ + u_int16_t en_fos; /* floating operand segment selector */ + u_int16_t en_pad1; /* padding */ + u_int32_t en_mxcsr; /* SSE sontorol/status register */ + u_int32_t en_pad2; /* padding */ +}; + +/* Contents of each SSE extended accumulator */ +struct xmmacc { + u_char xmm_bytes[16]; +}; + +struct savexmm { + struct envxmm sv_env; + struct { + struct fpacc87 fp_acc; + u_char fp_pad[6]; /* padding */ + } sv_fp[8]; + struct xmmacc sv_xmm[8]; + u_char sv_pad[224]; +} __aligned(16); + +union savefpu { + struct save87 sv_87; + struct savexmm sv_xmm; +}; + +/* + * The hardware default control word for i387's and later coprocessors is + * 0x37F, giving: + * + * round to nearest + * 64-bit precision + * all exceptions masked. + * + * We modify the affine mode bit and precision bits in this to give: + * + * affine mode for 287's (if they work at all) (1 in bitfield 1<<12) + * 53-bit precision (2 in bitfield 3<<8) + * + * 64-bit precision often gives bad results with high level languages + * because it makes the results of calculations depend on whether + * intermediate values are stored in memory or in FPU registers. + */ +#define __INITIAL_NPXCW__ 0x127F + +#ifdef _KERNEL +int npxdna(void); +void npxdrop(void); +void npxexit(struct thread *td); +int npxformat(void); +int npxgetregs(struct thread *td, union savefpu *addr); +void npxinit(u_short control); +void npxsave(union savefpu *addr); +void npxsetregs(struct thread *td, union savefpu *addr); +int npxtrap(void); +#endif + +#endif /* !_MACHINE_NPX_H_ */ diff --git a/src/include/machine/param.h b/src/include/machine/param.h new file mode 100644 index 0000000..72030a9 --- /dev/null +++ b/src/include/machine/param.h @@ -0,0 +1,142 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)param.h 5.8 (Berkeley) 6/28/91 + * $FreeBSD: src/sys/i386/include/param.h,v 1.70 2004/04/07 20:46:05 imp Exp $ + */ + +/* + * Machine dependent constants for Intel 386. + */ + +/* + * Round p (pointer or byte index) up to a correctly-aligned value + * for all data types (int, long, ...). The result is unsigned int + * and must be cast to any desired pointer type. + */ +#ifndef _ALIGNBYTES +#define _ALIGNBYTES (sizeof(int) - 1) +#endif +#ifndef _ALIGN +#define _ALIGN(p) (((unsigned)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) +#endif + +#ifndef _MACHINE +#define _MACHINE i386 +#endif +#ifndef _MACHINE_ARCH +#define _MACHINE_ARCH i386 +#endif + +#ifndef _NO_NAMESPACE_POLLUTION + +#ifndef _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#ifndef MACHINE +#define MACHINE "i386" +#endif +#ifndef MACHINE_ARCH +#define MACHINE_ARCH "i386" +#endif +#define MID_MACHINE MID_I386 + +#ifdef SMP +#define MAXCPU 16 +#else +#define MAXCPU 1 +#endif /* SMP */ + +#define ALIGNBYTES _ALIGNBYTES +#define ALIGN(p) _ALIGN(p) + +#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ +#define PAGE_SIZE (1<> PAGE_SHIFT) +#define ptoa(x) ((x) << PAGE_SHIFT) + +#define i386_btop(x) ((x) >> PAGE_SHIFT) +#define i386_ptob(x) ((x) << PAGE_SHIFT) + +#define pgtok(x) ((x) * (PAGE_SIZE / 1024)) + +#endif /* !_MACHINE_PARAM_H_ */ +#endif /* !_NO_NAMESPACE_POLLUTION */ diff --git a/src/include/machine/pcaudioio.h b/src/include/machine/pcaudioio.h new file mode 100644 index 0000000..0b4e57b --- /dev/null +++ b/src/include/machine/pcaudioio.h @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 1994 S�ren Schmidt + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/pcaudioio.h,v 1.10 1999/08/28 00:44:20 peter Exp $ + */ + +#ifndef _MACHINE_PCAUDIOIO_H_ +#define _MACHINE_PCAUDIOIO_H_ + +#include + +typedef struct audio_prinfo { + unsigned sample_rate; /* samples per second */ + unsigned channels; /* # of channels (interleaved) */ + unsigned precision; /* sample size in bits */ + unsigned encoding; /* encoding method used */ + + unsigned gain; /* volume level: 0 - 255 */ + unsigned port; /* input/output device */ + unsigned _fill1[4]; + + unsigned samples; /* samples played */ + unsigned eof; /* ?!? */ + unsigned char pause; /* !=0 pause, ==0 continue */ + unsigned char error; /* !=0 if overflow/underflow */ + unsigned char waiting; /* !=0 if others wants access */ + unsigned char _fill2[3]; + + unsigned char open; /* is device open */ + unsigned char active; /* !=0 if sound hardware is active */ +} audio_prinfo_t; + +typedef struct audio_info { + audio_prinfo_t play; + audio_prinfo_t record; + unsigned monitor_gain; + unsigned _fill[4]; +} audio_info_t; + +#define AUDIO_ENCODING_ULAW (1) /* u-law encoding */ +#define AUDIO_ENCODING_ALAW (2) /* A-law encoding */ +#define AUDIO_ENCODING_RAW (3) /* linear encoding */ + +#define AUDIO_MIN_GAIN (0) /* minimum volume value */ +#define AUDIO_MAX_GAIN (255) /* maximum volume value */ + +#define AUDIO_INITINFO(i) memset((void*)i, 0xff, sizeof(audio_info_t)) + +#define AUDIO_GETINFO _IOR('A', 1, audio_info_t) +#define AUDIO_SETINFO _IOWR('A', 2, audio_info_t) +#define AUDIO_DRAIN _IO('A', 3) +#define AUDIO_FLUSH _IO('A', 4) + +/* compatibility to /dev/audio */ +#define AUDIO_COMPAT_DRAIN _IO('P', 1) +#define AUDIO_COMPAT_FLUSH _IO('P', 0) + +#endif /* !_MACHINE_PCAUDIOIO_H_ */ diff --git a/src/include/machine/pcb.h b/src/include/machine/pcb.h new file mode 100644 index 0000000..dadd6ae --- /dev/null +++ b/src/include/machine/pcb.h @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)pcb.h 5.10 (Berkeley) 5/12/91 + * $FreeBSD: src/sys/i386/include/pcb.h,v 1.51 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _I386_PCB_H_ +#define _I386_PCB_H_ + +/* + * Intel 386 process control block + */ +#include + +struct pcb { + int pcb_cr3; + int pcb_edi; + int pcb_esi; + int pcb_ebp; + int pcb_esp; + int pcb_ebx; + int pcb_eip; + + int pcb_dr0; + int pcb_dr1; + int pcb_dr2; + int pcb_dr3; + int pcb_dr6; + int pcb_dr7; + + union savefpu pcb_save; + u_int pcb_flags; +#define FP_SOFTFP 0x01 /* process using software fltng pnt emulator */ +#define PCB_DBREGS 0x02 /* process using debug registers */ +#define PCB_NPXTRAP 0x04 /* npx trap pending */ +#define PCB_NPXINITDONE 0x08 /* fpu state is initialized */ +#define PCB_VM86CALL 0x10 /* in vm86 call */ + + caddr_t pcb_onfault; /* copyin/out fault recovery */ + int pcb_gs; + struct pcb_ext *pcb_ext; /* optional pcb extension */ + int pcb_psl; /* process status long */ + void (*pcb_switchout)(void); /* Special switchout function. */ + u_long __pcb_spare[1]; /* adjust to avoid core dump size changes */ +}; + +#ifdef _KERNEL +void savectx(struct pcb *); +#endif + +#endif /* _I386_PCB_H_ */ diff --git a/src/include/machine/pcb_ext.h b/src/include/machine/pcb_ext.h new file mode 100644 index 0000000..b5a160e --- /dev/null +++ b/src/include/machine/pcb_ext.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1997 Jonathan Lemon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/pcb_ext.h,v 1.9 2002/03/20 05:48:58 alfred Exp $ + */ + +#ifndef _I386_PCB_EXT_H_ +#define _I386_PCB_EXT_H_ + +/* + * Extension to the 386 process control block + */ +#include +#include +#include + +struct pcb_ext { + struct segment_descriptor ext_tssd; /* tss descriptor */ + struct i386tss ext_tss; /* per-process i386tss */ + caddr_t ext_iomap; /* i/o permission bitmap */ + struct vm86_kernel ext_vm86; /* vm86 area */ +}; + +#ifdef _KERNEL + +int i386_extend_pcb(struct thread *); + +#endif + +#endif /* _I386_PCB_EXT_H_ */ diff --git a/src/include/machine/pci_cfgreg.h b/src/include/machine/pci_cfgreg.h new file mode 100644 index 0000000..22ee8fe --- /dev/null +++ b/src/include/machine/pci_cfgreg.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1997, Stefan Esser + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/pci_cfgreg.h,v 1.12 2004/05/04 21:17:52 jhb Exp $ + * + */ + +#define CONF1_ADDR_PORT 0x0cf8 +#define CONF1_DATA_PORT 0x0cfc + +#define CONF1_ENABLE 0x80000000ul +#define CONF1_ENABLE_CHK 0x80000000ul +#define CONF1_ENABLE_MSK 0x7f000000ul +#define CONF1_ENABLE_CHK1 0xff000001ul +#define CONF1_ENABLE_MSK1 0x80000001ul +#define CONF1_ENABLE_RES1 0x80000000ul + +#define CONF2_ENABLE_PORT 0x0cf8 +#ifdef PC98 +#define CONF2_FORWARD_PORT 0x0cf9 +#else +#define CONF2_FORWARD_PORT 0x0cfa +#endif + +#define CONF2_ENABLE_CHK 0x0e +#define CONF2_ENABLE_RES 0x0e + +int pci_cfgregopen(void); +u_int32_t pci_cfgregread(int bus, int slot, int func, int reg, int bytes); +void pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes); +void pci_pir_open(void); +int pci_pir_probe(int bus, int require_parse); +int pci_pir_route_interrupt(int bus, int device, int func, int pin); diff --git a/src/include/machine/pcpu.h b/src/include/machine/pcpu.h new file mode 100644 index 0000000..49c971d --- /dev/null +++ b/src/include/machine/pcpu.h @@ -0,0 +1,170 @@ +/*- + * Copyright (c) Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/pcpu.h,v 1.42 2004/03/12 21:45:30 trhodes Exp $ + */ + +#ifndef _MACHINE_PCPU_H_ +#define _MACHINE_PCPU_H_ + +#ifdef _KERNEL + +#include +#include + +/* + * The SMP parts are setup in pmap.c and locore.s for the BSP, and + * mp_machdep.c sets up the data for the AP's to "see" when they awake. + * The reason for doing it via a struct is so that an array of pointers + * to each CPU's data can be set up for things like "check curproc on all + * other processors" + */ +#define PCPU_MD_FIELDS \ + struct pcpu *pc_prvspace; /* Self-reference */ \ + struct pmap *pc_curpmap; \ + struct i386tss pc_common_tss; \ + struct segment_descriptor pc_common_tssd; \ + struct segment_descriptor *pc_tss_gdt; \ + int pc_currentldt; \ + u_int pc_acpi_id; \ + u_int pc_apic_id + +#if defined(lint) + +extern struct pcpu *pcpup; + +#define PCPU_GET(member) (pcpup->pc_ ## member) +#define PCPU_PTR(member) (&pcpup->pc_ ## member) +#define PCPU_SET(member,value) (pcpup->pc_ ## member = (value)) + +#elif defined(__GNUC__) || defined (__INTEL_COMPILER) + +/* + * Evaluates to the byte offset of the per-cpu variable name. + */ +#define __pcpu_offset(name) \ + __offsetof(struct pcpu, name) + +/* + * Evaluates to the type of the per-cpu variable name. + */ +#define __pcpu_type(name) \ + __typeof(((struct pcpu *)0)->name) + +/* + * Evaluates to the address of the per-cpu variable name. + */ +#define __PCPU_PTR(name) __extension__ ({ \ + __pcpu_type(name) *__p; \ + \ + __asm __volatile("movl %%fs:%1,%0; addl %2,%0" \ + : "=r" (__p) \ + : "m" (*(struct pcpu *)(__pcpu_offset(pc_prvspace))), \ + "i" (__pcpu_offset(name))); \ + \ + __p; \ +}) + +/* + * Evaluates to the value of the per-cpu variable name. + */ +#define __PCPU_GET(name) __extension__ ({ \ + __pcpu_type(name) __result; \ + \ + if (sizeof(__result) == 1) { \ + u_char __b; \ + __asm __volatile("movb %%fs:%1,%0" \ + : "=r" (__b) \ + : "m" (*(u_char *)(__pcpu_offset(name)))); \ + __result = *(__pcpu_type(name) *)(void *)&__b; \ + } else if (sizeof(__result) == 2) { \ + u_short __w; \ + __asm __volatile("movw %%fs:%1,%0" \ + : "=r" (__w) \ + : "m" (*(u_short *)(__pcpu_offset(name)))); \ + __result = *(__pcpu_type(name) *)(void *)&__w; \ + } else if (sizeof(__result) == 4) { \ + u_int __i; \ + __asm __volatile("movl %%fs:%1,%0" \ + : "=r" (__i) \ + : "m" (*(u_int *)(__pcpu_offset(name)))); \ + __result = *(__pcpu_type(name) *)(void *)&__i; \ + } else { \ + __result = *__PCPU_PTR(name); \ + } \ + \ + __result; \ +}) + +/* + * Sets the value of the per-cpu variable name to value val. + */ +#define __PCPU_SET(name, val) { \ + __pcpu_type(name) __val = (val); \ + \ + if (sizeof(__val) == 1) { \ + u_char __b; \ + __b = *(u_char *)&__val; \ + __asm __volatile("movb %1,%%fs:%0" \ + : "=m" (*(u_char *)(__pcpu_offset(name))) \ + : "r" (__b)); \ + } else if (sizeof(__val) == 2) { \ + u_short __w; \ + __w = *(u_short *)&__val; \ + __asm __volatile("movw %1,%%fs:%0" \ + : "=m" (*(u_short *)(__pcpu_offset(name))) \ + : "r" (__w)); \ + } else if (sizeof(__val) == 4) { \ + u_int __i; \ + __i = *(u_int *)&__val; \ + __asm __volatile("movl %1,%%fs:%0" \ + : "=m" (*(u_int *)(__pcpu_offset(name))) \ + : "r" (__i)); \ + } else { \ + *__PCPU_PTR(name) = __val; \ + } \ +} + +#define PCPU_GET(member) __PCPU_GET(pc_ ## member) +#define PCPU_PTR(member) __PCPU_PTR(pc_ ## member) +#define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val) + +static __inline struct thread * +__curthread(void) +{ + struct thread *td; + + __asm __volatile("movl %%fs:0,%0" : "=r" (td)); + return (td); +} +#define curthread (__curthread()) + +#else +#error gcc or lint is required to use this file +#endif + +#endif /* _KERNEL */ + +#endif /* ! _MACHINE_PCPU_H_ */ diff --git a/src/include/machine/pcvt_ioctl.h b/src/include/machine/pcvt_ioctl.h new file mode 100644 index 0000000..6eb4b54 --- /dev/null +++ b/src/include/machine/pcvt_ioctl.h @@ -0,0 +1,536 @@ +/* + * Copyright (c) 1992, 2000 Hellmuth Michaelis + * Copyright (c) 1992, 1995 Joerg Wunsch. + * Copyright (c) 1992, 1993 Brian Dunford-Shore and Holger Veit. + * Copyright (C) 1992, 1993 Soeren Schmidt. + * All rights reserved. + * + * For the sake of compatibility, portions of this code regarding the + * X server interface are taken from Soeren Schmidt's syscons driver. + * + * This code is derived from software contributed to 386BSD by + * Holger Veit. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz and Don Ahn. + * + * 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 + * Hellmuth Michaelis, Brian Dunford-Shore, Joerg Wunsch, Holger Veit + * and Soeren Schmidt. + * 4. The name authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. + */ + +/*--------------------------------------------------------------------------- + * + * pcvt_ioctl.h ioctl's for the VT220 video driver 'pcvt' + * --------------------------------------------------------- + * + * Last Edit-Date: [Fri Mar 31 10:22:29 2000] + * + * $FreeBSD: src/sys/i386/include/pcvt_ioctl.h,v 1.16 2003/12/10 02:49:16 obrien Exp $ + * + *---------------------------------------------------------------------------*/ + +#ifndef _MACHINE_PCVT_IOCTL_H_ +#define _MACHINE_PCVT_IOCTL_H_ + +/* pcvt version information for VGAPCVTID ioctl */ + +#define PCVTIDNAME "pcvt" /* driver id - string */ +#define PCVTIDMAJOR 3 /* driver id - major release */ +#define PCVTIDMINOR 60 /* driver id - minor release */ + +#if !defined(_KERNEL) +#include +#endif +#include + +/*---------------------------------------------------------------------------* + * IOCTLs for MF II and AT Keyboards + *---------------------------------------------------------------------------*/ + +#define KBDRESET _IO('K', 1) /* reset keyboard / set defaults */ +#define KBDGTPMAT _IOR('K', 2, int) /* get current typematic value */ +#define KBDSTPMAT _IOW('K', 3, int) /* set current typematic value */ + +/* Typematic Delay Values */ + +#define KBD_TPD250 0x00 /* 250 ms */ +#define KBD_TPD500 0x20 /* 500 ms */ +#define KBD_TPD750 0x40 /* 750 ms */ +#define KBD_TPD1000 0x60 /* 1000 ms */ + +/* Typematic Repeat Rate */ + +#define KBD_TPM300 0x00 /* 30.0 char/second */ +#define KBD_TPM267 0x01 /* 26.7 char/second */ +#define KBD_TPM240 0x02 /* 24.0 char/second */ +#define KBD_TPM218 0x03 /* 21.8 char/second */ +#define KBD_TPM200 0x04 /* 20.0 char/second */ +#define KBD_TPM185 0x05 /* 18.5 char/second */ +#define KBD_TPM171 0x06 /* 17.1 char/second */ +#define KBD_TPM160 0x07 /* 16.0 char/second */ +#define KBD_TPM150 0x08 /* 15.0 char/second */ +#define KBD_TPM133 0x09 /* 13.3 char/second */ +#define KBD_TPM120 0x0A /* 12.0 char/second */ +#define KBD_TPM109 0x0B /* 10.9 char/second */ +#define KBD_TPM100 0x0C /* 10.0 char/second */ +#define KBD_TPM92 0x0D /* 9.2 char/second */ +#define KBD_TPM86 0x0E /* 8.6 char/second */ +#define KBD_TPM80 0x0F /* 8.0 char/second */ +#define KBD_TPM75 0x10 /* 7.5 char/second */ +#define KBD_TPM67 0x11 /* 6.7 char/second */ +#define KBD_TPM60 0x12 /* 6.0 char/second */ +#define KBD_TPM55 0x13 /* 5.5 char/second */ +#define KBD_TPM50 0x14 /* 5.0 char/second */ +#define KBD_TPM46 0x15 /* 4.6 char/second */ +#define KBD_TPM43 0x16 /* 4.3 char/second */ +#define KBD_TPM40 0x17 /* 4.0 char/second */ +#define KBD_TPM37 0x18 /* 3.7 char/second */ +#define KBD_TPM33 0x19 /* 3.3 char/second */ +#define KBD_TPM30 0x1A /* 3.0 char/second */ +#define KBD_TPM27 0x1B /* 2.7 char/second */ +#define KBD_TPM25 0x1C /* 2.5 char/second */ +#define KBD_TPM23 0x1D /* 2.3 char/second */ +#define KBD_TPM21 0x1E /* 2.1 char/second */ +#define KBD_TPM20 0x1F /* 2.0 char/second */ + +#define KBDGREPSW _IOR('K', 4, int) /* get key repetition switch */ +#define KBDSREPSW _IOW('K', 5, int) /* set key repetition switch */ +#define KBD_REPEATOFF 0 +#define KBD_REPEATON 1 + +#define KBDGLEDS _IOR('K', 6, int) /* get LED state */ +#define KBDSLEDS _IOW('K', 7, int) /* set LED state, does not influence */ +#define KBD_SCROLLLOCK 0x0001 /* the driver's idea of lock key state */ +#define KBD_NUMLOCK 0x0002 +#define KBD_CAPSLOCK 0x0004 +#define KBDGLOCK _IOR('K', 8, int) /* gets state of SCROLL,NUM,CAPS */ +#define KBDSLOCK _IOW('K', 9, int) /* sets state of SCROLL,NUM,CAPS + LEDs */ + +#define KBDMAXOVLKEYSIZE 15 /* + zero byte */ + +struct kbd_ovlkey /* complete definition of a key */ +{ + u_short keynum; /* the key itself */ + u_short type; /* type of key, see below */ + u_char subu; /* subtype, ignored on write */ + char unshift[KBDMAXOVLKEYSIZE+1]; /* emitted string, unshifted */ + u_char subs; /* subtype, ignored on write */ + char shift[KBDMAXOVLKEYSIZE+1]; /* emitted string, shifted */ + u_char subc; /* subtype, ignored on write */ + char ctrl[KBDMAXOVLKEYSIZE+1]; /* emitted string, control */ + u_char suba; /* subtype, ignored on write */ + char altgr[KBDMAXOVLKEYSIZE+1]; /* emitted string, altgr */ +}; + +/* Max value for keynum field */ + +#define KBDMAXKEYS 128 /* Max No. of Keys */ + +/* Values for type field */ + +#define KBD_NONE 0 /* no function, key is disabled */ +#define KBD_SHIFT 1 /* keyboard shift */ +#define KBD_META 2 /* alternate shift, sets bit8 to ASCII code */ +#define KBD_NUM 3 /* numeric shift, keypad num / appl */ +#define KBD_CTL 4 /* control code generation */ +#define KBD_CAPS 5 /* caps shift - swaps case of letter */ +#define KBD_ASCII 6 /* ascii code generating key */ +#define KBD_SCROLL 7 /* stop output */ +#define KBD_FUNC 8 /* function key */ +#define KBD_KP 9 /* keypad keys */ +#define KBD_BREAK 10 /* ignored */ +#define KBD_ALTGR 11 /* AltGr Translation feature */ +#define KBD_SHFTLOCK 12 /* shiftlock */ +#define KBD_CURSOR 13 /* cursor keys */ +#define KBD_RETURN 14 /* RETURN/ENTER keys */ + +/* Values for subtype field */ + +#define KBD_SUBT_STR 0 /* key is bound to a string */ +#define KBD_SUBT_FNC 1 /* key is bound to a function */ + + +#define KBD_OVERLOAD 0x8000 /* Key is overloaded, ignored in ioctl */ +#define KBD_MASK (~KBD_OVERLOAD) /* mask for type */ + +#define KBDGCKEY _IOWR('K',16, struct kbd_ovlkey) /* get current key values */ +#define KBDSCKEY _IOW('K',17, struct kbd_ovlkey) /* set new key assignment values*/ +#define KBDGOKEY _IOWR('K',18, struct kbd_ovlkey) /* get original key assignment values*/ + +#define KBDRMKEY _IOW('K',19, int) /* remove a key assignment */ +#define KBDDEFAULT _IO('K',20) /* remove all key assignments */ + +/*---------------------------------------------------------------------------* + * IOCTLs for Video Adapter + *---------------------------------------------------------------------------*/ + +/* Definition of PC Video Adaptor Types */ + +#define UNKNOWN_ADAPTOR 0 /* Unidentified adaptor ... */ +#define MDA_ADAPTOR 1 /* Monochrome Display Adaptor/Hercules Graphics Card */ +#define CGA_ADAPTOR 2 /* Color Graphics Adaptor */ +#define EGA_ADAPTOR 3 /* Enhanced Graphics Adaptor */ +#define VGA_ADAPTOR 4 /* Video Graphics Adaptor/Array */ + +/* Definitions of Monitor types */ + +#define MONITOR_MONO 0 /* Monochrome Monitor */ +#define MONITOR_COLOR 1 /* Color Monitor */ + +/* Types of VGA chips detectable by current driver version */ + +#define VGA_F_NONE 0 /* FAMILY NOT KNOWN */ +#define VGA_UNKNOWN 0 /* default, no 132 columns */ + +#define VGA_F_TSENG 1 /* FAMILY TSENG */ +#define VGA_ET4000 1 /* Tseng Labs ET4000 */ +#define VGA_ET3000 2 /* Tseng Labs ET3000 */ + +#define VGA_F_WD 2 /* FAMILY WD */ +#define VGA_PVGA 3 /* Western Digital Paradise VGA */ +#define VGA_WD90C00 4 /* Western Digital WD90C00 */ +#define VGA_WD90C10 5 /* Western Digital WD90C10 */ +#define VGA_WD90C11 6 /* Western Digital WD90C11 */ + +#define VGA_F_V7 3 /* FAMILY VIDEO 7 */ +#define VGA_V7VEGA 7 /* Video 7 VEGA VGA */ +#define VGA_V7FWVR 8 /* Video 7 FASTWRITE/VRAM */ +#define VGA_V7V5 9 /* Video 7 Version 5 */ +#define VGA_V71024I 10 /* Video 7 1024i */ +#define VGA_V7UNKNOWN 11 /* Video 7 unknown board .. */ + +#define VGA_F_TRI 4 /* FAMILY TRIDENT */ +#define VGA_TR8800BR 12 /* Trident TVGA 8800BR */ +#define VGA_TR8800CS 13 /* Trident TVGA 8800CS */ +#define VGA_TR8900B 14 /* Trident TVGA 8900B */ +#define VGA_TR8900C 15 /* Trident TVGA 8900C */ +#define VGA_TR8900CL 16 /* Trident TVGA 8900CL */ +#define VGA_TR9000 17 /* Trident TVGA 9000 */ +#define VGA_TR9100 18 /* Trident TVGA 9100 */ +#define VGA_TR9200 19 /* Trident TVGA 9200 */ +#define VGA_TRUNKNOWN 20 /* Trident unknown */ + +#define VGA_F_S3 5 /* FAMILY S3 */ +#define VGA_S3_911 21 /* S3 911 */ +#define VGA_S3_924 22 /* S3 924 */ +#define VGA_S3_80x 23 /* S3 801/805 */ +#define VGA_S3_928 24 /* S3 928 */ +#define VGA_S3_UNKNOWN 25 /* unknown S3 chipset */ + +#define VGA_F_CIR 6 /* FAMILY CIRRUS */ +#define VGA_CL_GD5402 26 /* Cirrus CL-GD5402 */ +#define VGA_CL_GD5402r1 27 /* Cirrus CL-GD5402r1 */ +#define VGA_CL_GD5420 28 /* Cirrus CL-GD5420 */ +#define VGA_CL_GD5420r1 29 /* Cirrus CL-GD5420r1 */ +#define VGA_CL_GD5422 30 /* Cirrus CL-GD5422 */ +#define VGA_CL_GD5424 31 /* Cirrus CL-GD5424 */ +#define VGA_CL_GD5426 32 /* Cirrus CL-GD5426 */ +#define VGA_CL_GD5428 33 /* Cirrus CL-GD5428 */ + +/*****************************************************************************/ +/* NOTE: update the 'scon' utility when adding support for more chipsets !!! */ +/*****************************************************************************/ + +/* Definitions of Vertical Screen Sizes for EGA/VGA Adaptors */ + +#define SIZ_25ROWS 0 /* VGA: 25 lines, 8x16 font */ + /* EGA: 25 lines, 8x14 font */ +#define SIZ_28ROWS 1 /* VGA: 28 lines, 8x14 font */ +#define SIZ_35ROWS 2 /* EGA: 35 lines, 8x10 font */ +#define SIZ_40ROWS 3 /* VGA: 40 lines, 8x10 font */ +#define SIZ_43ROWS 4 /* EGA: 43 lines, 8x8 font */ +#define SIZ_50ROWS 5 /* VGA: 50 lines, 8x8 font */ + +/* Definitions of Font Sizes for EGA/VGA Adaptors */ + +#define FNT_8x16 0 /* 8x16 Pixel Font, only VGA */ +#define FNT_8x14 1 /* 8x14 Pixel Font, EGA/VGA */ +#define FNT_8x10 2 /* 8x10 Pixel Font, EGA/VGA */ +#define FNT_8x8 3 /* 8x8 Pixel Font, EGA/VGA */ + +/* Definitions of Character Set (Font) Numbers */ + +#define CH_SET0 0 /* Character Set (Font) 0, EGA/VGA */ +#define CH_SET1 1 /* Character Set (Font) 1, EGA/VGA */ +#define CH_SET2 2 /* Character Set (Font) 2, EGA/VGA */ +#define CH_SET3 3 /* Character Set (Font) 3, EGA/VGA */ +#define CH_SETMAX_EGA 3 /* EGA has 4 Character Sets / Fonts */ +#define CH_SET4 4 /* Character Set (Font) 4, VGA */ +#define CH_SET5 5 /* Character Set (Font) 5, VGA */ +#define CH_SET6 6 /* Character Set (Font) 6, VGA */ +#define CH_SET7 7 /* Character Set (Font) 7, VGA */ +#define CH_SETMAX_VGA 7 /* VGA has 8 Character Sets / Fonts */ + +/* Definitions of Terminal Emulation Modes */ + +#define M_HPVT 0 /* VTxxx and HP Mode, Labels & Status Line on */ +#define M_PUREVT 1 /* only VTxxx Sequences recognized, no Labels */ + +/*---*/ + +#define VGACURSOR _IOW('V',100, struct cursorshape) /* set cursor shape */ + +struct cursorshape { + int screen_no; /* screen number for which to set, */ + /* or -1 to set on current active screen */ + int start; /* top scanline, range 0... Character Height - 1 */ + int end; /* end scanline, range 0... Character Height - 1 */ +}; + +#define VGALOADCHAR _IOW('V',101, struct vgaloadchar) /* load vga char */ + +struct vgaloadchar { + int character_set; /* VGA character set to load into */ + int character; /* Character to load */ + int character_scanlines; /* Scanlines per character */ + u_char char_table[32]; /* VGA character shape table */ +}; + +#define VGASETFONTATTR _IOW('V',102, struct vgafontattr) /* set font attr */ +#define VGAGETFONTATTR _IOWR('V',103, struct vgafontattr) /* get font attr */ + +struct vgafontattr { + int character_set; /* VGA character set */ + int font_loaded; /* Mark font loaded or unloaded */ + int screen_size; /* Character rows per screen */ + int character_scanlines; /* Scanlines per character - 1 */ + int screen_scanlines; /* Scanlines per screen - 1 byte */ +}; + +#define VGASETSCREEN _IOW('V',104, struct screeninfo) /* set screen info */ +#define VGAGETSCREEN _IOWR('V',105, struct screeninfo) /* get screen info */ + +struct screeninfo { + int adaptor_type; /* type of video adaptor installed */ + /* read only, ignored on write */ + int monitor_type; /* type of monitor (mono/color)installed*/ + /* read only, ignored on write */ + int totalfonts; /* no of downloadable fonts */ + /* read only, ignored on write */ + int totalscreens; /* no of virtual screens */ + /* read only, ignored on write */ + int screen_no; /* screen number, this was got from */ + /* on write, if -1, apply pure_vt_mode */ + /* and/or screen_size to current screen */ + /* else to screen_no supplied */ + int current_screen; /* screen number, which is displayed. */ + /* on write, if -1, make this screen */ + /* the current screen, else set current */ + /* displayed screen to parameter */ + int pure_vt_mode; /* flag, pure VT mode or HP/VT mode */ + /* on write, if -1, no change */ + int screen_size; /* screen size */ + /* on write, if -1, no change */ + int force_24lines; /* force 24 lines if 25 lines VT mode */ + /* or 28 lines HP mode to get pure */ + /* VT220 screen size */ + /* on write, if -1, no change */ + int vga_family; /* if adaptor_type = VGA, this reflects */ + /* the chipset family after a read */ + /* nothing happens on write ... */ + int vga_type; /* if adaptor_type = VGA, this reflects */ + /* the chipset after a read */ + /* nothing happens on write ... */ + int vga_132; /* set to 1 if driver has support for */ + /* 132 column operation for chipset */ + /* currently ignored on write */ +}; + +#define VGAREADPEL _IOWR('V', 110, struct vgapel) /*r VGA palette entry */ +#define VGAWRITEPEL _IOW('V', 111, struct vgapel) /*w VGA palette entry */ + +struct vgapel { + unsigned idx; /* index into palette, 0 .. 255 valid */ + unsigned r, g, b; /* RGB values, masked by VGA_PMASK (63) */ +}; + +/* NOTE: The next ioctl is only valid if option PCVT_SCREENSAVER is configured*/ +/* this is *not* restricted to VGA's, but won't introduce new garbage... */ + +#define VGASCREENSAVER _IOW('V', 112, int) /* set timeout for screen */ + /* saver in seconds; 0 turns */ + /* it off */ + +#define VGAPCVTID _IOWR('V',113, struct pcvtid) /* get driver id */ + +struct pcvtid { /* THIS STRUCTURE IS NOW FROZEN !!! */ +#define PCVTIDNAMELN 16 /* driver id - string length */ + char name[PCVTIDNAMELN]; /* driver name, == PCVTIDSTR */ + int rmajor; /* revision number, major */ + int rminor; /* revision number, minor */ +}; /* END OF COLD PART ... */ + +#define VGAPCVTINFO _IOWR('V',114, struct pcvtinfo) /* get driver info */ + +struct pcvtinfo { /* compile time option values */ + u_int nscreens; /* PCVT_NSCREENS */ + u_int scanset; /* PCVT_SCANSET */ + u_int updatefast; /* PCVT_UPDATEFAST */ + u_int updateslow; /* PCVT_UPDATESLOW */ + u_int sysbeepf; /* PCVT_SYSBEEPF */ + u_int pcburst; /* PCVT_PCBURST */ + u_int kbd_fifo_sz; /* PCVT_KBD_FIFO_SZ */ + +/* config booleans */ + + u_long compile_opts; /* PCVT_xxxxxxxxxxxxxxx */ + +#define CONF_VT220KEYB 0x00000001 +#define CONF_SCREENSAVER 0x00000002 +#define CONF_PRETTYSCRNS 0x00000004 +#define CONF_CTRL_ALT_DEL 0x00000008 +#define CONF_USEKBDSEC 0x00000010 +#define CONF_24LINESDEF 0x00000020 +#define CONF_SHOWKEYS 0x00000040 +#define CONF_NULLCHARS 0x00000080 +#define CONF_SETCOLOR 0x00000100 +#define CONF_132GENERIC 0x00000200 +#define CONF_XSERVER 0x00000400 +#define CONF_INHIBIT_NUMLOCK 0x00000800 +#define CONF_META_ESC 0x00001000 +#define CONF_SLOW_INTERRUPT 0x00002000 +#define CONF_NO_LED_UPDATE 0x00004000 +#define CONF_GREENSAVER 0x00008000 +}; + +#define VGASETCOLMS _IOW('V', 115, int) /* set number of columns (80/132)*/ + +/* + * start of USL VT compatibility stuff (in case XSERVER defined) + * these definitions must match those ones used by syscons + * + * Note that some of the ioctl command definitions below break the Berkeley + * style. They accept a parameter of type "int" (instead of Berkeley style + * "int *") in order to pass a single integer to the ioctl. These macros + * below are marked with a dummy "int" comment. Dont blame anyone else + * than USL for that braindeadness. It is done here to be a bit source- + * level compatible to SysV. (N.B., within the ioctl, the argument is + * dereferenced by "int *" anyway. The translation is done by the upper- + * level ioctl stuff.) + */ + +/* + * NB: Some of the definitions below apparently override the definitions + * in the KBD section above. But, due to BSDs encoding of the IO direction + * and transfer size, the resulting ioctl cmds differ, so we can take them + * here. The only real conflict would appear if we implemented KDGKBMODE, + * which would be identical to KBDGLEDS above. Since this command is not + * necessary for XFree86 2.0, we omit it. + */ + +/* #define KDGKBMODE _IOR('K', 6, int) */ /* not yet implemented */ + +#define KDSKBMODE _IO('K', 7 /*, int */) +#define K_RAW 0 /* keyboard returns scancodes */ +#define K_XLATE 1 /* keyboard returns ascii */ + +#define KDMKTONE _IO('K', 8 /*, int */) + +/* #define KDGETMODE _IOR('K', 9, int) */ /* not yet implemented */ + +#define KDSETMODE _IO('K', 10 /*, int */) +#define KD_TEXT 0 /* set text mode restore fonts */ +#define KD_GRAPHICS 1 /* set graphics mode */ + +/* we cannot see any sense to support KD_TEXT0 or KD_TEXT1 */ + +#define KDENABIO _IO('K', 60) /* only allowed if euid == 0 */ +#define KDDISABIO _IO('K', 61) + +#define KDGETLED _IOR('K', 65, int) +#define KDSETLED _IO('K', 66 /*, int */) +#define LED_CAP 1 +#define LED_NUM 2 +#define LED_SCR 4 + +#define KDSETRAD _IO('K', 67 /*, int */) + +/* + * Note that since our idea of key mapping is much different from the + * SysV style, we _only_ support mapping layers base (0), shifted (1), + * alt (4), and alt-shift (5), and only for the basic keys (without + * any function keys). This is what XFree86 2.0+ needs to establish + * the default X keysym mapping. + */ +#define GIO_KEYMAP _IOR('k', 6, keymap_t) + +#define VT_OPENQRY _IOR('v', 1, int) +#define VT_SETMODE _IOW('v', 2, vtmode_t) +#define VT_GETMODE _IOR('v', 3, vtmode_t) + +#define VT_RELDISP _IO('v', 4 /*, int */) + +/* acceptable values for the VT_RELDISP command */ + +#define VT_FALSE 0 /* release of VT refused */ +#define VT_TRUE 1 /* VT released */ +#define VT_ACKACQ 2 /* acknowledging VT acquisition */ + + +#define VT_ACTIVATE _IO('v', 5 /*, int */) +#define VT_WAITACTIVE _IO('v', 6 /*, int */) +#define VT_GETACTIVE _IOR('v', 7, int) + +#ifndef _VT_MODE_DECLARED +#define _VT_MODE_DECLARED +struct vt_mode { + char mode; + +#define VT_AUTO 0 /* switching controlled by drvr */ +#define VT_PROCESS 1 /* switching controlled by prog */ + + char waitv; /* not implemented yet SOS */ + short relsig; + short acqsig; + short frsig; /* not implemented yet SOS */ +}; + +typedef struct vt_mode vtmode_t; +#endif /* !_VT_MODE_DECLARED */ + +#define NUM_KEYS 256 +#define NUM_STATES 8 + +#ifndef _KEYMAP_DECLARED +#define _KEYMAP_DECLARED +struct keyent_t { + u_char map[NUM_STATES]; + u_char spcl; + u_char flgs; +}; + +struct keymap { + u_short n_keys; + struct keyent_t key[NUM_KEYS]; +}; + +typedef struct keymap keymap_t; +#endif /* !_KEYMAP_DECLARED */ + +/* end of USL VT compatibility stuff */ + +#endif /* !_MACHINE_PCVT_IOCTL_H_ */ diff --git a/src/include/machine/pecoff_machdep.h b/src/include/machine/pecoff_machdep.h new file mode 100644 index 0000000..d1056a5 --- /dev/null +++ b/src/include/machine/pecoff_machdep.h @@ -0,0 +1,60 @@ +/* $NetBSD: pecoff_machdep.h,v 1.5 2000/01/10 03:03:54 matt Exp $ */ +/* $FreeBSD: src/sys/i386/include/pecoff_machdep.h,v 1.1 2000/12/20 12:50:50 takawata Exp $ */ +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef _I386_PECOFF_MACHDEP_H_ +#define _I386_PECOFF_MACHDEP_H_ + +#define COFF_MAGIC_I386 0x14c +#define COFF_BADMAG(ex) (ex->f_magic != COFF_MAGIC_I386) + +#endif /* !_I386_PECOFF_MACHDEP_H_ */ + + + + + + + + + + + + + + + diff --git a/src/include/machine/perfmon.h b/src/include/machine/perfmon.h new file mode 100644 index 0000000..014de4b --- /dev/null +++ b/src/include/machine/perfmon.h @@ -0,0 +1,255 @@ +/* + * Copyright 1996 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + * + * $FreeBSD: src/sys/i386/include/perfmon.h,v 1.8 2002/03/20 05:48:58 alfred Exp $ + */ + +/* + * Interface to performance-monitoring counters for Intel Pentium and + * Pentium Pro CPUs. + */ + +#ifndef _MACHINE_PERFMON_H_ +#define _MACHINE_PERFMON_H_ + +#ifndef _KERNEL +#include +#endif +#include + +#define NPMC 2 + +#define PMIOSETUP _IOW('5', 1, struct pmc) +#define PMIOGET _IOWR('5', 7, struct pmc) +#define PMIOSTART _IOW('5', 2, int) +#define PMIOSTOP _IOW('5', 3, int) +#define PMIOREAD _IOWR('5', 4, struct pmc_data) +#define PMIORESET _IOW('5', 5, int) +#define PMIOTSTAMP _IOR('5', 6, struct pmc_tstamp) + +struct pmc { + int pmc_num; + union { + struct { + unsigned char pmcus_event; + unsigned char pmcus_unit; + unsigned char pmcus_flags; + unsigned char pmcus_mask; + } pmcu_s; + unsigned int pmcu_val; + } pmc_pmcu; +}; + +#define PMC_ALL (-1) + +#define pmc_event pmc_pmcu.pmcu_s.pmcus_event +#define pmc_unit pmc_pmcu.pmcu_s.pmcus_unit +#define pmc_flags pmc_pmcu.pmcu_s.pmcus_flags +#define pmc_mask pmc_pmcu.pmcu_s.pmcus_mask +#define pmc_val pmc_pmcu.pmcu_val + +#define PMCF_USR 0x01 /* count events in user mode */ +#define PMCF_OS 0x02 /* count events in kernel mode */ +#define PMCF_E 0x04 /* use edge-detection mode */ +#define PMCF_PC 0x08 /* PMx output pin control */ +#define PMCF_INT 0x10 /* APIC interrupt enable (do not use) */ +#define PMCF_EN 0x40 /* enable counters */ +#define PMCF_INV 0x80 /* invert counter mask comparison */ + +#define PMCF_SYS_FLAGS (PMCF_INT | PMCF_EN) /* user cannot set */ + +struct pmc_data { + int pmcd_num; + quad_t pmcd_value; +}; + +struct pmc_tstamp { + int pmct_rate; + quad_t pmct_value; +}; + +#ifndef _KERNEL + +#define _PATH_PERFMON "/dev/perfmon" + +#else + +/* + * Intra-kernel interface to performance monitoring counters + */ +void perfmon_init(void); +int perfmon_avail(void); +int perfmon_setup(int, unsigned int); +int perfmon_get(int, unsigned int *); +int perfmon_fini(int); +int perfmon_start(int); +int perfmon_stop(int); +int perfmon_read(int, quad_t *); +int perfmon_reset(int); + +#endif /* _KERNEL */ + +/* + * Pentium Pro performance counters, from Appendix B. + */ +/* Data Cache Unit */ +#define PMC6_DATA_MEM_REFS 0x43 +#define PMC6_DCU_LINES_IN 0x45 +#define PMC6_DCU_M_LINES_IN 0x46 +#define PMC6_DCU_M_LINES_OUT 0x47 +#define PMC6_DCU_MISS_OUTSTANDING 0x48 + +/* Instruction Fetch Unit */ +#define PMC6_IFU_IFETCH 0x80 +#define PMC6_IFU_IFETCH_MISS 0x81 +#define PMC6_ITLB_MISS 0x85 +#define PMC6_IFU_MEM_STALL 0x86 +#define PMC6_ILD_STALL 0x87 + +/* L2 Cache */ +#define PMC6_L2_IFETCH 0x28 /* MESI */ +#define PMC6_L2_LD 0x29 /* MESI */ +#define PMC6_L2_ST 0x2a /* MESI */ +#define PMC6_L2_LINES_IN 0x24 +#define PMC6_L2_LINES_OUT 0x26 +#define PMC6_L2_M_LINES_INM 0x25 +#define PMC6_L2_M_LINES_OUTM 0x27 +#define PMC6_L2_RQSTS 0x2e /* MESI */ +#define PMC6_L2_ADS 0x21 +#define PMC6_L2_DBUS_BUSY 0x22 +#define PMC6_L2_DBUS_BUSY_RD 0x23 + +/* External Bus Logic */ +#define PMC6_BUS_DRDY_CLOCKS 0x62 +#define PMC6_BUS_LOCK_CLOCKS 0x63 +#define PMC6_BUS_REQ_OUTSTANDING 0x60 +#define PMC6_BUS_TRAN_BRD 0x65 +#define PMC6_BUS_TRAN_RFO 0x66 +#define PMC6_BUS_TRAN_WB 0x67 +#define PMC6_BUS_TRAN_IFETCH 0x68 +#define PMC6_BUS_TRAN_INVAL 0x69 +#define PMC6_BUS_TRAN_PWR 0x6a +#define PMC6_BUS_TRAN_P 0x6b +#define PMC6_BUS_TRAN_IO 0x6c +#define PMC6_BUS_TRAN_DEF 0x6d +#define PMC6_BUS_TRAN_BURST 0x6e +#define PMC6_BUS_TRAN_ANY 0x70 +#define PMC6_BUS_TRAN_MEM 0x6f +#define PMC6_BUS_DATA_RCV 0x64 +#define PMC6_BUS_BNR_DRV 0x61 +#define PMC6_BUS_HIT_DRV 0x7a +#define PMC6_BUS_HITM_DRV 0x7b +#define PMC6_BUS_SNOOP_STALL 0x7e + +/* Floating Point Unit */ +#define PMC6_FLOPS 0xc1 /* counter 0 only */ +#define PMC6_FP_COMP_OPS_EXE 0x10 /* counter 0 only */ +#define PMC6_FP_ASSIST 0x11 /* counter 1 only */ +#define PMC6_MUL 0x12 /* counter 1 only */ +#define PMC6_DIV 0x13 /* counter 1 only */ +#define PMC6_CYCLES_DIV_BUSY 0x14 /* counter 0 only */ + +/* Memory Ordering */ +#define PMC6_LD_BLOCKS 0x03 +#define PMC6_SB_DRAINS 0x04 +#define PMC6_MISALIGN_MEM_REF 0x05 + +/* Instruction Decoding and Retirement */ +#define PMC6_INST_RETIRED 0xc0 +#define PMC6_UOPS_RETIRED 0xc2 +#define PMC6_INST_DECODER 0xd0 /* (sic) */ + +/* Interrupts */ +#define PMC6_HW_INT_RX 0xc8 +#define PMC6_CYCLES_INT_MASKED 0xc6 +#define PMC6_CYCLES_INT_PENDING_AND_MASKED 0xc7 + +/* Branches */ +#define PMC6_BR_INST_RETIRED 0xc4 +#define PMC6_BR_MISS_PRED_RETIRED 0xc5 +#define PMC6_BR_TAKEN_RETIRED 0xc9 +#define PMC6_BR_MISS_PRED_TAKEN_RET 0xca +#define PMC6_BR_INST_DECODED 0xe0 +#define PMC6_BTB_MISSES 0xe2 +#define PMC6_BR_BOGUS 0xe4 +#define PMC6_BACLEARS 0xe6 + +/* Stalls */ +#define PMC6_RESOURCE_STALLS 0xa2 +#define PMC6_PARTIAL_RAT_STALLS 0xd2 + +/* Segment Register Loads */ +#define PMC6_SEGMENT_REG_LOADS 0x06 + +/* Clocks */ +#define PMC6_CPU_CLK_UNHALTED 0x79 + +/* + * Pentium Performance Counters + * This list comes from the Harvard people, not Intel. + */ +#define PMC5_DATA_READ 0 +#define PMC5_DATA_WRITE 1 +#define PMC5_DATA_TLB_MISS 2 +#define PMC5_DATA_READ_MISS 3 +#define PMC5_DATA_WRITE_MISS 4 +#define PMC5_WRITE_M_E 5 +#define PMC5_DATA_LINES_WBACK 6 +#define PMC5_DATA_CACHE_SNOOP 7 +#define PMC5_DATA_CACHE_SNOOP_HIT 8 +#define PMC5_MEM_ACCESS_BOTH 9 +#define PMC5_BANK_CONFLICTS 10 +#define PMC5_MISALIGNED_DATA 11 +#define PMC5_INST_READ 12 +#define PMC5_INST_TLB_MISS 13 +#define PMC5_INST_CACHE_MISS 14 +#define PMC5_SEGMENT_REG_LOAD 15 +#define PMC5_BRANCHES 18 +#define PMC5_BTB_HITS 19 +#define PMC5_BRANCH_TAKEN 20 +#define PMC5_PIPELINE_FLUSH 21 +#define PMC5_INST_EXECUTED 22 +#define PMC5_INST_EXECUTED_V 23 +#define PMC5_BUS_UTILIZATION 24 +#define PMC5_WRITE_BACKUP_STALL 25 +#define PMC5_DATA_READ_STALL 26 +#define PMC5_WRITE_E_M_STALL 27 +#define PMC5_LOCKED_BUS 28 +#define PMC5_IO_CYCLE 29 +#define PMC5_NONCACHE_MEMORY 30 +#define PMC5_ADDR_GEN_INTERLOCK 31 +#define PMC5_FLOPS 34 +#define PMC5_BP0_MATCH 35 +#define PMC5_BP1_MATCH 36 +#define PMC5_BP2_MATCH 37 +#define PMC5_BP3_MATCH 38 +#define PMC5_HW_INTR 39 +#define PMC5_DATA_RW 40 +#define PMC5_DATA_RW_MISS 41 + +#endif /* !_MACHINE_PERFMON_H_ */ diff --git a/src/include/machine/physio_proc.h b/src/include/machine/physio_proc.h new file mode 100644 index 0000000..28e7598 --- /dev/null +++ b/src/include/machine/physio_proc.h @@ -0,0 +1,57 @@ +/* $FreeBSD: src/sys/i386/include/physio_proc.h,v 1.5 2003/04/01 09:02:58 phk Exp $ */ +/* $NecBSD: physio_proc.h,v 3.4 1999/07/23 20:47:03 honda Exp $ */ +/* $NetBSD$ */ + +/* + * [NetBSD for NEC PC-98 series] + * Copyright (c) 1998 + * NetBSD/pc98 porting staff. 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ +#ifndef _I386_PHYSIO_PROC_H_ +#define _I386_PHYSIO_PROC_H_ +#include + +struct buf; + +struct physio_proc { +}; + +static __inline struct physio_proc *physio_proc_enter(struct buf *); +static __inline void physio_proc_leave(struct physio_proc *); + +static __inline struct physio_proc * +physio_proc_enter(bp) + struct buf *bp; +{ + return NULL; +} + +static __inline void +physio_proc_leave(pp) + struct physio_proc *pp; +{ +} +#endif /* _I386_PHYSIO_PROC_H_ */ diff --git a/src/include/machine/pmap.h b/src/include/machine/pmap.h new file mode 100644 index 0000000..eb46fcd --- /dev/null +++ b/src/include/machine/pmap.h @@ -0,0 +1,347 @@ +/* + * Copyright (c) 1991 Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and William Jolitz of UUNET Technologies Inc. + * + * 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. + * 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. + * + * Derived from hp300 version by Mike Hibler, this version by William + * Jolitz uses a recursive map [a pde points to the page directory] to + * map the page tables using the pagetables themselves. This is done to + * reduce the impact on kernel virtual memory for lots of sparse address + * space, and to reduce the cost of memory to each process. + * + * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 + * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 + * $FreeBSD: src/sys/i386/include/pmap.h,v 1.108 2004/04/10 23:28:49 alc Exp $ + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +/* + * Page-directory and page-table entires follow this format, with a few + * of the fields not present here and there, depending on a lot of things. + */ + /* ---- Intel Nomenclature ---- */ +#define PG_V 0x001 /* P Valid */ +#define PG_RW 0x002 /* R/W Read/Write */ +#define PG_U 0x004 /* U/S User/Supervisor */ +#define PG_NC_PWT 0x008 /* PWT Write through */ +#define PG_NC_PCD 0x010 /* PCD Cache disable */ +#define PG_A 0x020 /* A Accessed */ +#define PG_M 0x040 /* D Dirty */ +#define PG_PS 0x080 /* PS Page size (0=4k,1=4M) */ +#define PG_G 0x100 /* G Global */ +#define PG_AVAIL1 0x200 /* / Available for system */ +#define PG_AVAIL2 0x400 /* < programmers use */ +#define PG_AVAIL3 0x800 /* \ */ + + +/* Our various interpretations of the above */ +#define PG_W PG_AVAIL1 /* "Wired" pseudoflag */ +#define PG_MANAGED PG_AVAIL2 +#define PG_FRAME (~((vm_paddr_t)PAGE_MASK)) +#define PG_PROT (PG_RW|PG_U) /* all protection bits . */ +#define PG_N (PG_NC_PWT|PG_NC_PCD) /* Non-cacheable */ + +/* + * Page Protection Exception bits + */ + +#define PGEX_P 0x01 /* Protection violation vs. not present */ +#define PGEX_W 0x02 /* during a Write cycle */ +#define PGEX_U 0x04 /* access from User mode (UPL) */ + +/* + * Size of Kernel address space. This is the number of page table pages + * (4MB each) to use for the kernel. 256 pages == 1 Gigabyte. + * This **MUST** be a multiple of 4 (eg: 252, 256, 260, etc). + */ +#ifndef KVA_PAGES +#ifdef PAE +#define KVA_PAGES 512 +#else +#define KVA_PAGES 256 +#endif +#endif + +/* + * Pte related macros + */ +#define VADDR(pdi, pti) ((vm_offset_t)(((pdi)< 0xffbfffff + */ +#ifdef SMP +#define MPPTDI (NPDEPTD-1) /* per cpu ptd entry */ +#define KPTDI (MPPTDI-NKPDE) /* start of kernel virtual pde's */ +#else +#define KPTDI (NPDEPTD-NKPDE)/* start of kernel virtual pde's */ +#endif /* SMP */ +#define PTDPTDI (KPTDI-NPGPTD) /* ptd entry that points to ptd! */ + +/* + * XXX doesn't really belong here I guess... + */ +#define ISA_HOLE_START 0xa0000 +#define ISA_HOLE_LENGTH (0x100000-ISA_HOLE_START) + +#ifndef LOCORE + +#include + +#ifdef PAE + +typedef uint64_t pdpt_entry_t; +typedef uint64_t pd_entry_t; +typedef uint64_t pt_entry_t; + +#define PTESHIFT (3) +#define PDESHIFT (3) + +#else + +typedef uint32_t pd_entry_t; +typedef uint32_t pt_entry_t; + +#define PTESHIFT (2) +#define PDESHIFT (2) + +#endif + +/* + * Address of current and alternate address space page table maps + * and directories. + */ +#ifdef _KERNEL +extern pt_entry_t PTmap[]; +extern pd_entry_t PTD[]; +extern pd_entry_t PTDpde[]; + +#ifdef PAE +extern pdpt_entry_t *IdlePDPT; +#endif +extern pd_entry_t *IdlePTD; /* physical address of "Idle" state directory */ +#endif + +#ifdef _KERNEL +/* + * virtual address to page table entry and + * to physical address. Likewise for alternate address space. + * Note: these work recursively, thus vtopte of a pte will give + * the corresponding pde that in turn maps it. + */ +#define vtopte(va) (PTmap + i386_btop(va)) + +/* + * Routine: pmap_kextract + * Function: + * Extract the physical page address associated + * kernel virtual address. + */ +static __inline vm_paddr_t +pmap_kextract(vm_offset_t va) +{ + vm_paddr_t pa; + + if ((pa = PTD[va >> PDRSHIFT]) & PG_PS) { + pa = (pa & ~(NBPDR - 1)) | (va & (NBPDR - 1)); + } else { + pa = *vtopte(va); + pa = (pa & PG_FRAME) | (va & PAGE_MASK); + } + return pa; +} + +#define vtophys(va) pmap_kextract(((vm_offset_t) (va))) + +#ifdef PAE + +static __inline pt_entry_t +pte_load(pt_entry_t *ptep) +{ + pt_entry_t r; + + __asm __volatile( + "lock; cmpxchg8b %1" + : "=A" (r) + : "m" (*ptep), "a" (0), "d" (0), "b" (0), "c" (0)); + return (r); +} + +static __inline pt_entry_t +pte_load_store(pt_entry_t *ptep, pt_entry_t v) +{ + pt_entry_t r; + + r = *ptep; + __asm __volatile( + "1:\n" + "\tlock; cmpxchg8b %1\n" + "\tjnz 1b" + : "+A" (r) + : "m" (*ptep), "b" ((uint32_t)v), "c" ((uint32_t)(v >> 32))); + return (r); +} + +#define pte_load_clear(ptep) pte_load_store((ptep), (pt_entry_t)0ULL) + +#else /* PAE */ + +static __inline pt_entry_t +pte_load(pt_entry_t *ptep) +{ + pt_entry_t r; + + r = *ptep; + return (r); +} + +static __inline pt_entry_t +pte_load_store(pt_entry_t *ptep, pt_entry_t pte) +{ + pt_entry_t r; + + r = *ptep; + *ptep = pte; + return (r); +} + +#define pte_load_clear(pte) atomic_readandclear_int(pte) + +#endif /* PAE */ + +#define pte_clear(ptep) pte_load_store((ptep), (pt_entry_t)0ULL) +#define pte_store(ptep, pte) pte_load_store((ptep), (pt_entry_t)pte) + +#define pde_store(pdep, pde) pte_store((pdep), (pde)) + +#endif /* _KERNEL */ + +/* + * Pmap stuff + */ +struct pv_entry; + +struct md_page { + int pv_list_count; + TAILQ_HEAD(,pv_entry) pv_list; +}; + +struct pmap { + pd_entry_t *pm_pdir; /* KVA of page directory */ + TAILQ_HEAD(,pv_entry) pm_pvlist; /* list of mappings in pmap */ + u_int pm_active; /* active on cpus */ + struct pmap_statistics pm_stats; /* pmap statistics */ + LIST_ENTRY(pmap) pm_list; /* List of all pmaps */ +#ifdef PAE + pdpt_entry_t *pm_pdpt; /* KVA of page director pointer + table */ +#endif +}; + +#define pmap_page_is_mapped(m) (!TAILQ_EMPTY(&(m)->md.pv_list)) + +typedef struct pmap *pmap_t; + +#ifdef _KERNEL +extern struct pmap kernel_pmap_store; +#define kernel_pmap (&kernel_pmap_store) +#endif + +/* + * For each vm_page_t, there is a list of all currently valid virtual + * mappings of that page. An entry is a pv_entry_t, the list is pv_table. + */ +typedef struct pv_entry { + pmap_t pv_pmap; /* pmap where mapping lies */ + vm_offset_t pv_va; /* virtual address for mapping */ + TAILQ_ENTRY(pv_entry) pv_list; + TAILQ_ENTRY(pv_entry) pv_plist; + vm_page_t pv_ptem; /* VM page for pte */ +} *pv_entry_t; + +#ifdef _KERNEL + +#define NPPROVMTRR 8 +#define PPRO_VMTRRphysBase0 0x200 +#define PPRO_VMTRRphysMask0 0x201 +struct ppro_vmtrr { + u_int64_t base, mask; +}; +extern struct ppro_vmtrr PPro_vmtrr[NPPROVMTRR]; + +extern caddr_t CADDR1; +extern pt_entry_t *CMAP1; +extern vm_paddr_t avail_end; +extern vm_paddr_t phys_avail[]; +extern int pseflag; +extern int pgeflag; +extern char *ptvmmap; /* poor name! */ +extern vm_offset_t virtual_avail; +extern vm_offset_t virtual_end; + +void pmap_bootstrap(vm_paddr_t, vm_paddr_t); +void pmap_kenter(vm_offset_t va, vm_paddr_t pa); +void *pmap_kenter_temporary(vm_paddr_t pa, int i); +void pmap_kremove(vm_offset_t); +void *pmap_mapdev(vm_paddr_t, vm_size_t); +void pmap_unmapdev(vm_offset_t, vm_size_t); +pt_entry_t *pmap_pte(pmap_t, vm_offset_t) __pure2; +void pmap_set_pg(void); +void pmap_invalidate_page(pmap_t, vm_offset_t); +void pmap_invalidate_range(pmap_t, vm_offset_t, vm_offset_t); +void pmap_invalidate_all(pmap_t); + +#endif /* _KERNEL */ + +#endif /* !LOCORE */ + +#endif /* !_MACHINE_PMAP_H_ */ diff --git a/src/include/machine/privatespace.h b/src/include/machine/privatespace.h new file mode 100644 index 0000000..26b8d0d --- /dev/null +++ b/src/include/machine/privatespace.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/privatespace.h,v 1.3 2001/12/11 23:33:40 jhb Exp $ + */ + +#ifndef _MACHINE_PRIVATESPACE_H_ +#define _MACHINE_PRIVATESPACE_H_ + +/* + * This is the upper (0xff800000) address space layout that is per-cpu. + * It is setup in locore.s and pmap.c for the BSP and in mp_machdep.c for + * each AP. This is only applicable to the x86 SMP kernel. + */ +struct privatespace { + /* page 0 - data page */ + struct pcpu pcpu; + char __filler0[PAGE_SIZE - sizeof(struct pcpu)]; + + /* page 1 - idle stack (KSTACK_PAGES pages) */ + char idlekstack[KSTACK_PAGES * PAGE_SIZE]; + /* page 1+KSTACK_PAGES... */ +}; + +extern struct privatespace SMP_prvspace[]; + +#endif /* ! _MACHINE_PRIVATESPACE_H_ */ diff --git a/src/include/machine/proc.h b/src/include/machine/proc.h new file mode 100644 index 0000000..cc6af0f --- /dev/null +++ b/src/include/machine/proc.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1991 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. + * 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. + * + * from: @(#)proc.h 7.1 (Berkeley) 5/15/91 + * $FreeBSD: src/sys/i386/include/proc.h,v 1.21 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_PROC_H_ +#define _MACHINE_PROC_H_ + +#include + +struct proc_ldt { + caddr_t ldt_base; + int ldt_len; + int ldt_refcnt; + u_long ldt_active; + struct segment_descriptor ldt_sd; +}; + +/* + * Machine-dependent part of the proc structure for i386. + */ +struct mdthread { + register_t md_savecrit; +}; + +struct mdproc { + struct proc_ldt *md_ldt; /* (j) per-process ldt */ +}; + +#ifdef _KERNEL + +void set_user_ldt(struct mdproc *); +struct proc_ldt *user_ldt_alloc(struct mdproc *, int); +void user_ldt_free(struct thread *); + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_PROC_H_ */ diff --git a/src/include/machine/profile.h b/src/include/machine/profile.h new file mode 100644 index 0000000..9b60f4e --- /dev/null +++ b/src/include/machine/profile.h @@ -0,0 +1,164 @@ +/* + * Copyright (c) 1992, 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. + * 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. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD: src/sys/i386/include/profile.h,v 1.34 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_PROFILE_H_ +#define _MACHINE_PROFILE_H_ + +#ifdef _KERNEL + +/* + * Config generates something to tell the compiler to align functions on 16 + * byte boundaries. A strict alignment is good for keeping the tables small. + */ +#define FUNCTION_ALIGNMENT 16 + +/* + * The kernel uses assembler stubs instead of unportable inlines. + * This is mainly to save a little time when profiling is not enabled, + * which is the usual case for the kernel. + */ +#define _MCOUNT_DECL void mcount +#define MCOUNT + +#ifdef GUPROF +#define CALIB_SCALE 1000 +#define KCOUNT(p,index) ((p)->kcount[(index) \ + / (HISTFRACTION * sizeof(HISTCOUNTER))]) +#define MCOUNT_DECL(s) +#define MCOUNT_ENTER(s) +#define MCOUNT_EXIT(s) +#define PC_TO_I(p, pc) ((uintfptr_t)(pc) - (uintfptr_t)(p)->lowpc) +#else +#define MCOUNT_DECL(s) u_long s; +#ifdef SMP +extern int mcount_lock; +#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); \ + while (!atomic_cmpset_acq_int(&mcount_lock, 0, 1)) \ + /* nothing */ ; } +#define MCOUNT_EXIT(s) { atomic_store_rel_int(&mcount_lock, 0); \ + write_eflags(s); } +#else +#define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); } +#define MCOUNT_EXIT(s) (write_eflags(s)) +#endif +#endif /* GUPROF */ + +#else /* !_KERNEL */ + +#define FUNCTION_ALIGNMENT 4 + +#define _MCOUNT_DECL static __inline void _mcount + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#define MCOUNT \ +void \ +mcount() \ +{ \ + uintfptr_t selfpc, frompc; \ + /* \ + * Find the return address for mcount, \ + * and the return address for mcount's caller. \ + * \ + * selfpc = pc pushed by call to mcount \ + */ \ + __asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \ + /* \ + * frompc = pc pushed by call to mcount's caller. \ + * The caller's stack frame has already been built, so %ebp is \ + * the caller's frame pointer. The caller's raddr is in the \ + * caller's frame following the caller's caller's frame pointer.\ + */ \ + __asm("movl (%%ebp),%0" : "=r" (frompc)); \ + frompc = ((uintfptr_t *)frompc)[1]; \ + _mcount(frompc, selfpc); \ +} +#else /* !(__GNUC__ || __INTEL_COMPILER) */ +#define MCOUNT \ +void \ +mcount() \ +{ \ +} +#endif /* __GNUC__ || __INTEL_COMPILER */ + +typedef unsigned int uintfptr_t; + +#endif /* _KERNEL */ + +/* + * An unsigned integral type that can hold non-negative difference between + * function pointers. + */ +typedef u_int fptrdiff_t; + +#ifdef _KERNEL + +void mcount(uintfptr_t frompc, uintfptr_t selfpc); +void kmupetext(uintfptr_t nhighpc); + +#ifdef GUPROF +struct gmonparam; + +void nullfunc_loop_profiled(void); +void nullfunc_profiled(void); +void startguprof(struct gmonparam *p); +void stopguprof(struct gmonparam *p); +#else +#define startguprof(p) +#define stopguprof(p) +#endif /* GUPROF */ + +#else /* !_KERNEL */ + +#include + +__BEGIN_DECLS +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +void mcount(void) __asm(".mcount"); +#endif +__END_DECLS + +#endif /* _KERNEL */ + +#ifdef GUPROF +/* XXX doesn't quite work outside kernel yet. */ +extern int cputime_bias; + +__BEGIN_DECLS +int cputime(void); +void empty_loop(void); +void mexitcount(uintfptr_t selfpc); +void nullfunc(void); +void nullfunc_loop(void); +__END_DECLS +#endif + +#endif /* !_MACHINE_PROFILE_H_ */ diff --git a/src/include/machine/psl.h b/src/include/machine/psl.h new file mode 100644 index 0000000..427102b --- /dev/null +++ b/src/include/machine/psl.h @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)psl.h 5.2 (Berkeley) 1/18/91 + * $FreeBSD: src/sys/i386/include/psl.h,v 1.12 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * 386 processor status longword. + */ +#define PSL_C 0x00000001 /* carry bit */ +#define PSL_PF 0x00000004 /* parity bit */ +#define PSL_AF 0x00000010 /* bcd carry bit */ +#define PSL_Z 0x00000040 /* zero bit */ +#define PSL_N 0x00000080 /* negative bit */ +#define PSL_T 0x00000100 /* trace enable bit */ +#define PSL_I 0x00000200 /* interrupt enable bit */ +#define PSL_D 0x00000400 /* string instruction direction bit */ +#define PSL_V 0x00000800 /* overflow bit */ +#define PSL_IOPL 0x00003000 /* i/o privilege level */ +#define PSL_NT 0x00004000 /* nested task bit */ +#define PSL_RF 0x00010000 /* resume flag bit */ +#define PSL_VM 0x00020000 /* virtual 8086 mode bit */ +#define PSL_AC 0x00040000 /* alignment checking */ +#define PSL_VIF 0x00080000 /* virtual interrupt enable */ +#define PSL_VIP 0x00100000 /* virtual interrupt pending */ +#define PSL_ID 0x00200000 /* identification bit */ + +/* + * The i486 manual says that we are not supposed to change reserved flags, + * but this is too much trouble since the reserved flags depend on the cpu + * and setting them to their historical values works in practice. + */ +#define PSL_RESERVED_DEFAULT 0x00000002 + +/* + * Initial flags for kernel and user mode. The kernel later inherits + * PSL_I and some other flags from user mode. + */ +#define PSL_KERNEL PSL_RESERVED_DEFAULT +#define PSL_USER (PSL_RESERVED_DEFAULT | PSL_I) + +/* + * Bits that can be changed in user mode on 486's. We allow these bits + * to be changed using ptrace(), sigreturn() and procfs. Setting PS_NT + * is undesirable but it may as well be allowed since users can inflict + * it on the kernel directly. Changes to PSL_AC are silently ignored on + * 386's. + */ +#define PSL_USERCHANGE (PSL_C | PSL_PF | PSL_AF | PSL_Z | PSL_N | PSL_T \ + | PSL_D | PSL_V | PSL_NT | PSL_AC | PSL_ID) + +#endif /* !_MACHINE_PSL_H_ */ diff --git a/src/include/machine/ptrace.h b/src/include/machine/ptrace.h new file mode 100644 index 0000000..5ba508e --- /dev/null +++ b/src/include/machine/ptrace.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1992, 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. + * 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. + * + * @(#)ptrace.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD: src/sys/i386/include/ptrace.h,v 1.12 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_PTRACE_H_ +#define _MACHINE_PTRACE_H_ + +#endif diff --git a/src/include/machine/reg.h b/src/include/machine/reg.h new file mode 100644 index 0000000..590554c --- /dev/null +++ b/src/include/machine/reg.h @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)reg.h 5.5 (Berkeley) 1/18/91 + * $FreeBSD: src/sys/i386/include/reg.h,v 1.30 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +/* + * Indices for registers in `struct trapframe' and `struct regs'. + * + * This interface is deprecated. In the kernel, it is only used in FPU + * emulators to convert from register numbers encoded in instructions to + * register values. Everything else just accesses the relevant struct + * members. In userland, debuggers tend to abuse this interface since + * they don't understand that `struct regs' is a struct. I hope they have + * stopped accessing the registers in the trap frame via PT_{READ,WRITE}_U + * and we can stop supporting the user area soon. + */ +#define tFS (0) +#define tES (1) +#define tDS (2) +#define tEDI (3) +#define tESI (4) +#define tEBP (5) +#define tISP (6) +#define tEBX (7) +#define tEDX (8) +#define tECX (9) +#define tEAX (10) +#define tERR (12) +#define tEIP (13) +#define tCS (14) +#define tEFLAGS (15) +#define tESP (16) +#define tSS (17) + +/* + * Indices for registers in `struct regs' only. + * + * Some registers live in the pcb and are only in an "array" with the + * other registers in application interfaces that copy all the registers + * to or from a `struct regs'. + */ +#define tGS (18) + +/* + * Register set accessible via /proc/$pid/regs and PT_{SET,GET}REGS. + */ +struct reg { + unsigned int r_fs; + unsigned int r_es; + unsigned int r_ds; + unsigned int r_edi; + unsigned int r_esi; + unsigned int r_ebp; + unsigned int r_isp; + unsigned int r_ebx; + unsigned int r_edx; + unsigned int r_ecx; + unsigned int r_eax; + unsigned int r_trapno; + unsigned int r_err; + unsigned int r_eip; + unsigned int r_cs; + unsigned int r_eflags; + unsigned int r_esp; + unsigned int r_ss; + unsigned int r_gs; +}; + +/* + * Register set accessible via /proc/$pid/fpregs. + */ +struct fpreg { + /* + * XXX should get struct from npx.h. Here we give a slightly + * simplified struct. This may be too much detail. Perhaps + * an array of unsigned longs is best. + */ + unsigned long fpr_env[7]; + unsigned char fpr_acc[8][10]; + unsigned long fpr_ex_sw; + unsigned char fpr_pad[64]; +}; + +/* + * Register set accessible via /proc/$pid/dbregs. + */ +struct dbreg { + unsigned int dr[8]; /* debug registers */ + /* Index 0-3: debug address registers */ + /* Index 4-5: reserved */ + /* Index 6: debug status */ + /* Index 7: debug control */ +}; + +#define DBREG_DR7_EXEC 0x00 /* break on execute */ +#define DBREG_DR7_WRONLY 0x01 /* break on write */ +#define DBREG_DR7_RDWR 0x03 /* break on read or write */ +#define DBREG_DRX(d,x) ((d)->dr[(x)]) /* reference dr0 - dr7 by + register number */ + + +#ifdef _KERNEL +/* + * XXX these interfaces are MI, so they should be declared in a MI place. + */ +int fill_regs(struct thread *, struct reg *); +int set_regs(struct thread *, struct reg *); +int fill_fpregs(struct thread *, struct fpreg *); +int set_fpregs(struct thread *, struct fpreg *); +int fill_dbregs(struct thread *, struct dbreg *); +int set_dbregs(struct thread *, struct dbreg *); +#endif + +#endif /* !_MACHINE_REG_H_ */ diff --git a/src/include/machine/reloc.h b/src/include/machine/reloc.h new file mode 100644 index 0000000..942c956 --- /dev/null +++ b/src/include/machine/reloc.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 1992, 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. + * 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. + * + * @(#)reloc.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD: src/sys/i386/include/reloc.h,v 1.8 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _I386_MACHINE_RELOC_H_ +#define _I386_MACHINE_RELOC_H_ + +/* Relocation format. */ +struct relocation_info { + int r_address; /* offset in text or data segment */ + unsigned int r_symbolnum : 24, /* ordinal number of add symbol */ + r_pcrel : 1, /* 1 if value should be pc-relative */ + r_length : 2, /* log base 2 of value's width */ + r_extern : 1, /* 1 if need to add symbol to value */ + r_baserel : 1, /* linkage table relative */ + r_jmptable : 1, /* relocate to jump table */ + r_relative : 1, /* load address relative */ + r_copy : 1; /* run time copy */ +}; + +#endif diff --git a/src/include/machine/resource.h b/src/include/machine/resource.h new file mode 100644 index 0000000..dbe0766 --- /dev/null +++ b/src/include/machine/resource.h @@ -0,0 +1,44 @@ +/* $FreeBSD: src/sys/i386/include/resource.h,v 1.3 1999/10/14 21:38:30 dfr Exp $ */ +/* + * Copyright 1998 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + */ + +#ifndef _MACHINE_RESOURCE_H_ +#define _MACHINE_RESOURCE_H_ 1 + +/* + * Definitions of resource types for Intel Architecture machines + * with support for legacy ISA devices and drivers. + */ + +#define SYS_RES_IRQ 1 /* interrupt lines */ +#define SYS_RES_DRQ 2 /* isa dma lines */ +#define SYS_RES_MEMORY 3 /* i/o memory */ +#define SYS_RES_IOPORT 4 /* i/o ports */ + +#endif /* !_MACHINE_RESOURCE_H_ */ diff --git a/src/include/machine/runq.h b/src/include/machine/runq.h new file mode 100644 index 0000000..adb162f --- /dev/null +++ b/src/include/machine/runq.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2001 Jake Burkholder + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/runq.h,v 1.2 2002/06/20 06:21:20 peter Exp $ + */ + +#ifndef _MACHINE_RUNQ_H_ +#define _MACHINE_RUNQ_H_ + +#define RQB_LEN (2) /* Number of priority status words. */ +#define RQB_L2BPW (5) /* Log2(sizeof(rqb_word_t) * NBBY)). */ +#define RQB_BPW (1<> RQB_L2BPW) + +#define RQB_FFS(word) (ffs(word) - 1) + +/* + * Type of run queue status word. + */ +typedef u_int32_t rqb_word_t; + +#endif diff --git a/src/include/machine/segments.h b/src/include/machine/segments.h new file mode 100644 index 0000000..34a1836 --- /dev/null +++ b/src/include/machine/segments.h @@ -0,0 +1,250 @@ +/*- + * Copyright (c) 1989, 1990 William F. Jolitz + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)segments.h 7.1 (Berkeley) 5/9/91 + * $FreeBSD: src/sys/i386/include/segments.h,v 1.37 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_SEGMENTS_H_ +#define _MACHINE_SEGMENTS_H_ + +/* + * 386 Segmentation Data Structures and definitions + * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 + */ + +/* + * Selectors + */ + +#define ISPL(s) ((s)&3) /* what is the priority level of a selector */ +#define SEL_KPL 0 /* kernel priority level */ +#define SEL_UPL 3 /* user priority level */ +#define ISLDT(s) ((s)&SEL_LDT) /* is it local or global */ +#define SEL_LDT 4 /* local descriptor table */ +#define IDXSEL(s) (((s)>>3) & 0x1fff) /* index of selector */ +#define LSEL(s,r) (((s)<<3) | SEL_LDT | r) /* a local selector */ +#define GSEL(s,r) (((s)<<3) | r) /* a global selector */ + +/* + * Memory and System segment descriptors + */ +struct segment_descriptor { + unsigned sd_lolimit:16 ; /* segment extent (lsb) */ + unsigned sd_lobase:24 __packed; /* segment base address (lsb) */ + unsigned sd_type:5 ; /* segment type */ + unsigned sd_dpl:2 ; /* segment descriptor priority level */ + unsigned sd_p:1 ; /* segment descriptor present */ + unsigned sd_hilimit:4 ; /* segment extent (msb) */ + unsigned sd_xx:2 ; /* unused */ + unsigned sd_def32:1 ; /* default 32 vs 16 bit size */ + unsigned sd_gran:1 ; /* limit granularity (byte/page units)*/ + unsigned sd_hibase:8 ; /* segment base address (msb) */ +} ; + +/* + * Gate descriptors (e.g. indirect descriptors) + */ +struct gate_descriptor { + unsigned gd_looffset:16 ; /* gate offset (lsb) */ + unsigned gd_selector:16 ; /* gate segment selector */ + unsigned gd_stkcpy:5 ; /* number of stack wds to cpy */ + unsigned gd_xx:3 ; /* unused */ + unsigned gd_type:5 ; /* segment type */ + unsigned gd_dpl:2 ; /* segment descriptor priority level */ + unsigned gd_p:1 ; /* segment descriptor present */ + unsigned gd_hioffset:16 ; /* gate offset (msb) */ +} ; + +/* + * Generic descriptor + */ +union descriptor { + struct segment_descriptor sd; + struct gate_descriptor gd; +}; + + /* system segments and gate types */ +#define SDT_SYSNULL 0 /* system null */ +#define SDT_SYS286TSS 1 /* system 286 TSS available */ +#define SDT_SYSLDT 2 /* system local descriptor table */ +#define SDT_SYS286BSY 3 /* system 286 TSS busy */ +#define SDT_SYS286CGT 4 /* system 286 call gate */ +#define SDT_SYSTASKGT 5 /* system task gate */ +#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ +#define SDT_SYS286TGT 7 /* system 286 trap gate */ +#define SDT_SYSNULL2 8 /* system null again */ +#define SDT_SYS386TSS 9 /* system 386 TSS available */ +#define SDT_SYSNULL3 10 /* system null again */ +#define SDT_SYS386BSY 11 /* system 386 TSS busy */ +#define SDT_SYS386CGT 12 /* system 386 call gate */ +#define SDT_SYSNULL4 13 /* system null again */ +#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ +#define SDT_SYS386TGT 15 /* system 386 trap gate */ + + /* memory segment types */ +#define SDT_MEMRO 16 /* memory read only */ +#define SDT_MEMROA 17 /* memory read only accessed */ +#define SDT_MEMRW 18 /* memory read write */ +#define SDT_MEMRWA 19 /* memory read write accessed */ +#define SDT_MEMROD 20 /* memory read only expand dwn limit */ +#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ +#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ +#define SDT_MEMRWDA 23 /* memory read write expand dwn limit accessed */ +#define SDT_MEME 24 /* memory execute only */ +#define SDT_MEMEA 25 /* memory execute only accessed */ +#define SDT_MEMER 26 /* memory execute read */ +#define SDT_MEMERA 27 /* memory execute read accessed */ +#define SDT_MEMEC 28 /* memory execute only conforming */ +#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ +#define SDT_MEMERC 30 /* memory execute read conforming */ +#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ + +/* + * Software definitions are in this convenient format, + * which are translated into inconvenient segment descriptors + * when needed to be used by the 386 hardware + */ + +struct soft_segment_descriptor { + unsigned ssd_base ; /* segment base address */ + unsigned ssd_limit ; /* segment extent */ + unsigned ssd_type:5 ; /* segment type */ + unsigned ssd_dpl:2 ; /* segment descriptor priority level */ + unsigned ssd_p:1 ; /* segment descriptor present */ + unsigned ssd_xx:4 ; /* unused */ + unsigned ssd_xx1:2 ; /* unused */ + unsigned ssd_def32:1 ; /* default 32 vs 16 bit size */ + unsigned ssd_gran:1 ; /* limit granularity (byte/page units)*/ +}; + +/* + * region descriptors, used to load gdt/idt tables before segments yet exist. + */ +struct region_descriptor { + unsigned rd_limit:16; /* segment extent */ + unsigned rd_base:32 __packed; /* base address */ +}; + +/* + * Segment Protection Exception code bits + */ + +#define SEGEX_EXT 0x01 /* recursive or externally induced */ +#define SEGEX_IDT 0x02 /* interrupt descriptor table */ +#define SEGEX_TI 0x04 /* local descriptor table */ + /* other bits are affected descriptor index */ +#define SEGEX_IDX(s) (((s)>>3)&0x1fff) + +/* + * Size of IDT table + */ + +#define NIDT 256 /* 32 reserved, 0x80 syscall, most are h/w */ +#define NRSVIDT 32 /* reserved entries for cpu exceptions */ + +/* + * Entries in the Interrupt Descriptor Table (IDT) + */ +#define IDT_DE 0 /* #DE: Divide Error */ +#define IDT_DB 1 /* #DB: Debug */ +#define IDT_NMI 2 /* Nonmaskable External Interrupt */ +#define IDT_BP 3 /* #BP: Breakpoint */ +#define IDT_OF 4 /* #OF: Overflow */ +#define IDT_BR 5 /* #BR: Bound Range Exceeded */ +#define IDT_UD 6 /* #UD: Undefined/Invalid Opcode */ +#define IDT_NM 7 /* #NM: No Math Coprocessor */ +#define IDT_DF 8 /* #DF: Double Fault */ +#define IDT_FPUGP 9 /* Coprocessor Segment Overrun */ +#define IDT_TS 10 /* #TS: Invalid TSS */ +#define IDT_NP 11 /* #NP: Segment Not Present */ +#define IDT_SS 12 /* #SS: Stack Segment Fault */ +#define IDT_GP 13 /* #GP: General Protection Fault */ +#define IDT_PF 14 /* #PF: Page Fault */ +#define IDT_MF 16 /* #MF: FPU Floating-Point Error */ +#define IDT_AC 17 /* #AC: Alignment Check */ +#define IDT_MC 18 /* #MC: Machine Check */ +#define IDT_XF 19 /* #XF: SIMD Floating-Point Exception */ +#define IDT_IO_INTS NRSVIDT /* Base of IDT entries for I/O interrupts. */ +#define IDT_SYSCALL 0x80 /* System Call Interrupt Vector */ + +/* + * Entries in the Global Descriptor Table (GDT) + */ +#define GNULL_SEL 0 /* Null Descriptor */ +#define GCODE_SEL 1 /* Kernel Code Descriptor */ +#define GDATA_SEL 2 /* Kernel Data Descriptor */ +#define GPRIV_SEL 3 /* SMP Per-Processor Private Data */ +#define GPROC0_SEL 4 /* Task state process slot zero and up */ +#define GLDT_SEL 5 /* LDT - eventually one per process */ +#define GUSERLDT_SEL 6 /* User LDT */ +#define GTGATE_SEL 7 /* Process task switch gate */ +#define GBIOSLOWMEM_SEL 8 /* BIOS low memory access (must be entry 8) */ +#define GPANIC_SEL 9 /* Task state to consider panic from */ +#define GBIOSCODE32_SEL 10 /* BIOS interface (32bit Code) */ +#define GBIOSCODE16_SEL 11 /* BIOS interface (16bit Code) */ +#define GBIOSDATA_SEL 12 /* BIOS interface (Data) */ +#define GBIOSUTIL_SEL 13 /* BIOS interface (Utility) */ +#define GBIOSARGS_SEL 14 /* BIOS interface (Arguments) */ + +#define NGDT 15 + +/* + * Entries in the Local Descriptor Table (LDT) + */ +#define LSYS5CALLS_SEL 0 /* forced by intel BCS */ +#define LSYS5SIGR_SEL 1 +#define L43BSDCALLS_SEL 2 /* notyet */ +#define LUCODE_SEL 3 +#define LSOL26CALLS_SEL 4 /* Solaris >= 2.6 system call gate */ +#define LUDATA_SEL 5 +/* separate stack, es,fs,gs sels ? */ +/* #define LPOSIXCALLS_SEL 5*/ /* notyet */ +#define LBSDICALLS_SEL 16 /* BSDI system call gate */ +#define NLDT (LBSDICALLS_SEL + 1) + +#ifdef _KERNEL +extern int _default_ldt; +extern union descriptor gdt[]; +extern struct soft_segment_descriptor gdt_segs[]; +extern struct gate_descriptor *idt; +extern union descriptor ldt[NLDT]; +extern struct region_descriptor r_gdt, r_idt; + +void lgdt(struct region_descriptor *rdp); +void sdtossd(struct segment_descriptor *sdp, + struct soft_segment_descriptor *ssdp); +void ssdtosd(struct soft_segment_descriptor *ssdp, + struct segment_descriptor *sdp); +#endif /* _KERNEL */ + +#endif /* !_MACHINE_SEGMENTS_H_ */ diff --git a/src/include/machine/setjmp.h b/src/include/machine/setjmp.h new file mode 100644 index 0000000..c6d2f2c --- /dev/null +++ b/src/include/machine/setjmp.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 1998 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. + * + * $FreeBSD: src/sys/i386/include/setjmp.h,v 1.7 2002/10/05 05:47:55 mike Exp $ + */ + +#ifndef _MACHINE_SETJMP_H_ +#define _MACHINE_SETJMP_H_ + +#include + +#define _JBLEN 11 /* Size of the jmp_buf on x86. */ + +/* + * jmp_buf and sigjmp_buf are encapsulated in different structs to force + * compile-time diagnostics for mismatches. The structs are the same + * internally to avoid some run-time errors for mismatches. + */ +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XSI_VISIBLE +typedef struct _sigjmp_buf { int _sjb[_JBLEN + 1]; } sigjmp_buf[1]; +#endif + +typedef struct _jmp_buf { int _jb[_JBLEN + 1]; } jmp_buf[1]; + +#endif /* !_MACHINE_SETJMP_H_ */ diff --git a/src/include/machine/sf_buf.h b/src/include/machine/sf_buf.h new file mode 100644 index 0000000..47e5686 --- /dev/null +++ b/src/include/machine/sf_buf.h @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2003 Alan L. Cox + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/sf_buf.h,v 1.3 2003/12/07 22:49:25 alc Exp $ + */ + +#ifndef _MACHINE_SF_BUF_H_ +#define _MACHINE_SF_BUF_H_ + +#include + +struct vm_page; + +struct sf_buf { + LIST_ENTRY(sf_buf) list_entry; /* list of buffers */ + TAILQ_ENTRY(sf_buf) free_entry; /* list of buffers */ + struct vm_page *m; /* currently mapped page */ + vm_offset_t kva; /* va of mapping */ + int ref_count; /* usage of this mapping */ +}; + +static __inline vm_offset_t +sf_buf_kva(struct sf_buf *sf) +{ + + return (sf->kva); +} + +static __inline struct vm_page * +sf_buf_page(struct sf_buf *sf) +{ + + return (sf->m); +} + +#endif /* !_MACHINE_SF_BUF_H_ */ diff --git a/src/include/machine/sigframe.h b/src/include/machine/sigframe.h new file mode 100644 index 0000000..5f658dc --- /dev/null +++ b/src/include/machine/sigframe.h @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 1999 Marcel Moolenaar + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/sigframe.h,v 1.8 2002/10/25 19:10:56 peter Exp $ + */ + +#ifndef _MACHINE_SIGFRAME_H_ +#define _MACHINE_SIGFRAME_H_ + +/* + * Signal frames, arguments passed to application signal handlers. + */ +#ifdef _KERNEL +#ifdef COMPAT_43 +struct osigframe { + /* + * The first four members may be used by applications. + */ + + register_t sf_signum; + + /* + * Either 'int' for old-style FreeBSD handler or 'siginfo_t *' + * pointing to sf_siginfo for SA_SIGINFO handlers. + */ + register_t sf_arg2; + + /* Points to sf_siginfo.si_sc. */ + register_t sf_scp; + + register_t sf_addr; + + /* + * The following arguments are not constrained by the + * function call protocol. + * Applications are not supposed to access these members, + * except using the pointers we provide in the first three + * arguments. + */ + + union { + __osiginfohandler_t *sf_action; + __sighandler_t *sf_handler; + } sf_ahu; + + /* In the SA_SIGINFO case, sf_arg2 points here. */ + osiginfo_t sf_siginfo; +}; +#endif +#ifdef COMPAT_FREEBSD4 +/* FreeBSD 4.x */ +struct sigframe4 { + register_t sf_signum; + register_t sf_siginfo; /* code or pointer to sf_si */ + register_t sf_ucontext; /* points to sf_uc */ + register_t sf_addr; /* undocumented 4th arg */ + + union { + __siginfohandler_t *sf_action; + __sighandler_t *sf_handler; + } sf_ahu; + struct ucontext4 sf_uc; /* = *sf_ucontext */ + siginfo_t sf_si; /* = *sf_siginfo (SA_SIGINFO case) */ +}; +#endif +#endif + +struct sigframe { + /* + * The first four members may be used by applications. + * + * NOTE: The 4th argument is undocumented, ill commented + * on and seems to be somewhat BSD "standard". Handlers + * installed with sigvec may be using it. + */ + register_t sf_signum; + register_t sf_siginfo; /* code or pointer to sf_si */ + register_t sf_ucontext; /* points to sf_uc */ + register_t sf_addr; /* undocumented 4th arg */ + + union { + __siginfohandler_t *sf_action; + __sighandler_t *sf_handler; + } sf_ahu; + ucontext_t sf_uc; /* = *sf_ucontext */ + siginfo_t sf_si; /* = *sf_siginfo (SA_SIGINFO case) */ +}; + +#endif /* !_MACHINE_SIGFRAME_H_ */ diff --git a/src/include/machine/signal.h b/src/include/machine/signal.h new file mode 100644 index 0000000..3d3c6ea --- /dev/null +++ b/src/include/machine/signal.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 1986, 1989, 1991, 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. + * 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. + * + * @(#)signal.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD: src/sys/i386/include/signal.h,v 1.21 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include +#include + +/* + * Machine-dependent signal definitions + */ + +typedef int sig_atomic_t; + +#if __XSI_VISIBLE +/* + * Minimum signal stack size. The current signal frame + * for i386 is 408 bytes large. + */ +#define MINSIGSTKSZ (512 * 4) +#endif + +#if __BSD_VISIBLE +#include /* codes for SIGILL, SIGFPE */ + +/* + * Only the kernel should need these old type definitions. + */ +#if defined(_KERNEL) && defined(COMPAT_43) +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct osigcontext { + int sc_onstack; /* sigstack state to restore */ + osigset_t sc_mask; /* signal mask to restore */ + int sc_esp; /* machine state follows: */ + int sc_ebp; + int sc_isp; + int sc_eip; + int sc_efl; + int sc_es; + int sc_ds; + int sc_cs; + int sc_ss; + int sc_edi; + int sc_esi; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + int sc_gs; + int sc_fs; + int sc_trapno; + int sc_err; +}; +#endif + +/* + * The sequence of the fields/registers in struct sigcontext should match + * those in mcontext_t. + */ +struct sigcontext { + struct __sigset sc_mask; /* signal mask to restore */ + int sc_onstack; /* sigstack state to restore */ + int sc_gs; /* machine state (struct trapframe) */ + int sc_fs; + int sc_es; + int sc_ds; + int sc_edi; + int sc_esi; + int sc_ebp; + int sc_isp; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + int sc_trapno; + int sc_err; + int sc_eip; + int sc_cs; + int sc_efl; + int sc_esp; + int sc_ss; + int sc_len; /* sizeof(mcontext_t) */ + /* + * XXX - See and for + * the following fields. + */ + int sc_fpformat; + int sc_ownedfp; + int sc_spare1[1]; + int sc_fpstate[128] __aligned(16); + int sc_spare2[8]; +}; + +#define sc_sp sc_esp +#define sc_fp sc_ebp +#define sc_pc sc_eip +#define sc_ps sc_efl +#define sc_eflags sc_efl + +#endif /* __BSD_VISIBLE */ + +#endif /* !_MACHINE_SIGNAL_H_ */ diff --git a/src/include/machine/smapi.h b/src/include/machine/smapi.h new file mode 100644 index 0000000..1d30c16 --- /dev/null +++ b/src/include/machine/smapi.h @@ -0,0 +1,91 @@ +/*- + * Copyright (c) 2003 Matthew N. Dodd + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/smapi.h,v 1.2 2003/03/24 20:44:39 mdodd Exp $ + */ + +#ifndef _MACHINE_SMAPI_H_ +#define _MACHINE_SMAPI_H_ + +#ifndef _KERNEL +#include +#endif +#include + +struct smapi_bios_header { + u_int8_t signature[4]; /* '$SMB' */ + u_int8_t version_major; + u_int8_t version_minor; + u_int8_t length; + u_int8_t checksum; + u_int16_t information; +#define SMAPI_REAL_VM86 0x0001 +#define SMAPI_PROT_16BIT 0x0002 +#define SMAPI_PROT_32BIT 0x0004 + u_int16_t reserved1; + + u_int16_t real16_offset; + u_int16_t real16_segment; + + u_int16_t reserved2; + + u_int16_t prot16_offset; + u_int32_t prot16_segment; + + u_int32_t prot32_offset; + u_int32_t prot32_segment; + +} __packed; + +struct smapi_bios_parameter { + union { + struct { + u_int8_t func; + u_int8_t sub_func; + } in; + struct { + u_int8_t rc; + u_int8_t sub_rc; + } out; + } type; + + u_int16_t param1; + u_int16_t param2; + u_int16_t param3; + + u_int32_t param4; + u_int32_t param5; + +} __packed; + +#define cmd_func type.in.func +#define cmd_sub_func type.in.sub_func +#define rsp_rc type.out.rc +#define rsp_sub_rc type.out.sub_rc + +#define SMAPIOGHEADER _IOR('$', 0, struct smapi_bios_header) +#define SMAPIOCGFUNCTION _IOWR('$', 1, struct smapi_bios_parameter) + +#endif /* _MACHINE_SMAPI_H_ */ diff --git a/src/include/machine/smp.h b/src/include/machine/smp.h new file mode 100644 index 0000000..640b595 --- /dev/null +++ b/src/include/machine/smp.h @@ -0,0 +1,91 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/i386/include/smp.h,v 1.78 2003/12/11 03:48:31 jeff Exp $ + * + */ + +#ifndef _MACHINE_SMP_H_ +#define _MACHINE_SMP_H_ + +#ifdef _KERNEL + +#ifdef SMP + +#ifndef LOCORE + +/* + * For sending values to POST displays. + * XXX FIXME: where does this really belong, isa.h/isa.c perhaps? + */ +extern int current_postcode; /** XXX currently in mp_machdep.c */ +#define POSTCODE(X) current_postcode = (X), \ + outb(0x80, current_postcode) +#define POSTCODE_LO(X) current_postcode &= 0xf0, \ + current_postcode |= ((X) & 0x0f), \ + outb(0x80, current_postcode) +#define POSTCODE_HI(X) current_postcode &= 0x0f, \ + current_postcode |= (((X) << 4) & 0xf0), \ + outb(0x80, current_postcode) + +#include +#include +#include +#include + +/* global data in mpboot.s */ +extern int bootMP_size; + +/* functions in mpboot.s */ +void bootMP(void); + +/* global data in mp_machdep.c */ +extern int mp_naps; +extern int boot_cpu_id; +extern struct pcb stoppcbs[]; +extern struct mtx smp_tlb_mtx; + +/* IPI handlers */ +inthand_t + IDTVEC(invltlb), /* TLB shootdowns - global */ + IDTVEC(invlpg), /* TLB shootdowns - 1 page */ + IDTVEC(invlrng), /* TLB shootdowns - page range */ + IDTVEC(hardclock), /* Forward hardclock() */ + IDTVEC(statclock), /* Forward statclock() */ + IDTVEC(cpuast), /* Additional software trap on other cpu */ + IDTVEC(cpustop), /* CPU stops & waits to be restarted */ + IDTVEC(rendezvous), /* handle CPU rendezvous */ + IDTVEC(lazypmap); /* handle lazy pmap release */ + +/* functions in mp_machdep.c */ +void cpu_add(u_int apic_id, char boot_cpu); +void init_secondary(void); +void ipi_selected(u_int cpus, u_int ipi); +void ipi_all(u_int ipi); +void ipi_all_but_self(u_int ipi); +void ipi_self(u_int ipi); +void forward_statclock(void); +void forwarded_statclock(struct clockframe frame); +void forward_hardclock(void); +void forwarded_hardclock(struct clockframe frame); +u_int mp_bootaddress(u_int); +int mp_grab_cpu_hlt(void); +void mp_topology(void); +void smp_invlpg(vm_offset_t addr); +void smp_masked_invlpg(u_int mask, vm_offset_t addr); +void smp_invlpg_range(vm_offset_t startva, vm_offset_t endva); +void smp_masked_invlpg_range(u_int mask, vm_offset_t startva, + vm_offset_t endva); +void smp_invltlb(void); +void smp_masked_invltlb(u_int mask); + +#endif /* !LOCORE */ +#endif /* SMP */ + +#endif /* _KERNEL */ +#endif /* _MACHINE_SMP_H_ */ diff --git a/src/include/machine/smptests.h b/src/include/machine/smptests.h new file mode 100644 index 0000000..cff5dcd --- /dev/null +++ b/src/include/machine/smptests.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 1996, by Steve Passe + * 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. The name of the developer may NOT be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/smptests.h,v 1.46 2003/11/16 00:55:53 bde Exp $ + */ + +#ifndef _MACHINE_SMPTESTS_H_ +#define _MACHINE_SMPTESTS_H_ + + +/* + * Various 'tests in progress' and configuration parameters. + */ + +/* + * Send CPUSTOP IPI for stop/restart of other CPUs on DDB break. +#define VERBOSE_CPUSTOP_ON_DDBBREAK + */ +#define CPUSTOP_ON_DDBBREAK + +/* + * Misc. counters. + * +#define COUNT_XINVLTLB_HITS + */ + +/* + * Address of POST hardware port. + * Defining this enables POSTCODE macros. + * +#define POST_ADDR 0x80 + */ + + +/* + * POST hardware macros. + */ +#ifdef POST_ADDR +#define ASMPOSTCODE_INC \ + pushl %eax ; \ + movl _current_postcode, %eax ; \ + incl %eax ; \ + andl $0xff, %eax ; \ + movl %eax, _current_postcode ; \ + outb %al, $POST_ADDR ; \ + popl %eax + +/* + * Overwrite the current_postcode value. + */ +#define ASMPOSTCODE(X) \ + pushl %eax ; \ + movl $X, %eax ; \ + movl %eax, _current_postcode ; \ + outb %al, $POST_ADDR ; \ + popl %eax + +/* + * Overwrite the current_postcode low nibble. + */ +#define ASMPOSTCODE_LO(X) \ + pushl %eax ; \ + movl _current_postcode, %eax ; \ + andl $0xf0, %eax ; \ + orl $X, %eax ; \ + movl %eax, _current_postcode ; \ + outb %al, $POST_ADDR ; \ + popl %eax + +/* + * Overwrite the current_postcode high nibble. + */ +#define ASMPOSTCODE_HI(X) \ + pushl %eax ; \ + movl _current_postcode, %eax ; \ + andl $0x0f, %eax ; \ + orl $(X<<4), %eax ; \ + movl %eax, _current_postcode ; \ + outb %al, $POST_ADDR ; \ + popl %eax +#else +#define ASMPOSTCODE_INC +#define ASMPOSTCODE(X) +#define ASMPOSTCODE_LO(X) +#define ASMPOSTCODE_HI(X) +#endif /* POST_ADDR */ + + +#endif /* _MACHINE_SMPTESTS_H_ */ diff --git a/src/include/machine/speaker.h b/src/include/machine/speaker.h new file mode 100644 index 0000000..f14117d --- /dev/null +++ b/src/include/machine/speaker.h @@ -0,0 +1,29 @@ +/* + * speaker.h -- interface definitions for speaker ioctl() + * + * v1.4 by Eric S. Raymond (esr@snark.thyrsus.com) Aug 1993 + * modified for FreeBSD by Andrew A. Chernov + * + * $FreeBSD: src/sys/i386/include/speaker.h,v 1.7 2002/10/23 10:14:30 markm Exp $ + */ + +#ifndef _MACHINE_SPEAKER_H_ +#define _MACHINE_SPEAKER_H_ + +#include + +#define SPKRTONE _IOW('S', 1, tone_t) /* emit tone */ +#define SPKRTUNE _IO('S', 2) /* emit tone sequence*/ + +typedef struct +{ + int frequency; /* in hertz */ + int duration; /* in 1/100ths of a second */ +} tone_t; + +/* + * Strings written to the speaker device are interpreted as tunes and played; + * see the spkr(4) man page for details. + */ + +#endif /* !_MACHINE_SPEAKER_H_ */ diff --git a/src/include/machine/specialreg.h b/src/include/machine/specialreg.h new file mode 100644 index 0000000..482b38b --- /dev/null +++ b/src/include/machine/specialreg.h @@ -0,0 +1,391 @@ +/*- + * Copyright (c) 1991 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. + * 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. + * + * from: @(#)specialreg.h 7.1 (Berkeley) 5/9/91 + * $FreeBSD: src/sys/i386/include/specialreg.h,v 1.27 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_SPECIALREG_H_ +#define _MACHINE_SPECIALREG_H_ + +/* + * Bits in 386 special registers: + */ +#define CR0_PE 0x00000001 /* Protected mode Enable */ +#define CR0_MP 0x00000002 /* "Math" Present (NPX or NPX emulator) */ +#define CR0_EM 0x00000004 /* EMulate non-NPX coproc. (trap ESC only) */ +#define CR0_TS 0x00000008 /* Task Switched (if MP, trap ESC and WAIT) */ +#ifdef notused +#define CR0_ET 0x00000010 /* Extension Type (387 (if set) vs 287) */ +#endif +#define CR0_PG 0x80000000 /* PaGing enable */ + +/* + * Bits in 486 special registers: + */ +#define CR0_NE 0x00000020 /* Numeric Error enable (EX16 vs IRQ13) */ +#define CR0_WP 0x00010000 /* Write Protect (honor page protect in + all modes) */ +#define CR0_AM 0x00040000 /* Alignment Mask (set to enable AC flag) */ +#define CR0_NW 0x20000000 /* Not Write-through */ +#define CR0_CD 0x40000000 /* Cache Disable */ + +/* + * Bits in PPro special registers + */ +#define CR4_VME 0x00000001 /* Virtual 8086 mode extensions */ +#define CR4_PVI 0x00000002 /* Protected-mode virtual interrupts */ +#define CR4_TSD 0x00000004 /* Time stamp disable */ +#define CR4_DE 0x00000008 /* Debugging extensions */ +#define CR4_PSE 0x00000010 /* Page size extensions */ +#define CR4_PAE 0x00000020 /* Physical address extension */ +#define CR4_MCE 0x00000040 /* Machine check enable */ +#define CR4_PGE 0x00000080 /* Page global enable */ +#define CR4_PCE 0x00000100 /* Performance monitoring counter enable */ +#define CR4_FXSR 0x00000200 /* Fast FPU save/restore used by OS */ +#define CR4_XMM 0x00000400 /* enable SIMD/MMX2 to use except 16 */ + +/* + * CPUID instruction features register + */ +#define CPUID_FPU 0x00000001 +#define CPUID_VME 0x00000002 +#define CPUID_DE 0x00000004 +#define CPUID_PSE 0x00000008 +#define CPUID_TSC 0x00000010 +#define CPUID_MSR 0x00000020 +#define CPUID_PAE 0x00000040 +#define CPUID_MCE 0x00000080 +#define CPUID_CX8 0x00000100 +#define CPUID_APIC 0x00000200 +#define CPUID_B10 0x00000400 +#define CPUID_SEP 0x00000800 +#define CPUID_MTRR 0x00001000 +#define CPUID_PGE 0x00002000 +#define CPUID_MCA 0x00004000 +#define CPUID_CMOV 0x00008000 +#define CPUID_PAT 0x00010000 +#define CPUID_PSE36 0x00020000 +#define CPUID_PSN 0x00040000 +#define CPUID_CLFSH 0x00080000 +#define CPUID_B20 0x00100000 +#define CPUID_DS 0x00200000 +#define CPUID_ACPI 0x00400000 +#define CPUID_MMX 0x00800000 +#define CPUID_FXSR 0x01000000 +#define CPUID_SSE 0x02000000 +#define CPUID_XMM 0x02000000 +#define CPUID_SSE2 0x04000000 +#define CPUID_SS 0x08000000 +#define CPUID_HTT 0x10000000 +#define CPUID_TM 0x20000000 +#define CPUID_IA64 0x40000000 +#define CPUID_PBE 0x80000000 + +/* + * CPUID instruction 1 ebx info + */ +#define CPUID_BRAND_INDEX 0x000000ff +#define CPUID_CLFUSH_SIZE 0x0000ff00 +#define CPUID_HTT_CORES 0x00ff0000 +#define CPUID_LOCAL_APIC_ID 0xff000000 + +/* + * Model-specific registers for the i386 family + */ +#define MSR_P5_MC_ADDR 0x000 +#define MSR_P5_MC_TYPE 0x001 +#define MSR_TSC 0x010 +#define MSR_P5_CESR 0x011 +#define MSR_P5_CTR0 0x012 +#define MSR_P5_CTR1 0x013 +#define MSR_IA32_PLATFORM_ID 0x017 +#define MSR_APICBASE 0x01b +#define MSR_EBL_CR_POWERON 0x02a +#define MSR_TEST_CTL 0x033 +#define MSR_BIOS_UPDT_TRIG 0x079 +#define MSR_BBL_CR_D0 0x088 +#define MSR_BBL_CR_D1 0x089 +#define MSR_BBL_CR_D2 0x08a +#define MSR_BIOS_SIGN 0x08b +#define MSR_PERFCTR0 0x0c1 +#define MSR_PERFCTR1 0x0c2 +#define MSR_MTRRcap 0x0fe +#define MSR_BBL_CR_ADDR 0x116 +#define MSR_BBL_CR_DECC 0x118 +#define MSR_BBL_CR_CTL 0x119 +#define MSR_BBL_CR_TRIG 0x11a +#define MSR_BBL_CR_BUSY 0x11b +#define MSR_BBL_CR_CTL3 0x11e +#define MSR_SYSENTER_CS_MSR 0x174 +#define MSR_SYSENTER_ESP_MSR 0x175 +#define MSR_SYSENTER_EIP_MSR 0x176 +#define MSR_MCG_CAP 0x179 +#define MSR_MCG_STATUS 0x17a +#define MSR_MCG_CTL 0x17b +#define MSR_EVNTSEL0 0x186 +#define MSR_EVNTSEL1 0x187 +#define MSR_THERM_CONTROL 0x19a +#define MSR_THERM_INTERRUPT 0x19b +#define MSR_THERM_STATUS 0x19c +#define MSR_DEBUGCTLMSR 0x1d9 +#define MSR_LASTBRANCHFROMIP 0x1db +#define MSR_LASTBRANCHTOIP 0x1dc +#define MSR_LASTINTFROMIP 0x1dd +#define MSR_LASTINTTOIP 0x1de +#define MSR_ROB_CR_BKUPTMPDR6 0x1e0 +#define MSR_MTRRVarBase 0x200 +#define MSR_MTRR64kBase 0x250 +#define MSR_MTRR16kBase 0x258 +#define MSR_MTRR4kBase 0x268 +#define MSR_MTRRdefType 0x2ff +#define MSR_MC0_CTL 0x400 +#define MSR_MC0_STATUS 0x401 +#define MSR_MC0_ADDR 0x402 +#define MSR_MC0_MISC 0x403 +#define MSR_MC1_CTL 0x404 +#define MSR_MC1_STATUS 0x405 +#define MSR_MC1_ADDR 0x406 +#define MSR_MC1_MISC 0x407 +#define MSR_MC2_CTL 0x408 +#define MSR_MC2_STATUS 0x409 +#define MSR_MC2_ADDR 0x40a +#define MSR_MC2_MISC 0x40b +#define MSR_MC4_CTL 0x40c +#define MSR_MC4_STATUS 0x40d +#define MSR_MC4_ADDR 0x40e +#define MSR_MC4_MISC 0x40f +#define MSR_MC3_CTL 0x410 +#define MSR_MC3_STATUS 0x411 +#define MSR_MC3_ADDR 0x412 +#define MSR_MC3_MISC 0x413 + +/* + * Constants related to MSR's. + */ +#define APICBASE_RESERVED 0x000006ff +#define APICBASE_BSP 0x00000100 +#define APICBASE_ENABLED 0x00000800 +#define APICBASE_ADDRESS 0xfffff000 + +/* + * Constants related to MTRRs + */ +#define MTRR_N64K 8 /* numbers of fixed-size entries */ +#define MTRR_N16K 16 +#define MTRR_N4K 64 + +/* + * Cyrix configuration registers, accessible as IO ports. + */ +#define CCR0 0xc0 /* Configuration control register 0 */ +#define CCR0_NC0 0x01 /* First 64K of each 1M memory region is + non-cacheable */ +#define CCR0_NC1 0x02 /* 640K-1M region is non-cacheable */ +#define CCR0_A20M 0x04 /* Enables A20M# input pin */ +#define CCR0_KEN 0x08 /* Enables KEN# input pin */ +#define CCR0_FLUSH 0x10 /* Enables FLUSH# input pin */ +#define CCR0_BARB 0x20 /* Flushes internal cache when entering hold + state */ +#define CCR0_CO 0x40 /* Cache org: 1=direct mapped, 0=2x set + assoc */ +#define CCR0_SUSPEND 0x80 /* Enables SUSP# and SUSPA# pins */ + +#define CCR1 0xc1 /* Configuration control register 1 */ +#define CCR1_RPL 0x01 /* Enables RPLSET and RPLVAL# pins */ +#define CCR1_SMI 0x02 /* Enables SMM pins */ +#define CCR1_SMAC 0x04 /* System management memory access */ +#define CCR1_MMAC 0x08 /* Main memory access */ +#define CCR1_NO_LOCK 0x10 /* Negate LOCK# */ +#define CCR1_SM3 0x80 /* SMM address space address region 3 */ + +#define CCR2 0xc2 +#define CCR2_WB 0x02 /* Enables WB cache interface pins */ +#define CCR2_SADS 0x02 /* Slow ADS */ +#define CCR2_LOCK_NW 0x04 /* LOCK NW Bit */ +#define CCR2_SUSP_HLT 0x08 /* Suspend on HALT */ +#define CCR2_WT1 0x10 /* WT region 1 */ +#define CCR2_WPR1 0x10 /* Write-protect region 1 */ +#define CCR2_BARB 0x20 /* Flushes write-back cache when entering + hold state. */ +#define CCR2_BWRT 0x40 /* Enables burst write cycles */ +#define CCR2_USE_SUSP 0x80 /* Enables suspend pins */ + +#define CCR3 0xc3 +#define CCR3_SMILOCK 0x01 /* SMM register lock */ +#define CCR3_NMI 0x02 /* Enables NMI during SMM */ +#define CCR3_LINBRST 0x04 /* Linear address burst cycles */ +#define CCR3_SMMMODE 0x08 /* SMM Mode */ +#define CCR3_MAPEN0 0x10 /* Enables Map0 */ +#define CCR3_MAPEN1 0x20 /* Enables Map1 */ +#define CCR3_MAPEN2 0x40 /* Enables Map2 */ +#define CCR3_MAPEN3 0x80 /* Enables Map3 */ + +#define CCR4 0xe8 +#define CCR4_IOMASK 0x07 +#define CCR4_MEM 0x08 /* Enables momory bypassing */ +#define CCR4_DTE 0x10 /* Enables directory table entry cache */ +#define CCR4_FASTFPE 0x20 /* Fast FPU exception */ +#define CCR4_CPUID 0x80 /* Enables CPUID instruction */ + +#define CCR5 0xe9 +#define CCR5_WT_ALLOC 0x01 /* Write-through allocate */ +#define CCR5_SLOP 0x02 /* LOOP instruction slowed down */ +#define CCR5_LBR1 0x10 /* Local bus region 1 */ +#define CCR5_ARREN 0x20 /* Enables ARR region */ + +#define CCR6 0xea + +#define CCR7 0xeb + +/* Performance Control Register (5x86 only). */ +#define PCR0 0x20 +#define PCR0_RSTK 0x01 /* Enables return stack */ +#define PCR0_BTB 0x02 /* Enables branch target buffer */ +#define PCR0_LOOP 0x04 /* Enables loop */ +#define PCR0_AIS 0x08 /* Enables all instrcutions stalled to + serialize pipe. */ +#define PCR0_MLR 0x10 /* Enables reordering of misaligned loads */ +#define PCR0_BTBRT 0x40 /* Enables BTB test register. */ +#define PCR0_LSSER 0x80 /* Disable reorder */ + +/* Device Identification Registers */ +#define DIR0 0xfe +#define DIR1 0xff + +/* + * The following four 3-byte registers control the non-cacheable regions. + * These registers must be written as three separate bytes. + * + * NCRx+0: A31-A24 of starting address + * NCRx+1: A23-A16 of starting address + * NCRx+2: A15-A12 of starting address | NCR_SIZE_xx. + * + * The non-cacheable region's starting address must be aligned to the + * size indicated by the NCR_SIZE_xx field. + */ +#define NCR1 0xc4 +#define NCR2 0xc7 +#define NCR3 0xca +#define NCR4 0xcd + +#define NCR_SIZE_0K 0 +#define NCR_SIZE_4K 1 +#define NCR_SIZE_8K 2 +#define NCR_SIZE_16K 3 +#define NCR_SIZE_32K 4 +#define NCR_SIZE_64K 5 +#define NCR_SIZE_128K 6 +#define NCR_SIZE_256K 7 +#define NCR_SIZE_512K 8 +#define NCR_SIZE_1M 9 +#define NCR_SIZE_2M 10 +#define NCR_SIZE_4M 11 +#define NCR_SIZE_8M 12 +#define NCR_SIZE_16M 13 +#define NCR_SIZE_32M 14 +#define NCR_SIZE_4G 15 + +/* + * The address region registers are used to specify the location and + * size for the eight address regions. + * + * ARRx + 0: A31-A24 of start address + * ARRx + 1: A23-A16 of start address + * ARRx + 2: A15-A12 of start address | ARR_SIZE_xx + */ +#define ARR0 0xc4 +#define ARR1 0xc7 +#define ARR2 0xca +#define ARR3 0xcd +#define ARR4 0xd0 +#define ARR5 0xd3 +#define ARR6 0xd6 +#define ARR7 0xd9 + +#define ARR_SIZE_0K 0 +#define ARR_SIZE_4K 1 +#define ARR_SIZE_8K 2 +#define ARR_SIZE_16K 3 +#define ARR_SIZE_32K 4 +#define ARR_SIZE_64K 5 +#define ARR_SIZE_128K 6 +#define ARR_SIZE_256K 7 +#define ARR_SIZE_512K 8 +#define ARR_SIZE_1M 9 +#define ARR_SIZE_2M 10 +#define ARR_SIZE_4M 11 +#define ARR_SIZE_8M 12 +#define ARR_SIZE_16M 13 +#define ARR_SIZE_32M 14 +#define ARR_SIZE_4G 15 + +/* + * The region control registers specify the attributes associated with + * the ARRx addres regions. + */ +#define RCR0 0xdc +#define RCR1 0xdd +#define RCR2 0xde +#define RCR3 0xdf +#define RCR4 0xe0 +#define RCR5 0xe1 +#define RCR6 0xe2 +#define RCR7 0xe3 + +#define RCR_RCD 0x01 /* Disables caching for ARRx (x = 0-6). */ +#define RCR_RCE 0x01 /* Enables caching for ARR7. */ +#define RCR_WWO 0x02 /* Weak write ordering. */ +#define RCR_WL 0x04 /* Weak locking. */ +#define RCR_WG 0x08 /* Write gathering. */ +#define RCR_WT 0x10 /* Write-through. */ +#define RCR_NLB 0x20 /* LBA# pin is not asserted. */ + +/* AMD Write Allocate Top-Of-Memory and Control Register */ +#define AMD_WT_ALLOC_TME 0x40000 /* top-of-memory enable */ +#define AMD_WT_ALLOC_PRE 0x20000 /* programmable range enable */ +#define AMD_WT_ALLOC_FRE 0x10000 /* fixed (A0000-FFFFF) range enable */ + + +#ifndef LOCORE +static __inline u_char +read_cyrix_reg(u_char reg) +{ + outb(0x22, reg); + return inb(0x23); +} + +static __inline void +write_cyrix_reg(u_char reg, u_char data) +{ + outb(0x22, reg); + outb(0x23, data); +} +#endif + +#endif /* !_MACHINE_SPECIALREG_H_ */ diff --git a/src/include/machine/spigot.h b/src/include/machine/spigot.h new file mode 100644 index 0000000..8bac527 --- /dev/null +++ b/src/include/machine/spigot.h @@ -0,0 +1,97 @@ +/* + * Video spigot capture driver. + * + * Copyright (c) 1995, Jim Lowe. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * Version 1.2, Aug 30, 1995. + * $FreeBSD: src/sys/i386/include/spigot.h,v 1.5 1999/12/29 04:33:08 peter Exp $ + */ + +#ifndef _MACHINE_SPIGOT_H_ +#define _MACHINE_SPIGOT_H_ + +#include + +struct spigot_info { + unsigned long maddr; + unsigned short irq; +}; + +/* + * Get memory address. + */ +#define SPIGOT_GET_INFO _IOR('s', 4, struct spigot_info) +/* + * Set up a user interrupt. + */ +#define SPIGOT_SETINT _IOW('s', 5, int) +/* + * Allow/disallow access to the I/O Page. + */ +#define SPIGOT_IOPL_ON _IO ('s', 6) +#define SPIGOT_IOPL_OFF _IO ('s', 7) + +#ifndef _KERNEL +/* + * Defines for spigot library. + */ +unsigned short * spigot_open(char *dev); +void spigot_close(void); +void spigot_set_capture_size(int width, int vtof); +unsigned char spigot_start_xfer(int num_frames); +void spigot_stop_xfer(void); +unsigned char spigot_status(void); + +/* + * Define the status bits. + */ +#define SPIGOT_COLOR 0x01 /* Color present (No color) */ +#define SPIGOT_60HZ 0x02 /* 60 hz input signal (50hz) */ +#define SPIGOT_NO_HORIZONTAL_LOCK 0x04 /* Horizontal lock present */ +#define SPIGOT_HPLL_LOCKED 0x08 /* HPLL locked (HPLL unlocked)*/ +#define SPIGOT_VCR_MODE 0x10 /* VCR mode (TV mode) */ +#define SPIGOT_VSYNC_PRESENT 0x20 /* Vsync present */ + +/* + * spigot_open() returns a data address pointing to the spigot data. + * Each read from this address returns the next word. The ``dev'' passed + * is usually "/dev/spigot". Data is described in the phillips desktop + * video data handbook under the 7191 chip. Formats may be either + * YUV 4:2:2 or YUV 4:1:1. A sample device driver for ``nv'' is included + * with this code. + * + * spigot_close() cleans up and closes the device. + * + * spigot_set_capture_size() will set the capture window size. Width should be + * one of: 80, 160, 240, 320, or 640 for NTSC or + * 96, 192, 288, 384 for PAL. + * vtof is the Vertical top of frame offset and must be between 0 and 15 lines. + * + * spigot_start_xfer() will start a transfer from the 7191 to the data fifo. + * spigot_stop_xfer() will clear the data fifo and abort any transfers. + * + * spigot_status() will return the above status bits. + */ +#endif /* !_KERNEL */ + +#endif /* !_MACHINE_SPIGOT_H_ */ diff --git a/src/include/machine/stdarg.h b/src/include/machine/stdarg.h new file mode 100644 index 0000000..0825298 --- /dev/null +++ b/src/include/machine/stdarg.h @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 2002 David E. O'Brien. All rights reserved. + * Copyright (c) 1991, 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. + * + * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD: src/sys/i386/include/stdarg.h,v 1.19 2004/03/12 21:45:31 trhodes Exp $ + */ + +#ifndef _MACHINE_STDARG_H_ +#define _MACHINE_STDARG_H_ + +#include +#include + +#ifndef _VA_LIST_DECLARED +#define _VA_LIST_DECLARED +typedef __va_list va_list; +#endif + +#if (defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)) + +#define va_start(ap, last) \ + __builtin_stdarg_start((ap), (last)) + +#define va_arg(ap, type) \ + __builtin_va_arg((ap), type) + +#if __ISO_C_VISIBLE >= 1999 +#define va_copy(dest, src) \ + __builtin_va_copy((dest), (src)) +#endif + +#define va_end(ap) \ + __builtin_va_end(ap) + +#else /* ! (__GNUC__ post GCC 2.95 || __INTEL_COMPILER) */ + +#define __va_size(type) \ + (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) + +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define va_start(ap, last) \ + ((ap) = (va_list)__builtin_next_arg(last)) +#else /* non-GNU compiler */ +#define va_start(ap, last) \ + ((ap) = (va_list)&(last) + __va_size(last)) +#endif /* __GNUC__ */ + +#define va_arg(ap, type) \ + (*(type *)((ap) += __va_size(type), (ap) - __va_size(type))) + +#if __ISO_C_VISIBLE >= 1999 +#define va_copy(dest, src) \ + ((dest) = (src)) +#endif + +#define va_end(ap) + +#endif /* __GNUC__ post GCC 2.95 */ + +#endif /* !_MACHINE_STDARG_H_ */ diff --git a/src/include/machine/sysarch.h b/src/include/machine/sysarch.h new file mode 100644 index 0000000..f7818d2 --- /dev/null +++ b/src/include/machine/sysarch.h @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 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. + * 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. + * + * $FreeBSD: src/sys/i386/include/sysarch.h,v 1.20 2004/04/07 20:46:05 imp Exp $ + */ + +/* + * Architecture specific syscalls (i386) + */ +#ifndef _MACHINE_SYSARCH_H_ +#define _MACHINE_SYSARCH_H_ + +#define I386_GET_LDT 0 +#define I386_SET_LDT 1 +#define LDT_AUTO_ALLOC 0xffffffff + /* I386_IOPL */ +#define I386_GET_IOPERM 3 +#define I386_SET_IOPERM 4 + /* xxxxx */ +#define I386_VM86 6 + +struct i386_ldt_args { + unsigned int start; + union descriptor *descs; + unsigned int num; +}; + +struct i386_ioperm_args { + unsigned int start; + unsigned int length; + int enable; +}; + +struct i386_vm86_args { + int sub_op; /* sub-operation to perform */ + char *sub_args; /* args */ +}; + +#ifndef _KERNEL +#include + +union descriptor; +struct dbreg; + +__BEGIN_DECLS +int i386_get_ldt(int, union descriptor *, int); +int i386_set_ldt(int, union descriptor *, int); +int i386_get_ioperm(unsigned int, unsigned int *, int *); +int i386_set_ioperm(unsigned int, unsigned int, int); +int i386_vm86(int, void *); +int i386_set_watch(int, unsigned int, int, int, struct dbreg *); +int i386_clr_watch(int, struct dbreg *); +int sysarch(int, void *); +__END_DECLS +#endif + +#endif /* !_MACHINE_SYSARCH_H_ */ diff --git a/src/include/machine/trap.h b/src/include/machine/trap.h new file mode 100644 index 0000000..9f982d6 --- /dev/null +++ b/src/include/machine/trap.h @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)trap.h 5.4 (Berkeley) 5/9/91 + * $FreeBSD: src/sys/i386/include/trap.h,v 1.14 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_TRAP_H_ +#define _MACHINE_TRAP_H_ + +/* + * Trap type values + * also known in trap.c for name strings + */ + +#define T_PRIVINFLT 1 /* privileged instruction */ +#define T_BPTFLT 3 /* breakpoint instruction */ +#define T_ARITHTRAP 6 /* arithmetic trap */ +#define T_PROTFLT 9 /* protection fault */ +#define T_TRCTRAP 10 /* debug exception (sic) */ +#define T_PAGEFLT 12 /* page fault */ +#define T_ALIGNFLT 14 /* alignment fault */ + +#define T_DIVIDE 18 /* integer divide fault */ +#define T_NMI 19 /* non-maskable trap */ +#define T_OFLOW 20 /* overflow trap */ +#define T_BOUND 21 /* bound instruction fault */ +#define T_DNA 22 /* device not available fault */ +#define T_DOUBLEFLT 23 /* double fault */ +#define T_FPOPFLT 24 /* fp coprocessor operand fetch fault */ +#define T_TSSFLT 25 /* invalid tss fault */ +#define T_SEGNPFLT 26 /* segment not present fault */ +#define T_STKFLT 27 /* stack fault */ +#define T_MCHK 28 /* machine check trap */ +#define T_XMMFLT 29 /* SIMD floating-point exception */ +#define T_RESERVED 30 /* reserved (unknown) */ + +/* XXX most of the following codes aren't used, but could be. */ + +/* definitions for */ +#define ILL_RESAD_FAULT T_RESADFLT +#define ILL_PRIVIN_FAULT T_PRIVINFLT +#define ILL_RESOP_FAULT T_RESOPFLT +#define ILL_ALIGN_FAULT T_ALIGNFLT +#define ILL_FPOP_FAULT T_FPOPFLT /* coprocessor operand fault */ + +/* portable macros for SIGFPE/ARITHTRAP */ +#define FPE_INTOVF 1 /* integer overflow */ +#define FPE_INTDIV 2 /* integer divide by zero */ +#define FPE_FLTDIV 3 /* floating point divide by zero */ +#define FPE_FLTOVF 4 /* floating point overflow */ +#define FPE_FLTUND 5 /* floating point underflow */ +#define FPE_FLTRES 6 /* floating point inexact result */ +#define FPE_FLTINV 7 /* invalid floating point operation */ +#define FPE_FLTSUB 8 /* subscript out of range */ + +/* old FreeBSD macros, deprecated */ +#define FPE_INTOVF_TRAP 0x1 /* integer overflow */ +#define FPE_INTDIV_TRAP 0x2 /* integer divide by zero */ +#define FPE_FLTDIV_TRAP 0x3 /* floating/decimal divide by zero */ +#define FPE_FLTOVF_TRAP 0x4 /* floating overflow */ +#define FPE_FLTUND_TRAP 0x5 /* floating underflow */ +#define FPE_FPU_NP_TRAP 0x6 /* floating point unit not present */ +#define FPE_SUBRNG_TRAP 0x7 /* subrange out of bounds */ + +/* codes for SIGBUS */ +#define BUS_PAGE_FAULT T_PAGEFLT /* page fault protection base */ +#define BUS_SEGNP_FAULT T_SEGNPFLT /* segment not present */ +#define BUS_STK_FAULT T_STKFLT /* stack segment */ +#define BUS_SEGM_FAULT T_RESERVED /* segment protection base */ + +/* Trap's coming from user mode */ +#define T_USER 0x100 + +#endif /* !_MACHINE_TRAP_H_ */ diff --git a/src/include/machine/tss.h b/src/include/machine/tss.h new file mode 100644 index 0000000..8dc2910 --- /dev/null +++ b/src/include/machine/tss.h @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)tss.h 5.4 (Berkeley) 1/18/91 + * $FreeBSD: src/sys/i386/include/tss.h,v 1.14 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_TSS_H_ +#define _MACHINE_TSS_H_ 1 + +/* + * Intel 386 Context Data Type + */ + +struct i386tss { + int tss_link; /* actually 16 bits: top 16 bits must be zero */ + int tss_esp0; /* kernel stack pointer privilege level 0 */ + int tss_ss0; /* actually 16 bits: top 16 bits must be zero */ + int tss_esp1; /* kernel stack pointer privilege level 1 */ + int tss_ss1; /* actually 16 bits: top 16 bits must be zero */ + int tss_esp2; /* kernel stack pointer privilege level 2 */ + int tss_ss2; /* actually 16 bits: top 16 bits must be zero */ + int tss_cr3; /* page table directory */ + int tss_eip; /* program counter */ + int tss_eflags; /* program status longword */ + int tss_eax; + int tss_ecx; + int tss_edx; + int tss_ebx; + int tss_esp; /* user stack pointer */ + int tss_ebp; /* user frame pointer */ + int tss_esi; + int tss_edi; + int tss_es; /* actually 16 bits: top 16 bits must be zero */ + int tss_cs; /* actually 16 bits: top 16 bits must be zero */ + int tss_ss; /* actually 16 bits: top 16 bits must be zero */ + int tss_ds; /* actually 16 bits: top 16 bits must be zero */ + int tss_fs; /* actually 16 bits: top 16 bits must be zero */ + int tss_gs; /* actually 16 bits: top 16 bits must be zero */ + int tss_ldt; /* actually 16 bits: top 16 bits must be zero */ + int tss_ioopt; /* options & io offset bitmap: currently zero */ + /* XXX unimplemented .. i/o permission bitmap */ +}; + +#endif /* _MACHINE_TSS_H_ */ diff --git a/src/include/machine/ucontext.h b/src/include/machine/ucontext.h new file mode 100644 index 0000000..2e43dff --- /dev/null +++ b/src/include/machine/ucontext.h @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 1999 Marcel Moolenaar + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/ucontext.h,v 1.10 2002/12/02 19:58:55 deischen Exp $ + */ + +#ifndef _MACHINE_UCONTEXT_H_ +#define _MACHINE_UCONTEXT_H_ + +typedef struct __mcontext { + /* + * The first 20 fields must match the definition of + * sigcontext. So that we can support sigcontext + * and ucontext_t at the same time. + */ + int mc_onstack; /* XXX - sigcontext compat. */ + int mc_gs; /* machine state (struct trapframe) */ + int mc_fs; + int mc_es; + int mc_ds; + int mc_edi; + int mc_esi; + int mc_ebp; + int mc_isp; + int mc_ebx; + int mc_edx; + int mc_ecx; + int mc_eax; + int mc_trapno; + int mc_err; + int mc_eip; + int mc_cs; + int mc_eflags; + int mc_esp; + int mc_ss; + + int mc_len; /* sizeof(mcontext_t) */ +#define _MC_FPFMT_NODEV 0x10000 /* device not present or configured */ +#define _MC_FPFMT_387 0x10001 +#define _MC_FPFMT_XMM 0x10002 + int mc_fpformat; +#define _MC_FPOWNED_NONE 0x20000 /* FP state not used */ +#define _MC_FPOWNED_FPU 0x20001 /* FP state came from FPU */ +#define _MC_FPOWNED_PCB 0x20002 /* FP state came from PCB */ + int mc_ownedfp; + int mc_spare1[1]; /* align next field to 16 bytes */ + /* + * See for the internals of mc_fpstate[]. + */ + int mc_fpstate[128] __aligned(16); + int mc_spare2[8]; +} mcontext_t; + +#if defined(_KERNEL) && defined(COMPAT_FREEBSD4) +struct mcontext4 { + int mc_onstack; /* XXX - sigcontext compat. */ + int mc_gs; /* machine state (struct trapframe) */ + int mc_fs; + int mc_es; + int mc_ds; + int mc_edi; + int mc_esi; + int mc_ebp; + int mc_isp; + int mc_ebx; + int mc_edx; + int mc_ecx; + int mc_eax; + int mc_trapno; + int mc_err; + int mc_eip; + int mc_cs; + int mc_eflags; + int mc_esp; /* machine state */ + int mc_ss; + int mc_fpregs[28]; /* env87 + fpacc87 + u_long */ + int __spare__[17]; +}; +#endif + +#endif /* !_MACHINE_UCONTEXT_H_ */ diff --git a/src/include/machine/varargs.h b/src/include/machine/varargs.h new file mode 100644 index 0000000..abfad23 --- /dev/null +++ b/src/include/machine/varargs.h @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2002 David E. O'Brien. All rights reserved. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)varargs.h 8.2 (Berkeley) 3/22/94 + * $FreeBSD: src/sys/i386/include/varargs.h,v 1.13 2004/04/07 20:46:05 imp Exp $ + */ + +#ifndef _MACHINE_VARARGS_H_ +#define _MACHINE_VARARGS_H_ + +#if defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ > 95 || __GNUC__ >= 3) + +#include + +#ifndef _VA_LIST_DECLARED +#define _VA_LIST_DECLARED +typedef __va_list va_list; +#endif + +typedef int __builtin_va_alist_t __attribute__((__mode__(__word__))); + +#define va_alist __builtin_va_alist +#define va_dcl __builtin_va_alist_t __builtin_va_alist; ... +#define va_start(ap) __builtin_varargs_start(ap) +#define va_arg(ap, type) __builtin_va_arg((ap), type) +#define va_end(ap) __builtin_va_end(ap) + +#else /* ! __GNUC__ post GCC 2.95 */ + +typedef char *va_list; + +#define __va_size(type) \ + (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) + +#ifdef __GNUC__ +#define va_alist __builtin_va_alist +#endif +#if __GNUC__ > 1 +#define va_dcl int va_alist; ... +#else +#define va_dcl int va_alist; +#endif + +#define va_start(ap) \ + ((ap) = (va_list)&va_alist) + +#define va_arg(ap, type) \ + (*(type *)((ap) += __va_size(type), (ap) - __va_size(type))) + +#define va_end(ap) + +#endif /* __GNUC__ post GCC 2.95 */ + +#endif /* !_MACHINE_VARARGS_H_ */ diff --git a/src/include/machine/vm86.h b/src/include/machine/vm86.h new file mode 100644 index 0000000..2b1d233 --- /dev/null +++ b/src/include/machine/vm86.h @@ -0,0 +1,164 @@ +/*- + * Copyright (c) 1997 Jonathan Lemon + * All rights reserved. + * + * Derived from register.h, which is + * Copyright (c) 1996 Michael Smith. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/i386/include/vm86.h,v 1.17 2002/11/07 01:34:23 davidxu Exp $ + */ + +#ifndef _MACHINE_VM86_H_ +#define _MACHINE_VM86_H_ 1 + +/* standard register representation */ +typedef union { + u_int r_ex; + struct { + u_short r_x; + u_int :16; + } r_w; + struct { + u_char r_l; + u_char r_h; + u_int :16; + } r_b; +} reg86_t; + +/* layout must match definition of struct trapframe_vm86 in */ + +struct vm86frame { + int kernel_fs; + int kernel_es; + int kernel_ds; + reg86_t edi; + reg86_t esi; + reg86_t ebp; + reg86_t isp; + reg86_t ebx; + reg86_t edx; + reg86_t ecx; + reg86_t eax; + int vmf_trapno; + int vmf_err; + reg86_t eip; + reg86_t cs; + reg86_t eflags; + reg86_t esp; + reg86_t ss; + reg86_t es; + reg86_t ds; + reg86_t fs; + reg86_t gs; +#define vmf_ah eax.r_b.r_h +#define vmf_al eax.r_b.r_l +#define vmf_ax eax.r_w.r_x +#define vmf_eax eax.r_ex +#define vmf_bh ebx.r_b.r_h +#define vmf_bl ebx.r_b.r_l +#define vmf_bx ebx.r_w.r_x +#define vmf_ebx ebx.r_ex +#define vmf_ch ecx.r_b.r_h +#define vmf_cl ecx.r_b.r_l +#define vmf_cx ecx.r_w.r_x +#define vmf_ecx ecx.r_ex +#define vmf_dh edx.r_b.r_h +#define vmf_dl edx.r_b.r_l +#define vmf_dx edx.r_w.r_x +#define vmf_edx edx.r_ex +#define vmf_si esi.r_w.r_x +#define vmf_di edi.r_w.r_x +#define vmf_cs cs.r_w.r_x +#define vmf_ds ds.r_w.r_x +#define vmf_es es.r_w.r_x +#define vmf_ss ss.r_w.r_x +#define vmf_sp esp.r_w.r_x +#define vmf_ip eip.r_w.r_x +#define vmf_flags eflags.r_w.r_x +#define vmf_eflags eflags.r_ex +}; + +#define VM86_PMAPSIZE 3 +#define VMAP_MALLOC 1 /* page was malloced by us */ + +struct vm86context { + int npages; + struct vm86pmap { + int flags; + int pte_num; + vm_offset_t kva; + u_int old_pte; + } pmap[VM86_PMAPSIZE]; +}; + +#define VM_USERCHANGE (PSL_USERCHANGE | PSL_RF) +#define VME_USERCHANGE (VM_USERCHANGE | PSL_VIP | PSL_VIF) + +struct vm86_kernel { + caddr_t vm86_intmap; /* interrupt map */ + u_int vm86_eflags; /* emulated flags */ + int vm86_has_vme; /* VME support */ + int vm86_inited; /* we were initialized */ + int vm86_debug; + caddr_t vm86_sproc; /* address of sproc */ +}; + +#define VM86_INIT 1 +#define VM86_SET_VME 2 +#define VM86_GET_VME 3 +#define VM86_INTCALL 4 + +struct vm86_init_args { + int debug; /* debug flag */ + int cpu_type; /* cpu type to emulate */ + u_char int_map[32]; /* interrupt map */ +}; + +struct vm86_vme_args { + int state; /* status */ +}; + +struct vm86_intcall_args { + int intnum; + struct vm86frame vmf; +}; + +#ifdef _KERNEL +extern int vm86paddr; + +struct thread; +extern int vm86_emulate(struct vm86frame *); +extern int vm86_sysarch(struct thread *, char *); +extern void vm86_trap(struct vm86frame *); +extern int vm86_intcall(int, struct vm86frame *); +extern int vm86_datacall(int, struct vm86frame *, struct vm86context *); +extern void vm86_initialize(void); +extern vm_offset_t vm86_getpage(struct vm86context *, int); +extern vm_offset_t vm86_addpage(struct vm86context *, int, vm_offset_t); +extern int vm86_getptr(struct vm86context *, vm_offset_t, u_short *, u_short *); + +extern vm_offset_t vm86_getaddr(struct vm86context *, u_short, u_short); +#endif /* _KERNEL */ + +#endif /* _MACHINE_VM86_H_ */ diff --git a/src/include/machine/vmparam.h b/src/include/machine/vmparam.h new file mode 100644 index 0000000..bcf3490 --- /dev/null +++ b/src/include/machine/vmparam.h @@ -0,0 +1,137 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 1994 John S. Dyson + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 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. + * + * from: @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + * $FreeBSD: src/sys/i386/include/vmparam.h,v 1.38 2004/04/07 20:46:05 imp Exp $ + */ + + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ 1 + +/* + * Machine dependent constants for 386. + */ + +#define VM_PROT_READ_IS_EXEC /* if you can read -- then you can exec */ + +/* + * Virtual memory related constants, all in bytes + */ +#define MAXTSIZ (128UL*1024*1024) /* max text size */ +#ifndef DFLDSIZ +#define DFLDSIZ (128UL*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (512UL*1024*1024) /* max data size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (8UL*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (64UL*1024*1024) /* max stack size */ +#endif +#ifndef SGROWSIZ +#define SGROWSIZ (128UL*1024) /* amount to grow stack */ +#endif + +#define USRTEXT (1*PAGE_SIZE) /* base of user text XXX bogus */ + +/* + * The time for a process to be blocked before being very swappable. + * This is a number of seconds which the system takes as being a non-trivial + * amount of real time. You probably shouldn't change this; + * it is used in subtle ways (fractions and multiples of it are, that is, like + * half of a ``long time'', almost a long time, etc.) + * It is related to human patience and other factors which don't really + * change over time. + */ +#define MAXSLP 20 + + +/* + * Kernel physical load address. + */ +#ifndef KERNLOAD +#define KERNLOAD (1 << PDRSHIFT) +#endif + +/* + * Virtual addresses of things. Derived from the page directory and + * page table indexes from pmap.h for precision. + * Because of the page that is both a PD and PT, it looks a little + * messy at times, but hey, we'll do anything to save a page :-) + */ + +#define VM_MAX_KERNEL_ADDRESS VADDR(KPTDI+NKPDE-1, NPTEPG-1) +#define VM_MIN_KERNEL_ADDRESS VADDR(PTDPTDI, PTDPTDI) + +#define KERNBASE VADDR(KPTDI, 0) + +#define UPT_MAX_ADDRESS VADDR(PTDPTDI, PTDPTDI) +#define UPT_MIN_ADDRESS VADDR(PTDPTDI, 0) + +#define VM_MAXUSER_ADDRESS VADDR(PTDPTDI, 0) + +#define USRSTACK VM_MAXUSER_ADDRESS + +#define VM_MAX_ADDRESS VADDR(PTDPTDI, PTDPTDI) +#define VM_MIN_ADDRESS ((vm_offset_t)0) + +/* virtual sizes (bytes) for various kernel submaps */ +#ifndef VM_KMEM_SIZE +#define VM_KMEM_SIZE (12 * 1024 * 1024) +#endif + +/* + * How many physical pages per KVA page allocated. + * min(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE), VM_KMEM_SIZE_MAX) + * is the total KVA space allocated for kmem_map. + */ +#ifndef VM_KMEM_SIZE_SCALE +#define VM_KMEM_SIZE_SCALE (3) +#endif + +/* + * Ceiling on amount of kmem_map kva space. + */ +#ifndef VM_KMEM_SIZE_MAX +#define VM_KMEM_SIZE_MAX (200 * 1024 * 1024) +#endif + +/* initial pagein size of beginning of executable file */ +#ifndef VM_INITIAL_PAGEIN +#define VM_INITIAL_PAGEIN 16 +#endif + +#endif /* _MACHINE_VMPARAM_H_ */ diff --git a/src/include/machine/wtio.h b/src/include/machine/wtio.h new file mode 100644 index 0000000..cb40a01 --- /dev/null +++ b/src/include/machine/wtio.h @@ -0,0 +1,30 @@ +#ifndef _MACHINE_WTIO_H +#define _MACHINE_WTIO_H + +/* + * Streamer tape driver for 386bsd and FreeBSD. + * Supports Archive and Wangtek compatible QIC-02/QIC-36 boards. + * + * Copyright (C) 1993 by: + * Sergey Ryzhkov + * Serge Vakulenko + * + * This software is distributed with NO WARRANTIES, not even the implied + * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Authors grant any other persons or organizations permission to use + * or modify this software as long as this message is kept with the software, + * all derivative works or modified versions. + * + * This driver is derived from the old 386bsd Wangtek streamer tape driver, + * made by Robert Baron at CMU, based on Intel sources. + * + * $FreeBSD: src/sys/i386/include/wtio.h,v 1.4 1999/08/28 00:44:28 peter Exp $ + * + */ + +/* formats for printing flags and error values */ +#define WTDS_BITS "\20\1inuse\2read\3write\4start\5rmark\6wmark\7rew\10excep\11vol\12wo\13ro\14wany\15rany\16wp\17timer\20active" +#define WTER_BITS "\20\1eof\2bnl\3uda\4eom\5wrp\6usl\7cni\11por\12erm\13bpe\14bom\15mbd\16ndt\17ill" + +#endif /* _MACHINE_WTIO_H */ diff --git a/src/include/malloc.h b/src/include/malloc.h new file mode 100644 index 0000000..0688aaa --- /dev/null +++ b/src/include/malloc.h @@ -0,0 +1,6 @@ +/* $FreeBSD: src/include/malloc.h,v 1.5 2001/11/07 23:14:31 obrien Exp $ */ +#if __STDC__ +#error " has been replaced by " +#else +#include +#endif diff --git a/src/include/math.h b/src/include/math.h new file mode 100644 index 0000000..a7b5fce --- /dev/null +++ b/src/include/math.h @@ -0,0 +1,415 @@ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * from: @(#)fdlibm.h 5.1 93/09/24 + * $FreeBSD: src/lib/msun/src/math.h,v 1.32 2004/05/07 18:56:31 stefanf Exp $ + */ + +#ifndef _MATH_H_ +#define _MATH_H_ + +#include + +/* + * ANSI/POSIX + */ +extern const union __infinity_un { + unsigned char __uc[8]; + double __ud; +} __infinity; + +extern const union __nan_un { + unsigned char __uc[sizeof(float)]; + float __uf; +} __nan; + +#define HUGE_VAL (__infinity.__ud) + +#if __ISO_C_VISIBLE >= 1999 +#define FP_ILOGB0 (-0x7fffffff - 1) /* INT_MIN */ +#define FP_ILOGBNAN 0x7fffffff /* INT_MAX */ +#define HUGE_VALF (float)HUGE_VAL +#define HUGE_VALL (long double)HUGE_VAL +#define INFINITY HUGE_VALF +#define NAN (__nan.__uf) + +#define MATH_ERRNO 1 +#define MATH_ERREXCEPT 2 +#define math_errhandling 0 + +/* Symbolic constants to classify floating point numbers. */ +#define FP_INFINITE 0x01 +#define FP_NAN 0x02 +#define FP_NORMAL 0x04 +#define FP_SUBNORMAL 0x08 +#define FP_ZERO 0x10 +#define fpclassify(x) \ + ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ + : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ + : __fpclassifyl(x)) + +#define isfinite(x) ((fpclassify(x) & (FP_INFINITE|FP_NAN)) == 0) +#define isinf(x) (fpclassify(x) == FP_INFINITE) +#define isnan(x) (fpclassify(x) == FP_NAN) +#define isnormal(x) (fpclassify(x) == FP_NORMAL) + +#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) +#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) +#define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) +#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) +#define islessgreater(x, y) (!isunordered((x), (y)) && \ + ((x) > (y) || (y) > (x))) +#define isunordered(x, y) (isnan(x) || isnan(y)) + +#define signbit(x) __signbit(x) + +typedef __double_t double_t; +typedef __float_t float_t; +#endif /* __ISO_C_VISIBLE >= 1999 */ + +/* + * XOPEN/SVID + */ +#if __BSD_VISIBLE || __XSI_VISIBLE +#define M_E 2.7182818284590452354 /* e */ +#define M_LOG2E 1.4426950408889634074 /* log 2e */ +#define M_LOG10E 0.43429448190325182765 /* log 10e */ +#define M_LN2 0.69314718055994530942 /* log e2 */ +#define M_LN10 2.30258509299404568402 /* log e10 */ +#define M_PI 3.14159265358979323846 /* pi */ +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#define M_PI_4 0.78539816339744830962 /* pi/4 */ +#define M_1_PI 0.31830988618379067154 /* 1/pi */ +#define M_2_PI 0.63661977236758134308 /* 2/pi */ +#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ +#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ + +#define MAXFLOAT ((float)3.40282346638528860e+38) +extern int signgam; +#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ + +#if __BSD_VISIBLE +enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; + +#define _LIB_VERSION_TYPE enum fdversion +#define _LIB_VERSION _fdlib_version + +/* if global variable _LIB_VERSION is not desirable, one may + * change the following to be a constant by: + * #define _LIB_VERSION_TYPE const enum version + * In that case, after one initializes the value _LIB_VERSION (see + * s_lib_version.c) during compile time, it cannot be modified + * in the middle of a program + */ +extern _LIB_VERSION_TYPE _LIB_VERSION; + +#define _IEEE_ fdlibm_ieee +#define _SVID_ fdlibm_svid +#define _XOPEN_ fdlibm_xopen +#define _POSIX_ fdlibm_posix + +/* We have a problem when using C++ since `exception' is a reserved + name in C++. */ +#ifndef __cplusplus +struct exception { + int type; + char *name; + double arg1; + double arg2; + double retval; +}; +#endif + +#define isnanf(x) isnan(x) + +#if 0 +/* Old value from 4.4BSD-Lite math.h; this is probably better. */ +#define HUGE HUGE_VAL +#else +#define HUGE MAXFLOAT +#endif + +#define X_TLOSS 1.41484755040568800000e+16 /* pi*2**52 */ + +#define DOMAIN 1 +#define SING 2 +#define OVERFLOW 3 +#define UNDERFLOW 4 +#define TLOSS 5 +#define PLOSS 6 + +#endif /* __BSD_VISIBLE */ + +#include + +/* + * Most of these functions have the side effect of setting errno, so they + * are not declared as __pure2. (XXX: this point needs to be revisited, + * since C99 doesn't require the mistake of setting errno, and we mostly + * don't set it anyway. In C99, pragmas and functions for changing the + * rounding mode affect the purity of these functions.) + */ +__BEGIN_DECLS +/* + * ANSI/POSIX + */ +int __fpclassifyd(double) __pure2; +int __fpclassifyf(float) __pure2; +int __fpclassifyl(long double) __pure2; +int __signbit(double) __pure2; + +double acos(double); +double asin(double); +double atan(double); +double atan2(double, double); +double cos(double); +double sin(double); +double tan(double); + +double cosh(double); +double sinh(double); +double tanh(double); + +double exp(double); +double frexp(double, int *); /* fundamentally !__pure2 */ +double ldexp(double, int); +double log(double); +double log10(double); +double modf(double, double *); /* fundamentally !__pure2 */ + +double pow(double, double); +double sqrt(double); + +double ceil(double); +double fabs(double); +double floor(double); +double fmod(double, double); + +/* + * These functions are not in C90 so they can be "right". The ones that + * never set errno in lib/msun are declared as __pure2. + */ +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE +double acosh(double); +double asinh(double); +double atanh(double); +double cbrt(double) __pure2; +double erf(double); +double erfc(double) __pure2; +double expm1(double) __pure2; +double hypot(double, double); +int ilogb(double); +double lgamma(double); +double log1p(double) __pure2; +double logb(double) __pure2; +double nextafter(double, double); +double remainder(double, double); +double rint(double) __pure2; +#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */ + +#if __BSD_VISIBLE || __XSI_VISIBLE +double j0(double); +double j1(double); +double jn(int, double); +double scalb(double, double); +double y0(double); +double y1(double); +double yn(int, double); + +#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE +double gamma(double); +#endif +#endif /* __BSD_VISIBLE || __XSI_VISIBLE */ + +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 +double copysign(double, double) __pure2; +double scalbn(double, int); +double tgamma(double); +#endif + +/* + * BSD math library entry points + */ +#if __BSD_VISIBLE +double drem(double, double); +int finite(double) __pure2; + +/* + * Reentrant version of gamma & lgamma; passes signgam back by reference + * as the second argument; user must allocate space for signgam. + */ +double gamma_r(double, int *); +double lgamma_r(double, int *); + +/* + * IEEE Test Vector + */ +double significand(double); + +#ifndef __cplusplus +int matherr(struct exception *); +#endif +#endif /* __BSD_VISIBLE */ + +/* float versions of ANSI/POSIX functions */ +#if __ISO_C_VISIBLE >= 1999 +float acosf(float); +float asinf(float); +float atanf(float); +float atan2f(float, float); +float cosf(float); +float sinf(float); +float tanf(float); + +float coshf(float); +float sinhf(float); +float tanhf(float); + +float expf(float); +float expm1f(float) __pure2; +float frexpf(float, int *); /* fundamentally !__pure2 */ +int ilogbf(float); +float ldexpf(float, int); +float log10f(float); +float log1pf(float) __pure2; +float logf(float); +float modff(float, float *); /* fundamentally !__pure2 */ + +float powf(float, float); +float sqrtf(float); + +float ceilf(float); +float fabsf(float); +float floorf(float); +float fmodf(float, float); + +float erff(float); +float erfcf(float) __pure2; +float hypotf(float, float) __pure2; +float lgammaf(float); + +float acoshf(float); +float asinhf(float); +float atanhf(float); +float cbrtf(float) __pure2; +float logbf(float) __pure2; +float copysignf(float, float) __pure2; +float nextafterf(float, float); +float remainderf(float, float); +float rintf(float); +float scalbnf(float, int); +#endif + +/* + * float versions of BSD math library entry points + */ +#if __BSD_VISIBLE +float dremf(float, float); +int finitef(float) __pure2; +float gammaf(float); +float j0f(float); +float j1f(float); +float jnf(int, float); +float scalbf(float, float); +float y0f(float); +float y1f(float); +float ynf(int, float); + +/* + * Float versions of reentrant version of gamma & lgamma; passes + * signgam back by reference as the second argument; user must + * allocate space for signgam. + */ +float gammaf_r(float, int *); +float lgammaf_r(float, int *); + +/* + * float version of IEEE Test Vector + */ +float significandf(float); +#endif /* __BSD_VISIBLE */ + +/* + * long double versions of ISO/POSIX math functions + */ +#if __ISO_C_VISIBLE >= 1999 +#if 0 +long double acoshl(long double); +long double acosl(long double); +long double asinhl(long double); +long double asinl(long double); +long double atan2l(long double, long double); +long double atanhl(long double); +long double atanl(long double); +long double cbrtl(long double); +long double ceill(long double); +#endif +long double copysignl(long double, long double); +#if 0 +long double coshl(long double); +long double cosl(long double); +long double erfcl(long double); +long double erfl(long double); +long double exp2l(long double); +long double expl(long double); +long double expm1l(long double); +#endif +long double fabsl(long double); +#if 0 +long double fdiml(long double, long double); +long double floorl(long double); +long double fmal(long double, long double, long double); +long double fmaxl(long double, long double); +long double fminl(long double, long double); +long double fmodl(long double, long double); +long double frexpl(long double value, int *); +long double hypotl(long double, long double); +int ilogbl(long double); +long double ldexpl(long double, int); +long double lgammal(long double); +long long llrintl(long double); +long long llroundl(long double); +long double log10l(long double); +long double log1pl(long double); +long double log2l(long double); +long double logbl(long double); +long double logl(long double); +long lrintl(long double); +long lroundl(long double); +long double modfl(long double, long double *); +long double nanl(const char *); +long double nearbyintl(long double); +long double nextafterl(long double, long double); +double nexttoward(double, long double); +float nexttowardf(float, long double); +long double nexttowardl(long double, long double); +long double powl(long double, long double); +long double remainderl(long double, long double); +long double remquol(long double, long double, int *); +long double rintl(long double); +long double roundl(long double); +long double scalblnl(long double, long); +long double scalbnl(long double, int); +long double sinhl(long double); +long double sinl(long double); +long double sqrtl(long double); +long double tanhl(long double); +long double tanl(long double); +long double tgammal(long double); +long double truncl(long double); +#endif + +#endif /* __ISO_C_VISIBLE >= 1999 */ +__END_DECLS + +#endif /* !_MATH_H_ */ diff --git a/src/include/md2.h b/src/include/md2.h new file mode 100644 index 0000000..4b1adef --- /dev/null +++ b/src/include/md2.h @@ -0,0 +1,46 @@ +/* MD2.H - header file for MD2C.C + * $FreeBSD: src/lib/libmd/md2.h,v 1.9 2001/03/17 10:00:50 phk Exp $ + */ + +/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All + rights reserved. + + License to copy and use this software is granted for + non-commercial Internet Privacy-Enhanced Mail provided that it is + identified as the "RSA Data Security, Inc. MD2 Message Digest + Algorithm" in all material mentioning or referencing this software + or this function. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. + */ + +#ifndef _MD2_H_ +#define _MD2_H_ + +typedef struct MD2Context { + unsigned char state[16]; /* state */ + unsigned char checksum[16]; /* checksum */ + unsigned int count; /* number of bytes, modulo 16 */ + unsigned char buffer[16]; /* input buffer */ +} MD2_CTX; + +#include + +__BEGIN_DECLS +void MD2Init(MD2_CTX *); +void MD2Update(MD2_CTX *, const unsigned char *, unsigned int); +void MD2Pad(MD2_CTX *); +void MD2Final(unsigned char [16], MD2_CTX *); +char * MD2End(MD2_CTX *, char *); +char * MD2File(const char *, char *); +char * MD2FileChunk(const char *, char *, off_t, off_t); +char * MD2Data(const unsigned char *, unsigned int, char *); +__END_DECLS + +#endif /* _MD2_H_ */ diff --git a/src/include/md4.h b/src/include/md4.h new file mode 100644 index 0000000..0c2eaed --- /dev/null +++ b/src/include/md4.h @@ -0,0 +1,48 @@ +/* MD4.H - header file for MD4C.C + * $FreeBSD: src/lib/libmd/md4.h,v 1.10 2001/03/17 10:00:50 phk Exp $ + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD4 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD4 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. + */ + +#ifndef _MD4_H_ +#define _MD4_H_ +/* MD4 context. */ +typedef struct MD4Context { + u_int32_t state[4]; /* state (ABCD) */ + u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD4_CTX; + +#include + +__BEGIN_DECLS +void MD4Init(MD4_CTX *); +void MD4Update(MD4_CTX *, const unsigned char *, unsigned int); +void MD4Pad(MD4_CTX *); +void MD4Final(unsigned char [16], MD4_CTX *); +char * MD4End(MD4_CTX *, char *); +char * MD4File(const char *, char *); +char * MD4FileChunk(const char *, char *, off_t, off_t); +char * MD4Data(const unsigned char *, unsigned int, char *); +__END_DECLS + +#endif /* _MD4_H_ */ diff --git a/src/include/md5.h b/src/include/md5.h new file mode 100644 index 0000000..803a88f --- /dev/null +++ b/src/include/md5.h @@ -0,0 +1,4 @@ +#ifndef _MD5_H_ +#define _MD5_H_ +#include +#endif /* _MD5_H_ */ diff --git a/src/include/memory.h b/src/include/memory.h new file mode 100644 index 0000000..cb9c8b5 --- /dev/null +++ b/src/include/memory.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 1988, 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. + * + * @(#)memory.h 8.1 (Berkeley) 6/2/93 + */ + +#include diff --git a/src/include/menu.h b/src/include/menu.h new file mode 100644 index 0000000..8c12894 --- /dev/null +++ b/src/include/menu.h @@ -0,0 +1,254 @@ +/**************************************************************************** + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Juergen Pfeifer 1995,1997 * + ****************************************************************************/ + +#ifndef ETI_MENU +#define ETI_MENU + +#ifdef AMIGA +#define TEXT TEXT_ncurses +#endif + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int Menu_Options; +typedef int Item_Options; + +/* Menu options: */ +#define O_ONEVALUE (0x01) +#define O_SHOWDESC (0x02) +#define O_ROWMAJOR (0x04) +#define O_IGNORECASE (0x08) +#define O_SHOWMATCH (0x10) +#define O_NONCYCLIC (0x20) + +/* Item options: */ +#define O_SELECTABLE (0x01) + +typedef struct +{ + const char* str; + unsigned short length; +} TEXT; + +typedef struct tagITEM +{ + TEXT name; /* name of menu item */ + TEXT description; /* description of item, optional in display */ + struct tagMENU *imenu; /* Pointer to parent menu */ + void *userptr; /* Pointer to user defined per item data */ + Item_Options opt; /* Item options */ + short index; /* Item number if connected to a menu */ + short y; /* y and x location of item in menu */ + short x; + bool value; /* Selection value */ + + struct tagITEM *left; /* neighbour items */ + struct tagITEM *right; + struct tagITEM *up; + struct tagITEM *down; + +} ITEM; + +typedef void (*Menu_Hook)(struct tagMENU *); + +typedef struct tagMENU +{ + short height; /* Nr. of chars high */ + short width; /* Nr. of chars wide */ + short rows; /* Nr. of items high */ + short cols; /* Nr. of items wide */ + short frows; /* Nr. of formatted items high */ + short fcols; /* Nr. of formatted items wide */ + short arows; /* Nr. of items high (actual) */ + short namelen; /* Max. name length */ + short desclen; /* Max. description length */ + short marklen; /* Length of mark, if any */ + short itemlen; /* Length of one item */ + short spc_desc; /* Spacing for descriptor */ + short spc_cols; /* Spacing for columns */ + short spc_rows; /* Spacing for rows */ + char *pattern; /* Buffer to store match chars */ + short pindex; /* Index into pattern buffer */ + WINDOW *win; /* Window containing menu */ + WINDOW *sub; /* Subwindow for menu display */ + WINDOW *userwin; /* User's window */ + WINDOW *usersub; /* User's subwindow */ + ITEM **items; /* array of items */ + short nitems; /* Nr. of items in menu */ + ITEM *curitem; /* Current item */ + short toprow; /* Top row of menu */ + chtype fore; /* Selection attribute */ + chtype back; /* Nonselection attribute */ + chtype grey; /* Inactive attribute */ + unsigned char pad; /* Pad character */ + + Menu_Hook menuinit; /* User hooks */ + Menu_Hook menuterm; + Menu_Hook iteminit; + Menu_Hook itemterm; + + void *userptr; /* Pointer to menus user data */ + char *mark; /* Pointer to marker string */ + + Menu_Options opt; /* Menu options */ + unsigned short status; /* Internal state of menu */ + +} MENU; + + +/* Define keys */ + +#define REQ_LEFT_ITEM (KEY_MAX + 1) +#define REQ_RIGHT_ITEM (KEY_MAX + 2) +#define REQ_UP_ITEM (KEY_MAX + 3) +#define REQ_DOWN_ITEM (KEY_MAX + 4) +#define REQ_SCR_ULINE (KEY_MAX + 5) +#define REQ_SCR_DLINE (KEY_MAX + 6) +#define REQ_SCR_DPAGE (KEY_MAX + 7) +#define REQ_SCR_UPAGE (KEY_MAX + 8) +#define REQ_FIRST_ITEM (KEY_MAX + 9) +#define REQ_LAST_ITEM (KEY_MAX + 10) +#define REQ_NEXT_ITEM (KEY_MAX + 11) +#define REQ_PREV_ITEM (KEY_MAX + 12) +#define REQ_TOGGLE_ITEM (KEY_MAX + 13) +#define REQ_CLEAR_PATTERN (KEY_MAX + 14) +#define REQ_BACK_PATTERN (KEY_MAX + 15) +#define REQ_NEXT_MATCH (KEY_MAX + 16) +#define REQ_PREV_MATCH (KEY_MAX + 17) + +#define MIN_MENU_COMMAND (KEY_MAX + 1) +#define MAX_MENU_COMMAND (KEY_MAX + 17) + +/* + * Some AT&T code expects MAX_COMMAND to be out-of-band not + * just for menu commands but for forms ones as well. + */ +#if defined(MAX_COMMAND) +# if (MAX_MENU_COMMAND > MAX_COMMAND) +# error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND +# elif (MAX_COMMAND != (KEY_MAX + 128)) +# error Something is wrong -- MAX_COMMAND is already inconsistently defined. +# endif +#else +# define MAX_COMMAND (KEY_MAX + 128) +#endif + + +/* --------- prototypes for libmenu functions ----------------------------- */ + +extern NCURSES_EXPORT(ITEM **) menu_items (const MENU *); +extern NCURSES_EXPORT(ITEM *) current_item (const MENU *); +extern NCURSES_EXPORT(ITEM *) new_item (const char *,const char *); + +extern NCURSES_EXPORT(MENU *) new_menu (ITEM **); + +extern NCURSES_EXPORT(Item_Options) item_opts (const ITEM *); +extern NCURSES_EXPORT(Menu_Options) menu_opts (const MENU *); + +extern NCURSES_EXPORT(Menu_Hook) item_init (const MENU *); +extern NCURSES_EXPORT(Menu_Hook) item_term (const MENU *); +extern NCURSES_EXPORT(Menu_Hook) menu_init (const MENU *); +extern NCURSES_EXPORT(Menu_Hook) menu_term (const MENU *); + +extern NCURSES_EXPORT(WINDOW *) menu_sub (const MENU *); +extern NCURSES_EXPORT(WINDOW *) menu_win (const MENU *); + +extern NCURSES_EXPORT(const char *) item_description (const ITEM *); +extern NCURSES_EXPORT(const char *) item_name (const ITEM *); +extern NCURSES_EXPORT(const char *) menu_mark (const MENU *); +extern NCURSES_EXPORT(const char *) menu_request_name (int); + +extern NCURSES_EXPORT(char *) menu_pattern (const MENU *); + +extern NCURSES_EXPORT(void *) menu_userptr (const MENU *); +extern NCURSES_EXPORT(void *) item_userptr (const ITEM *); + +extern NCURSES_EXPORT(chtype) menu_back (const MENU *); +extern NCURSES_EXPORT(chtype) menu_fore (const MENU *); +extern NCURSES_EXPORT(chtype) menu_grey (const MENU *); + +extern NCURSES_EXPORT(int) free_item (ITEM *); +extern NCURSES_EXPORT(int) free_menu (MENU *); +extern NCURSES_EXPORT(int) item_count (const MENU *); +extern NCURSES_EXPORT(int) item_index (const ITEM *); +extern NCURSES_EXPORT(int) item_opts_off (ITEM *,Item_Options); +extern NCURSES_EXPORT(int) item_opts_on (ITEM *,Item_Options); +extern NCURSES_EXPORT(int) menu_driver (MENU *,int); +extern NCURSES_EXPORT(int) menu_opts_off (MENU *,Menu_Options); +extern NCURSES_EXPORT(int) menu_opts_on (MENU *,Menu_Options); +extern NCURSES_EXPORT(int) menu_pad (const MENU *); +extern NCURSES_EXPORT(int) pos_menu_cursor (const MENU *); +extern NCURSES_EXPORT(int) post_menu (MENU *); +extern NCURSES_EXPORT(int) scale_menu (const MENU *,int *,int *); +extern NCURSES_EXPORT(int) set_current_item (MENU *menu,ITEM *item); +extern NCURSES_EXPORT(int) set_item_init (MENU *,void(*)(MENU *)); +extern NCURSES_EXPORT(int) set_item_opts (ITEM *,Item_Options); +extern NCURSES_EXPORT(int) set_item_term (MENU *,void(*)(MENU *)); +extern NCURSES_EXPORT(int) set_item_userptr (ITEM *, void *); +extern NCURSES_EXPORT(int) set_item_value (ITEM *,bool); +extern NCURSES_EXPORT(int) set_menu_back (MENU *,chtype); +extern NCURSES_EXPORT(int) set_menu_fore (MENU *,chtype); +extern NCURSES_EXPORT(int) set_menu_format (MENU *,int,int); +extern NCURSES_EXPORT(int) set_menu_grey (MENU *,chtype); +extern NCURSES_EXPORT(int) set_menu_init (MENU *,void(*)(MENU *)); +extern NCURSES_EXPORT(int) set_menu_items (MENU *,ITEM **); +extern NCURSES_EXPORT(int) set_menu_mark (MENU *, const char *); +extern NCURSES_EXPORT(int) set_menu_opts (MENU *,Menu_Options); +extern NCURSES_EXPORT(int) set_menu_pad (MENU *,int); +extern NCURSES_EXPORT(int) set_menu_pattern (MENU *,const char *); +extern NCURSES_EXPORT(int) set_menu_sub (MENU *,WINDOW *); +extern NCURSES_EXPORT(int) set_menu_term (MENU *,void(*)(MENU *)); +extern NCURSES_EXPORT(int) set_menu_userptr (MENU *,void *); +extern NCURSES_EXPORT(int) set_menu_win (MENU *,WINDOW *); +extern NCURSES_EXPORT(int) set_top_row (MENU *,int); +extern NCURSES_EXPORT(int) top_row (const MENU *); +extern NCURSES_EXPORT(int) unpost_menu (MENU *); +extern NCURSES_EXPORT(int) menu_request_by_name (const char *); +extern NCURSES_EXPORT(int) set_menu_spacing (MENU *,int,int,int); +extern NCURSES_EXPORT(int) menu_spacing (const MENU *,int *,int *,int *); + + +extern NCURSES_EXPORT(bool) item_value (const ITEM *); +extern NCURSES_EXPORT(bool) item_visible (const ITEM *); + +extern NCURSES_EXPORT(void) menu_format (const MENU *,int *,int *); + +#ifdef __cplusplus + } +#endif + +#endif /* ETI_MENU */ diff --git a/src/include/mmintrin.h b/src/include/mmintrin.h new file mode 100644 index 0000000..00e77e4 --- /dev/null +++ b/src/include/mmintrin.h @@ -0,0 +1,917 @@ +/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. + + This file is part of GNU CC. + + GNU CC is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU CC is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU CC; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, if you include this header file into source + files compiled by GCC, this header file does not by itself cause + the resulting executable to be covered by the GNU General Public + License. This exception does not however invalidate any other + reasons why the executable file might be covered by the GNU General + Public License. */ + +/* Implemented from the specification included in the Intel C++ Compiler + User Guide and Reference, version 8.0. */ + +#ifndef _MMINTRIN_H_INCLUDED +#define _MMINTRIN_H_INCLUDED + +#ifndef __MMX__ +# error "MMX instruction set not enabled" +#else +/* The data type intended for user use. */ +typedef int __m64 __attribute__ ((__mode__ (__V2SI__))); + +/* Internal data types for implementing the intrinsics. */ +typedef int __v2si __attribute__ ((__mode__ (__V2SI__))); +typedef int __v4hi __attribute__ ((__mode__ (__V4HI__))); +typedef int __v8qi __attribute__ ((__mode__ (__V8QI__))); + +/* Empty the multimedia state. */ +static __inline void +_mm_empty (void) +{ + __builtin_ia32_emms (); +} + +static __inline void +_m_empty (void) +{ + _mm_empty (); +} + +/* Convert I to a __m64 object. The integer is zero-extended to 64-bits. */ +static __inline __m64 +_mm_cvtsi32_si64 (int __i) +{ + long long __tmp = (unsigned int)__i; + return (__m64) __tmp; +} + +static __inline __m64 +_m_from_int (int __i) +{ + return _mm_cvtsi32_si64 (__i); +} + +#ifdef __x86_64__ +/* Convert I to a __m64 object. */ +static __inline __m64 +_mm_cvtsi64x_si64 (long long __i) +{ + return (__m64) __i; +} + +/* Convert I to a __m64 object. */ +static __inline __m64 +_mm_set_pi64x (long long __i) +{ + return (__m64) __i; +} +#endif + +/* Convert the lower 32 bits of the __m64 object into an integer. */ +static __inline int +_mm_cvtsi64_si32 (__m64 __i) +{ + long long __tmp = (long long)__i; + return __tmp; +} + +static __inline int +_m_to_int (__m64 __i) +{ + return _mm_cvtsi64_si32 (__i); +} + +#ifdef __x86_64__ +/* Convert the lower 32 bits of the __m64 object into an integer. */ +static __inline long long +_mm_cvtsi64_si64x (__m64 __i) +{ + return (long long)__i; +} +#endif + +/* Pack the four 16-bit values from M1 into the lower four 8-bit values of + the result, and the four 16-bit values from M2 into the upper four 8-bit + values of the result, all with signed saturation. */ +static __inline __m64 +_mm_packs_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_packsswb ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_packsswb (__m64 __m1, __m64 __m2) +{ + return _mm_packs_pi16 (__m1, __m2); +} + +/* Pack the two 32-bit values from M1 in to the lower two 16-bit values of + the result, and the two 32-bit values from M2 into the upper two 16-bit + values of the result, all with signed saturation. */ +static __inline __m64 +_mm_packs_pi32 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_packssdw ((__v2si)__m1, (__v2si)__m2); +} + +static __inline __m64 +_m_packssdw (__m64 __m1, __m64 __m2) +{ + return _mm_packs_pi32 (__m1, __m2); +} + +/* Pack the four 16-bit values from M1 into the lower four 8-bit values of + the result, and the four 16-bit values from M2 into the upper four 8-bit + values of the result, all with unsigned saturation. */ +static __inline __m64 +_mm_packs_pu16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_packuswb ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_packuswb (__m64 __m1, __m64 __m2) +{ + return _mm_packs_pu16 (__m1, __m2); +} + +/* Interleave the four 8-bit values from the high half of M1 with the four + 8-bit values from the high half of M2. */ +static __inline __m64 +_mm_unpackhi_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_punpckhbw ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_punpckhbw (__m64 __m1, __m64 __m2) +{ + return _mm_unpackhi_pi8 (__m1, __m2); +} + +/* Interleave the two 16-bit values from the high half of M1 with the two + 16-bit values from the high half of M2. */ +static __inline __m64 +_mm_unpackhi_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_punpckhwd ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_punpckhwd (__m64 __m1, __m64 __m2) +{ + return _mm_unpackhi_pi16 (__m1, __m2); +} + +/* Interleave the 32-bit value from the high half of M1 with the 32-bit + value from the high half of M2. */ +static __inline __m64 +_mm_unpackhi_pi32 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_punpckhdq ((__v2si)__m1, (__v2si)__m2); +} + +static __inline __m64 +_m_punpckhdq (__m64 __m1, __m64 __m2) +{ + return _mm_unpackhi_pi32 (__m1, __m2); +} + +/* Interleave the four 8-bit values from the low half of M1 with the four + 8-bit values from the low half of M2. */ +static __inline __m64 +_mm_unpacklo_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_punpcklbw ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_punpcklbw (__m64 __m1, __m64 __m2) +{ + return _mm_unpacklo_pi8 (__m1, __m2); +} + +/* Interleave the two 16-bit values from the low half of M1 with the two + 16-bit values from the low half of M2. */ +static __inline __m64 +_mm_unpacklo_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_punpcklwd ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_punpcklwd (__m64 __m1, __m64 __m2) +{ + return _mm_unpacklo_pi16 (__m1, __m2); +} + +/* Interleave the 32-bit value from the low half of M1 with the 32-bit + value from the low half of M2. */ +static __inline __m64 +_mm_unpacklo_pi32 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_punpckldq ((__v2si)__m1, (__v2si)__m2); +} + +static __inline __m64 +_m_punpckldq (__m64 __m1, __m64 __m2) +{ + return _mm_unpacklo_pi32 (__m1, __m2); +} + +/* Add the 8-bit values in M1 to the 8-bit values in M2. */ +static __inline __m64 +_mm_add_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_paddb (__m64 __m1, __m64 __m2) +{ + return _mm_add_pi8 (__m1, __m2); +} + +/* Add the 16-bit values in M1 to the 16-bit values in M2. */ +static __inline __m64 +_mm_add_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_paddw (__m64 __m1, __m64 __m2) +{ + return _mm_add_pi16 (__m1, __m2); +} + +/* Add the 32-bit values in M1 to the 32-bit values in M2. */ +static __inline __m64 +_mm_add_pi32 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddd ((__v2si)__m1, (__v2si)__m2); +} + +static __inline __m64 +_m_paddd (__m64 __m1, __m64 __m2) +{ + return _mm_add_pi32 (__m1, __m2); +} + +/* Add the 64-bit values in M1 to the 64-bit values in M2. */ +static __inline __m64 +_mm_add_si64 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddq ((long long)__m1, (long long)__m2); +} + +/* Add the 8-bit values in M1 to the 8-bit values in M2 using signed + saturated arithmetic. */ +static __inline __m64 +_mm_adds_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddsb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_paddsb (__m64 __m1, __m64 __m2) +{ + return _mm_adds_pi8 (__m1, __m2); +} + +/* Add the 16-bit values in M1 to the 16-bit values in M2 using signed + saturated arithmetic. */ +static __inline __m64 +_mm_adds_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddsw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_paddsw (__m64 __m1, __m64 __m2) +{ + return _mm_adds_pi16 (__m1, __m2); +} + +/* Add the 8-bit values in M1 to the 8-bit values in M2 using unsigned + saturated arithmetic. */ +static __inline __m64 +_mm_adds_pu8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddusb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_paddusb (__m64 __m1, __m64 __m2) +{ + return _mm_adds_pu8 (__m1, __m2); +} + +/* Add the 16-bit values in M1 to the 16-bit values in M2 using unsigned + saturated arithmetic. */ +static __inline __m64 +_mm_adds_pu16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_paddusw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_paddusw (__m64 __m1, __m64 __m2) +{ + return _mm_adds_pu16 (__m1, __m2); +} + +/* Subtract the 8-bit values in M2 from the 8-bit values in M1. */ +static __inline __m64 +_mm_sub_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_psubb (__m64 __m1, __m64 __m2) +{ + return _mm_sub_pi8 (__m1, __m2); +} + +/* Subtract the 16-bit values in M2 from the 16-bit values in M1. */ +static __inline __m64 +_mm_sub_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_psubw (__m64 __m1, __m64 __m2) +{ + return _mm_sub_pi16 (__m1, __m2); +} + +/* Subtract the 32-bit values in M2 from the 32-bit values in M1. */ +static __inline __m64 +_mm_sub_pi32 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubd ((__v2si)__m1, (__v2si)__m2); +} + +static __inline __m64 +_m_psubd (__m64 __m1, __m64 __m2) +{ + return _mm_sub_pi32 (__m1, __m2); +} + +/* Add the 64-bit values in M1 to the 64-bit values in M2. */ +static __inline __m64 +_mm_sub_si64 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubq ((long long)__m1, (long long)__m2); +} + +/* Subtract the 8-bit values in M2 from the 8-bit values in M1 using signed + saturating arithmetic. */ +static __inline __m64 +_mm_subs_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubsb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_psubsb (__m64 __m1, __m64 __m2) +{ + return _mm_subs_pi8 (__m1, __m2); +} + +/* Subtract the 16-bit values in M2 from the 16-bit values in M1 using + signed saturating arithmetic. */ +static __inline __m64 +_mm_subs_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubsw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_psubsw (__m64 __m1, __m64 __m2) +{ + return _mm_subs_pi16 (__m1, __m2); +} + +/* Subtract the 8-bit values in M2 from the 8-bit values in M1 using + unsigned saturating arithmetic. */ +static __inline __m64 +_mm_subs_pu8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubusb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_psubusb (__m64 __m1, __m64 __m2) +{ + return _mm_subs_pu8 (__m1, __m2); +} + +/* Subtract the 16-bit values in M2 from the 16-bit values in M1 using + unsigned saturating arithmetic. */ +static __inline __m64 +_mm_subs_pu16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_psubusw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_psubusw (__m64 __m1, __m64 __m2) +{ + return _mm_subs_pu16 (__m1, __m2); +} + +/* Multiply four 16-bit values in M1 by four 16-bit values in M2 producing + four 32-bit intermediate results, which are then summed by pairs to + produce two 32-bit results. */ +static __inline __m64 +_mm_madd_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pmaddwd ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_pmaddwd (__m64 __m1, __m64 __m2) +{ + return _mm_madd_pi16 (__m1, __m2); +} + +/* Multiply four signed 16-bit values in M1 by four signed 16-bit values in + M2 and produce the high 16 bits of the 32-bit results. */ +static __inline __m64 +_mm_mulhi_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pmulhw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_pmulhw (__m64 __m1, __m64 __m2) +{ + return _mm_mulhi_pi16 (__m1, __m2); +} + +/* Multiply four 16-bit values in M1 by four 16-bit values in M2 and produce + the low 16 bits of the results. */ +static __inline __m64 +_mm_mullo_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pmullw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_pmullw (__m64 __m1, __m64 __m2) +{ + return _mm_mullo_pi16 (__m1, __m2); +} + +/* Shift four 16-bit values in M left by COUNT. */ +static __inline __m64 +_mm_sll_pi16 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_psllw ((__v4hi)__m, (long long)__count); +} + +static __inline __m64 +_m_psllw (__m64 __m, __m64 __count) +{ + return _mm_sll_pi16 (__m, __count); +} + +static __inline __m64 +_mm_slli_pi16 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_psllw ((__v4hi)__m, __count); +} + +static __inline __m64 +_m_psllwi (__m64 __m, int __count) +{ + return _mm_slli_pi16 (__m, __count); +} + +/* Shift two 32-bit values in M left by COUNT. */ +static __inline __m64 +_mm_sll_pi32 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_pslld ((__v2si)__m, (long long)__count); +} + +static __inline __m64 +_m_pslld (__m64 __m, __m64 __count) +{ + return _mm_sll_pi32 (__m, __count); +} + +static __inline __m64 +_mm_slli_pi32 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_pslld ((__v2si)__m, __count); +} + +static __inline __m64 +_m_pslldi (__m64 __m, int __count) +{ + return _mm_slli_pi32 (__m, __count); +} + +/* Shift the 64-bit value in M left by COUNT. */ +static __inline __m64 +_mm_sll_si64 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_psllq ((long long)__m, (long long)__count); +} + +static __inline __m64 +_m_psllq (__m64 __m, __m64 __count) +{ + return _mm_sll_si64 (__m, __count); +} + +static __inline __m64 +_mm_slli_si64 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_psllq ((long long)__m, (long long)__count); +} + +static __inline __m64 +_m_psllqi (__m64 __m, int __count) +{ + return _mm_slli_si64 (__m, __count); +} + +/* Shift four 16-bit values in M right by COUNT; shift in the sign bit. */ +static __inline __m64 +_mm_sra_pi16 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_psraw ((__v4hi)__m, (long long)__count); +} + +static __inline __m64 +_m_psraw (__m64 __m, __m64 __count) +{ + return _mm_sra_pi16 (__m, __count); +} + +static __inline __m64 +_mm_srai_pi16 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_psraw ((__v4hi)__m, __count); +} + +static __inline __m64 +_m_psrawi (__m64 __m, int __count) +{ + return _mm_srai_pi16 (__m, __count); +} + +/* Shift two 32-bit values in M right by COUNT; shift in the sign bit. */ +static __inline __m64 +_mm_sra_pi32 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_psrad ((__v2si)__m, (long long)__count); +} + +static __inline __m64 +_m_psrad (__m64 __m, __m64 __count) +{ + return _mm_sra_pi32 (__m, __count); +} + +static __inline __m64 +_mm_srai_pi32 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_psrad ((__v2si)__m, __count); +} + +static __inline __m64 +_m_psradi (__m64 __m, int __count) +{ + return _mm_srai_pi32 (__m, __count); +} + +/* Shift four 16-bit values in M right by COUNT; shift in zeros. */ +static __inline __m64 +_mm_srl_pi16 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_psrlw ((__v4hi)__m, (long long)__count); +} + +static __inline __m64 +_m_psrlw (__m64 __m, __m64 __count) +{ + return _mm_srl_pi16 (__m, __count); +} + +static __inline __m64 +_mm_srli_pi16 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_psrlw ((__v4hi)__m, __count); +} + +static __inline __m64 +_m_psrlwi (__m64 __m, int __count) +{ + return _mm_srli_pi16 (__m, __count); +} + +/* Shift two 32-bit values in M right by COUNT; shift in zeros. */ +static __inline __m64 +_mm_srl_pi32 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_psrld ((__v2si)__m, (long long)__count); +} + +static __inline __m64 +_m_psrld (__m64 __m, __m64 __count) +{ + return _mm_srl_pi32 (__m, __count); +} + +static __inline __m64 +_mm_srli_pi32 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_psrld ((__v2si)__m, __count); +} + +static __inline __m64 +_m_psrldi (__m64 __m, int __count) +{ + return _mm_srli_pi32 (__m, __count); +} + +/* Shift the 64-bit value in M left by COUNT; shift in zeros. */ +static __inline __m64 +_mm_srl_si64 (__m64 __m, __m64 __count) +{ + return (__m64) __builtin_ia32_psrlq ((long long)__m, (long long)__count); +} + +static __inline __m64 +_m_psrlq (__m64 __m, __m64 __count) +{ + return _mm_srl_si64 (__m, __count); +} + +static __inline __m64 +_mm_srli_si64 (__m64 __m, int __count) +{ + return (__m64) __builtin_ia32_psrlq ((long long)__m, (long long)__count); +} + +static __inline __m64 +_m_psrlqi (__m64 __m, int __count) +{ + return _mm_srli_si64 (__m, __count); +} + +/* Bit-wise AND the 64-bit values in M1 and M2. */ +static __inline __m64 +_mm_and_si64 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pand ((long long)__m1, (long long)__m2); +} + +static __inline __m64 +_m_pand (__m64 __m1, __m64 __m2) +{ + return _mm_and_si64 (__m1, __m2); +} + +/* Bit-wise complement the 64-bit value in M1 and bit-wise AND it with the + 64-bit value in M2. */ +static __inline __m64 +_mm_andnot_si64 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pandn ((long long)__m1, (long long)__m2); +} + +static __inline __m64 +_m_pandn (__m64 __m1, __m64 __m2) +{ + return _mm_andnot_si64 (__m1, __m2); +} + +/* Bit-wise inclusive OR the 64-bit values in M1 and M2. */ +static __inline __m64 +_mm_or_si64 (__m64 __m1, __m64 __m2) +{ + return (__m64)__builtin_ia32_por ((long long)__m1, (long long)__m2); +} + +static __inline __m64 +_m_por (__m64 __m1, __m64 __m2) +{ + return _mm_or_si64 (__m1, __m2); +} + +/* Bit-wise exclusive OR the 64-bit values in M1 and M2. */ +static __inline __m64 +_mm_xor_si64 (__m64 __m1, __m64 __m2) +{ + return (__m64)__builtin_ia32_pxor ((long long)__m1, (long long)__m2); +} + +static __inline __m64 +_m_pxor (__m64 __m1, __m64 __m2) +{ + return _mm_xor_si64 (__m1, __m2); +} + +/* Compare eight 8-bit values. The result of the comparison is 0xFF if the + test is true and zero if false. */ +static __inline __m64 +_mm_cmpeq_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pcmpeqb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_pcmpeqb (__m64 __m1, __m64 __m2) +{ + return _mm_cmpeq_pi8 (__m1, __m2); +} + +static __inline __m64 +_mm_cmpgt_pi8 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pcmpgtb ((__v8qi)__m1, (__v8qi)__m2); +} + +static __inline __m64 +_m_pcmpgtb (__m64 __m1, __m64 __m2) +{ + return _mm_cmpgt_pi8 (__m1, __m2); +} + +/* Compare four 16-bit values. The result of the comparison is 0xFFFF if + the test is true and zero if false. */ +static __inline __m64 +_mm_cmpeq_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pcmpeqw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_pcmpeqw (__m64 __m1, __m64 __m2) +{ + return _mm_cmpeq_pi16 (__m1, __m2); +} + +static __inline __m64 +_mm_cmpgt_pi16 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pcmpgtw ((__v4hi)__m1, (__v4hi)__m2); +} + +static __inline __m64 +_m_pcmpgtw (__m64 __m1, __m64 __m2) +{ + return _mm_cmpgt_pi16 (__m1, __m2); +} + +/* Compare two 32-bit values. The result of the comparison is 0xFFFFFFFF if + the test is true and zero if false. */ +static __inline __m64 +_mm_cmpeq_pi32 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pcmpeqd ((__v2si)__m1, (__v2si)__m2); +} + +static __inline __m64 +_m_pcmpeqd (__m64 __m1, __m64 __m2) +{ + return _mm_cmpeq_pi32 (__m1, __m2); +} + +static __inline __m64 +_mm_cmpgt_pi32 (__m64 __m1, __m64 __m2) +{ + return (__m64) __builtin_ia32_pcmpgtd ((__v2si)__m1, (__v2si)__m2); +} + +static __inline __m64 +_m_pcmpgtd (__m64 __m1, __m64 __m2) +{ + return _mm_cmpgt_pi32 (__m1, __m2); +} + +/* Creates a 64-bit zero. */ +static __inline __m64 +_mm_setzero_si64 (void) +{ + return (__m64)__builtin_ia32_mmx_zero (); +} + +/* Creates a vector of two 32-bit values; I0 is least significant. */ +static __inline __m64 +_mm_set_pi32 (int __i1, int __i0) +{ + union { + __m64 __q; + struct { + unsigned int __i0; + unsigned int __i1; + } __s; + } __u; + + __u.__s.__i0 = __i0; + __u.__s.__i1 = __i1; + + return __u.__q; +} + +/* Creates a vector of four 16-bit values; W0 is least significant. */ +static __inline __m64 +_mm_set_pi16 (short __w3, short __w2, short __w1, short __w0) +{ + unsigned int __i1 = (unsigned short)__w3 << 16 | (unsigned short)__w2; + unsigned int __i0 = (unsigned short)__w1 << 16 | (unsigned short)__w0; + return _mm_set_pi32 (__i1, __i0); + +} + +/* Creates a vector of eight 8-bit values; B0 is least significant. */ +static __inline __m64 +_mm_set_pi8 (char __b7, char __b6, char __b5, char __b4, + char __b3, char __b2, char __b1, char __b0) +{ + unsigned int __i1, __i0; + + __i1 = (unsigned char)__b7; + __i1 = __i1 << 8 | (unsigned char)__b6; + __i1 = __i1 << 8 | (unsigned char)__b5; + __i1 = __i1 << 8 | (unsigned char)__b4; + + __i0 = (unsigned char)__b3; + __i0 = __i0 << 8 | (unsigned char)__b2; + __i0 = __i0 << 8 | (unsigned char)__b1; + __i0 = __i0 << 8 | (unsigned char)__b0; + + return _mm_set_pi32 (__i1, __i0); +} + +/* Similar, but with the arguments in reverse order. */ +static __inline __m64 +_mm_setr_pi32 (int __i0, int __i1) +{ + return _mm_set_pi32 (__i1, __i0); +} + +static __inline __m64 +_mm_setr_pi16 (short __w0, short __w1, short __w2, short __w3) +{ + return _mm_set_pi16 (__w3, __w2, __w1, __w0); +} + +static __inline __m64 +_mm_setr_pi8 (char __b0, char __b1, char __b2, char __b3, + char __b4, char __b5, char __b6, char __b7) +{ + return _mm_set_pi8 (__b7, __b6, __b5, __b4, __b3, __b2, __b1, __b0); +} + +/* Creates a vector of two 32-bit values, both elements containing I. */ +static __inline __m64 +_mm_set1_pi32 (int __i) +{ + return _mm_set_pi32 (__i, __i); +} + +/* Creates a vector of four 16-bit values, all elements containing W. */ +static __inline __m64 +_mm_set1_pi16 (short __w) +{ + unsigned int __i = (unsigned short)__w << 16 | (unsigned short)__w; + return _mm_set1_pi32 (__i); +} + +/* Creates a vector of eight 8-bit values, all elements containing B. */ +static __inline __m64 +_mm_set1_pi8 (char __b) +{ + unsigned int __w = (unsigned char)__b << 8 | (unsigned char)__b; + unsigned int __i = __w << 16 | __w; + return _mm_set1_pi32 (__i); +} + +#endif /* __MMX__ */ +#endif /* _MMINTRIN_H_INCLUDED */ diff --git a/src/include/monetary.h b/src/include/monetary.h new file mode 100644 index 0000000..4d4c69d --- /dev/null +++ b/src/include/monetary.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/monetary.h,v 1.7 2002/09/20 08:22:48 mike Exp $ + */ + +#ifndef _MONETARY_H_ +#define _MONETARY_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +__BEGIN_DECLS +ssize_t strfmon(char * __restrict, size_t, const char * __restrict, ...); +__END_DECLS + +#endif /* !_MONETARY_H_ */ diff --git a/src/include/mp.h b/src/include/mp.h new file mode 100644 index 0000000..dbe5023 --- /dev/null +++ b/src/include/mp.h @@ -0,0 +1,32 @@ +/* $FreeBSD: src/lib/libmp/mp.h,v 1.2 2003/01/28 23:03:15 markm Exp $ */ + +#ifndef _MP_H_ +#define _MP_H_ + +#ifndef HEADER_BN_H_ +#include +#endif + +typedef struct _mint { + BIGNUM *bn; +} MINT; + +void gcd(const MINT *, const MINT *, MINT *); +MINT *itom(short); +void madd(const MINT *, const MINT *, MINT *); +int mcmp(const MINT *, const MINT *); +void mdiv(const MINT *, const MINT *, MINT *, MINT *); +void mfree(MINT *); +void min(MINT *); +void mout(const MINT *); +void move(const MINT *, MINT *); +void msqrt(const MINT *, MINT *, MINT *); +void msub(const MINT *, const MINT *, MINT *); +char *mtox(const MINT *); +void mult(const MINT *, const MINT *, MINT *); +void pow(const MINT *, const MINT *, const MINT *, MINT *); +void rpow(const MINT *, short, MINT *); +void sdiv(const MINT *, short, MINT *, short *); +MINT *xtom(const char *); + +#endif /* !_MP_H_ */ diff --git a/src/include/mpool.h b/src/include/mpool.h new file mode 100644 index 0000000..8342ca1 --- /dev/null +++ b/src/include/mpool.h @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 1991, 1993, 1994 + * 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. + * + * @(#)mpool.h 8.2 (Berkeley) 7/14/94 + * $FreeBSD: src/include/mpool.h,v 1.9 2002/03/23 17:24:53 imp Exp $ + */ + +#ifndef _MPOOL_H_ +#define _MPOOL_H_ + +#include + +/* + * The memory pool scheme is a simple one. Each in-memory page is referenced + * by a bucket which is threaded in up to two of three ways. All active pages + * are threaded on a hash chain (hashed by page number) and an lru chain. + * Inactive pages are threaded on a free chain. Each reference to a memory + * pool is handed an opaque MPOOL cookie which stores all of this information. + */ +#define HASHSIZE 128 +#define HASHKEY(pgno) ((pgno - 1) % HASHSIZE) + +/* The BKT structures are the elements of the queues. */ +typedef struct _bkt { + TAILQ_ENTRY(_bkt) hq; /* hash queue */ + TAILQ_ENTRY(_bkt) q; /* lru queue */ + void *page; /* page */ + pgno_t pgno; /* page number */ + +#define MPOOL_DIRTY 0x01 /* page needs to be written */ +#define MPOOL_PINNED 0x02 /* page is pinned into memory */ + u_int8_t flags; /* flags */ +} BKT; + +typedef struct MPOOL { + TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ + /* hash queue array */ + TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; + pgno_t curcache; /* current number of cached pages */ + pgno_t maxcache; /* max number of cached pages */ + pgno_t npages; /* number of pages in the file */ + u_long pagesize; /* file page size */ + int fd; /* file descriptor */ + /* page in conversion routine */ + void (*pgin)(void *, pgno_t, void *); + /* page out conversion routine */ + void (*pgout)(void *, pgno_t, void *); + void *pgcookie; /* cookie for page in/out routines */ +#ifdef STATISTICS + u_long cachehit; + u_long cachemiss; + u_long pagealloc; + u_long pageflush; + u_long pageget; + u_long pagenew; + u_long pageput; + u_long pageread; + u_long pagewrite; +#endif +} MPOOL; + +__BEGIN_DECLS +MPOOL *mpool_open(void *, int, pgno_t, pgno_t); +void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *), + void (*)(void *, pgno_t, void *), void *); +void *mpool_new(MPOOL *, pgno_t *); +void *mpool_get(MPOOL *, pgno_t, u_int); +int mpool_put(MPOOL *, void *, u_int); +int mpool_sync(MPOOL *); +int mpool_close(MPOOL *); +#ifdef STATISTICS +void mpool_stat(MPOOL *); +#endif +__END_DECLS + +#endif diff --git a/src/include/namespace.h b/src/include/namespace.h new file mode 100644 index 0000000..1e59c6c --- /dev/null +++ b/src/include/namespace.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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. + * + * $FreeBSD: src/lib/libc/include/namespace.h,v 1.16 2003/05/01 19:03:13 nectar Exp $ + */ + +#ifndef _NAMESPACE_H_ +#define _NAMESPACE_H_ + +/* + * Adjust names so that headers declare "hidden" names. + * + * README: When modifying this file don't forget to make the appropriate + * changes in un-namespace.h!!! + */ + +/* + * ISO C (C90) section. Most names in libc aren't in ISO C, so they + * should be here. Most aren't here... + */ +#define err _err +#define warn _warn +#define nsdispatch _nsdispatch + +/* + * Prototypes for syscalls/functions that need to be overridden + * in libc_r/libpthread. + */ +#define accept _accept +#define __acl_aclcheck_fd ___acl_aclcheck_fd +#define __acl_delete_fd ___acl_delete_fd +#define __acl_get_fd ___acl_get_fd +#define __acl_set_fd ___acl_set_fd +#define bind _bind +#define __cap_get_fd ___cap_get_fd +#define __cap_set_fd ___cap_set_fd +#define close _close +#define connect _connect +#define dup _dup +#define dup2 _dup2 +#define execve _execve +#define fcntl _fcntl +/*#define flock _flock */ +#define flockfile _flockfile +#define fpathconf _fpathconf +#define fstat _fstat +#define fstatfs _fstatfs +#define fsync _fsync +#define funlockfile _funlockfile +#define getdirentries _getdirentries +#define getlogin _getlogin +#define getpeername _getpeername +#define getprogname _getprogname +#define getsockname _getsockname +#define getsockopt _getsockopt +#define ioctl _ioctl +/* #define kevent _kevent */ +#define listen _listen +#define nanosleep _nanosleep +#define open _open +#define poll _poll +#define pthread_cond_broadcast _pthread_cond_broadcast +#define pthread_cond_destroy _pthread_cond_destroy +#define pthread_cond_init _pthread_cond_init +#define pthread_cond_signal _pthread_cond_signal +#define pthread_cond_timedwait _pthread_cond_timedwait +#define pthread_cond_wait _pthread_cond_wait +#define pthread_exit _pthread_exit +#define pthread_getspecific _pthread_getspecific +#define pthread_key_create _pthread_key_create +#define pthread_key_delete _pthread_key_delete +#define pthread_main_np _pthread_main_np +#define pthread_mutex_destroy _pthread_mutex_destroy +#define pthread_mutex_init _pthread_mutex_init +#define pthread_mutex_lock _pthread_mutex_lock +#define pthread_mutex_trylock _pthread_mutex_trylock +#define pthread_mutex_unlock _pthread_mutex_unlock +#define pthread_mutexattr_destroy _pthread_mutexattr_destroy +#define pthread_mutexattr_init _pthread_mutexattr_init +#define pthread_mutexattr_settype _pthread_mutexattr_settype +#define pthread_once _pthread_once +#define pthread_rwlock_destroy _pthread_rwlock_destroy +#define pthread_rwlock_init _pthread_rwlock_init +#define pthread_rwlock_rdlock _pthread_rwlock_rdlock +#define pthread_rwlock_wrlock _pthread_rwlock_wrlock +#define pthread_rwlock_tryrdlock _pthread_rwlock_tryrdlock +#define pthread_rwlock_trywrlock _pthread_rwlock_trywrlock +#define pthread_rwlock_unlock _pthread_rwlock_unlock +#define pthread_self _pthread_self +#define pthread_setspecific _pthread_setspecific +#define pthread_sigmask _pthread_sigmask +#define read _read +#define readv _readv +#define recvfrom _recvfrom +#define recvmsg _recvmsg +#define select _select +#define sendmsg _sendmsg +#define sendto _sendto +#define setsockopt _setsockopt +/*#define sigaction _sigaction*/ +#define sigprocmask _sigprocmask +#define sigsuspend _sigsuspend +#define socket _socket +#define socketpair _socketpair +#define wait4 _wait4 +#define waitpid _waitpid +#define write _write +#define writev _writev + + +/* + * Other hidden syscalls/functions that libc_r needs to override + * but are not used internally by libc. + * + * XXX - When modifying libc to use one of the following, remove + * the prototype from below and place it in the list above. + */ +#if 0 +#define creat _creat +#define fchflags _fchflags +#define fchmod _fchmod +#define ftrylockfile _ftrylockfile +#define msync _msync +#define nfssvc _nfssvc +#define pause _pause +#define pthread_rwlockattr_init _pthread_rwlockattr_init +#define pthread_rwlockattr_destroy _pthread_rwlockattr_destroy +#define sched_yield _sched_yield +#define sendfile _sendfile +#define shutdown _shutdown +#define sigaltstack _sigaltstack +#define sigpending _sigpending +#define sigreturn _sigreturn +#define sigsetmask _sigsetmask +#define sleep _sleep +#define system _system +#define tcdrain _tcdrain +#define wait _wait +#endif + +#endif /* _NAMESPACE_H_ */ diff --git a/src/include/ncurses.h b/src/include/ncurses.h new file mode 100644 index 0000000..059fc5f --- /dev/null +++ b/src/include/ncurses.h @@ -0,0 +1,1194 @@ +/**************************************************************************** + * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim 1992,1995 * + * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * + ****************************************************************************/ + +/* $Id$ */ + +#ifndef __NCURSES_H +#define __NCURSES_H + +#define CURSES 1 +#define CURSES_H 1 + +/* This should be defined for the enhanced functionality to be visible. + * However, none of the wide-character (enhanced) functionality is implemented. + * So we do not define it (yet). +#define _XOPEN_CURSES 1 + */ + +/* These are defined only in curses.h, and are used for conditional compiles */ +#define NCURSES_VERSION_MAJOR 5 +#define NCURSES_VERSION_MINOR 2 +#define NCURSES_VERSION_PATCH 20020615 + +/* This is defined in more than one ncurses header, for identification */ +#undef NCURSES_VERSION +#define NCURSES_VERSION "5.2" + +#include + +#ifdef NCURSES_NOMACROS +#define NCURSES_ATTR_T attr_t +#endif + +#ifndef NCURSES_ATTR_T +#define NCURSES_ATTR_T int +#endif + +#undef NCURSES_CONST +#define NCURSES_CONST const + +#undef NCURSES_COLOR_T +#define NCURSES_COLOR_T short + +#undef NCURSES_SIZE_T +#define NCURSES_SIZE_T short + +#undef NCURSES_CH_T +#define NCURSES_CH_T chtype + +typedef unsigned long chtype; + +#include +#include +#include /* we need va_list */ +#ifdef _XOPEN_SOURCE_EXTENDED +#include /* we want wchar_t */ +#endif /* _XOPEN_SOURCE_EXTENDED */ + +/* XSI and SVr4 specify that curses implements 'bool'. However, C++ may also + * implement it. If so, we must use the C++ compiler's type to avoid conflict + * with other interfaces. + * + * A further complication is that may declare 'bool' to be a + * different type, such as an enum which is not necessarily compatible with + * C++. If we have , make 'bool' a macro, so users may #undef it. + * Otherwise, let it remain a typedef to avoid conflicts with other #define's. + * In either case, make a typedef for NCURSES_BOOL which can be used if needed + * from either C or C++. + */ + +#undef TRUE +#define TRUE 1 + +#undef FALSE +#define FALSE 0 + +typedef unsigned char NCURSES_BOOL; + +#if (!defined(__cplusplus) || !1) && (!0) + +#if 1 +#include +#endif + +#undef bool + +#if 1 +#define bool NCURSES_BOOL +#else +typedef unsigned char bool; +#endif + +#endif /* !__cplusplus, etc. */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * XSI attributes. In the ncurses implementation, they are identical to the + * A_ attributes. + */ +#define WA_ATTRIBUTES A_ATTRIBUTES +#define WA_NORMAL A_NORMAL +#define WA_STANDOUT A_STANDOUT +#define WA_UNDERLINE A_UNDERLINE +#define WA_REVERSE A_REVERSE +#define WA_BLINK A_BLINK +#define WA_DIM A_DIM +#define WA_BOLD A_BOLD +#define WA_ALTCHARSET A_ALTCHARSET +#define WA_INVIS A_INVIS +#define WA_PROTECT A_PROTECT +#define WA_HORIZONTAL A_HORIZONTAL +#define WA_LEFT A_LEFT +#define WA_LOW A_LOW +#define WA_RIGHT A_RIGHT +#define WA_TOP A_TOP +#define WA_VERTICAL A_VERTICAL + +/* colors */ +extern NCURSES_EXPORT_VAR(int) COLORS; +extern NCURSES_EXPORT_VAR(int) COLOR_PAIRS; + +#define COLOR_BLACK 0 +#define COLOR_RED 1 +#define COLOR_GREEN 2 +#define COLOR_YELLOW 3 +#define COLOR_BLUE 4 +#define COLOR_MAGENTA 5 +#define COLOR_CYAN 6 +#define COLOR_WHITE 7 + +/* line graphics */ + +#if 0 +extern NCURSES_EXPORT_VAR(chtype*) _nc_acs_map(void); +#define acs_map (_nc_acs_map()) +#else +extern NCURSES_EXPORT_VAR(chtype) acs_map[]; +#endif + +/* VT100 symbols begin here */ +#define ACS_ULCORNER (acs_map['l']) /* upper left corner */ +#define ACS_LLCORNER (acs_map['m']) /* lower left corner */ +#define ACS_URCORNER (acs_map['k']) /* upper right corner */ +#define ACS_LRCORNER (acs_map['j']) /* lower right corner */ +#define ACS_LTEE (acs_map['t']) /* tee pointing right */ +#define ACS_RTEE (acs_map['u']) /* tee pointing left */ +#define ACS_BTEE (acs_map['v']) /* tee pointing up */ +#define ACS_TTEE (acs_map['w']) /* tee pointing down */ +#define ACS_HLINE (acs_map['q']) /* horizontal line */ +#define ACS_VLINE (acs_map['x']) /* vertical line */ +#define ACS_PLUS (acs_map['n']) /* large plus or crossover */ +#define ACS_S1 (acs_map['o']) /* scan line 1 */ +#define ACS_S9 (acs_map['s']) /* scan line 9 */ +#define ACS_DIAMOND (acs_map['`']) /* diamond */ +#define ACS_CKBOARD (acs_map['a']) /* checker board (stipple) */ +#define ACS_DEGREE (acs_map['f']) /* degree symbol */ +#define ACS_PLMINUS (acs_map['g']) /* plus/minus */ +#define ACS_BULLET (acs_map['~']) /* bullet */ +/* Teletype 5410v1 symbols begin here */ +#define ACS_LARROW (acs_map[',']) /* arrow pointing left */ +#define ACS_RARROW (acs_map['+']) /* arrow pointing right */ +#define ACS_DARROW (acs_map['.']) /* arrow pointing down */ +#define ACS_UARROW (acs_map['-']) /* arrow pointing up */ +#define ACS_BOARD (acs_map['h']) /* board of squares */ +#define ACS_LANTERN (acs_map['i']) /* lantern symbol */ +#define ACS_BLOCK (acs_map['0']) /* solid square block */ +/* + * These aren't documented, but a lot of System Vs have them anyway + * (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings). + * The ACS_names may not match AT&T's, our source didn't know them. + */ +#define ACS_S3 (acs_map['p']) /* scan line 3 */ +#define ACS_S7 (acs_map['r']) /* scan line 7 */ +#define ACS_LEQUAL (acs_map['y']) /* less/equal */ +#define ACS_GEQUAL (acs_map['z']) /* greater/equal */ +#define ACS_PI (acs_map['{']) /* Pi */ +#define ACS_NEQUAL (acs_map['|']) /* not equal */ +#define ACS_STERLING (acs_map['}']) /* UK pound sign */ + +/* + * Line drawing ACS names are of the form ACS_trbl, where t is the top, r + * is the right, b is the bottom, and l is the left. t, r, b, and l might + * be B (blank), S (single), D (double), or T (thick). The subset defined + * here only uses B and S. + */ +#define ACS_BSSB ACS_ULCORNER +#define ACS_SSBB ACS_LLCORNER +#define ACS_BBSS ACS_URCORNER +#define ACS_SBBS ACS_LRCORNER +#define ACS_SBSS ACS_RTEE +#define ACS_SSSB ACS_LTEE +#define ACS_SSBS ACS_BTEE +#define ACS_BSSS ACS_TTEE +#define ACS_BSBS ACS_HLINE +#define ACS_SBSB ACS_VLINE +#define ACS_SSSS ACS_PLUS + +#if defined(ERR) && ((ERR) != -1) +#undef ERR +#endif + +#if !defined(ERR) +#define ERR (-1) +#endif + +#if defined(OK) && ((OK) != 0) +#undef OK +#endif + +#if !defined(OK) +#define OK (0) +#endif + +/* values for the _flags member */ +#define _SUBWIN 0x01 /* is this a sub-window? */ +#define _ENDLINE 0x02 /* is the window flush right? */ +#define _FULLWIN 0x04 /* is the window full-screen? */ +#define _SCROLLWIN 0x08 /* bottom edge is at screen bottom? */ +#define _ISPAD 0x10 /* is this window a pad? */ +#define _HASMOVED 0x20 /* has cursor moved since last refresh? */ +#define _WRAPPED 0x40 /* cursor was just wrappped */ + +/* + * this value is used in the firstchar and lastchar fields to mark + * unchanged lines + */ +#define _NOCHANGE -1 + +/* + * this value is used in the oldindex field to mark lines created by insertions + * and scrolls. + */ +#define _NEWINDEX -1 + +typedef struct screen SCREEN; +typedef struct _win_st WINDOW; + +typedef chtype attr_t; /* ...must be at least as wide as chtype */ + +#ifdef _XOPEN_SOURCE_EXTENDED + +#if 0 +#ifdef mblen /* libutf8.h defines it w/o undefining first */ +#undef mblen +#endif +#include +#define __wchar_t +#define __wint_t +#endif + +#if 0 +#include /* ...to get mbstate_t, etc. */ +#endif + +#ifndef __wchar_t +typedef unsigned long wchar_t; +#endif /* __wchar_t */ +#ifndef __wint_t +typedef long int wint_t; +#endif /* __wint_t */ + +#define CCHARW_MAX 5 +typedef struct +{ + attr_t attr; + wchar_t chars[CCHARW_MAX]; +} +cchar_t; + +#endif /* _XOPEN_SOURCE_EXTENDED */ + +struct ldat; + +struct _win_st +{ + NCURSES_SIZE_T _cury, _curx; /* current cursor position */ + + /* window location and size */ + NCURSES_SIZE_T _maxy, _maxx; /* maximums of x and y, NOT window size */ + NCURSES_SIZE_T _begy, _begx; /* screen coords of upper-left-hand corner */ + + short _flags; /* window state flags */ + + /* attribute tracking */ + attr_t _attrs; /* current attribute for non-space character */ + chtype _bkgd; /* current background char/attribute pair */ + + /* option values set by user */ + bool _notimeout; /* no time out on function-key entry? */ + bool _clear; /* consider all data in the window invalid? */ + bool _leaveok; /* OK to not reset cursor on exit? */ + bool _scroll; /* OK to scroll this window? */ + bool _idlok; /* OK to use insert/delete line? */ + bool _idcok; /* OK to use insert/delete char? */ + bool _immed; /* window in immed mode? (not yet used) */ + bool _sync; /* window in sync mode? */ + bool _use_keypad; /* process function keys into KEY_ symbols? */ + int _delay; /* 0 = nodelay, <0 = blocking, >0 = delay */ + + struct ldat *_line; /* the actual line data */ + + /* global screen state */ + NCURSES_SIZE_T _regtop; /* top line of scrolling region */ + NCURSES_SIZE_T _regbottom; /* bottom line of scrolling region */ + + /* these are used only if this is a sub-window */ + int _parx; /* x coordinate of this window in parent */ + int _pary; /* y coordinate of this window in parent */ + WINDOW *_parent; /* pointer to parent if a sub-window */ + + /* these are used only if this is a pad */ + struct pdat + { + NCURSES_SIZE_T _pad_y, _pad_x; + NCURSES_SIZE_T _pad_top, _pad_left; + NCURSES_SIZE_T _pad_bottom, _pad_right; + } _pad; + + NCURSES_SIZE_T _yoffset; /* real begy is _begy + _yoffset */ + +#ifdef _XOPEN_SOURCE_EXTENDED + cchar_t _bkgrnd; /* current background char/attribute pair */ +#endif +}; + +extern NCURSES_EXPORT_VAR(WINDOW *) stdscr; +extern NCURSES_EXPORT_VAR(WINDOW *) curscr; +extern NCURSES_EXPORT_VAR(WINDOW *) newscr; + +extern NCURSES_EXPORT_VAR(int) LINES; +extern NCURSES_EXPORT_VAR(int) COLS; +extern NCURSES_EXPORT_VAR(int) TABSIZE; + +/* + * This global was an undocumented feature under AIX curses. + */ +extern NCURSES_EXPORT_VAR(int) ESCDELAY; /* ESC expire time in milliseconds */ + +extern NCURSES_EXPORT_VAR(char) ttytype[]; /* needed for backward compatibility */ + +/* + * These functions are extensions - not in XSI Curses. + */ +#if 1 +extern NCURSES_EXPORT(bool) is_term_resized (int, int); +extern NCURSES_EXPORT(char *) keybound (int, int); +extern NCURSES_EXPORT(const char *) curses_version (void); +extern NCURSES_EXPORT(int) assume_default_colors (int, int); +extern NCURSES_EXPORT(int) define_key (char *, int); +extern NCURSES_EXPORT(int) keyok (int, bool); +extern NCURSES_EXPORT(int) resize_term (int, int); +extern NCURSES_EXPORT(int) resizeterm (int, int); +extern NCURSES_EXPORT(int) use_default_colors (void); +extern NCURSES_EXPORT(int) use_extended_names (bool); +extern NCURSES_EXPORT(int) wresize (WINDOW *, int, int); +#else +#define curses_version() NCURSES_VERSION +#endif + +/* + * GCC (and some other compilers) define '__attribute__'; we're using this + * macro to alert the compiler to flag inconsistencies in printf/scanf-like + * function calls. Just in case '__attribute__' isn't defined, make a dummy. + * G++ doesn't accept it anyway. + */ +#if !defined(__GNUC__) && !defined(__attribute__) +#define __attribute__(p) /* nothing */ +#endif + +/* + * For g++, turn off our macros that use __attribute__ (g++ recognizes some + * of them, but not at the same version levels as gcc). + */ +#ifdef __cplusplus +#undef GCC_NORETURN +#undef GCC_PRINTF +#undef GCC_SCANF +#undef GCC_UNUSED +#endif + +/* + * We cannot define these in ncurses_cfg.h, since they require parameters to be + * passed (that's non-portable). + */ +#ifndef GCC_PRINTFLIKE +#if defined(GCC_PRINTF) && !defined(printf) +#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) +#else +#define GCC_PRINTFLIKE(fmt,var) /*nothing*/ +#endif +#endif + +#ifndef GCC_SCANFLIKE +#if defined(GCC_SCANF) && !defined(scanf) +#define GCC_SCANFLIKE(fmt,var) __attribute__((format(scanf,fmt,var))) +#else +#define GCC_SCANFLIKE(fmt,var) /*nothing*/ +#endif +#endif + +#ifndef GCC_NORETURN +#define GCC_NORETURN /* nothing */ +#endif + +#ifndef GCC_UNUSED +#define GCC_UNUSED /* nothing */ +#endif + +/* + * Function prototypes. This is the complete XSI Curses list of required + * functions. Those marked `generated' will have sources generated from the + * macro definitions later in this file, in order to satisfy XPG4.2 + * requirements. + */ + +extern NCURSES_EXPORT(int) addch (const chtype); /* generated */ +extern NCURSES_EXPORT(int) addchnstr (const chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) addchstr (const chtype *); /* generated */ +extern NCURSES_EXPORT(int) addnstr (const char *, int); /* generated */ +extern NCURSES_EXPORT(int) addstr (const char *); /* generated */ +extern NCURSES_EXPORT(int) attroff (NCURSES_ATTR_T); /* generated */ +extern NCURSES_EXPORT(int) attron (NCURSES_ATTR_T); /* generated */ +extern NCURSES_EXPORT(int) attrset (NCURSES_ATTR_T); /* generated */ +extern NCURSES_EXPORT(int) attr_get (attr_t *, short *, void *); /* generated */ +extern NCURSES_EXPORT(int) attr_off (attr_t, void *); /* generated */ +extern NCURSES_EXPORT(int) attr_on (attr_t, void *); /* generated */ +extern NCURSES_EXPORT(int) attr_set (attr_t, short, void *); /* generated */ +extern NCURSES_EXPORT(int) baudrate (void); /* implemented */ +extern NCURSES_EXPORT(int) beep (void); /* implemented */ +extern NCURSES_EXPORT(int) bkgd (chtype); /* generated */ +extern NCURSES_EXPORT(void) bkgdset (chtype); /* generated */ +extern NCURSES_EXPORT(int) border (chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* generated */ +extern NCURSES_EXPORT(int) box (WINDOW *, chtype, chtype); /* generated */ +extern NCURSES_EXPORT(bool) can_change_color (void); /* implemented */ +extern NCURSES_EXPORT(int) cbreak (void); /* implemented */ +extern NCURSES_EXPORT(int) chgat (int, attr_t, short, const void *); /* generated */ +extern NCURSES_EXPORT(int) clear (void); /* generated */ +extern NCURSES_EXPORT(int) clearok (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) clrtobot (void); /* generated */ +extern NCURSES_EXPORT(int) clrtoeol (void); /* generated */ +extern NCURSES_EXPORT(int) color_content (short,short*,short*,short*); /* implemented */ +extern NCURSES_EXPORT(int) color_set (short,void*); /* generated */ +extern NCURSES_EXPORT(int) COLOR_PAIR (int); /* generated */ +extern NCURSES_EXPORT(int) copywin (const WINDOW*,WINDOW*,int,int,int,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) curs_set (int); /* implemented */ +extern NCURSES_EXPORT(int) def_prog_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) def_shell_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) delay_output (int); /* implemented */ +extern NCURSES_EXPORT(int) delch (void); /* generated */ +extern NCURSES_EXPORT(void) delscreen (SCREEN *); /* implemented */ +extern NCURSES_EXPORT(int) delwin (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) deleteln (void); /* generated */ +extern NCURSES_EXPORT(WINDOW *) derwin (WINDOW *,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) doupdate (void); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) dupwin (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) echo (void); /* implemented */ +extern NCURSES_EXPORT(int) echochar (const chtype); /* generated */ +extern NCURSES_EXPORT(int) erase (void); /* generated */ +extern NCURSES_EXPORT(int) endwin (void); /* implemented */ +extern NCURSES_EXPORT(char) erasechar (void); /* implemented */ +extern NCURSES_EXPORT(void) filter (void); /* implemented */ +extern NCURSES_EXPORT(int) flash (void); /* implemented */ +extern NCURSES_EXPORT(int) flushinp (void); /* implemented */ +extern NCURSES_EXPORT(chtype) getbkgd (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) getch (void); /* generated */ +extern NCURSES_EXPORT(int) getnstr (char *, int); /* generated */ +extern NCURSES_EXPORT(int) getstr (char *); /* generated */ +extern NCURSES_EXPORT(WINDOW *) getwin (FILE *); /* implemented */ +extern NCURSES_EXPORT(int) halfdelay (int); /* implemented */ +extern NCURSES_EXPORT(bool) has_colors (void); /* implemented */ +extern NCURSES_EXPORT(bool) has_ic (void); /* implemented */ +extern NCURSES_EXPORT(bool) has_il (void); /* implemented */ +extern NCURSES_EXPORT(int) hline (chtype, int); /* generated */ +extern NCURSES_EXPORT(void) idcok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(int) idlok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(void) immedok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(chtype) inch (void); /* generated */ +extern NCURSES_EXPORT(int) inchnstr (chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) inchstr (chtype *); /* generated */ +extern NCURSES_EXPORT(WINDOW *) initscr (void); /* implemented */ +extern NCURSES_EXPORT(int) init_color (short,short,short,short); /* implemented */ +extern NCURSES_EXPORT(int) init_pair (short,short,short); /* implemented */ +extern NCURSES_EXPORT(int) innstr (char *, int); /* generated */ +extern NCURSES_EXPORT(int) insch (chtype); /* generated */ +extern NCURSES_EXPORT(int) insdelln (int); /* generated */ +extern NCURSES_EXPORT(int) insertln (void); /* generated */ +extern NCURSES_EXPORT(int) insnstr (const char *, int); /* generated */ +extern NCURSES_EXPORT(int) insstr (const char *); /* generated */ +extern NCURSES_EXPORT(int) instr (char *); /* generated */ +extern NCURSES_EXPORT(int) intrflush (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(bool) isendwin (void); /* implemented */ +extern NCURSES_EXPORT(bool) is_linetouched (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(bool) is_wintouched (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(NCURSES_CONST char *) keyname (int); /* implemented */ +extern NCURSES_EXPORT(int) keypad (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(char) killchar (void); /* implemented */ +extern NCURSES_EXPORT(int) leaveok (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(char *) longname (void); /* implemented */ +extern NCURSES_EXPORT(int) meta (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) move (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvaddch (int, int, const chtype); /* generated */ +extern NCURSES_EXPORT(int) mvaddchnstr (int, int, const chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) mvaddchstr (int, int, const chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvaddnstr (int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvaddstr (int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvchgat (int, int, int, attr_t, short, const void *); /* generated */ +extern NCURSES_EXPORT(int) mvcur (int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) mvdelch (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvderwin (WINDOW *, int, int); /* implemented */ +extern NCURSES_EXPORT(int) mvgetch (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvgetnstr (int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvgetstr (int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvhline (int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(chtype) mvinch (int, int); /* generated */ +extern NCURSES_EXPORT(int) mvinchnstr (int, int, chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) mvinchstr (int, int, chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvinnstr (int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvinsch (int, int, chtype); /* generated */ +extern NCURSES_EXPORT(int) mvinsnstr (int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvinsstr (int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvinstr (int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvprintw (int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(3,4); +extern NCURSES_EXPORT(int) mvscanw (int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(3,4); +extern NCURSES_EXPORT(int) mvvline (int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(int) mvwaddch (WINDOW *, int, int, const chtype); /* generated */ +extern NCURSES_EXPORT(int) mvwaddchnstr (WINDOW *, int, int, const chtype *, int);/* generated */ +extern NCURSES_EXPORT(int) mvwaddchstr (WINDOW *, int, int, const chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvwaddnstr (WINDOW *, int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwaddstr (WINDOW *, int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvwchgat (WINDOW *, int, int, int, attr_t, short, const void *);/* generated */ +extern NCURSES_EXPORT(int) mvwdelch (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) mvwgetch (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) mvwgetnstr (WINDOW *, int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwgetstr (WINDOW *, int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvwhline (WINDOW *, int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(int) mvwin (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(chtype) mvwinch (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinchnstr (WINDOW *, int, int, chtype *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinchstr (WINDOW *, int, int, chtype *); /* generated */ +extern NCURSES_EXPORT(int) mvwinnstr (WINDOW *, int, int, char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinsch (WINDOW *, int, int, chtype); /* generated */ +extern NCURSES_EXPORT(int) mvwinsnstr (WINDOW *, int, int, const char *, int); /* generated */ +extern NCURSES_EXPORT(int) mvwinsstr (WINDOW *, int, int, const char *); /* generated */ +extern NCURSES_EXPORT(int) mvwinstr (WINDOW *, int, int, char *); /* generated */ +extern NCURSES_EXPORT(int) mvwprintw (WINDOW*,int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(4,5); +extern NCURSES_EXPORT(int) mvwscanw (WINDOW *,int,int, NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(4,5); +extern NCURSES_EXPORT(int) mvwvline (WINDOW *,int, int, chtype, int); /* generated */ +extern NCURSES_EXPORT(int) napms (int); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) newpad (int,int); /* implemented */ +extern NCURSES_EXPORT(SCREEN *) newterm (NCURSES_CONST char *,FILE *,FILE *); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) newwin (int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) nl (void); /* implemented */ +extern NCURSES_EXPORT(int) nocbreak (void); /* implemented */ +extern NCURSES_EXPORT(int) nodelay (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) noecho (void); /* implemented */ +extern NCURSES_EXPORT(int) nonl (void); /* implemented */ +extern NCURSES_EXPORT(void) noqiflush (void); /* implemented */ +extern NCURSES_EXPORT(int) noraw (void); /* implemented */ +extern NCURSES_EXPORT(int) notimeout (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) overlay (const WINDOW*,WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) overwrite (const WINDOW*,WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) pair_content (short,short*,short*); /* implemented */ +extern NCURSES_EXPORT(int) PAIR_NUMBER (int); /* generated */ +extern NCURSES_EXPORT(int) pechochar (WINDOW *, const chtype); /* implemented */ +extern NCURSES_EXPORT(int) pnoutrefresh (WINDOW*,int,int,int,int,int,int);/* implemented */ +extern NCURSES_EXPORT(int) prefresh (WINDOW *,int,int,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) printw (NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(1,2); +extern NCURSES_EXPORT(int) putp (const char *); /* implemented */ +extern NCURSES_EXPORT(int) putwin (WINDOW *, FILE *); /* implemented */ +extern NCURSES_EXPORT(void) qiflush (void); /* implemented */ +extern NCURSES_EXPORT(int) raw (void); /* implemented */ +extern NCURSES_EXPORT(int) redrawwin (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) refresh (void); /* generated */ +extern NCURSES_EXPORT(int) resetty (void); /* implemented */ +extern NCURSES_EXPORT(int) reset_prog_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) reset_shell_mode (void); /* implemented */ +extern NCURSES_EXPORT(int) ripoffline (int, int (*)(WINDOW *, int)); /* implemented */ +extern NCURSES_EXPORT(int) savetty (void); /* implemented */ +extern NCURSES_EXPORT(int) scanw (NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(1,2); +extern NCURSES_EXPORT(int) scr_dump (const char *); /* implemented */ +extern NCURSES_EXPORT(int) scr_init (const char *); /* implemented */ +extern NCURSES_EXPORT(int) scrl (int); /* generated */ +extern NCURSES_EXPORT(int) scroll (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) scrollok (WINDOW *,bool); /* implemented */ +extern NCURSES_EXPORT(int) scr_restore (const char *); /* implemented */ +extern NCURSES_EXPORT(int) scr_set (const char *); /* implemented */ +extern NCURSES_EXPORT(int) setscrreg (int,int); /* generated */ +extern NCURSES_EXPORT(SCREEN *) set_term (SCREEN *); /* implemented */ +extern NCURSES_EXPORT(int) slk_attroff (const chtype); /* implemented */ +extern NCURSES_EXPORT(int) slk_attr_off (const attr_t, void *); /* generated:WIDEC */ +extern NCURSES_EXPORT(int) slk_attron (const chtype); /* implemented */ +extern NCURSES_EXPORT(int) slk_attr_on (attr_t,void*); /* generated:WIDEC */ +extern NCURSES_EXPORT(int) slk_attrset (const chtype); /* implemented */ +extern NCURSES_EXPORT(attr_t) slk_attr (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_attr_set (const attr_t,short,void*); /* implemented */ +extern NCURSES_EXPORT(int) slk_clear (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_color (short); /* implemented */ +extern NCURSES_EXPORT(int) slk_init (int); /* implemented */ +extern NCURSES_EXPORT(char *) slk_label (int); /* implemented */ +extern NCURSES_EXPORT(int) slk_noutrefresh (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_refresh (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_restore (void); /* implemented */ +extern NCURSES_EXPORT(int) slk_set (int,const char *,int); /* implemented */ +extern NCURSES_EXPORT(int) slk_touch (void); /* implemented */ +extern NCURSES_EXPORT(int) standout (void); /* generated */ +extern NCURSES_EXPORT(int) standend (void); /* generated */ +extern NCURSES_EXPORT(int) start_color (void); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) subpad (WINDOW *, int, int, int, int); /* implemented */ +extern NCURSES_EXPORT(WINDOW *) subwin (WINDOW *,int,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) syncok (WINDOW *, bool); /* implemented */ +extern NCURSES_EXPORT(chtype) termattrs (void); /* implemented */ +extern NCURSES_EXPORT(char *) termname (void); /* implemented */ +extern NCURSES_EXPORT(int) tigetflag (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(char *) tigetstr (NCURSES_CONST char *); /* implemented */ +extern NCURSES_EXPORT(void) timeout (int); /* generated */ +extern NCURSES_EXPORT(int) touchline (WINDOW *, int, int); /* generated */ +extern NCURSES_EXPORT(int) touchwin (WINDOW *); /* generated */ +extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, ...); /* implemented */ +extern NCURSES_EXPORT(int) typeahead (int); /* implemented */ +extern NCURSES_EXPORT(int) ungetch (int); /* implemented */ +extern NCURSES_EXPORT(int) untouchwin (WINDOW *); /* generated */ +extern NCURSES_EXPORT(void) use_env (bool); /* implemented */ +extern NCURSES_EXPORT(int) vidattr (chtype); /* implemented */ +extern NCURSES_EXPORT(int) vidputs (chtype, int (*)(int)); /* implemented */ +extern NCURSES_EXPORT(int) vline (chtype, int); /* generated */ +extern NCURSES_EXPORT(int) vwprintw (WINDOW *, NCURSES_CONST char *,va_list); /* implemented */ +extern NCURSES_EXPORT(int) vw_printw (WINDOW *, NCURSES_CONST char *,va_list); /* generated */ +extern NCURSES_EXPORT(int) vwscanw (WINDOW *, NCURSES_CONST char *,va_list); /* implemented */ +extern NCURSES_EXPORT(int) vw_scanw (WINDOW *, NCURSES_CONST char *,va_list); /* generated */ +extern NCURSES_EXPORT(int) waddch (WINDOW *, const chtype); /* implemented */ +extern NCURSES_EXPORT(int) waddchnstr (WINDOW *,const chtype *const,int); /* implemented */ +extern NCURSES_EXPORT(int) waddchstr (WINDOW *,const chtype *); /* generated */ +extern NCURSES_EXPORT(int) waddnstr (WINDOW *,const char *const,int); /* implemented */ +extern NCURSES_EXPORT(int) waddstr (WINDOW *,const char *); /* generated */ +extern NCURSES_EXPORT(int) wattron (WINDOW *, int); /* generated */ +extern NCURSES_EXPORT(int) wattroff (WINDOW *, int); /* generated */ +extern NCURSES_EXPORT(int) wattrset (WINDOW *, int); /* generated */ +extern NCURSES_EXPORT(int) wattr_get (WINDOW *, attr_t *, short *, void *); /* generated */ +extern NCURSES_EXPORT(int) wattr_on (WINDOW *, NCURSES_CONST attr_t, void *); /* implemented */ +extern NCURSES_EXPORT(int) wattr_off (WINDOW *, NCURSES_CONST attr_t, void *); /* implemented */ +extern NCURSES_EXPORT(int) wattr_set (WINDOW *, attr_t, short, void *); /* generated */ +extern NCURSES_EXPORT(int) wbkgd (WINDOW *,const chtype); /* implemented */ +extern NCURSES_EXPORT(void) wbkgdset (WINDOW *,chtype); /* implemented */ +extern NCURSES_EXPORT(int) wborder (WINDOW *,chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* implemented */ +extern NCURSES_EXPORT(int) wchgat (WINDOW *, int, attr_t, short, const void *);/* implemented */ +extern NCURSES_EXPORT(int) wclear (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wclrtobot (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wclrtoeol (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wcolor_set (WINDOW*,short,void*); /* implemented */ +extern NCURSES_EXPORT(void) wcursyncup (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wdelch (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wdeleteln (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) wechochar (WINDOW *, const chtype); /* implemented */ +extern NCURSES_EXPORT(int) werase (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wgetch (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wgetnstr (WINDOW *,char *,int); /* implemented */ +extern NCURSES_EXPORT(int) wgetstr (WINDOW *, char *); /* generated */ +extern NCURSES_EXPORT(int) whline (WINDOW *, chtype, int); /* implemented */ +extern NCURSES_EXPORT(chtype) winch (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) winchnstr (WINDOW *, chtype *, int); /* implemented */ +extern NCURSES_EXPORT(int) winchstr (WINDOW *, chtype *); /* generated */ +extern NCURSES_EXPORT(int) winnstr (WINDOW *, char *, int); /* implemented */ +extern NCURSES_EXPORT(int) winsch (WINDOW *, chtype); /* implemented */ +extern NCURSES_EXPORT(int) winsdelln (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(int) winsertln (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) winsnstr (WINDOW *, const char *,int); /* implemented */ +extern NCURSES_EXPORT(int) winsstr (WINDOW *, const char *); /* generated */ +extern NCURSES_EXPORT(int) winstr (WINDOW *, char *); /* generated */ +extern NCURSES_EXPORT(int) wmove (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wnoutrefresh (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wprintw (WINDOW *, NCURSES_CONST char *,...) /* implemented */ + GCC_PRINTFLIKE(2,3); +extern NCURSES_EXPORT(int) wredrawln (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wrefresh (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(int) wscanw (WINDOW *, NCURSES_CONST char *,...) /* implemented */ + GCC_SCANFLIKE(2,3); +extern NCURSES_EXPORT(int) wscrl (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(int) wsetscrreg (WINDOW *,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wstandout (WINDOW *); /* generated */ +extern NCURSES_EXPORT(int) wstandend (WINDOW *); /* generated */ +extern NCURSES_EXPORT(void) wsyncdown (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(void) wsyncup (WINDOW *); /* implemented */ +extern NCURSES_EXPORT(void) wtimeout (WINDOW *,int); /* implemented */ +extern NCURSES_EXPORT(int) wtouchln (WINDOW *,int,int,int); /* implemented */ +extern NCURSES_EXPORT(int) wvline (WINDOW *,chtype,int); /* implemented */ + +/* + * vid_attr() was implemented originally based on the draft of XSI curses. + */ +#ifndef _XOPEN_SOURCE_EXTENDED +#define vid_attr(a,pair,opts) vidattr(a) +#endif + +/* attributes */ + +#define NCURSES_ATTR_SHIFT 8 +#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + NCURSES_ATTR_SHIFT)) + +#define A_NORMAL 0L +#define A_ATTRIBUTES NCURSES_BITS(~(1UL - 1UL),0) +#define A_CHARTEXT (NCURSES_BITS(1UL,0) - 1UL) +#define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) +#define A_STANDOUT NCURSES_BITS(1UL,8) +#define A_UNDERLINE NCURSES_BITS(1UL,9) +#define A_REVERSE NCURSES_BITS(1UL,10) +#define A_BLINK NCURSES_BITS(1UL,11) +#define A_DIM NCURSES_BITS(1UL,12) +#define A_BOLD NCURSES_BITS(1UL,13) +#define A_ALTCHARSET NCURSES_BITS(1UL,14) +#define A_INVIS NCURSES_BITS(1UL,15) +#define A_PROTECT NCURSES_BITS(1UL,16) +#define A_HORIZONTAL NCURSES_BITS(1UL,17) +#define A_LEFT NCURSES_BITS(1UL,18) +#define A_LOW NCURSES_BITS(1UL,19) +#define A_RIGHT NCURSES_BITS(1UL,20) +#define A_TOP NCURSES_BITS(1UL,21) +#define A_VERTICAL NCURSES_BITS(1UL,22) + +#define COLOR_PAIR(n) NCURSES_BITS(n, 0) +#define PAIR_NUMBER(a) (((a) & A_COLOR) >> NCURSES_ATTR_SHIFT) + +/* + * pseudo functions + */ +#define wgetstr(w, s) wgetnstr(w, s, -1) +#define getnstr(s, n) wgetnstr(stdscr, s, n) + +#define setterm(term) setupterm(term, 1, (int *)0) + +#define fixterm() reset_prog_mode() +#define resetterm() reset_shell_mode() +#define saveterm() def_prog_mode() +#define crmode() cbreak() +#define nocrmode() nocbreak() +#define gettmode() + +#define getyx(win,y,x) (y = (win)?(win)->_cury:ERR, x = (win)?(win)->_curx:ERR) +#define getbegyx(win,y,x) (y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR) +#define getmaxyx(win,y,x) (y = (win)?((win)->_maxy + 1):ERR, x = (win)?((win)->_maxx + 1):ERR) +#define getparyx(win,y,x) (y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR) +#define getsyx(y,x) do { if(newscr->_leaveok) (y)=(x)=-1; \ + else getyx(newscr,(y),(x)); \ + } while(0) +#define setsyx(y,x) do { if((y)==-1 && (x)==-1) newscr->_leaveok=TRUE; \ + else {newscr->_leaveok=FALSE;wmove(newscr,(y),(x));} \ + } while(0) + +/* It seems older SYSV curses versions define these */ +#define getattrs(win) ((win)?(win)->_attrs:A_NORMAL) +#define getcurx(win) ((win)?(win)->_curx:ERR) +#define getcury(win) ((win)?(win)->_cury:ERR) +#define getbegx(win) ((win)?(win)->_begx:ERR) +#define getbegy(win) ((win)?(win)->_begy:ERR) +#define getmaxx(win) ((win)?((win)->_maxx + 1):ERR) +#define getmaxy(win) ((win)?((win)->_maxy + 1):ERR) +#define getparx(win) ((win)?(win)->_parx:ERR) +#define getpary(win) ((win)?(win)->_pary:ERR) + +#define wstandout(win) (wattrset(win,A_STANDOUT)) +#define wstandend(win) (wattrset(win,A_NORMAL)) +#define wattr_set(win,a,p,opts) ((win)->_attrs = (((a) & ~A_COLOR) | COLOR_PAIR(p)), OK) + +#define wattron(win,at) wattr_on(win, at, (void *)0) +#define wattroff(win,at) wattr_off(win, at, (void *)0) +#define wattrset(win,at) ((win)->_attrs = (at)) + +#define scroll(win) wscrl(win,1) + +#define touchwin(win) wtouchln((win), 0, getmaxy(win), 1) +#define touchline(win, s, c) wtouchln((win), s, c, 1) +#define untouchwin(win) wtouchln((win), 0, getmaxy(win), 0) + +#define box(win, v, h) wborder(win, v, v, h, h, 0, 0, 0, 0) +#define border(ls, rs, ts, bs, tl, tr, bl, br) wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br) +#define hline(ch, n) whline(stdscr, ch, n) +#define vline(ch, n) wvline(stdscr, ch, n) + +#define winstr(w, s) winnstr(w, s, -1) +#define winchstr(w, s) winchnstr(w, s, -1) +#define winsstr(w, s) winsnstr(w, s, -1) + +#define redrawwin(win) wredrawln(win, 0, (win)->_maxy+1) +#define waddstr(win,str) waddnstr(win,str,-1) +#define waddchstr(win,str) waddchnstr(win,str,-1) + +/* + * pseudo functions for standard screen + */ + +#define addch(ch) waddch(stdscr,ch) +#define addchnstr(str,n) waddchnstr(stdscr,str,n) +#define addchstr(str) waddchstr(stdscr,str) +#define addnstr(str,n) waddnstr(stdscr,str,n) +#define addstr(str) waddnstr(stdscr,str,-1) +#define attroff(at) wattroff(stdscr,at) +#define attron(at) wattron(stdscr,at) +#define attrset(at) wattrset(stdscr,at) +#define attr_get(ap,cp,o) wattr_get(stdscr,ap,cp,o) +#define attr_off(a,o) wattr_off(stdscr,a,o) +#define attr_on(a,o) wattr_on(stdscr,a,o) +#define attr_set(a,c,o) wattr_set(stdscr,a,c,o) +#define bkgd(ch) wbkgd(stdscr,ch) +#define bkgdset(ch) wbkgdset(stdscr,ch) +#define chgat(n,a,c,o) wchgat(stdscr,n,a,c,o) +#define clear() wclear(stdscr) +#define clrtobot() wclrtobot(stdscr) +#define clrtoeol() wclrtoeol(stdscr) +#define color_set(c,o) wcolor_set(stdscr,c,o) +#define delch() wdelch(stdscr) +#define deleteln() winsdelln(stdscr,-1) +#define echochar(c) wechochar(stdscr,c) +#define erase() werase(stdscr) +#define getch() wgetch(stdscr) +#define getstr(str) wgetstr(stdscr,str) +#define inch() winch(stdscr) +#define inchnstr(s,n) winchnstr(stdscr,s,n) +#define inchstr(s) winchstr(stdscr,s) +#define innstr(s,n) winnstr(stdscr,s,n) +#define insch(c) winsch(stdscr,c) +#define insdelln(n) winsdelln(stdscr,n) +#define insertln() winsdelln(stdscr,1) +#define insnstr(s,n) winsnstr(stdscr,s,n) +#define insstr(s) winsstr(stdscr,s) +#define instr(s) winstr(stdscr,s) +#define move(y,x) wmove(stdscr,y,x) +#define refresh() wrefresh(stdscr) +#define scrl(n) wscrl(stdscr,n) +#define setscrreg(t,b) wsetscrreg(stdscr,t,b) +#define standend() wstandend(stdscr) +#define standout() wstandout(stdscr) +#define timeout(delay) wtimeout(stdscr,delay) +#define wdeleteln(win) winsdelln(win,-1) +#define winsertln(win) winsdelln(win,1) + +/* + * mv functions + */ + +#define mvwaddch(win,y,x,ch) (wmove(win,y,x) == ERR ? ERR : waddch(win,ch)) +#define mvwaddchnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,n)) +#define mvwaddchstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,-1)) +#define mvwaddnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,n)) +#define mvwaddstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,-1)) +#define mvwdelch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wdelch(win)) +#define mvwchgat(win,y,x,n,a,c,o) (wmove(win,y,x) == ERR ? ERR : wchgat(win,n,a,c,o)) +#define mvwgetch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wgetch(win)) +#define mvwgetnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : wgetnstr(win,str,n)) +#define mvwgetstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : wgetstr(win,str)) +#define mvwhline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : whline(win,c,n)) +#define mvwinch(win,y,x) (wmove(win,y,x) == ERR ? (chtype)ERR : winch(win)) +#define mvwinchnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winchnstr(win,s,n)) +#define mvwinchstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winchstr(win,s)) +#define mvwinnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winnstr(win,s,n)) +#define mvwinsch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : winsch(win,c)) +#define mvwinsnstr(win,y,x,s,n) (wmove(win,y,x) == ERR ? ERR : winsnstr(win,s,n)) +#define mvwinsstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winsstr(win,s)) +#define mvwinstr(win,y,x,s) (wmove(win,y,x) == ERR ? ERR : winstr(win,s)) +#define mvwvline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : wvline(win,c,n)) + +#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch) +#define mvaddchnstr(y,x,str,n) mvwaddchnstr(stdscr,y,x,str,n) +#define mvaddchstr(y,x,str) mvwaddchstr(stdscr,y,x,str) +#define mvaddnstr(y,x,str,n) mvwaddnstr(stdscr,y,x,str,n) +#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str) +#define mvchgat(y,x,n,a,c,o) mvwchgat(stdscr,y,x,n,a,c,o) +#define mvdelch(y,x) mvwdelch(stdscr,y,x) +#define mvgetch(y,x) mvwgetch(stdscr,y,x) +#define mvgetnstr(y,x,str,n) mvwgetnstr(stdscr,y,x,str,n) +#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str) +#define mvhline(y,x,c,n) mvwhline(stdscr,y,x,c,n) +#define mvinch(y,x) mvwinch(stdscr,y,x) +#define mvinchnstr(y,x,s,n) mvwinchnstr(stdscr,y,x,s,n) +#define mvinchstr(y,x,s) mvwinchstr(stdscr,y,x,s) +#define mvinnstr(y,x,s,n) mvwinnstr(stdscr,y,x,s,n) +#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c) +#define mvinsnstr(y,x,s,n) mvwinsnstr(stdscr,y,x,s,n) +#define mvinsstr(y,x,s) mvwinsstr(stdscr,y,x,s) +#define mvinstr(y,x,s) mvwinstr(stdscr,y,x,s) +#define mvvline(y,x,c,n) mvwvline(stdscr,y,x,c,n) + +/* + * Some wide-character functions do not depend on the extensions. + */ +#define getbkgd(win) ((win)->_bkgd) + +#define slk_attr_off(a,v) ((v) ? ERR : slk_attroff(a)) +#define slk_attr_on(a,v) ((v) ? ERR : slk_attron(a)) + +#define wattr_get(win,a,p,opts) ((void)((a) != 0 && (*(a) = (win)->_attrs)), \ + (void)((p) != 0 && (*(p) = PAIR_NUMBER((win)->_attrs))), \ + OK) + +/* + * XSI curses deprecates SVr4 vwprintw/vwscanw, which are supposed to use + * varargs.h. It adds new calls vw_printw/vw_scanw, which are supposed to + * use POSIX stdarg.h. The ncurses versions of vwprintw/vwscanw already + * use stdarg.h, so... + */ +#define vw_printw vwprintw +#define vw_scanw vwscanw + +/* + * Export fallback function for use in C++ binding. + */ +#if !1 +#define vsscanf(a,b,c) _nc_vsscanf(a,b,c) +NCURSES_EXPORT(int) vsscanf(const char *, const char *, va_list); +#endif + +/* + * Pseudo-character tokens outside ASCII range. The curses wgetch() function + * will return any given one of these only if the corresponding k- capability + * is defined in your terminal's terminfo entry. + * + * Some keys (KEY_A1, etc) are arranged like this: + * a1 up a3 + * left b2 right + * c1 down c3 + * + * A few key codes do not depend upon the terminfo entry. + */ +#define KEY_CODE_YES 0400 /* A wchar_t contains a key code */ +#define KEY_MIN 0401 /* Minimum curses key */ +#define KEY_BREAK 0401 /* Break key (unreliable) */ +#define KEY_SRESET 0530 /* Soft (partial) reset (unreliable) */ +#define KEY_RESET 0531 /* Reset or hard reset (unreliable) */ +/* + * These definitions were generated by /usr/src/lib/libncurses/../../contrib/ncurses/include/MKkey_defs.sh /usr/src/lib/libncurses/../../contrib/ncurses/include/Caps + */ +#define KEY_DOWN 0402 /* down-arrow key */ +#define KEY_UP 0403 /* up-arrow key */ +#define KEY_LEFT 0404 /* left-arrow key */ +#define KEY_RIGHT 0405 /* right-arrow key */ +#define KEY_HOME 0406 /* home key */ +#define KEY_BACKSPACE 0407 /* backspace key */ +#define KEY_F0 0410 /* Function keys. Space for 64 */ +#define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */ +#define KEY_DL 0510 /* delete-line key */ +#define KEY_IL 0511 /* insert-line key */ +#define KEY_DC 0512 /* delete-character key */ +#define KEY_IC 0513 /* insert-character key */ +#define KEY_EIC 0514 /* sent by rmir or smir in insert mode */ +#define KEY_CLEAR 0515 /* clear-screen or erase key */ +#define KEY_EOS 0516 /* clear-to-end-of-screen key */ +#define KEY_EOL 0517 /* clear-to-end-of-line key */ +#define KEY_SF 0520 /* scroll-forward key */ +#define KEY_SR 0521 /* scroll-backward key */ +#define KEY_NPAGE 0522 /* next-page key */ +#define KEY_PPAGE 0523 /* previous-page key */ +#define KEY_STAB 0524 /* set-tab key */ +#define KEY_CTAB 0525 /* clear-tab key */ +#define KEY_CATAB 0526 /* clear-all-tabs key */ +#define KEY_ENTER 0527 /* enter/send key */ +#define KEY_PRINT 0532 /* print key */ +#define KEY_LL 0533 /* lower-left key (home down) */ +#define KEY_A1 0534 /* upper left of keypad */ +#define KEY_A3 0535 /* upper right of keypad */ +#define KEY_B2 0536 /* center of keypad */ +#define KEY_C1 0537 /* lower left of keypad */ +#define KEY_C3 0540 /* lower right of keypad */ +#define KEY_BTAB 0541 /* back-tab key */ +#define KEY_BEG 0542 /* begin key */ +#define KEY_CANCEL 0543 /* cancel key */ +#define KEY_CLOSE 0544 /* close key */ +#define KEY_COMMAND 0545 /* command key */ +#define KEY_COPY 0546 /* copy key */ +#define KEY_CREATE 0547 /* create key */ +#define KEY_END 0550 /* end key */ +#define KEY_EXIT 0551 /* exit key */ +#define KEY_FIND 0552 /* find key */ +#define KEY_HELP 0553 /* help key */ +#define KEY_MARK 0554 /* mark key */ +#define KEY_MESSAGE 0555 /* message key */ +#define KEY_MOVE 0556 /* move key */ +#define KEY_NEXT 0557 /* next key */ +#define KEY_OPEN 0560 /* open key */ +#define KEY_OPTIONS 0561 /* options key */ +#define KEY_PREVIOUS 0562 /* previous key */ +#define KEY_REDO 0563 /* redo key */ +#define KEY_REFERENCE 0564 /* reference key */ +#define KEY_REFRESH 0565 /* refresh key */ +#define KEY_REPLACE 0566 /* replace key */ +#define KEY_RESTART 0567 /* restart key */ +#define KEY_RESUME 0570 /* resume key */ +#define KEY_SAVE 0571 /* save key */ +#define KEY_SBEG 0572 /* shifted begin key */ +#define KEY_SCANCEL 0573 /* shifted cancel key */ +#define KEY_SCOMMAND 0574 /* shifted command key */ +#define KEY_SCOPY 0575 /* shifted copy key */ +#define KEY_SCREATE 0576 /* shifted create key */ +#define KEY_SDC 0577 /* shifted delete-character key */ +#define KEY_SDL 0600 /* shifted delete-line key */ +#define KEY_SELECT 0601 /* select key */ +#define KEY_SEND 0602 /* shifted end key */ +#define KEY_SEOL 0603 /* shifted clear-to-end-of-line key */ +#define KEY_SEXIT 0604 /* shifted exit key */ +#define KEY_SFIND 0605 /* shifted find key */ +#define KEY_SHELP 0606 /* shifted help key */ +#define KEY_SHOME 0607 /* shifted home key */ +#define KEY_SIC 0610 /* shifted insert-character key */ +#define KEY_SLEFT 0611 /* shifted left-arrow key */ +#define KEY_SMESSAGE 0612 /* shifted message key */ +#define KEY_SMOVE 0613 /* shifted move key */ +#define KEY_SNEXT 0614 /* shifted next key */ +#define KEY_SOPTIONS 0615 /* shifted options key */ +#define KEY_SPREVIOUS 0616 /* shifted previous key */ +#define KEY_SPRINT 0617 /* shifted print key */ +#define KEY_SREDO 0620 /* shifted redo key */ +#define KEY_SREPLACE 0621 /* shifted replace key */ +#define KEY_SRIGHT 0622 /* shifted right-arrow key */ +#define KEY_SRSUME 0623 /* shifted resume key */ +#define KEY_SSAVE 0624 /* shifted save key */ +#define KEY_SSUSPEND 0625 /* shifted suspend key */ +#define KEY_SUNDO 0626 /* shifted undo key */ +#define KEY_SUSPEND 0627 /* suspend key */ +#define KEY_UNDO 0630 /* undo key */ +#define KEY_MOUSE 0631 /* Mouse event has occurred */ +#define KEY_RESIZE 0632 /* Terminal resize event */ + +#define KEY_MAX 0777 /* Maximum key value is 0632 */ +/* $Id$ */ + +/* mouse interface */ +#define NCURSES_MOUSE_VERSION 1 + +/* event masks */ +#define BUTTON1_RELEASED 000000000001L +#define BUTTON1_PRESSED 000000000002L +#define BUTTON1_CLICKED 000000000004L +#define BUTTON1_DOUBLE_CLICKED 000000000010L +#define BUTTON1_TRIPLE_CLICKED 000000000020L +#define BUTTON1_RESERVED_EVENT 000000000040L +#define BUTTON2_RELEASED 000000000100L +#define BUTTON2_PRESSED 000000000200L +#define BUTTON2_CLICKED 000000000400L +#define BUTTON2_DOUBLE_CLICKED 000000001000L +#define BUTTON2_TRIPLE_CLICKED 000000002000L +#define BUTTON2_RESERVED_EVENT 000000004000L +#define BUTTON3_RELEASED 000000010000L +#define BUTTON3_PRESSED 000000020000L +#define BUTTON3_CLICKED 000000040000L +#define BUTTON3_DOUBLE_CLICKED 000000100000L +#define BUTTON3_TRIPLE_CLICKED 000000200000L +#define BUTTON3_RESERVED_EVENT 000000400000L +#define BUTTON4_RELEASED 000001000000L +#define BUTTON4_PRESSED 000002000000L +#define BUTTON4_CLICKED 000004000000L +#define BUTTON4_DOUBLE_CLICKED 000010000000L +#define BUTTON4_TRIPLE_CLICKED 000020000000L +#define BUTTON4_RESERVED_EVENT 000040000000L +#define BUTTON_CTRL 000100000000L +#define BUTTON_SHIFT 000200000000L +#define BUTTON_ALT 000400000000L +#define ALL_MOUSE_EVENTS 000777777777L +#define REPORT_MOUSE_POSITION 001000000000L + +/* macros to extract single event-bits from masks */ +#define BUTTON_RELEASE(e, x) ((e) & (001 << (6 * ((x) - 1)))) +#define BUTTON_PRESS(e, x) ((e) & (002 << (6 * ((x) - 1)))) +#define BUTTON_CLICK(e, x) ((e) & (004 << (6 * ((x) - 1)))) +#define BUTTON_DOUBLE_CLICK(e, x) ((e) & (010 << (6 * ((x) - 1)))) +#define BUTTON_TRIPLE_CLICK(e, x) ((e) & (020 << (6 * ((x) - 1)))) +#define BUTTON_RESERVED_EVENT(e, x) ((e) & (040 << (6 * ((x) - 1)))) + +typedef unsigned long mmask_t; + +typedef struct +{ + short id; /* ID to distinguish multiple devices */ + int x, y, z; /* event coordinates (character-cell) */ + mmask_t bstate; /* button state bits */ +} +MEVENT; + +extern NCURSES_EXPORT(int) getmouse (MEVENT *); +extern NCURSES_EXPORT(int) ungetmouse (MEVENT *); +extern NCURSES_EXPORT(mmask_t) mousemask (mmask_t, mmask_t *); +extern NCURSES_EXPORT(bool) wenclose (const WINDOW *, int, int); +extern NCURSES_EXPORT(int) mouseinterval (int); +extern NCURSES_EXPORT(bool) wmouse_trafo (const WINDOW* win,int* y, int* x, bool to_screen); +extern NCURSES_EXPORT(bool) mouse_trafo (int*, int*, bool); /* generated */ + +#define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen) + +/* other non-XSI functions */ + +extern NCURSES_EXPORT(int) mcprint (char *, int); /* direct data to printer */ +extern NCURSES_EXPORT(int) has_key (int); /* do we have given key? */ + +/* Debugging : use with libncurses_g.a */ + +extern NCURSES_EXPORT(void) _tracef (const char *, ...) GCC_PRINTFLIKE(1,2); +extern NCURSES_EXPORT(void) _tracedump (const char *, WINDOW *); +extern NCURSES_EXPORT(char *) _traceattr (attr_t); +extern NCURSES_EXPORT(char *) _traceattr2 (int, chtype); +extern NCURSES_EXPORT(char *) _nc_tracebits (void); +extern NCURSES_EXPORT(char *) _tracechar (int); +extern NCURSES_EXPORT(char *) _tracechtype (chtype); +extern NCURSES_EXPORT(char *) _tracechtype2 (int, chtype); +#ifdef _XOPEN_SOURCE_EXTENDED +#define _tracech_t _tracecchar_t +extern NCURSES_EXPORT(char *) _tracecchar_t (const cchar_t *); +#define _tracech_t2 _tracecchar_t2 +extern NCURSES_EXPORT(char *) _tracecchar_t2 (int, const cchar_t *); +#else +#define _tracech_t _tracechtype +#define _tracech_t2 _tracechtype2 +#endif +extern NCURSES_EXPORT(char *) _tracemouse (const MEVENT *); +extern NCURSES_EXPORT(void) trace (const unsigned int); + +/* trace masks */ +#define TRACE_DISABLE 0x0000 /* turn off tracing */ +#define TRACE_TIMES 0x0001 /* trace user and system times of updates */ +#define TRACE_TPUTS 0x0002 /* trace tputs calls */ +#define TRACE_UPDATE 0x0004 /* trace update actions, old & new screens */ +#define TRACE_MOVE 0x0008 /* trace cursor moves and scrolls */ +#define TRACE_CHARPUT 0x0010 /* trace all character outputs */ +#define TRACE_ORDINARY 0x001F /* trace all update actions */ +#define TRACE_CALLS 0x0020 /* trace all curses calls */ +#define TRACE_VIRTPUT 0x0040 /* trace virtual character puts */ +#define TRACE_IEVENT 0x0080 /* trace low-level input processing */ +#define TRACE_BITS 0x0100 /* trace state of TTY control bits */ +#define TRACE_ICALLS 0x0200 /* trace internal/nested calls */ +#define TRACE_CCALLS 0x0400 /* trace per-character calls */ +#define TRACE_DATABASE 0x0800 /* trace read/write of terminfo/termcap data */ +#define TRACE_ATTRS 0x1000 /* trace attribute updates */ +#define TRACE_MAXIMUM 0xffff /* maximum trace level */ + +#if defined(TRACE) || defined(NCURSES_TEST) +extern NCURSES_EXPORT_VAR(int) _nc_optimize_enable; /* enable optimizations */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern NCURSES_EXPORT(const char *) _nc_viswbuf(const wchar_t *); +#endif +extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *); +#define OPTIMIZE_MVCUR 0x01 /* cursor movement optimization */ +#define OPTIMIZE_HASHMAP 0x02 /* diff hashing to detect scrolls */ +#define OPTIMIZE_SCROLL 0x04 /* scroll optimization */ +#define OPTIMIZE_ALL 0xff /* enable all optimizations (dflt) */ +#endif + +#ifdef __cplusplus + +/* these names conflict with STL */ +#undef box +#undef clear +#undef erase +#undef move +#undef refresh + +} +#endif + +#endif /* __NCURSES_H */ diff --git a/src/include/ncurses_dll.h b/src/include/ncurses_dll.h new file mode 100644 index 0000000..28a5253 --- /dev/null +++ b/src/include/ncurses_dll.h @@ -0,0 +1,48 @@ +/* $Id$ */ + +#ifndef NCURSES_DLL_H_incl +#define NCURSES_DLL_H_incl 1 + +#undef NCURSES_DLL /* cygwin dll not implemented */ +#define NCURSES_STATIC /* cygwin dll not implemented */ + +#if defined(__CYGWIN__) +# if defined(NCURSES_DLL) +# if defined(NCURSES_STATIC) +# undef NCURSES_STATIC +# endif +# endif +# undef NCURSES_IMPEXP +# undef NCURSES_API +# undef NCURSES_EXPORT(type) +# undef NCURSES_EXPORT_VAR(type) +# if defined(NCURSES_DLL) +/* building a DLL */ +# define NCURSES_IMPEXP __declspec(dllexport) +# elif defined(NCURSES_STATIC) +/* building or linking to a static library */ +# define NCURSES_IMPEXP /* nothing */ +# else +/* linking to the DLL */ +# define NCURSES_IMPEXP __declspec(dllimport) +# endif +# define NCURSES_API __cdecl +# define NCURSES_EXPORT(type) NCURSES_IMPEXP type NCURSES_API +# define NCURSES_EXPORT_VAR(type) NCURSES_IMPEXP type +#endif + +/* Take care of non-cygwin platforms */ +#if !defined(NCURSES_IMPEXP) +# define NCURSES_IMPEXP /* nothing */ +#endif +#if !defined(NCURSES_API) +# define NCURSES_API /* nothing */ +#endif +#if !defined(NCURSES_EXPORT) +# define NCURSES_EXPORT(type) NCURSES_IMPEXP type NCURSES_API +#endif +#if !defined(NCURSES_EXPORT_VAR) +# define NCURSES_EXPORT_VAR(type) NCURSES_IMPEXP type +#endif + +#endif /* NCURSES_DLL_H_incl */ diff --git a/src/include/ndbm.h b/src/include/ndbm.h new file mode 100644 index 0000000..1637cd9 --- /dev/null +++ b/src/include/ndbm.h @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + * + * @(#)ndbm.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/ndbm.h,v 1.4 2002/03/23 17:24:53 imp Exp $ + */ + +#ifndef _NDBM_H_ +#define _NDBM_H_ + +#include + +/* Map dbm interface onto db(3). */ +#define DBM_RDONLY O_RDONLY + +/* Flags to dbm_store(). */ +#define DBM_INSERT 0 +#define DBM_REPLACE 1 + +/* + * The db(3) support for ndbm always appends this suffix to the + * file name to avoid overwriting the user's original database. + */ +#define DBM_SUFFIX ".db" + +typedef struct { + char *dptr; + int dsize; +} datum; + +typedef DB DBM; +#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE + +__BEGIN_DECLS +int dbm_clearerr(DBM *); +void dbm_close(DBM *); +int dbm_delete(DBM *, datum); +int dbm_error(DBM *); +datum dbm_fetch(DBM *, datum); +datum dbm_firstkey(DBM *); +long dbm_forder(DBM *, datum); +datum dbm_nextkey(DBM *); +DBM *dbm_open(const char *, int, int); +int dbm_store(DBM *, datum, datum, int); +int dbm_dirfno(DBM *); +__END_DECLS + +#endif /* !_NDBM_H_ */ diff --git a/src/include/netconfig.h b/src/include/netconfig.h new file mode 100644 index 0000000..cead321 --- /dev/null +++ b/src/include/netconfig.h @@ -0,0 +1,96 @@ +/* $NetBSD: netconfig.h,v 1.1 2000/06/02 22:57:54 fvdl Exp $ */ +/* $FreeBSD: src/include/netconfig.h,v 1.3 2002/03/23 17:24:53 imp Exp $ */ + + +#ifndef _NETCONFIG_H_ +#define _NETCONFIG_H_ + +#include + +#define NETCONFIG "/etc/netconfig" +#define NETPATH "NETPATH" + +struct netconfig { + char *nc_netid; /* Network ID */ + unsigned long nc_semantics; /* Semantics (see below) */ + unsigned long nc_flag; /* Flags (see below) */ + char *nc_protofmly; /* Protocol family */ + char *nc_proto; /* Protocol name */ + char *nc_device; /* Network device pathname */ + unsigned long nc_nlookups; /* Number of directory lookup libs */ + char **nc_lookups; /* Names of the libraries */ + unsigned long nc_unused[9]; /* reserved */ +}; + +typedef struct { + struct netconfig **nc_head; + struct netconfig **nc_curr; +} NCONF_HANDLE; + +/* + * nc_semantics values + */ +#define NC_TPI_CLTS 1 +#define NC_TPI_COTS 2 +#define NC_TPI_COTS_ORD 3 +#define NC_TPI_RAW 4 + +/* + * nc_flag values + */ +#define NC_NOFLAG 0x00 +#define NC_VISIBLE 0x01 +#define NC_BROADCAST 0x02 + +/* + * nc_protofmly values + */ +#define NC_NOPROTOFMLY "-" +#define NC_LOOPBACK "loopback" +#define NC_INET "inet" +#define NC_INET6 "inet6" +#define NC_IMPLINK "implink" +#define NC_PUP "pup" +#define NC_CHAOS "chaos" +#define NC_NS "ns" +#define NC_NBS "nbs" +#define NC_ECMA "ecma" +#define NC_DATAKIT "datakit" +#define NC_CCITT "ccitt" +#define NC_SNA "sna" +#define NC_DECNET "decnet" +#define NC_DLI "dli" +#define NC_LAT "lat" +#define NC_HYLINK "hylink" +#define NC_APPLETALK "appletalk" +#define NC_NIT "nit" +#define NC_IEEE802 "ieee802" +#define NC_OSI "osi" +#define NC_X25 "x25" +#define NC_OSINET "osinet" +#define NC_GOSIP "gosip" + +/* + * nc_proto values + */ +#define NC_NOPROTO "-" +#define NC_TCP "tcp" +#define NC_UDP "udp" +#define NC_ICMP "icmp" + +__BEGIN_DECLS +void *setnetconfig(void); +struct netconfig *getnetconfig(void *); +struct netconfig *getnetconfigent(const char *); +void freenetconfigent(struct netconfig *); +int endnetconfig(void *); + +void *setnetpath(void); +struct netconfig *getnetpath(void *); +int endnetpath(void *); + +void nc_perror(const char *); +char *nc_sperror(void); +__END_DECLS + +#endif /* _NETCONFIG_H_ */ diff --git a/src/include/netdb.h b/src/include/netdb.h new file mode 100644 index 0000000..d2911f5 --- /dev/null +++ b/src/include/netdb.h @@ -0,0 +1,272 @@ +/*- + * Copyright (c) 1980, 1983, 1988, 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. + * + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * - + * --Copyright-- + */ + +/* + * @(#)netdb.h 8.1 (Berkeley) 6/2/93 + * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ + * $FreeBSD: src/include/netdb.h,v 1.32 2004/02/25 21:03:44 green Exp $ + */ + +#ifndef _NETDB_H_ +#define _NETDB_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SOCKLEN_T_DECLARED +typedef __socklen_t socklen_t; +#define _SOCKLEN_T_DECLARED +#endif + +#ifndef _PATH_HEQUIV +# define _PATH_HEQUIV "/etc/hosts.equiv" +#endif +#define _PATH_HOSTS "/etc/hosts" +#define _PATH_NETWORKS "/etc/networks" +#define _PATH_PROTOCOLS "/etc/protocols" +#define _PATH_SERVICES "/etc/services" + +#define h_errno (*__h_error()) + +/* + * Structures returned by network data base library. All addresses are + * supplied in host order, and returned in network order (suitable for + * use in system calls). + */ +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +#define h_addr h_addr_list[0] /* address, for backward compatibility */ +}; + +/* + * Assumption here is that a network number + * fits in an unsigned long -- probably a poor one. + */ +struct netent { + char *n_name; /* official name of net */ + char **n_aliases; /* alias list */ + int n_addrtype; /* net address type */ + unsigned long n_net; /* network # */ +}; + +struct servent { + char *s_name; /* official service name */ + char **s_aliases; /* alias list */ + int s_port; /* port # */ + char *s_proto; /* protocol to use */ +}; + +struct protoent { + char *p_name; /* official protocol name */ + char **p_aliases; /* alias list */ + int p_proto; /* protocol # */ +}; + +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for hostname */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; + +/* + * Error return codes from gethostbyname() and gethostbyaddr() + * (left in h_errno). + */ + +#define NETDB_INTERNAL -1 /* see errno */ +#define NETDB_SUCCESS 0 /* no problem */ +#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ +#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ +#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ +#define NO_DATA 4 /* Valid name, no data record of requested type */ +#define NO_ADDRESS NO_DATA /* no address, look for MX record */ + +/* + * Error return codes from getaddrinfo() + */ +#if 0 +/* obsoleted */ +#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ +#endif +#define EAI_AGAIN 2 /* temporary failure in name resolution */ +#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* ai_family not supported */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#if 0 +/* obsoleted */ +#define EAI_NODATA 7 /* no address associated with hostname */ +#endif +#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ +#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ +#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ +#define EAI_SYSTEM 11 /* system error returned in errno */ +#define EAI_BADHINTS 12 +#define EAI_PROTOCOL 13 +#define EAI_MAX 14 + +/* + * Flag values for getaddrinfo() + */ +#define AI_PASSIVE 0x00000001 /* get address to use bind() */ +#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ +#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ +/* valid flags for addrinfo */ +#define AI_MASK \ + (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG) + +#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ +#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ +#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ +#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ +/* special recommended flags for getipnodebyname */ +#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) + +/* + * Constants for getnameinfo() + */ +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 + +/* + * Flag values for getnameinfo() + */ +#define NI_NOFQDN 0x00000001 +#define NI_NUMERICHOST 0x00000002 +#define NI_NAMEREQD 0x00000004 +#define NI_NUMERICSERV 0x00000008 +#define NI_DGRAM 0x00000010 +#if 1 /* obsolete */ +#define NI_WITHSCOPEID 0x00000020 +#endif + +/* + * Scope delimit character + */ +#define SCOPE_DELIMITER '%' + +__BEGIN_DECLS +void endhostent(void); +void endnetent(void); +void endnetgrent(void); +void endprotoent(void); +void endservent(void); +void freehostent(struct hostent *); +struct hostent *gethostbyaddr(const char *, int, int); +struct hostent *gethostbyname(const char *); +struct hostent *gethostbyname2(const char *, int); +struct hostent *gethostent(void); +struct hostent *getipnodebyaddr(const void *, size_t, int, int *); +struct hostent *getipnodebyname(const char *, int, int, int *); +struct netent *getnetbyaddr(unsigned long, int); +struct netent *getnetbyname(const char *); +struct netent *getnetent(void); +int getnetgrent(char **, char **, char **); +struct protoent *getprotobyname(const char *); +struct protoent *getprotobynumber(int); +struct protoent *getprotoent(void); +struct servent *getservbyname(const char *, const char *); +struct servent *getservbyport(int, const char *); +struct servent *getservent(void); +void herror(const char *); +__const char *hstrerror(int); +int innetgr(const char *, const char *, const char *, const char *); +void sethostent(int); +/* void sethostfile(const char *); */ +void setnetent(int); +void setprotoent(int); +int getaddrinfo(const char *, const char *, + const struct addrinfo *, struct addrinfo **); +int getnameinfo(const struct sockaddr *, socklen_t, char *, + size_t, char *, size_t, int); +void freeaddrinfo(struct addrinfo *); +char *gai_strerror(int); +void setnetgrent(const char *); +void setservent(int); + +/* + * PRIVATE functions specific to the FreeBSD implementation + */ + +/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ +int * __h_error(void); +void _sethosthtent(int); +void _endhosthtent(void); +void _sethostdnsent(int); +void _endhostdnsent(void); +void _setnethtent(int); +void _endnethtent(void); +void _setnetdnsent(int); +void _endnetdnsent(void); +struct hostent * _gethostbynisname(const char *, int); +struct hostent * _gethostbynisaddr(const char *, int, int); +void _map_v4v6_address(const char *, char *); +void _map_v4v6_hostent(struct hostent *, char **, char **); +__END_DECLS + +#endif /* !_NETDB_H_ */ diff --git a/src/include/netgraph.h b/src/include/netgraph.h new file mode 100644 index 0000000..21038a4 --- /dev/null +++ b/src/include/netgraph.h @@ -0,0 +1,69 @@ + +/* + * netgraph.h + * + * Copyright (c) 1996-1999 Whistle Communications, Inc. + * All rights reserved. + * + * Subject to the following obligations and disclaimer of warranty, use and + * redistribution of this software, in source or object code forms, with or + * without modifications are expressly permitted by Whistle Communications; + * provided, however, that: + * 1. Any and all reproductions of the source or object code must include the + * copyright notice above and the following disclaimer of warranties; and + * 2. No rights are granted, in any manner or form, to use Whistle + * Communications, Inc. trademarks, including the mark "WHISTLE + * COMMUNICATIONS" on advertising, endorsements, or otherwise except as + * such appears in the above copyright notice or in the software. + * + * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO + * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY + * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS + * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. + * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES + * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING + * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER 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 WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Archie Cobbs + * + * $FreeBSD: src/lib/libnetgraph/netgraph.h,v 1.4 2004/01/27 20:25:14 ru Exp $ + * $Whistle: netgraph.h,v 1.7 1999/01/20 00:57:23 archie Exp $ + */ + +#ifndef _NETGRAPH_H_ +#define _NETGRAPH_H_ + +#include +#include + +__BEGIN_DECLS +int NgMkSockNode(const char *, int *, int *); +int NgNameNode(int, const char *, const char *, ...) __printflike(3, 4); +int NgSendMsg(int, const char *, int, int, const void *, size_t); +int NgSendAsciiMsg(int, const char *, const char *, ...) __printflike(3, 4); +int NgSendReplyMsg(int, const char *, + const struct ng_mesg *, const void *, size_t); +int NgRecvMsg(int, struct ng_mesg *, size_t, char *); +int NgAllocRecvMsg(int, struct ng_mesg **, char *); +int NgRecvAsciiMsg(int, struct ng_mesg *, size_t, char *); +int NgAllocRecvAsciiMsg(int, struct ng_mesg **, char *); +int NgSendData(int, const char *, const u_char *, size_t); +int NgRecvData(int, u_char *, size_t, char *); +int NgAllocRecvData(int, u_char **, char *); +int NgSetDebug(int); +void NgSetErrLog(void (*)(const char *fmt, ...), + void (*)(const char *fmt, ...)); +__END_DECLS + +#endif + diff --git a/src/include/nl_types.h b/src/include/nl_types.h new file mode 100644 index 0000000..f064b12 --- /dev/null +++ b/src/include/nl_types.h @@ -0,0 +1,56 @@ +/*- + * Copyright 1990, by Alfalfa Software Incorporated, Cambridge, Massachusetts. + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and that + * both that copyright notice and this permission notice appear in + * supporting documentation, and that Alfalfa's name not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. + * + * ALPHALPHA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING + * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL + * ALPHALPHA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR + * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * + * If you make any modifications, bugfixes or other changes to this software + * we'd appreciate it if you could send a copy to us so we can keep things + * up-to-date. Many thanks. + * Kee Hinckley + * Alfalfa Software, Inc. + * 267 Allston St., #3 + * Cambridge, MA 02139 USA + * nazgul@alfalfa.com + * + * $FreeBSD: src/include/nl_types.h,v 1.10 2002/09/24 17:28:12 mike Exp $ + */ + +#ifndef _NL_TYPES_H_ +#define _NL_TYPES_H_ + +#include +#include + +#define NL_SETD 0 +#define NL_CAT_LOCALE 1 + +typedef void *nl_catd; + +#ifndef _NL_ITEM_DECLARED +typedef __nl_item nl_item; +#define _NL_ITEM_DECLARED +#endif + +__BEGIN_DECLS +nl_catd catopen(__const char *, int); +char *catgets(nl_catd, int, int, __const char *); +int catclose(nl_catd); +__END_DECLS + +#endif /* !_NL_TYPES_H_ */ diff --git a/src/include/nlist.h b/src/include/nlist.h new file mode 100644 index 0000000..ec55074 --- /dev/null +++ b/src/include/nlist.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)nlist.h 8.2 (Berkeley) 1/21/94 + * + * $FreeBSD: src/include/nlist.h,v 1.9 2002/08/22 20:37:57 peter Exp $ + */ + +#ifndef _NLIST_H_ +#define _NLIST_H_ + +#include +#include + +__BEGIN_DECLS +int nlist(const char *, struct nlist *); +__END_DECLS + +#endif /* !_NLIST_H_ */ diff --git a/src/include/nss.h b/src/include/nss.h new file mode 100644 index 0000000..792b16b --- /dev/null +++ b/src/include/nss.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/nss.h,v 1.2 2004/01/09 13:43:49 nectar Exp $ + * + * Compatibility header for the GNU C Library-style nsswitch interface. + */ +#ifndef _NSS_H_ +#define _NSS_H_ + +#include + +enum nss_status { + NSS_STATUS_TRYAGAIN = -2, + NSS_STATUS_UNAVAIL, + NSS_STATUS_NOTFOUND, + NSS_STATUS_SUCCESS, + NSS_STATUS_RETURN +}; + +#define __nss_compat_result(rv, err) \ +((rv == NSS_STATUS_TRYAGAIN && err == ERANGE) ? NS_RETURN : \ + (rv == NSS_STATUS_TRYAGAIN) ? NS_TRYAGAIN : \ + (rv == NSS_STATUS_UNAVAIL) ? NS_UNAVAIL : \ + (rv == NSS_STATUS_NOTFOUND) ? NS_NOTFOUND : \ + (rv == NSS_STATUS_SUCCESS) ? NS_SUCCESS : \ + (rv == NSS_STATUS_RETURN) ? NS_RETURN : 0) + +#endif diff --git a/src/include/nss_tls.h b/src/include/nss_tls.h new file mode 100644 index 0000000..7420f92 --- /dev/null +++ b/src/include/nss_tls.h @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/include/nss_tls.h,v 1.3 2004/03/30 15:56:15 nectar Exp $ + * + * Macros which generate thread local storage handling code in NSS modules. + */ +#ifndef _NSS_TLS_H_ +#define _NSS_TLS_H_ + +#define NSS_TLS_HANDLING(name) \ +static pthread_key_t name##_state_key; \ +static void name##_keyinit(void); \ +static int name##_getstate(struct name##_state **); \ +\ +static void \ +name##_keyinit(void) \ +{ \ + (void)_pthread_key_create(&name##_state_key, name##_endstate); \ +} \ +\ +static int \ +name##_getstate(struct name##_state **p) \ +{ \ + static struct name##_state st; \ + static pthread_once_t keyinit = PTHREAD_ONCE_INIT; \ + int rv; \ + \ + if (!__isthreaded || _pthread_main_np() != 0) { \ + *p = &st; \ + return (0); \ + } \ + rv = _pthread_once(&keyinit, name##_keyinit); \ + if (rv != 0) \ + return (rv); \ + *p = _pthread_getspecific(name##_state_key); \ + if (*p != NULL) \ + return (0); \ + *p = calloc(1, sizeof(**p)); \ + if (*p == NULL) \ + return (ENOMEM); \ + rv = _pthread_setspecific(name##_state_key, *p); \ + if (rv != 0) { \ + free(*p); \ + *p = NULL; \ + } \ + return (rv); \ +} \ +/* allow the macro invocation to end with a semicolon */ \ +struct _clashproof_bmVjdGFy + +#endif /* _NSS_TLS_H_ */ diff --git a/src/include/nsswitch.h b/src/include/nsswitch.h new file mode 100644 index 0000000..9936ad1 --- /dev/null +++ b/src/include/nsswitch.h @@ -0,0 +1,246 @@ +/* $NetBSD: nsswitch.h,v 1.6 1999/01/26 01:04:07 lukem Exp $ */ +/* $FreeBSD: src/include/nsswitch.h,v 1.3 2003/04/17 14:14:21 nectar Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef _NSSWITCH_H +#define _NSSWITCH_H 1 + +#include +#include + +#define NSS_MODULE_INTERFACE_VERSION 1 + +#ifndef _PATH_NS_CONF +#define _PATH_NS_CONF "/etc/nsswitch.conf" +#endif + +/* NSS source actions */ +#define NS_ACTION_CONTINUE 0 /* try the next source */ +#define NS_ACTION_RETURN 1 /* look no further */ + +#define NS_SUCCESS (1<<0) /* entry was found */ +#define NS_UNAVAIL (1<<1) /* source not responding, or corrupt */ +#define NS_NOTFOUND (1<<2) /* source responded 'no such entry' */ +#define NS_TRYAGAIN (1<<3) /* source busy, may respond to retry */ +#define NS_RETURN (1<<4) /* stop search, e.g. for ERANGE */ +#define NS_TERMINATE (NS_SUCCESS|NS_RETURN) /* flags that end search */ +#define NS_STATUSMASK 0x000000ff /* bitmask to get the status flags */ + +/* + * currently implemented sources + */ +#define NSSRC_FILES "files" /* local files */ +#define NSSRC_DNS "dns" /* DNS; IN for hosts, HS for others */ +#define NSSRC_NIS "nis" /* YP/NIS */ +#define NSSRC_COMPAT "compat" /* passwd,group in YP compat mode */ + +/* + * currently implemented databases + */ +#define NSDB_HOSTS "hosts" +#define NSDB_GROUP "group" +#define NSDB_GROUP_COMPAT "group_compat" +#define NSDB_NETGROUP "netgroup" +#define NSDB_NETWORKS "networks" +#define NSDB_PASSWD "passwd" +#define NSDB_PASSWD_COMPAT "passwd_compat" +#define NSDB_SHELLS "shells" + +/* + * suggested databases to implement + */ +#define NSDB_ALIASES "aliases" +#define NSDB_AUTH "auth" +#define NSDB_AUTOMOUNT "automount" +#define NSDB_BOOTPARAMS "bootparams" +#define NSDB_ETHERS "ethers" +#define NSDB_EXPORTS "exports" +#define NSDB_NETMASKS "netmasks" +#define NSDB_PHONES "phones" +#define NSDB_PRINTCAP "printcap" +#define NSDB_PROTOCOLS "protocols" +#define NSDB_REMOTE "remote" +#define NSDB_RPC "rpc" +#define NSDB_SENDMAILVARS "sendmailvars" +#define NSDB_SERVICES "services" +#define NSDB_TERMCAP "termcap" +#define NSDB_TTYS "ttys" + +/* + * ns_dtab `method' function signature. + */ +typedef int (*nss_method)(void *_retval, void *_mdata, va_list _ap); + +/* + * Macro for generating method prototypes. + */ +#define NSS_METHOD_PROTOTYPE(method) \ + int method(void *, void *, va_list) + +/* + * ns_dtab - `nsswitch dispatch table' + * Contains an entry for each source and the appropriate function to + * call. ns_dtabs are used in the nsdispatch() API in order to allow + * the application to override built-in actions. + */ +typedef struct _ns_dtab { + const char *src; /* Source this entry implements */ + nss_method method; /* Method to be called */ + void *mdata; /* Data passed to method */ +} ns_dtab; + +/* + * macros to help build an ns_dtab[] + */ +#define NS_FILES_CB(F,C) { NSSRC_FILES, F, C }, +#define NS_COMPAT_CB(F,C) { NSSRC_COMPAT, F, C }, + +#ifdef HESIOD +# define NS_DNS_CB(F,C) { NSSRC_DNS, F, C }, +#else +# define NS_DNS_CB(F,C) +#endif + +#ifdef YP +# define NS_NIS_CB(F,C) { NSSRC_NIS, F, C }, +#else +# define NS_NIS_CB(F,C) +#endif + +/* + * ns_src - `nsswitch source' + * used by the nsparser routines to store a mapping between a source + * and its dispatch control flags for a given database. + */ +typedef struct _ns_src { + const char *name; + u_int32_t flags; +} ns_src; + + +/* + * default sourcelist (if nsswitch.conf is missing, corrupt, + * or the requested database doesn't have an entry. + */ +extern const ns_src __nsdefaultsrc[]; + +/* + * ns_mtab - NSS method table + * An NSS module provides a mapping from (database name, method name) + * tuples to the nss_method and associated data. + */ +typedef struct _ns_mtab { + const char *database; + const char *name; + nss_method method; + void *mdata; +} ns_mtab; + +/* + * NSS module de-registration, called at module unload. + */ +typedef void (*nss_module_unregister_fn)(ns_mtab *, unsigned int); + +/* + * NSS module registration, called at module load. + */ +typedef ns_mtab *(*nss_module_register_fn)(const char *, unsigned int *, + nss_module_unregister_fn *); + +/* + * Many NSS interfaces follow the getXXnam, getXXid, getXXent pattern. + * Developers are encouraged to use nss_lookup_type where approriate. + */ +enum nss_lookup_type { + nss_lt_name = 1, + nss_lt_id = 2, + nss_lt_all = 3 +}; + +#ifdef _NS_PRIVATE + +/* + * private data structures for back-end nsswitch implementation + */ + +/* + * ns_dbt - `nsswitch database thang' + * for each database in /etc/nsswitch.conf there is a ns_dbt, with its + * name and a list of ns_src's containing the source information. + */ +typedef struct _ns_dbt { + const char *name; /* name of database */ + ns_src *srclist; /* list of sources */ + int srclistsize; /* size of srclist */ +} ns_dbt; + +/* + * ns_mod - NSS module + */ +typedef struct _ns_mod { + char *name; /* module name */ + void *handle; /* handle from dlopen */ + ns_mtab *mtab; /* method table */ + unsigned int mtabsize; /* count of entries in method table */ + nss_module_unregister_fn unregister; /* called to unload module */ +} ns_mod; + +#endif /* _NS_PRIVATE */ + + +#include + +__BEGIN_DECLS +extern int nsdispatch(void *, const ns_dtab [], const char *, + const char *, const ns_src [], ...); + +#ifdef _NS_PRIVATE +extern void _nsdbtaddsrc(ns_dbt *, const ns_src *); +extern void _nsdbtput(const ns_dbt *); +extern void _nsyyerror(const char *); +extern int _nsyylex(void); +extern int _nsyyparse(void); +extern int _nsyylineno; +#ifdef _NSS_DEBUG +extern void _nsdbtdump(const ns_dbt *); +#endif +#endif /* _NS_PRIVATE */ + +__END_DECLS + +#endif /* !_NSSWITCH_H */ diff --git a/src/include/objformat.h b/src/include/objformat.h new file mode 100644 index 0000000..e894323 --- /dev/null +++ b/src/include/objformat.h @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 1998 John D. Polstra + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/objformat.h,v 1.2 1999/08/27 23:44:51 peter Exp $ + */ + +#ifndef _OBJFORMAT_H_ +#define _OBJFORMAT_H_ + +#include +#include + +__BEGIN_DECLS +int getobjformat(char *, size_t, int *, char **); +__END_DECLS + +#endif /* _OBJFORMAT_H_ */ diff --git a/src/include/opie.h b/src/include/opie.h new file mode 100644 index 0000000..a3fe84f --- /dev/null +++ b/src/include/opie.h @@ -0,0 +1,175 @@ +/* opie.h: Data structures and values for the OPIE authentication + system that a program might need. + +%%% portions-copyright-cmetz-96 +Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights +Reserved. The Inner Net License Version 2 applies to these portions of +the software. +You should have received a copy of the license with this software. If +you didn't get a copy, you may request one from . + +Portions of this software are Copyright 1995 by Randall Atkinson and Dan +McDonald, All Rights Reserved. All Rights under this copyright are assigned +to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and +License Agreement applies to this software. + + History: + + Modified by cmetz for OPIE 2.4. Added sequence number limits. Added + struct opie_otpkey and made many functions use it. Added + opiestrncpy(). Include header with libmissing prototypes. + Modified by cmetz for OPIE 2.32. Added symbolic flag names for + opiepasswd(). Added __opieparsechallenge() prototype. + Modified by cmetz for OPIE 2.31. Removed active attack protection. + Modified by cmetz for OPIE 2.3. Renamed PTR to VOIDPTR. Added + re-init key and extension file fields to struct opie. Added + opie_ prefix on struct opie members. Added opie_flags field + and definitions. Added more prototypes. Changed opiehash() + prototype. + Modified by cmetz for OPIE 2.22. Define __P correctly if this file + is included in a third-party program. + Modified by cmetz for OPIE 2.2. Re-did prototypes. Added FUNCTION + definition et al. Multiple-include protection. Added struct + utsname fake. Got rid of gethostname() cruft. Moved UINT4 + here. Provide for *seek whence values. Move MDx context here + and unify. Re-did prototypes. + Modified at NRL for OPIE 2.0. + Written at Bellcore for the S/Key Version 1 software distribution + (skey.h). + +$FreeBSD: src/contrib/opie/opie.h,v 1.8 2002/03/21 23:42:52 markm Exp $ +*/ +#ifndef _OPIE_H +#define _OPIE_H 1 + +struct opie { + int opie_flags; + char opie_buf[256]; + char *opie_principal; + int opie_n; + char *opie_seed; + char *opie_val; + long opie_recstart; +}; + +#define __OPIE_FLAGS_RW 1 +#define __OPIE_FLAGS_READ 2 + +/* Minimum length of a secret password */ +#ifndef OPIE_SECRET_MIN +#define OPIE_SECRET_MIN 10 +#endif /* OPIE_SECRET_MIN */ + +/* Maximum length of a secret password */ +#define OPIE_SECRET_MAX 127 + +/* Minimum length of a seed */ +#define OPIE_SEED_MIN 5 + +/* Maximum length of a seed */ +#define OPIE_SEED_MAX 16 + +/* Max length of hash algorithm name (md4/md5) */ +#define OPIE_HASHNAME_MAX 3 + +/* Maximum length of a challenge (otp-md? 9999 seed) */ +#define OPIE_CHALLENGE_MAX (4+OPIE_HASHNAME_MAX+1+4+1+OPIE_SEED_MAX) + +/* Maximum length of a response that we allow */ +#define OPIE_RESPONSE_MAX (9+1+19+1+9+OPIE_SEED_MAX+1+19+1+19+1+19) + +/* Maximum length of a principal (read: user name) */ +#define OPIE_PRINCIPAL_MAX 32 + +/* Maximum sequence number */ +#ifndef OPIE_SEQUENCE_MAX +#define OPIE_SEQUENCE_MAX 9999 +#endif /* OPIE_SEQUENCE_MAX */ + +/* Restricted sequence number */ +#ifndef OPIE_SEQUENCE_RESTRICT +#define OPIE_SEQUENCE_RESTRICT 9 +#endif /* OPIE_SEQUENCE_RESTRICT */ + +#define UINT4 u_int32_t + +struct opie_otpkey { + UINT4 words[2]; +}; + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif /* SEEK_SET */ + +#ifndef SEEK_END +#define SEEK_END 2 +#endif /* SEEK_END */ + +__BEGIN_DECLS +int opieaccessfile __P((char *)); +int rdnets __P((long)); +int isaddr __P((register char *)); +int opiealways __P((char *)); +char *opieatob8 __P((struct opie_otpkey *, char *)); +void opiebackspace __P((char *)); +char *opiebtoa8 __P((char *, struct opie_otpkey *)); +char *opiebtoe __P((char *, struct opie_otpkey *)); +char *opiebtoh __P((char *, struct opie_otpkey *)); +int opieetob __P((struct opie_otpkey *, char *)); +int opiechallenge __P((struct opie *,char *,char *)); +int opiegenerator __P((char *,char *,char *)); +int opiegetsequence __P((struct opie *)); +void opiehash __P((struct opie_otpkey *, unsigned)); +int opiehtoi __P((register char)); +int opiekeycrunch __P((int, struct opie_otpkey *, char *, char *)); +int opielock __P((char *)); +int opieunlock __P((void)); +void opieunlockaeh __P((void)); +void opiedisableaeh __P((void)); +int opielookup __P((struct opie *,char *)); +int opiepasscheck __P((char *)); +void opierandomchallenge __P((char *)); +char * opieskipspace __P((register char *)); +void opiestripcrlf __P((char *)); +int opieverify __P((struct opie *,char *)); +int opiepasswd __P((struct opie *, int, char *, int, char *, char *)); +char *opiereadpass __P((char *, int, int)); +int opielogin __P((char *line, char *name, char *host)); +const char *opie_get_algorithm __P((void)); +int opie_haskey __P((char *username)); +char *opie_keyinfo __P((char *)); +int opie_passverify __P((char *username, char *passwd)); +__END_DECLS + +#if _OPIE +#define VOIDPTR void * +#define VOIDRET void +#define NOARGS void +#define FUNCTION(arglist, args) (args) +#define AND , +#define FUNCTION_NOARGS () + +__BEGIN_DECLS +struct utmp; +int __opiegetutmpentry __P((char *, struct utmp *)); +#ifdef EOF +FILE *__opieopen __P((char *, int, int)); +#endif /* EOF */ +int __opiereadrec __P((struct opie *)); +int __opiewriterec __P((struct opie *)); +int __opieparsechallenge __P((char *buffer, int *algorithm, int *sequence, char **seed, int *exts)); +__END_DECLS + +#define opiestrncpy(dst, src, n) \ + do { \ + strncpy(dst, src, n-1); \ + dst[n-1] = 0; \ + } while(0) + +/* #include "missing.h" */ +#endif /* _OPIE */ + +#define OPIEPASSWD_CONSOLE 1 +#define OPIEPASSWD_FORCE 2 + +#endif /* _OPIE_H */ diff --git a/src/include/osreldate.h b/src/include/osreldate.h new file mode 100644 index 0000000..1d59ef6 --- /dev/null +++ b/src/include/osreldate.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 1992-2004 The FreeBSD Project. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#ifdef _KERNEL +#error " cannot be used in the kernel, use " +#else +#undef __FreeBSD_version +#define __FreeBSD_version 502112 +#endif diff --git a/src/include/panel.h b/src/include/panel.h new file mode 100644 index 0000000..3b8542a --- /dev/null +++ b/src/include/panel.h @@ -0,0 +1,75 @@ +/**************************************************************************** + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim 1995 * + * and: Eric S. Raymond * + ****************************************************************************/ + +/* panel.h -- interface file for panels library */ + +#ifndef NCURSES_PANEL_H_incl +#define NCURSES_PANEL_H_incl 1 + +#include + +typedef struct panel +{ + WINDOW *win; + struct panel *below; + struct panel *above; + NCURSES_CONST void *user; +} PANEL; + +#if defined(__cplusplus) +extern "C" { +#endif + +extern NCURSES_EXPORT(WINDOW*) panel_window (const PANEL *); +extern NCURSES_EXPORT(void) update_panels (void); +extern NCURSES_EXPORT(int) hide_panel (PANEL *); +extern NCURSES_EXPORT(int) show_panel (PANEL *); +extern NCURSES_EXPORT(int) del_panel (PANEL *); +extern NCURSES_EXPORT(int) top_panel (PANEL *); +extern NCURSES_EXPORT(int) bottom_panel (PANEL *); +extern NCURSES_EXPORT(PANEL*) new_panel (WINDOW *); +extern NCURSES_EXPORT(PANEL*) panel_above (const PANEL *); +extern NCURSES_EXPORT(PANEL*) panel_below (const PANEL *); +extern NCURSES_EXPORT(int) set_panel_userptr (PANEL *, NCURSES_CONST void *); +extern NCURSES_EXPORT(NCURSES_CONST void*) panel_userptr (const PANEL *); +extern NCURSES_EXPORT(int) move_panel (PANEL *, int, int); +extern NCURSES_EXPORT(int) replace_panel (PANEL *,WINDOW *); +extern NCURSES_EXPORT(int) panel_hidden (const PANEL *); + +#if defined(__cplusplus) +} +#endif + +#endif /* NCURSES_PANEL_H_incl */ + +/* end of panel.h */ diff --git a/src/include/paths.h b/src/include/paths.h new file mode 100644 index 0000000..952a3ae --- /dev/null +++ b/src/include/paths.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 1989, 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. + * + * @(#)paths.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/paths.h,v 1.25 2004/01/04 17:17:46 iedowse Exp $ + */ + +#ifndef _PATHS_H_ +#define _PATHS_H_ + +#include + +/* Default search path. */ +#define _PATH_DEFPATH "/usr/bin:/bin" +/* All standard utilities path. */ +#define _PATH_STDPATH \ + "/usr/bin:/bin:/usr/sbin:/sbin:" +/* Locate system binaries */ +#define _PATH_SYSPATH \ + "/sbin:/usr/sbin" + +#define _PATH_AUTHCONF "/etc/auth.conf" +#define _PATH_BSHELL "/bin/sh" +#define _PATH_CAPABILITY "/etc/capability" +#define _PATH_CAPABILITY_DB "/etc/capability.db" +#define _PATH_CONSOLE "/dev/console" +#define _PATH_CP "/bin/cp" +#define _PATH_CSHELL "/bin/csh" +#define _PATH_DEFTAPE "/dev/sa0" +#define _PATH_DEVNULL "/dev/null" +#define _PATH_DEVZERO "/dev/zero" +#define _PATH_DRUM "/dev/drum" +#define _PATH_ETC "/etc" +#define _PATH_FTPUSERS "/etc/ftpusers" +#define _PATH_HALT "/sbin/halt" +#define _PATH_IFCONFIG "/sbin/ifconfig" +#define _PATH_KMEM "/dev/kmem" +#define _PATH_LIBMAP_CONF "/etc/libmap.conf" +#define _PATH_LOCALE "/usr/share/locale" +#define _PATH_LOGIN "/usr/bin/login" +#define _PATH_MAILDIR "/var/mail" +#define _PATH_MAN "/usr/share/man" +#define _PATH_MDCONFIG "/sbin/mdconfig" +#define _PATH_MEM "/dev/mem" +#define _PATH_MKSNAP_FFS "/sbin/mksnap_ffs" +#define _PATH_MOUNT "/sbin/mount" +#define _PATH_NEWFS "/sbin/newfs" +#define _PATH_NOLOGIN "/var/run/nologin" +#define _PATH_RCP "/bin/rcp" +#define _PATH_REBOOT "/sbin/reboot" +#define _PATH_RLOGIN "/usr/bin/rlogin" +#define _PATH_RM "/bin/rm" +#define _PATH_RSH "/usr/bin/rsh" +#define _PATH_SENDMAIL "/usr/sbin/sendmail" +#define _PATH_SHELLS "/etc/shells" +#define _PATH_TTY "/dev/tty" +#define _PATH_UNIX "don't use _PATH_UNIX" +#define _PATH_VI "/usr/bin/vi" +#define _PATH_WALL "/usr/bin/wall" + +/* Provide trailing slash, since mostly used for building pathnames. */ +#define _PATH_DEV "/dev/" +#define _PATH_TMP "/tmp/" +#define _PATH_VARDB "/var/db/" +#define _PATH_VARRUN "/var/run/" +#define _PATH_VARTMP "/var/tmp/" +#define _PATH_YP "/var/yp/" +#define _PATH_UUCPLOCK "/var/spool/lock/" + +/* How to get the correct name of the kernel. */ +__BEGIN_DECLS +const char *getbootfile(void); +__END_DECLS + +#ifdef RESCUE +#undef _PATH_DEFPATH +#define _PATH_DEFPATH "/rescue:/usr/bin:/bin" +#undef _PATH_STDPATH +#define _PATH_STDPATH "/rescue:/usr/bin:/bin:/usr/sbin:/sbin" +#undef _PATH_SYSPATH +#define _PATH_SYSPATH "/rescue:/sbin:/usr/sbin" +#undef _PATH_BSHELL +#define _PATH_BSHELL "/rescue/sh" +#undef _PATH_CP +#define _PATH_CP "/rescue/cp" +#undef _PATH_CSHELL +#define _PATH_CSHELL "/rescue/csh" +#undef _PATH_HALT +#define _PATH_HALT "/rescue/halt" +#undef _PATH_IFCONFIG +#define _PATH_IFCONFIG "/rescue/ifconfig" +#undef _PATH_MDCONFIG +#define _PATH_MDCONFIG "/rescue/mdconfig" +#undef _PATH_MOUNT +#define _PATH_MOUNT "/rescue/mount" +#undef _PATH_NEWFS +#define _PATH_NEWFS "/rescue/newfs" +#undef _PATH_RCP +#define _PATH_RCP "/rescue/rcp" +#undef _PATH_REBOOT +#define _PATH_REBOOT "/rescue/reboot" +#undef _PATH_RM +#define _PATH_RM "/rescue/rm" +#undef _PATH_VI +#define _PATH_VI "/rescue/vi" +#undef _PATH_WALL +#define _PATH_WALL "/rescue/wall" +#endif /* RESCUE */ + +#endif /* !_PATHS_H_ */ diff --git a/src/include/pcap-int.h b/src/include/pcap-int.h new file mode 100644 index 0000000..8a8c1cd --- /dev/null +++ b/src/include/pcap-int.h @@ -0,0 +1,277 @@ +/* + * Copyright (c) 1994, 1995, 1996 + * 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 Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory 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. + * + * $FreeBSD: src/contrib/libpcap/pcap-int.h,v 1.9 2004/03/31 18:15:37 bms Exp $ + * @(#) $Header$ (LBL) + */ + +#ifndef pcap_int_h +#define pcap_int_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifdef WIN32 +#include +#endif /* WIN32 */ + +/* + * Savefile + */ +typedef enum { + NOT_SWAPPED, + SWAPPED, + MAYBE_SWAPPED +} swapped_type_t; + +struct pcap_sf { + FILE *rfile; + int swapped; + int hdrsize; + swapped_type_t lengths_swapped; + int version_major; + int version_minor; + u_char *base; +}; + +struct pcap_md { + struct pcap_stat stat; + /*XXX*/ + int use_bpf; /* using kernel filter */ + u_long TotPkts; /* can't oflow for 79 hrs on ether */ + u_long TotAccepted; /* count accepted by filter */ + u_long TotDrops; /* count of dropped packets */ + long TotMissed; /* missed by i/f during this run */ + long OrigMissed; /* missed by i/f before this run */ +#ifdef linux + int sock_packet; /* using Linux 2.0 compatible interface */ + int timeout; /* timeout specified to pcap_open_live */ + int clear_promisc; /* must clear promiscuous mode when we close */ + int cooked; /* using SOCK_DGRAM rather than SOCK_RAW */ + int lo_ifindex; /* interface index of the loopback device */ + char *device; /* device name */ + struct pcap *next; /* list of open promiscuous sock_packet pcaps */ +#endif + +#ifdef HAVE_DAG_API + void *dag_mem_base; /* DAG card memory base address */ + u_int dag_mem_bottom; /* DAG card current memory bottom pointer */ + u_int dag_mem_top; /* DAG card current memory top pointer */ + int dag_fcs_bits; /* Number of checksum bits from link layer */ + int dag_offset_flags; /* Flags to pass to dag_offset(). */ +#endif +}; + +struct pcap { +#ifdef WIN32 + ADAPTER *adapter; + LPPACKET Packet; + int timeout; + int nonblock; +#else + int fd; + int selectable_fd; +#endif /* WIN32 */ + int snapshot; + int linktype; + int tzoff; /* timezone offset */ + int offset; /* offset for proper alignment */ + + int break_loop; /* flag set to force break from packet-reading loop */ + + struct pcap_sf sf; + struct pcap_md md; + + /* + * Read buffer. + */ + int bufsize; + u_char *buffer; + u_char *bp; + int cc; + + /* + * Place holder for pcap_next(). + */ + u_char *pkt; + + /* + * Methods. + */ + int (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *); + int (*setfilter_op)(pcap_t *, struct bpf_program *); + int (*set_datalink_op)(pcap_t *, int); + int (*getnonblock_op)(pcap_t *, char *); + int (*setnonblock_op)(pcap_t *, int, char *); + int (*stats_op)(pcap_t *, struct pcap_stat *); + void (*close_op)(pcap_t *); + + /* + * Placeholder for filter code if bpf not in kernel. + */ + struct bpf_program fcode; + + char errbuf[PCAP_ERRBUF_SIZE + 1]; + int dlt_count; + int *dlt_list; + + struct pcap_pkthdr pcap_header; /* This is needed for the pcap_next_ex() to work */ +}; + +/* + * This is a timeval as stored in disk in a dumpfile. + * It has to use the same types everywhere, independent of the actual + * `struct timeval' + */ + +struct pcap_timeval { + bpf_int32 tv_sec; /* seconds */ + bpf_int32 tv_usec; /* microseconds */ +}; + +/* + * How a `pcap_pkthdr' is actually stored in the dumpfile. + * + * Do not change the format of this structure, in any way (this includes + * changes that only affect the length of fields in this structure), + * and do not make the time stamp anything other than seconds and + * microseconds (e.g., seconds and nanoseconds). Instead: + * + * introduce a new structure for the new format; + * + * send mail to "tcpdump-workers@tcpdump.org", requesting a new + * magic number for your new capture file format, and, when + * you get the new magic number, put it in "savefile.c"; + * + * use that magic number for save files with the changed record + * header; + * + * make the code in "savefile.c" capable of reading files with + * the old record header as well as files with the new record header + * (using the magic number to determine the header format). + * + * Then supply the changes to "patches@tcpdump.org", so that future + * versions of libpcap and programs that use it (such as tcpdump) will + * be able to read your new capture file format. + */ + +struct pcap_sf_pkthdr { + struct pcap_timeval ts; /* time stamp */ + bpf_u_int32 caplen; /* length of portion present */ + bpf_u_int32 len; /* length this packet (off wire) */ +}; + +/* + * How a `pcap_pkthdr' is actually stored in dumpfiles written + * by some patched versions of libpcap (e.g. the ones in Red + * Hat Linux 6.1 and 6.2). + * + * Do not change the format of this structure, in any way (this includes + * changes that only affect the length of fields in this structure). + * Instead, introduce a new structure, as per the above. + */ + +struct pcap_sf_patched_pkthdr { + struct pcap_timeval ts; /* time stamp */ + bpf_u_int32 caplen; /* length of portion present */ + bpf_u_int32 len; /* length this packet (off wire) */ + int index; + unsigned short protocol; + unsigned char pkt_type; +}; + +int yylex(void); + +#ifndef min +#define min(a, b) ((a) > (b) ? (b) : (a)) +#endif + +/* XXX should these be in pcap.h? */ +int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *); +int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *); + + +/* + * Ultrix, DEC OSF/1^H^H^H^H^H^H^H^H^HDigital UNIX^H^H^H^H^H^H^H^H^H^H^H^H + * Tru64 UNIX, and NetBSD pad to make everything line up on a nice boundary. + */ +#if defined(ultrix) || defined(__osf__) || defined(__NetBSD__) +#define PCAP_FDDIPAD 3 +#endif + +#include + +/* + * Routines that most pcap implementations can use for non-blocking mode. + */ +#ifndef WIN32 +int pcap_getnonblock_fd(pcap_t *, char *); +int pcap_setnonblock_fd(pcap_t *p, int, char *); +#endif + +/* + * Internal interfaces for "pcap_findalldevs()". + * + * "pcap_platform_finddevs()" is a platform-dependent routine to + * add devices not found by the "standard" mechanisms (SIOCGIFCONF, + * "getifaddrs()", etc.. + * + * "pcap_add_if()" adds an interface to the list of interfaces. + */ +int pcap_platform_finddevs(pcap_if_t **, char *); +int add_addr_to_iflist(pcap_if_t **, char *, u_int, struct sockaddr *, + size_t, struct sockaddr *, size_t, struct sockaddr *, size_t, + struct sockaddr *, size_t, char *); +int pcap_add_if(pcap_if_t **, char *, u_int, const char *, char *); +struct sockaddr *dup_sockaddr(struct sockaddr *, size_t); +int add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int, + const char *, char *); + +#ifdef WIN32 +char *pcap_win32strerror(void); +#endif + +/* XXX */ +extern int pcap_fddipad; + +int install_bpf_program(pcap_t *, struct bpf_program *); + +int pcap_strcasecmp(const char *, const char *); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/pcap-namedb.h b/src/include/pcap-namedb.h new file mode 100644 index 0000000..249c0cb --- /dev/null +++ b/src/include/pcap-namedb.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 1994, 1996 + * 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 Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory 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. + * + * $FreeBSD: src/contrib/libpcap/pcap-namedb.h,v 1.4 2001/04/03 04:32:48 fenner Exp $ + * @(#) $Header$ (LBL) + */ + +#ifndef lib_pcap_ethers_h +#define lib_pcap_ethers_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * As returned by the pcap_next_etherent() + * XXX this stuff doesn't belong in this interface, but this + * library already must do name to address translation, so + * on systems that don't have support for /etc/ethers, we + * export these hooks since they'll + */ +struct pcap_etherent { + u_char addr[6]; + char name[122]; +}; +#ifndef PCAP_ETHERS_FILE +#define PCAP_ETHERS_FILE "/etc/ethers" +#endif +struct pcap_etherent *pcap_next_etherent(FILE *); +u_char *pcap_ether_hostton(const char*); +u_char *pcap_ether_aton(const char *); + +bpf_u_int32 **pcap_nametoaddr(const char *); +#ifdef INET6 +struct addrinfo *pcap_nametoaddrinfo(const char *); +#endif +bpf_u_int32 pcap_nametonetaddr(const char *); + +int pcap_nametoport(const char *, int *, int *); +int pcap_nametoproto(const char *); +int pcap_nametoeproto(const char *); +/* + * If a protocol is unknown, PROTO_UNDEF is returned. + * Also, pcap_nametoport() returns the protocol along with the port number. + * If there are ambiguous entried in /etc/services (i.e. domain + * can be either tcp or udp) PROTO_UNDEF is returned. + */ +#define PROTO_UNDEF -1 + +/* XXX move these to pcap-int.h? */ +int __pcap_atodn(const char *, bpf_u_int32 *); +int __pcap_atoin(const char *, bpf_u_int32 *); +u_short __pcap_nametodnaddr(const char *); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/pcap.h b/src/include/pcap.h new file mode 100644 index 0000000..f66bc88 --- /dev/null +++ b/src/include/pcap.h @@ -0,0 +1,253 @@ +/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997 + * 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 Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory 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. + * + * $FreeBSD: src/contrib/libpcap/pcap.h,v 1.9 2004/03/31 10:21:28 bms Exp $ + * @(#) $Header$ (LBL) + */ + +#ifndef lib_pcap_h +#define lib_pcap_h + +#include +#include + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PCAP_VERSION_MAJOR 2 +#define PCAP_VERSION_MINOR 4 + +#define PCAP_ERRBUF_SIZE 256 + +/* + * Compatibility for systems that have a bpf.h that + * predates the bpf typedefs for 64-bit support. + */ +#if BPF_RELEASE - 0 < 199406 +typedef int bpf_int32; +typedef u_int bpf_u_int32; +#endif + +typedef struct pcap pcap_t; +typedef struct pcap_dumper pcap_dumper_t; +typedef struct pcap_if pcap_if_t; +typedef struct pcap_addr pcap_addr_t; + +/* + * The first record in the file contains saved values for some + * of the flags used in the printout phases of tcpdump. + * Many fields here are 32 bit ints so compilers won't insert unwanted + * padding; these files need to be interchangeable across architectures. + * + * Do not change the layout of this structure, in any way (this includes + * changes that only affect the length of fields in this structure). + * + * Also, do not change the interpretation of any of the members of this + * structure, in any way (this includes using values other than + * LINKTYPE_ values, as defined in "savefile.c", in the "linktype" + * field). + * + * Instead: + * + * introduce a new structure for the new format, if the layout + * of the structure changed; + * + * send mail to "tcpdump-workers@tcpdump.org", requesting a new + * magic number for your new capture file format, and, when + * you get the new magic number, put it in "savefile.c"; + * + * use that magic number for save files with the changed file + * header; + * + * make the code in "savefile.c" capable of reading files with + * the old file header as well as files with the new file header + * (using the magic number to determine the header format). + * + * Then supply the changes to "patches@tcpdump.org", so that future + * versions of libpcap and programs that use it (such as tcpdump) will + * be able to read your new capture file format. + */ +struct pcap_file_header { + bpf_u_int32 magic; + u_short version_major; + u_short version_minor; + bpf_int32 thiszone; /* gmt to local correction */ + bpf_u_int32 sigfigs; /* accuracy of timestamps */ + bpf_u_int32 snaplen; /* max length saved portion of each pkt */ + bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */ +}; + +/* + * Each packet in the dump file is prepended with this generic header. + * This gets around the problem of different headers for different + * packet interfaces. + */ +struct pcap_pkthdr { + struct timeval ts; /* time stamp */ + bpf_u_int32 caplen; /* length of portion present */ + bpf_u_int32 len; /* length this packet (off wire) */ +}; + +/* + * As returned by the pcap_stats() + */ +struct pcap_stat { + u_int ps_recv; /* number of packets received */ + u_int ps_drop; /* number of packets dropped */ + u_int ps_ifdrop; /* drops by interface XXX not yet supported */ +#ifdef WIN32 + u_int bs_capt; /* number of packets that reach the application */ +#endif /* WIN32 */ +}; + +/* + * Item in a list of interfaces. + */ +struct pcap_if { + struct pcap_if *next; + char *name; /* name to hand to "pcap_open_live()" */ + char *description; /* textual description of interface, or NULL */ + struct pcap_addr *addresses; + bpf_u_int32 flags; /* PCAP_IF_ interface flags */ +}; + +#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */ + +/* + * Representation of an interface address. + */ +struct pcap_addr { + struct pcap_addr *next; + struct sockaddr *addr; /* address */ + struct sockaddr *netmask; /* netmask for that address */ + struct sockaddr *broadaddr; /* broadcast address for that address */ + struct sockaddr *dstaddr; /* P2P destination address for that address */ +}; + +typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, + const u_char *); + +char *pcap_lookupdev(char *); +int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *); +pcap_t *pcap_open_live(const char *, int, int, int, char *); +pcap_t *pcap_open_dead(int, int); +pcap_t *pcap_open_offline(const char *, char *); +void pcap_close(pcap_t *); +int pcap_loop(pcap_t *, int, pcap_handler, u_char *); +int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); +const u_char* + pcap_next(pcap_t *, struct pcap_pkthdr *); +int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **); +void pcap_breakloop(pcap_t *); +int pcap_stats(pcap_t *, struct pcap_stat *); +int pcap_setfilter(pcap_t *, struct bpf_program *); +int pcap_getnonblock(pcap_t *, char *); +int pcap_setnonblock(pcap_t *, int, char *); +void pcap_perror(pcap_t *, char *); +char *pcap_strerror(int); +char *pcap_geterr(pcap_t *); +int pcap_compile(pcap_t *, struct bpf_program *, char *, int, + bpf_u_int32); +int pcap_compile_nopcap(int, int, struct bpf_program *, + char *, int, bpf_u_int32); +void pcap_freecode(struct bpf_program *); +int pcap_datalink(pcap_t *); +int pcap_list_datalinks(pcap_t *, int **); +int pcap_set_datalink(pcap_t *, int); +int pcap_datalink_name_to_val(const char *); +const char *pcap_datalink_val_to_name(int); +const char *pcap_datalink_val_to_description(int); +int pcap_snapshot(pcap_t *); +int pcap_is_swapped(pcap_t *); +int pcap_major_version(pcap_t *); +int pcap_minor_version(pcap_t *); + +/* XXX */ +FILE *pcap_file(pcap_t *); +int pcap_fileno(pcap_t *); + +pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); +int pcap_dump_flush(pcap_dumper_t *); +void pcap_dump_close(pcap_dumper_t *); +void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); +FILE *pcap_dump_file(pcap_dumper_t *); + +int pcap_findalldevs(pcap_if_t **, char *); +void pcap_freealldevs(pcap_if_t *); + +const char *pcap_lib_version(void); + +/* XXX this guy lives in the bpf tree */ +u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); +int bpf_validate(struct bpf_insn *f, int len); +char *bpf_image(struct bpf_insn *, int); +void bpf_dump(struct bpf_program *, int); + +#ifdef WIN32 +/* + * Win32 definitions + */ + +int pcap_setbuff(pcap_t *p, int dim); +int pcap_setmode(pcap_t *p, int mode); +int pcap_sendpacket(pcap_t *p, u_char *buf, int size); +int pcap_setmintocopy(pcap_t *p, int size); + +#ifdef WPCAP +/* Include file with the wpcap-specific extensions */ +#include +#endif + +#define MODE_CAPT 0 +#define MODE_STAT 1 +#define MODE_MON 2 + +#else +/* + * UN*X definitions + */ + +int pcap_get_selectable_fd(pcap_t *); + +#endif /* WIN32 */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/pmmintrin.h b/src/include/pmmintrin.h new file mode 100644 index 0000000..5649c00 --- /dev/null +++ b/src/include/pmmintrin.h @@ -0,0 +1,132 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + + This file is part of GNU CC. + + GNU CC is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU CC is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU CC; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, if you include this header file into source + files compiled by GCC, this header file does not by itself cause + the resulting executable to be covered by the GNU General Public + License. This exception does not however invalidate any other + reasons why the executable file might be covered by the GNU General + Public License. */ + +/* Implemented from the specification included in the Intel C++ Compiler + User Guide and Reference, version 8.0. */ + +#ifndef _PMMINTRIN_H_INCLUDED +#define _PMMINTRIN_H_INCLUDED + +#ifdef __PNI__ +#include +#include + +/* Additional bits in the MXCSR. */ +#define _MM_DENORMALS_ZERO_MASK 0x0040 +#define _MM_DENORMALS_ZERO_ON 0x0040 +#define _MM_DENORMALS_ZERO_OFF 0x0000 + +#define _MM_SET_DENORMALS_ZERO_MODE(mode) \ + _mm_setcsr ((_mm_getcsr () & ~_MM_DENORMALS_ZERO_MASK) | (mode)) +#define _MM_GET_DENORMALS_ZERO_MODE() \ + (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK) + +static __inline __m128 +_mm_addsub_ps (__m128 __X, __m128 __Y) +{ + return (__m128) __builtin_ia32_addsubps ((__v4sf)__X, (__v4sf)__Y); +} + +static __inline __m128 +_mm_hadd_ps (__m128 __X, __m128 __Y) +{ + return (__m128) __builtin_ia32_haddps ((__v4sf)__X, (__v4sf)__Y); +} + +static __inline __m128 +_mm_hsub_ps (__m128 __X, __m128 __Y) +{ + return (__m128) __builtin_ia32_hsubps ((__v4sf)__X, (__v4sf)__Y); +} + +static __inline __m128 +_mm_movehdup_ps (__m128 __X) +{ + return (__m128) __builtin_ia32_movshdup ((__v4sf)__X); +} + +static __inline __m128 +_mm_moveldup_ps (__m128 __X) +{ + return (__m128) __builtin_ia32_movsldup ((__v4sf)__X); +} + +static __inline __m128d +_mm_addsub_pd (__m128d __X, __m128d __Y) +{ + return (__m128d) __builtin_ia32_addsubpd ((__v2df)__X, (__v2df)__Y); +} + +static __inline __m128d +_mm_hadd_pd (__m128d __X, __m128d __Y) +{ + return (__m128d) __builtin_ia32_haddpd ((__v2df)__X, (__v2df)__Y); +} + +static __inline __m128d +_mm_hsub_pd (__m128d __X, __m128d __Y) +{ + return (__m128d) __builtin_ia32_hsubpd ((__v2df)__X, (__v2df)__Y); +} + +static __inline __m128d +_mm_loaddup_pd (double const *__P) +{ + return (__m128d) __builtin_ia32_loadddup (__P); +} + +static __inline __m128d +_mm_movedup_pd (__m128d __X) +{ + return (__m128d) __builtin_ia32_movddup ((__v2df)__X); +} + +static __inline __m128i +_mm_lddqu_si128 (__m128i const *__P) +{ + return (__m128i) __builtin_ia32_lddqu ((char const *)__P); +} + +#if 0 +static __inline void +_mm_monitor (void const * __P, unsigned int __E, unsigned int __H) +{ + __builtin_ia32_monitor (__P, __E, __H); +} + +static __inline void +_mm_mwait (unsigned int __E, unsigned int __H) +{ + __builtin_ia32_mwait (__E, __H); +} +#else +#define _mm_monitor(P, E, H) __builtin_ia32_monitor ((P), (E), (H)) +#define _mm_mwait(E, H) __builtin_ia32_mwait ((E), (H)) +#endif + +#endif /* __PNI__ */ + +#endif /* _PMMINTRIN_H_INCLUDED */ diff --git a/src/include/poll.h b/src/include/poll.h new file mode 100644 index 0000000..9ea42b9 --- /dev/null +++ b/src/include/poll.h @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 1997 Peter Wemm + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/poll.h,v 1.13 2002/07/10 04:47:25 mike Exp $ + */ + +#ifndef _SYS_POLL_H_ +#define _SYS_POLL_H_ + +#include + +/* + * This file is intended to be compatible with the traditional poll.h. + */ + +typedef unsigned int nfds_t; + +/* + * This structure is passed as an array to poll(2). + */ +struct pollfd { + int fd; /* which file descriptor to poll */ + short events; /* events we are interested in */ + short revents; /* events found on return */ +}; + +/* + * Requestable events. If poll(2) finds any of these set, they are + * copied to revents on return. + * XXX Note that FreeBSD doesn't make much distinction between POLLPRI + * and POLLRDBAND since none of the file types have distinct priority + * bands - and only some have an urgent "mode". + * XXX Note POLLIN isn't really supported in true SVSV terms. Under SYSV + * POLLIN includes all of normal, band and urgent data. Most poll handlers + * on FreeBSD only treat it as "normal" data. + */ +#define POLLIN 0x0001 /* any readable data available */ +#define POLLPRI 0x0002 /* OOB/Urgent readable data */ +#define POLLOUT 0x0004 /* file descriptor is writeable */ +#define POLLRDNORM 0x0040 /* non-OOB/URG data available */ +#define POLLWRNORM POLLOUT /* no write type differentiation */ +#define POLLRDBAND 0x0080 /* OOB/Urgent readable data */ +#define POLLWRBAND 0x0100 /* OOB/Urgent data can be written */ + +#if __BSD_VISIBLE +/* General FreeBSD extension (currently only supported for sockets): */ +#define POLLINIGNEOF 0x2000 /* like POLLIN, except ignore EOF */ +#endif + +/* + * These events are set if they occur regardless of whether they were + * requested. + */ +#define POLLERR 0x0008 /* some poll error occurred */ +#define POLLHUP 0x0010 /* file descriptor was "hung up" */ +#define POLLNVAL 0x0020 /* requested events "invalid" */ + +#if __BSD_VISIBLE + +#define POLLSTANDARD (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|\ + POLLWRBAND|POLLERR|POLLHUP|POLLNVAL) + +/* + * Request that poll() wait forever. + * XXX in SYSV, this is defined in stropts.h, which is not included + * by poll.h. + */ +#define INFTIM (-1) + +#endif + +#ifndef _KERNEL + +__BEGIN_DECLS +int poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_POLL_H_ */ diff --git a/src/include/pthread.h b/src/include/pthread.h new file mode 100644 index 0000000..dac74e5 --- /dev/null +++ b/src/include/pthread.h @@ -0,0 +1,324 @@ +/* + * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu + * Copyright (c) 1995-1998 by John Birrell + * 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * $FreeBSD: src/include/pthread.h,v 1.32 2003/11/04 20:10:15 deischen Exp $ + */ +#ifndef _PTHREAD_H_ +#define _PTHREAD_H_ + +/* + * Header files. + */ +#include +#include +#include +#include +#include +#include + +/* + * Run-time invariant values: + */ +#define PTHREAD_DESTRUCTOR_ITERATIONS 4 +#define PTHREAD_KEYS_MAX 256 +#define PTHREAD_STACK_MIN 1024 +#define PTHREAD_THREADS_MAX ULONG_MAX +#define PTHREAD_BARRIER_SERIAL_THREAD -1 + +/* + * Flags for threads and thread attributes. + */ +#define PTHREAD_DETACHED 0x1 +#define PTHREAD_SCOPE_SYSTEM 0x2 +#define PTHREAD_INHERIT_SCHED 0x4 +#define PTHREAD_NOFLOAT 0x8 + +#define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_SCOPE_PROCESS 0 +#define PTHREAD_EXPLICIT_SCHED 0 + +/* + * Flags for read/write lock attributes + */ +#define PTHREAD_PROCESS_PRIVATE 0 +#define PTHREAD_PROCESS_SHARED 1 + +/* + * Flags for cancelling threads + */ +#define PTHREAD_CANCEL_ENABLE 0 +#define PTHREAD_CANCEL_DISABLE 1 +#define PTHREAD_CANCEL_DEFERRED 0 +#define PTHREAD_CANCEL_ASYNCHRONOUS 2 +#define PTHREAD_CANCELED ((void *) 1) + +/* + * Forward structure definitions. + * + * These are mostly opaque to the user. + */ +struct pthread; +struct pthread_attr; +struct pthread_cond; +struct pthread_cond_attr; +struct pthread_mutex; +struct pthread_mutex_attr; +struct pthread_once; +struct pthread_rwlock; +struct pthread_rwlockattr; +struct pthread_barrier; +struct pthread_barrier_attr; +struct pthread_spinlock; + +/* + * Primitive system data type definitions required by P1003.1c. + * + * Note that P1003.1c specifies that there are no defined comparison + * or assignment operators for the types pthread_attr_t, pthread_cond_t, + * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t. + */ +typedef struct pthread *pthread_t; +typedef struct pthread_attr *pthread_attr_t; +typedef struct pthread_mutex *pthread_mutex_t; +typedef struct pthread_mutex_attr *pthread_mutexattr_t; +typedef struct pthread_cond *pthread_cond_t; +typedef struct pthread_cond_attr *pthread_condattr_t; +typedef int pthread_key_t; +typedef struct pthread_once pthread_once_t; +typedef struct pthread_rwlock *pthread_rwlock_t; +typedef struct pthread_rwlockattr *pthread_rwlockattr_t; +typedef struct pthread_barrier *pthread_barrier_t; +typedef struct pthread_barrierattr *pthread_barrierattr_t; +typedef struct pthread_spinlock *pthread_spinlock_t; + +/* + * Additional type definitions: + * + * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for + * use in header symbols. + */ +typedef void *pthread_addr_t; +typedef void *(*pthread_startroutine_t)(void *); + +/* + * Once definitions. + */ +struct pthread_once { + int state; + pthread_mutex_t mutex; +}; + +/* + * Flags for once initialization. + */ +#define PTHREAD_NEEDS_INIT 0 +#define PTHREAD_DONE_INIT 1 + +/* + * Static once initialization values. + */ +#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } + +/* + * Static initialization values. + */ +#define PTHREAD_MUTEX_INITIALIZER NULL +#define PTHREAD_COND_INITIALIZER NULL +#define PTHREAD_RWLOCK_INITIALIZER NULL + +/* + * Default attribute arguments (draft 4, deprecated). + */ +#ifndef PTHREAD_KERNEL +#define pthread_condattr_default NULL +#define pthread_mutexattr_default NULL +#define pthread_attr_default NULL +#endif + +#define PTHREAD_PRIO_NONE 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_PROTECT 2 + +/* + * Mutex types (Single UNIX Specification, Version 2, 1997). + * + * Note that a mutex attribute with one of the following types: + * + * PTHREAD_MUTEX_NORMAL + * PTHREAD_MUTEX_RECURSIVE + * MUTEX_TYPE_FAST (deprecated) + * MUTEX_TYPE_COUNTING_FAST (deprecated) + * + * will deviate from POSIX specified semantics. + */ +enum pthread_mutextype { + PTHREAD_MUTEX_ERRORCHECK = 1, /* Default POSIX mutex */ + PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */ + PTHREAD_MUTEX_NORMAL = 3, /* No error checking */ + MUTEX_TYPE_MAX +}; + +#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK +#define MUTEX_TYPE_FAST PTHREAD_MUTEX_NORMAL +#define MUTEX_TYPE_COUNTING_FAST PTHREAD_MUTEX_RECURSIVE + +/* + * Thread function prototype definitions: + */ +__BEGIN_DECLS +int pthread_atfork(void (*prepare)(void), void (*parent)(void), + void (*child)(void)); +int pthread_attr_destroy(pthread_attr_t *); +int pthread_attr_getstack(const pthread_attr_t * __restrict, + void ** __restrict stackaddr, + size_t * __restrict stacksize); +int pthread_attr_getstacksize(const pthread_attr_t *, size_t *); +int pthread_attr_getguardsize(const pthread_attr_t *, size_t *); +int pthread_attr_getstackaddr(const pthread_attr_t *, void **); +int pthread_attr_getdetachstate(const pthread_attr_t *, int *); +int pthread_attr_init(pthread_attr_t *); +int pthread_attr_setstacksize(pthread_attr_t *, size_t); +int pthread_attr_setguardsize(pthread_attr_t *, size_t); +int pthread_attr_setstack(pthread_attr_t *, void *, size_t); +int pthread_attr_setstackaddr(pthread_attr_t *, void *); +int pthread_attr_setdetachstate(pthread_attr_t *, int); +int pthread_barrier_destroy(pthread_barrier_t *); +int pthread_barrier_init(pthread_barrier_t *, + const pthread_barrierattr_t *, unsigned); +int pthread_barrier_wait(pthread_barrier_t *); +int pthread_barrierattr_destroy(pthread_barrierattr_t *); +int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, + int *); +int pthread_barrierattr_init(pthread_barrierattr_t *); +int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); +void pthread_cleanup_pop(int); +void pthread_cleanup_push(void (*) (void *), void *routine_arg); +int pthread_condattr_destroy(pthread_condattr_t *); +int pthread_condattr_init(pthread_condattr_t *); + +int pthread_cond_broadcast(pthread_cond_t *); +int pthread_cond_destroy(pthread_cond_t *); +int pthread_cond_init(pthread_cond_t *, + const pthread_condattr_t *); +int pthread_cond_signal(pthread_cond_t *); +int pthread_cond_timedwait(pthread_cond_t *, + pthread_mutex_t *, const struct timespec *); +int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); +int pthread_create(pthread_t *, const pthread_attr_t *, + void *(*) (void *), void *); +int pthread_detach(pthread_t); +int pthread_equal(pthread_t, pthread_t); +void pthread_exit(void *) __dead2; +void *pthread_getspecific(pthread_key_t); +int pthread_join(pthread_t, void **); +int pthread_key_create(pthread_key_t *, + void (*) (void *)); +int pthread_key_delete(pthread_key_t); +int pthread_kill(pthread_t, int); +int pthread_mutexattr_init(pthread_mutexattr_t *); +int pthread_mutexattr_destroy(pthread_mutexattr_t *); +int pthread_mutexattr_gettype(pthread_mutexattr_t *, int *); +int pthread_mutexattr_settype(pthread_mutexattr_t *, int); +int pthread_mutex_destroy(pthread_mutex_t *); +int pthread_mutex_init(pthread_mutex_t *, + const pthread_mutexattr_t *); +int pthread_mutex_lock(pthread_mutex_t *); +int pthread_mutex_trylock(pthread_mutex_t *); +int pthread_mutex_timedlock(pthread_mutex_t *, + const struct timespec *); +int pthread_mutex_unlock(pthread_mutex_t *); +int pthread_once(pthread_once_t *, void (*) (void)); +int pthread_rwlock_destroy(pthread_rwlock_t *); +int pthread_rwlock_init(pthread_rwlock_t *, + const pthread_rwlockattr_t *); +int pthread_rwlock_rdlock(pthread_rwlock_t *); +int pthread_rwlock_timedrdlock(pthread_rwlock_t *, + const struct timespec *); +int pthread_rwlock_timedrwlock(pthread_rwlock_t *, + const struct timespec *); +int pthread_rwlock_tryrdlock(pthread_rwlock_t *); +int pthread_rwlock_trywrlock(pthread_rwlock_t *); +int pthread_rwlock_unlock(pthread_rwlock_t *); +int pthread_rwlock_wrlock(pthread_rwlock_t *); +int pthread_rwlockattr_init(pthread_rwlockattr_t *); +int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, + int *); +int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); +int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); +pthread_t pthread_self(void); +int pthread_setspecific(pthread_key_t, const void *); +int pthread_sigmask(int, const sigset_t *, sigset_t *); + +int pthread_spin_init(pthread_spinlock_t *, int); +int pthread_spin_destroy(pthread_spinlock_t *); +int pthread_spin_lock(pthread_spinlock_t *); +int pthread_spin_trylock(pthread_spinlock_t *); +int pthread_spin_unlock(pthread_spinlock_t *); +int pthread_cancel(pthread_t); +int pthread_setcancelstate(int, int *); +int pthread_setcanceltype(int, int *); +void pthread_testcancel(void); + +int pthread_getprio(pthread_t); +int pthread_setprio(pthread_t, int); +void pthread_yield(void); + +int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *, + int *); +int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, + int); +int pthread_mutex_getprioceiling(pthread_mutex_t *, int *); +int pthread_mutex_setprioceiling(pthread_mutex_t *, int, int *); + +int pthread_mutexattr_getprotocol(pthread_mutexattr_t *, int *); +int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); + +int pthread_attr_getinheritsched(const pthread_attr_t *, int *); +int pthread_attr_getschedparam(const pthread_attr_t *, + struct sched_param *); +int pthread_attr_getschedpolicy(const pthread_attr_t *, int *); +int pthread_attr_getscope(const pthread_attr_t *, int *); +int pthread_attr_setinheritsched(pthread_attr_t *, int); +int pthread_attr_setschedparam(pthread_attr_t *, + const struct sched_param *); +int pthread_attr_setschedpolicy(pthread_attr_t *, int); +int pthread_attr_setscope(pthread_attr_t *, int); +int pthread_getschedparam(pthread_t pthread, int *, + struct sched_param *); +int pthread_setschedparam(pthread_t, int, + const struct sched_param *); +int pthread_getconcurrency(void); +int pthread_setconcurrency(int); +__END_DECLS + +#endif diff --git a/src/include/pthread_np.h b/src/include/pthread_np.h new file mode 100644 index 0000000..3c2a82c --- /dev/null +++ b/src/include/pthread_np.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 1996-98 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. + * + * $FreeBSD: src/include/pthread_np.h,v 1.15 2003/01/07 21:43:30 fjoe Exp $ + */ +#ifndef _PTHREAD_NP_H_ +#define _PTHREAD_NP_H_ + +/* + * Non-POSIX type definitions: + */ +typedef void (*pthread_switch_routine_t)(pthread_t, pthread_t); + +/* + * Non-POSIX thread function prototype definitions: + */ +__BEGIN_DECLS +int pthread_attr_setcreatesuspend_np(pthread_attr_t *); +int pthread_attr_get_np(pthread_t, pthread_attr_t *); +int pthread_main_np(void); +int pthread_multi_np(void); +int pthread_mutexattr_getkind_np(pthread_mutexattr_t); +int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int); +void pthread_resume_all_np(void); +int pthread_resume_np(pthread_t); +void pthread_set_name_np(pthread_t, const char *); +int pthread_single_np(void); +void pthread_suspend_all_np(void); +int pthread_suspend_np(pthread_t); +int pthread_switch_add_np(pthread_switch_routine_t); +int pthread_switch_delete_np(pthread_switch_routine_t); +__END_DECLS + +#endif diff --git a/src/include/pwd.h b/src/include/pwd.h new file mode 100644 index 0000000..f01d70d --- /dev/null +++ b/src/include/pwd.h @@ -0,0 +1,172 @@ +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)pwd.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/include/pwd.h,v 1.15 2003/04/18 14:11:17 nectar Exp $ + */ + +#ifndef _PWD_H_ +#define _PWD_H_ + +#include +#include + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#define _PATH_PWD "/etc" +#define _PATH_PASSWD "/etc/passwd" +#define _PASSWD "passwd" +#define _PATH_MASTERPASSWD "/etc/master.passwd" +#define _MASTERPASSWD "master.passwd" + +#define _PATH_MP_DB "/etc/pwd.db" +#define _MP_DB "pwd.db" +#define _PATH_SMP_DB "/etc/spwd.db" +#define _SMP_DB "spwd.db" + +#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb" + +/* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format + * `1 octet tag | key', where the tag is one of the _PW_KEY* values + * listed below. These values happen to be ASCII digits. Starting + * with FreeBSD 5.1, the tag is now still a single octet, but the + * upper 4 bits are interpreted as a version. Pre-FreeBSD 5.1 format + * entries are version `3' -- this conveniently results in the same + * key values as before. The new, architecture-independent entries + * are version `4'. + * As it happens, some applications read the database directly. + * (Bad app, no cookie!) Thus, we leave the _PW_KEY* symbols at their + * old pre-FreeBSD 5.1 values so these apps still work. Consequently + * we have to do muck around a bit more to get the correct, versioned + * tag, and that is what the _PW_VERSIONED macros is about. + */ + +#define _PW_VERSION_MASK '0xF0' +#define _PW_VERSIONED(x, v) ((unsigned char)(((x) & 0xCF) | ((v)<<4))) + +#define _PW_KEYBYNAME '\x31' /* stored by name */ +#define _PW_KEYBYNUM '\x32' /* stored by entry in the "file" */ +#define _PW_KEYBYUID '\x33' /* stored by uid */ +#define _PW_KEYYPENABLED '\x34' /* YP is enabled */ +#define _PW_KEYYPBYNUM '\x35' /* special +@netgroup entries */ + +/* The database also contains a key to indicate the format version of + * the entries therein. There may be other, older versioned entries + * as well. + */ +#define _PWD_VERSION_KEY "\xFF" "VERSION" +#define _PWD_CURRENT_VERSION '\x04' + +#define _PASSWORD_EFMT1 '_' /* extended encryption format */ + +#define _PASSWORD_LEN 128 /* max length, not counting NULL */ + +struct passwd { + char *pw_name; /* user name */ + char *pw_passwd; /* encrypted password */ + uid_t pw_uid; /* user uid */ + gid_t pw_gid; /* user gid */ + time_t pw_change; /* password change time */ + char *pw_class; /* user access class */ + char *pw_gecos; /* Honeywell login info */ + char *pw_dir; /* home directory */ + char *pw_shell; /* default shell */ + time_t pw_expire; /* account expiration */ + int pw_fields; /* internal: fields filled in */ +}; + +/* Mapping from fields to bits for pw_fields. */ +#define _PWF(x) (1 << x) +#define _PWF_NAME _PWF(0) +#define _PWF_PASSWD _PWF(1) +#define _PWF_UID _PWF(2) +#define _PWF_GID _PWF(3) +#define _PWF_CHANGE _PWF(4) +#define _PWF_CLASS _PWF(5) +#define _PWF_GECOS _PWF(6) +#define _PWF_DIR _PWF(7) +#define _PWF_SHELL _PWF(8) +#define _PWF_EXPIRE _PWF(9) + +/* XXX These flags are bogus. With nsswitch, there are many + * possible sources and they cannot be represented in a small integer. + */ +#define _PWF_SOURCE 0x3000 +#define _PWF_FILES 0x1000 +#define _PWF_NIS 0x2000 +#define _PWF_HESIOD 0x3000 + +__BEGIN_DECLS +struct passwd *getpwnam(const char *); +struct passwd *getpwuid(uid_t); + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 +void endpwent(void); +struct passwd *getpwent(void); +void setpwent(void); +int getpwnam_r(const char *, struct passwd *, char *, size_t, + struct passwd **); +int getpwuid_r(uid_t, struct passwd *, char *, size_t, + struct passwd **); +#endif + +#if __BSD_VISIBLE +int getpwent_r(struct passwd *, char *, size_t, struct passwd **); +int setpassent(int); +const char *user_from_uid(uid_t, int); +#endif +__END_DECLS + +#endif /* !_PWD_H_ */ diff --git a/src/include/quad.h b/src/include/quad.h new file mode 100644 index 0000000..4f65864 --- /dev/null +++ b/src/include/quad.h @@ -0,0 +1,4 @@ +#include + +quad_t __divdi3(quad_t a,quad_t b); +u_quad_t __udivdi3(u_quad_t a,u_quad_t b); diff --git a/src/include/radlib.h b/src/include/radlib.h new file mode 100644 index 0000000..e6cacc2 --- /dev/null +++ b/src/include/radlib.h @@ -0,0 +1,220 @@ +/*- + * Copyright 1998 Juniper Networks, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libradius/radlib.h,v 1.7 2004/04/27 15:00:29 ru Exp $ + */ + +#ifndef _RADLIB_H_ +#define _RADLIB_H_ + +#include +#include + +/* Limits */ +#define RAD_MAX_ATTR_LEN 253 + +/* Message types */ +#define RAD_ACCESS_REQUEST 1 +#define RAD_ACCESS_ACCEPT 2 +#define RAD_ACCESS_REJECT 3 +#define RAD_ACCOUNTING_REQUEST 4 +#define RAD_ACCOUNTING_RESPONSE 5 +#define RAD_ACCESS_CHALLENGE 11 + +/* Attribute types and values */ +#define RAD_USER_NAME 1 /* String */ +#define RAD_USER_PASSWORD 2 /* String */ +#define RAD_CHAP_PASSWORD 3 /* String */ +#define RAD_NAS_IP_ADDRESS 4 /* IP address */ +#define RAD_NAS_PORT 5 /* Integer */ +#define RAD_SERVICE_TYPE 6 /* Integer */ + #define RAD_LOGIN 1 + #define RAD_FRAMED 2 + #define RAD_CALLBACK_LOGIN 3 + #define RAD_CALLBACK_FRAMED 4 + #define RAD_OUTBOUND 5 + #define RAD_ADMINISTRATIVE 6 + #define RAD_NAS_PROMPT 7 + #define RAD_AUTHENTICATE_ONLY 8 + #define RAD_CALLBACK_NAS_PROMPT 9 +#define RAD_FRAMED_PROTOCOL 7 /* Integer */ + #define RAD_PPP 1 + #define RAD_SLIP 2 + #define RAD_ARAP 3 /* Appletalk */ + #define RAD_GANDALF 4 + #define RAD_XYLOGICS 5 +#define RAD_FRAMED_IP_ADDRESS 8 /* IP address */ +#define RAD_FRAMED_IP_NETMASK 9 /* IP address */ +#define RAD_FRAMED_ROUTING 10 /* Integer */ +#define RAD_FILTER_ID 11 /* String */ +#define RAD_FRAMED_MTU 12 /* Integer */ +#define RAD_FRAMED_COMPRESSION 13 /* Integer */ + #define RAD_COMP_NONE 0 + #define RAD_COMP_VJ 1 + #define RAD_COMP_IPXHDR 2 +#define RAD_LOGIN_IP_HOST 14 /* IP address */ +#define RAD_LOGIN_SERVICE 15 /* Integer */ +#define RAD_LOGIN_TCP_PORT 16 /* Integer */ + /* unassiged 17 */ +#define RAD_REPLY_MESSAGE 18 /* String */ +#define RAD_CALLBACK_NUMBER 19 /* String */ +#define RAD_CALLBACK_ID 20 /* String */ + /* unassiged 21 */ +#define RAD_FRAMED_ROUTE 22 /* String */ +#define RAD_FRAMED_IPX_NETWORK 23 /* IP address */ +#define RAD_STATE 24 /* String */ +#define RAD_CLASS 25 /* Integer */ +#define RAD_VENDOR_SPECIFIC 26 /* Integer */ +#define RAD_SESSION_TIMEOUT 27 /* Integer */ +#define RAD_IDLE_TIMEOUT 28 /* Integer */ +#define RAD_TERMINATION_ACTION 29 /* Integer */ +#define RAD_CALLED_STATION_ID 30 /* String */ +#define RAD_CALLING_STATION_ID 31 /* String */ +#define RAD_NAS_IDENTIFIER 32 /* Integer */ +#define RAD_PROXY_STATE 33 /* Integer */ +#define RAD_LOGIN_LAT_SERVICE 34 /* Integer */ +#define RAD_LOGIN_LAT_NODE 35 /* Integer */ +#define RAD_LOGIN_LAT_GROUP 36 /* Integer */ +#define RAD_FRAMED_APPLETALK_LINK 37 /* Integer */ +#define RAD_FRAMED_APPLETALK_NETWORK 38 /* Integer */ +#define RAD_FRAMED_APPLETALK_ZONE 39 /* Integer */ + /* reserved for accounting 40-59 */ +#define RAD_ACCT_INPUT_GIGAWORDS 52 +#define RAD_ACCT_OUTPUT_GIGAWORDS 53 + +#define RAD_CHAP_CHALLENGE 60 /* String */ +#define RAD_NAS_PORT_TYPE 61 /* Integer */ + #define RAD_ASYNC 0 + #define RAD_SYNC 1 + #define RAD_ISDN_SYNC 2 + #define RAD_ISDN_ASYNC_V120 3 + #define RAD_ISDN_ASYNC_V110 4 + #define RAD_VIRTUAL 5 + #define RAD_PIAFS 6 + #define RAD_HDLC_CLEAR_CHANNEL 7 + #define RAD_X_25 8 + #define RAD_X_75 9 + #define RAD_G_3_FAX 10 + #define RAD_SDSL 11 + #define RAD_ADSL_CAP 12 + #define RAD_ADSL_DMT 13 + #define RAD_IDSL 14 + #define RAD_ETHERNET 15 + #define RAD_XDSL 16 + #define RAD_CABLE 17 + #define RAD_WIRELESS_OTHER 18 + #define RAD_WIRELESS_IEEE_802_11 19 +#define RAD_PORT_LIMIT 62 /* Integer */ +#define RAD_LOGIN_LAT_PORT 63 /* Integer */ +#define RAD_CONNECT_INFO 77 /* String */ +#define RAD_EAP_MESSAGE 79 /* Octets */ +#define RAD_MESSAGE_AUTHENTIC 80 /* Octets */ +#define RAD_ACCT_INTERIM_INTERVAL 85 /* Integer */ +#define RAD_NAS_IPV6_ADDRESS 95 /* IPv6 address */ +#define RAD_FRAMED_INTERFACE_ID 96 /* 8 octets */ +#define RAD_FRAMED_IPV6_PREFIX 97 /* Octets */ +#define RAD_LOGIN_IPV6_HOST 98 /* IPv6 address */ +#define RAD_FRAMED_IPV6_ROUTE 99 /* String */ +#define RAD_FRAMED_IPV6_POOL 100 /* String */ + +/* Accounting attribute types and values */ +#define RAD_ACCT_STATUS_TYPE 40 /* Integer */ + #define RAD_START 1 + #define RAD_STOP 2 + #define RAD_UPDATE 3 + #define RAD_ACCOUNTING_ON 7 + #define RAD_ACCOUNTING_OFF 8 +#define RAD_ACCT_DELAY_TIME 41 /* Integer */ +#define RAD_ACCT_INPUT_OCTETS 42 /* Integer */ +#define RAD_ACCT_OUTPUT_OCTETS 43 /* Integer */ +#define RAD_ACCT_SESSION_ID 44 /* String */ +#define RAD_ACCT_AUTHENTIC 45 /* Integer */ + #define RAD_AUTH_RADIUS 1 + #define RAD_AUTH_LOCAL 2 + #define RAD_AUTH_REMOTE 3 +#define RAD_ACCT_SESSION_TIME 46 /* Integer */ +#define RAD_ACCT_INPUT_PACKETS 47 /* Integer */ +#define RAD_ACCT_OUTPUT_PACKETS 48 /* Integer */ +#define RAD_ACCT_TERMINATE_CAUSE 49 /* Integer */ + #define RAD_TERM_USER_REQUEST 1 + #define RAD_TERM_LOST_CARRIER 2 + #define RAD_TERM_LOST_SERVICE 3 + #define RAD_TERM_IDLE_TIMEOUT 4 + #define RAD_TERM_SESSION_TIMEOUT 5 + #define RAD_TERM_ADMIN_RESET 6 + #define RAD_TERM_ADMIN_REBOOT 7 + #define RAD_TERM_PORT_ERROR 8 + #define RAD_TERM_NAS_ERROR 9 + #define RAD_TERM_NAS_REQUEST 10 + #define RAD_TERM_NAS_REBOOT 11 + #define RAD_TERM_PORT_UNNEEDED 12 + #define RAD_TERM_PORT_PREEMPTED 13 + #define RAD_TERM_PORT_SUSPENDED 14 + #define RAD_TERM_SERVICE_UNAVAILABLE 15 + #define RAD_TERM_CALLBACK 16 + #define RAD_TERM_USER_ERROR 17 + #define RAD_TERM_HOST_REQUEST 18 +#define RAD_ACCT_MULTI_SESSION_ID 50 /* String */ +#define RAD_ACCT_LINK_COUNT 51 /* Integer */ + +struct rad_handle; +struct timeval; + +__BEGIN_DECLS +struct rad_handle *rad_acct_open(void); +int rad_add_server(struct rad_handle *, + const char *, int, const char *, int, int); +struct rad_handle *rad_auth_open(void); +void rad_close(struct rad_handle *); +int rad_config(struct rad_handle *, const char *); +int rad_continue_send_request(struct rad_handle *, int, + int *, struct timeval *); +int rad_create_request(struct rad_handle *, int); +struct in_addr rad_cvt_addr(const void *); +u_int32_t rad_cvt_int(const void *); +char *rad_cvt_string(const void *, size_t); +int rad_get_attr(struct rad_handle *, const void **, + size_t *); +int rad_init_send_request(struct rad_handle *, int *, + struct timeval *); +struct rad_handle *rad_open(void); /* Deprecated, == rad_auth_open */ +int rad_put_addr(struct rad_handle *, int, struct in_addr); +int rad_put_attr(struct rad_handle *, int, + const void *, size_t); +int rad_put_int(struct rad_handle *, int, u_int32_t); +int rad_put_string(struct rad_handle *, int, + const char *); +int rad_put_message_authentic(struct rad_handle *); +ssize_t rad_request_authenticator(struct rad_handle *, char *, + size_t); +int rad_send_request(struct rad_handle *); +const char *rad_server_secret(struct rad_handle *); +const char *rad_strerror(struct rad_handle *); +u_char *rad_demangle(struct rad_handle *, const void *, + size_t); + +__END_DECLS + +#endif /* _RADLIB_H_ */ diff --git a/src/include/radlib_vs.h b/src/include/radlib_vs.h new file mode 100644 index 0000000..c9ab743 --- /dev/null +++ b/src/include/radlib_vs.h @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2002 Brian Somers + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libradius/radlib_vs.h,v 1.3 2004/04/27 15:00:29 ru Exp $ + */ + +#ifndef _RADLIB_VS_H_ +#define _RADLIB_VS_H_ + +#include +#include + +#define RAD_VENDOR_MICROSOFT 311 /* rfc2548 */ + #define RAD_MICROSOFT_MS_CHAP_RESPONSE 1 + #define RAD_MICROSOFT_MS_CHAP_ERROR 2 + #define RAD_MICROSOFT_MS_CHAP_PW_1 3 + #define RAD_MICROSOFT_MS_CHAP_PW_2 4 + #define RAD_MICROSOFT_MS_CHAP_LM_ENC_PW 5 + #define RAD_MICROSOFT_MS_CHAP_NT_ENC_PW 6 + #define RAD_MICROSOFT_MS_MPPE_ENCRYPTION_POLICY 7 + #define RAD_MICROSOFT_MS_MPPE_ENCRYPTION_TYPES 8 + #define RAD_MICROSOFT_MS_RAS_VENDOR 9 + #define RAD_MICROSOFT_MS_CHAP_DOMAIN 10 + #define RAD_MICROSOFT_MS_CHAP_CHALLENGE 11 + #define RAD_MICROSOFT_MS_CHAP_MPPE_KEYS 12 + #define RAD_MICROSOFT_MS_BAP_USAGE 13 + #define RAD_MICROSOFT_MS_LINK_UTILIZATION_THRESHOLD 14 + #define RAD_MICROSOFT_MS_LINK_DROP_TIME_LIMIT 15 + #define RAD_MICROSOFT_MS_MPPE_SEND_KEY 16 + #define RAD_MICROSOFT_MS_MPPE_RECV_KEY 17 + #define RAD_MICROSOFT_MS_RAS_VERSION 18 + #define RAD_MICROSOFT_MS_OLD_ARAP_PASSWORD 19 + #define RAD_MICROSOFT_MS_NEW_ARAP_PASSWORD 20 + #define RAD_MICROSOFT_MS_ARAP_PASSWORD_CHANGE_REASON 21 + #define RAD_MICROSOFT_MS_FILTER 22 + #define RAD_MICROSOFT_MS_ACCT_AUTH_TYPE 23 + #define RAD_MICROSOFT_MS_ACCT_EAP_TYPE 24 + #define RAD_MICROSOFT_MS_CHAP2_RESPONSE 25 + #define RAD_MICROSOFT_MS_CHAP2_SUCCESS 26 + #define RAD_MICROSOFT_MS_CHAP2_PW 27 + #define RAD_MICROSOFT_MS_PRIMARY_DNS_SERVER 28 + #define RAD_MICROSOFT_MS_SECONDARY_DNS_SERVER 29 + #define RAD_MICROSOFT_MS_PRIMARY_NBNS_SERVER 30 + #define RAD_MICROSOFT_MS_SECONDARY_NBNS_SERVER 31 + #define RAD_MICROSOFT_MS_ARAP_CHALLENGE 33 + +#define SALT_LEN 2 + +struct rad_handle; + +__BEGIN_DECLS +int rad_get_vendor_attr(u_int32_t *, const void **, size_t *); +int rad_put_vendor_addr(struct rad_handle *, int, int, struct in_addr); +int rad_put_vendor_attr(struct rad_handle *, int, int, const void *, + size_t); +int rad_put_vendor_int(struct rad_handle *, int, int, u_int32_t); +int rad_put_vendor_string(struct rad_handle *, int, int, const char *); +u_char *rad_demangle_mppe_key(struct rad_handle *, const void *, size_t, + size_t *); +__END_DECLS + +#endif /* _RADLIB_VS_H_ */ diff --git a/src/include/ranlib.h b/src/include/ranlib.h new file mode 100644 index 0000000..c842919 --- /dev/null +++ b/src/include/ranlib.h @@ -0,0 +1,50 @@ +/*- + * 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. + * + * @(#)ranlib.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _RANLIB_H_ +#define _RANLIB_H_ + +#define RANLIBMAG "__.SYMDEF" /* archive file name */ +#define RANLIBSKEW 3 /* creation time offset */ + +struct ranlib { + union { + long ran_strx; /* string table index */ + char *ran_name; /* in memory symbol name */ + } ran_un; + long ran_off; /* archive file offset */ +}; + +#endif /* !_RANLIB_H_ */ diff --git a/src/include/readpassphrase.h b/src/include/readpassphrase.h new file mode 100644 index 0000000..ce28f2a --- /dev/null +++ b/src/include/readpassphrase.h @@ -0,0 +1,47 @@ +/* $OpenBSD: /usr/local/www/cvsroot/OpenBSD/src/include/readpassphrase.h,v 1.2 2002/02/16 21:27:17 millert Exp $ */ +/* $FreeBSD: src/include/readpassphrase.h,v 1.2 2002/03/08 20:52:52 green Exp $ */ + +/* + * Copyright (c) 2000 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. + */ + +#ifndef _READPASSPHRASE_H_ +#define _READPASSPHRASE_H_ + +#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */ +#define RPP_ECHO_ON 0x01 /* Leave echo on. */ +#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */ +#define RPP_FORCELOWER 0x04 /* Force input to lower case. */ +#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ +#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ + +#include + +__BEGIN_DECLS +char * readpassphrase(const char *, char *, size_t, int); +__END_DECLS + +#endif /* !_READPASSPHRASE_H_ */ diff --git a/src/include/regex.h b/src/include/regex.h new file mode 100644 index 0000000..a58db6f --- /dev/null +++ b/src/include/regex.h @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 1992 Henry Spencer. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Henry Spencer of the University of Toronto. + * + * 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. + * + * @(#)regex.h 8.2 (Berkeley) 1/3/94 + * $FreeBSD: src/include/regex.h,v 1.10 2003/12/18 10:41:39 jkh Exp $ + */ + +#ifndef _REGEX_H_ +#define _REGEX_H_ + +#include +#include + +/* types */ +typedef __off_t regoff_t; + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +typedef struct { + int re_magic; + size_t re_nsub; /* number of parenthesized subexpressions */ + __const char *re_endp; /* end pointer for REG_PEND */ + struct re_guts *re_g; /* none of your business :-) */ +} regex_t; + +typedef struct { + regoff_t rm_so; /* start of match */ + regoff_t rm_eo; /* end of match */ +} regmatch_t; + +/* regcomp() flags */ +#define REG_BASIC 0000 +#define REG_EXTENDED 0001 +#define REG_ICASE 0002 +#define REG_NOSUB 0004 +#define REG_NEWLINE 0010 +#define REG_NOSPEC 0020 +#define REG_PEND 0040 +#define REG_DUMP 0200 + +/* regerror() flags */ +#define REG_ENOSYS (-1) +#define REG_NOMATCH 1 +#define REG_BADPAT 2 +#define REG_ECOLLATE 3 +#define REG_ECTYPE 4 +#define REG_EESCAPE 5 +#define REG_ESUBREG 6 +#define REG_EBRACK 7 +#define REG_EPAREN 8 +#define REG_EBRACE 9 +#define REG_BADBR 10 +#define REG_ERANGE 11 +#define REG_ESPACE 12 +#define REG_BADRPT 13 +#define REG_EMPTY 14 +#define REG_ASSERT 15 +#define REG_INVARG 16 +#define REG_ATOI 255 /* convert name to number (!) */ +#define REG_ITOA 0400 /* convert number to name (!) */ + +/* regexec() flags */ +#define REG_NOTBOL 00001 +#define REG_NOTEOL 00002 +#define REG_STARTEND 00004 +#define REG_TRACE 00400 /* tracing of execution */ +#define REG_LARGE 01000 /* force large representation */ +#define REG_BACKR 02000 /* force use of backref code */ + +__BEGIN_DECLS +int regcomp(regex_t * __restrict, const char * __restrict, int); +size_t regerror(int, const regex_t * __restrict, char * __restrict, size_t); +/* + * XXX forth parameter should be `regmatch_t [__restrict]', but isn't because + * of a bug in GCC 3.2 (when -std=c99 is specified) which perceives this as a + * syntax error. + */ +int regexec(const regex_t * __restrict, const char * __restrict, size_t, + regmatch_t * __restrict, int); +void regfree(regex_t *); +__END_DECLS + +#endif /* !_REGEX_H_ */ diff --git a/src/include/regexp.h b/src/include/regexp.h new file mode 100644 index 0000000..5333015 --- /dev/null +++ b/src/include/regexp.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1986 by University of Toronto. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley + * by Henry Spencer. + * + * 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. + * + * @(#)regexp.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/regexp.h,v 1.2 2002/03/23 17:24:53 imp Exp $ + */ + +#ifndef _REGEXP_H_ +#define _REGEXP_H_ + +/* + * Definitions etc. for regexp(3) routines. + * + * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], + * not the System V one. + */ +#define NSUBEXP 10 +typedef struct regexp { + char *startp[NSUBEXP]; + char *endp[NSUBEXP]; + char regstart; /* Internal use only. */ + char reganch; /* Internal use only. */ + char *regmust; /* Internal use only. */ + int regmlen; /* Internal use only. */ + char program[1]; /* Unwarranted chumminess with compiler. */ +} regexp; + +#include + +__BEGIN_DECLS +regexp *regcomp(const char *); +int regexec(const regexp *, const char *); +void regsub(const regexp *, const char *, char *); +void regerror(const char *); +__END_DECLS + +#endif /* !_REGEXP_H_ */ diff --git a/src/include/resolv.h b/src/include/resolv.h new file mode 100644 index 0000000..cceddc1 --- /dev/null +++ b/src/include/resolv.h @@ -0,0 +1,331 @@ +/*- + * Copyright (c) 1983, 1987, 1989, 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. + */ + +/* + * Portions Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * @(#)resolv.h 8.1 (Berkeley) 6/2/93 + * From Id: resolv.h,v 8.12 1998/04/28 19:36:46 halley Exp $ + * $FreeBSD: src/include/resolv.h,v 1.25 2004/03/15 17:08:28 des Exp $ + */ + +#ifndef _RESOLV_H_ +#define _RESOLV_H_ + +#include +#include +#include +#include +#include + +/* + * Revision information. This is the release date in YYYYMMDD format. + * It can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__RES > 19931104)". Do not + * compare for equality; rather, use it to determine whether your resolver + * is new enough to contain a certain feature. + */ + +#define __RES 19960801 + +/* + * Resolver configuration file. + * Normally not present, but may contain the address of the + * inital name server(s) to query and the domain search list. + */ + +#ifndef _PATH_RESCONF +#define _PATH_RESCONF "/etc/resolv.conf" +#endif + +/* + * Global defines and variables for resolver stub. + */ +#define MAXNS 3 /* max # name servers we'll track */ +#define MAXDFLSRCH 3 /* # default domain levels to try */ +#define MAXDNSRCH 6 /* max # domains in search path */ +#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */ + +#define RES_TIMEOUT 5 /* min. seconds between retries */ +#define MAXRESOLVSORT 10 /* number of net to sort on */ +#define RES_MAXNDOTS 15 /* should reflect bit field size */ +#define RES_MAXRETRANS 30 /* only for resolv.conf/RES_OPTIONS */ +#define RES_MAXRETRY 5 /* only for resolv.conf/RES_OPTIONS */ + +struct __res_state { + int retrans; /* retransmition time interval */ + int retry; /* number of times to retransmit */ + u_long options; /* option flags - see below. */ + int nscount; /* number of name servers */ + struct sockaddr_in + nsaddr_list[MAXNS]; /* address of name server */ +#define nsaddr nsaddr_list[0] /* for backward compatibility */ + u_short id; /* current message id */ + char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ + char defdname[256]; /* default domain (deprecated) */ + u_long pfcode; /* RES_PRF_ flags - see below. */ + unsigned ndots:4; /* threshold for initial abs. query */ + unsigned nsort:4; /* number of elements in sort_list[] */ + char unused[3]; + struct { + struct in_addr addr; + u_int32_t mask; + } sort_list[MAXRESOLVSORT]; + char pad[72]; /* on an i386 this means 512b total */ +}; + +/* for INET6 */ +/* + * replacement of __res_state, separated to keep binary compatibility. + */ +struct __res_state_ext { + struct sockaddr_storage nsaddr_list[MAXNS]; + struct { + int af; /* address family for addr, mask */ + union { + struct in_addr ina; + struct in6_addr in6a; + } addr, mask; + } sort_list[MAXRESOLVSORT]; +}; + +/* + * Resolver options (keep these in synch with res_debug.c, please) + */ +#define RES_INIT 0x00000001 /* address initialized */ +#define RES_DEBUG 0x00000002 /* print debug messages */ +#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/ +#define RES_USEVC 0x00000008 /* use virtual circuit */ +#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */ +#define RES_IGNTC 0x00000020 /* ignore truncation errors */ +#define RES_RECURSE 0x00000040 /* recursion desired */ +#define RES_DEFNAMES 0x00000080 /* use default domain name */ +#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */ +#define RES_DNSRCH 0x00000200 /* search up local domain tree */ +#define RES_INSECURE1 0x00000400 /* type 1 security disabled */ +#define RES_INSECURE2 0x00000800 /* type 2 security disabled */ +#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */ +#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */ +#define RES_NOTLDQUERY 0x00004000 /* Don't query TLD names */ +/* KAME extensions: use higher bit to avoid conflict with ISC use */ +#define RES_USE_EDNS0 0x40000000 /* use EDNS0 */ + +#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH) + +/* + * Resolver "pfcode" values. Used by dig. + */ +#define RES_PRF_STATS 0x00000001 +#define RES_PRF_UPDATE 0x00000002 +#define RES_PRF_CLASS 0x00000004 +#define RES_PRF_CMD 0x00000008 +#define RES_PRF_QUES 0x00000010 +#define RES_PRF_ANS 0x00000020 +#define RES_PRF_AUTH 0x00000040 +#define RES_PRF_ADD 0x00000080 +#define RES_PRF_HEAD1 0x00000100 +#define RES_PRF_HEAD2 0x00000200 +#define RES_PRF_TTLID 0x00000400 +#define RES_PRF_HEADX 0x00000800 +#define RES_PRF_QUERY 0x00001000 +#define RES_PRF_REPLY 0x00002000 +#define RES_PRF_INIT 0x00004000 +/* 0x00008000 */ + +typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error } + res_sendhookact; + +typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *ns, + const u_char **query, + int *querylen, + u_char *ans, + int anssiz, + int *resplen); + +typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *ns, + const u_char *query, + int querylen, + u_char *ans, + int anssiz, + int *resplen); + +struct res_sym { + int number; /* Identifying number, like T_MX */ + char * name; /* Its symbolic name, like "MX" */ + char * humanname; /* Its fun name, like "mail exchanger" */ +}; + +__BEGIN_DECLS +extern struct __res_state *___res(void); +extern struct __res_state_ext *___res_ext(void); +__END_DECLS +#define _res (*___res()) +#define _res_ext (*___res_ext()) +/* for INET6 */ +extern struct __res_state_ext _res_ext; + +extern const struct res_sym __p_class_syms[]; +extern const struct res_sym __p_type_syms[]; + +/* Private routines shared between libc/net, named, nslookup and others. */ +#define res_hnok __res_hnok +#define res_ownok __res_ownok +#define res_mailok __res_mailok +#define res_dnok __res_dnok +#define sym_ston __sym_ston +#define sym_ntos __sym_ntos +#define sym_ntop __sym_ntop +#define b64_ntop __b64_ntop +#define b64_pton __b64_pton +#define loc_ntoa __loc_ntoa +#define loc_aton __loc_aton +#define fp_resstat __fp_resstat +#define p_query __p_query +#define dn_skipname __dn_skipname +#define fp_resstat __fp_resstat +#define fp_query __fp_query +#define fp_nquery __fp_nquery +#define hostalias __hostalias +#define putlong __putlong +#define putshort __putshort +#define p_class __p_class +#define p_time __p_time +#define p_type __p_type +#define p_query __p_query +#define p_cdnname __p_cdnname +#define p_section __p_section +#define p_cdname __p_cdname +#define p_fqnname __p_fqnname +#define p_fqname __p_fqname +#define p_option __p_option +#define p_secstodate __p_secstodate +#define dn_count_labels __dn_count_labels +#define dn_comp __dn_comp +#define dn_expand __dn_expand +#define res_init __res_init +#define res_randomid __res_randomid +#define res_query __res_query +#define res_search __res_search +#define res_querydomain __res_querydomain +#define res_mkquery __res_mkquery +#define res_send __res_send +#define res_isourserver __res_isourserver +#define res_nameinquery __res_nameinquery +#define res_queriesmatch __res_queriesmatch +#define res_close __res_close +#define res_opt __res_opt +#define res_mkupdate __res_mkupdate +#define res_mkupdrec __res_mkupdrec +#define res_freeupdrec __res_freeupdrec + +__BEGIN_DECLS +int res_hnok(const char *); +int res_ownok(const char *); +int res_mailok(const char *); +int res_dnok(const char *); +int sym_ston(const struct res_sym *, const char *, int *); +const char * sym_ntos(const struct res_sym *, int, int *); +const char * sym_ntop(const struct res_sym *, int, int *); +int b64_ntop(u_char const *, size_t, char *, size_t); +int b64_pton(char const *, u_char *, size_t); +int loc_aton(const char *, u_char *); +const char * loc_ntoa(const u_char *, char *); +int dn_skipname(const u_char *, const u_char *); +void fp_resstat(struct __res_state *, FILE *); +void fp_query(const u_char *, FILE *); +void fp_nquery(const u_char *, int, FILE *); +const char * hostalias(const char *); +void putlong(u_int32_t, u_char *); +void putshort(u_int16_t, u_char *); +const char * p_class(int); +const char * p_time(u_int32_t); +const char * p_type(int); +void p_query(const u_char *); +const u_char * p_cdnname(const u_char *, const u_char *, int, FILE *); +const u_char * p_cdname(const u_char *, const u_char *, FILE *); +const u_char * p_fqnname(const u_char *, const u_char *, + int, char *, int); +const u_char * p_fqname(const u_char *, const u_char *, FILE *); +const char * p_option(u_long); +char * p_secstodate(u_long); +int dn_count_labels(const char *); +int dn_comp(const char *, u_char *, int, u_char **, u_char **); +int dn_expand(const u_char *, const u_char *, const u_char *, + char *, int); +int res_init(void); +u_int res_randomid(void); +int res_query(const char *, int, int, u_char *, int); +int res_search(const char *, int, int, u_char *, int); +int res_querydomain(const char *, const char *, int, int, + u_char *, int); +int res_mkquery(int, const char *, int, int, const u_char *, + int, const u_char *, u_char *, int); +int res_send(const u_char *, int, u_char *, int); +int res_isourserver(const struct sockaddr_in *); +int res_nameinquery(const char *, int, int, + const u_char *, const u_char *); +int res_queriesmatch(const u_char *, const u_char *, + const u_char *, const u_char *); +void res_close(void); +int res_opt(int, u_char *, int, int); +const char * p_section(int, int); +/* XXX These must be exported for BIND4 compatibility. */ +void __putlong(u_int32_t, u_char *); +void __putshort(u_int16_t, u_char *); +u_int32_t _getlong(const u_char *); +u_int16_t _getshort(const u_char *); +/* XXX The following depend on the ns_updrec typedef in arpa/nameser.h */ +#ifdef _ARPA_NAMESER_H_ +int res_update(ns_updrec *); +int res_mkupdate(ns_updrec *, u_char *, int); +ns_updrec * res_mkupdrec(int, const char *, u_int, u_int, u_long); +void res_freeupdrec(ns_updrec *); +#endif +__END_DECLS + +#endif /* !_RESOLV_H_ */ diff --git a/src/include/ripemd.h b/src/include/ripemd.h new file mode 100644 index 0000000..ca13e62 --- /dev/null +++ b/src/include/ripemd.h @@ -0,0 +1,94 @@ +/* crypto/ripemd/ripemd.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * 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 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 cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 AUTHOR 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. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* + * $FreeBSD: src/lib/libmd/ripemd.h,v 1.2 2001/03/17 10:00:50 phk Exp $ + */ + +#ifndef HEADER_RIPEMD_H +#define HEADER_RIPEMD_H + +#include +#include /* XXX switch to machine/ansi.h and __ types */ + +#define RIPEMD160_CBLOCK 64 +#define RIPEMD160_LBLOCK 16 +#define RIPEMD160_BLOCK 16 +#define RIPEMD160_LAST_BLOCK 56 +#define RIPEMD160_LENGTH_BLOCK 8 +#define RIPEMD160_DIGEST_LENGTH 20 + +typedef struct RIPEMD160state_st { + u_int32_t A,B,C,D,E; + u_int32_t Nl,Nh; + u_int32_t data[RIPEMD160_LBLOCK]; + int num; +} RIPEMD160_CTX; + +__BEGIN_DECLS +void RIPEMD160_Init(RIPEMD160_CTX *c); +void RIPEMD160_Update(RIPEMD160_CTX *c, const unsigned char *data, + size_t len); +void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); +char *RIPEMD160_End(RIPEMD160_CTX *, char *); +char *RIPEMD160_File(const char *, char *); +char *RIPEMD160_FileChunk(const char *, char *, off_t, off_t); +char *RIPEMD160_Data(const unsigned char *, unsigned int, char *); +__END_DECLS + +#endif diff --git a/src/include/roken-common.h b/src/include/roken-common.h new file mode 100644 index 0000000..f1e5ed8 --- /dev/null +++ b/src/include/roken-common.h @@ -0,0 +1,338 @@ +/* + * Copyright (c) 1995 - 2002 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $Id$ */ + +#ifndef __ROKEN_COMMON_H__ +#define __ROKEN_COMMON_H__ + +#ifdef __cplusplus +#define ROKEN_CPP_START extern "C" { +#define ROKEN_CPP_END } +#else +#define ROKEN_CPP_START +#define ROKEN_CPP_END +#endif + +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + +#ifndef INADDR_LOOPBACK +#define INADDR_LOOPBACK 0x7f000001 +#endif + +#ifndef SOMAXCONN +#define SOMAXCONN 5 +#endif + +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif + +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif + +#ifndef max +#define max(a,b) (((a)>(b))?(a):(b)) +#endif + +#ifndef min +#define min(a,b) (((a)<(b))?(a):(b)) +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef LOG_DAEMON +#define openlog(id,option,facility) openlog((id),(option)) +#define LOG_DAEMON 0 +#endif +#ifndef LOG_ODELAY +#define LOG_ODELAY 0 +#endif +#ifndef LOG_NDELAY +#define LOG_NDELAY 0x08 +#endif +#ifndef LOG_CONS +#define LOG_CONS 0 +#endif +#ifndef LOG_AUTH +#define LOG_AUTH 0 +#endif +#ifndef LOG_AUTHPRIV +#define LOG_AUTHPRIV LOG_AUTH +#endif + +#ifndef F_OK +#define F_OK 0 +#endif + +#ifndef O_ACCMODE +#define O_ACCMODE 003 +#endif + +#ifndef _PATH_DEV +#define _PATH_DEV "/dev/" +#endif + +#ifndef _PATH_DEVNULL +#define _PATH_DEVNULL "/dev/null" +#endif + +#ifndef _PATH_HEQUIV +#define _PATH_HEQUIV "/etc/hosts.equiv" +#endif + +#ifndef _PATH_VARRUN +#define _PATH_VARRUN "/var/run/" +#endif + +#ifndef _PATH_BSHELL +#define _PATH_BSHELL "/bin/sh" +#endif + +#ifndef MAXPATHLEN +#define MAXPATHLEN (1024+4) +#endif + +#ifndef SIG_ERR +#define SIG_ERR ((RETSIGTYPE (*)(int))-1) +#endif + +/* + * error code for getipnodeby{name,addr} + */ + +#ifndef HOST_NOT_FOUND +#define HOST_NOT_FOUND 1 +#endif + +#ifndef TRY_AGAIN +#define TRY_AGAIN 2 +#endif + +#ifndef NO_RECOVERY +#define NO_RECOVERY 3 +#endif + +#ifndef NO_DATA +#define NO_DATA 4 +#endif + +#ifndef NO_ADDRESS +#define NO_ADDRESS NO_DATA +#endif + +/* + * error code for getaddrinfo + */ + +#ifndef EAI_NOERROR +#define EAI_NOERROR 0 /* no error */ +#endif + +#ifndef EAI_NONAME + +#define EAI_ADDRFAMILY 1 /* address family for nodename not supported */ +#define EAI_AGAIN 2 /* temporary failure in name resolution */ +#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* ai_family not supported */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#define EAI_NODATA 7 /* no address associated with nodename */ +#define EAI_NONAME 8 /* nodename nor servname provided, or not known */ +#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ +#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ +#define EAI_SYSTEM 11 /* system error returned in errno */ + +#endif /* EAI_NONAME */ + +/* flags for getaddrinfo() */ + +#ifndef AI_PASSIVE +#define AI_PASSIVE 0x01 +#define AI_CANONNAME 0x02 +#endif /* AI_PASSIVE */ + +#ifndef AI_NUMERICHOST +#define AI_NUMERICHOST 0x04 +#endif + +/* flags for getnameinfo() */ + +#ifndef NI_DGRAM +#define NI_DGRAM 0x01 +#define NI_NAMEREQD 0x02 +#define NI_NOFQDN 0x04 +#define NI_NUMERICHOST 0x08 +#define NI_NUMERICSERV 0x10 +#endif + +/* + * constants for getnameinfo + */ + +#ifndef NI_MAXHOST +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 +#endif + +/* + * constants for inet_ntop + */ + +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 16 +#endif + +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN 46 +#endif + +/* + * for shutdown(2) + */ + +#ifndef SHUT_RD +#define SHUT_RD 0 +#endif + +#ifndef SHUT_WR +#define SHUT_WR 1 +#endif + +#ifndef SHUT_RDWR +#define SHUT_RDWR 2 +#endif + +#ifndef HAVE___ATTRIBUTE__ +#define __attribute__(x) +#endif + +ROKEN_CPP_START + +#ifndef IRIX4 /* fix for compiler bug */ +#ifdef RETSIGTYPE +typedef RETSIGTYPE (*SigAction)(int); +SigAction signal(int iSig, SigAction pAction); /* BSD compatible */ +#endif +#endif + +int ROKEN_LIB_FUNCTION simple_execve(const char*, char*const[], char*const[]); +int ROKEN_LIB_FUNCTION simple_execvp(const char*, char *const[]); +int ROKEN_LIB_FUNCTION simple_execlp(const char*, ...); +int ROKEN_LIB_FUNCTION simple_execle(const char*, ...); +int ROKEN_LIB_FUNCTION simple_execl(const char *file, ...); + +int ROKEN_LIB_FUNCTION wait_for_process(pid_t); +int ROKEN_LIB_FUNCTION pipe_execv(FILE**, FILE**, FILE**, const char*, ...); + +void ROKEN_LIB_FUNCTION print_version(const char *); + +ssize_t ROKEN_LIB_FUNCTION eread (int fd, void *buf, size_t nbytes); +ssize_t ROKEN_LIB_FUNCTION ewrite (int fd, const void *buf, size_t nbytes); + +struct hostent; + +const char * +hostent_find_fqdn (const struct hostent *he); + +void +esetenv(const char *var, const char *val, int rewrite); + +void +socket_set_address_and_port (struct sockaddr *sa, const void *ptr, int port); + +size_t +socket_addr_size (const struct sockaddr *sa); + +void +socket_set_any (struct sockaddr *sa, int af); + +size_t +socket_sockaddr_size (const struct sockaddr *sa); + +void * +socket_get_address (struct sockaddr *sa); + +int +socket_get_port (const struct sockaddr *sa); + +void +socket_set_port (struct sockaddr *sa, int port); + +void +socket_set_portrange (int sock, int restr, int af); + +void +socket_set_debug (int sock); + +void +socket_set_tos (int sock, int tos); + +void +socket_set_reuseaddr (int sock, int val); + +char ** +vstrcollect(va_list *ap); + +char ** +strcollect(char *first, ...); + +void timevalfix(struct timeval *t1); +void timevaladd(struct timeval *t1, const struct timeval *t2); +void timevalsub(struct timeval *t1, const struct timeval *t2); + +char *pid_file_write (const char *progname); +void pid_file_delete (char **); + +int +read_environment(const char *file, char ***env); + +void warnerr(int doerrno, const char *fmt, va_list ap) + __attribute__ ((format (printf, 2, 0))); + +ROKEN_CPP_END + +#endif /* __ROKEN_COMMON_H__ */ diff --git a/src/include/roken.h b/src/include/roken.h new file mode 100644 index 0000000..41c41ad --- /dev/null +++ b/src/include/roken.h @@ -0,0 +1,244 @@ +/* This is an OS dependent, generated file */ + + +#ifndef __ROKEN_H__ +#define __ROKEN_H__ + +/* -*- C -*- */ +/* + * Copyright (c) 1995 - 2002 Kungliga Tekniska H�gskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $Id$ */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#define ROKEN_LIB_FUNCTION + + +#include + +ROKEN_CPP_START + + + + + + + + + + +int asnprintf (char **ret, size_t max_sz, const char *format, ...) + __attribute__ ((format (printf, 3, 4))); + +int vasnprintf (char **ret, size_t max_sz, const char *format, va_list ap) + __attribute__((format (printf, 3, 0))); + + +char * strndup(const char *old, size_t sz); + +char * strlwr(char *); + +size_t strnlen(const char*, size_t); + + +ssize_t strsep_copy(const char**, const char*, char*, size_t); + + + + +char * strupr(char *); + + + + + + + + + + + +#include +struct passwd *k_getpwnam (const char *user); +struct passwd *k_getpwuid (uid_t uid); + +const char *get_default_username (void); + + + + + + + + + + + + + + + + + + +void pidfile (const char*); + +unsigned int bswap32(unsigned int); + +unsigned short bswap16(unsigned short); + + +time_t tm2time (struct tm tm, int local); + +int unix_verify_user(char *user, char *password); + +int roken_concat (char *s, size_t len, ...); + +size_t roken_mconcat (char **s, size_t max_len, ...); + +int roken_vconcat (char *s, size_t len, va_list args); + +size_t roken_vmconcat (char **s, size_t max_len, va_list args); + +ssize_t net_write (int fd, const void *buf, size_t nbytes); + +ssize_t net_read (int fd, void *buf, size_t nbytes); + +int issuid(void); + + +int get_window_size(int fd, struct winsize *); + + + +extern const char *__progname; + +extern char **environ; + + + + +struct hostent * +copyhostent (const struct hostent *h); + + + + + + + + +int +getnameinfo_verified(const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, + char *serv, size_t servlen, + int flags); + +int roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **); +int roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **); + + + +void *emalloc (size_t); +void *ecalloc(size_t num, size_t sz); +void *erealloc (void *, size_t); +char *estrdup (const char *); + +/* + * kludges and such + */ + +int roken_gethostby_setup(const char*, const char*); +struct hostent* roken_gethostbyname(const char*); +struct hostent* roken_gethostbyaddr(const void*, size_t, int); + +#define roken_getservbyname(x,y) getservbyname(x,y) + +#define roken_openlog(a,b,c) openlog(a,b,c) + +#define roken_getsockname(a,b,c) getsockname(a,b,c) + + + +void mini_inetd_addrinfo (struct addrinfo*); +void mini_inetd (int port); + +void set_progname(char *argv0); +const char *get_progname(void); + + +int +strsvis(char *dst, const char *src, int flag, const char *extra); + + + + +char * +svis(char *dst, int c, int flag, int nextc, const char *extra); + + + +ROKEN_CPP_END +#define ROKEN_VERSION 0.6.1 + +#endif /* __ROKEN_H__ */ diff --git a/src/include/rune.h b/src/include/rune.h new file mode 100644 index 0000000..b1e6115 --- /dev/null +++ b/src/include/rune.h @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + * + * @(#)rune.h 8.1 (Berkeley) 6/27/93 + * $FreeBSD: src/include/rune.h,v 1.4 2003/06/25 22:28:33 phantom Exp $ + */ + +#ifndef _RUNE_H_ +#define _RUNE_H_ + +#include +#include + +#ifndef _RUNE_T_DECLARED +#define _RUNE_T_DECLARED +typedef __rune_t rune_t; +#endif + +#define _INVALID_RUNE _CurrentRuneLocale->invalid_rune + +#define __sgetrune _CurrentRuneLocale->sgetrune +#define __sputrune _CurrentRuneLocale->sputrune + +#define sgetrune(s, n, r) (*__sgetrune)((s), (n), (r)) +#define sputrune(c, s, n, r) (*__sputrune)((c), (s), (n), (r)) + +__BEGIN_DECLS +char *mbrune(const char *, rune_t); +char *mbrrune(const char *, rune_t); +char *mbmb(const char *, char *); +long fgetrune(FILE *); +int fputrune(rune_t, FILE *); +int fungetrune(rune_t, FILE *); +int setrunelocale(char *); +void setinvalidrune(rune_t); +__END_DECLS + +#endif /*! _RUNE_H_ */ diff --git a/src/include/runetype.h b/src/include/runetype.h new file mode 100644 index 0000000..d7001f0 --- /dev/null +++ b/src/include/runetype.h @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + * + * @(#)runetype.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/runetype.h,v 1.8 2002/09/06 04:22:54 mike Exp $ + */ + +#ifndef _RUNETYPE_H_ +#define _RUNETYPE_H_ + +#include +#include + +#define _CACHED_RUNES (1 <<8 ) /* Must be a power of 2 */ +#define _CRMASK (~(_CACHED_RUNES - 1)) + +/* + * The lower 8 bits of runetype[] contain the digit value of the rune. + */ +typedef struct { + __rune_t min; /* First rune of the range */ + __rune_t max; /* Last rune (inclusive) of the range */ + __rune_t map; /* What first maps to in maps */ + unsigned long *types; /* Array of types in range */ +} _RuneEntry; + +typedef struct { + int nranges; /* Number of ranges stored */ + _RuneEntry *ranges; /* Pointer to the ranges */ +} _RuneRange; + +typedef struct { + char magic[8]; /* Magic saying what version we are */ + char encoding[32]; /* ASCII name of this encoding */ + + __rune_t (*sgetrune)(const char *, __size_t, char const **); + int (*sputrune)(__rune_t, char *, __size_t, char **); + __rune_t invalid_rune; + + unsigned long runetype[_CACHED_RUNES]; + __rune_t maplower[_CACHED_RUNES]; + __rune_t mapupper[_CACHED_RUNES]; + + /* + * The following are to deal with Runes larger than _CACHED_RUNES - 1. + * Their data is actually contiguous with this structure so as to make + * it easier to read/write from/to disk. + */ + _RuneRange runetype_ext; + _RuneRange maplower_ext; + _RuneRange mapupper_ext; + + void *variable; /* Data which depends on the encoding */ + int variable_len; /* how long that data is */ +} _RuneLocale; + +#define _RUNE_MAGIC_1 "RuneMagi" /* Indicates version 0 of RuneLocale */ + +extern _RuneLocale _DefaultRuneLocale; +extern _RuneLocale *_CurrentRuneLocale; + +#endif /* !_RUNETYPE_H_ */ diff --git a/src/include/sched.h b/src/include/sched.h new file mode 100644 index 0000000..0079d9a --- /dev/null +++ b/src/include/sched.h @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 1996, 1997 + * HD Associates, Inc. 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 HD Associates, Inc + * and Jukka Antero Ukkonen. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES 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 HD ASSOCIATES 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. + * + * $FreeBSD: src/sys/posix4/sched.h,v 1.7 2002/10/03 06:27:50 mike Exp $ + */ + +/* sched.h: POSIX 1003.1b Process Scheduling header */ + +#ifndef _SCHED_H_ +#define _SCHED_H_ + +#include + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +/* + * Scheduling policies + */ +#define SCHED_FIFO 1 +#define SCHED_OTHER 2 +#define SCHED_RR 3 + +struct sched_param { + int sched_priority; +}; + +#ifndef _KERNEL +#include + +struct timespec; + +__BEGIN_DECLS +int sched_get_priority_max(int); +int sched_get_priority_min(int); +int sched_getparam(pid_t, struct sched_param *); +int sched_getscheduler(pid_t); +int sched_rr_get_interval(pid_t, struct timespec *); +int sched_setparam(pid_t, const struct sched_param *); +int sched_setscheduler(pid_t, int, const struct sched_param *); +int sched_yield(void); +__END_DECLS + +#endif + +#endif /* !_SCHED_H_ */ diff --git a/src/include/sdp.h b/src/include/sdp.h new file mode 100644 index 0000000..8dd1951 --- /dev/null +++ b/src/include/sdp.h @@ -0,0 +1,602 @@ +/* + * sdp.h + * + * Copyright (c) 2001-2003 Maksim Yevmenkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $Id$ + * $FreeBSD: src/lib/libsdp/sdp.h,v 1.4 2004/01/20 20:48:25 emax Exp $ + */ + +#ifndef _SDP_H_ +#define _SDP_H_ + +__BEGIN_DECLS + +/* + * Data representation (page 349) + */ + +/* Nil, the null type */ +#define SDP_DATA_NIL 0x00 + +/* Unsigned integer */ +#define SDP_DATA_UINT8 0x08 +#define SDP_DATA_UINT16 0x09 +#define SDP_DATA_UINT32 0x0A +#define SDP_DATA_UINT64 0x0B +#define SDP_DATA_UINT128 0x0C + +/* Signed two's-complement integer */ +#define SDP_DATA_INT8 0x10 +#define SDP_DATA_INT16 0x11 +#define SDP_DATA_INT32 0x12 +#define SDP_DATA_INT64 0x13 +#define SDP_DATA_INT128 0x14 + +/* UUID, a universally unique identifier */ +#define SDP_DATA_UUID16 0x19 +#define SDP_DATA_UUID32 0x1A +#define SDP_DATA_UUID128 0x1C + +/* Text string */ +#define SDP_DATA_STR8 0x25 +#define SDP_DATA_STR16 0x26 +#define SDP_DATA_STR32 0x27 + +/* Boolean */ +#define SDP_DATA_BOOL 0x28 + +/* + * Data element sequence. + * A data element whose data field is a sequence of data elements + */ +#define SDP_DATA_SEQ8 0x35 +#define SDP_DATA_SEQ16 0x36 +#define SDP_DATA_SEQ32 0x37 + +/* + * Data element alternative. + * A data element whose data field is a sequence of data elements from + * which one data element is to be selected. + */ +#define SDP_DATA_ALT8 0x3D +#define SDP_DATA_ALT16 0x3E +#define SDP_DATA_ALT32 0x3F + +/* URL, a uniform resource locator */ +#define SDP_DATA_URL8 0x45 +#define SDP_DATA_URL16 0x46 +#define SDP_DATA_URL32 0x47 + +/* + * Protocols UUID (short) http://www.bluetoothsig.org/assigned-numbers/sdp.htm + * BASE UUID 00000000-0000-1000-8000-00805F9B34FB + */ + +#define SDP_UUID_PROTOCOL_SDP 0x0001 +#define SDP_UUID_PROTOCOL_UDP 0x0002 +#define SDP_UUID_PROTOCOL_RFCOMM 0x0003 +#define SDP_UUID_PROTOCOL_TCP 0x0004 +#define SDP_UUID_PROTOCOL_TCS_BIN 0x0005 +#define SDP_UUID_PROTOCOL_TCS_AT 0x0006 +#define SDP_UUID_PROTOCOL_OBEX 0x0008 +#define SDP_UUID_PROTOCOL_IP 0x0009 +#define SDP_UUID_PROTOCOL_FTP 0x000A +#define SDP_UUID_PROTOCOL_HTTP 0x000C +#define SDP_UUID_PROTOCOL_WSP 0x000E +#define SDP_UUID_PROTOCOL_BNEP 0x000F +#define SDP_UUID_PROTOCOL_UPNP 0x0010 +#define SDP_UUID_PROTOCOL_HIDP 0x0011 +#define SDP_UUID_PROTOCOL_HARDCOPY_CONTROL_CHANNEL 0x0012 +#define SDP_UUID_PROTOCOL_HARDCOPY_DATA_CHANNEL 0x0014 +#define SDP_UUID_PROTOCOL_HARDCOPY_NOTIFICATION 0x0016 +#define SDP_UUID_PROTOCOL_AVCTP 0x0017 +#define SDP_UUID_PROTOCOL_AVDTP 0x0019 +#define SDP_UUID_PROTOCOL_CMPT 0x001B +#define SDP_UUID_PROTOCOL_UDI_C_PLANE 0x001D +#define SDP_UUID_PROTOCOL_L2CAP 0x0100 + +/* + * Service class IDs http://www.bluetoothsig.org/assigned-numbers/sdp.htm + */ + +#define SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER 0x1000 +#define SDP_SERVICE_CLASS_BROWSE_GROUP_DESCRIPTOR 0x1001 +#define SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP 0x1002 +#define SDP_SERVICE_CLASS_SERIAL_PORT 0x1101 +#define SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP 0x1102 +#define SDP_SERVICE_CLASS_DIALUP_NETWORKING 0x1103 +#define SDP_SERVICE_CLASS_IR_MC_SYNC 0x1104 +#define SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH 0x1105 +#define SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER 0x1106 +#define SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND 0x1107 +#define SDP_SERVICE_CLASS_HEADSET 0x1108 +#define SDP_SERVICE_CLASS_CORDLESS_TELEPHONY 0x1109 +#define SDP_SERVICE_CLASS_AUDIO_SOURCE 0x110A +#define SDP_SERVICE_CLASS_AUDIO_SINK 0x110B +#define SDP_SERVICE_CLASS_AV_REMOTE_CONTROL_TARGET 0x110C +#define SDP_SERVICE_CLASS_ADVANCED_AUDIO_DISTRIBUTION 0x110D +#define SDP_SERVICE_CLASS_AV_REMOTE_CONTROL 0x110E +#define SDP_SERVICE_CLASS_VIDEO_CONFERENCING 0x110F +#define SDP_SERVICE_CLASS_INTERCOM 0x1110 +#define SDP_SERVICE_CLASS_FAX 0x1111 +#define SDP_SERVICE_CLASS_HEADSET_AUDIO_GATEWAY 0x1112 +#define SDP_SERVICE_CLASS_WAP 0x1113 +#define SDP_SERVICE_CLASS_WAP_CLIENT 0x1114 +#define SDP_SERVICE_CLASS_PANU 0x1115 +#define SDP_SERVICE_CLASS_NAP 0x1116 +#define SDP_SERVICE_CLASS_GN 0x1117 +#define SDP_SERVICE_CLASS_DIRECT_PRINTING 0x1118 +#define SDP_SERVICE_CLASS_REFERENCE_PRINTING 0x1119 +#define SDP_SERVICE_CLASS_IMAGING 0x111A +#define SDP_SERVICE_CLASS_IMAGING_RESPONDER 0x111B +#define SDP_SERVICE_CLASS_IMAGING_AUTOMATIC_ARCHIVE 0x111C +#define SDP_SERVICE_CLASS_IMAGING_REFERENCED_OBJECTS 0x111D +#define SDP_SERVICE_CLASS_HANDSFREE 0x111E +#define SDP_SERVICE_CLASS_HANDSFREE_AUDIO_GATEWAY 0x111F +#define SDP_SERVICE_CLASS_DIRECT_PRINTING_REFERENCE_OBJECTS 0x1120 +#define SDP_SERVICE_CLASS_REFLECTED_UI 0x1121 +#define SDP_SERVICE_CLASS_BASIC_PRINTING 0x1122 +#define SDP_SERVICE_CLASS_PRINTING_STATUS 0x1123 +#define SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE 0x1124 +#define SDP_SERVICE_CLASS_HARDCOPY_CABLE_REPLACEMENT 0x1125 +#define SDP_SERVICE_CLASS_HCR_PRINT 0x1126 +#define SDP_SERVICE_CLASS_HCR_SCAN 0x1127 +#define SDP_SERVICE_CLASS_COMMON_ISDN_ACCESS 0x1128 +#define SDP_SERVICE_CLASS_VIDEO_CONFERENCING_GW 0x1129 +#define SDP_SERVICE_CLASS_UDI_MT 0x112A +#define SDP_SERVICE_CLASS_UDI_TA 0x112B +#define SDP_SERVICE_CLASS_AUDIO_VIDEO 0x112C +#define SDP_SERVICE_CLASS_SIM_ACCESS 0x112D +#define SDP_SERVICE_CLASS_PNP_INFORMATION 0x1200 +#define SDP_SERVICE_CLASS_GENERIC_NETWORKING 0x1201 +#define SDP_SERVICE_CLASS_GENERIC_FILE_TRANSFER 0x1202 +#define SDP_SERVICE_CLASS_GENERIC_AUDIO 0x1203 +#define SDP_SERVICE_CLASS_GENERIC_TELEPHONY 0x1204 +#define SDP_SERVICE_CLASS_UPNP 0x1205 +#define SDP_SERVICE_CLASS_UPNP_IP 0x1206 +#define SDP_SERVICE_CLASS_ESDP_UPNP_IP_PAN 0x1300 +#define SDP_SERVICE_CLASS_ESDP_UPNP_IP_LAP 0x1301 +#define SDP_SERVICE_CLASS_ESDP_UPNP_L2CAP 0x1302 + +/* + * Universal attribute definitions (page 366) and + * http://www.bluetoothsig.org/assigned-numbers/sdp.htm + */ + +#define SDP_ATTR_RANGE(lo, hi) \ + (uint32_t)(((uint16_t)(lo) << 16) | ((uint16_t)(hi))) + +#define SDP_ATTR_SERVICE_RECORD_HANDLE 0x0000 +#define SDP_ATTR_SERVICE_CLASS_ID_LIST 0x0001 +#define SDP_ATTR_SERVICE_RECORD_STATE 0x0002 +#define SDP_ATTR_SERVICE_ID 0x0003 +#define SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST 0x0004 +#define SDP_ATTR_BROWSE_GROUP_LIST 0x0005 +#define SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST 0x0006 +#define SDP_ATTR_SERVICE_INFO_TIME_TO_LIVE 0x0007 +#define SDP_ATTR_SERVICE_AVAILABILITY 0x0008 +#define SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST 0x0009 +#define SDP_ATTR_DOCUMENTATION_URL 0x000A +#define SDP_ATTR_CLIENT_EXECUTABLE_URL 0x000B +#define SDP_ATTR_ICON_URL 0x000C +#define SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS 0x000D +#define SDP_ATTR_GROUP_ID 0x0200 +#define SDP_ATTR_IP_SUBNET 0x0200 +#define SDP_ATTR_VERSION_NUMBER_LIST 0x0200 +#define SDP_ATTR_SERVICE_DATABASE_STATE 0x0201 +#define SDP_ATTR_SERVICE_VERSION 0x0300 +#define SDP_ATTR_EXTERNAL_NETWORK 0x0301 +#define SDP_ATTR_NETWORK 0x0301 +#define SDP_ATTR_SUPPORTED_DATA_STORES_LIST 0x0301 +#define SDP_ATTR_FAX_CLASS1_SUPPORT 0x0302 +#define SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 +#define SDP_ATTR_FAX_CLASS20_SUPPORT 0x0303 +#define SDP_ATTR_SUPPORTED_FORMATS_LIST 0x0303 +#define SDP_ATTR_FAX_CLASS2_SUPPORT 0x0304 +#define SDP_ATTR_AUDIO_FEEDBACK_SUPPORT 0x0305 +#define SDP_ATTR_NETWORK_ADDRESS 0x0306 +#define SDP_ATTR_WAP_GATEWAY 0x0307 +#define SDP_ATTR_HOME_PAGE_URL 0x0308 +#define SDP_ATTR_WAP_STACK_TYPE 0x0309 +#define SDP_ATTR_SECURITY_DESCRIPTION 0x030A +#define SDP_ATTR_NET_ACCESS_TYPE 0x030B +#define SDP_ATTR_MAX_NET_ACCESS_RATE 0x030C +#define SDP_ATTR_IPV4_SUBNET 0x030D +#define SDP_ATTR_IPV6_SUBNET 0x030E +#define SDP_ATTR_SUPPORTED_CAPABALITIES 0x0310 +#define SDP_ATTR_SUPPORTED_FEATURES 0x0311 +#define SDP_ATTR_SUPPORTED_FUNCTIONS 0x0312 +#define SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY 0x0313 + +/* + * The offset must be added to the attribute ID base (contained in the + * LANGUAGE_BASE_ATTRIBUTE_ID_LIST attribute) in order to compute the + * attribute ID for these attributes. + */ + +#define SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID 0x0100 +#define SDP_ATTR_SERVICE_NAME_OFFSET 0x0000 +#define SDP_ATTR_SERVICE_DESCRIPTION_OFFSET 0x0001 +#define SDP_ATTR_PROVIDER_NAME_OFFSET 0x0002 + +/* + * Protocol data unit (PDU) format (page 352) + */ + +#define SDP_PDU_ERROR_RESPONSE 0x01 +#define SDP_PDU_SERVICE_SEARCH_REQUEST 0x02 +#define SDP_PDU_SERVICE_SEARCH_RESPONSE 0x03 +#define SDP_PDU_SERVICE_ATTRIBUTE_REQUEST 0x04 +#define SDP_PDU_SERVICE_ATTRIBUTE_RESPONSE 0x05 +#define SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_REQUEST 0x06 +#define SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_RESPONSE 0x07 + +struct sdp_pdu { + uint8_t pid; /* PDU ID - SDP_PDU_xxx */ + uint16_t tid; /* transaction ID */ + uint16_t len; /* parameters length (in bytes) */ +} __attribute__ ((packed)); +typedef struct sdp_pdu sdp_pdu_t; +typedef struct sdp_pdu * sdp_pdu_p; + +/* + * Error codes for SDP_PDU_ERROR_RESPONSE + */ + +#define SDP_ERROR_CODE_INVALID_SDP_VERSION 0x0001 +#define SDP_ERROR_CODE_INVALID_SERVICE_RECORD_HANDLE 0x0002 +#define SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX 0x0003 +#define SDP_ERROR_CODE_INVALID_PDU_SIZE 0x0004 +#define SDP_ERROR_CODE_INVALID_CONTINUATION_STATE 0x0005 +#define SDP_ERROR_CODE_INSUFFICIENT_RESOURCES 0x0006 + +/* + * SDP int128/uint128 parameter + */ + +struct int128 { + int8_t b[16]; +}; +typedef struct int128 int128_t; +typedef struct int128 uint128_t; + +/* + * SDP attribute + */ + +struct sdp_attr { + uint16_t flags; +#define SDP_ATTR_OK (0 << 0) +#define SDP_ATTR_INVALID (1 << 0) +#define SDP_ATTR_TRUNCATED (1 << 1) + uint16_t attr; /* SDP_ATTR_xxx */ + uint32_t vlen; /* length of the value[] in bytes */ + uint8_t *value; /* base pointer */ +}; +typedef struct sdp_attr sdp_attr_t; +typedef struct sdp_attr * sdp_attr_p; + +/****************************************************************************** + * User interface + *****************************************************************************/ + +/* Inline versions of get/put byte/short/long. Pointer is advanced */ +#define SDP_GET8(b, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + (b) = *t_cp; \ + (cp) ++; \ +} + +#define SDP_GET16(s, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + (s) = ((uint16_t)t_cp[0] << 8) \ + | ((uint16_t)t_cp[1]) \ + ; \ + (cp) += 2; \ +} + +#define SDP_GET32(l, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + (l) = ((uint32_t)t_cp[0] << 24) \ + | ((uint32_t)t_cp[1] << 16) \ + | ((uint32_t)t_cp[2] << 8) \ + | ((uint32_t)t_cp[3]) \ + ; \ + (cp) += 4; \ +} + +#define SDP_GET64(l, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + (l) = ((uint64_t)t_cp[0] << 56) \ + | ((uint64_t)t_cp[1] << 48) \ + | ((uint64_t)t_cp[2] << 40) \ + | ((uint64_t)t_cp[3] << 32) \ + | ((uint64_t)t_cp[4] << 24) \ + | ((uint64_t)t_cp[5] << 16) \ + | ((uint64_t)t_cp[6] << 8) \ + | ((uint64_t)t_cp[7]) \ + ; \ + (cp) += 8; \ +} + +#if BYTE_ORDER == LITTLE_ENDIAN +#define SDP_GET128(l, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + (l)->b[15] = *t_cp++; \ + (l)->b[14] = *t_cp++; \ + (l)->b[13] = *t_cp++; \ + (l)->b[12] = *t_cp++; \ + (l)->b[11] = *t_cp++; \ + (l)->b[10] = *t_cp++; \ + (l)->b[9] = *t_cp++; \ + (l)->b[8] = *t_cp++; \ + (l)->b[7] = *t_cp++; \ + (l)->b[6] = *t_cp++; \ + (l)->b[5] = *t_cp++; \ + (l)->b[4] = *t_cp++; \ + (l)->b[3] = *t_cp++; \ + (l)->b[2] = *t_cp++; \ + (l)->b[1] = *t_cp++; \ + (cp) += 16; \ +} +#else /* BYTE_ORDER != LITTLE_ENDIAN */ +#define SDP_GET128(l, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + (l)->b[0] = *t_cp++; \ + (l)->b[1] = *t_cp++; \ + (l)->b[2] = *t_cp++; \ + (l)->b[3] = *t_cp++; \ + (l)->b[4] = *t_cp++; \ + (l)->b[5] = *t_cp++; \ + (l)->b[6] = *t_cp++; \ + (l)->b[7] = *t_cp++; \ + (l)->b[8] = *t_cp++; \ + (l)->b[9] = *t_cp++; \ + (l)->b[10] = *t_cp++; \ + (l)->b[11] = *t_cp++; \ + (l)->b[12] = *t_cp++; \ + (l)->b[13] = *t_cp++; \ + (l)->b[14] = *t_cp++; \ + (l)->b[15] = *t_cp++; \ + (cp) += 16; \ +} +#endif /* BYTE_ORDER */ + +#define SDP_PUT8(b, cp) { \ + register uint8_t t_b = (uint8_t)(b); \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + *t_cp = t_b; \ + (cp) ++; \ +} + +#define SDP_PUT16(s, cp) { \ + register uint16_t t_s = (uint16_t)(s); \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + *t_cp++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += 2; \ +} + +#define SDP_PUT32(l, cp) { \ + register uint32_t t_l = (uint32_t)(l); \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += 4; \ +} + +#define SDP_PUT64(l, cp) { \ + register uint64_t t_l = (uint64_t)(l); \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + *t_cp++ = t_l >> 56; \ + *t_cp++ = t_l >> 48; \ + *t_cp++ = t_l >> 40; \ + *t_cp++ = t_l >> 32; \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += 8; \ +} + +#if BYTE_ORDER == LITTLE_ENDIAN +#define SDP_PUT128(l, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + *t_cp++ = (l)->b[15]; \ + *t_cp++ = (l)->b[14]; \ + *t_cp++ = (l)->b[13]; \ + *t_cp++ = (l)->b[12]; \ + *t_cp++ = (l)->b[11]; \ + *t_cp++ = (l)->b[10]; \ + *t_cp++ = (l)->b[9]; \ + *t_cp++ = (l)->b[8]; \ + *t_cp++ = (l)->b[7]; \ + *t_cp++ = (l)->b[6]; \ + *t_cp++ = (l)->b[5]; \ + *t_cp++ = (l)->b[4]; \ + *t_cp++ = (l)->b[3]; \ + *t_cp++ = (l)->b[2]; \ + *t_cp++ = (l)->b[1]; \ + *t_cp = (l)->b[0]; \ + (cp) += 16; \ +} +#else /* BYTE_ORDER != LITTLE_ENDIAN */ +#define SDP_PUT128(l, cp) { \ + register uint8_t *t_cp = (uint8_t *)(cp); \ + *t_cp++ = (l)->b[0]; \ + *t_cp++ = (l)->b[1]; \ + *t_cp++ = (l)->b[2]; \ + *t_cp++ = (l)->b[3]; \ + *t_cp++ = (l)->b[4]; \ + *t_cp++ = (l)->b[5]; \ + *t_cp++ = (l)->b[6]; \ + *t_cp++ = (l)->b[7]; \ + *t_cp++ = (l)->b[8]; \ + *t_cp++ = (l)->b[9]; \ + *t_cp++ = (l)->b[10]; \ + *t_cp++ = (l)->b[11]; \ + *t_cp++ = (l)->b[12]; \ + *t_cp++ = (l)->b[13]; \ + *t_cp++ = (l)->b[14]; \ + *t_cp = (l)->b[15]; \ + (cp) += 16; \ +} +#endif /* BYTE_ORDER */ + +void * sdp_open (bdaddr_t const *l, bdaddr_t const *r); +void * sdp_open_local (char const *control); +int32_t sdp_close (void *xs); +int32_t sdp_error (void *xs); + +int32_t sdp_search (void *xs, + uint32_t plen, uint16_t const *pp, + uint32_t alen, uint32_t const *ap, + uint32_t vlen, sdp_attr_t *vp); + +char const * const sdp_attr2desc (uint16_t attr); +char const * const sdp_uuid2desc (uint16_t uuid); +void sdp_print (uint32_t level, uint8_t const *start, + uint8_t const *end); + +/****************************************************************************** + * sdpd interface and Bluetooth profiles data + *****************************************************************************/ + +#define SDP_LOCAL_PATH "/var/run/sdp" +#define SDP_LOCAL_MTU 4096 + +/* + * These are NOT defined in spec and only accepted on control sockets. + * The response to these request always will be SDP_PDU_ERROR_RESPONSE. + * The first 2 bytes (after PDU header) is an error code (in network + * byte order). The rest of the data (pdu->len - 2) is a response data + * and depend on the request. + * + * SDP_PDU_SERVICE_REGISTER_REQUEST + * pdu_header_t hdr; + * u_int16_t uuid; service class UUID (network byte order) + * bdaddr_t bdaddr; local BD_ADDR (or ANY) + * profile data[pdu->len - sizeof(uuid) - sizeof(bdaddr)] + * + * in successful reponse additional data will contain 4 bytes record handle + * + * + * SDP_PDU_SERVICE_UNREGISTER_REQUEST + * pdu_header_t hdr; + * u_int32_t record_handle; (network byte order) + * + * no additional data in response. + * + * + * SDP_PDU_SERVICE_CHANGE_REQUEST + * pdu_header_t hdr; + * u_int32_t record_handle; (network byte order) + * profile data[pdu->len - sizeof(record_handle)] + * + * no additional data in response. + */ + +#define SDP_PDU_SERVICE_REGISTER_REQUEST 0x81 +#define SDP_PDU_SERVICE_UNREGISTER_REQUEST 0x82 +#define SDP_PDU_SERVICE_CHANGE_REQUEST 0x83 + +struct sdp_dun_profile +{ + uint8_t server_channel; + uint8_t audio_feedback_support; + uint8_t reserved[2]; +}; +typedef struct sdp_dun_profile sdp_dun_profile_t; +typedef struct sdp_dun_profile * sdp_dun_profile_p; + +struct sdp_ftrn_profile +{ + uint8_t server_channel; + uint8_t reserved[3]; +}; +typedef struct sdp_ftrn_profile sdp_ftrn_profile_t; +typedef struct sdp_ftrn_profile * sdp_ftrn_profile_p; + +/* Keep this in sync with sdp_opush_profile */ +struct sdp_irmc_profile +{ + uint8_t server_channel; + uint8_t supported_formats_size; + uint8_t supported_formats[30]; +}; +typedef struct sdp_irmc_profile sdp_irmc_profile_t; +typedef struct sdp_irmc_profile * sdp_irmc_profile_p; + +struct sdp_irmc_command_profile +{ + uint8_t server_channel; + uint8_t reserved[3]; +}; +typedef struct sdp_irmc_command_profile sdp_irmc_command_profile_t; +typedef struct sdp_irmc_command_profile * sdp_irmc_command_profile_p; + +struct sdp_lan_profile +{ + uint8_t server_channel; + uint8_t load_factor; + uint8_t reserved; + uint8_t ip_subnet_radius; + uint32_t ip_subnet; +}; +typedef struct sdp_lan_profile sdp_lan_profile_t; +typedef struct sdp_lan_profile * sdp_lan_profile_p; + +/* Keep this in sync with sdp_irmc_profile */ +struct sdp_opush_profile +{ + uint8_t server_channel; + uint8_t supported_formats_size; + uint8_t supported_formats[30]; +}; +typedef struct sdp_opush_profile sdp_opush_profile_t; +typedef struct sdp_opush_profile * sdp_opush_profile_p; + +struct sdp_sp_profile +{ + uint8_t server_channel; + uint8_t reserved[3]; +}; +typedef struct sdp_sp_profile sdp_sp_profile_t; +typedef struct sdp_sp_profile * sdp_sp_profile_p; + +int32_t sdp_register_service (void *xss, uint16_t uuid, + bdaddr_p const bdaddr, uint8_t const *data, + uint32_t datalen, uint32_t *handle); +int32_t sdp_unregister_service (void *xss, uint32_t handle); +int32_t sdp_change_service (void *xss, uint32_t handle, + uint8_t const *data, uint32_t datalen); + +__END_DECLS + +#endif /* ndef _SDP_H_ */ + diff --git a/src/include/search.h b/src/include/search.h new file mode 100644 index 0000000..e401e01 --- /dev/null +++ b/src/include/search.h @@ -0,0 +1,66 @@ +/*- + * Written by J.T. Conklin + * Public domain. + * + * $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $ + * $FreeBSD: src/include/search.h,v 1.10 2002/10/16 14:29:23 robert Exp $ + */ + +#ifndef _SEARCH_H_ +#define _SEARCH_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +typedef struct entry { + char *key; + void *data; +} ENTRY; + +typedef enum { + FIND, ENTER +} ACTION; + +typedef enum { + preorder, + postorder, + endorder, + leaf +} VISIT; + +#ifdef _SEARCH_PRIVATE +typedef struct node { + char *key; + struct node *llink, *rlink; +} node_t; + +struct que_elem { + struct que_elem *next; + struct que_elem *prev; +}; +#endif + +__BEGIN_DECLS +int hcreate(size_t); +void hdestroy(void); +ENTRY *hsearch(ENTRY, ACTION); +void insque(void *, void *); +void *lfind(const void *, const void *, size_t *, size_t, + int (*)(const void *, const void *)); +void *lsearch(const void *, void *, size_t *, size_t, + int (*)(const void *, const void *)); +void remque(void *); +void *tdelete(const void * __restrict, void ** __restrict, + int (*)(const void *, const void *)); +void *tfind(const void *, void * const *, + int (*)(const void *, const void *)); +void *tsearch(const void *, void **, int (*)(const void *, const void *)); +void twalk(const void *, void (*)(const void *, VISIT, int)); +__END_DECLS + +#endif /* !_SEARCH_H_ */ diff --git a/src/include/semaphore.h b/src/include/semaphore.h new file mode 100644 index 0000000..b2daf34 --- /dev/null +++ b/src/include/semaphore.h @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1996, 1997 + * HD Associates, Inc. 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 HD Associates, Inc + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES 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 HD ASSOCIATES 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. + * + * $FreeBSD: src/sys/posix4/semaphore.h,v 1.11 2004/02/03 22:27:03 deischen Exp $ + */ + +/* semaphore.h: POSIX 1003.1b semaphores */ + +#ifndef _SEMAPHORE_H_ +#define _SEMAPHORE_H_ + +/* Opaque type definition. */ +struct sem; +typedef struct sem * sem_t; + +#define SEM_FAILED ((sem_t *)0) +#define SEM_VALUE_MAX (~0U) /* Equivalent to UINT_MAX. */ + +#ifndef _KERNEL +#include + +struct timespec; + +__BEGIN_DECLS +int sem_close(sem_t *); +int sem_destroy(sem_t *); +int sem_getvalue(sem_t * __restrict, int * __restrict); +int sem_init(sem_t *, int, unsigned int); +sem_t *sem_open(const char *, int, ...); +int sem_post(sem_t *); +int sem_timedwait(sem_t * __restrict, const struct timespec * __restrict); +int sem_trywait(sem_t *); +int sem_unlink(const char *); +int sem_wait(sem_t *); +__END_DECLS + +#endif + +#endif /* !_SEMAPHORE_H_ */ diff --git a/src/include/setjmp.h b/src/include/setjmp.h new file mode 100644 index 0000000..eb8e630 --- /dev/null +++ b/src/include/setjmp.h @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)setjmp.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/include/setjmp.h,v 1.8 2002/10/05 05:48:50 mike Exp $ + */ + +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +#include + +/* The size of the jmp_buf is machine dependent: */ +#include + +__BEGIN_DECLS +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +void _longjmp(jmp_buf, int) __dead2; +int _setjmp(jmp_buf); +#endif +void longjmp(jmp_buf, int) __dead2; +#if __BSD_VISIBLE +void longjmperror(void); +#endif +int setjmp(jmp_buf); +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XSI_VISIBLE +void siglongjmp(sigjmp_buf, int) __dead2; +int sigsetjmp(sigjmp_buf, int); +#endif +__END_DECLS + +#endif /* !_SETJMP_H_ */ diff --git a/src/include/sgtty.h b/src/include/sgtty.h new file mode 100644 index 0000000..723c69d --- /dev/null +++ b/src/include/sgtty.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1985, 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. + * + * @(#)sgtty.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef USE_OLD_TTY +#define USE_OLD_TTY +#endif +#include diff --git a/src/include/sha.h b/src/include/sha.h new file mode 100644 index 0000000..7b399e5 --- /dev/null +++ b/src/include/sha.h @@ -0,0 +1,98 @@ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * 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 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 cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 AUTHOR 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. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + * + * $FreeBSD: src/lib/libmd/sha.h,v 1.4 2001/03/17 10:00:50 phk Exp $ + */ + +#ifndef _SHA_H_ +#define _SHA_H_ 1 + +#include +#include /* XXX switch to machine/ansi.h and __ types */ + +#define SHA_CBLOCK 64 +#define SHA_LBLOCK 16 +#define SHA_BLOCK 16 +#define SHA_LAST_BLOCK 56 +#define SHA_LENGTH_BLOCK 8 +#define SHA_DIGEST_LENGTH 20 + +typedef struct SHAstate_st { + u_int32_t h0, h1, h2, h3, h4; + u_int32_t Nl, Nh; + u_int32_t data[SHA_LBLOCK]; + int num; +} SHA_CTX; +#define SHA1_CTX SHA_CTX + +__BEGIN_DECLS +void SHA_Init(SHA_CTX *c); +void SHA_Update(SHA_CTX *c, const unsigned char *data, size_t len); +void SHA_Final(unsigned char *md, SHA_CTX *c); +char *SHA_End(SHA_CTX *, char *); +char *SHA_File(const char *, char *); +char *SHA_FileChunk(const char *, char *, off_t, off_t); +char *SHA_Data(const unsigned char *, unsigned int, char *); +void SHA1_Init(SHA_CTX *c); +void SHA1_Update(SHA_CTX *c, const unsigned char *data, size_t len); +void SHA1_Final(unsigned char *md, SHA_CTX *c); +char *SHA1_End(SHA_CTX *, char *); +char *SHA1_File(const char *, char *); +char *SHA1_FileChunk(const char *, char *, off_t, off_t); +char *SHA1_Data(const unsigned char *, unsigned int, char *); +__END_DECLS + +#endif /* !_SHA_H_ */ diff --git a/src/include/signal.h b/src/include/signal.h new file mode 100644 index 0000000..9c8dc75 --- /dev/null +++ b/src/include/signal.h @@ -0,0 +1,116 @@ +/*- + * Copyright (c) 1991, 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. + * + * @(#)signal.h 8.3 (Berkeley) 3/30/94 + * $FreeBSD: src/include/signal.h,v 1.24 2003/03/31 23:30:41 jeff Exp $ + */ + +#ifndef _SIGNAL_H_ +#define _SIGNAL_H_ + +#include +#include +#include + +#if __BSD_VISIBLE +/* + * XXX should enlarge these, if only to give empty names instead of bounds + * errors for large signal numbers. + */ +extern __const char *__const sys_signame[NSIG]; +extern __const char *__const sys_siglist[NSIG]; +extern __const int sys_nsig; +#endif + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif +#endif + +__BEGIN_DECLS +int raise(int); + +#if __POSIX_VISIBLE || __XSI_VISIBLE +int kill(__pid_t, int); +int sigaction(int, const struct sigaction * __restrict, + struct sigaction * __restrict); +int sigaddset(sigset_t *, int); +int sigdelset(sigset_t *, int); +int sigemptyset(sigset_t *); +int sigfillset(sigset_t *); +int sigismember(const sigset_t *, int); +int sigpending(sigset_t *); +int sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict); +int sigsuspend(const sigset_t *); +int sigwait(const sigset_t * __restrict, int * __restrict); +#endif + +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 600 +#if 0 +/* + * PR: 35924 + * XXX we don't actually have these. We set _POSIX_REALTIME_SIGNALS to + * -1 to show that we don't have them, but this symbol is not necessarily + * in scope (in the current implementation), so we can't use it here. + */ +int sigqueue(__pid_t, int, const union sigval); +#endif +struct timespec; +int sigtimedwait(const sigset_t * __restrict, siginfo_t * __restrict, + const struct timespec * __restrict); +int sigwaitinfo(const sigset_t * __restrict, siginfo_t * __restrict); +#endif + +#if __XSI_VISIBLE +int killpg(__pid_t, int); +int sigaltstack(const stack_t * __restrict, stack_t * __restrict); +int sigpause(int); +#endif + +#if __POSIX_VISIBLE >= 200112 +int siginterrupt(int, int); +#endif + +#if __BSD_VISIBLE +int sigblock(int); +struct __ucontext; /* XXX spec requires a complete declaration. */ +int sigreturn(const struct __ucontext *); +int sigsetmask(int); +int sigstack(const struct sigstack *, struct sigstack *); +int sigvec(int, struct sigvec *, struct sigvec *); +void psignal(unsigned int, const char *); +#endif +__END_DECLS + +#endif /* !_SIGNAL_H_ */ diff --git a/src/include/spinlock.h b/src/include/spinlock.h new file mode 100644 index 0000000..8e9adb1 --- /dev/null +++ b/src/include/spinlock.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 1998 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. + * + * $FreeBSD: src/lib/libc/include/spinlock.h,v 1.7 2003/11/05 18:17:30 deischen Exp $ + * + * Lock definitions used in both libc and libpthread. + * + */ + +#ifndef _SPINLOCK_H_ +#define _SPINLOCK_H_ +#include +#include + +/* + * Lock structure with room for debugging information. + */ +struct _spinlock { + volatile long access_lock; + volatile long lock_owner; + volatile char *fname; + volatile int lineno; +}; +typedef struct _spinlock spinlock_t; + +#define _SPINLOCK_INITIALIZER { 0, 0, 0, 0 } + +#define _SPINUNLOCK(_lck) _spinunlock(_lck); +#ifdef _LOCK_DEBUG +#define _SPINLOCK(_lck) _spinlock_debug(_lck, __FILE__, __LINE__) +#else +#define _SPINLOCK(_lck) _spinlock(_lck) +#endif + +/* + * Thread function prototype definitions: + */ +__BEGIN_DECLS +long _atomic_lock(volatile long *); +void _spinlock(spinlock_t *); +void _spinunlock(spinlock_t *); +void _spinlock_debug(spinlock_t *, char *, int); +__END_DECLS + +#endif /* _SPINLOCK_H_ */ diff --git a/src/include/stab.h b/src/include/stab.h new file mode 100644 index 0000000..9200f52 --- /dev/null +++ b/src/include/stab.h @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 1991, 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. + * + * @(#)stab.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _STAB_H_ +#define _STAB_H_ + +/* + * The following are symbols used by various debuggers and by the Pascal + * compiler. Each of them must have one (or more) of the bits defined by + * the N_STAB mask set. + */ + +#define N_GSYM 0x20 /* global symbol */ +#define N_FNAME 0x22 /* F77 function name */ +#define N_FUN 0x24 /* procedure name */ +#define N_STSYM 0x26 /* data segment variable */ +#define N_LCSYM 0x28 /* bss segment variable */ +#define N_MAIN 0x2a /* main function name */ +#define N_PC 0x30 /* global Pascal symbol */ +#define N_RSYM 0x40 /* register variable */ +#define N_SLINE 0x44 /* text segment line number */ +#define N_DSLINE 0x46 /* data segment line number */ +#define N_BSLINE 0x48 /* bss segment line number */ +#define N_SSYM 0x60 /* structure/union element */ +#define N_SO 0x64 /* main source file name */ +#define N_LSYM 0x80 /* stack variable */ +#define N_BINCL 0x82 /* include file beginning */ +#define N_SOL 0x84 /* included source file name */ +#define N_PSYM 0xa0 /* parameter variable */ +#define N_EINCL 0xa2 /* include file end */ +#define N_ENTRY 0xa4 /* alternate entry point */ +#define N_LBRAC 0xc0 /* left bracket */ +#define N_EXCL 0xc2 /* deleted include file */ +#define N_RBRAC 0xe0 /* right bracket */ +#define N_BCOMM 0xe2 /* begin common */ +#define N_ECOMM 0xe4 /* end common */ +#define N_ECOML 0xe8 /* end common (local name) */ +#define N_LENG 0xfe /* length of preceding entry */ + +#endif diff --git a/src/include/stand.h b/src/include/stand.h new file mode 100644 index 0000000..a400752 --- /dev/null +++ b/src/include/stand.h @@ -0,0 +1,410 @@ +/* + * Copyright (c) 1998 Michael Smith. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libstand/stand.h,v 1.39 2004/01/15 18:35:32 jhb Exp $ + * From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $ + */ + +/*- + * Copyright (c) 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. + * + * @(#)stand.h 8.1 (Berkeley) 6/11/93 + */ + +#include +#include +#include +#include +#include + +#define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __FUNCTION__, __LINE__ , ##args) +#define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __FUNCTION__, __LINE__ , ##args); getchar();} + +#ifndef NULL +#define NULL 0 +#endif + +/* Avoid unwanted userlandish components */ +#define _KERNEL +#include +#undef _KERNEL + +/* special stand error codes */ +#define EADAPT (ELAST+1) /* bad adaptor */ +#define ECTLR (ELAST+2) /* bad controller */ +#define EUNIT (ELAST+3) /* bad unit */ +#define ESLICE (ELAST+4) /* bad slice */ +#define EPART (ELAST+5) /* bad partition */ +#define ERDLAB (ELAST+6) /* can't read disk label */ +#define EUNLAB (ELAST+7) /* unlabeled disk */ +#define EOFFSET (ELAST+8) /* relative seek not supported */ +#define ESALAST (ELAST+8) /* */ + +struct open_file; + +/* + * This structure is used to define file system operations in a file system + * independent way. + * + * XXX note that filesystem providers should export a pointer to their fs_ops + * struct, so that consumers can reference this and thus include the + * filesystems that they require. + */ +struct fs_ops { + const char *fs_name; + int (*fo_open)(const char *path, struct open_file *f); + int (*fo_close)(struct open_file *f); + int (*fo_read)(struct open_file *f, void *buf, + size_t size, size_t *resid); + int (*fo_write)(struct open_file *f, void *buf, + size_t size, size_t *resid); + off_t (*fo_seek)(struct open_file *f, off_t offset, int where); + int (*fo_stat)(struct open_file *f, struct stat *sb); + int (*fo_readdir)(struct open_file *f, struct dirent *d); +}; + +/* + * libstand-supplied filesystems + */ +extern struct fs_ops ufs_fsops; +extern struct fs_ops tftp_fsops; +extern struct fs_ops nfs_fsops; +extern struct fs_ops cd9660_fsops; +extern struct fs_ops gzipfs_fsops; +extern struct fs_ops bzipfs_fsops; +extern struct fs_ops dosfs_fsops; +extern struct fs_ops ext2fs_fsops; +extern struct fs_ops splitfs_fsops; + +/* where values for lseek(2) */ +#define SEEK_SET 0 /* set file offset to offset */ +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#define SEEK_END 2 /* set file offset to EOF plus offset */ + +/* + * Device switch + */ +struct devsw { + const char dv_name[8]; + int dv_type; /* opaque type constant, arch-dependant */ + int (*dv_init)(void); /* early probe call */ + int (*dv_strategy)(void *devdata, int rw, daddr_t blk, size_t size, + char *buf, size_t *rsize); + int (*dv_open)(struct open_file *f, ...); + int (*dv_close)(struct open_file *f); + int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data); + void (*dv_print)(int verbose); /* print device information */ + void (*dv_cleanup)(void); +}; + +/* + * libstand-supplied device switch + */ +extern struct devsw netdev; + +extern int errno; + +struct open_file { + int f_flags; /* see F_* below */ + struct devsw *f_dev; /* pointer to device operations */ + void *f_devdata; /* device specific data */ + struct fs_ops *f_ops; /* pointer to file system operations */ + void *f_fsdata; /* file system specific data */ + off_t f_offset; /* current file offset */ + char *f_rabuf; /* readahead buffer pointer */ + size_t f_ralen; /* valid data in readahead buffer */ + off_t f_raoffset; /* consumer offset in readahead buffer */ +#define SOPEN_RASIZE 512 +}; + +#define SOPEN_MAX 8 +extern struct open_file files[]; + +/* f_flags values */ +#define F_READ 0x0001 /* file opened for reading */ +#define F_WRITE 0x0002 /* file opened for writing */ +#define F_RAW 0x0004 /* raw device open - no file system */ +#define F_NODEV 0x0008 /* network open - no device */ + +#define isascii(c) (((c) & ~0x7F) == 0) + +static __inline int isupper(int c) +{ + return c >= 'A' && c <= 'Z'; +} + +static __inline int islower(int c) +{ + return c >= 'a' && c <= 'z'; +} + +static __inline int isspace(int c) +{ + return c == ' ' || (c >= 0x9 && c <= 0xd); +} + +static __inline int isdigit(int c) +{ + return c >= '0' && c <= '9'; +} + +static __inline int isxdigit(int c) +{ + return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); +} + +static __inline int isalpha(int c) +{ + return isupper(c) || islower(c); +} + +static __inline int isalnum(int c) +{ + return isalpha(c) || isdigit(c); +} + +static __inline int toupper(int c) +{ + return islower(c) ? c - 'a' + 'A' : c; +} + +static __inline int tolower(int c) +{ + return isupper(c) ? c - 'A' + 'a' : c; +} + +/* sbrk emulation */ +extern void setheap(void *base, void *top); +extern char *sbrk(int incr); + +/* Matt Dillon's zalloc/zmalloc */ +extern void *malloc(size_t bytes); +extern void free(void *ptr); +/*#define free(p) {CHK("free %p", p); free(p);} */ /* use for catching guard violations */ +extern void *calloc(size_t n1, size_t n2); +extern void *realloc(void *ptr, size_t size); +extern void *reallocf(void *ptr, size_t size); +extern void mallocstats(void); +#ifdef __alpha__ +extern void free_region(void *start, void *end); +#endif + +/* disklabel support (undocumented, may be junk) */ +struct disklabel; +extern char *getdisklabel(const char *, struct disklabel *); + +extern int printf(const char *fmt, ...) __printflike(1, 2); +extern void vprintf(const char *fmt, __va_list); +extern int sprintf(char *buf, const char *cfmt, ...) __printflike(2, 3); +extern void vsprintf(char *buf, const char *cfmt, __va_list); + +extern void twiddle(void); + +extern void ngets(char *, int); +#define gets(x) ngets((x), 0) +extern int fgetstr(char *buf, int size, int fd); + +extern int open(const char *, int); +#define O_RDONLY 0x0 +#define O_WRONLY 0x1 +#define O_RDWR 0x2 +extern int close(int); +extern void closeall(void); +extern ssize_t read(int, void *, size_t); +extern ssize_t write(int, void *, size_t); +extern struct dirent *readdirfd(int); + +extern void srandom(u_long seed); +extern u_long random(void); + +/* imports from stdlib, locally modified */ +extern long strtol(const char *, char **, int); +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt, optreset; +extern int getopt(int, char * const [], const char *); + +/* pager.c */ +extern void pager_open(void); +extern void pager_close(void); +extern int pager_output(const char *lines); +extern int pager_file(const char *fname); + +/* No signal state to preserve */ +#define setjmp _setjmp +#define longjmp _longjmp + +/* environment.c */ +#define EV_DYNAMIC (1<<0) /* value was dynamically allocated, free if changed/unset */ +#define EV_VOLATILE (1<<1) /* value is volatile, make a copy of it */ +#define EV_NOHOOK (1<<2) /* don't call hook when setting */ + +struct env_var; +typedef char *(ev_format_t)(struct env_var *ev); +typedef int (ev_sethook_t)(struct env_var *ev, int flags, + const void *value); +typedef int (ev_unsethook_t)(struct env_var *ev); + +struct env_var +{ + char *ev_name; + int ev_flags; + void *ev_value; + ev_sethook_t *ev_sethook; + ev_unsethook_t *ev_unsethook; + struct env_var *ev_next, *ev_prev; +}; +extern struct env_var *environ; + +extern struct env_var *env_getenv(const char *name); +extern int env_setenv(const char *name, int flags, + const void *value, ev_sethook_t sethook, + ev_unsethook_t unsethook); +extern char *getenv(const char *name); +extern int setenv(const char *name, const char *value, + int overwrite); +extern int putenv(const char *string); +extern int unsetenv(const char *name); + +extern ev_sethook_t env_noset; /* refuse set operation */ +extern ev_unsethook_t env_nounset; /* refuse unset operation */ + +/* BCD conversions (undocumented) */ +extern u_char const bcd2bin_data[]; +extern u_char const bin2bcd_data[]; +extern char const hex2ascii_data[]; + +#define bcd2bin(bcd) (bcd2bin_data[bcd]) +#define bin2bcd(bin) (bin2bcd_data[bin]) +#define hex2ascii(hex) (hex2ascii_data[hex]) + +/* min/max (undocumented) */ +static __inline int imax(int a, int b) { return (a > b ? a : b); } +static __inline int imin(int a, int b) { return (a < b ? a : b); } +static __inline long lmax(long a, long b) { return (a > b ? a : b); } +static __inline long lmin(long a, long b) { return (a < b ? a : b); } +static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); } +static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } +static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); } +static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); } +static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); } +static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); } + +/* swaps (undocumented, useful?) */ +#ifdef __i386__ +extern u_int32_t bswap32(u_int32_t x); +extern u_int64_t bswap64(u_int64_t x); +#endif + +/* null functions for device/filesystem switches (undocumented) */ +extern int nodev(void); +extern int noioctl(struct open_file *, u_long, void *); +extern void nullsys(void); + +extern int null_open(const char *path, struct open_file *f); +extern int null_close(struct open_file *f); +extern int null_read(struct open_file *f, void *buf, size_t size, size_t *resid); +extern int null_write(struct open_file *f, void *buf, size_t size, size_t *resid); +extern off_t null_seek(struct open_file *f, off_t offset, int where); +extern int null_stat(struct open_file *f, struct stat *sb); +extern int null_readdir(struct open_file *f, struct dirent *d); + + +/* + * Machine dependent functions and data, must be provided or stubbed by + * the consumer + */ +extern int getchar(void); +extern int ischar(void); +extern void putchar(int); +extern int devopen(struct open_file *, const char *, const char **); +extern int devclose(struct open_file *f); +extern void panic(const char *, ...) __dead2 __printflike(1, 2); +extern struct fs_ops *file_system[]; +extern struct devsw *devsw[]; + +/* + * Expose byteorder(3) functions. + */ +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +extern uint32_t htonl(uint32_t); +extern uint16_t htons(uint16_t); +extern uint32_t ntohl(uint32_t); +extern uint16_t ntohs(uint16_t); +#endif + +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif + +void *Malloc(size_t, const char *, int); +void *Calloc(size_t, size_t, const char *, int); +void *Realloc(void *, size_t, const char *, int); +void Free(void *, const char *, int); + +#if 1 +#define malloc(x) Malloc(x, __FILE__, __LINE__) +#define calloc(x, y) Calloc(x, y, __FILE__, __LINE__) +#define free(x) Free(x, __FILE__, __LINE__) +#define realloc(x, y) Realloc(x, y, __FILE__, __LINE__) +#else +#define malloc(x) Malloc(x, NULL, 0) +#define calloc(x, y) Calloc(x, y, NULL, 0) +#define free(x) Free(x, NULL, 0) +#define realloc(x, y) Realloc(x, y, NULL, 0) +#endif diff --git a/src/include/stdarg.h b/src/include/stdarg.h new file mode 100644 index 0000000..0825298 --- /dev/null +++ b/src/include/stdarg.h @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 2002 David E. O'Brien. All rights reserved. + * Copyright (c) 1991, 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. + * + * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD: src/sys/i386/include/stdarg.h,v 1.19 2004/03/12 21:45:31 trhodes Exp $ + */ + +#ifndef _MACHINE_STDARG_H_ +#define _MACHINE_STDARG_H_ + +#include +#include + +#ifndef _VA_LIST_DECLARED +#define _VA_LIST_DECLARED +typedef __va_list va_list; +#endif + +#if (defined(__GNUC__) && (__GNUC__ == 2 && __GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)) + +#define va_start(ap, last) \ + __builtin_stdarg_start((ap), (last)) + +#define va_arg(ap, type) \ + __builtin_va_arg((ap), type) + +#if __ISO_C_VISIBLE >= 1999 +#define va_copy(dest, src) \ + __builtin_va_copy((dest), (src)) +#endif + +#define va_end(ap) \ + __builtin_va_end(ap) + +#else /* ! (__GNUC__ post GCC 2.95 || __INTEL_COMPILER) */ + +#define __va_size(type) \ + (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) + +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define va_start(ap, last) \ + ((ap) = (va_list)__builtin_next_arg(last)) +#else /* non-GNU compiler */ +#define va_start(ap, last) \ + ((ap) = (va_list)&(last) + __va_size(last)) +#endif /* __GNUC__ */ + +#define va_arg(ap, type) \ + (*(type *)((ap) += __va_size(type), (ap) - __va_size(type))) + +#if __ISO_C_VISIBLE >= 1999 +#define va_copy(dest, src) \ + ((dest) = (src)) +#endif + +#define va_end(ap) + +#endif /* __GNUC__ post GCC 2.95 */ + +#endif /* !_MACHINE_STDARG_H_ */ diff --git a/src/include/stdbool.h b/src/include/stdbool.h new file mode 100644 index 0000000..be545ce --- /dev/null +++ b/src/include/stdbool.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2000 Jeroen Ruigrok van der Werven + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/stdbool.h,v 1.6 2002/08/16 07:33:14 alfred Exp $ + */ + +#ifndef _STDBOOL_H_ +#define _STDBOOL_H_ + +#define __bool_true_false_are_defined 1 + +#ifndef __cplusplus + +#define false 0 +#define true 1 + +#define bool _Bool +#if __STDC_VERSION__ < 199901L && __GNUC__ < 3 +typedef int _Bool; +#endif + +#endif /* !__cplusplus */ + +#endif /* !_STDBOOL_H_ */ diff --git a/src/include/stddef.h b/src/include/stddef.h new file mode 100644 index 0000000..a331305 --- /dev/null +++ b/src/include/stddef.h @@ -0,0 +1,68 @@ +/*- + * 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. + * + * @(#)stddef.h 8.1 (Berkeley) 6/2/93 + * + * $FreeBSD: src/include/stddef.h,v 1.10 2003/12/07 21:10:06 marcel Exp $ + */ + +#ifndef _STDDEF_H_ +#define _STDDEF_H_ + +#include +#include +#include + +typedef __ptrdiff_t ptrdiff_t; + +#if __BSD_VISIBLE +#ifndef _RUNE_T_DECLARED +typedef __rune_t rune_t; +#define _RUNE_T_DECLARED +#endif +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +typedef __wchar_t wchar_t; +#define _WCHAR_T_DECLARED +#endif +#endif + +#define offsetof(type, member) __offsetof(type, member) + +#endif /* _STDDEF_H_ */ diff --git a/src/include/stdint.h b/src/include/stdint.h new file mode 100644 index 0000000..b0d6632 --- /dev/null +++ b/src/include/stdint.h @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/stdint.h,v 1.4 2002/08/21 16:20:01 mike Exp $ + */ + +#ifndef _SYS_STDINT_H_ +#define _SYS_STDINT_H_ + +#include +#include + +#include + +#ifndef _INT8_T_DECLARED +typedef __int8_t int8_t; +#define _INT8_T_DECLARED +#endif + +#ifndef _INT16_T_DECLARED +typedef __int16_t int16_t; +#define _INT16_T_DECLARED +#endif + +#ifndef _INT32_T_DECLARED +typedef __int32_t int32_t; +#define _INT32_T_DECLARED +#endif + +#ifndef _INT64_T_DECLARED +typedef __int64_t int64_t; +#define _INT64_T_DECLARED +#endif + +#ifndef _UINT8_T_DECLARED +typedef __uint8_t uint8_t; +#define _UINT8_T_DECLARED +#endif + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif + +typedef __int_least8_t int_least8_t; +typedef __int_least16_t int_least16_t; +typedef __int_least32_t int_least32_t; +typedef __int_least64_t int_least64_t; + +typedef __uint_least8_t uint_least8_t; +typedef __uint_least16_t uint_least16_t; +typedef __uint_least32_t uint_least32_t; +typedef __uint_least64_t uint_least64_t; + +typedef __int_fast8_t int_fast8_t; +typedef __int_fast16_t int_fast16_t; +typedef __int_fast32_t int_fast32_t; +typedef __int_fast64_t int_fast64_t; + +typedef __uint_fast8_t uint_fast8_t; +typedef __uint_fast16_t uint_fast16_t; +typedef __uint_fast32_t uint_fast32_t; +typedef __uint_fast64_t uint_fast64_t; + +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + +#ifndef _INTPTR_T_DECLARED +typedef __intptr_t intptr_t; +typedef __uintptr_t uintptr_t; +#define _INTPTR_T_DECLARED +#endif + +#endif /* !_SYS_STDINT_H_ */ diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 0000000..8371b05 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,454 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)stdio.h 8.5 (Berkeley) 4/29/95 + * $FreeBSD: src/include/stdio.h,v 1.54 2004/03/20 11:45:52 tjr Exp $ + */ + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#include +#include +#include + +typedef __off_t fpos_t; + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#ifndef _VA_LIST_DECLARED +typedef __va_list va_list; +#define _VA_LIST_DECLARED +#endif +#endif + +#define _FSTDIO /* Define for new stdio with functions. */ + +/* + * NB: to fit things in six character monocase externals, the stdio + * code uses the prefix `__s' for stdio objects, typically followed + * by a three-character attempt at a mnemonic. + */ + +/* stdio buffers */ +struct __sbuf { + unsigned char *_base; + int _size; +}; + +/* hold a buncha junk that would grow the ABI */ +struct __sFILEX; + +/* + * stdio state variables. + * + * The following always hold: + * + * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), + * _lbfsize is -_bf._size, else _lbfsize is 0 + * if _flags&__SRD, _w is 0 + * if _flags&__SWR, _r is 0 + * + * This ensures that the getc and putc macros (or inline functions) never + * try to write or read from a file that is in `read' or `write' mode. + * (Moreover, they can, and do, automatically switch from read mode to + * write mode, and back, on "r+" and "w+" files.) + * + * _lbfsize is used only to make the inline line-buffered output stream + * code as compact as possible. + * + * _ub, _up, and _ur are used when ungetc() pushes back more characters + * than fit in the current _bf, or when ungetc() pushes back a character + * that does not match the previous one in _bf. When this happens, + * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff + * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. + * + * NB: see WARNING above before changing the layout of this structure! + */ +typedef struct __sFILE { + unsigned char *_p; /* current position in (some) buffer */ + int _r; /* read space left for getc() */ + int _w; /* write space left for putc() */ + short _flags; /* flags, below; this FILE is free if 0 */ + short _file; /* fileno, if Unix descriptor, else -1 */ + struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ + int _lbfsize; /* 0 or -_bf._size, for inline putc */ + + /* operations */ + void *_cookie; /* cookie passed to io functions */ + int (*_close)(void *); + int (*_read)(void *, char *, int); + fpos_t (*_seek)(void *, fpos_t, int); + int (*_write)(void *, const char *, int); + + /* separate buffer for long sequences of ungetc() */ + struct __sbuf _ub; /* ungetc buffer */ + struct __sFILEX *_extra; /* additions to FILE to not break ABI */ + int _ur; /* saved _r when _r is counting ungetc data */ + + /* tricks to meet minimum requirements even when malloc() fails */ + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ + unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + + /* separate buffer for fgetln() when line crosses buffer boundary */ + struct __sbuf _lb; /* buffer for fgetln() */ + + /* Unix stdio files get aligned to block boundaries on fseek() */ + int _blksize; /* stat.st_blksize (may be != _bf._size) */ + fpos_t _offset; /* current lseek offset (see WARNING) */ +} FILE; + +__BEGIN_DECLS +extern FILE *__stdinp; +extern FILE *__stdoutp; +extern FILE *__stderrp; +__END_DECLS + +#define __SLBF 0x0001 /* line buffered */ +#define __SNBF 0x0002 /* unbuffered */ +#define __SRD 0x0004 /* OK to read */ +#define __SWR 0x0008 /* OK to write */ + /* RD and WR are never simultaneously asserted */ +#define __SRW 0x0010 /* open for reading & writing */ +#define __SEOF 0x0020 /* found EOF */ +#define __SERR 0x0040 /* found error */ +#define __SMBF 0x0080 /* _buf is from malloc */ +#define __SAPP 0x0100 /* fdopen()ed in append mode */ +#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ +#define __SOPT 0x0400 /* do fseek() optimization */ +#define __SNPT 0x0800 /* do not do fseek() optimization */ +#define __SOFF 0x1000 /* set iff _offset is in fact correct */ +#define __SMOD 0x2000 /* true => fgetln modified _p text */ +#define __SALC 0x4000 /* allocate string space dynamically */ +#define __SIGN 0x8000 /* ignore this file in _fwalk */ + +/* + * The following three definitions are for ANSI C, which took them + * from System V, which brilliantly took internal interface macros and + * made them official arguments to setvbuf(), without renaming them. + * Hence, these ugly _IOxxx names are *supposed* to appear in user code. + * + * Although numbered as their counterparts above, the implementation + * does not rely on this. + */ +#define _IOFBF 0 /* setvbuf should set fully buffered */ +#define _IOLBF 1 /* setvbuf should set line buffered */ +#define _IONBF 2 /* setvbuf should set unbuffered */ + +#define BUFSIZ 1024 /* size of buffer used by setbuf */ +#define EOF (-1) + +/* + * FOPEN_MAX is a minimum maximum, and is the number of streams that + * stdio can provide without attempting to allocate further resources + * (which could fail). Do not use this for anything. + */ + /* must be == _POSIX_STREAM_MAX */ +#define FOPEN_MAX 20 /* must be <= OPEN_MAX */ +#define FILENAME_MAX 1024 /* must be <= PATH_MAX */ + +/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ +#if __XSI_VISIBLE +#define P_tmpdir "/var/tmp/" +#endif +#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ +#define TMP_MAX 308915776 + +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#define stdin __stdinp +#define stdout __stdoutp +#define stderr __stderrp + +__BEGIN_DECLS +/* + * Functions defined in ANSI C standard. + */ +void clearerr(FILE *); +int fclose(FILE *); +int feof(FILE *); +int ferror(FILE *); +int fflush(FILE *); +int fgetc(FILE *); +int fgetpos(FILE * __restrict, fpos_t * __restrict); +char *fgets(char * __restrict, int, FILE * __restrict); +FILE *fopen(const char * __restrict, const char * __restrict); +int fprintf(FILE * __restrict, const char * __restrict, ...); +int fputc(int, FILE *); +int fputs(const char * __restrict, FILE * __restrict); +size_t fread(void * __restrict, size_t, size_t, FILE * __restrict); +FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict); +int fscanf(FILE * __restrict, const char * __restrict, ...); +int fseek(FILE *, long, int); +int fsetpos(FILE *, const fpos_t *); +long ftell(FILE *); +size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); +int getc(FILE *); +int getchar(void); +char *gets(char *); +void perror(const char *); +int printf(const char * __restrict, ...); +int putc(int, FILE *); +int putchar(int); +int puts(const char *); +int remove(const char *); +int rename(const char *, const char *); +void rewind(FILE *); +int scanf(const char * __restrict, ...); +void setbuf(FILE * __restrict, char * __restrict); +int setvbuf(FILE * __restrict, char * __restrict, int, size_t); +int sprintf(char * __restrict, const char * __restrict, ...); +int sscanf(const char * __restrict, const char * __restrict, ...); +FILE *tmpfile(void); +char *tmpnam(char *); +int ungetc(int, FILE *); +int vfprintf(FILE * __restrict, const char * __restrict, + __va_list); +int vprintf(const char * __restrict, __va_list); +int vsprintf(char * __restrict, const char * __restrict, + __va_list); + +#if __ISO_C_VISIBLE >= 1999 +int snprintf(char * __restrict, size_t, const char * __restrict, + ...) __printflike(3, 4); +int vfscanf(FILE * __restrict, const char * __restrict, __va_list) + __scanflike(2, 0); +int vscanf(const char * __restrict, __va_list) __scanflike(1, 0); +int vsnprintf(char * __restrict, size_t, const char * __restrict, + __va_list) __printflike(3, 0); +int vsscanf(const char * __restrict, const char * __restrict, __va_list) + __scanflike(2, 0); +#endif + +/* + * Functions defined in all versions of POSIX 1003.1. + */ +#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506 +/* size for cuserid(3); UT_NAMESIZE + 1, see */ +#define L_cuserid 17 /* legacy */ +#endif + +#if __POSIX_VISIBLE +#define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */ + +char *ctermid(char *); +FILE *fdopen(int, const char *); +int fileno(FILE *); +#endif /* __POSIX_VISIBLE */ + +#if __POSIX_VISIBLE >= 199209 +int pclose(FILE *); +FILE *popen(const char *, const char *); +#endif + +#if __POSIX_VISIBLE >= 199506 +int ftrylockfile(FILE *); +void flockfile(FILE *); +void funlockfile(FILE *); + +/* + * These are normally used through macros as defined below, but POSIX + * requires functions as well. + */ +int getc_unlocked(FILE *); +int getchar_unlocked(void); +int putc_unlocked(int, FILE *); +int putchar_unlocked(int); +#endif +#if __BSD_VISIBLE +void clearerr_unlocked(FILE *); +int feof_unlocked(FILE *); +int ferror_unlocked(FILE *); +int fileno_unlocked(FILE *); +#endif + +#if __POSIX_VISIBLE >= 200112 +int fseeko(FILE *, __off_t, int); +__off_t ftello(FILE *); +#endif + +#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600 +int getw(FILE *); +int putw(int, FILE *); +#endif /* BSD or X/Open before issue 6 */ + +#if __XSI_VISIBLE +char *tempnam(const char *, const char *); +#endif + +/* + * Routines that are purely local. + */ +#if __BSD_VISIBLE +int asprintf(char **, const char *, ...) __printflike(2, 3); +char *ctermid_r(char *); +char *fgetln(FILE *, size_t *); +#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3 +#define __ATTR_FORMAT_ARG __attribute__((__format_arg__(2))) +#else +#define __ATTR_FORMAT_ARG +#endif +__const char *fmtcheck(const char *, const char *) __ATTR_FORMAT_ARG; +int fpurge(FILE *); +void setbuffer(FILE *, char *, int); +int setlinebuf(FILE *); +int vasprintf(char **, const char *, __va_list) + __printflike(2, 0); + +/* + * The system error table contains messages for the first sys_nerr + * positive errno values. Use strerror() or strerror_r() from + * instead. + */ +extern __const int sys_nerr; +extern __const char *__const sys_errlist[]; + +/* + * Stdio function-access interface. + */ +FILE *funopen(const void *, + int (*)(void *, char *, int), + int (*)(void *, const char *, int), + fpos_t (*)(void *, fpos_t, int), + int (*)(void *)); +#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) +#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) + +/* + * Portability hacks. See . + */ +#ifndef _FTRUNCATE_DECLARED +#define _FTRUNCATE_DECLARED +int ftruncate(int, __off_t); +#endif +#ifndef _LSEEK_DECLARED +#define _LSEEK_DECLARED +__off_t lseek(int, __off_t, int); +#endif +#ifndef _MMAP_DECLARED +#define _MMAP_DECLARED +void *mmap(void *, size_t, int, int, int, __off_t); +#endif +#ifndef _TRUNCATE_DECLARED +#define _TRUNCATE_DECLARED +int truncate(const char *, __off_t); +#endif +#endif /* __BSD_VISIBLE */ + +/* + * Functions internal to the implementation. + */ +int __srget(FILE *); +int __swbuf(int, FILE *); + +/* + * The __sfoo macros are here so that we can + * define function versions in the C library. + */ +#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) +#if defined(__GNUC__) && defined(__STDC__) +static __inline int __sputc(int _c, FILE *_p) { + if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) + return (*_p->_p++ = _c); + else + return (__swbuf(_c, _p)); +} +#else +/* + * This has been tuned to generate reasonable code on the vax using pcc. + */ +#define __sputc(c, p) \ + (--(p)->_w < 0 ? \ + (p)->_w >= (p)->_lbfsize ? \ + (*(p)->_p = (c)), *(p)->_p != '\n' ? \ + (int)*(p)->_p++ : \ + __swbuf('\n', p) : \ + __swbuf((int)(c), p) : \ + (*(p)->_p = (c), (int)*(p)->_p++)) +#endif + +#define __sfeof(p) (((p)->_flags & __SEOF) != 0) +#define __sferror(p) (((p)->_flags & __SERR) != 0) +#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) +#define __sfileno(p) ((p)->_file) + +extern int __isthreaded; + +#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p)) +#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p)) +#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p)) + +#if __POSIX_VISIBLE +#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p)) +#endif + +#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp)) +#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp)) + +#define getchar() getc(stdin) +#define putchar(x) putc(x, stdout) + +#if __BSD_VISIBLE +/* + * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12 + * B.8.2.7 for the rationale behind the *_unlocked() macros. + */ +#define feof_unlocked(p) __sfeof(p) +#define ferror_unlocked(p) __sferror(p) +#define clearerr_unlocked(p) __sclearerr(p) +#define fileno_unlocked(p) __sfileno(p) +#endif +#if __POSIX_VISIBLE >= 199506 +#define getc_unlocked(fp) __sgetc(fp) +#define putc_unlocked(x, fp) __sputc(x, fp) + +#define getchar_unlocked() getc_unlocked(stdin) +#define putchar_unlocked(x) putc_unlocked(x, stdout) +#endif + +__END_DECLS +#endif /* !_STDIO_H_ */ diff --git a/src/include/stdlib.h b/src/include/stdlib.h new file mode 100644 index 0000000..111d4a4 --- /dev/null +++ b/src/include/stdlib.h @@ -0,0 +1,282 @@ +/*- + * 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. + * + * @(#)stdlib.h 8.5 (Berkeley) 5/19/95 + * $FreeBSD: src/include/stdlib.h,v 1.56 2004/02/23 03:16:58 ache Exp $ + */ + +#ifndef _STDLIB_H_ +#define _STDLIB_H_ + +#include +#include +#include + +#if __BSD_VISIBLE +#ifndef _RUNE_T_DECLARED +typedef __rune_t rune_t; +#define _RUNE_T_DECLARED +#endif +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +typedef __wchar_t wchar_t; +#define _WCHAR_T_DECLARED +#endif +#endif + +typedef struct { + int quot; /* quotient */ + int rem; /* remainder */ +} div_t; + +typedef struct { + long quot; + long rem; +} ldiv_t; + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#define RAND_MAX 0x7fffffff + +extern int __mb_cur_max; +#define MB_CUR_MAX __mb_cur_max + +__BEGIN_DECLS +void abort(void) __dead2; +int abs(int) __pure2; +int atexit(void (*)(void)); +double atof(const char *); +int atoi(const char *); +long atol(const char *); +void *bsearch(const void *, const void *, size_t, + size_t, int (*)(const void *, const void *)); +void *calloc(size_t, size_t); +div_t div(int, int) __pure2; +void exit(int) __dead2; +void free(void *); +char *getenv(const char *); +long labs(long) __pure2; +ldiv_t ldiv(long, long) __pure2; +void *malloc(size_t); +int mblen(const char *, size_t); +size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t); +int mbtowc(wchar_t * __restrict, const char * __restrict, size_t); +void qsort(void *, size_t, size_t, + int (*)(const void *, const void *)); +int rand(void); +void *realloc(void *, size_t); +void srand(unsigned); +double strtod(const char * __restrict, char ** __restrict); +float strtof(const char * __restrict, char ** __restrict); +long strtol(const char * __restrict, char ** __restrict, int); +long double + strtold(const char * __restrict, char ** __restrict); +unsigned long + strtoul(const char * __restrict, char ** __restrict, int); +int system(const char *); +int wctomb(char *, wchar_t); +size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); + +/* + * Functions added in C99 which we make conditionally available in the + * BSD^C89 namespace if the compiler supports `long long'. + * The #if test is more complicated than it ought to be because + * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long' + * is not supported in the compilation environment (which therefore means + * that it can't really be ISO C99). + * + * (The only other extension made by C99 in thie header is _Exit().) + */ +#if __ISO_C_VISIBLE >= 1999 +#ifdef __LONG_LONG_SUPPORTED +/* LONGLONG */ +typedef struct { + long long quot; + long long rem; +} lldiv_t; + +/* LONGLONG */ +long long + atoll(const char *); +/* LONGLONG */ +long long + llabs(long long) __pure2; +/* LONGLONG */ +lldiv_t lldiv(long long, long long) __pure2; +/* LONGLONG */ +long long + strtoll(const char * __restrict, char ** __restrict, int); +/* LONGLONG */ +unsigned long long + strtoull(const char * __restrict, char ** __restrict, int); +#endif /* __LONG_LONG_SUPPORTED */ + +void _Exit(int) __dead2; +#endif /* __ISO_C_VISIBLE >= 1999 */ + +/* + * Extensions made by POSIX relative to C. We don't know yet which edition + * of POSIX made these extensions, so assume they've always been there until + * research can be done. + */ +#if __POSIX_VISIBLE /* >= ??? */ +/* int posix_memalign(void **, size_t, size_t); (ADV) */ +int rand_r(unsigned *); /* (TSF) */ +int setenv(const char *, const char *, int); +void unsetenv(const char *); +#endif + +/* + * The only changes to the XSI namespace in revision 6 were the deletion + * of the ttyslot() and valloc() functions, which FreeBSD never declared + * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which + * FreeBSD also does not have, and mktemp(), are to be deleted. + */ +#if __XSI_VISIBLE +/* XXX XSI requires pollution from here. We'd rather not. */ +/* long a64l(const char *); */ +double drand48(void); +/* char *ecvt(double, int, int * __restrict, int * __restrict); */ +double erand48(unsigned short[3]); +/* char *fcvt(double, int, int * __restrict, int * __restrict); */ +/* char *gcvt(double, int, int * __restrict, int * __restrict); */ +int getsubopt(char **, char *const *, char **); +int grantpt(int); +char *initstate(unsigned long /* XSI requires u_int */, char *, long); +long jrand48(unsigned short[3]); +/* char *l64a(long); */ +void lcong48(unsigned short[7]); +long lrand48(void); +#ifndef _MKSTEMP_DECLARED +int mkstemp(char *); +#define _MKSTEMP_DECLARED +#endif +#ifndef _MKTEMP_DECLARED +char *mktemp(char *); +#define _MKTEMP_DECLARED +#endif +long mrand48(void); +long nrand48(unsigned short[3]); +int posix_openpt(int); +char *ptsname(int); +int putenv(const char *); +long random(void); +char *realpath(const char *, char resolved_path[]); +unsigned short + *seed48(unsigned short[3]); +#ifndef _SETKEY_DECLARED +int setkey(const char *); +#define _SETKEY_DECLARED +#endif +char *setstate(/* const */ char *); +void srand48(long); +void srandom(unsigned long); +int unlockpt(int); +#endif /* __XSI_VISIBLE */ + +#if __BSD_VISIBLE +extern const char *_malloc_options; +extern void (*_malloc_message)(const char *, const char *, const char *, + const char *); + +/* + * The alloca() function can't be implemented in C, and on some + * platforms it can't be implemented at all as a callable function. + * The GNU C compiler provides a built-in alloca() which we can use; + * in all other cases, provide a prototype, mainly to pacify various + * incarnations of lint. On platforms where alloca() is not in libc, + * programs which use it will fail to link when compiled with non-GNU + * compilers. + */ +#if __GNUC__ >= 2 || defined(__INTEL_COMPILER) +#undef alloca /* some GNU bits try to get cute and define this on their own */ +#define alloca(sz) __builtin_alloca(sz) +#elif defined(lint) +void *alloca(size_t); +#endif + +__uint32_t + arc4random(void); +void arc4random_addrandom(unsigned char *dat, int datlen); +void arc4random_stir(void); +char *getbsize(int *, long *); + /* getcap(3) functions */ +char *cgetcap(char *, const char *, int); +int cgetclose(void); +int cgetent(char **, char **, const char *); +int cgetfirst(char **, char **); +int cgetmatch(const char *, const char *); +int cgetnext(char **, char **); +int cgetnum(char *, const char *, long *); +int cgetset(const char *); +int cgetstr(char *, const char *, char **); +int cgetustr(char *, const char *, char **); + +int daemon(int, int); +char *devname(int, int); +char *devname_r(int, int, char *, int); +int getloadavg(double [], int); +__const char * + getprogname(void); + +int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); +int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); +void qsort_r(void *, size_t, size_t, void *, + int (*)(void *, const void *, const void *)); +int radixsort(const unsigned char **, int, const unsigned char *, + unsigned); +void *reallocf(void *, size_t); +void setprogname(const char *); +int sradixsort(const unsigned char **, int, const unsigned char *, + unsigned); +void sranddev(void); +void srandomdev(void); + +/* Deprecated interfaces, to be removed in FreeBSD 6.0. */ +__int64_t + strtoq(const char *, char **, int); +__uint64_t + strtouq(const char *, char **, int); + +extern char *suboptarg; /* getsubopt(3) external variable */ +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_STDLIB_H_ */ diff --git a/src/include/string.h b/src/include/string.h new file mode 100644 index 0000000..07ba85e --- /dev/null +++ b/src/include/string.h @@ -0,0 +1,115 @@ +/*- + * 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. + * + * @(#)string.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/string.h,v 1.19 2003/12/07 21:10:06 marcel Exp $ + */ + +#ifndef _STRING_H_ +#define _STRING_H_ + +#include +#include +#include + +/* + * Prototype functions which were historically defined in , but + * are required by POSIX to be prototyped in . + */ +#if __BSD_VISIBLE +#include +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +void *memccpy(void * __restrict, const void * __restrict, int, size_t); +#endif +void *memchr(const void *, int, size_t); +int memcmp(const void *, const void *, size_t); +void *memcpy(void * __restrict, const void * __restrict, size_t); +void *memmove(void *, const void *, size_t); +void *memset(void *, int, size_t); +#if __BSD_VISIBLE +char *stpcpy(char *, const char *); +char *strcasestr(const char *, const char *); +#endif +char *strcat(char * __restrict, const char * __restrict); +char *strchr(const char *, int); +int strcmp(const char *, const char *); +int strcoll(const char *, const char *); +char *strcpy(char * __restrict, const char * __restrict); +size_t strcspn(const char *, const char *); +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +char *strdup(const char *); +#endif +char *strerror(int); +#if __POSIX_VISIBLE >= 200112 +int strerror_r(int, char *, size_t); +#endif +#if __BSD_VISIBLE +size_t strlcat(char *, const char *, size_t); +size_t strlcpy(char *, const char *, size_t); +#endif +size_t strlen(const char *); +#if __BSD_VISIBLE +void strmode(int, char *); +#endif +char *strncat(char * __restrict, const char * __restrict, size_t); +int strncmp(const char *, const char *, size_t); +char *strncpy(char * __restrict, const char * __restrict, size_t); +#if __BSD_VISIBLE +char *strnstr(const char *, const char *, size_t); +#endif +char *strpbrk(const char *, const char *); +char *strrchr(const char *, int); +#if __BSD_VISIBLE +char *strsep(char **, const char *); +char *strsignal(int); +#endif +size_t strspn(const char *, const char *); +char *strstr(const char *, const char *); +char *strtok(char * __restrict, const char * __restrict); +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500 +char *strtok_r(char *, const char *, char **); +#endif +size_t strxfrm(char * __restrict, const char * __restrict, size_t); +#if __BSD_VISIBLE +void swab(const void *, void *, size_t); +#endif +__END_DECLS + +#endif /* _STRING_H_ */ diff --git a/src/include/stringlist.h b/src/include/stringlist.h new file mode 100644 index 0000000..52a121c --- /dev/null +++ b/src/include/stringlist.h @@ -0,0 +1,57 @@ +/* $NetBSD: stringlist.h,v 1.2 1997/01/17 06:11:36 lukem Exp $ */ + +/* + * Copyright (c) 1994 Christos Zoulas + * 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/include/stringlist.h,v 1.3 2003/01/19 01:16:00 obrien Exp $ + */ + +#ifndef _STRINGLIST_H +#define _STRINGLIST_H +#include +#include + +/* + * Simple string list + */ +typedef struct _stringlist { + char **sl_str; + size_t sl_max; + size_t sl_cur; +} StringList; + +__BEGIN_DECLS +StringList *sl_init(void); +int sl_add(StringList *, char *); +void sl_free(StringList *, int); +char *sl_find(StringList *, char *); +__END_DECLS + +#endif /* _STRINGLIST_H */ diff --git a/src/include/strings.h b/src/include/strings.h new file mode 100644 index 0000000..508fbac --- /dev/null +++ b/src/include/strings.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/strings.h,v 1.4 2004/01/13 16:05:47 des Exp $ + */ + +#ifndef _STRINGS_H_ +#define _STRINGS_H_ + +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +int bcmp(const void *, const void *, size_t); /* LEGACY */ +void bcopy(const void *, void *, size_t); /* LEGACY */ +void bzero(void *, size_t); /* LEGACY */ +int ffs(int); +int ffsl(long); +int fls(int); +int flsl(long); +char *index(const char *, int); /* LEGACY */ +char *rindex(const char *, int); /* LEGACY */ +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); +__END_DECLS + +#endif /* _STRINGS_H_ */ diff --git a/src/include/sys/_iovec.h b/src/include/sys/_iovec.h new file mode 100644 index 0000000..d93a3e9 --- /dev/null +++ b/src/include/sys/_iovec.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1982, 1986, 1993, 1994 + * 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. + * 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. + * + * @(#)uio.h 8.5 (Berkeley) 2/22/94 + * $FreeBSD: src/sys/sys/_iovec.h,v 1.3 2004/04/07 04:19:48 imp Exp $ + */ + +#ifndef _SYS__IOVEC_H_ +#define _SYS__IOVEC_H_ + +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +struct iovec { + void *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ +}; + +#endif /* !_SYS__IOVEC_H_ */ diff --git a/src/include/sys/_label.h b/src/include/sys/_label.h new file mode 100644 index 0000000..5dae687 --- /dev/null +++ b/src/include/sys/_label.h @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1999-2002 Robert N. M. Watson + * Copyright (c) 2001-2002 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * This software was developed for the FreeBSD Project in part by Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), + * as part of the DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/_label.h,v 1.6 2004/05/10 18:38:07 rwatson Exp $ + */ +#ifndef _SYS__LABEL_H_ +#define _SYS__LABEL_H_ + +/* + * XXXMAC: This shouldn't be exported to userland, but is because of ucred.h + * and various other messes. + */ + +#define MAC_MAX_SLOTS 4 + +#define MAC_FLAG_INITIALIZED 0x0000001 /* Is initialized for use. */ + +struct label { + int l_flags; + union { + void *l_ptr; + long l_long; + } l_perpolicy[MAC_MAX_SLOTS]; +}; + +#endif /* !_SYS__LABEL_H_ */ diff --git a/src/include/sys/_lock.h b/src/include/sys/_lock.h new file mode 100644 index 0000000..bada8b8 --- /dev/null +++ b/src/include/sys/_lock.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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. + * + * $FreeBSD: src/sys/sys/_lock.h,v 1.8 2002/06/07 14:37:09 bde Exp $ + */ + +#ifndef _SYS__LOCK_H_ +#define _SYS__LOCK_H_ + +struct lock_object { + struct lock_class *lo_class; + const char *lo_name; /* Individual lock name. */ + const char *lo_type; /* General lock type. */ + u_int lo_flags; + TAILQ_ENTRY(lock_object) lo_list; /* List of all locks in system. */ + struct witness *lo_witness; +}; + +#endif /* !_SYS__LOCK_H_ */ diff --git a/src/include/sys/_mutex.h b/src/include/sys/_mutex.h new file mode 100644 index 0000000..b1fb045 --- /dev/null +++ b/src/include/sys/_mutex.h @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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. + * + * $FreeBSD: src/sys/sys/_mutex.h,v 1.11 2004/01/25 01:59:26 rwatson Exp $ + */ + +#ifndef _SYS__MUTEX_H_ +#define _SYS__MUTEX_H_ + +/* + * Sleep/spin mutex. + */ +struct mtx { + struct lock_object mtx_object; /* Common lock properties. */ + volatile uintptr_t mtx_lock; /* Owner and flags. */ + volatile u_int mtx_recurse; /* Number of recursive holds. */ + +#ifdef MUTEX_PROFILING + /* + * This does not result in variant structure sizes because + * MUTEX_PROFILING is in opt_global.h + */ + u_int64_t mtx_acqtime; + const char *mtx_filename; + int mtx_lineno; + /* + * Fields relating to measuring contention on mutexes. + * holding must be accessed atomically since it's + * modified by threads that don't yet hold the mutex. + * locking is only modified and referenced while + * the mutex is held. + */ + u_int mtx_contest_holding; + u_int mtx_contest_locking; +#endif +}; + +#endif /* !_SYS__MUTEX_H_ */ diff --git a/src/include/sys/_null.h b/src/include/sys/_null.h new file mode 100644 index 0000000..29209a9 --- /dev/null +++ b/src/include/sys/_null.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2003 Marcel Moolenaar + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/_null.h,v 1.6 2004/03/05 08:10:19 markm Exp $ + */ + +#ifndef NULL + +#if defined(_KERNEL) || !defined(__cplusplus) +#define NULL ((void *)0) +#else +#if defined(__LP64__) +#define NULL (0L) +#else +#define NULL 0 +#endif /* __LP64__ */ +#endif /* _KERNEL || !__cplusplus */ + +#endif diff --git a/src/include/sys/_sigset.h b/src/include/sys/_sigset.h new file mode 100644 index 0000000..ce02d3c --- /dev/null +++ b/src/include/sys/_sigset.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)signal.h 8.4 (Berkeley) 5/4/95 + * $FreeBSD: src/sys/sys/_sigset.h,v 1.35 2004/04/07 04:19:48 imp Exp $ + */ + +#ifndef _SYS__SIGSET_H_ +#define _SYS__SIGSET_H_ + +/* + * sigset_t macros. + */ +#define _SIG_WORDS 4 +#define _SIG_MAXSIG 128 +#define _SIG_IDX(sig) ((sig) - 1) +#define _SIG_WORD(sig) (_SIG_IDX(sig) >> 5) +#define _SIG_BIT(sig) (1 << (_SIG_IDX(sig) & 31)) +#define _SIG_VALID(sig) ((sig) <= _SIG_MAXSIG && (sig) > 0) + +typedef struct __sigset { + __uint32_t __bits[_SIG_WORDS]; +} __sigset_t; + +#if defined(_KERNEL) && defined(COMPAT_43) +typedef unsigned int osigset_t; +#endif + +#endif /* !_SYS__SIGSET_H_ */ diff --git a/src/include/sys/_task.h b/src/include/sys/_task.h new file mode 100644 index 0000000..38eb739 --- /dev/null +++ b/src/include/sys/_task.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2000 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/_task.h,v 1.1 2004/01/23 20:44:26 rwatson Exp $ + */ + +#ifndef _SYS__TASK_H_ +#define _SYS__TASK_H_ + +#ifndef _KERNEL +#error "no user-servicable parts inside" +#endif + +#include + +/* + * Each task includes a function which is called from + * taskqueue_run(). The first argument is taken from the 'ta_context' + * field of struct task and the second argument is a count of how many + * times the task was enqueued before the call to taskqueue_run(). + */ +typedef void task_fn_t(void *context, int pending); + +struct task { + STAILQ_ENTRY(task) ta_link; /* link for queue */ + int ta_pending; /* count times queued */ + int ta_priority; /* priority of task in queue */ + task_fn_t *ta_func; /* task handler */ + void *ta_context; /* argument for handler */ +}; + +#endif /* !_SYS__TASK_H_ */ diff --git a/src/include/sys/_timespec.h b/src/include/sys/_timespec.h new file mode 100644 index 0000000..9b725d2 --- /dev/null +++ b/src/include/sys/_timespec.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp + * $FreeBSD: src/sys/sys/_timespec.h,v 1.4 2004/04/07 04:19:48 imp Exp $ + */ + +/* + * Prerequisite: + * + * This file must be kept synchronized with . + * It defines a structure which must be a type pun for + * `struct timespec'; this structure is used in header files where + * the ABI uses a `struct timespec' but standards prohibit its + * definition. (Currently only .) + * + * XXX should just declare struct __timespec as necessary. It's simple, + * so is easy to keep synchronized, and hopefully not needed in as many + * places as struct timespec, so we don't need this extra header. + * Perhaps we don't need timespec.h either. + */ + +#ifndef _SYS__TIMESPEC_H_ +#define _SYS__TIMESPEC_H_ + +struct __timespec { + __time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +#endif /* !_SYS__TIMESPEC_H_ */ diff --git a/src/include/sys/_timeval.h b/src/include/sys/_timeval.h new file mode 100644 index 0000000..9784bcf --- /dev/null +++ b/src/include/sys/_timeval.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/_timeval.h,v 1.1 2002/12/31 04:08:41 mike Exp $ + */ + +#ifndef _SYS__TIMEVAL_H_ +#define _SYS__TIMEVAL_H_ + +#include + +#ifndef _SUSECONDS_T_DECLARED +typedef __suseconds_t suseconds_t; +#define _SUSECONDS_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +/* + * Structure returned by gettimeofday(2) system call, and used in other calls. + */ +struct timeval { + long tv_sec; /* seconds (XXX should be time_t) */ + suseconds_t tv_usec; /* and microseconds */ +}; + +#endif /* !_SYS__TIMEVAL_H_ */ diff --git a/src/include/sys/_types.h b/src/include/sys/_types.h new file mode 100644 index 0000000..5f91cdd --- /dev/null +++ b/src/include/sys/_types.h @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/_types.h,v 1.14 2003/03/28 15:27:30 mike Exp $ + */ + +#ifndef _SYS__TYPES_H_ +#define _SYS__TYPES_H_ + +#include +#include + +/* + * Standard type definitions. + */ +typedef __int32_t __clockid_t; /* clock_gettime()... */ +typedef __uint32_t __fflags_t; /* file flags */ +typedef __uint64_t __fsblkcnt_t; +typedef __uint64_t __fsfilcnt_t; +typedef __uint32_t __gid_t; +typedef __int64_t __id_t; /* can hold a gid_t, pid_t, or uid_t */ +typedef __uint32_t __ino_t; /* inode number */ +typedef long __key_t; /* IPC key (for Sys V IPC) */ +typedef __uint16_t __mode_t; /* permissions */ +typedef int __nl_item; +typedef __uint16_t __nlink_t; /* link count */ +typedef __int64_t __off_t; /* file offset */ +typedef __int32_t __pid_t; /* process [group] */ +typedef __int64_t __rlim_t; /* resource limit (XXX not unsigned) */ +typedef __uint8_t __sa_family_t; +typedef __uint32_t __socklen_t; +typedef long __suseconds_t; /* microseconds (signed) */ +typedef __int32_t __timer_t; /* timer_gettime()... */ +typedef __uint32_t __udev_t; /* device number */ +typedef __uint32_t __uid_t; +typedef unsigned int __useconds_t; /* microseconds (unsigned) */ + +/* + * Unusual type definitions. + */ +/* + * rune_t is declared to be an ``int'' instead of the more natural + * ``unsigned long'' or ``long''. Two things are happening here. It is not + * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, + * it looks like 10646 will be a 31 bit standard. This means that if your + * ints cannot hold 32 bits, you will be in trouble. The reason an int was + * chosen over a long is that the is*() and to*() routines take ints (says + * ANSI C), but they use __ct_rune_t instead of int. + * + * NOTE: rune_t is not covered by ANSI nor other standards, and should not + * be instantiated outside of lib/libc/locale. Use wchar_t. wchar_t and + * rune_t must be the same type. Also, wint_t must be no narrower than + * wchar_t, and should be able to hold all members of the largest + * character set plus one extra value (WEOF), and must be at least 16 bits. + */ +typedef int __ct_rune_t; +typedef __ct_rune_t __rune_t; +typedef __ct_rune_t __wchar_t; +typedef __ct_rune_t __wint_t; + +/* + * dev_t has differing meanings in userland and the kernel. + */ +#ifdef _KERNEL +struct cdev; +typedef struct cdev *__dev_t; +#else +typedef __udev_t __dev_t; /* device number */ +#endif + +/* + * mbstate_t is an opaque object to keep conversion state during multibyte + * stream conversions. + */ +typedef union { + char __mbstate8[128]; + __int64_t _mbstateL; /* for alignment */ +} __mbstate_t; + +#endif /* !_SYS__TYPES_H_ */ diff --git a/src/include/sys/acct.h b/src/include/sys/acct.h new file mode 100644 index 0000000..6755310 --- /dev/null +++ b/src/include/sys/acct.h @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)acct.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/acct.h,v 1.17 2004/04/07 04:19:48 imp Exp $ + */ + +#ifndef _SYS_ACCT_H_ +#define _SYS_ACCT_H_ + +/* + * Accounting structures; these use a comp_t type which is a 3 bits base 8 + * exponent, 13 bit fraction ``floating point'' number. Units are 1/AHZ + * seconds. + */ +typedef u_int16_t comp_t; + +#define AC_COMM_LEN 16 +struct acct { + char ac_comm[AC_COMM_LEN]; /* command name */ + comp_t ac_utime; /* user time */ + comp_t ac_stime; /* system time */ + comp_t ac_etime; /* elapsed time */ + time_t ac_btime; /* starting time */ + uid_t ac_uid; /* user id */ + gid_t ac_gid; /* group id */ + u_int16_t ac_mem; /* average memory usage */ + comp_t ac_io; /* count of IO blocks */ + __udev_t ac_tty; /* controlling tty */ + +#define AFORK 0x01 /* forked but not exec'ed */ +/* ASU is no longer supported */ +#define ASU 0x02 /* used super-user permissions */ +#define ACOMPAT 0x04 /* used compatibility mode */ +#define ACORE 0x08 /* dumped core */ +#define AXSIG 0x10 /* killed by a signal */ + u_int8_t ac_flag; /* accounting flags */ +}; + +/* + * 1/AHZ is the granularity of the data encoded in the comp_t fields. + * This is not necessarily equal to hz. + */ +#define AHZ 64 + +#ifdef _KERNEL +struct thread; + +int acct_process(struct thread *td); +#endif + +#endif /* !_SYS_ACCT_H_ */ diff --git a/src/include/sys/acl.h b/src/include/sys/acl.h new file mode 100644 index 0000000..3df9789 --- /dev/null +++ b/src/include/sys/acl.h @@ -0,0 +1,229 @@ +/*- + * Copyright (c) 1999-2001 Robert N. M. Watson + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/acl.h,v 1.27 2004/05/10 18:38:07 rwatson Exp $ + */ +/* + * Developed by the TrustedBSD Project. + * Support for POSIX.1e access control lists. + */ + +#ifndef _SYS_ACL_H_ +#define _SYS_ACL_H_ + +/* + * POSIX.1e ACL types and related constants. + */ + +#define POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define POSIX1E_ACL_ACCESS_EXTATTR_NAME "posix1e.acl_access" +#define POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define POSIX1E_ACL_DEFAULT_EXTATTR_NAME "posix1e.acl_default" +#define ACL_MAX_ENTRIES 32 /* maximum entries in an ACL */ + +typedef int acl_type_t; +typedef int acl_tag_t; +typedef mode_t acl_perm_t; +typedef mode_t *acl_permset_t; + +struct acl_entry { + acl_tag_t ae_tag; + uid_t ae_id; + acl_perm_t ae_perm; +}; +typedef struct acl_entry *acl_entry_t; + +/* internal ACL structure */ +struct acl { + int acl_cnt; + struct acl_entry acl_entry[ACL_MAX_ENTRIES]; +}; + +/* external ACL structure */ +struct acl_t_struct { + struct acl ats_acl; + int ats_cur_entry; +}; +typedef struct acl_t_struct *acl_t; + +/* + * Possible valid values for ae_tag field. + */ +#define ACL_UNDEFINED_TAG 0x00000000 +#define ACL_USER_OBJ 0x00000001 +#define ACL_USER 0x00000002 +#define ACL_GROUP_OBJ 0x00000004 +#define ACL_GROUP 0x00000008 +#define ACL_MASK 0x00000010 +#define ACL_OTHER 0x00000020 +#define ACL_OTHER_OBJ ACL_OTHER + +/* + * Possible valid values for acl_type_t arguments. + */ +#define ACL_TYPE_ACCESS 0x00000000 +#define ACL_TYPE_DEFAULT 0x00000001 +#define ACL_TYPE_AFS 0x00000002 +#define ACL_TYPE_CODA 0x00000003 +#define ACL_TYPE_NTFS 0x00000004 +#define ACL_TYPE_NWFS 0x00000005 + +/* + * Possible flags in ae_perm field. + */ +#define ACL_EXECUTE 0x0001 +#define ACL_WRITE 0x0002 +#define ACL_READ 0x0004 +#define ACL_PERM_NONE 0x0000 +#define ACL_PERM_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) +#define ACL_POSIX1E_BITS (ACL_EXECUTE | ACL_WRITE | ACL_READ) + +/* + * Possible entry_id values for acl_get_entry() + */ +#define ACL_FIRST_ENTRY 0 +#define ACL_NEXT_ENTRY 1 + +/* + * Undefined value in ae_id field + */ +#define ACL_UNDEFINED_ID ((uid_t)-1) + + +#ifdef _KERNEL + +/* + * POSIX.1e ACLs are capable of expressing the read, write, and execute + * bits of the POSIX mode field. We provide two masks: one that defines + * the bits the ACL will replace in the mode, and the other that defines + * the bits that must be preseved when an ACL is updating a mode. + */ +#define ACL_OVERRIDE_MASK (S_IRWXU | S_IRWXG | S_IRWXO) +#define ACL_PRESERVE_MASK (~ACL_OVERRIDE_MASK) + +/* + * Storage for ACLs and support structures. + */ +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_ACL); +#endif + +/* + * File system independent code to move back and forth between POSIX mode + * and POSIX.1e ACL representations. + */ +acl_perm_t acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode); +struct acl_entry acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid, + gid_t gid, mode_t mode); +mode_t acl_posix1e_perms_to_mode( + struct acl_entry *acl_user_obj_entry, + struct acl_entry *acl_group_obj_entry, + struct acl_entry *acl_other_entry); +mode_t acl_posix1e_acl_to_mode(struct acl *acl); +mode_t acl_posix1e_newfilemode(mode_t cmode, + struct acl *dacl); + +/* + * File system independent syntax check for a POSIX.1e ACL. + */ +int acl_posix1e_check(struct acl *acl); + +#else /* !_KERNEL */ + +/* + * Syscall interface -- use the library calls instead as the syscalls + * have strict acl entry ordering requirements. + */ +__BEGIN_DECLS +int __acl_aclcheck_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_aclcheck_file(const char *_path, acl_type_t _type, + struct acl *_aclp); +int __acl_aclcheck_link(const char *_path, acl_type_t _type, + struct acl *_aclp); +int __acl_delete_fd(int _filedes, acl_type_t _type); +int __acl_delete_file(const char *_path_p, acl_type_t _type); +int __acl_delete_link(const char *_path_p, acl_type_t _type); +int __acl_get_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_get_file(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_get_link(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_set_fd(int _filedes, acl_type_t _type, struct acl *_aclp); +int __acl_set_file(const char *_path, acl_type_t _type, struct acl *_aclp); +int __acl_set_link(const char *_path, acl_type_t _type, struct acl *_aclp); +__END_DECLS + +/* + * Supported POSIX.1e ACL manipulation and assignment/retrieval API + * _np calls are local extensions that reflect an environment capable of + * opening file descriptors of directories, and allowing additional + * ACL type for different filesystems (i.e., AFS). + */ +__BEGIN_DECLS +int acl_add_perm(acl_permset_t _permset_d, acl_perm_t _perm); +int acl_calc_mask(acl_t *_acl_p); +int acl_clear_perms(acl_permset_t _permset_d); +int acl_copy_entry(acl_entry_t _dest_d, acl_entry_t _src_d); +ssize_t acl_copy_ext(void *_buf_p, acl_t _acl, ssize_t _size); +acl_t acl_copy_int(const void *_buf_p); +int acl_create_entry(acl_t *_acl_p, acl_entry_t *_entry_p); +int acl_delete_entry(acl_t _acl, acl_entry_t _entry_d); +int acl_delete_fd_np(int _filedes, acl_type_t _type); +int acl_delete_file_np(const char *_path_p, acl_type_t _type); +int acl_delete_link_np(const char *_path_p, acl_type_t _type); +int acl_delete_def_file(const char *_path_p); +int acl_delete_def_link_np(const char *_path_p); +int acl_delete_perm(acl_permset_t _permset_d, acl_perm_t _perm); +acl_t acl_dup(acl_t _acl); +int acl_free(void *_obj_p); +acl_t acl_from_text(const char *_buf_p); +int acl_get_entry(acl_t _acl, int _entry_id, acl_entry_t *_entry_p); +acl_t acl_get_fd(int _fd); +acl_t acl_get_fd_np(int fd, acl_type_t _type); +acl_t acl_get_file(const char *_path_p, acl_type_t _type); +acl_t acl_get_link_np(const char *_path_p, acl_type_t _type); +void *acl_get_qualifier(acl_entry_t _entry_d); +int acl_get_perm_np(acl_permset_t _permset_d, acl_perm_t _perm); +int acl_get_permset(acl_entry_t _entry_d, acl_permset_t *_permset_p); +int acl_get_tag_type(acl_entry_t _entry_d, acl_tag_t *_tag_type_p); +acl_t acl_init(int _count); +int acl_set_fd(int _fd, acl_t _acl); +int acl_set_fd_np(int _fd, acl_t _acl, acl_type_t _type); +int acl_set_file(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_set_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_set_permset(acl_entry_t _entry_d, acl_permset_t _permset_d); +int acl_set_qualifier(acl_entry_t _entry_d, const void *_tag_qualifier_p); +int acl_set_tag_type(acl_entry_t _entry_d, acl_tag_t _tag_type); +ssize_t acl_size(acl_t _acl); +char *acl_to_text(acl_t _acl, ssize_t *_len_p); +int acl_valid(acl_t _acl); +int acl_valid_fd_np(int _fd, acl_type_t _type, acl_t _acl); +int acl_valid_file_np(const char *_path_p, acl_type_t _type, acl_t _acl); +int acl_valid_link_np(const char *_path_p, acl_type_t _type, acl_t _acl); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_ACL_H_ */ diff --git a/src/include/sys/agpio.h b/src/include/sys/agpio.h new file mode 100644 index 0000000..a265415 --- /dev/null +++ b/src/include/sys/agpio.h @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2000 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/agpio.h,v 1.4 2003/10/23 18:08:56 jhb Exp $ + */ + +#ifndef _SYS_AGPIO_H_ +#define _SYS_AGPIO_H_ + +/* + * The AGP gatt uses 4k pages irrespective of the host page size. + */ +#define AGP_PAGE_SIZE 4096 +#define AGP_PAGE_SHIFT 12 + +/* + * Macros to manipulate AGP mode words. + * + * SBA = Sideband Address Port + * FW = Fast Writes + */ +#define AGP_MODE_GET_RQ(x) (((x) & 0xff000000U) >> 24) +#define AGP_MODE_GET_ARQSZ(x) (((x) & 0x0000e000U) >> 13) +#define AGP_MODE_GET_CAL(x) (((x) & 0x00001c00U) >> 10) +#define AGP_MODE_GET_SBA(x) (((x) & 0x00000200U) >> 9) +#define AGP_MODE_GET_AGP(x) (((x) & 0x00000100U) >> 8) +#define AGP_MODE_GET_GART_64(x) (((x) & 0x00000080U) >> 7) +#define AGP_MODE_GET_OVER_4G(x) (((x) & 0x00000020U) >> 5) +#define AGP_MODE_GET_FW(x) (((x) & 0x00000010U) >> 4) +#define AGP_MODE_GET_MODE_3(x) (((x) & 0x00000008U) >> 3) +#define AGP_MODE_GET_RATE(x) ((x) & 0x00000007U) +#define AGP_MODE_SET_RQ(x,v) (((x) & ~0xff000000U) | ((v) << 24)) +#define AGP_MODE_SET_ARQSZ(x,v) (((x) & ~0x0000e000U) | ((v) << 13)) +#define AGP_MODE_SET_CAL(x,v) (((x) & ~0x00001c00U) | ((v) << 10)) +#define AGP_MODE_SET_SBA(x,v) (((x) & ~0x00000200U) | ((v) << 9)) +#define AGP_MODE_SET_AGP(x,v) (((x) & ~0x00000100U) | ((v) << 8)) +#define AGP_MODE_SET_GART_64(x,v) (((x) & ~0x00000080U) | ((v) << 7)) +#define AGP_MODE_SET_OVER_4G(x,v) (((x) & ~0x00000020U) | ((v) << 5)) +#define AGP_MODE_SET_FW(x,v) (((x) & ~0x00000010U) | ((v) << 4)) +#define AGP_MODE_SET_MODE_3(x,v) (((x) & ~0x00000008U) | ((v) << 3)) +#define AGP_MODE_SET_RATE(x,v) (((x) & ~0x00000007U) | (v)) +#define AGP_MODE_V2_RATE_1x 0x00000001 +#define AGP_MODE_V2_RATE_2x 0x00000002 +#define AGP_MODE_V2_RATE_4x 0x00000004 +#define AGP_MODE_V3_RATE_4x 0x00000001 +#define AGP_MODE_V3_RATE_8x 0x00000002 +#define AGP_MODE_V3_RATE_RSVD 0x00000004 + +/* XXX: Compat */ +#define AGP_MODE_GET_4G(x) AGP_MODE_GET_OVER_4G(x) +#define AGP_MODE_SET_4G(x) AGP_MODE_SET_OVER_4G(x) +#define AGP_MODE_RATE_1x AGP_MODE_V2_RATE_1x +#define AGP_MODE_RATE_2x AGP_MODE_V2_RATE_2x +#define AGP_MODE_RATE_4x AGP_MODE_V2_RATE_4x + +#define AGPIOC_BASE 'A' +#define AGPIOC_INFO _IOR (AGPIOC_BASE, 0, agp_info) +#define AGPIOC_ACQUIRE _IO (AGPIOC_BASE, 1) +#define AGPIOC_RELEASE _IO (AGPIOC_BASE, 2) +#define AGPIOC_SETUP _IOW (AGPIOC_BASE, 3, agp_setup) +#if 0 +#define AGPIOC_RESERVE _IOW (AGPIOC_BASE, 4, agp_region) +#define AGPIOC_PROTECT _IOW (AGPIOC_BASE, 5, agp_region) +#endif +#define AGPIOC_ALLOCATE _IOWR(AGPIOC_BASE, 6, agp_allocate) +#define AGPIOC_DEALLOCATE _IOW (AGPIOC_BASE, 7, int) +#define AGPIOC_BIND _IOW (AGPIOC_BASE, 8, agp_bind) +#define AGPIOC_UNBIND _IOW (AGPIOC_BASE, 9, agp_unbind) + +typedef struct _agp_version { + u_int16_t major; + u_int16_t minor; +} agp_version; + +typedef struct _agp_info { + agp_version version; /* version of the driver */ + u_int32_t bridge_id; /* bridge vendor/device */ + u_int32_t agp_mode; /* mode info of bridge */ + off_t aper_base; /* base of aperture */ + size_t aper_size; /* size of aperture */ + size_t pg_total; /* max pages (swap + system) */ + size_t pg_system; /* max pages (system) */ + size_t pg_used; /* current pages used */ +} agp_info; + +typedef struct _agp_setup { + u_int32_t agp_mode; /* mode info of bridge */ +} agp_setup; + +#if 0 +/* + * The "prot" down below needs still a "sleep" flag somehow ... + */ +typedef struct _agp_segment { + off_t pg_start; /* starting page to populate */ + size_t pg_count; /* number of pages */ + int prot; /* prot flags for mmap */ +} agp_segment; + +typedef struct _agp_region { + pid_t pid; /* pid of process */ + size_t seg_count; /* number of segments */ + struct _agp_segment *seg_list; +} agp_region; +#endif + +typedef struct _agp_allocate { + int key; /* tag of allocation */ + size_t pg_count; /* number of pages */ + u_int32_t type; /* 0 == normal, other devspec */ + u_int32_t physical; /* device specific (some devices + * need a phys address of the + * actual page behind the gatt + * table) */ +} agp_allocate; + +typedef struct _agp_bind { + int key; /* tag of allocation */ + off_t pg_start; /* starting page to populate */ +} agp_bind; + +typedef struct _agp_unbind { + int key; /* tag of allocation */ + u_int32_t priority; /* priority for paging out */ +} agp_unbind; + +#endif /* !_SYS_AGPIO_H_ */ diff --git a/src/include/sys/aio.h b/src/include/sys/aio.h new file mode 100644 index 0000000..f311e3c --- /dev/null +++ b/src/include/sys/aio.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 1997 John S. Dyson. 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. John S. Dyson's name may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * DISCLAIMER: This code isn't warranted to do anything useful. Anything + * bad that happens because of using this software isn't the responsibility + * of the author. This software is distributed AS-IS. + * + * $FreeBSD: src/sys/sys/aio.h,v 1.29 2002/01/06 21:03:39 alc Exp $ + */ + +#ifndef _SYS_AIO_H_ +#define _SYS_AIO_H_ + +#include +#include +#include + +/* + * Returned by aio_cancel: + */ +#define AIO_CANCELED 0x1 +#define AIO_NOTCANCELED 0x2 +#define AIO_ALLDONE 0x3 + +/* + * LIO opcodes + */ +#define LIO_NOP 0x0 +#define LIO_WRITE 0x1 +#define LIO_READ 0x2 + +/* + * LIO modes + */ +#define LIO_NOWAIT 0x0 +#define LIO_WAIT 0x1 + +/* + * Maximum number of allowed LIO operations + */ +#define AIO_LISTIO_MAX 16 + +/* + * Private members for aiocb -- don't access + * directly. + */ +struct __aiocb_private { + long status; + long error; + void *kernelinfo; +}; + +/* + * I/O control block + */ +typedef struct aiocb { + int aio_fildes; /* File descriptor */ + off_t aio_offset; /* File offset for I/O */ + volatile void *aio_buf; /* I/O buffer in process space */ + size_t aio_nbytes; /* Number of bytes for I/O */ + struct sigevent aio_sigevent; /* Signal to deliver */ + int aio_lio_opcode; /* LIO opcode */ + int aio_reqprio; /* Request priority -- ignored */ + struct __aiocb_private _aiocb_private; +} aiocb_t; + +#ifndef _KERNEL + +__BEGIN_DECLS +/* + * Asynchronously read from a file + */ +int aio_read(struct aiocb *); + +/* + * Asynchronously write to file + */ +int aio_write(struct aiocb *); + +/* + * List I/O Asynchronously/synchronously read/write to/from file + * "lio_mode" specifies whether or not the I/O is synchronous. + * "acb_list" is an array of "nacb_listent" I/O control blocks. + * when all I/Os are complete, the optional signal "sig" is sent. + */ +int lio_listio(int, struct aiocb * const [], int, struct sigevent *); + +/* + * Get completion status + * returns EINPROGRESS until I/O is complete. + * this routine does not block. + */ +int aio_error(const struct aiocb *); + +/* + * Finish up I/O, releasing I/O resources and returns the value + * that would have been associated with a synchronous I/O request. + * This routine must be called once and only once for each + * I/O control block who has had I/O associated with it. + */ +ssize_t aio_return(struct aiocb *); + +/* + * Cancel I/O + */ +int aio_cancel(int, struct aiocb *); + +/* + * Suspend until all specified I/O or timeout is complete. + */ +int aio_suspend(const struct aiocb * const[], int, const struct timespec *); + +int aio_waitcomplete(struct aiocb **, struct timespec *); + +__END_DECLS + +#else + +/* Forward declarations for prototypes below. */ +struct socket; +struct sockbuf; + +extern void (*aio_swake)(struct socket *, struct sockbuf *); + +#endif + +#endif diff --git a/src/include/sys/alq.h b/src/include/sys/alq.h new file mode 100644 index 0000000..78afc1d --- /dev/null +++ b/src/include/sys/alq.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2002, Jeffrey Roberson + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/alq.h,v 1.4 2003/06/22 22:28:55 rwatson Exp $ + * + */ +#ifndef _SYS_ALQ_H_ +#define _SYS_ALQ_H_ + +/* + * Opaque type for the Async. Logging Queue + */ +struct alq; + +/* The thread for the logging daemon */ +extern struct thread *ald_thread; + +/* + * Async. Logging Entry + */ +struct ale { + struct ale *ae_next; /* Next Entry */ + char *ae_data; /* Entry buffer */ + int ae_flags; /* Entry flags */ +}; + +#define AE_VALID 0x0001 /* Entry has valid data */ + + +/* waitok options */ +#define ALQ_NOWAIT 0x0001 +#define ALQ_WAITOK 0x0002 + +/* + * alq_open: Creates a new queue + * + * Arguments: + * alq Storage for a pointer to the newly created queue. + * file The filename to open for logging. + * size The size of each entry in the queue. + * count The number of items in the buffer, this should be large enough + * to store items over the period of a disk write. + * Returns: + * error from open or 0 on success + */ +struct ucred; +int alq_open(struct alq **, const char *file, struct ucred *cred, int size, + int count); + +/* + * alq_write: Write data into the queue + * + * Arguments: + * alq The queue we're writing to + * data The entry to be recorded + * waitok Are we permitted to wait? + * + * Returns: + * EWOULDBLOCK if: + * Waitok is ALQ_NOWAIT and the queue is full. + * The system is shutting down. + * 0 on success. + */ +int alq_write(struct alq *alq, void *data, int waitok); + +/* + * alq_flush: Flush the queue out to disk + */ +void alq_flush(struct alq *alq); + +/* + * alq_close: Flush the queue and free all resources. + */ +void alq_close(struct alq *alq); + +/* + * alq_get: Return an entry for direct access + * + * Arguments: + * alq The queue to retrieve an entry from + * waitok Are we permitted to wait? + * + * Returns: + * The next available ale on success. + * NULL if: + * Waitok is ALQ_NOWAIT and the queue is full. + * The system is shutting down. + * + * This leaves the queue locked until a subsequent alq_post. + */ +struct ale *alq_get(struct alq *alq, int waitok); + +/* + * alq_post: Schedule the ale retrieved by alq_get for writing. + * alq The queue to post the entry to. + * ale An asynch logging entry returned by alq_get. + */ +void alq_post(struct alq *, struct ale *); + +#endif /* _SYS_ALQ_H_ */ diff --git a/src/include/sys/assym.h b/src/include/sys/assym.h new file mode 100644 index 0000000..c9dc097 --- /dev/null +++ b/src/include/sys/assym.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 1999 Marcel Moolenaar + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/assym.h,v 1.5 2004/03/12 21:45:32 trhodes Exp $ + */ + +#ifndef _SYS_ASSYM_H_ +#define _SYS_ASSYM_H_ + +#define ASSYM_BIAS 0x10000 /* avoid zero-length arrays */ +#define ASSYM_ABS(value) ((value) < 0 ? -((value) + 1) + 1ULL : (value)) + +#define ASSYM(name, value) \ +char name ## sign[((value) < 0 ? 1 : 0) + ASSYM_BIAS]; \ +char name ## w0[(ASSYM_ABS(value) & 0xFFFFU) + ASSYM_BIAS]; \ +char name ## w1[((ASSYM_ABS(value) & 0xFFFF0000UL) >> 16) + ASSYM_BIAS]; \ +char name ## w2[((ASSYM_ABS(value) & 0xFFFF00000000ULL) >> 32) + ASSYM_BIAS]; \ +char name ## w3[((ASSYM_ABS(value) & 0xFFFF000000000000ULL) >> 48) + ASSYM_BIAS] + +#endif /* !_SYS_ASSYM_H_ */ diff --git a/src/include/sys/ata.h b/src/include/sys/ata.h new file mode 100644 index 0000000..8e6d165 --- /dev/null +++ b/src/include/sys/ata.h @@ -0,0 +1,409 @@ +/*- + * Copyright (c) 2000 - 2004 S�ren Schmidt + * 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, + * without modification, immediately at the beginning of the file. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/ata.h,v 1.22 2004/03/15 13:17:24 sos Exp $ + */ + +#ifndef _SYS_ATA_H_ +#define _SYS_ATA_H_ + +#include + +/* ATA/ATAPI device parameters */ +struct ata_params { +/*000*/ u_int16_t config; /* configuration info */ +#define ATA_PROTO_MASK 0x8003 +#define ATA_PROTO_ATA 0x0002 +#define ATA_PROTO_ATAPI_12 0x8000 +#define ATA_PROTO_ATAPI_16 0x8001 +#define ATA_ATAPI_TYPE_MASK 0x1f00 +#define ATA_ATAPI_TYPE_DIRECT 0x0000 /* disk/floppy */ +#define ATA_ATAPI_TYPE_TAPE 0x0100 /* streaming tape */ +#define ATA_ATAPI_TYPE_CDROM 0x0500 /* CD-ROM device */ +#define ATA_ATAPI_TYPE_OPTICAL 0x0700 /* optical disk */ +#define ATA_DRQ_MASK 0x0060 +#define ATA_DRQ_SLOW 0x0000 /* cpu 3 ms delay */ +#define ATA_DRQ_INTR 0x0020 /* interrupt 10 ms delay */ +#define ATA_DRQ_FAST 0x0040 /* accel 50 us delay */ + +/*001*/ u_int16_t cylinders; /* # of cylinders */ + u_int16_t reserved2; +/*003*/ u_int16_t heads; /* # heads */ + u_int16_t obsolete4; + u_int16_t obsolete5; +/*006*/ u_int16_t sectors; /* # sectors/track */ +/*007*/ u_int16_t vendor7[3]; +/*010*/ u_int8_t serial[20]; /* serial number */ +/*020*/ u_int16_t retired20; + u_int16_t retired21; + u_int16_t obsolete22; +/*023*/ u_int8_t revision[8]; /* firmware revision */ +/*027*/ u_int8_t model[40]; /* model name */ +/*047*/ u_int16_t sectors_intr; /* sectors per interrupt */ +/*048*/ u_int16_t usedmovsd; /* double word read/write? */ +/*049*/ u_int16_t capabilities1; +#define ATA_SUPPORT_DMA 0x0100 +#define ATA_SUPPORT_LBA 0x0200 +#define ATA_SUPPORT_OVERLAP 0x4000 + +/*050*/ u_int16_t capabilities2; +/*051*/ u_int16_t retired_piomode; /* PIO modes 0-2 */ +#define ATA_RETIRED_PIO_MASK 0x0300 + +/*052*/ u_int16_t retired_dmamode; /* DMA modes */ +#define ATA_RETIRED_DMA_MASK 0x0003 + +/*053*/ u_int16_t atavalid; /* fields valid */ +#define ATA_FLAG_54_58 0x0001 /* words 54-58 valid */ +#define ATA_FLAG_64_70 0x0002 /* words 64-70 valid */ +#define ATA_FLAG_88 0x0004 /* word 88 valid */ + +/*054*/ u_int16_t obsolete54[5]; +/*059*/ u_int16_t multi; +#define ATA_MULTI_VALID 0x0100 + +/*060*/ u_int16_t lba_size_1; + u_int16_t lba_size_2; + u_int16_t obsolete62; +/*063*/ u_int16_t mwdmamodes; /* multiword DMA modes */ +/*064*/ u_int16_t apiomodes; /* advanced PIO modes */ + +/*065*/ u_int16_t mwdmamin; /* min. M/W DMA time/word ns */ +/*066*/ u_int16_t mwdmarec; /* rec. M/W DMA time ns */ +/*067*/ u_int16_t pioblind; /* min. PIO cycle w/o flow */ +/*068*/ u_int16_t pioiordy; /* min. PIO cycle IORDY flow */ + u_int16_t reserved69; + u_int16_t reserved70; +/*071*/ u_int16_t rlsovlap; /* rel time (us) for overlap */ +/*072*/ u_int16_t rlsservice; /* rel time (us) for service */ + u_int16_t reserved73; + u_int16_t reserved74; +/*075*/ u_int16_t queue; +#define ATA_QUEUE_LEN(x) ((x) & 0x001f) + + u_int16_t satacapabilities; +#define ATA_SATA_GEN1 0x0002 +#define ATA_SATA_GEN2 0x0004 +#define ATA_SUPPORT_NCQ 0x0100 +#define ATA_SUPPORT_IFPWRMNGTRCV 0x0200 + + u_int16_t reserved77; + u_int16_t satasupport; +#define ATA_SUPPORT_NONZERO 0x0002 +#define ATA_SUPPORT_AUTOACTIVATE 0x0004 +#define ATA_SUPPORT_IFPWRMNGT 0x0008 +#define ATA_SUPPORT_INORDERDATA 0x0010 + u_int16_t sataenabled; + +/*080*/ u_int16_t version_major; +/*081*/ u_int16_t version_minor; + + struct { +/*082/085*/ u_int16_t command1; +#define ATA_SUPPORT_SMART 0x0001 +#define ATA_SUPPORT_SECURITY 0x0002 +#define ATA_SUPPORT_REMOVABLE 0x0004 +#define ATA_SUPPORT_POWERMGT 0x0008 +#define ATA_SUPPORT_PACKET 0x0010 +#define ATA_SUPPORT_WRITECACHE 0x0020 +#define ATA_SUPPORT_LOOKAHEAD 0x0040 +#define ATA_SUPPORT_RELEASEIRQ 0x0080 +#define ATA_SUPPORT_SERVICEIRQ 0x0100 +#define ATA_SUPPORT_RESET 0x0200 +#define ATA_SUPPORT_PROTECTED 0x0400 +#define ATA_SUPPORT_WRITEBUFFER 0x1000 +#define ATA_SUPPORT_READBUFFER 0x2000 +#define ATA_SUPPORT_NOP 0x4000 + +/*083/086*/ u_int16_t command2; +#define ATA_SUPPORT_MICROCODE 0x0001 +#define ATA_SUPPORT_QUEUED 0x0002 +#define ATA_SUPPORT_CFA 0x0004 +#define ATA_SUPPORT_APM 0x0008 +#define ATA_SUPPORT_NOTIFY 0x0010 +#define ATA_SUPPORT_STANDBY 0x0020 +#define ATA_SUPPORT_SPINUP 0x0040 +#define ATA_SUPPORT_MAXSECURITY 0x0100 +#define ATA_SUPPORT_AUTOACOUSTIC 0x0200 +#define ATA_SUPPORT_ADDRESS48 0x0400 +#define ATA_SUPPORT_OVERLAY 0x0800 +#define ATA_SUPPORT_FLUSHCACHE 0x1000 +#define ATA_SUPPORT_FLUSHCACHE48 0x2000 + +/*084/087*/ u_int16_t extension; + } support, enabled; + +/*088*/ u_int16_t udmamodes; /* UltraDMA modes */ +/*089*/ u_int16_t erase_time; +/*090*/ u_int16_t enhanced_erase_time; +/*091*/ u_int16_t apm_value; +/*092*/ u_int16_t master_passwd_revision; +/*093*/ u_int16_t hwres; +#define ATA_CABLE_ID 0x2000 + +/*094*/ u_int16_t acoustic; +#define ATA_ACOUSTIC_CURRENT(x) ((x) & 0x00ff) +#define ATA_ACOUSTIC_VENDOR(x) (((x) & 0xff00) >> 8) + +/*095*/ u_int16_t stream_min_req_size; +/*096*/ u_int16_t stream_transfer_time; +/*097*/ u_int16_t stream_access_latency; +/*098*/ u_int32_t stream_granularity; +/*100*/ u_int16_t lba_size48_1; + u_int16_t lba_size48_2; + u_int16_t lba_size48_3; + u_int16_t lba_size48_4; + u_int16_t reserved104[23]; +/*127*/ u_int16_t removable_status; +/*128*/ u_int16_t security_status; + u_int16_t reserved129[31]; +/*160*/ u_int16_t cfa_powermode1; + u_int16_t reserved161[14]; +/*176*/ u_int16_t media_serial[30]; + u_int16_t reserved206[49]; +/*255*/ u_int16_t integrity; +}; + +/* ATA transfer modes */ +#define ATA_MODE_MASK 0x0f +#define ATA_DMA_MASK 0xf0 +#define ATA_PIO 0x00 +#define ATA_PIO0 0x08 +#define ATA_PIO1 0x09 +#define ATA_PIO2 0x0a +#define ATA_PIO3 0x0b +#define ATA_PIO4 0x0c +#define ATA_PIO_MAX 0x0f +#define ATA_DMA 0x10 +#define ATA_WDMA0 0x20 +#define ATA_WDMA1 0x21 +#define ATA_WDMA2 0x22 +#define ATA_UDMA0 0x40 +#define ATA_UDMA1 0x41 +#define ATA_UDMA2 0x42 +#define ATA_UDMA3 0x43 +#define ATA_UDMA4 0x44 +#define ATA_UDMA5 0x45 +#define ATA_UDMA6 0x46 +#define ATA_SA150 0x47 +#define ATA_DMA_MAX 0x4f + +/* ATA commands */ +#define ATA_NOP 0x00 /* NOP command */ +#define ATA_NF_FLUSHQUEUE 0x00 /* flush queued cmd's */ +#define ATA_NF_AUTOPOLL 0x01 /* start autopoll function */ +#define ATA_ATAPI_RESET 0x08 /* reset ATAPI device */ +#define ATA_READ 0x20 /* read command */ +#define ATA_READ48 0x24 /* read command */ +#define ATA_READ_DMA48 0x25 /* read w/DMA command */ +#define ATA_READ_DMA_QUEUED48 0x26 /* read w/DMA QUEUED command */ +#define ATA_READ_MUL48 0x29 /* read multi command */ +#define ATA_WRITE 0x30 /* write command */ +#define ATA_WRITE48 0x34 /* write command */ +#define ATA_WRITE_DMA48 0x35 /* write w/DMA command */ +#define ATA_WRITE_DMA_QUEUED48 0x36 /* write w/DMA QUEUED command */ +#define ATA_WRITE_MUL48 0x39 /* write multi command */ +#define ATA_PACKET_CMD 0xa0 /* packet command */ +#define ATA_ATAPI_IDENTIFY 0xa1 /* get ATAPI params*/ +#define ATA_SERVICE 0xa2 /* service command */ +#define ATA_READ_MUL 0xc4 /* read multi command */ +#define ATA_WRITE_MUL 0xc5 /* write multi command */ +#define ATA_SET_MULTI 0xc6 /* set multi size command */ +#define ATA_READ_DMA_QUEUED 0xc7 /* read w/DMA QUEUED command */ +#define ATA_READ_DMA 0xc8 /* read w/DMA command */ +#define ATA_WRITE_DMA 0xca /* write w/DMA command */ +#define ATA_WRITE_DMA_QUEUED 0xcc /* write w/DMA QUEUED command */ +#define ATA_SLEEP 0xe6 /* sleep command */ +#define ATA_FLUSHCACHE 0xe7 /* flush cache to disk */ +#define ATA_FLUSHCACHE48 0xea /* flush cache to disk */ +#define ATA_ATA_IDENTIFY 0xec /* get ATA params */ +#define ATA_SETFEATURES 0xef /* features command */ +#define ATA_SF_SETXFER 0x03 /* set transfer mode */ +#define ATA_SF_ENAB_WCACHE 0x02 /* enable write cache */ +#define ATA_SF_DIS_WCACHE 0x82 /* disable write cache */ +#define ATA_SF_ENAB_RCACHE 0xaa /* enable readahead cache */ +#define ATA_SF_DIS_RCACHE 0x55 /* disable readahead cache */ +#define ATA_SF_ENAB_RELIRQ 0x5d /* enable release interrupt */ +#define ATA_SF_DIS_RELIRQ 0xdd /* disable release interrupt */ +#define ATA_SF_ENAB_SRVIRQ 0x5e /* enable service interrupt */ +#define ATA_SF_DIS_SRVIRQ 0xde /* disable service interrupt */ + +/* ATAPI commands */ +#define ATAPI_TEST_UNIT_READY 0x00 /* check if device is ready */ +#define ATAPI_REZERO 0x01 /* rewind */ +#define ATAPI_REQUEST_SENSE 0x03 /* get sense data */ +#define ATAPI_FORMAT 0x04 /* format unit */ +#define ATAPI_READ 0x08 /* read data */ +#define ATAPI_WRITE 0x0a /* write data */ +#define ATAPI_WEOF 0x10 /* write filemark */ +#define ATAPI_WF_WRITE 0x01 +#define ATAPI_SPACE 0x11 /* space command */ +#define ATAPI_SP_FM 0x01 +#define ATAPI_SP_EOD 0x03 +#define ATAPI_MODE_SELECT 0x15 /* mode select */ +#define ATAPI_ERASE 0x19 /* erase */ +#define ATAPI_MODE_SENSE 0x1a /* mode sense */ +#define ATAPI_START_STOP 0x1b /* start/stop unit */ +#define ATAPI_SS_LOAD 0x01 +#define ATAPI_SS_RETENSION 0x02 +#define ATAPI_SS_EJECT 0x04 +#define ATAPI_PREVENT_ALLOW 0x1e /* media removal */ +#define ATAPI_READ_FORMAT_CAPACITIES 0x23 /* get format capacities */ +#define ATAPI_READ_CAPACITY 0x25 /* get volume capacity */ +#define ATAPI_READ_BIG 0x28 /* read data */ +#define ATAPI_WRITE_BIG 0x2a /* write data */ +#define ATAPI_LOCATE 0x2b /* locate to position */ +#define ATAPI_READ_POSITION 0x34 /* read position */ +#define ATAPI_SYNCHRONIZE_CACHE 0x35 /* flush buf, close channel */ +#define ATAPI_WRITE_BUFFER 0x3b /* write device buffer */ +#define ATAPI_READ_BUFFER 0x3c /* read device buffer */ +#define ATAPI_READ_SUBCHANNEL 0x42 /* get subchannel info */ +#define ATAPI_READ_TOC 0x43 /* get table of contents */ +#define ATAPI_PLAY_10 0x45 /* play by lba */ +#define ATAPI_PLAY_MSF 0x47 /* play by MSF address */ +#define ATAPI_PLAY_TRACK 0x48 /* play by track number */ +#define ATAPI_PAUSE 0x4b /* pause audio operation */ +#define ATAPI_READ_DISK_INFO 0x51 /* get disk info structure */ +#define ATAPI_READ_TRACK_INFO 0x52 /* get track info structure */ +#define ATAPI_RESERVE_TRACK 0x53 /* reserve track */ +#define ATAPI_SEND_OPC_INFO 0x54 /* send OPC structurek */ +#define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */ +#define ATAPI_REPAIR_TRACK 0x58 /* repair track */ +#define ATAPI_READ_MASTER_CUE 0x59 /* read master CUE info */ +#define ATAPI_MODE_SENSE_BIG 0x5a /* get device parameters */ +#define ATAPI_CLOSE_TRACK 0x5b /* close track/session */ +#define ATAPI_READ_BUFFER_CAPACITY 0x5c /* get buffer capicity */ +#define ATAPI_SEND_CUE_SHEET 0x5d /* send CUE sheet */ +#define ATAPI_BLANK 0xa1 /* blank the media */ +#define ATAPI_SEND_KEY 0xa3 /* send DVD key structure */ +#define ATAPI_REPORT_KEY 0xa4 /* get DVD key structure */ +#define ATAPI_PLAY_12 0xa5 /* play by lba */ +#define ATAPI_LOAD_UNLOAD 0xa6 /* changer control command */ +#define ATAPI_READ_STRUCTURE 0xad /* get DVD structure */ +#define ATAPI_PLAY_CD 0xb4 /* universal play command */ +#define ATAPI_SET_SPEED 0xbb /* set drive speed */ +#define ATAPI_MECH_STATUS 0xbd /* get changer status */ +#define ATAPI_READ_CD 0xbe /* read data */ +#define ATAPI_POLL_DSC 0xff /* poll DSC status bit */ + +struct ata_cmd { + int channel; + int device; + int cmd; +#define ATAGMAXCHANNEL 0x0101 +#define ATAGPARM 0x0102 +#define ATAGMODE 0x0103 +#define ATASMODE 0x0104 +#define ATAREQUEST 0x0108 +#define ATAREINIT 0x0110 +#define ATAATTACH 0x0111 +#define ATADETACH 0x0112 +#define ATARAIDCREATE 0x0120 +#define ATARAIDDELETE 0x0121 +#define ATARAIDSTATUS 0x0122 +#define ATARAIDADDSPARE 0x0123 +#define ATARAIDREBUILD 0x0124 +#define ATAENCSTAT 0x0130 + + union { + int maxchan; + + struct { + int type[2]; + char name[2][32]; + struct ata_params params[2]; + } param; + + struct { + int mode[2]; + } mode; + + struct { + union { + struct { + u_int8_t command; + u_int8_t feature; + u_int64_t lba; + u_int16_t count; + } ata; + struct { + char ccb[16]; + } atapi; + } u; + caddr_t data; + int count; + int flags; +#define ATA_CMD_CONTROL 0x01 +#define ATA_CMD_READ 0x02 +#define ATA_CMD_WRITE 0x04 +#define ATA_CMD_ATAPI 0x08 + + int timeout; + int error; + } request; + + struct raid_setup { + int type; +#define AR_RAID0 1 +#define AR_RAID1 2 +#define AR_SPAN 4 + + int total_disks; + int disks[16]; + int interleave; + int unit; + } raid_setup; + + struct raid_status { + int type; + int total_disks; + int disks[16]; + int interleave; + int status; +#define AR_READY 1 +#define AR_DEGRADED 2 +#define AR_REBUILDING 4 + + int progress; + } raid_status; + + struct { + int disk; + } raid_spare; + + struct { + int fan; + int temp; + int v05; + int v12; + } enclosure; + } u; +}; + +#define IOCATA _IOWR('a', 1, struct ata_cmd) + +#endif /* _SYS_ATA_H_ */ diff --git a/src/include/sys/bio.h b/src/include/sys/bio.h new file mode 100644 index 0000000..db8c91a --- /dev/null +++ b/src/include/sys/bio.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)buf.h 8.9 (Berkeley) 3/30/95 + * $FreeBSD: src/sys/sys/bio.h,v 1.137 2004/04/07 04:19:48 imp Exp $ + */ + +#ifndef _SYS_BIO_H_ +#define _SYS_BIO_H_ + +#include + +struct disk; +struct bio; + +typedef void bio_task_t(void *); + +/* + * The bio structure describes an I/O operation in the kernel. + */ +struct bio { + u_int bio_cmd; /* I/O operation. */ + dev_t bio_dev; /* Device to do I/O on. */ + struct disk *bio_disk; /* Valid below geom_disk.c only */ + off_t bio_offset; /* Offset into file. */ + long bio_bcount; /* Valid bytes in buffer. */ + caddr_t bio_data; /* Memory, superblocks, indirect etc. */ + u_int bio_flags; /* BIO_ flags. */ + int bio_error; /* Errno for BIO_ERROR. */ + long bio_resid; /* Remaining I/0 in bytes. */ + void (*bio_done)(struct bio *); + void *bio_driver1; /* Private use by the callee. */ + void *bio_driver2; /* Private use by the callee. */ + void *bio_caller1; /* Private use by the caller. */ + void *bio_caller2; /* Private use by the caller. */ + TAILQ_ENTRY(bio) bio_queue; /* Disksort queue. */ + const char *bio_attribute; /* Attribute for BIO_[GS]ETATTR */ + struct g_consumer *bio_from; /* GEOM linkage */ + struct g_provider *bio_to; /* GEOM linkage */ + off_t bio_length; /* Like bio_bcount */ + off_t bio_completed; /* Inverse of bio_resid */ + u_int bio_children; /* Number of spawned bios */ + u_int bio_inbed; /* Children safely home by now */ + struct bio *bio_parent; /* Pointer to parent */ + struct bintime bio_t0; /* Time request started */ + + bio_task_t *bio_task; /* Task_queue handler */ + void *bio_task_arg; /* Argument to above */ + + /* XXX: these go away when bio chaining is introduced */ + daddr_t bio_pblkno; /* physical block number */ +}; + +/* bio_cmd */ +#define BIO_READ 0x00000001 +#define BIO_WRITE 0x00000002 +#define BIO_DELETE 0x00000004 +#define BIO_GETATTR 0x00000008 +#define BIO_CMD1 0x40000000 /* Available for local hacks */ +#define BIO_CMD2 0x80000000 /* Available for local hacks */ + +/* bio_flags */ +#define BIO_ERROR 0x00000001 +#define BIO_DONE 0x00000004 +#define BIO_FLAG2 0x40000000 /* Available for local hacks */ +#define BIO_FLAG1 0x80000000 /* Available for local hacks */ + +#ifdef _KERNEL + +struct uio; +struct devstat; + +struct bio_queue_head { + TAILQ_HEAD(bio_queue, bio) queue; + off_t last_offset; + struct bio *insert_point; + struct bio *switch_point; +}; + +void biodone(struct bio *bp); +void biofinish(struct bio *bp, struct devstat *stat, int error); +int biowait(struct bio *bp, const char *wchan); + +void bioq_disksort(struct bio_queue_head *ap, struct bio *bp); +struct bio *bioq_first(struct bio_queue_head *head); +void bioq_flush(struct bio_queue_head *head, struct devstat *stp, int error); +void bioq_init(struct bio_queue_head *head); +void bioq_insert_tail(struct bio_queue_head *head, struct bio *bp); +void bioq_remove(struct bio_queue_head *head, struct bio *bp); + +void bio_taskqueue(struct bio *bp, bio_task_t *fund, void *arg); + +int physio(dev_t dev, struct uio *uio, int ioflag); +#define physread physio +#define physwrite physio + +#endif /* _KERNEL */ + +#endif /* !_SYS_BIO_H_ */ diff --git a/src/include/sys/bitstring.h b/src/include/sys/bitstring.h new file mode 100644 index 0000000..e18fdab --- /dev/null +++ b/src/include/sys/bitstring.h @@ -0,0 +1,146 @@ +/* + * 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. + * 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. + * + * $FreeBSD: src/sys/sys/bitstring.h,v 1.4 2004/04/07 04:19:48 imp Exp $ + */ + +#ifndef _SYS_BITSTRING_H_ +#define _SYS_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) + 7) >> 3) + + /* allocate a bitstring */ +#define bit_alloc(nbits) \ + (bitstr_t *)calloc((size_t)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) do { \ + 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); \ + } \ +} while (0) + + /* set bits start ... stop in bitstring */ +#define bit_nset(name, start, stop) do { \ + 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)); \ + } \ +} while (0) + + /* find first bit clear in name */ +#define bit_ffc(name, nbits, value) do { \ + register bitstr_t *_name = (name); \ + register int _byte, _nbits = (nbits); \ + register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \ + if (_nbits > 0) \ + for (_byte = 0; _byte <= _stopbyte; ++_byte) \ + if (_name[_byte] != 0xff) { \ + bitstr_t _lb; \ + _value = _byte << 3; \ + for (_lb = _name[_byte]; (_lb&0x1); \ + ++_value, _lb >>= 1); \ + break; \ + } \ + if (_value >= nbits) \ + _value = -1; \ + *(value) = _value; \ +} while (0) + + /* find first bit set in name */ +#define bit_ffs(name, nbits, value) do { \ + register bitstr_t *_name = (name); \ + register int _byte, _nbits = (nbits); \ + register int _stopbyte = _bit_byte(_nbits - 1), _value = -1; \ + if (_nbits > 0) \ + for (_byte = 0; _byte <= _stopbyte; ++_byte) \ + if (_name[_byte]) { \ + bitstr_t _lb; \ + _value = _byte << 3; \ + for (_lb = _name[_byte]; !(_lb&0x1); \ + ++_value, _lb >>= 1); \ + break; \ + } \ + if (_value >= nbits) \ + _value = -1; \ + *(value) = _value; \ +} while (0) + +#endif /* !_SYS_BITSTRING_H_ */ diff --git a/src/include/sys/blist.h b/src/include/sys/blist.h new file mode 100644 index 0000000..52e3041 --- /dev/null +++ b/src/include/sys/blist.h @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 1998 Matthew Dillon. 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. + * 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 AUTHOR ``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 AUTHOR 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. + * + * Implements bitmap resource lists. + * + * Usage: + * blist = blist_create(blocks) + * (void) blist_destroy(blist) + * blkno = blist_alloc(blist, count) + * (void) blist_free(blist, blkno, count) + * nblks = blist_fill(blist, blkno, count) + * (void) blist_resize(&blist, count, freeextra) + * + * + * Notes: + * on creation, the entire list is marked reserved. You should + * first blist_free() the sections you want to make available + * for allocation before doing general blist_alloc()/free() + * ops. + * + * SWAPBLK_NONE is returned on failure. This module is typically + * capable of managing up to (2^31) blocks per blist, though + * the memory utilization would be insane if you actually did + * that. Managing something like 512MB worth of 4K blocks + * eats around 32 KBytes of memory. + * + * $FreeBSD: src/sys/sys/blist.h,v 1.7 2003/08/12 23:24:05 imp Exp $ + */ + +#ifndef _SYS_BLIST_H_ +#define _SYS_BLIST_H_ + +typedef u_int32_t u_daddr_t; /* unsigned disk address */ + +/* + * blmeta and bl_bitmap_t MUST be a power of 2 in size. + */ + +typedef struct blmeta { + union { + daddr_t bmu_avail; /* space available under us */ + u_daddr_t bmu_bitmap; /* bitmap if we are a leaf */ + } u; + daddr_t bm_bighint; /* biggest contiguous block hint*/ +} blmeta_t; + +typedef struct blist { + daddr_t bl_blocks; /* area of coverage */ + daddr_t bl_radix; /* coverage radix */ + daddr_t bl_skip; /* starting skip */ + daddr_t bl_free; /* number of free blocks */ + blmeta_t *bl_root; /* root of radix tree */ + daddr_t bl_rootblks; /* daddr_t blks allocated for tree */ +} *blist_t; + +#define BLIST_META_RADIX 16 +#define BLIST_BMAP_RADIX (sizeof(u_daddr_t)*8) + +#define BLIST_MAX_ALLOC BLIST_BMAP_RADIX + +extern blist_t blist_create(daddr_t blocks); +extern void blist_destroy(blist_t blist); +extern daddr_t blist_alloc(blist_t blist, daddr_t count); +extern void blist_free(blist_t blist, daddr_t blkno, daddr_t count); +extern int blist_fill(blist_t bl, daddr_t blkno, daddr_t count); +extern void blist_print(blist_t blist); +extern void blist_resize(blist_t *pblist, daddr_t count, int freenew); + +#endif /* _SYS_BLIST_H_ */ + diff --git a/src/include/sys/buf.h b/src/include/sys/buf.h new file mode 100644 index 0000000..0615432 --- /dev/null +++ b/src/include/sys/buf.h @@ -0,0 +1,531 @@ +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)buf.h 8.9 (Berkeley) 3/30/95 + * $FreeBSD: src/sys/sys/buf.h,v 1.166 2004/04/07 04:19:48 imp Exp $ + */ + +#ifndef _SYS_BUF_H_ +#define _SYS_BUF_H_ + +#include +#include +#include + +struct bio; +struct buf; +struct mount; +struct vnode; + +/* + * To avoid including + */ +LIST_HEAD(workhead, worklist); +/* + * These are currently used only by the soft dependency code, hence + * are stored once in a global variable. If other subsystems wanted + * to use these hooks, a pointer to a set of bio_ops could be added + * to each buffer. + */ +extern struct bio_ops { + int (*io_prewrite)(struct vnode *, struct buf *); + void (*io_start)(struct buf *); + void (*io_complete)(struct buf *); + void (*io_deallocate)(struct buf *); + void (*io_movedeps)(struct buf *, struct buf *); + int (*io_countdeps)(struct buf *, int); +} bioops; + +struct buf_ops { + char *bop_name; + int (*bop_write)(struct buf *); +}; + +extern struct buf_ops buf_ops_bio; + +struct vm_object; + +typedef unsigned char b_xflags_t; + +/* + * The buffer header describes an I/O operation in the kernel. + * + * NOTES: + * b_bufsize, b_bcount. b_bufsize is the allocation size of the + * buffer, either DEV_BSIZE or PAGE_SIZE aligned. b_bcount is the + * originally requested buffer size and can serve as a bounds check + * against EOF. For most, but not all uses, b_bcount == b_bufsize. + * + * b_dirtyoff, b_dirtyend. Buffers support piecemeal, unaligned + * ranges of dirty data that need to be written to backing store. + * The range is typically clipped at b_bcount ( not b_bufsize ). + * + * b_resid. Number of bytes remaining in I/O. After an I/O operation + * completes, b_resid is usually 0 indicating 100% success. + * + * All fields are protected by the buffer lock except those marked: + * V - Protected by owning vnode lock + * Q - Protected by the buf queue lock + * D - Protected by an dependency implementation specific lock + */ +struct buf { + struct bio b_io; /* "Builtin" I/O request. */ +#define b_bcount b_io.bio_bcount +#define b_caller1 b_io.bio_caller1 +#define b_data b_io.bio_data +#define b_dev b_io.bio_dev +#define b_error b_io.bio_error +#define b_iocmd b_io.bio_cmd +#define b_ioflags b_io.bio_flags +#define b_iooffset b_io.bio_offset +#define b_resid b_io.bio_resid + struct buf_ops *b_op; + unsigned b_magic; +#define B_MAGIC_BIO 0x10b10b10 +#define B_MAGIC_NFS 0x67238234 + void (*b_iodone)(struct buf *); + daddr_t b_blkno; /* Underlying physical block number. */ + off_t b_offset; /* Offset into file. */ + TAILQ_ENTRY(buf) b_vnbufs; /* (V) Buffer's associated vnode. */ + struct buf *b_left; /* (V) splay tree link */ + struct buf *b_right; /* (V) splay tree link */ + uint32_t b_vflags; /* (V) BV_* flags */ + TAILQ_ENTRY(buf) b_freelist; /* (Q) Free list position inactive. */ + unsigned short b_qindex; /* (Q) buffer queue index */ + uint32_t b_flags; /* B_* flags. */ + b_xflags_t b_xflags; /* extra flags */ + struct lock b_lock; /* Buffer lock */ + long b_bufsize; /* Allocated buffer size. */ + long b_runningbufspace; /* when I/O is running, pipelining */ + caddr_t b_kvabase; /* base kva for buffer */ + int b_kvasize; /* size of kva for buffer */ + daddr_t b_lblkno; /* Logical block number. */ + struct vnode *b_vp; /* Device vnode. */ + struct vm_object *b_object; /* Object for vp */ + int b_dirtyoff; /* Offset in buffer of dirty region. */ + int b_dirtyend; /* Offset of end of dirty region. */ + struct ucred *b_rcred; /* Read credentials reference. */ + struct ucred *b_wcred; /* Write credentials reference. */ + void *b_saveaddr; /* Original b_addr for physio. */ + union pager_info { + int pg_reqpage; + } b_pager; + union cluster_info { + TAILQ_HEAD(cluster_list_head, buf) cluster_head; + TAILQ_ENTRY(buf) cluster_entry; + } b_cluster; + struct vm_page *b_pages[btoc(MAXPHYS)]; + int b_npages; + struct workhead b_dep; /* (D) List of filesystem dependencies. */ +}; + +/* + * These flags are kept in b_flags. + * + * Notes: + * + * B_ASYNC VOP calls on bp's are usually async whether or not + * B_ASYNC is set, but some subsystems, such as NFS, like + * to know what is best for the caller so they can + * optimize the I/O. + * + * B_PAGING Indicates that bp is being used by the paging system or + * some paging system and that the bp is not linked into + * the b_vp's clean/dirty linked lists or ref counts. + * Buffer vp reassignments are illegal in this case. + * + * B_CACHE This may only be set if the buffer is entirely valid. + * The situation where B_DELWRI is set and B_CACHE is + * clear MUST be committed to disk by getblk() so + * B_DELWRI can also be cleared. See the comments for + * getblk() in kern/vfs_bio.c. If B_CACHE is clear, + * the caller is expected to clear BIO_ERROR and B_INVAL, + * set BIO_READ, and initiate an I/O. + * + * The 'entire buffer' is defined to be the range from + * 0 through b_bcount. + * + * B_MALLOC Request that the buffer be allocated from the malloc + * pool, DEV_BSIZE aligned instead of PAGE_SIZE aligned. + * + * B_CLUSTEROK This flag is typically set for B_DELWRI buffers + * by filesystems that allow clustering when the buffer + * is fully dirty and indicates that it may be clustered + * with other adjacent dirty buffers. Note the clustering + * may not be used with the stage 1 data write under NFS + * but may be used for the commit rpc portion. + * + * B_VMIO Indicates that the buffer is tied into an VM object. + * The buffer's data is always PAGE_SIZE aligned even + * if b_bufsize and b_bcount are not. ( b_bufsize is + * always at least DEV_BSIZE aligned, though ). + * + * B_DIRECT Hint that we should attempt to completely free + * the pages underlying the buffer. B_DIRECT is + * sticky until the buffer is released and typically + * only has an effect when B_RELBUF is also set. + * + */ + +#define B_AGE 0x00000001 /* Move to age queue when I/O done. */ +#define B_NEEDCOMMIT 0x00000002 /* Append-write in progress. */ +#define B_ASYNC 0x00000004 /* Start I/O, do not wait. */ +#define B_DIRECT 0x00000008 /* direct I/O flag (pls free vmio) */ +#define B_DEFERRED 0x00000010 /* Skipped over for cleaning */ +#define B_CACHE 0x00000020 /* Bread found us in the cache. */ +#define B_VALIDSUSPWRT 0x00000040 /* Valid write during suspension. */ +#define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */ +#define B_00000100 0x00000100 /* Available flag. */ +#define B_DONE 0x00000200 /* I/O completed. */ +#define B_EINTR 0x00000400 /* I/O was interrupted */ +#define B_00000800 0x00000800 /* Available flag. */ +#define B_00001000 0x00001000 /* Available flag. */ +#define B_INVAL 0x00002000 /* Does not contain valid info. */ +#define B_00004000 0x00004000 /* Available flag. */ +#define B_NOCACHE 0x00008000 /* Do not cache block after use. */ +#define B_MALLOC 0x00010000 /* malloced b_data */ +#define B_CLUSTEROK 0x00020000 /* Pagein op, so swap() can count it. */ +#define B_000400000 0x00040000 /* Available flag. */ +#define B_000800000 0x00080000 /* Available flag. */ +#define B_00100000 0x00100000 /* Available flag. */ +#define B_DIRTY 0x00200000 /* Needs writing later (in EXT2FS). */ +#define B_RELBUF 0x00400000 /* Release VMIO buffer. */ +#define B_00800000 0x00800000 /* Available flag. */ +#define B_WRITEINPROG 0x01000000 /* Write in progress. */ +#define B_02000000 0x02000000 /* Available flag. */ +#define B_PAGING 0x04000000 /* volatile paging I/O -- bypass VMIO */ +#define B_08000000 0x08000000 /* Available flag. */ +#define B_RAM 0x10000000 /* Read ahead mark (flag) */ +#define B_VMIO 0x20000000 /* VMIO flag */ +#define B_CLUSTER 0x40000000 /* pagein op, so swap() can count it */ +#define B_80000000 0x80000000 /* Available flag. */ + +#define PRINT_BUF_FLAGS "\20\40b31\37cluster\36vmio\35ram\34b27" \ + "\33paging\32b25\31writeinprog\30b23\27relbuf\26dirty\25b20" \ + "\24b19\23phys\22clusterok\21malloc\20nocache\17locked\16inval" \ + "\15scanned\14nowdrain\13eintr\12done\11b8\10delwri\7validsuspwrt" \ + "\6cache\5deferred\4direct\3async\2needcommit\1age" + +/* + * These flags are kept in b_xflags. + */ +#define BX_VNDIRTY 0x00000001 /* On vnode dirty list */ +#define BX_VNCLEAN 0x00000002 /* On vnode clean list */ +#define BX_BKGRDWRITE 0x00000010 /* Do writes in background */ +#define BX_BKGRDMARKER 0x00000020 /* Mark buffer for splay tree */ +#define BX_ALTDATA 0x00000040 /* Holds extended data */ + +#define NOOFFSET (-1LL) /* No buffer offset calculated yet */ + +/* + * These flags are kept in b_vflags. + */ +#define BV_SCANNED 0x00000001 /* VOP_FSYNC funcs mark written bufs */ +#define BV_BKGRDINPROG 0x00000002 /* Background write in progress */ +#define BV_BKGRDWAIT 0x00000004 /* Background write waiting */ + +#ifdef _KERNEL +/* + * Buffer locking + */ +extern const char *buf_wmesg; /* Default buffer lock message */ +#define BUF_WMESG "bufwait" +#include /* XXX for curthread */ +#include + +/* + * Initialize a lock. + */ +#define BUF_LOCKINIT(bp) \ + lockinit(&(bp)->b_lock, PRIBIO + 4, buf_wmesg, 0, 0) +/* + * + * Get a lock sleeping non-interruptably until it becomes available. + */ +static __inline int BUF_LOCK(struct buf *, int, struct mtx *); +static __inline int +BUF_LOCK(struct buf *bp, int locktype, struct mtx *interlock) +{ + int s, ret; + + s = splbio(); + mtx_lock(bp->b_lock.lk_interlock); + locktype |= LK_INTERNAL; + bp->b_lock.lk_wmesg = buf_wmesg; + bp->b_lock.lk_prio = PRIBIO + 4; + ret = lockmgr(&(bp)->b_lock, locktype, interlock, curthread); + splx(s); + return ret; +} +/* + * Get a lock sleeping with specified interruptably and timeout. + */ +static __inline int BUF_TIMELOCK(struct buf *, int, struct mtx *, + char *, int, int); +static __inline int +BUF_TIMELOCK(struct buf *bp, int locktype, struct mtx *interlock, + char *wmesg, int catch, int timo) +{ + int s, ret; + + s = splbio(); + mtx_lock(bp->b_lock.lk_interlock); + locktype |= LK_INTERNAL | LK_TIMELOCK; + bp->b_lock.lk_wmesg = wmesg; + bp->b_lock.lk_prio = (PRIBIO + 4) | catch; + bp->b_lock.lk_timo = timo; + ret = lockmgr(&(bp)->b_lock, (locktype), interlock, curthread); + splx(s); + return ret; +} +/* + * Release a lock. Only the acquiring process may free the lock unless + * it has been handed off to biodone. + */ +static __inline void BUF_UNLOCK(struct buf *); +static __inline void +BUF_UNLOCK(struct buf *bp) +{ + int s; + + s = splbio(); + lockmgr(&(bp)->b_lock, LK_RELEASE, NULL, curthread); + splx(s); +} + +/* + * Free a buffer lock. + */ +#define BUF_LOCKFREE(bp) \ +do { \ + if (BUF_REFCNT(bp) > 0) \ + panic("free locked buf"); \ + lockdestroy(&(bp)->b_lock); \ +} while (0) + +#ifdef _SYS_PROC_H_ /* Avoid #include pollution */ +/* + * When initiating asynchronous I/O, change ownership of the lock to the + * kernel. Once done, the lock may legally released by biodone. The + * original owning process can no longer acquire it recursively, but must + * wait until the I/O is completed and the lock has been freed by biodone. + */ +static __inline void BUF_KERNPROC(struct buf *); +static __inline void +BUF_KERNPROC(struct buf *bp) +{ + struct thread *td = curthread; + + if ((td != PCPU_GET(idlethread)) + && bp->b_lock.lk_lockholder == td) + td->td_locks--; + bp->b_lock.lk_lockholder = LK_KERNPROC; +} +#endif +/* + * Find out the number of references to a lock. + */ +static __inline int BUF_REFCNT(struct buf *); +static __inline int +BUF_REFCNT(struct buf *bp) +{ + int s, ret; + + /* + * When the system is panicing, the lock manager grants all lock + * requests whether or not the lock is available. To avoid "unlocked + * buffer" panics after a crash, we just claim that all buffers + * are locked when cleaning up after a system panic. + */ + if (panicstr != NULL) + return (1); + s = splbio(); + ret = lockcount(&(bp)->b_lock); + splx(s); + return ret; +} + +#endif /* _KERNEL */ + +struct buf_queue_head { + TAILQ_HEAD(buf_queue, buf) queue; + daddr_t last_pblkno; + struct buf *insert_point; + struct buf *switch_point; +}; + +/* + * This structure describes a clustered I/O. It is stored in the b_saveaddr + * field of the buffer on which I/O is done. At I/O completion, cluster + * callback uses the structure to parcel I/O's to individual buffers, and + * then free's this structure. + */ +struct cluster_save { + long bs_bcount; /* Saved b_bcount. */ + long bs_bufsize; /* Saved b_bufsize. */ + void *bs_saveaddr; /* Saved b_addr. */ + int bs_nchildren; /* Number of associated buffers. */ + struct buf **bs_children; /* List of associated buffers. */ +}; + +#ifdef _KERNEL + + +static __inline int +buf_prewrite(struct vnode *vp, struct buf *bp) +{ + if (bioops.io_prewrite) + return (*bioops.io_prewrite)(vp, bp); + else + return (0); +} + +static __inline void +buf_start(struct buf *bp) +{ + if (bioops.io_start) + (*bioops.io_start)(bp); +} + +static __inline void +buf_complete(struct buf *bp) +{ + if (bioops.io_complete) + (*bioops.io_complete)(bp); +} + +static __inline void +buf_deallocate(struct buf *bp) +{ + if (bioops.io_deallocate) + (*bioops.io_deallocate)(bp); + BUF_LOCKFREE(bp); +} + +static __inline void +buf_movedeps(struct buf *bp, struct buf *bp2) +{ + if (bioops.io_movedeps) + (*bioops.io_movedeps)(bp, bp2); +} + +static __inline int +buf_countdeps(struct buf *bp, int i) +{ + if (bioops.io_countdeps) + return ((*bioops.io_countdeps)(bp, i)); + else + return (0); +} + +#endif /* _KERNEL */ + +/* + * Zero out the buffer's data area. + */ +#define clrbuf(bp) { \ + bzero((bp)->b_data, (u_int)(bp)->b_bcount); \ + (bp)->b_resid = 0; \ +} + +/* + * Flags for getblk's last parameter. + */ +#define GB_LOCK_NOWAIT 0x0001 /* Fail if we block on a buf lock. */ +#define GB_NOCREAT 0x0002 /* Don't create a buf if not found. */ + +#ifdef _KERNEL +extern int nbuf; /* The number of buffer headers */ +extern int maxswzone; /* Max KVA for swap structures */ +extern int maxbcache; /* Max KVA for buffer cache */ +extern int runningbufspace; +extern int buf_maxio; /* nominal maximum I/O for buffer */ +extern struct buf *buf; /* The buffer headers. */ +extern char *buffers; /* The buffer contents. */ +extern int bufpages; /* Number of memory pages in the buffer pool. */ +extern struct buf *swbuf; /* Swap I/O buffer headers. */ +extern int nswbuf; /* Number of swap I/O buffer headers. */ + +struct uio; + +caddr_t kern_vfs_bio_buffer_alloc(caddr_t v, long physmem_est); +void bufinit(void); +void bwillwrite(void); +int buf_dirty_count_severe(void); +void bremfree(struct buf *); +int bread(struct vnode *, daddr_t, int, struct ucred *, struct buf **); +int breadn(struct vnode *, daddr_t, int, daddr_t *, int *, int, + struct ucred *, struct buf **); +int bwrite(struct buf *); +void bdwrite(struct buf *); +void bawrite(struct buf *); +void bdirty(struct buf *); +void bundirty(struct buf *); +void brelse(struct buf *); +void bqrelse(struct buf *); +int vfs_bio_awrite(struct buf *); +struct buf * getpbuf(int *); +struct buf *incore(struct vnode *, daddr_t); +struct buf *gbincore(struct vnode *, daddr_t); +int inmem(struct vnode *, daddr_t); +struct buf *getblk(struct vnode *, daddr_t, int, int, int, int); +struct buf *geteblk(int); +int bufwait(struct buf *); +void bufdone(struct buf *); + +void cluster_callback(struct buf *); +int cluster_read(struct vnode *, u_quad_t, daddr_t, long, + struct ucred *, long, int, struct buf **); +int cluster_wbuild(struct vnode *, long, daddr_t, int); +void cluster_write(struct buf *, u_quad_t, int); +void vfs_bio_set_validclean(struct buf *, int base, int size); +void vfs_bio_clrbuf(struct buf *); +void vfs_busy_pages(struct buf *, int clear_modify); +void vfs_unbusy_pages(struct buf *); +void vwakeup(struct buf *); +int vmapbuf(struct buf *); +void vunmapbuf(struct buf *); +void relpbuf(struct buf *, int *); +void brelvp(struct buf *); +void bgetvp(struct vnode *, struct buf *); +void pbgetvp(struct vnode *, struct buf *); +void pbrelvp(struct buf *); +int allocbuf(struct buf *bp, int size); +void reassignbuf(struct buf *, struct vnode *); +struct buf *trypbuf(int *); +void bwait(struct buf *, u_char, const char *); +void bdone(struct buf *); + +#endif /* _KERNEL */ + +#endif /* !_SYS_BUF_H_ */ diff --git a/src/include/sys/bus.h b/src/include/sys/bus.h new file mode 100644 index 0000000..109e6c1 --- /dev/null +++ b/src/include/sys/bus.h @@ -0,0 +1,473 @@ +/*- + * Copyright (c) 1997,1998,2003 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/bus.h,v 1.58 2004/03/17 17:40:34 njl Exp $ + */ + +#ifndef _SYS_BUS_H_ +#define _SYS_BUS_H_ + +/* + * Interface information structure. + */ +struct u_businfo { + int ub_version; /* interface version */ +#define BUS_USER_VERSION 1 + int ub_generation; /* generation count */ +}; + +/* + * State of the device. + */ +typedef enum device_state { + DS_NOTPRESENT, /* not probed or probe failed */ + DS_ALIVE, /* probe succeeded */ + DS_ATTACHED, /* attach method called */ + DS_BUSY /* device is open */ +} device_state_t; + +/* + * Device information exported to userspace. + */ +struct u_device { + uintptr_t dv_handle; + uintptr_t dv_parent; + + char dv_name[32]; /* Name of device in tree. */ + char dv_desc[32]; /* Driver description */ + char dv_drivername[32]; /* Driver name */ + char dv_pnpinfo[128]; /* Plug and play info */ + char dv_location[128]; /* Where is the device? */ + uint32_t dv_devflags; /* API Flags for device */ + uint16_t dv_flags; /* flags for dev date */ + device_state_t dv_state; /* State of attachment */ + /* XXX more driver info? */ +}; + +#ifdef _KERNEL + +#include +#include + +/* + * devctl hooks. Typically one should use the devctl_notify + * hook to send the message. However, devctl_queue_data is also + * included in case devctl_notify isn't sufficiently general. + */ +void devctl_notify(const char *__system, const char *__subsystem, + const char *__type, const char *__data); +void devctl_queue_data(char *__data); + +/* + * Forward declarations + */ +typedef struct device *device_t; +typedef struct kobj_class driver_t; +typedef struct devclass *devclass_t; +#define device_method_t kobj_method_t + +typedef void driver_intr_t(void*); + +/* + * Interrupt type bits. These flags are used both by newbus interrupt + * registration (nexus.c) and also in struct intrec, which defines + * interrupt properties. + * + * XXX We should probably revisit this and remove the vestiges of the + * spls implicit in names like INTR_TYPE_TTY. In the meantime, don't + * confuse things by renaming them (Grog, 18 July 2000). + * + * We define this in terms of bits because some devices may belong + * to multiple classes (and therefore need to be included in + * multiple interrupt masks, which is what this really serves to + * indicate. Buses which do interrupt remapping will want to + * change their type to reflect what sort of devices are underneath. + */ +enum intr_type { + INTR_TYPE_TTY = 1, + INTR_TYPE_BIO = 2, + INTR_TYPE_NET = 4, + INTR_TYPE_CAM = 8, + INTR_TYPE_MISC = 16, + INTR_TYPE_CLK = 32, + INTR_TYPE_AV = 64, + INTR_FAST = 128, + INTR_EXCL = 256, /* exclusive interrupt */ + INTR_MPSAFE = 512, /* this interrupt is SMP safe */ + INTR_ENTROPY = 1024 /* this interrupt provides entropy */ +}; + +enum intr_trigger { + INTR_TRIGGER_CONFORM = 0, + INTR_TRIGGER_EDGE = 1, + INTR_TRIGGER_LEVEL = 2 +}; + +enum intr_polarity { + INTR_POLARITY_CONFORM = 0, + INTR_POLARITY_HIGH = 1, + INTR_POLARITY_LOW = 2 +}; + +typedef int (*devop_t)(void); + +/* + * This structure is deprecated. Use the kobj(9) macro DEFINE_CLASS to + * declare classes which implement device drivers. + */ +struct driver { + KOBJ_CLASS_FIELDS; +}; + +/* + * Definitions for drivers which need to keep simple lists of resources + * for their child devices. + */ +struct resource; + +struct resource_list_entry { + SLIST_ENTRY(resource_list_entry) link; + int type; /* type argument to alloc_resource */ + int rid; /* resource identifier */ + struct resource *res; /* the real resource when allocated */ + u_long start; /* start of resource range */ + u_long end; /* end of resource range */ + u_long count; /* count within range */ +}; +SLIST_HEAD(resource_list, resource_list_entry); + +/* + * Initialise a resource list. + */ +void resource_list_init(struct resource_list *rl); + +/* + * Reclaim memory used by a resource list. + */ +void resource_list_free(struct resource_list *rl); + +/* + * Add a resource entry or modify an existing entry if one exists with + * the same type and rid. + */ +void resource_list_add(struct resource_list *rl, + int type, int rid, + u_long start, u_long end, u_long count); +int resource_list_add_next(struct resource_list *rl, + int type, + u_long start, u_long end, u_long count); + + +/* + * Find a resource entry by type and rid. + */ +struct resource_list_entry* + resource_list_find(struct resource_list *rl, + int type, int rid); + +/* + * Delete a resource entry. + */ +void resource_list_delete(struct resource_list *rl, + int type, int rid); + +/* + * Implement BUS_ALLOC_RESOURCE by looking up a resource from the list + * and passing the allocation up to the parent of bus. This assumes + * that the first entry of device_get_ivars(child) is a struct + * resource_list. This also handles 'passthrough' allocations where a + * child is a remote descendant of bus by passing the allocation up to + * the parent of bus. + */ +struct resource * + resource_list_alloc(struct resource_list *rl, + device_t bus, device_t child, + int type, int *rid, + u_long start, u_long end, + u_long count, u_int flags); + +/* + * Implement BUS_RELEASE_RESOURCE. + */ +int resource_list_release(struct resource_list *rl, + device_t bus, device_t child, + int type, int rid, struct resource *res); + +/* + * Print all resources of a specified type, for use in bus_print_child. + * The name is printed if at least one resource of the given type is available. + * The format ist used to print resource start and end. + */ +int resource_list_print_type(struct resource_list *rl, + const char *name, int type, + const char *format); + +/* + * The root bus, to which all top-level busses are attached. + */ +extern device_t root_bus; +extern devclass_t root_devclass; +void root_bus_configure(void); + +/* + * Useful functions for implementing busses. + */ + +int bus_generic_activate_resource(device_t dev, device_t child, int type, + int rid, struct resource *r); +struct resource * + bus_generic_alloc_resource(device_t bus, device_t child, int type, + int *rid, u_long start, u_long end, + u_long count, u_int flags); +int bus_generic_attach(device_t dev); +int bus_generic_child_present(device_t dev, device_t child); +int bus_generic_config_intr(device_t, int, enum intr_trigger, + enum intr_polarity); +int bus_generic_deactivate_resource(device_t dev, device_t child, int type, + int rid, struct resource *r); +int bus_generic_detach(device_t dev); +void bus_generic_driver_added(device_t dev, driver_t *driver); +struct resource_list * + bus_generic_get_resource_list (device_t, device_t); +int bus_print_child_header(device_t dev, device_t child); +int bus_print_child_footer(device_t dev, device_t child); +int bus_generic_print_child(device_t dev, device_t child); +int bus_generic_probe(device_t dev); +int bus_generic_read_ivar(device_t dev, device_t child, int which, + uintptr_t *result); +int bus_generic_release_resource(device_t bus, device_t child, + int type, int rid, struct resource *r); +int bus_generic_resume(device_t dev); +int bus_generic_setup_intr(device_t dev, device_t child, + struct resource *irq, int flags, + driver_intr_t *intr, void *arg, void **cookiep); + +struct resource * + bus_generic_rl_alloc_resource (device_t, device_t, int, int *, + u_long, u_long, u_long, u_int); +void bus_generic_rl_delete_resource (device_t, device_t, int, int); +int bus_generic_rl_get_resource (device_t, device_t, int, int, u_long *, + u_long *); +int bus_generic_rl_set_resource (device_t, device_t, int, int, u_long, + u_long); +int bus_generic_rl_release_resource (device_t, device_t, int, int, + struct resource *); + +int bus_generic_shutdown(device_t dev); +int bus_generic_suspend(device_t dev); +int bus_generic_teardown_intr(device_t dev, device_t child, + struct resource *irq, void *cookie); +int bus_generic_write_ivar(device_t dev, device_t child, int which, + uintptr_t value); + +/* + * Wrapper functions for the BUS_*_RESOURCE methods to make client code + * a little simpler. + */ +struct resource *bus_alloc_resource(device_t dev, int type, int *rid, + u_long start, u_long end, u_long count, + u_int flags); +int bus_activate_resource(device_t dev, int type, int rid, + struct resource *r); +int bus_deactivate_resource(device_t dev, int type, int rid, + struct resource *r); +int bus_release_resource(device_t dev, int type, int rid, + struct resource *r); +int bus_setup_intr(device_t dev, struct resource *r, int flags, + driver_intr_t handler, void *arg, void **cookiep); +int bus_teardown_intr(device_t dev, struct resource *r, void *cookie); +int bus_set_resource(device_t dev, int type, int rid, + u_long start, u_long count); +int bus_get_resource(device_t dev, int type, int rid, + u_long *startp, u_long *countp); +u_long bus_get_resource_start(device_t dev, int type, int rid); +u_long bus_get_resource_count(device_t dev, int type, int rid); +void bus_delete_resource(device_t dev, int type, int rid); +int bus_child_present(device_t child); +int bus_child_pnpinfo_str(device_t child, char *buf, size_t buflen); +int bus_child_location_str(device_t child, char *buf, size_t buflen); + +static __inline struct resource * +bus_alloc_resource_any(device_t dev, int type, int *rid, u_int flags) +{ + return (bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags)); +} + +/* + * Access functions for device. + */ +device_t device_add_child(device_t dev, const char *name, int unit); +device_t device_add_child_ordered(device_t dev, int order, + const char *name, int unit); +void device_busy(device_t dev); +int device_delete_child(device_t dev, device_t child); +int device_detach(device_t dev); +void device_disable(device_t dev); +void device_enable(device_t dev); +device_t device_find_child(device_t dev, const char *classname, + int unit); +const char *device_get_desc(device_t dev); +devclass_t device_get_devclass(device_t dev); +driver_t *device_get_driver(device_t dev); +u_int32_t device_get_flags(device_t dev); +device_t device_get_parent(device_t dev); +int device_get_children(device_t dev, device_t **listp, int *countp); +void *device_get_ivars(device_t dev); +void device_set_ivars(device_t dev, void *ivars); +const char *device_get_name(device_t dev); +const char *device_get_nameunit(device_t dev); +void *device_get_softc(device_t dev); +device_state_t device_get_state(device_t dev); +int device_get_unit(device_t dev); +int device_is_alive(device_t dev); /* did probe succeed? */ +int device_is_attached(device_t dev); /* did attach succeed? */ +int device_is_enabled(device_t dev); +int device_is_quiet(device_t dev); +int device_print_prettyname(device_t dev); +int device_printf(device_t dev, const char *, ...) __printflike(2, 3); +int device_probe_and_attach(device_t dev); +void device_quiet(device_t dev); +void device_set_desc(device_t dev, const char* desc); +void device_set_desc_copy(device_t dev, const char* desc); +int device_set_devclass(device_t dev, const char *classname); +int device_set_driver(device_t dev, driver_t *driver); +void device_set_flags(device_t dev, u_int32_t flags); +void device_set_softc(device_t dev, void *softc); +int device_set_unit(device_t dev, int unit); /* XXX DONT USE XXX */ +int device_shutdown(device_t dev); +void device_unbusy(device_t dev); +void device_verbose(device_t dev); + +/* + * Access functions for devclass. + */ +int devclass_add_driver(devclass_t dc, kobj_class_t driver); +int devclass_delete_driver(devclass_t dc, kobj_class_t driver); +devclass_t devclass_create(const char *classname); +devclass_t devclass_find(const char *classname); +kobj_class_t devclass_find_driver(devclass_t dc, const char *classname); +const char *devclass_get_name(devclass_t dc); +device_t devclass_get_device(devclass_t dc, int unit); +void *devclass_get_softc(devclass_t dc, int unit); +int devclass_get_devices(devclass_t dc, device_t **listp, int *countp); +int devclass_get_maxunit(devclass_t dc); +int devclass_find_free_unit(devclass_t dc, int unit); +void devclass_set_parent(devclass_t dc, devclass_t pdc); +devclass_t devclass_get_parent(devclass_t dc); + +/* + * Access functions for device resources. + */ + +int resource_int_value(const char *name, int unit, const char *resname, + int *result); +int resource_long_value(const char *name, int unit, const char *resname, + long *result); +int resource_string_value(const char *name, int unit, const char *resname, + const char **result); +int resource_disabled(const char *name, int unit); +int resource_find_match(int *anchor, const char **name, int *unit, + const char *resname, const char *value); +int resource_find_dev(int *anchor, const char *name, int *unit, + const char *resname, const char *value); +int resource_set_int(const char *name, int unit, const char *resname, + int value); +int resource_set_long(const char *name, int unit, const char *resname, + long value); +int resource_set_string(const char *name, int unit, const char *resname, + const char *value); +/* + * Functions for maintaining and checking consistency of + * bus information exported to userspace. + */ +int bus_data_generation_check(int generation); +void bus_data_generation_update(void); + +/* + * Shorthand for constructing method tables. + */ +#define DEVMETHOD KOBJMETHOD + +/* + * Some common device interfaces. + */ +#include "device_if.h" +#include "bus_if.h" + +struct module; + +int driver_module_handler(struct module *, int, void *); + +/* + * Module support for automatically adding drivers to busses. + */ +struct driver_module_data { + int (*dmd_chainevh)(struct module *, int, void *); + void *dmd_chainarg; + const char *dmd_busname; + kobj_class_t dmd_driver; + devclass_t *dmd_devclass; +}; + +#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ + \ +static struct driver_module_data name##_##busname##_driver_mod = { \ + evh, arg, \ + #busname, \ + (kobj_class_t) &driver, \ + &devclass \ +}; \ + \ +static moduledata_t name##_##busname##_mod = { \ + #busname "/" #name, \ + driver_module_handler, \ + &name##_##busname##_driver_mod \ +}; \ +DECLARE_MODULE(name##_##busname, name##_##busname##_mod, \ + SI_SUB_DRIVERS, SI_ORDER_MIDDLE) + +/* + * Generic ivar accessor generation macros for bus drivers + */ +#define __BUS_ACCESSOR(varp, var, ivarp, ivar, type) \ + \ +static __inline type varp ## _get_ ## var(device_t dev) \ +{ \ + uintptr_t v; \ + BUS_READ_IVAR(device_get_parent(dev), dev, \ + ivarp ## _IVAR_ ## ivar, &v); \ + return ((type) v); \ +} \ + \ +static __inline void varp ## _set_ ## var(device_t dev, type t) \ +{ \ + uintptr_t v = (uintptr_t) t; \ + BUS_WRITE_IVAR(device_get_parent(dev), dev, \ + ivarp ## _IVAR_ ## ivar, v); \ +} + +#endif /* _KERNEL */ + +#endif /* !_SYS_BUS_H_ */ diff --git a/src/include/sys/callout.h b/src/include/sys/callout.h new file mode 100644 index 0000000..f0e1081 --- /dev/null +++ b/src/include/sys/callout.h @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)callout.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/callout.h,v 1.27 2004/04/20 15:49:31 cperciva Exp $ + */ + +#ifndef _SYS_CALLOUT_H_ +#define _SYS_CALLOUT_H_ + +#include + +SLIST_HEAD(callout_list, callout); +TAILQ_HEAD(callout_tailq, callout); + +struct callout { + union { + SLIST_ENTRY(callout) sle; + TAILQ_ENTRY(callout) tqe; + } c_links; + int c_time; /* ticks to the event */ + void *c_arg; /* function argument */ + void (*c_func)(void *); /* function to call */ + int c_flags; /* state of this entry */ +}; + +#define CALLOUT_LOCAL_ALLOC 0x0001 /* was allocated from callfree */ +#define CALLOUT_ACTIVE 0x0002 /* callout is currently active */ +#define CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */ +#define CALLOUT_MPSAFE 0x0008 /* callout handler is mp safe */ + +struct callout_handle { + struct callout *callout; +}; + +#ifdef _KERNEL +extern struct callout_list callfree; +extern struct callout *callout; +extern int ncallout; +extern struct callout_tailq *callwheel; +extern int callwheelsize, callwheelbits, callwheelmask, softticks; +extern struct mtx callout_lock; + +#define callout_active(c) ((c)->c_flags & CALLOUT_ACTIVE) +#define callout_deactivate(c) ((c)->c_flags &= ~CALLOUT_ACTIVE) +#define callout_drain(c) _callout_stop_safe(c, 1) +void callout_init(struct callout *, int); +#define callout_pending(c) ((c)->c_flags & CALLOUT_PENDING) +void callout_reset(struct callout *, int, void (*)(void *), void *); +#define callout_stop(c) _callout_stop_safe(c, 0) +int _callout_stop_safe(struct callout *, int); + +#endif + +#endif /* _SYS_CALLOUT_H_ */ diff --git a/src/include/sys/cdefs.h b/src/include/sys/cdefs.h new file mode 100644 index 0000000..e6a266d --- /dev/null +++ b/src/include/sys/cdefs.h @@ -0,0 +1,460 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Berkeley Software Design, Inc. + * + * 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. + * 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. + * + * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/cdefs.h,v 1.81 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ + +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +/* + * Macro to test if we're using a specific version of gcc or later. + */ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __GNUC_PREREQ__(ma, mi) \ + (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) +#else +#define __GNUC_PREREQ__(ma, mi) 0 +#endif + +/* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. + * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. + * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI + * mode -- there must be no spaces between its arguments, and for nested + * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also + * concatenate double-quoted strings produced by the __STRING macro, but + * this only works with ANSI C. + * + * __XSTRING is like __STRING, but it expands any macros in its argument + * first. It is only available with ANSI C. + */ +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#define __CONCAT1(x,y) x ## y +#define __CONCAT(x,y) __CONCAT1(x,y) +#define __STRING(x) #x /* stringify without expanding x */ +#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ + +#define __const const /* define reserved names to standard */ +#define __signed signed +#define __volatile volatile +#if defined(__cplusplus) +#define __inline inline /* convert to C++ keyword */ +#else +#if !(defined(__GNUC__) || defined(__INTEL_COMPILER)) +#define __inline /* delete GCC keyword */ +#endif /* !(__GNUC__ || __INTEL_COMPILER) */ +#endif /* !__cplusplus */ + +#else /* !(__STDC__ || __cplusplus) */ +#define __P(protos) () /* traditional C preprocessor */ +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" + +#if !(defined(__GNUC__) || defined(__INTEL_COMPILER)) +#define __const /* delete pseudo-ANSI C keywords */ +#define __inline +#define __signed +#define __volatile +/* + * In non-ANSI C environments, new programs will want ANSI-only C keywords + * deleted from the program and old programs will want them left alone. + * When using a compiler other than gcc, programs using the ANSI C keywords + * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. + * When using "gcc -traditional", we assume that this is the intent; if + * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. + */ +#ifndef NO_ANSI_KEYWORDS +#define const /* delete ANSI C keywords */ +#define inline +#define signed +#define volatile +#endif /* !NO_ANSI_KEYWORDS */ +#endif /* !(__GNUC__ || __INTEL_COMPILER) */ +#endif /* !(__STDC__ || __cplusplus) */ + +/* + * Compiler-dependent macros to help declare dead (non-returning) and + * pure (no side effects) functions, and unused variables. They are + * null except for versions of gcc that are known to support the features + * properly (old versions of gcc-2 supported the dead and pure features + * in a different (wrong) way). If we do not provide an implementation + * for a given compiler, let the compile fail if it is told to use + * a feature that we cannot live without. + */ +#ifdef lint +#define __dead2 +#define __pure2 +#define __unused +#define __packed +#define __aligned(x) +#define __section(x) +#else +#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) +#define __dead2 +#define __pure2 +#define __unused +#endif +#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused +/* XXX Find out what to do for __packed, __aligned and __section */ +#endif +#if __GNUC_PREREQ__(2, 7) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused __attribute__((__unused__)) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#define __section(x) __attribute__((__section__(x))) +#endif +#if defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused __attribute__((__unused__)) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#define __section(x) __attribute__((__section__(x))) +#endif +#endif + +#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#define __always_inline __attribute__((__always_inline__)) +#else +#define __always_inline +#endif + +#if __GNUC_PREREQ__(3, 3) +#define __nonnull(x) __attribute__((__nonnull__(x))) +#else +#define __nonnull(x) +#endif + +/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __func__ NULL +#endif + +#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 +#define __LONG_LONG_SUPPORTED +#endif + +/* + * GCC 2.95 provides `__restrict' as an extension to C90 to support the + * C99-specific `restrict' type qualifier. We happen to use `__restrict' as + * a way to define the `restrict' type qualifier without disturbing older + * software that is unaware of C99 keywords. + */ +#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 +#define __restrict +#else +#define __restrict restrict +#endif +#endif + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to utilize this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if __GNUC_PREREQ__(2, 96) +#define __predict_true(exp) __builtin_expect((exp), 1) +#define __predict_false(exp) __builtin_expect((exp), 0) +#else +#define __predict_true(exp) (exp) +#define __predict_false(exp) (exp) +#endif + +/* + * We define this here since , , and + * require it. + */ +#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) + +/* + * Compiler-dependent macros to declare that functions take printf-like + * or scanf-like arguments. They are null except for versions of gcc + * that are known to support the features properly (old versions of gcc-2 + * didn't permit keeping the keywords out of the application namespace). + */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __printflike(fmtarg, firstvararg) +#define __scanflike(fmtarg, firstvararg) +#else +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#define __scanflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) +#endif + +/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ +#if __FreeBSD_cc_version >= 300001 && defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __printf0like(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) +#else +#define __printf0like(fmtarg, firstvararg) +#endif + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#ifndef __INTEL_COMPILER +#define __strong_reference(sym,aliassym) \ + extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))); +#endif +#ifdef __STDC__ +#define __weak_reference(sym,alias) \ + __asm__(".weak " #alias); \ + __asm__(".equ " #alias ", " #sym) +#define __warn_references(sym,msg) \ + __asm__(".section .gnu.warning." #sym); \ + __asm__(".asciz \"" msg "\""); \ + __asm__(".previous") +#else +#define __weak_reference(sym,alias) \ + __asm__(".weak alias"); \ + __asm__(".equ alias, sym") +#define __warn_references(sym,msg) \ + __asm__(".section .gnu.warning.sym"); \ + __asm__(".asciz \"msg\""); \ + __asm__(".previous") +#endif /* __STDC__ */ +#endif /* __GNUC__ || __INTEL_COMPILER */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") +#else +/* + * The following definition might not work well if used in header files, + * but it should be better than nothing. If you want a "do nothing" + * version, then it should generate some harmless declaration, such as: + * #define __IDSTRING(name,string) struct __hack + */ +#define __IDSTRING(name,string) static const char name[] __unused = string +#endif + +/* + * Embed the rcs id of a source file in the resulting library. Note that in + * more recent ELF binutils, we use .ident allowing the ID to be stripped. + * Usage: + * __FBSDID("$FreeBSD: src/sys/sys/cdefs.h,v 1.81 2004/04/07 04:19:49 imp Exp $"); + */ +#ifndef __FBSDID +#if !defined(lint) && !defined(STRIP_FBSDID) +#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) +#else +#define __FBSDID(s) struct __hack +#endif +#endif + +#ifndef __RCSID +#ifndef NO__RCSID +#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) +#else +#define __RCSID(s) struct __hack +#endif +#endif + +#ifndef __RCSID_SOURCE +#ifndef NO__RCSID_SOURCE +#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) +#else +#define __RCSID_SOURCE(s) struct __hack +#endif +#endif + +#ifndef __SCCSID +#ifndef NO__SCCSID +#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) +#else +#define __SCCSID(s) struct __hack +#endif +#endif + +#ifndef __COPYRIGHT +#ifndef NO__COPYRIGHT +#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) +#else +#define __COPYRIGHT(s) struct __hack +#endif +#endif + +#ifndef __DECONST +#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) +#endif + +#ifndef __DEVOLATILE +#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) +#endif + +#ifndef __DEQUALIFY +#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) +#endif + +/*- + * The following definitions are an extension of the behavior originally + * implemented in , but with a different level of granularity. + * POSIX.1 requires that the macros we test be defined before any standard + * header file is included. + * + * Here's a quick run-down of the versions: + * defined(_POSIX_SOURCE) 1003.1-1988 + * _POSIX_C_SOURCE == 1 1003.1-1990 + * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option + * _POSIX_C_SOURCE == 199309 1003.1b-1993 + * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, + * and the omnibus ISO/IEC 9945-1: 1996 + * _POSIX_C_SOURCE == 200112 1003.1-2001 + * + * In addition, the X/Open Portability Guide, which is now the Single UNIX + * Specification, defines a feature-test macro which indicates the version of + * that specification, and which subsumes _POSIX_C_SOURCE. + * + * Our macros begin with two underscores to avoid namespace screwage. + */ + +/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 +#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ +#define _POSIX_C_SOURCE 199009 +#endif + +/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199209 +#endif + +/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ +#ifdef _XOPEN_SOURCE +#if _XOPEN_SOURCE - 0 >= 600 +#define __XSI_VISIBLE 600 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112 +#elif _XOPEN_SOURCE - 0 >= 500 +#define __XSI_VISIBLE 500 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199506 +#endif +#endif + +/* + * Deal with all versions of POSIX. The ordering relative to the tests above is + * important. + */ +#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 198808 +#endif +#ifdef _POSIX_C_SOURCE +#if _POSIX_C_SOURCE >= 200112 +#define __POSIX_VISIBLE 200112 +#define __ISO_C_VISIBLE 1999 +#elif _POSIX_C_SOURCE >= 199506 +#define __POSIX_VISIBLE 199506 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199309 +#define __POSIX_VISIBLE 199309 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199209 +#define __POSIX_VISIBLE 199209 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199009 +#define __POSIX_VISIBLE 199009 +#define __ISO_C_VISIBLE 1990 +#else +#define __POSIX_VISIBLE 198808 +#define __ISO_C_VISIBLE 0 +#endif /* _POSIX_C_SOURCE */ +#else +/*- + * Deal with _ANSI_SOURCE: + * If it is defined, and no other compilation environment is explicitly + * requested, then define our internal feature-test macros to zero. This + * makes no difference to the preprocessor (undefined symbols in preprocessing + * expressions are defined to have value zero), but makes it more convenient for + * a test program to print out the values. + * + * If a program mistakenly defines _ANSI_SOURCE and some other macro such as + * _POSIX_C_SOURCE, we will assume that it wants the broader compilation + * environment (and in fact we will never get here). + */ +#if defined(_ANSI_SOURCE) /* Hide almost everything. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1990 +#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1999 +#else /* Default environment: show everything. */ +#define __POSIX_VISIBLE 200112 +#define __XSI_VISIBLE 600 +#define __BSD_VISIBLE 1 +#define __ISO_C_VISIBLE 1999 +#endif +#endif + +#endif /* !_SYS_CDEFS_H_ */ diff --git a/src/include/sys/cdio.h b/src/include/sys/cdio.h new file mode 100644 index 0000000..1c38473 --- /dev/null +++ b/src/include/sys/cdio.h @@ -0,0 +1,277 @@ +/* + * 16 Feb 93 Julian Elischer (julian@dialix.oz.au) + * + * $FreeBSD: src/sys/sys/cdio.h,v 1.25 2003/10/20 09:29:40 sos Exp $ + */ + +/* +<1> Fixed a conflict with ioctl usage. There were two different + functions using code #25. Made file formatting consistent. + Added two new ioctl codes: door closing and audio pitch playback. + Added a STEREO union called STEREO. + 5-Mar-95 Frank Durda IV bsdmail@nemesis.lonestar.org + +<2> Added a new ioctl that allows you to find out what capabilities + a drive has and what commands it will accept. This allows a + user application to only offer controls (buttons, sliders, etc) + for functions that drive can actually do. Things it can't do + can disappear or be greyed-out (like some other system). + If the driver doesn't respond to this call, well, handle it the + way you used to do it. + 2-Apr-95 Frank Durda IV bsdmail@nemesis.lonestar.org +*/ + +/* Shared between kernel & process */ + +#ifndef _SYS_CDIO_H_ +#define _SYS_CDIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +union msf_lba { + struct { + unsigned char unused; + unsigned char minute; + unsigned char second; + unsigned char frame; + } msf; + int lba; /* network byte order */ + u_char addr[4]; +}; + +struct cd_toc_entry { +#if BYTE_ORDER == LITTLE_ENDIAN + u_int :8; + u_int control:4; + u_int addr_type:4; +#else + u_int :8; + u_int addr_type:4; + u_int control:4; +#endif + u_char track; + u_int :8; + union msf_lba addr; +}; + +struct cd_sub_channel_header { + u_int :8; + u_char audio_status; +#define CD_AS_AUDIO_INVALID 0x00 +#define CD_AS_PLAY_IN_PROGRESS 0x11 +#define CD_AS_PLAY_PAUSED 0x12 +#define CD_AS_PLAY_COMPLETED 0x13 +#define CD_AS_PLAY_ERROR 0x14 +#define CD_AS_NO_STATUS 0x15 + u_char data_len[2]; +}; + +struct cd_sub_channel_position_data { + u_char data_format; + u_int control:4; + u_int addr_type:4; + u_char track_number; + u_char index_number; + union msf_lba absaddr; + union msf_lba reladdr; +}; + +struct cd_sub_channel_media_catalog { + u_char data_format; + u_int :8; + u_int :8; + u_int :8; + u_int :7; + u_int mc_valid:1; + u_char mc_number[15]; +}; + +struct cd_sub_channel_track_info { + u_char data_format; + u_int :8; + u_char track_number; + u_int :8; + u_int :7; + u_int ti_valid:1; + u_char ti_number[15]; +}; + +struct cd_sub_channel_info { + struct cd_sub_channel_header header; + union { + struct cd_sub_channel_position_data position; + struct cd_sub_channel_media_catalog media_catalog; + struct cd_sub_channel_track_info track_info; + } what; +}; + + +/***************************************************************\ +* Ioctls for the CD drive * +\***************************************************************/ + +struct ioc_play_track { + u_char start_track; + u_char start_index; + u_char end_track; + u_char end_index; +}; +#define CDIOCPLAYTRACKS _IOW('c',1,struct ioc_play_track) + + +struct ioc_play_blocks { + int blk; + int len; +}; +#define CDIOCPLAYBLOCKS _IOW('c',2,struct ioc_play_blocks) + + +struct ioc_read_subchannel { + u_char address_format; +#define CD_LBA_FORMAT 1 +#define CD_MSF_FORMAT 2 + u_char data_format; +#define CD_SUBQ_DATA 0 +#define CD_CURRENT_POSITION 1 +#define CD_MEDIA_CATALOG 2 +#define CD_TRACK_INFO 3 + u_char track; + int data_len; + struct cd_sub_channel_info *data; +}; +#define CDIOCREADSUBCHANNEL _IOWR('c', 3 , struct ioc_read_subchannel ) + + +struct ioc_toc_header { + u_short len; + u_char starting_track; + u_char ending_track; +}; +#define CDIOREADTOCHEADER _IOR('c',4,struct ioc_toc_header) + + +struct ioc_read_toc_entry { + u_char address_format; + u_char starting_track; + u_short data_len; + struct cd_toc_entry *data; +}; +#define CDIOREADTOCENTRYS _IOWR('c',5,struct ioc_read_toc_entry) + + +struct ioc_read_toc_single_entry { + u_char address_format; + u_char track; + struct cd_toc_entry entry; +}; +#define CDIOREADTOCENTRY _IOWR('c',6,struct ioc_read_toc_single_entry) + + +struct ioc_patch { + u_char patch[4]; /* one for each channel */ +}; +#define CDIOCSETPATCH _IOW('c',9,struct ioc_patch) + + +struct ioc_vol { + u_char vol[4]; /* one for each channel */ +}; +#define CDIOCGETVOL _IOR('c',10,struct ioc_vol) + +#define CDIOCSETVOL _IOW('c',11,struct ioc_vol) + +#define CDIOCSETMONO _IO('c',12) + +#define CDIOCSETSTERIO _IO('c',13) +#define CDIOCSETSTEREO _IO('c',13) + +#define CDIOCSETMUTE _IO('c',14) + +#define CDIOCSETLEFT _IO('c',15) + +#define CDIOCSETRIGHT _IO('c',16) + +#define CDIOCSETDEBUG _IO('c',17) + +#define CDIOCCLRDEBUG _IO('c',18) + +#define CDIOCPAUSE _IO('c',19) + +#define CDIOCRESUME _IO('c',20) + +#define CDIOCRESET _IO('c',21) + +#define CDIOCSTART _IO('c',22) + +#define CDIOCSTOP _IO('c',23) + +#define CDIOCEJECT _IO('c',24) + + +struct ioc_play_msf { + u_char start_m; + u_char start_s; + u_char start_f; + u_char end_m; + u_char end_s; + u_char end_f; +}; +#define CDIOCPLAYMSF _IOW('c',25,struct ioc_play_msf) + +#define CDIOCALLOW _IO('c',26) + +#define CDIOCPREVENT _IO('c',27) + + /*<1>For drives that support it, this*/ + /*<1>causes the drive to close its door*/ + /*<1>and make the media (if any) ready*/ +#define CDIOCCLOSE _IO('c',28) /*<1>*/ + + +struct ioc_pitch { /*<1>For drives that support it, this*/ + /*<1>call instructs the drive to play the*/ + short speed; /*<1>audio at a faster or slower-than-normal*/ +}; /*<1>rate. -32767 to -1 is slower, 0==normal,*/ + /*<1>and 1 to 32767 is faster. LSB bits are*/ + /*<1>discarded first by drives with less res.*/ +#define CDIOCPITCH _IOW('c',29,struct ioc_pitch) /*<1>*/ + +struct ioc_capability { /*<2>*/ + u_long play_function; /*<2>*/ +#define CDDOPLAYTRK 0x00000001 /*<2>Can Play tracks/index*/ +#define CDDOPLAYMSF 0x00000002 /*<2>Can Play msf to msf*/ +#define CDDOPLAYBLOCKS 0x00000004 /*<2>Can Play range of blocks*/ +#define CDDOPAUSE 0x00000100 /*<2>Output can be paused*/ +#define CDDORESUME 0x00000200 /*<2>Output can be resumed*/ +#define CDDORESET 0x00000400 /*<2>Drive can be completely reset*/ +#define CDDOSTART 0x00000800 /*<2>Audio can be started*/ +#define CDDOSTOP 0x00001000 /*<2>Audio can be stopped*/ +#define CDDOPITCH 0x00002000 /*<2>Audio pitch */ + + u_long routing_function; /*<2>*/ +#define CDREADVOLUME 0x00000001 /*<2>Volume settings can be read*/ +#define CDSETVOLUME 0x00000002 /*<2>Volume settings can be set*/ +#define CDSETMONO 0x00000100 /*<2>Output can be set to mono*/ +#define CDSETSTEREO 0x00000200 /*<2>Output can be set to stereo (def)*/ +#define CDSETLEFT 0x00000400 /*<2>Output can be set to left only*/ +#define CDSETRIGHT 0x00000800 /*<2>Output can be set to right only*/ +#define CDSETMUTE 0x00001000 /*<2>Output can be muted*/ +#define CDSETPATCH 0x00008000 /*<2>Direct routing control allowed*/ + + u_long special_function; /*<2>*/ +#define CDDOEJECT 0x00000001 /*<2>The tray can be opened*/ +#define CDDOCLOSE 0x00000002 /*<2>The tray can be closed*/ +#define CDDOLOCK 0x00000004 /*<2>The tray can be locked*/ +#define CDREADHEADER 0x00000100 /*<2>Can read Table of Contents*/ +#define CDREADENTRIES 0x00000200 /*<2>Can read TOC Entries*/ +#define CDREADSUBQ 0x00000200 /*<2>Can read Subchannel info*/ +#define CDREADRW 0x00000400 /*<2>Can read subcodes R-W*/ +#define CDHASDEBUG 0x00004000 /*<2>The tray has dynamic debugging*/ +}; /*<2>*/ + +#define CDIOCCAPABILITY _IOR('c',30,struct ioc_capability) /*<2>*/ + +#endif /* !_SYS_CDIO_H_ */ diff --git a/src/include/sys/cdrio.h b/src/include/sys/cdrio.h new file mode 100644 index 0000000..f325855 --- /dev/null +++ b/src/include/sys/cdrio.h @@ -0,0 +1,139 @@ +/*- + * Copyright (c) 2000,2001,2002 S�ren Schmidt + * 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, + * without modification, immediately at the beginning of the file. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/cdrio.h,v 1.9 2002/10/18 22:03:38 njl Exp $ + */ + +#ifndef _SYS_CDRIO_H_ +#define _SYS_CDRIO_H_ + +#include + +struct cdr_track { + int datablock_type; /* data type code */ +#define CDR_DB_RAW 0x0 /* 2352 bytes of raw data */ +#define CDR_DB_RAW_PQ 0x1 /* 2368 bytes raw data + P/Q subchan */ +#define CDR_DB_RAW_PW 0x2 /* 2448 bytes raw data + P-W subchan */ +#define CDR_DB_RAW_PW_R 0x3 /* 2448 bytes raw data + P-W raw sub */ +#define CDR_DB_RES_4 0x4 /* reserved */ +#define CDR_DB_RES_5 0x5 /* reserved */ +#define CDR_DB_RES_6 0x6 /* reserved */ +#define CDR_DB_VS_7 0x7 /* vendor specific */ +#define CDR_DB_ROM_MODE1 0x8 /* 2048 bytes Mode 1 (ISO/IEC 10149) */ +#define CDR_DB_ROM_MODE2 0x9 /* 2336 bytes Mode 2 (ISO/IEC 10149) */ +#define CDR_DB_XA_MODE1 0xa /* 2048 bytes Mode 1 (CD-ROM XA 1) */ +#define CDR_DB_XA_MODE2_F1 0xb /* 2056 bytes Mode 2 (CD-ROM XA 1) */ +#define CDR_DB_XA_MODE2_F2 0xc /* 2324 bytes Mode 2 (CD-ROM XA 2) */ +#define CDR_DB_XA_MODE2_MIX 0xd /* 2332 bytes Mode 2 (CD-ROM XA 1/2) */ +#define CDR_DB_RES_14 0xe /* reserved */ +#define CDR_DB_VS_15 0xf /* vendor specific */ + + int preemp; /* preemphasis if audio track*/ + int test_write; /* use test writes, laser turned off */ +}; + +struct cdr_cue_entry { + u_int8_t adr:4; + u_int8_t ctl:4; + u_int8_t track; + u_int8_t index; + u_int8_t dataform; + u_int8_t scms; + u_int8_t min; + u_int8_t sec; + u_int8_t frame; +}; + +struct cdr_cuesheet { + int32_t len; + struct cdr_cue_entry *entries; + int session_format; +#define CDR_SESS_CDROM 0x00 +#define CDR_SESS_CDI 0x10 +#define CDR_SESS_CDROM_XA 0x20 + + int session_type; +#define CDR_SESS_NONE 0x00 +#define CDR_SESS_FINAL 0x01 +#define CDR_SESS_RESERVED 0x02 +#define CDR_SESS_MULTI 0x03 + + int test_write; +}; + +struct cdr_format_capacity { + u_int32_t blocks; + u_int32_t reserved:2; + u_int32_t type:6; + u_int32_t param:24; +}; + +struct cdr_format_capacities { + u_int8_t reserved1[3]; + u_int8_t length; + u_int32_t blocks; + u_int32_t type:2; + u_int32_t reserved2:6; + u_int32_t block_size:24; + struct cdr_format_capacity format[32]; +}; + +struct cdr_format_params { + u_int8_t reserved; + u_int8_t vs:1; + u_int8_t immed:1; + u_int8_t try_out:1; + u_int8_t ip:1; + u_int8_t stpf:1; + u_int8_t dcrt:1; + u_int8_t dpry:1; + u_int8_t fov:1; + u_int16_t length; + struct cdr_format_capacity format; +}; + +#define CDRIOCBLANK _IOW('c', 100, int) +#define CDR_B_ALL 0x0 +#define CDR_B_MIN 0x1 +#define CDR_B_SESSION 0x6 + +#define CDRIOCNEXTWRITEABLEADDR _IOR('c', 101, int) +#define CDRIOCINITWRITER _IOW('c', 102, int) +#define CDRIOCINITTRACK _IOW('c', 103, struct cdr_track) +#define CDRIOCSENDCUE _IOW('c', 104, struct cdr_cuesheet) +#define CDRIOCFLUSH _IO('c', 105) +#define CDRIOCFIXATE _IOW('c', 106, int) +#define CDRIOCREADSPEED _IOW('c', 107, int) +#define CDRIOCWRITESPEED _IOW('c', 108, int) +#define CDR_MAX_SPEED 0xffff +#define CDRIOCGETBLOCKSIZE _IOR('c', 109, int) +#define CDRIOCSETBLOCKSIZE _IOW('c', 110, int) +#define CDRIOCGETPROGRESS _IOR('c', 111, int) +#define CDRIOCREADFORMATCAPS _IOR('c', 112, struct cdr_format_capacities) +#define CDRIOCFORMAT _IOW('c', 113, struct cdr_format_params) + +#endif /* !_SYS_CDRIO_H_ */ diff --git a/src/include/sys/chio.h b/src/include/sys/chio.h new file mode 100644 index 0000000..0219a4d --- /dev/null +++ b/src/include/sys/chio.h @@ -0,0 +1,227 @@ +/* + * Copyright (c) 1996 Jason R. Thorpe + * 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 acknowledgements: + * This product includes software developed by Jason R. Thorpe + * for And Communications, http://www.and.com/ + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/chio.h,v 1.16 2003/05/31 16:54:37 phk Exp $ + */ + +#ifndef _SYS_CHIO_H_ +#define _SYS_CHIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Element types. Used as "to" and "from" type indicators in move + * and exchange operations. + * + * Note that code in sys/scsi/ch.c relies on these values (uses them + * as offsets in an array, and other evil), so don't muck with them + * unless you know what you're doing. + */ +#define CHET_MT 0 /* medium transport (picker) */ +#define CHET_ST 1 /* storage transport (slot) */ +#define CHET_IE 2 /* import/export (portal) */ +#define CHET_DT 3 /* data transfer (drive) */ +#define CHET_MAX CHET_DT + +/* + * Maximum length of a volume identification string + */ +#define CH_VOLTAG_MAXLEN 32 + +/* + * Structure used to execute a MOVE MEDIUM command. + */ +struct changer_move { + u_int16_t cm_fromtype; /* element type to move from */ + u_int16_t cm_fromunit; /* logical unit of from element */ + u_int16_t cm_totype; /* element type to move to */ + u_int16_t cm_tounit; /* logical unit of to element */ + u_int16_t cm_flags; /* misc. flags */ +}; + +/* cm_flags */ +#define CM_INVERT 0x01 /* invert media */ + +/* + * Structure used to execute an EXCHANGE MEDIUM command. In an + * exchange operation, the following steps occur: + * + * - media from source is moved to first destination. + * + * - media previously occupying first destination is moved + * to the second destination. + * + * The second destination may or may not be the same as the source. + * In the case of a simple exchange, the source and second destination + * are the same. + */ +struct changer_exchange { + u_int16_t ce_srctype; /* element type of source */ + u_int16_t ce_srcunit; /* logical unit of source */ + u_int16_t ce_fdsttype; /* element type of first destination */ + u_int16_t ce_fdstunit; /* logical unit of first destination */ + u_int16_t ce_sdsttype; /* element type of second destination */ + u_int16_t ce_sdstunit; /* logical unit of second destination */ + u_int16_t ce_flags; /* misc. flags */ +}; + +/* ce_flags */ +#define CE_INVERT1 0x01 /* invert media 1 */ +#define CE_INVERT2 0x02 /* invert media 2 */ + +/* + * Structure used to execute a POSITION TO ELEMENT command. This + * moves the current picker in front of the specified element. + */ +struct changer_position { + u_int16_t cp_type; /* element type */ + u_int16_t cp_unit; /* logical unit of element */ + u_int16_t cp_flags; /* misc. flags */ +}; + +/* cp_flags */ +#define CP_INVERT 0x01 /* invert picker */ + +/* + * Data returned by CHIOGPARAMS. + */ +struct changer_params { + u_int16_t cp_npickers; /* number of pickers */ + u_int16_t cp_nslots; /* number of slots */ + u_int16_t cp_nportals; /* number of import/export portals */ + u_int16_t cp_ndrives; /* number of drives */ +}; + +/* + * Command used to get element status. + */ + +struct changer_voltag { + u_char cv_volid[CH_VOLTAG_MAXLEN+1]; + u_int16_t cv_serial; +}; + +typedef struct changer_voltag changer_voltag_t; + +/* + * Flags definitions for ces_status + * Not all flags have meaning for all element types. + */ +typedef enum { + CES_STATUS_FULL = 0x001, /* element is full */ + CES_STATUS_IMPEXP = 0x002, /* media deposited by operator */ + CES_STATUS_EXCEPT = 0x004, /* element in abnormal state */ + CES_PICKER_MASK = 0x005, /* flags valid for pickers */ + CES_STATUS_ACCESS = 0x008, /* media accessible by picker */ + CES_SLOT_MASK = 0x00c, /* flags valid for slots */ + CES_DRIVE_MASK = 0x00c, /* flags valid for drives */ + CES_STATUS_EXENAB = 0x010, /* element supports exporting */ + CES_STATUS_INENAB = 0x020, /* element supports importing */ + CES_PORTAL_MASK = 0x03f, /* flags valid for portals */ + CES_INVERT = 0x040, /* invert bit */ + CES_SOURCE_VALID = 0x080, /* source address (ces_source) valid */ + CES_SCSIID_VALID = 0x100, /* ces_scsi_id is valid */ + CES_LUN_VALID = 0x200 /* ces_scsi_lun is valid */ +} ces_status_flags; + +struct changer_element_status { + u_int8_t ces_type; /* element type */ + u_int16_t ces_addr; /* logical element address */ + u_int16_t ces_int_addr; /* changer element address */ + ces_status_flags ces_flags; /* + * see CESTATUS definitions + * below + */ + u_int8_t ces_sensecode; /* + * additional sense + * code for element */ + u_int8_t ces_sensequal; /* + * additional sense + * code qualifier + */ + u_int8_t ces_source_type; /* + * element type of + * source address + */ + u_int16_t ces_source_addr; /* + * source address of medium + */ + changer_voltag_t ces_pvoltag; /* primary volume tag */ + changer_voltag_t ces_avoltag; /* alternate volume tag */ + u_int8_t ces_scsi_id; /* SCSI id of element */ + u_int8_t ces_scsi_lun; /* SCSI lun of element */ +}; + +struct changer_element_status_request { + u_int16_t cesr_element_type; + u_int16_t cesr_element_base; + u_int16_t cesr_element_count; + + u_int16_t cesr_flags; +#define CESR_VOLTAGS 0x01 + + struct changer_element_status *cesr_element_status; +}; + + +struct changer_set_voltag_request { + u_int16_t csvr_type; + u_int16_t csvr_addr; + + u_int16_t csvr_flags; +#define CSVR_MODE_MASK 0x0f /* mode mask, acceptable modes below: */ +#define CSVR_MODE_SET 0x00 /* set volume tag if not set */ +#define CSVR_MODE_REPLACE 0x01 /* unconditionally replace volume tag */ +#define CSVR_MODE_CLEAR 0x02 /* clear volume tag */ + +#define CSVR_ALTERNATE 0x10 /* set to work with alternate voltag */ + + changer_voltag_t csvr_voltag; +}; + + +#define CESTATUS_BITS \ + "\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL" + +#define CHIOMOVE _IOW('c', 0x01, struct changer_move) +#define CHIOEXCHANGE _IOW('c', 0x02, struct changer_exchange) +#define CHIOPOSITION _IOW('c', 0x03, struct changer_position) +#define CHIOGPICKER _IOR('c', 0x04, int) +#define CHIOSPICKER _IOW('c', 0x05, int) +#define CHIOGPARAMS _IOR('c', 0x06, struct changer_params) +#define CHIOIELEM _IOW('c', 0x07, u_int32_t) +#define CHIOGSTATUS _IOW('c', 0x08, struct changer_element_status_request) +#define CHIOSETVOLTAG _IOW('c', 0x09, struct changer_set_voltag_request) + +#endif /* !_SYS_CHIO_H_ */ diff --git a/src/include/sys/clist.h b/src/include/sys/clist.h new file mode 100644 index 0000000..cda18a5 --- /dev/null +++ b/src/include/sys/clist.h @@ -0,0 +1,47 @@ +/*- + * 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. + * 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. + * + * @(#)clist.h 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/sys/sys/clist.h,v 1.11 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_CLIST_H_ +#define _SYS_CLIST_H_ + +struct cblock { + struct cblock *c_next; /* next cblock in queue */ + unsigned char c_quote[CBQSIZE]; /* quoted characters */ + unsigned char c_info[CBSIZE]; /* characters */ +}; + +#ifdef _KERNEL +extern struct cblock *cfree; +extern int cfreecount; +#endif + +#endif diff --git a/src/include/sys/clock.h b/src/include/sys/clock.h new file mode 100644 index 0000000..a53ccd8 --- /dev/null +++ b/src/include/sys/clock.h @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Gordon W. Ross + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + * + * $NetBSD: clock_subr.h,v 1.7 2000/10/03 13:41:07 tsutsui Exp $ + * + * $FreeBSD: src/sys/sys/clock.h,v 1.1 2002/04/04 23:39:08 tmm Exp $ + */ + +#ifndef _SYS_CLOCK_H_ +#define _SYS_CLOCK_H_ + +/* + * Structure to hold the values typically reported by time-of-day clocks. + * This can be passed to the generic conversion functions to be converted + * to a struct timespec. + */ +struct clocktime { + int year; /* year - 1900 */ + int mon; /* month (1 - 12) */ + int day; /* day (1 - 31) */ + int hour; /* hour (0 - 23) */ + int min; /* minute (0 - 59) */ + int sec; /* second (0 - 59) */ + int dow; /* day of week (0 - 6; 0 = Sunday) */ + long nsec; /* nano seconds */ +}; + +int clock_ct_to_ts(struct clocktime *, struct timespec *); +void clock_ts_to_ct(struct timespec *, struct clocktime *); +void clock_register(device_t, long); + +/* + * BCD to decimal and decimal to BCD. + */ +#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf)) +#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10)) + +/* Some handy constants. */ +#define SECDAY (24 * 60 * 60) +#define SECYR (SECDAY * 365) + +/* Traditional POSIX base year */ +#define POSIX_BASE_YEAR 1970 + +#endif /* !_SYS_CLOCK_H_ */ diff --git a/src/include/sys/condvar.h b/src/include/sys/condvar.h new file mode 100644 index 0000000..05eb57d --- /dev/null +++ b/src/include/sys/condvar.h @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2000 Jake Burkholder . + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/condvar.h,v 1.12 2004/05/05 21:57:44 jhb Exp $ + */ + +#ifndef _SYS_CONDVAR_H_ +#define _SYS_CONDVAR_H_ + +#ifndef LOCORE +#include + +struct mtx; +struct thread; + +TAILQ_HEAD(cv_waitq, thread); + +/* + * Condition variable. The waiters count is protected by the mutex that + * protects the condition; that is, the mutex that is passed to cv_wait*() + * and is held across calls to cv_signal() and cv_broadcast(). It is an + * optimization to avoid looking up the sleep queue if there are no waiters. + */ +struct cv { + const char *cv_description; + int cv_waiters; +}; + +#ifdef _KERNEL +void cv_init(struct cv *cvp, const char *desc); +void cv_destroy(struct cv *cvp); + +void cv_wait(struct cv *cvp, struct mtx *mp); +int cv_wait_sig(struct cv *cvp, struct mtx *mp); +int cv_timedwait(struct cv *cvp, struct mtx *mp, int timo); +int cv_timedwait_sig(struct cv *cvp, struct mtx *mp, int timo); + +void cv_signal(struct cv *cvp); +void cv_broadcastpri(struct cv *cvp, int pri); + +#define cv_broadcast(cvp) cv_broadcastpri(cvp, -1) + +#define cv_wmesg(cvp) ((cvp)->cv_description) + +#endif /* _KERNEL */ +#endif /* !LOCORE */ +#endif /* _SYS_CONDVAR_H_ */ diff --git a/src/include/sys/conf.h b/src/include/sys/conf.h new file mode 100644 index 0000000..24ab456 --- /dev/null +++ b/src/include/sys/conf.h @@ -0,0 +1,357 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2000 + * Poul-Henning Kamp. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)conf.h 8.5 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/conf.h,v 1.184 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_CONF_H_ +#define _SYS_CONF_H_ + +#ifdef _KERNEL +#include + +struct tty; +struct disk; +struct vnode; +struct buf; +TAILQ_HEAD(snaphead, inode); + +struct cdev { + u_int si_flags; +#define SI_STASHED 0x0001 /* created in stashed storage */ +#define SI_ALIAS 0x0002 /* carrier of alias name */ +#define SI_NAMED 0x0004 /* make_dev{_alias} has been called */ +#define SI_CHEAPCLONE 0x0008 /* can be removed_dev'ed when vnode reclaims */ +#define SI_CHILD 0x0010 /* child of another dev_t */ +#define SI_DEVOPEN 0x0020 /* opened by device */ +#define SI_CONSOPEN 0x0040 /* opened by console */ +#define SI_DUMPDEV 0x0080 /* is kernel dumpdev */ +#define SI_CANDELETE 0x0100 /* can do BIO_DELETE */ +#define SI_CLONELIST 0x0200 /* on a clone list */ + struct timespec si_atime; + struct timespec si_ctime; + struct timespec si_mtime; + udev_t si_udev; + int si_refcount; + LIST_ENTRY(cdev) si_list; + LIST_ENTRY(cdev) si_clone; + LIST_ENTRY(cdev) si_hash; + SLIST_HEAD(, vnode) si_hlist; + LIST_HEAD(, cdev) si_children; + LIST_ENTRY(cdev) si_siblings; + dev_t si_parent; + u_int si_inode; + char *si_name; + void *si_drv1, *si_drv2; + struct cdevsw *si_devsw; + int si_iosize_max; /* maximum I/O size (for physio &al) */ + u_int si_stripesize; + u_int si_stripeoffset; + uid_t si_uid; + gid_t si_gid; + mode_t si_mode; + u_long si_usecount; + union { + struct { + struct tty *__sit_tty; + } __si_tty; + struct { + struct mount *__sid_mountpoint; + int __sid_bsize_phys; /* min physical block size */ + int __sid_bsize_best; /* optimal block size */ + struct snaphead __sid_snapshots; + daddr_t __sid_snaplistsize; /* size of snapblklist. */ + daddr_t *__sid_snapblklist; /* known snapshot blocks. */ + int (*__sid_copyonwrite)(struct vnode *, struct buf *); + } __si_disk; + } __si_u; + char __si_namebuf[SPECNAMELEN + 1]; +}; + +#define si_tty __si_u.__si_tty.__sit_tty +#define si_mountpoint __si_u.__si_disk.__sid_mountpoint +#define si_bsize_phys __si_u.__si_disk.__sid_bsize_phys +#define si_bsize_best __si_u.__si_disk.__sid_bsize_best +#define si_snapshots __si_u.__si_disk.__sid_snapshots +#define si_snaplistsize __si_u.__si_disk.__sid_snaplistsize +#define si_snapblklist __si_u.__si_disk.__sid_snapblklist +#define si_copyonwrite __si_u.__si_disk.__sid_copyonwrite + +/* + * Special device management + */ +#define SPECHSZ 64 +#define SPECHASH(rdev) (((unsigned)(minor(rdev)))%SPECHSZ) + +/* + * Definitions of device driver entry switches + */ + +struct bio; +struct buf; +struct thread; +struct uio; +struct knote; +struct clonedevs; + +/* + * Note: d_thread_t is provided as a transition aid for those drivers + * that treat struct proc/struct thread as an opaque data type and + * exist in substantially the same form in both 4.x and 5.x. Writers + * of drivers that dips into the d_thread_t structure should use + * struct thread or struct proc as appropriate for the version of the + * OS they are using. It is provided in lieu of each device driver + * inventing its own way of doing this. While it does violate style(9) + * in a number of ways, this violation is deemed to be less + * important than the benefits that a uniform API between releases + * gives. + * + * Users of struct thread/struct proc that aren't device drivers should + * not use d_thread_t. + */ + +typedef struct thread d_thread_t; + +typedef int d_open_t(dev_t dev, int oflags, int devtype, struct thread *td); +typedef int d_fdopen_t(dev_t dev, int oflags, struct thread *td, int fdidx); +typedef int d_close_t(dev_t dev, int fflag, int devtype, struct thread *td); +typedef void d_strategy_t(struct bio *bp); +typedef int d_ioctl_t(dev_t dev, u_long cmd, caddr_t data, + int fflag, struct thread *td); + +typedef int d_read_t(dev_t dev, struct uio *uio, int ioflag); +typedef int d_write_t(dev_t dev, struct uio *uio, int ioflag); +typedef int d_poll_t(dev_t dev, int events, struct thread *td); +typedef int d_kqfilter_t(dev_t dev, struct knote *kn); +typedef int d_mmap_t(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, + int nprot); + +typedef int l_open_t(dev_t dev, struct tty *tp); +typedef int l_close_t(struct tty *tp, int flag); +typedef int l_read_t(struct tty *tp, struct uio *uio, int flag); +typedef int l_write_t(struct tty *tp, struct uio *uio, int flag); +typedef int l_ioctl_t(struct tty *tp, u_long cmd, caddr_t data, + int flag, struct thread *td); +typedef int l_rint_t(int c, struct tty *tp); +typedef int l_start_t(struct tty *tp); +typedef int l_modem_t(struct tty *tp, int flag); + +typedef int dumper_t( + void *priv, /* Private to the driver. */ + void *virtual, /* Virtual (mapped) address. */ + vm_offset_t physical, /* Physical address of virtual. */ + off_t offset, /* Byte-offset to write at. */ + size_t length); /* Number of bytes to dump. */ + +#define DEV_STRATEGY(bp) dev_strategy(bp) + +#endif /* _KERNEL */ + +/* + * Types for d_flags. + */ +#define D_TAPE 0x0001 +#define D_DISK 0x0002 +#define D_TTY 0x0004 +#define D_MEM 0x0008 + +#ifdef _KERNEL + +#define D_TYPEMASK 0xffff + +/* + * Flags for d_flags which the drivers can set. + */ +#define D_MEMDISK 0x00010000 /* memory type disk */ +#define D_TRACKCLOSE 0x00080000 /* track all closes */ +#define D_MMAP_ANON 0x00100000 /* special treatment in vm_mmap.c */ +#define D_PSEUDO 0x00200000 /* make_dev() can return NULL */ +#define D_NEEDGIANT 0x00400000 /* driver want Giant */ + +/* + * Version numbers. + */ +#define D_VERSION_00 0x20011966 +#define D_VERSION D_VERSION_00 + +/* + * Flags used for internal housekeeping + */ +#define D_INIT 0x80000000 /* cdevsw initialized */ +#define D_ALLOCMAJ 0x40000000 /* major# is allocated */ + +/* + * Character device switch table + */ +struct cdevsw { + int d_version; + int d_maj; + u_int d_flags; + const char *d_name; + d_open_t *d_open; + d_fdopen_t *d_fdopen; + d_close_t *d_close; + d_read_t *d_read; + d_write_t *d_write; + d_ioctl_t *d_ioctl; + d_poll_t *d_poll; + d_mmap_t *d_mmap; + d_strategy_t *d_strategy; + dumper_t *d_dump; + d_kqfilter_t *d_kqfilter; + + /* These fields should not be messed with by drivers */ + LIST_ENTRY(cdevsw) d_list; + LIST_HEAD(, cdev) d_devs; + int d_refcount; +}; + +/* + * Line discipline switch table + */ +struct linesw { + l_open_t *l_open; + l_close_t *l_close; + l_read_t *l_read; + l_write_t *l_write; + l_ioctl_t *l_ioctl; + l_rint_t *l_rint; + l_start_t *l_start; + l_modem_t *l_modem; + u_char l_hotchar; +}; + +extern struct linesw linesw[]; +extern int nlinesw; + +int ldisc_register(int , struct linesw *); +void ldisc_deregister(int); +#define LDISC_LOAD -1 /* Loadable line discipline */ +#endif /* _KERNEL */ + +#ifdef _KERNEL + +#define NUMCDEVSW 256 + +/* + * XXX: do not use MAJOR_AUTO unless you have no choice. In general drivers + * should just not initialize .d_maj and that will DTRT. + */ +#define MAJOR_AUTO 0 /* XXX: Not GM */ + +l_ioctl_t l_nullioctl; +l_read_t l_noread; +l_write_t l_nowrite; + +struct module; + +struct devsw_module_data { + int (*chainevh)(struct module *, int, void *); /* next handler */ + void *chainarg; /* arg for next event handler */ + /* Do not initialize fields hereafter */ +}; + +#define DEV_MODULE(name, evh, arg) \ +static moduledata_t name##_mod = { \ + #name, \ + evh, \ + arg \ +}; \ +DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) + + +void clone_setup(struct clonedevs **cdp); +void clone_cleanup(struct clonedevs **); +#define CLONE_UNITMASK 0xfffff +#define CLONE_FLAG0 (CLONE_UNITMASK + 1) +int clone_create(struct clonedevs **, struct cdevsw *, int *unit, dev_t *dev, u_int extra); + +int count_dev(dev_t _dev); +void destroy_dev(dev_t _dev); +struct cdevsw *devsw(dev_t _dev); +void cdevsw_ref(struct cdevsw *); +void cdevsw_rel(struct cdevsw *); +const char *devtoname(dev_t _dev); +int dev_named(dev_t _pdev, const char *_name); +void dev_depends(dev_t _pdev, dev_t _cdev); +void dev_ref(dev_t dev); +void dev_rel(dev_t dev); +void dev_strategy(struct buf *bp); +dev_t makebdev(int _maj, int _min); +dev_t make_dev(struct cdevsw *_devsw, int _minor, uid_t _uid, gid_t _gid, + int _perms, const char *_fmt, ...) __printflike(6, 7); +dev_t make_dev_alias(dev_t _pdev, const char *_fmt, ...) __printflike(2, 3); +int dev2unit(dev_t _dev); +int unit2minor(int _unit); +void setconf(void); +dev_t getdiskbyname(char *_name); + +void devfs_create(dev_t dev); +void devfs_destroy(dev_t dev); + +#define UID_ROOT 0 +#define UID_BIN 3 +#define UID_UUCP 66 + +#define GID_WHEEL 0 +#define GID_KMEM 2 +#define GID_OPERATOR 5 +#define GID_BIN 7 +#define GID_GAMES 13 +#define GID_DIALER 68 + +typedef void (*dev_clone_fn)(void *arg, char *name, int namelen, dev_t *result); + +int dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit); +EVENTHANDLER_DECLARE(dev_clone, dev_clone_fn); + +/* Stuff relating to kernel-dump */ + +struct dumperinfo { + dumper_t *dumper; /* Dumping function. */ + void *priv; /* Private parts. */ + u_int blocksize; /* Size of block in bytes. */ + off_t mediaoffset; /* Initial offset in bytes. */ + off_t mediasize; /* Space available in bytes. */ +}; + +int set_dumper(struct dumperinfo *); +void dumpsys(struct dumperinfo *); +extern int dumping; /* system is dumping */ + +#endif /* _KERNEL */ + +#endif /* !_SYS_CONF_H_ */ diff --git a/src/include/sys/cons.h b/src/include/sys/cons.h new file mode 100644 index 0000000..3ef18f1 --- /dev/null +++ b/src/include/sys/cons.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1991 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + * 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. + * + * from: @(#)cons.h 7.2 (Berkeley) 5/9/91 + * $FreeBSD: src/sys/sys/cons.h,v 1.36 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _MACHINE_CONS_H_ +#define _MACHINE_CONS_H_ + +struct consdev; +typedef void cn_probe_t(struct consdev *); +typedef void cn_init_t(struct consdev *); +typedef void cn_term_t(struct consdev *); +typedef int cn_getc_t(struct consdev *); +typedef int cn_checkc_t(struct consdev *); +typedef void cn_putc_t(struct consdev *, int); +typedef void cn_dbctl_t(struct consdev *, int); + +struct consdev { + cn_probe_t *cn_probe; + /* probe hardware and fill in consdev info */ + cn_init_t *cn_init; + /* turn on as console */ + cn_term_t *cn_term; + /* turn off as console */ + cn_getc_t *cn_getc; + /* kernel getchar interface */ + cn_checkc_t *cn_checkc; + /* kernel "return char if available" interface */ + cn_putc_t *cn_putc; + /* kernel putchar interface */ + cn_dbctl_t *cn_dbctl; + /* debugger control interface */ + struct tty *cn_tp; /* tty structure for console device */ + short cn_pri; /* pecking order; the higher the better */ + void *cn_arg; /* drivers method argument */ + int cn_unit; /* some drivers prefer this */ + int cn_flags; /* capabilities of this console */ + char cn_name[SPECNAMELEN + 1]; /* console (device) name */ +}; + +/* values for cn_pri - reflect our policy for console selection */ +#define CN_DEAD 0 /* device doesn't exist */ +#define CN_LOW 1 /* device is a last restort only */ +#define CN_NORMAL 2 /* device exists but is nothing special */ +#define CN_INTERNAL 3 /* "internal" bit-mapped display */ +#define CN_REMOTE 4 /* serial interface with remote bit set */ + +/* Values for cn_flags. */ +#define CN_FLAG_NODEBUG 0x00000001 /* Not supported with debugger. */ +#define CN_FLAG_NOAVAIL 0x00000002 /* Temporarily not available. */ + +#ifdef _KERNEL + +#define CONS_DRIVER(name, probe, init, term, getc, checkc, putc, dbctl) \ + static struct consdev name##_consdev = { \ + probe, init, term, getc, checkc, putc, dbctl \ + }; \ + DATA_SET(cons_set, name##_consdev) + +/* Other kernel entry points. */ +void cninit(void); +void cninit_finish(void); +int cnadd(struct consdev *); +void cnavailable(struct consdev *, int); +void cnremove(struct consdev *); +void cnselect(struct consdev *); +int cncheckc(void); +int cngetc(void); +void cndbctl(int); +void cnputc(int); +int cnunavailable(void); + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_CONS_H_ */ diff --git a/src/include/sys/consio.h b/src/include/sys/consio.h new file mode 100644 index 0000000..742a12a --- /dev/null +++ b/src/include/sys/consio.h @@ -0,0 +1,444 @@ +/*- + * Copyright (c) 1991-1996 S�ren Schmidt + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/consio.h,v 1.16 2002/08/19 16:32:09 sobomax Exp $ + */ + +#ifndef _SYS_CONSIO_H_ +#define _SYS_CONSIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Console ioctl commands. Some commands are named as KDXXXX, GIO_XXX, and + * PIO_XXX, rather than CONS_XXX, for historical and compatibility reasons. + * Some other CONS_XXX commands are works as wrapper around frame buffer + * ioctl commands FBIO_XXX. Do not try to change all these commands, + * otherwise we shall have compatibility problems. + */ + +/* get/set video mode */ +#define KD_TEXT 0 /* set text mode restore fonts */ +#define KD_TEXT0 0 /* ditto */ +#define KD_GRAPHICS 1 /* set graphics mode */ +#define KD_TEXT1 2 /* set text mode !restore fonts */ +#define KD_PIXEL 3 /* set pixel mode */ +#define KDGETMODE _IOR('K', 9, int) +#define KDSETMODE _IO('K', 10 /*, int */) + +/* set border color */ +#define KDSBORDER _IO('K', 13 /*, int */) + +/* set up raster(pixel) text mode */ +struct _scr_size { + int scr_size[3]; +}; +typedef struct _scr_size scr_size_t; + +#define KDRASTER _IOW('K', 100, scr_size_t) + +/* get/set screen char map */ +struct _scrmap { + char scrmap[256]; +}; +typedef struct _scrmap scrmap_t; + +#define GIO_SCRNMAP _IOR('k', 2, scrmap_t) +#define PIO_SCRNMAP _IOW('k', 3, scrmap_t) + +/* get the current text attribute */ +#define GIO_ATTR _IOR('a', 0, int) + +/* get the current text color */ +#define GIO_COLOR _IOR('c', 0, int) + +/* get the adapter type (equivalent to FBIO_ADPTYPE) */ +#define CONS_CURRENT _IOR('c', 1, int) + +/* get the current video mode (equivalent to FBIO_GETMODE) */ +#define CONS_GET _IOR('c', 2, int) + +/* not supported? */ +#define CONS_IO _IO('c', 3) + +/* set blank time interval */ +#define CONS_BLANKTIME _IOW('c', 4, int) + +/* set/get the screen saver (these ioctls are current noop) */ +struct ssaver { +#define MAXSSAVER 16 + char name[MAXSSAVER]; + int num; + long time; +}; +typedef struct ssaver ssaver_t; + +#define CONS_SSAVER _IOW('c', 5, ssaver_t) +#define CONS_GSAVER _IOWR('c', 6, ssaver_t) + +/* set the text cursor type (obsolete, see CONS_CURSORSHAPE below) */ +/* +#define CONS_BLINK_CURSOR (1 << 0) +#define CONS_CHAR_CURSOR (1 << 1) +*/ +#define CONS_CURSORTYPE _IOW('c', 7, int) + +/* set the bell type to audible or visual */ +#define CONS_VISUAL_BELL (1 << 0) +#define CONS_QUIET_BELL (1 << 1) +#define CONS_BELLTYPE _IOW('c', 8, int) + +/* set the history (scroll back) buffer size (in lines) */ +#define CONS_HISTORY _IOW('c', 9, int) + +/* clear the history (scroll back) buffer */ +#define CONS_CLRHIST _IO('c', 10) + +/* mouse cursor ioctl */ +struct mouse_data { + int x; + int y; + int z; + int buttons; +}; +typedef struct mouse_data mouse_data_t; + +struct mouse_mode { + int mode; + int signal; +}; +typedef struct mouse_mode mouse_mode_t; + +struct mouse_event { + int id; /* one based */ + int value; +}; +typedef struct mouse_event mouse_event_t; + +struct mouse_info { + int operation; +#define MOUSE_SHOW 0x01 +#define MOUSE_HIDE 0x02 +#define MOUSE_MOVEABS 0x03 +#define MOUSE_MOVEREL 0x04 +#define MOUSE_GETINFO 0x05 +#define MOUSE_MODE 0x06 +#define MOUSE_ACTION 0x07 +#define MOUSE_MOTION_EVENT 0x08 +#define MOUSE_BUTTON_EVENT 0x09 +#define MOUSE_MOUSECHAR 0x0a + union { + mouse_data_t data; + mouse_mode_t mode; + mouse_event_t event; + int mouse_char; + } u; +}; +typedef struct mouse_info mouse_info_t; + +#define CONS_MOUSECTL _IOWR('c', 10, mouse_info_t) + +/* see if the vty has been idle */ +#define CONS_IDLE _IOR('c', 11, int) + +/* set the screen saver mode */ +#define CONS_NO_SAVER (-1) +#define CONS_LKM_SAVER 0 +#define CONS_USR_SAVER 1 +#define CONS_SAVERMODE _IOW('c', 12, int) + +/* start the screen saver */ +#define CONS_SAVERSTART _IOW('c', 13, int) + +/* set the text cursor shape (see also CONS_CURSORTYPE above) */ +#define CONS_BLINK_CURSOR (1 << 0) +#define CONS_CHAR_CURSOR (1 << 1) +#define CONS_HIDDEN_CURSOR (1 << 2) +#define CONS_CURSOR_ATTRS (CONS_BLINK_CURSOR | CONS_CHAR_CURSOR | \ + CONS_HIDDEN_CURSOR) +#define CONS_RESET_CURSOR (1 << 30) +#define CONS_LOCAL_CURSOR (1 << 31) +#define CONS_CURSOR_FLAGS (CONS_RESET_CURSOR | CONS_LOCAL_CURSOR) +struct cshape { + /* shape[0]: flags, shape[1]: base, shape[2]: height */ + int shape[3]; +}; +#define CONS_GETCURSORSHAPE _IOWR('c', 14, struct cshape) +#define CONS_SETCURSORSHAPE _IOW('c', 15, struct cshape) + +/* set/get font data */ +struct fnt8 { + char fnt8x8[8*256]; +}; +typedef struct fnt8 fnt8_t; + +struct fnt14 { + char fnt8x14[14*256]; +}; +typedef struct fnt14 fnt14_t; + +struct fnt16 { + char fnt8x16[16*256]; +}; +typedef struct fnt16 fnt16_t; + +#define PIO_FONT8x8 _IOW('c', 64, fnt8_t) +#define GIO_FONT8x8 _IOR('c', 65, fnt8_t) +#define PIO_FONT8x14 _IOW('c', 66, fnt14_t) +#define GIO_FONT8x14 _IOR('c', 67, fnt14_t) +#define PIO_FONT8x16 _IOW('c', 68, fnt16_t) +#define GIO_FONT8x16 _IOR('c', 69, fnt16_t) + +/* get video mode information */ +struct colors { + char fore; + char back; +}; + +struct vid_info { + short size; + short m_num; + u_short font_size; + u_short mv_row, mv_col; + u_short mv_rsz, mv_csz; + u_short mv_hsz; + struct colors mv_norm, + mv_rev, + mv_grfc; + u_char mv_ovscan; + u_char mk_keylock; +}; +typedef struct vid_info vid_info_t; + +#define CONS_GETINFO _IOWR('c', 73, vid_info_t) + +/* get version */ +#define CONS_GETVERS _IOR('c', 74, int) + +/* get the video adapter index (equivalent to FBIO_ADAPTER) */ +#define CONS_CURRENTADP _IOR('c', 100, int) + +/* get the video adapter information (equivalent to FBIO_ADPINFO) */ +#define CONS_ADPINFO _IOWR('c', 101, video_adapter_info_t) + +/* get the video mode information (equivalent to FBIO_MODEINFO) */ +#define CONS_MODEINFO _IOWR('c', 102, video_info_t) + +/* find a video mode (equivalent to FBIO_FINDMODE) */ +#define CONS_FINDMODE _IOWR('c', 103, video_info_t) + +/* set the frame buffer window origin (equivalent to FBIO_SETWINORG) */ +#define CONS_SETWINORG _IO('c', 104 /*, u_int */) + +/* use the specified keyboard */ +#define CONS_SETKBD _IO('c', 110 /*, int */) + +/* release the current keyboard */ +#define CONS_RELKBD _IO('c', 111) + +struct scrshot { + int x; + int y; + int xsize; + int ysize; + u_int16_t* buf; +}; +typedef struct scrshot scrshot_t; + +/* Snapshot the current video buffer */ +#define CONS_SCRSHOT _IOWR('c', 105, scrshot_t) + +/* get/set the current terminal emulator info. */ +#define TI_NAME_LEN 32 +#define TI_DESC_LEN 64 + +struct term_info { + int ti_index; + int ti_flags; + u_char ti_name[TI_NAME_LEN]; + u_char ti_desc[TI_DESC_LEN]; +}; +typedef struct term_info term_info_t; + +#define CONS_GETTERM _IOWR('c', 112, term_info_t) +#define CONS_SETTERM _IOW('c', 113, term_info_t) + +#ifdef PC98 +#define ADJUST_CLOCK _IO('t',100) /* for 98note resume */ +#endif + +/* + * Vty switching ioctl commands. + */ + +/* get the next available vty */ +#define VT_OPENQRY _IOR('v', 1, int) + +/* set/get vty switching mode */ +#ifndef _VT_MODE_DECLARED +#define _VT_MODE_DECLARED +struct vt_mode { + char mode; +#define VT_AUTO 0 /* switching is automatic */ +#define VT_PROCESS 1 /* switching controlled by prog */ +#define VT_KERNEL 255 /* switching controlled in kernel */ + char waitv; /* not implemented yet SOS */ + short relsig; + short acqsig; + short frsig; /* not implemented yet SOS */ +}; +typedef struct vt_mode vtmode_t; +#endif /* !_VT_MODE_DECLARED */ + +#define VT_SETMODE _IOW('v', 2, vtmode_t) +#define VT_GETMODE _IOR('v', 3, vtmode_t) + +/* acknowledge release or acquisition of a vty */ +#define VT_FALSE 0 +#define VT_TRUE 1 +#define VT_ACKACQ 2 +#define VT_RELDISP _IO('v', 4 /*, int */) + +/* activate the specified vty */ +#define VT_ACTIVATE _IO('v', 5 /*, int */) + +/* wait until the specified vty is activate */ +#define VT_WAITACTIVE _IO('v', 6 /*, int */) + +/* get the currently active vty */ +#define VT_GETACTIVE _IOR('v', 7, int) + +/* get the index of the vty */ +#define VT_GETINDEX _IOR('v', 8, int) + +/* prevent switching vtys */ +#define VT_LOCKSWITCH _IOW('v', 9, int) + +/* + * Video mode switching ioctl. See sys/fbio.h for mode numbers. + */ + +#define SW_B40x25 _IO('S', M_B40x25) +#define SW_C40x25 _IO('S', M_C40x25) +#define SW_B80x25 _IO('S', M_B80x25) +#define SW_C80x25 _IO('S', M_C80x25) +#define SW_BG320 _IO('S', M_BG320) +#define SW_CG320 _IO('S', M_CG320) +#define SW_BG640 _IO('S', M_BG640) +#define SW_EGAMONO80x25 _IO('S', M_EGAMONO80x25) +#define SW_CG320_D _IO('S', M_CG320_D) +#define SW_CG640_E _IO('S', M_CG640_E) +#define SW_EGAMONOAPA _IO('S', M_EGAMONOAPA) +#define SW_CG640x350 _IO('S', M_CG640x350) +#define SW_ENH_MONOAPA2 _IO('S', M_ENHMONOAPA2) +#define SW_ENH_CG640 _IO('S', M_ENH_CG640) +#define SW_ENH_B40x25 _IO('S', M_ENH_B40x25) +#define SW_ENH_C40x25 _IO('S', M_ENH_C40x25) +#define SW_ENH_B80x25 _IO('S', M_ENH_B80x25) +#define SW_ENH_C80x25 _IO('S', M_ENH_C80x25) +#define SW_ENH_B80x43 _IO('S', M_ENH_B80x43) +#define SW_ENH_C80x43 _IO('S', M_ENH_C80x43) +#define SW_MCAMODE _IO('S', M_MCA_MODE) +#define SW_VGA_C40x25 _IO('S', M_VGA_C40x25) +#define SW_VGA_C80x25 _IO('S', M_VGA_C80x25) +#define SW_VGA_C80x30 _IO('S', M_VGA_C80x30) +#define SW_VGA_C80x50 _IO('S', M_VGA_C80x50) +#define SW_VGA_C80x60 _IO('S', M_VGA_C80x60) +#define SW_VGA_M80x25 _IO('S', M_VGA_M80x25) +#define SW_VGA_M80x30 _IO('S', M_VGA_M80x30) +#define SW_VGA_M80x50 _IO('S', M_VGA_M80x50) +#define SW_VGA_M80x60 _IO('S', M_VGA_M80x60) +#define SW_VGA11 _IO('S', M_VGA11) +#define SW_BG640x480 _IO('S', M_VGA11) +#define SW_VGA12 _IO('S', M_VGA12) +#define SW_CG640x480 _IO('S', M_VGA12) +#define SW_VGA13 _IO('S', M_VGA13) +#define SW_VGA_CG320 _IO('S', M_VGA13) +#define SW_VGA_CG640 _IO('S', M_VGA_CG640) +#define SW_VGA_MODEX _IO('S', M_VGA_MODEX) + +#define SW_PC98_80x25 _IO('S', M_PC98_80x25) +#define SW_PC98_80x30 _IO('S', M_PC98_80x30) +#define SW_PC98_EGC640x400 _IO('S', M_PC98_EGC640x400) +#define SW_PC98_PEGC640x400 _IO('S', M_PC98_PEGC640x400) +#define SW_PC98_PEGC640x480 _IO('S', M_PC98_PEGC640x480) + +#define SW_VGA_C90x25 _IO('S', M_VGA_C90x25) +#define SW_VGA_M90x25 _IO('S', M_VGA_M90x25) +#define SW_VGA_C90x30 _IO('S', M_VGA_C90x30) +#define SW_VGA_M90x30 _IO('S', M_VGA_M90x30) +#define SW_VGA_C90x43 _IO('S', M_VGA_C90x43) +#define SW_VGA_M90x43 _IO('S', M_VGA_M90x43) +#define SW_VGA_C90x50 _IO('S', M_VGA_C90x50) +#define SW_VGA_M90x50 _IO('S', M_VGA_M90x50) +#define SW_VGA_C90x60 _IO('S', M_VGA_C90x60) +#define SW_VGA_M90x60 _IO('S', M_VGA_M90x60) + +#define SW_TEXT_80x25 _IO('S', M_TEXT_80x25) +#define SW_TEXT_80x30 _IO('S', M_TEXT_80x30) +#define SW_TEXT_80x43 _IO('S', M_TEXT_80x43) +#define SW_TEXT_80x50 _IO('S', M_TEXT_80x50) +#define SW_TEXT_80x60 _IO('S', M_TEXT_80x60) +#define SW_TEXT_132x25 _IO('S', M_TEXT_132x25) +#define SW_TEXT_132x30 _IO('S', M_TEXT_132x30) +#define SW_TEXT_132x43 _IO('S', M_TEXT_132x43) +#define SW_TEXT_132x50 _IO('S', M_TEXT_132x50) +#define SW_TEXT_132x60 _IO('S', M_TEXT_132x60) + +#define SW_VESA_CG640x400 _IO('V', M_VESA_CG640x400 - M_VESA_BASE) +#define SW_VESA_CG640x480 _IO('V', M_VESA_CG640x480 - M_VESA_BASE) +#define SW_VESA_800x600 _IO('V', M_VESA_800x600 - M_VESA_BASE) +#define SW_VESA_CG800x600 _IO('V', M_VESA_CG800x600 - M_VESA_BASE) +#define SW_VESA_1024x768 _IO('V', M_VESA_1024x768 - M_VESA_BASE) +#define SW_VESA_CG1024x768 _IO('V', M_VESA_CG1024x768 - M_VESA_BASE) +#define SW_VESA_1280x1024 _IO('V', M_VESA_1280x1024 - M_VESA_BASE) +#define SW_VESA_CG1280x1024 _IO('V', M_VESA_CG1280x1024 - M_VESA_BASE) +#define SW_VESA_C80x60 _IO('V', M_VESA_C80x60 - M_VESA_BASE) +#define SW_VESA_C132x25 _IO('V', M_VESA_C132x25 - M_VESA_BASE) +#define SW_VESA_C132x43 _IO('V', M_VESA_C132x43 - M_VESA_BASE) +#define SW_VESA_C132x50 _IO('V', M_VESA_C132x50 - M_VESA_BASE) +#define SW_VESA_C132x60 _IO('V', M_VESA_C132x60 - M_VESA_BASE) +#define SW_VESA_32K_320 _IO('V', M_VESA_32K_320 - M_VESA_BASE) +#define SW_VESA_64K_320 _IO('V', M_VESA_64K_320 - M_VESA_BASE) +#define SW_VESA_FULL_320 _IO('V', M_VESA_FULL_320 - M_VESA_BASE) +#define SW_VESA_32K_640 _IO('V', M_VESA_32K_640 - M_VESA_BASE) +#define SW_VESA_64K_640 _IO('V', M_VESA_64K_640 - M_VESA_BASE) +#define SW_VESA_FULL_640 _IO('V', M_VESA_FULL_640 - M_VESA_BASE) +#define SW_VESA_32K_800 _IO('V', M_VESA_32K_800 - M_VESA_BASE) +#define SW_VESA_64K_800 _IO('V', M_VESA_64K_800 - M_VESA_BASE) +#define SW_VESA_FULL_800 _IO('V', M_VESA_FULL_800 - M_VESA_BASE) +#define SW_VESA_32K_1024 _IO('V', M_VESA_32K_1024 - M_VESA_BASE) +#define SW_VESA_64K_1024 _IO('V', M_VESA_64K_1024 - M_VESA_BASE) +#define SW_VESA_FULL_1024 _IO('V', M_VESA_FULL_1024 - M_VESA_BASE) +#define SW_VESA_32K_1280 _IO('V', M_VESA_32K_1280 - M_VESA_BASE) +#define SW_VESA_64K_1280 _IO('V', M_VESA_64K_1280 - M_VESA_BASE) +#define SW_VESA_FULL_1280 _IO('V', M_VESA_FULL_1280 - M_VESA_BASE) + +#endif /* !_SYS_CONSIO_H_ */ diff --git a/src/include/sys/copyright.h b/src/include/sys/copyright.h new file mode 100644 index 0000000..87b3b60 --- /dev/null +++ b/src/include/sys/copyright.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 1992-2004 The FreeBSD Project. 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. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/copyright.h,v 1.17 2003/12/31 22:27:51 imp Exp $ + */ + + +/* Copyrights macros */ + +/* FreeBSD */ +#define COPYRIGHT_FreeBSD \ + "Copyright (c) 1992-2004 The FreeBSD Project.\n" + +/* Berkeley */ +#define COPYRIGHT_UCB \ + "Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994\n\tThe Regents of the University of California. All rights reserved.\n" + +/* a port of FreeBSD to the NEC PC98, Japan */ +#define COPYRIGHT_PC98 \ + "Copyright (c) 1994-2004 FreeBSD(98) porting team.\nCopyright (c) 1992 A.Kojima F.Ukai M.Ishii (KMC).\n" + +#if defined(PC98) +char copyright[] = COPYRIGHT_FreeBSD/**/COPYRIGHT_PC98/**/COPYRIGHT_UCB; + +#else +char copyright[] = COPYRIGHT_FreeBSD/**/COPYRIGHT_UCB; +#endif diff --git a/src/include/sys/ctype.h b/src/include/sys/ctype.h new file mode 100644 index 0000000..5070853 --- /dev/null +++ b/src/include/sys/ctype.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 1982, 1988, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * $FreeBSD: src/sys/sys/ctype.h,v 1.4 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_CTYPE_H_ +#define _SYS_CTYPE_H_ + +#ifdef _KERNEL + +#define isspace(c) ((c) == ' ' || ((c) >= '\t' && (c) <= '\r')) +#define isascii(c) (((c) & ~0x7f) == 0) +#define isupper(c) ((c) >= 'A' && (c) <= 'Z') +#define islower(c) ((c) >= 'a' && (c) <= 'z') +#define isalpha(c) (isupper(c) || islower(c)) +#define isdigit(c) ((c) >= '0' && (c) <= '9') +#define isxdigit(c) (isdigit(c) \ + || ((c) >= 'A' && (c) <= 'F') \ + || ((c) >= 'a' && (c) <= 'f')) +#define isprint(c) ((c) >= ' ' && (c) <= '~') + +#define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z'))) +#define tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z'))) + +#endif +#endif /* !_SYS_CTYPE_H_ */ diff --git a/src/include/sys/dataacq.h b/src/include/sys/dataacq.h new file mode 100644 index 0000000..300fadc --- /dev/null +++ b/src/include/sys/dataacq.h @@ -0,0 +1,37 @@ +/* + * Header for general data acquisition definitions. + * + * $FreeBSD: src/sys/sys/dataacq.h,v 1.5 2000/05/01 20:11:13 peter Exp $ + */ + +#ifndef _SYS_DATAACQ_H_ +#define _SYS_DATAACQ_H_ + +#include + +/* Period in microseconds between analog I/O samples. + */ +#define AD_MICRO_PERIOD_SET _IOW('A', 1, long) +#define AD_MICRO_PERIOD_GET _IOR('A', 2, long) + +/* Gain list support. Initially all gains are 1. If the board + * supports no gains at all then AD_NGAINS_GET will return a 0. + * + * AD_NGAINS_GET: Return the number of gains the board supports + * + * AD_SUPPORTED_GAINS: Get the supported gains. + * The driver will copy out "ngains" doubles, + * where "ngains" is obtained with AD_NGAINS_GET. + * + * AD_GAINS_SET: Set the gain list. The driver will copy in "ngains" ints. + * + * AD_GAINS_GET: Get the gain list. The driver will copy out "ngains" ints. + */ + +#define AD_NGAINS_GET _IOR('A', 3, int) +#define AD_NCHANS_GET _IOR('A', 4, int) +#define AD_SUPPORTED_GAINS _IO('A', 5) +#define AD_GAINS_SET _IO('A', 6) +#define AD_GAINS_GET _IO('A', 7) + +#endif /* !_SYS_DATAACQ_H_ */ diff --git a/src/include/sys/device_port.h b/src/include/sys/device_port.h new file mode 100644 index 0000000..977bf7a --- /dev/null +++ b/src/include/sys/device_port.h @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 1999 Mitsuru IWASAKI + * Copyright (c) 1999 Takanori Watanabe + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/device_port.h,v 1.1 2000/10/23 12:55:51 non Exp $ + */ + +#if defined(__NetBSD__) +# include +#elif defined(__FreeBSD__) +# if __FreeBSD_version >= 400001 +# include +# include +# else +# include +# endif +#endif + +/* + * Macro's to cope with the differences between operating systems and versions. + */ + +#if defined(__NetBSD__) +# define DEVPORT_DEVICE struct device +# define DEVPORT_DEVNAME(dev) (dev).dv_xname +# define DEVPORT_DEVUNIT(dev) (dev).dv_unit + +#elif defined(__FreeBSD__) +/* + * FreeBSD (compatibility for struct device) + */ +#if __FreeBSD_version >= 400001 +# define DEVPORT_DEVICE device_t +# define DEVPORT_DEVNAME(dev) device_get_name(dev) +# define DEVPORT_DEVUNIT(dev) device_get_unit(dev) +# define DEVPORT_ALLOC_SOFTC(dev) device_get_softc(dev) +# define DEVPORT_GET_SOFTC(dev) device_get_softc(dev) + +# define UNCONF 1 /* print " not configured\n" */ + +#else + +# define DEVPORT_DEVICE struct device +# define DEVPORT_DEVNAME(dev) (dev).dv_xname +# define DEVPORT_DEVUNIT(dev) (dev).dv_unit +# ifdef DEVPORT_ALLOCSOFTCFUNC +# define DEVPORT_ALLOC_SOFTC(dev) (DEVPORT_ALLOCSOFTCFUNC)((dev).dv_unit) +# else +# define DEVPORT_ALLOC_SOFTC(dev) DEVPORT_ALLOCSOFTCFUNC_is_not_defined_prior_than_device_port_h +# endif +# ifdef DEVPORT_SOFTCARRAY +# define DEVPORT_GET_SOFTC(dev) (DEVPORT_SOFTCARRAY)[(dev).dv_unit] +# else +# define DEVPORT_GET_SOFTC(dev) DEVPORT_SOFTCARRAY_is_not_defined_prior_than_device_port_h +# endif + +#endif + +/* + * PC-Card device driver (compatibility for struct pccard_devinfo *) + */ +#if __FreeBSD_version >= 400001 +# define DEVPORT_PDEVICE device_t +# define DEVPORT_PDEVUNIT(pdev) device_get_unit(pdev) +# define DEVPORT_PDEVFLAGS(pdev) device_get_flags(pdev) +# define DEVPORT_PDEVIOBASE(pdev) bus_get_resource_start(pdev, SYS_RES_IOPORT, 0) +# define DEVPORT_PDEVIRQ(pdev) bus_get_resource_start(pdev, SYS_RES_IRQ, 0) +# define DEVPORT_PDEVMADDR(pdev) bus_get_resource_start(pdev, SYS_RES_MEMORY, 0) +# define DEVPORT_PDEVALLOC_SOFTC(pdev) device_get_softc(pdev) +# define DEVPORT_PDEVGET_SOFTC(pdev) device_get_softc(pdev) + +#else + +# define DEVPORT_PDEVICE struct pccard_devinfo * +# define DEVPORT_PDEVUNIT(pdev) (pdev)->pd_unit +# define DEVPORT_PDEVFLAGS(pdev) (pdev)->pd_flags +# define DEVPORT_PDEVIOBASE(pdev) (pdev)->pd_iobase +# define DEVPORT_PDEVIRQ(pdev) (pdev)->pd_irq +# define DEVPORT_PDEVMADDR(pdev) (pdev)->pd_maddr +# ifdef DEVPORT_ALLOCSOFTCFUNC +# define DEVPORT_PDEVALLOC_SOFTC(pdev) (DEVPORT_ALLOCSOFTCFUNC)((pdev)->pd_unit) +# else +# define DEVPORT_PDEVALLOC_SOFTC(pdev) DEVPORT_ALLOCSOFTCFUNC_is_not_defined_prior_than_device_port_h +# endif +# ifdef DEVPORT_SOFTCARRAY +# define DEVPORT_PDEVGET_SOFTC(pdev) (DEVPORT_SOFTCARRAY)[(pdev)->pd_unit] +# else +# define DEVPORT_PDEVGET_SOFTC(pdev) DEVPORT_SOFTCARRAY_is_not_defined_prior_than_device_port_h +# endif +#endif + +#endif /* __FreeBSD__ */ + diff --git a/src/include/sys/devicestat.h b/src/include/sys/devicestat.h new file mode 100644 index 0000000..24f3a67 --- /dev/null +++ b/src/include/sys/devicestat.h @@ -0,0 +1,204 @@ +/* + * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/devicestat.h,v 1.25 2003/05/31 21:10:01 phk Exp $ + */ + +#ifndef _DEVICESTAT_H +#define _DEVICESTAT_H + +#include +#include + +/* + * XXX: Should really be SPECNAMELEN + */ +#define DEVSTAT_NAME_LEN 16 + +/* + * device name for the mmap device + */ +#define DEVSTAT_DEVICE_NAME "devstat" + +/* + * ATTENTION: The devstat version below should be incremented any time a + * change is made in struct devstat, or any time a change is made in the + * enumerated types that struct devstat uses. (Only if those changes + * would require a recompile -- i.e. re-arranging the order of an + * enumerated type or something like that.) This version number is used by + * userland utilities to determine whether or not they are in sync with the + * kernel. + */ +#define DEVSTAT_VERSION 6 + +/* + * These flags specify which statistics features are supported or not + * supported by a particular device. The default is all statistics are + * supported. + */ +typedef enum { + DEVSTAT_ALL_SUPPORTED = 0x00, + DEVSTAT_NO_BLOCKSIZE = 0x01, + DEVSTAT_NO_ORDERED_TAGS = 0x02, + DEVSTAT_BS_UNAVAILABLE = 0x04 +} devstat_support_flags; + +typedef enum { + DEVSTAT_NO_DATA = 0x00, + DEVSTAT_READ = 0x01, + DEVSTAT_WRITE = 0x02, + DEVSTAT_FREE = 0x03 +} devstat_trans_flags; +#define DEVSTAT_N_TRANS_FLAGS 4 + +typedef enum { + DEVSTAT_TAG_SIMPLE = 0x00, + DEVSTAT_TAG_HEAD = 0x01, + DEVSTAT_TAG_ORDERED = 0x02, + DEVSTAT_TAG_NONE = 0x03 +} devstat_tag_type; + +typedef enum { + DEVSTAT_PRIORITY_MIN = 0x000, + DEVSTAT_PRIORITY_OTHER = 0x020, + DEVSTAT_PRIORITY_PASS = 0x030, + DEVSTAT_PRIORITY_FD = 0x040, + DEVSTAT_PRIORITY_WFD = 0x050, + DEVSTAT_PRIORITY_TAPE = 0x060, + DEVSTAT_PRIORITY_CD = 0x090, + DEVSTAT_PRIORITY_DISK = 0x110, + DEVSTAT_PRIORITY_ARRAY = 0x120, + DEVSTAT_PRIORITY_MAX = 0xfff +} devstat_priority; + +/* + * These types are intended to aid statistics gathering/display programs. + * The first 13 types (up to the 'target' flag) are identical numerically + * to the SCSI device type numbers. The next 3 types designate the device + * interface. Currently the choices are IDE, SCSI, and 'other'. The last + * flag specifies whether or not the given device is a passthrough device + * or not. If it is a passthrough device, the lower 4 bits specify which + * type of physical device lies under the passthrough device, and the next + * 4 bits specify the interface. + */ +typedef enum { + DEVSTAT_TYPE_DIRECT = 0x000, + DEVSTAT_TYPE_SEQUENTIAL = 0x001, + DEVSTAT_TYPE_PRINTER = 0x002, + DEVSTAT_TYPE_PROCESSOR = 0x003, + DEVSTAT_TYPE_WORM = 0x004, + DEVSTAT_TYPE_CDROM = 0x005, + DEVSTAT_TYPE_SCANNER = 0x006, + DEVSTAT_TYPE_OPTICAL = 0x007, + DEVSTAT_TYPE_CHANGER = 0x008, + DEVSTAT_TYPE_COMM = 0x009, + DEVSTAT_TYPE_ASC0 = 0x00a, + DEVSTAT_TYPE_ASC1 = 0x00b, + DEVSTAT_TYPE_STORARRAY = 0x00c, + DEVSTAT_TYPE_ENCLOSURE = 0x00d, + DEVSTAT_TYPE_FLOPPY = 0x00e, + DEVSTAT_TYPE_MASK = 0x00f, + DEVSTAT_TYPE_IF_SCSI = 0x010, + DEVSTAT_TYPE_IF_IDE = 0x020, + DEVSTAT_TYPE_IF_OTHER = 0x030, + DEVSTAT_TYPE_IF_MASK = 0x0f0, + DEVSTAT_TYPE_PASS = 0x100 +} devstat_type_flags; + +/* + * XXX: Next revision should add + * off_t offset[DEVSTAT_N_TRANS_FLAGS]; + * XXX: which should contain the offset of the last completed transfer. + */ +struct devstat { + /* Internal house-keeping fields */ + u_int sequence0; /* Update sequence# */ + int allocated; /* Allocated entry */ + u_int start_count; /* started ops */ + u_int end_count; /* completed ops */ + struct bintime busy_from; /* + * busy time unaccounted + * for since this time + */ + STAILQ_ENTRY(devstat) dev_links; + u_int32_t device_number; /* + * Devstat device + * number. + */ + char device_name[DEVSTAT_NAME_LEN]; + int unit_number; + u_int64_t bytes[DEVSTAT_N_TRANS_FLAGS]; + u_int64_t operations[DEVSTAT_N_TRANS_FLAGS]; + struct bintime duration[DEVSTAT_N_TRANS_FLAGS]; + struct bintime busy_time; + struct bintime creation_time; /* + * Time the device was + * created. + */ + u_int32_t block_size; /* Block size, bytes */ + u_int64_t tag_types[3]; /* + * The number of + * simple, ordered, + * and head of queue + * tags sent. + */ + devstat_support_flags flags; /* + * Which statistics + * are supported by a + * given device. + */ + devstat_type_flags device_type; /* Device type */ + devstat_priority priority; /* Controls list pos. */ + const void *id; /* + * Identification for + * GEOM nodes + */ + u_int sequence1; /* Update sequence# */ +}; + +STAILQ_HEAD(devstatlist, devstat); + +#ifdef _KERNEL +struct bio; + +struct devstat *devstat_new_entry(const void *dev_name, int unit_number, + u_int32_t block_size, + devstat_support_flags flags, + devstat_type_flags device_type, + devstat_priority priority); + +void devstat_remove_entry(struct devstat *ds); +void devstat_start_transaction(struct devstat *ds, struct bintime *now); +void devstat_start_transaction_bio(struct devstat *ds, struct bio *bp); +void devstat_end_transaction(struct devstat *ds, u_int32_t bytes, + devstat_tag_type tag_type, + devstat_trans_flags flags, + struct bintime *now, struct bintime *then); +void devstat_end_transaction_bio(struct devstat *ds, struct bio *bp); +#endif + +#endif /* _DEVICESTAT_H */ diff --git a/src/include/sys/digiio.h b/src/include/sys/digiio.h new file mode 100644 index 0000000..d593bb2 --- /dev/null +++ b/src/include/sys/digiio.h @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2001 Brian Somers + * based on work by Slawa Olhovchenkov + * John Prince + * Eric Hernes + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/digiio.h,v 1.4 2001/06/20 14:51:58 brian Exp $ + */ + +/* + * A very small subset of cards. + */ +enum digi_model { + PCXE, + PCXEVE, + PCXI, + PCXEM, + PCCX, + PCIEPCX, + PCIXR +}; + +enum { + DIGIDB_INIT = (1<<0), + DIGIDB_OPEN = (1<<1), + DIGIDB_CLOSE = (1<<2), + DIGIDB_SET = (1<<3), + DIGIDB_INT = (1<<4), + DIGIDB_READ = (1<<5), + DIGIDB_WRITE = (1<<6), + DIGIDB_RX = (1<<7), + DIGIDB_TX = (1<<8), + DIGIDB_IRQ = (1<<9), + DIGIDB_MODEM = (1<<10), + DIGIDB_RI = (1<<11), +}; + +#define DIGIIO_REINIT _IO('e', 'A') +#define DIGIIO_DEBUG _IOW('e', 'B', int) +#define DIGIIO_RING _IO('e', 'C') +#define DIGIIO_MODEL _IOR('e', 'D', enum digi_model) +#define DIGIIO_IDENT _IOW('e', 'E', char *) +#define DIGIIO_SETALTPIN _IOW('e', 'F', int) +#define DIGIIO_GETALTPIN _IOR('e', 'G', int) diff --git a/src/include/sys/dir.h b/src/include/sys/dir.h new file mode 100644 index 0000000..d5091fd --- /dev/null +++ b/src/include/sys/dir.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 1982, 1986, 1989, 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. + * 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. + * + * @(#)dir.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/sys/dir.h,v 1.8 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_DIR_H_ +#define _SYS_DIR_H_ + +#if defined(__GNUC__) || defined (__INTEL_COMPILER) +#warning "The information in this file should be obtained from " +#warning "and is provided solely (and temporarily) for backward compatibility." +#endif + +#include + +/* + * Backwards compatibility. + */ +#define direct dirent +#define DIRSIZ(dp) _GENERIC_DIRSIZ(dp) + +#endif /* !_SYS_DIR_H_ */ diff --git a/src/include/sys/dirent.h b/src/include/sys/dirent.h new file mode 100644 index 0000000..c5fb25a --- /dev/null +++ b/src/include/sys/dirent.h @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 1989, 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. + * 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. + * + * @(#)dirent.h 8.3 (Berkeley) 8/10/94 + * $FreeBSD: src/sys/sys/dirent.h,v 1.14 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_DIRENT_H_ +#define _SYS_DIRENT_H_ + +#include +#include + +/* + * The dirent structure defines the format of directory entries returned by + * the getdirentries(2) system call. + * + * A directory entry has a struct dirent at the front of it, containing its + * inode number, the length of the entry, and the length of the name + * contained in the entry. These are followed by the name padded to a 4 + * byte boundary with null bytes. All names are guaranteed null terminated. + * The maximum length of a name in a directory is MAXNAMLEN. + */ + +struct dirent { + __uint32_t d_fileno; /* file number of entry */ + __uint16_t d_reclen; /* length of this record */ + __uint8_t d_type; /* file type, see below */ + __uint8_t d_namlen; /* length of string in d_name */ +#if __BSD_VISIBLE +#define MAXNAMLEN 255 + char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ +#else + char d_name[255 + 1]; /* name must be no longer than this */ +#endif +}; + +#if __BSD_VISIBLE +/* + * File types + */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 + +/* + * Convert between stat structure types and directory types. + */ +#define IFTODT(mode) (((mode) & 0170000) >> 12) +#define DTTOIF(dirtype) ((dirtype) << 12) + +/* + * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold + * the directory entry. This requires the amount of space in struct direct + * without the d_name field, plus enough space for the name with a terminating + * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. + * + * XXX although this macro is in the implementation namespace, it requires + * a manifest constant that is not. + */ +#define _GENERIC_DIRSIZ(dp) \ + ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +#define GENERIC_DIRSIZ(dp) _GENERIC_DIRSIZ(dp) +#endif + +#endif /* !_SYS_DIRENT_H_ */ diff --git a/src/include/sys/disk.h b/src/include/sys/disk.h new file mode 100644 index 0000000..1ac37ff --- /dev/null +++ b/src/include/sys/disk.h @@ -0,0 +1,71 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/sys/disk.h,v 1.39 2003/04/01 18:55:04 phk Exp $ + * + */ + +#ifndef _SYS_DISK_H_ +#define _SYS_DISK_H_ + +#include + +#ifdef _KERNEL + +#ifndef _SYS_CONF_H_ +#include /* XXX: temporary to avoid breakage */ +#endif + +struct disk; +struct disk *disk_enumerate(struct disk *disk); +void disk_err(struct bio *bp, const char *what, int blkdone, int nl); + +#endif + +#define DIOCGSECTORSIZE _IOR('d', 128, u_int) + /*- + * Get the sectorsize of the device in bytes. The sectorsize is the + * smallest unit of data which can be transfered from this device. + * Usually this is a power of two but it may not be. (ie: CDROM audio) + */ + +#define DIOCGMEDIASIZE _IOR('d', 129, off_t) /* Get media size in bytes */ + /*- + * Get the size of the entire device in bytes. This should be a + * multiple of the sectorsize. + */ + +#define DIOCGFWSECTORS _IOR('d', 130, u_int) /* Get firmware sectorcount */ + /*- + * Get the firmwares notion of number of sectors per track. This + * value is mostly used for compatibility with various ill designed + * disk label formats. Don't use it unless you have to. + */ + +#define DIOCGFWHEADS _IOR('d', 131, u_int) /* Get firmware headcount */ + /*- + * Get the firmwares notion of number of heads per cylinder. This + * value is mostly used for compatibility with various ill designed + * disk label formats. Don't use it unless you have to. + */ + +#define DIOCSKERNELDUMP _IOW('d', 133, u_int) /* Set/Clear kernel dumps */ + /*- + * Enable/Disable (the argument is boolean) the device for kernel + * core dumps. + */ + +#define DIOCGFRONTSTUFF _IOR('d', 134, off_t) + /*- + * Many disk formats have some amount of space reserved at the + * start of the disk to hold bootblocks, various disklabels and + * similar stuff. This ioctl returns the number of such bytes + * which may apply to the device. + */ + +#endif /* _SYS_DISK_H_ */ diff --git a/src/include/sys/disklabel.h b/src/include/sys/disklabel.h new file mode 100644 index 0000000..1ec5eee --- /dev/null +++ b/src/include/sys/disklabel.h @@ -0,0 +1,296 @@ +/* + * Copyright (c) 1987, 1988, 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. + * 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. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD: src/sys/sys/disklabel.h,v 1.105 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_DISKLABEL_H_ +#define _SYS_DISKLABEL_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Disk description table, see disktab(5) + */ +#define _PATH_DISKTAB "/etc/disktab" + +/* + * Each disk has a label which includes information about the hardware + * disk geometry, filesystem partitions, and drive specific information. + * The label is in block 0 or 1, possibly offset from the beginning + * to leave room for a bootstrap, etc. + */ + +/* XXX these should be defined per controller (or drive) elsewhere, not here! */ +#if defined(__i386__) || defined(__amd64__) || defined(__ia64__) +#define LABELSECTOR 1 /* sector containing label */ +#define LABELOFFSET 0 /* offset of label in sector */ +#endif + +#ifdef __alpha__ +#define LABELSECTOR 0 +#define LABELOFFSET 64 +#endif + +#define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */ +#ifndef MAXPARTITIONS +#define MAXPARTITIONS 8 +#endif + +/* Size of bootblock area in sector-size neutral bytes */ +#define BBSIZE 8192 + +#define LABEL_PART 2 /* partition containing label */ +#define RAW_PART 2 /* partition containing whole disk */ +#define SWAP_PART 1 /* partition normally containing swap */ + +struct disklabel { + u_int32_t d_magic; /* the magic number */ + u_int16_t d_type; /* drive type */ + u_int16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + + char d_packname[16]; /* pack identifier */ + + /* disk geometry: */ + u_int32_t d_secsize; /* # of bytes per sector */ + u_int32_t d_nsectors; /* # of data sectors per track */ + u_int32_t d_ntracks; /* # of tracks per cylinder */ + u_int32_t d_ncylinders; /* # of data cylinders per unit */ + u_int32_t d_secpercyl; /* # of data sectors per cylinder */ + u_int32_t d_secperunit; /* # of data sectors per unit */ + + /* + * Spares (bad sector replacements) below are not counted in + * d_nsectors or d_secpercyl. Spare sectors are assumed to + * be physical sectors which occupy space at the end of each + * track and/or cylinder. + */ + u_int16_t d_sparespertrack; /* # of spare sectors per track */ + u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */ + /* + * Alternate cylinders include maintenance, replacement, configuration + * description areas, etc. + */ + u_int32_t d_acylinders; /* # of alt. cylinders per unit */ + + /* hardware characteristics: */ + /* + * d_interleave, d_trackskew and d_cylskew describe perturbations + * in the media format used to compensate for a slow controller. + * Interleave is physical sector interleave, set up by the + * formatter or controller when formatting. When interleaving is + * in use, logically adjacent sectors are not physically + * contiguous, but instead are separated by some number of + * sectors. It is specified as the ratio of physical sectors + * traversed per logical sector. Thus an interleave of 1:1 + * implies contiguous layout, while 2:1 implies that logical + * sector 0 is separated by one sector from logical sector 1. + * d_trackskew is the offset of sector 0 on track N relative to + * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew + * is the offset of sector 0 on cylinder N relative to sector 0 + * on cylinder N-1. + */ + u_int16_t d_rpm; /* rotational speed */ + u_int16_t d_interleave; /* hardware sector interleave */ + u_int16_t d_trackskew; /* sector 0 skew, per track */ + u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ + u_int32_t d_headswitch; /* head switch time, usec */ + u_int32_t d_trkseek; /* track-to-track seek, usec */ + u_int32_t d_flags; /* generic flags */ +#define NDDATA 5 + u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */ +#define NSPARE 5 + u_int32_t d_spare[NSPARE]; /* reserved for future use */ + u_int32_t d_magic2; /* the magic number (again) */ + u_int16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + u_int16_t d_npartitions; /* number of partitions in following */ + u_int32_t d_bbsize; /* size of boot area at sn0, bytes */ + u_int32_t d_sbsize; /* max size of fs superblock, bytes */ + struct partition { /* the partition table */ + u_int32_t p_size; /* number of sectors in partition */ + u_int32_t p_offset; /* starting sector */ + u_int32_t p_fsize; /* filesystem basic fragment size */ + u_int8_t p_fstype; /* filesystem type, see below */ + u_int8_t p_frag; /* filesystem fragments per block */ + u_int16_t p_cpg; /* filesystem cylinders per group */ + } d_partitions[MAXPARTITIONS]; /* actually may be more */ +}; + +#ifdef CTASSERT +CTASSERT(sizeof(struct disklabel) == 148 + MAXPARTITIONS * 16); +#endif + +static __inline u_int16_t dkcksum(struct disklabel *lp); +static __inline u_int16_t +dkcksum(struct disklabel *lp) +{ + u_int16_t *start, *end; + u_int16_t sum = 0; + + start = (u_int16_t *)lp; + end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions]; + while (start < end) + sum ^= *start++; + return (sum); +} + + +/* d_type values: */ +#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define DTYPE_MSCP 2 /* MSCP */ +#define DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define DTYPE_SCSI 4 /* SCSI */ +#define DTYPE_ESDI 5 /* ESDI interface */ +#define DTYPE_ST506 6 /* ST506 etc. */ +#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define DTYPE_HPFL 8 /* HP Fiber-link */ +#define DTYPE_FLOPPY 10 /* floppy */ +#define DTYPE_CCD 11 /* concatenated disk */ +#define DTYPE_VINUM 12 /* vinum volume */ +#define DTYPE_DOC2K 13 /* Msys DiskOnChip */ +#define DTYPE_RAID 14 /* CMU RAIDFrame */ +#define DTYPE_JFS2 16 /* IBM JFS 2 */ + +#ifdef DKTYPENAMES +static const char *dktypenames[] = { + "unknown", + "SMD", + "MSCP", + "old DEC", + "SCSI", + "ESDI", + "ST506", + "HP-IB", + "HP-FL", + "type 9", + "floppy", + "CCD", + "Vinum", + "DOC2K", + "Raid", + "?", + "jfs", + NULL +}; +#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) +#endif + +/* + * Filesystem type and version. + * Used to interpret other filesystem-specific + * per-partition information. + */ +#define FS_UNUSED 0 /* unused */ +#define FS_SWAP 1 /* swap */ +#define FS_V6 2 /* Sixth Edition */ +#define FS_V7 3 /* Seventh Edition */ +#define FS_SYSV 4 /* System V */ +#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ +#define FS_V8 6 /* Eighth Edition, 4K blocks */ +#define FS_BSDFFS 7 /* 4.2BSD fast filesystem */ +#define FS_MSDOS 8 /* MSDOS filesystem */ +#define FS_BSDLFS 9 /* 4.4BSD log-structured filesystem */ +#define FS_OTHER 10 /* in use, but unknown/unsupported */ +#define FS_HPFS 11 /* OS/2 high-performance filesystem */ +#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ +#define FS_BOOT 13 /* partition contains bootstrap */ +#define FS_VINUM 14 /* Vinum drive */ +#define FS_RAID 15 /* RAIDFrame drive */ +#define FS_JFS2 21 /* IBM JFS2 */ + +#ifdef FSTYPENAMES +static const char *fstypenames[] = { + "unused", + "swap", + "Version 6", + "Version 7", + "System V", + "4.1BSD", + "Eighth Edition", + "4.2BSD", + "MSDOS", + "4.4LFS", + "unknown", + "HPFS", + "ISO9660", + "boot", + "vinum", + "raid", + "?", + "?", + "?", + "?", + "jfs", + NULL +}; +#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) +#endif + +/* + * flags shared by various drives: + */ +#define D_REMOVABLE 0x01 /* removable media */ +#define D_ECC 0x02 /* supports ECC */ +#define D_BADSECT 0x04 /* supports bad sector forw. */ +#define D_RAMDISK 0x08 /* disk emulator */ +#define D_CHAIN 0x10 /* can do back-back transfers */ + +/* + * Disklabel-specific ioctls. + * + * NB: defines ioctls from 'd'/128 and up. + */ + /* get and set disklabel */ +#define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */ +#define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */ +#define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */ +#define DIOCBSDBB _IOW('d', 110, void *) /* write bootblocks */ + +/* + * Functions for proper encoding/decoding of struct disklabel into/from + * bytestring. + */ +void bsd_partition_le_dec(u_char *ptr, struct partition *d); +int bsd_disklabel_le_dec(u_char *ptr, struct disklabel *d, int maxpart); +void bsd_partition_le_enc(u_char *ptr, struct partition *d); +void bsd_disklabel_le_enc(u_char *ptr, struct disklabel *d); + +#ifndef _KERNEL +__BEGIN_DECLS +struct disklabel *getdiskbyname(const char *); +__END_DECLS +#endif + +#endif /* !_SYS_DISKLABEL_H_ */ diff --git a/src/include/sys/diskmbr.h b/src/include/sys/diskmbr.h new file mode 100644 index 0000000..426c32e --- /dev/null +++ b/src/include/sys/diskmbr.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1987, 1988, 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. + * 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. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD: src/sys/sys/diskmbr.h,v 1.99 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_DISKMBR_H_ +#define _SYS_DISKMBR_H_ + +#include + +#define DOSBBSECTOR 0 /* DOS boot block relative sector number */ +#define DOSPARTOFF 446 +#define DOSPARTSIZE 16 +#define NDOSPART 4 +#define NEXTDOSPART 32 +#define DOSMAGICOFFSET 510 +#define DOSMAGIC 0xAA55 + +#define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */ +#define DOSPTYP_LINSWP 0x82 /* Linux swap partition */ +#define DOSPTYP_LINUX 0x83 /* Linux partition */ +#define DOSPTYP_PMBR 0xee /* GPT Protective MBR */ +#define DOSPTYP_EXT 5 /* DOS extended partition */ +#define DOSPTYP_EXTLBA 15 /* DOS extended partition */ + +struct dos_partition { + unsigned char dp_flag; /* bootstrap flags */ + unsigned char dp_shd; /* starting head */ + unsigned char dp_ssect; /* starting sector */ + unsigned char dp_scyl; /* starting cylinder */ + unsigned char dp_typ; /* partition type */ + unsigned char dp_ehd; /* end head */ + unsigned char dp_esect; /* end sector */ + unsigned char dp_ecyl; /* end cylinder */ + u_int32_t dp_start; /* absolute starting sector number */ + u_int32_t dp_size; /* partition size in sectors */ +}; +#ifdef CTASSERT +CTASSERT(sizeof (struct dos_partition) == DOSPARTSIZE); +#endif + +void dos_partition_dec(void const *pp, struct dos_partition *d); +void dos_partition_enc(void *pp, struct dos_partition *d); + +#define DPSECT(s) ((s) & 0x3f) /* isolate relevant bits of sector */ +#define DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */ + +#define DIOCSMBR _IOW('M', 129, u_char[512]) + +#endif /* !_SYS_DISKMBR_H_ */ diff --git a/src/include/sys/diskpc98.h b/src/include/sys/diskpc98.h new file mode 100644 index 0000000..49e4928 --- /dev/null +++ b/src/include/sys/diskpc98.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1987, 1988, 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. + * 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. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD: src/sys/sys/diskpc98.h,v 1.100 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_DISKPC98_H_ +#define _SYS_DISKPC98_H_ + +#include + +#define DOSBBSECTOR 0 /* DOS boot block relative sector number */ +#define DOSPARTOFF 0 +#define NDOSPART 16 +#define DOSPTYP_386BSD 0x94 /* 386BSD partition type */ + +struct pc98_partition { + unsigned char dp_mid; +#define DOSMID_386BSD (0x14|0x80) /* 386bsd|bootable */ + unsigned char dp_sid; +#define DOSSID_386BSD (0x44|0x80) /* 386bsd|active */ + unsigned char dp_dum1; + unsigned char dp_dum2; + unsigned char dp_ipl_sct; + unsigned char dp_ipl_head; + unsigned short dp_ipl_cyl; + unsigned char dp_ssect; /* starting sector */ + unsigned char dp_shd; /* starting head */ + unsigned short dp_scyl; /* starting cylinder */ + unsigned char dp_esect; /* end sector */ + unsigned char dp_ehd; /* end head */ + unsigned short dp_ecyl; /* end cylinder */ + unsigned char dp_name[16]; +}; +#ifdef CTASSERT +CTASSERT(sizeof (struct pc98_partition) == 32); +#endif + +void pc98_partition_dec(void const *pp, struct pc98_partition *d); +void pc98_partition_enc(void *pp, struct pc98_partition *d); + +#define DIOCSPC98 _IOW('M', 129, u_char[8192]) + +#endif /* !_SYS_DISKPC98_H_ */ diff --git a/src/include/sys/dkstat.h b/src/include/sys/dkstat.h new file mode 100644 index 0000000..a4b7bdb --- /dev/null +++ b/src/include/sys/dkstat.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)dkstat.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/dkstat.h,v 1.18 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_DKSTAT_H_ +#define _SYS_DKSTAT_H_ 1 + +#include + +#endif /* _SYS_DKSTAT_H_ */ diff --git a/src/include/sys/domain.h b/src/include/sys/domain.h new file mode 100644 index 0000000..e5e39a7 --- /dev/null +++ b/src/include/sys/domain.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)domain.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/domain.h,v 1.19 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_DOMAIN_H_ +#define _SYS_DOMAIN_H_ + +/* + * Structure per communications domain. + */ + +/* + * Forward structure declarations for function prototypes [sic]. + */ +struct mbuf; +struct ifnet; + +struct domain { + int dom_family; /* AF_xxx */ + char *dom_name; + void (*dom_init) /* initialize domain data structures */ + (void); + int (*dom_externalize) /* externalize access rights */ + (struct mbuf *, struct mbuf **); + void (*dom_dispose) /* dispose of internalized rights */ + (struct mbuf *); + struct protosw *dom_protosw, *dom_protoswNPROTOSW; + struct domain *dom_next; + int (*dom_rtattach) /* initialize routing table */ + (void **, int); + int dom_rtoffset; /* an arg to rtattach, in bits */ + int dom_maxrtkey; /* for routing layer */ + void *(*dom_ifattach)(struct ifnet *); + void (*dom_ifdetach)(struct ifnet *, void *); + /* af-dependent data on ifnet */ +}; + +#ifdef _KERNEL +extern struct domain *domains; +extern struct domain localdomain; +extern void net_add_domain(void *); + +#define DOMAIN_SET(name) \ + SYSINIT(domain_ ## name, SI_SUB_PROTO_DOMAIN, SI_ORDER_SECOND, net_add_domain, & name ## domain) + +#endif + +#endif diff --git a/src/include/sys/dvdio.h b/src/include/sys/dvdio.h new file mode 100644 index 0000000..eac709e --- /dev/null +++ b/src/include/sys/dvdio.h @@ -0,0 +1,110 @@ +/*- + * Copyright (c) 1999,2000,2001,2002 S�ren Schmidt + * 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, + * without modification, immediately at the beginning of the file. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/dvdio.h,v 1.5 2002/03/04 21:08:35 sos Exp $ + */ + +#ifndef _SYS_DVDIO_H_ +#define _SYS_DVDIO_H_ + +struct dvd_layer { + u_int8_t book_type :4; + u_int8_t book_version :4; + u_int8_t disc_size :4; + u_int8_t max_rate :4; + u_int8_t nlayers :2; + u_int8_t track_path :1; + u_int8_t layer_type :4; + u_int8_t linear_density :4; + u_int8_t track_density :4; + u_int8_t bca :1; + u_int32_t start_sector; + u_int32_t end_sector; + u_int32_t end_sector_l0; +}; + +struct dvd_struct { + u_char format; + u_char layer_num; + u_char cpst; + u_char rmi; + u_int8_t agid :2; + u_int32_t length; + u_char data[2048]; +}; + +struct dvd_authinfo { + unsigned char format; + u_int8_t agid :2; + u_int8_t asf :1; + u_int8_t cpm :1; + u_int8_t cp_sec :1; + u_int8_t cgms :2; + u_int8_t reg_type :2; + u_int8_t vend_rsts :3; + u_int8_t user_rsts :3; + u_int8_t region; + u_int8_t rpc_scheme; + u_int32_t lba; + u_char keychal[10]; +}; + +#define DVD_STRUCT_PHYSICAL 0x00 +#define DVD_STRUCT_COPYRIGHT 0x01 +#define DVD_STRUCT_DISCKEY 0x02 +#define DVD_STRUCT_BCA 0x03 +#define DVD_STRUCT_MANUFACT 0x04 +#define DVD_STRUCT_CMI 0x05 +#define DVD_STRUCT_PROTDISCID 0x06 +#define DVD_STRUCT_DISCKEYBLOCK 0x07 +#define DVD_STRUCT_DDS 0x08 +#define DVD_STRUCT_MEDIUM_STAT 0x09 +#define DVD_STRUCT_SPARE_AREA 0x0A +#define DVD_STRUCT_RMD_LAST 0x0C +#define DVD_STRUCT_RMD_RMA 0x0D +#define DVD_STRUCT_PRERECORDED 0x0E +#define DVD_STRUCT_UNIQUEID 0x0F +#define DVD_STRUCT_DCB 0x30 +#define DVD_STRUCT_LIST 0xFF + +#define DVD_REPORT_AGID 0 +#define DVD_REPORT_CHALLENGE 1 +#define DVD_REPORT_KEY1 2 +#define DVD_REPORT_TITLE_KEY 4 +#define DVD_REPORT_ASF 5 +#define DVD_REPORT_RPC 8 +#define DVD_INVALIDATE_AGID 0x3f + +#define DVD_SEND_CHALLENGE 1 +#define DVD_SEND_KEY2 3 +#define DVD_SEND_RPC 6 + +#define DVDIOCREPORTKEY _IOWR('c', 200, struct dvd_authinfo) +#define DVDIOCSENDKEY _IOWR('c', 201, struct dvd_authinfo) +#define DVDIOCREADSTRUCTURE _IOWR('c', 202, struct dvd_struct) + +#endif /* _SYS_DVDIO_H_ */ diff --git a/src/include/sys/elf32.h b/src/include/sys/elf32.h new file mode 100644 index 0000000..5dfe9c8 --- /dev/null +++ b/src/include/sys/elf32.h @@ -0,0 +1,156 @@ +/*- + * Copyright (c) 1996-1998 John D. Polstra. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/elf32.h,v 1.8 2002/05/30 08:32:18 dfr Exp $ + */ + +#ifndef _SYS_ELF32_H_ +#define _SYS_ELF32_H_ 1 + +#include + +/* + * ELF definitions common to all 32-bit architectures. + */ + +typedef u_int32_t Elf32_Addr; +typedef u_int16_t Elf32_Half; +typedef u_int32_t Elf32_Off; +typedef int32_t Elf32_Sword; +typedef u_int32_t Elf32_Word; +typedef u_int32_t Elf32_Size; +typedef Elf32_Off Elf32_Hashelt; + +/* + * ELF header. + */ + +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* File identification. */ + Elf32_Half e_type; /* File type. */ + Elf32_Half e_machine; /* Machine architecture. */ + Elf32_Word e_version; /* ELF format version. */ + Elf32_Addr e_entry; /* Entry point. */ + Elf32_Off e_phoff; /* Program header file offset. */ + Elf32_Off e_shoff; /* Section header file offset. */ + Elf32_Word e_flags; /* Architecture-specific flags. */ + Elf32_Half e_ehsize; /* Size of ELF header in bytes. */ + Elf32_Half e_phentsize; /* Size of program header entry. */ + Elf32_Half e_phnum; /* Number of program header entries. */ + Elf32_Half e_shentsize; /* Size of section header entry. */ + Elf32_Half e_shnum; /* Number of section header entries. */ + Elf32_Half e_shstrndx; /* Section name strings section. */ +} Elf32_Ehdr; + +/* + * Section header. + */ + +typedef struct { + Elf32_Word sh_name; /* Section name (index into the + section header string table). */ + Elf32_Word sh_type; /* Section type. */ + Elf32_Word sh_flags; /* Section flags. */ + Elf32_Addr sh_addr; /* Address in memory image. */ + Elf32_Off sh_offset; /* Offset in file. */ + Elf32_Size sh_size; /* Size in bytes. */ + Elf32_Word sh_link; /* Index of a related section. */ + Elf32_Word sh_info; /* Depends on section type. */ + Elf32_Size sh_addralign; /* Alignment in bytes. */ + Elf32_Size sh_entsize; /* Size of each entry in section. */ +} Elf32_Shdr; + +/* + * Program header. + */ + +typedef struct { + Elf32_Word p_type; /* Entry type. */ + Elf32_Off p_offset; /* File offset of contents. */ + Elf32_Addr p_vaddr; /* Virtual address in memory image. */ + Elf32_Addr p_paddr; /* Physical address (not used). */ + Elf32_Size p_filesz; /* Size of contents in file. */ + Elf32_Size p_memsz; /* Size of contents in memory. */ + Elf32_Word p_flags; /* Access permission flags. */ + Elf32_Size p_align; /* Alignment in memory and file. */ +} Elf32_Phdr; + +/* + * Dynamic structure. The ".dynamic" section contains an array of them. + */ + +typedef struct { + Elf32_Sword d_tag; /* Entry type. */ + union { + Elf32_Size d_val; /* Integer value. */ + Elf32_Addr d_ptr; /* Address value. */ + } d_un; +} Elf32_Dyn; + +/* + * Relocation entries. + */ + +/* Relocations that don't need an addend field. */ +typedef struct { + Elf32_Addr r_offset; /* Location to be relocated. */ + Elf32_Word r_info; /* Relocation type and symbol index. */ +} Elf32_Rel; + +/* Relocations that need an addend field. */ +typedef struct { + Elf32_Addr r_offset; /* Location to be relocated. */ + Elf32_Word r_info; /* Relocation type and symbol index. */ + Elf32_Sword r_addend; /* Addend. */ +} Elf32_Rela; + +/* Macros for accessing the fields of r_info. */ +#define ELF32_R_SYM(info) ((info) >> 8) +#define ELF32_R_TYPE(info) ((unsigned char)(info)) + +/* Macro for constructing r_info from field values. */ +#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type)) + +/* + * Symbol table entries. + */ + +typedef struct { + Elf32_Word st_name; /* String table index of name. */ + Elf32_Addr st_value; /* Symbol value. */ + Elf32_Size st_size; /* Size of associated object. */ + unsigned char st_info; /* Type and binding information. */ + unsigned char st_other; /* Reserved (not used). */ + Elf32_Half st_shndx; /* Section index of symbol. */ +} Elf32_Sym; + +/* Macros for accessing the fields of st_info. */ +#define ELF32_ST_BIND(info) ((info) >> 4) +#define ELF32_ST_TYPE(info) ((info) & 0xf) + +/* Macro for constructing st_info from field values. */ +#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) + +#endif /* !_SYS_ELF32_H_ */ diff --git a/src/include/sys/elf64.h b/src/include/sys/elf64.h new file mode 100644 index 0000000..30aee19 --- /dev/null +++ b/src/include/sys/elf64.h @@ -0,0 +1,169 @@ +/*- + * Copyright (c) 1996-1998 John D. Polstra. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/elf64.h,v 1.10 2002/05/30 08:32:18 dfr Exp $ + */ + +#ifndef _SYS_ELF64_H_ +#define _SYS_ELF64_H_ 1 + +#include + +/* + * ELF definitions common to all 64-bit architectures. + */ + +typedef u_int64_t Elf64_Addr; +typedef u_int32_t Elf64_Half; +typedef u_int64_t Elf64_Off; +typedef int64_t Elf64_Sword; +typedef u_int64_t Elf64_Word; +typedef u_int64_t Elf64_Size; +typedef u_int16_t Elf64_Quarter; + +/* + * Types of dynamic symbol hash table bucket and chain elements. + * + * This is inconsistent among 64 bit architectures, so a machine dependent + * typedef is required. + */ + +#ifdef __alpha__ +typedef Elf64_Off Elf64_Hashelt; +#else +typedef Elf64_Half Elf64_Hashelt; +#endif + +/* + * ELF header. + */ + +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* File identification. */ + Elf64_Quarter e_type; /* File type. */ + Elf64_Quarter e_machine; /* Machine architecture. */ + Elf64_Half e_version; /* ELF format version. */ + Elf64_Addr e_entry; /* Entry point. */ + Elf64_Off e_phoff; /* Program header file offset. */ + Elf64_Off e_shoff; /* Section header file offset. */ + Elf64_Half e_flags; /* Architecture-specific flags. */ + Elf64_Quarter e_ehsize; /* Size of ELF header in bytes. */ + Elf64_Quarter e_phentsize; /* Size of program header entry. */ + Elf64_Quarter e_phnum; /* Number of program header entries. */ + Elf64_Quarter e_shentsize; /* Size of section header entry. */ + Elf64_Quarter e_shnum; /* Number of section header entries. */ + Elf64_Quarter e_shstrndx; /* Section name strings section. */ +} Elf64_Ehdr; + +/* + * Section header. + */ + +typedef struct { + Elf64_Half sh_name; /* Section name (index into the + section header string table). */ + Elf64_Half sh_type; /* Section type. */ + Elf64_Size sh_flags; /* Section flags. */ + Elf64_Addr sh_addr; /* Address in memory image. */ + Elf64_Off sh_offset; /* Offset in file. */ + Elf64_Size sh_size; /* Size in bytes. */ + Elf64_Half sh_link; /* Index of a related section. */ + Elf64_Half sh_info; /* Depends on section type. */ + Elf64_Size sh_addralign; /* Alignment in bytes. */ + Elf64_Size sh_entsize; /* Size of each entry in section. */ +} Elf64_Shdr; + +/* + * Program header. + */ + +typedef struct { + Elf64_Half p_type; /* Entry type. */ + Elf64_Half p_flags; /* Access permission flags. */ + Elf64_Off p_offset; /* File offset of contents. */ + Elf64_Addr p_vaddr; /* Virtual address in memory image. */ + Elf64_Addr p_paddr; /* Physical address (not used). */ + Elf64_Size p_filesz; /* Size of contents in file. */ + Elf64_Size p_memsz; /* Size of contents in memory. */ + Elf64_Size p_align; /* Alignment in memory and file. */ +} Elf64_Phdr; + +/* + * Dynamic structure. The ".dynamic" section contains an array of them. + */ + +typedef struct { + Elf64_Size d_tag; /* Entry type. */ + union { + Elf64_Size d_val; /* Integer value. */ + Elf64_Addr d_ptr; /* Address value. */ + } d_un; +} Elf64_Dyn; + +/* + * Relocation entries. + */ + +/* Relocations that don't need an addend field. */ +typedef struct { + Elf64_Addr r_offset; /* Location to be relocated. */ + Elf64_Size r_info; /* Relocation type and symbol index. */ +} Elf64_Rel; + +/* Relocations that need an addend field. */ +typedef struct { + Elf64_Addr r_offset; /* Location to be relocated. */ + Elf64_Size r_info; /* Relocation type and symbol index. */ + Elf64_Off r_addend; /* Addend. */ +} Elf64_Rela; + +/* Macros for accessing the fields of r_info. */ +#define ELF64_R_SYM(info) ((info) >> 32) +#define ELF64_R_TYPE(info) ((unsigned char)(info)) + +/* Macro for constructing r_info from field values. */ +#define ELF64_R_INFO(sym, type) (((sym) << 32) + (unsigned char)(type)) + +/* + * Symbol table entries. + */ + +typedef struct { + Elf64_Half st_name; /* String table index of name. */ + unsigned char st_info; /* Type and binding information. */ + unsigned char st_other; /* Reserved (not used). */ + Elf64_Quarter st_shndx; /* Section index of symbol. */ + Elf64_Addr st_value; /* Symbol value. */ + Elf64_Size st_size; /* Size of associated object. */ +} Elf64_Sym; + +/* Macros for accessing the fields of st_info. */ +#define ELF64_ST_BIND(info) ((info) >> 4) +#define ELF64_ST_TYPE(info) ((info) & 0xf) + +/* Macro for constructing st_info from field values. */ +#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) + +#endif /* !_SYS_ELF64_H_ */ diff --git a/src/include/sys/elf_common.h b/src/include/sys/elf_common.h new file mode 100644 index 0000000..f637c9a --- /dev/null +++ b/src/include/sys/elf_common.h @@ -0,0 +1,299 @@ +/*- + * Copyright (c) 1998 John D. Polstra. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/elf_common.h,v 1.15 2004/05/05 02:38:54 marcel Exp $ + */ + +#ifndef _SYS_ELF_COMMON_H_ +#define _SYS_ELF_COMMON_H_ 1 + +/* + * ELF definitions that are independent of architecture or word size. + */ + +/* + * Note header. The ".note" section contains an array of notes. Each + * begins with this header, aligned to a word boundary. Immediately + * following the note header is n_namesz bytes of name, padded to the + * next word boundary. Then comes n_descsz bytes of descriptor, again + * padded to a word boundary. The values of n_namesz and n_descsz do + * not include the padding. + */ + +typedef struct { + u_int32_t n_namesz; /* Length of name. */ + u_int32_t n_descsz; /* Length of descriptor. */ + u_int32_t n_type; /* Type of this note. */ +} Elf_Note; + +/* Indexes into the e_ident array. Keep synced with + http://www.sco.com/developer/gabi/ch4.eheader.html */ +#define EI_MAG0 0 /* Magic number, byte 0. */ +#define EI_MAG1 1 /* Magic number, byte 1. */ +#define EI_MAG2 2 /* Magic number, byte 2. */ +#define EI_MAG3 3 /* Magic number, byte 3. */ +#define EI_CLASS 4 /* Class of machine. */ +#define EI_DATA 5 /* Data format. */ +#define EI_VERSION 6 /* ELF format version. */ +#define EI_OSABI 7 /* Operating system / ABI identification */ +#define EI_ABIVERSION 8 /* ABI version */ +#define OLD_EI_BRAND 8 /* Start of architecture identification. */ +#define EI_PAD 9 /* Start of padding (per SVR4 ABI). */ +#define EI_NIDENT 16 /* Size of e_ident array. */ + +/* Values for the magic number bytes. */ +#define ELFMAG0 0x7f +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" /* magic string */ +#define SELFMAG 4 /* magic string size */ + +/* Values for e_ident[EI_VERSION] and e_version. */ +#define EV_NONE 0 +#define EV_CURRENT 1 + +/* Values for e_ident[EI_CLASS]. */ +#define ELFCLASSNONE 0 /* Unknown class. */ +#define ELFCLASS32 1 /* 32-bit architecture. */ +#define ELFCLASS64 2 /* 64-bit architecture. */ + +/* Values for e_ident[EI_DATA]. */ +#define ELFDATANONE 0 /* Unknown data format. */ +#define ELFDATA2LSB 1 /* 2's complement little-endian. */ +#define ELFDATA2MSB 2 /* 2's complement big-endian. */ + +/* Values for e_ident[EI_OSABI]. */ +#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ +#define ELFOSABI_NONE ELFOSABI_SYSV /* symbol used in old spec */ +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ +#define ELFOSABI_NETBSD 2 /* NetBSD */ +#define ELFOSABI_LINUX 3 /* GNU/Linux */ +#define ELFOSABI_HURD 4 /* GNU/Hurd */ +#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ +#define ELFOSABI_SOLARIS 6 /* Solaris */ +#define ELFOSABI_MONTEREY 7 /* Monterey */ +#define ELFOSABI_IRIX 8 /* IRIX */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ +#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ +#define ELFOSABI_OPENBSD 12 /* OpenBSD */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ + +/* e_ident */ +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ + (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ + (ehdr).e_ident[EI_MAG3] == ELFMAG3) + +/* Values for e_type. */ +#define ET_NONE 0 /* Unknown type. */ +#define ET_REL 1 /* Relocatable. */ +#define ET_EXEC 2 /* Executable. */ +#define ET_DYN 3 /* Shared object. */ +#define ET_CORE 4 /* Core file. */ + +/* Values for e_machine. */ +#define EM_NONE 0 /* Unknown machine. */ +#define EM_M32 1 /* AT&T WE32100. */ +#define EM_SPARC 2 /* Sun SPARC. */ +#define EM_386 3 /* Intel i386. */ +#define EM_68K 4 /* Motorola 68000. */ +#define EM_88K 5 /* Motorola 88000. */ +#define EM_486 6 /* Intel i486. */ +#define EM_860 7 /* Intel i860. */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ + +/* Extensions. This list is not complete. */ +#define EM_S370 9 /* IBM System/370 */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ /* Depreciated */ +#define EM_PARISC 15 /* HPPA */ +#define EM_SPARC32PLUS 18 /* SPARC v8plus */ +#define EM_PPC 20 /* PowerPC 32-bit */ +#define EM_PPC64 21 /* PowerPC 64-bit */ +#define EM_ARM 40 /* ARM */ +#define EM_SPARCV9 43 /* SPARC v9 64-bit */ +#define EM_IA_64 50 /* Intel IA-64 Processor */ +#define EM_X86_64 62 /* Advanced Micro Devices x86-64 */ +#define EM_ALPHA 0x9026 /* Alpha (written in the absence of an ABI */ + +/* Special section indexes. */ +#define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */ +#define SHN_LORESERVE 0xff00 /* First of reserved range. */ +#define SHN_LOPROC 0xff00 /* First processor-specific. */ +#define SHN_HIPROC 0xff1f /* Last processor-specific. */ +#define SHN_ABS 0xfff1 /* Absolute values. */ +#define SHN_COMMON 0xfff2 /* Common data. */ +#define SHN_HIRESERVE 0xffff /* Last of reserved range. */ + +/* sh_type */ +#define SHT_NULL 0 /* inactive */ +#define SHT_PROGBITS 1 /* program defined information */ +#define SHT_SYMTAB 2 /* symbol table section */ +#define SHT_STRTAB 3 /* string table section */ +#define SHT_RELA 4 /* relocation section with addends */ +#define SHT_HASH 5 /* symbol hash table section */ +#define SHT_DYNAMIC 6 /* dynamic section */ +#define SHT_NOTE 7 /* note section */ +#define SHT_NOBITS 8 /* no space section */ +#define SHT_REL 9 /* relocation section - no addends */ +#define SHT_SHLIB 10 /* reserved - purpose unknown */ +#define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_NUM 12 /* number of section types */ +#define SHT_LOOS 0x60000000 /* First of OS specific semantics */ +#define SHT_HIOS 0x6fffffff /* Last of OS specific semantics */ +#define SHT_LOPROC 0x70000000 /* reserved range for processor */ +#define SHT_HIPROC 0x7fffffff /* specific section header types */ +#define SHT_LOUSER 0x80000000 /* reserved range for application */ +#define SHT_HIUSER 0xffffffff /* specific indexes */ + +/* Flags for sh_flags. */ +#define SHF_WRITE 0x1 /* Section contains writable data. */ +#define SHF_ALLOC 0x2 /* Section occupies memory. */ +#define SHF_EXECINSTR 0x4 /* Section contains instructions. */ +#define SHF_TLS 0x400 /* Section contains TLS data. */ +#define SHF_MASKPROC 0xf0000000 /* Reserved for processor-specific. */ + +/* Values for p_type. */ +#define PT_NULL 0 /* Unused entry. */ +#define PT_LOAD 1 /* Loadable segment. */ +#define PT_DYNAMIC 2 /* Dynamic linking information segment. */ +#define PT_INTERP 3 /* Pathname of interpreter. */ +#define PT_NOTE 4 /* Auxiliary information. */ +#define PT_SHLIB 5 /* Reserved (not used). */ +#define PT_PHDR 6 /* Location of program header itself. */ +#define PT_TLS 7 /* Thread local storage segment */ + +#define PT_COUNT 8 /* Number of defined p_type values. */ + +#define PT_LOOS 0x60000000 /* OS-specific */ +#define PT_HIOS 0x6fffffff /* OS-specific */ +#define PT_LOPROC 0x70000000 /* First processor-specific type. */ +#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */ + +/* Values for p_flags. */ +#define PF_X 0x1 /* Executable. */ +#define PF_W 0x2 /* Writable. */ +#define PF_R 0x4 /* Readable. */ + +/* Values for d_tag. */ +#define DT_NULL 0 /* Terminating entry. */ +#define DT_NEEDED 1 /* String table offset of a needed shared + library. */ +#define DT_PLTRELSZ 2 /* Total size in bytes of PLT relocations. */ +#define DT_PLTGOT 3 /* Processor-dependent address. */ +#define DT_HASH 4 /* Address of symbol hash table. */ +#define DT_STRTAB 5 /* Address of string table. */ +#define DT_SYMTAB 6 /* Address of symbol table. */ +#define DT_RELA 7 /* Address of ElfNN_Rela relocations. */ +#define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */ +#define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */ +#define DT_STRSZ 10 /* Size of string table. */ +#define DT_SYMENT 11 /* Size of each symbol table entry. */ +#define DT_INIT 12 /* Address of initialization function. */ +#define DT_FINI 13 /* Address of finalization function. */ +#define DT_SONAME 14 /* String table offset of shared object + name. */ +#define DT_RPATH 15 /* String table offset of library path. [sup] */ +#define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. [sup] */ +#define DT_REL 17 /* Address of ElfNN_Rel relocations. */ +#define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */ +#define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */ +#define DT_PLTREL 20 /* Type of relocation used for PLT. */ +#define DT_DEBUG 21 /* Reserved (not used). */ +#define DT_TEXTREL 22 /* Indicates there may be relocations in + non-writable segments. [sup] */ +#define DT_JMPREL 23 /* Address of PLT relocations. */ +#define DT_BIND_NOW 24 /* [sup] */ +#define DT_INIT_ARRAY 25 /* Address of the array of pointers to + initialization functions */ +#define DT_FINI_ARRAY 26 /* Address of the array of pointers to + termination functions */ +#define DT_INIT_ARRAYSZ 27 /* Size in bytes of the array of + initialization functions. */ +#define DT_FINI_ARRAYSZ 28 /* Size in bytes of the array of + terminationfunctions. */ +#define DT_RUNPATH 29 /* String table offset of a null-terminated + library search path string. */ +#define DT_FLAGS 30 /* Object specific flag values. */ +#define DT_ENCODING 32 /* Values greater than or equal to DT_ENCODING + and less than DT_LOOS follow the rules for + the interpretation of the d_un union + as follows: even == 'd_ptr', even == 'd_val' + or none */ +#define DT_PREINIT_ARRAY 32 /* Address of the array of pointers to + pre-initialization functions. */ +#define DT_PREINIT_ARRAYSZ 33 /* Size in bytes of the array of + pre-initialization functions. */ + +#define DT_COUNT 33 /* Number of defined d_tag values. */ + +#define DT_LOOS 0x6000000d /* First OS-specific */ +#define DT_HIOS 0x6fff0000 /* Last OS-specific */ +#define DT_LOPROC 0x70000000 /* First processor-specific type. */ +#define DT_HIPROC 0x7fffffff /* Last processor-specific type. */ + +/* Values for DT_FLAGS */ +#define DF_ORIGIN 0x0001 /* Indicates that the object being loaded may + make reference to the $ORIGIN substitution + string */ +#define DF_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */ +#define DF_TEXTREL 0x0004 /* Indicates there may be relocations in + non-writable segments. */ +#define DF_BIND_NOW 0x0008 /* Indicates that the dynamic linker should + process all relocations for the object + containing this entry before transferring + control to the program. */ +#define DF_STATIC_TLS 0x0010 /* Indicates that the shared object or + executable contains code using a static + thread-local storage scheme. */ + +/* Values for n_type. Used in core files. */ +#define NT_PRSTATUS 1 /* Process status. */ +#define NT_FPREGSET 2 /* Floating point registers. */ +#define NT_PRPSINFO 3 /* Process state info. */ + +/* Symbol Binding - ELFNN_ST_BIND - st_info */ +#define STB_LOCAL 0 /* Local symbol */ +#define STB_GLOBAL 1 /* Global symbol */ +#define STB_WEAK 2 /* like global - lower precedence */ +#define STB_LOPROC 13 /* reserved range for processor */ +#define STB_HIPROC 15 /* specific symbol bindings */ + +/* Symbol type - ELFNN_ST_TYPE - st_info */ +#define STT_NOTYPE 0 /* Unspecified type. */ +#define STT_OBJECT 1 /* Data object. */ +#define STT_FUNC 2 /* Function. */ +#define STT_SECTION 3 /* Section. */ +#define STT_FILE 4 /* Source file. */ +#define STT_TLS 6 /* TLS object. */ +#define STT_LOPROC 13 /* reserved range for processor */ +#define STT_HIPROC 15 /* specific symbol types */ + +/* Special symbol table indexes. */ +#define STN_UNDEF 0 /* Undefined symbol index. */ + +#endif /* !_SYS_ELF_COMMON_H_ */ diff --git a/src/include/sys/elf_generic.h b/src/include/sys/elf_generic.h new file mode 100644 index 0000000..5aed299 --- /dev/null +++ b/src/include/sys/elf_generic.h @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 1998 John D. Polstra. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/elf_generic.h,v 1.6 2002/07/20 02:56:11 peter Exp $ + */ + +#ifndef _SYS_ELF_GENERIC_H_ +#define _SYS_ELF_GENERIC_H_ 1 + +#include + +/* + * Definitions of generic ELF names which relieve applications from + * needing to know the word size. + */ + +#if __ELF_WORD_SIZE != 32 && __ELF_WORD_SIZE != 64 +#error "__ELF_WORD_SIZE must be defined as 32 or 64" +#endif + +#define ELF_CLASS __CONCAT(ELFCLASS,__ELF_WORD_SIZE) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define ELF_DATA ELFDATA2LSB +#elif BYTE_ORDER == BIG_ENDIAN +#define ELF_DATA ELFDATA2MSB +#else +#error "Unknown byte order" +#endif + +#define __elfN(x) __CONCAT(__CONCAT(__CONCAT(elf,__ELF_WORD_SIZE),_),x) +#define __ElfN(x) __CONCAT(__CONCAT(__CONCAT(Elf,__ELF_WORD_SIZE),_),x) +#define __ELFN(x) __CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x) +#define __ElfType(x) typedef __ElfN(x) __CONCAT(Elf_,x) + +__ElfType(Addr); +__ElfType(Half); +__ElfType(Off); +__ElfType(Sword); +__ElfType(Word); +__ElfType(Size); +__ElfType(Hashelt); +__ElfType(Ehdr); +__ElfType(Shdr); +__ElfType(Phdr); +__ElfType(Dyn); +__ElfType(Rel); +__ElfType(Rela); +__ElfType(Sym); + +#define ELF_R_SYM __ELFN(R_SYM) +#define ELF_R_TYPE __ELFN(R_TYPE) +#define ELF_R_INFO __ELFN(R_INFO) +#define ELF_ST_BIND __ELFN(ST_BIND) +#define ELF_ST_TYPE __ELFN(ST_TYPE) +#define ELF_ST_INFO __ELFN(ST_INFO) + +#endif /* !_SYS_ELF_GENERIC_H_ */ diff --git a/src/include/sys/endian.h b/src/include/sys/endian.h new file mode 100644 index 0000000..33b4307 --- /dev/null +++ b/src/include/sys/endian.h @@ -0,0 +1,200 @@ +/*- + * Copyright (c) 2002 Thomas Moestl + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/endian.h,v 1.6 2003/10/15 20:05:57 obrien Exp $ + */ + +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ + +#include +#include +#include + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif + +/* + * General byte order swapping functions. + */ +#define bswap16(x) __bswap16(x) +#define bswap32(x) __bswap32(x) +#define bswap64(x) __bswap64(x) + +/* + * Host to big endian, host to little endian, big endian to host, and little + * endian to host byte order functions as detailed in byteorder(9). + */ +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define htobe16(x) bswap16((x)) +#define htobe32(x) bswap32((x)) +#define htobe64(x) bswap64((x)) +#define htole16(x) ((uint16_t)(x)) +#define htole32(x) ((uint32_t)(x)) +#define htole64(x) ((uint64_t)(x)) + +#define be16toh(x) bswap16((x)) +#define be32toh(x) bswap32((x)) +#define be64toh(x) bswap64((x)) +#define le16toh(x) ((uint16_t)(x)) +#define le32toh(x) ((uint32_t)(x)) +#define le64toh(x) ((uint64_t)(x)) +#else /* _BYTE_ORDER != _LITTLE_ENDIAN */ +#define htobe16(x) ((uint16_t)(x)) +#define htobe32(x) ((uint32_t)(x)) +#define htobe64(x) ((uint64_t)(x)) +#define htole16(x) bswap16((x)) +#define htole32(x) bswap32((x)) +#define htole64(x) bswap64((x)) + +#define be16toh(x) ((uint16_t)(x)) +#define be32toh(x) ((uint32_t)(x)) +#define be64toh(x) ((uint64_t)(x)) +#define le16toh(x) bswap16((x)) +#define le32toh(x) bswap32((x)) +#define le64toh(x) bswap64((x)) +#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ + +/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ + +static __inline uint16_t +be16dec(const void *pp) +{ + unsigned char const *p = (unsigned char const *)pp; + + return ((p[0] << 8) | p[1]); +} + +static __inline uint32_t +be32dec(const void *pp) +{ + unsigned char const *p = (unsigned char const *)pp; + + return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); +} + +static __inline uint64_t +be64dec(const void *pp) +{ + unsigned char const *p = (unsigned char const *)pp; + + return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4)); +} + +static __inline uint16_t +le16dec(const void *pp) +{ + unsigned char const *p = (unsigned char const *)pp; + + return ((p[1] << 8) | p[0]); +} + +static __inline uint32_t +le32dec(const void *pp) +{ + unsigned char const *p = (unsigned char const *)pp; + + return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); +} + +static __inline uint64_t +le64dec(const void *pp) +{ + unsigned char const *p = (unsigned char const *)pp; + + return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p)); +} + +static __inline void +be16enc(void *pp, uint16_t u) +{ + unsigned char *p = (unsigned char *)pp; + + p[0] = (u >> 8) & 0xff; + p[1] = u & 0xff; +} + +static __inline void +be32enc(void *pp, uint32_t u) +{ + unsigned char *p = (unsigned char *)pp; + + p[0] = (u >> 24) & 0xff; + p[1] = (u >> 16) & 0xff; + p[2] = (u >> 8) & 0xff; + p[3] = u & 0xff; +} + +static __inline void +be64enc(void *pp, uint64_t u) +{ + unsigned char *p = (unsigned char *)pp; + + be32enc(p, u >> 32); + be32enc(p + 4, u & 0xffffffff); +} + +static __inline void +le16enc(void *pp, uint16_t u) +{ + unsigned char *p = (unsigned char *)pp; + + p[0] = u & 0xff; + p[1] = (u >> 8) & 0xff; +} + +static __inline void +le32enc(void *pp, uint32_t u) +{ + unsigned char *p = (unsigned char *)pp; + + p[0] = u & 0xff; + p[1] = (u >> 8) & 0xff; + p[2] = (u >> 16) & 0xff; + p[3] = (u >> 24) & 0xff; +} + +static __inline void +le64enc(void *pp, uint64_t u) +{ + unsigned char *p = (unsigned char *)pp; + + le32enc(p, u & 0xffffffff); + le32enc(p + 4, u >> 32); +} + +#endif /* _SYS_ENDIAN_H_ */ diff --git a/src/include/sys/errno.h b/src/include/sys/errno.h new file mode 100644 index 0000000..d775e98 --- /dev/null +++ b/src/include/sys/errno.h @@ -0,0 +1,182 @@ +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)errno.h 8.5 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/errno.h,v 1.26 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_ERRNO_H_ +#define _SYS_ERRNO_H_ + +#ifndef _KERNEL +#include +__BEGIN_DECLS +int * __error(void); +__END_DECLS +#define errno (* __error()) +#endif + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* Device not configured */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EDEADLK 11 /* Resource deadlock avoided */ + /* 11 was EAGAIN */ +#define ENOMEM 12 /* Cannot allocate memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#ifndef _POSIX_SOURCE +#define ENOTBLK 15 /* Block device required */ +#endif +#define EBUSY 16 /* Device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* Operation not supported by device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate ioctl for device */ +#ifndef _POSIX_SOURCE +#define ETXTBSY 26 /* Text file busy */ +#endif +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only filesystem */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ + +/* math software */ +#define EDOM 33 /* Numerical argument out of domain */ +#define ERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define EAGAIN 35 /* Resource temporarily unavailable */ +#ifndef _POSIX_SOURCE +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ + +/* ipc/network software -- argument errors */ +#define ENOTSOCK 38 /* Socket operation on non-socket */ +#define EDESTADDRREQ 39 /* Destination address required */ +#define EMSGSIZE 40 /* Message too long */ +#define EPROTOTYPE 41 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 42 /* Protocol not available */ +#define EPROTONOSUPPORT 43 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ +#define EOPNOTSUPP 45 /* Operation not supported */ +#define ENOTSUP EOPNOTSUPP /* Operation not supported */ +#define EPFNOSUPPORT 46 /* Protocol family not supported */ +#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define EADDRINUSE 48 /* Address already in use */ +#define EADDRNOTAVAIL 49 /* Can't assign requested address */ + +/* ipc/network software -- operational errors */ +#define ENETDOWN 50 /* Network is down */ +#define ENETUNREACH 51 /* Network is unreachable */ +#define ENETRESET 52 /* Network dropped connection on reset */ +#define ECONNABORTED 53 /* Software caused connection abort */ +#define ECONNRESET 54 /* Connection reset by peer */ +#define ENOBUFS 55 /* No buffer space available */ +#define EISCONN 56 /* Socket is already connected */ +#define ENOTCONN 57 /* Socket is not connected */ +#define ESHUTDOWN 58 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 59 /* Too many references: can't splice */ +#define ETIMEDOUT 60 /* Operation timed out */ +#define ECONNREFUSED 61 /* Connection refused */ + +#define ELOOP 62 /* Too many levels of symbolic links */ +#endif /* _POSIX_SOURCE */ +#define ENAMETOOLONG 63 /* File name too long */ + +/* should be rearranged */ +#ifndef _POSIX_SOURCE +#define EHOSTDOWN 64 /* Host is down */ +#define EHOSTUNREACH 65 /* No route to host */ +#endif /* _POSIX_SOURCE */ +#define ENOTEMPTY 66 /* Directory not empty */ + +/* quotas & mush */ +#ifndef _POSIX_SOURCE +#define EPROCLIM 67 /* Too many processes */ +#define EUSERS 68 /* Too many users */ +#define EDQUOT 69 /* Disc quota exceeded */ + +/* Network File System */ +#define ESTALE 70 /* Stale NFS file handle */ +#define EREMOTE 71 /* Too many levels of remote in path */ +#define EBADRPC 72 /* RPC struct is bad */ +#define ERPCMISMATCH 73 /* RPC version wrong */ +#define EPROGUNAVAIL 74 /* RPC prog. not avail */ +#define EPROGMISMATCH 75 /* Program version wrong */ +#define EPROCUNAVAIL 76 /* Bad procedure for program */ +#endif /* _POSIX_SOURCE */ + +#define ENOLCK 77 /* No locks available */ +#define ENOSYS 78 /* Function not implemented */ + +#ifndef _POSIX_SOURCE +#define EFTYPE 79 /* Inappropriate file type or format */ +#define EAUTH 80 /* Authentication error */ +#define ENEEDAUTH 81 /* Need authenticator */ +#define EIDRM 82 /* Identifier removed */ +#define ENOMSG 83 /* No message of desired type */ +#define EOVERFLOW 84 /* Value too large to be stored in data type */ +#define ECANCELED 85 /* Operation canceled */ +#define EILSEQ 86 /* Illegal byte sequence */ +#define ENOATTR 87 /* Attribute not found */ + +#define EDOOFUS 88 /* Programming error */ + +#define ELAST 88 /* Must be equal largest errno */ + +#endif /* _POSIX_SOURCE */ + +#ifdef _KERNEL +/* pseudo-errors returned inside kernel to modify return to process */ +#define ERESTART (-1) /* restart syscall */ +#define EJUSTRETURN (-2) /* don't modify regs, just return */ +#define ENOIOCTL (-3) /* ioctl not handled by this layer */ +#define EDIRIOCTL (-4) /* do direct ioctl in GEOM */ +#endif + +#endif diff --git a/src/include/sys/event.h b/src/include/sys/event.h new file mode 100644 index 0000000..4f8cf68 --- /dev/null +++ b/src/include/sys/event.h @@ -0,0 +1,198 @@ +/*- + * Copyright (c) 1999,2000,2001 Jonathan Lemon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/event.h,v 1.22 2003/02/02 19:39:51 nectar Exp $ + */ + +#ifndef _SYS_EVENT_H_ +#define _SYS_EVENT_H_ + +#define EVFILT_READ (-1) +#define EVFILT_WRITE (-2) +#define EVFILT_AIO (-3) /* attached to aio requests */ +#define EVFILT_VNODE (-4) /* attached to vnodes */ +#define EVFILT_PROC (-5) /* attached to struct proc */ +#define EVFILT_SIGNAL (-6) /* attached to struct proc */ +#define EVFILT_TIMER (-7) /* timers */ +#define EVFILT_NETDEV (-8) /* network devices */ + +#define EVFILT_SYSCOUNT 8 + +#define EV_SET(kevp_, a, b, c, d, e, f) do { \ + struct kevent *kevp = (kevp_); \ + (kevp)->ident = (a); \ + (kevp)->filter = (b); \ + (kevp)->flags = (c); \ + (kevp)->fflags = (d); \ + (kevp)->data = (e); \ + (kevp)->udata = (f); \ +} while(0) + +struct kevent { + uintptr_t ident; /* identifier for this event */ + short filter; /* filter for event */ + u_short flags; + u_int fflags; + intptr_t data; + void *udata; /* opaque user data identifier */ +}; + +/* actions */ +#define EV_ADD 0x0001 /* add event to kq (implies enable) */ +#define EV_DELETE 0x0002 /* delete event from kq */ +#define EV_ENABLE 0x0004 /* enable event */ +#define EV_DISABLE 0x0008 /* disable event (not reported) */ + +/* flags */ +#define EV_ONESHOT 0x0010 /* only report one occurrence */ +#define EV_CLEAR 0x0020 /* clear event state after reporting */ + +#define EV_SYSFLAGS 0xF000 /* reserved by system */ +#define EV_FLAG1 0x2000 /* filter-specific flag */ + +/* returned values */ +#define EV_EOF 0x8000 /* EOF detected */ +#define EV_ERROR 0x4000 /* error, data contains errno */ + +/* + * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace + */ +#define NOTE_LOWAT 0x0001 /* low water mark */ + +/* + * data/hint flags for EVFILT_VNODE, shared with userspace + */ +#define NOTE_DELETE 0x0001 /* vnode was removed */ +#define NOTE_WRITE 0x0002 /* data contents changed */ +#define NOTE_EXTEND 0x0004 /* size increased */ +#define NOTE_ATTRIB 0x0008 /* attributes changed */ +#define NOTE_LINK 0x0010 /* link count changed */ +#define NOTE_RENAME 0x0020 /* vnode was renamed */ +#define NOTE_REVOKE 0x0040 /* vnode access was revoked */ + +/* + * data/hint flags for EVFILT_PROC, shared with userspace + */ +#define NOTE_EXIT 0x80000000 /* process exited */ +#define NOTE_FORK 0x40000000 /* process forked */ +#define NOTE_EXEC 0x20000000 /* process exec'd */ +#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ +#define NOTE_PDATAMASK 0x000fffff /* mask for pid */ + +/* additional flags for EVFILT_PROC */ +#define NOTE_TRACK 0x00000001 /* follow across forks */ +#define NOTE_TRACKERR 0x00000002 /* could not track child */ +#define NOTE_CHILD 0x00000004 /* am a child process */ + +/* + * data/hint flags for EVFILT_NETDEV, shared with userspace + */ +#define NOTE_LINKUP 0x0001 /* link is up */ +#define NOTE_LINKDOWN 0x0002 /* link is down */ +#define NOTE_LINKINV 0x0004 /* link state is invalid */ + +/* + * This is currently visible to userland to work around broken + * programs which pull in . + */ +#include +struct knote; +SLIST_HEAD(klist, knote); + +#ifdef _KERNEL + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_KQUEUE); +#endif + +#define KNOTE(list, hint) if ((list) != NULL) knote(list, hint) + +/* + * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also + * shared by EVFILT_PROC (all knotes attached to p->p_klist) + */ +#define NOTE_SIGNAL 0x08000000 + +struct filterops { + int f_isfd; /* true if ident == filedescriptor */ + int (*f_attach)(struct knote *kn); + void (*f_detach)(struct knote *kn); + int (*f_event)(struct knote *kn, long hint); +}; + +struct knote { + SLIST_ENTRY(knote) kn_link; /* for fd */ + SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */ + TAILQ_ENTRY(knote) kn_tqe; + struct kqueue *kn_kq; /* which queue we are on */ + struct kevent kn_kevent; + int kn_status; + int kn_sfflags; /* saved filter flags */ + intptr_t kn_sdata; /* saved data field */ + union { + struct file *p_fp; /* file data pointer */ + struct proc *p_proc; /* proc pointer */ + } kn_ptr; + struct filterops *kn_fop; + void *kn_hook; +#define KN_ACTIVE 0x01 /* event has been triggered */ +#define KN_QUEUED 0x02 /* event is on queue */ +#define KN_DISABLED 0x04 /* event is disabled */ +#define KN_DETACHED 0x08 /* knote is detached */ + +#define kn_id kn_kevent.ident +#define kn_filter kn_kevent.filter +#define kn_flags kn_kevent.flags +#define kn_fflags kn_kevent.fflags +#define kn_data kn_kevent.data +#define kn_fp kn_ptr.p_fp +}; + +struct thread; +struct proc; + +extern void knote(struct klist *list, long hint); +extern void knote_remove(struct thread *p, struct klist *list); +extern void knote_fdclose(struct thread *p, int fd); +extern int kqueue_register(struct kqueue *kq, + struct kevent *kev, struct thread *p); +extern int kqueue_add_filteropts(int filt, struct filterops *filtops); +extern int kqueue_del_filteropts(int filt); + +#else /* !_KERNEL */ + +#include +struct timespec; + +__BEGIN_DECLS +int kqueue(void); +int kevent(int kq, const struct kevent *changelist, int nchanges, + struct kevent *eventlist, int nevents, + const struct timespec *timeout); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_EVENT_H_ */ diff --git a/src/include/sys/eventhandler.h b/src/include/sys/eventhandler.h new file mode 100644 index 0000000..83ddd8b --- /dev/null +++ b/src/include/sys/eventhandler.h @@ -0,0 +1,174 @@ +/*- + * Copyright (c) 1999 Michael Smith + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/eventhandler.h,v 1.32 2004/03/14 02:06:28 peter Exp $ + */ + +#ifndef SYS_EVENTHANDLER_H +#define SYS_EVENTHANDLER_H + +#include +#include +#include +#include + +struct eventhandler_entry { + TAILQ_ENTRY(eventhandler_entry) ee_link; + int ee_priority; +#define EHE_DEAD_PRIORITY (-1) + void *ee_arg; +}; + +struct eventhandler_list { + char *el_name; + int el_flags; +#define EHL_INITTED (1<<0) + u_int el_runcount; + struct mtx el_lock; + TAILQ_ENTRY(eventhandler_list) el_link; + TAILQ_HEAD(,eventhandler_entry) el_entries; +}; + +typedef struct eventhandler_entry *eventhandler_tag; + +#define EHL_LOCK(p) mtx_lock(&(p)->el_lock) +#define EHL_UNLOCK(p) mtx_unlock(&(p)->el_lock) +#define EHL_LOCK_ASSERT(p, x) mtx_assert(&(p)->el_lock, x) + +/* + * Macro to invoke the handlers for a given event. + */ +#define _EVENTHANDLER_INVOKE(name, list, ...) do { \ + struct eventhandler_entry *_ep; \ + struct eventhandler_entry_ ## name *_t; \ + \ + KASSERT((list)->el_flags & EHL_INITTED, \ + ("eventhandler_invoke: running non-inited list")); \ + EHL_LOCK_ASSERT((list), MA_OWNED); \ + (list)->el_runcount++; \ + KASSERT((list)->el_runcount > 0, \ + ("eventhandler_invoke: runcount overflow")); \ + CTR0(KTR_EVH, "eventhandler_invoke(\"" __STRING(name) "\")"); \ + TAILQ_FOREACH(_ep, &((list)->el_entries), ee_link) { \ + if (_ep->ee_priority != EHE_DEAD_PRIORITY) { \ + EHL_UNLOCK((list)); \ + _t = (struct eventhandler_entry_ ## name *)_ep; \ + CTR1(KTR_EVH, "eventhandler_invoke: executing %p", \ + (void *)_t->eh_func); \ + _t->eh_func(_ep->ee_arg , ## __VA_ARGS__); \ + EHL_LOCK((list)); \ + } \ + } \ + KASSERT((list)->el_runcount > 0, \ + ("eventhandler_invoke: runcount underflow")); \ + (list)->el_runcount--; \ + if ((list)->el_runcount == 0) \ + eventhandler_prune_list(list); \ + EHL_UNLOCK((list)); \ +} while (0) + +/* + * Slow handlers are entirely dynamic; lists are created + * when entries are added to them, and thus have no concept of "owner", + * + * Slow handlers need to be declared, but do not need to be defined. The + * declaration must be in scope wherever the handler is to be invoked. + */ +#define EVENTHANDLER_DECLARE(name, type) \ +struct eventhandler_entry_ ## name \ +{ \ + struct eventhandler_entry ee; \ + type eh_func; \ +}; \ +struct __hack + +#define EVENTHANDLER_INVOKE(name, ...) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + _EVENTHANDLER_INVOKE(name, _el , ## __VA_ARGS__); \ +} while (0) + +#define EVENTHANDLER_REGISTER(name, func, arg, priority) \ + eventhandler_register(NULL, #name, func, arg, priority) + +#define EVENTHANDLER_DEREGISTER(name, tag) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + eventhandler_deregister(_el, tag); \ +} while(0) + + +eventhandler_tag eventhandler_register(struct eventhandler_list *list, + char *name, void *func, void *arg, int priority); +void eventhandler_deregister(struct eventhandler_list *list, + eventhandler_tag tag); +struct eventhandler_list *eventhandler_find_list(char *name); +void eventhandler_prune_list(struct eventhandler_list *list); + +/* + * Standard system event queues. + */ + +/* Generic priority levels */ +#define EVENTHANDLER_PRI_FIRST 0 +#define EVENTHANDLER_PRI_ANY 10000 +#define EVENTHANDLER_PRI_LAST 20000 + +/* Shutdown events */ +typedef void (*shutdown_fn)(void *, int); + +#define SHUTDOWN_PRI_FIRST EVENTHANDLER_PRI_FIRST +#define SHUTDOWN_PRI_DEFAULT EVENTHANDLER_PRI_ANY +#define SHUTDOWN_PRI_LAST EVENTHANDLER_PRI_LAST + +EVENTHANDLER_DECLARE(shutdown_pre_sync, shutdown_fn); /* before fs sync */ +EVENTHANDLER_DECLARE(shutdown_post_sync, shutdown_fn); /* after fs sync */ +EVENTHANDLER_DECLARE(shutdown_final, shutdown_fn); + +/* Low memory event */ +typedef void (*vm_lowmem_handler_t)(void *, int); +#define LOWMEM_PRI_DEFAULT EVENTHANDLER_PRI_FIRST +EVENTHANDLER_DECLARE(vm_lowmem, vm_lowmem_handler_t); + +/* + * Process events + * process_fork and exit handlers are called without Giant. + * exec handlers are called with Giant, but that is by accident. + */ +struct proc; + +typedef void (*exitlist_fn)(void *, struct proc *); +typedef void (*forklist_fn)(void *, struct proc *, struct proc *, int); +typedef void (*execlist_fn)(void *, struct proc *); + +EVENTHANDLER_DECLARE(process_exit, exitlist_fn); +EVENTHANDLER_DECLARE(process_fork, forklist_fn); +EVENTHANDLER_DECLARE(process_exec, execlist_fn); + +#endif /* SYS_EVENTHANDLER_H */ diff --git a/src/include/sys/eventvar.h b/src/include/sys/eventvar.h new file mode 100644 index 0000000..2f900c5 --- /dev/null +++ b/src/include/sys/eventvar.h @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 1999,2000 Jonathan Lemon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/eventvar.h,v 1.4 2000/07/18 19:31:48 jlemon Exp $ + */ + +#ifndef _SYS_EVENTVAR_H_ +#define _SYS_EVENTVAR_H_ + +#define KQ_NEVENTS 8 /* minimize copy{in,out} calls */ +#define KQEXTENT 256 /* linear growth by this amount */ + +struct kqueue { + TAILQ_HEAD(kqlist, knote) kq_head; /* list of pending event */ + int kq_count; /* number of pending events */ + struct selinfo kq_sel; + struct filedesc *kq_fdp; + int kq_state; +#define KQ_SEL 0x01 +#define KQ_SLEEP 0x02 + struct kevent kq_kev[KQ_NEVENTS]; +}; + +#endif /* !_SYS_EVENTVAR_H_ */ diff --git a/src/include/sys/exec.h b/src/include/sys/exec.h new file mode 100644 index 0000000..d64575f --- /dev/null +++ b/src/include/sys/exec.h @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)exec.h 8.3 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/exec.h,v 1.30 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_EXEC_H_ +#define _SYS_EXEC_H_ + +/* + * The following structure is found at the top of the user stack of each + * user process. The ps program uses it to locate argv and environment + * strings. Programs that wish ps to display other information may modify + * it; normally ps_argvstr points to the argv vector, and ps_nargvstr + * is the same as the program's argc. The fields ps_envstr and ps_nenvstr + * are the equivalent for the environment. + */ +struct ps_strings { + char **ps_argvstr; /* first of 0 or more argument strings */ + int ps_nargvstr; /* the number of argument strings */ + char **ps_envstr; /* first of 0 or more environment strings */ + int ps_nenvstr; /* the number of environment strings */ +}; + +/* + * Address of ps_strings structure (in user space). + */ +#define PS_STRINGS (USRSTACK - sizeof(struct ps_strings)) +#define SPARE_USRSPACE 4096 + +struct image_params; + +struct execsw { + int (*ex_imgact)(struct image_params *); + const char *ex_name; +}; + +#include + +#ifdef _KERNEL +#include + +int exec_map_first_page(struct image_params *); +void exec_unmap_first_page(struct image_params *); + +int exec_register(const struct execsw *); +int exec_unregister(const struct execsw *); + +/* + * note: name##_mod cannot be const storage because the + * linker_file_sysinit() function modifies _file in the + * moduledata_t. + */ + +#include + +#define EXEC_SET(name, execsw_arg) \ + static int __CONCAT(name,_modevent)(module_t mod, int type, \ + void *data) \ + { \ + struct execsw *exec = (struct execsw *)data; \ + int error = 0; \ + switch (type) { \ + case MOD_LOAD: \ + /* printf(#name " module loaded\n"); */ \ + error = exec_register(exec); \ + if (error) \ + printf(__XSTRING(name) "register failed\n"); \ + break; \ + case MOD_UNLOAD: \ + /* printf(#name " module unloaded\n"); */ \ + error = exec_unregister(exec); \ + if (error) \ + printf(__XSTRING(name) " unregister failed\n");\ + break; \ + default: \ + break; \ + } \ + return error; \ + } \ + static moduledata_t __CONCAT(name,_mod) = { \ + __XSTRING(name), \ + __CONCAT(name,_modevent), \ + (void *)& execsw_arg \ + }; \ + DECLARE_MODULE(name, __CONCAT(name,_mod), SI_SUB_EXEC, SI_ORDER_ANY) +#endif + +#endif diff --git a/src/include/sys/extattr.h b/src/include/sys/extattr.h new file mode 100644 index 0000000..5651477 --- /dev/null +++ b/src/include/sys/extattr.h @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 1999-2001 Robert N. M. Watson + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/extattr.h,v 1.12 2003/06/04 04:04:24 rwatson Exp $ + */ +/* + * Developed by the TrustedBSD Project. + * Support for extended filesystem attributes. + */ + +#ifndef _SYS_EXTATTR_H_ +#define _SYS_EXTATTR_H_ + +#define EXTATTR_NAMESPACE_USER 0x00000001 +#define EXTATTR_NAMESPACE_USER_STRING "user" +#define EXTATTR_NAMESPACE_SYSTEM 0x00000002 +#define EXTATTR_NAMESPACE_SYSTEM_STRING "system" + +#ifdef _KERNEL + +#define EXTATTR_MAXNAMELEN NAME_MAX +struct thread; +struct ucred; +struct vnode; +int extattr_check_cred(struct vnode *vp, int attrnamespace, + struct ucred *cred, struct thread *td, int access); + +#else +#include + +struct iovec; + +__BEGIN_DECLS +int extattrctl(const char *_path, int _cmd, const char *_filename, + int _attrnamespace, const char *_attrname); +int extattr_delete_fd(int _fd, int _attrnamespace, const char *_attrname); +int extattr_delete_file(const char *_path, int _attrnamespace, + const char *_attrname); +int extattr_delete_link(const char *_path, int _attrnamespace, + const char *_attrname); +ssize_t extattr_get_fd(int _fd, int _attrnamespace, const char *_attrname, + void *_data, size_t _nbytes); +ssize_t extattr_get_file(const char *_path, int _attrnamespace, + const char *_attrname, void *_data, size_t _nbytes); +ssize_t extattr_get_link(const char *_path, int _attrnamespace, + const char *_attrname, void *_data, size_t _nbytes); +ssize_t extattr_list_fd(int _fd, int _attrnamespace, void *_data, + size_t _nbytes); +ssize_t extattr_list_file(const char *_path, int _attrnamespace, void *_data, + size_t _nbytes); +ssize_t extattr_list_link(const char *_path, int _attrnamespace, void *_data, + size_t _nbytes); +int extattr_set_fd(int _fd, int _attrnamespace, const char *_attrname, + const void *_data, size_t _nbytes); +int extattr_set_file(const char *_path, int _attrnamespace, + const char *_attrname, const void *_data, size_t _nbytes); +int extattr_set_link(const char *_path, int _attrnamespace, + const char *_attrname, const void *_data, size_t _nbytes); +__END_DECLS + +#endif /* !_KERNEL */ +#endif /* !_SYS_EXTATTR_H_ */ diff --git a/src/include/sys/fbio.h b/src/include/sys/fbio.h new file mode 100644 index 0000000..4642de0 --- /dev/null +++ b/src/include/sys/fbio.h @@ -0,0 +1,555 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software developed by the Computer Systems + * Engineering group at Lawrence Berkeley Laboratory under DARPA + * contract BG 91-66 and contributed to Berkeley. + * + * 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. + * 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. + * + * @(#)fbio.h 8.2 (Berkeley) 10/30/93 + * + * $FreeBSD: src/sys/sys/fbio.h,v 1.14 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_FBIO_H_ +#define _SYS_FBIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Frame buffer ioctls (from Sprite, trimmed to essentials for X11). + */ + +/* + * Frame buffer type codes. + */ +#define FBTYPE_SUN1BW 0 /* multibus mono */ +#define FBTYPE_SUN1COLOR 1 /* multibus color */ +#define FBTYPE_SUN2BW 2 /* memory mono */ +#define FBTYPE_SUN2COLOR 3 /* color w/rasterop chips */ +#define FBTYPE_SUN2GP 4 /* GP1/GP2 */ +#define FBTYPE_SUN5COLOR 5 /* RoadRunner accelerator */ +#define FBTYPE_SUN3COLOR 6 /* memory color */ +#define FBTYPE_MEMCOLOR 7 /* memory 24-bit */ +#define FBTYPE_SUN4COLOR 8 /* memory color w/overlay */ + +#define FBTYPE_NOTSUN1 9 /* reserved for customer */ +#define FBTYPE_NOTSUN2 10 /* reserved for customer */ +#define FBTYPE_NOTSUN3 11 /* reserved for customer */ + +#define FBTYPE_SUNFAST_COLOR 12 /* accelerated 8bit */ +#define FBTYPE_SUNROP_COLOR 13 /* MEMCOLOR with rop h/w */ +#define FBTYPE_SUNFB_VIDEO 14 /* Simple video mixing */ +#define FBTYPE_RESERVED5 15 /* reserved, do not use */ +#define FBTYPE_RESERVED4 16 /* reserved, do not use */ +#define FBTYPE_SUNGP3 17 +#define FBTYPE_SUNGT 18 +#define FBTYPE_SUNLEO 19 /* zx Leo */ + +#define FBTYPE_MDA 20 +#define FBTYPE_HERCULES 21 +#define FBTYPE_CGA 22 +#define FBTYPE_EGA 23 +#define FBTYPE_VGA 24 +#define FBTYPE_PC98 25 +#define FBTYPE_TGA 26 +#define FBTYPE_TGA2 27 + +#define FBTYPE_MDICOLOR 28 /* cg14 */ +#define FBTYPE_TCXCOLOR 29 /* SUNW,tcx */ +#define FBTYPE_CREATOR 30 + +#define FBTYPE_LASTPLUSONE 31 /* max number of fbs (change as add) */ + +/* + * Frame buffer descriptor as returned by FBIOGTYPE. + */ +struct fbtype { + int fb_type; /* as defined above */ + int fb_height; /* in pixels */ + int fb_width; /* in pixels */ + int fb_depth; /* bits per pixel */ + int fb_cmsize; /* size of color map (entries) */ + int fb_size; /* total size in bytes */ +}; +#define FBIOGTYPE _IOR('F', 0, struct fbtype) + +#ifdef notdef +/* + * General purpose structure for passing info in and out of frame buffers + * (used for gp1) -- unsupported. + */ +struct fbinfo { + int fb_physaddr; /* physical frame buffer address */ + int fb_hwwidth; /* fb board width */ + int fb_hwheight; /* fb board height */ + int fb_addrdelta; /* phys addr diff between boards */ + u_char *fb_ropaddr; /* fb virtual addr */ + int fb_unit; /* minor devnum of fb */ +}; +#define FBIOGINFO _IOR('F', 2, struct fbinfo) +#endif + +/* + * Color map I/O. + */ +struct fbcmap { + int index; /* first element (0 origin) */ + int count; /* number of elements */ + u_char *red; /* red color map elements */ + u_char *green; /* green color map elements */ + u_char *blue; /* blue color map elements */ +}; +#define FBIOPUTCMAP _IOW('F', 3, struct fbcmap) +#define FBIOGETCMAP _IOW('F', 4, struct fbcmap) + +/* + * Set/get attributes. + */ +#define FB_ATTR_NDEVSPECIFIC 8 /* no. of device specific values */ +#define FB_ATTR_NEMUTYPES 4 /* no. of emulation types */ + +struct fbsattr { + int flags; /* flags; see below */ + int emu_type; /* emulation type (-1 if unused) */ + int dev_specific[FB_ATTR_NDEVSPECIFIC]; /* catchall */ +}; +#define FB_ATTR_AUTOINIT 1 /* emulation auto init flag */ +#define FB_ATTR_DEVSPECIFIC 2 /* dev. specific stuff valid flag */ + +struct fbgattr { + int real_type; /* real device type */ + int owner; /* PID of owner, 0 if myself */ + struct fbtype fbtype; /* fbtype info for real device */ + struct fbsattr sattr; /* see above */ + int emu_types[FB_ATTR_NEMUTYPES]; /* possible emulations */ + /* (-1 if unused) */ +}; +#define FBIOSATTR _IOW('F', 5, struct fbsattr) +#define FBIOGATTR _IOR('F', 6, struct fbgattr) + +/* + * Video control. + */ +#define FBVIDEO_OFF 0 +#define FBVIDEO_ON 1 + +#define FBIOSVIDEO _IOW('F', 7, int) +#define FBIOGVIDEO _IOR('F', 8, int) + +/* vertical retrace */ +#define FBIOVERTICAL _IO('F', 9) + +/* + * Hardware cursor control (for, e.g., CG6). A rather complex and icky + * interface that smells like VMS, but there it is.... + */ +struct fbcurpos { + short x; + short y; +}; + +struct fbcursor { + short set; /* flags; see below */ + short enable; /* nonzero => cursor on, 0 => cursor off */ + struct fbcurpos pos; /* position on display */ + struct fbcurpos hot; /* hot-spot within cursor */ + struct fbcmap cmap; /* cursor color map */ + struct fbcurpos size; /* number of valid bits in image & mask */ + caddr_t image; /* cursor image bits */ + caddr_t mask; /* cursor mask bits */ +}; +#define FB_CUR_SETCUR 0x01 /* set on/off (i.e., obey fbcursor.enable) */ +#define FB_CUR_SETPOS 0x02 /* set position */ +#define FB_CUR_SETHOT 0x04 /* set hot-spot */ +#define FB_CUR_SETCMAP 0x08 /* set cursor color map */ +#define FB_CUR_SETSHAPE 0x10 /* set size & bits */ +#define FB_CUR_SETALL (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT | \ + FB_CUR_SETCMAP | FB_CUR_SETSHAPE) + +/* controls for cursor attributes & shape (including position) */ +#define FBIOSCURSOR _IOW('F', 24, struct fbcursor) +#define FBIOGCURSOR _IOWR('F', 25, struct fbcursor) + +/* controls for cursor position only */ +#define FBIOSCURPOS _IOW('F', 26, struct fbcurpos) +#define FBIOGCURPOS _IOW('F', 27, struct fbcurpos) + +/* get maximum cursor size */ +#define FBIOGCURMAX _IOR('F', 28, struct fbcurpos) + +/* + * Video board information + */ +struct brd_info { + u_short accessible_width; /* accessible bytes in scanline */ + u_short accessible_height; /* number of accessible scanlines */ + u_short line_bytes; /* number of bytes/scanline */ + u_short hdb_capable; /* can this thing hardware db? */ + u_short vmsize; /* video memory size */ + u_char boardrev; /* board revision # */ + u_char pad0; + u_long pad1; +}; +#define FBIOGXINFO _IOR('F', 39, struct brd_info) + +/* + * Monitor information + */ +struct mon_info { + u_long mon_type; /* bit array */ +#define MON_TYPE_STEREO 0x8 /* stereo display */ +#define MON_TYPE_0_OFFSET 0x4 /* black level 0 ire instead of 7.5 */ +#define MON_TYPE_OVERSCAN 0x2 /* overscan */ +#define MON_TYPE_GRAY 0x1 /* greyscale monitor */ + u_long pixfreq; /* pixel frequency in Hz */ + u_long hfreq; /* horizontal freq in Hz */ + u_long vfreq; /* vertical freq in Hz */ + u_long vsync; /* vertical sync in scanlines */ + u_long hsync; /* horizontal sync in pixels */ + /* these are in pixel units */ + u_short hfporch; /* horizontal front porch */ + u_short hbporch; /* horizontal back porch */ + u_short vfporch; /* vertical front porch */ + u_short vbporch; /* vertical back porch */ +}; +#define FBIOMONINFO _IOR('F', 40, struct mon_info) + +/* + * Color map I/O. + */ +struct fbcmap_i { + unsigned int flags; +#define FB_CMAP_BLOCK (1 << 0) /* wait for vertical refresh */ +#define FB_CMAP_KERNEL (1 << 1) /* called within kernel */ + int id; /* color map id */ + int index; /* first element (0 origin) */ + int count; /* number of elements */ + u_char *red; /* red color map elements */ + u_char *green; /* green color map elements */ + u_char *blue; /* blue color map elements */ +}; +#define FBIOPUTCMAPI _IOW('F', 41, struct fbcmap_i) +#define FBIOGETCMAPI _IOW('F', 42, struct fbcmap_i) + +/* The new style frame buffer ioctls. */ + +/* video mode information block */ +struct video_info { + int vi_mode; /* mode number, see below */ + int vi_flags; +#define V_INFO_COLOR (1 << 0) +#define V_INFO_GRAPHICS (1 << 1) +#define V_INFO_LINEAR (1 << 2) +#define V_INFO_VESA (1 << 3) + int vi_width; + int vi_height; + int vi_cwidth; + int vi_cheight; + int vi_depth; + int vi_planes; + vm_offset_t vi_window; /* physical address */ + size_t vi_window_size; + size_t vi_window_gran; + vm_offset_t vi_buffer; /* physical address */ + size_t vi_buffer_size; + int vi_mem_model; +#define V_INFO_MM_OTHER (-1) +#define V_INFO_MM_TEXT 0 +#define V_INFO_MM_PLANAR 1 +#define V_INFO_MM_PACKED 2 +#define V_INFO_MM_DIRECT 3 +#define V_INFO_MM_CGA 100 +#define V_INFO_MM_HGC 101 +#define V_INFO_MM_VGAX 102 + /* for MM_PACKED and MM_DIRECT only */ + int vi_pixel_size; /* in bytes */ + /* for MM_DIRECT only */ + int vi_pixel_fields[4]; /* RGB and reserved fields */ + int vi_pixel_fsizes[4]; + /* reserved */ + u_char vi_reserved[64]; + vm_offset_t vi_registers; /* physical address */ + vm_offset_t vi_registers_size; +}; +typedef struct video_info video_info_t; + +/* adapter infromation block */ +struct video_adapter { + int va_index; + int va_type; +#define KD_OTHER 0 /* unknown */ +#define KD_MONO 1 /* monochrome adapter */ +#define KD_HERCULES 2 /* hercules adapter */ +#define KD_CGA 3 /* color graphics adapter */ +#define KD_EGA 4 /* enhanced graphics adapter */ +#define KD_VGA 5 /* video graphics adapter */ +#define KD_PC98 6 /* PC-98 display */ +#define KD_TGA 7 /* TGA */ +#define KD_TGA2 8 /* TGA2 */ + char *va_name; + int va_unit; + int va_minor; + int va_flags; +#define V_ADP_COLOR (1 << 0) +#define V_ADP_MODECHANGE (1 << 1) +#define V_ADP_STATESAVE (1 << 2) +#define V_ADP_STATELOAD (1 << 3) +#define V_ADP_FONT (1 << 4) +#define V_ADP_PALETTE (1 << 5) +#define V_ADP_BORDER (1 << 6) +#define V_ADP_VESA (1 << 7) +#define V_ADP_BOOTDISPLAY (1 << 8) +#define V_ADP_PROBED (1 << 16) +#define V_ADP_INITIALIZED (1 << 17) +#define V_ADP_REGISTERED (1 << 18) +#define V_ADP_ATTACHED (1 << 19) + vm_offset_t va_io_base; + int va_io_size; + vm_offset_t va_crtc_addr; + vm_offset_t va_mem_base; + int va_mem_size; + vm_offset_t va_window; /* virtual address */ + size_t va_window_size; + size_t va_window_gran; + u_int va_window_orig; + vm_offset_t va_buffer; /* virtual address */ + size_t va_buffer_size; + int va_initial_mode; + int va_initial_bios_mode; + int va_mode; + struct video_info va_info; + int va_line_width; + struct { + int x; + int y; + } va_disp_start; + void *va_token; + int va_model; + int va_little_bitian; + int va_little_endian; + int va_buffer_alias; + vm_offset_t va_registers; /* virtual address */ + vm_offset_t va_registers_size; +}; +typedef struct video_adapter video_adapter_t; + +struct video_adapter_info { + int va_index; + int va_type; + char va_name[16]; + int va_unit; + int va_flags; + vm_offset_t va_io_base; + int va_io_size; + vm_offset_t va_crtc_addr; + vm_offset_t va_mem_base; + int va_mem_size; + vm_offset_t va_window; /* virtual address */ + size_t va_window_size; + size_t va_window_gran; + vm_offset_t va_unused0; + size_t va_buffer_size; + int va_initial_mode; + int va_initial_bios_mode; + int va_mode; + int va_line_width; + struct { + int x; + int y; + } va_disp_start; + u_int va_window_orig; + /* reserved */ + u_char va_reserved[64]; +}; +typedef struct video_adapter_info video_adapter_info_t; + +/* some useful video adapter index */ +#define V_ADP_PRIMARY 0 +#define V_ADP_SECONDARY 1 + +/* video mode numbers */ + +#define M_B40x25 0 /* black & white 40 columns */ +#define M_C40x25 1 /* color 40 columns */ +#define M_B80x25 2 /* black & white 80 columns */ +#define M_C80x25 3 /* color 80 columns */ +#define M_BG320 4 /* black & white graphics 320x200 */ +#define M_CG320 5 /* color graphics 320x200 */ +#define M_BG640 6 /* black & white graphics 640x200 hi-res */ +#define M_EGAMONO80x25 7 /* ega-mono 80x25 */ +#define M_CG320_D 13 /* ega mode D */ +#define M_CG640_E 14 /* ega mode E */ +#define M_EGAMONOAPA 15 /* ega mode F */ +#define M_CG640x350 16 /* ega mode 10 */ +#define M_ENHMONOAPA2 17 /* ega mode F with extended memory */ +#define M_ENH_CG640 18 /* ega mode 10* */ +#define M_ENH_B40x25 19 /* ega enhanced black & white 40 columns */ +#define M_ENH_C40x25 20 /* ega enhanced color 40 columns */ +#define M_ENH_B80x25 21 /* ega enhanced black & white 80 columns */ +#define M_ENH_C80x25 22 /* ega enhanced color 80 columns */ +#define M_VGA_C40x25 23 /* vga 8x16 font on color */ +#define M_VGA_C80x25 24 /* vga 8x16 font on color */ +#define M_VGA_M80x25 25 /* vga 8x16 font on mono */ + +#define M_VGA11 26 /* vga 640x480 2 colors */ +#define M_BG640x480 26 +#define M_VGA12 27 /* vga 640x480 16 colors */ +#define M_CG640x480 27 +#define M_VGA13 28 /* vga 320x200 256 colors */ +#define M_VGA_CG320 28 + +#define M_VGA_C80x50 30 /* vga 8x8 font on color */ +#define M_VGA_M80x50 31 /* vga 8x8 font on color */ +#define M_VGA_C80x30 32 /* vga 8x16 font on color */ +#define M_VGA_M80x30 33 /* vga 8x16 font on color */ +#define M_VGA_C80x60 34 /* vga 8x8 font on color */ +#define M_VGA_M80x60 35 /* vga 8x8 font on color */ +#define M_VGA_CG640 36 /* vga 640x400 256 color */ +#define M_VGA_MODEX 37 /* vga 320x240 256 color */ + +#define M_VGA_C90x25 40 /* vga 8x16 font on color */ +#define M_VGA_M90x25 41 /* vga 8x16 font on mono */ +#define M_VGA_C90x30 42 /* vga 8x16 font on color */ +#define M_VGA_M90x30 43 /* vga 8x16 font on mono */ +#define M_VGA_C90x43 44 /* vga 8x8 font on color */ +#define M_VGA_M90x43 45 /* vga 8x8 font on mono */ +#define M_VGA_C90x50 46 /* vga 8x8 font on color */ +#define M_VGA_M90x50 47 /* vga 8x8 font on mono */ +#define M_VGA_C90x60 48 /* vga 8x8 font on color */ +#define M_VGA_M90x60 49 /* vga 8x8 font on mono */ + +#define M_ENH_B80x43 0x70 /* ega black & white 80x43 */ +#define M_ENH_C80x43 0x71 /* ega color 80x43 */ + +#define M_PC98_80x25 98 /* PC98 text 80x25 */ +#define M_PC98_80x30 99 /* PC98 text 80x30 */ +#define M_PC98_EGC640x400 100 /* PC98 graphic 640x400 16 colors */ +#define M_PC98_PEGC640x400 101 /* PC98 graphic 640x400 256 colors */ +#define M_PC98_PEGC640x480 102 /* PC98 graphic 640x480 256 colors */ + +#define M_HGC_P0 0xe0 /* hercules graphics - page 0 @ B0000 */ +#define M_HGC_P1 0xe1 /* hercules graphics - page 1 @ B8000 */ +#define M_MCA_MODE 0xff /* monochrome adapter mode */ + +#define M_TEXT_80x25 200 /* generic text modes */ +#define M_TEXT_80x30 201 +#define M_TEXT_80x43 202 +#define M_TEXT_80x50 203 +#define M_TEXT_80x60 204 +#define M_TEXT_132x25 205 +#define M_TEXT_132x30 206 +#define M_TEXT_132x43 207 +#define M_TEXT_132x50 208 +#define M_TEXT_132x60 209 + +#define M_VESA_BASE 0x100 /* VESA mode number base */ +#define M_VESA_CG640x400 0x100 /* 640x400, 256 color */ +#define M_VESA_CG640x480 0x101 /* 640x480, 256 color */ +#define M_VESA_800x600 0x102 /* 800x600, 16 color */ +#define M_VESA_CG800x600 0x103 /* 800x600, 256 color */ +#define M_VESA_1024x768 0x104 /* 1024x768, 16 color */ +#define M_VESA_CG1024x768 0x105 /* 1024x768, 256 color */ +#define M_VESA_1280x1024 0x106 /* 1280x1024, 16 color */ +#define M_VESA_CG1280x1024 0x107 /* 1280x1024, 256 color */ +#define M_VESA_C80x60 0x108 /* 8x8 font */ +#define M_VESA_C132x25 0x109 /* 8x16 font */ +#define M_VESA_C132x43 0x10a /* 8x14 font */ +#define M_VESA_C132x50 0x10b /* 8x8 font */ +#define M_VESA_C132x60 0x10c /* 8x8 font */ +#define M_VESA_32K_320 0x10d /* 320x200, 5:5:5 */ +#define M_VESA_64K_320 0x10e /* 320x200, 5:6:5 */ +#define M_VESA_FULL_320 0x10f /* 320x200, 8:8:8 */ +#define M_VESA_32K_640 0x110 /* 640x480, 5:5:5 */ +#define M_VESA_64K_640 0x111 /* 640x480, 5:6:5 */ +#define M_VESA_FULL_640 0x112 /* 640x480, 8:8:8 */ +#define M_VESA_32K_800 0x113 /* 800x600, 5:5:5 */ +#define M_VESA_64K_800 0x114 /* 800x600, 5:6:5 */ +#define M_VESA_FULL_800 0x115 /* 800x600, 8:8:8 */ +#define M_VESA_32K_1024 0x116 /* 1024x768, 5:5:5 */ +#define M_VESA_64K_1024 0x117 /* 1024x768, 5:6:5 */ +#define M_VESA_FULL_1024 0x118 /* 1024x768, 8:8:8 */ +#define M_VESA_32K_1280 0x119 /* 1280x1024, 5:5:5 */ +#define M_VESA_64K_1280 0x11a /* 1280x1024, 5:6:5 */ +#define M_VESA_FULL_1280 0x11b /* 1280x1024, 8:8:8 */ +#define M_VESA_MODE_MAX 0x1ff + +struct video_display_start { + int x; + int y; +}; +typedef struct video_display_start video_display_start_t; + +struct video_color_palette { + int index; /* first element (zero-based) */ + int count; /* number of elements */ + u_char *red; /* red */ + u_char *green; /* green */ + u_char *blue; /* blue */ + u_char *transparent; /* may be NULL */ +}; +typedef struct video_color_palette video_color_palette_t; + +/* adapter info. */ +#define FBIO_ADAPTER _IOR('F', 100, int) +#define FBIO_ADPTYPE _IOR('F', 101, int) +#define FBIO_ADPINFO _IOR('F', 102, struct video_adapter_info) + +/* video mode control */ +#define FBIO_MODEINFO _IOWR('F', 103, struct video_info) +#define FBIO_FINDMODE _IOWR('F', 104, struct video_info) +#define FBIO_GETMODE _IOR('F', 105, int) +#define FBIO_SETMODE _IOW('F', 106, int) + +/* get/set frame buffer window origin */ +#define FBIO_GETWINORG _IOR('F', 107, u_int) +#define FBIO_SETWINORG _IOW('F', 108, u_int) + +/* get/set display start address */ +#define FBIO_GETDISPSTART _IOR('F', 109, video_display_start_t) +#define FBIO_SETDISPSTART _IOW('F', 110, video_display_start_t) + +/* get/set scan line width */ +#define FBIO_GETLINEWIDTH _IOR('F', 111, u_int) +#define FBIO_SETLINEWIDTH _IOW('F', 112, u_int) + +/* color palette control */ +#define FBIO_GETPALETTE _IOW('F', 113, video_color_palette_t) +#define FBIO_SETPALETTE _IOW('F', 114, video_color_palette_t) + +/* blank display */ +#define V_DISPLAY_ON 0 +#define V_DISPLAY_BLANK 1 +#define V_DISPLAY_STAND_BY 2 +#define V_DISPLAY_SUSPEND 3 + +#define FBIO_BLANK _IOW('F', 115, int) + +#endif /* !_SYS_FBIO_H_ */ diff --git a/src/include/sys/fcntl.h b/src/include/sys/fcntl.h new file mode 100644 index 0000000..2fb656e --- /dev/null +++ b/src/include/sys/fcntl.h @@ -0,0 +1,229 @@ +/*- + * Copyright (c) 1983, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)fcntl.h 8.3 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/fcntl.h,v 1.16 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_FCNTL_H_ +#define _SYS_FCNTL_H_ + +/* + * This file includes the definitions for open and fcntl + * described by POSIX for ; it also includes + * related kernel definitions. + */ + +#include +#include + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +/* + * File status flags: these are used by open(2), fcntl(2). + * They are also used (indirectly) in the kernel file structure f_flags, + * which is a superset of the open/fcntl flags. Open flags and f_flags + * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). + * Open/fcntl flags begin with O_; kernel-internal flags begin with F. + */ +/* open-only flags */ +#define O_RDONLY 0x0000 /* open for reading only */ +#define O_WRONLY 0x0001 /* open for writing only */ +#define O_RDWR 0x0002 /* open for reading and writing */ +#define O_ACCMODE 0x0003 /* mask for above modes */ + +/* + * Kernel encoding of open mode; separate read and write bits that are + * independently testable: 1 greater than the above. + * + * XXX + * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH, + * which was documented to use FREAD/FWRITE, continues to work. + */ +#if __BSD_VISIBLE +#define FREAD 0x0001 +#define FWRITE 0x0002 +#endif +#define O_NONBLOCK 0x0004 /* no delay */ +#define O_APPEND 0x0008 /* set append mode */ +#if __BSD_VISIBLE +#define O_SHLOCK 0x0010 /* open with shared file lock */ +#define O_EXLOCK 0x0020 /* open with exclusive file lock */ +#define O_ASYNC 0x0040 /* signal pgrp when data ready */ +#define O_FSYNC 0x0080 /* synchronous writes */ +#endif +#define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */ +#if __BSD_VISIBLE +#define O_NOFOLLOW 0x0100 /* don't follow symlinks */ +#endif +#define O_CREAT 0x0200 /* create if nonexistent */ +#define O_TRUNC 0x0400 /* truncate to zero length */ +#define O_EXCL 0x0800 /* error if already exists */ +#ifdef _KERNEL +#define FHASLOCK 0x4000 /* descriptor holds advisory lock */ +#endif + +/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */ +#define O_NOCTTY 0x8000 /* don't assign controlling terminal */ + +#if __BSD_VISIBLE +/* Attempt to bypass buffer cache */ +#define O_DIRECT 0x00010000 +#endif + +/* + * XXX missing O_DSYNC, O_RSYNC. + */ + +#ifdef _KERNEL +/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ +#define FFLAGS(oflags) ((oflags) + 1) +#define OFLAGS(fflags) ((fflags) - 1) + +/* bits to save after open */ +#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT) +/* bits settable by fcntl(F_SETFL, ...) */ +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT) +#endif + +/* + * The O_* flags used to have only F* names, which were used in the kernel + * and by fcntl. We retain the F* names for the kernel f_flag field + * and for backward compatibility for fcntl. These flags are deprecated. + */ +#if __BSD_VISIBLE +#define FAPPEND O_APPEND /* kernel/compat */ +#define FASYNC O_ASYNC /* kernel/compat */ +#define FFSYNC O_FSYNC /* kernel */ +#define FNONBLOCK O_NONBLOCK /* kernel */ +#define FNDELAY O_NONBLOCK /* compat */ +#define O_NDELAY O_NONBLOCK /* compat */ +#endif + +/* + * We are out of bits in f_flag (which is a short). However, + * the flag bits not set in FMASK are only meaningful in the + * initial open syscall. Those bits can thus be given a + * different meaning for fcntl(2). + */ +#if __BSD_VISIBLE + +/* + * Set by shm_open(3) to get automatic MAP_ASYNC behavior + * for POSIX shared memory objects (which are otherwise + * implemented as plain files). + */ +#define FPOSIXSHM O_NOFOLLOW +#endif + +/* + * Constants used for fcntl(2) + */ + +/* command values */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ +#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ +#endif +#define F_GETLK 7 /* get record locking information */ +#define F_SETLK 8 /* set record locking information */ +#define F_SETLKW 9 /* F_SETLK; wait if blocked */ + +/* file descriptor flags (F_GETFD, F_SETFD) */ +#define FD_CLOEXEC 1 /* close-on-exec flag */ + +/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ +#define F_RDLCK 1 /* shared or read lock */ +#define F_UNLCK 2 /* unlock */ +#define F_WRLCK 3 /* exclusive or write lock */ +#ifdef _KERNEL +#define F_WAIT 0x010 /* Wait until lock is granted */ +#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ +#define F_POSIX 0x040 /* Use POSIX semantics for lock */ +#endif + +/* + * Advisory file segment locking data type - + * information passed to system by user + */ +struct flock { + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ +}; + + +#if __BSD_VISIBLE +/* lock operations for flock(2) */ +#define LOCK_SH 0x01 /* shared file lock */ +#define LOCK_EX 0x02 /* exclusive file lock */ +#define LOCK_NB 0x04 /* don't block when locking */ +#define LOCK_UN 0x08 /* unlock file */ +#endif + +/* + * XXX missing posix_fadvise() and posix_fallocate(), and POSIX_FADV_* macros. + */ + +#ifndef _KERNEL +__BEGIN_DECLS +int open(const char *, int, ...); +int creat(const char *, mode_t); +int fcntl(int, int, ...); +#if __BSD_VISIBLE +int flock(int, int); +#endif +__END_DECLS +#endif + +#endif /* !_SYS_FCNTL_H_ */ diff --git a/src/include/sys/fdcio.h b/src/include/sys/fdcio.h new file mode 100644 index 0000000..cb63596 --- /dev/null +++ b/src/include/sys/fdcio.h @@ -0,0 +1,170 @@ +/* + * Copyright (C) 1992-1994,2001 by Joerg Wunsch, Dresden + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR(S) 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. + * + * $FreeBSD: src/sys/sys/fdcio.h,v 1.17 2001/12/15 19:07:58 joerg Exp $ + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#ifndef _KERNEL +#include +#endif +#include + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* FDC_???KBPS */ + + union { + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependent since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } structured; + u_char raw[1]; /* to have continuous indexed access */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.structured.secshift +# define fd_formb_nsecs format_info.structured.nsecs +# define fd_formb_gaplen format_info.structured.gaplen +# define fd_formb_fillbyte format_info.structured.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.structured.idfields[i].cylno +# define fd_formb_headno(i) format_info.structured.idfields[i].headno +# define fd_formb_secno(i) format_info.structured.idfields[i].secno +# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize + +struct fd_type { + int sectrac; /* sectors per track */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int gap; /* gap len between sectors */ + int tracks; /* total number of cylinders */ + int size; /* size of disk in sectors */ + int trans; /* transfer speed code */ + int heads; /* number of heads */ + int f_gap; /* format gap len */ + int f_inter; /* format interleave factor */ + int offset_side2; /* offset of sectors on side2 */ + int flags; /* misc. features */ +#define FL_MFM 0x0001 /* MFM recording */ +#define FL_2STEP 0x0002 /* 2 steps between cylinders */ +#define FL_PERPND 0x0004 /* perpendicular recording */ +}; + +struct fdc_status { + u_int status[7]; +}; + +/* + * cyl and head are being passed into ioctl(FD_READID) + * all four fields are being returned + */ +struct fdc_readid { + u_char cyl; /* C - 0...79 */ + u_char head; /* H - 0...1 */ + u_char sec; /* R - 1...n */ + u_char secshift; /* N - log2(secsize / 128) */ +}; + +/* + * Diskette drive type, basically the same as stored in RTC on ISA + * machines (see /sys/isa/rtc.h), but right-shifted by four bits. + */ +enum fd_drivetype { + FDT_NONE, FDT_360K, FDT_12M, FDT_720K, FDT_144M, FDT_288M_1, + FDT_288M +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FD_DEBUG _IOW('F', 66, int) + +#define FD_CLRERR _IO('F', 67) /* clear error counter */ + +#define FD_READID _IOWR('F', 68, struct fdc_readid) /* read ID field */ + +/* + * Obtain NE765 status registers. Only successful if there is + * a valid status stored in fdc->status[]. + */ +#define FD_GSTAT _IOR('F', 69, struct fdc_status) + +#define FD_GDTYPE _IOR('F', 70, enum fd_drivetype) /* obtain drive type */ + +/* Options for FD_GOPTS/FD_SOPTS, cleared on device close */ +#define FDOPT_NORETRY 0x0001 /* no retries on failure */ +#define FDOPT_NOERRLOG 0x002 /* no "hard error" kernel log messages */ +#define FDOPT_NOERROR 0x0004 /* do not indicate errors, caller will use + FD_GSTAT in order to obtain status */ +#define FDOPT_AUTOSEL 0x8000 /* read/only option: device performs media + * autoselection */ + +/* + * Transfer rate definitions. Used in the structures above. They + * represent the hardware encoding of bits 0 and 1 of the FDC control + * register when writing to the register. + * Transfer rates for FM encoding are half the values listed here + * (but we currently don't support FM encoding). + */ +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_1MBPS 0x03 /* 1MPBS MFM drive transfer rate */ + +#endif /* !_MACHINE_IOCTL_FD_H_ */ diff --git a/src/include/sys/file.h b/src/include/sys/file.h new file mode 100644 index 0000000..97ad04d --- /dev/null +++ b/src/include/sys/file.h @@ -0,0 +1,302 @@ +/* + * Copyright (c) 1982, 1986, 1989, 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. + * 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. + * + * @(#)file.h 8.3 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/file.h,v 1.64 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_FILE_H_ +#define _SYS_FILE_H_ + +#ifndef _KERNEL +#include /* XXX */ +#include +#include +#else +#include +#include +#include + +struct stat; +struct thread; +struct uio; +struct knote; +struct vnode; +struct socket; + + +#endif /* _KERNEL */ + +#define DTYPE_VNODE 1 /* file */ +#define DTYPE_SOCKET 2 /* communications endpoint */ +#define DTYPE_PIPE 3 /* pipe */ +#define DTYPE_FIFO 4 /* fifo (named pipe) */ +#define DTYPE_KQUEUE 5 /* event queue */ +#define DTYPE_CRYPTO 6 /* crypto */ + +#ifdef _KERNEL + +struct file; +struct ucred; + +typedef int fo_rdwr_t(struct file *fp, struct uio *uio, + struct ucred *active_cred, int flags, + struct thread *td); +#define FOF_OFFSET 1 /* Use the offset in uio argument */ +typedef int fo_ioctl_t(struct file *fp, u_long com, void *data, + struct ucred *active_cred, struct thread *td); +typedef int fo_poll_t(struct file *fp, int events, + struct ucred *active_cred, struct thread *td); +typedef int fo_kqfilter_t(struct file *fp, struct knote *kn); +typedef int fo_stat_t(struct file *fp, struct stat *sb, + struct ucred *active_cred, struct thread *td); +typedef int fo_close_t(struct file *fp, struct thread *td); +typedef int fo_flags_t; + +struct fileops { + fo_rdwr_t *fo_read; + fo_rdwr_t *fo_write; + fo_ioctl_t *fo_ioctl; + fo_poll_t *fo_poll; + fo_kqfilter_t *fo_kqfilter; + fo_stat_t *fo_stat; + fo_close_t *fo_close; + fo_flags_t fo_flags; /* DFLAG_* below */ +}; + +#define DFLAG_PASSABLE 0x01 /* may be passed via unix sockets. */ +#define DFLAG_SEEKABLE 0x02 /* seekable / nonsequential */ + +/* + * Kernel descriptor table. + * One entry for each open kernel vnode and socket. + * + * Below is the list of locks that protects members in struct file. + * + * (fl) filelist_lock + * (f) f_mtx in struct file + * none not locked + */ + +struct file { + LIST_ENTRY(file) f_list;/* (fl) list of active files */ + short f_type; /* descriptor type */ + void *f_data; /* file descriptor specific data */ + u_int f_flag; /* see fcntl.h */ + struct mtx *f_mtxp; /* mutex to protect data */ + struct fileops *f_ops; /* File operations */ + struct ucred *f_cred; /* credentials associated with descriptor */ + int f_count; /* (f) reference count */ + struct vnode *f_vnode; /* NULL or applicable vnode */ + + /* DFLAG_SEEKABLE specific fields */ + off_t f_offset; + + /* DTYPE_SOCKET specific fields */ + short f_gcflag; /* used by thread doing fd garbage collection */ +#define FMARK 0x1 /* mark during gc() */ +#define FDEFER 0x2 /* defer for next gc pass */ + int f_msgcount; /* (f) references from message queue */ + + /* DTYPE_VNODE specific fields */ + int f_seqcount; /* + * count of sequential accesses -- cleared + * by most seek operations. + */ + off_t f_nextoff; /* + * offset of next expected read or write + */ +}; + +#endif /* _KERNEL */ + +/* + * Userland version of struct file, for sysctl + */ +struct xfile { + size_t xf_size; /* size of struct xfile */ + pid_t xf_pid; /* owning process */ + uid_t xf_uid; /* effective uid of owning process */ + int xf_fd; /* descriptor number */ + void *xf_file; /* address of struct file */ + short xf_type; /* descriptor type */ + int xf_count; /* reference count */ + int xf_msgcount; /* references from message queue */ + off_t xf_offset; /* file offset */ + void *xf_data; /* file descriptor specific data */ + u_int xf_flag; /* flags (see fcntl.h) */ +}; + +#ifdef _KERNEL + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_FILE); +#endif + +LIST_HEAD(filelist, file); +extern struct filelist filehead; /* (fl) head of list of open files */ +extern struct fileops vnops; +extern struct fileops badfileops; +extern struct fileops socketops; +extern int maxfiles; /* kernel limit on number of open files */ +extern int maxfilesperproc; /* per process limit on number of open files */ +extern int nfiles; /* (fl) actual number of open files */ +extern struct sx filelist_lock; /* sx to protect filelist and nfiles */ + +int fget(struct thread *td, int fd, struct file **fpp); +int fget_read(struct thread *td, int fd, struct file **fpp); +int fget_write(struct thread *td, int fd, struct file **fpp); +int fdrop(struct file *fp, struct thread *td); +int fdrop_locked(struct file *fp, struct thread *td); + +/* + * The socket operations are used a couple of places. + * XXX: This is wrong, they should go through the operations vector for + * XXX: sockets instead of going directly for the individual functions. /phk + */ +fo_rdwr_t soo_read; +fo_rdwr_t soo_write; +fo_ioctl_t soo_ioctl; +fo_poll_t soo_poll; +fo_kqfilter_t soo_kqfilter; +fo_stat_t soo_stat; +fo_close_t soo_close; + +/* Lock a file. */ +#define FILE_LOCK(f) mtx_lock((f)->f_mtxp) +#define FILE_UNLOCK(f) mtx_unlock((f)->f_mtxp) +#define FILE_LOCKED(f) mtx_owned((f)->f_mtxp) +#define FILE_LOCK_ASSERT(f, type) mtx_assert((f)->f_mtxp, (type)) + +int fgetvp(struct thread *td, int fd, struct vnode **vpp); +int fgetvp_read(struct thread *td, int fd, struct vnode **vpp); +int fgetvp_write(struct thread *td, int fd, struct vnode **vpp); + +int fgetsock(struct thread *td, int fd, struct socket **spp, u_int *fflagp); +void fputsock(struct socket *sp); + +#define fhold_locked(fp) \ + do { \ + FILE_LOCK_ASSERT(fp, MA_OWNED); \ + (fp)->f_count++; \ + } while (0) + +#define fhold(fp) \ + do { \ + FILE_LOCK(fp); \ + fhold_locked(fp); \ + FILE_UNLOCK(fp); \ + } while (0) + +static __inline fo_rdwr_t fo_read; +static __inline fo_rdwr_t fo_write; +static __inline fo_ioctl_t fo_ioctl; +static __inline fo_poll_t fo_poll; +static __inline fo_kqfilter_t fo_kqfilter; +static __inline fo_stat_t fo_stat; +static __inline fo_close_t fo_close; + +static __inline int +fo_read(fp, uio, active_cred, flags, td) + struct file *fp; + struct uio *uio; + struct ucred *active_cred; + int flags; + struct thread *td; +{ + + return ((*fp->f_ops->fo_read)(fp, uio, active_cred, flags, td)); +} + +static __inline int +fo_write(fp, uio, active_cred, flags, td) + struct file *fp; + struct uio *uio; + struct ucred *active_cred; + int flags; + struct thread *td; +{ + + return ((*fp->f_ops->fo_write)(fp, uio, active_cred, flags, td)); +} + +static __inline int +fo_ioctl(fp, com, data, active_cred, td) + struct file *fp; + u_long com; + void *data; + struct ucred *active_cred; + struct thread *td; +{ + + return ((*fp->f_ops->fo_ioctl)(fp, com, data, active_cred, td)); +} + +static __inline int +fo_poll(fp, events, active_cred, td) + struct file *fp; + int events; + struct ucred *active_cred; + struct thread *td; +{ + + return ((*fp->f_ops->fo_poll)(fp, events, active_cred, td)); +} + +static __inline int +fo_stat(fp, sb, active_cred, td) + struct file *fp; + struct stat *sb; + struct ucred *active_cred; + struct thread *td; +{ + + return ((*fp->f_ops->fo_stat)(fp, sb, active_cred, td)); +} + +static __inline int +fo_close(fp, td) + struct file *fp; + struct thread *td; +{ + + return ((*fp->f_ops->fo_close)(fp, td)); +} + +static __inline int +fo_kqfilter(fp, kn) + struct file *fp; + struct knote *kn; +{ + + return ((*fp->f_ops->fo_kqfilter)(fp, kn)); +} + +#endif /* _KERNEL */ + +#endif /* !SYS_FILE_H */ diff --git a/src/include/sys/filedesc.h b/src/include/sys/filedesc.h new file mode 100644 index 0000000..0cea793 --- /dev/null +++ b/src/include/sys/filedesc.h @@ -0,0 +1,170 @@ +/* + * 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. + * 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. + * + * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/filedesc.h,v 1.60 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_FILEDESC_H_ +#define _SYS_FILEDESC_H_ + +#include +#include +#include + +#include + +/* + * This structure is used for the management of descriptors. It may be + * shared by multiple processes. + * + * A process is initially started out with NDFILE descriptors stored within + * this structure, selected to be enough for typical applications based on + * the historical limit of 20 open files (and the usage of descriptors by + * shells). If these descriptors are exhausted, a larger descriptor table + * may be allocated, up to a process' resource limit; the internal arrays + * are then unused. + */ +#define NDFILE 20 +#define NDSLOTTYPE u_long +#define NDSLOTSIZE sizeof(NDSLOTTYPE) +#define NDENTRIES (NDSLOTSIZE * __CHAR_BIT) +#define NDSLOT(x) ((x) / NDENTRIES) +#define NDBIT(x) ((NDSLOTTYPE)1 << ((x) % NDENTRIES)) +#define NDSLOTS(x) (((x) + NDENTRIES - 1) / NDENTRIES) + +struct filedesc { + struct file **fd_ofiles; /* file structures for open files */ + char *fd_ofileflags; /* per-process open file flags */ + struct vnode *fd_cdir; /* current directory */ + struct vnode *fd_rdir; /* root directory */ + struct vnode *fd_jdir; /* jail root directory */ + int fd_nfiles; /* number of open files allocated */ + NDSLOTTYPE *fd_map; /* bitmap of free fds */ + int fd_lastfile; /* high-water mark of fd_ofiles */ + int fd_freefile; /* approx. next free file */ + u_short fd_cmask; /* mask for file creation */ + u_short fd_refcnt; /* reference count */ + + int fd_knlistsize; /* size of knlist */ + struct klist *fd_knlist; /* list of attached knotes */ + u_long fd_knhashmask; /* size of knhash */ + struct klist *fd_knhash; /* hash table for attached knotes */ + struct mtx fd_mtx; /* protects members of this struct */ + int fd_holdleaderscount; /* block fdfree() for shared close() */ + int fd_holdleaderswakeup; /* fdfree() needs wakeup */ +}; + +/* + * Basic allocation of descriptors: + * one of the above, plus arrays for NDFILE descriptors. + */ +struct filedesc0 { + struct filedesc fd_fd; + /* + * These arrays are used when the number of open files is + * <= NDFILE, and are then pointed to by the pointers above. + */ + struct file *fd_dfiles[NDFILE]; + char fd_dfileflags[NDFILE]; + NDSLOTTYPE fd_dmap[NDSLOTS(NDFILE)]; +}; + +/* + * Structure to keep track of (process leader, struct fildedesc) tuples. + * Each process has a pointer to such a structure when detailed tracking + * is needed, e.g., when rfork(RFPROC | RFMEM) causes a file descriptor + * table to be shared by processes having different "p_leader" pointers + * and thus distinct POSIX style locks. + * + * fdl_refcount and fdl_holdcount are protected by struct filedesc mtx. + */ +struct filedesc_to_leader { + int fdl_refcount; /* references from struct proc */ + int fdl_holdcount; /* temporary hold during closef */ + int fdl_wakeup; /* fdfree() waits on closef() */ + struct proc *fdl_leader; /* owner of POSIX locks */ + /* Circular list: */ + struct filedesc_to_leader *fdl_prev; + struct filedesc_to_leader *fdl_next; +}; + +/* + * Per-process open flags. + */ +#define UF_EXCLOSE 0x01 /* auto-close on exec */ + +/* + * Storage required per open file descriptor. + */ +#define OFILESIZE (sizeof(struct file *) + sizeof(char)) + +#ifdef _KERNEL + +/* Lock a file descriptor table. */ +#define FILEDESC_LOCK(fd) mtx_lock(&(fd)->fd_mtx) +#define FILEDESC_UNLOCK(fd) mtx_unlock(&(fd)->fd_mtx) +#define FILEDESC_LOCKED(fd) mtx_owned(&(fd)->fd_mtx) +#define FILEDESC_LOCK_ASSERT(fd, type) mtx_assert(&(fd)->fd_mtx, (type)) +#define FILEDESC_LOCK_DESC "filedesc structure" + +struct thread; + +int closef(struct file *fp, struct thread *td); +int dupfdopen(struct thread *td, struct filedesc *fdp, int indx, int dfd, + int mode, int error); +int falloc(struct thread *td, struct file **resultfp, int *resultfd); +int fdalloc(struct thread *td, int minfd, int *result); +int fdavail(struct thread *td, int n); +int fdcheckstd(struct thread *td); +void fdcloseexec(struct thread *td); +struct filedesc *fdcopy(struct filedesc *fdp); +void fdfree(struct thread *td); +struct filedesc *fdinit(struct filedesc *fdp); +struct filedesc *fdshare(struct filedesc *fdp); +void fdunused(struct filedesc *fdp, int fd); +void fdused(struct filedesc *fdp, int fd); +void ffree(struct file *fp); +struct filedesc_to_leader * + filedesc_to_leader_alloc(struct filedesc_to_leader *old, + struct filedesc *fdp, struct proc *leader); +int getvnode(struct filedesc *fdp, int fd, struct file **fpp); +void setugidsafety(struct thread *td); + +static __inline struct file * +fget_locked(struct filedesc *fdp, int fd) +{ + + return (fd < 0 || fd >= fdp->fd_nfiles ? NULL : fdp->fd_ofiles[fd]); +} + +extern struct mtx fdesc_mtx; + +#endif /* _KERNEL */ + +#endif /* !_SYS_FILEDESC_H_ */ diff --git a/src/include/sys/filio.h b/src/include/sys/filio.h new file mode 100644 index 0000000..7bf13b9 --- /dev/null +++ b/src/include/sys/filio.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)filio.h 8.1 (Berkeley) 3/28/94 + * $FreeBSD: src/sys/sys/filio.h,v 1.8 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_FILIO_H_ +#define _SYS_FILIO_H_ + +#include + +/* Generic file-descriptor ioctl's. */ +#define FIOCLEX _IO('f', 1) /* set close on exec on fd */ +#define FIONCLEX _IO('f', 2) /* remove close on exec */ +#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ +#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ +#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */ +#define FIOSETOWN _IOW('f', 124, int) /* set owner */ +#define FIOGETOWN _IOR('f', 123, int) /* get owner */ +#define FIODTYPE _IOR('f', 122, int) /* get d_flags type part */ +#define FIOGETLBA _IOR('f', 121, int) /* get start blk # */ + +#endif /* !_SYS_FILIO_H_ */ diff --git a/src/include/sys/fnv_hash.h b/src/include/sys/fnv_hash.h new file mode 100644 index 0000000..256af02 --- /dev/null +++ b/src/include/sys/fnv_hash.h @@ -0,0 +1,68 @@ +/* + * Fowler / Noll / Vo Hash (FNV Hash) + * http://www.isthe.com/chongo/tech/comp/fnv/ + * + * This is an implementation of the algorithms posted above. + * This file is placed in the public domain by Peter Wemm. + * + * $FreeBSD: src/sys/sys/fnv_hash.h,v 1.2 2001/03/20 02:10:18 peter Exp $ + */ + +typedef u_int32_t Fnv32_t; +typedef u_int64_t Fnv64_t; + +#define FNV1_32_INIT ((Fnv32_t) 33554467UL) +#define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL) + +#define FNV_32_PRIME ((Fnv32_t) 0x01000193UL) +#define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL) + +static __inline Fnv32_t +fnv_32_buf(const void *buf, size_t len, Fnv32_t hval) +{ + const u_int8_t *s = (const u_int8_t *)buf; + + while (len-- != 0) { + hval *= FNV_32_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline Fnv32_t +fnv_32_str(const char *str, Fnv32_t hval) +{ + const u_int8_t *s = (const u_int8_t *)str; + Fnv32_t c; + + while ((c = *s++) != 0) { + hval *= FNV_32_PRIME; + hval ^= c; + } + return hval; +} + +static __inline Fnv64_t +fnv_64_buf(const void *buf, size_t len, Fnv64_t hval) +{ + const u_int8_t *s = (const u_int8_t *)buf; + + while (len-- != 0) { + hval *= FNV_64_PRIME; + hval ^= *s++; + } + return hval; +} + +static __inline Fnv64_t +fnv_64_str(const char *str, Fnv64_t hval) +{ + const u_int8_t *s = (const u_int8_t *)str; + u_register_t c; /* 32 bit on i386, 64 bit on alpha,ia64 */ + + while ((c = *s++) != 0) { + hval *= FNV_64_PRIME; + hval ^= c; + } + return hval; +} diff --git a/src/include/sys/gmon.h b/src/include/sys/gmon.h new file mode 100644 index 0000000..5a347cd --- /dev/null +++ b/src/include/sys/gmon.h @@ -0,0 +1,201 @@ +/*- + * Copyright (c) 1982, 1986, 1992, 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. + * 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. + * + * @(#)gmon.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/sys/gmon.h,v 1.17 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_GMON_H_ +#define _SYS_GMON_H_ + +#include + +/* + * Structure prepended to gmon.out profiling data file. + */ +struct gmonhdr { + u_long lpc; /* base pc address of sample buffer */ + u_long hpc; /* max pc address of sampled buffer */ + int ncnt; /* size of sample buffer (plus this header) */ + int version; /* version number */ + int profrate; /* profiling clock rate */ + int histcounter_type; /* size (in bits) and sign of HISTCOUNTER */ + int spare[2]; /* reserved */ +}; +#define GMONVERSION 0x00051879 + +/* + * Type of histogram counters used in the kernel. + */ +#ifdef GPROF4 +#define HISTCOUNTER int64_t +#else +#define HISTCOUNTER unsigned short +#endif + +/* + * Fraction of text space to allocate for histogram counters. + * We allocate counters at the same or higher density as function + * addresses, so that each counter belongs to a unique function. + * A lower density of counters would give less resolution but a + * higher density would be wasted. + */ +#define HISTFRACTION (FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER) == 0 \ + ? 1 : FUNCTION_ALIGNMENT / sizeof(HISTCOUNTER)) + +/* + * Fraction of text space to allocate for from hash buckets. + * The value of HASHFRACTION is based on the minimum number of bytes + * of separation between two subroutine call points in the object code. + * Given MIN_SUBR_SEPARATION bytes of separation the value of + * HASHFRACTION is calculated as: + * + * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1); + * + * For example, on the VAX, the shortest two call sequence is: + * + * calls $0,(r0) + * calls $0,(r0) + * + * which is separated by only three bytes, thus HASHFRACTION is + * calculated as: + * + * HASHFRACTION = 3 / (2 * 2 - 1) = 1 + * + * Note that the division above rounds down, thus if MIN_SUBR_FRACTION + * is less than three, this algorithm will not work! + * + * In practice, however, call instructions are rarely at a minimal + * distance. Hence, we will define HASHFRACTION to be 2 across all + * architectures. This saves a reasonable amount of space for + * profiling data structures without (in practice) sacrificing + * any granularity. + */ +/* + * XXX I think the above analysis completely misses the point. I think + * the point is that addresses in different functions must hash to + * different values. Since the hash is essentially division by + * sizeof(unsigned short), the correct formula is: + * + * HASHFRACTION = MIN_FUNCTION_ALIGNMENT / sizeof(unsigned short) + * + * Note that he unsigned short here has nothing to do with the one for + * HISTFRACTION. + * + * Hash collisions from a two call sequence don't matter. They get + * handled like collisions for calls to different addresses from the + * same address through a function pointer. + */ +#define HASHFRACTION (FUNCTION_ALIGNMENT / sizeof(unsigned short) == 0 \ + ? 1 : FUNCTION_ALIGNMENT / sizeof(unsigned short)) + +/* + * percent of text space to allocate for tostructs with a minimum. + */ +#define ARCDENSITY 2 +#define MINARCS 50 + +/* + * Limit on the number of arcs to so that arc numbers can be stored in + * `*froms' and stored and incremented without overflow in links. + */ +#define MAXARCS (((u_long)1 << (8 * sizeof(u_short))) - 2) + +struct tostruct { + u_long selfpc; + long count; + u_short link; + u_short pad; +}; + +/* + * a raw arc, with pointers to the calling site and + * the called site and a count. + */ +struct rawarc { + u_long raw_frompc; + u_long raw_selfpc; + long raw_count; +}; + +/* + * general rounding functions. + */ +#define ROUNDDOWN(x,y) rounddown(x,y) +#define ROUNDUP(x,y) roundup(x,y) + +/* + * The profiling data structures are housed in this structure. + */ +struct gmonparam { + int state; + HISTCOUNTER *kcount; + u_long kcountsize; + u_short *froms; + u_long fromssize; + struct tostruct *tos; + u_long tossize; + long tolimit; + uintfptr_t lowpc; + uintfptr_t highpc; + u_long textsize; + u_long hashfraction; + int profrate; /* XXX wrong type to match gmonhdr */ + HISTCOUNTER *cputime_count; + int cputime_overhead; + HISTCOUNTER *mcount_count; + int mcount_overhead; + int mcount_post_overhead; + int mcount_pre_overhead; + HISTCOUNTER *mexitcount_count; + int mexitcount_overhead; + int mexitcount_post_overhead; + int mexitcount_pre_overhead; + int histcounter_type; +}; +extern struct gmonparam _gmonparam; + +/* + * Possible states of profiling. + */ +#define GMON_PROF_ON 0 +#define GMON_PROF_BUSY 1 +#define GMON_PROF_ERROR 2 +#define GMON_PROF_OFF 3 +#define GMON_PROF_HIRES 4 + +/* + * Sysctl definitions for extracting profiling information from the kernel. + */ +#define GPROF_STATE 0 /* int: profiling enabling variable */ +#define GPROF_COUNT 1 /* struct: profile tick count buffer */ +#define GPROF_FROMS 2 /* struct: from location hash bucket */ +#define GPROF_TOS 3 /* struct: destination/count structure */ +#define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */ + +#endif /* !_SYS_GMON_H_ */ diff --git a/src/include/sys/gpt.h b/src/include/sys/gpt.h new file mode 100644 index 0000000..ef8ed41 --- /dev/null +++ b/src/include/sys/gpt.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2002 Marcel Moolenaar + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/gpt.h,v 1.6 2002/11/10 20:13:58 marcel Exp $ + */ + +#ifndef _SYS_GPT_H_ +#define _SYS_GPT_H_ + +#include + +struct gpt_hdr { + char hdr_sig[8]; +#define GPT_HDR_SIG "EFI PART" + uint32_t hdr_revision; +#define GPT_HDR_REVISION 0x00010000 + uint32_t hdr_size; + uint32_t hdr_crc_self; + uint32_t __reserved; + uint64_t hdr_lba_self; + uint64_t hdr_lba_alt; + uint64_t hdr_lba_start; + uint64_t hdr_lba_end; + struct uuid hdr_uuid; + uint64_t hdr_lba_table; + uint32_t hdr_entries; + uint32_t hdr_entsz; + uint32_t hdr_crc_table; + /* + * The header as defined in the EFI spec is not a multiple of 8 bytes + * and given that the alignment requirement is on an 8 byte boundary, + * padding will happen. We make the padding explicit so that we can + * correct the value returned by sizeof() when we put the size of the + * header in field hdr_size, or otherwise use offsetof(). + */ + uint32_t padding; +}; + +struct gpt_ent { + struct uuid ent_type; + struct uuid ent_uuid; + uint64_t ent_lba_start; + uint64_t ent_lba_end; + uint64_t ent_attr; +#define GPT_ENT_ATTR_PLATFORM (1ULL << 0) + short ent_name[36]; /* UNICODE-16. */ +}; + +#define GPT_ENT_TYPE_UNUSED \ + {0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}} +#define GPT_ENT_TYPE_EFI \ + {0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}} +#define GPT_ENT_TYPE_MBR \ + {0x024dee41,0x33e7,0x11d3,0x9d,0x69,{0x00,0x08,0xc7,0x81,0xf3,0x9f}} +#define GPT_ENT_TYPE_FREEBSD \ + {0x516e7cb4,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_SWAP \ + {0x516e7cb5,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_UFS \ + {0x516e7cb6,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_UFS2 \ + {0x516e7cb7,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} +#define GPT_ENT_TYPE_FREEBSD_VINUM \ + {0x516e7cb8,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}} + +/* + * Foreign partition types that we're likely to encounter. Note that Linux + * apparently choose to share data partitions with MS. I don't what the + * advantage might be. I can see how sharing swap partitions is advantaous + * though. + */ +#define GPT_ENT_TYPE_MS_RESERVED \ + {0xe3c9e316,0x0b5c,0x4db8,0x81,0x7d,{0xf9,0x2d,0xf0,0x02,0x15,0xae}} +#define GPT_ENT_TYPE_MS_BASIC_DATA \ + {0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}} +#define GPT_ENT_TYPE_MS_LDM_METADATA \ + {0x5808c8aa,0x7e8f,0x42e0,0x85,0xd2,{0xe1,0xe9,0x04,0x34,0xcf,0xb3}} +#define GPT_ENT_TYPE_MS_LDM_DATA \ + {0xaf9b60a0,0x1431,0x4f62,0xbc,0x68,{0x33,0x11,0x71,0x4a,0x69,0xad}} + +#define GPT_ENT_TYPE_LINUX_DATA GPT_ENT_TYPE_MS_BASIC_DATA +#define GPT_ENT_TYPE_LINUX_RAID \ + {0xa19d880f,0x05fc,0x4d3b,0xa0,0x06,{0x74,0x3f,0x0f,0x84,0x91,0x1e}} +#define GPT_ENT_TYPE_LINUX_SWAP \ + {0x0657fd6d,0xa4ab,0x43c4,0x84,0xe5,{0x09,0x33,0xc8,0x4b,0x4f,0x4f}} +#define GPT_ENT_TYPE_LINUX_LVM \ + {0xe6d6d379,0xf507,0x44c2,0xa2,0x3c,{0x23,0x8f,0x2a,0x3d,0xf9,0x28}} + +#endif /* _SYS_GPT_H_ */ diff --git a/src/include/sys/iconv.h b/src/include/sys/iconv.h new file mode 100644 index 0000000..149ebf4 --- /dev/null +++ b/src/include/sys/iconv.h @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2000-2001, Boris Popov + * 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 Boris Popov. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/iconv.h,v 1.8 2003/12/08 08:32:20 fjoe Exp $ + */ +#ifndef _SYS_ICONV_H_ +#define _SYS_ICONV_H_ + +#define ICONV_CSNMAXLEN 31 /* maximum length of charset name */ +#define ICONV_CNVNMAXLEN 31 /* maximum length of converter name */ +#define ICONV_CSMAXDATALEN (2048+262144) /* maximum size of data associated with cs pair */ + +#define XLAT16_ACCEPT_NULL_OUT 0x01000000 +#define XLAT16_ACCEPT_NULL_IN 0x02000000 +#define XLAT16_HAS_LOWER_CASE 0x04000000 +#define XLAT16_HAS_UPPER_CASE 0x08000000 +#define XLAT16_HAS_FROM_LOWER_CASE 0x10000000 +#define XLAT16_HAS_FROM_UPPER_CASE 0x20000000 +#define XLAT16_IS_3BYTE_CHR 0x40000000 + +#define KICONV_LOWER 1 /* tolower converted character */ +#define KICONV_UPPER 2 /* toupper converted character */ +#define KICONV_FROM_LOWER 4 /* tolower source character, then convert */ +#define KICONV_FROM_UPPER 8 /* toupper source character, then convert */ + +/* + * Entry for cslist sysctl + */ +#define ICONV_CSPAIR_INFO_VER 1 + +struct iconv_cspair_info { + int cs_version; + int cs_id; + int cs_base; + int cs_refcount; + char cs_to[ICONV_CSNMAXLEN]; + char cs_from[ICONV_CSNMAXLEN]; +}; + +/* + * Paramters for 'add' sysctl + */ +#define ICONV_ADD_VER 1 + +struct iconv_add_in { + int ia_version; + char ia_converter[ICONV_CNVNMAXLEN]; + char ia_to[ICONV_CSNMAXLEN]; + char ia_from[ICONV_CSNMAXLEN]; + int ia_datalen; + const void *ia_data; +}; + +struct iconv_add_out { + int ia_csid; +}; + +#ifndef _KERNEL + +__BEGIN_DECLS + +#define ENCODING_UNICODE "ISO-10646-UCS-2" +#define KICONV_VENDOR_MICSFT 1 /* Microsoft Vendor Code for quirk */ + +int kiconv_add_xlat_table(const char *, const char *, const u_char *); +int kiconv_add_xlat16_cspair(const char *, const char *, int); +int kiconv_add_xlat16_cspairs(const char *, const char *); +int kiconv_add_xlat16_table(const char *, const char *, const void *, int); +const char *kiconv_quirkcs(const char *, int); + +__END_DECLS + +#else /* !_KERNEL */ + +#include +#include /* can't avoid that */ +#include /* can't avoid that */ +#include /* can't avoid that */ + +struct iconv_cspair; +struct iconv_cspairdata; + +/* + * iconv converter class definition + */ +struct iconv_converter_class { + KOBJ_CLASS_FIELDS; + TAILQ_ENTRY(iconv_converter_class) cc_link; +}; + +struct iconv_cspair { + int cp_id; /* unique id of charset pair */ + int cp_refcount; /* number of references from other pairs */ + const char * cp_from; + const char * cp_to; + void * cp_data; + struct iconv_converter_class * cp_dcp; + struct iconv_cspair *cp_base; + TAILQ_ENTRY(iconv_cspair) cp_link; +}; + +#define KICONV_CONVERTER(name,size) \ + static DEFINE_CLASS(iconv_ ## name, iconv_ ## name ## _methods, (size)); \ + static moduledata_t iconv_ ## name ## _mod = { \ + "iconv_"#name, iconv_converter_handler, \ + (void*)&iconv_ ## name ## _class \ + }; \ + DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY); + +#define KICONV_CES(name,size) \ + static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \ + static moduledata_t iconv_ces_ ## name ## _mod = { \ + "iconv_ces_"#name, iconv_cesmod_handler, \ + (void*)&iconv_ces_ ## name ## _class \ + }; \ + DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY); + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_ICONV); +#endif + +/* + * Basic conversion functions + */ +int iconv_open(const char *to, const char *from, void **handle); +int iconv_close(void *handle); +int iconv_conv(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +int iconv_conv_case(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype); +int iconv_convchr(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +int iconv_convchr_case(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int casetype); +char* iconv_convstr(void *handle, char *dst, const char *src); +void* iconv_convmem(void *handle, void *dst, const void *src, int size); +int iconv_vfs_refcount(const char *fsname); + +/* + * Bridge struct of iconv functions + */ +struct iconv_functions { + int (*open)(const char *to, const char *from, void **handle); + int (*close)(void *handle); + int (*conv)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + int (*conv_case)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, int casetype); + int (*convchr)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + int (*convchr_case)(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, int casetype); +}; + +#define VFS_DECLARE_ICONV(fsname) \ + static struct iconv_functions fsname ## _iconv_core = { \ + iconv_open, \ + iconv_close, \ + iconv_conv, \ + iconv_conv_case, \ + iconv_convchr, \ + iconv_convchr_case \ + }; \ + extern struct iconv_functions *fsname ## _iconv; \ + static int fsname ## _iconv_mod_handler(module_t mod, \ + int type, void *d); \ + static int \ + fsname ## _iconv_mod_handler(module_t mod, int type, void *d) \ + { \ + int error = 0; \ + switch(type) { \ + case MOD_LOAD: \ + fsname ## _iconv = & fsname ## _iconv_core; \ + break; \ + case MOD_UNLOAD: \ + error = iconv_vfs_refcount(#fsname); \ + if (error) \ + return (EBUSY); \ + fsname ## _iconv = NULL; \ + break; \ + default: \ + error = EINVAL; \ + break; \ + } \ + return (error); \ + } \ + static moduledata_t fsname ## _iconv_mod = { \ + #fsname"_iconv", \ + fsname ## _iconv_mod_handler, \ + NULL \ + }; \ + DECLARE_MODULE(fsname ## _iconv, fsname ## _iconv_mod, \ + SI_SUB_DRIVERS, SI_ORDER_ANY); \ + MODULE_DEPEND(fsname ## _iconv, fsname, 1, 1, 1); \ + MODULE_DEPEND(fsname ## _iconv, libiconv, 2, 2, 2); \ + MODULE_VERSION(fsname ## _iconv, 1) + +/* + * Internal functions + */ +int iconv_lookupcp(char **cpp, const char *s); + +int iconv_converter_initstub(struct iconv_converter_class *dp); +int iconv_converter_donestub(struct iconv_converter_class *dp); +int iconv_converter_handler(module_t mod, int type, void *data); + +#ifdef ICONV_DEBUG +#define ICDEBUG(format, ...) printf("%s: "format, __func__ , __VA_ARGS__) +#else +#define ICDEBUG(format, ...) +#endif + +#endif /* !_KERNEL */ + +#endif /* !_SYS_ICONV_H_ */ diff --git a/src/include/sys/imgact.h b/src/include/sys/imgact.h new file mode 100644 index 0000000..668a5e4 --- /dev/null +++ b/src/include/sys/imgact.h @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 1993, David Greenman + * 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. + * 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/imgact.h,v 1.36 2004/04/24 06:44:33 bde Exp $ + */ + +#ifndef _SYS_IMGACT_H_ +#define _SYS_IMGACT_H_ + +#define MAXSHELLCMDLEN 128 + +struct image_params { + struct proc *proc; /* our process struct */ + char **userspace_argv; /* system call argument */ + char **userspace_envv; /* system call argument */ + struct label *execlabel; /* optional exec label */ + struct vnode *vp; /* pointer to vnode of file to exec */ + struct vm_object *object; /* The vm object for this vp */ + struct vattr *attr; /* attributes of file */ + const char *image_header; /* head of file to exec */ + char *stringbase; /* base address of tmp string storage */ + char *stringp; /* current 'end' pointer of tmp strings */ + char *endargs; /* end of argv vector */ + int stringspace; /* space left in tmp string storage area */ + int argc, envc; /* count of argument and environment strings */ + char *argv0; /* Replacement for argv[0] when interpreting */ + unsigned long entry_addr; /* entry address of target executable */ + char vmspace_destroyed; /* flag - we've blown away original vm space */ + char interpreted; /* flag - this executable is interpreted */ + char interpreter_name[MAXSHELLCMDLEN]; /* name of the interpreter */ + void *auxargs; /* ELF Auxinfo structure pointer */ + struct sf_buf *firstpage; /* first page that we mapped */ + char *fname; /* pointer to filename of executable (user space) */ + unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */ + size_t auxarg_size; +}; + +#ifdef _KERNEL +struct sysentvec; +struct thread; + +int exec_check_permissions(struct image_params *); +register_t *exec_copyout_strings(struct image_params *); +int exec_extract_strings(struct image_params *); +int exec_new_vmspace(struct image_params *, struct sysentvec *); +void exec_setregs(struct thread *, u_long, u_long, u_long); +int exec_shell_imgact(struct image_params *); +#endif + +#endif /* !_SYS_IMGACT_H_ */ diff --git a/src/include/sys/imgact_aout.h b/src/include/sys/imgact_aout.h new file mode 100644 index 0000000..b433dfd --- /dev/null +++ b/src/include/sys/imgact_aout.h @@ -0,0 +1,154 @@ +/*- + * Copyright (c) 1992, 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. + * 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. + * + * from: @(#)exec.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD: src/sys/sys/imgact_aout.h,v 1.20 2004/05/04 22:49:47 cognet Exp $ + */ + +#ifndef _IMGACT_AOUT_H_ +#define _IMGACT_AOUT_H_ + +#define N_GETMAGIC(ex) \ + ( (ex).a_midmag & 0xffff ) +#define N_GETMID(ex) \ + ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \ + ((ex).a_midmag >> 16) & 0x03ff ) +#define N_GETFLAG(ex) \ + ( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \ + ((ex).a_midmag >> 26) & 0x3f ) +#define N_SETMAGIC(ex,mag,mid,flag) \ + ( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \ + ((mag) & 0xffff) ) + +#define N_GETMAGIC_NET(ex) \ + (ntohl((ex).a_midmag) & 0xffff) +#define N_GETMID_NET(ex) \ + ((ntohl((ex).a_midmag) >> 16) & 0x03ff) +#define N_GETFLAG_NET(ex) \ + ((ntohl((ex).a_midmag) >> 26) & 0x3f) +#define N_SETMAGIC_NET(ex,mag,mid,flag) \ + ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) \ + | (((mag)&0xffff)) ) ) + +#define N_ALIGN(ex,x) \ + (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \ + N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \ + ((x) + __LDPGSZ - 1) & ~(unsigned long)(__LDPGSZ - 1) : (x)) + +/* Valid magic number check. */ +#define N_BADMAG(ex) \ + (N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \ + N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \ + N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \ + N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC) + + +/* Address of the bottom of the text segment. */ +/* + * This can not be done right. Abuse a_entry in some cases to handle kernels. + */ +#define N_TXTADDR(ex) \ + ((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \ + N_GETMAGIC(ex) == ZMAGIC) ? \ + ((ex).a_entry < (ex).a_text ? 0 : (ex).a_entry & ~__LDPGSZ) : __LDPGSZ) + +/* Address of the bottom of the data segment. */ +#define N_DATADDR(ex) \ + N_ALIGN(ex, N_TXTADDR(ex) + (ex).a_text) + +/* Text segment offset. */ +#define N_TXTOFF(ex) \ + (N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \ + N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec)) + +/* Data segment offset. */ +#define N_DATOFF(ex) \ + N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text) + +/* Relocation table offset. */ +#define N_RELOFF(ex) \ + N_ALIGN(ex, N_DATOFF(ex) + (ex).a_data) + +/* Symbol table offset. */ +#define N_SYMOFF(ex) \ + (N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize) + +/* String table offset. */ +#define N_STROFF(ex) (N_SYMOFF(ex) + (ex).a_syms) + +/* + * Header prepended to each a.out file. + * only manipulate the a_midmag field via the + * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros in a.out.h + */ + +struct exec { + unsigned long a_midmag; /* flags<<26 | mid<<16 | magic */ + unsigned long a_text; /* text segment size */ + unsigned long a_data; /* initialized data size */ + unsigned long a_bss; /* uninitialized data size */ + unsigned long a_syms; /* symbol table size */ + unsigned long a_entry; /* entry point */ + unsigned long a_trsize; /* text relocation size */ + unsigned long a_drsize; /* data relocation size */ +}; +#define a_magic a_midmag /* XXX Hack to work with current kern_execve.c */ + +/* a_magic */ +#define OMAGIC 0407 /* old impure format */ +#define NMAGIC 0410 /* read-only text */ +#define ZMAGIC 0413 /* demand load format */ +#define QMAGIC 0314 /* "compact" demand load format */ + +/* a_mid */ +#define MID_ZERO 0 /* unknown - implementation dependent */ +#define MID_SUN010 1 /* sun 68010/68020 binary */ +#define MID_SUN020 2 /* sun 68020-only binary */ +#define MID_I386 134 /* i386 BSD binary */ +#define MID_SPARC 138 /* sparc */ +#define MID_ARM6 143 /* ARM6 */ +#define MID_HP200 200 /* hp200 (68010) BSD binary */ +#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ +#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ +#define MID_HPUX800 0x20B /* hp800 HP-UX binary */ + +/* + * a_flags + */ +#define EX_PIC 0x10 /* contains position independent code */ +#define EX_DYNAMIC 0x20 /* contains run-time link-edit info */ +#define EX_DPMASK 0x30 /* mask for the above */ + +#ifdef _KERNEL +struct thread; +struct vnode; + +int aout_coredump(struct thread *td, struct vnode *vp, off_t limit); +#endif + +#endif /* !_IMGACT_AOUT_H_ */ diff --git a/src/include/sys/imgact_elf.h b/src/include/sys/imgact_elf.h new file mode 100644 index 0000000..c698458 --- /dev/null +++ b/src/include/sys/imgact_elf.h @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 1995-1996 S�ren Schmidt + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/imgact_elf.h,v 1.26 2003/12/23 02:42:38 peter Exp $ + */ + +#ifndef _SYS_IMGACT_ELF_H_ +#define _SYS_IMGACT_ELF_H_ + +#include + +#ifdef _KERNEL + +#define AUXARGS_ENTRY(pos, id, val) {suword(pos++, id); suword(pos++, val);} + +struct thread; + +/* + * Structure used to pass infomation from the loader to the + * stack fixup routine. + */ +typedef struct { + Elf_Sword execfd; + Elf_Word phdr; + Elf_Word phent; + Elf_Word phnum; + Elf_Word pagesz; + Elf_Word base; + Elf_Word flags; + Elf_Word entry; + Elf_Word trace; +} __ElfN(Auxargs); + +typedef struct { + int brand; + int machine; + const char *compat_3_brand; /* pre Binutils 2.10 method (FBSD 3) */ + const char *emul_path; + const char *interp_path; + struct sysentvec *sysvec; + const char *interp_newpath; +} __ElfN(Brandinfo); + +__ElfType(Auxargs); +__ElfType(Brandinfo); + +#define MAX_BRANDS 8 + +int __elfN(brand_inuse)(Elf_Brandinfo *entry); +int __elfN(insert_brand_entry)(Elf_Brandinfo *entry); +int __elfN(remove_brand_entry)(Elf_Brandinfo *entry); +int __elfN(freebsd_fixup)(register_t **, struct image_params *); +int __elfN(coredump)(struct thread *, struct vnode *, off_t); + +extern int __elfN(fallback_brand); + +#endif /* _KERNEL */ + +#endif /* !_SYS_IMGACT_ELF_H_ */ diff --git a/src/include/sys/inflate.h b/src/include/sys/inflate.h new file mode 100644 index 0000000..8c4a578 --- /dev/null +++ b/src/include/sys/inflate.h @@ -0,0 +1,53 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/sys/inflate.h,v 1.13 2002/03/26 08:29:40 phk Exp $ + * + */ +#ifndef _SYS_INFLATE_H_ +#define _SYS_INFLATE_H_ + +#if defined(_KERNEL) || defined(KZIP) + +#define GZ_EOF -1 + +#define GZ_WSIZE 0x8000 + +/* + * Global variables used by inflate and friends. + * This structure is used in order to make inflate() reentrant. + */ +struct inflate { + /* Public part */ + + /* This pointer is passed along to the two functions below */ + void *gz_private; + + /* Fetch next character to be uncompressed */ + int (*gz_input)(void *); + + /* Dispose of uncompressed characters */ + int (*gz_output)(void *, u_char *, u_long); + + /* Private part */ + u_long gz_bb; /* bit buffer */ + unsigned gz_bk; /* bits in bit buffer */ + unsigned gz_hufts; /* track memory usage */ + struct huft *gz_fixed_tl; /* must init to NULL !! */ + struct huft *gz_fixed_td; + int gz_fixed_bl; + int gz_fixed_bd; + u_char *gz_slide; + unsigned gz_wp; +}; + +int inflate(struct inflate *); + +#endif /* _KERNEL || KZIP */ + +#endif /* ! _SYS_INFLATE_H_ */ diff --git a/src/include/sys/interrupt.h b/src/include/sys/interrupt.h new file mode 100644 index 0000000..abdaa91 --- /dev/null +++ b/src/include/sys/interrupt.h @@ -0,0 +1,132 @@ +/* + * Copyright (c) 1997, Stefan Esser + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/interrupt.h,v 1.26 2003/11/17 06:08:10 peter Exp $ + */ + +#ifndef _SYS_INTERRUPT_H_ +#define _SYS_INTERRUPT_H_ + +#include +#include + +/* + * Describe a hardware interrupt handler. + * + * Multiple interrupt handlers for a specific vector can be chained + * together. + */ +struct intrhand { + driver_intr_t *ih_handler; /* Handler function. */ + void *ih_argument; /* Argument to pass to handler. */ + int ih_flags; + const char *ih_name; /* Name of handler. */ + struct ithd *ih_ithread; /* Ithread we are connected to. */ + int ih_need; /* Needs service. */ + TAILQ_ENTRY(intrhand) ih_next; /* Next handler for this vector. */ + u_char ih_pri; /* Priority of this handler. */ +}; + +/* Interrupt handle flags kept in ih_flags */ +#define IH_FAST 0x00000001 /* Fast interrupt. */ +#define IH_EXCLUSIVE 0x00000002 /* Exclusive interrupt. */ +#define IH_ENTROPY 0x00000004 /* Device is a good entropy source. */ +#define IH_DEAD 0x00000008 /* Handler should be removed. */ +#define IH_MPSAFE 0x80000000 /* Handler does not need Giant. */ + +/* + * Describe an interrupt thread. There is one of these per interrupt vector. + * Note that this actually describes an interrupt source. There may or may + * not be an actual kernel thread attached to a given source. + */ +struct ithd { + struct mtx it_lock; + struct thread *it_td; /* Interrupt process. */ + LIST_ENTRY(ithd) it_list; /* All interrupt threads. */ + TAILQ_HEAD(, intrhand) it_handlers; /* Interrupt handlers. */ + struct ithd *it_interrupted; /* Who we interrupted. */ + void (*it_disable)(uintptr_t); /* Enable interrupt source. */ + void (*it_enable)(uintptr_t); /* Disable interrupt source. */ + void *it_md; /* Hook for MD interrupt code. */ + int it_flags; /* Interrupt-specific flags. */ + int it_need; /* Needs service. */ + uintptr_t it_vector; + char it_name[MAXCOMLEN + 1]; +}; + +/* Interrupt thread flags kept in it_flags */ +#define IT_SOFT 0x000001 /* Software interrupt. */ +#define IT_ENTROPY 0x000002 /* Interrupt is an entropy source. */ +#define IT_DEAD 0x000004 /* Thread is waiting to exit. */ + +/* Flags to pass to sched_swi. */ +#define SWI_DELAY 0x2 + +/* + * Software interrupt bit numbers in priority order. The priority only + * determines which swi will be dispatched next; a higher priority swi + * may be dispatched when a nested h/w interrupt handler returns. + */ +#define SWI_TTY 0 +#define SWI_NET 1 +#define SWI_CAMNET 2 +#define SWI_CAMBIO 3 +#define SWI_VM 4 +#define SWI_TQ_FAST 5 +#define SWI_TQ_GIANT 6 +#define SWI_TQ 7 +#define SWI_CLOCK 8 + +extern struct ithd *tty_ithd; +extern struct ithd *clk_ithd; +extern void *net_ih; +extern void *softclock_ih; +extern void *vm_ih; + +/* Counts and names for statistics (defined in MD code). */ +extern u_long eintrcnt[]; /* end of intrcnt[] */ +extern char eintrnames[]; /* end of intrnames[] */ +extern u_long intrcnt[]; /* counts for for each device and stray */ +extern char intrnames[]; /* string table containing device names */ + +#ifdef DDB +void db_dump_ithread(struct ithd *ithd, int handlers); +#endif +int ithread_create(struct ithd **ithread, uintptr_t vector, int flags, + void (*disable)(uintptr_t), void (*enable)(uintptr_t), + const char *fmt, ...) __printflike(6, 7); +int ithread_destroy(struct ithd *ithread); +u_char ithread_priority(enum intr_type flags); +int ithread_add_handler(struct ithd *ithread, const char *name, + driver_intr_t handler, void *arg, u_char pri, enum intr_type flags, + void **cookiep); +int ithread_remove_handler(void *cookie); +int ithread_schedule(struct ithd *ithread, int do_switch); +int swi_add(struct ithd **ithdp, const char *name, + driver_intr_t handler, void *arg, int pri, enum intr_type flags, + void **cookiep); +void swi_sched(void *cookie, int flags); + +#endif diff --git a/src/include/sys/ioccom.h b/src/include/sys/ioccom.h new file mode 100644 index 0000000..67eb299 --- /dev/null +++ b/src/include/sys/ioccom.h @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * 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. + * 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. + * + * @(#)ioccom.h 8.2 (Berkeley) 3/28/94 + * $FreeBSD: src/sys/sys/ioccom.h,v 1.15 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_IOCCOM_H_ +#define _SYS_IOCCOM_H_ + +/* + * Ioctl's have the command encoded in the lower word, and the size of + * any in or out parameters in the upper word. The high 3 bits of the + * upper word are used to encode the in/out status of the parameter. + */ +#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ +#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) +#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16)) +#define IOCGROUP(x) (((x) >> 8) & 0xff) + +#define IOCPARM_MAX PAGE_SIZE /* max size of ioctl, mult. of PAGE_SIZE */ +#define IOC_VOID 0x20000000 /* no parameters */ +#define IOC_OUT 0x40000000 /* copy out parameters */ +#define IOC_IN 0x80000000 /* copy in parameters */ +#define IOC_INOUT (IOC_IN|IOC_OUT) +#define IOC_DIRMASK 0xe0000000 /* mask for IN/OUT/VOID */ + +#define _IOC(inout,group,num,len) \ + ((unsigned long)(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))) +#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) +#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) +#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) +/* this should be _IORW, but stdio got there first */ +#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int ioctl(int, unsigned long, ...); +__END_DECLS + +#endif + +#endif /* !_SYS_IOCCOM_H_ */ diff --git a/src/include/sys/ioctl.h b/src/include/sys/ioctl.h new file mode 100644 index 0000000..69984e6 --- /dev/null +++ b/src/include/sys/ioctl.h @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)ioctl.h 8.6 (Berkeley) 3/28/94 + * $FreeBSD: src/sys/sys/ioctl.h,v 1.12 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_IOCTL_H_ +#define _SYS_IOCTL_H_ + +#ifdef _KERNEL +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#warning "Don't #include ioctl.h in the kernel. Include xxxio.h instead." +#endif +#endif + +#include + +/* + * Pun for SunOS prior to 3.2. SunOS 3.2 and later support TIOCGWINSZ + * and TIOCSWINSZ (yes, even 3.2-3.5, the fact that it wasn't documented + * notwithstanding). + */ +struct ttysize { + unsigned short ts_lines; + unsigned short ts_cols; + unsigned short ts_xxx; + unsigned short ts_yyy; +}; +#define TIOCGSIZE TIOCGWINSZ +#define TIOCSSIZE TIOCSWINSZ + +#include + +#include +#include + +#endif /* !_SYS_IOCTL_H_ */ + +/* + * Keep outside _SYS_IOCTL_H_ + * Compatibility with old terminal driver + * + * Source level -> #define USE_OLD_TTY + * Kernel level -> options COMPAT_43 or COMPAT_SUNOS + */ +#if defined(USE_OLD_TTY) || defined(COMPAT_43) || defined(COMPAT_SUNOS) +#include +#endif diff --git a/src/include/sys/ioctl_compat.h b/src/include/sys/ioctl_compat.h new file mode 100644 index 0000000..1428899 --- /dev/null +++ b/src/include/sys/ioctl_compat.h @@ -0,0 +1,164 @@ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)ioctl_compat.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/ioctl_compat.h,v 1.6 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_IOCTL_COMPAT_H_ +#define _SYS_IOCTL_COMPAT_H_ + +#include +#include + +struct tchars { + char t_intrc; /* interrupt */ + char t_quitc; /* quit */ + char t_startc; /* start output */ + char t_stopc; /* stop output */ + char t_eofc; /* end-of-file */ + char t_brkc; /* input delimiter (like nl) */ +}; + +struct ltchars { + char t_suspc; /* stop process signal */ + char t_dsuspc; /* delayed stop process signal */ + char t_rprntc; /* reprint line */ + char t_flushc; /* flush output (toggles) */ + char t_werasc; /* word erase */ + char t_lnextc; /* literal next character */ +}; + +/* + * Structure for TIOCGETP and TIOCSETP ioctls. + */ +#ifndef _SGTTYB_ +#define _SGTTYB_ +struct sgttyb { + char sg_ispeed; /* input speed */ + char sg_ospeed; /* output speed */ + char sg_erase; /* erase character */ + char sg_kill; /* kill character */ + short sg_flags; /* mode flags */ +}; +#endif + +#ifdef USE_OLD_TTY +# undef TIOCGETD +# define TIOCGETD _IOR('t', 0, int) /* get line discipline */ +# undef TIOCSETD +# define TIOCSETD _IOW('t', 1, int) /* set line discipline */ +#else +# define OTIOCGETD _IOR('t', 0, int) /* get line discipline */ +# define OTIOCSETD _IOW('t', 1, int) /* set line discipline */ +#endif +#define TIOCHPCL _IO('t', 2) /* hang up on last close */ +#define TIOCGETP _IOR('t', 8,struct sgttyb)/* get parameters -- gtty */ +#define TIOCSETP _IOW('t', 9,struct sgttyb)/* set parameters -- stty */ +#define TIOCSETN _IOW('t',10,struct sgttyb)/* as above, but no flushtty*/ +#define TIOCSETC _IOW('t',17,struct tchars)/* set special characters */ +#define TIOCGETC _IOR('t',18,struct tchars)/* get special characters */ +#define TANDEM 0x00000001 /* send stopc on out q full */ +#define CBREAK 0x00000002 /* half-cooked mode */ +#define LCASE 0x00000004 /* simulate lower case */ +#define ECHO 0x00000008 /* echo input */ +#define CRMOD 0x00000010 /* map \r to \r\n on output */ +#define RAW 0x00000020 /* no i/o processing */ +#define ODDP 0x00000040 /* get/send odd parity */ +#define EVENP 0x00000080 /* get/send even parity */ +#define ANYP 0x000000c0 /* get any parity/send none */ +#define NLDELAY 0x00000300 /* \n delay */ +#define NL0 0x00000000 +#define NL1 0x00000100 /* tty 37 */ +#define NL2 0x00000200 /* vt05 */ +#define NL3 0x00000300 +#define TBDELAY 0x00000c00 /* horizontal tab delay */ +#define TAB0 0x00000000 +#define TAB1 0x00000400 /* tty 37 */ +#define TAB2 0x00000800 +#define XTABS 0x00000c00 /* expand tabs on output */ +#define CRDELAY 0x00003000 /* \r delay */ +#define CR0 0x00000000 +#define CR1 0x00001000 /* tn 300 */ +#define CR2 0x00002000 /* tty 37 */ +#define CR3 0x00003000 /* concept 100 */ +#define VTDELAY 0x00004000 /* vertical tab delay */ +#define FF0 0x00000000 +#define FF1 0x00004000 /* tty 37 */ +#define BSDELAY 0x00008000 /* \b delay */ +#define BS0 0x00000000 +#define BS1 0x00008000 +#define ALLDELAY (NLDELAY|TBDELAY|CRDELAY|VTDELAY|BSDELAY) +#define CRTBS 0x00010000 /* do backspacing for crt */ +#define PRTERA 0x00020000 /* \ ... / erase */ +#define CRTERA 0x00040000 /* " \b " to wipe out char */ +#define TILDE 0x00080000 /* hazeltine tilde kludge */ +#define MDMBUF 0x00100000 /*start/stop output on carrier*/ +#define LITOUT 0x00200000 /* literal output */ +#define TOSTOP 0x00400000 /*SIGSTOP on background output*/ +#define FLUSHO 0x00800000 /* flush output to terminal */ +#define NOHANG 0x01000000 /* (no-op) was no SIGHUP on carrier drop */ +#define L001000 0x02000000 +#define CRTKIL 0x04000000 /* kill line with " \b " */ +#define PASS8 0x08000000 +#define CTLECH 0x10000000 /* echo control chars as ^X */ +#define PENDIN 0x20000000 /* tp->t_rawq needs reread */ +#define DECCTQ 0x40000000 /* only ^Q starts after ^S */ +#define NOFLSH 0x80000000 /* no output flush on signal */ +#define TIOCLBIS _IOW('t', 127, int) /* bis local mode bits */ +#define TIOCLBIC _IOW('t', 126, int) /* bic local mode bits */ +#define TIOCLSET _IOW('t', 125, int) /* set entire local mode word */ +#define TIOCLGET _IOR('t', 124, int) /* get local modes */ +#define LCRTBS (CRTBS>>16) +#define LPRTERA (PRTERA>>16) +#define LCRTERA (CRTERA>>16) +#define LTILDE (TILDE>>16) +#define LMDMBUF (MDMBUF>>16) +#define LLITOUT (LITOUT>>16) +#define LTOSTOP (TOSTOP>>16) +#define LFLUSHO (FLUSHO>>16) +#define LNOHANG (NOHANG>>16) +#define LCRTKIL (CRTKIL>>16) +#define LPASS8 (PASS8>>16) +#define LCTLECH (CTLECH>>16) +#define LPENDIN (PENDIN>>16) +#define LDECCTQ (DECCTQ>>16) +#define LNOFLSH (NOFLSH>>16) +#define TIOCSLTC _IOW('t',117,struct ltchars)/* set local special chars*/ +#define TIOCGLTC _IOR('t',116,struct ltchars)/* get local special chars*/ +#define OTIOCCONS _IO('t', 98) /* for hp300 -- sans int arg */ +#define OTTYDISC 0 +#define NETLDISC 1 +#define NTTYDISC 2 + +#endif /* !_SYS_IOCTL_COMPAT_H_ */ diff --git a/src/include/sys/ipc.h b/src/include/sys/ipc.h new file mode 100644 index 0000000..c2e4ad2 --- /dev/null +++ b/src/include/sys/ipc.h @@ -0,0 +1,128 @@ +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + * 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. + * + * @(#)ipc.h 8.4 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/ipc.h,v 1.24 2004/04/07 04:19:49 imp Exp $ + */ + +/* + * SVID compatible ipc.h file + */ +#ifndef _SYS_IPC_H_ +#define _SYS_IPC_H_ + +#include +#include + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _KEY_T_DECLARED +typedef __key_t key_t; +#define _KEY_T_DECLARED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +/* + * XXX almost all members have wrong types. + */ +struct ipc_perm { + unsigned short cuid; /* creator user id */ + unsigned short cgid; /* creator group id */ + unsigned short uid; /* user id */ + unsigned short gid; /* group id */ + unsigned short mode; /* r/w permission */ + unsigned short seq; /* sequence # (to generate unique ipcid) */ + key_t key; /* user specified msg/sem/shm key */ +}; + +#if __BSD_VISIBLE +/* common mode bits */ +#define IPC_R 000400 /* read permission */ +#define IPC_W 000200 /* write/alter permission */ +#define IPC_M 010000 /* permission to change control info */ +#endif + +/* SVID required constants (same values as system 5) */ +#define IPC_CREAT 001000 /* create entry if key does not exist */ +#define IPC_EXCL 002000 /* fail if key exists */ +#define IPC_NOWAIT 004000 /* error if request must wait */ + +#define IPC_PRIVATE (key_t)0 /* private key */ + +#define IPC_RMID 0 /* remove identifier */ +#define IPC_SET 1 /* set options */ +#define IPC_STAT 2 /* get options */ +#if __BSD_VISIBLE +#define IPC_INFO 3 /* get info */ +#endif + +#ifdef _KERNEL +/* Macros to convert between ipc ids and array indices or sequence ids */ +#define IPCID_TO_IX(id) ((id) & 0xffff) +#define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff) +#define IXSEQ_TO_IPCID(ix,perm) (((perm.seq) << 16) | (ix & 0xffff)) + +struct thread; +struct proc; +struct vmspace; + +int ipcperm(struct thread *, struct ipc_perm *, int); +extern void (*shmfork_hook)(struct proc *, struct proc *); +extern void (*shmexit_hook)(struct vmspace *); + +#else /* ! _KERNEL */ + +__BEGIN_DECLS +key_t ftok(const char *, int); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_IPC_H_ */ diff --git a/src/include/sys/jail.h b/src/include/sys/jail.h new file mode 100644 index 0000000..0f6b21d --- /dev/null +++ b/src/include/sys/jail.h @@ -0,0 +1,108 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/sys/jail.h,v 1.21 2004/04/26 19:46:52 bmilekic Exp $ + * + */ + +#ifndef _SYS_JAIL_H_ +#define _SYS_JAIL_H_ + +struct jail { + u_int32_t version; + char *path; + char *hostname; + u_int32_t ip_number; +}; + +struct xprison { + int pr_version; + int pr_id; + char pr_path[MAXPATHLEN]; + char pr_host[MAXHOSTNAMELEN]; + u_int32_t pr_ip; +}; +#define XPRISON_VERSION 1 + +#ifndef _KERNEL + +int jail(struct jail *); +int jail_attach(int); + +#else /* _KERNEL */ + +#include +#include +#include +#include + +#define JAIL_MAX 999999 + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_PRISON); +#endif + +/* + * This structure describes a prison. It is pointed to by all struct + * ucreds's of the inmates. pr_ref keeps track of them and is used to + * delete the struture when the last inmate is dead. + * + * Lock key: + * (a) allprison_mutex + * (p) locked by pr_mutex + * (c) set only during creation before the structure is shared, no mutex + * required to read + * (d) set only during destruction of jail, no mutex needed + */ +struct prison { + LIST_ENTRY(prison) pr_list; /* (a) all prisons */ + int pr_id; /* (c) prison id */ + int pr_ref; /* (p) refcount */ + char pr_path[MAXPATHLEN]; /* (c) chroot path */ + struct vnode *pr_root; /* (c) vnode to rdir */ + char pr_host[MAXHOSTNAMELEN]; /* (p) jail hostname */ + u_int32_t pr_ip; /* (c) ip addr host */ + void *pr_linux; /* (p) linux abi */ + int pr_securelevel; /* (p) securelevel */ + struct task pr_task; /* (d) destroy task */ + struct mtx pr_mtx; +}; + +/* + * Sysctl-set variables that determine global jail policy + * + * XXX MIB entries will need to be protected by a mutex. + */ +extern int jail_set_hostname_allowed; +extern int jail_socket_unixiproute_only; +extern int jail_sysvipc_allowed; +extern int jail_getfsstat_jailrootonly; +extern int jail_allow_raw_sockets; + +LIST_HEAD(prisonlist, prison); +extern struct prisonlist allprison; + +/* + * Kernel support functions for jail(). + */ +struct ucred; +struct mount; +struct sockaddr; +int jailed(struct ucred *cred); +void getcredhostname(struct ucred *cred, char *, size_t); +int prison_check(struct ucred *cred1, struct ucred *cred2); +int prison_check_mount(struct ucred *cred, struct mount *mp); +void prison_free(struct prison *pr); +u_int32_t prison_getip(struct ucred *cred); +void prison_hold(struct prison *pr); +int prison_if(struct ucred *cred, struct sockaddr *sa); +int prison_ip(struct ucred *cred, int flag, u_int32_t *ip); +void prison_remote_ip(struct ucred *cred, int flags, u_int32_t *ip); + +#endif /* !_KERNEL */ +#endif /* !_SYS_JAIL_H_ */ diff --git a/src/include/sys/joystick.h b/src/include/sys/joystick.h new file mode 100644 index 0000000..52ae923 --- /dev/null +++ b/src/include/sys/joystick.h @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1995 Jean-Marc Zucconi + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/joystick.h,v 1.5 2002/06/02 20:05:56 schweikh Exp $ + */ + +#ifndef _SYS_JOYSTICK_H_ +#define _SYS_JOYSTICK_H_ + +#include + +struct joystick { + int x; + int y; + int b1; + int b2; +}; + +#define JOY_SETTIMEOUT _IOW('J', 1, int) /* set timeout */ +#define JOY_GETTIMEOUT _IOR('J', 2, int) /* get timeout */ +#define JOY_SET_X_OFFSET _IOW('J', 3, int) /* set offset on X-axis */ +#define JOY_SET_Y_OFFSET _IOW('J', 4, int) /* set offset on X-axis */ +#define JOY_GET_X_OFFSET _IOR('J', 5, int) /* get offset on X-axis */ +#define JOY_GET_Y_OFFSET _IOR('J', 6, int) /* get offset on Y-axis */ + +#endif /* !_SYS_JOYSTICK_H_ */ diff --git a/src/include/sys/jumbo.h b/src/include/sys/jumbo.h new file mode 100644 index 0000000..3a2e711 --- /dev/null +++ b/src/include/sys/jumbo.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 1997, Duke University + * All rights reserved. + * + * Author: + * Andrew Gallatin + * + * 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. The name of Duke University may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY DUKE UNIVERSITY ``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 DUKE UNIVERSITY 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 PROFITSOR 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. + * + * $FreeBSD: src/sys/sys/jumbo.h,v 1.5 2003/03/25 01:47:29 jake Exp $ + */ + +#ifndef _SYS_JUMBO_H_ +#define _SYS_JUMBO_H_ + +#ifdef _KERNEL +extern vm_offset_t jumbo_basekva; + +static __inline caddr_t jumbo_phys_to_kva(vm_paddr_t pa); +static __inline caddr_t +jumbo_phys_to_kva(vm_paddr_t pa) +{ + vm_page_t pg; + + pg = PHYS_TO_VM_PAGE(pa); + pg->flags &= ~PG_BUSY; + return (caddr_t)(ptoa((vm_offset_t)pg->pindex) + jumbo_basekva); +} + +int jumbo_vm_init(void); +void jumbo_freem(void *addr, void *args); +vm_page_t jumbo_pg_alloc(void); +void jumbo_pg_free(vm_offset_t addr); +void jumbo_pg_steal(vm_page_t pg); +#endif /* _KERNEL */ + +#endif /* !_SYS_JUMBO_H_ */ diff --git a/src/include/sys/kbio.h b/src/include/sys/kbio.h new file mode 100644 index 0000000..eaf05bc --- /dev/null +++ b/src/include/sys/kbio.h @@ -0,0 +1,239 @@ +/*- + * $FreeBSD: src/sys/sys/kbio.h,v 1.7 2001/03/11 22:47:04 ache Exp $ + */ + +#ifndef _SYS_KBIO_H_ +#define _SYS_KBIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* get/set keyboard I/O mode */ +#define K_RAW 0 /* keyboard returns scancodes */ +#define K_XLATE 1 /* keyboard returns ascii */ +#define K_CODE 2 /* keyboard returns keycodes */ +#define KDGKBMODE _IOR('K', 6, int) +#define KDSKBMODE _IO('K', 7 /*, int */) + +/* make tone */ +#define KDMKTONE _IO('K', 8 /*, int */) + +/* see console.h for the definitions of the following ioctls */ +#if notdef +#define KDGETMODE _IOR('K', 9, int) +#define KDSETMODE _IO('K', 10 /*, int */) +#define KDSBORDER _IO('K', 13 /*, int */) +#endif + +/* get/set keyboard lock state */ +#define CLKED 1 /* Caps locked */ +#define NLKED 2 /* Num locked */ +#define SLKED 4 /* Scroll locked */ +#define ALKED 8 /* AltGr locked */ +#define LOCK_MASK (CLKED | NLKED | SLKED | ALKED) +#define KDGKBSTATE _IOR('K', 19, int) +#define KDSKBSTATE _IO('K', 20 /*, int */) + +/* enable/disable I/O access */ +#define KDENABIO _IO('K', 60) +#define KDDISABIO _IO('K', 61) + +/* make sound */ +#define KIOCSOUND _IO('K', 63 /*, int */) + +/* get keyboard model */ +#define KB_OTHER 0 /* keyboard not known */ +#define KB_84 1 /* 'old' 84 key AT-keyboard */ +#define KB_101 2 /* MF-101 or MF-102 keyboard */ +#define KDGKBTYPE _IOR('K', 64, int) + +/* get/set keyboard LED state */ +#define LED_CAP 1 /* Caps lock LED */ +#define LED_NUM 2 /* Num lock LED */ +#define LED_SCR 4 /* Scroll lock LED */ +#define LED_MASK (LED_CAP | LED_NUM | LED_SCR) +#define KDGETLED _IOR('K', 65, int) +#define KDSETLED _IO('K', 66 /*, int */) + +/* set keyboard repeat rate (obsolete, use KDSETREPEAT below) */ +#define KDSETRAD _IO('K', 67 /*, int */) + +/* see console.h for the definition of the following ioctl */ +#if notdef +#define KDRASTER _IOW('K', 100, scr_size_t) +#endif + +/* get keyboard information */ +struct keyboard_info { + int kb_index; /* kbdio index# */ + char kb_name[16]; /* driver name */ + int kb_unit; /* unit# */ + int kb_type; /* KB_84, KB_101, KB_OTHER,... */ + int kb_config; /* device configuration flags */ + int kb_flags; /* internal flags */ +}; +typedef struct keyboard_info keyboard_info_t; +#define KDGKBINFO _IOR('K', 101, keyboard_info_t) + +/* set/get keyboard repeat rate (new interface) */ +struct keyboard_repeat { + int kb_repeat[2]; +}; +typedef struct keyboard_repeat keyboard_repeat_t; +#define KDSETREPEAT _IOW('K', 102, keyboard_repeat_t) +#define KDGETREPEAT _IOR('K', 103, keyboard_repeat_t) + +/* get/set key map/accent map/function key strings */ + +#define NUM_KEYS 256 /* number of keys in table */ +#define NUM_STATES 8 /* states per key */ +#define ALTGR_OFFSET 128 /* offset for altlock keys */ + +#define NUM_DEADKEYS 15 /* number of accent keys */ +#define NUM_ACCENTCHARS 52 /* max number of accent chars */ + +#define NUM_FKEYS 96 /* max number of function keys */ +#define MAXFK 16 /* max length of a function key str */ + +#ifndef _KEYMAP_DECLARED +#define _KEYMAP_DECLARED + +struct keyent_t { + u_char map[NUM_STATES]; + u_char spcl; + u_char flgs; +#define FLAG_LOCK_O 0 +#define FLAG_LOCK_C 1 +#define FLAG_LOCK_N 2 +}; + +struct keymap { + u_short n_keys; + struct keyent_t key[NUM_KEYS]; +}; +typedef struct keymap keymap_t; + +#endif /* !_KEYMAP_DECLARED */ + +/* defines for "special" keys (spcl bit set in keymap) */ +#define NOP 0x00 /* nothing (dead key) */ +#define LSH 0x02 /* left shift key */ +#define RSH 0x03 /* right shift key */ +#define CLK 0x04 /* caps lock key */ +#define NLK 0x05 /* num lock key */ +#define SLK 0x06 /* scroll lock key */ +#define LALT 0x07 /* left alt key */ +#define BTAB 0x08 /* backwards tab */ +#define LCTR 0x09 /* left control key */ +#define NEXT 0x0a /* switch to next screen */ +#define F_SCR 0x0b /* switch to first screen */ +#define L_SCR 0x1a /* switch to last screen */ +#define F_FN 0x1b /* first function key */ +#define L_FN 0x7a /* last function key */ +/* 0x7b-0x7f reserved do not use ! */ +#define RCTR 0x80 /* right control key */ +#define RALT 0x81 /* right alt (altgr) key */ +#define ALK 0x82 /* alt lock key */ +#define ASH 0x83 /* alt shift key */ +#define META 0x84 /* meta key */ +#define RBT 0x85 /* boot machine */ +#define DBG 0x86 /* call debugger */ +#define SUSP 0x87 /* suspend power (APM) */ +#define SPSC 0x88 /* toggle splash/text screen */ + +#define F_ACC DGRA /* first accent key */ +#define DGRA 0x89 /* grave */ +#define DACU 0x8a /* acute */ +#define DCIR 0x8b /* circumflex */ +#define DTIL 0x8c /* tilde */ +#define DMAC 0x8d /* macron */ +#define DBRE 0x8e /* breve */ +#define DDOT 0x8f /* dot */ +#define DUML 0x90 /* umlaut/diaresis */ +#define DDIA 0x90 /* diaresis */ +#define DSLA 0x91 /* slash */ +#define DRIN 0x92 /* ring */ +#define DCED 0x93 /* cedilla */ +#define DAPO 0x94 /* apostrophe */ +#define DDAC 0x95 /* double acute */ +#define DOGO 0x96 /* ogonek */ +#define DCAR 0x97 /* caron */ +#define L_ACC DCAR /* last accent key */ + +#define STBY 0x98 /* Go into standby mode (apm) */ +#define PREV 0x99 /* switch to previous screen */ +#define PNC 0x9a /* force system panic */ +#define LSHA 0x9b /* left shift key / alt lock */ +#define RSHA 0x9c /* right shift key / alt lock */ +#define LCTRA 0x9d /* left ctrl key / alt lock */ +#define RCTRA 0x9e /* right ctrl key / alt lock */ +#define LALTA 0x9f /* left alt key / alt lock */ +#define RALTA 0xa0 /* right alt key / alt lock */ +#define HALT 0xa1 /* halt machine */ +#define PDWN 0xa2 /* halt machine and power down */ +#define PASTE 0xa3 /* paste from cut-paste buffer */ + +#define F(x) ((x)+F_FN-1) +#define S(x) ((x)+F_SCR-1) +#define ACC(x) ((x)+F_ACC) + +struct acc_t { + u_char accchar; + u_char map[NUM_ACCENTCHARS][2]; +}; + +struct accentmap { + u_short n_accs; + struct acc_t acc[NUM_DEADKEYS]; +}; +typedef struct accentmap accentmap_t; + +struct keyarg { + u_short keynum; + struct keyent_t key; +}; +typedef struct keyarg keyarg_t; + +struct fkeytab { + u_char str[MAXFK]; + u_char len; +}; +typedef struct fkeytab fkeytab_t; + +struct fkeyarg { + u_short keynum; + char keydef[MAXFK]; + char flen; +}; +typedef struct fkeyarg fkeyarg_t; + +#define GETFKEY _IOWR('k', 0, fkeyarg_t) +#define SETFKEY _IOWR('k', 1, fkeyarg_t) +#if notdef /* see console.h */ +#define GIO_SCRNMAP _IOR('k', 2, scrmap_t) +#define PIO_SCRNMAP _IOW('k', 3, scrmap_t) +#endif +#define GIO_KEYMAP _IOR('k', 6, keymap_t) +#define PIO_KEYMAP _IOW('k', 7, keymap_t) +#define GIO_DEADKEYMAP _IOR('k', 8, accentmap_t) +#define PIO_DEADKEYMAP _IOW('k', 9, accentmap_t) +#define GIO_KEYMAPENT _IOWR('k', 10, keyarg_t) +#define PIO_KEYMAPENT _IOW('k', 11, keyarg_t) + +/* flags set to the return value in the KD_XLATE mode */ + +#define NOKEY 0x100 /* no key pressed marker */ +#define FKEY 0x200 /* function key marker */ +#define MKEY 0x400 /* meta key marker (prepend ESC)*/ +#define BKEY 0x800 /* backtab (ESC [ Z) */ + +#define SPCLKEY 0x8000 /* special key */ +#define RELKEY 0x4000 /* key released */ +#define ERRKEY 0x2000 /* error */ + +#define KEYCHAR(c) ((c) & 0x00ff) +#define KEYFLAGS(c) ((c) & ~0x00ff) + +#endif /* !_SYS_KBIO_H_ */ diff --git a/src/include/sys/kenv.h b/src/include/sys/kenv.h new file mode 100644 index 0000000..efca13a --- /dev/null +++ b/src/include/sys/kenv.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2002 Maxime Henrion + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/kenv.h,v 1.1 2002/04/17 13:06:36 mux Exp $ + */ + +#ifndef _SYS_KENV_H_ +#define _SYS_KENV_H_ + +/* + * Constants for the kenv(2) syscall + */ +#define KENV_GET 0 +#define KENV_SET 1 +#define KENV_UNSET 2 +#define KENV_DUMP 3 + +#define KENV_MNAMELEN 128 /* Maximum name length (for the syscall) */ +#define KENV_MVALLEN 128 /* Maximum value length (for the syscall) */ + +#endif /* !_SYS_KENV_H_ */ diff --git a/src/include/sys/kernel.h b/src/include/sys/kernel.h new file mode 100644 index 0000000..3db6eaa --- /dev/null +++ b/src/include/sys/kernel.h @@ -0,0 +1,342 @@ +/*- + * Copyright (c) 1995 Terrence R. Lambert + * All rights reserved. + * + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)kernel.h 8.3 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/kernel.h,v 1.116 2004/03/10 09:23:27 phk Exp $ + */ + +#ifndef _SYS_KERNEL_H_ +#define _SYS_KERNEL_H_ + +#include + +#ifdef _KERNEL + +/* for intrhook below */ +#include + +/* THIS MUST DIE! */ +#include + +/* Global variables for the kernel. */ + +/* 1.1 */ +extern unsigned long hostid; +extern char hostname[MAXHOSTNAMELEN]; +extern int hostnamelen; +extern char domainname[MAXHOSTNAMELEN]; +extern int domainnamelen; +extern char kernelname[MAXPATHLEN]; + +extern int tick; /* usec per tick (1000000 / hz) */ +extern int hz; /* system clock's frequency */ +extern int psratio; /* ratio: prof / stat */ +extern int stathz; /* statistics clock's frequency */ +extern int profhz; /* profiling clock's frequency */ +extern int profprocs; /* number of process's profiling */ +extern int ticks; +extern int lbolt; /* once a second sleep address */ + +extern int tz_minuteswest; +extern int tz_dsttime; + +#endif /* _KERNEL */ + +/* + * Enumerated types for known system startup interfaces. + * + * Startup occurs in ascending numeric order; the list entries are + * sorted prior to attempting startup to guarantee order. Items + * of the same level are arbitrated for order based on the 'order' + * element. + * + * These numbers are arbitrary and are chosen ONLY for ordering; the + * enumeration values are explicit rather than implicit to provide + * for binary compatibility with inserted elements. + * + * The SI_SUB_RUN_SCHEDULER value must have the highest lexical value. + * + * The SI_SUB_CONSOLE and SI_SUB_SWAP values represent values used by + * the BSD 4.4Lite but not by FreeBSD; they are maintained in dependent + * order to support porting. + * + * The SI_SUB_PROTO_BEGIN and SI_SUB_PROTO_END bracket a range of + * initializations to take place at splimp(). This is a historical + * wart that should be removed -- probably running everything at + * splimp() until the first init that doesn't want it is the correct + * fix. They are currently present to ensure historical behavior. + */ +enum sysinit_sub_id { + SI_SUB_DUMMY = 0x0000000, /* not executed; for linker*/ + SI_SUB_DONE = 0x0000001, /* processed*/ + SI_SUB_TUNABLES = 0x0700000, /* establish tunable values */ + SI_SUB_CONSOLE = 0x0800000, /* console*/ + SI_SUB_COPYRIGHT = 0x0800001, /* first use of console*/ + SI_SUB_MTX_POOL_STATIC = 0x0900000, /* static mutex pool */ + SI_SUB_LOCKMGR = 0x0980000, /* lockmgr locks */ + SI_SUB_VM = 0x1000000, /* virtual memory system init*/ + SI_SUB_KMEM = 0x1800000, /* kernel memory*/ + SI_SUB_KVM_RSRC = 0x1A00000, /* kvm operational limits*/ + SI_SUB_WITNESS = 0x1A80000, /* witness initialization */ + SI_SUB_MTX_POOL_DYNAMIC = 0x1AC0000, /* dynamic mutex pool */ + SI_SUB_LOCK = 0x1B00000, /* various locks */ + SI_SUB_EVENTHANDLER = 0x1C00000, /* eventhandler init */ + SI_SUB_KLD = 0x2000000, /* KLD and module setup */ + SI_SUB_CPU = 0x2100000, /* CPU resource(s)*/ + SI_SUB_MAC = 0x2180000, /* TrustedBSD MAC subsystem */ + SI_SUB_MAC_POLICY = 0x21C0000, /* TrustedBSD MAC policies */ + SI_SUB_MAC_LATE = 0x21D0000, /* TrustedBSD MAC subsystem */ + SI_SUB_INTRINSIC = 0x2200000, /* proc 0*/ + SI_SUB_VM_CONF = 0x2300000, /* config VM, set limits*/ + SI_SUB_RUN_QUEUE = 0x2400000, /* set up run queue*/ + SI_SUB_KTRACE = 0x2480000, /* ktrace */ + SI_SUB_CREATE_INIT = 0x2500000, /* create init process*/ + SI_SUB_SCHED_IDLE = 0x2600000, /* required idle procs */ + SI_SUB_MBUF = 0x2700000, /* mbuf subsystem */ + SI_SUB_INTR = 0x2800000, /* interrupt threads */ + SI_SUB_SOFTINTR = 0x2800001, /* start soft interrupt thread */ + SI_SUB_DEVFS = 0x2F00000, /* devfs ready for devices */ + SI_SUB_INIT_IF = 0x3000000, /* prep for net interfaces */ + SI_SUB_DRIVERS = 0x3100000, /* Let Drivers initialize */ + SI_SUB_CONFIGURE = 0x3800000, /* Configure devices */ + SI_SUB_VFS = 0x4000000, /* virtual filesystem*/ + SI_SUB_CLOCKS = 0x4800000, /* real time and stat clocks*/ + SI_SUB_CLIST = 0x5800000, /* clists*/ + SI_SUB_SYSV_SHM = 0x6400000, /* System V shared memory*/ + SI_SUB_SYSV_SEM = 0x6800000, /* System V semaphores*/ + SI_SUB_SYSV_MSG = 0x6C00000, /* System V message queues*/ + SI_SUB_P1003_1B = 0x6E00000, /* P1003.1B realtime */ + SI_SUB_PSEUDO = 0x7000000, /* pseudo devices*/ + SI_SUB_EXEC = 0x7400000, /* execve() handlers */ + SI_SUB_PROTO_BEGIN = 0x8000000, /* XXX: set splimp (kludge)*/ + SI_SUB_PROTO_IF = 0x8400000, /* interfaces*/ + SI_SUB_PROTO_DOMAIN = 0x8800000, /* domains (address families?)*/ + SI_SUB_PROTO_IFATTACHDOMAIN = 0x8800001, /* domain dependent data init*/ + SI_SUB_PROTO_END = 0x8ffffff, /* XXX: set splx (kludge)*/ + SI_SUB_KPROF = 0x9000000, /* kernel profiling*/ + SI_SUB_KICK_SCHEDULER = 0xa000000, /* start the timeout events*/ + SI_SUB_INT_CONFIG_HOOKS = 0xa800000, /* Interrupts enabled config */ + SI_SUB_ROOT_CONF = 0xb000000, /* Find root devices */ + SI_SUB_DUMP_CONF = 0xb200000, /* Find dump devices */ + SI_SUB_RAID = 0xb380000, /* Configure RAIDframe or Vinum */ + SI_SUB_MOUNT_ROOT = 0xb400000, /* root mount*/ + SI_SUB_SWAP = 0xc000000, /* swap */ + SI_SUB_INTRINSIC_POST = 0xd000000, /* proc 0 cleanup*/ + SI_SUB_KTHREAD_INIT = 0xe000000, /* init process*/ + SI_SUB_KTHREAD_PAGE = 0xe400000, /* pageout daemon*/ + SI_SUB_KTHREAD_VM = 0xe800000, /* vm daemon*/ + SI_SUB_KTHREAD_BUF = 0xea00000, /* buffer daemon*/ + SI_SUB_KTHREAD_UPDATE = 0xec00000, /* update daemon*/ + SI_SUB_KTHREAD_IDLE = 0xee00000, /* idle procs*/ + SI_SUB_SMP = 0xf000000, /* start the APs*/ + SI_SUB_RUN_SCHEDULER = 0xfffffff /* scheduler*/ +}; + + +/* + * Some enumerated orders; "ANY" sorts last. + */ +enum sysinit_elem_order { + SI_ORDER_FIRST = 0x0000000, /* first*/ + SI_ORDER_SECOND = 0x0000001, /* second*/ + SI_ORDER_THIRD = 0x0000002, /* third*/ + SI_ORDER_MIDDLE = 0x1000000, /* somewhere in the middle */ + SI_ORDER_ANY = 0xfffffff /* last*/ +}; + + +/* + * A system initialization call instance + * + * At the moment there is one instance of sysinit. We probably do not + * want two which is why this code is if'd out, but we definitely want + * to discern SYSINIT's which take non-constant data pointers and + * SYSINIT's which take constant data pointers, + * + * The C_* macros take functions expecting const void * arguments + * while the non-C_* macros take functions expecting just void * arguments. + * + * With -Wcast-qual on, the compiler issues warnings: + * - if we pass non-const data or functions taking non-const data + * to a C_* macro. + * + * - if we pass const data to the normal macros + * + * However, no warning is issued if we pass a function taking const data + * through a normal non-const macro. This is ok because the function is + * saying it won't modify the data so we don't care whether the data is + * modifiable or not. + */ + +typedef void (*sysinit_nfunc_t)(void *); +typedef void (*sysinit_cfunc_t)(const void *); + +struct sysinit { + enum sysinit_sub_id subsystem; /* subsystem identifier*/ + enum sysinit_elem_order order; /* init order within subsystem*/ + sysinit_cfunc_t func; /* function */ + const void *udata; /* multiplexer/argument */ +}; + +/* + * Default: no special processing + * + * The C_ version of SYSINIT is for data pointers to const + * data ( and functions taking data pointers to const data ). + * At the moment it is no different from SYSINIT and thus + * still results in warnings. + * + * The casts are necessary to have the compiler produce the + * correct warnings when -Wcast-qual is used. + * + */ +#define C_SYSINIT(uniquifier, subsystem, order, func, ident) \ + static struct sysinit uniquifier ## _sys_init = { \ + subsystem, \ + order, \ + func, \ + (ident) \ + }; \ + DATA_SET(sysinit_set,uniquifier ## _sys_init); + +#define SYSINIT(uniquifier, subsystem, order, func, ident) \ + C_SYSINIT(uniquifier, subsystem, order, \ + (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident)) + +/* + * Called on module unload: no special processing + */ +#define C_SYSUNINIT(uniquifier, subsystem, order, func, ident) \ + static struct sysinit uniquifier ## _sys_uninit = { \ + subsystem, \ + order, \ + func, \ + (ident) \ + }; \ + DATA_SET(sysuninit_set,uniquifier ## _sys_uninit) + +#define SYSUNINIT(uniquifier, subsystem, order, func, ident) \ + C_SYSUNINIT(uniquifier, subsystem, order, \ + (sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)(ident)) + +void sysinit_add(struct sysinit **set, struct sysinit **set_end); + +/* + * Infrastructure for tunable 'constants'. Value may be specified at compile + * time or kernel load time. Rules relating tunables together can be placed + * in a SYSINIT function at SI_SUB_TUNABLES with SI_ORDER_LAST. + * + * WARNING: developers should never use the reserved suffixes specified in + * loader.conf(5) for any tunables or conflicts will result. + */ + +extern void tunable_int_init(void *); +struct tunable_int { + const char *path; + int *var; +}; +#define TUNABLE_INT(path, var) \ + _TUNABLE_INT((path), (var), __LINE__) +#define _TUNABLE_INT(path, var, line) \ + __TUNABLE_INT((path), (var), line) + +#define __TUNABLE_INT(path, var, line) \ + static struct tunable_int __tunable_int_ ## line = { \ + path, \ + var, \ + }; \ + SYSINIT(__Tunable_init_ ## line, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, \ + tunable_int_init, &__tunable_int_ ## line) + +#define TUNABLE_INT_FETCH(path, var) getenv_int((path), (var)) + +extern void tunable_quad_init(void *); +struct tunable_quad { + const char *path; + quad_t *var; +}; +#define TUNABLE_QUAD(path, var) \ + _TUNABLE_QUAD((path), (var), __LINE__) +#define _TUNABLE_QUAD(path, var, line) \ + __TUNABLE_QUAD((path), (var), line) + +#define __TUNABLE_QUAD(path, var, line) \ + static struct tunable_quad __tunable_quad_ ## line = { \ + path, \ + var, \ + }; \ + SYSINIT(__Tunable_init_ ## line, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, \ + tunable_quad_init, &__tunable_quad_ ## line) + +#define TUNABLE_QUAD_FETCH(path, var) getenv_quad((path), (var)) + +extern void tunable_str_init(void *); +struct tunable_str { + const char *path; + char *var; + int size; +}; +#define TUNABLE_STR(path, var, size) \ + _TUNABLE_STR((path), (var), (size), __LINE__) +#define _TUNABLE_STR(path, var, size, line) \ + __TUNABLE_STR((path), (var), (size), line) + +#define __TUNABLE_STR(path, var, size, line) \ + static struct tunable_str __tunable_str_ ## line = { \ + path, \ + var, \ + size, \ + }; \ + SYSINIT(__Tunable_init_ ## line, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, \ + tunable_str_init, &__tunable_str_ ## line) + +#define TUNABLE_STR_FETCH(path, var, size) \ + getenv_string((path), (var), (size)) + +struct intr_config_hook { + TAILQ_ENTRY(intr_config_hook) ich_links; + void (*ich_func)(void *arg); + void *ich_arg; +}; + +int config_intrhook_establish(struct intr_config_hook *hook); +void config_intrhook_disestablish(struct intr_config_hook *hook); + +#endif /* !_SYS_KERNEL_H_*/ diff --git a/src/include/sys/kerneldump.h b/src/include/sys/kerneldump.h new file mode 100644 index 0000000..368c62d --- /dev/null +++ b/src/include/sys/kerneldump.h @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2002 Poul-Henning Kamp + * Copyright (c) 2002 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by Poul-Henning Kamp + * and NAI Labs, the Security Research Division of Network Associates, Inc. + * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the + * DARPA CHATS research program. + * + * 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. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/kerneldump.h,v 1.6 2002/10/20 17:03:15 tmm Exp $ + */ + +#ifndef _SYS_KERNELDUMP_H +#define _SYS_KERNELDUMP_H + +#include + +#if BYTE_ORDER == LITTLE_ENDIAN +#define dtoh32(x) __bswap32(x) +#define dtoh64(x) __bswap64(x) +#define htod32(x) __bswap32(x) +#define htod64(x) __bswap64(x) +#elif BYTE_ORDER == BIG_ENDIAN +#define dtoh32(x) (x) +#define dtoh64(x) (x) +#define htod32(x) (x) +#define htod64(x) (x) +#endif + +/* + * All uintX_t fields are in dump byte order, which is the same as + * network byte order. Use the macros defined above to read or + * write the fields. + */ +struct kerneldumpheader { + char magic[20]; +#define KERNELDUMPMAGIC "FreeBSD Kernel Dump" +#define KERNELDUMPMAGIC_CLEARED "Cleared Kernel Dump" + char architecture[12]; + uint32_t version; +#define KERNELDUMPVERSION 1 + uint32_t architectureversion; +#define KERNELDUMP_ALPHA_VERSION 1 +#define KERNELDUMP_I386_VERSION 1 +#define KERNELDUMP_IA64_VERSION 1 +#define KERNELDUMP_SPARC64_VERSION 1 + uint64_t dumplength; /* excl headers */ + uint64_t dumptime; + uint32_t blocksize; + char hostname[64]; + char versionstring[192]; + char panicstring[192]; + uint32_t parity; +}; + +/* + * Parity calculation is endian insensitive. + */ +static __inline u_int32_t +kerneldump_parity(struct kerneldumpheader *kdhp) +{ + uint32_t *up, parity; + u_int i; + + up = (uint32_t *)kdhp; + parity = 0; + for (i = 0; i < sizeof *kdhp; i += sizeof *up) + parity ^= *up++; + return (parity); +} + + +#endif /* _SYS_KERNELDUMP_H */ diff --git a/src/include/sys/kobj.h b/src/include/sys/kobj.h new file mode 100644 index 0000000..296ea07 --- /dev/null +++ b/src/include/sys/kobj.h @@ -0,0 +1,249 @@ +/*- + * Copyright (c) 2000,2003 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/kobj.h,v 1.9 2003/10/16 09:16:28 dfr Exp $ + */ + +#ifndef _SYS_KOBJ_H_ +#define _SYS_KOBJ_H_ + +/* + * Forward declarations + */ +typedef struct kobj *kobj_t; +typedef struct kobj_class *kobj_class_t; +typedef struct kobj_method kobj_method_t; +typedef int (*kobjop_t)(void); +typedef struct kobj_ops *kobj_ops_t; +typedef struct kobjop_desc *kobjop_desc_t; +struct malloc_type; + +struct kobj_method { + kobjop_desc_t desc; + kobjop_t func; +}; + +/* + * A class is simply a method table and a sizeof value. When the first + * instance of the class is created, the method table will be compiled + * into a form more suited to efficient method dispatch. This compiled + * method table is always the first field of the object. + */ +#define KOBJ_CLASS_FIELDS \ + const char *name; /* class name */ \ + kobj_method_t *methods; /* method table */ \ + size_t size; /* object size */ \ + kobj_class_t *baseclasses; /* base classes */ \ + u_int refs; /* reference count */ \ + kobj_ops_t ops /* compiled method table */ + +struct kobj_class { + KOBJ_CLASS_FIELDS; +}; + +/* + * Implementation of kobj. + */ +#define KOBJ_FIELDS \ + kobj_ops_t ops + +struct kobj { + KOBJ_FIELDS; +}; + +/* + * The ops table is used as a cache of results from kobj_lookup_method(). + */ + +#define KOBJ_CACHE_SIZE 256 + +struct kobj_ops { + kobj_method_t *cache[KOBJ_CACHE_SIZE]; + kobj_class_t cls; +}; + +struct kobjop_desc { + unsigned int id; /* unique ID */ + kobj_method_t *deflt; /* default implementation */ +}; + +/* + * Shorthand for constructing method tables. + */ +#define KOBJMETHOD(NAME, FUNC) { &NAME##_desc, (kobjop_t) FUNC } + +/* + * Declare a class (which should be defined in another file. + */ +#define DECLARE_CLASS(name) extern struct kobj_class name + +/* + * Define a class with no base classes (api backward-compatible. with + * FreeBSD-5.1 and earlier). + */ +#define DEFINE_CLASS(name, methods, size) \ +DEFINE_CLASS_0(name, name ## _class, methods, size) + +/* + * Define a class with no base classes. Use like this: + * + * DEFINE_CLASS_0(foo, foo_class, foo_methods, sizeof(foo_softc)); + */ +#define DEFINE_CLASS_0(name, classvar, methods, size) \ + \ +struct kobj_class classvar = { \ + #name, methods, size, 0 \ +} + +/* + * Define a class inheriting a single base class. Use like this: + * + * DEFINE_CLASS1(foo, foo_class, foo_methods, sizeof(foo_softc), + * bar); + */ +#define DEFINE_CLASS_1(name, classvar, methods, size, \ + base1) \ + \ +static kobj_class_t name ## _baseclasses[] = \ + { &base1, 0 }; \ +struct kobj_class classvar = { \ + #name, methods, size, name ## _baseclasses \ +} + +/* + * Define a class inheriting two base classes. Use like this: + * + * DEFINE_CLASS2(foo, foo_class, foo_methods, sizeof(foo_softc), + * bar, baz); + */ +#define DEFINE_CLASS_2(name, methods, size, \ + base1, base2) \ + \ +static kobj_class_t name ## _baseclasses[] = \ + { &base1, \ + &base2, 0 }; \ +struct kobj_class name ## _class = { \ + #name, methods, size, name ## _baseclasses \ +} + +/* + * Define a class inheriting three base classes. Use like this: + * + * DEFINE_CLASS3(foo, foo_class, foo_methods, sizeof(foo_softc), + * bar, baz, foobar); + */ +#define DEFINE_CLASS_3(name, methods, size, \ + base1, base2, base3) \ + \ +static kobj_class_t name ## _baseclasses[] = \ + { &base1, \ + &base2, \ + &base3, 0 }; \ +struct kobj_class name ## _class = { \ + #name, methods, size, name ## _baseclasses \ +} + + +/* + * Compile the method table in a class. + */ +void kobj_class_compile(kobj_class_t cls); + +/* + * Compile the method table, with the caller providing the space for + * the ops table.(for use before malloc is initialised). + */ +void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops); + +/* + * Free the compiled method table in a class. + */ +void kobj_class_free(kobj_class_t cls); + +/* + * Allocate memory for and initialise a new object. + */ +kobj_t kobj_create(kobj_class_t cls, + struct malloc_type *mtype, + int mflags); + +/* + * Initialise a pre-allocated object. + */ +void kobj_init(kobj_t obj, kobj_class_t cls); + +/* + * Delete an object. If mtype is non-zero, free the memory. + */ +void kobj_delete(kobj_t obj, struct malloc_type *mtype); + +/* + * Maintain stats on hits/misses in lookup caches. + */ +#ifdef KOBJ_STATS +extern u_int kobj_lookup_hits; +extern u_int kobj_lookup_misses; +#endif + +/* + * Lookup the method in the cache and if it isn't there look it up the + * slow way. + */ +#ifdef KOBJ_STATS +#define KOBJOPLOOKUP(OPS,OP) do { \ + kobjop_desc_t _desc = &OP##_##desc; \ + kobj_method_t **_cep = \ + &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)]; \ + kobj_method_t *_ce = *_cep; \ + kobj_lookup_hits++; /* assume hit */ \ + if (_ce->desc != _desc) \ + _ce = kobj_lookup_method(OPS->cls, \ + _cep, _desc); \ + _m = _ce->func; \ +} while(0) +#else +#define KOBJOPLOOKUP(OPS,OP) do { \ + kobjop_desc_t _desc = &OP##_##desc; \ + kobj_method_t **_cep = \ + &OPS->cache[_desc->id & (KOBJ_CACHE_SIZE-1)]; \ + kobj_method_t *_ce = *_cep; \ + if (_ce->desc != _desc) \ + _ce = kobj_lookup_method(OPS->cls, \ + _cep, _desc); \ + _m = _ce->func; \ +} while(0) +#endif + +kobj_method_t* kobj_lookup_method(kobj_class_t cls, + kobj_method_t **cep, + kobjop_desc_t desc); + + +/* + * Default method implementation. Returns ENXIO. + */ +int kobj_error_method(void); + +#endif /* !_SYS_KOBJ_H_ */ diff --git a/src/include/sys/kse.h b/src/include/sys/kse.h new file mode 100644 index 0000000..3ed482a --- /dev/null +++ b/src/include/sys/kse.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2001 Julian Elischer + * for the FreeBSD Foundation. + * + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD: src/sys/sys/kse.h,v 1.21 2003/12/24 00:51:30 peter Exp $ + */ + +#ifndef _SYS_KSE_H_ +#define _SYS_KSE_H_ + +#include +#include +#include + +/* + * This file defines the structures needed for communication between + * the userland and the kernel when running a KSE-based threading system. + * The only programs that should see this file are the user thread + * scheduler (UTS) and the kernel. + */ +struct kse_mailbox; + +typedef void kse_func_t(struct kse_mailbox *); + +/* + * Thread mailbox. + * + * This describes a user thread to the kernel scheduler. + */ +struct kse_thr_mailbox { + ucontext_t tm_context; /* User and machine context */ + unsigned int tm_flags; /* Thread flags */ + struct kse_thr_mailbox *tm_next; /* Next thread in list */ + void *tm_udata; /* For use by the UTS */ + uint32_t tm_uticks; + uint32_t tm_sticks; + siginfo_t tm_syncsig; + int tm_spare[8]; +}; + +/* + * KSE mailbox. + * + * Communication path between the UTS and the kernel scheduler specific to + * a single KSE. + */ +struct kse_mailbox { + int km_version; /* Mailbox version */ + struct kse_thr_mailbox *km_curthread; /* Currently running thread */ + struct kse_thr_mailbox *km_completed; /* Threads back from kernel */ + sigset_t km_sigscaught; /* Caught signals */ + uint32_t km_flags; /* KSE flags */ + kse_func_t *km_func; /* UTS function */ + stack_t km_stack; /* UTS context */ + void *km_udata; /* For use by the UTS */ + struct timespec km_timeofday; /* Time of day */ + int km_quantum; /* Upcall quantum in msecs */ + int km_spare[8]; +}; + +#define KSE_VER_0 0 +#define KSE_VERSION KSE_VER_0 + +/* These flags are kept in km_flags */ +#define KMF_NOUPCALL 0x01 +#define KMF_NOCOMPLETED 0x02 +#define KMF_DONE 0x04 +#define KMF_BOUND 0x08 +#define KMF_WAITSIGEVENT 0x10 + +/* These flags are kept in tm_flags */ +#define TMF_NOUPCALL 0x01 + +/* Commands for kse_thr_interrupt */ +#define KSE_INTR_INTERRUPT 0x01 +#define KSE_INTR_RESTART 0x02 +#define KSE_INTR_SENDSIG 0x03 +#define KSE_INTR_SIGEXIT 0x04 + +#ifndef _KERNEL +int kse_create(struct kse_mailbox *, int); +int kse_exit(void); +int kse_release(struct timespec *); +int kse_thr_interrupt(struct kse_thr_mailbox *, int, long); +int kse_wakeup(struct kse_mailbox *); +int kse_switchin(mcontext_t *, long, long *); +#endif /* !_KERNEL */ + +#endif /* !_SYS_KSE_H_ */ diff --git a/src/include/sys/kthread.h b/src/include/sys/kthread.h new file mode 100644 index 0000000..fe27022 --- /dev/null +++ b/src/include/sys/kthread.h @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 1999 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/kthread.h,v 1.8 2002/10/02 07:44:28 scottl Exp $ + */ + +#ifndef _SYS_KTHREAD_H_ +#define _SYS_KTHREAD_H_ + +#include + +/*- + * A kernel process descriptor; used to start "internal" daemons. + * + * Note: global_procpp may be NULL for no global save area. + */ +struct kproc_desc { + char *arg0; /* arg 0 (for 'ps' listing) */ + void (*func)(void); /* "main" for kernel process */ + struct proc **global_procpp; /* ptr to proc ptr save area */ +}; + +void kproc_shutdown(void *, int); +void kproc_start(const void *); +int kthread_create(void (*)(void *), void *, struct proc **, + int flags, int pages, const char *, ...) __printflike(6, 7); +void kthread_exit(int) __dead2; +int kthread_resume(struct proc *); /* XXXKSE */ +int kthread_suspend(struct proc *, int); /* XXXKSE */ +void kthread_suspend_check(struct proc *); /* XXXKSE */ + +#endif /* !_SYS_KTHREAD_H_ */ diff --git a/src/include/sys/ktr.h b/src/include/sys/ktr.h new file mode 100644 index 0000000..6710ba0 --- /dev/null +++ b/src/include/sys/ktr.h @@ -0,0 +1,188 @@ +/*- + * Copyright (c) 1996 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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. + * + * from BSDI $Id$ + * $FreeBSD: src/sys/sys/ktr.h,v 1.21 2003/03/11 20:07:22 jhb Exp $ + */ + +/* + * Wraparound kernel trace buffer support. + */ + +#ifndef _SYS_KTR_H_ +#define _SYS_KTR_H_ + +/* + * Hack around due to egcs-1.1.2 not knowing what __func__ is. + */ +#ifdef __GNUC__ +#if __GNUC__ == 2 && __GNUC_MINOR__ == 91 /* egcs 1.1.2 */ +#define __func__ __FUNCTION__ +#endif +#endif + +/* + * Trace classes + */ +#define KTR_GEN 0x00000001 /* General (TR) */ +#define KTR_NET 0x00000002 /* Network */ +#define KTR_DEV 0x00000004 /* Device driver */ +#define KTR_LOCK 0x00000008 /* MP locking */ +#define KTR_SMP 0x00000010 /* MP general */ +#define KTR_FS 0x00000020 /* Filesystem */ +#define KTR_PMAP 0x00000040 /* Pmap tracing */ +#define KTR_MALLOC 0x00000080 /* Malloc tracing */ +#define KTR_TRAP 0x00000100 /* Trap processing */ +#define KTR_INTR 0x00000200 /* Interrupt tracing */ +#define KTR_SIG 0x00000400 /* Signal processing */ +#define KTR_CLK 0x00000800 /* hardclock verbose */ +#define KTR_PROC 0x00001000 /* Process scheduling */ +#define KTR_SYSC 0x00002000 /* System call */ +#define KTR_INIT 0x00004000 /* System initialization */ +#define KTR_KGDB 0x00008000 /* Trace kgdb internals */ +#define KTR_IO 0x00010000 /* Upper I/O */ +#define KTR_EVH 0x00020000 /* Eventhandler */ +#define KTR_NFS 0x00040000 /* The obvious */ +#define KTR_VOP 0x00080000 /* The obvious */ +#define KTR_VM 0x00100000 /* The virtual memory system */ +#define KTR_WITNESS 0x00200000 +#define KTR_RUNQ 0x00400000 /* Run queue */ +#define KTR_CONTENTION 0x00800000 /* Lock contention */ +#define KTR_ALL 0x00ffffff + +/* + * Trace classes which can be assigned to particular use at compile time + * These must remain in high 22 as some assembly code counts on it + */ +#define KTR_CT1 0x01000000 +#define KTR_CT2 0x02000000 +#define KTR_CT3 0x04000000 +#define KTR_CT4 0x08000000 +#define KTR_CT5 0x10000000 +#define KTR_CT6 0x20000000 +#define KTR_CT7 0x40000000 +#define KTR_CT8 0x80000000 + +/* Trace classes to compile in */ +#ifndef KTR_COMPILE +#define KTR_COMPILE (KTR_GEN) +#endif + +/* Trace classes that can not be used with KTR_ALQ */ +#define KTR_ALQ_MASK (KTR_WITNESS) + +/* + * Version number for ktr_entry struct. Increment this when you break binary + * compatibility. + */ +#define KTR_VERSION 1 + +#define KTR_PARMS 6 + +#ifndef LOCORE + +struct ktr_entry { + u_int64_t ktr_timestamp; + int ktr_cpu; + int ktr_line; + const char *ktr_file; + const char *ktr_desc; + u_long ktr_parms[KTR_PARMS]; +}; + +extern int ktr_cpumask; +extern int ktr_mask; +extern int ktr_entries; +extern int ktr_verbose; + +extern volatile int ktr_idx; +extern struct ktr_entry ktr_buf[]; + +#endif /* !LOCORE */ +#ifdef KTR + +void ktr_tracepoint(u_int mask, const char *file, int line, + const char *format, u_long arg1, u_long arg2, u_long arg3, + u_long arg4, u_long arg5, u_long arg6); + +#define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \ + if (KTR_COMPILE & (m)) \ + ktr_tracepoint((m), __FILE__, __LINE__, format, \ + (u_long)(p1), (u_long)(p2), (u_long)(p3), \ + (u_long)(p4), (u_long)(p5), (u_long)(p6)); \ + } while(0) +#define CTR0(m, format) CTR6(m, format, 0, 0, 0, 0, 0, 0) +#define CTR1(m, format, p1) CTR6(m, format, p1, 0, 0, 0, 0, 0) +#define CTR2(m, format, p1, p2) CTR6(m, format, p1, p2, 0, 0, 0, 0) +#define CTR3(m, format, p1, p2, p3) CTR6(m, format, p1, p2, p3, 0, 0, 0) +#define CTR4(m, format, p1, p2, p3, p4) CTR6(m, format, p1, p2, p3, p4, 0, 0) +#define CTR5(m, format, p1, p2, p3, p4, p5) CTR6(m, format, p1, p2, p3, p4, p5, 0) +#else /* KTR */ +#undef KTR_COMPILE +#define KTR_COMPILE 0 +#define CTR0(m, d) +#define CTR1(m, d, p1) +#define CTR2(m, d, p1, p2) +#define CTR3(m, d, p1, p2, p3) +#define CTR4(m, d, p1, p2, p3, p4) +#define CTR5(m, d, p1, p2, p3, p4, p5) +#define CTR6(m, d, p1, p2, p3, p4, p5, p6) +#endif /* KTR */ + +#define TR0(d) CTR0(KTR_GEN, d) +#define TR1(d, p1) CTR1(KTR_GEN, d, p1) +#define TR2(d, p1, p2) CTR2(KTR_GEN, d, p1, p2) +#define TR3(d, p1, p2, p3) CTR3(KTR_GEN, d, p1, p2, p3) +#define TR4(d, p1, p2, p3, p4) CTR4(KTR_GEN, d, p1, p2, p3, p4) +#define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5) +#define TR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_GEN, d, p1, p2, p3, p4, p5, p6) + +/* + * Trace initialization events, similar to CTR with KTR_INIT, but + * completely ifdef'ed out if KTR_INIT isn't in KTR_COMPILE (to + * save string space, the compiler doesn't optimize out strings + * for the conditional ones above). + */ +#if (KTR_COMPILE & KTR_INIT) != 0 +#define ITR0(d) CTR0(KTR_INIT, d) +#define ITR1(d, p1) CTR1(KTR_INIT, d, p1) +#define ITR2(d, p1, p2) CTR2(KTR_INIT, d, p1, p2) +#define ITR3(d, p1, p2, p3) CTR3(KTR_INIT, d, p1, p2, p3) +#define ITR4(d, p1, p2, p3, p4) CTR4(KTR_INIT, d, p1, p2, p3, p4) +#define ITR5(d, p1, p2, p3, p4, p5) CTR5(KTR_INIT, d, p1, p2, p3, p4, p5) +#define ITR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_INIT, d, p1, p2, p3, p4, p5, p6) +#else +#define ITR0(d) +#define ITR1(d, p1) +#define ITR2(d, p1, p2) +#define ITR3(d, p1, p2, p3) +#define ITR4(d, p1, p2, p3, p4) +#define ITR5(d, p1, p2, p3, p4, p5) +#define ITR6(d, p1, p2, p3, p4, p5, p6) +#endif + +#endif /* !_SYS_KTR_H_ */ diff --git a/src/include/sys/ktrace.h b/src/include/sys/ktrace.h new file mode 100644 index 0000000..91445c4 --- /dev/null +++ b/src/include/sys/ktrace.h @@ -0,0 +1,189 @@ +/* + * Copyright (c) 1988, 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. + * 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. + * + * @(#)ktrace.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/ktrace.h,v 1.28 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_KTRACE_H_ +#define _SYS_KTRACE_H_ + +/* + * operations to ktrace system call (KTROP(op)) + */ +#define KTROP_SET 0 /* set trace points */ +#define KTROP_CLEAR 1 /* clear trace points */ +#define KTROP_CLEARFILE 2 /* stop all tracing to file */ +#define KTROP(o) ((o)&3) /* macro to extract operation */ +/* + * flags (ORed in with operation) + */ +#define KTRFLAG_DESCEND 4 /* perform op on all children too */ + +/* + * ktrace record header + */ +struct ktr_header { + int ktr_len; /* length of buf */ + short ktr_type; /* trace record type */ + pid_t ktr_pid; /* process id */ + char ktr_comm[MAXCOMLEN+1]; /* command name */ + struct timeval ktr_time; /* timestamp */ + void *ktr_buffer; +}; + +/* + * Test for kernel trace point (MP SAFE). + * + * KTRCHECK() just checks that the type is enabled and is only for + * internal use in the ktrace subsystem. KTRPOINT() checks against + * ktrace recursion as well as checking that the type is enabled and + * is the public interface. + */ +#define KTRCHECK(td, type) ((td)->td_proc->p_traceflag & (1 << type)) +#define KTRPOINT(td, type) \ + (KTRCHECK((td), (type)) && !((td)->td_pflags & TDP_INKTRACE)) + +/* + * ktrace record types + */ + +/* + * KTR_SYSCALL - system call record + */ +#define KTR_SYSCALL 1 +struct ktr_syscall { + short ktr_code; /* syscall number */ + short ktr_narg; /* number of arguments */ + /* + * followed by ktr_narg register_t + */ + register_t ktr_args[1]; +}; + +/* + * KTR_SYSRET - return from system call record + */ +#define KTR_SYSRET 2 +struct ktr_sysret { + short ktr_code; + short ktr_eosys; + int ktr_error; + register_t ktr_retval; +}; + +/* + * KTR_NAMEI - namei record + */ +#define KTR_NAMEI 3 + /* record contains pathname */ + +/* + * KTR_GENIO - trace generic process i/o + */ +#define KTR_GENIO 4 +struct ktr_genio { + int ktr_fd; + enum uio_rw ktr_rw; + /* + * followed by data successfully read/written + */ +}; + +/* + * KTR_PSIG - trace processed signal + */ +#define KTR_PSIG 5 +struct ktr_psig { + int signo; + sig_t action; + int code; + sigset_t mask; +}; + +/* + * KTR_CSW - trace context switches + */ +#define KTR_CSW 6 +struct ktr_csw { + int out; /* 1 if switch out, 0 if switch in */ + int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */ +}; + +/* + * KTR_USER - data comming from userland + */ +#define KTR_USER_MAXLEN 2048 /* maximum length of passed data */ +#define KTR_USER 7 + +/* + * KTR_DROP - If this bit is set in ktr_type, then at least one event + * between the previous record and this record was dropped. + */ +#define KTR_DROP 0x8000 + +/* + * kernel trace points (in p_traceflag) + */ +#define KTRFAC_MASK 0x00ffffff +#define KTRFAC_SYSCALL (1< + +__BEGIN_DECLS +int ktrace(const char *, int, int, pid_t); +int utrace(const void *, size_t); +__END_DECLS + +#endif + +#endif diff --git a/src/include/sys/libkern.h b/src/include/sys/libkern.h new file mode 100644 index 0000000..057b0f2 --- /dev/null +++ b/src/include/sys/libkern.h @@ -0,0 +1,139 @@ +/*- + * Copyright (c) 1992, 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. + * 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. + * + * @(#)libkern.h 8.1 (Berkeley) 6/10/93 + * $FreeBSD: src/sys/sys/libkern.h,v 1.45 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_LIBKERN_H_ +#define _SYS_LIBKERN_H_ + +#include +#include +#ifdef _KERNEL +#include +#endif + +/* BCD conversions. */ +extern u_char const bcd2bin_data[]; +extern u_char const bin2bcd_data[]; +extern char const hex2ascii_data[]; + +#define bcd2bin(bcd) (bcd2bin_data[bcd]) +#define bin2bcd(bin) (bin2bcd_data[bin]) +#define hex2ascii(hex) (hex2ascii_data[hex]) + +static __inline int imax(int a, int b) { return (a > b ? a : b); } +static __inline int imin(int a, int b) { return (a < b ? a : b); } +static __inline long lmax(long a, long b) { return (a > b ? a : b); } +static __inline long lmin(long a, long b) { return (a < b ? a : b); } +static __inline u_int max(u_int a, u_int b) { return (a > b ? a : b); } +static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } +static __inline quad_t qmax(quad_t a, quad_t b) { return (a > b ? a : b); } +static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); } +static __inline u_long ulmax(u_long a, u_long b) { return (a > b ? a : b); } +static __inline u_long ulmin(u_long a, u_long b) { return (a < b ? a : b); } + +static __inline int abs(int a) { return (a < 0 ? -a : a); } +static __inline long labs(long a) { return (a < 0 ? -a : a); } +static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); } + +/* Prototypes for non-quad routines. */ +struct malloc_type; +uint32_t arc4random(void); +void arc4rand(void *ptr, u_int len, int reseed); +int bcmp(const void *, const void *, size_t); +void *bsearch(const void *, const void *, size_t, + size_t, int (*)(const void *, const void *)); +#ifndef HAVE_INLINE_FFS +int ffs(int); +#endif +#ifndef HAVE_INLINE_FFSL +int ffsl(long); +#endif +#ifndef HAVE_INLINE_FLS +int fls(int); +#endif +#ifndef HAVE_INLINE_FLSL +int flsl(long); +#endif +int fnmatch(const char *, const char *, int); +int locc(int, char *, u_int); +void qsort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)); +u_long random(void); +char *index(const char *, int); +char *rindex(const char *, int); +int scanc(u_int, const u_char *, const u_char *, int); +int skpc(int, int, char *); +void srandom(u_long); +char *strcat(char * __restrict, const char * __restrict); +int strcmp(const char *, const char *); +char *strcpy(char * __restrict, const char * __restrict); +char *strdup(const char *__restrict, struct malloc_type *); +size_t strlcat(char *, const char *, size_t); +size_t strlcpy(char *, const char *, size_t); +size_t strlen(const char *); +int strncmp(const char *, const char *, size_t); +char *strncpy(char * __restrict, const char * __restrict, size_t); +char *strsep(char **, const char *delim); +int strvalid(const char *, size_t); + + +static __inline int +memcmp(const void *b1, const void *b2, size_t len) +{ + return (bcmp(b1, b2, len)); +} + +static __inline void * +memset(void *b, int c, size_t len) +{ + char *bb; + + if (c == 0) + bzero(b, len); + else + for (bb = (char *)b; len--; ) + *bb++ = c; + return (b); +} + +/* fnmatch() return values. */ +#define FNM_NOMATCH 1 /* Match failed. */ + +/* fnmatch() flags. */ +#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ +#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ +#define FNM_PERIOD 0x04 /* Period must be matched by period. */ +#define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME + +#endif /* !_SYS_LIBKERN_H_ */ diff --git a/src/include/sys/limits.h b/src/include/sys/limits.h new file mode 100644 index 0000000..3d8fb49 --- /dev/null +++ b/src/include/sys/limits.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 1988, 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. + * 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. + * + * $FreeBSD: src/sys/sys/limits.h,v 1.8 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_LIMITS_H_ +#define _SYS_LIMITS_H_ + +#include +#include + +#define CHAR_BIT __CHAR_BIT /* number of bits in a char */ + +#define SCHAR_MAX __SCHAR_MAX /* max value for a signed char */ +#define SCHAR_MIN __SCHAR_MIN /* min value for a signed char */ + +#define UCHAR_MAX __UCHAR_MAX /* max value for an unsigned char */ + +#ifdef __CHAR_UNSIGNED__ +#define CHAR_MAX UCHAR_MAX /* max value for a char */ +#define CHAR_MIN 0 /* min value for a char */ +#else +#define CHAR_MAX SCHAR_MAX +#define CHAR_MIN SCHAR_MIN +#endif + +#define USHRT_MAX __USHRT_MAX /* max value for an unsigned short */ +#define SHRT_MAX __SHRT_MAX /* max value for a short */ +#define SHRT_MIN __SHRT_MIN /* min value for a short */ + +#define UINT_MAX __UINT_MAX /* max value for an unsigned int */ +#define INT_MAX __INT_MAX /* max value for an int */ +#define INT_MIN __INT_MIN /* min value for an int */ + +#define ULONG_MAX __ULONG_MAX /* max for an unsigned long */ +#define LONG_MAX __LONG_MAX /* max for a long */ +#define LONG_MIN __LONG_MIN /* min for a long */ + +#ifdef __LONG_LONG_SUPPORTED +#define ULLONG_MAX __ULLONG_MAX /* max for an unsigned long long */ +#define LLONG_MAX __LLONG_MAX /* max for a long long */ +#define LLONG_MIN __LLONG_MIN /* min for a long long */ +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SSIZE_MAX __SSIZE_MAX /* max value for an ssize_t */ +#endif + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#define SIZE_T_MAX __SIZE_T_MAX /* max value for a size_t */ + +#define OFF_MAX __OFF_MAX /* max value for an off_t */ +#define OFF_MIN __OFF_MIN /* min value for an off_t */ +#endif + +#if __BSD_VISIBLE +#define GID_MAX UINT_MAX /* max value for a gid_t */ +#define UID_MAX UINT_MAX /* max value for a uid_t */ + +#define UQUAD_MAX (__UQUAD_MAX) /* max value for a uquad_t */ +#define QUAD_MAX (__QUAD_MAX) /* max value for a quad_t */ +#define QUAD_MIN (__QUAD_MIN) /* min value for a quad_t */ +#endif + +#if __XSI_VISIBLE +#define LONG_BIT __LONG_BIT +#define WORD_BIT __WORD_BIT +#endif + +#endif /* !_SYS_LIMITS_H_ */ diff --git a/src/include/sys/link_aout.h b/src/include/sys/link_aout.h new file mode 100644 index 0000000..3fefa55 --- /dev/null +++ b/src/include/sys/link_aout.h @@ -0,0 +1,288 @@ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/link_aout.h,v 1.24 2002/08/22 20:35:23 peter Exp $ + */ + +/* + * RRS section definitions. + * + * The layout of some data structures defined in this header file is + * such that we can provide compatibility with the SunOS 4.x shared + * library scheme. + */ + +#ifndef _SYS_LINK_AOUT_H_ +#define _SYS_LINK_AOUT_H_ + +struct dl_info; + +/* + * A `Shared Object Descriptor' describes a shared object that is needed + * to complete the link edit process of the object containing it. + * A list of such objects (chained through `sod_next') is pointed at + * by `sdt_sods' in the section_dispatch_table structure. + */ + +struct sod { /* Shared Object Descriptor */ + long sod_name; /* name (relative to load address) */ + u_int sod_library : 1, /* Searched for by library rules */ + sod_reserved : 31; + short sod_major; /* major version number */ + short sod_minor; /* minor version number */ + long sod_next; /* next sod */ +}; + +/* + * `Shared Object Map's are used by the run-time link editor (ld.so) to + * keep track of all shared objects loaded into a process' address space. + * These structures are only used at run-time and do not occur within + * the text or data segment of an executable or shared library. + */ +struct so_map { /* Shared Object Map */ + caddr_t som_addr; /* Address at which object mapped */ + char *som_path; /* Path to mmap'ed file */ + struct so_map *som_next; /* Next map in chain */ + struct sod *som_sod; /* Sod responsible for this map */ + caddr_t som_sodbase; /* Base address of this sod */ + u_int som_write : 1; /* Text is currently writable */ + struct _dynamic *som_dynamic; /* _dynamic structure */ + caddr_t som_spd; /* Private data */ +}; + +/* + * Symbol description with size. This is simply an `nlist' with + * one field (nz_size) added. + * Used to convey size information on items in the data segment + * of shared objects. An array of these live in the shared object's + * text segment and is addressed by the `sdt_nzlist' field. + */ +struct nzlist { + struct nlist nlist; + u_long nz_size; +}; + +#define nz_un nlist.n_un +#define nz_strx nlist.n_un.n_strx +#define nz_name nlist.n_un.n_name +#define nz_type nlist.n_type +#define nz_value nlist.n_value +#define nz_desc nlist.n_desc +#define nz_other nlist.n_other + +/* + * The `section_dispatch_table' structure contains offsets to various data + * structures needed to do run-time relocation. + */ +struct section_dispatch_table { + struct so_map *sdt_loaded; /* List of loaded objects */ + long sdt_sods; /* List of shared objects descriptors */ + long sdt_paths; /* Library search paths */ + long sdt_got; /* Global offset table */ + long sdt_plt; /* Procedure linkage table */ + long sdt_rel; /* Relocation table */ + long sdt_hash; /* Symbol hash table */ + long sdt_nzlist; /* Symbol table itself */ + long sdt_filler2; /* Unused (was: stab_hash) */ + long sdt_buckets; /* Number of hash buckets */ + long sdt_strings; /* Symbol strings */ + long sdt_str_sz; /* Size of symbol strings */ + long sdt_text_sz; /* Size of text area */ + long sdt_plt_sz; /* Size of procedure linkage table */ +}; + +/* + * RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table. + * Used to quickly lookup symbols of the shared object by hashing + * on the symbol's name. `rh_symbolnum' is the index of the symbol + * in the shared object's symbol list (`sdt_nzlist'), `rh_next' is + * the next symbol in the hash bucket (in case of collisions). + */ +struct rrs_hash { + int rh_symbolnum; /* Symbol number */ + int rh_next; /* Next hash entry */ +}; + +/* + * `rt_symbols' is used to keep track of run-time allocated commons + * and data items copied from shared objects. + */ +struct rt_symbol { + struct nzlist *rt_sp; /* The symbol */ + struct rt_symbol *rt_next; /* Next in linear list */ + struct rt_symbol *rt_link; /* Next in bucket */ + caddr_t rt_srcaddr; /* Address of "master" copy */ + struct so_map *rt_smp; /* Originating map */ +}; + +/* + * Debugger interface structure. + */ +struct so_debug { + int dd_version; /* Version # of interface */ + int dd_in_debugger; /* Set when run by debugger */ + int dd_sym_loaded; /* Run-time linking brought more + symbols into scope */ + char *dd_bpt_addr; /* Address of rtld-generated bpt */ + int dd_bpt_shadow; /* Original contents of bpt */ + struct rt_symbol *dd_cc; /* Allocated commons/copied data */ +}; + +/* + * Version returned to crt0 from ld.so + */ +#define LDSO_VERSION_NONE 0 /* FreeBSD2.0, 2.0.5 */ +#define LDSO_VERSION_HAS_DLEXIT 1 /* includes dlexit in ld_entry */ +#define LDSO_VERSION_HAS_DLSYM3 2 /* includes 3-argument dlsym */ +#define LDSO_VERSION_HAS_DLADDR 3 /* includes dladdr in ld_entry */ + +/* + * Entry points into ld.so - user interface to the run-time linker. + * Entries are valid for the given version numbers returned by ld.so + * to crt0. + */ +struct ld_entry { + void *(*dlopen)(const char *, int); /* NONE */ + int (*dlclose)(void *); /* NONE */ + void *(*dlsym)(void *, const char *); /* NONE */ + const char *(*dlerror)(void); /* NONE */ + void (*dlexit)(void); /* HAS_DLEXIT */ + void *(*dlsym3)(void *, const char *, void *); /* HAS_DLSYM3 */ + int (*dladdr)(const void *, struct dl_info *); /* HAS_DLADDR */ +}; + +/* + * This is the structure pointed at by the __DYNAMIC symbol if an + * executable requires the attention of the run-time link editor. + * __DYNAMIC is given the value zero if no run-time linking needs to + * be done (it is always present in shared objects). + * The union `d_un' provides for different versions of the dynamic + * linking mechanism (switched on by `d_version'). The last version + * used by Sun is 3. We leave some room here and go to version number + * 8 for NetBSD, the main difference lying in the support for the + * `nz_list' type of symbols. + */ + +struct _dynamic { + int d_version; /* version # of this interface */ + struct so_debug *d_debug; + union { + struct section_dispatch_table *d_sdt; + } d_un; + struct ld_entry *d_entry; /* XXX */ +}; + +#define LD_VERSION_SUN (3) +#define LD_VERSION_BSD (8) +#define LD_VERSION_NZLIST_P(v) ((v) >= 8) + +#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got) +#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt) +#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel) +#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist) +#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash) +#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings) +#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods) +#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets) +#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths) + +#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got) +#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel) +#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash) +#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist) +#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz) +#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz) +#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz) + +/* + * Interface to ld.so + */ +struct crt_ldso { + int crt_ba; /* Base address of ld.so */ + int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */ + int crt_ldfd; /* ld.so file descriptor */ + struct _dynamic *crt_dp; /* Main's __DYNAMIC */ + char **crt_ep; /* environment strings */ + caddr_t crt_bp; /* Breakpoint if run from debugger */ + char *crt_prog; /* Program name (v3) */ + char *crt_ldso; /* Link editor name (v4) */ + struct ld_entry *crt_ldentry; /* dl*() access (v4) */ + char **crt_argv; /* argument strings (v5) */ +}; + +/* + * Version passed from crt0 to ld.so (1st argument to _rtld()). + */ +#define CRT_VERSION_SUN 1 +#define CRT_VERSION_BSD_2 2 +#define CRT_VERSION_BSD_3 3 +#define CRT_VERSION_BSD_4 4 +#define CRT_VERSION_BSD_5 5 + +/* + * Maximum number of recognized shared object version numbers. + */ +#define MAXDEWEY 8 + +/* + * Header of the hints file. + */ +struct hints_header { + long hh_magic; +#define HH_MAGIC 011421044151 + long hh_version; /* Interface version number */ +#define LD_HINTS_VERSION_1 1 +#define LD_HINTS_VERSION_2 2 + long hh_hashtab; /* Location of hash table */ + long hh_nbucket; /* Number of buckets in hashtab */ + long hh_strtab; /* Location of strings */ + long hh_strtab_sz; /* Size of strings */ + long hh_ehints; /* End of hints (max offset in file) */ + long hh_dirlist; /* Colon-separated list of srch dirs */ +}; + +#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) + +/* + * Hash table element in hints file. + */ +struct hints_bucket { + /* namex and pathx are indices into the string table */ + int hi_namex; /* Library name */ + int hi_pathx; /* Full path */ + int hi_dewey[MAXDEWEY]; /* The versions */ + int hi_ndewey; /* Number of version numbers */ +#define hi_major hi_dewey[0] +#define hi_minor hi_dewey[1] + int hi_next; /* Next in this bucket */ +}; + +#define _PATH_LD_HINTS "/var/run/ld.so.hints" + +#endif /* _SYS_LINK_AOUT_H_ */ diff --git a/src/include/sys/link_elf.h b/src/include/sys/link_elf.h new file mode 100644 index 0000000..8395a72 --- /dev/null +++ b/src/include/sys/link_elf.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/link_elf.h,v 1.25 2003/02/13 17:47:44 kan Exp $ + */ + +/* + * RRS section definitions. + * + * The layout of some data structures defined in this header file is + * such that we can provide compatibility with the SunOS 4.x shared + * library scheme. + */ + +#ifndef _SYS_LINK_ELF_H_ +#define _SYS_LINK_ELF_H_ + +#include + +/* + * Flags that describe the origin of the entries in Dl_serinfo. + * SunOS has these in , we follow the suit. + */ +#define LA_SER_ORIG 0x01 /* original (needed) name */ +#define LA_SER_LIBPATH 0x02 /* LD_LIBRARY_PATH entry prepended */ +#define LA_SER_RUNPATH 0x04 /* runpath entry prepended */ +#define LA_SER_CONFIG 0x08 /* configuration entry prepended */ +#define LA_SER_DEFAULT 0x40 /* default path prepended */ +#define LA_SER_SECURE 0x80 /* default (secure) path prepended */ + +typedef struct link_map { + caddr_t l_addr; /* Base Address of library */ +#ifdef __mips__ + caddr_t l_offs; /* Load Offset of library */ +#endif + const char *l_name; /* Absolute Path to Library */ + const void *l_ld; /* Pointer to .dynamic in memory */ + struct link_map *l_next, *l_prev; /* linked list of of mapped libs */ +} Link_map; + +struct r_debug { + int r_version; /* not used */ + struct link_map *r_map; /* list of loaded images */ + void (*r_brk)(struct r_debug *, struct link_map *); + /* pointer to break point */ + enum { + RT_CONSISTENT, /* things are stable */ + RT_ADD, /* adding a shared library */ + RT_DELETE /* removing a shared library */ + } r_state; +}; + +#endif /* _SYS_LINK_ELF_H_ */ diff --git a/src/include/sys/linker.h b/src/include/sys/linker.h new file mode 100644 index 0000000..8228a49 --- /dev/null +++ b/src/include/sys/linker.h @@ -0,0 +1,294 @@ +/*- + * Copyright (c) 1997-2000 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/linker.h,v 1.37 2004/05/16 20:00:28 peter Exp $ + */ + +#ifndef _SYS_LINKER_H_ +#define _SYS_LINKER_H_ + +#ifdef _KERNEL + +#include +#include + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_LINKER); +#endif + +struct mod_depend; + +/* + * Object representing a file which has been loaded by the linker. + */ +typedef struct linker_file* linker_file_t; +typedef TAILQ_HEAD(, linker_file) linker_file_list_t; + +typedef caddr_t linker_sym_t; /* opaque symbol */ +typedef c_caddr_t c_linker_sym_t; /* const opaque symbol */ +typedef int (*linker_function_name_callback_t)(const char *, void *); + +/* + * expanded out linker_sym_t + */ +typedef struct linker_symval { + const char* name; + caddr_t value; + size_t size; +} linker_symval_t; + +struct common_symbol { + STAILQ_ENTRY(common_symbol) link; + char* name; + caddr_t address; +}; + +struct linker_file { + KOBJ_FIELDS; + int refs; /* reference count */ + int userrefs; /* kldload(2) count */ + int flags; +#define LINKER_FILE_LINKED 0x1 /* file has been fully linked */ + TAILQ_ENTRY(linker_file) link; /* list of all loaded files */ + char* filename; /* file which was loaded */ + int id; /* unique id */ + caddr_t address; /* load address */ + size_t size; /* size of file */ + int ndeps; /* number of dependencies */ + linker_file_t* deps; /* list of dependencies */ + STAILQ_HEAD(, common_symbol) common; /* list of common symbols */ + TAILQ_HEAD(, module) modules; /* modules in this file */ + TAILQ_ENTRY(linker_file) loaded; /* preload dependency support */ +}; + +/* + * Object implementing a class of file (a.out, elf, etc.) + */ +typedef struct linker_class *linker_class_t; +typedef TAILQ_HEAD(, linker_class) linker_class_list_t; + +struct linker_class { + KOBJ_CLASS_FIELDS; + TAILQ_ENTRY(linker_class) link; /* list of all file classes */ +}; + +/* + * The "file" for the kernel. + */ +extern linker_file_t linker_kernel_file; + +/* + * Add a new file class to the linker. + */ +int linker_add_class(linker_class_t _cls); + +/* + * Load a kernel module. + */ +int linker_load_module(const char *_kldname, const char *_modname, + struct linker_file *_parent, struct mod_depend *_verinfo, + struct linker_file **_lfpp); + +/* + * Obtain a reference to a module, loading it if required. + */ +int linker_reference_module(const char* _modname, struct mod_depend *_verinfo, + linker_file_t* _result); + +/* + * Find a currently loaded file given its filename. + */ +linker_file_t linker_find_file_by_name(const char* _filename); + +/* + * Find a currently loaded file given its file id. + */ +linker_file_t linker_find_file_by_id(int _fileid); + +/* + * Called from a class handler when a file is laoded. + */ +linker_file_t linker_make_file(const char* _filename, linker_class_t _cls); + +/* + * Unload a file, freeing up memory. + */ +int linker_file_unload(linker_file_t _file); + +/* + * Add a dependency to a file. + */ +int linker_file_add_dependency(linker_file_t _file, linker_file_t _dep); + +/* + * Lookup a symbol in a file. If deps is TRUE, look in dependencies + * if not found in file. + */ +caddr_t linker_file_lookup_symbol(linker_file_t _file, const char* _name, + int _deps); + +/* + * Lookup a linker set in a file. Return pointers to the first entry, + * last + 1, and count of entries. Use: for (p = start; p < stop; p++) {} + * void *start is really: "struct yoursetmember ***start;" + */ +int linker_file_lookup_set(linker_file_t _file, const char *_name, + void *_start, void *_stop, int *_count); + +/* + * This routine is responsible for finding dependencies of userland + * initiated kldload(2)'s of files. + */ +int linker_load_dependencies(linker_file_t _lf); + +/* + * DDB Helpers, tuned specifically for ddb/db_kld.c + */ +int linker_ddb_lookup(const char *_symstr, c_linker_sym_t *_sym); +int linker_ddb_search_symbol(caddr_t _value, c_linker_sym_t *_sym, + long *_diffp); +int linker_ddb_symbol_values(c_linker_sym_t _sym, linker_symval_t *_symval); + + +#endif /* _KERNEL */ + +/* + * Module information subtypes + */ +#define MODINFO_END 0x0000 /* End of list */ +#define MODINFO_NAME 0x0001 /* Name of module (string) */ +#define MODINFO_TYPE 0x0002 /* Type of module (string) */ +#define MODINFO_ADDR 0x0003 /* Loaded address */ +#define MODINFO_SIZE 0x0004 /* Size of module */ +#define MODINFO_EMPTY 0x0005 /* Has been deleted */ +#define MODINFO_ARGS 0x0006 /* Parameters string */ +#define MODINFO_METADATA 0x8000 /* Module-specfic */ + +#define MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */ +#define MODINFOMD_ELFHDR 0x0002 /* ELF header */ +#define MODINFOMD_SSYM 0x0003 /* start of symbols */ +#define MODINFOMD_ESYM 0x0004 /* end of symbols */ +#define MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */ +/* These values are MD on these two platforms */ +#if !defined(__sparc64__) && !defined(__powerpc__) +#define MODINFOMD_ENVP 0x0006 /* envp[] */ +#define MODINFOMD_HOWTO 0x0007 /* boothowto */ +#define MODINFOMD_KERNEND 0x0008 /* kernend */ +#endif +#define MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */ + +#define MODINFOMD_DEPLIST (0x4001 | MODINFOMD_NOCOPY) /* depends on */ + +#ifdef _KERNEL +#define MD_FETCH(mdp, info, type) ({ \ + type *__p; \ + __p = (type *)preload_search_info((mdp), MODINFO_METADATA | (info)); \ + __p ? *__p : 0; \ +}) +#endif + +#define LINKER_HINTS_VERSION 1 /* linker.hints file version */ + +#ifdef _KERNEL + +/* + * Module lookup + */ +extern caddr_t preload_metadata; +extern caddr_t preload_search_by_name(const char *_name); +extern caddr_t preload_search_by_type(const char *_type); +extern caddr_t preload_search_next_name(caddr_t _base); +extern caddr_t preload_search_info(caddr_t _mod, int _inf); +extern void preload_delete_name(const char *_name); +extern void preload_bootstrap_relocate(vm_offset_t _offset); + +#ifdef KLD_DEBUG + +extern int kld_debug; +#define KLD_DEBUG_FILE 1 /* file load/unload */ +#define KLD_DEBUG_SYM 2 /* symbol lookup */ + +#define KLD_DPF(cat, args) \ + do { \ + if (kld_debug & KLD_DEBUG_##cat) printf args; \ + } while (0) + +#else + +#define KLD_DPF(cat, args) + +#endif + +typedef Elf_Addr elf_lookup_fn(linker_file_t, Elf_Word, int); + +/* Support functions */ +int elf_reloc(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu); +int elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu); +const Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Word _symidx); +const char *elf_get_symname(linker_file_t _lf, Elf_Word _symidx); + +int elf_cpu_load_file(linker_file_t); +int elf_cpu_unload_file(linker_file_t); + +/* values for type */ +#define ELF_RELOC_REL 1 +#define ELF_RELOC_RELA 2 + +#endif /* _KERNEL */ + +struct kld_file_stat { + int version; /* set to sizeof(linker_file_stat) */ + char name[MAXPATHLEN]; + int refs; + int id; + caddr_t address; /* load address */ + size_t size; /* size in bytes */ +}; + +struct kld_sym_lookup { + int version; /* set to sizeof(struct kld_sym_lookup) */ + char *symname; /* Symbol name we are looking up */ + u_long symvalue; + size_t symsize; +}; +#define KLDSYM_LOOKUP 1 + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int kldload(const char* _file); +int kldunload(int _fileid); +int kldfind(const char* _file); +int kldnext(int _fileid); +int kldstat(int _fileid, struct kld_file_stat* _stat); +int kldfirstmod(int _fileid); +int kldsym(int _fileid, int _cmd, void *_data); +__END_DECLS + +#endif + +#endif /* !_SYS_LINKER_H_ */ diff --git a/src/include/sys/linker_set.h b/src/include/sys/linker_set.h new file mode 100644 index 0000000..08bc93d --- /dev/null +++ b/src/include/sys/linker_set.h @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 1999 John D. Polstra + * Copyright (c) 1999,2001 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/linker_set.h,v 1.14 2004/03/12 21:45:32 trhodes Exp $ + */ + +#ifndef _SYS_LINKER_SET_H_ +#define _SYS_LINKER_SET_H_ + +/* + * The following macros are used to declare global sets of objects, which + * are collected by the linker into a `linker_set' as defined below. + * For ELF, this is done by constructing a separate segment for each set. + */ + +/* + * Private macros, not to be used outside this header file. + */ +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#define __MAKE_SET(set, sym) \ + static void const * const __set_##set##_sym_##sym \ + __section("set_" #set) __unused = &sym +#else /* !(__GNUC__ || __INTEL_COMPILER) */ +#ifndef lint +#error "This file needs to be compiled by GCC, an Intel compiler or lint" +#endif /* lint */ +#define __MAKE_SET(set, sym) extern void const * const (__set_##set##_sym_##sym) +#endif /* __GNUC__ || __INTEL_COMPILER */ + +/* + * Public macros. + */ +#define TEXT_SET(set, sym) __MAKE_SET(set, sym) +#define DATA_SET(set, sym) __MAKE_SET(set, sym) +#define BSS_SET(set, sym) __MAKE_SET(set, sym) +#define ABS_SET(set, sym) __MAKE_SET(set, sym) +#define SET_ENTRY(set, sym) __MAKE_SET(set, sym) + +/* + * Initialize before referring to a give linker set + */ +#define SET_DECLARE(set, ptype) \ + extern ptype *__CONCAT(__start_set_,set); \ + extern ptype *__CONCAT(__stop_set_,set) + +#define SET_BEGIN(set) \ + (&__CONCAT(__start_set_,set)) +#define SET_LIMIT(set) \ + (&__CONCAT(__stop_set_,set)) + +/* + * Iterate over all the elements of a set. + * + * Sets always contain addresses of things, and "pvar" points to words + * containing those addresses. Thus is must be declared as "type **pvar", + * and the address of each set item is obtained inside the loop by "*pvar". + */ +#define SET_FOREACH(pvar, set) \ + for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) + +#define SET_ITEM(set, i) \ + ((SET_BEGIN(set))[i]) + +/* + * Provide a count of the items in a set. + */ +#define SET_COUNT(set) \ + (SET_LIMIT(set) - SET_BEGIN(set)) + +#endif /* _SYS_LINKER_SET_H_ */ diff --git a/src/include/sys/lock.h b/src/include/sys/lock.h new file mode 100644 index 0000000..df610ac --- /dev/null +++ b/src/include/sys/lock.h @@ -0,0 +1,300 @@ +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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. + * + * from BSDI $Id$ + * $FreeBSD: src/sys/sys/lock.h,v 1.50 2004/01/28 20:39:57 jhb Exp $ + */ + +#ifndef _SYS_LOCK_H_ +#define _SYS_LOCK_H_ + +#include +#include + +struct thread; + +/* + * Lock classes. Each lock has a class which describes characteristics + * common to all types of locks of a given class. + * + * Spin locks in general must always protect against preemption, as it is + * an error to perform any type of context switch while holding a spin lock. + * Also, for an individual lock to be recursable, its class must allow + * recursion and the lock itself must explicitly allow recursion. + */ + +struct lock_class { + const char *lc_name; + u_int lc_flags; +}; + +#define LC_SLEEPLOCK 0x00000001 /* Sleep lock. */ +#define LC_SPINLOCK 0x00000002 /* Spin lock. */ +#define LC_SLEEPABLE 0x00000004 /* Sleeping allowed with this lock. */ +#define LC_RECURSABLE 0x00000008 /* Locks of this type may recurse. */ +#define LC_UPGRADABLE 0x00000010 /* Upgrades and downgrades permitted. */ + +#define LO_CLASSFLAGS 0x0000ffff /* Class specific flags. */ +#define LO_INITIALIZED 0x00010000 /* Lock has been initialized. */ +#define LO_WITNESS 0x00020000 /* Should witness monitor this lock. */ +#define LO_QUIET 0x00040000 /* Don't log locking operations. */ +#define LO_RECURSABLE 0x00080000 /* Lock may recurse. */ +#define LO_SLEEPABLE 0x00100000 /* Lock may be held while sleeping. */ +#define LO_UPGRADABLE 0x00200000 /* Lock may be upgraded/downgraded. */ +#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */ + +#define LI_RECURSEMASK 0x0000ffff /* Recursion depth of lock instance. */ +#define LI_EXCLUSIVE 0x00010000 /* Exclusive lock instance. */ + +/* + * Option flags passed to lock operations that witness also needs to know + * about or that are generic across all locks. + */ +#define LOP_NEWORDER 0x00000001 /* Define a new lock order. */ +#define LOP_QUIET 0x00000002 /* Don't log locking operations. */ +#define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */ +#define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */ + +/* Flags passed to witness_assert. */ +#define LA_UNLOCKED 0x00000000 /* Lock is unlocked. */ +#define LA_LOCKED 0x00000001 /* Lock is at least share locked. */ +#define LA_SLOCKED 0x00000002 /* Lock is exactly share locked. */ +#define LA_XLOCKED 0x00000004 /* Lock is exclusively locked. */ +#define LA_RECURSED 0x00000008 /* Lock is recursed. */ +#define LA_NOTRECURSED 0x00000010 /* Lock is not recursed. */ + +#ifdef _KERNEL +/* + * Lock instances. A lock instance is the data associated with a lock while + * it is held by witness. For example, a lock instance will hold the + * recursion count of a lock. Lock instances are held in lists. Spin locks + * are held in a per-cpu list while sleep locks are held in per-process list. + */ +struct lock_instance { + struct lock_object *li_lock; + const char *li_file; /* File and line of last acquire. */ + int li_line; + u_int li_flags; /* Recursion count and LI_* flags. */ +}; + +/* + * A simple list type used to build the list of locks held by a process + * or CPU. We can't simply embed the list in struct lock_object since a + * lock may be held by more than one process if it is a shared lock. Locks + * are added to the head of the list, so we fill up each list entry from + * "the back" logically. To ease some of the arithmetic, we actually fill + * in each list entry the normal way (childer[0] then children[1], etc.) but + * when we traverse the list we read children[count-1] as the first entry + * down to children[0] as the final entry. + */ +#define LOCK_NCHILDREN 3 + +struct lock_list_entry { + struct lock_list_entry *ll_next; + struct lock_instance ll_children[LOCK_NCHILDREN]; + u_int ll_count; +}; + +/* + * If any of WITNESS, INVARIANTS, or KTR_LOCK KTR tracing has been enabled, + * then turn on LOCK_DEBUG. When this option is on, extra debugging + * facilities such as tracking the file and line number of lock operations + * are enabled. Also, mutex locking operations are not inlined to avoid + * bloat from all the extra debugging code. We also have to turn on all the + * calling conventions for this debugging code in modules so that modules can + * work with both debug and non-debug kernels. + */ +#if defined(KLD_MODULE) || defined(WITNESS) || defined(INVARIANTS) || defined(INVARIANT_SUPPORT) || defined(KTR) || defined(MUTEX_PROFILING) +#define LOCK_DEBUG 1 +#else +#define LOCK_DEBUG 0 +#endif + +/* + * In the LOCK_DEBUG case, use the filename and line numbers for debugging + * operations. Otherwise, use default values to avoid the unneeded bloat. + */ +#if LOCK_DEBUG > 0 +#define LOCK_FILE __FILE__ +#define LOCK_LINE __LINE__ +#else +#define LOCK_FILE NULL +#define LOCK_LINE 0 +#endif + +/* + * Macros for KTR_LOCK tracing. + * + * opname - name of this operation (LOCK/UNLOCK/SLOCK, etc.) + * lo - struct lock_object * for this lock + * flags - flags passed to the lock operation + * recurse - this locks recursion level (or 0 if class is not recursable) + * result - result of a try lock operation + * file - file name + * line - line number + */ +#define LOCK_LOG_TEST(lo, flags) \ + (((flags) & LOP_QUIET) == 0 && ((lo)->lo_flags & LO_QUIET) == 0) + +#define LOCK_LOG_LOCK(opname, lo, flags, recurse, file, line) do { \ + if (LOCK_LOG_TEST((lo), (flags))) \ + CTR5(KTR_LOCK, opname " (%s) %s r = %d at %s:%d", \ + (lo)->lo_class->lc_name, (lo)->lo_name, \ + (u_int)(recurse), (file), (line)); \ +} while (0) + +#define LOCK_LOG_TRY(opname, lo, flags, result, file, line) do { \ + if (LOCK_LOG_TEST((lo), (flags))) \ + CTR5(KTR_LOCK, "TRY_" opname " (%s) %s result=%d at %s:%d",\ + (lo)->lo_class->lc_name, (lo)->lo_name, \ + (u_int)(result), (file), (line)); \ +} while (0) + +#define LOCK_LOG_INIT(lo, flags) do { \ + if (LOCK_LOG_TEST((lo), (flags))) \ + CTR4(KTR_LOCK, "%s: %p (%s) %s", __func__, (lo), \ + (lo)->lo_class->lc_name, (lo)->lo_name); \ +} while (0) + +#define LOCK_LOG_DESTROY(lo, flags) LOCK_LOG_INIT(lo, flags) + +/* + * Helpful macros for quickly coming up with assertions with informative + * panic messages. + */ +#define MPASS(ex) MPASS4(ex, #ex, __FILE__, __LINE__) +#define MPASS2(ex, what) MPASS4(ex, what, __FILE__, __LINE__) +#define MPASS3(ex, file, line) MPASS4(ex, #ex, file, line) +#define MPASS4(ex, what, file, line) \ + KASSERT((ex), ("Assertion %s failed at %s:%d", what, file, line)) + +extern struct lock_class lock_class_mtx_sleep; +extern struct lock_class lock_class_mtx_spin; +extern struct lock_class lock_class_sx; + +void witness_init(struct lock_object *); +void witness_destroy(struct lock_object *); +int witness_defineorder(struct lock_object *, struct lock_object *); +void witness_checkorder(struct lock_object *, int, const char *, int); +void witness_lock(struct lock_object *, int, const char *, int); +void witness_upgrade(struct lock_object *, int, const char *, int); +void witness_downgrade(struct lock_object *, int, const char *, int); +void witness_unlock(struct lock_object *, int, const char *, int); +void witness_save(struct lock_object *, const char **, int *); +void witness_restore(struct lock_object *, const char *, int); +int witness_list_locks(struct lock_list_entry **); +int witness_warn(int, struct lock_object *, const char *, ...); +void witness_assert(struct lock_object *, int, const char *, int); +void witness_display_spinlock(struct lock_object *, struct thread *); +int witness_line(struct lock_object *); +const char *witness_file(struct lock_object *); + +#ifdef WITNESS + +/* Flags for witness_warn(). */ +#define WARN_GIANTOK 0x01 /* Giant is exempt from this check. */ +#define WARN_PANIC 0x02 /* Panic if check fails. */ +#define WARN_SLEEPOK 0x04 /* Sleepable locks are exempt from check. */ + +#define WITNESS_INIT(lock) \ + witness_init((lock)) + +#define WITNESS_DESTROY(lock) \ + witness_destroy(lock) + +#define WITNESS_CHECKORDER(lock, flags, file, line) \ + witness_checkorder((lock), (flags), (file), (line)) + +#define WITNESS_DEFINEORDER(lock1, lock2) \ + witness_defineorder((struct lock_object *)(lock1), \ + (struct lock_object *)(lock2)) + +#define WITNESS_LOCK(lock, flags, file, line) \ + witness_lock((lock), (flags), (file), (line)) + +#define WITNESS_UPGRADE(lock, flags, file, line) \ + witness_upgrade((lock), (flags), (file), (line)) + +#define WITNESS_DOWNGRADE(lock, flags, file, line) \ + witness_downgrade((lock), (flags), (file), (line)) + +#define WITNESS_UNLOCK(lock, flags, file, line) \ + witness_unlock((lock), (flags), (file), (line)) + +#define WITNESS_WARN(flags, lock, fmt, ...) \ + witness_warn((flags), (lock), (fmt), ## __VA_ARGS__) + +#define WITNESS_SAVE_DECL(n) \ + const char * __CONCAT(n, __wf); \ + int __CONCAT(n, __wl) + +#define WITNESS_SAVE(lock, n) \ + witness_save((lock), &__CONCAT(n, __wf), &__CONCAT(n, __wl)) + +#define WITNESS_RESTORE(lock, n) \ + witness_restore((lock), __CONCAT(n, __wf), __CONCAT(n, __wl)) + +#define WITNESS_FILE(lock) \ + witness_file(lock) + +#define WITNESS_LINE(lock) \ + witness_line(lock) + +#else /* WITNESS */ +#define WITNESS_INIT(lock) ((lock)->lo_flags |= LO_INITIALIZED) +#define WITNESS_DESTROY(lock) ((lock)->lo_flags &= ~LO_INITIALIZED) +#define WITNESS_DEFINEORDER(lock1, lock2) 0 +#define WITNESS_CHECKORDER(lock, flags, file, line) +#define WITNESS_LOCK(lock, flags, file, line) +#define WITNESS_UPGRADE(lock, flags, file, line) +#define WITNESS_DOWNGRADE(lock, flags, file, line) +#define WITNESS_UNLOCK(lock, flags, file, line) +#define WITNESS_WARN(flags, lock, fmt, ...) +#define WITNESS_SAVE_DECL(n) +#define WITNESS_SAVE(lock, n) +#define WITNESS_RESTORE(lock, n) +#define WITNESS_FILE(lock) ("?") +#define WITNESS_LINE(lock) (0) +#endif /* WITNESS */ + +/* + * Helper macros to allow developers to add explicit lock order checks + * wherever they please without having to actually grab a lock to do so. + */ +#define witness_check_mutex(m) \ + WITNESS_CHECKORDER(&(m)->mtx_object, LOP_EXCLUSIVE, LOCK_FILE, \ + LOCK_LINE) + +#define witness_check_shared_sx(sx) \ + WITNESS_CHECKORDER(&(sx)->sx_object, 0, LOCK_FILE, LOCK_LINE) + +#define witness_check_exclusive_sx(sx) \ + WITNESS_CHECKORDER(&(sx)->sx_object, LOP_EXCLUSIVE, LOCK_FILE, \ + LOCK_LINE) + +#endif /* _KERNEL */ +#endif /* _SYS_LOCK_H_ */ diff --git a/src/include/sys/lockf.h b/src/include/sys/lockf.h new file mode 100644 index 0000000..b7f87c2 --- /dev/null +++ b/src/include/sys/lockf.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Scooter Morris at Genentech Inc. + * + * 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. + * 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. + * + * @(#)lockf.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD: src/sys/sys/lockf.h,v 1.16 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_LOCKF_H_ +#define _SYS_LOCKF_H_ + +#include + +struct vop_advlock_args; + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_LOCKF); +#endif + +/* + * The lockf structure is a kernel structure which contains the information + * associated with a byte range lock. The lockf structures are linked into + * the inode structure. Locks are sorted by the starting byte of the lock for + * efficiency. + */ +TAILQ_HEAD(locklist, lockf); + +struct lockf { + short lf_flags; /* Semantics: F_POSIX, F_FLOCK, F_WAIT */ + short lf_type; /* Lock type: F_RDLCK, F_WRLCK */ + off_t lf_start; /* Byte # of the start of the lock */ + off_t lf_end; /* Byte # of the end of the lock (-1=EOF) */ + caddr_t lf_id; /* Id of the resource holding the lock */ + struct lockf **lf_head; /* Back pointer to the head of the locf list */ + struct inode *lf_inode; /* Back pointer to the inode */ + struct lockf *lf_next; /* Pointer to the next lock on this inode */ + struct locklist lf_blkhd; /* List of requests blocked on this lock */ + TAILQ_ENTRY(lockf) lf_block;/* A request waiting for a lock */ +}; + +/* Maximum length of sleep chains to traverse to try and detect deadlock. */ +#define MAXDEPTH 50 + +int lf_advlock(struct vop_advlock_args *, struct lockf **, u_quad_t); + +#ifdef LOCKF_DEBUG +void lf_print(char *, struct lockf *); +void lf_printlist(char *, struct lockf *); +#endif + +#endif /* !_SYS_LOCKF_H_ */ diff --git a/src/include/sys/lockmgr.h b/src/include/sys/lockmgr.h new file mode 100644 index 0000000..dfb01b5 --- /dev/null +++ b/src/include/sys/lockmgr.h @@ -0,0 +1,226 @@ +/* + * Copyright (c) 1995 + * The Regents of the University of California. All rights reserved. + * + * This code contains ideas from software contributed to Berkeley by + * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating + * System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * @(#)lock.h 8.12 (Berkeley) 5/19/95 + * $FreeBSD: src/sys/sys/lockmgr.h,v 1.40 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_LOCKMGR_H_ +#define _SYS_LOCKMGR_H_ + +struct mtx; + +/* + * The general lock structure. Provides for multiple shared locks, + * upgrading from shared to exclusive, and sleeping until the lock + * can be gained. + */ +struct lock { + struct mtx *lk_interlock; /* lock on remaining fields */ + u_int lk_flags; /* see below */ + int lk_sharecount; /* # of accepted shared locks */ + int lk_waitcount; /* # of processes sleeping for lock */ + short lk_exclusivecount; /* # of recursive exclusive locks */ + short lk_prio; /* priority at which to sleep */ + const char *lk_wmesg; /* resource sleeping (for tsleep) */ + int lk_timo; /* maximum sleep time (for tsleep) */ + struct thread *lk_lockholder; /* thread of exclusive lock holder */ + struct lock *lk_newlock; /* lock taking over this lock */ +#ifdef DEBUG_LOCKS + const char *lk_filename; + const char *lk_lockername; + int lk_lineno; + + struct thread *lk_slockholder; + const char *lk_sfilename; + const char *lk_slockername; + int lk_slineno; +#endif +}; +/* + * Lock request types: + * LK_SHARED - get one of many possible shared locks. If a process + * holding an exclusive lock requests a shared lock, the exclusive + * lock(s) will be downgraded to shared locks. + * LK_EXCLUSIVE - stop further shared locks, when they are cleared, + * grant a pending upgrade if it exists, then grant an exclusive + * lock. Only one exclusive lock may exist at a time, except that + * a process holding an exclusive lock may get additional exclusive + * locks if it explicitly sets the LK_CANRECURSE flag in the lock + * request, or if the LK_CANRECUSE flag was set when the lock was + * initialized. + * LK_UPGRADE - the process must hold a shared lock that it wants to + * have upgraded to an exclusive lock. Other processes may get + * exclusive access to the resource between the time that the upgrade + * is requested and the time that it is granted. + * LK_EXCLUPGRADE - the process must hold a shared lock that it wants to + * have upgraded to an exclusive lock. If the request succeeds, no + * other processes will have gotten exclusive access to the resource + * between the time that the upgrade is requested and the time that + * it is granted. However, if another process has already requested + * an upgrade, the request will fail (see error returns below). + * LK_DOWNGRADE - the process must hold an exclusive lock that it wants + * to have downgraded to a shared lock. If the process holds multiple + * (recursive) exclusive locks, they will all be downgraded to shared + * locks. + * LK_RELEASE - release one instance of a lock. + * LK_DRAIN - wait for all activity on the lock to end, then mark it + * decommissioned. This feature is used before freeing a lock that + * is part of a piece of memory that is about to be freed. + * LK_EXCLOTHER - return for lockstatus(). Used when another process + * holds the lock exclusively. + * + * These are flags that are passed to the lockmgr routine. + */ +#define LK_TYPE_MASK 0x0000000f /* type of lock sought */ +#define LK_SHARED 0x00000001 /* shared lock */ +#define LK_EXCLUSIVE 0x00000002 /* exclusive lock */ +#define LK_UPGRADE 0x00000003 /* shared-to-exclusive upgrade */ +#define LK_EXCLUPGRADE 0x00000004 /* first shared-to-exclusive upgrade */ +#define LK_DOWNGRADE 0x00000005 /* exclusive-to-shared downgrade */ +#define LK_RELEASE 0x00000006 /* release any type of lock */ +#define LK_DRAIN 0x00000007 /* wait for all lock activity to end */ +#define LK_EXCLOTHER 0x00000008 /* other process holds lock */ +/* + * External lock flags. + * + * The first three flags may be set in lock_init to set their mode permanently, + * or passed in as arguments to the lock manager. The LK_REENABLE flag may be + * set only at the release of a lock obtained by drain. + */ +#define LK_EXTFLG_MASK 0x03000070 /* mask of external flags */ +#define LK_NOWAIT 0x00000010 /* do not sleep to await lock */ +#define LK_SLEEPFAIL 0x00000020 /* sleep, then return failure */ +#define LK_CANRECURSE 0x00000040 /* allow recursive exclusive lock */ +#define LK_REENABLE 0x00000080 /* lock is be reenabled after drain */ +#define LK_NOPAUSE 0x01000000 /* no spinloop */ +#define LK_TIMELOCK 0x02000000 /* use lk_timo, else no timeout */ +/* + * Internal lock flags. + * + * These flags are used internally to the lock manager. + */ +#define LK_WANT_UPGRADE 0x00000100 /* waiting for share-to-excl upgrade */ +#define LK_WANT_EXCL 0x00000200 /* exclusive lock sought */ +#define LK_HAVE_EXCL 0x00000400 /* exclusive lock obtained */ +#define LK_WAITDRAIN 0x00000800 /* process waiting for lock to drain */ +#define LK_DRAINING 0x00004000 /* lock is being drained */ +/* + * Control flags + * + * Non-persistent external flags. + */ +#define LK_INTERLOCK 0x00010000 /* + * unlock passed mutex after getting + * lk_interlock + */ +#define LK_RETRY 0x00020000 /* vn_lock: retry until locked */ +#define LK_THISLAYER 0x00040000 /* vn_lock: lock/unlock only current layer */ +#define LK_INTERNAL 0x00080000/* The internal lock is already held */ + +/* + * Internal state flags corresponding to lk_sharecount, and lk_waitcount + */ +#define LK_SHARE_NONZERO 0x00100000 +#define LK_WAIT_NONZERO 0x00200000 + +/* + * Lock return status. + * + * Successfully obtained locks return 0. Locks will always succeed + * unless one of the following is true: + * LK_FORCEUPGRADE is requested and some other process has already + * requested a lock upgrade (returns EBUSY). + * LK_WAIT is set and a sleep would be required (returns EBUSY). + * LK_SLEEPFAIL is set and a sleep was done (returns ENOLCK). + * PCATCH is set in lock priority and a signal arrives (returns + * either EINTR or ERESTART if system calls is to be restarted). + * Non-null lock timeout and timeout expires (returns EWOULDBLOCK). + * A failed lock attempt always returns a non-zero error value. No lock + * is held after an error return (in particular, a failed LK_UPGRADE + * or LK_FORCEUPGRADE will have released its shared access lock). + */ + +/* + * Indicator that no process holds exclusive lock + */ +#define LK_KERNPROC ((struct thread *)-2) +#define LK_NOPROC ((struct thread *) -1) + +#ifdef INVARIANTS +#define LOCKMGR_ASSERT(lkp, what, p) do { \ + switch ((what)) { \ + case LK_SHARED: \ + if (lockstatus((lkp), (p)) == LK_SHARED) \ + break; \ + /* fall into exclusive */ \ + case LK_EXCLUSIVE: \ + if (lockstatus((lkp), (p)) != LK_EXCLUSIVE) \ + panic("lock %s %s not held at %s:%d", \ + (lkp)->lk_wmesg, #what, __FILE__, \ + __LINE__); \ + break; \ + default: \ + panic("unknown LOCKMGR_ASSERT at %s:%d", __FILE__, \ + __LINE__); \ + } \ +} while (0) +#else /* INVARIANTS */ +#define LOCKMGR_ASSERT(lkp, p, what) +#endif /* INVARIANTS */ + +void dumplockinfo(struct lock *lkp); +struct thread; + +void lockinit(struct lock *, int prio, const char *wmesg, + int timo, int flags); +void lockdestroy(struct lock *); + +#ifdef DEBUG_LOCKS +int debuglockmgr(struct lock *, u_int flags, + struct mtx *, struct thread *p, + const char *, + const char *, + int); +#define lockmgr(lockp, flags, slockp, proc) \ + debuglockmgr((lockp), (flags), (slockp), (proc), \ + "lockmgr", __FILE__, __LINE__) +#else +int lockmgr(struct lock *, u_int flags, + struct mtx *, struct thread *p); +#endif +void transferlockers(struct lock *, struct lock *); +void lockmgr_printinfo(struct lock *); +int lockstatus(struct lock *, struct thread *); +int lockcount(struct lock *); + +#endif /* !_SYS_LOCKMGR_H_ */ diff --git a/src/include/sys/mac.h b/src/include/sys/mac.h new file mode 100644 index 0000000..6c19685 --- /dev/null +++ b/src/include/sys/mac.h @@ -0,0 +1,367 @@ +/*- + * Copyright (c) 1999-2002 Robert N. M. Watson + * Copyright (c) 2001-2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * This software was developed for the FreeBSD Project in part by Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), + * as part of the DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/mac.h,v 1.57 2004/05/10 18:38:07 rwatson Exp $ + */ +/* + * Userland/kernel interface for Mandatory Access Control. + * + * The POSIX.1e implementation page may be reached at: + * http://www.trustedbsd.org/ + */ +#ifndef _SYS_MAC_H_ +#define _SYS_MAC_H_ + +#include + +#ifndef _POSIX_MAC +#define _POSIX_MAC +#endif + +/* + * MAC framework-related constants and limits. + */ +#define MAC_MAX_POLICY_NAME 32 +#define MAC_MAX_LABEL_ELEMENT_NAME 32 +#define MAC_MAX_LABEL_ELEMENT_DATA 4096 +#define MAC_MAX_LABEL_BUF_LEN 8192 + +struct mac { + size_t m_buflen; + char *m_string; +}; + +typedef struct mac *mac_t; + +#ifndef _KERNEL + +/* + * Location of the userland MAC framework configuration file. mac.conf + * binds policy names to shared libraries that understand those policies, + * as well as setting defaults for MAC-aware applications. + */ +#define MAC_CONFFILE "/etc/mac.conf" + +/* + * Extended non-POSIX.1e interfaces that offer additional services + * available from the userland and kernel MAC frameworks. + */ +__BEGIN_DECLS +int mac_execve(char *fname, char **argv, char **envv, mac_t _label); +int mac_free(mac_t _label); +int mac_from_text(mac_t *_label, const char *_text); +int mac_get_fd(int _fd, mac_t _label); +int mac_get_file(const char *_path, mac_t _label); +int mac_get_link(const char *_path, mac_t _label); +int mac_get_peer(int _fd, mac_t _label); +int mac_get_pid(pid_t _pid, mac_t _label); +int mac_get_proc(mac_t _label); +int mac_is_present(const char *_policyname); +int mac_prepare(mac_t *_label, const char *_elements); +int mac_prepare_file_label(mac_t *_label); +int mac_prepare_ifnet_label(mac_t *_label); +int mac_prepare_process_label(mac_t *_label); +int mac_prepare_type(mac_t *_label, const char *_type); +int mac_set_fd(int _fildes, const mac_t _label); +int mac_set_file(const char *_path, mac_t _label); +int mac_set_link(const char *_path, mac_t _label); +int mac_set_proc(const mac_t _label); +int mac_syscall(const char *_policyname, int _call, void *_arg); +int mac_to_text(mac_t mac, char **_text); +__END_DECLS + +#else /* _KERNEL */ + +/* + * Kernel functions to manage and evaluate labels. + */ +struct bpf_d; +struct componentname; +struct devfs_dirent; +struct ifnet; +struct ifreq; +struct inpcb; +struct image_params; +struct inpcb; +struct ipq; +struct m_tag; +struct mbuf; +struct mount; +struct proc; +struct sockaddr; +struct socket; +struct sysctl_oid; +struct sysctl_req; +struct pipepair; +struct thread; +struct timespec; +struct ucred; +struct uio; +struct vattr; +struct vnode; + +#include /* XXX acl_type_t */ + +struct vop_setlabel_args; + +/* + * Label operations. + */ +void mac_init_bpfdesc(struct bpf_d *); +void mac_init_cred(struct ucred *); +void mac_init_devfsdirent(struct devfs_dirent *); +void mac_init_ifnet(struct ifnet *); +int mac_init_inpcb(struct inpcb *, int flag); +int mac_init_ipq(struct ipq *, int flag); +int mac_init_socket(struct socket *, int flag); +void mac_init_pipe(struct pipepair *); +int mac_init_mbuf(struct mbuf *mbuf, int flag); +int mac_init_mbuf_tag(struct m_tag *, int flag); +void mac_init_mount(struct mount *); +void mac_init_proc(struct proc *); +void mac_init_vnode(struct vnode *); +void mac_copy_mbuf_tag(struct m_tag *, struct m_tag *); +void mac_copy_vnode_label(struct label *, struct label *label); +void mac_destroy_bpfdesc(struct bpf_d *); +void mac_destroy_cred(struct ucred *); +void mac_destroy_devfsdirent(struct devfs_dirent *); +void mac_destroy_ifnet(struct ifnet *); +void mac_destroy_inpcb(struct inpcb *); +void mac_destroy_ipq(struct ipq *); +void mac_destroy_socket(struct socket *); +void mac_destroy_pipe(struct pipepair *); +void mac_destroy_proc(struct proc *); +void mac_destroy_mbuf_tag(struct m_tag *); +void mac_destroy_mount(struct mount *); +void mac_destroy_vnode(struct vnode *); + +struct label *mac_cred_label_alloc(void); +void mac_cred_label_free(struct label *label); +struct label *mac_vnode_label_alloc(void); +void mac_vnode_label_free(struct label *label); + +/* + * Labeling event operations: file system objects, and things that + * look a lot like file system objects. + */ +void mac_associate_vnode_devfs(struct mount *mp, struct devfs_dirent *de, + struct vnode *vp); +int mac_associate_vnode_extattr(struct mount *mp, struct vnode *vp); +void mac_associate_vnode_singlelabel(struct mount *mp, struct vnode *vp); +void mac_create_devfs_device(struct mount *mp, dev_t dev, + struct devfs_dirent *de); +void mac_create_devfs_directory(struct mount *mp, char *dirname, + int dirnamelen, struct devfs_dirent *de); +void mac_create_devfs_symlink(struct ucred *cred, struct mount *mp, + struct devfs_dirent *dd, struct devfs_dirent *de); +int mac_create_vnode_extattr(struct ucred *cred, struct mount *mp, + struct vnode *dvp, struct vnode *vp, struct componentname *cnp); +void mac_create_mount(struct ucred *cred, struct mount *mp); +void mac_create_root_mount(struct ucred *cred, struct mount *mp); +void mac_relabel_vnode(struct ucred *cred, struct vnode *vp, + struct label *newlabel); +void mac_update_devfsdirent(struct mount *mp, struct devfs_dirent *de, + struct vnode *vp); + +/* + * Labeling event operations: IPC objects. + */ +void mac_create_mbuf_from_socket(struct socket *so, struct mbuf *m); +void mac_create_socket(struct ucred *cred, struct socket *socket); +void mac_create_socket_from_socket(struct socket *oldsocket, + struct socket *newsocket); +void mac_set_socket_peer_from_mbuf(struct mbuf *mbuf, + struct socket *socket); +void mac_set_socket_peer_from_socket(struct socket *oldsocket, + struct socket *newsocket); +void mac_create_pipe(struct ucred *cred, struct pipepair *pp); + +/* + * Labeling event operations: network objects. + */ +void mac_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d); +void mac_create_ifnet(struct ifnet *ifp); +void mac_create_inpcb_from_socket(struct socket *so, struct inpcb *inp); +void mac_create_ipq(struct mbuf *fragment, struct ipq *ipq); +void mac_create_datagram_from_ipq(struct ipq *ipq, struct mbuf *datagram); +void mac_create_fragment(struct mbuf *datagram, struct mbuf *fragment); +void mac_create_mbuf_from_inpcb(struct inpcb *inp, struct mbuf *m); +void mac_create_mbuf_from_mbuf(struct mbuf *oldmbuf, struct mbuf *newmbuf); +void mac_create_mbuf_linklayer(struct ifnet *ifnet, struct mbuf *m); +void mac_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct mbuf *m); +void mac_create_mbuf_from_ifnet(struct ifnet *ifnet, struct mbuf *m); +void mac_create_mbuf_multicast_encap(struct mbuf *oldmbuf, + struct ifnet *ifnet, struct mbuf *newmbuf); +void mac_create_mbuf_netlayer(struct mbuf *oldmbuf, struct mbuf *newmbuf); +int mac_fragment_match(struct mbuf *fragment, struct ipq *ipq); +void mac_reflect_mbuf_icmp(struct mbuf *m); +void mac_reflect_mbuf_tcp(struct mbuf *m); +void mac_update_ipq(struct mbuf *fragment, struct ipq *ipq); +void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp); + +/* + * Labeling event operations: processes. + */ +void mac_copy_cred(struct ucred *cr1, struct ucred *cr2); +int mac_execve_enter(struct image_params *imgp, struct mac *mac_p); +void mac_execve_exit(struct image_params *imgp); +void mac_execve_transition(struct ucred *old, struct ucred *new, + struct vnode *vp, struct label *interpvnodelabel, + struct image_params *imgp); +int mac_execve_will_transition(struct ucred *old, struct vnode *vp, + struct label *interpvnodelabel, struct image_params *imgp); +void mac_create_proc0(struct ucred *cred); +void mac_create_proc1(struct ucred *cred); +void mac_thread_userret(struct thread *td); + +/* Access control checks. */ +int mac_check_bpfdesc_receive(struct bpf_d *bpf_d, struct ifnet *ifnet); +int mac_check_cred_visible(struct ucred *u1, struct ucred *u2); +int mac_check_ifnet_transmit(struct ifnet *ifnet, struct mbuf *m); +int mac_check_inpcb_deliver(struct inpcb *inp, struct mbuf *m); +int mac_check_kenv_dump(struct ucred *cred); +int mac_check_kenv_get(struct ucred *cred, char *name); +int mac_check_kenv_set(struct ucred *cred, char *name, char *value); +int mac_check_kenv_unset(struct ucred *cred, char *name); +int mac_check_kld_load(struct ucred *cred, struct vnode *vp); +int mac_check_kld_stat(struct ucred *cred); +int mac_check_kld_unload(struct ucred *cred); +int mac_check_mount_stat(struct ucred *cred, struct mount *mp); +int mac_check_pipe_ioctl(struct ucred *cred, struct pipepair *pp, + unsigned long cmd, void *data); +int mac_check_pipe_poll(struct ucred *cred, struct pipepair *pp); +int mac_check_pipe_read(struct ucred *cred, struct pipepair *pp); +int mac_check_pipe_stat(struct ucred *cred, struct pipepair *pp); +int mac_check_pipe_write(struct ucred *cred, struct pipepair *pp); +int mac_check_proc_debug(struct ucred *cred, struct proc *proc); +int mac_check_proc_sched(struct ucred *cred, struct proc *proc); +int mac_check_proc_signal(struct ucred *cred, struct proc *proc, + int signum); +int mac_check_socket_bind(struct ucred *cred, struct socket *so, + struct sockaddr *sockaddr); +int mac_check_socket_connect(struct ucred *cred, struct socket *so, + struct sockaddr *sockaddr); +int mac_check_socket_deliver(struct socket *so, struct mbuf *m); +int mac_check_socket_listen(struct ucred *cred, struct socket *so); +int mac_check_socket_receive(struct ucred *cred, struct socket *so); +int mac_check_socket_send(struct ucred *cred, struct socket *so); +int mac_check_socket_visible(struct ucred *cred, struct socket *so); +int mac_check_sysarch_ioperm(struct ucred *cred); +int mac_check_system_acct(struct ucred *cred, struct vnode *vp); +int mac_check_system_nfsd(struct ucred *cred); +int mac_check_system_reboot(struct ucred *cred, int howto); +int mac_check_system_settime(struct ucred *cred); +int mac_check_system_swapon(struct ucred *cred, struct vnode *vp); +int mac_check_system_swapoff(struct ucred *cred, struct vnode *vp); +int mac_check_system_sysctl(struct ucred *cred, struct sysctl_oid *oidp, + void *arg1, int arg2, struct sysctl_req *req); +int mac_check_vnode_access(struct ucred *cred, struct vnode *vp, + int acc_mode); +int mac_check_vnode_chdir(struct ucred *cred, struct vnode *dvp); +int mac_check_vnode_chroot(struct ucred *cred, struct vnode *dvp); +int mac_check_vnode_create(struct ucred *cred, struct vnode *dvp, + struct componentname *cnp, struct vattr *vap); +int mac_check_vnode_delete(struct ucred *cred, struct vnode *dvp, + struct vnode *vp, struct componentname *cnp); +int mac_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, + acl_type_t type); +int mac_check_vnode_deleteextattr(struct ucred *cred, struct vnode *vp, + int attrnamespace, const char *name); +int mac_check_vnode_exec(struct ucred *cred, struct vnode *vp, + struct image_params *imgp); +int mac_check_vnode_getacl(struct ucred *cred, struct vnode *vp, + acl_type_t type); +int mac_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, + int attrnamespace, const char *name, struct uio *uio); +int mac_check_vnode_link(struct ucred *cred, struct vnode *dvp, + struct vnode *vp, struct componentname *cnp); +int mac_check_vnode_listextattr(struct ucred *cred, struct vnode *vp, + int attrnamespace); +int mac_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, + struct componentname *cnp); +int mac_check_vnode_mmap(struct ucred *cred, struct vnode *vp, + int prot); +int mac_check_vnode_mprotect(struct ucred *cred, struct vnode *vp, + int prot); +int mac_check_vnode_open(struct ucred *cred, struct vnode *vp, + int acc_mode); +int mac_check_vnode_poll(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp); +int mac_check_vnode_read(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp); +int mac_check_vnode_readdir(struct ucred *cred, struct vnode *vp); +int mac_check_vnode_readlink(struct ucred *cred, struct vnode *vp); +int mac_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, + struct vnode *vp, struct componentname *cnp); +int mac_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, + struct vnode *vp, int samedir, struct componentname *cnp); +int mac_check_vnode_revoke(struct ucred *cred, struct vnode *vp); +int mac_check_vnode_setacl(struct ucred *cred, struct vnode *vp, + acl_type_t type, struct acl *acl); +int mac_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, + int attrnamespace, const char *name, struct uio *uio); +int mac_check_vnode_setflags(struct ucred *cred, struct vnode *vp, + u_long flags); +int mac_check_vnode_setmode(struct ucred *cred, struct vnode *vp, + mode_t mode); +int mac_check_vnode_setowner(struct ucred *cred, struct vnode *vp, + uid_t uid, gid_t gid); +int mac_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, + struct timespec atime, struct timespec mtime); +int mac_check_vnode_stat(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp); +int mac_check_vnode_write(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp); +int mac_getsockopt_label(struct ucred *cred, struct socket *so, + struct mac *extmac); +int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so, + struct mac *extmac); +int mac_ioctl_ifnet_get(struct ucred *cred, struct ifreq *ifr, + struct ifnet *ifnet); +int mac_ioctl_ifnet_set(struct ucred *cred, struct ifreq *ifr, + struct ifnet *ifnet); +int mac_setsockopt_label(struct ucred *cred, struct socket *so, + struct mac *extmac); +int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp, + struct label *label); +void mac_cred_mmapped_drop_perms(struct thread *td, struct ucred *cred); + +/* + * Calls to help various file systems implement labeling functionality + * using their existing EA implementation. + */ +int vop_stdsetlabel_ea(struct vop_setlabel_args *ap); + +#endif /* !_KERNEL */ + +#endif /* !_SYS_MAC_H_ */ diff --git a/src/include/sys/mac_policy.h b/src/include/sys/mac_policy.h new file mode 100644 index 0000000..aff235e --- /dev/null +++ b/src/include/sys/mac_policy.h @@ -0,0 +1,505 @@ +/*- + * Copyright (c) 1999-2002 Robert N. M. Watson + * Copyright (c) 2001-2004 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed by Robert Watson for the TrustedBSD Project. + * + * This software was developed for the FreeBSD Project in part by Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), + * as part of the DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/mac_policy.h,v 1.53 2004/05/10 18:38:07 rwatson Exp $ + */ +/* + * Kernel interface for MAC policy modules. + */ +#ifndef _SYS_MAC_POLICY_H_ +#define _SYS_MAC_POLICY_H_ + +/*- + * Pluggable access control policy definition structure. + * + * List of operations that are performed as part of the implementation + * of a MAC policy. Policy implementors declare operations with a + * mac_policy_ops structure, and using the MAC_POLICY_SET() macro. + * If an entry point is not declared, then then the policy will be ignored + * during evaluation of that event or check. + * + * Operations are sorted first by general class of operation, then + * alphabetically. + */ +struct acl; +struct bpf_d; +struct componentname; +struct devfs_dirent; +struct ifnet; +struct image_params; +struct inpcb; +struct ipq; +struct label; +struct mac_policy_conf; +struct mbuf; +struct mount; +struct pipepair; +struct proc; +struct sbuf; +struct sockaddr; +struct socket; +struct sysctl_oid; +struct sysctl_req; +struct thread; +struct ucred; +struct uio; +struct vattr; +struct vnode; +struct mac_policy_ops { + /* + * Policy module operations. + */ + void (*mpo_destroy)(struct mac_policy_conf *mpc); + void (*mpo_init)(struct mac_policy_conf *mpc); + + /* + * General policy-directed security system call so that policies + * may implement new services without reserving explicit + * system call numbers. + */ + int (*mpo_syscall)(struct thread *td, int call, void *arg); + + /* + * Label operations. + */ + void (*mpo_init_bpfdesc_label)(struct label *label); + void (*mpo_init_cred_label)(struct label *label); + void (*mpo_init_devfsdirent_label)(struct label *label); + void (*mpo_init_ifnet_label)(struct label *label); + int (*mpo_init_inpcb_label)(struct label *label, int flag); + int (*mpo_init_ipq_label)(struct label *label, int flag); + int (*mpo_init_mbuf_label)(struct label *label, int flag); + void (*mpo_init_mount_label)(struct label *label); + void (*mpo_init_mount_fs_label)(struct label *label); + int (*mpo_init_socket_label)(struct label *label, int flag); + int (*mpo_init_socket_peer_label)(struct label *label, int flag); + void (*mpo_init_pipe_label)(struct label *label); + void (*mpo_init_proc_label)(struct label *label); + void (*mpo_init_vnode_label)(struct label *label); + void (*mpo_destroy_bpfdesc_label)(struct label *label); + void (*mpo_destroy_cred_label)(struct label *label); + void (*mpo_destroy_devfsdirent_label)(struct label *label); + void (*mpo_destroy_ifnet_label)(struct label *label); + void (*mpo_destroy_inpcb_label)(struct label *label); + void (*mpo_destroy_ipq_label)(struct label *label); + void (*mpo_destroy_mbuf_label)(struct label *label); + void (*mpo_destroy_mount_label)(struct label *label); + void (*mpo_destroy_mount_fs_label)(struct label *label); + void (*mpo_destroy_socket_label)(struct label *label); + void (*mpo_destroy_socket_peer_label)(struct label *label); + void (*mpo_destroy_pipe_label)(struct label *label); + void (*mpo_destroy_proc_label)(struct label *label); + void (*mpo_destroy_vnode_label)(struct label *label); + void (*mpo_copy_cred_label)(struct label *src, + struct label *dest); + void (*mpo_copy_mbuf_label)(struct label *src, + struct label *dest); + void (*mpo_copy_pipe_label)(struct label *src, + struct label *dest); + void (*mpo_copy_socket_label)(struct label *src, + struct label *dest); + void (*mpo_copy_vnode_label)(struct label *src, + struct label *dest); + int (*mpo_externalize_cred_label)(struct label *label, + char *element_name, struct sbuf *sb, int *claimed); + int (*mpo_externalize_ifnet_label)(struct label *label, + char *element_name, struct sbuf *sb, int *claimed); + int (*mpo_externalize_pipe_label)(struct label *label, + char *element_name, struct sbuf *sb, int *claimed); + int (*mpo_externalize_socket_label)(struct label *label, + char *element_name, struct sbuf *sb, int *claimed); + int (*mpo_externalize_socket_peer_label)(struct label *label, + char *element_name, struct sbuf *sb, int *claimed); + int (*mpo_externalize_vnode_label)(struct label *label, + char *element_name, struct sbuf *sb, int *claimed); + int (*mpo_internalize_cred_label)(struct label *label, + char *element_name, char *element_data, int *claimed); + int (*mpo_internalize_ifnet_label)(struct label *label, + char *element_name, char *element_data, int *claimed); + int (*mpo_internalize_pipe_label)(struct label *label, + char *element_name, char *element_data, int *claimed); + int (*mpo_internalize_socket_label)(struct label *label, + char *element_name, char *element_data, int *claimed); + int (*mpo_internalize_vnode_label)(struct label *label, + char *element_name, char *element_data, int *claimed); + + /* + * Labeling event operations: file system objects, and things that + * look a lot like file system objects. + */ + void (*mpo_associate_vnode_devfs)(struct mount *mp, + struct label *fslabel, struct devfs_dirent *de, + struct label *delabel, struct vnode *vp, + struct label *vlabel); + int (*mpo_associate_vnode_extattr)(struct mount *mp, + struct label *fslabel, struct vnode *vp, + struct label *vlabel); + void (*mpo_associate_vnode_singlelabel)(struct mount *mp, + struct label *fslabel, struct vnode *vp, + struct label *vlabel); + void (*mpo_create_devfs_device)(struct mount *mp, dev_t dev, + struct devfs_dirent *de, struct label *label); + void (*mpo_create_devfs_directory)(struct mount *mp, char *dirname, + int dirnamelen, struct devfs_dirent *de, + struct label *label); + void (*mpo_create_devfs_symlink)(struct ucred *cred, + struct mount *mp, struct devfs_dirent *dd, + struct label *ddlabel, struct devfs_dirent *de, + struct label *delabel); + int (*mpo_create_vnode_extattr)(struct ucred *cred, + struct mount *mp, struct label *fslabel, + struct vnode *dvp, struct label *dlabel, + struct vnode *vp, struct label *vlabel, + struct componentname *cnp); + void (*mpo_create_mount)(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel); + void (*mpo_create_root_mount)(struct ucred *cred, struct mount *mp, + struct label *mountlabel, struct label *fslabel); + void (*mpo_relabel_vnode)(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *label); + int (*mpo_setlabel_vnode_extattr)(struct ucred *cred, + struct vnode *vp, struct label *vlabel, + struct label *intlabel); + void (*mpo_update_devfsdirent)(struct mount *mp, + struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, + struct label *vnodelabel); + + /* + * Labeling event operations: IPC objects. + */ + void (*mpo_create_mbuf_from_socket)(struct socket *so, + struct label *socketlabel, struct mbuf *m, + struct label *mbuflabel); + void (*mpo_create_socket)(struct ucred *cred, struct socket *so, + struct label *socketlabel); + void (*mpo_create_socket_from_socket)(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketlabel); + void (*mpo_relabel_socket)(struct ucred *cred, struct socket *so, + struct label *oldlabel, struct label *newlabel); + void (*mpo_relabel_pipe)(struct ucred *cred, struct pipepair *pp, + struct label *oldlabel, struct label *newlabel); + void (*mpo_set_socket_peer_from_mbuf)(struct mbuf *mbuf, + struct label *mbuflabel, struct socket *so, + struct label *socketpeerlabel); + void (*mpo_set_socket_peer_from_socket)(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketpeerlabel); + void (*mpo_create_pipe)(struct ucred *cred, struct pipepair *pp, + struct label *pipelabel); + + /* + * Labeling event operations: network objects. + */ + void (*mpo_create_bpfdesc)(struct ucred *cred, struct bpf_d *bpf_d, + struct label *bpflabel); + void (*mpo_create_ifnet)(struct ifnet *ifnet, + struct label *ifnetlabel); + void (*mpo_create_inpcb_from_socket)(struct socket *so, + struct label *solabel, struct inpcb *inp, + struct label *inplabel); + void (*mpo_create_ipq)(struct mbuf *fragment, + struct label *fragmentlabel, struct ipq *ipq, + struct label *ipqlabel); + void (*mpo_create_datagram_from_ipq) + (struct ipq *ipq, struct label *ipqlabel, + struct mbuf *datagram, struct label *datagramlabel); + void (*mpo_create_fragment)(struct mbuf *datagram, + struct label *datagramlabel, struct mbuf *fragment, + struct label *fragmentlabel); + void (*mpo_create_mbuf_from_inpcb)(struct inpcb *inp, + struct label *inplabel, struct mbuf *m, + struct label *mlabel); + void (*mpo_create_mbuf_from_mbuf)(struct mbuf *oldmbuf, + struct label *oldlabel, struct mbuf *newmbuf, + struct label *newlabel); + void (*mpo_create_mbuf_linklayer)(struct ifnet *ifnet, + struct label *ifnetlabel, struct mbuf *mbuf, + struct label *mbuflabel); + void (*mpo_create_mbuf_from_bpfdesc)(struct bpf_d *bpf_d, + struct label *bpflabel, struct mbuf *mbuf, + struct label *mbuflabel); + void (*mpo_create_mbuf_from_ifnet)(struct ifnet *ifnet, + struct label *ifnetlabel, struct mbuf *mbuf, + struct label *mbuflabel); + void (*mpo_create_mbuf_multicast_encap)(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct ifnet *ifnet, + struct label *ifnetlabel, struct mbuf *newmbuf, + struct label *newmbuflabel); + void (*mpo_create_mbuf_netlayer)(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, + struct label *newmbuflabel); + int (*mpo_fragment_match)(struct mbuf *fragment, + struct label *fragmentlabel, struct ipq *ipq, + struct label *ipqlabel); + void (*mpo_reflect_mbuf_icmp)(struct mbuf *m, + struct label *mlabel); + void (*mpo_reflect_mbuf_tcp)(struct mbuf *m, struct label *mlabel); + void (*mpo_relabel_ifnet)(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel); + void (*mpo_update_ipq)(struct mbuf *fragment, + struct label *fragmentlabel, struct ipq *ipq, + struct label *ipqlabel); + void (*mpo_inpcb_sosetlabel)(struct socket *so, + struct label *label, struct inpcb *inp, + struct label *inplabel); + + /* + * Labeling event operations: processes. + */ + void (*mpo_execve_transition)(struct ucred *old, struct ucred *new, + struct vnode *vp, struct label *vnodelabel, + struct label *interpvnodelabel, + struct image_params *imgp, struct label *execlabel); + int (*mpo_execve_will_transition)(struct ucred *old, + struct vnode *vp, struct label *vnodelabel, + struct label *interpvnodelabel, + struct image_params *imgp, struct label *execlabel); + void (*mpo_create_proc0)(struct ucred *cred); + void (*mpo_create_proc1)(struct ucred *cred); + void (*mpo_relabel_cred)(struct ucred *cred, + struct label *newlabel); + void (*mpo_thread_userret)(struct thread *thread); + + /* + * Access control checks. + */ + int (*mpo_check_bpfdesc_receive)(struct bpf_d *bpf_d, + struct label *bpflabel, struct ifnet *ifnet, + struct label *ifnetlabel); + int (*mpo_check_cred_relabel)(struct ucred *cred, + struct label *newlabel); + int (*mpo_check_cred_visible)(struct ucred *u1, struct ucred *u2); + int (*mpo_check_ifnet_relabel)(struct ucred *cred, + struct ifnet *ifnet, struct label *ifnetlabel, + struct label *newlabel); + int (*mpo_check_ifnet_transmit)(struct ifnet *ifnet, + struct label *ifnetlabel, struct mbuf *m, + struct label *mbuflabel); + int (*mpo_check_inpcb_deliver)(struct inpcb *inp, + struct label *inplabel, struct mbuf *m, + struct label *mlabel); + int (*mpo_check_kenv_dump)(struct ucred *cred); + int (*mpo_check_kenv_get)(struct ucred *cred, char *name); + int (*mpo_check_kenv_set)(struct ucred *cred, char *name, + char *value); + int (*mpo_check_kenv_unset)(struct ucred *cred, char *name); + int (*mpo_check_kld_load)(struct ucred *cred, struct vnode *vp, + struct label *vlabel); + int (*mpo_check_kld_stat)(struct ucred *cred); + int (*mpo_check_kld_unload)(struct ucred *cred); + int (*mpo_check_mount_stat)(struct ucred *cred, struct mount *mp, + struct label *mntlabel); + int (*mpo_check_pipe_ioctl)(struct ucred *cred, + struct pipepair *pp, struct label *pipelabel, + unsigned long cmd, void *data); + int (*mpo_check_pipe_poll)(struct ucred *cred, + struct pipepair *pp, struct label *pipelabel); + int (*mpo_check_pipe_read)(struct ucred *cred, + struct pipepair *pp, struct label *pipelabel); + int (*mpo_check_pipe_relabel)(struct ucred *cred, + struct pipepair *pp, struct label *pipelabel, + struct label *newlabel); + int (*mpo_check_pipe_stat)(struct ucred *cred, + struct pipepair *pp, struct label *pipelabel); + int (*mpo_check_pipe_write)(struct ucred *cred, + struct pipepair *pp, struct label *pipelabel); + int (*mpo_check_proc_debug)(struct ucred *cred, + struct proc *proc); + int (*mpo_check_proc_sched)(struct ucred *cred, + struct proc *proc); + int (*mpo_check_proc_signal)(struct ucred *cred, + struct proc *proc, int signum); + int (*mpo_check_socket_bind)(struct ucred *cred, + struct socket *so, struct label *socketlabel, + struct sockaddr *sockaddr); + int (*mpo_check_socket_connect)(struct ucred *cred, + struct socket *so, struct label *socketlabel, + struct sockaddr *sockaddr); + int (*mpo_check_socket_deliver)(struct socket *so, + struct label *socketlabel, struct mbuf *m, + struct label *mbuflabel); + int (*mpo_check_socket_listen)(struct ucred *cred, + struct socket *so, struct label *socketlabel); + int (*mpo_check_socket_receive)(struct ucred *cred, + struct socket *so, struct label *socketlabel); + int (*mpo_check_socket_relabel)(struct ucred *cred, + struct socket *so, struct label *socketlabel, + struct label *newlabel); + int (*mpo_check_socket_send)(struct ucred *cred, + struct socket *so, struct label *socketlabel); + int (*mpo_check_socket_visible)(struct ucred *cred, + struct socket *so, struct label *socketlabel); + int (*mpo_check_sysarch_ioperm)(struct ucred *cred); + int (*mpo_check_system_acct)(struct ucred *cred, + struct vnode *vp, struct label *vlabel); + int (*mpo_check_system_nfsd)(struct ucred *cred); + int (*mpo_check_system_reboot)(struct ucred *cred, int howto); + int (*mpo_check_system_settime)(struct ucred *cred); + int (*mpo_check_system_swapon)(struct ucred *cred, + struct vnode *vp, struct label *label); + int (*mpo_check_system_swapoff)(struct ucred *cred, + struct vnode *vp, struct label *label); + int (*mpo_check_system_sysctl)(struct ucred *cred, + struct sysctl_oid *oidp, void *arg1, int arg2, + struct sysctl_req *req); + int (*mpo_check_vnode_access)(struct ucred *cred, + struct vnode *vp, struct label *label, int acc_mode); + int (*mpo_check_vnode_chdir)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel); + int (*mpo_check_vnode_chroot)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel); + int (*mpo_check_vnode_create)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel, + struct componentname *cnp, struct vattr *vap); + int (*mpo_check_vnode_delete)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel, + struct vnode *vp, struct label *label, + struct componentname *cnp); + int (*mpo_check_vnode_deleteacl)(struct ucred *cred, + struct vnode *vp, struct label *label, acl_type_t type); + int (*mpo_check_vnode_deleteextattr)(struct ucred *cred, + struct vnode *vp, struct label *label, int attrnamespace, + const char *name); + int (*mpo_check_vnode_exec)(struct ucred *cred, struct vnode *vp, + struct label *label, struct image_params *imgp, + struct label *execlabel); + int (*mpo_check_vnode_getacl)(struct ucred *cred, + struct vnode *vp, struct label *label, acl_type_t type); + int (*mpo_check_vnode_getextattr)(struct ucred *cred, + struct vnode *vp, struct label *label, int attrnamespace, + const char *name, struct uio *uio); + int (*mpo_check_vnode_link)(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, + struct label *label, struct componentname *cnp); + int (*mpo_check_vnode_listextattr)(struct ucred *cred, + struct vnode *vp, struct label *label, int attrnamespace); + int (*mpo_check_vnode_lookup)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel, + struct componentname *cnp); + int (*mpo_check_vnode_mmap)(struct ucred *cred, struct vnode *vp, + struct label *label, int prot); + void (*mpo_check_vnode_mmap_downgrade)(struct ucred *cred, + struct vnode *vp, struct label *label, int *prot); + int (*mpo_check_vnode_mprotect)(struct ucred *cred, + struct vnode *vp, struct label *label, int prot); + int (*mpo_check_vnode_open)(struct ucred *cred, struct vnode *vp, + struct label *label, int acc_mode); + int (*mpo_check_vnode_poll)(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp, + struct label *label); + int (*mpo_check_vnode_read)(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp, + struct label *label); + int (*mpo_check_vnode_readdir)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel); + int (*mpo_check_vnode_readlink)(struct ucred *cred, + struct vnode *vp, struct label *label); + int (*mpo_check_vnode_relabel)(struct ucred *cred, + struct vnode *vp, struct label *vnodelabel, + struct label *newlabel); + int (*mpo_check_vnode_rename_from)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel, struct vnode *vp, + struct label *label, struct componentname *cnp); + int (*mpo_check_vnode_rename_to)(struct ucred *cred, + struct vnode *dvp, struct label *dlabel, struct vnode *vp, + struct label *label, int samedir, + struct componentname *cnp); + int (*mpo_check_vnode_revoke)(struct ucred *cred, + struct vnode *vp, struct label *label); + int (*mpo_check_vnode_setacl)(struct ucred *cred, + struct vnode *vp, struct label *label, acl_type_t type, + struct acl *acl); + int (*mpo_check_vnode_setextattr)(struct ucred *cred, + struct vnode *vp, struct label *label, int attrnamespace, + const char *name, struct uio *uio); + int (*mpo_check_vnode_setflags)(struct ucred *cred, + struct vnode *vp, struct label *label, u_long flags); + int (*mpo_check_vnode_setmode)(struct ucred *cred, + struct vnode *vp, struct label *label, mode_t mode); + int (*mpo_check_vnode_setowner)(struct ucred *cred, + struct vnode *vp, struct label *label, uid_t uid, + gid_t gid); + int (*mpo_check_vnode_setutimes)(struct ucred *cred, + struct vnode *vp, struct label *label, + struct timespec atime, struct timespec mtime); + int (*mpo_check_vnode_stat)(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp, + struct label *label); + int (*mpo_check_vnode_write)(struct ucred *active_cred, + struct ucred *file_cred, struct vnode *vp, + struct label *label); +}; + +struct mac_policy_conf { + char *mpc_name; /* policy name */ + char *mpc_fullname; /* policy full name */ + struct mac_policy_ops *mpc_ops; /* policy operations */ + int mpc_loadtime_flags; /* flags */ + int *mpc_field_off; /* security field */ + int mpc_runtime_flags; /* flags */ + LIST_ENTRY(mac_policy_conf) mpc_list; /* global list */ +}; + +/* Flags for the mpc_loadtime_flags field. */ +#define MPC_LOADTIME_FLAG_NOTLATE 0x00000001 +#define MPC_LOADTIME_FLAG_UNLOADOK 0x00000002 +#define MPC_LOADTIME_FLAG_LABELMBUFS 0x00000004 + +/* Flags for the mpc_runtime_flags field. */ +#define MPC_RUNTIME_FLAG_REGISTERED 0x00000001 + +#define MAC_POLICY_SET(mpops, mpname, mpfullname, mpflags, privdata_wanted) \ + static struct mac_policy_conf mpname##_mac_policy_conf = { \ + #mpname, \ + mpfullname, \ + mpops, \ + mpflags, \ + privdata_wanted, \ + 0, \ + }; \ + static moduledata_t mpname##_mod = { \ + #mpname, \ + mac_policy_modevent, \ + &mpname##_mac_policy_conf \ + }; \ + MODULE_DEPEND(mpname, kernel_mac_support, 1, 1, 1); \ + DECLARE_MODULE(mpname, mpname##_mod, SI_SUB_MAC_POLICY, \ + SI_ORDER_MIDDLE) + +int mac_policy_modevent(module_t mod, int type, void *data); + +#define LABEL_TO_SLOT(l, s) (l)->l_perpolicy[s] + +#endif /* !_SYS_MAC_POLICY_H_ */ diff --git a/src/include/sys/malloc.h b/src/include/sys/malloc.h new file mode 100644 index 0000000..f2ee047 --- /dev/null +++ b/src/include/sys/malloc.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 1987, 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. + * 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. + * + * @(#)malloc.h 8.5 (Berkeley) 5/3/95 + * $FreeBSD: src/sys/sys/malloc.h,v 1.76 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_MALLOC_H_ +#define _SYS_MALLOC_H_ + +#include +#include +#include + +#define MINALLOCSIZE UMA_SMALLEST_UNIT + +/* + * flags to malloc. + */ +#define M_NOWAIT 0x0001 /* do not block */ +#define M_WAITOK 0x0002 /* ok to block */ +#define M_ZERO 0x0100 /* bzero the allocation */ +#define M_NOVM 0x0200 /* don't ask VM for pages */ +#define M_USE_RESERVE 0x0400 /* can alloc out of reserve memory */ + +#define M_MAGIC 877983977 /* time when first defined :-) */ + +struct malloc_type { + struct malloc_type *ks_next; /* next in list */ + u_long ks_memuse; /* total memory held in bytes */ + u_long ks_size; /* sizes of this thing that are allocated */ + u_long ks_inuse; /* # of packets of this type currently in use */ + uint64_t ks_calls; /* total packets of this type ever allocated */ + u_long ks_maxused; /* maximum number ever used */ + u_long ks_magic; /* if it's not magic, don't touch it */ + const char *ks_shortdesc; /* short description */ + struct mtx ks_mtx; /* lock for stats */ +}; + +#ifdef _KERNEL +#define MALLOC_DEFINE(type, shortdesc, longdesc) \ + struct malloc_type type[1] = { \ + { NULL, 0, 0, 0, 0, 0, M_MAGIC, shortdesc, {} } \ + }; \ + SYSINIT(type##_init, SI_SUB_KMEM, SI_ORDER_SECOND, malloc_init, type); \ + SYSUNINIT(type##_uninit, SI_SUB_KMEM, SI_ORDER_ANY, malloc_uninit, type) + +#define MALLOC_DECLARE(type) \ + extern struct malloc_type type[1] + +MALLOC_DECLARE(M_CACHE); +MALLOC_DECLARE(M_DEVBUF); +MALLOC_DECLARE(M_TEMP); + +MALLOC_DECLARE(M_IP6OPT); /* for INET6 */ +MALLOC_DECLARE(M_IP6NDP); /* for INET6 */ + +/* + * Deprecated macro versions of not-quite-malloc() and free(). + */ +#define MALLOC(space, cast, size, type, flags) \ + ((space) = (cast)malloc((u_long)(size), (type), (flags))) +#define FREE(addr, type) free((addr), (type)) + +/* + * XXX this should be declared in , but that tends to fail + * because is included in a header before the source file + * has a chance to include to get MALLOC_DECLARE() defined. + */ +MALLOC_DECLARE(M_IOV); + +extern struct mtx malloc_mtx; + +/* XXX struct malloc_type is unused for contig*(). */ +void contigfree(void *addr, unsigned long size, struct malloc_type *type); +void *contigmalloc(unsigned long size, struct malloc_type *type, int flags, + vm_paddr_t low, vm_paddr_t high, unsigned long alignment, + unsigned long boundary); +void free(void *addr, struct malloc_type *type); +void *malloc(unsigned long size, struct malloc_type *type, int flags); +void malloc_init(void *); +int malloc_last_fail(void); +void malloc_uninit(void *); +void *realloc(void *addr, unsigned long size, struct malloc_type *type, + int flags); +void *reallocf(void *addr, unsigned long size, struct malloc_type *type, + int flags); +#endif /* _KERNEL */ + +#endif /* !_SYS_MALLOC_H_ */ diff --git a/src/include/sys/mbpool.h b/src/include/sys/mbpool.h new file mode 100644 index 0000000..6a7b303 --- /dev/null +++ b/src/include/sys/mbpool.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2003 + * Fraunhofer Institute for Open Communication Systems (FhG Fokus). + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * Author: Hartmut Brandt + * + * This implements pools of DMA-able buffers that conserve DMA address space + * by putting several buffers into one page and that allow to map between + * 32-bit handles for the buffer and buffer addresses (to use 32-bit network + * interfaces on 64bit machines). This assists network interfaces that may need + * huge numbers of mbufs. + * + * $FreeBSD: src/sys/sys/mbpool.h,v 1.1 2003/07/15 08:59:37 harti Exp $ + */ +#ifndef _SYS_MBPOOL_H_ +#define _SYS_MBPOOL_H_ + +#ifdef _KERNEL + +#include + +/* opaque */ +struct mbpool; + +/* size of reserved area at end of each chunk */ +#define MBPOOL_TRAILER_SIZE 4 + +/* maximum value of max_pages */ +#define MBPOOL_MAX_MAXPAGES ((1 << 14) - 1) + +/* maximum number of chunks per page */ +#define MBPOOL_MAX_CHUNKS (1 << 9) + +/* initialize a pool */ +int mbp_create(struct mbpool **, const char *, bus_dma_tag_t, u_int, + size_t, size_t); + +/* destroy a pool */ +void mbp_destroy(struct mbpool *); + +/* allocate a chunk and set used and on card */ +void *mbp_alloc(struct mbpool *, bus_addr_t *, uint32_t *); + +/* free a chunk */ +void mbp_free(struct mbpool *, void *); + +/* free a chunk that is an external mbuf */ +void mbp_ext_free(void *, void *); + +/* free all buffers that are marked to be on the card */ +void mbp_card_free(struct mbpool *); + +/* count used buffers and buffers on card */ +void mbp_count(struct mbpool *, u_int *, u_int *, u_int *); + +/* get the buffer from a handle and clear card bit */ +void *mbp_get(struct mbpool *, uint32_t); + +/* get the buffer from a handle and don't clear card bit */ +void *mbp_get_keep(struct mbpool *, uint32_t); + +/* sync the chunk */ +void mbp_sync(struct mbpool *, uint32_t, bus_addr_t, bus_size_t, u_int); + +#endif /* _KERNEL */ +#endif /* _SYS_MBPOOL_H_ */ diff --git a/src/include/sys/mbuf.h b/src/include/sys/mbuf.h new file mode 100644 index 0000000..70d2903 --- /dev/null +++ b/src/include/sys/mbuf.h @@ -0,0 +1,669 @@ +/*- + * Copyright (c) 1982, 1986, 1988, 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. + * 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. + * + * @(#)mbuf.h 8.5 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/mbuf.h,v 1.143 2004/05/02 15:10:17 darrenr Exp $ + */ + +#ifndef _SYS_MBUF_H_ +#define _SYS_MBUF_H_ + +#include + +/* + * Mbufs are of a single size, MSIZE (sys/param.h), which + * includes overhead. An mbuf may add a single "mbuf cluster" of size + * MCLBYTES (also in sys/param.h), which has no additional overhead + * and is used instead of the internal data area; this is done when + * at least MINCLSIZE of data must be stored. Additionally, it is possible + * to allocate a separate buffer externally and attach it to the mbuf in + * a way similar to that of mbuf clusters. + */ +#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */ +#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */ +#define MINCLSIZE (MHLEN + 1) /* smallest amount to put in cluster */ +#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */ + +#ifdef _KERNEL +/*- + * Macros for type conversion: + * mtod(m, t) -- Convert mbuf pointer to data pointer of correct type. + * dtom(x) -- Convert data pointer within mbuf to mbuf pointer (XXX). + */ +#define mtod(m, t) ((t)((m)->m_data)) +#define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1))) +#endif /* _KERNEL */ + +/* + * Header present at the beginning of every mbuf. + */ +struct m_hdr { + struct mbuf *mh_next; /* next buffer in chain */ + struct mbuf *mh_nextpkt; /* next chain in queue/record */ + caddr_t mh_data; /* location of data */ + int mh_len; /* amount of data in this mbuf */ + int mh_flags; /* flags; see below */ + short mh_type; /* type of data in this mbuf */ +}; + +/* + * Packet tag structure (see below for details). + */ +struct m_tag { + SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */ + u_int16_t m_tag_id; /* Tag ID */ + u_int16_t m_tag_len; /* Length of data */ + u_int32_t m_tag_cookie; /* ABI/Module ID */ + void (*m_tag_free)(struct m_tag *); +}; + +/* + * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set. + */ +struct pkthdr { + struct ifnet *rcvif; /* rcv interface */ + int len; /* total packet length */ + /* variables for ip and tcp reassembly */ + void *header; /* pointer to packet header */ + /* variables for hardware checksum */ + int csum_flags; /* flags regarding checksum */ + int csum_data; /* data field used by csum routines */ + SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */ +}; + +/* + * Description of external storage mapped into mbuf; valid only if M_EXT is set. + */ +struct m_ext { + caddr_t ext_buf; /* start of buffer */ + void (*ext_free) /* free routine if not the usual */ + (void *, void *); + void *ext_args; /* optional argument pointer */ + u_int ext_size; /* size of buffer, for ext_free */ + u_int *ref_cnt; /* pointer to ref count info */ + int ext_type; /* type of external storage */ +}; + +/* + * The core of the mbuf object along with some shortcut defines for + * practical purposes. + */ +struct mbuf { + struct m_hdr m_hdr; + union { + struct { + struct pkthdr MH_pkthdr; /* M_PKTHDR set */ + union { + struct m_ext MH_ext; /* M_EXT set */ + char MH_databuf[MHLEN]; + } MH_dat; + } MH; + char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */ + } M_dat; +}; +#define m_next m_hdr.mh_next +#define m_len m_hdr.mh_len +#define m_data m_hdr.mh_data +#define m_type m_hdr.mh_type +#define m_flags m_hdr.mh_flags +#define m_nextpkt m_hdr.mh_nextpkt +#define m_act m_nextpkt +#define m_pkthdr M_dat.MH.MH_pkthdr +#define m_ext M_dat.MH.MH_dat.MH_ext +#define m_pktdat M_dat.MH.MH_dat.MH_databuf +#define m_dat M_dat.M_databuf + +/* + * mbuf flags. + */ +#define M_EXT 0x0001 /* has associated external storage */ +#define M_PKTHDR 0x0002 /* start of record */ +#define M_EOR 0x0004 /* end of record */ +#define M_RDONLY 0x0008 /* associated data is marked read-only */ +#define M_PROTO1 0x0010 /* protocol-specific */ +#define M_PROTO2 0x0020 /* protocol-specific */ +#define M_PROTO3 0x0040 /* protocol-specific */ +#define M_PROTO4 0x0080 /* protocol-specific */ +#define M_PROTO5 0x0100 /* protocol-specific */ +#define M_PROTO6 0x4000 /* protocol-specific (avoid M_BCAST conflict) */ +#define M_FREELIST 0x8000 /* mbuf is on the free list */ + +/* + * mbuf pkthdr flags (also stored in m_flags). + */ +#define M_BCAST 0x0200 /* send/received as link-level broadcast */ +#define M_MCAST 0x0400 /* send/received as link-level multicast */ +#define M_FRAG 0x0800 /* packet is a fragment of a larger packet */ +#define M_FIRSTFRAG 0x1000 /* packet is first fragment */ +#define M_LASTFRAG 0x2000 /* packet is last fragment */ + +/* + * External buffer types: identify ext_buf type. + */ +#define EXT_CLUSTER 1 /* mbuf cluster */ +#define EXT_SFBUF 2 /* sendfile(2)'s sf_bufs */ +#define EXT_NET_DRV 100 /* custom ext_buf provided by net driver(s) */ +#define EXT_MOD_TYPE 200 /* custom module's ext_buf type */ +#define EXT_DISPOSABLE 300 /* can throw this buffer away w/page flipping */ +#define EXT_EXTREF 400 /* has externally maintained ref_cnt ptr*/ + +/* + * Flags copied when copying m_pkthdr. + */ +#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_RDONLY|M_PROTO1|M_PROTO1|M_PROTO2|\ + M_PROTO3|M_PROTO4|M_PROTO5|M_PROTO6|\ + M_BCAST|M_MCAST|M_FRAG|M_FIRSTFRAG|M_LASTFRAG) + +/* + * Flags indicating hw checksum support and sw checksum requirements. + */ +#define CSUM_IP 0x0001 /* will csum IP */ +#define CSUM_TCP 0x0002 /* will csum TCP */ +#define CSUM_UDP 0x0004 /* will csum UDP */ +#define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */ +#define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */ + +#define CSUM_IP_CHECKED 0x0100 /* did csum IP */ +#define CSUM_IP_VALID 0x0200 /* ... the csum is valid */ +#define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */ +#define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */ + +#define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP) +#define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */ + +/* + * mbuf types. + */ +#define MT_NOTMBUF 0 /* USED INTERNALLY ONLY! Object is not mbuf */ +#define MT_DATA 1 /* dynamic (data) allocation */ +#define MT_HEADER 2 /* packet header */ +#if 0 +#define MT_SOCKET 3 /* socket structure */ +#define MT_PCB 4 /* protocol control block */ +#define MT_RTABLE 5 /* routing tables */ +#define MT_HTABLE 6 /* IMP host tables */ +#define MT_ATABLE 7 /* address resolution tables */ +#endif +#define MT_SONAME 8 /* socket name */ +#if 0 +#define MT_SOOPTS 10 /* socket options */ +#endif +#define MT_FTABLE 11 /* fragment reassembly header */ +#if 0 +#define MT_RIGHTS 12 /* access rights */ +#define MT_IFADDR 13 /* interface address */ +#endif +#define MT_CONTROL 14 /* extra-data protocol message */ +#define MT_OOBDATA 15 /* expedited data */ +#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */ + +/* + * Mbuf and cluster allocation statistics PCPU structure. + */ +struct mbpstat { + u_long mb_mbfree; + u_long mb_mbbucks; + u_long mb_clfree; + u_long mb_clbucks; + long mb_mbtypes[MT_NTYPES]; + short mb_active; +}; + +/* + * General mbuf allocator statistics structure. + * XXX: Modifications of these are not protected by any mutex locks nor by + * any atomic() manipulations. As a result, we may occasionally lose + * a count or two. Luckily, not all of these fields are modified at all + * and remain static, and those that are manipulated are only manipulated + * in failure situations, which do not occur (hopefully) very often. + */ +struct mbstat { + u_long m_drops; /* times failed to allocate */ + u_long m_wait; /* times succesfully returned from wait */ + u_long m_drain; /* times drained protocols for space */ + u_long m_mcfail; /* XXX: times m_copym failed */ + u_long m_mpfail; /* XXX: times m_pullup failed */ + u_long m_msize; /* length of an mbuf */ + u_long m_mclbytes; /* length of an mbuf cluster */ + u_long m_minclsize; /* min length of data to allocate a cluster */ + u_long m_mlen; /* length of data in an mbuf */ + u_long m_mhlen; /* length of data in a header mbuf */ + u_int m_mbperbuck; /* number of mbufs per "bucket" */ + u_int m_clperbuck; /* number of clusters per "bucket" */ + /* Number of mbtypes (gives # elems in mbpstat's mb_mbtypes[] array: */ + short m_numtypes; + /* XXX: Sendfile stats should eventually move to their own struct */ + u_long sf_iocnt; /* times sendfile had to do disk I/O */ + u_long sf_allocfail; /* times sfbuf allocation failed */ + u_long sf_allocwait; /* times sfbuf allocation had to wait */ +}; + +/* + * Flags specifying how an allocation should be made. + * M_DONTWAIT means "don't block if nothing is available" whereas + * M_TRYWAIT means "block for mbuf_wait ticks at most if nothing is + * available." + */ +#define M_DONTWAIT 0x4 /* don't conflict with M_NOWAIT */ +#define M_TRYWAIT 0x8 /* or M_WAITOK */ +#define M_WAIT M_TRYWAIT /* XXX: deprecated */ +#define MBTOM(how) ((how) & M_TRYWAIT ? M_WAITOK : M_NOWAIT) + +#ifdef _KERNEL +/*- + * mbuf external reference count management macros. + * + * MEXT_IS_REF(m): true if (m) is not the only mbuf referencing + * the external buffer ext_buf. + * + * MEXT_REM_REF(m): remove reference to m_ext object. + * + * MEXT_ADD_REF(m): add reference to m_ext object already + * referred to by (m). + */ +#define MEXT_IS_REF(m) (*((m)->m_ext.ref_cnt) > 1) + +#define MEXT_REM_REF(m) do { \ + KASSERT(*((m)->m_ext.ref_cnt) > 0, ("m_ext refcnt < 0")); \ + atomic_subtract_int((m)->m_ext.ref_cnt, 1); \ +} while(0) + +#define MEXT_ADD_REF(m) atomic_add_int((m)->m_ext.ref_cnt, 1) + +/* + * mbuf, cluster, and external object allocation macros + * (for compatibility purposes). + */ +/* NB: M_COPY_PKTHDR is deprecated. Use M_MOVE_PKTHDR or m_dup_pktdr. */ +#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from)) +#define m_getclr(how, type) m_get_clrd((how), (type)) +#define MGET(m, how, type) ((m) = m_get((how), (type))) +#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) +#define MCLGET(m, how) m_clget((m), (how)) +#define MEXTADD(m, buf, size, free, args, flags, type) \ + m_extadd((m), (caddr_t)(buf), (size), (free), (args), (flags), (type)) + +/* + * MEXTFREE(m): disassociate (and possibly free) an external object from (m). + * + * If the atomic_cmpset_int() returns 0, then we effectively do nothing + * in terms of "cleaning up" (freeing the ext buf and ref. counter) as + * this means that either there are still references, or another thread + * is taking care of the clean-up. + */ +#define MEXTFREE(m) do { \ + struct mbuf *_mb = (m); \ + \ + MEXT_REM_REF(_mb); \ + if (atomic_cmpset_int(_mb->m_ext.ref_cnt, 0, 1)) \ + _mext_free(_mb); \ + _mb->m_flags &= ~M_EXT; \ +} while (0) + +/* + * Evaluate TRUE if it's safe to write to the mbuf m's data region (this + * can be both the local data payload, or an external buffer area, + * depending on whether M_EXT is set). + */ +#define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \ + & M_EXT) || !MEXT_IS_REF(m))) + +/* + * Check if the supplied mbuf has a packet header, or else panic. + */ +#define M_ASSERTPKTHDR(m) \ + KASSERT(m != NULL && m->m_flags & M_PKTHDR, \ + ("%s: no mbuf packet header!", __func__)) + +/* + * Ensure that the supplied mbuf is a valid, non-free mbuf. + */ +#define M_ASSERTVALID(m) \ + KASSERT((((struct mbuf *)m)->m_flags & M_FREELIST) == 0, \ + ("%s: attempted use of a free mbuf!", __func__)) + +/* + * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place + * an object of the specified size at the end of the mbuf, longword aligned. + */ +#define M_ALIGN(m, len) do { \ + (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1); \ +} while (0) + +/* + * As above, for mbufs allocated with m_gethdr/MGETHDR + * or initialized by M_COPY_PKTHDR. + */ +#define MH_ALIGN(m, len) do { \ + (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \ +} while (0) + +/* + * Compute the amount of space available + * before the current start of data in an mbuf. + * + * The M_WRITABLE() is a temporary, conservative safety measure: the burden + * of checking writability of the mbuf data area rests solely with the caller. + */ +#define M_LEADINGSPACE(m) \ + ((m)->m_flags & M_EXT ? \ + (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \ + (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \ + (m)->m_data - (m)->m_dat) + +/* + * Compute the amount of space available + * after the end of data in an mbuf. + * + * The M_WRITABLE() is a temporary, conservative safety measure: the burden + * of checking writability of the mbuf data area rests solely with the caller. + */ +#define M_TRAILINGSPACE(m) \ + ((m)->m_flags & M_EXT ? \ + (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \ + - ((m)->m_data + (m)->m_len) : 0) : \ + &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len)) + +/* + * Arrange to prepend space of size plen to mbuf m. + * If a new mbuf must be allocated, how specifies whether to wait. + * If the allocation fails, the original mbuf chain is freed and m is + * set to NULL. + */ +#define M_PREPEND(m, plen, how) do { \ + struct mbuf **_mmp = &(m); \ + struct mbuf *_mm = *_mmp; \ + int _mplen = (plen); \ + int __mhow = (how); \ + \ + if (M_LEADINGSPACE(_mm) >= _mplen) { \ + _mm->m_data -= _mplen; \ + _mm->m_len += _mplen; \ + } else \ + _mm = m_prepend(_mm, _mplen, __mhow); \ + if (_mm != NULL && _mm->m_flags & M_PKTHDR) \ + _mm->m_pkthdr.len += _mplen; \ + *_mmp = _mm; \ +} while (0) + +/* + * Change mbuf to new type. + * This is a relatively expensive operation and should be avoided. + */ +#define MCHTYPE(m, t) m_chtype((m), (t)) + +/* Length to m_copy to copy all. */ +#define M_COPYALL 1000000000 + +/* Compatibility with 4.3. */ +#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT) + +extern int max_datalen; /* MHLEN - max_hdr */ +extern int max_hdr; /* Largest link + protocol header */ +extern int max_linkhdr; /* Largest link-level header */ +extern int max_protohdr; /* Largest protocol header */ +extern struct mbstat mbstat; /* General mbuf stats/infos */ +extern int nmbclusters; /* Maximum number of clusters */ +extern int nmbcnt; /* Scale kmem_map for counter space */ +extern int nmbufs; /* Maximum number of mbufs */ + +struct uio; + +void _mext_free(struct mbuf *); +void m_adj(struct mbuf *, int); +int m_apply(struct mbuf *, int, int, + int (*)(void *, void *, unsigned int), void *); +void m_cat(struct mbuf *, struct mbuf *); +void m_chtype(struct mbuf *, short); +void m_clget(struct mbuf *, int); +void m_extadd(struct mbuf *, caddr_t, u_int, + void (*)(void *, void *), void *, int, int); +void m_copyback(struct mbuf *, int, int, c_caddr_t); +void m_copydata(const struct mbuf *, int, int, caddr_t); +struct mbuf *m_copym(struct mbuf *, int, int, int); +struct mbuf *m_copypacket(struct mbuf *, int); +void m_copy_pkthdr(struct mbuf *, struct mbuf *); +struct mbuf *m_defrag(struct mbuf *, int); +struct mbuf *m_devget(char *, int, int, struct ifnet *, + void (*)(char *, caddr_t, u_int)); +struct mbuf *m_dup(struct mbuf *, int); +int m_dup_pkthdr(struct mbuf *, struct mbuf *, int); +u_int m_fixhdr(struct mbuf *); +struct mbuf *m_fragment(struct mbuf *, int, int); +struct mbuf *m_free(struct mbuf *); +void m_freem(struct mbuf *); +struct mbuf *m_get(int, short); +struct mbuf *m_get_clrd(int, short); +struct mbuf *m_getcl(int, short, int); +struct mbuf *m_gethdr(int, short); +struct mbuf *m_gethdr_clrd(int, short); +struct mbuf *m_getm(struct mbuf *, int, int, short); +struct mbuf *m_getptr(struct mbuf *, int, int *); +u_int m_length(struct mbuf *, struct mbuf **); +void m_move_pkthdr(struct mbuf *, struct mbuf *); +struct mbuf *m_prepend(struct mbuf *, int, int); +void m_print(const struct mbuf *); +struct mbuf *m_pulldown(struct mbuf *, int, int, int *); +struct mbuf *m_pullup(struct mbuf *, int); +struct mbuf *m_split(struct mbuf *, int, int); +struct mbuf * + m_uiotombuf(struct uio *uio, int how, int len); + +/* + * Packets may have annotations attached by affixing a list + * of "packet tags" to the pkthdr structure. Packet tags are + * dynamically allocated semi-opaque data structures that have + * a fixed header (struct m_tag) that specifies the size of the + * memory block and a pair that identifies it. + * The cookie is a 32-bit unique unsigned value used to identify + * a module or ABI. By convention this value is chose as the + * date+time that the module is created, expressed as the number of + * seconds since the epoch (e.g., using date -u +'%s'). The type value + * is an ABI/module-specific value that identifies a particular annotation + * and is private to the module. For compatibility with systems + * like OpenBSD that define packet tags w/o an ABI/module cookie, + * the value PACKET_ABI_COMPAT is used to implement m_tag_get and + * m_tag_find compatibility shim functions and several tag types are + * defined below. Users that do not require compatibility should use + * a private cookie value so that packet tag-related definitions + * can be maintained privately. + * + * Note that the packet tag returned by m_tag_allocate has the default + * memory alignment implemented by malloc. To reference private data + * one can use a construct like: + * + * struct m_tag *mtag = m_tag_allocate(...); + * struct foo *p = (struct foo *)(mtag+1); + * + * if the alignment of struct m_tag is sufficient for referencing members + * of struct foo. Otherwise it is necessary to embed struct m_tag within + * the private data structure to insure proper alignment; e.g., + * + * struct foo { + * struct m_tag tag; + * ... + * }; + * struct foo *p = (struct foo *) m_tag_allocate(...); + * struct m_tag *mtag = &p->tag; + */ + +/* + * Persistent tags stay with an mbuf until the mbuf is reclaimed. + * Otherwise tags are expected to ``vanish'' when they pass through + * a network interface. For most interfaces this happens normally + * as the tags are reclaimed when the mbuf is free'd. However in + * some special cases reclaiming must be done manually. An example + * is packets that pass through the loopback interface. Also, one + * must be careful to do this when ``turning around'' packets (e.g., + * icmp_reflect). + * + * To mark a tag persistent bit-or this flag in when defining the + * tag id. The tag will then be treated as described above. + */ +#define MTAG_PERSISTENT 0x800 + +#define PACKET_TAG_NONE 0 /* Nadda */ + +/* Packet tag for use with PACKET_ABI_COMPAT. */ +#define PACKET_TAG_IPSEC_IN_DONE 1 /* IPsec applied, in */ +#define PACKET_TAG_IPSEC_OUT_DONE 2 /* IPsec applied, out */ +#define PACKET_TAG_IPSEC_IN_CRYPTO_DONE 3 /* NIC IPsec crypto done */ +#define PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED 4 /* NIC IPsec crypto req'ed */ +#define PACKET_TAG_IPSEC_IN_COULD_DO_CRYPTO 5 /* NIC notifies IPsec */ +#define PACKET_TAG_IPSEC_PENDING_TDB 6 /* Reminder to do IPsec */ +#define PACKET_TAG_BRIDGE 7 /* Bridge processing done */ +#define PACKET_TAG_GIF 8 /* GIF processing done */ +#define PACKET_TAG_GRE 9 /* GRE processing done */ +#define PACKET_TAG_IN_PACKET_CHECKSUM 10 /* NIC checksumming done */ +#define PACKET_TAG_ENCAP 11 /* Encap. processing */ +#define PACKET_TAG_IPSEC_SOCKET 12 /* IPSEC socket ref */ +#define PACKET_TAG_IPSEC_HISTORY 13 /* IPSEC history */ +#define PACKET_TAG_IPV6_INPUT 14 /* IPV6 input processing */ +#define PACKET_TAG_DUMMYNET 15 /* dummynet info */ +#define PACKET_TAG_DIVERT 17 /* divert info */ +#define PACKET_TAG_IPFORWARD 18 /* ipforward info */ +#define PACKET_TAG_MACLABEL (19 | MTAG_PERSISTENT) /* MAC label */ +#define PACKET_TAG_PF_GENERATED (20 | MTAG_PERSISTENT) /* PF, pass always */ +#define PACKET_TAG_PF_ROUTED 21 /* PF routed, avoid loops */ +#define PACKET_TAG_PF_FRAGCACHE 22 /* PF fragment cached */ +#define PACKET_TAG_PF_QID 23 /* PF ALTQ queue id */ +#define PACKET_TAG_PF_TAG 24 /* PF tagged */ + +/* Packet tag routines. */ +struct m_tag *m_tag_alloc(u_int32_t, int, int, int); +void m_tag_delete(struct mbuf *, struct m_tag *); +void m_tag_delete_chain(struct mbuf *, struct m_tag *); +struct m_tag *m_tag_locate(struct mbuf *, u_int32_t, int, struct m_tag *); +struct m_tag *m_tag_copy(struct m_tag *, int); +int m_tag_copy_chain(struct mbuf *, struct mbuf *, int); +void m_tag_delete_nonpersistent(struct mbuf *); + +/* + * Initialize the list of tags associated with an mbuf. + */ +static __inline void +m_tag_init(struct mbuf *m) +{ + SLIST_INIT(&m->m_pkthdr.tags); +} + +/* + * Setup the contents of a tag. Note that this does not + * fillin the free method; the caller is expected to do that. + * + * XXX probably should be called m_tag_init; but that was + * already taken. + */ +static __inline void +m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len) +{ + t->m_tag_id = type; + t->m_tag_len = len; + t->m_tag_cookie = cookie; +} + +/* + * Reclaim resources associated with a tag. + */ +static __inline void +m_tag_free(struct m_tag *t) +{ + (*t->m_tag_free)(t); +} + +/* + * Return the first tag associated with an mbuf. + */ +static __inline struct m_tag * +m_tag_first(struct mbuf *m) +{ + return SLIST_FIRST(&m->m_pkthdr.tags); +} + +/* + * Return the next tag in the list of tags associated with an mbuf. + */ +static __inline struct m_tag * +m_tag_next(struct mbuf *m, struct m_tag *t) +{ + return SLIST_NEXT(t, m_tag_link); +} + +/* + * Prepend a tag to the list of tags associated with an mbuf. + */ +static __inline void +m_tag_prepend(struct mbuf *m, struct m_tag *t) +{ + SLIST_INSERT_HEAD(&m->m_pkthdr.tags, t, m_tag_link); +} + +/* + * Unlink a tag from the list of tags associated with an mbuf. + */ +static __inline void +m_tag_unlink(struct mbuf *m, struct m_tag *t) +{ + SLIST_REMOVE(&m->m_pkthdr.tags, t, m_tag, m_tag_link); +} + +/* These are for OpenBSD compatibility. */ +#define MTAG_ABI_COMPAT 0 /* compatibility ABI */ + +static __inline struct m_tag * +m_tag_get(int type, int length, int wait) +{ + return m_tag_alloc(MTAG_ABI_COMPAT, type, length, wait); +} + +static __inline struct m_tag * +m_tag_find(struct mbuf *m, int type, struct m_tag *start) +{ + return SLIST_EMPTY(&m->m_pkthdr.tags) ? + NULL : m_tag_locate(m, MTAG_ABI_COMPAT, type, start); +} + +/* + * Obtain next_hop information asociated with the mbuf; if any. + * If a tag is present devalidate it also. + */ +static __inline struct sockaddr_in * +m_claim_next(struct mbuf *m, int type) +{ + struct m_tag *mtag = m_tag_find(m, type, NULL); + if (mtag) { + struct sockaddr_in *sin = *(struct sockaddr_in **)(mtag+1); + mtag->m_tag_id = PACKET_TAG_NONE; + return sin; + } else + return NULL; +} + +#endif /* _KERNEL */ + +#endif /* !_SYS_MBUF_H_ */ diff --git a/src/include/sys/mchain.h b/src/include/sys/mchain.h new file mode 100644 index 0000000..b715529 --- /dev/null +++ b/src/include/sys/mchain.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2000, 2001 Boris Popov + * 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 Boris Popov. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/mchain.h,v 1.7 2003/02/21 16:24:49 bmilekic Exp $ + */ +#ifndef _SYS_MCHAIN_H_ +#define _SYS_MCHAIN_H_ + +#include + +#ifndef _KERNEL +/* + * This macros probably belongs to the endian.h + */ +#if (BYTE_ORDER == LITTLE_ENDIAN) + +#define htoles(x) ((u_int16_t)(x)) +#define letohs(x) ((u_int16_t)(x)) +#define htolel(x) ((u_int32_t)(x)) +#define letohl(x) ((u_int32_t)(x)) +#define htoleq(x) ((int64_t)(x)) +#define letohq(x) ((int64_t)(x)) + +#define htobes(x) (__htons(x)) +#define betohs(x) (__ntohs(x)) +#define htobel(x) (__htonl(x)) +#define betohl(x) (__ntohl(x)) + +static __inline int64_t +htobeq(int64_t x) +{ + return (int64_t)__htonl((u_int32_t)(x >> 32)) | + (int64_t)__htonl((u_int32_t)(x & 0xffffffff)) << 32; +} + +static __inline int64_t +betohq(int64_t x) +{ + return (int64_t)__ntohl((u_int32_t)(x >> 32)) | + (int64_t)__ntohl((u_int32_t)(x & 0xffffffff)) << 32; +} + +#else /* (BYTE_ORDER == LITTLE_ENDIAN) */ + +#error "Macros for Big-Endians are incomplete" + +/* +#define htoles(x) ((u_int16_t)(x)) +#define letohs(x) ((u_int16_t)(x)) +#define htolel(x) ((u_int32_t)(x)) +#define letohl(x) ((u_int32_t)(x)) +*/ +#endif /* (BYTE_ORDER == LITTLE_ENDIAN) */ +#endif /* _KERNEL */ + + +#ifdef _KERNEL + +/* + * Type of copy for mb_{put|get}_mem() + */ +#define MB_MSYSTEM 0 /* use bcopy() */ +#define MB_MUSER 1 /* use copyin()/copyout() */ +#define MB_MINLINE 2 /* use an inline copy loop */ +#define MB_MZERO 3 /* bzero(), mb_put_mem only */ +#define MB_MCUSTOM 4 /* use an user defined function */ + +struct mbuf; +struct mbchain; + +typedef int mb_copy_t(struct mbchain *mbp, c_caddr_t src, caddr_t dst, size_t len); + +struct mbchain { + struct mbuf * mb_top; /* head of mbufs chain */ + struct mbuf * mb_cur; /* current mbuf */ + int mb_mleft; /* free space in the current mbuf */ + int mb_count; /* total number of bytes */ + mb_copy_t * mb_copy; /* user defined copy function */ + void * mb_udata; /* user data */ +}; + +struct mdchain { + struct mbuf * md_top; /* head of mbufs chain */ + struct mbuf * md_cur; /* current mbuf */ + u_char * md_pos; /* offset in the current mbuf */ +}; + +int mb_init(struct mbchain *mbp); +void mb_initm(struct mbchain *mbp, struct mbuf *m); +void mb_done(struct mbchain *mbp); +struct mbuf *mb_detach(struct mbchain *mbp); +int mb_fixhdr(struct mbchain *mbp); +caddr_t mb_reserve(struct mbchain *mbp, int size); + +int mb_put_uint8(struct mbchain *mbp, u_int8_t x); +int mb_put_uint16be(struct mbchain *mbp, u_int16_t x); +int mb_put_uint16le(struct mbchain *mbp, u_int16_t x); +int mb_put_uint32be(struct mbchain *mbp, u_int32_t x); +int mb_put_uint32le(struct mbchain *mbp, u_int32_t x); +int mb_put_int64be(struct mbchain *mbp, int64_t x); +int mb_put_int64le(struct mbchain *mbp, int64_t x); +int mb_put_mem(struct mbchain *mbp, c_caddr_t source, int size, int type); +int mb_put_mbuf(struct mbchain *mbp, struct mbuf *m); +int mb_put_uio(struct mbchain *mbp, struct uio *uiop, int size); + +int md_init(struct mdchain *mdp); +void md_initm(struct mdchain *mbp, struct mbuf *m); +void md_done(struct mdchain *mdp); +void md_append_record(struct mdchain *mdp, struct mbuf *top); +int md_next_record(struct mdchain *mdp); +int md_get_uint8(struct mdchain *mdp, u_int8_t *x); +int md_get_uint16(struct mdchain *mdp, u_int16_t *x); +int md_get_uint16le(struct mdchain *mdp, u_int16_t *x); +int md_get_uint16be(struct mdchain *mdp, u_int16_t *x); +int md_get_uint32(struct mdchain *mdp, u_int32_t *x); +int md_get_uint32be(struct mdchain *mdp, u_int32_t *x); +int md_get_uint32le(struct mdchain *mdp, u_int32_t *x); +int md_get_int64(struct mdchain *mdp, int64_t *x); +int md_get_int64be(struct mdchain *mdp, int64_t *x); +int md_get_int64le(struct mdchain *mdp, int64_t *x); +int md_get_mem(struct mdchain *mdp, caddr_t target, int size, int type); +int md_get_mbuf(struct mdchain *mdp, int size, struct mbuf **m); +int md_get_uio(struct mdchain *mdp, struct uio *uiop, int size); + +#endif /* ifdef _KERNEL */ + +#endif /* !_SYS_MCHAIN_H_ */ diff --git a/src/include/sys/md4.h b/src/include/sys/md4.h new file mode 100644 index 0000000..05bc8fe --- /dev/null +++ b/src/include/sys/md4.h @@ -0,0 +1,47 @@ +/* MD4.H - header file for MD4C.C + * $FreeBSD: src/sys/sys/md4.h,v 1.1 2001/04/10 07:59:06 bp Exp $ + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All + rights reserved. + + License to copy and use this software is granted provided that it + is identified as the "RSA Data Security, Inc. MD4 Message-Digest + Algorithm" in all material mentioning or referencing this software + or this function. + License is also granted to make and use derivative works provided + that such works are identified as "derived from the RSA Data + Security, Inc. MD4 Message-Digest Algorithm" in all material + mentioning or referencing the derived work. + + RSA Data Security, Inc. makes no representations concerning either + the merchantability of this software or the suitability of this + software for any particular purpose. It is provided "as is" + without express or implied warranty of any kind. + + These notices must be retained in any copies of any part of this + documentation and/or software. + */ + +#ifndef _MD4_H_ +#define _MD4_H_ +/* MD4 context. */ +typedef struct MD4Context { + u_int32_t state[4]; /* state (ABCD) */ + u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD4_CTX; + +#include + +__BEGIN_DECLS +void MD4Init(MD4_CTX *); +void MD4Update(MD4_CTX *, const unsigned char *, unsigned int); +void MD4Pad(MD4_CTX *); +void MD4Final(unsigned char [16], MD4_CTX *); +char * MD4End(MD4_CTX *, char *); +char * MD4File(const char *, char *); +char * MD4Data(const unsigned char *, unsigned int, char *); +__END_DECLS + +#endif /* _MD4_H_ */ diff --git a/src/include/sys/md5.h b/src/include/sys/md5.h new file mode 100644 index 0000000..4eabbf9 --- /dev/null +++ b/src/include/sys/md5.h @@ -0,0 +1,48 @@ +/* MD5.H - header file for MD5C.C + * $FreeBSD: src/sys/sys/md5.h,v 1.16 2002/06/24 14:18:39 mux Exp $ + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD5 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. + +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD5 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. + */ + +#ifndef _SYS_MD5_H_ +#define _SYS_MD5_H_ +/* MD5 context. */ +typedef struct MD5Context { + u_int32_t state[4]; /* state (ABCD) */ + u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + +#include + +__BEGIN_DECLS +void MD5Init (MD5_CTX *); +void MD5Update (MD5_CTX *, const unsigned char *, unsigned int); +void MD5Pad (MD5_CTX *); +void MD5Final (unsigned char [16], MD5_CTX *); +char * MD5End(MD5_CTX *, char *); +char * MD5File(const char *, char *); +char * MD5FileChunk(const char *, char *, off_t, off_t); +char * MD5Data(const unsigned char *, unsigned int, char *); +__END_DECLS +#endif /* _SYS_MD5_H_ */ diff --git a/src/include/sys/mdioctl.h b/src/include/sys/mdioctl.h new file mode 100644 index 0000000..02fd719 --- /dev/null +++ b/src/include/sys/mdioctl.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + * 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. + * + * from: Utah $Hdr: fdioctl.h 1.1 90/07/09$ + * + * @(#)vnioctl.h 8.1 (Berkeley) 6/10/93 + * + * From: src/sys/sys/vnioctl.h,v 1.4 + * + * $FreeBSD: src/sys/sys/mdioctl.h,v 1.15 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_MDIOCTL_H_ +#define _SYS_MDIOCTL_H_ + +enum md_types {MD_MALLOC, MD_PRELOAD, MD_VNODE, MD_SWAP}; + +/* + * Ioctl definitions for memory disk pseudo-device. + */ + +#define MDNPAD 97 +struct md_ioctl { + unsigned md_version; /* Structure layout version */ + unsigned md_unit; /* unit number */ + enum md_types md_type ; /* type of disk */ + char *md_file; /* pathname of file to mount */ + unsigned md_size; /* size of disk in DEV_BSIZE units */ + unsigned md_options; /* options */ + u_int64_t md_base; /* base address */ + int md_secsize; /* sectorsize */ + int md_fwheads; /* firmware heads */ + int md_fwsectors; /* firmware sectors */ + int md_pad[MDNPAD]; /* padding for future ideas */ +}; + +#define MD_NAME "md" +#define MDCTL_NAME "mdctl" +#define MDIOVERSION 0 + +/* + * Before you can use a unit, it must be configured with MDIOCSET. + * The configuration persists across opens and closes of the device; + * an MDIOCCLR must be used to reset a configuration. An attempt to + * MDIOCSET an already active unit will return EBUSY. + */ + +#define MDIOCATTACH _IOWR('m', 0, struct md_ioctl) /* attach disk */ +#define MDIOCDETACH _IOWR('m', 1, struct md_ioctl) /* detach disk */ +#define MDIOCQUERY _IOWR('m', 2, struct md_ioctl) /* query status */ +#define MDIOCLIST _IOWR('m', 3, struct md_ioctl) /* query status */ + +#define MD_CLUSTER 0x01 /* Don't cluster */ +#define MD_RESERVE 0x02 /* Pre-reserve swap */ +#define MD_AUTOUNIT 0x04 /* Assign next free unit */ +#define MD_READONLY 0x08 /* Readonly mode */ +#define MD_COMPRESS 0x10 /* Compression mode */ +#define MD_FORCE 0x20 /* Don't try to prevent foot-shooting */ +#define MD_ASYNC 0x40 /* Don't try to prevent foot-shooting */ + +#endif /* _SYS_MDIOCTL_H_*/ diff --git a/src/include/sys/memrange.h b/src/include/sys/memrange.h new file mode 100644 index 0000000..36c8f85 --- /dev/null +++ b/src/include/sys/memrange.h @@ -0,0 +1,71 @@ +/* + * Memory range attribute operations, peformed on /dev/mem + * + * $FreeBSD: src/sys/sys/memrange.h,v 1.6 2002/09/15 15:07:50 dwmalone Exp $ + */ + +/* Memory range attributes */ +#define MDF_UNCACHEABLE (1<<0) /* region not cached */ +#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" action */ +#define MDF_WRITETHROUGH (1<<2) /* write-through cached */ +#define MDF_WRITEBACK (1<<3) /* write-back cached */ +#define MDF_WRITEPROTECT (1<<4) /* read-only region */ +#define MDF_UNKNOWN (1<<5) /* any state we don't understand */ +#define MDF_ATTRMASK (0x00ffffff) + +#define MDF_FIXBASE (1<<24) /* fixed base */ +#define MDF_FIXLEN (1<<25) /* fixed length */ +#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */ +#define MDF_ACTIVE (1<<27) /* currently active */ +#define MDF_BOGUS (1<<28) /* we don't like it */ +#define MDF_FIXACTIVE (1<<29) /* can't be turned off */ +#define MDF_BUSY (1<<30) /* range is in use */ +#define MDF_FORCE (1<<31) /* force risky changes */ + +struct mem_range_desc +{ + u_int64_t mr_base; + u_int64_t mr_len; + int mr_flags; + char mr_owner[8]; +}; + +struct mem_range_op +{ + struct mem_range_desc *mo_desc; + int mo_arg[2]; +#define MEMRANGE_SET_UPDATE 0 +#define MEMRANGE_SET_REMOVE 1 + /* XXX want a flag that says "set and undo when I exit" */ +}; + +#define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op) +#define MEMRANGE_SET _IOW('m', 51, struct mem_range_op) + +#ifdef _KERNEL + +MALLOC_DECLARE(M_MEMDESC); + +struct mem_range_softc; +struct mem_range_ops +{ + void (*init)(struct mem_range_softc *sc); + int (*set)(struct mem_range_softc *sc, struct mem_range_desc *mrd, int *arg); + void (*initAP)(struct mem_range_softc *sc); +}; + +struct mem_range_softc +{ + struct mem_range_ops *mr_op; + int mr_cap; + int mr_ndesc; + struct mem_range_desc *mr_desc; +}; + +extern struct mem_range_softc mem_range_softc; + +extern int mem_range_attr_get(struct mem_range_desc *mrd, int *arg); +extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg); +extern void mem_range_AP_init(void); +#endif + diff --git a/src/include/sys/mman.h b/src/include/sys/mman.h new file mode 100644 index 0000000..a4c8b6e --- /dev/null +++ b/src/include/sys/mman.h @@ -0,0 +1,196 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)mman.h 8.2 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/mman.h,v 1.39 2004/04/27 13:13:20 mux Exp $ + */ + +#ifndef _SYS_MMAN_H_ +#define _SYS_MMAN_H_ + +#include +#include + +#if __BSD_VISIBLE +/* + * Inheritance for minherit() + */ +#define INHERIT_SHARE 0 +#define INHERIT_COPY 1 +#define INHERIT_NONE 2 +#endif + +/* + * Protections are chosen from these bits, or-ed together + */ +#define PROT_NONE 0x00 /* no permissions */ +#define PROT_READ 0x01 /* pages can be read */ +#define PROT_WRITE 0x02 /* pages can be written */ +#define PROT_EXEC 0x04 /* pages can be executed */ + +/* + * Flags contain sharing type and options. + * Sharing types; choose one. + */ +#define MAP_SHARED 0x0001 /* share changes */ +#define MAP_PRIVATE 0x0002 /* changes are private */ +#define MAP_COPY MAP_PRIVATE /* Obsolete */ + +#if __BSD_VISIBLE +/* + * Other flags + */ +#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ +#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */ +#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */ +#define MAP_RESERVED0080 0x0080 /* previously misimplemented MAP_INHERIT */ +#define MAP_RESERVED0100 0x0100 /* previously unimplemented MAP_NOEXTEND */ +#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */ +#define MAP_STACK 0x0400 /* region grows down, like a stack */ +#define MAP_NOSYNC 0x0800 /* page to but do not sync underlying file */ + +/* + * Mapping type + */ +#define MAP_FILE 0x0000 /* map from file (default) */ +#define MAP_ANON 0x1000 /* allocated from memory, swap space */ + +/* + * Extended flags + */ +#define MAP_NOCORE 0x00020000 /* dont include these pages in a coredump */ +#endif /* __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 199309 +/* + * Process memory locking + */ +#define MCL_CURRENT 0x0001 /* Lock only current memory */ +#define MCL_FUTURE 0x0002 /* Lock all future memory as well */ +#endif + +/* + * Error return from mmap() + */ +#define MAP_FAILED ((void *)-1) + +/* + * msync() flags + */ +#define MS_SYNC 0x0000 /* msync synchronously */ +#define MS_ASYNC 0x0001 /* return immediately */ +#define MS_INVALIDATE 0x0002 /* invalidate all cached data */ + +#if __BSD_VISIBLE +/* + * Advice to madvise + */ +#define MADV_NORMAL 0 /* no further special treatment */ +#define MADV_RANDOM 1 /* expect random page references */ +#define MADV_SEQUENTIAL 2 /* expect sequential page references */ +#define MADV_WILLNEED 3 /* will need these pages */ +#define MADV_DONTNEED 4 /* dont need these pages */ +#define MADV_FREE 5 /* dont need these pages, and junk contents */ +#define MADV_NOSYNC 6 /* try to avoid flushes to physical media */ +#define MADV_AUTOSYNC 7 /* revert to default flushing strategy */ +#define MADV_NOCORE 8 /* do not include these pages in a core file */ +#define MADV_CORE 9 /* revert to including pages in a core file */ +#define MADV_PROTECT 10 /* protect process from pageout kill */ + +/* + * Return bits from mincore + */ +#define MINCORE_INCORE 0x1 /* Page is incore */ +#define MINCORE_REFERENCED 0x2 /* Page has been referenced by us */ +#define MINCORE_MODIFIED 0x4 /* Page has been modified by us */ +#define MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */ +#define MINCORE_MODIFIED_OTHER 0x10 /* Page has been modified */ +#endif /* __BSD_VISIBLE */ + +/* + * XXX missing POSIX_TYPED_MEM_* macros and + * posix_typed_mem_info structure. + */ +#if __POSIX_VISIBLE >= 200112 +#define POSIX_MADV_NORMAL MADV_NORMAL +#define POSIX_MADV_RANDOM MADV_RANDOM +#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL +#define POSIX_MADV_WILLNEED MADV_WILLNEED +#define POSIX_MADV_DONTNEED MADV_DONTNEED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _KERNEL + +__BEGIN_DECLS +/* + * XXX not yet implemented: posix_mem_offset(), posix_typed_mem_get_info(), + * posix_typed_mem_open(). + */ +#if __BSD_VISIBLE +int madvise(void *, size_t, int); +int mincore(const void *, size_t, char *); +int minherit(void *, size_t, int); +#endif +int mlock(const void *, size_t); +#ifndef _MMAP_DECLARED +#define _MMAP_DECLARED +void * mmap(void *, size_t, int, int, int, off_t); +#endif +int mprotect(const void *, size_t, int); +int msync(void *, size_t, int); +int munlock(const void *, size_t); +int munmap(void *, size_t); +#if __POSIX_VISIBLE >= 200112 +int posix_madvise(void *, size_t, int); +#endif +#if __POSIX_VISIBLE >= 199309 +int mlockall(int); +int munlockall(void); +int shm_open(const char *, int, mode_t); +int shm_unlink(const char *); +#endif +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_MMAN_H_ */ diff --git a/src/include/sys/module.h b/src/include/sys/module.h new file mode 100644 index 0000000..65e0529 --- /dev/null +++ b/src/include/sys/module.h @@ -0,0 +1,188 @@ +/*- + * Copyright (c) 1997 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/module.h,v 1.20 2002/03/18 07:45:30 arr Exp $ + */ + +#ifndef _SYS_MODULE_H_ +#define _SYS_MODULE_H_ + +/* + * Module metadata types + */ +#define MDT_DEPEND 1 /* argument is a module name */ +#define MDT_MODULE 2 /* module declaration */ +#define MDT_VERSION 3 /* module version(s) */ + +#define MDT_STRUCT_VERSION 1 /* version of metadata structure */ +#define MDT_SETNAME "modmetadata_set" + +typedef enum modeventtype { + MOD_LOAD, + MOD_UNLOAD, + MOD_SHUTDOWN +} modeventtype_t; + +typedef struct module *module_t; +typedef int (*modeventhand_t)(module_t, int /* modeventtype_t */, void *); + +/* + * Struct for registering modules statically via SYSINIT. + */ +typedef struct moduledata { + const char *name; /* module name */ + modeventhand_t evhand; /* event handler */ + void *priv; /* extra data */ +} moduledata_t; + +/* + * A module can use this to report module specific data to the user via + * kldstat(2). + */ +typedef union modspecific { + int intval; + u_int uintval; + long longval; + u_long ulongval; +} modspecific_t; + +/* + * Module dependency declarartion + */ +struct mod_depend { + int md_ver_minimum; + int md_ver_preferred; + int md_ver_maximum; +}; + +/* + * Module version declaration + */ +struct mod_version { + int mv_version; +}; + +struct mod_metadata { + int md_version; /* structure version MDTV_* */ + int md_type; /* type of entry MDT_* */ + void *md_data; /* specific data */ + const char *md_cval; /* common string label */ +}; + +#ifdef _KERNEL + +#include + +#define MODULE_METADATA(uniquifier, type, data, cval) \ + static struct mod_metadata _mod_metadata##uniquifier = { \ + MDT_STRUCT_VERSION, \ + type, \ + data, \ + cval \ + }; \ + DATA_SET(modmetadata_set, _mod_metadata##uniquifier) + +#define MODULE_DEPEND(module, mdepend, vmin, vpref, vmax) \ + static struct mod_depend _##module##_depend_on_##mdepend = { \ + vmin, \ + vpref, \ + vmax \ + }; \ + MODULE_METADATA(_md_##module##_on_##mdepend, MDT_DEPEND, \ + &_##module##_depend_on_##mdepend, #mdepend) + +#define DECLARE_MODULE(name, data, sub, order) \ + MODULE_METADATA(_md_##name, MDT_MODULE, &data, #name); \ + SYSINIT(name##module, sub, order, module_register_init, &data) \ + struct __hack + +#define MODULE_VERSION(module, version) \ + static struct mod_version _##module##_version = { \ + version \ + }; \ + MODULE_METADATA(_##module##_version, MDT_VERSION, \ + &_##module##_version, #module) + +extern struct sx modules_sx; + +#define MOD_XLOCK sx_xlock(&modules_sx) +#define MOD_SLOCK sx_slock(&modules_sx) +#define MOD_XUNLOCK sx_xunlock(&modules_sx) +#define MOD_SUNLOCK sx_sunlock(&modules_sx) +#define MOD_LOCK_ASSERT sx_assert(&modules_sx, SX_LOCKED) +#define MOD_XLOCK_ASSERT sx_assert(&modules_sx, SX_XLOCKED) + +struct linker_file; + +void module_register_init(const void *); +int module_register(const struct moduledata *, struct linker_file *); +module_t module_lookupbyname(const char *); +module_t module_lookupbyid(int); +void module_reference(module_t); +void module_release(module_t); +int module_unload(module_t); +int module_getid(module_t); +module_t module_getfnext(module_t); +void module_setspecific(module_t, modspecific_t *); + +#ifdef MOD_DEBUG +extern int mod_debug; +#define MOD_DEBUG_REFS 1 + +#define MOD_DPF(cat, args) do { \ + if (mod_debug & MOD_DEBUG_##cat) \ + printf(args); \ +} while (0) + +#else /* !MOD_DEBUG */ + +#define MOD_DPF(cat, args) +#endif +#endif /* _KERNEL */ + +#define MAXMODNAME 32 + +struct module_stat { + int version; /* set to sizeof(struct module_stat) */ + char name[MAXMODNAME]; + int refs; + int id; + modspecific_t data; +}; + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int modnext(int _modid); +int modfnext(int _modid); +int modstat(int _modid, struct module_stat *_stat); +int modfind(const char *_name); +__END_DECLS + +#endif + +#endif /* !_SYS_MODULE_H_ */ diff --git a/src/include/sys/mount.h b/src/include/sys/mount.h new file mode 100644 index 0000000..48c646f --- /dev/null +++ b/src/include/sys/mount.h @@ -0,0 +1,563 @@ +/* + * Copyright (c) 1989, 1991, 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. + * 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. + * + * @(#)mount.h 8.21 (Berkeley) 5/20/95 + * $FreeBSD: src/sys/sys/mount.h,v 1.161 2004/04/11 21:36:31 mux Exp $ + */ + +#ifndef _SYS_MOUNT_H_ +#define _SYS_MOUNT_H_ + +#include +#include +#ifdef _KERNEL +#include +#include +#include +#endif + +typedef struct fsid { int32_t val[2]; } fsid_t; /* filesystem id type */ + +/* + * File identifier. + * These are unique per filesystem on a single machine. + */ +#define MAXFIDSZ 16 + +struct fid { + u_short fid_len; /* length of data in bytes */ + u_short fid_reserved; /* force longword alignment */ + char fid_data[MAXFIDSZ]; /* data (variable length) */ +}; + +/* + * filesystem statistics + */ +#define MFSNAMELEN 16 /* length of type name including null */ +#define MNAMELEN 88 /* size of on/from name bufs */ +#define STATFS_VERSION 0x20030518 /* current version number */ +struct statfs { + uint32_t f_version; /* structure version number */ + uint32_t f_type; /* type of filesystem */ + uint64_t f_flags; /* copy of mount exported flags */ + uint64_t f_bsize; /* filesystem fragment size */ + uint64_t f_iosize; /* optimal transfer block size */ + uint64_t f_blocks; /* total data blocks in filesystem */ + uint64_t f_bfree; /* free blocks in filesystem */ + int64_t f_bavail; /* free blocks avail to non-superuser */ + uint64_t f_files; /* total file nodes in filesystem */ + int64_t f_ffree; /* free nodes avail to non-superuser */ + uint64_t f_syncwrites; /* count of sync writes since mount */ + uint64_t f_asyncwrites; /* count of async writes since mount */ + uint64_t f_syncreads; /* count of sync reads since mount */ + uint64_t f_asyncreads; /* count of async reads since mount */ + uint64_t f_spare[10]; /* unused spare */ + uint32_t f_namemax; /* maximum filename length */ + uid_t f_owner; /* user that mounted the filesystem */ + fsid_t f_fsid; /* filesystem id */ + char f_charspare[80]; /* spare string space */ + char f_fstypename[MFSNAMELEN]; /* filesystem type name */ + char f_mntfromname[MNAMELEN]; /* mounted filesystem */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ +}; + +#ifdef _KERNEL +#define OMFSNAMELEN 16 /* length of fs type name, including null */ +#define OMNAMELEN (88 - 2 * sizeof(long)) /* size of on/from name bufs */ + +/* XXX getfsstat.2 is out of date with write and read counter changes here. */ +/* XXX statfs.2 is out of date with read counter changes here. */ +struct ostatfs { + long f_spare2; /* placeholder */ + long f_bsize; /* fundamental filesystem block size */ + long f_iosize; /* optimal transfer block size */ + long f_blocks; /* total data blocks in filesystem */ + long f_bfree; /* free blocks in fs */ + long f_bavail; /* free blocks avail to non-superuser */ + long f_files; /* total file nodes in filesystem */ + long f_ffree; /* free file nodes in fs */ + fsid_t f_fsid; /* filesystem id */ + uid_t f_owner; /* user that mounted the filesystem */ + int f_type; /* type of filesystem */ + int f_flags; /* copy of mount exported flags */ + long f_syncwrites; /* count of sync writes since mount */ + long f_asyncwrites; /* count of async writes since mount */ + char f_fstypename[OMFSNAMELEN]; /* fs type name */ + char f_mntonname[OMNAMELEN]; /* directory on which mounted */ + long f_syncreads; /* count of sync reads since mount */ + long f_asyncreads; /* count of async reads since mount */ + short f_spares1; /* unused spare */ + char f_mntfromname[OMNAMELEN];/* mounted filesystem */ + short f_spares2; /* unused spare */ + /* + * XXX on machines where longs are aligned to 8-byte boundaries, there + * is an unnamed int32_t here. This spare was after the apparent end + * of the struct until we bit off the read counters from f_mntonname. + */ + long f_spare[2]; /* unused spare */ +}; + +#define MMAXOPTIONLEN 65536 /* maximum length of a mount option */ + +TAILQ_HEAD(vnodelst, vnode); +TAILQ_HEAD(vfsoptlist, vfsopt); +struct vfsopt { + TAILQ_ENTRY(vfsopt) link; + char *name; + void *value; + int len; +}; + +/* + * Structure per mounted filesystem. Each mounted filesystem has an + * array of operations and an instance record. The filesystems are + * put on a doubly linked list. + * + */ +struct mount { + TAILQ_ENTRY(mount) mnt_list; /* mount list */ + struct vfsops *mnt_op; /* operations on fs */ + struct vfsconf *mnt_vfc; /* configuration info */ + struct vnode *mnt_vnodecovered; /* vnode we mounted on */ + struct vnode *mnt_syncer; /* syncer vnode */ + struct vnodelst mnt_nvnodelist; /* list of vnodes this mount */ + struct lock mnt_lock; /* mount structure lock */ + struct mtx mnt_mtx; /* mount structure interlock */ + int mnt_writeopcount; /* write syscalls in progress */ + int mnt_flag; /* flags shared with user */ + struct vfsoptlist *mnt_opt; /* current mount options */ + struct vfsoptlist *mnt_optnew; /* new options passed to fs */ + int mnt_kern_flag; /* kernel only flags */ + int mnt_maxsymlinklen; /* max size of short symlink */ + struct statfs mnt_stat; /* cache of filesystem stats */ + struct ucred *mnt_cred; /* credentials of mounter */ + qaddr_t mnt_data; /* private data */ + time_t mnt_time; /* last time written*/ + int mnt_iosize_max; /* max size for clusters, etc */ + struct netexport *mnt_export; /* export list */ + struct label *mnt_mntlabel; /* MAC label for the mount */ + struct label *mnt_fslabel; /* MAC label for the fs */ + int mnt_nvnodelistsize; /* # of vnodes on this mount */ +}; + + +#define MNT_ILOCK(mp) mtx_lock(&(mp)->mnt_mtx) +#define MNT_IUNLOCK(mp) mtx_unlock(&(mp)->mnt_mtx) + +#endif /* _KERNEL */ + +/* + * User specifiable flags. + */ +#define MNT_RDONLY 0x00000001 /* read only filesystem */ +#define MNT_SYNCHRONOUS 0x00000002 /* filesystem written synchronously */ +#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ +#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ +#define MNT_NODEV 0x00000010 /* don't interpret special files */ +#define MNT_UNION 0x00000020 /* union with underlying filesystem */ +#define MNT_ASYNC 0x00000040 /* filesystem written asynchronously */ +#define MNT_SUIDDIR 0x00100000 /* special handling of SUID on dirs */ +#define MNT_SOFTDEP 0x00200000 /* soft updates being done */ +#define MNT_NOSYMFOLLOW 0x00400000 /* do not follow symlinks */ +#define MNT_JAILDEVFS 0x02000000 /* jail-friendly DEVFS behaviour */ +#define MNT_MULTILABEL 0x04000000 /* MAC support for individual objects */ +#define MNT_ACLS 0x08000000 /* ACL support enabled */ +#define MNT_NOATIME 0x10000000 /* disable update of file access time */ +#define MNT_NOCLUSTERR 0x40000000 /* disable cluster read */ +#define MNT_NOCLUSTERW 0x80000000 /* disable cluster write */ + +/* + * NFS export related mount flags. + */ +#define MNT_EXRDONLY 0x00000080 /* exported read only */ +#define MNT_EXPORTED 0x00000100 /* filesystem is exported */ +#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ +#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ +#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */ +#define MNT_EXPUBLIC 0x20000000 /* public export (WebNFS) */ + +/* + * Flags set by internal operations, + * but visible to the user. + * XXX some of these are not quite right.. (I've never seen the root flag set) + */ +#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ +#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ +#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ +#define MNT_USER 0x00008000 /* mounted by a user */ +#define MNT_IGNORE 0x00800000 /* do not show entry in df */ + +/* + * Mask of flags that are visible to statfs(). + * XXX I think that this could now become (~(MNT_CMDFLAGS)) + * but the 'mount' program may need changing to handle this. + */ +#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \ + MNT_NOSUID | MNT_NODEV | MNT_UNION | \ + MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \ + MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \ + MNT_LOCAL | MNT_USER | MNT_QUOTA | \ + MNT_ROOTFS | MNT_NOATIME | MNT_NOCLUSTERR| \ + MNT_NOCLUSTERW | MNT_SUIDDIR | MNT_SOFTDEP | \ + MNT_IGNORE | MNT_EXPUBLIC | MNT_NOSYMFOLLOW | \ + MNT_JAILDEVFS | MNT_MULTILABEL | MNT_ACLS) + +/* Mask of flags that can be updated. */ +#define MNT_UPDATEMASK (MNT_NOSUID | MNT_NOEXEC | MNT_NODEV | \ + MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | \ + MNT_NOATIME | \ + MNT_NOSYMFOLLOW | MNT_IGNORE | MNT_JAILDEVFS | \ + MNT_NOCLUSTERR | MNT_NOCLUSTERW | MNT_SUIDDIR | \ + MNT_ACLS | MNT_USER) + +/* + * External filesystem command modifier flags. + * Unmount can use the MNT_FORCE flag. + * XXX These are not STATES and really should be somewhere else. + */ +#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ +#define MNT_DELEXPORT 0x00020000 /* delete export host lists */ +#define MNT_RELOAD 0x00040000 /* reload filesystem data */ +#define MNT_FORCE 0x00080000 /* force unmount or readonly change */ +#define MNT_SNAPSHOT 0x01000000 /* snapshot the filesystem */ +#define MNT_BYFSID 0x08000000 /* specify filesystem by ID. */ +#define MNT_CMDFLAGS (MNT_UPDATE | MNT_DELEXPORT | MNT_RELOAD | \ + MNT_FORCE | MNT_SNAPSHOT | MNT_BYFSID) +/* + * Internal filesystem control flags stored in mnt_kern_flag. + * + * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed + * past the mount point. This keeps the subtree stable during mounts + * and unmounts. + * + * MNTK_UNMOUNTF permits filesystems to detect a forced unmount while + * dounmount() is still waiting to lock the mountpoint. This allows + * the filesystem to cancel operations that might otherwise deadlock + * with the unmount attempt (used by NFS). + */ +#define MNTK_UNMOUNTF 0x00000001 /* forced unmount in progress */ +#define MNTK_UNMOUNT 0x01000000 /* unmount in progress */ +#define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */ +#define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */ +#define MNTK_SUSPEND 0x08000000 /* request write suspension */ +#define MNTK_SUSPENDED 0x10000000 /* write operations are suspended */ + +/* + * Sysctl CTL_VFS definitions. + * + * Second level identifier specifies which filesystem. Second level + * identifier VFS_VFSCONF returns information about all filesystems. + * Second level identifier VFS_GENERIC is non-terminal. + */ +#define VFS_VFSCONF 0 /* get configured filesystems */ +#define VFS_GENERIC 0 /* generic filesystem information */ +/* + * Third level identifiers for VFS_GENERIC are given below; third + * level identifiers for specific filesystems are given in their + * mount specific header files. + */ +#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ +#define VFS_CONF 2 /* struct: vfsconf for filesystem given + as next argument */ + +/* + * Flags for various system call interfaces. + * + * waitfor flags to vfs_sync() and getfsstat() + */ +#define MNT_WAIT 1 /* synchronously wait for I/O to complete */ +#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */ +#define MNT_LAZY 3 /* push data not written by filesystem syncer */ + +/* + * Generic file handle + */ +struct fhandle { + fsid_t fh_fsid; /* Filesystem id of mount point */ + struct fid fh_fid; /* Filesys specific id */ +}; +typedef struct fhandle fhandle_t; + +/* + * Export arguments for local filesystem mount calls. + */ +struct export_args { + int ex_flags; /* export related flags */ + uid_t ex_root; /* mapping for root uid */ + struct xucred ex_anon; /* mapping for anonymous user */ + struct sockaddr *ex_addr; /* net address to which exported */ + u_char ex_addrlen; /* and the net address length */ + struct sockaddr *ex_mask; /* mask of valid bits in saddr */ + u_char ex_masklen; /* and the smask length */ + char *ex_indexfile; /* index file for WebNFS URLs */ +}; + +/* + * Structure holding information for a publicly exported filesystem + * (WebNFS). Currently the specs allow just for one such filesystem. + */ +struct nfs_public { + int np_valid; /* Do we hold valid information */ + fhandle_t np_handle; /* Filehandle for pub fs (internal) */ + struct mount *np_mount; /* Mountpoint of exported fs */ + char *np_index; /* Index file */ +}; + +/* + * Filesystem configuration information. One of these exists for each + * type of filesystem supported by the kernel. These are searched at + * mount time to identify the requested filesystem. + */ +struct vfsconf { + struct vfsops *vfc_vfsops; /* filesystem operations vector */ + char vfc_name[MFSNAMELEN]; /* filesystem type name */ + int vfc_typenum; /* historic filesystem type number */ + int vfc_refcount; /* number mounted of this type */ + int vfc_flags; /* permanent flags */ + struct vfsoptdecl *vfc_opts; /* mount options */ + struct vfsconf *vfc_next; /* next in list */ +}; + +/* Userland version of the struct vfsconf. */ +struct xvfsconf { + struct vfsops *vfc_vfsops; /* filesystem operations vector */ + char vfc_name[MFSNAMELEN]; /* filesystem type name */ + int vfc_typenum; /* historic filesystem type number */ + int vfc_refcount; /* number mounted of this type */ + int vfc_flags; /* permanent flags */ + struct vfsconf *vfc_next; /* next in list */ +}; + +#ifndef BURN_BRIDGES +struct ovfsconf { + void *vfc_vfsops; + char vfc_name[32]; + int vfc_index; + int vfc_refcount; + int vfc_flags; +}; +#endif + +/* + * NB: these flags refer to IMPLEMENTATION properties, not properties of + * any actual mounts; i.e., it does not make sense to change the flags. + */ +#define VFCF_STATIC 0x00010000 /* statically compiled into kernel */ +#define VFCF_NETWORK 0x00020000 /* may get data over the network */ +#define VFCF_READONLY 0x00040000 /* writes are not implemented */ +#define VFCF_SYNTHETIC 0x00080000 /* data does not represent real files */ +#define VFCF_LOOPBACK 0x00100000 /* aliases some other mounted FS */ +#define VFCF_UNICODE 0x00200000 /* stores file names as Unicode*/ + +struct iovec; +struct uio; + +#ifdef _KERNEL + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_MOUNT); +#endif +extern int maxvfsconf; /* highest defined filesystem type */ +extern int nfs_mount_type; /* vfc_typenum for nfs, or -1 */ +extern struct vfsconf *vfsconf; /* head of list of filesystem types */ + +/* + * Operations supported on mounted filesystem. + */ +struct mount_args; +struct nameidata; + +typedef int vfs_mount_t(struct mount *mp, char *path, caddr_t data, + struct nameidata *ndp, struct thread *td); +typedef int vfs_start_t(struct mount *mp, int flags, struct thread *td); +typedef int vfs_unmount_t(struct mount *mp, int mntflags, struct thread *td); +typedef int vfs_root_t(struct mount *mp, struct vnode **vpp); +typedef int vfs_quotactl_t(struct mount *mp, int cmds, uid_t uid, + caddr_t arg, struct thread *td); +typedef int vfs_statfs_t(struct mount *mp, struct statfs *sbp, + struct thread *td); +typedef int vfs_sync_t(struct mount *mp, int waitfor, struct ucred *cred, + struct thread *td); +typedef int vfs_vget_t(struct mount *mp, ino_t ino, int flags, + struct vnode **vpp); +typedef int vfs_fhtovp_t(struct mount *mp, struct fid *fhp, struct vnode **vpp); +typedef int vfs_checkexp_t(struct mount *mp, struct sockaddr *nam, + int *extflagsp, struct ucred **credanonp); +typedef int vfs_vptofh_t(struct vnode *vp, struct fid *fhp); +typedef int vfs_init_t(struct vfsconf *); +typedef int vfs_uninit_t(struct vfsconf *); +typedef int vfs_extattrctl_t(struct mount *mp, int cmd, + struct vnode *filename_vp, int attrnamespace, + const char *attrname, struct thread *td); +typedef int vfs_nmount_t(struct mount *mp, struct nameidata *ndp, + struct thread *td); + +struct vfsops { + vfs_mount_t *vfs_mount; + vfs_start_t *vfs_start; + vfs_unmount_t *vfs_unmount; + vfs_root_t *vfs_root; + vfs_quotactl_t *vfs_quotactl; + vfs_statfs_t *vfs_statfs; + vfs_sync_t *vfs_sync; + vfs_vget_t *vfs_vget; + vfs_fhtovp_t *vfs_fhtovp; + vfs_checkexp_t *vfs_checkexp; + vfs_vptofh_t *vfs_vptofh; + vfs_init_t *vfs_init; + vfs_uninit_t *vfs_uninit; + vfs_extattrctl_t *vfs_extattrctl; + /* Additions below are not binary compatible with 5.0 and below. */ + vfs_nmount_t *vfs_nmount; +}; + +#define VFS_NMOUNT(MP, NDP, P) (*(MP)->mnt_op->vfs_nmount)(MP, NDP, P) +#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ + (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) +#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) +#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) +#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) +#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) +#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) +#define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P) +#define VFS_VGET(MP, INO, FLAGS, VPP) \ + (*(MP)->mnt_op->vfs_vget)(MP, INO, FLAGS, VPP) +#define VFS_FHTOVP(MP, FIDP, VPP) \ + (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, VPP) +#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) +#define VFS_CHECKEXP(MP, NAM, EXFLG, CRED) \ + (*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED) +#define VFS_EXTATTRCTL(MP, C, FN, NS, N, P) \ + (*(MP)->mnt_op->vfs_extattrctl)(MP, C, FN, NS, N, P) + +#include + +#define VFS_SET(vfsops, fsname, flags) \ + static struct vfsconf fsname ## _vfsconf = { \ + &vfsops, \ + #fsname, \ + -1, \ + 0, \ + flags \ + }; \ + static moduledata_t fsname ## _mod = { \ + #fsname, \ + vfs_modevent, \ + & fsname ## _vfsconf \ + }; \ + DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE) + +extern char *mountrootfsname; + +/* + * exported vnode operations + */ +int dounmount(struct mount *, int, struct thread *); +int kernel_mount(struct iovec *, u_int, int); +int kernel_vmount(int flags, ...); +int vfs_getopt(struct vfsoptlist *, const char *, void **, int *); +int vfs_copyopt(struct vfsoptlist *, const char *, void *, int); +int vfs_mount(struct thread *, const char *, char *, int, void *); +int vfs_nmount(struct thread *, int, struct uio *); +int vfs_setpublicfs /* set publicly exported fs */ + (struct mount *, struct netexport *, struct export_args *); +int vfs_lock(struct mount *); /* lock a vfs */ +void vfs_msync(struct mount *, int); +void vfs_unlock(struct mount *); /* unlock a vfs */ +int vfs_busy(struct mount *, int, struct mtx *, struct thread *); +int vfs_export /* process mount export info */ + (struct mount *, struct export_args *); +struct netcred *vfs_export_lookup /* lookup host in fs export list */ + (struct mount *, struct sockaddr *); +int vfs_allocate_syncvnode(struct mount *); +void vfs_getnewfsid(struct mount *); +dev_t vfs_getrootfsid(struct mount *); +struct mount *vfs_getvfs(fsid_t *); /* return vfs given fsid */ +int vfs_modevent(module_t, int, void *); +int vfs_mountedon(struct vnode *); /* is a vfs mounted on vp */ +void vfs_mountroot(void); /* mount our root filesystem */ +int vfs_rootmountalloc(char *, char *, struct mount **); +void vfs_mount_destroy(struct mount *, struct thread *); +void vfs_unbusy(struct mount *, struct thread *); +void vfs_unmountall(void); +int vfs_register(struct vfsconf *); +int vfs_unregister(struct vfsconf *); +extern TAILQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ +extern struct mtx mountlist_mtx; +extern struct nfs_public nfs_pub; + +/* + * Declarations for these vfs default operations are located in + * kern/vfs_default.c, they should be used instead of making "dummy" + * functions or casting entries in the VFS op table to "enopnotsupp()". + */ +vfs_start_t vfs_stdstart; +vfs_root_t vfs_stdroot; +vfs_quotactl_t vfs_stdquotactl; +vfs_statfs_t vfs_stdstatfs; +vfs_sync_t vfs_stdsync; +vfs_sync_t vfs_stdnosync; +vfs_vget_t vfs_stdvget; +vfs_fhtovp_t vfs_stdfhtovp; +vfs_checkexp_t vfs_stdcheckexp; +vfs_vptofh_t vfs_stdvptofh; +vfs_init_t vfs_stdinit; +vfs_uninit_t vfs_stduninit; +vfs_extattrctl_t vfs_stdextattrctl; + +/* XXX - these should be indirect functions!!! */ +int softdep_fsync(struct vnode *); +int softdep_process_worklist(struct mount *); + +#else /* !_KERNEL */ + +#include + +struct stat; + +__BEGIN_DECLS +int fhopen(const struct fhandle *, int); +int fhstat(const struct fhandle *, struct stat *); +int fhstatfs(const struct fhandle *, struct statfs *); +int fstatfs(int, struct statfs *); +int getfh(const char *, fhandle_t *); +int getfsstat(struct statfs *, long, int); +int getmntinfo(struct statfs **, int); +int lgetfh(const char *, fhandle_t *); +int mount(const char *, const char *, int, void *); +int nmount(struct iovec *, unsigned int, int); +int statfs(const char *, struct statfs *); +int unmount(const char *, int); + +/* C library stuff */ +int getvfsbyname(const char *, struct xvfsconf *); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_MOUNT_H_ */ diff --git a/src/include/sys/mouse.h b/src/include/sys/mouse.h new file mode 100644 index 0000000..c32c31c --- /dev/null +++ b/src/include/sys/mouse.h @@ -0,0 +1,336 @@ +/*- + * Copyright (c) 1992, 1993 Erik Forsberg. + * Copyright (c) 1996, 1997 Kazutaka YOKOTA + * 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. + * + * THIS SOFTWARE IS PROVIDED BY ``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 I 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. + * + * $FreeBSD: src/sys/sys/mouse.h,v 1.19 2002/03/24 03:07:07 will Exp $ + */ + +#ifndef _SYS_MOUSE_H_ +#define _SYS_MOUSE_H_ + +#include +#include + +/* ioctls */ +#define MOUSE_GETSTATUS _IOR('M', 0, mousestatus_t) +#define MOUSE_GETHWINFO _IOR('M', 1, mousehw_t) +#define MOUSE_GETMODE _IOR('M', 2, mousemode_t) +#define MOUSE_SETMODE _IOW('M', 3, mousemode_t) +#define MOUSE_GETLEVEL _IOR('M', 4, int) +#define MOUSE_SETLEVEL _IOW('M', 5, int) +#define MOUSE_GETVARS _IOR('M', 6, mousevar_t) +#define MOUSE_SETVARS _IOW('M', 7, mousevar_t) +#define MOUSE_READSTATE _IOWR('M', 8, mousedata_t) +#define MOUSE_READDATA _IOWR('M', 9, mousedata_t) + +#if notyet +#define MOUSE_SETRESOLUTION _IOW('M', 10, int) +#define MOUSE_SETSCALING _IOW('M', 11, int) +#define MOUSE_SETRATE _IOW('M', 12, int) +#define MOUSE_GETHWID _IOR('M', 13, int) +#endif + +/* mouse status block */ +typedef struct mousestatus { + int flags; /* state change flags */ + int button; /* button status */ + int obutton; /* previous button status */ + int dx; /* x movement */ + int dy; /* y movement */ + int dz; /* z movement */ +} mousestatus_t; + +/* button */ +#define MOUSE_BUTTON1DOWN 0x0001 /* left */ +#define MOUSE_BUTTON2DOWN 0x0002 /* middle */ +#define MOUSE_BUTTON3DOWN 0x0004 /* right */ +#define MOUSE_BUTTON4DOWN 0x0008 +#define MOUSE_BUTTON5DOWN 0x0010 +#define MOUSE_BUTTON6DOWN 0x0020 +#define MOUSE_BUTTON7DOWN 0x0040 +#define MOUSE_BUTTON8DOWN 0x0080 +#define MOUSE_MAXBUTTON 31 +#define MOUSE_STDBUTTONS 0x0007 /* buttons 1-3 */ +#define MOUSE_EXTBUTTONS 0x7ffffff8 /* the others (28 of them!) */ +#define MOUSE_BUTTONS (MOUSE_STDBUTTONS | MOUSE_EXTBUTTONS) + +/* flags */ +#define MOUSE_STDBUTTONSCHANGED MOUSE_STDBUTTONS +#define MOUSE_EXTBUTTONSCHANGED MOUSE_EXTBUTTONS +#define MOUSE_BUTTONSCHANGED MOUSE_BUTTONS +#define MOUSE_POSCHANGED 0x80000000 + +typedef struct mousehw { + int buttons; /* -1 if unknown */ + int iftype; /* MOUSE_IF_XXX */ + int type; /* mouse/track ball/pad... */ + int model; /* I/F dependent model ID: MOUSE_MODEL_XXX */ + int hwid; /* I/F dependent hardware ID + * for the PS/2 mouse, it will be PSM_XXX_ID + */ +} mousehw_t; + +/* iftype */ +#define MOUSE_IF_UNKNOWN (-1) +#define MOUSE_IF_SERIAL 0 +#define MOUSE_IF_BUS 1 +#define MOUSE_IF_INPORT 2 +#define MOUSE_IF_PS2 3 +#define MOUSE_IF_SYSMOUSE 4 +#define MOUSE_IF_USB 5 + +/* type */ +#define MOUSE_UNKNOWN (-1) /* should be treated as a mouse */ +#define MOUSE_MOUSE 0 +#define MOUSE_TRACKBALL 1 +#define MOUSE_STICK 2 +#define MOUSE_PAD 3 + +/* model */ +#define MOUSE_MODEL_UNKNOWN (-1) +#define MOUSE_MODEL_GENERIC 0 +#define MOUSE_MODEL_GLIDEPOINT 1 +#define MOUSE_MODEL_NETSCROLL 2 +#define MOUSE_MODEL_NET 3 +#define MOUSE_MODEL_INTELLI 4 +#define MOUSE_MODEL_THINK 5 +#define MOUSE_MODEL_EASYSCROLL 6 +#define MOUSE_MODEL_MOUSEMANPLUS 7 +#define MOUSE_MODEL_KIDSPAD 8 +#define MOUSE_MODEL_VERSAPAD 9 +#define MOUSE_MODEL_EXPLORER 10 +#define MOUSE_MODEL_4D 11 +#define MOUSE_MODEL_4DPLUS 12 + +typedef struct mousemode { + int protocol; /* MOUSE_PROTO_XXX */ + int rate; /* report rate (per sec), -1 if unknown */ + int resolution; /* MOUSE_RES_XXX, -1 if unknown */ + int accelfactor; /* accelation factor (must be 1 or greater) */ + int level; /* driver operation level */ + int packetsize; /* the length of the data packet */ + unsigned char syncmask[2]; /* sync. data bits in the header byte */ +} mousemode_t; + +/* protocol */ +/* + * Serial protocols: + * Microsoft, MouseSystems, Logitech, MM series, MouseMan, Hitachi Tablet, + * GlidePoint, IntelliMouse, Thinking Mouse, MouseRemote, Kidspad, + * VersaPad + * Bus mouse protocols: + * bus, InPort + * PS/2 mouse protocol: + * PS/2 + */ +#define MOUSE_PROTO_UNKNOWN (-1) +#define MOUSE_PROTO_MS 0 /* Microsoft Serial, 3 bytes */ +#define MOUSE_PROTO_MSC 1 /* Mouse Systems, 5 bytes */ +#define MOUSE_PROTO_LOGI 2 /* Logitech, 3 bytes */ +#define MOUSE_PROTO_MM 3 /* MM series, 3 bytes */ +#define MOUSE_PROTO_LOGIMOUSEMAN 4 /* Logitech MouseMan 3/4 bytes */ +#define MOUSE_PROTO_BUS 5 /* MS/Logitech bus mouse */ +#define MOUSE_PROTO_INPORT 6 /* MS/ATI InPort mouse */ +#define MOUSE_PROTO_PS2 7 /* PS/2 mouse, 3 bytes */ +#define MOUSE_PROTO_HITTAB 8 /* Hitachi Tablet 3 bytes */ +#define MOUSE_PROTO_GLIDEPOINT 9 /* ALPS GlidePoint, 3/4 bytes */ +#define MOUSE_PROTO_INTELLI 10 /* MS IntelliMouse, 4 bytes */ +#define MOUSE_PROTO_THINK 11 /* Kensignton Thinking Mouse, 3/4 bytes */ +#define MOUSE_PROTO_SYSMOUSE 12 /* /dev/sysmouse */ +#define MOUSE_PROTO_X10MOUSEREM 13 /* X10 MouseRemote, 3 bytes */ +#define MOUSE_PROTO_KIDSPAD 14 /* Genius Kidspad */ +#define MOUSE_PROTO_VERSAPAD 15 /* Interlink VersaPad, 6 bytes */ +#define MOUSE_PROTO_JOGDIAL 16 /* Vaio's JogDial */ + +#define MOUSE_RES_UNKNOWN (-1) +#define MOUSE_RES_DEFAULT 0 +#define MOUSE_RES_LOW (-2) +#define MOUSE_RES_MEDIUMLOW (-3) +#define MOUSE_RES_MEDIUMHIGH (-4) +#define MOUSE_RES_HIGH (-5) + +typedef struct mousedata { + int len; /* # of data in the buffer */ + int buf[16]; /* data buffer */ +} mousedata_t; + +#if (defined(MOUSE_GETVARS)) + +typedef struct mousevar { + int var[16]; +} mousevar_t; + +/* magic numbers in var[0] */ +#define MOUSE_VARS_PS2_SIG 0x00325350 /* 'PS2' */ +#define MOUSE_VARS_BUS_SIG 0x00535542 /* 'BUS' */ +#define MOUSE_VARS_INPORT_SIG 0x00504e49 /* 'INP' */ + +#endif /* MOUSE_GETVARS */ + +/* Microsoft Serial mouse data packet */ +#define MOUSE_MSS_PACKETSIZE 3 +#define MOUSE_MSS_SYNCMASK 0x40 +#define MOUSE_MSS_SYNC 0x40 +#define MOUSE_MSS_BUTTONS 0x30 +#define MOUSE_MSS_BUTTON1DOWN 0x20 /* left */ +#define MOUSE_MSS_BUTTON2DOWN 0x00 /* no middle button */ +#define MOUSE_MSS_BUTTON3DOWN 0x10 /* right */ + +/* Logitech MouseMan data packet (M+ protocol) */ +#define MOUSE_LMAN_BUTTON2DOWN 0x20 /* middle button, the 4th byte */ + +/* ALPS GlidePoint extension (variant of M+ protocol) */ +#define MOUSE_ALPS_BUTTON2DOWN 0x20 /* middle button, the 4th byte */ +#define MOUSE_ALPS_TAP 0x10 /* `tapping' action, the 4th byte */ + +/* Kinsington Thinking Mouse extension (variant of M+ protocol) */ +#define MOUSE_THINK_BUTTON2DOWN 0x20 /* lower-left button, the 4th byte */ +#define MOUSE_THINK_BUTTON4DOWN 0x10 /* lower-right button, the 4th byte */ + +/* MS IntelliMouse (variant of MS Serial) */ +#define MOUSE_INTELLI_PACKETSIZE 4 +#define MOUSE_INTELLI_BUTTON2DOWN 0x10 /* middle button in the 4th byte */ + +/* Mouse Systems Corp. mouse data packet */ +#define MOUSE_MSC_PACKETSIZE 5 +#define MOUSE_MSC_SYNCMASK 0xf8 +#define MOUSE_MSC_SYNC 0x80 +#define MOUSE_MSC_BUTTONS 0x07 +#define MOUSE_MSC_BUTTON1UP 0x04 /* left */ +#define MOUSE_MSC_BUTTON2UP 0x02 /* middle */ +#define MOUSE_MSC_BUTTON3UP 0x01 /* right */ +#define MOUSE_MSC_MAXBUTTON 3 + +/* MM series mouse data packet */ +#define MOUSE_MM_PACKETSIZE 3 +#define MOUSE_MM_SYNCMASK 0xe0 +#define MOUSE_MM_SYNC 0x80 +#define MOUSE_MM_BUTTONS 0x07 +#define MOUSE_MM_BUTTON1DOWN 0x04 /* left */ +#define MOUSE_MM_BUTTON2DOWN 0x02 /* middle */ +#define MOUSE_MM_BUTTON3DOWN 0x01 /* right */ +#define MOUSE_MM_XPOSITIVE 0x10 +#define MOUSE_MM_YPOSITIVE 0x08 + +/* PS/2 mouse data packet */ +#define MOUSE_PS2_PACKETSIZE 3 +#define MOUSE_PS2_SYNCMASK 0xc8 +#define MOUSE_PS2_SYNC 0x08 +#define MOUSE_PS2_BUTTONS 0x07 /* 0x03 for 2 button mouse */ +#define MOUSE_PS2_BUTTON1DOWN 0x01 /* left */ +#define MOUSE_PS2_BUTTON2DOWN 0x04 /* middle */ +#define MOUSE_PS2_BUTTON3DOWN 0x02 /* right */ +#define MOUSE_PS2_TAP MOUSE_PS2_SYNC /* GlidePoint (PS/2) `tapping' + * Yes! this is the same bit + * as SYNC! + */ + +#define MOUSE_PS2_XNEG 0x10 +#define MOUSE_PS2_YNEG 0x20 +#define MOUSE_PS2_XOVERFLOW 0x40 +#define MOUSE_PS2_YOVERFLOW 0x80 + +/* Logitech MouseMan+ (PS/2) data packet (PS/2++ protocol) */ +#define MOUSE_PS2PLUS_SYNCMASK 0x48 +#define MOUSE_PS2PLUS_SYNC 0x48 +#define MOUSE_PS2PLUS_ZNEG 0x08 /* sign bit */ +#define MOUSE_PS2PLUS_BUTTON4DOWN 0x10 /* 4th button on MouseMan+ */ +#define MOUSE_PS2PLUS_BUTTON5DOWN 0x20 + +/* IBM ScrollPoint (PS/2) also uses PS/2++ protocol */ +#define MOUSE_SPOINT_ZNEG 0x80 /* sign bits */ +#define MOUSE_SPOINT_WNEG 0x08 + +/* MS IntelliMouse (PS/2) data packet */ +#define MOUSE_PS2INTELLI_PACKETSIZE 4 +/* some compatible mice have additional buttons */ +#define MOUSE_PS2INTELLI_BUTTON4DOWN 0x40 +#define MOUSE_PS2INTELLI_BUTTON5DOWN 0x80 + +/* MS IntelliMouse Explorer (PS/2) data packet (variation of IntelliMouse) */ +#define MOUSE_EXPLORER_ZNEG 0x08 /* sign bit */ +/* IntelliMouse Explorer has additional button data in the fourth byte */ +#define MOUSE_EXPLORER_BUTTON4DOWN 0x10 +#define MOUSE_EXPLORER_BUTTON5DOWN 0x20 + +/* Interlink VersaPad (serial I/F) data packet */ +#define MOUSE_VERSA_PACKETSIZE 6 +#define MOUSE_VERSA_IN_USE 0x04 +#define MOUSE_VERSA_SYNCMASK 0xc3 +#define MOUSE_VERSA_SYNC 0xc0 +#define MOUSE_VERSA_BUTTONS 0x30 +#define MOUSE_VERSA_BUTTON1DOWN 0x20 /* left */ +#define MOUSE_VERSA_BUTTON2DOWN 0x00 /* middle */ +#define MOUSE_VERSA_BUTTON3DOWN 0x10 /* right */ +#define MOUSE_VERSA_TAP 0x08 + +/* Interlink VersaPad (PS/2 I/F) data packet */ +#define MOUSE_PS2VERSA_PACKETSIZE 6 +#define MOUSE_PS2VERSA_IN_USE 0x10 +#define MOUSE_PS2VERSA_SYNCMASK 0xe8 +#define MOUSE_PS2VERSA_SYNC 0xc8 +#define MOUSE_PS2VERSA_BUTTONS 0x05 +#define MOUSE_PS2VERSA_BUTTON1DOWN 0x04 /* left */ +#define MOUSE_PS2VERSA_BUTTON2DOWN 0x00 /* middle */ +#define MOUSE_PS2VERSA_BUTTON3DOWN 0x01 /* right */ +#define MOUSE_PS2VERSA_TAP 0x02 + +/* A4 Tech 4D Mouse (PS/2) data packet */ +#define MOUSE_4D_PACKETSIZE 3 +#define MOUSE_4D_WHEELBITS 0xf0 + +/* A4 Tech 4D+ Mouse (PS/2) data packet */ +#define MOUSE_4DPLUS_PACKETSIZE 3 +#define MOUSE_4DPLUS_ZNEG 0x04 /* sign bit */ +#define MOUSE_4DPLUS_BUTTON4DOWN 0x08 + +/* sysmouse extended data packet */ +/* + * /dev/sysmouse sends data in two formats, depending on the protocol + * level. At the level 0, format is exactly the same as MousSystems' + * five byte packet. At the level 1, the first five bytes are the same + * as at the level 0. There are additional three bytes which shows + * `dz' and the states of additional buttons. `dz' is expressed as the + * sum of the byte 5 and 6 which contain signed seven bit values. + * The states of the button 4 though 10 are in the bit 0 though 6 in + * the byte 7 respectively: 1 indicates the button is up. + */ +#define MOUSE_SYS_PACKETSIZE 8 +#define MOUSE_SYS_SYNCMASK 0xf8 +#define MOUSE_SYS_SYNC 0x80 +#define MOUSE_SYS_BUTTON1UP 0x04 /* left, 1st byte */ +#define MOUSE_SYS_BUTTON2UP 0x02 /* middle, 1st byte */ +#define MOUSE_SYS_BUTTON3UP 0x01 /* right, 1st byte */ +#define MOUSE_SYS_BUTTON4UP 0x0001 /* 7th byte */ +#define MOUSE_SYS_BUTTON5UP 0x0002 +#define MOUSE_SYS_BUTTON6UP 0x0004 +#define MOUSE_SYS_BUTTON7UP 0x0008 +#define MOUSE_SYS_BUTTON8UP 0x0010 +#define MOUSE_SYS_BUTTON9UP 0x0020 +#define MOUSE_SYS_BUTTON10UP 0x0040 +#define MOUSE_SYS_MAXBUTTON 10 +#define MOUSE_SYS_STDBUTTONS 0x07 +#define MOUSE_SYS_EXTBUTTONS 0x7f /* the others */ + +/* Mouse remote socket */ +#define _PATH_MOUSEREMOTE "/var/run/MouseRemote" + +#endif /* _SYS_MOUSE_H_ */ diff --git a/src/include/sys/mpi.h b/src/include/sys/mpi.h new file mode 100644 index 0000000..d0f2a7e --- /dev/null +++ b/src/include/sys/mpi.h @@ -0,0 +1,73 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MPI_H +#define _MPI_H + +#include + +#define MESSAGE_LENGTH 248 + +struct mpiMessage { + char data[MESSAGE_LENGTH]; + uInt32 type; + struct mpiMessage *next; + }; + +typedef struct mpiMessage mpiMessage_t; + + +int mpiCreateMbox(char *); +int mpiDestroyMbox(char *); +int mpiPostMessage(char *,uInt32,void *); +int mpiFetchMessage(char *,mpiMessage_t *); +int mpiSpam(uInt32 type,void *); + +#endif + +/*** + $Log$ + Revision 1.4 2004/05/28 03:53:30 reddawg + mpi: oops can't forget userland + + Revision 1.3 2004/05/26 15:39:22 reddawg + mpi: brought mpiDestroyMbox(char *name) in to the userland + + Revision 1.2 2004/05/25 18:48:48 reddawg + Userland now uses MESSAGE_LENGTH + + Revision 1.1 2004/05/25 15:43:27 reddawg + Added Userland MPI access + + Revision 1.1 2004/05/25 14:07:01 reddawg + Sorry we can't forget the headers files + + END + ***/ + diff --git a/src/include/sys/msg.h b/src/include/sys/msg.h new file mode 100644 index 0000000..afd9c61 --- /dev/null +++ b/src/include/sys/msg.h @@ -0,0 +1,138 @@ +/* $FreeBSD: src/sys/sys/msg.h,v 1.16 2003/01/26 20:09:34 alfred Exp $ */ +/* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */ + +/* + * SVID compatible msg.h file + * + * Author: Daniel Boulet + * + * Copyright 1993 Daniel Boulet and RTMX Inc. + * + * This system call was implemented by Daniel Boulet under contract from RTMX. + * + * Redistribution and use in source forms, with and without modification, + * are permitted provided that this entire comment appears intact. + * + * Redistribution in binary form may occur without any restrictions. + * Obviously, it would be nice if you gave credit where credit is due + * but requiring it would be too onerous. + * + * This software is provided ``AS IS'' without any warranties of any kind. + */ + +#ifndef _SYS_MSG_H_ +#define _SYS_MSG_H_ + +#include +#include +#include + +/* + * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct + * are as defined by the SV API Intel 386 Processor Supplement. + */ + +#define MSG_NOERROR 010000 /* don't complain about too long msgs */ + +typedef unsigned long msglen_t; +typedef unsigned long msgqnum_t; + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +/* + * XXX there seems to be no prefix reserved for this header, so the name + * "msg" in "struct msg" and the names of all of the nonstandard members + * (mainly "msg_pad*) are namespace pollution. + */ + +struct msqid_ds { + struct ipc_perm msg_perm; /* msg queue permission bits */ + struct msg *msg_first; /* first message in the queue */ + struct msg *msg_last; /* last message in the queue */ + msglen_t msg_cbytes; /* number of bytes in use on the queue */ + msgqnum_t msg_qnum; /* number of msgs in the queue */ + msglen_t msg_qbytes; /* max # of bytes on the queue */ + pid_t msg_lspid; /* pid of last msgsnd() */ + pid_t msg_lrpid; /* pid of last msgrcv() */ + time_t msg_stime; /* time of last msgsnd() */ + long msg_pad1; + time_t msg_rtime; /* time of last msgrcv() */ + long msg_pad2; + time_t msg_ctime; /* time of last msgctl() */ + long msg_pad3; + long msg_pad4[4]; +}; + +#if __BSD_VISIBLE +/* + * Structure describing a message. The SVID doesn't suggest any + * particular name for this structure. There is a reference in the + * msgop man page that reads "The structure mymsg is an example of what + * this user defined buffer might look like, and includes the following + * members:". This sentence is followed by two lines equivalent + * to the mtype and mtext field declarations below. It isn't clear + * if "mymsg" refers to the name of the structure type or the name of an + * instance of the structure... + */ +struct mymsg { + long mtype; /* message type (+ve integer) */ + char mtext[1]; /* message body */ +}; +#endif + +#ifdef _KERNEL + +/* + * Based on the configuration parameters described in an SVR2 (yes, two) + * config(1m) man page. + * + * Each message is broken up and stored in segments that are msgssz bytes + * long. For efficiency reasons, this should be a power of two. Also, + * it doesn't make sense if it is less than 8 or greater than about 256. + * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of + * two between 8 and 1024 inclusive (and panic's if it isn't). + */ +struct msginfo { + int msgmax, /* max chars in a message */ + msgmni, /* max message queue identifiers */ + msgmnb, /* max chars in a queue */ + msgtql, /* max messages in system */ + msgssz, /* size of a message segment (see notes above) */ + msgseg; /* number of message segments */ +}; +extern struct msginfo msginfo; + +#else /* !_KERNEL */ + +__BEGIN_DECLS +int msgctl(int, int, struct msqid_ds *); +int msgget(key_t, int); +/* XXX return value should be ssize_t. */ +int msgrcv(int, void *, size_t, long, int); +int msgsnd(int, const void *, size_t, int); +#if __BSD_VISIBLE +int msgsys(int, ...); +#endif +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_MSG_H_ */ diff --git a/src/include/sys/msgbuf.h b/src/include/sys/msgbuf.h new file mode 100644 index 0000000..a8a2969 --- /dev/null +++ b/src/include/sys/msgbuf.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1981, 1984, 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. + * 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. + * + * @(#)msgbuf.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/msgbuf.h,v 1.25 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_MSGBUF_H_ +#define _SYS_MSGBUF_H_ + +struct msgbuf { + char *msg_ptr; /* pointer to buffer */ +#define MSG_MAGIC 0x063062 + u_int msg_magic; + u_int msg_size; /* size of buffer area */ + u_int msg_wseq; /* write sequence number */ + u_int msg_rseq; /* read sequence number */ + u_int msg_cksum; /* checksum of contents */ + u_int msg_seqmod; /* range for sequence numbers */ +}; + +/* Normalise a sequence number or a difference between sequence numbers. */ +#define MSGBUF_SEQNORM(mbp, seq) (((seq) + (mbp)->msg_seqmod) % \ + (mbp)->msg_seqmod) +#define MSGBUF_SEQ_TO_POS(mbp, seq) ((seq) % (mbp)->msg_size) +/* Subtract sequence numbers. Note that only positive values result. */ +#define MSGBUF_SEQSUB(mbp, seq1, seq2) (MSGBUF_SEQNORM((mbp), (seq1) - (seq2))) + +#ifdef _KERNEL +extern int msgbuftrigger; +extern struct msgbuf *msgbufp; + +void msgbufinit(void *ptr, int size); +void msgbuf_addchar(struct msgbuf *mbp, int c); +void msgbuf_clear(struct msgbuf *mbp); +void msgbuf_copy(struct msgbuf *src, struct msgbuf *dst); +int msgbuf_getbytes(struct msgbuf *mbp, char *buf, int buflen); +int msgbuf_getchar(struct msgbuf *mbp); +int msgbuf_getcount(struct msgbuf *mbp); +void msgbuf_init(struct msgbuf *mbp, void *ptr, int size); +int msgbuf_peekbytes(struct msgbuf *mbp, char *buf, int buflen, + u_int *seqp); +void msgbuf_reinit(struct msgbuf *mbp, void *ptr, int size); + +#ifndef MSGBUF_SIZE +#define MSGBUF_SIZE 32768 +#endif +#endif /* KERNEL */ + +#endif /* !_SYS_MSGBUF_H_ */ diff --git a/src/include/sys/mtio.h b/src/include/sys/mtio.h new file mode 100644 index 0000000..5ab346d --- /dev/null +++ b/src/include/sys/mtio.h @@ -0,0 +1,233 @@ +/* + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)mtio.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/mtio.h,v 1.28 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_MTIO_H_ +#define _SYS_MTIO_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Structures and definitions for mag tape io control commands + */ + +/* structure for MTIOCTOP - mag tape op command */ +struct mtop { + short mt_op; /* operations defined below */ + int32_t mt_count; /* how many of them */ +}; + +/* operations */ +#define MTWEOF 0 /* write an end-of-file record */ +#define MTFSF 1 /* forward space file */ +#define MTBSF 2 /* backward space file */ +#define MTFSR 3 /* forward space record */ +#define MTBSR 4 /* backward space record */ +#define MTREW 5 /* rewind */ +#define MTOFFL 6 /* rewind and put the drive offline */ +#define MTNOP 7 /* no operation, sets status only */ +#define MTCACHE 8 /* enable controller cache */ +#define MTNOCACHE 9 /* disable controller cache */ + +#if defined(__FreeBSD__) +/* Set block size for device. If device is a variable size dev */ +/* a non zero parameter will change the device to a fixed block size */ +/* device with block size set to that of the parameter passed in. */ +/* Resetting the block size to 0 will restore the device to a variable */ +/* block size device. */ + +#define MTSETBSIZ 10 + +/* Set density values for device. Sets the value for the opened mode only. */ + +#define MTSETDNSTY 11 + +#define MTERASE 12 /* erase to EOM */ +#define MTEOD 13 /* Space to EOM */ +#define MTCOMP 14 /* select compression mode 0=off, 1=def */ +#define MTRETENS 15 /* re-tension tape */ +#define MTWSS 16 /* write setmark(s) */ +#define MTFSS 17 /* forward space setmark */ +#define MTBSS 18 /* backward space setmark */ + +#define MT_COMP_ENABLE 0xffffffff +#define MT_COMP_DISABLED 0xfffffffe +#define MT_COMP_UNSUPP 0xfffffffd + +/* + * Values in mt_dsreg that say what the device is doing + */ +#define MTIO_DSREG_NIL 0 /* Unknown */ +#define MTIO_DSREG_REST 1 /* Doing Nothing */ +#define MTIO_DSREG_RBSY 2 /* Communicating with tape (but no motion) */ +#define MTIO_DSREG_WR 20 /* Writing */ +#define MTIO_DSREG_FMK 21 /* Writing Filemarks */ +#define MTIO_DSREG_ZER 22 /* Erasing */ +#define MTIO_DSREG_RD 30 /* Reading */ +#define MTIO_DSREG_FWD 40 /* Spacing Forward */ +#define MTIO_DSREG_REV 41 /* Spacing Reverse */ +#define MTIO_DSREG_POS 42 /* Hardware Positioning (direction unknown) */ +#define MTIO_DSREG_REW 43 /* Rewinding */ +#define MTIO_DSREG_TEN 44 /* Retensioning */ +#define MTIO_DSREG_UNL 45 /* Unloading */ +#define MTIO_DSREG_LD 46 /* Loading */ + +#endif /* __FreeBSD__ */ + +/* structure for MTIOCGET - mag tape get status command */ + +struct mtget { + short mt_type; /* type of magtape device */ +/* the following two registers are grossly device dependent */ + short mt_dsreg; /* ``drive status'' register */ + short mt_erreg; /* ``error'' register */ +/* end device-dependent registers */ + /* + * Note that the residual count, while maintained, may be + * be nonsense because the size of the residual may (greatly) + * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a + * more accurate count. + */ + short mt_resid; /* residual count */ +#if defined (__FreeBSD__) + int32_t mt_blksiz; /* presently operating blocksize */ + int32_t mt_density; /* presently operating density */ + u_int32_t mt_comp; /* presently operating compression */ + int32_t mt_blksiz0; /* blocksize for mode 0 */ + int32_t mt_blksiz1; /* blocksize for mode 1 */ + int32_t mt_blksiz2; /* blocksize for mode 2 */ + int32_t mt_blksiz3; /* blocksize for mode 3 */ + int32_t mt_density0; /* density for mode 0 */ + int32_t mt_density1; /* density for mode 1 */ + int32_t mt_density2; /* density for mode 2 */ + int32_t mt_density3; /* density for mode 3 */ +/* the following are not yet implemented */ + u_int32_t mt_comp0; /* compression type for mode 0 */ + u_int32_t mt_comp1; /* compression type for mode 1 */ + u_int32_t mt_comp2; /* compression type for mode 2 */ + u_int32_t mt_comp3; /* compression type for mode 3 */ +/* end not yet implemented */ +#endif + int32_t mt_fileno; /* relative file number of current position */ + int32_t mt_blkno; /* relative block number of current position */ +}; + +/* structure for MTIOCERRSTAT - tape get error status command */ +/* really only supported for SCSI tapes right now */ +struct scsi_tape_errors { + /* + * These are latched from the last command that had a SCSI + * Check Condition noted for these operations. The act + * of issuing an MTIOCERRSTAT unlatches and clears them. + */ + u_int8_t io_sense[32]; /* Last Sense Data For Data I/O */ + int32_t io_resid; /* residual count from last Data I/O */ + u_int8_t io_cdb[16]; /* Command that Caused the Last Data Sense */ + u_int8_t ctl_sense[32]; /* Last Sense Data For Control I/O */ + int32_t ctl_resid; /* residual count from last Control I/O */ + u_int8_t ctl_cdb[16]; /* Command that Caused the Last Control Sense */ + /* + * These are the read and write cumulative error counters. + * (how to reset cumulative error counters is not yet defined). + * (not implemented as yet but space is being reserved for them) + */ + struct { + u_int32_t retries; /* total # retries performed */ + u_int32_t corrected; /* total # corrections performed */ + u_int32_t processed; /* total # corrections successful */ + u_int32_t failures; /* total # corrections/retries failed */ + u_int64_t nbytes; /* total # bytes processed */ + } wterr, rderr; +}; + +union mterrstat { + struct scsi_tape_errors scsi_errstat; + char _reserved_padding[256]; +}; + +/* + * Constants for mt_type byte. These are the same + * for controllers compatible with the types listed. + */ +#define MT_ISTS 0x01 /* TS-11 */ +#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */ +#define MT_ISTM 0x03 /* TM11/TE10 Unibus */ +#define MT_ISMT 0x04 /* TM78/TU78 Massbus */ +#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */ +#define MT_ISCPC 0x06 /* SUN */ +#define MT_ISAR 0x07 /* SUN */ +#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */ +#define MT_ISCY 0x09 /* CCI Cipher */ +#define MT_ISCT 0x0a /* HP 1/4 tape */ +#define MT_ISFHP 0x0b /* HP 7980 1/2 tape */ +#define MT_ISEXABYTE 0x0c /* Exabyte */ +#define MT_ISEXA8200 0x0c /* Exabyte EXB-8200 */ +#define MT_ISEXA8500 0x0d /* Exabyte EXB-8500 */ +#define MT_ISVIPER1 0x0e /* Archive Viper-150 */ +#define MT_ISPYTHON 0x0f /* Archive Python (DAT) */ +#define MT_ISHPDAT 0x10 /* HP 35450A DAT drive */ +#define MT_ISMFOUR 0x11 /* M4 Data 1/2 9track drive */ +#define MT_ISTK50 0x12 /* DEC SCSI TK50 */ +#define MT_ISMT02 0x13 /* Emulex MT02 SCSI tape controller */ + +/* mag tape io control commands */ +#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */ +#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */ +/* these two do not appear to be used anywhere */ +#define MTIOCIEOT _IO('m', 3) /* ignore EOT error */ +#define MTIOCEEOT _IO('m', 4) /* enable EOT error */ +/* + * When more SCSI-3 SSC (streaming device) devices are out there + * that support the full 32 byte type 2 structure, we'll have to + * rethink these ioctls to support all the entities they haul into + * the picture (64 bit blocks, logical file record numbers, etc..). + */ +#define MTIOCRDSPOS _IOR('m', 5, u_int32_t) /* get logical blk addr */ +#define MTIOCRDHPOS _IOR('m', 6, u_int32_t) /* get hardware blk addr */ +#define MTIOCSLOCATE _IOW('m', 5, u_int32_t) /* seek to logical blk addr */ +#define MTIOCHLOCATE _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */ +#define MTIOCERRSTAT _IOR('m', 7, union mterrstat) /* get tape errors */ +/* + * Set EOT model- argument is number of filemarks to end a tape with. + * Note that not all possible values will be accepted. + */ +#define MTIOCSETEOTMODEL _IOW('m', 8, u_int32_t) +/* Get current EOT model */ +#define MTIOCGETEOTMODEL _IOR('m', 8, u_int32_t) + +#ifndef _KERNEL +#define DEFTAPE "/dev/nsa0" +#endif + +#endif /* !_SYS_MTIO_H_ */ diff --git a/src/include/sys/mutex.h b/src/include/sys/mutex.h new file mode 100644 index 0000000..6e5c775 --- /dev/null +++ b/src/include/sys/mutex.h @@ -0,0 +1,422 @@ +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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. + * + * from BSDI $Id$ + * $FreeBSD: src/sys/sys/mutex.h,v 1.70 2004/03/28 23:12:19 rwatson Exp $ + */ + +#ifndef _SYS_MUTEX_H_ +#define _SYS_MUTEX_H_ + +#ifndef LOCORE +#include +#include +#include + +#ifdef _KERNEL +#include +#include +#include +#endif /* _KERNEL_ */ +#endif /* !LOCORE */ + +#include + +#ifdef _KERNEL + +/* + * Mutex types and options passed to mtx_init(). MTX_QUIET can also be + * passed in. + */ +#define MTX_DEF 0x00000000 /* DEFAULT (sleep) lock */ +#define MTX_SPIN 0x00000001 /* Spin lock (disables interrupts) */ +#define MTX_RECURSE 0x00000004 /* Option: lock allowed to recurse */ +#define MTX_NOWITNESS 0x00000008 /* Don't do any witness checking. */ +#define MTX_DUPOK 0x00000020 /* Don't log a duplicate acquire */ + +/* + * Option flags passed to certain lock/unlock routines, through the use + * of corresponding mtx_{lock,unlock}_flags() interface macros. + */ +#define MTX_QUIET LOP_QUIET /* Don't log a mutex event */ + +/* + * State bits kept in mutex->mtx_lock, for the DEFAULT lock type. None of this, + * with the exception of MTX_UNOWNED, applies to spin locks. + */ +#define MTX_RECURSED 0x00000001 /* lock recursed (for MTX_DEF only) */ +#define MTX_CONTESTED 0x00000002 /* lock contested (for MTX_DEF only) */ +#define MTX_UNOWNED 0x00000004 /* Cookie for free mutex */ +#define MTX_FLAGMASK ~(MTX_RECURSED | MTX_CONTESTED) + +#endif /* _KERNEL */ + +#ifndef LOCORE + +/* + * XXX: Friendly reminder to fix things in MP code that is presently being + * XXX: worked on. + */ +#define mp_fixme(string) + +#ifdef _KERNEL + +/* + * Prototypes + * + * NOTE: Functions prepended with `_' (underscore) are exported to other parts + * of the kernel via macros, thus allowing us to use the cpp LOCK_FILE + * and LOCK_LINE. These functions should not be called directly by any + * code using the API. Their macros cover their functionality. + * + * [See below for descriptions] + * + */ +void mtx_init(struct mtx *m, const char *name, const char *type, int opts); +void mtx_destroy(struct mtx *m); +void mtx_sysinit(void *arg); +void mutex_init(void); +void _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line); +void _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line); +void _mtx_lock_spin(struct mtx *m, int opts, const char *file, int line); +void _mtx_unlock_spin(struct mtx *m, int opts, const char *file, int line); +int _mtx_trylock(struct mtx *m, int opts, const char *file, int line); +void _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line); +void _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line); +void _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, + int line); +void _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, + int line); +#ifdef INVARIANT_SUPPORT +void _mtx_assert(struct mtx *m, int what, const char *file, int line); +#endif + +/* + * We define our machine-independent (unoptimized) mutex micro-operations + * here, if they are not already defined in the machine-dependent mutex.h + */ + +/* Actually obtain mtx_lock */ +#ifndef _obtain_lock +#define _obtain_lock(mp, tid) \ + atomic_cmpset_acq_ptr(&(mp)->mtx_lock, (void *)MTX_UNOWNED, (tid)) +#endif + +/* Actually release mtx_lock */ +#ifndef _release_lock +#define _release_lock(mp, tid) \ + atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), (void *)MTX_UNOWNED) +#endif + +/* Actually release mtx_lock quickly, assuming we own it. */ +#ifndef _release_lock_quick +#define _release_lock_quick(mp) \ + atomic_store_rel_ptr(&(mp)->mtx_lock, (void *)MTX_UNOWNED) +#endif + +/* + * Obtain a sleep lock inline, or call the "hard" function if we can't get it + * easy. + */ +#ifndef _get_sleep_lock +#define _get_sleep_lock(mp, tid, opts, file, line) do { \ + if (!_obtain_lock((mp), (tid))) \ + _mtx_lock_sleep((mp), (opts), (file), (line)); \ +} while (0) +#endif + +/* + * Obtain a spin lock inline, or call the "hard" function if we can't get it + * easy. For spinlocks, we handle recursion inline (it turns out that function + * calls can be significantly expensive on some architectures). + * Since spin locks are not _too_ common, inlining this code is not too big + * a deal. + */ +#ifndef _get_spin_lock +#define _get_spin_lock(mp, tid, opts, file, line) do { \ + critical_enter(); \ + if (!_obtain_lock((mp), (tid))) { \ + if ((mp)->mtx_lock == (uintptr_t)(tid)) \ + (mp)->mtx_recurse++; \ + else \ + _mtx_lock_spin((mp), (opts), (file), (line)); \ + } \ +} while (0) +#endif + +/* + * Release a sleep lock inline, or call the "hard" function if we can't do it + * easy. + */ +#ifndef _rel_sleep_lock +#define _rel_sleep_lock(mp, tid, opts, file, line) do { \ + if (!_release_lock((mp), (tid))) \ + _mtx_unlock_sleep((mp), (opts), (file), (line)); \ +} while (0) +#endif + +/* + * For spinlocks, we can handle everything inline, as it's pretty simple and + * a function call would be too expensive (at least on some architectures). + * Since spin locks are not _too_ common, inlining this code is not too big + * a deal. + * + * Since we always perform a critical_enter() when attempting to acquire a + * spin lock, we need to always perform a matching critical_exit() when + * releasing a spin lock. This includes the recursion cases. + */ +#ifndef _rel_spin_lock +#define _rel_spin_lock(mp) do { \ + if (mtx_recursed((mp))) \ + (mp)->mtx_recurse--; \ + else \ + _release_lock_quick((mp)); \ + critical_exit(); \ +} while (0) +#endif + +/* + * Exported lock manipulation interface. + * + * mtx_lock(m) locks MTX_DEF mutex `m' + * + * mtx_lock_spin(m) locks MTX_SPIN mutex `m' + * + * mtx_unlock(m) unlocks MTX_DEF mutex `m' + * + * mtx_unlock_spin(m) unlocks MTX_SPIN mutex `m' + * + * mtx_lock_spin_flags(m, opts) and mtx_lock_flags(m, opts) locks mutex `m' + * and passes option flags `opts' to the "hard" function, if required. + * With these routines, it is possible to pass flags such as MTX_QUIET + * to the appropriate lock manipulation routines. + * + * mtx_trylock(m) attempts to acquire MTX_DEF mutex `m' but doesn't sleep if + * it cannot. Rather, it returns 0 on failure and non-zero on success. + * It does NOT handle recursion as we assume that if a caller is properly + * using this part of the interface, he will know that the lock in question + * is _not_ recursed. + * + * mtx_trylock_flags(m, opts) is used the same way as mtx_trylock() but accepts + * relevant option flags `opts.' + * + * mtx_initialized(m) returns non-zero if the lock `m' has been initialized. + * + * mtx_owned(m) returns non-zero if the current thread owns the lock `m' + * + * mtx_recursed(m) returns non-zero if the lock `m' is presently recursed. + */ +#define mtx_lock(m) mtx_lock_flags((m), 0) +#define mtx_lock_spin(m) mtx_lock_spin_flags((m), 0) +#define mtx_trylock(m) mtx_trylock_flags((m), 0) +#define mtx_unlock(m) mtx_unlock_flags((m), 0) +#define mtx_unlock_spin(m) mtx_unlock_spin_flags((m), 0) + +struct mtx_pool; + +struct mtx_pool *mtx_pool_create(const char *mtx_name, int pool_size, int opts); +void mtx_pool_destroy(struct mtx_pool **poolp); +struct mtx *mtx_pool_find(struct mtx_pool *pool, void *ptr); +struct mtx *mtx_pool_alloc(struct mtx_pool *pool); +#define mtx_pool_lock(pool, ptr) \ + mtx_lock(mtx_pool_find((pool), (ptr))) +#define mtx_pool_lock_spin(pool, ptr) \ + mtx_lock_spin(mtx_pool_find((pool), (ptr))) +#define mtx_pool_unlock(pool, ptr) \ + mtx_unlock(mtx_pool_find((pool), (ptr))) +#define mtx_pool_unlock_spin(pool, ptr) \ + mtx_unlock_spin(mtx_pool_find((pool), (ptr))) + +/* + * mtxpool_lockbuilder is a pool of sleep locks that is not witness + * checked and should only be used for building higher level locks. + * + * mtxpool_sleep is a general purpose pool of sleep mutexes. + */ +extern struct mtx_pool *mtxpool_lockbuilder; +extern struct mtx_pool *mtxpool_sleep; + +#ifndef LOCK_DEBUG +#error LOCK_DEBUG not defined, include before +#endif +#if LOCK_DEBUG > 0 || defined(MUTEX_NOINLINE) +#define mtx_lock_flags(m, opts) \ + _mtx_lock_flags((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_unlock_flags(m, opts) \ + _mtx_unlock_flags((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_lock_spin_flags(m, opts) \ + _mtx_lock_spin_flags((m), (opts), LOCK_FILE, LOCK_LINE) +#define mtx_unlock_spin_flags(m, opts) \ + _mtx_unlock_spin_flags((m), (opts), LOCK_FILE, LOCK_LINE) +#else /* LOCK_DEBUG == 0 && !MUTEX_NOINLINE */ +#define mtx_lock_flags(m, opts) \ + _get_sleep_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE) +#define mtx_unlock_flags(m, opts) \ + _rel_sleep_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE) +#ifndef SMPnotyet +#define mtx_lock_spin_flags(m, opts) \ + _get_spin_lock((m), curthread, (opts), LOCK_FILE, LOCK_LINE) +#define mtx_unlock_spin_flags(m, opts) \ + _rel_spin_lock((m)) +#else /* SMP */ +#define mtx_lock_spin_flags(m, opts) critical_enter() +#define mtx_unlock_spin_flags(m, opts) critical_exit() +#endif /* SMP */ +#endif /* LOCK_DEBUG > 0 || MUTEX_NOINLINE */ + +#define mtx_trylock_flags(m, opts) \ + _mtx_trylock((m), (opts), LOCK_FILE, LOCK_LINE) + +#define mtx_initialized(m) ((m)->mtx_object.lo_flags & LO_INITIALIZED) + +#define mtx_owned(m) (((m)->mtx_lock & MTX_FLAGMASK) == (uintptr_t)curthread) + +#define mtx_recursed(m) ((m)->mtx_recurse != 0) + +#define mtx_name(m) ((m)->mtx_object.lo_name) + +/* + * Global locks. + */ +extern struct mtx sched_lock; +extern struct mtx Giant; + +/* + * Giant lock manipulation and clean exit macros. + * Used to replace return with an exit Giant and return. + * + * Note that DROP_GIANT*() needs to be paired with PICKUP_GIANT() + * The #ifndef is to allow lint-like tools to redefine DROP_GIANT. + */ +#ifndef DROP_GIANT +#define DROP_GIANT() \ +do { \ + int _giantcnt; \ + WITNESS_SAVE_DECL(Giant); \ + \ + if (mtx_owned(&Giant)) \ + WITNESS_SAVE(&Giant.mtx_object, Giant); \ + for (_giantcnt = 0; mtx_owned(&Giant); _giantcnt++) \ + mtx_unlock(&Giant) + +#define PICKUP_GIANT() \ + mtx_assert(&Giant, MA_NOTOWNED); \ + while (_giantcnt--) \ + mtx_lock(&Giant); \ + if (mtx_owned(&Giant)) \ + WITNESS_RESTORE(&Giant.mtx_object, Giant); \ +} while (0) + +#define PARTIAL_PICKUP_GIANT() \ + mtx_assert(&Giant, MA_NOTOWNED); \ + while (_giantcnt--) \ + mtx_lock(&Giant); \ + if (mtx_owned(&Giant)) \ + WITNESS_RESTORE(&Giant.mtx_object, Giant) +#endif + +/* + * Network MPSAFE temporary workarounds. When debug_mpsafenet + * is 1 the network is assumed to operate without Giant on the + * input path and protocols that require Giant must collect it + * on entry. When 0 Giant is grabbed in the network interface + * ISR's and in the netisr path and there is no need to grab + * the Giant lock. Note that, unlike GIANT_PICKUP() and + * GIANT_DROP(), these macros directly wrap mutex operations + * without special recursion handling. + * + * This mechanism is intended as temporary until everything of + * importance is properly locked. + */ +extern int debug_mpsafenet; /* defined in net/netisr.c */ +#define NET_LOCK_GIANT() do { \ + if (!debug_mpsafenet) \ + mtx_lock(&Giant); \ +} while (0) +#define NET_UNLOCK_GIANT() do { \ + if (!debug_mpsafenet) \ + mtx_unlock(&Giant); \ +} while (0) +#define NET_ASSERT_GIANT() do { \ + if (!debug_mpsafenet) \ + mtx_assert(&Giant, MA_OWNED); \ +} while (0) + +#define UGAR(rval) do { \ + int _val = (rval); \ + mtx_unlock(&Giant); \ + return (_val); \ +} while (0) + +struct mtx_args { + struct mtx *ma_mtx; + const char *ma_desc; + int ma_opts; +}; + +#define MTX_SYSINIT(name, mtx, desc, opts) \ + static struct mtx_args name##_args = { \ + (mtx), \ + (desc), \ + (opts) \ + }; \ + SYSINIT(name##_mtx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + mtx_sysinit, &name##_args) + +/* + * The INVARIANTS-enabled mtx_assert() functionality. + * + * The constants need to be defined for INVARIANT_SUPPORT infrastructure + * support as _mtx_assert() itself uses them and the latter implies that + * _mtx_assert() must build. + */ +#ifdef INVARIANT_SUPPORT +#define MA_OWNED 0x01 +#define MA_NOTOWNED 0x02 +#define MA_RECURSED 0x04 +#define MA_NOTRECURSED 0x08 +#endif /* INVARIANT_SUPPORT */ + +#ifdef INVARIANTS +#define mtx_assert(m, what) \ + _mtx_assert((m), (what), __FILE__, __LINE__) + +#define GIANT_REQUIRED mtx_assert(&Giant, MA_OWNED) + +#else /* INVARIANTS */ +#define mtx_assert(m, what) +#define GIANT_REQUIRED +#endif /* INVARIANTS */ + +/* + * Common lock type names. + */ +#define MTX_NETWORK_LOCK "network driver" + +#endif /* _KERNEL */ +#endif /* !LOCORE */ +#endif /* _SYS_MUTEX_H_ */ diff --git a/src/include/sys/namei.h b/src/include/sys/namei.h new file mode 100644 index 0000000..4153d9f --- /dev/null +++ b/src/include/sys/namei.h @@ -0,0 +1,195 @@ +/* + * Copyright (c) 1985, 1989, 1991, 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. + * 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. + * + * @(#)namei.h 8.5 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/namei.h,v 1.41 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_NAMEI_H_ +#define _SYS_NAMEI_H_ + +#include +#include + +struct componentname { + /* + * Arguments to lookup. + */ + u_long cn_nameiop; /* namei operation */ + u_long cn_flags; /* flags to namei */ + struct thread *cn_thread;/* thread requesting lookup */ + struct ucred *cn_cred; /* credentials */ + /* + * Shared between lookup and commit routines. + */ + char *cn_pnbuf; /* pathname buffer */ + char *cn_nameptr; /* pointer to looked up name */ + long cn_namelen; /* length of looked up component */ + long cn_consume; /* chars to consume in lookup() */ +}; + +/* + * Encapsulation of namei parameters. + */ +struct nameidata { + /* + * Arguments to namei/lookup. + */ + const char *ni_dirp; /* pathname pointer */ + enum uio_seg ni_segflg; /* location of pathname */ + /* + * Arguments to lookup. + */ + struct vnode *ni_startdir; /* starting directory */ + struct vnode *ni_rootdir; /* logical root directory */ + struct vnode *ni_topdir; /* logical top directory */ + /* + * Results: returned from/manipulated by lookup + */ + struct vnode *ni_vp; /* vnode of result */ + struct vnode *ni_dvp; /* vnode of intermediate directory */ + /* + * Shared between namei and lookup/commit routines. + */ + size_t ni_pathlen; /* remaining chars in path */ + char *ni_next; /* next location in pathname */ + u_long ni_loopcnt; /* count of symlinks encountered */ + /* + * Lookup parameters: this structure describes the subset of + * information from the nameidata structure that is passed + * through the VOP interface. + */ + struct componentname ni_cnd; +}; + +#ifdef _KERNEL +/* + * namei operations + */ +#define LOOKUP 0 /* perform name lookup only */ +#define CREATE 1 /* setup for file creation */ +#define DELETE 2 /* setup for file deletion */ +#define RENAME 3 /* setup for file renaming */ +#define OPMASK 3 /* mask for operation */ +/* + * namei operational modifier flags, stored in ni_cnd.flags + */ +#define LOCKLEAF 0x0004 /* lock inode on return */ +#define LOCKPARENT 0x0008 /* want parent vnode returned locked */ +#define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ +#define NOCACHE 0x0020 /* name must not be left in cache */ +#define FOLLOW 0x0040 /* follow symbolic links */ +#define NOOBJ 0x0080 /* don't create object */ +#define LOCKSHARED 0x0100 /* Shared lock leaf */ +#define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ +#define MODMASK 0x01fc /* mask of operational modifiers */ +/* + * Namei parameter descriptors. + * + * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. + * If the caller of namei sets the flag (for example execve wants to + * know the name of the program that is being executed), then it must + * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must + * be freed by either the commit routine or the VOP_ABORT routine. + * SAVESTART is set only by the callers of namei. It implies SAVENAME + * plus the addition of saving the parent directory that contains the + * name in ni_startdir. It allows repeated calls to lookup for the + * name being sought. The caller is responsible for releasing the + * buffer and for vrele'ing ni_startdir. + */ +#define RDONLY 0x000200 /* lookup with read-only semantics */ +#define HASBUF 0x000400 /* has allocated pathname buffer */ +#define SAVENAME 0x000800 /* save pathname buffer */ +#define SAVESTART 0x001000 /* save starting directory */ +#define ISDOTDOT 0x002000 /* current component name is .. */ +#define MAKEENTRY 0x004000 /* entry is to be added to name cache */ +#define ISLASTCN 0x008000 /* this is last component of pathname */ +#define ISSYMLINK 0x010000 /* symlink needs interpretation */ +#define ISWHITEOUT 0x020000 /* found whiteout */ +#define DOWHITEOUT 0x040000 /* do whiteouts */ +#define WILLBEDIR 0x080000 /* new files will be dirs; allow trailing / */ +#define ISUNICODE 0x100000 /* current component name is unicode*/ +#define PDIRUNLOCK 0x200000 /* filesystem lookup() unlocked parent dir */ +#define NOCROSSMOUNT 0x400000 /* do not cross mount points */ +#define NOMACCHECK 0x800000 /* do not perform MAC checks */ +#define PARAMASK 0xfffe00 /* mask of parameter descriptors */ + +/* + * Initialization of a nameidata structure. + */ +static void NDINIT(struct nameidata *, u_long, u_long, enum uio_seg, + const char *, struct thread *); +static __inline void +NDINIT(struct nameidata *ndp, + u_long op, u_long flags, + enum uio_seg segflg, + const char *namep, + struct thread *td) +{ + ndp->ni_cnd.cn_nameiop = op; + ndp->ni_cnd.cn_flags = flags; + ndp->ni_segflg = segflg; + ndp->ni_dirp = namep; + ndp->ni_cnd.cn_thread = td; +} + +#define NDF_NO_DVP_RELE 0x00000001 +#define NDF_NO_DVP_UNLOCK 0x00000002 +#define NDF_NO_DVP_PUT 0x00000003 +#define NDF_NO_VP_RELE 0x00000004 +#define NDF_NO_VP_UNLOCK 0x00000008 +#define NDF_NO_VP_PUT 0x0000000c +#define NDF_NO_STARTDIR_RELE 0x00000010 +#define NDF_NO_FREE_PNBUF 0x00000020 +#define NDF_ONLY_PNBUF (~NDF_NO_FREE_PNBUF) + +void NDFREE(struct nameidata *, const u_int); + +int namei(struct nameidata *ndp); +int lookup(struct nameidata *ndp); +int relookup(struct vnode *dvp, struct vnode **vpp, + struct componentname *cnp); +#endif + +/* + * Stats on usefulness of namei caches. + */ +struct nchstats { + long ncs_goodhits; /* hits that we can really use */ + long ncs_neghits; /* negative hits that we can use */ + long ncs_badhits; /* hits we must drop */ + long ncs_falsehits; /* hits with id mismatch */ + long ncs_miss; /* misses */ + long ncs_long; /* long names that ignore cache */ + long ncs_pass2; /* names found with passes == 2 */ + long ncs_2passes; /* number of times we attempt it */ +}; + +extern struct nchstats nchstats; + +#endif /* !_SYS_NAMEI_H_ */ diff --git a/src/include/sys/nlist_aout.h b/src/include/sys/nlist_aout.h new file mode 100644 index 0000000..6537470 --- /dev/null +++ b/src/include/sys/nlist_aout.h @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)nlist.h 8.2 (Berkeley) 1/21/94 + * + * $FreeBSD: src/sys/sys/nlist_aout.h,v 1.11 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_NLIST_AOUT_H_ +#define _SYS_NLIST_AOUT_H_ + +/* + * Symbol table entries in a.out files. + */ + +/* + * Layout of each symbol. The "#ifdef _AOUT_INCLUDE_" is so that + * programs including nlist.h can initialize nlist structures + * statically. + */ +struct nlist { +#ifdef _AOUT_INCLUDE_ + union { + char *n_name; /* symbol name (in memory) */ + long n_strx; /* file string table offset (on disk) */ + } n_un; +#else + char *n_name; /* symbol name (in memory) */ + int : 8 * (sizeof(long) > sizeof(char *) ? + sizeof(long) - sizeof(char *) : sizeof(char *) - sizeof(long)); +#endif + unsigned char n_type; /* type defines */ + char n_other; /* ".type" and binding information */ + short n_desc; /* used by stab entries */ + unsigned long n_value; /* address/value of the symbol */ +}; + +#define n_hash n_desc /* used internally by ld(1); XXX */ + +/* + * Defines for n_type. + */ +#define N_UNDF 0x00 /* undefined */ +#define N_ABS 0x02 /* absolute address */ +#define N_TEXT 0x04 /* text segment */ +#define N_DATA 0x06 /* data segment */ +#define N_BSS 0x08 /* bss segment */ +#define N_INDR 0x0a /* alias definition */ +#define N_SIZE 0x0c /* pseudo type, defines a symbol's size */ +#define N_COMM 0x12 /* common reference */ +/* GNU extensions */ +#define N_SETA 0x14 /* Absolute set element symbol */ +#define N_SETT 0x16 /* Text set element symbol */ +#define N_SETD 0x18 /* Data set element symbol */ +#define N_SETB 0x1a /* Bss set element symbol */ +#define N_SETV 0x1c /* Pointer to set vector in data area. */ +/* end GNU extensions */ +#define N_FN 0x1e /* file name (N_EXT on) */ +#define N_WARN 0x1e /* warning message (N_EXT off) */ + +#define N_EXT 0x01 /* external (global) bit, OR'ed in */ +#define N_TYPE 0x1e /* mask for all the type bits */ +#define N_STAB 0xe0 /* mask for debugger symbols -- stab(5) */ + +/* + * Defines for n_other. It contains the ".type" (AUX) field in the least + * significant 4 bits, and the binding (for weak symbols) in the most + * significant 4 bits. + */ +#define N_AUX(p) ((p)->n_other & 0xf) +#define N_BIND(p) (((unsigned int)(p)->n_other >> 4) & 0xf) +#define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf)) + +#define AUX_OBJECT 1 /* data object */ +#define AUX_FUNC 2 /* function */ + +/*#define BIND_LOCAL 0 not used */ +/*#define BIND_GLOBAL 1 not used */ +#define BIND_WEAK 2 /* weak binding */ + +#define N_FORMAT "%08x" /* namelist value format; XXX */ + +#endif /* !_SYS_NLIST_AOUT_H_ */ diff --git a/src/include/sys/param.h b/src/include/sys/param.h new file mode 100644 index 0000000..b41a30f --- /dev/null +++ b/src/include/sys/param.h @@ -0,0 +1,327 @@ +/*- + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)param.h 8.3 (Berkeley) 4/4/95 + * $FreeBSD: src/sys/sys/param.h,v 1.191 2004/04/13 09:33:33 ru Exp $ + */ + +#ifndef _SYS_PARAM_H_ +#define _SYS_PARAM_H_ + +#include + +#define BSD 199506 /* System version (year & month). */ +#define BSD4_3 1 +#define BSD4_4 1 + +/* + * __FreeBSD_version numbers are documented in the Porter's Handbook. + * If you bump the version for any reason, you should update the documentation + * there. + * Currently this lives here: + * + * doc/en_US.ISO8859-1/books/porters-handbook/book.sgml + * + * scheme is: <0 if release branch, otherwise 1>xx + */ +#undef __FreeBSD_version +#define __FreeBSD_version 502112 /* Master, propagated to newvers */ + +#ifndef LOCORE +#include +#endif + +/* + * Machine-independent constants (some used in following include files). + * Redefined constants are from POSIX 1003.1 limits file. + * + * MAXCOMLEN should be >= sizeof(ac_comm) (see ) + * MAXLOGNAME should be == UT_NAMESIZE+1 (see ) + */ +#include + +#define MAXCOMLEN 19 /* max command name remembered */ +#define MAXINTERP 32 /* max interpreter file name length */ +#define MAXLOGNAME 17 /* max login name length (incl. NUL) */ +#define MAXUPRC CHILD_MAX /* max simultaneous processes */ +#define NCARGS ARG_MAX /* max bytes for an exec function */ +#define NGROUPS NGROUPS_MAX /* max number groups */ +#define NOFILE OPEN_MAX /* max open files per process */ +#define NOGROUP 65535 /* marker for empty group set member */ +#define MAXHOSTNAMELEN 256 /* max hostname size */ +#define SPECNAMELEN 63 /* max length of devicename */ + +/* More types and definitions used throughout the kernel. */ +#ifdef _KERNEL +#if (defined(BURN_BRIDGES) || __FreeBSD_version >= 600000) \ + && defined(OBSOLETE_IN_6) +#error "This file contains obsolete code to be removed in 6.0-current" +#endif +#include +#include +#include +#include + +#define FALSE 0 +#define TRUE 1 +#endif + +#ifndef _KERNEL +/* Signals. */ +#include +#endif + +/* Machine type dependent parameters. */ +#include +#ifndef _KERNEL +#include +#endif + +#ifndef _NO_NAMESPACE_POLLUTION + +#ifndef DEV_BSHIFT +#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ +#endif +#define DEV_BSIZE (1<>PAGE_SHIFT) +#endif + +/* + * btodb() is messy and perhaps slow because `bytes' may be an off_t. We + * want to shift an unsigned type to avoid sign extension and we don't + * want to widen `bytes' unnecessarily. Assume that the result fits in + * a daddr_t. + */ +#ifndef btodb +#define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ + (sizeof (bytes) > sizeof(long) \ + ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ + : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) +#endif + +#ifndef dbtob +#define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ + ((off_t)(db) << DEV_BSHIFT) +#endif + +#endif /* _NO_NAMESPACE_POLLUTION */ + +#define PRIMASK 0x0ff +#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ +#define PDROP 0x200 /* OR'd with pri to stop re-entry of interlock mutex */ + +#define NZERO 0 /* default "nice" */ + +#define NBBY 8 /* number of bits in a byte */ +#define NBPW sizeof(int) /* number of bytes per word (integer) */ + +#define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ +#ifdef _KERNEL +#define NOUDEV (udev_t)(-1) /* non-existent device */ +#define NOMAJ 256 /* non-existent device */ +#define NODEV NULL /* non-existent device */ +#else +#define NODEV (dev_t)(-1) /* non-existent device */ +#endif + +#define CBLOCK 128 /* Clist block size, must be a power of 2. */ +#define CBQSIZE (CBLOCK/NBBY) /* Quote bytes/cblock - can do better. */ + /* Data chars/clist. */ +#define CBSIZE (CBLOCK - sizeof(struct cblock *) - CBQSIZE) +#define CROUND (CBLOCK - 1) /* Clist rounding. */ + +/* + * File system parameters and macros. + * + * MAXBSIZE - Filesystems are made out of blocks of at most MAXBSIZE bytes + * per block. MAXBSIZE may be made larger without effecting + * any existing filesystems as long as it does not exceed MAXPHYS, + * and may be made smaller at the risk of not being able to use + * filesystems which require a block size exceeding MAXBSIZE. + * + * BKVASIZE - Nominal buffer space per buffer, in bytes. BKVASIZE is the + * minimum KVM memory reservation the kernel is willing to make. + * Filesystems can of course request smaller chunks. Actual + * backing memory uses a chunk size of a page (PAGE_SIZE). + * + * If you make BKVASIZE too small you risk seriously fragmenting + * the buffer KVM map which may slow things down a bit. If you + * make it too big the kernel will not be able to optimally use + * the KVM memory reserved for the buffer cache and will wind + * up with too-few buffers. + * + * The default is 16384, roughly 2x the block size used by a + * normal UFS filesystem. + */ +#define MAXBSIZE 65536 /* must be power of 2 */ +#define BKVASIZE 16384 /* must be power of 2 */ +#define BKVAMASK (BKVASIZE-1) + +/* + * MAXPATHLEN defines the longest permissible path length after expanding + * symbolic links. It is used to allocate a temporary buffer from the buffer + * pool in which to do the name expansion, hence should be a power of two, + * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the + * maximum number of symbolic links that may be expanded in a path name. + * It should be set high enough to allow all legitimate uses, but halt + * infinite loops reasonably quickly. + */ +#define MAXPATHLEN PATH_MAX +#define MAXSYMLINKS 32 + +/* Bit map related macros. */ +#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) +#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) +#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) +#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) + +/* Macros for counting and rounding. */ +#ifndef howmany +#define howmany(x, y) (((x)+((y)-1))/(y)) +#endif +#define rounddown(x, y) (((x)/(y))*(y)) +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ +#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ +#define powerof2(x) ((((x)-1)&(x))==0) + +/* Macros for min/max. */ +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +#ifdef _KERNEL +/* + * Basic byte order function prototypes for non-inline functions. + */ +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +__BEGIN_DECLS +__uint32_t htonl(__uint32_t); +__uint16_t htons(__uint16_t); +__uint32_t ntohl(__uint32_t); +__uint16_t ntohs(__uint16_t); +__END_DECLS +#endif + +#ifndef lint +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif /* !_BYTEORDER_FUNC_DEFINED */ +#endif /* lint */ +#endif /* _KERNEL */ + +/* + * Constants for setting the parameters of the kernel memory allocator. + * + * 2 ** MINBUCKET is the smallest unit of memory that will be + * allocated. It must be at least large enough to hold a pointer. + * + * Units of memory less or equal to MAXALLOCSAVE will permanently + * allocate physical memory; requests for these size pieces of + * memory are quite fast. Allocations greater than MAXALLOCSAVE must + * always allocate and free physical memory; requests for these + * size allocations should be done infrequently as they will be slow. + * + * Constraints: PAGE_SIZE <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and + * MAXALLOCSIZE must be a power of two. + */ +#if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) +#define MINBUCKET 5 /* 5 => min allocation of 32 bytes */ +#else +#define MINBUCKET 4 /* 4 => min allocation of 16 bytes */ +#endif +#define MAXALLOCSAVE (2 * PAGE_SIZE) + +/* + * Scale factor for scaled integers used to count %cpu time and load avgs. + * + * The number of CPU `tick's that map to a unique `%age' can be expressed + * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that + * can be calculated (assuming 32 bits) can be closely approximated using + * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). + * + * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', + * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. + */ +#define FSHIFT 11 /* bits to right of fixed binary point */ +#define FSCALE (1<> (PAGE_SHIFT - DEV_BSHIFT)) + +#define ctodb(db) /* calculates pages to devblks */ \ + ((db) << (PAGE_SHIFT - DEV_BSHIFT)) + +#endif /* _SYS_PARAM_H_ */ diff --git a/src/include/sys/pciio.h b/src/include/sys/pciio.h new file mode 100644 index 0000000..f5ddec6 --- /dev/null +++ b/src/include/sys/pciio.h @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 1997, Stefan Esser + * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/pciio.h,v 1.6 2001/09/05 01:22:14 obrien Exp $ + * + */ + +#ifndef _SYS_PCIIO_H_ +#define _SYS_PCIIO_H_ + +#include + +#define PCI_MAXNAMELEN 16 + +typedef enum { + PCI_GETCONF_LAST_DEVICE, + PCI_GETCONF_LIST_CHANGED, + PCI_GETCONF_MORE_DEVS, + PCI_GETCONF_ERROR +} pci_getconf_status; + +typedef enum { + PCI_GETCONF_NO_MATCH = 0x00, + PCI_GETCONF_MATCH_BUS = 0x01, + PCI_GETCONF_MATCH_DEV = 0x02, + PCI_GETCONF_MATCH_FUNC = 0x04, + PCI_GETCONF_MATCH_NAME = 0x08, + PCI_GETCONF_MATCH_UNIT = 0x10, + PCI_GETCONF_MATCH_VENDOR = 0x20, + PCI_GETCONF_MATCH_DEVICE = 0x40, + PCI_GETCONF_MATCH_CLASS = 0x80 +} pci_getconf_flags; + +struct pcisel { + u_int8_t pc_bus; /* bus number */ + u_int8_t pc_dev; /* device on this bus */ + u_int8_t pc_func; /* function on this device */ +}; + +struct pci_conf { + struct pcisel pc_sel; /* bus+slot+function */ + u_int8_t pc_hdr; /* PCI header type */ + u_int16_t pc_subvendor; /* card vendor ID */ + u_int16_t pc_subdevice; /* card device ID, assigned by + card vendor */ + u_int16_t pc_vendor; /* chip vendor ID */ + u_int16_t pc_device; /* chip device ID, assigned by + chip vendor */ + u_int8_t pc_class; /* chip PCI class */ + u_int8_t pc_subclass; /* chip PCI subclass */ + u_int8_t pc_progif; /* chip PCI programming interface */ + u_int8_t pc_revid; /* chip revision ID */ + char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ + u_long pd_unit; /* device unit number */ +}; + +struct pci_match_conf { + struct pcisel pc_sel; /* bus+slot+function */ + char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ + u_long pd_unit; /* Unit number */ + u_int16_t pc_vendor; /* PCI Vendor ID */ + u_int16_t pc_device; /* PCI Device ID */ + u_int8_t pc_class; /* PCI class */ + pci_getconf_flags flags; /* Matching expression */ +}; + +struct pci_conf_io { + u_int32_t pat_buf_len; /* pattern buffer length */ + u_int32_t num_patterns; /* number of patterns */ + struct pci_match_conf *patterns; /* pattern buffer */ + u_int32_t match_buf_len; /* match buffer length */ + u_int32_t num_matches; /* number of matches returned */ + struct pci_conf *matches; /* match buffer */ + u_int32_t offset; /* offset into device list */ + u_int32_t generation; /* device list generation */ + pci_getconf_status status; /* request status */ +}; + +struct pci_io { + struct pcisel pi_sel; /* device to operate on */ + int pi_reg; /* configuration register to examine */ + int pi_width; /* width (in bytes) of read or write */ + u_int32_t pi_data; /* data to write or result of read */ +}; + + +#define PCIOCGETCONF _IOWR('p', 1, struct pci_conf_io) +#define PCIOCREAD _IOWR('p', 2, struct pci_io) +#define PCIOCWRITE _IOWR('p', 3, struct pci_io) +#define PCIOCATTACHED _IOWR('p', 4, struct pci_io) + +#endif /* !_SYS_PCIIO_H_ */ diff --git a/src/include/sys/pcpu.h b/src/include/sys/pcpu.h new file mode 100644 index 0000000..f719d61 --- /dev/null +++ b/src/include/sys/pcpu.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2001 Wind River Systems, Inc. + * All rights reserved. + * Written by: John Baldwin + * + * 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. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/pcpu.h,v 1.13 2004/03/27 18:21:24 marcel Exp $ + */ + +#ifndef _SYS_PCPU_H_ +#define _SYS_PCPU_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +#ifdef LOCORE +#error "no assembler-serviceable parts inside" +#endif + +#include +#include +#include + +struct pcb; +struct thread; + +/* + * This structure maps out the global data that needs to be kept on a + * per-cpu basis. The members are accessed via the PCPU_GET/SET/PTR + * macros defined in . Machine dependent fields are + * defined in the PCPU_MD_FIELDS macro defined in . + */ +struct pcpu { + struct thread *pc_curthread; /* Current thread */ + struct thread *pc_idlethread; /* Idle thread */ + struct thread *pc_fpcurthread; /* Fp state owner */ + struct thread *pc_deadthread; /* Zombie thread or NULL */ + struct pcb *pc_curpcb; /* Current pcb */ + struct bintime pc_switchtime; + int pc_switchticks; + u_int pc_cpuid; /* This cpu number */ + cpumask_t pc_cpumask; /* This cpu mask */ + cpumask_t pc_other_cpus; /* Mask of all other cpus */ + SLIST_ENTRY(pcpu) pc_allcpu; + struct lock_list_entry *pc_spinlocks; +#ifdef KTR_PERCPU + int pc_ktr_idx; /* Index into trace table */ + char *pc_ktr_buf; +#endif + PCPU_MD_FIELDS; + struct vmmeter pc_cnt; /* VM stats counters */ + struct device *pc_device; +}; + +SLIST_HEAD(cpuhead, pcpu); + +extern struct cpuhead cpuhead; + +#define CURPROC (curthread->td_proc) +#define curkse (curthread->td_kse) +#define curksegrp (curthread->td_ksegrp) +#define curproc (curthread->td_proc) +#ifndef curthread +#define curthread PCPU_GET(curthread) +#endif + +/* + * MI PCPU support functions + * + * PCPU_LAZY_INC() - Lazily increment a per-cpu stats counter, without + * guarenteeing atomicity or even necessarily consistency. + * + * XXX we need to create MD primitives to support + * this to guarentee at least some level of consistency, + * i.e., to prevent us from totally corrupting the + * counters due to preemption in a multi-instruction + * increment sequence for architectures that do not + * support single-instruction memory increments. + */ +#define PCPU_LAZY_INC(var) (++*PCPU_PTR(var)) + +/* + * Machine dependent callouts. cpu_pcpu_init() is responsible for + * initializing machine dependent fields of struct pcpu, and + * db_show_mdpcpu() is responsible for handling machine dependent + * fields for the DDB 'show pcpu' command. + */ +void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size); +void db_show_mdpcpu(struct pcpu *pcpu); + +void pcpu_destroy(struct pcpu *pcpu); +struct pcpu *pcpu_find(u_int cpuid); +void pcpu_init(struct pcpu *pcpu, int cpuid, size_t size); + +#endif /* !_SYS_PCPU_H_ */ diff --git a/src/include/sys/pioctl.h b/src/include/sys/pioctl.h new file mode 100644 index 0000000..56bd653 --- /dev/null +++ b/src/include/sys/pioctl.h @@ -0,0 +1,79 @@ +/* + * Copryight 1997 Sean Eric Fagan + * + * 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 Sean Eric Fagan + * 4. Neither the name of the author may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +/* + * procfs ioctl definitions. + * + * $FreeBSD: src/sys/sys/pioctl.h,v 1.12 2002/08/04 01:06:58 mdodd Exp $ + */ + +#ifndef _SYS_PIOCTL_H +# define _SYS_PIOCTL_H + +# include + +struct procfs_status { + int state; /* Running, stopped, something else? */ + int flags; /* Any flags */ + unsigned long events; /* Events to stop on */ + int why; /* What event, if any, proc stopped on */ + unsigned long val; /* Any extra data */ +}; + +# define PIOCBIS _IOC(IOC_IN, 'p', 1, 0) /* Set event flag */ +# define PIOCBIC _IOC(IOC_IN, 'p', 2, 0) /* Clear event flag */ +# define PIOCSFL _IOC(IOC_IN, 'p', 3, 0) /* Set flags */ + /* wait for proc to stop */ +# define PIOCWAIT _IOR('p', 4, struct procfs_status) +# define PIOCCONT _IOC(IOC_IN, 'p', 5, 0) /* Continue a process */ + /* Get proc status */ +# define PIOCSTATUS _IOR('p', 6, struct procfs_status) +# define PIOCGFL _IOR('p', 7, unsigned int) /* Get flags */ + +# define S_EXEC 0x00000001 /* stop-on-exec */ +# define S_SIG 0x00000002 /* stop-on-signal */ +# define S_SCE 0x00000004 /* stop on syscall entry */ +# define S_SCX 0x00000008 /* stop on syscall exit */ +# define S_CORE 0x00000010 /* stop on coredump */ +# define S_EXIT 0x00000020 /* stop on exit */ +# define S_ALLSTOPS 0x003f /* stop on all events */ + +/* + * If PF_LINGER is set in procp->p_pfsflags, then the last close + * of a /proc//mem file will nto clear out the stops and continue + * the process. + */ + +# define PF_LINGER 0x01 /* Keep stops around after last close */ +# define PF_ISUGID 0x02 /* Ignore UID/GID changes */ +# define PF_FORK 0x04 /* Retain settings on fork() */ +#endif diff --git a/src/include/sys/pipe.h b/src/include/sys/pipe.h new file mode 100644 index 0000000..58ea038 --- /dev/null +++ b/src/include/sys/pipe.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 1996 John S. Dyson + * 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 immediately at the beginning of the file, without modification, + * 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. Absolutely no warranty of function or purpose is made by the author + * John S. Dyson. + * 4. This work was done expressly for inclusion into FreeBSD. Other use + * is allowed if this notation is included. + * 5. Modifications may be freely made to this file if the above conditions + * are met. + * + * $FreeBSD: src/sys/sys/pipe.h,v 1.27 2004/03/27 19:50:23 alc Exp $ + */ + +#ifndef _SYS_PIPE_H_ +#define _SYS_PIPE_H_ + +#ifndef _KERNEL +#include /* for struct timespec */ +#include /* for struct selinfo */ +#include /* for vm_page_t */ +#include /* for PAGE_SIZE */ +#endif + +/* + * Pipe buffer size, keep moderate in value, pipes take kva space. + */ +#ifndef PIPE_SIZE +#define PIPE_SIZE 16384 +#endif + +#ifndef BIG_PIPE_SIZE +#define BIG_PIPE_SIZE (64*1024) +#endif + +#ifndef SMALL_PIPE_SIZE +#define SMALL_PIPE_SIZE PAGE_SIZE +#endif + +/* + * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger + * than PIPE_BUF. + */ +#ifndef PIPE_MINDIRECT +#define PIPE_MINDIRECT 8192 +#endif + +#define PIPENPAGES (BIG_PIPE_SIZE / PAGE_SIZE + 1) + +/* + * See sys_pipe.c for info on what these limits mean. + */ +extern int maxpipekva; + +/* + * Pipe buffer information. + * Separate in, out, cnt are used to simplify calculations. + * Buffered write is active when the buffer.cnt field is set. + */ +struct pipebuf { + u_int cnt; /* number of chars currently in buffer */ + u_int in; /* in pointer */ + u_int out; /* out pointer */ + u_int size; /* size of buffer */ + caddr_t buffer; /* kva of buffer */ +}; + +/* + * Information to support direct transfers between processes for pipes. + */ +struct pipemapping { + vm_size_t cnt; /* number of chars in buffer */ + vm_size_t pos; /* current position of transfer */ + int npages; /* number of pages */ + vm_page_t ms[PIPENPAGES]; /* pages in source process */ +}; + +/* + * Bits in pipe_state. + */ +#define PIPE_ASYNC 0x004 /* Async? I/O. */ +#define PIPE_WANTR 0x008 /* Reader wants some characters. */ +#define PIPE_WANTW 0x010 /* Writer wants space to put characters. */ +#define PIPE_WANT 0x020 /* Pipe is wanted to be run-down. */ +#define PIPE_SEL 0x040 /* Pipe has a select active. */ +#define PIPE_EOF 0x080 /* Pipe is in EOF condition. */ +#define PIPE_LOCKFL 0x100 /* Process has exclusive access to pointers/data. */ +#define PIPE_LWANT 0x200 /* Process wants exclusive access to pointers/data. */ +#define PIPE_DIRECTW 0x400 /* Pipe direct write active. */ +#define PIPE_DIRECTOK 0x800 /* Direct mode ok. */ + +/* + * Per-pipe data structure. + * Two of these are linked together to produce bi-directional pipes. + */ +struct pipe { + struct pipebuf pipe_buffer; /* data storage */ + struct pipemapping pipe_map; /* pipe mapping for direct I/O */ + struct selinfo pipe_sel; /* for compat with select */ + struct timespec pipe_atime; /* time of last access */ + struct timespec pipe_mtime; /* time of last modify */ + struct timespec pipe_ctime; /* time of status change */ + struct sigio *pipe_sigio; /* information for async I/O */ + struct pipe *pipe_peer; /* link with other direction */ + struct pipepair *pipe_pair; /* container structure pointer */ + u_int pipe_state; /* pipe status info */ + int pipe_busy; /* busy flag, mostly to handle rundown sanely */ + int pipe_present; /* still present? */ +}; + +/* + * Container structure to hold the two pipe endpoints, mutex, and label + * pointer. + */ +struct pipepair { + struct pipe pp_rpipe; + struct pipe pp_wpipe; + struct mtx pp_mtx; + struct label *pp_label; +}; + +#define PIPE_MTX(pipe) (&(pipe)->pipe_pair->pp_mtx) +#define PIPE_LOCK(pipe) mtx_lock(PIPE_MTX(pipe)) +#define PIPE_UNLOCK(pipe) mtx_unlock(PIPE_MTX(pipe)) +#define PIPE_LOCK_ASSERT(pipe, type) mtx_assert(PIPE_MTX(pipe), (type)) + + +#endif /* !_SYS_PIPE_H_ */ diff --git a/src/include/sys/poll.h b/src/include/sys/poll.h new file mode 100644 index 0000000..9ea42b9 --- /dev/null +++ b/src/include/sys/poll.h @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 1997 Peter Wemm + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/poll.h,v 1.13 2002/07/10 04:47:25 mike Exp $ + */ + +#ifndef _SYS_POLL_H_ +#define _SYS_POLL_H_ + +#include + +/* + * This file is intended to be compatible with the traditional poll.h. + */ + +typedef unsigned int nfds_t; + +/* + * This structure is passed as an array to poll(2). + */ +struct pollfd { + int fd; /* which file descriptor to poll */ + short events; /* events we are interested in */ + short revents; /* events found on return */ +}; + +/* + * Requestable events. If poll(2) finds any of these set, they are + * copied to revents on return. + * XXX Note that FreeBSD doesn't make much distinction between POLLPRI + * and POLLRDBAND since none of the file types have distinct priority + * bands - and only some have an urgent "mode". + * XXX Note POLLIN isn't really supported in true SVSV terms. Under SYSV + * POLLIN includes all of normal, band and urgent data. Most poll handlers + * on FreeBSD only treat it as "normal" data. + */ +#define POLLIN 0x0001 /* any readable data available */ +#define POLLPRI 0x0002 /* OOB/Urgent readable data */ +#define POLLOUT 0x0004 /* file descriptor is writeable */ +#define POLLRDNORM 0x0040 /* non-OOB/URG data available */ +#define POLLWRNORM POLLOUT /* no write type differentiation */ +#define POLLRDBAND 0x0080 /* OOB/Urgent readable data */ +#define POLLWRBAND 0x0100 /* OOB/Urgent data can be written */ + +#if __BSD_VISIBLE +/* General FreeBSD extension (currently only supported for sockets): */ +#define POLLINIGNEOF 0x2000 /* like POLLIN, except ignore EOF */ +#endif + +/* + * These events are set if they occur regardless of whether they were + * requested. + */ +#define POLLERR 0x0008 /* some poll error occurred */ +#define POLLHUP 0x0010 /* file descriptor was "hung up" */ +#define POLLNVAL 0x0020 /* requested events "invalid" */ + +#if __BSD_VISIBLE + +#define POLLSTANDARD (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|\ + POLLWRBAND|POLLERR|POLLHUP|POLLNVAL) + +/* + * Request that poll() wait forever. + * XXX in SYSV, this is defined in stropts.h, which is not included + * by poll.h. + */ +#define INFTIM (-1) + +#endif + +#ifndef _KERNEL + +__BEGIN_DECLS +int poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_POLL_H_ */ diff --git a/src/include/sys/power.h b/src/include/sys/power.h new file mode 100644 index 0000000..941a7329 --- /dev/null +++ b/src/include/sys/power.h @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2001 Mitsuru IWASAKI + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/power.h,v 1.3 2002/07/15 14:06:03 markm Exp $ + */ + +#ifndef _SYS_POWER_H_ +#define _SYS_POWER_H_ + +#include + +/* Power management system type */ +#define POWER_PM_TYPE_APM 0x00 +#define POWER_PM_TYPE_ACPI 0x01 +#define POWER_PM_TYPE_NONE 0xff + +/* Commands for Power management function */ +#define POWER_CMD_SUSPEND 0x00 + +/* Sleep state */ +#define POWER_SLEEP_STATE_STANDBY 0x00 +#define POWER_SLEEP_STATE_SUSPEND 0x01 +#define POWER_SLEEP_STATE_HIBERNATE 0x02 + +typedef int (*power_pm_fn_t)(u_long, void*, ...); +extern int power_pm_register(u_int, power_pm_fn_t, void *); +extern u_int power_pm_get_type(void); +extern void power_pm_suspend(int); + +/* + * System power API. + */ +#define POWER_PROFILE_PERFORMANCE 0 +#define POWER_PROFILE_ECONOMY 1 + +extern int power_profile_get_state(void); +extern void power_profile_set_state(int); + +typedef void (*power_profile_change_hook)(void *, int); +EVENTHANDLER_DECLARE(power_profile_change, power_profile_change_hook); + +#endif /* !_SYS_POWER_H_ */ + diff --git a/src/include/sys/priority.h b/src/include/sys/priority.h new file mode 100644 index 0000000..c51d836 --- /dev/null +++ b/src/include/sys/priority.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 1994, Henrik Vestergaard Draboel + * 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 (name). + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/priority.h,v 1.2 2001/09/05 01:22:14 obrien Exp $ + */ + +#ifndef _SYS_PRIORITY_H_ +#define _SYS_PRIORITY_H_ + +/* + * Process priority specifications. + */ + +/* + * Priority classes. + */ + +#define PRI_ITHD 1 /* Interrupt thread. */ +#define PRI_REALTIME 2 /* Real time process. */ +#define PRI_TIMESHARE 3 /* Time sharing process. */ +#define PRI_IDLE 4 /* Idle process. */ + +/* + * PRI_FIFO is POSIX.1B SCHED_FIFO. + */ + +#define PRI_FIFO_BIT 8 +#define PRI_FIFO (PRI_FIFO_BIT | PRI_REALTIME) + +#define PRI_BASE(P) ((P) & ~PRI_FIFO_BIT) +#define PRI_IS_REALTIME(P) (PRI_BASE(P) == PRI_REALTIME) +#define PRI_NEED_RR(P) ((P) != PRI_FIFO) + +/* + * Priorities. Note that with 64 run queues, differences less than 4 are + * insignificant. + */ + +/* + * Priorities range from 0 to 255, but differences of less then 4 (RQ_PPQ) + * are insignificant. Ranges are as follows: + * + * Interrupt threads: 0 - 63 + * Top half kernel threads: 64 - 127 + * Realtime user threads: 128 - 159 + * Time sharing user threads: 160 - 223 + * Idle user threads: 224 - 255 + * + * XXX If/When the specific interrupt thread and top half thread ranges + * disappear, a larger range can be used for user processes. + */ + +#define PRI_MIN (0) /* Highest priority. */ +#define PRI_MAX (255) /* Lowest priority. */ + +#define PRI_MIN_ITHD (PRI_MIN) +#define PRI_MAX_ITHD (PRI_MIN_KERN - 1) + +#define PI_REALTIME (PRI_MIN_ITHD + 0) +#define PI_AV (PRI_MIN_ITHD + 4) +#define PI_TTYHIGH (PRI_MIN_ITHD + 8) +#define PI_TAPE (PRI_MIN_ITHD + 12) +#define PI_NET (PRI_MIN_ITHD + 16) +#define PI_DISK (PRI_MIN_ITHD + 20) +#define PI_TTYLOW (PRI_MIN_ITHD + 24) +#define PI_DISKLOW (PRI_MIN_ITHD + 28) +#define PI_DULL (PRI_MIN_ITHD + 32) +#define PI_SOFT (PRI_MIN_ITHD + 36) + +#define PRI_MIN_KERN (64) +#define PRI_MAX_KERN (PRI_MIN_REALTIME - 1) + +#define PSWP (PRI_MIN_KERN + 0) +#define PVM (PRI_MIN_KERN + 4) +#define PINOD (PRI_MIN_KERN + 8) +#define PRIBIO (PRI_MIN_KERN + 12) +#define PVFS (PRI_MIN_KERN + 16) +#define PZERO (PRI_MIN_KERN + 20) +#define PSOCK (PRI_MIN_KERN + 24) +#define PWAIT (PRI_MIN_KERN + 28) +#define PCONFIG (PRI_MIN_KERN + 32) +#define PLOCK (PRI_MIN_KERN + 36) +#define PPAUSE (PRI_MIN_KERN + 40) + +#define PRI_MIN_REALTIME (128) +#define PRI_MAX_REALTIME (PRI_MIN_TIMESHARE - 1) + +#define PRI_MIN_TIMESHARE (160) +#define PRI_MAX_TIMESHARE (PRI_MIN_IDLE - 1) + +#define PUSER (PRI_MIN_TIMESHARE) + +#define PRI_MIN_IDLE (224) +#define PRI_MAX_IDLE (PRI_MAX) + +struct priority { + u_char pri_class; /* Scheduling class. */ + u_char pri_level; /* Normal priority level. */ + u_char pri_native; /* Priority before propogation. */ + u_char pri_user; /* User priority based on p_cpu and p_nice. */ +}; + +#endif /* !_SYS_PRIORITY_H_ */ diff --git a/src/include/sys/proc.h b/src/include/sys/proc.h new file mode 100644 index 0000000..8191ff4 --- /dev/null +++ b/src/include/sys/proc.h @@ -0,0 +1,937 @@ +/*- + * Copyright (c) 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)proc.h 8.15 (Berkeley) 5/19/95 + * $FreeBSD: src/sys/sys/proc.h,v 1.375 2004/04/28 20:36:53 deischen Exp $ + */ + +#ifndef _SYS_PROC_H_ +#define _SYS_PROC_H_ + +#include /* For struct callout. */ +#include /* For struct klist. */ +#ifndef _KERNEL +#include +#endif +#include +#include +#include +#include +#include /* XXX. */ +#include +#include +#include +#ifndef _KERNEL +#include /* For structs itimerval, timeval. */ +#else +#include +#endif +#include +#include +#include /* Machine-dependent proc substruct. */ + +/* + * One structure allocated per session. + * + * List of locks + * (m) locked by s_mtx mtx + * (e) locked by proctree_lock sx + * (c) const until freeing + */ +struct session { + int s_count; /* (m) Ref cnt; pgrps in session. */ + struct proc *s_leader; /* (m + e) Session leader. */ + struct vnode *s_ttyvp; /* (m) Vnode of controlling tty. */ + struct tty *s_ttyp; /* (m) Controlling tty. */ + pid_t s_sid; /* (c) Session ID. */ + /* (m) Setlogin() name: */ + char s_login[roundup(MAXLOGNAME, sizeof(long))]; + struct mtx s_mtx; /* Mutex to protect members. */ +}; + +/* + * One structure allocated per process group. + * + * List of locks + * (m) locked by pg_mtx mtx + * (e) locked by proctree_lock sx + * (c) const until freeing + */ +struct pgrp { + LIST_ENTRY(pgrp) pg_hash; /* (e) Hash chain. */ + LIST_HEAD(, proc) pg_members; /* (m + e) Pointer to pgrp members. */ + struct session *pg_session; /* (c) Pointer to session. */ + struct sigiolst pg_sigiolst; /* (m) List of sigio sources. */ + pid_t pg_id; /* (c) Pgrp id. */ + int pg_jobc; /* (m) job cntl proc count */ + struct mtx pg_mtx; /* Mutex to protect members */ +}; + +/* + * pargs, used to hold a copy of the command line, if it had a sane length. + */ +struct pargs { + u_int ar_ref; /* Reference count. */ + u_int ar_length; /* Length. */ + u_char ar_args[1]; /* Arguments. */ +}; + +/*- + * Description of a process. + * + * This structure contains the information needed to manage a thread of + * control, known in UN*X as a process; it has references to substructures + * containing descriptions of things that the process uses, but may share + * with related processes. The process structure and the substructures + * are always addressable except for those marked "(CPU)" below, + * which might be addressable only on a processor on which the process + * is running. + * + * Below is a key of locks used to protect each member of struct proc. The + * lock is indicated by a reference to a specific character in parens in the + * associated comment. + * * - not yet protected + * a - only touched by curproc or parent during fork/wait + * b - created at fork, never changes + * (exception aiods switch vmspaces, but they are also + * marked 'P_SYSTEM' so hopefully it will be left alone) + * c - locked by proc mtx + * d - locked by allproc_lock lock + * e - locked by proctree_lock lock + * f - session mtx + * g - process group mtx + * h - callout_lock mtx + * i - by curproc or the master session mtx + * j - locked by sched_lock mtx + * k - only accessed by curthread + * l - the attaching proc or attaching proc parent + * m - Giant + * n - not locked, lazy + * o - ktrace lock + * p - select lock (sellock) + * q - td_contested lock + * r - p_peers lock + * x - created at fork, only changes during single threading in exec + * z - zombie threads/kse/ksegroup lock + * + * If the locking key specifies two identifiers (for example, p_pptr) then + * either lock is sufficient for read access, but both locks must be held + * for write access. + */ +struct ithd; +struct ke_sched; +struct kg_sched; +struct nlminfo; +struct p_sched; +struct sleepqueue; +struct td_sched; +struct trapframe; +struct turnstile; + +/* + * Here we define the four structures used for process information. + * + * The first is the thread. It might be though of as a "Kernel + * Schedulable Entity Context". + * This structure contains all the information as to where a thread of + * execution is now, or was when it was suspended, why it was suspended, + * and anything else that will be needed to restart it when it is + * rescheduled. Always associated with a KSE when running, but can be + * reassigned to an equivalent KSE when being restarted for + * load balancing. Each of these is associated with a kernel stack + * and a pcb. + * + * It is important to remember that a particular thread structure only + * exists as long as the system call or kernel entrance (e.g. by pagefault) + * which it is currently executing. It should therefore NEVER be referenced + * by pointers in long lived structures that live longer than a single + * request. If several threads complete their work at the same time, + * they will all rewind their stacks to the user boundary, report their + * completion state, and all but one will be freed. That last one will + * be kept to provide a kernel stack and pcb for the NEXT syscall or kernel + * entrance. (basically to save freeing and then re-allocating it) The KSE + * keeps a cached thread available to allow it to quickly + * get one when it needs a new one. There is also a system + * cache of free threads. Threads have priority and partake in priority + * inheritance schemes. + */ +struct thread; + +/* + * The second structure is the Kernel Schedulable Entity. (KSE) + * It represents the ability to take a slot in the scheduler queue. + * As long as this is scheduled, it could continue to run any threads that + * are assigned to the KSEGRP (see later) until either it runs out + * of runnable threads of high enough priority, or CPU. + * It runs on one CPU and is assigned a quantum of time. When a thread is + * blocked, The KSE continues to run and will search for another thread + * in a runnable state amongst those it has. It May decide to return to user + * mode with a new 'empty' thread if there are no runnable threads. + * Threads are temporarily associated with a KSE for scheduling reasons. + */ +struct kse; + +/* + * The KSEGRP is allocated resources across a number of CPUs. + * (Including a number of CPUxQUANTA. It parcels these QUANTA up among + * its KSEs, each of which should be running in a different CPU. + * BASE priority and total available quanta are properties of a KSEGRP. + * Multiple KSEGRPs in a single process compete against each other + * for total quanta in the same way that a forked child competes against + * it's parent process. + */ +struct ksegrp; + +/* + * A process is the owner of all system resources allocated to a task + * except CPU quanta. + * All KSEGs under one process see, and have the same access to, these + * resources (e.g. files, memory, sockets, permissions kqueues). + * A process may compete for CPU cycles on the same basis as a + * forked process cluster by spawning several KSEGRPs. + */ +struct proc; + +/*************** + * In pictures: + With a single run queue used by all processors: + + RUNQ: --->KSE---KSE--... SLEEPQ:[]---THREAD---THREAD---THREAD + | / []---THREAD + KSEG---THREAD--THREAD--THREAD [] + []---THREAD---THREAD + + (processors run THREADs from the KSEG until they are exhausted or + the KSEG exhausts its quantum) + +With PER-CPU run queues: +KSEs on the separate run queues directly +They would be given priorities calculated from the KSEG. + + * + *****************/ + +/* + * Kernel runnable context (thread). + * This is what is put to sleep and reactivated. + * The first KSE available in the correct group will run this thread. + * If several are available, use the one on the same CPU as last time. + * When waiting to be run, threads are hung off the KSEGRP in priority order. + * with N runnable and queued KSEs in the KSEGRP, the first N threads + * are linked to them. Other threads are not yet assigned. + */ +struct thread { + struct proc *td_proc; /* (*) Associated process. */ + struct ksegrp *td_ksegrp; /* (*) Associated KSEG. */ + TAILQ_ENTRY(thread) td_plist; /* (*) All threads in this proc. */ + TAILQ_ENTRY(thread) td_kglist; /* (*) All threads in this ksegrp. */ + + /* The two queues below should someday be merged. */ + TAILQ_ENTRY(thread) td_slpq; /* (j) Sleep queue. */ + TAILQ_ENTRY(thread) td_lockq; /* (j) Lock queue. */ + TAILQ_ENTRY(thread) td_runq; /* (j/z) Run queue(s). XXXKSE */ + + TAILQ_HEAD(, selinfo) td_selq; /* (p) List of selinfos. */ + struct sleepqueue *td_sleepqueue; /* (k) Associated sleep queue. */ + struct turnstile *td_turnstile; /* (k) Associated turnstile. */ + int td_tid; /* (b) Thread ID. */ + +/* Cleared during fork1() or thread_sched_upcall(). */ +#define td_startzero td_flags + int td_flags; /* (j) TDF_* flags. */ + int td_inhibitors; /* (j) Why can not run. */ + int td_pflags; /* (k) Private thread (TDP_*) flags. */ + struct kse *td_last_kse; /* (j) Previous value of td_kse. */ + struct kse *td_kse; /* (j) Current KSE if running. */ + int td_dupfd; /* (k) Ret value from fdopen. XXX */ + void *td_wchan; /* (j) Sleep address. */ + const char *td_wmesg; /* (j) Reason for sleep. */ + u_char td_lastcpu; /* (j) Last cpu we were on. */ + u_char td_oncpu; /* (j) Which cpu we are on. */ + short td_locks; /* (k) DEBUG: lockmgr count of locks. */ + struct turnstile *td_blocked; /* (j) Lock process is blocked on. */ + struct ithd *td_ithd; /* (b) For interrupt threads only. */ + const char *td_lockname; /* (j) Name of lock blocked on. */ + LIST_HEAD(, turnstile) td_contested; /* (q) Contested locks. */ + struct lock_list_entry *td_sleeplocks; /* (k) Held sleep locks. */ + int td_intr_nesting_level; /* (k) Interrupt recursion. */ + int td_pinned; /* (k) Temporary cpu pin count. */ + struct kse_thr_mailbox *td_mailbox; /* (*) Userland mailbox address. */ + struct ucred *td_ucred; /* (k) Reference to credentials. */ + struct thread *td_standin; /* (*) Use this for an upcall. */ + u_int td_prticks; /* (*) Profclock hits in sys for user */ + struct kse_upcall *td_upcall; /* (*) Upcall structure. */ + u_int64_t td_sticks; /* (j) Statclock hits in system mode. */ + u_int td_uuticks; /* (*) Statclock in user, for UTS. */ + u_int td_usticks; /* (*) Statclock in kernel, for UTS. */ + int td_intrval; /* (*) Return value of TDF_INTERRUPT. */ + sigset_t td_oldsigmask; /* (k) Saved mask from pre sigpause. */ + sigset_t td_sigmask; /* (c) Current signal mask. */ + sigset_t td_siglist; /* (c) Sigs arrived, not delivered. */ + sigset_t *td_waitset; /* (c) Wait set for sigwait. */ + TAILQ_ENTRY(thread) td_umtx; /* (c?) Link for when we're blocked. */ + volatile u_int td_generation; /* (k) Enable detection of preemption */ + stack_t td_sigstk; /* (k) Stack ptr and on-stack flag. */ + int td_kflags; /* (c) Flags for KSE threading. */ + +#define td_endzero td_base_pri + +/* Copied during fork1() or thread_sched_upcall(). */ +#define td_startcopy td_endzero + u_char td_base_pri; /* (j) Thread base kernel priority. */ + u_char td_priority; /* (j) Thread active priority. */ +#define td_endcopy td_pcb + +/* + * fields that must be manually set in fork1() or thread_sched_upcall() + * or already have been set in the allocator, contstructor, etc.. + */ + struct pcb *td_pcb; /* (k) Kernel VA of pcb and kstack. */ + enum { + TDS_INACTIVE = 0x0, + TDS_INHIBITED, + TDS_CAN_RUN, + TDS_RUNQ, + TDS_RUNNING + } td_state; + register_t td_retval[2]; /* (k) Syscall aux returns. */ + struct callout td_slpcallout; /* (h) Callout for sleep. */ + struct trapframe *td_frame; /* (k) */ + struct vm_object *td_kstack_obj;/* (a) Kstack object. */ + vm_offset_t td_kstack; /* (a) Kernel VA of kstack. */ + int td_kstack_pages; /* (a) Size of the kstack. */ + struct vm_object *td_altkstack_obj;/* (a) Alternate kstack object. */ + vm_offset_t td_altkstack; /* (a) Kernel VA of alternate kstack. */ + int td_altkstack_pages; /* (a) Size of the alternate kstack */ + u_int td_critnest; /* (k) Critical section nest level. */ + struct mdthread td_md; /* (k) Any machine-dependent fields. */ + struct td_sched *td_sched; /* (*) Scheduler-specific data. */ +}; + +/* Flags kept in td_flags: */ +#define TDF_INPANIC 0x000002 /* Caused a panic, let it drive crashdump. */ +#define TDF_CAN_UNBIND 0x000004 /* Only temporarily bound. */ +#define TDF_SINTR 0x000008 /* Sleep is interruptible. */ +#define TDF_TIMEOUT 0x000010 /* Timing out during sleep. */ +#define TDF_IDLETD 0x000020 /* This is one of the per-CPU idle threads. */ +#define TDF_SELECT 0x000040 /* Selecting; wakeup/waiting danger. */ +#define TDF_TSNOBLOCK 0x000100 /* Don't block on a turnstile due to race. */ +#define TDF_ASTPENDING 0x000800 /* Thread has some asynchronous events. */ +#define TDF_TIMOFAIL 0x001000 /* Timeout from sleep after we were awake. */ +#define TDF_INTERRUPT 0x002000 /* Thread is marked as interrupted. */ +#define TDF_USTATCLOCK 0x004000 /* Finish user statclock hit at next AST. */ +#define TDF_OWEUPC 0x008000 /* Owe thread an addupc() call at next AST. */ +#define TDF_NEEDRESCHED 0x010000 /* Thread needs to yield. */ +#define TDF_NEEDSIGCHK 0x020000 /* Thread may need signal delivery. */ +#define TDF_SA 0x040000 /* A scheduler activation based thread. */ +#define TDF_UMTXWAKEUP 0x080000 /* Libthr thread must not sleep on a umtx. */ +#define TDF_THRWAKEUP 0x100000 /* Libthr thread must not suspend itself. */ +#define TDF_DEADLKTREAT 0x800000 /* Lock aquisition - deadlock treatment. */ + +/* "Private" flags kept in td_pflags: */ +#define TDP_OLDMASK 0x0001 /* Need to restore mask after suspend. */ +#define TDP_INKTR 0x0002 /* Thread is currently in KTR code. */ +#define TDP_INKTRACE 0x0004 /* Thread is currently in KTRACE code. */ +#define TDP_UPCALLING 0x0008 /* This thread is doing an upcall. */ +#define TDP_COWINPROGRESS 0x0010 /* Snapshot copy-on-write in progress. */ +#define TDP_ALTSTACK 0x0020 /* Have alternate signal stack. */ + +#define TDI_SUSPENDED 0x0001 /* On suspension queue. */ +#define TDI_SLEEPING 0x0002 /* Actually asleep! (tricky). */ +#define TDI_SWAPPED 0x0004 /* Stack not in mem.. bad juju if run. */ +#define TDI_LOCK 0x0008 /* Stopped on a lock. */ +#define TDI_IWAIT 0x0010 /* Awaiting interrupt. */ + +#define TDK_KSEREL 0x0001 /* Blocked in msleep on kg->kg_completed. */ +#define TDK_KSERELSIG 0x0002 /* Blocked in msleep on p->p_siglist. */ +#define TDK_WAKEUP 0x0004 /* Thread has been woken by kse_wakeup. */ + +#define TD_CAN_UNBIND(td) \ + (((td)->td_flags & TDF_CAN_UNBIND) == TDF_CAN_UNBIND && \ + ((td)->td_upcall != NULL)) + +#define TD_IS_SLEEPING(td) ((td)->td_inhibitors & TDI_SLEEPING) +#define TD_ON_SLEEPQ(td) ((td)->td_wchan != NULL) +#define TD_IS_SUSPENDED(td) ((td)->td_inhibitors & TDI_SUSPENDED) +#define TD_IS_SWAPPED(td) ((td)->td_inhibitors & TDI_SWAPPED) +#define TD_ON_LOCK(td) ((td)->td_inhibitors & TDI_LOCK) +#define TD_AWAITING_INTR(td) ((td)->td_inhibitors & TDI_IWAIT) +#define TD_IS_RUNNING(td) ((td)->td_state == TDS_RUNNING) +#define TD_ON_RUNQ(td) ((td)->td_state == TDS_RUNQ) +#define TD_CAN_RUN(td) ((td)->td_state == TDS_CAN_RUN) +#define TD_IS_INHIBITED(td) ((td)->td_state == TDS_INHIBITED) + +#define TD_SET_INHIB(td, inhib) do { \ + (td)->td_state = TDS_INHIBITED; \ + (td)->td_inhibitors |= (inhib); \ +} while (0) + +#define TD_CLR_INHIB(td, inhib) do { \ + if (((td)->td_inhibitors & (inhib)) && \ + (((td)->td_inhibitors &= ~(inhib)) == 0)) \ + (td)->td_state = TDS_CAN_RUN; \ +} while (0) + +#define TD_SET_SLEEPING(td) TD_SET_INHIB((td), TDI_SLEEPING) +#define TD_SET_SWAPPED(td) TD_SET_INHIB((td), TDI_SWAPPED) +#define TD_SET_LOCK(td) TD_SET_INHIB((td), TDI_LOCK) +#define TD_SET_SUSPENDED(td) TD_SET_INHIB((td), TDI_SUSPENDED) +#define TD_SET_IWAIT(td) TD_SET_INHIB((td), TDI_IWAIT) +#define TD_SET_EXITING(td) TD_SET_INHIB((td), TDI_EXITING) + +#define TD_CLR_SLEEPING(td) TD_CLR_INHIB((td), TDI_SLEEPING) +#define TD_CLR_SWAPPED(td) TD_CLR_INHIB((td), TDI_SWAPPED) +#define TD_CLR_LOCK(td) TD_CLR_INHIB((td), TDI_LOCK) +#define TD_CLR_SUSPENDED(td) TD_CLR_INHIB((td), TDI_SUSPENDED) +#define TD_CLR_IWAIT(td) TD_CLR_INHIB((td), TDI_IWAIT) + +#define TD_SET_RUNNING(td) (td)->td_state = TDS_RUNNING +#define TD_SET_RUNQ(td) (td)->td_state = TDS_RUNQ +#define TD_SET_CAN_RUN(td) (td)->td_state = TDS_CAN_RUN + +/* + * The schedulable entity that can be given a context to run. + * A process may have several of these. Probably one per processor + * but posibly a few more. In this universe they are grouped + * with a KSEG that contains the priority and niceness + * for the group. + */ +struct kse { + struct proc *ke_proc; /* (*) Associated process. */ + struct ksegrp *ke_ksegrp; /* (*) Associated KSEG. */ + TAILQ_ENTRY(kse) ke_kglist; /* (*) Queue of KSEs in ke_ksegrp. */ + TAILQ_ENTRY(kse) ke_kgrlist; /* (*) Queue of KSEs in this state. */ + TAILQ_ENTRY(kse) ke_procq; /* (j/z) Run queue. */ + +#define ke_startzero ke_flags + int ke_flags; /* (j) KEF_* flags. */ + struct thread *ke_thread; /* (*) Active associated thread. */ + fixpt_t ke_pctcpu; /* (j) %cpu during p_swtime. */ + u_char ke_oncpu; /* (j) Which cpu we are on. */ + char ke_rqindex; /* (j) Run queue index. */ + enum { + KES_UNUSED = 0x0, + KES_IDLE, + KES_ONRUNQ, + KES_UNQUEUED, /* in transit */ + KES_THREAD /* slaved to thread state */ + } ke_state; /* (j) KSE status. */ +#define ke_endzero ke_dummy + u_char ke_dummy; + struct ke_sched *ke_sched; /* (*) Scheduler-specific data. */ +}; + +/* flags kept in ke_flags */ +#define KEF_SCHED0 0x00001 /* For scheduler-specific use. */ +#define KEF_SCHED1 0x00002 /* For scheduler-specific use. */ +#define KEF_SCHED2 0X00004 /* For scheduler-specific use. */ +#define KEF_SCHED3 0x00008 /* For scheduler-specific use. */ +#define KEF_DIDRUN 0x02000 /* KSE actually ran. */ +#define KEF_EXIT 0x04000 /* KSE is being killed. */ + +/* + * The upcall management structure. + * The upcall is used when returning to userland. If a thread does not have + * an upcall on return to userland the thread exports its context and exits. + */ +struct kse_upcall { + TAILQ_ENTRY(kse_upcall) ku_link; /* List of upcalls in KSEG. */ + struct ksegrp *ku_ksegrp; /* Associated KSEG. */ + struct thread *ku_owner; /* owning thread */ + int ku_flags; /* KUF_* flags. */ + struct kse_mailbox *ku_mailbox; /* userland mailbox address. */ + stack_t ku_stack; /* userland upcall stack. */ + void *ku_func; /* userland upcall function. */ + unsigned int ku_mflags; /* cached upcall mailbox flags */ +}; + +#define KUF_DOUPCALL 0x00001 /* Do upcall now, don't wait. */ +#define KUF_EXITING 0x00002 /* Upcall structure is exiting. */ + +/* + * Kernel-scheduled entity group (KSEG). The scheduler considers each KSEG to + * be an indivisible unit from a time-sharing perspective, though each KSEG may + * contain multiple KSEs. + */ +struct ksegrp { + struct proc *kg_proc; /* (*) Process that contains this KSEG. */ + TAILQ_ENTRY(ksegrp) kg_ksegrp; /* (*) Queue of KSEGs in kg_proc. */ + TAILQ_HEAD(, kse) kg_kseq; /* (ke_kglist) All KSEs. */ + TAILQ_HEAD(, kse) kg_iq; /* (ke_kgrlist) All idle KSEs. */ + TAILQ_HEAD(, thread) kg_threads;/* (td_kglist) All threads. */ + TAILQ_HEAD(, thread) kg_runq; /* (td_runq) waiting RUNNABLE threads */ + TAILQ_HEAD(, thread) kg_slpq; /* (td_runq) NONRUNNABLE threads. */ + TAILQ_HEAD(, kse_upcall) kg_upcalls; /* All upcalls in the group. */ +#define kg_startzero kg_estcpu + u_int kg_estcpu; /* (j) Sum of the same field in KSEs. */ + u_int kg_slptime; /* (j) How long completely blocked. */ + struct thread *kg_last_assigned; /* (j) Last thread assigned to a KSE. */ + int kg_runnable; /* (j) Num runnable threads on queue. */ + int kg_runq_kses; /* (j) Num KSEs on runq. */ + int kg_idle_kses; /* (j) Num KSEs on iq. */ + int kg_numupcalls; /* (j) Num upcalls. */ + int kg_upsleeps; /* (c) Num threads in kse_release(). */ + struct kse_thr_mailbox *kg_completed; /* (c) Completed thread mboxes. */ + int kg_nextupcall; /* (*) Next upcall time. */ + int kg_upquantum; /* (*) Quantum to schedule an upcall. */ +#define kg_endzero kg_pri_class + +#define kg_startcopy kg_endzero + u_char kg_pri_class; /* (j) Scheduling class. */ + u_char kg_user_pri; /* (j) User pri from estcpu and nice. */ + signed char kg_nice; /* (c + j) Process "nice" value. */ +#define kg_endcopy kg_numthreads + int kg_numthreads; /* (j) Num threads in total. */ + int kg_kses; /* (j) Num KSEs in group. */ + struct kg_sched *kg_sched; /* (*) Scheduler-specific data. */ +}; + +/* + * The old fashionned process. May have multiple threads, KSEGRPs + * and KSEs. Starts off with a single embedded KSEGRP, KSE and THREAD. + */ +struct proc { + LIST_ENTRY(proc) p_list; /* (d) List of all processes. */ + TAILQ_HEAD(, ksegrp) p_ksegrps; /* (kg_ksegrp) All KSEGs. */ + TAILQ_HEAD(, thread) p_threads; /* (td_plist) Threads. (shortcut) */ + TAILQ_HEAD(, thread) p_suspended; /* (td_runq) Suspended threads. */ + struct ucred *p_ucred; /* (c) Process owner's identity. */ + struct filedesc *p_fd; /* (b) Ptr to open files structure. */ + struct filedesc_to_leader *p_fdtol; /* (b) Ptr to tracking node */ + /* Accumulated stats for all KSEs? */ + struct pstats *p_stats; /* (b) Accounting/statistics (CPU). */ + struct plimit *p_limit; /* (c) Process limits. */ + struct vm_object *p_upages_obj; /* (a) Upages object. */ + struct sigacts *p_sigacts; /* (x) Signal actions, state (CPU). */ + /* + * The following don't make too much sense.. + * See the td_ or ke_ versions of the same flags + */ + int p_flag; /* (c) P_* flags. */ + int p_sflag; /* (j) PS_* flags. */ + enum { + PRS_NEW = 0, /* In creation */ + PRS_NORMAL, /* KSEs can be run. */ + PRS_ZOMBIE + } p_state; /* (j/c) S* process status. */ + pid_t p_pid; /* (b) Process identifier. */ + LIST_ENTRY(proc) p_hash; /* (d) Hash chain. */ + LIST_ENTRY(proc) p_pglist; /* (g + e) List of processes in pgrp. */ + struct proc *p_pptr; /* (c + e) Pointer to parent process. */ + LIST_ENTRY(proc) p_sibling; /* (e) List of sibling processes. */ + LIST_HEAD(, proc) p_children; /* (e) Pointer to list of children. */ + struct mtx p_mtx; /* (n) Lock for this struct. */ + +/* The following fields are all zeroed upon creation in fork. */ +#define p_startzero p_oppid + pid_t p_oppid; /* (c + e) Save ppid in ptrace. XXX */ + struct vmspace *p_vmspace; /* (b) Address space. */ + u_int p_swtime; /* (j) Time swapped in or out. */ + struct itimerval p_realtimer; /* (c) Alarm timer. */ + struct bintime p_runtime; /* (j) Real time. */ + u_int64_t p_uu; /* (j) Previous user time in usec. */ + u_int64_t p_su; /* (j) Previous system time in usec. */ + u_int64_t p_iu; /* (j) Previous intr time in usec. */ + u_int64_t p_uticks; /* (j) Statclock hits in user mode. */ + u_int64_t p_sticks; /* (j) Statclock hits in system mode. */ + u_int64_t p_iticks; /* (j) Statclock hits in intr. */ + int p_profthreads; /* (c) Num threads in addupc_task. */ + int p_maxthrwaits; /* (c) Max threads num waiters */ + int p_traceflag; /* (o) Kernel trace points. */ + struct vnode *p_tracevp; /* (c + o) Trace to vnode. */ + struct ucred *p_tracecred; /* (o) Credentials to trace with. */ + struct vnode *p_textvp; /* (b) Vnode of executable. */ + sigset_t p_siglist; /* (c) Sigs not delivered to a td. */ + char p_lock; /* (c) Proclock (prevent swap) count. */ + struct klist p_klist; /* (c) Knotes attached to this proc. */ + struct sigiolst p_sigiolst; /* (c) List of sigio sources. */ + int p_sigparent; /* (c) Signal to parent on exit. */ + int p_sig; /* (n) For core dump/debugger XXX. */ + u_long p_code; /* (n) For core dump/debugger XXX. */ + u_int p_stops; /* (c) Stop event bitmask. */ + u_int p_stype; /* (c) Stop event type. */ + char p_step; /* (c) Process is stopped. */ + u_char p_pfsflags; /* (c) Procfs flags. */ + struct nlminfo *p_nlminfo; /* (?) Only used by/for lockd. */ + void *p_aioinfo; /* (?) ASYNC I/O info. */ + struct thread *p_singlethread;/* (c + j) If single threading this is it */ + int p_suspcount; /* (c) # threads in suspended mode */ +/* End area that is zeroed on creation. */ +#define p_endzero p_magic + +/* The following fields are all copied upon creation in fork. */ +#define p_startcopy p_endzero + u_int p_magic; /* (b) Magic number. */ + char p_comm[MAXCOMLEN + 1]; /* (b) Process name. */ + struct pgrp *p_pgrp; /* (c + e) Pointer to process group. */ + struct sysentvec *p_sysent; /* (b) Syscall dispatch info. */ + struct pargs *p_args; /* (c) Process arguments. */ + rlim_t p_cpulimit; /* (j) Current CPU limit in seconds. */ +/* End area that is copied on creation. */ +#define p_endcopy p_xstat + + u_short p_xstat; /* (c) Exit status; also stop sig. */ + int p_numthreads; /* (j) Number of threads. */ + int p_numksegrps; /* (?) number of ksegrps */ + struct mdproc p_md; /* Any machine-dependent fields. */ + struct callout p_itcallout; /* (h + c) Interval timer callout. */ + struct user *p_uarea; /* (k) Kernel VA of u-area (CPU). */ + u_short p_acflag; /* (c) Accounting flags. */ + struct rusage *p_ru; /* (a) Exit information. XXX */ + struct proc *p_peers; /* (r) */ + struct proc *p_leader; /* (b) */ + void *p_emuldata; /* (c) Emulator state data. */ + struct label *p_label; /* (*) Proc (not subject) MAC label. */ + struct p_sched *p_sched; /* (*) Scheduler-specific data. */ +}; + +#define p_session p_pgrp->pg_session +#define p_pgid p_pgrp->pg_id + +#define NOCPU 0xff /* For when we aren't on a CPU. (SMP) */ + +/* Status values (p_stat). */ + +/* These flags are kept in p_flag. */ +#define P_ADVLOCK 0x00001 /* Process may hold a POSIX advisory lock. */ +#define P_CONTROLT 0x00002 /* Has a controlling terminal. */ +#define P_KTHREAD 0x00004 /* Kernel thread. (*)*/ +#define P_NOLOAD 0x00008 /* Ignore during load avg calculations. */ +#define P_PPWAIT 0x00010 /* Parent is waiting for child to exec/exit. */ +#define P_PROFIL 0x00020 /* Has started profiling. */ +#define P_STOPPROF 0x00040 /* Has thread in requesting to stop prof */ +#define P_SUGID 0x00100 /* Had set id privileges since last exec. */ +#define P_SYSTEM 0x00200 /* System proc: no sigs, stats or swapping. */ +#define P_SINGLE_EXIT 0x00400 /* Threads suspending should exit, not wait. */ +#define P_TRACED 0x00800 /* Debugged process being traced. */ +#define P_WAITED 0x01000 /* Someone is waiting for us. */ +#define P_WEXIT 0x02000 /* Working on exiting. */ +#define P_EXEC 0x04000 /* Process called exec. */ +#define P_SA 0x08000 /* Using scheduler activations. */ +#define P_CONTINUED 0x10000 /* Proc has continued from a stopped state. */ +#define P_STOPPED_SIG 0x20000 /* Stopped due to SIGSTOP/SIGTSTP. */ +#define P_STOPPED_TRACE 0x40000 /* Stopped because of tracing. */ +#define P_STOPPED_SINGLE 0x80000 /* Only one thread can continue */ + /* (not to user) */ +#define P_PROTECTED 0x100000 /* Do not kill on memory overcommit. */ +#define P_SIGEVENT 0x200000 /* Process pending signals changed. */ + +#define P_JAILED 0x1000000 /* Process is in jail. */ +#define P_INEXEC 0x4000000 /* Process is in execve(). */ + +#define P_STOPPED (P_STOPPED_SIG|P_STOPPED_SINGLE|P_STOPPED_TRACE) +#define P_SHOULDSTOP(p) ((p)->p_flag & P_STOPPED) + +/* These flags are kept in p_sflag and are protected with sched_lock. */ +#define PS_INMEM 0x00001 /* Loaded into memory. */ +#define PS_XCPU 0x00002 /* Exceeded CPU limit. */ +#define PS_ALRMPEND 0x00020 /* Pending SIGVTALRM needs to be posted. */ +#define PS_PROFPEND 0x00040 /* Pending SIGPROF needs to be posted. */ +#define PS_SWAPINREQ 0x00100 /* Swapin request due to wakeup. */ +#define PS_SWAPPINGOUT 0x00200 /* Process is being swapped out. */ +#define PS_SWAPPINGIN 0x04000 /* Process is being swapped in. */ +#define PS_MACPEND 0x08000 /* Ast()-based MAC event pending. */ + +/* used only in legacy conversion code */ +#define SIDL 1 /* Process being created by fork. */ +#define SRUN 2 /* Currently runnable. */ +#define SSLEEP 3 /* Sleeping on an address. */ +#define SSTOP 4 /* Process debugging or suspension. */ +#define SZOMB 5 /* Awaiting collection by parent. */ +#define SWAIT 6 /* Waiting for interrupt. */ +#define SLOCK 7 /* Blocked on a lock. */ + +#define P_MAGIC 0xbeefface + +#ifdef _KERNEL + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_PARGS); +MALLOC_DECLARE(M_PGRP); +MALLOC_DECLARE(M_SESSION); +MALLOC_DECLARE(M_SUBPROC); +MALLOC_DECLARE(M_ZOMBIE); +#endif + +#define FOREACH_PROC_IN_SYSTEM(p) \ + LIST_FOREACH((p), &allproc, p_list) +#define FOREACH_KSEGRP_IN_PROC(p, kg) \ + TAILQ_FOREACH((kg), &(p)->p_ksegrps, kg_ksegrp) +#define FOREACH_THREAD_IN_GROUP(kg, td) \ + TAILQ_FOREACH((td), &(kg)->kg_threads, td_kglist) +#define FOREACH_KSE_IN_GROUP(kg, ke) \ + TAILQ_FOREACH((ke), &(kg)->kg_kseq, ke_kglist) +#define FOREACH_UPCALL_IN_GROUP(kg, ku) \ + TAILQ_FOREACH((ku), &(kg)->kg_upcalls, ku_link) +#define FOREACH_THREAD_IN_PROC(p, td) \ + TAILQ_FOREACH((td), &(p)->p_threads, td_plist) + +/* XXXKSE the lines below should probably only be used in 1:1 code */ +#define FIRST_THREAD_IN_PROC(p) TAILQ_FIRST(&(p)->p_threads) +#define FIRST_KSEGRP_IN_PROC(p) TAILQ_FIRST(&(p)->p_ksegrps) +#define FIRST_KSE_IN_KSEGRP(kg) TAILQ_FIRST(&(kg)->kg_kseq) +#define FIRST_KSE_IN_PROC(p) FIRST_KSE_IN_KSEGRP(FIRST_KSEGRP_IN_PROC(p)) + +/* + * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t, + * as it is used to represent "no process group". + */ +#define PID_MAX 99999 +#define NO_PID 100000 + +#define SESS_LEADER(p) ((p)->p_session->s_leader == (p)) +#define SESSHOLD(s) ((s)->s_count++) +#define SESSRELE(s) { \ + if (--(s)->s_count == 0) \ + FREE(s, M_SESSION); \ +} + +#define STOPEVENT(p, e, v) do { \ + if ((p)->p_stops & (e)) { \ + PROC_LOCK(p); \ + stopevent((p), (e), (v)); \ + PROC_UNLOCK(p); \ + } \ +} while (0) +#define _STOPEVENT(p, e, v) do { \ + PROC_LOCK_ASSERT(p, MA_OWNED); \ + if ((p)->p_stops & (e)) \ + stopevent((p), (e), (v)); \ +} while (0) + +/* Lock and unlock a process. */ +#define PROC_LOCK(p) mtx_lock(&(p)->p_mtx) +#define PROC_TRYLOCK(p) mtx_trylock(&(p)->p_mtx) +#define PROC_UNLOCK(p) mtx_unlock(&(p)->p_mtx) +#define PROC_LOCKED(p) mtx_owned(&(p)->p_mtx) +#define PROC_LOCK_ASSERT(p, type) mtx_assert(&(p)->p_mtx, (type)) + +/* Lock and unlock a process group. */ +#define PGRP_LOCK(pg) mtx_lock(&(pg)->pg_mtx) +#define PGRP_UNLOCK(pg) mtx_unlock(&(pg)->pg_mtx) +#define PGRP_LOCKED(pg) mtx_owned(&(pg)->pg_mtx) +#define PGRP_LOCK_ASSERT(pg, type) mtx_assert(&(pg)->pg_mtx, (type)) + +#define PGRP_LOCK_PGSIGNAL(pg) do { \ + if ((pg) != NULL) \ + PGRP_LOCK(pg); \ +} while (0) +#define PGRP_UNLOCK_PGSIGNAL(pg) do { \ + if ((pg) != NULL) \ + PGRP_UNLOCK(pg); \ +} while (0) + +/* Lock and unlock a session. */ +#define SESS_LOCK(s) mtx_lock(&(s)->s_mtx) +#define SESS_UNLOCK(s) mtx_unlock(&(s)->s_mtx) +#define SESS_LOCKED(s) mtx_owned(&(s)->s_mtx) +#define SESS_LOCK_ASSERT(s, type) mtx_assert(&(s)->s_mtx, (type)) + +/* Hold process U-area in memory, normally for ptrace/procfs work. */ +#define PHOLD(p) do { \ + PROC_LOCK(p); \ + _PHOLD(p); \ + PROC_UNLOCK(p); \ +} while (0) +#define _PHOLD(p) do { \ + PROC_LOCK_ASSERT((p), MA_OWNED); \ + (p)->p_lock++; \ + if (((p)->p_sflag & PS_INMEM) == 0) \ + faultin((p)); \ +} while (0) + +#define PRELE(p) do { \ + PROC_LOCK((p)); \ + _PRELE((p)); \ + PROC_UNLOCK((p)); \ +} while (0) +#define _PRELE(p) do { \ + PROC_LOCK_ASSERT((p), MA_OWNED); \ + (--(p)->p_lock); \ +} while (0) + +/* Check whether a thread is safe to be swapped out. */ +#define thread_safetoswapout(td) (TD_IS_SLEEPING(td) || TD_IS_SUSPENDED(td)) + +/* Lock and unlock process arguments. */ +#define PARGS_LOCK(p) mtx_lock(&pargs_ref_lock) +#define PARGS_UNLOCK(p) mtx_unlock(&pargs_ref_lock) + +#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash]) +extern LIST_HEAD(pidhashhead, proc) *pidhashtbl; +extern u_long pidhash; + +#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash]) +extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl; +extern u_long pgrphash; + +extern struct sx allproc_lock; +extern struct sx proctree_lock; +extern struct mtx pargs_ref_lock; +extern struct mtx ppeers_lock; +extern struct proc proc0; /* Process slot for swapper. */ +extern struct thread thread0; /* Primary thread in proc0. */ +extern struct ksegrp ksegrp0; /* Primary ksegrp in proc0. */ +extern struct kse kse0; /* Primary kse in proc0. */ +extern struct vmspace vmspace0; /* VM space for proc0. */ +extern int hogticks; /* Limit on kernel cpu hogs. */ +extern int nprocs, maxproc; /* Current and max number of procs. */ +extern int maxprocperuid; /* Max procs per uid. */ +extern u_long ps_arg_cache_limit; +extern int sched_quantum; /* Scheduling quantum in ticks. */ + +LIST_HEAD(proclist, proc); +TAILQ_HEAD(procqueue, proc); +TAILQ_HEAD(threadqueue, thread); +extern struct proclist allproc; /* List of all processes. */ +extern struct proclist zombproc; /* List of zombie processes. */ +extern struct proc *initproc, *pageproc; /* Process slots for init, pager. */ +extern struct proc *updateproc; /* Process slot for syncer (sic). */ + +extern struct uma_zone *proc_zone; + +extern int lastpid; + +struct proc *pfind(pid_t); /* Find process by id. */ +struct pgrp *pgfind(pid_t); /* Find process group by id. */ +struct proc *zpfind(pid_t); /* Find zombie process by id. */ + +void adjustrunqueue(struct thread *, int newpri); +void ast(struct trapframe *framep); +struct thread *choosethread(void); +int cr_cansignal(struct ucred *cred, struct proc *proc, int signum); +int enterpgrp(struct proc *p, pid_t pgid, struct pgrp *pgrp, struct session *sess); +int enterthispgrp(struct proc *p, struct pgrp *pgrp); +void faultin(struct proc *p); +void fixjobc(struct proc *p, struct pgrp *pgrp, int entering); +int fork1(struct thread *, int, int, struct proc **); +void fork_exit(void (*)(void *, struct trapframe *), void *, + struct trapframe *); +void fork_return(struct thread *, struct trapframe *); +int inferior(struct proc *p); +int leavepgrp(struct proc *p); +void mi_switch(int flags); +/* Flags for mi_switch(). */ +#define SW_VOL 0x0001 /* Voluntary switch. */ +#define SW_INVOL 0x0002 /* Involuntary switch. */ +int p_candebug(struct thread *td, struct proc *p); +int p_cansee(struct thread *td, struct proc *p); +int p_cansched(struct thread *td, struct proc *p); +int p_cansignal(struct thread *td, struct proc *p, int signum); +struct pargs *pargs_alloc(int len); +void pargs_drop(struct pargs *pa); +void pargs_free(struct pargs *pa); +void pargs_hold(struct pargs *pa); +void procinit(void); +void threadinit(void); +void proc_linkup(struct proc *p, struct ksegrp *kg, + struct kse *ke, struct thread *td); +void proc_reparent(struct proc *child, struct proc *newparent); +int securelevel_ge(struct ucred *cr, int level); +int securelevel_gt(struct ucred *cr, int level); +void setrunnable(struct thread *); +void setrunqueue(struct thread *); +void setsugid(struct proc *p); +int sigonstack(size_t sp); +void sleepinit(void); +void stopevent(struct proc *, u_int, u_int); +void cpu_idle(void); +extern void (*cpu_idle_hook)(void); /* Hook to machdep CPU idler. */ +void cpu_switch(struct thread *old, struct thread *new); +void cpu_throw(struct thread *old, struct thread *new) __dead2; +void unsleep(struct thread *); +void userret(struct thread *, struct trapframe *, u_int); + +void cpu_exit(struct thread *); +void cpu_sched_exit(struct thread *); +void exit1(struct thread *, int) __dead2; +void cpu_fork(struct thread *, struct proc *, struct thread *, int); +void cpu_set_fork_handler(struct thread *, void (*)(void *), void *); + +/* New in KSE. */ +struct ksegrp *ksegrp_alloc(void); +void ksegrp_free(struct ksegrp *kg); +void ksegrp_stash(struct ksegrp *kg); +struct kse *kse_alloc(void); +void kse_free(struct kse *ke); +void kse_stash(struct kse *ke); +void cpu_set_upcall(struct thread *td, struct thread *td0); +void cpu_set_upcall_kse(struct thread *td, struct kse_upcall *ku); +void cpu_thread_clean(struct thread *); +void cpu_thread_exit(struct thread *); +void cpu_thread_setup(struct thread *td); +void cpu_thread_siginfo(int sig, u_long code, siginfo_t *si); +void cpu_thread_swapin(struct thread *); +void cpu_thread_swapout(struct thread *); +void kse_reassign(struct kse *ke); +void kse_link(struct kse *ke, struct ksegrp *kg); +void kse_unlink(struct kse *ke); +void ksegrp_link(struct ksegrp *kg, struct proc *p); +void ksegrp_unlink(struct ksegrp *kg); +void thread_signal_add(struct thread *td, int sig); +struct thread *thread_alloc(void); +void thread_exit(void) __dead2; +int thread_export_context(struct thread *td, int willexit); +void thread_free(struct thread *td); +void thread_link(struct thread *td, struct ksegrp *kg); +int thread_new_tid(void); +void thread_reap(void); +struct thread *thread_schedule_upcall(struct thread *td, struct kse_upcall *ku); +int thread_single(int how); +#define SINGLE_NO_EXIT 0 /* values for 'how' */ +#define SINGLE_EXIT 1 +void thread_single_end(void); +void thread_stash(struct thread *td); +int thread_suspend_check(int how); +void thread_suspend_one(struct thread *td); +void thread_unlink(struct thread *td); +void thread_unsuspend(struct proc *p); +void thread_unsuspend_one(struct thread *td); +int thread_userret(struct thread *td, struct trapframe *frame); +int thread_upcall_check(struct thread *td); +void thread_user_enter(struct proc *p, struct thread *td); +void thread_wait(struct proc *p); +int thread_statclock(int user); +struct kse_upcall *upcall_alloc(void); +void upcall_free(struct kse_upcall *ku); +void upcall_link(struct kse_upcall *ku, struct ksegrp *kg); +void upcall_unlink(struct kse_upcall *ku); +void upcall_remove(struct thread *td); +void upcall_stash(struct kse_upcall *ke); +void thread_sanity_check(struct thread *td, char *); +void thread_stopped(struct proc *p); +void thread_switchout(struct thread *td); +void thr_exit1(void); +#endif /* _KERNEL */ + +#endif /* !_SYS_PROC_H_ */ diff --git a/src/include/sys/procfs.h b/src/include/sys/procfs.h new file mode 100644 index 0000000..75f5ac5 --- /dev/null +++ b/src/include/sys/procfs.h @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 1998 John D. Polstra. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/procfs.h,v 1.3 2001/08/16 08:35:51 peter Exp $ + */ + +#ifndef _SYS_PROCFS_H_ +#define _SYS_PROCFS_H_ + +#include +#include + +typedef struct reg gregset_t; +typedef struct fpreg fpregset_t; + +/* + * These structures define an interface between core files and the debugger. + * Never change or delete any elements. If you add elements, add them to + * the end of the structure, and increment the value of its version field. + * This will help to ensure that today's core dump will still be usable + * with next year's debugger. + * + * A lot more things should be added to these structures. At present, + * they contain the absolute bare minimum required to allow GDB to work + * with ELF core dumps. + */ + +/* + * The parenthsized numbers like (1) indicate the minimum version number + * for which each element exists in the structure. + */ + +#define PRSTATUS_VERSION 1 /* Current version of prstatus_t */ + +typedef struct prstatus { + int pr_version; /* Version number of struct (1) */ + size_t pr_statussz; /* sizeof(prstatus_t) (1) */ + size_t pr_gregsetsz; /* sizeof(gregset_t) (1) */ + size_t pr_fpregsetsz; /* sizeof(fpregset_t) (1) */ + int pr_osreldate; /* Kernel version (1) */ + int pr_cursig; /* Current signal (1) */ + pid_t pr_pid; /* Process ID (1) */ + gregset_t pr_reg; /* General purpose registers (1) */ +} prstatus_t; + +typedef fpregset_t prfpregset_t; + +#define PRFNAMESZ 16 /* Maximum command length saved */ +#define PRARGSZ 80 /* Maximum argument bytes saved */ + +#define PRPSINFO_VERSION 1 /* Current version of prpsinfo_t */ + +typedef struct prpsinfo { + int pr_version; /* Version number of struct (1) */ + size_t pr_psinfosz; /* sizeof(prpsinfo_t) (1) */ + char pr_fname[PRFNAMESZ+1]; /* Command name, null terminated (1) */ + char pr_psargs[PRARGSZ+1]; /* Arguments, null terminated (1) */ +} prpsinfo_t; + +#endif /* _SYS_PROCFS_H_ */ diff --git a/src/include/sys/protosw.h b/src/include/sys/protosw.h new file mode 100644 index 0000000..9f41fd0 --- /dev/null +++ b/src/include/sys/protosw.h @@ -0,0 +1,324 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)protosw.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/protosw.h,v 1.43 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_PROTOSW_H_ +#define _SYS_PROTOSW_H_ + +/* Forward declare these structures referenced from prototypes below. */ +struct mbuf; +struct thread; +struct sockaddr; +struct socket; +struct sockopt; + +/*#ifdef _KERNEL*/ +/* + * Protocol switch table. + * + * Each protocol has a handle initializing one of these structures, + * which is used for protocol-protocol and system-protocol communication. + * + * A protocol is called through the pr_init entry before any other. + * Thereafter it is called every 200ms through the pr_fasttimo entry and + * every 500ms through the pr_slowtimo for timer based actions. + * The system will call the pr_drain entry if it is low on space and + * this should throw away any non-critical data. + * + * Protocols pass data between themselves as chains of mbufs using + * the pr_input and pr_output hooks. Pr_input passes data up (towards + * the users) and pr_output passes it down (towards the interfaces); control + * information passes up and down on pr_ctlinput and pr_ctloutput. + * The protocol is responsible for the space occupied by any the + * arguments to these entries and must dispose it. + * + * In retrospect, it would be a lot nicer to use an interface + * similar to the vnode VOP interface. + */ +/* USE THESE FOR YOUR PROTOTYPES ! */ +typedef void pr_input_t (struct mbuf *, int); +typedef int pr_input6_t (struct mbuf **, int*, int); /* XXX FIX THIS */ +typedef void pr_in_input_t (struct mbuf *, int, int); /* XXX FIX THIS */ +typedef int pr_output_t (struct mbuf *, struct socket *); +typedef int pr_in_output_t (struct mbuf *, struct socket *, struct sockaddr *); +typedef void pr_ctlinput_t (int, struct sockaddr *, void *); +typedef int pr_ctloutput_t (struct socket *, struct sockopt *); +typedef void pr_init_t (void); +typedef void pr_fasttimo_t (void); +typedef void pr_slowtimo_t (void); +typedef void pr_drain_t (void); + +typedef int pr_usrreq_t(struct socket *, int, struct mbuf *, + struct mbuf *, struct mbuf *, struct thread *); + +struct protosw { + short pr_type; /* socket type used for */ + struct domain *pr_domain; /* domain protocol a member of */ + short pr_protocol; /* protocol number */ + short pr_flags; /* see below */ +/* protocol-protocol hooks */ + pr_input_t *pr_input; /* input to protocol (from below) */ + pr_output_t *pr_output; /* output to protocol (from above) */ + pr_ctlinput_t *pr_ctlinput; /* control input (from below) */ + pr_ctloutput_t *pr_ctloutput; /* control output (from above) */ +/* user-protocol hook */ + pr_usrreq_t *pr_ousrreq; +/* utility hooks */ + pr_init_t *pr_init; + pr_fasttimo_t *pr_fasttimo; /* fast timeout (200ms) */ + pr_slowtimo_t *pr_slowtimo; /* slow timeout (500ms) */ + pr_drain_t *pr_drain; /* flush any excess space possible */ + + struct pr_usrreqs *pr_usrreqs; /* supersedes pr_usrreq() */ +}; +/*#endif*/ + +#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ +#define PR_FASTHZ 5 /* 5 fast timeouts per second */ + +/* + * Values for pr_flags. + * PR_ADDR requires PR_ATOMIC; + * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. + * PR_IMPLOPCL means that the protocol allows sendto without prior connect, + * and the protocol understands the MSG_EOF flag. The first property is + * is only relevant if PR_CONNREQUIRED is set (otherwise sendto is allowed + * anyhow). + */ +#define PR_ATOMIC 0x01 /* exchange atomic messages only */ +#define PR_ADDR 0x02 /* addresses given with messages */ +#define PR_CONNREQUIRED 0x04 /* connection required by protocol */ +#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */ +#define PR_RIGHTS 0x10 /* passes capabilities */ +#define PR_IMPLOPCL 0x20 /* implied open/close */ +#define PR_LASTHDR 0x40 /* enforce ipsec policy; last header */ + +/* + * The arguments to usrreq are: + * (*protosw[].pr_usrreq)(up, req, m, nam, opt); + * where up is a (struct socket *), req is one of these requests, + * m is an optional mbuf chain containing a message, + * nam is an optional mbuf chain containing an address, + * and opt is a pointer to a socketopt structure or nil. + * The protocol is responsible for disposal of the mbuf chain m, + * the caller is responsible for any space held by nam and opt. + * A non-zero return from usrreq gives an + * UNIX error number which should be passed to higher level software. + */ +#define PRU_ATTACH 0 /* attach protocol to up */ +#define PRU_DETACH 1 /* detach protocol from up */ +#define PRU_BIND 2 /* bind socket to address */ +#define PRU_LISTEN 3 /* listen for connection */ +#define PRU_CONNECT 4 /* establish connection to peer */ +#define PRU_ACCEPT 5 /* accept connection from peer */ +#define PRU_DISCONNECT 6 /* disconnect from peer */ +#define PRU_SHUTDOWN 7 /* won't send any more data */ +#define PRU_RCVD 8 /* have taken data; more room now */ +#define PRU_SEND 9 /* send this data */ +#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */ +#define PRU_CONTROL 11 /* control operations on protocol */ +#define PRU_SENSE 12 /* return status into m */ +#define PRU_RCVOOB 13 /* retrieve out of band data */ +#define PRU_SENDOOB 14 /* send out of band data */ +#define PRU_SOCKADDR 15 /* fetch socket's address */ +#define PRU_PEERADDR 16 /* fetch peer's address */ +#define PRU_CONNECT2 17 /* connect two sockets */ +/* begin for protocols internal use */ +#define PRU_FASTTIMO 18 /* 200ms timeout */ +#define PRU_SLOWTIMO 19 /* 500ms timeout */ +#define PRU_PROTORCV 20 /* receive from below */ +#define PRU_PROTOSEND 21 /* send to below */ +/* end for protocol's internal use */ +#define PRU_SEND_EOF 22 /* send and close */ +#define PRU_NREQ 22 + +#ifdef PRUREQUESTS +const char *prurequests[] = { + "ATTACH", "DETACH", "BIND", "LISTEN", + "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", + "RCVD", "SEND", "ABORT", "CONTROL", + "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", + "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", + "PROTORCV", "PROTOSEND", + "SEND_EOF", +}; +#endif + +#ifdef _KERNEL /* users shouldn't see this decl */ + +struct ifnet; +struct stat; +struct ucred; +struct uio; + +/* + * If the ordering here looks odd, that's because it's alphabetical. + * Having this structure separated out from the main protoswitch is allegedly + * a big (12 cycles per call) lose on high-end CPUs. We will eventually + * migrate this stuff back into the main structure. + */ +struct pr_usrreqs { + int (*pru_abort)(struct socket *so); + int (*pru_accept)(struct socket *so, struct sockaddr **nam); + int (*pru_attach)(struct socket *so, int proto, struct thread *td); + int (*pru_bind)(struct socket *so, struct sockaddr *nam, + struct thread *td); + int (*pru_connect)(struct socket *so, struct sockaddr *nam, + struct thread *td); + int (*pru_connect2)(struct socket *so1, struct socket *so2); + int (*pru_control)(struct socket *so, u_long cmd, caddr_t data, + struct ifnet *ifp, struct thread *td); + int (*pru_detach)(struct socket *so); + int (*pru_disconnect)(struct socket *so); + int (*pru_listen)(struct socket *so, struct thread *td); + int (*pru_peeraddr)(struct socket *so, struct sockaddr **nam); + int (*pru_rcvd)(struct socket *so, int flags); + int (*pru_rcvoob)(struct socket *so, struct mbuf *m, int flags); + int (*pru_send)(struct socket *so, int flags, struct mbuf *m, + struct sockaddr *addr, struct mbuf *control, + struct thread *td); +#define PRUS_OOB 0x1 +#define PRUS_EOF 0x2 +#define PRUS_MORETOCOME 0x4 + int (*pru_sense)(struct socket *so, struct stat *sb); + int (*pru_shutdown)(struct socket *so); + int (*pru_sockaddr)(struct socket *so, struct sockaddr **nam); + + /* + * These three added later, so they are out of order. They are used + * for shortcutting (fast path input/output) in some protocols. + * XXX - that's a lie, they are not implemented yet + * Rather than calling sosend() etc. directly, calls are made + * through these entry points. For protocols which still use + * the generic code, these just point to those routines. + */ + int (*pru_sosend)(struct socket *so, struct sockaddr *addr, + struct uio *uio, struct mbuf *top, struct mbuf *control, + int flags, struct thread *td); + int (*pru_soreceive)(struct socket *so, struct sockaddr **paddr, + struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, + int *flagsp); + int (*pru_sopoll)(struct socket *so, int events, + struct ucred *cred, struct thread *td); + void (*pru_sosetlabel)(struct socket *so); +}; + +int pru_accept_notsupp(struct socket *so, struct sockaddr **nam); +int pru_connect_notsupp(struct socket *so, struct sockaddr *nam, + struct thread *td); +int pru_connect2_notsupp(struct socket *so1, struct socket *so2); +int pru_control_notsupp(struct socket *so, u_long cmd, caddr_t data, + struct ifnet *ifp, struct thread *td); +int pru_listen_notsupp(struct socket *so, struct thread *td); +int pru_rcvd_notsupp(struct socket *so, int flags); +int pru_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags); +int pru_sense_null(struct socket *so, struct stat *sb); +void pru_sosetlabel_null(struct socket *so); + +#endif /* _KERNEL */ + +/* + * The arguments to the ctlinput routine are + * (*protosw[].pr_ctlinput)(cmd, sa, arg); + * where cmd is one of the commands below, sa is a pointer to a sockaddr, + * and arg is a `void *' argument used within a protocol family. + */ +#define PRC_IFDOWN 0 /* interface transition */ +#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ +#define PRC_IFUP 2 /* interface has come back up */ +#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ +#define PRC_QUENCH 4 /* some one said to slow down */ +#define PRC_MSGSIZE 5 /* message size forced drop */ +#define PRC_HOSTDEAD 6 /* host appears to be down */ +#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ +#define PRC_UNREACH_NET 8 /* no route to network */ +#define PRC_UNREACH_HOST 9 /* no route to host */ +#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ +#define PRC_UNREACH_PORT 11 /* bad port # */ +/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ +#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ +#define PRC_REDIRECT_NET 14 /* net routing redirect */ +#define PRC_REDIRECT_HOST 15 /* host routing redirect */ +#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ +#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ +#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ +#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ +#define PRC_PARAMPROB 20 /* header incorrect */ +#define PRC_UNREACH_ADMIN_PROHIB 21 /* packet administrativly prohibited */ + +#define PRC_NCMDS 22 + +#define PRC_IS_REDIRECT(cmd) \ + ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) + +#ifdef PRCREQUESTS +char *prcrequests[] = { + "IFDOWN", "ROUTEDEAD", "IFUP", "DEC-BIT-QUENCH2", + "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", + "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", + "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", + "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", + "PARAMPROB", "ADMIN-UNREACH" +}; +#endif + +/* + * The arguments to ctloutput are: + * (*protosw[].pr_ctloutput)(req, so, level, optname, optval, p); + * req is one of the actions listed below, so is a (struct socket *), + * level is an indication of which protocol layer the option is intended. + * optname is a protocol dependent socket option request, + * optval is a pointer to a mbuf-chain pointer, for value-return results. + * The protocol is responsible for disposal of the mbuf chain *optval + * if supplied, + * the caller is responsible for any space held by *optval, when returned. + * A non-zero return from usrreq gives an + * UNIX error number which should be passed to higher level software. + */ +#define PRCO_GETOPT 0 +#define PRCO_SETOPT 1 + +#define PRCO_NCMDS 2 + +#ifdef PRCOREQUESTS +char *prcorequests[] = { + "GETOPT", "SETOPT", +}; +#endif + +#ifdef _KERNEL +void pfctlinput(int, struct sockaddr *); +void pfctlinput2(int, struct sockaddr *, void *); +struct protosw *pffindproto(int family, int protocol, int type); +struct protosw *pffindtype(int family, int type); +#endif + +#endif diff --git a/src/include/sys/ptio.h b/src/include/sys/ptio.h new file mode 100644 index 0000000..f1d60e1 --- /dev/null +++ b/src/include/sys/ptio.h @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 1999 Kenneth D. Merry. + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/ptio.h,v 1.3 1999/08/28 00:51:57 peter Exp $ + */ + +#ifndef _SYS_PTIO_H_ +#define _SYS_PTIO_H_ + +#include + +#define PTIOCGETTIMEOUT _IOR('T', 1, int) +#define PTIOCSETTIMEOUT _IOW('T', 2, int) + +#endif /* !_SYS_PTIO_H_ */ diff --git a/src/include/sys/ptrace.h b/src/include/sys/ptrace.h new file mode 100644 index 0000000..7a90a61 --- /dev/null +++ b/src/include/sys/ptrace.h @@ -0,0 +1,129 @@ +/*- + * Copyright (c) 1984, 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. + * 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. + * + * @(#)ptrace.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/sys/ptrace.h,v 1.22 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_PTRACE_H_ +#define _SYS_PTRACE_H_ + +#define PT_TRACE_ME 0 /* child declares it's being traced */ +#define PT_READ_I 1 /* read word in child's I space */ +#define PT_READ_D 2 /* read word in child's D space */ +/* was PT_READ_U 3 * read word in child's user structure */ +#define PT_WRITE_I 4 /* write word in child's I space */ +#define PT_WRITE_D 5 /* write word in child's D space */ +/* was PT_WRITE_U 6 * write word in child's user structure */ +#define PT_CONTINUE 7 /* continue the child */ +#define PT_KILL 8 /* kill the child process */ +#define PT_STEP 9 /* single step the child */ + +#define PT_ATTACH 10 /* trace some running process */ +#define PT_DETACH 11 /* stop tracing a process */ +#define PT_IO 12 /* do I/O to/from stopped process. */ + +#define PT_TO_SCE 20 +#define PT_TO_SCX 21 +#define PT_SYSCALL 22 + +#define PT_GETREGS 33 /* get general-purpose registers */ +#define PT_SETREGS 34 /* set general-purpose registers */ +#define PT_GETFPREGS 35 /* get floating-point registers */ +#define PT_SETFPREGS 36 /* set floating-point registers */ +#define PT_GETDBREGS 37 /* get debugging registers */ +#define PT_SETDBREGS 38 /* set debugging registers */ + +#define PT_FIRSTMACH 64 /* for machine-specific requests */ +#include /* machine-specific requests, if any */ + +struct ptrace_io_desc { + int piod_op; /* I/O operation */ + void *piod_offs; /* child offset */ + void *piod_addr; /* parent offset */ + size_t piod_len; /* request length */ +}; + +/* + * Operations in piod_op. + */ +#define PIOD_READ_D 1 /* Read from D space */ +#define PIOD_WRITE_D 2 /* Write to D space */ +#define PIOD_READ_I 3 /* Read from I space */ +#define PIOD_WRITE_I 4 /* Write to I space */ + +#ifdef _KERNEL + +#define PTRACESTOP_SC(p, td, flag) \ + if ((p)->p_flag & P_TRACED && (p)->p_stops & (flag)) { \ + PROC_LOCK(p); \ + ptracestop((td), SIGTRAP); \ + } +/* + * The flags below are used for ptrace(2) tracing and have no relation + * to procfs. They are stored in struct proc's p_stops member. + */ +#define S_PT_SCE 0x000010000 +#define S_PT_SCX 0x000020000 + +int ptrace_set_pc(struct thread *_td, unsigned long _addr); +int ptrace_single_step(struct thread *_td); + +#ifdef __HAVE_PTRACE_MACHDEP +int cpu_ptrace(struct thread *_td, int _req, void *_addr, int _data); +#endif + +/* + * These are prototypes for functions that implement some of the + * debugging functionality exported by procfs / linprocfs and by the + * ptrace(2) syscall. They used to be part of procfs, but they don't + * really belong there. + */ +struct reg; +struct fpreg; +struct dbreg; +struct uio; +int proc_read_regs(struct thread *_td, struct reg *_reg); +int proc_write_regs(struct thread *_td, struct reg *_reg); +int proc_read_fpregs(struct thread *_td, struct fpreg *_fpreg); +int proc_write_fpregs(struct thread *_td, struct fpreg *_fpreg); +int proc_read_dbregs(struct thread *_td, struct dbreg *_dbreg); +int proc_write_dbregs(struct thread *_td, struct dbreg *_dbreg); +int proc_sstep(struct thread *_td); +int proc_rwmem(struct proc *_p, struct uio *_uio); +#else /* !_KERNEL */ + +#include + +__BEGIN_DECLS +int ptrace(int _request, pid_t _pid, caddr_t _addr, int _data); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_PTRACE_H_ */ diff --git a/src/include/sys/queue.h b/src/include/sys/queue.h new file mode 100644 index 0000000..e31b26c --- /dev/null +++ b/src/include/sys/queue.h @@ -0,0 +1,553 @@ +/* + * Copyright (c) 1991, 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. + * 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. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + * $FreeBSD: src/sys/sys/queue.h,v 1.58 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +#include + +/* + * This file defines four types of data structures: singly-linked lists, + * singly-linked tail queues, lists and tail queues. + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A singly-linked tail queue is headed by a pair of pointers, one to the + * head of the list and the other to the tail of the list. The elements are + * singly linked for minimum space and pointer manipulation overhead at the + * expense of O(n) removal for arbitrary elements. New elements can be added + * to the list after an existing element, at the head of the list, or at the + * end of the list. Elements being removed from the head of the tail queue + * should use the explicit macro for this purpose for optimum efficiency. + * A singly-linked tail queue may only be traversed in the forward direction. + * Singly-linked tail queues are ideal for applications with large datasets + * and few or no removals or for implementing a FIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * For details on the use of these macros, see the queue(3) manual page. + * + * + * SLIST LIST STAILQ TAILQ + * _HEAD + + + + + * _HEAD_INITIALIZER + + + + + * _ENTRY + + + + + * _INIT + + + + + * _EMPTY + + + + + * _FIRST + + + + + * _NEXT + + + + + * _PREV - - - + + * _LAST - - + + + * _FOREACH + + + + + * _FOREACH_SAFE + + + + + * _FOREACH_REVERSE - - - + + * _FOREACH_REVERSE_SAFE - - - + + * _INSERT_HEAD + + + + + * _INSERT_BEFORE - + - + + * _INSERT_AFTER + + + + + * _INSERT_TAIL - - + + + * _CONCAT - - + + + * _REMOVE_HEAD + - + - + * _REMOVE + + + + + * + */ +#define QUEUE_MACRO_DEBUG 0 +#if QUEUE_MACRO_DEBUG +/* Store the last 2 places the queue element or head was altered */ +struct qm_trace { + char * lastfile; + int lastline; + char * prevfile; + int prevline; +}; + +#define TRACEBUF struct qm_trace trace; +#define TRASHIT(x) do {(x) = (void *)-1;} while (0) + +#define QMD_TRACE_HEAD(head) do { \ + (head)->trace.prevline = (head)->trace.lastline; \ + (head)->trace.prevfile = (head)->trace.lastfile; \ + (head)->trace.lastline = __LINE__; \ + (head)->trace.lastfile = __FILE__; \ +} while (0) + +#define QMD_TRACE_ELEM(elem) do { \ + (elem)->trace.prevline = (elem)->trace.lastline; \ + (elem)->trace.prevfile = (elem)->trace.lastfile; \ + (elem)->trace.lastline = __LINE__; \ + (elem)->trace.lastfile = __FILE__; \ +} while (0) + +#else +#define QMD_TRACE_ELEM(elem) +#define QMD_TRACE_HEAD(head) +#define TRACEBUF +#define TRASHIT(x) +#endif /* QUEUE_MACRO_DEBUG */ + +/* + * Singly-linked List declarations. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) + +#define SLIST_FIRST(head) ((head)->slh_first) + +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST((head)); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ + for ((varp) = &SLIST_FIRST((head)); \ + ((var) = *(varp)) != NULL; \ + (varp) = &SLIST_NEXT((var), field)) + +#define SLIST_INIT(head) do { \ + SLIST_FIRST((head)) = NULL; \ +} while (0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ + SLIST_NEXT((slistelm), field) = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ + SLIST_FIRST((head)) = (elm); \ +} while (0) + +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if (SLIST_FIRST((head)) == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = SLIST_FIRST((head)); \ + while (SLIST_NEXT(curelm, field) != (elm)) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_NEXT(curelm, field) = \ + SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ + } \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = STAILQ_FIRST((head)); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((tqelm), field) = (elm); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? \ + NULL : \ + ((struct type *) \ + ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = STAILQ_FIRST((head)); \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + if ((STAILQ_NEXT(curelm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ + } \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ + if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +/* + * List declarations. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#define LIST_EMPTY(head) ((head)->lh_first == NULL) + +#define LIST_FIRST(head) ((head)->lh_first) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = LIST_FIRST((head)); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define LIST_INIT(head) do { \ + LIST_FIRST((head)) = NULL; \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ + LIST_NEXT((listelm), field)->field.le_prev = \ + &LIST_NEXT((elm), field); \ + LIST_NEXT((listelm), field) = (elm); \ + (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + LIST_NEXT((elm), field) = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ + LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ + LIST_FIRST((head)) = (elm); \ + (elm)->field.le_prev = &LIST_FIRST((head)); \ +} while (0) + +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_REMOVE(elm, field) do { \ + if (LIST_NEXT((elm), field) != NULL) \ + LIST_NEXT((elm), field)->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = LIST_NEXT((elm), field); \ +} while (0) + +/* + * Tail queue declarations. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ +} + +/* + * Tail queue functions. + */ +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_HEAD(head2); \ + } \ +} while (0) + +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST((head)); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + +#define TAILQ_INIT(head) do { \ + TAILQ_FIRST((head)) = NULL; \ + (head)->tqh_last = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else { \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + } \ + TAILQ_NEXT((listelm), field) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&listelm->field); \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + TAILQ_NEXT((elm), field) = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&listelm->field); \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ + TAILQ_FIRST((head))->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + TAILQ_FIRST((head)) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + TAILQ_NEXT((elm), field) = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if ((TAILQ_NEXT((elm), field)) != NULL) \ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else { \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + QMD_TRACE_HEAD(head); \ + } \ + *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ + TRASHIT((elm)->field.tqe_next); \ + TRASHIT((elm)->field.tqe_prev); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + + +#ifdef _KERNEL + +/* + * XXX insque() and remque() are an old way of handling certain queues. + * They bogusly assumes that all queue heads look alike. + */ + +struct quehead { + struct quehead *qh_link; + struct quehead *qh_rlink; +}; + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +static __inline void +insque(void *a, void *b) +{ + struct quehead *element = (struct quehead *)a, + *head = (struct quehead *)b; + + element->qh_link = head->qh_link; + element->qh_rlink = head; + head->qh_link = element; + element->qh_link->qh_rlink = element; +} + +static __inline void +remque(void *a) +{ + struct quehead *element = (struct quehead *)a; + + element->qh_link->qh_rlink = element->qh_rlink; + element->qh_rlink->qh_link = element->qh_link; + element->qh_rlink = 0; +} + +#else /* !(__GNUC__ || __INTEL_COMPILER) */ + +void insque(void *a, void *b); +void remque(void *a); + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +#endif /* _KERNEL */ + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/src/include/sys/random.h b/src/include/sys/random.h new file mode 100644 index 0000000..99559cd --- /dev/null +++ b/src/include/sys/random.h @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2000 Mark R. V. Murray + * 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 + * in this position and unchanged. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/random.h,v 1.33 2002/10/04 20:34:08 sam Exp $ + */ + +#ifndef _SYS_RANDOM_H_ +#define _SYS_RANDOM_H_ + +#ifdef _KERNEL + +int read_random(void *, int); + +enum esource { + RANDOM_START = 0, + RANDOM_WRITE = 0, + RANDOM_KEYBOARD, + RANDOM_MOUSE, + RANDOM_NET, + RANDOM_INTERRUPT, + RANDOM_PURE, + ENTROPYSOURCE +}; +void random_harvest(void *, u_int, u_int, u_int, enum esource); + +/* Allow the sysadmin to select the broad category of + * entropy types to harvest + */ +struct harvest_select { + int ethernet; + int point_to_point; + int interrupt; + int swi; +}; + +extern struct harvest_select harvest; + +#endif /* _KERNEL */ + +#endif /* _SYS_RANDOM_H_ */ diff --git a/src/include/sys/reboot.h b/src/include/sys/reboot.h new file mode 100644 index 0000000..5c77ff7 --- /dev/null +++ b/src/include/sys/reboot.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1982, 1986, 1988, 1993, 1994 + * 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. + * 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. + * + * @(#)reboot.h 8.3 (Berkeley) 12/13/94 + * $FreeBSD: src/sys/sys/reboot.h,v 1.24 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_REBOOT_H_ +#define _SYS_REBOOT_H_ + +/* + * Arguments to reboot system call. These are passed to + * the boot program and on to init. + */ +#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */ + +#define RB_ASKNAME 0x001 /* ask for file name to reboot from */ +#define RB_SINGLE 0x002 /* reboot to single user only */ +#define RB_NOSYNC 0x004 /* dont sync before reboot */ +#define RB_HALT 0x008 /* don't reboot, just halt */ +#define RB_INITNAME 0x010 /* name given for /etc/init (unused) */ +#define RB_DFLTROOT 0x020 /* use compiled-in rootdev */ +#define RB_KDB 0x040 /* give control to kernel debugger */ +#define RB_RDONLY 0x080 /* mount root fs read-only */ +#define RB_DUMP 0x100 /* dump kernel memory before reboot */ +#define RB_MINIROOT 0x200 /* mini-root present in memory at boot time */ +#define RB_CONFIG 0x400 /* invoke user configuration routing */ +#define RB_VERBOSE 0x800 /* print all potentially useful info */ +#define RB_SERIAL 0x1000 /* use serial port as console */ +#define RB_CDROM 0x2000 /* use cdrom as root */ +#define RB_POWEROFF 0x4000 /* turn the power off if possible */ +#define RB_GDB 0x8000 /* use GDB remote debugger instead of DDB */ +#define RB_MUTE 0x10000 /* start up with the console muted */ +#define RB_SELFTEST 0x20000 /* don't complete the boot; do selftest */ +#define RB_RESERVED1 0x40000 /* reserved for internal use of boot blocks */ +#define RB_RESERVED2 0x80000 /* reserved for internal use of boot blocks */ +#define RB_PAUSE 0x100000 /* pause after each output line during probe */ +#define RB_MULTIPLE 0x20000000 /* use multiple consoles */ + +#define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */ + +#endif diff --git a/src/include/sys/regression.h b/src/include/sys/regression.h new file mode 100644 index 0000000..0ce5be6 --- /dev/null +++ b/src/include/sys/regression.h @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2001 Robert N. M. Watson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/regression.h,v 1.3 2004/05/10 18:38:07 rwatson Exp $ + */ +#ifndef _SYS_REGRESSION_H_ +#define _SYS_REGRESSION_H_ + +#ifndef _KERNEL +/* + * System calls associated with regression testing functions in kernel. + */ +int __setugid(int _flag); +#endif /* !_KERNEL */ + +#endif /* !_SYS_REGRESSION_H_ */ diff --git a/src/include/sys/resource.h b/src/include/sys/resource.h new file mode 100644 index 0000000..d08f9bd --- /dev/null +++ b/src/include/sys/resource.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)resource.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/resource.h,v 1.22 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_RESOURCE_H_ +#define _SYS_RESOURCE_H_ + +/* + * Process priority specifications to get/setpriority. + */ +#define PRIO_MIN -20 +#define PRIO_MAX 20 + +#define PRIO_PROCESS 0 +#define PRIO_PGRP 1 +#define PRIO_USER 2 + +/* + * Resource utilization information. + */ + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 + +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ + long ru_maxrss; /* max resident set size */ +#define ru_first ru_ixrss + long ru_ixrss; /* integral shared memory size */ + long ru_idrss; /* integral unshared data " */ + long ru_isrss; /* integral unshared stack " */ + long ru_minflt; /* page reclaims */ + long ru_majflt; /* page faults */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* messages sent */ + long ru_msgrcv; /* messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary " */ +#define ru_last ru_nivcsw +}; + +/* + * Resource limits + */ +#define RLIMIT_CPU 0 /* cpu time in milliseconds */ +#define RLIMIT_FSIZE 1 /* maximum file size */ +#define RLIMIT_DATA 2 /* data size */ +#define RLIMIT_STACK 3 /* stack size */ +#define RLIMIT_CORE 4 /* core file size */ +#define RLIMIT_RSS 5 /* resident set size */ +#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */ +#define RLIMIT_NPROC 7 /* number of processes */ +#define RLIMIT_NOFILE 8 /* number of open files */ +#define RLIMIT_SBSIZE 9 /* maximum size of all socket buffers */ +#define RLIMIT_VMEM 10 /* virtual process size (inclusive of mmap) */ + +#define RLIM_NLIMITS 11 /* number of resource limits */ + +#define RLIM_INFINITY ((rlim_t)(((u_quad_t)1 << 63) - 1)) + + +/* + * Resource limit string identifiers + */ + +#ifdef _RLIMIT_IDENT +static char *rlimit_ident[] = { + "cpu", + "fsize", + "data", + "stack", + "core", + "rss", + "memlock", + "nproc", + "nofile", + "sbsize", + "vmem", +}; +#endif + +struct orlimit { + int32_t rlim_cur; /* current (soft) limit */ + int32_t rlim_max; /* maximum value for rlim_cur */ +}; + +struct rlimit { + rlim_t rlim_cur; /* current (soft) limit */ + rlim_t rlim_max; /* maximum value for rlim_cur */ +}; + +/* Load average structure. */ +struct loadavg { + fixpt_t ldavg[3]; + long fscale; +}; + +#define CP_USER 0 +#define CP_NICE 1 +#define CP_SYS 2 +#define CP_INTR 3 +#define CP_IDLE 4 +#define CPUSTATES 5 + +#ifdef _KERNEL +extern struct loadavg averunnable; +extern long cp_time[CPUSTATES]; + +int kern_setrlimit(struct thread *, u_int, struct rlimit *); + +#else +#include + +__BEGIN_DECLS +int getpriority(int, int); +int getrlimit(int, struct rlimit *); +int getrusage(int, struct rusage *); +int setpriority(int, int, int); +int setrlimit(int, const struct rlimit *); +__END_DECLS + +#endif /* _KERNEL */ +#endif /* !_SYS_RESOURCE_H_ */ diff --git a/src/include/sys/resourcevar.h b/src/include/sys/resourcevar.h new file mode 100644 index 0000000..41639a7 --- /dev/null +++ b/src/include/sys/resourcevar.h @@ -0,0 +1,128 @@ +/* + * Copyright (c) 1991, 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. + * 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. + * + * @(#)resourcevar.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/resourcevar.h,v 1.41 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_RESOURCEVAR_H_ +#define _SYS_RESOURCEVAR_H_ + +#include +#include +#ifdef _KERNEL +#include +#include +#endif + +/* + * Kernel per-process accounting / statistics + * (not necessarily resident except when running). + */ +struct pstats { +#define pstat_startzero p_ru + struct rusage p_ru; /* stats for this proc */ + struct rusage p_cru; /* sum of stats for reaped children */ + struct itimerval p_timer[3]; /* virtual-time timers */ +#define pstat_endzero pstat_startcopy + +#define pstat_startcopy p_prof + struct uprof { /* profile arguments */ + caddr_t pr_base; /* buffer base */ + u_long pr_size; /* buffer size */ + u_long pr_off; /* pc offset */ + u_long pr_scale; /* pc scaling */ + u_long pr_addr; /* temp storage for addr until AST */ + u_int pr_ticks; /* temp storage for ticks until AST */ + } p_prof; +#define pstat_endcopy p_start + struct timeval p_start; /* starting time */ +}; + +#ifdef _KERNEL + +/* + * Kernel shareable process resource limits. Because this structure + * is moderately large but changes infrequently, it is normally + * shared copy-on-write after forks. + */ +struct plimit { + struct rlimit pl_rlimit[RLIM_NLIMITS]; + int pl_refcnt; /* number of references */ + struct mtx *pl_mtx; +}; + +#define LIM_LOCK(lim) mtx_lock((lim)->pl_mtx) +#define LIM_UNLOCK(lim) mtx_unlock((lim)->pl_mtx) +#define LIM_LOCK_ASSERT(lim, f) mtx_assert((lim)->pl_mtx, (f)) + +/* + * Per uid resource consumption + */ +struct uidinfo { + LIST_ENTRY(uidinfo) ui_hash; + rlim_t ui_sbsize; /* socket buffer space consumed */ + long ui_proccnt; /* number of processes */ + uid_t ui_uid; /* uid */ + u_int ui_ref; /* reference count */ + struct mtx *ui_mtxp; /* protect all counts/limits */ +}; + +#define UIDINFO_LOCK(ui) mtx_lock((ui)->ui_mtxp) +#define UIDINFO_UNLOCK(ui) mtx_unlock((ui)->ui_mtxp) + +struct proc; +struct thread; + +void addupc_intr(struct thread *td, uintptr_t pc, u_int ticks); +void addupc_task(struct thread *td, uintptr_t pc, u_int ticks); +void calcru(struct proc *p, struct timeval *up, struct timeval *sp, + struct timeval *ip); +int chgproccnt(struct uidinfo *uip, int diff, int max); +int chgsbsize(struct uidinfo *uip, u_int *hiwat, u_int to, + rlim_t max); +int fuswintr(void *base); +struct plimit + *lim_alloc(void); +void lim_copy(struct plimit *dst, struct plimit *src); +rlim_t lim_cur(struct proc *p, int which); +void lim_free(struct plimit *limp); +struct plimit + *lim_hold(struct plimit *limp); +rlim_t lim_max(struct proc *p, int which); +void lim_rlimit(struct proc *p, int which, struct rlimit *rlp); +void ruadd(struct rusage *ru, struct rusage *ru2); +int suswintr(void *base, int word); +struct uidinfo + *uifind(uid_t uid); +void uifree(struct uidinfo *uip); +void uihashinit(void); +void uihold(struct uidinfo *uip); + +#endif /* _KERNEL */ +#endif /* !_SYS_RESOURCEVAR_H_ */ diff --git a/src/include/sys/rman.h b/src/include/sys/rman.h new file mode 100644 index 0000000..1214db7 --- /dev/null +++ b/src/include/sys/rman.h @@ -0,0 +1,152 @@ +/* + * Copyright 1998 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + * + * $FreeBSD: src/sys/sys/rman.h,v 1.19 2003/02/12 07:00:59 imp Exp $ + */ + +#ifndef _SYS_RMAN_H_ +#define _SYS_RMAN_H_ 1 + +#ifndef _KERNEL +#include +#endif + +#define RF_ALLOCATED 0x0001 /* resource has been reserved */ +#define RF_ACTIVE 0x0002 /* resource allocation has been activated */ +#define RF_SHAREABLE 0x0004 /* resource permits contemporaneous sharing */ +#define RF_TIMESHARE 0x0008 /* resource permits time-division sharing */ +#define RF_WANTED 0x0010 /* somebody is waiting for this resource */ +#define RF_FIRSTSHARE 0x0020 /* first in sharing list */ +#define RF_PREFETCHABLE 0x0040 /* resource is prefetchable */ + +#define RF_ALIGNMENT_SHIFT 10 /* alignment size bit starts bit 10 */ +#define RF_ALIGNMENT_MASK (0x003F << RF_ALIGNMENT_SHIFT) + /* resource address alignemnt size bit mask */ +#define RF_ALIGNMENT_LOG2(x) ((x) << RF_ALIGNMENT_SHIFT) +#define RF_ALIGNMENT(x) (((x) & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT) + +enum rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY }; + +/* + * String length exported to userspace for resource names, etc. + */ +#define RM_TEXTLEN 32 + +/* + * Userspace-exported structures. + */ +struct u_resource { + uintptr_t r_handle; /* resource uniquifier */ + uintptr_t r_parent; /* parent rman */ + uintptr_t r_device; /* device owning this resource */ + char r_devname[RM_TEXTLEN]; /* device name XXX obsolete */ + + u_long r_start; /* offset in resource space */ + u_long r_size; /* size in resource space */ + u_int r_flags; /* RF_* flags */ +}; + +struct u_rman { + uintptr_t rm_handle; /* rman uniquifier */ + char rm_descr[RM_TEXTLEN]; /* rman description */ + + u_long rm_start; /* base of managed region */ + u_long rm_size; /* size of managed region */ + enum rman_type rm_type; /* region type */ +}; + +#ifdef _KERNEL +/* + * We use a linked list rather than a bitmap because we need to be able to + * represent potentially huge objects (like all of a processor's physical + * address space). That is also why the indices are defined to have type + * `unsigned long' -- that being the largest integral type in ISO C (1990). + * The 1999 version of C allows `long long'; we may need to switch to that + * at some point in the future, particularly if we want to support 36-bit + * addresses on IA32 hardware. + */ +TAILQ_HEAD(resource_head, resource); +struct resource { + TAILQ_ENTRY(resource) r_link; + LIST_ENTRY(resource) r_sharelink; + LIST_HEAD(, resource) *r_sharehead; + u_long r_start; /* index of the first entry in this resource */ + u_long r_end; /* index of the last entry (inclusive) */ + u_int r_flags; + void *r_virtual; /* virtual address of this resource */ + bus_space_tag_t r_bustag; /* bus_space tag */ + bus_space_handle_t r_bushandle; /* bus_space handle */ + struct device *r_dev; /* device which has allocated this resource */ + struct rman *r_rm; /* resource manager from whence this came */ + int r_rid; /* optional rid for this resource. */ +}; + +struct rman { + struct resource_head rm_list; + struct mtx *rm_mtx; /* mutex used to protect rm_list */ + TAILQ_ENTRY(rman) rm_link; /* link in list of all rmans */ + u_long rm_start; /* index of globally first entry */ + u_long rm_end; /* index of globally last entry */ + enum rman_type rm_type; /* what type of resource this is */ + const char *rm_descr; /* text descripion of this resource */ +}; +TAILQ_HEAD(rman_head, rman); + +int rman_activate_resource(struct resource *r); +int rman_await_resource(struct resource *r, int pri, int timo); +int rman_deactivate_resource(struct resource *r); +int rman_fini(struct rman *rm); +int rman_init(struct rman *rm); +int rman_manage_region(struct rman *rm, u_long start, u_long end); +int rman_release_resource(struct resource *r); +struct resource *rman_reserve_resource(struct rman *rm, u_long start, + u_long end, u_long count, + u_int flags, struct device *dev); +struct resource *rman_reserve_resource_bound(struct rman *rm, u_long start, + u_long end, u_long count, u_long bound, + u_int flags, struct device *dev); +uint32_t rman_make_alignment_flags(uint32_t size); + +u_long rman_get_start(struct resource *_r); +u_long rman_get_end(struct resource *_r); +struct device *rman_get_device(struct resource *); +u_long rman_get_size(struct resource *_r); +u_int rman_get_flags(struct resource *_r); +void rman_set_virtual(struct resource *_r, void *_v); +void *rman_get_virtual(struct resource *_r); +void rman_set_bustag(struct resource *_r, bus_space_tag_t _t); +bus_space_tag_t rman_get_bustag(struct resource *_r); +void rman_set_bushandle(struct resource *_r, bus_space_handle_t _h); +bus_space_handle_t rman_get_bushandle(struct resource *_r); +void rman_set_rid(struct resource *_r, int _rid); +int rman_get_rid(struct resource *_r); + +extern struct rman_head rman_head; +#endif /* _KERNEL */ + +#endif /* !_SYS_RMAN_H_ */ diff --git a/src/include/sys/rtprio.h b/src/include/sys/rtprio.h new file mode 100644 index 0000000..b8aaa81 --- /dev/null +++ b/src/include/sys/rtprio.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 1994, Henrik Vestergaard Draboel + * 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 (name). + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/rtprio.h,v 1.13 2002/03/19 20:18:41 alfred Exp $ + */ + +#ifndef _SYS_RTPRIO_H_ +#define _SYS_RTPRIO_H_ + +#include + +/* + * Process realtime-priority specifications to rtprio. + */ + +/* priority types. Start at 1 to catch uninitialized fields. */ + +#define RTP_PRIO_REALTIME PRI_REALTIME /* real time process */ +#define RTP_PRIO_NORMAL PRI_TIMESHARE /* time sharing process */ +#define RTP_PRIO_IDLE PRI_IDLE /* idle process */ + +/* RTP_PRIO_FIFO is POSIX.1B SCHED_FIFO. + */ + +#define RTP_PRIO_FIFO_BIT PRI_FIFO_BIT +#define RTP_PRIO_FIFO PRI_FIFO +#define RTP_PRIO_BASE(P) PRI_BASE(P) +#define RTP_PRIO_IS_REALTIME(P) PRI_IS_REALTIME(P) +#define RTP_PRIO_NEED_RR(P) PRI_NEED_RR(P) + +/* priority range */ +#define RTP_PRIO_MIN 0 /* Highest priority */ +#define RTP_PRIO_MAX 31 /* Lowest priority */ + +/* + * rtprio() syscall functions + */ +#define RTP_LOOKUP 0 +#define RTP_SET 1 + +#ifndef LOCORE +/* + * Scheduling class information. + */ +struct rtprio { + u_short type; /* scheduling class */ + u_short prio; +}; + +#ifdef _KERNEL +struct ksegrp; +int rtp_to_pri(struct rtprio *, struct ksegrp *); +void pri_to_rtp(struct ksegrp *, struct rtprio *); +#endif +#endif + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +int rtprio(int, pid_t, struct rtprio *); +__END_DECLS +#endif /* !_KERNEL */ +#endif /* !_SYS_RTPRIO_H_ */ diff --git a/src/include/sys/runq.h b/src/include/sys/runq.h new file mode 100644 index 0000000..54379c2 --- /dev/null +++ b/src/include/sys/runq.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2001 Jake Burkholder + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/runq.h,v 1.4 2002/05/25 01:12:23 jake Exp $ + */ + +#ifndef _RUNQ_H_ +#define _RUNQ_H_ + +#include + +struct kse; + +/* + * Run queue parameters. + */ + +#define RQ_NQS (64) /* Number of run queues. */ +#define RQ_PPQ (4) /* Priorities per queue. */ + +/* + * Head of run queues. + */ +TAILQ_HEAD(rqhead, kse); + +/* + * Bit array which maintains the status of a run queue. When a queue is + * non-empty the bit corresponding to the queue number will be set. + */ +struct rqbits { + rqb_word_t rqb_bits[RQB_LEN]; +}; + +/* + * Run queue structure. Contains an array of run queues on which processes + * are placed, and a structure to maintain the status of each queue. + */ +struct runq { + struct rqbits rq_status; + struct rqhead rq_queues[RQ_NQS]; +}; + +void runq_add(struct runq *, struct kse *); +int runq_check(struct runq *); +struct kse *runq_choose(struct runq *); +void runq_init(struct runq *); +void runq_remove(struct runq *, struct kse *); + +#endif diff --git a/src/include/sys/sbuf.h b/src/include/sys/sbuf.h new file mode 100644 index 0000000..c82968d --- /dev/null +++ b/src/include/sys/sbuf.h @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2000 Poul-Henning Kamp and Dag-Erling Co�dan Sm�rgrav + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/sbuf.h,v 1.13 2002/10/04 09:58:13 phk Exp $ + */ + +#ifndef _SYS_SBUF_H_ +#define _SYS_SBUF_H_ + +#include + +/* + * Structure definition + */ +struct sbuf { + char *s_buf; /* storage buffer */ + void *s_unused; /* binary compatibility. */ + int s_size; /* size of storage buffer */ + int s_len; /* current length of string */ +#define SBUF_FIXEDLEN 0x00000000 /* fixed length buffer (default) */ +#define SBUF_AUTOEXTEND 0x00000001 /* automatically extend buffer */ +#define SBUF_USRFLAGMSK 0x0000ffff /* mask of flags the user may specify */ +#define SBUF_DYNAMIC 0x00010000 /* s_buf must be freed */ +#define SBUF_FINISHED 0x00020000 /* set by sbuf_finish() */ +#define SBUF_OVERFLOWED 0x00040000 /* sbuf overflowed */ +#define SBUF_DYNSTRUCT 0x00080000 /* sbuf must be freed */ + int s_flags; /* flags */ +}; + +__BEGIN_DECLS +/* + * API functions + */ +struct sbuf *sbuf_new(struct sbuf *, char *, int, int); +void sbuf_clear(struct sbuf *); +int sbuf_setpos(struct sbuf *, int); +int sbuf_bcat(struct sbuf *, const char *, size_t); +int sbuf_bcpy(struct sbuf *, const char *, size_t); +int sbuf_cat(struct sbuf *, const char *); +int sbuf_cpy(struct sbuf *, const char *); +int sbuf_printf(struct sbuf *, const char *, ...) __printflike(2, 3); +int sbuf_vprintf(struct sbuf *, const char *, __va_list) __printflike(2, 0); +int sbuf_putc(struct sbuf *, int); +int sbuf_trim(struct sbuf *); +int sbuf_overflowed(struct sbuf *); +void sbuf_finish(struct sbuf *); +char *sbuf_data(struct sbuf *); +int sbuf_len(struct sbuf *); +int sbuf_done(struct sbuf *); +void sbuf_delete(struct sbuf *); + +#ifdef _KERNEL +struct uio; +struct sbuf *sbuf_uionew(struct sbuf *, struct uio *, int *); +int sbuf_bcopyin(struct sbuf *, const void *, size_t); +int sbuf_copyin(struct sbuf *, const void *, size_t); +#endif +__END_DECLS + +#endif diff --git a/src/include/sys/sched.h b/src/include/sys/sched.h new file mode 100644 index 0000000..4c1f007 --- /dev/null +++ b/src/include/sys/sched.h @@ -0,0 +1,122 @@ +/*- + * Copyright (c) 2002, Jeffrey Roberson + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/sched.h,v 1.11 2004/02/27 18:52:44 jhb Exp $ + */ + +#ifndef _SYS_SCHED_H_ +#define _SYS_SCHED_H_ + +/* + * General scheduling info. + * + * sched_load: + * Total runnable non-ithread threads in the system. + * + * sched_runnable: + * Runnable threads for this processor. + */ +int sched_load(void); +int sched_rr_interval(void); +int sched_runnable(void); + +/* + * Proc related scheduling hooks. + */ +void sched_exit(struct proc *p, struct proc *child); +void sched_fork(struct proc *p, struct proc *child); + +/* + * KSE Groups contain scheduling priority information. They record the + * behavior of groups of KSEs and threads. + */ +void sched_class(struct ksegrp *kg, int class); +void sched_exit_ksegrp(struct ksegrp *kg, struct ksegrp *child); +void sched_fork_ksegrp(struct ksegrp *kg, struct ksegrp *child); +void sched_nice(struct ksegrp *kg, int nice); + +/* + * Threads are switched in and out, block on resources, have temporary + * priorities inherited from their ksegs, and use up cpu time. + */ +void sched_exit_thread(struct thread *td, struct thread *child); +void sched_fork_thread(struct thread *td, struct thread *child); +fixpt_t sched_pctcpu(struct thread *td); +void sched_prio(struct thread *td, u_char prio); +void sched_sleep(struct thread *td); +void sched_switch(struct thread *td); +void sched_userret(struct thread *td); +void sched_wakeup(struct thread *td); + +/* + * Threads are moved on and off of run queues + */ +void sched_add(struct thread *td); +struct kse *sched_choose(void); /* XXX Should be thread * */ +void sched_clock(struct thread *td); +void sched_rem(struct thread *td); + +/* + * Binding makes cpu affinity permanent while pinning is used to temporarily + * hold a thread on a particular CPU. + */ +void sched_bind(struct thread *td, int cpu); +static __inline void sched_pin(void); +void sched_unbind(struct thread *td); +static __inline void sched_unpin(void); + +/* + * These interfaces will eventually be removed. + */ +void sched_exit_kse(struct kse *ke, struct kse *child); +void sched_fork_kse(struct kse *ke, struct kse *child); + +/* + * These procedures tell the process data structure allocation code how + * many bytes to actually allocate. + */ +int sched_sizeof_kse(void); +int sched_sizeof_ksegrp(void); +int sched_sizeof_proc(void); +int sched_sizeof_thread(void); + +extern struct ke_sched *kse0_sched; +extern struct kg_sched *ksegrp0_sched; +extern struct p_sched *proc0_sched; +extern struct td_sched *thread0_sched; + +static __inline void +sched_pin(void) +{ + curthread->td_pinned++; +} + +static __inline void +sched_unpin(void) +{ + curthread->td_pinned--; +} + +#endif /* !_SYS_SCHED_H_ */ diff --git a/src/include/sys/select.h b/src/include/sys/select.h new file mode 100644 index 0000000..9bfb494 --- /dev/null +++ b/src/include/sys/select.h @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 1992, 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. + * 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. + * + * $FreeBSD: src/sys/sys/select.h,v 1.19 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SELECT_H_ +#define _SYS_SELECT_H_ + +#include +#include + +#include +#include +#include + +typedef unsigned long __fd_mask; +#if __BSD_VISIBLE +typedef __fd_mask fd_mask; +#endif + +#ifndef _SIGSET_T_DECLARED +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; +#endif + +/* + * Select uses bit masks of file descriptors in longs. These macros + * manipulate such bit fields (the filesystem macros use chars). + * FD_SETSIZE may be defined by the user, but the default here should + * be enough for most uses. + */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 1024U +#endif + +#define _NFDBITS (sizeof(__fd_mask) * 8) /* bits per mask */ +#if __BSD_VISIBLE +#define NFDBITS _NFDBITS +#endif + +#ifndef _howmany +#define _howmany(x, y) (((x) + ((y) - 1)) / (y)) +#endif + +typedef struct fd_set { + __fd_mask __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)]; +} fd_set; +#if __BSD_VISIBLE +#define fds_bits __fds_bits +#endif + +#define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS)) +#define FD_CLR(n, p) ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n)) +#if __BSD_VISIBLE +#define FD_COPY(f, t) (void)(*(t) = *(f)) +#endif +#define FD_ISSET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) +#define FD_SET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n)) +#define FD_ZERO(p) do { \ + fd_set *_p; \ + __size_t _n; \ + \ + _p = (p); \ + _n = _howmany(FD_SETSIZE, _NFDBITS); \ + while (_n > 0) \ + _p->__fds_bits[--_n] = 0; \ +} while (0) + +#ifndef _KERNEL + +__BEGIN_DECLS +int pselect(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, + const struct timespec *__restrict, const sigset_t *__restrict); +#ifndef _SELECT_DECLARED +#define _SELECT_DECLARED +/* XXX missing restrict type-qualifier */ +int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +#endif +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* _SYS_SELECT_H_ */ diff --git a/src/include/sys/selinfo.h b/src/include/sys/selinfo.h new file mode 100644 index 0000000..c96a6c9 --- /dev/null +++ b/src/include/sys/selinfo.h @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1992, 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. + * 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. + * + * @(#)select.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/sys/selinfo.h,v 1.17 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SELINFO_H_ +#define _SYS_SELINFO_H_ + +#include /* for struct klist */ + +/* + * Used to maintain information about processes that wish to be + * notified when I/O becomes possible. + */ +struct selinfo { + TAILQ_ENTRY(selinfo) si_thrlist; /* list hung off of thread */ + struct thread *si_thread; /* thread waiting */ + struct klist si_note; /* kernel note list */ + short si_flags; /* see below */ +}; +#define SI_COLL 0x0001 /* collision occurred */ + +#define SEL_WAITING(si) \ + ((si)->si_thread != NULL || ((si)->si_flags & SI_COLL) != 0) + +#ifdef _KERNEL +void clear_selinfo_list(struct thread *td); +void selrecord(struct thread *selector, struct selinfo *sip); +void selwakeup(struct selinfo *sip); +void selwakeuppri(struct selinfo *sip, int pri); +#endif + +#endif /* !_SYS_SELINFO_H_ */ diff --git a/src/include/sys/sem.h b/src/include/sys/sem.h new file mode 100644 index 0000000..9ed20b8 --- /dev/null +++ b/src/include/sys/sem.h @@ -0,0 +1,119 @@ +/* $FreeBSD: src/sys/sys/sem.h,v 1.27 2003/06/02 17:23:37 schweikh Exp $ */ +/* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ + +/* + * SVID compatible sem.h file + * + * Author: Daniel Boulet + */ + +#ifndef _SYS_SEM_H_ +#define _SYS_SEM_H_ + +#include + +struct sem; + +struct semid_ds { + struct ipc_perm sem_perm; /* operation permission struct */ + struct sem *sem_base; /* pointer to first semaphore in set */ + unsigned short sem_nsems; /* number of sems in set */ + time_t sem_otime; /* last operation time */ + long sem_pad1; /* SVABI/386 says I need this here */ + time_t sem_ctime; /* last change time */ + /* Times measured in secs since */ + /* 00:00:00 GMT, Jan. 1, 1970 */ + long sem_pad2; /* SVABI/386 says I need this here */ + long sem_pad3[4]; /* SVABI/386 says I need this here */ +}; + +/* + * semop's sops parameter structure + */ +struct sembuf { + unsigned short sem_num; /* semaphore # */ + short sem_op; /* semaphore operation */ + short sem_flg; /* operation flags */ +}; +#define SEM_UNDO 010000 + +/* + * semctl's arg parameter structure + */ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + unsigned short *array; /* array for GETALL & SETALL */ +}; + +/* + * commands for semctl + */ +#define GETNCNT 3 /* Return the value of semncnt {READ} */ +#define GETPID 4 /* Return the value of sempid {READ} */ +#define GETVAL 5 /* Return the value of semval {READ} */ +#define GETALL 6 /* Return semvals into arg.array {READ} */ +#define GETZCNT 7 /* Return the value of semzcnt {READ} */ +#define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ +#define SETALL 9 /* Set semvals from arg.array {ALTER} */ +#define SEM_STAT 10 /* Like IPC_STAT but treats semid as sema-index */ +#define SEM_INFO 11 /* Like IPC_INFO but treats semid as sema-index */ + +/* + * Permissions + */ +#define SEM_A IPC_W /* alter permission */ +#define SEM_R IPC_R /* read permission */ + +#ifdef _KERNEL + +/* + * semaphore info struct + */ +struct seminfo { + int semmap, /* # of entries in semaphore map */ + semmni, /* # of semaphore identifiers */ + semmns, /* # of semaphores in system */ + semmnu, /* # of undo structures in system */ + semmsl, /* max # of semaphores per id */ + semopm, /* max # of operations per semop call */ + semume, /* max # of undo entries per process */ + semusz, /* size in bytes of undo structure */ + semvmx, /* semaphore maximum value */ + semaem; /* adjust on exit max value */ +}; +extern struct seminfo seminfo; + +/* internal "mode" bits */ +#define SEM_ALLOC 01000 /* semaphore is allocated */ +#define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ + +/* + * Process sem_undo vectors at proc exit. + */ +void semexit(struct proc *p); +#endif /* _KERNEL */ + +#ifndef _KERNEL +#include +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +__BEGIN_DECLS +int semsys(int, ...); +int semctl(int, int, int, ...); +int semget(key_t, int, int); +int semop(int, struct sembuf *, size_t); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_SEM_H_ */ diff --git a/src/include/sys/sema.h b/src/include/sys/sema.h new file mode 100644 index 0000000..949fab7 --- /dev/null +++ b/src/include/sys/sema.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2001 Jason Evans . 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD: src/sys/sys/sema.h,v 1.3 2001/10/10 10:26:07 bde Exp $ + */ + +#ifndef _SYS_SEMA_H_ +#define _SYS_SEMA_H_ + +#include +#include +#include +#include + +struct sema { + struct mtx sema_mtx; /* General protection lock. */ + struct cv sema_cv; /* Waiters. */ + int sema_waiters; /* Number of waiters. */ + int sema_value; /* Semaphore value. */ +}; + +#ifdef _KERNEL +void sema_init(struct sema *sema, int value, const char *description); +void sema_destroy(struct sema *sema); +void _sema_post(struct sema *sema, const char *file, int line); +void _sema_wait(struct sema *sema, const char *file, int line); +int _sema_timedwait(struct sema *sema, int timo, const char *file, int + line); +int _sema_trywait(struct sema *sema, const char *file, int line); +int sema_value(struct sema *sema); + +#define sema_post(sema) _sema_post((sema), LOCK_FILE, LOCK_LINE) +#define sema_wait(sema) _sema_wait((sema), LOCK_FILE, LOCK_LINE) +#define sema_timedwait(sema, timo) \ + _sema_timedwait((sema), (timo), LOCK_FILE, LOCK_LINE) +#define sema_trywait(sema) _sema_trywait((sema), LOCK_FILE, LOCK_LINE) + +#endif /* _KERNEL */ +#endif /* _SYS_SEMA_H_ */ diff --git a/src/include/sys/sf_buf.h b/src/include/sys/sf_buf.h new file mode 100644 index 0000000..c283285 --- /dev/null +++ b/src/include/sys/sf_buf.h @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2003 Alan L. Cox + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/sf_buf.h,v 1.4 2004/04/03 09:16:27 alc Exp $ + */ + +#ifndef _SYS_SF_BUF_H_ +#define _SYS_SF_BUF_H_ + +#include + +struct vm_page; + +extern int nsfbufs; /* Number of sendfile(2) bufs alloced */ +extern int nsfbufspeak; /* Peak of nsfbufsused */ +extern int nsfbufsused; /* Number of sendfile(2) bufs in use */ + +struct sf_buf * + sf_buf_alloc(struct vm_page *m, int pri); +void sf_buf_free(struct sf_buf *sf); +void sf_buf_mext(void *addr, void *args); + +#endif /* !_SYS_SF_BUF_H_ */ diff --git a/src/include/sys/shm.h b/src/include/sys/shm.h new file mode 100644 index 0000000..8422bc3 --- /dev/null +++ b/src/include/sys/shm.h @@ -0,0 +1,123 @@ +/* $FreeBSD: src/sys/sys/shm.h,v 1.19 2003/01/25 21:33:05 alfred Exp $ */ +/* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ + +/* + * Copyright (c) 1994 Adam Glass + * 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 Adam Glass. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +/* + * As defined+described in "X/Open System Interfaces and Headers" + * Issue 4, p. XXX + */ + +#ifndef _SYS_SHM_H_ +#define _SYS_SHM_H_ + +#include + +#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ +#define SHM_RND 020000 /* Round attach address to SHMLBA */ +#define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ + +/* "official" access mode definitions; somewhat braindead since you have + to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ +#define SHM_R (IPC_R) +#define SHM_W (IPC_W) + +/* predefine tbd *LOCK shmctl commands */ +#define SHM_LOCK 11 +#define SHM_UNLOCK 12 + +/* ipcs shmctl commands */ +#define SHM_STAT 13 +#define SHM_INFO 14 + +struct shmid_ds { + struct ipc_perm shm_perm; /* operation permission structure */ + int shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shared memory op */ + pid_t shm_cpid; /* process ID of creator */ + short shm_nattch; /* number of current attaches */ + time_t shm_atime; /* time of last shmat() */ + time_t shm_dtime; /* time of last shmdt() */ + time_t shm_ctime; /* time of last change by shmctl() */ + void *shm_internal; /* sysv stupidity */ +}; + +#ifdef _KERNEL + +/* + * System 5 style catch-all structure for shared memory constants that + * might be of interest to user programs. Do we really want/need this? + */ +struct shminfo { + int shmmax, /* max shared memory segment size (bytes) */ + shmmin, /* min shared memory segment size (bytes) */ + shmmni, /* max number of shared memory identifiers */ + shmseg, /* max shared memory segments per process */ + shmall; /* max amount of shared memory (pages) */ +}; +extern struct shminfo shminfo; +extern struct shmid_ds *shmsegs; + +struct shm_info { + int used_ids; + unsigned long shm_tot; + unsigned long shm_rss; + unsigned long shm_swp; + unsigned long swap_attempts; + unsigned long swap_successes; +}; + +struct thread; +struct proc; +struct vmspace; + +void shmexit(struct vmspace *); +void shmfork(struct proc *, struct proc *); +#else /* !_KERNEL */ + +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +__BEGIN_DECLS +int shmsys(int, ...); +void *shmat(int, const void *, int); +int shmget(key_t, size_t, int); +int shmctl(int, int, struct shmid_ds *); +int shmdt(const void *); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_SHM_H_ */ diff --git a/src/include/sys/sigio.h b/src/include/sys/sigio.h new file mode 100644 index 0000000..cc2934f --- /dev/null +++ b/src/include/sys/sigio.h @@ -0,0 +1,67 @@ +/* + * 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. + * 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. + * + * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/sigio.h,v 1.2 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SIGIO_H_ +#define _SYS_SIGIO_H_ + +/* + * This structure holds the information needed to send a SIGIO or + * a SIGURG signal to a process or process group when new data arrives + * on a device or socket. The structure is placed on an SLIST belonging + * to the proc or pgrp so that the entire list may be revoked when the + * process exits or the process group disappears. + * + * (c) const + * (pg) locked by either the process or process group lock + */ +struct sigio { + union { + struct proc *siu_proc; /* (c) process to receive SIGIO/SIGURG */ + struct pgrp *siu_pgrp; /* (c) process group to receive ... */ + } sio_u; + SLIST_ENTRY(sigio) sio_pgsigio; /* (pg) sigio's for process or group */ + struct sigio **sio_myref; /* (c) location of the pointer that holds + * the reference to this structure */ + struct ucred *sio_ucred; /* (c) current credentials */ + pid_t sio_pgid; /* (c) pgid for signals */ +}; +#define sio_proc sio_u.siu_proc +#define sio_pgrp sio_u.siu_pgrp + +SLIST_HEAD(sigiolst, sigio); + +pid_t fgetown(struct sigio **sigiop); +int fsetown(pid_t pgid, struct sigio **sigiop); +void funsetown(struct sigio **sigiop); +void funsetownlst(struct sigiolst *sigiolst); + +#endif /* _SYS_SIGIO_H_ */ diff --git a/src/include/sys/signal.h b/src/include/sys/signal.h new file mode 100644 index 0000000..075a716 --- /dev/null +++ b/src/include/sys/signal.h @@ -0,0 +1,354 @@ +/*- + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)signal.h 8.4 (Berkeley) 5/4/95 + * $FreeBSD: src/sys/sys/signal.h,v 1.43 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SIGNAL_H_ +#define _SYS_SIGNAL_H_ + +#include +#include +#include + +#include /* sig_atomic_t; trap codes; sigcontext */ + +/* + * System defined signals. + */ +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGHUP 1 /* hangup */ +#endif +#define SIGINT 2 /* interrupt */ +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGQUIT 3 /* quit */ +#endif +#define SIGILL 4 /* illegal instr. (not reset when caught) */ +#if __XSI_VISIBLE +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#endif +#define SIGABRT 6 /* abort() */ +#if __BSD_VISIBLE +#define SIGIOT SIGABRT /* compatibility */ +#define SIGEMT 7 /* EMT instruction */ +#endif +#define SIGFPE 8 /* floating point exception */ +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#endif +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#define SIGBUS 10 /* bus error */ +#endif +#define SIGSEGV 11 /* segmentation violation */ +#if __BSD_VISIBLE +#define SIGSYS 12 /* non-existent system call invoked */ +#endif +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#endif +#define SIGTERM 15 /* software termination signal from kill */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +#define SIGURG 16 /* urgent condition on IO channel */ +#endif +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGSTOP 17 /* sendable stop signal not from tty */ +#define SIGTSTP 18 /* stop signal from tty */ +#define SIGCONT 19 /* continue a stopped process */ +#define SIGCHLD 20 /* to parent on child stop or exit */ +#define SIGTTIN 21 /* to readers pgrp upon background tty read */ +#define SIGTTOU 22 /* like TTIN if (tp->t_local<OSTOP) */ +#endif +#if __BSD_VISIBLE +#define SIGIO 23 /* input/output possible signal */ +#endif +#if __XSI_VISIBLE +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ +#define SIGPROF 27 /* profiling time alarm */ +#endif +#if __BSD_VISIBLE +#define SIGWINCH 28 /* window size changes */ +#define SIGINFO 29 /* information request */ +#endif +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SIGUSR1 30 /* user defined signal 1 */ +#define SIGUSR2 31 /* user defined signal 2 */ +#endif +#if __BSD_VISIBLE +#define SIGTHR 32 /* Thread interrupt. */ +#endif +/* + * XXX missing SIGRTMIN, SIGRTMAX. + */ + +#define SIG_DFL ((__sighandler_t *)0) +#define SIG_IGN ((__sighandler_t *)1) +#define SIG_ERR ((__sighandler_t *)-1) +/* + * XXX missing SIG_HOLD. + */ + +/*- + * Type of a signal handling function. + * + * Language spec sez signal handlers take exactly one arg, even though we + * actually supply three. Ugh! + * + * We don't try to hide the difference by leaving out the args because + * that would cause warnings about conformant programs. Nonconformant + * programs can avoid the warnings by casting to (__sighandler_t *) or + * sig_t before calling signal() or assigning to sa_handler or sv_handler. + * + * The kernel should reverse the cast before calling the function. It + * has no way to do this, but on most machines 1-arg and 3-arg functions + * have the same calling protocol so there is no problem in practice. + * A bit in sa_flags could be used to specify the number of args. + */ +typedef void __sighandler_t(int); + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#ifndef _SIGSET_T_DECLARED +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; +#endif +#endif + +#if __POSIX_VISIBLE >= 199309 || __XSI_VISIBLE >= 500 +union sigval { + /* Members as suggested by Annex C of POSIX 1003.1b. */ + int sigval_int; + void *sigval_ptr; +}; +#endif + +#if __POSIX_VISIBLE >= 199309 +struct sigevent { + int sigev_notify; /* Notification type */ + union { + int __sigev_signo; /* Signal number */ + int __sigev_notify_kqueue; + } __sigev_u; + union sigval sigev_value; /* Signal value */ +/* + * XXX missing sigev_notify_function, sigev_notify_attributes. + */ +}; +#define sigev_signo __sigev_u.__sigev_signo +#if __BSD_VISIBLE +#define sigev_notify_kqueue __sigev_u.__sigev_notify_kqueue +#endif + +#define SIGEV_NONE 0 /* No async notification */ +#define SIGEV_SIGNAL 1 /* Generate a queued signal */ +#if __BSD_VISIBLE +#define SIGEV_KEVENT 3 /* Generate a kevent */ +#endif +/* + * XXX missing SIGEV_THREAD. + */ +#endif /* __POSIX_VISIBLE >= 199309 */ + +#if __POSIX_VISIBLE >= 199309 || __XSI_VISIBLE +typedef struct __siginfo { + int si_signo; /* signal number */ + int si_errno; /* errno association */ + /* + * Cause of signal, one of the SI_ macros or signal-specific + * values, i.e. one of the FPE_... values for SIGFPE. This + * value is equivalent to the second argument to an old-style + * FreeBSD signal handler. + */ + int si_code; /* signal code */ + __pid_t si_pid; /* sending process */ + __uid_t si_uid; /* sender's ruid */ + int si_status; /* exit value */ + void *si_addr; /* faulting instruction */ + union sigval si_value; /* signal value */ + long si_band; /* band event for SIGPOLL */ + int __spare__[7]; /* gimme some slack */ +} siginfo_t; +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +struct __siginfo; + +/* + * Signal vector "template" used in sigaction call. + */ +struct sigaction { + union { + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, struct __siginfo *, void *); + } __sigaction_u; /* signal handler */ + int sa_flags; /* see signal options below */ + sigset_t sa_mask; /* signal mask to apply */ +}; + +#define sa_handler __sigaction_u.__sa_handler +#endif + +#if __XSI_VISIBLE +/* If SA_SIGINFO is set, sa_sigaction must be used instead of sa_handler. */ +#define sa_sigaction __sigaction_u.__sa_sigaction +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ +#endif /* __POSIX_VISIBLE || __XSI_VISIBLE */ + +#if __XSI_VISIBLE +#define SA_ONSTACK 0x0001 /* take signal on signal stack */ +#define SA_RESTART 0x0002 /* restart system call on signal return */ +#define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */ +#define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ +#define SA_NOCLDWAIT 0x0020 /* don't keep zombies around */ +#define SA_SIGINFO 0x0040 /* signal handler with SA_SIGINFO args */ +#endif +#if __BSD_VISIBLE +/* XXX dubious. */ +#ifdef COMPAT_SUNOS +#define SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp */ +#endif +#endif + +#if __BSD_VISIBLE +#define NSIG 32 /* number of old signals (counting 0) */ +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +#define SI_USER 0x10001 +#define SI_QUEUE 0x10002 +#define SI_TIMER 0x10003 +#define SI_ASYNCIO 0x10004 +#define SI_MESGQ 0x10005 +#endif +#if __BSD_VISIBLE +#define SI_UNDEFINED 0 +#endif + +#if __BSD_VISIBLE +typedef __sighandler_t *sig_t; /* type of pointer to a signal function */ +typedef void __siginfohandler_t(int, struct __siginfo *, void *); +#endif + +#if __XSI_VISIBLE +/* + * Structure used in sigaltstack call. + */ +#if __BSD_VISIBLE +typedef struct sigaltstack { +#else +typedef struct { +#endif + char *ss_sp; /* signal stack base */ + __size_t ss_size; /* signal stack length */ + int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ +} stack_t; + +#define SS_ONSTACK 0x0001 /* take signal on alternate stack */ +#define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */ +#define SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended stack size */ +#endif + +#if __BSD_VISIBLE +/* + * 4.3 compatibility: + * Signal vector "template" used in sigvec call. + */ +struct sigvec { + __sighandler_t *sv_handler; /* signal handler */ + int sv_mask; /* signal mask to apply */ + int sv_flags; /* see signal options below */ +}; + +#define SV_ONSTACK SA_ONSTACK +#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ +#define SV_RESETHAND SA_RESETHAND +#define SV_NODEFER SA_NODEFER +#define SV_NOCLDSTOP SA_NOCLDSTOP +#define SV_SIGINFO SA_SIGINFO +#define sv_onstack sv_flags /* isn't compatibility wonderful! */ +#endif + +/* Keep this in one place only */ +#if defined(_KERNEL) && defined(COMPAT_43) && \ + !defined(__i386__) && !defined(__alpha__) +struct osigcontext { + int _not_used; +}; +#endif + +#if __XSI_VISIBLE +/* + * Structure used in sigstack call. + */ +struct sigstack { + /* XXX ss_sp's type should be `void *'. */ + char *ss_sp; /* signal stack pointer */ + int ss_onstack; /* current status */ +}; +#endif + +#if __BSD_VISIBLE || __POSIX_VISIBLE > 0 && __POSIX_VISIBLE <= 200112 +/* + * Macro for converting signal number to a mask suitable for + * sigblock(). + */ +#define sigmask(m) (1 << ((m)-1)) +#endif + +#if __BSD_VISIBLE +#define BADSIG SIG_ERR +#endif + +#if __POSIX_VISIBLE || __XSI_VISIBLE +/* + * Flags for sigprocmask: + */ +#define SIG_BLOCK 1 /* block specified signal set */ +#define SIG_UNBLOCK 2 /* unblock specified signal set */ +#define SIG_SETMASK 3 /* set specified signal set */ +#endif + +/* + * For historical reasons; programs expect signal's return value to be + * defined by . + */ +__BEGIN_DECLS +__sighandler_t *signal(int, __sighandler_t *); +__END_DECLS + +#endif /* !_SYS_SIGNAL_H_ */ diff --git a/src/include/sys/signalvar.h b/src/include/sys/signalvar.h new file mode 100644 index 0000000..c1fa701 --- /dev/null +++ b/src/include/sys/signalvar.h @@ -0,0 +1,283 @@ +/* + * Copyright (c) 1991, 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. + * 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. + * + * @(#)signalvar.h 8.6 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/signalvar.h,v 1.66 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SIGNALVAR_H_ +#define _SYS_SIGNALVAR_H_ + +#include +#include +#include +#include + +/* + * Kernel signal definitions and data structures, + * not exported to user programs. + */ + +/* + * Logical process signal actions and state, needed only within the process + * The mapping between sigacts and proc structures is 1:1 except for rfork() + * processes masquerading as threads which use one structure for the whole + * group. All members are locked by the included mutex. The reference count + * and mutex must be last for the bcopy in sigacts_copy() to work. + */ +struct sigacts { + sig_t ps_sigact[_SIG_MAXSIG]; /* Disposition of signals. */ + sigset_t ps_catchmask[_SIG_MAXSIG]; /* Signals to be blocked. */ + sigset_t ps_sigonstack; /* Signals to take on sigstack. */ + sigset_t ps_sigintr; /* Signals that interrupt syscalls. */ + sigset_t ps_sigreset; /* Signals that reset when caught. */ + sigset_t ps_signodefer; /* Signals not masked while handled. */ + sigset_t ps_siginfo; /* Signals that want SA_SIGINFO args. */ + sigset_t ps_sigignore; /* Signals being ignored. */ + sigset_t ps_sigcatch; /* Signals being caught by user. */ + sigset_t ps_freebsd4; /* signals using freebsd4 ucontext. */ + sigset_t ps_osigset; /* Signals using <= 3.x osigset_t. */ + sigset_t ps_usertramp; /* SunOS compat; libc sigtramp. XXX */ + int ps_flag; + int ps_refcnt; + struct mtx ps_mtx; +}; + +#define PS_NOCLDWAIT 0x0001 /* No zombies if child dies */ +#define PS_NOCLDSTOP 0x0002 /* No SIGCHLD when children stop. */ +#define PS_CLDSIGIGN 0x0004 /* The SIGCHLD handler is SIG_IGN. */ + +#if defined(_KERNEL) && defined(COMPAT_43) +/* + * Compatibility. + */ +typedef struct { + struct osigcontext si_sc; + int si_signo; + int si_code; + union sigval si_value; +} osiginfo_t; + +struct osigaction { + union { + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, osiginfo_t *, void *); + } __sigaction_u; /* signal handler */ + osigset_t sa_mask; /* signal mask to apply */ + int sa_flags; /* see signal options below */ +}; + +typedef void __osiginfohandler_t(int, osiginfo_t *, void *); +#endif /* _KERNEL && COMPAT_43 */ + +/* additional signal action values, used only temporarily/internally */ +#define SIG_CATCH ((__sighandler_t *)2) +#define SIG_HOLD ((__sighandler_t *)3) + +/* + * get signal action for process and signal; currently only for current process + */ +#define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) + +/* + * sigset_t manipulation macros + */ +#define SIGADDSET(set, signo) \ + ((set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)) + +#define SIGDELSET(set, signo) \ + ((set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)) + +#define SIGEMPTYSET(set) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set).__bits[__i] = 0; \ + } while (0) + +#define SIGFILLSET(set) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set).__bits[__i] = ~0U; \ + } while (0) + +#define SIGISMEMBER(set, signo) \ + ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) + +#define SIGISEMPTY(set) (__sigisempty(&(set))) +#define SIGNOTEMPTY(set) (!__sigisempty(&(set))) + +#define SIGSETEQ(set1, set2) (__sigseteq(&(set1), &(set2))) +#define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2))) + +#define SIGSETOR(set1, set2) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set1).__bits[__i] |= (set2).__bits[__i]; \ + } while (0) + +#define SIGSETAND(set1, set2) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set1).__bits[__i] &= (set2).__bits[__i]; \ + } while (0) + +#define SIGSETNAND(set1, set2) \ + do { \ + int __i; \ + for (__i = 0; __i < _SIG_WORDS; __i++) \ + (set1).__bits[__i] &= ~(set2).__bits[__i]; \ + } while (0) + +#define SIGSETLO(set1, set2) ((set1).__bits[0] = (set2).__bits[0]) +#define SIGSETOLD(set, oset) ((set).__bits[0] = (oset)) + +#define SIG_CANTMASK(set) \ + SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP) + +#define SIG_STOPSIGMASK(set) \ + SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \ + SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU) + +#define SIG_CONTSIGMASK(set) \ + SIGDELSET(set, SIGCONT) + +#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) + +#define SIG2OSIG(sig, osig) (osig = (sig).__bits[0]) +#define OSIG2SIG(osig, sig) SIGEMPTYSET(sig); (sig).__bits[0] = osig + +static __inline int +__sigisempty(sigset_t *set) +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) { + if (set->__bits[i]) + return (0); + } + return (1); +} + +static __inline int +__sigseteq(sigset_t *set1, sigset_t *set2) +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) { + if (set1->__bits[i] != set2->__bits[i]) + return (0); + } + return (1); +} + +#ifdef _KERNEL + +/* + * Specifies the target of a signal. + * P - Doesn't matter which thread it gets delivered to. + * TD - Must be delivered to a specific thread. + */ +typedef enum sigtarget_enum { SIGTARGET_P, SIGTARGET_TD } sigtarget_t; + +/* Return nonzero if process p has an unmasked pending signal. */ +#define SIGPENDING(td) \ + (!SIGISEMPTY((td)->td_siglist) && \ + !sigsetmasked(&(td)->td_siglist, &(td)->td_sigmask)) + +/* + * Return the value of the pseudo-expression ((*set & ~*mask) != 0). This + * is an optimized version of SIGISEMPTY() on a temporary variable + * containing SIGSETNAND(*set, *mask). + */ +static __inline int +sigsetmasked(sigset_t *set, sigset_t *mask) +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) { + if (set->__bits[i] & ~mask->__bits[i]) + return (0); + } + return (1); +} + +struct pgrp; +struct thread; +struct proc; +struct sigio; +struct mtx; + +extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */ +extern struct mtx sigio_lock; + +/* + * Lock the pointers for a sigio object in the underlying objects of + * a file descriptor. + */ +#define SIGIO_LOCK() mtx_lock(&sigio_lock) +#define SIGIO_TRYLOCK() mtx_trylock(&sigio_lock) +#define SIGIO_UNLOCK() mtx_unlock(&sigio_lock) +#define SIGIO_LOCKED() mtx_owned(&sigio_lock) +#define SIGIO_ASSERT(type) mtx_assert(&sigio_lock, type) + +/* + * Machine-independent functions: + */ +int cursig(struct thread *td); +void execsigs(struct proc *p); +void gsignal(int pgid, int sig); +void killproc(struct proc *p, char *why); +void pgsigio(struct sigio **, int signum, int checkctty); +void pgsignal(struct pgrp *pgrp, int sig, int checkctty); +void postsig(int sig); +void psignal(struct proc *p, int sig); +struct sigacts *sigacts_alloc(void); +void sigacts_copy(struct sigacts *dest, struct sigacts *src); +void sigacts_free(struct sigacts *ps); +struct sigacts *sigacts_hold(struct sigacts *ps); +int sigacts_shared(struct sigacts *ps); +void sigexit(struct thread *td, int signum) __dead2; +int sig_ffs(sigset_t *set); +void siginit(struct proc *p); +void signotify(struct thread *td); +void tdsignal(struct thread *td, int sig, sigtarget_t target); +void trapsignal(struct thread *td, int sig, u_long code); +void ptracestop(struct thread *td, int sig); + +/* + * Machine-dependent functions: + */ +void sendsig(sig_t action, int sig, sigset_t *retmask, u_long code); + +#endif /* _KERNEL */ + +#endif /* !_SYS_SIGNALVAR_H_ */ diff --git a/src/include/sys/sleepqueue.h b/src/include/sys/sleepqueue.h new file mode 100644 index 0000000..a567600 --- /dev/null +++ b/src/include/sys/sleepqueue.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2004 John Baldwin + * 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. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/sleepqueue.h,v 1.2 2004/03/12 19:06:18 jhb Exp $ + */ + +#ifndef _SYS_SLEEPQUEUE_H_ +#define _SYS_SLEEPQUEUE_H_ + +/* + * Sleep queue interface. Sleep/wakeup and condition variables use a sleep + * queue for the queue of threads blocked on a sleep channel. + * + * A thread calls sleepq_lookup() to look up the proper sleep queue in the + * hash table that is associated with a specified wait channel. This + * function returns a pointer to the queue and locks the associated sleep + * queue chain. A thread calls sleepq_add() to add themself onto a sleep + * queue and calls one of the sleepq_wait() functions to actually go to + * sleep. If a thread needs to abort a sleep operation it should call + * sleepq_release() to unlock the associated sleep queue chain lock. If + * the thread also needs to remove itself from a queue it just enqueued + * itself on, it can use sleepq_remove(). + * + * If the thread only wishes to sleep for a limited amount of time, it can + * call sleepq_set_timeout() after sleepq_add() to setup a timeout. It + * should then use one of the sleepq_timedwait() functions to block. + * + * If the thread wants to the sleep to be interruptible by signals, it can + * call sleepq_catch_signals() after sleepq_add(). It should then use + * one of the sleepq_wait_sig() functions to block. After the thread has + * been resumed, it should call sleepq_calc_signal_retval() to determine + * if it should return EINTR or ERESTART passing in the value returned from + * the earlier call to sleepq_catch_signals(). + * + * A thread is normally resumed from a sleep queue by either the + * sleepq_signal() or sleepq_broadcast() functions. Sleepq_signal() wakes + * the thread with the highest priority that is sleeping on the specified + * wait channel. Sleepq_broadcast() wakes all threads that are sleeping + * on the specified wait channel. A thread sleeping in an interruptible + * sleep can be interrupted by calling sleepq_abort(). A thread can also + * be removed from a specified sleep queue using the sleepq_remove() + * function. + * + * Each thread allocates a sleep queue at thread creation via sleepq_alloc() + * and releases it at thread destruction via sleepq_free(). Note that + * a sleep queue is not tied to a specific thread and that the sleep queue + * released at thread destruction may not be the same sleep queue that the + * thread allocated when it was created. + * + * XXX: Some other parts of the kernel such as ithread sleeping may end up + * using this interface as well (death to TDI_IWAIT!) + */ + +struct mtx; +struct sleepqueue; +struct thread; + +#ifdef _KERNEL + +#define SLEEPQ_CONDVAR 0x1 /* Sleep queue is a cv. */ + +void init_sleepqueues(void); +void sleepq_abort(struct thread *td); +void sleepq_add(struct sleepqueue *, void *, struct mtx *, const char *, + int); +struct sleepqueue *sleepq_alloc(void); +void sleepq_broadcast(void *, int, int); +int sleepq_calc_signal_retval(int sig); +int sleepq_catch_signals(void *wchan); +void sleepq_free(struct sleepqueue *); +struct sleepqueue *sleepq_lookup(void *); +void sleepq_release(void *); +void sleepq_remove(struct thread *, void *); +void sleepq_signal(void *, int, int); +void sleepq_set_timeout(void *wchan, int timo); +int sleepq_timedwait(void *wchan, int signal_caught); +int sleepq_timedwait_sig(void *wchan, int signal_caught); +void sleepq_wait(void *); +int sleepq_wait_sig(void *wchan); + +#endif /* _KERNEL */ +#endif /* !_SYS_SLEEPQUEUE_H_ */ diff --git a/src/include/sys/smp.h b/src/include/sys/smp.h new file mode 100644 index 0000000..72b2eaf --- /dev/null +++ b/src/include/sys/smp.h @@ -0,0 +1,105 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/sys/smp.h,v 1.77 2004/03/27 18:21:24 marcel Exp $ + */ + +#ifndef _SYS_SMP_H_ +#define _SYS_SMP_H_ + +#ifdef _KERNEL + +#ifndef LOCORE + +#ifdef SMP + +/* + * Topology of a NUMA or HTT system. + * + * The top level topology is an array of pointers to groups. Each group + * contains a bitmask of cpus in its group or subgroups. It may also + * contain a pointer to an array of child groups. + * + * The bitmasks at non leaf groups may be used by consumers who support + * a smaller depth than the hardware provides. + * + * The topology may be omitted by systems where all CPUs are equal. + */ + +struct cpu_group { + cpumask_t cg_mask; /* Mask of cpus in this group. */ + int cg_count; /* Count of cpus in this group. */ + int cg_children; /* Number of children groups. */ + struct cpu_group *cg_child; /* Optional child group. */ +}; + +struct cpu_top { + int ct_count; /* Count of groups. */ + struct cpu_group *ct_group; /* Array of pointers to cpu groups. */ +}; + +extern struct cpu_top *smp_topology; +extern void (*cpustop_restartfunc)(void); +extern int smp_active; +extern int smp_cpus; +extern volatile cpumask_t started_cpus; +extern volatile cpumask_t stopped_cpus; +#endif /* SMP */ + +extern cpumask_t all_cpus; +extern u_int mp_maxid; +extern int mp_ncpus; +extern volatile int smp_started; + +/* + * Macro allowing us to determine whether a CPU is absent at any given + * time, thus permitting us to configure sparse maps of cpuid-dependent + * (per-CPU) structures. + */ +#define CPU_ABSENT(x_cpu) ((all_cpus & (1 << (x_cpu))) == 0) + +#ifdef SMP +/* + * Machine dependent functions used to initialize MP support. + * + * The cpu_mp_probe() should check to see if MP support is present and return + * zero if it is not or non-zero if it is. If MP support is present, then + * cpu_mp_start() will be called so that MP can be enabled. This function + * should do things such as startup secondary processors. It should also + * setup mp_ncpus, all_cpus, and smp_cpus. It should also ensure that + * smp_active and smp_started are initialized at the appropriate time. + * Once cpu_mp_start() returns, machine independent MP startup code will be + * executed and a simple message will be output to the console. Finally, + * cpu_mp_announce() will be called so that machine dependent messages about + * the MP support may be output to the console if desired. + * + * The cpu_setmaxid() function is called very early during the boot process + * so that the MD code may set mp_maxid to provide an upper bound on CPU IDs + * that other subsystems may use. If a platform is not able to determine + * the exact maximum ID that early, then it may set mp_maxid to MAXCPU - 1. + */ +struct thread; + +void cpu_mp_announce(void); +int cpu_mp_probe(void); +void cpu_mp_setmaxid(void); +void cpu_mp_start(void); + +void forward_signal(struct thread *); +void forward_roundrobin(void); +int restart_cpus(cpumask_t); +int stop_cpus(cpumask_t); +void smp_rendezvous_action(void); +#endif /* SMP */ +void smp_rendezvous(void (*)(void *), + void (*)(void *), + void (*)(void *), + void *arg); +#endif /* !LOCORE */ +#endif /* _KERNEL */ +#endif /* _SYS_SMP_H_ */ diff --git a/src/include/sys/snoop.h b/src/include/sys/snoop.h new file mode 100644 index 0000000..bef5646 --- /dev/null +++ b/src/include/sys/snoop.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 1995 Ugen J.S.Antsilevich + * + * Redistribution and use in source forms, with and without modification, + * are permitted provided that this entire comment appears intact. + * + * Redistribution in binary form may occur without any restrictions. + * Obviously, it would be nice if you gave credit where credit is due + * but requiring it would be too onerous. + * + * This software is provided ``AS IS'' without any warranties of any kind. + * + * Snoop stuff. + * + * $FreeBSD: src/sys/sys/snoop.h,v 1.22 2002/11/11 10:45:31 tmm Exp $ + */ + +#ifndef _SYS_SNOOP_H_ +#define _SYS_SNOOP_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * These are snoop io controls + * SNPSTTY accepts 'struct snptty' as input. + * If ever type or unit set to -1,snoop device + * detached from its current tty. + */ + +#define SNPSTTY _IOW('T', 90, udev_t) +#define SNPGTTY _IOR('T', 89, udev_t) + +/* + * These values would be returned by FIONREAD ioctl + * instead of number of characters in buffer in case + * of specific errors. + */ +#define SNP_OFLOW -1 +#define SNP_TTYCLOSE -2 +#define SNP_DETACH -3 + +#endif /* !_SYS_SNOOP_H_ */ diff --git a/src/include/sys/socket.h b/src/include/sys/socket.h new file mode 100644 index 0000000..1a482ba --- /dev/null +++ b/src/include/sys/socket.h @@ -0,0 +1,546 @@ +/* + * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 + * 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. + * 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. + * + * @(#)socket.h 8.4 (Berkeley) 2/21/94 + * $FreeBSD: src/sys/sys/socket.h,v 1.79 2004/05/10 02:24:56 emax Exp $ + */ + +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +#include +#include +#include +#define _NO_NAMESPACE_POLLUTION +#include +#undef _NO_NAMESPACE_POLLUTION + +/* + * Definitions related to sockets: types, address families, options. + */ + +/* + * Data types. + */ +#if __BSD_VISIBLE +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif +#endif + +#ifndef _SA_FAMILY_T_DECLARED +typedef __sa_family_t sa_family_t; +#define _SA_FAMILY_T_DECLARED +#endif + +#ifndef _SOCKLEN_T_DECLARED +typedef __socklen_t socklen_t; +#define _SOCKLEN_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#if __BSD_VISIBLE +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif +#endif + +/* + * Types + */ +#define SOCK_STREAM 1 /* stream socket */ +#define SOCK_DGRAM 2 /* datagram socket */ +#define SOCK_RAW 3 /* raw-protocol interface */ +#if __BSD_VISIBLE +#define SOCK_RDM 4 /* reliably-delivered message */ +#endif +#define SOCK_SEQPACKET 5 /* sequenced packet stream */ + +/* + * Option flags per-socket. + */ +#define SO_DEBUG 0x0001 /* turn on debugging info recording */ +#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ +#define SO_REUSEADDR 0x0004 /* allow local address reuse */ +#define SO_KEEPALIVE 0x0008 /* keep connections alive */ +#define SO_DONTROUTE 0x0010 /* just use interface addresses */ +#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ +#if __BSD_VISIBLE +#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ +#endif +#define SO_LINGER 0x0080 /* linger on close if data present */ +#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ +#if __BSD_VISIBLE +#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ +#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */ +#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */ +#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ +#define SO_BINTIME 0x2000 /* timestamp received dgram traffic */ +#endif + +/* + * Additional options, not kept in so_options. + */ +#define SO_SNDBUF 0x1001 /* send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_SNDLOWAT 0x1003 /* send low-water mark */ +#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ +#define SO_SNDTIMEO 0x1005 /* send timeout */ +#define SO_RCVTIMEO 0x1006 /* receive timeout */ +#define SO_ERROR 0x1007 /* get error status and clear */ +#define SO_TYPE 0x1008 /* get socket type */ +#if __BSD_VISIBLE +#define SO_LABEL 0x1009 /* socket's MAC label */ +#define SO_PEERLABEL 0x1010 /* socket's peer's MAC label */ +#endif + +/* + * Structure used for manipulating linger option. + */ +struct linger { + int l_onoff; /* option on/off */ + int l_linger; /* linger time */ +}; + +#if __BSD_VISIBLE +struct accept_filter_arg { + char af_name[16]; + char af_arg[256-16]; +}; +#endif + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 0xffff /* options for socket level */ + +/* + * Address families. + */ +#define AF_UNSPEC 0 /* unspecified */ +#if __BSD_VISIBLE +#define AF_LOCAL AF_UNIX /* local to host (pipes, portals) */ +#endif +#define AF_UNIX 1 /* standardized name for AF_LOCAL */ +#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ +#if __BSD_VISIBLE +#define AF_IMPLINK 3 /* arpanet imp addresses */ +#define AF_PUP 4 /* pup protocols: e.g. BSP */ +#define AF_CHAOS 5 /* mit CHAOS protocols */ +#define AF_NETBIOS 6 /* SMB protocols */ +#define AF_ISO 7 /* ISO protocols */ +#define AF_OSI AF_ISO +#define AF_ECMA 8 /* European computer manufacturers */ +#define AF_DATAKIT 9 /* datakit protocols */ +#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ +#define AF_SNA 11 /* IBM SNA */ +#define AF_DECnet 12 /* DECnet */ +#define AF_DLI 13 /* DEC Direct data link interface */ +#define AF_LAT 14 /* LAT */ +#define AF_HYLINK 15 /* NSC Hyperchannel */ +#define AF_APPLETALK 16 /* Apple Talk */ +#define AF_ROUTE 17 /* Internal Routing Protocol */ +#define AF_LINK 18 /* Link layer interface */ +#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ +#define AF_COIP 20 /* connection-oriented IP, aka ST II */ +#define AF_CNT 21 /* Computer Network Technology */ +#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ +#define AF_IPX 23 /* Novell Internet Protocol */ +#define AF_SIP 24 /* Simple Internet Protocol */ +#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ +#define AF_ISDN 26 /* Integrated Services Digital Network*/ +#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ +#define pseudo_AF_KEY 27 /* Internal key-management function */ +#endif +#define AF_INET6 28 /* IPv6 */ +#if __BSD_VISIBLE +#define AF_NATM 29 /* native ATM access */ +#define AF_ATM 30 /* ATM */ +#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers + * in interface output routine + */ +#define AF_NETGRAPH 32 /* Netgraph sockets */ +#define AF_SLOW 33 /* 802.3ad slow protocol */ +#define AF_SCLUSTER 34 /* Sitara cluster protocol */ +#define AF_ARP 35 +#define AF_BLUETOOTH 36 /* Bluetooth sockets */ +#define AF_MAX 37 +#endif + +/* + * Structure used by kernel to store most + * addresses. + */ +struct sockaddr { + unsigned char sa_len; /* total length */ + sa_family_t sa_family; /* address family */ + char sa_data[14]; /* actually longer; address value */ +}; +#if __BSD_VISIBLE +#define SOCK_MAXADDRLEN 255 /* longest possible addresses */ + +/* + * Structure used by kernel to pass protocol + * information in raw sockets. + */ +struct sockproto { + unsigned short sp_family; /* address family */ + unsigned short sp_protocol; /* protocol */ +}; +#endif + +/* + * RFC 2553: protocol-independent placeholder for socket addresses + */ +#define _SS_MAXSIZE 128U +#define _SS_ALIGNSIZE (sizeof(__int64_t)) +#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) - \ + sizeof(sa_family_t)) +#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) - \ + sizeof(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE) + +struct sockaddr_storage { + unsigned char ss_len; /* address length */ + sa_family_t ss_family; /* address family */ + char __ss_pad1[_SS_PAD1SIZE]; + __int64_t __ss_align; /* force desired struct alignment */ + char __ss_pad2[_SS_PAD2SIZE]; +}; + +#if __BSD_VISIBLE +/* + * Protocol families, same as address families for now. + */ +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_UNIX PF_LOCAL /* backward compatibility */ +#define PF_INET AF_INET +#define PF_IMPLINK AF_IMPLINK +#define PF_PUP AF_PUP +#define PF_CHAOS AF_CHAOS +#define PF_NETBIOS AF_NETBIOS +#define PF_ISO AF_ISO +#define PF_OSI AF_ISO +#define PF_ECMA AF_ECMA +#define PF_DATAKIT AF_DATAKIT +#define PF_CCITT AF_CCITT +#define PF_SNA AF_SNA +#define PF_DECnet AF_DECnet +#define PF_DLI AF_DLI +#define PF_LAT AF_LAT +#define PF_HYLINK AF_HYLINK +#define PF_APPLETALK AF_APPLETALK +#define PF_ROUTE AF_ROUTE +#define PF_LINK AF_LINK +#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ +#define PF_COIP AF_COIP +#define PF_CNT AF_CNT +#define PF_SIP AF_SIP +#define PF_IPX AF_IPX +#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ +#define PF_PIP pseudo_AF_PIP +#define PF_ISDN AF_ISDN +#define PF_KEY pseudo_AF_KEY +#define PF_INET6 AF_INET6 +#define PF_NATM AF_NATM +#define PF_ATM AF_ATM +#define PF_NETGRAPH AF_NETGRAPH +#define PF_SLOW AF_SLOW +#define PF_SCLUSTER AF_SCLUSTER +#define PF_ARP AF_ARP +#define PF_BLUETOOTH AF_BLUETOOTH + +#define PF_MAX AF_MAX + +/* + * Definitions for network related sysctl, CTL_NET. + * + * Second level is protocol family. + * Third level is protocol number. + * + * Further levels are defined by the individual families below. + */ +#define NET_MAXID AF_MAX + +#define CTL_NET_NAMES { \ + { 0, 0 }, \ + { "unix", CTLTYPE_NODE }, \ + { "inet", CTLTYPE_NODE }, \ + { "implink", CTLTYPE_NODE }, \ + { "pup", CTLTYPE_NODE }, \ + { "chaos", CTLTYPE_NODE }, \ + { "xerox_ns", CTLTYPE_NODE }, \ + { "iso", CTLTYPE_NODE }, \ + { "emca", CTLTYPE_NODE }, \ + { "datakit", CTLTYPE_NODE }, \ + { "ccitt", CTLTYPE_NODE }, \ + { "ibm_sna", CTLTYPE_NODE }, \ + { "decnet", CTLTYPE_NODE }, \ + { "dec_dli", CTLTYPE_NODE }, \ + { "lat", CTLTYPE_NODE }, \ + { "hylink", CTLTYPE_NODE }, \ + { "appletalk", CTLTYPE_NODE }, \ + { "route", CTLTYPE_NODE }, \ + { "link_layer", CTLTYPE_NODE }, \ + { "xtp", CTLTYPE_NODE }, \ + { "coip", CTLTYPE_NODE }, \ + { "cnt", CTLTYPE_NODE }, \ + { "rtip", CTLTYPE_NODE }, \ + { "ipx", CTLTYPE_NODE }, \ + { "sip", CTLTYPE_NODE }, \ + { "pip", CTLTYPE_NODE }, \ + { "isdn", CTLTYPE_NODE }, \ + { "key", CTLTYPE_NODE }, \ + { "inet6", CTLTYPE_NODE }, \ + { "natm", CTLTYPE_NODE }, \ + { "atm", CTLTYPE_NODE }, \ + { "hdrcomplete", CTLTYPE_NODE }, \ + { "netgraph", CTLTYPE_NODE }, \ + { "snp", CTLTYPE_NODE }, \ + { "scp", CTLTYPE_NODE }, \ +} + +/* + * PF_ROUTE - Routing table + * + * Three additional levels are defined: + * Fourth: address family, 0 is wildcard + * Fifth: type of info, defined below + * Sixth: flag(s) to mask with for NET_RT_FLAGS + */ +#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ +#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ +#define NET_RT_IFLIST 3 /* survey interface list */ +#define NET_RT_IFMALIST 4 /* return multicast address list */ +#define NET_RT_MAXID 5 + +#define CTL_NET_RT_NAMES { \ + { 0, 0 }, \ + { "dump", CTLTYPE_STRUCT }, \ + { "flags", CTLTYPE_STRUCT }, \ + { "iflist", CTLTYPE_STRUCT }, \ + { "ifmalist", CTLTYPE_STRUCT }, \ +} +#endif /* __BSD_VISIBLE */ + +/* + * Maximum queue length specifiable by listen. + */ +#define SOMAXCONN 128 + +/* + * Message header for recvmsg and sendmsg calls. + * Used value-result for recvmsg, value only for sendmsg. + */ +struct msghdr { + void *msg_name; /* optional address */ + socklen_t msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + int msg_iovlen; /* # elements in msg_iov */ + void *msg_control; /* ancillary data, see below */ + socklen_t msg_controllen; /* ancillary data buffer len */ + int msg_flags; /* flags on received message */ +}; + +#define MSG_OOB 0x1 /* process out-of-band data */ +#define MSG_PEEK 0x2 /* peek at incoming message */ +#define MSG_DONTROUTE 0x4 /* send without using routing tables */ +#define MSG_EOR 0x8 /* data completes record */ +#define MSG_TRUNC 0x10 /* data discarded before delivery */ +#define MSG_CTRUNC 0x20 /* control data lost before delivery */ +#define MSG_WAITALL 0x40 /* wait for full request or error */ +#if __BSD_VISIBLE +#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ +#define MSG_EOF 0x100 /* data completes connection */ +#define MSG_COMPAT 0x8000 /* used in sendit() */ +#endif + +/* + * Header for ancillary data objects in msg_control buffer. + * Used for additional information with/about a datagram + * not expressible by flags. The format is a sequence + * of message elements headed by cmsghdr structures. + */ +struct cmsghdr { + socklen_t cmsg_len; /* data byte count, including hdr */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +/* followed by u_char cmsg_data[]; */ +}; + +#if __BSD_VISIBLE +/* + * While we may have more groups than this, the cmsgcred struct must + * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow + * this. +*/ +#define CMGROUP_MAX 16 + +/* + * Credentials structure, used to verify the identity of a peer + * process that has sent us a message. This is allocated by the + * peer process but filled in by the kernel. This prevents the + * peer from lying about its identity. (Note that cmcred_groups[0] + * is the effective GID.) + */ +struct cmsgcred { + pid_t cmcred_pid; /* PID of sending process */ + uid_t cmcred_uid; /* real UID of sending process */ + uid_t cmcred_euid; /* effective UID of sending process */ + gid_t cmcred_gid; /* real GID of sending process */ + short cmcred_ngroups; /* number or groups */ + gid_t cmcred_groups[CMGROUP_MAX]; /* groups */ +}; +#endif /* __BSD_VISIBLE */ + +/* given pointer to struct cmsghdr, return pointer to data */ +#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \ + _ALIGN(sizeof(struct cmsghdr))) + +/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ +#define CMSG_NXTHDR(mhdr, cmsg) \ + (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \ + _ALIGN(sizeof(struct cmsghdr)) > \ + (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)NULL : \ + (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len))) + +#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) + +#if __BSD_VISIBLE +/* RFC 2292 additions */ +#define CMSG_SPACE(l) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l)) +#define CMSG_LEN(l) (_ALIGN(sizeof(struct cmsghdr)) + (l)) +#endif + +#ifdef _KERNEL +#define CMSG_ALIGN(n) _ALIGN(n) +#endif + +/* "Socket"-level control message types: */ +#define SCM_RIGHTS 0x01 /* access rights (array of int) */ +#if __BSD_VISIBLE +#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */ +#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */ +#define SCM_BINTIME 0x04 /* timestamp (struct bintime) */ +#endif + +#if __BSD_VISIBLE +/* + * 4.3 compat sockaddr, move to compat file later + */ +struct osockaddr { + unsigned short sa_family; /* address family */ + char sa_data[14]; /* up to 14 bytes of direct address */ +}; + +/* + * 4.3-compat message header (move to compat file later). + */ +struct omsghdr { + char *msg_name; /* optional address */ + int msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + int msg_iovlen; /* # elements in msg_iov */ + char *msg_accrights; /* access rights sent/received */ + int msg_accrightslen; +}; +#endif + +/* + * howto arguments for shutdown(2), specified by Posix.1g. + */ +#define SHUT_RD 0 /* shut down the reading side */ +#define SHUT_WR 1 /* shut down the writing side */ +#define SHUT_RDWR 2 /* shut down both sides */ + +#if __BSD_VISIBLE +/* + * sendfile(2) header/trailer struct + */ +struct sf_hdtr { + struct iovec *headers; /* pointer to an array of header struct iovec's */ + int hdr_cnt; /* number of header iovec's */ + struct iovec *trailers; /* pointer to an array of trailer struct iovec's */ + int trl_cnt; /* number of trailer iovec's */ +}; + +/* + * Sendfile-specific flag(s) + */ +#define SF_NODISKIO 0x00000001 +#endif + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int accept(int, struct sockaddr * __restrict, socklen_t * __restrict); +int bind(int, const struct sockaddr *, socklen_t); +int connect(int, const struct sockaddr *, socklen_t); +int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); +int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict); +int listen(int, int); +ssize_t recv(int, void *, size_t, int); +ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict); +ssize_t recvmsg(int, struct msghdr *, int); +ssize_t send(int, const void *, size_t, int); +ssize_t sendto(int, const void *, + size_t, int, const struct sockaddr *, socklen_t); +ssize_t sendmsg(int, const struct msghdr *, int); +#if __BSD_VISIBLE +int sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int); +#endif +int setsockopt(int, int, int, const void *, socklen_t); +int shutdown(int, int); +int sockatmark(int); +int socket(int, int, int); +int socketpair(int, int, int, int *); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_SOCKET_H_ */ diff --git a/src/include/sys/socketvar.h b/src/include/sys/socketvar.h new file mode 100644 index 0000000..e8fe004 --- /dev/null +++ b/src/include/sys/socketvar.h @@ -0,0 +1,448 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)socketvar.h 8.3 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/socketvar.h,v 1.111 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SOCKETVAR_H_ +#define _SYS_SOCKETVAR_H_ + +#include /* for TAILQ macros */ +#include /* for struct selinfo */ + +/* + * Kernel structure per socket. + * Contains send and receive buffer queues, + * handle on protocol and pointer to protocol + * private data and error information. + */ +typedef u_quad_t so_gen_t; + +/* + * List of locks: + * (c) const, inited in either socreate() or sonewconn() + * (m) sb_mtx mutex + * (mr) so_rcv.sb_mtx mutex + * (sg) sigio_lock sx + * (sh) sohead_lock sx + * + * Lock of so_rcv.sb_mtx can duplicate, provided that sohead_lock + * is exclusively locked. + * + * Brackets mean that this data is not protected yet. + */ +struct socket { + int so_count; /* reference count */ + short so_type; /* generic type, see socket.h */ + short so_options; /* from socket call, see socket.h */ + short so_linger; /* time to linger while closing */ + short so_state; /* internal state flags SS_*, below */ + void *so_pcb; /* protocol control block */ + struct protosw *so_proto; /* protocol handle */ +/* + * Variables for connection queuing. + * Socket where accepts occur is so_head in all subsidiary sockets. + * If so_head is 0, socket is not related to an accept. + * For head socket so_incomp queues partially completed connections, + * while so_comp is a queue of connections ready to be accepted. + * If a connection is aborted and it has so_head set, then + * it has to be pulled out of either so_incomp or so_comp. + * We allow connections to queue up based on current queue lengths + * and limit on number of queued connections for this socket. + */ + struct socket *so_head; /* back pointer to accept socket */ + TAILQ_HEAD(, socket) so_incomp; /* queue of partial unaccepted connections */ + TAILQ_HEAD(, socket) so_comp; /* queue of complete unaccepted connections */ + TAILQ_ENTRY(socket) so_list; /* list of unaccepted connections */ + short so_qlen; /* number of unaccepted connections */ + short so_incqlen; /* number of unaccepted incomplete + connections */ + short so_qlimit; /* max number queued connections */ + short so_timeo; /* connection timeout */ + u_short so_error; /* error affecting connection */ + struct sigio *so_sigio; /* [sg] information for async I/O or + out of band data (SIGURG) */ + u_long so_oobmark; /* chars to oob mark */ + TAILQ_HEAD(, aiocblist) so_aiojobq; /* AIO ops waiting on socket */ +/* + * Variables for socket buffering. + */ + struct sockbuf { + struct selinfo sb_sel; /* process selecting read/write */ +#define sb_startzero sb_mb + struct mbuf *sb_mb; /* the mbuf chain */ + struct mbuf *sb_mbtail; /* the last mbuf in the chain */ + struct mbuf *sb_lastrecord; /* first mbuf of last record in + * socket buffer */ + u_int sb_cc; /* actual chars in buffer */ + u_int sb_hiwat; /* max actual char count */ + u_int sb_mbcnt; /* chars of mbufs used */ + u_int sb_mbmax; /* max chars of mbufs to use */ + u_int sb_ctl; /* non-data chars in buffer */ + int sb_lowat; /* low water mark */ + int sb_timeo; /* timeout for read/write */ + short sb_flags; /* flags, see below */ + } so_rcv, so_snd; +#define SB_MAX (256*1024) /* default for max chars in sockbuf */ +#define SB_LOCK 0x01 /* lock on data queue */ +#define SB_WANT 0x02 /* someone is waiting to lock */ +#define SB_WAIT 0x04 /* someone is waiting for data/space */ +#define SB_SEL 0x08 /* someone is selecting */ +#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */ +#define SB_UPCALL 0x20 /* someone wants an upcall */ +#define SB_NOINTR 0x40 /* operations not interruptible */ +#define SB_AIO 0x80 /* AIO operations queued */ +#define SB_KNOTE 0x100 /* kernel note attached */ + + void (*so_upcall)(struct socket *, void *, int); + void *so_upcallarg; + struct ucred *so_cred; /* user credentials */ + struct label *so_label; /* MAC label for socket */ + struct label *so_peerlabel; /* cached MAC label for socket peer */ + /* NB: generation count must not be first; easiest to make it last. */ + so_gen_t so_gencnt; /* generation count */ + void *so_emuldata; /* private data for emulators */ + struct so_accf { + struct accept_filter *so_accept_filter; + void *so_accept_filter_arg; /* saved filter args */ + char *so_accept_filter_str; /* saved user args */ + } *so_accf; +}; + +#define SB_EMPTY_FIXUP(sb) do { \ + if ((sb)->sb_mb == NULL) { \ + (sb)->sb_mbtail = NULL; \ + (sb)->sb_lastrecord = NULL; \ + } \ +} while (/*CONSTCOND*/0) + +/* + * Socket state bits. + */ +#define SS_NOFDREF 0x0001 /* no file table ref any more */ +#define SS_ISCONNECTED 0x0002 /* socket connected to a peer */ +#define SS_ISCONNECTING 0x0004 /* in process of connecting to peer */ +#define SS_ISDISCONNECTING 0x0008 /* in process of disconnecting */ +#define SS_CANTSENDMORE 0x0010 /* can't send more data to peer */ +#define SS_CANTRCVMORE 0x0020 /* can't receive more data from peer */ +#define SS_RCVATMARK 0x0040 /* at mark on input */ + +#define SS_NBIO 0x0100 /* non-blocking ops */ +#define SS_ASYNC 0x0200 /* async i/o notify */ +#define SS_ISCONFIRMING 0x0400 /* deciding to accept connection req */ + +#define SS_INCOMP 0x0800 /* unaccepted, incomplete connection */ +#define SS_COMP 0x1000 /* unaccepted, complete connection */ +#define SS_ISDISCONNECTED 0x2000 /* socket disconnected from peer */ + +/* + * Externalized form of struct socket used by the sysctl(3) interface. + */ +struct xsocket { + size_t xso_len; /* length of this structure */ + struct socket *xso_so; /* makes a convenient handle sometimes */ + short so_type; + short so_options; + short so_linger; + short so_state; + caddr_t so_pcb; /* another convenient handle */ + int xso_protocol; + int xso_family; + short so_qlen; + short so_incqlen; + short so_qlimit; + short so_timeo; + u_short so_error; + pid_t so_pgid; + u_long so_oobmark; + struct xsockbuf { + u_int sb_cc; + u_int sb_hiwat; + u_int sb_mbcnt; + u_int sb_mbmax; + int sb_lowat; + int sb_timeo; + short sb_flags; + } so_rcv, so_snd; + uid_t so_uid; /* XXX */ +}; + +/* + * Macros for sockets and socket buffering. + */ + +/* + * Do we need to notify the other side when I/O is possible? + */ +#define sb_notify(sb) (((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \ + SB_UPCALL | SB_AIO | SB_KNOTE)) != 0) + +/* + * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? + * This is problematical if the fields are unsigned, as the space might + * still be negative (cc > hiwat or mbcnt > mbmax). Should detect + * overflow and return 0. Should use "lmin" but it doesn't exist now. + */ +#define sbspace(sb) \ + ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \ + (int)((sb)->sb_mbmax - (sb)->sb_mbcnt))) + +/* do we have to send all at once on a socket? */ +#define sosendallatonce(so) \ + ((so)->so_proto->pr_flags & PR_ATOMIC) + +/* can we read something from so? */ +#define soreadable(so) \ + ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \ + ((so)->so_state & SS_CANTRCVMORE) || \ + !TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error) + +/* can we write something to so? */ +#define sowriteable(so) \ + ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \ + (((so)->so_state&SS_ISCONNECTED) || \ + ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \ + ((so)->so_state & SS_CANTSENDMORE) || \ + (so)->so_error) + +/* adjust counters in sb reflecting allocation of m */ +#define sballoc(sb, m) { \ + (sb)->sb_cc += (m)->m_len; \ + if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \ + (m)->m_type != MT_OOBDATA) \ + (sb)->sb_ctl += (m)->m_len; \ + (sb)->sb_mbcnt += MSIZE; \ + if ((m)->m_flags & M_EXT) \ + (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ +} + +/* adjust counters in sb reflecting freeing of m */ +#define sbfree(sb, m) { \ + (sb)->sb_cc -= (m)->m_len; \ + if ((m)->m_type != MT_DATA && (m)->m_type != MT_HEADER && \ + (m)->m_type != MT_OOBDATA) \ + (sb)->sb_ctl -= (m)->m_len; \ + (sb)->sb_mbcnt -= MSIZE; \ + if ((m)->m_flags & M_EXT) \ + (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ +} + +/* + * Set lock on sockbuf sb; sleep if lock is already held. + * Unless SB_NOINTR is set on sockbuf, sleep is interruptible. + * Returns error without lock if sleep is interrupted. + */ +#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \ + (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \ + ((sb)->sb_flags |= SB_LOCK), 0) + +/* release lock on sockbuf sb */ +#define sbunlock(sb) { \ + (sb)->sb_flags &= ~SB_LOCK; \ + if ((sb)->sb_flags & SB_WANT) { \ + (sb)->sb_flags &= ~SB_WANT; \ + wakeup(&(sb)->sb_flags); \ + } \ +} + +/* + * soref()/sorele() ref-count the socket structure. Note that you must + * still explicitly close the socket, but the last ref count will free + * the structure. + */ +#define soref(so) do { \ + ++(so)->so_count; \ + } while (0) + +#define sorele(so) do { \ + if ((so)->so_count <= 0) \ + panic("sorele");\ + if (--(so)->so_count == 0)\ + sofree(so); \ + } while (0) + +#define sotryfree(so) do { \ + if ((so)->so_count == 0) \ + sofree(so); \ + } while(0) + +#define sorwakeup(so) do { \ + if (sb_notify(&(so)->so_rcv)) \ + sowakeup((so), &(so)->so_rcv); \ + } while (0) + +#define sowwakeup(so) do { \ + if (sb_notify(&(so)->so_snd)) \ + sowakeup((so), &(so)->so_snd); \ + } while (0) + +#ifdef _KERNEL + +/* + * Argument structure for sosetopt et seq. This is in the KERNEL + * section because it will never be visible to user code. + */ +enum sopt_dir { SOPT_GET, SOPT_SET }; +struct sockopt { + enum sopt_dir sopt_dir; /* is this a get or a set? */ + int sopt_level; /* second arg of [gs]etsockopt */ + int sopt_name; /* third arg of [gs]etsockopt */ + void *sopt_val; /* fourth arg of [gs]etsockopt */ + size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */ + struct thread *sopt_td; /* calling thread or null if kernel */ +}; + +struct accept_filter { + char accf_name[16]; + void (*accf_callback) + (struct socket *so, void *arg, int waitflag); + void * (*accf_create) + (struct socket *so, char *arg); + void (*accf_destroy) + (struct socket *so); + SLIST_ENTRY(accept_filter) accf_next; +}; + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_ACCF); +MALLOC_DECLARE(M_PCB); +MALLOC_DECLARE(M_SONAME); +#endif + +extern int maxsockets; +extern u_long sb_max; +extern struct uma_zone *socket_zone; +extern so_gen_t so_gencnt; + +struct mbuf; +struct sockaddr; +struct ucred; +struct uio; + +/* + * From uipc_socket and friends + */ +int sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type); +int getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len); +void sbappend(struct sockbuf *sb, struct mbuf *m); +void sbappendstream(struct sockbuf *sb, struct mbuf *m); +int sbappendaddr(struct sockbuf *sb, struct sockaddr *asa, + struct mbuf *m0, struct mbuf *control); +int sbappendcontrol(struct sockbuf *sb, struct mbuf *m0, + struct mbuf *control); +void sbappendrecord(struct sockbuf *sb, struct mbuf *m0); +void sbcheck(struct sockbuf *sb); +void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n); +struct mbuf * + sbcreatecontrol(caddr_t p, int size, int type, int level); +void sbdrop(struct sockbuf *sb, int len); +void sbdroprecord(struct sockbuf *sb); +void sbflush(struct sockbuf *sb); +void sbinsertoob(struct sockbuf *sb, struct mbuf *m0); +void sbrelease(struct sockbuf *sb, struct socket *so); +int sbreserve(struct sockbuf *sb, u_long cc, struct socket *so, + struct thread *td); +void sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb); +int sbwait(struct sockbuf *sb); +int sb_lock(struct sockbuf *sb); +int soabort(struct socket *so); +int soaccept(struct socket *so, struct sockaddr **nam); +struct socket *soalloc(int mflags); +int socheckuid(struct socket *so, uid_t uid); +int sobind(struct socket *so, struct sockaddr *nam, struct thread *td); +void socantrcvmore(struct socket *so); +void socantsendmore(struct socket *so); +int soclose(struct socket *so); +int soconnect(struct socket *so, struct sockaddr *nam, struct thread *td); +int soconnect2(struct socket *so1, struct socket *so2); +int socow_setup(struct mbuf *m0, struct uio *uio); +int socreate(int dom, struct socket **aso, int type, int proto, + struct ucred *cred, struct thread *td); +void sodealloc(struct socket *so); +int sodisconnect(struct socket *so); +struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags); +void sofree(struct socket *so); +int sogetopt(struct socket *so, struct sockopt *sopt); +void sohasoutofband(struct socket *so); +void soisconnected(struct socket *so); +void soisconnecting(struct socket *so); +void soisdisconnected(struct socket *so); +void soisdisconnecting(struct socket *so); +int solisten(struct socket *so, int backlog, struct thread *td); +struct socket * + sonewconn(struct socket *head, int connstatus); +int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen); +int sooptcopyout(struct sockopt *sopt, const void *buf, size_t len); + +/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */ +int soopt_getm(struct sockopt *sopt, struct mbuf **mp); +int soopt_mcopyin(struct sockopt *sopt, struct mbuf *m); +int soopt_mcopyout(struct sockopt *sopt, struct mbuf *m); + +int sopoll(struct socket *so, int events, struct ucred *active_cred, + struct thread *td); +int soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio, + struct mbuf **mp0, struct mbuf **controlp, int *flagsp); +int soreserve(struct socket *so, u_long sndcc, u_long rcvcc); +void sorflush(struct socket *so); +int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, + struct mbuf *top, struct mbuf *control, int flags, + struct thread *td); +int sosetopt(struct socket *so, struct sockopt *sopt); +int soshutdown(struct socket *so, int how); +void sotoxsocket(struct socket *so, struct xsocket *xso); +void sowakeup(struct socket *so, struct sockbuf *sb); + +#ifdef SOCKBUF_DEBUG +void sblastrecordchk(struct sockbuf *, const char *, int); +#define SBLASTRECORDCHK(sb) sblastrecordchk((sb), __FILE__, __LINE__) + +void sblastmbufchk(struct sockbuf *, const char *, int); +#define SBLASTMBUFCHK(sb) sblastmbufchk((sb), __FILE__, __LINE__) +#else +#define SBLASTRECORDCHK(sb) /* nothing */ +#define SBLASTMBUFCHK(sb) /* nothing */ +#endif /* SOCKBUF_DEBUG */ + +/* + * Accept filter functions (duh). + */ +int accept_filt_add(struct accept_filter *filt); +int accept_filt_del(char *name); +struct accept_filter *accept_filt_get(char *name); +#ifdef ACCEPT_FILTER_MOD +#ifdef SYSCTL_DECL +SYSCTL_DECL(_net_inet_accf); +#endif +int accept_filt_generic_mod_event(module_t mod, int event, void *data); +#endif + +#endif /* _KERNEL */ + +#endif /* !_SYS_SOCKETVAR_H_ */ diff --git a/src/include/sys/sockio.h b/src/include/sys/sockio.h new file mode 100644 index 0000000..b323cd1 --- /dev/null +++ b/src/include/sys/sockio.h @@ -0,0 +1,112 @@ +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * 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. + * 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. + * + * @(#)sockio.h 8.1 (Berkeley) 3/28/94 + * $FreeBSD: src/sys/sys/sockio.h,v 1.27 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SOCKIO_H_ +#define _SYS_SOCKIO_H_ + +#include + +/* Socket ioctl's. */ +#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */ +#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */ +#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */ +#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */ +#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ +#define SIOCSPGRP _IOW('s', 8, int) /* set process group */ +#define SIOCGPGRP _IOR('s', 9, int) /* get process group */ + +#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */ +#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */ +#define SIOCGETVIFCNT _IOWR('r', 15, struct sioc_vif_req)/* get vif pkt cnt */ +#define SIOCGETSGCNT _IOWR('r', 16, struct sioc_sg_req) /* get s,g pkt cnt */ + +#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */ +#define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */ +#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ +#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */ +#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */ +#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */ +#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */ +#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */ +#define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */ +#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */ +#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */ +#define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */ +#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */ +#define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */ +#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */ +#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */ +#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */ +#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */ +#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */ +#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */ + +#define SIOCALIFADDR _IOW('i', 27, struct if_laddrreq) /* add IF addr */ +#define SIOCGLIFADDR _IOWR('i', 28, struct if_laddrreq) /* get IF addr */ +#define SIOCDLIFADDR _IOW('i', 29, struct if_laddrreq) /* delete IF addr */ +#define SIOCSIFCAP _IOW('i', 30, struct ifreq) /* set IF features */ +#define SIOCGIFCAP _IOWR('i', 31, struct ifreq) /* get IF features */ +#define SIOCGIFINDEX _IOWR('i', 32, struct ifreq) /* get IF index */ +#define SIOCGIFMAC _IOWR('i', 38, struct ifreq) /* get IF MAC label */ +#define SIOCSIFMAC _IOW('i', 39, struct ifreq) /* set IF MAC label */ +#define SIOCSIFNAME _IOW('i', 40, struct ifreq) /* set IF name */ + +#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ +#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */ +#define SIOCGIFMTU _IOWR('i', 51, struct ifreq) /* get IF mtu */ +#define SIOCSIFMTU _IOW('i', 52, struct ifreq) /* set IF mtu */ +#define SIOCGIFPHYS _IOWR('i', 53, struct ifreq) /* get IF wire */ +#define SIOCSIFPHYS _IOW('i', 54, struct ifreq) /* set IF wire */ +#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ +#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ + +#define SIOCSIFGENERIC _IOW('i', 57, struct ifreq) /* generic IF set op */ +#define SIOCGIFGENERIC _IOWR('i', 58, struct ifreq) /* generic IF get op */ + +#define SIOCGIFSTATUS _IOWR('i', 59, struct ifstat) /* get IF status */ +#define SIOCSIFLLADDR _IOW('i', 60, struct ifreq) /* set linklevel addr */ + +#define SIOCSIFPHYADDR _IOW('i', 70, struct ifaliasreq) /* set gif addres */ +#define SIOCGIFPSRCADDR _IOWR('i', 71, struct ifreq) /* get gif psrc addr */ +#define SIOCGIFPDSTADDR _IOWR('i', 72, struct ifreq) /* get gif pdst addr */ +#define SIOCDIFPHYADDR _IOW('i', 73, struct ifreq) /* delete gif addrs */ +#define SIOCSLIFPHYADDR _IOW('i', 74, struct if_laddrreq) /* set gif addrs */ +#define SIOCGLIFPHYADDR _IOWR('i', 75, struct if_laddrreq) /* get gif addrs */ + +#define SIOCGPRIVATE_0 _IOWR('i', 80, struct ifreq) /* device private 0 */ +#define SIOCGPRIVATE_1 _IOWR('i', 81, struct ifreq) /* device private 1 */ + +#define SIOCIFCREATE _IOWR('i', 122, struct ifreq) /* create clone if */ +#define SIOCIFDESTROY _IOW('i', 121, struct ifreq) /* destroy clone if */ +#define SIOCIFGCLONERS _IOWR('i', 120, struct if_clonereq) /* get cloners */ + +#endif /* !_SYS_SOCKIO_H_ */ diff --git a/src/include/sys/soundcard.h b/src/include/sys/soundcard.h new file mode 100644 index 0000000..60dc129 --- /dev/null +++ b/src/include/sys/soundcard.h @@ -0,0 +1,1434 @@ +/* + * soundcard.h + * + * Copyright by Hannu Savolainen 1993 + * Modified for the new FreeBSD sound driver by Luigi Rizzo, 1997 + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR + * 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. + * + * $FreeBSD: src/sys/sys/soundcard.h,v 1.43 2003/11/22 03:27:09 matk Exp $ + */ + +#ifndef _SYS_SOUNDCARD_H_ +#define _SYS_SOUNDCARD_H_ + /* + * If you make modifications to this file, please contact me before + * distributing the modified version. There is already enough + * diversity in the world. + * + * Regards, + * Hannu Savolainen + * hannu@voxware.pp.fi + * + ********************************************************************** + * PS. The Hacker's Guide to VoxWare available from + * nic.funet.fi:pub/Linux/ALPHA/sound. The file is + * snd-sdk-doc-0.1.ps.gz (gzipped postscript). It contains + * some useful information about programming with VoxWare. + * (NOTE! The pub/Linux/ALPHA/ directories are hidden. You have + * to cd inside them before the files are accessible.) + ********************************************************************** + */ + +/* + * SOUND_VERSION is only used by the voxware driver. Hopefully apps + * should not depend on it, but rather look at the capabilities + * of the driver in the kernel! + */ +#define SOUND_VERSION 301 +#define VOXWARE /* does this have any use ? */ + +/* + * Supported card ID numbers (Should be somewhere else? We keep + * them here just for compativility with the old driver, but these + * constants are of little or no use). + */ + +#define SNDCARD_ADLIB 1 +#define SNDCARD_SB 2 +#define SNDCARD_PAS 3 +#define SNDCARD_GUS 4 +#define SNDCARD_MPU401 5 +#define SNDCARD_SB16 6 +#define SNDCARD_SB16MIDI 7 +#define SNDCARD_UART6850 8 +#define SNDCARD_GUS16 9 +#define SNDCARD_MSS 10 +#define SNDCARD_PSS 11 +#define SNDCARD_SSCAPE 12 +#define SNDCARD_PSS_MPU 13 +#define SNDCARD_PSS_MSS 14 +#define SNDCARD_SSCAPE_MSS 15 +#define SNDCARD_TRXPRO 16 +#define SNDCARD_TRXPRO_SB 17 +#define SNDCARD_TRXPRO_MPU 18 +#define SNDCARD_MAD16 19 +#define SNDCARD_MAD16_MPU 20 +#define SNDCARD_CS4232 21 +#define SNDCARD_CS4232_MPU 22 +#define SNDCARD_MAUI 23 +#define SNDCARD_PSEUDO_MSS 24 +#define SNDCARD_AWE32 25 +#define SNDCARD_NSS 26 +#define SNDCARD_UART16550 27 +#define SNDCARD_OPL 28 + +#include +#include +#ifndef _IOWR +#include +#endif /* !_IOWR */ + +/* + * The first part of this file contains the new FreeBSD sound ioctl + * interface. Tries to minimize the number of different ioctls, and + * to be reasonably general. + * + * 970821: some of the new calls have not been implemented yet. + */ + +/* + * the following three calls extend the generic file descriptor + * interface. AIONWRITE is the dual of FIONREAD, i.e. returns the max + * number of bytes for a write operation to be non-blocking. + * + * AIOGSIZE/AIOSSIZE are used to change the behaviour of the device, + * from a character device (default) to a block device. In block mode, + * (not to be confused with blocking mode) the main difference for the + * application is that select() will return only when a complete + * block can be read/written to the device, whereas in character mode + * select will return true when one byte can be exchanged. For audio + * devices, character mode makes select almost useless since one byte + * will always be ready by the next sample time (which is often only a + * handful of microseconds away). + * Use a size of 0 or 1 to return to character mode. + */ +#define AIONWRITE _IOR('A', 10, int) /* get # bytes to write */ +struct snd_size { + int play_size; + int rec_size; +}; +#define AIOGSIZE _IOR('A', 11, struct snd_size)/* read current blocksize */ +#define AIOSSIZE _IOWR('A', 11, struct snd_size) /* sets blocksize */ + +/* + * The following constants define supported audio formats. The + * encoding follows voxware conventions, i.e. 1 bit for each supported + * format. We extend it by using bit 31 (RO) to indicate full-duplex + * capability, and bit 29 (RO) to indicate that the card supports/ + * needs different formats on capture & playback channels. + * Bit 29 (RW) is used to indicate/ask stereo. + * + * The number of bits required to store the sample is: + * o 4 bits for the IDA ADPCM format, + * o 8 bits for 8-bit formats, mu-law and A-law, + * o 16 bits for the 16-bit formats, and + * o 32 bits for the 24/32-bit formats. + * o undefined for the MPEG audio format. + */ + +#define AFMT_QUERY 0x00000000 /* Return current format */ +#define AFMT_MU_LAW 0x00000001 /* Logarithmic mu-law */ +#define AFMT_A_LAW 0x00000002 /* Logarithmic A-law */ +#define AFMT_IMA_ADPCM 0x00000004 /* A 4:1 compressed format where 16-bit + * squence represented using the + * the average 4 bits per sample */ +#define AFMT_U8 0x00000008 /* Unsigned 8-bit */ +#define AFMT_S16_LE 0x00000010 /* Little endian signed 16-bit */ +#define AFMT_S16_BE 0x00000020 /* Big endian signed 16-bit */ +#define AFMT_S8 0x00000040 /* Signed 8-bit */ +#define AFMT_U16_LE 0x00000080 /* Little endian unsigned 16-bit */ +#define AFMT_U16_BE 0x00000100 /* Big endian unsigned 16-bit */ +#define AFMT_MPEG 0x00000200 /* MPEG MP2/MP3 audio */ +#define AFMT_AC3 0x00000400 /* Dolby Digital AC3 */ + +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define AFMT_S16_NE AFMT_S16_LE /* native endian signed 16 */ +#else +#define AFMT_S16_NE AFMT_S16_BE +#endif + +/* + * 32-bit formats below used for 24-bit audio data where the data is stored + * in the 24 most significant bits and the least significant bits are not used + * (should be set to 0). + */ +#define AFMT_S32_LE 0x00001000 /* Little endian signed 32-bit */ +#define AFMT_S32_BE 0x00002000 /* Big endian signed 32-bit */ +#define AFMT_U32_LE 0x00004000 /* Little endian unsigned 32-bit */ +#define AFMT_U32_BE 0x00008000 /* Big endian unsigned 32-bit */ + +#define AFMT_STEREO 0x10000000 /* can do/want stereo */ + +/* + * the following are really capabilities + */ +#define AFMT_WEIRD 0x20000000 /* weird hardware... */ + /* + * AFMT_WEIRD reports that the hardware might need to operate + * with different formats in the playback and capture + * channels when operating in full duplex. + * As an example, SoundBlaster16 cards only support U8 in one + * direction and S16 in the other one, and applications should + * be aware of this limitation. + */ +#define AFMT_FULLDUPLEX 0x80000000 /* can do full duplex */ + +/* + * The following structure is used to get/set format and sampling rate. + * While it would be better to have things such as stereo, bits per + * sample, endiannes, etc split in different variables, it turns out + * that formats are not that many, and not all combinations are possible. + * So we followed the Voxware approach of associating one bit to each + * format. + */ + +typedef struct _snd_chan_param { + u_long play_rate; /* sampling rate */ + u_long rec_rate; /* sampling rate */ + u_long play_format; /* everything describing the format */ + u_long rec_format; /* everything describing the format */ +} snd_chan_param; +#define AIOGFMT _IOR('f', 12, snd_chan_param) /* get format */ +#define AIOSFMT _IOWR('f', 12, snd_chan_param) /* sets format */ + +/* + * The following structure is used to get/set the mixer setting. + * Up to 32 mixers are supported, each one with up to 32 channels. + */ +typedef struct _snd_mix_param { + u_char subdev; /* which output */ + u_char line; /* which input */ + u_char left,right; /* volumes, 0..255, 0 = mute */ +} snd_mix_param ; + +/* XXX AIOGMIX, AIOSMIX not implemented yet */ +#define AIOGMIX _IOWR('A', 13, snd_mix_param) /* return mixer status */ +#define AIOSMIX _IOWR('A', 14, snd_mix_param) /* sets mixer status */ + +/* + * channel specifiers used in AIOSTOP and AIOSYNC + */ +#define AIOSYNC_PLAY 0x1 /* play chan */ +#define AIOSYNC_CAPTURE 0x2 /* capture chan */ +/* AIOSTOP stop & flush a channel, returns the residual count */ +#define AIOSTOP _IOWR ('A', 15, int) + +/* alternate method used to notify the sync condition */ +#define AIOSYNC_SIGNAL 0x100 +#define AIOSYNC_SELECT 0x200 + +/* what the 'pos' field refers to */ +#define AIOSYNC_READY 0x400 +#define AIOSYNC_FREE 0x800 + +typedef struct _snd_sync_parm { + long chan ; /* play or capture channel, plus modifier */ + long pos; +} snd_sync_parm; +#define AIOSYNC _IOWR ('A', 15, snd_sync_parm) /* misc. synchronization */ + +/* + * The following is used to return device capabilities. If the structure + * passed to the ioctl is zeroed, default values are returned for rate + * and formats, a bitmap of available mixers is returned, and values + * (inputs, different levels) for the first one are returned. + * + * If formats, mixers, inputs are instantiated, then detailed info + * are returned depending on the call. + */ +typedef struct _snd_capabilities { + u_long rate_min, rate_max; /* min-max sampling rate */ + u_long formats; + u_long bufsize; /* DMA buffer size */ + u_long mixers; /* bitmap of available mixers */ + u_long inputs; /* bitmap of available inputs (per mixer) */ + u_short left, right; /* how many levels are supported */ +} snd_capabilities; +#define AIOGCAP _IOWR('A', 15, snd_capabilities) /* get capabilities */ + +/* + * here is the old (Voxware) ioctl interface + */ + +/* + * IOCTL Commands for /dev/sequencer + */ + +#define SNDCTL_SEQ_RESET _IO ('Q', 0) +#define SNDCTL_SEQ_SYNC _IO ('Q', 1) +#define SNDCTL_SYNTH_INFO _IOWR('Q', 2, struct synth_info) +#define SNDCTL_SEQ_CTRLRATE _IOWR('Q', 3, int) /* Set/get timer res.(hz) */ +#define SNDCTL_SEQ_GETOUTCOUNT _IOR ('Q', 4, int) +#define SNDCTL_SEQ_GETINCOUNT _IOR ('Q', 5, int) +#define SNDCTL_SEQ_PERCMODE _IOW ('Q', 6, int) +#define SNDCTL_FM_LOAD_INSTR _IOW ('Q', 7, struct sbi_instrument) /* Valid for FM only */ +#define SNDCTL_SEQ_TESTMIDI _IOW ('Q', 8, int) +#define SNDCTL_SEQ_RESETSAMPLES _IOW ('Q', 9, int) +#define SNDCTL_SEQ_NRSYNTHS _IOR ('Q',10, int) +#define SNDCTL_SEQ_NRMIDIS _IOR ('Q',11, int) +#define SNDCTL_MIDI_INFO _IOWR('Q',12, struct midi_info) +#define SNDCTL_SEQ_THRESHOLD _IOW ('Q',13, int) +#define SNDCTL_SEQ_TRESHOLD SNDCTL_SEQ_THRESHOLD /* there was once a typo */ +#define SNDCTL_SYNTH_MEMAVL _IOWR('Q',14, int) /* in=dev#, out=memsize */ +#define SNDCTL_FM_4OP_ENABLE _IOW ('Q',15, int) /* in=dev# */ +#define SNDCTL_PMGR_ACCESS _IOWR('Q',16, struct patmgr_info) +#define SNDCTL_SEQ_PANIC _IO ('Q',17) +#define SNDCTL_SEQ_OUTOFBAND _IOW ('Q',18, struct seq_event_rec) +#define SNDCTL_SEQ_GETTIME _IOR ('Q',19, int) + +struct seq_event_rec { + u_char arr[8]; +}; + +#define SNDCTL_TMR_TIMEBASE _IOWR('T', 1, int) +#define SNDCTL_TMR_START _IO ('T', 2) +#define SNDCTL_TMR_STOP _IO ('T', 3) +#define SNDCTL_TMR_CONTINUE _IO ('T', 4) +#define SNDCTL_TMR_TEMPO _IOWR('T', 5, int) +#define SNDCTL_TMR_SOURCE _IOWR('T', 6, int) +# define TMR_INTERNAL 0x00000001 +# define TMR_EXTERNAL 0x00000002 +# define TMR_MODE_MIDI 0x00000010 +# define TMR_MODE_FSK 0x00000020 +# define TMR_MODE_CLS 0x00000040 +# define TMR_MODE_SMPTE 0x00000080 +#define SNDCTL_TMR_METRONOME _IOW ('T', 7, int) +#define SNDCTL_TMR_SELECT _IOW ('T', 8, int) + +/* + * Endian aware patch key generation algorithm. + */ + +#if defined(_AIX) || defined(AIX) +# define _PATCHKEY(id) (0xfd00|id) +#else +# define _PATCHKEY(id) ((id<<8)|0xfd) +#endif + +/* + * Sample loading mechanism for internal synthesizers (/dev/sequencer) + * The following patch_info structure has been designed to support + * Gravis UltraSound. It tries to be universal format for uploading + * sample based patches but is probably too limited. + */ + +struct patch_info { +/* u_short key; Use GUS_PATCH here */ + short key; /* Use GUS_PATCH here */ +#define GUS_PATCH _PATCHKEY(0x04) +#define OBSOLETE_GUS_PATCH _PATCHKEY(0x02) + + short device_no; /* Synthesizer number */ + short instr_no; /* Midi pgm# */ + + u_long mode; +/* + * The least significant byte has the same format than the GUS .PAT + * files + */ +#define WAVE_16_BITS 0x01 /* bit 0 = 8 or 16 bit wave data. */ +#define WAVE_UNSIGNED 0x02 /* bit 1 = Signed - Unsigned data. */ +#define WAVE_LOOPING 0x04 /* bit 2 = looping enabled-1. */ +#define WAVE_BIDIR_LOOP 0x08 /* bit 3 = Set is bidirectional looping. */ +#define WAVE_LOOP_BACK 0x10 /* bit 4 = Set is looping backward. */ +#define WAVE_SUSTAIN_ON 0x20 /* bit 5 = Turn sustaining on. (Env. pts. 3)*/ +#define WAVE_ENVELOPES 0x40 /* bit 6 = Enable envelopes - 1 */ + /* (use the env_rate/env_offs fields). */ +/* Linux specific bits */ +#define WAVE_VIBRATO 0x00010000 /* The vibrato info is valid */ +#define WAVE_TREMOLO 0x00020000 /* The tremolo info is valid */ +#define WAVE_SCALE 0x00040000 /* The scaling info is valid */ +/* Other bits must be zeroed */ + + long len; /* Size of the wave data in bytes */ + long loop_start, loop_end; /* Byte offsets from the beginning */ + +/* + * The base_freq and base_note fields are used when computing the + * playback speed for a note. The base_note defines the tone frequency + * which is heard if the sample is played using the base_freq as the + * playback speed. + * + * The low_note and high_note fields define the minimum and maximum note + * frequencies for which this sample is valid. It is possible to define + * more than one samples for an instrument number at the same time. The + * low_note and high_note fields are used to select the most suitable one. + * + * The fields base_note, high_note and low_note should contain + * the note frequency multiplied by 1000. For example value for the + * middle A is 440*1000. + */ + + u_int base_freq; + u_long base_note; + u_long high_note; + u_long low_note; + int panning; /* -128=left, 127=right */ + int detuning; + +/* New fields introduced in version 1.99.5 */ + + /* Envelope. Enabled by mode bit WAVE_ENVELOPES */ + u_char env_rate[ 6 ]; /* GUS HW ramping rate */ + u_char env_offset[ 6 ]; /* 255 == 100% */ + + /* + * The tremolo, vibrato and scale info are not supported yet. + * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or + * WAVE_SCALE + */ + + u_char tremolo_sweep; + u_char tremolo_rate; + u_char tremolo_depth; + + u_char vibrato_sweep; + u_char vibrato_rate; + u_char vibrato_depth; + + int scale_frequency; + u_int scale_factor; /* from 0 to 2048 or 0 to 2 */ + + int volume; + int spare[4]; + char data[1]; /* The waveform data starts here */ +}; + +struct sysex_info { + short key; /* Use GUS_PATCH here */ +#define SYSEX_PATCH _PATCHKEY(0x05) +#define MAUI_PATCH _PATCHKEY(0x06) + short device_no; /* Synthesizer number */ + long len; /* Size of the sysex data in bytes */ + u_char data[1]; /* Sysex data starts here */ +}; + +/* + * Patch management interface (/dev/sequencer, /dev/patmgr#) + * Don't use these calls if you want to maintain compatibility with + * the future versions of the driver. + */ + +#define PS_NO_PATCHES 0 /* No patch support on device */ +#define PS_MGR_NOT_OK 1 /* Plain patch support (no mgr) */ +#define PS_MGR_OK 2 /* Patch manager supported */ +#define PS_MANAGED 3 /* Patch manager running */ + +#define SNDCTL_PMGR_IFACE _IOWR('P', 1, struct patmgr_info) + +/* + * The patmgr_info is a fixed size structure which is used for two + * different purposes. The intended use is for communication between + * the application using /dev/sequencer and the patch manager daemon + * associated with a synthesizer device (ioctl(SNDCTL_PMGR_ACCESS)). + * + * This structure is also used with ioctl(SNDCTL_PGMR_IFACE) which allows + * a patch manager daemon to read and write device parameters. This + * ioctl available through /dev/sequencer also. Avoid using it since it's + * extremely hardware dependent. In addition access trough /dev/sequencer + * may confuse the patch manager daemon. + */ + +struct patmgr_info { /* Note! size must be < 4k since kmalloc() is used */ + u_long key; /* Don't worry. Reserved for communication + between the patch manager and the driver. */ +#define PM_K_EVENT 1 /* Event from the /dev/sequencer driver */ +#define PM_K_COMMAND 2 /* Request from an application */ +#define PM_K_RESPONSE 3 /* From patmgr to application */ +#define PM_ERROR 4 /* Error returned by the patmgr */ + int device; + int command; + +/* + * Commands 0x000 to 0xfff reserved for patch manager programs + */ +#define PM_GET_DEVTYPE 1 /* Returns type of the patch mgr interface of dev */ +#define PMTYPE_FM2 1 /* 2 OP fm */ +#define PMTYPE_FM4 2 /* Mixed 4 or 2 op FM (OPL-3) */ +#define PMTYPE_WAVE 3 /* Wave table synthesizer (GUS) */ +#define PM_GET_NRPGM 2 /* Returns max # of midi programs in parm1 */ +#define PM_GET_PGMMAP 3 /* Returns map of loaded midi programs in data8 */ +#define PM_GET_PGM_PATCHES 4 /* Return list of patches of a program (parm1) */ +#define PM_GET_PATCH 5 /* Return patch header of patch parm1 */ +#define PM_SET_PATCH 6 /* Set patch header of patch parm1 */ +#define PM_READ_PATCH 7 /* Read patch (wave) data */ +#define PM_WRITE_PATCH 8 /* Write patch (wave) data */ + +/* + * Commands 0x1000 to 0xffff are for communication between the patch manager + * and the client + */ +#define _PM_LOAD_PATCH 0x100 + +/* + * Commands above 0xffff reserved for device specific use + */ + + long parm1; + long parm2; + long parm3; + + union { + u_char data8[4000]; + u_short data16[2000]; + u_long data32[1000]; + struct patch_info patch; + } data; +}; + +/* + * When a patch manager daemon is present, it will be informed by the + * driver when something important happens. For example when the + * /dev/sequencer is opened or closed. A record with key == PM_K_EVENT is + * returned. The command field contains the event type: + */ +#define PM_E_OPENED 1 /* /dev/sequencer opened */ +#define PM_E_CLOSED 2 /* /dev/sequencer closed */ +#define PM_E_PATCH_RESET 3 /* SNDCTL_RESETSAMPLES called */ +#define PM_E_PATCH_LOADED 4 /* A patch has been loaded by appl */ + +/* + * /dev/sequencer input events. + * + * The data written to the /dev/sequencer is a stream of events. Events + * are records of 4 or 8 bytes. The first byte defines the size. + * Any number of events can be written with a write call. There + * is a set of macros for sending these events. Use these macros if you + * want to maximize portability of your program. + * + * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events. + * (All input events are currently 4 bytes long. Be prepared to support + * 8 byte events also. If you receive any event having first byte >= 128, + * it's a 8 byte event. + * + * The events are documented at the end of this file. + * + * Normal events (4 bytes) + * There is also a 8 byte version of most of the 4 byte events. The + * 8 byte one is recommended. + */ +#define SEQ_NOTEOFF 0 +#define SEQ_FMNOTEOFF SEQ_NOTEOFF /* Just old name */ +#define SEQ_NOTEON 1 +#define SEQ_FMNOTEON SEQ_NOTEON +#define SEQ_WAIT TMR_WAIT_ABS +#define SEQ_PGMCHANGE 3 +#define SEQ_FMPGMCHANGE SEQ_PGMCHANGE +#define SEQ_SYNCTIMER TMR_START +#define SEQ_MIDIPUTC 5 +#define SEQ_DRUMON 6 /*** OBSOLETE ***/ +#define SEQ_DRUMOFF 7 /*** OBSOLETE ***/ +#define SEQ_ECHO TMR_ECHO /* For synching programs with output */ +#define SEQ_AFTERTOUCH 9 +#define SEQ_CONTROLLER 10 + +/* + * Midi controller numbers + * + * Controllers 0 to 31 (0x00 to 0x1f) and 32 to 63 (0x20 to 0x3f) + * are continuous controllers. + * In the MIDI 1.0 these controllers are sent using two messages. + * Controller numbers 0 to 31 are used to send the MSB and the + * controller numbers 32 to 63 are for the LSB. Note that just 7 bits + * are used in MIDI bytes. + */ + +#define CTL_BANK_SELECT 0x00 +#define CTL_MODWHEEL 0x01 +#define CTL_BREATH 0x02 +/* undefined 0x03 */ +#define CTL_FOOT 0x04 +#define CTL_PORTAMENTO_TIME 0x05 +#define CTL_DATA_ENTRY 0x06 +#define CTL_MAIN_VOLUME 0x07 +#define CTL_BALANCE 0x08 +/* undefined 0x09 */ +#define CTL_PAN 0x0a +#define CTL_EXPRESSION 0x0b +/* undefined 0x0c - 0x0f */ +#define CTL_GENERAL_PURPOSE1 0x10 +#define CTL_GENERAL_PURPOSE2 0x11 +#define CTL_GENERAL_PURPOSE3 0x12 +#define CTL_GENERAL_PURPOSE4 0x13 +/* undefined 0x14 - 0x1f */ + +/* undefined 0x20 */ + +/* + * The controller numbers 0x21 to 0x3f are reserved for the + * least significant bytes of the controllers 0x00 to 0x1f. + * These controllers are not recognised by the driver. + * + * Controllers 64 to 69 (0x40 to 0x45) are on/off switches. + * 0=OFF and 127=ON (intermediate values are possible) + */ +#define CTL_DAMPER_PEDAL 0x40 +#define CTL_SUSTAIN CTL_DAMPER_PEDAL /* Alias */ +#define CTL_HOLD CTL_DAMPER_PEDAL /* Alias */ +#define CTL_PORTAMENTO 0x41 +#define CTL_SOSTENUTO 0x42 +#define CTL_SOFT_PEDAL 0x43 +/* undefined 0x44 */ +#define CTL_HOLD2 0x45 +/* undefined 0x46 - 0x4f */ + +#define CTL_GENERAL_PURPOSE5 0x50 +#define CTL_GENERAL_PURPOSE6 0x51 +#define CTL_GENERAL_PURPOSE7 0x52 +#define CTL_GENERAL_PURPOSE8 0x53 +/* undefined 0x54 - 0x5a */ +#define CTL_EXT_EFF_DEPTH 0x5b +#define CTL_TREMOLO_DEPTH 0x5c +#define CTL_CHORUS_DEPTH 0x5d +#define CTL_DETUNE_DEPTH 0x5e +#define CTL_CELESTE_DEPTH CTL_DETUNE_DEPTH /* Alias for the above one */ +#define CTL_PHASER_DEPTH 0x5f +#define CTL_DATA_INCREMENT 0x60 +#define CTL_DATA_DECREMENT 0x61 +#define CTL_NONREG_PARM_NUM_LSB 0x62 +#define CTL_NONREG_PARM_NUM_MSB 0x63 +#define CTL_REGIST_PARM_NUM_LSB 0x64 +#define CTL_REGIST_PARM_NUM_MSB 0x65 +/* undefined 0x66 - 0x78 */ +/* reserved 0x79 - 0x7f */ + +/* Pseudo controllers (not midi compatible) */ +#define CTRL_PITCH_BENDER 255 +#define CTRL_PITCH_BENDER_RANGE 254 +#define CTRL_EXPRESSION 253 /* Obsolete */ +#define CTRL_MAIN_VOLUME 252 /* Obsolete */ + +#define SEQ_BALANCE 11 +#define SEQ_VOLMODE 12 + +/* + * Volume mode decides how volumes are used + */ + +#define VOL_METHOD_ADAGIO 1 +#define VOL_METHOD_LINEAR 2 + +/* + * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as + * input events. + */ + +/* + * Event codes 0xf0 to 0xfc are reserved for future extensions. + */ + +#define SEQ_FULLSIZE 0xfd /* Long events */ +/* + * SEQ_FULLSIZE events are used for loading patches/samples to the + * synthesizer devices. These events are passed directly to the driver + * of the associated synthesizer device. There is no limit to the size + * of the extended events. These events are not queued but executed + * immediately when the write() is called (execution can take several + * seconds of time). + * + * When a SEQ_FULLSIZE message is written to the device, it must + * be written using exactly one write() call. Other events cannot + * be mixed to the same write. + * + * For FM synths (YM3812/OPL3) use struct sbi_instrument and write + * it to the /dev/sequencer. Don't write other data together with + * the instrument structure Set the key field of the structure to + * FM_PATCH. The device field is used to route the patch to the + * corresponding device. + * + * For Gravis UltraSound use struct patch_info. Initialize the key field + * to GUS_PATCH. + */ +#define SEQ_PRIVATE 0xfe /* Low level HW dependent events (8 bytes) */ +#define SEQ_EXTENDED 0xff /* Extended events (8 bytes) OBSOLETE */ + +/* + * Record for FM patches + */ + +typedef u_char sbi_instr_data[32]; + +struct sbi_instrument { + u_short key; /* FM_PATCH or OPL3_PATCH */ +#define FM_PATCH _PATCHKEY(0x01) +#define OPL3_PATCH _PATCHKEY(0x03) + short device; /* Synth# (0-4) */ + int channel; /* Program# to be initialized */ + sbi_instr_data operators; /* Reg. settings for operator cells + * (.SBI format) */ +}; + +struct synth_info { /* Read only */ + char name[30]; + int device; /* 0-N. INITIALIZE BEFORE CALLING */ + int synth_type; +#define SYNTH_TYPE_FM 0 +#define SYNTH_TYPE_SAMPLE 1 +#define SYNTH_TYPE_MIDI 2 /* Midi interface */ + + int synth_subtype; +#define FM_TYPE_ADLIB 0x00 +#define FM_TYPE_OPL3 0x01 +#define MIDI_TYPE_MPU401 0x401 + +#define SAMPLE_TYPE_BASIC 0x10 +#define SAMPLE_TYPE_GUS SAMPLE_TYPE_BASIC +#define SAMPLE_TYPE_AWE32 0x20 + + int perc_mode; /* No longer supported */ + int nr_voices; + int nr_drums; /* Obsolete field */ + int instr_bank_size; + u_long capabilities; +#define SYNTH_CAP_PERCMODE 0x00000001 /* No longer used */ +#define SYNTH_CAP_OPL3 0x00000002 /* Set if OPL3 supported */ +#define SYNTH_CAP_INPUT 0x00000004 /* Input (MIDI) device */ + int dummies[19]; /* Reserve space */ +}; + +struct sound_timer_info { + char name[32]; + int caps; +}; + +#define MIDI_CAP_MPU401 1 /* MPU-401 intelligent mode */ + +struct midi_info { + char name[30]; + int device; /* 0-N. INITIALIZE BEFORE CALLING */ + u_long capabilities; /* To be defined later */ + int dev_type; + int dummies[18]; /* Reserve space */ +}; + +/* + * ioctl commands for the /dev/midi## + */ +typedef struct { + u_char cmd; + char nr_args, nr_returns; + u_char data[30]; +} mpu_command_rec; + +#define SNDCTL_MIDI_PRETIME _IOWR('m', 0, int) +#define SNDCTL_MIDI_MPUMODE _IOWR('m', 1, int) +#define SNDCTL_MIDI_MPUCMD _IOWR('m', 2, mpu_command_rec) +#define MIOSPASSTHRU _IOWR('m', 3, int) +#define MIOGPASSTHRU _IOWR('m', 4, int) + +/* + * IOCTL commands for /dev/dsp and /dev/audio + */ + +#define SNDCTL_DSP_RESET _IO ('P', 0) +#define SNDCTL_DSP_SYNC _IO ('P', 1) +#define SNDCTL_DSP_SPEED _IOWR('P', 2, int) +#define SNDCTL_DSP_STEREO _IOWR('P', 3, int) +#define SNDCTL_DSP_GETBLKSIZE _IOR('P', 4, int) +#define SNDCTL_DSP_SETBLKSIZE _IOW('P', 4, int) +#define SNDCTL_DSP_SETFMT _IOWR('P',5, int) /* Selects ONE fmt*/ + +/* + * SOUND_PCM_WRITE_CHANNELS is not that different + * from SNDCTL_DSP_STEREO + */ +#define SOUND_PCM_WRITE_CHANNELS _IOWR('P', 6, int) +#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS +#define SOUND_PCM_WRITE_FILTER _IOWR('P', 7, int) +#define SNDCTL_DSP_POST _IO ('P', 8) + +/* + * SNDCTL_DSP_SETBLKSIZE and the following two calls mostly do + * the same thing, i.e. set the block size used in DMA transfers. + */ +#define SNDCTL_DSP_SUBDIVIDE _IOWR('P', 9, int) +#define SNDCTL_DSP_SETFRAGMENT _IOWR('P',10, int) + + +#define SNDCTL_DSP_GETFMTS _IOR ('P',11, int) /* Returns a mask */ +/* + * Buffer status queries. + */ +typedef struct audio_buf_info { + int fragments; /* # of avail. frags (partly used ones not counted) */ + int fragstotal; /* Total # of fragments allocated */ + int fragsize; /* Size of a fragment in bytes */ + + int bytes; /* Avail. space in bytes (includes partly used fragments) */ + /* Note! 'bytes' could be more than fragments*fragsize */ +} audio_buf_info; + +#define SNDCTL_DSP_GETOSPACE _IOR ('P',12, audio_buf_info) +#define SNDCTL_DSP_GETISPACE _IOR ('P',13, audio_buf_info) + +/* + * SNDCTL_DSP_NONBLOCK is the same (but less powerful, since the + * action cannot be undone) of FIONBIO. The same can be achieved + * by opening the device with O_NDELAY + */ +#define SNDCTL_DSP_NONBLOCK _IO ('P',14) + +#define SNDCTL_DSP_GETCAPS _IOR ('P',15, int) +#define DSP_CAP_REVISION 0x000000ff /* revision level (0 to 255) */ +#define DSP_CAP_DUPLEX 0x00000100 /* Full duplex record/playback */ +#define DSP_CAP_REALTIME 0x00000200 /* Real time capability */ +#define DSP_CAP_BATCH 0x00000400 + /* + * Device has some kind of internal buffers which may + * cause some delays and decrease precision of timing + */ +#define DSP_CAP_COPROC 0x00000800 + /* Has a coprocessor, sometimes it's a DSP but usually not */ +#define DSP_CAP_TRIGGER 0x00001000 /* Supports SETTRIGGER */ +#define DSP_CAP_MMAP 0x00002000 /* Supports mmap() */ + +/* + * What do these function do ? + */ +#define SNDCTL_DSP_GETTRIGGER _IOR ('P',16, int) +#define SNDCTL_DSP_SETTRIGGER _IOW ('P',16, int) +#define PCM_ENABLE_INPUT 0x00000001 +#define PCM_ENABLE_OUTPUT 0x00000002 + +typedef struct count_info { + int bytes; /* Total # of bytes processed */ + int blocks; /* # of fragment transitions since last time */ + int ptr; /* Current DMA pointer value */ +} count_info; + +/* + * GETIPTR and GETISPACE are not that different... same for out. + */ +#define SNDCTL_DSP_GETIPTR _IOR ('P',17, count_info) +#define SNDCTL_DSP_GETOPTR _IOR ('P',18, count_info) + +typedef struct buffmem_desc { + caddr_t buffer; + int size; +} buffmem_desc; + +#define SNDCTL_DSP_MAPINBUF _IOR ('P', 19, buffmem_desc) +#define SNDCTL_DSP_MAPOUTBUF _IOR ('P', 20, buffmem_desc) +#define SNDCTL_DSP_SETSYNCRO _IO ('P', 21) +#define SNDCTL_DSP_SETDUPLEX _IO ('P', 22) +#define SNDCTL_DSP_GETODELAY _IOR ('P', 23, int) + +/* + * I guess these are the readonly version of the same + * functions that exist above as SNDCTL_DSP_... + */ +#define SOUND_PCM_READ_RATE _IOR ('P', 2, int) +#define SOUND_PCM_READ_CHANNELS _IOR ('P', 6, int) +#define SOUND_PCM_READ_BITS _IOR ('P', 5, int) +#define SOUND_PCM_READ_FILTER _IOR ('P', 7, int) + +/* + * ioctl calls to be used in communication with coprocessors and + * DSP chips. + */ + +typedef struct copr_buffer { + int command; /* Set to 0 if not used */ + int flags; +#define CPF_NONE 0x0000 +#define CPF_FIRST 0x0001 /* First block */ +#define CPF_LAST 0x0002 /* Last block */ + int len; + int offs; /* If required by the device (0 if not used) */ + + u_char data[4000]; /* NOTE! 4000 is not 4k */ +} copr_buffer; + +typedef struct copr_debug_buf { + int command; /* Used internally. Set to 0 */ + int parm1; + int parm2; + int flags; + int len; /* Length of data in bytes */ +} copr_debug_buf; + +typedef struct copr_msg { + int len; + u_char data[4000]; +} copr_msg; + +#define SNDCTL_COPR_RESET _IO ('C', 0) +#define SNDCTL_COPR_LOAD _IOWR('C', 1, copr_buffer) +#define SNDCTL_COPR_RDATA _IOWR('C', 2, copr_debug_buf) +#define SNDCTL_COPR_RCODE _IOWR('C', 3, copr_debug_buf) +#define SNDCTL_COPR_WDATA _IOW ('C', 4, copr_debug_buf) +#define SNDCTL_COPR_WCODE _IOW ('C', 5, copr_debug_buf) +#define SNDCTL_COPR_RUN _IOWR('C', 6, copr_debug_buf) +#define SNDCTL_COPR_HALT _IOWR('C', 7, copr_debug_buf) +#define SNDCTL_COPR_SENDMSG _IOW ('C', 8, copr_msg) +#define SNDCTL_COPR_RCVMSG _IOR ('C', 9, copr_msg) + +/* + * IOCTL commands for /dev/mixer + */ + +/* + * Mixer devices + * + * There can be up to 20 different analog mixer channels. The + * SOUND_MIXER_NRDEVICES gives the currently supported maximum. + * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells + * the devices supported by the particular mixer. + */ + +#define SOUND_MIXER_NRDEVICES 25 +#define SOUND_MIXER_VOLUME 0 /* Master output level */ +#define SOUND_MIXER_BASS 1 /* Treble level of all output channels */ +#define SOUND_MIXER_TREBLE 2 /* Bass level of all output channels */ +#define SOUND_MIXER_SYNTH 3 /* Volume of synthesier input */ +#define SOUND_MIXER_PCM 4 /* Output level for the audio device */ +#define SOUND_MIXER_SPEAKER 5 /* Output level for the PC speaker + * signals */ +#define SOUND_MIXER_LINE 6 /* Volume level for the line in jack */ +#define SOUND_MIXER_MIC 7 /* Volume for the signal coming from + * the microphone jack */ +#define SOUND_MIXER_CD 8 /* Volume level for the input signal + * connected to the CD audio input */ +#define SOUND_MIXER_IMIX 9 /* Recording monitor. It controls the + * output volume of the selected + * recording sources while recording */ +#define SOUND_MIXER_ALTPCM 10 /* Volume of the alternative codec + * device */ +#define SOUND_MIXER_RECLEV 11 /* Global recording level */ +#define SOUND_MIXER_IGAIN 12 /* Input gain */ +#define SOUND_MIXER_OGAIN 13 /* Output gain */ +/* + * The AD1848 codec and compatibles have three line level inputs + * (line, aux1 and aux2). Since each card manufacturer have assigned + * different meanings to these inputs, it's inpractical to assign + * specific meanings (line, cd, synth etc.) to them. + */ +#define SOUND_MIXER_LINE1 14 /* Input source 1 (aux1) */ +#define SOUND_MIXER_LINE2 15 /* Input source 2 (aux2) */ +#define SOUND_MIXER_LINE3 16 /* Input source 3 (line) */ +#define SOUND_MIXER_DIGITAL1 17 /* Digital (input) 1 */ +#define SOUND_MIXER_DIGITAL2 18 /* Digital (input) 2 */ +#define SOUND_MIXER_DIGITAL3 19 /* Digital (input) 3 */ +#define SOUND_MIXER_PHONEIN 20 /* Phone input */ +#define SOUND_MIXER_PHONEOUT 21 /* Phone output */ +#define SOUND_MIXER_VIDEO 22 /* Video/TV (audio) in */ +#define SOUND_MIXER_RADIO 23 /* Radio in */ +#define SOUND_MIXER_MONITOR 24 /* Monitor (usually mic) volume */ + + +/* + * Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX) + * Not counted to SOUND_MIXER_NRDEVICES, but use the same number space + */ +#define SOUND_ONOFF_MIN 28 +#define SOUND_ONOFF_MAX 30 +#define SOUND_MIXER_MUTE 28 /* 0 or 1 */ +#define SOUND_MIXER_ENHANCE 29 /* Enhanced stereo (0, 40, 60 or 80) */ +#define SOUND_MIXER_LOUD 30 /* 0 or 1 */ + +/* Note! Number 31 cannot be used since the sign bit is reserved */ +#define SOUND_MIXER_NONE 31 + +#define SOUND_DEVICE_LABELS { \ + "Vol ", "Bass ", "Trebl", "Synth", "Pcm ", "Spkr ", "Line ", \ + "Mic ", "CD ", "Mix ", "Pcm2 ", "Rec ", "IGain", "OGain", \ + "Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \ + "PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"} + +#define SOUND_DEVICE_NAMES { \ + "vol", "bass", "treble", "synth", "pcm", "speaker", "line", \ + "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \ + "line1", "line2", "line3", "dig1", "dig2", "dig3", \ + "phin", "phout", "video", "radio", "monitor"} + +/* Device bitmask identifiers */ + +#define SOUND_MIXER_RECSRC 0xff /* 1 bit per recording source */ +#define SOUND_MIXER_DEVMASK 0xfe /* 1 bit per supported device */ +#define SOUND_MIXER_RECMASK 0xfd /* 1 bit per supp. recording source */ +#define SOUND_MIXER_CAPS 0xfc +#define SOUND_CAP_EXCL_INPUT 0x00000001 /* Only 1 rec. src at a time */ +#define SOUND_MIXER_STEREODEVS 0xfb /* Mixer channels supporting stereo */ + +/* Device mask bits */ + +#define SOUND_MASK_VOLUME (1 << SOUND_MIXER_VOLUME) +#define SOUND_MASK_BASS (1 << SOUND_MIXER_BASS) +#define SOUND_MASK_TREBLE (1 << SOUND_MIXER_TREBLE) +#define SOUND_MASK_SYNTH (1 << SOUND_MIXER_SYNTH) +#define SOUND_MASK_PCM (1 << SOUND_MIXER_PCM) +#define SOUND_MASK_SPEAKER (1 << SOUND_MIXER_SPEAKER) +#define SOUND_MASK_LINE (1 << SOUND_MIXER_LINE) +#define SOUND_MASK_MIC (1 << SOUND_MIXER_MIC) +#define SOUND_MASK_CD (1 << SOUND_MIXER_CD) +#define SOUND_MASK_IMIX (1 << SOUND_MIXER_IMIX) +#define SOUND_MASK_ALTPCM (1 << SOUND_MIXER_ALTPCM) +#define SOUND_MASK_RECLEV (1 << SOUND_MIXER_RECLEV) +#define SOUND_MASK_IGAIN (1 << SOUND_MIXER_IGAIN) +#define SOUND_MASK_OGAIN (1 << SOUND_MIXER_OGAIN) +#define SOUND_MASK_LINE1 (1 << SOUND_MIXER_LINE1) +#define SOUND_MASK_LINE2 (1 << SOUND_MIXER_LINE2) +#define SOUND_MASK_LINE3 (1 << SOUND_MIXER_LINE3) +#define SOUND_MASK_DIGITAL1 (1 << SOUND_MIXER_DIGITAL1) +#define SOUND_MASK_DIGITAL2 (1 << SOUND_MIXER_DIGITAL2) +#define SOUND_MASK_DIGITAL3 (1 << SOUND_MIXER_DIGITAL3) +#define SOUND_MASK_PHONEIN (1 << SOUND_MIXER_PHONEIN) +#define SOUND_MASK_PHONEOUT (1 << SOUND_MIXER_PHONEOUT) +#define SOUND_MASK_RADIO (1 << SOUND_MIXER_RADIO) +#define SOUND_MASK_VIDEO (1 << SOUND_MIXER_VIDEO) +#define SOUND_MASK_MONITOR (1 << SOUND_MIXER_MONITOR) + +/* Obsolete macros */ +#define SOUND_MASK_MUTE (1 << SOUND_MIXER_MUTE) +#define SOUND_MASK_ENHANCE (1 << SOUND_MIXER_ENHANCE) +#define SOUND_MASK_LOUD (1 << SOUND_MIXER_LOUD) + +#define MIXER_READ(dev) _IOR('M', dev, int) +#define SOUND_MIXER_READ_VOLUME MIXER_READ(SOUND_MIXER_VOLUME) +#define SOUND_MIXER_READ_BASS MIXER_READ(SOUND_MIXER_BASS) +#define SOUND_MIXER_READ_TREBLE MIXER_READ(SOUND_MIXER_TREBLE) +#define SOUND_MIXER_READ_SYNTH MIXER_READ(SOUND_MIXER_SYNTH) +#define SOUND_MIXER_READ_PCM MIXER_READ(SOUND_MIXER_PCM) +#define SOUND_MIXER_READ_SPEAKER MIXER_READ(SOUND_MIXER_SPEAKER) +#define SOUND_MIXER_READ_LINE MIXER_READ(SOUND_MIXER_LINE) +#define SOUND_MIXER_READ_MIC MIXER_READ(SOUND_MIXER_MIC) +#define SOUND_MIXER_READ_CD MIXER_READ(SOUND_MIXER_CD) +#define SOUND_MIXER_READ_IMIX MIXER_READ(SOUND_MIXER_IMIX) +#define SOUND_MIXER_READ_ALTPCM MIXER_READ(SOUND_MIXER_ALTPCM) +#define SOUND_MIXER_READ_RECLEV MIXER_READ(SOUND_MIXER_RECLEV) +#define SOUND_MIXER_READ_IGAIN MIXER_READ(SOUND_MIXER_IGAIN) +#define SOUND_MIXER_READ_OGAIN MIXER_READ(SOUND_MIXER_OGAIN) +#define SOUND_MIXER_READ_LINE1 MIXER_READ(SOUND_MIXER_LINE1) +#define SOUND_MIXER_READ_LINE2 MIXER_READ(SOUND_MIXER_LINE2) +#define SOUND_MIXER_READ_LINE3 MIXER_READ(SOUND_MIXER_LINE3) +#define SOUND_MIXER_READ_DIGITAL1 MIXER_READ(SOUND_MIXER_DIGITAL1) +#define SOUND_MIXER_READ_DIGITAL2 MIXER_READ(SOUND_MIXER_DIGITAL2) +#define SOUND_MIXER_READ_DIGITAL3 MIXER_READ(SOUND_MIXER_DIGITAL3) +#define SOUND_MIXER_READ_PHONEIN MIXER_READ(SOUND_MIXER_PHONEIN) +#define SOUND_MIXER_READ_PHONEOUT MIXER_READ(SOUND_MIXER_PHONEOUT) +#define SOUND_MIXER_READ_RADIO MIXER_READ(SOUND_MIXER_RADIO) +#define SOUND_MIXER_READ_VIDEO MIXER_READ(SOUND_MIXER_VIDEO) +#define SOUND_MIXER_READ_MONITOR MIXER_READ(SOUND_MIXER_MONITOR) + +/* Obsolete macros */ +#define SOUND_MIXER_READ_MUTE MIXER_READ(SOUND_MIXER_MUTE) +#define SOUND_MIXER_READ_ENHANCE MIXER_READ(SOUND_MIXER_ENHANCE) +#define SOUND_MIXER_READ_LOUD MIXER_READ(SOUND_MIXER_LOUD) + +#define SOUND_MIXER_READ_RECSRC MIXER_READ(SOUND_MIXER_RECSRC) +#define SOUND_MIXER_READ_DEVMASK MIXER_READ(SOUND_MIXER_DEVMASK) +#define SOUND_MIXER_READ_RECMASK MIXER_READ(SOUND_MIXER_RECMASK) +#define SOUND_MIXER_READ_STEREODEVS MIXER_READ(SOUND_MIXER_STEREODEVS) +#define SOUND_MIXER_READ_CAPS MIXER_READ(SOUND_MIXER_CAPS) + +#define MIXER_WRITE(dev) _IOWR('M', dev, int) +#define SOUND_MIXER_WRITE_VOLUME MIXER_WRITE(SOUND_MIXER_VOLUME) +#define SOUND_MIXER_WRITE_BASS MIXER_WRITE(SOUND_MIXER_BASS) +#define SOUND_MIXER_WRITE_TREBLE MIXER_WRITE(SOUND_MIXER_TREBLE) +#define SOUND_MIXER_WRITE_SYNTH MIXER_WRITE(SOUND_MIXER_SYNTH) +#define SOUND_MIXER_WRITE_PCM MIXER_WRITE(SOUND_MIXER_PCM) +#define SOUND_MIXER_WRITE_SPEAKER MIXER_WRITE(SOUND_MIXER_SPEAKER) +#define SOUND_MIXER_WRITE_LINE MIXER_WRITE(SOUND_MIXER_LINE) +#define SOUND_MIXER_WRITE_MIC MIXER_WRITE(SOUND_MIXER_MIC) +#define SOUND_MIXER_WRITE_CD MIXER_WRITE(SOUND_MIXER_CD) +#define SOUND_MIXER_WRITE_IMIX MIXER_WRITE(SOUND_MIXER_IMIX) +#define SOUND_MIXER_WRITE_ALTPCM MIXER_WRITE(SOUND_MIXER_ALTPCM) +#define SOUND_MIXER_WRITE_RECLEV MIXER_WRITE(SOUND_MIXER_RECLEV) +#define SOUND_MIXER_WRITE_IGAIN MIXER_WRITE(SOUND_MIXER_IGAIN) +#define SOUND_MIXER_WRITE_OGAIN MIXER_WRITE(SOUND_MIXER_OGAIN) +#define SOUND_MIXER_WRITE_LINE1 MIXER_WRITE(SOUND_MIXER_LINE1) +#define SOUND_MIXER_WRITE_LINE2 MIXER_WRITE(SOUND_MIXER_LINE2) +#define SOUND_MIXER_WRITE_LINE3 MIXER_WRITE(SOUND_MIXER_LINE3) +#define SOUND_MIXER_WRITE_DIGITAL1 MIXER_WRITE(SOUND_MIXER_DIGITAL1) +#define SOUND_MIXER_WRITE_DIGITAL2 MIXER_WRITE(SOUND_MIXER_DIGITAL2) +#define SOUND_MIXER_WRITE_DIGITAL3 MIXER_WRITE(SOUND_MIXER_DIGITAL3) +#define SOUND_MIXER_WRITE_PHONEIN MIXER_WRITE(SOUND_MIXER_PHONEIN) +#define SOUND_MIXER_WRITE_PHONEOUT MIXER_WRITE(SOUND_MIXER_PHONEOUT) +#define SOUND_MIXER_WRITE_RADIO MIXER_WRITE(SOUND_MIXER_RADIO) +#define SOUND_MIXER_WRITE_VIDEO MIXER_WRITE(SOUND_MIXER_VIDEO) +#define SOUND_MIXER_WRITE_MONITOR MIXER_WRITE(SOUND_MIXER_MONITOR) + +#define SOUND_MIXER_WRITE_MUTE MIXER_WRITE(SOUND_MIXER_MUTE) +#define SOUND_MIXER_WRITE_ENHANCE MIXER_WRITE(SOUND_MIXER_ENHANCE) +#define SOUND_MIXER_WRITE_LOUD MIXER_WRITE(SOUND_MIXER_LOUD) + +#define SOUND_MIXER_WRITE_RECSRC MIXER_WRITE(SOUND_MIXER_RECSRC) + +typedef struct mixer_info { + char id[16]; + char name[32]; + int modify_counter; + int fillers[10]; +} mixer_info; + +#define SOUND_MIXER_INFO _IOR('M', 101, mixer_info) + +#define LEFT_CHN 0 +#define RIGHT_CHN 1 + +/* + * Level 2 event types for /dev/sequencer + */ + +/* + * The 4 most significant bits of byte 0 specify the class of + * the event: + * + * 0x8X = system level events, + * 0x9X = device/port specific events, event[1] = device/port, + * The last 4 bits give the subtype: + * 0x02 = Channel event (event[3] = chn). + * 0x01 = note event (event[4] = note). + * (0x01 is not used alone but always with bit 0x02). + * event[2] = MIDI message code (0x80=note off etc.) + * + */ + +#define EV_SEQ_LOCAL 0x80 +#define EV_TIMING 0x81 +#define EV_CHN_COMMON 0x92 +#define EV_CHN_VOICE 0x93 +#define EV_SYSEX 0x94 +/* + * Event types 200 to 220 are reserved for application use. + * These numbers will not be used by the driver. + */ + +/* + * Events for event type EV_CHN_VOICE + */ + +#define MIDI_NOTEOFF 0x80 +#define MIDI_NOTEON 0x90 +#define MIDI_KEY_PRESSURE 0xA0 + +/* + * Events for event type EV_CHN_COMMON + */ + +#define MIDI_CTL_CHANGE 0xB0 +#define MIDI_PGM_CHANGE 0xC0 +#define MIDI_CHN_PRESSURE 0xD0 +#define MIDI_PITCH_BEND 0xE0 + +#define MIDI_SYSTEM_PREFIX 0xF0 + +/* + * Timer event types + */ +#define TMR_WAIT_REL 1 /* Time relative to the prev time */ +#define TMR_WAIT_ABS 2 /* Absolute time since TMR_START */ +#define TMR_STOP 3 +#define TMR_START 4 +#define TMR_CONTINUE 5 +#define TMR_TEMPO 6 +#define TMR_ECHO 8 +#define TMR_CLOCK 9 /* MIDI clock */ +#define TMR_SPP 10 /* Song position pointer */ +#define TMR_TIMESIG 11 /* Time signature */ + +/* + * Local event types + */ +#define LOCL_STARTAUDIO 1 + +#if (!defined(_KERNEL) && !defined(INKERNEL)) || defined(USE_SEQ_MACROS) +/* + * Some convenience macros to simplify programming of the + * /dev/sequencer interface + * + * These macros define the API which should be used when possible. + */ + +#ifndef USE_SIMPLE_MACROS +void seqbuf_dump(void); /* This function must be provided by programs */ + +/* Sample seqbuf_dump() implementation: + * + * SEQ_DEFINEBUF (2048); -- Defines a buffer for 2048 bytes + * + * int seqfd; -- The file descriptor for /dev/sequencer. + * + * void + * seqbuf_dump () + * { + * if (_seqbufptr) + * if (write (seqfd, _seqbuf, _seqbufptr) == -1) + * { + * perror ("write /dev/sequencer"); + * exit (-1); + * } + * _seqbufptr = 0; + * } + */ + +#define SEQ_DEFINEBUF(len) \ + u_char _seqbuf[len]; int _seqbuflen = len;int _seqbufptr = 0 +#define SEQ_USE_EXTBUF() \ + extern u_char _seqbuf[]; \ + extern int _seqbuflen;extern int _seqbufptr +#define SEQ_DECLAREBUF() SEQ_USE_EXTBUF() +#define SEQ_PM_DEFINES struct patmgr_info _pm_info +#define _SEQ_NEEDBUF(len) \ + if ((_seqbufptr+(len)) > _seqbuflen) \ + seqbuf_dump() +#define _SEQ_ADVBUF(len) _seqbufptr += len +#define SEQ_DUMPBUF seqbuf_dump +#else +/* + * This variation of the sequencer macros is used just to format one event + * using fixed buffer. + * + * The program using the macro library must define the following macros before + * using this library. + * + * #define _seqbuf name of the buffer (u_char[]) + * #define _SEQ_ADVBUF(len) If the applic needs to know the exact + * size of the event, this macro can be used. + * Otherwise this must be defined as empty. + * #define _seqbufptr Define the name of index variable or 0 if + * not required. + */ +#define _SEQ_NEEDBUF(len) /* empty */ +#endif + +#define PM_LOAD_PATCH(dev, bank, pgm) \ + (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \ + _pm_info.device=dev, _pm_info.data.data8[0]=pgm, \ + _pm_info.parm1 = bank, _pm_info.parm2 = 1, \ + ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info)) +#define PM_LOAD_PATCHES(dev, bank, pgm) \ + (SEQ_DUMPBUF(), _pm_info.command = _PM_LOAD_PATCH, \ + _pm_info.device=dev, bcopy( pgm, _pm_info.data.data8, 128), \ + _pm_info.parm1 = bank, _pm_info.parm2 = 128, \ + ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info)) + +#define SEQ_VOLUME_MODE(dev, mode) { \ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = SEQ_EXTENDED;\ + _seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\ + _seqbuf[_seqbufptr+2] = (dev);\ + _seqbuf[_seqbufptr+3] = (mode);\ + _seqbuf[_seqbufptr+4] = 0;\ + _seqbuf[_seqbufptr+5] = 0;\ + _seqbuf[_seqbufptr+6] = 0;\ + _seqbuf[_seqbufptr+7] = 0;\ + _SEQ_ADVBUF(8);} + +/* + * Midi voice messages + */ + +#define _CHN_VOICE(dev, event, chn, note, parm) { \ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = EV_CHN_VOICE;\ + _seqbuf[_seqbufptr+1] = (dev);\ + _seqbuf[_seqbufptr+2] = (event);\ + _seqbuf[_seqbufptr+3] = (chn);\ + _seqbuf[_seqbufptr+4] = (note);\ + _seqbuf[_seqbufptr+5] = (parm);\ + _seqbuf[_seqbufptr+6] = (0);\ + _seqbuf[_seqbufptr+7] = 0;\ + _SEQ_ADVBUF(8);} + +#define SEQ_START_NOTE(dev, chn, note, vol) \ + _CHN_VOICE(dev, MIDI_NOTEON, chn, note, vol) + +#define SEQ_STOP_NOTE(dev, chn, note, vol) \ + _CHN_VOICE(dev, MIDI_NOTEOFF, chn, note, vol) + +#define SEQ_KEY_PRESSURE(dev, chn, note, pressure) \ + _CHN_VOICE(dev, MIDI_KEY_PRESSURE, chn, note, pressure) + +/* + * Midi channel messages + */ + +#define _CHN_COMMON(dev, event, chn, p1, p2, w14) { \ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = EV_CHN_COMMON;\ + _seqbuf[_seqbufptr+1] = (dev);\ + _seqbuf[_seqbufptr+2] = (event);\ + _seqbuf[_seqbufptr+3] = (chn);\ + _seqbuf[_seqbufptr+4] = (p1);\ + _seqbuf[_seqbufptr+5] = (p2);\ + *(short *)&_seqbuf[_seqbufptr+6] = (w14);\ + _SEQ_ADVBUF(8);} +/* + * SEQ_SYSEX permits sending of sysex messages. (It may look that it permits + * sending any MIDI bytes but it's absolutely not possible. Trying to do + * so _will_ cause problems with MPU401 intelligent mode). + * + * Sysex messages are sent in blocks of 1 to 6 bytes. Longer messages must be + * sent by calling SEQ_SYSEX() several times (there must be no other events + * between them). First sysex fragment must have 0xf0 in the first byte + * and the last byte (buf[len-1] of the last fragment must be 0xf7. No byte + * between these sysex start and end markers cannot be larger than 0x7f. Also + * lengths of each fragments (except the last one) must be 6. + * + * Breaking the above rules may work with some MIDI ports but is likely to + * cause fatal problems with some other devices (such as MPU401). + */ +#define SEQ_SYSEX(dev, buf, len) { \ + int i, l=(len); if (l>6)l=6;\ + _SEQ_NEEDBUF(8);\ + _seqbuf[_seqbufptr] = EV_SYSEX;\ + for(i=0;i +#include + +/* XXX missing blkcnt_t, blksize_t. */ + +#ifndef _DEV_T_DECLARED +typedef __dev_t dev_t; +#define _DEV_T_DECLARED +#endif + +#ifndef _FFLAGS_T_DECLARED +typedef __fflags_t fflags_t; +#define _FFLAGS_T_DECLARED +#endif + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _INO_T_DECLARED +typedef __ino_t ino_t; +#define _INO_T_DECLARED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; +#define _MODE_T_DECLARED +#endif + +#ifndef _NLINK_T_DECLARED +typedef __nlink_t nlink_t; +#define _NLINK_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#if !defined(_KERNEL) && __BSD_VISIBLE +/* + * XXX we need this for struct timespec. We get miscellaneous namespace + * pollution with it. + */ +#include +#endif + +#if !__BSD_VISIBLE +#include +#endif + +#if __BSD_VISIBLE +struct ostat { + __uint16_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + mode_t st_mode; /* inode protection mode */ + nlink_t st_nlink; /* number of hard links */ + __uint16_t st_uid; /* user ID of the file's owner */ + __uint16_t st_gid; /* group ID of the file's group */ + __uint16_t st_rdev; /* device type */ + __int32_t st_size; /* file size, in bytes */ + struct timespec st_atimespec; /* time of last access */ + struct timespec st_mtimespec; /* time of last data modification */ + struct timespec st_ctimespec; /* time of last file status change */ + __int32_t st_blksize; /* optimal blocksize for I/O */ + __int32_t st_blocks; /* blocks allocated for file */ + fflags_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ +}; +#endif /* __BSD_VISIBLE */ + +struct stat { + __udev_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + mode_t st_mode; /* inode protection mode */ + nlink_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + __udev_t st_rdev; /* device type */ +#if __BSD_VISIBLE + struct timespec st_atimespec; /* time of last access */ + struct timespec st_mtimespec; /* time of last data modification */ + struct timespec st_ctimespec; /* time of last file status change */ +#else + time_t st_atime; /* time of last access */ + long st_atimensec; /* nsec of last access */ + time_t st_mtime; /* time of last data modification */ + long st_mtimensec; /* nsec of last data modification */ + time_t st_ctime; /* time of last file status change */ + long st_ctimensec; /* nsec of last file status change */ +#endif + off_t st_size; /* file size, in bytes */ + __int64_t st_blocks; /* blocks allocated for file */ + __uint32_t st_blksize; /* optimal blocksize for I/O */ + fflags_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ + __int32_t st_lspare; +#if __BSD_VISIBLE + struct timespec st_birthtimespec; /* time of file creation */ + /* + * Explicitly pad st_birthtimespec to 16 bytes so that the size of + * struct stat is backwards compatible. We use bitfields instead + * of an array of chars so that this doesn't require a C99 compiler + * to compile if the size of the padding is 0. We use 2 bitfields + * to cover up to 64 bits on 32-bit machines. We assume that + * CHAR_BIT is 8... + */ + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); +#else + time_t st_birthtime; /* time of file creation */ + long st_birthtimensec; /* nsec of file creation */ + unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec)); + unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec)); +#endif +}; + +#if __BSD_VISIBLE +struct nstat { + __udev_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + __uint32_t st_mode; /* inode protection mode */ + __uint32_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + __udev_t st_rdev; /* device type */ + struct timespec st_atimespec; /* time of last access */ + struct timespec st_mtimespec; /* time of last data modification */ + struct timespec st_ctimespec; /* time of last file status change */ + off_t st_size; /* file size, in bytes */ + __int64_t st_blocks; /* blocks allocated for file */ + __uint32_t st_blksize; /* optimal blocksize for I/O */ + fflags_t st_flags; /* user defined flags for file */ + __uint32_t st_gen; /* file generation number */ + struct timespec st_birthtimespec; /* time of file creation */ + /* + * See above about the following padding. + */ + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); + unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec)); +}; +#endif + +#if __BSD_VISIBLE +#define st_atime st_atimespec.tv_sec +#define st_mtime st_mtimespec.tv_sec +#define st_ctime st_ctimespec.tv_sec +#define st_birthtime st_birthtimespec.tv_sec +#endif + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#if __BSD_VISIBLE +#define S_ISTXT 0001000 /* sticky bit */ +#endif + +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ + +#if __BSD_VISIBLE +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#define S_IEXEC S_IXUSR +#endif + +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ + +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ + +#if __XSI_VISIBLE +#define S_IFMT 0170000 /* type of file mask */ +#define S_IFIFO 0010000 /* named pipe (fifo) */ +#define S_IFCHR 0020000 /* character special */ +#define S_IFDIR 0040000 /* directory */ +#define S_IFBLK 0060000 /* block special */ +#define S_IFREG 0100000 /* regular */ +#define S_IFLNK 0120000 /* symbolic link */ +#define S_IFSOCK 0140000 /* socket */ +#define S_ISVTX 0001000 /* save swapped text even after use */ +#endif +#if __BSD_VISIBLE +#define S_IFWHT 0160000 /* whiteout */ +#endif + +#define S_ISDIR(m) (((m) & 0170000) == 0040000) /* directory */ +#define S_ISCHR(m) (((m) & 0170000) == 0020000) /* char special */ +#define S_ISBLK(m) (((m) & 0170000) == 0060000) /* block special */ +#define S_ISREG(m) (((m) & 0170000) == 0100000) /* regular file */ +#define S_ISFIFO(m) (((m) & 0170000) == 0010000) /* fifo or socket */ +#if __POSIX_VISIBLE >= 200112 +#define S_ISLNK(m) (((m) & 0170000) == 0120000) /* symbolic link */ +#define S_ISSOCK(m) (((m) & 0170000) == 0140000) /* socket */ +#endif +#if __XSI_VISIBLE +#define S_ISWHT(m) (((m) & 0170000) == 0160000) /* whiteout */ +#endif + +#if __BSD_VISIBLE +#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */ + /* 7777 */ +#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) + /* 0666 */ +#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) + +#define S_BLKSIZE 512 /* block size used in the stat struct */ + +/* + * Definitions of flags stored in file flags word. + * + * Super-user and owner changeable flags. + */ +#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ +#define UF_NODUMP 0x00000001 /* do not dump file */ +#define UF_IMMUTABLE 0x00000002 /* file may not be changed */ +#define UF_APPEND 0x00000004 /* writes to file may only append */ +#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ +#define UF_NOUNLINK 0x00000010 /* file may not be removed or renamed */ +/* + * Super-user changeable flags. + */ +#define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ +#define SF_ARCHIVED 0x00010000 /* file is archived */ +#define SF_IMMUTABLE 0x00020000 /* file may not be changed */ +#define SF_APPEND 0x00040000 /* writes to file may only append */ +#define SF_NOUNLINK 0x00100000 /* file may not be removed or renamed */ +#define SF_SNAPSHOT 0x00200000 /* snapshot inode */ + +#ifdef _KERNEL +/* + * Shorthand abbreviations of above. + */ +#define OPAQUE (UF_OPAQUE) +#define APPEND (UF_APPEND | SF_APPEND) +#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) +#define NOUNLINK (UF_NOUNLINK | SF_NOUNLINK) +#endif + +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL +__BEGIN_DECLS +#if __BSD_VISIBLE +int chflags(const char *, unsigned long); +#endif +int chmod(const char *, mode_t); +#if __BSD_VISIBLE +int fchflags(int, unsigned long); +int fchmod(int, mode_t); +#endif +int fstat(int, struct stat *); +#if __BSD_VISIBLE +int lchflags(const char *, int); +int lchmod(const char *, mode_t); +#endif +#if __POSIX_VISIBLE >= 200112 +int lstat(const char *, struct stat *); +#endif +int mkdir(const char *, mode_t); +int mkfifo(const char *, mode_t); +int stat(const char *, struct stat *); +mode_t umask(mode_t); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_STAT_H_ */ diff --git a/src/include/sys/statvfs.h b/src/include/sys/statvfs.h new file mode 100644 index 0000000..cb73ffa --- /dev/null +++ b/src/include/sys/statvfs.h @@ -0,0 +1,81 @@ +/* + * Copyright 2002 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + * + * $FreeBSD: src/sys/sys/statvfs.h,v 1.3 2002/08/21 16:20:01 mike Exp $ + */ + +#ifndef _SYS_STATVFS_H_ +#define _SYS_STATVFS_H_ + +#include +#include + +/* + * POSIX says we must define the fsblkcnt_t and fsfilcnt_t types here. + * Note that these must be unsigned integer types, so we have to be + * careful in converting the signed statfs members to the unsigned + * statvfs members. (Well, actually, we don't -- see below -- but + * a quality implementation should.) + */ +#ifndef _FSBLKCNT_T_DECLARED /* always declared together */ +typedef __fsblkcnt_t fsblkcnt_t; +typedef __fsfilcnt_t fsfilcnt_t; +#define _FSBLKCNT_T_DECLARED +#endif + +/* + * The difference between `avail' and `free' is that `avail' represents + * space available to unprivileged processes, whereas `free' includes all + * unallocated space, including that reserved for privileged processes. + * Or at least, that's the most useful interpretation. (According to + * the letter of the standard, this entire interface is completely + * unspecified!) + */ +struct statvfs { + fsblkcnt_t f_bavail; /* Number of blocks */ + fsblkcnt_t f_bfree; + fsblkcnt_t f_blocks; + fsfilcnt_t f_favail; /* Number of files (e.g., inodes) */ + fsfilcnt_t f_ffree; + fsfilcnt_t f_files; + unsigned long f_bsize; /* Size of blocks counted above */ + unsigned long f_flag; + unsigned long f_frsize; /* Size of fragments */ + unsigned long f_fsid; /* Not meaningful */ + unsigned long f_namemax; /* Same as pathconf(_PC_NAME_MAX) */ +}; + +/* flag bits for f_flag: */ +#define ST_RDONLY 0x1 +#define ST_NOSUID 0x2 + +__BEGIN_DECLS +int fstatvfs(int, struct statvfs *); +int statvfs(const char *__restrict, struct statvfs *__restrict); +__END_DECLS +#endif /* _SYS_STATVFS_H_ */ diff --git a/src/include/sys/stddef.h b/src/include/sys/stddef.h new file mode 100644 index 0000000..3e0b15d --- /dev/null +++ b/src/include/sys/stddef.h @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2002 Maxime Henrion + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/stddef.h,v 1.2 2003/12/07 21:10:06 marcel Exp $ + */ + +#ifndef _SYS_STDDEF_H_ +#define _SYS_STDDEF_H_ + +#include +#include +#include + +typedef __ptrdiff_t ptrdiff_t; + +#define offsetof(type, field) __offsetof(type, field) + +#endif /* !_SYS_STDDEF_H_ */ diff --git a/src/include/sys/stdint.h b/src/include/sys/stdint.h new file mode 100644 index 0000000..b0d6632 --- /dev/null +++ b/src/include/sys/stdint.h @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/stdint.h,v 1.4 2002/08/21 16:20:01 mike Exp $ + */ + +#ifndef _SYS_STDINT_H_ +#define _SYS_STDINT_H_ + +#include +#include + +#include + +#ifndef _INT8_T_DECLARED +typedef __int8_t int8_t; +#define _INT8_T_DECLARED +#endif + +#ifndef _INT16_T_DECLARED +typedef __int16_t int16_t; +#define _INT16_T_DECLARED +#endif + +#ifndef _INT32_T_DECLARED +typedef __int32_t int32_t; +#define _INT32_T_DECLARED +#endif + +#ifndef _INT64_T_DECLARED +typedef __int64_t int64_t; +#define _INT64_T_DECLARED +#endif + +#ifndef _UINT8_T_DECLARED +typedef __uint8_t uint8_t; +#define _UINT8_T_DECLARED +#endif + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif + +typedef __int_least8_t int_least8_t; +typedef __int_least16_t int_least16_t; +typedef __int_least32_t int_least32_t; +typedef __int_least64_t int_least64_t; + +typedef __uint_least8_t uint_least8_t; +typedef __uint_least16_t uint_least16_t; +typedef __uint_least32_t uint_least32_t; +typedef __uint_least64_t uint_least64_t; + +typedef __int_fast8_t int_fast8_t; +typedef __int_fast16_t int_fast16_t; +typedef __int_fast32_t int_fast32_t; +typedef __int_fast64_t int_fast64_t; + +typedef __uint_fast8_t uint_fast8_t; +typedef __uint_fast16_t uint_fast16_t; +typedef __uint_fast32_t uint_fast32_t; +typedef __uint_fast64_t uint_fast64_t; + +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + +#ifndef _INTPTR_T_DECLARED +typedef __intptr_t intptr_t; +typedef __uintptr_t uintptr_t; +#define _INTPTR_T_DECLARED +#endif + +#endif /* !_SYS_STDINT_H_ */ diff --git a/src/include/sys/sun_disklabel.h b/src/include/sys/sun_disklabel.h new file mode 100644 index 0000000..e004938 --- /dev/null +++ b/src/include/sys/sun_disklabel.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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. + * 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. + * + * @(#)sun_disklabel.h 8.1 (Berkeley) 6/11/93 + * $NetBSD: disklabel.h,v 1.2 1998/08/22 14:55:28 mrg Exp $ + * + * $FreeBSD: src/sys/sys/sun_disklabel.h,v 1.8 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SUN_DISKLABEL_H_ +#define _SYS_SUN_DISKLABEL_H_ + +/* + * SunOS/Solaris disk label layout (partial). + * + * Suns disk label format contains a lot of historical baggage which we + * ignore entirely. The structure below contains the relevant bits and the + * _enc/_dec functions encode/decode only these fields. + */ + +#define SUN_DKMAGIC 55998 +#define SUN_NPART 8 +#define SUN_RAWPART 2 +#define SUN_SIZE 512 +/* + * XXX: I am actually not sure if this should be "16 sectors" or "8192 bytes". + * XXX: Considering that Sun went to the effort of getting 512 byte compatible + * XXX: CDROM drives produced my guess is that Sun computers stand little or + * XXX: even no chance of running, much less booting on !=512 byte media. + * XXX: Define this is in terms of bytes since that is easier for us. + */ +#define SUN_BOOTSIZE 8192 + +/* partition info */ +struct sun_dkpart { + u_int32_t sdkp_cyloffset; /* starting cylinder */ + u_int32_t sdkp_nsectors; /* number of sectors */ +}; + +struct sun_disklabel { + char sl_text[128]; + u_int16_t sl_rpm; /* rotational speed */ + u_int16_t sl_pcylinders; /* number of physical cyls */ + u_int16_t sl_sparespercyl; /* spare sectors per cylinder */ + u_int16_t sl_interleave; /* interleave factor */ + u_int16_t sl_ncylinders; /* data cylinders */ + u_int16_t sl_acylinders; /* alternate cylinders */ + u_int16_t sl_ntracks; /* tracks per cylinder */ + u_int16_t sl_nsectors; /* sectors per track */ + struct sun_dkpart sl_part[SUN_NPART]; /* partition layout */ + u_int16_t sl_magic; /* == SUN_DKMAGIC */ +}; + +int sunlabel_dec(void const *pp, struct sun_disklabel *sl); +void sunlabel_enc(void *pp, struct sun_disklabel *sl); + +#endif /* _SYS_SUN_DISKLABEL_H_ */ diff --git a/src/include/sys/sx.h b/src/include/sys/sx.h new file mode 100644 index 0000000..f83d4a8 --- /dev/null +++ b/src/include/sys/sx.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2001 Jason Evans . 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD: src/sys/sys/sx.h,v 1.19 2004/02/04 14:18:21 bde Exp $ + */ + +#ifndef _SYS_SX_H_ +#define _SYS_SX_H_ + +#include +#include +#include /* XXX */ + +struct sx { + struct lock_object sx_object; /* Common lock properties. */ + struct mtx *sx_lock; /* General protection lock. */ + int sx_cnt; /* -1: xlock, > 0: slock count. */ + struct cv sx_shrd_cv; /* slock waiters. */ + int sx_shrd_wcnt; /* Number of slock waiters. */ + struct cv sx_excl_cv; /* xlock waiters. */ + int sx_excl_wcnt; /* Number of xlock waiters. */ + struct thread *sx_xholder; /* Thread presently holding xlock. */ +}; + +#ifdef _KERNEL +void sx_sysinit(void *arg); +void sx_init(struct sx *sx, const char *description); +void sx_destroy(struct sx *sx); +void _sx_slock(struct sx *sx, const char *file, int line); +void _sx_xlock(struct sx *sx, const char *file, int line); +int _sx_try_slock(struct sx *sx, const char *file, int line); +int _sx_try_xlock(struct sx *sx, const char *file, int line); +void _sx_sunlock(struct sx *sx, const char *file, int line); +void _sx_xunlock(struct sx *sx, const char *file, int line); +int _sx_try_upgrade(struct sx *sx, const char *file, int line); +void _sx_downgrade(struct sx *sx, const char *file, int line); +#ifdef INVARIANT_SUPPORT +void _sx_assert(struct sx *sx, int what, const char *file, int line); +#endif + +struct sx_args { + struct sx *sa_sx; + const char *sa_desc; +}; + +#define SX_SYSINIT(name, sxa, desc) \ + static struct sx_args name##_args = { \ + sxa, \ + desc \ + }; \ + SYSINIT(name##_sx_sysinit, SI_SUB_LOCK, SI_ORDER_MIDDLE, \ + sx_sysinit, &name##_args) + +#define sx_slock(sx) _sx_slock((sx), LOCK_FILE, LOCK_LINE) +#define sx_xlock(sx) _sx_xlock((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_slock(sx) _sx_try_slock((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_xlock(sx) _sx_try_xlock((sx), LOCK_FILE, LOCK_LINE) +#define sx_sunlock(sx) _sx_sunlock((sx), LOCK_FILE, LOCK_LINE) +#define sx_xunlock(sx) _sx_xunlock((sx), LOCK_FILE, LOCK_LINE) +#define sx_try_upgrade(sx) _sx_try_upgrade((sx), LOCK_FILE, LOCK_LINE) +#define sx_downgrade(sx) _sx_downgrade((sx), LOCK_FILE, LOCK_LINE) + +#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT) +#define SX_LOCKED LA_LOCKED +#define SX_SLOCKED LA_SLOCKED +#define SX_XLOCKED LA_XLOCKED +#define SX_UNLOCKED LA_UNLOCKED +#endif + +#ifdef INVARIANTS +#define sx_assert(sx, what) _sx_assert((sx), (what), LOCK_FILE, LOCK_LINE) +#else +#define sx_assert(sx, what) +#endif + +#endif /* _KERNEL */ + +#endif /* !_SYS_SX_H_ */ diff --git a/src/include/sys/sys.h b/src/include/sys/sys.h new file mode 100644 index 0000000..19ee01f --- /dev/null +++ b/src/include/sys/sys.h @@ -0,0 +1,35 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _SYS_H +#define _SYS_H + +int exec(char *,int argc,char **argv); +int pidStatus(int pid); +void *getPage(int count); +void *getDrives(); +int getuptime(); +int gettime(); +int startSDE(); + +#endif diff --git a/src/include/sys/syscall.h b/src/include/sys/syscall.h new file mode 100644 index 0000000..5966a50 --- /dev/null +++ b/src/include/sys/syscall.h @@ -0,0 +1,359 @@ +/* + * System call numbers. + * + * DO NOT EDIT-- this file is automatically generated. + * $FreeBSD: src/sys/sys/syscall.h,v 1.154 2004/04/05 10:16:38 dfr Exp $ + * created from FreeBSD: src/sys/kern/syscalls.master,v 1.171 2004/04/05 10:15:53 dfr Exp + */ + +#define SYS_syscall 0 +#define SYS_exit 1 +#define SYS_fork 2 +#define SYS_read 3 +#define SYS_write 4 +#define SYS_open 5 +#define SYS_close 6 +#define SYS_wait4 7 + /* 8 is old creat */ +#define SYS_link 9 +#define SYS_unlink 10 + /* 11 is obsolete execv */ +#define SYS_chdir 12 +#define SYS_fchdir 13 +#define SYS_mknod 14 +#define SYS_chmod 15 +#define SYS_chown 16 +#define SYS_break 17 + /* 18 is old getfsstat */ + /* 19 is old lseek */ +#define SYS_getpid 20 +#define SYS_mount 21 +#define SYS_unmount 22 +#define SYS_setuid 23 +#define SYS_getuid 24 +#define SYS_geteuid 25 +#define SYS_ptrace 26 +#define SYS_recvmsg 27 +#define SYS_sendmsg 28 +#define SYS_recvfrom 29 +#define SYS_accept 30 +#define SYS_getpeername 31 +#define SYS_getsockname 32 +#define SYS_access 33 +#define SYS_chflags 34 +#define SYS_fchflags 35 +#define SYS_sync 36 +#define SYS_kill 37 + /* 38 is old stat */ +#define SYS_getppid 39 + /* 40 is old lstat */ +#define SYS_dup 41 +#define SYS_pipe 42 +#define SYS_getegid 43 +#define SYS_profil 44 +#define SYS_ktrace 45 + /* 46 is old sigaction */ +#define SYS_getgid 47 + /* 48 is old sigprocmask */ +#define SYS_getlogin 49 +#define SYS_setlogin 50 +#define SYS_acct 51 + /* 52 is old sigpending */ +#define SYS_sigaltstack 53 +#define SYS_ioctl 54 +#define SYS_reboot 55 +#define SYS_revoke 56 +#define SYS_symlink 57 +#define SYS_readlink 58 +#define SYS_execve 59 +#define SYS_umask 60 +#define SYS_chroot 61 + /* 62 is old fstat */ + /* 63 is old getkerninfo */ + /* 64 is old getpagesize */ +#define SYS_msync 65 +#define SYS_vfork 66 + /* 67 is obsolete vread */ + /* 68 is obsolete vwrite */ +#define SYS_sbrk 69 +#define SYS_sstk 70 + /* 71 is old mmap */ +#define SYS_vadvise 72 +#define SYS_munmap 73 +#define SYS_mprotect 74 +#define SYS_madvise 75 + /* 76 is obsolete vhangup */ + /* 77 is obsolete vlimit */ +#define SYS_mincore 78 +#define SYS_getgroups 79 +#define SYS_setgroups 80 +#define SYS_getpgrp 81 +#define SYS_setpgid 82 +#define SYS_setitimer 83 + /* 84 is old wait */ +#define SYS_swapon 85 +#define SYS_getitimer 86 + /* 87 is old gethostname */ + /* 88 is old sethostname */ +#define SYS_getdtablesize 89 +#define SYS_dup2 90 +#define SYS_fcntl 92 +#define SYS_select 93 +#define SYS_fsync 95 +#define SYS_setpriority 96 +#define SYS_socket 97 +#define SYS_connect 98 + /* 99 is old accept */ +#define SYS_getpriority 100 + /* 101 is old send */ + /* 102 is old recv */ + /* 103 is old sigreturn */ +#define SYS_bind 104 +#define SYS_setsockopt 105 +#define SYS_listen 106 + /* 107 is obsolete vtimes */ + /* 108 is old sigvec */ + /* 109 is old sigblock */ + /* 110 is old sigsetmask */ + /* 111 is old sigsuspend */ + /* 112 is old sigstack */ + /* 113 is old recvmsg */ + /* 114 is old sendmsg */ + /* 115 is obsolete vtrace */ +#define SYS_gettimeofday 116 +#define SYS_getrusage 117 +#define SYS_getsockopt 118 +#define SYS_readv 120 +#define SYS_writev 121 +#define SYS_settimeofday 122 +#define SYS_fchown 123 +#define SYS_fchmod 124 + /* 125 is old recvfrom */ +#define SYS_setreuid 126 +#define SYS_setregid 127 +#define SYS_rename 128 + /* 129 is old truncate */ + /* 130 is old ftruncate */ +#define SYS_flock 131 +#define SYS_mkfifo 132 +#define SYS_sendto 133 +#define SYS_shutdown 134 +#define SYS_socketpair 135 +#define SYS_mkdir 136 +#define SYS_rmdir 137 +#define SYS_utimes 138 + /* 139 is obsolete 4.2 sigreturn */ +#define SYS_adjtime 140 + /* 141 is old getpeername */ + /* 142 is old gethostid */ + /* 143 is old sethostid */ + /* 144 is old getrlimit */ + /* 145 is old setrlimit */ + /* 146 is old killpg */ +#define SYS_setsid 147 +#define SYS_quotactl 148 + /* 149 is old quota */ + /* 150 is old getsockname */ +#define SYS_nfssvc 155 + /* 156 is old getdirentries */ + /* 157 is old statfs */ + /* 158 is old fstatfs */ +#define SYS_lgetfh 160 +#define SYS_getfh 161 +#define SYS_getdomainname 162 +#define SYS_setdomainname 163 +#define SYS_uname 164 +#define SYS_sysarch 165 +#define SYS_rtprio 166 +#define SYS_semsys 169 +#define SYS_msgsys 170 +#define SYS_shmsys 171 +#define SYS_pread 173 +#define SYS_pwrite 174 +#define SYS_ntp_adjtime 176 +#define SYS_setgid 181 +#define SYS_setegid 182 +#define SYS_seteuid 183 +#define SYS_stat 188 +#define SYS_fstat 189 +#define SYS_lstat 190 +#define SYS_pathconf 191 +#define SYS_fpathconf 192 +#define SYS_getrlimit 194 +#define SYS_setrlimit 195 +#define SYS_getdirentries 196 +#define SYS_mmap 197 +#define SYS___syscall 198 +#define SYS_lseek 199 +#define SYS_truncate 200 +#define SYS_ftruncate 201 +#define SYS___sysctl 202 +#define SYS_mlock 203 +#define SYS_munlock 204 +#define SYS_undelete 205 +#define SYS_futimes 206 +#define SYS_getpgid 207 +#define SYS_poll 209 +#define SYS___semctl 220 +#define SYS_semget 221 +#define SYS_semop 222 +#define SYS_msgctl 224 +#define SYS_msgget 225 +#define SYS_msgsnd 226 +#define SYS_msgrcv 227 +#define SYS_shmat 228 +#define SYS_shmctl 229 +#define SYS_shmdt 230 +#define SYS_shmget 231 +#define SYS_clock_gettime 232 +#define SYS_clock_settime 233 +#define SYS_clock_getres 234 +#define SYS_nanosleep 240 +#define SYS_minherit 250 +#define SYS_rfork 251 +#define SYS_openbsd_poll 252 +#define SYS_issetugid 253 +#define SYS_lchown 254 +#define SYS_getdents 272 +#define SYS_lchmod 274 +#define SYS_netbsd_lchown 275 +#define SYS_lutimes 276 +#define SYS_netbsd_msync 277 +#define SYS_nstat 278 +#define SYS_nfstat 279 +#define SYS_nlstat 280 + /* 297 is old fhstatfs */ +#define SYS_fhopen 298 +#define SYS_fhstat 299 +#define SYS_modnext 300 +#define SYS_modstat 301 +#define SYS_modfnext 302 +#define SYS_modfind 303 +#define SYS_kldload 304 +#define SYS_kldunload 305 +#define SYS_kldfind 306 +#define SYS_kldnext 307 +#define SYS_kldstat 308 +#define SYS_kldfirstmod 309 +#define SYS_getsid 310 +#define SYS_setresuid 311 +#define SYS_setresgid 312 + /* 313 is obsolete signanosleep */ +#define SYS_aio_return 314 +#define SYS_aio_suspend 315 +#define SYS_aio_cancel 316 +#define SYS_aio_error 317 +#define SYS_aio_read 318 +#define SYS_aio_write 319 +#define SYS_lio_listio 320 +#define SYS_yield 321 + /* 322 is obsolete thr_sleep */ + /* 323 is obsolete thr_wakeup */ +#define SYS_mlockall 324 +#define SYS_munlockall 325 +#define SYS___getcwd 326 +#define SYS_sched_setparam 327 +#define SYS_sched_getparam 328 +#define SYS_sched_setscheduler 329 +#define SYS_sched_getscheduler 330 +#define SYS_sched_yield 331 +#define SYS_sched_get_priority_max 332 +#define SYS_sched_get_priority_min 333 +#define SYS_sched_rr_get_interval 334 +#define SYS_utrace 335 + /* 336 is old sendfile */ +#define SYS_kldsym 337 +#define SYS_jail 338 +#define SYS_sigprocmask 340 +#define SYS_sigsuspend 341 + /* 342 is old sigaction */ +#define SYS_sigpending 343 + /* 344 is old sigreturn */ +#define SYS_sigtimedwait 345 +#define SYS_sigwaitinfo 346 +#define SYS___acl_get_file 347 +#define SYS___acl_set_file 348 +#define SYS___acl_get_fd 349 +#define SYS___acl_set_fd 350 +#define SYS___acl_delete_file 351 +#define SYS___acl_delete_fd 352 +#define SYS___acl_aclcheck_file 353 +#define SYS___acl_aclcheck_fd 354 +#define SYS_extattrctl 355 +#define SYS_extattr_set_file 356 +#define SYS_extattr_get_file 357 +#define SYS_extattr_delete_file 358 +#define SYS_aio_waitcomplete 359 +#define SYS_getresuid 360 +#define SYS_getresgid 361 +#define SYS_kqueue 362 +#define SYS_kevent 363 +#define SYS_extattr_set_fd 371 +#define SYS_extattr_get_fd 372 +#define SYS_extattr_delete_fd 373 +#define SYS___setugid 374 +#define SYS_nfsclnt 375 +#define SYS_eaccess 376 +#define SYS_nmount 378 +#define SYS_kse_exit 379 +#define SYS_kse_wakeup 380 +#define SYS_kse_create 381 +#define SYS_kse_thr_interrupt 382 +#define SYS_kse_release 383 +#define SYS___mac_get_proc 384 +#define SYS___mac_set_proc 385 +#define SYS___mac_get_fd 386 +#define SYS___mac_get_file 387 +#define SYS___mac_set_fd 388 +#define SYS___mac_set_file 389 +#define SYS_kenv 390 +#define SYS_lchflags 391 +#define SYS_uuidgen 392 +#define SYS_sendfile 393 +#define SYS_mac_syscall 394 +#define SYS_getfsstat 395 +#define SYS_statfs 396 +#define SYS_fstatfs 397 +#define SYS_fhstatfs 398 +#define SYS_ksem_close 400 +#define SYS_ksem_post 401 +#define SYS_ksem_wait 402 +#define SYS_ksem_trywait 403 +#define SYS_ksem_init 404 +#define SYS_ksem_open 405 +#define SYS_ksem_unlink 406 +#define SYS_ksem_getvalue 407 +#define SYS_ksem_destroy 408 +#define SYS___mac_get_pid 409 +#define SYS___mac_get_link 410 +#define SYS___mac_set_link 411 +#define SYS_extattr_set_link 412 +#define SYS_extattr_get_link 413 +#define SYS_extattr_delete_link 414 +#define SYS___mac_execve 415 +#define SYS_sigaction 416 +#define SYS_sigreturn 417 +#define SYS_getcontext 421 +#define SYS_setcontext 422 +#define SYS_swapcontext 423 +#define SYS_swapoff 424 +#define SYS___acl_get_link 425 +#define SYS___acl_set_link 426 +#define SYS___acl_delete_link 427 +#define SYS___acl_aclcheck_link 428 +#define SYS_sigwait 429 +#define SYS_thr_create 430 +#define SYS_thr_exit 431 +#define SYS_thr_self 432 +#define SYS_thr_kill 433 +#define SYS__umtx_lock 434 +#define SYS__umtx_unlock 435 +#define SYS_jail_attach 436 +#define SYS_extattr_list_fd 437 +#define SYS_extattr_list_file 438 +#define SYS_extattr_list_link 439 +#define SYS_kse_switchin 440 +#define SYS_ksem_timedwait 441 +#define SYS_thr_suspend 442 +#define SYS_thr_wake 443 +#define SYS_MAXSYSCALL 444 diff --git a/src/include/sys/syscallsubr.h b/src/include/sys/syscallsubr.h new file mode 100644 index 0000000..1ec78f9 --- /dev/null +++ b/src/include/sys/syscallsubr.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2002 Ian Dowse. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/syscallsubr.h,v 1.10 2003/11/05 01:53:10 fjoe Exp $ + */ + +#ifndef _SYS_SYSCALLSUBR_H_ +#define _SYS_SYSCALLSUBR_H_ + +#include +#include + +struct sockaddr; +struct msghdr; +struct mbuf; + +int kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, + u_int buflen); +int kern_access(struct thread *td, char *path, enum uio_seg pathseg, + int flags); +int kern_bind(struct thread *td, int fd, struct sockaddr *sa); +int kern_chdir(struct thread *td, char *path, enum uio_seg pathseg); +int kern_chmod(struct thread *td, char *path, enum uio_seg pathseg, + int mode); +int kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int uid, + int gid); +int kern_connect(struct thread *td, int fd, struct sockaddr *sa); +int kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg); +int kern_futimes(struct thread *td, int fd, struct timeval *tptr, + enum uio_seg tptrseg); +int kern_lchown(struct thread *td, char *path, enum uio_seg pathseg, + int uid, int gid); +int kern_link(struct thread *td, char *path, char *link, + enum uio_seg segflg); +int kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg, + struct timeval *tptr, enum uio_seg tptrseg); +int kern_mkdir(struct thread *td, char *path, enum uio_seg segflg, + int mode); +int kern_mkfifo(struct thread *td, char *path, enum uio_seg pathseg, + int mode); +int kern_mknod(struct thread *td, char *path, enum uio_seg pathseg, + int mode, int dev); +int kern_open(struct thread *td, char *path, enum uio_seg pathseg, + int flags, int mode); +int kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, + int data); +int kern_readlink(struct thread *td, char *path, enum uio_seg pathseg, + char *buf, enum uio_seg bufseg, int count); +int kern_rename(struct thread *td, char *from, char *to, + enum uio_seg pathseg); +int kern_rmdir(struct thread *td, char *path, enum uio_seg pathseg); +int kern_select(struct thread *td, int nd, fd_set *fd_in, fd_set *fd_ou, + fd_set *fd_ex, struct timeval *tvp); +int kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags, + struct mbuf *control); +int kern_shmat(struct thread *td, int shmid, const void *shmaddr, + int shmflg); +int kern_shmctl(struct thread *td, int shmid, int cmd, void *buf, + size_t *bufsz); +int kern_sigaction(struct thread *td, int sig, struct sigaction *act, + struct sigaction *oact, int flags); +int kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss); +int kern_sigprocmask(struct thread *td, int how, + sigset_t *set, sigset_t *oset, int old); +int kern_sigsuspend(struct thread *td, sigset_t mask); +int kern_symlink(struct thread *td, char *path, char *link, + enum uio_seg segflg); +int kern_truncate(struct thread *td, char *path, enum uio_seg pathseg, + off_t length); +int kern_unlink(struct thread *td, char *path, enum uio_seg pathseg); +int kern_utimes(struct thread *td, char *path, enum uio_seg pathseg, + struct timeval *tptr, enum uio_seg tptrseg); + +/* flags for kern_sigaction */ +#define KSA_OSIGSET 0x0001 /* uses osigact_t */ +#define KSA_FREEBSD4 0x0002 /* uses ucontext4 */ + +#endif /* !_SYS_SYSCALLSUBR_H_ */ diff --git a/src/include/sys/sysctl.h b/src/include/sys/sysctl.h new file mode 100644 index 0000000..cd16b16 --- /dev/null +++ b/src/include/sys/sysctl.h @@ -0,0 +1,637 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Karels at Berkeley Software Design, Inc. + * + * 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. + * 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. + * + * @(#)sysctl.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/sysctl.h,v 1.128 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SYSCTL_H_ +#define _SYS_SYSCTL_H_ + +#include + +struct thread; +/* + * Definitions for sysctl call. The sysctl call uses a hierarchical name + * for objects that can be examined or modified. The name is expressed as + * a sequence of integers. Like a file path name, the meaning of each + * component depends on its place in the hierarchy. The top-level and kern + * identifiers are defined here, and other identifiers are defined in the + * respective subsystem header files. + */ + +#define CTL_MAXNAME 24 /* largest number of components supported */ + +/* + * Each subsystem defined by sysctl defines a list of variables + * for that subsystem. Each name is either a node with further + * levels defined below it, or it is a leaf of some particular + * type given below. Each sysctl level defines a set of name/type + * pairs to be used by sysctl(8) in manipulating the subsystem. + */ +struct ctlname { + char *ctl_name; /* subsystem name */ + int ctl_type; /* type of name */ +}; + +#define CTLTYPE 0xf /* Mask for the type */ +#define CTLTYPE_NODE 1 /* name is a node */ +#define CTLTYPE_INT 2 /* name describes an integer */ +#define CTLTYPE_STRING 3 /* name describes a string */ +#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */ +#define CTLTYPE_OPAQUE 5 /* name describes a structure */ +#define CTLTYPE_STRUCT CTLTYPE_OPAQUE /* name describes a structure */ +#define CTLTYPE_UINT 6 /* name describes an unsigned integer */ +#define CTLTYPE_LONG 7 /* name describes a long */ +#define CTLTYPE_ULONG 8 /* name describes an unsigned long */ + +#define CTLFLAG_RD 0x80000000 /* Allow reads of variable */ +#define CTLFLAG_WR 0x40000000 /* Allow writes to the variable */ +#define CTLFLAG_RW (CTLFLAG_RD|CTLFLAG_WR) +#define CTLFLAG_NOLOCK 0x20000000 /* XXX Don't Lock */ +#define CTLFLAG_ANYBODY 0x10000000 /* All users can set this var */ +#define CTLFLAG_SECURE 0x08000000 /* Permit set only if securelevel<=0 */ +#define CTLFLAG_PRISON 0x04000000 /* Prisoned roots can fiddle */ +#define CTLFLAG_DYN 0x02000000 /* Dynamic oid - can be freed */ +#define CTLFLAG_SKIP 0x01000000 /* Skip this sysctl when listing */ +#define CTLMASK_SECURE 0x00F00000 /* Secure level */ +#define CTLFLAG_TUN 0x00080000 /* Tunable variable */ +#define CTLFLAG_RDTUN (CTLFLAG_RD|CTLFLAG_TUN) + +/* + * Secure level. Note that CTLFLAG_SECURE == CTLFLAG_SECURE1. + * + * Secure when the securelevel is raised to at least N. + */ +#define CTLSHIFT_SECURE 20 +#define CTLFLAG_SECURE1 (CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE)) +#define CTLFLAG_SECURE2 (CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE)) +#define CTLFLAG_SECURE3 (CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE)) + +/* + * USE THIS instead of a hardwired number from the categories below + * to get dynamically assigned sysctl entries using the linker-set + * technology. This is the way nearly all new sysctl variables should + * be implemented. + * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, ""); + */ +#define OID_AUTO (-1) + +/* + * The starting number for dynamically-assigned entries. WARNING! + * ALL static sysctl entries should have numbers LESS than this! + */ +#define CTL_AUTO_START 0x100 + +#ifdef _KERNEL +#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, int arg2, \ + struct sysctl_req *req + +/* definitions for sysctl_req 'lock' member */ +#define REQ_UNLOCKED 0 /* not locked and not wired */ +#define REQ_LOCKED 1 /* locked and not wired */ +#define REQ_WIRED 2 /* locked and wired */ + +/* + * This describes the access space for a sysctl request. This is needed + * so that we can use the interface from the kernel or from user-space. + */ +struct sysctl_req { + struct thread *td; /* used for access checking */ + int lock; /* locking/wiring state */ + void *oldptr; + size_t oldlen; + size_t oldidx; + int (*oldfunc)(struct sysctl_req *, const void *, size_t); + void *newptr; + size_t newlen; + size_t newidx; + int (*newfunc)(struct sysctl_req *, void *, size_t); + size_t validlen; +}; + +SLIST_HEAD(sysctl_oid_list, sysctl_oid); + +/* + * This describes one "oid" in the MIB tree. Potentially more nodes can + * be hidden behind it, expanded by the handler. + */ +struct sysctl_oid { + struct sysctl_oid_list *oid_parent; + SLIST_ENTRY(sysctl_oid) oid_link; + int oid_number; + u_int oid_kind; + void *oid_arg1; + int oid_arg2; + const char *oid_name; + int (*oid_handler)(SYSCTL_HANDLER_ARGS); + const char *oid_fmt; + int oid_refcnt; + const char *descr; +}; + +#define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l) +#define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l) + +int sysctl_handle_int(SYSCTL_HANDLER_ARGS); +int sysctl_handle_long(SYSCTL_HANDLER_ARGS); +int sysctl_handle_intptr(SYSCTL_HANDLER_ARGS); +int sysctl_handle_string(SYSCTL_HANDLER_ARGS); +int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS); + +/* + * These functions are used to add/remove an oid from the mib. + */ +void sysctl_register_oid(struct sysctl_oid *oidp); +void sysctl_unregister_oid(struct sysctl_oid *oidp); + +/* Declare a static oid to allow child oids to be added to it. */ +#define SYSCTL_DECL(name) \ + extern struct sysctl_oid_list sysctl_##name##_children + +/* Hide these in macros */ +#define SYSCTL_CHILDREN(oid_ptr) (struct sysctl_oid_list *) \ + (oid_ptr)->oid_arg1 +#define SYSCTL_STATIC_CHILDREN(oid_name) \ + (&sysctl_##oid_name##_children) + +/* === Structs and macros related to context handling === */ + +/* All dynamically created sysctls can be tracked in a context list. */ +struct sysctl_ctx_entry { + struct sysctl_oid *entry; + TAILQ_ENTRY(sysctl_ctx_entry) link; +}; + +TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); + +#define SYSCTL_NODE_CHILDREN(parent, name) \ + sysctl_##parent##_##name##_children + +/* This constructs a "raw" MIB oid. */ +#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ + static struct sysctl_oid sysctl__##parent##_##name = { \ + &sysctl_##parent##_children, { 0 }, \ + nbr, kind, a1, a2, #name, handler, fmt, 0, descr }; \ + DATA_SET(sysctl_set, sysctl__##parent##_##name) + +#define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) + +/* This constructs a node from which other oids can hang. */ +#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ + struct sysctl_oid_list SYSCTL_NODE_CHILDREN(parent, name); \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_NODE|(access), \ + (void*)&SYSCTL_NODE_CHILDREN(parent, name), 0, handler, \ + "N", descr) + +#define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \ + 0, 0, handler, "N", descr) + +/* Oid for a string. len can be 0 to indicate '\0' termination. */ +#define SYSCTL_STRING(parent, nbr, name, access, arg, len, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access), \ + arg, len, sysctl_handle_string, "A", descr) + +#define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \ + arg, len, sysctl_handle_string, "A", descr) + +/* Oid for an int. If ptr is NULL, val is returned. */ +#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|(access), \ + ptr, val, sysctl_handle_int, "I", descr) + +#define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_INT|(access), \ + ptr, val, sysctl_handle_int, "I", descr) + +/* Oid for an unsigned int. If ptr is NULL, val is returned. */ +#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_UINT|(access), \ + ptr, val, sysctl_handle_int, "IU", descr) + +#define SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \ + ptr, val, sysctl_handle_int, "IU", descr) + +/* Oid for a long. The pointer must be non NULL. */ +#define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_LONG|(access), \ + ptr, val, sysctl_handle_long, "L", descr) + +#define SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_LONG|(access), \ + ptr, 0, sysctl_handle_long, "L", descr) + +/* Oid for an unsigned long. The pointer must be non NULL. */ +#define SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_ULONG|(access), \ + ptr, val, sysctl_handle_long, "LU", descr) + +#define SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \ + ptr, 0, sysctl_handle_long, "LU", descr) + +/* Oid for an opaque object. Specified by a pointer and a length. */ +#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + ptr, len, sysctl_handle_opaque, fmt, descr) + +#define SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)\ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + ptr, len, sysctl_handle_opaque, fmt, descr) + +/* Oid for a struct. Specified by a pointer and a type. */ +#define SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + ptr, sizeof(struct type), sysctl_handle_opaque, \ + "S," #type, descr) + +#define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ + ptr, sizeof(struct type), sysctl_handle_opaque, "S," #type, descr) + +/* Oid for a procedure. Specified by a pointer and an arg. */ +#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ + SYSCTL_OID(parent, nbr, name, (access), \ + ptr, arg, handler, fmt, descr) + +#define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \ + sysctl_add_oid(ctx, parent, nbr, name, (access), \ + ptr, arg, handler, fmt, descr) + +#endif /* _KERNEL */ + +/* + * Top-level identifiers + */ +#define CTL_UNSPEC 0 /* unused */ +#define CTL_KERN 1 /* "high kernel": proc, limits */ +#define CTL_VM 2 /* virtual memory */ +#define CTL_VFS 3 /* filesystem, mount type is next */ +#define CTL_NET 4 /* network, see socket.h */ +#define CTL_DEBUG 5 /* debugging parameters */ +#define CTL_HW 6 /* generic cpu/io */ +#define CTL_MACHDEP 7 /* machine dependent */ +#define CTL_USER 8 /* user-level */ +#define CTL_P1003_1B 9 /* POSIX 1003.1B */ +#define CTL_MAXID 10 /* number of valid top-level ids */ + +#define CTL_NAMES { \ + { 0, 0 }, \ + { "kern", CTLTYPE_NODE }, \ + { "vm", CTLTYPE_NODE }, \ + { "vfs", CTLTYPE_NODE }, \ + { "net", CTLTYPE_NODE }, \ + { "debug", CTLTYPE_NODE }, \ + { "hw", CTLTYPE_NODE }, \ + { "machdep", CTLTYPE_NODE }, \ + { "user", CTLTYPE_NODE }, \ + { "p1003_1b", CTLTYPE_NODE }, \ +} + +/* + * CTL_KERN identifiers + */ +#define KERN_OSTYPE 1 /* string: system version */ +#define KERN_OSRELEASE 2 /* string: system release */ +#define KERN_OSREV 3 /* int: system revision */ +#define KERN_VERSION 4 /* string: compile time info */ +#define KERN_MAXVNODES 5 /* int: max vnodes */ +#define KERN_MAXPROC 6 /* int: max processes */ +#define KERN_MAXFILES 7 /* int: max open files */ +#define KERN_ARGMAX 8 /* int: max arguments to exec */ +#define KERN_SECURELVL 9 /* int: system security level */ +#define KERN_HOSTNAME 10 /* string: hostname */ +#define KERN_HOSTID 11 /* int: host identifier */ +#define KERN_CLOCKRATE 12 /* struct: struct clockrate */ +#define KERN_VNODE 13 /* struct: vnode structures */ +#define KERN_PROC 14 /* struct: process entries */ +#define KERN_FILE 15 /* struct: file entries */ +#define KERN_PROF 16 /* node: kernel profiling info */ +#define KERN_POSIX1 17 /* int: POSIX.1 version */ +#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ +#define KERN_JOB_CONTROL 19 /* int: is job control available */ +#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ +#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ +#define KERN_NISDOMAINNAME 22 /* string: YP domain name */ +#define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */ +#define KERN_OSRELDATE 24 /* int: kernel release date */ +#define KERN_NTP_PLL 25 /* node: NTP PLL control */ +#define KERN_BOOTFILE 26 /* string: name of booted kernel */ +#define KERN_MAXFILESPERPROC 27 /* int: max open files per proc */ +#define KERN_MAXPROCPERUID 28 /* int: max processes per uid */ +#define KERN_DUMPDEV 29 /* dev_t: device to dump on */ +#define KERN_IPC 30 /* node: anything related to IPC */ +#define KERN_DUMMY 31 /* unused */ +#define KERN_PS_STRINGS 32 /* int: address of PS_STRINGS */ +#define KERN_USRSTACK 33 /* int: address of USRSTACK */ +#define KERN_LOGSIGEXIT 34 /* int: do we log sigexit procs? */ +#define KERN_IOV_MAX 35 /* int: value of UIO_MAXIOV */ +#define KERN_MAXID 36 /* number of valid kern ids */ + +#define CTL_KERN_NAMES { \ + { 0, 0 }, \ + { "ostype", CTLTYPE_STRING }, \ + { "osrelease", CTLTYPE_STRING }, \ + { "osrevision", CTLTYPE_INT }, \ + { "version", CTLTYPE_STRING }, \ + { "maxvnodes", CTLTYPE_INT }, \ + { "maxproc", CTLTYPE_INT }, \ + { "maxfiles", CTLTYPE_INT }, \ + { "argmax", CTLTYPE_INT }, \ + { "securelevel", CTLTYPE_INT }, \ + { "hostname", CTLTYPE_STRING }, \ + { "hostid", CTLTYPE_UINT }, \ + { "clockrate", CTLTYPE_STRUCT }, \ + { "vnode", CTLTYPE_STRUCT }, \ + { "proc", CTLTYPE_STRUCT }, \ + { "file", CTLTYPE_STRUCT }, \ + { "profiling", CTLTYPE_NODE }, \ + { "posix1version", CTLTYPE_INT }, \ + { "ngroups", CTLTYPE_INT }, \ + { "job_control", CTLTYPE_INT }, \ + { "saved_ids", CTLTYPE_INT }, \ + { "boottime", CTLTYPE_STRUCT }, \ + { "nisdomainname", CTLTYPE_STRING }, \ + { "update", CTLTYPE_INT }, \ + { "osreldate", CTLTYPE_INT }, \ + { "ntp_pll", CTLTYPE_NODE }, \ + { "bootfile", CTLTYPE_STRING }, \ + { "maxfilesperproc", CTLTYPE_INT }, \ + { "maxprocperuid", CTLTYPE_INT }, \ + { "ipc", CTLTYPE_NODE }, \ + { "dummy", CTLTYPE_INT }, \ + { "ps_strings", CTLTYPE_INT }, \ + { "usrstack", CTLTYPE_INT }, \ + { "logsigexit", CTLTYPE_INT }, \ + { "iov_max", CTLTYPE_INT }, \ +} + +/* + * CTL_VFS identifiers + */ +#define CTL_VFS_NAMES { \ + { "vfsconf", CTLTYPE_STRUCT }, \ +} + +/* + * KERN_PROC subtypes + */ +#define KERN_PROC_ALL 0 /* everything */ +#define KERN_PROC_PID 1 /* by process id */ +#define KERN_PROC_PGRP 2 /* by process group id */ +#define KERN_PROC_SESSION 3 /* by session of pid */ +#define KERN_PROC_TTY 4 /* by controlling tty */ +#define KERN_PROC_UID 5 /* by effective uid */ +#define KERN_PROC_RUID 6 /* by real uid */ +#define KERN_PROC_ARGS 7 /* get/set arguments/proctitle */ +#define KERN_PROC_PROC 8 /* only return procs */ +#define KERN_PROC_SV_NAME 9 /* get syscall vector name */ +#define KERN_PROC_INC_THREAD 0x10 /* + * modifier for pid, pgrp, tty, + * uid, ruid, and proc + */ + +/* + * KERN_IPC identifiers + */ +#define KIPC_MAXSOCKBUF 1 /* int: max size of a socket buffer */ +#define KIPC_SOCKBUF_WASTE 2 /* int: wastage factor in sockbuf */ +#define KIPC_SOMAXCONN 3 /* int: max length of connection q */ +#define KIPC_MAX_LINKHDR 4 /* int: max length of link header */ +#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header */ +#define KIPC_MAX_HDR 6 /* int: max total length of headers */ +#define KIPC_MAX_DATALEN 7 /* int: max length of data? */ + +/* + * CTL_HW identifiers + */ +#define HW_MACHINE 1 /* string: machine class */ +#define HW_MODEL 2 /* string: specific machine model */ +#define HW_NCPU 3 /* int: number of cpus */ +#define HW_BYTEORDER 4 /* int: machine byte order */ +#define HW_PHYSMEM 5 /* int: total memory */ +#define HW_USERMEM 6 /* int: non-kernel memory */ +#define HW_PAGESIZE 7 /* int: software page size */ +#define HW_DISKNAMES 8 /* strings: disk drive names */ +#define HW_DISKSTATS 9 /* struct: diskstats[] */ +#define HW_FLOATINGPT 10 /* int: has HW floating point? */ +#define HW_MACHINE_ARCH 11 /* string: machine architecture */ +#define HW_MAXID 12 /* number of valid hw ids */ + +#define CTL_HW_NAMES { \ + { 0, 0 }, \ + { "machine", CTLTYPE_STRING }, \ + { "model", CTLTYPE_STRING }, \ + { "ncpu", CTLTYPE_INT }, \ + { "byteorder", CTLTYPE_INT }, \ + { "physmem", CTLTYPE_ULONG }, \ + { "usermem", CTLTYPE_ULONG }, \ + { "pagesize", CTLTYPE_INT }, \ + { "disknames", CTLTYPE_STRUCT }, \ + { "diskstats", CTLTYPE_STRUCT }, \ + { "floatingpoint", CTLTYPE_INT }, \ +} + +/* + * CTL_USER definitions + */ +#define USER_CS_PATH 1 /* string: _CS_PATH */ +#define USER_BC_BASE_MAX 2 /* int: BC_BASE_MAX */ +#define USER_BC_DIM_MAX 3 /* int: BC_DIM_MAX */ +#define USER_BC_SCALE_MAX 4 /* int: BC_SCALE_MAX */ +#define USER_BC_STRING_MAX 5 /* int: BC_STRING_MAX */ +#define USER_COLL_WEIGHTS_MAX 6 /* int: COLL_WEIGHTS_MAX */ +#define USER_EXPR_NEST_MAX 7 /* int: EXPR_NEST_MAX */ +#define USER_LINE_MAX 8 /* int: LINE_MAX */ +#define USER_RE_DUP_MAX 9 /* int: RE_DUP_MAX */ +#define USER_POSIX2_VERSION 10 /* int: POSIX2_VERSION */ +#define USER_POSIX2_C_BIND 11 /* int: POSIX2_C_BIND */ +#define USER_POSIX2_C_DEV 12 /* int: POSIX2_C_DEV */ +#define USER_POSIX2_CHAR_TERM 13 /* int: POSIX2_CHAR_TERM */ +#define USER_POSIX2_FORT_DEV 14 /* int: POSIX2_FORT_DEV */ +#define USER_POSIX2_FORT_RUN 15 /* int: POSIX2_FORT_RUN */ +#define USER_POSIX2_LOCALEDEF 16 /* int: POSIX2_LOCALEDEF */ +#define USER_POSIX2_SW_DEV 17 /* int: POSIX2_SW_DEV */ +#define USER_POSIX2_UPE 18 /* int: POSIX2_UPE */ +#define USER_STREAM_MAX 19 /* int: POSIX2_STREAM_MAX */ +#define USER_TZNAME_MAX 20 /* int: POSIX2_TZNAME_MAX */ +#define USER_MAXID 21 /* number of valid user ids */ + +#define CTL_USER_NAMES { \ + { 0, 0 }, \ + { "cs_path", CTLTYPE_STRING }, \ + { "bc_base_max", CTLTYPE_INT }, \ + { "bc_dim_max", CTLTYPE_INT }, \ + { "bc_scale_max", CTLTYPE_INT }, \ + { "bc_string_max", CTLTYPE_INT }, \ + { "coll_weights_max", CTLTYPE_INT }, \ + { "expr_nest_max", CTLTYPE_INT }, \ + { "line_max", CTLTYPE_INT }, \ + { "re_dup_max", CTLTYPE_INT }, \ + { "posix2_version", CTLTYPE_INT }, \ + { "posix2_c_bind", CTLTYPE_INT }, \ + { "posix2_c_dev", CTLTYPE_INT }, \ + { "posix2_char_term", CTLTYPE_INT }, \ + { "posix2_fort_dev", CTLTYPE_INT }, \ + { "posix2_fort_run", CTLTYPE_INT }, \ + { "posix2_localedef", CTLTYPE_INT }, \ + { "posix2_sw_dev", CTLTYPE_INT }, \ + { "posix2_upe", CTLTYPE_INT }, \ + { "stream_max", CTLTYPE_INT }, \ + { "tzname_max", CTLTYPE_INT }, \ +} + +#define CTL_P1003_1B_ASYNCHRONOUS_IO 1 /* boolean */ +#define CTL_P1003_1B_MAPPED_FILES 2 /* boolean */ +#define CTL_P1003_1B_MEMLOCK 3 /* boolean */ +#define CTL_P1003_1B_MEMLOCK_RANGE 4 /* boolean */ +#define CTL_P1003_1B_MEMORY_PROTECTION 5 /* boolean */ +#define CTL_P1003_1B_MESSAGE_PASSING 6 /* boolean */ +#define CTL_P1003_1B_PRIORITIZED_IO 7 /* boolean */ +#define CTL_P1003_1B_PRIORITY_SCHEDULING 8 /* boolean */ +#define CTL_P1003_1B_REALTIME_SIGNALS 9 /* boolean */ +#define CTL_P1003_1B_SEMAPHORES 10 /* boolean */ +#define CTL_P1003_1B_FSYNC 11 /* boolean */ +#define CTL_P1003_1B_SHARED_MEMORY_OBJECTS 12 /* boolean */ +#define CTL_P1003_1B_SYNCHRONIZED_IO 13 /* boolean */ +#define CTL_P1003_1B_TIMERS 14 /* boolean */ +#define CTL_P1003_1B_AIO_LISTIO_MAX 15 /* int */ +#define CTL_P1003_1B_AIO_MAX 16 /* int */ +#define CTL_P1003_1B_AIO_PRIO_DELTA_MAX 17 /* int */ +#define CTL_P1003_1B_DELAYTIMER_MAX 18 /* int */ +#define CTL_P1003_1B_MQ_OPEN_MAX 19 /* int */ +#define CTL_P1003_1B_PAGESIZE 20 /* int */ +#define CTL_P1003_1B_RTSIG_MAX 21 /* int */ +#define CTL_P1003_1B_SEM_NSEMS_MAX 22 /* int */ +#define CTL_P1003_1B_SEM_VALUE_MAX 23 /* int */ +#define CTL_P1003_1B_SIGQUEUE_MAX 24 /* int */ +#define CTL_P1003_1B_TIMER_MAX 25 /* int */ + +#define CTL_P1003_1B_MAXID 26 + +#define CTL_P1003_1B_NAMES { \ + { 0, 0 }, \ + { "asynchronous_io", CTLTYPE_INT }, \ + { "mapped_files", CTLTYPE_INT }, \ + { "memlock", CTLTYPE_INT }, \ + { "memlock_range", CTLTYPE_INT }, \ + { "memory_protection", CTLTYPE_INT }, \ + { "message_passing", CTLTYPE_INT }, \ + { "prioritized_io", CTLTYPE_INT }, \ + { "priority_scheduling", CTLTYPE_INT }, \ + { "realtime_signals", CTLTYPE_INT }, \ + { "semaphores", CTLTYPE_INT }, \ + { "fsync", CTLTYPE_INT }, \ + { "shared_memory_objects", CTLTYPE_INT }, \ + { "synchronized_io", CTLTYPE_INT }, \ + { "timers", CTLTYPE_INT }, \ + { "aio_listio_max", CTLTYPE_INT }, \ + { "aio_max", CTLTYPE_INT }, \ + { "aio_prio_delta_max", CTLTYPE_INT }, \ + { "delaytimer_max", CTLTYPE_INT }, \ + { "mq_open_max", CTLTYPE_INT }, \ + { "pagesize", CTLTYPE_INT }, \ + { "rtsig_max", CTLTYPE_INT }, \ + { "nsems_max", CTLTYPE_INT }, \ + { "sem_value_max", CTLTYPE_INT }, \ + { "sigqueue_max", CTLTYPE_INT }, \ + { "timer_max", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +/* + * Declare some common oids. + */ +extern struct sysctl_oid_list sysctl__children; +SYSCTL_DECL(_kern); +SYSCTL_DECL(_sysctl); +SYSCTL_DECL(_vm); +SYSCTL_DECL(_vfs); +SYSCTL_DECL(_net); +SYSCTL_DECL(_debug); +SYSCTL_DECL(_debug_sizeof); +SYSCTL_DECL(_hw); +SYSCTL_DECL(_machdep); +SYSCTL_DECL(_user); +SYSCTL_DECL(_compat); + +extern char machine[]; +extern char osrelease[]; +extern char ostype[]; +extern char kern_ident[]; + +/* Dynamic oid handling */ +struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist, + struct sysctl_oid_list *parent, int nbr, const char *name, + int kind, void *arg1, int arg2, + int (*handler) (SYSCTL_HANDLER_ARGS), + const char *fmt, const char *descr); +int sysctl_move_oid(struct sysctl_oid *oidp, + struct sysctl_oid_list *parent); +int sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse); +int sysctl_ctx_init(struct sysctl_ctx_list *clist); +int sysctl_ctx_free(struct sysctl_ctx_list *clist); +struct sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist, + struct sysctl_oid *oidp); +struct sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist, + struct sysctl_oid *oidp); +int sysctl_ctx_entry_del(struct sysctl_ctx_list *clist, + struct sysctl_oid *oidp); + +int kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old, + size_t *oldlenp, void *new, size_t newlen, + size_t *retval); +int kernel_sysctlbyname(struct thread *td, char *name, + void *old, size_t *oldlenp, void *new, size_t newlen, + size_t *retval); +int userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, + size_t *oldlenp, int inkernel, void *new, size_t newlen, + size_t *retval); +int sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid, + int *nindx, struct sysctl_req *req); +int sysctl_wire_old_buffer(struct sysctl_req *req, size_t len); + +#else /* !_KERNEL */ +#include + +__BEGIN_DECLS +int sysctl(int *, u_int, void *, size_t *, void *, size_t); +int sysctlbyname(const char *, void *, size_t *, void *, size_t); +int sysctlnametomib(const char *, int *, size_t *); +__END_DECLS +#endif /* _KERNEL */ + +#endif /* !_SYS_SYSCTL_H_ */ diff --git a/src/include/sys/sysent.h b/src/include/sys/sysent.h new file mode 100644 index 0000000..6f30f0f --- /dev/null +++ b/src/include/sys/sysent.h @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 1982, 1988, 1991 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. + * 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. + * + * $FreeBSD: src/sys/sys/sysent.h,v 1.44 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SYSENT_H_ +#define _SYS_SYSENT_H_ + +struct thread; + +typedef int sy_call_t(struct thread *, void *); + +struct sysent { /* system call table */ + int sy_narg; /* number of arguments */ + sy_call_t *sy_call; /* implementing function */ +}; + +#define SYF_ARGMASK 0x0000FFFF +#define SYF_MPSAFE 0x00010000 + +struct image_params; +struct __sigset; +struct trapframe; +struct vnode; + +struct sysentvec { + int sv_size; /* number of entries */ + struct sysent *sv_table; /* pointer to sysent */ + u_int sv_mask; /* optional mask to index */ + int sv_sigsize; /* size of signal translation table */ + int *sv_sigtbl; /* signal translation table */ + int sv_errsize; /* size of errno translation table */ + int *sv_errtbl; /* errno translation table */ + int (*sv_transtrap)(int, int); + /* translate trap-to-signal mapping */ + int (*sv_fixup)(register_t **, struct image_params *); + /* stack fixup function */ + void (*sv_sendsig)(void (*)(int), int, struct __sigset *, + u_long); /* send signal */ + char *sv_sigcode; /* start of sigtramp code */ + int *sv_szsigcode; /* size of sigtramp code */ + void (*sv_prepsyscall)(struct trapframe *, int *, u_int *, + caddr_t *); + char *sv_name; /* name of binary type */ + int (*sv_coredump)(struct thread *, struct vnode *, off_t); + /* function to dump core, or NULL */ + int (*sv_imgact_try)(struct image_params *); + int sv_minsigstksz; /* minimum signal stack size */ + int sv_pagesize; /* pagesize */ + vm_offset_t sv_minuser; /* VM_MIN_ADDRESS */ + vm_offset_t sv_maxuser; /* VM_MAXUSER_ADDRESS */ + vm_offset_t sv_usrstack; /* USRSTACK */ + vm_offset_t sv_psstrings; /* PS_STRINGS */ + int sv_stackprot; /* vm protection for stack */ + register_t *(*sv_copyout_strings)(struct image_params *); + void (*sv_setregs)(struct thread *, u_long, u_long, u_long); + void (*sv_fixlimits)(struct image_params *); +}; + +#ifdef _KERNEL +extern struct sysentvec aout_sysvec; +extern struct sysentvec elf_freebsd_sysvec; +extern struct sysentvec null_sysvec; +extern struct sysent sysent[]; + +#define NO_SYSCALL (-1) + +struct module; + +struct syscall_module_data { + int (*chainevh)(struct module *, int, void *); /* next handler */ + void *chainarg; /* arg for next event handler */ + int *offset; /* offset into sysent */ + struct sysent *new_sysent; /* new sysent */ + struct sysent old_sysent; /* old sysent */ +}; + +#define SYSCALL_MODULE(name, offset, new_sysent, evh, arg) \ +static struct syscall_module_data name##_syscall_mod = { \ + evh, arg, offset, new_sysent, { 0, NULL } \ +}; \ + \ +static moduledata_t name##_mod = { \ + #name, \ + syscall_module_handler, \ + &name##_syscall_mod \ +}; \ +DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE) + +#define SYSCALL_MODULE_HELPER(syscallname) \ +static int syscallname##_syscall = SYS_##syscallname; \ +static struct sysent syscallname##_sysent = { \ + (sizeof(struct syscallname ## _args ) \ + / sizeof(register_t)), \ + (sy_call_t *)& syscallname \ +}; \ +SYSCALL_MODULE(syscallname, \ + & syscallname##_syscall, & syscallname##_sysent, \ + NULL, NULL); + +int syscall_register(int *offset, struct sysent *new_sysent, + struct sysent *old_sysent); +int syscall_deregister(int *offset, struct sysent *old_sysent); +int syscall_module_handler(struct module *mod, int what, void *arg); + +#endif /* _KERNEL */ + +#endif /* !_SYS_SYSENT_H_ */ diff --git a/src/include/sys/syslimits.h b/src/include/sys/syslimits.h new file mode 100644 index 0000000..1f2fdd9 --- /dev/null +++ b/src/include/sys/syslimits.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1988, 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. + * 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. + * + * @(#)syslimits.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/syslimits.h,v 1.18 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SYSLIMITS_H_ +#define _SYS_SYSLIMITS_H_ + +#if !defined(_KERNEL) && !defined(_LIMITS_H_) && !defined(_SYS_PARAM_H_) +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#warning "No user-serviceable parts inside." +#endif +#endif + +/* + * Do not add any new variables here. (See the comment at the end of + * the file for why.) + */ +#define ARG_MAX 65536 /* max bytes for an exec function */ +#ifndef CHILD_MAX +#define CHILD_MAX 40 /* max simultaneous processes */ +#endif +#define LINK_MAX 32767 /* max file link count */ +#define MAX_CANON 255 /* max bytes in term canon input line */ +#define MAX_INPUT 255 /* max bytes in terminal input */ +#define NAME_MAX 255 /* max bytes in a file name */ +#define NGROUPS_MAX 16 /* max supplemental group id's */ +#ifndef OPEN_MAX +#define OPEN_MAX 64 /* max open files per process */ +#endif +#define PATH_MAX 1024 /* max bytes in pathname */ +#define PIPE_BUF 512 /* max bytes for atomic pipe writes */ +#define IOV_MAX 1024 /* max elements in i/o vector */ + +/* + * We leave the following values undefined to force applications to either + * assume conservative values or call sysconf() to get the current value. + * + * HOST_NAME_MAX + * + * (We should do this for most of the values currently defined here, + * but many programs are not prepared to deal with this yet.) + */ +#endif diff --git a/src/include/sys/syslog.h b/src/include/sys/syslog.h new file mode 100644 index 0000000..727cf4f --- /dev/null +++ b/src/include/sys/syslog.h @@ -0,0 +1,200 @@ +/* + * Copyright (c) 1982, 1986, 1988, 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. + * 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. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/syslog.h,v 1.24 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SYSLOG_H_ +#define _SYS_SYSLOG_H_ + +#define _PATH_LOG "/var/run/log" +#define _PATH_OLDLOG "/dev/log" /* backward compatibility */ + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) ((fac) | (pri)) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK LOG_MAKEPRI((LOG_NFACILITIES<<3), 0) +typedef struct _code { + const char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = { + { "alert", LOG_ALERT, }, + { "crit", LOG_CRIT, }, + { "debug", LOG_DEBUG, }, + { "emerg", LOG_EMERG, }, + { "err", LOG_ERR, }, + { "error", LOG_ERR, }, /* DEPRECATED */ + { "info", LOG_INFO, }, + { "none", INTERNAL_NOPRI, }, /* INTERNAL */ + { "notice", LOG_NOTICE, }, + { "panic", LOG_EMERG, }, /* DEPRECATED */ + { "warn", LOG_WARNING, }, /* DEPRECATED */ + { "warning", LOG_WARNING, }, + { NULL, -1, } +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* authorization messages (private) */ + /* Facility #10 clashes in DEC UNIX, where */ + /* it's defined as LOG_MEGASAFE for AdvFS */ + /* event logging. */ +#define LOG_FTP (11<<3) /* ftp daemon */ +#define LOG_NTP (12<<3) /* NTP subsystem */ +#define LOG_SECURITY (13<<3) /* security subsystems (firewalling, etc.) */ +#define LOG_CONSOLE (14<<3) /* /dev/console output */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = { + { "auth", LOG_AUTH, }, + { "authpriv", LOG_AUTHPRIV, }, + { "console", LOG_CONSOLE, }, + { "cron", LOG_CRON, }, + { "daemon", LOG_DAEMON, }, + { "ftp", LOG_FTP, }, + { "kern", LOG_KERN, }, + { "lpr", LOG_LPR, }, + { "mail", LOG_MAIL, }, + { "mark", INTERNAL_MARK, }, /* INTERNAL */ + { "news", LOG_NEWS, }, + { "ntp", LOG_NTP, }, + { "security", LOG_SECURITY, }, + { "syslog", LOG_SYSLOG, }, + { "user", LOG_USER, }, + { "uucp", LOG_UUCP, }, + { "local0", LOG_LOCAL0, }, + { "local1", LOG_LOCAL1, }, + { "local2", LOG_LOCAL2, }, + { "local3", LOG_LOCAL3, }, + { "local4", LOG_LOCAL4, }, + { "local5", LOG_LOCAL5, }, + { "local6", LOG_LOCAL6, }, + { "local7", LOG_LOCAL7, }, + { NULL, -1, } +}; +#endif + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifdef _KERNEL + +#else /* not _KERNEL */ + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two + * places ( and ), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include syslog.h, so we get + * __va_list from and use it. + */ +#include +#include + +__BEGIN_DECLS +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...) __printflike(2, 3); +void vsyslog(int, const char *, __va_list) __printflike(2, 0); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif diff --git a/src/include/sys/sysproto.h b/src/include/sys/sysproto.h new file mode 100644 index 0000000..34ba9a8 --- /dev/null +++ b/src/include/sys/sysproto.h @@ -0,0 +1,1823 @@ +/* + * System call prototypes. + * + * DO NOT EDIT-- this file is automatically generated. + * $FreeBSD: src/sys/sys/sysproto.h,v 1.153 2004/04/05 10:16:39 dfr Exp $ + * created from FreeBSD: src/sys/kern/syscalls.master,v 1.171 2004/04/05 10:15:53 dfr Exp + */ + +#ifndef _SYS_SYSPROTO_H_ +#define _SYS_SYSPROTO_H_ + +#include +#include +#include +#include +#include + +#include + +struct proc; + +struct thread; + +#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ + 0 : sizeof(register_t) - sizeof(t)) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define PADL_(t) 0 +#define PADR_(t) PAD_(t) +#else +#define PADL_(t) PAD_(t) +#define PADR_(t) 0 +#endif + +struct nosys_args { + register_t dummy; +}; +struct sys_exit_args { + char rval_l_[PADL_(int)]; int rval; char rval_r_[PADR_(int)]; +}; +struct fork_args { + register_t dummy; +}; +struct read_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; +}; +struct write_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; +}; +struct open_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct close_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; +struct wait_args { + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; + char status_l_[PADL_(int *)]; int * status; char status_r_[PADR_(int *)]; + char options_l_[PADL_(int)]; int options; char options_r_[PADR_(int)]; + char rusage_l_[PADL_(struct rusage *)]; struct rusage * rusage; char rusage_r_[PADR_(struct rusage *)]; +}; +struct link_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char link_l_[PADL_(char *)]; char * link; char link_r_[PADR_(char *)]; +}; +struct unlink_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct chdir_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct fchdir_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; +struct mknod_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; + char dev_l_[PADL_(int)]; int dev; char dev_r_[PADR_(int)]; +}; +struct chmod_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct chown_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char gid_l_[PADL_(int)]; int gid; char gid_r_[PADR_(int)]; +}; +struct obreak_args { + char nsize_l_[PADL_(char *)]; char * nsize; char nsize_r_[PADR_(char *)]; +}; +struct getpid_args { + register_t dummy; +}; +struct mount_args { + char type_l_[PADL_(char *)]; char * type; char type_r_[PADR_(char *)]; + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char data_l_[PADL_(caddr_t)]; caddr_t data; char data_r_[PADR_(caddr_t)]; +}; +struct unmount_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct setuid_args { + char uid_l_[PADL_(uid_t)]; uid_t uid; char uid_r_[PADR_(uid_t)]; +}; +struct getuid_args { + register_t dummy; +}; +struct geteuid_args { + register_t dummy; +}; +struct ptrace_args { + char req_l_[PADL_(int)]; int req; char req_r_[PADR_(int)]; + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)]; + char data_l_[PADL_(int)]; int data; char data_r_[PADR_(int)]; +}; +struct recvmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct sendmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct recvfrom_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char from_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict from; char from_r_[PADR_(struct sockaddr *__restrict)]; + char fromlenaddr_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict fromlenaddr; char fromlenaddr_r_[PADR_(__socklen_t *__restrict)]; +}; +struct accept_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict name; char name_r_[PADR_(struct sockaddr *__restrict)]; + char anamelen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict anamelen; char anamelen_r_[PADR_(__socklen_t *__restrict)]; +}; +struct getpeername_args { + char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)]; + char asa_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict asa; char asa_r_[PADR_(struct sockaddr *__restrict)]; + char alen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict alen; char alen_r_[PADR_(__socklen_t *__restrict)]; +}; +struct getsockname_args { + char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)]; + char asa_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict asa; char asa_r_[PADR_(struct sockaddr *__restrict)]; + char alen_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict alen; char alen_r_[PADR_(__socklen_t *__restrict)]; +}; +struct access_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct chflags_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct fchflags_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct sync_args { + register_t dummy; +}; +struct kill_args { + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; +}; +struct getppid_args { + register_t dummy; +}; +struct dup_args { + char fd_l_[PADL_(u_int)]; u_int fd; char fd_r_[PADR_(u_int)]; +}; +struct pipe_args { + register_t dummy; +}; +struct getegid_args { + register_t dummy; +}; +struct profil_args { + char samples_l_[PADL_(caddr_t)]; caddr_t samples; char samples_r_[PADR_(caddr_t)]; + char size_l_[PADL_(size_t)]; size_t size; char size_r_[PADR_(size_t)]; + char offset_l_[PADL_(size_t)]; size_t offset; char offset_r_[PADR_(size_t)]; + char scale_l_[PADL_(u_int)]; u_int scale; char scale_r_[PADR_(u_int)]; +}; +struct ktrace_args { + char fname_l_[PADL_(const char *)]; const char * fname; char fname_r_[PADR_(const char *)]; + char ops_l_[PADL_(int)]; int ops; char ops_r_[PADR_(int)]; + char facs_l_[PADL_(int)]; int facs; char facs_r_[PADR_(int)]; + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; +}; +struct getgid_args { + register_t dummy; +}; +struct getlogin_args { + char namebuf_l_[PADL_(char *)]; char * namebuf; char namebuf_r_[PADR_(char *)]; + char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)]; +}; +struct setlogin_args { + char namebuf_l_[PADL_(char *)]; char * namebuf; char namebuf_r_[PADR_(char *)]; +}; +struct acct_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct osigpending_args { + register_t dummy; +}; +struct sigaltstack_args { + char ss_l_[PADL_(stack_t *)]; stack_t * ss; char ss_r_[PADR_(stack_t *)]; + char oss_l_[PADL_(stack_t *)]; stack_t * oss; char oss_r_[PADR_(stack_t *)]; +}; +struct ioctl_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char com_l_[PADL_(u_long)]; u_long com; char com_r_[PADR_(u_long)]; + char data_l_[PADL_(caddr_t)]; caddr_t data; char data_r_[PADR_(caddr_t)]; +}; +struct reboot_args { + char opt_l_[PADL_(int)]; int opt; char opt_r_[PADR_(int)]; +}; +struct revoke_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct symlink_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char link_l_[PADL_(char *)]; char * link; char link_r_[PADR_(char *)]; +}; +struct readlink_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(int)]; int count; char count_r_[PADR_(int)]; +}; +struct execve_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char argv_l_[PADL_(char **)]; char ** argv; char argv_r_[PADR_(char **)]; + char envv_l_[PADL_(char **)]; char ** envv; char envv_r_[PADR_(char **)]; +}; +struct umask_args { + char newmask_l_[PADL_(int)]; int newmask; char newmask_r_[PADR_(int)]; +}; +struct chroot_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct getpagesize_args { + register_t dummy; +}; +struct msync_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct vfork_args { + register_t dummy; +}; +struct sbrk_args { + char incr_l_[PADL_(int)]; int incr; char incr_r_[PADR_(int)]; +}; +struct sstk_args { + char incr_l_[PADL_(int)]; int incr; char incr_r_[PADR_(int)]; +}; +struct ovadvise_args { + char anom_l_[PADL_(int)]; int anom; char anom_r_[PADR_(int)]; +}; +struct munmap_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct mprotect_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; +}; +struct madvise_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char behav_l_[PADL_(int)]; int behav; char behav_r_[PADR_(int)]; +}; +struct mincore_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char vec_l_[PADL_(char *)]; char * vec; char vec_r_[PADR_(char *)]; +}; +struct getgroups_args { + char gidsetsize_l_[PADL_(u_int)]; u_int gidsetsize; char gidsetsize_r_[PADR_(u_int)]; + char gidset_l_[PADL_(gid_t *)]; gid_t * gidset; char gidset_r_[PADR_(gid_t *)]; +}; +struct setgroups_args { + char gidsetsize_l_[PADL_(u_int)]; u_int gidsetsize; char gidsetsize_r_[PADR_(u_int)]; + char gidset_l_[PADL_(gid_t *)]; gid_t * gidset; char gidset_r_[PADR_(gid_t *)]; +}; +struct getpgrp_args { + register_t dummy; +}; +struct setpgid_args { + char pid_l_[PADL_(int)]; int pid; char pid_r_[PADR_(int)]; + char pgid_l_[PADL_(int)]; int pgid; char pgid_r_[PADR_(int)]; +}; +struct setitimer_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char itv_l_[PADL_(struct itimerval *)]; struct itimerval * itv; char itv_r_[PADR_(struct itimerval *)]; + char oitv_l_[PADL_(struct itimerval *)]; struct itimerval * oitv; char oitv_r_[PADR_(struct itimerval *)]; +}; +struct owait_args { + register_t dummy; +}; +struct swapon_args { + char name_l_[PADL_(char *)]; char * name; char name_r_[PADR_(char *)]; +}; +struct getitimer_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char itv_l_[PADL_(struct itimerval *)]; struct itimerval * itv; char itv_r_[PADR_(struct itimerval *)]; +}; +struct getdtablesize_args { + register_t dummy; +}; +struct dup2_args { + char from_l_[PADL_(u_int)]; u_int from; char from_r_[PADR_(u_int)]; + char to_l_[PADL_(u_int)]; u_int to; char to_r_[PADR_(u_int)]; +}; +struct fcntl_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char arg_l_[PADL_(long)]; long arg; char arg_r_[PADR_(long)]; +}; +struct select_args { + char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)]; + char in_l_[PADL_(fd_set *)]; fd_set * in; char in_r_[PADR_(fd_set *)]; + char ou_l_[PADL_(fd_set *)]; fd_set * ou; char ou_r_[PADR_(fd_set *)]; + char ex_l_[PADL_(fd_set *)]; fd_set * ex; char ex_r_[PADR_(fd_set *)]; + char tv_l_[PADL_(struct timeval *)]; struct timeval * tv; char tv_r_[PADR_(struct timeval *)]; +}; +struct fsync_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; +}; +struct setpriority_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)]; + char prio_l_[PADL_(int)]; int prio; char prio_r_[PADR_(int)]; +}; +struct socket_args { + char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)]; + char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)]; + char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)]; +}; +struct connect_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)]; + char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)]; +}; +struct getpriority_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)]; +}; +struct bind_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char name_l_[PADL_(caddr_t)]; caddr_t name; char name_r_[PADR_(caddr_t)]; + char namelen_l_[PADL_(int)]; int namelen; char namelen_r_[PADR_(int)]; +}; +struct setsockopt_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char level_l_[PADL_(int)]; int level; char level_r_[PADR_(int)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; + char val_l_[PADL_(caddr_t)]; caddr_t val; char val_r_[PADR_(caddr_t)]; + char valsize_l_[PADL_(int)]; int valsize; char valsize_r_[PADR_(int)]; +}; +struct listen_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char backlog_l_[PADL_(int)]; int backlog; char backlog_r_[PADR_(int)]; +}; +struct gettimeofday_args { + char tp_l_[PADL_(struct timeval *)]; struct timeval * tp; char tp_r_[PADR_(struct timeval *)]; + char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)]; +}; +struct getrusage_args { + char who_l_[PADL_(int)]; int who; char who_r_[PADR_(int)]; + char rusage_l_[PADL_(struct rusage *)]; struct rusage * rusage; char rusage_r_[PADR_(struct rusage *)]; +}; +struct getsockopt_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char level_l_[PADL_(int)]; int level; char level_r_[PADR_(int)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; + char val_l_[PADL_(caddr_t)]; caddr_t val; char val_r_[PADR_(caddr_t)]; + char avalsize_l_[PADL_(int *)]; int * avalsize; char avalsize_r_[PADR_(int *)]; +}; +struct readv_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)]; +}; +struct writev_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)]; +}; +struct settimeofday_args { + char tv_l_[PADL_(struct timeval *)]; struct timeval * tv; char tv_r_[PADR_(struct timeval *)]; + char tzp_l_[PADL_(struct timezone *)]; struct timezone * tzp; char tzp_r_[PADR_(struct timezone *)]; +}; +struct fchown_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char gid_l_[PADL_(int)]; int gid; char gid_r_[PADR_(int)]; +}; +struct fchmod_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct setreuid_args { + char ruid_l_[PADL_(int)]; int ruid; char ruid_r_[PADR_(int)]; + char euid_l_[PADL_(int)]; int euid; char euid_r_[PADR_(int)]; +}; +struct setregid_args { + char rgid_l_[PADL_(int)]; int rgid; char rgid_r_[PADR_(int)]; + char egid_l_[PADL_(int)]; int egid; char egid_r_[PADR_(int)]; +}; +struct rename_args { + char from_l_[PADL_(char *)]; char * from; char from_r_[PADR_(char *)]; + char to_l_[PADL_(char *)]; char * to; char to_r_[PADR_(char *)]; +}; +struct flock_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; +}; +struct mkfifo_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct sendto_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)]; + char tolen_l_[PADL_(int)]; int tolen; char tolen_r_[PADR_(int)]; +}; +struct shutdown_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; +}; +struct socketpair_args { + char domain_l_[PADL_(int)]; int domain; char domain_r_[PADR_(int)]; + char type_l_[PADL_(int)]; int type; char type_r_[PADR_(int)]; + char protocol_l_[PADL_(int)]; int protocol; char protocol_r_[PADR_(int)]; + char rsv_l_[PADL_(int *)]; int * rsv; char rsv_r_[PADR_(int *)]; +}; +struct mkdir_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct rmdir_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct utimes_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char tptr_l_[PADL_(struct timeval *)]; struct timeval * tptr; char tptr_r_[PADR_(struct timeval *)]; +}; +struct adjtime_args { + char delta_l_[PADL_(struct timeval *)]; struct timeval * delta; char delta_r_[PADR_(struct timeval *)]; + char olddelta_l_[PADL_(struct timeval *)]; struct timeval * olddelta; char olddelta_r_[PADR_(struct timeval *)]; +}; +struct ogethostid_args { + register_t dummy; +}; +struct setsid_args { + register_t dummy; +}; +struct quotactl_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char arg_l_[PADL_(caddr_t)]; caddr_t arg; char arg_r_[PADR_(caddr_t)]; +}; +struct oquota_args { + register_t dummy; +}; +struct nfssvc_args { + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; + char argp_l_[PADL_(caddr_t)]; caddr_t argp; char argp_r_[PADR_(caddr_t)]; +}; +struct lgetfh_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; +}; +struct getfh_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char fhp_l_[PADL_(struct fhandle *)]; struct fhandle * fhp; char fhp_r_[PADR_(struct fhandle *)]; +}; +struct getdomainname_args { + char domainname_l_[PADL_(char *)]; char * domainname; char domainname_r_[PADR_(char *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; +}; +struct setdomainname_args { + char domainname_l_[PADL_(char *)]; char * domainname; char domainname_r_[PADR_(char *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; +}; +struct uname_args { + char name_l_[PADL_(struct utsname *)]; struct utsname * name; char name_r_[PADR_(struct utsname *)]; +}; +struct sysarch_args { + char op_l_[PADL_(int)]; int op; char op_r_[PADR_(int)]; + char parms_l_[PADL_(char *)]; char * parms; char parms_r_[PADR_(char *)]; +}; +struct rtprio_args { + char function_l_[PADL_(int)]; int function; char function_r_[PADR_(int)]; + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char rtp_l_[PADL_(struct rtprio *)]; struct rtprio * rtp; char rtp_r_[PADR_(struct rtprio *)]; +}; +struct semsys_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)]; + char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)]; + char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)]; + char a5_l_[PADL_(int)]; int a5; char a5_r_[PADR_(int)]; +}; +struct msgsys_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)]; + char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)]; + char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)]; + char a5_l_[PADL_(int)]; int a5; char a5_r_[PADR_(int)]; + char a6_l_[PADL_(int)]; int a6; char a6_r_[PADR_(int)]; +}; +struct shmsys_args { + char which_l_[PADL_(int)]; int which; char which_r_[PADR_(int)]; + char a2_l_[PADL_(int)]; int a2; char a2_r_[PADR_(int)]; + char a3_l_[PADL_(int)]; int a3; char a3_r_[PADR_(int)]; + char a4_l_[PADL_(int)]; int a4; char a4_r_[PADR_(int)]; +}; +struct pread_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(void *)]; void * buf; char buf_r_[PADR_(void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct pwrite_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(const void *)]; const void * buf; char buf_r_[PADR_(const void *)]; + char nbyte_l_[PADL_(size_t)]; size_t nbyte; char nbyte_r_[PADR_(size_t)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; +}; +struct ntp_adjtime_args { + char tp_l_[PADL_(struct timex *)]; struct timex * tp; char tp_r_[PADR_(struct timex *)]; +}; +struct setgid_args { + char gid_l_[PADL_(gid_t)]; gid_t gid; char gid_r_[PADR_(gid_t)]; +}; +struct setegid_args { + char egid_l_[PADL_(gid_t)]; gid_t egid; char egid_r_[PADR_(gid_t)]; +}; +struct seteuid_args { + char euid_l_[PADL_(uid_t)]; uid_t euid; char euid_r_[PADR_(uid_t)]; +}; +struct stat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct stat *)]; struct stat * ub; char ub_r_[PADR_(struct stat *)]; +}; +struct fstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct stat *)]; struct stat * sb; char sb_r_[PADR_(struct stat *)]; +}; +struct lstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct stat *)]; struct stat * ub; char ub_r_[PADR_(struct stat *)]; +}; +struct pathconf_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; +}; +struct fpathconf_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char name_l_[PADL_(int)]; int name; char name_r_[PADR_(int)]; +}; +struct __getrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct rlimit *)]; struct rlimit * rlp; char rlp_r_[PADR_(struct rlimit *)]; +}; +struct __setrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct rlimit *)]; struct rlimit * rlp; char rlp_r_[PADR_(struct rlimit *)]; +}; +struct getdirentries_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(u_int)]; u_int count; char count_r_[PADR_(u_int)]; + char basep_l_[PADL_(long *)]; long * basep; char basep_r_[PADR_(long *)]; +}; +struct mmap_args { + char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char pos_l_[PADL_(off_t)]; off_t pos; char pos_r_[PADR_(off_t)]; +}; +struct lseek_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char whence_l_[PADL_(int)]; int whence; char whence_r_[PADR_(int)]; +}; +struct truncate_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char length_l_[PADL_(off_t)]; off_t length; char length_r_[PADR_(off_t)]; +}; +struct ftruncate_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pad_l_[PADL_(int)]; int pad; char pad_r_[PADR_(int)]; + char length_l_[PADL_(off_t)]; off_t length; char length_r_[PADR_(off_t)]; +}; +struct sysctl_args { + char name_l_[PADL_(int *)]; int * name; char name_r_[PADR_(int *)]; + char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)]; + char old_l_[PADL_(void *)]; void * old; char old_r_[PADR_(void *)]; + char oldlenp_l_[PADL_(size_t *)]; size_t * oldlenp; char oldlenp_r_[PADR_(size_t *)]; + char new_l_[PADL_(void *)]; void * new; char new_r_[PADR_(void *)]; + char newlen_l_[PADL_(size_t)]; size_t newlen; char newlen_r_[PADR_(size_t)]; +}; +struct mlock_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct munlock_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct undelete_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; +}; +struct futimes_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char tptr_l_[PADL_(struct timeval *)]; struct timeval * tptr; char tptr_r_[PADR_(struct timeval *)]; +}; +struct getpgid_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; +}; +struct poll_args { + char fds_l_[PADL_(struct pollfd *)]; struct pollfd * fds; char fds_r_[PADR_(struct pollfd *)]; + char nfds_l_[PADL_(u_int)]; u_int nfds; char nfds_r_[PADR_(u_int)]; + char timeout_l_[PADL_(int)]; int timeout; char timeout_r_[PADR_(int)]; +}; +struct __semctl_args { + char semid_l_[PADL_(int)]; int semid; char semid_r_[PADR_(int)]; + char semnum_l_[PADL_(int)]; int semnum; char semnum_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char arg_l_[PADL_(union semun *)]; union semun * arg; char arg_r_[PADR_(union semun *)]; +}; +struct semget_args { + char key_l_[PADL_(key_t)]; key_t key; char key_r_[PADR_(key_t)]; + char nsems_l_[PADL_(int)]; int nsems; char nsems_r_[PADR_(int)]; + char semflg_l_[PADL_(int)]; int semflg; char semflg_r_[PADR_(int)]; +}; +struct semop_args { + char semid_l_[PADL_(int)]; int semid; char semid_r_[PADR_(int)]; + char sops_l_[PADL_(struct sembuf *)]; struct sembuf * sops; char sops_r_[PADR_(struct sembuf *)]; + char nsops_l_[PADL_(size_t)]; size_t nsops; char nsops_r_[PADR_(size_t)]; +}; +struct msgctl_args { + char msqid_l_[PADL_(int)]; int msqid; char msqid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char buf_l_[PADL_(struct msqid_ds *)]; struct msqid_ds * buf; char buf_r_[PADR_(struct msqid_ds *)]; +}; +struct msgget_args { + char key_l_[PADL_(key_t)]; key_t key; char key_r_[PADR_(key_t)]; + char msgflg_l_[PADL_(int)]; int msgflg; char msgflg_r_[PADR_(int)]; +}; +struct msgsnd_args { + char msqid_l_[PADL_(int)]; int msqid; char msqid_r_[PADR_(int)]; + char msgp_l_[PADL_(const void *)]; const void * msgp; char msgp_r_[PADR_(const void *)]; + char msgsz_l_[PADL_(size_t)]; size_t msgsz; char msgsz_r_[PADR_(size_t)]; + char msgflg_l_[PADL_(int)]; int msgflg; char msgflg_r_[PADR_(int)]; +}; +struct msgrcv_args { + char msqid_l_[PADL_(int)]; int msqid; char msqid_r_[PADR_(int)]; + char msgp_l_[PADL_(void *)]; void * msgp; char msgp_r_[PADR_(void *)]; + char msgsz_l_[PADL_(size_t)]; size_t msgsz; char msgsz_r_[PADR_(size_t)]; + char msgtyp_l_[PADL_(long)]; long msgtyp; char msgtyp_r_[PADR_(long)]; + char msgflg_l_[PADL_(int)]; int msgflg; char msgflg_r_[PADR_(int)]; +}; +struct shmat_args { + char shmid_l_[PADL_(int)]; int shmid; char shmid_r_[PADR_(int)]; + char shmaddr_l_[PADL_(const void *)]; const void * shmaddr; char shmaddr_r_[PADR_(const void *)]; + char shmflg_l_[PADL_(int)]; int shmflg; char shmflg_r_[PADR_(int)]; +}; +struct shmctl_args { + char shmid_l_[PADL_(int)]; int shmid; char shmid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char buf_l_[PADL_(struct shmid_ds *)]; struct shmid_ds * buf; char buf_r_[PADR_(struct shmid_ds *)]; +}; +struct shmdt_args { + char shmaddr_l_[PADL_(const void *)]; const void * shmaddr; char shmaddr_r_[PADR_(const void *)]; +}; +struct shmget_args { + char key_l_[PADL_(key_t)]; key_t key; char key_r_[PADR_(key_t)]; + char size_l_[PADL_(size_t)]; size_t size; char size_r_[PADR_(size_t)]; + char shmflg_l_[PADL_(int)]; int shmflg; char shmflg_r_[PADR_(int)]; +}; +struct clock_gettime_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char tp_l_[PADL_(struct timespec *)]; struct timespec * tp; char tp_r_[PADR_(struct timespec *)]; +}; +struct clock_settime_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char tp_l_[PADL_(const struct timespec *)]; const struct timespec * tp; char tp_r_[PADR_(const struct timespec *)]; +}; +struct clock_getres_args { + char clock_id_l_[PADL_(clockid_t)]; clockid_t clock_id; char clock_id_r_[PADR_(clockid_t)]; + char tp_l_[PADL_(struct timespec *)]; struct timespec * tp; char tp_r_[PADR_(struct timespec *)]; +}; +struct nanosleep_args { + char rqtp_l_[PADL_(const struct timespec *)]; const struct timespec * rqtp; char rqtp_r_[PADR_(const struct timespec *)]; + char rmtp_l_[PADL_(struct timespec *)]; struct timespec * rmtp; char rmtp_r_[PADR_(struct timespec *)]; +}; +struct minherit_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; + char inherit_l_[PADL_(int)]; int inherit; char inherit_r_[PADR_(int)]; +}; +struct rfork_args { + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct openbsd_poll_args { + char fds_l_[PADL_(struct pollfd *)]; struct pollfd * fds; char fds_r_[PADR_(struct pollfd *)]; + char nfds_l_[PADL_(u_int)]; u_int nfds; char nfds_r_[PADR_(u_int)]; + char timeout_l_[PADL_(int)]; int timeout; char timeout_r_[PADR_(int)]; +}; +struct issetugid_args { + register_t dummy; +}; +struct lchown_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char uid_l_[PADL_(int)]; int uid; char uid_r_[PADR_(int)]; + char gid_l_[PADL_(int)]; int gid; char gid_r_[PADR_(int)]; +}; +struct getdents_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(size_t)]; size_t count; char count_r_[PADR_(size_t)]; +}; +struct lchmod_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; +}; +struct lutimes_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char tptr_l_[PADL_(struct timeval *)]; struct timeval * tptr; char tptr_r_[PADR_(struct timeval *)]; +}; +struct nstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct nstat *)]; struct nstat * ub; char ub_r_[PADR_(struct nstat *)]; +}; +struct nfstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct nstat *)]; struct nstat * sb; char sb_r_[PADR_(struct nstat *)]; +}; +struct nlstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct nstat *)]; struct nstat * ub; char ub_r_[PADR_(struct nstat *)]; +}; +struct fhopen_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct fhstat_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char sb_l_[PADL_(struct stat *)]; struct stat * sb; char sb_r_[PADR_(struct stat *)]; +}; +struct modnext_args { + char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)]; +}; +struct modstat_args { + char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)]; + char stat_l_[PADL_(struct module_stat *)]; struct module_stat * stat; char stat_r_[PADR_(struct module_stat *)]; +}; +struct modfnext_args { + char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)]; +}; +struct modfind_args { + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; +}; +struct kldload_args { + char file_l_[PADL_(const char *)]; const char * file; char file_r_[PADR_(const char *)]; +}; +struct kldunload_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; +}; +struct kldfind_args { + char file_l_[PADL_(const char *)]; const char * file; char file_r_[PADR_(const char *)]; +}; +struct kldnext_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; +}; +struct kldstat_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; + char stat_l_[PADL_(struct kld_file_stat *)]; struct kld_file_stat * stat; char stat_r_[PADR_(struct kld_file_stat *)]; +}; +struct kldfirstmod_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; +}; +struct getsid_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; +}; +struct setresuid_args { + char ruid_l_[PADL_(uid_t)]; uid_t ruid; char ruid_r_[PADR_(uid_t)]; + char euid_l_[PADL_(uid_t)]; uid_t euid; char euid_r_[PADR_(uid_t)]; + char suid_l_[PADL_(uid_t)]; uid_t suid; char suid_r_[PADR_(uid_t)]; +}; +struct setresgid_args { + char rgid_l_[PADL_(gid_t)]; gid_t rgid; char rgid_r_[PADR_(gid_t)]; + char egid_l_[PADL_(gid_t)]; gid_t egid; char egid_r_[PADR_(gid_t)]; + char sgid_l_[PADL_(gid_t)]; gid_t sgid; char sgid_r_[PADR_(gid_t)]; +}; +struct aio_return_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct aio_suspend_args { + char aiocbp_l_[PADL_(struct aiocb *const *)]; struct aiocb *const * aiocbp; char aiocbp_r_[PADR_(struct aiocb *const *)]; + char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)]; + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct aio_cancel_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct aio_error_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct aio_read_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct aio_write_args { + char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)]; +}; +struct lio_listio_args { + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; + char acb_list_l_[PADL_(struct aiocb *const *)]; struct aiocb *const * acb_list; char acb_list_r_[PADR_(struct aiocb *const *)]; + char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)]; + char sig_l_[PADL_(struct sigevent *)]; struct sigevent * sig; char sig_r_[PADR_(struct sigevent *)]; +}; +struct yield_args { + register_t dummy; +}; +struct mlockall_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; +}; +struct munlockall_args { + register_t dummy; +}; +struct __getcwd_args { + char buf_l_[PADL_(u_char *)]; u_char * buf; char buf_r_[PADR_(u_char *)]; + char buflen_l_[PADL_(u_int)]; u_int buflen; char buflen_r_[PADR_(u_int)]; +}; +struct sched_setparam_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char param_l_[PADL_(const struct sched_param *)]; const struct sched_param * param; char param_r_[PADR_(const struct sched_param *)]; +}; +struct sched_getparam_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char param_l_[PADL_(struct sched_param *)]; struct sched_param * param; char param_r_[PADR_(struct sched_param *)]; +}; +struct sched_setscheduler_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char policy_l_[PADL_(int)]; int policy; char policy_r_[PADR_(int)]; + char param_l_[PADL_(const struct sched_param *)]; const struct sched_param * param; char param_r_[PADR_(const struct sched_param *)]; +}; +struct sched_getscheduler_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; +}; +struct sched_yield_args { + register_t dummy; +}; +struct sched_get_priority_max_args { + char policy_l_[PADL_(int)]; int policy; char policy_r_[PADR_(int)]; +}; +struct sched_get_priority_min_args { + char policy_l_[PADL_(int)]; int policy; char policy_r_[PADR_(int)]; +}; +struct sched_rr_get_interval_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char interval_l_[PADL_(struct timespec *)]; struct timespec * interval; char interval_r_[PADR_(struct timespec *)]; +}; +struct utrace_args { + char addr_l_[PADL_(const void *)]; const void * addr; char addr_r_[PADR_(const void *)]; + char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)]; +}; +struct kldsym_args { + char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; +}; +struct jail_args { + char jail_l_[PADL_(struct jail *)]; struct jail * jail; char jail_r_[PADR_(struct jail *)]; +}; +struct sigprocmask_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char oset_l_[PADL_(sigset_t *)]; sigset_t * oset; char oset_r_[PADR_(sigset_t *)]; +}; +struct sigsuspend_args { + char sigmask_l_[PADL_(const sigset_t *)]; const sigset_t * sigmask; char sigmask_r_[PADR_(const sigset_t *)]; +}; +struct sigpending_args { + char set_l_[PADL_(sigset_t *)]; sigset_t * set; char set_r_[PADR_(sigset_t *)]; +}; +struct sigtimedwait_args { + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char info_l_[PADL_(siginfo_t *)]; siginfo_t * info; char info_r_[PADR_(siginfo_t *)]; + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct sigwaitinfo_args { + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char info_l_[PADL_(siginfo_t *)]; siginfo_t * info; char info_r_[PADR_(siginfo_t *)]; +}; +struct __acl_get_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_set_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_get_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_set_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_delete_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; +}; +struct __acl_delete_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; +}; +struct __acl_aclcheck_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_aclcheck_fd_args { + char filedes_l_[PADL_(int)]; int filedes; char filedes_r_[PADR_(int)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct extattrctl_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char filename_l_[PADL_(const char *)]; const char * filename; char filename_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct extattr_set_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_get_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_delete_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct aio_waitcomplete_args { + char aiocbp_l_[PADL_(struct aiocb **)]; struct aiocb ** aiocbp; char aiocbp_r_[PADR_(struct aiocb **)]; + char timeout_l_[PADL_(struct timespec *)]; struct timespec * timeout; char timeout_r_[PADR_(struct timespec *)]; +}; +struct getresuid_args { + char ruid_l_[PADL_(uid_t *)]; uid_t * ruid; char ruid_r_[PADR_(uid_t *)]; + char euid_l_[PADL_(uid_t *)]; uid_t * euid; char euid_r_[PADR_(uid_t *)]; + char suid_l_[PADL_(uid_t *)]; uid_t * suid; char suid_r_[PADR_(uid_t *)]; +}; +struct getresgid_args { + char rgid_l_[PADL_(gid_t *)]; gid_t * rgid; char rgid_r_[PADR_(gid_t *)]; + char egid_l_[PADL_(gid_t *)]; gid_t * egid; char egid_r_[PADR_(gid_t *)]; + char sgid_l_[PADL_(gid_t *)]; gid_t * sgid; char sgid_r_[PADR_(gid_t *)]; +}; +struct kqueue_args { + register_t dummy; +}; +struct kevent_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char changelist_l_[PADL_(const struct kevent *)]; const struct kevent * changelist; char changelist_r_[PADR_(const struct kevent *)]; + char nchanges_l_[PADL_(int)]; int nchanges; char nchanges_r_[PADR_(int)]; + char eventlist_l_[PADL_(struct kevent *)]; struct kevent * eventlist; char eventlist_r_[PADR_(struct kevent *)]; + char nevents_l_[PADL_(int)]; int nevents; char nevents_r_[PADR_(int)]; + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct extattr_set_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_get_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_delete_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct __setugid_args { + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; +}; +struct nfsclnt_args { + char flag_l_[PADL_(int)]; int flag; char flag_r_[PADR_(int)]; + char argp_l_[PADL_(caddr_t)]; caddr_t argp; char argp_r_[PADR_(caddr_t)]; +}; +struct eaccess_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct nmount_args { + char iovp_l_[PADL_(struct iovec *)]; struct iovec * iovp; char iovp_r_[PADR_(struct iovec *)]; + char iovcnt_l_[PADL_(unsigned int)]; unsigned int iovcnt; char iovcnt_r_[PADR_(unsigned int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct kse_exit_args { + register_t dummy; +}; +struct kse_wakeup_args { + char mbx_l_[PADL_(struct kse_mailbox *)]; struct kse_mailbox * mbx; char mbx_r_[PADR_(struct kse_mailbox *)]; +}; +struct kse_create_args { + char mbx_l_[PADL_(struct kse_mailbox *)]; struct kse_mailbox * mbx; char mbx_r_[PADR_(struct kse_mailbox *)]; + char newgroup_l_[PADL_(int)]; int newgroup; char newgroup_r_[PADR_(int)]; +}; +struct kse_thr_interrupt_args { + char tmbx_l_[PADL_(struct kse_thr_mailbox *)]; struct kse_thr_mailbox * tmbx; char tmbx_r_[PADR_(struct kse_thr_mailbox *)]; + char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)]; + char data_l_[PADL_(long)]; long data; char data_r_[PADR_(long)]; +}; +struct kse_release_args { + char timeout_l_[PADL_(struct timespec *)]; struct timespec * timeout; char timeout_r_[PADR_(struct timespec *)]; +}; +struct __mac_get_proc_args { + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_proc_args { + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_get_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_get_file_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_file_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct kenv_args { + char what_l_[PADL_(int)]; int what; char what_r_[PADR_(int)]; + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; + char value_l_[PADL_(char *)]; char * value; char value_r_[PADR_(char *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; +}; +struct lchflags_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct uuidgen_args { + char store_l_[PADL_(struct uuid *)]; struct uuid * store; char store_r_[PADR_(struct uuid *)]; + char count_l_[PADL_(int)]; int count; char count_r_[PADR_(int)]; +}; +struct sendfile_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; + char hdtr_l_[PADL_(struct sf_hdtr *)]; struct sf_hdtr * hdtr; char hdtr_r_[PADR_(struct sf_hdtr *)]; + char sbytes_l_[PADL_(off_t *)]; off_t * sbytes; char sbytes_r_[PADR_(off_t *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct mac_syscall_args { + char policy_l_[PADL_(const char *)]; const char * policy; char policy_r_[PADR_(const char *)]; + char call_l_[PADL_(int)]; int call; char call_r_[PADR_(int)]; + char arg_l_[PADL_(void *)]; void * arg; char arg_r_[PADR_(void *)]; +}; +struct getfsstat_args { + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; + char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct statfs_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; +}; +struct fstatfs_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; +}; +struct fhstatfs_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; +}; +struct ksem_close_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_post_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_wait_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_trywait_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct ksem_init_args { + char idp_l_[PADL_(semid_t *)]; semid_t * idp; char idp_r_[PADR_(semid_t *)]; + char value_l_[PADL_(unsigned int)]; unsigned int value; char value_r_[PADR_(unsigned int)]; +}; +struct ksem_open_args { + char idp_l_[PADL_(semid_t *)]; semid_t * idp; char idp_r_[PADR_(semid_t *)]; + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; + char oflag_l_[PADL_(int)]; int oflag; char oflag_r_[PADR_(int)]; + char mode_l_[PADL_(mode_t)]; mode_t mode; char mode_r_[PADR_(mode_t)]; + char value_l_[PADL_(unsigned int)]; unsigned int value; char value_r_[PADR_(unsigned int)]; +}; +struct ksem_unlink_args { + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; +}; +struct ksem_getvalue_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; + char val_l_[PADL_(int *)]; int * val; char val_r_[PADR_(int *)]; +}; +struct ksem_destroy_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; +}; +struct __mac_get_pid_args { + char pid_l_[PADL_(pid_t)]; pid_t pid; char pid_r_[PADR_(pid_t)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_get_link_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct __mac_set_link_args { + char path_p_l_[PADL_(const char *)]; const char * path_p; char path_p_r_[PADR_(const char *)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct extattr_set_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_get_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_delete_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char attrname_l_[PADL_(const char *)]; const char * attrname; char attrname_r_[PADR_(const char *)]; +}; +struct __mac_execve_args { + char fname_l_[PADL_(char *)]; char * fname; char fname_r_[PADR_(char *)]; + char argv_l_[PADL_(char **)]; char ** argv; char argv_r_[PADR_(char **)]; + char envv_l_[PADL_(char **)]; char ** envv; char envv_r_[PADR_(char **)]; + char mac_p_l_[PADL_(struct mac *)]; struct mac * mac_p; char mac_p_r_[PADR_(struct mac *)]; +}; +struct sigaction_args { + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; + char act_l_[PADL_(const struct sigaction *)]; const struct sigaction * act; char act_r_[PADR_(const struct sigaction *)]; + char oact_l_[PADL_(struct sigaction *)]; struct sigaction * oact; char oact_r_[PADR_(struct sigaction *)]; +}; +struct sigreturn_args { + char sigcntxp_l_[PADL_(const struct __ucontext *)]; const struct __ucontext * sigcntxp; char sigcntxp_r_[PADR_(const struct __ucontext *)]; +}; +struct getcontext_args { + char ucp_l_[PADL_(struct __ucontext *)]; struct __ucontext * ucp; char ucp_r_[PADR_(struct __ucontext *)]; +}; +struct setcontext_args { + char ucp_l_[PADL_(const struct __ucontext *)]; const struct __ucontext * ucp; char ucp_r_[PADR_(const struct __ucontext *)]; +}; +struct swapcontext_args { + char oucp_l_[PADL_(struct __ucontext *)]; struct __ucontext * oucp; char oucp_r_[PADR_(struct __ucontext *)]; + char ucp_l_[PADL_(const struct __ucontext *)]; const struct __ucontext * ucp; char ucp_r_[PADR_(const struct __ucontext *)]; +}; +struct swapoff_args { + char name_l_[PADL_(const char *)]; const char * name; char name_r_[PADR_(const char *)]; +}; +struct __acl_get_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_set_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct __acl_delete_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; +}; +struct __acl_aclcheck_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char type_l_[PADL_(acl_type_t)]; acl_type_t type; char type_r_[PADR_(acl_type_t)]; + char aclp_l_[PADL_(struct acl *)]; struct acl * aclp; char aclp_r_[PADR_(struct acl *)]; +}; +struct sigwait_args { + char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)]; + char sig_l_[PADL_(int *)]; int * sig; char sig_r_[PADR_(int *)]; +}; +struct thr_create_args { + char ctx_l_[PADL_(ucontext_t *)]; ucontext_t * ctx; char ctx_r_[PADR_(ucontext_t *)]; + char id_l_[PADL_(thr_id_t *)]; thr_id_t * id; char id_r_[PADR_(thr_id_t *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct thr_exit_args { + register_t dummy; +}; +struct thr_self_args { + char id_l_[PADL_(thr_id_t *)]; thr_id_t * id; char id_r_[PADR_(thr_id_t *)]; +}; +struct thr_kill_args { + char id_l_[PADL_(thr_id_t)]; thr_id_t id; char id_r_[PADR_(thr_id_t)]; + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; +}; +struct _umtx_lock_args { + char umtx_l_[PADL_(struct umtx *)]; struct umtx * umtx; char umtx_r_[PADR_(struct umtx *)]; +}; +struct _umtx_unlock_args { + char umtx_l_[PADL_(struct umtx *)]; struct umtx * umtx; char umtx_r_[PADR_(struct umtx *)]; +}; +struct jail_attach_args { + char jid_l_[PADL_(int)]; int jid; char jid_r_[PADR_(int)]; +}; +struct extattr_list_fd_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_list_file_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct extattr_list_link_args { + char path_l_[PADL_(const char *)]; const char * path; char path_r_[PADR_(const char *)]; + char attrnamespace_l_[PADL_(int)]; int attrnamespace; char attrnamespace_r_[PADR_(int)]; + char data_l_[PADL_(void *)]; void * data; char data_r_[PADR_(void *)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; +}; +struct kse_switchin_args { + char mcp_l_[PADL_(const struct __mcontext *)]; const struct __mcontext * mcp; char mcp_r_[PADR_(const struct __mcontext *)]; + char val_l_[PADL_(long)]; long val; char val_r_[PADR_(long)]; + char loc_l_[PADL_(long *)]; long * loc; char loc_r_[PADR_(long *)]; +}; +struct ksem_timedwait_args { + char id_l_[PADL_(semid_t)]; semid_t id; char id_r_[PADR_(semid_t)]; + char abstime_l_[PADL_(struct timespec *)]; struct timespec * abstime; char abstime_r_[PADR_(struct timespec *)]; +}; +struct thr_suspend_args { + char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)]; +}; +struct thr_wake_args { + char id_l_[PADL_(thr_id_t)]; thr_id_t id; char id_r_[PADR_(thr_id_t)]; +}; +int nosys(struct thread *, struct nosys_args *); +void sys_exit(struct thread *, struct sys_exit_args *); +int fork(struct thread *, struct fork_args *); +int read(struct thread *, struct read_args *); +int write(struct thread *, struct write_args *); +int open(struct thread *, struct open_args *); +int close(struct thread *, struct close_args *); +int wait4(struct thread *, struct wait_args *); +int link(struct thread *, struct link_args *); +int unlink(struct thread *, struct unlink_args *); +int chdir(struct thread *, struct chdir_args *); +int fchdir(struct thread *, struct fchdir_args *); +int mknod(struct thread *, struct mknod_args *); +int chmod(struct thread *, struct chmod_args *); +int chown(struct thread *, struct chown_args *); +int obreak(struct thread *, struct obreak_args *); +int getpid(struct thread *, struct getpid_args *); +int mount(struct thread *, struct mount_args *); +int unmount(struct thread *, struct unmount_args *); +int setuid(struct thread *, struct setuid_args *); +int getuid(struct thread *, struct getuid_args *); +int geteuid(struct thread *, struct geteuid_args *); +int ptrace(struct thread *, struct ptrace_args *); +int recvmsg(struct thread *, struct recvmsg_args *); +int sendmsg(struct thread *, struct sendmsg_args *); +int recvfrom(struct thread *, struct recvfrom_args *); +int accept(struct thread *, struct accept_args *); +int getpeername(struct thread *, struct getpeername_args *); +int getsockname(struct thread *, struct getsockname_args *); +int access(struct thread *, struct access_args *); +int chflags(struct thread *, struct chflags_args *); +int fchflags(struct thread *, struct fchflags_args *); +int sync(struct thread *, struct sync_args *); +int kill(struct thread *, struct kill_args *); +int getppid(struct thread *, struct getppid_args *); +int dup(struct thread *, struct dup_args *); +int pipe(struct thread *, struct pipe_args *); +int getegid(struct thread *, struct getegid_args *); +int profil(struct thread *, struct profil_args *); +int ktrace(struct thread *, struct ktrace_args *); +int getgid(struct thread *, struct getgid_args *); +int getlogin(struct thread *, struct getlogin_args *); +int setlogin(struct thread *, struct setlogin_args *); +int acct(struct thread *, struct acct_args *); +int sigaltstack(struct thread *, struct sigaltstack_args *); +int ioctl(struct thread *, struct ioctl_args *); +int reboot(struct thread *, struct reboot_args *); +int revoke(struct thread *, struct revoke_args *); +int symlink(struct thread *, struct symlink_args *); +int readlink(struct thread *, struct readlink_args *); +int execve(struct thread *, struct execve_args *); +int umask(struct thread *, struct umask_args *); +int chroot(struct thread *, struct chroot_args *); +int msync(struct thread *, struct msync_args *); +int vfork(struct thread *, struct vfork_args *); +int sbrk(struct thread *, struct sbrk_args *); +int sstk(struct thread *, struct sstk_args *); +int ovadvise(struct thread *, struct ovadvise_args *); +int munmap(struct thread *, struct munmap_args *); +int mprotect(struct thread *, struct mprotect_args *); +int madvise(struct thread *, struct madvise_args *); +int mincore(struct thread *, struct mincore_args *); +int getgroups(struct thread *, struct getgroups_args *); +int setgroups(struct thread *, struct setgroups_args *); +int getpgrp(struct thread *, struct getpgrp_args *); +int setpgid(struct thread *, struct setpgid_args *); +int setitimer(struct thread *, struct setitimer_args *); +int swapon(struct thread *, struct swapon_args *); +int getitimer(struct thread *, struct getitimer_args *); +int getdtablesize(struct thread *, struct getdtablesize_args *); +int dup2(struct thread *, struct dup2_args *); +int fcntl(struct thread *, struct fcntl_args *); +int select(struct thread *, struct select_args *); +int fsync(struct thread *, struct fsync_args *); +int setpriority(struct thread *, struct setpriority_args *); +int socket(struct thread *, struct socket_args *); +int connect(struct thread *, struct connect_args *); +int getpriority(struct thread *, struct getpriority_args *); +int bind(struct thread *, struct bind_args *); +int setsockopt(struct thread *, struct setsockopt_args *); +int listen(struct thread *, struct listen_args *); +int gettimeofday(struct thread *, struct gettimeofday_args *); +int getrusage(struct thread *, struct getrusage_args *); +int getsockopt(struct thread *, struct getsockopt_args *); +int readv(struct thread *, struct readv_args *); +int writev(struct thread *, struct writev_args *); +int settimeofday(struct thread *, struct settimeofday_args *); +int fchown(struct thread *, struct fchown_args *); +int fchmod(struct thread *, struct fchmod_args *); +int setreuid(struct thread *, struct setreuid_args *); +int setregid(struct thread *, struct setregid_args *); +int rename(struct thread *, struct rename_args *); +int flock(struct thread *, struct flock_args *); +int mkfifo(struct thread *, struct mkfifo_args *); +int sendto(struct thread *, struct sendto_args *); +int shutdown(struct thread *, struct shutdown_args *); +int socketpair(struct thread *, struct socketpair_args *); +int mkdir(struct thread *, struct mkdir_args *); +int rmdir(struct thread *, struct rmdir_args *); +int utimes(struct thread *, struct utimes_args *); +int adjtime(struct thread *, struct adjtime_args *); +int setsid(struct thread *, struct setsid_args *); +int quotactl(struct thread *, struct quotactl_args *); +int nfssvc(struct thread *, struct nfssvc_args *); +int lgetfh(struct thread *, struct lgetfh_args *); +int getfh(struct thread *, struct getfh_args *); +int getdomainname(struct thread *, struct getdomainname_args *); +int setdomainname(struct thread *, struct setdomainname_args *); +int uname(struct thread *, struct uname_args *); +int sysarch(struct thread *, struct sysarch_args *); +int rtprio(struct thread *, struct rtprio_args *); +int semsys(struct thread *, struct semsys_args *); +int msgsys(struct thread *, struct msgsys_args *); +int shmsys(struct thread *, struct shmsys_args *); +int pread(struct thread *, struct pread_args *); +int pwrite(struct thread *, struct pwrite_args *); +int ntp_adjtime(struct thread *, struct ntp_adjtime_args *); +int setgid(struct thread *, struct setgid_args *); +int setegid(struct thread *, struct setegid_args *); +int seteuid(struct thread *, struct seteuid_args *); +int stat(struct thread *, struct stat_args *); +int fstat(struct thread *, struct fstat_args *); +int lstat(struct thread *, struct lstat_args *); +int pathconf(struct thread *, struct pathconf_args *); +int fpathconf(struct thread *, struct fpathconf_args *); +int getrlimit(struct thread *, struct __getrlimit_args *); +int setrlimit(struct thread *, struct __setrlimit_args *); +int getdirentries(struct thread *, struct getdirentries_args *); +int mmap(struct thread *, struct mmap_args *); +int lseek(struct thread *, struct lseek_args *); +int truncate(struct thread *, struct truncate_args *); +int ftruncate(struct thread *, struct ftruncate_args *); +int __sysctl(struct thread *, struct sysctl_args *); +int mlock(struct thread *, struct mlock_args *); +int munlock(struct thread *, struct munlock_args *); +int undelete(struct thread *, struct undelete_args *); +int futimes(struct thread *, struct futimes_args *); +int getpgid(struct thread *, struct getpgid_args *); +int poll(struct thread *, struct poll_args *); +int lkmnosys(struct thread *, struct nosys_args *); +int __semctl(struct thread *, struct __semctl_args *); +int semget(struct thread *, struct semget_args *); +int semop(struct thread *, struct semop_args *); +int msgctl(struct thread *, struct msgctl_args *); +int msgget(struct thread *, struct msgget_args *); +int msgsnd(struct thread *, struct msgsnd_args *); +int msgrcv(struct thread *, struct msgrcv_args *); +int shmat(struct thread *, struct shmat_args *); +int shmctl(struct thread *, struct shmctl_args *); +int shmdt(struct thread *, struct shmdt_args *); +int shmget(struct thread *, struct shmget_args *); +int clock_gettime(struct thread *, struct clock_gettime_args *); +int clock_settime(struct thread *, struct clock_settime_args *); +int clock_getres(struct thread *, struct clock_getres_args *); +int nanosleep(struct thread *, struct nanosleep_args *); +int minherit(struct thread *, struct minherit_args *); +int rfork(struct thread *, struct rfork_args *); +int openbsd_poll(struct thread *, struct openbsd_poll_args *); +int issetugid(struct thread *, struct issetugid_args *); +int lchown(struct thread *, struct lchown_args *); +int getdents(struct thread *, struct getdents_args *); +int lchmod(struct thread *, struct lchmod_args *); +int lutimes(struct thread *, struct lutimes_args *); +int nstat(struct thread *, struct nstat_args *); +int nfstat(struct thread *, struct nfstat_args *); +int nlstat(struct thread *, struct nlstat_args *); +int fhopen(struct thread *, struct fhopen_args *); +int fhstat(struct thread *, struct fhstat_args *); +int modnext(struct thread *, struct modnext_args *); +int modstat(struct thread *, struct modstat_args *); +int modfnext(struct thread *, struct modfnext_args *); +int modfind(struct thread *, struct modfind_args *); +int kldload(struct thread *, struct kldload_args *); +int kldunload(struct thread *, struct kldunload_args *); +int kldfind(struct thread *, struct kldfind_args *); +int kldnext(struct thread *, struct kldnext_args *); +int kldstat(struct thread *, struct kldstat_args *); +int kldfirstmod(struct thread *, struct kldfirstmod_args *); +int getsid(struct thread *, struct getsid_args *); +int setresuid(struct thread *, struct setresuid_args *); +int setresgid(struct thread *, struct setresgid_args *); +int aio_return(struct thread *, struct aio_return_args *); +int aio_suspend(struct thread *, struct aio_suspend_args *); +int aio_cancel(struct thread *, struct aio_cancel_args *); +int aio_error(struct thread *, struct aio_error_args *); +int aio_read(struct thread *, struct aio_read_args *); +int aio_write(struct thread *, struct aio_write_args *); +int lio_listio(struct thread *, struct lio_listio_args *); +int yield(struct thread *, struct yield_args *); +int mlockall(struct thread *, struct mlockall_args *); +int munlockall(struct thread *, struct munlockall_args *); +int __getcwd(struct thread *, struct __getcwd_args *); +int sched_setparam(struct thread *, struct sched_setparam_args *); +int sched_getparam(struct thread *, struct sched_getparam_args *); +int sched_setscheduler(struct thread *, struct sched_setscheduler_args *); +int sched_getscheduler(struct thread *, struct sched_getscheduler_args *); +int sched_yield(struct thread *, struct sched_yield_args *); +int sched_get_priority_max(struct thread *, struct sched_get_priority_max_args *); +int sched_get_priority_min(struct thread *, struct sched_get_priority_min_args *); +int sched_rr_get_interval(struct thread *, struct sched_rr_get_interval_args *); +int utrace(struct thread *, struct utrace_args *); +int kldsym(struct thread *, struct kldsym_args *); +int jail(struct thread *, struct jail_args *); +int sigprocmask(struct thread *, struct sigprocmask_args *); +int sigsuspend(struct thread *, struct sigsuspend_args *); +int sigpending(struct thread *, struct sigpending_args *); +int sigtimedwait(struct thread *, struct sigtimedwait_args *); +int sigwaitinfo(struct thread *, struct sigwaitinfo_args *); +int __acl_get_file(struct thread *, struct __acl_get_file_args *); +int __acl_set_file(struct thread *, struct __acl_set_file_args *); +int __acl_get_fd(struct thread *, struct __acl_get_fd_args *); +int __acl_set_fd(struct thread *, struct __acl_set_fd_args *); +int __acl_delete_file(struct thread *, struct __acl_delete_file_args *); +int __acl_delete_fd(struct thread *, struct __acl_delete_fd_args *); +int __acl_aclcheck_file(struct thread *, struct __acl_aclcheck_file_args *); +int __acl_aclcheck_fd(struct thread *, struct __acl_aclcheck_fd_args *); +int extattrctl(struct thread *, struct extattrctl_args *); +int extattr_set_file(struct thread *, struct extattr_set_file_args *); +int extattr_get_file(struct thread *, struct extattr_get_file_args *); +int extattr_delete_file(struct thread *, struct extattr_delete_file_args *); +int aio_waitcomplete(struct thread *, struct aio_waitcomplete_args *); +int getresuid(struct thread *, struct getresuid_args *); +int getresgid(struct thread *, struct getresgid_args *); +int kqueue(struct thread *, struct kqueue_args *); +int kevent(struct thread *, struct kevent_args *); +int lkmressys(struct thread *, struct nosys_args *); +int extattr_set_fd(struct thread *, struct extattr_set_fd_args *); +int extattr_get_fd(struct thread *, struct extattr_get_fd_args *); +int extattr_delete_fd(struct thread *, struct extattr_delete_fd_args *); +int __setugid(struct thread *, struct __setugid_args *); +int nfsclnt(struct thread *, struct nfsclnt_args *); +int eaccess(struct thread *, struct eaccess_args *); +int nmount(struct thread *, struct nmount_args *); +int kse_exit(struct thread *, struct kse_exit_args *); +int kse_wakeup(struct thread *, struct kse_wakeup_args *); +int kse_create(struct thread *, struct kse_create_args *); +int kse_thr_interrupt(struct thread *, struct kse_thr_interrupt_args *); +int kse_release(struct thread *, struct kse_release_args *); +int __mac_get_proc(struct thread *, struct __mac_get_proc_args *); +int __mac_set_proc(struct thread *, struct __mac_set_proc_args *); +int __mac_get_fd(struct thread *, struct __mac_get_fd_args *); +int __mac_get_file(struct thread *, struct __mac_get_file_args *); +int __mac_set_fd(struct thread *, struct __mac_set_fd_args *); +int __mac_set_file(struct thread *, struct __mac_set_file_args *); +int kenv(struct thread *, struct kenv_args *); +int lchflags(struct thread *, struct lchflags_args *); +int uuidgen(struct thread *, struct uuidgen_args *); +int sendfile(struct thread *, struct sendfile_args *); +int mac_syscall(struct thread *, struct mac_syscall_args *); +int getfsstat(struct thread *, struct getfsstat_args *); +int statfs(struct thread *, struct statfs_args *); +int fstatfs(struct thread *, struct fstatfs_args *); +int fhstatfs(struct thread *, struct fhstatfs_args *); +int ksem_close(struct thread *, struct ksem_close_args *); +int ksem_post(struct thread *, struct ksem_post_args *); +int ksem_wait(struct thread *, struct ksem_wait_args *); +int ksem_trywait(struct thread *, struct ksem_trywait_args *); +int ksem_init(struct thread *, struct ksem_init_args *); +int ksem_open(struct thread *, struct ksem_open_args *); +int ksem_unlink(struct thread *, struct ksem_unlink_args *); +int ksem_getvalue(struct thread *, struct ksem_getvalue_args *); +int ksem_destroy(struct thread *, struct ksem_destroy_args *); +int __mac_get_pid(struct thread *, struct __mac_get_pid_args *); +int __mac_get_link(struct thread *, struct __mac_get_link_args *); +int __mac_set_link(struct thread *, struct __mac_set_link_args *); +int extattr_set_link(struct thread *, struct extattr_set_link_args *); +int extattr_get_link(struct thread *, struct extattr_get_link_args *); +int extattr_delete_link(struct thread *, struct extattr_delete_link_args *); +int __mac_execve(struct thread *, struct __mac_execve_args *); +int sigaction(struct thread *, struct sigaction_args *); +int sigreturn(struct thread *, struct sigreturn_args *); +int getcontext(struct thread *, struct getcontext_args *); +int setcontext(struct thread *, struct setcontext_args *); +int swapcontext(struct thread *, struct swapcontext_args *); +int swapoff(struct thread *, struct swapoff_args *); +int __acl_get_link(struct thread *, struct __acl_get_link_args *); +int __acl_set_link(struct thread *, struct __acl_set_link_args *); +int __acl_delete_link(struct thread *, struct __acl_delete_link_args *); +int __acl_aclcheck_link(struct thread *, struct __acl_aclcheck_link_args *); +int sigwait(struct thread *, struct sigwait_args *); +int thr_create(struct thread *, struct thr_create_args *); +int thr_exit(struct thread *, struct thr_exit_args *); +int thr_self(struct thread *, struct thr_self_args *); +int thr_kill(struct thread *, struct thr_kill_args *); +int _umtx_lock(struct thread *, struct _umtx_lock_args *); +int _umtx_unlock(struct thread *, struct _umtx_unlock_args *); +int jail_attach(struct thread *, struct jail_attach_args *); +int extattr_list_fd(struct thread *, struct extattr_list_fd_args *); +int extattr_list_file(struct thread *, struct extattr_list_file_args *); +int extattr_list_link(struct thread *, struct extattr_list_link_args *); +int kse_switchin(struct thread *, struct kse_switchin_args *); +int ksem_timedwait(struct thread *, struct ksem_timedwait_args *); +int thr_suspend(struct thread *, struct thr_suspend_args *); +int thr_wake(struct thread *, struct thr_wake_args *); + +#ifdef COMPAT_43 + +struct ocreat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; +}; +struct olseek_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char offset_l_[PADL_(long)]; long offset; char offset_r_[PADR_(long)]; + char whence_l_[PADL_(int)]; int whence; char whence_r_[PADR_(int)]; +}; +struct ostat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct ostat *)]; struct ostat * ub; char ub_r_[PADR_(struct ostat *)]; +}; +struct olstat_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char ub_l_[PADL_(struct ostat *)]; struct ostat * ub; char ub_r_[PADR_(struct ostat *)]; +}; +struct osigaction_args { + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; + char nsa_l_[PADL_(struct osigaction *)]; struct osigaction * nsa; char nsa_r_[PADR_(struct osigaction *)]; + char osa_l_[PADL_(struct osigaction *)]; struct osigaction * osa; char osa_r_[PADR_(struct osigaction *)]; +}; +struct osigprocmask_args { + char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)]; + char mask_l_[PADL_(osigset_t)]; osigset_t mask; char mask_r_[PADR_(osigset_t)]; +}; +struct ofstat_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char sb_l_[PADL_(struct ostat *)]; struct ostat * sb; char sb_r_[PADR_(struct ostat *)]; +}; +struct getkerninfo_args { + char op_l_[PADL_(int)]; int op; char op_r_[PADR_(int)]; + char where_l_[PADL_(char *)]; char * where; char where_r_[PADR_(char *)]; + char size_l_[PADL_(size_t *)]; size_t * size; char size_r_[PADR_(size_t *)]; + char arg_l_[PADL_(int)]; int arg; char arg_r_[PADR_(int)]; +}; +struct ommap_args { + char addr_l_[PADL_(void *)]; void * addr; char addr_r_[PADR_(void *)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; + char prot_l_[PADL_(int)]; int prot; char prot_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char pos_l_[PADL_(long)]; long pos; char pos_r_[PADR_(long)]; +}; +struct gethostname_args { + char hostname_l_[PADL_(char *)]; char * hostname; char hostname_r_[PADR_(char *)]; + char len_l_[PADL_(u_int)]; u_int len; char len_r_[PADR_(u_int)]; +}; +struct sethostname_args { + char hostname_l_[PADL_(char *)]; char * hostname; char hostname_r_[PADR_(char *)]; + char len_l_[PADL_(u_int)]; u_int len; char len_r_[PADR_(u_int)]; +}; +struct osend_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct orecv_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)]; + char len_l_[PADL_(int)]; int len; char len_r_[PADR_(int)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct osigreturn_args { + char sigcntxp_l_[PADL_(struct osigcontext *)]; struct osigcontext * sigcntxp; char sigcntxp_r_[PADR_(struct osigcontext *)]; +}; +struct osigvec_args { + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; + char nsv_l_[PADL_(struct sigvec *)]; struct sigvec * nsv; char nsv_r_[PADR_(struct sigvec *)]; + char osv_l_[PADL_(struct sigvec *)]; struct sigvec * osv; char osv_r_[PADR_(struct sigvec *)]; +}; +struct osigblock_args { + char mask_l_[PADL_(int)]; int mask; char mask_r_[PADR_(int)]; +}; +struct osigsetmask_args { + char mask_l_[PADL_(int)]; int mask; char mask_r_[PADR_(int)]; +}; +struct osigsuspend_args { + char mask_l_[PADL_(osigset_t)]; osigset_t mask; char mask_r_[PADR_(osigset_t)]; +}; +struct osigstack_args { + char nss_l_[PADL_(struct sigstack *)]; struct sigstack * nss; char nss_r_[PADR_(struct sigstack *)]; + char oss_l_[PADL_(struct sigstack *)]; struct sigstack * oss; char oss_r_[PADR_(struct sigstack *)]; +}; +struct orecvmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(struct omsghdr *)]; struct omsghdr * msg; char msg_r_[PADR_(struct omsghdr *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct osendmsg_args { + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char msg_l_[PADL_(caddr_t)]; caddr_t msg; char msg_r_[PADR_(caddr_t)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct otruncate_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char length_l_[PADL_(long)]; long length; char length_r_[PADR_(long)]; +}; +struct oftruncate_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char length_l_[PADL_(long)]; long length; char length_r_[PADR_(long)]; +}; +struct ogetpeername_args { + char fdes_l_[PADL_(int)]; int fdes; char fdes_r_[PADR_(int)]; + char asa_l_[PADL_(caddr_t)]; caddr_t asa; char asa_r_[PADR_(caddr_t)]; + char alen_l_[PADL_(int *)]; int * alen; char alen_r_[PADR_(int *)]; +}; +struct osethostid_args { + char hostid_l_[PADL_(long)]; long hostid; char hostid_r_[PADR_(long)]; +}; +struct ogetrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct orlimit *)]; struct orlimit * rlp; char rlp_r_[PADR_(struct orlimit *)]; +}; +struct osetrlimit_args { + char which_l_[PADL_(u_int)]; u_int which; char which_r_[PADR_(u_int)]; + char rlp_l_[PADL_(struct orlimit *)]; struct orlimit * rlp; char rlp_r_[PADR_(struct orlimit *)]; +}; +struct okillpg_args { + char pgid_l_[PADL_(int)]; int pgid; char pgid_r_[PADR_(int)]; + char signum_l_[PADL_(int)]; int signum; char signum_r_[PADR_(int)]; +}; +struct ogetdirentries_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(char *)]; char * buf; char buf_r_[PADR_(char *)]; + char count_l_[PADL_(u_int)]; u_int count; char count_r_[PADR_(u_int)]; + char basep_l_[PADL_(long *)]; long * basep; char basep_r_[PADR_(long *)]; +}; +int ocreat(struct thread *, struct ocreat_args *); +int olseek(struct thread *, struct olseek_args *); +int ostat(struct thread *, struct ostat_args *); +int olstat(struct thread *, struct olstat_args *); +int osigaction(struct thread *, struct osigaction_args *); +int osigprocmask(struct thread *, struct osigprocmask_args *); +int osigpending(struct thread *, struct osigpending_args *); +int ofstat(struct thread *, struct ofstat_args *); +int ogetkerninfo(struct thread *, struct getkerninfo_args *); +int ogetpagesize(struct thread *, struct getpagesize_args *); +int ommap(struct thread *, struct ommap_args *); +int owait(struct thread *, struct owait_args *); +int ogethostname(struct thread *, struct gethostname_args *); +int osethostname(struct thread *, struct sethostname_args *); +int oaccept(struct thread *, struct accept_args *); +int osend(struct thread *, struct osend_args *); +int orecv(struct thread *, struct orecv_args *); +int osigreturn(struct thread *, struct osigreturn_args *); +int osigvec(struct thread *, struct osigvec_args *); +int osigblock(struct thread *, struct osigblock_args *); +int osigsetmask(struct thread *, struct osigsetmask_args *); +int osigsuspend(struct thread *, struct osigsuspend_args *); +int osigstack(struct thread *, struct osigstack_args *); +int orecvmsg(struct thread *, struct orecvmsg_args *); +int osendmsg(struct thread *, struct osendmsg_args *); +int orecvfrom(struct thread *, struct recvfrom_args *); +int otruncate(struct thread *, struct otruncate_args *); +int oftruncate(struct thread *, struct oftruncate_args *); +int ogetpeername(struct thread *, struct ogetpeername_args *); +int ogethostid(struct thread *, struct ogethostid_args *); +int osethostid(struct thread *, struct osethostid_args *); +int ogetrlimit(struct thread *, struct ogetrlimit_args *); +int osetrlimit(struct thread *, struct osetrlimit_args *); +int okillpg(struct thread *, struct okillpg_args *); +int oquota(struct thread *, struct oquota_args *); +int ogetsockname(struct thread *, struct getsockname_args *); +int ogetdirentries(struct thread *, struct ogetdirentries_args *); + +#endif /* COMPAT_43 */ + + +#ifdef COMPAT_FREEBSD4 + +struct freebsd4_getfsstat_args { + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; + char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct freebsd4_statfs_args { + char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; +}; +struct freebsd4_fstatfs_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; +}; +struct freebsd4_fhstatfs_args { + char u_fhp_l_[PADL_(const struct fhandle *)]; const struct fhandle * u_fhp; char u_fhp_r_[PADR_(const struct fhandle *)]; + char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; +}; +struct freebsd4_sendfile_args { + char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)]; + char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)]; + char offset_l_[PADL_(off_t)]; off_t offset; char offset_r_[PADR_(off_t)]; + char nbytes_l_[PADL_(size_t)]; size_t nbytes; char nbytes_r_[PADR_(size_t)]; + char hdtr_l_[PADL_(struct sf_hdtr *)]; struct sf_hdtr * hdtr; char hdtr_r_[PADR_(struct sf_hdtr *)]; + char sbytes_l_[PADL_(off_t *)]; off_t * sbytes; char sbytes_r_[PADR_(off_t *)]; + char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; +}; +struct freebsd4_sigaction_args { + char sig_l_[PADL_(int)]; int sig; char sig_r_[PADR_(int)]; + char act_l_[PADL_(const struct sigaction *)]; const struct sigaction * act; char act_r_[PADR_(const struct sigaction *)]; + char oact_l_[PADL_(struct sigaction *)]; struct sigaction * oact; char oact_r_[PADR_(struct sigaction *)]; +}; +struct freebsd4_sigreturn_args { + char sigcntxp_l_[PADL_(const struct ucontext4 *)]; const struct ucontext4 * sigcntxp; char sigcntxp_r_[PADR_(const struct ucontext4 *)]; +}; +int freebsd4_getfsstat(struct thread *, struct freebsd4_getfsstat_args *); +int freebsd4_statfs(struct thread *, struct freebsd4_statfs_args *); +int freebsd4_fstatfs(struct thread *, struct freebsd4_fstatfs_args *); +int freebsd4_fhstatfs(struct thread *, struct freebsd4_fhstatfs_args *); +int freebsd4_sendfile(struct thread *, struct freebsd4_sendfile_args *); +int freebsd4_sigaction(struct thread *, struct freebsd4_sigaction_args *); +int freebsd4_sigreturn(struct thread *, struct freebsd4_sigreturn_args *); + +#endif /* COMPAT_FREEBSD4 */ + +#undef PAD_ +#undef PADL_ +#undef PADR_ + +#endif /* !_SYS_SYSPROTO_H_ */ diff --git a/src/include/sys/systm.h b/src/include/sys/systm.h new file mode 100644 index 0000000..e05b056 --- /dev/null +++ b/src/include/sys/systm.h @@ -0,0 +1,330 @@ +/*- + * Copyright (c) 1982, 1988, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)systm.h 8.7 (Berkeley) 3/29/95 + * $FreeBSD: src/sys/sys/systm.h,v 1.205 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SYSTM_H_ +#define _SYS_SYSTM_H_ + +#include +#include +#include +#include +#include +#include /* for people using printf mainly */ + +extern int securelevel; /* system security level (see init(8)) */ +extern int suser_enabled; /* suser() is permitted to return 0 */ + +extern int cold; /* nonzero if we are doing a cold boot */ +extern const char *panicstr; /* panic message */ +extern char version[]; /* system version */ +extern char copyright[]; /* system copyright */ +extern int kstack_pages; /* number of kernel stack pages */ +extern int uarea_pages; /* number of user struct pages */ + +extern int nswap; /* size of swap space */ + +extern u_int nselcoll; /* select collisions since boot */ +extern struct mtx sellock; /* select lock variable */ +extern struct cv selwait; /* select conditional variable */ + +extern long physmem; /* physical memory */ + +extern dev_t rootdev; /* root device */ +extern dev_t rootdevs[2]; /* possible root devices */ +extern char *rootdevnames[2]; /* names of possible root devices */ +extern struct vnode *rootvp; /* vnode equivalent to above */ + +extern int boothowto; /* reboot flags, from console subsystem */ +extern int bootverbose; /* nonzero to print verbose messages */ + +extern int maxusers; /* system tune hint */ + +#ifdef INVARIANTS /* The option is always available */ +#define KASSERT(exp,msg) do { \ + if (__predict_false(!(exp))) \ + panic msg; \ +} while (0) +#else +#define KASSERT(exp,msg) +#endif + +#ifndef CTASSERT /* Allow lint to override */ +#define CTASSERT(x) _CTASSERT(x, __LINE__) +#define _CTASSERT(x, y) __CTASSERT(x, y) +#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] +#endif + +/* + * XXX the hints declarations are even more misplaced than most declarations + * in this file, since they are needed in one file (per arch) and only used + * in two files. + * XXX most of these variables should be const. + */ +extern int envmode; +extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */ +extern int dynamic_kenv; +extern struct sx kenv_lock; +extern char *kern_envp; +extern char static_env[]; +extern char static_hints[]; /* by config for now */ + +extern char **kenvp; + +/* + * General function declarations. + */ + +struct clockframe; +struct malloc_type; +struct mtx; +struct proc; +struct kse; +struct socket; +struct thread; +struct tty; +struct ucred; +struct uio; +struct _jmp_buf; + +int setjmp(struct _jmp_buf *); +void longjmp(struct _jmp_buf *, int) __dead2; +void Debugger(const char *msg) __nonnull(1); +int dumpstatus(vm_offset_t addr, off_t count); +int nullop(void); +int eopnotsupp(void); +int ureadc(int, struct uio *); +void hashdestroy(void *, struct malloc_type *, u_long); +void *hashinit(int count, struct malloc_type *type, u_long *hashmask); +void *phashinit(int count, struct malloc_type *type, u_long *nentries); + +#ifdef RESTARTABLE_PANICS +void __panic(const char *file, int line, const char *, ...) __printflike(3, 4); +#else +void __panic(const char *file, int line, const char *, ...) __dead2 __printflike(3, 4); +#endif + +#define panic(...) __panic(__FILE__, __LINE__, __VA_ARGS__) + +void backtrace(void); +void cpu_boot(int); +void cpu_rootconf(void); +extern uint32_t crc32_tab[]; +uint32_t crc32(const void *buf, size_t size); +void critical_enter(void); +void critical_exit(void); +void init_param1(void); +void init_param2(long physpages); +void init_param3(long kmempages); +void tablefull(const char *); +int kvprintf(char const *, void (*)(int, void*), void *, int, + __va_list) __printflike(1, 0); +void log(int, const char *, ...) __printflike(2, 3); +void log_console(struct uio *); +int printf(const char *, ...) __printflike(1, 2); +int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); +int sprintf(char *buf, const char *, ...) __printflike(2, 3); +int uprintf(const char *, ...) __printflike(1, 2); +int vprintf(const char *, __va_list) __printflike(1, 0); +int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); +int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0); +int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0); +int ttyprintf(struct tty *, const char *, ...) __printflike(2, 3); +int sscanf(const char *, char const *, ...) __nonnull(1) __nonnull(2); +int vsscanf(const char *, char const *, __va_list) __nonnull(1) __nonnull(2); +long strtol(const char *, char **, int) __nonnull(1); +u_long strtoul(const char *, char **, int) __nonnull(1); +quad_t strtoq(const char *, char **, int) __nonnull(1); +u_quad_t strtouq(const char *, char **, int) __nonnull(1); +void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4); +void hexdump(void *ptr, int length, const char *hdr, int flags); +#define HD_COLUMN_MASK 0xff +#define HD_DELIM_MASK 0xff00 +#define HD_OMIT_COUNT (1 << 16) +#define HD_OMIT_HEX (1 << 17) +#define HD_OMIT_CHARS (1 << 18) + +#define ovbcopy(f, t, l) bcopy((f), (t), (l)) +void bcopy(const void *from, void *to, size_t len) __nonnull(1) __nonnull(2); +void bzero(void *buf, size_t len) __nonnull(1); + +void *memcpy(void *to, const void *from, size_t len) __nonnull(1) __nonnull(2); + +int copystr(const void * __restrict kfaddr, void * __restrict kdaddr, + size_t len, size_t * __restrict lencopied) + __nonnull(1) __nonnull(2); +int copyinstr(const void * __restrict udaddr, void * __restrict kaddr, + size_t len, size_t * __restrict lencopied) + __nonnull(1) __nonnull(2); +int copyin(const void * __restrict udaddr, void * __restrict kaddr, + size_t len) __nonnull(1) __nonnull(2); +int copyout(const void * __restrict kaddr, void * __restrict udaddr, + size_t len) __nonnull(1) __nonnull(2); + +int fubyte(const void *base); +long fuword(const void *base); +int fuword16(void *base); +int32_t fuword32(const void *base); +int64_t fuword64(const void *base); +int subyte(void *base, int byte); +int suword(void *base, long word); +int suword16(void *base, int word); +int suword32(void *base, int32_t word); +int suword64(void *base, int64_t word); +intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t new); + +void realitexpire(void *); + +void hardclock(struct clockframe *frame); +void hardclock_process(struct clockframe *frame); +void softclock(void *); +void statclock(struct clockframe *frame); +void profclock(struct clockframe *frame); + +void startprofclock(struct proc *); +void stopprofclock(struct proc *); +void cpu_startprofclock(void); +void cpu_stopprofclock(void); + +/* flags for suser() and suser_cred() */ +#define PRISON_ROOT 1 + +int suser(struct thread *td); +int suser_cred(struct ucred *cred, int flag); +int cr_cansee(struct ucred *u1, struct ucred *u2); +int cr_canseesocket(struct ucred *cred, struct socket *so); + +char *getenv(const char *name); +void freeenv(char *env); +int getenv_int(const char *name, int *data); +int getenv_string(const char *name, char *data, int size); +int getenv_quad(const char *name, quad_t *data); +int setenv(const char *name, const char *value); +int unsetenv(const char *name); +int testenv(const char *name); + +#ifdef APM_FIXUP_CALLTODO +struct timeval; +void adjust_timeout_calltodo(struct timeval *time_change); +#endif /* APM_FIXUP_CALLTODO */ + +#include + +/* Initialize the world */ +void consinit(void); +void cpu_initclocks(void); +void usrinfoinit(void); + +/* Finalize the world. */ +void shutdown_nice(int); + +/* + * Kernel to clock driver interface. + */ +void inittodr(time_t base); +void resettodr(void); +void startrtclock(void); + +/* Timeouts */ +typedef void timeout_t(void *); /* timeout function type */ +#define CALLOUT_HANDLE_INITIALIZER(handle) \ + { NULL } + +void callout_handle_init(struct callout_handle *); +struct callout_handle timeout(timeout_t *, void *, int); +void untimeout(timeout_t *, void *, struct callout_handle); +caddr_t kern_timeout_callwheel_alloc(caddr_t v); +void kern_timeout_callwheel_init(void); + +/* Stubs for obsolete functions that used to be for interrupt management */ +static __inline void spl0(void) { return; } +static __inline intrmask_t splbio(void) { return 0; } +static __inline intrmask_t splcam(void) { return 0; } +static __inline intrmask_t splclock(void) { return 0; } +static __inline intrmask_t splhigh(void) { return 0; } +static __inline intrmask_t splimp(void) { return 0; } +static __inline intrmask_t splnet(void) { return 0; } +static __inline intrmask_t splsoftcam(void) { return 0; } +static __inline intrmask_t splsoftclock(void) { return 0; } +static __inline intrmask_t splsofttty(void) { return 0; } +static __inline intrmask_t splsoftvm(void) { return 0; } +static __inline intrmask_t splsofttq(void) { return 0; } +static __inline intrmask_t splstatclock(void) { return 0; } +static __inline intrmask_t spltty(void) { return 0; } +static __inline intrmask_t splvm(void) { return 0; } +static __inline void splx(intrmask_t ipl __unused) { return; } + +/* + * Various callout lists. + */ + +/* + * Not exactly a callout LIST, but a callout entry. + * Allow an external module to define a hardware watchdog tickler. + * Normally a process would do this, but there are times when the + * kernel needs to be able to hold off the watchdog, when the process + * is not active, e.g., when dumping core. + */ +typedef void (*watchdog_tickle_fn)(void); + +extern watchdog_tickle_fn wdog_tickler; + +/* + * Common `proc' functions are declared here so that proc.h can be included + * less often. + */ +int msleep(void *chan, struct mtx *mtx, int pri, const char *wmesg, + int timo); +#define tsleep(chan, pri, wmesg, timo) msleep(chan, NULL, pri, wmesg, timo) +void wakeup(void *chan) __nonnull(1); +void wakeup_one(void *chan) __nonnull(1); + +/* + * Common `dev_t' stuff are declared here to avoid #include poisoning + */ + +int major(dev_t x); +int minor(dev_t x); +udev_t dev2udev(dev_t x); +dev_t udev2dev(udev_t x); +int uminor(udev_t dev); +int umajor(udev_t dev); +udev_t makeudev(int x, int y); + +/* XXX: Should be void nanodelay(u_int nsec); */ +void DELAY(int usec); + +#endif /* !_SYS_SYSTM_H_ */ diff --git a/src/include/sys/taskqueue.h b/src/include/sys/taskqueue.h new file mode 100644 index 0000000..05e859e --- /dev/null +++ b/src/include/sys/taskqueue.h @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2000 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/taskqueue.h,v 1.10 2004/01/23 20:44:26 rwatson Exp $ + */ + +#ifndef _SYS_TASKQUEUE_H_ +#define _SYS_TASKQUEUE_H_ + +#ifndef _KERNEL +#error "no user-servicable parts inside" +#endif + +#include +#include + +struct taskqueue; + +/* + * A notification callback function which is called from + * taskqueue_enqueue(). The context argument is given in the call to + * taskqueue_create(). This function would normally be used to allow the + * queue to arrange to run itself later (e.g., by scheduling a software + * interrupt or waking a kernel thread). + */ +typedef void (*taskqueue_enqueue_fn)(void *context); + +struct taskqueue *taskqueue_create(const char *name, int mflags, + taskqueue_enqueue_fn enqueue, + void *context); +int taskqueue_enqueue(struct taskqueue *queue, struct task *task); +struct taskqueue *taskqueue_find(const char *name); +void taskqueue_free(struct taskqueue *queue); +void taskqueue_run(struct taskqueue *queue); + +/* + * Initialise a task structure. + */ +#define TASK_INIT(task, priority, func, context) do { \ + (task)->ta_pending = 0; \ + (task)->ta_priority = (priority); \ + (task)->ta_func = (func); \ + (task)->ta_context = (context); \ +} while (0) + +/* + * Declare a reference to a taskqueue. + */ +#define TASKQUEUE_DECLARE(name) \ +extern struct taskqueue *taskqueue_##name + +/* + * Define and initialise a taskqueue. + */ +#define TASKQUEUE_DEFINE(name, enqueue, context, init) \ + \ +struct taskqueue *taskqueue_##name; \ + \ +static void \ +taskqueue_define_##name(void *arg) \ +{ \ + taskqueue_##name = \ + taskqueue_create(#name, M_NOWAIT, (enqueue), (context)); \ + init; \ +} \ + \ +SYSINIT(taskqueue_##name, SI_SUB_CONFIGURE, SI_ORDER_SECOND, \ + taskqueue_define_##name, NULL) \ + \ +struct __hack + +/* + * These queues are serviced by software interrupt handlers. To enqueue + * a task, call taskqueue_enqueue(taskqueue_swi, &task) or + * taskqueue_enqueue(taskqueue_swi_giant, &task). + */ +TASKQUEUE_DECLARE(swi_giant); +TASKQUEUE_DECLARE(swi); + +/* + * This queue is serviced by a kernel thread. To enqueue a task, call + * taskqueue_enqueue(taskqueue_thread, &task). + */ +TASKQUEUE_DECLARE(thread); + +/* + * Queue for swi handlers dispatched from fast interrupt handlers. + * These are necessarily different from the above because the queue + * must be locked with spinlocks since sleep mutex's cannot be used + * from a fast interrupt handler context. + */ +TASKQUEUE_DECLARE(fast); +int taskqueue_enqueue_fast(struct taskqueue *queue, struct task *task); + +#endif /* !_SYS_TASKQUEUE_H_ */ diff --git a/src/include/sys/termios.h b/src/include/sys/termios.h new file mode 100644 index 0000000..a5621d0 --- /dev/null +++ b/src/include/sys/termios.h @@ -0,0 +1,284 @@ +/* + * Copyright (c) 1988, 1989, 1993, 1994 + * 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. + * 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. + * + * @(#)termios.h 8.3 (Berkeley) 3/28/94 + * $FreeBSD: src/sys/sys/termios.h,v 1.19 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +/* + * Special Control Characters + * + * Index into c_cc[] character array. + * + * Name Subscript Enabled by + */ +#define VEOF 0 /* ICANON */ +#define VEOL 1 /* ICANON */ +#ifndef _POSIX_SOURCE +#define VEOL2 2 /* ICANON together with IEXTEN */ +#endif +#define VERASE 3 /* ICANON */ +#ifndef _POSIX_SOURCE +#define VWERASE 4 /* ICANON together with IEXTEN */ +#endif +#define VKILL 5 /* ICANON */ +#ifndef _POSIX_SOURCE +#define VREPRINT 6 /* ICANON together with IEXTEN */ +#define VERASE2 7 /* ICANON */ +#endif +/* 7 ex-spare 1 */ +#define VINTR 8 /* ISIG */ +#define VQUIT 9 /* ISIG */ +#define VSUSP 10 /* ISIG */ +#ifndef _POSIX_SOURCE +#define VDSUSP 11 /* ISIG together with IEXTEN */ +#endif +#define VSTART 12 /* IXON, IXOFF */ +#define VSTOP 13 /* IXON, IXOFF */ +#ifndef _POSIX_SOURCE +#define VLNEXT 14 /* IEXTEN */ +#define VDISCARD 15 /* IEXTEN */ +#endif +#define VMIN 16 /* !ICANON */ +#define VTIME 17 /* !ICANON */ +#ifndef _POSIX_SOURCE +#define VSTATUS 18 /* ICANON together with IEXTEN */ +/* 19 spare 2 */ +#endif +#define NCCS 20 + +#define _POSIX_VDISABLE 0xff + +#ifndef _POSIX_SOURCE +#define CCEQ(val, c) ((c) == (val) ? (val) != _POSIX_VDISABLE : 0) +#endif + +/* + * Input flags - software input processing + */ +#define IGNBRK 0x00000001 /* ignore BREAK condition */ +#define BRKINT 0x00000002 /* map BREAK to SIGINTR */ +#define IGNPAR 0x00000004 /* ignore (discard) parity errors */ +#define PARMRK 0x00000008 /* mark parity and framing errors */ +#define INPCK 0x00000010 /* enable checking of parity errors */ +#define ISTRIP 0x00000020 /* strip 8th bit off chars */ +#define INLCR 0x00000040 /* map NL into CR */ +#define IGNCR 0x00000080 /* ignore CR */ +#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */ +#define IXON 0x00000200 /* enable output flow control */ +#define IXOFF 0x00000400 /* enable input flow control */ +#ifndef _POSIX_SOURCE +#define IXANY 0x00000800 /* any char will restart after stop */ +#define IMAXBEL 0x00002000 /* ring bell on input queue full */ +#endif /*_POSIX_SOURCE */ + +/* + * Output flags - software output processing + */ +#define OPOST 0x00000001 /* enable following output processing */ +#ifndef _POSIX_SOURCE +#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */ +#define OXTABS 0x00000004 /* expand tabs to spaces */ +#define ONOEOT 0x00000008 /* discard EOT's (^D) on output) */ +#define OCRNL 0x00000010 /* map CR to NL on output */ +#define ONOCR 0x00000020 /* no CR output at column 0 */ +#define ONLRET 0x00000040 /* NL performs CR function */ +#endif /*_POSIX_SOURCE */ + +/* + * Control flags - hardware control of terminal + */ +#ifndef _POSIX_SOURCE +#define CIGNORE 0x00000001 /* ignore control flags */ +#endif +#define CSIZE 0x00000300 /* character size mask */ +#define CS5 0x00000000 /* 5 bits (pseudo) */ +#define CS6 0x00000100 /* 6 bits */ +#define CS7 0x00000200 /* 7 bits */ +#define CS8 0x00000300 /* 8 bits */ +#define CSTOPB 0x00000400 /* send 2 stop bits */ +#define CREAD 0x00000800 /* enable receiver */ +#define PARENB 0x00001000 /* parity enable */ +#define PARODD 0x00002000 /* odd parity, else even */ +#define HUPCL 0x00004000 /* hang up on last close */ +#define CLOCAL 0x00008000 /* ignore modem status lines */ +#ifndef _POSIX_SOURCE +#define CCTS_OFLOW 0x00010000 /* CTS flow control of output */ +#define CRTSCTS (CCTS_OFLOW | CRTS_IFLOW) +#define CRTS_IFLOW 0x00020000 /* RTS flow control of input */ +#define CDTR_IFLOW 0x00040000 /* DTR flow control of input */ +#define CDSR_OFLOW 0x00080000 /* DSR flow control of output */ +#define CCAR_OFLOW 0x00100000 /* DCD flow control of output */ +#define MDMBUF 0x00100000 /* old name for CCAR_OFLOW */ +#endif + + +/* + * "Local" flags - dumping ground for other state + * + * Warning: some flags in this structure begin with + * the letter "I" and look like they belong in the + * input flag. + */ + +#ifndef _POSIX_SOURCE +#define ECHOKE 0x00000001 /* visual erase for line kill */ +#endif /*_POSIX_SOURCE */ +#define ECHOE 0x00000002 /* visually erase chars */ +#define ECHOK 0x00000004 /* echo NL after line kill */ +#define ECHO 0x00000008 /* enable echoing */ +#define ECHONL 0x00000010 /* echo NL even if ECHO is off */ +#ifndef _POSIX_SOURCE +#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */ +#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */ +#endif /*_POSIX_SOURCE */ +#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */ +#define ICANON 0x00000100 /* canonicalize input lines */ +#ifndef _POSIX_SOURCE +#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */ +#endif /*_POSIX_SOURCE */ +#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */ +#define EXTPROC 0x00000800 /* external processing */ +#define TOSTOP 0x00400000 /* stop background jobs from output */ +#ifndef _POSIX_SOURCE +#define FLUSHO 0x00800000 /* output being flushed (state) */ +#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */ +#define PENDIN 0x20000000 /* XXX retype pending input (state) */ +#endif /*_POSIX_SOURCE */ +#define NOFLSH 0x80000000 /* don't flush after interrupt */ + +typedef unsigned int tcflag_t; +typedef unsigned char cc_t; +typedef unsigned int speed_t; + +struct termios { + tcflag_t c_iflag; /* input flags */ + tcflag_t c_oflag; /* output flags */ + tcflag_t c_cflag; /* control flags */ + tcflag_t c_lflag; /* local flags */ + cc_t c_cc[NCCS]; /* control chars */ + speed_t c_ispeed; /* input speed */ + speed_t c_ospeed; /* output speed */ +}; + +/* + * Commands passed to tcsetattr() for setting the termios structure. + */ +#define TCSANOW 0 /* make change immediate */ +#define TCSADRAIN 1 /* drain output, then change */ +#define TCSAFLUSH 2 /* drain output, flush input */ +#ifndef _POSIX_SOURCE +#define TCSASOFT 0x10 /* flag - don't alter h.w. state */ +#endif + +/* + * Standard speeds + */ +#define B0 0 +#define B50 50 +#define B75 75 +#define B110 110 +#define B134 134 +#define B150 150 +#define B200 200 +#define B300 300 +#define B600 600 +#define B1200 1200 +#define B1800 1800 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#ifndef _POSIX_SOURCE +#define B7200 7200 +#define B14400 14400 +#define B28800 28800 +#define B57600 57600 +#define B76800 76800 +#define B115200 115200 +#define B230400 230400 +#define B460800 460800 +#define B921600 921600 +#define EXTA 19200 +#define EXTB 38400 +#endif /* !_POSIX_SOURCE */ + +#ifndef _KERNEL + +#define TCIFLUSH 1 +#define TCOFLUSH 2 +#define TCIOFLUSH 3 +#define TCOOFF 1 +#define TCOON 2 +#define TCIOFF 3 +#define TCION 4 + +#include + +__BEGIN_DECLS +speed_t cfgetispeed(const struct termios *); +speed_t cfgetospeed(const struct termios *); +int cfsetispeed(struct termios *, speed_t); +int cfsetospeed(struct termios *, speed_t); +int tcgetattr(int, struct termios *); +int tcsetattr(int, int, const struct termios *); +int tcdrain(int); +int tcflow(int, int); +int tcflush(int, int); +int tcsendbreak(int, int); + +#ifndef _POSIX_SOURCE +void cfmakeraw(struct termios *); +int cfsetspeed(struct termios *, speed_t); +#endif /* !_POSIX_SOURCE */ +__END_DECLS + +#endif /* !_KERNEL */ + +#ifndef _POSIX_SOURCE + +/* + * Include tty ioctl's that aren't just for backwards compatibility + * with the old tty driver. These ioctl definitions were previously + * in . + */ +#include +#endif + +/* + * END OF PROTECTED INCLUDE. + */ +#endif /* !_SYS_TERMIOS_H_ */ + +#ifndef _POSIX_SOURCE +#include +#endif diff --git a/src/include/sys/thr.h b/src/include/sys/thr.h new file mode 100644 index 0000000..fd53836 --- /dev/null +++ b/src/include/sys/thr.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2003, Jeffrey Roberson + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/thr.h,v 1.2 2004/03/27 14:30:43 mtm Exp $ + * + */ + +#ifndef _SYS_THR_H_ +#define _SYS_THR_H_ + +/* + * Globally unique thread id type. + */ +typedef void * thr_id_t; + +#define THR_SUSPENDED 0x0001 /* Create the thread in the suspended state. */ + +/* + * See pthread_* + */ +#ifndef _KERNEL + +int thr_create(ucontext_t *ctx, thr_id_t *id, int flags); +int thr_self(thr_id_t *id); +void thr_exit(void); +int thr_kill(thr_id_t id, int sig); +int thr_suspend(const struct timespec *timeout); +int thr_wake(thr_id_t id); + +#endif /* !_KERNEL */ + +#endif /* ! _SYS_THR_H_ */ diff --git a/src/include/sys/tiio.h b/src/include/sys/tiio.h new file mode 100644 index 0000000..7b4dca4 --- /dev/null +++ b/src/include/sys/tiio.h @@ -0,0 +1,333 @@ +/*- + * Copyright (c) 1999, 2000 Kenneth D. Merry. + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/tiio.h,v 1.1 2002/06/26 03:37:47 ken Exp $ + */ +/* + * The ti_stats structure below is from code with the following copyright, + * and originally comes from the Alteon firmware documentation. + */ +/* + * Copyright (c) 1997, 1998, 1999 + * Bill Paul . 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 Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD + * 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. + * + * from: if_tireg.h,v 1.8 1999/07/23 18:46:24 wpaul Exp $ + */ + +#ifndef _SYS_TIIO_H_ +#define _SYS_TIIO_H_ + +#include + +/* + * Tigon statistics counters. + */ +struct ti_stats { + /* + * MAC stats, taken from RFC 1643, ethernet-like MIB + */ + volatile u_int32_t dot3StatsAlignmentErrors; /* 0 */ + volatile u_int32_t dot3StatsFCSErrors; /* 1 */ + volatile u_int32_t dot3StatsSingleCollisionFrames; /* 2 */ + volatile u_int32_t dot3StatsMultipleCollisionFrames; /* 3 */ + volatile u_int32_t dot3StatsSQETestErrors; /* 4 */ + volatile u_int32_t dot3StatsDeferredTransmissions; /* 5 */ + volatile u_int32_t dot3StatsLateCollisions; /* 6 */ + volatile u_int32_t dot3StatsExcessiveCollisions; /* 7 */ + volatile u_int32_t dot3StatsInternalMacTransmitErrors; /* 8 */ + volatile u_int32_t dot3StatsCarrierSenseErrors; /* 9 */ + volatile u_int32_t dot3StatsFrameTooLongs; /* 10 */ + volatile u_int32_t dot3StatsInternalMacReceiveErrors; /* 11 */ + /* + * interface stats, taken from RFC 1213, MIB-II, interfaces group + */ + volatile u_int32_t ifIndex; /* 12 */ + volatile u_int32_t ifType; /* 13 */ + volatile u_int32_t ifMtu; /* 14 */ + volatile u_int32_t ifSpeed; /* 15 */ + volatile u_int32_t ifAdminStatus; /* 16 */ +#define IF_ADMIN_STATUS_UP 1 +#define IF_ADMIN_STATUS_DOWN 2 +#define IF_ADMIN_STATUS_TESTING 3 + volatile u_int32_t ifOperStatus; /* 17 */ +#define IF_OPER_STATUS_UP 1 +#define IF_OPER_STATUS_DOWN 2 +#define IF_OPER_STATUS_TESTING 3 +#define IF_OPER_STATUS_UNKNOWN 4 +#define IF_OPER_STATUS_DORMANT 5 + volatile u_int32_t ifLastChange; /* 18 */ + volatile u_int32_t ifInDiscards; /* 19 */ + volatile u_int32_t ifInErrors; /* 20 */ + volatile u_int32_t ifInUnknownProtos; /* 21 */ + volatile u_int32_t ifOutDiscards; /* 22 */ + volatile u_int32_t ifOutErrors; /* 23 */ + volatile u_int32_t ifOutQLen; /* deprecated */ /* 24 */ + volatile u_int8_t ifPhysAddress[8]; /* 8 bytes */ /* 25 - 26 */ + volatile u_int8_t ifDescr[32]; /* 27 - 34 */ + u_int32_t alignIt; /* align to 64 bit for u_int64_ts following */ + /* + * more interface stats, taken from RFC 1573, MIB-IIupdate, + * interfaces group + */ + volatile u_int64_t ifHCInOctets; /* 36 - 37 */ + volatile u_int64_t ifHCInUcastPkts; /* 38 - 39 */ + volatile u_int64_t ifHCInMulticastPkts; /* 40 - 41 */ + volatile u_int64_t ifHCInBroadcastPkts; /* 42 - 43 */ + volatile u_int64_t ifHCOutOctets; /* 44 - 45 */ + volatile u_int64_t ifHCOutUcastPkts; /* 46 - 47 */ + volatile u_int64_t ifHCOutMulticastPkts; /* 48 - 49 */ + volatile u_int64_t ifHCOutBroadcastPkts; /* 50 - 51 */ + volatile u_int32_t ifLinkUpDownTrapEnable; /* 52 */ + volatile u_int32_t ifHighSpeed; /* 53 */ + volatile u_int32_t ifPromiscuousMode; /* 54 */ + volatile u_int32_t ifConnectorPresent; /* follow link state 55 */ + /* + * Host Commands + */ + volatile u_int32_t nicCmdsHostState; /* 56 */ + volatile u_int32_t nicCmdsFDRFiltering; /* 57 */ + volatile u_int32_t nicCmdsSetRecvProdIndex; /* 58 */ + volatile u_int32_t nicCmdsUpdateGencommStats; /* 59 */ + volatile u_int32_t nicCmdsResetJumboRing; /* 60 */ + volatile u_int32_t nicCmdsAddMCastAddr; /* 61 */ + volatile u_int32_t nicCmdsDelMCastAddr; /* 62 */ + volatile u_int32_t nicCmdsSetPromiscMode; /* 63 */ + volatile u_int32_t nicCmdsLinkNegotiate; /* 64 */ + volatile u_int32_t nicCmdsSetMACAddr; /* 65 */ + volatile u_int32_t nicCmdsClearProfile; /* 66 */ + volatile u_int32_t nicCmdsSetMulticastMode; /* 67 */ + volatile u_int32_t nicCmdsClearStats; /* 68 */ + volatile u_int32_t nicCmdsSetRecvJumboProdIndex; /* 69 */ + volatile u_int32_t nicCmdsSetRecvMiniProdIndex; /* 70 */ + volatile u_int32_t nicCmdsRefreshStats; /* 71 */ + volatile u_int32_t nicCmdsUnknown; /* 72 */ + /* + * NIC Events + */ + volatile u_int32_t nicEventsNICFirmwareOperational; /* 73 */ + volatile u_int32_t nicEventsStatsUpdated; /* 74 */ + volatile u_int32_t nicEventsLinkStateChanged; /* 75 */ + volatile u_int32_t nicEventsError; /* 76 */ + volatile u_int32_t nicEventsMCastListUpdated; /* 77 */ + volatile u_int32_t nicEventsResetJumboRing; /* 78 */ + /* + * Ring manipulation + */ + volatile u_int32_t nicRingSetSendProdIndex; /* 79 */ + volatile u_int32_t nicRingSetSendConsIndex; /* 80 */ + volatile u_int32_t nicRingSetRecvReturnProdIndex; /* 81 */ + /* + * Interrupts + */ + volatile u_int32_t nicInterrupts; /* 82 */ + volatile u_int32_t nicAvoidedInterrupts; /* 83 */ + /* + * BD Coalessing Thresholds + */ + volatile u_int32_t nicEventThresholdHit; /* 84 */ + volatile u_int32_t nicSendThresholdHit; /* 85 */ + volatile u_int32_t nicRecvThresholdHit; /* 86 */ + /* + * DMA Attentions + */ + volatile u_int32_t nicDmaRdOverrun; /* 87 */ + volatile u_int32_t nicDmaRdUnderrun; /* 88 */ + volatile u_int32_t nicDmaWrOverrun; /* 89 */ + volatile u_int32_t nicDmaWrUnderrun; /* 90 */ + volatile u_int32_t nicDmaWrMasterAborts; /* 91 */ + volatile u_int32_t nicDmaRdMasterAborts; /* 92 */ + /* + * NIC Resources + */ + volatile u_int32_t nicDmaWriteRingFull; /* 93 */ + volatile u_int32_t nicDmaReadRingFull; /* 94 */ + volatile u_int32_t nicEventRingFull; /* 95 */ + volatile u_int32_t nicEventProducerRingFull; /* 96 */ + volatile u_int32_t nicTxMacDescrRingFull; /* 97 */ + volatile u_int32_t nicOutOfTxBufSpaceFrameRetry; /* 98 */ + volatile u_int32_t nicNoMoreWrDMADescriptors; /* 99 */ + volatile u_int32_t nicNoMoreRxBDs; /* 100 */ + volatile u_int32_t nicNoSpaceInReturnRing; /* 101 */ + volatile u_int32_t nicSendBDs; /* current count 102 */ + volatile u_int32_t nicRecvBDs; /* current count 103 */ + volatile u_int32_t nicJumboRecvBDs; /* current count 104 */ + volatile u_int32_t nicMiniRecvBDs; /* current count 105 */ + volatile u_int32_t nicTotalRecvBDs; /* current count 106 */ + volatile u_int32_t nicTotalSendBDs; /* current count 107 */ + volatile u_int32_t nicJumboSpillOver; /* 108 */ + volatile u_int32_t nicSbusHangCleared; /* 109 */ + volatile u_int32_t nicEnqEventDelayed; /* 110 */ + /* + * Stats from MAC rx completion + */ + volatile u_int32_t nicMacRxLateColls; /* 111 */ + volatile u_int32_t nicMacRxLinkLostDuringPkt; /* 112 */ + volatile u_int32_t nicMacRxPhyDecodeErr; /* 113 */ + volatile u_int32_t nicMacRxMacAbort; /* 114 */ + volatile u_int32_t nicMacRxTruncNoResources; /* 115 */ + /* + * Stats from the mac_stats area + */ + volatile u_int32_t nicMacRxDropUla; /* 116 */ + volatile u_int32_t nicMacRxDropMcast; /* 117 */ + volatile u_int32_t nicMacRxFlowControl; /* 118 */ + volatile u_int32_t nicMacRxDropSpace; /* 119 */ + volatile u_int32_t nicMacRxColls; /* 120 */ + /* + * MAC RX Attentions + */ + volatile u_int32_t nicMacRxTotalAttns; /* 121 */ + volatile u_int32_t nicMacRxLinkAttns; /* 122 */ + volatile u_int32_t nicMacRxSyncAttns; /* 123 */ + volatile u_int32_t nicMacRxConfigAttns; /* 124 */ + volatile u_int32_t nicMacReset; /* 125 */ + volatile u_int32_t nicMacRxBufDescrAttns; /* 126 */ + volatile u_int32_t nicMacRxBufAttns; /* 127 */ + volatile u_int32_t nicMacRxZeroFrameCleanup; /* 128 */ + volatile u_int32_t nicMacRxOneFrameCleanup; /* 129 */ + volatile u_int32_t nicMacRxMultipleFrameCleanup; /* 130 */ + volatile u_int32_t nicMacRxTimerCleanup; /* 131 */ + volatile u_int32_t nicMacRxDmaCleanup; /* 132 */ + /* + * Stats from the mac_stats area + */ + volatile u_int32_t nicMacTxCollisionHistogram[15]; /* 133 */ + /* + * MAC TX Attentions + */ + volatile u_int32_t nicMacTxTotalAttns; /* 134 */ + /* + * NIC Profile + */ + volatile u_int32_t nicProfile[32]; /* 135 */ + /* + * Pat to 1024 bytes. + */ + u_int32_t pad[75]; +}; + +struct tg_reg { + u_int32_t data; + u_int32_t addr; +}; + +struct tg_mem { + u_int32_t tgAddr; + caddr_t userAddr; + int len; +}; + + +typedef enum { + TI_PARAM_NONE = 0x00, + TI_PARAM_STAT_TICKS = 0x01, + TI_PARAM_RX_COAL_TICKS = 0x02, + TI_PARAM_TX_COAL_TICKS = 0x04, + TI_PARAM_RX_COAL_BDS = 0x08, + TI_PARAM_TX_COAL_BDS = 0x10, + TI_PARAM_TX_BUF_RATIO = 0x20, + TI_PARAM_ALL = 0x2f +} ti_param_mask; + +struct ti_params { + u_int32_t ti_stat_ticks; + u_int32_t ti_rx_coal_ticks; + u_int32_t ti_tx_coal_ticks; + u_int32_t ti_rx_max_coal_bds; + u_int32_t ti_tx_max_coal_bds; + u_int32_t ti_tx_buf_ratio; + ti_param_mask param_mask; +}; + +typedef enum { + TI_TRACE_TYPE_NONE = 0x00000000, + TI_TRACE_TYPE_SEND = 0x00000001, + TI_TRACE_TYPE_RECV = 0x00000002, + TI_TRACE_TYPE_DMA = 0x00000004, + TI_TRACE_TYPE_EVENT = 0x00000008, + TI_TRACE_TYPE_COMMAND = 0x00000010, + TI_TRACE_TYPE_MAC = 0x00000020, + TI_TRACE_TYPE_STATS = 0x00000040, + TI_TRACE_TYPE_TIMER = 0x00000080, + TI_TRACE_TYPE_DISP = 0x00000100, + TI_TRACE_TYPE_MAILBOX = 0x00000200, + TI_TRACE_TYPE_RECV_BD = 0x00000400, + TI_TRACE_TYPE_LNK_PHY = 0x00000800, + TI_TRACE_TYPE_LNK_NEG = 0x00001000, + TI_TRACE_LEVEL_1 = 0x10000000, + TI_TRACE_LEVEL_2 = 0x20000000 +} ti_trace_type; + +struct ti_trace_buf { + u_long *buf; + int buf_len; + int fill_len; + u_long cur_trace_ptr; +}; + +#define TIIOCGETSTATS _IOR('T', 1, struct ti_stats) +#define TIIOCGETPARAMS _IOR('T', 2, struct ti_params) +#define TIIOCSETPARAMS _IOW('T', 3, struct ti_params) +#define TIIOCSETTRACE _IOW('T', 11, ti_trace_type) +#define TIIOCGETTRACE _IOWR('T', 12, struct ti_trace_buf) + +/* + * Taken from Alteon's altioctl.h. Alteon's ioctl numbers 1-6 aren't + * used by the FreeBSD driver. + */ +#define ALT_ATTACH _IO('a', 7) +#define ALT_READ_TG_MEM _IOWR('a', 10, struct tg_mem) +#define ALT_WRITE_TG_MEM _IOWR('a', 11, struct tg_mem) +#define ALT_READ_TG_REG _IOWR('a', 12, struct tg_reg) +#define ALT_WRITE_TG_REG _IOWR('a', 13, struct tg_reg) + +#endif /* _SYS_TIIO_H_ */ diff --git a/src/include/sys/time.h b/src/include/sys/time.h new file mode 100644 index 0000000..b9edb53 --- /dev/null +++ b/src/include/sys/time.h @@ -0,0 +1,318 @@ +/* + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * $FreeBSD: src/sys/sys/time.h,v 1.65 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include +#include +#include + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ + +#if __BSD_VISIBLE +struct bintime { + time_t sec; + uint64_t frac; +}; + +static __inline void +bintime_addx(struct bintime *bt, uint64_t x) +{ + uint64_t u; + + u = bt->frac; + bt->frac += x; + if (u > bt->frac) + bt->sec++; +} + +static __inline void +bintime_add(struct bintime *bt, const struct bintime *bt2) +{ + uint64_t u; + + u = bt->frac; + bt->frac += bt2->frac; + if (u > bt->frac) + bt->sec++; + bt->sec += bt2->sec; +} + +static __inline void +bintime_sub(struct bintime *bt, const struct bintime *bt2) +{ + uint64_t u; + + u = bt->frac; + bt->frac -= bt2->frac; + if (u < bt->frac) + bt->sec--; + bt->sec -= bt2->sec; +} + +/*- + * Background information: + * + * When converting between timestamps on parallel timescales of differing + * resolutions it is historical and scientific practice to round down rather + * than doing 4/5 rounding. + * + * The date changes at midnight, not at noon. + * + * Even at 15:59:59.999999999 it's not four'o'clock. + * + * time_second ticks after N.999999999 not after N.4999999999 + */ + +static __inline void +bintime2timespec(const struct bintime *bt, struct timespec *ts) +{ + + ts->tv_sec = bt->sec; + ts->tv_nsec = ((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32; +} + +static __inline void +timespec2bintime(const struct timespec *ts, struct bintime *bt) +{ + + bt->sec = ts->tv_sec; + /* 18446744073 = int(2^64 / 1000000000) */ + bt->frac = ts->tv_nsec * (uint64_t)18446744073LL; +} + +static __inline void +bintime2timeval(const struct bintime *bt, struct timeval *tv) +{ + + tv->tv_sec = bt->sec; + tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32; +} + +static __inline void +timeval2bintime(const struct timeval *tv, struct bintime *bt) +{ + + bt->sec = tv->tv_sec; + /* 18446744073709 = int(2^64 / 1000000) */ + bt->frac = tv->tv_usec * (uint64_t)18446744073709LL; +} +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL + +/* Operations on timespecs */ +#define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) +#define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) +#define timespeccmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timespecadd(vvp, uvp) \ + do { \ + (vvp)->tv_sec += (uvp)->tv_sec; \ + (vvp)->tv_nsec += (uvp)->tv_nsec; \ + if ((vvp)->tv_nsec >= 1000000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_nsec -= 1000000000; \ + } \ + } while (0) +#define timespecsub(vvp, uvp) \ + do { \ + (vvp)->tv_sec -= (uvp)->tv_sec; \ + (vvp)->tv_nsec -= (uvp)->tv_nsec; \ + if ((vvp)->tv_nsec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_nsec += 1000000000; \ + } \ + } while (0) + +/* Operations on timevals. */ + +#define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timevalcmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) + +/* timevaladd and timevalsub are not inlined */ + +#endif /* _KERNEL */ + +#ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */ + +#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) +#endif + +/* + * Names of the interval timers, and structure + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; + +/* + * Getkerninfo clock information structure + */ +struct clockinfo { + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int spare; + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ +}; + +/* CLOCK_REALTIME and TIMER_ABSTIME are supposed to be in time.h */ + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif +#define CLOCK_VIRTUAL 1 +#define CLOCK_PROF 2 +#define CLOCK_MONOTONIC 4 + +#define TIMER_RELTIME 0x0 /* relative timer */ +#ifndef TIMER_ABSTIME +#define TIMER_ABSTIME 0x1 /* absolute timer */ +#endif + +#ifdef _KERNEL +extern time_t time_second; +extern time_t time_uptime; +extern struct timeval boottime; + +/* + * Functions for looking at our clock: [get]{bin,nano,micro}[up]time() + * + * Functions without the "get" prefix returns the best timestamp + * we can produce in the given format. + * + * "bin" == struct bintime == seconds + 64 bit fraction of seconds. + * "nano" == struct timespec == seconds + nanoseconds. + * "micro" == struct timeval == seconds + microseconds. + * + * Functions containing "up" returns time relative to boot and + * should be used for calculating time intervals. + * + * Functions without "up" returns GMT time. + * + * Functions with the "get" prefix returns a less precise result + * much faster than the functions without "get" prefix and should + * be used where a precision of 10 msec is acceptable or where + * performance is priority. (NB: "precision", _not_ "resolution" !) + * + */ + +void binuptime(struct bintime *bt); +void nanouptime(struct timespec *tsp); +void microuptime(struct timeval *tvp); + +void bintime(struct bintime *bt); +void nanotime(struct timespec *tsp); +void microtime(struct timeval *tvp); + +void getbinuptime(struct bintime *bt); +void getnanouptime(struct timespec *tsp); +void getmicrouptime(struct timeval *tvp); + +void getbintime(struct bintime *bt); +void getnanotime(struct timespec *tsp); +void getmicrotime(struct timeval *tvp); + +/* Other functions */ +int itimerdecr(struct itimerval *itp, int usec); +int itimerfix(struct timeval *tv); +int ppsratecheck(struct timeval *, int *, int); +int ratecheck(struct timeval *, const struct timeval *); +void timevaladd(struct timeval *t1, const struct timeval *t2); +void timevalsub(struct timeval *t1, const struct timeval *t2); +int tvtohz(struct timeval *tv); +#else /* !_KERNEL */ +#include + +#include + +__BEGIN_DECLS +int adjtime(const struct timeval *, struct timeval *); +int futimes(int, const struct timeval *); +int getitimer(int, struct itimerval *); +int gettimeofday(struct timeval *, struct timezone *); +int lutimes(const char *, const struct timeval *); +int setitimer(int, const struct itimerval *, struct itimerval *); +int settimeofday(const struct timeval *, const struct timezone *); +int utimes(const char *, const struct timeval *); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_TIME_H_ */ diff --git a/src/include/sys/timeb.h b/src/include/sys/timeb.h new file mode 100644 index 0000000..ccd83fb --- /dev/null +++ b/src/include/sys/timeb.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)timeb.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/timeb.h,v 1.9 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_TIMEB_H_ +#define _SYS_TIMEB_H_ + +/* The ftime(2) system call structure -- deprecated. */ +struct timeb { + time_t time; /* seconds since the Epoch */ + unsigned short millitm; /* + milliseconds since the Epoch */ + short timezone; /* minutes west of CUT */ + short dstflag; /* DST == non-zero */ +}; + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +int ftime(struct timeb *); +__END_DECLS +#endif /* _KERNEL */ + +#endif diff --git a/src/include/sys/timepps.h b/src/include/sys/timepps.h new file mode 100644 index 0000000..4d21e61 --- /dev/null +++ b/src/include/sys/timepps.h @@ -0,0 +1,200 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/sys/timepps.h,v 1.18 2003/11/23 18:52:23 phk Exp $ + * + * The is a FreeBSD version of the RFC 2783 API for Pulse Per Second + * timing interfaces. + */ + +#ifndef _SYS_TIMEPPS_H_ +#define _SYS_TIMEPPS_H_ + +#include +#include + +#define PPS_API_VERS_1 1 + +typedef int pps_handle_t; + +typedef unsigned pps_seq_t; + +typedef struct ntp_fp { + unsigned int integral; + unsigned int fractional; +} ntp_fp_t; + +typedef union pps_timeu { + struct timespec tspec; + ntp_fp_t ntpfp; + unsigned long longpad[3]; +} pps_timeu_t; + +typedef struct { + pps_seq_t assert_sequence; /* assert event seq # */ + pps_seq_t clear_sequence; /* clear event seq # */ + pps_timeu_t assert_tu; + pps_timeu_t clear_tu; + int current_mode; /* current mode bits */ +} pps_info_t; + +#define assert_timestamp assert_tu.tspec +#define clear_timestamp clear_tu.tspec + +#define assert_timestamp_ntpfp assert_tu.ntpfp +#define clear_timestamp_ntpfp clear_tu.ntpfp + +typedef struct { + int api_version; /* API version # */ + int mode; /* mode bits */ + pps_timeu_t assert_off_tu; + pps_timeu_t clear_off_tu; +} pps_params_t; + +#define assert_offset assert_off_tu.tspec +#define clear_offset clear_off_tu.tspec + +#define assert_offset_ntpfp assert_off_tu.ntpfp +#define clear_offset_ntpfp clear_off_tu.ntpfp + + +#define PPS_CAPTUREASSERT 0x01 +#define PPS_CAPTURECLEAR 0x02 +#define PPS_CAPTUREBOTH 0x03 + +#define PPS_OFFSETASSERT 0x10 +#define PPS_OFFSETCLEAR 0x20 + +#define PPS_ECHOASSERT 0x40 +#define PPS_ECHOCLEAR 0x80 + +#define PPS_CANWAIT 0x100 +#define PPS_CANPOLL 0x200 + +#define PPS_TSFMT_TSPEC 0x1000 +#define PPS_TSFMT_NTPFP 0x2000 + +#define PPS_KC_HARDPPS 0 +#define PPS_KC_HARDPPS_PLL 1 +#define PPS_KC_HARDPPS_FLL 2 + +struct pps_fetch_args { + int tsformat; + pps_info_t pps_info_buf; + struct timespec timeout; +}; + +struct pps_kcbind_args { + int kernel_consumer; + int edge; + int tsformat; +}; + +#define PPS_IOC_CREATE _IO('1', 1) +#define PPS_IOC_DESTROY _IO('1', 2) +#define PPS_IOC_SETPARAMS _IOW('1', 3, pps_params_t) +#define PPS_IOC_GETPARAMS _IOR('1', 4, pps_params_t) +#define PPS_IOC_GETCAP _IOR('1', 5, int) +#define PPS_IOC_FETCH _IOWR('1', 6, struct pps_fetch_args) +#define PPS_IOC_KCBIND _IOW('1', 7, struct pps_kcbind_args) + +#ifdef _KERNEL + +struct pps_state { + /* Capture information. */ + struct timehands *capth; + unsigned capgen; + unsigned capcount; + + /* State information. */ + pps_params_t ppsparam; + pps_info_t ppsinfo; + int kcmode; + int ppscap; + struct timecounter *ppstc; + unsigned ppscount[3]; +}; + +void pps_capture(struct pps_state *pps); +void pps_event(struct pps_state *pps, int event); +void pps_init(struct pps_state *pps); +int pps_ioctl(unsigned long cmd, caddr_t data, struct pps_state *pps); +void hardpps(struct timespec *tsp, long nsec); + +#else /* !_KERNEL */ + +static __inline int +time_pps_create(int filedes, pps_handle_t *handle) +{ + int error; + + *handle = -1; + error = ioctl(filedes, PPS_IOC_CREATE, 0); + if (error < 0) + return (-1); + *handle = filedes; + return (0); +} + +static __inline int +time_pps_destroy(pps_handle_t handle) +{ + return (ioctl(handle, PPS_IOC_DESTROY, 0)); +} + +static __inline int +time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams) +{ + return (ioctl(handle, PPS_IOC_SETPARAMS, ppsparams)); +} + +static __inline int +time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams) +{ + return (ioctl(handle, PPS_IOC_GETPARAMS, ppsparams)); +} + +static __inline int +time_pps_getcap(pps_handle_t handle, int *mode) +{ + return (ioctl(handle, PPS_IOC_GETCAP, mode)); +} + +static __inline int +time_pps_fetch(pps_handle_t handle, const int tsformat, + pps_info_t *ppsinfobuf, const struct timespec *timeout) +{ + int error; + struct pps_fetch_args arg; + + arg.tsformat = tsformat; + if (timeout == NULL) { + arg.timeout.tv_sec = -1; + arg.timeout.tv_nsec = -1; + } else + arg.timeout = *timeout; + error = ioctl(handle, PPS_IOC_FETCH, &arg); + *ppsinfobuf = arg.pps_info_buf; + return (error); +} + +static __inline int +time_pps_kcbind(pps_handle_t handle, const int kernel_consumer, + const int edge, const int tsformat) +{ + struct pps_kcbind_args arg; + + arg.kernel_consumer = kernel_consumer; + arg.edge = edge; + arg.tsformat = tsformat; + return (ioctl(handle, PPS_IOC_KCBIND, &arg)); +} + +#endif /* KERNEL */ + +#endif /* !_SYS_TIMEPPS_H_ */ diff --git a/src/include/sys/timers.h b/src/include/sys/timers.h new file mode 100644 index 0000000..f159a3c --- /dev/null +++ b/src/include/sys/timers.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu + * 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * $FreeBSD: src/sys/sys/timers.h,v 1.4 1999/08/28 00:52:05 peter Exp $ + * + * Description : Basic timers header. + */ + +#ifndef _SYS_TIMERS_H_ +#define _SYS_TIMERS_H_ + +#include + +#endif diff --git a/src/include/sys/times.h b/src/include/sys/times.h new file mode 100644 index 0000000..d5c34f1 --- /dev/null +++ b/src/include/sys/times.h @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)times.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/times.h,v 1.9 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_TIMES_H_ +#define _SYS_TIMES_H_ + +#include + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +struct tms { + clock_t tms_utime; /* User CPU time */ + clock_t tms_stime; /* System CPU time */ + clock_t tms_cutime; /* User CPU time of terminated child procs */ + clock_t tms_cstime; /* System CPU time of terminated child procs */ +}; + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +clock_t times(struct tms *); +__END_DECLS +#endif +#endif /* !_SYS_TIMES_H_ */ diff --git a/src/include/sys/timespec.h b/src/include/sys/timespec.h new file mode 100644 index 0000000..7c8b42a --- /dev/null +++ b/src/include/sys/timespec.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp + * $FreeBSD: src/sys/sys/timespec.h,v 1.3 2004/04/07 04:19:50 imp Exp $ + */ + +/* + * Prerequisites: , + */ + +#ifndef _SYS_TIMESPEC_H_ +#define _SYS_TIMESPEC_H_ + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +#if __BSD_VISIBLE +#define TIMEVAL_TO_TIMESPEC(tv, ts) \ + do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ + } while (0) +#define TIMESPEC_TO_TIMEVAL(tv, ts) \ + do { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ + } while (0) + +#endif /* __BSD_VISIBLE */ + +#endif /* _SYS_TIMESPEC_H_ */ diff --git a/src/include/sys/timetc.h b/src/include/sys/timetc.h new file mode 100644 index 0000000..3709497 --- /dev/null +++ b/src/include/sys/timetc.h @@ -0,0 +1,78 @@ +/*- + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/sys/timetc.h,v 1.58 2003/08/16 08:23:52 phk Exp $ + */ + +#ifndef _SYS_TIMETC_H_ +#define _SYS_TIMETC_H_ + +#ifndef _KERNEL +#error "no user-serviceable parts inside" +#endif + +/*- + * `struct timecounter' is the interface between the hardware which implements + * a timecounter and the MI code which uses this to keep track of time. + * + * A timecounter is a binary counter which has two properties: + * * it runs at a fixed, known frequency. + * * it has sufficient bits to not roll over in less than approximately + * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta, + * for some indeterminate value of delta.) + */ + +struct timecounter; +typedef u_int timecounter_get_t(struct timecounter *); +typedef void timecounter_pps_t(struct timecounter *); + +struct timecounter { + timecounter_get_t *tc_get_timecount; + /* + * This function reads the counter. It is not required to + * mask any unimplemented bits out, as long as they are + * constant. + */ + timecounter_pps_t *tc_poll_pps; + /* + * This function is optional. It will be called whenever the + * timecounter is rewound, and is intended to check for PPS + * events. Normal hardware does not need it but timecounters + * which latch PPS in hardware (like sys/pci/xrpu.c) do. + */ + u_int tc_counter_mask; + /* This mask should mask off any unimplemented bits. */ + u_int64_t tc_frequency; + /* Frequency of the counter in Hz. */ + char *tc_name; + /* Name of the timecounter. */ + int tc_quality; + /* + * Used to determine if this timecounter is better than + * another timecounter higher means better. Negative + * means "only use at explicit request". + */ + + void *tc_priv; + /* Pointer to the timecounter's private parts. */ + struct timecounter *tc_next; + /* Pointer to the next timecounter. */ +}; + +extern struct timecounter *timecounter; + +u_int64_t tc_getfrequency(void); +void tc_init(struct timecounter *tc); +void tc_setclock(struct timespec *ts); +void tc_ticktock(void); + +#ifdef SYSCTL_DECL +SYSCTL_DECL(_kern_timecounter); +#endif + +#endif /* !_SYS_TIMETC_H_ */ diff --git a/src/include/sys/timex.h b/src/include/sys/timex.h new file mode 100644 index 0000000..8389fe5 --- /dev/null +++ b/src/include/sys/timex.h @@ -0,0 +1,235 @@ +/*********************************************************************** + * * + * Copyright (c) David L. Mills 1993-2001 * + * * + * Permission to use, copy, modify, and distribute this software and * + * its documentation for any purpose and without fee is hereby * + * granted, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission * + * notice appear in supporting documentation, and that the name * + * University of Delaware not be used in advertising or publicity * + * pertaining to distribution of the software without specific, * + * written prior permission. The University of Delaware makes no * + * representations about the suitability this software for any * + * purpose. It is provided "as is" without express or implied * + * warranty. * + * * + **********************************************************************/ + +/* + * Modification history timex.h + * + * 16 Aug 00 David L. Mills + * API Version 4. Added MOD_TAI and tai member of ntptimeval + * structure. + * + * 17 Nov 98 David L. Mills + * Revised for nanosecond kernel and user interface. + * + * 26 Sep 94 David L. Mills + * Added defines for hybrid phase/frequency-lock loop. + * + * 19 Mar 94 David L. Mills + * Moved defines from kernel routines to header file and added new + * defines for PPS phase-lock loop. + * + * 20 Feb 94 David L. Mills + * Revised status codes and structures for external clock and PPS + * signal discipline. + * + * 28 Nov 93 David L. Mills + * Adjusted parameters to improve stability and increase poll + * interval. + * + * 17 Sep 93 David L. Mills + * Created file + * + * $FreeBSD: src/sys/sys/timex.h,v 1.17 2002/04/28 09:51:45 bde Exp $ + */ +/* + * This header file defines the Network Time Protocol (NTP) interfaces + * for user and daemon application programs. These are implemented using + * defined syscalls and data structures and require specific kernel + * support. + * + * The original precision time kernels developed from 1993 have an + * ultimate resolution of one microsecond; however, the most recent + * kernels have an ultimate resolution of one nanosecond. In these + * kernels, a ntp_adjtime() syscalls can be used to determine which + * resolution is in use and to select either one at any time. The + * resolution selected affects the scaling of certain fields in the + * ntp_gettime() and ntp_adjtime() syscalls, as described below. + * + * NAME + * ntp_gettime - NTP user application interface + * + * SYNOPSIS + * #include + * + * int ntp_gettime(struct ntptimeval *ntv); + * + * DESCRIPTION + * The time returned by ntp_gettime() is in a timespec structure, + * but may be in either microsecond (seconds and microseconds) or + * nanosecond (seconds and nanoseconds) format. The particular + * format in use is determined by the STA_NANO bit of the status + * word returned by the ntp_adjtime() syscall. + * + * NAME + * ntp_adjtime - NTP daemon application interface + * + * SYNOPSIS + * #include + * #include + * + * int syscall(SYS_ntp_adjtime, tptr); + * int SYS_ntp_adjtime; + * struct timex *tptr; + * + * DESCRIPTION + * Certain fields of the timex structure are interpreted in either + * microseconds or nanoseconds according to the state of the + * STA_NANO bit in the status word. See the description below for + * further information. + */ +#ifndef _SYS_TIMEX_H_ +#define _SYS_TIMEX_H_ 1 +#define NTP_API 4 /* NTP API version */ + +#ifndef MSDOS /* Microsoft specific */ +#include +#endif /* MSDOS */ + +/* + * The following defines establish the performance envelope of the + * kernel discipline loop. Phase or frequency errors greater than + * NAXPHASE or MAXFREQ are clamped to these maxima. For update intervals + * less than MINSEC, the loop always operates in PLL mode; while, for + * update intervals greater than MAXSEC, the loop always operates in FLL + * mode. Between these two limits the operating mode is selected by the + * STA_FLL bit in the status word. + */ +#define MAXPHASE 500000000L /* max phase error (ns) */ +#define MAXFREQ 500000L /* max freq error (ns/s) */ +#define MINSEC 256 /* min FLL update interval (s) */ +#define MAXSEC 2048 /* max PLL update interval (s) */ +#define NANOSECOND 1000000000L /* nanoseconds in one second */ +#define SCALE_PPM (65536 / 1000) /* crude ns/s to scaled PPM */ +#define MAXTC 10 /* max time constant */ + +/* + * The following defines and structures define the user interface for + * the ntp_gettime() and ntp_adjtime() syscalls. + * + * Control mode codes (timex.modes) + */ +#define MOD_OFFSET 0x0001 /* set time offset */ +#define MOD_FREQUENCY 0x0002 /* set frequency offset */ +#define MOD_MAXERROR 0x0004 /* set maximum time error */ +#define MOD_ESTERROR 0x0008 /* set estimated time error */ +#define MOD_STATUS 0x0010 /* set clock status bits */ +#define MOD_TIMECONST 0x0020 /* set PLL time constant */ +#define MOD_PPSMAX 0x0040 /* set PPS maximum averaging time */ +#define MOD_TAI 0x0080 /* set TAI offset */ +#define MOD_MICRO 0x1000 /* select microsecond resolution */ +#define MOD_NANO 0x2000 /* select nanosecond resolution */ +#define MOD_CLKB 0x4000 /* select clock B */ +#define MOD_CLKA 0x8000 /* select clock A */ + +/* + * Status codes (timex.status) + */ +#define STA_PLL 0x0001 /* enable PLL updates (rw) */ +#define STA_PPSFREQ 0x0002 /* enable PPS freq discipline (rw) */ +#define STA_PPSTIME 0x0004 /* enable PPS time discipline (rw) */ +#define STA_FLL 0x0008 /* enable FLL mode (rw) */ +#define STA_INS 0x0010 /* insert leap (rw) */ +#define STA_DEL 0x0020 /* delete leap (rw) */ +#define STA_UNSYNC 0x0040 /* clock unsynchronized (rw) */ +#define STA_FREQHOLD 0x0080 /* hold frequency (rw) */ +#define STA_PPSSIGNAL 0x0100 /* PPS signal present (ro) */ +#define STA_PPSJITTER 0x0200 /* PPS signal jitter exceeded (ro) */ +#define STA_PPSWANDER 0x0400 /* PPS signal wander exceeded (ro) */ +#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */ +#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */ +#define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */ +#define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */ +#define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */ + +#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ + STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) + +/* + * Clock states (time_state) + */ +#define TIME_OK 0 /* no leap second warning */ +#define TIME_INS 1 /* insert leap second warning */ +#define TIME_DEL 2 /* delete leap second warning */ +#define TIME_OOP 3 /* leap second in progress */ +#define TIME_WAIT 4 /* leap second has occured */ +#define TIME_ERROR 5 /* error (see status word) */ + +/* + * NTP user interface (ntp_gettime()) - used to read kernel clock values + * + * Note: The time member is in microseconds if STA_NANO is zero and + * nanoseconds if not. + */ +struct ntptimeval { + struct timespec time; /* current time (ns) (ro) */ + long maxerror; /* maximum error (us) (ro) */ + long esterror; /* estimated error (us) (ro) */ + long tai; /* TAI offset */ + int time_state; /* time status */ +}; + +/* + * NTP daemon interface (ntp_adjtime()) - used to discipline CPU clock + * oscillator and determine status. + * + * Note: The offset, precision and jitter members are in microseconds if + * STA_NANO is zero and nanoseconds if not. + */ +struct timex { + unsigned int modes; /* clock mode bits (wo) */ + long offset; /* time offset (ns/us) (rw) */ + long freq; /* frequency offset (scaled PPM) (rw) */ + long maxerror; /* maximum error (us) (rw) */ + long esterror; /* estimated error (us) (rw) */ + int status; /* clock status bits (rw) */ + long constant; /* poll interval (log2 s) (rw) */ + long precision; /* clock precision (ns/us) (ro) */ + long tolerance; /* clock frequency tolerance (scaled + * PPM) (ro) */ + /* + * The following read-only structure members are implemented + * only if the PPS signal discipline is configured in the + * kernel. They are included in all configurations to insure + * portability. + */ + long ppsfreq; /* PPS frequency (scaled PPM) (ro) */ + long jitter; /* PPS jitter (ns/us) (ro) */ + int shift; /* interval duration (s) (shift) (ro) */ + long stabil; /* PPS stability (scaled PPM) (ro) */ + long jitcnt; /* jitter limit exceeded (ro) */ + long calcnt; /* calibration intervals (ro) */ + long errcnt; /* calibration errors (ro) */ + long stbcnt; /* stability limit exceeded (ro) */ +}; + +#ifdef __FreeBSD__ + +#ifdef _KERNEL +void ntp_update_second(int64_t *adjustment, time_t *newsec); +#else /* !_KERNEL */ +#include + +__BEGIN_DECLS +int ntp_adjtime(struct timex *); +int ntp_gettime(struct ntptimeval *); +__END_DECLS +#endif /* _KERNEL */ + +#endif /* __FreeBSD__ */ + +#endif /* !_SYS_TIMEX_H_ */ diff --git a/src/include/sys/tree.h b/src/include/sys/tree.h new file mode 100644 index 0000000..5648e46 --- /dev/null +++ b/src/include/sys/tree.h @@ -0,0 +1,681 @@ +/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */ +/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ +/* + * Copyright 2002 Niels Provos + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#ifndef _SYS_TREE_H_ +#define _SYS_TREE_H_ + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ +void name##_RB_INSERT_COLOR(struct name *, struct type *); \ +void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ +struct type *name##_RB_REMOVE(struct name *, struct type *); \ +struct type *name##_RB_INSERT(struct name *, struct type *); \ +struct type *name##_RB_FIND(struct name *, struct type *); \ +struct type *name##_RB_NEXT(struct type *); \ +struct type *name##_RB_MINMAX(struct name *, int); \ + \ + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ +void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) != NULL && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} \ + \ +void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)) \ + != NULL) \ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)) \ + != NULL) \ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} \ + \ +struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field)) != NULL) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field)) != NULL); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* ARGSUSED */ \ +struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#endif /* _SYS_TREE_H_ */ diff --git a/src/include/sys/tty.h b/src/include/sys/tty.h new file mode 100644 index 0000000..bebcbd2 --- /dev/null +++ b/src/include/sys/tty.h @@ -0,0 +1,320 @@ +/*- + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Copyright (c) 2002 Networks Associates Technologies, Inc. + * All rights reserved. + * + * Portions of this software were developed for the FreeBSD Project by + * ThinkSec AS and NAI Labs, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * 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. + * 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. + * + * @(#)tty.h 8.6 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/tty.h,v 1.73 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_TTY_H_ +#define _SYS_TTY_H_ + +#include +#include +#include + +/* + * Clists are character lists, which is a variable length linked list + * of cblocks, with a count of the number of characters in the list. + */ +struct clist { + int c_cc; /* Number of characters in the clist. */ + int c_cbcount; /* Number of cblocks. */ + int c_cbmax; /* Max # cblocks allowed for this clist. */ + int c_cbreserved; /* # cblocks reserved for this clist. */ + char *c_cf; /* Pointer to the first cblock. */ + char *c_cl; /* Pointer to the last cblock. */ +}; + +/* + * Per-tty structure. + * + * Should be split in two, into device and tty drivers. + * Glue could be masks of what to echo and circular buffer + * (low, high, timeout). + */ +struct tty { + struct clist t_rawq; /* Device raw input queue. */ + long t_rawcc; /* Raw input queue statistics. */ + struct clist t_canq; /* Device canonical queue. */ + long t_cancc; /* Canonical queue statistics. */ + struct clist t_outq; /* Device output queue. */ + long t_outcc; /* Output queue statistics. */ + int t_line; /* Interface to device drivers. */ + union { + dev_t t_kdev; /* Device. */ + udev_t t_udev; /* Userland (sysctl) instance. */ + void *t_devp; /* Keep user/kernel size in sync. */ + } ttyu; + int t_state; /* Device and driver (TS*) state. */ + int t_flags; /* Tty flags. */ + int t_timeout; /* Timeout for ttywait() */ + struct pgrp *t_pgrp; /* Foreground process group. */ + struct session *t_session; /* Enclosing session. */ + struct sigio *t_sigio; /* Information for async I/O. */ + struct selinfo t_rsel; /* Tty read/oob select. */ + struct selinfo t_wsel; /* Tty write select. */ + struct termios t_termios; /* Termios state. */ + struct winsize t_winsize; /* Window size. */ + /* Start output. */ + void (*t_oproc)(struct tty *); + /* Stop output. */ + void (*t_stop)(struct tty *, int); + /* Set hardware state. */ + int (*t_param)(struct tty *, struct termios *); + void *t_sc; /* XXX: net/if_sl.c:sl_softc. */ + int t_column; /* Tty output column. */ + int t_rocount, t_rocol; /* Tty. */ + int t_ififosize; /* Total size of upstream fifos. */ + int t_ihiwat; /* High water mark for input. */ + int t_ilowat; /* Low water mark for input. */ + speed_t t_ispeedwat; /* t_ispeed override for watermarks. */ + int t_ohiwat; /* High water mark for output. */ + int t_olowat; /* Low water mark for output. */ + speed_t t_ospeedwat; /* t_ospeed override for watermarks. */ + int t_gen; /* Generation number. */ + SLIST_ENTRY(tty) t_list; /* Global chain of ttys for pstat(8) */ +}; + +#define t_cc t_termios.c_cc +#define t_cflag t_termios.c_cflag +#define t_dev ttyu.t_kdev +#define t_iflag t_termios.c_iflag +#define t_ispeed t_termios.c_ispeed +#define t_lflag t_termios.c_lflag +#define t_min t_termios.c_min +#define t_oflag t_termios.c_oflag +#define t_ospeed t_termios.c_ospeed +#define t_time t_termios.c_time + +#define TTIPRI (PSOCK + 1) /* Sleep priority for tty reads. */ +#define TTOPRI (PSOCK + 2) /* Sleep priority for tty writes. */ + +/* + * Userland version of struct tty, for sysctl. + */ +struct xtty { + size_t xt_size; /* Structure size. */ + long xt_rawcc; /* Raw input queue statistics. */ + long xt_cancc; /* Canonical queue statistics. */ + long xt_outcc; /* Output queue statistics. */ + int xt_line; /* Interface to device drivers. */ + udev_t xt_dev; /* Userland (sysctl) instance. */ + int xt_state; /* Device and driver (TS*) state. */ + int xt_flags; /* Tty flags. */ + int xt_timeout; /* Timeout for ttywait(). */ + pid_t xt_pgid; /* Process group ID. */ + pid_t xt_sid; /* Session ID. */ + struct termios xt_termios; /* Termios state. */ + struct winsize xt_winsize; /* Window size. */ + int xt_column; /* Tty output column. */ + int xt_rocount, xt_rocol; /* Tty. */ + int xt_ififosize; /* Total size of upstream fifos. */ + int xt_ihiwat; /* High water mark for input. */ + int xt_ilowat; /* Low water mark for input. */ + speed_t xt_ispeedwat; /* t_ispeed override for watermarks. */ + int xt_ohiwat; /* High water mark for output. */ + int xt_olowat; /* Low water mark for output. */ + speed_t xt_ospeedwat; /* t_ospeed override for watermarks. */ +}; + +/* + * User data unfortunately has to be copied through buffers on the way to + * and from clists. The buffers are on the stack so their sizes must be + * fairly small. + */ +#define IBUFSIZ 384 /* Should be >= max value of MIN. */ +#define OBUFSIZ 100 + +#ifndef TTYHOG +#define TTYHOG 8192 +#endif + +#ifdef _KERNEL +#define TTMAXHIWAT roundup(2048, CBSIZE) +#define TTMINHIWAT roundup(100, CBSIZE) +#define TTMAXLOWAT 256 +#define TTMINLOWAT 32 +#endif + +/* These flags are kept in t_state. */ +#define TS_SO_OLOWAT 0x00001 /* Wake up when output <= low water. */ +#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */ +#define TS_BUSY 0x00004 /* Draining output. */ +#define TS_CARR_ON 0x00008 /* Carrier is present. */ +#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */ +#define TS_ISOPEN 0x00020 /* Open has completed. */ +#define TS_TBLOCK 0x00040 /* Further input blocked. */ +#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */ +#define TS_TTSTOP 0x00100 /* Output paused. */ +#ifdef notyet +#define TS_WOPEN 0x00200 /* Open in progress. */ +#endif +#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */ + +/* State for intra-line fancy editing work. */ +#define TS_BKSL 0x00800 /* State for lowercase \ work. */ +#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */ +#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */ +#define TS_LNCH 0x04000 /* Next character is literal. */ +#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */ +#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN) + +/* Extras. */ +#define TS_CAN_BYPASS_L_RINT 0x010000 /* Device in "raw" mode. */ +#define TS_CONNECTED 0x020000 /* Connection open. */ +#define TS_SNOOP 0x040000 /* Device is being snooped on. */ +#define TS_SO_OCOMPLETE 0x080000 /* Wake up when output completes. */ +#define TS_ZOMBIE 0x100000 /* Connection lost. */ + +/* Hardware flow-control-invoked bits. */ +#define TS_CAR_OFLOW 0x200000 /* For MDMBUF (XXX handle in driver). */ +#ifdef notyet +#define TS_CTS_OFLOW 0x400000 /* For CCTS_OFLOW. */ +#define TS_DSR_OFLOW 0x800000 /* For CDSR_OFLOW. */ +#endif + +/* Character type information. */ +#define ORDINARY 0 +#define CONTROL 1 +#define BACKSPACE 2 +#define NEWLINE 3 +#define TAB 4 +#define VTAB 5 +#define RETURN 6 + +struct speedtab { + int sp_speed; /* Speed. */ + int sp_code; /* Code. */ +}; + +/* Modem control commands (driver). */ +#define DMSET 0 +#define DMBIS 1 +#define DMBIC 2 +#define DMGET 3 + +/* Flags on a character passed to ttyinput. */ +#define TTY_CHARMASK 0x000000ff /* Character mask */ +#define TTY_QUOTE 0x00000100 /* Character quoted */ +#define TTY_ERRORMASK 0xff000000 /* Error mask */ +#define TTY_FE 0x01000000 /* Framing error */ +#define TTY_PE 0x02000000 /* Parity error */ +#define TTY_OE 0x04000000 /* Overrun error */ +#define TTY_BI 0x08000000 /* Break condition */ + +/* Is tp controlling terminal for p? */ +#define isctty(p, tp) \ + ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT) + +/* Is p in background of tp? */ +#define isbackground(p, tp) \ + (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp) + +/* Unique sleep addresses. */ +#define TSA_CARR_ON(tp) ((void *)&(tp)->t_rawq) +#define TSA_HUP_OR_INPUT(tp) ((void *)&(tp)->t_rawq.c_cf) +#define TSA_OCOMPLETE(tp) ((void *)&(tp)->t_outq.c_cl) +#define TSA_OLOWAT(tp) ((void *)&(tp)->t_outq) +#define TSA_PTC_READ(tp) ((void *)&(tp)->t_outq.c_cf) +#define TSA_PTC_WRITE(tp) ((void *)&(tp)->t_rawq.c_cl) +#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq) + +#ifdef _KERNEL +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_TTYS); +#endif +extern struct msgbuf consmsgbuf; /* Message buffer for constty. */ +extern struct tty *constty; /* Temporary virtual console. */ +extern long tk_cancc; +extern long tk_nin; +extern long tk_nout; +extern long tk_rawcc; + +int b_to_q(char *cp, int cc, struct clist *q); +void catq(struct clist *from, struct clist *to); +void clist_alloc_cblocks(struct clist *q, int ccmax, int ccres); +void clist_free_cblocks(struct clist *q); +void constty_set(struct tty *tp); +void constty_clear(void); +int getc(struct clist *q); +void ndflush(struct clist *q, int cc); +char *nextc(struct clist *q, char *cp, int *c); +void nottystop(struct tty *tp, int rw); +int putc(int c, struct clist *q); +int q_to_b(struct clist *q, char *cp, int cc); +void termioschars(struct termios *t); +int tputchar(int c, struct tty *tp); +int ttcompat(struct tty *tp, u_long com, caddr_t data, int flag); +int ttioctl(struct tty *tp, u_long com, void *data, int flag); +int ttread(struct tty *tp, struct uio *uio, int flag); +void ttrstrt(void *tp); +int ttsetcompat(struct tty *tp, u_long *com, caddr_t data, + struct termios *term); +void ttsetwater(struct tty *tp); +int ttspeedtab(int speed, struct speedtab *table); +int ttstart(struct tty *tp); +void ttwakeup(struct tty *tp); +int ttwrite(struct tty *tp, struct uio *uio, int flag); +void ttwwakeup(struct tty *tp); +void ttyblock(struct tty *tp); +void ttychars(struct tty *tp); +int ttycheckoutq(struct tty *tp, int wait); +int ttyclose(struct tty *tp); +void ttyflush(struct tty *tp, int rw); +void ttyfree(struct tty *tp); +void ttyinfo(struct tty *tp); +int ttyinput(int c, struct tty *tp); +int ttykqfilter(dev_t dev, struct knote *kn); +int ttylclose(struct tty *tp, int flag); +struct tty *ttymalloc(struct tty *tp); +int ttymodem(struct tty *tp, int flag); +int ttyopen(dev_t device, struct tty *tp); +int ttypoll(dev_t dev, int events, struct thread *td); +int ttyread(dev_t dev, struct uio *uio, int flag); +void ttyregister(struct tty *tp); +int ttysleep(struct tty *tp, void *chan, int pri, char *wmesg, int timo); +int ttywait(struct tty *tp); +int ttywrite(dev_t dev, struct uio *uio, int flag); +int unputc(struct clist *q); + +#endif /* _KERNEL */ + +#endif /* !_SYS_TTY_H_ */ diff --git a/src/include/sys/ttychars.h b/src/include/sys/ttychars.h new file mode 100644 index 0000000..4048199 --- /dev/null +++ b/src/include/sys/ttychars.h @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)ttychars.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/sys/ttychars.h,v 1.8 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_TTYCHARS_H_ +#define _SYS_TTYCHARS_H_ + +/* + * 4.3 COMPATIBILITY FILE + * + * User visible structures and constants related to terminal handling. + */ + +struct ttychars { + char tc_erase; /* erase last character */ + char tc_kill; /* erase entire line */ + char tc_intrc; /* interrupt */ + char tc_quitc; /* quit */ + char tc_startc; /* start output */ + char tc_stopc; /* stop output */ + char tc_eofc; /* end-of-file */ + char tc_brkc; /* input delimiter (like nl) */ + char tc_suspc; /* stop process signal */ + char tc_dsuspc; /* delayed stop process signal */ + char tc_rprntc; /* reprint line */ + char tc_flushc; /* flush output (toggles) */ + char tc_werasc; /* word erase */ + char tc_lnextc; /* literal next character */ +}; +#ifdef USE_OLD_TTY +#include /* to pick up character defaults */ +#endif +#endif /* !_SYS_TTYCHARS_H_ */ diff --git a/src/include/sys/ttycom.h b/src/include/sys/ttycom.h new file mode 100644 index 0000000..6cdbd84 --- /dev/null +++ b/src/include/sys/ttycom.h @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)ttycom.h 8.1 (Berkeley) 3/28/94 + * $FreeBSD: src/sys/sys/ttycom.h,v 1.20 2004/05/10 02:24:56 emax Exp $ + */ + +#ifndef _SYS_TTYCOM_H_ +#define _SYS_TTYCOM_H_ + +#include + +/* + * Tty ioctl's except for those supported only for backwards compatibility + * with the old tty driver. + */ + +/* + * Window/terminal size structure. This information is stored by the kernel + * in order to provide a consistent interface, but is not used by the kernel. + */ +struct winsize { + unsigned short ws_row; /* rows, in characters */ + unsigned short ws_col; /* columns, in characters */ + unsigned short ws_xpixel; /* horizontal size, pixels */ + unsigned short ws_ypixel; /* vertical size, pixels */ +}; + + /* 0-2 compat */ + /* 3-4 obsolete */ + /* 5-7 obsolete or unused */ + /* 8-10 compat */ + /* 11-12 obsolete or unused */ +#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */ +#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */ + /* 15 unused */ +#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */ + /* 17-18 compat */ +#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */ +#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */ +#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */ +#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */ + /* 23-25 obsolete or unused */ +#define TIOCGETD _IOR('t', 26, int) /* get line discipline */ +#define TIOCSETD _IOW('t', 27, int) /* set line discipline */ + /* 28-69 free */ + /* 127-124 compat */ +#define TIOCSBRK _IO('t', 123) /* set break bit */ +#define TIOCCBRK _IO('t', 122) /* clear break bit */ +#define TIOCSDTR _IO('t', 121) /* set data terminal ready */ +#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */ +#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ +#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ + /* 117-116 compat */ +#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ +#define TIOCSTI _IOW('t', 114, char) /* simulate terminal input */ +#define TIOCNOTTY _IO('t', 113) /* void tty association */ +#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */ +#define TIOCPKT_DATA 0x00 /* data packet */ +#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ +#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ +#define TIOCPKT_STOP 0x04 /* stop output */ +#define TIOCPKT_START 0x08 /* start output */ +#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ +#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ +#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */ +#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */ +#define TIOCSTART _IO('t', 110) /* start output, like ^Q */ +#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */ +#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */ +#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */ +#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */ +#define TIOCM_LE 0001 /* line enable */ +#define TIOCM_DTR 0002 /* data terminal ready */ +#define TIOCM_RTS 0004 /* request to send */ +#define TIOCM_ST 0010 /* secondary transmit */ +#define TIOCM_SR 0020 /* secondary receive */ +#define TIOCM_CTS 0040 /* clear to send */ +#define TIOCM_CAR 0100 /* carrier detect */ +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RNG 0200 /* ring */ +#define TIOCM_RI TIOCM_RNG +#define TIOCM_DSR 0400 /* data set ready */ +#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */ +#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ +#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ +#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ +#define TIOCSTAT _IO('t', 101) /* simulate ^T status message */ +#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */ + /* 100 see consio.h */ + /* 99 obsolete or unused */ +#define TIOCCONS _IOW('t', 98, int) /* become virtual console */ +#define TIOCSCTTY _IO('t', 97) /* become controlling tty */ + /* 97-90 tun; some conflicts */ +#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */ +#define TIOCSIG _IO('t', 95) /* pty: generate signal */ +#define TIOCDRAIN _IO('t', 94) /* wait till output drained */ + /* 92-90 tap; some conflicts */ +#define TIOCMSDTRWAIT _IOW('t', 91, int) /* modem: set wait on close */ +#define TIOCMGDTRWAIT _IOR('t', 90, int) /* modem: get wait on close */ + /* 90-70 ppp; many conflicts */ +#define TIOCTIMESTAMP _IOR('t', 89, struct timeval) /* enable/get timestamp + * of last input event */ +#define TIOCDCDTIMESTAMP _IOR('t', 88, struct timeval) /* enable/get timestamp + * of last DCd rise */ + /* 88 slip; conflicts */ +#define TIOCSDRAINWAIT _IOW('t', 87, int) /* set ttywait timeout */ +#define TIOCGDRAINWAIT _IOR('t', 86, int) /* get ttywait timeout */ + /* 84-80 slip */ + +#define TTYDISC 0 /* termios tty line discipline */ +#define SLIPDISC 4 /* serial IP discipline */ +#define PPPDISC 5 /* PPP discipline */ +#define NETGRAPHDISC 6 /* Netgraph tty node discipline */ +#define H4DISC 7 /* Netgraph Bluetooth H4 discipline */ + +#endif /* !_SYS_TTYCOM_H_ */ diff --git a/src/include/sys/ttydefaults.h b/src/include/sys/ttydefaults.h new file mode 100644 index 0000000..659e804 --- /dev/null +++ b/src/include/sys/ttydefaults.h @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94 + * $FreeBSD: src/sys/sys/ttydefaults.h,v 1.15 2004/04/07 04:19:50 imp Exp $ + */ + +/* + * System wide defaults for terminal state. + */ +#ifndef _SYS_TTYDEFAULTS_H_ +#define _SYS_TTYDEFAULTS_H_ + +/* + * Defaults on "first" open. + */ +#define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY) +#define TTYDEF_OFLAG (OPOST | ONLCR) +#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) +#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL) +#define TTYDEF_SPEED (B9600) + +/* + * Control Character Defaults + */ +#define CTRL(x) (x&037) +#define CEOF CTRL('d') +#define CEOL 0xff /* XXX avoid _POSIX_VDISABLE */ +#define CERASE 0177 +#define CERASE2 CTRL('h') +#define CINTR CTRL('c') +#define CSTATUS CTRL('t') +#define CKILL CTRL('u') +#define CMIN 1 +#define CQUIT 034 /* FS, ^\ */ +#define CSUSP CTRL('z') +#define CTIME 0 +#define CDSUSP CTRL('y') +#define CSTART CTRL('q') +#define CSTOP CTRL('s') +#define CLNEXT CTRL('v') +#define CDISCARD CTRL('o') +#define CWERASE CTRL('w') +#define CREPRINT CTRL('r') +#define CEOT CEOF +/* compat */ +#define CBRK CEOL +#define CRPRNT CREPRINT +#define CFLUSH CDISCARD + +/* PROTECTED INCLUSION ENDS HERE */ +#endif /* !_SYS_TTYDEFAULTS_H_ */ + +/* + * #define TTYDEFCHARS to include an array of default control characters. + */ +#ifdef TTYDEFCHARS +static cc_t ttydefchars[NCCS] = { + CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT, + CERASE2, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT, + CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE +}; +#undef TTYDEFCHARS +#endif diff --git a/src/include/sys/ttydev.h b/src/include/sys/ttydev.h new file mode 100644 index 0000000..d1edb63 --- /dev/null +++ b/src/include/sys/ttydev.h @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)ttydev.h 8.2 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/sys/ttydev.h,v 1.10 2004/04/07 04:19:50 imp Exp $ + */ + +/* COMPATIBILITY HEADER FILE */ + +#ifndef _SYS_TTYDEV_H_ +#define _SYS_TTYDEV_H_ + +#ifdef USE_OLD_TTY +#define B0 0 +#define B50 1 +#define B75 2 +#define B110 3 +#define B134 4 +#define B150 5 +#define B200 6 +#define B300 7 +#define B600 8 +#define B1200 9 +#define B1800 10 +#define B2400 11 +#define B4800 12 +#define B9600 13 +#define EXTA 14 +#define EXTB 15 +#define B57600 16 +#define B115200 17 +#define B230400 18 +#define B460800 19 +#define B921600 20 +#endif /* USE_OLD_TTY */ + +#endif /* !_SYS_TTYDEV_H_ */ diff --git a/src/include/sys/turnstile.h b/src/include/sys/turnstile.h new file mode 100644 index 0000000..902706e --- /dev/null +++ b/src/include/sys/turnstile.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2002 John Baldwin + * 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. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/turnstile.h,v 1.4 2004/04/06 19:08:40 jhb Exp $ + */ + +#ifndef _SYS_TURNSTILE_H_ +#define _SYS_TURNSTILE_H_ + +/* + * Turnstile interface. Non-sleepable locks use a turnstile for the + * queue of threads blocked on them when they are contested. + * + * A thread calls turnstile_lookup() to look up the proper turnstile in + * the hash table. This function returns a pointer to the turnstile and + * locks the associated turnstile chain. A thread calls turnstile_wait() + * when the lock is contested to be put on the queue and block. If a + * thread needs to retry a lock operation instead of blocking, it should + * call turnstile_release() to unlock the associated turnstile chain lock. + * + * When a lock is released, either turnstile_signal() or turnstile_broadcast() + * is called to mark blocked threads for a pending wakeup. + * turnstile_signal() marks the highest priority blocked thread while + * turnstile_broadcast() marks all blocked threads. The turnstile_signal() + * function returns true if the turnstile became empty as a result. After + * the higher level code finishes releasing the lock, turnstile_unpend() + * must be called to wakeup the pending thread(s). + * + * When a lock is acquired that already has at least one thread contested + * on it, the new owner of the lock must claim ownership of the turnstile + * via turnstile_claim(). + * + * Each thread allocates a turnstile at thread creation via turnstile_alloc() + * and releases it at thread destruction via turnstile_free(). Note that + * a turnstile is not tied to a specific thread and that the turnstile + * released at thread destruction may not be the same turnstile that the + * thread allocated when it was created. + * + * A function can query a turnstile to see if it is empty via + * turnstile_empty(). The highest priority thread blocked on a turnstile + * can be obtained via turnstile_head(). + */ + +struct lock_object; +struct thread; +struct turnstile; + +#ifdef _KERNEL + +void init_turnstiles(void); +struct turnstile *turnstile_alloc(void); +void turnstile_broadcast(struct turnstile *); +void turnstile_claim(struct turnstile *); +int turnstile_empty(struct turnstile *); +void turnstile_free(struct turnstile *); +struct thread *turnstile_head(struct turnstile *); +struct turnstile *turnstile_lookup(struct lock_object *); +void turnstile_release(struct lock_object *); +int turnstile_signal(struct turnstile *); +void turnstile_unpend(struct turnstile *); +void turnstile_wait(struct turnstile *, struct lock_object *, + struct thread *); + +#endif /* _KERNEL */ +#endif /* _SYS_TURNSTILE_H_ */ diff --git a/src/include/sys/types.h b/src/include/sys/types.h new file mode 100644 index 0000000..b553e19 --- /dev/null +++ b/src/include/sys/types.h @@ -0,0 +1,328 @@ +/*- + * Copyright (c) 1982, 1986, 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 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. + * + * @(#)types.h 8.6 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/types.h,v 1.86 2004/04/19 22:49:00 obrien Exp $ + */ + +#ifndef _SYS_TYPES_H_ +#define _SYS_TYPES_H_ + +#include + +/* Machine type dependent parameters. */ +#include +#include + +#if __BSD_VISIBLE +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; +#ifndef _KERNEL +typedef unsigned short ushort; /* Sys V compatibility */ +typedef unsigned int uint; /* Sys V compatibility */ +#endif +#endif + +/* + * XXX POSIX sized integrals that should appear only in . + */ +#ifndef _INT8_T_DECLARED +typedef __int8_t int8_t; +#define _INT8_T_DECLARED +#endif + +#ifndef _INT16_T_DECLARED +typedef __int16_t int16_t; +#define _INT16_T_DECLARED +#endif + +#ifndef _INT32_T_DECLARED +typedef __int32_t int32_t; +#define _INT32_T_DECLARED +#endif + +#ifndef _INT64_T_DECLARED +typedef __int64_t int64_t; +#define _INT64_T_DECLARED +#endif + +#ifndef _UINT8_T_DECLARED +typedef __uint8_t uint8_t; +#define _UINT8_T_DECLARED +#endif + +#ifndef _UINT16_T_DECLARED +typedef __uint16_t uint16_t; +#define _UINT16_T_DECLARED +#endif + +#ifndef _UINT32_T_DECLARED +typedef __uint32_t uint32_t; +#define _UINT32_T_DECLARED +#endif + +#ifndef _UINT64_T_DECLARED +typedef __uint64_t uint64_t; +#define _UINT64_T_DECLARED +#endif + +#ifndef _INTPTR_T_DECLARED +typedef __intptr_t intptr_t; +typedef __uintptr_t uintptr_t; +#define _INTPTR_T_DECLARED +#endif + +typedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */ +typedef __uint16_t u_int16_t; +typedef __uint32_t u_int32_t; +typedef __uint64_t u_int64_t; + +typedef __uint64_t u_quad_t; /* quads (deprecated) */ +typedef __int64_t quad_t; +typedef quad_t * qaddr_t; + +typedef char * caddr_t; /* core address */ +typedef __const char * c_caddr_t; /* core address, pointer to const */ +typedef __volatile char *v_caddr_t; /* core address, pointer to volatile */ + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +#ifndef _CLOCKID_T_DECLARED +typedef __clockid_t clockid_t; +#define _CLOCKID_T_DECLARED +#endif + +typedef __critical_t critical_t; /* Critical section value */ +typedef __int64_t daddr_t; /* disk address */ + +#ifndef _DEV_T_DECLARED +typedef __dev_t dev_t; /* device number or struct cdev */ +#define _DEV_T_DECLARED +#endif + +#ifndef _FFLAGS_T_DECLARED +typedef __fflags_t fflags_t; /* file flags */ +#define _FFLAGS_T_DECLARED +#endif + +typedef __uint32_t fixpt_t; /* fixed point number */ + +#ifndef _FSBLKCNT_T_DECLARED /* for statvfs() */ +typedef __fsblkcnt_t fsblkcnt_t; +typedef __fsfilcnt_t fsfilcnt_t; +#define _FSBLKCNT_T_DECLARED +#endif + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; /* group id */ +#define _GID_T_DECLARED +#endif + +#ifndef _IN_ADDR_T_DECLARED +typedef __uint32_t in_addr_t; /* base type for internet address */ +#define _IN_ADDR_T_DECLARED +#endif + +#ifndef _IN_PORT_T_DECLARED +typedef __uint16_t in_port_t; +#define _IN_PORT_T_DECLARED +#endif + +#ifndef _ID_T_DECLARED +typedef __id_t id_t; /* can hold a uid_t or pid_t */ +#define _ID_T_DECLARED +#endif + +#ifndef _INO_T_DECLARED +typedef __ino_t ino_t; /* inode number */ +#define _INO_T_DECLARED +#endif + +#ifndef _KEY_T_DECLARED +typedef __key_t key_t; /* IPC key (for Sys V IPC) */ +#define _KEY_T_DECLARED +#endif + +#ifndef _MODE_T_DECLARED +typedef __mode_t mode_t; /* permissions */ +#define _MODE_T_DECLARED +#endif + +#ifndef _NLINK_T_DECLARED +typedef __nlink_t nlink_t; /* link count */ +#define _NLINK_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; /* file offset */ +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; /* process id */ +#define _PID_T_DECLARED +#endif + +typedef __register_t register_t; + +#ifndef _RLIM_T_DECLARED +typedef __rlim_t rlim_t; /* resource limit */ +#define _RLIM_T_DECLARED +#endif + +typedef __segsz_t segsz_t; /* segment size (in pages) */ + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _SUSECONDS_T_DECLARED +typedef __suseconds_t suseconds_t; /* microseconds (signed) */ +#define _SUSECONDS_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _TIMER_T_DECLARED +typedef __timer_t timer_t; +#define _TIMER_T_DECLARED +#endif + +typedef __u_register_t u_register_t; +typedef __udev_t udev_t; /* device number */ + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; /* user id */ +#define _UID_T_DECLARED +#endif + +#ifndef _USECONDS_T_DECLARED +typedef __useconds_t useconds_t; /* microseconds (unsigned) */ +#define _USECONDS_T_DECLARED +#endif + +typedef __vm_offset_t vm_offset_t; +typedef __vm_ooffset_t vm_ooffset_t; +typedef __vm_paddr_t vm_paddr_t; +typedef __vm_pindex_t vm_pindex_t; +typedef __vm_size_t vm_size_t; + +#ifdef _KERNEL +typedef int boolean_t; +typedef __cpumask_t cpumask_t; +typedef __intfptr_t intfptr_t; + +/*- + * XXX this is fixed width for historical reasons. It should have had type + * __int_fast32_t. Fixed-width types should not be used unless binary + * compatibility is essential. Least-width types should be used even less + * since they provide smaller benefits. + * XXX should be MD. + * XXX this is bogus in -current, but still used for spl*(). + */ +typedef __uint32_t intrmask_t; /* Interrupt mask (spl, xxx_imask...) */ + +typedef __uintfptr_t uintfptr_t; +typedef __uint64_t uoff_t; +typedef struct vm_page *vm_page_t; + +#define offsetof(type, field) __offsetof(type, field) + +#endif /* !_KERNEL */ + +/* + * The following are all things that really shouldn't exist in this header, + * since its purpose is to provide typedefs, not miscellaneous doodads. + */ +#if __BSD_VISIBLE + +#include + +#ifndef _KERNEL +/* + * minor() gives a cookie instead of an index since we don't want to + * change the meanings of bits 0-15 or waste time and space shifting + * bits 16-31 for devices that don't use them. + */ +#define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */ +#define minor(x) ((int)((x)&0xffff00ff)) /* minor number */ +#define makedev(x,y) ((dev_t)(((x) << 8) | (y))) /* create dev_t */ +#endif /* !_KERNEL */ + +/* + * These declarations belong elsewhere, but are repeated here and in + * to give broken programs a better chance of working with + * 64-bit off_t's. + */ +#ifndef _KERNEL +__BEGIN_DECLS +#ifndef _FTRUNCATE_DECLARED +#define _FTRUNCATE_DECLARED +int ftruncate(int, off_t); +#endif +#ifndef _LSEEK_DECLARED +#define _LSEEK_DECLARED +off_t lseek(int, off_t, int); +#endif +#ifndef _MMAP_DECLARED +#define _MMAP_DECLARED +void * mmap(void *, size_t, int, int, int, off_t); +#endif +#ifndef _TRUNCATE_DECLARED +#define _TRUNCATE_DECLARED +int truncate(const char *, off_t); +#endif +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* __BSD_VISIBLE */ + +typedef unsigned char uInt8; +typedef unsigned short uInt16; +typedef unsigned long uInt32; + +#endif /* !_SYS_TYPES_H_ */ diff --git a/src/include/sys/ucontext.h b/src/include/sys/ucontext.h new file mode 100644 index 0000000..6ca4dda --- /dev/null +++ b/src/include/sys/ucontext.h @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 1999 Marcel Moolenaar + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/ucontext.h,v 1.11 2003/11/09 20:31:04 marcel Exp $ + */ + +#ifndef _SYS_UCONTEXT_H_ +#define _SYS_UCONTEXT_H_ + +#include +#include + +typedef struct __ucontext { + /* + * Keep the order of the first two fields. Also, + * keep them the first two fields in the structure. + * This way we can have a union with struct + * sigcontext and ucontext_t. This allows us to + * support them both at the same time. + * note: the union is not defined, though. + */ + sigset_t uc_sigmask; + mcontext_t uc_mcontext; + + struct __ucontext *uc_link; + stack_t uc_stack; + int uc_flags; +#define UCF_SWAPPED 0x00000001 /* Used by swapcontext(3). */ + int __spare__[4]; +} ucontext_t; + +#if defined(_KERNEL) && defined(COMPAT_FREEBSD4) +#if defined(__i386__) || defined(__alpha__) +struct ucontext4 { + sigset_t uc_sigmask; + struct mcontext4 uc_mcontext; + struct ucontext4 *uc_link; + stack_t uc_stack; + int __spare__[8]; +}; +#else /* __i386__ || __alpha__ */ +#define ucontext4 ucontext +#endif /* __i386__ || __alpha__ */ +#endif /* _KERNEL */ + +#ifndef _KERNEL + +__BEGIN_DECLS + +int getcontext(ucontext_t *); +int setcontext(const ucontext_t *); +void makecontext(ucontext_t *, void (*)(void), int, ...); +int signalcontext(ucontext_t *, int, __sighandler_t *); +int swapcontext(ucontext_t *, const ucontext_t *); + +__END_DECLS + +#else /* _KERNEL */ + +struct thread; + +/* + * Flags for get_mcontext(). The low order 4 bits (i.e a mask of 0x0f) are + * reserved for use by machine independent code. All other bits are for use + * by machine dependent code. + */ +#define GET_MC_CLEAR_RET 1 + +/* Machine-dependent functions: */ +int get_mcontext(struct thread *, mcontext_t *, int); +int set_mcontext(struct thread *, const mcontext_t *); + +#endif /* !_KERNEL */ + +#endif /* !_SYS_UCONTEXT_H_ */ diff --git a/src/include/sys/ucred.h b/src/include/sys/ucred.h new file mode 100644 index 0000000..ea4cf99 --- /dev/null +++ b/src/include/sys/ucred.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1989, 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. + * 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. + * + * @(#)ucred.h 8.4 (Berkeley) 1/9/95 + * $FreeBSD: src/sys/sys/ucred.h,v 1.49 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_UCRED_H_ +#define _SYS_UCRED_H_ + +/* + * Credentials. + * + * Please do not inspect cr_uid directly to determine superuserness. + * Only the suser() or suser_cred() function should be used for this. + */ +#if defined(_KERNEL) || defined(_WANT_UCRED) +struct ucred { + u_int cr_ref; /* reference count */ +#define cr_startcopy cr_uid + uid_t cr_uid; /* effective user id */ + uid_t cr_ruid; /* real user id */ + uid_t cr_svuid; /* saved user id */ + short cr_ngroups; /* number of groups */ + gid_t cr_groups[NGROUPS]; /* groups */ + gid_t cr_rgid; /* real group id */ + gid_t cr_svgid; /* saved user id */ + struct uidinfo *cr_uidinfo; /* per euid resource consumption */ + struct uidinfo *cr_ruidinfo; /* per ruid resource consumption */ + struct prison *cr_prison; /* jail(2) */ +#define cr_endcopy cr_label + struct label *cr_label; /* MAC label */ + struct mtx *cr_mtxp; /* protect refcount */ +}; +#define NOCRED ((struct ucred *)0) /* no credential available */ +#define FSCRED ((struct ucred *)-1) /* filesystem credential */ +#endif /* _KERNEL || _WANT_UCRED */ + +/* + * This is the external representation of struct ucred. + */ +struct xucred { + u_int cr_version; /* structure layout version */ + uid_t cr_uid; /* effective user id */ + short cr_ngroups; /* number of groups */ + gid_t cr_groups[NGROUPS]; /* groups */ + void *_cr_unused1; /* compatibility with old ucred */ +}; +#define XUCRED_VERSION 0 + +/* This can be used for both ucred and xucred structures. */ +#define cr_gid cr_groups[0] + +#ifdef _KERNEL +struct thread; + +void change_egid(struct ucred *newcred, gid_t egid); +void change_euid(struct ucred *newcred, struct uidinfo *euip); +void change_rgid(struct ucred *newcred, gid_t rgid); +void change_ruid(struct ucred *newcred, struct uidinfo *ruip); +void change_svgid(struct ucred *newcred, gid_t svgid); +void change_svuid(struct ucred *newcred, uid_t svuid); +void crcopy(struct ucred *dest, struct ucred *src); +struct ucred *crdup(struct ucred *cr); +#ifdef DIAGNOSTIC +void cred_free_thread(struct thread *td); +#endif +void cred_update_thread(struct thread *td); +void crfree(struct ucred *cr); +struct ucred *crget(void); +struct ucred *crhold(struct ucred *cr); +int crshared(struct ucred *cr); +void cru2x(struct ucred *cr, struct xucred *xcr); +int groupmember(gid_t gid, struct ucred *cred); +#endif /* _KERNEL */ + +#endif /* !_SYS_UCRED_H_ */ diff --git a/src/include/sys/uio.h b/src/include/sys/uio.h new file mode 100644 index 0000000..ff6eacd --- /dev/null +++ b/src/include/sys/uio.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1982, 1986, 1993, 1994 + * 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. + * 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. + * + * @(#)uio.h 8.5 (Berkeley) 2/22/94 + * $FreeBSD: src/sys/sys/uio.h,v 1.35 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#include +#include +#include + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#if __BSD_VISIBLE +enum uio_rw { UIO_READ, UIO_WRITE }; + +/* Segment flag values. */ +enum uio_seg { + UIO_USERSPACE, /* from user data space */ + UIO_SYSSPACE, /* from system space */ + UIO_NOCOPY /* don't copy, already in object */ +}; +#endif + +#ifdef _KERNEL + +struct uio { + struct iovec *uio_iov; + int uio_iovcnt; + off_t uio_offset; + int uio_resid; + enum uio_seg uio_segflg; + enum uio_rw uio_rw; + struct thread *uio_td; +}; + +/* + * Limits + * + * N.B.: UIO_MAXIOV must be no less than IOV_MAX from + * which in turn must be no less than _XOPEN_IOV_MAX from . If + * we ever make this tunable (probably pointless), then IOV_MAX should be + * removed from and applications would be expected to use + * sysconf(3) to find out the correct value, or else assume the worst + * (_XOPEN_IOV_MAX). Perhaps UIO_MAXIOV should be simply defined as + * IOV_MAX. + */ +#define UIO_MAXIOV 1024 /* max 1K of iov's */ +#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */ + +struct vm_object; +struct vm_page; + +int copyinfrom(const void * __restrict src, void * __restrict dst, + size_t len, int seg); +int copyinstrfrom(const void * __restrict src, void * __restrict dst, + size_t len, size_t * __restrict copied, int seg); +void uio_yield(void); +int uiofromiov(struct iovec *iovp, u_int iovcnt, struct uio *auio); +int uiomove(void *cp, int n, struct uio *uio); +int uiomove_frombuf(void *buf, int buflen, struct uio *uio); +int uiomove_fromphys(struct vm_page *ma[], vm_offset_t offset, int n, + struct uio *uio); +int uiomoveco(void *cp, int n, struct uio *uio, struct vm_object *obj, + int disposable); + +#else /* !_KERNEL */ + +__BEGIN_DECLS +ssize_t readv(int, const struct iovec *, int); +ssize_t writev(int, const struct iovec *, int); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_UIO_H_ */ diff --git a/src/include/sys/umtx.h b/src/include/sys/umtx.h new file mode 100644 index 0000000..3984c94 --- /dev/null +++ b/src/include/sys/umtx.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2002, Jeffrey Roberson + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/umtx.h,v 1.3 2003/12/23 02:36:43 peter Exp $ + * + */ + +#ifndef _SYS_UMTX_H_ +#define _SYS_UMTX_H_ + +/* + * See pthread_* + */ + +#define UMTX_UNOWNED 0x0 +#define UMTX_CONTESTED 0x1 + + +struct umtx { + thr_id_t u_owner; /* Owner of the mutex. */ +}; + +#ifndef _KERNEL + +/* + * System calls for acquiring and releasing contested mutexes. + */ +int _umtx_lock(struct umtx *mtx); +int _umtx_unlock(struct umtx *mtx); + +/* + * Standard api. Try uncontested acquire/release and asks the + * kernel to resolve failures. + */ +static __inline int +umtx_lock(struct umtx *umtx, thr_id_t id) +{ + if (atomic_cmpset_acq_ptr(&umtx->u_owner, UMTX_UNOWNED, id) == 0) + if (_umtx_lock(umtx) == -1) + return (errno); + + return (0); +} + +static __inline int +umtx_trylock(struct umtx *umtx, thr_id_t id) +{ + if (atomic_cmpset_acq_ptr(&umtx->u_owner, UMTX_UNOWNED, id) == 0) + return (EBUSY); + + return (0); +} + +static __inline int +umtx_unlock(struct umtx *umtx, thr_id_t id) +{ + if (atomic_cmpset_rel_ptr(&umtx->u_owner, id, UMTX_UNOWNED) == 0) + if (_umtx_unlock(umtx) == -1) + return (errno); + return (0); +} +#endif /* !_KERNEL */ + +#endif /* !_SYS_UMTX_H_ */ diff --git a/src/include/sys/un.h b/src/include/sys/un.h new file mode 100644 index 0000000..09de645 --- /dev/null +++ b/src/include/sys/un.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)un.h 8.3 (Berkeley) 2/19/95 + * $FreeBSD: src/sys/sys/un.h,v 1.27 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_UN_H_ +#define _SYS_UN_H_ + +#include +#include + +#ifndef _SA_FAMILY_T_DECLARED +typedef __sa_family_t sa_family_t; +#define _SA_FAMILY_T_DECLARED +#endif + +/* + * Definitions for UNIX IPC domain. + */ +struct sockaddr_un { + unsigned char sun_len; /* sockaddr len including null */ + sa_family_t sun_family; /* AF_UNIX */ + char sun_path[104]; /* path name (gag) */ +}; + +#if __BSD_VISIBLE + +/* Socket options. */ +#define LOCAL_PEERCRED 0x001 /* retrieve peer credentails */ + +#ifdef _KERNEL +struct mbuf; +struct socket; +struct sockopt; + +int uipc_connect2(struct socket *so1, struct socket *so2); +int uipc_ctloutput(struct socket *so, struct sockopt *sopt); +int uipc_usrreq(struct socket *so, int req, struct mbuf *m, + struct mbuf *nam, struct mbuf *control); +void unp_dispose(struct mbuf *m); +int unp_externalize(struct mbuf *mbuf, struct mbuf **controlp); +void unp_init(void); +extern struct pr_usrreqs uipc_usrreqs; + +#else /* !_KERNEL */ + +/* actual length of an initialized sockaddr_un */ +#define SUN_LEN(su) \ + (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) + +#endif /* _KERNEL */ + +#endif /* __BSD_VISIBLE */ + +#endif /* !_SYS_UN_H_ */ diff --git a/src/include/sys/unistd.h b/src/include/sys/unistd.h new file mode 100644 index 0000000..d2a5d97 --- /dev/null +++ b/src/include/sys/unistd.h @@ -0,0 +1,179 @@ +/* + * Copyright (c) 1989, 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. + * 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. + * + * @(#)unistd.h 8.2 (Berkeley) 1/7/94 + * $FreeBSD: src/sys/sys/unistd.h,v 1.40 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_UNISTD_H_ +#define _SYS_UNISTD_H_ + +#include + +/* + * POSIX options and option groups we unconditionally do or don't + * implement. Those options which are implemented (or not) entirely + * in user mode are defined in . Please keep this list in + * alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ +#define _POSIX_ADVISORY_INFO -1 +#define _POSIX_ASYNCHRONOUS_IO 0 +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_CLOCK_SELECTION -1 +#define _POSIX_CPUTIME -1 +#define _POSIX_FSYNC 200112L +#define _POSIX_IPV6 0 +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_MAPPED_FILES 200112L +#define _POSIX_MEMLOCK -1 +#define _POSIX_MEMLOCK_RANGE 200112L +#define _POSIX_MEMORY_PROTECTION 200112L +#define _POSIX_MESSAGE_PASSING -1 +#define _POSIX_MONOTONIC_CLOCK -1 +#define _POSIX_NO_TRUNC 1 +#define _POSIX_PRIORITIZED_IO -1 +#define _POSIX_PRIORITY_SCHEDULING 200112L +#define _POSIX_RAW_SOCKETS 200112L +#define _POSIX_REALTIME_SIGNALS -1 +#define _POSIX_SEMAPHORES -1 +#define _POSIX_SHARED_MEMORY_OBJECTS 200112L +#define _POSIX_SPORADIC_SERVER -1 +#define _POSIX_SYNCHRONIZED_IO -1 +#define _POSIX_TIMEOUTS -1 +#define _POSIX_TYPED_MEMORY_OBJECTS -1 +#define _POSIX_VDISABLE 0xff + +#if __XSI_VISIBLE +#define _XOPEN_SHM 1 +#define _XOPEN_STREAMS -1 +#endif + +/* + * Although we have saved user/group IDs, we do not use them in setuid + * as described in POSIX 1003.1, because the feature does not work for + * root. We use the saved IDs in seteuid/setegid, which are not currently + * part of the POSIX 1003.1 specification. XXX revisit for 1003.1-2001 + * as this is now mandatory. + */ +#ifdef _NOT_AVAILABLE +#define _POSIX_SAVED_IDS 1 /* saved set-user-ID and set-group-ID */ +#endif + +/* Define the POSIX.1 version we target for compliance. */ +#define _POSIX_VERSION 200112L + +/* access function */ +#define F_OK 0 /* test for existence of file */ +#define X_OK 0x01 /* test for execute or search permission */ +#define W_OK 0x02 /* test for write permission */ +#define R_OK 0x04 /* test for read permission */ + +/* whence values for lseek(2) */ +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +#ifndef _POSIX_SOURCE +/* whence values for lseek(2); renamed by POSIX 1003.1 */ +#define L_SET SEEK_SET +#define L_INCR SEEK_CUR +#define L_XTND SEEK_END +#endif + +/* configurable pathname variables */ +#define _PC_LINK_MAX 1 +#define _PC_MAX_CANON 2 +#define _PC_MAX_INPUT 3 +#define _PC_NAME_MAX 4 +#define _PC_PATH_MAX 5 +#define _PC_PIPE_BUF 6 +#define _PC_CHOWN_RESTRICTED 7 +#define _PC_NO_TRUNC 8 +#define _PC_VDISABLE 9 + +#if __POSIX_VISIBLE >= 199309 +#define _PC_ASYNC_IO 53 +#define _PC_PRIO_IO 54 +#define _PC_SYNC_IO 55 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _PC_ALLOC_SIZE_MIN 10 +#define _PC_FILESIZEBITS 12 +#define _PC_REC_INCR_XFER_SIZE 14 +#define _PC_REC_MAX_XFER_SIZE 15 +#define _PC_REC_MIN_XFER_SIZE 16 +#define _PC_REC_XFER_ALIGN 17 +#define _PC_SYMLINK_MAX 18 +#endif + +#if __BSD_VISIBLE +#define _PC_ACL_EXTENDED 59 +#define _PC_ACL_PATH_MAX 60 +#define _PC_CAP_PRESENT 61 +#define _PC_INF_PRESENT 62 +#define _PC_MAC_PRESENT 63 +#endif + +#if __BSD_VISIBLE +/* + * rfork() options. + * + * XXX currently, some operations without RFPROC set are not supported. + */ +#define RFNAMEG (1<<0) /* UNIMPL new plan9 `name space' */ +#define RFENVG (1<<1) /* UNIMPL copy plan9 `env space' */ +#define RFFDG (1<<2) /* copy fd table */ +#define RFNOTEG (1<<3) /* UNIMPL create new plan9 `note group' */ +#define RFPROC (1<<4) /* change child (else changes curproc) */ +#define RFMEM (1<<5) /* share `address space' */ +#define RFNOWAIT (1<<6) /* give child to init */ +#define RFCNAMEG (1<<10) /* UNIMPL zero plan9 `name space' */ +#define RFCENVG (1<<11) /* UNIMPL zero plan9 `env space' */ +#define RFCFDG (1<<12) /* close all fds, zero fd table */ +#define RFTHREAD (1<<13) /* enable kernel thread support */ +#define RFSIGSHARE (1<<14) /* share signal handlers */ +#define RFLINUXTHPN (1<<16) /* do linux clone exit parent notification */ +#define RFSTOPPED (1<<17) /* leave child in a stopped state */ +#define RFHIGHPID (1<<18) /* use a pid higher then 10 (idleproc) */ +#define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */ +#define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPPWAIT) + +#endif /* __BSD_VISIBLE */ + +#endif /* !_SYS_UNISTD_H_ */ diff --git a/src/include/sys/unpcb.h b/src/include/sys/unpcb.h new file mode 100644 index 0000000..954fd14 --- /dev/null +++ b/src/include/sys/unpcb.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 1982, 1986, 1989, 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. + * 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. + * + * @(#)unpcb.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/unpcb.h,v 1.17 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_UNPCB_H_ +#define _SYS_UNPCB_H_ + +#include +#include + +/* + * Protocol control block for an active + * instance of a UNIX internal protocol. + * + * A socket may be associated with a vnode in the + * filesystem. If so, the unp_vnode pointer holds + * a reference count to this vnode, which should be irele'd + * when the socket goes away. + * + * A socket may be connected to another socket, in which + * case the control block of the socket to which it is connected + * is given by unp_conn. + * + * A socket may be referenced by a number of sockets (e.g. several + * sockets may be connected to a datagram socket.) These sockets + * are in a linked list starting with unp_refs, linked through + * unp_nextref and null-terminated. Note that a socket may be referenced + * by a number of other sockets and may also reference a socket (not + * necessarily one which is referencing it). This generates + * the need for unp_refs and unp_nextref to be separate fields. + * + * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt + * so that changes in the sockbuf may be computed to modify + * back pressure on the sender accordingly. + */ +typedef u_quad_t unp_gen_t; +LIST_HEAD(unp_head, unpcb); + +struct unpcb { + LIST_ENTRY(unpcb) unp_link; /* glue on list of all PCBs */ + struct socket *unp_socket; /* pointer back to socket */ + struct vnode *unp_vnode; /* if associated with file */ + ino_t unp_ino; /* fake inode number */ + struct unpcb *unp_conn; /* control block of connected socket */ + struct unp_head unp_refs; /* referencing socket linked list */ + LIST_ENTRY(unpcb) unp_reflink; /* link in unp_refs list */ + struct sockaddr_un *unp_addr; /* bound address of socket */ + int unp_cc; /* copy of rcv.sb_cc */ + int unp_mbcnt; /* copy of rcv.sb_mbcnt */ + unp_gen_t unp_gencnt; /* generation count of this instance */ + int unp_flags; /* flags */ + struct xucred unp_peercred; /* peer credentials, if applicable */ +}; + +/* + * Flags in unp_flags. + * + * UNP_HAVEPC - indicates that the unp_peercred member is filled in + * and is really the credentials of the connected peer. This is used + * to determine whether the contents should be sent to the user or + * not. + * + * UNP_HAVEPCCACHED - indicates that the unp_peercred member is filled + * in, but does *not* contain the credentials of the connected peer + * (there may not even be a peer). This is set in unp_listen() when + * it fills in unp_peercred for later consumption by unp_connect(). + */ +#define UNP_HAVEPC 0x001 +#define UNP_HAVEPCCACHED 0x002 + +#define sotounpcb(so) ((struct unpcb *)((so)->so_pcb)) + +/* Hack alert -- this structure depends on . */ +#ifdef _SYS_SOCKETVAR_H_ +struct xunpcb { + size_t xu_len; /* length of this structure */ + struct unpcb *xu_unpp; /* to help netstat, fstat */ + struct unpcb xu_unp; /* our information */ + union { + struct sockaddr_un xuu_addr; /* our bound address */ + char xu_dummy1[256]; + } xu_au; +#define xu_addr xu_au.xuu_addr + union { + struct sockaddr_un xuu_caddr; /* their bound address */ + char xu_dummy2[256]; + } xu_cau; +#define xu_caddr xu_cau.xuu_caddr + struct xsocket xu_socket; + u_quad_t xu_alignment_hack; +}; + +struct xunpgen { + size_t xug_len; + u_int xug_count; + unp_gen_t xug_gen; + so_gen_t xug_sogen; +}; +#endif /* _SYS_SOCKETVAR_H_ */ + +#endif /* _SYS_UNPCB_H_ */ diff --git a/src/include/sys/user.h b/src/include/sys/user.h new file mode 100644 index 0000000..289815a --- /dev/null +++ b/src/include/sys/user.h @@ -0,0 +1,180 @@ +/* + * Copyright (c) 1982, 1986, 1989, 1991, 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. + * 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. + * + * @(#)user.h 8.2 (Berkeley) 9/23/93 + * $FreeBSD: src/sys/sys/user.h,v 1.56 2004/05/07 15:37:56 cognet Exp $ + */ + +#ifndef _SYS_USER_H_ +#define _SYS_USER_H_ + +#include +#ifndef _KERNEL +/* stuff that *used* to be included by user.h, or is now needed */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* XXX */ +#include /* XXX */ +#include /* XXX */ +#include /* XXX */ +#endif /* !_KERNEL */ +#ifndef _SYS_RESOURCEVAR_H_ +#include +#endif +#ifndef _SYS_SIGNALVAR_H_ +#include +#endif + +/* + * KERN_PROC subtype ops return arrays of selected proc structure entries: + * + * When adding new fields to this structure, ALWAYS add them at the end + * and decrease the size of the spare field by the amount of space that + * you are adding. Byte aligned data should be added to the ki_sparestring + * space; other entries should be added to the ki_spare space. Always + * verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE when you are + * done. If you change the size of this structure, many programs will stop + * working! Once you have added the new field, you will need to add code + * to initialize it in two places: kern/kern_proc.c in the function + * fill_kinfo_proc and in lib/libkvm/kvm_proc.c in the function kvm_proclist. + */ +#if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) || \ + defined(__amd64__) +#define KINFO_PROC_SIZE 912 /* the correct size for kinfo_proc */ +#endif +#if __i386__ || defined __arm__ +#define KINFO_PROC_SIZE 648 /* the correct size for kinfo_proc */ +#endif +#ifdef __powerpc__ +#define KINFO_PROC_SIZE 656 +#endif +#ifndef KINFO_PROC_SIZE +#error "Unknown architecture" +#endif +#define WMESGLEN 8 /* size of returned wchan message */ +#define LOCKNAMELEN 8 /* size of returned lock name */ +#define OCOMMLEN 16 /* size of returned ki_ocomm name */ +#define COMMLEN 19 /* size of returned ki_comm name */ +#define KI_NGROUPS 16 /* number of groups in ki_groups */ +#define LOGNAMELEN 17 /* size of returned ki_login */ + +struct kinfo_proc { + int ki_structsize; /* size of this structure */ + int ki_layout; /* reserved: layout identifier */ + struct pargs *ki_args; /* address of command arguments */ + struct proc *ki_paddr; /* address of proc */ + struct user *ki_addr; /* kernel virtual addr of u-area */ + struct vnode *ki_tracep; /* pointer to trace file */ + struct vnode *ki_textvp; /* pointer to executable file */ + struct filedesc *ki_fd; /* pointer to open file info */ + struct vmspace *ki_vmspace; /* pointer to kernel vmspace struct */ + void *ki_wchan; /* sleep address */ + pid_t ki_pid; /* Process identifier */ + pid_t ki_ppid; /* parent process id */ + pid_t ki_pgid; /* process group id */ + pid_t ki_tpgid; /* tty process group id */ + pid_t ki_sid; /* Process session ID */ + pid_t ki_tsid; /* Terminal session ID */ + short ki_jobc; /* job control counter */ + udev_t ki_tdev; /* controlling tty dev */ + sigset_t ki_siglist; /* Signals arrived but not delivered */ + sigset_t ki_sigmask; /* Current signal mask */ + sigset_t ki_sigignore; /* Signals being ignored */ + sigset_t ki_sigcatch; /* Signals being caught by user */ + uid_t ki_uid; /* effective user id */ + uid_t ki_ruid; /* Real user id */ + uid_t ki_svuid; /* Saved effective user id */ + gid_t ki_rgid; /* Real group id */ + gid_t ki_svgid; /* Saved effective group id */ + short ki_ngroups; /* number of groups */ + gid_t ki_groups[KI_NGROUPS]; /* groups */ + vm_size_t ki_size; /* virtual size */ + segsz_t ki_rssize; /* current resident set size in pages */ + segsz_t ki_swrss; /* resident set size before last swap */ + segsz_t ki_tsize; /* text size (pages) XXX */ + segsz_t ki_dsize; /* data size (pages) XXX */ + segsz_t ki_ssize; /* stack size (pages) */ + u_short ki_xstat; /* Exit status for wait & stop signal */ + u_short ki_acflag; /* Accounting flags */ + fixpt_t ki_pctcpu; /* %cpu for process during ki_swtime */ + u_int ki_estcpu; /* Time averaged value of ki_cpticks */ + u_int ki_slptime; /* Time since last blocked */ + u_int ki_swtime; /* Time swapped in or out */ + u_int64_t ki_runtime; /* Real time in microsec */ + struct timeval ki_start; /* starting time */ + struct timeval ki_childtime; /* time used by process children */ + long ki_flag; /* P_* flags */ + long ki_kiflag; /* KI_* flags (below) */ + int ki_traceflag; /* Kernel trace points */ + char ki_stat; /* S* process status */ + signed char ki_nice; /* Process "nice" value */ + char ki_lock; /* Process lock (prevent swap) count */ + char ki_rqindex; /* Run queue index */ + u_char ki_oncpu; /* Which cpu we are on */ + u_char ki_lastcpu; /* Last cpu we were on */ + char ki_ocomm[OCOMMLEN+1]; /* command name */ + char ki_wmesg[WMESGLEN+1]; /* wchan message */ + char ki_login[LOGNAMELEN+1]; /* setlogin name */ + char ki_lockname[LOCKNAMELEN+1]; /* lock name */ + char ki_comm[COMMLEN+1]; /* command name */ + char ki_sparestrings[85]; /* spare string space */ + struct rusage ki_rusage; /* process rusage statistics */ + long ki_sflag; /* PS_* flags */ + struct priority ki_pri; /* process priority */ + long ki_tdflags; /* XXXKSE kthread flag */ + struct pcb *ki_pcb; /* kernel virtual addr of pcb */ + void *ki_kstack; /* kernel virtual addr of stack */ + long ki_spare[22]; /* spare constants */ +}; +void fill_kinfo_proc(struct proc *, struct kinfo_proc *); + +/* ki_sessflag values */ +#define KI_CTTY 0x00000001 /* controlling tty vnode active */ +#define KI_SLEADER 0x00000002 /* session leader */ +#define KI_LOCKBLOCK 0x00000004 /* proc blocked on lock ki_lockname */ + +/* + * Per process structure containing data that isn't needed in core + * when the process isn't running (esp. when swapped out). + */ +struct user { + struct pstats u_stats; /* *p_stats */ + /* + * Remaining field for a.out core dumps - not valid at other times! + */ + struct kinfo_proc u_kproc; /* eproc */ +}; + +#endif diff --git a/src/include/sys/utsname.h b/src/include/sys/utsname.h new file mode 100644 index 0000000..50876a5 --- /dev/null +++ b/src/include/sys/utsname.h @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chuck Karish of Mindcraft, Inc. + * + * 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. + * 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. + * + * @(#)utsname.h 8.1 (Berkeley) 1/4/94 + * $FreeBSD: src/sys/sys/utsname.h,v 1.11 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_UTSNAME_H +#define _SYS_UTSNAME_H + +#ifdef _KERNEL +#define SYS_NMLN 32 /* uname(2) for the FreeBSD 1.1 ABI. */ +#endif + +#ifndef SYS_NMLN +#define SYS_NMLN 256 /* User can override. */ +#endif + +struct utsname { + char sysname[SYS_NMLN]; /* Name of this OS. */ + char nodename[SYS_NMLN]; /* Name of this network node. */ + char release[SYS_NMLN]; /* Release level. */ + char version[SYS_NMLN]; /* Version level. */ + char machine[SYS_NMLN]; /* Hardware type. */ +}; + +#include + +#ifndef _KERNEL +__BEGIN_DECLS +int __xuname(int, void *); /* Variable record size. */ +__END_DECLS + +static __inline int +uname(struct utsname *name) +{ + return __xuname(SYS_NMLN, (void *)name); +} +#endif /* _KERNEL */ + +#endif /* !_SYS_UTSNAME_H */ diff --git a/src/include/sys/uuid.h b/src/include/sys/uuid.h new file mode 100644 index 0000000..35a9291 --- /dev/null +++ b/src/include/sys/uuid.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2002 Marcel Moolenaar + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/uuid.h,v 1.3 2003/05/31 16:47:07 phk Exp $ + */ + +#ifndef _SYS_UUID_H_ +#define _SYS_UUID_H_ + +#include + +/* Length of a node address (an IEEE 802 address). */ +#define _UUID_NODE_LEN 6 + +/* + * See also: + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm + * + * A DCE 1.1 compatible source representation of UUIDs. + */ +struct uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; +}; + +#ifdef _KERNEL + +#define UUID_NODE_LEN _UUID_NODE_LEN + +struct sbuf; + +int snprintf_uuid(char *, size_t, struct uuid *); +int printf_uuid(struct uuid *); +int sbuf_printf_uuid(struct sbuf *, struct uuid *); +void be_uuid_dec(void const *buf, struct uuid *uuid); +void be_uuid_enc(void *buf, struct uuid const *uuid); +void le_uuid_dec(void const *buf, struct uuid *uuid); +void le_uuid_enc(void *buf, struct uuid const *uuid); + +#else /* _KERNEL */ + +/* XXX namespace pollution? */ +typedef struct uuid uuid_t; + +__BEGIN_DECLS +int uuidgen(struct uuid *, int); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* _SYS_UUID_H_ */ diff --git a/src/include/sys/vmmeter.h b/src/include/sys/vmmeter.h new file mode 100644 index 0000000..da2e3fd --- /dev/null +++ b/src/include/sys/vmmeter.h @@ -0,0 +1,248 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 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. + * + * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD: src/sys/sys/vmmeter.h,v 1.25 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_VMMETER_H_ +#define _SYS_VMMETER_H_ + +/* + * System wide statistics counters. + */ +struct vmmeter { + /* + * General system activity. + */ + u_int v_swtch; /* context switches */ + u_int v_trap; /* calls to trap */ + u_int v_syscall; /* calls to syscall() */ + u_int v_intr; /* device interrupts */ + u_int v_soft; /* software interrupts */ + /* + * Virtual memory activity. + */ + u_int v_vm_faults; /* number of address memory faults */ + u_int v_cow_faults; /* number of copy-on-writes */ + u_int v_cow_optim; /* number of optimized copy-on-writes */ + u_int v_zfod; /* pages zero filled on demand */ + u_int v_ozfod; /* optimized zero fill pages */ + u_int v_swapin; /* swap pager pageins */ + u_int v_swapout; /* swap pager pageouts */ + u_int v_swappgsin; /* swap pager pages paged in */ + u_int v_swappgsout; /* swap pager pages paged out */ + u_int v_vnodein; /* vnode pager pageins */ + u_int v_vnodeout; /* vnode pager pageouts */ + u_int v_vnodepgsin; /* vnode_pager pages paged in */ + u_int v_vnodepgsout; /* vnode pager pages paged out */ + u_int v_intrans; /* intransit blocking page faults */ + u_int v_reactivated; /* number of pages reactivated from free list */ + u_int v_pdwakeups; /* number of times daemon has awaken from sleep */ + u_int v_pdpages; /* number of pages analyzed by daemon */ + + u_int v_dfree; /* pages freed by daemon */ + u_int v_pfree; /* pages freed by exiting processes */ + u_int v_tfree; /* total pages freed */ + /* + * Distribution of page usages. + */ + u_int v_page_size; /* page size in bytes */ + u_int v_page_count; /* total number of pages in system */ + u_int v_free_reserved; /* number of pages reserved for deadlock */ + u_int v_free_target; /* number of pages desired free */ + u_int v_free_min; /* minimum number of pages desired free */ + u_int v_free_count; /* number of pages free */ + u_int v_wire_count; /* number of pages wired down */ + u_int v_active_count; /* number of pages active */ + u_int v_inactive_target; /* number of pages desired inactive */ + u_int v_inactive_count; /* number of pages inactive */ + u_int v_cache_count; /* number of pages on buffer cache queue */ + u_int v_cache_min; /* min number of pages desired on cache queue */ + u_int v_cache_max; /* max number of pages in cached obj */ + u_int v_pageout_free_min; /* min number pages reserved for kernel */ + u_int v_interrupt_free_min; /* reserved number of pages for int code */ + u_int v_free_severe; /* severe depletion of pages below this pt */ + /* + * Fork/vfork/rfork activity. + */ + u_int v_forks; /* number of fork() calls */ + u_int v_vforks; /* number of vfork() calls */ + u_int v_rforks; /* number of rfork() calls */ + u_int v_kthreads; /* number of fork() calls by kernel */ + u_int v_forkpages; /* number of VM pages affected by fork() */ + u_int v_vforkpages; /* number of VM pages affected by vfork() */ + u_int v_rforkpages; /* number of VM pages affected by rfork() */ + u_int v_kthreadpages; /* number of VM pages affected by fork() by kernel */ +}; +#ifdef _KERNEL + +extern struct vmmeter cnt; + +/* + * Return TRUE if we are under our reserved low-free-pages threshold + */ + +static __inline +int +vm_page_count_reserved(void) +{ + return (cnt.v_free_reserved > (cnt.v_free_count + cnt.v_cache_count)); +} + +/* + * Return TRUE if we are under our severe low-free-pages threshold + * + * This routine is typically used at the user<->system interface to determine + * whether we need to block in order to avoid a low memory deadlock. + */ + +static __inline +int +vm_page_count_severe(void) +{ + return (cnt.v_free_severe > (cnt.v_free_count + cnt.v_cache_count)); +} + +/* + * Return TRUE if we are under our minimum low-free-pages threshold. + * + * This routine is typically used within the system to determine whether + * we can execute potentially very expensive code in terms of memory. It + * is also used by the pageout daemon to calculate when to sleep, when + * to wake waiters up, and when (after making a pass) to become more + * desparate. + */ + +static __inline +int +vm_page_count_min(void) +{ + return (cnt.v_free_min > (cnt.v_free_count + cnt.v_cache_count)); +} + +/* + * Return TRUE if we have not reached our free page target during + * free page recovery operations. + */ + +static __inline +int +vm_page_count_target(void) +{ + return (cnt.v_free_target > (cnt.v_free_count + cnt.v_cache_count)); +} + +/* + * Return the number of pages we need to free-up or cache + * A positive number indicates that we do not have enough free pages. + */ + +static __inline +int +vm_paging_target(void) +{ + return ( + (cnt.v_free_target + cnt.v_cache_min) - + (cnt.v_free_count + cnt.v_cache_count) + ); +} + +/* + * Returns TRUE if the pagedaemon needs to be woken up. + */ + +static __inline +int +vm_paging_needed(void) +{ + return ( + (cnt.v_free_reserved + cnt.v_cache_min) > + (cnt.v_free_count + cnt.v_cache_count) + ); +} + +#endif + +/* systemwide totals computed every five seconds */ +struct vmtotal { + int16_t t_rq; /* length of the run queue */ + int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */ + int16_t t_pw; /* jobs in page wait */ + int16_t t_sl; /* jobs sleeping in core */ + int16_t t_sw; /* swapped out runnable/short block jobs */ + int32_t t_vm; /* total virtual memory */ + int32_t t_avm; /* active virtual memory */ + int32_t t_rm; /* total real memory in use */ + int32_t t_arm; /* active real memory */ + int32_t t_vmshr; /* shared virtual memory */ + int32_t t_avmshr; /* active shared virtual memory */ + int32_t t_rmshr; /* shared real memory */ + int32_t t_armshr; /* active shared real memory */ + int32_t t_free; /* free memory pages */ +}; + +/* + * Optional instrumentation. + */ +#ifdef PGINPROF + +#define NDMON 128 +#define NSMON 128 + +#define DRES 20 +#define SRES 5 + +#define PMONMIN 20 +#define PRES 50 +#define NPMON 64 + +#define RMONMIN 130 +#define RRES 5 +#define NRMON 64 + +/* data and stack size distribution counters */ +u_int dmon[NDMON+1]; +u_int smon[NSMON+1]; + +/* page in time distribution counters */ +u_int pmon[NPMON+2]; + +/* reclaim time distribution counters */ +u_int rmon[NRMON+2]; + +int pmonmin; +int pres; +int rmonmin; +int rres; + +u_int rectime; /* accumulator for reclaim times */ +u_int pgintime; /* accumulator for page in times */ +#endif + +#endif diff --git a/src/include/sys/vnode.h b/src/include/sys/vnode.h new file mode 100644 index 0000000..a353ed3 --- /dev/null +++ b/src/include/sys/vnode.h @@ -0,0 +1,725 @@ +/* + * Copyright (c) 1989, 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. + * 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. + * + * @(#)vnode.h 8.7 (Berkeley) 2/4/94 + * $FreeBSD: src/sys/sys/vnode.h,v 1.236 2004/04/07 04:19:50 imp Exp $ + */ + +#ifndef _SYS_VNODE_H_ +#define _SYS_VNODE_H_ + +/* + * XXX - compatability until lockmgr() goes away or all the #includes are + * updated. + */ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The vnode is the focus of all file activity in UNIX. There is a + * unique vnode allocated for each active file, each current directory, + * each mounted-on file, text file, and the root. + */ + +/* + * Vnode types. VNON means no type. + */ +enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; + +/* + * Each underlying filesystem allocates its own private area and hangs + * it from v_data. If non-null, this area is freed in getnewvnode(). + */ +TAILQ_HEAD(buflists, buf); + +typedef int vop_t(void *); +struct namecache; + +struct vpollinfo { + struct mtx vpi_lock; /* lock to protect below */ + struct selinfo vpi_selinfo; /* identity of poller(s) */ + short vpi_events; /* what they are looking for */ + short vpi_revents; /* what has happened */ +}; + +/* + * Reading or writing any of these items requires holding the appropriate lock. + * + * Lock reference: + * c - namecache mutex + * f - freelist mutex + * i - interlock + * m - mntvnodes mutex + * p - pollinfo lock + * s - spechash mutex + * S - syncer mutex + * u - Only a reference to the vnode is needed to read. + * v - vnode lock + * + * Vnodes may be found on many lists. The general way to deal with operating + * on a vnode that is on a list is: + * 1) Lock the list and find the vnode. + * 2) Lock interlock so that the vnode does not go away. + * 3) Unlock the list to avoid lock order reversals. + * 4) vget with LK_INTERLOCK and check for ENOENT, or + * 5) Check for XLOCK if the vnode lock is not required. + * 6) Perform your operation, then vput(). + * + * XXX Not all fields are locked yet and some fields that are marked are not + * locked consistently. This is a work in progress. Requires Giant! + */ + +struct vnode { + struct mtx v_interlock; /* lock for "i" things */ + u_long v_iflag; /* i vnode flags (see below) */ + int v_usecount; /* i ref count of users */ + long v_numoutput; /* i writes in progress */ + struct thread *v_vxthread; /* i thread owning VXLOCK */ + int v_holdcnt; /* i page & buffer references */ + struct buflists v_cleanblkhd; /* i SORTED clean blocklist */ + struct buf *v_cleanblkroot; /* i clean buf splay tree */ + int v_cleanbufcnt; /* i number of clean buffers */ + struct buflists v_dirtyblkhd; /* i SORTED dirty blocklist */ + struct buf *v_dirtyblkroot; /* i dirty buf splay tree */ + int v_dirtybufcnt; /* i number of dirty buffers */ + u_long v_vflag; /* v vnode flags */ + int v_writecount; /* v ref count of writers */ + struct vm_object *v_object; /* v Place to store VM object */ + daddr_t v_lastw; /* v last write (write cluster) */ + daddr_t v_cstart; /* v start block of cluster */ + daddr_t v_lasta; /* v last allocation (cluster) */ + int v_clen; /* v length of current cluster */ + union { + struct mount *vu_mountedhere;/* v ptr to mounted vfs (VDIR) */ + struct socket *vu_socket; /* v unix ipc (VSOCK) */ + struct { + struct cdev *vu_cdev; /* v device (VCHR, VBLK) */ + SLIST_ENTRY(vnode) vu_specnext; /* s device aliases */ + } vu_spec; + struct fifoinfo *vu_fifoinfo; /* v fifo (VFIFO) */ + } v_un; + TAILQ_ENTRY(vnode) v_freelist; /* f vnode freelist */ + TAILQ_ENTRY(vnode) v_nmntvnodes; /* m vnodes for mount point */ + LIST_ENTRY(vnode) v_synclist; /* S dirty vnode list */ + enum vtype v_type; /* u vnode type */ + const char *v_tag; /* u type of underlying data */ + void *v_data; /* u private data for fs */ + struct lock v_lock; /* u used if fs don't have one */ + struct lock *v_vnlock; /* u pointer to vnode lock */ + vop_t **v_op; /* u vnode operations vector */ + struct mount *v_mount; /* u ptr to vfs we are in */ + LIST_HEAD(, namecache) v_cache_src; /* c Cache entries from us */ + TAILQ_HEAD(, namecache) v_cache_dst; /* c Cache entries to us */ + u_long v_id; /* c capability identifier */ + struct vnode *v_dd; /* c .. vnode */ + u_long v_ddid; /* c .. capability identifier */ + struct vpollinfo *v_pollinfo; /* p Poll events */ + struct label *v_label; /* MAC label for vnode */ +#ifdef DEBUG_LOCKS + const char *filename; /* Source file doing locking */ + int line; /* Line number doing locking */ +#endif + udev_t v_cachedfs; /* cached fs id */ + ino_t v_cachedid; /* cached file id */ +}; +#define v_mountedhere v_un.vu_mountedhere +#define v_socket v_un.vu_socket +#define v_rdev v_un.vu_spec.vu_cdev +#define v_specnext v_un.vu_spec.vu_specnext +#define v_fifoinfo v_un.vu_fifoinfo + +/* + * Userland version of struct vnode, for sysctl. + */ +struct xvnode { + size_t xv_size; /* sizeof(struct xvnode) */ + void *xv_vnode; /* address of real vnode */ + u_long xv_flag; /* vnode vflags */ + int xv_usecount; /* reference count of users */ + int xv_writecount; /* reference count of writers */ + int xv_holdcnt; /* page & buffer references */ + u_long xv_id; /* capability identifier */ + void *xv_mount; /* address of parent mount */ + long xv_numoutput; /* num of writes in progress */ + enum vtype xv_type; /* vnode type */ + union { + void *xvu_socket; /* socket, if VSOCK */ + void *xvu_fifo; /* fifo, if VFIFO */ + udev_t xvu_rdev; /* maj/min, if VBLK/VCHR */ + struct { + udev_t xvu_dev; /* device, if VDIR/VREG/VLNK */ + ino_t xvu_ino; /* id, if VDIR/VREG/VLNK */ + } xv_uns; + } xv_un; +}; +#define xv_socket xv_un.xvu_socket +#define xv_fifo xv_un.xvu_fifo +#define xv_rdev xv_un.xvu_rdev +#define xv_dev xv_un.xv_uns.xvu_dev +#define xv_ino xv_un.xv_uns.xvu_ino + +#define VN_POLLEVENT(vp, events) \ + do { \ + if ((vp)->v_pollinfo != NULL && \ + (vp)->v_pollinfo->vpi_events & (events)) \ + vn_pollevent((vp), (events)); \ + } while (0) + +#define VN_KNOTE(vp, b) \ + do { \ + if ((vp)->v_pollinfo != NULL) \ + KNOTE(&vp->v_pollinfo->vpi_selinfo.si_note, (b)); \ + } while (0) + +/* + * Vnode flags. + * VI flags are protected by interlock and live in v_iflag + * VV flags are protected by the vnode lock and live in v_vflag + */ +#define VI_XLOCK 0x0001 /* vnode is locked to change vtype */ +#define VI_XWANT 0x0002 /* thread is waiting for vnode */ +#define VI_BWAIT 0x0004 /* waiting for output to complete */ +#define VI_OLOCK 0x0008 /* vnode is locked waiting for an object */ +#define VI_OWANT 0x0010 /* a thread is waiting for VOLOCK */ +#define VI_MOUNT 0x0020 /* Mount in progress */ +#define VI_AGE 0x0040 /* Insert vnode at head of free list */ +#define VI_DOOMED 0x0080 /* This vnode is being recycled */ +#define VI_FREE 0x0100 /* This vnode is on the freelist */ +#define VI_OBJDIRTY 0x0400 /* object might be dirty */ +#define VI_DOINGINACT 0x0800 /* VOP_INACTIVE is in progress */ +/* + * XXX VI_ONWORKLST could be replaced with a check for NULL list elements + * in v_synclist. + */ +#define VI_ONWORKLST 0x0200 /* On syncer work-list */ + +#define VV_ROOT 0x0001 /* root of its filesystem */ +#define VV_ISTTY 0x0002 /* vnode represents a tty */ +#define VV_NOSYNC 0x0004 /* unlinked, stop syncing */ +#define VV_OBJBUF 0x0008 /* Allocate buffers in VM object */ +#define VV_CACHEDLABEL 0x0010 /* Vnode has valid cached MAC label */ +#define VV_TEXT 0x0020 /* vnode is a pure text prototype */ +#define VV_COPYONWRITE 0x0040 /* vnode is doing copy-on-write */ +#define VV_SYSTEM 0x0080 /* vnode being used by kernel */ +#define VV_PROCDEP 0x0100 /* vnode is process dependent */ + +/* + * Vnode attributes. A field value of VNOVAL represents a field whose value + * is unavailable (getattr) or which is not to be changed (setattr). + */ +struct vattr { + enum vtype va_type; /* vnode type (for create) */ + u_short va_mode; /* files access mode and type */ + short va_nlink; /* number of references to file */ + uid_t va_uid; /* owner user id */ + gid_t va_gid; /* owner group id */ + udev_t va_fsid; /* filesystem id */ + long va_fileid; /* file id */ + u_quad_t va_size; /* file size in bytes */ + long va_blocksize; /* blocksize preferred for i/o */ + struct timespec va_atime; /* time of last access */ + struct timespec va_mtime; /* time of last modification */ + struct timespec va_ctime; /* time file changed */ + struct timespec va_birthtime; /* time file created */ + u_long va_gen; /* generation number of file */ + u_long va_flags; /* flags defined for file */ + udev_t va_rdev; /* device the special file represents */ + u_quad_t va_bytes; /* bytes of disk space held by file */ + u_quad_t va_filerev; /* file modification number */ + u_int va_vaflags; /* operations flags, see below */ + long va_spare; /* remain quad aligned */ +}; + +/* + * Flags for va_vaflags. + */ +#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ +#define VA_EXCLUSIVE 0x02 /* exclusive create request */ + +/* + * Flags for ioflag. (high 16 bits used to ask for read-ahead and + * help with write clustering) + */ +#define IO_UNIT 0x0001 /* do I/O as atomic unit */ +#define IO_APPEND 0x0002 /* append write to end */ +#define IO_SYNC 0x0004 /* do I/O synchronously */ +#define IO_NODELOCKED 0x0008 /* underlying node already locked */ +#define IO_NDELAY 0x0010 /* FNDELAY flag set in file table */ +#define IO_VMIO 0x0020 /* data already in VMIO space */ +#define IO_INVAL 0x0040 /* invalidate after I/O */ +#define IO_ASYNC 0x0080 /* bawrite rather then bdwrite */ +#define IO_DIRECT 0x0100 /* attempt to bypass buffer cache */ +#define IO_EXT 0x0400 /* operate on external attributes */ +#define IO_NORMAL 0x0800 /* operate on regular data */ +#define IO_NOMACCHECK 0x1000 /* MAC checks unnecessary */ + +#define IO_SEQMAX 0x7F /* seq heuristic max value */ +#define IO_SEQSHIFT 16 /* seq heuristic in upper 16 bits */ + +/* + * Modes. Some values same as Ixxx entries from inode.h for now. + */ +#define VEXEC 000100 /* execute/search permission */ +#define VWRITE 000200 /* write permission */ +#define VREAD 000400 /* read permission */ +#define VSVTX 001000 /* save swapped text even after use */ +#define VSGID 002000 /* set group id on execution */ +#define VSUID 004000 /* set user id on execution */ +#define VADMIN 010000 /* permission to administer */ +#define VSTAT 020000 /* permission to retrieve attrs */ +#define VAPPEND 040000 /* permission to write/append */ +#define VALLPERM (VEXEC | VWRITE | VREAD | VADMIN | VSTAT | VAPPEND) + +/* + * Token indicating no attribute value yet assigned. + */ +#define VNOVAL (-1) + +/* + * LK_TIMELOCK timeout for vnode locks (used mainly by the pageout daemon) + */ +#define VLKTIMEOUT (hz / 20 + 1) + +#ifdef _KERNEL + +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_VNODE); +#endif + +/* + * Convert between vnode types and inode formats (since POSIX.1 + * defines mode word of stat structure in terms of inode formats). + */ +extern enum vtype iftovt_tab[]; +extern int vttoif_tab[]; +#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) +#define VTTOIF(indx) (vttoif_tab[(int)(indx)]) +#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) + +/* + * Flags to various vnode functions. + */ +#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ +#define FORCECLOSE 0x0002 /* vflush: force file closure */ +#define WRITECLOSE 0x0004 /* vflush: only close writable files */ +#define DOCLOSE 0x0008 /* vclean: close active files */ +#define V_SAVE 0x0001 /* vinvalbuf: sync file first */ +#define V_ALT 0x0002 /* vinvalbuf: invalidate only alternate bufs */ +#define V_NORMAL 0x0004 /* vinvalbuf: invalidate only regular bufs */ +#define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */ +#define V_WAIT 0x0001 /* vn_start_write: sleep for suspend */ +#define V_NOWAIT 0x0002 /* vn_start_write: don't sleep for suspend */ +#define V_XSLEEP 0x0004 /* vn_start_write: just return after sleep */ + +#define VREF(vp) vref(vp) + +#ifdef DIAGNOSTIC +#define VATTR_NULL(vap) vattr_null(vap) +#else +#define VATTR_NULL(vap) (*(vap) = va_null) /* initialize a vattr */ +#endif /* DIAGNOSTIC */ + +#define NULLVP ((struct vnode *)NULL) + +#define VNODEOP_SET(f) \ + C_SYSINIT(f##init, SI_SUB_VFS, SI_ORDER_SECOND, vfs_add_vnodeops, &f); \ + C_SYSUNINIT(f##uninit, SI_SUB_VFS, SI_ORDER_SECOND, vfs_rm_vnodeops, &f); + +/* + * Global vnode data. + */ +extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ +extern int async_io_version; /* 0 or POSIX version of AIO i'face */ +extern int desiredvnodes; /* number of vnodes desired */ +extern struct uma_zone *namei_zone; +extern int prtactive; /* nonzero to call vprint() */ +extern struct vattr va_null; /* predefined null vattr structure */ + +/* + * Macro/function to check for client cache inconsistency w.r.t. leasing. + */ +#define LEASE_READ 0x1 /* Check lease for readers */ +#define LEASE_WRITE 0x2 /* Check lease for modifiers */ + +extern void (*lease_updatetime)(int deltat); + +/* Requires interlock. */ +#define VSHOULDFREE(vp) \ + (!((vp)->v_iflag & (VI_FREE|VI_DOOMED|VI_DOINGINACT)) && \ + !(vp)->v_holdcnt && !(vp)->v_usecount && \ + (!(vp)->v_object || \ + !((vp)->v_object->ref_count || (vp)->v_object->resident_page_count))) + +/* Requires interlock. */ +#define VMIGHTFREE(vp) \ + (!((vp)->v_iflag & (VI_FREE|VI_DOOMED|VI_XLOCK|VI_DOINGINACT)) && \ + LIST_EMPTY(&(vp)->v_cache_src) && !(vp)->v_usecount) + +/* Requires interlock. */ +#define VSHOULDBUSY(vp) \ + (((vp)->v_iflag & VI_FREE) && \ + ((vp)->v_holdcnt || (vp)->v_usecount)) + +#define VI_LOCK(vp) mtx_lock(&(vp)->v_interlock) +#define VI_TRYLOCK(vp) mtx_trylock(&(vp)->v_interlock) +#define VI_UNLOCK(vp) mtx_unlock(&(vp)->v_interlock) +#define VI_MTX(vp) (&(vp)->v_interlock) + +#endif /* _KERNEL */ + +/* + * Mods for extensibility. + */ + +/* + * Flags for vdesc_flags: + */ +#define VDESC_MAX_VPS 16 +/* Low order 16 flag bits are reserved for willrele flags for vp arguments. */ +#define VDESC_VP0_WILLRELE 0x0001 +#define VDESC_VP1_WILLRELE 0x0002 +#define VDESC_VP2_WILLRELE 0x0004 +#define VDESC_VP3_WILLRELE 0x0008 +#define VDESC_NOMAP_VPP 0x0100 +#define VDESC_VPP_WILLRELE 0x0200 + +/* + * VDESC_NO_OFFSET is used to identify the end of the offset list + * and in places where no such field exists. + */ +#define VDESC_NO_OFFSET -1 + +/* + * This structure describes the vnode operation taking place. + */ +struct vnodeop_desc { + int vdesc_offset; /* offset in vector,first for speed */ + char *vdesc_name; /* a readable name for debugging */ + int vdesc_flags; /* VDESC_* flags */ + + /* + * These ops are used by bypass routines to map and locate arguments. + * Creds and procs are not needed in bypass routines, but sometimes + * they are useful to (for example) transport layers. + * Nameidata is useful because it has a cred in it. + */ + int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */ + int vdesc_vpp_offset; /* return vpp location */ + int vdesc_cred_offset; /* cred location, if any */ + int vdesc_thread_offset; /* thread location, if any */ + int vdesc_componentname_offset; /* if any */ + /* + * Finally, we've got a list of private data (about each operation) + * for each transport layer. (Support to manage this list is not + * yet part of BSD.) + */ + caddr_t *vdesc_transports; +}; + +#ifdef _KERNEL +/* + * A list of all the operation descs. + */ +extern struct vnodeop_desc *vnodeop_descs[]; + +#define VOPARG_OFFSETOF(s_type, field) __offsetof(s_type, field) +#define VOPARG_OFFSETTO(s_type, s_offset, struct_p) \ + ((s_type)(((char*)(struct_p)) + (s_offset))) + +/* + * This structure is used to configure the new vnodeops vector. + */ +struct vnodeopv_entry_desc { + struct vnodeop_desc *opve_op; /* which operation this is */ + vop_t *opve_impl; /* code implementing this operation */ +}; +struct vnodeopv_desc { + /* ptr to the ptr to the vector where op should go */ + vop_t ***opv_desc_vector_p; + struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */ +}; + +/* + * A generic structure. + * This can be used by bypass routines to identify generic arguments. + */ +struct vop_generic_args { + struct vnodeop_desc *a_desc; + /* other random data follows, presumably */ +}; + +#ifdef DEBUG_VFS_LOCKS +/* + * Support code to aid in debugging VFS locking problems. Not totally + * reliable since if the thread sleeps between changing the lock + * state and checking it with the assert, some other thread could + * change the state. They are good enough for debugging a single + * filesystem using a single-threaded test. + */ +void assert_vi_locked(struct vnode *vp, const char *str); +void assert_vi_unlocked(struct vnode *vp, const char *str); +#if 0 +void assert_vop_elocked(struct vnode *vp, const char *str); +void assert_vop_elocked_other(struct vnode *vp, const char *str); +#endif +void assert_vop_locked(struct vnode *vp, const char *str); +#if 0 +voi0 assert_vop_slocked(struct vnode *vp, const char *str); +#endif +void assert_vop_unlocked(struct vnode *vp, const char *str); + +/* These are called from within the actual VOPS. */ +void vop_lock_pre(void *a); +void vop_lock_post(void *a, int rc); +void vop_lookup_post(void *a, int rc); +void vop_lookup_pre(void *a); +void vop_rename_pre(void *a); +void vop_strategy_pre(void *a); +void vop_unlock_post(void *a, int rc); +void vop_unlock_pre(void *a); + +#define ASSERT_VI_LOCKED(vp, str) assert_vi_locked((vp), (str)) +#define ASSERT_VI_UNLOCKED(vp, str) assert_vi_unlocked((vp), (str)) +#if 0 +#define ASSERT_VOP_ELOCKED(vp, str) assert_vop_elocked((vp), (str)) +#define ASSERT_VOP_ELOCKED_OTHER(vp, str) assert_vop_locked_other((vp), (str)) +#endif +#define ASSERT_VOP_LOCKED(vp, str) assert_vop_locked((vp), (str)) +#if 0 +#define ASSERT_VOP_SLOCKED(vp, str) assert_vop_slocked((vp), (str)) +#endif +#define ASSERT_VOP_UNLOCKED(vp, str) assert_vop_unlocked((vp), (str)) + +#else /* !DEBUG_VFS_LOCKS */ + +#define ASSERT_VI_LOCKED(vp, str) +#define ASSERT_VI_UNLOCKED(vp, str) +#if 0 +#define ASSERT_VOP_ELOCKED(vp, str) +#define ASSERT_VOP_ELOCKED_OTHER(vp, str) +#endif +#define ASSERT_VOP_LOCKED(vp, str) +#if 0 +#define ASSERT_VOP_SLOCKED(vp, str) +#endif +#define ASSERT_VOP_UNLOCKED(vp, str) +#endif /* DEBUG_VFS_LOCKS */ + +/* + * VOCALL calls an op given an ops vector. We break it out because BSD's + * vclean changes the ops vector and then wants to call ops with the old + * vector. + */ +#define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP)) + +/* + * This call works for vnodes in the kernel. + */ +#define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP)) +#define VDESC(OP) (& __CONCAT(OP,_desc)) +#define VOFFSET(OP) (VDESC(OP)->vdesc_offset) + +/* + * VMIO support inline + */ + +extern int vmiodirenable; + +static __inline int +vn_canvmio(struct vnode *vp) +{ + if (vp && (vp->v_type == VREG || (vmiodirenable && vp->v_type == VDIR))) + return(TRUE); + return(FALSE); +} + +/* + * Finally, include the default set of vnode operations. + */ +#include "vnode_if.h" + +/* + * Public vnode manipulation functions. + */ +struct componentname; +struct file; +struct mount; +struct nameidata; +struct ostat; +struct thread; +struct proc; +struct stat; +struct nstat; +struct ucred; +struct uio; +struct vattr; +struct vnode; + +extern int (*lease_check_hook)(struct vop_lease_args *); +extern int (*softdep_fsync_hook)(struct vnode *); +extern int (*softdep_process_worklist_hook)(struct mount *); + +struct vnode *addaliasu(struct vnode *vp, udev_t nvp_rdev); +int bdevvp(dev_t dev, struct vnode **vpp); +/* cache_* may belong in namei.h. */ +void cache_enter(struct vnode *dvp, struct vnode *vp, + struct componentname *cnp); +int cache_lookup(struct vnode *dvp, struct vnode **vpp, + struct componentname *cnp); +void cache_purge(struct vnode *vp); +void cache_purgevfs(struct mount *mp); +int cache_leaf_test(struct vnode *vp); +int change_dir(struct vnode *vp, struct thread *td); +int change_root(struct vnode *vp, struct thread *td); +void cvtstat(struct stat *st, struct ostat *ost); +void cvtnstat(struct stat *sb, struct nstat *nsb); +int getnewvnode(const char *tag, struct mount *mp, vop_t **vops, + struct vnode **vpp); +int lease_check(struct vop_lease_args *ap); +int spec_vnoperate(struct vop_generic_args *); +int speedup_syncer(void); +#define textvp_fullpath(p, rb, rfb) \ + vn_fullpath(FIRST_THREAD_IN_PROC(p), (p)->p_textvp, rb, rfb) +int vn_fullpath(struct thread *td, struct vnode *vn, + char **retbuf, char **freebuf); +int vaccess(enum vtype type, mode_t file_mode, uid_t uid, gid_t gid, + mode_t acc_mode, struct ucred *cred, int *privused); +int vaccess_acl_posix1e(enum vtype type, uid_t file_uid, + gid_t file_gid, struct acl *acl, mode_t acc_mode, + struct ucred *cred, int *privused); +void vattr_null(struct vattr *vap); +int vcount(struct vnode *vp); +void vdrop(struct vnode *); +void vdropl(struct vnode *); +int vfinddev(dev_t dev, struct vnode **vpp); +void vfs_add_vnodeops(const void *); +void vfs_rm_vnodeops(const void *); +int vflush(struct mount *mp, int rootrefs, int flags); +int vget(struct vnode *vp, int lockflag, struct thread *td); +void vgone(struct vnode *vp); +void vgonel(struct vnode *vp, struct thread *td); +void vhold(struct vnode *); +void vholdl(struct vnode *); +int vinvalbuf(struct vnode *vp, int save, struct ucred *cred, + struct thread *td, int slpflag, int slptimeo); +int vtruncbuf(struct vnode *vp, struct ucred *cred, struct thread *td, + off_t length, int blksize); +void vprint(char *label, struct vnode *vp); +int vrecycle(struct vnode *vp, struct mtx *inter_lkp, + struct thread *td); +int vn_close(struct vnode *vp, + int flags, struct ucred *file_cred, struct thread *td); +void vn_finished_write(struct mount *mp); +int vn_isdisk(struct vnode *vp, int *errp); +int vn_lock(struct vnode *vp, int flags, struct thread *td); +#ifdef DEBUG_LOCKS +int debug_vn_lock(struct vnode *vp, int flags, struct thread *p, + const char *filename, int line); +#define vn_lock(vp,flags,p) debug_vn_lock(vp,flags,p,__FILE__,__LINE__) +#endif +int vn_open(struct nameidata *ndp, int *flagp, int cmode, int fdidx); +int vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, + struct ucred *cred, int fdidx); +void vn_pollevent(struct vnode *vp, int events); +void vn_pollgone(struct vnode *vp); +int vn_pollrecord(struct vnode *vp, struct thread *p, int events); +int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, + int len, off_t offset, enum uio_seg segflg, int ioflg, + struct ucred *active_cred, struct ucred *file_cred, int *aresid, + struct thread *td); +int vn_rdwr_inchunks(enum uio_rw rw, struct vnode *vp, caddr_t base, + int len, off_t offset, enum uio_seg segflg, int ioflg, + struct ucred *active_cred, struct ucred *file_cred, int *aresid, + struct thread *td); +int vn_stat(struct vnode *vp, struct stat *sb, struct ucred *active_cred, + struct ucred *file_cred, struct thread *td); +int vn_start_write(struct vnode *vp, struct mount **mpp, int flags); +dev_t vn_todev(struct vnode *vp); +int vn_write_suspend_wait(struct vnode *vp, struct mount *mp, + int flags); +int vn_writechk(struct vnode *vp); +int vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace, + const char *attrname, int *buflen, char *buf, struct thread *td); +int vn_extattr_set(struct vnode *vp, int ioflg, int attrnamespace, + const char *attrname, int buflen, char *buf, struct thread *td); +int vn_extattr_rm(struct vnode *vp, int ioflg, int attrnamespace, + const char *attrname, struct thread *td); +int vfs_cache_lookup(struct vop_lookup_args *ap); +int vfs_object_create(struct vnode *vp, struct thread *td, + struct ucred *cred); +void vfs_timestamp(struct timespec *); +void vfs_write_resume(struct mount *mp); +int vfs_write_suspend(struct mount *mp); +int vop_stdbmap(struct vop_bmap_args *); +int vop_stdfsync(struct vop_fsync_args *); +int vop_stdgetwritemount(struct vop_getwritemount_args *); +int vop_stdgetpages(struct vop_getpages_args *); +int vop_stdinactive(struct vop_inactive_args *); +int vop_stdislocked(struct vop_islocked_args *); +int vop_stdlock(struct vop_lock_args *); +int vop_stdputpages(struct vop_putpages_args *); +int vop_stdunlock(struct vop_unlock_args *); +int vop_nopoll(struct vop_poll_args *); +int vop_stdpathconf(struct vop_pathconf_args *); +int vop_stdpoll(struct vop_poll_args *); +int vop_revoke(struct vop_revoke_args *); +int vop_eopnotsupp(struct vop_generic_args *ap); +int vop_ebadf(struct vop_generic_args *ap); +int vop_einval(struct vop_generic_args *ap); +int vop_enotty(struct vop_generic_args *ap); +int vop_defaultop(struct vop_generic_args *ap); +int vop_null(struct vop_generic_args *ap); +int vop_panic(struct vop_generic_args *ap); +int vop_stdcreatevobject(struct vop_createvobject_args *ap); +int vop_stddestroyvobject(struct vop_destroyvobject_args *ap); +int vop_stdgetvobject(struct vop_getvobject_args *ap); + +void vfree(struct vnode *); +void vput(struct vnode *vp); +void vrele(struct vnode *vp); +void vref(struct vnode *vp); +int vrefcnt(struct vnode *vp); +void vbusy(struct vnode *vp); +void v_addpollinfo(struct vnode *vp); + +extern vop_t **default_vnodeop_p; +extern vop_t **spec_vnodeop_p; +extern vop_t **dead_vnodeop_p; + +#endif /* _KERNEL */ + +#endif /* !_SYS_VNODE_H_ */ diff --git a/src/include/sys/wait.h b/src/include/sys/wait.h new file mode 100644 index 0000000..982a737 --- /dev/null +++ b/src/include/sys/wait.h @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 1982, 1986, 1989, 1993, 1994 + * 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. + * 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. + * + * @(#)wait.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD: src/sys/sys/wait.h,v 1.20 2004/04/09 13:14:32 bde Exp $ + */ + +#ifndef _SYS_WAIT_H_ +#define _SYS_WAIT_H_ + +#include + +/* + * This file holds definitions relevant to the wait4 system call and the + * alternate interfaces that use it (wait, wait3, waitpid). + */ + +/* + * Macros to test the exit status returned by wait and extract the relevant + * values. + */ +#if __BSD_VISIBLE +#define _W_INT(w) (*(int *)&(w)) /* Convert union wait to int. */ +#define WCOREFLAG 0200 +#else +#define _W_INT(i) (i) +#endif + +#define _WSTATUS(x) (_W_INT(x) & 0177) +#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ +#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) +#define WSTOPSIG(x) (_W_INT(x) >> 8) +#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) +#define WTERMSIG(x) (_WSTATUS(x)) +#define WIFEXITED(x) (_WSTATUS(x) == 0) +#define WEXITSTATUS(x) (_W_INT(x) >> 8) +#define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */ +#if __BSD_VISIBLE +#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) + +#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) +#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) +#endif + +/* + * Option bits for the third argument of wait4. WNOHANG causes the + * wait to not hang if there are no stopped or terminated processes, rather + * returning an error indication in this case (pid==0). WUNTRACED + * indicates that the caller should receive status about untraced children + * which stop due to signals. If children are stopped and a wait without + * this option is done, it is as though they were still running... nothing + * about them is returned. + */ +#define WNOHANG 1 /* Don't hang in wait. */ +#define WUNTRACED 2 /* Tell about stopped, untraced children. */ +#define WCONTINUED 4 /* Report a job control continued process. */ + +#if __BSD_VISIBLE +#define WLINUXCLONE 0x80000000 /* Wait for kthread spawned from linux_clone. */ +#endif + +/* + * Tokens for special values of the "pid" parameter to wait4. + */ +#if __BSD_VISIBLE +#define WAIT_ANY (-1) /* any process */ +#define WAIT_MYPGRP 0 /* any process in my process group */ +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +struct rusage; +int kern_wait(struct thread *td, pid_t pid, int *status, int options, + struct rusage *rup); +#else /* !_KERNEL */ +#include + +__BEGIN_DECLS +pid_t wait(int *); +pid_t waitpid(pid_t, int *, int); +#if __BSD_VISIBLE +struct rusage; +pid_t wait3(int *, int, struct rusage *); +pid_t wait4(pid_t, int *, int, struct rusage *); +#endif +__END_DECLS +#endif /* _KERNEL */ + +#endif /* !_SYS_WAIT_H_ */ diff --git a/src/include/sys/watchdog.h b/src/include/sys/watchdog.h new file mode 100644 index 0000000..abfb37b --- /dev/null +++ b/src/include/sys/watchdog.h @@ -0,0 +1,87 @@ +/*- + * Copyright (c) 2003 Poul-Henning Kamp + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/watchdog.h,v 1.3 2004/02/28 20:06:58 phk Exp $ + */ +#ifndef _SYS_WATCHDOG_H +#define _SYS_WATCHDOG_H + +#include + +#ifdef I_HAVE_TOTALLY_LOST_MY_SENSE_OF_HUMOUR +#define _PATH_WATCHDOG "watchdog" +#else +#define _PATH_WATCHDOG "fido" +#endif + +#define WDIOCPATPAT _IOW('W', 42, u_int) + +#define WD_ACTIVE 0x8000000 + /* + * Watchdog reset, timeout set to value in WD_INTERVAL field. + * The kernel will arm the watchdog and unless the userland + * program calls WDIOCPATPAT again before the timer expires + * the system will reinitialize. + */ + +#define WD_PASSIVE 0x0400000 + /* + * Set the watchdog in passive mode. + * The kernel will chose an appropriate timeout duration and + * periodically reset the timer provided everything looks all + * right to the kernel. + */ + +#define WD_INTERVAL 0x00000ff + /* + * Mask for duration bits. + * The watchdog will have a nominal patience of 2^N * nanoseconds. + * Example: N == 30 gives a patience of 2^30 nanoseconds ~= 1 second. + * NB: Expect variance in the +/- 10-20% range. + */ + +/* Handy macros for humans not used to power of two nanoseconds */ +#define WD_TO_NEVER 0 +#define WD_TO_1MS 20 +#define WD_TO_125MS 27 +#define WD_TO_250MS 28 +#define WD_TO_500MS 29 +#define WD_TO_1SEC 30 +#define WD_TO_2SEC 31 +#define WD_TO_4SEC 32 +#define WD_TO_8SEC 33 +#define WD_TO_16SEC 34 +#define WD_TO_32SEC 35 + +#ifdef _KERNEL + +#include + +typedef void (*watchdog_fn)(void *, u_int, int *); + +EVENTHANDLER_DECLARE(watchdog_list, watchdog_fn); +#endif + +#endif /* _SYS_WATCHDOG_H */ diff --git a/src/include/sys/xrpuio.h b/src/include/sys/xrpuio.h new file mode 100644 index 0000000..c0c0e67 --- /dev/null +++ b/src/include/sys/xrpuio.h @@ -0,0 +1,37 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sys/sys/xrpuio.h,v 1.2 1999/08/28 00:52:12 peter Exp $ + * + */ + +#ifndef _SYS_XRPUIO_H_ +#define _SYS_XRPUIO_H_ + +#include + +#define XRPU_MAX_PPS 16 +struct xrpu_timecounting { + + /* The timecounter itself */ + u_int xt_addr_trigger; + u_int xt_addr_latch; + unsigned xt_mask; + u_int32_t xt_frequency; + char xt_name[16]; + + /* The PPS latches */ + struct { + u_int xt_addr_assert; + u_int xt_addr_clear; + } xt_pps[XRPU_MAX_PPS]; +}; + +#define XRPU_IOC_TIMECOUNTING _IOW('6', 1, struct xrpu_timecounting) + +#endif /* _SYS_XRPUIO_H_ */ diff --git a/src/include/sysexits.h b/src/include/sysexits.h new file mode 100644 index 0000000..464cb11 --- /dev/null +++ b/src/include/sysexits.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 1987, 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. + * + * @(#)sysexits.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYSEXITS_H_ +#define _SYSEXITS_H_ + +/* + * SYSEXITS.H -- Exit status codes for system programs. + * + * This include file attempts to categorize possible error + * exit statuses for system programs, notably delivermail + * and the Berkeley network. + * + * Error numbers begin at EX__BASE to reduce the possibility of + * clashing with other exit statuses that random programs may + * already return. The meaning of the codes is approximately + * as follows: + * + * EX_USAGE -- The command was used incorrectly, e.g., with + * the wrong number of arguments, a bad flag, a bad + * syntax in a parameter, or whatever. + * EX_DATAERR -- The input data was incorrect in some way. + * This should only be used for user's data & not + * system files. + * EX_NOINPUT -- An input file (not a system file) did not + * exist or was not readable. This could also include + * errors like "No message" to a mailer (if it cared + * to catch it). + * EX_NOUSER -- The user specified did not exist. This might + * be used for mail addresses or remote logins. + * EX_NOHOST -- The host specified did not exist. This is used + * in mail addresses or network requests. + * EX_UNAVAILABLE -- A service is unavailable. This can occur + * if a support program or file does not exist. This + * can also be used as a catchall message when something + * you wanted to do doesn't work, but you don't know + * why. + * EX_SOFTWARE -- An internal software error has been detected. + * This should be limited to non-operating system related + * errors as possible. + * EX_OSERR -- An operating system error has been detected. + * This is intended to be used for such things as "cannot + * fork", "cannot create pipe", or the like. It includes + * things like getuid returning a user that does not + * exist in the passwd file. + * EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp, + * etc.) does not exist, cannot be opened, or has some + * sort of error (e.g., syntax error). + * EX_CANTCREAT -- A (user specified) output file cannot be + * created. + * EX_IOERR -- An error occurred while doing I/O on some file. + * EX_TEMPFAIL -- temporary failure, indicating something that + * is not really an error. In sendmail, this means + * that a mailer (e.g.) could not create a connection, + * and the request should be reattempted later. + * EX_PROTOCOL -- the remote system returned something that + * was "not possible" during a protocol exchange. + * EX_NOPERM -- You did not have sufficient permission to + * perform the operation. This is not intended for + * file system problems, which should use NOINPUT or + * CANTCREAT, but rather for higher level permissions. + */ + +#define EX_OK 0 /* successful termination */ + +#define EX__BASE 64 /* base value for error messages */ + +#define EX_USAGE 64 /* command line usage error */ +#define EX_DATAERR 65 /* data format error */ +#define EX_NOINPUT 66 /* cannot open input */ +#define EX_NOUSER 67 /* addressee unknown */ +#define EX_NOHOST 68 /* host name unknown */ +#define EX_UNAVAILABLE 69 /* service unavailable */ +#define EX_SOFTWARE 70 /* internal software error */ +#define EX_OSERR 71 /* system error (e.g., can't fork) */ +#define EX_OSFILE 72 /* critical OS file missing */ +#define EX_CANTCREAT 73 /* can't create (user) output file */ +#define EX_IOERR 74 /* input/output error */ +#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ +#define EX_PROTOCOL 76 /* remote error in protocol */ +#define EX_NOPERM 77 /* permission denied */ +#define EX_CONFIG 78 /* configuration error */ + +#define EX__MAX 78 /* maximum listed value */ + +#endif /* !_SYSEXITS_H_ */ diff --git a/src/include/syslog.h b/src/include/syslog.h new file mode 100644 index 0000000..727cf4f --- /dev/null +++ b/src/include/syslog.h @@ -0,0 +1,200 @@ +/* + * Copyright (c) 1982, 1986, 1988, 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. + * 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. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/sys/sys/syslog.h,v 1.24 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_SYSLOG_H_ +#define _SYS_SYSLOG_H_ + +#define _PATH_LOG "/var/run/log" +#define _PATH_OLDLOG "/dev/log" /* backward compatibility */ + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) ((fac) | (pri)) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK LOG_MAKEPRI((LOG_NFACILITIES<<3), 0) +typedef struct _code { + const char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = { + { "alert", LOG_ALERT, }, + { "crit", LOG_CRIT, }, + { "debug", LOG_DEBUG, }, + { "emerg", LOG_EMERG, }, + { "err", LOG_ERR, }, + { "error", LOG_ERR, }, /* DEPRECATED */ + { "info", LOG_INFO, }, + { "none", INTERNAL_NOPRI, }, /* INTERNAL */ + { "notice", LOG_NOTICE, }, + { "panic", LOG_EMERG, }, /* DEPRECATED */ + { "warn", LOG_WARNING, }, /* DEPRECATED */ + { "warning", LOG_WARNING, }, + { NULL, -1, } +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* authorization messages (private) */ + /* Facility #10 clashes in DEC UNIX, where */ + /* it's defined as LOG_MEGASAFE for AdvFS */ + /* event logging. */ +#define LOG_FTP (11<<3) /* ftp daemon */ +#define LOG_NTP (12<<3) /* NTP subsystem */ +#define LOG_SECURITY (13<<3) /* security subsystems (firewalling, etc.) */ +#define LOG_CONSOLE (14<<3) /* /dev/console output */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = { + { "auth", LOG_AUTH, }, + { "authpriv", LOG_AUTHPRIV, }, + { "console", LOG_CONSOLE, }, + { "cron", LOG_CRON, }, + { "daemon", LOG_DAEMON, }, + { "ftp", LOG_FTP, }, + { "kern", LOG_KERN, }, + { "lpr", LOG_LPR, }, + { "mail", LOG_MAIL, }, + { "mark", INTERNAL_MARK, }, /* INTERNAL */ + { "news", LOG_NEWS, }, + { "ntp", LOG_NTP, }, + { "security", LOG_SECURITY, }, + { "syslog", LOG_SYSLOG, }, + { "user", LOG_USER, }, + { "uucp", LOG_UUCP, }, + { "local0", LOG_LOCAL0, }, + { "local1", LOG_LOCAL1, }, + { "local2", LOG_LOCAL2, }, + { "local3", LOG_LOCAL3, }, + { "local4", LOG_LOCAL4, }, + { "local5", LOG_LOCAL5, }, + { "local6", LOG_LOCAL6, }, + { "local7", LOG_LOCAL7, }, + { NULL, -1, } +}; +#endif + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifdef _KERNEL + +#else /* not _KERNEL */ + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two + * places ( and ), so if we include one + * of them here we may collide with the utility's includes. It's unreasonable + * for utilities to have to include one of them to include syslog.h, so we get + * __va_list from and use it. + */ +#include +#include + +__BEGIN_DECLS +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...) __printflike(2, 3); +void vsyslog(int, const char *, __va_list) __printflike(2, 0); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif diff --git a/src/include/taclib.h b/src/include/taclib.h new file mode 100644 index 0000000..53d9c10 --- /dev/null +++ b/src/include/taclib.h @@ -0,0 +1,132 @@ +/*- + * Copyright (c) 1998, 2001, Juniper Networks, Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libtacplus/taclib.h,v 1.2 2002/09/25 23:18:51 pst Exp $ + */ + +#ifndef _TACLIB_H_ +#define _TACLIB_H_ + +#include + +struct tac_handle; + +/* Flags for tac_add_server(). */ +#define TAC_SRVR_SINGLE_CONNECT 0x04 /* Keep connection open for multiple + sessions. */ + +/* Disassembly of tac_send_authen() return value. */ +#define TAC_AUTHEN_STATUS(s) ((s) & 0xff) +#define TAC_AUTHEN_NOECHO(s) ((s) & (1<<8)) + +/* Disassembly of tac_send_author() return value. */ +#define TAC_AUTHOR_STATUS(s) ((s) & 0xff) +#define TAC_AUTHEN_AV_COUNT(s) (((s)>>8) & 0xff) + +/* Privilege levels */ +#define TAC_PRIV_LVL_MIN 0x00 +#define TAC_PRIV_LVL_USER 0x01 +#define TAC_PRIV_LVL_ROOT 0x0f +#define TAC_PRIV_LVL_MAX 0x0f + +/* Authentication actions */ +#define TAC_AUTHEN_LOGIN 0x01 +#define TAC_AUTHEN_CHPASS 0x02 +#define TAC_AUTHEN_SENDPASS 0x03 +#define TAC_AUTHEN_SENDAUTH 0x04 + +/* Authentication types */ +#define TAC_AUTHEN_TYPE_ASCII 0x01 +#define TAC_AUTHEN_TYPE_PAP 0x02 +#define TAC_AUTHEN_TYPE_CHAP 0x03 +#define TAC_AUTHEN_TYPE_ARAP 0x04 +#define TAC_AUTHEN_TYPE_MSCHAP 0x05 + +/* Authentication services */ +#define TAC_AUTHEN_SVC_NONE 0x00 +#define TAC_AUTHEN_SVC_LOGIN 0x01 +#define TAC_AUTHEN_SVC_ENABLE 0x02 +#define TAC_AUTHEN_SVC_PPP 0x03 +#define TAC_AUTHEN_SVC_ARAP 0x04 +#define TAC_AUTHEN_SVC_PT 0x05 +#define TAC_AUTHEN_SVC_RCMD 0x06 +#define TAC_AUTHEN_SVC_X25 0x07 +#define TAC_AUTHEN_SVC_NASI 0x08 +#define TAC_AUTHEN_SVC_FWPROXY 0x09 + +/* Authentication reply status codes */ +#define TAC_AUTHEN_STATUS_PASS 0x01 +#define TAC_AUTHEN_STATUS_FAIL 0x02 +#define TAC_AUTHEN_STATUS_GETDATA 0x03 +#define TAC_AUTHEN_STATUS_GETUSER 0x04 +#define TAC_AUTHEN_STATUS_GETPASS 0x05 +#define TAC_AUTHEN_STATUS_RESTART 0x06 +#define TAC_AUTHEN_STATUS_ERROR 0x07 +#define TAC_AUTHEN_STATUS_FOLLOW 0x21 + +/* Authorization authenticatication methods */ +#define TAC_AUTHEN_METH_NOT_SET 0x00 +#define TAC_AUTHEN_METH_NONE 0x01 +#define TAC_AUTHEN_METH_KRB5 0x02 +#define TAC_AUTHEN_METH_LINE 0x03 +#define TAC_AUTHEN_METH_ENABLE 0x04 +#define TAC_AUTHEN_METH_LOCAL 0x05 +#define TAC_AUTHEN_METH_TACACSPLUS 0x06 +#define TAC_AUTHEN_METH_RCMD 0x20 +/* If adding more, see comments in protocol_version() in taclib.c */ + +/* Authorization status */ +#define TAC_AUTHOR_STATUS_PASS_ADD 0x01 +#define TAC_AUTHOR_STATUS_PASS_REPL 0x02 +#define TAC_AUTHOR_STATUS_FAIL 0x10 +#define TAC_AUTHOR_STATUS_ERROR 0x11 + +__BEGIN_DECLS +int tac_add_server(struct tac_handle *, + const char *, int, const char *, int, int); +void tac_close(struct tac_handle *); +int tac_config(struct tac_handle *, const char *); +int tac_create_authen(struct tac_handle *, int, int, int); +void *tac_get_data(struct tac_handle *, size_t *); +char *tac_get_msg(struct tac_handle *); +struct tac_handle *tac_open(void); +int tac_send_authen(struct tac_handle *); +int tac_set_data(struct tac_handle *, + const void *, size_t); +int tac_set_msg(struct tac_handle *, const char *); +int tac_set_port(struct tac_handle *, const char *); +int tac_set_priv(struct tac_handle *, int); +int tac_set_rem_addr(struct tac_handle *, const char *); +int tac_set_user(struct tac_handle *, const char *); +const char *tac_strerror(struct tac_handle *); +int tac_send_author(struct tac_handle *); +int tac_create_author(struct tac_handle *, int, int, int); +int tac_set_av(struct tac_handle *, u_int, const char *); +char *tac_get_av(struct tac_handle *, u_int); +char *tac_get_av_value(struct tac_handle *, const char *); +void tac_clear_avs(struct tac_handle *); +__END_DECLS + +#endif /* _TACLIB_H_ */ diff --git a/src/include/tar.h b/src/include/tar.h new file mode 100644 index 0000000..764ca01 --- /dev/null +++ b/src/include/tar.h @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chuck Karish of Mindcraft, Inc. + * + * 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. + * + * @(#)tar.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _TAR_H +#define _TAR_H + +#define TMAGIC "ustar" /* ustar and a null */ +#define TMAGLEN 6 +#define TVERSION "00" /* 00 and no null */ +#define TVERSLEN 2 + +/* Values used in typeflag field */ +#define REGTYPE '0' /* Regular file */ +#define AREGTYPE '\0' /* Regular file */ +#define LNKTYPE '1' /* Link */ +#define SYMTYPE '2' /* Reserved */ +#define CHRTYPE '3' /* Character special */ +#define BLKTYPE '4' /* Block special */ +#define DIRTYPE '5' /* Directory */ +#define FIFOTYPE '6' /* FIFO special */ +#define CONTTYPE '7' /* Reserved */ + +/* Bits used in the mode field - values in octal */ +#define TSUID 04000 /* Set UID on execution */ +#define TSGID 02000 /* Set GID on execution */ +#define TSVTX 01000 /* Reserved */ + /* File permissions */ +#define TUREAD 00400 /* Read by owner */ +#define TUWRITE 00200 /* Write by owner */ +#define TUEXEC 00100 /* Execute/Search by owner */ +#define TGREAD 00040 /* Read by group */ +#define TGWRITE 00020 /* Write by group */ +#define TGEXEC 00010 /* Execute/Search by group */ +#define TOREAD 00004 /* Read by other */ +#define TOWRITE 00002 /* Write by other */ +#define TOEXEC 00001 /* Execute/Search by other */ + +#endif diff --git a/src/include/tcpd.h b/src/include/tcpd.h new file mode 100644 index 0000000..07ef87e --- /dev/null +++ b/src/include/tcpd.h @@ -0,0 +1,225 @@ + /* + * @(#) tcpd.h 1.5 96/03/19 16:22:24 + * + * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. + * + * $FreeBSD: src/contrib/tcp_wrappers/tcpd.h,v 1.2 2000/02/03 10:26:59 shin Exp $ + */ + +/* Structure to describe one communications endpoint. */ + +#define STRING_LENGTH 128 /* hosts, users, processes */ + +struct host_info { + char name[STRING_LENGTH]; /* access via eval_hostname(host) */ + char addr[STRING_LENGTH]; /* access via eval_hostaddr(host) */ +#ifdef INET6 + struct sockaddr *sin; /* socket address or 0 */ +#else + struct sockaddr_in *sin; /* socket address or 0 */ +#endif + struct t_unitdata *unit; /* TLI transport address or 0 */ + struct request_info *request; /* for shared information */ +}; + +/* Structure to describe what we know about a service request. */ + +struct request_info { + int fd; /* socket handle */ + char user[STRING_LENGTH]; /* access via eval_user(request) */ + char daemon[STRING_LENGTH]; /* access via eval_daemon(request) */ + char pid[10]; /* access via eval_pid(request) */ + struct host_info client[1]; /* client endpoint info */ + struct host_info server[1]; /* server endpoint info */ + void (*sink) (); /* datagram sink function or 0 */ + void (*hostname) (); /* address to printable hostname */ + void (*hostaddr) (); /* address to printable address */ + void (*cleanup) (); /* cleanup function or 0 */ + struct netconfig *config; /* netdir handle */ +}; + +/* Common string operations. Less clutter should be more readable. */ + +#define STRN_CPY(d,s,l) { strncpy((d),(s),(l)); (d)[(l)-1] = 0; } + +#define STRN_EQ(x,y,l) (strncasecmp((x),(y),(l)) == 0) +#define STRN_NE(x,y,l) (strncasecmp((x),(y),(l)) != 0) +#define STR_EQ(x,y) (strcasecmp((x),(y)) == 0) +#define STR_NE(x,y) (strcasecmp((x),(y)) != 0) + + /* + * Initially, all above strings have the empty value. Information that + * cannot be determined at runtime is set to "unknown", so that we can + * distinguish between `unavailable' and `not yet looked up'. A hostname + * that we do not believe in is set to "paranoid". + */ + +#define STRING_UNKNOWN "unknown" /* lookup failed */ +#define STRING_PARANOID "paranoid" /* hostname conflict */ + +extern char unknown[]; +extern char paranoid[]; + +#define HOSTNAME_KNOWN(s) (STR_NE((s),unknown) && STR_NE((s),paranoid)) + +#define NOT_INADDR(s) (s[strspn(s,"01234567890./")] != 0) + +/* Global functions. */ + +#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) +extern void fromhost(); /* get/validate client host info */ +#else +#define fromhost sock_host /* no TLI support needed */ +#endif + +extern int hosts_access(); /* access control */ +extern void shell_cmd(); /* execute shell command */ +extern char *percent_x(); /* do % expansion */ +extern void rfc931(); /* client name from RFC 931 daemon */ +extern void clean_exit(); /* clean up and exit */ +extern void refuse(); /* clean up and exit */ +extern char *xgets(); /* fgets() on steroids */ +extern char *split_at(); /* strchr() and split */ +extern unsigned long dot_quad_addr(); /* restricted inet_addr() */ + +/* Global variables. */ + +extern int allow_severity; /* for connection logging */ +extern int deny_severity; /* for connection logging */ +extern char *hosts_allow_table; /* for verification mode redirection */ +extern char *hosts_deny_table; /* for verification mode redirection */ +extern int hosts_access_verbose; /* for verbose matching mode */ +extern int rfc931_timeout; /* user lookup timeout */ +extern int resident; /* > 0 if resident process */ + + /* + * Routines for controlled initialization and update of request structure + * attributes. Each attribute has its own key. + */ + +#ifdef __STDC__ +extern struct request_info *request_init(struct request_info *,...); +extern struct request_info *request_set(struct request_info *,...); +#else +extern struct request_info *request_init(); /* initialize request */ +extern struct request_info *request_set(); /* update request structure */ +#endif + +#define RQ_FILE 1 /* file descriptor */ +#define RQ_DAEMON 2 /* server process (argv[0]) */ +#define RQ_USER 3 /* client user name */ +#define RQ_CLIENT_NAME 4 /* client host name */ +#define RQ_CLIENT_ADDR 5 /* client host address */ +#define RQ_CLIENT_SIN 6 /* client endpoint (internal) */ +#define RQ_SERVER_NAME 7 /* server host name */ +#define RQ_SERVER_ADDR 8 /* server host address */ +#define RQ_SERVER_SIN 9 /* server endpoint (internal) */ + + /* + * Routines for delayed evaluation of request attributes. Each attribute + * type has its own access method. The trivial ones are implemented by + * macros. The other ones are wrappers around the transport-specific host + * name, address, and client user lookup methods. The request_info and + * host_info structures serve as caches for the lookup results. + */ + +extern char *eval_user(); /* client user */ +extern char *eval_hostname(); /* printable hostname */ +extern char *eval_hostaddr(); /* printable host address */ +extern char *eval_hostinfo(); /* host name or address */ +extern char *eval_client(); /* whatever is available */ +extern char *eval_server(); /* whatever is available */ +#define eval_daemon(r) ((r)->daemon) /* daemon process name */ +#define eval_pid(r) ((r)->pid) /* process id */ + +/* Socket-specific methods, including DNS hostname lookups. */ + +extern void sock_host(); /* look up endpoint addresses */ +extern void sock_hostname(); /* translate address to hostname */ +extern void sock_hostaddr(); /* address to printable address */ +#define sock_methods(r) \ + { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; } + +/* The System V Transport-Level Interface (TLI) interface. */ + +#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) +extern void tli_host(); /* look up endpoint addresses etc. */ +#endif + + /* + * Problem reporting interface. Additional file/line context is reported + * when available. The jump buffer (tcpd_buf) is not declared here, or + * everyone would have to include . + */ + +#ifdef __STDC__ +extern void tcpd_warn(char *, ...); /* report problem and proceed */ +extern void tcpd_jump(char *, ...); /* report problem and jump */ +#else +extern void tcpd_warn(); +extern void tcpd_jump(); +#endif + +struct tcpd_context { + char *file; /* current file */ + int line; /* current line */ +}; +extern struct tcpd_context tcpd_context; + + /* + * While processing access control rules, error conditions are handled by + * jumping back into the hosts_access() routine. This is cleaner than + * checking the return value of each and every silly little function. The + * (-1) returns are here because zero is already taken by longjmp(). + */ + +#define AC_PERMIT 1 /* permit access */ +#define AC_DENY (-1) /* deny_access */ +#define AC_ERROR AC_DENY /* XXX */ + + /* + * In verification mode an option function should just say what it would do, + * instead of really doing it. An option function that would not return + * should clear the dry_run flag to inform the caller of this unusual + * behavior. + */ + +extern void process_options(); /* execute options */ +extern int dry_run; /* verification flag */ + +/* Bug workarounds. */ + +#ifdef INET_ADDR_BUG /* inet_addr() returns struct */ +#define inet_addr fix_inet_addr +extern long fix_inet_addr(); +#endif + +#ifdef BROKEN_FGETS /* partial reads from sockets */ +#define fgets fix_fgets +extern char *fix_fgets(); +#endif + +#ifdef RECVFROM_BUG /* no address family info */ +#define recvfrom fix_recvfrom +extern int fix_recvfrom(); +#endif + +#ifdef GETPEERNAME_BUG /* claims success with UDP */ +#define getpeername fix_getpeername +extern int fix_getpeername(); +#endif + +#ifdef SOLARIS_24_GETHOSTBYNAME_BUG /* lists addresses as aliases */ +#define gethostbyname fix_gethostbyname +extern struct hostent *fix_gethostbyname(); +#endif + +#ifdef USE_STRSEP /* libc calls strtok() */ +#define strtok fix_strtok +extern char *fix_strtok(); +#endif + +#ifdef LIBC_CALLS_STRTOK /* libc calls strtok() */ +#define strtok my_strtok +extern char *my_strtok(); +#endif diff --git a/src/include/term.h b/src/include/term.h new file mode 100644 index 0000000..0261d50 --- /dev/null +++ b/src/include/term.h @@ -0,0 +1,782 @@ +/**************************************************************************** + * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/****************************************************************************/ +/* Author: Zeyd M. Ben-Halim 1992,1995 */ +/* and: Eric S. Raymond */ +/****************************************************************************/ + +/* $Id$ */ + +/* +** term.h -- Definition of struct term +*/ + +#ifndef NCURSES_TERM_H_incl +#define NCURSES_TERM_H_incl 1 + +#undef NCURSES_VERSION +#define NCURSES_VERSION "5.2" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Make this file self-contained by providing defaults for the HAVE_TERMIO[S]_H + * definition (based on the system for which this was configured). + */ + +#undef HAVE_TERMIOS_H +#define HAVE_TERMIOS_H 1 + +#undef HAVE_TCGETATTR +#define HAVE_TCGETATTR 1 + +#undef NCURSES_CONST +#define NCURSES_CONST const + +#undef NCURSES_XNAMES +#define NCURSES_XNAMES 1 + +/* We will use these symbols to hide differences between + * termios/termio/sgttyb interfaces. + */ +#undef TTY +#undef SET_TTY +#undef GET_TTY + +/* Assume POSIX termio if we have the header and function */ +#if HAVE_TERMIOS_H && HAVE_TCGETATTR + +#undef TERMIOS +#define TERMIOS 1 + +#include +#define TTY struct termios + +#else /* !HAVE_TERMIOS_H */ + +#if 0 /* HAVE_TERMIO_H */ + +#undef TERMIOS +#define TERMIOS 1 + +#include +#define TTY struct termio + +/* Add definitions to make termio look like termios. + * But ifdef it, since there are some implementations + * that try to do this for us in a fake . + */ +#ifndef TCSANOW +#define TCSANOW TCSETA +#endif +#ifndef TCSADRAIN +#define TCSADRAIN TCSETAW +#endif +#ifndef TCSAFLUSH +#define TCSAFLUSH TCSETAF +#endif +#ifndef tcsetattr +#define tcsetattr(fd, cmd, arg) ioctl(fd, cmd, arg) +#endif +#ifndef tcgetattr +#define tcgetattr(fd, arg) ioctl(fd, TCGETA, arg) +#endif +#ifndef cfgetospeed +#define cfgetospeed(t) ((t)->c_cflag & CBAUD) +#endif +#ifndef TCIFLUSH +#define TCIFLUSH 0 +#endif +#ifndef TCOFLUSH +#define TCOFLUSH 1 +#endif +#ifndef TCIOFLUSH +#define TCIOFLUSH 2 +#endif +#ifndef tcflush +#define tcflush(fd, arg) ioctl(fd, TCFLSH, arg) +#endif + +#else /* !HAVE_TERMIO_H */ + +#undef TERMIOS +#include +#include +#define TTY struct sgttyb + +#endif /* HAVE_TERMIO_H */ + +#endif /* HAVE_TERMIOS_H */ + +#ifdef TERMIOS +#define GET_TTY(fd, buf) tcgetattr(fd, buf) +#define SET_TTY(fd, buf) tcsetattr(fd, TCSADRAIN, buf) +#else +#define GET_TTY(fd, buf) gtty(fd, buf) +#define SET_TTY(fd, buf) stty(fd, buf) +#endif + +#define NAMESIZE 256 + +#define CUR cur_term->type. + +#define auto_left_margin CUR Booleans[0] +#define auto_right_margin CUR Booleans[1] +#define no_esc_ctlc CUR Booleans[2] +#define ceol_standout_glitch CUR Booleans[3] +#define eat_newline_glitch CUR Booleans[4] +#define erase_overstrike CUR Booleans[5] +#define generic_type CUR Booleans[6] +#define hard_copy CUR Booleans[7] +#define has_meta_key CUR Booleans[8] +#define has_status_line CUR Booleans[9] +#define insert_null_glitch CUR Booleans[10] +#define memory_above CUR Booleans[11] +#define memory_below CUR Booleans[12] +#define move_insert_mode CUR Booleans[13] +#define move_standout_mode CUR Booleans[14] +#define over_strike CUR Booleans[15] +#define status_line_esc_ok CUR Booleans[16] +#define dest_tabs_magic_smso CUR Booleans[17] +#define tilde_glitch CUR Booleans[18] +#define transparent_underline CUR Booleans[19] +#define xon_xoff CUR Booleans[20] +#define needs_xon_xoff CUR Booleans[21] +#define prtr_silent CUR Booleans[22] +#define hard_cursor CUR Booleans[23] +#define non_rev_rmcup CUR Booleans[24] +#define no_pad_char CUR Booleans[25] +#define non_dest_scroll_region CUR Booleans[26] +#define can_change CUR Booleans[27] +#define back_color_erase CUR Booleans[28] +#define hue_lightness_saturation CUR Booleans[29] +#define col_addr_glitch CUR Booleans[30] +#define cr_cancels_micro_mode CUR Booleans[31] +#define has_print_wheel CUR Booleans[32] +#define row_addr_glitch CUR Booleans[33] +#define semi_auto_right_margin CUR Booleans[34] +#define cpi_changes_res CUR Booleans[35] +#define lpi_changes_res CUR Booleans[36] +#define columns CUR Numbers[0] +#define init_tabs CUR Numbers[1] +#define lines CUR Numbers[2] +#define lines_of_memory CUR Numbers[3] +#define magic_cookie_glitch CUR Numbers[4] +#define padding_baud_rate CUR Numbers[5] +#define virtual_terminal CUR Numbers[6] +#define width_status_line CUR Numbers[7] +#define num_labels CUR Numbers[8] +#define label_height CUR Numbers[9] +#define label_width CUR Numbers[10] +#define max_attributes CUR Numbers[11] +#define maximum_windows CUR Numbers[12] +#define max_colors CUR Numbers[13] +#define max_pairs CUR Numbers[14] +#define no_color_video CUR Numbers[15] +#define buffer_capacity CUR Numbers[16] +#define dot_vert_spacing CUR Numbers[17] +#define dot_horz_spacing CUR Numbers[18] +#define max_micro_address CUR Numbers[19] +#define max_micro_jump CUR Numbers[20] +#define micro_col_size CUR Numbers[21] +#define micro_line_size CUR Numbers[22] +#define number_of_pins CUR Numbers[23] +#define output_res_char CUR Numbers[24] +#define output_res_line CUR Numbers[25] +#define output_res_horz_inch CUR Numbers[26] +#define output_res_vert_inch CUR Numbers[27] +#define print_rate CUR Numbers[28] +#define wide_char_size CUR Numbers[29] +#define buttons CUR Numbers[30] +#define bit_image_entwining CUR Numbers[31] +#define bit_image_type CUR Numbers[32] +#define back_tab CUR Strings[0] +#define bell CUR Strings[1] +#define carriage_return CUR Strings[2] +#define change_scroll_region CUR Strings[3] +#define clear_all_tabs CUR Strings[4] +#define clear_screen CUR Strings[5] +#define clr_eol CUR Strings[6] +#define clr_eos CUR Strings[7] +#define column_address CUR Strings[8] +#define command_character CUR Strings[9] +#define cursor_address CUR Strings[10] +#define cursor_down CUR Strings[11] +#define cursor_home CUR Strings[12] +#define cursor_invisible CUR Strings[13] +#define cursor_left CUR Strings[14] +#define cursor_mem_address CUR Strings[15] +#define cursor_normal CUR Strings[16] +#define cursor_right CUR Strings[17] +#define cursor_to_ll CUR Strings[18] +#define cursor_up CUR Strings[19] +#define cursor_visible CUR Strings[20] +#define delete_character CUR Strings[21] +#define delete_line CUR Strings[22] +#define dis_status_line CUR Strings[23] +#define down_half_line CUR Strings[24] +#define enter_alt_charset_mode CUR Strings[25] +#define enter_blink_mode CUR Strings[26] +#define enter_bold_mode CUR Strings[27] +#define enter_ca_mode CUR Strings[28] +#define enter_delete_mode CUR Strings[29] +#define enter_dim_mode CUR Strings[30] +#define enter_insert_mode CUR Strings[31] +#define enter_secure_mode CUR Strings[32] +#define enter_protected_mode CUR Strings[33] +#define enter_reverse_mode CUR Strings[34] +#define enter_standout_mode CUR Strings[35] +#define enter_underline_mode CUR Strings[36] +#define erase_chars CUR Strings[37] +#define exit_alt_charset_mode CUR Strings[38] +#define exit_attribute_mode CUR Strings[39] +#define exit_ca_mode CUR Strings[40] +#define exit_delete_mode CUR Strings[41] +#define exit_insert_mode CUR Strings[42] +#define exit_standout_mode CUR Strings[43] +#define exit_underline_mode CUR Strings[44] +#define flash_screen CUR Strings[45] +#define form_feed CUR Strings[46] +#define from_status_line CUR Strings[47] +#define init_1string CUR Strings[48] +#define init_2string CUR Strings[49] +#define init_3string CUR Strings[50] +#define init_file CUR Strings[51] +#define insert_character CUR Strings[52] +#define insert_line CUR Strings[53] +#define insert_padding CUR Strings[54] +#define key_backspace CUR Strings[55] +#define key_catab CUR Strings[56] +#define key_clear CUR Strings[57] +#define key_ctab CUR Strings[58] +#define key_dc CUR Strings[59] +#define key_dl CUR Strings[60] +#define key_down CUR Strings[61] +#define key_eic CUR Strings[62] +#define key_eol CUR Strings[63] +#define key_eos CUR Strings[64] +#define key_f0 CUR Strings[65] +#define key_f1 CUR Strings[66] +#define key_f10 CUR Strings[67] +#define key_f2 CUR Strings[68] +#define key_f3 CUR Strings[69] +#define key_f4 CUR Strings[70] +#define key_f5 CUR Strings[71] +#define key_f6 CUR Strings[72] +#define key_f7 CUR Strings[73] +#define key_f8 CUR Strings[74] +#define key_f9 CUR Strings[75] +#define key_home CUR Strings[76] +#define key_ic CUR Strings[77] +#define key_il CUR Strings[78] +#define key_left CUR Strings[79] +#define key_ll CUR Strings[80] +#define key_npage CUR Strings[81] +#define key_ppage CUR Strings[82] +#define key_right CUR Strings[83] +#define key_sf CUR Strings[84] +#define key_sr CUR Strings[85] +#define key_stab CUR Strings[86] +#define key_up CUR Strings[87] +#define keypad_local CUR Strings[88] +#define keypad_xmit CUR Strings[89] +#define lab_f0 CUR Strings[90] +#define lab_f1 CUR Strings[91] +#define lab_f10 CUR Strings[92] +#define lab_f2 CUR Strings[93] +#define lab_f3 CUR Strings[94] +#define lab_f4 CUR Strings[95] +#define lab_f5 CUR Strings[96] +#define lab_f6 CUR Strings[97] +#define lab_f7 CUR Strings[98] +#define lab_f8 CUR Strings[99] +#define lab_f9 CUR Strings[100] +#define meta_off CUR Strings[101] +#define meta_on CUR Strings[102] +#define newline CUR Strings[103] +#define pad_char CUR Strings[104] +#define parm_dch CUR Strings[105] +#define parm_delete_line CUR Strings[106] +#define parm_down_cursor CUR Strings[107] +#define parm_ich CUR Strings[108] +#define parm_index CUR Strings[109] +#define parm_insert_line CUR Strings[110] +#define parm_left_cursor CUR Strings[111] +#define parm_right_cursor CUR Strings[112] +#define parm_rindex CUR Strings[113] +#define parm_up_cursor CUR Strings[114] +#define pkey_key CUR Strings[115] +#define pkey_local CUR Strings[116] +#define pkey_xmit CUR Strings[117] +#define print_screen CUR Strings[118] +#define prtr_off CUR Strings[119] +#define prtr_on CUR Strings[120] +#define repeat_char CUR Strings[121] +#define reset_1string CUR Strings[122] +#define reset_2string CUR Strings[123] +#define reset_3string CUR Strings[124] +#define reset_file CUR Strings[125] +#define restore_cursor CUR Strings[126] +#define row_address CUR Strings[127] +#define save_cursor CUR Strings[128] +#define scroll_forward CUR Strings[129] +#define scroll_reverse CUR Strings[130] +#define set_attributes CUR Strings[131] +#define set_tab CUR Strings[132] +#define set_window CUR Strings[133] +#define tab CUR Strings[134] +#define to_status_line CUR Strings[135] +#define underline_char CUR Strings[136] +#define up_half_line CUR Strings[137] +#define init_prog CUR Strings[138] +#define key_a1 CUR Strings[139] +#define key_a3 CUR Strings[140] +#define key_b2 CUR Strings[141] +#define key_c1 CUR Strings[142] +#define key_c3 CUR Strings[143] +#define prtr_non CUR Strings[144] +#define char_padding CUR Strings[145] +#define acs_chars CUR Strings[146] +#define plab_norm CUR Strings[147] +#define key_btab CUR Strings[148] +#define enter_xon_mode CUR Strings[149] +#define exit_xon_mode CUR Strings[150] +#define enter_am_mode CUR Strings[151] +#define exit_am_mode CUR Strings[152] +#define xon_character CUR Strings[153] +#define xoff_character CUR Strings[154] +#define ena_acs CUR Strings[155] +#define label_on CUR Strings[156] +#define label_off CUR Strings[157] +#define key_beg CUR Strings[158] +#define key_cancel CUR Strings[159] +#define key_close CUR Strings[160] +#define key_command CUR Strings[161] +#define key_copy CUR Strings[162] +#define key_create CUR Strings[163] +#define key_end CUR Strings[164] +#define key_enter CUR Strings[165] +#define key_exit CUR Strings[166] +#define key_find CUR Strings[167] +#define key_help CUR Strings[168] +#define key_mark CUR Strings[169] +#define key_message CUR Strings[170] +#define key_move CUR Strings[171] +#define key_next CUR Strings[172] +#define key_open CUR Strings[173] +#define key_options CUR Strings[174] +#define key_previous CUR Strings[175] +#define key_print CUR Strings[176] +#define key_redo CUR Strings[177] +#define key_reference CUR Strings[178] +#define key_refresh CUR Strings[179] +#define key_replace CUR Strings[180] +#define key_restart CUR Strings[181] +#define key_resume CUR Strings[182] +#define key_save CUR Strings[183] +#define key_suspend CUR Strings[184] +#define key_undo CUR Strings[185] +#define key_sbeg CUR Strings[186] +#define key_scancel CUR Strings[187] +#define key_scommand CUR Strings[188] +#define key_scopy CUR Strings[189] +#define key_screate CUR Strings[190] +#define key_sdc CUR Strings[191] +#define key_sdl CUR Strings[192] +#define key_select CUR Strings[193] +#define key_send CUR Strings[194] +#define key_seol CUR Strings[195] +#define key_sexit CUR Strings[196] +#define key_sfind CUR Strings[197] +#define key_shelp CUR Strings[198] +#define key_shome CUR Strings[199] +#define key_sic CUR Strings[200] +#define key_sleft CUR Strings[201] +#define key_smessage CUR Strings[202] +#define key_smove CUR Strings[203] +#define key_snext CUR Strings[204] +#define key_soptions CUR Strings[205] +#define key_sprevious CUR Strings[206] +#define key_sprint CUR Strings[207] +#define key_sredo CUR Strings[208] +#define key_sreplace CUR Strings[209] +#define key_sright CUR Strings[210] +#define key_srsume CUR Strings[211] +#define key_ssave CUR Strings[212] +#define key_ssuspend CUR Strings[213] +#define key_sundo CUR Strings[214] +#define req_for_input CUR Strings[215] +#define key_f11 CUR Strings[216] +#define key_f12 CUR Strings[217] +#define key_f13 CUR Strings[218] +#define key_f14 CUR Strings[219] +#define key_f15 CUR Strings[220] +#define key_f16 CUR Strings[221] +#define key_f17 CUR Strings[222] +#define key_f18 CUR Strings[223] +#define key_f19 CUR Strings[224] +#define key_f20 CUR Strings[225] +#define key_f21 CUR Strings[226] +#define key_f22 CUR Strings[227] +#define key_f23 CUR Strings[228] +#define key_f24 CUR Strings[229] +#define key_f25 CUR Strings[230] +#define key_f26 CUR Strings[231] +#define key_f27 CUR Strings[232] +#define key_f28 CUR Strings[233] +#define key_f29 CUR Strings[234] +#define key_f30 CUR Strings[235] +#define key_f31 CUR Strings[236] +#define key_f32 CUR Strings[237] +#define key_f33 CUR Strings[238] +#define key_f34 CUR Strings[239] +#define key_f35 CUR Strings[240] +#define key_f36 CUR Strings[241] +#define key_f37 CUR Strings[242] +#define key_f38 CUR Strings[243] +#define key_f39 CUR Strings[244] +#define key_f40 CUR Strings[245] +#define key_f41 CUR Strings[246] +#define key_f42 CUR Strings[247] +#define key_f43 CUR Strings[248] +#define key_f44 CUR Strings[249] +#define key_f45 CUR Strings[250] +#define key_f46 CUR Strings[251] +#define key_f47 CUR Strings[252] +#define key_f48 CUR Strings[253] +#define key_f49 CUR Strings[254] +#define key_f50 CUR Strings[255] +#define key_f51 CUR Strings[256] +#define key_f52 CUR Strings[257] +#define key_f53 CUR Strings[258] +#define key_f54 CUR Strings[259] +#define key_f55 CUR Strings[260] +#define key_f56 CUR Strings[261] +#define key_f57 CUR Strings[262] +#define key_f58 CUR Strings[263] +#define key_f59 CUR Strings[264] +#define key_f60 CUR Strings[265] +#define key_f61 CUR Strings[266] +#define key_f62 CUR Strings[267] +#define key_f63 CUR Strings[268] +#define clr_bol CUR Strings[269] +#define clear_margins CUR Strings[270] +#define set_left_margin CUR Strings[271] +#define set_right_margin CUR Strings[272] +#define label_format CUR Strings[273] +#define set_clock CUR Strings[274] +#define display_clock CUR Strings[275] +#define remove_clock CUR Strings[276] +#define create_window CUR Strings[277] +#define goto_window CUR Strings[278] +#define hangup CUR Strings[279] +#define dial_phone CUR Strings[280] +#define quick_dial CUR Strings[281] +#define tone CUR Strings[282] +#define pulse CUR Strings[283] +#define flash_hook CUR Strings[284] +#define fixed_pause CUR Strings[285] +#define wait_tone CUR Strings[286] +#define user0 CUR Strings[287] +#define user1 CUR Strings[288] +#define user2 CUR Strings[289] +#define user3 CUR Strings[290] +#define user4 CUR Strings[291] +#define user5 CUR Strings[292] +#define user6 CUR Strings[293] +#define user7 CUR Strings[294] +#define user8 CUR Strings[295] +#define user9 CUR Strings[296] +#define orig_pair CUR Strings[297] +#define orig_colors CUR Strings[298] +#define initialize_color CUR Strings[299] +#define initialize_pair CUR Strings[300] +#define set_color_pair CUR Strings[301] +#define set_foreground CUR Strings[302] +#define set_background CUR Strings[303] +#define change_char_pitch CUR Strings[304] +#define change_line_pitch CUR Strings[305] +#define change_res_horz CUR Strings[306] +#define change_res_vert CUR Strings[307] +#define define_char CUR Strings[308] +#define enter_doublewide_mode CUR Strings[309] +#define enter_draft_quality CUR Strings[310] +#define enter_italics_mode CUR Strings[311] +#define enter_leftward_mode CUR Strings[312] +#define enter_micro_mode CUR Strings[313] +#define enter_near_letter_quality CUR Strings[314] +#define enter_normal_quality CUR Strings[315] +#define enter_shadow_mode CUR Strings[316] +#define enter_subscript_mode CUR Strings[317] +#define enter_superscript_mode CUR Strings[318] +#define enter_upward_mode CUR Strings[319] +#define exit_doublewide_mode CUR Strings[320] +#define exit_italics_mode CUR Strings[321] +#define exit_leftward_mode CUR Strings[322] +#define exit_micro_mode CUR Strings[323] +#define exit_shadow_mode CUR Strings[324] +#define exit_subscript_mode CUR Strings[325] +#define exit_superscript_mode CUR Strings[326] +#define exit_upward_mode CUR Strings[327] +#define micro_column_address CUR Strings[328] +#define micro_down CUR Strings[329] +#define micro_left CUR Strings[330] +#define micro_right CUR Strings[331] +#define micro_row_address CUR Strings[332] +#define micro_up CUR Strings[333] +#define order_of_pins CUR Strings[334] +#define parm_down_micro CUR Strings[335] +#define parm_left_micro CUR Strings[336] +#define parm_right_micro CUR Strings[337] +#define parm_up_micro CUR Strings[338] +#define select_char_set CUR Strings[339] +#define set_bottom_margin CUR Strings[340] +#define set_bottom_margin_parm CUR Strings[341] +#define set_left_margin_parm CUR Strings[342] +#define set_right_margin_parm CUR Strings[343] +#define set_top_margin CUR Strings[344] +#define set_top_margin_parm CUR Strings[345] +#define start_bit_image CUR Strings[346] +#define start_char_set_def CUR Strings[347] +#define stop_bit_image CUR Strings[348] +#define stop_char_set_def CUR Strings[349] +#define subscript_characters CUR Strings[350] +#define superscript_characters CUR Strings[351] +#define these_cause_cr CUR Strings[352] +#define zero_motion CUR Strings[353] +#define char_set_names CUR Strings[354] +#define key_mouse CUR Strings[355] +#define mouse_info CUR Strings[356] +#define req_mouse_pos CUR Strings[357] +#define get_mouse CUR Strings[358] +#define set_a_foreground CUR Strings[359] +#define set_a_background CUR Strings[360] +#define pkey_plab CUR Strings[361] +#define device_type CUR Strings[362] +#define code_set_init CUR Strings[363] +#define set0_des_seq CUR Strings[364] +#define set1_des_seq CUR Strings[365] +#define set2_des_seq CUR Strings[366] +#define set3_des_seq CUR Strings[367] +#define set_lr_margin CUR Strings[368] +#define set_tb_margin CUR Strings[369] +#define bit_image_repeat CUR Strings[370] +#define bit_image_newline CUR Strings[371] +#define bit_image_carriage_return CUR Strings[372] +#define color_names CUR Strings[373] +#define define_bit_image_region CUR Strings[374] +#define end_bit_image_region CUR Strings[375] +#define set_color_band CUR Strings[376] +#define set_page_length CUR Strings[377] +#define display_pc_char CUR Strings[378] +#define enter_pc_charset_mode CUR Strings[379] +#define exit_pc_charset_mode CUR Strings[380] +#define enter_scancode_mode CUR Strings[381] +#define exit_scancode_mode CUR Strings[382] +#define pc_term_options CUR Strings[383] +#define scancode_escape CUR Strings[384] +#define alt_scancode_esc CUR Strings[385] +#define enter_horizontal_hl_mode CUR Strings[386] +#define enter_left_hl_mode CUR Strings[387] +#define enter_low_hl_mode CUR Strings[388] +#define enter_right_hl_mode CUR Strings[389] +#define enter_top_hl_mode CUR Strings[390] +#define enter_vertical_hl_mode CUR Strings[391] +#define set_a_attributes CUR Strings[392] +#define set_pglen_inch CUR Strings[393] + +#define BOOLWRITE 37 +#define NUMWRITE 33 +#define STRWRITE 394 + +/* older synonyms for some capabilities */ +#define beehive_glitch no_esc_ctlc +#define teleray_glitch dest_tabs_magic_smso +#define micro_char_size micro_col_size + +#ifdef __INTERNAL_CAPS_VISIBLE +#define termcap_init2 CUR Strings[394] +#define termcap_reset CUR Strings[395] +#define magic_cookie_glitch_ul CUR Numbers[33] +#define backspaces_with_bs CUR Booleans[37] +#define crt_no_scrolling CUR Booleans[38] +#define no_correctly_working_cr CUR Booleans[39] +#define carriage_return_delay CUR Numbers[34] +#define new_line_delay CUR Numbers[35] +#define linefeed_if_not_lf CUR Strings[396] +#define backspace_if_not_bs CUR Strings[397] +#define gnu_has_meta_key CUR Booleans[40] +#define linefeed_is_newline CUR Booleans[41] +#define backspace_delay CUR Numbers[36] +#define horizontal_tab_delay CUR Numbers[37] +#define number_of_function_keys CUR Numbers[38] +#define other_non_function_keys CUR Strings[398] +#define arrow_key_map CUR Strings[399] +#define has_hardware_tabs CUR Booleans[42] +#define return_does_clr_eol CUR Booleans[43] +#define acs_ulcorner CUR Strings[400] +#define acs_llcorner CUR Strings[401] +#define acs_urcorner CUR Strings[402] +#define acs_lrcorner CUR Strings[403] +#define acs_ltee CUR Strings[404] +#define acs_rtee CUR Strings[405] +#define acs_btee CUR Strings[406] +#define acs_ttee CUR Strings[407] +#define acs_hline CUR Strings[408] +#define acs_vline CUR Strings[409] +#define acs_plus CUR Strings[410] +#define memory_lock CUR Strings[411] +#define memory_unlock CUR Strings[412] +#define box_chars_1 CUR Strings[413] +#endif /* __INTERNAL_CAPS_VISIBLE */ + + +/* + * Predefined terminfo array sizes + */ +#define BOOLCOUNT 44 +#define NUMCOUNT 39 +#define STRCOUNT 414 + +/* used by code for comparing entries */ +#define acs_chars_index 146 + +typedef struct termtype { /* in-core form of terminfo data */ + char *term_names; /* str_table offset of term names */ + char *str_table; /* pointer to string table */ + char *Booleans; /* array of boolean values */ + short *Numbers; /* array of integer values */ + char **Strings; /* array of string offsets */ + +#if NCURSES_XNAMES + char *ext_str_table; /* pointer to extended string table */ + char **ext_Names; /* corresponding names */ + + unsigned short num_Booleans;/* count total Booleans */ + unsigned short num_Numbers; /* count total Numbers */ + unsigned short num_Strings; /* count total Strings */ + + unsigned short ext_Booleans;/* count extensions to Booleans */ + unsigned short ext_Numbers; /* count extensions to Numbers */ + unsigned short ext_Strings; /* count extensions to Strings */ +#endif /* NCURSES_XNAMES */ + +} TERMTYPE; + +typedef struct term { /* describe an actual terminal */ + TERMTYPE type; /* terminal type description */ + short Filedes; /* file description being written to */ + TTY Ottyb, /* original state of the terminal */ + Nttyb; /* current state of the terminal */ + int _baudrate; /* used to compute padding */ +} TERMINAL; + +extern NCURSES_EXPORT_VAR(TERMINAL *) cur_term; + +#if 0 /* BROKEN_LINKER */ +#define boolnames _nc_boolnames() +#define boolcodes _nc_boolcodes() +#define boolfnames _nc_boolfnames() +#define numnames _nc_numnames() +#define numcodes _nc_numcodes() +#define numfnames _nc_numfnames() +#define strnames _nc_strnames() +#define strcodes _nc_strcodes() +#define strfnames _nc_strfnames() + +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_boolnames (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_boolcodes (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_boolfnames (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_numnames (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_numcodes (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_numfnames (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_strnames (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_strcodes (void); +extern NCURSES_EXPORT(NCURSES_CONST char * const *) _nc_strfnames (void); + +#else + +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolnames[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolcodes[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) boolfnames[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numnames[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numcodes[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) numfnames[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strnames[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strcodes[]; +extern NCURSES_EXPORT_VAR(NCURSES_CONST char * const ) strfnames[]; + +#endif + +/* internals */ +extern NCURSES_EXPORT(int) _nc_set_tty_mode (TTY *buf); +extern NCURSES_EXPORT(int) _nc_get_tty_mode (TTY *buf); +extern NCURSES_EXPORT(int) _nc_read_entry (const char * const, char * const, TERMTYPE *const); +extern NCURSES_EXPORT(int) _nc_read_file_entry (const char *const, TERMTYPE *); +extern NCURSES_EXPORT(char *) _nc_first_name (const char *const); +extern NCURSES_EXPORT(int) _nc_name_match (const char *const, const char *const, const char *const); +extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const); +extern NCURSES_EXPORT(const TERMTYPE *) _nc_fallback (const char *); + +/* entry points */ +extern NCURSES_EXPORT(TERMINAL *) set_curterm (TERMINAL *); +extern NCURSES_EXPORT(int) del_curterm (TERMINAL *); + +/* miscellaneous entry points */ +extern NCURSES_EXPORT(int) restartterm (NCURSES_CONST char *, int, int *); +extern NCURSES_EXPORT(int) setupterm (NCURSES_CONST char *,int,int *); + +/* terminfo entry points, also declared in curses.h */ +#if !defined(__NCURSES_H) +extern NCURSES_EXPORT(char *) tigetstr (NCURSES_CONST char *); +extern NCURSES_EXPORT(char *) tparm (NCURSES_CONST char *, ...); +extern NCURSES_EXPORT_VAR(char) ttytype[]; +extern NCURSES_EXPORT(int) putp (const char *); +extern NCURSES_EXPORT(int) tigetflag (NCURSES_CONST char *); +extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *); +#endif /* __NCURSES_H */ + +/* termcap database emulation (XPG4 uses const only for 2nd param of tgetent) */ +#if !defined(NCURSES_TERMCAP_H_incl) +extern NCURSES_EXPORT(char *) tgetstr (NCURSES_CONST char *, char **); +extern NCURSES_EXPORT(char *) tgoto (const char *, int, int); +extern NCURSES_EXPORT(int) tgetent (char *, const char *); +extern NCURSES_EXPORT(int) tgetflag (NCURSES_CONST char *); +extern NCURSES_EXPORT(int) tgetnum (NCURSES_CONST char *); +extern NCURSES_EXPORT(int) tputs (const char *, int, int (*)(int)); +#endif /* NCURSES_TERMCAP_H_incl */ + +#ifdef __cplusplus +} +#endif + +#endif /* NCURSES_TERM_H_incl */ diff --git a/src/include/termcap.h b/src/include/termcap.h new file mode 100644 index 0000000..bc90c9b --- /dev/null +++ b/src/include/termcap.h @@ -0,0 +1,75 @@ +/**************************************************************************** + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim 1992,1995 * + * and: Eric S. Raymond * + ****************************************************************************/ + +/* $Id$ */ + +#ifndef NCURSES_TERMCAP_H_incl +#define NCURSES_TERMCAP_H_incl 1 + +#undef NCURSES_VERSION +#define NCURSES_VERSION "5.2" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +#include + +#undef NCURSES_CONST +#define NCURSES_CONST const + +#undef NCURSES_OSPEED +#define NCURSES_OSPEED short + +extern NCURSES_EXPORT_VAR(char) PC; +extern NCURSES_EXPORT_VAR(char *) UP; +extern NCURSES_EXPORT_VAR(char *) BC; +extern NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed; + +#if !defined(NCURSES_TERM_H_incl) +extern NCURSES_EXPORT(char *) tgetstr (NCURSES_CONST char *, char **); +extern NCURSES_EXPORT(char *) tgoto (const char *, int, int); +extern NCURSES_EXPORT(int) tgetent (char *, const char *); +extern NCURSES_EXPORT(int) tgetflag (NCURSES_CONST char *); +extern NCURSES_EXPORT(int) tgetnum (NCURSES_CONST char *); +extern NCURSES_EXPORT(int) tputs (const char *, int, int (*)(int)); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* NCURSES_TERMCAP_H_incl */ diff --git a/src/include/termios.h b/src/include/termios.h new file mode 100644 index 0000000..a5621d0 --- /dev/null +++ b/src/include/termios.h @@ -0,0 +1,284 @@ +/* + * Copyright (c) 1988, 1989, 1993, 1994 + * 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. + * 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. + * + * @(#)termios.h 8.3 (Berkeley) 3/28/94 + * $FreeBSD: src/sys/sys/termios.h,v 1.19 2004/04/07 04:19:49 imp Exp $ + */ + +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +/* + * Special Control Characters + * + * Index into c_cc[] character array. + * + * Name Subscript Enabled by + */ +#define VEOF 0 /* ICANON */ +#define VEOL 1 /* ICANON */ +#ifndef _POSIX_SOURCE +#define VEOL2 2 /* ICANON together with IEXTEN */ +#endif +#define VERASE 3 /* ICANON */ +#ifndef _POSIX_SOURCE +#define VWERASE 4 /* ICANON together with IEXTEN */ +#endif +#define VKILL 5 /* ICANON */ +#ifndef _POSIX_SOURCE +#define VREPRINT 6 /* ICANON together with IEXTEN */ +#define VERASE2 7 /* ICANON */ +#endif +/* 7 ex-spare 1 */ +#define VINTR 8 /* ISIG */ +#define VQUIT 9 /* ISIG */ +#define VSUSP 10 /* ISIG */ +#ifndef _POSIX_SOURCE +#define VDSUSP 11 /* ISIG together with IEXTEN */ +#endif +#define VSTART 12 /* IXON, IXOFF */ +#define VSTOP 13 /* IXON, IXOFF */ +#ifndef _POSIX_SOURCE +#define VLNEXT 14 /* IEXTEN */ +#define VDISCARD 15 /* IEXTEN */ +#endif +#define VMIN 16 /* !ICANON */ +#define VTIME 17 /* !ICANON */ +#ifndef _POSIX_SOURCE +#define VSTATUS 18 /* ICANON together with IEXTEN */ +/* 19 spare 2 */ +#endif +#define NCCS 20 + +#define _POSIX_VDISABLE 0xff + +#ifndef _POSIX_SOURCE +#define CCEQ(val, c) ((c) == (val) ? (val) != _POSIX_VDISABLE : 0) +#endif + +/* + * Input flags - software input processing + */ +#define IGNBRK 0x00000001 /* ignore BREAK condition */ +#define BRKINT 0x00000002 /* map BREAK to SIGINTR */ +#define IGNPAR 0x00000004 /* ignore (discard) parity errors */ +#define PARMRK 0x00000008 /* mark parity and framing errors */ +#define INPCK 0x00000010 /* enable checking of parity errors */ +#define ISTRIP 0x00000020 /* strip 8th bit off chars */ +#define INLCR 0x00000040 /* map NL into CR */ +#define IGNCR 0x00000080 /* ignore CR */ +#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */ +#define IXON 0x00000200 /* enable output flow control */ +#define IXOFF 0x00000400 /* enable input flow control */ +#ifndef _POSIX_SOURCE +#define IXANY 0x00000800 /* any char will restart after stop */ +#define IMAXBEL 0x00002000 /* ring bell on input queue full */ +#endif /*_POSIX_SOURCE */ + +/* + * Output flags - software output processing + */ +#define OPOST 0x00000001 /* enable following output processing */ +#ifndef _POSIX_SOURCE +#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */ +#define OXTABS 0x00000004 /* expand tabs to spaces */ +#define ONOEOT 0x00000008 /* discard EOT's (^D) on output) */ +#define OCRNL 0x00000010 /* map CR to NL on output */ +#define ONOCR 0x00000020 /* no CR output at column 0 */ +#define ONLRET 0x00000040 /* NL performs CR function */ +#endif /*_POSIX_SOURCE */ + +/* + * Control flags - hardware control of terminal + */ +#ifndef _POSIX_SOURCE +#define CIGNORE 0x00000001 /* ignore control flags */ +#endif +#define CSIZE 0x00000300 /* character size mask */ +#define CS5 0x00000000 /* 5 bits (pseudo) */ +#define CS6 0x00000100 /* 6 bits */ +#define CS7 0x00000200 /* 7 bits */ +#define CS8 0x00000300 /* 8 bits */ +#define CSTOPB 0x00000400 /* send 2 stop bits */ +#define CREAD 0x00000800 /* enable receiver */ +#define PARENB 0x00001000 /* parity enable */ +#define PARODD 0x00002000 /* odd parity, else even */ +#define HUPCL 0x00004000 /* hang up on last close */ +#define CLOCAL 0x00008000 /* ignore modem status lines */ +#ifndef _POSIX_SOURCE +#define CCTS_OFLOW 0x00010000 /* CTS flow control of output */ +#define CRTSCTS (CCTS_OFLOW | CRTS_IFLOW) +#define CRTS_IFLOW 0x00020000 /* RTS flow control of input */ +#define CDTR_IFLOW 0x00040000 /* DTR flow control of input */ +#define CDSR_OFLOW 0x00080000 /* DSR flow control of output */ +#define CCAR_OFLOW 0x00100000 /* DCD flow control of output */ +#define MDMBUF 0x00100000 /* old name for CCAR_OFLOW */ +#endif + + +/* + * "Local" flags - dumping ground for other state + * + * Warning: some flags in this structure begin with + * the letter "I" and look like they belong in the + * input flag. + */ + +#ifndef _POSIX_SOURCE +#define ECHOKE 0x00000001 /* visual erase for line kill */ +#endif /*_POSIX_SOURCE */ +#define ECHOE 0x00000002 /* visually erase chars */ +#define ECHOK 0x00000004 /* echo NL after line kill */ +#define ECHO 0x00000008 /* enable echoing */ +#define ECHONL 0x00000010 /* echo NL even if ECHO is off */ +#ifndef _POSIX_SOURCE +#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */ +#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */ +#endif /*_POSIX_SOURCE */ +#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */ +#define ICANON 0x00000100 /* canonicalize input lines */ +#ifndef _POSIX_SOURCE +#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */ +#endif /*_POSIX_SOURCE */ +#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */ +#define EXTPROC 0x00000800 /* external processing */ +#define TOSTOP 0x00400000 /* stop background jobs from output */ +#ifndef _POSIX_SOURCE +#define FLUSHO 0x00800000 /* output being flushed (state) */ +#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */ +#define PENDIN 0x20000000 /* XXX retype pending input (state) */ +#endif /*_POSIX_SOURCE */ +#define NOFLSH 0x80000000 /* don't flush after interrupt */ + +typedef unsigned int tcflag_t; +typedef unsigned char cc_t; +typedef unsigned int speed_t; + +struct termios { + tcflag_t c_iflag; /* input flags */ + tcflag_t c_oflag; /* output flags */ + tcflag_t c_cflag; /* control flags */ + tcflag_t c_lflag; /* local flags */ + cc_t c_cc[NCCS]; /* control chars */ + speed_t c_ispeed; /* input speed */ + speed_t c_ospeed; /* output speed */ +}; + +/* + * Commands passed to tcsetattr() for setting the termios structure. + */ +#define TCSANOW 0 /* make change immediate */ +#define TCSADRAIN 1 /* drain output, then change */ +#define TCSAFLUSH 2 /* drain output, flush input */ +#ifndef _POSIX_SOURCE +#define TCSASOFT 0x10 /* flag - don't alter h.w. state */ +#endif + +/* + * Standard speeds + */ +#define B0 0 +#define B50 50 +#define B75 75 +#define B110 110 +#define B134 134 +#define B150 150 +#define B200 200 +#define B300 300 +#define B600 600 +#define B1200 1200 +#define B1800 1800 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#ifndef _POSIX_SOURCE +#define B7200 7200 +#define B14400 14400 +#define B28800 28800 +#define B57600 57600 +#define B76800 76800 +#define B115200 115200 +#define B230400 230400 +#define B460800 460800 +#define B921600 921600 +#define EXTA 19200 +#define EXTB 38400 +#endif /* !_POSIX_SOURCE */ + +#ifndef _KERNEL + +#define TCIFLUSH 1 +#define TCOFLUSH 2 +#define TCIOFLUSH 3 +#define TCOOFF 1 +#define TCOON 2 +#define TCIOFF 3 +#define TCION 4 + +#include + +__BEGIN_DECLS +speed_t cfgetispeed(const struct termios *); +speed_t cfgetospeed(const struct termios *); +int cfsetispeed(struct termios *, speed_t); +int cfsetospeed(struct termios *, speed_t); +int tcgetattr(int, struct termios *); +int tcsetattr(int, int, const struct termios *); +int tcdrain(int); +int tcflow(int, int); +int tcflush(int, int); +int tcsendbreak(int, int); + +#ifndef _POSIX_SOURCE +void cfmakeraw(struct termios *); +int cfsetspeed(struct termios *, speed_t); +#endif /* !_POSIX_SOURCE */ +__END_DECLS + +#endif /* !_KERNEL */ + +#ifndef _POSIX_SOURCE + +/* + * Include tty ioctl's that aren't just for backwards compatibility + * with the old tty driver. These ioctl definitions were previously + * in . + */ +#include +#endif + +/* + * END OF PROTECTED INCLUDE. + */ +#endif /* !_SYS_TERMIOS_H_ */ + +#ifndef _POSIX_SOURCE +#include +#endif diff --git a/src/include/time.h b/src/include/time.h new file mode 100644 index 0000000..2b05e1b --- /dev/null +++ b/src/include/time.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)time.h 8.3 (Berkeley) 1/21/94 + */ + +/* + * $FreeBSD: src/include/time.h,v 1.31 2003/12/07 21:10:06 marcel Exp $ + */ + +#ifndef _TIME_H_ +#define _TIME_H_ + +#include +#include +#include + +#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE +/* + * Frequency of the clock ticks reported by times(). Deprecated - use + * sysconf(_SC_CLK_TCK) instead. (Removed in 1003.1-2001.) + */ +#define CLK_TCK 128 +#endif + +/* Frequency of the clock ticks reported by clock(). */ +#define CLOCKS_PER_SEC 128 + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#if __POSIX_VISIBLE >= 199309 +/* + * New in POSIX 1003.1b-1993. + */ +#ifndef _CLOCKID_T_DECLARED +typedef __clockid_t clockid_t; +#define _CLOCKID_T_DECLARED +#endif + +#ifndef _TIMER_T_DECLARED +typedef __timer_t timer_t; +#define _TIMER_T_DECLARED +#endif + +#include +#endif /* __POSIX_VISIBLE >= 199309 */ + +struct tm { + int tm_sec; /* seconds after the minute [0-60] */ + int tm_min; /* minutes after the hour [0-59] */ + int tm_hour; /* hours since midnight [0-23] */ + int tm_mday; /* day of the month [1-31] */ + int tm_mon; /* months since January [0-11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday [0-6] */ + int tm_yday; /* days since January 1 [0-365] */ + int tm_isdst; /* Daylight Savings Time flag */ + long tm_gmtoff; /* offset from UTC in seconds */ + char *tm_zone; /* timezone abbreviation */ +}; + +#if __POSIX_VISIBLE +extern char *tzname[]; +#endif + +__BEGIN_DECLS +char *asctime(const struct tm *); +clock_t clock(void); +char *ctime(const time_t *); +double difftime(time_t, time_t); +struct tm *gmtime(const time_t *); +struct tm *localtime(const time_t *); +time_t mktime(struct tm *); +size_t strftime(char * __restrict, size_t, const char * __restrict, + const struct tm * __restrict); +time_t time(time_t *); + +#if __POSIX_VISIBLE +void tzset(void); +#endif + +#if __POSIX_VISIBLE >= 199309 +int clock_getres(clockid_t, struct timespec *); +int clock_gettime(clockid_t, struct timespec *); +int clock_settime(clockid_t, const struct timespec *); +int nanosleep(const struct timespec *, struct timespec *); +#endif /* __POSIX_VISIBLE >= 199309 */ + +#if __POSIX_VISIBLE >= 199506 +char *asctime_r(const struct tm *, char *); +char *ctime_r(const time_t *, char *); +struct tm *gmtime_r(const time_t *, struct tm *); +struct tm *localtime_r(const time_t *, struct tm *); +#endif + +#if __XSI_VISIBLE +char *strptime(const char * __restrict, const char * __restrict, + struct tm * __restrict); +#endif + +#if __BSD_VISIBLE +char *timezone(int, int); +void tzsetwall(void); +time_t timelocal(struct tm * const); +time_t timegm(struct tm * const); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_TIME_H_ */ diff --git a/src/include/timeconv.h b/src/include/timeconv.h new file mode 100644 index 0000000..a9345c6 --- /dev/null +++ b/src/include/timeconv.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)time.h 8.3 (Berkeley) 1/21/94 + */ + +/* + * $FreeBSD: src/include/timeconv.h,v 1.2 2002/08/21 16:19:55 mike Exp $ + */ + +#ifndef _TIMECONV_H_ +#define _TIMECONV_H_ + +#include +#include + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +time_t _time32_to_time(__int32_t t32); +__int32_t _time_to_time32(time_t t); +time_t _time64_to_time(__int64_t t64); +__int64_t _time_to_time64(time_t t); +long _time_to_long(time_t t); +time_t _long_to_time(long tlong); +int _time_to_int(time_t t); +time_t _int_to_time(int tint); + +#endif /* _TIMECONV_H_ */ diff --git a/src/include/timers.h b/src/include/timers.h new file mode 100644 index 0000000..9a6eacd --- /dev/null +++ b/src/include/timers.h @@ -0,0 +1,45 @@ +/* ==== timers.h ============================================================ + * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu + * 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * $FreeBSD: src/include/timers.h,v 1.4 1999/08/27 23:44:52 peter Exp $ + * + * Description : Basic timers header. + * + * 1.00 94/06/13 proven + * -Started coding this file. + */ + +#ifndef _TIMERS_H_ +#define _TIMERS_H_ + +#include + +#endif diff --git a/src/include/ttyent.h b/src/include/ttyent.h new file mode 100644 index 0000000..e870d70 --- /dev/null +++ b/src/include/ttyent.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1989, 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. + * + * @(#)ttyent.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/ttyent.h,v 1.7 2002/03/23 17:24:53 imp Exp $ + */ + +#ifndef _TTYENT_H_ +#define _TTYENT_H_ + +#define _PATH_TTYS "/etc/ttys" + +#define _TTYS_OFF "off" +#define _TTYS_ON "on" +#define _TTYS_SECURE "secure" +#define _TTYS_INSECURE "insecure" +#define _TTYS_WINDOW "window" +#define _TTYS_GROUP "group" +#define _TTYS_NOGROUP "none" +#define _TTYS_DIALUP "dialup" +#define _TTYS_NETWORK "network" + +struct ttyent { + char *ty_name; /* terminal device name */ + char *ty_getty; /* command to execute, usually getty */ + char *ty_type; /* terminal type for termcap */ +#define TTY_ON 0x01 /* enable logins (start ty_getty program) */ +#define TTY_SECURE 0x02 /* allow uid of 0 to login */ +#define TTY_DIALUP 0x04 /* is a dialup tty */ +#define TTY_NETWORK 0x08 /* is a network tty */ + int ty_status; /* status flags */ + char *ty_window; /* command to start up window manager */ + char *ty_comment; /* comment field */ + char *ty_group; /* tty group */ +}; + +#include + +__BEGIN_DECLS +struct ttyent *getttyent(void); +struct ttyent *getttynam(const char *); +int setttyent(void); +int endttyent(void); +int isdialuptty(const char *); +int isnettty(const char *); +__END_DECLS + +#endif /* !_TTYENT_H_ */ diff --git a/src/include/ucontext.h b/src/include/ucontext.h new file mode 100644 index 0000000..6ca4dda --- /dev/null +++ b/src/include/ucontext.h @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 1999 Marcel Moolenaar + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/ucontext.h,v 1.11 2003/11/09 20:31:04 marcel Exp $ + */ + +#ifndef _SYS_UCONTEXT_H_ +#define _SYS_UCONTEXT_H_ + +#include +#include + +typedef struct __ucontext { + /* + * Keep the order of the first two fields. Also, + * keep them the first two fields in the structure. + * This way we can have a union with struct + * sigcontext and ucontext_t. This allows us to + * support them both at the same time. + * note: the union is not defined, though. + */ + sigset_t uc_sigmask; + mcontext_t uc_mcontext; + + struct __ucontext *uc_link; + stack_t uc_stack; + int uc_flags; +#define UCF_SWAPPED 0x00000001 /* Used by swapcontext(3). */ + int __spare__[4]; +} ucontext_t; + +#if defined(_KERNEL) && defined(COMPAT_FREEBSD4) +#if defined(__i386__) || defined(__alpha__) +struct ucontext4 { + sigset_t uc_sigmask; + struct mcontext4 uc_mcontext; + struct ucontext4 *uc_link; + stack_t uc_stack; + int __spare__[8]; +}; +#else /* __i386__ || __alpha__ */ +#define ucontext4 ucontext +#endif /* __i386__ || __alpha__ */ +#endif /* _KERNEL */ + +#ifndef _KERNEL + +__BEGIN_DECLS + +int getcontext(ucontext_t *); +int setcontext(const ucontext_t *); +void makecontext(ucontext_t *, void (*)(void), int, ...); +int signalcontext(ucontext_t *, int, __sighandler_t *); +int swapcontext(ucontext_t *, const ucontext_t *); + +__END_DECLS + +#else /* _KERNEL */ + +struct thread; + +/* + * Flags for get_mcontext(). The low order 4 bits (i.e a mask of 0x0f) are + * reserved for use by machine independent code. All other bits are for use + * by machine dependent code. + */ +#define GET_MC_CLEAR_RET 1 + +/* Machine-dependent functions: */ +int get_mcontext(struct thread *, mcontext_t *, int); +int set_mcontext(struct thread *, const mcontext_t *); + +#endif /* !_KERNEL */ + +#endif /* !_SYS_UCONTEXT_H_ */ diff --git a/src/include/ugidfw.h b/src/include/ugidfw.h new file mode 100644 index 0000000..a662056 --- /dev/null +++ b/src/include/ugidfw.h @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2002, 2004 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by Network Associates + * Laboratories, the Security Research Division of Network Associates, Inc. + * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the + * DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libugidfw/ugidfw.h,v 1.4 2004/02/25 03:24:39 rwatson Exp $ + */ + +#ifndef _UGIDFW_H +#define _UGIDFW_H + +__BEGIN_DECLS +int bsde_rule_to_string(struct mac_bsdextended_rule *rule, char *buf, + size_t buflen); +int bsde_parse_identity(int argc, char *argv[], + struct mac_bsdextended_identity *identity, size_t buflen, + char *errstr); +int bsde_parse_mode(int argc, char *argv[], mode_t *mode, size_t buflen, + char *errstr); +int bsde_parse_rule(int argc, char *argv[], + struct mac_bsdextended_rule *rule, size_t buflen, char *errstr); +int bsde_parse_rule_string(const char *string, + struct mac_bsdextended_rule *rule, size_t buflen, char *errstr); +int bsde_get_mib(const char *string, int *name, size_t *namelen); +int bsde_get_rule_count(size_t buflen, char *errstr); +int bsde_get_rule_slots(size_t buflen, char *errstr); +int bsde_get_rule(int rulenum, struct mac_bsdextended_rule *rule, + size_t errlen, char *errstr); +int bsde_delete_rule(int rulenum, size_t buflen, char *errstr); +int bsde_set_rule(int rulenum, struct mac_bsdextended_rule *rule, + size_t buflen, char *errstr); +int bsde_add_rule(int *rulename, struct mac_bsdextended_rule *rule, + size_t buflen, char *errstr); +__END_DECLS + +#endif diff --git a/src/include/ulimit.h b/src/include/ulimit.h new file mode 100644 index 0000000..c6a451c --- /dev/null +++ b/src/include/ulimit.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2002 Kyle Martin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/ulimit.h,v 1.4 2003/01/08 01:18:13 tjr Exp $ + */ + +#ifndef _ULIMIT_H_ +#define _ULIMIT_H_ + +#include + +#define UL_GETFSIZE 1 +#define UL_SETFSIZE 2 + +__BEGIN_DECLS +long ulimit(int, ...); +__END_DECLS + +#endif /* !_ULIMIT_H_ */ diff --git a/src/include/un-namespace.h b/src/include/un-namespace.h new file mode 100644 index 0000000..067e22d --- /dev/null +++ b/src/include/un-namespace.h @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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. + * + * $FreeBSD: src/lib/libc/include/un-namespace.h,v 1.13 2003/05/01 19:03:13 nectar Exp $ + */ + +#ifndef _UN_NAMESPACE_H_ +#define _UN_NAMESPACE_H_ + +#undef accept +#undef __acl_aclcheck_fd +#undef __acl_delete_fd +#undef __acl_get_fd +#undef __acl_set_fd +#undef bind +#undef __cap_get_fd +#undef __cap_set_fd +#undef close +#undef connect +#undef dup +#undef dup2 +#undef execve +#undef fcntl +#undef flock +#undef flockfile +#undef fpathconf +#undef fstat +#undef fstatfs +#undef fsync +#undef funlockfile +#undef getdirentries +#undef getlogin +#undef getpeername +#undef getprogname +#undef getsockname +#undef getsockopt +#undef ioctl +#undef kevent +#undef listen +#undef nanosleep +#undef open +#undef poll +#undef pthread_cond_broadcast +#undef pthread_cond_destroy +#undef pthread_cond_init +#undef pthread_cond_signal +#undef pthread_cond_timedwait +#undef pthread_cond_wait +#undef pthread_exit +#undef pthread_getspecific +#undef pthread_key_create +#undef pthread_key_delete +#undef pthread_main_np +#undef pthread_mutex_destroy +#undef pthread_mutex_init +#undef pthread_mutex_lock +#undef pthread_mutex_trylock +#undef pthread_mutex_unlock +#undef pthread_mutexattr_init +#undef pthread_mutexattr_destroy +#undef pthread_mutexattr_settype +#undef pthread_once +#undef pthread_rwlock_destroy +#undef pthread_rwlock_init +#undef pthread_rwlock_rdlock +#undef pthread_rwlock_wrlock +#undef pthread_rwlock_tryrdlock +#undef pthread_rwlock_trywrlock +#undef pthread_rwlock_unlock +#undef pthread_self +#undef pthread_setspecific +#undef pthread_sigmask +#undef read +#undef readv +#undef recvfrom +#undef recvmsg +#undef select +#undef sendmsg +#undef sendto +#undef setsockopt +#undef sigaction +#undef sigprocmask +#undef sigsuspend +#undef socket +#undef socketpair +#undef wait4 +#undef waitpid +#undef write +#undef writev + +#if 0 +#undef creat +#undef fchflags +#undef fchmod +#undef ftrylockfile +#undef msync +#undef nfssvc +#undef pause +#undef pthread_rwlockattr_init +#undef pthread_rwlockattr_destroy +#undef sched_yield +#undef sendfile +#undef shutdown +#undef sigaltstack +#undef sigpending +#undef sigreturn +#undef sigsetmask +#undef sleep +#undef system +#undef tcdrain +#undef wait +#endif /* 0 */ + +#ifdef _SIGNAL_H_ +int _sigaction(int, const struct sigaction *, struct sigaction *); +#endif + +#ifdef _SYS_EVENT_H_ +int _kevent(int, const struct kevent *, int, struct kevent *, + int, const struct timespec *); +#endif + +#ifdef _SYS_FCNTL_H_ +int _flock(int, int); +#endif + +#undef err +#undef warn +#undef nsdispatch + +#endif /* _UN_NAMESPACE_H_ */ diff --git a/src/include/unctrl.h b/src/include/unctrl.h new file mode 100644 index 0000000..567fec8 --- /dev/null +++ b/src/include/unctrl.h @@ -0,0 +1,63 @@ +/**************************************************************************** + * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim 1992,1995 * + * and: Eric S. Raymond * + ****************************************************************************/ + +/* + * unctrl.h + * + * Display a printable version of a control character. + * Control characters are displayed in caret notation (^x), DELETE is displayed + * as ^?. Printable characters are displayed as is. + */ + +/* $Id$ */ + +#ifndef NCURSES_UNCTRL_H_incl +#define NCURSES_UNCTRL_H_incl 1 + +#undef NCURSES_VERSION +#define NCURSES_VERSION "5.2" + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#undef unctrl +NCURSES_EXPORT(NCURSES_CONST char *) unctrl (chtype); + +#ifdef __cplusplus +} +#endif + +#endif /* NCURSES_UNCTRL_H_incl */ diff --git a/src/include/unistd.h b/src/include/unistd.h new file mode 100644 index 0000000..4a1eb67 --- /dev/null +++ b/src/include/unistd.h @@ -0,0 +1,552 @@ +/*- + * Copyright (c) 1991, 1993, 1994 + * 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. + * + * @(#)unistd.h 8.12 (Berkeley) 4/27/95 + * $FreeBSD: src/include/unistd.h,v 1.73 2004/02/23 04:51:07 ache Exp $ + */ + +#ifndef _UNISTD_H_ +#define _UNISTD_H_ + +#include +#include /* XXX adds too much pollution. */ +#include +#include +#include + +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#ifndef _USECONDS_T_DECLARED +typedef __useconds_t useconds_t; +#define _USECONDS_T_DECLARED +#endif + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +#define F_ULOCK 0 /* unlock locked section */ +#define F_LOCK 1 /* lock a section for exclusive use */ +#define F_TLOCK 2 /* test and lock a section for exclusive use */ +#define F_TEST 3 /* test a section for locks by other procs */ +#endif + +/* + * POSIX options and option groups we unconditionally do or don't + * implement. This list includes those options which are exclusively + * implemented (or not) in user mode. Please keep this list in + * alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ +#define _POSIX_BARRIERS -1 +#define _POSIX_READER_WRITER_LOCKS 200112L +#define _POSIX_REGEXP 1 +#define _POSIX_SHELL 1 +#define _POSIX_SPAWN -1 +#define _POSIX_SPIN_LOCKS -1 +#define _POSIX_THREAD_ATTR_STACKADDR 200112L +#define _POSIX_THREAD_ATTR_STACKSIZE 200112L +#define _POSIX_THREAD_CPUTIME -1 +#define _POSIX_THREAD_PRIO_INHERIT 200112L +#define _POSIX_THREAD_PRIO_PROTECT 200112L +#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L +#define _POSIX_THREAD_PROCESS_SHARED -1 +#define _POSIX_THREAD_SAFE_FUNCTIONS -1 +#define _POSIX_THREAD_SPORADIC_SERVER -1 +#define _POSIX_THREADS 200112L +#define _POSIX_TRACE -1 +#define _POSIX_TRACE_EVENT_FILTER -1 +#define _POSIX_TRACE_INHERIT -1 +#define _POSIX_TRACE_LOG -1 +#define _POSIX2_C_BIND 200112L /* mandatory */ +#define _POSIX2_C_DEV -1 /* need c99 utility */ +#define _POSIX2_CHAR_TERM 1 +#define _POSIX2_FORT_DEV -1 /* need fort77 utility */ +#define _POSIX2_FORT_RUN 200112L +#define _POSIX2_LOCALEDEF -1 +#define _POSIX2_PBS -1 +#define _POSIX2_PBS_ACCOUNTING -1 +#define _POSIX2_PBS_CHECKPOINT -1 +#define _POSIX2_PBS_LOCATE -1 +#define _POSIX2_PBS_MESSAGE -1 +#define _POSIX2_PBS_TRACK -1 +#define _POSIX2_SW_DEV -1 /* XXX ??? */ +#define _POSIX2_UPE 200112L +#define _V6_ILP32_OFF32 -1 +#define _V6_ILP32_OFFBIG 0 +#define _V6_LP64_OFF64 0 +#define _V6_LPBIG_OFFBIG -1 + +#if __XSI_VISIBLE +#define _XOPEN_CRYPT -1 /* XXX ??? */ +#define _XOPEN_ENH_I18N -1 /* mandatory in XSI */ +#define _XOPEN_LEGACY -1 +#define _XOPEN_REALTIME -1 +#define _XOPEN_REALTIME_THREADS -1 +#define _XOPEN_UNIX -1 +#endif + +/* Define the POSIX.2 version we target for compliance. */ +#define _POSIX2_VERSION 199212L + +/* + * POSIX-style system configuration variable accessors (for the + * sysconf function). The kernel does not directly implement the + * sysconf() interface; rather, a C library stub translates references + * to sysconf() into calls to sysctl() using a giant switch statement. + * Those that are marked `user' are implemented entirely in the C + * library and never query the kernel. pathconf() is implemented + * directly by the kernel so those are not defined here. + */ +#define _SC_ARG_MAX 1 +#define _SC_CHILD_MAX 2 +#define _SC_CLK_TCK 3 +#define _SC_NGROUPS_MAX 4 +#define _SC_OPEN_MAX 5 +#define _SC_JOB_CONTROL 6 +#define _SC_SAVED_IDS 7 +#define _SC_VERSION 8 +#define _SC_BC_BASE_MAX 9 /* user */ +#define _SC_BC_DIM_MAX 10 /* user */ +#define _SC_BC_SCALE_MAX 11 /* user */ +#define _SC_BC_STRING_MAX 12 /* user */ +#define _SC_COLL_WEIGHTS_MAX 13 /* user */ +#define _SC_EXPR_NEST_MAX 14 /* user */ +#define _SC_LINE_MAX 15 /* user */ +#define _SC_RE_DUP_MAX 16 /* user */ +#define _SC_2_VERSION 17 /* user */ +#define _SC_2_C_BIND 18 /* user */ +#define _SC_2_C_DEV 19 /* user */ +#define _SC_2_CHAR_TERM 20 /* user */ +#define _SC_2_FORT_DEV 21 /* user */ +#define _SC_2_FORT_RUN 22 /* user */ +#define _SC_2_LOCALEDEF 23 /* user */ +#define _SC_2_SW_DEV 24 /* user */ +#define _SC_2_UPE 25 /* user */ +#define _SC_STREAM_MAX 26 /* user */ +#define _SC_TZNAME_MAX 27 /* user */ + +#if __POSIX_VISIBLE >= 199309 +#define _SC_ASYNCHRONOUS_IO 28 +#define _SC_MAPPED_FILES 29 +#define _SC_MEMLOCK 30 +#define _SC_MEMLOCK_RANGE 31 +#define _SC_MEMORY_PROTECTION 32 +#define _SC_MESSAGE_PASSING 33 +#define _SC_PRIORITIZED_IO 34 +#define _SC_PRIORITY_SCHEDULING 35 +#define _SC_REALTIME_SIGNALS 36 +#define _SC_SEMAPHORES 37 +#define _SC_FSYNC 38 +#define _SC_SHARED_MEMORY_OBJECTS 39 +#define _SC_SYNCHRONIZED_IO 40 +#define _SC_TIMERS 41 +#define _SC_AIO_LISTIO_MAX 42 +#define _SC_AIO_MAX 43 +#define _SC_AIO_PRIO_DELTA_MAX 44 +#define _SC_DELAYTIMER_MAX 45 +#define _SC_MQ_OPEN_MAX 46 +#define _SC_PAGESIZE 47 +#define _SC_RTSIG_MAX 48 +#define _SC_SEM_NSEMS_MAX 49 +#define _SC_SEM_VALUE_MAX 50 +#define _SC_SIGQUEUE_MAX 51 +#define _SC_TIMER_MAX 52 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _SC_2_PBS 59 /* user */ +#define _SC_2_PBS_ACCOUNTING 60 /* user */ +#define _SC_2_PBS_CHECKPOINT 61 /* user */ +#define _SC_2_PBS_LOCATE 62 /* user */ +#define _SC_2_PBS_MESSAGE 63 /* user */ +#define _SC_2_PBS_TRACK 64 /* user */ +#define _SC_ADVISORY_INFO 65 +#define _SC_BARRIERS 66 /* user */ +#define _SC_CLOCK_SELECTION 67 +#define _SC_CPUTIME 68 +#define _SC_FILE_LOCKING 69 +#define _SC_GETGR_R_SIZE_MAX 70 /* user */ +#define _SC_GETPW_R_SIZE_MAX 71 /* user */ +#define _SC_HOST_NAME_MAX 72 +#define _SC_LOGIN_NAME_MAX 73 +#define _SC_MONOTONIC_CLOCK 74 +#define _SC_MQ_PRIO_MAX 75 +#define _SC_READER_WRITER_LOCKS 76 /* user */ +#define _SC_REGEXP 77 /* user */ +#define _SC_SHELL 78 /* user */ +#define _SC_SPAWN 79 /* user */ +#define _SC_SPIN_LOCKS 80 /* user */ +#define _SC_SPORADIC_SERVER 81 +#define _SC_THREAD_ATTR_STACKADDR 82 /* user */ +#define _SC_THREAD_ATTR_STACKSIZE 83 /* user */ +#define _SC_THREAD_CPUTIME 84 /* user */ +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 85 /* user */ +#define _SC_THREAD_KEYS_MAX 86 /* user */ +#define _SC_THREAD_PRIO_INHERIT 87 /* user */ +#define _SC_THREAD_PRIO_PROTECT 88 /* user */ +#define _SC_THREAD_PRIORITY_SCHEDULING 89 /* user */ +#define _SC_THREAD_PROCESS_SHARED 90 /* user */ +#define _SC_THREAD_SAFE_FUNCTIONS 91 /* user */ +#define _SC_THREAD_SPORADIC_SERVER 92 /* user */ +#define _SC_THREAD_STACK_MIN 93 /* user */ +#define _SC_THREAD_THREADS_MAX 94 /* user */ +#define _SC_TIMEOUTS 95 /* user */ +#define _SC_THREADS 96 /* user */ +#define _SC_TRACE 97 /* user */ +#define _SC_TRACE_EVENT_FILTER 98 /* user */ +#define _SC_TRACE_INHERIT 99 /* user */ +#define _SC_TRACE_LOG 100 /* user */ +#define _SC_TTY_NAME_MAX 101 /* user */ +#define _SC_TYPED_MEMORY_OBJECTS 102 +#define _SC_V6_ILP32_OFF32 103 /* user */ +#define _SC_V6_ILP32_OFFBIG 104 /* user */ +#define _SC_V6_LP64_OFF64 105 /* user */ +#define _SC_V6_LPBIG_OFFBIG 106 /* user */ +#define _SC_IPV6 118 +#define _SC_RAW_SOCKETS 119 +#define _SC_SYMLOOP_MAX 120 +#endif + +#if __XSI_VISIBLE +#define _SC_ATEXIT_MAX 107 /* user */ +#define _SC_IOV_MAX 56 +#define _SC_PAGE_SIZE _SC_PAGESIZE +#define _SC_XOPEN_CRYPT 108 /* user */ +#define _SC_XOPEN_ENH_I18N 109 /* user */ +#define _SC_XOPEN_LEGACY 110 /* user */ +#define _SC_XOPEN_REALTIME 111 +#define _SC_XOPEN_REALTIME_THREADS 112 +#define _SC_XOPEN_SHM 113 +#define _SC_XOPEN_STREAMS 114 +#define _SC_XOPEN_UNIX 115 +#define _SC_XOPEN_VERSION 116 +#define _SC_XOPEN_XCU_VERSION 117 /* user */ +#endif + +#if __BSD_VISIBLE +#define _SC_NPROCESSORS_CONF 57 +#define _SC_NPROCESSORS_ONLN 58 +#endif + +/* Keys for the confstr(3) function. */ +#if __POSIX_VISIBLE >= 199209 +#define _CS_PATH 1 /* default value of PATH */ +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 2 +#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 3 +#define _CS_POSIX_V6_ILP32_OFF32_LIBS 4 +#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 5 +#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 6 +#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 7 +#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 8 +#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 9 +#define _CS_POSIX_V6_LP64_OFF64_LIBS 10 +#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 11 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 12 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 13 +#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 14 +#endif + +__BEGIN_DECLS +/* 1003.1-1990 */ +void _exit(int) __dead2; +int access(const char *, int); +unsigned int alarm(unsigned int); +int chdir(const char *); +int chown(const char *, uid_t, gid_t); +int close(int); +int dup(int); +int dup2(int, int); +int eaccess(const char *, int); +int execl(const char *, const char *, ...); +int execle(const char *, const char *, ...); +int execlp(const char *, const char *, ...); +int execv(const char *, char * const *); +int execve(const char *, char * const *, char * const *); +int execvp(const char *, char * const *); +pid_t fork(void); +long fpathconf(int, int); +char *getcwd(char *, size_t); +gid_t getegid(void); +uid_t geteuid(void); +gid_t getgid(void); +int getgroups(int, gid_t []); +char *getlogin(void); +pid_t getpgrp(void); +pid_t getpid(void); +pid_t getppid(void); +uid_t getuid(void); +int isatty(int); +int link(const char *, const char *); +#ifndef _LSEEK_DECLARED +#define _LSEEK_DECLARED +off_t lseek(int, off_t, int); +#endif +long pathconf(const char *, int); +int pause(void); +int pipe(int *); +ssize_t read(int, void *, size_t); +int rmdir(const char *); +int setgid(gid_t); +int setpgid(pid_t, pid_t); +void setproctitle(const char *_fmt, ...) __printf0like(1, 2); +pid_t setsid(void); +int setuid(uid_t); +unsigned int sleep(unsigned int); +long sysconf(int); +pid_t tcgetpgrp(int); +int tcsetpgrp(int, pid_t); +char *ttyname(int); +int unlink(const char *); +ssize_t write(int, const void *, size_t); + +/* 1003.2-1992 */ +#if __POSIX_VISIBLE >= 199209 || __XSI_VISIBLE +size_t confstr(int, char *, size_t); +#ifndef _GETOPT_DECLARED +#define _GETOPT_DECLARED +int getopt(int, char * const [], const char *); + +extern char *optarg; /* getopt(3) external variables */ +extern int optind, opterr, optopt; +#endif /* _GETOPT_DECLARED */ +#endif + +/* ISO/IEC 9945-1: 1996 */ +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE +int fsync(int); + +/* + * ftruncate() was in the POSIX Realtime Extension (it's used for shared + * memory), but truncate() was not. + */ +#ifndef _FTRUNCATE_DECLARED +#define _FTRUNCATE_DECLARED +int ftruncate(int, off_t); +#endif +#endif + +#if __POSIX_VISIBLE >= 199506 +int getlogin_r(char *, int); +#endif + +/* 1003.1-2001 */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +int fchown(int, uid_t, gid_t); +int readlink(const char *, char *, int); +#endif +#if __POSIX_VISIBLE >= 200112 +int gethostname(char *, size_t); +int setegid(gid_t); +int seteuid(uid_t); +#endif + +/* + * symlink() was originally in POSIX.1a, which was withdrawn after + * being overtaken by events (1003.1-2001). It was in XPG4.2, and of + * course has been in BSD since 4.2. + */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 402 || __BSD_VISIBLE +int symlink(const char * __restrict, const char * __restrict); +#endif + +/* X/Open System Interfaces */ +#if __XSI_VISIBLE +char *crypt(const char *, const char *); +/* char *ctermid(char *); */ /* XXX ??? */ +int encrypt(char *, int); +int fchdir(int); +long gethostid(void); +int getpgid(pid_t _pid); +int getsid(pid_t _pid); +char *getwd(char *); /* LEGACY: obsoleted by getcwd() */ +int lchown(const char *, uid_t, gid_t); +int lockf(int, int, off_t); +int nice(int); +ssize_t pread(int, void *, size_t, off_t); +ssize_t pwrite(int, const void *, size_t, off_t); +int setpgrp(pid_t _pid, pid_t _pgrp); /* obsoleted by setpgid() */ +int setregid(gid_t, gid_t); +int setreuid(uid_t, uid_t); +/* void swab(const void * __restrict, void * __restrict, ssize_t); */ +void sync(void); +useconds_t ualarm(useconds_t, useconds_t); +int usleep(useconds_t); +pid_t vfork(void); + +/* See comment at ftruncate() above. */ +#ifndef _TRUNCATE_DECLARED +#define _TRUNCATE_DECLARED +int truncate(const char *, off_t); +#endif +#endif /* __XSI_VISIBLE */ + +#if __XSI_VISIBLE <= 500 || __BSD_VISIBLE +int brk(const void *); +int chroot(const char *); +int getdtablesize(void); +int getpagesize(void) __pure2; +char *getpass(const char *); +void *sbrk(intptr_t); +#endif + +#if __BSD_VISIBLE +struct timeval; /* select(2) */ +int acct(const char *); +int async_daemon(void); +int check_utility_compat(const char *); +const char * + crypt_get_format(void); +int crypt_set_format(const char *); +int des_cipher(const char *, char *, long, int); +int des_setkey(const char *key); +void endusershell(void); +int exect(const char *, char * const *, char * const *); +int execvP(const char *, const char *, char * const *); +char *fflagstostr(u_long); +int getdomainname(char *, int); +int getgrouplist(const char *, gid_t, gid_t *, int *); +mode_t getmode(const void *, mode_t); +int getpeereid(int, uid_t *, gid_t *); +int getresgid(gid_t *, gid_t *, gid_t *); +int getresuid(uid_t *, uid_t *, uid_t *); +char *getusershell(void); +int initgroups(const char *, gid_t); +int iruserok(unsigned long, int, const char *, const char *); +int iruserok_sa(const void *, int, int, const char *, const char *); +int issetugid(void); +char *mkdtemp(char *); +int mknod(const char *, mode_t, dev_t); +#ifndef _MKSTEMP_DECLARED +int mkstemp(char *); +#define _MKSTEMP_DECLARED +#endif +int mkstemps(char *, int); +#ifndef _MKTEMP_DECLARED +char *mktemp(char *); +#define _MKTEMP_DECLARED +#endif +int nfsclnt(int, void *); +int nfssvc(int, void *); +int profil(char *, size_t, vm_offset_t, int); +int rcmd(char **, int, const char *, const char *, const char *, int *); +int rcmd_af(char **, int, const char *, + const char *, const char *, int *, int); +int rcmdsh(char **, int, const char *, + const char *, const char *, const char *); +char *re_comp(const char *); +int re_exec(const char *); +int reboot(int); +int revoke(const char *); +pid_t rfork(int); +pid_t rfork_thread(int, void *, int (*)(void *), void *); +int rresvport(int *); +int rresvport_af(int *, int); +int ruserok(const char *, int, const char *, const char *); +#if __BSD_VISIBLE +#ifndef _SELECT_DECLARED +#define _SELECT_DECLARED +int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +#endif +#endif +int setdomainname(const char *, int); +int setgroups(int, const gid_t *); +void sethostid(long); +int sethostname(const char *, int); +#ifndef _SETKEY_DECLARED +int setkey(const char *); +#define _SETKEY_DECLARED +#endif +int setlogin(const char *); +void *setmode(const char *); +int setresgid(gid_t, gid_t, gid_t); +int setresuid(uid_t, uid_t, uid_t); +int setrgid(gid_t); +int setruid(uid_t); +void setusershell(void); +int strtofflags(char **, u_long *, u_long *); +int swapon(const char *); +int swapoff(const char *); +int syscall(int, ...); +off_t __syscall(quad_t, ...); +int ttyslot(void); +int undelete(const char *); +int unwhiteout(const char *); +void *valloc(size_t); /* obsoleted by malloc() */ + +#ifndef _OPTRESET_DECLARED +#define _OPTRESET_DECLARED +extern int optreset; /* getopt(3) external variable */ +#endif +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_UNISTD_H_ */ diff --git a/src/include/usbhid.h b/src/include/usbhid.h new file mode 100644 index 0000000..f84c1f5 --- /dev/null +++ b/src/include/usbhid.h @@ -0,0 +1,105 @@ +/* $NetBSD: usb.h,v 1.8 2000/08/13 22:22:02 augustss Exp $ */ + +/* + * Copyright (c) 1999 Lennart Augustsson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libusbhid/usbhid.h,v 1.10 2004/02/11 21:09:13 emax Exp $ + * + */ + +#include + +typedef struct report_desc *report_desc_t; + +typedef struct hid_data *hid_data_t; + +typedef enum hid_kind { + hid_input = 0, + hid_output = 1, + hid_feature = 2, + hid_collection, + hid_endcollection +} hid_kind_t; + +typedef struct hid_item { + /* Global */ + unsigned int _usage_page; + int logical_minimum; + int logical_maximum; + int physical_minimum; + int physical_maximum; + int unit_exponent; + int unit; + int report_size; + int report_ID; +#define NO_REPORT_ID 0 + int report_count; + /* Local */ + unsigned int usage; + int usage_minimum; + int usage_maximum; + int designator_index; + int designator_minimum; + int designator_maximum; + int string_index; + int string_minimum; + int string_maximum; + int set_delimiter; + /* Misc */ + int collection; + int collevel; + enum hid_kind kind; + unsigned int flags; + /* Absolute data position (bits) */ + unsigned int pos; + /* */ + struct hid_item *next; +} hid_item_t; + +#define HID_PAGE(u) (((u) >> 16) & 0xffff) +#define HID_USAGE(u) ((u) & 0xffff) + +/* Obtaining a report descriptor, descr.c: */ +report_desc_t hid_get_report_desc(int file); +report_desc_t hid_use_report_desc(unsigned char *data, unsigned int size); +void hid_dispose_report_desc(report_desc_t); + +/* Parsing of a HID report descriptor, parse.c: */ +hid_data_t hid_start_parse(report_desc_t d, int kindset, int id); +void hid_end_parse(hid_data_t s); +int hid_get_item(hid_data_t s, hid_item_t *h); +int hid_report_size(report_desc_t d, enum hid_kind k, int id); +int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h, int id); + +/* Conversion to/from usage names, usage.c: */ +const char *hid_usage_page(int i); +const char *hid_usage_in_page(unsigned int u); +void hid_init(const char *file); +int hid_parse_usage_in_page(const char *name); +int hid_parse_usage_page(const char *name); + +/* Extracting/insertion of data, data.c: */ +int hid_get_data(const void *p, const hid_item_t *h); +void hid_set_data(void *p, const hid_item_t *h, int data); diff --git a/src/include/utime.h b/src/include/utime.h new file mode 100644 index 0000000..ded805a --- /dev/null +++ b/src/include/utime.h @@ -0,0 +1,57 @@ +/*- + * 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. + * + * @(#)utime.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/utime.h,v 1.5 2002/08/24 00:11:52 mike Exp $ + */ + +#ifndef _UTIME_H_ +#define _UTIME_H_ + +#include +#include + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +struct utimbuf { + time_t actime; /* Access time */ + time_t modtime; /* Modification time */ +}; + +__BEGIN_DECLS +int utime(const char *, const struct utimbuf *); +__END_DECLS + +#endif /* !_UTIME_H_ */ diff --git a/src/include/utmp.h b/src/include/utmp.h new file mode 100644 index 0000000..fdd9acc --- /dev/null +++ b/src/include/utmp.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)utmp.h 8.2 (Berkeley) 1/21/94 + * $FreeBSD: src/include/utmp.h,v 1.10 2001/10/27 20:40:54 peter Exp $ + */ + +#ifndef _UTMP_H_ +#define _UTMP_H_ + +#define _PATH_UTMP "/var/run/utmp" +#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_LASTLOG "/var/log/lastlog" + +#define UT_NAMESIZE 16 /* see MAXLOGNAME in */ +#define UT_LINESIZE 8 +#define UT_HOSTSIZE 16 + +struct lastlog { + int32_t ll_time; + char ll_line[UT_LINESIZE]; + char ll_host[UT_HOSTSIZE]; +}; + +struct utmp { + char ut_line[UT_LINESIZE]; + char ut_name[UT_NAMESIZE]; + char ut_host[UT_HOSTSIZE]; + int32_t ut_time; +}; + +#endif /* !_UTMP_H_ */ diff --git a/src/include/uuid.h b/src/include/uuid.h new file mode 100644 index 0000000..c2800eb --- /dev/null +++ b/src/include/uuid.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2002 Marcel Moolenaar + * Copyright (c) 2002 Hiten Mahesh Pandya + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/uuid.h,v 1.2 2002/11/05 10:55:16 jmallett Exp $ + */ + +#ifndef _UUID_H_ +#define _UUID_H_ + +#include +#include + +/* + * This implementation mostly conforms to the DCE 1.1 specification. + * See Also: + * uuidgen(1), uuidgen(2), uuid(3) + */ + +/* Status codes returned by the functions. */ +#define uuid_s_ok 0 +#define uuid_s_bad_version 1 +#define uuid_s_invalid_string_uuid 2 +#define uuid_s_no_memory 3 + +__BEGIN_DECLS +int32_t uuid_compare(uuid_t *, uuid_t *, uint32_t *); +void uuid_create(uuid_t *, uint32_t *); +void uuid_create_nil(uuid_t *, uint32_t *); +int32_t uuid_equal(uuid_t *, uuid_t *, uint32_t *); +void uuid_from_string(const char *, uuid_t *, uint32_t *); +uint16_t uuid_hash(uuid_t *, uint32_t *); +int32_t uuid_is_nil(uuid_t *, uint32_t *); +void uuid_to_string(uuid_t *, char **, uint32_t *); +__END_DECLS + +#endif /* _UUID_H_ */ diff --git a/src/include/varargs.h b/src/include/varargs.h new file mode 100644 index 0000000..cd5444f --- /dev/null +++ b/src/include/varargs.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2003 Alexander Kabaev + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/varargs.h,v 1.1 2003/09/01 03:28:25 kan Exp $ + */ + +#ifndef _VARARGS_H_ +#define _VARARGS_H_ + +#if defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ > 2 || __GNUC__ >= 4) + +#error " is obsolete with this version of GCC." +#error "Change your code to use instead." + +#else /* ! __GNUC__ post GCC 3.3 */ + +#include + +#endif /* __GNUC__ post GCC 3.3 */ + +#endif /* !_VARARGS_H_ */ diff --git a/src/include/vgl.h b/src/include/vgl.h new file mode 100644 index 0000000..24a5c38 --- /dev/null +++ b/src/include/vgl.h @@ -0,0 +1,154 @@ +/*- + * Copyright (c) 1991-1997 S�ren Schmidt + * 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 + * in this position and unchanged. + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/lib/libvgl/vgl.h,v 1.8 2002/06/02 20:05:39 schweikh Exp $ + */ + +#ifndef _VGL_H_ +#define _VGL_H_ + +#include +#include +#include +#include + +typedef unsigned char byte; +typedef struct { + byte Type; + int Xsize, Ysize; + int VXsize, VYsize; + int Xorigin, Yorigin; + byte *Bitmap; + int PixelBytes; +} VGLBitmap; + +#define VGLBITMAP_INITIALIZER(t, x, y, bits) \ + { (t), (x), (y), (x), (y), 0, 0, (bits) } + +/* + * Defined Type's + */ +#define MEMBUF 0 +#define VIDBUF4 1 +#define VIDBUF8 2 +#define VIDBUF8X 3 +#define VIDBUF8S 4 +#define VIDBUF4S 5 +#define VIDBUF16 6 /* Direct Color linear buffer */ +#define VIDBUF24 7 /* Direct Color linear buffer */ +#define VIDBUF32 8 /* Direct Color linear buffer */ +#define VIDBUF16S 9 /* Direct Color segmented buffer */ +#define VIDBUF24S 10 /* Direct Color segmented buffer */ +#define VIDBUF32S 11 /* Direct Color segmented buffer */ +#define NOBUF 255 + +typedef struct VGLText { + byte Width, Height; + byte *BitmapArray; +} VGLText; + +typedef struct VGLObject { + int Id; + int Type; + int Status; + int Xpos, Ypos; + int Xhot, Yhot; + VGLBitmap *Image; + VGLBitmap *Mask; + int (*CallBackFunction)(); +} VGLObject; + +#define MOUSE_IMG_SIZE 16 +#define VGL_MOUSEHIDE 0 +#define VGL_MOUSESHOW 1 +#define VGL_MOUSEFREEZE 0 +#define VGL_MOUSEUNFREEZE 1 +#define VGL_DIR_RIGHT 0 +#define VGL_DIR_UP 1 +#define VGL_DIR_LEFT 2 +#define VGL_DIR_DOWN 3 +#define VGL_RAWKEYS 1 +#define VGL_CODEKEYS 2 +#define VGL_XLATEKEYS 3 + +extern video_adapter_info_t VGLAdpInfo; +extern video_info_t VGLModeInfo; +extern VGLBitmap *VGLDisplay; +extern byte *VGLBuf; + +/* + * Prototypes + */ +/* bitmap.c */ +int __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); +int VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, VGLBitmap *dst, int dstx, int dsty, int width, int hight); +VGLBitmap *VGLBitmapCreate(int type, int xsize, int ysize, byte *bits); +void VGLBitmapDestroy(VGLBitmap *object); +int VGLBitmapAllocateBits(VGLBitmap *object); +/* keyboard.c */ +int VGLKeyboardInit(int mode); +void VGLKeyboardEnd(void); +int VGLKeyboardGetCh(void); +/* main.c */ +void VGLEnd(void); +int VGLInit(int mode); +void VGLCheckSwitch(void); +int VGLSetVScreenSize(VGLBitmap *object, int VXsize, int VYsize); +int VGLPanScreen(VGLBitmap *object, int x, int y); +int VGLSetSegment(unsigned int offset); +/* mouse.c */ +void VGLMousePointerShow(void); +void VGLMousePointerHide(void); +void VGLMouseMode(int mode); +void VGLMouseAction(int dummy); +void VGLMouseSetImage(VGLBitmap *AndMask, VGLBitmap *OrMask); +void VGLMouseSetStdImage(void); +int VGLMouseInit(int mode); +int VGLMouseStatus(int *x, int *y, char *buttons); +int VGLMouseFreeze(int x, int y, int width, int hight, byte color); +void VGLMouseUnFreeze(void); +/* simple.c */ +void VGLSetXY(VGLBitmap *object, int x, int y, u_long color); +u_long VGLGetXY(VGLBitmap *object, int x, int y); +void VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color); +void VGLBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color); +void VGLFilledBox(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color); +void VGLEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color); +void VGLFilledEllipse(VGLBitmap *object, int xc, int yc, int a, int b, u_long color); +void VGLClear(VGLBitmap *object, u_long color); +void VGLRestorePalette(void); +void VGLSavePalette(void); +void VGLSetPalette(byte *red, byte *green, byte *blue); +void VGLSetPaletteIndex(byte color, byte red, byte green, byte blue); +void VGLSetBorder(byte color); +void VGLBlankDisplay(int blank); +/* text.c */ +int VGLTextSetFontFile(char *filename); +void VGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch, byte fgcol, byte bgcol, int fill, int dir); +void VGLBitmapString(VGLBitmap *Object, int x, int y, char *str, byte fgcol, byte bgcol, int fill, int dir); + +#endif /* !_VGL_H_ */ diff --git a/src/include/vis.h b/src/include/vis.h new file mode 100644 index 0000000..f06cfba --- /dev/null +++ b/src/include/vis.h @@ -0,0 +1,95 @@ +/*- + * 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. + * + * @(#)vis.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: src/include/vis.h,v 1.11 2003/10/30 10:40:49 phk Exp $ + */ + +#ifndef _VIS_H_ +#define _VIS_H_ + +#include + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +/* + * to select alternate encoding format + */ +#define VIS_OCTAL 0x01 /* use octal \ddd format */ +#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ + +/* + * to alter set of characters encoded (default is to encode all + * non-graphic except space, tab, and newline). + */ +#define VIS_SP 0x04 /* also encode space */ +#define VIS_TAB 0x08 /* also encode tab */ +#define VIS_NL 0x10 /* also encode newline */ +#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) +#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ + +/* + * other + */ +#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ +#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */ +#define VIS_GLOB 0x100 /* encode glob(3) magics */ + +/* + * unvis return codes + */ +#define UNVIS_VALID 1 /* character valid */ +#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ +#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ +#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ +#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ + +/* + * unvis flags + */ +#define UNVIS_END 1 /* no more characters */ + +#include + +__BEGIN_DECLS +char *vis(char *, int, int, int); +int strvis(char *, const char *, int); +int strvisx(char *, const char *, size_t, int); +int strunvis(char *, const char *); +int strunvisx(char *, const char *, int); +int unvis(char *, int, int *, int); +__END_DECLS + +#endif /* !_VIS_H_ */ diff --git a/src/include/vm/pmap.h b/src/include/vm/pmap.h new file mode 100644 index 0000000..7ec377f --- /dev/null +++ b/src/include/vm/pmap.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * from: @(#)pmap.h 8.1 (Berkeley) 6/11/93 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Avadis Tevanian, Jr. + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/pmap.h,v 1.69 2004/04/10 22:41:46 alc Exp $ + */ + +/* + * Machine address mapping definitions -- machine-independent + * section. [For machine-dependent section, see "machine/pmap.h".] + */ + +#ifndef _PMAP_VM_ +#define _PMAP_VM_ +/* + * Each machine dependent implementation is expected to + * keep certain statistics. They may do this anyway they + * so choose, but are expected to return the statistics + * in the following structure. + */ +struct pmap_statistics { + long resident_count; /* # of pages mapped (total) */ + long wired_count; /* # of pages wired */ +}; +typedef struct pmap_statistics *pmap_statistics_t; + +#include + +#ifdef _KERNEL +struct proc; +struct thread; + +/* + * Updates to kernel_vm_end are synchronized by the kernel_map's system mutex. + */ +extern vm_offset_t kernel_vm_end; + +extern int pmap_pagedaemon_waken; + +void pmap_change_wiring(pmap_t, vm_offset_t, boolean_t); +void pmap_clear_modify(vm_page_t m); +void pmap_clear_reference(vm_page_t m); +void pmap_copy(pmap_t, pmap_t, vm_offset_t, vm_size_t, vm_offset_t); +void pmap_copy_page(vm_page_t, vm_page_t); +void pmap_enter(pmap_t, vm_offset_t, vm_page_t, vm_prot_t, + boolean_t); +vm_page_t pmap_enter_quick(pmap_t pmap, vm_offset_t va, vm_page_t m, + vm_page_t mpte); +vm_paddr_t pmap_extract(pmap_t pmap, vm_offset_t va); +vm_page_t pmap_extract_and_hold(pmap_t pmap, vm_offset_t va, + vm_prot_t prot); +void pmap_growkernel(vm_offset_t); +void pmap_init(void); +boolean_t pmap_is_modified(vm_page_t m); +boolean_t pmap_is_prefaultable(pmap_t pmap, vm_offset_t va); +boolean_t pmap_ts_referenced(vm_page_t m); +vm_offset_t pmap_map(vm_offset_t *, vm_paddr_t, vm_paddr_t, int); +void pmap_object_init_pt(pmap_t pmap, vm_offset_t addr, + vm_object_t object, vm_pindex_t pindex, vm_size_t size); +boolean_t pmap_page_exists_quick(pmap_t pmap, vm_page_t m); +void pmap_page_protect(vm_page_t m, vm_prot_t prot); +void pmap_pinit(pmap_t); +void pmap_pinit0(pmap_t); +void pmap_protect(pmap_t, vm_offset_t, vm_offset_t, vm_prot_t); +void pmap_qenter(vm_offset_t, vm_page_t *, int); +void pmap_qremove(vm_offset_t, int); +void pmap_release(pmap_t); +void pmap_remove(pmap_t, vm_offset_t, vm_offset_t); +void pmap_remove_all(vm_page_t m); +void pmap_remove_pages(pmap_t, vm_offset_t, vm_offset_t); +void pmap_zero_page(vm_page_t); +void pmap_zero_page_area(vm_page_t, int off, int size); +void pmap_zero_page_idle(vm_page_t); +int pmap_mincore(pmap_t pmap, vm_offset_t addr); +void pmap_activate(struct thread *td); +vm_offset_t pmap_addr_hint(vm_object_t obj, vm_offset_t addr, vm_size_t size); +void pmap_init2(void); + +#define pmap_resident_count(pm) ((pm)->pm_stats.resident_count) +#define pmap_wired_count(pm) ((pm)->pm_stats.wired_count) + +#endif /* _KERNEL */ +#endif /* _PMAP_VM_ */ diff --git a/src/include/vm/swap_pager.h b/src/include/vm/swap_pager.h new file mode 100644 index 0000000..61ace31 --- /dev/null +++ b/src/include/vm/swap_pager.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1990 University of Utah. + * Copyright (c) 1991 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + * 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. + * + * from: @(#)swap_pager.h 7.1 (Berkeley) 12/5/90 + * $FreeBSD: src/sys/vm/swap_pager.h,v 1.49 2004/04/06 20:15:36 imp Exp $ + */ + +#ifndef _VM_SWAP_PAGER_H_ +#define _VM_SWAP_PAGER_H_ 1 + +#ifdef _KERNEL + +extern int swap_pager_full; +extern int swap_pager_avail; + +struct swdevt; +void swap_pager_copy(vm_object_t, vm_object_t, vm_pindex_t, int); +void swap_pager_freespace(vm_object_t, vm_pindex_t, vm_size_t); +void swap_pager_swap_init(void); +int swap_pager_isswapped(vm_object_t, struct swdevt *); +int swap_pager_reserve(vm_object_t, vm_pindex_t, vm_size_t); +void swap_pager_status(int *total, int *used); + +#endif /* _KERNEL */ +#endif /* _VM_SWAP_PAGER_H_ */ diff --git a/src/include/vm/uma.h b/src/include/vm/uma.h new file mode 100644 index 0000000..56fe04b --- /dev/null +++ b/src/include/vm/uma.h @@ -0,0 +1,434 @@ +/* + * Copyright (c) 2002, Jeffrey Roberson + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/vm/uma.h,v 1.16 2003/09/19 08:37:44 jeff Exp $ + * + */ + +/* + * uma.h - External definitions for the Universal Memory Allocator + * +*/ + +#ifndef VM_UMA_H +#define VM_UMA_H + +#include /* For NULL */ +#include /* For M_* */ + +/* User visable parameters */ +#define UMA_SMALLEST_UNIT (PAGE_SIZE / 256) /* Smallest item allocated */ + +/* Types and type defs */ + +struct uma_zone; +/* Opaque type used as a handle to the zone */ +typedef struct uma_zone * uma_zone_t; + +/* + * Item constructor + * + * Arguments: + * item A pointer to the memory which has been allocated. + * arg The arg field passed to uma_zalloc_arg + * size The size of the allocated item + * + * Returns: + * Nothing + * + * Discussion: + * The constructor is called just before the memory is returned + * to the user. It may block if necessary. + */ +typedef void (*uma_ctor)(void *mem, int size, void *arg); + +/* + * Item destructor + * + * Arguments: + * item A pointer to the memory which has been allocated. + * size The size of the item being destructed. + * arg Argument passed through uma_zfree_arg + * + * Returns: + * Nothing + * + * Discussion: + * The destructor may perform operations that differ from those performed + * by the initializer, but it must leave the object in the same state. + * This IS type stable storage. This is called after EVERY zfree call. + */ +typedef void (*uma_dtor)(void *mem, int size, void *arg); + +/* + * Item initializer + * + * Arguments: + * item A pointer to the memory which has been allocated. + * size The size of the item being initialized. + * + * Returns: + * Nothing + * + * Discussion: + * The initializer is called when the memory is cached in the uma zone. + * this should be the same state that the destructor leaves the object in. + */ +typedef void (*uma_init)(void *mem, int size); + +/* + * Item discard function + * + * Arguments: + * item A pointer to memory which has been 'freed' but has not left the + * zone's cache. + * size The size of the item being discarded. + * + * Returns: + * Nothing + * + * Discussion: + * This routine is called when memory leaves a zone and is returned to the + * system for other uses. It is the counter part to the init function. + */ +typedef void (*uma_fini)(void *mem, int size); + +/* + * What's the difference between initializing and constructing? + * + * The item is initialized when it is cached, and this is the state that the + * object should be in when returned to the allocator. The purpose of this is + * to remove some code which would otherwise be called on each allocation by + * utilizing a known, stable state. This differs from the constructor which + * will be called on EVERY allocation. + * + * For example, in the initializer you may want to initialize embeded locks, + * NULL list pointers, set up initial states, magic numbers, etc. This way if + * the object is held in the allocator and re-used it won't be necessary to + * re-initialize it. + * + * The constructor may be used to lock a data structure, link it on to lists, + * bump reference counts or total counts of outstanding structures, etc. + * + */ + + +/* Function proto types */ + +/* + * Create a new uma zone + * + * Arguments: + * name The text name of the zone for debugging and stats, this memory + * should not be freed until the zone has been deallocated. + * size The size of the object that is being created. + * ctor The constructor that is called when the object is allocated + * dtor The destructor that is called when the object is freed. + * init An initializer that sets up the initial state of the memory. + * fini A discard function that undoes initialization done by init. + * ctor/dtor/init/fini may all be null, see notes above. + * align A bitmask that corisponds to the requested alignment + * eg 4 would be 0x3 + * flags A set of parameters that control the behavior of the zone + * + * Returns: + * A pointer to a structure which is intended to be opaque to users of + * the interface. The value may be null if the wait flag is not set. + */ + +uma_zone_t uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor, + uma_init uminit, uma_fini fini, int align, + u_int16_t flags); + +/* + * Definitions for uma_zcreate flags + * + * These flags share space with UMA_ZFLAGs in uma_int.h. Be careful not to + * overlap when adding new features. 0xf000 is in use by uma_int.h. + */ +#define UMA_ZONE_PAGEABLE 0x0001 /* Return items not fully backed by + physical memory XXX Not yet */ +#define UMA_ZONE_ZINIT 0x0002 /* Initialize with zeros */ +#define UMA_ZONE_STATIC 0x0004 /* Staticly sized zone */ +#define UMA_ZONE_OFFPAGE 0x0008 /* Force the slab structure allocation + off of the real memory */ +#define UMA_ZONE_MALLOC 0x0010 /* For use by malloc(9) only! */ +#define UMA_ZONE_NOFREE 0x0020 /* Do not free slabs of this type! */ +#define UMA_ZONE_MTXCLASS 0x0040 /* Create a new lock class */ +#define UMA_ZONE_VM 0x0080 /* + * Used for internal vm datastructures + * only. + */ +#define UMA_ZONE_HASH 0x0100 /* + * Use a hash table instead of caching + * information in the vm_page. + */ + +/* Definitions for align */ +#define UMA_ALIGN_PTR (sizeof(void *) - 1) /* Alignment fit for ptr */ +#define UMA_ALIGN_LONG (sizeof(long) - 1) /* "" long */ +#define UMA_ALIGN_INT (sizeof(int) - 1) /* "" int */ +#define UMA_ALIGN_SHORT (sizeof(short) - 1) /* "" short */ +#define UMA_ALIGN_CHAR (sizeof(char) - 1) /* "" char */ +#define UMA_ALIGN_CACHE (16 - 1) /* Cache line size align */ + +/* + * Destroys an empty uma zone. If the zone is not empty uma complains loudly. + * + * Arguments: + * zone The zone we want to destroy. + * + */ + +void uma_zdestroy(uma_zone_t zone); + +/* + * Allocates an item out of a zone + * + * Arguments: + * zone The zone we are allocating from + * arg This data is passed to the ctor function + * flags See sys/malloc.h for available flags. + * + * Returns: + * A non null pointer to an initialized element from the zone is + * garanteed if the wait flag is M_WAITOK, otherwise a null pointer may be + * returned if the zone is empty or the ctor failed. + */ + +void *uma_zalloc_arg(uma_zone_t zone, void *arg, int flags); + +/* + * Allocates an item out of a zone without supplying an argument + * + * This is just a wrapper for uma_zalloc_arg for convenience. + * + */ +static __inline void *uma_zalloc(uma_zone_t zone, int flags); + +static __inline void * +uma_zalloc(uma_zone_t zone, int flags) +{ + return uma_zalloc_arg(zone, NULL, flags); +} + +/* + * Frees an item back into the specified zone. + * + * Arguments: + * zone The zone the item was originally allocated out of. + * item The memory to be freed. + * arg Argument passed to the destructor + * + * Returns: + * Nothing. + */ + +void uma_zfree_arg(uma_zone_t zone, void *item, void *arg); + +/* + * Frees an item back to a zone without supplying an argument + * + * This is just a wrapper for uma_zfree_arg for convenience. + * + */ +static __inline void uma_zfree(uma_zone_t zone, void *item); + +static __inline void +uma_zfree(uma_zone_t zone, void *item) +{ + uma_zfree_arg(zone, item, NULL); +} + +/* + * XXX The rest of the prototypes in this header are h0h0 magic for the VM. + * If you think you need to use it for a normal zone you're probably incorrect. + */ + +/* + * Backend page supplier routines + * + * Arguments: + * zone The zone that is requesting pages + * size The number of bytes being requested + * pflag Flags for these memory pages, see below. + * wait Indicates our willingness to block. + * + * Returns: + * A pointer to the alloced memory or NULL on failure. + */ + +typedef void *(*uma_alloc)(uma_zone_t zone, int size, u_int8_t *pflag, int wait); + +/* + * Backend page free routines + * + * Arguments: + * item A pointer to the previously allocated pages + * size The original size of the allocation + * pflag The flags for the slab. See UMA_SLAB_* below + * + * Returns: + * None + */ +typedef void (*uma_free)(void *item, int size, u_int8_t pflag); + + + +/* + * Sets up the uma allocator. (Called by vm_mem_init) + * + * Arguments: + * bootmem A pointer to memory used to bootstrap the system. + * + * Returns: + * Nothing + * + * Discussion: + * This memory is used for zones which allocate things before the + * backend page supplier can give us pages. It should be + * UMA_SLAB_SIZE * UMA_BOOT_PAGES bytes. (see uma_int.h) + * + */ + +void uma_startup(void *bootmem); + +/* + * Finishes starting up the allocator. This should + * be called when kva is ready for normal allocs. + * + * Arguments: + * None + * + * Returns: + * Nothing + * + * Discussion: + * uma_startup2 is called by kmeminit() to enable us of uma for malloc. + */ + +void uma_startup2(void); + +/* + * Reclaims unused memory for all zones + * + * Arguments: + * None + * Returns: + * None + * + * This should only be called by the page out daemon. + */ + +void uma_reclaim(void); + +/* + * Switches the backing object of a zone + * + * Arguments: + * zone The zone to update + * obj The obj to use for future allocations + * size The size of the object to allocate + * + * Returns: + * 0 if kva space can not be allocated + * 1 if successful + * + * Discussion: + * A NULL object can be used and uma will allocate one for you. Setting + * the size will limit the amount of memory allocated to this zone. + * + */ +struct vm_object; +int uma_zone_set_obj(uma_zone_t zone, struct vm_object *obj, int size); + +/* + * Sets a high limit on the number of items allowed in a zone + * + * Arguments: + * zone The zone to limit + * + * Returns: + * Nothing + */ +void uma_zone_set_max(uma_zone_t zone, int nitems); + +/* + * Replaces the standard page_alloc or obj_alloc functions for this zone + * + * Arguments: + * zone The zone whos back end allocator is being changed. + * allocf A pointer to the allocation function + * + * Returns: + * Nothing + * + * Discussion: + * This could be used to implement pageable allocation, or perhaps + * even DMA allocators if used in conjunction with the OFFPAGE + * zone flag. + */ + +void uma_zone_set_allocf(uma_zone_t zone, uma_alloc allocf); + +/* + * Used for freeing memory provided by the allocf above + * + * Arguments: + * zone The zone that intends to use this free routine. + * freef The page freeing routine. + * + * Returns: + * Nothing + */ + +void uma_zone_set_freef(uma_zone_t zone, uma_free freef); + +/* + * These flags are setable in the allocf and visable in the freef. + */ +#define UMA_SLAB_BOOT 0x01 /* Slab alloced from boot pages */ +#define UMA_SLAB_KMEM 0x02 /* Slab alloced from kmem_map */ +#define UMA_SLAB_PRIV 0x08 /* Slab alloced from priv allocator */ +#define UMA_SLAB_OFFP 0x10 /* Slab is managed separately */ +#define UMA_SLAB_MALLOC 0x20 /* Slab is a large malloc slab */ +/* 0x40 and 0x80 are available */ + +/* + * Used to pre-fill a zone with some number of items + * + * Arguments: + * zone The zone to fill + * itemcnt The number of items to reserve + * + * Returns: + * Nothing + * + * NOTE: This is blocking and should only be done at startup + */ +void uma_prealloc(uma_zone_t zone, int itemcnt); + + +#endif diff --git a/src/include/vm/uma_dbg.h b/src/include/vm/uma_dbg.h new file mode 100644 index 0000000..99fd7a4 --- /dev/null +++ b/src/include/vm/uma_dbg.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2002, Jeffrey Roberson + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/vm/uma_dbg.h,v 1.4 2002/09/19 06:05:32 jeff Exp $ + * + */ + +/* + * + * This file includes definitions, structures, prototypes, and inlines used + * when debugging users of the UMA interface. + * + */ + +#ifndef VM_UMA_DBG_H +#define VM_UMA_DBG_H + +void trash_ctor(void *mem, int size, void *arg); +void trash_dtor(void *mem, int size, void *arg); +void trash_init(void *mem, int size); +void trash_fini(void *mem, int size); + +/* For use only by malloc */ +void mtrash_ctor(void *mem, int size, void *arg); +void mtrash_dtor(void *mem, int size, void *arg); +void mtrash_init(void *mem, int size); +void mtrash_fini(void *mem, int size); + +void uma_dbg_free(uma_zone_t zone, uma_slab_t slab, void *item); +void uma_dbg_alloc(uma_zone_t zone, uma_slab_t slab, void *item); + +#endif /* VM_UMA_DBG_H */ diff --git a/src/include/vm/uma_int.h b/src/include/vm/uma_int.h new file mode 100644 index 0000000..b3b4202 --- /dev/null +++ b/src/include/vm/uma_int.h @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2002, Jeffrey Roberson + * 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 unmodified, 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/sys/vm/uma_int.h,v 1.23 2004/01/18 05:51:06 alc Exp $ + * + */ + +/* + * This file includes definitions, structures, prototypes, and inlines that + * should not be used outside of the actual implementation of UMA. + */ + +/* + * Here's a quick description of the relationship between the objects: + * + * Zones contain lists of slabs which are stored in either the full bin, empty + * bin, or partially allocated bin, to reduce fragmentation. They also contain + * the user supplied value for size, which is adjusted for alignment purposes + * and rsize is the result of that. The zone also stores information for + * managing a hash of page addresses that maps pages to uma_slab_t structures + * for pages that don't have embedded uma_slab_t's. + * + * The uma_slab_t may be embedded in a UMA_SLAB_SIZE chunk of memory or it may + * be allocated off the page from a special slab zone. The free list within a + * slab is managed with a linked list of indexes, which are 8 bit values. If + * UMA_SLAB_SIZE is defined to be too large I will have to switch to 16bit + * values. Currently on alpha you can get 250 or so 32 byte items and on x86 + * you can get 250 or so 16byte items. For item sizes that would yield more + * than 10% memory waste we potentially allocate a separate uma_slab_t if this + * will improve the number of items per slab that will fit. + * + * Other potential space optimizations are storing the 8bit of linkage in space + * wasted between items due to alignment problems. This may yield a much better + * memory footprint for certain sizes of objects. Another alternative is to + * increase the UMA_SLAB_SIZE, or allow for dynamic slab sizes. I prefer + * dynamic slab sizes because we could stick with 8 bit indexes and only use + * large slab sizes for zones with a lot of waste per slab. This may create + * ineffeciencies in the vm subsystem due to fragmentation in the address space. + * + * The only really gross cases, with regards to memory waste, are for those + * items that are just over half the page size. You can get nearly 50% waste, + * so you fall back to the memory footprint of the power of two allocator. I + * have looked at memory allocation sizes on many of the machines available to + * me, and there does not seem to be an abundance of allocations at this range + * so at this time it may not make sense to optimize for it. This can, of + * course, be solved with dynamic slab sizes. + * + */ + +/* + * This is the representation for normal (Non OFFPAGE slab) + * + * i == item + * s == slab pointer + * + * <---------------- Page (UMA_SLAB_SIZE) ------------------> + * ___________________________________________________________ + * | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ | + * ||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i| |slab header|| + * ||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_| |___________|| + * |___________________________________________________________| + * + * + * This is an OFFPAGE slab. These can be larger than UMA_SLAB_SIZE. + * + * ___________________________________________________________ + * | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | + * ||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i| | + * ||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_| | + * |___________________________________________________________| + * ___________ ^ + * |slab header| | + * |___________|---* + * + */ + +#ifndef VM_UMA_INT_H +#define VM_UMA_INT_H + +#define UMA_SLAB_SIZE PAGE_SIZE /* How big are our slabs? */ +#define UMA_SLAB_MASK (PAGE_SIZE - 1) /* Mask to get back to the page */ +#define UMA_SLAB_SHIFT PAGE_SHIFT /* Number of bits PAGE_MASK */ + +#define UMA_BOOT_PAGES 40 /* Pages allocated for startup */ + +/* Max waste before going to off page slab management */ +#define UMA_MAX_WASTE (UMA_SLAB_SIZE / 10) + +/* + * I doubt there will be many cases where this is exceeded. This is the initial + * size of the hash table for uma_slabs that are managed off page. This hash + * does expand by powers of two. Currently it doesn't get smaller. + */ +#define UMA_HASH_SIZE_INIT 32 + +/* + * I should investigate other hashing algorithms. This should yield a low + * number of collisions if the pages are relatively contiguous. + * + * This is the same algorithm that most processor caches use. + * + * I'm shifting and masking instead of % because it should be faster. + */ + +#define UMA_HASH(h, s) ((((unsigned long)s) >> UMA_SLAB_SHIFT) & \ + (h)->uh_hashmask) + +#define UMA_HASH_INSERT(h, s, mem) \ + SLIST_INSERT_HEAD(&(h)->uh_slab_hash[UMA_HASH((h), \ + (mem))], (s), us_hlink); +#define UMA_HASH_REMOVE(h, s, mem) \ + SLIST_REMOVE(&(h)->uh_slab_hash[UMA_HASH((h), \ + (mem))], (s), uma_slab, us_hlink); + +/* Page management structure */ + +/* Sorry for the union, but space efficiency is important */ +struct uma_slab { + uma_zone_t us_zone; /* Zone we live in */ + union { + LIST_ENTRY(uma_slab) _us_link; /* slabs in zone */ + unsigned long _us_size; /* Size of allocation */ + } us_type; + SLIST_ENTRY(uma_slab) us_hlink; /* Link for hash table */ + u_int8_t *us_data; /* First item */ + u_int8_t us_flags; /* Page flags see uma.h */ + u_int8_t us_freecount; /* How many are free? */ + u_int8_t us_firstfree; /* First free item index */ + u_int8_t us_freelist[1]; /* Free List (actually larger) */ +}; + +#define us_link us_type._us_link +#define us_size us_type._us_size + +typedef struct uma_slab * uma_slab_t; + +/* Hash table for freed address -> slab translation */ + +SLIST_HEAD(slabhead, uma_slab); + +struct uma_hash { + struct slabhead *uh_slab_hash; /* Hash table for slabs */ + int uh_hashsize; /* Current size of the hash table */ + int uh_hashmask; /* Mask used during hashing */ +}; + +/* + * Structures for per cpu queues. + */ + +struct uma_bucket { + LIST_ENTRY(uma_bucket) ub_link; /* Link into the zone */ + int16_t ub_cnt; /* Count of free items. */ + int16_t ub_entries; /* Max items. */ + void *ub_bucket[]; /* actual allocation storage */ +}; + +typedef struct uma_bucket * uma_bucket_t; + +struct uma_cache { + uma_bucket_t uc_freebucket; /* Bucket we're freeing to */ + uma_bucket_t uc_allocbucket; /* Bucket to allocate from */ + u_int64_t uc_allocs; /* Count of allocations */ +}; + +typedef struct uma_cache * uma_cache_t; + +/* + * Zone management structure + * + * TODO: Optimize for cache line size + * + */ +struct uma_zone { + char *uz_name; /* Text name of the zone */ + LIST_ENTRY(uma_zone) uz_link; /* List of all zones */ + u_int32_t uz_align; /* Alignment mask */ + u_int32_t uz_pages; /* Total page count */ + +/* Used during alloc / free */ + struct mtx uz_lock; /* Lock for the zone */ + u_int32_t uz_free; /* Count of items free in slabs */ + u_int16_t uz_ipers; /* Items per slab */ + u_int16_t uz_flags; /* Internal flags */ + + LIST_HEAD(,uma_slab) uz_part_slab; /* partially allocated slabs */ + LIST_HEAD(,uma_slab) uz_free_slab; /* empty slab list */ + LIST_HEAD(,uma_slab) uz_full_slab; /* full slabs */ + LIST_HEAD(,uma_bucket) uz_full_bucket; /* full buckets */ + LIST_HEAD(,uma_bucket) uz_free_bucket; /* Buckets for frees */ + u_int32_t uz_size; /* Requested size of each item */ + u_int32_t uz_rsize; /* Real size of each item */ + + struct uma_hash uz_hash; + u_int16_t uz_pgoff; /* Offset to uma_slab struct */ + u_int16_t uz_ppera; /* pages per allocation from backend */ + + uma_ctor uz_ctor; /* Constructor for each allocation */ + uma_dtor uz_dtor; /* Destructor */ + u_int64_t uz_allocs; /* Total number of allocations */ + + uma_init uz_init; /* Initializer for each item */ + uma_fini uz_fini; /* Discards memory */ + uma_alloc uz_allocf; /* Allocation function */ + uma_free uz_freef; /* Free routine */ + struct vm_object *uz_obj; /* Zone specific object */ + vm_offset_t uz_kva; /* Base kva for zones with objs */ + u_int32_t uz_maxpages; /* Maximum number of pages to alloc */ + int uz_recurse; /* Allocation recursion count */ + uint16_t uz_fills; /* Outstanding bucket fills */ + uint16_t uz_count; /* Highest value ub_ptr can have */ + /* + * This HAS to be the last item because we adjust the zone size + * based on NCPU and then allocate the space for the zones. + */ + struct uma_cache uz_cpu[1]; /* Per cpu caches */ +}; + +/* + * These flags must not overlap with the UMA_ZONE flags specified in uma.h. + */ +#define UMA_ZFLAG_PRIVALLOC 0x1000 /* Use uz_allocf. */ +#define UMA_ZFLAG_INTERNAL 0x2000 /* No offpage no PCPU. */ +#define UMA_ZFLAG_FULL 0x4000 /* Reached uz_maxpages */ +#define UMA_ZFLAG_CACHEONLY 0x8000 /* Don't ask VM for buckets. */ + +/* Internal prototypes */ +static __inline uma_slab_t hash_sfind(struct uma_hash *hash, u_int8_t *data); +void *uma_large_malloc(int size, int wait); +void uma_large_free(uma_slab_t slab); + +/* Lock Macros */ + +#define ZONE_LOCK_INIT(z, lc) \ + do { \ + if ((lc)) \ + mtx_init(&(z)->uz_lock, (z)->uz_name, \ + (z)->uz_name, MTX_DEF | MTX_DUPOK); \ + else \ + mtx_init(&(z)->uz_lock, (z)->uz_name, \ + "UMA zone", MTX_DEF | MTX_DUPOK); \ + } while (0) + +#define ZONE_LOCK_FINI(z) mtx_destroy(&(z)->uz_lock) +#define ZONE_LOCK(z) mtx_lock(&(z)->uz_lock) +#define ZONE_UNLOCK(z) mtx_unlock(&(z)->uz_lock) + +#define CPU_LOCK_INIT(cpu) \ + mtx_init(&uma_pcpu_mtx[(cpu)], "UMA pcpu", "UMA pcpu", \ + MTX_DEF | MTX_DUPOK) + +#define CPU_LOCK(cpu) \ + mtx_lock(&uma_pcpu_mtx[(cpu)]) + +#define CPU_UNLOCK(cpu) \ + mtx_unlock(&uma_pcpu_mtx[(cpu)]) + +/* + * Find a slab within a hash table. This is used for OFFPAGE zones to lookup + * the slab structure. + * + * Arguments: + * hash The hash table to search. + * data The base page of the item. + * + * Returns: + * A pointer to a slab if successful, else NULL. + */ +static __inline uma_slab_t +hash_sfind(struct uma_hash *hash, u_int8_t *data) +{ + uma_slab_t slab; + int hval; + + hval = UMA_HASH(hash, data); + + SLIST_FOREACH(slab, &hash->uh_slab_hash[hval], us_hlink) { + if ((u_int8_t *)slab->us_data == data) + return (slab); + } + return (NULL); +} + +static __inline uma_slab_t +vtoslab(vm_offset_t va) +{ + vm_page_t p; + uma_slab_t slab; + + p = PHYS_TO_VM_PAGE(pmap_kextract(va)); + slab = (uma_slab_t )p->object; + + if (p->flags & PG_SLAB) + return (slab); + else + return (NULL); +} + +static __inline void +vsetslab(vm_offset_t va, uma_slab_t slab) +{ + vm_page_t p; + + p = PHYS_TO_VM_PAGE(pmap_kextract((vm_offset_t)va)); + p->object = (vm_object_t)slab; + p->flags |= PG_SLAB; +} + +static __inline void +vsetobj(vm_offset_t va, vm_object_t obj) +{ + vm_page_t p; + + p = PHYS_TO_VM_PAGE(pmap_kextract((vm_offset_t)va)); + p->object = obj; + p->flags &= ~PG_SLAB; +} + +/* + * The following two functions may be defined by architecture specific code + * if they can provide more effecient allocation functions. This is useful + * for using direct mapped addresses. + */ +void *uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait); +void uma_small_free(void *mem, int size, u_int8_t flags); + +#endif /* VM_UMA_INT_H */ diff --git a/src/include/vm/vm.h b/src/include/vm/vm.h new file mode 100644 index 0000000..71004a3 --- /dev/null +++ b/src/include/vm/vm.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 1991, 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. + * 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. + * + * @(#)vm.h 8.2 (Berkeley) 12/13/93 + * @(#)vm_prot.h 8.1 (Berkeley) 6/11/93 + * @(#)vm_inherit.h 8.1 (Berkeley) 6/11/93 + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Authors: Avadis Tevanian, Jr., Michael Wayne Young + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/vm.h,v 1.23 2004/04/06 20:15:36 imp Exp $ + */ + +#ifndef VM_H +#define VM_H + +typedef char vm_inherit_t; /* inheritance codes */ + +#define VM_INHERIT_SHARE ((vm_inherit_t) 0) +#define VM_INHERIT_COPY ((vm_inherit_t) 1) +#define VM_INHERIT_NONE ((vm_inherit_t) 2) +#define VM_INHERIT_DEFAULT VM_INHERIT_COPY + +typedef u_char vm_prot_t; /* protection codes */ + +#define VM_PROT_NONE ((vm_prot_t) 0x00) +#define VM_PROT_READ ((vm_prot_t) 0x01) +#define VM_PROT_WRITE ((vm_prot_t) 0x02) +#define VM_PROT_EXECUTE ((vm_prot_t) 0x04) +#define VM_PROT_OVERRIDE_WRITE ((vm_prot_t) 0x08) /* copy-on-write */ + +#define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) +#define VM_PROT_RW (VM_PROT_READ|VM_PROT_WRITE) +#define VM_PROT_DEFAULT VM_PROT_ALL + +union vm_map_object; +typedef union vm_map_object vm_map_object_t; + +struct vm_map_entry; +typedef struct vm_map_entry *vm_map_entry_t; + +struct vm_map; +typedef struct vm_map *vm_map_t; + +struct vm_object; +typedef struct vm_object *vm_object_t; + +#ifndef _KERNEL +/* + * This is defined in for the kernel so that non-vm kernel + * sources (mainly Mach-derived ones such as ddb) don't have to include + * vm stuff. Defining it there for applications might break things. + * Define it here for "applications" that include vm headers (e.g., + * genassym). + */ +typedef int boolean_t; + +/* + * This is defined in for the kernel so that vnode_if.h + * doesn't have to include . + */ +struct vm_page; +typedef struct vm_page *vm_page_t; +#endif /* _KERNEL */ + +/* + * Information passed from the machine-independant VM initialization code + * for use by machine-dependant code (mainly for MMU support) + */ +struct kva_md_info { + vm_offset_t buffer_sva; + vm_offset_t buffer_eva; + vm_offset_t clean_sva; + vm_offset_t clean_eva; + vm_offset_t pager_sva; + vm_offset_t pager_eva; +}; + +extern struct kva_md_info kmi; +extern void vm_ksubmap_init(struct kva_md_info *); + +#endif /* VM_H */ + diff --git a/src/include/vm/vm_extern.h b/src/include/vm/vm_extern.h new file mode 100644 index 0000000..8de87d3 --- /dev/null +++ b/src/include/vm/vm_extern.h @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 1992, 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. + * 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. + * + * @(#)vm_extern.h 8.2 (Berkeley) 1/12/94 + * $FreeBSD: src/sys/vm/vm_extern.h,v 1.72 2004/04/06 20:15:36 imp Exp $ + */ + +#ifndef _VM_EXTERN_H_ +#define _VM_EXTERN_H_ + +struct buf; +struct proc; +struct vmspace; +struct vmtotal; +struct mount; +struct vnode; + +#ifdef _KERNEL + +#ifdef TYPEDEF_FOR_UAP +int getpagesize(struct thread *, void *, int *); +int madvise(struct thread *, void *, int *); +int mincore(struct thread *, void *, int *); +int mprotect(struct thread *, void *, int *); +int msync(struct thread *, void *, int *); +int munmap(struct thread *, void *, int *); +int obreak(struct thread *, void *, int *); +int sbrk(struct thread *, void *, int *); +int sstk(struct thread *, void *, int *); +int swapon(struct thread *, void *, int *); +#endif /* TYPEDEF_FOR_UAP */ + +int kernacc(void *, int, int); +vm_offset_t kmem_alloc(vm_map_t, vm_size_t); +vm_offset_t kmem_alloc_nofault(vm_map_t, vm_size_t); +vm_offset_t kmem_alloc_pageable(vm_map_t, vm_size_t); +vm_offset_t kmem_alloc_wait(vm_map_t, vm_size_t); +void kmem_free(vm_map_t, vm_offset_t, vm_size_t); +void kmem_free_wakeup(vm_map_t, vm_offset_t, vm_size_t); +void kmem_init(vm_offset_t, vm_offset_t); +vm_offset_t kmem_malloc(vm_map_t, vm_size_t, boolean_t); +vm_map_t kmem_suballoc(vm_map_t, vm_offset_t *, vm_offset_t *, vm_size_t); +void swapout_procs(int); +int useracc(void *, int, int); +int vm_fault(vm_map_t, vm_offset_t, vm_prot_t, int); +void vm_fault_copy_entry(vm_map_t, vm_map_t, vm_map_entry_t, vm_map_entry_t); +void vm_fault_unwire(vm_map_t, vm_offset_t, vm_offset_t); +int vm_fault_wire(vm_map_t, vm_offset_t, vm_offset_t, boolean_t); +void vm_forkproc(struct thread *, struct proc *, struct thread *, int); +void vm_waitproc(struct proc *); +int vm_mmap(vm_map_t, vm_offset_t *, vm_size_t, vm_prot_t, vm_prot_t, int, void *, vm_ooffset_t); +void vm_set_page_size(void); +struct vmspace *vmspace_alloc(vm_offset_t, vm_offset_t); +struct vmspace *vmspace_fork(struct vmspace *); +void vmspace_exec(struct proc *, vm_offset_t, vm_offset_t); +void vmspace_unshare(struct proc *); +void vmspace_free(struct vmspace *); +void vmspace_exitfree(struct proc *); +void vnode_pager_setsize(struct vnode *, vm_ooffset_t); +int vslock(void *, size_t); +void vsunlock(void *, size_t); +void vm_object_print(/* db_expr_t */ long, boolean_t, /* db_expr_t */ long, + char *); +int vm_fault_quick(caddr_t v, int prot); +void vm_proc_new(struct proc *p); +void vm_proc_dispose(struct proc *p); +void vm_thread_dispose(struct thread *td); +void vm_thread_dispose_altkstack(struct thread *td); +void vm_thread_new(struct thread *td, int pages); +void vm_thread_new_altkstack(struct thread *td, int pages); +void vm_thread_swapin(struct thread *td); +void vm_thread_swapout(struct thread *td); +#endif /* _KERNEL */ +#endif /* !_VM_EXTERN_H_ */ diff --git a/src/include/vm/vm_kern.h b/src/include/vm/vm_kern.h new file mode 100644 index 0000000..22b8e37 --- /dev/null +++ b/src/include/vm/vm_kern.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * from: @(#)vm_kern.h 8.1 (Berkeley) 6/11/93 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Authors: Avadis Tevanian, Jr., Michael Wayne Young + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/vm_kern.h,v 1.27 2004/04/06 20:15:36 imp Exp $ + */ + +#ifndef _VM_VM_KERN_H_ +#define _VM_VM_KERN_H_ 1 + +/* Kernel memory management definitions. */ +extern vm_map_t buffer_map; +extern vm_map_t kernel_map; +extern vm_map_t kmem_map; +extern vm_map_t clean_map; +extern vm_map_t exec_map; +extern vm_map_t pipe_map; +extern u_int vm_kmem_size; + +#endif /* _VM_VM_KERN_H_ */ diff --git a/src/include/vm/vm_map.h b/src/include/vm/vm_map.h new file mode 100644 index 0000000..cd0763b --- /dev/null +++ b/src/include/vm/vm_map.h @@ -0,0 +1,354 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * @(#)vm_map.h 8.9 (Berkeley) 5/17/95 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Authors: Avadis Tevanian, Jr., Michael Wayne Young + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/vm_map.h,v 1.109 2004/04/24 03:46:44 alc Exp $ + */ + +/* + * Virtual memory map module definitions. + */ +#ifndef _VM_MAP_ +#define _VM_MAP_ + +#include +#include +#include + +/* + * Types defined: + * + * vm_map_t the high-level address map data structure. + * vm_map_entry_t an entry in an address map. + */ + +typedef u_char vm_flags_t; +typedef u_int vm_eflags_t; + +/* + * Objects which live in maps may be either VM objects, or + * another map (called a "sharing map") which denotes read-write + * sharing with other maps. + */ +union vm_map_object { + struct vm_object *vm_object; /* object object */ + struct vm_map *sub_map; /* belongs to another map */ +}; + +/* + * Address map entries consist of start and end addresses, + * a VM object (or sharing map) and offset into that object, + * and user-exported inheritance and protection information. + * Also included is control information for virtual copy operations. + */ +struct vm_map_entry { + struct vm_map_entry *prev; /* previous entry */ + struct vm_map_entry *next; /* next entry */ + struct vm_map_entry *left; /* left child in binary search tree */ + struct vm_map_entry *right; /* right child in binary search tree */ + vm_offset_t start; /* start address */ + vm_offset_t end; /* end address */ + vm_offset_t avail_ssize; /* amt can grow if this is a stack */ + union vm_map_object object; /* object I point to */ + vm_ooffset_t offset; /* offset into object */ + vm_eflags_t eflags; /* map entry flags */ + /* Only in task maps: */ + vm_prot_t protection; /* protection code */ + vm_prot_t max_protection; /* maximum protection */ + vm_inherit_t inheritance; /* inheritance */ + int wired_count; /* can be paged if = 0 */ + vm_pindex_t lastr; /* last read */ +}; + +#define MAP_ENTRY_NOSYNC 0x0001 +#define MAP_ENTRY_IS_SUB_MAP 0x0002 +#define MAP_ENTRY_COW 0x0004 +#define MAP_ENTRY_NEEDS_COPY 0x0008 +#define MAP_ENTRY_NOFAULT 0x0010 +#define MAP_ENTRY_USER_WIRED 0x0020 + +#define MAP_ENTRY_BEHAV_NORMAL 0x0000 /* default behavior */ +#define MAP_ENTRY_BEHAV_SEQUENTIAL 0x0040 /* expect sequential access */ +#define MAP_ENTRY_BEHAV_RANDOM 0x0080 /* expect random access */ +#define MAP_ENTRY_BEHAV_RESERVED 0x00C0 /* future use */ + +#define MAP_ENTRY_BEHAV_MASK 0x00C0 + +#define MAP_ENTRY_IN_TRANSITION 0x0100 /* entry being changed */ +#define MAP_ENTRY_NEEDS_WAKEUP 0x0200 /* waiters in transition */ +#define MAP_ENTRY_NOCOREDUMP 0x0400 /* don't include in a core */ + +#define MAP_ENTRY_GROWS_DOWN 0x1000 /* Top-down stacks */ +#define MAP_ENTRY_GROWS_UP 0x2000 /* Bottom-up stacks */ + +#ifdef _KERNEL +static __inline u_char +vm_map_entry_behavior(vm_map_entry_t entry) +{ + return (entry->eflags & MAP_ENTRY_BEHAV_MASK); +} +#endif /* _KERNEL */ + +/* + * A map is a set of map entries. These map entries are + * organized both as a binary search tree and as a doubly-linked + * list. Both structures are ordered based upon the start and + * end addresses contained within each map entry. Sleator and + * Tarjan's top-down splay algorithm is employed to control + * height imbalance in the binary search tree. + * + * Note: the lock structure cannot be the first element of vm_map + * because this can result in a running lockup between two or more + * system processes trying to kmem_alloc_wait() due to kmem_alloc_wait() + * and free tsleep/waking up 'map' and the underlying lockmgr also + * sleeping and waking up on 'map'. The lockup occurs when the map fills + * up. The 'exec' map, for example. + * + * List of locks + * (c) const until freed + */ +struct vm_map { + struct vm_map_entry header; /* List of entries */ + struct lock lock; /* Lock for map data */ + struct mtx system_mtx; + int nentries; /* Number of entries */ + vm_size_t size; /* virtual size */ + u_int timestamp; /* Version number */ + u_char needs_wakeup; + u_char system_map; /* Am I a system map? */ + u_char infork; /* Am I in fork processing? */ + vm_flags_t flags; /* flags for this vm_map */ + vm_map_entry_t root; /* Root of a binary search tree */ + vm_map_entry_t first_free; /* First free space hint */ + pmap_t pmap; /* (c) Physical map */ +#define min_offset header.start /* (c) */ +#define max_offset header.end /* (c) */ +}; + +/* + * vm_flags_t values + */ +#define MAP_WIREFUTURE 0x01 /* wire all future pages */ + +#ifdef _KERNEL +static __inline vm_offset_t +vm_map_max(vm_map_t map) +{ + return (map->max_offset); +} + +static __inline vm_offset_t +vm_map_min(vm_map_t map) +{ + return (map->min_offset); +} + +static __inline pmap_t +vm_map_pmap(vm_map_t map) +{ + return (map->pmap); +} + +static __inline void +vm_map_modflags(vm_map_t map, vm_flags_t set, vm_flags_t clear) +{ + map->flags = (map->flags | set) & ~clear; +} +#endif /* _KERNEL */ + +/* + * Shareable process virtual address space. + * + * List of locks + * (c) const until freed + */ +struct vmspace { + struct vm_map vm_map; /* VM address map */ + struct pmap vm_pmap; /* private physical map */ + int vm_refcnt; /* number of references */ + struct shmmap_state *vm_shm; /* SYS5 shared memory private data XXX */ +/* we copy between vm_startcopy and vm_endcopy on fork */ +#define vm_startcopy vm_rssize + segsz_t vm_rssize; /* current resident set size in pages */ + segsz_t vm_swrss; /* resident set size before last swap */ + segsz_t vm_tsize; /* text size (pages) XXX */ + segsz_t vm_dsize; /* data size (pages) XXX */ + segsz_t vm_ssize; /* stack size (pages) */ + caddr_t vm_taddr; /* (c) user virtual address of text */ + caddr_t vm_daddr; /* (c) user virtual address of data */ + caddr_t vm_maxsaddr; /* user VA at max stack growth */ +#define vm_endcopy vm_exitingcnt + int vm_exitingcnt; /* several processes zombied in exit1 */ +}; + +#ifdef _KERNEL +static __inline pmap_t +vmspace_pmap(struct vmspace *vmspace) +{ + return &vmspace->vm_pmap; +} +#endif /* _KERNEL */ + +#ifdef _KERNEL +/* + * Macros: vm_map_lock, etc. + * Function: + * Perform locking on the data portion of a map. Note that + * these macros mimic procedure calls returning void. The + * semicolon is supplied by the user of these macros, not + * by the macros themselves. The macros can safely be used + * as unbraced elements in a higher level statement. + */ + +void _vm_map_lock(vm_map_t map, const char *file, int line); +void _vm_map_unlock(vm_map_t map, const char *file, int line); +void _vm_map_lock_read(vm_map_t map, const char *file, int line); +void _vm_map_unlock_read(vm_map_t map, const char *file, int line); +int _vm_map_trylock(vm_map_t map, const char *file, int line); +int _vm_map_trylock_read(vm_map_t map, const char *file, int line); +int _vm_map_lock_upgrade(vm_map_t map, const char *file, int line); +void _vm_map_lock_downgrade(vm_map_t map, const char *file, int line); +int vm_map_unlock_and_wait(vm_map_t map, boolean_t user_wait); +void vm_map_wakeup(vm_map_t map); + +#define vm_map_lock(map) _vm_map_lock(map, LOCK_FILE, LOCK_LINE) +#define vm_map_unlock(map) _vm_map_unlock(map, LOCK_FILE, LOCK_LINE) +#define vm_map_lock_read(map) _vm_map_lock_read(map, LOCK_FILE, LOCK_LINE) +#define vm_map_unlock_read(map) _vm_map_unlock_read(map, LOCK_FILE, LOCK_LINE) +#define vm_map_trylock(map) _vm_map_trylock(map, LOCK_FILE, LOCK_LINE) +#define vm_map_trylock_read(map) \ + _vm_map_trylock_read(map, LOCK_FILE, LOCK_LINE) +#define vm_map_lock_upgrade(map) \ + _vm_map_lock_upgrade(map, LOCK_FILE, LOCK_LINE) +#define vm_map_lock_downgrade(map) \ + _vm_map_lock_downgrade(map, LOCK_FILE, LOCK_LINE) + +long vmspace_resident_count(struct vmspace *vmspace); +long vmspace_wired_count(struct vmspace *vmspace); +#endif /* _KERNEL */ + + +/* XXX: number of kernel maps and entries to statically allocate */ +#define MAX_KMAP 10 +#define MAX_KMAPENT 128 +#define MAX_MAPENT 128 + +/* + * Copy-on-write flags for vm_map operations + */ +#define MAP_UNUSED_01 0x0001 +#define MAP_COPY_ON_WRITE 0x0002 +#define MAP_NOFAULT 0x0004 +#define MAP_PREFAULT 0x0008 +#define MAP_PREFAULT_PARTIAL 0x0010 +#define MAP_DISABLE_SYNCER 0x0020 +#define MAP_DISABLE_COREDUMP 0x0100 +#define MAP_PREFAULT_MADVISE 0x0200 /* from (user) madvise request */ +#define MAP_STACK_GROWS_DOWN 0x1000 +#define MAP_STACK_GROWS_UP 0x2000 + +/* + * vm_fault option flags + */ +#define VM_FAULT_NORMAL 0 /* Nothing special */ +#define VM_FAULT_CHANGE_WIRING 1 /* Change the wiring as appropriate */ +#define VM_FAULT_USER_WIRE 2 /* Likewise, but for user purposes */ +#define VM_FAULT_WIRE_MASK (VM_FAULT_CHANGE_WIRING|VM_FAULT_USER_WIRE) +#define VM_FAULT_DIRTY 8 /* Dirty the page */ + +/* + * vm_map_wire and vm_map_unwire option flags + */ +#define VM_MAP_WIRE_SYSTEM 0 /* wiring in a kernel map */ +#define VM_MAP_WIRE_USER 1 /* wiring in a user map */ + +#define VM_MAP_WIRE_NOHOLES 0 /* region must not have holes */ +#define VM_MAP_WIRE_HOLESOK 2 /* region may have holes */ + +#ifdef _KERNEL +boolean_t vm_map_check_protection (vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t); +vm_map_t vm_map_create(pmap_t, vm_offset_t, vm_offset_t); +int vm_map_delete (vm_map_t, vm_offset_t, vm_offset_t); +int vm_map_find (vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, boolean_t, vm_prot_t, vm_prot_t, int); +int vm_map_findspace (vm_map_t, vm_offset_t, vm_size_t, vm_offset_t *); +int vm_map_inherit (vm_map_t, vm_offset_t, vm_offset_t, vm_inherit_t); +void vm_map_init (struct vm_map *, vm_offset_t, vm_offset_t); +int vm_map_insert (vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t, vm_offset_t, vm_prot_t, vm_prot_t, int); +int vm_map_lookup (vm_map_t *, vm_offset_t, vm_prot_t, vm_map_entry_t *, vm_object_t *, + vm_pindex_t *, vm_prot_t *, boolean_t *); +void vm_map_lookup_done (vm_map_t, vm_map_entry_t); +boolean_t vm_map_lookup_entry (vm_map_t, vm_offset_t, vm_map_entry_t *); +void vm_map_pmap_enter(vm_map_t map, vm_offset_t addr, vm_prot_t prot, + vm_object_t object, vm_pindex_t pindex, vm_size_t size, int flags); +int vm_map_protect (vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t, boolean_t); +int vm_map_remove (vm_map_t, vm_offset_t, vm_offset_t); +void vm_map_startup (void); +int vm_map_submap (vm_map_t, vm_offset_t, vm_offset_t, vm_map_t); +int vm_map_sync(vm_map_t, vm_offset_t, vm_offset_t, boolean_t, boolean_t); +int vm_map_madvise (vm_map_t, vm_offset_t, vm_offset_t, int); +void vm_map_simplify_entry (vm_map_t, vm_map_entry_t); +void vm_init2 (void); +int vm_map_stack (vm_map_t, vm_offset_t, vm_size_t, vm_prot_t, vm_prot_t, int); +int vm_map_growstack (struct proc *p, vm_offset_t addr); +int vm_map_unwire(vm_map_t map, vm_offset_t start, vm_offset_t end, + int flags); +int vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t end, + int flags); +int vmspace_swap_count (struct vmspace *vmspace); +#endif /* _KERNEL */ +#endif /* _VM_MAP_ */ diff --git a/src/include/vm/vm_object.h b/src/include/vm/vm_object.h new file mode 100644 index 0000000..a9f4fef --- /dev/null +++ b/src/include/vm/vm_object.h @@ -0,0 +1,220 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * from: @(#)vm_object.h 8.3 (Berkeley) 1/12/94 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Authors: Avadis Tevanian, Jr., Michael Wayne Young + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/vm_object.h,v 1.104 2004/04/06 20:15:37 imp Exp $ + */ + +/* + * Virtual memory object module definitions. + */ + +#ifndef _VM_OBJECT_ +#define _VM_OBJECT_ + +#include +#include +#include + +enum obj_type { OBJT_DEFAULT, OBJT_SWAP, OBJT_VNODE, OBJT_DEVICE, OBJT_PHYS, + OBJT_DEAD }; +typedef u_char objtype_t; + +/* + * Types defined: + * + * vm_object_t Virtual memory object. + * + * List of locks + * (c) const until freed + * + */ + +struct vm_object { + struct mtx mtx; + TAILQ_ENTRY(vm_object) object_list; /* list of all objects */ + LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */ + LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */ + TAILQ_HEAD(, vm_page) memq; /* list of resident pages */ + vm_page_t root; /* root of the resident page splay tree */ + vm_pindex_t size; /* Object size */ + int generation; /* generation ID */ + int ref_count; /* How many refs?? */ + int shadow_count; /* how many objects that this is a shadow for */ + objtype_t type; /* type of pager */ + u_short flags; /* see below */ + u_short pg_color; /* (c) color of first page in obj */ + u_short paging_in_progress; /* Paging (in or out) so don't collapse or destroy */ + int resident_page_count; /* number of resident pages */ + struct vm_object *backing_object; /* object that I'm a shadow of */ + vm_ooffset_t backing_object_offset;/* Offset in backing object */ + TAILQ_ENTRY(vm_object) pager_object_list; /* list of all objects of this pager type */ + void *handle; + union { + /* + * VNode pager + * + * vnp_size - current size of file + */ + struct { + off_t vnp_size; + } vnp; + + /* + * Device pager + * + * devp_pglist - list of allocated pages + */ + struct { + TAILQ_HEAD(, vm_page) devp_pglist; + } devp; + + /* + * Swap pager + * + * swp_bcount - number of swap 'swblock' metablocks, each + * contains up to 16 swapblk assignments. + * see vm/swap_pager.h + */ + struct { + int swp_bcount; + } swp; + } un_pager; +}; + +/* + * Flags + */ +#define OBJ_ACTIVE 0x0004 /* active objects */ +#define OBJ_DEAD 0x0008 /* dead objects (during rundown) */ +#define OBJ_NOSPLIT 0x0010 /* dont split this object */ +#define OBJ_PIPWNT 0x0040 /* paging in progress wanted */ +#define OBJ_WRITEABLE 0x0080 /* object has been made writable */ +#define OBJ_MIGHTBEDIRTY 0x0100 /* object might be dirty */ +#define OBJ_CLEANING 0x0200 +#define OBJ_ONEMAPPING 0x2000 /* One USE (a single, non-forked) mapping flag */ + +#define IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT) +#define OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT)) + +#ifdef _KERNEL + +#define OBJPC_SYNC 0x1 /* sync I/O */ +#define OBJPC_INVAL 0x2 /* invalidate */ +#define OBJPC_NOSYNC 0x4 /* skip if PG_NOSYNC */ + +TAILQ_HEAD(object_q, vm_object); + +extern struct object_q vm_object_list; /* list of allocated objects */ +extern struct mtx vm_object_list_mtx; /* lock for object list and count */ + +extern struct vm_object kernel_object_store; +extern struct vm_object kmem_object_store; + +#define kernel_object (&kernel_object_store) +#define kmem_object (&kmem_object_store) + +#define VM_OBJECT_LOCK(object) mtx_lock(&(object)->mtx) +#define VM_OBJECT_LOCK_ASSERT(object, type) \ + mtx_assert(&(object)->mtx, (type)) +#define VM_OBJECT_LOCK_INIT(object) mtx_init(&(object)->mtx, "vm object", \ + NULL, MTX_DEF | MTX_DUPOK) +#define VM_OBJECT_LOCKED(object) mtx_owned(&(object)->mtx) +#define VM_OBJECT_MTX(object) (&(object)->mtx) +#define VM_OBJECT_TRYLOCK(object) mtx_trylock(&(object)->mtx) +#define VM_OBJECT_UNLOCK(object) mtx_unlock(&(object)->mtx) + +/* + * The object must be locked or thread private. + */ +static __inline void +vm_object_set_flag(vm_object_t object, u_short bits) +{ + + object->flags |= bits; +} + +void vm_object_clear_flag(vm_object_t object, u_short bits); +void vm_object_pip_add(vm_object_t object, short i); +void vm_object_pip_subtract(vm_object_t object, short i); +void vm_object_pip_wakeup(vm_object_t object); +void vm_object_pip_wakeupn(vm_object_t object, short i); +void vm_object_pip_wait(vm_object_t object, char *waitid); + +vm_object_t vm_object_allocate (objtype_t, vm_pindex_t); +vm_object_t vm_object_allocate_wait (objtype_t, vm_pindex_t, int); +void _vm_object_allocate (objtype_t, vm_pindex_t, vm_object_t); +boolean_t vm_object_coalesce (vm_object_t, vm_pindex_t, vm_size_t, vm_size_t); +void vm_object_collapse (vm_object_t); +void vm_object_deallocate (vm_object_t); +void vm_object_terminate (vm_object_t); +void vm_object_vndeallocate (vm_object_t); +void vm_object_set_writeable_dirty (vm_object_t); +void vm_object_init (void); +void vm_object_page_clean (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t); +void vm_object_page_remove (vm_object_t, vm_pindex_t, vm_pindex_t, boolean_t); +void vm_object_reference (vm_object_t); +void vm_object_reference_locked(vm_object_t); +void vm_object_shadow (vm_object_t *, vm_ooffset_t *, vm_size_t); +void vm_object_split(vm_map_entry_t); +void vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t, + boolean_t); +void vm_object_madvise (vm_object_t, vm_pindex_t, int, int); +#endif /* _KERNEL */ + +#endif /* _VM_OBJECT_ */ diff --git a/src/include/vm/vm_page.h b/src/include/vm/vm_page.h new file mode 100644 index 0000000..9d4a8e2 --- /dev/null +++ b/src/include/vm/vm_page.h @@ -0,0 +1,396 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * from: @(#)vm_page.h 8.2 (Berkeley) 12/13/93 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Authors: Avadis Tevanian, Jr., Michael Wayne Young + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/vm_page.h,v 1.128 2004/04/06 20:15:37 imp Exp $ + */ + +/* + * Resident memory system definitions. + */ + +#ifndef _VM_PAGE_ +#define _VM_PAGE_ + +#if !defined(KLD_MODULE) +#include "opt_vmpage.h" +#endif + +#include + +/* + * Management of resident (logical) pages. + * + * A small structure is kept for each resident + * page, indexed by page number. Each structure + * is an element of several lists: + * + * A hash table bucket used to quickly + * perform object/offset lookups + * + * A list of all pages for a given object, + * so they can be quickly deactivated at + * time of deallocation. + * + * An ordered list of pages due for pageout. + * + * In addition, the structure contains the object + * and offset to which this page belongs (for pageout), + * and sundry status bits. + * + * Fields in this structure are locked either by the lock on the + * object that the page belongs to (O) or by the lock on the page + * queues (P). + * + * The 'valid' and 'dirty' fields are distinct. A page may have dirty + * bits set without having associated valid bits set. This is used by + * NFS to implement piecemeal writes. + */ + +TAILQ_HEAD(pglist, vm_page); + +struct vm_page { + TAILQ_ENTRY(vm_page) pageq; /* queue info for FIFO queue or free list (P) */ + TAILQ_ENTRY(vm_page) listq; /* pages in same object (O) */ + struct vm_page *left; /* splay tree link (O) */ + struct vm_page *right; /* splay tree link (O) */ + + vm_object_t object; /* which object am I in (O,P)*/ + vm_pindex_t pindex; /* offset into object (O,P) */ + vm_paddr_t phys_addr; /* physical address of page */ + struct md_page md; /* machine dependant stuff */ + u_short queue; /* page queue index */ + u_short flags, /* see below */ + pc; /* page color */ + u_short wire_count; /* wired down maps refs (P) */ + short hold_count; /* page hold count */ + u_char act_count; /* page usage count */ + u_char busy; /* page busy count */ + /* NOTE that these must support one bit per DEV_BSIZE in a page!!! */ + /* so, on normal X86 kernels, they must be at least 8 bits wide */ +#if PAGE_SIZE == 4096 + u_char valid; /* map of valid DEV_BSIZE chunks (O) */ + u_char dirty; /* map of dirty DEV_BSIZE chunks */ +#elif PAGE_SIZE == 8192 + u_short valid; /* map of valid DEV_BSIZE chunks (O) */ + u_short dirty; /* map of dirty DEV_BSIZE chunks */ +#elif PAGE_SIZE == 16384 + u_int valid; /* map of valid DEV_BSIZE chunks (O) */ + u_int dirty; /* map of dirty DEV_BSIZE chunks */ +#elif PAGE_SIZE == 32768 + u_long valid; /* map of valid DEV_BSIZE chunks (O) */ + u_long dirty; /* map of dirty DEV_BSIZE chunks */ +#endif + u_int cow; /* page cow mapping count */ +}; + +/* Make sure that u_long is at least 64 bits when PAGE_SIZE is 32K. */ +#if PAGE_SIZE == 32768 +#ifdef CTASSERT +CTASSERT(sizeof(u_long) >= 8); +#endif +#endif + +/* + * note: currently use SWAPBLK_NONE as an absolute value rather then + * a flag bit. + */ + +#define SWAPBLK_MASK ((daddr_t)((u_daddr_t)-1 >> 1)) /* mask */ +#define SWAPBLK_NONE ((daddr_t)((u_daddr_t)SWAPBLK_MASK + 1))/* flag */ + +#if !defined(KLD_MODULE) +/* + * Page coloring parameters + */ +/* Each of PQ_FREE, and PQ_CACHE have PQ_HASH_SIZE entries */ + +/* Backward compatibility for existing PQ_*CACHE config options. */ +#if !defined(PQ_CACHESIZE) +#if defined(PQ_HUGECACHE) +#define PQ_CACHESIZE 1024 +#elif defined(PQ_LARGECACHE) +#define PQ_CACHESIZE 512 +#elif defined(PQ_MEDIUMCACHE) +#define PQ_CACHESIZE 256 +#elif defined(PQ_NORMALCACHE) +#define PQ_CACHESIZE 64 +#elif defined(PQ_NOOPT) +#define PQ_CACHESIZE 0 +#else +#define PQ_CACHESIZE 128 +#endif +#endif /* !defined(PQ_CACHESIZE) */ + +#if PQ_CACHESIZE >= 1024 +#define PQ_PRIME1 31 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_PRIME2 23 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_L2_SIZE 256 /* A number of colors opt for 1M cache */ + +#elif PQ_CACHESIZE >= 512 +#define PQ_PRIME1 31 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_PRIME2 23 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_L2_SIZE 128 /* A number of colors opt for 512K cache */ + +#elif PQ_CACHESIZE >= 256 +#define PQ_PRIME1 13 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_PRIME2 7 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_L2_SIZE 64 /* A number of colors opt for 256K cache */ + +#elif PQ_CACHESIZE >= 128 +#define PQ_PRIME1 9 /* Produces a good PQ_L2_SIZE/3 + PQ_PRIME1 */ +#define PQ_PRIME2 5 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_L2_SIZE 32 /* A number of colors opt for 128k cache */ + +#elif PQ_CACHESIZE >= 64 +#define PQ_PRIME1 5 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_PRIME2 3 /* Prime number somewhat less than PQ_HASH_SIZE */ +#define PQ_L2_SIZE 16 /* A reasonable number of colors (opt for 64K cache) */ + +#else +#define PQ_PRIME1 1 /* Disable page coloring. */ +#define PQ_PRIME2 1 +#define PQ_L2_SIZE 1 + +#endif + +#define PQ_L2_MASK (PQ_L2_SIZE - 1) + +#define PQ_NONE 0 +#define PQ_FREE 1 +#define PQ_INACTIVE (1 + 1*PQ_L2_SIZE) +#define PQ_ACTIVE (2 + 1*PQ_L2_SIZE) +#define PQ_CACHE (3 + 1*PQ_L2_SIZE) +#define PQ_HOLD (3 + 2*PQ_L2_SIZE) +#define PQ_COUNT (4 + 2*PQ_L2_SIZE) + +struct vpgqueues { + struct pglist pl; + int *cnt; + int lcnt; +}; + +extern struct vpgqueues vm_page_queues[PQ_COUNT]; +extern struct mtx vm_page_queue_free_mtx; + +#endif /* !defined(KLD_MODULE) */ + +/* + * These are the flags defined for vm_page. + * + * Note: PG_FILLED and PG_DIRTY are added for the filesystems. + * + * Note: PG_UNMANAGED (used by OBJT_PHYS) indicates that the page is + * not under PV management but otherwise should be treated as a + * normal page. Pages not under PV management cannot be paged out + * via the object/vm_page_t because there is no knowledge of their + * pte mappings, nor can they be removed from their objects via + * the object, and such pages are also not on any PQ queue. + */ +#define PG_BUSY 0x0001 /* page is in transit (O) */ +#define PG_WANTED 0x0002 /* someone is waiting for page (O) */ +#define PG_WINATCFLS 0x0004 /* flush dirty page on inactive q */ +#define PG_FICTITIOUS 0x0008 /* physical page doesn't exist (O) */ +#define PG_WRITEABLE 0x0010 /* page is mapped writeable */ +#define PG_ZERO 0x0040 /* page is zeroed */ +#define PG_REFERENCED 0x0080 /* page has been referenced */ +#define PG_CLEANCHK 0x0100 /* page will be checked for cleaning */ +#define PG_SWAPINPROG 0x0200 /* swap I/O in progress on page */ +#define PG_NOSYNC 0x0400 /* do not collect for syncer */ +#define PG_UNMANAGED 0x0800 /* No PV management for page */ +#define PG_MARKER 0x1000 /* special queue marker page */ +#define PG_SLAB 0x2000 /* object pointer is actually a slab */ + +/* + * Misc constants. + */ +#define ACT_DECLINE 1 +#define ACT_ADVANCE 3 +#define ACT_INIT 5 +#define ACT_MAX 64 + +#ifdef _KERNEL +/* + * Each pageable resident page falls into one of four lists: + * + * free + * Available for allocation now. + * + * The following are all LRU sorted: + * + * cache + * Almost available for allocation. Still in an + * object, but clean and immediately freeable at + * non-interrupt times. + * + * inactive + * Low activity, candidates for reclamation. + * This is the list of pages that should be + * paged out next. + * + * active + * Pages that are "active" i.e. they have been + * recently referenced. + * + * zero + * Pages that are really free and have been pre-zeroed + * + */ + +extern int vm_page_zero_count; + +extern vm_page_t vm_page_array; /* First resident page in table */ +extern int vm_page_array_size; /* number of vm_page_t's */ +extern long first_page; /* first physical page number */ + +#define VM_PAGE_TO_PHYS(entry) ((entry)->phys_addr) + +#define PHYS_TO_VM_PAGE(pa) \ + (&vm_page_array[atop(pa) - first_page ]) + +extern struct mtx vm_page_queue_mtx; +#define vm_page_lock_queues() mtx_lock(&vm_page_queue_mtx) +#define vm_page_unlock_queues() mtx_unlock(&vm_page_queue_mtx) + +#if PAGE_SIZE == 4096 +#define VM_PAGE_BITS_ALL 0xffu +#elif PAGE_SIZE == 8192 +#define VM_PAGE_BITS_ALL 0xffffu +#elif PAGE_SIZE == 16384 +#define VM_PAGE_BITS_ALL 0xffffffffu +#elif PAGE_SIZE == 32768 +#define VM_PAGE_BITS_ALL 0xfffffffffffffffflu +#endif + +/* page allocation classes: */ +#define VM_ALLOC_NORMAL 0 +#define VM_ALLOC_INTERRUPT 1 +#define VM_ALLOC_SYSTEM 2 +#define VM_ALLOC_CLASS_MASK 3 +/* page allocation flags: */ +#define VM_ALLOC_WIRED 0x0020 /* non pageable */ +#define VM_ALLOC_ZERO 0x0040 /* Try to obtain a zeroed page */ +#define VM_ALLOC_RETRY 0x0080 /* vm_page_grab() only */ +#define VM_ALLOC_NOOBJ 0x0100 /* No associated object */ + +void vm_page_flag_set(vm_page_t m, unsigned short bits); +void vm_page_flag_clear(vm_page_t m, unsigned short bits); +void vm_page_busy(vm_page_t m); +void vm_page_flash(vm_page_t m); +void vm_page_io_start(vm_page_t m); +void vm_page_io_finish(vm_page_t m); +void vm_page_hold(vm_page_t mem); +void vm_page_unhold(vm_page_t mem); +void vm_page_free(vm_page_t m); +void vm_page_free_zero(vm_page_t m); +int vm_page_sleep_if_busy(vm_page_t m, int also_m_busy, const char *msg); +void vm_page_dirty(vm_page_t m); +void vm_page_wakeup(vm_page_t m); + +void vm_pageq_init(void); +vm_page_t vm_pageq_add_new_page(vm_paddr_t pa); +void vm_pageq_enqueue(int queue, vm_page_t m); +void vm_pageq_remove_nowakeup(vm_page_t m); +void vm_pageq_remove(vm_page_t m); +vm_page_t vm_pageq_find(int basequeue, int index, boolean_t prefer_zero); +void vm_pageq_requeue(vm_page_t m); + +void vm_page_activate (vm_page_t); +vm_page_t vm_page_alloc (vm_object_t, vm_pindex_t, int); +vm_page_t vm_page_grab (vm_object_t, vm_pindex_t, int); +void vm_page_cache (register vm_page_t); +int vm_page_try_to_cache (vm_page_t); +int vm_page_try_to_free (vm_page_t); +void vm_page_dontneed (register vm_page_t); +void vm_page_deactivate (vm_page_t); +void vm_page_insert (vm_page_t, vm_object_t, vm_pindex_t); +vm_page_t vm_page_lookup (vm_object_t, vm_pindex_t); +void vm_page_remove (vm_page_t); +void vm_page_rename (vm_page_t, vm_object_t, vm_pindex_t); +vm_page_t vm_page_select_cache(int); +vm_page_t vm_page_splay(vm_pindex_t, vm_page_t); +vm_offset_t vm_page_startup(vm_offset_t vaddr); +void vm_page_unmanage (vm_page_t); +void vm_page_unwire (vm_page_t, int); +void vm_page_wire (vm_page_t); +void vm_page_set_validclean (vm_page_t, int, int); +void vm_page_clear_dirty (vm_page_t, int, int); +void vm_page_set_invalid (vm_page_t, int, int); +int vm_page_is_valid (vm_page_t, int, int); +void vm_page_test_dirty (vm_page_t); +int vm_page_bits (int, int); +void vm_page_zero_invalid(vm_page_t m, boolean_t setvalid); +void vm_page_free_toq(vm_page_t m); +void vm_page_zero_idle_wakeup(void); +void vm_page_cowfault (vm_page_t); +void vm_page_cowsetup (vm_page_t); +void vm_page_cowclear (vm_page_t); + +/* + * vm_page_undirty: + * + * Set page to not be dirty. Note: does not clear pmap modify bits + */ +static __inline void +vm_page_undirty(vm_page_t m) +{ + m->dirty = 0; +} + +#endif /* _KERNEL */ +#endif /* !_VM_PAGE_ */ diff --git a/src/include/vm/vm_pageout.h b/src/include/vm/vm_pageout.h new file mode 100644 index 0000000..c462d5b --- /dev/null +++ b/src/include/vm/vm_pageout.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * from: @(#)vm_pageout.h 8.2 (Berkeley) 1/12/94 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Avadis Tevanian, Jr. + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/vm_pageout.h,v 1.39 2004/04/06 20:15:37 imp Exp $ + */ + +#ifndef _VM_VM_PAGEOUT_H_ +#define _VM_VM_PAGEOUT_H_ + +/* + * Header file for pageout daemon. + */ + +/* + * Exported data structures. + */ + +extern int vm_page_max_wired; +extern int vm_pages_needed; /* should be some "event" structure */ +extern int vm_pageout_pages_needed; +extern int vm_pageout_deficit; +extern int vm_pageout_page_count; + +/* + * Swap out requests + */ +#define VM_SWAP_NORMAL 1 +#define VM_SWAP_IDLE 2 + +/* + * Exported routines. + */ + +/* + * Signal pageout-daemon and wait for it. + */ + +extern void pagedaemon_wakeup(void); +#define VM_WAIT vm_wait() +#define VM_WAITPFAULT vm_waitpfault() +extern void vm_wait(void); +extern void vm_waitpfault(void); + +/* XXX This is probably misplaced. */ +#ifndef NO_SWAPPING +struct swdevt; +void vm_proc_swapin_all(struct swdevt *); +#endif /* !NO_SWAPPING */ + +#ifdef _KERNEL +int vm_pageout_flush(vm_page_t *, int, int); +#endif +#endif /* _VM_VM_PAGEOUT_H_ */ diff --git a/src/include/vm/vm_pager.h b/src/include/vm/vm_pager.h new file mode 100644 index 0000000..d78461c --- /dev/null +++ b/src/include/vm/vm_pager.h @@ -0,0 +1,190 @@ +/* + * Copyright (c) 1990 University of Utah. + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + * 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. + * + * @(#)vm_pager.h 8.4 (Berkeley) 1/12/94 + * $FreeBSD: src/sys/vm/vm_pager.h,v 1.47 2004/04/08 19:08:49 alc Exp $ + */ + +/* + * Pager routine interface definition. + */ + +#ifndef _VM_PAGER_ +#define _VM_PAGER_ + +#include + +TAILQ_HEAD(pagerlst, vm_object); + +struct bio; + +struct pagerops { + void (*pgo_init)(void); /* Initialize pager. */ + vm_object_t (*pgo_alloc)(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); /* Allocate pager. */ + void (*pgo_dealloc)(vm_object_t); /* Disassociate. */ + int (*pgo_getpages)(vm_object_t, vm_page_t *, int, int); /* Get (read) page. */ + void (*pgo_putpages)(vm_object_t, vm_page_t *, int, int, int *); /* Put (write) page. */ + boolean_t (*pgo_haspage)(vm_object_t, vm_pindex_t, int *, int *); /* Does pager have page? */ + void (*pgo_pageunswapped)(vm_page_t); +}; + +extern struct pagerops defaultpagerops; +extern struct pagerops swappagerops; +extern struct pagerops vnodepagerops; +extern struct pagerops devicepagerops; +extern struct pagerops physpagerops; + +/* + * get/put return values + * OK operation was successful + * BAD specified data was out of the accepted range + * FAIL specified data was in range, but doesn't exist + * PEND operations was initiated but not completed + * ERROR error while accessing data that is in range and exists + * AGAIN temporary resource shortage prevented operation from happening + */ +#define VM_PAGER_OK 0 +#define VM_PAGER_BAD 1 +#define VM_PAGER_FAIL 2 +#define VM_PAGER_PEND 3 +#define VM_PAGER_ERROR 4 +#define VM_PAGER_AGAIN 5 + +#define VM_PAGER_PUT_SYNC 0x0001 +#define VM_PAGER_PUT_INVAL 0x0002 +#define VM_PAGER_IGNORE_CLEANCHK 0x0004 +#define VM_PAGER_CLUSTER_OK 0x0008 + +#ifdef _KERNEL +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_VMPGDATA); +#endif + +extern vm_map_t pager_map; +extern struct pagerops *pagertab[]; +extern struct mtx pbuf_mtx; + +vm_object_t vm_pager_allocate(objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); +void vm_pager_bufferinit(void); +void vm_pager_deallocate(vm_object_t); +static __inline int vm_pager_get_pages(vm_object_t, vm_page_t *, int, int); +static __inline boolean_t vm_pager_has_page(vm_object_t, vm_pindex_t, int *, int *); +void vm_pager_init(void); +vm_object_t vm_pager_object_lookup(struct pagerlst *, void *); + +/* + * vm_page_get_pages: + * + * Retrieve pages from the VM system in order to map them into an object + * ( or into VM space somewhere ). If the pagein was successful, we + * must fully validate it. + */ +static __inline int +vm_pager_get_pages( + vm_object_t object, + vm_page_t *m, + int count, + int reqpage +) { + int r; + + VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); + r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage); + if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) { + vm_page_zero_invalid(m[reqpage], TRUE); + } + return (r); +} + +static __inline void +vm_pager_put_pages( + vm_object_t object, + vm_page_t *m, + int count, + int flags, + int *rtvals +) { + + VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); + (*pagertab[object->type]->pgo_putpages) + (object, m, count, flags, rtvals); +} + +/* + * vm_pager_haspage + * + * Check to see if an object's pager has the requested page. The + * object's pager will also set before and after to give the caller + * some idea of the number of pages before and after the requested + * page can be I/O'd efficiently. + * + * This routine does not have to be called at any particular spl. + */ +static __inline boolean_t +vm_pager_has_page( + vm_object_t object, + vm_pindex_t offset, + int *before, + int *after +) { + boolean_t ret; + + VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); + ret = (*pagertab[object->type]->pgo_haspage) + (object, offset, before, after); + return (ret); +} + +/* + * vm_pager_page_unswapped + * + * called at splvm() to destroy swap associated with the page. + * + * This function may not block. + * + * XXX: A much better name would be "vm_pager_page_dirtied()" + * XXX: It is not obvious if this could be profitably used by any + * XXX: pagers besides the swap_pager or if it should even be a + * XXX: generic pager_op in the first place. + */ +static __inline void +vm_pager_page_unswapped(vm_page_t m) +{ + + VM_OBJECT_LOCK_ASSERT(m->object, MA_OWNED); + if (pagertab[m->object->type]->pgo_pageunswapped) + (*pagertab[m->object->type]->pgo_pageunswapped)(m); +} + +#endif /* _KERNEL */ +#endif /* _VM_PAGER_ */ diff --git a/src/include/vm/vm_param.h b/src/include/vm/vm_param.h new file mode 100644 index 0000000..9f9cd3c --- /dev/null +++ b/src/include/vm/vm_param.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * 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. + * + * from: @(#)vm_param.h 8.1 (Berkeley) 6/11/93 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Authors: Avadis Tevanian, Jr., Michael Wayne Young + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + * + * $FreeBSD: src/sys/vm/vm_param.h,v 1.18 2004/04/06 20:15:37 imp Exp $ + */ + +/* + * Machine independent virtual memory parameters. + */ + +#ifndef _VM_PARAM_ +#define _VM_PARAM_ + +#include + +/* + * CTL_VM identifiers + */ +#define VM_TOTAL 1 /* struct vmtotal */ +#define VM_METER VM_TOTAL/* deprecated, use VM_TOTAL */ +#define VM_LOADAVG 2 /* struct loadavg */ +#define VM_V_FREE_MIN 3 /* cnt.v_free_min */ +#define VM_V_FREE_TARGET 4 /* cnt.v_free_target */ +#define VM_V_FREE_RESERVED 5 /* cnt.v_free_reserved */ +#define VM_V_INACTIVE_TARGET 6 /* cnt.v_inactive_target */ +#define VM_V_CACHE_MIN 7 /* cnt.v_cache_max */ +#define VM_V_CACHE_MAX 8 /* cnt.v_cache_min */ +#define VM_V_PAGEOUT_FREE_MIN 9 /* cnt.v_pageout_free_min */ +#define VM_PAGEOUT_ALGORITHM 10 /* pageout algorithm */ +#define VM_SWAPPING_ENABLED 11 /* swapping enabled */ +#define VM_MAXID 12 /* number of valid vm ids */ + +#define CTL_VM_NAMES { \ + { 0, 0 }, \ + { "vmtotal", CTLTYPE_STRUCT }, \ + { "loadavg", CTLTYPE_STRUCT }, \ + { "v_free_min", CTLTYPE_INT }, \ + { "v_free_target", CTLTYPE_INT }, \ + { "v_free_reserved", CTLTYPE_INT }, \ + { "v_inactive_target", CTLTYPE_INT }, \ + { "v_cache_min", CTLTYPE_INT }, \ + { "v_cache_max", CTLTYPE_INT }, \ + { "v_pageout_free_min", CTLTYPE_INT}, \ + { "pageout_algorithm", CTLTYPE_INT}, \ + { "swapping_enabled", CTLTYPE_INT},\ +} + +/* + * Structure for swap device statistics + */ +#define XSWDEV_VERSION 1 +struct xswdev { + u_int xsw_version; + udev_t xsw_dev; + int xsw_flags; + int xsw_nblks; + int xsw_used; +}; + +/* + * Return values from the VM routines. + */ +#define KERN_SUCCESS 0 +#define KERN_INVALID_ADDRESS 1 +#define KERN_PROTECTION_FAILURE 2 +#define KERN_NO_SPACE 3 +#define KERN_INVALID_ARGUMENT 4 +#define KERN_FAILURE 5 +#define KERN_RESOURCE_SHORTAGE 6 +#define KERN_NOT_RECEIVER 7 +#define KERN_NO_ACCESS 8 + +#ifndef ASSEMBLER +#ifdef _KERNEL +#define num_pages(x) \ + ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT)) +extern u_quad_t maxtsiz; +extern u_quad_t dfldsiz; +extern u_quad_t maxdsiz; +extern u_quad_t dflssiz; +extern u_quad_t maxssiz; +extern u_quad_t sgrowsiz; +#endif /* _KERNEL */ +#endif /* ASSEMBLER */ +#endif /* _VM_PARAM_ */ diff --git a/src/include/vm/vnode_pager.h b/src/include/vm/vnode_pager.h new file mode 100644 index 0000000..f596db8 --- /dev/null +++ b/src/include/vm/vnode_pager.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1990 University of Utah. + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + * 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. + * + * @(#)vnode_pager.h 8.1 (Berkeley) 6/11/93 + * $FreeBSD: src/sys/vm/vnode_pager.h,v 1.18 2004/04/06 20:15:37 imp Exp $ + */ + +#ifndef _VNODE_PAGER_ +#define _VNODE_PAGER_ 1 + +#ifdef _KERNEL +vm_object_t vnode_pager_alloc(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t); +struct vnode *vnode_pager_lock(vm_object_t); + +/* + * XXX Generic routines; currently called by badly written FS code; these + * XXX should go away soon. + */ +int vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m, + int count, int reqpage); +int vnode_pager_generic_putpages(struct vnode *vp, vm_page_t *m, + int count, boolean_t sync, + int *rtvals); +#endif /* _KERNEL */ +#endif /* _VNODE_PAGER_ */ diff --git a/src/include/wchar.h b/src/include/wchar.h new file mode 100644 index 0000000..cc1bbce --- /dev/null +++ b/src/include/wchar.h @@ -0,0 +1,204 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/wchar.h,v 1.36 2003/12/07 21:10:06 marcel Exp $ + */ + +/*- + * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + * + * $NetBSD: wchar.h,v 1.8 2000/12/22 05:31:42 itojun Exp $ + */ + +#ifndef _WCHAR_H_ +#define _WCHAR_H_ + +#include +#include +#include +#include + +#ifndef _MBSTATE_T_DECLARED +typedef __mbstate_t mbstate_t; +#define _MBSTATE_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef __cplusplus +#ifndef _WCHAR_T_DECLARED +typedef __wchar_t wchar_t; +#define _WCHAR_T_DECLARED +#endif +#endif + +#ifndef _WINT_T_DECLARED +typedef __wint_t wint_t; +#define _WINT_T_DECLARED +#endif + +#ifndef WCHAR_MIN +#define WCHAR_MIN __INT_MIN +#define WCHAR_MAX __INT_MAX +#endif + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +struct __sFILE; +struct tm; + +__BEGIN_DECLS +wint_t btowc(int); +wint_t fgetwc(struct __sFILE *); +wchar_t * + fgetws(wchar_t * __restrict, int, struct __sFILE * __restrict); +wint_t fputwc(wchar_t, struct __sFILE *); +int fputws(const wchar_t * __restrict, struct __sFILE * __restrict); +int fwide(struct __sFILE *, int); +int fwprintf(struct __sFILE * __restrict, const wchar_t * __restrict, ...); +int fwscanf(struct __sFILE * __restrict, const wchar_t * __restrict, ...); +wint_t getwc(struct __sFILE *); +wint_t getwchar(void); +size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict); +size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int mbsinit(const mbstate_t *); +size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, + mbstate_t * __restrict); +wint_t putwc(wchar_t, struct __sFILE *); +wint_t putwchar(wchar_t); +int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, + ...); +int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...); +wint_t ungetwc(wint_t, struct __sFILE *); +int vfwprintf(struct __sFILE * __restrict, const wchar_t * __restrict, + __va_list); +int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, + __va_list); +int vwprintf(const wchar_t * __restrict, __va_list); +size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); +wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict); +wchar_t *wcschr(const wchar_t *, wchar_t); +int wcscmp(const wchar_t *, const wchar_t *); +int wcscoll(const wchar_t *, const wchar_t *); +wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict); +size_t wcscspn(const wchar_t *, const wchar_t *); +size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t * __restrict, + const struct tm * __restrict); +size_t wcslen(const wchar_t *); +wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict, + size_t); +int wcsncmp(const wchar_t *, const wchar_t *, size_t); +wchar_t *wcsncpy(wchar_t * __restrict , const wchar_t * __restrict, size_t); +wchar_t *wcspbrk(const wchar_t *, const wchar_t *); +wchar_t *wcsrchr(const wchar_t *, wchar_t); +size_t wcsrtombs(char * __restrict, const wchar_t ** __restrict, size_t, + mbstate_t * __restrict); +size_t wcsspn(const wchar_t *, const wchar_t *); +wchar_t *wcsstr(const wchar_t * __restrict, const wchar_t * __restrict); +size_t wcsxfrm(wchar_t * __restrict, const wchar_t * __restrict, size_t); +int wctob(wint_t); +double wcstod(const wchar_t * __restrict, wchar_t ** __restrict); +wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict, + wchar_t ** __restrict); +long wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int); +unsigned long + wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, int); +wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); +int wmemcmp(const wchar_t *, const wchar_t *, size_t); +wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t); +wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); +wchar_t *wmemset(wchar_t *, wchar_t, size_t); +int wprintf(const wchar_t * __restrict, ...); +int wscanf(const wchar_t * __restrict, ...); + +#if __ISO_C_VISIBLE >= 1999 +int vfwscanf(struct __sFILE * __restrict, const wchar_t * __restrict, + __va_list); +int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict, + __va_list); +int vwscanf(const wchar_t * __restrict, __va_list); +float wcstof(const wchar_t * __restrict, wchar_t ** __restrict); +long double + wcstold(const wchar_t * __restrict, wchar_t ** __restrict); +#ifdef __LONG_LONG_SUPPORTED +/* LONGLONG */ +long long + wcstoll(const wchar_t * __restrict, wchar_t ** __restrict, int); +/* LONGLONG */ +unsigned long long + wcstoull(const wchar_t * __restrict, wchar_t ** __restrict, int); +#endif +#endif /* __ISO_C_VISIBLE >= 1999 */ + +#if __XSI_VISIBLE +int wcswidth(const wchar_t *, size_t); +int wcwidth(wchar_t); +#endif + +#if __BSD_VISIBLE +size_t wcslcat(wchar_t *, const wchar_t *, size_t); +size_t wcslcpy(wchar_t *, const wchar_t *, size_t); +#endif +__END_DECLS + +#endif /* !_WCHAR_H_ */ diff --git a/src/include/wctype.h b/src/include/wctype.h new file mode 100644 index 0000000..4173492 --- /dev/null +++ b/src/include/wctype.h @@ -0,0 +1,117 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp + * $NetBSD: wctype.h,v 1.3 2000/12/22 14:16:16 itojun Exp $ + * $FreeBSD: src/include/wctype.h,v 1.10 2002/08/21 16:19:55 mike Exp $ + */ + +#ifndef _WCTYPE_H_ +#define _WCTYPE_H_ + +#include +#include + +#include + +#ifndef _WCTRANS_T +typedef int wctrans_t; +#define _WCTRANS_T +#endif + +#ifndef _WCTYPE_T +typedef unsigned long wctype_t; +#define _WCTYPE_T +#endif + +#ifndef _WINT_T_DECLARED +typedef __wint_t wint_t; +#define _WINT_T_DECLARED +#endif + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +__BEGIN_DECLS +int iswalnum(wint_t); +int iswalpha(wint_t); +int iswblank(wint_t); +int iswcntrl(wint_t); +int iswctype(wint_t, wctype_t); +int iswdigit(wint_t); +int iswgraph(wint_t); +int iswlower(wint_t); +int iswprint(wint_t); +int iswpunct(wint_t); +int iswspace(wint_t); +int iswupper(wint_t); +int iswxdigit(wint_t); +wint_t towctrans(wint_t, wctrans_t); +wint_t towlower(wint_t); +wint_t towupper(wint_t); +wctrans_t + wctrans(const char *); +wctype_t + wctype(const char *); + +#if __BSD_VISIBLE +wint_t iswascii(wint_t); +wint_t iswhexnumber(wint_t); +wint_t iswideogram(wint_t); +wint_t iswnumber(wint_t); +wint_t iswphonogram(wint_t); +wint_t iswrune(wint_t); +wint_t iswspecial(wint_t); +#endif +__END_DECLS + +#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D) +#define iswalpha(wc) __istype((wc), _CTYPE_A) +#define iswblank(wc) __istype((wc), _CTYPE_B) +#define iswcntrl(wc) __istype((wc), _CTYPE_C) +#define iswctype(wc, charclass) __istype((wc), (charclass)) +#define iswdigit(wc) __istype((wc), _CTYPE_D) +#define iswgraph(wc) __istype((wc), _CTYPE_G) +#define iswlower(wc) __istype((wc), _CTYPE_L) +#define iswprint(wc) __istype((wc), _CTYPE_R) +#define iswpunct(wc) __istype((wc), _CTYPE_P) +#define iswspace(wc) __istype((wc), _CTYPE_S) +#define iswupper(wc) __istype((wc), _CTYPE_U) +#define iswxdigit(wc) __istype((wc), _CTYPE_X) +#define towlower(wc) __tolower(wc) +#define towupper(wc) __toupper(wc) + +#if __BSD_VISIBLE +#define iswascii(wc) (((wc) & ~0x7F) == 0) +#define iswhexnumber(wc) __istype((wc), _CTYPE_X) +#define iswideogram(wc) __istype((wc), _CTYPE_I) +#define iswnumber(wc) __istype((wc), _CTYPE_D) +#define iswphonogram(wc) __istype((wc), _CTYPE_Q) +#define iswrune(wc) __istype((wc), 0xFFFFFF00L) +#define iswspecial(wc) __istype((wc), _CTYPE_T) +#endif + +#endif /* _WCTYPE_H_ */ diff --git a/src/include/wordexp.h b/src/include/wordexp.h new file mode 100644 index 0000000..a1b1860 --- /dev/null +++ b/src/include/wordexp.h @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/include/wordexp.h,v 1.4 2003/01/03 12:03:38 tjr Exp $ + */ + +#ifndef _WORDEXP_H_ +#define _WORDEXP_H_ + +#include +#include + +#if __XSI_VISIBLE && !defined(_SIZE_T_DECLARED) +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +typedef struct { + __size_t we_wordc; /* count of words matched */ + char **we_wordv; /* pointer to list of words */ + __size_t we_offs; /* slots to reserve in we_wordv */ + char *we_strings; /* storage for wordv strings */ + __size_t we_nbytes; /* size of we_strings */ +} wordexp_t; + +/* + * Flags for wordexp(). + */ +#define WRDE_APPEND 0x1 /* append to previously generated */ +#define WRDE_DOOFS 0x2 /* we_offs member is valid */ +#define WRDE_NOCMD 0x4 /* disallow command substitution */ +#define WRDE_REUSE 0x8 /* reuse wordexp_t */ +#define WRDE_SHOWERR 0x10 /* don't redirect stderr to /dev/null */ +#define WRDE_UNDEF 0x20 /* disallow undefined shell vars */ + +/* + * Return values from wordexp(). + */ +#define WRDE_BADCHAR 1 /* unquoted special character */ +#define WRDE_BADVAL 2 /* undefined variable */ +#define WRDE_CMDSUB 3 /* command substitution not allowed */ +#define WRDE_NOSPACE 4 /* no memory for result */ +#if __XSI_VISIBLE +#define WRDE_NOSYS 5 /* obsolete, reserved */ +#endif +#define WRDE_SYNTAX 6 /* shell syntax error */ + +__BEGIN_DECLS +int wordexp(const char * __restrict, wordexp_t * __restrict, int); +void wordfree(wordexp_t *); +__END_DECLS + +#endif /* !_WORDEXP_H_ */ diff --git a/src/include/xmmintrin.h b/src/include/xmmintrin.h new file mode 100644 index 0000000..1829ab0 --- /dev/null +++ b/src/include/xmmintrin.h @@ -0,0 +1,1230 @@ +/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. + + This file is part of GNU CC. + + GNU CC is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU CC is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU CC; see the file COPYING. If not, write to + the Free Software Foundation, 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, if you include this header file into source + files compiled by GCC, this header file does not by itself cause + the resulting executable to be covered by the GNU General Public + License. This exception does not however invalidate any other + reasons why the executable file might be covered by the GNU General + Public License. */ + +/* Implemented from the specification included in the Intel C++ Compiler + User Guide and Reference, version 8.0. */ + +#ifndef _XMMINTRIN_H_INCLUDED +#define _XMMINTRIN_H_INCLUDED + +#ifndef __SSE__ +# error "SSE instruction set not enabled" +#else + +/* We need type definitions from the MMX header file. */ +#include + +/* The data type indended for user use. */ +typedef int __m128 __attribute__ ((__mode__(__V4SF__))); + +/* Internal data types for implementing the instrinsics. */ +typedef int __v4sf __attribute__ ((__mode__(__V4SF__))); +typedef int __v4si __attribute__ ((__mode__(__V4SI__))); + +/* Create a selector for use with the SHUFPS instruction. */ +#define _MM_SHUFFLE(fp3,fp2,fp1,fp0) \ + (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | (fp0)) + +/* Constants for use with _mm_prefetch. */ +enum _mm_hint +{ + _MM_HINT_T0 = 3, + _MM_HINT_T1 = 2, + _MM_HINT_T2 = 1, + _MM_HINT_NTA = 0 +}; + +/* Bits in the MXCSR. */ +#define _MM_EXCEPT_MASK 0x003f +#define _MM_EXCEPT_INVALID 0x0001 +#define _MM_EXCEPT_DENORM 0x0002 +#define _MM_EXCEPT_DIV_ZERO 0x0004 +#define _MM_EXCEPT_OVERFLOW 0x0008 +#define _MM_EXCEPT_UNDERFLOW 0x0010 +#define _MM_EXCEPT_INEXACT 0x0020 + +#define _MM_MASK_MASK 0x1f80 +#define _MM_MASK_INVALID 0x0080 +#define _MM_MASK_DENORM 0x0100 +#define _MM_MASK_DIV_ZERO 0x0200 +#define _MM_MASK_OVERFLOW 0x0400 +#define _MM_MASK_UNDERFLOW 0x0800 +#define _MM_MASK_INEXACT 0x1000 + +#define _MM_ROUND_MASK 0x6000 +#define _MM_ROUND_NEAREST 0x0000 +#define _MM_ROUND_DOWN 0x2000 +#define _MM_ROUND_UP 0x4000 +#define _MM_ROUND_TOWARD_ZERO 0x6000 + +#define _MM_FLUSH_ZERO_MASK 0x8000 +#define _MM_FLUSH_ZERO_ON 0x8000 +#define _MM_FLUSH_ZERO_OFF 0x0000 + +/* Perform the respective operation on the lower SPFP (single-precision + floating-point) values of A and B; the upper three SPFP values are + passed through from A. */ + +static __inline __m128 +_mm_add_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_addss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_sub_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_subss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_mul_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_mulss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_div_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_divss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_sqrt_ss (__m128 __A) +{ + return (__m128) __builtin_ia32_sqrtss ((__v4sf)__A); +} + +static __inline __m128 +_mm_rcp_ss (__m128 __A) +{ + return (__m128) __builtin_ia32_rcpss ((__v4sf)__A); +} + +static __inline __m128 +_mm_rsqrt_ss (__m128 __A) +{ + return (__m128) __builtin_ia32_rsqrtss ((__v4sf)__A); +} + +static __inline __m128 +_mm_min_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_minss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_max_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_maxss ((__v4sf)__A, (__v4sf)__B); +} + +/* Perform the respective operation on the four SPFP values in A and B. */ + +static __inline __m128 +_mm_add_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_addps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_sub_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_subps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_mul_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_mulps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_div_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_divps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_sqrt_ps (__m128 __A) +{ + return (__m128) __builtin_ia32_sqrtps ((__v4sf)__A); +} + +static __inline __m128 +_mm_rcp_ps (__m128 __A) +{ + return (__m128) __builtin_ia32_rcpps ((__v4sf)__A); +} + +static __inline __m128 +_mm_rsqrt_ps (__m128 __A) +{ + return (__m128) __builtin_ia32_rsqrtps ((__v4sf)__A); +} + +static __inline __m128 +_mm_min_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_minps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_max_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_maxps ((__v4sf)__A, (__v4sf)__B); +} + +/* Perform logical bit-wise operations on 128-bit values. */ + +static __inline __m128 +_mm_and_ps (__m128 __A, __m128 __B) +{ + return __builtin_ia32_andps (__A, __B); +} + +static __inline __m128 +_mm_andnot_ps (__m128 __A, __m128 __B) +{ + return __builtin_ia32_andnps (__A, __B); +} + +static __inline __m128 +_mm_or_ps (__m128 __A, __m128 __B) +{ + return __builtin_ia32_orps (__A, __B); +} + +static __inline __m128 +_mm_xor_ps (__m128 __A, __m128 __B) +{ + return __builtin_ia32_xorps (__A, __B); +} + +/* Perform a comparison on the lower SPFP values of A and B. If the + comparison is true, place a mask of all ones in the result, otherwise a + mask of zeros. The upper three SPFP values are passed through from A. */ + +static __inline __m128 +_mm_cmpeq_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpeqss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmplt_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpltss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmple_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpless ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpgt_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_movss ((__v4sf) __A, + (__v4sf) + __builtin_ia32_cmpltss ((__v4sf) __B, + (__v4sf) + __A)); +} + +static __inline __m128 +_mm_cmpge_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_movss ((__v4sf) __A, + (__v4sf) + __builtin_ia32_cmpless ((__v4sf) __B, + (__v4sf) + __A)); +} + +static __inline __m128 +_mm_cmpneq_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpneqss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpnlt_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpnltss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpnle_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpnless ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpngt_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_movss ((__v4sf) __A, + (__v4sf) + __builtin_ia32_cmpnltss ((__v4sf) __B, + (__v4sf) + __A)); +} + +static __inline __m128 +_mm_cmpnge_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_movss ((__v4sf) __A, + (__v4sf) + __builtin_ia32_cmpnless ((__v4sf) __B, + (__v4sf) + __A)); +} + +static __inline __m128 +_mm_cmpord_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpordss ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpunord_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpunordss ((__v4sf)__A, (__v4sf)__B); +} + +/* Perform a comparison on the four SPFP values of A and B. For each + element, if the comparison is true, place a mask of all ones in the + result, otherwise a mask of zeros. */ + +static __inline __m128 +_mm_cmpeq_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpeqps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmplt_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpltps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmple_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpleps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpgt_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpgtps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpge_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpgeps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpneq_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpneqps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpnlt_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpnltps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpnle_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpnleps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpngt_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpngtps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpnge_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpngeps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpord_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpordps ((__v4sf)__A, (__v4sf)__B); +} + +static __inline __m128 +_mm_cmpunord_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_cmpunordps ((__v4sf)__A, (__v4sf)__B); +} + +/* Compare the lower SPFP values of A and B and return 1 if true + and 0 if false. */ + +static __inline int +_mm_comieq_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_comieq ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_comilt_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_comilt ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_comile_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_comile ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_comigt_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_comigt ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_comige_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_comige ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_comineq_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_comineq ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_ucomieq_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_ucomieq ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_ucomilt_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_ucomilt ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_ucomile_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_ucomile ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_ucomigt_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_ucomigt ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_ucomige_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_ucomige ((__v4sf)__A, (__v4sf)__B); +} + +static __inline int +_mm_ucomineq_ss (__m128 __A, __m128 __B) +{ + return __builtin_ia32_ucomineq ((__v4sf)__A, (__v4sf)__B); +} + +/* Convert the lower SPFP value to a 32-bit integer according to the current + rounding mode. */ +static __inline int +_mm_cvtss_si32 (__m128 __A) +{ + return __builtin_ia32_cvtss2si ((__v4sf) __A); +} + +static __inline int +_mm_cvt_ss2si (__m128 __A) +{ + return _mm_cvtss_si32 (__A); +} + +#ifdef __x86_64__ +/* Convert the lower SPFP value to a 32-bit integer according to the current + rounding mode. */ +static __inline long long +_mm_cvtss_si64x (__m128 __A) +{ + return __builtin_ia32_cvtss2si64 ((__v4sf) __A); +} +#endif + +/* Convert the two lower SPFP values to 32-bit integers according to the + current rounding mode. Return the integers in packed form. */ +static __inline __m64 +_mm_cvtps_pi32 (__m128 __A) +{ + return (__m64) __builtin_ia32_cvtps2pi ((__v4sf) __A); +} + +static __inline __m64 +_mm_cvt_ps2pi (__m128 __A) +{ + return _mm_cvtps_pi32 (__A); +} + +/* Truncate the lower SPFP value to a 32-bit integer. */ +static __inline int +_mm_cvttss_si32 (__m128 __A) +{ + return __builtin_ia32_cvttss2si ((__v4sf) __A); +} + +static __inline int +_mm_cvtt_ss2si (__m128 __A) +{ + return _mm_cvttss_si32 (__A); +} + +#ifdef __x86_64__ +/* Truncate the lower SPFP value to a 32-bit integer. */ +static __inline long long +_mm_cvttss_si64x (__m128 __A) +{ + return __builtin_ia32_cvttss2si64 ((__v4sf) __A); +} +#endif + +/* Truncate the two lower SPFP values to 32-bit integers. Return the + integers in packed form. */ +static __inline __m64 +_mm_cvttps_pi32 (__m128 __A) +{ + return (__m64) __builtin_ia32_cvttps2pi ((__v4sf) __A); +} + +static __inline __m64 +_mm_cvtt_ps2pi (__m128 __A) +{ + return _mm_cvttps_pi32 (__A); +} + +/* Convert B to a SPFP value and insert it as element zero in A. */ +static __inline __m128 +_mm_cvtsi32_ss (__m128 __A, int __B) +{ + return (__m128) __builtin_ia32_cvtsi2ss ((__v4sf) __A, __B); +} + +static __inline __m128 +_mm_cvt_si2ss (__m128 __A, int __B) +{ + return _mm_cvtsi32_ss (__A, __B); +} + +#ifdef __x86_64__ +/* Convert B to a SPFP value and insert it as element zero in A. */ +static __inline __m128 +_mm_cvtsi64x_ss (__m128 __A, long long __B) +{ + return (__m128) __builtin_ia32_cvtsi642ss ((__v4sf) __A, __B); +} +#endif + +/* Convert the two 32-bit values in B to SPFP form and insert them + as the two lower elements in A. */ +static __inline __m128 +_mm_cvtpi32_ps (__m128 __A, __m64 __B) +{ + return (__m128) __builtin_ia32_cvtpi2ps ((__v4sf) __A, (__v2si)__B); +} + +static __inline __m128 +_mm_cvt_pi2ps (__m128 __A, __m64 __B) +{ + return _mm_cvtpi32_ps (__A, __B); +} + +/* Convert the four signed 16-bit values in A to SPFP form. */ +static __inline __m128 +_mm_cvtpi16_ps (__m64 __A) +{ + __v4hi __sign; + __v2si __hisi, __losi; + __v4sf __r; + + /* This comparison against zero gives us a mask that can be used to + fill in the missing sign bits in the unpack operations below, so + that we get signed values after unpacking. */ + __sign = (__v4hi) __builtin_ia32_mmx_zero (); + __sign = __builtin_ia32_pcmpgtw (__sign, (__v4hi)__A); + + /* Convert the four words to doublewords. */ + __hisi = (__v2si) __builtin_ia32_punpckhwd ((__v4hi)__A, __sign); + __losi = (__v2si) __builtin_ia32_punpcklwd ((__v4hi)__A, __sign); + + /* Convert the doublewords to floating point two at a time. */ + __r = (__v4sf) __builtin_ia32_setzerops (); + __r = __builtin_ia32_cvtpi2ps (__r, __hisi); + __r = __builtin_ia32_movlhps (__r, __r); + __r = __builtin_ia32_cvtpi2ps (__r, __losi); + + return (__m128) __r; +} + +/* Convert the four unsigned 16-bit values in A to SPFP form. */ +static __inline __m128 +_mm_cvtpu16_ps (__m64 __A) +{ + __v4hi __zero = (__v4hi) __builtin_ia32_mmx_zero (); + __v2si __hisi, __losi; + __v4sf __r; + + /* Convert the four words to doublewords. */ + __hisi = (__v2si) __builtin_ia32_punpckhwd ((__v4hi)__A, __zero); + __losi = (__v2si) __builtin_ia32_punpcklwd ((__v4hi)__A, __zero); + + /* Convert the doublewords to floating point two at a time. */ + __r = (__v4sf) __builtin_ia32_setzerops (); + __r = __builtin_ia32_cvtpi2ps (__r, __hisi); + __r = __builtin_ia32_movlhps (__r, __r); + __r = __builtin_ia32_cvtpi2ps (__r, __losi); + + return (__m128) __r; +} + +/* Convert the low four signed 8-bit values in A to SPFP form. */ +static __inline __m128 +_mm_cvtpi8_ps (__m64 __A) +{ + __v8qi __sign; + + /* This comparison against zero gives us a mask that can be used to + fill in the missing sign bits in the unpack operations below, so + that we get signed values after unpacking. */ + __sign = (__v8qi) __builtin_ia32_mmx_zero (); + __sign = __builtin_ia32_pcmpgtb (__sign, (__v8qi)__A); + + /* Convert the four low bytes to words. */ + __A = (__m64) __builtin_ia32_punpcklbw ((__v8qi)__A, __sign); + + return _mm_cvtpi16_ps(__A); +} + +/* Convert the low four unsigned 8-bit values in A to SPFP form. */ +static __inline __m128 +_mm_cvtpu8_ps(__m64 __A) +{ + __v8qi __zero = (__v8qi) __builtin_ia32_mmx_zero (); + __A = (__m64) __builtin_ia32_punpcklbw ((__v8qi)__A, __zero); + return _mm_cvtpu16_ps(__A); +} + +/* Convert the four signed 32-bit values in A and B to SPFP form. */ +static __inline __m128 +_mm_cvtpi32x2_ps(__m64 __A, __m64 __B) +{ + __v4sf __zero = (__v4sf) __builtin_ia32_setzerops (); + __v4sf __sfa = __builtin_ia32_cvtpi2ps (__zero, (__v2si)__A); + __v4sf __sfb = __builtin_ia32_cvtpi2ps (__zero, (__v2si)__B); + return (__m128) __builtin_ia32_movlhps (__sfa, __sfb); +} + +/* Convert the four SPFP values in A to four signed 16-bit integers. */ +static __inline __m64 +_mm_cvtps_pi16(__m128 __A) +{ + __v4sf __hisf = (__v4sf)__A; + __v4sf __losf = __builtin_ia32_movhlps (__hisf, __hisf); + __v2si __hisi = __builtin_ia32_cvtps2pi (__hisf); + __v2si __losi = __builtin_ia32_cvtps2pi (__losf); + return (__m64) __builtin_ia32_packssdw (__hisi, __losi); +} + +/* Convert the four SPFP values in A to four signed 8-bit integers. */ +static __inline __m64 +_mm_cvtps_pi8(__m128 __A) +{ + __v4hi __tmp = (__v4hi) _mm_cvtps_pi16 (__A); + __v4hi __zero = (__v4hi) __builtin_ia32_mmx_zero (); + return (__m64) __builtin_ia32_packsswb (__tmp, __zero); +} + +/* Selects four specific SPFP values from A and B based on MASK. */ +#if 0 +static __inline __m128 +_mm_shuffle_ps (__m128 __A, __m128 __B, int __mask) +{ + return (__m128) __builtin_ia32_shufps ((__v4sf)__A, (__v4sf)__B, __mask); +} +#else +#define _mm_shuffle_ps(A, B, MASK) \ + ((__m128) __builtin_ia32_shufps ((__v4sf)(A), (__v4sf)(B), (MASK))) +#endif + + +/* Selects and interleaves the upper two SPFP values from A and B. */ +static __inline __m128 +_mm_unpackhi_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_unpckhps ((__v4sf)__A, (__v4sf)__B); +} + +/* Selects and interleaves the lower two SPFP values from A and B. */ +static __inline __m128 +_mm_unpacklo_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_unpcklps ((__v4sf)__A, (__v4sf)__B); +} + +/* Sets the upper two SPFP values with 64-bits of data loaded from P; + the lower two values are passed through from A. */ +static __inline __m128 +_mm_loadh_pi (__m128 __A, __m64 const *__P) +{ + return (__m128) __builtin_ia32_loadhps ((__v4sf)__A, (__v2si *)__P); +} + +/* Stores the upper two SPFP values of A into P. */ +static __inline void +_mm_storeh_pi (__m64 *__P, __m128 __A) +{ + __builtin_ia32_storehps ((__v2si *)__P, (__v4sf)__A); +} + +/* Moves the upper two values of B into the lower two values of A. */ +static __inline __m128 +_mm_movehl_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_movhlps ((__v4sf)__A, (__v4sf)__B); +} + +/* Moves the lower two values of B into the upper two values of A. */ +static __inline __m128 +_mm_movelh_ps (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_movlhps ((__v4sf)__A, (__v4sf)__B); +} + +/* Sets the lower two SPFP values with 64-bits of data loaded from P; + the upper two values are passed through from A. */ +static __inline __m128 +_mm_loadl_pi (__m128 __A, __m64 const *__P) +{ + return (__m128) __builtin_ia32_loadlps ((__v4sf)__A, (__v2si *)__P); +} + +/* Stores the lower two SPFP values of A into P. */ +static __inline void +_mm_storel_pi (__m64 *__P, __m128 __A) +{ + __builtin_ia32_storelps ((__v2si *)__P, (__v4sf)__A); +} + +/* Creates a 4-bit mask from the most significant bits of the SPFP values. */ +static __inline int +_mm_movemask_ps (__m128 __A) +{ + return __builtin_ia32_movmskps ((__v4sf)__A); +} + +/* Return the contents of the control register. */ +static __inline unsigned int +_mm_getcsr (void) +{ + return __builtin_ia32_stmxcsr (); +} + +/* Read exception bits from the control register. */ +static __inline unsigned int +_MM_GET_EXCEPTION_STATE (void) +{ + return _mm_getcsr() & _MM_EXCEPT_MASK; +} + +static __inline unsigned int +_MM_GET_EXCEPTION_MASK (void) +{ + return _mm_getcsr() & _MM_MASK_MASK; +} + +static __inline unsigned int +_MM_GET_ROUNDING_MODE (void) +{ + return _mm_getcsr() & _MM_ROUND_MASK; +} + +static __inline unsigned int +_MM_GET_FLUSH_ZERO_MODE (void) +{ + return _mm_getcsr() & _MM_FLUSH_ZERO_MASK; +} + +/* Set the control register to I. */ +static __inline void +_mm_setcsr (unsigned int __I) +{ + __builtin_ia32_ldmxcsr (__I); +} + +/* Set exception bits in the control register. */ +static __inline void +_MM_SET_EXCEPTION_STATE(unsigned int __mask) +{ + _mm_setcsr((_mm_getcsr() & ~_MM_EXCEPT_MASK) | __mask); +} + +static __inline void +_MM_SET_EXCEPTION_MASK (unsigned int __mask) +{ + _mm_setcsr((_mm_getcsr() & ~_MM_MASK_MASK) | __mask); +} + +static __inline void +_MM_SET_ROUNDING_MODE (unsigned int __mode) +{ + _mm_setcsr((_mm_getcsr() & ~_MM_ROUND_MASK) | __mode); +} + +static __inline void +_MM_SET_FLUSH_ZERO_MODE (unsigned int __mode) +{ + _mm_setcsr((_mm_getcsr() & ~_MM_FLUSH_ZERO_MASK) | __mode); +} + +/* Create a vector with element 0 as *P and the rest zero. */ +static __inline __m128 +_mm_load_ss (float const *__P) +{ + return (__m128) __builtin_ia32_loadss (__P); +} + +/* Create a vector with all four elements equal to *P. */ +static __inline __m128 +_mm_load1_ps (float const *__P) +{ + __v4sf __tmp = __builtin_ia32_loadss (__P); + return (__m128) __builtin_ia32_shufps (__tmp, __tmp, _MM_SHUFFLE (0,0,0,0)); +} + +static __inline __m128 +_mm_load_ps1 (float const *__P) +{ + return _mm_load1_ps (__P); +} + +/* Load four SPFP values from P. The address must be 16-byte aligned. */ +static __inline __m128 +_mm_load_ps (float const *__P) +{ + return (__m128) __builtin_ia32_loadaps (__P); +} + +/* Load four SPFP values from P. The address need not be 16-byte aligned. */ +static __inline __m128 +_mm_loadu_ps (float const *__P) +{ + return (__m128) __builtin_ia32_loadups (__P); +} + +/* Load four SPFP values in reverse order. The address must be aligned. */ +static __inline __m128 +_mm_loadr_ps (float const *__P) +{ + __v4sf __tmp = __builtin_ia32_loadaps (__P); + return (__m128) __builtin_ia32_shufps (__tmp, __tmp, _MM_SHUFFLE (0,1,2,3)); +} + +/* Create a vector with element 0 as F and the rest zero. */ +static __inline __m128 +_mm_set_ss (float __F) +{ + return (__m128) __builtin_ia32_loadss (&__F); +} + +/* Create a vector with all four elements equal to F. */ +static __inline __m128 +_mm_set1_ps (float __F) +{ + __v4sf __tmp = __builtin_ia32_loadss (&__F); + return (__m128) __builtin_ia32_shufps (__tmp, __tmp, _MM_SHUFFLE (0,0,0,0)); +} + +static __inline __m128 +_mm_set_ps1 (float __F) +{ + return _mm_set1_ps (__F); +} + +/* Create the vector [Z Y X W]. */ +static __inline __m128 +_mm_set_ps (float __Z, float __Y, float __X, float __W) +{ + union { + float __a[4]; + __m128 __v; + } __u; + + __u.__a[0] = __W; + __u.__a[1] = __X; + __u.__a[2] = __Y; + __u.__a[3] = __Z; + + return __u.__v; +} + +/* Create the vector [W X Y Z]. */ +static __inline __m128 +_mm_setr_ps (float __Z, float __Y, float __X, float __W) +{ + return _mm_set_ps (__W, __X, __Y, __Z); +} + +/* Create a vector of zeros. */ +static __inline __m128 +_mm_setzero_ps (void) +{ + return (__m128) __builtin_ia32_setzerops (); +} + +/* Stores the lower SPFP value. */ +static __inline void +_mm_store_ss (float *__P, __m128 __A) +{ + __builtin_ia32_storess (__P, (__v4sf)__A); +} + +/* Store the lower SPFP value across four words. */ +static __inline void +_mm_store1_ps (float *__P, __m128 __A) +{ + __v4sf __va = (__v4sf)__A; + __v4sf __tmp = __builtin_ia32_shufps (__va, __va, _MM_SHUFFLE (0,0,0,0)); + __builtin_ia32_storeaps (__P, __tmp); +} + +static __inline void +_mm_store_ps1 (float *__P, __m128 __A) +{ + _mm_store1_ps (__P, __A); +} + +/* Store four SPFP values. The address must be 16-byte aligned. */ +static __inline void +_mm_store_ps (float *__P, __m128 __A) +{ + __builtin_ia32_storeaps (__P, (__v4sf)__A); +} + +/* Store four SPFP values. The address need not be 16-byte aligned. */ +static __inline void +_mm_storeu_ps (float *__P, __m128 __A) +{ + __builtin_ia32_storeups (__P, (__v4sf)__A); +} + +/* Store four SPFP values in reverse order. The address must be aligned. */ +static __inline void +_mm_storer_ps (float *__P, __m128 __A) +{ + __v4sf __va = (__v4sf)__A; + __v4sf __tmp = __builtin_ia32_shufps (__va, __va, _MM_SHUFFLE (0,1,2,3)); + __builtin_ia32_storeaps (__P, __tmp); +} + +/* Sets the low SPFP value of A from the low value of B. */ +static __inline __m128 +_mm_move_ss (__m128 __A, __m128 __B) +{ + return (__m128) __builtin_ia32_movss ((__v4sf)__A, (__v4sf)__B); +} + +/* Extracts one of the four words of A. The selector N must be immediate. */ +#if 0 +static __inline int +_mm_extract_pi16 (__m64 __A, int __N) +{ + return __builtin_ia32_pextrw ((__v4hi)__A, __N); +} + +static __inline int +_m_pextrw (__m64 __A, int __N) +{ + return _mm_extract_pi16 (__A, __N); +} +#else +#define _mm_extract_pi16(A, N) \ + __builtin_ia32_pextrw ((__v4hi)(A), (N)) +#define _m_pextrw(A, N) _mm_extract_pi16((A), (N)) +#endif + +/* Inserts word D into one of four words of A. The selector N must be + immediate. */ +#if 0 +static __inline __m64 +_mm_insert_pi16 (__m64 __A, int __D, int __N) +{ + return (__m64)__builtin_ia32_pinsrw ((__v4hi)__A, __D, __N); +} + +static __inline __m64 +_m_pinsrw (__m64 __A, int __D, int __N) +{ + return _mm_insert_pi16 (__A, __D, __N); +} +#else +#define _mm_insert_pi16(A, D, N) \ + ((__m64) __builtin_ia32_pinsrw ((__v4hi)(A), (D), (N))) +#define _m_pinsrw(A, D, N) _mm_insert_pi16((A), (D), (N)) +#endif + +/* Compute the element-wise maximum of signed 16-bit values. */ +static __inline __m64 +_mm_max_pi16 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_pmaxsw ((__v4hi)__A, (__v4hi)__B); +} + +static __inline __m64 +_m_pmaxsw (__m64 __A, __m64 __B) +{ + return _mm_max_pi16 (__A, __B); +} + +/* Compute the element-wise maximum of unsigned 8-bit values. */ +static __inline __m64 +_mm_max_pu8 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_pmaxub ((__v8qi)__A, (__v8qi)__B); +} + +static __inline __m64 +_m_pmaxub (__m64 __A, __m64 __B) +{ + return _mm_max_pu8 (__A, __B); +} + +/* Compute the element-wise minimum of signed 16-bit values. */ +static __inline __m64 +_mm_min_pi16 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_pminsw ((__v4hi)__A, (__v4hi)__B); +} + +static __inline __m64 +_m_pminsw (__m64 __A, __m64 __B) +{ + return _mm_min_pi16 (__A, __B); +} + +/* Compute the element-wise minimum of unsigned 8-bit values. */ +static __inline __m64 +_mm_min_pu8 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_pminub ((__v8qi)__A, (__v8qi)__B); +} + +static __inline __m64 +_m_pminub (__m64 __A, __m64 __B) +{ + return _mm_min_pu8 (__A, __B); +} + +/* Create an 8-bit mask of the signs of 8-bit values. */ +static __inline int +_mm_movemask_pi8 (__m64 __A) +{ + return __builtin_ia32_pmovmskb ((__v8qi)__A); +} + +static __inline int +_m_pmovmskb (__m64 __A) +{ + return _mm_movemask_pi8 (__A); +} + +/* Multiply four unsigned 16-bit values in A by four unsigned 16-bit values + in B and produce the high 16 bits of the 32-bit results. */ +static __inline __m64 +_mm_mulhi_pu16 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_pmulhuw ((__v4hi)__A, (__v4hi)__B); +} + +static __inline __m64 +_m_pmulhuw (__m64 __A, __m64 __B) +{ + return _mm_mulhi_pu16 (__A, __B); +} + +/* Return a combination of the four 16-bit values in A. The selector + must be an immediate. */ +#if 0 +static __inline __m64 +_mm_shuffle_pi16 (__m64 __A, int __N) +{ + return (__m64) __builtin_ia32_pshufw ((__v4hi)__A, __N); +} + +static __inline __m64 +_m_pshufw (__m64 __A, int __N) +{ + return _mm_shuffle_pi16 (__A, __N); +} +#else +#define _mm_shuffle_pi16(A, N) \ + ((__m64) __builtin_ia32_pshufw ((__v4hi)(A), (N))) +#define _m_pshufw(A, N) _mm_shuffle_pi16 ((A), (N)) +#endif + +/* Conditionally store byte elements of A into P. The high bit of each + byte in the selector N determines whether the corresponding byte from + A is stored. */ +static __inline void +_mm_maskmove_si64 (__m64 __A, __m64 __N, char *__P) +{ + __builtin_ia32_maskmovq ((__v8qi)__A, (__v8qi)__N, __P); +} + +static __inline void +_m_maskmovq (__m64 __A, __m64 __N, char *__P) +{ + _mm_maskmove_si64 (__A, __N, __P); +} + +/* Compute the rounded averages of the unsigned 8-bit values in A and B. */ +static __inline __m64 +_mm_avg_pu8 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_pavgb ((__v8qi)__A, (__v8qi)__B); +} + +static __inline __m64 +_m_pavgb (__m64 __A, __m64 __B) +{ + return _mm_avg_pu8 (__A, __B); +} + +/* Compute the rounded averages of the unsigned 16-bit values in A and B. */ +static __inline __m64 +_mm_avg_pu16 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_pavgw ((__v4hi)__A, (__v4hi)__B); +} + +static __inline __m64 +_m_pavgw (__m64 __A, __m64 __B) +{ + return _mm_avg_pu16 (__A, __B); +} + +/* Compute the sum of the absolute differences of the unsigned 8-bit + values in A and B. Return the value in the lower 16-bit word; the + upper words are cleared. */ +static __inline __m64 +_mm_sad_pu8 (__m64 __A, __m64 __B) +{ + return (__m64) __builtin_ia32_psadbw ((__v8qi)__A, (__v8qi)__B); +} + +static __inline __m64 +_m_psadbw (__m64 __A, __m64 __B) +{ + return _mm_sad_pu8 (__A, __B); +} + +/* Loads one cache line from address P to a location "closer" to the + processor. The selector I specifies the type of prefetch operation. */ +#if 0 +static __inline void +_mm_prefetch (void *__P, enum _mm_hint __I) +{ + __builtin_prefetch (__P, 0, __I); +} +#else +#define _mm_prefetch(P, I) \ + __builtin_prefetch ((P), 0, (I)) +#endif + +/* Stores the data in A to the address P without polluting the caches. */ +static __inline void +_mm_stream_pi (__m64 *__P, __m64 __A) +{ + __builtin_ia32_movntq ((unsigned long long *)__P, (unsigned long long)__A); +} + +/* Likewise. The address must be 16-byte aligned. */ +static __inline void +_mm_stream_ps (float *__P, __m128 __A) +{ + __builtin_ia32_movntps (__P, (__v4sf)__A); +} + +/* Guarantees that every preceeding store is globally visible before + any subsequent store. */ +static __inline void +_mm_sfence (void) +{ + __builtin_ia32_sfence (); +} + +/* The execution of the next instruction is delayed by an implementation + specific amount of time. The instruction does not modify the + architectural state. */ +static __inline void +_mm_pause (void) +{ + __asm__ __volatile__ ("rep; nop" : : ); +} + +/* Transpose the 4x4 matrix composed of row[0-3]. */ +#define _MM_TRANSPOSE4_PS(row0, row1, row2, row3) \ +do { \ + __v4sf __r0 = (row0), __r1 = (row1), __r2 = (row2), __r3 = (row3); \ + __v4sf __t0 = __builtin_ia32_shufps (__r0, __r1, 0x44); \ + __v4sf __t2 = __builtin_ia32_shufps (__r0, __r1, 0xEE); \ + __v4sf __t1 = __builtin_ia32_shufps (__r2, __r3, 0x44); \ + __v4sf __t3 = __builtin_ia32_shufps (__r2, __r3, 0xEE); \ + (row0) = __builtin_ia32_shufps (__t0, __t1, 0x88); \ + (row1) = __builtin_ia32_shufps (__t0, __t1, 0xDD); \ + (row2) = __builtin_ia32_shufps (__t2, __t3, 0x88); \ + (row3) = __builtin_ia32_shufps (__t2, __t3, 0xDD); \ +} while (0) + +/* For backward source compatibility. */ +#include + +#endif /* __SSE__ */ +#endif /* _XMMINTRIN_H_INCLUDED */ diff --git a/src/include/ypclnt.h b/src/include/ypclnt.h new file mode 100644 index 0000000..48537e6 --- /dev/null +++ b/src/include/ypclnt.h @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2002 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by ThinkSec AS and + * NAI Labs, the Security Research Division of Network Associates, Inc. + * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the + * DARPA CHATS research program. + * + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libypclnt/ypclnt.h,v 1.2 2002/05/08 00:48:39 des Exp $ + */ + +#ifndef _YPCLNT_H_INCLUDED + +typedef struct ypclnt ypclnt_t; +struct ypclnt { + char *domain; /* Domain name */ + char *map; /* Map name */ + char *server; /* Server name */ + char *error; /* Error message */ +}; + +struct passwd; + +ypclnt_t *ypclnt_new(const char *, const char *, const char *); +void ypclnt_free(ypclnt_t *); +void ypclnt_error(ypclnt_t *, const char *, const char *, ...); +int ypclnt_connect(ypclnt_t *); +int ypclnt_havepasswdd(ypclnt_t *); +int ypclnt_passwd(ypclnt_t *, const struct passwd *, const char *); + +#if defined(DEBUG) && defined(__GNUC__) +#define YPCLNT_DEBUG(fmt...) warnx(__FUNCTION__ ": " fmt, ##fmt) +#else +#define YPCLNT_DEBUG(fmt...) +#endif + +#endif diff --git a/src/include/zconf.h b/src/include/zconf.h new file mode 100644 index 0000000..ae3ecee --- /dev/null +++ b/src/include/zconf.h @@ -0,0 +1,281 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2002 Jean-loup Gailly. + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $FreeBSD: src/lib/libz/zconf.h,v 1.7 2002/03/11 22:36:26 green Exp $ */ + +#ifndef _ZCONF_H +#define _ZCONF_H + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + */ +#ifdef Z_PREFIX +# define deflateInit_ z_deflateInit_ +# define deflate z_deflate +# define deflateEnd z_deflateEnd +# define inflateInit_ z_inflateInit_ +# define inflate z_inflate +# define inflateEnd z_inflateEnd +# define deflateInit2_ z_deflateInit2_ +# define deflateSetDictionary z_deflateSetDictionary +# define deflateCopy z_deflateCopy +# define deflateReset z_deflateReset +# define deflateParams z_deflateParams +# define inflateInit2_ z_inflateInit2_ +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateReset z_inflateReset +# define compress z_compress +# define compress2 z_compress2 +# define uncompress z_uncompress +# define adler32 z_adler32 +# define crc32 z_crc32 +# define get_crc_table z_get_crc_table + +# define Byte z_Byte +# define uInt z_uInt +# define uLong z_uLong +# define Bytef z_Bytef +# define charf z_charf +# define intf z_intf +# define uIntf z_uIntf +# define uLongf z_uLongf +# define voidpf z_voidpf +# define voidp z_voidp +#endif + +#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) +# define WIN32 +#endif +#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386) +# ifndef __32BIT__ +# define __32BIT__ +# endif +#endif +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#if defined(MSDOS) && !defined(__32BIT__) +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC) +# define STDC +#endif +#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__) +# ifndef STDC +# define STDC +# endif +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const +# endif +#endif + +/* Some Mac compilers merge all .h files incorrectly: */ +#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__) +# define NO_DUMMY_DECL +#endif + +/* Old Borland C incorrectly complains about missing returns: */ +#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) +# define NEED_DUMMY_RETURN +#endif + + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus a few kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +#endif +#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__)) +# ifndef __32BIT__ +# define SMALL_MEDIUM +# define FAR _far +# endif +#endif + +/* Compile with -DZLIB_DLL for Windows DLL support */ +#if defined(ZLIB_DLL) +# if defined(_WINDOWS) || defined(WINDOWS) +# ifdef FAR +# undef FAR +# endif +# include +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR _cdecl _export +# endif +# endif +# if defined (__BORLANDC__) +# if (__BORLANDC__ >= 0x0500) && defined (WIN32) +# include +# define ZEXPORT __declspec(dllexport) WINAPI +# define ZEXPORTRVA __declspec(dllexport) WINAPIV +# else +# if defined (_Windows) && defined (__DLL__) +# define ZEXPORT _export +# define ZEXPORTVA _export +# endif +# endif +# endif +#endif + +#if defined (__BEOS__) +# if defined (ZLIB_DLL) +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +#endif + +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif +#ifndef ZEXTERN +# define ZEXTERN extern +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(MACOS) && !defined(TARGET_OS_MAC) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#ifdef HAVE_UNISTD_H +# include /* for off_t */ +# include /* for SEEK_* and off_t */ +#endif +#ifndef SEEK_SET +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +/* + * This is hard-configured for FreeBSD, since zlib doesn't actually support + * using the system off_t for offsets unless off_t is no longer than long. + */ +#define z_off_t long + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) +# pragma map(deflateInit_,"DEIN") +# pragma map(deflateInit2_,"DEIN2") +# pragma map(deflateEnd,"DEEND") +# pragma map(inflateInit_,"ININ") +# pragma map(inflateInit2_,"ININ2") +# pragma map(inflateEnd,"INEND") +# pragma map(inflateSync,"INSY") +# pragma map(inflateSetDictionary,"INSEDI") +# pragma map(inflate_blocks,"INBL") +# pragma map(inflate_blocks_new,"INBLNE") +# pragma map(inflate_blocks_free,"INBLFR") +# pragma map(inflate_blocks_reset,"INBLRE") +# pragma map(inflate_codes_free,"INCOFR") +# pragma map(inflate_codes,"INCO") +# pragma map(inflate_fast,"INFA") +# pragma map(inflate_flush,"INFLU") +# pragma map(inflate_mask,"INMA") +# pragma map(inflate_set_dictionary,"INSEDI2") +# pragma map(inflate_copyright,"INCOPY") +# pragma map(inflate_trees_bits,"INTRBI") +# pragma map(inflate_trees_dynamic,"INTRDY") +# pragma map(inflate_trees_fixed,"INTRFI") +# pragma map(inflate_trees_free,"INTRFR") +#endif + +#endif /* _ZCONF_H */ diff --git a/src/include/zlib.h b/src/include/zlib.h new file mode 100644 index 0000000..52cb529 --- /dev/null +++ b/src/include/zlib.h @@ -0,0 +1,893 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.1.4, March 11th, 2002 + + Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt + (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). +*/ + +#ifndef _ZLIB_H +#define _ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.1.4" + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed + data. This version of the library supports only one compression method + (deflation) but other algorithms will be added later and will have the same + stream interface. + + Compression can be done in a single step if the buffers are large + enough (for example if an input file is mmap'ed), or can be done by + repeated calls of the compression function. In the latter case, the + application must provide more input and/or consume the output + (providing more output space) before each call. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never + crash even in case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total nb of input bytes read so far */ + + Bytef *next_out; /* next output byte should be put there */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total nb of bytes output so far */ + + char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: ascii or binary */ + uLong adler; /* adler32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + The application must update next_in and avail_in when avail_in has + dropped to zero. It must update next_out and avail_out when avail_out + has dropped to zero. The application must initialize zalloc, zfree and + opaque before calling the init function. All other fields are set by the + compression library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this + if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, + pointers returned by zalloc for objects of exactly 65536 bytes *must* + have their offset normalized to zero. The default allocation function + provided by this library ensures this (see zutil.c). To reduce memory + requirements and avoid any allocation of 64K objects, at the expense of + compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or + progress reports. After compression, total_in holds the total size of + the uncompressed data and may be saved for use in the decompressor + (particularly if the decompressor wants to decompress everything in + a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +/* Allowed flush values; see deflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative + * values are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_ASCII 1 +#define Z_UNKNOWN 2 +/* Possible values of the data_type field */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is + not compatible with the zlib.h header file used by the application. + This check is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. + If zalloc and zfree are set to Z_NULL, deflateInit updates them to + use default allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at + all (the input data is simply copied a block at a time). + Z_DEFAULT_COMPRESSION requests a default compromise between speed and + compression (currently equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if level is not a valid compression level, + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). + msg is set to null if there is no error message. deflateInit does not + perform any compression: this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce some + output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary (in interactive applications). + Some output may be provided even if flush is not set. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating avail_in or avail_out accordingly; avail_out + should never be zero before the call. The application can consume the + compressed output when it wants, for example when the output buffer is full + (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK + and with zero avail_out, it must be called again after making room in the + output buffer because there might be more output pending. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In particular + avail_in is zero after the call if enough output space has been provided + before the call.) Flushing may degrade compression for some compression + algorithms and so it should be used only when necessary. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + the compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there + was enough output space; if deflate returns with Z_OK, this function must be + called again with Z_FINISH and more output space (updated avail_out) but no + more input data, until it returns with Z_STREAM_END or an error. After + deflate has returned Z_STREAM_END, the only possible operations on the + stream are deflateReset or deflateEnd. + + Z_FINISH can be used immediately after deflateInit if all the compression + is to be done in a single step. In this case, avail_out must be at least + 0.1% larger than avail_in plus 12 bytes. If deflate does not return + Z_STREAM_END, then it must be called again as described above. + + deflate() sets strm->adler to the adler32 checksum of all input read + so far (that is, total_in bytes). + + deflate() may update data_type if it can make a good guess about + the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered + binary. This field is only for information purposes and does not affect + the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible + (for example avail_in or avail_out was zero). +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, + msg may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. If next_in is not Z_NULL and avail_in is large enough (the exact + value depends on the compression method), inflateInit determines the + compression method from the zlib header and allocates all data structures + accordingly; otherwise the allocation will be deferred to the first call of + inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to + use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller. msg is set to null if there is no error + message. inflateInit does not perform any decompression apart from reading + the zlib header if present: this will be done by inflate(). (So next_in and + avail_in may be modified, but next_out and avail_out are unchanged.) +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may some + introduce some output latency (reading input without producing any output) + except when forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in is updated and processing + will resume at this point for the next call of inflate(). + + - Provide more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there + is no more input data or no more space in the output buffer (see below + about the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming + more output, and updating the next_* and avail_* values accordingly. + The application can consume the uncompressed output when it wants, for + example when the output buffer is full (avail_out == 0), or after each + call of inflate(). If inflate returns Z_OK and with zero avail_out, it + must be called again after making room in the output buffer because there + might be more output pending. + + If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much + output as possible to the output buffer. The flushing behavior of inflate is + not specified for values of the flush parameter other than Z_SYNC_FLUSH + and Z_FINISH, but the current implementation actually flushes as much output + as possible anyway. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step + (a single call of inflate), the parameter flush should be set to + Z_FINISH. In this case all pending input is processed and all pending + output is flushed; avail_out must be large enough to hold all the + uncompressed data. (The size of the uncompressed data may have been saved + by the compressor for this purpose.) The next operation on this stream must + be inflateEnd to deallocate the decompression state. The use of Z_FINISH + is never required, but can be used to inform inflate that a faster routine + may be used for the single inflate() call. + + If a preset dictionary is needed at this point (see inflateSetDictionary + below), inflate sets strm-adler to the adler32 checksum of the + dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise + it sets strm->adler to the adler32 checksum of all output produced + so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or + an error code as described below. At the end of the stream, inflate() + checks that its computed adler32 checksum is equal to that saved by the + compressor and returns Z_STREAM_END only if the checksum is correct. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect + adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent + (for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if no progress is possible or if there was not + enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR + case, the application may then call inflateSync to look for a good + compression block. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any + pending output. + + inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state + was inconsistent. In the error case, msg may be set but then points to a + static string (which must not be deallocated). +*/ + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by + the caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but + is slow and reduces compression ratio; memLevel=9 uses maximum memory + for optimal speed. The default value is 8. See zconf.h for total memory + usage as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match). Filtered data consists mostly of small values with a + somewhat random distribution. In this case, the compression algorithm is + tuned to compress them better. The effect of Z_FILTERED is to force more + Huffman coding and less string matching; it is somewhat intermediate + between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects + the compression ratio but not the correctness of the compressed output even + if it is not set appropriately. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid + method). msg is set to null if there is no error message. deflateInit2 does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. This function must be called + immediately after deflateInit, deflateInit2 or deflateReset, before any + call of deflate. The compressor and decompressor must use exactly the same + dictionary (see inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size in + deflate or deflate2. Thus the strings most likely to be useful should be + put at the end of the dictionary, not at the front. + + Upon return of this function, strm->adler is set to the Adler32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The Adler32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if the compression method is bsort). deflateSetDictionary does not + perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and + can consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, + but does not free and reallocate all the internal compression state. + The stream will keep the same compression level and any other attributes + that may have been set by deflateInit2. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2. This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different + strategy. If the compression level is changed, the input available so far + is compressed with the old level (and may be flushed); the new level will + take effect only at the next call of deflate(). + + Before the call of deflateParams, the stream state must be set as for + a call of deflate(), since the currently available input may have to + be compressed and flushed. In particular, strm->avail_out must be non-zero. + + deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source + stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR + if strm->avail_out was zero. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. If a compressed stream with a larger window size is given as + input, inflate() will return with the error code Z_DATA_ERROR instead of + trying to allocate a larger window. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative + memLevel). msg is set to null if there is no error message. inflateInit2 + does not perform any decompression apart from reading the zlib header if + present: this will be done by inflate(). (So next_in and avail_in may be + modified, but next_out and avail_out are unchanged.) +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate + if this call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the Adler32 value returned by this call of + inflate. The compressor and decompressor must use exactly the same + dictionary (see deflateSetDictionary). + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (such as NULL dictionary) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect Adler32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a full flush point (see above the + description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR + if no more input was provided, Z_DATA_ERROR if no flush point has been found, + or Z_STREAM_ERROR if the stream structure was inconsistent. In the success + case, the application may save the current current value of total_in which + indicates where valid compressed data was found. In the error case, the + application may repeatedly call inflateSync, providing more input each time, + until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate all the internal decompression state. + The stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being NULL). +*/ + + + /* utility functions */ + +/* + The following utility functions are implemented on top of the + basic stream-oriented functions. To simplify the interface, some + default options are assumed (compression level and memory usage, + standard memory allocation functions). The source code of these + utility functions can easily be modified if you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be at least 0.1% larger than + sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the + compressed buffer. + This function can be used to compress a whole file at once if the + input file is mmap'ed. + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least 0.1% larger than sourceLen plus + 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total + size of the destination buffer, which must be large enough to hold the + entire uncompressed data. (The size of the uncompressed data must have + been saved previously by the compressor and transmitted to the decompressor + by some mechanism outside the scope of this compression library.) + Upon exit, destLen is the actual size of the compressed buffer. + This function can be used to decompress a whole file at once if the + input file is mmap'ed. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted. +*/ + + +typedef voidp gzFile; + +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +/* + Opens a gzip (.gz) file for reading or writing. The mode parameter + is as in fopen ("rb" or "wb") but can also include a compression level + ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for + Huffman only compression as in "wb1h". (See the description + of deflateInit2 for more information about the strategy parameter.) + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. + + gzopen returns NULL if the file could not be opened or if there was + insufficient memory to allocate the (de)compression state; errno + can be checked to distinguish the two cases (if errno is zero, the + zlib error is Z_MEM_ERROR). */ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen() associates a gzFile with the file descriptor fd. File + descriptors are obtained from calls like open, dup, creat, pipe or + fileno (in the file has been previously opened with fopen). + The mode parameter is as in gzopen. + The next call of gzclose on the returned gzFile will also close the + file descriptor fd, just like fclose(fdopen(fd), mode) closes the file + descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). + gzdopen returns NULL if there was insufficient memory to allocate + the (de)compression state. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. + gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not + opened for writing. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. + If the input file was not in gzip format, gzread copies the given number + of bytes into the buffer. + gzread returns the number of uncompressed bytes actually read (0 for + end of file, -1 for error). */ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + const voidp buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes actually written + (0 in case of error). +*/ + +ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the args to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written (0 in case of error). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or + a newline character is read and transferred to buf, or an end-of-file + condition is encountered. The string is then terminated with a null + character. + gzgets returns buf, or Z_NULL in case of error. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. + gzputc returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte + or -1 in case of end of file or error. +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter + flush is as in the deflate() function. The return value is the zlib + error number (see function gzerror below). gzflush returns Z_OK if + the flush parameter is Z_FINISH and all output could be flushed. + gzflush should be called only when strictly necessary because it can + degrade compression. +*/ + +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); +/* + Sets the starting position for the next gzread or gzwrite on the + given compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +/* + Returns the starting position for the next gzread or gzwrite on the + given compressed file. This position represents a number of bytes in the + uncompressed data stream. + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns 1 when EOF has previously been detected reading the given + input stream, otherwise zero. +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file + and deallocates all the (de)compression state. The return value is the zlib + error number (see function gzerror below). +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the + given compressed file. errnum is set to zlib error number. If an + error occurred in the file system and not in the compression library, + errnum is set to Z_ERRNO and the application may consult errno + to get the exact error code. +*/ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the + compression library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); + +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is NULL, this function returns + the required initial value for the checksum. + An Adler-32 checksum is almost as reliable as a CRC32 but can be computed + much faster. Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running crc with the bytes buf[0..len-1] and return the updated + crc. If buf is NULL, this function returns the required initial value + for the crc. Pre- and post-conditioning (one's complement) is performed + within this function so it shouldn't be done by the application. + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +#define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, sizeof(z_stream)) +#define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) + + +#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) + struct internal_state {int dummy;}; /* hack for buggy compilers */ +#endif + +ZEXTERN const char * ZEXPORT zError OF((int err)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); +ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); + +#ifdef __cplusplus +} +#endif + +#endif /* _ZLIB_H */ diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc new file mode 100644 index 0000000..b3cb8c4 --- /dev/null +++ b/src/lib/Makefile.inc @@ -0,0 +1,5 @@ +# $Id$ +# 'lib' options + +LDFLAGS = -Bshareable +CFLAGS = -fno-builtin diff --git a/src/lib/libc/Makefile b/src/lib/libc/Makefile new file mode 100644 index 0000000..f1b5cf6 --- /dev/null +++ b/src/lib/libc/Makefile @@ -0,0 +1,57 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Objects +OBJS = + +#Sub Sections +SUBS = ./stdio/*.o ./sys/*.o ./string/*.o ./stdlib/*.o ./quad/*.o ./generic/*.o ./locale/*.o ./gen/*.o ./gdtoa/*.o + +#Output +OUTPUT = libc.so + +lib.so: $(OBJS) + (cd stdio;make) + (cd stdlib;make) + (cd locale;make) + (cd quad;make) + (cd sys;make) + (cd string;make) + (cd generic;make) + (cd gen;make) + (cd gdtoa;make) +# $(LD) $(LDFLAGS) -o $(OUTPUT) $(OBJS) ./stdio/*.o ./sys/*.o ./string/*.o ./stdlib/*.o + $(CC) -nostdlib -shared -Wl,-soname,libc.so -o $(OUTPUT) $(OBJS) $(SUBS) + +# Compile the source files +.cc.o: + $(CXX) -Wall -nostdinc -O -I./include -c -o $@ $< + +.cc.s: + $(CXX) -Wall -nostdinc -O -I./include -S -o $@ $< + +.c.o: + $(CC) -Wall -nostdinc -O -I./include -c $< + +.c.s: + $(CC) -Wall -nostdinc -O -I./include -S -o $@ $< + +.S.o: + $(CC) -Wall -nostdinc -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) + (cd stdio;make clean) + (cd sys;make clean) + (cd stdlib;make clean) + (cd locale;make clean) + (cd generic;make clean) + (cd string;make clean) + (cd quad;make clean) + (cd gen;make clean) + (cd gdtoa;make clean) diff --git a/src/lib/libc/gdtoa/Makefile b/src/lib/libc/gdtoa/Makefile new file mode 100644 index 0000000..44c015e --- /dev/null +++ b/src/lib/libc/gdtoa/Makefile @@ -0,0 +1,33 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = arithchk.o dmisc.o dtoa.o g_Qfmt.o g__fmt.o g_ddfmt.o g_dfmt.o g_ffmt.o g_xLfmt.o g_xfmt.o gdtoa.o gethex.o gmisc.o hd_init.o hexnan.o misc.o smisc.o strtoIQ.o strtoId.o strtoIdd.o strtoIf.o strtoIg.o strtoIx.o strtoIxL.o strtod.o strtodI.o strtodg.o strtof.o strtopQ.o strtopd.o strtopdd.o strtopf.o strtopx.o strtopxL.o strtorQ.o strtord.o strtordd.o strtorf.o strtorx.o strtorxL.o sum.o ulp.o +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../../../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../../../include -I../i386 -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdlib -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/gdtoa/arithchk.c b/src/lib/libc/gdtoa/arithchk.c new file mode 100644 index 0000000..59eaad7 --- /dev/null +++ b/src/lib/libc/gdtoa/arithchk.c @@ -0,0 +1,182 @@ +/**************************************************************** +Copyright (C) 1997, 1998 Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. +****************************************************************/ + +/* Try to deduce arith.h from arithmetic properties. */ + +#include + + static int dalign; + typedef struct +Akind { + char *name; + int kind; + } Akind; + + static Akind +IEEE_8087 = { "IEEE_8087", 1 }, +IEEE_MC68k = { "IEEE_MC68k", 2 }, +IBM = { "IBM", 3 }, +VAX = { "VAX", 4 }, +CRAY = { "CRAY", 5}; + + static Akind * +Lcheck() +{ + union { + double d; + long L[2]; + } u; + struct { + double d; + long L; + } x[2]; + + if (sizeof(x) > 2*(sizeof(double) + sizeof(long))) + dalign = 1; + u.L[0] = u.L[1] = 0; + u.d = 1e13; + if (u.L[0] == 1117925532 && u.L[1] == -448790528) + return &IEEE_MC68k; + if (u.L[1] == 1117925532 && u.L[0] == -448790528) + return &IEEE_8087; + if (u.L[0] == -2065213935 && u.L[1] == 10752) + return &VAX; + if (u.L[0] == 1267827943 && u.L[1] == 704643072) + return &IBM; + return 0; + } + + static Akind * +icheck() +{ + union { + double d; + int L[2]; + } u; + struct { + double d; + int L; + } x[2]; + + if (sizeof(x) > 2*(sizeof(double) + sizeof(int))) + dalign = 1; + u.L[0] = u.L[1] = 0; + u.d = 1e13; + if (u.L[0] == 1117925532 && u.L[1] == -448790528) + return &IEEE_MC68k; + if (u.L[1] == 1117925532 && u.L[0] == -448790528) + return &IEEE_8087; + if (u.L[0] == -2065213935 && u.L[1] == 10752) + return &VAX; + if (u.L[0] == 1267827943 && u.L[1] == 704643072) + return &IBM; + return 0; + } + +char *emptyfmt = ""; /* avoid possible warning message with printf("") */ + + static Akind * +ccheck() +{ + union { + double d; + long L; + } u; + long Cray1; + + /* Cray1 = 4617762693716115456 -- without overflow on non-Crays */ + Cray1 = printf(emptyfmt) < 0 ? 0 : 4617762; + if (printf(emptyfmt, Cray1) >= 0) + Cray1 = 1000000*Cray1 + 693716; + if (printf(emptyfmt, Cray1) >= 0) + Cray1 = 1000000*Cray1 + 115456; + u.d = 1e13; + if (u.L == Cray1) + return &CRAY; + return 0; + } + + static int +fzcheck() +{ + double a, b; + int i; + + a = 1.; + b = .1; + for(i = 155;; b *= b, i >>= 1) { + if (i & 1) { + a *= b; + if (i == 1) + break; + } + } + b = a * a; + return b == 0.; + } + +main() +{ + Akind *a = 0; + int Ldef = 0; + FILE *f; + +#ifdef WRITE_ARITH_H /* for Symantec's buggy "make" */ + f = fopen("arith.h", "w"); + if (!f) { + printf("Cannot open arith.h\n"); + return 1; + } +#else + f = stdout; +#endif + + if (sizeof(double) == 2*sizeof(long)) + a = Lcheck(); + else if (sizeof(double) == 2*sizeof(int)) { + Ldef = 1; + a = icheck(); + } + else if (sizeof(double) == sizeof(long)) + a = ccheck(); + if (a) { + fprintf(f, "#define %s\n#define Arith_Kind_ASL %d\n", + a->name, a->kind); + if (Ldef) + fprintf(f, "#define Long int\n#define Intcast (int)(long)\n"); + if (dalign) + fprintf(f, "#define Double_Align\n"); + if (sizeof(char*) == 8) + fprintf(f, "#define X64_bit_pointers\n"); +#ifndef NO_LONG_LONG + if (sizeof(long long) < 8) +#endif + fprintf(f, "#define NO_LONG_LONG\n"); + if (a->kind <= 2 && fzcheck()) + fprintf(f, "#define Sudden_Underflow\n"); + return 0; + } + fprintf(f, "/* Unknown arithmetic */\n"); + return 1; + } diff --git a/src/lib/libc/gdtoa/dmisc.c b/src/lib/libc/gdtoa/dmisc.c new file mode 100644 index 0000000..14b5d7e --- /dev/null +++ b/src/lib/libc/gdtoa/dmisc.c @@ -0,0 +1,222 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#ifndef MULTIPLE_THREADS + char *dtoa_result; +#endif + + char * +#ifdef KR_headers +rv_alloc(i) int i; +#else +rv_alloc(int i) +#endif +{ + int j, k, *r; + + j = sizeof(ULong); + for(k = 0; + sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i; + j <<= 1) + k++; + r = (int*)Balloc(k); + *r = k; + return +#ifndef MULTIPLE_THREADS + dtoa_result = +#endif + (char *)(r+1); + } + + char * +#ifdef KR_headers +nrv_alloc(s, rve, n) char *s, **rve; int n; +#else +nrv_alloc(char *s, char **rve, int n) +#endif +{ + char *rv, *t; + + t = rv = rv_alloc(n); + while((*t = *s++) !=0) + t++; + if (rve) + *rve = t; + return rv; + } + +/* freedtoa(s) must be used to free values s returned by dtoa + * when MULTIPLE_THREADS is #defined. It should be used in all cases, + * but for consistency with earlier versions of dtoa, it is optional + * when MULTIPLE_THREADS is not defined. + */ + + void +#ifdef KR_headers +freedtoa(s) char *s; +#else +freedtoa(char *s) +#endif +{ + Bigint *b = (Bigint *)((int *)s - 1); + b->maxwds = 1 << (b->k = *(int*)b); + Bfree(b); +#ifndef MULTIPLE_THREADS + if (s == dtoa_result) + dtoa_result = 0; +#endif + } + + int +quorem +#ifdef KR_headers + (b, S) Bigint *b, *S; +#else + (Bigint *b, Bigint *S) +#endif +{ + int n; + ULong *bx, *bxe, q, *sx, *sxe; +#ifdef ULLong + ULLong borrow, carry, y, ys; +#else + ULong borrow, carry, y, ys; +#ifdef Pack_32 + ULong si, z, zs; +#endif +#endif + + n = S->wds; +#ifdef DEBUG + /*debug*/ if (b->wds > n) + /*debug*/ Bug("oversize b in quorem"); +#endif + if (b->wds < n) + return 0; + sx = S->x; + sxe = sx + --n; + bx = b->x; + bxe = bx + n; + q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ +#ifdef DEBUG + /*debug*/ if (q > 9) + /*debug*/ Bug("oversized quotient in quorem"); +#endif + if (q) { + borrow = 0; + carry = 0; + do { +#ifdef ULLong + ys = *sx++ * (ULLong)q + carry; + carry = ys >> 32; + y = *bx - (ys & 0xffffffffUL) - borrow; + borrow = y >> 32 & 1UL; + *bx++ = y & 0xffffffffUL; +#else +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) * q + carry; + zs = (si >> 16) * q + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*bx >> 16) - (zs & 0xffff) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(bx, z, y); +#else + ys = *sx++ * q + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + *bx++ = y & 0xffff; +#endif +#endif + } + while(sx <= sxe); + if (!*bxe) { + bx = b->x; + while(--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + if (cmp(b, S) >= 0) { + q++; + borrow = 0; + carry = 0; + bx = b->x; + sx = S->x; + do { +#ifdef ULLong + ys = *sx++ + carry; + carry = ys >> 32; + y = *bx - (ys & 0xffffffffUL) - borrow; + borrow = y >> 32 & 1UL; + *bx++ = y & 0xffffffffUL; +#else +#ifdef Pack_32 + si = *sx++; + ys = (si & 0xffff) + carry; + zs = (si >> 16) + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*bx >> 16) - (zs & 0xffff) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(bx, z, y); +#else + ys = *sx++ + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + *bx++ = y & 0xffff; +#endif +#endif + } + while(sx <= sxe); + bx = b->x; + bxe = bx + n; + if (!*bxe) { + while(--bxe > bx && !*bxe) + --n; + b->wds = n; + } + } + return q; + } diff --git a/src/lib/libc/gdtoa/dtoa.c b/src/lib/libc/gdtoa/dtoa.c new file mode 100644 index 0000000..20e2405 --- /dev/null +++ b/src/lib/libc/gdtoa/dtoa.c @@ -0,0 +1,759 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 1999 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. + * + * Inspired by "How to Print Floating-Point Numbers Accurately" by + * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101]. + * + * Modifications: + * 1. Rather than iterating, we use a simple numeric overestimate + * to determine k = floor(log10(d)). We scale relevant + * quantities using O(log2(k)) rather than O(k) multiplications. + * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't + * try to generate digits strictly left to right. Instead, we + * compute with fewer bits and propagate the carry if necessary + * when rounding the final digit up. This is often faster. + * 3. Under the assumption that input will be rounded nearest, + * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. + * That is, we allow equality in stopping tests when the + * round-nearest rule will give the same floating-point value + * as would satisfaction of the stopping test with strict + * inequality. + * 4. We remove common factors of powers of 2 from relevant + * quantities. + * 5. When converting floating-point integers less than 1e16, + * we use floating-point arithmetic rather than resorting + * to multiple-precision integers. + * 6. When asked to produce fewer than 15 digits, we first try + * to get by with floating-point arithmetic; we resort to + * multiple-precision integer arithmetic only if we cannot + * guarantee that the floating-point calculation has given + * the correctly rounded result. For k requested digits and + * "uniformly" distributed input, the probability is + * something like 10^(k-15) that we must resort to the Long + * calculation. + */ + +#ifdef Honor_FLT_ROUNDS +#define Rounding rounding +#undef Check_FLT_ROUNDS +#define Check_FLT_ROUNDS +#else +#define Rounding Flt_Rounds +#endif + + char * +dtoa +#ifdef KR_headers + (d, mode, ndigits, decpt, sign, rve) + double d; int mode, ndigits, *decpt, *sign; char **rve; +#else + (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) +#endif +{ + /* Arguments ndigits, decpt, sign are similar to those + of ecvt and fcvt; trailing zeros are suppressed from + the returned string. If not null, *rve is set to point + to the end of the return value. If d is +-Infinity or NaN, + then *decpt is set to 9999. + + mode: + 0 ==> shortest string that yields d when read in + and rounded to nearest. + 1 ==> like 0, but with Steele & White stopping rule; + e.g. with IEEE P754 arithmetic , mode 0 gives + 1e23 whereas mode 1 gives 9.999999999999999e22. + 2 ==> max(1,ndigits) significant digits. This gives a + return value similar to that of ecvt, except + that trailing zeros are suppressed. + 3 ==> through ndigits past the decimal point. This + gives a return value similar to that from fcvt, + except that trailing zeros are suppressed, and + ndigits can be negative. + 4,5 ==> similar to 2 and 3, respectively, but (in + round-nearest mode) with the tests of mode 0 to + possibly return a shorter string that rounds to d. + With IEEE arithmetic and compilation with + -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same + as modes 2 and 3 when FLT_ROUNDS != 1. + 6-9 ==> Debugging modes similar to mode - 4: don't try + fast floating-point estimate (if applicable). + + Values of mode other than 0-9 are treated as mode 0. + + Sufficient space is allocated to the return value + to hold the suppressed trailing zeros. + */ + + int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, + j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, + spec_case, try_quick; + Long L; +#ifndef Sudden_Underflow + int denorm; + ULong x; +#endif + Bigint *b, *b1, *delta, *mlo, *mhi, *S; + double d2, ds, eps; + char *s, *s0; +#ifdef Honor_FLT_ROUNDS + int rounding; +#endif +#ifdef SET_INEXACT + int inexact, oldinexact; +#endif + +#ifndef MULTIPLE_THREADS + if (dtoa_result) { + freedtoa(dtoa_result); + dtoa_result = 0; + } +#endif + + if (word0(d) & Sign_bit) { + /* set sign for everything, including 0's and NaNs */ + *sign = 1; + word0(d) &= ~Sign_bit; /* clear sign bit */ + } + else + *sign = 0; + +#if defined(IEEE_Arith) + defined(VAX) +#ifdef IEEE_Arith + if ((word0(d) & Exp_mask) == Exp_mask) +#else + if (word0(d) == 0x8000) +#endif + { + /* Infinity or NaN */ + *decpt = 9999; +#ifdef IEEE_Arith + if (!word1(d) && !(word0(d) & 0xfffff)) + return nrv_alloc("Infinity", rve, 8); +#endif + return nrv_alloc("NaN", rve, 3); + } +#endif +#ifdef IBM + dval(d) += 0; /* normalize */ +#endif + if (!dval(d)) { + *decpt = 1; + return nrv_alloc("0", rve, 1); + } + +#ifdef SET_INEXACT + try_quick = oldinexact = get_inexact(); + inexact = 1; +#endif +#ifdef Honor_FLT_ROUNDS + if ((rounding = Flt_Rounds) >= 2) { + if (*sign) + rounding = rounding == 2 ? 0 : 2; + else + if (rounding != 2) + rounding = 0; + } +#endif + + b = d2b(dval(d), &be, &bbits); +#ifdef Sudden_Underflow + i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); +#else + if (( i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) { +#endif + dval(d2) = dval(d); + word0(d2) &= Frac_mask1; + word0(d2) |= Exp_11; +#ifdef IBM + if (( j = 11 - hi0bits(word0(d2) & Frac_mask) )!=0) + dval(d2) /= 1 << j; +#endif + + /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 + * log10(x) = log(x) / log(10) + * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) + * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * + * This suggests computing an approximation k to log10(d) by + * + * k = (i - Bias)*0.301029995663981 + * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); + * + * We want k to be too large rather than too small. + * The error in the first-order Taylor series approximation + * is in our favor, so we just round up the constant enough + * to compensate for any error in the multiplication of + * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, + * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, + * adding 1e-13 to the constant term more than suffices. + * Hence we adjust the constant term to 0.1760912590558. + * (We could get a more accurate k by invoking log10, + * but this is probably not worthwhile.) + */ + + i -= Bias; +#ifdef IBM + i <<= 2; + i += j; +#endif +#ifndef Sudden_Underflow + denorm = 0; + } + else { + /* d is denormalized */ + + i = bbits + be + (Bias + (P-1) - 1); + x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 + : word1(d) << 32 - i; + dval(d2) = x; + word0(d2) -= 31*Exp_msk1; /* adjust exponent */ + i -= (Bias + (P-1) - 1) + 1; + denorm = 1; + } +#endif + ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; + k = (int)ds; + if (ds < 0. && ds != k) + k--; /* want k = floor(ds) */ + k_check = 1; + if (k >= 0 && k <= Ten_pmax) { + if (dval(d) < tens[k]) + k--; + k_check = 0; + } + j = bbits - i - 1; + if (j >= 0) { + b2 = 0; + s2 = j; + } + else { + b2 = -j; + s2 = 0; + } + if (k >= 0) { + b5 = 0; + s5 = k; + s2 += k; + } + else { + b2 -= k; + b5 = -k; + s5 = 0; + } + if (mode < 0 || mode > 9) + mode = 0; + +#ifndef SET_INEXACT +#ifdef Check_FLT_ROUNDS + try_quick = Rounding == 1; +#else + try_quick = 1; +#endif +#endif /*SET_INEXACT*/ + + if (mode > 5) { + mode -= 4; + try_quick = 0; + } + leftright = 1; + switch(mode) { + case 0: + case 1: + ilim = ilim1 = -1; + i = 18; + ndigits = 0; + break; + case 2: + leftright = 0; + /* no break */ + case 4: + if (ndigits <= 0) + ndigits = 1; + ilim = ilim1 = i = ndigits; + break; + case 3: + leftright = 0; + /* no break */ + case 5: + i = ndigits + k + 1; + ilim = i; + ilim1 = i - 1; + if (i <= 0) + i = 1; + } + s = s0 = rv_alloc(i); + +#ifdef Honor_FLT_ROUNDS + if (mode > 1 && rounding != 1) + leftright = 0; +#endif + + if (ilim >= 0 && ilim <= Quick_max && try_quick) { + + /* Try to get by with floating-point arithmetic. */ + + i = 0; + dval(d2) = dval(d); + k0 = k; + ilim0 = ilim; + ieps = 2; /* conservative */ + if (k > 0) { + ds = tens[k&0xf]; + j = k >> 4; + if (j & Bletch) { + /* prevent overflows */ + j &= Bletch - 1; + dval(d) /= bigtens[n_bigtens-1]; + ieps++; + } + for(; j; j >>= 1, i++) + if (j & 1) { + ieps++; + ds *= bigtens[i]; + } + dval(d) /= ds; + } + else if (( j1 = -k )!=0) { + dval(d) *= tens[j1 & 0xf]; + for(j = j1 >> 4; j; j >>= 1, i++) + if (j & 1) { + ieps++; + dval(d) *= bigtens[i]; + } + } + if (k_check && dval(d) < 1. && ilim > 0) { + if (ilim1 <= 0) + goto fast_failed; + ilim = ilim1; + k--; + dval(d) *= 10.; + ieps++; + } + dval(eps) = ieps*dval(d) + 7.; + word0(eps) -= (P-1)*Exp_msk1; + if (ilim == 0) { + S = mhi = 0; + dval(d) -= 5.; + if (dval(d) > dval(eps)) + goto one_digit; + if (dval(d) < -dval(eps)) + goto no_digits; + goto fast_failed; + } +#ifndef No_leftright + if (leftright) { + /* Use Steele & White method of only + * generating digits needed. + */ + dval(eps) = 0.5/tens[ilim-1] - dval(eps); + for(i = 0;;) { + L = dval(d); + dval(d) -= L; + *s++ = '0' + (int)L; + if (dval(d) < dval(eps)) + goto ret1; + if (1. - dval(d) < dval(eps)) + goto bump_up; + if (++i >= ilim) + break; + dval(eps) *= 10.; + dval(d) *= 10.; + } + } + else { +#endif + /* Generate ilim digits, then fix them up. */ + dval(eps) *= tens[ilim-1]; + for(i = 1;; i++, dval(d) *= 10.) { + L = (Long)(dval(d)); + if (!(dval(d) -= L)) + ilim = i; + *s++ = '0' + (int)L; + if (i == ilim) { + if (dval(d) > 0.5 + dval(eps)) + goto bump_up; + else if (dval(d) < 0.5 - dval(eps)) { + while(*--s == '0'); + s++; + goto ret1; + } + break; + } + } +#ifndef No_leftright + } +#endif + fast_failed: + s = s0; + dval(d) = dval(d2); + k = k0; + ilim = ilim0; + } + + /* Do we have a "small" integer? */ + + if (be >= 0 && k <= Int_max) { + /* Yes. */ + ds = tens[k]; + if (ndigits < 0 && ilim <= 0) { + S = mhi = 0; + if (ilim < 0 || dval(d) <= 5*ds) + goto no_digits; + goto one_digit; + } + for(i = 1;; i++, dval(d) *= 10.) { + L = (Long)(dval(d) / ds); + dval(d) -= L*ds; +#ifdef Check_FLT_ROUNDS + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (dval(d) < 0) { + L--; + dval(d) += ds; + } +#endif + *s++ = '0' + (int)L; + if (!dval(d)) { +#ifdef SET_INEXACT + inexact = 0; +#endif + break; + } + if (i == ilim) { +#ifdef Honor_FLT_ROUNDS + if (mode > 1) + switch(rounding) { + case 0: goto ret1; + case 2: goto bump_up; + } +#endif + dval(d) += dval(d); + if (dval(d) > ds || dval(d) == ds && L & 1) { + bump_up: + while(*--s == '9') + if (s == s0) { + k++; + *s = '0'; + break; + } + ++*s++; + } + break; + } + } + goto ret1; + } + + m2 = b2; + m5 = b5; + mhi = mlo = 0; + if (leftright) { + i = +#ifndef Sudden_Underflow + denorm ? be + (Bias + (P-1) - 1 + 1) : +#endif +#ifdef IBM + 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3); +#else + 1 + P - bbits; +#endif + b2 += i; + s2 += i; + mhi = i2b(1); + } + if (m2 > 0 && s2 > 0) { + i = m2 < s2 ? m2 : s2; + b2 -= i; + m2 -= i; + s2 -= i; + } + if (b5 > 0) { + if (leftright) { + if (m5 > 0) { + mhi = pow5mult(mhi, m5); + b1 = mult(mhi, b); + Bfree(b); + b = b1; + } + if (( j = b5 - m5 )!=0) + b = pow5mult(b, j); + } + else + b = pow5mult(b, b5); + } + S = i2b(1); + if (s5 > 0) + S = pow5mult(S, s5); + + /* Check for special case that d is a normalized power of 2. */ + + spec_case = 0; + if ((mode < 2 || leftright) +#ifdef Honor_FLT_ROUNDS + && rounding == 1 +#endif + ) { + if (!word1(d) && !(word0(d) & Bndry_mask) +#ifndef Sudden_Underflow + && word0(d) & (Exp_mask & ~Exp_msk1) +#endif + ) { + /* The special case */ + b2 += Log2P; + s2 += Log2P; + spec_case = 1; + } + } + + /* Arrange for convenient computation of quotients: + * shift left if necessary so divisor has 4 leading 0 bits. + * + * Perhaps we should just compute leading 28 bits of S once + * and for all and pass them and a shift to quorem, so it + * can do shifts and ors to compute the numerator for q. + */ +#ifdef Pack_32 + if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f )!=0) + i = 32 - i; +#else + if (( i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf )!=0) + i = 16 - i; +#endif + if (i > 4) { + i -= 4; + b2 += i; + m2 += i; + s2 += i; + } + else if (i < 4) { + i += 28; + b2 += i; + m2 += i; + s2 += i; + } + if (b2 > 0) + b = lshift(b, b2); + if (s2 > 0) + S = lshift(S, s2); + if (k_check) { + if (cmp(b,S) < 0) { + k--; + b = multadd(b, 10, 0); /* we botched the k estimate */ + if (leftright) + mhi = multadd(mhi, 10, 0); + ilim = ilim1; + } + } + if (ilim <= 0 && (mode == 3 || mode == 5)) { + if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) { + /* no digits, fcvt style */ + no_digits: + k = -1 - ndigits; + goto ret; + } + one_digit: + *s++ = '1'; + k++; + goto ret; + } + if (leftright) { + if (m2 > 0) + mhi = lshift(mhi, m2); + + /* Compute mlo -- check for special case + * that d is a normalized power of 2. + */ + + mlo = mhi; + if (spec_case) { + mhi = Balloc(mhi->k); + Bcopy(mhi, mlo); + mhi = lshift(mhi, Log2P); + } + + for(i = 1;;i++) { + dig = quorem(b,S) + '0'; + /* Do we yet have the shortest decimal string + * that will round to d? + */ + j = cmp(b, mlo); + delta = diff(S, mhi); + j1 = delta->sign ? 1 : cmp(b, delta); + Bfree(delta); +#ifndef ROUND_BIASED + if (j1 == 0 && mode != 1 && !(word1(d) & 1) +#ifdef Honor_FLT_ROUNDS + && rounding >= 1 +#endif + ) { + if (dig == '9') + goto round_9_up; + if (j > 0) + dig++; +#ifdef SET_INEXACT + else if (!b->x[0] && b->wds <= 1) + inexact = 0; +#endif + *s++ = dig; + goto ret; + } +#endif + if (j < 0 || j == 0 && mode != 1 +#ifndef ROUND_BIASED + && !(word1(d) & 1) +#endif + ) { + if (!b->x[0] && b->wds <= 1) { +#ifdef SET_INEXACT + inexact = 0; +#endif + goto accept_dig; + } +#ifdef Honor_FLT_ROUNDS + if (mode > 1) + switch(rounding) { + case 0: goto accept_dig; + case 2: goto keep_dig; + } +#endif /*Honor_FLT_ROUNDS*/ + if (j1 > 0) { + b = lshift(b, 1); + j1 = cmp(b, S); + if ((j1 > 0 || j1 == 0 && dig & 1) + && dig++ == '9') + goto round_9_up; + } + accept_dig: + *s++ = dig; + goto ret; + } + if (j1 > 0) { +#ifdef Honor_FLT_ROUNDS + if (!rounding) + goto accept_dig; +#endif + if (dig == '9') { /* possible if i == 1 */ + round_9_up: + *s++ = '9'; + goto roundoff; + } + *s++ = dig + 1; + goto ret; + } +#ifdef Honor_FLT_ROUNDS + keep_dig: +#endif + *s++ = dig; + if (i == ilim) + break; + b = multadd(b, 10, 0); + if (mlo == mhi) + mlo = mhi = multadd(mhi, 10, 0); + else { + mlo = multadd(mlo, 10, 0); + mhi = multadd(mhi, 10, 0); + } + } + } + else + for(i = 1;; i++) { + *s++ = dig = quorem(b,S) + '0'; + if (!b->x[0] && b->wds <= 1) { +#ifdef SET_INEXACT + inexact = 0; +#endif + goto ret; + } + if (i >= ilim) + break; + b = multadd(b, 10, 0); + } + + /* Round off last digit */ + +#ifdef Honor_FLT_ROUNDS + switch(rounding) { + case 0: goto trimzeros; + case 2: goto roundoff; + } +#endif + b = lshift(b, 1); + j = cmp(b, S); + if (j > 0 || j == 0 && dig & 1) { + roundoff: + while(*--s == '9') + if (s == s0) { + k++; + *s++ = '1'; + goto ret; + } + ++*s++; + } + else { + trimzeros: + while(*--s == '0'); + s++; + } + ret: + Bfree(S); + if (mhi) { + if (mlo && mlo != mhi) + Bfree(mlo); + Bfree(mhi); + } + ret1: +#ifdef SET_INEXACT + if (inexact) { + if (!oldinexact) { + word0(d) = Exp_1 + (70 << Exp_shift); + word1(d) = 0; + dval(d) += 1.; + } + } + else if (!oldinexact) + clear_inexact(); +#endif + Bfree(b); + *s = 0; + *decpt = k + 1; + if (rve) + *rve = s; + return s0; + } diff --git a/src/lib/libc/gdtoa/g_Qfmt.c b/src/lib/libc/gdtoa/g_Qfmt.c new file mode 100644 index 0000000..896b9d4 --- /dev/null +++ b/src/lib/libc/gdtoa/g_Qfmt.c @@ -0,0 +1,120 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#endif +#ifdef IEEE_8087 +#define _0 3 +#define _1 2 +#define _2 1 +#define _3 0 +#endif + + char* +#ifdef KR_headers +g_Qfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; unsigned bufsize; +#else +g_Qfmt(char *buf, void *V, int ndig, unsigned bufsize) +#endif +{ + static FPI fpi = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 0 }; + char *b, *s, *se; + ULong bits[4], *L, sign; + int decpt, ex, i, mode; + + if (ndig < 0) + ndig = 0; + if (bufsize < ndig + 10) + return 0; + + L = (ULong*)V; + sign = L[_0] & 0x80000000L; + bits[3] = L[_0] & 0xffff; + bits[2] = L[_1]; + bits[1] = L[_2]; + bits[0] = L[_3]; + b = buf; + if ( (ex = (L[_0] & 0x7fff0000L) >> 16) !=0) { + if (ex == 0x7fff) { + /* Infinity or NaN */ + if (bits[0] | bits[1] | bits[2] | bits[3]) + b = strcpy(b, "NaN"); + else { + b = buf; + if (sign) + *b++ = '-'; + b = strcp(b, "Infinity"); + } + return b; + } + i = STRTOG_Normal; + bits[3] |= 0x10000; + } + else if (bits[0] | bits[1] | bits[2] | bits[3]) { + i = STRTOG_Denormal; + ex = 1; + } + else { +#ifndef IGNORE_ZERO_SIGN + if (sign) + *b++ = '-'; +#endif + *b++ = '0'; + *b = 0; + return b; + } + ex -= 0x3fff + 112; + mode = 2; + if (ndig <= 0) { + if (bufsize < 48) + return 0; + mode = 0; + } + s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + return g__fmt(buf, s, se, decpt, sign); + } diff --git a/src/lib/libc/gdtoa/g__fmt.c b/src/lib/libc/gdtoa/g__fmt.c new file mode 100644 index 0000000..6274681 --- /dev/null +++ b/src/lib/libc/gdtoa/g__fmt.c @@ -0,0 +1,101 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + dmg@acm.org + */ + +#include "gdtoaimp.h" + +#ifdef USE_LOCALE +#include "locale.h" +#endif + + char * +#ifdef KR_headers +g__fmt(b, s, se, decpt, sign) char *b; char *s; char *se; int decpt; ULong sign; +#else +g__fmt(char *b, char *s, char *se, int decpt, ULong sign) +#endif +{ + int i, j, k; + char *s0 = s; +#ifdef USE_LOCALE + char decimalpoint = *localeconv()->decimal_point; +#else +#define decimalpoint '.' +#endif + if (sign) + *b++ = '-'; + if (decpt <= -4 || decpt > se - s + 5) { + *b++ = *s++; + if (*s) { + *b++ = decimalpoint; + while((*b = *s++) !=0) + b++; + } + *b++ = 'e'; + /* sprintf(b, "%+.2d", decpt - 1); */ + if (--decpt < 0) { + *b++ = '-'; + decpt = -decpt; + } + else + *b++ = '+'; + for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10){} + for(;;) { + i = decpt / k; + *b++ = i + '0'; + if (--j <= 0) + break; + decpt -= i*k; + decpt *= 10; + } + *b = 0; + } + else if (decpt <= 0) { + *b++ = decimalpoint; + for(; decpt < 0; decpt++) + *b++ = '0'; + while((*b = *s++) !=0) + b++; + } + else { + while((*b = *s++) !=0) { + b++; + if (--decpt == 0 && *s) + *b++ = decimalpoint; + } + for(; decpt > 0; decpt--) + *b++ = '0'; + *b = 0; + } + freedtoa(s0); + return b; + } diff --git a/src/lib/libc/gdtoa/g_ddfmt.c b/src/lib/libc/gdtoa/g_ddfmt.c new file mode 100644 index 0000000..7d214ba --- /dev/null +++ b/src/lib/libc/gdtoa/g_ddfmt.c @@ -0,0 +1,161 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" +#include + + char * +#ifdef KR_headers +g_ddfmt(buf, dd, ndig, bufsize) char *buf; double *dd; int ndig; unsigned bufsize; +#else +g_ddfmt(char *buf, double *dd, int ndig, unsigned bufsize) +#endif +{ + FPI fpi; + char *b, *s, *se; + ULong *L, bits0[4], *bits, *zx; + int bx, by, decpt, ex, ey, i, j, mode; + Bigint *x, *y, *z; + double ddx[2]; + + if (bufsize < 10 || bufsize < ndig + 8) + return 0; + + L = (ULong*)dd; + if ((L[_0] & 0x7ff00000L) == 0x7ff00000L) { + /* Infinity or NaN */ + if (L[_0] & 0xfffff || L[_1]) { + nanret: + return strcp(buf, "NaN"); + } + if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) { + if (L[2+_0] & 0xfffff || L[2+_1]) + goto nanret; + if ((L[_0] ^ L[2+_0]) & 0x80000000L) + goto nanret; /* Infinity - Infinity */ + } + infret: + b = buf; + if (L[_0] & 0x80000000L) + *b++ = '-'; + return strcp(b, "Infinity"); + } + if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) { + L += 2; + if (L[_0] & 0xfffff || L[_1]) + goto nanret; + goto infret; + } + if (dd[0] + dd[1] == 0.) { + b = buf; +#ifndef IGNORE_ZERO_SIGN + if (L[_0] & L[2+_0] & 0x80000000L) + *b++ = '-'; +#endif + *b++ = '0'; + *b = 0; + return b; + } + if ((L[_0] & 0x7ff00000L) < (L[2+_0] & 0x7ff00000L)) { + ddx[1] = dd[0]; + ddx[0] = dd[1]; + dd = ddx; + L = (ULong*)dd; + } + z = d2b(dd[0], &ex, &bx); + if (dd[1] == 0.) + goto no_y; + x = z; + y = d2b(dd[1], &ey, &by); + if ( (i = ex - ey) !=0) { + if (i > 0) { + x = lshift(x, i); + ex = ey; + } + else + y = lshift(y, -i); + } + if ((L[_0] ^ L[2+_0]) & 0x80000000L) { + z = diff(x, y); + if (L[_0] & 0x80000000L) + z->sign = 1 - z->sign; + } + else { + z = sum(x, y); + if (L[_0] & 0x80000000L) + z->sign = 1; + } + Bfree(x); + Bfree(y); + no_y: + bits = zx = z->x; + for(i = 0; !*zx; zx++) + i += 32; + i += lo0bits(zx); + if (i) { + rshift(z, i); + ex += i; + } + fpi.nbits = z->wds * 32 - hi0bits(z->x[j = z->wds-1]); + if (fpi.nbits < 106) { + fpi.nbits = 106; + if (j < 3) { + for(i = 0; i <= j; i++) + bits0[i] = bits[i]; + while(i < 4) + bits0[i++] = 0; + bits = bits0; + } + } + mode = 2; + if (ndig <= 0) { + if (bufsize < (int)(fpi.nbits * .301029995664) + 10) { + Bfree(z); + return 0; + } + mode = 0; + } + fpi.emin = 1-1023-53+1; + fpi.emax = 2046-1023-106+1; + fpi.rounding = FPI_Round_near; + fpi.sudden_underflow = 0; + i = STRTOG_Normal; + s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + b = g__fmt(buf, s, se, decpt, z->sign); + Bfree(z); + return b; + } diff --git a/src/lib/libc/gdtoa/g_dfmt.c b/src/lib/libc/gdtoa/g_dfmt.c new file mode 100644 index 0000000..1ade834 --- /dev/null +++ b/src/lib/libc/gdtoa/g_dfmt.c @@ -0,0 +1,95 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + char* +#ifdef KR_headers +g_dfmt(buf, d, ndig, bufsize) char *buf; double *d; int ndig; unsigned bufsize; +#else +g_dfmt(char *buf, double *d, int ndig, unsigned bufsize) +#endif +{ + static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 }; + char *b, *s, *se; + ULong bits[2], *L, sign; + int decpt, ex, i, mode; + + if (ndig < 0) + ndig = 0; + if (bufsize < ndig + 10) + return 0; + + L = (ULong*)d; + sign = L[_0] & 0x80000000L; + if ((L[_0] & 0x7ff00000) == 0x7ff00000) { + /* Infinity or NaN */ + if (L[_0] & 0xfffff || L[_1]) { + return strcp(buf, "NaN"); + } + b = buf; + if (sign) + *b++ = '-'; + return strcp(b, "Infinity"); + } + if (L[_1] == 0 && (L[_0] ^ sign) == 0 /*d == 0.*/) { + b = buf; +#ifndef IGNORE_ZERO_SIGN + if (L[_0] & 0x80000000L) + *b++ = '-'; +#endif + *b++ = '0'; + *b = 0; + return b; + } + bits[0] = L[_1]; + bits[1] = L[_0] & 0xfffff; + if ( (ex = (L[_0] >> 20) & 0x7ff) !=0) + bits[1] |= 0x100000; + else + ex = 1; + ex -= 0x3ff + 52; + mode = 2; + if (ndig <= 0) { + if (bufsize < 25) + return 0; + mode = 0; + } + i = STRTOG_Normal; + s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + return g__fmt(buf, s, se, decpt, sign); + } diff --git a/src/lib/libc/gdtoa/g_ffmt.c b/src/lib/libc/gdtoa/g_ffmt.c new file mode 100644 index 0000000..851394a --- /dev/null +++ b/src/lib/libc/gdtoa/g_ffmt.c @@ -0,0 +1,94 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + char* +#ifdef KR_headers +g_ffmt(buf, f, ndig, bufsize) char *buf; float *f; int ndig; unsigned bufsize; +#else +g_ffmt(char *buf, float *f, int ndig, unsigned bufsize) +#endif +{ + static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 0 }; + char *b, *s, *se; + ULong bits[1], *L, sign; + int decpt, ex, i, mode; + + if (ndig < 0) + ndig = 0; + if (bufsize < ndig + 10) + return 0; + + L = (ULong*)f; + sign = L[0] & 0x80000000L; + if ((L[0] & 0x7f800000) == 0x7f800000) { + /* Infinity or NaN */ + if (L[0] & 0x7fffff) { + return strcp(buf, "NaN"); + } + b = buf; + if (sign) + *b++ = '-'; + return strcp(b, "Infinity"); + } + if (*f == 0.) { + b = buf; +#ifndef IGNORE_ZERO_SIGN + if (L[0] & 0x80000000L) + *b++ = '-'; +#endif + *b++ = '0'; + *b = 0; + return b; + } + bits[0] = L[0] & 0x7fffff; + if ( (ex = (L[0] >> 23) & 0xff) !=0) + bits[0] |= 0x800000; + else + ex = 1; + ex -= 0x7f + 23; + mode = 2; + if (ndig <= 0) { + if (bufsize < 16) + return 0; + mode = 0; + } + i = STRTOG_Normal; + s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + return g__fmt(buf, s, se, decpt, sign); + } diff --git a/src/lib/libc/gdtoa/g_xLfmt.c b/src/lib/libc/gdtoa/g_xLfmt.c new file mode 100644 index 0000000..fc17643 --- /dev/null +++ b/src/lib/libc/gdtoa/g_xLfmt.c @@ -0,0 +1,114 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#endif +#ifdef IEEE_8087 +#define _0 2 +#define _1 1 +#define _2 0 +#endif + + char* +#ifdef KR_headers +g_xLfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; unsigned bufsize; +#else +g_xLfmt(char *buf, void *V, int ndig, unsigned bufsize) +#endif +{ + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; + char *b, *s, *se; + ULong bits[2], *L, sign; + int decpt, ex, i, mode; + + if (ndig < 0) + ndig = 0; + if (bufsize < ndig + 10) + return 0; + + L = (ULong*)V; + sign = L[_0] & 0x80000000L; + bits[1] = L[_1]; + bits[0] = L[_2]; + if ( (ex = (L[_0] >> 16) & 0x7fff) !=0) { + if (ex == 0x7fff) { + /* Infinity or NaN */ + if (bits[0] | bits[1]) + b = strcp(buf, "NaN"); + else { + b = buf; + if (sign) + *b++ = '-'; + b = strcp(b, "Infinity"); + } + return b; + } + i = STRTOG_Normal; + } + else if (bits[0] | bits[1]) { + i = STRTOG_Denormal; + } + else { + b = buf; +#ifndef IGNORE_ZERO_SIGN + if (sign) + *b++ = '-'; +#endif + *b++ = '0'; + *b = 0; + return b; + } + ex -= 0x3fff + 63; + mode = 2; + if (ndig <= 0) { + if (bufsize < 32) + return 0; + mode = 0; + } + s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + return g__fmt(buf, s, se, decpt, sign); + } diff --git a/src/lib/libc/gdtoa/g_xfmt.c b/src/lib/libc/gdtoa/g_xfmt.c new file mode 100644 index 0000000..1e2a381 --- /dev/null +++ b/src/lib/libc/gdtoa/g_xfmt.c @@ -0,0 +1,119 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#define _4 4 +#endif +#ifdef IEEE_8087 +#define _0 4 +#define _1 3 +#define _2 2 +#define _3 1 +#define _4 0 +#endif + + char* +#ifdef KR_headers +g_xfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; unsigned bufsize; +#else +g_xfmt(char *buf, void *V, int ndig, unsigned bufsize) +#endif +{ + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; + char *b, *s, *se; + ULong bits[2], sign; + UShort *L; + int decpt, ex, i, mode; + + if (ndig < 0) + ndig = 0; + if (bufsize < ndig + 10) + return 0; + + L = (UShort *)V; + sign = L[_0] & 0x8000; + bits[1] = (L[_1] << 16) | L[_2]; + bits[0] = (L[_3] << 16) | L[_4]; + if ( (ex = L[_0] & 0x7fff) !=0) { + if (ex == 0x7fff) { + /* Infinity or NaN */ + if (bits[0] | bits[1]) + b = strcp(buf, "NaN"); + else { + b = buf; + if (sign) + *b++ = '-'; + b = strcp(b, "Infinity"); + } + return b; + } + i = STRTOG_Normal; + } + else if (bits[0] | bits[1]) { + i = STRTOG_Denormal; + } + else { + b = buf; +#ifndef IGNORE_ZERO_SIGN + if (sign) + *b++ = '-'; +#endif + *b++ = '0'; + *b = 0; + return b; + } + ex -= 0x3fff + 63; + mode = 2; + if (ndig <= 0) { + if (bufsize < 32) + return 0; + mode = 0; + } + s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + return g__fmt(buf, s, se, decpt, sign); + } diff --git a/src/lib/libc/gdtoa/gdtoa.c b/src/lib/libc/gdtoa/gdtoa.c new file mode 100644 index 0000000..706c055 --- /dev/null +++ b/src/lib/libc/gdtoa/gdtoa.c @@ -0,0 +1,764 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 1999 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + static Bigint * +#ifdef KR_headers +bitstob(bits, nbits, bbits) ULong *bits; int nbits; int *bbits; +#else +bitstob(ULong *bits, int nbits, int *bbits) +#endif +{ + int i, k; + Bigint *b; + ULong *be, *x, *x0; + + i = ULbits; + k = 0; + while(i < nbits) { + i <<= 1; + k++; + } +#ifndef Pack_32 + if (!k) + k = 1; +#endif + b = Balloc(k); + be = bits + ((nbits - 1) >> kshift); + x = x0 = b->x; + do { + *x++ = *bits & ALL_ON; +#ifdef Pack_16 + *x++ = (*bits >> 16) & ALL_ON; +#endif + } while(++bits <= be); + i = x - x0; + while(!x0[--i]) + if (!i) { + b->wds = 0; + *bbits = 0; + goto ret; + } + b->wds = i + 1; + *bbits = i*ULbits + 32 - hi0bits(b->x[i]); + ret: + return b; + } + +/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. + * + * Inspired by "How to Print Floating-Point Numbers Accurately" by + * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101]. + * + * Modifications: + * 1. Rather than iterating, we use a simple numeric overestimate + * to determine k = floor(log10(d)). We scale relevant + * quantities using O(log2(k)) rather than O(k) multiplications. + * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't + * try to generate digits strictly left to right. Instead, we + * compute with fewer bits and propagate the carry if necessary + * when rounding the final digit up. This is often faster. + * 3. Under the assumption that input will be rounded nearest, + * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. + * That is, we allow equality in stopping tests when the + * round-nearest rule will give the same floating-point value + * as would satisfaction of the stopping test with strict + * inequality. + * 4. We remove common factors of powers of 2 from relevant + * quantities. + * 5. When converting floating-point integers less than 1e16, + * we use floating-point arithmetic rather than resorting + * to multiple-precision integers. + * 6. When asked to produce fewer than 15 digits, we first try + * to get by with floating-point arithmetic; we resort to + * multiple-precision integer arithmetic only if we cannot + * guarantee that the floating-point calculation has given + * the correctly rounded result. For k requested digits and + * "uniformly" distributed input, the probability is + * something like 10^(k-15) that we must resort to the Long + * calculation. + */ + + char * +gdtoa +#ifdef KR_headers + (fpi, be, bits, kindp, mode, ndigits, decpt, rve) + FPI *fpi; int be; ULong *bits; + int *kindp, mode, ndigits, *decpt; char **rve; +#else + (FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve) +#endif +{ + /* Arguments ndigits and decpt are similar to the second and third + arguments of ecvt and fcvt; trailing zeros are suppressed from + the returned string. If not null, *rve is set to point + to the end of the return value. If d is +-Infinity or NaN, + then *decpt is set to 9999. + + mode: + 0 ==> shortest string that yields d when read in + and rounded to nearest. + 1 ==> like 0, but with Steele & White stopping rule; + e.g. with IEEE P754 arithmetic , mode 0 gives + 1e23 whereas mode 1 gives 9.999999999999999e22. + 2 ==> max(1,ndigits) significant digits. This gives a + return value similar to that of ecvt, except + that trailing zeros are suppressed. + 3 ==> through ndigits past the decimal point. This + gives a return value similar to that from fcvt, + except that trailing zeros are suppressed, and + ndigits can be negative. + 4-9 should give the same return values as 2-3, i.e., + 4 <= mode <= 9 ==> same return as mode + 2 + (mode & 1). These modes are mainly for + debugging; often they run slower but sometimes + faster than modes 2-3. + 4,5,8,9 ==> left-to-right digit generation. + 6-9 ==> don't try fast floating-point estimate + (if applicable). + + Values of mode other than 0-9 are treated as mode 0. + + Sufficient space is allocated to the return value + to hold the suppressed trailing zeros. + */ + + int bbits, b2, b5, be0, dig, i, ieps, ilim, ilim0, ilim1, inex; + int j, j1, k, k0, k_check, kind, leftright, m2, m5, nbits; + int rdir, s2, s5, spec_case, try_quick; + Long L; + Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S; + double d, d2, ds, eps; + char *s, *s0; + +#ifndef MULTIPLE_THREADS + if (dtoa_result) { + freedtoa(dtoa_result); + dtoa_result = 0; + } +#endif + inex = 0; + kind = *kindp &= ~STRTOG_Inexact; + switch(kind & STRTOG_Retmask) { + case STRTOG_Zero: + goto ret_zero; + case STRTOG_Normal: + case STRTOG_Denormal: + break; + case STRTOG_Infinite: + *decpt = -32768; + return nrv_alloc("Infinity", rve, 8); + case STRTOG_NaN: + *decpt = -32768; + return nrv_alloc("NaN", rve, 3); + default: + return 0; + } + b = bitstob(bits, nbits = fpi->nbits, &bbits); + be0 = be; + if ( (i = trailz(b)) !=0) { + rshift(b, i); + be += i; + bbits -= i; + } + if (!b->wds) { + Bfree(b); + ret_zero: + *decpt = 1; + return nrv_alloc("0", rve, 1); + } + + dval(d) = b2d(b, &i); + i = be + bbits - 1; + word0(d) &= Frac_mask1; + word0(d) |= Exp_11; +#ifdef IBM + if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0) + dval(d) /= 1 << j; +#endif + + /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 + * log10(x) = log(x) / log(10) + * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) + * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * + * This suggests computing an approximation k to log10(d) by + * + * k = (i - Bias)*0.301029995663981 + * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); + * + * We want k to be too large rather than too small. + * The error in the first-order Taylor series approximation + * is in our favor, so we just round up the constant enough + * to compensate for any error in the multiplication of + * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, + * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, + * adding 1e-13 to the constant term more than suffices. + * Hence we adjust the constant term to 0.1760912590558. + * (We could get a more accurate k by invoking log10, + * but this is probably not worthwhile.) + */ +#ifdef IBM + i <<= 2; + i += j; +#endif + ds = (dval(d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; + + /* correct assumption about exponent range */ + if ((j = i) < 0) + j = -j; + if ((j -= 1077) > 0) + ds += j * 7e-17; + + k = (int)ds; + if (ds < 0. && ds != k) + k--; /* want k = floor(ds) */ + k_check = 1; +#ifdef IBM + j = be + bbits - 1; + if ( (j1 = j & 3) !=0) + dval(d) *= 1 << j1; + word0(d) += j << Exp_shift - 2 & Exp_mask; +#else + word0(d) += (be + bbits - 1) << Exp_shift; +#endif + if (k >= 0 && k <= Ten_pmax) { + if (dval(d) < tens[k]) + k--; + k_check = 0; + } + j = bbits - i - 1; + if (j >= 0) { + b2 = 0; + s2 = j; + } + else { + b2 = -j; + s2 = 0; + } + if (k >= 0) { + b5 = 0; + s5 = k; + s2 += k; + } + else { + b2 -= k; + b5 = -k; + s5 = 0; + } + if (mode < 0 || mode > 9) + mode = 0; + try_quick = 1; + if (mode > 5) { + mode -= 4; + try_quick = 0; + } + leftright = 1; + switch(mode) { + case 0: + case 1: + ilim = ilim1 = -1; + i = (int)(nbits * .30103) + 3; + ndigits = 0; + break; + case 2: + leftright = 0; + /* no break */ + case 4: + if (ndigits <= 0) + ndigits = 1; + ilim = ilim1 = i = ndigits; + break; + case 3: + leftright = 0; + /* no break */ + case 5: + i = ndigits + k + 1; + ilim = i; + ilim1 = i - 1; + if (i <= 0) + i = 1; + } + s = s0 = rv_alloc(i); + + if ( (rdir = fpi->rounding - 1) !=0) { + if (rdir < 0) + rdir = 2; + if (kind & STRTOG_Neg) + rdir = 3 - rdir; + } + + /* Now rdir = 0 ==> round near, 1 ==> round up, 2 ==> round down. */ + + if (ilim >= 0 && ilim <= Quick_max && try_quick && !rdir +#ifndef IMPRECISE_INEXACT + && k == 0 +#endif + ) { + + /* Try to get by with floating-point arithmetic. */ + + i = 0; + d2 = dval(d); +#ifdef IBM + if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0) + dval(d) /= 1 << j; +#endif + k0 = k; + ilim0 = ilim; + ieps = 2; /* conservative */ + if (k > 0) { + ds = tens[k&0xf]; + j = k >> 4; + if (j & Bletch) { + /* prevent overflows */ + j &= Bletch - 1; + dval(d) /= bigtens[n_bigtens-1]; + ieps++; + } + for(; j; j >>= 1, i++) + if (j & 1) { + ieps++; + ds *= bigtens[i]; + } + } + else { + ds = 1.; + if ( (j1 = -k) !=0) { + dval(d) *= tens[j1 & 0xf]; + for(j = j1 >> 4; j; j >>= 1, i++) + if (j & 1) { + ieps++; + dval(d) *= bigtens[i]; + } + } + } + if (k_check && dval(d) < 1. && ilim > 0) { + if (ilim1 <= 0) + goto fast_failed; + ilim = ilim1; + k--; + dval(d) *= 10.; + ieps++; + } + dval(eps) = ieps*dval(d) + 7.; + word0(eps) -= (P-1)*Exp_msk1; + if (ilim == 0) { + S = mhi = 0; + dval(d) -= 5.; + if (dval(d) > dval(eps)) + goto one_digit; + if (dval(d) < -dval(eps)) + goto no_digits; + goto fast_failed; + } +#ifndef No_leftright + if (leftright) { + /* Use Steele & White method of only + * generating digits needed. + */ + dval(eps) = ds*0.5/tens[ilim-1] - dval(eps); + for(i = 0;;) { + L = (Long)(dval(d)/ds); + dval(d) -= L*ds; + *s++ = '0' + (int)L; + if (dval(d) < dval(eps)) { + if (dval(d)) + inex = STRTOG_Inexlo; + goto ret1; + } + if (ds - dval(d) < dval(eps)) + goto bump_up; + if (++i >= ilim) + break; + dval(eps) *= 10.; + dval(d) *= 10.; + } + } + else { +#endif + /* Generate ilim digits, then fix them up. */ + dval(eps) *= tens[ilim-1]; + for(i = 1;; i++, dval(d) *= 10.) { + if ( (L = (Long)(dval(d)/ds)) !=0) + dval(d) -= L*ds; + *s++ = '0' + (int)L; + if (i == ilim) { + ds *= 0.5; + if (dval(d) > ds + dval(eps)) + goto bump_up; + else if (dval(d) < ds - dval(eps)) { + while(*--s == '0'){} + s++; + if (dval(d)) + inex = STRTOG_Inexlo; + goto ret1; + } + break; + } + } +#ifndef No_leftright + } +#endif + fast_failed: + s = s0; + dval(d) = d2; + k = k0; + ilim = ilim0; + } + + /* Do we have a "small" integer? */ + + if (be >= 0 && k <= Int_max) { + /* Yes. */ + ds = tens[k]; + if (ndigits < 0 && ilim <= 0) { + S = mhi = 0; + if (ilim < 0 || dval(d) <= 5*ds) + goto no_digits; + goto one_digit; + } + for(i = 1;; i++, dval(d) *= 10.) { + L = dval(d) / ds; + dval(d) -= L*ds; +#ifdef Check_FLT_ROUNDS + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (dval(d) < 0) { + L--; + dval(d) += ds; + } +#endif + *s++ = '0' + (int)L; + if (dval(d) == 0.) + break; + if (i == ilim) { + if (rdir) { + if (rdir == 1) + goto bump_up; + inex = STRTOG_Inexlo; + goto ret1; + } + dval(d) += dval(d); + if (dval(d) > ds || dval(d) == ds && L & 1) { + bump_up: + inex = STRTOG_Inexhi; + while(*--s == '9') + if (s == s0) { + k++; + *s = '0'; + break; + } + ++*s++; + } + else + inex = STRTOG_Inexlo; + break; + } + } + goto ret1; + } + + m2 = b2; + m5 = b5; + mhi = mlo = 0; + if (leftright) { + if (mode < 2) { + i = nbits - bbits; + if (be - i++ < fpi->emin) + /* denormal */ + i = be - fpi->emin + 1; + } + else { + j = ilim - 1; + if (m5 >= j) + m5 -= j; + else { + s5 += j -= m5; + b5 += j; + m5 = 0; + } + if ((i = ilim) < 0) { + m2 -= i; + i = 0; + } + } + b2 += i; + s2 += i; + mhi = i2b(1); + } + if (m2 > 0 && s2 > 0) { + i = m2 < s2 ? m2 : s2; + b2 -= i; + m2 -= i; + s2 -= i; + } + if (b5 > 0) { + if (leftright) { + if (m5 > 0) { + mhi = pow5mult(mhi, m5); + b1 = mult(mhi, b); + Bfree(b); + b = b1; + } + if ( (j = b5 - m5) !=0) + b = pow5mult(b, j); + } + else + b = pow5mult(b, b5); + } + S = i2b(1); + if (s5 > 0) + S = pow5mult(S, s5); + + /* Check for special case that d is a normalized power of 2. */ + + spec_case = 0; + if (mode < 2) { + if (bbits == 1 && be0 > fpi->emin + 1) { + /* The special case */ + b2++; + s2++; + spec_case = 1; + } + } + + /* Arrange for convenient computation of quotients: + * shift left if necessary so divisor has 4 leading 0 bits. + * + * Perhaps we should just compute leading 28 bits of S once + * and for all and pass them and a shift to quorem, so it + * can do shifts and ors to compute the numerator for q. + */ +#ifdef Pack_32 + if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) !=0) + i = 32 - i; +#else + if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) !=0) + i = 16 - i; +#endif + if (i > 4) { + i -= 4; + b2 += i; + m2 += i; + s2 += i; + } + else if (i < 4) { + i += 28; + b2 += i; + m2 += i; + s2 += i; + } + if (b2 > 0) + b = lshift(b, b2); + if (s2 > 0) + S = lshift(S, s2); + if (k_check) { + if (cmp(b,S) < 0) { + k--; + b = multadd(b, 10, 0); /* we botched the k estimate */ + if (leftright) + mhi = multadd(mhi, 10, 0); + ilim = ilim1; + } + } + if (ilim <= 0 && mode > 2) { + if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) { + /* no digits, fcvt style */ + no_digits: + k = -1 - ndigits; + inex = STRTOG_Inexlo; + goto ret; + } + one_digit: + inex = STRTOG_Inexhi; + *s++ = '1'; + k++; + goto ret; + } + if (leftright) { + if (m2 > 0) + mhi = lshift(mhi, m2); + + /* Compute mlo -- check for special case + * that d is a normalized power of 2. + */ + + mlo = mhi; + if (spec_case) { + mhi = Balloc(mhi->k); + Bcopy(mhi, mlo); + mhi = lshift(mhi, 1); + } + + for(i = 1;;i++) { + dig = quorem(b,S) + '0'; + /* Do we yet have the shortest decimal string + * that will round to d? + */ + j = cmp(b, mlo); + delta = diff(S, mhi); + j1 = delta->sign ? 1 : cmp(b, delta); + Bfree(delta); +#ifndef ROUND_BIASED + if (j1 == 0 && !mode && !(bits[0] & 1) && !rdir) { + if (dig == '9') + goto round_9_up; + if (j <= 0) { + if (b->wds > 1 || b->x[0]) + inex = STRTOG_Inexlo; + } + else { + dig++; + inex = STRTOG_Inexhi; + } + *s++ = dig; + goto ret; + } +#endif + if (j < 0 || j == 0 && !mode +#ifndef ROUND_BIASED + && !(bits[0] & 1) +#endif + ) { + if (rdir && (b->wds > 1 || b->x[0])) { + if (rdir == 2) { + inex = STRTOG_Inexlo; + goto accept; + } + while (cmp(S,mhi) > 0) { + *s++ = dig; + mhi1 = multadd(mhi, 10, 0); + if (mlo == mhi) + mlo = mhi1; + mhi = mhi1; + b = multadd(b, 10, 0); + dig = quorem(b,S) + '0'; + } + if (dig++ == '9') + goto round_9_up; + inex = STRTOG_Inexhi; + goto accept; + } + if (j1 > 0) { + b = lshift(b, 1); + j1 = cmp(b, S); + if ((j1 > 0 || j1 == 0 && dig & 1) + && dig++ == '9') + goto round_9_up; + inex = STRTOG_Inexhi; + } + if (b->wds > 1 || b->x[0]) + inex = STRTOG_Inexlo; + accept: + *s++ = dig; + goto ret; + } + if (j1 > 0 && rdir != 2) { + if (dig == '9') { /* possible if i == 1 */ + round_9_up: + *s++ = '9'; + inex = STRTOG_Inexhi; + goto roundoff; + } + inex = STRTOG_Inexhi; + *s++ = dig + 1; + goto ret; + } + *s++ = dig; + if (i == ilim) + break; + b = multadd(b, 10, 0); + if (mlo == mhi) + mlo = mhi = multadd(mhi, 10, 0); + else { + mlo = multadd(mlo, 10, 0); + mhi = multadd(mhi, 10, 0); + } + } + } + else + for(i = 1;; i++) { + *s++ = dig = quorem(b,S) + '0'; + if (i >= ilim) + break; + b = multadd(b, 10, 0); + } + + /* Round off last digit */ + + if (rdir) { + if (rdir == 2 || b->wds <= 1 && !b->x[0]) + goto chopzeros; + goto roundoff; + } + b = lshift(b, 1); + j = cmp(b, S); + if (j > 0 || j == 0 && dig & 1) { + roundoff: + inex = STRTOG_Inexhi; + while(*--s == '9') + if (s == s0) { + k++; + *s++ = '1'; + goto ret; + } + ++*s++; + } + else { + chopzeros: + if (b->wds > 1 || b->x[0]) + inex = STRTOG_Inexlo; + while(*--s == '0'){} + s++; + } + ret: + Bfree(S); + if (mhi) { + if (mlo && mlo != mhi) + Bfree(mlo); + Bfree(mhi); + } + ret1: + Bfree(b); + *s = 0; + *decpt = k + 1; + if (rve) + *rve = s; + *kindp |= inex; + return s0; + } diff --git a/src/lib/libc/gdtoa/gdtoa.h b/src/lib/libc/gdtoa/gdtoa.h new file mode 100644 index 0000000..62553f2 --- /dev/null +++ b/src/lib/libc/gdtoa/gdtoa.h @@ -0,0 +1,159 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#ifndef GDTOA_H_INCLUDED +#define GDTOA_H_INCLUDED + +#include "arith.h" + +#ifndef Long +#define Long long +#endif +#ifndef ULong +typedef unsigned Long ULong; +#endif +#ifndef UShort +typedef unsigned short UShort; +#endif + +#ifndef ANSI +#ifdef KR_headers +#define ANSI(x) () +#define Void /*nothing*/ +#else +#define ANSI(x) x +#define Void void +#endif +#endif /* ANSI */ + +#ifndef CONST +#ifdef KR_headers +#define CONST /* blank */ +#else +#define CONST const +#endif +#endif /* CONST */ + + enum { /* return values from strtodg */ + STRTOG_Zero = 0, + STRTOG_Normal = 1, + STRTOG_Denormal = 2, + STRTOG_Infinite = 3, + STRTOG_NaN = 4, + STRTOG_NaNbits = 5, + STRTOG_NoNumber = 6, + STRTOG_Retmask = 7, + + /* The following may be or-ed into one of the above values. */ + + STRTOG_Neg = 0x08, + STRTOG_Inexlo = 0x10, + STRTOG_Inexhi = 0x20, + STRTOG_Inexact = 0x30, + STRTOG_Underflow= 0x40, + STRTOG_Overflow = 0x80 + }; + + typedef struct +FPI { + int nbits; + int emin; + int emax; + int rounding; + int sudden_underflow; + } FPI; + +enum { /* FPI.rounding values: same as FLT_ROUNDS */ + FPI_Round_zero = 0, + FPI_Round_near = 1, + FPI_Round_up = 2, + FPI_Round_down = 3 + }; + +#ifdef __cplusplus +extern "C" { +#endif + +extern char* dtoa ANSI((double d, int mode, int ndigits, int *decpt, + int *sign, char **rve)); +extern char* gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp, + int mode, int ndigits, int *decpt, char **rve)); +extern void freedtoa ANSI((char*)); +extern float strtof ANSI((CONST char *, char **)); +extern double strtod ANSI((CONST char *, char **)); +extern int strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*)); + +extern char* g_ddfmt ANSI((char*, double*, int, unsigned)); +extern char* g_dfmt ANSI((char*, double*, int, unsigned)); +extern char* g_ffmt ANSI((char*, float*, int, unsigned)); +extern char* g_Qfmt ANSI((char*, void*, int, unsigned)); +extern char* g_xfmt ANSI((char*, void*, int, unsigned)); +extern char* g_xLfmt ANSI((char*, void*, int, unsigned)); + +extern int strtoId ANSI((CONST char*, char**, double*, double*)); +extern int strtoIdd ANSI((CONST char*, char**, double*, double*)); +extern int strtoIf ANSI((CONST char*, char**, float*, float*)); +extern int strtoIQ ANSI((CONST char*, char**, void*, void*)); +extern int strtoIx ANSI((CONST char*, char**, void*, void*)); +extern int strtoIxL ANSI((CONST char*, char**, void*, void*)); +extern int strtord ANSI((CONST char*, char**, int, double*)); +extern int strtordd ANSI((CONST char*, char**, int, double*)); +extern int strtorf ANSI((CONST char*, char**, int, float*)); +extern int strtorQ ANSI((CONST char*, char**, int, void*)); +extern int strtorx ANSI((CONST char*, char**, int, void*)); +extern int strtorxL ANSI((CONST char*, char**, int, void*)); +#if 1 +extern int strtodI ANSI((CONST char*, char**, double*)); +extern int strtopd ANSI((CONST char*, char**, double*)); +extern int strtopdd ANSI((CONST char*, char**, double*)); +extern int strtopf ANSI((CONST char*, char**, float*)); +extern int strtopQ ANSI((CONST char*, char**, void*)); +extern int strtopx ANSI((CONST char*, char**, void*)); +extern int strtopxL ANSI((CONST char*, char**, void*)); +#else +#define strtopd(s,se,x) strtord(s,se,1,x) +#define strtopdd(s,se,x) strtordd(s,se,1,x) +#define strtopf(s,se,x) strtorf(s,se,1,x) +#define strtopQ(s,se,x) strtorQ(s,se,1,x) +#define strtopx(s,se,x) strtorx(s,se,1,x) +#define strtopxL(s,se,x) strtorxL(s,se,1,x) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* GDTOA_H_INCLUDED */ diff --git a/src/lib/libc/gdtoa/gdtoaimp.h b/src/lib/libc/gdtoa/gdtoaimp.h new file mode 100644 index 0000000..745043a --- /dev/null +++ b/src/lib/libc/gdtoa/gdtoaimp.h @@ -0,0 +1,691 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* $FreeBSD: src/contrib/gdtoa/gdtoaimp.h,v 1.6 2003/06/21 08:20:14 das Exp $ */ + +/* This is a variation on dtoa.c that converts arbitary binary + floating-point formats to and from decimal notation. It uses + double-precision arithmetic internally, so there are still + various #ifdefs that adapt the calculations to the native + double-precision arithmetic (any of IEEE, VAX D_floating, + or IBM mainframe arithmetic). + + Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +/* On a machine with IEEE extended-precision registers, it is + * necessary to specify double-precision (53-bit) rounding precision + * before invoking strtod or dtoa. If the machine uses (the equivalent + * of) Intel 80x87 arithmetic, the call + * _control87(PC_53, MCW_PC); + * does this with many compilers. Whether this or another call is + * appropriate depends on the compiler; for this to work, it may be + * necessary to #include "float.h" or another system-dependent header + * file. + */ + +/* strtod for IEEE-, VAX-, and IBM-arithmetic machines. + * + * This strtod returns a nearest machine number to the input decimal + * string (or sets errno to ERANGE). With IEEE arithmetic, ties are + * broken by the IEEE round-even rule. Otherwise ties are broken by + * biased rounding (add half and chop). + * + * Inspired loosely by William D. Clinger's paper "How to Read Floating + * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101]. + * + * Modifications: + * + * 1. We only require IEEE, IBM, or VAX double-precision + * arithmetic (not IEEE double-extended). + * 2. We get by with floating-point arithmetic in a case that + * Clinger missed -- when we're computing d * 10^n + * for a small integer d and the integer n is not too + * much larger than 22 (the maximum integer k for which + * we can represent 10^k exactly), we may be able to + * compute (d*10^k) * 10^(e-k) with just one roundoff. + * 3. Rather than a bit-at-a-time adjustment of the binary + * result in the hard case, we use floating-point + * arithmetic to determine the adjustment to within + * one bit; only in really hard cases do we need to + * compute a second residual. + * 4. Because of 3., we don't need a large table of powers of 10 + * for ten-to-e (just some small tables, e.g. of 10^k + * for 0 <= k <= 22). + */ + +/* + * #define IEEE_8087 for IEEE-arithmetic machines where the least + * significant byte has the lowest address. + * #define IEEE_MC68k for IEEE-arithmetic machines where the most + * significant byte has the lowest address. + * #define Long int on machines with 32-bit ints and 64-bit longs. + * #define Sudden_Underflow for IEEE-format machines without gradual + * underflow (i.e., that flush to zero on underflow). + * #define IBM for IBM mainframe-style floating-point arithmetic. + * #define VAX for VAX-style floating-point arithmetic (D_floating). + * #define No_leftright to omit left-right logic in fast floating-point + * computation of dtoa. + * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3. + * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines + * that use extended-precision instructions to compute rounded + * products and quotients) with IBM. + * #define ROUND_BIASED for IEEE-format with biased rounding. + * #define Inaccurate_Divide for IEEE-format with correctly rounded + * products but inaccurate quotients, e.g., for Intel i860. + * #define NO_LONG_LONG on machines that do not have a "long long" + * integer type (of >= 64 bits). On such machines, you can + * #define Just_16 to store 16 bits per 32-bit Long when doing + * high-precision integer arithmetic. Whether this speeds things + * up or slows things down depends on the machine and the number + * being converted. If long long is available and the name is + * something other than "long long", #define Llong to be the name, + * and if "unsigned Llong" does not work as an unsigned version of + * Llong, #define #ULLong to be the corresponding unsigned type. + * #define KR_headers for old-style C function headers. + * #define Bad_float_h if your system lacks a float.h or if it does not + * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, + * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. + * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) + * if memory is available and otherwise does something you deem + * appropriate. If MALLOC is undefined, malloc will be invoked + * directly -- and assumed always to succeed. + * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making + * memory allocations from a private pool of memory when possible. + * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, + * unless #defined to be a different length. This default length + * suffices to get rid of MALLOC calls except for unusual cases, + * such as decimal-to-binary conversion of a very long string of + * digits. When converting IEEE double precision values, the + * longest string gdtoa can return is about 751 bytes long. For + * conversions by strtod of strings of 800 digits and all gdtoa + * conversions of IEEE doubles in single-threaded executions with + * 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with + * 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate. + * #define INFNAN_CHECK on IEEE systems to cause strtod to check for + * Infinity and NaN (case insensitively). On some systems (e.g., + * some HP systems), it may be necessary to #define NAN_WORD0 + * appropriately -- to the most significant word of a quiet NaN. + * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.) + * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined, + * strtodg also accepts (case insensitively) strings of the form + * NaN(x), where x is a string of hexadecimal digits and spaces; + * if there is only one string of hexadecimal digits, it is taken + * for the fraction bits of the resulting NaN; if there are two or + * more strings of hexadecimal digits, each string is assigned + * to the next available sequence of 32-bit words of fractions + * bits (starting with the most significant), right-aligned in + * each sequence. + * #define MULTIPLE_THREADS if the system offers preemptively scheduled + * multiple threads. In this case, you must provide (or suitably + * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed + * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed + * in pow5mult, ensures lazy evaluation of only one copy of high + * powers of 5; omitting this lock would introduce a small + * probability of wasting memory, but would otherwise be harmless.) + * You must also invoke freedtoa(s) to free the value s returned by + * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined. + * #define IMPRECISE_INEXACT if you do not care about the setting of + * the STRTOG_Inexact bits in the special case of doing IEEE double + * precision conversions (which could also be done by the strtog in + * dtoa.c). + * #define NO_HEX_FP to disable recognition of C9x's hexadecimal + * floating-point constants. + * #define -DNO_ERRNO to suppress setting errno (in strtod.c and + * strtodg.c). + * #define NO_STRING_H to use private versions of memcpy. + * On some K&R systems, it may also be necessary to + * #define DECLARE_SIZE_T in this case. + * #define YES_ALIAS to permit aliasing certain double values with + * arrays of ULongs. This leads to slightly better code with + * some compilers and was always used prior to 19990916, but it + * is not strictly legal and can cause trouble with aggressively + * optimizing compilers (e.g., gcc 2.95.1 under -O2). + * #define USE_LOCALE to use the current locale's decimal_point value. + */ + +#ifndef GDTOAIMP_H_INCLUDED +#define GDTOAIMP_H_INCLUDED +#include "gdtoa.h" + +#ifdef DEBUG +#include "stdio.h" +#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} +#endif + +#include "limits.h" +#include "stdlib.h" +#include "string.h" +#include "libc_private.h" + +#include "namespace.h" +#include +#include "un-namespace.h" + +#ifdef KR_headers +#define Char char +#else +#define Char void +#endif + +#ifdef MALLOC +extern Char *MALLOC ANSI((size_t)); +#else +#define MALLOC malloc +#endif + +#define INFNAN_CHECK +#define USE_LOCALE + +#undef IEEE_Arith +#undef Avoid_Underflow +#ifdef IEEE_MC68k +#define IEEE_Arith +#endif +#ifdef IEEE_8087 +#define IEEE_Arith +#endif + +#include "errno.h" +#ifdef Bad_float_h + +#ifdef IEEE_Arith +#define DBL_DIG 15 +#define DBL_MAX_10_EXP 308 +#define DBL_MAX_EXP 1024 +#define FLT_RADIX 2 +#define DBL_MAX 1.7976931348623157e+308 +#endif + +#ifdef IBM +#define DBL_DIG 16 +#define DBL_MAX_10_EXP 75 +#define DBL_MAX_EXP 63 +#define FLT_RADIX 16 +#define DBL_MAX 7.2370055773322621e+75 +#endif + +#ifdef VAX +#define DBL_DIG 16 +#define DBL_MAX_10_EXP 38 +#define DBL_MAX_EXP 127 +#define FLT_RADIX 2 +#define DBL_MAX 1.7014118346046923e+38 +#define n_bigtens 2 +#endif + +#ifndef LONG_MAX +#define LONG_MAX 2147483647 +#endif + +#else /* ifndef Bad_float_h */ +#include "float.h" +#endif /* Bad_float_h */ + +#ifdef IEEE_Arith +#define Scale_Bit 0x10 +#define n_bigtens 5 +#endif + +#ifdef IBM +#define n_bigtens 3 +#endif + +#ifdef VAX +#define n_bigtens 2 +#endif + +#ifndef __MATH_H__ +#include "math.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 +Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. +#endif + +typedef union { double d; ULong L[2]; } U; + +#ifdef YES_ALIAS +#define dval(x) x +#ifdef IEEE_8087 +#define word0(x) ((ULong *)&x)[1] +#define word1(x) ((ULong *)&x)[0] +#else +#define word0(x) ((ULong *)&x)[0] +#define word1(x) ((ULong *)&x)[1] +#endif +#else /* !YES_ALIAS */ +#ifdef IEEE_8087 +#define word0(x) ((U*)&x)->L[1] +#define word1(x) ((U*)&x)->L[0] +#else +#define word0(x) ((U*)&x)->L[0] +#define word1(x) ((U*)&x)->L[1] +#endif +#define dval(x) ((U*)&x)->d +#endif /* YES_ALIAS */ + +/* The following definition of Storeinc is appropriate for MIPS processors. + * An alternative that might be better on some machines is + * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) + */ +#if defined(IEEE_8087) + defined(VAX) +#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ +((unsigned short *)a)[0] = (unsigned short)c, a++) +#else +#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ +((unsigned short *)a)[1] = (unsigned short)c, a++) +#endif + +/* #define P DBL_MANT_DIG */ +/* Ten_pmax = floor(P*log(2)/log(5)) */ +/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ +/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ +/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ + +#ifdef IEEE_Arith +#define Exp_shift 20 +#define Exp_shift1 20 +#define Exp_msk1 0x100000 +#define Exp_msk11 0x100000 +#define Exp_mask 0x7ff00000 +#define P 53 +#define Bias 1023 +#define Emin (-1022) +#define Exp_1 0x3ff00000 +#define Exp_11 0x3ff00000 +#define Ebits 11 +#define Frac_mask 0xfffff +#define Frac_mask1 0xfffff +#define Ten_pmax 22 +#define Bletch 0x10 +#define Bndry_mask 0xfffff +#define Bndry_mask1 0xfffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 1 +#define Tiny0 0 +#define Tiny1 1 +#define Quick_max 14 +#define Int_max 14 + +#ifndef Flt_Rounds +#ifdef FLT_ROUNDS +#define Flt_Rounds FLT_ROUNDS +#else +#define Flt_Rounds 1 +#endif +#endif /*Flt_Rounds*/ + +#else /* ifndef IEEE_Arith */ +#undef Sudden_Underflow +#define Sudden_Underflow +#ifdef IBM +#undef Flt_Rounds +#define Flt_Rounds 0 +#define Exp_shift 24 +#define Exp_shift1 24 +#define Exp_msk1 0x1000000 +#define Exp_msk11 0x1000000 +#define Exp_mask 0x7f000000 +#define P 14 +#define Bias 65 +#define Exp_1 0x41000000 +#define Exp_11 0x41000000 +#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ +#define Frac_mask 0xffffff +#define Frac_mask1 0xffffff +#define Bletch 4 +#define Ten_pmax 22 +#define Bndry_mask 0xefffff +#define Bndry_mask1 0xffffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 4 +#define Tiny0 0x100000 +#define Tiny1 0 +#define Quick_max 14 +#define Int_max 15 +#else /* VAX */ +#undef Flt_Rounds +#define Flt_Rounds 1 +#define Exp_shift 23 +#define Exp_shift1 7 +#define Exp_msk1 0x80 +#define Exp_msk11 0x800000 +#define Exp_mask 0x7f80 +#define P 56 +#define Bias 129 +#define Exp_1 0x40800000 +#define Exp_11 0x4080 +#define Ebits 8 +#define Frac_mask 0x7fffff +#define Frac_mask1 0xffff007f +#define Ten_pmax 24 +#define Bletch 2 +#define Bndry_mask 0xffff007f +#define Bndry_mask1 0xffff007f +#define LSB 0x10000 +#define Sign_bit 0x8000 +#define Log2P 1 +#define Tiny0 0x80 +#define Tiny1 0 +#define Quick_max 15 +#define Int_max 15 +#endif /* IBM, VAX */ +#endif /* IEEE_Arith */ + +#ifndef IEEE_Arith +#define ROUND_BIASED +#endif + +#ifdef RND_PRODQUOT +#define rounded_product(a,b) a = rnd_prod(a, b) +#define rounded_quotient(a,b) a = rnd_quot(a, b) +#ifdef KR_headers +extern double rnd_prod(), rnd_quot(); +#else +extern double rnd_prod(double, double), rnd_quot(double, double); +#endif +#else +#define rounded_product(a,b) a *= b +#define rounded_quotient(a,b) a /= b +#endif + +#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) +#define Big1 0xffffffff + +#undef Pack_16 +#ifndef Pack_32 +#define Pack_32 +#endif + +#ifdef NO_LONG_LONG +#undef ULLong +#ifdef Just_16 +#undef Pack_32 +#define Pack_16 +/* When Pack_32 is not defined, we store 16 bits per 32-bit Long. + * This makes some inner loops simpler and sometimes saves work + * during multiplications, but it often seems to make things slightly + * slower. Hence the default is now to store 32 bits per Long. + */ +#endif +#else /* long long available */ +#ifndef Llong +#define Llong long long +#endif +#ifndef ULLong +#define ULLong unsigned Llong +#endif +#endif /* NO_LONG_LONG */ + +#ifdef Pack_32 +#define ULbits 32 +#define kshift 5 +#define kmask 31 +#define ALL_ON 0xffffffff +#else +#define ULbits 16 +#define kshift 4 +#define kmask 15 +#define ALL_ON 0xffff +#endif + +#define MULTIPLE_THREADS +extern pthread_mutex_t __gdtoa_locks[2]; +#define ACQUIRE_DTOA_LOCK(n) do { \ + if (__isthreaded) \ + _pthread_mutex_lock(&__gdtoa_locks[n]); \ +} while(0) +#define FREE_DTOA_LOCK(n) do { \ + if (__isthreaded) \ + _pthread_mutex_unlock(&__gdtoa_locks[n]); \ +} while(0) + +#define Kmax 15 + + struct +Bigint { + struct Bigint *next; + int k, maxwds, sign, wds; + ULong x[1]; + }; + + typedef struct Bigint Bigint; + +#ifdef NO_STRING_H +#ifdef DECLARE_SIZE_T +typedef unsigned int size_t; +#endif +extern void memcpy_D2A ANSI((void*, const void*, size_t)); +#define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int)) +#else /* !NO_STRING_H */ +#define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int)) +#endif /* NO_STRING_H */ + +/* + * Paranoia: Protect exported symbols, including ones in files we don't + * compile right now. The standard strtof and strtod survive. + */ +#define dtoa __dtoa +#define gdtoa __gdtoa +#define freedtoa __freedtoa +#define strtodg __strtodg +#define g_ddfmt __g_ddfmt +#define g_dfmt __g_dfmt +#define g_ffmt __g_ffmt +#define g_Qfmt __g_Qfmt +#define g_xfmt __g_xfmt +#define g_xLfmt __g_xLfmt +#define strtoId __strtoId +#define strtoIdd __strtoIdd +#define strtoIf __strtoIf +#define strtoIQ __strtoIQ +#define strtoIx __strtoIx +#define strtoIxL __strtoIxL +#define strtord __strtord +#define strtordd __strtordd +#define strtorf __strtorf +#define strtorQ __strtorQ +#define strtorx __strtorx +#define strtorxL __strtorxL +#define strtodI __strtodI +#define strtopd __strtopd +#define strtopdd __strtopdd +#define strtopf __strtopf +#define strtopQ __strtopQ +#define strtopx __strtopx +#define strtopxL __strtopxL + +/* Protect gdtoa-internal symbols */ +#define Balloc __Balloc_D2A +#define Bfree __Bfree_D2A +#define ULtoQ __ULtoQ_D2A +#define ULtof __ULtof_D2A +#define ULtod __ULtod_D2A +#define ULtodd __ULtodd_D2A +#define ULtox __ULtox_D2A +#define ULtoxL __ULtoxL_D2A +#define any_on __any_on_D2A +#define b2d __b2d_D2A +#define bigtens __bigtens_D2A +#define cmp __cmp_D2A +#define copybits __copybits_D2A +#define d2b __d2b_D2A +#define decrement __decrement_D2A +#define diff __diff_D2A +#define dtoa_result __dtoa_result_D2A +#define g__fmt __g__fmt_D2A +#define gethex __gethex_D2A +#define hexdig __hexdig_D2A +#define hexdig_init_D2A __hexdig_init_D2A +#define hexnan __hexnan_D2A +#define hi0bits __hi0bits_D2A +#define i2b __i2b_D2A +#define increment __increment_D2A +#define lo0bits __lo0bits_D2A +#define lshift __lshift_D2A +#define match __match_D2A +#define mult __mult_D2A +#define multadd __multadd_D2A +#define nrv_alloc __nrv_alloc_D2A +#define pow5mult __pow5mult_D2A +#define quorem __quorem_D2A +#define ratio __ratio_D2A +#define rshift __rshift_D2A +#define rv_alloc __rv_alloc_D2A +#define s2b __s2b_D2A +#define set_ones __set_ones_D2A +#define strcp __strcp_D2A +#define strcp_D2A __strcp_D2A +#define strtoIg __strtoIg_D2A +#define sum __sum_D2A +#define tens __tens_D2A +#define tinytens __tinytens_D2A +#define tinytens __tinytens_D2A +#define trailz __trailz_D2A +#define ulp __ulp_D2A + + extern char *dtoa_result; + extern CONST double bigtens[], tens[], tinytens[]; + extern unsigned char hexdig[]; + + extern Bigint *Balloc ANSI((int)); + extern void Bfree ANSI((Bigint*)); + extern void ULtof ANSI((ULong*, ULong*, Long, int)); + extern void ULtod ANSI((ULong*, ULong*, Long, int)); + extern void ULtodd ANSI((ULong*, ULong*, Long, int)); + extern void ULtoQ ANSI((ULong*, ULong*, Long, int)); + extern void ULtox ANSI((UShort*, ULong*, Long, int)); + extern void ULtoxL ANSI((ULong*, ULong*, Long, int)); + extern ULong any_on ANSI((Bigint*, int)); + extern double b2d ANSI((Bigint*, int*)); + extern int cmp ANSI((Bigint*, Bigint*)); + extern void copybits ANSI((ULong*, int, Bigint*)); + extern Bigint *d2b ANSI((double, int*, int*)); + extern int decrement ANSI((Bigint*)); + extern Bigint *diff ANSI((Bigint*, Bigint*)); + extern char *dtoa ANSI((double d, int mode, int ndigits, + int *decpt, int *sign, char **rve)); + extern void freedtoa ANSI((char*)); + extern char *gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp, + int mode, int ndigits, int *decpt, char **rve)); + extern char *g__fmt ANSI((char*, char*, char*, int, ULong)); + extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int)); + extern void hexdig_init_D2A(Void); + extern int hexnan ANSI((CONST char**, FPI*, ULong*)); + extern int hi0bits ANSI((ULong)); + extern Bigint *i2b ANSI((int)); + extern Bigint *increment ANSI((Bigint*)); + extern int lo0bits ANSI((ULong*)); + extern Bigint *lshift ANSI((Bigint*, int)); + extern int match ANSI((CONST char**, char*)); + extern Bigint *mult ANSI((Bigint*, Bigint*)); + extern Bigint *multadd ANSI((Bigint*, int, int)); + extern char *nrv_alloc ANSI((char*, char **, int)); + extern Bigint *pow5mult ANSI((Bigint*, int)); + extern int quorem ANSI((Bigint*, Bigint*)); + extern double ratio ANSI((Bigint*, Bigint*)); + extern void rshift ANSI((Bigint*, int)); + extern char *rv_alloc ANSI((int)); + extern Bigint *s2b ANSI((CONST char*, int, int, ULong)); + extern Bigint *set_ones ANSI((Bigint*, int)); + extern char *strcp ANSI((char*, const char*)); + extern int strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*)); + + extern int strtoId ANSI((CONST char *, char **, double *, double *)); + extern int strtoIdd ANSI((CONST char *, char **, double *, double *)); + extern int strtoIf ANSI((CONST char *, char **, float *, float *)); + extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*)); + extern int strtoIQ ANSI((CONST char *, char **, void *, void *)); + extern int strtoIx ANSI((CONST char *, char **, void *, void *)); + extern int strtoIxL ANSI((CONST char *, char **, void *, void *)); + extern double strtod ANSI((const char *s00, char **se)); + extern int strtopQ ANSI((CONST char *, char **, Void *)); + extern int strtopf ANSI((CONST char *, char **, float *)); + extern int strtopd ANSI((CONST char *, char **, double *)); + extern int strtopdd ANSI((CONST char *, char **, double *)); + extern int strtopx ANSI((CONST char *, char **, Void *)); + extern int strtopxL ANSI((CONST char *, char **, Void *)); + extern int strtord ANSI((CONST char *, char **, int, double *)); + extern int strtordd ANSI((CONST char *, char **, int, double *)); + extern int strtorf ANSI((CONST char *, char **, int, float *)); + extern int strtorQ ANSI((CONST char *, char **, int, void *)); + extern int strtorx ANSI((CONST char *, char **, int, void *)); + extern int strtorxL ANSI((CONST char *, char **, int, void *)); + extern Bigint *sum ANSI((Bigint*, Bigint*)); + extern int trailz ANSI((Bigint*)); + extern double ulp ANSI((double)); + +#ifdef __cplusplus +} +#endif + + +#ifdef IEEE_Arith +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#else +#define _0 1 +#define _1 0 +#endif +#else +#undef INFNAN_CHECK +#endif + +#ifdef INFNAN_CHECK + +#ifndef NAN_WORD0 +#define NAN_WORD0 0x7ff80000 +#endif + +#ifndef NAN_WORD1 +#define NAN_WORD1 0 +#endif +#endif /* INFNAN_CHECK */ + +#undef SI +#ifdef Sudden_Underflow +#define SI 1 +#else +#define SI 0 +#endif + +#endif /* GDTOAIMP_H_INCLUDED */ diff --git a/src/lib/libc/gdtoa/gethex.c b/src/lib/libc/gdtoa/gethex.c new file mode 100644 index 0000000..fadb5de --- /dev/null +++ b/src/lib/libc/gdtoa/gethex.c @@ -0,0 +1,249 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + dmg@acm.org + */ + +#include "gdtoaimp.h" + +#ifdef USE_LOCALE +#include "locale.h" +#endif + + int +#ifdef KR_headers +gethex(sp, fpi, exp, bp, sign) + CONST char **sp; FPI *fpi; Long *exp; Bigint **bp; int sign; +#else +gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign) +#endif +{ + Bigint *b; + CONST unsigned char *decpt, *s0, *s, *s1; + int esign, havedig, irv, k, n, nbits, up; + ULong L, lostbits, *x; + Long e, e1; +#ifdef USE_LOCALE + unsigned char decimalpoint = *localeconv()->decimal_point; +#else +#define decimalpoint '.' +#endif + + if (!hexdig['0']) + hexdig_init_D2A(); + havedig = 0; + s0 = *(CONST unsigned char **)sp + 2; + while(s0[havedig] == '0') + havedig++; + s0 += havedig; + s = s0; + decpt = 0; + if (!hexdig[*s]) { + if (*s == decimalpoint) { + decpt = ++s; + if (!hexdig[*s]) + goto ret0; + } + else { + ret0: + *sp = (char*)s; + return havedig ? STRTOG_Zero : STRTOG_NoNumber; + } + while(*s == '0') + s++; + havedig = 1; + if (!hexdig[*s]) + goto ret0; + s0 = s; + } + while(hexdig[*s]) + s++; + if (*s == decimalpoint && !decpt) { + decpt = ++s; + while(hexdig[*s]) + s++; + } + e = 0; + if (decpt) + e = -(((Long)(s-decpt)) << 2); + s1 = s; + switch(*s) { + case 'p': + case 'P': + esign = 0; + switch(*++s) { + case '-': + esign = 1; + /* no break */ + case '+': + s++; + } + if ((n = hexdig[*s]) == 0 || n > 0x19) { + s = s1; + break; + } + e1 = n - 0x10; + while((n = hexdig[*++s]) !=0 && n <= 0x19) + e1 = 10*e1 + n - 0x10; + if (esign) + e1 = -e1; + e += e1; + } + *sp = (char*)s; + n = s1 - s0 - 1; + for(k = 0; n > 7; n >>= 1) + k++; + b = Balloc(k); + x = b->x; + n = 0; + L = 0; + while(s1 > s0) { + if (*--s1 == decimalpoint) + continue; + if (n == 32) { + *x++ = L; + L = 0; + n = 0; + } + L |= (hexdig[*s1] & 0x0f) << n; + n += 4; + } + *x++ = L; + b->wds = n = x - b->x; + n = 32*n - hi0bits(L); + nbits = fpi->nbits; + lostbits = 0; + x = b->x; + if (n > nbits) { + n -= nbits; + if (any_on(b,n)) { + lostbits = 1; + k = n - 1; + if (x[k>>kshift] & 1 << (k & kmask)) { + lostbits = 2; + if (k > 1 && any_on(b,k-1)) + lostbits = 3; + } + } + rshift(b, n); + e += n; + } + else if (n < nbits) { + n = nbits - n; + b = lshift(b, n); + e -= n; + x = b->x; + } + if (e > fpi->emax) { + ovfl: + Bfree(b); + *bp = 0; + return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; + } + irv = STRTOG_Normal; + if (e < fpi->emin) { + irv = STRTOG_Denormal; + n = fpi->emin - e; + if (n >= nbits) { + switch (fpi->rounding) { + case FPI_Round_near: + if (n == nbits && (n < 2 || any_on(b,n-1))) + goto one_bit; + break; + case FPI_Round_up: + if (!sign) + goto one_bit; + break; + case FPI_Round_down: + if (sign) { + one_bit: + *exp = fpi->emin; + x[0] = b->wds = 1; + *bp = b; + return STRTOG_Denormal | STRTOG_Inexhi + | STRTOG_Underflow; + } + } + Bfree(b); + *bp = 0; + return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow; + } + k = n - 1; + if (lostbits) + lostbits = 1; + else if (k > 0) + lostbits = any_on(b,k); + if (x[k>>kshift] & 1 << (k & kmask)) + lostbits |= 2; + nbits -= n; + rshift(b,n); + e = fpi->emin; + } + if (lostbits) { + up = 0; + switch(fpi->rounding) { + case FPI_Round_zero: + break; + case FPI_Round_near: + if (lostbits & 2 + && (lostbits & 1) | x[0] & 1) + up = 1; + break; + case FPI_Round_up: + up = 1 - sign; + break; + case FPI_Round_down: + up = sign; + } + if (up) { + k = b->wds; + b = increment(b); + x = b->x; + if (irv == STRTOG_Denormal) { + if (nbits == fpi->nbits - 1 + && x[nbits >> kshift] & 1 << (nbits & kmask)) + irv = STRTOG_Normal; + } + else if (b->wds > k + || (n = nbits & kmask) !=0 + && hi0bits(x[k-1]) < 32-n) { + rshift(b,1); + if (++e > fpi->emax) + goto ovfl; + } + irv |= STRTOG_Inexhi; + } + else + irv |= STRTOG_Inexlo; + } + *bp = b; + *exp = e; + return irv; + } diff --git a/src/lib/libc/gdtoa/gmisc.c b/src/lib/libc/gdtoa/gmisc.c new file mode 100644 index 0000000..1607f4b --- /dev/null +++ b/src/lib/libc/gdtoa/gmisc.c @@ -0,0 +1,92 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + void +#ifdef KR_headers +rshift(b, k) Bigint *b; int k; +#else +rshift(Bigint *b, int k) +#endif +{ + ULong *x, *x1, *xe, y; + int n; + + x = x1 = b->x; + n = k >> kshift; + if (n < b->wds) { + xe = x + b->wds; + x += n; + if (k &= kmask) { + n = ULbits - k; + y = *x++ >> k; + while(x < xe) { + *x1++ = (y | (*x << n)) & ALL_ON; + y = *x++ >> k; + } + if ((*x1 = y) !=0) + x1++; + } + else + while(x < xe) + *x1++ = *x++; + } + if ((b->wds = x1 - b->x) == 0) + b->x[0] = 0; + } + + int +#ifdef KR_headers +trailz(b) Bigint *b; +#else +trailz(Bigint *b) +#endif +{ + ULong L, *x, *xe; + int n = 0; + + x = b->x; + xe = x + b->wds; + for(n = 0; x < xe && !*x; x++) + n += ULbits; + if (x < xe) { + L = *x; + n += lo0bits(&L); + } + return n; + } diff --git a/src/lib/libc/gdtoa/hd_init.c b/src/lib/libc/gdtoa/hd_init.c new file mode 100644 index 0000000..73afca1 --- /dev/null +++ b/src/lib/libc/gdtoa/hd_init.c @@ -0,0 +1,61 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + unsigned char hexdig[256]; + + static void +#ifdef KR_headers +htinit(h, s, inc) unsigned char *h; unsigned char *s; int inc; +#else +htinit(unsigned char *h, unsigned char *s, int inc) +#endif +{ + int i, j; + for(i = 0; (j = s[i]) !=0; i++) + h[j] = i + inc; + } + + void +hexdig_init_D2A(Void) +{ +#define USC (unsigned char *) + htinit(hexdig, USC "0123456789", 0x10); + htinit(hexdig, USC "abcdef", 0x10 + 10); + htinit(hexdig, USC "ABCDEF", 0x10 + 10); + } diff --git a/src/lib/libc/gdtoa/hexnan.c b/src/lib/libc/gdtoa/hexnan.c new file mode 100644 index 0000000..7a7e03a --- /dev/null +++ b/src/lib/libc/gdtoa/hexnan.c @@ -0,0 +1,137 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + static void +#ifdef KR_headers +L_shift(x, x1, i) ULong *x; ULong *x1; int i; +#else +L_shift(ULong *x, ULong *x1, int i) +#endif +{ + int j; + + i = 8 - i; + i <<= 2; + j = ULbits - i; + do { + *x |= x[1] << j; + x[1] >>= i; + } while(++x < x1); + } + + int +#ifdef KR_headers +hexnan(sp, fpi, x0) + CONST char **sp; FPI *fpi; ULong *x0; +#else +hexnan( CONST char **sp, FPI *fpi, ULong *x0) +#endif +{ + ULong c, h, *x, *x1, *xe; + CONST char *s; + int havedig, hd0, i, nbits; + + if (!hexdig['0']) + hexdig_init_D2A(); + nbits = fpi->nbits; + x = x0 + (nbits >> kshift); + if (nbits & kmask) + x++; + *--x = 0; + x1 = xe = x; + havedig = hd0 = i = 0; + s = *sp; + while(c = *(CONST unsigned char*)++s) { + if (!(h = hexdig[c])) { + if (c <= ' ') { + if (hd0 < havedig) { + if (x < x1 && i < 8) + L_shift(x, x1, i); + if (x <= x0) { + i = 8; + continue; + } + hd0 = havedig; + *--x = 0; + x1 = x; + i = 0; + } + continue; + } + if (/*(*/ c == ')' && havedig) { + *sp = s + 1; + break; + } + return STRTOG_NaN; + } + havedig++; + if (++i > 8) { + if (x <= x0) + continue; + i = 1; + *--x = 0; + } + *x = (*x << 4) | h & 0xf; + } + if (!havedig) + return STRTOG_NaN; + if (x < x1 && i < 8) + L_shift(x, x1, i); + if (x > x0) { + x1 = x0; + do *x1++ = *x++; + while(x <= xe); + do *x1++ = 0; + while(x1 <= xe); + } + else { + /* truncate high-order word if necessary */ + if ( (i = nbits & (ULbits-1)) !=0) + *xe &= ((ULong)0xffffffff) >> (ULbits - i); + } + for(x1 = xe;; --x1) { + if (*x1 != 0) + break; + if (x1 == x0) { + *x1 = 1; + break; + } + } + return STRTOG_NaNbits; + } diff --git a/src/lib/libc/gdtoa/misc.c b/src/lib/libc/gdtoa/misc.c new file mode 100644 index 0000000..5f5cbc2 --- /dev/null +++ b/src/lib/libc/gdtoa/misc.c @@ -0,0 +1,862 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 1999 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + static Bigint *freelist[Kmax+1]; +#ifndef Omit_Private_Memory +#ifndef PRIVATE_MEM +#define PRIVATE_MEM 2304 +#endif +#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double)) +static double private_mem[PRIVATE_mem], *pmem_next = private_mem; +#endif + + Bigint * +Balloc +#ifdef KR_headers + (k) int k; +#else + (int k) +#endif +{ + int x; + Bigint *rv; +#ifndef Omit_Private_Memory + unsigned int len; +#endif + + ACQUIRE_DTOA_LOCK(0); + if ( (rv = freelist[k]) !=0) { + freelist[k] = rv->next; + } + else { + x = 1 << k; +#ifdef Omit_Private_Memory + rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong)); +#else + len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) + /sizeof(double); + if (pmem_next - private_mem + len <= PRIVATE_mem) { + rv = (Bigint*)pmem_next; + pmem_next += len; + } + else + rv = (Bigint*)MALLOC(len*sizeof(double)); +#endif + rv->k = k; + rv->maxwds = x; + } + FREE_DTOA_LOCK(0); + rv->sign = rv->wds = 0; + return rv; + } + + void +Bfree +#ifdef KR_headers + (v) Bigint *v; +#else + (Bigint *v) +#endif +{ + if (v) { + ACQUIRE_DTOA_LOCK(0); + v->next = freelist[v->k]; + freelist[v->k] = v; + FREE_DTOA_LOCK(0); + } + } + + int +lo0bits +#ifdef KR_headers + (y) ULong *y; +#else + (ULong *y) +#endif +{ + register int k; + register ULong x = *y; + + if (x & 7) { + if (x & 1) + return 0; + if (x & 2) { + *y = x >> 1; + return 1; + } + *y = x >> 2; + return 2; + } + k = 0; + if (!(x & 0xffff)) { + k = 16; + x >>= 16; + } + if (!(x & 0xff)) { + k += 8; + x >>= 8; + } + if (!(x & 0xf)) { + k += 4; + x >>= 4; + } + if (!(x & 0x3)) { + k += 2; + x >>= 2; + } + if (!(x & 1)) { + k++; + x >>= 1; + if (!x & 1) + return 32; + } + *y = x; + return k; + } + + Bigint * +multadd +#ifdef KR_headers + (b, m, a) Bigint *b; int m, a; +#else + (Bigint *b, int m, int a) /* multiply by m and add a */ +#endif +{ + int i, wds; +#ifdef ULLong + ULong *x; + ULLong carry, y; +#else + ULong carry, *x, y; +#ifdef Pack_32 + ULong xi, z; +#endif +#endif + Bigint *b1; + + wds = b->wds; + x = b->x; + i = 0; + carry = a; + do { +#ifdef ULLong + y = *x * (ULLong)m + carry; + carry = y >> 32; + *x++ = y & 0xffffffffUL; +#else +#ifdef Pack_32 + xi = *x; + y = (xi & 0xffff) * m + carry; + z = (xi >> 16) * m + (y >> 16); + carry = z >> 16; + *x++ = (z << 16) + (y & 0xffff); +#else + y = *x * m + carry; + carry = y >> 16; + *x++ = y & 0xffff; +#endif +#endif + } + while(++i < wds); + if (carry) { + if (wds >= b->maxwds) { + b1 = Balloc(b->k+1); + Bcopy(b1, b); + Bfree(b); + b = b1; + } + b->x[wds++] = carry; + b->wds = wds; + } + return b; + } + + int +hi0bits +#ifdef KR_headers + (x) register ULong x; +#else + (register ULong x) +#endif +{ + register int k = 0; + + if (!(x & 0xffff0000)) { + k = 16; + x <<= 16; + } + if (!(x & 0xff000000)) { + k += 8; + x <<= 8; + } + if (!(x & 0xf0000000)) { + k += 4; + x <<= 4; + } + if (!(x & 0xc0000000)) { + k += 2; + x <<= 2; + } + if (!(x & 0x80000000)) { + k++; + if (!(x & 0x40000000)) + return 32; + } + return k; + } + + Bigint * +i2b +#ifdef KR_headers + (i) int i; +#else + (int i) +#endif +{ + Bigint *b; + + b = Balloc(1); + b->x[0] = i; + b->wds = 1; + return b; + } + + Bigint * +mult +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + Bigint *c; + int k, wa, wb, wc; + ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; + ULong y; +#ifdef ULLong + ULLong carry, z; +#else + ULong carry, z; +#ifdef Pack_32 + ULong z2; +#endif +#endif + + if (a->wds < b->wds) { + c = a; + a = b; + b = c; + } + k = a->k; + wa = a->wds; + wb = b->wds; + wc = wa + wb; + if (wc > a->maxwds) + k++; + c = Balloc(k); + for(x = c->x, xa = x + wc; x < xa; x++) + *x = 0; + xa = a->x; + xae = xa + wa; + xb = b->x; + xbe = xb + wb; + xc0 = c->x; +#ifdef ULLong + for(; xb < xbe; xc0++) { + if ( (y = *xb++) !=0) { + x = xa; + xc = xc0; + carry = 0; + do { + z = *x++ * (ULLong)y + *xc + carry; + carry = z >> 32; + *xc++ = z & 0xffffffffUL; + } + while(x < xae); + *xc = carry; + } + } +#else +#ifdef Pack_32 + for(; xb < xbe; xb++, xc0++) { + if ( (y = *xb & 0xffff) !=0) { + x = xa; + xc = xc0; + carry = 0; + do { + z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; + carry = z >> 16; + z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; + carry = z2 >> 16; + Storeinc(xc, z2, z); + } + while(x < xae); + *xc = carry; + } + if ( (y = *xb >> 16) !=0) { + x = xa; + xc = xc0; + carry = 0; + z2 = *xc; + do { + z = (*x & 0xffff) * y + (*xc >> 16) + carry; + carry = z >> 16; + Storeinc(xc, z, z2); + z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; + carry = z2 >> 16; + } + while(x < xae); + *xc = z2; + } + } +#else + for(; xb < xbe; xc0++) { + if ( (y = *xb++) !=0) { + x = xa; + xc = xc0; + carry = 0; + do { + z = *x++ * y + *xc + carry; + carry = z >> 16; + *xc++ = z & 0xffff; + } + while(x < xae); + *xc = carry; + } + } +#endif +#endif + for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ; + c->wds = wc; + return c; + } + + static Bigint *p5s; + + Bigint * +pow5mult +#ifdef KR_headers + (b, k) Bigint *b; int k; +#else + (Bigint *b, int k) +#endif +{ + Bigint *b1, *p5, *p51; + int i; + static int p05[3] = { 5, 25, 125 }; + + if ( (i = k & 3) !=0) + b = multadd(b, p05[i-1], 0); + + if (!(k >>= 2)) + return b; + if ((p5 = p5s) == 0) { + /* first time */ +#ifdef MULTIPLE_THREADS + ACQUIRE_DTOA_LOCK(1); + if (!(p5 = p5s)) { + p5 = p5s = i2b(625); + p5->next = 0; + } + FREE_DTOA_LOCK(1); +#else + p5 = p5s = i2b(625); + p5->next = 0; +#endif + } + for(;;) { + if (k & 1) { + b1 = mult(b, p5); + Bfree(b); + b = b1; + } + if (!(k >>= 1)) + break; + if ((p51 = p5->next) == 0) { +#ifdef MULTIPLE_THREADS + ACQUIRE_DTOA_LOCK(1); + if (!(p51 = p5->next)) { + p51 = p5->next = mult(p5,p5); + p51->next = 0; + } + FREE_DTOA_LOCK(1); +#else + p51 = p5->next = mult(p5,p5); + p51->next = 0; +#endif + } + p5 = p51; + } + return b; + } + + Bigint * +lshift +#ifdef KR_headers + (b, k) Bigint *b; int k; +#else + (Bigint *b, int k) +#endif +{ + int i, k1, n, n1; + Bigint *b1; + ULong *x, *x1, *xe, z; + + n = k >> kshift; + k1 = b->k; + n1 = n + b->wds + 1; + for(i = b->maxwds; n1 > i; i <<= 1) + k1++; + b1 = Balloc(k1); + x1 = b1->x; + for(i = 0; i < n; i++) + *x1++ = 0; + x = b->x; + xe = x + b->wds; + if (k &= kmask) { +#ifdef Pack_32 + k1 = 32 - k; + z = 0; + do { + *x1++ = *x << k | z; + z = *x++ >> k1; + } + while(x < xe); + if ((*x1 = z) !=0) + ++n1; +#else + k1 = 16 - k; + z = 0; + do { + *x1++ = *x << k & 0xffff | z; + z = *x++ >> k1; + } + while(x < xe); + if (*x1 = z) + ++n1; +#endif + } + else do + *x1++ = *x++; + while(x < xe); + b1->wds = n1 - 1; + Bfree(b); + return b1; + } + + int +cmp +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + ULong *xa, *xa0, *xb, *xb0; + int i, j; + + i = a->wds; + j = b->wds; +#ifdef DEBUG + if (i > 1 && !a->x[i-1]) + Bug("cmp called with a->x[a->wds-1] == 0"); + if (j > 1 && !b->x[j-1]) + Bug("cmp called with b->x[b->wds-1] == 0"); +#endif + if (i -= j) + return i; + xa0 = a->x; + xa = xa0 + j; + xb0 = b->x; + xb = xb0 + j; + for(;;) { + if (*--xa != *--xb) + return *xa < *xb ? -1 : 1; + if (xa <= xa0) + break; + } + return 0; + } + + Bigint * +diff +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + Bigint *c; + int i, wa, wb; + ULong *xa, *xae, *xb, *xbe, *xc; +#ifdef ULLong + ULLong borrow, y; +#else + ULong borrow, y; +#ifdef Pack_32 + ULong z; +#endif +#endif + + i = cmp(a,b); + if (!i) { + c = Balloc(0); + c->wds = 1; + c->x[0] = 0; + return c; + } + if (i < 0) { + c = a; + a = b; + b = c; + i = 1; + } + else + i = 0; + c = Balloc(a->k); + c->sign = i; + wa = a->wds; + xa = a->x; + xae = xa + wa; + wb = b->wds; + xb = b->x; + xbe = xb + wb; + xc = c->x; + borrow = 0; +#ifdef ULLong + do { + y = (ULLong)*xa++ - *xb++ - borrow; + borrow = y >> 32 & 1UL; + *xc++ = y & 0xffffffffUL; + } + while(xb < xbe); + while(xa < xae) { + y = *xa++ - borrow; + borrow = y >> 32 & 1UL; + *xc++ = y & 0xffffffffUL; + } +#else +#ifdef Pack_32 + do { + y = (*xa & 0xffff) - (*xb & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*xa++ >> 16) - (*xb++ >> 16) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } + while(xb < xbe); + while(xa < xae) { + y = (*xa & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*xa++ >> 16) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } +#else + do { + y = *xa++ - *xb++ - borrow; + borrow = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } + while(xb < xbe); + while(xa < xae) { + y = *xa++ - borrow; + borrow = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } +#endif +#endif + while(!*--xc) + wa--; + c->wds = wa; + return c; + } + + double +b2d +#ifdef KR_headers + (a, e) Bigint *a; int *e; +#else + (Bigint *a, int *e) +#endif +{ + ULong *xa, *xa0, w, y, z; + int k; + double d; +#ifdef VAX + ULong d0, d1; +#else +#define d0 word0(d) +#define d1 word1(d) +#endif + + xa0 = a->x; + xa = xa0 + a->wds; + y = *--xa; +#ifdef DEBUG + if (!y) Bug("zero y in b2d"); +#endif + k = hi0bits(y); + *e = 32 - k; +#ifdef Pack_32 + if (k < Ebits) { + d0 = Exp_1 | y >> Ebits - k; + w = xa > xa0 ? *--xa : 0; + d1 = y << (32-Ebits) + k | w >> Ebits - k; + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + if (k -= Ebits) { + d0 = Exp_1 | y << k | z >> 32 - k; + y = xa > xa0 ? *--xa : 0; + d1 = z << k | y >> 32 - k; + } + else { + d0 = Exp_1 | y; + d1 = z; + } +#else + if (k < Ebits + 16) { + z = xa > xa0 ? *--xa : 0; + d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; + w = xa > xa0 ? *--xa : 0; + y = xa > xa0 ? *--xa : 0; + d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + w = xa > xa0 ? *--xa : 0; + k -= Ebits + 16; + d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; + y = xa > xa0 ? *--xa : 0; + d1 = w << k + 16 | y << k; +#endif + ret_d: +#ifdef VAX + word0(d) = d0 >> 16 | d0 << 16; + word1(d) = d1 >> 16 | d1 << 16; +#endif + return dval(d); + } +#undef d0 +#undef d1 + + Bigint * +d2b +#ifdef KR_headers + (d, e, bits) double d; int *e, *bits; +#else + (double d, int *e, int *bits) +#endif +{ + Bigint *b; + int de, i, k; + ULong *x, y, z; +#ifdef VAX + ULong d0, d1; + d0 = word0(d) >> 16 | word0(d) << 16; + d1 = word1(d) >> 16 | word1(d) << 16; +#else +#define d0 word0(d) +#define d1 word1(d) +#endif + +#ifdef Pack_32 + b = Balloc(1); +#else + b = Balloc(2); +#endif + x = b->x; + + z = d0 & Frac_mask; + d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ +#ifdef Sudden_Underflow + de = (int)(d0 >> Exp_shift); +#ifndef IBM + z |= Exp_msk11; +#endif +#else + if ( (de = (int)(d0 >> Exp_shift)) !=0) + z |= Exp_msk1; +#endif +#ifdef Pack_32 + if ( (y = d1) !=0) { + if ( (k = lo0bits(&y)) !=0) { + x[0] = y | z << 32 - k; + z >>= k; + } + else + x[0] = y; + i = b->wds = (x[1] = z) !=0 ? 2 : 1; + } + else { +#ifdef DEBUG + if (!z) + Bug("Zero passed to d2b"); +#endif + k = lo0bits(&z); + x[0] = z; + i = b->wds = 1; + k += 32; + } +#else + if ( (y = d1) !=0) { + if ( (k = lo0bits(&y)) !=0) + if (k >= 16) { + x[0] = y | z << 32 - k & 0xffff; + x[1] = z >> k - 16 & 0xffff; + x[2] = z >> k; + i = 2; + } + else { + x[0] = y & 0xffff; + x[1] = y >> 16 | z << 16 - k & 0xffff; + x[2] = z >> k & 0xffff; + x[3] = z >> k+16; + i = 3; + } + else { + x[0] = y & 0xffff; + x[1] = y >> 16; + x[2] = z & 0xffff; + x[3] = z >> 16; + i = 3; + } + } + else { +#ifdef DEBUG + if (!z) + Bug("Zero passed to d2b"); +#endif + k = lo0bits(&z); + if (k >= 16) { + x[0] = z; + i = 0; + } + else { + x[0] = z & 0xffff; + x[1] = z >> 16; + i = 1; + } + k += 32; + } + while(!x[i]) + --i; + b->wds = i + 1; +#endif +#ifndef Sudden_Underflow + if (de) { +#endif +#ifdef IBM + *e = (de - Bias - (P-1) << 2) + k; + *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); +#else + *e = de - Bias - (P-1) + k; + *bits = P - k; +#endif +#ifndef Sudden_Underflow + } + else { + *e = de - Bias - (P-1) + 1 + k; +#ifdef Pack_32 + *bits = 32*i - hi0bits(x[i-1]); +#else + *bits = (i+2)*16 - hi0bits(x[i]); +#endif + } +#endif + return b; + } +#undef d0 +#undef d1 + + CONST double +#ifdef IEEE_Arith +bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; +CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 + }; +#else +#ifdef IBM +bigtens[] = { 1e16, 1e32, 1e64 }; +CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 }; +#else +bigtens[] = { 1e16, 1e32 }; +CONST double tinytens[] = { 1e-16, 1e-32 }; +#endif +#endif + + CONST double +tens[] = { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22 +#ifdef VAX + , 1e23, 1e24 +#endif + }; + + char * +#ifdef KR_headers +strcp_D2A(a, b) char *a; char *b; +#else +strcp_D2A(char *a, CONST char *b) +#endif +{ + while(*a = *b++) + a++; + return a; + } + +#ifdef NO_STRING_H + + Char * +#ifdef KR_headers +memcpy_D2A(a, b, len) Char *a; Char *b; size_t len; +#else +memcpy_D2A(void *a1, void *b1, size_t len) +#endif +{ + register char *a = (char*)a1, *ae = a + len; + register char *b = (char*)b1, *a0 = a; + while(a < ae) + *a++ = *b++; + return a0; + } + +#endif /* NO_STRING_H */ diff --git a/src/lib/libc/gdtoa/smisc.c b/src/lib/libc/gdtoa/smisc.c new file mode 100644 index 0000000..e20e9da --- /dev/null +++ b/src/lib/libc/gdtoa/smisc.c @@ -0,0 +1,197 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 1999 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + Bigint * +s2b +#ifdef KR_headers + (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; +#else + (CONST char *s, int nd0, int nd, ULong y9) +#endif +{ + Bigint *b; + int i, k; + Long x, y; + + x = (nd + 8) / 9; + for(k = 0, y = 1; x > y; y <<= 1, k++) ; +#ifdef Pack_32 + b = Balloc(k); + b->x[0] = y9; + b->wds = 1; +#else + b = Balloc(k+1); + b->x[0] = y9 & 0xffff; + b->wds = (b->x[1] = y9 >> 16) ? 2 : 1; +#endif + + i = 9; + if (9 < nd0) { + s += 9; + do b = multadd(b, 10, *s++ - '0'); + while(++i < nd0); + s++; + } + else + s += 10; + for(; i < nd; i++) + b = multadd(b, 10, *s++ - '0'); + return b; + } + + double +ratio +#ifdef KR_headers + (a, b) Bigint *a, *b; +#else + (Bigint *a, Bigint *b) +#endif +{ + double da, db; + int k, ka, kb; + + dval(da) = b2d(a, &ka); + dval(db) = b2d(b, &kb); + k = ka - kb + ULbits*(a->wds - b->wds); +#ifdef IBM + if (k > 0) { + word0(da) += (k >> 2)*Exp_msk1; + if (k &= 3) + dval(da) *= 1 << k; + } + else { + k = -k; + word0(db) += (k >> 2)*Exp_msk1; + if (k &= 3) + dval(db) *= 1 << k; + } +#else + if (k > 0) + word0(da) += k*Exp_msk1; + else { + k = -k; + word0(db) += k*Exp_msk1; + } +#endif + return dval(da) / dval(db); + } + +#ifdef INFNAN_CHECK + + int +match +#ifdef KR_headers + (sp, t) char **sp, *t; +#else + (CONST char **sp, char *t) +#endif +{ + int c, d; + CONST char *s = *sp; + + while( (d = *t++) !=0) { + if ((c = *++s) >= 'A' && c <= 'Z') + c += 'a' - 'A'; + if (c != d) + return 0; + } + *sp = s + 1; + return 1; + } +#endif /* INFNAN_CHECK */ + + void +#ifdef KR_headers +copybits(c, n, b) ULong *c; int n; Bigint *b; +#else +copybits(ULong *c, int n, Bigint *b) +#endif +{ + ULong *ce, *x, *xe; +#ifdef Pack_16 + int nw, nw1; +#endif + + ce = c + ((n-1) >> kshift) + 1; + x = b->x; +#ifdef Pack_32 + xe = x + b->wds; + while(x < xe) + *c++ = *x++; +#else + nw = b->wds; + nw1 = nw & 1; + for(xe = x + (nw - nw1); x < xe; x += 2) + Storeinc(c, x[1], x[0]); + if (nw1) + *c++ = *x; +#endif + while(c < ce) + *c++ = 0; + } + + ULong +#ifdef KR_headers +any_on(b, k) Bigint *b; int k; +#else +any_on(Bigint *b, int k) +#endif +{ + int n, nwds; + ULong *x, *x0, x1, x2; + + x = b->x; + nwds = b->wds; + n = k >> kshift; + if (n > nwds) + n = nwds; + else if (n < nwds && (k &= kmask)) { + x1 = x2 = x[n]; + x1 >>= k; + x1 <<= k; + if (x1 != x2) + return 1; + } + x0 = x; + x += n; + while(x > x0) + if (*--x) + return 1; + return 0; + } diff --git a/src/lib/libc/gdtoa/strtoIQ.c b/src/lib/libc/gdtoa/strtoIQ.c new file mode 100644 index 0000000..0ce0420 --- /dev/null +++ b/src/lib/libc/gdtoa/strtoIQ.c @@ -0,0 +1,69 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtoIQ(s, sp, a, b) CONST char *s; char **sp; void *a; void *b; +#else +strtoIQ(CONST char *s, char **sp, void *a, void *b) +#endif +{ + static FPI fpi = { 113, 1-16383-113+1, 32766-16383-113+1, 1, SI }; + Long exp[2]; + Bigint *B[2]; + int k, rv[2]; + ULong *L = (ULong *)a, *M = (ULong *)b; + + B[0] = Balloc(2); + B[0]->wds = 4; + k = strtoIg(s, sp, &fpi, exp, B, rv); + ULtoQ(L, B[0]->x, exp[0], rv[0]); + Bfree(B[0]); + if (B[1]) { + ULtoQ(M, B[1]->x, exp[1], rv[1]); + Bfree(B[1]); + } + else { + M[0] = L[0]; + M[1] = L[1]; + M[2] = L[2]; + M[3] = L[3]; + } + return k; + } diff --git a/src/lib/libc/gdtoa/strtoId.c b/src/lib/libc/gdtoa/strtoId.c new file mode 100644 index 0000000..f986e04 --- /dev/null +++ b/src/lib/libc/gdtoa/strtoId.c @@ -0,0 +1,66 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtoId(s, sp, f0, f1) CONST char *s; char **sp; double *f0, *f1; +#else +strtoId(CONST char *s, char **sp, double *f0, double *f1) +#endif +{ + static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; + Long exp[2]; + Bigint *B[2]; + int k, rv[2]; + + B[0] = Balloc(1); + B[0]->wds = 2; + k = strtoIg(s, sp, &fpi, exp, B, rv); + ULtod((ULong*)f0, B[0]->x, exp[0], rv[0]); + Bfree(B[0]); + if (B[1]) { + ULtod((ULong*)f1, B[1]->x, exp[1], rv[1]); + Bfree(B[1]); + } + else { + ((ULong*)f1)[0] = ((ULong*)f0)[0]; + ((ULong*)f1)[1] = ((ULong*)f0)[1]; + } + return k; + } diff --git a/src/lib/libc/gdtoa/strtoIdd.c b/src/lib/libc/gdtoa/strtoIdd.c new file mode 100644 index 0000000..9622c18 --- /dev/null +++ b/src/lib/libc/gdtoa/strtoIdd.c @@ -0,0 +1,72 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtoIdd(s, sp, f0, f1) CONST char *s; char **sp; double *f0, *f1; +#else +strtoIdd(CONST char *s, char **sp, double *f0, double *f1) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 106, 1-1023, 2046-1023-106+1, 1, 1 }; +#else + static FPI fpi = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 }; +#endif + Long exp[2]; + Bigint *B[2]; + int k, rv[2]; + + B[0] = Balloc(2); + B[0]->wds = 4; + k = strtoIg(s, sp, &fpi, exp, B, rv); + ULtodd((ULong*)f0, B[0]->x, exp[0], rv[0]); + Bfree(B[0]); + if (B[1]) { + ULtodd((ULong*)f1, B[1]->x, exp[1], rv[1]); + Bfree(B[1]); + } + else { + ((ULong*)f1)[0] = ((ULong*)f0)[0]; + ((ULong*)f1)[1] = ((ULong*)f0)[1]; + ((ULong*)f1)[2] = ((ULong*)f0)[2]; + ((ULong*)f1)[3] = ((ULong*)f0)[3]; + } + return k; + } diff --git a/src/lib/libc/gdtoa/strtoIf.c b/src/lib/libc/gdtoa/strtoIf.c new file mode 100644 index 0000000..c439ff5 --- /dev/null +++ b/src/lib/libc/gdtoa/strtoIf.c @@ -0,0 +1,64 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtoIf(s, sp, f0, f1) CONST char *s; char **sp; float *f0, *f1; +#else +strtoIf(CONST char *s, char **sp, float *f0, float *f1) +#endif +{ + static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; + Long exp[2]; + Bigint *B[2]; + int k, rv[2]; + + B[0] = Balloc(0); + B[0]->wds = 1; + k = strtoIg(s, sp, &fpi, exp, B, rv); + ULtof((ULong*)f0, B[0]->x, exp[0], rv[0]); + Bfree(B[0]); + if (B[1]) { + ULtof((ULong*)f1, B[1]->x, exp[1], rv[1]); + Bfree(B[1]); + } + else + *(ULong*)f1 = *(ULong*)f0; + return k; + } diff --git a/src/lib/libc/gdtoa/strtoIg.c b/src/lib/libc/gdtoa/strtoIg.c new file mode 100644 index 0000000..a766813 --- /dev/null +++ b/src/lib/libc/gdtoa/strtoIg.c @@ -0,0 +1,139 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtoIg(s00, se, fpi, exp, B, rvp) CONST char *s00; char **se; FPI *fpi; Long *exp; Bigint **B; int *rvp; +#else +strtoIg(CONST char *s00, char **se, FPI *fpi, Long *exp, Bigint **B, int *rvp) +#endif +{ + Bigint *b, *b1; + int i, nb, nw, nw1, rv, rv1, swap; + unsigned int nb1, nb11; + Long e1; + + b = *B; + rv = strtodg(s00, se, fpi, exp, b->x); + if (!(rv & STRTOG_Inexact)) { + B[1] = 0; + return *rvp = rv; + } + e1 = exp[0]; + rv1 = rv ^ STRTOG_Inexact; + b1 = Balloc(b->k); + Bcopy(b1, b); + nb = fpi->nbits; + nb1 = nb & 31; + nb11 = (nb1 - 1) & 31; + nw = b->wds; + nw1 = nw - 1; + if (rv & STRTOG_Inexlo) { + swap = 0; + b1 = increment(b1); + if (fpi->sudden_underflow + && (rv & STRTOG_Retmask) == STRTOG_Zero) { + b1->x[0] = 0; + b1->x[nw1] = 1L << nb11; + rv1 += STRTOG_Normal - STRTOG_Zero; + rv1 &= ~STRTOG_Underflow; + goto swapcheck; + } + if (b1->wds > nw + || nb1 && b1->x[nw1] & 1L << nb1) { + if (++e1 > fpi->emax) + rv1 = STRTOG_Infinite | STRTOG_Inexhi; + rshift(b1, 1); + } + else if ((rv & STRTOG_Retmask) == STRTOG_Denormal) { + if (b1->x[nw1] & 1L << nb11) { + rv1 += STRTOG_Normal - STRTOG_Denormal; + rv1 &= ~STRTOG_Underflow; + } + } + } + else { + swap = STRTOG_Neg; + if ((rv & STRTOG_Retmask) == STRTOG_Infinite) { + b1 = set_ones(b1, nb); + e1 = fpi->emax; + rv1 = STRTOG_Normal | STRTOG_Inexlo; + goto swapcheck; + } + decrement(b1); + if ((rv & STRTOG_Retmask) == STRTOG_Denormal) { + for(i = nw1; !b1->x[i]; --i) + if (!i) { + rv1 = STRTOG_Zero | STRTOG_Inexlo; + break; + } + goto swapcheck; + } + if (!(b1->x[nw1] & 1L << nb11)) { + if (e1 == fpi->emin) { + if (fpi->sudden_underflow) + rv1 += STRTOG_Zero - STRTOG_Normal; + else + rv1 += STRTOG_Denormal - STRTOG_Normal; + rv1 |= STRTOG_Underflow; + } + else { + b1 = lshift(b1, 1); + b1->x[0] |= 1; + --e1; + } + } + } + swapcheck: + if (swap ^ (rv & STRTOG_Neg)) { + rvp[0] = rv1; + rvp[1] = rv; + B[0] = b1; + B[1] = b; + exp[1] = exp[0]; + exp[0] = e1; + } + else { + rvp[0] = rv; + rvp[1] = rv1; + B[1] = b1; + exp[1] = e1; + } + return rv; + } diff --git a/src/lib/libc/gdtoa/strtoIx.c b/src/lib/libc/gdtoa/strtoIx.c new file mode 100644 index 0000000..d699f04 --- /dev/null +++ b/src/lib/libc/gdtoa/strtoIx.c @@ -0,0 +1,70 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtoIx(s, sp, a, b) CONST char *s; char **sp; void *a; void *b; +#else +strtoIx(CONST char *s, char **sp, void *a, void *b) +#endif +{ + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + Long exp[2]; + Bigint *B[2]; + int k, rv[2]; + UShort *L = (UShort *)a, *M = (UShort *)b; + + B[0] = Balloc(1); + B[0]->wds = 2; + k = strtoIg(s, sp, &fpi, exp, B, rv); + ULtox(L, B[0]->x, exp[0], rv[0]); + Bfree(B[0]); + if (B[1]) { + ULtox(M, B[1]->x, exp[1], rv[1]); + Bfree(B[1]); + } + else { + M[0] = L[0]; + M[1] = L[1]; + M[2] = L[2]; + M[3] = L[3]; + M[4] = L[4]; + } + return k; + } diff --git a/src/lib/libc/gdtoa/strtoIxL.c b/src/lib/libc/gdtoa/strtoIxL.c new file mode 100644 index 0000000..c579589 --- /dev/null +++ b/src/lib/libc/gdtoa/strtoIxL.c @@ -0,0 +1,68 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtoIxL(s, sp, a, b) CONST char *s; char **sp; void *a; void *b; +#else +strtoIxL(CONST char *s, char **sp, void *a, void *b) +#endif +{ + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + Long exp[2]; + Bigint *B[2]; + int k, rv[2]; + ULong *L = (ULong *)a, *M = (ULong *)b; + + B[0] = Balloc(1); + B[0]->wds = 2; + k = strtoIg(s, sp, &fpi, exp, B, rv); + ULtoxL(L, B[0]->x, exp[0], rv[0]); + Bfree(B[0]); + if (B[1]) { + ULtoxL(M, B[1]->x, exp[1], rv[1]); + Bfree(B[1]); + } + else { + M[0] = L[0]; + M[1] = L[1]; + M[2] = L[2]; + } + return k; + } diff --git a/src/lib/libc/gdtoa/strtod.c b/src/lib/libc/gdtoa/strtod.c new file mode 100644 index 0000000..4913d50 --- /dev/null +++ b/src/lib/libc/gdtoa/strtod.c @@ -0,0 +1,966 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + dmg@acm.org + */ + +#include "gdtoaimp.h" + +#ifdef USE_LOCALE +#include "locale.h" +#endif + +#ifdef IEEE_Arith +#ifndef NO_IEEE_Scale +#define Avoid_Underflow +#undef tinytens +/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */ +/* flag unnecessarily. It leads to a song and dance at the end of strtod. */ +static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, + 9007199254740992.e-256 + }; +#endif +#endif + +#ifdef Honor_FLT_ROUNDS +#define Rounding rounding +#undef Check_FLT_ROUNDS +#define Check_FLT_ROUNDS +#else +#define Rounding Flt_Rounds +#endif + + double +strtod +#ifdef KR_headers + (s00, se) CONST char *s00; char **se; +#else + (CONST char *s00, char **se) +#endif +{ +#ifdef Avoid_Underflow + int scale; +#endif + int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, + e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; + CONST char *s, *s0, *s1; + double aadj, aadj1, adj, rv, rv0; + Long L; + ULong y, z; + Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; +#ifdef SET_INEXACT + int inexact, oldinexact; +#endif +#ifdef Honor_FLT_ROUNDS + int rounding; +#endif + + sign = nz0 = nz = 0; + dval(rv) = 0.; + for(s = s00;;s++) switch(*s) { + case '-': + sign = 1; + /* no break */ + case '+': + if (*++s) + goto break2; + /* no break */ + case 0: + goto ret0; + case '\t': + case '\n': + case '\v': + case '\f': + case '\r': + case ' ': + continue; + default: + goto break2; + } + break2: + if (*s == '0') { +#ifndef NO_HEX_FP + { + static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; + Long exp; + ULong bits[2]; + switch(s[1]) { + case 'x': + case 'X': + switch((i = gethex(&s, &fpi, &exp, &bb, sign)) & STRTOG_Retmask) { + case STRTOG_NoNumber: + s = s00; + sign = 0; + case STRTOG_Zero: + break; + default: + if (bb) { + copybits(bits, fpi.nbits, bb); + Bfree(bb); + } + ULtod(((U*)&rv)->L, bits, exp, i); + } + goto ret; + } + } +#endif + nz0 = 1; + while(*++s == '0') ; + if (!*s) + goto ret; + } + s0 = s; + y = z = 0; + for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) + if (nd < 9) + y = 10*y + c - '0'; + else if (nd < 16) + z = 10*z + c - '0'; + nd0 = nd; +#ifdef USE_LOCALE + if (c == *localeconv()->decimal_point) +#else + if (c == '.') +#endif + { + c = *++s; + if (!nd) { + for(; c == '0'; c = *++s) + nz++; + if (c > '0' && c <= '9') { + s0 = s; + nf += nz; + nz = 0; + goto have_dig; + } + goto dig_done; + } + for(; c >= '0' && c <= '9'; c = *++s) { + have_dig: + nz++; + if (c -= '0') { + nf += nz; + for(i = 1; i < nz; i++) + if (nd++ < 9) + y *= 10; + else if (nd <= DBL_DIG + 1) + z *= 10; + if (nd++ < 9) + y = 10*y + c; + else if (nd <= DBL_DIG + 1) + z = 10*z + c; + nz = 0; + } + } + } + dig_done: + e = 0; + if (c == 'e' || c == 'E') { + if (!nd && !nz && !nz0) { + goto ret0; + } + s00 = s; + esign = 0; + switch(c = *++s) { + case '-': + esign = 1; + case '+': + c = *++s; + } + if (c >= '0' && c <= '9') { + while(c == '0') + c = *++s; + if (c > '0' && c <= '9') { + L = c - '0'; + s1 = s; + while((c = *++s) >= '0' && c <= '9') + L = 10*L + c - '0'; + if (s - s1 > 8 || L > 19999) + /* Avoid confusion from exponents + * so large that e might overflow. + */ + e = 19999; /* safe for 16 bit ints */ + else + e = (int)L; + if (esign) + e = -e; + } + else + e = 0; + } + else + s = s00; + } + if (!nd) { + if (!nz && !nz0) { +#ifdef INFNAN_CHECK + /* Check for Nan and Infinity */ + ULong bits[2]; + static FPI fpinan = /* only 52 explicit bits */ + { 52, 1-1023-53+1, 2046-1023-53+1, 1, SI }; + switch(c) { + case 'i': + case 'I': + if (match(&s,"nf")) { + --s; + if (!match(&s,"inity")) + ++s; + word0(rv) = 0x7ff00000; + word1(rv) = 0; + goto ret; + } + break; + case 'n': + case 'N': + if (match(&s, "an")) { +#ifndef No_Hex_NaN + if (*s == '(' /*)*/ + && hexnan(&s, &fpinan, bits) + == STRTOG_NaNbits) { + word0(rv) = 0x7ff00000 | bits[1]; + word1(rv) = bits[0]; + } + else { + word0(rv) = NAN_WORD0; + word1(rv) = NAN_WORD1; + } +#endif + goto ret; + } + } +#endif /* INFNAN_CHECK */ + ret0: + s = s00; + sign = 0; + } + goto ret; + } + e1 = e -= nf; + + /* Now we have nd0 digits, starting at s0, followed by a + * decimal point, followed by nd-nd0 digits. The number we're + * after is the integer represented by those digits times + * 10**e */ + + if (!nd0) + nd0 = nd; + k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; + dval(rv) = y; + if (k > 9) { +#ifdef SET_INEXACT + if (k > DBL_DIG) + oldinexact = get_inexact(); +#endif + dval(rv) = tens[k - 9] * dval(rv) + z; + } + bd0 = 0; + if (nd <= DBL_DIG +#ifndef RND_PRODQUOT +#ifndef Honor_FLT_ROUNDS + && Flt_Rounds == 1 +#endif +#endif + ) { + if (!e) + goto ret; + if (e > 0) { + if (e <= Ten_pmax) { +#ifdef VAX + goto vax_ovfl_check; +#else +#ifdef Honor_FLT_ROUNDS + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv = -rv; + sign = 0; + } +#endif + /* rv = */ rounded_product(dval(rv), tens[e]); + goto ret; +#endif + } + i = DBL_DIG - nd; + if (e <= Ten_pmax + i) { + /* A fancier test would sometimes let us do + * this for larger i values. + */ +#ifdef Honor_FLT_ROUNDS + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv = -rv; + sign = 0; + } +#endif + e -= i; + dval(rv) *= tens[i]; +#ifdef VAX + /* VAX exponent range is so narrow we must + * worry about overflow here... + */ + vax_ovfl_check: + word0(rv) -= P*Exp_msk1; + /* rv = */ rounded_product(dval(rv), tens[e]); + if ((word0(rv) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) + goto ovfl; + word0(rv) += P*Exp_msk1; +#else + /* rv = */ rounded_product(dval(rv), tens[e]); +#endif + goto ret; + } + } +#ifndef Inaccurate_Divide + else if (e >= -Ten_pmax) { +#ifdef Honor_FLT_ROUNDS + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv = -rv; + sign = 0; + } +#endif + /* rv = */ rounded_quotient(dval(rv), tens[-e]); + goto ret; + } +#endif + } + e1 += nd - k; + +#ifdef IEEE_Arith +#ifdef SET_INEXACT + inexact = 1; + if (k <= DBL_DIG) + oldinexact = get_inexact(); +#endif +#ifdef Avoid_Underflow + scale = 0; +#endif +#ifdef Honor_FLT_ROUNDS + if ((rounding = Flt_Rounds) >= 2) { + if (sign) + rounding = rounding == 2 ? 0 : 2; + else + if (rounding != 2) + rounding = 0; + } +#endif +#endif /*IEEE_Arith*/ + + /* Get starting approximation = rv * 10**e1 */ + + if (e1 > 0) { + if ( (i = e1 & 15) !=0) + dval(rv) *= tens[i]; + if (e1 &= ~15) { + if (e1 > DBL_MAX_10_EXP) { + ovfl: +#ifndef NO_ERRNO + errno = ERANGE; +#endif + /* Can't trust HUGE_VAL */ +#ifdef IEEE_Arith +#ifdef Honor_FLT_ROUNDS + switch(rounding) { + case 0: /* toward 0 */ + case 3: /* toward -infinity */ + word0(rv) = Big0; + word1(rv) = Big1; + break; + default: + word0(rv) = Exp_mask; + word1(rv) = 0; + } +#else /*Honor_FLT_ROUNDS*/ + word0(rv) = Exp_mask; + word1(rv) = 0; +#endif /*Honor_FLT_ROUNDS*/ +#ifdef SET_INEXACT + /* set overflow bit */ + dval(rv0) = 1e300; + dval(rv0) *= dval(rv0); +#endif +#else /*IEEE_Arith*/ + word0(rv) = Big0; + word1(rv) = Big1; +#endif /*IEEE_Arith*/ + if (bd0) + goto retfree; + goto ret; + } + e1 >>= 4; + for(j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= bigtens[j]; + /* The last multiplication could overflow. */ + word0(rv) -= P*Exp_msk1; + dval(rv) *= bigtens[j]; + if ((z = word0(rv) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-P)) + goto ovfl; + if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) { + /* set to largest number */ + /* (Can't trust DBL_MAX) */ + word0(rv) = Big0; + word1(rv) = Big1; + } + else + word0(rv) += P*Exp_msk1; + } + } + else if (e1 < 0) { + e1 = -e1; + if ( (i = e1 & 15) !=0) + dval(rv) /= tens[i]; + if (e1 >>= 4) { + if (e1 >= 1 << n_bigtens) + goto undfl; +#ifdef Avoid_Underflow + if (e1 & Scale_Bit) + scale = 2*P; + for(j = 0; e1 > 0; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= tinytens[j]; + if (scale && (j = 2*P + 1 - ((word0(rv) & Exp_mask) + >> Exp_shift)) > 0) { + /* scaled rv is denormal; zap j low bits */ + if (j >= 32) { + word1(rv) = 0; + if (j >= 53) + word0(rv) = (P+2)*Exp_msk1; + else + word0(rv) &= 0xffffffff << j-32; + } + else + word1(rv) &= 0xffffffff << j; + } +#else + for(j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= tinytens[j]; + /* The last multiplication could underflow. */ + dval(rv0) = dval(rv); + dval(rv) *= tinytens[j]; + if (!dval(rv)) { + dval(rv) = 2.*dval(rv0); + dval(rv) *= tinytens[j]; +#endif + if (!dval(rv)) { + undfl: + dval(rv) = 0.; +#ifndef NO_ERRNO + errno = ERANGE; +#endif + if (bd0) + goto retfree; + goto ret; + } +#ifndef Avoid_Underflow + word0(rv) = Tiny0; + word1(rv) = Tiny1; + /* The refinement below will clean + * this approximation up. + */ + } +#endif + } + } + + /* Now the hard part -- adjusting rv to the correct value.*/ + + /* Put digits into bd: true value = bd * 10^e */ + + bd0 = s2b(s0, nd0, nd, y); + + for(;;) { + bd = Balloc(bd0->k); + Bcopy(bd, bd0); + bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ + bs = i2b(1); + + if (e >= 0) { + bb2 = bb5 = 0; + bd2 = bd5 = e; + } + else { + bb2 = bb5 = -e; + bd2 = bd5 = 0; + } + if (bbe >= 0) + bb2 += bbe; + else + bd2 -= bbe; + bs2 = bb2; +#ifdef Honor_FLT_ROUNDS + if (rounding != 1) + bs2++; +#endif +#ifdef Avoid_Underflow + j = bbe - scale; + i = j + bbbits - 1; /* logb(rv) */ + if (i < Emin) /* denormal */ + j += P - Emin; + else + j = P + 1 - bbbits; +#else /*Avoid_Underflow*/ +#ifdef Sudden_Underflow +#ifdef IBM + j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3); +#else + j = P + 1 - bbbits; +#endif +#else /*Sudden_Underflow*/ + j = bbe; + i = j + bbbits - 1; /* logb(rv) */ + if (i < Emin) /* denormal */ + j += P - Emin; + else + j = P + 1 - bbbits; +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + bb2 += j; + bd2 += j; +#ifdef Avoid_Underflow + bd2 += scale; +#endif + i = bb2 < bd2 ? bb2 : bd2; + if (i > bs2) + i = bs2; + if (i > 0) { + bb2 -= i; + bd2 -= i; + bs2 -= i; + } + if (bb5 > 0) { + bs = pow5mult(bs, bb5); + bb1 = mult(bs, bb); + Bfree(bb); + bb = bb1; + } + if (bb2 > 0) + bb = lshift(bb, bb2); + if (bd5 > 0) + bd = pow5mult(bd, bd5); + if (bd2 > 0) + bd = lshift(bd, bd2); + if (bs2 > 0) + bs = lshift(bs, bs2); + delta = diff(bb, bd); + dsign = delta->sign; + delta->sign = 0; + i = cmp(delta, bs); +#ifdef Honor_FLT_ROUNDS + if (rounding != 1) { + if (i < 0) { + /* Error is less than an ulp */ + if (!delta->x[0] && delta->wds <= 1) { + /* exact */ +#ifdef SET_INEXACT + inexact = 0; +#endif + break; + } + if (rounding) { + if (dsign) { + adj = 1.; + goto apply_adj; + } + } + else if (!dsign) { + adj = -1.; + if (!word1(rv) + && !(word0(rv) & Frac_mask)) { + y = word0(rv) & Exp_mask; +#ifdef Avoid_Underflow + if (!scale || y > 2*P*Exp_msk1) +#else + if (y) +#endif + { + delta = lshift(delta,Log2P); + if (cmp(delta, bs) <= 0) + adj = -0.5; + } + } + apply_adj: +#ifdef Avoid_Underflow + if (scale && (y = word0(rv) & Exp_mask) + <= 2*P*Exp_msk1) + word0(adj) += (2*P+1)*Exp_msk1 - y; +#else +#ifdef Sudden_Underflow + if ((word0(rv) & Exp_mask) <= + P*Exp_msk1) { + word0(rv) += P*Exp_msk1; + dval(rv) += adj*ulp(dval(rv)); + word0(rv) -= P*Exp_msk1; + } + else +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + dval(rv) += adj*ulp(dval(rv)); + } + break; + } + adj = ratio(delta, bs); + if (adj < 1.) + adj = 1.; + if (adj <= 0x7ffffffe) { + /* adj = rounding ? ceil(adj) : floor(adj); */ + y = adj; + if (y != adj) { + if (!((rounding>>1) ^ dsign)) + y++; + adj = y; + } + } +#ifdef Avoid_Underflow + if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) + word0(adj) += (2*P+1)*Exp_msk1 - y; +#else +#ifdef Sudden_Underflow + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { + word0(rv) += P*Exp_msk1; + adj *= ulp(dval(rv)); + if (dsign) + dval(rv) += adj; + else + dval(rv) -= adj; + word0(rv) -= P*Exp_msk1; + goto cont; + } +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + adj *= ulp(dval(rv)); + if (dsign) + dval(rv) += adj; + else + dval(rv) -= adj; + goto cont; + } +#endif /*Honor_FLT_ROUNDS*/ + + if (i < 0) { + /* Error is less than half an ulp -- check for + * special case of mantissa a power of two. + */ + if (dsign || word1(rv) || word0(rv) & Bndry_mask +#ifdef IEEE_Arith +#ifdef Avoid_Underflow + || (word0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1 +#else + || (word0(rv) & Exp_mask) <= Exp_msk1 +#endif +#endif + ) { +#ifdef SET_INEXACT + if (!delta->x[0] && delta->wds <= 1) + inexact = 0; +#endif + break; + } + if (!delta->x[0] && delta->wds <= 1) { + /* exact result */ +#ifdef SET_INEXACT + inexact = 0; +#endif + break; + } + delta = lshift(delta,Log2P); + if (cmp(delta, bs) > 0) + goto drop_down; + break; + } + if (i == 0) { + /* exactly half-way between */ + if (dsign) { + if ((word0(rv) & Bndry_mask1) == Bndry_mask1 + && word1(rv) == ( +#ifdef Avoid_Underflow + (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) + ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) : +#endif + 0xffffffff)) { + /*boundary case -- increment exponent*/ + word0(rv) = (word0(rv) & Exp_mask) + + Exp_msk1 +#ifdef IBM + | Exp_msk1 >> 4 +#endif + ; + word1(rv) = 0; +#ifdef Avoid_Underflow + dsign = 0; +#endif + break; + } + } + else if (!(word0(rv) & Bndry_mask) && !word1(rv)) { + drop_down: + /* boundary case -- decrement exponent */ +#ifdef Sudden_Underflow /*{{*/ + L = word0(rv) & Exp_mask; +#ifdef IBM + if (L < Exp_msk1) +#else +#ifdef Avoid_Underflow + if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1)) +#else + if (L <= Exp_msk1) +#endif /*Avoid_Underflow*/ +#endif /*IBM*/ + goto undfl; + L -= Exp_msk1; +#else /*Sudden_Underflow}{*/ +#ifdef Avoid_Underflow + if (scale) { + L = word0(rv) & Exp_mask; + if (L <= (2*P+1)*Exp_msk1) { + if (L > (P+2)*Exp_msk1) + /* round even ==> */ + /* accept rv */ + break; + /* rv = smallest denormal */ + goto undfl; + } + } +#endif /*Avoid_Underflow*/ + L = (word0(rv) & Exp_mask) - Exp_msk1; +#endif /*Sudden_Underflow}*/ + word0(rv) = L | Bndry_mask1; + word1(rv) = 0xffffffff; +#ifdef IBM + goto cont; +#else + break; +#endif + } +#ifndef ROUND_BIASED + if (!(word1(rv) & LSB)) + break; +#endif + if (dsign) + dval(rv) += ulp(dval(rv)); +#ifndef ROUND_BIASED + else { + dval(rv) -= ulp(dval(rv)); +#ifndef Sudden_Underflow + if (!dval(rv)) + goto undfl; +#endif + } +#ifdef Avoid_Underflow + dsign = 1 - dsign; +#endif +#endif + break; + } + if ((aadj = ratio(delta, bs)) <= 2.) { + if (dsign) + aadj = aadj1 = 1.; + else if (word1(rv) || word0(rv) & Bndry_mask) { +#ifndef Sudden_Underflow + if (word1(rv) == Tiny1 && !word0(rv)) + goto undfl; +#endif + aadj = 1.; + aadj1 = -1.; + } + else { + /* special case -- power of FLT_RADIX to be */ + /* rounded down... */ + + if (aadj < 2./FLT_RADIX) + aadj = 1./FLT_RADIX; + else + aadj *= 0.5; + aadj1 = -aadj; + } + } + else { + aadj *= 0.5; + aadj1 = dsign ? aadj : -aadj; +#ifdef Check_FLT_ROUNDS + switch(Rounding) { + case 2: /* towards +infinity */ + aadj1 -= 0.5; + break; + case 0: /* towards 0 */ + case 3: /* towards -infinity */ + aadj1 += 0.5; + } +#else + if (Flt_Rounds == 0) + aadj1 += 0.5; +#endif /*Check_FLT_ROUNDS*/ + } + y = word0(rv) & Exp_mask; + + /* Check for overflow */ + + if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { + dval(rv0) = dval(rv); + word0(rv) -= P*Exp_msk1; + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; + if ((word0(rv) & Exp_mask) >= + Exp_msk1*(DBL_MAX_EXP+Bias-P)) { + if (word0(rv0) == Big0 && word1(rv0) == Big1) + goto ovfl; + word0(rv) = Big0; + word1(rv) = Big1; + goto cont; + } + else + word0(rv) += P*Exp_msk1; + } + else { +#ifdef Avoid_Underflow + if (scale && y <= 2*P*Exp_msk1) { + if (aadj <= 0x7fffffff) { + if ((z = aadj) <= 0) + z = 1; + aadj = z; + aadj1 = dsign ? aadj : -aadj; + } + word0(aadj1) += (2*P+1)*Exp_msk1 - y; + } + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; +#else +#ifdef Sudden_Underflow + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { + dval(rv0) = dval(rv); + word0(rv) += P*Exp_msk1; + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; +#ifdef IBM + if ((word0(rv) & Exp_mask) < P*Exp_msk1) +#else + if ((word0(rv) & Exp_mask) <= P*Exp_msk1) +#endif + { + if (word0(rv0) == Tiny0 + && word1(rv0) == Tiny1) + goto undfl; + word0(rv) = Tiny0; + word1(rv) = Tiny1; + goto cont; + } + else + word0(rv) -= P*Exp_msk1; + } + else { + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; + } +#else /*Sudden_Underflow*/ + /* Compute adj so that the IEEE rounding rules will + * correctly round rv + adj in some half-way cases. + * If rv * ulp(rv) is denormalized (i.e., + * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid + * trouble from bits lost to denormalization; + * example: 1.2e-307 . + */ + if (y <= (P-1)*Exp_msk1 && aadj > 1.) { + aadj1 = (double)(int)(aadj + 0.5); + if (!dsign) + aadj1 = -aadj1; + } + adj = aadj1 * ulp(dval(rv)); + dval(rv) += adj; +#endif /*Sudden_Underflow*/ +#endif /*Avoid_Underflow*/ + } + z = word0(rv) & Exp_mask; +#ifndef SET_INEXACT +#ifdef Avoid_Underflow + if (!scale) +#endif + if (y == z) { + /* Can we stop now? */ + L = (Long)aadj; + aadj -= L; + /* The tolerances below are conservative. */ + if (dsign || word1(rv) || word0(rv) & Bndry_mask) { + if (aadj < .4999999 || aadj > .5000001) + break; + } + else if (aadj < .4999999/FLT_RADIX) + break; + } +#endif + cont: + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(delta); + } +#ifdef SET_INEXACT + if (inexact) { + if (!oldinexact) { + word0(rv0) = Exp_1 + (70 << Exp_shift); + word1(rv0) = 0; + dval(rv0) += 1.; + } + } + else if (!oldinexact) + clear_inexact(); +#endif +#ifdef Avoid_Underflow + if (scale) { + word0(rv0) = Exp_1 - 2*P*Exp_msk1; + word1(rv0) = 0; + dval(rv) *= dval(rv0); +#ifndef NO_ERRNO + /* try to avoid the bug of testing an 8087 register value */ + if (word0(rv) == 0 && word1(rv) == 0) + errno = ERANGE; +#endif + } +#endif /* Avoid_Underflow */ +#ifdef SET_INEXACT + if (inexact && !(word0(rv) & Exp_mask)) { + /* set underflow bit */ + dval(rv0) = 1e-300; + dval(rv0) *= dval(rv0); + } +#endif + retfree: + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(bd0); + Bfree(delta); + ret: + if (se) + *se = (char *)s; + return sign ? -dval(rv) : dval(rv); + } + diff --git a/src/lib/libc/gdtoa/strtodI.c b/src/lib/libc/gdtoa/strtodI.c new file mode 100644 index 0000000..163f363 --- /dev/null +++ b/src/lib/libc/gdtoa/strtodI.c @@ -0,0 +1,177 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + static double +#ifdef KR_headers +ulpdown(d) double *d; +#else +ulpdown(double *d) +#endif +{ + double u; + ULong *L = (ULong*)d; + + u = ulp(*d); + if (!(L[_1] | L[_0] & 0xfffff) + && (L[_0] & 0x7ff00000) > 0x00100000) + u *= 0.5; + return u; + } + + int +#ifdef KR_headers +strtodI(s, sp, dd) CONST char *s; char **sp; double *dd; +#else +strtodI(CONST char *s, char **sp, double *dd) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 1 }; +#else + static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 }; +#endif + ULong bits[2], sign; + Long exp; + int j, k; + typedef union { + double d[2]; + ULong L[4]; + } U; + U *u; + + k = strtodg(s, sp, &fpi, &exp, bits); + u = (U*)dd; + sign = k & STRTOG_Neg ? 0x80000000L : 0; + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + u->d[0] = u->d[1] = 0.; + break; + + case STRTOG_Zero: + u->d[0] = u->d[1] = 0.; +#ifdef Sudden_Underflow + if (k & STRTOG_Inexact) { + if (sign) + u->L[_0] = 0x80100000L; + else + u->L[2+_0] = 0x100000L; + } + break; +#else + goto contain; +#endif + + case STRTOG_Denormal: + u->L[_1] = bits[0]; + u->L[_0] = bits[1]; + goto contain; + + case STRTOG_Normal: + u->L[_1] = bits[0]; + u->L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20); + contain: + j = k & STRTOG_Inexact; + if (sign) { + u->L[_0] |= sign; + j = STRTOG_Inexact - j; + } + switch(j) { + case STRTOG_Inexlo: +#ifdef Sudden_Underflow + if ((u->L[_0] & 0x7ff00000) < 0x3500000) { + u->L[2+_0] = u->L[_0] + 0x3500000; + u->L[2+_1] = u->L[_1]; + u->d[1] += ulp(u->d[1]); + u->L[2+_0] -= 0x3500000; + if (!(u->L[2+_0] & 0x7ff00000)) { + u->L[2+_0] = sign; + u->L[2+_1] = 0; + } + } + else +#endif + u->d[1] = u->d[0] + ulp(u->d[0]); + break; + case STRTOG_Inexhi: + u->d[1] = u->d[0]; +#ifdef Sudden_Underflow + if ((u->L[_0] & 0x7ff00000) < 0x3500000) { + u->L[_0] += 0x3500000; + u->d[0] -= ulpdown(u->d); + u->L[_0] -= 0x3500000; + if (!(u->L[_0] & 0x7ff00000)) { + u->L[_0] = sign; + u->L[_1] = 0; + } + } + else +#endif + u->d[0] -= ulpdown(u->d); + break; + default: + u->d[1] = u->d[0]; + } + break; + + case STRTOG_Infinite: + u->L[_0] = u->L[2+_0] = sign | 0x7ff00000; + u->L[_1] = u->L[2+_1] = 0; + if (k & STRTOG_Inexact) { + if (sign) { + u->L[2+_0] = 0xffefffffL; + u->L[2+_1] = 0xffffffffL; + } + else { + u->L[_0] = 0x7fefffffL; + u->L[_1] = 0xffffffffL; + } + } + break; + + case STRTOG_NaN: + u->L[_0] = u->L[2+_0] = 0x7fffffff | sign; + u->L[_1] = u->L[2+_1] = (ULong)-1; + break; + + case STRTOG_NaNbits: + u->L[_0] = u->L[2+_0] = 0x7ff00000 | sign | bits[1]; + u->L[_1] = u->L[2+_1] = bits[0]; + } + return k; + } diff --git a/src/lib/libc/gdtoa/strtodg.c b/src/lib/libc/gdtoa/strtodg.c new file mode 100644 index 0000000..bf30e33 --- /dev/null +++ b/src/lib/libc/gdtoa/strtodg.c @@ -0,0 +1,1001 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + dmg@acm.org + */ + +#include "gdtoaimp.h" + +#ifdef USE_LOCALE +#include "locale.h" +#endif + + static CONST int +fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21, + 24, 26, 28, 31, 33, 35, 38, 40, 42, 45, + 47, 49, 52 +#ifdef VAX + , 54, 56 +#endif + }; + + Bigint * +#ifdef KR_headers +increment(b) Bigint *b; +#else +increment(Bigint *b) +#endif +{ + ULong *x, *xe; + Bigint *b1; +#ifdef Pack_16 + ULong carry = 1, y; +#endif + + x = b->x; + xe = x + b->wds; +#ifdef Pack_32 + do { + if (*x < (ULong)0xffffffffL) { + ++*x; + return b; + } + *x++ = 0; + } while(x < xe); +#else + do { + y = *x + carry; + carry = y >> 16; + *x++ = y & 0xffff; + if (!carry) + return b; + } while(x < xe); + if (carry) +#endif + { + if (b->wds >= b->maxwds) { + b1 = Balloc(b->k+1); + Bcopy(b1,b); + Bfree(b); + b = b1; + } + b->x[b->wds++] = 1; + } + return b; + } + + int +#ifdef KR_headers +decrement(b) Bigint *b; +#else +decrement(Bigint *b) +#endif +{ + ULong *x, *xe; +#ifdef Pack_16 + ULong borrow = 1, y; +#endif + + x = b->x; + xe = x + b->wds; +#ifdef Pack_32 + do { + if (*x) { + --*x; + break; + } + *x++ = 0xffffffffL; + } + while(x < xe); +#else + do { + y = *x - borrow; + borrow = (y & 0x10000) >> 16; + *x++ = y & 0xffff; + } while(borrow && x < xe); +#endif + return STRTOG_Inexlo; + } + + static int +#ifdef KR_headers +all_on(b, n) Bigint *b; int n; +#else +all_on(Bigint *b, int n) +#endif +{ + ULong *x, *xe; + + x = b->x; + xe = x + (n >> kshift); + while(x < xe) + if ((*x++ & ALL_ON) != ALL_ON) + return 0; + if (n &= kmask) + return ((*x | (ALL_ON << n)) & ALL_ON) == ALL_ON; + return 1; + } + + Bigint * +#ifdef KR_headers +set_ones(b, n) Bigint *b; int n; +#else +set_ones(Bigint *b, int n) +#endif +{ + int k; + ULong *x, *xe; + + k = (n + ((1 << kshift) - 1)) >> kshift; + if (b->k < k) { + Bfree(b); + b = Balloc(k); + } + k = n >> kshift; + if (n &= kmask) + k++; + b->wds = k; + x = b->x; + xe = x + k; + while(x < xe) + *x++ = ALL_ON; + if (n) + x[-1] >>= ULbits - n; + return b; + } + + static int +rvOK +#ifdef KR_headers + (d, fpi, exp, bits, exact, rd, irv) + double d; FPI *fpi; Long *exp; ULong *bits; int exact, rd, *irv; +#else + (double d, FPI *fpi, Long *exp, ULong *bits, int exact, int rd, int *irv) +#endif +{ + Bigint *b; + ULong carry, inex, lostbits; + int bdif, e, j, k, k1, nb, rv; + + carry = rv = 0; + b = d2b(d, &e, &bdif); + bdif -= nb = fpi->nbits; + e += bdif; + if (bdif <= 0) { + if (exact) + goto trunc; + goto ret; + } + if (P == nb) { + if ( +#ifndef IMPRECISE_INEXACT + exact && +#endif + fpi->rounding == +#ifdef RND_PRODQUOT + FPI_Round_near +#else + Flt_Rounds +#endif + ) goto trunc; + goto ret; + } + switch(rd) { + case 1: + goto trunc; + case 2: + break; + default: /* round near */ + k = bdif - 1; + if (k < 0) + goto trunc; + if (!k) { + if (!exact) + goto ret; + if (b->x[0] & 2) + break; + goto trunc; + } + if (b->x[k>>kshift] & ((ULong)1 << (k & kmask))) + break; + goto trunc; + } + /* "break" cases: round up 1 bit, then truncate; bdif > 0 */ + carry = 1; + trunc: + inex = lostbits = 0; + if (bdif > 0) { + if ( (lostbits = any_on(b, bdif)) !=0) + inex = STRTOG_Inexlo; + rshift(b, bdif); + if (carry) { + inex = STRTOG_Inexhi; + b = increment(b); + if ( (j = nb & kmask) !=0) + j = 32 - j; + if (hi0bits(b->x[b->wds - 1]) != j) { + if (!lostbits) + lostbits = b->x[0] & 1; + rshift(b, 1); + e++; + } + } + } + else if (bdif < 0) + b = lshift(b, -bdif); + if (e < fpi->emin) { + k = fpi->emin - e; + e = fpi->emin; + if (k > nb || fpi->sudden_underflow) { + b->wds = inex = 0; + *irv = STRTOG_Underflow | STRTOG_Inexlo; + } + else { + k1 = k - 1; + if (k1 > 0 && !lostbits) + lostbits = any_on(b, k1); + if (!lostbits && !exact) + goto ret; + lostbits |= + carry = b->x[k1>>kshift] & (1 << (k1 & kmask)); + rshift(b, k); + *irv = STRTOG_Denormal; + if (carry) { + b = increment(b); + inex = STRTOG_Inexhi | STRTOG_Underflow; + } + else if (lostbits) + inex = STRTOG_Inexlo | STRTOG_Underflow; + } + } + else if (e > fpi->emax) { + e = fpi->emax + 1; + *irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; +#ifndef NO_ERRNO + errno = ERANGE; +#endif + b->wds = inex = 0; + } + *exp = e; + copybits(bits, nb, b); + *irv |= inex; + rv = 1; + ret: + Bfree(b); + return rv; + } + + static int +#ifdef KR_headers +mantbits(d) double d; +#else +mantbits(double d) +#endif +{ + ULong L; +#ifdef VAX + L = word1(d) << 16 | word1(d) >> 16; + if (L) +#else + if ( (L = word1(d)) !=0) +#endif + return P - lo0bits(&L); +#ifdef VAX + L = word0(d) << 16 | word0(d) >> 16 | Exp_msk11; +#else + L = word0(d) | Exp_msk1; +#endif + return P - 32 - lo0bits(&L); + } + + int +strtodg +#ifdef KR_headers + (s00, se, fpi, exp, bits) + CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits; +#else + (CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits) +#endif +{ + int abe, abits, asub; + int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2; + int c, denorm, dsign, e, e1, e2, emin, esign, finished, i, inex, irv; + int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign; + int sudden_underflow; + CONST char *s, *s0, *s1; + double adj, adj0, rv, tol; + Long L; + ULong y, z; + Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0; + + irv = STRTOG_Zero; + denorm = sign = nz0 = nz = 0; + dval(rv) = 0.; + rvb = 0; + nbits = fpi->nbits; + for(s = s00;;s++) switch(*s) { + case '-': + sign = 1; + /* no break */ + case '+': + if (*++s) + goto break2; + /* no break */ + case 0: + sign = 0; + irv = STRTOG_NoNumber; + s = s00; + goto ret; + case '\t': + case '\n': + case '\v': + case '\f': + case '\r': + case ' ': + continue; + default: + goto break2; + } + break2: + if (*s == '0') { +#ifndef NO_HEX_FP + switch(s[1]) { + case 'x': + case 'X': + irv = gethex(&s, fpi, exp, &rvb, sign); + if (irv == STRTOG_NoNumber) { + s = s00; + sign = 0; + } + goto ret; + } +#endif + nz0 = 1; + while(*++s == '0') ; + if (!*s) + goto ret; + } + sudden_underflow = fpi->sudden_underflow; + s0 = s; + y = z = 0; + for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) + if (nd < 9) + y = 10*y + c - '0'; + else if (nd < 16) + z = 10*z + c - '0'; + nd0 = nd; +#ifdef USE_LOCALE + if (c == *localeconv()->decimal_point) +#else + if (c == '.') +#endif + { + c = *++s; + if (!nd) { + for(; c == '0'; c = *++s) + nz++; + if (c > '0' && c <= '9') { + s0 = s; + nf += nz; + nz = 0; + goto have_dig; + } + goto dig_done; + } + for(; c >= '0' && c <= '9'; c = *++s) { + have_dig: + nz++; + if (c -= '0') { + nf += nz; + for(i = 1; i < nz; i++) + if (nd++ < 9) + y *= 10; + else if (nd <= DBL_DIG + 1) + z *= 10; + if (nd++ < 9) + y = 10*y + c; + else if (nd <= DBL_DIG + 1) + z = 10*z + c; + nz = 0; + } + } + } + dig_done: + e = 0; + if (c == 'e' || c == 'E') { + if (!nd && !nz && !nz0) { + irv = STRTOG_NoNumber; + s = s00; + goto ret; + } + s00 = s; + esign = 0; + switch(c = *++s) { + case '-': + esign = 1; + case '+': + c = *++s; + } + if (c >= '0' && c <= '9') { + while(c == '0') + c = *++s; + if (c > '0' && c <= '9') { + L = c - '0'; + s1 = s; + while((c = *++s) >= '0' && c <= '9') + L = 10*L + c - '0'; + if (s - s1 > 8 || L > 19999) + /* Avoid confusion from exponents + * so large that e might overflow. + */ + e = 19999; /* safe for 16 bit ints */ + else + e = (int)L; + if (esign) + e = -e; + } + else + e = 0; + } + else + s = s00; + } + if (!nd) { + if (!nz && !nz0) { +#ifdef INFNAN_CHECK + /* Check for Nan and Infinity */ + switch(c) { + case 'i': + case 'I': + if (match(&s,"nf")) { + --s; + if (!match(&s,"inity")) + ++s; + irv = STRTOG_Infinite; + goto infnanexp; + } + break; + case 'n': + case 'N': + if (match(&s, "an")) { + irv = STRTOG_NaN; + *exp = fpi->emax + 1; +#ifndef No_Hex_NaN + if (*s == '(') /*)*/ + irv = hexnan(&s, fpi, bits); +#endif + goto infnanexp; + } + } +#endif /* INFNAN_CHECK */ + irv = STRTOG_NoNumber; + s = s00; + } + goto ret; + } + + irv = STRTOG_Normal; + e1 = e -= nf; + rd = 0; + switch(fpi->rounding & 3) { + case FPI_Round_up: + rd = 2 - sign; + break; + case FPI_Round_zero: + rd = 1; + break; + case FPI_Round_down: + rd = 1 + sign; + } + + /* Now we have nd0 digits, starting at s0, followed by a + * decimal point, followed by nd-nd0 digits. The number we're + * after is the integer represented by those digits times + * 10**e */ + + if (!nd0) + nd0 = nd; + k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; + dval(rv) = y; + if (k > 9) + dval(rv) = tens[k - 9] * dval(rv) + z; + bd0 = 0; + if (nbits <= P && nd <= DBL_DIG) { + if (!e) { + if (rvOK(dval(rv), fpi, exp, bits, 1, rd, &irv)) + goto ret; + } + else if (e > 0) { + if (e <= Ten_pmax) { +#ifdef VAX + goto vax_ovfl_check; +#else + i = fivesbits[e] + mantbits(dval(rv)) <= P; + /* rv = */ rounded_product(dval(rv), tens[e]); + if (rvOK(dval(rv), fpi, exp, bits, i, rd, &irv)) + goto ret; + e1 -= e; + goto rv_notOK; +#endif + } + i = DBL_DIG - nd; + if (e <= Ten_pmax + i) { + /* A fancier test would sometimes let us do + * this for larger i values. + */ + e2 = e - i; + e1 -= i; + dval(rv) *= tens[i]; +#ifdef VAX + /* VAX exponent range is so narrow we must + * worry about overflow here... + */ + vax_ovfl_check: + dval(adj) = dval(rv); + word0(adj) -= P*Exp_msk1; + /* adj = */ rounded_product(dval(adj), tens[e2]); + if ((word0(adj) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) + goto rv_notOK; + word0(adj) += P*Exp_msk1; + dval(rv) = dval(adj); +#else + /* rv = */ rounded_product(dval(rv), tens[e2]); +#endif + if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv)) + goto ret; + e1 -= e2; + } + } +#ifndef Inaccurate_Divide + else if (e >= -Ten_pmax) { + /* rv = */ rounded_quotient(dval(rv), tens[-e]); + if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv)) + goto ret; + e1 -= e; + } +#endif + } + rv_notOK: + e1 += nd - k; + + /* Get starting approximation = rv * 10**e1 */ + + e2 = 0; + if (e1 > 0) { + if ( (i = e1 & 15) !=0) + dval(rv) *= tens[i]; + if (e1 &= ~15) { + e1 >>= 4; + while(e1 >= (1 << n_bigtens-1)) { + e2 += ((word0(rv) & Exp_mask) + >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + dval(rv) *= bigtens[n_bigtens-1]; + e1 -= 1 << n_bigtens-1; + } + e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + for(j = 0; e1 > 0; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= bigtens[j]; + } + } + else if (e1 < 0) { + e1 = -e1; + if ( (i = e1 & 15) !=0) + dval(rv) /= tens[i]; + if (e1 &= ~15) { + e1 >>= 4; + while(e1 >= (1 << n_bigtens-1)) { + e2 += ((word0(rv) & Exp_mask) + >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + dval(rv) *= tinytens[n_bigtens-1]; + e1 -= 1 << n_bigtens-1; + } + e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + for(j = 0; e1 > 0; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= tinytens[j]; + } + } + + rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */ + rve += e2; + if ((j = rvbits - nbits) > 0) { + rshift(rvb, j); + rvbits = nbits; + rve += j; + } + bb0 = 0; /* trailing zero bits in rvb */ + e2 = rve + rvbits - nbits; + if (e2 > fpi->emax) { + rvb->wds = 0; + irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; +#ifndef NO_ERRNO + errno = ERANGE; +#endif + infnanexp: + *exp = fpi->emax + 1; + goto ret; + } + rve1 = rve + rvbits - nbits; + if (e2 < (emin = fpi->emin)) { + denorm = 1; + j = rve - emin; + if (j > 0) { + rvb = lshift(rvb, j); + rvbits += j; + } + else if (j < 0) { + rvbits += j; + if (rvbits <= 0) { + if (rvbits < -1) { + ufl: + rvb->wds = 0; + rvb->x[0] = 0; + *exp = emin; + irv = STRTOG_Underflow | STRTOG_Inexlo; + goto ret; + } + rvb->x[0] = rvb->wds = rvbits = 1; + } + else + rshift(rvb, -j); + } + rve = rve1 = emin; + if (sudden_underflow && e2 + 1 < emin) + goto ufl; + } + + /* Now the hard part -- adjusting rv to the correct value.*/ + + /* Put digits into bd: true value = bd * 10^e */ + + bd0 = s2b(s0, nd0, nd, y); + + for(;;) { + bd = Balloc(bd0->k); + Bcopy(bd, bd0); + bb = Balloc(rvb->k); + Bcopy(bb, rvb); + bbbits = rvbits - bb0; + bbe = rve + bb0; + bs = i2b(1); + + if (e >= 0) { + bb2 = bb5 = 0; + bd2 = bd5 = e; + } + else { + bb2 = bb5 = -e; + bd2 = bd5 = 0; + } + if (bbe >= 0) + bb2 += bbe; + else + bd2 -= bbe; + bs2 = bb2; + j = nbits + 1 - bbbits; + i = bbe + bbbits - nbits; + if (i < emin) /* denormal */ + j += i - emin; + bb2 += j; + bd2 += j; + i = bb2 < bd2 ? bb2 : bd2; + if (i > bs2) + i = bs2; + if (i > 0) { + bb2 -= i; + bd2 -= i; + bs2 -= i; + } + if (bb5 > 0) { + bs = pow5mult(bs, bb5); + bb1 = mult(bs, bb); + Bfree(bb); + bb = bb1; + } + bb2 -= bb0; + if (bb2 > 0) + bb = lshift(bb, bb2); + else if (bb2 < 0) + rshift(bb, -bb2); + if (bd5 > 0) + bd = pow5mult(bd, bd5); + if (bd2 > 0) + bd = lshift(bd, bd2); + if (bs2 > 0) + bs = lshift(bs, bs2); + asub = 1; + inex = STRTOG_Inexhi; + delta = diff(bb, bd); + if (delta->wds <= 1 && !delta->x[0]) + break; + dsign = delta->sign; + delta->sign = finished = 0; + L = 0; + i = cmp(delta, bs); + if (rd && i <= 0) { + irv = STRTOG_Normal; + if ( (finished = dsign ^ (rd&1)) !=0) { + if (dsign != 0) { + irv |= STRTOG_Inexhi; + goto adj1; + } + irv |= STRTOG_Inexlo; + if (rve1 == emin) + goto adj1; + for(i = 0, j = nbits; j >= ULbits; + i++, j -= ULbits) { + if (rvb->x[i] & ALL_ON) + goto adj1; + } + if (j > 1 && lo0bits(rvb->x + i) < j - 1) + goto adj1; + rve = rve1 - 1; + rvb = set_ones(rvb, rvbits = nbits); + break; + } + irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi; + break; + } + if (i < 0) { + /* Error is less than half an ulp -- check for + * special case of mantissa a power of two. + */ + irv = dsign + ? STRTOG_Normal | STRTOG_Inexlo + : STRTOG_Normal | STRTOG_Inexhi; + if (dsign || bbbits > 1 || denorm || rve1 == emin) + break; + delta = lshift(delta,1); + if (cmp(delta, bs) > 0) { + irv = STRTOG_Normal | STRTOG_Inexlo; + goto drop_down; + } + break; + } + if (i == 0) { + /* exactly half-way between */ + if (dsign) { + if (denorm && all_on(rvb, rvbits)) { + /*boundary case -- increment exponent*/ + rvb->wds = 1; + rvb->x[0] = 1; + rve = emin + nbits - (rvbits = 1); + irv = STRTOG_Normal | STRTOG_Inexhi; + denorm = 0; + break; + } + irv = STRTOG_Normal | STRTOG_Inexlo; + } + else if (bbbits == 1) { + irv = STRTOG_Normal; + drop_down: + /* boundary case -- decrement exponent */ + if (rve1 == emin) { + irv = STRTOG_Normal | STRTOG_Inexhi; + if (rvb->wds == 1 && rvb->x[0] == 1) + sudden_underflow = 1; + break; + } + rve -= nbits; + rvb = set_ones(rvb, rvbits = nbits); + break; + } + else + irv = STRTOG_Normal | STRTOG_Inexhi; + if (bbbits < nbits && !denorm || !(rvb->x[0] & 1)) + break; + if (dsign) { + rvb = increment(rvb); + if ( (j = rvbits >> kshift) !=0) + j = 32 - j; + if (hi0bits(rvb->x[(rvb->wds - 1) >> kshift]) + != j) + rvbits++; + irv = STRTOG_Normal | STRTOG_Inexhi; + } + else { + if (bbbits == 1) + goto undfl; + decrement(rvb); + irv = STRTOG_Normal | STRTOG_Inexlo; + } + break; + } + if ((dval(adj) = ratio(delta, bs)) <= 2.) { + adj1: + inex = STRTOG_Inexlo; + if (dsign) { + asub = 0; + inex = STRTOG_Inexhi; + } + else if (denorm && bbbits <= 1) { + undfl: + rvb->wds = 0; + rve = emin; + irv = STRTOG_Underflow | STRTOG_Inexlo; + break; + } + adj0 = dval(adj) = 1.; + } + else { + adj0 = dval(adj) *= 0.5; + if (dsign) { + asub = 0; + inex = STRTOG_Inexlo; + } + if (dval(adj) < 2147483647.) { + L = adj0; + adj0 -= L; + switch(rd) { + case 0: + if (adj0 >= .5) + goto inc_L; + break; + case 1: + if (asub && adj0 > 0.) + goto inc_L; + break; + case 2: + if (!asub && adj0 > 0.) { + inc_L: + L++; + inex = STRTOG_Inexact - inex; + } + } + dval(adj) = L; + } + } + y = rve + rvbits; + + /* adj *= ulp(dval(rv)); */ + /* if (asub) rv -= adj; else rv += adj; */ + + if (!denorm && rvbits < nbits) { + rvb = lshift(rvb, j = nbits - rvbits); + rve -= j; + rvbits = nbits; + } + ab = d2b(dval(adj), &abe, &abits); + if (abe < 0) + rshift(ab, -abe); + else if (abe > 0) + ab = lshift(ab, abe); + rvb0 = rvb; + if (asub) { + /* rv -= adj; */ + j = hi0bits(rvb->x[rvb->wds-1]); + rvb = diff(rvb, ab); + k = rvb0->wds - 1; + if (denorm) + /* do nothing */; + else if (rvb->wds <= k + || hi0bits( rvb->x[k]) > + hi0bits(rvb0->x[k])) { + /* unlikely; can only have lost 1 high bit */ + if (rve1 == emin) { + --rvbits; + denorm = 1; + } + else { + rvb = lshift(rvb, 1); + --rve; + --rve1; + L = finished = 0; + } + } + } + else { + rvb = sum(rvb, ab); + k = rvb->wds - 1; + if (k >= rvb0->wds + || hi0bits(rvb->x[k]) < hi0bits(rvb0->x[k])) { + if (denorm) { + if (++rvbits == nbits) + denorm = 0; + } + else { + rshift(rvb, 1); + rve++; + rve1++; + L = 0; + } + } + } + Bfree(ab); + Bfree(rvb0); + if (finished) + break; + + z = rve + rvbits; + if (y == z && L) { + /* Can we stop now? */ + tol = dval(adj) * 5e-16; /* > max rel error */ + dval(adj) = adj0 - .5; + if (dval(adj) < -tol) { + if (adj0 > tol) { + irv |= inex; + break; + } + } + else if (dval(adj) > tol && adj0 < 1. - tol) { + irv |= inex; + break; + } + } + bb0 = denorm ? 0 : trailz(rvb); + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(delta); + } + if (!denorm && rvbits < nbits) { + j = nbits - rvbits; + rvb = lshift(rvb, j); + rve -= j; + } + *exp = rve; + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(bd0); + Bfree(delta); + ret: + if (denorm) { + if (sudden_underflow) { + rvb->wds = 0; + irv = STRTOG_Underflow | STRTOG_Inexlo; + } + else { + irv = (irv & ~STRTOG_Retmask) | + (rvb->wds > 0 ? STRTOG_Denormal : STRTOG_Zero); + if (irv & STRTOG_Inexact) + irv |= STRTOG_Underflow; + } + } + if (se) + *se = (char *)s; + if (sign) + irv |= STRTOG_Neg; + if (rvb) { + copybits(bits, nbits, rvb); + Bfree(rvb); + } + return irv; + } diff --git a/src/lib/libc/gdtoa/strtof.c b/src/lib/libc/gdtoa/strtof.c new file mode 100644 index 0000000..bb283ae --- /dev/null +++ b/src/lib/libc/gdtoa/strtof.c @@ -0,0 +1,83 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + float +#ifdef KR_headers +strtof(s, sp) CONST char *s; char **sp; +#else +strtof(CONST char *s, char **sp) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 1 }; +#else + static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 0 }; +#endif + ULong bits[1]; + Long exp; + int k; + union { ULong L[1]; float f; } u; + + k = strtodg(s, sp, &fpi, &exp, bits); + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + u.L[0] = 0; + break; + + case STRTOG_Normal: + case STRTOG_NaNbits: + u.L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; + break; + + case STRTOG_Denormal: + u.L[0] = bits[0]; + break; + + case STRTOG_Infinite: + u.L[0] = 0x7f800000; + break; + + case STRTOG_NaN: + u.L[0] = 0x7fffffff; + } + if (k & STRTOG_Neg) + u.L[0] |= 0x80000000L; + return u.f; + } diff --git a/src/lib/libc/gdtoa/strtopQ.c b/src/lib/libc/gdtoa/strtopQ.c new file mode 100644 index 0000000..4bcc581 --- /dev/null +++ b/src/lib/libc/gdtoa/strtopQ.c @@ -0,0 +1,109 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#endif +#ifdef IEEE_8087 +#define _0 3 +#define _1 2 +#define _2 1 +#define _3 0 +#endif + + int +#ifdef KR_headers +strtopQ(s, sp, V) CONST char *s; char **sp; void *V; +#else +strtopQ(CONST char *s, char **sp, void *V) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 1 }; +#else + static FPI fpi = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 0 }; +#endif + ULong bits[4]; + Long exp; + int k; + ULong *L = (ULong*)V; + + k = strtodg(s, sp, &fpi, &exp, bits); + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = L[3] = 0; + break; + + case STRTOG_Normal: + case STRTOG_NaNbits: + L[_3] = bits[0]; + L[_2] = bits[1]; + L[_1] = bits[2]; + L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16); + break; + + case STRTOG_Denormal: + L[_3] = bits[0]; + L[_2] = bits[1]; + L[_1] = bits[2]; + L[_0] = bits[3]; + break; + + case STRTOG_Infinite: + L[_0] = 0x7fff0000; + L[_1] = L[_2] = L[_3] = 0; + break; + + case STRTOG_NaN: + L[_0] = 0x7fffffff; + L[_1] = L[_2] = L[_3] = (ULong)-1; + } + if (k & STRTOG_Neg) + L[_0] |= 0x80000000L; + return k; + } diff --git a/src/lib/libc/gdtoa/strtopd.c b/src/lib/libc/gdtoa/strtopd.c new file mode 100644 index 0000000..54e0838 --- /dev/null +++ b/src/lib/libc/gdtoa/strtopd.c @@ -0,0 +1,55 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtopd(s, sp, d) char *s; char **sp; double *d; +#else +strtopd(CONST char *s, char **sp, double *d) +#endif +{ + static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; + ULong bits[2]; + Long exp; + int k; + + k = strtodg(s, sp, &fpi0, &exp, bits); + ULtod((ULong*)d, bits, exp, k); + return k; + } diff --git a/src/lib/libc/gdtoa/strtopdd.c b/src/lib/libc/gdtoa/strtopdd.c new file mode 100644 index 0000000..f71bced --- /dev/null +++ b/src/lib/libc/gdtoa/strtopdd.c @@ -0,0 +1,184 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtopdd(s, sp, dd) CONST char *s; char **sp; double *dd; +#else +strtopdd(CONST char *s, char **sp, double *dd) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 106, 1-1023, 2046-1023-106+1, 1, 1 }; +#else + static FPI fpi = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 }; +#endif + ULong bits[4]; + Long exp; + int i, j, rv; + typedef union { + double d[2]; + ULong L[4]; + } U; + U *u; + + rv = strtodg(s, sp, &fpi, &exp, bits); + u = (U*)dd; + switch(rv & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + u->d[0] = u->d[1] = 0.; + break; + + case STRTOG_Normal: + u->L[_1] = (bits[1] >> 21 | bits[2] << 11) & 0xffffffffL; + u->L[_0] = bits[2] >> 21 | bits[3] << 11 & 0xfffff + | exp + 0x3ff + 105 << 20; + exp += 0x3ff + 52; + if (bits[1] &= 0x1fffff) { + i = hi0bits(bits[1]) - 11; + if (i >= exp) { + i = exp - 1; + exp = 0; + } + else + exp -= i; + if (i > 0) { + bits[1] = bits[1] << i | bits[0] >> 32-i; + bits[0] = bits[0] << i & 0xffffffffL; + } + } + else if (bits[0]) { + i = hi0bits(bits[0]) + 21; + if (i >= exp) { + i = exp - 1; + exp = 0; + } + else + exp -= i; + if (i < 32) { + bits[1] = bits[0] >> 32 - i; + bits[0] = bits[0] << i & 0xffffffffL; + } + else { + bits[1] = bits[0] << i - 32; + bits[0] = 0; + } + } + else { + u->L[2] = u->L[3] = 0; + break; + } + u->L[2+_1] = bits[0]; + u->L[2+_0] = bits[1] & 0xfffff | exp << 20; + break; + + case STRTOG_Denormal: + if (bits[3]) + goto nearly_normal; + if (bits[2]) + goto partly_normal; + if (bits[1] & 0xffe00000) + goto hardly_normal; + /* completely denormal */ + u->L[2] = u->L[3] = 0; + u->L[_1] = bits[0]; + u->L[_0] = bits[1]; + break; + + nearly_normal: + i = hi0bits(bits[3]) - 11; /* i >= 12 */ + j = 32 - i; + u->L[_0] = (bits[3] << i | bits[2] >> j) & 0xfffff + | 65 - i << 20; + u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; + u->L[2+_0] = bits[1] & (1L << j) - 1; + u->L[2+_1] = bits[0]; + break; + + partly_normal: + i = hi0bits(bits[2]) - 11; + if (i < 0) { + j = -i; + i += 32; + u->L[_0] = bits[2] >> j & 0xfffff | (33 + j) << 20; + u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; + u->L[2+_0] = bits[1] & (1L << j) - 1; + u->L[2+_1] = bits[0]; + break; + } + if (i == 0) { + u->L[_0] = bits[2] & 0xfffff | 33 << 20; + u->L[_1] = bits[1]; + u->L[2+_0] = 0; + u->L[2+_1] = bits[0]; + break; + } + j = 32 - i; + u->L[_0] = (bits[2] << i | bits[1] >> j) & 0xfffff + | j + 1 << 20; + u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; + u->L[2+_0] = 0; + u->L[2+_1] = bits[0] & (1L << j) - 1; + break; + + hardly_normal: + j = 11 - hi0bits(bits[1]); + i = 32 - j; + u->L[_0] = bits[1] >> j & 0xfffff | j + 1 << 20; + u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; + u->L[2+_0] = 0; + u->L[2+_1] = bits[0] & (1L << j) - 1; + break; + + case STRTOG_Infinite: + u->L[_0] = u->L[2+_0] = 0x7ff00000; + u->L[_1] = u->L[2+_1] = 0; + break; + + case STRTOG_NaN: + u->L[_0] = u->L[2+_0] = 0x7fffffff; + u->L[_1] = u->L[2+_1] = (ULong)-1; + } + if (rv & STRTOG_Neg) { + u->L[ _0] |= 0x80000000L; + u->L[2+_0] |= 0x80000000L; + } + return rv; + } diff --git a/src/lib/libc/gdtoa/strtopf.c b/src/lib/libc/gdtoa/strtopf.c new file mode 100644 index 0000000..c49fc96 --- /dev/null +++ b/src/lib/libc/gdtoa/strtopf.c @@ -0,0 +1,83 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + int +#ifdef KR_headers +strtopf(s, sp, f) CONST char *s; char **sp; float *f; +#else +strtopf(CONST char *s, char **sp, float *f) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 1 }; +#else + static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 0 }; +#endif + ULong bits[1], *L; + Long exp; + int k; + + k = strtodg(s, sp, &fpi, &exp, bits); + L = (ULong*)f; + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = 0; + break; + + case STRTOG_Normal: + case STRTOG_NaNbits: + L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; + break; + + case STRTOG_Denormal: + L[0] = bits[0]; + break; + + case STRTOG_Infinite: + L[0] = 0x7f800000; + break; + + case STRTOG_NaN: + L[0] = 0x7fffffff; + } + if (k & STRTOG_Neg) + L[0] |= 0x80000000L; + return k; + } diff --git a/src/lib/libc/gdtoa/strtopx.c b/src/lib/libc/gdtoa/strtopx.c new file mode 100644 index 0000000..190b80f --- /dev/null +++ b/src/lib/libc/gdtoa/strtopx.c @@ -0,0 +1,106 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#define _4 4 +#endif +#ifdef IEEE_8087 +#define _0 4 +#define _1 3 +#define _2 2 +#define _3 1 +#define _4 0 +#endif + + int +#ifdef KR_headers +strtopx(s, sp, V) CONST char *s; char **sp; void *V; +#else +strtopx(CONST char *s, char **sp, void *V) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 1 }; +#else + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; +#endif + ULong bits[2]; + Long exp; + int k; + UShort *L = (UShort*)V; + + k = strtodg(s, sp, &fpi, &exp, bits); + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = L[3] = L[4] = 0; + break; + + case STRTOG_Normal: + case STRTOG_Denormal: + case STRTOG_NaNbits: + L[_4] = (UShort)bits[0]; + L[_3] = (UShort)(bits[0] >> 16); + L[_2] = (UShort)bits[1]; + L[_1] = (UShort)(bits[1] >> 16); + L[_0] = exp + 0x3fff + 63; + break; + + case STRTOG_Infinite: + L[_0] = 0x7fff; + L[_1] = L[_2] = L[_3] = L[_4] = 0; + break; + + case STRTOG_NaN: + L[_0] = 0x7fff; + L[_1] = L[_2] = L[_3] = L[_4] = (UShort)-1; + } + if (k & STRTOG_Neg) + L[_0] |= 0x8000; + return k; + } diff --git a/src/lib/libc/gdtoa/strtopxL.c b/src/lib/libc/gdtoa/strtopxL.c new file mode 100644 index 0000000..95fd3d5 --- /dev/null +++ b/src/lib/libc/gdtoa/strtopxL.c @@ -0,0 +1,100 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#endif +#ifdef IEEE_8087 +#define _0 2 +#define _1 1 +#define _2 0 +#endif + + int +#ifdef KR_headers +strtopxL(s, sp, V) CONST char *s; char **sp; void *V; +#else +strtopxL(CONST char *s, char **sp, void *V) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 1 }; +#else + static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; +#endif + ULong bits[2]; + Long exp; + int k; + ULong *L = (ULong*)V; + + k = strtodg(s, sp, &fpi, &exp, bits); + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = 0; + break; + + case STRTOG_Normal: + case STRTOG_Denormal: + case STRTOG_NaNbits: + L[_2] = bits[0]; + L[_1] = bits[1]; + L[_0] = (exp + 0x3fff + 63) << 16; + break; + + case STRTOG_Infinite: + L[_0] = 0x7fff << 16; + L[_1] = L[_2] = 0; + break; + + case STRTOG_NaN: + L[_0] = 0x7fff << 16; + L[_1] = L[_2] = (ULong)-1; + } + if (k & STRTOG_Neg) + L[_0] |= 0x80000000L; + return k; + } diff --git a/src/lib/libc/gdtoa/strtorQ.c b/src/lib/libc/gdtoa/strtorQ.c new file mode 100644 index 0000000..63a7b6a --- /dev/null +++ b/src/lib/libc/gdtoa/strtorQ.c @@ -0,0 +1,121 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#endif +#ifdef IEEE_8087 +#define _0 3 +#define _1 2 +#define _2 1 +#define _3 0 +#endif + + void +#ifdef KR_headers +ULtoQ(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +#else +ULtoQ(ULong *L, ULong *bits, Long exp, int k) +#endif +{ + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = L[3] = 0; + break; + + case STRTOG_Normal: + case STRTOG_NaNbits: + L[_3] = bits[0]; + L[_2] = bits[1]; + L[_1] = bits[2]; + L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16); + break; + + case STRTOG_Denormal: + L[_3] = bits[0]; + L[_2] = bits[1]; + L[_1] = bits[2]; + L[_0] = bits[3]; + break; + + case STRTOG_Infinite: + L[_0] = 0x7fff0000; + L[_1] = L[_2] = L[_3] = 0; + break; + + case STRTOG_NaN: + L[_0] = 0x7fffffff; + L[_1] = L[_2] = L[_3] = (ULong)-1; + } + if (k & STRTOG_Neg) + L[_0] |= 0x80000000L; + } + + int +#ifdef KR_headers +strtorQ(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L; +#else +strtorQ(CONST char *s, char **sp, int rounding, void *L) +#endif +{ + static FPI fpi0 = { 113, 1-16383-113+1, 32766-16383-113+1, 1, SI }; + FPI *fpi, fpi1; + ULong bits[4]; + Long exp; + int k; + + fpi = &fpi0; + if (rounding != FPI_Round_near) { + fpi1 = fpi0; + fpi1.rounding = rounding; + fpi = &fpi1; + } + k = strtodg(s, sp, fpi, &exp, bits); + ULtoQ((ULong*)L, bits, exp, k); + return k; + } diff --git a/src/lib/libc/gdtoa/strtord.c b/src/lib/libc/gdtoa/strtord.c new file mode 100644 index 0000000..12213f9 --- /dev/null +++ b/src/lib/libc/gdtoa/strtord.c @@ -0,0 +1,99 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + void +#ifdef KR_headers +ULtod(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +#else +ULtod(ULong *L, ULong *bits, Long exp, int k) +#endif +{ + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = 0; + break; + + case STRTOG_Denormal: + L[_1] = bits[0]; + L[_0] = bits[1]; + break; + + case STRTOG_Normal: + case STRTOG_NaNbits: + L[_1] = bits[0]; + L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20); + break; + + case STRTOG_Infinite: + L[_0] = 0x7ff00000; + L[_1] = 0; + break; + + case STRTOG_NaN: + L[_0] = 0x7fffffff; + L[_1] = (ULong)-1; + } + if (k & STRTOG_Neg) + L[_0] |= 0x80000000L; + } + + int +#ifdef KR_headers +strtord(s, sp, rounding, d) CONST char *s; char **sp; int rounding; double *d; +#else +strtord(CONST char *s, char **sp, int rounding, double *d) +#endif +{ + static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; + FPI *fpi, fpi1; + ULong bits[2]; + Long exp; + int k; + + fpi = &fpi0; + if (rounding != FPI_Round_near) { + fpi1 = fpi0; + fpi1.rounding = rounding; + fpi = &fpi1; + } + k = strtodg(s, sp, fpi, &exp, bits); + ULtod((ULong*)d, bits, exp, k); + return k; + } diff --git a/src/lib/libc/gdtoa/strtordd.c b/src/lib/libc/gdtoa/strtordd.c new file mode 100644 index 0000000..626a4d3 --- /dev/null +++ b/src/lib/libc/gdtoa/strtordd.c @@ -0,0 +1,205 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + void +#ifdef KR_headers +ULtodd(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +#else +ULtodd(ULong *L, ULong *bits, Long exp, int k) +#endif +{ + int i, j; + + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = L[3] = 0; + break; + + case STRTOG_Normal: + L[_1] = (bits[1] >> 21 | bits[2] << 11) & (ULong)0xffffffffL; + L[_0] = bits[2] >> 21 | bits[3] << 11 & 0xfffff + | exp + 0x3ff + 105 << 20; + exp += 0x3ff + 52; + if (bits[1] &= 0x1fffff) { + i = hi0bits(bits[1]) - 11; + if (i >= exp) { + i = exp - 1; + exp = 0; + } + else + exp -= i; + if (i > 0) { + bits[1] = bits[1] << i | bits[0] >> 32-i; + bits[0] = bits[0] << i & (ULong)0xffffffffL; + } + } + else if (bits[0]) { + i = hi0bits(bits[0]) + 21; + if (i >= exp) { + i = exp - 1; + exp = 0; + } + else + exp -= i; + if (i < 32) { + bits[1] = bits[0] >> 32 - i; + bits[0] = bits[0] << i & (ULong)0xffffffffL; + } + else { + bits[1] = bits[0] << i - 32; + bits[0] = 0; + } + } + else { + L[2] = L[3] = 0; + break; + } + L[2+_1] = bits[0]; + L[2+_0] = bits[1] & 0xfffff | exp << 20; + break; + + case STRTOG_Denormal: + if (bits[3]) + goto nearly_normal; + if (bits[2]) + goto partly_normal; + if (bits[1] & 0xffe00000) + goto hardly_normal; + /* completely denormal */ + L[2] = L[3] = 0; + L[_1] = bits[0]; + L[_0] = bits[1]; + break; + + nearly_normal: + i = hi0bits(bits[3]) - 11; /* i >= 12 */ + j = 32 - i; + L[_0] = (bits[3] << i | bits[2] >> j) & 0xfffff + | 65 - i << 20; + L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; + L[2+_0] = bits[1] & ((ULong)1L << j) - 1; + L[2+_1] = bits[0]; + break; + + partly_normal: + i = hi0bits(bits[2]) - 11; + if (i < 0) { + j = -i; + i += 32; + L[_0] = bits[2] >> j & 0xfffff | (33 + j) << 20; + L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; + L[2+_0] = bits[1] & ((ULong)1L << j) - 1; + L[2+_1] = bits[0]; + break; + } + if (i == 0) { + L[_0] = bits[2] & 0xfffff | 33 << 20; + L[_1] = bits[1]; + L[2+_0] = 0; + L[2+_1] = bits[0]; + break; + } + j = 32 - i; + L[_0] = (bits[2] << i | bits[1] >> j) & 0xfffff + | j + 1 << 20; + L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; + L[2+_0] = 0; + L[2+_1] = bits[0] & (1L << j) - 1; + break; + + hardly_normal: + j = 11 - hi0bits(bits[1]); + i = 32 - j; + L[_0] = bits[1] >> j & 0xfffff | j + 1 << 20; + L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; + L[2+_0] = 0; + L[2+_1] = bits[0] & ((ULong)1L << j) - 1; + break; + + case STRTOG_Infinite: + L[_0] = L[2+_0] = 0x7ff00000; + L[_1] = L[2+_1] = 0; + break; + + case STRTOG_NaN: + L[_0] = L[2+_0] = 0x7fffffff; + L[_1] = L[2+_1] = (ULong)-1; + break; + + case STRTOG_NaNbits: + L[_1] = (bits[1] >> 21 | bits[2] << 11) & (ULong)0xffffffffL; + L[_0] = bits[2] >> 21 | bits[3] << 11 + | (ULong)0x7ff00000L; + L[2+_1] = bits[0]; + L[2+_0] = bits[1] | (ULong)0x7ff00000L; + } + if (k & STRTOG_Neg) { + L[_0] |= 0x80000000L; + L[2+_0] |= 0x80000000L; + } + } + + int +#ifdef KR_headers +strtordd(s, sp, rounding, dd) CONST char *s; char **sp; int rounding; double *dd; +#else +strtordd(CONST char *s, char **sp, int rounding, double *dd) +#endif +{ +#ifdef Sudden_Underflow + static FPI fpi0 = { 106, 1-1023, 2046-1023-106+1, 1, 1 }; +#else + static FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 }; +#endif + FPI *fpi, fpi1; + ULong bits[4]; + Long exp; + int k; + + fpi = &fpi0; + if (rounding != FPI_Round_near) { + fpi1 = fpi0; + fpi1.rounding = rounding; + fpi = &fpi1; + } + k = strtodg(s, sp, fpi, &exp, bits); + ULtodd((ULong*)dd, bits, exp, k); + return k; + } diff --git a/src/lib/libc/gdtoa/strtorf.c b/src/lib/libc/gdtoa/strtorf.c new file mode 100644 index 0000000..ecd1c0b --- /dev/null +++ b/src/lib/libc/gdtoa/strtorf.c @@ -0,0 +1,95 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + void +#ifdef KR_headers +ULtof(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +#else +ULtof(ULong *L, ULong *bits, Long exp, int k) +#endif +{ + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + *L = 0; + break; + + case STRTOG_Normal: + case STRTOG_NaNbits: + L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; + break; + + case STRTOG_Denormal: + L[0] = bits[0]; + break; + + case STRTOG_Infinite: + L[0] = 0x7f800000; + break; + + case STRTOG_NaN: + L[0] = 0x7fffffff; + } + if (k & STRTOG_Neg) + L[0] |= 0x80000000L; + } + + int +#ifdef KR_headers +strtorf(s, sp, rounding, f) CONST char *s; char **sp; int rounding; float *f; +#else +strtorf(CONST char *s, char **sp, int rounding, float *f) +#endif +{ + static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; + FPI *fpi, fpi1; + ULong bits[1]; + Long exp; + int k; + + fpi = &fpi0; + if (rounding != FPI_Round_near) { + fpi1 = fpi0; + fpi1.rounding = rounding; + fpi = &fpi1; + } + k = strtodg(s, sp, fpi, &exp, bits); + ULtof((ULong*)f, bits, exp, k); + return k; + } diff --git a/src/lib/libc/gdtoa/strtorx.c b/src/lib/libc/gdtoa/strtorx.c new file mode 100644 index 0000000..0a81e95 --- /dev/null +++ b/src/lib/libc/gdtoa/strtorx.c @@ -0,0 +1,118 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#define _4 4 +#endif +#ifdef IEEE_8087 +#define _0 4 +#define _1 3 +#define _2 2 +#define _3 1 +#define _4 0 +#endif + + void +#ifdef KR_headers +ULtox(L, bits, exp, k) UShort *L; ULong *bits; Long exp; int k; +#else +ULtox(UShort *L, ULong *bits, Long exp, int k) +#endif +{ + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = L[3] = L[4] = 0; + break; + + case STRTOG_Normal: + case STRTOG_Denormal: + case STRTOG_NaNbits: + L[_4] = (UShort)bits[0]; + L[_3] = (UShort)(bits[0] >> 16); + L[_2] = (UShort)bits[1]; + L[_1] = (UShort)(bits[1] >> 16); + L[_0] = exp + 0x3fff + 63; + break; + + case STRTOG_Infinite: + L[_0] = 0x7fff; + L[_1] = L[_2] = L[_3] = L[_4] = 0; + break; + + case STRTOG_NaN: + L[_0] = 0x7fff; + L[_1] = L[_2] = L[_3] = L[_4] = (UShort)-1; + } + if (k & STRTOG_Neg) + L[_0] |= 0x8000; + } + + int +#ifdef KR_headers +strtorx(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L; +#else +strtorx(CONST char *s, char **sp, int rounding, void *L) +#endif +{ + static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + FPI *fpi, fpi1; + ULong bits[2]; + Long exp; + int k; + + fpi = &fpi0; + if (rounding != FPI_Round_near) { + fpi1 = fpi0; + fpi1.rounding = rounding; + fpi = &fpi1; + } + k = strtodg(s, sp, fpi, &exp, bits); + ULtox((UShort*)L, bits, exp, k); + return k; + } diff --git a/src/lib/libc/gdtoa/strtorxL.c b/src/lib/libc/gdtoa/strtorxL.c new file mode 100644 index 0000000..126cef8 --- /dev/null +++ b/src/lib/libc/gdtoa/strtorxL.c @@ -0,0 +1,112 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#endif +#ifdef IEEE_8087 +#define _0 2 +#define _1 1 +#define _2 0 +#endif + + void +#ifdef KR_headers +ULtoxL(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +#else +ULtoxL(ULong *L, ULong *bits, Long exp, int k) +#endif +{ + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = 0; + break; + + case STRTOG_Normal: + case STRTOG_Denormal: + case STRTOG_NaNbits: + L[_0] = (exp + 0x3fff + 63) << 16; + L[_1] = bits[1]; + L[_2] = bits[0]; + break; + + case STRTOG_Infinite: + L[_0] = 0x7fff << 16; + L[_1] = L[_2] = 0; + break; + + case STRTOG_NaN: + L[_0] = 0x7fff << 16; + L[_1] = L[_2] = (ULong)-1; + } + if (k & STRTOG_Neg) + L[_0] |= 0x80000000L; + } + + int +#ifdef KR_headers +strtorxL(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L; +#else +strtorxL(CONST char *s, char **sp, int rounding, void *L) +#endif +{ + static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + FPI *fpi, fpi1; + ULong bits[2]; + Long exp; + int k; + + fpi = &fpi0; + if (rounding != FPI_Round_near) { + fpi1 = fpi0; + fpi1.rounding = rounding; + fpi = &fpi1; + } + k = strtodg(s, sp, fpi, &exp, bits); + ULtoxL((ULong*)L, bits, exp, k); + return k; + } diff --git a/src/lib/libc/gdtoa/sum.c b/src/lib/libc/gdtoa/sum.c new file mode 100644 index 0000000..1e1a4de --- /dev/null +++ b/src/lib/libc/gdtoa/sum.c @@ -0,0 +1,104 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + Bigint * +#ifdef KR_headers +sum(a, b) Bigint *a; Bigint *b; +#else +sum(Bigint *a, Bigint *b) +#endif +{ + Bigint *c; + ULong carry, *xc, *xa, *xb, *xe, y; +#ifdef Pack_32 + ULong z; +#endif + + if (a->wds < b->wds) { + c = b; b = a; a = c; + } + c = Balloc(a->k); + c->wds = a->wds; + carry = 0; + xa = a->x; + xb = b->x; + xc = c->x; + xe = xc + b->wds; +#ifdef Pack_32 + do { + y = (*xa & 0xffff) + (*xb & 0xffff) + carry; + carry = (y & 0x10000) >> 16; + z = (*xa++ >> 16) + (*xb++ >> 16) + carry; + carry = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } + while(xc < xe); + xe += a->wds - b->wds; + while(xc < xe) { + y = (*xa & 0xffff) + carry; + carry = (y & 0x10000) >> 16; + z = (*xa++ >> 16) + carry; + carry = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } +#else + do { + y = *xa++ + *xb++ + carry; + carry = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } + while(xc < xe); + xe += a->wds - b->wds; + while(xc < xe) { + y = *xa++ + carry; + carry = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } +#endif + if (carry) { + if (c->wds == c->maxwds) { + b = Balloc(c->k + 1); + Bcopy(b, c); + Bfree(c); + c = b; + } + c->x[c->wds++] = 1; + } + return c; + } diff --git a/src/lib/libc/gdtoa/ulp.c b/src/lib/libc/gdtoa/ulp.c new file mode 100644 index 0000000..536994a --- /dev/null +++ b/src/lib/libc/gdtoa/ulp.c @@ -0,0 +1,76 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 1999 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#include "gdtoaimp.h" + + double +ulp +#ifdef KR_headers + (x) double x; +#else + (double x) +#endif +{ + Long L; + double a; + + L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; +#ifndef Sudden_Underflow + if (L > 0) { +#endif +#ifdef IBM + L |= Exp_msk1 >> 4; +#endif + word0(a) = L; + word1(a) = 0; +#ifndef Sudden_Underflow + } + else { + L = -L >> Exp_shift; + if (L < Exp_shift) { + word0(a) = 0x80000 >> L; + word1(a) = 0; + } + else { + word0(a) = 0; + L -= Exp_shift; + word1(a) = L >= 31 ? 1 : 1 << 31 - L; + } + } +#endif + return a; + } diff --git a/src/lib/libc/gen/Makefile b/src/lib/libc/gen/Makefile new file mode 100644 index 0000000..ea7412b --- /dev/null +++ b/src/lib/libc/gen/Makefile @@ -0,0 +1,34 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = __xuname.o _pthread_stubs.o _rand48.o _spinlock_stub.o _thread_init.o alarm.o arc4random.o assert.o basename.o check_utility_compat.o clock.o closedir.o confstr.o crypt.o ctermid.o daemon.o devname.o dirname.o disklabel.o dlfcn.o dlfunc.o drand48.o erand48.o err.o errlst.o errno.o exec.o fmtcheck.o fmtmsg.o fnmatch.o fpclassify.o fstab.o ftok.o fts.o getbootfile.o getbsize.o getcap.o getcwd.o getdomainname.o getgrent.o getgrouplist.o gethostname.o getloadavg.o getlogin.o getmntinfo.o getnetgrent.o getobjformat.o getosreldate.o getpagesize.o getpeereid.o getprogname.o getpwent.o getttyent.o getusershell.o getvfsbyname.o glob.o initgroups.o isatty.o jrand48.o lcong48.o lockf.o lrand48.o mrand48.o nice.o nlist.o nrand48.o ntp_gettime.o opendir.o pause.o pmadvise.o popen.o posixshm.o pselect.o psignal.o pw_scan.o pwcache.o raise.o readdir.o readpassphrase.o rewinddir.o scandir.o seed48.o seekdir.o sem.o semctl.o setdomainname.o sethostname.o setjmperr.o setmode.o setproctitle.o setprogname.o siginterrupt.o siglist.o signal.o signbit.o sigsetops.o sleep.o srand48.o statvfs.o stringlist.o strtofflags.o swapcontext.o sysconf.o sysctl.o sysctlbyname.o sysctlnametomib.o syslog.o telldir.o termios.o time.o times.o timezone.o ttyname.o ttyslot.o ualarm.o ulimit.o uname.o unvis.o usleep.o utime.o valloc.o vis.o wait.o wait3.o waitpid.o wordexp.o + +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../../../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../../../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I. -I../../../include -I../locale -I../i386 -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../../../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdlib -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/gen/__xuname.c b/src/lib/libc/gen/__xuname.c new file mode 100644 index 0000000..359f8ea --- /dev/null +++ b/src/lib/libc/gen/__xuname.c @@ -0,0 +1,132 @@ +/*- + * Copyright (c) 1994 + * 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[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94";*/ +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/__xuname.c,v 1.9 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include +#include +#include + +int +__xuname(int namesize, void *namebuf) +{ + int mib[2], rval; + size_t len; + char *p; + int oerrno; + struct xutsname { + char sysname[namesize]; /* Name of this OS. */ + char nodename[namesize]; /* Name of this network node. */ + char release[namesize]; /* Release level. */ + char version[namesize]; /* Version level. */ + char machine[namesize]; /* Hardware type. */ + } *name; + + name = (struct xutsname *)namebuf; + rval = 0; + + mib[0] = CTL_KERN; + mib[1] = KERN_OSTYPE; + len = sizeof(name->sysname); + oerrno = errno; + if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) { + if(errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } + name->sysname[sizeof(name->sysname) - 1] = '\0'; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTNAME; + len = sizeof(name->nodename); + oerrno = errno; + if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) { + if(errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } + name->nodename[sizeof(name->nodename) - 1] = '\0'; + + mib[0] = CTL_KERN; + mib[1] = KERN_OSRELEASE; + len = sizeof(name->release); + oerrno = errno; + if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) { + if(errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } + name->release[sizeof(name->release) - 1] = '\0'; + + /* The version may have newlines in it, turn them into spaces. */ + mib[0] = CTL_KERN; + mib[1] = KERN_VERSION; + len = sizeof(name->version); + oerrno = errno; + if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) { + if (errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } + name->version[sizeof(name->version) - 1] = '\0'; + for (p = name->version; len--; ++p) { + if (*p == '\n' || *p == '\t') { + if (len > 1) + *p = ' '; + else + *p = '\0'; + } + } + + mib[0] = CTL_HW; + mib[1] = HW_MACHINE; + len = sizeof(name->machine); + oerrno = errno; + if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) { + if (errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } + name->machine[sizeof(name->machine) - 1] = '\0'; + return (rval); +} diff --git a/src/lib/libc/gen/_pthread_stubs.c b/src/lib/libc/gen/_pthread_stubs.c new file mode 100644 index 0000000..eac6575 --- /dev/null +++ b/src/lib/libc/gen/_pthread_stubs.c @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * 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. + * + * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/_pthread_stubs.c,v 1.10 2002/11/13 21:55:22 deischen Exp $"); + +#include +#include + +#include "libc_private.h" + +/* + * Weak symbols: All libc internal usage of these functions should + * use the weak symbol versions (_pthread_XXX). If libpthread is + * linked, it will override these functions with (non-weak) routines. + * The _pthread_XXX functions are provided solely for internal libc + * usage to avoid unwanted cancellation points and to differentiate + * between application locks and libc locks (threads holding the + * latter can't be allowed to exit/terminate). + */ + +/* Define a null pthread structure just to satisfy _pthread_self. */ +struct pthread { +}; + +static struct pthread main_thread; + +static int stub_main(void); +static void *stub_null(void); +static struct pthread *stub_self(void); +static int stub_zero(void); + +#define PJT_DUAL_ENTRY(entry) \ + (pthread_func_t)entry, (pthread_func_t)entry + +pthread_func_entry_t __thr_jtable[PJT_MAX] = { + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_COND_BROADCAST */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_COND_DESTROY */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_COND_INIT */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_COND_SIGNAL */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_COND_WAIT */ + {PJT_DUAL_ENTRY(stub_null)}, /* PJT_GETSPECIFIC */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_KEY_CREATE */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_KEY_DELETE */ + {PJT_DUAL_ENTRY(stub_main)}, /* PJT_MAIN_NP */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEX_DESTROY */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEX_INIT */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEX_LOCK */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEX_TRYLOCK */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEX_UNLOCK */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEXATTR_DESTROY */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEXATTR_INIT */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_MUTEXATTR_SETTYPE */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_ONCE */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_RWLOCK_DESTROY */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_RWLOCK_INIT */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_RWLOCK_RDLOCK */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_RWLOCK_TRYRDLOCK */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_RWLOCK_TRYWRLOCK */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_RWLOCK_UNLOCK */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_RWLOCK_WRLOCK */ + {PJT_DUAL_ENTRY(stub_self)}, /* PJT_SELF */ + {PJT_DUAL_ENTRY(stub_zero)}, /* PJT_SETSPECIFIC */ + {PJT_DUAL_ENTRY(stub_zero)} /* PJT_SIGMASK */ +}; + +/* + * Weak aliases for exported (pthread_*) and internal (_pthread_*) routines. + */ +#define WEAK_REF(sym, alias) __weak_reference(sym, alias) + +#define FUNC_TYPE(name) __CONCAT(name, _func_t) +#define FUNC_INT(name) __CONCAT(name, _int) +#define FUNC_EXP(name) __CONCAT(name, _exp) + +#define STUB_FUNC(name, idx, ret) \ + static ret FUNC_EXP(name)(void) __unused; \ + static ret FUNC_INT(name)(void) __unused; \ + WEAK_REF(FUNC_EXP(name), name); \ + WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ + typedef ret (*FUNC_TYPE(name))(void); \ + static ret FUNC_EXP(name)(void) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ + return (func()); \ + } \ + static ret FUNC_INT(name)(void) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ + return (func()); \ + } + +#define STUB_FUNC1(name, idx, ret, p0_type) \ + static ret FUNC_EXP(name)(p0_type) __unused; \ + static ret FUNC_INT(name)(p0_type) __unused; \ + WEAK_REF(FUNC_EXP(name), name); \ + WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ + typedef ret (*FUNC_TYPE(name))(p0_type); \ + static ret FUNC_EXP(name)(p0_type p0) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ + return (func(p0)); \ + } \ + static ret FUNC_INT(name)(p0_type p0) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ + return (func(p0)); \ + } + +#define STUB_FUNC2(name, idx, ret, p0_type, p1_type) \ + static ret FUNC_EXP(name)(p0_type, p1_type) __unused; \ + static ret FUNC_INT(name)(p0_type, p1_type) __unused; \ + WEAK_REF(FUNC_EXP(name), name); \ + WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ + typedef ret (*FUNC_TYPE(name))(p0_type, p1_type); \ + static ret FUNC_EXP(name)(p0_type p0, p1_type p1) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ + return (func(p0, p1)); \ + } \ + static ret FUNC_INT(name)(p0_type p0, p1_type p1) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ + return (func(p0, p1)); \ + } + +#define STUB_FUNC3(name, idx, ret, p0_type, p1_type, p2_type) \ + static ret FUNC_EXP(name)(p0_type, p1_type, p2_type) __unused; \ + static ret FUNC_INT(name)(p0_type, p1_type, p2_type) __unused; \ + WEAK_REF(FUNC_EXP(name), name); \ + WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ + typedef ret (*FUNC_TYPE(name))(p0_type, p1_type, p2_type); \ + static ret FUNC_EXP(name)(p0_type p0, p1_type p1, p2_type p2) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ + return (func(p0, p1, p2)); \ + } \ + static ret FUNC_INT(name)(p0_type p0, p1_type p1, p2_type p2) \ + { \ + FUNC_TYPE(name) func; \ + func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ + return (func(p0, p1, p2)); \ + } + +STUB_FUNC1(pthread_cond_broadcast, PJT_COND_BROADCAST, int, void *) +STUB_FUNC1(pthread_cond_destroy, PJT_COND_DESTROY, int, void *) +STUB_FUNC2(pthread_cond_init, PJT_COND_INIT, int, void *, void *) +STUB_FUNC1(pthread_cond_signal, PJT_COND_SIGNAL, int, void *) +STUB_FUNC1(pthread_cond_wait, PJT_COND_WAIT, int, void *) +STUB_FUNC1(pthread_getspecific, PJT_GETSPECIFIC, void *, pthread_key_t) +STUB_FUNC2(pthread_key_create, PJT_KEY_CREATE, int, void *, void *) +STUB_FUNC1(pthread_key_delete, PJT_KEY_DELETE, int, pthread_key_t) +STUB_FUNC(pthread_main_np, PJT_MAIN_NP, int) +STUB_FUNC1(pthread_mutex_destroy, PJT_MUTEX_DESTROY, int, void *) +STUB_FUNC2(pthread_mutex_init, PJT_MUTEX_INIT, int, void *, void *) +STUB_FUNC1(pthread_mutex_lock, PJT_MUTEX_LOCK, int, void *) +STUB_FUNC1(pthread_mutex_trylock, PJT_MUTEX_TRYLOCK, int, void *) +STUB_FUNC1(pthread_mutex_unlock, PJT_MUTEX_UNLOCK, int, void *) +STUB_FUNC1(pthread_mutexattr_destroy, PJT_MUTEXATTR_DESTROY, int, void *) +STUB_FUNC1(pthread_mutexattr_init, PJT_MUTEXATTR_INIT, int, void *) +STUB_FUNC1(pthread_mutexattr_settype, PJT_MUTEXATTR_SETTYPE, int, void *) +STUB_FUNC2(pthread_once, PJT_ONCE, int, void *, void *) +STUB_FUNC1(pthread_rwlock_destroy, PJT_RWLOCK_DESTROY, int, void *) +STUB_FUNC2(pthread_rwlock_init, PJT_RWLOCK_INIT, int, void *, void *) +STUB_FUNC1(pthread_rwlock_rdlock, PJT_RWLOCK_RDLOCK, int, void *) +STUB_FUNC1(pthread_rwlock_tryrdlock, PJT_RWLOCK_TRYRDLOCK, int, void *) +STUB_FUNC1(pthread_rwlock_trywrlock, PJT_RWLOCK_TRYWRLOCK, int, void *) +STUB_FUNC1(pthread_rwlock_unlock, PJT_RWLOCK_UNLOCK, int, void *) +STUB_FUNC1(pthread_rwlock_wrlock, PJT_RWLOCK_WRLOCK, int, void *) +STUB_FUNC(pthread_self, PJT_SELF, pthread_t) +STUB_FUNC2(pthread_setspecific, PJT_SETSPECIFIC, int, pthread_key_t, void *) +STUB_FUNC3(pthread_sigmask, PJT_SIGMASK, int, int, void *, void *) + +static int +stub_zero(void) +{ + return (0); +} + +static void * +stub_null(void) +{ + return (NULL); +} + +static struct pthread * +stub_self(void) +{ + return (&main_thread); +} + +static int +stub_main(void) +{ + return (-1); +} diff --git a/src/lib/libc/gen/_rand48.c b/src/lib/libc/gen/_rand48.c new file mode 100644 index 0000000..4dbf0d7 --- /dev/null +++ b/src/lib/libc/gen/_rand48.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/_rand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +unsigned short _rand48_seed[3] = { + RAND48_SEED_0, + RAND48_SEED_1, + RAND48_SEED_2 +}; +unsigned short _rand48_mult[3] = { + RAND48_MULT_0, + RAND48_MULT_1, + RAND48_MULT_2 +}; +unsigned short _rand48_add = RAND48_ADD; + +void +_dorand48(unsigned short xseed[3]) +{ + unsigned long accu; + unsigned short temp[2]; + + accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] + + (unsigned long) _rand48_add; + temp[0] = (unsigned short) accu; /* lower 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] + + (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; + temp[1] = (unsigned short) accu; /* middle 16 bits */ + accu >>= sizeof(unsigned short) * 8; + accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0]; + xseed[0] = temp[0]; + xseed[1] = temp[1]; + xseed[2] = (unsigned short) accu; +} diff --git a/src/lib/libc/gen/_spinlock_stub.c b/src/lib/libc/gen/_spinlock_stub.c new file mode 100644 index 0000000..78512b3 --- /dev/null +++ b/src/lib/libc/gen/_spinlock_stub.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1998 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/_spinlock_stub.c,v 1.8 2003/03/26 04:02:24 jeff Exp $"); + +#include + +#include "spinlock.h" + +/* + * Declare weak definitions in case the application is not linked + * with libpthread. + */ +__weak_reference(_atomic_lock_stub, _atomic_lock); +__weak_reference(_spinlock_stub, _spinlock); +__weak_reference(_spinlock_stub, _spinunlock); +__weak_reference(_spinlock_debug_stub, _spinlock_debug); + + +/* + * This function is a stub for the _atomic_lock function in libpthread. + */ +long +_atomic_lock_stub(volatile long *lck) +{ + return (0L); +} + + +/* + * This function is a stub for the spinlock function in libpthread. + */ +void +_spinlock_stub(spinlock_t *lck) +{ +} + +/* + * This function is a stub for the spinunlock function in libpthread. + */ +void +_spinunlock_stub(spinlock_t *lck) +{ +} + +/* + * This function is a stub for the debug spinlock function in libpthread. + */ +void +_spinlock_debug_stub(spinlock_t *lck, char *fname, int lineno) +{ +} diff --git a/src/lib/libc/gen/_thread_init.c b/src/lib/libc/gen/_thread_init.c new file mode 100644 index 0000000..afcd856 --- /dev/null +++ b/src/lib/libc/gen/_thread_init.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2001 Daniel Eischen + * 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. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/_thread_init.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); + +#include + +__weak_reference(_thread_init_stub, _thread_init); +__weak_reference(_thread_autoinit_dummy_decl_stub, _thread_autoinit_dummy_decl); + +int _thread_autoinit_dummy_decl_stub = 0; + +void +_thread_init_stub(void) +{ + /* This is just a stub; there is nothing to do. */ +} diff --git a/src/lib/libc/gen/alarm.c b/src/lib/libc/gen/alarm.c new file mode 100644 index 0000000..58cce20 --- /dev/null +++ b/src/lib/libc/gen/alarm.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)alarm.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/alarm.c,v 1.2 2002/02/01 01:08:47 obrien Exp $"); + +/* + * Backwards compatible alarm. + */ +#include +#include + +unsigned int +alarm(secs) + unsigned int secs; +{ + struct itimerval it, oitv; + struct itimerval *itp = ⁢ + + timerclear(&itp->it_interval); + itp->it_value.tv_sec = secs; + itp->it_value.tv_usec = 0; + if (setitimer(ITIMER_REAL, itp, &oitv) < 0) + return (-1); + if (oitv.it_value.tv_usec) + oitv.it_value.tv_sec++; + return (oitv.it_value.tv_sec); +} diff --git a/src/lib/libc/gen/arc4random.c b/src/lib/libc/gen/arc4random.c new file mode 100644 index 0000000..7d882b8 --- /dev/null +++ b/src/lib/libc/gen/arc4random.c @@ -0,0 +1,235 @@ +/* + * Arc4 random number generator for OpenBSD. + * Copyright 1996 David Mazieres . + * + * Modification and redistribution in source and binary forms is + * permitted provided that due credit is given to the author and the + * OpenBSD project (for instance by leaving this copyright notice + * intact). + */ + +/* + * This code is derived from section 17.1 of Applied Cryptography, + * second edition, which describes a stream cipher allegedly + * compatible with RSA Labs "RC4" cipher (the actual description of + * which is a trade secret). The same algorithm is used as a stream + * cipher called "arcfour" in Tatu Ylonen's ssh package. + * + * Here the stream cipher has been modified always to include the time + * when initializing the state. That makes it impossible to + * regenerate the same random sequence twice, so this can't be used + * for encryption, but will generate good random numbers. + * + * RC4 is a registered trademark of RSA Laboratories. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/arc4random.c,v 1.10 2004/03/24 14:44:57 green Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include + +#include "libc_private.h" +#include "un-namespace.h" + +struct arc4_stream { + u_int8_t i; + u_int8_t j; + u_int8_t s[256]; +}; + +static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; + +#define RANDOMDEV "/dev/urandom" +#define THREAD_LOCK() \ + do { \ + if (__isthreaded) \ + _pthread_mutex_lock(&arc4random_mtx); \ + } while (0) + +#define THREAD_UNLOCK() \ + do { \ + if (__isthreaded) \ + _pthread_mutex_unlock(&arc4random_mtx); \ + } while (0) + +static struct arc4_stream rs; +static int rs_initialized; +static int rs_stired; + +static inline u_int8_t arc4_getbyte(struct arc4_stream *); +static void arc4_stir(struct arc4_stream *); + +static inline void +arc4_init(as) + struct arc4_stream *as; +{ + int n; + + for (n = 0; n < 256; n++) + as->s[n] = n; + as->i = 0; + as->j = 0; +} + +static inline void +arc4_addrandom(as, dat, datlen) + struct arc4_stream *as; + u_char *dat; + int datlen; +{ + int n; + u_int8_t si; + + as->i--; + for (n = 0; n < 256; n++) { + as->i = (as->i + 1); + si = as->s[as->i]; + as->j = (as->j + si + dat[n % datlen]); + as->s[as->i] = as->s[as->j]; + as->s[as->j] = si; + } +} + +static void +arc4_stir(as) + struct arc4_stream *as; +{ + int fd, n; + struct { + struct timeval tv; + pid_t pid; + u_int8_t rnd[128 - sizeof(struct timeval) - sizeof(pid_t)]; + } rdat; + + gettimeofday(&rdat.tv, NULL); + rdat.pid = getpid(); + fd = _open(RANDOMDEV, O_RDONLY, 0); + if (fd >= 0) { + (void) _read(fd, rdat.rnd, sizeof(rdat.rnd)); + _close(fd); + } + /* fd < 0? Ah, what the heck. We'll just take whatever was on the + * stack... */ + + arc4_addrandom(as, (void *) &rdat, sizeof(rdat)); + + /* + * Throw away the first N bytes of output, as suggested in the + * paper "Weaknesses in the Key Scheduling Algorithm of RC4" + * by Fluher, Mantin, and Shamir. N=1024 is based on + * suggestions in the paper "(Not So) Random Shuffles of RC4" + * by Ilya Mironov. + */ + for (n = 0; n < 1024; n++) + arc4_getbyte(as); +} + +static inline u_int8_t +arc4_getbyte(as) + struct arc4_stream *as; +{ + u_int8_t si, sj; + + as->i = (as->i + 1); + si = as->s[as->i]; + as->j = (as->j + si); + sj = as->s[as->j]; + as->s[as->i] = sj; + as->s[as->j] = si; + + return (as->s[(si + sj) & 0xff]); +} + +static inline u_int32_t +arc4_getword(as) + struct arc4_stream *as; +{ + u_int32_t val; + + val = arc4_getbyte(as) << 24; + val |= arc4_getbyte(as) << 16; + val |= arc4_getbyte(as) << 8; + val |= arc4_getbyte(as); + + return (val); +} + +static void +arc4_check_init(void) +{ + if (!rs_initialized) { + arc4_init(&rs); + rs_initialized = 1; + } +} + +static void +arc4_check_stir(void) +{ + if (!rs_stired) { + arc4_stir(&rs); + rs_stired = 1; + } +} + +void +arc4random_stir() +{ + THREAD_LOCK(); + arc4_check_init(); + arc4_stir(&rs); + THREAD_UNLOCK(); +} + +void +arc4random_addrandom(dat, datlen) + u_char *dat; + int datlen; +{ + THREAD_LOCK(); + arc4_check_init(); + arc4_check_stir(); + arc4_addrandom(&rs, dat, datlen); + THREAD_UNLOCK(); +} + +u_int32_t +arc4random() +{ + u_int32_t rnd; + + THREAD_LOCK(); + arc4_check_init(); + arc4_check_stir(); + rnd = arc4_getword(&rs); + THREAD_UNLOCK(); + + return (rnd); +} + +#if 0 +/*-------- Test code for i386 --------*/ +#include +#include +int +main(int argc, char **argv) +{ + const int iter = 1000000; + int i; + pctrval v; + + v = rdtsc(); + for (i = 0; i < iter; i++) + arc4random(); + v = rdtsc() - v; + v /= iter; + + printf("%qd cycles\n", v); +} +#endif diff --git a/src/lib/libc/gen/assert.c b/src/lib/libc/gen/assert.c new file mode 100644 index 0000000..0ab0c3d --- /dev/null +++ b/src/lib/libc/gen/assert.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1992, 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[] = "@(#)assert.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/assert.c,v 1.7 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include +#include + +void +__assert(const char *func,const char *file,int line,iconst char *failedexpr) { + if (func == NULL) + (void)fprintf(stderr, + "Assertion failed: (%s), file %s, line %d.\n", failedexpr, + file, line); + else + (void)fprintf(stderr, + "Assertion failed: (%s), function %s, file %s, line %d.\n", + failedexpr, func, file, line); + abort(); + /* NOTREACHED */ +} diff --git a/src/lib/libc/gen/basename.c b/src/lib/libc/gen/basename.c new file mode 100644 index 0000000..c5da463 --- /dev/null +++ b/src/lib/libc/gen/basename.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 1997 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 0 +#ifndef lint +static char rcsid[] = "$OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; +#endif /* not lint */ +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/basename.c,v 1.7 2002/12/30 01:41:14 marcel Exp $"); + +#include +#include +#include +#include +#include + +char * +basename(path) + const char *path; +{ + static char *bname = NULL; + const char *endp, *startp; + + if (bname == NULL) { + bname = (char *)malloc(MAXPATHLEN); + if (bname == NULL) + return(NULL); + } + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + (void)strcpy(bname, "."); + return(bname); + } + + /* Strip trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* All slashes becomes "/" */ + if (endp == path && *endp == '/') { + (void)strcpy(bname, "/"); + return(bname); + } + + /* Find the start of the base */ + startp = endp; + while (startp > path && *(startp - 1) != '/') + startp--; + + if (endp - startp + 2 > MAXPATHLEN) { + errno = ENAMETOOLONG; + return(NULL); + } + (void)strncpy(bname, startp, endp - startp + 1); + bname[endp - startp + 1] = '\0'; + return(bname); +} diff --git a/src/lib/libc/gen/check_utility_compat.c b/src/lib/libc/gen/check_utility_compat.c new file mode 100644 index 0000000..716f5b2 --- /dev/null +++ b/src/lib/libc/gen/check_utility_compat.c @@ -0,0 +1,75 @@ +/* + * Copyright 2002 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/check_utility_compat.c,v 1.3 2003/05/01 19:03:13 nectar Exp $"); + +/* + * I din't use "namespace.h" here because none of the relevant utilities + * are threaded, so I'm not concerned about cancellation points or other + * niceties. + */ +#include +#include +#include +#include + +#ifndef LINE_MAX +#define LINE_MAX _POSIX2_LINE_MAX +#endif + +#define _PATH_UTIL_COMPAT "/etc/compat-FreeBSD-4-util" +#define _ENV_UTIL_COMPAT "_COMPAT_FreeBSD_4" + +int +check_utility_compat(const char *utility) +{ + char buf[LINE_MAX]; + char *p, *bp; + int len; + + if ((p = getenv(_ENV_UTIL_COMPAT)) != NULL) { + strlcpy(buf, p, sizeof buf); + } else { + if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof buf)) < 0) + return 0; + if (len > sizeof buf) + len = sizeof buf; + buf[len] = '\0'; + } + if (buf[0] == '\0') + return 1; + + bp = buf; + while ((p = strsep(&bp, ",")) != NULL) { + if (strcmp(p, utility) == 0) + return 1; + } + return 0; +} diff --git a/src/lib/libc/gen/clock.c b/src/lib/libc/gen/clock.c new file mode 100644 index 0000000..ddfccbe --- /dev/null +++ b/src/lib/libc/gen/clock.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)clock.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/clock.c,v 1.3 2002/03/22 21:52:05 obrien Exp $"); + +#include +#include +#include + +/* + * Convert usec to clock ticks; could do (usec * CLOCKS_PER_SEC) / 1000000, + * but this would overflow if we switch to nanosec. + */ +#define CONVTCK(r) ((r).tv_sec * CLOCKS_PER_SEC \ + + (r).tv_usec / (1000000 / CLOCKS_PER_SEC)) + +clock_t +clock() +{ + struct rusage ru; + + if (getrusage(RUSAGE_SELF, &ru)) + return ((clock_t) -1); + return((clock_t)((CONVTCK(ru.ru_utime) + CONVTCK(ru.ru_stime)))); +} diff --git a/src/lib/libc/gen/closedir.c b/src/lib/libc/gen/closedir.c new file mode 100644 index 0000000..31dedc0 --- /dev/null +++ b/src/lib/libc/gen/closedir.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1983, 1993 + * 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[] = "@(#)closedir.c 8.1 (Berkeley) 6/10/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/closedir.c,v 1.10 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" +#include "telldir.h" + +/* + * close a directory. + */ +int +closedir(dirp) + DIR *dirp; +{ + int fd; + + if (__isthreaded) + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _seekdir(dirp, dirp->dd_rewind); /* free seekdir storage */ + fd = dirp->dd_fd; + dirp->dd_fd = -1; + dirp->dd_loc = 0; + free((void *)dirp->dd_buf); + _reclaim_telldir(dirp); + if (__isthreaded) { + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_destroy((pthread_mutex_t *)&dirp->dd_lock); + } + free((void *)dirp); + return(_close(fd)); +} diff --git a/src/lib/libc/gen/confstr.c b/src/lib/libc/gen/confstr.c new file mode 100644 index 0000000..7c4699c --- /dev/null +++ b/src/lib/libc/gen/confstr.c @@ -0,0 +1,125 @@ +/*- + * Copyright (c) 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[] = "@(#)confstr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/confstr.c,v 1.9 2003/05/01 19:03:13 nectar Exp $"); + +#include + +#include +#include +#include +#include +#include + + +size_t +confstr(int name, char *buf, size_t len) +{ + const char *p; + const char UPE[] = "unsupported programming environment"; + + switch (name) { + case _CS_PATH: + p = _PATH_STDPATH; + goto docopy; + + /* + * POSIX/SUS ``Programming Environments'' stuff + * + * We don't support more than one programming environment + * on any platform (yet), so we just return the empty + * string for the environment we are compiled for, + * and the string "unsupported programming environment" + * for anything else. (The Standard says that if these + * values are used on a system which does not support + * this environment -- determined via sysconf() -- then + * the value we return is unspecified. So, we return + * something which will cause obvious breakage.) + */ + case _CS_POSIX_V6_ILP32_OFF32_CFLAGS: + case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS: + case _CS_POSIX_V6_ILP32_OFF32_LIBS: + case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS: + case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS: + case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS: + /* + * These two environments are never supported. + */ + p = UPE; + goto docopy; + + case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS: + case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS: + case _CS_POSIX_V6_ILP32_OFFBIG_LIBS: + if (sizeof(long) * CHAR_BIT == 32 && + sizeof(off_t) > sizeof(long)) + p = ""; + else + p = UPE; + goto docopy; + + case _CS_POSIX_V6_LP64_OFF64_CFLAGS: + case _CS_POSIX_V6_LP64_OFF64_LDFLAGS: + case _CS_POSIX_V6_LP64_OFF64_LIBS: + if (sizeof(long) * CHAR_BIT >= 64 && + sizeof(void *) * CHAR_BIT >= 64 && + sizeof(int) * CHAR_BIT >= 32 && + sizeof(off_t) >= sizeof(long)) + p = ""; + else + p = UPE; + goto docopy; + + case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS: + /* XXX - should have more complete coverage */ + if (sizeof(long) * CHAR_BIT >= 64) + p = "_POSIX_V6_LP64_OFF64"; + else + p = "_POSIX_V6_ILP32_OFFBIG"; + goto docopy; + +docopy: + if (len != 0 && buf != NULL) + strlcpy(buf, p, len); + return (strlen(p) + 1); + + default: + errno = EINVAL; + return (0); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/gen/crypt.c b/src/lib/libc/gen/crypt.c new file mode 100644 index 0000000..f846343 --- /dev/null +++ b/src/lib/libc/gen/crypt.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Tom Truscott. + * + * 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) +/* from static char sccsid[] = "@(#)crypt.c 5.11 (Berkeley) 6/25/91"; */ +#endif /* LIBC_SCCS and not lint */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/crypt.c,v 1.8 2002/10/18 16:24:20 markm Exp $"); + +#include +#include +#include + +/* + * UNIX password, and DES, encryption. + * + * since this is non-exportable, this is just a dummy. if you want real + * encryption, make sure you've got libcrypt.a around. + */ + +__warn_references(des_setkey, + "WARNING! des_setkey(3) not present in the system!"); + +/* ARGSUSED */ +int +des_setkey(const char *key __unused) +{ + fprintf(stderr, "WARNING! des_setkey(3) not present in the system!\n"); + return (0); +} + +__warn_references(des_cipher, + "WARNING! des_cipher(3) not present in the system!"); + +/* ARGSUSED */ +int +des_cipher(const char *in, char *out, long salt __unused, int num_iter __unused) +{ + fprintf(stderr, "WARNING! des_cipher(3) not present in the system!\n"); + bcopy(in, out, 8); + return (0); +} + +__warn_references(setkey, + "WARNING! setkey(3) not present in the system!"); + +/* ARGSUSED */ +int +setkey(const char *key __unused) +{ + fprintf(stderr, "WARNING! setkey(3) not present in the system!\n"); + return (0); +} + +__warn_references(encrypt, + "WARNING! encrypt(3) not present in the system!"); + +/* ARGSUSED */ +int +encrypt(char *block __unused, int flag __unused) +{ + fprintf(stderr, "WARNING! encrypt(3) not present in the system!\n"); + return (0); +} diff --git a/src/lib/libc/gen/ctermid.c b/src/lib/libc/gen/ctermid.c new file mode 100644 index 0000000..6b2c682 --- /dev/null +++ b/src/lib/libc/gen/ctermid.c @@ -0,0 +1,61 @@ +/*- + * 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[] = "@(#)ctermid.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/ctermid.c,v 1.3 2002/03/22 21:52:05 obrien Exp $"); + +#include +#include +#include + +char * +ctermid(char *s) +{ + static char def[] = _PATH_TTY; + + if (s) { + bcopy(def, s, sizeof(_PATH_TTY)); + return(s); + } + return(def); +} + + +char * +ctermid_r(char *s) +{ + return (s) ? ctermid(s) : NULL; +} diff --git a/src/lib/libc/gen/daemon.c b/src/lib/libc/gen/daemon.c new file mode 100644 index 0000000..1b9b706 --- /dev/null +++ b/src/lib/libc/gen/daemon.c @@ -0,0 +1,94 @@ +/*- + * 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[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/daemon.c,v 1.6 2003/11/10 22:01:42 ghelmer Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +int +daemon(nochdir, noclose) + int nochdir, noclose; +{ + struct sigaction osa, sa; + int fd; + pid_t newgrp; + int oerrno; + int osa_ok; + + /* A SIGHUP may be thrown when the parent exits below. */ + sigemptyset(&sa.sa_mask); + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + osa_ok = _sigaction(SIGHUP, &sa, &osa); + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + newgrp = setsid(); + oerrno = errno; + if (osa_ok != -1) + _sigaction(SIGHUP, &osa, NULL); + + if (newgrp == -1) { + errno = oerrno; + return (-1); + } + + if (!nochdir) + (void)chdir("/"); + + if (!noclose && (fd = _open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { + (void)_dup2(fd, STDIN_FILENO); + (void)_dup2(fd, STDOUT_FILENO); + (void)_dup2(fd, STDERR_FILENO); + if (fd > 2) + (void)_close(fd); + } + return (0); +} diff --git a/src/lib/libc/gen/devname.c b/src/lib/libc/gen/devname.c new file mode 100644 index 0000000..bf5af30 --- /dev/null +++ b/src/lib/libc/gen/devname.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)devname.c 8.2 (Berkeley) 4/29/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/devname.c,v 1.9 2003/06/20 09:52:27 phk Exp $"); + +#include +#include + +#include +#include +#include +#include +#include +#include + +char * +devname_r(dev_t dev, mode_t type, char *buf, int len) +{ + int i; + size_t j; + char *r; + + if ((type & S_IFMT) == S_IFCHR) { + j = len; + i = sysctlbyname("kern.devname", buf, &j, &dev, sizeof (dev)); + if (i == 0) + return (buf); + } + + /* Finally just format it */ + if (dev == NODEV) + r = "#NODEV"; + else + r = "#%c:%d:0x%x"; + snprintf(buf, len, r, + (type & S_IFMT) == S_IFCHR ? 'C' : 'B', major(dev), minor(dev)); + return (buf); +} + +char * +devname(dev_t dev, mode_t type) +{ + static char buf[SPECNAMELEN + 1]; + + return(devname_r(dev, type, buf, sizeof(buf))); +} diff --git a/src/lib/libc/gen/dirname.c b/src/lib/libc/gen/dirname.c new file mode 100644 index 0000000..8a4e1c9 --- /dev/null +++ b/src/lib/libc/gen/dirname.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 1997 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 0 +#ifndef lint +static char rcsid[] = "$OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $"; +#endif /* not lint */ +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/dirname.c,v 1.7 2002/12/30 01:41:14 marcel Exp $"); + +#include +#include +#include +#include +#include + +char * +dirname(path) + const char *path; +{ + static char *bname = NULL; + const char *endp; + + if (bname == NULL) { + bname = (char *)malloc(MAXPATHLEN); + if (bname == NULL) + return(NULL); + } + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + (void)strcpy(bname, "."); + return(bname); + } + + /* Strip trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* Find the start of the dir */ + while (endp > path && *endp != '/') + endp--; + + /* Either the dir is "/" or there are no slashes */ + if (endp == path) { + (void)strcpy(bname, *endp == '/' ? "/" : "."); + return(bname); + } else { + do { + endp--; + } while (endp > path && *endp == '/'); + } + + if (endp - path + 2 > MAXPATHLEN) { + errno = ENAMETOOLONG; + return(NULL); + } + (void)strncpy(bname, path, endp - path + 1); + bname[endp - path + 1] = '\0'; + return(bname); +} diff --git a/src/lib/libc/gen/disklabel.c b/src/lib/libc/gen/disklabel.c new file mode 100644 index 0000000..82ef800 --- /dev/null +++ b/src/lib/libc/gen/disklabel.c @@ -0,0 +1,163 @@ +/* + * Copyright (c) 1983, 1987, 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[] = "@(#)disklabel.c 8.2 (Berkeley) 5/3/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/disklabel.c,v 1.16 2002/08/16 15:33:20 bmilekic Exp $"); + +#include +#define DKTYPENAMES +#define FSTYPENAMES +#include + +#include +#include +#include +#include +#include +#include + +static int +gettype(char *t, const char **names) +{ + const char **nm; + + for (nm = names; *nm; nm++) + if (strcasecmp(t, *nm) == 0) + return (nm - names); + if (isdigit((unsigned char)*t)) + return (atoi(t)); + return (0); +} + +struct disklabel * +getdiskbyname(const char *name) +{ + static struct disklabel disk; + struct disklabel *dp = &disk; + struct partition *pp; + char *buf; + char *db_array[2] = { _PATH_DISKTAB, 0 }; + char *cp, *cq; /* can't be register */ + char p, max, psize[3], pbsize[3], + pfsize[3], poffset[3], ptype[3]; + u_int32_t *dx; + + if (cgetent(&buf, db_array, (char *) name) < 0) + return NULL; + + bzero((char *)&disk, sizeof(disk)); + /* + * typename + */ + cq = dp->d_typename; + cp = buf; + while (cq < dp->d_typename + sizeof(dp->d_typename) - 1 && + (*cq = *cp) && *cq != '|' && *cq != ':') + cq++, cp++; + *cq = '\0'; + + if (cgetstr(buf, "ty", &cq) > 0 && strcmp(cq, "removable") == 0) + dp->d_flags |= D_REMOVABLE; + else if (cq && strcmp(cq, "simulated") == 0) + dp->d_flags |= D_RAMDISK; + if (cgetcap(buf, "sf", ':') != NULL) + dp->d_flags |= D_BADSECT; + +#define getnumdflt(field, dname, dflt) \ + { long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; } + + getnumdflt(dp->d_secsize, "se", DEV_BSIZE); + getnumdflt(dp->d_ntracks, "nt", 0); + getnumdflt(dp->d_nsectors, "ns", 0); + getnumdflt(dp->d_ncylinders, "nc", 0); + + if (cgetstr(buf, "dt", &cq) > 0) + dp->d_type = gettype(cq, dktypenames); + else + getnumdflt(dp->d_type, "dt", 0); + getnumdflt(dp->d_secpercyl, "sc", dp->d_nsectors * dp->d_ntracks); + getnumdflt(dp->d_secperunit, "su", dp->d_secpercyl * dp->d_ncylinders); + getnumdflt(dp->d_rpm, "rm", 3600); + getnumdflt(dp->d_interleave, "il", 1); + getnumdflt(dp->d_trackskew, "sk", 0); + getnumdflt(dp->d_cylskew, "cs", 0); + getnumdflt(dp->d_headswitch, "hs", 0); + getnumdflt(dp->d_trkseek, "ts", 0); + getnumdflt(dp->d_bbsize, "bs", BBSIZE); + getnumdflt(dp->d_sbsize, "sb", 0); + strcpy(psize, "px"); + strcpy(pbsize, "bx"); + strcpy(pfsize, "fx"); + strcpy(poffset, "ox"); + strcpy(ptype, "tx"); + max = 'a' - 1; + pp = &dp->d_partitions[0]; + for (p = 'a'; p < 'a' + MAXPARTITIONS; p++, pp++) { + long l; + psize[1] = pbsize[1] = pfsize[1] = poffset[1] = ptype[1] = p; + if (cgetnum(buf, psize, &l) == -1) + pp->p_size = 0; + else { + pp->p_size = l; + cgetnum(buf, poffset, &l); + pp->p_offset = l; + getnumdflt(pp->p_fsize, pfsize, 0); + if (pp->p_fsize) { + long bsize; + + if (cgetnum(buf, pbsize, &bsize) == 0) + pp->p_frag = bsize / pp->p_fsize; + else + pp->p_frag = 8; + } + getnumdflt(pp->p_fstype, ptype, 0); + if (pp->p_fstype == 0 && cgetstr(buf, ptype, &cq) > 0) + pp->p_fstype = gettype(cq, fstypenames); + max = p; + } + } + dp->d_npartitions = max + 1 - 'a'; + (void)strcpy(psize, "dx"); + dx = dp->d_drivedata; + for (p = '0'; p < '0' + NDDATA; p++, dx++) { + psize[1] = p; + getnumdflt(*dx, psize, 0); + } + dp->d_magic = DISKMAGIC; + dp->d_magic2 = DISKMAGIC; + free(buf); + return (dp); +} diff --git a/src/lib/libc/gen/dlfcn.c b/src/lib/libc/gen/dlfcn.c new file mode 100644 index 0000000..971b2dc --- /dev/null +++ b/src/lib/libc/gen/dlfcn.c @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 1998 John D. Polstra + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/dlfcn.c,v 1.12 2004/03/05 08:10:17 markm Exp $"); + +/* + * Linkage to services provided by the dynamic linker. + */ +#include +#include + +static const char sorry[] = "Service unavailable"; + +/* + * For ELF, the dynamic linker directly resolves references to its + * services to functions inside the dynamic linker itself. These + * weak-symbol stubs are necessary so that "ld" won't complain about + * undefined symbols. The stubs are executed only when the program is + * linked statically, or when a given service isn't implemented in the + * dynamic linker. They must return an error if called, and they must + * be weak symbols so that the dynamic linker can override them. + */ + +#pragma weak _rtld_error +void +_rtld_error(const char *fmt, ...) +{ +} + +#pragma weak dladdr +int +dladdr(const void *addr, Dl_info *dlip) +{ + _rtld_error(sorry); + return 0; +} + +#pragma weak dlclose +int +dlclose(void *handle) +{ + _rtld_error(sorry); + return -1; +} + +#pragma weak dlerror +const char * +dlerror(void) +{ + return sorry; +} + +#pragma weak dllockinit +void +dllockinit(void *context, + void *(*lock_create)(void *context), + void (*rlock_acquire)(void *lock), + void (*wlock_acquire)(void *lock), + void (*lock_release)(void *lock), + void (*lock_destroy)(void *lock), + void (*context_destroy)(void *context)) +{ + if (context_destroy != NULL) + context_destroy(context); +} + +#pragma weak dlopen +void * +dlopen(const char *name, int mode) +{ + _rtld_error(sorry); + return NULL; +} + +#pragma weak dlsym +void * +dlsym(void * __restrict handle, const char * __restrict name) +{ + _rtld_error(sorry); + return NULL; +} + +#pragma weak dlinfo +int +dlinfo(void * __restrict handle, int request, void * __restrict p) +{ + _rtld_error(sorry); + return 0; +} + +#pragma weak _rtld_thread_init +void +_rtld_thread_init(void * li) +{ + _rtld_error(sorry); +} diff --git a/src/lib/libc/gen/dlfunc.c b/src/lib/libc/gen/dlfunc.c new file mode 100644 index 0000000..933ea19 --- /dev/null +++ b/src/lib/libc/gen/dlfunc.c @@ -0,0 +1,30 @@ +/* + * This source file is in the public domain. + * Garrett A. Wollman, 2002-05-28. + * + * $FreeBSD: src/lib/libc/gen/dlfunc.c,v 1.3 2002/09/11 05:05:48 mike Exp $ + */ + +#include + +/* + * Implement the dlfunc() interface, which behaves exactly the same as + * dlsym() except that it returns a function pointer instead of a data + * pointer. This can be used by applications to avoid compiler warnings + * about undefined behavior, and is intended as prior art for future + * POSIX standardization. This function requires that all pointer types + * have the same representation, which is true on all platforms FreeBSD + * runs on, but is not guaranteed by the C standard. + */ +dlfunc_t +dlfunc(void * __restrict handle, const char * __restrict symbol) +{ + union { + void *d; + dlfunc_t f; + } rv; + + rv.d = dlsym(handle, symbol); + return (rv.f); +} + diff --git a/src/lib/libc/gen/drand48.c b/src/lib/libc/gen/drand48.c new file mode 100644 index 0000000..92aeb80 --- /dev/null +++ b/src/lib/libc/gen/drand48.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/drand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; + +double +drand48(void) +{ + return erand48(_rand48_seed); +} diff --git a/src/lib/libc/gen/erand48.c b/src/lib/libc/gen/erand48.c new file mode 100644 index 0000000..4b0c1df --- /dev/null +++ b/src/lib/libc/gen/erand48.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/erand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +double +erand48(unsigned short xseed[3]) +{ + _dorand48(xseed); + return ldexp((double) xseed[0], -48) + + ldexp((double) xseed[1], -32) + + ldexp((double) xseed[2], -16); +} diff --git a/src/lib/libc/gen/err.c b/src/lib/libc/gen/err.c new file mode 100644 index 0000000..aa0d306 --- /dev/null +++ b/src/lib/libc/gen/err.c @@ -0,0 +1,213 @@ +/*- + * Copyright (c) 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[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/err.c,v 1.13 2002/03/29 22:43:41 markm Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" + +static FILE *err_file; /* file to use for error output */ +static void (*err_exit)(int); + +/* + * This is declared to take a `void *' so that the caller is not required + * to include first. However, it is really a `FILE *', and the + * manual page documents it as such. + */ +void +err_set_file(void *fp) +{ + if (fp) + err_file = fp; + else + err_file = stderr; +} + +void +err_set_exit(void (*ef)(int)) +{ + err_exit = ef; +} + +__weak_reference(_err, err); + +void +_err(int eval, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + verrc(eval, errno, fmt, ap); + va_end(ap); +} + +void +verr(eval, fmt, ap) + int eval; + const char *fmt; + va_list ap; +{ + verrc(eval, errno, fmt, ap); +} + +void +errc(int eval, int code, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + verrc(eval, code, fmt, ap); + va_end(ap); +} + +void +verrc(eval, code, fmt, ap) + int eval; + int code; + const char *fmt; + va_list ap; +{ + if (err_file == 0) + err_set_file((FILE *)0); + fprintf(err_file, "%s: ", _getprogname()); + if (fmt != NULL) { + vfprintf(err_file, fmt, ap); + fprintf(err_file, ": "); + } + fprintf(err_file, "%s\n", strerror(code)); + if (err_exit) + err_exit(eval); + exit(eval); +} + +void +errx(int eval, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + verrx(eval, fmt, ap); + va_end(ap); +} + +void +verrx(eval, fmt, ap) + int eval; + const char *fmt; + va_list ap; +{ + if (err_file == 0) + err_set_file((FILE *)0); + fprintf(err_file, "%s: ", _getprogname()); + if (fmt != NULL) + vfprintf(err_file, fmt, ap); + fprintf(err_file, "\n"); + if (err_exit) + err_exit(eval); + exit(eval); +} + +__weak_reference(_warn, warn); + +void +_warn(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnc(errno, fmt, ap); + va_end(ap); +} + +void +vwarn(fmt, ap) + const char *fmt; + va_list ap; +{ + vwarnc(errno, fmt, ap); +} + +void +warnc(int code, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnc(code, fmt, ap); + va_end(ap); +} + +void +vwarnc(code, fmt, ap) + int code; + const char *fmt; + va_list ap; +{ + if (err_file == 0) + err_set_file((FILE *)0); + fprintf(err_file, "%s: ", _getprogname()); + if (fmt != NULL) { + vfprintf(err_file, fmt, ap); + fprintf(err_file, ": "); + } + fprintf(err_file, "%s\n", strerror(code)); +} + +void +warnx(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vwarnx(fmt, ap); + va_end(ap); +} + +void +vwarnx(fmt, ap) + const char *fmt; + va_list ap; +{ + if (err_file == 0) + err_set_file((FILE *)0); + fprintf(err_file, "%s: ", _getprogname()); + if (fmt != NULL) + vfprintf(err_file, fmt, ap); + fprintf(err_file, "\n"); +} diff --git a/src/lib/libc/gen/errlst.c b/src/lib/libc/gen/errlst.c new file mode 100644 index 0000000..5207748 --- /dev/null +++ b/src/lib/libc/gen/errlst.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 1982, 1985, 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[] = "@(#)errlst.c 8.2 (Berkeley) 11/16/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/errlst.c,v 1.7 2002/10/09 08:04:24 peter Exp $"); + +#include + +const char *const sys_errlist[] = { + "Undefined error: 0", /* 0 - ENOERROR */ + "Operation not permitted", /* 1 - EPERM */ + "No such file or directory", /* 2 - ENOENT */ + "No such process", /* 3 - ESRCH */ + "Interrupted system call", /* 4 - EINTR */ + "Input/output error", /* 5 - EIO */ + "Device not configured", /* 6 - ENXIO */ + "Argument list too long", /* 7 - E2BIG */ + "Exec format error", /* 8 - ENOEXEC */ + "Bad file descriptor", /* 9 - EBADF */ + "No child processes", /* 10 - ECHILD */ + "Resource deadlock avoided", /* 11 - EDEADLK */ + "Cannot allocate memory", /* 12 - ENOMEM */ + "Permission denied", /* 13 - EACCES */ + "Bad address", /* 14 - EFAULT */ + "Block device required", /* 15 - ENOTBLK */ + "Device busy", /* 16 - EBUSY */ + "File exists", /* 17 - EEXIST */ + "Cross-device link", /* 18 - EXDEV */ + "Operation not supported by device", /* 19 - ENODEV */ + "Not a directory", /* 20 - ENOTDIR */ + "Is a directory", /* 21 - EISDIR */ + "Invalid argument", /* 22 - EINVAL */ + "Too many open files in system", /* 23 - ENFILE */ + "Too many open files", /* 24 - EMFILE */ + "Inappropriate ioctl for device", /* 25 - ENOTTY */ + "Text file busy", /* 26 - ETXTBSY */ + "File too large", /* 27 - EFBIG */ + "No space left on device", /* 28 - ENOSPC */ + "Illegal seek", /* 29 - ESPIPE */ + "Read-only file system", /* 30 - EROFS */ + "Too many links", /* 31 - EMLINK */ + "Broken pipe", /* 32 - EPIPE */ + +/* math software */ + "Numerical argument out of domain", /* 33 - EDOM */ + "Result too large", /* 34 - ERANGE */ + +/* non-blocking and interrupt i/o */ + "Resource temporarily unavailable", /* 35 - EAGAIN */ + /* 35 - EWOULDBLOCK */ + "Operation now in progress", /* 36 - EINPROGRESS */ + "Operation already in progress", /* 37 - EALREADY */ + +/* ipc/network software -- argument errors */ + "Socket operation on non-socket", /* 38 - ENOTSOCK */ + "Destination address required", /* 39 - EDESTADDRREQ */ + "Message too long", /* 40 - EMSGSIZE */ + "Protocol wrong type for socket", /* 41 - EPROTOTYPE */ + "Protocol not available", /* 42 - ENOPROTOOPT */ + "Protocol not supported", /* 43 - EPROTONOSUPPORT */ + "Socket type not supported", /* 44 - ESOCKTNOSUPPORT */ + "Operation not supported", /* 45 - EOPNOTSUPP */ + "Protocol family not supported", /* 46 - EPFNOSUPPORT */ + /* 47 - EAFNOSUPPORT */ + "Address family not supported by protocol family", + "Address already in use", /* 48 - EADDRINUSE */ + "Can't assign requested address", /* 49 - EADDRNOTAVAIL */ + +/* ipc/network software -- operational errors */ + "Network is down", /* 50 - ENETDOWN */ + "Network is unreachable", /* 51 - ENETUNREACH */ + "Network dropped connection on reset", /* 52 - ENETRESET */ + "Software caused connection abort", /* 53 - ECONNABORTED */ + "Connection reset by peer", /* 54 - ECONNRESET */ + "No buffer space available", /* 55 - ENOBUFS */ + "Socket is already connected", /* 56 - EISCONN */ + "Socket is not connected", /* 57 - ENOTCONN */ + "Can't send after socket shutdown", /* 58 - ESHUTDOWN */ + "Too many references: can't splice", /* 59 - ETOOMANYREFS */ + "Operation timed out", /* 60 - ETIMEDOUT */ + "Connection refused", /* 61 - ECONNREFUSED */ + + "Too many levels of symbolic links", /* 62 - ELOOP */ + "File name too long", /* 63 - ENAMETOOLONG */ + +/* should be rearranged */ + "Host is down", /* 64 - EHOSTDOWN */ + "No route to host", /* 65 - EHOSTUNREACH */ + "Directory not empty", /* 66 - ENOTEMPTY */ + +/* quotas & mush */ + "Too many processes", /* 67 - EPROCLIM */ + "Too many users", /* 68 - EUSERS */ + "Disc quota exceeded", /* 69 - EDQUOT */ + +/* Network File System */ + "Stale NFS file handle", /* 70 - ESTALE */ + "Too many levels of remote in path", /* 71 - EREMOTE */ + "RPC struct is bad", /* 72 - EBADRPC */ + "RPC version wrong", /* 73 - ERPCMISMATCH */ + "RPC prog. not avail", /* 74 - EPROGUNAVAIL */ + "Program version wrong", /* 75 - EPROGMISMATCH */ + "Bad procedure for program", /* 76 - EPROCUNAVAIL */ + + "No locks available", /* 77 - ENOLCK */ + "Function not implemented", /* 78 - ENOSYS */ + "Inappropriate file type or format", /* 79 - EFTYPE */ + "Authentication error", /* 80 - EAUTH */ + "Need authenticator", /* 81 - ENEEDAUTH */ + "Identifier removed", /* 82 - EIDRM */ + "No message of desired type", /* 83 - ENOMSG */ + "Value too large to be stored in data type", /* 84 - EOVERFLOW */ + "Operation canceled", /* 85 - ECANCELED */ + "Illegal byte sequence", /* 86 - EILSEQ */ + "Attribute not found", /* 87 - ENOATTR */ + +/* General */ + "Programming error", /* 88 - EDOOFUS */ +}; +const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]); diff --git a/src/lib/libc/gen/errno.c b/src/lib/libc/gen/errno.c new file mode 100644 index 0000000..7d98857 --- /dev/null +++ b/src/lib/libc/gen/errno.c @@ -0,0 +1,30 @@ +/*- + * Copyright (c) 2002 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/errno.c,v 1.1 2002/10/09 08:04:24 peter Exp $"); + +int errno; diff --git a/src/lib/libc/gen/exec.c b/src/lib/libc/gen/exec.c new file mode 100644 index 0000000..211eb78 --- /dev/null +++ b/src/lib/libc/gen/exec.c @@ -0,0 +1,275 @@ +/*- + * Copyright (c) 1991, 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[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/exec.c,v 1.22 2003/07/01 12:30:03 bde Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "un-namespace.h" + +extern char **environ; + +int +execl(const char *name, const char *arg, ...) +{ + va_list ap; + char **argv; + int n; + + va_start(ap, arg); + n = 1; + while (va_arg(ap, char *) != NULL) + n++; + va_end(ap); + argv = alloca((n + 1) * sizeof(*argv)); + if (argv == NULL) { + errno = ENOMEM; + return (-1); + } + va_start(ap, arg); + n = 1; + argv[0] = (char *)arg; + while ((argv[n] = va_arg(ap, char *)) != NULL) + n++; + va_end(ap); + return (_execve(name, argv, environ)); +} + +int +execle(const char *name, const char *arg, ...) +{ + va_list ap; + char **argv, **envp; + int n; + + va_start(ap, arg); + n = 1; + while (va_arg(ap, char *) != NULL) + n++; + va_end(ap); + argv = alloca((n + 1) * sizeof(*argv)); + if (argv == NULL) { + errno = ENOMEM; + return (-1); + } + va_start(ap, arg); + n = 1; + argv[0] = (char *)arg; + while ((argv[n] = va_arg(ap, char *)) != NULL) + n++; + envp = va_arg(ap, char **); + va_end(ap); + return (_execve(name, argv, envp)); +} + +int +execlp(const char *name, const char *arg, ...) +{ + va_list ap; + char **argv; + int n; + + va_start(ap, arg); + n = 1; + while (va_arg(ap, char *) != NULL) + n++; + va_end(ap); + argv = alloca((n + 1) * sizeof(*argv)); + if (argv == NULL) { + errno = ENOMEM; + return (-1); + } + va_start(ap, arg); + n = 1; + argv[0] = (char *)arg; + while ((argv[n] = va_arg(ap, char *)) != NULL) + n++; + va_end(ap); + return (execvp(name, argv)); +} + +int +execv(name, argv) + const char *name; + char * const *argv; +{ + (void)_execve(name, argv, environ); + return (-1); +} + +int +execvp(const char *name, char * const *argv) +{ + const char *path; + + /* Get the path we're searching. */ + if ((path = getenv("PATH")) == NULL) + path = _PATH_DEFPATH; + + return (execvP(name, path, argv)); +} + +int +execvP(name, path, argv) + const char *name; + const char *path; + char * const *argv; +{ + char **memp; + int cnt, lp, ln; + char *p; + int eacces, save_errno; + char *bp, *cur, buf[MAXPATHLEN]; + struct stat sb; + + eacces = 0; + + /* If it's an absolute or relative path name, it's easy. */ + if (index(name, '/')) { + bp = (char *)name; + cur = NULL; + goto retry; + } + bp = buf; + + /* If it's an empty path name, fail in the usual POSIX way. */ + if (*name == '\0') { + errno = ENOENT; + return (-1); + } + + cur = alloca(strlen(path) + 1); + if (cur == NULL) { + errno = ENOMEM; + return (-1); + } + strcpy(cur, path); + while ((p = strsep(&cur, ":")) != NULL) { + /* + * It's a SHELL path -- double, leading and trailing colons + * mean the current directory. + */ + if (*p == '\0') { + p = "."; + lp = 1; + } else + lp = strlen(p); + ln = strlen(name); + + /* + * If the path is too long complain. This is a possible + * security issue; given a way to make the path too long + * the user may execute the wrong program. + */ + if (lp + ln + 2 > sizeof(buf)) { + (void)_write(STDERR_FILENO, "execvP: ", 8); + (void)_write(STDERR_FILENO, p, lp); + (void)_write(STDERR_FILENO, ": path too long\n", + 16); + continue; + } + bcopy(p, buf, lp); + buf[lp] = '/'; + bcopy(name, buf + lp + 1, ln); + buf[lp + ln + 1] = '\0'; + +retry: (void)_execve(bp, argv, environ); + switch (errno) { + case E2BIG: + goto done; + case ELOOP: + case ENAMETOOLONG: + case ENOENT: + break; + case ENOEXEC: + for (cnt = 0; argv[cnt]; ++cnt) + ; + memp = alloca((cnt + 2) * sizeof(char *)); + if (memp == NULL) { + /* errno = ENOMEM; XXX override ENOEXEC? */ + goto done; + } + memp[0] = "sh"; + memp[1] = bp; + bcopy(argv + 1, memp + 2, cnt * sizeof(char *)); + (void)_execve(_PATH_BSHELL, memp, environ); + goto done; + case ENOMEM: + goto done; + case ENOTDIR: + break; + case ETXTBSY: + /* + * We used to retry here, but sh(1) doesn't. + */ + goto done; + default: + /* + * EACCES may be for an inaccessible directory or + * a non-executable file. Call stat() to decide + * which. This also handles ambiguities for EFAULT + * and EIO, and undocumented errors like ESTALE. + * We hope that the race for a stat() is unimportant. + */ + save_errno = errno; + if (stat(bp, &sb) != 0) + break; + if (save_errno == EACCES) { + eacces = 1; + continue; + } + errno = save_errno; + goto done; + } + } + if (eacces) + errno = EACCES; + else + errno = ENOENT; +done: + return (-1); +} diff --git a/src/lib/libc/gen/fmtcheck.c b/src/lib/libc/gen/fmtcheck.c new file mode 100644 index 0000000..e907995 --- /dev/null +++ b/src/lib/libc/gen/fmtcheck.c @@ -0,0 +1,267 @@ +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code was contributed to The NetBSD Foundation by Allen Briggs. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* $NetBSD: fmtcheck.c,v 1.2 2000/11/01 01:17:20 briggs Exp $ */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/fmtcheck.c,v 1.7 2004/05/02 10:55:05 das Exp $"); + +#include +#include +#include + +__weak_reference(__fmtcheck, fmtcheck); + +enum __e_fmtcheck_types { + FMTCHECK_START, + FMTCHECK_SHORT, + FMTCHECK_INT, + FMTCHECK_LONG, + FMTCHECK_QUAD, + FMTCHECK_PTRDIFFT, + FMTCHECK_SIZET, + FMTCHECK_SHORTPOINTER, + FMTCHECK_INTPOINTER, + FMTCHECK_LONGPOINTER, + FMTCHECK_QUADPOINTER, + FMTCHECK_PTRDIFFTPOINTER, + FMTCHECK_SIZETPOINTER, +#ifndef NO_FLOATING_POINT + FMTCHECK_DOUBLE, + FMTCHECK_LONGDOUBLE, +#endif + FMTCHECK_STRING, + FMTCHECK_WIDTH, + FMTCHECK_PRECISION, + FMTCHECK_DONE, + FMTCHECK_UNKNOWN +}; +typedef enum __e_fmtcheck_types EFT; + +#define RETURN(pf,f,r) do { \ + *(pf) = (f); \ + return r; \ + } /*NOTREACHED*/ /*CONSTCOND*/ while (0) + +static EFT +get_next_format_from_precision(const char **pf) +{ + int sh, lg, quad, longdouble, ptrdifft, sizet; + const char *f; + + sh = lg = quad = longdouble = ptrdifft = sizet = 0; + + f = *pf; + switch (*f) { + case 'h': + f++; + sh = 1; + break; + case 'l': + f++; + if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); + if (*f == 'l') { + f++; + quad = 1; + } else { + lg = 1; + } + break; + case 'q': + f++; + quad = 1; + break; + case 't': + f++; + ptrdifft = 1; + break; + case 'z': + f++; + sizet = 1; + break; + case 'L': + f++; + longdouble = 1; + break; + default: + break; + } + if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); + if (strchr("diouxX", *f)) { + if (longdouble) + RETURN(pf,f,FMTCHECK_UNKNOWN); + if (lg) + RETURN(pf,f,FMTCHECK_LONG); + if (quad) + RETURN(pf,f,FMTCHECK_QUAD); + if (ptrdifft) + RETURN(pf,f,FMTCHECK_PTRDIFFT); + if (sizet) + RETURN(pf,f,FMTCHECK_SIZET); + RETURN(pf,f,FMTCHECK_INT); + } + if (*f == 'n') { + if (longdouble) + RETURN(pf,f,FMTCHECK_UNKNOWN); + if (sh) + RETURN(pf,f,FMTCHECK_SHORTPOINTER); + if (lg) + RETURN(pf,f,FMTCHECK_LONGPOINTER); + if (quad) + RETURN(pf,f,FMTCHECK_QUADPOINTER); + if (ptrdifft) + RETURN(pf,f,FMTCHECK_PTRDIFFTPOINTER); + if (sizet) + RETURN(pf,f,FMTCHECK_SIZETPOINTER); + RETURN(pf,f,FMTCHECK_INTPOINTER); + } + if (strchr("DOU", *f)) { + if (sh + lg + quad + longdouble + ptrdifft + sizet) + RETURN(pf,f,FMTCHECK_UNKNOWN); + RETURN(pf,f,FMTCHECK_LONG); + } +#ifndef NO_FLOATING_POINT + if (strchr("aAeEfFgG", *f)) { + if (longdouble) + RETURN(pf,f,FMTCHECK_LONGDOUBLE); + if (sh + lg + quad + ptrdifft + sizet) + RETURN(pf,f,FMTCHECK_UNKNOWN); + RETURN(pf,f,FMTCHECK_DOUBLE); + } +#endif + if (*f == 'c') { + if (sh + lg + quad + longdouble + ptrdifft + sizet) + RETURN(pf,f,FMTCHECK_UNKNOWN); + RETURN(pf,f,FMTCHECK_INT); + } + if (*f == 's') { + if (sh + lg + quad + longdouble + ptrdifft + sizet) + RETURN(pf,f,FMTCHECK_UNKNOWN); + RETURN(pf,f,FMTCHECK_STRING); + } + if (*f == 'p') { + if (sh + lg + quad + longdouble + ptrdifft + sizet) + RETURN(pf,f,FMTCHECK_UNKNOWN); + RETURN(pf,f,FMTCHECK_LONG); + } + RETURN(pf,f,FMTCHECK_UNKNOWN); + /*NOTREACHED*/ +} + +static EFT +get_next_format_from_width(const char **pf) +{ + const char *f; + + f = *pf; + if (*f == '.') { + f++; + if (*f == '*') { + RETURN(pf,f,FMTCHECK_PRECISION); + } + /* eat any precision (empty is allowed) */ + while (isdigit(*f)) f++; + if (!*f) RETURN(pf,f,FMTCHECK_UNKNOWN); + } + RETURN(pf,f,get_next_format_from_precision(pf)); + /*NOTREACHED*/ +} + +static EFT +get_next_format(const char **pf, EFT eft) +{ + int infmt; + const char *f; + + if (eft == FMTCHECK_WIDTH) { + (*pf)++; + return get_next_format_from_width(pf); + } else if (eft == FMTCHECK_PRECISION) { + (*pf)++; + return get_next_format_from_precision(pf); + } + + f = *pf; + infmt = 0; + while (!infmt) { + f = strchr(f, '%'); + if (f == NULL) + RETURN(pf,f,FMTCHECK_DONE); + f++; + if (!*f) + RETURN(pf,f,FMTCHECK_UNKNOWN); + if (*f != '%') + infmt = 1; + else + f++; + } + + /* Eat any of the flags */ + while (*f && (strchr("#0- +", *f))) + f++; + + if (*f == '*') { + RETURN(pf,f,FMTCHECK_WIDTH); + } + /* eat any width */ + while (isdigit(*f)) f++; + if (!*f) { + RETURN(pf,f,FMTCHECK_UNKNOWN); + } + + RETURN(pf,f,get_next_format_from_width(pf)); + /*NOTREACHED*/ +} + +__const char * +__fmtcheck(const char *f1, const char *f2) +{ + const char *f1p, *f2p; + EFT f1t, f2t; + + if (!f1) return f2; + + f1p = f1; + f1t = FMTCHECK_START; + f2p = f2; + f2t = FMTCHECK_START; + while ((f1t = get_next_format(&f1p, f1t)) != FMTCHECK_DONE) { + if (f1t == FMTCHECK_UNKNOWN) + return f2; + f2t = get_next_format(&f2p, f2t); + if (f1t != f2t) + return f2; + } + return f1; +} diff --git a/src/lib/libc/gen/fmtmsg.c b/src/lib/libc/gen/fmtmsg.c new file mode 100644 index 0000000..4db35dc --- /dev/null +++ b/src/lib/libc/gen/fmtmsg.c @@ -0,0 +1,220 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/fmtmsg.c,v 1.5 2003/05/01 19:03:13 nectar Exp $"); + +#include +#include +#include +#include + +/* Default value for MSGVERB. */ +#define DFLT_MSGVERB "label:severity:text:action:tag" + +/* Maximum valid size for a MSGVERB. */ +#define MAX_MSGVERB sizeof(DFLT_MSGVERB) + +static char *printfmt(char *, long, const char *, int, const char *, + const char *, const char *); +static char *nextcomp(const char *); +static const char + *sevinfo(int); +static int validmsgverb(const char *); + +static const char *validlist[] = { + "label", "severity", "text", "action", "tag", NULL +}; + +int +fmtmsg(long class, const char *label, int sev, const char *text, + const char *action, const char *tag) +{ + FILE *fp; + char *env, *msgverb, *output; + + if (class & MM_PRINT) { + if ((env = getenv("MSGVERB")) != NULL && *env != '\0' && + strlen(env) <= strlen(DFLT_MSGVERB)) { + if ((msgverb = strdup(env)) == NULL) + return (MM_NOTOK); + else if (validmsgverb(msgverb) == 0) { + free(msgverb); + goto def; + } + } else { +def: + if ((msgverb = strdup(DFLT_MSGVERB)) == NULL) + return (MM_NOTOK); + } + output = printfmt(msgverb, class, label, sev, text, action, + tag); + if (output == NULL) { + free(msgverb); + return (MM_NOTOK); + } + if (*output != '\0') + fprintf(stderr, "%s", output); + free(msgverb); + free(output); + } + if (class & MM_CONSOLE) { + output = printfmt(DFLT_MSGVERB, class, label, sev, text, + action, tag); + if (output == NULL) + return (MM_NOCON); + if (*output != '\0') { + if ((fp = fopen("/dev/console", "a")) == NULL) { + free(output); + return (MM_NOCON); + } + fprintf(fp, "%s", output); + fclose(fp); + } + free(output); + } + return (MM_OK); +} + +#define INSERT_COLON \ + if (*output != '\0') \ + strlcat(output, ": ", size) +#define INSERT_NEWLINE \ + if (*output != '\0') \ + strlcat(output, "\n", size) +#define INSERT_SPACE \ + if (*output != '\0') \ + strlcat(output, " ", size) + +/* + * Returns NULL on memory allocation failure, otherwise returns a pointer to + * a newly malloc()'d output buffer. + */ +static char * +printfmt(char *msgverb, long class, const char *label, int sev, + const char *text, const char *act, const char *tag) +{ + size_t size; + char *comp, *output; + const char *sevname; + + size = 32; + if (label != MM_NULLLBL) + size += strlen(label); + if ((sevname = sevinfo(sev)) != NULL) + size += strlen(sevname); + if (text != MM_NULLTXT) + size += strlen(text); + if (text != MM_NULLACT) + size += strlen(act); + if (tag != MM_NULLTAG) + size += strlen(tag); + + if ((output = malloc(size)) == NULL) + return (NULL); + *output = '\0'; + while ((comp = nextcomp(msgverb)) != NULL) { + if (strcmp(comp, "label") == 0 && label != MM_NULLLBL) { + INSERT_COLON; + strlcat(output, label, size); + } else if (strcmp(comp, "severity") == 0 && sevname != NULL) { + INSERT_COLON; + strlcat(output, sevinfo(sev), size); + } else if (strcmp(comp, "text") == 0 && text != MM_NULLTXT) { + INSERT_COLON; + strlcat(output, text, size); + } else if (strcmp(comp, "action") == 0 && act != MM_NULLACT) { + INSERT_NEWLINE; + strlcat(output, "TO FIX: ", size); + strlcat(output, act, size); + } else if (strcmp(comp, "tag") == 0 && tag != MM_NULLTAG) { + INSERT_SPACE; + strlcat(output, tag, size); + } + } + INSERT_NEWLINE; + return (output); +} + +/* + * Returns a component of a colon delimited string. NULL is returned to + * indicate that there are no remaining components. This function must be + * called until it returns NULL in order for the local state to be cleared. + */ +static char * +nextcomp(const char *msgverb) +{ + static char lmsgverb[MAX_MSGVERB], *state; + char *retval; + + if (*lmsgverb == '\0') { + strlcpy(lmsgverb, msgverb, sizeof(lmsgverb)); + retval = strtok_r(lmsgverb, ":", &state); + } else { + retval = strtok_r(NULL, ":", &state); + } + if (retval == NULL) + *lmsgverb = '\0'; + return (retval); +} + +static const char * +sevinfo(int sev) +{ + + switch (sev) { + case MM_HALT: + return ("HALT"); + case MM_ERROR: + return ("ERROR"); + case MM_WARNING: + return ("WARNING"); + case MM_INFO: + return ("INFO"); + default: + return (NULL); + } +} + +/* + * Returns 1 if the msgverb list is valid, otherwise 0. + */ +static int +validmsgverb(const char *msgverb) +{ + char *msgcomp; + int i, equality; + + equality = 0; + while ((msgcomp = nextcomp(msgverb)) != NULL) { + equality--; + for (i = 0; validlist[i] != NULL; i++) { + if (strcmp(msgcomp, validlist[i]) == 0) + equality++; + } + } + return (!equality); +} diff --git a/src/lib/libc/gen/fnmatch.c b/src/lib/libc/gen/fnmatch.c new file mode 100644 index 0000000..7b6f10d --- /dev/null +++ b/src/lib/libc/gen/fnmatch.c @@ -0,0 +1,233 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * 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[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/fnmatch.c,v 1.15 2002/02/01 01:32:19 obrien Exp $"); + +/* + * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. + * Compares a filename or pathname to a pattern. + */ + +#include +#include +#include +#include + +#include "collate.h" + +#define EOS '\0' + +#define RANGE_MATCH 1 +#define RANGE_NOMATCH 0 +#define RANGE_ERROR (-1) + +static int rangematch(const char *, char, int, char **); + +int +fnmatch(pattern, string, flags) + const char *pattern, *string; + int flags; +{ + const char *stringstart; + char *newp; + char c, test; + + for (stringstart = string;;) + switch (c = *pattern++) { + case EOS: + if ((flags & FNM_LEADING_DIR) && *string == '/') + return (0); + return (*string == EOS ? 0 : FNM_NOMATCH); + case '?': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + ++string; + break; + case '*': + c = *pattern; + /* Collapse multiple stars. */ + while (c == '*') + c = *++pattern; + + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + /* Optimize for pattern with * at end or before /. */ + if (c == EOS) + if (flags & FNM_PATHNAME) + return ((flags & FNM_LEADING_DIR) || + strchr(string, '/') == NULL ? + 0 : FNM_NOMATCH); + else + return (0); + else if (c == '/' && flags & FNM_PATHNAME) { + if ((string = strchr(string, '/')) == NULL) + return (FNM_NOMATCH); + break; + } + + /* General case, use recursion. */ + while ((test = *string) != EOS) { + if (!fnmatch(pattern, string, flags & ~FNM_PERIOD)) + return (0); + if (test == '/' && flags & FNM_PATHNAME) + break; + ++string; + } + return (FNM_NOMATCH); + case '[': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + switch (rangematch(pattern, *string, flags, &newp)) { + case RANGE_ERROR: + goto norm; + case RANGE_MATCH: + pattern = newp; + break; + case RANGE_NOMATCH: + return (FNM_NOMATCH); + } + ++string; + break; + case '\\': + if (!(flags & FNM_NOESCAPE)) { + if ((c = *pattern++) == EOS) { + c = '\\'; + --pattern; + } + } + /* FALLTHROUGH */ + default: + norm: + if (c == *string) + ; + else if ((flags & FNM_CASEFOLD) && + (tolower((unsigned char)c) == + tolower((unsigned char)*string))) + ; + else + return (FNM_NOMATCH); + string++; + break; + } + /* NOTREACHED */ +} + +static int +rangematch(pattern, test, flags, newp) + const char *pattern; + char test; + int flags; + char **newp; +{ + int negate, ok; + char c, c2; + + /* + * A bracket expression starting with an unquoted circumflex + * character produces unspecified results (IEEE 1003.2-1992, + * 3.13.2). This implementation treats it like '!', for + * consistency with the regular expression syntax. + * J.T. Conklin (conklin@ngai.kaleida.com) + */ + if ( (negate = (*pattern == '!' || *pattern == '^')) ) + ++pattern; + + if (flags & FNM_CASEFOLD) + test = tolower((unsigned char)test); + + /* + * A right bracket shall lose its special meaning and represent + * itself in a bracket expression if it occurs first in the list. + * -- POSIX.2 2.8.3.2 + */ + ok = 0; + c = *pattern++; + do { + if (c == '\\' && !(flags & FNM_NOESCAPE)) + c = *pattern++; + if (c == EOS) + return (RANGE_ERROR); + + if (c == '/' && (flags & FNM_PATHNAME)) + return (RANGE_NOMATCH); + + if (flags & FNM_CASEFOLD) + c = tolower((unsigned char)c); + + if (*pattern == '-' + && (c2 = *(pattern+1)) != EOS && c2 != ']') { + pattern += 2; + if (c2 == '\\' && !(flags & FNM_NOESCAPE)) + c2 = *pattern++; + if (c2 == EOS) + return (RANGE_ERROR); + + if (flags & FNM_CASEFOLD) + c2 = tolower((unsigned char)c2); + + if (__collate_load_error ? + c <= test && test <= c2 : + __collate_range_cmp(c, test) <= 0 + && __collate_range_cmp(test, c2) <= 0 + ) + ok = 1; + } else if (c == test) + ok = 1; + } while ((c = *pattern++) != ']'); + + *newp = (char *)pattern; + return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH); +} diff --git a/src/lib/libc/gen/fpclassify.c b/src/lib/libc/gen/fpclassify.c new file mode 100644 index 0000000..e7eae15 --- /dev/null +++ b/src/lib/libc/gen/fpclassify.c @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 2003 Mike Barcroft + * Copyright (c) 2002, 2003 David Schultz + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/gen/fpclassify.c,v 1.1 2003/02/08 20:37:50 mike Exp $ + */ + +#include + +#include +#include + +#include "fpmath.h" + +int +__fpclassifyf(float f) +{ + union IEEEf2bits u; + + u.f = f; + if (u.bits.exp == 0) { + if (u.bits.man == 0) + return (FP_ZERO); + return (FP_SUBNORMAL); + } + if (u.bits.exp == 255) { + if (u.bits.man == 0) + return (FP_INFINITE); + return (FP_NAN); + } + return (FP_NORMAL); +} + +int +__fpclassifyd(double d) +{ + union IEEEd2bits u; + + u.d = d; + if (u.bits.exp == 0) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_ZERO); + return (FP_SUBNORMAL); + } + if (u.bits.exp == 2047) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_INFINITE); + return (FP_NAN); + } + return (FP_NORMAL); +} + +int +__fpclassifyl(long double e) +{ + union IEEEl2bits u; + + u.e = e; + if (u.bits.exp == 0) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_ZERO); + return (FP_SUBNORMAL); + } + mask_nbit_l(u); /* Mask normalization bit if applicable. */ + if (u.bits.exp == 32767) { + if ((u.bits.manl | u.bits.manh) == 0) + return (FP_INFINITE); + return (FP_NAN); + } + return (FP_NORMAL); +} diff --git a/src/lib/libc/gen/fstab.c b/src/lib/libc/gen/fstab.c new file mode 100644 index 0000000..33fc309 --- /dev/null +++ b/src/lib/libc/gen/fstab.c @@ -0,0 +1,298 @@ +/* + * Copyright (c) 1980, 1988, 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[] = "@(#)fstab.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/fstab.c,v 1.14 2003/04/07 12:55:00 mdodd Exp $"); + +#include "namespace.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +static FILE *_fs_fp; +static struct fstab _fs_fstab; +static int LineNo = 0; +static char *path_fstab; +static char fstab_path[PATH_MAX]; +static int fsp_set = 0; + +static void error(int); +static void fixfsfile(void); +static int fstabscan(void); + +void +setfstab(const char *file) +{ + + if (file == NULL) { + path_fstab = _PATH_FSTAB; + } else { + strncpy(fstab_path, file, PATH_MAX); + fstab_path[PATH_MAX - 1] = '\0'; + path_fstab = fstab_path; + } + fsp_set = 1; + + return; +} + +const char * +getfstab (void) +{ + + if (fsp_set) + return (path_fstab); + else + return (_PATH_FSTAB); +} + +static void +fixfsfile() +{ + static char buf[sizeof(_PATH_DEV) + MNAMELEN]; + struct stat sb; + struct statfs sf; + + if (strcmp(_fs_fstab.fs_file, "/") != 0) + return; + if (statfs("/", &sf) != 0) + return; + if (sf.f_mntfromname[0] == '/') + buf[0] = '\0'; + else + strcpy(buf, _PATH_DEV); + strcat(buf, sf.f_mntfromname); + if (stat(buf, &sb) != 0 || + (!S_ISBLK(sb.st_mode) && !S_ISCHR(sb.st_mode))) + return; + _fs_fstab.fs_spec = buf; +} + +static int +fstabscan() +{ + char *cp, *p; +#define MAXLINELENGTH 1024 + static char line[MAXLINELENGTH]; + char subline[MAXLINELENGTH]; + int typexx; + + for (;;) { + + if (!(p = fgets(line, sizeof(line), _fs_fp))) + return(0); +/* OLD_STYLE_FSTAB */ + ++LineNo; + if (*line == '#' || *line == '\n') + continue; + if (!strpbrk(p, " \t")) { + _fs_fstab.fs_spec = strsep(&p, ":\n"); + _fs_fstab.fs_file = strsep(&p, ":\n"); + fixfsfile(); + _fs_fstab.fs_type = strsep(&p, ":\n"); + if (_fs_fstab.fs_type) { + if (!strcmp(_fs_fstab.fs_type, FSTAB_XX)) + continue; + _fs_fstab.fs_mntops = _fs_fstab.fs_type; + _fs_fstab.fs_vfstype = + strcmp(_fs_fstab.fs_type, FSTAB_SW) ? + "ufs" : "swap"; + if ((cp = strsep(&p, ":\n")) != NULL) { + _fs_fstab.fs_freq = atoi(cp); + if ((cp = strsep(&p, ":\n")) != NULL) { + _fs_fstab.fs_passno = atoi(cp); + return(1); + } + } + } + goto bad; + } +/* OLD_STYLE_FSTAB */ + while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') + ; + _fs_fstab.fs_spec = cp; + if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#') + continue; + while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') + ; + _fs_fstab.fs_file = cp; + fixfsfile(); + while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') + ; + _fs_fstab.fs_vfstype = cp; + while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') + ; + _fs_fstab.fs_mntops = cp; + if (_fs_fstab.fs_mntops == NULL) + goto bad; + _fs_fstab.fs_freq = 0; + _fs_fstab.fs_passno = 0; + while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') + ; + if (cp != NULL) { + _fs_fstab.fs_freq = atoi(cp); + while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0') + ; + if (cp != NULL) + _fs_fstab.fs_passno = atoi(cp); + } + strcpy(subline, _fs_fstab.fs_mntops); + p = subline; + for (typexx = 0, cp = strsep(&p, ","); cp; + cp = strsep(&p, ",")) { + if (strlen(cp) != 2) + continue; + if (!strcmp(cp, FSTAB_RW)) { + _fs_fstab.fs_type = FSTAB_RW; + break; + } + if (!strcmp(cp, FSTAB_RQ)) { + _fs_fstab.fs_type = FSTAB_RQ; + break; + } + if (!strcmp(cp, FSTAB_RO)) { + _fs_fstab.fs_type = FSTAB_RO; + break; + } + if (!strcmp(cp, FSTAB_SW)) { + _fs_fstab.fs_type = FSTAB_SW; + break; + } + if (!strcmp(cp, FSTAB_XX)) { + _fs_fstab.fs_type = FSTAB_XX; + typexx++; + break; + } + } + if (typexx) + continue; + if (cp != NULL) + return(1); + +bad: /* no way to distinguish between EOF and syntax error */ + error(EFTYPE); + } + /* NOTREACHED */ +} + +struct fstab * +getfsent() +{ + if ((!_fs_fp && !setfsent()) || !fstabscan()) + return((struct fstab *)NULL); + return(&_fs_fstab); +} + +struct fstab * +getfsspec(name) + const char *name; +{ + if (setfsent()) + while (fstabscan()) + if (!strcmp(_fs_fstab.fs_spec, name)) + return(&_fs_fstab); + return((struct fstab *)NULL); +} + +struct fstab * +getfsfile(name) + const char *name; +{ + if (setfsent()) + while (fstabscan()) + if (!strcmp(_fs_fstab.fs_file, name)) + return(&_fs_fstab); + return((struct fstab *)NULL); +} + +int +setfsent() +{ + if (_fs_fp) { + rewind(_fs_fp); + LineNo = 0; + return(1); + } + if (fsp_set == 0) { + if (issetugid()) + setfstab(NULL); + else + setfstab(getenv("PATH_FSTAB")); + } + if ((_fs_fp = fopen(path_fstab, "r")) != NULL) { + LineNo = 0; + return(1); + } + error(errno); + return(0); +} + +void +endfsent() +{ + if (_fs_fp) { + (void)fclose(_fs_fp); + _fs_fp = NULL; + } + + fsp_set = 0; +} + +static void +error(err) + int err; +{ + char *p; + char num[30]; + + (void)_write(STDERR_FILENO, "fstab: ", 7); + (void)_write(STDERR_FILENO, path_fstab, strlen(path_fstab)); + (void)_write(STDERR_FILENO, ":", 1); + sprintf(num, "%d: ", LineNo); + (void)_write(STDERR_FILENO, num, strlen(num)); + p = strerror(err); + (void)_write(STDERR_FILENO, p, strlen(p)); + (void)_write(STDERR_FILENO, "\n", 1); +} diff --git a/src/lib/libc/gen/ftok.c b/src/lib/libc/gen/ftok.c new file mode 100644 index 0000000..9a5c72d --- /dev/null +++ b/src/lib/libc/gen/ftok.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1994 SigmaSoft, Th. Lockert + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/ftok.c,v 1.6 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include +#include + +key_t +ftok(path, id) + const char *path; + char id; +{ + struct stat st; + + if (stat(path, &st) < 0) + return (key_t)-1; + + return (key_t) (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff)); +} diff --git a/src/lib/libc/gen/fts.c b/src/lib/libc/gen/fts.c new file mode 100644 index 0000000..9ecec07 --- /dev/null +++ b/src/lib/libc/gen/fts.c @@ -0,0 +1,1228 @@ +/*- + * Copyright (c) 1990, 1993, 1994 + * 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. + * + * $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $ + */ + +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; +#endif /* LIBC_SCCS and not lint */ +#endif + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/fts.c,v 1.26 2004/05/13 15:59:38 bde Exp $"); + +#include "namespace.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +static FTSENT *fts_alloc(FTS *, char *, int); +static FTSENT *fts_build(FTS *, int); +static void fts_lfree(FTSENT *); +static void fts_load(FTS *, FTSENT *); +static size_t fts_maxarglen(char * const *); +static void fts_padjust(FTS *, FTSENT *); +static int fts_palloc(FTS *, size_t); +static FTSENT *fts_sort(FTS *, FTSENT *, int); +static u_short fts_stat(FTS *, FTSENT *, int); +static int fts_safe_changedir(FTS *, FTSENT *, int, char *); +static int fts_ufslinks(FTS *, const FTSENT *); + +#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) + +#define CLR(opt) (sp->fts_options &= ~(opt)) +#define ISSET(opt) (sp->fts_options & (opt)) +#define SET(opt) (sp->fts_options |= (opt)) + +#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) + +/* fts_build flags */ +#define BCHILD 1 /* fts_children */ +#define BNAMES 2 /* fts_children, names only */ +#define BREAD 3 /* fts_read */ + +/* + * Internal representation of an FTS, including extra implementation + * details. The FTS returned from fts_open points to this structure's + * ftsp_fts member (and can be cast to an _fts_private as required) + */ +struct _fts_private { + FTS ftsp_fts; + struct statfs ftsp_statfs; + dev_t ftsp_dev; + int ftsp_linksreliable; +}; + +/* + * The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it + * knows that a directory could not possibly have subdirectories. This + * is decided by looking at the link count: a subdirectory would + * increment its parent's link count by virtue of its own ".." entry. + * This assumption only holds for UFS-like filesystems that implement + * links and directories this way, so we must punt for others. + */ + +static const char *ufslike_filesystems[] = { + "ufs", + "nfs", + "nfs4", + "ext2fs", + 0 +}; + +FTS * +fts_open(argv, options, compar) + char * const *argv; + int options; + int (*compar)(const FTSENT * const *, const FTSENT * const *); +{ + struct _fts_private *priv; + FTS *sp; + FTSENT *p, *root; + int nitems; + FTSENT *parent, *tmp; + int len; + + /* Options check. */ + if (options & ~FTS_OPTIONMASK) { + errno = EINVAL; + return (NULL); + } + + /* Allocate/initialize the stream. */ + if ((priv = malloc(sizeof(*priv))) == NULL) + return (NULL); + memset(priv, 0, sizeof(*priv)); + sp = &priv->ftsp_fts; + sp->fts_compar = compar; + sp->fts_options = options; + + /* Shush, GCC. */ + tmp = NULL; + + /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ + if (ISSET(FTS_LOGICAL)) + SET(FTS_NOCHDIR); + + /* + * Start out with 1K of path space, and enough, in any case, + * to hold the user's paths. + */ + if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) + goto mem1; + + /* Allocate/initialize root's parent. */ + if ((parent = fts_alloc(sp, "", 0)) == NULL) + goto mem2; + parent->fts_level = FTS_ROOTPARENTLEVEL; + + /* Allocate/initialize root(s). */ + for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) { + /* Don't allow zero-length paths. */ + if ((len = strlen(*argv)) == 0) { + errno = ENOENT; + goto mem3; + } + + p = fts_alloc(sp, *argv, len); + p->fts_level = FTS_ROOTLEVEL; + p->fts_parent = parent; + p->fts_accpath = p->fts_name; + p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); + + /* Command-line "." and ".." are real directories. */ + if (p->fts_info == FTS_DOT) + p->fts_info = FTS_D; + + /* + * If comparison routine supplied, traverse in sorted + * order; otherwise traverse in the order specified. + */ + if (compar) { + p->fts_link = root; + root = p; + } else { + p->fts_link = NULL; + if (root == NULL) + tmp = root = p; + else { + tmp->fts_link = p; + tmp = p; + } + } + } + if (compar && nitems > 1) + root = fts_sort(sp, root, nitems); + + /* + * Allocate a dummy pointer and make fts_read think that we've just + * finished the node before the root(s); set p->fts_info to FTS_INIT + * so that everything about the "current" node is ignored. + */ + if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) + goto mem3; + sp->fts_cur->fts_link = root; + sp->fts_cur->fts_info = FTS_INIT; + + /* + * If using chdir(2), grab a file descriptor pointing to dot to ensure + * that we can get back here; this could be avoided for some paths, + * but almost certainly not worth the effort. Slashes, symbolic links, + * and ".." are all fairly nasty problems. Note, if we can't get the + * descriptor we run anyway, just more slowly. + */ + if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0) + SET(FTS_NOCHDIR); + + return (sp); + +mem3: fts_lfree(root); + free(parent); +mem2: free(sp->fts_path); +mem1: free(sp); + return (NULL); +} + +static void +fts_load(sp, p) + FTS *sp; + FTSENT *p; +{ + int len; + char *cp; + + /* + * Load the stream structure for the next traversal. Since we don't + * actually enter the directory until after the preorder visit, set + * the fts_accpath field specially so the chdir gets done to the right + * place and the user can access the first node. From fts_open it's + * known that the path will fit. + */ + len = p->fts_pathlen = p->fts_namelen; + memmove(sp->fts_path, p->fts_name, len + 1); + if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { + len = strlen(++cp); + memmove(p->fts_name, cp, len + 1); + p->fts_namelen = len; + } + p->fts_accpath = p->fts_path = sp->fts_path; + sp->fts_dev = p->fts_dev; +} + +int +fts_close(sp) + FTS *sp; +{ + FTSENT *freep, *p; + int saved_errno; + + /* + * This still works if we haven't read anything -- the dummy structure + * points to the root list, so we step through to the end of the root + * list which has a valid parent pointer. + */ + if (sp->fts_cur) { + for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { + freep = p; + p = p->fts_link != NULL ? p->fts_link : p->fts_parent; + free(freep); + } + free(p); + } + + /* Free up child linked list, sort array, path buffer. */ + if (sp->fts_child) + fts_lfree(sp->fts_child); + if (sp->fts_array) + free(sp->fts_array); + free(sp->fts_path); + + /* Return to original directory, save errno if necessary. */ + if (!ISSET(FTS_NOCHDIR)) { + saved_errno = fchdir(sp->fts_rfd) ? errno : 0; + (void)_close(sp->fts_rfd); + + /* Set errno and return. */ + if (saved_errno != 0) { + /* Free up the stream pointer. */ + free(sp); + errno = saved_errno; + return (-1); + } + } + + /* Free up the stream pointer. */ + free(sp); + return (0); +} + +/* + * Special case of "/" at the end of the path so that slashes aren't + * appended which would cause paths to be written as "....//foo". + */ +#define NAPPEND(p) \ + (p->fts_path[p->fts_pathlen - 1] == '/' \ + ? p->fts_pathlen - 1 : p->fts_pathlen) + +FTSENT * +fts_read(sp) + FTS *sp; +{ + FTSENT *p, *tmp; + int instr; + char *t; + int saved_errno; + + /* If finished or unrecoverable error, return NULL. */ + if (sp->fts_cur == NULL || ISSET(FTS_STOP)) + return (NULL); + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* Save and zero out user instructions. */ + instr = p->fts_instr; + p->fts_instr = FTS_NOINSTR; + + /* Any type of file may be re-visited; re-stat and re-turn. */ + if (instr == FTS_AGAIN) { + p->fts_info = fts_stat(sp, p, 0); + return (p); + } + + /* + * Following a symlink -- SLNONE test allows application to see + * SLNONE and recover. If indirecting through a symlink, have + * keep a pointer to current location. If unable to get that + * pointer, follow fails. + */ + if (instr == FTS_FOLLOW && + (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { + p->fts_info = fts_stat(sp, p, 1); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { + if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + } + return (p); + } + + /* Directory in pre-order. */ + if (p->fts_info == FTS_D) { + /* If skipped or crossed mount point, do post-order visit. */ + if (instr == FTS_SKIP || + (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { + if (p->fts_flags & FTS_SYMFOLLOW) + (void)_close(p->fts_symfd); + if (sp->fts_child) { + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + p->fts_info = FTS_DP; + return (p); + } + + /* Rebuild if only read the names and now traversing. */ + if (sp->fts_child != NULL && ISSET(FTS_NAMEONLY)) { + CLR(FTS_NAMEONLY); + fts_lfree(sp->fts_child); + sp->fts_child = NULL; + } + + /* + * Cd to the subdirectory. + * + * If have already read and now fail to chdir, whack the list + * to make the names come out right, and set the parent errno + * so the application will eventually get an error condition. + * Set the FTS_DONTCHDIR flag so that when we logically change + * directories back to the parent we don't do a chdir. + * + * If haven't read do so. If the read fails, fts_build sets + * FTS_STOP or the fts_info field of the node. + */ + if (sp->fts_child != NULL) { + if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { + p->fts_errno = errno; + p->fts_flags |= FTS_DONTCHDIR; + for (p = sp->fts_child; p != NULL; + p = p->fts_link) + p->fts_accpath = + p->fts_parent->fts_accpath; + } + } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { + if (ISSET(FTS_STOP)) + return (NULL); + return (p); + } + p = sp->fts_child; + sp->fts_child = NULL; + goto name; + } + + /* Move to the next node on this level. */ +next: tmp = p; + if ((p = p->fts_link) != NULL) { + free(tmp); + + /* + * If reached the top, return to the original directory (or + * the root of the tree), and load the paths for the next root. + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } + fts_load(sp, p); + return (sp->fts_cur = p); + } + + /* + * User may have called fts_set on the node. If skipped, + * ignore. If followed, get a file descriptor so we can + * get back if necessary. + */ + if (p->fts_instr == FTS_SKIP) + goto next; + if (p->fts_instr == FTS_FOLLOW) { + p->fts_info = fts_stat(sp, p, 1); + if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { + if ((p->fts_symfd = + _open(".", O_RDONLY, 0)) < 0) { + p->fts_errno = errno; + p->fts_info = FTS_ERR; + } else + p->fts_flags |= FTS_SYMFOLLOW; + } + p->fts_instr = FTS_NOINSTR; + } + +name: t = sp->fts_path + NAPPEND(p->fts_parent); + *t++ = '/'; + memmove(t, p->fts_name, p->fts_namelen + 1); + return (sp->fts_cur = p); + } + + /* Move up to the parent node. */ + p = tmp->fts_parent; + free(tmp); + + if (p->fts_level == FTS_ROOTPARENTLEVEL) { + /* + * Done; free everything up and set errno to 0 so the user + * can distinguish between error and EOF. + */ + free(p); + errno = 0; + return (sp->fts_cur = NULL); + } + + /* NUL terminate the pathname. */ + sp->fts_path[p->fts_pathlen] = '\0'; + + /* + * Return to the parent directory. If at a root node or came through + * a symlink, go back through the file descriptor. Otherwise, cd up + * one directory. + */ + if (p->fts_level == FTS_ROOTLEVEL) { + if (FCHDIR(sp, sp->fts_rfd)) { + SET(FTS_STOP); + return (NULL); + } + } else if (p->fts_flags & FTS_SYMFOLLOW) { + if (FCHDIR(sp, p->fts_symfd)) { + saved_errno = errno; + (void)_close(p->fts_symfd); + errno = saved_errno; + SET(FTS_STOP); + return (NULL); + } + (void)_close(p->fts_symfd); + } else if (!(p->fts_flags & FTS_DONTCHDIR) && + fts_safe_changedir(sp, p->fts_parent, -1, "..")) { + SET(FTS_STOP); + return (NULL); + } + p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; + return (sp->fts_cur = p); +} + +/* + * Fts_set takes the stream as an argument although it's not used in this + * implementation; it would be necessary if anyone wanted to add global + * semantics to fts using fts_set. An error return is allowed for similar + * reasons. + */ +/* ARGSUSED */ +int +fts_set(sp, p, instr) + FTS *sp; + FTSENT *p; + int instr; +{ + if (instr != 0 && instr != FTS_AGAIN && instr != FTS_FOLLOW && + instr != FTS_NOINSTR && instr != FTS_SKIP) { + errno = EINVAL; + return (1); + } + p->fts_instr = instr; + return (0); +} + +FTSENT * +fts_children(sp, instr) + FTS *sp; + int instr; +{ + FTSENT *p; + int fd; + + if (instr != 0 && instr != FTS_NAMEONLY) { + errno = EINVAL; + return (NULL); + } + + /* Set current node pointer. */ + p = sp->fts_cur; + + /* + * Errno set to 0 so user can distinguish empty directory from + * an error. + */ + errno = 0; + + /* Fatal errors stop here. */ + if (ISSET(FTS_STOP)) + return (NULL); + + /* Return logical hierarchy of user's arguments. */ + if (p->fts_info == FTS_INIT) + return (p->fts_link); + + /* + * If not a directory being visited in pre-order, stop here. Could + * allow FTS_DNR, assuming the user has fixed the problem, but the + * same effect is available with FTS_AGAIN. + */ + if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) + return (NULL); + + /* Free up any previous child list. */ + if (sp->fts_child != NULL) + fts_lfree(sp->fts_child); + + if (instr == FTS_NAMEONLY) { + SET(FTS_NAMEONLY); + instr = BNAMES; + } else + instr = BCHILD; + + /* + * If using chdir on a relative path and called BEFORE fts_read does + * its chdir to the root of a traversal, we can lose -- we need to + * chdir into the subdirectory, and we don't know where the current + * directory is, so we can't get back so that the upcoming chdir by + * fts_read will work. + */ + if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || + ISSET(FTS_NOCHDIR)) + return (sp->fts_child = fts_build(sp, instr)); + + if ((fd = _open(".", O_RDONLY, 0)) < 0) + return (NULL); + sp->fts_child = fts_build(sp, instr); + if (fchdir(fd)) + return (NULL); + (void)_close(fd); + return (sp->fts_child); +} + +#ifndef fts_get_clientptr +#error "fts_get_clientptr not defined" +#endif + +void * +(fts_get_clientptr)(FTS *sp) +{ + + return (fts_get_clientptr(sp)); +} + +#ifndef fts_get_stream +#error "fts_get_stream not defined" +#endif + +FTS * +(fts_get_stream)(FTSENT *p) +{ + return (fts_get_stream(p)); +} + +void +fts_set_clientptr(FTS *sp, void *clientptr) +{ + + sp->fts_clientptr = clientptr; +} + +/* + * This is the tricky part -- do not casually change *anything* in here. The + * idea is to build the linked list of entries that are used by fts_children + * and fts_read. There are lots of special cases. + * + * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is + * set and it's a physical walk (so that symbolic links can't be directories), + * we can do things quickly. First, if it's a 4.4BSD file system, the type + * of the file is in the directory entry. Otherwise, we assume that the number + * of subdirectories in a node is equal to the number of links to the parent. + * The former skips all stat calls. The latter skips stat calls in any leaf + * directories and for any files after the subdirectories in the directory have + * been found, cutting the stat calls by about 2/3. + */ +static FTSENT * +fts_build(sp, type) + FTS *sp; + int type; +{ + struct dirent *dp; + FTSENT *p, *head; + int nitems; + FTSENT *cur, *tail; + DIR *dirp; + void *oldaddr; + size_t dnamlen; + int cderrno, descend, len, level, maxlen, nlinks, oflag, saved_errno, + nostat, doadjust; + char *cp; + + /* Set current node pointer. */ + cur = sp->fts_cur; + + /* + * Open the directory for reading. If this fails, we're done. + * If being called from fts_read, set the fts_info field. + */ +#ifdef FTS_WHITEOUT + if (ISSET(FTS_WHITEOUT)) + oflag = DTF_NODUP | DTF_REWIND; + else + oflag = DTF_HIDEW | DTF_NODUP | DTF_REWIND; +#else +#define __opendir2(path, flag) opendir(path) +#endif + if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { + if (type == BREAD) { + cur->fts_info = FTS_DNR; + cur->fts_errno = errno; + } + return (NULL); + } + + /* + * Nlinks is the number of possible entries of type directory in the + * directory if we're cheating on stat calls, 0 if we're not doing + * any stat calls at all, -1 if we're doing stats on everything. + */ + if (type == BNAMES) { + nlinks = 0; + /* Be quiet about nostat, GCC. */ + nostat = 0; + } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { + if (fts_ufslinks(sp, cur)) + nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); + else + nlinks = -1; + nostat = 1; + } else { + nlinks = -1; + nostat = 0; + } + +#ifdef notdef + (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); + (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", + ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); +#endif + /* + * If we're going to need to stat anything or we want to descend + * and stay in the directory, chdir. If this fails we keep going, + * but set a flag so we don't chdir after the post-order visit. + * We won't be able to stat anything, but we can still return the + * names themselves. Note, that since fts_read won't be able to + * chdir into the directory, it will have to return different path + * names than before, i.e. "a/b" instead of "b". Since the node + * has already been visited in pre-order, have to wait until the + * post-order visit to return the error. There is a special case + * here, if there was nothing to stat then it's not an error to + * not be able to stat. This is all fairly nasty. If a program + * needed sorted entries or stat information, they had better be + * checking FTS_NS on the returned nodes. + */ + cderrno = 0; + if (nlinks || type == BREAD) { + if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { + if (nlinks && type == BREAD) + cur->fts_errno = errno; + cur->fts_flags |= FTS_DONTCHDIR; + descend = 0; + cderrno = errno; + (void)closedir(dirp); + dirp = NULL; + } else + descend = 1; + } else + descend = 0; + + /* + * Figure out the max file name length that can be stored in the + * current path -- the inner loop allocates more path as necessary. + * We really wouldn't have to do the maxlen calculations here, we + * could do them in fts_read before returning the path, but it's a + * lot easier here since the length is part of the dirent structure. + * + * If not changing directories set a pointer so that can just append + * each new name into the path. + */ + len = NAPPEND(cur); + if (ISSET(FTS_NOCHDIR)) { + cp = sp->fts_path + len; + *cp++ = '/'; + } else { + /* GCC, you're too verbose. */ + cp = NULL; + } + len++; + maxlen = sp->fts_pathlen - len; + + level = cur->fts_level + 1; + + /* Read the directory, attaching each entry to the `link' pointer. */ + doadjust = 0; + for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { + dnamlen = dp->d_namlen; + if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) + continue; + + if ((p = fts_alloc(sp, dp->d_name, (int)dnamlen)) == NULL) + goto mem1; + if (dnamlen >= maxlen) { /* include space for NUL */ + oldaddr = sp->fts_path; + if (fts_palloc(sp, dnamlen + len + 1)) { + /* + * No more memory for path or structures. Save + * errno, free up the current structure and the + * structures already allocated. + */ +mem1: saved_errno = errno; + if (p) + free(p); + fts_lfree(head); + (void)closedir(dirp); + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + errno = saved_errno; + return (NULL); + } + /* Did realloc() change the pointer? */ + if (oldaddr != sp->fts_path) { + doadjust = 1; + if (ISSET(FTS_NOCHDIR)) + cp = sp->fts_path + len; + } + maxlen = sp->fts_pathlen - len; + } + + if (len + dnamlen >= USHRT_MAX) { + /* + * In an FTSENT, fts_pathlen is a u_short so it is + * possible to wraparound here. If we do, free up + * the current structure and the structures already + * allocated, then error out with ENAMETOOLONG. + */ + free(p); + fts_lfree(head); + (void)closedir(dirp); + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + errno = ENAMETOOLONG; + return (NULL); + } + p->fts_level = level; + p->fts_parent = sp->fts_cur; + p->fts_pathlen = len + dnamlen; + +#ifdef FTS_WHITEOUT + if (dp->d_type == DT_WHT) + p->fts_flags |= FTS_ISW; +#endif + + if (cderrno) { + if (nlinks) { + p->fts_info = FTS_NS; + p->fts_errno = cderrno; + } else + p->fts_info = FTS_NSOK; + p->fts_accpath = cur->fts_accpath; + } else if (nlinks == 0 +#ifdef DT_DIR + || (nostat && + dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) +#endif + ) { + p->fts_accpath = + ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; + p->fts_info = FTS_NSOK; + } else { + /* Build a file name for fts_stat to stat. */ + if (ISSET(FTS_NOCHDIR)) { + p->fts_accpath = p->fts_path; + memmove(cp, p->fts_name, p->fts_namelen + 1); + } else + p->fts_accpath = p->fts_name; + /* Stat it. */ + p->fts_info = fts_stat(sp, p, 0); + + /* Decrement link count if applicable. */ + if (nlinks > 0 && (p->fts_info == FTS_D || + p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) + --nlinks; + } + + /* We walk in directory order so "ls -f" doesn't get upset. */ + p->fts_link = NULL; + if (head == NULL) + head = tail = p; + else { + tail->fts_link = p; + tail = p; + } + ++nitems; + } + if (dirp) + (void)closedir(dirp); + + /* + * If realloc() changed the address of the path, adjust the + * addresses for the rest of the tree and the dir list. + */ + if (doadjust) + fts_padjust(sp, head); + + /* + * If not changing directories, reset the path back to original + * state. + */ + if (ISSET(FTS_NOCHDIR)) { + if (len == sp->fts_pathlen || nitems == 0) + --cp; + *cp = '\0'; + } + + /* + * If descended after called from fts_children or after called from + * fts_read and nothing found, get back. At the root level we use + * the saved fd; if one of fts_open()'s arguments is a relative path + * to an empty directory, we wind up here with no other way back. If + * can't get back, we're done. + */ + if (descend && (type == BCHILD || !nitems) && + (cur->fts_level == FTS_ROOTLEVEL ? + FCHDIR(sp, sp->fts_rfd) : + fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { + cur->fts_info = FTS_ERR; + SET(FTS_STOP); + return (NULL); + } + + /* If didn't find anything, return NULL. */ + if (!nitems) { + if (type == BREAD) + cur->fts_info = FTS_DP; + return (NULL); + } + + /* Sort the entries. */ + if (sp->fts_compar && nitems > 1) + head = fts_sort(sp, head, nitems); + return (head); +} + +static u_short +fts_stat(sp, p, follow) + FTS *sp; + FTSENT *p; + int follow; +{ + FTSENT *t; + dev_t dev; + ino_t ino; + struct stat *sbp, sb; + int saved_errno; + + /* If user needs stat info, stat buffer already allocated. */ + sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; + +#ifdef FTS_WHITEOUT + /* Check for whiteout. */ + if (p->fts_flags & FTS_ISW) { + if (sbp != &sb) { + memset(sbp, '\0', sizeof(*sbp)); + sbp->st_mode = S_IFWHT; + } + return (FTS_W); + } +#endif + + /* + * If doing a logical walk, or application requested FTS_FOLLOW, do + * a stat(2). If that fails, check for a non-existent symlink. If + * fail, set the errno from the stat call. + */ + if (ISSET(FTS_LOGICAL) || follow) { + if (stat(p->fts_accpath, sbp)) { + saved_errno = errno; + if (!lstat(p->fts_accpath, sbp)) { + errno = 0; + return (FTS_SLNONE); + } + p->fts_errno = saved_errno; + goto err; + } + } else if (lstat(p->fts_accpath, sbp)) { + p->fts_errno = errno; +err: memset(sbp, 0, sizeof(struct stat)); + return (FTS_NS); + } + + if (S_ISDIR(sbp->st_mode)) { + /* + * Set the device/inode. Used to find cycles and check for + * crossing mount points. Also remember the link count, used + * in fts_build to limit the number of stat calls. It is + * understood that these fields are only referenced if fts_info + * is set to FTS_D. + */ + dev = p->fts_dev = sbp->st_dev; + ino = p->fts_ino = sbp->st_ino; + p->fts_nlink = sbp->st_nlink; + + if (ISDOT(p->fts_name)) + return (FTS_DOT); + + /* + * Cycle detection is done by brute force when the directory + * is first encountered. If the tree gets deep enough or the + * number of symbolic links to directories is high enough, + * something faster might be worthwhile. + */ + for (t = p->fts_parent; + t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) + if (ino == t->fts_ino && dev == t->fts_dev) { + p->fts_cycle = t; + return (FTS_DC); + } + return (FTS_D); + } + if (S_ISLNK(sbp->st_mode)) + return (FTS_SL); + if (S_ISREG(sbp->st_mode)) + return (FTS_F); + return (FTS_DEFAULT); +} + +/* + * The comparison function takes pointers to pointers to FTSENT structures. + * Qsort wants a comparison function that takes pointers to void. + * (Both with appropriate levels of const-poisoning, of course!) + * Use a trampoline function to deal with the difference. + */ +static int +fts_compar(const void *a, const void *b) +{ + FTS *parent; + + parent = (*(const FTSENT * const *)a)->fts_fts; + return (*parent->fts_compar)(a, b); +} + +static FTSENT * +fts_sort(sp, head, nitems) + FTS *sp; + FTSENT *head; + int nitems; +{ + FTSENT **ap, *p; + + /* + * Construct an array of pointers to the structures and call qsort(3). + * Reassemble the array in the order returned by qsort. If unable to + * sort for memory reasons, return the directory entries in their + * current order. Allocate enough space for the current needs plus + * 40 so don't realloc one entry at a time. + */ + if (nitems > sp->fts_nitems) { + sp->fts_nitems = nitems + 40; + if ((sp->fts_array = reallocf(sp->fts_array, + sp->fts_nitems * sizeof(FTSENT *))) == NULL) { + sp->fts_nitems = 0; + return (head); + } + } + for (ap = sp->fts_array, p = head; p; p = p->fts_link) + *ap++ = p; + qsort(sp->fts_array, nitems, sizeof(FTSENT *), fts_compar); + for (head = *(ap = sp->fts_array); --nitems; ++ap) + ap[0]->fts_link = ap[1]; + ap[0]->fts_link = NULL; + return (head); +} + +static FTSENT * +fts_alloc(sp, name, namelen) + FTS *sp; + char *name; + int namelen; +{ + FTSENT *p; + size_t len; + + struct ftsent_withstat { + FTSENT ent; + struct stat statbuf; + }; + + /* + * The file name is a variable length array and no stat structure is + * necessary if the user has set the nostat bit. Allocate the FTSENT + * structure, the file name and the stat structure in one chunk, but + * be careful that the stat structure is reasonably aligned. + */ + if (ISSET(FTS_NOSTAT)) + len = sizeof(FTSENT) + namelen + 1; + else + len = sizeof(struct ftsent_withstat) + namelen + 1; + + if ((p = malloc(len)) == NULL) + return (NULL); + + if (ISSET(FTS_NOSTAT)) { + p->fts_name = (char *)(p + 1); + p->fts_statp = NULL; + } else { + p->fts_name = (char *)((struct ftsent_withstat *)p + 1); + p->fts_statp = &((struct ftsent_withstat *)p)->statbuf; + } + + /* Copy the name and guarantee NUL termination. */ + memcpy(p->fts_name, name, namelen); + p->fts_name[namelen] = '\0'; + p->fts_namelen = namelen; + p->fts_path = sp->fts_path; + p->fts_errno = 0; + p->fts_flags = 0; + p->fts_instr = FTS_NOINSTR; + p->fts_number = 0; + p->fts_pointer = NULL; + p->fts_fts = sp; + return (p); +} + +static void +fts_lfree(head) + FTSENT *head; +{ + FTSENT *p; + + /* Free a linked list of structures. */ + while ((p = head)) { + head = head->fts_link; + free(p); + } +} + +/* + * Allow essentially unlimited paths; find, rm, ls should all work on any tree. + * Most systems will allow creation of paths much longer than MAXPATHLEN, even + * though the kernel won't resolve them. Add the size (not just what's needed) + * plus 256 bytes so don't realloc the path 2 bytes at a time. + */ +static int +fts_palloc(sp, more) + FTS *sp; + size_t more; +{ + + sp->fts_pathlen += more + 256; + /* + * Check for possible wraparound. In an FTS, fts_pathlen is + * a signed int but in an FTSENT it is an unsigned short. + * We limit fts_pathlen to USHRT_MAX to be safe in both cases. + */ + if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) { + if (sp->fts_path) + free(sp->fts_path); + sp->fts_path = NULL; + errno = ENAMETOOLONG; + return (1); + } + sp->fts_path = reallocf(sp->fts_path, sp->fts_pathlen); + return (sp->fts_path == NULL); +} + +/* + * When the path is realloc'd, have to fix all of the pointers in structures + * already returned. + */ +static void +fts_padjust(sp, head) + FTS *sp; + FTSENT *head; +{ + FTSENT *p; + char *addr = sp->fts_path; + +#define ADJUST(p) do { \ + if ((p)->fts_accpath != (p)->fts_name) { \ + (p)->fts_accpath = \ + (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ + } \ + (p)->fts_path = addr; \ +} while (0) + /* Adjust the current set of children. */ + for (p = sp->fts_child; p; p = p->fts_link) + ADJUST(p); + + /* Adjust the rest of the tree, including the current level. */ + for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { + ADJUST(p); + p = p->fts_link ? p->fts_link : p->fts_parent; + } +} + +static size_t +fts_maxarglen(argv) + char * const *argv; +{ + size_t len, max; + + for (max = 0; *argv; ++argv) + if ((len = strlen(*argv)) > max) + max = len; + return (max + 1); +} + +/* + * Change to dir specified by fd or p->fts_accpath without getting + * tricked by someone changing the world out from underneath us. + * Assumes p->fts_dev and p->fts_ino are filled in. + */ +static int +fts_safe_changedir(sp, p, fd, path) + FTS *sp; + FTSENT *p; + int fd; + char *path; +{ + int ret, oerrno, newfd; + struct stat sb; + + newfd = fd; + if (ISSET(FTS_NOCHDIR)) + return (0); + if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0) + return (-1); + if (_fstat(newfd, &sb)) { + ret = -1; + goto bail; + } + if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) { + errno = ENOENT; /* disinformation */ + ret = -1; + goto bail; + } + ret = fchdir(newfd); +bail: + oerrno = errno; + if (fd < 0) + (void)_close(newfd); + errno = oerrno; + return (ret); +} + +/* + * Check if the filesystem for "ent" has UFS-style links. + */ +static int +fts_ufslinks(FTS *sp, const FTSENT *ent) +{ + struct _fts_private *priv; + const char **cpp; + + priv = (struct _fts_private *)sp; + /* + * If this node's device is different from the previous, grab + * the filesystem information, and decide on the reliability + * of the link information from this filesystem for stat(2) + * avoidance. + */ + if (priv->ftsp_dev != ent->fts_dev) { + if (statfs(ent->fts_path, &priv->ftsp_statfs) != -1) { + priv->ftsp_dev = ent->fts_dev; + priv->ftsp_linksreliable = 0; + for (cpp = ufslike_filesystems; *cpp; cpp++) { + if (strcmp(priv->ftsp_statfs.f_fstypename, + *cpp) == 0) { + priv->ftsp_linksreliable = 1; + break; + } + } + } else { + priv->ftsp_linksreliable = 0; + } + } + return (priv->ftsp_linksreliable); +} diff --git a/src/lib/libc/gen/getbootfile.c b/src/lib/libc/gen/getbootfile.c new file mode 100644 index 0000000..6acbb95 --- /dev/null +++ b/src/lib/libc/gen/getbootfile.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1989, 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[] = "From: @(#)gethostname.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getbootfile.c,v 1.7 2003/04/11 13:54:28 tjr Exp $"); + +#include +#include + +const char * +getbootfile(void) +{ + static char name[MAXPATHLEN]; + size_t size = sizeof name; + int mib[2]; + + mib[0] = CTL_KERN; + mib[1] = KERN_BOOTFILE; + if (sysctl(mib, 2, name, &size, NULL, 0) == -1) + return ("/boot/kernel/kernel"); + return (name); +} diff --git a/src/lib/libc/gen/getbsize.c b/src/lib/libc/gen/getbsize.c new file mode 100644 index 0000000..b922f1c --- /dev/null +++ b/src/lib/libc/gen/getbsize.c @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 1991, 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[] = "@(#)getbsize.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getbsize.c,v 1.7 2002/12/30 19:04:06 obrien Exp $"); + +#include +#include +#include +#include + +char * +getbsize(headerlenp, blocksizep) + int *headerlenp; + long *blocksizep; +{ + static char header[20]; + long n, max, mul, blocksize; + char *ep, *p; + const char *form; + +#define KB (1024L) +#define MB (1024L * 1024L) +#define GB (1024L * 1024L * 1024L) +#define MAXB GB /* No tera, peta, nor exa. */ + form = ""; + if ((p = getenv("BLOCKSIZE")) != NULL && *p != '\0') { + if ((n = strtol(p, &ep, 10)) < 0) + goto underflow; + if (n == 0) + n = 1; + if (*ep && ep[1]) + goto fmterr; + switch (*ep) { + case 'G': case 'g': + form = "G"; + max = MAXB / GB; + mul = GB; + break; + case 'K': case 'k': + form = "K"; + max = MAXB / KB; + mul = KB; + break; + case 'M': case 'm': + form = "M"; + max = MAXB / MB; + mul = MB; + break; + case '\0': + max = MAXB; + mul = 1; + break; + default: +fmterr: warnx("%s: unknown blocksize", p); + n = 512; + mul = 1; + break; + } + if (n > max) { + warnx("maximum blocksize is %ldG", MAXB / GB); + n = max; + } + if ((blocksize = n * mul) < 512) { +underflow: warnx("minimum blocksize is 512"); + form = ""; + blocksize = n = 512; + } + } else + blocksize = n = 512; + + (void)snprintf(header, sizeof(header), "%ld%s-blocks", n, form); + *headerlenp = strlen(header); + *blocksizep = blocksize; + return (header); +} diff --git a/src/lib/libc/gen/getcap.c b/src/lib/libc/gen/getcap.c new file mode 100644 index 0000000..3cf07fa --- /dev/null +++ b/src/lib/libc/gen/getcap.c @@ -0,0 +1,1058 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Casey Leedom of Lawrence Livermore National Laboratory. + * + * 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[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getcap.c,v 1.19 2003/01/02 10:19:43 thomas Exp $"); + +#include "namespace.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include + +#define BFRAG 1024 +#define BSIZE 1024 +#define ESC ('[' & 037) /* ASCII ESC */ +#define MAX_RECURSION 32 /* maximum getent recursion */ +#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */ + +#define RECOK (char)0 +#define TCERR (char)1 +#define SHADOW (char)2 + +static size_t topreclen; /* toprec length */ +static char *toprec; /* Additional record specified by cgetset() */ +static int gottoprec; /* Flag indicating retrieval of toprecord */ + +static int cdbget(DB *, char **, const char *); +static int getent(char **, u_int *, char **, int, const char *, int, char *); +static int nfcmp(char *, char *); + +/* + * Cgetset() allows the addition of a user specified buffer to be added + * to the database array, in effect "pushing" the buffer on top of the + * virtual database. 0 is returned on success, -1 on failure. + */ +int +cgetset(const char *ent) +{ + if (ent == NULL) { + if (toprec) + free(toprec); + toprec = NULL; + topreclen = 0; + return (0); + } + topreclen = strlen(ent); + if ((toprec = malloc (topreclen + 1)) == NULL) { + errno = ENOMEM; + return (-1); + } + gottoprec = 0; + (void)strcpy(toprec, ent); + return (0); +} + +/* + * Cgetcap searches the capability record buf for the capability cap with + * type `type'. A pointer to the value of cap is returned on success, NULL + * if the requested capability couldn't be found. + * + * Specifying a type of ':' means that nothing should follow cap (:cap:). + * In this case a pointer to the terminating ':' or NUL will be returned if + * cap is found. + * + * If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator) + * return NULL. + */ +char * +cgetcap(char *buf, const char *cap, int type) +{ + char *bp; + const char *cp; + + bp = buf; + for (;;) { + /* + * Skip past the current capability field - it's either the + * name field if this is the first time through the loop, or + * the remainder of a field whose name failed to match cap. + */ + for (;;) + if (*bp == '\0') + return (NULL); + else + if (*bp++ == ':') + break; + + /* + * Try to match (cap, type) in buf. + */ + for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++) + continue; + if (*cp != '\0') + continue; + if (*bp == '@') + return (NULL); + if (type == ':') { + if (*bp != '\0' && *bp != ':') + continue; + return(bp); + } + if (*bp != type) + continue; + bp++; + return (*bp == '@' ? NULL : bp); + } + /* NOTREACHED */ +} + +/* + * Cgetent extracts the capability record name from the NULL terminated file + * array db_array and returns a pointer to a malloc'd copy of it in buf. + * Buf must be retained through all subsequent calls to cgetcap, cgetnum, + * cgetflag, and cgetstr, but may then be free'd. 0 is returned on success, + * -1 if the requested record couldn't be found, -2 if a system error was + * encountered (couldn't open/read a file, etc.), and -3 if a potential + * reference loop is detected. + */ +int +cgetent(char **buf, char **db_array, const char *name) +{ + u_int dummy; + + return (getent(buf, &dummy, db_array, -1, name, 0, NULL)); +} + +/* + * Getent implements the functions of cgetent. If fd is non-negative, + * *db_array has already been opened and fd is the open file descriptor. We + * do this to save time and avoid using up file descriptors for tc= + * recursions. + * + * Getent returns the same success/failure codes as cgetent. On success, a + * pointer to a malloc'ed capability record with all tc= capabilities fully + * expanded and its length (not including trailing ASCII NUL) are left in + * *cap and *len. + * + * Basic algorithm: + * + Allocate memory incrementally as needed in chunks of size BFRAG + * for capability buffer. + * + Recurse for each tc=name and interpolate result. Stop when all + * names interpolated, a name can't be found, or depth exceeds + * MAX_RECURSION. + */ +static int +getent(char **cap, u_int *len, char **db_array, int fd, const char *name, + int depth, char *nfield) +{ + DB *capdbp; + char *r_end, *rp, **db_p; + int myfd, eof, foundit, retval, clen; + char *record, *cbuf; + int tc_not_resolved; + char pbuf[_POSIX_PATH_MAX]; + + /* + * Return with ``loop detected'' error if we've recursed more than + * MAX_RECURSION times. + */ + if (depth > MAX_RECURSION) + return (-3); + + /* + * Check if we have a top record from cgetset(). + */ + if (depth == 0 && toprec != NULL && cgetmatch(toprec, name) == 0) { + if ((record = malloc (topreclen + BFRAG)) == NULL) { + errno = ENOMEM; + return (-2); + } + (void)strcpy(record, toprec); + myfd = 0; + db_p = db_array; + rp = record + topreclen + 1; + r_end = rp + BFRAG; + goto tc_exp; + } + /* + * Allocate first chunk of memory. + */ + if ((record = malloc(BFRAG)) == NULL) { + errno = ENOMEM; + return (-2); + } + r_end = record + BFRAG; + foundit = 0; + /* + * Loop through database array until finding the record. + */ + + for (db_p = db_array; *db_p != NULL; db_p++) { + eof = 0; + + /* + * Open database if not already open. + */ + + if (fd >= 0) { + (void)lseek(fd, (off_t)0, SEEK_SET); + myfd = 0; + } else { + (void)snprintf(pbuf, sizeof(pbuf), "%s.db", *db_p); + if ((capdbp = dbopen(pbuf, O_RDONLY, 0, DB_HASH, 0)) + != NULL) { + free(record); + retval = cdbget(capdbp, &record, name); + if (retval < 0) { + /* no record available */ + (void)capdbp->close(capdbp); + return (retval); + } + /* save the data; close frees it */ + clen = strlen(record); + cbuf = malloc(clen + 1); + memcpy(cbuf, record, clen + 1); + if (capdbp->close(capdbp) < 0) { + free(cbuf); + return (-2); + } + *len = clen; + *cap = cbuf; + return (retval); + } else { + fd = _open(*db_p, O_RDONLY, 0); + if (fd < 0) + continue; + myfd = 1; + } + } + /* + * Find the requested capability record ... + */ + { + char buf[BUFSIZ]; + char *b_end, *bp; + int c; + + /* + * Loop invariants: + * There is always room for one more character in record. + * R_end always points just past end of record. + * Rp always points just past last character in record. + * B_end always points just past last character in buf. + * Bp always points at next character in buf. + */ + b_end = buf; + bp = buf; + for (;;) { + + /* + * Read in a line implementing (\, newline) + * line continuation. + */ + rp = record; + for (;;) { + if (bp >= b_end) { + int n; + + n = _read(fd, buf, sizeof(buf)); + if (n <= 0) { + if (myfd) + (void)_close(fd); + if (n < 0) { + free(record); + return (-2); + } else { + fd = -1; + eof = 1; + break; + } + } + b_end = buf+n; + bp = buf; + } + + c = *bp++; + if (c == '\n') { + if (rp > record && *(rp-1) == '\\') { + rp--; + continue; + } else + break; + } + *rp++ = c; + + /* + * Enforce loop invariant: if no room + * left in record buffer, try to get + * some more. + */ + if (rp >= r_end) { + u_int pos; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + BFRAG; + record = reallocf(record, newsize); + if (record == NULL) { + errno = ENOMEM; + if (myfd) + (void)_close(fd); + return (-2); + } + r_end = record + newsize; + rp = record + pos; + } + } + /* loop invariant let's us do this */ + *rp++ = '\0'; + + /* + * If encountered eof check next file. + */ + if (eof) + break; + + /* + * Toss blank lines and comments. + */ + if (*record == '\0' || *record == '#') + continue; + + /* + * See if this is the record we want ... + */ + if (cgetmatch(record, name) == 0) { + if (nfield == NULL || !nfcmp(nfield, record)) { + foundit = 1; + break; /* found it! */ + } + } + } + } + if (foundit) + break; + } + + if (!foundit) { + free(record); + return (-1); + } + + /* + * Got the capability record, but now we have to expand all tc=name + * references in it ... + */ +tc_exp: { + char *newicap, *s; + int newilen; + u_int ilen; + int diff, iret, tclen; + char *icap, *scan, *tc, *tcstart, *tcend; + + /* + * Loop invariants: + * There is room for one more character in record. + * R_end points just past end of record. + * Rp points just past last character in record. + * Scan points at remainder of record that needs to be + * scanned for tc=name constructs. + */ + scan = record; + tc_not_resolved = 0; + for (;;) { + if ((tc = cgetcap(scan, "tc", '=')) == NULL) + break; + + /* + * Find end of tc=name and stomp on the trailing `:' + * (if present) so we can use it to call ourselves. + */ + s = tc; + for (;;) + if (*s == '\0') + break; + else + if (*s++ == ':') { + *(s - 1) = '\0'; + break; + } + tcstart = tc - 3; + tclen = s - tcstart; + tcend = s; + + iret = getent(&icap, &ilen, db_p, fd, tc, depth+1, + NULL); + newicap = icap; /* Put into a register. */ + newilen = ilen; + if (iret != 0) { + /* an error */ + if (iret < -1) { + if (myfd) + (void)_close(fd); + free(record); + return (iret); + } + if (iret == 1) + tc_not_resolved = 1; + /* couldn't resolve tc */ + if (iret == -1) { + *(s - 1) = ':'; + scan = s - 1; + tc_not_resolved = 1; + continue; + + } + } + /* not interested in name field of tc'ed record */ + s = newicap; + for (;;) + if (*s == '\0') + break; + else + if (*s++ == ':') + break; + newilen -= s - newicap; + newicap = s; + + /* make sure interpolated record is `:'-terminated */ + s += newilen; + if (*(s-1) != ':') { + *s = ':'; /* overwrite NUL with : */ + newilen++; + } + + /* + * Make sure there's enough room to insert the + * new record. + */ + diff = newilen - tclen; + if (diff >= r_end - rp) { + u_int pos, tcpos, tcposend; + size_t newsize; + + pos = rp - record; + newsize = r_end - record + diff + BFRAG; + tcpos = tcstart - record; + tcposend = tcend - record; + record = reallocf(record, newsize); + if (record == NULL) { + errno = ENOMEM; + if (myfd) + (void)_close(fd); + free(icap); + return (-2); + } + r_end = record + newsize; + rp = record + pos; + tcstart = record + tcpos; + tcend = record + tcposend; + } + + /* + * Insert tc'ed record into our record. + */ + s = tcstart + newilen; + bcopy(tcend, s, rp - tcend); + bcopy(newicap, tcstart, newilen); + rp += diff; + free(icap); + + /* + * Start scan on `:' so next cgetcap works properly + * (cgetcap always skips first field). + */ + scan = s-1; + } + + } + /* + * Close file (if we opened it), give back any extra memory, and + * return capability, length and success. + */ + if (myfd) + (void)_close(fd); + *len = rp - record - 1; /* don't count NUL */ + if (r_end > rp) + if ((record = + reallocf(record, (size_t)(rp - record))) == NULL) { + errno = ENOMEM; + return (-2); + } + + *cap = record; + if (tc_not_resolved) + return (1); + return (0); +} + +static int +cdbget(DB *capdbp, char **bp, const char *name) +{ + DBT key, data; + char *namebuf; + + namebuf = strdup(name); + if (namebuf == NULL) + return (-2); + key.data = namebuf; + key.size = strlen(namebuf); + + for (;;) { + /* Get the reference. */ + switch(capdbp->get(capdbp, &key, &data, 0)) { + case -1: + free(namebuf); + return (-2); + case 1: + free(namebuf); + return (-1); + } + + /* If not an index to another record, leave. */ + if (((char *)data.data)[0] != SHADOW) + break; + + key.data = (char *)data.data + 1; + key.size = data.size - 1; + } + + *bp = (char *)data.data + 1; + free(namebuf); + return (((char *)(data.data))[0] == TCERR ? 1 : 0); +} + +/* + * Cgetmatch will return 0 if name is one of the names of the capability + * record buf, -1 if not. + */ +int +cgetmatch(const char *buf, const char *name) +{ + const char *np, *bp; + + if (name == NULL || *name == '\0') + return -1; + + /* + * Start search at beginning of record. + */ + bp = buf; + for (;;) { + /* + * Try to match a record name. + */ + np = name; + for (;;) + if (*np == '\0') + if (*bp == '|' || *bp == ':' || *bp == '\0') + return (0); + else + break; + else + if (*bp++ != *np++) + break; + + /* + * Match failed, skip to next name in record. + */ + bp--; /* a '|' or ':' may have stopped the match */ + for (;;) + if (*bp == '\0' || *bp == ':') + return (-1); /* match failed totally */ + else + if (*bp++ == '|') + break; /* found next name */ + } +} + + + + + +int +cgetfirst(char **buf, char **db_array) +{ + (void)cgetclose(); + return (cgetnext(buf, db_array)); +} + +static FILE *pfp; +static int slash; +static char **dbp; + +int +cgetclose(void) +{ + if (pfp != NULL) { + (void)fclose(pfp); + pfp = NULL; + } + dbp = NULL; + gottoprec = 0; + slash = 0; + return(0); +} + +/* + * Cgetnext() gets either the first or next entry in the logical database + * specified by db_array. It returns 0 upon completion of the database, 1 + * upon returning an entry with more remaining, and -1 if an error occurs. + */ +int +cgetnext(char **bp, char **db_array) +{ + size_t len; + int done, hadreaderr, i, savederrno, status; + char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; + u_int dummy; + + if (dbp == NULL) + dbp = db_array; + + if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) { + (void)cgetclose(); + return (-1); + } + for(;;) { + if (toprec && !gottoprec) { + gottoprec = 1; + line = toprec; + } else { + line = fgetln(pfp, &len); + if (line == NULL && pfp) { + hadreaderr = ferror(pfp); + if (hadreaderr) + savederrno = errno; + fclose(pfp); + pfp = NULL; + if (hadreaderr) { + cgetclose(); + errno = savederrno; + return (-1); + } else { + if (*++dbp == NULL) { + (void)cgetclose(); + return (0); + } else if ((pfp = + fopen(*dbp, "r")) == NULL) { + (void)cgetclose(); + return (-1); + } else + continue; + } + } else + line[len - 1] = '\0'; + if (len == 1) { + slash = 0; + continue; + } + if (isspace((unsigned char)*line) || + *line == ':' || *line == '#' || slash) { + if (line[len - 2] == '\\') + slash = 1; + else + slash = 0; + continue; + } + if (line[len - 2] == '\\') + slash = 1; + else + slash = 0; + } + + + /* + * Line points to a name line. + */ + i = 0; + done = 0; + np = nbuf; + for (;;) { + for (cp = line; *cp != '\0'; cp++) { + if (*cp == ':') { + *np++ = ':'; + done = 1; + break; + } + if (*cp == '\\') + break; + *np++ = *cp; + } + if (done) { + *np = '\0'; + break; + } else { /* name field extends beyond the line */ + line = fgetln(pfp, &len); + if (line == NULL && pfp) { + /* Name extends beyond the EOF! */ + hadreaderr = ferror(pfp); + if (hadreaderr) + savederrno = errno; + fclose(pfp); + pfp = NULL; + if (hadreaderr) { + cgetclose(); + errno = savederrno; + return (-1); + } else { + cgetclose(); + return (-1); + } + } else + line[len - 1] = '\0'; + } + } + rp = buf; + for(cp = nbuf; *cp != '\0'; cp++) + if (*cp == '|' || *cp == ':') + break; + else + *rp++ = *cp; + + *rp = '\0'; + /* + * XXX + * Last argument of getent here should be nbuf if we want true + * sequential access in the case of duplicates. + * With NULL, getent will return the first entry found + * rather than the duplicate entry record. This is a + * matter of semantics that should be resolved. + */ + status = getent(bp, &dummy, db_array, -1, buf, 0, NULL); + if (status == -2 || status == -3) + (void)cgetclose(); + + return (status + 1); + } + /* NOTREACHED */ +} + +/* + * Cgetstr retrieves the value of the string capability cap from the + * capability record pointed to by buf. A pointer to a decoded, NUL + * terminated, malloc'd copy of the string is returned in the char * + * pointed to by str. The length of the string not including the trailing + * NUL is returned on success, -1 if the requested string capability + * couldn't be found, -2 if a system error was encountered (storage + * allocation failure). + */ +int +cgetstr(char *buf, const char *cap, char **str) +{ + u_int m_room; + char *bp, *mp; + int len; + char *mem; + + /* + * Find string capability cap + */ + bp = cgetcap(buf, cap, '='); + if (bp == NULL) + return (-1); + + /* + * Conversion / storage allocation loop ... Allocate memory in + * chunks SFRAG in size. + */ + if ((mem = malloc(SFRAG)) == NULL) { + errno = ENOMEM; + return (-2); /* couldn't even allocate the first fragment */ + } + m_room = SFRAG; + mp = mem; + + while (*bp != ':' && *bp != '\0') { + /* + * Loop invariants: + * There is always room for one more character in mem. + * Mp always points just past last character in mem. + * Bp always points at next character in buf. + */ + if (*bp == '^') { + bp++; + if (*bp == ':' || *bp == '\0') + break; /* drop unfinished escape */ + if (*bp == '?') { + *mp++ = '\177'; + bp++; + } else + *mp++ = *bp++ & 037; + } else if (*bp == '\\') { + bp++; + if (*bp == ':' || *bp == '\0') + break; /* drop unfinished escape */ + if ('0' <= *bp && *bp <= '7') { + int n, i; + + n = 0; + i = 3; /* maximum of three octal digits */ + do { + n = n * 8 + (*bp++ - '0'); + } while (--i && '0' <= *bp && *bp <= '7'); + *mp++ = n; + } + else switch (*bp++) { + case 'b': case 'B': + *mp++ = '\b'; + break; + case 't': case 'T': + *mp++ = '\t'; + break; + case 'n': case 'N': + *mp++ = '\n'; + break; + case 'f': case 'F': + *mp++ = '\f'; + break; + case 'r': case 'R': + *mp++ = '\r'; + break; + case 'e': case 'E': + *mp++ = ESC; + break; + case 'c': case 'C': + *mp++ = ':'; + break; + default: + /* + * Catches '\', '^', and + * everything else. + */ + *mp++ = *(bp-1); + break; + } + } else + *mp++ = *bp++; + m_room--; + + /* + * Enforce loop invariant: if no room left in current + * buffer, try to get some more. + */ + if (m_room == 0) { + size_t size = mp - mem; + + if ((mem = reallocf(mem, size + SFRAG)) == NULL) + return (-2); + m_room = SFRAG; + mp = mem + size; + } + } + *mp++ = '\0'; /* loop invariant let's us do this */ + m_room--; + len = mp - mem - 1; + + /* + * Give back any extra memory and return value and success. + */ + if (m_room != 0) + if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL) + return (-2); + *str = mem; + return (len); +} + +/* + * Cgetustr retrieves the value of the string capability cap from the + * capability record pointed to by buf. The difference between cgetustr() + * and cgetstr() is that cgetustr does not decode escapes but rather treats + * all characters literally. A pointer to a NUL terminated malloc'd + * copy of the string is returned in the char pointed to by str. The + * length of the string not including the trailing NUL is returned on success, + * -1 if the requested string capability couldn't be found, -2 if a system + * error was encountered (storage allocation failure). + */ +int +cgetustr(char *buf, const char *cap, char **str) +{ + u_int m_room; + char *bp, *mp; + int len; + char *mem; + + /* + * Find string capability cap + */ + if ((bp = cgetcap(buf, cap, '=')) == NULL) + return (-1); + + /* + * Conversion / storage allocation loop ... Allocate memory in + * chunks SFRAG in size. + */ + if ((mem = malloc(SFRAG)) == NULL) { + errno = ENOMEM; + return (-2); /* couldn't even allocate the first fragment */ + } + m_room = SFRAG; + mp = mem; + + while (*bp != ':' && *bp != '\0') { + /* + * Loop invariants: + * There is always room for one more character in mem. + * Mp always points just past last character in mem. + * Bp always points at next character in buf. + */ + *mp++ = *bp++; + m_room--; + + /* + * Enforce loop invariant: if no room left in current + * buffer, try to get some more. + */ + if (m_room == 0) { + size_t size = mp - mem; + + if ((mem = reallocf(mem, size + SFRAG)) == NULL) + return (-2); + m_room = SFRAG; + mp = mem + size; + } + } + *mp++ = '\0'; /* loop invariant let's us do this */ + m_room--; + len = mp - mem - 1; + + /* + * Give back any extra memory and return value and success. + */ + if (m_room != 0) + if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL) + return (-2); + *str = mem; + return (len); +} + +/* + * Cgetnum retrieves the value of the numeric capability cap from the + * capability record pointed to by buf. The numeric value is returned in + * the long pointed to by num. 0 is returned on success, -1 if the requested + * numeric capability couldn't be found. + */ +int +cgetnum(char *buf, const char *cap, long *num) +{ + long n; + int base, digit; + char *bp; + + /* + * Find numeric capability cap + */ + bp = cgetcap(buf, cap, '#'); + if (bp == NULL) + return (-1); + + /* + * Look at value and determine numeric base: + * 0x... or 0X... hexadecimal, + * else 0... octal, + * else decimal. + */ + if (*bp == '0') { + bp++; + if (*bp == 'x' || *bp == 'X') { + bp++; + base = 16; + } else + base = 8; + } else + base = 10; + + /* + * Conversion loop ... + */ + n = 0; + for (;;) { + if ('0' <= *bp && *bp <= '9') + digit = *bp - '0'; + else if ('a' <= *bp && *bp <= 'f') + digit = 10 + *bp - 'a'; + else if ('A' <= *bp && *bp <= 'F') + digit = 10 + *bp - 'A'; + else + break; + + if (digit >= base) + break; + + n = n * base + digit; + bp++; + } + + /* + * Return value and success. + */ + *num = n; + return (0); +} + + +/* + * Compare name field of record. + */ +static int +nfcmp(char *nf, char *rec) +{ + char *cp, tmp; + int ret; + + for (cp = rec; *cp != ':'; cp++) + ; + + tmp = *(cp + 1); + *(cp + 1) = '\0'; + ret = strcmp(nf, rec); + *(cp + 1) = tmp; + + return (ret); +} diff --git a/src/lib/libc/gen/getcwd.c b/src/lib/libc/gen/getcwd.c new file mode 100644 index 0000000..3b6a813 --- /dev/null +++ b/src/lib/libc/gen/getcwd.c @@ -0,0 +1,261 @@ +/* + * Copyright (c) 1989, 1991, 1993, 1995 + * 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[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getcwd.c,v 1.25 2003/10/29 10:45:01 tjr Exp $"); + +#include "namespace.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#define ISDOT(dp) \ + (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ + (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) + +extern int __getcwd(char *, size_t); + +char * +getcwd(pt, size) + char *pt; + size_t size; +{ + struct dirent *dp; + DIR *dir = NULL; + dev_t dev; + ino_t ino; + int first; + char *bpt, *bup; + struct stat s; + dev_t root_dev; + ino_t root_ino; + size_t ptsize, upsize; + int save_errno; + char *ept, *eup, *up, c; + + /* + * If no buffer specified by the user, allocate one as necessary. + * If a buffer is specified, the size has to be non-zero. The path + * is built from the end of the buffer backwards. + */ + if (pt) { + ptsize = 0; + if (!size) { + errno = EINVAL; + return (NULL); + } + if (size == 1) { + errno = ERANGE; + return (NULL); + } + ept = pt + size; + } else { + if ((pt = malloc(ptsize = 1024 - 4)) == NULL) + return (NULL); + ept = pt + ptsize; + } + if (__getcwd(pt, ept - pt) == 0) { + if (*pt != '/') { + bpt = pt; + ept = pt + strlen(pt) - 1; + while (bpt < ept) { + c = *bpt; + *bpt++ = *ept; + *ept-- = c; + } + } + return (pt); + } + bpt = ept - 1; + *bpt = '\0'; + + /* + * Allocate bytes (1024 - malloc space) for the string of "../"'s. + * Should always be enough (it's 340 levels). If it's not, allocate + * as necessary. Special case the first stat, it's ".", not "..". + */ + if ((up = malloc(upsize = 1024 - 4)) == NULL) + goto err; + eup = up + MAXPATHLEN; + bup = up; + up[0] = '.'; + up[1] = '\0'; + + /* Save root values, so know when to stop. */ + if (stat("/", &s)) + goto err; + root_dev = s.st_dev; + root_ino = s.st_ino; + + errno = 0; /* XXX readdir has no error return. */ + + for (first = 1;; first = 0) { + /* Stat the current level. */ + if (lstat(up, &s)) + goto err; + + /* Save current node values. */ + ino = s.st_ino; + dev = s.st_dev; + + /* Check for reaching root. */ + if (root_dev == dev && root_ino == ino) { + *--bpt = '/'; + /* + * It's unclear that it's a requirement to copy the + * path to the beginning of the buffer, but it's always + * been that way and stuff would probably break. + */ + bcopy(bpt, pt, ept - bpt); + free(up); + return (pt); + } + + /* + * Build pointer to the parent directory, allocating memory + * as necessary. Max length is 3 for "../", the largest + * possible component name, plus a trailing NUL. + */ + if (bup + 3 + MAXNAMLEN + 1 >= eup) { + if ((up = reallocf(up, upsize *= 2)) == NULL) + goto err; + bup = up; + eup = up + upsize; + } + *bup++ = '.'; + *bup++ = '.'; + *bup = '\0'; + + /* Open and stat parent directory. */ + if (!(dir = opendir(up)) || _fstat(dirfd(dir), &s)) + goto err; + + /* Add trailing slash for next directory. */ + *bup++ = '/'; + *bup = '\0'; + + /* + * If it's a mount point, have to stat each element because + * the inode number in the directory is for the entry in the + * parent directory, not the inode number of the mounted file. + */ + save_errno = 0; + if (s.st_dev == dev) { + for (;;) { + if (!(dp = readdir(dir))) + goto notfound; + if (dp->d_fileno == ino) + break; + } + } else + for (;;) { + if (!(dp = readdir(dir))) + goto notfound; + if (ISDOT(dp)) + continue; + bcopy(dp->d_name, bup, dp->d_namlen + 1); + + /* Save the first error for later. */ + if (lstat(up, &s)) { + if (!save_errno) + save_errno = errno; + errno = 0; + continue; + } + if (s.st_dev == dev && s.st_ino == ino) + break; + } + + /* + * Check for length of the current name, preceding slash, + * leading slash. + */ + if (bpt - pt < dp->d_namlen + (first ? 1 : 2)) { + size_t len, off; + + if (!ptsize) { + errno = ERANGE; + goto err; + } + off = bpt - pt; + len = ept - bpt; + if ((pt = reallocf(pt, ptsize *= 2)) == NULL) + goto err; + bpt = pt + off; + ept = pt + ptsize; + bcopy(bpt, ept - len, len); + bpt = ept - len; + } + if (!first) + *--bpt = '/'; + bpt -= dp->d_namlen; + bcopy(dp->d_name, bpt, dp->d_namlen); + (void) closedir(dir); + dir = NULL; + + /* Truncate any file name. */ + *bup = '\0'; + } + +notfound: + /* + * If readdir set errno, use it, not any saved error; otherwise, + * didn't find the current directory in its parent directory, set + * errno to ENOENT. + */ + if (!errno) + errno = save_errno ? save_errno : ENOENT; + /* FALLTHROUGH */ +err: + save_errno = errno; + + if (ptsize) + free(pt); + if (dir) + (void) closedir(dir); + free(up); + + errno = save_errno; + return (NULL); +} diff --git a/src/lib/libc/gen/getdomainname.c b/src/lib/libc/gen/getdomainname.c new file mode 100644 index 0000000..05441d7 --- /dev/null +++ b/src/lib/libc/gen/getdomainname.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getdomainname.c,v 1.7 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include + +#include + +int +getdomainname(name, namelen) + char *name; + int namelen; +{ + int mib[2]; + size_t size; + + mib[0] = CTL_KERN; + mib[1] = KERN_NISDOMAINNAME; + size = namelen; + if (sysctl(mib, 2, name, &size, NULL, 0) == -1) + return (-1); + return (0); +} diff --git a/src/lib/libc/gen/getgrent.c b/src/lib/libc/gen/getgrent.c new file mode 100644 index 0000000..bf86ecc --- /dev/null +++ b/src/lib/libc/gen/getgrent.c @@ -0,0 +1,1152 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getgrent.c,v 1.32 2004/05/17 22:15:49 kientzle Exp $"); + +#include "namespace.h" +#include +#ifdef YP +#include +#include +#include +#endif +#include +#include +#ifdef HESIOD +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "nss_tls.h" + + +enum constants { + GRP_STORAGE_INITIAL = 1 << 10, /* 1 KByte */ + GRP_STORAGE_MAX = 1 << 20, /* 1 MByte */ + SETGRENT = 1, + ENDGRENT = 2, + HESIOD_NAME_MAX = 256, +}; + +static const ns_src defaultsrc[] = { + { NSSRC_COMPAT, NS_SUCCESS }, + { NULL, 0 } +}; + +int __gr_match_entry(const char *, size_t, enum nss_lookup_type, + const char *, gid_t); +int __gr_parse_entry(char *, size_t, struct group *, char *, size_t, + int *); + +static int is_comment_line(const char *, size_t); + +union key { + const char *name; + gid_t gid; +}; +static struct group *getgr(int (*)(union key, struct group *, char *, size_t, + struct group **), union key); +static int wrap_getgrnam_r(union key, struct group *, char *, size_t, + struct group **); +static int wrap_getgrgid_r(union key, struct group *, char *, size_t, + struct group **); +static int wrap_getgrent_r(union key, struct group *, char *, size_t, + struct group **); + +struct files_state { + FILE *fp; + int stayopen; +}; +static void files_endstate(void *); +NSS_TLS_HANDLING(files); +static int files_setgrent(void *, void *, va_list); +static int files_group(void *, void *, va_list); + + +#ifdef HESIOD +struct dns_state { + long counter; +}; +static void dns_endstate(void *); +NSS_TLS_HANDLING(dns); +static int dns_setgrent(void *, void *, va_list); +static int dns_group(void *, void *, va_list); +#endif + + +#ifdef YP +struct nis_state { + char domain[MAXHOSTNAMELEN]; + int done; + char *key; + int keylen; +}; +static void nis_endstate(void *); +NSS_TLS_HANDLING(nis); +static int nis_setgrent(void *, void *, va_list); +static int nis_group(void *, void *, va_list); +#endif + +struct compat_state { + FILE *fp; + int stayopen; + char *name; + enum _compat { + COMPAT_MODE_OFF = 0, + COMPAT_MODE_ALL, + COMPAT_MODE_NAME + } compat; +}; +static void compat_endstate(void *); +NSS_TLS_HANDLING(compat); +static int compat_setgrent(void *, void *, va_list); +static int compat_group(void *, void *, va_list); + + +/* XXX IEEE Std 1003.1, 2003 specifies `void setgrent(void)' */ +int +setgrent(void) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_setgrent, (void *)SETGRENT }, +#ifdef HESIOD + { NSSRC_DNS, dns_setgrent, (void *)SETGRENT }, +#endif +#ifdef YP + { NSSRC_NIS, nis_setgrent, (void *)SETGRENT }, +#endif + { NSSRC_COMPAT, compat_setgrent, (void *)SETGRENT }, + { NULL, NULL, NULL } + }; + (void)_nsdispatch(NULL, dtab, NSDB_GROUP, "setgrent", defaultsrc, 0); + return (1); +} + + +int +setgroupent(int stayopen) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_setgrent, (void *)SETGRENT }, +#ifdef HESIOD + { NSSRC_DNS, dns_setgrent, (void *)SETGRENT }, +#endif +#ifdef YP + { NSSRC_NIS, nis_setgrent, (void *)SETGRENT }, +#endif + { NSSRC_COMPAT, compat_setgrent, (void *)SETGRENT }, + { NULL, NULL, NULL } + }; + (void)_nsdispatch(NULL, dtab, NSDB_GROUP, "setgrent", defaultsrc, + stayopen); + return (1); +} + + +void +endgrent(void) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_setgrent, (void *)ENDGRENT }, +#ifdef HESIOD + { NSSRC_DNS, dns_setgrent, (void *)ENDGRENT }, +#endif +#ifdef YP + { NSSRC_NIS, nis_setgrent, (void *)ENDGRENT }, +#endif + { NSSRC_COMPAT, compat_setgrent, (void *)ENDGRENT }, + { NULL, NULL, NULL } + }; + (void)_nsdispatch(NULL, dtab, NSDB_GROUP, "endgrent", defaultsrc); +} + + +int +getgrent_r(struct group *grp, char *buffer, size_t bufsize, + struct group **result) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_group, (void *)nss_lt_all }, +#ifdef HESIOD + { NSSRC_DNS, dns_group, (void *)nss_lt_all }, +#endif +#ifdef YP + { NSSRC_NIS, nis_group, (void *)nss_lt_all }, +#endif + { NSSRC_COMPAT, compat_group, (void *)nss_lt_all }, + { NULL, NULL, NULL } + }; + int rv, ret_errno; + + ret_errno = 0; + *result = NULL; + rv = _nsdispatch(result, dtab, NSDB_GROUP, "getgrent_r", defaultsrc, + grp, buffer, bufsize, &ret_errno); + if (rv == NS_SUCCESS) + return (0); + else + return (ret_errno); +} + + +int +getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize, + struct group **result) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_group, (void *)nss_lt_name }, +#ifdef HESIOD + { NSSRC_DNS, dns_group, (void *)nss_lt_name }, +#endif +#ifdef YP + { NSSRC_NIS, nis_group, (void *)nss_lt_name }, +#endif + { NSSRC_COMPAT, compat_group, (void *)nss_lt_name }, + { NULL, NULL, NULL } + }; + int rv, ret_errno; + + ret_errno = 0; + *result = NULL; + rv = _nsdispatch(result, dtab, NSDB_GROUP, "getgrnam_r", defaultsrc, + name, grp, buffer, bufsize, &ret_errno); + if (rv == NS_SUCCESS) + return (0); + else + return (ret_errno); +} + + +int +getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, + struct group **result) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_group, (void *)nss_lt_id }, +#ifdef HESIOD + { NSSRC_DNS, dns_group, (void *)nss_lt_id }, +#endif +#ifdef YP + { NSSRC_NIS, nis_group, (void *)nss_lt_id }, +#endif + { NSSRC_COMPAT, compat_group, (void *)nss_lt_id }, + { NULL, NULL, NULL } + }; + int rv, ret_errno; + + ret_errno = 0; + *result = NULL; + rv = _nsdispatch(result, dtab, NSDB_GROUP, "getgrgid_r", defaultsrc, + gid, grp, buffer, bufsize, &ret_errno); + if (rv == NS_SUCCESS) + return (0); + else + return (ret_errno); +} + + +static struct group grp; +static char *grp_storage; +static size_t grp_storage_size; + +static struct group * +getgr(int (*fn)(union key, struct group *, char *, size_t, struct group **), + union key key) +{ + int rv; + struct group *res; + + if (grp_storage == NULL) { + grp_storage = malloc(GRP_STORAGE_INITIAL); + if (grp_storage == NULL) + return (NULL); + grp_storage_size = GRP_STORAGE_INITIAL; + } + do { + rv = fn(key, &grp, grp_storage, grp_storage_size, &res); + if (res == NULL && rv == ERANGE) { + free(grp_storage); + if ((grp_storage_size << 1) > GRP_STORAGE_MAX) { + grp_storage = NULL; + errno = ERANGE; + return (NULL); + } + grp_storage_size <<= 1; + grp_storage = malloc(grp_storage_size); + if (grp_storage == NULL) + return (NULL); + } + } while (res == NULL && rv == ERANGE); + if (rv != 0) + errno = rv; + return (res); +} + + +static int +wrap_getgrnam_r(union key key, struct group *grp, char *buffer, size_t bufsize, + struct group **res) +{ + return (getgrnam_r(key.name, grp, buffer, bufsize, res)); +} + + +static int +wrap_getgrgid_r(union key key, struct group *grp, char *buffer, size_t bufsize, + struct group **res) +{ + return (getgrgid_r(key.gid, grp, buffer, bufsize, res)); +} + + +static int +wrap_getgrent_r(union key key __unused, struct group *grp, char *buffer, + size_t bufsize, struct group **res) +{ + return (getgrent_r(grp, buffer, bufsize, res)); +} + + +struct group * +getgrnam(const char *name) +{ + union key key; + + key.name = name; + return (getgr(wrap_getgrnam_r, key)); +} + + +struct group * +getgrgid(gid_t gid) +{ + union key key; + + key.gid = gid; + return (getgr(wrap_getgrgid_r, key)); +} + + +struct group * +getgrent(void) +{ + union key key; + + key.gid = 0; /* not used */ + return (getgr(wrap_getgrent_r, key)); +} + + +static int +is_comment_line(const char *s, size_t n) +{ + const char *eom; + + eom = &s[n]; + + for (; s < eom; s++) + if (*s == '#' || !isspace((unsigned char)*s)) + break; + return (*s == '#' || s == eom); +} + + +/* + * files backend + */ +static void +files_endstate(void *p) +{ + + if (p == NULL) + return; + if (((struct files_state *)p)->fp != NULL) + fclose(((struct files_state *)p)->fp); + free(p); +} + + +static int +files_setgrent(void *retval, void *mdata, va_list ap) +{ + struct files_state *st; + int rv, stayopen; + + rv = files_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + switch ((enum constants)mdata) { + case SETGRENT: + stayopen = va_arg(ap, int); + if (st->fp != NULL) + rewind(st->fp); + else if (stayopen) + st->fp = fopen(_PATH_GROUP, "r"); + break; + case ENDGRENT: + if (st->fp != NULL) { + fclose(st->fp); + st->fp = NULL; + } + break; + default: + break; + } + return (NS_UNAVAIL); +} + + +static int +files_group(void *retval, void *mdata, va_list ap) +{ + struct files_state *st; + enum nss_lookup_type how; + const char *name, *line; + struct group *grp; + gid_t gid; + char *buffer; + size_t bufsize, linesize; + int rv, stayopen, *errnop; + + name = NULL; + gid = (gid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + break; + case nss_lt_id: + gid = va_arg(ap, gid_t); + break; + case nss_lt_all: + break; + default: + return (NS_NOTFOUND); + } + grp = va_arg(ap, struct group *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = files_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (st->fp == NULL && + ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) { + *errnop = errno; + return (NS_UNAVAIL); + } + if (how == nss_lt_all) + stayopen = 1; + else { + rewind(st->fp); + stayopen = st->stayopen; + } + rv = NS_NOTFOUND; + while ((line = fgetln(st->fp, &linesize)) != NULL) { + if (line[linesize-1] == '\n') + linesize--; + rv = __gr_match_entry(line, linesize, how, name, gid); + if (rv != NS_SUCCESS) + continue; + /* We need room at least for the line, a string NUL + * terminator, alignment padding, and one (char *) + * pointer for the member list terminator. + */ + if (bufsize <= linesize + _ALIGNBYTES + sizeof(char *)) { + *errnop = ERANGE; + rv = NS_RETURN; + break; + } + memcpy(buffer, line, linesize); + buffer[linesize] = '\0'; + rv = __gr_parse_entry(buffer, linesize, grp, + &buffer[linesize + 1], bufsize - linesize - 1, errnop); + if (rv & NS_TERMINATE) + break; + } + if (!stayopen && st->fp != NULL) { + fclose(st->fp); + st->fp = NULL; + } + if (rv == NS_SUCCESS && retval != NULL) + *(struct group **)retval = grp; + return (rv); +} + + +#ifdef HESIOD +/* + * dns backend + */ +static void +dns_endstate(void *p) +{ + + free(p); +} + + +static int +dns_setgrent(void *retval, void *cb_data, va_list ap) +{ + struct dns_state *st; + int rv; + + rv = dns_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + st->counter = 0; + return (NS_UNAVAIL); +} + + +static int +dns_group(void *retval, void *mdata, va_list ap) +{ + char buf[HESIOD_NAME_MAX]; + struct dns_state *st; + struct group *grp; + const char *name, *label; + void *ctx; + char *buffer, **hes; + size_t bufsize, adjsize, linesize; + gid_t gid; + enum nss_lookup_type how; + int rv, *errnop; + + ctx = NULL; + hes = NULL; + name = NULL; + gid = (gid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + break; + case nss_lt_id: + gid = va_arg(ap, gid_t); + break; + case nss_lt_all: + break; + } + grp = va_arg(ap, struct group *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = dns_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (hesiod_init(&ctx) != 0) { + *errnop = errno; + rv = NS_UNAVAIL; + goto fin; + } + do { + rv = NS_NOTFOUND; + switch (how) { + case nss_lt_name: + label = name; + break; + case nss_lt_id: + if (snprintf(buf, sizeof(buf), "%lu", + (unsigned long)gid) >= sizeof(buf)) + goto fin; + label = buf; + break; + case nss_lt_all: + if (st->counter < 0) + goto fin; + if (snprintf(buf, sizeof(buf), "group-%ld", + st->counter++) >= sizeof(buf)) + goto fin; + label = buf; + break; + } + hes = hesiod_resolve(ctx, label, + how == nss_lt_id ? "gid" : "group"); + if ((how == nss_lt_id && hes == NULL && + (hes = hesiod_resolve(ctx, buf, "group")) == NULL) || + hes == NULL) { + if (how == nss_lt_all) + st->counter = -1; + if (errno != ENOENT) + *errnop = errno; + goto fin; + } + rv = __gr_match_entry(hes[0], strlen(hes[0]), how, name, gid); + if (rv != NS_SUCCESS) { + hesiod_free_list(ctx, hes); + hes = NULL; + continue; + } + /* We need room at least for the line, a string NUL + * terminator, alignment padding, and one (char *) + * pointer for the member list terminator. + */ + adjsize = bufsize - _ALIGNBYTES - sizeof(char *); + linesize = strlcpy(buffer, hes[0], adjsize); + if (linesize >= adjsize) { + *errnop = ERANGE; + rv = NS_RETURN; + goto fin; + } + hesiod_free_list(ctx, hes); + hes = NULL; + rv = __gr_parse_entry(buffer, linesize, grp, + &buffer[linesize + 1], bufsize - linesize - 1, errnop); + } while (how == nss_lt_all && !(rv & NS_TERMINATE)); +fin: + if (hes != NULL) + hesiod_free_list(ctx, hes); + if (ctx != NULL) + hesiod_end(ctx); + if (rv == NS_SUCCESS && retval != NULL) + *(struct group **)retval = grp; + return (rv); +} +#endif /* HESIOD */ + + +#ifdef YP +/* + * nis backend + */ +static void +nis_endstate(void *p) +{ + + if (p == NULL) + return; + free(((struct nis_state *)p)->key); + free(p); +} + + +static int +nis_setgrent(void *retval, void *cb_data, va_list ap) +{ + struct nis_state *st; + int rv; + + rv = nis_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + st->done = 0; + free(st->key); + st->key = NULL; + return (NS_UNAVAIL); +} + + +static int +nis_group(void *retval, void *mdata, va_list ap) +{ + char *map; + struct nis_state *st; + struct group *grp; + const char *name; + char *buffer, *key, *result; + size_t bufsize; + gid_t gid; + enum nss_lookup_type how; + int *errnop, keylen, resultlen, rv; + + name = NULL; + gid = (gid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + map = "group.byname"; + break; + case nss_lt_id: + gid = va_arg(ap, gid_t); + map = "group.bygid"; + break; + case nss_lt_all: + map = "group.byname"; + break; + } + grp = va_arg(ap, struct group *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = nis_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (st->domain[0] == '\0') { + if (getdomainname(st->domain, sizeof(st->domain)) != 0) { + *errnop = errno; + return (NS_UNAVAIL); + } + } + result = NULL; + do { + rv = NS_NOTFOUND; + switch (how) { + case nss_lt_name: + if (strlcpy(buffer, name, bufsize) >= bufsize) + goto erange; + break; + case nss_lt_id: + if (snprintf(buffer, bufsize, "%lu", + (unsigned long)gid) >= bufsize) + goto erange; + break; + case nss_lt_all: + if (st->done) + goto fin; + break; + } + result = NULL; + if (how == nss_lt_all) { + if (st->key == NULL) + rv = yp_first(st->domain, map, &st->key, + &st->keylen, &result, &resultlen); + else { + key = st->key; + keylen = st->keylen; + st->key = NULL; + rv = yp_next(st->domain, map, key, keylen, + &st->key, &st->keylen, &result, + &resultlen); + free(key); + } + if (rv != 0) { + free(result); + free(st->key); + st->key = NULL; + if (rv == YPERR_NOMORE) { + st->done = 1; + rv = NS_NOTFOUND; + } else + rv = NS_UNAVAIL; + goto fin; + } + } else { + rv = yp_match(st->domain, map, buffer, strlen(buffer), + &result, &resultlen); + if (rv == YPERR_KEY) { + rv = NS_NOTFOUND; + continue; + } else if (rv != 0) { + free(result); + rv = NS_UNAVAIL; + continue; + } + } + /* We need room at least for the line, a string NUL + * terminator, alignment padding, and one (char *) + * pointer for the member list terminator. + */ + if (resultlen >= bufsize - _ALIGNBYTES - sizeof(char *)) + goto erange; + memcpy(buffer, result, resultlen); + buffer[resultlen] = '\0'; + free(result); + rv = __gr_match_entry(buffer, resultlen, how, name, gid); + if (rv == NS_SUCCESS) + rv = __gr_parse_entry(buffer, resultlen, grp, + &buffer[resultlen+1], bufsize - resultlen - 1, + errnop); + } while (how == nss_lt_all && !(rv & NS_TERMINATE)); +fin: + if (rv == NS_SUCCESS && retval != NULL) + *(struct group **)retval = grp; + return (rv); +erange: + *errnop = ERANGE; + return (NS_RETURN); +} +#endif /* YP */ + + + +/* + * compat backend + */ +static void +compat_endstate(void *p) +{ + struct compat_state *st; + + if (p == NULL) + return; + st = (struct compat_state *)p; + free(st->name); + if (st->fp != NULL) + fclose(st->fp); + free(p); +} + + +static int +compat_setgrent(void *retval, void *mdata, va_list ap) +{ + static const ns_src compatsrc[] = { +#ifdef YP + { NSSRC_NIS, NS_SUCCESS }, +#endif + { NULL, 0 } + }; + ns_dtab dtab[] = { +#ifdef HESIOD + { NSSRC_DNS, dns_setgrent, NULL }, +#endif +#ifdef YP + { NSSRC_NIS, nis_setgrent, NULL }, +#endif + { NULL, NULL, NULL } + }; + struct compat_state *st; + int rv, stayopen; + +#define set_setent(x, y) do { \ + int i; \ + \ + for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + x[i].mdata = (void *)y; \ +} while (0) + + rv = compat_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + switch ((enum constants)mdata) { + case SETGRENT: + stayopen = va_arg(ap, int); + if (st->fp != NULL) + rewind(st->fp); + else if (stayopen) + st->fp = fopen(_PATH_GROUP, "r"); + set_setent(dtab, mdata); + (void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "setgrent", + compatsrc, 0); + break; + case ENDGRENT: + if (st->fp != NULL) { + fclose(st->fp); + st->fp = NULL; + } + set_setent(dtab, mdata); + (void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "endgrent", + compatsrc, 0); + break; + default: + break; + } + st->compat = COMPAT_MODE_OFF; + free(st->name); + st->name = NULL; + return (NS_UNAVAIL); +#undef set_setent +} + + +static int +compat_group(void *retval, void *mdata, va_list ap) +{ + static const ns_src compatsrc[] = { +#ifdef YP + { NSSRC_NIS, NS_SUCCESS }, +#endif + { NULL, 0 } + }; + ns_dtab dtab[] = { +#ifdef YP + { NSSRC_NIS, nis_group, NULL }, +#endif +#ifdef HESIOD + { NSSRC_DNS, dns_group, NULL }, +#endif + { NULL, NULL, NULL } + }; + struct compat_state *st; + enum nss_lookup_type how; + const char *name, *line; + struct group *grp; + gid_t gid; + char *buffer, *p; + void *discard; + size_t bufsize, linesize; + int rv, stayopen, *errnop; + +#define set_lookup_type(x, y) do { \ + int i; \ + \ + for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + x[i].mdata = (void *)y; \ +} while (0) + + name = NULL; + gid = (gid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + break; + case nss_lt_id: + gid = va_arg(ap, gid_t); + break; + case nss_lt_all: + break; + default: + return (NS_NOTFOUND); + } + grp = va_arg(ap, struct group *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = compat_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (st->fp == NULL && + ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) { + *errnop = errno; + rv = NS_UNAVAIL; + goto fin; + } + if (how == nss_lt_all) + stayopen = 1; + else { + rewind(st->fp); + stayopen = st->stayopen; + } +docompat: + switch (st->compat) { + case COMPAT_MODE_ALL: + set_lookup_type(dtab, how); + switch (how) { + case nss_lt_all: + rv = _nsdispatch(&discard, dtab, NSDB_GROUP_COMPAT, + "getgrent_r", compatsrc, grp, buffer, bufsize, + errnop); + break; + case nss_lt_id: + rv = _nsdispatch(&discard, dtab, NSDB_GROUP_COMPAT, + "getgrgid_r", compatsrc, gid, grp, buffer, bufsize, + errnop); + break; + case nss_lt_name: + rv = _nsdispatch(&discard, dtab, NSDB_GROUP_COMPAT, + "getgrnam_r", compatsrc, name, grp, buffer, + bufsize, errnop); + break; + } + if (rv & NS_TERMINATE) + goto fin; + st->compat = COMPAT_MODE_OFF; + break; + case COMPAT_MODE_NAME: + set_lookup_type(dtab, nss_lt_name); + rv = _nsdispatch(&discard, dtab, NSDB_GROUP_COMPAT, + "getgrnam_r", compatsrc, st->name, grp, buffer, bufsize, + errnop); + switch (rv) { + case NS_SUCCESS: + switch (how) { + case nss_lt_name: + if (strcmp(name, grp->gr_name) != 0) + rv = NS_NOTFOUND; + break; + case nss_lt_id: + if (gid != grp->gr_gid) + rv = NS_NOTFOUND; + break; + default: + break; + } + break; + case NS_RETURN: + goto fin; + default: + break; + } + free(st->name); + st->name = NULL; + st->compat = COMPAT_MODE_OFF; + if (rv == NS_SUCCESS) + goto fin; + break; + default: + break; + } + rv = NS_NOTFOUND; + while ((line = fgetln(st->fp, &linesize)) != NULL) { + if (line[linesize-1] == '\n') + linesize--; + if (linesize > 2 && line[0] == '+') { + p = memchr(&line[1], ':', linesize); + if (p == NULL || p == &line[1]) + st->compat = COMPAT_MODE_ALL; + else { + st->name = malloc(p - line); + if (st->name == NULL) { + syslog(LOG_ERR, + "getgrent memory allocation failure"); + *errnop = ENOMEM; + rv = NS_UNAVAIL; + break; + } + memcpy(st->name, &line[1], p - line - 1); + st->name[p - line - 1] = '\0'; + st->compat = COMPAT_MODE_NAME; + } + goto docompat; + } + rv = __gr_match_entry(line, linesize, how, name, gid); + if (rv != NS_SUCCESS) + continue; + /* We need room at least for the line, a string NUL + * terminator, alignment padding, and one (char *) + * pointer for the member list terminator. + */ + if (bufsize <= linesize + _ALIGNBYTES + sizeof(char *)) { + *errnop = ERANGE; + rv = NS_RETURN; + break; + } + memcpy(buffer, line, linesize); + buffer[linesize] = '\0'; + rv = __gr_parse_entry(buffer, linesize, grp, + &buffer[linesize + 1], bufsize - linesize - 1, errnop); + if (rv & NS_TERMINATE) + break; + } +fin: + if (!stayopen && st->fp != NULL) { + fclose(st->fp); + st->fp = NULL; + } + if (rv == NS_SUCCESS && retval != NULL) + *(struct group **)retval = grp; + return (rv); +#undef set_lookup_type +} + + +/* + * common group line matching and parsing + */ +int +__gr_match_entry(const char *line, size_t linesize, enum nss_lookup_type how, + const char *name, gid_t gid) +{ + size_t namesize; + const char *p, *eol; + char *q; + unsigned long n; + int i, needed; + + if (linesize == 0 || is_comment_line(line, linesize)) + return (NS_NOTFOUND); + switch (how) { + case nss_lt_name: needed = 1; break; + case nss_lt_id: needed = 2; break; + default: needed = 2; break; + } + eol = &line[linesize]; + for (p = line, i = 0; i < needed && p < eol; p++) + if (*p == ':') + i++; + if (i < needed) + return (NS_NOTFOUND); + switch (how) { + case nss_lt_name: + namesize = strlen(name); + if (namesize + 1 == (size_t)(p - line) && + memcmp(line, name, namesize) == 0) + return (NS_SUCCESS); + break; + case nss_lt_id: + n = strtoul(p, &q, 10); + if (q < eol && *q == ':' && gid == (gid_t)n) + return (NS_SUCCESS); + break; + case nss_lt_all: + return (NS_SUCCESS); + default: + break; + } + return (NS_NOTFOUND); +} + + +int +__gr_parse_entry(char *line, size_t linesize, struct group *grp, char *membuf, + size_t membufsize, int *errnop) +{ + char *s_gid, *s_mem, *p, **members; + unsigned long n; + int maxmembers; + + memset(grp, 0, sizeof(*grp)); + members = (char **)_ALIGN(membuf); + membufsize -= (char *)members - membuf; + maxmembers = membufsize / sizeof(*members); + if (maxmembers <= 0 || + (grp->gr_name = strsep(&line, ":")) == NULL || + grp->gr_name[0] == '\0' || + (grp->gr_passwd = strsep(&line, ":")) == NULL || + (s_gid = strsep(&line, ":")) == NULL || + s_gid[0] == '\0') + return (NS_NOTFOUND); + s_mem = line; + n = strtoul(s_gid, &s_gid, 10); + if (s_gid[0] != '\0') + return (NS_NOTFOUND); + grp->gr_gid = (gid_t)n; + grp->gr_mem = members; + while (maxmembers > 1 && s_mem != NULL) { + p = strsep(&s_mem, ","); + if (p != NULL && *p != '\0') { + *members++ = p; + maxmembers--; + } + } + *members = NULL; + if (s_mem == NULL) + return (NS_SUCCESS); + else { + *errnop = ERANGE; + return (NS_RETURN); + } +} diff --git a/src/lib/libc/gen/getgrouplist.c b/src/lib/libc/gen/getgrouplist.c new file mode 100644 index 0000000..e01cad8 --- /dev/null +++ b/src/lib/libc/gen/getgrouplist.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 1991, 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[] = "@(#)getgrouplist.c 8.2 (Berkeley) 12/8/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getgrouplist.c,v 1.13 2003/02/16 17:29:09 nectar Exp $"); + +/* + * get credential + */ +#include +#include +#include + +int +getgrouplist(uname, agroup, groups, grpcnt) + const char *uname; + gid_t agroup; + gid_t *groups; + int *grpcnt; +{ + struct group *grp; + int i, maxgroups, ngroups, ret; + + ret = 0; + ngroups = 0; + maxgroups = *grpcnt; + /* + * When installing primary group, duplicate it; + * the first element of groups is the effective gid + * and will be overwritten when a setgid file is executed. + */ + groups[ngroups++] = agroup; + if (maxgroups > 1) + groups[ngroups++] = agroup; + /* + * Scan the group file to find additional groups. + */ + setgrent(); + while ((grp = getgrent()) != NULL) { + for (i = 0; i < ngroups; i++) { + if (grp->gr_gid == groups[i]) + goto skip; + } + for (i = 0; grp->gr_mem[i]; i++) { + if (!strcmp(grp->gr_mem[i], uname)) { + if (ngroups >= maxgroups) { + ret = -1; + break; + } + groups[ngroups++] = grp->gr_gid; + break; + } + } +skip: + ; + } + endgrent(); + *grpcnt = ngroups; + return (ret); +} diff --git a/src/lib/libc/gen/gethostname.c b/src/lib/libc/gen/gethostname.c new file mode 100644 index 0000000..9071be2 --- /dev/null +++ b/src/lib/libc/gen/gethostname.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/gethostname.c,v 1.5 2003/08/19 23:01:46 wollman Exp $"); + +#include +#include + +#include + +int +gethostname(name, namelen) + char *name; + size_t namelen; +{ + int mib[2]; + + /* Kluge to avoid ABI breakage. */ + namelen = (int)namelen; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTNAME; + if (sysctl(mib, 2, name, &namelen, NULL, 0) == -1) { + if (errno == ENOMEM) + errno = ENAMETOOLONG; + return (-1); + } + return (0); +} diff --git a/src/lib/libc/gen/getloadavg.c b/src/lib/libc/gen/getloadavg.c new file mode 100644 index 0000000..c3450f1 --- /dev/null +++ b/src/lib/libc/gen/getloadavg.c @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 1989, 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[] = "@(#)getloadavg.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getloadavg.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include +#include +#include +#include +#include + +#include + +/* + * getloadavg() -- Get system load averages. + * + * Put `nelem' samples into `loadavg' array. + * Return number of samples retrieved, or -1 on error. + */ +int +getloadavg(loadavg, nelem) + double loadavg[]; + int nelem; +{ + struct loadavg loadinfo; + int i, mib[2]; + size_t size; + + mib[0] = CTL_VM; + mib[1] = VM_LOADAVG; + size = sizeof(loadinfo); + if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0) + return (-1); + + nelem = MIN(nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t)); + for (i = 0; i < nelem; i++) + loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale; + return (nelem); +} diff --git a/src/lib/libc/gen/getlogin.c b/src/lib/libc/gen/getlogin.c new file mode 100644 index 0000000..6e3208c --- /dev/null +++ b/src/lib/libc/gen/getlogin.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)getlogin.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getlogin.c,v 1.9 2003/10/29 10:45:01 tjr Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include "namespace.h" +#include +#include "un-namespace.h" + +#include "libc_private.h" + +#define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&logname_mutex) +#define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&logname_mutex) + +extern int _getlogin(char *, int); + +int _logname_valid; /* known to setlogin() */ +static pthread_mutex_t logname_mutex = PTHREAD_MUTEX_INITIALIZER; + +static char * +getlogin_basic(int *status) +{ + static char logname[MAXLOGNAME]; + + if (_logname_valid == 0) { + if (_getlogin(logname, sizeof(logname)) < 0) { + *status = errno; + return (NULL); + } + _logname_valid = 1; + } + *status = 0; + return (*logname ? logname : NULL); +} + +char * +getlogin(void) +{ + char *result; + int status; + + THREAD_LOCK(); + result = getlogin_basic(&status); + THREAD_UNLOCK(); + return (result); +} + +int +getlogin_r(char *logname, int namelen) +{ + char *result; + int len; + int status; + + THREAD_LOCK(); + result = getlogin_basic(&status); + if (status == 0) { + if ((len = strlen(result) + 1) > namelen) + status = ERANGE; + else + strncpy(logname, result, len); + } + THREAD_UNLOCK(); + return (status); +} diff --git a/src/lib/libc/gen/getmntinfo.c b/src/lib/libc/gen/getmntinfo.c new file mode 100644 index 0000000..383df1e --- /dev/null +++ b/src/lib/libc/gen/getmntinfo.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)getmntinfo.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getmntinfo.c,v 1.4 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include +#include +#include + +/* + * Return information about mounted filesystems. + */ +int +getmntinfo(mntbufp, flags) + struct statfs **mntbufp; + int flags; +{ + static struct statfs *mntbuf; + static int mntsize; + static long bufsize; + + if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) + return (0); + if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) + return (0); + while (bufsize <= mntsize * sizeof(struct statfs)) { + if (mntbuf) + free(mntbuf); + bufsize = (mntsize + 1) * sizeof(struct statfs); + if ((mntbuf = (struct statfs *)malloc(bufsize)) == 0) + return (0); + if ((mntsize = getfsstat(mntbuf, bufsize, flags)) < 0) + return (0); + } + *mntbufp = mntbuf; + return (mntsize); +} diff --git a/src/lib/libc/gen/getnetgrent.c b/src/lib/libc/gen/getnetgrent.c new file mode 100644 index 0000000..eb3b1a2 --- /dev/null +++ b/src/lib/libc/gen/getnetgrent.c @@ -0,0 +1,635 @@ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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[] = "@(#)getnetgrent.c 8.2 (Berkeley) 4/27/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getnetgrent.c,v 1.30 2003/01/03 23:55:58 tjr Exp $"); + +#include +#include +#include +#include +#include + +#ifdef YP +/* + * Notes: + * We want to be able to use NIS netgroups properly while retaining + * the ability to use a local /etc/netgroup file. Unfortunately, you + * can't really do both at the same time - at least, not efficiently. + * NetBSD deals with this problem by creating a netgroup database + * using Berkeley DB (just like the password database) that allows + * for lookups using netgroup, netgroup.byuser or netgroup.byhost + * searches. This is a neat idea, but I don't have time to implement + * something like that now. (I think ultimately it would be nice + * if we DB-fied the group and netgroup stuff all in one shot, but + * for now I'm satisfied just to have something that works well + * without requiring massive code changes.) + * + * Therefore, to still permit the use of the local file and maintain + * optimum NIS performance, we allow for the following conditions: + * + * - If /etc/netgroup does not exist and NIS is turned on, we use + * NIS netgroups only. + * + * - If /etc/netgroup exists but is empty, we use NIS netgroups + * only. + * + * - If /etc/netgroup exists and contains _only_ a '+', we use + * NIS netgroups only. + * + * - If /etc/netgroup exists, contains locally defined netgroups + * and a '+', we use a mixture of NIS and the local entries. + * This method should return the same NIS data as just using + * NIS alone, but it will be slower if the NIS netgroup database + * is large (innetgr() in particular will suffer since extra + * processing has to be done in order to determine memberships + * using just the raw netgroup data). + * + * - If /etc/netgroup exists and contains only locally defined + * netgroup entries, we use just those local entries and ignore + * NIS (this is the original, pre-NIS behavior). + */ + +#include +#include +#include +#include +#include +#include +#include +static char *_netgr_yp_domain; +int _use_only_yp; +static int _netgr_yp_enabled; +static int _yp_innetgr; +#endif + +#ifndef _PATH_NETGROUP +#define _PATH_NETGROUP "/etc/netgroup" +#endif + +/* + * Static Variables and functions used by setnetgrent(), getnetgrent() and + * endnetgrent(). + * There are two linked lists: + * - linelist is just used by setnetgrent() to parse the net group file via. + * parse_netgrp() + * - netgrp is the list of entries for the current netgroup + */ +struct linelist { + struct linelist *l_next; /* Chain ptr. */ + int l_parsed; /* Flag for cycles */ + char *l_groupname; /* Name of netgroup */ + char *l_line; /* Netgroup entrie(s) to be parsed */ +}; + +struct netgrp { + struct netgrp *ng_next; /* Chain ptr */ + char *ng_str[3]; /* Field pointers, see below */ +}; +#define NG_HOST 0 /* Host name */ +#define NG_USER 1 /* User name */ +#define NG_DOM 2 /* and Domain name */ + +static struct linelist *linehead = (struct linelist *)0; +static struct netgrp *nextgrp = (struct netgrp *)0; +static struct { + struct netgrp *gr; + char *grname; +} grouphead = { + (struct netgrp *)0, + (char *)0, +}; +static FILE *netf = (FILE *)0; +static int parse_netgrp(); +static struct linelist *read_for_group(); +void setnetgrent(), endnetgrent(); +int getnetgrent(), innetgr(); + +#define LINSIZ 1024 /* Length of netgroup file line */ + +/* + * setnetgrent() + * Parse the netgroup file looking for the netgroup and build the list + * of netgrp structures. Let parse_netgrp() and read_for_group() do + * most of the work. + */ +void +setnetgrent(group) + char *group; +{ +#ifdef YP + struct stat _yp_statp; + char _yp_plus; +#endif + + /* Sanity check */ + + if (group == NULL || !strlen(group)) + return; + + if (grouphead.gr == (struct netgrp *)0 || + strcmp(group, grouphead.grname)) { + endnetgrent(); +#ifdef YP + /* Presumed guilty until proven innocent. */ + _use_only_yp = 0; + /* + * If /etc/netgroup doesn't exist or is empty, + * use NIS exclusively. + */ + if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) && + errno == ENOENT) || _yp_statp.st_size == 0) + _use_only_yp = _netgr_yp_enabled = 1; + if ((netf = fopen(_PATH_NETGROUP,"r")) != NULL ||_use_only_yp){ + /* + * Icky: grab the first character of the netgroup file + * and turn on NIS if it's a '+'. rewind the stream + * afterwards so we don't goof up read_for_group() later. + */ + if (netf) { + fscanf(netf, "%c", &_yp_plus); + rewind(netf); + if (_yp_plus == '+') + _use_only_yp = _netgr_yp_enabled = 1; + } + /* + * If we were called specifically for an innetgr() + * lookup and we're in NIS-only mode, short-circuit + * parse_netgroup() and cut directly to the chase. + */ + if (_use_only_yp && _yp_innetgr) { + /* dohw! */ + if (netf != NULL) + fclose(netf); + return; + } +#else + if (netf = fopen(_PATH_NETGROUP, "r")) { +#endif + if (parse_netgrp(group)) + endnetgrent(); + else { + grouphead.grname = (char *) + malloc(strlen(group) + 1); + strcpy(grouphead.grname, group); + } + if (netf) + fclose(netf); + } + } + nextgrp = grouphead.gr; +} + +/* + * Get the next netgroup off the list. + */ +int +getnetgrent(hostp, userp, domp) + char **hostp, **userp, **domp; +{ +#ifdef YP + _yp_innetgr = 0; +#endif + + if (nextgrp) { + *hostp = nextgrp->ng_str[NG_HOST]; + *userp = nextgrp->ng_str[NG_USER]; + *domp = nextgrp->ng_str[NG_DOM]; + nextgrp = nextgrp->ng_next; + return (1); + } + return (0); +} + +/* + * endnetgrent() - cleanup + */ +void +endnetgrent() +{ + struct linelist *lp, *olp; + struct netgrp *gp, *ogp; + + lp = linehead; + while (lp) { + olp = lp; + lp = lp->l_next; + free(olp->l_groupname); + free(olp->l_line); + free((char *)olp); + } + linehead = (struct linelist *)0; + if (grouphead.grname) { + free(grouphead.grname); + grouphead.grname = (char *)0; + } + gp = grouphead.gr; + while (gp) { + ogp = gp; + gp = gp->ng_next; + if (ogp->ng_str[NG_HOST]) + free(ogp->ng_str[NG_HOST]); + if (ogp->ng_str[NG_USER]) + free(ogp->ng_str[NG_USER]); + if (ogp->ng_str[NG_DOM]) + free(ogp->ng_str[NG_DOM]); + free((char *)ogp); + } + grouphead.gr = (struct netgrp *)0; +#ifdef YP + _netgr_yp_enabled = 0; +#endif +} + +#ifdef YP +static int _listmatch(list, group, len) + char *list, *group; + int len; +{ + char *ptr = list, *cptr; + int glen = strlen(group); + + /* skip possible leading whitespace */ + while(isspace((unsigned char)*ptr)) + ptr++; + + while (ptr < list + len) { + cptr = ptr; + while(*ptr != ',' && *ptr != '\0' && !isspace((unsigned char)*ptr)) + ptr++; + if (strncmp(cptr, group, glen) == 0 && glen == (ptr - cptr)) + return(1); + while(*ptr == ',' || isspace((unsigned char)*ptr)) + ptr++; + } + + return(0); +} + +static int _buildkey(key, str, dom, rotation) +char *key, *str, *dom; +int *rotation; +{ + (*rotation)++; + if (*rotation > 4) + return(0); + switch(*rotation) { + case(1): sprintf((char *)key, "%s.%s", str, dom ? dom : "*"); + break; + case(2): sprintf((char *)key, "%s.*", str); + break; + case(3): sprintf((char *)key, "*.%s", dom ? dom : "*"); + break; + case(4): sprintf((char *)key, "*.*"); + break; + } + return(1); +} +#endif + +/* + * Search for a match in a netgroup. + */ +int +innetgr(group, host, user, dom) + const char *group, *host, *user, *dom; +{ + char *hst, *usr, *dm; +#ifdef YP + char *result; + int resultlen; + int rv; +#endif + /* Sanity check */ + + if (group == NULL || !strlen(group)) + return (0); + +#ifdef YP + _yp_innetgr = 1; +#endif + setnetgrent(group); +#ifdef YP + _yp_innetgr = 0; + /* + * If we're in NIS-only mode, do the search using + * NIS 'reverse netgroup' lookups. + */ + if (_use_only_yp) { + char _key[MAXHOSTNAMELEN]; + int rot = 0, y = 0; + + if(yp_get_default_domain(&_netgr_yp_domain)) + return(0); + while(_buildkey(_key, user ? user : host, dom, &rot)) { + y = yp_match(_netgr_yp_domain, user? "netgroup.byuser": + "netgroup.byhost", _key, strlen(_key), &result, + &resultlen); + if (y) { + /* + * If we get an error other than 'no + * such key in map' then something is + * wrong and we should stop the search. + */ + if (y != YPERR_KEY) + break; + } else { + rv = _listmatch(result, group, resultlen); + free(result); + if (rv) + return(1); + else + return(0); + } + } + /* + * Couldn't match using NIS-exclusive mode. If the error + * was YPERR_MAP, then the failure happened because there + * was no netgroup.byhost or netgroup.byuser map. The odds + * are we are talking to a Sun NIS+ server in YP emulation + * mode; if this is the case, then we have to do the check + * the 'old-fashioned' way by grovelling through the netgroup + * map and resolving memberships on the fly. + */ + if (y != YPERR_MAP) + return(0); + } + + setnetgrent(group); +#endif /* YP */ + + while (getnetgrent(&hst, &usr, &dm)) + if ((host == NULL || hst == NULL || !strcmp(host, hst)) && + (user == NULL || usr == NULL || !strcmp(user, usr)) && + ( dom == NULL || dm == NULL || !strcmp(dom, dm))) { + endnetgrent(); + return (1); + } + endnetgrent(); + return (0); +} + +/* + * Parse the netgroup file setting up the linked lists. + */ +static int +parse_netgrp(group) + char *group; +{ + char *spos, *epos; + int len, strpos; +#ifdef DEBUG + int fields; +#endif + char *pos, *gpos; + struct netgrp *grp; + struct linelist *lp = linehead; + + /* + * First, see if the line has already been read in. + */ + while (lp) { + if (!strcmp(group, lp->l_groupname)) + break; + lp = lp->l_next; + } + if (lp == (struct linelist *)0 && + (lp = read_for_group(group)) == (struct linelist *)0) + return (1); + if (lp->l_parsed) { +#ifdef DEBUG + /* + * This error message is largely superflous since the + * code handles the error condition sucessfully, and + * spewing it out from inside libc can actually hose + * certain programs. + */ + fprintf(stderr, "Cycle in netgroup %s\n", lp->l_groupname); +#endif + return (1); + } else + lp->l_parsed = 1; + pos = lp->l_line; + /* Watch for null pointer dereferences, dammit! */ + while (pos != NULL && *pos != '\0') { + if (*pos == '(') { + grp = (struct netgrp *)malloc(sizeof (struct netgrp)); + bzero((char *)grp, sizeof (struct netgrp)); + grp->ng_next = grouphead.gr; + grouphead.gr = grp; + pos++; + gpos = strsep(&pos, ")"); +#ifdef DEBUG + fields = 0; +#endif + for (strpos = 0; strpos < 3; strpos++) { + if ((spos = strsep(&gpos, ","))) { +#ifdef DEBUG + fields++; +#endif + while (*spos == ' ' || *spos == '\t') + spos++; + if ((epos = strpbrk(spos, " \t"))) { + *epos = '\0'; + len = epos - spos; + } else + len = strlen(spos); + if (len > 0) { + grp->ng_str[strpos] = (char *) + malloc(len + 1); + bcopy(spos, grp->ng_str[strpos], + len + 1); + } + } else { + /* + * All other systems I've tested + * return NULL for empty netgroup + * fields. It's up to user programs + * to handle the NULLs appropriately. + */ + grp->ng_str[strpos] = NULL; + } + } +#ifdef DEBUG + /* + * Note: on other platforms, malformed netgroup + * entries are not normally flagged. While we + * can catch bad entries and report them, we should + * stay silent by default for compatibility's sake. + */ + if (fields < 3) + fprintf(stderr, "Bad entry (%s%s%s%s%s) in netgroup \"%s\"\n", + grp->ng_str[NG_HOST] == NULL ? "" : grp->ng_str[NG_HOST], + grp->ng_str[NG_USER] == NULL ? "" : ",", + grp->ng_str[NG_USER] == NULL ? "" : grp->ng_str[NG_USER], + grp->ng_str[NG_DOM] == NULL ? "" : ",", + grp->ng_str[NG_DOM] == NULL ? "" : grp->ng_str[NG_DOM], + lp->l_groupname); +#endif + } else { + spos = strsep(&pos, ", \t"); + if (parse_netgrp(spos)) + continue; + } + if (pos == NULL) + break; + while (*pos == ' ' || *pos == ',' || *pos == '\t') + pos++; + } + return (0); +} + +/* + * Read the netgroup file and save lines until the line for the netgroup + * is found. Return 1 if eof is encountered. + */ +static struct linelist * +read_for_group(group) + char *group; +{ + char *pos, *spos, *linep, *olinep; + int len, olen; + int cont; + struct linelist *lp; + char line[LINSIZ + 2]; +#ifdef YP + char *result; + int resultlen; + + while (_netgr_yp_enabled || fgets(line, LINSIZ, netf) != NULL) { + if (_netgr_yp_enabled) { + if(!_netgr_yp_domain) + if(yp_get_default_domain(&_netgr_yp_domain)) + continue; + if (yp_match(_netgr_yp_domain, "netgroup", group, + strlen(group), &result, &resultlen)) { + free(result); + if (_use_only_yp) + return ((struct linelist *)0); + else { + _netgr_yp_enabled = 0; + continue; + } + } + snprintf(line, LINSIZ, "%s %s", group, result); + free(result); + } +#else + while (fgets(line, LINSIZ, netf) != NULL) { +#endif + pos = (char *)&line; +#ifdef YP + if (*pos == '+') { + _netgr_yp_enabled = 1; + continue; + } +#endif + if (*pos == '#') + continue; + while (*pos == ' ' || *pos == '\t') + pos++; + spos = pos; + while (*pos != ' ' && *pos != '\t' && *pos != '\n' && + *pos != '\0') + pos++; + len = pos - spos; + while (*pos == ' ' || *pos == '\t') + pos++; + if (*pos != '\n' && *pos != '\0') { + lp = (struct linelist *)malloc(sizeof (*lp)); + lp->l_parsed = 0; + lp->l_groupname = (char *)malloc(len + 1); + bcopy(spos, lp->l_groupname, len); + *(lp->l_groupname + len) = '\0'; + len = strlen(pos); + olen = 0; + + /* + * Loop around handling line continuations. + */ + do { + if (*(pos + len - 1) == '\n') + len--; + if (*(pos + len - 1) == '\\') { + len--; + cont = 1; + } else + cont = 0; + if (len > 0) { + linep = (char *)malloc(olen + len + 1); + if (olen > 0) { + bcopy(olinep, linep, olen); + free(olinep); + } + bcopy(pos, linep + olen, len); + olen += len; + *(linep + olen) = '\0'; + olinep = linep; + } + if (cont) { + if (fgets(line, LINSIZ, netf)) { + pos = line; + len = strlen(pos); + } else + cont = 0; + } + } while (cont); + lp->l_line = linep; + lp->l_next = linehead; + linehead = lp; + + /* + * If this is the one we wanted, we are done. + */ + if (!strcmp(lp->l_groupname, group)) + return (lp); + } + } +#ifdef YP + /* + * Yucky. The recursive nature of this whole mess might require + * us to make more than one pass through the netgroup file. + * This might be best left outside the #ifdef YP, but YP is + * defined by default anyway, so I'll leave it like this + * until I know better. + */ + rewind(netf); +#endif + return ((struct linelist *)0); +} diff --git a/src/lib/libc/gen/getobjformat.c b/src/lib/libc/gen/getobjformat.c new file mode 100644 index 0000000..d1ac7df --- /dev/null +++ b/src/lib/libc/gen/getobjformat.c @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 1998 John D. Polstra + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getobjformat.c,v 1.7 2002/09/17 01:48:50 peter Exp $"); + +#include +#include +#include +#include +#include + +int +getobjformat(char *buf, size_t bufsize, int *argcp, char **argv) +{ + + if (bufsize < 4) + return -1; + strcpy(buf, "elf"); + return 3; +} diff --git a/src/lib/libc/gen/getosreldate.c b/src/lib/libc/gen/getosreldate.c new file mode 100644 index 0000000..97cd9bf --- /dev/null +++ b/src/lib/libc/gen/getosreldate.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)gethostid.c 8.1 (Berkeley) 6/2/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getosreldate.c,v 1.6 2002/05/28 16:59:39 alfred Exp $"); + +#include +#include + +int +getosreldate(void) +{ + int mib[2]; + size_t size; + int value; + + mib[0] = CTL_KERN; + mib[1] = KERN_OSRELDATE; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); + return (value); +} diff --git a/src/lib/libc/gen/getpagesize.c b/src/lib/libc/gen/getpagesize.c new file mode 100644 index 0000000..3c8881e --- /dev/null +++ b/src/lib/libc/gen/getpagesize.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)getpagesize.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getpagesize.c,v 1.4 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include + +/* + * This is unlikely to change over the running time of any + * program, so we cache the result to save some syscalls. + * + * NB: This function may be called from malloc(3) at initialization + * NB: so must not result in a malloc(3) related call! + */ + +int +getpagesize() +{ + int mib[2]; + static int value; + size_t size; + + if (!value) { + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); + } + return (value); +} diff --git a/src/lib/libc/gen/getpeereid.c b/src/lib/libc/gen/getpeereid.c new file mode 100644 index 0000000..5608c48 --- /dev/null +++ b/src/lib/libc/gen/getpeereid.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2001 Dima Dorfman. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getpeereid.c,v 1.6 2002/12/16 13:42:13 maxim Exp $"); + +#include +#include +#include +#include + +#include +#include + +int +getpeereid(int s, uid_t *euid, gid_t *egid) +{ + struct xucred xuc; + socklen_t xuclen; + int error; + + xuclen = sizeof(xuc); + error = getsockopt(s, 0, LOCAL_PEERCRED, &xuc, &xuclen); + if (error != 0) + return (error); + if (xuc.cr_version != XUCRED_VERSION) + return (EINVAL); + *euid = xuc.cr_uid; + *egid = xuc.cr_gid; + return (0); +} diff --git a/src/lib/libc/gen/getprogname.c b/src/lib/libc/gen/getprogname.c new file mode 100644 index 0000000..4be82e3 --- /dev/null +++ b/src/lib/libc/gen/getprogname.c @@ -0,0 +1,17 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getprogname.c,v 1.4 2002/03/29 22:43:41 markm Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" + +#include "libc_private.h" + +__weak_reference(_getprogname, getprogname); + +const char * +_getprogname(void) +{ + + return (__progname); +} diff --git a/src/lib/libc/gen/getpwent.c b/src/lib/libc/gen/getpwent.c new file mode 100644 index 0000000..cba41da --- /dev/null +++ b/src/lib/libc/gen/getpwent.c @@ -0,0 +1,1732 @@ +/*- + * Copyright (c) 2003 Networks Associates Technology, Inc. + * All rights reserved. + * + * This software was developed for the FreeBSD Project by + * Jacques A. Vidrine, Safeport Network Services, and Network + * Associates Laboratories, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getpwent.c,v 1.89 2004/05/17 18:27:05 kientzle Exp $"); + +#include "namespace.h" +#include +#ifdef YP +#include +#include +#include +#endif +#include +#include +#include +#ifdef HESIOD +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include +#include "libc_private.h" +#include "pw_scan.h" +#include "nss_tls.h" + +#ifndef CTASSERT +#define CTASSERT(x) _CTASSERT(x, __LINE__) +#define _CTASSERT(x, y) __CTASSERT(x, y) +#define __CTASSERT(x, y) typedef char __assert_ ## y [(x) ? 1 : -1] +#endif + +/* Counter as stored in /etc/pwd.db */ +typedef int pwkeynum; + +CTASSERT(MAXLOGNAME > sizeof(uid_t)); +CTASSERT(MAXLOGNAME > sizeof(pwkeynum)); + +enum constants { + PWD_STORAGE_INITIAL = 1 << 10, /* 1 KByte */ + PWD_STORAGE_MAX = 1 << 20, /* 1 MByte */ + SETPWENT = 1, + ENDPWENT = 2, + HESIOD_NAME_MAX = 256 +}; + +static const ns_src defaultsrc[] = { + { NSSRC_COMPAT, NS_SUCCESS }, + { NULL, 0 } +}; + +int __pw_match_entry(const char *, size_t, enum nss_lookup_type, + const char *, uid_t); +int __pw_parse_entry(char *, size_t, struct passwd *, int, int *errnop); + +static void pwd_init(struct passwd *); + +union key { + const char *name; + uid_t uid; +}; + +static struct passwd *getpw(int (*fn)(union key, struct passwd *, char *, + size_t, struct passwd **), union key); +static int wrap_getpwnam_r(union key, struct passwd *, char *, + size_t, struct passwd **); +static int wrap_getpwuid_r(union key, struct passwd *, char *, size_t, + struct passwd **); +static int wrap_getpwent_r(union key, struct passwd *, char *, size_t, + struct passwd **); + +static int pwdb_match_entry_v3(char *, size_t, enum nss_lookup_type, + const char *, uid_t); +static int pwdb_parse_entry_v3(char *, size_t, struct passwd *, int *); +static int pwdb_match_entry_v4(char *, size_t, enum nss_lookup_type, + const char *, uid_t); +static int pwdb_parse_entry_v4(char *, size_t, struct passwd *, int *); + + +struct { + int (*match)(char *, size_t, enum nss_lookup_type, const char *, + uid_t); + int (*parse)(char *, size_t, struct passwd *, int *); +} pwdb_versions[] = { + { NULL, NULL }, /* version 0 */ + { NULL, NULL }, /* version 1 */ + { NULL, NULL }, /* version 2 */ + { pwdb_match_entry_v3, pwdb_parse_entry_v3 }, /* version 3 */ + { pwdb_match_entry_v4, pwdb_parse_entry_v4 }, /* version 4 */ +}; + + +struct files_state { + DB *db; + pwkeynum keynum; + int stayopen; + int version; +}; +static void files_endstate(void *); +NSS_TLS_HANDLING(files); +static DB *pwdbopen(int *); +static void files_endstate(void *); +static int files_setpwent(void *, void *, va_list); +static int files_passwd(void *, void *, va_list); + + +#ifdef HESIOD +struct dns_state { + long counter; +}; +static void dns_endstate(void *); +NSS_TLS_HANDLING(dns); +static int dns_setpwent(void *, void *, va_list); +static int dns_passwd(void *, void *, va_list); +#endif + + +#ifdef YP +struct nis_state { + char domain[MAXHOSTNAMELEN]; + int done; + char *key; + int keylen; +}; +static void nis_endstate(void *); +NSS_TLS_HANDLING(nis); +static int nis_setpwent(void *, void *, va_list); +static int nis_passwd(void *, void *, va_list); +static int nis_map(char *, enum nss_lookup_type, char *, size_t, int *); +static int nis_adjunct(char *, const char *, char *, size_t); +#endif + + +struct compat_state { + DB *db; + pwkeynum keynum; + int stayopen; + int version; + DB *exclude; + struct passwd template; + char *name; + enum _compat { + COMPAT_MODE_OFF = 0, + COMPAT_MODE_ALL, + COMPAT_MODE_NAME, + COMPAT_MODE_NETGROUP + } compat; +}; +static void compat_endstate(void *); +NSS_TLS_HANDLING(compat); +static int compat_setpwent(void *, void *, va_list); +static int compat_passwd(void *, void *, va_list); +static void compat_clear_template(struct passwd *); +static int compat_set_template(struct passwd *, struct passwd *); +static int compat_use_template(struct passwd *, struct passwd *, char *, + size_t); +static int compat_redispatch(struct compat_state *, enum nss_lookup_type, + enum nss_lookup_type, const char *, const char *, uid_t, + struct passwd *, char *, size_t, int *); +void +setpwent(void) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_setpwent, (void *)SETPWENT }, +#ifdef HESIOD + { NSSRC_DNS, dns_setpwent, (void *)SETPWENT }, +#endif +#ifdef YP + { NSSRC_NIS, nis_setpwent, (void *)SETPWENT }, +#endif + { NSSRC_COMPAT, compat_setpwent, (void *)SETPWENT }, + { NULL, NULL, NULL } + }; + (void)_nsdispatch(NULL, dtab, NSDB_PASSWD, "setpwent", defaultsrc, 0); +} + + +int +setpassent(int stayopen) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_setpwent, (void *)SETPWENT }, +#ifdef HESIOD + { NSSRC_DNS, dns_setpwent, (void *)SETPWENT }, +#endif +#ifdef YP + { NSSRC_NIS, nis_setpwent, (void *)SETPWENT }, +#endif + { NSSRC_COMPAT, compat_setpwent, (void *)SETPWENT }, + { NULL, NULL, NULL } + }; + (void)_nsdispatch(NULL, dtab, NSDB_PASSWD, "setpwent", defaultsrc, + stayopen); + return (1); +} + + +void +endpwent(void) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_setpwent, (void *)ENDPWENT }, +#ifdef HESIOD + { NSSRC_DNS, dns_setpwent, (void *)ENDPWENT }, +#endif +#ifdef YP + { NSSRC_NIS, nis_setpwent, (void *)ENDPWENT }, +#endif + { NSSRC_COMPAT, compat_setpwent, (void *)ENDPWENT }, + { NULL, NULL, NULL } + }; + (void)_nsdispatch(NULL, dtab, NSDB_PASSWD, "endpwent", defaultsrc); +} + + +int +getpwent_r(struct passwd *pwd, char *buffer, size_t bufsize, + struct passwd **result) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_passwd, (void *)nss_lt_all }, +#ifdef HESIOD + { NSSRC_DNS, dns_passwd, (void *)nss_lt_all }, +#endif +#ifdef YP + { NSSRC_NIS, nis_passwd, (void *)nss_lt_all }, +#endif + { NSSRC_COMPAT, compat_passwd, (void *)nss_lt_all }, + { NULL, NULL, NULL } + }; + int rv, ret_errno; + + pwd_init(pwd); + ret_errno = 0; + *result = NULL; + rv = _nsdispatch(result, dtab, NSDB_PASSWD, "getpwent_r", defaultsrc, + pwd, buffer, bufsize, &ret_errno); + if (rv == NS_SUCCESS) + return (0); + else + return (ret_errno); +} + + +int +getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, + struct passwd **result) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_passwd, (void *)nss_lt_name }, +#ifdef HESIOD + { NSSRC_DNS, dns_passwd, (void *)nss_lt_name }, +#endif +#ifdef YP + { NSSRC_NIS, nis_passwd, (void *)nss_lt_name }, +#endif + { NSSRC_COMPAT, compat_passwd, (void *)nss_lt_name }, + { NULL, NULL, NULL } + }; + int rv, ret_errno; + + pwd_init(pwd); + ret_errno = 0; + *result = NULL; + rv = _nsdispatch(result, dtab, NSDB_PASSWD, "getpwnam_r", defaultsrc, + name, pwd, buffer, bufsize, &ret_errno); + if (rv == NS_SUCCESS) + return (0); + else + return (ret_errno); +} + + +int +getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, + struct passwd **result) +{ + static const ns_dtab dtab[] = { + { NSSRC_FILES, files_passwd, (void *)nss_lt_id }, +#ifdef HESIOD + { NSSRC_DNS, dns_passwd, (void *)nss_lt_id }, +#endif +#ifdef YP + { NSSRC_NIS, nis_passwd, (void *)nss_lt_id }, +#endif + { NSSRC_COMPAT, compat_passwd, (void *)nss_lt_id }, + { NULL, NULL, NULL } + }; + int rv, ret_errno; + + pwd_init(pwd); + ret_errno = 0; + *result = NULL; + rv = _nsdispatch(result, dtab, NSDB_PASSWD, "getpwuid_r", defaultsrc, + uid, pwd, buffer, bufsize, &ret_errno); + if (rv == NS_SUCCESS) + return (0); + else + return (ret_errno); +} + + +static void +pwd_init(struct passwd *pwd) +{ + static char nul[] = ""; + + memset(pwd, 0, sizeof(*pwd)); + pwd->pw_uid = (uid_t)-1; /* Considered least likely to lead to */ + pwd->pw_gid = (gid_t)-1; /* a security issue. */ + pwd->pw_name = nul; + pwd->pw_passwd = nul; + pwd->pw_class = nul; + pwd->pw_gecos = nul; + pwd->pw_dir = nul; + pwd->pw_shell = nul; +} + + +static struct passwd pwd; +static char *pwd_storage; +static size_t pwd_storage_size; + + +static struct passwd * +getpw(int (*fn)(union key, struct passwd *, char *, size_t, struct passwd **), + union key key) +{ + int rv; + struct passwd *res; + + if (pwd_storage == NULL) { + pwd_storage = malloc(PWD_STORAGE_INITIAL); + if (pwd_storage == NULL) + return (NULL); + pwd_storage_size = PWD_STORAGE_INITIAL; + } + do { + rv = fn(key, &pwd, pwd_storage, pwd_storage_size, &res); + if (res == NULL && rv == ERANGE) { + free(pwd_storage); + if ((pwd_storage_size << 1) > PWD_STORAGE_MAX) { + pwd_storage = NULL; + errno = ERANGE; + return (NULL); + } + pwd_storage_size <<= 1; + pwd_storage = malloc(pwd_storage_size); + if (pwd_storage == NULL) + return (NULL); + } + } while (res == NULL && rv == ERANGE); + if (rv != 0) + errno = rv; + return (res); +} + + +static int +wrap_getpwnam_r(union key key, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **res) +{ + return (getpwnam_r(key.name, pwd, buffer, bufsize, res)); +} + + +static int +wrap_getpwuid_r(union key key, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **res) +{ + return (getpwuid_r(key.uid, pwd, buffer, bufsize, res)); +} + + +static int +wrap_getpwent_r(union key key __unused, struct passwd *pwd, char *buffer, + size_t bufsize, struct passwd **res) +{ + return (getpwent_r(pwd, buffer, bufsize, res)); +} + + +struct passwd * +getpwnam(const char *name) +{ + union key key; + + key.name = name; + return (getpw(wrap_getpwnam_r, key)); +} + + +struct passwd * +getpwuid(uid_t uid) +{ + union key key; + + key.uid = uid; + return (getpw(wrap_getpwuid_r, key)); +} + + +struct passwd * +getpwent(void) +{ + union key key; + + key.uid = 0; /* not used */ + return (getpw(wrap_getpwent_r, key)); +} + + +/* + * files backend + */ +static DB * +pwdbopen(int *version) +{ + DB *res; + DBT key, entry; + int rv; + + if (geteuid() != 0 || + (res = dbopen(_PATH_SMP_DB, O_RDONLY, 0, DB_HASH, NULL)) == NULL) + res = dbopen(_PATH_MP_DB, O_RDONLY, 0, DB_HASH, NULL); + if (res == NULL) + return (NULL); + key.data = _PWD_VERSION_KEY; + key.size = strlen(_PWD_VERSION_KEY); + rv = res->get(res, &key, &entry, 0); + if (rv == 0) + *version = *(unsigned char *)entry.data; + else + *version = 3; + if (*version < 3 || + *version >= sizeof(pwdb_versions)/sizeof(pwdb_versions[0])) { + syslog(LOG_CRIT, "Unsupported password database version %d", + *version); + res->close(res); + res = NULL; + } + return (res); +} + + +static void +files_endstate(void *p) +{ + DB *db; + + if (p == NULL) + return; + db = ((struct files_state *)p)->db; + if (db != NULL) + db->close(db); + free(p); +} + + +static int +files_setpwent(void *retval, void *mdata, va_list ap) +{ + struct files_state *st; + int rv, stayopen; + + rv = files_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + switch ((enum constants)mdata) { + case SETPWENT: + stayopen = va_arg(ap, int); + st->keynum = 0; + if (stayopen) + st->db = pwdbopen(&st->version); + st->stayopen = stayopen; + break; + case ENDPWENT: + if (st->db != NULL) { + (void)st->db->close(st->db); + st->db = NULL; + } + break; + default: + break; + } + return (NS_UNAVAIL); +} + + +static int +files_passwd(void *retval, void *mdata, va_list ap) +{ + char keybuf[MAXLOGNAME + 1]; + DBT key, entry; + struct files_state *st; + enum nss_lookup_type how; + const char *name; + struct passwd *pwd; + char *buffer; + size_t bufsize, namesize; + uid_t uid; + uint32_t store; + int rv, stayopen, *errnop; + + name = NULL; + uid = (uid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + keybuf[0] = _PW_KEYBYNAME; + break; + case nss_lt_id: + uid = va_arg(ap, uid_t); + keybuf[0] = _PW_KEYBYUID; + break; + case nss_lt_all: + keybuf[0] = _PW_KEYBYNUM; + break; + default: + rv = NS_NOTFOUND; + goto fin; + } + pwd = va_arg(ap, struct passwd *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = files_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (how == nss_lt_all && st->keynum < 0) { + rv = NS_NOTFOUND; + goto fin; + } + if (st->db == NULL && + (st->db = pwdbopen(&st->version)) == NULL) { + *errnop = errno; + rv = NS_UNAVAIL; + goto fin; + } + if (how == nss_lt_all) + stayopen = 1; + else + stayopen = st->stayopen; + key.data = keybuf; + do { + switch (how) { + case nss_lt_name: + /* MAXLOGNAME includes NUL byte, but we do not + * include the NUL byte in the key. + */ + namesize = strlcpy(&keybuf[1], name, sizeof(keybuf)-1); + if (namesize >= sizeof(keybuf)-1) { + *errnop = EINVAL; + rv = NS_NOTFOUND; + goto fin; + } + key.size = namesize + 1; + break; + case nss_lt_id: + if (st->version < _PWD_CURRENT_VERSION) { + memcpy(&keybuf[1], &uid, sizeof(uid)); + key.size = sizeof(uid) + 1; + } else { + store = htonl(uid); + memcpy(&keybuf[1], &store, sizeof(store)); + key.size = sizeof(store) + 1; + } + break; + case nss_lt_all: + st->keynum++; + if (st->version < _PWD_CURRENT_VERSION) { + memcpy(&keybuf[1], &st->keynum, + sizeof(st->keynum)); + key.size = sizeof(st->keynum) + 1; + } else { + store = htonl(st->keynum); + memcpy(&keybuf[1], &store, sizeof(store)); + key.size = sizeof(store) + 1; + } + break; + } + keybuf[0] = _PW_VERSIONED(keybuf[0], st->version); + rv = st->db->get(st->db, &key, &entry, 0); + if (rv < 0 || rv > 1) { /* should never return > 1 */ + *errnop = errno; + rv = NS_UNAVAIL; + goto fin; + } else if (rv == 1) { + if (how == nss_lt_all) + st->keynum = -1; + rv = NS_NOTFOUND; + goto fin; + } + rv = pwdb_versions[st->version].match(entry.data, entry.size, + how, name, uid); + if (rv != NS_SUCCESS) + continue; + if (entry.size > bufsize) { + *errnop = ERANGE; + rv = NS_RETURN; + break; + } + memcpy(buffer, entry.data, entry.size); + rv = pwdb_versions[st->version].parse(buffer, entry.size, pwd, + errnop); + } while (how == nss_lt_all && !(rv & NS_TERMINATE)); +fin: + if (!stayopen && st->db != NULL) { + (void)st->db->close(st->db); + st->db = NULL; + } + if (rv == NS_SUCCESS) { + pwd->pw_fields &= ~_PWF_SOURCE; + pwd->pw_fields |= _PWF_FILES; + if (retval != NULL) + *(struct passwd **)retval = pwd; + } + return (rv); +} + + +static int +pwdb_match_entry_v3(char *entry, size_t entrysize, enum nss_lookup_type how, + const char *name, uid_t uid) +{ + const char *p, *eom; + uid_t uid2; + + eom = &entry[entrysize]; + for (p = entry; p < eom; p++) + if (*p == '\0') + break; + if (*p != '\0') + return (NS_NOTFOUND); + if (how == nss_lt_all) + return (NS_SUCCESS); + if (how == nss_lt_name) + return (strcmp(name, entry) == 0 ? NS_SUCCESS : NS_NOTFOUND); + for (p++; p < eom; p++) + if (*p == '\0') + break; + if (*p != '\0' || (++p) + sizeof(uid) >= eom) + return (NS_NOTFOUND); + memcpy(&uid2, p, sizeof(uid2)); + return (uid == uid2 ? NS_SUCCESS : NS_NOTFOUND); +} + + +static int +pwdb_parse_entry_v3(char *buffer, size_t bufsize, struct passwd *pwd, + int *errnop) +{ + char *p, *eom; + int32_t pw_change, pw_expire; + + /* THIS CODE MUST MATCH THAT IN pwd_mkdb. */ + p = buffer; + eom = &buffer[bufsize]; +#define STRING(field) do { \ + (field) = p; \ + while (p < eom && *p != '\0') \ + p++; \ + if (p >= eom) \ + return (NS_NOTFOUND); \ + p++; \ + } while (0) +#define SCALAR(field) do { \ + if (p + sizeof(field) > eom) \ + return (NS_NOTFOUND); \ + memcpy(&(field), p, sizeof(field)); \ + p += sizeof(field); \ + } while (0) + STRING(pwd->pw_name); + STRING(pwd->pw_passwd); + SCALAR(pwd->pw_uid); + SCALAR(pwd->pw_gid); + SCALAR(pw_change); + STRING(pwd->pw_class); + STRING(pwd->pw_gecos); + STRING(pwd->pw_dir); + STRING(pwd->pw_shell); + SCALAR(pw_expire); + SCALAR(pwd->pw_fields); +#undef STRING +#undef SCALAR + pwd->pw_change = pw_change; + pwd->pw_expire = pw_expire; + return (NS_SUCCESS); +} + + +static int +pwdb_match_entry_v4(char *entry, size_t entrysize, enum nss_lookup_type how, + const char *name, uid_t uid) +{ + const char *p, *eom; + uint32_t uid2; + + eom = &entry[entrysize]; + for (p = entry; p < eom; p++) + if (*p == '\0') + break; + if (*p != '\0') + return (NS_NOTFOUND); + if (how == nss_lt_all) + return (NS_SUCCESS); + if (how == nss_lt_name) + return (strcmp(name, entry) == 0 ? NS_SUCCESS : NS_NOTFOUND); + for (p++; p < eom; p++) + if (*p == '\0') + break; + if (*p != '\0' || (++p) + sizeof(uid) >= eom) + return (NS_NOTFOUND); + memcpy(&uid2, p, sizeof(uid2)); + uid2 = ntohl(uid2); + return (uid == (uid_t)uid2 ? NS_SUCCESS : NS_NOTFOUND); +} + + +static int +pwdb_parse_entry_v4(char *buffer, size_t bufsize, struct passwd *pwd, + int *errnop) +{ + char *p, *eom; + uint32_t n; + + /* THIS CODE MUST MATCH THAT IN pwd_mkdb. */ + p = buffer; + eom = &buffer[bufsize]; +#define STRING(field) do { \ + (field) = p; \ + while (p < eom && *p != '\0') \ + p++; \ + if (p >= eom) \ + return (NS_NOTFOUND); \ + p++; \ + } while (0) +#define SCALAR(field) do { \ + if (p + sizeof(n) > eom) \ + return (NS_NOTFOUND); \ + memcpy(&n, p, sizeof(n)); \ + (field) = ntohl(n); \ + p += sizeof(n); \ + } while (0) + STRING(pwd->pw_name); + STRING(pwd->pw_passwd); + SCALAR(pwd->pw_uid); + SCALAR(pwd->pw_gid); + SCALAR(pwd->pw_change); + STRING(pwd->pw_class); + STRING(pwd->pw_gecos); + STRING(pwd->pw_dir); + STRING(pwd->pw_shell); + SCALAR(pwd->pw_expire); + SCALAR(pwd->pw_fields); +#undef STRING +#undef SCALAR + return (NS_SUCCESS); +} + + +#ifdef HESIOD +/* + * dns backend + */ +static void +dns_endstate(void *p) +{ + free(p); +} + + +static int +dns_setpwent(void *retval, void *mdata, va_list ap) +{ + struct dns_state *st; + int rv; + + rv = dns_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + st->counter = 0; + return (NS_UNAVAIL); +} + + +static int +dns_passwd(void *retval, void *mdata, va_list ap) +{ + char buf[HESIOD_NAME_MAX]; + struct dns_state *st; + struct passwd *pwd; + const char *name, *label; + void *ctx; + char *buffer, **hes; + size_t bufsize, linesize; + uid_t uid; + enum nss_lookup_type how; + int rv, *errnop; + + ctx = NULL; + hes = NULL; + name = NULL; + uid = (uid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + break; + case nss_lt_id: + uid = va_arg(ap, uid_t); + break; + case nss_lt_all: + break; + } + pwd = va_arg(ap, struct passwd *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = dns_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (hesiod_init(&ctx) != 0) { + *errnop = errno; + rv = NS_UNAVAIL; + goto fin; + } + do { + rv = NS_NOTFOUND; + switch (how) { + case nss_lt_name: + label = name; + break; + case nss_lt_id: + if (snprintf(buf, sizeof(buf), "%lu", + (unsigned long)uid) >= sizeof(buf)) + goto fin; + label = buf; + break; + case nss_lt_all: + if (st->counter < 0) + goto fin; + if (snprintf(buf, sizeof(buf), "passwd-%ld", + st->counter++) >= sizeof(buf)) + goto fin; + label = buf; + break; + } + hes = hesiod_resolve(ctx, label, + how == nss_lt_id ? "uid" : "passwd"); + if (hes == NULL) { + if (how == nss_lt_all) + st->counter = -1; + if (errno != ENOENT) + *errnop = errno; + goto fin; + } + rv = __pw_match_entry(hes[0], strlen(hes[0]), how, name, uid); + if (rv != NS_SUCCESS) { + hesiod_free_list(ctx, hes); + hes = NULL; + continue; + } + linesize = strlcpy(buffer, hes[0], bufsize); + if (linesize >= bufsize) { + *errnop = ERANGE; + rv = NS_RETURN; + continue; + } + hesiod_free_list(ctx, hes); + hes = NULL; + rv = __pw_parse_entry(buffer, bufsize, pwd, 0, errnop); + } while (how == nss_lt_all && !(rv & NS_TERMINATE)); +fin: + if (hes != NULL) + hesiod_free_list(ctx, hes); + if (ctx != NULL) + hesiod_end(ctx); + if (rv == NS_SUCCESS) { + pwd->pw_fields &= ~_PWF_SOURCE; + pwd->pw_fields |= _PWF_HESIOD; + if (retval != NULL) + *(struct passwd **)retval = pwd; + } + return (rv); +} +#endif /* HESIOD */ + + +#ifdef YP +/* + * nis backend + */ +static void +nis_endstate(void *p) +{ + free(((struct nis_state *)p)->key); + free(p); +} + +/* + * Test for the presence of special FreeBSD-specific master.passwd.by* + * maps. We do this using yp_order(). If it fails, then either the server + * doesn't have the map, or the YPPROC_ORDER procedure isn't supported by + * the server (Sun NIS+ servers in YP compat mode behave this way). If + * the master.passwd.by* maps don't exist, then let the lookup routine try + * the regular passwd.by* maps instead. If the lookup routine fails, it + * can return an error as needed. + */ +static int +nis_map(char *domain, enum nss_lookup_type how, char *buffer, size_t bufsize, + int *master) +{ + int rv, order; + + *master = 0; + if (geteuid() == 0) { + if (snprintf(buffer, bufsize, "master.passwd.by%s", + (how == nss_lt_id) ? "uid" : "name") >= bufsize) + return (NS_UNAVAIL); + rv = yp_order(domain, buffer, &order); + if (rv == 0) { + *master = 1; + return (NS_SUCCESS); + } + } + + if (snprintf(buffer, bufsize, "passwd.by%s", + (how == nss_lt_id) ? "uid" : "name") >= bufsize) + return (NS_UNAVAIL); + + return (NS_SUCCESS); +} + + +static int +nis_adjunct(char *domain, const char *name, char *buffer, size_t bufsize) +{ + int rv; + char *result, *p, *q, *eor; + int resultlen; + + result = NULL; + rv = yp_match(domain, "passwd.adjunct.byname", name, strlen(name), + &result, &resultlen); + if (rv != 0) + rv = 1; + else { + eor = &result[resultlen]; + p = memchr(result, ':', eor - result); + if (p != NULL && ++p < eor && + (q = memchr(p, ':', eor - p)) != NULL) { + if (q - p >= bufsize) + rv = -1; + else { + memcpy(buffer, p, q - p); + buffer[q - p] ='\0'; + } + } else + rv = 1; + } + free(result); + return (rv); +} + + +static int +nis_setpwent(void *retval, void *mdata, va_list ap) +{ + struct nis_state *st; + int rv; + + rv = nis_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + st->done = 0; + free(st->key); + st->key = NULL; + return (NS_UNAVAIL); +} + + +static int +nis_passwd(void *retval, void *mdata, va_list ap) +{ + char map[YPMAXMAP]; + struct nis_state *st; + struct passwd *pwd; + const char *name; + char *buffer, *key, *result; + size_t bufsize; + uid_t uid; + enum nss_lookup_type how; + int *errnop, keylen, resultlen, rv, master; + + name = NULL; + uid = (uid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + break; + case nss_lt_id: + uid = va_arg(ap, uid_t); + break; + case nss_lt_all: + break; + } + pwd = va_arg(ap, struct passwd *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = nis_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (st->domain[0] == '\0') { + if (getdomainname(st->domain, sizeof(st->domain)) != 0) { + *errnop = errno; + return (NS_UNAVAIL); + } + } + rv = nis_map(st->domain, how, map, sizeof(map), &master); + if (rv != NS_SUCCESS) + return (rv); + result = NULL; + do { + rv = NS_NOTFOUND; + switch (how) { + case nss_lt_name: + if (strlcpy(buffer, name, bufsize) >= bufsize) + goto erange; + break; + case nss_lt_id: + if (snprintf(buffer, bufsize, "%lu", + (unsigned long)uid) >= bufsize) + goto erange; + break; + case nss_lt_all: + if (st->done) + goto fin; + break; + } + result = NULL; + if (how == nss_lt_all) { + if (st->key == NULL) + rv = yp_first(st->domain, map, &st->key, + &st->keylen, &result, &resultlen); + else { + key = st->key; + keylen = st->keylen; + st->key = NULL; + rv = yp_next(st->domain, map, key, keylen, + &st->key, &st->keylen, &result, + &resultlen); + free(key); + } + if (rv != 0) { + free(result); + free(st->key); + st->key = NULL; + if (rv == YPERR_NOMORE) + st->done = 1; + else + rv = NS_UNAVAIL; + goto fin; + } + } else { + rv = yp_match(st->domain, map, buffer, strlen(buffer), + &result, &resultlen); + if (rv == YPERR_KEY) { + rv = NS_NOTFOUND; + continue; + } else if (rv != 0) { + free(result); + rv = NS_UNAVAIL; + continue; + } + } + if (resultlen >= bufsize) + goto erange; + memcpy(buffer, result, resultlen); + buffer[resultlen] = '\0'; + free(result); + rv = __pw_match_entry(buffer, resultlen, how, name, uid); + if (rv == NS_SUCCESS) + rv = __pw_parse_entry(buffer, resultlen, pwd, master, + errnop); + } while (how == nss_lt_all && !(rv & NS_TERMINATE)); +fin: + if (rv == NS_SUCCESS) { + if (strstr(pwd->pw_passwd, "##") != NULL) { + rv = nis_adjunct(st->domain, pwd->pw_name, + &buffer[resultlen+1], bufsize-resultlen-1); + if (rv < 0) + goto erange; + else if (rv == 0) + pwd->pw_passwd = &buffer[resultlen+1]; + } + pwd->pw_fields &= ~_PWF_SOURCE; + pwd->pw_fields |= _PWF_NIS; + if (retval != NULL) + *(struct passwd **)retval = pwd; + rv = NS_SUCCESS; + } + return (rv); +erange: + *errnop = ERANGE; + return (NS_RETURN); +} +#endif /* YP */ + + +/* + * compat backend + */ +static void +compat_clear_template(struct passwd *template) +{ + + free(template->pw_passwd); + free(template->pw_gecos); + free(template->pw_dir); + free(template->pw_shell); + memset(template, 0, sizeof(*template)); +} + + +static int +compat_set_template(struct passwd *src, struct passwd *template) +{ + + compat_clear_template(template); +#ifdef PW_OVERRIDE_PASSWD + if ((src->pw_fields & _PWF_PASSWD) && + (template->pw_passwd = strdup(src->pw_passwd)) == NULL) + goto enomem; +#endif + if (src->pw_fields & _PWF_UID) + template->pw_uid = src->pw_uid; + if (src->pw_fields & _PWF_GID) + template->pw_gid = src->pw_gid; + if ((src->pw_fields & _PWF_GECOS) && + (template->pw_gecos = strdup(src->pw_gecos)) == NULL) + goto enomem; + if ((src->pw_fields & _PWF_DIR) && + (template->pw_dir = strdup(src->pw_dir)) == NULL) + goto enomem; + if ((src->pw_fields & _PWF_SHELL) && + (template->pw_shell = strdup(src->pw_shell)) == NULL) + goto enomem; + template->pw_fields = src->pw_fields; + return (0); +enomem: + syslog(LOG_ERR, "getpwent memory allocation failure"); + return (-1); +} + + +static int +compat_use_template(struct passwd *pwd, struct passwd *template, char *buffer, + size_t bufsize) +{ + struct passwd hold; + char *copy, *p, *q, *eob; + size_t n; + + /* We cannot know the layout of the password fields in `buffer', + * so we have to copy everything. + */ + if (template->pw_fields == 0) /* nothing to fill-in */ + return (0); + n = 0; + n += pwd->pw_name != NULL ? strlen(pwd->pw_name) + 1 : 0; + n += pwd->pw_passwd != NULL ? strlen(pwd->pw_passwd) + 1 : 0; + n += pwd->pw_class != NULL ? strlen(pwd->pw_class) + 1 : 0; + n += pwd->pw_gecos != NULL ? strlen(pwd->pw_gecos) + 1 : 0; + n += pwd->pw_dir != NULL ? strlen(pwd->pw_dir) + 1 : 0; + n += pwd->pw_shell != NULL ? strlen(pwd->pw_shell) + 1 : 0; + copy = malloc(n); + if (copy == NULL) { + syslog(LOG_ERR, "getpwent memory allocation failure"); + return (ENOMEM); + } + p = copy; + eob = ©[n]; +#define COPY(field) do { \ + if (pwd->field == NULL) \ + hold.field = NULL; \ + else { \ + hold.field = p; \ + p += strlcpy(p, pwd->field, eob-p) + 1; \ + } \ +} while (0) + COPY(pw_name); + COPY(pw_passwd); + COPY(pw_class); + COPY(pw_gecos); + COPY(pw_dir); + COPY(pw_shell); +#undef COPY + p = buffer; + eob = &buffer[bufsize]; +#define COPY(field, flag) do { \ + q = (template->pw_fields & flag) ? template->field : hold.field; \ + if (q == NULL) \ + pwd->field = NULL; \ + else { \ + pwd->field = p; \ + if ((n = strlcpy(p, q, eob-p)) >= eob-p) { \ + free(copy); \ + return (ERANGE); \ + } \ + p += n + 1; \ + } \ +} while (0) + COPY(pw_name, 0); +#ifdef PW_OVERRIDE_PASSWD + COPY(pw_passwd, _PWF_PASSWD); +#else + COPY(pw_passwd, 0); +#endif + COPY(pw_class, 0); + COPY(pw_gecos, _PWF_GECOS); + COPY(pw_dir, _PWF_DIR); + COPY(pw_shell, _PWF_SHELL); +#undef COPY +#define COPY(field, flag) do { \ + if (template->pw_fields & flag) \ + pwd->field = template->field; \ +} while (0) + COPY(pw_uid, _PWF_UID); + COPY(pw_gid, _PWF_GID); +#undef COPY + free(copy); + return (0); +} + + +static int +compat_exclude(const char *name, DB **db) +{ + DBT key, data; + + if (*db == NULL && + (*db = dbopen(NULL, O_RDWR, 600, DB_HASH, 0)) == NULL) + return (errno); + key.size = strlen(name); + key.data = (char *)name; + data.size = 0; + data.data = NULL; + + if ((*db)->put(*db, &key, &data, 0) == -1) + return (errno); + return (0); +} + + +static int +compat_is_excluded(const char *name, DB *db) +{ + DBT key, data; + + if (db == NULL) + return (0); + key.size = strlen(name); + key.data = (char *)name; + return (db->get(db, &key, &data, 0) == 0); +} + + +static int +compat_redispatch(struct compat_state *st, enum nss_lookup_type how, + enum nss_lookup_type lookup_how, const char *name, const char *lookup_name, + uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, int *errnop) +{ + static const ns_src compatsrc[] = { +#ifdef YP + { NSSRC_NIS, NS_SUCCESS }, +#endif + { NULL, 0 } + }; + ns_dtab dtab[] = { +#ifdef YP + { NSSRC_NIS, nis_passwd, NULL }, +#endif +#ifdef HESIOD + { NSSRC_DNS, dns_passwd, NULL }, +#endif + { NULL, NULL, NULL } + }; + void *discard; + int rv, e, i; + + for (i = 0; i < sizeof(dtab)/sizeof(dtab[0]) - 1; i++) + dtab[i].mdata = (void *)lookup_how; +more: + pwd_init(pwd); + switch (lookup_how) { + case nss_lt_all: + rv = _nsdispatch(&discard, dtab, NSDB_PASSWD_COMPAT, + "getpwent_r", compatsrc, pwd, buffer, bufsize, + errnop); + break; + case nss_lt_id: + rv = _nsdispatch(&discard, dtab, NSDB_PASSWD_COMPAT, + "getpwuid_r", compatsrc, uid, pwd, buffer, + bufsize, errnop); + break; + case nss_lt_name: + rv = _nsdispatch(&discard, dtab, NSDB_PASSWD_COMPAT, + "getpwnam_r", compatsrc, lookup_name, pwd, buffer, + bufsize, errnop); + break; + default: + return (NS_UNAVAIL); + } + if (rv != NS_SUCCESS) + return (rv); + if (compat_is_excluded(pwd->pw_name, st->exclude)) { + if (how == nss_lt_all) + goto more; + return (NS_NOTFOUND); + } + e = compat_use_template(pwd, &st->template, buffer, bufsize); + if (e != 0) { + *errnop = e; + if (e == ERANGE) + return (NS_RETURN); + else + return (NS_UNAVAIL); + } + switch (how) { + case nss_lt_name: + if (strcmp(name, pwd->pw_name) != 0) + return (NS_NOTFOUND); + break; + case nss_lt_id: + if (uid != pwd->pw_uid) + return (NS_NOTFOUND); + break; + default: + break; + } + return (NS_SUCCESS); +} + + +static void +compat_endstate(void *p) +{ + struct compat_state *st; + + if (p == NULL) + return; + st = (struct compat_state *)p; + if (st->db != NULL) + st->db->close(st->db); + if (st->exclude != NULL) + st->exclude->close(st->exclude); + compat_clear_template(&st->template); + free(p); +} + + +static int +compat_setpwent(void *retval, void *mdata, va_list ap) +{ + static const ns_src compatsrc[] = { +#ifdef YP + { NSSRC_NIS, NS_SUCCESS }, +#endif + { NULL, 0 } + }; + ns_dtab dtab[] = { +#ifdef YP + { NSSRC_NIS, nis_setpwent, NULL }, +#endif +#ifdef HESIOD + { NSSRC_DNS, dns_setpwent, NULL }, +#endif + { NULL, NULL, NULL } + }; + struct compat_state *st; + int rv, stayopen; + +#define set_setent(x, y) do { \ + int i; \ + \ + for (i = 0; i < (sizeof(x)/sizeof(x[0])) - 1; i++) \ + x[i].mdata = (void *)y; \ +} while (0) + + rv = compat_getstate(&st); + if (rv != 0) + return (NS_UNAVAIL); + switch ((enum constants)mdata) { + case SETPWENT: + stayopen = va_arg(ap, int); + st->keynum = 0; + if (stayopen) + st->db = pwdbopen(&st->version); + st->stayopen = stayopen; + set_setent(dtab, mdata); + (void)_nsdispatch(NULL, dtab, NSDB_PASSWD_COMPAT, "setpwent", + compatsrc, 0); + break; + case ENDPWENT: + if (st->db != NULL) { + (void)st->db->close(st->db); + st->db = NULL; + } + set_setent(dtab, mdata); + (void)_nsdispatch(NULL, dtab, NSDB_PASSWD_COMPAT, "endpwent", + compatsrc, 0); + break; + default: + break; + } + return (NS_UNAVAIL); +#undef set_setent +} + + +static int +compat_passwd(void *retval, void *mdata, va_list ap) +{ + char keybuf[MAXLOGNAME + 1]; + DBT key, entry; + struct compat_state *st; + enum nss_lookup_type how; + const char *name; + struct passwd *pwd; + char *buffer, *pw_name; + char *host, *user, *domain; + size_t bufsize; + uid_t uid; + uint32_t store; + int rv, from_compat, stayopen, *errnop; + + from_compat = 0; + name = NULL; + uid = (uid_t)-1; + how = (enum nss_lookup_type)mdata; + switch (how) { + case nss_lt_name: + name = va_arg(ap, const char *); + break; + case nss_lt_id: + uid = va_arg(ap, uid_t); + break; + case nss_lt_all: + break; + default: + rv = NS_NOTFOUND; + goto fin; + } + pwd = va_arg(ap, struct passwd *); + buffer = va_arg(ap, char *); + bufsize = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + *errnop = compat_getstate(&st); + if (*errnop != 0) + return (NS_UNAVAIL); + if (how == nss_lt_all && st->keynum < 0) { + rv = NS_NOTFOUND; + goto fin; + } + if (st->db == NULL && + (st->db = pwdbopen(&st->version)) == NULL) { + *errnop = errno; + rv = NS_UNAVAIL; + goto fin; + } + if (how == nss_lt_all) { + if (st->keynum < 0) { + rv = NS_NOTFOUND; + goto fin; + } + stayopen = 1; + } else { + st->keynum = 0; + stayopen = st->stayopen; + } +docompat: + rv = NS_NOTFOUND; + switch (st->compat) { + case COMPAT_MODE_ALL: + rv = compat_redispatch(st, how, how, name, name, uid, pwd, + buffer, bufsize, errnop); + if (rv != NS_SUCCESS) + st->compat = COMPAT_MODE_OFF; + break; + case COMPAT_MODE_NETGROUP: + /* XXX getnetgrent is not thread-safe. */ + do { + rv = getnetgrent(&host, &user, &domain); + if (rv == 0) { + endnetgrent(); + st->compat = COMPAT_MODE_OFF; + rv = NS_NOTFOUND; + continue; + } else if (user == NULL || user[0] == '\0') + continue; + rv = compat_redispatch(st, how, nss_lt_name, name, + user, uid, pwd, buffer, bufsize, errnop); + } while (st->compat == COMPAT_MODE_NETGROUP && + !(rv & NS_TERMINATE)); + break; + case COMPAT_MODE_NAME: + rv = compat_redispatch(st, how, nss_lt_name, name, st->name, + uid, pwd, buffer, bufsize, errnop); + free(st->name); + st->name = NULL; + st->compat = COMPAT_MODE_OFF; + break; + default: + break; + } + if (rv & NS_TERMINATE) { + from_compat = 1; + goto fin; + } + key.data = keybuf; + rv = NS_NOTFOUND; + while (st->keynum >= 0) { + st->keynum++; + if (st->version < _PWD_CURRENT_VERSION) { + memcpy(&keybuf[1], &st->keynum, sizeof(st->keynum)); + key.size = sizeof(st->keynum) + 1; + } else { + store = htonl(st->keynum); + memcpy(&keybuf[1], &store, sizeof(store)); + key.size = sizeof(store) + 1; + } + keybuf[0] = _PW_VERSIONED(_PW_KEYBYNUM, st->version); + rv = st->db->get(st->db, &key, &entry, 0); + if (rv < 0 || rv > 1) { /* should never return > 1 */ + *errnop = errno; + rv = NS_UNAVAIL; + goto fin; + } else if (rv == 1) { + st->keynum = -1; + rv = NS_NOTFOUND; + goto fin; + } + pw_name = (char *)entry.data; + switch (pw_name[0]) { + case '+': + switch (pw_name[1]) { + case '\0': + st->compat = COMPAT_MODE_ALL; + break; + case '@': + setnetgrent(&pw_name[2]); + st->compat = COMPAT_MODE_NETGROUP; + break; + default: + st->name = strdup(&pw_name[1]); + if (st->name == NULL) { + syslog(LOG_ERR, + "getpwent memory allocation failure"); + *errnop = ENOMEM; + rv = NS_UNAVAIL; + break; + } + st->compat = COMPAT_MODE_NAME; + } + if (entry.size > bufsize) { + *errnop = ERANGE; + rv = NS_RETURN; + goto fin; + } + memcpy(buffer, entry.data, entry.size); + rv = pwdb_versions[st->version].parse(buffer, + entry.size, pwd, errnop); + if (rv != NS_SUCCESS) + ; + else if (compat_set_template(pwd, &st->template) < 0) { + *errnop = ENOMEM; + rv = NS_UNAVAIL; + goto fin; + } + goto docompat; + case '-': + switch (pw_name[1]) { + case '\0': + /* XXX Maybe syslog warning */ + continue; + case '@': + setnetgrent(&pw_name[2]); + while (getnetgrent(&host, &user, &domain) != + 0) { + if (user != NULL && user[0] != '\0') + compat_exclude(user, + &st->exclude); + } + endnetgrent(); + continue; + default: + compat_exclude(&pw_name[1], &st->exclude); + continue; + } + break; + default: + break; + } + if (compat_is_excluded((char *)entry.data, st->exclude)) + continue; + rv = pwdb_versions[st->version].match(entry.data, entry.size, + how, name, uid); + if (rv == NS_RETURN) + break; + else if (rv != NS_SUCCESS) + continue; + if (entry.size > bufsize) { + *errnop = ERANGE; + rv = NS_RETURN; + break; + } + memcpy(buffer, entry.data, entry.size); + rv = pwdb_versions[st->version].parse(buffer, entry.size, pwd, + errnop); + if (rv & NS_TERMINATE) + break; + } +fin: + if (!stayopen && st->db != NULL) { + (void)st->db->close(st->db); + st->db = NULL; + } + if (rv == NS_SUCCESS) { + if (!from_compat) { + pwd->pw_fields &= ~_PWF_SOURCE; + pwd->pw_fields |= _PWF_FILES; + } + if (retval != NULL) + *(struct passwd **)retval = pwd; + } + return (rv); +} + + +/* + * common passwd line matching and parsing + */ +int +__pw_match_entry(const char *entry, size_t entrysize, enum nss_lookup_type how, + const char *name, uid_t uid) +{ + const char *p, *eom; + char *q; + size_t len; + unsigned long m; + + eom = entry + entrysize; + for (p = entry; p < eom; p++) + if (*p == ':') + break; + if (*p != ':') + return (NS_NOTFOUND); + if (how == nss_lt_all) + return (NS_SUCCESS); + if (how == nss_lt_name) { + len = strlen(name); + if (len == (p - entry) && memcmp(name, entry, len) == 0) + return (NS_SUCCESS); + else + return (NS_NOTFOUND); + } + for (p++; p < eom; p++) + if (*p == ':') + break; + if (*p != ':') + return (NS_NOTFOUND); + m = strtoul(++p, &q, 10); + if (q[0] != ':' || (uid_t)m != uid) + return (NS_NOTFOUND); + else + return (NS_SUCCESS); +} + + +/* XXX buffer must be NUL-terminated. errnop is not set correctly. */ +int +__pw_parse_entry(char *buffer, size_t bufsize __unused, struct passwd *pwd, + int master, int *errnop __unused) +{ + + if (__pw_scan(buffer, pwd, master ? _PWSCAN_MASTER : 0) == 0) + return (NS_NOTFOUND); + else + return (NS_SUCCESS); +} diff --git a/src/lib/libc/gen/getttyent.c b/src/lib/libc/gen/getttyent.c new file mode 100644 index 0000000..64506fa --- /dev/null +++ b/src/lib/libc/gen/getttyent.c @@ -0,0 +1,266 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)getttyent.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getttyent.c,v 1.12 2002/02/01 01:32:19 obrien Exp $"); + +#include +#include +#include +#include +#include + +static char zapchar; +static FILE *tf; +static size_t lbsize; +static char *line; + +#define MALLOCCHUNK 100 + +static char *skip(char *); +static char *value(char *); + +struct ttyent * +getttynam(tty) + const char *tty; +{ + struct ttyent *t; + + if (strncmp(tty, "/dev/", 5) == 0) + tty += 5; + setttyent(); + while ( (t = getttyent()) ) + if (!strcmp(tty, t->ty_name)) + break; + endttyent(); + return (t); +} + +struct ttyent * +getttyent() +{ + static struct ttyent tty; + char *p; + int c; + size_t i; + + if (!tf && !setttyent()) + return (NULL); + for (;;) { + if (!fgets(p = line, lbsize, tf)) + return (NULL); + /* extend buffer if line was too big, and retry */ + while (!index(p, '\n')) { + i = strlen(p); + lbsize += MALLOCCHUNK; + if ((p = realloc(line, lbsize)) == NULL) { + (void)endttyent(); + return (NULL); + } + line = p; + if (!fgets(&line[i], lbsize - i, tf)) + return (NULL); + } + while (isspace((unsigned char)*p)) + ++p; + if (*p && *p != '#') + break; + } + +#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace((unsigned char)p[sizeof(e) - 1]) +#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '=' + + zapchar = 0; + tty.ty_name = p; + p = skip(p); + if (!*(tty.ty_getty = p)) + tty.ty_getty = tty.ty_type = NULL; + else { + p = skip(p); + if (!*(tty.ty_type = p)) + tty.ty_type = NULL; + else { + /* compatibility kludge: handle network/dialup specially */ + if (scmp(_TTYS_DIALUP)) + tty.ty_status |= TTY_DIALUP; + else if (scmp(_TTYS_NETWORK)) + tty.ty_status |= TTY_NETWORK; + p = skip(p); + } + } + tty.ty_status = 0; + tty.ty_window = NULL; + tty.ty_group = _TTYS_NOGROUP; + + for (; *p; p = skip(p)) { + if (scmp(_TTYS_OFF)) + tty.ty_status &= ~TTY_ON; + else if (scmp(_TTYS_ON)) + tty.ty_status |= TTY_ON; + else if (scmp(_TTYS_SECURE)) + tty.ty_status |= TTY_SECURE; + else if (scmp(_TTYS_INSECURE)) + tty.ty_status &= ~TTY_SECURE; + else if (scmp(_TTYS_DIALUP)) + tty.ty_status |= TTY_DIALUP; + else if (scmp(_TTYS_NETWORK)) + tty.ty_status |= TTY_NETWORK; + else if (vcmp(_TTYS_WINDOW)) + tty.ty_window = value(p); + else if (vcmp(_TTYS_GROUP)) + tty.ty_group = value(p); + else + break; + } + + if (zapchar == '#' || *p == '#') + while ((c = *++p) == ' ' || c == '\t') + ; + tty.ty_comment = p; + if (*p == 0) + tty.ty_comment = 0; + if ( (p = index(p, '\n')) ) + *p = '\0'; + return (&tty); +} + +#define QUOTED 1 + +/* + * Skip over the current field, removing quotes, and return a pointer to + * the next field. + */ +static char * +skip(p) + char *p; +{ + char *t; + int c, q; + + for (q = 0, t = p; (c = *p) != '\0'; p++) { + if (c == '"') { + q ^= QUOTED; /* obscure, but nice */ + continue; + } + if (q == QUOTED && *p == '\\' && *(p+1) == '"') + p++; + *t++ = *p; + if (q == QUOTED) + continue; + if (c == '#') { + zapchar = c; + *p = 0; + break; + } + if (c == '\t' || c == ' ' || c == '\n') { + zapchar = c; + *p++ = 0; + while ((c = *p) == '\t' || c == ' ' || c == '\n') + p++; + break; + } + } + *--t = '\0'; + return (p); +} + +static char * +value(p) + char *p; +{ + + return ((p = index(p, '=')) ? ++p : NULL); +} + +int +setttyent() +{ + + if (line == NULL) { + if ((line = malloc(MALLOCCHUNK)) == NULL) + return (0); + lbsize = MALLOCCHUNK; + } + if (tf) { + rewind(tf); + return (1); + } else if ( (tf = fopen(_PATH_TTYS, "r")) ) + return (1); + return (0); +} + +int +endttyent() +{ + int rval; + + /* + * NB: Don't free `line' because getttynam() + * may still be referencing it + */ + if (tf) { + rval = (fclose(tf) != EOF); + tf = NULL; + return (rval); + } + return (1); +} + +static int +isttystat(tty, flag) + const char *tty; + int flag; +{ + struct ttyent *t; + + return ((t = getttynam(tty)) == NULL) ? 0 : !!(t->ty_status & flag); +} + + +int +isdialuptty(tty) + const char *tty; +{ + + return isttystat(tty, TTY_DIALUP); +} + +int isnettty(tty) + const char *tty; +{ + + return isttystat(tty, TTY_NETWORK); +} diff --git a/src/lib/libc/gen/getusershell.c b/src/lib/libc/gen/getusershell.c new file mode 100644 index 0000000..b8fd9b4 --- /dev/null +++ b/src/lib/libc/gen/getusershell.c @@ -0,0 +1,274 @@ +/* + * Copyright (c) 1985, 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[] = "@(#)getusershell.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +/* $NetBSD: getusershell.c,v 1.17 1999/01/25 01:09:34 lukem Exp $ */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getusershell.c,v 1.9 2003/04/24 20:16:21 nectar Exp $"); + +#include "namespace.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HESIOD +#include +#endif +#ifdef YP +#include +#include +#include +#endif +#include "un-namespace.h" + +/* + * Local shells should NOT be added here. They should be added in + * /etc/shells. + */ + +static const char *const okshells[] = { _PATH_BSHELL, _PATH_CSHELL, NULL }; +static const char *const *curshell; +static StringList *sl; + +static const char *const *initshells(void); + +/* + * Get a list of shells from "shells" nsswitch database + */ +char * +getusershell(void) +{ + char *ret; + + if (curshell == NULL) + curshell = initshells(); + /*LINTED*/ + ret = (char *)*curshell; + if (ret != NULL) + curshell++; + return (ret); +} + +void +endusershell(void) +{ + if (sl) { + sl_free(sl, 1); + sl = NULL; + } + curshell = NULL; +} + +void +setusershell(void) +{ + + curshell = initshells(); +} + + +static int _local_initshells(void *, void *, va_list); + +/*ARGSUSED*/ +static int +_local_initshells(rv, cb_data, ap) + void *rv; + void *cb_data; + va_list ap; +{ + char *sp, *cp; + FILE *fp; + char line[MAXPATHLEN + 2]; + + if (sl) + sl_free(sl, 1); + sl = sl_init(); + + if ((fp = fopen(_PATH_SHELLS, "r")) == NULL) + return NS_UNAVAIL; + + sp = cp = line; + while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { + while (*cp != '#' && *cp != '/' && *cp != '\0') + cp++; + if (*cp == '#' || *cp == '\0') + continue; + sp = cp; + while (!isspace(*cp) && *cp != '#' && *cp != '\0') + cp++; + *cp++ = '\0'; + sl_add(sl, strdup(sp)); + } + (void)fclose(fp); + return NS_SUCCESS; +} + +#ifdef HESIOD +static int _dns_initshells(void *, void *, va_list); + +/*ARGSUSED*/ +static int +_dns_initshells(rv, cb_data, ap) + void *rv; + void *cb_data; + va_list ap; +{ + char shellname[] = "shells-XXXXX"; + int hsindex, hpi, r; + char **hp; + void *context; + + if (sl) + sl_free(sl, 1); + sl = sl_init(); + r = NS_UNAVAIL; + if (hesiod_init(&context) == -1) + return (r); + + for (hsindex = 0; ; hsindex++) { + snprintf(shellname, sizeof(shellname)-1, "shells-%d", hsindex); + hp = hesiod_resolve(context, shellname, "shells"); + if (hp == NULL) { + if (errno == ENOENT) { + if (hsindex == 0) + r = NS_NOTFOUND; + else + r = NS_SUCCESS; + } + break; + } else { + for (hpi = 0; hp[hpi]; hpi++) + sl_add(sl, hp[hpi]); + free(hp); + } + } + hesiod_end(context); + return (r); +} +#endif /* HESIOD */ + +#ifdef YP +static int _nis_initshells(void *, void *, va_list); + +/*ARGSUSED*/ +static int +_nis_initshells(rv, cb_data, ap) + void *rv; + void *cb_data; + va_list ap; +{ + static char *ypdomain; + char *key, *data; + char *lastkey; + int keylen, datalen; + int r; + + if (sl) + sl_free(sl, 1); + sl = sl_init(); + + if (ypdomain == NULL) { + switch (yp_get_default_domain(&ypdomain)) { + case 0: + break; + case YPERR_RESRC: + return NS_TRYAGAIN; + default: + return NS_UNAVAIL; + } + } + + /* + * `key' and `data' point to strings dynamically allocated by + * the yp_... functions. + * `data' is directly put into the stringlist of shells. + */ + key = data = NULL; + if (yp_first(ypdomain, "shells", &key, &keylen, &data, &datalen)) + return NS_UNAVAIL; + do { + data[datalen] = '\0'; /* clear trailing \n */ + sl_add(sl, data); + + lastkey = key; + r = yp_next(ypdomain, "shells", lastkey, keylen, + &key, &keylen, &data, &datalen); + free(lastkey); + } while (r == 0); + + if (r == YPERR_NOMORE) { + /* + * `data' and `key' ought to be NULL - do not try to free them. + */ + return NS_SUCCESS; + } + + return NS_UNAVAIL; +} +#endif /* YP */ + +static const char *const * +initshells() +{ + static const ns_dtab dtab[] = { + NS_FILES_CB(_local_initshells, NULL) + NS_DNS_CB(_dns_initshells, NULL) + NS_NIS_CB(_nis_initshells, NULL) + { 0 } + }; + if (sl) + sl_free(sl, 1); + sl = sl_init(); + + if (_nsdispatch(NULL, dtab, NSDB_SHELLS, "initshells", __nsdefaultsrc) + != NS_SUCCESS) { + if (sl) + sl_free(sl, 1); + sl = NULL; + return (okshells); + } + sl_add(sl, NULL); + + return (const char *const *)(sl->sl_str); +} diff --git a/src/lib/libc/gen/getvfsbyname.c b/src/lib/libc/gen/getvfsbyname.c new file mode 100644 index 0000000..be93b00 --- /dev/null +++ b/src/lib/libc/gen/getvfsbyname.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1995 + * 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[] = "@(#)kvm_getvfsbyname.c 8.1 (Berkeley) 4/3/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/getvfsbyname.c,v 1.10 2003/10/29 10:45:01 tjr Exp $"); + +#include +#include +#include +#include +#include +#include + +/* + * Given a filesystem name, determine if it is resident in the kernel, + * and if it is resident, return its xvfsconf structure. + */ +int +getvfsbyname(fsname, vfcp) + const char *fsname; + struct xvfsconf *vfcp; +{ + struct xvfsconf *xvfsp; + size_t buflen; + int cnt, i; + + if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) + return (-1); + xvfsp = malloc(buflen); + if (xvfsp == NULL) + return (-1); + if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) { + free(xvfsp); + return (-1); + } + cnt = buflen / sizeof(struct xvfsconf); + for (i = 0; i < cnt; i++) { + if (strcmp(fsname, xvfsp[i].vfc_name) == 0) { + memcpy(vfcp, xvfsp + i, sizeof(struct xvfsconf)); + free(xvfsp); + return (0); + } + } + free(xvfsp); + errno = ENOENT; + return (-1); +} diff --git a/src/lib/libc/gen/glob.c b/src/lib/libc/gen/glob.c new file mode 100644 index 0000000..0f37b36 --- /dev/null +++ b/src/lib/libc/gen/glob.c @@ -0,0 +1,902 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * 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[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.21 2003/10/29 10:45:01 tjr Exp $"); + +/* + * glob(3) -- a superset of the one defined in POSIX 1003.2. + * + * The [!...] convention to negate a range is supported (SysV, Posix, ksh). + * + * Optional extra services, controlled by flags not defined by POSIX: + * + * GLOB_QUOTE: + * Escaping convention: \ inhibits any special meaning the following + * character might have (except \ at end of string is retained). + * GLOB_MAGCHAR: + * Set in gl_flags if pattern contained a globbing character. + * GLOB_NOMAGIC: + * Same as GLOB_NOCHECK, but it will only append pattern if it did + * not contain any magic characters. [Used in csh style globbing] + * GLOB_ALTDIRFUNC: + * Use alternately specified directory access functions. + * GLOB_TILDE: + * expand ~user/foo to the /home/dir/of/user/foo + * GLOB_BRACE: + * expand {1,2}{a,b} to 1a 1b 2a 2b + * gl_matchc: + * Number of matches in the current invocation of glob. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "collate.h" + +#define DOLLAR '$' +#define DOT '.' +#define EOS '\0' +#define LBRACKET '[' +#define NOT '!' +#define QUESTION '?' +#define QUOTE '\\' +#define RANGE '-' +#define RBRACKET ']' +#define SEP '/' +#define STAR '*' +#define TILDE '~' +#define UNDERSCORE '_' +#define LBRACE '{' +#define RBRACE '}' +#define SLASH '/' +#define COMMA ',' + +#ifndef DEBUG + +#define M_QUOTE 0x8000 +#define M_PROTECT 0x4000 +#define M_MASK 0xffff +#define M_ASCII 0x00ff + +typedef u_short Char; + +#else + +#define M_QUOTE 0x80 +#define M_PROTECT 0x40 +#define M_MASK 0xff +#define M_ASCII 0x7f + +typedef char Char; + +#endif + + +#define CHAR(c) ((Char)((c)&M_ASCII)) +#define META(c) ((Char)((c)|M_QUOTE)) +#define M_ALL META('*') +#define M_END META(']') +#define M_NOT META('!') +#define M_ONE META('?') +#define M_RNG META('-') +#define M_SET META('[') +#define ismeta(c) (((c)&M_QUOTE) != 0) + + +static int compare(const void *, const void *); +static int g_Ctoc(const Char *, char *, u_int); +static int g_lstat(Char *, struct stat *, glob_t *); +static DIR *g_opendir(Char *, glob_t *); +static Char *g_strchr(Char *, int); +#ifdef notdef +static Char *g_strcat(Char *, const Char *); +#endif +static int g_stat(Char *, struct stat *, glob_t *); +static int glob0(const Char *, glob_t *, int *); +static int glob1(Char *, glob_t *, int *); +static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *); +static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *); +static int globextend(const Char *, glob_t *, int *); +static const Char * + globtilde(const Char *, Char *, size_t, glob_t *); +static int globexp1(const Char *, glob_t *, int *); +static int globexp2(const Char *, const Char *, glob_t *, int *, int *); +static int match(Char *, Char *, Char *); +#ifdef DEBUG +static void qprintf(const char *, Char *); +#endif + +int +glob(pattern, flags, errfunc, pglob) + const char *pattern; + int flags, (*errfunc)(const char *, int); + glob_t *pglob; +{ + const u_char *patnext; + int c, limit; + Char *bufnext, *bufend, patbuf[MAXPATHLEN]; + + patnext = (u_char *) pattern; + if (!(flags & GLOB_APPEND)) { + pglob->gl_pathc = 0; + pglob->gl_pathv = NULL; + if (!(flags & GLOB_DOOFFS)) + pglob->gl_offs = 0; + } + if (flags & GLOB_LIMIT) { + limit = pglob->gl_matchc; + if (limit == 0) + limit = ARG_MAX; + } else + limit = 0; + pglob->gl_flags = flags & ~GLOB_MAGCHAR; + pglob->gl_errfunc = errfunc; + pglob->gl_matchc = 0; + + bufnext = patbuf; + bufend = bufnext + MAXPATHLEN - 1; + if (flags & GLOB_NOESCAPE) + while (bufnext < bufend && (c = *patnext++) != EOS) + *bufnext++ = c; + else { + /* Protect the quoted characters. */ + while (bufnext < bufend && (c = *patnext++) != EOS) + if (c == QUOTE) { + if ((c = *patnext++) == EOS) { + c = QUOTE; + --patnext; + } + *bufnext++ = c | M_PROTECT; + } + else + *bufnext++ = c; + } + *bufnext = EOS; + + if (flags & GLOB_BRACE) + return globexp1(patbuf, pglob, &limit); + else + return glob0(patbuf, pglob, &limit); +} + +/* + * Expand recursively a glob {} pattern. When there is no more expansion + * invoke the standard globbing routine to glob the rest of the magic + * characters + */ +static int +globexp1(pattern, pglob, limit) + const Char *pattern; + glob_t *pglob; + int *limit; +{ + const Char* ptr = pattern; + int rv; + + /* Protect a single {}, for find(1), like csh */ + if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) + return glob0(pattern, pglob, limit); + + while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL) + if (!globexp2(ptr, pattern, pglob, &rv, limit)) + return rv; + + return glob0(pattern, pglob, limit); +} + + +/* + * Recursive brace globbing helper. Tries to expand a single brace. + * If it succeeds then it invokes globexp1 with the new pattern. + * If it fails then it tries to glob the rest of the pattern and returns. + */ +static int +globexp2(ptr, pattern, pglob, rv, limit) + const Char *ptr, *pattern; + glob_t *pglob; + int *rv, *limit; +{ + int i; + Char *lm, *ls; + const Char *pe, *pm, *pl; + Char patbuf[MAXPATHLEN]; + + /* copy part up to the brace */ + for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) + continue; + *lm = EOS; + ls = lm; + + /* Find the balanced brace */ + for (i = 0, pe = ++ptr; *pe; pe++) + if (*pe == LBRACKET) { + /* Ignore everything between [] */ + for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) + continue; + if (*pe == EOS) { + /* + * We could not find a matching RBRACKET. + * Ignore and just look for RBRACE + */ + pe = pm; + } + } + else if (*pe == LBRACE) + i++; + else if (*pe == RBRACE) { + if (i == 0) + break; + i--; + } + + /* Non matching braces; just glob the pattern */ + if (i != 0 || *pe == EOS) { + *rv = glob0(patbuf, pglob, limit); + return 0; + } + + for (i = 0, pl = pm = ptr; pm <= pe; pm++) + switch (*pm) { + case LBRACKET: + /* Ignore everything between [] */ + for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) + continue; + if (*pm == EOS) { + /* + * We could not find a matching RBRACKET. + * Ignore and just look for RBRACE + */ + pm = pl; + } + break; + + case LBRACE: + i++; + break; + + case RBRACE: + if (i) { + i--; + break; + } + /* FALLTHROUGH */ + case COMMA: + if (i && *pm == COMMA) + break; + else { + /* Append the current string */ + for (lm = ls; (pl < pm); *lm++ = *pl++) + continue; + /* + * Append the rest of the pattern after the + * closing brace + */ + for (pl = pe + 1; (*lm++ = *pl++) != EOS;) + continue; + + /* Expand the current pattern */ +#ifdef DEBUG + qprintf("globexp2:", patbuf); +#endif + *rv = globexp1(patbuf, pglob, limit); + + /* move after the comma, to the next string */ + pl = pm + 1; + } + break; + + default: + break; + } + *rv = 0; + return 0; +} + + + +/* + * expand tilde from the passwd file. + */ +static const Char * +globtilde(pattern, patbuf, patbuf_len, pglob) + const Char *pattern; + Char *patbuf; + size_t patbuf_len; + glob_t *pglob; +{ + struct passwd *pwd; + char *h; + const Char *p; + Char *b, *eb; + + if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) + return pattern; + + /* + * Copy up to the end of the string or / + */ + eb = &patbuf[patbuf_len - 1]; + for (p = pattern + 1, h = (char *) patbuf; + h < (char *)eb && *p && *p != SLASH; *h++ = *p++) + continue; + + *h = EOS; + + if (((char *) patbuf)[0] == EOS) { + /* + * handle a plain ~ or ~/ by expanding $HOME first (iff + * we're not running setuid or setgid) and then trying + * the password file + */ + if (issetugid() != 0 || + (h = getenv("HOME")) == NULL) { + if (((h = getlogin()) != NULL && + (pwd = getpwnam(h)) != NULL) || + (pwd = getpwuid(getuid())) != NULL) + h = pwd->pw_dir; + else + return pattern; + } + } + else { + /* + * Expand a ~user + */ + if ((pwd = getpwnam((char*) patbuf)) == NULL) + return pattern; + else + h = pwd->pw_dir; + } + + /* Copy the home directory */ + for (b = patbuf; b < eb && *h; *b++ = *h++) + continue; + + /* Append the rest of the pattern */ + while (b < eb && (*b++ = *p++) != EOS) + continue; + *b = EOS; + + return patbuf; +} + + +/* + * The main glob() routine: compiles the pattern (optionally processing + * quotes), calls glob1() to do the real pattern matching, and finally + * sorts the list (unless unsorted operation is requested). Returns 0 + * if things went well, nonzero if errors occurred. + */ +static int +glob0(pattern, pglob, limit) + const Char *pattern; + glob_t *pglob; + int *limit; +{ + const Char *qpatnext; + int c, err, oldpathc; + Char *bufnext, patbuf[MAXPATHLEN]; + + qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob); + oldpathc = pglob->gl_pathc; + bufnext = patbuf; + + /* We don't need to check for buffer overflow any more. */ + while ((c = *qpatnext++) != EOS) { + switch (c) { + case LBRACKET: + c = *qpatnext; + if (c == NOT) + ++qpatnext; + if (*qpatnext == EOS || + g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) { + *bufnext++ = LBRACKET; + if (c == NOT) + --qpatnext; + break; + } + *bufnext++ = M_SET; + if (c == NOT) + *bufnext++ = M_NOT; + c = *qpatnext++; + do { + *bufnext++ = CHAR(c); + if (*qpatnext == RANGE && + (c = qpatnext[1]) != RBRACKET) { + *bufnext++ = M_RNG; + *bufnext++ = CHAR(c); + qpatnext += 2; + } + } while ((c = *qpatnext++) != RBRACKET); + pglob->gl_flags |= GLOB_MAGCHAR; + *bufnext++ = M_END; + break; + case QUESTION: + pglob->gl_flags |= GLOB_MAGCHAR; + *bufnext++ = M_ONE; + break; + case STAR: + pglob->gl_flags |= GLOB_MAGCHAR; + /* collapse adjacent stars to one, + * to avoid exponential behavior + */ + if (bufnext == patbuf || bufnext[-1] != M_ALL) + *bufnext++ = M_ALL; + break; + default: + *bufnext++ = CHAR(c); + break; + } + } + *bufnext = EOS; +#ifdef DEBUG + qprintf("glob0:", patbuf); +#endif + + if ((err = glob1(patbuf, pglob, limit)) != 0) + return(err); + + /* + * If there was no match we are going to append the pattern + * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified + * and the pattern did not contain any magic characters + * GLOB_NOMAGIC is there just for compatibility with csh. + */ + if (pglob->gl_pathc == oldpathc) { + if (((pglob->gl_flags & GLOB_NOCHECK) || + ((pglob->gl_flags & GLOB_NOMAGIC) && + !(pglob->gl_flags & GLOB_MAGCHAR)))) + return(globextend(pattern, pglob, limit)); + else + return(GLOB_NOMATCH); + } + if (!(pglob->gl_flags & GLOB_NOSORT)) + qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, + pglob->gl_pathc - oldpathc, sizeof(char *), compare); + return(0); +} + +static int +compare(p, q) + const void *p, *q; +{ + return(strcmp(*(char **)p, *(char **)q)); +} + +static int +glob1(pattern, pglob, limit) + Char *pattern; + glob_t *pglob; + int *limit; +{ + Char pathbuf[MAXPATHLEN]; + + /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ + if (*pattern == EOS) + return(0); + return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, + pattern, pglob, limit)); +} + +/* + * The functions glob2 and glob3 are mutually recursive; there is one level + * of recursion for each segment in the pattern that contains one or more + * meta characters. + */ +static int +glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit) + Char *pathbuf, *pathend, *pathend_last, *pattern; + glob_t *pglob; + int *limit; +{ + struct stat sb; + Char *p, *q; + int anymeta; + + /* + * Loop over pattern segments until end of pattern or until + * segment with meta character found. + */ + for (anymeta = 0;;) { + if (*pattern == EOS) { /* End of pattern? */ + *pathend = EOS; + if (g_lstat(pathbuf, &sb, pglob)) + return(0); + + if (((pglob->gl_flags & GLOB_MARK) && + pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) + || (S_ISLNK(sb.st_mode) && + (g_stat(pathbuf, &sb, pglob) == 0) && + S_ISDIR(sb.st_mode)))) { + if (pathend + 1 > pathend_last) + return (GLOB_ABORTED); + *pathend++ = SEP; + *pathend = EOS; + } + ++pglob->gl_matchc; + return(globextend(pathbuf, pglob, limit)); + } + + /* Find end of next segment, copy tentatively to pathend. */ + q = pathend; + p = pattern; + while (*p != EOS && *p != SEP) { + if (ismeta(*p)) + anymeta = 1; + if (q + 1 > pathend_last) + return (GLOB_ABORTED); + *q++ = *p++; + } + + if (!anymeta) { /* No expansion, do next segment. */ + pathend = q; + pattern = p; + while (*pattern == SEP) { + if (pathend + 1 > pathend_last) + return (GLOB_ABORTED); + *pathend++ = *pattern++; + } + } else /* Need expansion, recurse. */ + return(glob3(pathbuf, pathend, pathend_last, pattern, p, + pglob, limit)); + } + /* NOTREACHED */ +} + +static int +glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit) + Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern; + glob_t *pglob; + int *limit; +{ + struct dirent *dp; + DIR *dirp; + int err; + char buf[MAXPATHLEN]; + + /* + * The readdirfunc declaration can't be prototyped, because it is + * assigned, below, to two functions which are prototyped in glob.h + * and dirent.h as taking pointers to differently typed opaque + * structures. + */ + struct dirent *(*readdirfunc)(); + + if (pathend > pathend_last) + return (GLOB_ABORTED); + *pathend = EOS; + errno = 0; + + if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { + /* TODO: don't call for ENOENT or ENOTDIR? */ + if (pglob->gl_errfunc) { + if (g_Ctoc(pathbuf, buf, sizeof(buf))) + return (GLOB_ABORTED); + if (pglob->gl_errfunc(buf, errno) || + pglob->gl_flags & GLOB_ERR) + return (GLOB_ABORTED); + } + return(0); + } + + err = 0; + + /* Search directory for matching names. */ + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + readdirfunc = pglob->gl_readdir; + else + readdirfunc = readdir; + while ((dp = (*readdirfunc)(dirp))) { + u_char *sc; + Char *dc; + + /* Initial DOT must be matched literally. */ + if (dp->d_name[0] == DOT && *pattern != DOT) + continue; + dc = pathend; + sc = (u_char *) dp->d_name; + while (dc < pathend_last && (*dc++ = *sc++) != EOS) + ; + if (!match(pathend, pattern, restpattern)) { + *pathend = EOS; + continue; + } + err = glob2(pathbuf, --dc, pathend_last, restpattern, + pglob, limit); + if (err) + break; + } + + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + (*pglob->gl_closedir)(dirp); + else + closedir(dirp); + return(err); +} + + +/* + * Extend the gl_pathv member of a glob_t structure to accomodate a new item, + * add the new item, and update gl_pathc. + * + * This assumes the BSD realloc, which only copies the block when its size + * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic + * behavior. + * + * Return 0 if new item added, error code if memory couldn't be allocated. + * + * Invariant of the glob_t structure: + * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and + * gl_pathv points to (gl_offs + gl_pathc + 1) items. + */ +static int +globextend(path, pglob, limit) + const Char *path; + glob_t *pglob; + int *limit; +{ + char **pathv; + int i; + u_int newsize, len; + char *copy; + const Char *p; + + if (*limit && pglob->gl_pathc > *limit) { + errno = 0; + return (GLOB_NOSPACE); + } + + newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); + pathv = pglob->gl_pathv ? + realloc((char *)pglob->gl_pathv, newsize) : + malloc(newsize); + if (pathv == NULL) { + if (pglob->gl_pathv) { + free(pglob->gl_pathv); + pglob->gl_pathv = NULL; + } + return(GLOB_NOSPACE); + } + + if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { + /* first time around -- clear initial gl_offs items */ + pathv += pglob->gl_offs; + for (i = pglob->gl_offs; --i >= 0; ) + *--pathv = NULL; + } + pglob->gl_pathv = pathv; + + for (p = path; *p++;) + continue; + len = (size_t)(p - path); + if ((copy = malloc(len)) != NULL) { + if (g_Ctoc(path, copy, len)) { + free(copy); + return (GLOB_NOSPACE); + } + pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; + } + pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; + return(copy == NULL ? GLOB_NOSPACE : 0); +} + +/* + * pattern matching function for filenames. Each occurrence of the * + * pattern causes a recursion level. + */ +static int +match(name, pat, patend) + Char *name, *pat, *patend; +{ + int ok, negate_range; + Char c, k; + + while (pat < patend) { + c = *pat++; + switch (c & M_MASK) { + case M_ALL: + if (pat == patend) + return(1); + do + if (match(name, pat, patend)) + return(1); + while (*name++ != EOS); + return(0); + case M_ONE: + if (*name++ == EOS) + return(0); + break; + case M_SET: + ok = 0; + if ((k = *name++) == EOS) + return(0); + if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) + ++pat; + while (((c = *pat++) & M_MASK) != M_END) + if ((*pat & M_MASK) == M_RNG) { + if (__collate_load_error ? + CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]) : + __collate_range_cmp(CHAR(c), CHAR(k)) <= 0 + && __collate_range_cmp(CHAR(k), CHAR(pat[1])) <= 0 + ) + ok = 1; + pat += 2; + } else if (c == k) + ok = 1; + if (ok == negate_range) + return(0); + break; + default: + if (*name++ != c) + return(0); + break; + } + } + return(*name == EOS); +} + +/* Free allocated data belonging to a glob_t structure. */ +void +globfree(pglob) + glob_t *pglob; +{ + int i; + char **pp; + + if (pglob->gl_pathv != NULL) { + pp = pglob->gl_pathv + pglob->gl_offs; + for (i = pglob->gl_pathc; i--; ++pp) + if (*pp) + free(*pp); + free(pglob->gl_pathv); + pglob->gl_pathv = NULL; + } +} + +static DIR * +g_opendir(str, pglob) + Char *str; + glob_t *pglob; +{ + char buf[MAXPATHLEN]; + + if (!*str) + strcpy(buf, "."); + else { + if (g_Ctoc(str, buf, sizeof(buf))) + return (NULL); + } + + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + return((*pglob->gl_opendir)(buf)); + + return(opendir(buf)); +} + +static int +g_lstat(fn, sb, pglob) + Char *fn; + struct stat *sb; + glob_t *pglob; +{ + char buf[MAXPATHLEN]; + + if (g_Ctoc(fn, buf, sizeof(buf))) { + errno = ENAMETOOLONG; + return (-1); + } + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + return((*pglob->gl_lstat)(buf, sb)); + return(lstat(buf, sb)); +} + +static int +g_stat(fn, sb, pglob) + Char *fn; + struct stat *sb; + glob_t *pglob; +{ + char buf[MAXPATHLEN]; + + if (g_Ctoc(fn, buf, sizeof(buf))) { + errno = ENAMETOOLONG; + return (-1); + } + if (pglob->gl_flags & GLOB_ALTDIRFUNC) + return((*pglob->gl_stat)(buf, sb)); + return(stat(buf, sb)); +} + +static Char * +g_strchr(str, ch) + Char *str; + int ch; +{ + do { + if (*str == ch) + return (str); + } while (*str++); + return (NULL); +} + +static int +g_Ctoc(str, buf, len) + const Char *str; + char *buf; + u_int len; +{ + + while (len--) { + if ((*buf++ = *str++) == '\0') + return (0); + } + return (1); +} + +#ifdef DEBUG +static void +qprintf(str, s) + const char *str; + Char *s; +{ + Char *p; + + (void)printf("%s:\n", str); + for (p = s; *p; p++) + (void)printf("%c", CHAR(*p)); + (void)printf("\n"); + for (p = s; *p; p++) + (void)printf("%c", *p & M_PROTECT ? '"' : ' '); + (void)printf("\n"); + for (p = s; *p; p++) + (void)printf("%c", ismeta(*p) ? '_' : ' '); + (void)printf("\n"); +} +#endif diff --git a/src/lib/libc/gen/initgroups.c b/src/lib/libc/gen/initgroups.c new file mode 100644 index 0000000..50c910a --- /dev/null +++ b/src/lib/libc/gen/initgroups.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)initgroups.c 8.1 (Berkeley) 6/4/93"; +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/initgroups.c,v 1.8 2003/11/19 15:51:26 dds Exp $"); + +#include + +#include +#include "namespace.h" +#include +#include "un-namespace.h" +#include + +int +initgroups(uname, agroup) + const char *uname; + gid_t agroup; +{ + int ngroups; + /* + * Provide space for one group more than NGROUPS to allow + * setgroups to fail and set errno. + */ + gid_t groups[NGROUPS + 1]; + + ngroups = NGROUPS + 1; + getgrouplist(uname, agroup, groups, &ngroups); + return (setgroups(ngroups, groups)); +} diff --git a/src/lib/libc/gen/isatty.c b/src/lib/libc/gen/isatty.c new file mode 100644 index 0000000..d16a963 --- /dev/null +++ b/src/lib/libc/gen/isatty.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)isatty.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/isatty.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include + +int +isatty(fd) + int fd; +{ + int retval; + struct termios t; + + retval = (tcgetattr(fd, &t) != -1); + return(retval); +} diff --git a/src/lib/libc/gen/jrand48.c b/src/lib/libc/gen/jrand48.c new file mode 100644 index 0000000..f47bf2a --- /dev/null +++ b/src/lib/libc/gen/jrand48.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/jrand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +long +jrand48(unsigned short xseed[3]) +{ + _dorand48(xseed); + return ((long) xseed[2] << 16) + (long) xseed[1]; +} diff --git a/src/lib/libc/gen/lcong48.c b/src/lib/libc/gen/lcong48.c new file mode 100644 index 0000000..8b11e08 --- /dev/null +++ b/src/lib/libc/gen/lcong48.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/lcong48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; +extern unsigned short _rand48_mult[3]; +extern unsigned short _rand48_add; + +void +lcong48(unsigned short p[7]) +{ + _rand48_seed[0] = p[0]; + _rand48_seed[1] = p[1]; + _rand48_seed[2] = p[2]; + _rand48_mult[0] = p[3]; + _rand48_mult[1] = p[4]; + _rand48_mult[2] = p[5]; + _rand48_add = p[6]; +} diff --git a/src/lib/libc/gen/libc_private.h b/src/lib/libc/gen/libc_private.h new file mode 100644 index 0000000..63f8610 --- /dev/null +++ b/src/lib/libc/gen/libc_private.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 1998 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. + * + * $FreeBSD: src/lib/libc/include/libc_private.h,v 1.11 2003/11/05 18:17:30 deischen Exp $ + * + * Private definitions for libc, libc_r and libpthread. + * + */ + +#ifndef _LIBC_PRIVATE_H_ +#define _LIBC_PRIVATE_H_ + +/* + * This global flag is non-zero when a process has created one + * or more threads. It is used to avoid calling locking functions + * when they are not required. + */ +extern int __isthreaded; + +/* + * File lock contention is difficult to diagnose without knowing + * where locks were set. Allow a debug library to be built which + * records the source file and line number of each lock call. + */ +#ifdef _FLOCK_DEBUG +#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) +#else +#define _FLOCKFILE(x) _flockfile(x) +#endif + +/* + * Macros for locking and unlocking FILEs. These test if the + * process is threaded to avoid locking when not required. + */ +#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) +#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) + +/* + * Indexes into the pthread jump table. + * + * Warning! If you change this type, you must also change the threads + * libraries that reference it (libc_r, libpthread). + */ +typedef enum { + PJT_COND_BROADCAST, + PJT_COND_DESTROY, + PJT_COND_INIT, + PJT_COND_SIGNAL, + PJT_COND_WAIT, + PJT_GETSPECIFIC, + PJT_KEY_CREATE, + PJT_KEY_DELETE, + PJT_MAIN_NP, + PJT_MUTEX_DESTROY, + PJT_MUTEX_INIT, + PJT_MUTEX_LOCK, + PJT_MUTEX_TRYLOCK, + PJT_MUTEX_UNLOCK, + PJT_MUTEXATTR_DESTROY, + PJT_MUTEXATTR_INIT, + PJT_MUTEXATTR_SETTYPE, + PJT_ONCE, + PJT_RWLOCK_DESTROY, + PJT_RWLOCK_INIT, + PJT_RWLOCK_RDLOCK, + PJT_RWLOCK_TRYRDLOCK, + PJT_RWLOCK_TRYWRLOCK, + PJT_RWLOCK_UNLOCK, + PJT_RWLOCK_WRLOCK, + PJT_SELF, + PJT_SETSPECIFIC, + PJT_SIGMASK, + PJT_MAX +} pjt_index_t; + +typedef int (*pthread_func_t)(void); +typedef pthread_func_t pthread_func_entry_t[2]; + +extern pthread_func_entry_t __thr_jtable[]; + +/* + * yplib internal interfaces + */ +#ifdef YP +int _yp_check(char **); +#endif + + +/* + * This is a pointer in the C run-time startup code. It is used + * by getprogname() and setprogname(). + */ +extern const char *__progname; + +/* + * This is the lock to make malloc() thread-safe. It is externalized + * so that thread libraries can protect malloc across fork(). + */ +extern struct _spinlock *__malloc_lock; + +#endif /* _LIBC_PRIVATE_H_ */ diff --git a/src/lib/libc/gen/lockf.c b/src/lib/libc/gen/lockf.c new file mode 100644 index 0000000..375b2ce --- /dev/null +++ b/src/lib/libc/gen/lockf.c @@ -0,0 +1,89 @@ +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* $NetBSD: lockf.c,v 1.1 1997/12/20 20:23:18 kleink Exp $ */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/lockf.c,v 1.8 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" + +int +lockf(filedes, function, size) + int filedes; + int function; + off_t size; +{ + struct flock fl; + int cmd; + + fl.l_start = 0; + fl.l_len = size; + fl.l_whence = SEEK_CUR; + + switch (function) { + case F_ULOCK: + cmd = F_SETLK; + fl.l_type = F_UNLCK; + break; + case F_LOCK: + cmd = F_SETLKW; + fl.l_type = F_WRLCK; + break; + case F_TLOCK: + cmd = F_SETLK; + fl.l_type = F_WRLCK; + break; + case F_TEST: + fl.l_type = F_WRLCK; + if (_fcntl(filedes, F_GETLK, &fl) == -1) + return (-1); + if (fl.l_type == F_UNLCK || fl.l_pid == getpid()) + return (0); + errno = EAGAIN; + return (-1); + /* NOTREACHED */ + default: + errno = EINVAL; + return (-1); + /* NOTREACHED */ + } + + return (_fcntl(filedes, cmd, &fl)); +} diff --git a/src/lib/libc/gen/lrand48.c b/src/lib/libc/gen/lrand48.c new file mode 100644 index 0000000..948b923 --- /dev/null +++ b/src/lib/libc/gen/lrand48.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/lrand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; + +long +lrand48(void) +{ + _dorand48(_rand48_seed); + return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >> 1); +} diff --git a/src/lib/libc/gen/mrand48.c b/src/lib/libc/gen/mrand48.c new file mode 100644 index 0000000..f65ed77 --- /dev/null +++ b/src/lib/libc/gen/mrand48.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/mrand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; + +long +mrand48(void) +{ + _dorand48(_rand48_seed); + return ((long) _rand48_seed[2] << 16) + (long) _rand48_seed[1]; +} diff --git a/src/lib/libc/gen/namespace.h b/src/lib/libc/gen/namespace.h new file mode 100644 index 0000000..1e59c6c --- /dev/null +++ b/src/lib/libc/gen/namespace.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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. + * + * $FreeBSD: src/lib/libc/include/namespace.h,v 1.16 2003/05/01 19:03:13 nectar Exp $ + */ + +#ifndef _NAMESPACE_H_ +#define _NAMESPACE_H_ + +/* + * Adjust names so that headers declare "hidden" names. + * + * README: When modifying this file don't forget to make the appropriate + * changes in un-namespace.h!!! + */ + +/* + * ISO C (C90) section. Most names in libc aren't in ISO C, so they + * should be here. Most aren't here... + */ +#define err _err +#define warn _warn +#define nsdispatch _nsdispatch + +/* + * Prototypes for syscalls/functions that need to be overridden + * in libc_r/libpthread. + */ +#define accept _accept +#define __acl_aclcheck_fd ___acl_aclcheck_fd +#define __acl_delete_fd ___acl_delete_fd +#define __acl_get_fd ___acl_get_fd +#define __acl_set_fd ___acl_set_fd +#define bind _bind +#define __cap_get_fd ___cap_get_fd +#define __cap_set_fd ___cap_set_fd +#define close _close +#define connect _connect +#define dup _dup +#define dup2 _dup2 +#define execve _execve +#define fcntl _fcntl +/*#define flock _flock */ +#define flockfile _flockfile +#define fpathconf _fpathconf +#define fstat _fstat +#define fstatfs _fstatfs +#define fsync _fsync +#define funlockfile _funlockfile +#define getdirentries _getdirentries +#define getlogin _getlogin +#define getpeername _getpeername +#define getprogname _getprogname +#define getsockname _getsockname +#define getsockopt _getsockopt +#define ioctl _ioctl +/* #define kevent _kevent */ +#define listen _listen +#define nanosleep _nanosleep +#define open _open +#define poll _poll +#define pthread_cond_broadcast _pthread_cond_broadcast +#define pthread_cond_destroy _pthread_cond_destroy +#define pthread_cond_init _pthread_cond_init +#define pthread_cond_signal _pthread_cond_signal +#define pthread_cond_timedwait _pthread_cond_timedwait +#define pthread_cond_wait _pthread_cond_wait +#define pthread_exit _pthread_exit +#define pthread_getspecific _pthread_getspecific +#define pthread_key_create _pthread_key_create +#define pthread_key_delete _pthread_key_delete +#define pthread_main_np _pthread_main_np +#define pthread_mutex_destroy _pthread_mutex_destroy +#define pthread_mutex_init _pthread_mutex_init +#define pthread_mutex_lock _pthread_mutex_lock +#define pthread_mutex_trylock _pthread_mutex_trylock +#define pthread_mutex_unlock _pthread_mutex_unlock +#define pthread_mutexattr_destroy _pthread_mutexattr_destroy +#define pthread_mutexattr_init _pthread_mutexattr_init +#define pthread_mutexattr_settype _pthread_mutexattr_settype +#define pthread_once _pthread_once +#define pthread_rwlock_destroy _pthread_rwlock_destroy +#define pthread_rwlock_init _pthread_rwlock_init +#define pthread_rwlock_rdlock _pthread_rwlock_rdlock +#define pthread_rwlock_wrlock _pthread_rwlock_wrlock +#define pthread_rwlock_tryrdlock _pthread_rwlock_tryrdlock +#define pthread_rwlock_trywrlock _pthread_rwlock_trywrlock +#define pthread_rwlock_unlock _pthread_rwlock_unlock +#define pthread_self _pthread_self +#define pthread_setspecific _pthread_setspecific +#define pthread_sigmask _pthread_sigmask +#define read _read +#define readv _readv +#define recvfrom _recvfrom +#define recvmsg _recvmsg +#define select _select +#define sendmsg _sendmsg +#define sendto _sendto +#define setsockopt _setsockopt +/*#define sigaction _sigaction*/ +#define sigprocmask _sigprocmask +#define sigsuspend _sigsuspend +#define socket _socket +#define socketpair _socketpair +#define wait4 _wait4 +#define waitpid _waitpid +#define write _write +#define writev _writev + + +/* + * Other hidden syscalls/functions that libc_r needs to override + * but are not used internally by libc. + * + * XXX - When modifying libc to use one of the following, remove + * the prototype from below and place it in the list above. + */ +#if 0 +#define creat _creat +#define fchflags _fchflags +#define fchmod _fchmod +#define ftrylockfile _ftrylockfile +#define msync _msync +#define nfssvc _nfssvc +#define pause _pause +#define pthread_rwlockattr_init _pthread_rwlockattr_init +#define pthread_rwlockattr_destroy _pthread_rwlockattr_destroy +#define sched_yield _sched_yield +#define sendfile _sendfile +#define shutdown _shutdown +#define sigaltstack _sigaltstack +#define sigpending _sigpending +#define sigreturn _sigreturn +#define sigsetmask _sigsetmask +#define sleep _sleep +#define system _system +#define tcdrain _tcdrain +#define wait _wait +#endif + +#endif /* _NAMESPACE_H_ */ diff --git a/src/lib/libc/gen/nice.c b/src/lib/libc/gen/nice.c new file mode 100644 index 0000000..453caa7 --- /dev/null +++ b/src/lib/libc/gen/nice.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)nice.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/nice.c,v 1.3 2002/03/22 21:52:05 obrien Exp $"); + +#include +#include +#include +#include +#include + +/* + * Backwards compatible nice. + */ +int +nice(incr) + int incr; +{ + int prio; + + errno = 0; + prio = getpriority(PRIO_PROCESS, 0); + if (prio == -1 && errno) + return (-1); + return (setpriority(PRIO_PROCESS, 0, prio + incr)); +} diff --git a/src/lib/libc/gen/nlist.c b/src/lib/libc/gen/nlist.c new file mode 100644 index 0000000..ff20b50 --- /dev/null +++ b/src/lib/libc/gen/nlist.c @@ -0,0 +1,416 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/nlist.c,v 1.18 2003/02/27 13:40:00 nectar Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#define _NLIST_DO_AOUT +#define _NLIST_DO_ELF + +#ifdef _NLIST_DO_ELF +#include +#include +#endif + +int __fdnlist(int, struct nlist *); +int __aout_fdnlist(int, struct nlist *); +int __elf_fdnlist(int, struct nlist *); + +int +nlist(name, list) + const char *name; + struct nlist *list; +{ + int fd, n; + + fd = _open(name, O_RDONLY, 0); + if (fd < 0) + return (-1); + n = __fdnlist(fd, list); + (void)_close(fd); + return (n); +} + +static struct nlist_handlers { + int (*fn)(int fd, struct nlist *list); +} nlist_fn[] = { +#ifdef _NLIST_DO_AOUT + { __aout_fdnlist }, +#endif +#ifdef _NLIST_DO_ELF + { __elf_fdnlist }, +#endif +}; + +int +__fdnlist(fd, list) + int fd; + struct nlist *list; +{ + int n = -1, i; + + for (i = 0; i < sizeof(nlist_fn) / sizeof(nlist_fn[0]); i++) { + n = (nlist_fn[i].fn)(fd, list); + if (n != -1) + break; + } + return (n); +} + +#define ISLAST(p) (p->n_un.n_name == 0 || p->n_un.n_name[0] == 0) + +#ifdef _NLIST_DO_AOUT +int +__aout_fdnlist(fd, list) + int fd; + struct nlist *list; +{ + struct nlist *p, *symtab; + caddr_t strtab, a_out_mmap; + off_t stroff, symoff; + u_long symsize; + int nent; + struct exec * exec; + struct stat st; + + /* check that file is at least as large as struct exec! */ + if ((_fstat(fd, &st) < 0) || (st.st_size < sizeof(struct exec))) + return (-1); + + /* Check for files too large to mmap. */ + if (st.st_size > SIZE_T_MAX) { + errno = EFBIG; + return (-1); + } + + /* + * Map the whole a.out file into our address space. + * We then find the string table withing this area. + * We do not just mmap the string table, as it probably + * does not start at a page boundary - we save ourselves a + * lot of nastiness by mmapping the whole file. + * + * This gives us an easy way to randomly access all the strings, + * without making the memory allocation permanent as with + * malloc/free (i.e., munmap will return it to the system). + */ + a_out_mmap = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0); + if (a_out_mmap == MAP_FAILED) + return (-1); + + exec = (struct exec *)a_out_mmap; + if (N_BADMAG(*exec)) { + munmap(a_out_mmap, (size_t)st.st_size); + return (-1); + } + + symoff = N_SYMOFF(*exec); + symsize = exec->a_syms; + stroff = symoff + symsize; + + /* find the string table in our mmapped area */ + strtab = a_out_mmap + stroff; + symtab = (struct nlist *)(a_out_mmap + symoff); + + /* + * clean out any left-over information for all valid entries. + * Type and value defined to be 0 if not found; historical + * versions cleared other and desc as well. Also figure out + * the largest string length so don't read any more of the + * string table than we have to. + * + * XXX clearing anything other than n_type and n_value violates + * the semantics given in the man page. + */ + nent = 0; + for (p = list; !ISLAST(p); ++p) { + p->n_type = 0; + p->n_other = 0; + p->n_desc = 0; + p->n_value = 0; + ++nent; + } + + while (symsize > 0) { + int soff; + + symsize-= sizeof(struct nlist); + soff = symtab->n_un.n_strx; + + + if (soff != 0 && (symtab->n_type & N_STAB) == 0) + for (p = list; !ISLAST(p); p++) + if (!strcmp(&strtab[soff], p->n_un.n_name)) { + p->n_value = symtab->n_value; + p->n_type = symtab->n_type; + p->n_desc = symtab->n_desc; + p->n_other = symtab->n_other; + if (--nent <= 0) + break; + } + symtab++; + } + munmap(a_out_mmap, (size_t)st.st_size); + return (nent); +} +#endif + +#ifdef _NLIST_DO_ELF +static void elf_sym_to_nlist(struct nlist *, Elf_Sym *, Elf_Shdr *, int); + +/* + * __elf_is_okay__ - Determine if ehdr really + * is ELF and valid for the target platform. + * + * WARNING: This is NOT an ELF ABI function and + * as such its use should be restricted. + */ +int +__elf_is_okay__(ehdr) + Elf_Ehdr *ehdr; +{ + int retval = 0; + /* + * We need to check magic, class size, endianess, + * and version before we look at the rest of the + * Elf_Ehdr structure. These few elements are + * represented in a machine independant fashion. + */ + if (IS_ELF(*ehdr) && + ehdr->e_ident[EI_CLASS] == ELF_TARG_CLASS && + ehdr->e_ident[EI_DATA] == ELF_TARG_DATA && + ehdr->e_ident[EI_VERSION] == ELF_TARG_VER) { + + /* Now check the machine dependant header */ + if (ehdr->e_machine == ELF_TARG_MACH && + ehdr->e_version == ELF_TARG_VER) + retval = 1; + } + return retval; +} + +int +__elf_fdnlist(fd, list) + int fd; + struct nlist *list; +{ + struct nlist *p; + Elf_Off symoff = 0, symstroff = 0; + Elf_Word symsize = 0, symstrsize = 0; + Elf_Sword cc, i; + int nent = -1; + int errsave; + Elf_Sym sbuf[1024]; + Elf_Sym *s; + Elf_Ehdr ehdr; + char *strtab = NULL; + Elf_Shdr *shdr = NULL; + Elf_Word shdr_size; + void *base; + struct stat st; + + /* Make sure obj is OK */ + if (lseek(fd, (off_t)0, SEEK_SET) == -1 || + _read(fd, &ehdr, sizeof(Elf_Ehdr)) != sizeof(Elf_Ehdr) || + !__elf_is_okay__(&ehdr) || + _fstat(fd, &st) < 0) + return (-1); + + /* calculate section header table size */ + shdr_size = ehdr.e_shentsize * ehdr.e_shnum; + + /* Make sure it's not too big to mmap */ + if (shdr_size > SIZE_T_MAX) { + errno = EFBIG; + return (-1); + } + + /* mmap section header table */ + base = mmap(NULL, (size_t)shdr_size, PROT_READ, 0, fd, + (off_t)ehdr.e_shoff); + if (base == MAP_FAILED) + return (-1); + shdr = (Elf_Shdr *)base; + + /* + * Find the symbol table entry and it's corresponding + * string table entry. Version 1.1 of the ABI states + * that there is only one symbol table but that this + * could change in the future. + */ + for (i = 0; i < ehdr.e_shnum; i++) { + if (shdr[i].sh_type == SHT_SYMTAB) { + symoff = shdr[i].sh_offset; + symsize = shdr[i].sh_size; + symstroff = shdr[shdr[i].sh_link].sh_offset; + symstrsize = shdr[shdr[i].sh_link].sh_size; + break; + } + } + + /* Check for files too large to mmap. */ + if (symstrsize > SIZE_T_MAX) { + errno = EFBIG; + goto done; + } + /* + * Map string table into our address space. This gives us + * an easy way to randomly access all the strings, without + * making the memory allocation permanent as with malloc/free + * (i.e., munmap will return it to the system). + */ + base = mmap(NULL, (size_t)symstrsize, PROT_READ, 0, fd, + (off_t)symstroff); + if (base == MAP_FAILED) + goto done; + strtab = (char *)base; + + /* + * clean out any left-over information for all valid entries. + * Type and value defined to be 0 if not found; historical + * versions cleared other and desc as well. Also figure out + * the largest string length so don't read any more of the + * string table than we have to. + * + * XXX clearing anything other than n_type and n_value violates + * the semantics given in the man page. + */ + nent = 0; + for (p = list; !ISLAST(p); ++p) { + p->n_type = 0; + p->n_other = 0; + p->n_desc = 0; + p->n_value = 0; + ++nent; + } + + /* Don't process any further if object is stripped. */ + if (symoff == 0) + goto done; + + if (lseek(fd, (off_t) symoff, SEEK_SET) == -1) { + nent = -1; + goto done; + } + + while (symsize > 0 && nent > 0) { + cc = MIN(symsize, sizeof(sbuf)); + if (_read(fd, sbuf, cc) != cc) + break; + symsize -= cc; + for (s = sbuf; cc > 0 && nent > 0; ++s, cc -= sizeof(*s)) { + char *name; + struct nlist *p; + + name = strtab + s->st_name; + if (name[0] == '\0') + continue; + for (p = list; !ISLAST(p); p++) { + if ((p->n_un.n_name[0] == '_' && + strcmp(name, p->n_un.n_name+1) == 0) + || strcmp(name, p->n_un.n_name) == 0) { + elf_sym_to_nlist(p, s, shdr, + ehdr.e_shnum); + if (--nent <= 0) + break; + } + } + } + } + done: + errsave = errno; + if (strtab != NULL) + munmap(strtab, symstrsize); + if (shdr != NULL) + munmap(shdr, shdr_size); + errno = errsave; + return (nent); +} + +/* + * Convert an Elf_Sym into an nlist structure. This fills in only the + * n_value and n_type members. + */ +static void +elf_sym_to_nlist(nl, s, shdr, shnum) + struct nlist *nl; + Elf_Sym *s; + Elf_Shdr *shdr; + int shnum; +{ + nl->n_value = s->st_value; + + switch (s->st_shndx) { + case SHN_UNDEF: + case SHN_COMMON: + nl->n_type = N_UNDF; + break; + case SHN_ABS: + nl->n_type = ELF_ST_TYPE(s->st_info) == STT_FILE ? + N_FN : N_ABS; + break; + default: + if (s->st_shndx >= shnum) + nl->n_type = N_UNDF; + else { + Elf_Shdr *sh = shdr + s->st_shndx; + + nl->n_type = sh->sh_type == SHT_PROGBITS ? + (sh->sh_flags & SHF_WRITE ? N_DATA : N_TEXT) : + (sh->sh_type == SHT_NOBITS ? N_BSS : N_UNDF); + } + break; + } + + if (ELF_ST_BIND(s->st_info) == STB_GLOBAL || + ELF_ST_BIND(s->st_info) == STB_WEAK) + nl->n_type |= N_EXT; +} +#endif /* _NLIST_DO_ELF */ diff --git a/src/lib/libc/gen/nrand48.c b/src/lib/libc/gen/nrand48.c new file mode 100644 index 0000000..3a21c3f --- /dev/null +++ b/src/lib/libc/gen/nrand48.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/nrand48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +long +nrand48(unsigned short xseed[3]) +{ + _dorand48(xseed); + return ((long) xseed[2] << 15) + ((long) xseed[1] >> 1); +} diff --git a/src/lib/libc/gen/ntp_gettime.c b/src/lib/libc/gen/ntp_gettime.c new file mode 100644 index 0000000..583e7ac --- /dev/null +++ b/src/lib/libc/gen/ntp_gettime.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1989, 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/ntp_gettime.c,v 1.7 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include +#include +#include + +int +ntp_gettime(struct ntptimeval *ntv) +{ + struct ntptimeval tv; + size_t size = sizeof tv; + + if (sysctlbyname("kern.ntp_pll.gettime", &tv, &size, NULL, 0) == -1) + return TIME_ERROR; + if(ntv) *ntv = tv; + return tv.time_state; +} + diff --git a/src/lib/libc/gen/opendir.c b/src/lib/libc/gen/opendir.c new file mode 100644 index 0000000..035624e --- /dev/null +++ b/src/lib/libc/gen/opendir.c @@ -0,0 +1,287 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/opendir.c,v 1.21 2003/12/26 12:00:46 dfr Exp $"); + +#include "namespace.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "telldir.h" +/* + * Open a directory. + */ +DIR * +opendir(name) + const char *name; +{ + + return (__opendir2(name, DTF_HIDEW|DTF_NODUP)); +} + +DIR * +__opendir2(name, flags) + const char *name; + int flags; +{ + DIR *dirp; + int fd; + int incr; + int saved_errno; + int unionstack; + struct stat statb; + + /* + * stat() before _open() because opening of special files may be + * harmful. _fstat() after open because the file may have changed. + */ + if (stat(name, &statb) != 0) + return (NULL); + if (!S_ISDIR(statb.st_mode)) { + errno = ENOTDIR; + return (NULL); + } + if ((fd = _open(name, O_RDONLY | O_NONBLOCK)) == -1) + return (NULL); + dirp = NULL; + if (_fstat(fd, &statb) != 0) + goto fail; + if (!S_ISDIR(statb.st_mode)) { + errno = ENOTDIR; + goto fail; + } + if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || + (dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL) + goto fail; + + dirp->dd_td = (void *)dirp + sizeof(DIR); + LIST_INIT(&dirp->dd_td->td_locq); + dirp->dd_td->td_loccnt = 0; + + /* + * Use the system page size if that is a multiple of DIRBLKSIZ. + * Hopefully this can be a big win someday by allowing page + * trades to user space to be done by _getdirentries(). + */ + incr = getpagesize(); + if ((incr % DIRBLKSIZ) != 0) + incr = DIRBLKSIZ; + + /* + * Determine whether this directory is the top of a union stack. + */ + if (flags & DTF_NODUP) { + struct statfs sfb; + + if (_fstatfs(fd, &sfb) < 0) + goto fail; + unionstack = !strcmp(sfb.f_fstypename, "unionfs") + || (sfb.f_flags & MNT_UNION); + } else { + unionstack = 0; + } + + if (unionstack) { + int len = 0; + int space = 0; + char *buf = 0; + char *ddptr = 0; + char *ddeptr; + int n; + struct dirent **dpv; + + /* + * The strategy here is to read all the directory + * entries into a buffer, sort the buffer, and + * remove duplicate entries by setting the inode + * number to zero. + */ + + do { + /* + * Always make at least DIRBLKSIZ bytes + * available to _getdirentries + */ + if (space < DIRBLKSIZ) { + space += incr; + len += incr; + buf = reallocf(buf, len); + if (buf == NULL) + goto fail; + ddptr = buf + (len - space); + } + + n = _getdirentries(fd, ddptr, space, &dirp->dd_seek); + if (n > 0) { + ddptr += n; + space -= n; + } + } while (n > 0); + + ddeptr = ddptr; + flags |= __DTF_READALL; + + /* + * Re-open the directory. + * This has the effect of rewinding back to the + * top of the union stack and is needed by + * programs which plan to fchdir to a descriptor + * which has also been read -- see fts.c. + */ + if (flags & DTF_REWIND) { + (void)_close(fd); + if ((fd = _open(name, O_RDONLY)) == -1) { + saved_errno = errno; + free(buf); + free(dirp); + errno = saved_errno; + return (NULL); + } + } + + /* + * There is now a buffer full of (possibly) duplicate + * names. + */ + dirp->dd_buf = buf; + + /* + * Go round this loop twice... + * + * Scan through the buffer, counting entries. + * On the second pass, save pointers to each one. + * Then sort the pointers and remove duplicate names. + */ + for (dpv = 0;;) { + n = 0; + ddptr = buf; + while (ddptr < ddeptr) { + struct dirent *dp; + + dp = (struct dirent *) ddptr; + if ((long)dp & 03L) + break; + if ((dp->d_reclen <= 0) || + (dp->d_reclen > (ddeptr + 1 - ddptr))) + break; + ddptr += dp->d_reclen; + if (dp->d_fileno) { + if (dpv) + dpv[n] = dp; + n++; + } + } + + if (dpv) { + struct dirent *xp; + + /* + * This sort must be stable. + */ + mergesort(dpv, n, sizeof(*dpv), alphasort); + + dpv[n] = NULL; + xp = NULL; + + /* + * Scan through the buffer in sort order, + * zapping the inode number of any + * duplicate names. + */ + for (n = 0; dpv[n]; n++) { + struct dirent *dp = dpv[n]; + + if ((xp == NULL) || + strcmp(dp->d_name, xp->d_name)) { + xp = dp; + } else { + dp->d_fileno = 0; + } + if (dp->d_type == DT_WHT && + (flags & DTF_HIDEW)) + dp->d_fileno = 0; + } + + free(dpv); + break; + } else { + dpv = malloc((n+1) * sizeof(struct dirent *)); + if (dpv == NULL) + break; + } + } + + dirp->dd_len = len; + dirp->dd_size = ddptr - dirp->dd_buf; + } else { + dirp->dd_len = incr; + dirp->dd_size = 0; + dirp->dd_buf = malloc(dirp->dd_len); + if (dirp->dd_buf == NULL) + goto fail; + dirp->dd_seek = 0; + flags &= ~DTF_REWIND; + } + + dirp->dd_loc = 0; + dirp->dd_fd = fd; + dirp->dd_flags = flags; + dirp->dd_lock = NULL; + + /* + * Set up seek point for rewinddir. + */ + dirp->dd_rewind = telldir(dirp); + + return (dirp); + +fail: + saved_errno = errno; + free(dirp); + (void)_close(fd); + errno = saved_errno; + return (NULL); +} diff --git a/src/lib/libc/gen/pause.c b/src/lib/libc/gen/pause.c new file mode 100644 index 0000000..4f56289 --- /dev/null +++ b/src/lib/libc/gen/pause.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)pause.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/pause.c,v 1.6 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include + +/* + * Backwards compatible pause. + */ +int +__pause() +{ + return sigpause(sigblock(0L)); +} +__weak_reference(__pause, pause); +__weak_reference(__pause, _pause); diff --git a/src/lib/libc/gen/pmadvise.c b/src/lib/libc/gen/pmadvise.c new file mode 100644 index 0000000..744c6e5 --- /dev/null +++ b/src/lib/libc/gen/pmadvise.c @@ -0,0 +1,16 @@ +/* + * The contents of this file are in the public domain. + * Written by Garrett A. Wollman, 2000-10-07. + * + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/pmadvise.c,v 1.3 2003/08/09 03:23:24 bms Exp $"); + +#include + +int +posix_madvise(void *address, size_t size, int how) +{ + return madvise(address, size, how); +} diff --git a/src/lib/libc/gen/popen.c b/src/lib/libc/gen/popen.c new file mode 100644 index 0000000..0ed5657 --- /dev/null +++ b/src/lib/libc/gen/popen.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software written by Ken Arnold and + * published in UNIX Review, Vol. 6, No. 8. + * + * 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[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/popen.c,v 1.18 2003/01/04 00:15:15 tjr Exp $"); + +#include "namespace.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" + +extern char **environ; + +static struct pid { + struct pid *next; + FILE *fp; + pid_t pid; +} *pidlist; +static pthread_mutex_t pidlist_mutex = PTHREAD_MUTEX_INITIALIZER; + +#define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&pidlist_mutex) +#define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&pidlist_mutex) + +FILE * +popen(command, type) + const char *command, *type; +{ + struct pid *cur; + FILE *iop; + int pdes[2], pid, twoway; + char *argv[4]; + struct pid *p; + + /* + * Lite2 introduced two-way popen() pipes using _socketpair(). + * FreeBSD's pipe() is bidirectional, so we use that. + */ + if (strchr(type, '+')) { + twoway = 1; + type = "r+"; + } else { + twoway = 0; + if ((*type != 'r' && *type != 'w') || type[1]) + return (NULL); + } + if (pipe(pdes) < 0) + return (NULL); + + if ((cur = malloc(sizeof(struct pid))) == NULL) { + (void)_close(pdes[0]); + (void)_close(pdes[1]); + return (NULL); + } + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = (char *)command; + argv[3] = NULL; + + THREAD_LOCK(); + switch (pid = vfork()) { + case -1: /* Error. */ + THREAD_UNLOCK(); + (void)_close(pdes[0]); + (void)_close(pdes[1]); + free(cur); + return (NULL); + /* NOTREACHED */ + case 0: /* Child. */ + if (*type == 'r') { + /* + * The _dup2() to STDIN_FILENO is repeated to avoid + * writing to pdes[1], which might corrupt the + * parent's copy. This isn't good enough in + * general, since the _exit() is no return, so + * the compiler is free to corrupt all the local + * variables. + */ + (void)_close(pdes[0]); + if (pdes[1] != STDOUT_FILENO) { + (void)_dup2(pdes[1], STDOUT_FILENO); + (void)_close(pdes[1]); + if (twoway) + (void)_dup2(STDOUT_FILENO, STDIN_FILENO); + } else if (twoway && (pdes[1] != STDIN_FILENO)) + (void)_dup2(pdes[1], STDIN_FILENO); + } else { + if (pdes[0] != STDIN_FILENO) { + (void)_dup2(pdes[0], STDIN_FILENO); + (void)_close(pdes[0]); + } + (void)_close(pdes[1]); + } + for (p = pidlist; p; p = p->next) { + (void)_close(fileno(p->fp)); + } + _execve(_PATH_BSHELL, argv, environ); + _exit(127); + /* NOTREACHED */ + } + THREAD_UNLOCK(); + + /* Parent; assume fdopen can't fail. */ + if (*type == 'r') { + iop = fdopen(pdes[0], type); + (void)_close(pdes[1]); + } else { + iop = fdopen(pdes[1], type); + (void)_close(pdes[0]); + } + + /* Link into list of file descriptors. */ + cur->fp = iop; + cur->pid = pid; + THREAD_LOCK(); + cur->next = pidlist; + pidlist = cur; + THREAD_UNLOCK(); + + return (iop); +} + +/* + * pclose -- + * Pclose returns -1 if stream is not associated with a `popened' command, + * if already `pclosed', or waitpid returns an error. + */ +int +pclose(iop) + FILE *iop; +{ + struct pid *cur, *last; + int pstat; + pid_t pid; + + /* + * Find the appropriate file pointer and remove it from the list. + */ + THREAD_LOCK(); + for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next) + if (cur->fp == iop) + break; + if (cur == NULL) { + THREAD_UNLOCK(); + return (-1); + } + if (last == NULL) + pidlist = cur->next; + else + last->next = cur->next; + THREAD_UNLOCK(); + + (void)fclose(iop); + + do { + pid = _wait4(cur->pid, &pstat, 0, (struct rusage *)0); + } while (pid == -1 && errno == EINTR); + + free(cur); + + return (pid == -1 ? -1 : pstat); +} diff --git a/src/lib/libc/gen/posixshm.c b/src/lib/libc/gen/posixshm.c new file mode 100644 index 0000000..0baa700 --- /dev/null +++ b/src/lib/libc/gen/posixshm.c @@ -0,0 +1,72 @@ +/* + * Copyright 2000 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/posixshm.c,v 1.4 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include + +#include +#include +#include "un-namespace.h" + +int +shm_open(const char *path, int flags, mode_t mode) +{ + int fd; + struct stat stab; + + if ((flags & O_ACCMODE) == O_WRONLY) + return (EINVAL); + + fd = _open(path, flags, mode); + if (fd != -1) { + if (_fstat(fd, &stab) != 0 || !S_ISREG(stab.st_mode)) { + _close(fd); + errno = EINVAL; + return (-1); + } + + if (_fcntl(fd, F_SETFL, (int)FPOSIXSHM) != 0) { + _close(fd); + return (-1); + } + } + return (fd); +} + +int +shm_unlink(const char *path) +{ + return (unlink(path)); +} diff --git a/src/lib/libc/gen/pselect.c b/src/lib/libc/gen/pselect.c new file mode 100644 index 0000000..13b2553 --- /dev/null +++ b/src/lib/libc/gen/pselect.c @@ -0,0 +1,78 @@ +/* + * Copyright 2000 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/pselect.c,v 1.6 2002/10/12 16:13:37 mike Exp $"); + +#include "namespace.h" +#include +#include + +#include +#include +#include "un-namespace.h" + +__weak_reference(__pselect, pselect); + +/* + * Emulate the POSIX 1003.1g-2000 `pselect' interface. This is the + * same as the traditional BSD `select' function, except that it uses + * a timespec rather than a timeval, doesn't modify the timeout argument, + * and allows the user to specify a signal mask to apply during the select. + */ +int +__pselect(int count, fd_set * __restrict rfds, fd_set * __restrict wfds, + fd_set * __restrict efds, const struct timespec * __restrict timo, + const sigset_t * __restrict mask) +{ + sigset_t omask; + struct timeval tvtimo, *tvp; + int rv, sverrno; + + if (timo) { + TIMESPEC_TO_TIMEVAL(&tvtimo, timo); + tvp = &tvtimo; + } else + tvp = 0; + + if (mask != 0) { + rv = _sigprocmask(SIG_SETMASK, mask, &omask); + if (rv != 0) + return rv; + } + + rv = _select(count, rfds, wfds, efds, tvp); + if (mask != 0) { + sverrno = errno; + _sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0); + errno = sverrno; + } + + return rv; +} diff --git a/src/lib/libc/gen/psignal.c b/src/lib/libc/gen/psignal.c new file mode 100644 index 0000000..832e04b --- /dev/null +++ b/src/lib/libc/gen/psignal.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/psignal.c,v 1.7 2002/02/01 01:08:48 obrien Exp $"); + +/* + * Print the name of the signal indicated + * along with the supplied message. + */ +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" + +void +psignal(sig, s) + unsigned int sig; + const char *s; +{ + const char *c; + + if (sig < NSIG) + c = sys_siglist[sig]; + else + c = "Unknown signal"; + if (s != NULL && *s != '\0') { + (void)_write(STDERR_FILENO, s, strlen(s)); + (void)_write(STDERR_FILENO, ": ", 2); + } + (void)_write(STDERR_FILENO, c, strlen(c)); + (void)_write(STDERR_FILENO, "\n", 1); +} diff --git a/src/lib/libc/gen/pw_scan.c b/src/lib/libc/gen/pw_scan.c new file mode 100644 index 0000000..a5057f9 --- /dev/null +++ b/src/lib/libc/gen/pw_scan.c @@ -0,0 +1,205 @@ +/*- + * Copyright (c) 1990, 1993, 1994 + * 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[] = "@(#)pw_scan.c 8.3 (Berkeley) 4/2/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/pw_scan.c,v 1.25 2004/01/18 21:33:25 charnier Exp $"); + +/* + * This module is used to "verify" password entries by chpass(1) and + * pwd_mkdb(8). + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pw_scan.h" + +/* + * Some software assumes that IDs are short. We should emit warnings + * for id's which cannot be stored in a short, but we are more liberal + * by default, warning for IDs greater than USHRT_MAX. + * + * If pw_big_ids_warning is -1 on entry to pw_scan(), it will be set based + * on the existence of PW_SCAN_BIG_IDS in the environment. + */ +static int pw_big_ids_warning = -1; + +int +__pw_scan(char *bp, struct passwd *pw, int flags) +{ + uid_t id; + int root; + char *ep, *p, *sh; + + if (pw_big_ids_warning == -1) + pw_big_ids_warning = getenv("PW_SCAN_BIG_IDS") == NULL ? 1 : 0; + + pw->pw_fields = 0; + if (!(pw->pw_name = strsep(&bp, ":"))) /* login */ + goto fmt; + root = !strcmp(pw->pw_name, "root"); + if (pw->pw_name[0] && (pw->pw_name[0] != '+' || pw->pw_name[1] == '\0')) + pw->pw_fields |= _PWF_NAME; + + if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */ + goto fmt; + if (pw->pw_passwd[0]) + pw->pw_fields |= _PWF_PASSWD; + + if (!(p = strsep(&bp, ":"))) /* uid */ + goto fmt; + if (p[0]) + pw->pw_fields |= _PWF_UID; + else { + if (pw->pw_name[0] != '+' && pw->pw_name[0] != '-') { + if (flags & _PWSCAN_WARN) + warnx("no uid for user %s", pw->pw_name); + return (0); + } + } + id = strtoul(p, &ep, 10); + if (errno == ERANGE) { + if (flags & _PWSCAN_WARN) + warnx("%s > max uid value (%lu)", p, ULONG_MAX); + return (0); + } + if (*ep != '\0') { + if (flags & _PWSCAN_WARN) + warnx("%s uid is incorrect", p); + return (0); + } + if (root && id) { + if (flags & _PWSCAN_WARN) + warnx("root uid should be 0"); + return (0); + } + if (flags & _PWSCAN_WARN && pw_big_ids_warning && id > USHRT_MAX) { + warnx("%s > recommended max uid value (%u)", p, USHRT_MAX); + /*return (0);*/ /* THIS SHOULD NOT BE FATAL! */ + } + pw->pw_uid = id; + + if (!(p = strsep(&bp, ":"))) /* gid */ + goto fmt; + if (p[0]) + pw->pw_fields |= _PWF_GID; + else { + if (pw->pw_name[0] != '+' && pw->pw_name[0] != '-') { + if (flags & _PWSCAN_WARN) + warnx("no gid for user %s", pw->pw_name); + return (0); + } + } + id = strtoul(p, &ep, 10); + if (errno == ERANGE) { + if (flags & _PWSCAN_WARN) + warnx("%s > max gid value (%lu)", p, ULONG_MAX); + return (0); + } + if (*ep != '\0') { + if (flags & _PWSCAN_WARN) + warnx("%s gid is incorrect", p); + return (0); + } + if (flags & _PWSCAN_WARN && pw_big_ids_warning && id > USHRT_MAX) { + warnx("%s > recommended max gid value (%u)", p, USHRT_MAX); + /* return (0); This should not be fatal! */ + } + pw->pw_gid = id; + + if (flags & _PWSCAN_MASTER ) { + if (!(pw->pw_class = strsep(&bp, ":"))) /* class */ + goto fmt; + if (pw->pw_class[0]) + pw->pw_fields |= _PWF_CLASS; + + if (!(p = strsep(&bp, ":"))) /* change */ + goto fmt; + if (p[0]) + pw->pw_fields |= _PWF_CHANGE; + pw->pw_change = atol(p); + + if (!(p = strsep(&bp, ":"))) /* expire */ + goto fmt; + if (p[0]) + pw->pw_fields |= _PWF_EXPIRE; + pw->pw_expire = atol(p); + } + if (!(pw->pw_gecos = strsep(&bp, ":"))) /* gecos */ + goto fmt; + if (pw->pw_gecos[0]) + pw->pw_fields |= _PWF_GECOS; + + if (!(pw->pw_dir = strsep(&bp, ":"))) /* directory */ + goto fmt; + if (pw->pw_dir[0]) + pw->pw_fields |= _PWF_DIR; + + if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */ + goto fmt; + + p = pw->pw_shell; + if (root && *p) { /* empty == /bin/sh */ + for (setusershell();;) { + if (!(sh = getusershell())) { + if (flags & _PWSCAN_WARN) + warnx("warning, unknown root shell"); + break; + } + if (!strcmp(p, sh)) + break; + } + endusershell(); + } + if (p[0]) + pw->pw_fields |= _PWF_SHELL; + + if ((p = strsep(&bp, ":"))) { /* too many */ +fmt: + if (flags & _PWSCAN_WARN) + warnx("corrupted entry"); + return (0); + } + return (1); +} diff --git a/src/lib/libc/gen/pw_scan.h b/src/lib/libc/gen/pw_scan.h new file mode 100644 index 0000000..28669f7 --- /dev/null +++ b/src/lib/libc/gen/pw_scan.h @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 1994 + * 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. + * + * @(#)pw_scan.h 8.1 (Berkeley) 4/1/94 + * $FreeBSD: src/lib/libc/gen/pw_scan.h,v 1.6 2002/03/22 23:41:42 obrien Exp $ + */ + +#define _PWSCAN_MASTER 0x01 +#define _PWSCAN_WARN 0x02 + +extern int __pw_scan(char *, struct passwd *, int); diff --git a/src/lib/libc/gen/pwcache.c b/src/lib/libc/gen/pwcache.c new file mode 100644 index 0000000..2d4b272 --- /dev/null +++ b/src/lib/libc/gen/pwcache.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)pwcache.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/pwcache.c,v 1.10 2002/03/22 02:35:47 imp Exp $"); + +#include + +#include +#include +#include +#include +#include + +#define NCACHE 64 /* power of 2 */ +#define MASK (NCACHE - 1) /* bits to store with */ + +const char * +user_from_uid(uid_t uid, int nouser) +{ + static struct ncache { + uid_t uid; + int found; + char name[UT_NAMESIZE + 1]; + } c_uid[NCACHE]; + static int pwopen; + struct passwd *pw; + struct ncache *cp; + + cp = c_uid + (uid & MASK); + if (cp->uid != uid || !*cp->name) { + if (pwopen == 0) { + setpassent(1); + pwopen = 1; + } + pw = getpwuid(uid); + cp->uid = uid; + if (pw != NULL) { + cp->found = 1; + (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } else { + cp->found = 0; + (void)snprintf(cp->name, UT_NAMESIZE, "%u", uid); + if (nouser) + return (NULL); + } + } + return ((nouser && !cp->found) ? NULL : cp->name); +} + +const char * +group_from_gid(gid_t gid, int nogroup) +{ + static struct ncache { + gid_t gid; + int found; + char name[UT_NAMESIZE + 1]; + } c_gid[NCACHE]; + static int gropen; + struct group *gr; + struct ncache *cp; + + cp = c_gid + (gid & MASK); + if (cp->gid != gid || !*cp->name) { + if (gropen == 0) { + setgroupent(1); + gropen = 1; + } + gr = getgrgid(gid); + cp->gid = gid; + if (gr != NULL) { + cp->found = 1; + (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; + } else { + cp->found = 0; + (void)snprintf(cp->name, UT_NAMESIZE, "%u", gid); + if (nogroup) + return (NULL); + } + } + return ((nogroup && !cp->found) ? NULL : cp->name); +} diff --git a/src/lib/libc/gen/raise.c b/src/lib/libc/gen/raise.c new file mode 100644 index 0000000..4a94cb9 --- /dev/null +++ b/src/lib/libc/gen/raise.c @@ -0,0 +1,51 @@ +/*- + * 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[] = "@(#)raise.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/raise.c,v 1.4 2003/07/19 05:22:56 davidxu Exp $"); + +#include +#include + +__weak_reference(__raise, raise); +__weak_reference(__raise, _raise); + +int +__raise(s) + int s; +{ + return(kill(getpid(), s)); +} diff --git a/src/lib/libc/gen/rand48.h b/src/lib/libc/gen/rand48.h new file mode 100644 index 0000000..0a3d83d --- /dev/null +++ b/src/lib/libc/gen/rand48.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + * + * $FreeBSD: src/lib/libc/gen/rand48.h,v 1.2 2002/02/01 01:32:19 obrien Exp $ + */ + +#ifndef _RAND48_H_ +#define _RAND48_H_ + +#include +#include + +void _dorand48(unsigned short[3]); + +#define RAND48_SEED_0 (0x330e) +#define RAND48_SEED_1 (0xabcd) +#define RAND48_SEED_2 (0x1234) +#define RAND48_MULT_0 (0xe66d) +#define RAND48_MULT_1 (0xdeec) +#define RAND48_MULT_2 (0x0005) +#define RAND48_ADD (0x000b) + +#endif /* _RAND48_H_ */ diff --git a/src/lib/libc/gen/readdir.c b/src/lib/libc/gen/readdir.c new file mode 100644 index 0000000..fa0438c --- /dev/null +++ b/src/lib/libc/gen/readdir.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)readdir.c 8.3 (Berkeley) 9/29/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/readdir.c,v 1.11 2002/02/26 21:39:32 alfred Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" + +/* + * get next entry in a directory. + */ +struct dirent * +_readdir_unlocked(dirp) + DIR *dirp; +{ + struct dirent *dp; + + for (;;) { + if (dirp->dd_loc >= dirp->dd_size) { + if (dirp->dd_flags & __DTF_READALL) + return (NULL); + dirp->dd_loc = 0; + } + if (dirp->dd_loc == 0 && !(dirp->dd_flags & __DTF_READALL)) { + dirp->dd_size = _getdirentries(dirp->dd_fd, + dirp->dd_buf, dirp->dd_len, &dirp->dd_seek); + if (dirp->dd_size <= 0) + return (NULL); + } + dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc); + if ((long)dp & 03L) /* bogus pointer check */ + return (NULL); + if (dp->d_reclen <= 0 || + dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) + return (NULL); + dirp->dd_loc += dp->d_reclen; + if (dp->d_ino == 0) + continue; + if (dp->d_type == DT_WHT && (dirp->dd_flags & DTF_HIDEW)) + continue; + return (dp); + } +} + +struct dirent * +readdir(dirp) + DIR *dirp; +{ + struct dirent *dp; + + if (__isthreaded) { + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + dp = _readdir_unlocked(dirp); + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + } + else + dp = _readdir_unlocked(dirp); + return (dp); +} + +int +readdir_r(dirp, entry, result) + DIR *dirp; + struct dirent *entry; + struct dirent **result; +{ + struct dirent *dp; + int saved_errno; + + saved_errno = errno; + errno = 0; + if (__isthreaded) { + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + if ((dp = _readdir_unlocked(dirp)) != NULL) + memcpy(entry, dp, _GENERIC_DIRSIZ(dp)); + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + } + else if ((dp = _readdir_unlocked(dirp)) != NULL) + memcpy(entry, dp, _GENERIC_DIRSIZ(dp)); + + if (errno != 0) { + if (dp == NULL) + return (errno); + } else + errno = saved_errno; + + if (dp != NULL) + *result = entry; + else + *result = NULL; + + return (0); +} diff --git a/src/lib/libc/gen/readpassphrase.c b/src/lib/libc/gen/readpassphrase.c new file mode 100644 index 0000000..d100be4 --- /dev/null +++ b/src/lib/libc/gen/readpassphrase.c @@ -0,0 +1,178 @@ +/* $OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $ */ + +/* + * Copyright (c) 2000 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/readpassphrase.c,v 1.6 2002/03/09 03:16:41 green Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +static volatile sig_atomic_t signo; + +static void handler(int); + +char * +readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) +{ + ssize_t nr; + int input, output, save_errno; + char ch, *p, *end; + struct termios term, oterm; + struct sigaction sa, saveint, savehup, savequit, saveterm; + struct sigaction savetstp, savettin, savettou; + + /* I suppose we could alloc on demand in this case (XXX). */ + if (bufsiz == 0) { + errno = EINVAL; + return(NULL); + } + +restart: + /* + * Read and write to /dev/tty if available. If not, read from + * stdin and write to stderr unless a tty is required. + */ + if ((input = output = _open(_PATH_TTY, O_RDWR)) == -1) { + if (flags & RPP_REQUIRE_TTY) { + errno = ENOTTY; + return(NULL); + } + input = STDIN_FILENO; + output = STDERR_FILENO; + } + + /* + * Catch signals that would otherwise cause the user to end + * up with echo turned off in the shell. Don't worry about + * things like SIGALRM and SIGPIPE for now. + */ + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; /* don't restart system calls */ + sa.sa_handler = handler; + (void)_sigaction(SIGINT, &sa, &saveint); + (void)_sigaction(SIGHUP, &sa, &savehup); + (void)_sigaction(SIGQUIT, &sa, &savequit); + (void)_sigaction(SIGTERM, &sa, &saveterm); + (void)_sigaction(SIGTSTP, &sa, &savetstp); + (void)_sigaction(SIGTTIN, &sa, &savettin); + (void)_sigaction(SIGTTOU, &sa, &savettou); + + /* Turn off echo if possible. */ + if (tcgetattr(input, &oterm) == 0) { + memcpy(&term, &oterm, sizeof(term)); + if (!(flags & RPP_ECHO_ON)) + term.c_lflag &= ~(ECHO | ECHONL); + if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) + term.c_cc[VSTATUS] = _POSIX_VDISABLE; + (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term); + } else { + memset(&term, 0, sizeof(term)); + memset(&oterm, 0, sizeof(oterm)); + } + + (void)_write(output, prompt, strlen(prompt)); + end = buf + bufsiz - 1; + for (p = buf; (nr = _read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { + if (p < end) { + if ((flags & RPP_SEVENBIT)) + ch &= 0x7f; + if (isalpha(ch)) { + if ((flags & RPP_FORCELOWER)) + ch = tolower(ch); + if ((flags & RPP_FORCEUPPER)) + ch = toupper(ch); + } + *p++ = ch; + } + } + *p = '\0'; + save_errno = errno; + if (!(term.c_lflag & ECHO)) + (void)_write(output, "\n", 1); + + /* Restore old terminal settings and signals. */ + if (memcmp(&term, &oterm, sizeof(term)) != 0) + (void)tcsetattr(input, TCSANOW|TCSASOFT, &oterm); + (void)_sigaction(SIGINT, &saveint, NULL); + (void)_sigaction(SIGHUP, &savehup, NULL); + (void)_sigaction(SIGQUIT, &savequit, NULL); + (void)_sigaction(SIGTERM, &saveterm, NULL); + (void)_sigaction(SIGTSTP, &savetstp, NULL); + (void)_sigaction(SIGTTIN, &savettin, NULL); + (void)_sigaction(SIGTTOU, &savettou, NULL); + if (input != STDIN_FILENO) + (void)_close(input); + + /* + * If we were interrupted by a signal, resend it to ourselves + * now that we have restored the signal handlers. + */ + if (signo) { + kill(getpid(), signo); + switch (signo) { + case SIGTSTP: + case SIGTTIN: + case SIGTTOU: + signo = 0; + goto restart; + } + } + + errno = save_errno; + return(nr == -1 ? NULL : buf); +} + +char * +getpass(const char *prompt) +{ + static char buf[_PASSWORD_LEN + 1]; + + if (readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF) == NULL) + buf[0] = '\0'; + return(buf); +} + +static void handler(int s) +{ + + signo = s; +} diff --git a/src/lib/libc/gen/rewinddir.c b/src/lib/libc/gen/rewinddir.c new file mode 100644 index 0000000..dae75cc --- /dev/null +++ b/src/lib/libc/gen/rewinddir.c @@ -0,0 +1,52 @@ +/*- + * 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[] = "@(#)rewinddir.c 8.1 (Berkeley) 6/8/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/rewinddir.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include + +#include "telldir.h" + +void +rewinddir(dirp) + DIR *dirp; +{ + + _seekdir(dirp, dirp->dd_rewind); + dirp->dd_rewind = telldir(dirp); +} diff --git a/src/lib/libc/gen/scandir.c b/src/lib/libc/gen/scandir.c new file mode 100644 index 0000000..cf79bce --- /dev/null +++ b/src/lib/libc/gen/scandir.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)scandir.c 8.3 (Berkeley) 1/2/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/scandir.c,v 1.7 2002/02/01 01:32:19 obrien Exp $"); + +/* + * Scan the directory dirname calling select to make a list of selected + * directory entries then sort using qsort and compare routine dcomp. + * Returns the number of entries and a pointer to a list of pointers to + * struct dirent (through namelist). Returns -1 if there were any errors. + */ + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +/* + * The DIRSIZ macro is the minimum record length which will hold the directory + * entry. This requires the amount of space in struct dirent without the + * d_name field, plus enough space for the name and a terminating nul byte + * (dp->d_namlen + 1), rounded up to a 4 byte boundary. + */ +#undef DIRSIZ +#define DIRSIZ(dp) \ + ((sizeof(struct dirent) - sizeof(dp)->d_name) + \ + (((dp)->d_namlen + 1 + 3) &~ 3)) + +int +scandir(dirname, namelist, select, dcomp) + const char *dirname; + struct dirent ***namelist; + int (*select)(struct dirent *); + int (*dcomp)(const void *, const void *); +{ + struct dirent *d, *p, **names = NULL; + size_t nitems = 0; + struct stat stb; + long arraysz; + DIR *dirp; + + if ((dirp = opendir(dirname)) == NULL) + return(-1); + if (_fstat(dirp->dd_fd, &stb) < 0) + goto fail; + + /* + * estimate the array size by taking the size of the directory file + * and dividing it by a multiple of the minimum size entry. + */ + arraysz = (stb.st_size / 24); + names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); + if (names == NULL) + goto fail; + + while ((d = readdir(dirp)) != NULL) { + if (select != NULL && !(*select)(d)) + continue; /* just selected names */ + /* + * Make a minimum size copy of the data + */ + p = (struct dirent *)malloc(DIRSIZ(d)); + if (p == NULL) + goto fail; + p->d_fileno = d->d_fileno; + p->d_type = d->d_type; + p->d_reclen = d->d_reclen; + p->d_namlen = d->d_namlen; + bcopy(d->d_name, p->d_name, p->d_namlen + 1); + /* + * Check to make sure the array has space left and + * realloc the maximum size. + */ + if (nitems >= arraysz) { + const int inc = 10; /* increase by this much */ + struct dirent **names2; + + names2 = (struct dirent **)realloc((char *)names, + (arraysz + inc) * sizeof(struct dirent *)); + if (names2 == NULL) { + free(p); + goto fail; + } + names = names2; + arraysz += inc; + } + names[nitems++] = p; + } + closedir(dirp); + if (nitems && dcomp != NULL) + qsort(names, nitems, sizeof(struct dirent *), dcomp); + *namelist = names; + return(nitems); + +fail: + while (nitems > 0) + free(names[--nitems]); + free(names); + closedir(dirp); + return -1; +} + +/* + * Alphabetic order comparison routine for those who want it. + */ +int +alphasort(d1, d2) + const void *d1; + const void *d2; +{ + return(strcmp((*(struct dirent **)d1)->d_name, + (*(struct dirent **)d2)->d_name)); +} diff --git a/src/lib/libc/gen/seed48.c b/src/lib/libc/gen/seed48.c new file mode 100644 index 0000000..94167a7 --- /dev/null +++ b/src/lib/libc/gen/seed48.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/seed48.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; +extern unsigned short _rand48_mult[3]; +extern unsigned short _rand48_add; + +unsigned short * +seed48(unsigned short xseed[3]) +{ + static unsigned short sseed[3]; + + sseed[0] = _rand48_seed[0]; + sseed[1] = _rand48_seed[1]; + sseed[2] = _rand48_seed[2]; + _rand48_seed[0] = xseed[0]; + _rand48_seed[1] = xseed[1]; + _rand48_seed[2] = xseed[2]; + _rand48_mult[0] = RAND48_MULT_0; + _rand48_mult[1] = RAND48_MULT_1; + _rand48_mult[2] = RAND48_MULT_2; + _rand48_add = RAND48_ADD; + return sseed; +} diff --git a/src/lib/libc/gen/seekdir.c b/src/lib/libc/gen/seekdir.c new file mode 100644 index 0000000..5385819 --- /dev/null +++ b/src/lib/libc/gen/seekdir.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)seekdir.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/seekdir.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" +#include "telldir.h" + +/* + * Seek to an entry in a directory. + * _seekdir is in telldir.c so that it can share opaque data structures. + */ +void +seekdir(dirp, loc) + DIR *dirp; + long loc; +{ + if (__isthreaded) + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _seekdir(dirp, loc); + if (__isthreaded) + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); +} diff --git a/src/lib/libc/gen/sem.c b/src/lib/libc/gen/sem.c new file mode 100644 index 0000000..4054e3a --- /dev/null +++ b/src/lib/libc/gen/sem.c @@ -0,0 +1,360 @@ +/* + * Copyright (C) 2000 Jason Evans . + * 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(s), this list of conditions and the following disclaimer as + * the first lines of this file unmodified other than the possible + * addition of one or more copyright notices. + * 2. Redistributions in binary form must reproduce the above copyright + * notice(s), this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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. + * + * $FreeBSD: src/lib/libc/gen/sem.c,v 1.13 2004/02/06 15:15:44 deischen Exp $ + */ + +/* + * Some notes about this implementation. + * + * This is mostly a simple implementation of POSIX semaphores that + * does not need threading. Any semaphore created is a kernel-based + * semaphore regardless of the pshared attribute. This is necessary + * because libc's stub for pthread_cond_wait() doesn't really wait, + * and it is not worth the effort impose this behavior on libc. + * + * All functions here are designed to be thread-safe so that a + * threads library need not provide wrappers except to make + * sem_wait() and sem_timedwait() cancellation points or to + * provide a faster userland implementation for non-pshared + * semaphores. + * + * Also, this implementation of semaphores cannot really support + * real pshared semaphores. The sem_t is an allocated object + * and can't be seen by other processes when placed in shared + * memory. It should work across forks as long as the semaphore + * is created before any forks. + * + * The function sem_init() should be overridden by a threads + * library if it wants to provide a different userland version + * of semaphores. The functions sem_wait() and sem_timedwait() + * need to be wrapped to provide cancellation points. The function + * sem_post() may need to be wrapped to be signal-safe. + */ +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include <_semaphore.h> +#include "un-namespace.h" +#include "libc_private.h" + +static sem_t sem_alloc(unsigned int value, semid_t semid, int system_sem); +static void sem_free(sem_t sem); + +static LIST_HEAD(, sem) named_sems = LIST_HEAD_INITIALIZER(&named_sems); +static pthread_mutex_t named_sems_mtx = PTHREAD_MUTEX_INITIALIZER; + +__weak_reference(__sem_init, sem_init); +__weak_reference(__sem_destroy, sem_destroy); +__weak_reference(__sem_open, sem_open); +__weak_reference(__sem_close, sem_close); +__weak_reference(__sem_unlink, sem_unlink); +__weak_reference(__sem_wait, sem_wait); +__weak_reference(__sem_trywait, sem_trywait); +__weak_reference(__sem_timedwait, sem_timedwait); +__weak_reference(__sem_post, sem_post); +__weak_reference(__sem_getvalue, sem_getvalue); + + +static inline int +sem_check_validity(sem_t *sem) +{ + + if ((sem != NULL) && ((*sem)->magic == SEM_MAGIC)) + return (0); + else { + errno = EINVAL; + return (-1); + } +} + +static void +sem_free(sem_t sem) +{ + + _pthread_mutex_destroy(&sem->lock); + _pthread_cond_destroy(&sem->gtzero); + sem->magic = 0; + free(sem); +} + +static sem_t +sem_alloc(unsigned int value, semid_t semid, int system_sem) +{ + sem_t sem; + + if (value > SEM_VALUE_MAX) { + errno = EINVAL; + return (NULL); + } + + sem = (sem_t)malloc(sizeof(struct sem)); + if (sem == NULL) { + errno = ENOSPC; + return (NULL); + } + + sem->count = (u_int32_t)value; + sem->nwaiters = 0; + sem->magic = SEM_MAGIC; + sem->semid = semid; + sem->syssem = system_sem; + sem->lock = PTHREAD_MUTEX_INITIALIZER; + sem->gtzero = PTHREAD_COND_INITIALIZER; + return (sem); +} + +int +__sem_init(sem_t *sem, int pshared, unsigned int value) +{ + semid_t semid; + + /* + * We always have to create the kernel semaphore if the + * threads library isn't present since libc's version of + * pthread_cond_wait() is just a stub that doesn't really + * wait. + */ + if (ksem_init(&semid, value) != 0) + return (-1); + + (*sem) = sem_alloc(value, semid, 1); + if ((*sem) == NULL) { + ksem_destroy(semid); + return (-1); + } + return (0); +} + +int +__sem_destroy(sem_t *sem) +{ + int retval; + + if (sem_check_validity(sem) != 0) + return (-1); + + _pthread_mutex_lock(&(*sem)->lock); + /* + * If this is a system semaphore let the kernel track it otherwise + * make sure there are no waiters. + */ + if ((*sem)->syssem != 0) + retval = ksem_destroy((*sem)->semid); + else if ((*sem)->nwaiters > 0) { + errno = EBUSY; + retval = -1; + } + else { + retval = 0; + (*sem)->magic = 0; + } + _pthread_mutex_unlock(&(*sem)->lock); + + if (retval == 0) { + _pthread_mutex_destroy(&(*sem)->lock); + _pthread_cond_destroy(&(*sem)->gtzero); + sem_free(*sem); + } + return (retval); +} + +sem_t * +__sem_open(const char *name, int oflag, ...) +{ + sem_t *sem; + sem_t s; + semid_t semid; + mode_t mode; + unsigned int value; + + mode = 0; + value = 0; + + if ((oflag & O_CREAT) != 0) { + va_list ap; + + va_start(ap, oflag); + mode = va_arg(ap, int); + value = va_arg(ap, unsigned int); + va_end(ap); + } + /* + * we can be lazy and let the kernel handle the "oflag", + * we'll just merge duplicate IDs into our list. + */ + if (ksem_open(&semid, name, oflag, mode, value) == -1) + return (SEM_FAILED); + /* + * search for a duplicate ID, we must return the same sem_t * + * if we locate one. + */ + _pthread_mutex_lock(&named_sems_mtx); + LIST_FOREACH(s, &named_sems, entry) { + if (s->semid == semid) { + sem = s->backpointer; + _pthread_mutex_unlock(&named_sems_mtx); + return (sem); + } + } + sem = (sem_t *)malloc(sizeof(*sem)); + if (sem == NULL) + goto err; + *sem = sem_alloc(value, semid, 1); + if ((*sem) == NULL) + goto err; + LIST_INSERT_HEAD(&named_sems, *sem, entry); + (*sem)->backpointer = sem; + _pthread_mutex_unlock(&named_sems_mtx); + return (sem); +err: + _pthread_mutex_unlock(&named_sems_mtx); + ksem_close(semid); + if (sem != NULL) { + if (*sem != NULL) + sem_free(*sem); + else + errno = ENOSPC; + free(sem); + } else { + errno = ENOSPC; + } + return (SEM_FAILED); +} + +int +__sem_close(sem_t *sem) +{ + + if (sem_check_validity(sem) != 0) + return (-1); + + if ((*sem)->syssem == 0) { + errno = EINVAL; + return (-1); + } + + _pthread_mutex_lock(&named_sems_mtx); + if (ksem_close((*sem)->semid) != 0) { + _pthread_mutex_unlock(&named_sems_mtx); + return (-1); + } + LIST_REMOVE((*sem), entry); + _pthread_mutex_unlock(&named_sems_mtx); + sem_free(*sem); + *sem = NULL; + free(sem); + return (0); +} + +int +__sem_unlink(const char *name) +{ + + return (ksem_unlink(name)); +} + +int +__sem_wait(sem_t *sem) +{ + + if (sem_check_validity(sem) != 0) + return (-1); + + return (ksem_wait((*sem)->semid)); +} + +int +__sem_trywait(sem_t *sem) +{ + int retval; + + if (sem_check_validity(sem) != 0) + return (-1); + + if ((*sem)->syssem != 0) + retval = ksem_trywait((*sem)->semid); + else { + _pthread_mutex_lock(&(*sem)->lock); + if ((*sem)->count > 0) { + (*sem)->count--; + retval = 0; + } else { + errno = EAGAIN; + retval = -1; + } + _pthread_mutex_unlock(&(*sem)->lock); + } + return (retval); +} + +int +__sem_timedwait(sem_t * __restrict sem, + struct timespec * __restrict abs_timeout) +{ + if (sem_check_validity(sem) != 0) + return (-1); + + return (ksem_timedwait((*sem)->semid, abs_timeout)); +} + +int +__sem_post(sem_t *sem) +{ + + if (sem_check_validity(sem) != 0) + return (-1); + + return (ksem_post((*sem)->semid)); +} + +int +__sem_getvalue(sem_t * __restrict sem, int * __restrict sval) +{ + int retval; + + if (sem_check_validity(sem) != 0) + return (-1); + + if ((*sem)->syssem != 0) + retval = ksem_getvalue((*sem)->semid, sval); + else { + _pthread_mutex_lock(&(*sem)->lock); + *sval = (int)(*sem)->count; + _pthread_mutex_unlock(&(*sem)->lock); + + retval = 0; + } + return (retval); +} diff --git a/src/lib/libc/gen/semctl.c b/src/lib/libc/gen/semctl.c new file mode 100644 index 0000000..4c0b249 --- /dev/null +++ b/src/lib/libc/gen/semctl.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2002 Doug Rabson + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/semctl.c,v 1.9 2003/02/16 17:29:09 nectar Exp $"); + +#include +#include +#include +#include +#include + +extern int __semctl(int semid, int semnum, int cmd, union semun *arg); + +int semctl(int semid, int semnum, int cmd, ...) +{ + va_list ap; + union semun semun; + union semun *semun_ptr; + + va_start(ap, cmd); + if (cmd == IPC_SET || cmd == IPC_STAT || cmd == GETALL + || cmd == SETVAL || cmd == SETALL) { + semun = va_arg(ap, union semun); + semun_ptr = &semun; + } else { + semun_ptr = NULL; + } + va_end(ap); + + return (__semctl(semid, semnum, cmd, semun_ptr)); +} diff --git a/src/lib/libc/gen/setdomainname.c b/src/lib/libc/gen/setdomainname.c new file mode 100644 index 0000000..571a73f --- /dev/null +++ b/src/lib/libc/gen/setdomainname.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)sethostname.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/setdomainname.c,v 1.7 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include + +#include + +int +setdomainname(const char *name, int namelen) +{ + int mib[2]; + + mib[0] = CTL_KERN; + mib[1] = KERN_NISDOMAINNAME; + if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1) + return (-1); + return (0); +} diff --git a/src/lib/libc/gen/sethostname.c b/src/lib/libc/gen/sethostname.c new file mode 100644 index 0000000..3a15727 --- /dev/null +++ b/src/lib/libc/gen/sethostname.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)sethostname.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/sethostname.c,v 1.4 2002/05/28 16:59:39 alfred Exp $"); + +#include +#include + +int +sethostname(const char *name, int namelen) +{ + int mib[2]; + + mib[0] = CTL_KERN; + mib[1] = KERN_HOSTNAME; + if (sysctl(mib, 2, NULL, NULL, (void *)name, namelen) == -1) + return (-1); + return (0); +} diff --git a/src/lib/libc/gen/setjmperr.c b/src/lib/libc/gen/setjmperr.c new file mode 100644 index 0000000..d5d8d06 --- /dev/null +++ b/src/lib/libc/gen/setjmperr.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1980, 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[] = "@(#)setjmperr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/setjmperr.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); + +/* + * This routine is called from longjmp() when an error occurs. + * Programs that wish to exit gracefully from this error may + * write their own versions. + * If this routine returns, the program is aborted. + */ + +#include "namespace.h" +#include +#include +#include "un-namespace.h" + +void +longjmperror() +{ +#define ERRMSG "longjmp botch.\n" + (void)_write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1); +} diff --git a/src/lib/libc/gen/setmode.c b/src/lib/libc/gen/setmode.c new file mode 100644 index 0000000..3e4a6ee --- /dev/null +++ b/src/lib/libc/gen/setmode.c @@ -0,0 +1,459 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Dave Borman at Cray Research, Inc. + * + * 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[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/setmode.c,v 1.9 2003/02/23 00:24:03 mikeh Exp $"); + +#include "namespace.h" +#include +#include + +#include +#include +#include +#include +#include + +#ifdef SETMODE_DEBUG +#include +#endif +#include "un-namespace.h" + +#define SET_LEN 6 /* initial # of bitcmd struct to malloc */ +#define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */ + +typedef struct bitcmd { + char cmd; + char cmd2; + mode_t bits; +} BITCMD; + +#define CMD2_CLR 0x01 +#define CMD2_SET 0x02 +#define CMD2_GBITS 0x04 +#define CMD2_OBITS 0x08 +#define CMD2_UBITS 0x10 + +static BITCMD *addcmd(BITCMD *, int, int, int, u_int); +static void compress_mode(BITCMD *); +#ifdef SETMODE_DEBUG +static void dumpmode(BITCMD *); +#endif + +/* + * Given the old mode and an array of bitcmd structures, apply the operations + * described in the bitcmd structures to the old mode, and return the new mode. + * Note that there is no '=' command; a strict assignment is just a '-' (clear + * bits) followed by a '+' (set bits). + */ +mode_t +getmode(bbox, omode) + const void *bbox; + mode_t omode; +{ + const BITCMD *set; + mode_t clrval, newmode, value; + + set = (const BITCMD *)bbox; + newmode = omode; + for (value = 0;; set++) + switch(set->cmd) { + /* + * When copying the user, group or other bits around, we "know" + * where the bits are in the mode so that we can do shifts to + * copy them around. If we don't use shifts, it gets real + * grundgy with lots of single bit checks and bit sets. + */ + case 'u': + value = (newmode & S_IRWXU) >> 6; + goto common; + + case 'g': + value = (newmode & S_IRWXG) >> 3; + goto common; + + case 'o': + value = newmode & S_IRWXO; +common: if (set->cmd2 & CMD2_CLR) { + clrval = + (set->cmd2 & CMD2_SET) ? S_IRWXO : value; + if (set->cmd2 & CMD2_UBITS) + newmode &= ~((clrval<<6) & set->bits); + if (set->cmd2 & CMD2_GBITS) + newmode &= ~((clrval<<3) & set->bits); + if (set->cmd2 & CMD2_OBITS) + newmode &= ~(clrval & set->bits); + } + if (set->cmd2 & CMD2_SET) { + if (set->cmd2 & CMD2_UBITS) + newmode |= (value<<6) & set->bits; + if (set->cmd2 & CMD2_GBITS) + newmode |= (value<<3) & set->bits; + if (set->cmd2 & CMD2_OBITS) + newmode |= value & set->bits; + } + break; + + case '+': + newmode |= set->bits; + break; + + case '-': + newmode &= ~set->bits; + break; + + case 'X': + if (omode & (S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH)) + newmode |= set->bits; + break; + + case '\0': + default: +#ifdef SETMODE_DEBUG + (void)printf("getmode:%04o -> %04o\n", omode, newmode); +#endif + return (newmode); + } +} + +#define ADDCMD(a, b, c, d) \ + if (set >= endset) { \ + BITCMD *newset; \ + setlen += SET_LEN_INCR; \ + newset = realloc(saveset, sizeof(BITCMD) * setlen); \ + if (!newset) { \ + if (saveset) \ + free(saveset); \ + saveset = NULL; \ + return (NULL); \ + } \ + set = newset + (set - saveset); \ + saveset = newset; \ + endset = newset + (setlen - 2); \ + } \ + set = addcmd(set, (a), (b), (c), (d)) + +#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) + +void * +setmode(p) + const char *p; +{ + int perm, who; + char op, *ep; + BITCMD *set, *saveset, *endset; + sigset_t sigset, sigoset; + mode_t mask; + int equalopdone=0, permXbits, setlen; + long perml; + + if (!*p) + return (NULL); + + /* + * Get a copy of the mask for the permissions that are mask relative. + * Flip the bits, we want what's not set. Since it's possible that + * the caller is opening files inside a signal handler, protect them + * as best we can. + */ + sigfillset(&sigset); + (void)_sigprocmask(SIG_BLOCK, &sigset, &sigoset); + (void)umask(mask = umask(0)); + mask = ~mask; + (void)_sigprocmask(SIG_SETMASK, &sigoset, NULL); + + setlen = SET_LEN + 2; + + if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL) + return (NULL); + saveset = set; + endset = set + (setlen - 2); + + /* + * If an absolute number, get it and return; disallow non-octal digits + * or illegal bits. + */ + if (isdigit((unsigned char)*p)) { + perml = strtol(p, &ep, 8); + if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) { + free(saveset); + return (NULL); + } + perm = (mode_t)perml; + ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); + set->cmd = 0; + return (saveset); + } + + /* + * Build list of structures to set/clear/copy bits as described by + * each clause of the symbolic mode. + */ + for (;;) { + /* First, find out which bits might be modified. */ + for (who = 0;; ++p) { + switch (*p) { + case 'a': + who |= STANDARD_BITS; + break; + case 'u': + who |= S_ISUID|S_IRWXU; + break; + case 'g': + who |= S_ISGID|S_IRWXG; + break; + case 'o': + who |= S_IRWXO; + break; + default: + goto getop; + } + } + +getop: if ((op = *p++) != '+' && op != '-' && op != '=') { + free(saveset); + return (NULL); + } + if (op == '=') + equalopdone = 0; + + who &= ~S_ISTXT; + for (perm = 0, permXbits = 0;; ++p) { + switch (*p) { + case 'r': + perm |= S_IRUSR|S_IRGRP|S_IROTH; + break; + case 's': + /* If only "other" bits ignore set-id. */ + if (!who || who & ~S_IRWXO) + perm |= S_ISUID|S_ISGID; + break; + case 't': + /* If only "other" bits ignore sticky. */ + if (!who || who & ~S_IRWXO) { + who |= S_ISTXT; + perm |= S_ISTXT; + } + break; + case 'w': + perm |= S_IWUSR|S_IWGRP|S_IWOTH; + break; + case 'X': + permXbits = S_IXUSR|S_IXGRP|S_IXOTH; + break; + case 'x': + perm |= S_IXUSR|S_IXGRP|S_IXOTH; + break; + case 'u': + case 'g': + case 'o': + /* + * When ever we hit 'u', 'g', or 'o', we have + * to flush out any partial mode that we have, + * and then do the copying of the mode bits. + */ + if (perm) { + ADDCMD(op, who, perm, mask); + perm = 0; + } + if (op == '=') + equalopdone = 1; + if (op == '+' && permXbits) { + ADDCMD('X', who, permXbits, mask); + permXbits = 0; + } + ADDCMD(*p, who, op, mask); + break; + + default: + /* + * Add any permissions that we haven't already + * done. + */ + if (perm || (op == '=' && !equalopdone)) { + if (op == '=') + equalopdone = 1; + ADDCMD(op, who, perm, mask); + perm = 0; + } + if (permXbits) { + ADDCMD('X', who, permXbits, mask); + permXbits = 0; + } + goto apply; + } + } + +apply: if (!*p) + break; + if (*p != ',') + goto getop; + ++p; + } + set->cmd = 0; +#ifdef SETMODE_DEBUG + (void)printf("Before compress_mode()\n"); + dumpmode(saveset); +#endif + compress_mode(saveset); +#ifdef SETMODE_DEBUG + (void)printf("After compress_mode()\n"); + dumpmode(saveset); +#endif + return (saveset); +} + +static BITCMD * +addcmd(set, op, who, oparg, mask) + BITCMD *set; + int oparg, who; + int op; + u_int mask; +{ + switch (op) { + case '=': + set->cmd = '-'; + set->bits = who ? who : STANDARD_BITS; + set++; + + op = '+'; + /* FALLTHROUGH */ + case '+': + case '-': + case 'X': + set->cmd = op; + set->bits = (who ? who : mask) & oparg; + break; + + case 'u': + case 'g': + case 'o': + set->cmd = op; + if (who) { + set->cmd2 = ((who & S_IRUSR) ? CMD2_UBITS : 0) | + ((who & S_IRGRP) ? CMD2_GBITS : 0) | + ((who & S_IROTH) ? CMD2_OBITS : 0); + set->bits = (mode_t)~0; + } else { + set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS; + set->bits = mask; + } + + if (oparg == '+') + set->cmd2 |= CMD2_SET; + else if (oparg == '-') + set->cmd2 |= CMD2_CLR; + else if (oparg == '=') + set->cmd2 |= CMD2_SET|CMD2_CLR; + break; + } + return (set + 1); +} + +#ifdef SETMODE_DEBUG +static void +dumpmode(set) + BITCMD *set; +{ + for (; set->cmd; ++set) + (void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n", + set->cmd, set->bits, set->cmd2 ? " cmd2:" : "", + set->cmd2 & CMD2_CLR ? " CLR" : "", + set->cmd2 & CMD2_SET ? " SET" : "", + set->cmd2 & CMD2_UBITS ? " UBITS" : "", + set->cmd2 & CMD2_GBITS ? " GBITS" : "", + set->cmd2 & CMD2_OBITS ? " OBITS" : ""); +} +#endif + +/* + * Given an array of bitcmd structures, compress by compacting consecutive + * '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u', + * 'g' and 'o' commands continue to be separate. They could probably be + * compacted, but it's not worth the effort. + */ +static void +compress_mode(set) + BITCMD *set; +{ + BITCMD *nset; + int setbits, clrbits, Xbits, op; + + for (nset = set;;) { + /* Copy over any 'u', 'g' and 'o' commands. */ + while ((op = nset->cmd) != '+' && op != '-' && op != 'X') { + *set++ = *nset++; + if (!op) + return; + } + + for (setbits = clrbits = Xbits = 0;; nset++) { + if ((op = nset->cmd) == '-') { + clrbits |= nset->bits; + setbits &= ~nset->bits; + Xbits &= ~nset->bits; + } else if (op == '+') { + setbits |= nset->bits; + clrbits &= ~nset->bits; + Xbits &= ~nset->bits; + } else if (op == 'X') + Xbits |= nset->bits & ~setbits; + else + break; + } + if (clrbits) { + set->cmd = '-'; + set->cmd2 = 0; + set->bits = clrbits; + set++; + } + if (setbits) { + set->cmd = '+'; + set->cmd2 = 0; + set->bits = setbits; + set++; + } + if (Xbits) { + set->cmd = 'X'; + set->cmd2 = 0; + set->bits = Xbits; + set++; + } + } +} diff --git a/src/lib/libc/gen/setproctitle.c b/src/lib/libc/gen/setproctitle.c new file mode 100644 index 0000000..433bba2 --- /dev/null +++ b/src/lib/libc/gen/setproctitle.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 1995 Peter Wemm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice immediately at the beginning of the file, without modification, + * 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. Absolutely no warranty of function or purpose is made by the author + * Peter Wemm. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/setproctitle.c,v 1.18 2003/07/01 09:45:35 alfred Exp $"); + +#include "namespace.h" +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" + +/* + * Older FreeBSD 2.0, 2.1 and 2.2 had different ps_strings structures and + * in different locations. + * 1: old_ps_strings at the very top of the stack. + * 2: old_ps_strings at SPARE_USRSPACE below the top of the stack. + * 3: ps_strings at the very top of the stack. + * This attempts to support a kernel built in the #2 and #3 era. + */ + +struct old_ps_strings { + char *old_ps_argvstr; + int old_ps_nargvstr; + char *old_ps_envstr; + int old_ps_nenvstr; +}; +#define OLD_PS_STRINGS ((struct old_ps_strings *) \ + (USRSTACK - SPARE_USRSPACE - sizeof(struct old_ps_strings))) + +#include + +#define SPT_BUFSIZE 2048 /* from other parts of sendmail */ + +void +setproctitle(const char *fmt, ...) +{ + static struct ps_strings *ps_strings; + static char *buf = NULL; + static char *obuf = NULL; + static char **oargv, *kbuf; + static int oargc = -1; + static char *nargv[2] = { NULL, NULL }; + char **nargvp; + int nargc; + int i; + va_list ap; + size_t len; + unsigned long ul_ps_strings; + int oid[4]; + + if (buf == NULL) { + buf = malloc(SPT_BUFSIZE); + if (buf == NULL) + return; + nargv[0] = buf; + } + + if (obuf == NULL ) { + obuf = malloc(SPT_BUFSIZE); + if (obuf == NULL) + return; + *obuf = '\0'; + } + + va_start(ap, fmt); + + if (fmt) { + buf[SPT_BUFSIZE - 1] = '\0'; + + if (fmt[0] == '-') { + /* skip program name prefix */ + fmt++; + len = 0; + } else { + /* print program name heading for grep */ + (void)snprintf(buf, SPT_BUFSIZE, "%s: ", _getprogname()); + len = strlen(buf); + } + + /* print the argument string */ + (void) vsnprintf(buf + len, SPT_BUFSIZE - len, fmt, ap); + + nargvp = nargv; + nargc = 1; + kbuf = buf; + } else if (*obuf != '\0') { + /* Idea from NetBSD - reset the title on fmt == NULL */ + nargvp = oargv; + nargc = oargc; + kbuf = obuf; + } else + /* Nothing to restore */ + return; + + va_end(ap); + + /* Set the title into the kernel cached command line */ + oid[0] = CTL_KERN; + oid[1] = KERN_PROC; + oid[2] = KERN_PROC_ARGS; + oid[3] = getpid(); + sysctl(oid, 4, 0, 0, kbuf, strlen(kbuf) + 1); + + if (ps_strings == NULL) { + len = sizeof(ul_ps_strings); + if (sysctlbyname("kern.ps_strings", &ul_ps_strings, &len, NULL, + 0) == -1) + ul_ps_strings = PS_STRINGS; + ps_strings = (struct ps_strings *)ul_ps_strings; + } + + /* PS_STRINGS points to zeroed memory on a style #2 kernel */ + if (ps_strings->ps_argvstr) { + /* style #3 */ + if (oargc == -1) { + /* Record our original args */ + oargc = ps_strings->ps_nargvstr; + oargv = ps_strings->ps_argvstr; + for (i = len = 0; i < oargc; i++) { + /* + * The program may have scribbled into its + * argv array, e.g., to remove some arguments. + * If that has happened, break out before + * trying to call strlen on a NULL pointer. + */ + if (oargv[i] == NULL) { + oargc = i; + break; + } + snprintf(obuf + len, SPT_BUFSIZE - len, "%s%s", + len ? " " : "", oargv[i]); + if (len) + len++; + len += strlen(oargv[i]); + if (len >= SPT_BUFSIZE) + break; + } + } + ps_strings->ps_nargvstr = nargc; + ps_strings->ps_argvstr = nargvp; + } else { + /* style #2 - we can only restore our first arg :-( */ + if (*obuf == '\0') + strncpy(obuf, OLD_PS_STRINGS->old_ps_argvstr, + SPT_BUFSIZE - 1); + OLD_PS_STRINGS->old_ps_nargvstr = 1; + OLD_PS_STRINGS->old_ps_argvstr = nargvp[0]; + } +} diff --git a/src/lib/libc/gen/setprogname.c b/src/lib/libc/gen/setprogname.c new file mode 100644 index 0000000..654bef4 --- /dev/null +++ b/src/lib/libc/gen/setprogname.c @@ -0,0 +1,19 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/setprogname.c,v 1.8 2002/03/29 22:43:41 markm Exp $"); + +#include +#include + +#include "libc_private.h" + +void +setprogname(const char *progname) +{ + const char *p; + + p = strrchr(progname, '/'); + if (p != NULL) + __progname = p + 1; + else + __progname = progname; +} diff --git a/src/lib/libc/gen/siginterrupt.c b/src/lib/libc/gen/siginterrupt.c new file mode 100644 index 0000000..8c719f8 --- /dev/null +++ b/src/lib/libc/gen/siginterrupt.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/siginterrupt.c,v 1.4 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" + +/* + * Set signal state to prevent restart of system calls + * after an instance of the indicated signal. + */ +int +siginterrupt(sig, flag) + int sig, flag; +{ + extern sigset_t _sigintr; + struct sigaction sa; + int ret; + + if ((ret = _sigaction(sig, (struct sigaction *)0, &sa)) < 0) + return (ret); + if (flag) { + sigaddset(&_sigintr, sig); + sa.sa_flags &= ~SA_RESTART; + } else { + sigdelset(&_sigintr, sig); + sa.sa_flags |= SA_RESTART; + } + return (_sigaction(sig, &sa, (struct sigaction *)0)); +} diff --git a/src/lib/libc/gen/siglist.c b/src/lib/libc/gen/siglist.c new file mode 100644 index 0000000..f269026 --- /dev/null +++ b/src/lib/libc/gen/siglist.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)siglist.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/siglist.c,v 1.4 2002/09/07 08:14:19 jmallett Exp $"); + +#include +#include + +const char *const sys_signame[NSIG] = { + "Signal 0", + "hup", /* SIGHUP */ + "int", /* SIGINT */ + "quit", /* SIGQUIT */ + "ill", /* SIGILL */ + "trap", /* SIGTRAP */ + "abrt", /* SIGABRT */ + "emt", /* SIGEMT */ + "fpe", /* SIGFPE */ + "kill", /* SIGKILL */ + "bus", /* SIGBUS */ + "segv", /* SIGSEGV */ + "sys", /* SIGSYS */ + "pipe", /* SIGPIPE */ + "alrm", /* SIGALRM */ + "term", /* SIGTERM */ + "urg", /* SIGURG */ + "stop", /* SIGSTOP */ + "tstp", /* SIGTSTP */ + "cont", /* SIGCONT */ + "chld", /* SIGCHLD */ + "ttin", /* SIGTTIN */ + "ttou", /* SIGTTOU */ + "io", /* SIGIO */ + "xcpu", /* SIGXCPU */ + "xfsz", /* SIGXFSZ */ + "vtalrm", /* SIGVTALRM */ + "prof", /* SIGPROF */ + "winch", /* SIGWINCH */ + "info", /* SIGINFO */ + "usr1", /* SIGUSR1 */ + "usr2" /* SIGUSR2 */ +}; + +const char *const sys_siglist[NSIG] = { + "Signal 0", + "Hangup", /* SIGHUP */ + "Interrupt", /* SIGINT */ + "Quit", /* SIGQUIT */ + "Illegal instruction", /* SIGILL */ + "Trace/BPT trap", /* SIGTRAP */ + "Abort trap", /* SIGABRT */ + "EMT trap", /* SIGEMT */ + "Floating point exception", /* SIGFPE */ + "Killed", /* SIGKILL */ + "Bus error", /* SIGBUS */ + "Segmentation fault", /* SIGSEGV */ + "Bad system call", /* SIGSYS */ + "Broken pipe", /* SIGPIPE */ + "Alarm clock", /* SIGALRM */ + "Terminated", /* SIGTERM */ + "Urgent I/O condition", /* SIGURG */ + "Suspended (signal)", /* SIGSTOP */ + "Suspended", /* SIGTSTP */ + "Continued", /* SIGCONT */ + "Child exited", /* SIGCHLD */ + "Stopped (tty input)", /* SIGTTIN */ + "Stopped (tty output)", /* SIGTTOU */ + "I/O possible", /* SIGIO */ + "Cputime limit exceeded", /* SIGXCPU */ + "Filesize limit exceeded", /* SIGXFSZ */ + "Virtual timer expired", /* SIGVTALRM */ + "Profiling timer expired", /* SIGPROF */ + "Window size changes", /* SIGWINCH */ + "Information request", /* SIGINFO */ + "User defined signal 1", /* SIGUSR1 */ + "User defined signal 2" /* SIGUSR2 */ +}; +const int sys_nsig = sizeof(sys_siglist) / sizeof(sys_siglist[0]); diff --git a/src/lib/libc/gen/signal.c b/src/lib/libc/gen/signal.c new file mode 100644 index 0000000..a958347 --- /dev/null +++ b/src/lib/libc/gen/signal.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1985, 1989, 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[] = "@(#)signal.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/signal.c,v 1.3 2002/02/01 00:57:29 obrien Exp $"); + +/* + * Almost backwards compatible signal. + */ +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" + +sigset_t _sigintr; /* shared with siginterrupt */ + +sig_t +signal(s, a) + int s; + sig_t a; +{ + struct sigaction sa, osa; + + sa.sa_handler = a; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (!sigismember(&_sigintr, s)) + sa.sa_flags |= SA_RESTART; + if (_sigaction(s, &sa, &osa) < 0) + return (SIG_ERR); + return (osa.sa_handler); +} diff --git a/src/lib/libc/gen/signbit.c b/src/lib/libc/gen/signbit.c new file mode 100644 index 0000000..23829c3 --- /dev/null +++ b/src/lib/libc/gen/signbit.c @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2003 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/gen/signbit.c,v 1.1 2003/02/11 21:56:20 mike Exp $ + */ + +#include + +#include "fpmath.h" + +int +__signbit(double d) +{ + union IEEEd2bits u; + + u.d = d; + return (u.bits.sign); +} diff --git a/src/lib/libc/gen/sigsetops.c b/src/lib/libc/gen/sigsetops.c new file mode 100644 index 0000000..e345f26 --- /dev/null +++ b/src/lib/libc/gen/sigsetops.c @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 1989, 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. + * + * @(#)sigsetops.c 8.1 (Berkeley) 6/4/93 + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)sigsetops.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/sigsetops.c,v 1.8 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include + +int +sigaddset(set, signo) + sigset_t *set; + int signo; +{ + + if (signo <= 0 || signo > _SIG_MAXSIG) { + errno = EINVAL; + return (-1); + } + set->__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo); + return (0); +} + +int +sigdelset(set, signo) + sigset_t *set; + int signo; +{ + + if (signo <= 0 || signo > _SIG_MAXSIG) { + errno = EINVAL; + return (-1); + } + set->__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo); + return (0); +} + +int +sigemptyset(set) + sigset_t *set; +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) + set->__bits[i] = 0; + return (0); +} + +int +sigfillset(set) + sigset_t *set; +{ + int i; + + for (i = 0; i < _SIG_WORDS; i++) + set->__bits[i] = ~0U; + return (0); +} + +int +sigismember(set, signo) + const sigset_t *set; + int signo; +{ + + if (signo <= 0 || signo > _SIG_MAXSIG) { + errno = EINVAL; + return (-1); + } + return ((set->__bits[_SIG_WORD(signo)] & _SIG_BIT(signo)) ? 1 : 0); +} diff --git a/src/lib/libc/gen/sleep.c b/src/lib/libc/gen/sleep.c new file mode 100644 index 0000000..bd48358 --- /dev/null +++ b/src/lib/libc/gen/sleep.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)sleep.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/sleep.c,v 1.31 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" + +unsigned int +__sleep(seconds) + unsigned int seconds; +{ + struct timespec time_to_sleep; + struct timespec time_remaining; + + /* + * Avoid overflow when `seconds' is huge. This assumes that + * the maximum value for a time_t is >= INT_MAX. + */ + if (seconds > INT_MAX) + return (seconds - INT_MAX + __sleep(INT_MAX)); + + time_to_sleep.tv_sec = seconds; + time_to_sleep.tv_nsec = 0; + if (_nanosleep(&time_to_sleep, &time_remaining) != -1) + return (0); + if (errno != EINTR) + return (seconds); /* best guess */ + return (time_remaining.tv_sec + + (time_remaining.tv_nsec != 0)); /* round up */ +} + +__weak_reference(__sleep, sleep); +__weak_reference(__sleep, _sleep); diff --git a/src/lib/libc/gen/srand48.c b/src/lib/libc/gen/srand48.c new file mode 100644 index 0000000..fd369a0 --- /dev/null +++ b/src/lib/libc/gen/srand48.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +extern unsigned short _rand48_seed[3]; +extern unsigned short _rand48_mult[3]; +extern unsigned short _rand48_add; + +void +srand48(long seed) +{ + _rand48_seed[0] = RAND48_SEED_0; + _rand48_seed[1] = (unsigned short) seed; + _rand48_seed[2] = (unsigned short) (seed >> 16); + _rand48_mult[0] = RAND48_MULT_0; + _rand48_mult[1] = RAND48_MULT_1; + _rand48_mult[2] = RAND48_MULT_2; + _rand48_add = RAND48_ADD; +} diff --git a/src/lib/libc/gen/statvfs.c b/src/lib/libc/gen/statvfs.c new file mode 100644 index 0000000..303950b --- /dev/null +++ b/src/lib/libc/gen/statvfs.c @@ -0,0 +1,160 @@ +/* + * Copyright 2002 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/statvfs.c,v 1.2 2002/09/06 11:23:40 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include + +#include +#include +#include +#include "un-namespace.h" + +static int sfs2svfs(const struct statfs *from, struct statvfs *to); + +int +fstatvfs(int fd, struct statvfs *result) +{ + struct statfs sfs; + int rv; + long pcval; + + rv = _fstatfs(fd, &sfs); + if (rv != 0) + return (rv); + + rv = sfs2svfs(&sfs, result); + if (rv != 0) + return (rv); + + /* + * Whether pathconf's -1 return means error or unlimited does not + * make any difference in this best-effort implementation. + */ + pcval = _fpathconf(fd, _PC_NAME_MAX); + if (pcval == -1) + result->f_namemax = ~0UL; + else + result->f_namemax = (unsigned long)pcval; + return (0); +} + +int +statvfs(const char * __restrict path, struct statvfs * __restrict result) +{ + struct statfs sfs; + int rv; + long pcval; + + rv = statfs(path, &sfs); + if (rv != 0) + return (rv); + + sfs2svfs(&sfs, result); + + /* + * Whether pathconf's -1 return means error or unlimited does not + * make any difference in this best-effort implementation. + */ + pcval = pathconf(path, _PC_NAME_MAX); + if (pcval == -1) + result->f_namemax = ~0UL; + else + result->f_namemax = (unsigned long)pcval; + return (0); +} + +static int +sfs2svfs(const struct statfs *from, struct statvfs *to) +{ + static const struct statvfs zvfs; + + *to = zvfs; + + if (from->f_flags & MNT_RDONLY) + to->f_flag |= ST_RDONLY; + if (from->f_flags & MNT_NOSUID) + to->f_flag |= ST_NOSUID; + + /* XXX should we clamp negative values? */ +#define COPY(field) \ + do { \ + to->field = from->field; \ + if (from->field != to->field) { \ + errno = EOVERFLOW; \ + return (-1); \ + } \ + } while(0) + + COPY(f_bavail); + COPY(f_bfree); + COPY(f_blocks); + COPY(f_ffree); + COPY(f_files); + to->f_bsize = from->f_iosize; + to->f_frsize = from->f_bsize; + to->f_favail = to->f_ffree; + return (0); +} + +#ifdef MAIN +#include +#include +#include + +int +main(int argc, char **argv) +{ + struct statvfs buf; + + if (statvfs(argv[1], &buf) < 0) + err(1, "statvfs"); + +#define SHOW(field) \ + printf(#field ": %ju\n", (uintmax_t)buf.field) + + SHOW(f_bavail); + SHOW(f_bfree); + SHOW(f_blocks); + SHOW(f_favail); + SHOW(f_ffree); + SHOW(f_files); + SHOW(f_bsize); + SHOW(f_frsize); + SHOW(f_namemax); + printf("f_flag: %lx\n", (unsigned long)buf.f_flag); + + return 0; +} + +#endif /* MAIN */ diff --git a/src/lib/libc/gen/stringlist.c b/src/lib/libc/gen/stringlist.c new file mode 100644 index 0000000..1d977e4 --- /dev/null +++ b/src/lib/libc/gen/stringlist.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 1994 Christos Zoulas + * 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 *rcsid = "$NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/stringlist.c,v 1.7 2003/01/19 01:16:01 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#define _SL_CHUNKSIZE 20 + +/* + * sl_init(): Initialize a string list + */ +StringList * +sl_init() +{ + StringList *sl; + + sl = malloc(sizeof(StringList)); + if (sl == NULL) + _err(1, "stringlist: %m"); + + sl->sl_cur = 0; + sl->sl_max = _SL_CHUNKSIZE; + sl->sl_str = malloc(sl->sl_max * sizeof(char *)); + if (sl->sl_str == NULL) + _err(1, "stringlist: %m"); + return sl; +} + + +/* + * sl_add(): Add an item to the string list + */ +int +sl_add(sl, name) + StringList *sl; + char *name; +{ + if (sl->sl_cur == sl->sl_max - 1) { + sl->sl_max += _SL_CHUNKSIZE; + sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *)); + if (sl->sl_str == NULL) + return (-1); + } + sl->sl_str[sl->sl_cur++] = name; + return (0); +} + + +/* + * sl_free(): Free a stringlist + */ +void +sl_free(sl, all) + StringList *sl; + int all; +{ + size_t i; + + if (sl == NULL) + return; + if (sl->sl_str) { + if (all) + for (i = 0; i < sl->sl_cur; i++) + free(sl->sl_str[i]); + free(sl->sl_str); + } + free(sl); +} + + +/* + * sl_find(): Find a name in the string list + */ +char * +sl_find(sl, name) + StringList *sl; + char *name; +{ + size_t i; + + for (i = 0; i < sl->sl_cur; i++) + if (strcmp(sl->sl_str[i], name) == 0) + return sl->sl_str[i]; + + return NULL; +} diff --git a/src/lib/libc/gen/strtofflags.c b/src/lib/libc/gen/strtofflags.c new file mode 100644 index 0000000..20a5c9f --- /dev/null +++ b/src/lib/libc/gen/strtofflags.c @@ -0,0 +1,158 @@ +/*- + * Copyright (c) 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[] = "@(#)stat_flags.c 8.1 (Berkeley) 5/31/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/strtofflags.c,v 1.22 2002/04/16 11:03:22 joe Exp $"); + +#include +#include + +#include +#include +#include + +static struct { + char *name; + u_long flag; + int invert; +} mapping[] = { + /* shorter names per flag first, all prefixed by "no" */ + { "nosappnd", SF_APPEND, 0 }, + { "nosappend", SF_APPEND, 0 }, + { "noarch", SF_ARCHIVED, 0 }, + { "noarchived", SF_ARCHIVED, 0 }, + { "noschg", SF_IMMUTABLE, 0 }, + { "noschange", SF_IMMUTABLE, 0 }, + { "nosimmutable", SF_IMMUTABLE, 0 }, + { "nosunlnk", SF_NOUNLINK, 0 }, + { "nosunlink", SF_NOUNLINK, 0 }, +#ifdef SF_SNAPSHOT + { "nosnapshot", SF_SNAPSHOT, 0 }, +#endif + { "nouappnd", UF_APPEND, 0 }, + { "nouappend", UF_APPEND, 0 }, + { "nouchg", UF_IMMUTABLE, 0 }, + { "nouchange", UF_IMMUTABLE, 0 }, + { "nouimmutable", UF_IMMUTABLE, 0 }, + { "nodump", UF_NODUMP, 1 }, + { "noopaque", UF_OPAQUE, 0 }, + { "nouunlnk", UF_NOUNLINK, 0 }, + { "nouunlink", UF_NOUNLINK, 0 } +}; +#define longestflaglen 12 +#define nmappings (sizeof(mapping) / sizeof(mapping[0])) + +/* + * fflagstostr -- + * Convert file flags to a comma-separated string. If no flags + * are set, return the empty string. + */ +char * +fflagstostr(flags) + u_long flags; +{ + char *string; + char *sp, *dp; + u_long setflags; + int i; + + if ((string = (char *)malloc(nmappings * (longestflaglen + 1))) == NULL) + return (NULL); + + setflags = flags; + dp = string; + for (i = 0; i < nmappings; i++) { + if (setflags & mapping[i].flag) { + if (dp > string) + *dp++ = ','; + for (sp = mapping[i].invert ? mapping[i].name : + mapping[i].name + 2; *sp; *dp++ = *sp++) ; + setflags &= ~mapping[i].flag; + } + } + *dp = '\0'; + return (string); +} + +/* + * strtofflags -- + * Take string of arguments and return file flags. Return 0 on + * success, 1 on failure. On failure, stringp is set to point + * to the offending token. + */ +int +strtofflags(stringp, setp, clrp) + char **stringp; + u_long *setp, *clrp; +{ + char *string, *p; + int i; + + if (setp) + *setp = 0; + if (clrp) + *clrp = 0; + string = *stringp; + while ((p = strsep(&string, "\t ,")) != NULL) { + *stringp = p; + if (*p == '\0') + continue; + for (i = 0; i < nmappings; i++) { + if (strcmp(p, mapping[i].name + 2) == 0) { + if (mapping[i].invert) { + if (clrp) + *clrp |= mapping[i].flag; + } else { + if (setp) + *setp |= mapping[i].flag; + } + break; + } else if (strcmp(p, mapping[i].name) == 0) { + if (mapping[i].invert) { + if (setp) + *setp |= mapping[i].flag; + } else { + if (clrp) + *clrp |= mapping[i].flag; + } + break; + } + } + if (i == nmappings) + return 1; + } + return 0; +} diff --git a/src/lib/libc/gen/swapcontext.c b/src/lib/libc/gen/swapcontext.c new file mode 100644 index 0000000..1725068 --- /dev/null +++ b/src/lib/libc/gen/swapcontext.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2001 Daniel M. Eischen + * 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. Neither the name of the author 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 AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/swapcontext.c,v 1.5 2002/09/20 08:13:21 mini Exp $"); + +#include +#include +#include + +#include +#include + +__weak_reference(__swapcontext, swapcontext); + +int +__swapcontext(ucontext_t *oucp, const ucontext_t *ucp) +{ + int ret; + + if ((oucp == NULL) || (ucp == NULL)) { + errno = EINVAL; + return (-1); + } + oucp->uc_flags &= ~UCF_SWAPPED; + ret = getcontext(oucp); + if ((ret == 0) && !(oucp->uc_flags & UCF_SWAPPED)) { + oucp->uc_flags |= UCF_SWAPPED; + ret = setcontext(ucp); + } + return (ret); +} diff --git a/src/lib/libc/gen/sysconf.c b/src/lib/libc/gen/sysconf.c new file mode 100644 index 0000000..309e163 --- /dev/null +++ b/src/lib/libc/gen/sysconf.c @@ -0,0 +1,582 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Sean Eric Fagan of Cygnus Support. + * + * 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[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/sysconf.c,v 1.20 2002/11/17 08:54:29 dougb Exp $"); + +#include +#include +#include +#include +#include + +#include +#include +#include +#include /* we just need the limits */ +#include +#include + +#include "../stdlib/atexit.h" +#include "../stdtime/tzfile.h" + +#define _PATH_ZONEINFO TZDIR /* from tzfile.h */ + +/* + * sysconf -- + * get configurable system variables. + * + * XXX + * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values + * not change during the lifetime of the calling process. This would seem + * to require that any change to system limits kill all running processes. + * A workaround might be to cache the values when they are first retrieved + * and then simply return the cached value on subsequent calls. This is + * less useful than returning up-to-date values, however. + */ +long +sysconf(name) + int name; +{ + struct rlimit rl; + size_t len; + int mib[2], sverrno, value; + long defaultresult; + const char *path; + + len = sizeof(value); + defaultresult = -1; + + switch (name) { + case _SC_ARG_MAX: + mib[0] = CTL_KERN; + mib[1] = KERN_ARGMAX; + break; + case _SC_CHILD_MAX: + if (getrlimit(RLIMIT_NPROC, &rl) != 0) + return (-1); + if (rl.rlim_cur == RLIM_INFINITY) + return (-1); + if (rl.rlim_cur > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + return ((long)rl.rlim_cur); + case _SC_CLK_TCK: + return (CLK_TCK); + case _SC_NGROUPS_MAX: + mib[0] = CTL_KERN; + mib[1] = KERN_NGROUPS; + break; + case _SC_OPEN_MAX: + case _SC_STREAM_MAX: /* assume fds run out before memory does */ + if (getrlimit(RLIMIT_NOFILE, &rl) != 0) + return (-1); + if (rl.rlim_cur == RLIM_INFINITY) + return (-1); + if (rl.rlim_cur > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + return ((long)rl.rlim_cur); + case _SC_JOB_CONTROL: + return (_POSIX_JOB_CONTROL); + case _SC_SAVED_IDS: + /* XXX - must be 1 */ + mib[0] = CTL_KERN; + mib[1] = KERN_SAVED_IDS; + goto yesno; + case _SC_VERSION: + mib[0] = CTL_KERN; + mib[1] = KERN_POSIX1; + break; + case _SC_BC_BASE_MAX: + return (BC_BASE_MAX); + case _SC_BC_DIM_MAX: + return (BC_DIM_MAX); + case _SC_BC_SCALE_MAX: + return (BC_SCALE_MAX); + case _SC_BC_STRING_MAX: + return (BC_STRING_MAX); + case _SC_COLL_WEIGHTS_MAX: + return (COLL_WEIGHTS_MAX); + case _SC_EXPR_NEST_MAX: + return (EXPR_NEST_MAX); + case _SC_LINE_MAX: + return (LINE_MAX); + case _SC_RE_DUP_MAX: + return (RE_DUP_MAX); + case _SC_2_VERSION: + /* + * This is something of a lie, but it would be silly at + * this point to try to deduce this from the contents + * of the filesystem. + */ + return (_POSIX2_VERSION); + case _SC_2_C_BIND: + return (_POSIX2_C_BIND); + case _SC_2_C_DEV: + return (_POSIX2_C_DEV); + case _SC_2_CHAR_TERM: + return (_POSIX2_CHAR_TERM); + case _SC_2_FORT_DEV: + return (_POSIX2_FORT_DEV); + case _SC_2_FORT_RUN: + return (_POSIX2_FORT_RUN); + case _SC_2_LOCALEDEF: + return (_POSIX2_LOCALEDEF); + case _SC_2_SW_DEV: + return (_POSIX2_SW_DEV); + case _SC_2_UPE: + return (_POSIX2_UPE); + case _SC_TZNAME_MAX: + path = _PATH_ZONEINFO; +do_NAME_MAX: + sverrno = errno; + errno = 0; + value = pathconf(path, _PC_NAME_MAX); + if (value == -1 && errno != 0) + return (-1); + errno = sverrno; + return (value); + + case _SC_ASYNCHRONOUS_IO: +#if _POSIX_ASYNCHRONOUS_IO == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO; + break; +#else + return (_POSIX_ASYNCHRONOUS_IO); +#endif + case _SC_MAPPED_FILES: + return (_POSIX_MAPPED_FILES); + case _SC_MEMLOCK: + return (_POSIX_MEMLOCK); + case _SC_MEMLOCK_RANGE: + return (_POSIX_MEMLOCK_RANGE); + case _SC_MEMORY_PROTECTION: + return (_POSIX_MEMORY_PROTECTION); + case _SC_MESSAGE_PASSING: +#if _POSIX_MESSAGE_PASSING == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_MESSAGE_PASSING; + goto yesno; +#else + return (_POSIX_MESSAGE_PASSING); +#endif + case _SC_PRIORITIZED_IO: +#if _POSIX_PRIORITIZED_IO == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_PRIORITIZED_IO; + goto yesno; +#else + return (_POSIX_PRIORITIZED_IO); +#endif + case _SC_PRIORITY_SCHEDULING: +#if _POSIX_PRIORITY_SCHEDULING == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING; + goto yesno; +#else + return (_POSIX_PRIORITY_SCHEDULING); +#endif + case _SC_REALTIME_SIGNALS: +#if _POSIX_REALTIME_SIGNALS == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_REALTIME_SIGNALS; + goto yesno; +#else + return (_POSIX_REALTIME_SIGNALS); +#endif + case _SC_SEMAPHORES: +#if _POSIX_SEMAPHORES == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_SEMAPHORES; + goto yesno; +#else + return (_POSIX_SEMAPHORES); +#endif + case _SC_FSYNC: + return (_POSIX_FSYNC); + + case _SC_SHARED_MEMORY_OBJECTS: + return (_POSIX_SHARED_MEMORY_OBJECTS); + case _SC_SYNCHRONIZED_IO: +#if _POSIX_SYNCHRONIZED_IO == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO; + goto yesno; +#else + return (_POSIX_SYNCHRONIZED_IO); +#endif + case _SC_TIMERS: +#if _POSIX_TIMERS == 0 + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_TIMERS; + goto yesno; +#else + return (_POSIX_TIMERS); +#endif + case _SC_AIO_LISTIO_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX; + break; + case _SC_AIO_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_AIO_MAX; + break; + case _SC_AIO_PRIO_DELTA_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX; + break; + case _SC_DELAYTIMER_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_DELAYTIMER_MAX; + goto yesno; + case _SC_MQ_OPEN_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_MQ_OPEN_MAX; + goto yesno; + case _SC_PAGESIZE: + defaultresult = getpagesize(); + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_PAGESIZE; + goto yesno; + case _SC_RTSIG_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_RTSIG_MAX; + goto yesno; + case _SC_SEM_NSEMS_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX; + goto yesno; + case _SC_SEM_VALUE_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_SEM_VALUE_MAX; + goto yesno; + case _SC_SIGQUEUE_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_SIGQUEUE_MAX; + goto yesno; + case _SC_TIMER_MAX: + mib[0] = CTL_P1003_1B; + mib[1] = CTL_P1003_1B_TIMER_MAX; + +yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) + return (-1); + if (value == 0) + return (defaultresult); + return (value); + + case _SC_2_PBS: + case _SC_2_PBS_ACCOUNTING: + case _SC_2_PBS_CHECKPOINT: + case _SC_2_PBS_LOCATE: + case _SC_2_PBS_MESSAGE: + case _SC_2_PBS_TRACK: +#if _POSIX2_PBS == 0 +#error "don't know how to determine _SC_2_PBS" + /* + * This probably requires digging through the filesystem + * to see if the appropriate package has been installed. + * Since we don't currently support this option at all, + * it's not worth the effort to write the code now. + * Figuring out which of the sub-options are supported + * would be even more difficult, so it's probably easier + * to always say ``no''. + */ +#else + return (_POSIX2_PBS); +#endif + case _SC_ADVISORY_INFO: +#if _POSIX_ADVISORY_INFO == 0 +#error "_POSIX_ADVISORY_INFO" +#else + return (_POSIX_ADVISORY_INFO); +#endif + case _SC_BARRIERS: +#if _POSIX_BARRIERS == 0 +#error "_POSIX_BARRIERS" +#else + return (_POSIX_BARRIERS); +#endif + case _SC_CLOCK_SELECTION: +#if _POSIX_CLOCK_SELECTION == 0 +#error "_POSIX_CLOCK_SELECTION" +#else + return (_POSIX_CLOCK_SELECTION); +#endif + case _SC_CPUTIME: +#if _POSIX_CPUTIME == 0 +#error "_POSIX_CPUTIME" +#else + return (_POSIX_CPUTIME); +#endif +#ifdef notdef + case _SC_FILE_LOCKING: + /* + * XXX - The standard doesn't tell us how to define + * _POSIX_FILE_LOCKING, so we can't answer this one. + */ +#endif +#if _POSIX_THREAD_SAFE_FUNCTIONS > -1 + case _SC_GETGR_R_SIZE_MAX: + case _SC_GETPW_R_SIZE_MAX: +#error "somebody needs to implement this" +#endif + case _SC_HOST_NAME_MAX: + return (MAXHOSTNAMELEN - 1); /* does not include \0 */ + case _SC_LOGIN_NAME_MAX: + return (MAXLOGNAME); + case _SC_MONOTONIC_CLOCK: +#if _POSIX_MONOTONIC_CLOCK == 0 +#error "_POSIX_MONOTONIC_CLOCK" +#else + return (_POSIX_MONOTONIC_CLOCK); +#endif +#if _POSIX_MESSAGE_PASSING > -1 + case _SC_MQ_PRIO_MAX: + return (MQ_PRIO_MAX); +#endif + case _SC_READER_WRITER_LOCKS: + return (_POSIX_READER_WRITER_LOCKS); + case _SC_REGEXP: + return (_POSIX_REGEXP); + case _SC_SHELL: + return (_POSIX_SHELL); + case _SC_SPAWN: + return (_POSIX_SPAWN); + case _SC_SPIN_LOCKS: + return (_POSIX_SPIN_LOCKS); + case _SC_SPORADIC_SERVER: +#if _POSIX_SPORADIC_SERVER == 0 +#error "_POSIX_SPORADIC_SERVER" +#else + return (_POSIX_SPORADIC_SERVER); +#endif + case _SC_THREAD_ATTR_STACKADDR: + return (_POSIX_THREAD_ATTR_STACKADDR); + case _SC_THREAD_ATTR_STACKSIZE: + return (_POSIX_THREAD_ATTR_STACKSIZE); + case _SC_THREAD_CPUTIME: + return (_POSIX_THREAD_CPUTIME); + case _SC_THREAD_DESTRUCTOR_ITERATIONS: + return (PTHREAD_DESTRUCTOR_ITERATIONS); + case _SC_THREAD_KEYS_MAX: + return (PTHREAD_KEYS_MAX); + case _SC_THREAD_PRIO_INHERIT: + return (_POSIX_THREAD_PRIO_INHERIT); + case _SC_THREAD_PRIO_PROTECT: + return (_POSIX_THREAD_PRIO_PROTECT); + case _SC_THREAD_PRIORITY_SCHEDULING: + return (_POSIX_THREAD_PRIORITY_SCHEDULING); + case _SC_THREAD_PROCESS_SHARED: + return (_POSIX_THREAD_PROCESS_SHARED); + case _SC_THREAD_SAFE_FUNCTIONS: + return (_POSIX_THREAD_SAFE_FUNCTIONS); + case _SC_THREAD_STACK_MIN: + return (PTHREAD_STACK_MIN); + case _SC_THREAD_THREADS_MAX: + return (PTHREAD_THREADS_MAX); /* XXX wrong type! */ + case _SC_TIMEOUTS: + return (_POSIX_TIMEOUTS); + case _SC_THREADS: + return (_POSIX_THREADS); + case _SC_TRACE: +#if _POSIX_TRACE == 0 +#error "_POSIX_TRACE" + /* While you're implementing this, also do the ones below. */ +#else + return (_POSIX_TRACE); +#endif +#if _POSIX_TRACE > -1 + case _SC_TRACE_EVENT_FILTER: + return (_POSIX_TRACE_EVENT_FILTER); + case _SC_TRACE_INHERIT: + return (_POSIX_TRACE_INHERIT); + case _SC_TRACE_LOG: + return (_POSIX_TRACE_LOG); +#endif + case _SC_TTY_NAME_MAX: + path = _PATH_DEV; + goto do_NAME_MAX; + case _SC_TYPED_MEMORY_OBJECTS: +#if _POSIX_TYPED_MEMORY_OBJECTS == 0 +#error "_POSIX_TYPED_MEMORY_OBJECTS" +#else + return (_POSIX_TYPED_MEMORY_OBJECTS); +#endif + case _SC_V6_ILP32_OFF32: +#if _V6_ILP32_OFF32 == 0 + if (sizeof(int) * CHAR_BIT == 32 && + sizeof(int) == sizeof(long) && + sizeof(long) == sizeof(void *) && + sizeof(void *) == sizeof(off_t)) + return 1; + else + return -1; +#else + return (_V6_ILP32_OFF32); +#endif + case _SC_V6_ILP32_OFFBIG: +#if _V6_ILP32_OFFBIG == 0 + if (sizeof(int) * CHAR_BIT == 32 && + sizeof(int) == sizeof(long) && + sizeof(long) == sizeof(void *) && + sizeof(off_t) * CHAR_BIT >= 64) + return 1; + else + return -1; +#else + return (_V6_ILP32_OFFBIG); +#endif + case _SC_V6_LP64_OFF64: +#if _V6_LP64_OFF64 == 0 + if (sizeof(int) * CHAR_BIT == 32 && + sizeof(long) * CHAR_BIT == 64 && + sizeof(long) == sizeof(void *) && + sizeof(void *) == sizeof(off_t)) + return 1; + else + return -1; +#else + return (_V6_LP64_OFF64); +#endif + case _SC_V6_LPBIG_OFFBIG: +#if _V6_LPBIG_OFFBIG == 0 + if (sizeof(int) * CHAR_BIT >= 32 && + sizeof(long) * CHAR_BIT >= 64 && + sizeof(void *) * CHAR_BIT >= 64 && + sizeof(off_t) * CHAR_BIT >= 64) + return 1; + else + return -1; +#else + return (_V6_LPBIG_OFFBIG); +#endif + case _SC_ATEXIT_MAX: + return (ATEXIT_SIZE); + case _SC_IOV_MAX: + mib[0] = CTL_KERN; + mib[1] = KERN_IOV_MAX; + break; + case _SC_XOPEN_CRYPT: + return (_XOPEN_CRYPT); + case _SC_XOPEN_ENH_I18N: + return (_XOPEN_ENH_I18N); + case _SC_XOPEN_LEGACY: + return (_XOPEN_LEGACY); + case _SC_XOPEN_REALTIME: +#if _XOPEN_REALTIME == 0 + sverrno = errno; + value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 && + sysconf(_SC_MEMLOCK) > 0 && + sysconf(_SC_MEMLOCK_RANGE) > 0 && + sysconf(_SC_MESSAGE_PASSING) > 0 && + sysconf(_SC_PRIORITY_SCHEDULING) > 0 && + sysconf(_SC_REALTIME_SIGNALS) > 0 && + sysconf(_SC_SEMAPHORES) > 0 && + sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 && + sysconf(_SC_SYNCHRONIZED_IO) > 0 && + sysconf(_SC_TIMERS) > 0; + errno = sverrno; + if (value) + return (200112L); + else + return (-1); +#else + return (_XOPEN_REALTIME); +#endif + case _SC_XOPEN_REALTIME_THREADS: +#if _XOPEN_REALTIME_THREADS == 0 +#error "_XOPEN_REALTIME_THREADS" +#else + return (_XOPEN_REALTIME_THREADS); +#endif + case _SC_XOPEN_SHM: + sverrno = errno; + if (sysctlbyname("kern.ipc.shmmin", &value, &len, NULL, + 0) == -1) { + errno = sverrno; + return (-1); + } + errno = sverrno; + return (1); + case _SC_XOPEN_STREAMS: + return (_XOPEN_STREAMS); + case _SC_XOPEN_UNIX: + return (_XOPEN_UNIX); +#ifdef _XOPEN_VERSION + case _SC_XOPEN_VERSION: + return (_XOPEN_VERSION); +#endif +#ifdef _XOPEN_XCU_VERSION + case _SC_XOPEN_XCU_VERSION: + return (_XOPEN_XCU_VERSION); +#endif + case _SC_SYMLOOP_MAX: + return (MAXSYMLINKS); + case _SC_RAW_SOCKETS: + return (_POSIX_RAW_SOCKETS); + case _SC_IPV6: +#if _POSIX_IPV6 == 0 + sverrno = errno; + value = socket(PF_INET6, SOCK_DGRAM, 0); + errno = sverrno; + if (value >= 0) { + close(value); + return (200112L); + } else + return (0); +#else + return (_POSIX_IPV6); +#endif + + case _SC_NPROCESSORS_CONF: + case _SC_NPROCESSORS_ONLN: + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + break; + + default: + errno = EINVAL; + return (-1); + } + return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value); +} diff --git a/src/lib/libc/gen/sysctl.c b/src/lib/libc/gen/sysctl.c new file mode 100644 index 0000000..b6c89a0 --- /dev/null +++ b/src/lib/libc/gen/sysctl.c @@ -0,0 +1,187 @@ +/*- + * Copyright (c) 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[] = "@(#)sysctl.c 8.2 (Berkeley) 1/4/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/sysctl.c,v 1.5 2003/02/16 17:29:09 nectar Exp $"); + +#include +#include + +#include +#include +#include +#include +#include +#include + +extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, + void *newp, size_t newlen); + +int +sysctl(name, namelen, oldp, oldlenp, newp, newlen) + int *name; + u_int namelen; + void *oldp, *newp; + size_t *oldlenp, newlen; +{ + if (name[0] != CTL_USER) + return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); + + if (newp != NULL) { + errno = EPERM; + return (-1); + } + if (namelen != 2) { + errno = EINVAL; + return (-1); + } + + switch (name[1]) { + case USER_CS_PATH: + if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) { + errno = ENOMEM; + return -1; + } + *oldlenp = sizeof(_PATH_STDPATH); + if (oldp != NULL) + memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); + return (0); + } + + if (oldp && *oldlenp < sizeof(int)) { + errno = ENOMEM; + return (-1); + } + *oldlenp = sizeof(int); + if (oldp == NULL) + return (0); + + switch (name[1]) { + case USER_BC_BASE_MAX: + *(int *)oldp = BC_BASE_MAX; + return (0); + case USER_BC_DIM_MAX: + *(int *)oldp = BC_DIM_MAX; + return (0); + case USER_BC_SCALE_MAX: + *(int *)oldp = BC_SCALE_MAX; + return (0); + case USER_BC_STRING_MAX: + *(int *)oldp = BC_STRING_MAX; + return (0); + case USER_COLL_WEIGHTS_MAX: + *(int *)oldp = COLL_WEIGHTS_MAX; + return (0); + case USER_EXPR_NEST_MAX: + *(int *)oldp = EXPR_NEST_MAX; + return (0); + case USER_LINE_MAX: + *(int *)oldp = LINE_MAX; + return (0); + case USER_RE_DUP_MAX: + *(int *)oldp = RE_DUP_MAX; + return (0); + case USER_POSIX2_VERSION: + *(int *)oldp = _POSIX2_VERSION; + return (0); + case USER_POSIX2_C_BIND: +#ifdef POSIX2_C_BIND + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_C_DEV: +#ifdef POSIX2_C_DEV + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_CHAR_TERM: +#ifdef POSIX2_CHAR_TERM + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_FORT_DEV: +#ifdef POSIX2_FORT_DEV + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_FORT_RUN: +#ifdef POSIX2_FORT_RUN + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_LOCALEDEF: +#ifdef POSIX2_LOCALEDEF + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_SW_DEV: +#ifdef POSIX2_SW_DEV + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_POSIX2_UPE: +#ifdef POSIX2_UPE + *(int *)oldp = 1; +#else + *(int *)oldp = 0; +#endif + return (0); + case USER_STREAM_MAX: + *(int *)oldp = FOPEN_MAX; + return (0); + case USER_TZNAME_MAX: + *(int *)oldp = NAME_MAX; + return (0); + default: + errno = EINVAL; + return (-1); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/gen/sysctlbyname.c b/src/lib/libc/gen/sysctlbyname.c new file mode 100644 index 0000000..e949a5c --- /dev/null +++ b/src/lib/libc/gen/sysctlbyname.c @@ -0,0 +1,39 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/sysctlbyname.c,v 1.5 2002/02/01 00:57:29 obrien Exp $"); + +#include +#include +#include + +int +sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, + size_t newlen) +{ + int name2oid_oid[2]; + int real_oid[CTL_MAXNAME+2]; + int error; + size_t oidlen; + + name2oid_oid[0] = 0; /* This is magic & undocumented! */ + name2oid_oid[1] = 3; + + oidlen = sizeof(real_oid); + error = sysctl(name2oid_oid, 2, real_oid, &oidlen, (void *)name, + strlen(name)); + if (error < 0) + return error; + oidlen /= sizeof (int); + error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); + return (error); +} + diff --git a/src/lib/libc/gen/sysctlnametomib.c b/src/lib/libc/gen/sysctlnametomib.c new file mode 100644 index 0000000..1a932ec --- /dev/null +++ b/src/lib/libc/gen/sysctlnametomib.c @@ -0,0 +1,55 @@ +/* + * Copyright 2001 The FreeBSD Project. 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. + * + * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``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 FREEBSD PROJECT 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/sysctlnametomib.c,v 1.4 2003/01/04 00:11:11 tjr Exp $"); + +#include +#include +#include + +/* + * This function uses a presently undocumented interface to the kernel + * to walk the tree and get the type so it can print the value. + * This interface is under work and consideration, and should probably + * be killed with a big axe by the first person who can find the time. + * (be aware though, that the proper interface isn't as obvious as it + * may seem, there are various conflicting requirements. + */ +int +sysctlnametomib(const char *name, int *mibp, size_t *sizep) +{ + int oid[2]; + int error; + + oid[0] = 0; + oid[1] = 3; + + *sizep *= sizeof (int); + error = sysctl(oid, 2, mibp, sizep, (void *)name, strlen(name)); + *sizep /= sizeof (int); + return (error); +} diff --git a/src/lib/libc/gen/syslog.c b/src/lib/libc/gen/syslog.c new file mode 100644 index 0000000..0d66939 --- /dev/null +++ b/src/lib/libc/gen/syslog.c @@ -0,0 +1,367 @@ +/* + * Copyright (c) 1983, 1988, 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[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/syslog.c,v 1.30 2004/05/10 17:12:52 dds Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "un-namespace.h" + +#include "libc_private.h" + +static int LogFile = -1; /* fd for log */ +static int connected; /* have done connect */ +static int opened; /* have done openlog() */ +static int LogStat = 0; /* status bits, set by openlog() */ +static const char *LogTag = NULL; /* string to tag the entry with */ +static int LogFacility = LOG_USER; /* default facility code */ +static int LogMask = 0xff; /* mask of priorities to be logged */ + +static void disconnectlog(void); /* disconnect from syslogd */ +static void connectlog(void); /* (re)connect to syslogd */ + +/* + * Format of the magic cookie passed through the stdio hook + */ +struct bufcookie { + char *base; /* start of buffer */ + int left; +}; + +/* + * stdio write hook for writing to a static string buffer + * XXX: Maybe one day, dynamically allocate it so that the line length + * is `unlimited'. + */ +static +int writehook(cookie, buf, len) + void *cookie; /* really [struct bufcookie *] */ + char *buf; /* characters to copy */ + int len; /* length to copy */ +{ + struct bufcookie *h; /* private `handle' */ + + h = (struct bufcookie *)cookie; + if (len > h->left) { + /* clip in case of wraparound */ + len = h->left; + } + if (len > 0) { + (void)memcpy(h->base, buf, len); /* `write' it. */ + h->base += len; + h->left -= len; + } + return 0; +} + +/* + * syslog, vsyslog -- + * print message on log file; output is intended for syslogd(8). + */ +void +syslog(int pri, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog(pri, fmt, ap); + va_end(ap); +} + +void +vsyslog(pri, fmt, ap) + int pri; + const char *fmt; + va_list ap; +{ + int cnt; + char ch, *p; + time_t now; + int fd, saved_errno; + char *stdp, tbuf[2048], fmt_cpy[1024], timbuf[26]; + FILE *fp, *fmt_fp; + struct bufcookie tbuf_cookie; + struct bufcookie fmt_cookie; + +#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID + /* Check for invalid bits. */ + if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) { + syslog(INTERNALLOG, + "syslog: unknown facility/priority: %x", pri); + pri &= LOG_PRIMASK|LOG_FACMASK; + } + + /* Check priority against setlogmask values. */ + if (!(LOG_MASK(LOG_PRI(pri)) & LogMask)) + return; + + saved_errno = errno; + + /* Set default facility if none specified. */ + if ((pri & LOG_FACMASK) == 0) + pri |= LogFacility; + + /* Create the primary stdio hook */ + tbuf_cookie.base = tbuf; + tbuf_cookie.left = sizeof(tbuf); + fp = fwopen(&tbuf_cookie, writehook); + if (fp == NULL) + return; + + /* Build the message. */ + (void)time(&now); + (void)fprintf(fp, "<%d>", pri); + (void)fprintf(fp, "%.15s ", ctime_r(&now, timbuf) + 4); + if (LogStat & LOG_PERROR) { + /* Transfer to string buffer */ + (void)fflush(fp); + stdp = tbuf + (sizeof(tbuf) - tbuf_cookie.left); + } + if (LogTag == NULL) + LogTag = _getprogname(); + if (LogTag != NULL) + (void)fprintf(fp, "%s", LogTag); + if (LogStat & LOG_PID) + (void)fprintf(fp, "[%d]", getpid()); + if (LogTag != NULL) { + (void)fprintf(fp, ": "); + } + + /* Check to see if we can skip expanding the %m */ + if (strstr(fmt, "%m")) { + + /* Create the second stdio hook */ + fmt_cookie.base = fmt_cpy; + fmt_cookie.left = sizeof(fmt_cpy) - 1; + fmt_fp = fwopen(&fmt_cookie, writehook); + if (fmt_fp == NULL) { + fclose(fp); + return; + } + + /* + * Substitute error message for %m. Be careful not to + * molest an escaped percent "%%m". We want to pass it + * on untouched as the format is later parsed by vfprintf. + */ + for ( ; (ch = *fmt); ++fmt) { + if (ch == '%' && fmt[1] == 'm') { + ++fmt; + fputs(strerror(saved_errno), fmt_fp); + } else if (ch == '%' && fmt[1] == '%') { + ++fmt; + fputc(ch, fmt_fp); + fputc(ch, fmt_fp); + } else { + fputc(ch, fmt_fp); + } + } + + /* Null terminate if room */ + fputc(0, fmt_fp); + fclose(fmt_fp); + + /* Guarantee null termination */ + fmt_cpy[sizeof(fmt_cpy) - 1] = '\0'; + + fmt = fmt_cpy; + } + + (void)vfprintf(fp, fmt, ap); + (void)fclose(fp); + + cnt = sizeof(tbuf) - tbuf_cookie.left; + + /* Remove a trailing newline */ + if (tbuf[cnt - 1] == '\n') + cnt--; + + /* Output to stderr if requested. */ + if (LogStat & LOG_PERROR) { + struct iovec iov[2]; + struct iovec *v = iov; + + v->iov_base = stdp; + v->iov_len = cnt - (stdp - tbuf); + ++v; + v->iov_base = "\n"; + v->iov_len = 1; + (void)_writev(STDERR_FILENO, iov, 2); + } + + /* Get connected, output the message to the local logger. */ + if (!opened) + openlog(LogTag, LogStat | LOG_NDELAY, 0); + connectlog(); + if (send(LogFile, tbuf, cnt, 0) >= 0) + return; + + /* + * If the send() failed, the odds are syslogd was restarted. + * Make one (only) attempt to reconnect to /dev/log. + */ + disconnectlog(); + connectlog(); + if (send(LogFile, tbuf, cnt, 0) >= 0) + return; + + /* + * Output the message to the console; try not to block + * as a blocking console should not stop other processes. + * Make sure the error reported is the one from the syslogd failure. + */ + if (LogStat & LOG_CONS && + (fd = _open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) { + struct iovec iov[2]; + struct iovec *v = iov; + + p = strchr(tbuf, '>') + 1; + v->iov_base = p; + v->iov_len = cnt - (p - tbuf); + ++v; + v->iov_base = "\r\n"; + v->iov_len = 2; + (void)_writev(fd, iov, 2); + (void)_close(fd); + } +} +static void +disconnectlog() +{ + /* + * If the user closed the FD and opened another in the same slot, + * that's their problem. They should close it before calling on + * system services. + */ + if (LogFile != -1) { + _close(LogFile); + LogFile = -1; + } + connected = 0; /* retry connect */ +} + +static void +connectlog() +{ + struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ + + if (LogFile == -1) { + if ((LogFile = _socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + return; + (void)_fcntl(LogFile, F_SETFD, 1); + } + if (LogFile != -1 && !connected) { + SyslogAddr.sun_len = sizeof(SyslogAddr); + SyslogAddr.sun_family = AF_UNIX; + (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, + sizeof SyslogAddr.sun_path); + connected = _connect(LogFile, (struct sockaddr *)&SyslogAddr, + sizeof(SyslogAddr)) != -1; + + if (!connected) { + /* + * Try the old "/dev/log" path, for backward + * compatibility. + */ + (void)strncpy(SyslogAddr.sun_path, _PATH_OLDLOG, + sizeof SyslogAddr.sun_path); + connected = _connect(LogFile, + (struct sockaddr *)&SyslogAddr, + sizeof(SyslogAddr)) != -1; + } + + if (!connected) { + (void)_close(LogFile); + LogFile = -1; + } + } +} + +void +openlog(ident, logstat, logfac) + const char *ident; + int logstat, logfac; +{ + if (ident != NULL) + LogTag = ident; + LogStat = logstat; + if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) + LogFacility = logfac; + + if (LogStat & LOG_NDELAY) /* open immediately */ + connectlog(); + + opened = 1; /* ident and facility has been set */ +} + +void +closelog() +{ + (void)_close(LogFile); + LogFile = -1; + LogTag = NULL; + connected = 0; +} + +/* setlogmask -- set the log mask level */ +int +setlogmask(pmask) + int pmask; +{ + int omask; + + omask = LogMask; + if (pmask != 0) + LogMask = pmask; + return (omask); +} diff --git a/src/lib/libc/gen/telldir.c b/src/lib/libc/gen/telldir.c new file mode 100644 index 0000000..f321910 --- /dev/null +++ b/src/lib/libc/gen/telldir.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/telldir.c,v 1.8 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" +#include "telldir.h" + +/* + * The option SINGLEUSE may be defined to say that a telldir + * cookie may be used only once before it is freed. This option + * is used to avoid having memory usage grow without bound. + */ +#define SINGLEUSE + +/* + * return a pointer into a directory + */ +long +telldir(dirp) + DIR *dirp; +{ + struct ddloc *lp; + + if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) + return (-1); + if (__isthreaded) + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + lp->loc_index = dirp->dd_td->td_loccnt++; + lp->loc_seek = dirp->dd_seek; + lp->loc_loc = dirp->dd_loc; + LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe); + if (__isthreaded) + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + return (lp->loc_index); +} + +/* + * seek to an entry in a directory. + * Only values returned by "telldir" should be passed to seekdir. + */ +void +_seekdir(dirp, loc) + DIR *dirp; + long loc; +{ + struct ddloc *lp; + struct dirent *dp; + + LIST_FOREACH(lp, &dirp->dd_td->td_locq, loc_lqe) { + if (lp->loc_index == loc) + break; + } + if (lp == NULL) + return; + if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek) + goto found; + (void) lseek(dirp->dd_fd, (off_t)lp->loc_seek, SEEK_SET); + dirp->dd_seek = lp->loc_seek; + dirp->dd_loc = 0; + while (dirp->dd_loc < lp->loc_loc) { + dp = _readdir_unlocked(dirp); + if (dp == NULL) + break; + } +found: +#ifdef SINGLEUSE + LIST_REMOVE(lp, loc_lqe); + free((caddr_t)lp); +#endif +} + +/* + * Reclaim memory for telldir cookies which weren't used. + */ +void +_reclaim_telldir(dirp) + DIR *dirp; +{ + struct ddloc *lp; + struct ddloc *templp; + + lp = LIST_FIRST(&dirp->dd_td->td_locq); + while (lp != NULL) { + templp = lp; + lp = LIST_NEXT(lp, loc_lqe); + free(templp); + } + LIST_INIT(&dirp->dd_td->td_locq); +} diff --git a/src/lib/libc/gen/telldir.h b/src/lib/libc/gen/telldir.h new file mode 100644 index 0000000..82cf9c1 --- /dev/null +++ b/src/lib/libc/gen/telldir.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Copyright (c) 2000 + * Daniel Eischen. 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. 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. + * + * $FreeBSD: src/lib/libc/gen/telldir.h,v 1.2 2001/01/24 12:59:24 deischen Exp $ + */ + +#ifndef _TELLDIR_H_ +#define _TELLDIR_H_ + +#include + +/* + * One of these structures is malloced to describe the current directory + * position each time telldir is called. It records the current magic + * cookie returned by getdirentries and the offset within the buffer + * associated with that return value. + */ +struct ddloc { + LIST_ENTRY(ddloc) loc_lqe; /* entry in list */ + long loc_index; /* key associated with structure */ + long loc_seek; /* magic cookie returned by getdirentries */ + long loc_loc; /* offset of entry in buffer */ +}; + +/* + * One of these structures is malloced for each DIR to record telldir + * positions. + */ +struct _telldir { + LIST_HEAD(, ddloc) td_locq; /* list of locations */ + long td_loccnt; /* index of entry for sequential readdir's */ +}; + +struct dirent *_readdir_unlocked(DIR *); +void _reclaim_telldir(DIR *); +void _seekdir(DIR *, long); + +#endif diff --git a/src/lib/libc/gen/termios.c b/src/lib/libc/gen/termios.c new file mode 100644 index 0000000..65f8141 --- /dev/null +++ b/src/lib/libc/gen/termios.c @@ -0,0 +1,245 @@ +/*- + * Copyright (c) 1989, 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[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/termios.c,v 1.13 2002/05/28 16:59:39 alfred Exp $"); + +#include "namespace.h" +#include +#include +#include +#include + +#include +#include +#include +#include "un-namespace.h" + +int +tcgetattr(fd, t) + int fd; + struct termios *t; +{ + + return (_ioctl(fd, TIOCGETA, t)); +} + +int +tcsetattr(fd, opt, t) + int fd, opt; + const struct termios *t; +{ + struct termios localterm; + + if (opt & TCSASOFT) { + localterm = *t; + localterm.c_cflag |= CIGNORE; + t = &localterm; + } + switch (opt & ~TCSASOFT) { + case TCSANOW: + return (_ioctl(fd, TIOCSETA, t)); + case TCSADRAIN: + return (_ioctl(fd, TIOCSETAW, t)); + case TCSAFLUSH: + return (_ioctl(fd, TIOCSETAF, t)); + default: + errno = EINVAL; + return (-1); + } +} + +int +tcsetpgrp(int fd, pid_t pgrp) +{ + int s; + + s = pgrp; + return (_ioctl(fd, TIOCSPGRP, &s)); +} + +pid_t +tcgetpgrp(fd) + int fd; +{ + int s; + + if (_ioctl(fd, TIOCGPGRP, &s) < 0) + return ((pid_t)-1); + + return ((pid_t)s); +} + +speed_t +cfgetospeed(t) + const struct termios *t; +{ + + return (t->c_ospeed); +} + +speed_t +cfgetispeed(t) + const struct termios *t; +{ + + return (t->c_ispeed); +} + +int +cfsetospeed(t, speed) + struct termios *t; + speed_t speed; +{ + + t->c_ospeed = speed; + return (0); +} + +int +cfsetispeed(t, speed) + struct termios *t; + speed_t speed; +{ + + t->c_ispeed = speed; + return (0); +} + +int +cfsetspeed(t, speed) + struct termios *t; + speed_t speed; +{ + + t->c_ispeed = t->c_ospeed = speed; + return (0); +} + +/* + * Make a pre-existing termios structure into "raw" mode: character-at-a-time + * mode with no characters interpreted, 8-bit data path. + */ +void +cfmakeraw(t) + struct termios *t; +{ + + t->c_iflag &= ~(IMAXBEL|IXOFF|INPCK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IGNPAR); + t->c_iflag |= IGNBRK; + t->c_oflag &= ~OPOST; + t->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|NOFLSH|TOSTOP|PENDIN); + t->c_cflag &= ~(CSIZE|PARENB); + t->c_cflag |= CS8|CREAD; + t->c_cc[VMIN] = 1; + t->c_cc[VTIME] = 0; +} + +int +tcsendbreak(fd, len) + int fd, len; +{ + struct timeval sleepytime; + + sleepytime.tv_sec = 0; + sleepytime.tv_usec = 400000; + if (_ioctl(fd, TIOCSBRK, 0) == -1) + return (-1); + (void)_select(0, 0, 0, 0, &sleepytime); + if (_ioctl(fd, TIOCCBRK, 0) == -1) + return (-1); + return (0); +} + +int +__tcdrain(fd) + int fd; +{ + return (_ioctl(fd, TIOCDRAIN, 0)); +} + +__weak_reference(__tcdrain, tcdrain); +__weak_reference(__tcdrain, _tcdrain); + +int +tcflush(fd, which) + int fd, which; +{ + int com; + + switch (which) { + case TCIFLUSH: + com = FREAD; + break; + case TCOFLUSH: + com = FWRITE; + break; + case TCIOFLUSH: + com = FREAD | FWRITE; + break; + default: + errno = EINVAL; + return (-1); + } + return (_ioctl(fd, TIOCFLUSH, &com)); +} + +int +tcflow(fd, action) + int fd, action; +{ + struct termios term; + u_char c; + + switch (action) { + case TCOOFF: + return (_ioctl(fd, TIOCSTOP, 0)); + case TCOON: + return (_ioctl(fd, TIOCSTART, 0)); + case TCION: + case TCIOFF: + if (tcgetattr(fd, &term) == -1) + return (-1); + c = term.c_cc[action == TCIOFF ? VSTOP : VSTART]; + if (c != _POSIX_VDISABLE && _write(fd, &c, sizeof(c)) == -1) + return (-1); + return (0); + default: + errno = EINVAL; + return (-1); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/gen/time.c b/src/lib/libc/gen/time.c new file mode 100644 index 0000000..5bf0ce0 --- /dev/null +++ b/src/lib/libc/gen/time.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)time.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/time.c,v 1.4 2003/07/19 02:53:46 wollman Exp $"); + +#include +#include + +time_t +time(t) + time_t *t; +{ + struct timeval tt; + time_t retval; + + if (gettimeofday(&tt, (struct timezone *)0) < 0) + retval = -1; + else + retval = tt.tv_sec; + if (t != NULL) + *t = retval; + return (retval); +} diff --git a/src/lib/libc/gen/times.c b/src/lib/libc/gen/times.c new file mode 100644 index 0000000..5bdc607 --- /dev/null +++ b/src/lib/libc/gen/times.c @@ -0,0 +1,69 @@ +/*- + * 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[] = "@(#)times.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/times.c,v 1.2 2002/02/01 01:08:48 obrien Exp $"); + +#include +#include +#include +#include + +/* + * Convert usec to clock ticks; could do (usec * CLK_TCK) / 1000000, + * but this would overflow if we switch to nanosec. + */ +#define CONVTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK)) + +clock_t +times(tp) + struct tms *tp; +{ + struct rusage ru; + struct timeval t; + + if (getrusage(RUSAGE_SELF, &ru) < 0) + return ((clock_t)-1); + tp->tms_utime = CONVTCK(ru.ru_utime); + tp->tms_stime = CONVTCK(ru.ru_stime); + if (getrusage(RUSAGE_CHILDREN, &ru) < 0) + return ((clock_t)-1); + tp->tms_cutime = CONVTCK(ru.ru_utime); + tp->tms_cstime = CONVTCK(ru.ru_stime); + if (gettimeofday(&t, (struct timezone *)0)) + return ((clock_t)-1); + return ((clock_t)(CONVTCK(t))); +} diff --git a/src/lib/libc/gen/timezone.c b/src/lib/libc/gen/timezone.c new file mode 100644 index 0000000..8d8139a --- /dev/null +++ b/src/lib/libc/gen/timezone.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 1987, 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[] = "@(#)timezone.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/timezone.c,v 1.5 2002/02/01 01:08:48 obrien Exp $"); + +#include +#include +#include +#include +#include +#define TZ_MAX_CHARS 255 + +char *_tztab(); + +/* + * timezone -- + * The arguments are the number of minutes of time you are westward + * from Greenwich and whether DST is in effect. It returns a string + * giving the name of the local timezone. Should be replaced, in the + * application code, by a call to localtime. + */ + +static char czone[TZ_MAX_CHARS]; /* space for zone name */ + +char * +timezone(zone, dst) + int zone, + dst; +{ + char *beg, + *end; + + if ( (beg = getenv("TZNAME")) ) { /* set in environment */ + if ( (end = index(beg, ',')) ) {/* "PST,PDT" */ + if (dst) + return(++end); + *end = '\0'; + (void)strncpy(czone,beg,sizeof(czone) - 1); + czone[sizeof(czone) - 1] = '\0'; + *end = ','; + return(czone); + } + return(beg); + } + return(_tztab(zone,dst)); /* default: table or created zone */ +} + +static struct zone { + int offset; + char *stdzone; + char *dlzone; +} zonetab[] = { + {-1*60, "MET", "MET DST"}, /* Middle European */ + {-2*60, "EET", "EET DST"}, /* Eastern European */ + {4*60, "AST", "ADT"}, /* Atlantic */ + {5*60, "EST", "EDT"}, /* Eastern */ + {6*60, "CST", "CDT"}, /* Central */ + {7*60, "MST", "MDT"}, /* Mountain */ + {8*60, "PST", "PDT"}, /* Pacific */ +#ifdef notdef + /* there's no way to distinguish this from WET */ + {0, "GMT", 0}, /* Greenwich */ +#endif + {0*60, "WET", "WET DST"}, /* Western European */ + {-10*60,"EST", "EST"}, /* Aust: Eastern */ + {-10*60+30,"CST", "CST"}, /* Aust: Central */ + {-8*60, "WST", 0}, /* Aust: Western */ + {-1} +}; + +/* + * _tztab -- + * check static tables or create a new zone name; broken out so that + * we can make a guess as to what the zone is if the standard tables + * aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE + * STANDARD LIBRARY. + */ +char * +_tztab(zone,dst) + int zone; + int dst; +{ + struct zone *zp; + char sign; + + for (zp = zonetab; zp->offset != -1;++zp) /* static tables */ + if (zp->offset == zone) { + if (dst && zp->dlzone) + return(zp->dlzone); + if (!dst && zp->stdzone) + return(zp->stdzone); + } + + if (zone < 0) { /* create one */ + zone = -zone; + sign = '+'; + } + else + sign = '-'; + (void)snprintf(czone, sizeof(czone), + "GMT%c%d:%02d",sign,zone / 60,zone % 60); + return(czone); +} diff --git a/src/lib/libc/gen/ttyname.c b/src/lib/libc/gen/ttyname.c new file mode 100644 index 0000000..b4e52f7 --- /dev/null +++ b/src/lib/libc/gen/ttyname.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/ttyname.c,v 1.16 2004/01/06 18:26:14 nectar Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" + +static char buf[sizeof(_PATH_DEV) + MAXNAMLEN]; +static char *ttyname_threaded(int fd); +static char *ttyname_unthreaded(int fd); + +static pthread_mutex_t ttyname_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_key_t ttyname_key; +static int ttyname_init = 0; + +char * +ttyname(int fd) +{ + char *ret; + + if (__isthreaded == 0) + ret = ttyname_unthreaded(fd); + else + ret = ttyname_threaded(fd); + return (ret); +} + +char * +ttyname_r(int fd, char *buf, size_t len) +{ + struct stat sb; + char *rval; + + rval = NULL; + + /* Must be a terminal. */ + if (!isatty(fd)) + return (rval); + /* Must be a character device. */ + if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) + return (rval); + /* Must have enough room */ + if (len <= sizeof(_PATH_DEV)) + return (rval); + + strcpy(buf, _PATH_DEV); + devname_r(sb.st_rdev, S_IFCHR, + buf + strlen(buf), sizeof(buf) - strlen(buf)); + return (buf); +} + +static char * +ttyname_threaded(int fd) +{ + char *buf; + + if (ttyname_init == 0) { + _pthread_mutex_lock(&ttyname_lock); + if (ttyname_init == 0) { + if (_pthread_key_create(&ttyname_key, free)) { + _pthread_mutex_unlock(&ttyname_lock); + return (NULL); + } + ttyname_init = 1; + } + _pthread_mutex_unlock(&ttyname_lock); + } + + /* Must have thread specific data field to put data */ + if ((buf = _pthread_getspecific(ttyname_key)) == NULL) { + if ((buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN)) != NULL) { + if (_pthread_setspecific(ttyname_key, buf) != 0) { + free(buf); + return (NULL); + } + } else { + return (NULL); + } + } + return (ttyname_r(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN)); +} + +static char * +ttyname_unthreaded(int fd) +{ + struct stat sb; + struct termios ttyb; + + /* Must be a terminal. */ + if (tcgetattr(fd, &ttyb) < 0) + return (NULL); + /* Must be a character device. */ + if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) + return (NULL); + + strcpy(buf, _PATH_DEV); + devname_r(sb.st_rdev, S_IFCHR, + buf + strlen(buf), sizeof(buf) - strlen(buf)); + return (buf); +} diff --git a/src/lib/libc/gen/ttyslot.c b/src/lib/libc/gen/ttyslot.c new file mode 100644 index 0000000..0d7359c --- /dev/null +++ b/src/lib/libc/gen/ttyslot.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)ttyslot.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/ttyslot.c,v 1.4 2002/02/01 01:08:48 obrien Exp $"); + +#include +#include +#include +#include + +int +ttyslot() +{ + struct ttyent *ttyp; + int slot; + char *p; + int cnt; + char *name; + + setttyent(); + for (cnt = 0; cnt < 3; ++cnt) + if ( (name = ttyname(cnt)) ) { + if ( (p = rindex(name, '/')) ) + ++p; + else + p = name; + for (slot = 1; (ttyp = getttyent()); ++slot) + if (!strcmp(ttyp->ty_name, p)) { + endttyent(); + return(slot); + } + break; + } + endttyent(); + return(0); +} diff --git a/src/lib/libc/gen/ualarm.c b/src/lib/libc/gen/ualarm.c new file mode 100644 index 0000000..a9200ae --- /dev/null +++ b/src/lib/libc/gen/ualarm.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1985, 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[] = "@(#)ualarm.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/ualarm.c,v 1.4 2002/12/29 00:59:09 mike Exp $"); + +#include +#include + +#define USPS 1000000 /* # of microseconds in a second */ + +/* + * Generate a SIGALRM signal in ``usecs'' microseconds. + * If ``reload'' is non-zero, keep generating SIGALRM + * every ``reload'' microseconds after the first signal. + */ +useconds_t +ualarm(usecs, reload) + useconds_t usecs; + useconds_t reload; +{ + struct itimerval new, old; + + new.it_interval.tv_usec = reload % USPS; + new.it_interval.tv_sec = reload / USPS; + + new.it_value.tv_usec = usecs % USPS; + new.it_value.tv_sec = usecs / USPS; + + if (setitimer(ITIMER_REAL, &new, &old) == 0) + return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); + /* else */ + return (-1); +} diff --git a/src/lib/libc/gen/ulimit.c b/src/lib/libc/gen/ulimit.c new file mode 100644 index 0000000..d25ff47 --- /dev/null +++ b/src/lib/libc/gen/ulimit.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 2002 Kyle Martin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/gen/ulimit.c,v 1.3 2003/01/04 01:11:49 tjr Exp $ + */ + +#include +#include +#include + +#include +#include +#include +#include + +long +ulimit(int cmd, ...) +{ + struct rlimit limit; + va_list ap; + long arg; + + if (cmd == UL_GETFSIZE) { + if (getrlimit(RLIMIT_FSIZE, &limit) == -1) + return (-1); + limit.rlim_cur /= 512; + if (limit.rlim_cur > LONG_MAX) + return (LONG_MAX); + return ((long)limit.rlim_cur); + } else if (cmd == UL_SETFSIZE) { + va_start(ap, cmd); + arg = va_arg(ap, long); + va_end(ap); + limit.rlim_max = limit.rlim_cur = (rlim_t)arg * 512; + + /* The setrlimit() function sets errno to EPERM if needed. */ + if (setrlimit(RLIMIT_FSIZE, &limit) == -1) + return (-1); + if (arg * 512 > LONG_MAX) + return (LONG_MAX); + return (arg); + } else { + errno = EINVAL; + return (-1); + } +} diff --git a/src/lib/libc/gen/un-namespace.h b/src/lib/libc/gen/un-namespace.h new file mode 100644 index 0000000..067e22d --- /dev/null +++ b/src/lib/libc/gen/un-namespace.h @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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. + * + * $FreeBSD: src/lib/libc/include/un-namespace.h,v 1.13 2003/05/01 19:03:13 nectar Exp $ + */ + +#ifndef _UN_NAMESPACE_H_ +#define _UN_NAMESPACE_H_ + +#undef accept +#undef __acl_aclcheck_fd +#undef __acl_delete_fd +#undef __acl_get_fd +#undef __acl_set_fd +#undef bind +#undef __cap_get_fd +#undef __cap_set_fd +#undef close +#undef connect +#undef dup +#undef dup2 +#undef execve +#undef fcntl +#undef flock +#undef flockfile +#undef fpathconf +#undef fstat +#undef fstatfs +#undef fsync +#undef funlockfile +#undef getdirentries +#undef getlogin +#undef getpeername +#undef getprogname +#undef getsockname +#undef getsockopt +#undef ioctl +#undef kevent +#undef listen +#undef nanosleep +#undef open +#undef poll +#undef pthread_cond_broadcast +#undef pthread_cond_destroy +#undef pthread_cond_init +#undef pthread_cond_signal +#undef pthread_cond_timedwait +#undef pthread_cond_wait +#undef pthread_exit +#undef pthread_getspecific +#undef pthread_key_create +#undef pthread_key_delete +#undef pthread_main_np +#undef pthread_mutex_destroy +#undef pthread_mutex_init +#undef pthread_mutex_lock +#undef pthread_mutex_trylock +#undef pthread_mutex_unlock +#undef pthread_mutexattr_init +#undef pthread_mutexattr_destroy +#undef pthread_mutexattr_settype +#undef pthread_once +#undef pthread_rwlock_destroy +#undef pthread_rwlock_init +#undef pthread_rwlock_rdlock +#undef pthread_rwlock_wrlock +#undef pthread_rwlock_tryrdlock +#undef pthread_rwlock_trywrlock +#undef pthread_rwlock_unlock +#undef pthread_self +#undef pthread_setspecific +#undef pthread_sigmask +#undef read +#undef readv +#undef recvfrom +#undef recvmsg +#undef select +#undef sendmsg +#undef sendto +#undef setsockopt +#undef sigaction +#undef sigprocmask +#undef sigsuspend +#undef socket +#undef socketpair +#undef wait4 +#undef waitpid +#undef write +#undef writev + +#if 0 +#undef creat +#undef fchflags +#undef fchmod +#undef ftrylockfile +#undef msync +#undef nfssvc +#undef pause +#undef pthread_rwlockattr_init +#undef pthread_rwlockattr_destroy +#undef sched_yield +#undef sendfile +#undef shutdown +#undef sigaltstack +#undef sigpending +#undef sigreturn +#undef sigsetmask +#undef sleep +#undef system +#undef tcdrain +#undef wait +#endif /* 0 */ + +#ifdef _SIGNAL_H_ +int _sigaction(int, const struct sigaction *, struct sigaction *); +#endif + +#ifdef _SYS_EVENT_H_ +int _kevent(int, const struct kevent *, int, struct kevent *, + int, const struct timespec *); +#endif + +#ifdef _SYS_FCNTL_H_ +int _flock(int, int); +#endif + +#undef err +#undef warn +#undef nsdispatch + +#endif /* _UN_NAMESPACE_H_ */ diff --git a/src/lib/libc/gen/uname.c b/src/lib/libc/gen/uname.c new file mode 100644 index 0000000..699e7b2 --- /dev/null +++ b/src/lib/libc/gen/uname.c @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 1994 + * 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[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/uname.c,v 1.9 2002/02/01 00:57:29 obrien Exp $"); + +#define uname wrapped_uname +#include +#include +#include +#include +#undef uname + +int +uname(struct utsname *name) +{ + return __xuname(32, name); +} diff --git a/src/lib/libc/gen/unvis.c b/src/lib/libc/gen/unvis.c new file mode 100644 index 0000000..491df36 --- /dev/null +++ b/src/lib/libc/gen/unvis.c @@ -0,0 +1,303 @@ +/*- + * Copyright (c) 1989, 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[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/unvis.c,v 1.8 2003/02/16 17:29:09 nectar Exp $"); + +#include +#include +#include + +/* + * decode driven by state machine + */ +#define S_GROUND 0 /* haven't seen escape char */ +#define S_START 1 /* start decoding special sequence */ +#define S_META 2 /* metachar started (M) */ +#define S_META1 3 /* metachar more, regular char (-) */ +#define S_CTRL 4 /* control char started (^) */ +#define S_OCTAL2 5 /* octal digit 2 */ +#define S_OCTAL3 6 /* octal digit 3 */ +#define S_HEX2 7 /* hex digit 2 */ + +#define S_HTTP 0x080 /* %HEXHEX escape */ + +#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') +#define ishex(c) ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '9') || (((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f')) + +/* + * unvis - decode characters previously encoded by vis + */ +int +unvis(cp, c, astate, flag) + char *cp; + int c, *astate, flag; +{ + + if (flag & UNVIS_END) { + if (*astate == S_OCTAL2 || *astate == S_OCTAL3) { + *astate = S_GROUND; + return (UNVIS_VALID); + } + return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD); + } + + switch (*astate & ~S_HTTP) { + + case S_GROUND: + *cp = 0; + if (c == '\\') { + *astate = S_START; + return (0); + } + if (flag & VIS_HTTPSTYLE && c == '%') { + *astate = S_START | S_HTTP; + return (0); + } + *cp = c; + return (UNVIS_VALID); + + case S_START: + if (*astate & S_HTTP) { + if (ishex(tolower(c))) { + *cp = isdigit(c) ? (c - '0') : (tolower(c) - 'a'); + *astate = S_HEX2; + return (0); + } + } + switch(c) { + case '\\': + *cp = c; + *astate = S_GROUND; + return (UNVIS_VALID); + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + *cp = (c - '0'); + *astate = S_OCTAL2; + return (0); + case 'M': + *cp = 0200; + *astate = S_META; + return (0); + case '^': + *astate = S_CTRL; + return (0); + case 'n': + *cp = '\n'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'r': + *cp = '\r'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'b': + *cp = '\b'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'a': + *cp = '\007'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'v': + *cp = '\v'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 't': + *cp = '\t'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'f': + *cp = '\f'; + *astate = S_GROUND; + return (UNVIS_VALID); + case 's': + *cp = ' '; + *astate = S_GROUND; + return (UNVIS_VALID); + case 'E': + *cp = '\033'; + *astate = S_GROUND; + return (UNVIS_VALID); + case '\n': + /* + * hidden newline + */ + *astate = S_GROUND; + return (UNVIS_NOCHAR); + case '$': + /* + * hidden marker + */ + *astate = S_GROUND; + return (UNVIS_NOCHAR); + } + *astate = S_GROUND; + return (UNVIS_SYNBAD); + + case S_META: + if (c == '-') + *astate = S_META1; + else if (c == '^') + *astate = S_CTRL; + else { + *astate = S_GROUND; + return (UNVIS_SYNBAD); + } + return (0); + + case S_META1: + *astate = S_GROUND; + *cp |= c; + return (UNVIS_VALID); + + case S_CTRL: + if (c == '?') + *cp |= 0177; + else + *cp |= c & 037; + *astate = S_GROUND; + return (UNVIS_VALID); + + case S_OCTAL2: /* second possible octal digit */ + if (isoctal(c)) { + /* + * yes - and maybe a third + */ + *cp = (*cp << 3) + (c - '0'); + *astate = S_OCTAL3; + return (0); + } + /* + * no - done with current sequence, push back passed char + */ + *astate = S_GROUND; + return (UNVIS_VALIDPUSH); + + case S_OCTAL3: /* third possible octal digit */ + *astate = S_GROUND; + if (isoctal(c)) { + *cp = (*cp << 3) + (c - '0'); + return (UNVIS_VALID); + } + /* + * we were done, push back passed char + */ + return (UNVIS_VALIDPUSH); + + case S_HEX2: /* second mandatory hex digit */ + if (ishex(tolower(c))) { + *cp = (isdigit(c) ? (*cp << 4) + (c - '0') : (*cp << 4) + (tolower(c) - 'a' + 10)); + } + *astate = S_GROUND; + return (UNVIS_VALID); + + default: + /* + * decoder in unknown state - (probably uninitialized) + */ + *astate = S_GROUND; + return (UNVIS_SYNBAD); + } +} + +/* + * strunvis - decode src into dst + * + * Number of chars decoded into dst is returned, -1 on error. + * Dst is null terminated. + */ + +int +strunvis(dst, src) + char *dst; + const char *src; +{ + char c; + char *start = dst; + int state = 0; + + while ( (c = *src++) ) { + again: + switch (unvis(dst, c, &state, 0)) { + case UNVIS_VALID: + dst++; + break; + case UNVIS_VALIDPUSH: + dst++; + goto again; + case 0: + case UNVIS_NOCHAR: + break; + default: + return (-1); + } + } + if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) + dst++; + *dst = '\0'; + return (dst - start); +} + +int +strunvisx(dst, src, flag) + char *dst; + const char *src; +{ + char c; + char *start = dst; + int state = 0; + + while ( (c = *src++) ) { + again: + switch (unvis(dst, c, &state, flag)) { + case UNVIS_VALID: + dst++; + break; + case UNVIS_VALIDPUSH: + dst++; + goto again; + case 0: + case UNVIS_NOCHAR: + break; + default: + return (-1); + } + } + if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) + dst++; + *dst = '\0'; + return (dst - start); +} diff --git a/src/lib/libc/gen/usleep.c b/src/lib/libc/gen/usleep.c new file mode 100644 index 0000000..81eb948 --- /dev/null +++ b/src/lib/libc/gen/usleep.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/usleep.c,v 1.28 2002/12/29 00:59:09 mike Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" + +int +usleep(useconds) + useconds_t useconds; +{ + struct timespec time_to_sleep; + + time_to_sleep.tv_nsec = (useconds % 1000000) * 1000; + time_to_sleep.tv_sec = useconds / 1000000; + return (_nanosleep(&time_to_sleep, NULL)); +} diff --git a/src/lib/libc/gen/utime.c b/src/lib/libc/gen/utime.c new file mode 100644 index 0000000..cefa020 --- /dev/null +++ b/src/lib/libc/gen/utime.c @@ -0,0 +1,59 @@ +/*- + * 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[] = "@(#)utime.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/utime.c,v 1.2 2002/03/22 21:52:05 obrien Exp $"); + +#include + +#include + +int +utime(path, times) + const char *path; + const struct utimbuf *times; +{ + struct timeval tv[2], *tvp; + + if (times) { + tv[0].tv_sec = times->actime; + tv[1].tv_sec = times->modtime; + tv[0].tv_usec = tv[1].tv_usec = 0; + tvp = tv; + } else + tvp = NULL; + return (utimes(path, tvp)); +} diff --git a/src/lib/libc/gen/valloc.c b/src/lib/libc/gen/valloc.c new file mode 100644 index 0000000..206a7e8 --- /dev/null +++ b/src/lib/libc/gen/valloc.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 1980, 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[] = "@(#)valloc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/valloc.c,v 1.3 2002/03/22 21:52:05 obrien Exp $"); + +#include +#include + +void * +valloc(i) + size_t i; +{ + long valsiz = getpagesize(), j; + void *cp = malloc(i + (valsiz-1)); + + j = ((long)cp + (valsiz-1)) &~ (valsiz-1); + return ((void *)j); +} diff --git a/src/lib/libc/gen/vis.c b/src/lib/libc/gen/vis.c new file mode 100644 index 0000000..8b82877 --- /dev/null +++ b/src/lib/libc/gen/vis.c @@ -0,0 +1,205 @@ +/*- + * Copyright (c) 1989, 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[] = "@(#)vis.c 8.1 (Berkeley) 7/19/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/vis.c,v 1.13 2003/10/30 12:41:50 phk Exp $"); + +#include +#include +#include +#include +#include + +#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') + +/* + * vis - visually encode characters + */ +char * +vis(dst, c, flag, nextc) + char *dst; + int c, nextc; + int flag; +{ + c = (unsigned char)c; + + if (flag & VIS_HTTPSTYLE) { + /* Described in RFC 1808 */ + if (!(isalnum(c) /* alpha-numeric */ + /* safe */ + || c == '$' || c == '-' || c == '_' || c == '.' || c == '+' + /* extra */ + || c == '!' || c == '*' || c == '\'' || c == '(' + || c == ')' || c == ',')) { + *dst++ = '%'; + snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c); + dst += 2; + goto done; + } + } + + if ((flag & VIS_GLOB) && + (c == '*' || c == '?' || c == '[' || c == '#')) + ; + else if (isgraph(c) || + ((flag & VIS_SP) == 0 && c == ' ') || + ((flag & VIS_TAB) == 0 && c == '\t') || + ((flag & VIS_NL) == 0 && c == '\n') || + ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) { + *dst++ = c; + if (c == '\\' && (flag & VIS_NOSLASH) == 0) + *dst++ = '\\'; + *dst = '\0'; + return (dst); + } + + if (flag & VIS_CSTYLE) { + switch(c) { + case '\n': + *dst++ = '\\'; + *dst++ = 'n'; + goto done; + case '\r': + *dst++ = '\\'; + *dst++ = 'r'; + goto done; + case '\b': + *dst++ = '\\'; + *dst++ = 'b'; + goto done; + case '\a': + *dst++ = '\\'; + *dst++ = 'a'; + goto done; + case '\v': + *dst++ = '\\'; + *dst++ = 'v'; + goto done; + case '\t': + *dst++ = '\\'; + *dst++ = 't'; + goto done; + case '\f': + *dst++ = '\\'; + *dst++ = 'f'; + goto done; + case ' ': + *dst++ = '\\'; + *dst++ = 's'; + goto done; + case '\0': + *dst++ = '\\'; + *dst++ = '0'; + if (isoctal(nextc)) { + *dst++ = '0'; + *dst++ = '0'; + } + goto done; + } + } + if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) { + *dst++ = '\\'; + *dst++ = ((u_char)c >> 6 & 07) + '0'; + *dst++ = ((u_char)c >> 3 & 07) + '0'; + *dst++ = ((u_char)c & 07) + '0'; + goto done; + } + if ((flag & VIS_NOSLASH) == 0) + *dst++ = '\\'; + if (c & 0200) { + c &= 0177; + *dst++ = 'M'; + } + if (iscntrl(c)) { + *dst++ = '^'; + if (c == 0177) + *dst++ = '?'; + else + *dst++ = c + '@'; + } else { + *dst++ = '-'; + *dst++ = c; + } +done: + *dst = '\0'; + return (dst); +} + +/* + * strvis, strvisx - visually encode characters from src into dst + * + * Dst must be 4 times the size of src to account for possible + * expansion. The length of dst, not including the trailing NUL, + * is returned. + * + * Strvisx encodes exactly len bytes from src into dst. + * This is useful for encoding a block of data. + */ +int +strvis(dst, src, flag) + char *dst; + const char *src; + int flag; +{ + char c; + char *start; + + for (start = dst; (c = *src); ) + dst = vis(dst, c, flag, *++src); + *dst = '\0'; + return (dst - start); +} + +int +strvisx(dst, src, len, flag) + char *dst; + const char *src; + size_t len; + int flag; +{ + int c; + char *start; + + for (start = dst; len > 1; len--) { + c = *src; + dst = vis(dst, c, flag, *++src); + } + if (len) + dst = vis(dst, *src, flag, '\0'); + *dst = '\0'; + + return (dst - start); +} diff --git a/src/lib/libc/gen/wait.c b/src/lib/libc/gen/wait.c new file mode 100644 index 0000000..8cb80a4 --- /dev/null +++ b/src/lib/libc/gen/wait.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)wait.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/wait.c,v 1.6 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" + +pid_t +__wait(int *istat) +{ + return (_wait4(WAIT_ANY, istat, 0, (struct rusage *)0)); +} + +__weak_reference(__wait, wait); +__weak_reference(__wait, _wait); diff --git a/src/lib/libc/gen/wait3.c b/src/lib/libc/gen/wait3.c new file mode 100644 index 0000000..a4b91a7 --- /dev/null +++ b/src/lib/libc/gen/wait3.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)wait3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/wait3.c,v 1.3 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" + +pid_t +wait3(istat, options, rup) + int *istat; + int options; + struct rusage *rup; +{ + return (_wait4(WAIT_ANY, istat, options, rup)); +} diff --git a/src/lib/libc/gen/waitpid.c b/src/lib/libc/gen/waitpid.c new file mode 100644 index 0000000..273d1f3 --- /dev/null +++ b/src/lib/libc/gen/waitpid.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)waitpid.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/gen/waitpid.c,v 1.6 2002/02/01 00:57:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" + +pid_t +__waitpid(pid_t pid, int *istat, int options) +{ + return (_wait4(pid, istat, options, (struct rusage *)0)); +} + +__weak_reference(__waitpid, waitpid); +__weak_reference(__waitpid, _waitpid); diff --git a/src/lib/libc/gen/wordexp.c b/src/lib/libc/gen/wordexp.c new file mode 100644 index 0000000..5cbba1b --- /dev/null +++ b/src/lib/libc/gen/wordexp.c @@ -0,0 +1,316 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +__FBSDID("$FreeBSD: src/lib/libc/gen/wordexp.c,v 1.5 2004/04/09 11:32:32 tjr Exp $"); + +static int we_askshell(const char *, wordexp_t *, int); +static int we_check(const char *, int); + +/* + * wordexp -- + * Perform shell word expansion on `words' and place the resulting list + * of words in `we'. See wordexp(3). + * + * Specified by IEEE Std. 1003.1-2001. + */ +int +wordexp(const char * __restrict words, wordexp_t * __restrict we, int flags) +{ + int error; + + if (flags & WRDE_REUSE) + wordfree(we); + if ((flags & WRDE_APPEND) == 0) { + we->we_wordc = 0; + we->we_wordv = NULL; + we->we_strings = NULL; + we->we_nbytes = 0; + } + if ((error = we_check(words, flags)) != 0) { + wordfree(we); + return (error); + } + if ((error = we_askshell(words, we, flags)) != 0) { + wordfree(we); + return (error); + } + return (0); +} + +/* + * we_askshell -- + * Use the `wordexp' /bin/sh builtin function to do most of the work + * in expanding the word string. This function is complicated by + * memory management. + */ +static int +we_askshell(const char *words, wordexp_t *we, int flags) +{ + int pdes[2]; /* Pipe to child */ + char bbuf[9]; /* Buffer for byte count */ + char wbuf[9]; /* Buffer for word count */ + long nwords, nbytes; /* Number of words, bytes from child */ + long i; /* Handy integer */ + size_t sofs; /* Offset into we->we_strings */ + size_t vofs; /* Offset into we->we_wordv */ + pid_t pid; /* Process ID of child */ + int status; /* Child exit status */ + char *ifs; /* IFS env. var. */ + char *np, *p; /* Handy pointers */ + char *nstrings; /* Temporary for realloc() */ + char **nwv; /* Temporary for realloc() */ + + if ((ifs = getenv("IFS")) == NULL) + ifs = " \t\n"; + + if (pipe(pdes) < 0) + return (WRDE_NOSPACE); /* XXX */ + if ((pid = fork()) < 0) { + _close(pdes[0]); + _close(pdes[1]); + return (WRDE_NOSPACE); /* XXX */ + } + else if (pid == 0) { + /* + * We are the child; just get /bin/sh to run the wordexp + * builtin on `words'. + */ + int devnull; + char *cmd; + + _close(pdes[0]); + if (_dup2(pdes[1], STDOUT_FILENO) < 0) + _exit(1); + _close(pdes[1]); + if (asprintf(&cmd, "wordexp%c%s\n", *ifs, words) < 0) + _exit(1); + if ((flags & WRDE_SHOWERR) == 0) { + if ((devnull = _open(_PATH_DEVNULL, O_RDWR, 0666)) < 0) + _exit(1); + if (_dup2(devnull, STDERR_FILENO) < 0) + _exit(1); + _close(devnull); + } + execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u", + "-c", cmd, (char *)NULL); + _exit(1); + } + + /* + * We are the parent; read the output of the shell wordexp function, + * which is a 32-bit hexadecimal word count, a 32-bit hexadecimal + * byte count (not including terminating null bytes), followed by + * the expanded words separated by nulls. + */ + _close(pdes[1]); + if (_read(pdes[0], wbuf, 8) != 8 || _read(pdes[0], bbuf, 8) != 8) { + _close(pdes[0]); + _waitpid(pid, &status, 0); + return (flags & WRDE_UNDEF ? WRDE_BADVAL : WRDE_SYNTAX); + } + wbuf[8] = bbuf[8] = '\0'; + nwords = strtol(wbuf, NULL, 16); + nbytes = strtol(bbuf, NULL, 16) + nwords; + + /* + * Allocate or reallocate (when flags & WRDE_APPEND) the word vector + * and string storage buffers for the expanded words we're about to + * read from the child. + */ + sofs = we->we_nbytes; + vofs = we->we_wordc; + if ((flags & (WRDE_DOOFS|WRDE_APPEND)) == (WRDE_DOOFS|WRDE_APPEND)) + vofs += we->we_offs; + we->we_wordc += nwords; + we->we_nbytes += nbytes; + if ((nwv = realloc(we->we_wordv, (we->we_wordc + 1 + + (flags & WRDE_DOOFS ? we->we_offs : 0)) * + sizeof(char *))) == NULL) { + _close(pdes[0]); + _waitpid(pid, &status, 0); + return (WRDE_NOSPACE); + } + we->we_wordv = nwv; + if ((nstrings = realloc(we->we_strings, we->we_nbytes)) == NULL) { + _close(pdes[0]); + _waitpid(pid, &status, 0); + return (WRDE_NOSPACE); + } + for (i = 0; i < vofs; i++) + if (we->we_wordv[i] != NULL) + we->we_wordv[i] += nstrings - we->we_strings; + we->we_strings = nstrings; + + if (_read(pdes[0], we->we_strings + sofs, nbytes) != nbytes) { + _close(pdes[0]); + _waitpid(pid, &status, 0); + return (flags & WRDE_UNDEF ? WRDE_BADVAL : WRDE_SYNTAX); + } + + if (_waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || + WEXITSTATUS(status) != 0) { + _close(pdes[0]); + return (flags & WRDE_UNDEF ? WRDE_BADVAL : WRDE_SYNTAX); + } + _close(pdes[0]); + + /* + * Break the null-terminated expanded word strings out into + * the vector. + */ + if (vofs == 0 && flags & WRDE_DOOFS) + while (vofs < we->we_offs) + we->we_wordv[vofs++] = NULL; + p = we->we_strings + sofs; + while (nwords-- != 0) { + we->we_wordv[vofs++] = p; + if ((np = memchr(p, '\0', nbytes)) == NULL) + return (WRDE_NOSPACE); /* XXX */ + nbytes -= np - p + 1; + p = np + 1; + } + we->we_wordv[vofs] = NULL; + + return (0); +} + +/* + * we_check -- + * Check that the string contains none of the following unquoted + * special characters: |&;<>(){} + * or command substitutions when WRDE_NOCMD is set in flags. + */ +static int +we_check(const char *words, int flags) +{ + char c; + int dquote, level, quote, squote; + + quote = squote = dquote = 0; + while ((c = *words++) != '\0') { + switch (c) { + case '\\': + quote ^= 1; + continue; + case '\'': + if (quote + dquote == 0) + squote ^= 1; + break; + case '"': + if (quote + squote == 0) + dquote ^= 1; + break; + case '`': + if (quote + squote == 0 && flags & WRDE_NOCMD) + return (WRDE_CMDSUB); + while ((c = *words++) != '\0' && c != '`') + if (c == '\\' && (c = *words++) == '\0') + break; + if (c == '\0') + return (WRDE_SYNTAX); + break; + case '|': case '&': case ';': case '<': case '>': + case '{': case '}': case '(': case ')': case '\n': + if (quote + squote + dquote == 0) + return (WRDE_BADCHAR); + break; + case '$': + if ((c = *words++) == '\0') + break; + else if (quote + squote == 0 && c == '(') { + if (flags & WRDE_NOCMD && *words != '(') + return (WRDE_CMDSUB); + level = 1; + while ((c = *words++) != '\0') { + if (c == '\\') { + if ((c = *words++) == '\0') + break; + } else if (c == '(') + level++; + else if (c == ')' && --level == 0) + break; + } + if (c == '\0' || level != 0) + return (WRDE_SYNTAX); + } else if (quote + squote == 0 && c == '{') { + level = 1; + while ((c = *words++) != '\0') { + if (c == '\\') { + if ((c = *words++) == '\0') + break; + } else if (c == '{') + level++; + else if (c == '}' && --level == 0) + break; + } + if (c == '\0' || level != 0) + return (WRDE_SYNTAX); + } else + c = *--words; + break; + default: + break; + } + quote = 0; + } + if (quote + squote + dquote != 0) + return (WRDE_SYNTAX); + + return (0); +} + +/* + * wordfree -- + * Free the result of wordexp(). See wordexp(3). + * + * Specified by IEEE Std. 1003.1-2001. + */ +void +wordfree(wordexp_t *we) +{ + + if (we == NULL) + return; + free(we->we_wordv); + free(we->we_strings); + we->we_wordv = NULL; + we->we_strings = NULL; + we->we_nbytes = 0; + we->we_wordc = 0; +} diff --git a/src/lib/libc/generic/Makefile b/src/lib/libc/generic/Makefile new file mode 100644 index 0000000..f76f39f --- /dev/null +++ b/src/lib/libc/generic/Makefile @@ -0,0 +1,33 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = unlink.o getcwd.o mkdir.o chdir.o +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -I../../../include -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdlib -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/generic/chdir.c b/src/lib/libc/generic/chdir.c new file mode 100644 index 0000000..b1f7be4 --- /dev/null +++ b/src/lib/libc/generic/chdir.c @@ -0,0 +1,30 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +int chdir(const char *path) { + asm( + "int %0\n" + : : "i" (0x80),"a" (28),"b" (path) + ); + return(0x0); + } \ No newline at end of file diff --git a/src/lib/libc/generic/getcwd.c b/src/lib/libc/generic/getcwd.c new file mode 100644 index 0000000..5c03359 --- /dev/null +++ b/src/lib/libc/generic/getcwd.c @@ -0,0 +1,32 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +char *getcwd(char *cwd,uInt32 len) { + asm( + "int %0\n" + : : "i" (0x80),"a" (26),"b" (cwd) + ); + return(cwd); + } diff --git a/src/lib/libc/generic/mkdir.c b/src/lib/libc/generic/mkdir.c new file mode 100644 index 0000000..ac1dee4 --- /dev/null +++ b/src/lib/libc/generic/mkdir.c @@ -0,0 +1,32 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int mkdir(const char *path,mode_t mode) { + asm( + "int %0\n" + : : "i" (0x80),"a" (29),"b" (path) + ); + return(0x0); + } diff --git a/src/lib/libc/generic/unlink.c b/src/lib/libc/generic/unlink.c new file mode 100644 index 0000000..ef248e7 --- /dev/null +++ b/src/lib/libc/generic/unlink.c @@ -0,0 +1,31 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +int unlink(const char *path) { + int retVal = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (30),"b" (path),"c" (&retVal) + ); + return(retVal); + } diff --git a/src/lib/libc/i386/SYS.h b/src/lib/libc/i386/SYS.h new file mode 100644 index 0000000..209f0b2 --- /dev/null +++ b/src/lib/libc/i386/SYS.h @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * + * @(#)SYS.h 5.5 (Berkeley) 5/7/91 + * $FreeBSD: src/lib/libc/i386/SYS.h,v 1.24 2002/09/17 01:48:51 peter Exp $ + */ + +#include +#include + +#define SYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); \ + ENTRY(__CONCAT(__sys_,x)); \ + .weak CNAME(x); \ + .set CNAME(x),CNAME(__CONCAT(__sys_,x)); \ + .weak CNAME(__CONCAT(_,x)); \ + .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \ + mov __CONCAT($SYS_,x),%eax; KERNCALL; jb 2b + +#define RSYSCALL(x) SYSCALL(x); ret + +#define PSEUDO(x) ENTRY(__CONCAT(__sys_,x)); \ + .weak CNAME(__CONCAT(_,x)); \ + .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \ + mov __CONCAT($SYS_,x),%eax; KERNCALL; ret + +/* gas messes up offset -- although we don't currently need it, do for BCS */ +#define LCALL(x,y) .byte 0x9a ; .long y; .word x + +#define KERNCALL int $0x80 diff --git a/src/lib/libc/i386/_fpmath.h b/src/lib/libc/i386/_fpmath.h new file mode 100644 index 0000000..daebe95 --- /dev/null +++ b/src/lib/libc/i386/_fpmath.h @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2002, 2003 David Schultz + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/i386/_fpmath.h,v 1.3 2004/01/18 07:57:01 das Exp $ + */ + +union IEEEl2bits { + long double e; + struct { + unsigned int manl :32; + unsigned int manh :32; + unsigned int exp :15; + unsigned int sign :1; + unsigned int junk :16; + } bits; +}; + +#define mask_nbit_l(u) ((u).bits.manh &= 0x7fffffff) + +#define LDBL_MANH_SIZE 32 +#define LDBL_MANL_SIZE 32 + +#define LDBL_TO_ARRAY32(u, a) do { \ + (a)[0] = (uint32_t)(u).bits.manl; \ + (a)[1] = (uint32_t)(u).bits.manh; \ +} while(0) diff --git a/src/lib/libc/i386/arith.h b/src/lib/libc/i386/arith.h new file mode 100644 index 0000000..c55a4df --- /dev/null +++ b/src/lib/libc/i386/arith.h @@ -0,0 +1,15 @@ +/* + * MD header for contrib/gdtoa + * + * $FreeBSD: src/lib/libc/i386/arith.h,v 1.2 2003/05/08 13:50:43 das Exp $ + */ + +/* + * NOTE: The definitions in this file must be correct or strtod(3) and + * floating point formats in printf(3) will break! The file can be + * generated by running contrib/gdtoa/arithchk.c on the target + * architecture. See contrib/gdtoa/gdtoaimp.h for details. + */ + +#define IEEE_8087 +#define Arith_Kind_ASL 1 diff --git a/src/lib/libc/i386/gen/Makefile.inc b/src/lib/libc/i386/gen/Makefile.inc new file mode 100644 index 0000000..89bf26f --- /dev/null +++ b/src/lib/libc/i386/gen/Makefile.inc @@ -0,0 +1,6 @@ +# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/i386/gen/Makefile.inc,v 1.18 2002/11/16 06:39:11 deischen Exp $ + +SRCS+= _ctx_start.S _setjmp.S alloca.S fabs.S frexp.c \ + infinity.c isinf.c ldexp.c makecontext.c modf.S \ + rfork_thread.S setjmp.S signalcontext.c sigsetjmp.S diff --git a/src/lib/libc/i386/gen/_ctx_start.S b/src/lib/libc/i386/gen/_ctx_start.S new file mode 100644 index 0000000..b9fd17d --- /dev/null +++ b/src/lib/libc/i386/gen/_ctx_start.S @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2001 Daniel Eischen + * 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. Neither the name of the author 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 AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/_ctx_start.S,v 1.2 2002/03/23 02:44:18 obrien Exp $"); + +/* + * _ctx_start((void *func)(int arg1, ..., argn), + * int arg1, ..., argn, ucontext_t *ucp) + * + * 0(%esp) - func + * 4(%esp) - arg1 + * 8(%esp) - arg2 + * ... + * (4*n)(%esp) - argn + * (4*(n + 1))(%esp) - ucp, %ebp setup to point here (base of stack) + */ +ENTRY(_ctx_start) + popl %eax /* get start function */ + call *%eax /* call start function */ + movl %ebp, %esp /* + * setup stack for completion routine; + * ucp is now at top of stack + */ + call _ctx_done /* should never return */ + call abort /* fubar */ + ret diff --git a/src/lib/libc/i386/gen/_setjmp.S b/src/lib/libc/i386/gen/_setjmp.S new file mode 100644 index 0000000..c2fa562 --- /dev/null +++ b/src/lib/libc/i386/gen/_setjmp.S @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)_setjmp.s 5.1 (Berkeley) 4/23/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/_setjmp.S,v 1.16 2002/03/23 02:05:17 obrien Exp $"); + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v)" from the last call to + * _setjmp(a) + * by restoring registers from the environment 'a'. + * The previous signal state is NOT restored. + */ + +ENTRY(_setjmp) + movl 4(%esp),%eax + movl 0(%esp),%edx + movl %edx, 0(%eax) /* rta */ + movl %ebx, 4(%eax) + movl %esp, 8(%eax) + movl %ebp,12(%eax) + movl %esi,16(%eax) + movl %edi,20(%eax) + fnstcw 24(%eax) + xorl %eax,%eax + ret + + .weak CNAME(_longjmp) + .set CNAME(_longjmp),CNAME(___longjmp) +ENTRY(___longjmp) + movl 4(%esp),%edx + movl 8(%esp),%eax + movl 0(%edx),%ecx + movl 4(%edx),%ebx + movl 8(%edx),%esp + movl 12(%edx),%ebp + movl 16(%edx),%esi + movl 20(%edx),%edi + fninit + fldcw 24(%edx) + testl %eax,%eax + jnz 1f + incl %eax +1: movl %ecx,0(%esp) + ret diff --git a/src/lib/libc/i386/gen/alloca.S b/src/lib/libc/i386/gen/alloca.S new file mode 100644 index 0000000..dbf6fb8 --- /dev/null +++ b/src/lib/libc/i386/gen/alloca.S @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(__GNUC__) && !defined(__INTEL_COMPILER) +#error Please add alloca support for this compiler on FreeBSD. + +#if defined(LIBC_SCCS) && !defined(lint) + .asciz "@(#)alloca.s 5.2 (Berkeley) 5/14/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/alloca.S,v 1.12 2003/06/25 19:06:40 obrien Exp $"); + + +/* like alloc, but automatic automatic free in return */ + +ENTRY(alloca) + popl %edx /* pop return addr */ + popl %eax /* pop amount to allocate */ + movl %esp,%ecx + addl $3,%eax /* round up to next word */ + andl $0xfffffffc,%eax + subl %eax,%esp + movl %esp,%eax /* base of newly allocated space */ + pushl 8(%ecx) /* copy possible saved registers */ + pushl 4(%ecx) + pushl 0(%ecx) + pushl %eax /* dummy to pop at callsite */ + jmp *%edx /* "return" */ +#endif /*!__GNUC__*/ diff --git a/src/lib/libc/i386/gen/fabs.S b/src/lib/libc/i386/gen/fabs.S new file mode 100644 index 0000000..4350f18 --- /dev/null +++ b/src/lib/libc/i386/gen/fabs.S @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)fabs.s 5.2 (Berkeley) 12/17/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/fabs.S,v 1.9 2002/03/23 02:44:18 obrien Exp $"); + +ENTRY(fabs) + fldl 4(%esp) + fabs + ret diff --git a/src/lib/libc/i386/gen/frexp.c b/src/lib/libc/i386/gen/frexp.c new file mode 100644 index 0000000..377171c --- /dev/null +++ b/src/lib/libc/i386/gen/frexp.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1991, 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[] = "@(#)frexp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/frexp.c,v 1.8 2002/03/23 02:05:17 obrien Exp $"); + +#include +#include + +double +frexp(value, eptr) + double value; + int *eptr; +{ + union { + double v; + struct { + u_int u_mant2 : 32; + u_int u_mant1 : 20; + u_int u_exp : 11; + u_int u_sign : 1; + } s; + } u; + + if (value) { + u.v = value; + *eptr = u.s.u_exp - 1022; + u.s.u_exp = 1022; + return(u.v); + } else { + *eptr = 0; + return((double)0); + } +} diff --git a/src/lib/libc/i386/gen/infinity.c b/src/lib/libc/i386/gen/infinity.c new file mode 100644 index 0000000..dd54481 --- /dev/null +++ b/src/lib/libc/i386/gen/infinity.c @@ -0,0 +1,14 @@ +/* + * infinity.c + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/infinity.c,v 1.10 2003/02/08 20:37:52 mike Exp $"); + +#include + +/* bytes for +Infinity on a 387 */ +const union __infinity_un __infinity = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } }; + +/* bytes for NaN */ +const union __nan_un __nan = { { 0, 0, 0xc0, 0xff } }; diff --git a/src/lib/libc/i386/gen/isinf.c b/src/lib/libc/i386/gen/isinf.c new file mode 100644 index 0000000..e1116bb --- /dev/null +++ b/src/lib/libc/i386/gen/isinf.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 1991, 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. + */ + +/* For binary compat; to be removed in FreeBSD 6.0. */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/isinf.c,v 1.11 2004/02/16 10:02:39 das Exp $"); + +#include + +struct IEEEdp { + u_int manl : 32; + u_int manh : 20; + u_int exp : 11; + u_int sign : 1; +}; + +int +isnan(d) + double d; +{ + union { + double v; + struct IEEEdp s; + } u; + + u.v = d; + return (u.s.exp == 2047 && (u.s.manh || u.s.manl)); +} + +int +isinf(d) + double d; +{ + union { + double v; + struct IEEEdp s; + } u; + + u.v = d; + return (u.s.exp == 2047 && !u.s.manh && !u.s.manl); +} diff --git a/src/lib/libc/i386/gen/ldexp.c b/src/lib/libc/i386/gen/ldexp.c new file mode 100644 index 0000000..596c8dc --- /dev/null +++ b/src/lib/libc/i386/gen/ldexp.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Sean Eric Fagan. + * + * 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[] = "@(#)ldexp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/ldexp.c,v 1.11 2004/02/16 10:03:02 das Exp $"); + +/* + * ldexp(value, exp): return value * (2 ** exp). + * + * Written by Sean Eric Fagan (sef@kithrup.COM) + * Sun Mar 11 20:27:09 PST 1990 + */ + +/* + * We do the conversion in C to let gcc optimize it away, if possible. + */ +double +ldexp (double value, int exp) +{ + double temp, texp, temp2; + texp = exp; +#ifdef __GNUC__ + __asm ("fscale " + : "=u" (temp2), "=t" (temp) + : "0" (texp), "1" (value)); +#else +#error unknown asm +#endif + return (temp); +} diff --git a/src/lib/libc/i386/gen/makecontext.c b/src/lib/libc/i386/gen/makecontext.c new file mode 100644 index 0000000..d3ceb08 --- /dev/null +++ b/src/lib/libc/i386/gen/makecontext.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2001 Daniel M. Eischen + * 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. Neither the name of the author 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 AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/makecontext.c,v 1.3 2002/09/16 19:24:31 mini Exp $"); + +#include +#include +#include + +#include +#include +#include +#include + +/* Prototypes */ +extern void _ctx_start(ucontext_t *, int argc, ...); + + +__weak_reference(__makecontext, makecontext); + +void +_ctx_done (ucontext_t *ucp) +{ + if (ucp->uc_link == NULL) + exit(0); + else { + /* + * Since this context has finished, don't allow it + * to be restarted without being reinitialized (via + * setcontext or swapcontext). + */ + ucp->uc_mcontext.mc_len = 0; + + /* Set context to next one in link */ + /* XXX - what to do for error, abort? */ + setcontext((const ucontext_t *)ucp->uc_link); + abort(); /* should never get here */ + } +} + +void +__makecontext(ucontext_t *ucp, void (*start)(void), int argc, ...) +{ + va_list ap; + char *stack_top; + intptr_t *argp; + int i; + + if (ucp == NULL) + return; + else if ((ucp->uc_stack.ss_sp == NULL) || + (ucp->uc_stack.ss_size < MINSIGSTKSZ)) { + /* + * This should really return -1 with errno set to ENOMEM + * or something, but the spec says that makecontext is + * a void function. At least make sure that the context + * isn't valid so it can't be used without an error. + */ + ucp->uc_mcontext.mc_len = 0; + } + /* XXX - Do we want to sanity check argc? */ + else if ((argc < 0) || (argc > NCARGS)) { + ucp->uc_mcontext.mc_len = 0; + } + /* Make sure the context is valid. */ + else if (ucp->uc_mcontext.mc_len == sizeof(mcontext_t)) { + /* + * Arrange the stack as follows: + * + * _ctx_start() - context start wrapper + * start() - user start routine + * arg1 + * ... + * argn + * ucp - this context, %ebp points here + * + * When the context is started, control will return to + * the context start wrapper which will pop the user + * start routine from the top of the stack. After that, + * the top of the stack will be setup with all arguments + * necessary for calling the start routine. When the + * start routine returns, the context wrapper then sets + * the stack pointer to %ebp which was setup to point to + * the base of the stack (and where ucp is stored). It + * will then call _ctx_done() to swap in the next context + * (uc_link != 0) or exit the program (uc_link == 0). + */ + stack_top = (char *)(ucp->uc_stack.ss_sp + + ucp->uc_stack.ss_size - sizeof(double)); + stack_top = (char *)ALIGN(stack_top); + + /* + * Adjust top of stack to allow for 3 pointers (return + * address, _ctx_start, and ucp) and argc arguments. + * We allow the arguments to be pointers also. + */ + stack_top = stack_top - (sizeof(intptr_t) * (3 + argc)); + argp = (intptr_t *)stack_top; + + /* + * Setup the top of the stack with the user start routine + * followed by all of its aguments and the pointer to the + * ucontext. We need to leave a spare spot at the top of + * the stack because setcontext will move eip to the top + * of the stack before returning. + */ + *argp = (intptr_t)_ctx_start; /* overwritten with same value */ + argp++; + *argp = (intptr_t)start; + argp++; + + /* Add all the arguments: */ + va_start(ap, argc); + for (i = 0; i < argc; i++) { + *argp = va_arg(ap, intptr_t); + argp++; + } + va_end(ap); + + /* The ucontext is placed at the bottom of the stack. */ + *argp = (intptr_t)ucp; + + /* + * Set the machine context to point to the top of the + * stack and the program counter to the context start + * wrapper. Note that setcontext() pushes the return + * address onto the top of the stack, so allow for this + * by adjusting the stack downward 1 slot. Also set + * %ebp to point to the base of the stack where ucp + * is stored. + */ + ucp->uc_mcontext.mc_ebp = (int)argp; + ucp->uc_mcontext.mc_esp = (int)stack_top + sizeof(caddr_t); + ucp->uc_mcontext.mc_eip = (int)_ctx_start; + } +} diff --git a/src/lib/libc/i386/gen/modf.S b/src/lib/libc/i386/gen/modf.S new file mode 100644 index 0000000..de7c96a --- /dev/null +++ b/src/lib/libc/i386/gen/modf.S @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Sean Eric Fagan. + * + * 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) + .asciz "@(#)modf.s 5.5 (Berkeley) 3/18/91" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/modf.S,v 1.9 2002/03/23 02:05:17 obrien Exp $"); + +/* + * modf(value, iptr): return fractional part of value, and stores the + * integral part into iptr (a pointer to double). + * + * Written by Sean Eric Fagan (sef@kithrup.COM) + * Sun Mar 11 20:27:30 PST 1990 + */ + +/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ + +ENTRY(modf) + pushl %ebp + movl %esp,%ebp + subl $16,%esp + fnstcw -12(%ebp) + movw -12(%ebp),%dx + orw $3072,%dx + movw %dx,-16(%ebp) + fldcw -16(%ebp) + fldl 8(%ebp) + frndint + fstpl -8(%ebp) + fldcw -12(%ebp) + movl 16(%ebp),%eax + movl -8(%ebp),%edx + movl -4(%ebp),%ecx + movl %edx,(%eax) + movl %ecx,4(%eax) + fldl 8(%ebp) + fsubl -8(%ebp) + jmp L1 +L1: + leave + ret diff --git a/src/lib/libc/i386/gen/rfork_thread.S b/src/lib/libc/i386/gen/rfork_thread.S new file mode 100644 index 0000000..04ad549 --- /dev/null +++ b/src/lib/libc/i386/gen/rfork_thread.S @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2000 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/rfork_thread.S,v 1.5 2003/05/07 17:23:25 jhb Exp $"); + +/* + * With thanks to John Dyson for the original version of this. + */ + +#include + +/* + * 8 12 16 20 + * rfork_thread(flags, stack_addr, start_fnc, start_arg); + * + * flags: Flags to rfork system call. See rfork(2). + * stack_addr: Top of stack for thread. + * start_fnc: Address of thread function to call in child. + * start_arg: Argument to pass to the thread function in child. + */ + +ENTRY(rfork_thread) + pushl %ebp + movl %esp, %ebp + pushl %esi + + /* + * Push thread info onto the new thread's stack + */ + movl 12(%ebp), %esi # get stack addr + + subl $4, %esi + movl 20(%ebp), %eax # get start argument + movl %eax, (%esi) + + subl $4, %esi + movl 16(%ebp), %eax # get start thread address + movl %eax, (%esi) + + /* + * Prepare and execute the thread creation syscall + */ + pushl 8(%ebp) + pushl $0 + movl $SYS_rfork, %eax + KERNCALL + jb 2f + + /* + * Check to see if we are in the parent or child + */ + cmpl $0, %edx + jnz 1f + addl $8, %esp + popl %esi + movl %ebp, %esp + popl %ebp + ret + .p2align 2 + + /* + * If we are in the child (new thread), then + * set-up the call to the internal subroutine. If it + * returns, then call __exit. + */ +1: + movl %esi,%esp + popl %eax + call *%eax + addl $4, %esp + + /* + * Exit system call + */ + pushl %eax + pushl $0 +#ifdef SYS_exit + movl $SYS_exit, %eax +#else + movl $SYS_sys_exit, %eax +#endif + KERNCALL + + /* + * Branch here if the thread creation fails: + */ +2: + addl $8, %esp + popl %esi + movl %ebp, %esp + popl %ebp + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) diff --git a/src/lib/libc/i386/gen/setjmp.S b/src/lib/libc/i386/gen/setjmp.S new file mode 100644 index 0000000..89c2b56 --- /dev/null +++ b/src/lib/libc/i386/gen/setjmp.S @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)setjmp.s 5.1 (Berkeley) 4/23/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/setjmp.S,v 1.22 2002/03/23 02:05:17 obrien Exp $"); + +/* + * C library -- _setjmp, _longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from the last call to + * setjmp(a) + * by restoring registers from the environment 'a'. + * The previous signal state is restored. + */ + +#include "SYS.h" + +ENTRY(setjmp) + movl 4(%esp),%ecx + PIC_PROLOGUE + leal 28(%ecx), %eax + pushl %eax /* (sigset_t*)oset */ + pushl $0 /* (sigset_t*)set */ + pushl $1 /* SIG_BLOCK */ + call PIC_PLT(CNAME(_sigprocmask)) + addl $12,%esp + PIC_EPILOGUE + movl 4(%esp),%ecx + movl 0(%esp),%edx + movl %edx, 0(%ecx) + movl %ebx, 4(%ecx) + movl %esp, 8(%ecx) + movl %ebp,12(%ecx) + movl %esi,16(%ecx) + movl %edi,20(%ecx) + fnstcw 24(%ecx) + xorl %eax,%eax + ret + + .weak CNAME(longjmp) + .set CNAME(longjmp),CNAME(__longjmp) +ENTRY(__longjmp) + movl 4(%esp),%edx + PIC_PROLOGUE + pushl $0 /* (sigset_t*)oset */ + leal 28(%edx), %eax + pushl %eax /* (sigset_t*)set */ + pushl $3 /* SIG_SETMASK */ + call PIC_PLT(CNAME(_sigprocmask)) + addl $12,%esp + PIC_EPILOGUE + movl 4(%esp),%edx + movl 8(%esp),%eax + movl 0(%edx),%ecx + movl 4(%edx),%ebx + movl 8(%edx),%esp + movl 12(%edx),%ebp + movl 16(%edx),%esi + movl 20(%edx),%edi + fninit + fldcw 24(%edx) + testl %eax,%eax + jnz 1f + incl %eax +1: movl %ecx,0(%esp) + ret diff --git a/src/lib/libc/i386/gen/signalcontext.c b/src/lib/libc/i386/gen/signalcontext.c new file mode 100644 index 0000000..ebeecad --- /dev/null +++ b/src/lib/libc/i386/gen/signalcontext.c @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 2002 Jonathan Mini + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/signalcontext.c,v 1.6 2004/02/10 20:42:32 cperciva Exp $"); + +#include +#include +#include +#include +#include +#include + +__weak_reference(__signalcontext, signalcontext); + +extern void _ctx_start(ucontext_t *, int argc, ...); + +int +__signalcontext(ucontext_t *ucp, int sig, __sighandler_t *func) +{ + register_t *p; + struct sigframe *sfp; + + /*- + * Set up stack. + * (n = sizeof(int)) + * 2n+sizeof(struct sigframe) ucp + * 2n struct sigframe + * 1n &func + * 0n &_ctx_start + */ + p = (register_t *)(void *)(intptr_t)ucp->uc_mcontext.mc_esp; + *--p = (register_t)(intptr_t)ucp; + p = (register_t *)((u_register_t)p & ~0xF); /* Align to 16 bytes. */ + p = (register_t *)((u_register_t)p - sizeof(struct sigframe)); + sfp = (struct sigframe *)p; + bzero(sfp, sizeof(struct sigframe)); + sfp->sf_signum = sig; + sfp->sf_siginfo = (register_t)(intptr_t)&sfp->sf_si; + sfp->sf_ucontext = (register_t)(intptr_t)&sfp->sf_uc; + sfp->sf_ahu.sf_action = (__siginfohandler_t *)func; + bcopy(ucp, &sfp->sf_uc, sizeof(ucontext_t)); + sfp->sf_si.si_signo = sig; + *--p = (register_t)(intptr_t)func; + + /* + * Set up ucontext_t. + */ + ucp->uc_mcontext.mc_ebp = ucp->uc_mcontext.mc_esp - sizeof(int); + ucp->uc_mcontext.mc_esp = (register_t)(intptr_t)p; + ucp->uc_mcontext.mc_eip = (register_t)(intptr_t)_ctx_start; + ucp->uc_mcontext.mc_eflags &= ~PSL_T; + ucp->uc_link = &sfp->sf_uc; + sigdelset(&ucp->uc_sigmask, sig); + return (0); +} diff --git a/src/lib/libc/i386/gen/sigsetjmp.S b/src/lib/libc/i386/gen/sigsetjmp.S new file mode 100644 index 0000000..e376b60 --- /dev/null +++ b/src/lib/libc/i386/gen/sigsetjmp.S @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * + * @(#)setjmp.s 5.1 (Berkeley) 4/23/90" + */ + +#if defined(LIBC_SCCS) && !defined(lint) + .text + .asciz "$Id$" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/gen/sigsetjmp.S,v 1.24 2002/03/23 02:05:19 obrien Exp $"); + +#include "SYS.h" + +/*- + * TODO: + * Rename sigsetjmp to __sigsetjmp and siglongjmp to __siglongjmp, + * remove the other *jmp functions and define everything in terms + * of the renamed functions. This requires compiler support for + * the renamed functions (introduced in gcc-2.5.3; previous versions + * only supported *jmp with 0 or 1 leading underscores). + * + * Restore _all_ the registers and the signal mask atomically. Can + * use sigreturn() if sigreturn() works. + */ + +ENTRY(sigsetjmp) + movl 8(%esp),%eax + movl 4(%esp),%ecx + movl %eax,44(%ecx) + testl %eax,%eax + jz 2f + PIC_PROLOGUE + leal 28(%ecx), %eax + pushl %eax /* (sigset_t*)oset */ + pushl $0 /* (sigset_t*)set */ + pushl $1 /* SIG_BLOCK */ + call PIC_PLT(CNAME(_sigprocmask)) + addl $12,%esp + PIC_EPILOGUE + movl 4(%esp),%ecx +2: movl 0(%esp),%edx + movl %edx, 0(%ecx) + movl %ebx, 4(%ecx) + movl %esp, 8(%ecx) + movl %ebp,12(%ecx) + movl %esi,16(%ecx) + movl %edi,20(%ecx) + fnstcw 24(%ecx) + xorl %eax,%eax + ret + + .weak CNAME(siglongjmp); + .set CNAME(siglongjmp),CNAME(__siglongjmp); +ENTRY(__siglongjmp); + movl 4(%esp),%edx + cmpl $0,44(%edx) + jz 2f + PIC_PROLOGUE + pushl $0 /* (sigset_t*)oset */ + leal 28(%edx), %eax + pushl %eax /* (sigset_t*)set */ + pushl $3 /* SIG_SETMASK */ + call PIC_PLT(CNAME(_sigprocmask)) + addl $12,%esp + PIC_EPILOGUE + movl 4(%esp),%edx +2: movl 8(%esp),%eax + movl 0(%edx),%ecx + movl 4(%edx),%ebx + movl 8(%edx),%esp + movl 12(%edx),%ebp + movl 16(%edx),%esi + movl 20(%edx),%edi + fninit + fldcw 24(%edx) + testl %eax,%eax + jnz 1f + incl %eax +1: movl %ecx,0(%esp) + ret diff --git a/src/lib/libc/i386/net/Makefile.inc b/src/lib/libc/i386/net/Makefile.inc new file mode 100644 index 0000000..6878644 --- /dev/null +++ b/src/lib/libc/i386/net/Makefile.inc @@ -0,0 +1,4 @@ +# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/i386/net/Makefile.inc,v 1.6 1999/08/27 23:59:24 peter Exp $ + +SRCS+= htonl.S htons.S ntohl.S ntohs.S diff --git a/src/lib/libc/i386/net/htonl.S b/src/lib/libc/i386/net/htonl.S new file mode 100644 index 0000000..ab45c86 --- /dev/null +++ b/src/lib/libc/i386/net/htonl.S @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)htonl.s 5.3 (Berkeley) 12/17/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/net/htonl.S,v 1.9 2002/03/23 02:06:08 obrien Exp $"); + +/* netorder = htonl(hostorder) */ + + .weak CNAME(htonl) + .set CNAME(htonl),CNAME(__htonl) +ENTRY(__htonl) + movl 4(%esp),%eax + xchgb %al,%ah + roll $16,%eax + xchgb %al,%ah + ret diff --git a/src/lib/libc/i386/net/htons.S b/src/lib/libc/i386/net/htons.S new file mode 100644 index 0000000..37b92a6 --- /dev/null +++ b/src/lib/libc/i386/net/htons.S @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)htons.s 5.2 (Berkeley) 12/17/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/net/htons.S,v 1.9 2002/03/23 02:06:08 obrien Exp $"); + +/* netorder = htons(hostorder) */ + + .weak CNAME(htons) + .set CNAME(htons),CNAME(__htons) +ENTRY(__htons) + movzwl 4(%esp),%eax + xchgb %al,%ah + ret diff --git a/src/lib/libc/i386/net/ntohl.S b/src/lib/libc/i386/net/ntohl.S new file mode 100644 index 0000000..6622d77 --- /dev/null +++ b/src/lib/libc/i386/net/ntohl.S @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)ntohl.s 5.2 (Berkeley) 12/17/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/net/ntohl.S,v 1.9 2002/03/23 02:06:08 obrien Exp $"); + +/* hostorder = ntohl(netorder) */ + + .weak CNAME(ntohl) + .set CNAME(ntohl),CNAME(__ntohl) +ENTRY(__ntohl) + movl 4(%esp),%eax + xchgb %al,%ah + roll $16,%eax + xchgb %al,%ah + ret diff --git a/src/lib/libc/i386/net/ntohs.S b/src/lib/libc/i386/net/ntohs.S new file mode 100644 index 0000000..676b3ea --- /dev/null +++ b/src/lib/libc/i386/net/ntohs.S @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)ntohs.s 5.2 (Berkeley) 12/17/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/net/ntohs.S,v 1.9 2002/03/23 02:06:08 obrien Exp $"); + +/* hostorder = ntohs(netorder) */ + +#include + + .weak CNAME(ntohs) + .set CNAME(ntohs),CNAME(__ntohs) +ENTRY(__ntohs) + movzwl 4(%esp),%eax + xchgb %al,%ah + ret diff --git a/src/lib/libc/i386/stdlib/Makefile.inc b/src/lib/libc/i386/stdlib/Makefile.inc new file mode 100644 index 0000000..1bb5c21 --- /dev/null +++ b/src/lib/libc/i386/stdlib/Makefile.inc @@ -0,0 +1,4 @@ +# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/i386/stdlib/Makefile.inc,v 1.7 1999/08/27 23:59:26 peter Exp $ + +MDSRCS+=abs.S div.S labs.S ldiv.S diff --git a/src/lib/libc/i386/stdlib/abs.S b/src/lib/libc/i386/stdlib/abs.S new file mode 100644 index 0000000..31d7531 --- /dev/null +++ b/src/lib/libc/i386/stdlib/abs.S @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .text + .asciz "@(#)abs.s 5.2 (Berkeley) 12/17/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/stdlib/abs.S,v 1.9 2002/03/23 02:07:11 obrien Exp $"); + + +ENTRY(abs) + movl 4(%esp),%eax + testl %eax,%eax + jns 1f + negl %eax +1: ret diff --git a/src/lib/libc/i386/stdlib/div.S b/src/lib/libc/i386/stdlib/div.S new file mode 100644 index 0000000..383b31f --- /dev/null +++ b/src/lib/libc/i386/stdlib/div.S @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/stdlib/div.S,v 1.10 2002/12/22 06:41:09 kan Exp $"); + +ENTRY(div) + movl 4(%esp),%eax + movl 8(%esp),%ecx + cdq + idiv %ecx + movl %eax,4(%esp) + movl %edx,8(%esp) + ret diff --git a/src/lib/libc/i386/stdlib/gdtoa.mk b/src/lib/libc/i386/stdlib/gdtoa.mk new file mode 100644 index 0000000..3468989 --- /dev/null +++ b/src/lib/libc/i386/stdlib/gdtoa.mk @@ -0,0 +1,5 @@ +# $FreeBSD: src/lib/libc/i386/stdlib/gdtoa.mk,v 1.1 2003/03/12 20:29:59 das Exp $ + +# Long double is 80 bits +GDTOASRCS+=strtopx.c +MDSRCS+=machdep_ldisx.c diff --git a/src/lib/libc/i386/stdlib/labs.S b/src/lib/libc/i386/stdlib/labs.S new file mode 100644 index 0000000..3268520 --- /dev/null +++ b/src/lib/libc/i386/stdlib/labs.S @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .text + .asciz "@(#)abs.s 5.2 (Berkeley) 12/17/90" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/stdlib/labs.S,v 1.9 2002/03/23 02:07:11 obrien Exp $"); + + +ENTRY(labs) + movl 4(%esp),%eax + testl %eax,%eax + jns 1f + negl %eax +1: ret diff --git a/src/lib/libc/i386/stdlib/ldiv.S b/src/lib/libc/i386/stdlib/ldiv.S new file mode 100644 index 0000000..91e132a --- /dev/null +++ b/src/lib/libc/i386/stdlib/ldiv.S @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/stdlib/ldiv.S,v 1.10 2002/12/22 06:41:09 kan Exp $"); + +ENTRY(ldiv) + movl 4(%esp),%eax + movl 8(%esp),%ecx + cdq + idiv %ecx + movl %eax,4(%esp) + movl %edx,8(%esp) + ret diff --git a/src/lib/libc/i386/string/Makefile.inc b/src/lib/libc/i386/string/Makefile.inc new file mode 100644 index 0000000..753cc98 --- /dev/null +++ b/src/lib/libc/i386/string/Makefile.inc @@ -0,0 +1,7 @@ +# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 +# $FreeBSD: src/lib/libc/i386/string/Makefile.inc,v 1.13 2003/04/05 04:17:05 tjr Exp $ + +MDSRCS+=bcmp.S bcopy.S bzero.S ffs.S index.S memchr.S memcmp.S memcpy.S \ + memmove.S memset.S rindex.S strcat.S strchr.S strcmp.S strcpy.S \ + strlen.S strncmp.S strrchr.S swab.S wcschr.S wcscmp.S wcslen.S \ + wmemchr.S diff --git a/src/lib/libc/i386/string/bcmp.S b/src/lib/libc/i386/string/bcmp.S new file mode 100644 index 0000000..b8fe604 --- /dev/null +++ b/src/lib/libc/i386/string/bcmp.S @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/bcmp.S,v 1.8 2002/03/23 02:44:19 obrien Exp $"); + +/* + * bcmp (void *b1, void *b2, size_t len) + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(bcmp) + pushl %edi + pushl %esi + movl 12(%esp),%edi + movl 16(%esp),%esi + xorl %eax,%eax /* clear return value */ + cld /* set compare direction forward */ + + movl 20(%esp),%ecx /* compare by words */ + shrl $2,%ecx + repe + cmpsl + jne L1 + + movl 20(%esp),%ecx /* compare remainder by bytes */ + andl $3,%ecx + repe + cmpsb + je L2 + +L1: incl %eax +L2: popl %esi + popl %edi + ret diff --git a/src/lib/libc/i386/string/bcopy.S b/src/lib/libc/i386/string/bcopy.S new file mode 100644 index 0000000..be2f9f4 --- /dev/null +++ b/src/lib/libc/i386/string/bcopy.S @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from locore.s. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/bcopy.S,v 1.10 2002/10/15 09:50:07 sobomax Exp $"); + +#if 0 + RCSID("$NetBSD: bcopy.S,v 1.6 1996/11/12 00:50:06 jtc Exp $") +#endif + + /* + * (ov)bcopy (src,dst,cnt) + * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 + */ + +#ifdef MEMCOPY +ENTRY(memcpy) +#else +#ifdef MEMMOVE +ENTRY(memmove) +#else +ENTRY(bcopy) +#endif +#endif + pushl %esi + pushl %edi +#if defined(MEMCOPY) || defined(MEMMOVE) + movl 12(%esp),%edi + movl 16(%esp),%esi + movl %edi,%eax +#else + movl 12(%esp),%esi + movl 16(%esp),%edi +#endif + movl 20(%esp),%ecx + movl %edi,%edx + subl %esi,%edx + cmpl %ecx,%edx /* overlapping? */ + jb 1f + cld /* nope, copy forwards. */ + movl %ecx,%edx + shrl $2,%ecx /* copy by words */ + rep + movsl + movl %edx,%ecx + andl $3,%ecx /* any bytes left? */ + rep + movsb + popl %edi + popl %esi + ret +1: + addl %ecx,%edi /* copy backwards. */ + addl %ecx,%esi + std + movl %ecx,%edx + andl $3,%ecx /* any fractional bytes? */ + decl %edi + decl %esi + rep + movsb + movl %edx,%ecx /* copy remainder by words */ + shrl $2,%ecx + subl $3,%esi + subl $3,%edi + rep + movsl + popl %edi + popl %esi + cld + ret diff --git a/src/lib/libc/i386/string/bzero.S b/src/lib/libc/i386/string/bzero.S new file mode 100644 index 0000000..fb84201 --- /dev/null +++ b/src/lib/libc/i386/string/bzero.S @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/bzero.S,v 1.9 2002/06/02 20:05:36 schweikh Exp $"); + +/* + * bzero (void *b, size_t len) + * write len zero bytes to the string b. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(bzero) + pushl %edi + pushl %ebx + movl 12(%esp),%edi + movl 16(%esp),%ecx + + cld /* set fill direction forward */ + xorl %eax,%eax /* set fill data to 0 */ + + /* + * if the string is too short, it's really not worth the overhead + * of aligning to word boundries, etc. So we jump to a plain + * unaligned set. + */ + cmpl $0x0f,%ecx + jle L1 + + movl %edi,%edx /* compute misalignment */ + negl %edx + andl $3,%edx + movl %ecx,%ebx + subl %edx,%ebx + + movl %edx,%ecx /* zero until word aligned */ + rep + stosb + + movl %ebx,%ecx /* zero by words */ + shrl $2,%ecx + rep + stosl + + movl %ebx,%ecx + andl $3,%ecx /* zero remainder by bytes */ +L1: rep + stosb + + popl %ebx + popl %edi + ret diff --git a/src/lib/libc/i386/string/ffs.S b/src/lib/libc/i386/string/ffs.S new file mode 100644 index 0000000..b64411d --- /dev/null +++ b/src/lib/libc/i386/string/ffs.S @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/ffs.S,v 1.9 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * ffs(value) + * finds the first bit set in value and returns the index of + * that bit. Bits are numbered starting from 1, starting at the + * rightmost bit. A return value of 0 means that the argument + * was zero. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(ffs) + bsfl 4(%esp),%eax + jz L1 /* ZF is set if all bits are 0 */ + incl %eax /* bits numbered from 1, not 0 */ + ret + + .align 2 +L1: xorl %eax,%eax /* clear result */ + ret diff --git a/src/lib/libc/i386/string/index.S b/src/lib/libc/i386/string/index.S new file mode 100644 index 0000000..4bdde08 --- /dev/null +++ b/src/lib/libc/i386/string/index.S @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/index.S,v 1.9 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * index(s, c) + * return a pointer to the first occurance of the character c in + * string s, or NULL if c does not occur in the string. + * + * %edx - pointer iterating through string + * %eax - pointer to first occurance of 'c' + * %cl - character we're comparing against + * %bl - character at %edx + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(index) + pushl %ebx + movl 8(%esp),%eax + movb 12(%esp),%cl + .align 2,0x90 +L1: + movb (%eax),%bl + cmpb %bl,%cl /* found char??? */ + je L2 + incl %eax + testb %bl,%bl /* null terminator??? */ + jne L1 + xorl %eax,%eax +L2: + popl %ebx + ret diff --git a/src/lib/libc/i386/string/memchr.S b/src/lib/libc/i386/string/memchr.S new file mode 100644 index 0000000..5f4951a --- /dev/null +++ b/src/lib/libc/i386/string/memchr.S @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/memchr.S,v 1.12 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * memchr (b, c, len) + * locates the first occurance of c in string b. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(memchr) + pushl %edi + movl 8(%esp),%edi /* string address */ + movl 12(%esp),%eax /* set character to search for */ + movl 16(%esp),%ecx /* set length of search */ + testl %esp,%esp /* clear Z flag, for len == 0 */ + cld /* set search forward */ + repne /* search! */ + scasb + jnz L1 /* scan failed, return null */ + leal -1(%edi),%eax /* adjust result of scan */ + popl %edi + ret + .align 2,0x90 +L1: xorl %eax,%eax + popl %edi + ret diff --git a/src/lib/libc/i386/string/memcmp.S b/src/lib/libc/i386/string/memcmp.S new file mode 100644 index 0000000..27c479c --- /dev/null +++ b/src/lib/libc/i386/string/memcmp.S @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/memcmp.S,v 1.8 2002/03/23 02:44:19 obrien Exp $"); + +/* + * memcmp (void *b1, void *b2, size_t len) + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(memcmp) + pushl %edi + pushl %esi + movl 12(%esp),%edi + movl 16(%esp),%esi + cld /* set compare direction forward */ + + movl 20(%esp),%ecx /* compare by words */ + shrl $2,%ecx + repe + cmpsl + jne L5 /* do we match so far? */ + + movl 20(%esp),%ecx /* compare remainder by bytes */ + andl $3,%ecx + repe + cmpsb + jne L6 /* do we match? */ + + xorl %eax,%eax /* we match, return zero */ + popl %esi + popl %edi + ret + +L5: movl $4,%ecx /* We know that one of the next */ + subl %ecx,%edi /* four pairs of bytes do not */ + subl %ecx,%esi /* match. */ + repe + cmpsb +L6: movzbl -1(%edi),%eax /* Perform unsigned comparison */ + movzbl -1(%esi),%edx + subl %edx,%eax + popl %esi + popl %edi + ret diff --git a/src/lib/libc/i386/string/memcpy.S b/src/lib/libc/i386/string/memcpy.S new file mode 100644 index 0000000..5102bc7 --- /dev/null +++ b/src/lib/libc/i386/string/memcpy.S @@ -0,0 +1,5 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/memcpy.S,v 1.2 2002/03/23 02:44:19 obrien Exp $"); + +#define MEMCOPY +#include "bcopy.S" diff --git a/src/lib/libc/i386/string/memmove.S b/src/lib/libc/i386/string/memmove.S new file mode 100644 index 0000000..42b5263 --- /dev/null +++ b/src/lib/libc/i386/string/memmove.S @@ -0,0 +1,5 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/memmove.S,v 1.7 2002/03/23 02:44:19 obrien Exp $"); + +#define MEMMOVE +#include "bcopy.S" diff --git a/src/lib/libc/i386/string/memset.S b/src/lib/libc/i386/string/memset.S new file mode 100644 index 0000000..27eca36 --- /dev/null +++ b/src/lib/libc/i386/string/memset.S @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/memset.S,v 1.8 2002/03/23 02:44:19 obrien Exp $"); + +/* + * memset(void *b, int c, size_t len) + * write len bytes of value c (converted to an unsigned char) to + * the string b. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(memset) + pushl %edi + pushl %ebx + movl 12(%esp),%edi + movzbl 16(%esp),%eax /* unsigned char, zero extend */ + movl 20(%esp),%ecx + pushl %edi /* push address of buffer */ + + cld /* set fill direction forward */ + + /* + * if the string is too short, it's really not worth the overhead + * of aligning to word boundries, etc. So we jump to a plain + * unaligned set. + */ + cmpl $0x0f,%ecx + jle L1 + + movb %al,%ah /* copy char to all bytes in word */ + movl %eax,%edx + sall $16,%eax + orl %edx,%eax + + movl %edi,%edx /* compute misalignment */ + negl %edx + andl $3,%edx + movl %ecx,%ebx + subl %edx,%ebx + + movl %edx,%ecx /* set until word aligned */ + rep + stosb + + movl %ebx,%ecx + shrl $2,%ecx /* set by words */ + rep + stosl + + movl %ebx,%ecx /* set remainder by bytes */ + andl $3,%ecx +L1: rep + stosb + + popl %eax /* pop address of buffer */ + popl %ebx + popl %edi + ret diff --git a/src/lib/libc/i386/string/rindex.S b/src/lib/libc/i386/string/rindex.S new file mode 100644 index 0000000..c76cf8f --- /dev/null +++ b/src/lib/libc/i386/string/rindex.S @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/rindex.S,v 1.9 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * rindex(s, c) + * return a pointer to the last occurance of the character c in + * string s, or NULL if c does not occur in the string. + * + * %edx - pointer iterating through string + * %eax - pointer to last occurance of 'c' + * %cl - character we're comparing against + * %bl - character at %edx + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(rindex) + pushl %ebx + movl 8(%esp),%edx + movb 12(%esp),%cl + xorl %eax,%eax /* init pointer to null */ + .align 2,0x90 +L1: + movb (%edx),%bl + cmpb %bl,%cl + jne L2 + movl %edx,%eax +L2: + incl %edx + testb %bl,%bl /* null terminator??? */ + jne L1 + popl %ebx + ret diff --git a/src/lib/libc/i386/string/strcat.S b/src/lib/libc/i386/string/strcat.S new file mode 100644 index 0000000..a175d5b --- /dev/null +++ b/src/lib/libc/i386/string/strcat.S @@ -0,0 +1,100 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/strcat.S,v 1.10 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * strcat(s, append) + * append a copy of the null-terminated string "append" to the end + * of the null-terminated string s, then add a terminating `\0'. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +/* + * I've unrolled the loop eight times: large enough to make a + * significant difference, and small enough not to totally trash the + * cache. + */ + +ENTRY(strcat) + pushl %edi /* save edi */ + movl 8(%esp),%edi /* dst address */ + movl 12(%esp),%edx /* src address */ + pushl %edi /* push destination address */ + + cld /* set search forward */ + xorl %eax,%eax /* set search for null terminator */ + movl $-1,%ecx /* set search for lots of characters */ + repne /* search! */ + scasb + + leal -1(%edi),%ecx /* correct dst address */ + + .align 2,0x90 +L1: movb (%edx),%al /* unroll loop, but not too much */ + movb %al,(%ecx) + testb %al,%al + je L2 + movb 1(%edx),%al + movb %al,1(%ecx) + testb %al,%al + je L2 + movb 2(%edx),%al + movb %al,2(%ecx) + testb %al,%al + je L2 + movb 3(%edx),%al + movb %al,3(%ecx) + testb %al,%al + je L2 + movb 4(%edx),%al + movb %al,4(%ecx) + testb %al,%al + je L2 + movb 5(%edx),%al + movb %al,5(%ecx) + testb %al,%al + je L2 + movb 6(%edx),%al + movb %al,6(%ecx) + testb %al,%al + je L2 + movb 7(%edx),%al + movb %al,7(%ecx) + addl $8,%edx + addl $8,%ecx + testb %al,%al + jne L1 +L2: popl %eax /* pop destination address */ + popl %edi /* restore edi */ + ret diff --git a/src/lib/libc/i386/string/strchr.S b/src/lib/libc/i386/string/strchr.S new file mode 100644 index 0000000..87d4fda --- /dev/null +++ b/src/lib/libc/i386/string/strchr.S @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/strchr.S,v 1.9 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * strchr(s, c) + * return a pointer to the first occurance of the character c in + * string s, or NULL if c does not occur in the string. + * + * %edx - pointer iterating through string + * %eax - pointer to first occurance of 'c' + * %cl - character we're comparing against + * %bl - character at %edx + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(strchr) + pushl %ebx + movl 8(%esp),%eax + movb 12(%esp),%cl + .align 2,0x90 +L1: + movb (%eax),%bl + cmpb %bl,%cl /* found char??? */ + je L2 + incl %eax + testb %bl,%bl /* null terminator??? */ + jne L1 + xorl %eax,%eax +L2: + popl %ebx + ret diff --git a/src/lib/libc/i386/string/strcmp.S b/src/lib/libc/i386/string/strcmp.S new file mode 100644 index 0000000..6e98893 --- /dev/null +++ b/src/lib/libc/i386/string/strcmp.S @@ -0,0 +1,119 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/strcmp.S,v 1.10 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * strcmp(s1, s2) + * return an integer greater than, equal to, or less than 0, + * according as string s1 is greater than, equal to, or less + * than the string s2. + * + * %eax - pointer to s1 + * %edx - pointer to s2 + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +/* + * I've unrolled the loop eight times: large enough to make a + * significant difference, and small enough not to totally trash the + * cache. + */ + +ENTRY(strcmp) + movl 0x04(%esp),%eax + movl 0x08(%esp),%edx + jmp L2 /* Jump into the loop! */ + + .align 2,0x90 +L1: incl %eax + incl %edx +L2: movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + jne L3 + incl %eax + incl %edx + movb (%eax),%cl + testb %cl,%cl + je L3 + cmpb %cl,(%edx) + je L1 + .align 2, 0x90 +L3: movzbl (%eax),%eax /* unsigned comparison */ + movzbl (%edx),%edx + subl %edx,%eax + ret diff --git a/src/lib/libc/i386/string/strcpy.S b/src/lib/libc/i386/string/strcpy.S new file mode 100644 index 0000000..237175a --- /dev/null +++ b/src/lib/libc/i386/string/strcpy.S @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/strcpy.S,v 1.10 2002/06/02 20:05:37 schweikh Exp $"); + +/* + * strcpy (dst, src) + * copy the string src to dst. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +/* + * I've unrolled the loop eight times: large enough to make a + * significant difference, and small enough not to totally trash the + * cache. + */ + +ENTRY(strcpy) + movl 4(%esp),%ecx /* dst address */ + movl 8(%esp),%edx /* src address */ + pushl %ecx /* push dst address */ + + .align 2,0x90 +L1: movb (%edx),%al /* unroll loop, but not too much */ + movb %al,(%ecx) + testb %al,%al + je L2 + movb 1(%edx),%al + movb %al,1(%ecx) + testb %al,%al + je L2 + movb 2(%edx),%al + movb %al,2(%ecx) + testb %al,%al + je L2 + movb 3(%edx),%al + movb %al,3(%ecx) + testb %al,%al + je L2 + movb 4(%edx),%al + movb %al,4(%ecx) + testb %al,%al + je L2 + movb 5(%edx),%al + movb %al,5(%ecx) + testb %al,%al + je L2 + movb 6(%edx),%al + movb %al,6(%ecx) + testb %al,%al + je L2 + movb 7(%edx),%al + movb %al,7(%ecx) + addl $8,%edx + addl $8,%ecx + testb %al,%al + jne L1 +L2: popl %eax /* pop dst address */ + ret diff --git a/src/lib/libc/i386/string/strlen.S b/src/lib/libc/i386/string/strlen.S new file mode 100644 index 0000000..3f4ee5b --- /dev/null +++ b/src/lib/libc/i386/string/strlen.S @@ -0,0 +1,53 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/strlen.S,v 1.9 2002/06/02 20:05:38 schweikh Exp $"); + +/* + * strlen (s) + * compute the length of the string s. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(strlen) + pushl %edi + movl 8(%esp),%edi /* string address */ + cld /* set search forward */ + xorl %eax,%eax /* set search for null terminator */ + movl $-1,%ecx /* set search for lots of characters */ + repne /* search! */ + scasb + notl %ecx /* get length by taking complement */ + leal -1(%ecx),%eax /* and subtracting one */ + popl %edi + ret diff --git a/src/lib/libc/i386/string/strncmp.S b/src/lib/libc/i386/string/strncmp.S new file mode 100644 index 0000000..b6c1648 --- /dev/null +++ b/src/lib/libc/i386/string/strncmp.S @@ -0,0 +1,166 @@ +/* + * Copyright (c) 1993,94 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/strncmp.S,v 1.9 2002/03/23 02:44:19 obrien Exp $"); + +/* + * strncmp(s1, s2, n) + * return an integer greater than, equal to, or less than 0, + * according as the first n characters of string s1 is greater + * than, equal to, or less than the string s2. + * + * %eax - pointer to s1 + * %ecx - pointer to s2 + * %edx - length + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +/* + * I've unrolled the loop eight times: large enough to make a + * significant difference, and small enough not to totally trash the + * cache. + * + * TODO: change all the jz's back to je for consistency. + */ + +ENTRY(strncmp) + pushl %ebx + movl 8(%esp),%eax + movl 12(%esp),%ecx + movl 16(%esp),%edx + testl %edx,%edx + jmp L2 /* Jump into the loop! */ + + .align 2,0x90 +L1: incl %eax + incl %ecx + decl %edx +L2: jz L4 /* strings are equal */ + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + +/* + * XXX it might be best to move the next 4 instructions to the end of the + * unrolled part of the loop. The unrolled part would then be + * movb n(%eax),%bl; testb %bl, %bl; je L3; cmpb n(%ecx); jne L3 + * or maybe better + * movb n(%eax),%bl; cmpb n(%ecx); jne L3; testb %bl,%bl; je return_0 + * for n = 0, 1, ..., 8. The end of the loop would be + * L1: addl $8,%eax; addl $8,%ecx; subl $8,%edx; cmpl $8,%edx; jae Lx + * where residual counts of 0 to 7 are handled at Lx. However, this would + * be slower for short strings. Cache effects are probably not so + * important because we are only handling a byte at a time. + */ + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + jne L3 + + incl %eax + incl %ecx + decl %edx + jz L4 + movb (%eax),%bl + testb %bl,%bl + jz L3 + cmpb %bl,(%ecx) + je L1 + + .align 2,0x90 +L3: movzbl (%eax),%eax /* unsigned comparison */ + movzbl (%ecx),%ecx + subl %ecx,%eax + popl %ebx + ret + .align 2,0x90 +L4: xorl %eax,%eax + popl %ebx + ret diff --git a/src/lib/libc/i386/string/strrchr.S b/src/lib/libc/i386/string/strrchr.S new file mode 100644 index 0000000..9547d25 --- /dev/null +++ b/src/lib/libc/i386/string/strrchr.S @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1993 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/strrchr.S,v 1.9 2002/06/02 20:05:38 schweikh Exp $"); + +/* + * strrchr(s, c) + * return a pointer to the last occurance of the character c in + * string s, or NULL if c does not occur in the string. + * + * %edx - pointer iterating through string + * %eax - pointer to last occurance of 'c' + * %cl - character we're comparing against + * %bl - character at %edx + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(strrchr) + pushl %ebx + movl 8(%esp),%edx + movb 12(%esp),%cl + xorl %eax,%eax /* init pointer to null */ + .align 2,0x90 +L1: + movb (%edx),%bl + cmpb %bl,%cl + jne L2 + movl %edx,%eax +L2: + incl %edx + testb %bl,%bl /* null terminator??? */ + jne L1 + popl %ebx + ret diff --git a/src/lib/libc/i386/string/swab.S b/src/lib/libc/i386/string/swab.S new file mode 100644 index 0000000..40a48a6 --- /dev/null +++ b/src/lib/libc/i386/string/swab.S @@ -0,0 +1,99 @@ +/* + * Copyright (c) 1993,94 Winning Strategies, Inc. + * 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 Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/swab.S,v 1.9 2003/01/01 18:48:42 schweikh Exp $"); + +/* + * void + * swab (const void *src, void *dst, size_t len) + * copy len bytes from src to dst, swapping adjacent bytes + * + * On the i486, this code is negligibly faster than the code generated + * by gcc at about half the size. If my i386 databook is correct, it + * should be considerably faster than the gcc code on an i386. + * + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +ENTRY(swab) + pushl %esi + pushl %edi + movl 12(%esp),%esi + movl 16(%esp),%edi + movl 20(%esp),%ecx + + cld # set direction forward + + shrl $1,%ecx + testl $7,%ecx # copy first group of 1 to 7 words + jz L2 # while swaping alternate bytes. + .align 2,0x90 +L1: lodsw + rorw $8,%ax + stosw + decl %ecx + testl $7,%ecx + jnz L1 + +L2: shrl $3,%ecx # copy remainder 8 words at a time + jz L4 # while swapping alternate bytes. + .align 2,0x90 +L3: lodsw + rorw $8,%ax + stosw + lodsw + rorw $8,%ax + stosw + lodsw + rorw $8,%ax + stosw + lodsw + rorw $8,%ax + stosw + lodsw + rorw $8,%ax + stosw + lodsw + rorw $8,%ax + stosw + lodsw + rorw $8,%ax + stosw + lodsw + rorw $8,%ax + stosw + decl %ecx + jnz L3 + +L4: popl %edi + popl %esi + ret diff --git a/src/lib/libc/i386/string/wcschr.S b/src/lib/libc/i386/string/wcschr.S new file mode 100644 index 0000000..588a68b --- /dev/null +++ b/src/lib/libc/i386/string/wcschr.S @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 2003 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/wcschr.S,v 1.1 2003/04/05 04:17:05 tjr Exp $"); + +/* + * wchar_t * + * wcschr(const wchar_t *s, wchar_t c) -- + * Return pointer to first occurrence of the character `c' in the wide + * character string `s', or NULL if not found. + */ +ENTRY(wcschr) + movl 4(%esp),%ecx /* String */ + movl 8(%esp),%eax /* Character */ + pushl %ebx +.p2align 4,0x90 +L1: movl (%ecx),%ebx + cmpl %eax,%ebx + je found0 + testl %ebx,%ebx + jz no + movl 4(%ecx),%ebx + cmpl %eax,%ebx + je found1 + testl %ebx,%ebx + jz no + movl 8(%ecx),%ebx + cmpl %eax,%ebx + je found2 + testl %ebx,%ebx + jz no + movl 12(%ecx),%ebx + cmpl %eax,%ebx + je found3 + testl %ebx,%ebx + jz no + leal 16(%ecx),%ecx + jmp L1 +.p2align 2,0x90 +found3: leal 4(%ecx),%ecx +.p2align 2,0x90 +found2: leal 4(%ecx),%ecx +.p2align 2,0x90 +found1: leal 4(%ecx),%ecx +.p2align 2,0x90 +found0: popl %ebx + movl %ecx,%eax + ret +.p2align 2,0x90 +no: popl %ebx + xorl %eax,%eax + ret diff --git a/src/lib/libc/i386/string/wcscmp.S b/src/lib/libc/i386/string/wcscmp.S new file mode 100644 index 0000000..c609544 --- /dev/null +++ b/src/lib/libc/i386/string/wcscmp.S @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 2003 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/wcscmp.S,v 1.1 2003/03/10 10:54:36 tjr Exp $"); + +/* + * int + * wcscmp(const wchar_t *s1, const wchar_t *s2) -- + * Return an integer greater than, equal to, or less than 0, when + * the string s1 is greater than, equal to, or less than the string s2. + */ +ENTRY(wcscmp) + pushl %edi + pushl %esi + movl 12(%esp),%edi /* s1 */ + movl 16(%esp),%esi /* s2 */ +.p2align 4,0x90 +top: movl (%edi),%eax + cmpl %eax,(%esi) + jne no0 + testl %eax,%eax + jz same + movl 4(%edi),%eax + cmpl %eax,4(%esi) + jne no4 + testl %eax,%eax + jz same + movl 8(%edi),%eax + cmpl %eax,8(%esi) + jne no8 + testl %eax,%eax + jz same + movl 12(%edi),%eax + cmpl %eax,12(%esi) + jne no12 + leal 16(%edi),%edi + leal 16(%esi),%esi + testl %eax,%eax + jnz top +.p2align 2,0x90 +same: xorl %eax,%eax + popl %esi + popl %edi + ret +.p2align 2,0x90 +no12: leal 4(%esi),%esi +.p2align 2,0x90 +no8: leal 4(%esi),%esi +.p2align 2,0x90 +no4: leal 4(%esi),%esi +.p2align 2,0x90 +no0: subl (%esi),%eax + popl %esi + popl %edi + ret diff --git a/src/lib/libc/i386/string/wcslen.S b/src/lib/libc/i386/string/wcslen.S new file mode 100644 index 0000000..bb9c380 --- /dev/null +++ b/src/lib/libc/i386/string/wcslen.S @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 2003 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/wcslen.S,v 1.1 2003/03/14 11:01:12 tjr Exp $"); + +/* + * size_t + * wcslen(const wchar_t *s) -- + * Find the length of a wide character string. + */ +ENTRY(wcslen) + movl 4(%esp),%ecx /* String */ + pushl %ebx + xorl %ebx,%ebx + xorl %eax,%eax +.p2align 4,0x90 +L1: cmpl %ebx,(%ecx) + jz found0 + cmpl %ebx,4(%ecx) + jz found1 + cmpl %ebx,8(%ecx) + jz found2 + cmpl %ebx,12(%ecx) + jz found3 + cmpl %ebx,16(%ecx) + jz found4 + cmpl %ebx,20(%ecx) + jz found5 + cmpl %ebx,24(%ecx) + jz found6 + cmpl %ebx,28(%ecx) + jz found7 + leal 32(%ecx),%ecx + addl $8,%eax + jmp L1 +found7: incl %eax +found6: incl %eax +found5: incl %eax +found4: incl %eax +found3: incl %eax +found2: incl %eax +found1: incl %eax +found0: popl %ebx + ret diff --git a/src/lib/libc/i386/string/wmemchr.S b/src/lib/libc/i386/string/wmemchr.S new file mode 100644 index 0000000..9e0b41a --- /dev/null +++ b/src/lib/libc/i386/string/wmemchr.S @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 2003 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/string/wmemchr.S,v 1.2 2003/03/12 06:46:16 tjr Exp $"); + +/* + * wchar_t * + * wmemchr(const wchar_t *buf, wchar_t c, size_t n) -- + * Search the wide character array `buf', which has length `n', + * the character `c', return a pointer to it if found, or NULL on + * failure. + */ +ENTRY(wmemchr) + pushl %edi + pushl %ebx + movl 12(%esp),%edi /* Buffer */ + movl 16(%esp),%eax /* Wide character */ + movl 20(%esp),%ecx /* Length of buffer */ + + /* + * Search in chunks of 8 wide characters (32 bytes). + */ + movl %ecx,%ebx + shrl $3,%ecx + jz small +.p2align 4,0x90 +bigloop:cmpl %eax,(%edi) + je found + cmpl %eax,4(%edi) + je found4 + cmpl %eax,8(%edi) + je found8 + cmpl %eax,12(%edi) + je found12 + cmpl %eax,16(%edi) + je found16 + cmpl %eax,20(%edi) + je found20 + cmpl %eax,24(%edi) + je found24 + cmpl %eax,28(%edi) + je found28 + leal 32(%edi),%edi + decl %ecx + jnz bigloop + jmp small +found: movl %edi,%eax + popl %ebx + popl %edi + ret +found4: leal 4(%edi),%edi + jmp found +found8: leal 8(%edi),%edi + jmp found +found12:leal 12(%edi),%edi + jmp found +found16:leal 16(%edi),%edi + jmp found +found20:leal 20(%edi),%edi + jmp found +found24:leal 24(%edi),%edi + jmp found +found28:leal 28(%edi),%edi + jmp found + + /* + * Search remaining part of string. + */ +small: movl %ebx,%ecx + andl $7,%ecx + jz no +.p2align 2,0x90 +smltop: cmpl %eax,(%edi) + je found + leal 4(%edi),%edi + decl %ecx + jnz smltop +no: xorl %eax,%eax + popl %ebx + popl %edi + ret diff --git a/src/lib/libc/i386/sys/Makefile.inc b/src/lib/libc/i386/sys/Makefile.inc new file mode 100644 index 0000000..3089547 --- /dev/null +++ b/src/lib/libc/i386/sys/Makefile.inc @@ -0,0 +1,22 @@ +# from: Makefile.inc,v 1.1 1993/09/03 19:04:23 jtc Exp +# $FreeBSD: src/lib/libc/i386/sys/Makefile.inc,v 1.27 2003/09/04 00:20:40 peter Exp $ + +SRCS+= i386_clr_watch.c i386_get_ioperm.c i386_get_ldt.c i386_set_ioperm.c \ + i386_set_ldt.c i386_set_watch.c i386_vm86.c + +MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \ + reboot.S sbrk.S setlogin.S sigreturn.S syscall.S + +# Don't generate default code for these syscalls: +NOASM= break.o exit.o ftruncate.o getdomainname.o getlogin.o \ + lseek.o mmap.o openbsd_poll.o pread.o \ + pwrite.o setdomainname.o sstk.o truncate.o uname.o vfork.o yield.o + +PSEUDO= _getlogin.o _exit.o + +MAN+= i386_get_ioperm.2 i386_get_ldt.2 i386_vm86.2 +MAN+= i386_set_watch.3 + +MLINKS+=i386_get_ioperm.2 i386_set_ioperm.2 +MLINKS+=i386_get_ldt.2 i386_set_ldt.2 +MLINKS+=i386_set_watch.3 i386_clr_watch.3 diff --git a/src/lib/libc/i386/sys/Ovfork.S b/src/lib/libc/i386/sys/Ovfork.S new file mode 100644 index 0000000..a3ce2c9 --- /dev/null +++ b/src/lib/libc/i386/sys/Ovfork.S @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)Ovfork.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/Ovfork.S,v 1.19 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + + .weak _vfork + .set _vfork,__sys_vfork + .weak vfork + .set vfork,__sys_vfork +ENTRY(__sys_vfork) + popl %ecx /* my rta into ecx */ + mov $SYS_vfork,%eax + KERNCALL + jb 1f + jmp *%ecx +1: + pushl %ecx + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) diff --git a/src/lib/libc/i386/sys/brk.S b/src/lib/libc/i386/sys/brk.S new file mode 100644 index 0000000..1bc5359 --- /dev/null +++ b/src/lib/libc/i386/sys/brk.S @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)brk.s 5.2 (Berkeley) 12/17/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/brk.S,v 1.10 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + + .globl HIDENAME(curbrk) + .globl HIDENAME(minbrk) +ENTRY(_brk) + jmp ok + +ENTRY(brk) +#ifdef PIC + movl 4(%esp),%eax + PIC_PROLOGUE + movl PIC_GOT(HIDENAME(curbrk)),%edx # set up GOT addressing + movl PIC_GOT(HIDENAME(minbrk)),%ecx # + PIC_EPILOGUE + cmpl %eax,(%ecx) + jbe ok + movl (%ecx),%eax + movl %eax,4(%esp) +ok: + mov $SYS_break,%eax + KERNCALL + jb err + movl 4(%esp),%eax + movl %eax,(%edx) + movl $0,%eax + ret +err: + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) + +#else + + movl 4(%esp),%eax + cmpl %eax,HIDENAME(minbrk) + jbe ok + movl HIDENAME(minbrk),%eax + movl %eax,4(%esp) +ok: + mov $SYS_break,%eax + KERNCALL + jb err + movl 4(%esp),%eax + movl %eax,HIDENAME(curbrk) + movl $0,%eax + ret +err: + jmp HIDENAME(cerror) +#endif diff --git a/src/lib/libc/i386/sys/cerror.S b/src/lib/libc/i386/sys/cerror.S new file mode 100644 index 0000000..5d7248b --- /dev/null +++ b/src/lib/libc/i386/sys/cerror.S @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)cerror.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/cerror.S,v 1.12 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + + .globl HIDENAME(cerror) + + /* + * The __error() function is thread aware. For non-threaded + * programs and the initial threaded in threaded programs, + * it returns a pointer to the global errno variable. + */ + .globl CNAME(__error) + .type CNAME(__error),@function +HIDENAME(cerror): + pushl %eax +#ifdef PIC + /* The caller must execute the PIC prologue before jumping to cerror. */ + call PIC_PLT(CNAME(__error)) + popl %ecx + PIC_EPILOGUE +#else + call CNAME(__error) + popl %ecx +#endif + movl %ecx,(%eax) + movl $-1,%eax + movl $-1,%edx + ret + diff --git a/src/lib/libc/i386/sys/exect.S b/src/lib/libc/i386/sys/exect.S new file mode 100644 index 0000000..a7a6888 --- /dev/null +++ b/src/lib/libc/i386/sys/exect.S @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)exect.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/exect.S,v 1.9 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" +#include + +ENTRY(exect) + mov $SYS_execve,%eax + pushf + popl %edx + orl $ PSL_T,%edx + pushl %edx + popf + KERNCALL + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) /* exect(file, argv, env); */ diff --git a/src/lib/libc/i386/sys/getcontext.S b/src/lib/libc/i386/sys/getcontext.S new file mode 100644 index 0000000..97f6a01 --- /dev/null +++ b/src/lib/libc/i386/sys/getcontext.S @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2003 Peter Wemm + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/getcontext.S,v 1.1 2003/09/04 00:20:40 peter Exp $"); + +#include + +/* + * This has to be magic to handle the multiple returns. + * Otherwise, the setcontext() syscall will return here and we'll + * pop off the return address and go to the *setcontext* call. + */ + .weak _getcontext + .set _getcontext,__sys_getcontext + .weak getcontext + .set getcontext,__sys_getcontext +ENTRY(__sys_getcontext) + movl (%esp),%ecx /* save getcontext return address */ + mov $SYS_getcontext,%eax + KERNCALL + jb 1f + addl $4,%esp /* remove stale (setcontext) return address */ + jmp *%ecx /* restore return address */ +1: + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) diff --git a/src/lib/libc/i386/sys/i386_clr_watch.c b/src/lib/libc/i386/sys/i386_clr_watch.c new file mode 100644 index 0000000..1b0e935 --- /dev/null +++ b/src/lib/libc/i386/sys/i386_clr_watch.c @@ -0,0 +1,46 @@ +/* + * Copyright 2000 Brian S. Dean + * 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. + * + * THIS SOFTWARE IS PROVIDED BY BRIAN S. DEAN ``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 BRIAN S. DEAN 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/i386_clr_watch.c,v 1.3 2002/10/21 03:47:22 sam Exp $"); + +#include +#include + +int +i386_clr_watch(int watchnum, struct dbreg * d) +{ + + if (watchnum < 0 || watchnum >= 4) + return -1; + + DBREG_DRX(d,7) = DBREG_DRX(d,7) & ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16))); + DBREG_DRX(d,watchnum) = 0; + + return 0; +} diff --git a/src/lib/libc/i386/sys/i386_get_ioperm.2 b/src/lib/libc/i386/sys/i386_get_ioperm.2 new file mode 100644 index 0000000..2a26389 --- /dev/null +++ b/src/lib/libc/i386/sys/i386_get_ioperm.2 @@ -0,0 +1,86 @@ +.\" Copyright (c) 1998 Jonathan Lemon +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD: src/lib/libc/i386/sys/i386_get_ioperm.2,v 1.10 2002/12/18 12:39:25 ru Exp $ +.\" +.Dd July 27, 1998 +.Os +.Dt I386_GET_IOPERM 2 +.Sh NAME +.Nm i386_get_ioperm , +.Nm i386_set_ioperm +.Nd manage per-process access to the i386 I/O port space +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In machine/sysarch.h +.Ft int +.Fn i386_get_ioperm "unsigned int start" "unsigned int *length" "int *enable" +.Ft int +.Fn i386_set_ioperm "unsigned int start" "unsigned int length" "int enable" +.Sh DESCRIPTION +The +.Fn i386_get_ioperm +system call +will return the permission for the process' I/O port space in the +.Fa *enable +argument. The port range starts at +.Fa start +and the number of contiguous entries will be returned in +.Fa *length . +.Pp +The +.Fn i386_set_ioperm +system call +will set access to a range of I/O ports described by the +.Fa start +and +.Fa length +arguments to the state specified by the +.Fa enable +argument. +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +The +.Fn i386_get_ioperm +and +.Fn i386_set_ioperm +system calls +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +An invalid range was specified by the +.Fa start +or +.Fa length +arguments. +.It Bq Er EPERM +The caller of i386_set_ioperm was not the superuser. +.El +.Sh SEE ALSO +.Xr io 4 +.Sh AUTHORS +This man page was written by +.An Jonathan Lemon . diff --git a/src/lib/libc/i386/sys/i386_get_ioperm.c b/src/lib/libc/i386/sys/i386_get_ioperm.c new file mode 100644 index 0000000..fb3f48b --- /dev/null +++ b/src/lib/libc/i386/sys/i386_get_ioperm.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 1998 Jonathan Lemon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/i386_get_ioperm.c,v 1.8 2004/01/09 16:52:09 nectar Exp $"); + +#include + +int +i386_get_ioperm(unsigned int start, unsigned int *length, int *enable) +{ + struct i386_ioperm_args p; + int error; + + p.start = start; + p.length = *length; + p.enable = *enable; + + error = sysarch(I386_GET_IOPERM, &p); + + *length = p.length; + *enable = p.enable; + + return (error); +} diff --git a/src/lib/libc/i386/sys/i386_get_ldt.2 b/src/lib/libc/i386/sys/i386_get_ldt.2 new file mode 100644 index 0000000..15ae4fd --- /dev/null +++ b/src/lib/libc/i386/sys/i386_get_ldt.2 @@ -0,0 +1,143 @@ +.\" Copyright (c) 1980, 1991 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. +.\" +.\" from: @(#)fork.2 6.5 (Berkeley) 3/10/91 +.\" $FreeBSD: src/lib/libc/i386/sys/i386_get_ldt.2,v 1.20 2003/09/08 19:57:14 ru Exp $ +.\" +.Dd September 20, 1993 +.Dt I386_GET_LDT 2 +.Os +.Sh NAME +.Nm i386_get_ldt , +.Nm i386_set_ldt +.Nd manage i386 per-process Local Descriptor Table entries +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In machine/segments.h +.In machine/sysarch.h +.Ft int +.Fn i386_get_ldt "int start_sel" "union descriptor *descs" "int num_sels" +.Ft int +.Fn i386_set_ldt "int start_sel" "union descriptor *descs" "int num_sels" +.Sh DESCRIPTION +The +.Fn i386_get_ldt +system call +will return the list of i386 descriptors that the process has in its +LDT. +The +.Fn i386_set_ldt +system call +will set a list of i386 descriptors for the current process in its +LDT. +Both routines accept a starting selector number +.Fa start_sel , +an array of memory that +will contain the descriptors to be set or returned +.Fa descs , +and the number of entries to set or return +.Fa num_sels . +.Pp +The argument +.Fa descs +can be either segment_descriptor or gate_descriptor and are defined in +.In i386/segments.h . +These structures are defined by the architecture +as disjoint bit-fields, so care must be taken in constructing them. +.Pp +If +.Fa start_sel +is +.Em LDT_AUTO_ALLOC , +.Fa num_sels +is 1 and the descriptor pointed to by +.Fa descs +is legal, then +.Fn i386_set_ldt +will allocate a descriptor and return its +selector number. +.Pp +If +.Fa num_descs +is 1, +.Fa start_sels +is valid, and +.Fa descs +is NULL, then +.Fn i386_set_ldt +will free that descriptor +(making it available to be reallocated again later). +.Pp +If +.Fa num_descs +is 0, +.Fa start_sels +is 0 and +.Fa descs +is NULL then, as a special case, +.Fn i386_set_ldt +will free all descriptors. +.Sh RETURN VALUES +Upon successful completion, +.Fn i386_get_ldt +returns the number of descriptors currently in the LDT. +The +.Fn i386_set_ldt +system call +returns the first selector set. +In the case when a descriptor is allocated by the kernel, its number will +be returned. +Otherwise, a value of -1 is returned and the global +variable +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn i386_get_ldt +and +.Fn i386_set_ldt +system calls +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +An inappropriate value was used for +.Fa start_sel +or +.Fa num_sels . +.It Bq Er EACCES +The caller attempted to use a descriptor that would +circumvent protection or cause a failure. +.El +.Sh SEE ALSO +i386 Microprocessor Programmer's Reference Manual, Intel +.Sh WARNING +You can really hose your process using this. diff --git a/src/lib/libc/i386/sys/i386_get_ldt.c b/src/lib/libc/i386/sys/i386_get_ldt.c new file mode 100644 index 0000000..51ac9ef --- /dev/null +++ b/src/lib/libc/i386/sys/i386_get_ldt.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1993 John Brezak + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/i386_get_ldt.c,v 1.11 2004/01/09 16:52:09 nectar Exp $"); + +#include +#include +#include + +int +i386_get_ldt(int start, union descriptor *descs, int num) +{ + struct i386_ldt_args p; + + p.start = start; + p.descs = descs; + p.num = num; + + return sysarch(I386_GET_LDT, &p); +} diff --git a/src/lib/libc/i386/sys/i386_set_ioperm.c b/src/lib/libc/i386/sys/i386_set_ioperm.c new file mode 100644 index 0000000..cb3f776 --- /dev/null +++ b/src/lib/libc/i386/sys/i386_set_ioperm.c @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 1998 Jonathan Lemon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/i386_set_ioperm.c,v 1.8 2004/01/09 16:52:09 nectar Exp $"); + +#include + +int +i386_set_ioperm(unsigned int start, unsigned int length, int enable) +{ + struct i386_ioperm_args p; + + p.start = start; + p.length = length; + p.enable = enable; + + return (sysarch(I386_SET_IOPERM, &p)); +} diff --git a/src/lib/libc/i386/sys/i386_set_ldt.c b/src/lib/libc/i386/sys/i386_set_ldt.c new file mode 100644 index 0000000..df65f9f --- /dev/null +++ b/src/lib/libc/i386/sys/i386_set_ldt.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1993 John Brezak + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/i386_set_ldt.c,v 1.11 2004/01/09 16:52:09 nectar Exp $"); + +#include +#include +#include + +int +i386_set_ldt(int start, union descriptor *descs, int num) +{ + struct i386_ldt_args p; + + p.start = start; + p.descs = descs; + p.num = num; + + return sysarch(I386_SET_LDT, &p); +} diff --git a/src/lib/libc/i386/sys/i386_set_watch.3 b/src/lib/libc/i386/sys/i386_set_watch.3 new file mode 100644 index 0000000..6cf1ae4 --- /dev/null +++ b/src/lib/libc/i386/sys/i386_set_watch.3 @@ -0,0 +1,113 @@ +.\" Copyright (c) 2000 Brian S. Dean +.\" All rights reserved. +.\" +.\" This man-page is based on a similar man-page by Jonathan Lemon +.\" which is copyrighted under the following conditions: +.\" +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD: src/lib/libc/i386/sys/i386_set_watch.3,v 1.6 2002/12/27 12:15:28 schweikh Exp $ +.\" +.Dd August 24, 2000 +.Os +.Dt I386_SET_WATCH 3 +.Sh NAME +.Nm i386_clr_watch , +.Nm i386_set_watch +.Nd manage i386 debug register values +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In machine/reg.h +.In machine/sysarch.h +.Ft int +.Fn i386_clr_watch "int watchnum" "struct dbreg *d" +.Ft int +.Fn i386_set_watch "int watchnum" "unsigned int watchaddr" "int size" "int access" "struct dbreg *d" +.Sh DESCRIPTION +The +.Fn i386_clr_watch +function +will disable the indicated watch point within the specified debug +register set. +.Pp +The +.Fn i386_set_watch +function +will set up the specified debug registers as indicated by the +arguments. The +.Fa watchnum +argument specifies which watch register is used, 0, 1, 2, 3, or -1. If +.Fa watchnum +is -1, a free watch register is found and used. If there are no free +watch registers, an error code of -1 is returned. +The +.Fa watchaddr +argument +specifies the watch address, +.Fa size +specifies the size in bytes of the area to be watched (1, 2, or 4 bytes), +and +.Fa access +specifies the type of watch point: +.Pp +.Bd -literal -offset indent -compact +DBREG_DR7_EXEC An execution breakpoint. +DBREG_DR7_WRONLY Break only when the watch area is written to. +DBREG_DR7_RDWR Break when the watch area is read from or written + to. +.Ed +.Pp +Note that these functions do not actually set or clear breakpoints; +they manipulate the indicated debug register set. You must use +.Xr ptrace 2 +to retrieve and install the debug register values for a process. +.Sh RETURN VALUES +The +.Fn i386_clr_watch +function +returns 0 on success, or -1 if +.Fa watchnum +is invalid (not in the range of 0-3). +.Pp +The +.Fn i386_set_watch +function +will return the +.Fa watchnum +argument, or the watchnum actually used in the case that +.Fa watchnum +is -1 on success. On error, +.Fn i386_set_watch +will return -1 indicating that the watchpoint could not be set up +because either no more watchpoints are available, or +.Fa watchnum , +.Fa size , +or +.Fa access +is invalid. +.Sh SEE ALSO +.Xr ptrace 2 , +.Xr procfs 5 +.Sh AUTHORS +This man page was written by +.An Brian S. Dean . diff --git a/src/lib/libc/i386/sys/i386_set_watch.c b/src/lib/libc/i386/sys/i386_set_watch.c new file mode 100644 index 0000000..325aff7 --- /dev/null +++ b/src/lib/libc/i386/sys/i386_set_watch.c @@ -0,0 +1,84 @@ +/* + * Copyright 2000 Brian S. Dean + * 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. + * + * THIS SOFTWARE IS PROVIDED BY BRIAN S. DEAN ``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 BRIAN S. DEAN 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/i386_set_watch.c,v 1.3 2002/10/21 03:47:22 sam Exp $"); + +#include +#include + +int +i386_set_watch(int watchnum, unsigned int watchaddr, int size, + int access, struct dbreg * d) +{ + int i; + unsigned int mask; + + if (watchnum == -1) { + for (i = 0, mask = 0x3; i < 4; i++, mask <<= 2) + if ((DBREG_DRX(d,7) & mask) == 0) + break; + if (i < 4) + watchnum = i; + else + return -1; + } + + switch (access) { + case DBREG_DR7_EXEC: + size = 1; /* size must be 1 for an execution breakpoint */ + /* fall through */ + case DBREG_DR7_WRONLY: + case DBREG_DR7_RDWR: + break; + default : return -1; break; + } + + /* + * we can watch a 1, 2, or 4 byte sized location + */ + switch (size) { + case 1 : mask = 0x00; break; + case 2 : mask = 0x01 << 2; break; + case 4 : mask = 0x03 << 2; break; + default : return -1; break; + } + + mask |= access; + + /* clear the bits we are about to affect */ + DBREG_DRX(d,7) &= ~((0x3 << (watchnum*2)) | (0x0f << (watchnum*4+16))); + + /* set drN register to the address, N=watchnum */ + DBREG_DRX(d,watchnum) = watchaddr; + + /* enable the watchpoint */ + DBREG_DRX(d,7) |= (0x2 << (watchnum*2)) | (mask << (watchnum*4+16)); + + return watchnum; +} diff --git a/src/lib/libc/i386/sys/i386_vm86.2 b/src/lib/libc/i386/sys/i386_vm86.2 new file mode 100644 index 0000000..56e4f45 --- /dev/null +++ b/src/lib/libc/i386/sys/i386_vm86.2 @@ -0,0 +1,141 @@ +.\" Copyright (c) 1998 Jonathan Lemon +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD: src/lib/libc/i386/sys/i386_vm86.2,v 1.15 2003/05/22 13:02:27 ru Exp $ +.\" +.Dd July 27, 1998 +.Os +.Dt I386_VM86 2 +.Sh NAME +.Nm i386_vm86 +.Nd control vm86-related functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In machine/sysarch.h +.In machine/vm86.h +.Ft int +.Fn i386_vm86 "int function" "void *data" +.Sh DESCRIPTION +The +.Fn i386_vm86 +system call +is used to call various vm86 related functions. +The +.Fa function +argument +can be one of the following values: +.Bl -tag -offset indent -width VM86_SET_VME +.It Dv VM86_INIT +This will initialize the kernel's vm86 parameter area for the +process, and permit the process to make vm86 calls. +The +.Fa data +argument +points to the following structure: +.Bd -literal +struct vm86_init_args { + int debug; + int cpu_type; + u_char int_map[32]; +}; +.Ed +.Pp +The +.Fa debug +argument +is used to turn on debugging code. +The +.Fa cpu_type +argument +controls the type of CPU being emulated, and is currently unimplemented. +The +.Fa int_map +argument +is a bitmap which determines whether vm86 interrupts should be handled +in vm86 mode, or reflected back to the process. +If the +.Em Nth +bit is set, the interrupt will be reflected to the process, otherwise +it will be dispatched by the vm86 interrupt table. +.It Dv VM86_INTCALL +This allows calls to be made to vm86 interrupt handlers by the process. +It effectively simulates an INT instruction. +.Fa data +should point to the following structure: +.Bd -literal +struct vm86_intcall_args { + int intnum; + struct vm86frame vmf; +}; +.Ed +.Pp +.Fa intnum +specifies the operand of INT for the simulated call. +A value of 0x10, for example, would often be used to call into the VGA BIOS. +.Fa vmf +is used to initialize CPU registers according to the calling convention for +the interrupt handler. +.It Dv VM86_GET_VME +This is used to retrieve the current state of the Pentium(r) processor's +VME (Virtual-8086 Mode Extensions) flag, which is bit 0 of CR4. +.Fa data +should be initialized to point to the following: +.Bd -literal +struct vm86_vme_args { + int state; /* status */ +}; +.Ed +.Pp +.Fa state +will contain the state of the VME flag on return. +.\" .It Dv VM86_SET_VME +.El +.Pp +vm86 mode is entered by calling +.Xr sigreturn 2 +with the correct machine context for vm86, and with the +.Dv PSL_VM +bit set. +Control returns to the process upon delivery of a signal. +.Sh RETURN VALUES +.Rv -std i386_vm86 +.Sh ERRORS +The +.Fn i386_vm86 +system call +will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The kernel does not have vm86 support, or an invalid function was specified. +.It Bq Er ENOMEM +There is not enough memory to initialize the kernel data structures. +.El +.Sh AUTHORS +.An -nosplit +This man page was written by +.An Jonathan Lemon , +and updated by +.An Bruce M Simpson . diff --git a/src/lib/libc/i386/sys/i386_vm86.c b/src/lib/libc/i386/sys/i386_vm86.c new file mode 100644 index 0000000..02b3446 --- /dev/null +++ b/src/lib/libc/i386/sys/i386_vm86.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 1998 Jonathan Lemon + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/i386_vm86.c,v 1.7 2004/01/09 16:52:09 nectar Exp $"); + +#include + +int +i386_vm86(int fcn, void *data) +{ + struct i386_vm86_args p; + + p.sub_op = fcn; + p.sub_args = (char *)data; + + return (sysarch(I386_VM86, &p)); +} diff --git a/src/lib/libc/i386/sys/pipe.S b/src/lib/libc/i386/sys/pipe.S new file mode 100644 index 0000000..c6042ca --- /dev/null +++ b/src/lib/libc/i386/sys/pipe.S @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)pipe.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/pipe.S,v 1.11 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + +SYSCALL(pipe) + movl 4(%esp),%ecx + movl %eax,(%ecx) + movl %edx,4(%ecx) + movl $0,%eax + ret diff --git a/src/lib/libc/i386/sys/ptrace.S b/src/lib/libc/i386/sys/ptrace.S new file mode 100644 index 0000000..fb35a49 --- /dev/null +++ b/src/lib/libc/i386/sys/ptrace.S @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)ptrace.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/ptrace.S,v 1.9 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + +ENTRY(ptrace) + xorl %eax,%eax +#ifdef PIC + PIC_PROLOGUE + movl PIC_GOT(CNAME(errno)),%edx + movl %eax,(%edx) + PIC_EPILOGUE +#else + movl %eax,CNAME(errno) +#endif + mov $SYS_ptrace,%eax + KERNCALL + jb err + ret +err: + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) diff --git a/src/lib/libc/i386/sys/reboot.S b/src/lib/libc/i386/sys/reboot.S new file mode 100644 index 0000000..11bb985 --- /dev/null +++ b/src/lib/libc/i386/sys/reboot.S @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)reboot.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/reboot.S,v 1.7 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + +SYSCALL(reboot) + iret diff --git a/src/lib/libc/i386/sys/sbrk.S b/src/lib/libc/i386/sys/sbrk.S new file mode 100644 index 0000000..917e187 --- /dev/null +++ b/src/lib/libc/i386/sys/sbrk.S @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)sbrk.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/sbrk.S,v 1.11 2002/08/08 17:28:07 kan Exp $"); + +#include "SYS.h" + + .globl CNAME(_end) + .globl HIDENAME(minbrk) + .globl HIDENAME(curbrk) + + .data +HIDENAME(minbrk): .long CNAME(_end) +HIDENAME(curbrk): .long CNAME(_end) + .text + +ENTRY(sbrk) +#ifdef PIC + movl 4(%esp),%ecx + PIC_PROLOGUE + movl PIC_GOT(HIDENAME(curbrk)),%edx + movl (%edx),%eax + PIC_EPILOGUE + testl %ecx,%ecx + jz back + addl %eax,4(%esp) + mov $SYS_break,%eax + KERNCALL + jb err + PIC_PROLOGUE + movl PIC_GOT(HIDENAME(curbrk)),%edx + movl (%edx),%eax + addl %ecx,(%edx) + PIC_EPILOGUE +back: + ret +err: + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) + +#else /* !PIC */ + + movl 4(%esp),%ecx + movl HIDENAME(curbrk),%eax + testl %ecx,%ecx + jz back + addl %eax,4(%esp) + mov $SYS_break,%eax + KERNCALL + jb err + movl HIDENAME(curbrk),%eax + addl %ecx,HIDENAME(curbrk) +back: + ret +err: + jmp HIDENAME(cerror) +#endif /* PIC */ diff --git a/src/lib/libc/i386/sys/setlogin.S b/src/lib/libc/i386/sys/setlogin.S new file mode 100644 index 0000000..9dfd39e --- /dev/null +++ b/src/lib/libc/i386/sys/setlogin.S @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 1991 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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) + .asciz "@(#)setlogin.s 5.2 (Berkeley) 4/12/91" +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/setlogin.S,v 1.9 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + +.globl CNAME(_logname_valid) /* in _getlogin() */ + +SYSCALL(setlogin) +#ifdef PIC + PIC_PROLOGUE + pushl %eax + movl PIC_GOT(CNAME(_logname_valid)),%eax + movl $0,(%eax) + popl %eax + PIC_EPILOGUE +#else + movl $0,CNAME(_logname_valid) +#endif + ret /* setlogin(name) */ diff --git a/src/lib/libc/i386/sys/sigreturn.S b/src/lib/libc/i386/sys/sigreturn.S new file mode 100644 index 0000000..ff705c9 --- /dev/null +++ b/src/lib/libc/i386/sys/sigreturn.S @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)sigreturn.s 5.2 (Berkeley) 12/17/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/sigreturn.S,v 1.12 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + +/* + * NOTE: If the profiling ENTRY() code ever changes any registers, they + * must be saved. On FreeBSD, this is not the case. + */ + +RSYSCALL(sigreturn) diff --git a/src/lib/libc/i386/sys/syscall.S b/src/lib/libc/i386/sys/syscall.S new file mode 100644 index 0000000..3035e55 --- /dev/null +++ b/src/lib/libc/i386/sys/syscall.S @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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(SYSLIBC_SCCS) && !defined(lint) + .asciz "@(#)syscall.s 5.1 (Berkeley) 4/23/90" +#endif /* SYSLIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/i386/sys/syscall.S,v 1.8 2002/03/23 02:10:28 obrien Exp $"); + +#include "SYS.h" + +ENTRY(syscall) + pop %ecx /* rta */ + pop %eax /* syscall number */ + push %ecx + KERNCALL + push %ecx /* need to push a word to keep stack frame intact + upon return; the word must be the return address. */ + jb 1f + ret +1: + PIC_PROLOGUE + jmp PIC_PLT(HIDENAME(cerror)) diff --git a/src/lib/libc/locale/Makefile b/src/lib/libc/locale/Makefile new file mode 100644 index 0000000..5e146ef --- /dev/null +++ b/src/lib/libc/locale/Makefile @@ -0,0 +1,35 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = big5.o btowc.o collate.o collcmp.o euc.o fix_grouping.o frune.o gb18030.o gb2312.o gbk.o isctype.o iswctype.o ldpart.o lmessages.o lmonetary.o lnumeric.o localeconv.o mblen.o mbrlen.o mbrtowc.o mbrune.o mbsinit.o mbsrtowcs.o mbstowcs.o mbtowc.o mskanji.o nl_langinfo.o nomacros.o none.o rune.o runetype.o setinvalidrune.o setlocale.o setrunelocale.o srune.o table.o tolower.o toupper.o utf2.o utf8.o wcrtomb.o wcsftime.o wcsrtombs.o wcstod.o wcstof.o wcstoimax.o wcstol.o wcstold.o wcstoll.o wcstombs.o wcstoul.o wcstoull.o wcstoumax.o wctob.o wctomb.o wctrans.o wctype.o wcwidth.o + +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -I../../../include -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdlib -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) + diff --git a/src/lib/libc/locale/big5.c b/src/lib/libc/locale/big5.c new file mode 100644 index 0000000..26000a8 --- /dev/null +++ b/src/lib/libc/locale/big5.c @@ -0,0 +1,171 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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[] = "@(#)big5.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/big5.c,v 1.16 2004/05/17 11:16:14 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +int _BIG5_init(_RuneLocale *); +size_t _BIG5_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _BIG5_mbsinit(const mbstate_t *); +size_t _BIG5_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + wchar_t ch; +} _BIG5State; + +int +_BIG5_init(_RuneLocale *rl) +{ + + __mbrtowc = _BIG5_mbrtowc; + __wcrtomb = _BIG5_wcrtomb; + __mbsinit = _BIG5_mbsinit; + _CurrentRuneLocale = rl; + __mb_cur_max = 2; + return (0); +} + +int +_BIG5_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _BIG5State *)ps)->ch == 0); +} + +static __inline int +_big5_check(u_int c) +{ + + c &= 0xff; + return ((c >= 0xa1 && c <= 0xfe) ? 2 : 1); +} + +size_t +_BIG5_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps) +{ + _BIG5State *bs; + wchar_t wc; + size_t len; + + bs = (_BIG5State *)ps; + + if ((bs->ch & ~0xFF) != 0) { + /* Bad conversion state. */ + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + if (n == 0) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + + if (bs->ch != 0) { + if (*s == '\0') { + errno = EILSEQ; + return ((size_t)-1); + } + wc = (bs->ch << 8) | (*s & 0xFF); + if (pwc != NULL) + *pwc = wc; + bs->ch = 0; + return (1); + } + + len = (size_t)_big5_check(*s); + wc = *s++ & 0xff; + if (len == 2) { + if (n < 2) { + /* Incomplete multibyte sequence */ + bs->ch = wc; + return ((size_t)-2); + } + if (*s == '\0') { + errno = EILSEQ; + return ((size_t)-1); + } + wc = (wc << 8) | (*s++ & 0xff); + if (pwc != NULL) + *pwc = wc; + return (2); + } else { + if (pwc != NULL) + *pwc = wc; + return (wc == L'\0' ? 0 : 1); + } +} + +size_t +_BIG5_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _BIG5State *bs; + + bs = (_BIG5State *)ps; + + if (bs->ch != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + if (wc & 0x8000) { + *s++ = (wc >> 8) & 0xff; + *s = wc & 0xff; + return (2); + } + *s = wc & 0xff; + return (1); +} diff --git a/src/lib/libc/locale/btowc.c b/src/lib/libc/locale/btowc.c new file mode 100644 index 0000000..44b501e --- /dev/null +++ b/src/lib/libc/locale/btowc.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2002, 2003 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/btowc.c,v 1.4 2004/05/12 14:26:54 tjr Exp $"); + +#include +#include +#include "mblocal.h" + +wint_t +btowc(int c) +{ + static const mbstate_t initial; + mbstate_t mbs = initial; + char cc; + wchar_t wc; + + if (c == EOF) + return (WEOF); + /* + * We expect mbrtowc() to return 0 or 1, hence the check for n > 1 + * which detects error return values as well as "impossible" byte + * counts. + */ + cc = (char)c; + if (__mbrtowc(&wc, &cc, 1, &mbs) > 1) + return (WEOF); + return (wc); +} diff --git a/src/lib/libc/locale/collate.c b/src/lib/libc/locale/collate.c new file mode 100644 index 0000000..abc5f24 --- /dev/null +++ b/src/lib/libc/locale/collate.c @@ -0,0 +1,291 @@ +/*- + * Copyright (c) 1995 Alex Tatmanjants + * at Electronni Visti IA, Kiev, Ukraine. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/collate.c,v 1.32 2002/10/29 09:03:57 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "collate.h" +#include "setlocale.h" +#include "ldpart.h" + +#include "libc_private.h" + +int __collate_load_error = 1; +int __collate_substitute_nontrivial; + +u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; +struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1]; +struct __collate_st_chain_pri *__collate_chain_pri_table; + +void __collate_err(int ex, const char *f) __dead2; + +int +__collate_load_tables(const char *encoding) +{ + FILE *fp; + int i, saverr, chains; + uint32_t u32; + char strbuf[STR_LEN], buf[PATH_MAX]; + void *TMP_substitute_table, *TMP_char_pri_table, *TMP_chain_pri_table; + static char collate_encoding[ENCODING_LEN + 1]; + + /* 'encoding' must be already checked. */ + if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) { + __collate_load_error = 1; + return (_LDP_CACHE); + } + + /* + * If the locale name is the same as our cache, use the cache. + */ + if (strcmp(encoding, collate_encoding) == 0) { + __collate_load_error = 0; + return (_LDP_CACHE); + } + + /* + * Slurp the locale file into the cache. + */ + + /* 'PathLocale' must be already set & checked. */ + /* Range checking not needed, encoding has fixed size */ + (void)strcpy(buf, _PathLocale); + (void)strcat(buf, "/"); + (void)strcat(buf, encoding); + (void)strcat(buf, "/LC_COLLATE"); + if ((fp = fopen(buf, "r")) == NULL) + return (_LDP_ERROR); + + if (fread(strbuf, sizeof(strbuf), 1, fp) != 1) { + saverr = errno; + (void)fclose(fp); + errno = saverr; + return (_LDP_ERROR); + } + chains = -1; + if (strcmp(strbuf, COLLATE_VERSION) == 0) + chains = 0; + else if (strcmp(strbuf, COLLATE_VERSION1_1) == 0) + chains = 1; + if (chains < 0) { + (void)fclose(fp); + errno = EFTYPE; + return (_LDP_ERROR); + } + if (chains) { + if (fread(&u32, sizeof(u32), 1, fp) != 1) { + saverr = errno; + (void)fclose(fp); + errno = saverr; + return (_LDP_ERROR); + } + if ((chains = (int)ntohl(u32)) < 1) { + (void)fclose(fp); + errno = EFTYPE; + return (_LDP_ERROR); + } + } else + chains = TABLE_SIZE; + + if ((TMP_substitute_table = + malloc(sizeof(__collate_substitute_table))) == NULL) { + saverr = errno; + (void)fclose(fp); + errno = saverr; + return (_LDP_ERROR); + } + if ((TMP_char_pri_table = + malloc(sizeof(__collate_char_pri_table))) == NULL) { + saverr = errno; + free(TMP_substitute_table); + (void)fclose(fp); + errno = saverr; + return (_LDP_ERROR); + } + if ((TMP_chain_pri_table = + malloc(sizeof(*__collate_chain_pri_table) * chains)) == NULL) { + saverr = errno; + free(TMP_substitute_table); + free(TMP_char_pri_table); + (void)fclose(fp); + errno = saverr; + return (_LDP_ERROR); + } + +#define FREAD(a, b, c, d) \ +{ \ + if (fread(a, b, c, d) != c) { \ + saverr = errno; \ + free(TMP_substitute_table); \ + free(TMP_char_pri_table); \ + free(TMP_chain_pri_table); \ + (void)fclose(d); \ + errno = saverr; \ + return (_LDP_ERROR); \ + } \ +} + + FREAD(TMP_substitute_table, sizeof(__collate_substitute_table), 1, fp); + FREAD(TMP_char_pri_table, sizeof(__collate_char_pri_table), 1, fp); + FREAD(TMP_chain_pri_table, + sizeof(*__collate_chain_pri_table), chains, fp); + (void)fclose(fp); + + (void)strcpy(collate_encoding, encoding); + if (__collate_substitute_table_ptr != NULL) + free(__collate_substitute_table_ptr); + __collate_substitute_table_ptr = TMP_substitute_table; + if (__collate_char_pri_table_ptr != NULL) + free(__collate_char_pri_table_ptr); + __collate_char_pri_table_ptr = TMP_char_pri_table; + if (__collate_chain_pri_table != NULL) + free(__collate_chain_pri_table); + __collate_chain_pri_table = TMP_chain_pri_table; + + __collate_substitute_nontrivial = 0; + for (i = 0; i < UCHAR_MAX + 1; i++) { + if (__collate_substitute_table[i][0] != i || + __collate_substitute_table[i][1] != 0) { + __collate_substitute_nontrivial = 1; + break; + } + } + __collate_load_error = 0; + + return (_LDP_LOADED); +} + +u_char * +__collate_substitute(s) + const u_char *s; +{ + int dest_len, len, nlen; + int delta = strlen(s); + u_char *dest_str = NULL; + + if (s == NULL || *s == '\0') + return (__collate_strdup("")); + delta += delta / 8; + dest_str = malloc(dest_len = delta); + if (dest_str == NULL) + __collate_err(EX_OSERR, __FUNCTION__); + len = 0; + while (*s) { + nlen = len + strlen(__collate_substitute_table[*s]); + if (dest_len <= nlen) { + dest_str = reallocf(dest_str, dest_len = nlen + delta); + if (dest_str == NULL) + __collate_err(EX_OSERR, __FUNCTION__); + } + (void)strcpy(dest_str + len, __collate_substitute_table[*s++]); + len = nlen; + } + return (dest_str); +} + +void +__collate_lookup(t, len, prim, sec) + const u_char *t; + int *len, *prim, *sec; +{ + struct __collate_st_chain_pri *p2; + + *len = 1; + *prim = *sec = 0; + for (p2 = __collate_chain_pri_table; p2->str[0] != '\0'; p2++) { + if (*t == p2->str[0] && + strncmp(t, p2->str, strlen(p2->str)) == 0) { + *len = strlen(p2->str); + *prim = p2->prim; + *sec = p2->sec; + return; + } + } + *prim = __collate_char_pri_table[*t].prim; + *sec = __collate_char_pri_table[*t].sec; +} + +u_char * +__collate_strdup(s) + u_char *s; +{ + u_char *t = strdup(s); + + if (t == NULL) + __collate_err(EX_OSERR, __FUNCTION__); + return (t); +} + +void +__collate_err(int ex, const char *f) +{ + const char *s; + int serrno = errno; + + s = _getprogname(); + _write(STDERR_FILENO, s, strlen(s)); + _write(STDERR_FILENO, ": ", 2); + s = f; + _write(STDERR_FILENO, s, strlen(s)); + _write(STDERR_FILENO, ": ", 2); + s = strerror(serrno); + _write(STDERR_FILENO, s, strlen(s)); + _write(STDERR_FILENO, "\n", 1); + exit(ex); +} + +#ifdef COLLATE_DEBUG +void +__collate_print_tables() +{ + int i; + struct __collate_st_chain_pri *p2; + + printf("Substitute table:\n"); + for (i = 0; i < UCHAR_MAX + 1; i++) + if (i != *__collate_substitute_table[i]) + printf("\t'%c' --> \"%s\"\n", i, + __collate_substitute_table[i]); + printf("Chain priority table:\n"); + for (p2 = __collate_chain_pri_table; p2->str[0] != '\0'; p2++) + printf("\t\"%s\" : %d %d\n", p2->str, p2->prim, p2->sec); + printf("Char priority table:\n"); + for (i = 0; i < UCHAR_MAX + 1; i++) + printf("\t'%c' : %d %d\n", i, __collate_char_pri_table[i].prim, + __collate_char_pri_table[i].sec); +} +#endif diff --git a/src/lib/libc/locale/collate.h b/src/lib/libc/locale/collate.h new file mode 100644 index 0000000..4d55f9c --- /dev/null +++ b/src/lib/libc/locale/collate.h @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 1995 Alex Tatmanjants + * at Electronni Visti IA, Kiev, Ukraine. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/locale/collate.h,v 1.14 2002/08/30 20:26:02 ache Exp $ + */ + +#ifndef _COLLATE_H_ +#define _COLLATE_H_ + +#include +#include +#include + +#define STR_LEN 10 +#define TABLE_SIZE 100 +#define COLLATE_VERSION "1.0\n" +#define COLLATE_VERSION1_1 "1.1\n" + +struct __collate_st_char_pri { + int prim, sec; +}; +struct __collate_st_chain_pri { + u_char str[STR_LEN]; + int prim, sec; +}; + +extern int __collate_load_error; +extern int __collate_substitute_nontrivial; +#define __collate_substitute_table (*__collate_substitute_table_ptr) +extern u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; +#define __collate_char_pri_table (*__collate_char_pri_table_ptr) +extern struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1]; +extern struct __collate_st_chain_pri *__collate_chain_pri_table; + +__BEGIN_DECLS +u_char *__collate_strdup(u_char *); +u_char *__collate_substitute(const u_char *); +int __collate_load_tables(const char *); +void __collate_lookup(const u_char *, int *, int *, int *); +int __collate_range_cmp(int, int); +#ifdef COLLATE_DEBUG +void __collate_print_tables(void); +#endif +__END_DECLS + +#endif /* !_COLLATE_H_ */ diff --git a/src/lib/libc/locale/collcmp.c b/src/lib/libc/locale/collcmp.c new file mode 100644 index 0000000..8cbd213 --- /dev/null +++ b/src/lib/libc/locale/collcmp.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/collcmp.c,v 1.17 2003/08/03 19:28:23 ache Exp $"); + +#include +#include "collate.h" + +/* + * Compare two characters using collate + */ + +int __collate_range_cmp(c1, c2) + int c1, c2; +{ + static char s1[2], s2[2]; + + s1[0] = c1; + s2[0] = c2; + return (strcoll(s1, s2)); +} diff --git a/src/lib/libc/locale/euc.c b/src/lib/libc/locale/euc.c new file mode 100644 index 0000000..18d4bfc --- /dev/null +++ b/src/lib/libc/locale/euc.c @@ -0,0 +1,249 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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[] = "@(#)euc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/euc.c,v 1.18 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include +#include +#include +#include +#include +#include "mblocal.h" + +int _EUC_init(_RuneLocale *); +size_t _EUC_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _EUC_mbsinit(const mbstate_t *); +size_t _EUC_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + int count[4]; + wchar_t bits[4]; + wchar_t mask; +} _EucInfo; + +typedef struct { + int count; + u_char bytes[MB_LEN_MAX]; +} _EucState; + +int +_EUC_init(_RuneLocale *rl) +{ + _EucInfo *ei; + int x, new__mb_cur_max; + char *v, *e; + + if (rl->variable == NULL) + return (EFTYPE); + + v = (char *)rl->variable; + + while (*v == ' ' || *v == '\t') + ++v; + + if ((ei = malloc(sizeof(_EucInfo))) == NULL) + return (errno == 0 ? ENOMEM : errno); + + new__mb_cur_max = 0; + for (x = 0; x < 4; ++x) { + ei->count[x] = (int)strtol(v, &e, 0); + if (v == e || !(v = e)) { + free(ei); + return (EFTYPE); + } + if (new__mb_cur_max < ei->count[x]) + new__mb_cur_max = ei->count[x]; + while (*v == ' ' || *v == '\t') + ++v; + ei->bits[x] = (int)strtol(v, &e, 0); + if (v == e || !(v = e)) { + free(ei); + return (EFTYPE); + } + while (*v == ' ' || *v == '\t') + ++v; + } + ei->mask = (int)strtol(v, &e, 0); + if (v == e || !(v = e)) { + free(ei); + return (EFTYPE); + } + rl->variable = ei; + rl->variable_len = sizeof(_EucInfo); + _CurrentRuneLocale = rl; + __mb_cur_max = new__mb_cur_max; + __mbrtowc = _EUC_mbrtowc; + __wcrtomb = _EUC_wcrtomb; + __mbsinit = _EUC_mbsinit; + return (0); +} + +int +_EUC_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _EucState *)ps)->count == 0); +} + +#define CEI ((_EucInfo *)(_CurrentRuneLocale->variable)) + +#define _SS2 0x008e +#define _SS3 0x008f + +#define GR_BITS 0x80808080 /* XXX: to be fixed */ + +static __inline int +_euc_set(u_int c) +{ + c &= 0xff; + return ((c & 0x80) ? c == _SS3 ? 3 : c == _SS2 ? 2 : 1 : 0); +} + +size_t +_EUC_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps) +{ + _EucState *es; + int len, ocount, remain, set; + wchar_t wc; + size_t ncopy; + + es = (_EucState *)ps; + + if (es->count < 0 || es->count > sizeof(es->bytes)) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(es->bytes) - es->count); + memcpy(es->bytes + es->count, s, ncopy); + ocount = es->count; + es->count += ncopy; + s = (char *)es->bytes; + n = es->count; + + if (n == 0 || (size_t)(len = CEI->count[set = _euc_set(*s)]) > n) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + wc = 0; + remain = len; + switch (set) { + case 3: + case 2: + --remain; + ++s; + /* FALLTHROUGH */ + case 1: + case 0: + wc = (unsigned char)*s++; + while (--remain > 0) { + if (*s == '\0') { + errno = EILSEQ; + return ((size_t)-1); + } + wc = (wc << 8) | (unsigned char)*s++; + } + break; + } + wc = (wc & ~CEI->mask) | CEI->bits[set]; + if (pwc != NULL) + *pwc = wc; + es->count = 0; + return (wc == L'\0' ? 0 : len - ocount); +} + +size_t +_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _EucState *es; + wchar_t m, nm; + int i, len; + + es = (_EucState *)ps; + + if (es->count != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + + m = wc & CEI->mask; + nm = wc & ~m; + + if (m == CEI->bits[1]) { +CodeSet1: + /* Codeset 1: The first byte must have 0x80 in it. */ + i = len = CEI->count[1]; + while (i-- > 0) + *s++ = (nm >> (i << 3)) | 0x80; + } else { + if (m == CEI->bits[0]) + i = len = CEI->count[0]; + else if (m == CEI->bits[2]) { + i = len = CEI->count[2]; + *s++ = _SS2; + --i; + /* SS2 designates G2 into GR */ + nm |= GR_BITS; + } else if (m == CEI->bits[3]) { + i = len = CEI->count[3]; + *s++ = _SS3; + --i; + /* SS3 designates G3 into GR */ + nm |= GR_BITS; + } else + goto CodeSet1; /* Bletch */ + while (i-- > 0) + *s++ = (nm >> (i << 3)) & 0xff; + } + return (len); +} diff --git a/src/lib/libc/locale/fix_grouping.c b/src/lib/libc/locale/fix_grouping.c new file mode 100644 index 0000000..ab08f3f --- /dev/null +++ b/src/lib/libc/locale/fix_grouping.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/fix_grouping.c,v 1.8 2003/06/26 10:46:16 phantom Exp $"); + +#include +#include +#include + +static const char nogrouping[] = { CHAR_MAX, '\0' }; + +/* + * Internal helper used to convert grouping sequences from string + * representation into POSIX specified form, i.e. + * + * "3;3;-1" -> "\003\003\177\000" + */ + +const char * +__fix_locale_grouping_str(const char *str) +{ + char *src, *dst; + char n; + + if (str == NULL || *str == '\0') { + return nogrouping; + } + + for (src = (char*)str, dst = (char*)str; *src != '\0'; src++) { + + /* input string examples: "3;3", "3;2;-1" */ + if (*src == ';') + continue; + + if (*src == '-' && *(src+1) == '1') { + *dst++ = CHAR_MAX; + src++; + continue; + } + + if (!isdigit((unsigned char)*src)) { + /* broken grouping string */ + return nogrouping; + } + + /* assume all numbers <= 99 */ + n = *src - '0'; + if (isdigit((unsigned char)*(src+1))) { + src++; + n *= 10; + n += *src - '0'; + } + + *dst = n; + /* NOTE: assume all input started with "0" as 'no grouping' */ + if (*dst == '\0') + return (dst == (char*)str) ? nogrouping : str; + dst++; + } + *dst = '\0'; + return str; +} diff --git a/src/lib/libc/locale/frune.c b/src/lib/libc/locale/frune.c new file mode 100644 index 0000000..34d4a56 --- /dev/null +++ b/src/lib/libc/locale/frune.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2003 Tim J. Robbins. All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +/* f*rune() are obsolete in FreeBSD 6 -- use ANSI functions instead. */ +#define OBSOLETE_IN_6 + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)frune.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/frune.c,v 1.5 2003/10/31 10:55:19 tjr Exp $"); + +#include +#include +#include +#include +#include + +__warn_references(fgetrune, "warning: fgetrune() is deprecated. See fgetrune(3)."); +long +fgetrune(fp) + FILE *fp; +{ + wint_t ch; + + if ((ch = fgetwc(fp)) == WEOF) + return (feof(fp) ? EOF : _INVALID_RUNE); + return ((long)ch); +} + +__warn_references(fungetrune, "warning: fungetrune() is deprecated. See fungetrune(3)."); +int +fungetrune(r, fp) + rune_t r; + FILE* fp; +{ + + return (ungetwc((wint_t)r, fp) == WEOF ? EOF : 0); +} + +__warn_references(fputrune, "warning: fputrune() is deprecated. See fputrune(3)."); +int +fputrune(r, fp) + rune_t r; + FILE *fp; +{ + + return (fputwc((wchar_t)r, fp) == WEOF ? EOF : 0); +} diff --git a/src/lib/libc/locale/gb18030.c b/src/lib/libc/locale/gb18030.c new file mode 100644 index 0000000..192b0f6 --- /dev/null +++ b/src/lib/libc/locale/gb18030.c @@ -0,0 +1,218 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ +/* + * PRC National Standard GB 18030-2000 encoding of Chinese text. + * + * See gb18030(5) for details. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/gb18030.c,v 1.6 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +int _GB18030_init(_RuneLocale *); +size_t _GB18030_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _GB18030_mbsinit(const mbstate_t *); +size_t _GB18030_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + int count; + u_char bytes[4]; +} _GB18030State; + +int +_GB18030_init(_RuneLocale *rl) +{ + + __mbrtowc = _GB18030_mbrtowc; + __wcrtomb = _GB18030_wcrtomb; + __mbsinit = _GB18030_mbsinit; + _CurrentRuneLocale = rl; + __mb_cur_max = 4; + + return (0); +} + +int +_GB18030_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _GB18030State *)ps)->count == 0); +} + +size_t +_GB18030_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, + size_t n, mbstate_t * __restrict ps) +{ + _GB18030State *gs; + wchar_t wch; + int ch, len, ocount; + size_t ncopy; + + gs = (_GB18030State *)ps; + + if (gs->count < 0 || gs->count > sizeof(gs->bytes)) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(gs->bytes) - gs->count); + memcpy(gs->bytes + gs->count, s, ncopy); + ocount = gs->count; + gs->count += ncopy; + s = (char *)gs->bytes; + n = gs->count; + + if (n == 0) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + + /* + * Single byte: [00-7f] + * Two byte: [81-fe][40-7e,80-fe] + * Four byte: [81-fe][30-39][81-fe][30-39] + */ + ch = (unsigned char)*s++; + if (ch <= 0x7f) { + len = 1; + wch = ch; + } else if (ch >= 0x81 && ch <= 0xfe) { + wch = ch; + if (n < 2) + return ((size_t)-2); + ch = (unsigned char)*s++; + if ((ch >= 0x40 && ch <= 0x7e) || (ch >= 0x80 && ch <= 0xfe)) { + wch = (wch << 8) | ch; + len = 2; + } else if (ch >= 0x30 && ch <= 0x39) { + /* + * Strip high bit off the wide character we will + * eventually output so that it is positive when + * cast to wint_t on 32-bit twos-complement machines. + */ + wch = ((wch & 0x7f) << 8) | ch; + if (n < 3) + return ((size_t)-2); + ch = (unsigned char)*s++; + if (ch < 0x81 || ch > 0xfe) + goto ilseq; + wch = (wch << 8) | ch; + if (n < 4) + return ((size_t)-2); + ch = (unsigned char)*s++; + if (ch < 0x30 || ch > 0x39) + goto ilseq; + wch = (wch << 8) | ch; + len = 4; + } else + goto ilseq; + } else + goto ilseq; + + if (pwc != NULL) + *pwc = wch; + gs->count = 0; + return (wch == L'\0' ? 0 : len - ocount); +ilseq: + errno = EILSEQ; + return ((size_t)-1); +} + +size_t +_GB18030_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _GB18030State *gs; + size_t len; + int c; + + gs = (_GB18030State *)ps; + + if (gs->count != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + if ((wc & ~0x7fffffff) != 0) + goto ilseq; + if (wc & 0x7f000000) { + /* Replace high bit that mbrtowc() removed. */ + wc |= 0x80000000; + c = (wc >> 24) & 0xff; + if (c < 0x81 || c > 0xfe) + goto ilseq; + *s++ = c; + c = (wc >> 16) & 0xff; + if (c < 0x30 || c > 0x39) + goto ilseq; + *s++ = c; + c = (wc >> 8) & 0xff; + if (c < 0x81 || c > 0xfe) + goto ilseq; + *s++ = c; + c = wc & 0xff; + if (c < 0x30 || c > 0x39) + goto ilseq; + *s++ = c; + len = 4; + } else if (wc & 0x00ff0000) + goto ilseq; + else if (wc & 0x0000ff00) { + c = (wc >> 8) & 0xff; + if (c < 0x81 || c > 0xfe) + goto ilseq; + *s++ = c; + c = wc & 0xff; + if (c < 0x40 || c == 0x7f || c == 0xff) + goto ilseq; + *s++ = c; + len = 2; + } else if (wc <= 0x7f) { + *s++ = wc; + len = 1; + } else + goto ilseq; + + return (len); +ilseq: + errno = EILSEQ; + return ((size_t)-1); +} diff --git a/src/lib/libc/locale/gb2312.c b/src/lib/libc/locale/gb2312.c new file mode 100644 index 0000000..4cf94b7 --- /dev/null +++ b/src/lib/libc/locale/gb2312.c @@ -0,0 +1,154 @@ +/*- + * Copyright (c) 2004 Tim J. Robbins. All rights reserved. + * Copyright (c) 2003 David Xu + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/gb2312.c,v 1.8 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +int _GB2312_init(_RuneLocale *); +size_t _GB2312_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _GB2312_mbsinit(const mbstate_t *); +size_t _GB2312_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + int count; + u_char bytes[2]; +} _GB2312State; + +int +_GB2312_init(_RuneLocale *rl) +{ + + _CurrentRuneLocale = rl; + __mbrtowc = _GB2312_mbrtowc; + __wcrtomb = _GB2312_wcrtomb; + __mbsinit = _GB2312_mbsinit; + __mb_cur_max = 2; + return (0); +} + +int +_GB2312_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _GB2312State *)ps)->count == 0); +} + +static __inline int +_GB2312_check(const char *str, size_t n) +{ + const u_char *s = (const u_char *)str; + + if (n == 0) + /* Incomplete multibyte sequence */ + return (-2); + if (s[0] >= 0xa1 && s[0] <= 0xfe) { + if (n < 2) + /* Incomplete multibyte sequence */ + return (-2); + if (s[1] < 0xa1 || s[1] > 0xfe) + /* Invalid multibyte sequence */ + return (-1); + return (2); + } else if (s[0] & 0x80) { + /* Invalid multibyte sequence */ + return (-1); + } + return (1); +} + +size_t +_GB2312_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps) +{ + _GB2312State *gs; + wchar_t wc; + int i, len, ocount; + size_t ncopy; + + gs = (_GB2312State *)ps; + + if (gs->count < 0 || gs->count > sizeof(gs->bytes)) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(gs->bytes) - gs->count); + memcpy(gs->bytes + gs->count, s, ncopy); + ocount = gs->count; + gs->count += ncopy; + s = (char *)gs->bytes; + n = gs->count; + + if ((len = _GB2312_check(s, n)) < 0) + return ((size_t)len); + wc = 0; + i = len; + while (i-- > 0) + wc = (wc << 8) | (unsigned char)*s++; + if (pwc != NULL) + *pwc = wc; + gs->count = 0; + return (wc == L'\0' ? 0 : len - ocount); +} + +size_t +_GB2312_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _GB2312State *gs; + + gs = (_GB2312State *)ps; + + if (gs->count != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + if (wc & 0x8000) { + *s++ = (wc >> 8) & 0xff; + *s = wc & 0xff; + return (2); + } + *s = wc & 0xff; + return (1); +} diff --git a/src/lib/libc/locale/gbk.c b/src/lib/libc/locale/gbk.c new file mode 100644 index 0000000..6adcc41 --- /dev/null +++ b/src/lib/libc/locale/gbk.c @@ -0,0 +1,168 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/gbk.c,v 1.11 2004/05/17 11:16:14 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +int _GBK_init(_RuneLocale *); +size_t _GBK_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _GBK_mbsinit(const mbstate_t *); +size_t _GBK_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + wchar_t ch; +} _GBKState; + +int +_GBK_init(_RuneLocale *rl) +{ + + __mbrtowc = _GBK_mbrtowc; + __wcrtomb = _GBK_wcrtomb; + __mbsinit = _GBK_mbsinit; + _CurrentRuneLocale = rl; + __mb_cur_max = 2; + return (0); +} + +int +_GBK_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _GBKState *)ps)->ch == 0); +} + +static __inline int +_gbk_check(u_int c) +{ + + c &= 0xff; + return ((c >= 0x81 && c <= 0xfe) ? 2 : 1); +} + +size_t +_GBK_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps) +{ + _GBKState *gs; + wchar_t wc; + size_t len; + + gs = (_GBKState *)ps; + + if ((gs->ch & ~0xFF) != 0) { + /* Bad conversion state. */ + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + if (n == 0) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + + if (gs->ch != 0) { + if (*s == '\0') { + errno = EILSEQ; + return ((size_t)-1); + } + wc = (gs->ch << 8) | (*s & 0xFF); + if (pwc != NULL) + *pwc = wc; + gs->ch = 0; + return (1); + } + + len = (size_t)_gbk_check(*s); + wc = *s++ & 0xff; + if (len == 2) { + if (n < 2) { + /* Incomplete multibyte sequence */ + gs->ch = wc; + return ((size_t)-2); + } + if (*s == '\0') { + errno = EILSEQ; + return ((size_t)-1); + } + wc = (wc << 8) | (*s++ & 0xff); + if (pwc != NULL) + *pwc = wc; + return (2); + } else { + if (pwc != NULL) + *pwc = wc; + return (wc == L'\0' ? 0 : 1); + } +} + +size_t +_GBK_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _GBKState *gs; + + gs = (_GBKState *)ps; + + if (gs->ch != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + if (wc & 0x8000) { + *s++ = (wc >> 8) & 0xff; + *s = wc & 0xff; + return (2); + } + *s = wc & 0xff; + return (1); +} diff --git a/src/lib/libc/locale/isctype.c b/src/lib/libc/locale/isctype.c new file mode 100644 index 0000000..d718b77 --- /dev/null +++ b/src/lib/libc/locale/isctype.c @@ -0,0 +1,233 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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[] = "@(#)isctype.c 8.3 (Berkeley) 2/24/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/isctype.c,v 1.9 2002/08/17 20:03:44 ache Exp $"); + +#include + +#undef digittoint +int +digittoint(c) + int c; +{ + return (__maskrune(c, 0xFF)); +} + +#undef isalnum +int +isalnum(c) + int c; +{ + return (__istype(c, _CTYPE_A|_CTYPE_D)); +} + +#undef isalpha +int +isalpha(c) + int c; +{ + return (__istype(c, _CTYPE_A)); +} + +#undef isascii +int +isascii(c) + int c; +{ + return ((c & ~0x7F) == 0); +} + +#undef isblank +int +isblank(c) + int c; +{ + return (__istype(c, _CTYPE_B)); +} + +#undef iscntrl +int +iscntrl(c) + int c; +{ + return (__istype(c, _CTYPE_C)); +} + +#undef isdigit +int +isdigit(c) + int c; +{ + return (__isctype(c, _CTYPE_D)); +} + +#undef isgraph +int +isgraph(c) + int c; +{ + return (__istype(c, _CTYPE_G)); +} + +#undef ishexnumber +int +ishexnumber(c) + int c; +{ + return (__istype(c, _CTYPE_X)); +} + +#undef isideogram +int +isideogram(c) + int c; +{ + return (__istype(c, _CTYPE_I)); +} + +#undef islower +int +islower(c) + int c; +{ + return (__istype(c, _CTYPE_L)); +} + +#undef isnumber +int +isnumber(c) + int c; +{ + return (__istype(c, _CTYPE_D)); +} + +#undef isphonogram +int +isphonogram(c) + int c; +{ + return (__istype(c, _CTYPE_Q)); +} + +#undef isprint +int +isprint(c) + int c; +{ + return (__istype(c, _CTYPE_R)); +} + +#undef ispunct +int +ispunct(c) + int c; +{ + return (__istype(c, _CTYPE_P)); +} + +#undef isrune +int +isrune(c) + int c; +{ + return (__istype(c, 0xFFFFFF00L)); +} + +#undef isspace +int +isspace(c) + int c; +{ + return (__istype(c, _CTYPE_S)); +} + +#undef isspecial +int +isspecial(c) + int c; +{ + return (__istype(c, _CTYPE_T)); +} + +#undef isupper +int +isupper(c) + int c; +{ + return (__istype(c, _CTYPE_U)); +} + +#undef isxdigit +int +isxdigit(c) + int c; +{ + return (__isctype(c, _CTYPE_X)); +} + +#undef toascii +int +toascii(c) + int c; +{ + return (c & 0x7F); +} + +#undef tolower +int +tolower(c) + int c; +{ + return (__tolower(c)); +} + +#undef toupper +int +toupper(c) + int c; +{ + return (__toupper(c)); +} + diff --git a/src/lib/libc/locale/iswctype.c b/src/lib/libc/locale/iswctype.c new file mode 100644 index 0000000..37e2656 --- /dev/null +++ b/src/lib/libc/locale/iswctype.c @@ -0,0 +1,214 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/iswctype.c,v 1.6 2002/08/17 20:30:34 ache Exp $"); + +#include + +#undef iswalnum +int +iswalnum(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_A|_CTYPE_D)); +} + +#undef iswalpha +int +iswalpha(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_A)); +} + +#undef iswascii +int +iswascii(wc) + wint_t wc; +{ + return ((wc & ~0x7F) == 0); +} + +#undef iswblank +int +iswblank(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_B)); +} + +#undef iswcntrl +int +iswcntrl(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_C)); +} + +#undef iswdigit +int +iswdigit(wc) + wint_t wc; +{ + return (__isctype(wc, _CTYPE_D)); +} + +#undef iswgraph +int +iswgraph(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_G)); +} + +#undef iswhexnumber +int +iswhexnumber(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_X)); +} + +#undef iswideogram +int +iswideogram(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_I)); +} + +#undef iswlower +int +iswlower(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_L)); +} + +#undef iswnumber +int +iswnumber(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_D)); +} + +#undef iswphonogram +int +iswphonogram(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_Q)); +} + +#undef iswprint +int +iswprint(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_R)); +} + +#undef iswpunct +int +iswpunct(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_P)); +} + +#undef iswrune +int +iswrune(wc) + wint_t wc; +{ + return (__istype(wc, 0xFFFFFF00L)); +} + +#undef iswspace +int +iswspace(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_S)); +} + +#undef iswspecial +int +iswspecial(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_T)); +} + +#undef iswupper +int +iswupper(wc) + wint_t wc; +{ + return (__istype(wc, _CTYPE_U)); +} + +#undef iswxdigit +int +iswxdigit(wc) + wint_t wc; +{ + return (__isctype(wc, _CTYPE_X)); +} + +#undef towlower +wint_t +towlower(wc) + wint_t wc; +{ + return (__tolower(wc)); +} + +#undef towupper +wint_t +towupper(wc) + wint_t wc; +{ + return (__toupper(wc)); +} + diff --git a/src/lib/libc/locale/ldpart.c b/src/lib/libc/locale/ldpart.c new file mode 100644 index 0000000..932165f --- /dev/null +++ b/src/lib/libc/locale/ldpart.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/ldpart.c,v 1.15 2004/04/25 19:56:50 ache Exp $"); + +#include "namespace.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "ldpart.h" +#include "setlocale.h" + +static int split_lines(char *, const char *); + +int +__part_load_locale(const char *name, + int *using_locale, + char **locale_buf, + const char *category_filename, + int locale_buf_size_max, + int locale_buf_size_min, + const char **dst_localebuf) +{ + int saverr, fd, i, num_lines; + char *lbuf, *p; + const char *plim; + char filename[PATH_MAX]; + struct stat st; + size_t namesize, bufsize; + + /* 'name' must be already checked. */ + if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) { + *using_locale = 0; + return (_LDP_CACHE); + } + + /* + * If the locale name is the same as our cache, use the cache. + */ + if (*locale_buf != NULL && strcmp(name, *locale_buf) == 0) { + *using_locale = 1; + return (_LDP_CACHE); + } + + /* + * Slurp the locale file into the cache. + */ + namesize = strlen(name) + 1; + + /* 'PathLocale' must be already set & checked. */ + + /* Range checking not needed, 'name' size is limited */ + strcpy(filename, _PathLocale); + strcat(filename, "/"); + strcat(filename, name); + strcat(filename, "/"); + strcat(filename, category_filename); + if ((fd = _open(filename, O_RDONLY)) < 0) + return (_LDP_ERROR); + if (_fstat(fd, &st) != 0) + goto bad_locale; + if (st.st_size <= 0) { + errno = EFTYPE; + goto bad_locale; + } + bufsize = namesize + st.st_size; + if ((lbuf = malloc(bufsize)) == NULL) { + errno = ENOMEM; + goto bad_locale; + } + (void)strcpy(lbuf, name); + p = lbuf + namesize; + plim = p + st.st_size; + if (_read(fd, p, (size_t) st.st_size) != st.st_size) + goto bad_lbuf; + /* + * Parse the locale file into localebuf. + */ + if (plim[-1] != '\n') { + errno = EFTYPE; + goto bad_lbuf; + } + num_lines = split_lines(p, plim); + if (num_lines >= locale_buf_size_max) + num_lines = locale_buf_size_max; + else if (num_lines >= locale_buf_size_min) + num_lines = locale_buf_size_min; + else { + errno = EFTYPE; + goto bad_lbuf; + } + (void)_close(fd); + /* + * Record the successful parse in the cache. + */ + if (*locale_buf != NULL) + free(*locale_buf); + *locale_buf = lbuf; + for (p = *locale_buf, i = 0; i < num_lines; i++) + dst_localebuf[i] = (p += strlen(p) + 1); + for (i = num_lines; i < locale_buf_size_max; i++) + dst_localebuf[i] = NULL; + *using_locale = 1; + + return (_LDP_LOADED); + +bad_lbuf: + saverr = errno; + free(lbuf); + errno = saverr; +bad_locale: + saverr = errno; + (void)_close(fd); + errno = saverr; + + return (_LDP_ERROR); +} + +static int +split_lines(char *p, const char *plim) +{ + int i; + + i = 0; + while (p < plim) { + if (*p == '\n') { + *p = '\0'; + i++; + } + p++; + } + return (i); +} + diff --git a/src/lib/libc/locale/ldpart.h b/src/lib/libc/locale/ldpart.h new file mode 100644 index 0000000..02e0c95 --- /dev/null +++ b/src/lib/libc/locale/ldpart.h @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/locale/ldpart.h,v 1.6 2003/06/13 00:14:07 jkh Exp $ + */ + +#ifndef _LDPART_H_ +#define _LDPART_H_ + +#define _LDP_LOADED 0 +#define _LDP_ERROR (-1) +#define _LDP_CACHE 1 + +int __part_load_locale(const char *, int*, char **, const char *, + int, int, const char **); + +#endif /* !_LDPART_H_ */ diff --git a/src/lib/libc/locale/lmessages.c b/src/lib/libc/locale/lmessages.c new file mode 100644 index 0000000..488b572 --- /dev/null +++ b/src/lib/libc/locale/lmessages.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/lmessages.c,v 1.14 2003/06/26 10:46:16 phantom Exp $"); + +#include + +#include "ldpart.h" +#include "lmessages.h" + +#define LCMESSAGES_SIZE_FULL (sizeof(struct lc_messages_T) / sizeof(char *)) +#define LCMESSAGES_SIZE_MIN \ + (offsetof(struct lc_messages_T, yesstr) / sizeof(char *)) + +static char empty[] = ""; + +static const struct lc_messages_T _C_messages_locale = { + "^[yY]" , /* yesexpr */ + "^[nN]" , /* noexpr */ + "yes" , /* yesstr */ + "no" /* nostr */ +}; + +static struct lc_messages_T _messages_locale; +static int _messages_using_locale; +static char *_messages_locale_buf; + +int +__messages_load_locale(const char *name) +{ + int ret; + + ret = __part_load_locale(name, &_messages_using_locale, + &_messages_locale_buf, "LC_MESSAGES", + LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN, + (const char **)&_messages_locale); + if (ret == _LDP_LOADED) { + if (_messages_locale.yesstr == NULL) + _messages_locale.yesstr = empty; + if (_messages_locale.nostr == NULL) + _messages_locale.nostr = empty; + } + return (ret); +} + +struct lc_messages_T * +__get_current_messages_locale(void) +{ + return (_messages_using_locale + ? &_messages_locale + : (struct lc_messages_T *)&_C_messages_locale); +} + +#ifdef LOCALE_DEBUG +void +msgdebug() { +printf( "yesexpr = %s\n" + "noexpr = %s\n" + "yesstr = %s\n" + "nostr = %s\n", + _messages_locale.yesexpr, + _messages_locale.noexpr, + _messages_locale.yesstr, + _messages_locale.nostr +); +} +#endif /* LOCALE_DEBUG */ diff --git a/src/lib/libc/locale/lmessages.h b/src/lib/libc/locale/lmessages.h new file mode 100644 index 0000000..ee690ae --- /dev/null +++ b/src/lib/libc/locale/lmessages.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/locale/lmessages.h,v 1.3 2001/12/20 18:28:52 phantom Exp $ + */ + +#ifndef _LMESSAGES_H_ +#define _LMESSAGES_H_ + +struct lc_messages_T { + const char *yesexpr; + const char *noexpr; + const char *yesstr; + const char *nostr; +}; + +struct lc_messages_T *__get_current_messages_locale(void); +int __messages_load_locale(const char *); + +#endif /* !_LMESSAGES_H_ */ diff --git a/src/lib/libc/locale/lmonetary.c b/src/lib/libc/locale/lmonetary.c new file mode 100644 index 0000000..e3e7095 --- /dev/null +++ b/src/lib/libc/locale/lmonetary.c @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/lmonetary.c,v 1.19 2003/06/26 10:46:16 phantom Exp $"); + +#include +#include +#include + +#include "ldpart.h" +#include "lmonetary.h" + +extern int __mlocale_changed; +extern const char * __fix_locale_grouping_str(const char *); + +#define LCMONETARY_SIZE_FULL (sizeof(struct lc_monetary_T) / sizeof(char *)) +#define LCMONETARY_SIZE_MIN \ + (offsetof(struct lc_monetary_T, int_p_cs_precedes) / \ + sizeof(char *)) + +static char empty[] = ""; +static char numempty[] = { CHAR_MAX, '\0'}; + +static const struct lc_monetary_T _C_monetary_locale = { + empty, /* int_curr_symbol */ + empty, /* currency_symbol */ + empty, /* mon_decimal_point */ + empty, /* mon_thousands_sep */ + numempty, /* mon_grouping */ + empty, /* positive_sign */ + empty, /* negative_sign */ + numempty, /* int_frac_digits */ + numempty, /* frac_digits */ + numempty, /* p_cs_precedes */ + numempty, /* p_sep_by_space */ + numempty, /* n_cs_precedes */ + numempty, /* n_sep_by_space */ + numempty, /* p_sign_posn */ + numempty, /* n_sign_posn */ + numempty, /* int_p_cs_precedes */ + numempty, /* int_n_cs_precedes */ + numempty, /* int_p_sep_by_space */ + numempty, /* int_n_sep_by_space */ + numempty, /* int_p_sign_posn */ + numempty /* int_n_sign_posn */ +}; + +static struct lc_monetary_T _monetary_locale; +static int _monetary_using_locale; +static char *_monetary_locale_buf; + +static char +cnv(const char *str) +{ + int i = strtol(str, NULL, 10); + + if (i == -1) + i = CHAR_MAX; + return ((char)i); +} + +int +__monetary_load_locale(const char *name) +{ + int ret; + + ret = __part_load_locale(name, &_monetary_using_locale, + &_monetary_locale_buf, "LC_MONETARY", + LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN, + (const char **)&_monetary_locale); + if (ret != _LDP_ERROR) + __mlocale_changed = 1; + if (ret == _LDP_LOADED) { + _monetary_locale.mon_grouping = + __fix_locale_grouping_str(_monetary_locale.mon_grouping); + +#define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \ + cnv(_monetary_locale.NAME)) + + M_ASSIGN_CHAR(int_frac_digits); + M_ASSIGN_CHAR(frac_digits); + M_ASSIGN_CHAR(p_cs_precedes); + M_ASSIGN_CHAR(p_sep_by_space); + M_ASSIGN_CHAR(n_cs_precedes); + M_ASSIGN_CHAR(n_sep_by_space); + M_ASSIGN_CHAR(p_sign_posn); + M_ASSIGN_CHAR(n_sign_posn); + + /* + * The six additional C99 international monetary formatting + * parameters default to the national parameters when + * reading FreeBSD LC_MONETARY data files. + */ +#define M_ASSIGN_ICHAR(NAME) \ + do { \ + if (_monetary_locale.int_##NAME == NULL) \ + _monetary_locale.int_##NAME = \ + _monetary_locale.NAME; \ + else \ + M_ASSIGN_CHAR(int_##NAME); \ + } while (0) + + M_ASSIGN_ICHAR(p_cs_precedes); + M_ASSIGN_ICHAR(n_cs_precedes); + M_ASSIGN_ICHAR(p_sep_by_space); + M_ASSIGN_ICHAR(n_sep_by_space); + M_ASSIGN_ICHAR(p_sign_posn); + M_ASSIGN_ICHAR(n_sign_posn); + } + return (ret); +} + +struct lc_monetary_T * +__get_current_monetary_locale(void) +{ + return (_monetary_using_locale + ? &_monetary_locale + : (struct lc_monetary_T *)&_C_monetary_locale); +} + +#ifdef LOCALE_DEBUG +void +monetdebug() { +printf( "int_curr_symbol = %s\n" + "currency_symbol = %s\n" + "mon_decimal_point = %s\n" + "mon_thousands_sep = %s\n" + "mon_grouping = %s\n" + "positive_sign = %s\n" + "negative_sign = %s\n" + "int_frac_digits = %d\n" + "frac_digits = %d\n" + "p_cs_precedes = %d\n" + "p_sep_by_space = %d\n" + "n_cs_precedes = %d\n" + "n_sep_by_space = %d\n" + "p_sign_posn = %d\n" + "n_sign_posn = %d\n", + "int_p_cs_precedes = %d\n" + "int_p_sep_by_space = %d\n" + "int_n_cs_precedes = %d\n" + "int_n_sep_by_space = %d\n" + "int_p_sign_posn = %d\n" + "int_n_sign_posn = %d\n", + _monetary_locale.int_curr_symbol, + _monetary_locale.currency_symbol, + _monetary_locale.mon_decimal_point, + _monetary_locale.mon_thousands_sep, + _monetary_locale.mon_grouping, + _monetary_locale.positive_sign, + _monetary_locale.negative_sign, + _monetary_locale.int_frac_digits[0], + _monetary_locale.frac_digits[0], + _monetary_locale.p_cs_precedes[0], + _monetary_locale.p_sep_by_space[0], + _monetary_locale.n_cs_precedes[0], + _monetary_locale.n_sep_by_space[0], + _monetary_locale.p_sign_posn[0], + _monetary_locale.n_sign_posn[0], + _monetary_locale.int_p_cs_precedes[0], + _monetary_locale.int_p_sep_by_space[0], + _monetary_locale.int_n_cs_precedes[0], + _monetary_locale.int_n_sep_by_space[0], + _monetary_locale.int_p_sign_posn[0], + _monetary_locale.int_n_sign_posn[0] +); +} +#endif /* LOCALE_DEBUG */ diff --git a/src/lib/libc/locale/lmonetary.h b/src/lib/libc/locale/lmonetary.h new file mode 100644 index 0000000..e278ea5 --- /dev/null +++ b/src/lib/libc/locale/lmonetary.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/locale/lmonetary.h,v 1.4 2002/10/09 09:19:28 tjr Exp $ + */ + +#ifndef _LMONETARY_H_ +#define _LMONETARY_H_ + +struct lc_monetary_T { + const char *int_curr_symbol; + const char *currency_symbol; + const char *mon_decimal_point; + const char *mon_thousands_sep; + const char *mon_grouping; + const char *positive_sign; + const char *negative_sign; + const char *int_frac_digits; + const char *frac_digits; + const char *p_cs_precedes; + const char *p_sep_by_space; + const char *n_cs_precedes; + const char *n_sep_by_space; + const char *p_sign_posn; + const char *n_sign_posn; + const char *int_p_cs_precedes; + const char *int_n_cs_precedes; + const char *int_p_sep_by_space; + const char *int_n_sep_by_space; + const char *int_p_sign_posn; + const char *int_n_sign_posn; +}; + +struct lc_monetary_T *__get_current_monetary_locale(void); +int __monetary_load_locale(const char *); + +#endif /* !_LMONETARY_H_ */ diff --git a/src/lib/libc/locale/lnumeric.c b/src/lib/libc/locale/lnumeric.c new file mode 100644 index 0000000..ff9c948 --- /dev/null +++ b/src/lib/libc/locale/lnumeric.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.16 2003/06/26 10:46:16 phantom Exp $"); + +#include + +#include "ldpart.h" +#include "lnumeric.h" + +extern int __nlocale_changed; +extern const char *__fix_locale_grouping_str(const char *); + +#define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *)) + +static char numempty[] = { CHAR_MAX, '\0' }; + +static const struct lc_numeric_T _C_numeric_locale = { + ".", /* decimal_point */ + "", /* thousands_sep */ + numempty /* grouping */ +}; + +static struct lc_numeric_T _numeric_locale; +static int _numeric_using_locale; +static char *_numeric_locale_buf; + +int +__numeric_load_locale(const char *name) +{ + int ret; + + ret = __part_load_locale(name, &_numeric_using_locale, + &_numeric_locale_buf, "LC_NUMERIC", + LCNUMERIC_SIZE, LCNUMERIC_SIZE, + (const char **)&_numeric_locale); + if (ret != _LDP_ERROR) + __nlocale_changed = 1; + if (ret == _LDP_LOADED) { + /* Can't be empty according to C99 */ + if (*_numeric_locale.decimal_point == '\0') + _numeric_locale.decimal_point = + _C_numeric_locale.decimal_point; + _numeric_locale.grouping = + __fix_locale_grouping_str(_numeric_locale.grouping); + } + return (ret); +} + +struct lc_numeric_T * +__get_current_numeric_locale(void) +{ + return (_numeric_using_locale + ? &_numeric_locale + : (struct lc_numeric_T *)&_C_numeric_locale); +} + +#ifdef LOCALE_DEBUG +void +numericdebug(void) { +printf( "decimal_point = %s\n" + "thousands_sep = %s\n" + "grouping = %s\n", + _numeric_locale.decimal_point, + _numeric_locale.thousands_sep, + _numeric_locale.grouping +); +} +#endif /* LOCALE_DEBUG */ diff --git a/src/lib/libc/locale/lnumeric.h b/src/lib/libc/locale/lnumeric.h new file mode 100644 index 0000000..9678c1f --- /dev/null +++ b/src/lib/libc/locale/lnumeric.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/locale/lnumeric.h,v 1.3 2001/12/20 18:28:52 phantom Exp $ + */ + +#ifndef _LNUMERIC_H_ +#define _LNUMERIC_H_ + +struct lc_numeric_T { + const char *decimal_point; + const char *thousands_sep; + const char *grouping; +}; + +struct lc_numeric_T *__get_current_numeric_locale(void); +int __numeric_load_locale(const char *); + +#endif /* !_LNUMERIC_H_ */ diff --git a/src/lib/libc/locale/localeconv.c b/src/lib/libc/locale/localeconv.c new file mode 100644 index 0000000..1420aa8 --- /dev/null +++ b/src/lib/libc/locale/localeconv.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2001 Alexey Zelkin + * Copyright (c) 1991, 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[] = "@(#)localeconv.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.13 2003/06/26 10:46:16 phantom Exp $"); + +#include + +#include "lmonetary.h" +#include "lnumeric.h" + +/* + * The localeconv() function constructs a struct lconv from the current + * monetary and numeric locales. + * + * Because localeconv() may be called many times (especially by library + * routines like printf() & strtod()), the approprate members of the + * lconv structure are computed only when the monetary or numeric + * locale has been changed. + */ +int __mlocale_changed = 1; +int __nlocale_changed = 1; + +/* + * Return the current locale conversion. + */ +struct lconv * +localeconv() +{ + static struct lconv ret; + + if (__mlocale_changed) { + /* LC_MONETARY part */ + struct lc_monetary_T * mptr; + +#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME) +#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0]) + + mptr = __get_current_monetary_locale(); + M_ASSIGN_STR(int_curr_symbol); + M_ASSIGN_STR(currency_symbol); + M_ASSIGN_STR(mon_decimal_point); + M_ASSIGN_STR(mon_thousands_sep); + M_ASSIGN_STR(mon_grouping); + M_ASSIGN_STR(positive_sign); + M_ASSIGN_STR(negative_sign); + M_ASSIGN_CHAR(int_frac_digits); + M_ASSIGN_CHAR(frac_digits); + M_ASSIGN_CHAR(p_cs_precedes); + M_ASSIGN_CHAR(p_sep_by_space); + M_ASSIGN_CHAR(n_cs_precedes); + M_ASSIGN_CHAR(n_sep_by_space); + M_ASSIGN_CHAR(p_sign_posn); + M_ASSIGN_CHAR(n_sign_posn); + M_ASSIGN_CHAR(int_p_cs_precedes); + M_ASSIGN_CHAR(int_n_cs_precedes); + M_ASSIGN_CHAR(int_p_sep_by_space); + M_ASSIGN_CHAR(int_n_sep_by_space); + M_ASSIGN_CHAR(int_p_sign_posn); + M_ASSIGN_CHAR(int_n_sign_posn); + __mlocale_changed = 0; + } + + if (__nlocale_changed) { + /* LC_NUMERIC part */ + struct lc_numeric_T * nptr; + +#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME) + + nptr = __get_current_numeric_locale(); + N_ASSIGN_STR(decimal_point); + N_ASSIGN_STR(thousands_sep); + N_ASSIGN_STR(grouping); + __nlocale_changed = 0; + } + + return (&ret); +} diff --git a/src/lib/libc/locale/mblen.c b/src/lib/libc/locale/mblen.c new file mode 100644 index 0000000..da5264d --- /dev/null +++ b/src/lib/libc/locale/mblen.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mblen.c,v 1.7 2004/05/12 14:26:54 tjr Exp $"); + +#include +#include +#include +#include +#include "mblocal.h" + +int +mblen(const char *s, size_t n) +{ + static const mbstate_t initial; + static mbstate_t mbs; + size_t rval; + + if (s == NULL) { + /* No support for state dependent encodings. */ + mbs = initial; + return (0); + } + rval = __mbrtowc(NULL, s, n, &mbs); + if (rval == (size_t)-1 || rval == (size_t)-2) + return (-1); + if (rval > INT_MAX) { + errno = ERANGE; + return (-1); + } + return ((int)rval); +} diff --git a/src/lib/libc/locale/mblocal.h b/src/lib/libc/locale/mblocal.h new file mode 100644 index 0000000..8146ce1 --- /dev/null +++ b/src/lib/libc/locale/mblocal.h @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/locale/mblocal.h,v 1.2 2004/05/13 11:20:27 tjr Exp $ + */ + +#ifndef _MBLOCAL_H_ +#define _MBLOCAL_H_ + +#include /* XXX for rune_t */ + +/* + * Conversion function pointers for current encoding. + */ +extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, + size_t, mbstate_t * __restrict); +extern int (*__mbsinit)(const mbstate_t *); +extern size_t (*__mbsrtowcs)(wchar_t * __restrict, const char ** __restrict, + size_t, mbstate_t * __restrict); +extern size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict); +extern size_t (*__wcsrtombs)(char * __restrict, const wchar_t ** __restrict, + size_t, mbstate_t * __restrict); + +/* + * Conversion functions for "NONE"/C/POSIX encoding. + */ +extern size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict, + size_t, mbstate_t * __restrict); +extern int _none_mbsinit(const mbstate_t *); +extern size_t _none_mbsrtowcs(wchar_t * __restrict, const char ** __restrict, + size_t, mbstate_t * __restrict); +extern size_t _none_wcrtomb(char * __restrict, wchar_t, + mbstate_t * __restrict); +extern size_t _none_wcsrtombs(char * __restrict, const wchar_t ** __restrict, + size_t, mbstate_t * __restrict); + +extern size_t __mbsrtowcs_std(wchar_t * __restrict, const char ** __restrict, + size_t, mbstate_t * __restrict); +extern size_t __wcsrtombs_std(char * __restrict, const wchar_t ** __restrict, + size_t, mbstate_t * __restrict); + +/* + * Rune emulation functions. + */ +extern rune_t __emulated_sgetrune(const char *, size_t, const char **); +extern int __emulated_sputrune(rune_t, char *, size_t, char **); + +#endif /* _MBLOCAL_H_ */ diff --git a/src/lib/libc/locale/mbrlen.c b/src/lib/libc/locale/mbrlen.c new file mode 100644 index 0000000..33f7ea0 --- /dev/null +++ b/src/lib/libc/locale/mbrlen.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mbrlen.c,v 1.4 2004/05/12 14:26:54 tjr Exp $"); + +#include +#include "mblocal.h" + +size_t +mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__mbrtowc(NULL, s, n, ps)); +} diff --git a/src/lib/libc/locale/mbrtowc.c b/src/lib/libc/locale/mbrtowc.c new file mode 100644 index 0000000..9b19d10 --- /dev/null +++ b/src/lib/libc/locale/mbrtowc.c @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mbrtowc.c,v 1.7 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include "mblocal.h" + +size_t +mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, + size_t n, mbstate_t * __restrict ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__mbrtowc(pwc, s, n, ps)); +} diff --git a/src/lib/libc/locale/mbrune.c b/src/lib/libc/locale/mbrune.c new file mode 100644 index 0000000..caff65e --- /dev/null +++ b/src/lib/libc/locale/mbrune.c @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +/* mb*rune() and mbmb() are obsolete in FreeBSD 6. */ +#define OBSOLETE_IN_6 + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)mbrune.c 8.1 (Berkeley) 6/27/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mbrune.c,v 1.4 2003/06/13 07:13:54 tjr Exp $"); + +#include +#include +#include +#include + +__warn_references(mbrune, "warning: mbrune() is deprecated. See mbrune(3)."); +char * +mbrune(string, c) + const char *string; + rune_t c; +{ + char const *result; + rune_t r; + + while ((r = sgetrune(string, MB_LEN_MAX, &result))) { + if (r == c) + return ((char *)string); + string = result == string ? string + 1 : result; + } + + return (c == *string ? (char *)string : NULL); +} + +__warn_references(mbrrune, "warning: mbrrune() is deprecated. See mbrrune(3)."); +char * +mbrrune(string, c) + const char *string; + rune_t c; +{ + const char *last = 0; + char const *result; + rune_t r; + + while ((r = sgetrune(string, MB_LEN_MAX, &result))) { + if (r == c) + last = string; + string = result == string ? string + 1 : result; + } + return (c == *string ? (char *)string : (char *)last); +} + +__warn_references(mbmb, "warning: mbmb() is deprecated. See mbmb(3)."); +char * +mbmb(string, pattern) + const char *string; + char *pattern; +{ + rune_t first, r; + size_t plen, slen; + char const *result; + + plen = strlen(pattern); + slen = strlen(string); + if (plen > slen) + return (0); + + first = sgetrune(pattern, plen, &result); + if (result == string) + return (0); + + while (slen >= plen && (r = sgetrune(string, slen, &result))) { + if (r == first) { + if (strncmp(string, pattern, slen) == 0) + return ((char *) string); + } + if (result == string) { + --slen; + ++string; + } else { + slen -= result - string; + string = result; + } + } + return (0); +} diff --git a/src/lib/libc/locale/mbsinit.c b/src/lib/libc/locale/mbsinit.c new file mode 100644 index 0000000..cddb567 --- /dev/null +++ b/src/lib/libc/locale/mbsinit.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mbsinit.c,v 1.3 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include "mblocal.h" + +int +mbsinit(const mbstate_t *ps) +{ + + return (__mbsinit(ps)); +} diff --git a/src/lib/libc/locale/mbsrtowcs.c b/src/lib/libc/locale/mbsrtowcs.c new file mode 100644 index 0000000..a8c3ed5 --- /dev/null +++ b/src/lib/libc/locale/mbsrtowcs.c @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mbsrtowcs.c,v 1.5 2004/05/13 11:20:27 tjr Exp $"); + +#include +#include +#include +#include +#include "mblocal.h" + +size_t +mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, + mbstate_t * __restrict ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__mbsrtowcs(dst, src, len, ps)); +} + +size_t +__mbsrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src, + size_t len, mbstate_t * __restrict ps) +{ + const char *s; + size_t nchr; + wchar_t wc; + int nb; + + s = *src; + nchr = 0; + + if (dst == NULL) { + for (;;) { + if ((nb = (int)__mbrtowc(&wc, s, MB_CUR_MAX, ps)) < 0) + /* Invalid sequence - mbrtowc() sets errno. */ + return ((size_t)-1); + else if (nb == 0) + return (nchr); + s += nb; + nchr++; + } + /*NOTREACHED*/ + } + + while (len-- > 0) { + if ((nb = (int)__mbrtowc(dst, s, MB_CUR_MAX, ps)) < 0) { + *src = s; + return ((size_t)-1); + } else if (nb == 0) { + *src = NULL; + return (nchr); + } + s += nb; + nchr++; + dst++; + } + *src = s; + return (nchr); +} diff --git a/src/lib/libc/locale/mbstowcs.c b/src/lib/libc/locale/mbstowcs.c new file mode 100644 index 0000000..887601a --- /dev/null +++ b/src/lib/libc/locale/mbstowcs.c @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mbstowcs.c,v 1.10 2004/05/13 11:20:27 tjr Exp $"); + +#include +#include +#include "mblocal.h" + +size_t +mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n) +{ + static const mbstate_t initial; + mbstate_t mbs; + + mbs = initial; + return (__mbsrtowcs(pwcs, &s, n, &mbs)); +} diff --git a/src/lib/libc/locale/mbtowc.c b/src/lib/libc/locale/mbtowc.c new file mode 100644 index 0000000..18bb630 --- /dev/null +++ b/src/lib/libc/locale/mbtowc.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mbtowc.c,v 1.9 2004/05/12 14:26:54 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +int +mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n) +{ + static const mbstate_t initial; + static mbstate_t mbs; + size_t rval; + + if (s == NULL) { + /* No support for state dependent encodings. */ + mbs = initial; + return (0); + } + rval = __mbrtowc(pwc, s, n, &mbs); + if (rval == (size_t)-1 || rval == (size_t)-2) + return (-1); + if (rval > INT_MAX) { + errno = ERANGE; + return (-1); + } + return ((int)rval); +} diff --git a/src/lib/libc/locale/mskanji.c b/src/lib/libc/locale/mskanji.c new file mode 100644 index 0000000..c84661a --- /dev/null +++ b/src/lib/libc/locale/mskanji.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. + * + * ja_JP.SJIS locale table for BSD4.4/rune + * version 1.0 + * (C) Sin'ichiro MIYATANI / Phase One, Inc + * May 12, 1995 + * + * 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 Phase One, Inc. + * 4. The name of Phase One, Inc. 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[] = "@(#)mskanji.c 1.0 (Phase One) 5/5/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/mskanji.c,v 1.16 2004/05/14 15:40:47 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +int _MSKanji_init(_RuneLocale *); +size_t _MSKanji_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _MSKanji_mbsinit(const mbstate_t *); +size_t _MSKanji_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + wchar_t ch; +} _MSKanjiState; + +int +_MSKanji_init(_RuneLocale *rl) +{ + + __mbrtowc = _MSKanji_mbrtowc; + __wcrtomb = _MSKanji_wcrtomb; + __mbsinit = _MSKanji_mbsinit; + _CurrentRuneLocale = rl; + __mb_cur_max = 2; + return (0); +} + +int +_MSKanji_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _MSKanjiState *)ps)->ch == 0); +} + +size_t +_MSKanji_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps) +{ + _MSKanjiState *ms; + wchar_t wc; + + ms = (_MSKanjiState *)ps; + + if ((ms->ch & ~0xFF) != 0) { + /* Bad conversion state. */ + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + if (n == 0) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + + if (ms->ch != 0) { + if (*s == '\0') { + errno = EILSEQ; + return ((size_t)-1); + } + wc = (ms->ch << 8) | (*s & 0xFF); + if (pwc != NULL) + *pwc = wc; + ms->ch = 0; + return (1); + } + wc = *s++ & 0xff; + if ((wc > 0x80 && wc < 0xa0) || (wc >= 0xe0 && wc < 0xfd)) { + if (n < 2) { + /* Incomplete multibyte sequence */ + ms->ch = wc; + return ((size_t)-2); + } + if (*s == '\0') { + errno = EILSEQ; + return ((size_t)-1); + } + wc = (wc << 8) | (*s++ & 0xff); + if (pwc != NULL) + *pwc = wc; + return (2); + } else { + if (pwc != NULL) + *pwc = wc; + return (wc == L'\0' ? 0 : 1); + } +} + +size_t +_MSKanji_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _MSKanjiState *ms; + int len, i; + + ms = (_MSKanjiState *)ps; + + if (ms->ch != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + len = (wc > 0x100) ? 2 : 1; + for (i = len; i-- > 0; ) + *s++ = wc >> (i << 3); + return (len); +} diff --git a/src/lib/libc/locale/nl_langinfo.c b/src/lib/libc/locale/nl_langinfo.c new file mode 100644 index 0000000..22d27a3 --- /dev/null +++ b/src/lib/libc/locale/nl_langinfo.c @@ -0,0 +1,175 @@ +/*- + * Copyright (c) 2001, 2003 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/nl_langinfo.c,v 1.17 2003/06/26 10:46:16 phantom Exp $"); + +#include +#include +#include +#include +#include + +#include "lnumeric.h" +#include "lmessages.h" +#include "lmonetary.h" +#include "../stdtime/timelocal.h" + +#define _REL(BASE) ((int)item-BASE) + +char * +nl_langinfo(nl_item item) +{ + char *ret, *s, *cs; + static char *csym = NULL; + + switch (item) { + case CODESET: + ret = ""; + if ((s = setlocale(LC_CTYPE, NULL)) != NULL) { + if ((cs = strchr(s, '.')) != NULL) + ret = cs + 1; + else if (strcmp(s, "C") == 0 || + strcmp(s, "POSIX") == 0) + ret = "US-ASCII"; + } + break; + case D_T_FMT: + ret = (char *) __get_current_time_locale()->c_fmt; + break; + case D_FMT: + ret = (char *) __get_current_time_locale()->x_fmt; + break; + case T_FMT: + ret = (char *) __get_current_time_locale()->X_fmt; + break; + case T_FMT_AMPM: + ret = (char *) __get_current_time_locale()->ampm_fmt; + break; + case AM_STR: + ret = (char *) __get_current_time_locale()->am; + break; + case PM_STR: + ret = (char *) __get_current_time_locale()->pm; + break; + case DAY_1: case DAY_2: case DAY_3: + case DAY_4: case DAY_5: case DAY_6: case DAY_7: + ret = (char*) __get_current_time_locale()->weekday[_REL(DAY_1)]; + break; + case ABDAY_1: case ABDAY_2: case ABDAY_3: + case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7: + ret = (char*) __get_current_time_locale()->wday[_REL(ABDAY_1)]; + break; + case MON_1: case MON_2: case MON_3: case MON_4: + case MON_5: case MON_6: case MON_7: case MON_8: + case MON_9: case MON_10: case MON_11: case MON_12: + ret = (char*) __get_current_time_locale()->month[_REL(MON_1)]; + break; + case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: + case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8: + case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: + ret = (char*) __get_current_time_locale()->mon[_REL(ABMON_1)]; + break; + case ERA: + /* XXX: need to be implemented */ + ret = ""; + break; + case ERA_D_FMT: + /* XXX: need to be implemented */ + ret = ""; + break; + case ERA_D_T_FMT: + /* XXX: need to be implemented */ + ret = ""; + break; + case ERA_T_FMT: + /* XXX: need to be implemented */ + ret = ""; + break; + case ALT_DIGITS: + /* XXX: need to be implemented */ + ret = ""; + break; + case RADIXCHAR: + ret = (char*) __get_current_numeric_locale()->decimal_point; + break; + case THOUSEP: + ret = (char*) __get_current_numeric_locale()->thousands_sep; + break; + case YESEXPR: + ret = (char*) __get_current_messages_locale()->yesexpr; + break; + case NOEXPR: + ret = (char*) __get_current_messages_locale()->noexpr; + break; + /* + * YESSTR and NOSTR items marked with LEGACY are available, but not + * recomended by SUSv2 to be used in portable applications since + * they're subject to remove in future specification editions. + */ + case YESSTR: /* LEGACY */ + ret = (char*) __get_current_messages_locale()->yesstr; + break; + case NOSTR: /* LEGACY */ + ret = (char*) __get_current_messages_locale()->nostr; + break; + /* + * SUSv2 special formatted currency string + */ + case CRNCYSTR: + ret = ""; + cs = (char*) __get_current_monetary_locale()->currency_symbol; + if (*cs != '\0') { + char pos = localeconv()->p_cs_precedes; + + if (pos == localeconv()->n_cs_precedes) { + char psn = '\0'; + + if (pos == CHAR_MAX) { + if (strcmp(cs, __get_current_monetary_locale()->mon_decimal_point) == 0) + psn = '.'; + } else + psn = pos ? '-' : '+'; + if (psn != '\0') { + int clen = strlen(cs); + + if ((csym = reallocf(csym, clen + 2)) != NULL) { + *csym = psn; + strcpy(csym + 1, cs); + ret = csym; + } + } + } + } + break; + case D_MD_ORDER: /* FreeBSD local extension */ + ret = (char *) __get_current_time_locale()->md_order; + break; + default: + ret = ""; + } + return (ret); +} diff --git a/src/lib/libc/locale/nomacros.c b/src/lib/libc/locale/nomacros.c new file mode 100644 index 0000000..eea37d0 --- /dev/null +++ b/src/lib/libc/locale/nomacros.c @@ -0,0 +1,12 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/nomacros.c,v 1.5 2002/03/22 21:52:18 obrien Exp $"); + +/* + * Tell to generate extern versions of all its inline + * functions. The extern versions get called if the system doesn't + * support inlines or the user defines _DONT_USE_CTYPE_INLINE_ + * before including . + */ +#define _EXTERNALIZE_CTYPE_INLINES_ + +#include diff --git a/src/lib/libc/locale/none.c b/src/lib/libc/locale/none.c new file mode 100644 index 0000000..549ace0 --- /dev/null +++ b/src/lib/libc/locale/none.c @@ -0,0 +1,169 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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[] = "@(#)none.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/none.c,v 1.10 2004/05/13 11:20:27 tjr Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include "mblocal.h" + +int _none_init(_RuneLocale *); +size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _none_mbsinit(const mbstate_t *); +size_t _none_mbsrtowcs(wchar_t * __restrict, const char ** __restrict, + size_t, mbstate_t * __restrict); +size_t _none_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); +size_t _none_wcsrtombs(char * __restrict, const wchar_t ** __restrict, + size_t, mbstate_t * __restrict); + +int +_none_init(_RuneLocale *rl) +{ + + __mbrtowc = _none_mbrtowc; + __mbsinit = _none_mbsinit; + __mbsrtowcs = _none_mbsrtowcs; + __wcrtomb = _none_wcrtomb; + __wcsrtombs = _none_wcsrtombs; + _CurrentRuneLocale = rl; + __mb_cur_max = 1; + return(0); +} + +int +_none_mbsinit(const mbstate_t *ps __unused) +{ + + /* + * Encoding is not state dependent - we are always in the + * initial state. + */ + return (1); +} + +size_t +_none_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps __unused) +{ + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (0); + if (n == 0) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + if (pwc != NULL) + *pwc = (unsigned char)*s; + return (*s == '\0' ? 0 : 1); +} + +size_t +_none_wcrtomb(char * __restrict s, wchar_t wc, + mbstate_t * __restrict ps __unused) +{ + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + if (wc < 0 || wc > UCHAR_MAX) { + errno = EILSEQ; + return ((size_t)-1); + } + *s = (unsigned char)wc; + return (1); +} + +size_t +_none_mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, + size_t len, mbstate_t * __restrict ps __unused) +{ + const char *s; + size_t nchr; + + if (dst == NULL) + return (strlen(*src)); + + s = *src; + nchr = 0; + while (len-- > 0) { + if ((*dst++ = (unsigned char)*s++) == L'\0') { + *src = NULL; + return (nchr); + } + nchr++; + } + *src = s; + return (nchr); +} + +size_t +_none_wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, + size_t len, mbstate_t * __restrict ps __unused) +{ + const wchar_t *s; + size_t nchr; + + if (dst == NULL) + return (wcslen(*src)); + + s = *src; + nchr = 0; + while (len-- > 0) { + if (*s < 0 || *s > UCHAR_MAX) { + errno = EILSEQ; + return ((size_t)-1); + } + if ((*dst++ = *s++) == '\0') { + *src = NULL; + return (nchr); + } + nchr++; + } + *src = s; + return (nchr); +} diff --git a/src/lib/libc/locale/rune.c b/src/lib/libc/locale/rune.c new file mode 100644 index 0000000..b67d9e9 --- /dev/null +++ b/src/lib/libc/locale/rune.c @@ -0,0 +1,196 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/rune.c,v 1.10 2002/08/09 08:22:29 ache Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +_RuneLocale * +_Read_RuneMagi(fp) + FILE *fp; +{ + char *data; + void *lastp; + _RuneLocale *rl; + _RuneEntry *rr; + struct stat sb; + int x, saverr; + + if (_fstat(fileno(fp), &sb) < 0) + return (NULL); + + if (sb.st_size < sizeof(_RuneLocale)) { + errno = EFTYPE; + return (NULL); + } + + if ((data = malloc(sb.st_size)) == NULL) + return (NULL); + + errno = 0; + rewind(fp); /* Someone might have read the magic number once already */ + if (errno) { + saverr = errno; + free(data); + errno = saverr; + return (NULL); + } + + if (fread(data, sb.st_size, 1, fp) != 1) { + saverr = errno; + free(data); + errno = saverr; + return (NULL); + } + + rl = (_RuneLocale *)data; + lastp = data + sb.st_size; + + rl->variable = rl + 1; + + if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) { + free(data); + errno = EFTYPE; + return (NULL); + } + + rl->invalid_rune = ntohl(rl->invalid_rune); + rl->variable_len = ntohl(rl->variable_len); + rl->runetype_ext.nranges = ntohl(rl->runetype_ext.nranges); + rl->maplower_ext.nranges = ntohl(rl->maplower_ext.nranges); + rl->mapupper_ext.nranges = ntohl(rl->mapupper_ext.nranges); + + for (x = 0; x < _CACHED_RUNES; ++x) { + rl->runetype[x] = ntohl(rl->runetype[x]); + rl->maplower[x] = ntohl(rl->maplower[x]); + rl->mapupper[x] = ntohl(rl->mapupper[x]); + } + + rl->runetype_ext.ranges = (_RuneEntry *)rl->variable; + rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges; + if (rl->variable > lastp) { + free(data); + errno = EFTYPE; + return (NULL); + } + + rl->maplower_ext.ranges = (_RuneEntry *)rl->variable; + rl->variable = rl->maplower_ext.ranges + rl->maplower_ext.nranges; + if (rl->variable > lastp) { + free(data); + errno = EFTYPE; + return (NULL); + } + + rl->mapupper_ext.ranges = (_RuneEntry *)rl->variable; + rl->variable = rl->mapupper_ext.ranges + rl->mapupper_ext.nranges; + if (rl->variable > lastp) { + free(data); + errno = EFTYPE; + return (NULL); + } + + for (x = 0; x < rl->runetype_ext.nranges; ++x) { + rr = rl->runetype_ext.ranges; + + rr[x].min = ntohl(rr[x].min); + rr[x].max = ntohl(rr[x].max); + if ((rr[x].map = ntohl(rr[x].map)) == 0) { + int len = rr[x].max - rr[x].min + 1; + rr[x].types = rl->variable; + rl->variable = rr[x].types + len; + if (rl->variable > lastp) { + free(data); + errno = EFTYPE; + return (NULL); + } + while (len-- > 0) + rr[x].types[len] = ntohl(rr[x].types[len]); + } else + rr[x].types = 0; + } + + for (x = 0; x < rl->maplower_ext.nranges; ++x) { + rr = rl->maplower_ext.ranges; + + rr[x].min = ntohl(rr[x].min); + rr[x].max = ntohl(rr[x].max); + rr[x].map = ntohl(rr[x].map); + } + + for (x = 0; x < rl->mapupper_ext.nranges; ++x) { + rr = rl->mapupper_ext.ranges; + + rr[x].min = ntohl(rr[x].min); + rr[x].max = ntohl(rr[x].max); + rr[x].map = ntohl(rr[x].map); + } + if (((char *)rl->variable) + rl->variable_len > (char *)lastp) { + free(data); + errno = EFTYPE; + return (NULL); + } + + /* + * Go out and zero pointers that should be zero. + */ + if (!rl->variable_len) + rl->variable = 0; + + if (!rl->runetype_ext.nranges) + rl->runetype_ext.ranges = 0; + + if (!rl->maplower_ext.nranges) + rl->maplower_ext.ranges = 0; + + if (!rl->mapupper_ext.nranges) + rl->mapupper_ext.ranges = 0; + + return (rl); +} diff --git a/src/lib/libc/locale/runetype.c b/src/lib/libc/locale/runetype.c new file mode 100644 index 0000000..59893ee --- /dev/null +++ b/src/lib/libc/locale/runetype.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/runetype.c,v 1.9 2004/05/09 13:04:49 tjr Exp $"); + +#include +#include + +unsigned long +___runetype(c) + __ct_rune_t c; +{ + size_t lim; + _RuneRange *rr = &_CurrentRuneLocale->runetype_ext; + _RuneEntry *base, *re; + + if (c < 0 || c == EOF) + return(0L); + + /* Binary search -- see bsearch.c for explanation. */ + base = rr->ranges; + for (lim = rr->nranges; lim != 0; lim >>= 1) { + re = base + (lim >> 1); + if (re->min <= c && c <= re->max) { + if (re->types) + return(re->types[c - re->min]); + else + return(re->map); + } else if (c > re->max) { + base = re + 1; + lim--; + } + } + + return(0L); +} diff --git a/src/lib/libc/locale/setinvalidrune.c b/src/lib/libc/locale/setinvalidrune.c new file mode 100644 index 0000000..97f0fc2 --- /dev/null +++ b/src/lib/libc/locale/setinvalidrune.c @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +/* setinvalidrune() is obsolete in FreeBSD 6 -- use WEOF instead. */ +#define OBSOLETE_IN_6 + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/setinvalidrune.c,v 1.4 2003/06/13 07:13:54 tjr Exp $"); + +#include + +__warn_references(setinvalidrune, "warning: setinvalidrune() is deprecated. See setinvalidrune(3)."); +void +setinvalidrune(ir) + rune_t ir; +{ + _INVALID_RUNE = ir; +} diff --git a/src/lib/libc/locale/setlocale.c b/src/lib/libc/locale/setlocale.c new file mode 100644 index 0000000..e42f53a --- /dev/null +++ b/src/lib/libc/locale/setlocale.c @@ -0,0 +1,336 @@ +/* + * Copyright (c) 1996 - 2002 FreeBSD Project + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.50 2004/01/31 19:15:32 ache Exp $"); + +#include +#include +#include +#include +#include +#include /* for _PATH_LOCALE */ +#include +#include +#include +#include "collate.h" +#include "lmonetary.h" /* for __monetary_load_locale() */ +#include "lnumeric.h" /* for __numeric_load_locale() */ +#include "lmessages.h" /* for __messages_load_locale() */ +#include "setlocale.h" +#include "ldpart.h" +#include "../stdtime/timelocal.h" /* for __time_load_locale() */ + +/* + * Category names for getenv() + */ +static char *categories[_LC_LAST] = { + "LC_ALL", + "LC_COLLATE", + "LC_CTYPE", + "LC_MONETARY", + "LC_NUMERIC", + "LC_TIME", + "LC_MESSAGES", +}; + +/* + * Current locales for each category + */ +static char current_categories[_LC_LAST][ENCODING_LEN + 1] = { + "C", + "C", + "C", + "C", + "C", + "C", + "C", +}; + +/* + * Path to locale storage directory + */ +char *_PathLocale; + +/* + * The locales we are going to try and load + */ +static char new_categories[_LC_LAST][ENCODING_LEN + 1]; +static char saved_categories[_LC_LAST][ENCODING_LEN + 1]; + +static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]; + +static char *currentlocale(void); +static char *loadlocale(int); +static const char *__get_locale_env(int); + +char * +setlocale(category, locale) + int category; + const char *locale; +{ + int i, j, len, saverr; + const char *env, *r; + + if (category < LC_ALL || category >= _LC_LAST) { + errno = EINVAL; + return (NULL); + } + + if (locale == NULL) + return (category != LC_ALL ? + current_categories[category] : currentlocale()); + + /* + * Default to the current locale for everything. + */ + for (i = 1; i < _LC_LAST; ++i) + (void)strcpy(new_categories[i], current_categories[i]); + + /* + * Now go fill up new_categories from the locale argument + */ + if (!*locale) { + if (category == LC_ALL) { + for (i = 1; i < _LC_LAST; ++i) { + env = __get_locale_env(i); + if (strlen(env) > ENCODING_LEN) { + errno = EINVAL; + return (NULL); + } + (void)strcpy(new_categories[i], env); + } + } else { + env = __get_locale_env(category); + if (strlen(env) > ENCODING_LEN) { + errno = EINVAL; + return (NULL); + } + (void)strcpy(new_categories[category], env); + } + } else if (category != LC_ALL) { + if (strlen(locale) > ENCODING_LEN) { + errno = EINVAL; + return (NULL); + } + (void)strcpy(new_categories[category], locale); + } else { + if ((r = strchr(locale, '/')) == NULL) { + if (strlen(locale) > ENCODING_LEN) { + errno = EINVAL; + return (NULL); + } + for (i = 1; i < _LC_LAST; ++i) + (void)strcpy(new_categories[i], locale); + } else { + for (i = 1; r[1] == '/'; ++r) + ; + if (!r[1]) { + errno = EINVAL; + return (NULL); /* Hmm, just slashes... */ + } + do { + if (i == _LC_LAST) + break; /* Too many slashes... */ + if ((len = r - locale) > ENCODING_LEN) { + errno = EINVAL; + return (NULL); + } + (void)strlcpy(new_categories[i], locale, + len + 1); + i++; + while (*r == '/') + r++; + locale = r; + while (*r && *r != '/') + r++; + } while (*locale); + while (i < _LC_LAST) { + (void)strcpy(new_categories[i], + new_categories[i-1]); + i++; + } + } + } + + if (category != LC_ALL) + return (loadlocale(category)); + + for (i = 1; i < _LC_LAST; ++i) { + (void)strcpy(saved_categories[i], current_categories[i]); + if (loadlocale(i) == NULL) { + saverr = errno; + for (j = 1; j < i; j++) { + (void)strcpy(new_categories[j], + saved_categories[j]); + if (loadlocale(j) == NULL) { + (void)strcpy(new_categories[j], "C"); + (void)loadlocale(j); + } + } + errno = saverr; + return (NULL); + } + } + return (currentlocale()); +} + +static char * +currentlocale() +{ + int i; + + (void)strcpy(current_locale_string, current_categories[1]); + + for (i = 2; i < _LC_LAST; ++i) + if (strcmp(current_categories[1], current_categories[i])) { + for (i = 2; i < _LC_LAST; ++i) { + (void)strcat(current_locale_string, "/"); + (void)strcat(current_locale_string, + current_categories[i]); + } + break; + } + return (current_locale_string); +} + +static char * +loadlocale(category) + int category; +{ + char *new = new_categories[category]; + char *old = current_categories[category]; + int (*func)(const char *); + int saved_errno; + + if ((new[0] == '.' && + (new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) || + strchr(new, '/') != NULL) { + errno = EINVAL; + return (NULL); + } + + saved_errno = errno; + errno = __detect_path_locale(); + if (errno != 0) + return (NULL); + errno = saved_errno; + + switch (category) { + case LC_CTYPE: + func = __wrap_setrunelocale; + break; + case LC_COLLATE: + func = __collate_load_tables; + break; + case LC_TIME: + func = __time_load_locale; + break; + case LC_NUMERIC: + func = __numeric_load_locale; + break; + case LC_MONETARY: + func = __monetary_load_locale; + break; + case LC_MESSAGES: + func = __messages_load_locale; + break; + default: + errno = EINVAL; + return (NULL); + } + + if (strcmp(new, old) == 0) + return (old); + + if (func(new) != _LDP_ERROR) { + (void)strcpy(old, new); + return (old); + } + + return (NULL); +} + +static const char * +__get_locale_env(category) + int category; +{ + const char *env; + + /* 1. check LC_ALL. */ + env = getenv(categories[0]); + + /* 2. check LC_* */ + if (env == NULL || !*env) + env = getenv(categories[category]); + + /* 3. check LANG */ + if (env == NULL || !*env) + env = getenv("LANG"); + + /* 4. if none is set, fall to "C" */ + if (env == NULL || !*env) + env = "C"; + + return (env); +} + +/* + * Detect locale storage location and store its value to _PathLocale variable + */ +int +__detect_path_locale(void) +{ + if (_PathLocale == NULL) { + char *p = getenv("PATH_LOCALE"); + + if (p != NULL && !issetugid()) { + if (strlen(p) + 1/*"/"*/ + ENCODING_LEN + + 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX) + return (ENAMETOOLONG); + _PathLocale = strdup(p); + if (_PathLocale == NULL) + return (errno == 0 ? ENOMEM : errno); + } else + _PathLocale = _PATH_LOCALE; + } + return (0); +} + diff --git a/src/lib/libc/locale/setlocale.h b/src/lib/libc/locale/setlocale.h new file mode 100644 index 0000000..82462ee --- /dev/null +++ b/src/lib/libc/locale/setlocale.h @@ -0,0 +1,40 @@ +/*- + * Copyright (C) 1997 by Andrey A. Chernov, Moscow, Russia. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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. + * + * $FreeBSD: src/lib/libc/locale/setlocale.h,v 1.6 2003/07/06 02:03:37 ache Exp $ + */ + +#ifndef _SETLOCALE_H_ +#define _SETLOCALE_H_ + +#define ENCODING_LEN 31 +#define CATEGORY_LEN 11 + +extern char *_PathLocale; + +int __detect_path_locale(void); +int __wrap_setrunelocale(const char *); + +#endif /* !_SETLOCALE_H_ */ diff --git a/src/lib/libc/locale/setrunelocale.c b/src/lib/libc/locale/setrunelocale.c new file mode 100644 index 0000000..8e203ec --- /dev/null +++ b/src/lib/libc/locale/setrunelocale.c @@ -0,0 +1,216 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +/* setrunelocale() is obsolete in FreeBSD 6 -- use ANSI functions instead. */ +#define OBSOLETE_IN_6 + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.38 2004/05/13 11:20:27 tjr Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include "ldpart.h" +#include "mblocal.h" +#include "setlocale.h" + +extern int _none_init(_RuneLocale *); +extern int _UTF2_init(_RuneLocale *); +extern int _UTF8_init(_RuneLocale *); +extern int _EUC_init(_RuneLocale *); +extern int _GB18030_init(_RuneLocale *); +extern int _GB2312_init(_RuneLocale *); +extern int _GBK_init(_RuneLocale *); +extern int _BIG5_init(_RuneLocale *); +extern int _MSKanji_init(_RuneLocale *); +extern _RuneLocale *_Read_RuneMagi(FILE *); + +static int __setrunelocale(const char *); + +__warn_references(setrunelocale, "warning: setrunelocale() is deprecated. See setrunelocale(3)."); +int +setrunelocale(char *encoding) +{ + int ret; + + if (!encoding || !*encoding || strlen(encoding) > ENCODING_LEN || + (encoding[0] == '.' && + (encoding[1] == '\0' || + (encoding[1] == '.' && encoding[2] == '\0'))) || + strchr(encoding, '/') != NULL) + return (EINVAL); + + ret = __detect_path_locale(); + if (ret != 0) + return (ret); + + return (__setrunelocale((const char *)encoding)); +} + +static int +__setrunelocale(const char *encoding) +{ + FILE *fp; + char name[PATH_MAX]; + _RuneLocale *rl; + int saverr, ret; + static char ctype_encoding[ENCODING_LEN + 1]; + static _RuneLocale *CachedRuneLocale; + static int Cached__mb_cur_max; + static size_t (*Cached__mbrtowc)(wchar_t * __restrict, + const char * __restrict, size_t, mbstate_t * __restrict); + static size_t (*Cached__wcrtomb)(char * __restrict, wchar_t, + mbstate_t * __restrict); + static int (*Cached__mbsinit)(const mbstate_t *); + static size_t (*Cached__mbsrtowcs)(wchar_t * __restrict, + const char ** __restrict, size_t, mbstate_t * __restrict); + static size_t (*Cached__wcsrtombs)(char * __restrict, + const wchar_t ** __restrict, size_t, mbstate_t * __restrict); + + /* + * The "C" and "POSIX" locale are always here. + */ + if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) { + _CurrentRuneLocale = &_DefaultRuneLocale; + __mb_cur_max = 1; + __mbrtowc = _none_mbrtowc; + __mbsinit = _none_mbsinit; + __mbsrtowcs = _none_mbsrtowcs; + __wcrtomb = _none_wcrtomb; + __wcsrtombs = _none_wcsrtombs; + return (0); + } + + /* + * If the locale name is the same as our cache, use the cache. + */ + if (CachedRuneLocale != NULL && + strcmp(encoding, ctype_encoding) == 0) { + _CurrentRuneLocale = CachedRuneLocale; + __mb_cur_max = Cached__mb_cur_max; + __mbrtowc = Cached__mbrtowc; + __mbsinit = Cached__mbsinit; + __mbsrtowcs = Cached__mbsrtowcs; + __wcrtomb = Cached__wcrtomb; + __wcsrtombs = Cached__wcsrtombs; + return (0); + } + + /* + * Slurp the locale file into the cache. + */ + + /* Range checking not needed, encoding length already checked before */ + (void) strcpy(name, _PathLocale); + (void) strcat(name, "/"); + (void) strcat(name, encoding); + (void) strcat(name, "/LC_CTYPE"); + + if ((fp = fopen(name, "r")) == NULL) + return (errno == 0 ? ENOENT : errno); + + if ((rl = _Read_RuneMagi(fp)) == NULL) { + saverr = (errno == 0 ? EFTYPE : errno); + (void)fclose(fp); + return (saverr); + } + (void)fclose(fp); + + __mbrtowc = NULL; + __mbsinit = NULL; + __mbsrtowcs = __mbsrtowcs_std; + __wcrtomb = NULL; + __wcsrtombs = __wcsrtombs_std; + rl->sputrune = __emulated_sputrune; + rl->sgetrune = __emulated_sgetrune; + if (strcmp(rl->encoding, "NONE") == 0) + ret = _none_init(rl); + else if (strcmp(rl->encoding, "UTF2") == 0) + ret = _UTF2_init(rl); + else if (strcmp(rl->encoding, "UTF-8") == 0) + ret = _UTF8_init(rl); + else if (strcmp(rl->encoding, "EUC") == 0) + ret = _EUC_init(rl); + else if (strcmp(rl->encoding, "GB18030") == 0) + ret = _GB18030_init(rl); + else if (strcmp(rl->encoding, "GB2312") == 0) + ret = _GB2312_init(rl); + else if (strcmp(rl->encoding, "GBK") == 0) + ret = _GBK_init(rl); + else if (strcmp(rl->encoding, "BIG5") == 0) + ret = _BIG5_init(rl); + else if (strcmp(rl->encoding, "MSKanji") == 0) + ret = _MSKanji_init(rl); + else + ret = EFTYPE; + if (ret == 0) { + if (CachedRuneLocale != NULL) { + /* See euc.c */ + if (strcmp(CachedRuneLocale->encoding, "EUC") == 0) + free(CachedRuneLocale->variable); + free(CachedRuneLocale); + } + CachedRuneLocale = _CurrentRuneLocale; + Cached__mb_cur_max = __mb_cur_max; + Cached__mbrtowc = __mbrtowc; + Cached__mbsinit = __mbsinit; + Cached__mbsrtowcs = __mbsrtowcs; + Cached__wcrtomb = __wcrtomb; + Cached__wcsrtombs = __wcsrtombs; + (void)strcpy(ctype_encoding, encoding); + } else + free(rl); + + return (ret); +} + +int +__wrap_setrunelocale(const char *locale) +{ + int ret = __setrunelocale(locale); + + if (ret != 0) { + errno = ret; + return (_LDP_ERROR); + } + return (_LDP_LOADED); +} + diff --git a/src/lib/libc/locale/srune.c b/src/lib/libc/locale/srune.c new file mode 100644 index 0000000..75ec833 --- /dev/null +++ b/src/lib/libc/locale/srune.c @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 2003-2004 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +/* Not required when sgetrune() and sputrune() are removed. */ +#define OBSOLETE_IN_6 + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/srune.c,v 1.4 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include +#include +#include +#include "mblocal.h" + +/* + * Emulate the deprecated 4.4BSD sgetrune() function in terms of + * the ISO C mbrtowc() function. + */ +rune_t +__emulated_sgetrune(const char *string, size_t n, const char **result) +{ + static const mbstate_t initial; + mbstate_t mbs; + wchar_t wc; + size_t nconv; + + /* + * Pass a NULL conversion state to mbrtowc() since multibyte + * conversion states are not supported. + */ + mbs = initial; + nconv = mbrtowc(&wc, string, n, &mbs); + if (nconv == (size_t)-2) { + if (result != NULL) + *result = string; + return (_INVALID_RUNE); + } + if (nconv == (size_t)-1) { + if (result != NULL) + *result = string + 1; + return (_INVALID_RUNE); + } + if (nconv == 0) + nconv = 1; + if (result != NULL) + *result = string + nconv; + return ((rune_t)wc); +} + +/* + * Emulate the deprecated 4.4BSD sputrune() function in terms of + * the ISO C wcrtomb() function. + */ +int +__emulated_sputrune(rune_t rune, char *string, size_t n, char **result) +{ + static const mbstate_t initial; + mbstate_t mbs; + char buf[MB_LEN_MAX]; + size_t nconv; + + mbs = initial; + nconv = wcrtomb(buf, (wchar_t)rune, &mbs); + if (nconv == (size_t)-1) { + if (result != NULL) + *result = NULL; + return (0); + } + if (string == NULL) { + if (result != NULL) + *result = (char *)0 + nconv; + } else if (n >= nconv) { + memcpy(string, buf, nconv); + if (result != NULL) + *result = string + nconv; + } else { + if (result != NULL) + *result = NULL; + } + return (nconv); +} diff --git a/src/lib/libc/locale/table.c b/src/lib/libc/locale/table.c new file mode 100644 index 0000000..6af525f --- /dev/null +++ b/src/lib/libc/locale/table.c @@ -0,0 +1,263 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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[] = "@(#)table.c 8.1 (Berkeley) 6/27/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/table.c,v 1.23 2004/05/13 11:20:27 tjr Exp $"); + +#include +#include +#include +#include "mblocal.h" + +_RuneLocale _DefaultRuneLocale = { + _RUNE_MAGIC_1, + "NONE", + __emulated_sgetrune, + __emulated_sputrune, + 0xFFFD, + + { /*00*/ _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + /*08*/ _CTYPE_C, + _CTYPE_C|_CTYPE_S|_CTYPE_B, + _CTYPE_C|_CTYPE_S, + _CTYPE_C|_CTYPE_S, + _CTYPE_C|_CTYPE_S, + _CTYPE_C|_CTYPE_S, + _CTYPE_C, + _CTYPE_C, + /*10*/ _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + /*18*/ _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + /*20*/ _CTYPE_S|_CTYPE_B|_CTYPE_R, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + /*28*/ _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + /*30*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|0, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|1, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|2, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|3, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|4, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|5, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|6, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|7, + /*38*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|8, + _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|9, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + /*40*/ _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10, + _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11, + _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12, + _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13, + _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14, + _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + /*48*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + /*50*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + /*58*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + /*60*/ _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10, + _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11, + _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12, + _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13, + _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14, + _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + /*68*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + /*70*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + /*78*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_P|_CTYPE_R|_CTYPE_G, + _CTYPE_C, + }, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, + }, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, + }, +}; + +_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale; + +int __mb_cur_max = 1; +size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict) = _none_mbrtowc; +int (*__mbsinit)(const mbstate_t *) = _none_mbsinit; +size_t (*__mbsrtowcs)(wchar_t * __restrict, const char ** __restrict, + size_t, mbstate_t * __restrict) = _none_mbsrtowcs; +size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict) = + _none_wcrtomb; +size_t (*__wcsrtombs)(char * __restrict, const wchar_t ** __restrict, + size_t, mbstate_t * __restrict) = _none_wcsrtombs; diff --git a/src/lib/libc/locale/tolower.c b/src/lib/libc/locale/tolower.c new file mode 100644 index 0000000..ba72829 --- /dev/null +++ b/src/lib/libc/locale/tolower.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/tolower.c,v 1.9 2004/05/09 13:04:49 tjr Exp $"); + +#include +#include + +__ct_rune_t +___tolower(c) + __ct_rune_t c; +{ + size_t lim; + _RuneRange *rr = &_CurrentRuneLocale->maplower_ext; + _RuneEntry *base, *re; + + if (c < 0 || c == EOF) + return(c); + + /* Binary search -- see bsearch.c for explanation. */ + base = rr->ranges; + for (lim = rr->nranges; lim != 0; lim >>= 1) { + re = base + (lim >> 1); + if (re->min <= c && c <= re->max) + return (re->map + c - re->min); + else if (c > re->max) { + base = re + 1; + lim--; + } + } + + return(c); +} diff --git a/src/lib/libc/locale/toupper.c b/src/lib/libc/locale/toupper.c new file mode 100644 index 0000000..91d3f5b --- /dev/null +++ b/src/lib/libc/locale/toupper.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.9 2004/05/09 13:04:49 tjr Exp $"); + +#include +#include + +__ct_rune_t +___toupper(c) + __ct_rune_t c; +{ + size_t lim; + _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; + _RuneEntry *base, *re; + + if (c < 0 || c == EOF) + return(c); + + /* Binary search -- see bsearch.c for explanation. */ + base = rr->ranges; + for (lim = rr->nranges; lim != 0; lim >>= 1) { + re = base + (lim >> 1); + if (re->min <= c && c <= re->max) + return (re->map + c - re->min); + else if (c > re->max) { + base = re + 1; + lim--; + } + } + + return(c); +} diff --git a/src/lib/libc/locale/utf2.c b/src/lib/libc/locale/utf2.c new file mode 100644 index 0000000..14c2b01 --- /dev/null +++ b/src/lib/libc/locale/utf2.c @@ -0,0 +1,184 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ +/* + * UTF2 encoding. + * + * This is an obsolete subset of UTF-8, maintained for temporary + * compatibility with old applications. It is limited to 1-, 2- or + * 3-byte encodings, and allows redundantly-encoded characters. + * + * See utf2(5) for details. + */ + +/* UTF2 is obsolete and will be removed in FreeBSD 6 -- use UTF-8 instead. */ +#define OBSOLETE_IN_6 + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/utf2.c,v 1.13 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +size_t _UTF2_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _UTF2_mbsinit(const mbstate_t *); +size_t _UTF2_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + int count; + u_char bytes[3]; +} _UTF2State; + +int +_UTF2_init(_RuneLocale *rl) +{ + + __mbrtowc = _UTF2_mbrtowc; + __wcrtomb = _UTF2_wcrtomb; + __mbsinit = _UTF2_mbsinit; + _CurrentRuneLocale = rl; + __mb_cur_max = 3; + + return (0); +} + +int +_UTF2_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _UTF2State *)ps)->count == 0); +} + +size_t +_UTF2_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps) +{ + _UTF2State *us; + int ch, i, len, mask, ocount; + wchar_t wch; + size_t ncopy; + + us = (_UTF2State *)ps; + + if (us->count < 0 || us->count > sizeof(us->bytes)) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(us->bytes) - us->count); + memcpy(us->bytes + us->count, s, ncopy); + ocount = us->count; + us->count += ncopy; + s = (char *)us->bytes; + n = us->count; + + if (n == 0) + return ((size_t)-2); + + ch = (unsigned char)*s; + if ((ch & 0x80) == 0) { + mask = 0x7f; + len = 1; + } else if ((ch & 0xe0) == 0xc0) { + mask = 0x1f; + len = 2; + } else if ((ch & 0xf0) == 0xe0) { + mask = 0x0f; + len = 3; + } else { + errno = EILSEQ; + return ((size_t)-1); + } + + if (n < (size_t)len) + return ((size_t)-2); + + wch = (unsigned char)*s++ & mask; + i = len; + while (--i != 0) { + if ((*s & 0xc0) != 0x80) { + errno = EILSEQ; + return ((size_t)-1); + } + wch <<= 6; + wch |= *s++ & 0x3f; + } + if (pwc != NULL) + *pwc = wch; + us->count = 0; + return (wch == L'\0' ? 0 : len - ocount); +} + +size_t +_UTF2_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _UTF2State *us; + unsigned char lead; + int i, len; + + us = (_UTF2State *)ps; + + if (us->count != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial conversion state. */ + return (1); + + if ((wc & ~0x7f) == 0) { + lead = 0; + len = 1; + } else if ((wc & ~0x7ff) == 0) { + lead = 0xc0; + len = 2; + } else if ((wc & ~0xffff) == 0) { + lead = 0xe0; + len = 3; + } else { + errno = EILSEQ; + return ((size_t)-1); + } + + for (i = len - 1; i > 0; i--) { + s[i] = (wc & 0x3f) | 0x80; + wc >>= 6; + } + *s = (wc & 0xff) | lead; + + return (len); +} diff --git a/src/lib/libc/locale/utf8.c b/src/lib/libc/locale/utf8.c new file mode 100644 index 0000000..122144f --- /dev/null +++ b/src/lib/libc/locale/utf8.c @@ -0,0 +1,243 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.9 2004/05/17 12:32:40 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int _UTF8_mbsinit(const mbstate_t *); +size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); + +typedef struct { + wchar_t ch; + int want; + wchar_t lbound; +} _UTF8State; + +int +_UTF8_init(_RuneLocale *rl) +{ + + __mbrtowc = _UTF8_mbrtowc; + __wcrtomb = _UTF8_wcrtomb; + __mbsinit = _UTF8_mbsinit; + _CurrentRuneLocale = rl; + __mb_cur_max = 6; + + return (0); +} + +int +_UTF8_mbsinit(const mbstate_t *ps) +{ + + return (ps == NULL || ((const _UTF8State *)ps)->want == 0); +} + +size_t +_UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, + mbstate_t * __restrict ps) +{ + _UTF8State *us; + int ch, i, mask, want; + wchar_t lbound, wch; + + us = (_UTF8State *)ps; + + if (us->want < 0 || us->want > 6) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) { + s = ""; + n = 1; + pwc = NULL; + } + + if (n == 0) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + + if (us->want == 0) { + /* + * Determine the number of octets that make up this character + * from the first octet, and a mask that extracts the + * interesting bits of the first octet. We already know + * the character is at least two bytes long. + * + * We also specify a lower bound for the character code to + * detect redundant, non-"shortest form" encodings. For + * example, the sequence C0 80 is _not_ a legal representation + * of the null character. This enforces a 1-to-1 mapping + * between character codes and their multibyte representations. + */ + ch = (unsigned char)*s; + if ((ch & 0x80) == 0) { + mask = 0x7f; + want = 1; + lbound = 0; + } else if ((ch & 0xe0) == 0xc0) { + mask = 0x1f; + want = 2; + lbound = 0x80; + } else if ((ch & 0xf0) == 0xe0) { + mask = 0x0f; + want = 3; + lbound = 0x800; + } else if ((ch & 0xf8) == 0xf0) { + mask = 0x07; + want = 4; + lbound = 0x10000; + } else if ((ch & 0xfc) == 0xf8) { + mask = 0x03; + want = 5; + lbound = 0x200000; + } else if ((ch & 0xfc) == 0xfc) { + mask = 0x01; + want = 6; + lbound = 0x4000000; + } else { + /* + * Malformed input; input is not UTF-8. + */ + errno = EILSEQ; + return ((size_t)-1); + } + } else { + want = us->want; + lbound = us->lbound; + } + + /* + * Decode the octet sequence representing the character in chunks + * of 6 bits, most significant first. + */ + if (us->want == 0) + wch = (unsigned char)*s++ & mask; + else + wch = us->ch; + for (i = (us->want == 0) ? 1 : 0; i < MIN(want, n); i++) { + if ((*s & 0xc0) != 0x80) { + /* + * Malformed input; bad characters in the middle + * of a character. + */ + errno = EILSEQ; + return ((size_t)-1); + } + wch <<= 6; + wch |= *s++ & 0x3f; + } + if (i < want) { + /* Incomplete multibyte sequence. */ + us->want = want - i; + us->lbound = lbound; + us->ch = wch; + return ((size_t)-2); + } + if (wch < lbound) { + /* + * Malformed input; redundant encoding. + */ + errno = EILSEQ; + return ((size_t)-1); + } + if (pwc != NULL) + *pwc = wch; + us->want = 0; + return (wch == L'\0' ? 0 : want); +} + +size_t +_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + _UTF8State *us; + unsigned char lead; + int i, len; + + us = (_UTF8State *)ps; + + if (us->want != 0) { + errno = EINVAL; + return ((size_t)-1); + } + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + + /* + * Determine the number of octets needed to represent this character. + * We always output the shortest sequence possible. Also specify the + * first few bits of the first octet, which contains the information + * about the sequence length. + */ + if ((wc & ~0x7f) == 0) { + lead = 0; + len = 1; + } else if ((wc & ~0x7ff) == 0) { + lead = 0xc0; + len = 2; + } else if ((wc & ~0xffff) == 0) { + lead = 0xe0; + len = 3; + } else if ((wc & ~0x1fffff) == 0) { + lead = 0xf0; + len = 4; + } else if ((wc & ~0x3ffffff) == 0) { + lead = 0xf8; + len = 5; + } else if ((wc & ~0x7fffffff) == 0) { + lead = 0xfc; + len = 6; + } else { + errno = EILSEQ; + return ((size_t)-1); + } + + /* + * Output the octets representing the character in chunks + * of 6 bits, least significant last. The first octet is + * a special case because it contains the sequence length + * information. + */ + for (i = len - 1; i > 0; i--) { + s[i] = (wc & 0x3f) | 0x80; + wc >>= 6; + } + *s = (wc & 0xff) | lead; + + return (len); +} diff --git a/src/lib/libc/locale/wcrtomb.c b/src/lib/libc/locale/wcrtomb.c new file mode 100644 index 0000000..4d7b115 --- /dev/null +++ b/src/lib/libc/locale/wcrtomb.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcrtomb.c,v 1.8 2004/05/12 14:09:04 tjr Exp $"); + +#include +#include "mblocal.h" + +size_t +wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__wcrtomb(s, wc, ps)); +} diff --git a/src/lib/libc/locale/wcsftime.c b/src/lib/libc/locale/wcsftime.c new file mode 100644 index 0000000..2598043 --- /dev/null +++ b/src/lib/libc/locale/wcsftime.c @@ -0,0 +1,105 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr Exp $"); + +#include +#include +#include +#include +#include + +/* + * Convert date and time to a wide-character string. + * + * This is the wide-character counterpart of strftime(). So that we do not + * have to duplicate the code of strftime(), we convert the format string to + * multibyte, call strftime(), then convert the result back into wide + * characters. + * + * This technique loses in the presence of stateful multibyte encoding if any + * of the conversions in the format string change conversion state. When + * stateful encoding is implemented, we will need to reset the state between + * format specifications in the format string. + */ +size_t +wcsftime(wchar_t * __restrict wcs, size_t maxsize, + const wchar_t * __restrict format, const struct tm * __restrict timeptr) +{ + static const mbstate_t initial; + mbstate_t mbs; + char *dst, *dstp, *sformat; + size_t n, sflen; + int sverrno; + + sformat = dst = NULL; + + /* + * Convert the supplied format string to a multibyte representation + * for strftime(), which only handles single-byte characters. + */ + mbs = initial; + sflen = wcsrtombs(NULL, &format, 0, &mbs); + if (sflen == (size_t)-1) + goto error; + if ((sformat = malloc(sflen + 1)) == NULL) + goto error; + mbs = initial; + wcsrtombs(sformat, &format, sflen + 1, &mbs); + + /* + * Allocate memory for longest multibyte sequence that will fit + * into the caller's buffer and call strftime() to fill it. + * Then, copy and convert the result back into wide characters in + * the caller's buffer. + */ + if (SIZE_T_MAX / MB_CUR_MAX <= maxsize) { + /* maxsize is prepostorously large - avoid int. overflow. */ + errno = EINVAL; + goto error; + } + if ((dst = malloc(maxsize * MB_CUR_MAX)) == NULL) + goto error; + if (strftime(dst, maxsize, sformat, timeptr) == 0) + goto error; + dstp = dst; + mbs = initial; + n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, &mbs); + if (n == (size_t)-2 || n == (size_t)-1 || dstp != NULL) + goto error; + + free(sformat); + free(dst); + return (n); + +error: + sverrno = errno; + free(sformat); + free(dst); + errno = sverrno; + return (0); +} diff --git a/src/lib/libc/locale/wcsrtombs.c b/src/lib/libc/locale/wcsrtombs.c new file mode 100644 index 0000000..69ebb95 --- /dev/null +++ b/src/lib/libc/locale/wcsrtombs.c @@ -0,0 +1,111 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcsrtombs.c,v 1.5 2004/05/13 11:20:27 tjr Exp $"); + +#include +#include +#include +#include +#include "mblocal.h" + +size_t +wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len, + mbstate_t * __restrict ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__wcsrtombs(dst, src, len, ps)); +} + +size_t +__wcsrtombs_std(char * __restrict dst, const wchar_t ** __restrict src, + size_t len, mbstate_t * __restrict ps) +{ + mbstate_t mbsbak; + char buf[MB_LEN_MAX]; + const wchar_t *s; + size_t nbytes; + int nb; + + s = *src; + nbytes = 0; + + if (dst == NULL) { + for (;;) { + if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0) + /* Invalid character - wcrtomb() sets errno. */ + return ((size_t)-1); + else if (*s == L'\0') + return (nbytes + nb - 1); + s++; + nbytes += nb; + } + /*NOTREACHED*/ + } + + while (len > 0) { + if (len > (size_t)MB_CUR_MAX) { + /* Enough space to translate in-place. */ + if ((nb = (int)__wcrtomb(dst, *s, ps)) < 0) { + *src = s; + return ((size_t)-1); + } + } else { + /* + * May not be enough space; use temp. buffer. + * + * We need to save a copy of the conversion state + * here so we can restore it if the multibyte + * character is too long for the buffer. + */ + mbsbak = *ps; + if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0) { + *src = s; + return ((size_t)-1); + } + if (nb > (int)len) { + /* MB sequence for character won't fit. */ + *ps = mbsbak; + break; + } + memcpy(dst, buf, nb); + } + if (*s == L'\0') { + *src = NULL; + return (nbytes + nb - 1); + } + s++; + dst += nb; + len -= nb; + nbytes += nb; + } + *src = s; + return (nbytes); +} diff --git a/src/lib/libc/locale/wcstod.c b/src/lib/libc/locale/wcstod.c new file mode 100644 index 0000000..da90f16 --- /dev/null +++ b/src/lib/libc/locale/wcstod.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp $"); + +#include +#include +#include + +/* + * Convert a string to a double-precision number. + * + * This is the wide-character counterpart of strtod(). So that we do not + * have to duplicate the code of strtod() here, we convert the supplied + * wide character string to multibyte and call strtod() on the result. + * This assumes that the multibyte encoding is compatible with ASCII + * for at least the digits, radix character and letters. + */ +double +wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr) +{ + static const mbstate_t initial; + mbstate_t mbs; + double val; + char *buf, *end; + const wchar_t *wcp; + size_t len; + + while (iswspace(*nptr)) + nptr++; + + /* + * Convert the supplied numeric wide char. string to multibyte. + * + * We could attempt to find the end of the numeric portion of the + * wide char. string to avoid converting unneeded characters but + * choose not to bother; optimising the uncommon case where + * the input string contains a lot of text after the number + * duplicates a lot of strtod()'s functionality and slows down the + * most common cases. + */ + wcp = nptr; + mbs = initial; + if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) { + if (endptr != NULL) + *endptr = (wchar_t *)nptr; + return (0.0); + } + if ((buf = malloc(len + 1)) == NULL) + return (0.0); + mbs = initial; + wcsrtombs(buf, &wcp, len + 1, &mbs); + + /* Let strtod() do most of the work for us. */ + val = strtod(buf, &end); + + /* + * We only know where the number ended in the _multibyte_ + * representation of the string. If the caller wants to know + * where it ended, count multibyte characters to find the + * corresponding position in the wide char string. + */ + if (endptr != NULL) + /* XXX Assume each wide char is one byte. */ + *endptr = (wchar_t *)nptr + (end - buf); + + free(buf); + + return (val); +} diff --git a/src/lib/libc/locale/wcstof.c b/src/lib/libc/locale/wcstof.c new file mode 100644 index 0000000..a68b382 --- /dev/null +++ b/src/lib/libc/locale/wcstof.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2002, 2003 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstof.c,v 1.3 2004/04/07 09:47:56 tjr Exp $"); + +#include +#include +#include + +/* + * See wcstod() for comments as to the logic used. + */ +float +wcstof(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr) +{ + static const mbstate_t initial; + mbstate_t mbs; + float val; + char *buf, *end; + const wchar_t *wcp; + size_t len; + + while (iswspace(*nptr)) + nptr++; + + wcp = nptr; + mbs = initial; + if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) { + if (endptr != NULL) + *endptr = (wchar_t *)nptr; + return (0.0); + } + if ((buf = malloc(len + 1)) == NULL) + return (0.0); + mbs = initial; + wcsrtombs(buf, &wcp, len + 1, &mbs); + + val = strtof(buf, &end); + + if (endptr != NULL) + *endptr = (wchar_t *)nptr + (end - buf); + + free(buf); + + return (val); +} diff --git a/src/lib/libc/locale/wcstoimax.c b/src/lib/libc/locale/wcstoimax.c new file mode 100644 index 0000000..09e7817 --- /dev/null +++ b/src/lib/libc/locale/wcstoimax.c @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 1992, 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. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "from @(#)strtol.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoimax.c,v 1.8 2002/09/06 11:23:59 tjr Exp "); +#endif +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstoimax.c,v 1.2 2003/01/01 18:48:43 schweikh Exp $"); + +#include +#include +#include +#include +#include + +/* + * Convert a wide character string to an intmax_t integer. + */ +intmax_t +wcstoimax(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, + int base) +{ + const wchar_t *s; + uintmax_t acc; + wchar_t c; + uintmax_t cutoff; + int neg, any, cutlim; + + /* + * See strtoimax for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (iswspace(c)); + if (c == L'-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == L'+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = neg ? (uintmax_t)-(INTMAX_MIN + INTMAX_MAX) + INTMAX_MAX + : INTMAX_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { +#ifdef notyet + if (iswdigit(c)) + c = digittoint(c); + else +#endif + if (c >= L'0' && c <= L'9') + c -= L'0'; + else if (c >= L'A' && c <= L'Z') + c -= L'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? INTMAX_MIN : INTMAX_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/locale/wcstol.c b/src/lib/libc/locale/wcstol.c new file mode 100644 index 0000000..ae51c2e --- /dev/null +++ b/src/lib/libc/locale/wcstol.c @@ -0,0 +1,121 @@ +/*- + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstol.c,v 1.1 2002/09/08 13:27:26 tjr Exp $"); + +#include +#include +#include +#include +#include + +/* + * Convert a string to a long integer. + */ +long +wcstol(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base) +{ + const wchar_t *s; + unsigned long acc; + wchar_t c; + unsigned long cutoff; + int neg, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (iswspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == L'+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = neg ? (unsigned long)-(LONG_MIN + LONG_MAX) + LONG_MAX + : LONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { +#ifdef notyet + if (iswdigit(c)) + c = digittoint(c); + else +#endif + if (c >= L'0' && c <= L'9') + c -= L'0'; + else if (c >= L'A' && c <= L'Z') + c -= L'A' - 10; + else if (c >= L'a' && c <= L'z') + c -= L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_MIN : LONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/locale/wcstold.c b/src/lib/libc/locale/wcstold.c new file mode 100644 index 0000000..c50ffbd --- /dev/null +++ b/src/lib/libc/locale/wcstold.c @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2002, 2003 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstold.c,v 1.4 2004/04/07 09:47:56 tjr Exp $"); + +#include +#include +#include + +/* + * See wcstod() for comments as to the logic used. + */ +long double +wcstold(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr) +{ + static const mbstate_t initial; + mbstate_t mbs; + long double val; + char *buf, *end; + const wchar_t *wcp; + size_t len; + + while (iswspace(*nptr)) + nptr++; + + wcp = nptr; + mbs = initial; + if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) { + if (endptr != NULL) + *endptr = (wchar_t *)nptr; + return (0.0); + } + if ((buf = malloc(len + 1)) == NULL) + return (0.0); + mbs = initial; + wcsrtombs(buf, &wcp, len + 1, &mbs); + + val = strtold(buf, &end); + + if (endptr != NULL) + *endptr = (wchar_t *)nptr + (end - buf); + + free(buf); + + return (val); +} diff --git a/src/lib/libc/locale/wcstoll.c b/src/lib/libc/locale/wcstoll.c new file mode 100644 index 0000000..a48056c --- /dev/null +++ b/src/lib/libc/locale/wcstoll.c @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 1992, 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. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoll.c,v 1.19 2002/09/06 11:23:59 tjr Exp "); +#endif +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstoll.c,v 1.1 2002/09/22 08:06:45 tjr Exp $"); + +#include +#include +#include +#include +#include + +/* + * Convert a wide character string to a long long integer. + */ +long long +wcstoll(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base) +{ + const wchar_t *s; + unsigned long long acc; + wchar_t c; + unsigned long long cutoff; + int neg, any, cutlim; + + /* + * See strtoll for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (iswspace(c)); + if (c == L'-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == L'+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX + : LLONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { +#ifdef notyet + if (iswdigit(c)) + c = digittoint(c); + else +#endif + if (c >= L'0' && c <= L'9') + c -= L'0'; + else if (c >= L'A' && c <= L'Z') + c -= L'A' - 10; + else if (c >= L'a' && c <= L'z') + c -= L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LLONG_MIN : LLONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/locale/wcstombs.c b/src/lib/libc/locale/wcstombs.c new file mode 100644 index 0000000..6f80068 --- /dev/null +++ b/src/lib/libc/locale/wcstombs.c @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstombs.c,v 1.9 2004/05/13 11:20:27 tjr Exp $"); + +#include +#include +#include "mblocal.h" + +size_t +wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n) +{ + static const mbstate_t initial; + mbstate_t mbs; + + mbs = initial; + return (__wcsrtombs(s, &pwcs, n, &mbs)); +} diff --git a/src/lib/libc/locale/wcstoul.c b/src/lib/libc/locale/wcstoul.c new file mode 100644 index 0000000..f3b8b49 --- /dev/null +++ b/src/lib/libc/locale/wcstoul.c @@ -0,0 +1,119 @@ +/* + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstoul.c,v 1.1 2002/09/08 13:27:26 tjr Exp $"); + +#include +#include +#include +#include +#include + +/* + * Convert a wide character string to an unsigned long integer. + */ +unsigned long +wcstoul(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base) +{ + const wchar_t *s; + unsigned long acc; + wchar_t c; + unsigned long cutoff; + int neg, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (iswspace(c)); + if (c == L'-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == L'+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = ULONG_MAX / base; + cutlim = ULONG_MAX % base; + for ( ; ; c = *s++) { +#ifdef notyet + if (iswdigit(c)) + c = digittoint(c); + else +#endif + if (c >= L'0' && c <= L'9') + c -= L'0'; + else if (c >= L'A' && c <= L'Z') + c -= L'A' - 10; + else if (c >= L'a' && c <= L'z') + c -= L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/locale/wcstoull.c b/src/lib/libc/locale/wcstoull.c new file mode 100644 index 0000000..fd9558b --- /dev/null +++ b/src/lib/libc/locale/wcstoull.c @@ -0,0 +1,126 @@ +/*- + * Copyright (c) 1992, 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. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoull.c,v 1.18 2002/09/06 11:23:59 tjr Exp "); +#endif +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstoull.c,v 1.1 2002/09/22 08:06:45 tjr Exp $"); + +#include +#include +#include +#include +#include + +/* + * Convert a wide character string to an unsigned long long integer. + */ +unsigned long long +wcstoull(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, + int base) +{ + const wchar_t *s; + unsigned long long acc; + wchar_t c; + unsigned long long cutoff; + int neg, any, cutlim; + + /* + * See strtoull for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (iswspace(c)); + if (c == L'-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == L'+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = ULLONG_MAX / base; + cutlim = ULLONG_MAX % base; + for ( ; ; c = *s++) { +#ifdef notyet + if (iswdigit(c)) + c = digittoint(c); + else +#endif + if (c >= L'0' && c <= L'9') + c -= L'0'; + else if (c >= L'A' && c <= L'Z') + c -= L'A' - 10; + else if (c >= L'a' && c <= L'z') + c -= L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULLONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/locale/wcstoumax.c b/src/lib/libc/locale/wcstoumax.c new file mode 100644 index 0000000..01e25d5 --- /dev/null +++ b/src/lib/libc/locale/wcstoumax.c @@ -0,0 +1,126 @@ +/*- + * Copyright (c) 1992, 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. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "from @(#)strtoul.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoumax.c,v 1.8 2002/09/06 11:23:59 tjr Exp "); +#endif +__FBSDID("$FreeBSD: src/lib/libc/locale/wcstoumax.c,v 1.1 2002/09/22 08:06:45 tjr Exp $"); + +#include +#include +#include +#include +#include + +/* + * Convert a wide character string to a uintmax_t integer. + */ +uintmax_t +wcstoumax(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, + int base) +{ + const wchar_t *s; + uintmax_t acc; + wchar_t c; + uintmax_t cutoff; + int neg, any, cutlim; + + /* + * See strtoimax for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (iswspace(c)); + if (c == L'-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == L'+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == L'0' && (*s == L'x' || *s == L'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == L'0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = UINTMAX_MAX / base; + cutlim = UINTMAX_MAX % base; + for ( ; ; c = *s++) { +#ifdef notyet + if (iswdigit(c)) + c = digittoint(c); + else +#endif + if (c >= L'0' && c <= L'9') + c -= L'0'; + else if (c >= L'A' && c <= L'Z') + c -= L'A' - 10; + else if (c >= L'a' && c <= L'z') + c -= L'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = UINTMAX_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (wchar_t *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/locale/wctob.c b/src/lib/libc/locale/wctob.c new file mode 100644 index 0000000..a8f0056 --- /dev/null +++ b/src/lib/libc/locale/wctob.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wctob.c,v 1.4 2004/05/12 14:26:54 tjr Exp $"); + +#include +#include +#include +#include "mblocal.h" + +int +wctob(wint_t c) +{ + static const mbstate_t initial; + mbstate_t mbs = initial; + char buf[MB_LEN_MAX]; + + if (c == WEOF || __wcrtomb(buf, c, &mbs) != 1) + return (EOF); + return ((unsigned char)*buf); +} diff --git a/src/lib/libc/locale/wctomb.c b/src/lib/libc/locale/wctomb.c new file mode 100644 index 0000000..efd52e7 --- /dev/null +++ b/src/lib/libc/locale/wctomb.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wctomb.c,v 1.6 2004/05/12 14:26:54 tjr Exp $"); + +#include +#include +#include +#include +#include +#include "mblocal.h" + +int +wctomb(char *s, wchar_t wchar) +{ + static const mbstate_t initial; + static mbstate_t mbs; + size_t rval; + + if (s == NULL) { + /* No support for state dependent encodings. */ + mbs = initial; + return (0); + } + if ((rval = __wcrtomb(s, wchar, &mbs)) == (size_t)-1) + return (-1); + if (rval > INT_MAX) { + errno = ERANGE; + return (-1); + } + return ((int)rval); +} diff --git a/src/lib/libc/locale/wctrans.c b/src/lib/libc/locale/wctrans.c new file mode 100644 index 0000000..a86e5c7 --- /dev/null +++ b/src/lib/libc/locale/wctrans.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wctrans.c,v 1.3 2003/11/01 08:20:58 tjr Exp $"); + +#include +#include +#include + +enum { + _WCT_ERROR = 0, + _WCT_TOLOWER = 1, + _WCT_TOUPPER = 2 +}; + +wint_t +towctrans(wint_t wc, wctrans_t desc) +{ + + switch (desc) { + case _WCT_TOLOWER: + wc = towlower(wc); + break; + case _WCT_TOUPPER: + wc = towupper(wc); + break; + case _WCT_ERROR: + default: + errno = EINVAL; + break; + } + + return (wc); +} + +wctrans_t +wctrans(const char *charclass) +{ + struct { + const char *name; + wctrans_t trans; + } ccls[] = { + { "tolower", _WCT_TOLOWER }, + { "toupper", _WCT_TOUPPER }, + { NULL, _WCT_ERROR }, /* Default */ + }; + int i; + + i = 0; + while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0) + i++; + + if (ccls[i].trans == _WCT_ERROR) + errno = EINVAL; + return (ccls[i].trans); +} diff --git a/src/lib/libc/locale/wctype.c b/src/lib/libc/locale/wctype.c new file mode 100644 index 0000000..a0e21bc --- /dev/null +++ b/src/lib/libc/locale/wctype.c @@ -0,0 +1,74 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wctype.c,v 1.3 2004/03/27 08:59:21 tjr Exp $"); + +#include +#include +#include + +#undef iswctype +int +iswctype(wint_t wc, wctype_t charclass) +{ + + return (__istype(wc, charclass)); +} + +wctype_t +wctype(const char *property) +{ + struct { + const char *name; + wctype_t mask; + } props[] = { + { "alnum", _CTYPE_A|_CTYPE_D }, + { "alpha", _CTYPE_A }, + { "blank", _CTYPE_B }, + { "cntrl", _CTYPE_C }, + { "digit", _CTYPE_D }, + { "graph", _CTYPE_G }, + { "lower", _CTYPE_L }, + { "print", _CTYPE_R }, + { "punct", _CTYPE_P }, + { "space", _CTYPE_S }, + { "upper", _CTYPE_U }, + { "xdigit", _CTYPE_X }, + { "ideogram", _CTYPE_I }, /* BSD extension */ + { "special", _CTYPE_T }, /* BSD extension */ + { "phonogram", _CTYPE_Q }, /* BSD extension */ + { "rune", 0xFFFFFF00L }, /* BSD extension */ + { NULL, 0UL }, /* Default */ + }; + int i; + + i = 0; + while (props[i].name != NULL && strcmp(props[i].name, property) != 0) + i++; + + return (props[i].mask); +} diff --git a/src/lib/libc/locale/wcwidth.c b/src/lib/libc/locale/wcwidth.c new file mode 100644 index 0000000..79f59dd --- /dev/null +++ b/src/lib/libc/locale/wcwidth.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/locale/wcwidth.c,v 1.5 2002/08/19 20:32:27 ache Exp $"); + +#include +#include + +#define _CTYPE_SWM 0xe0000000L /* Mask to get screen width data */ +#define _CTYPE_SWS 30 /* Bits to shift to get width */ + +int +wcwidth(wchar_t wc) +{ + int width; + + if (wc == L'\0') + return (0); + + width = __maskrune(wc, _CTYPE_SWM); + + /* 0 is autowidth (default) */ + return (width ? (int)((unsigned)width >> _CTYPE_SWS) + : (iswprint(wc) ? 1 : -1)); +} + diff --git a/src/lib/libc/quad/Makefile b/src/lib/libc/quad/Makefile new file mode 100644 index 0000000..74dc758 --- /dev/null +++ b/src/lib/libc/quad/Makefile @@ -0,0 +1,33 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = adddi3.o anddi3.o ashldi3.o ashrdi3.o cmpdi2.o divdi3.o fixdfdi.o fixsfdi.o fixunsdfdi.o fixunssfdi.o floatdidf.o floatdisf.o floatunsdidf.o iordi3.o lshldi3.o lshrdi3.o moddi3.o muldi3.o negdi2.o notdi2.o qdivrem.o subdi3.o ucmpdi2.o udivdi3.o umoddi3.o xordi3.o +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../../../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../../../include -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdlib -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/quad/adddi3.c b/src/lib/libc/quad/adddi3.c new file mode 100644 index 0000000..d97059e --- /dev/null +++ b/src/lib/libc/quad/adddi3.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)adddi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/adddi3.c,v 1.2 2002/03/22 21:52:42 obrien Exp $"); + +#include "quad.h" + +/* + * Add two quads. This is trivial since a one-bit carry from a single + * u_long addition x+y occurs if and only if the sum x+y is less than + * either x or y (the choice to compare with x or y is arbitrary). + */ +quad_t +__adddi3(a, b) + quad_t a, b; +{ + union uu aa, bb, sum; + + aa.q = a; + bb.q = b; + sum.ul[L] = aa.ul[L] + bb.ul[L]; + sum.ul[H] = aa.ul[H] + bb.ul[H] + (sum.ul[L] < bb.ul[L]); + return (sum.q); +} diff --git a/src/lib/libc/quad/anddi3.c b/src/lib/libc/quad/anddi3.c new file mode 100644 index 0000000..7d58cf1 --- /dev/null +++ b/src/lib/libc/quad/anddi3.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)anddi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/anddi3.c,v 1.2 2002/03/22 21:52:42 obrien Exp $"); + +#include "quad.h" + +/* + * Return a & b, in quad. + */ +quad_t +__anddi3(a, b) + quad_t a, b; +{ + union uu aa, bb; + + aa.q = a; + bb.q = b; + aa.ul[0] &= bb.ul[0]; + aa.ul[1] &= bb.ul[1]; + return (aa.q); +} diff --git a/src/lib/libc/quad/ashldi3.c b/src/lib/libc/quad/ashldi3.c new file mode 100644 index 0000000..6e9d493 --- /dev/null +++ b/src/lib/libc/quad/ashldi3.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)ashldi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/ashldi3.c,v 1.2 2002/03/22 21:52:42 obrien Exp $"); + +#include "quad.h" + +/* + * Shift a (signed) quad value left (arithmetic shift left). + * This is the same as logical shift left! + */ +quad_t +__ashldi3(a, shift) + quad_t a; + qshift_t shift; +{ + union uu aa; + + aa.q = a; + if (shift >= LONG_BITS) { + aa.ul[H] = shift >= QUAD_BITS ? 0 : + aa.ul[L] << (shift - LONG_BITS); + aa.ul[L] = 0; + } else if (shift > 0) { + aa.ul[H] = (aa.ul[H] << shift) | + (aa.ul[L] >> (LONG_BITS - shift)); + aa.ul[L] <<= shift; + } + return (aa.q); +} diff --git a/src/lib/libc/quad/ashrdi3.c b/src/lib/libc/quad/ashrdi3.c new file mode 100644 index 0000000..0d57b20 --- /dev/null +++ b/src/lib/libc/quad/ashrdi3.c @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)ashrdi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/ashrdi3.c,v 1.2 2002/03/22 21:52:42 obrien Exp $"); + +#include "quad.h" + +/* + * Shift a (signed) quad value right (arithmetic shift right). + */ +quad_t +__ashrdi3(a, shift) + quad_t a; + qshift_t shift; +{ + union uu aa; + + aa.q = a; + if (shift >= LONG_BITS) { + long s; + + /* + * Smear bits rightward using the machine's right-shift + * method, whether that is sign extension or zero fill, + * to get the `sign word' s. Note that shifting by + * LONG_BITS is undefined, so we shift (LONG_BITS-1), + * then 1 more, to get our answer. + */ + s = (aa.sl[H] >> (LONG_BITS - 1)) >> 1; + aa.ul[L] = shift >= QUAD_BITS ? s : + aa.sl[H] >> (shift - LONG_BITS); + aa.ul[H] = s; + } else if (shift > 0) { + aa.ul[L] = (aa.ul[L] >> shift) | + (aa.ul[H] << (LONG_BITS - shift)); + aa.sl[H] >>= shift; + } + return (aa.q); +} diff --git a/src/lib/libc/quad/cmpdi2.c b/src/lib/libc/quad/cmpdi2.c new file mode 100644 index 0000000..495a8ee --- /dev/null +++ b/src/lib/libc/quad/cmpdi2.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)cmpdi2.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/cmpdi2.c,v 1.2 2002/03/22 21:52:42 obrien Exp $"); + +#include "quad.h" + +/* + * Return 0, 1, or 2 as a <, =, > b respectively. + * Both a and b are considered signed---which means only the high word is + * signed. + */ +int +__cmpdi2(a, b) + quad_t a, b; +{ + union uu aa, bb; + + aa.q = a; + bb.q = b; + return (aa.sl[H] < bb.sl[H] ? 0 : aa.sl[H] > bb.sl[H] ? 2 : + aa.ul[L] < bb.ul[L] ? 0 : aa.ul[L] > bb.ul[L] ? 2 : 1); +} diff --git a/src/lib/libc/quad/divdi3.c b/src/lib/libc/quad/divdi3.c new file mode 100644 index 0000000..a8290d8 --- /dev/null +++ b/src/lib/libc/quad/divdi3.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)divdi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/divdi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Divide two signed quads. + * ??? if -1/2 should produce -1 on this machine, this code is wrong + */ +quad_t +__divdi3(a, b) + quad_t a, b; +{ + u_quad_t ua, ub, uq; + int neg; + + if (a < 0) + ua = -(u_quad_t)a, neg = 1; + else + ua = a, neg = 0; + if (b < 0) + ub = -(u_quad_t)b, neg ^= 1; + else + ub = b; + uq = __qdivrem(ua, ub, (u_quad_t *)0); + return (neg ? -uq : uq); +} diff --git a/src/lib/libc/quad/fixdfdi.c b/src/lib/libc/quad/fixdfdi.c new file mode 100644 index 0000000..10c2d51 --- /dev/null +++ b/src/lib/libc/quad/fixdfdi.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)fixdfdi.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/fixdfdi.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Convert double to (signed) quad. + * We clamp anything that is out of range. + */ +quad_t +__fixdfdi(x) + double x; +{ + if (x < 0) + if (x <= QUAD_MIN) + return (QUAD_MIN); + else + return ((quad_t)-(u_quad_t)-x); + else + if (x >= QUAD_MAX) + return (QUAD_MAX); + else + return ((quad_t)(u_quad_t)x); +} diff --git a/src/lib/libc/quad/fixsfdi.c b/src/lib/libc/quad/fixsfdi.c new file mode 100644 index 0000000..647a4a1 --- /dev/null +++ b/src/lib/libc/quad/fixsfdi.c @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 1992 The Regents of the University of California. + * All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)fixsfdi.c 5.1 (Berkeley) 7/7/92"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/fixsfdi.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Convert float to (signed) quad. + * We clamp anything that is out of range. + * + * N.B.: must use new ANSI syntax (sorry). + */ +long long +__fixsfdi(float x) +{ + if (x < 0) + if (x <= QUAD_MIN) + return (QUAD_MIN); + else + return ((quad_t)-(u_quad_t)-x); + else + if (x >= QUAD_MAX) + return (QUAD_MAX); + else + return ((quad_t)(u_quad_t)x); +} diff --git a/src/lib/libc/quad/fixunsdfdi.c b/src/lib/libc/quad/fixunsdfdi.c new file mode 100644 index 0000000..694cd62 --- /dev/null +++ b/src/lib/libc/quad/fixunsdfdi.c @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)fixunsdfdi.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/fixunsdfdi.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +#define ONE_FOURTH (1 << (LONG_BITS - 2)) +#define ONE_HALF (ONE_FOURTH * 2.0) +#define ONE (ONE_FOURTH * 4.0) + +/* + * Convert double to (unsigned) quad. + * Not sure what to do with negative numbers---for now, anything out + * of range becomes UQUAD_MAX. + */ +u_quad_t +__fixunsdfdi(x) + double x; +{ + double toppart; + union uu t; + + if (x < 0) + return (UQUAD_MAX); /* ??? should be 0? ERANGE??? */ +#ifdef notdef /* this falls afoul of a GCC bug */ + if (x >= UQUAD_MAX) + return (UQUAD_MAX); +#else /* so we wire in 2^64-1 instead */ + if (x >= 18446744073709551615.0) + return (UQUAD_MAX); +#endif + /* + * Get the upper part of the result. Note that the divide + * may round up; we want to avoid this if possible, so we + * subtract `1/2' first. + */ + toppart = (x - ONE_HALF) / ONE; + /* + * Now build a u_quad_t out of the top part. The difference + * between x and this is the bottom part (this may introduce + * a few fuzzy bits, but what the heck). With any luck this + * difference will be nonnegative: x should wind up in the + * range [0..ULONG_MAX]. For paranoia, we assume [LONG_MIN.. + * 2*ULONG_MAX] instead. + */ + t.ul[H] = (unsigned long)toppart; + t.ul[L] = 0; + x -= (double)t.uq; + if (x < 0) { + t.ul[H]--; + x += ULONG_MAX; + } + if (x > ULONG_MAX) { + t.ul[H]++; + x -= ULONG_MAX; + } + t.ul[L] = (u_long)x; + return (t.uq); +} diff --git a/src/lib/libc/quad/fixunssfdi.c b/src/lib/libc/quad/fixunssfdi.c new file mode 100644 index 0000000..1263fee --- /dev/null +++ b/src/lib/libc/quad/fixunssfdi.c @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)fixunssfdi.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/fixunssfdi.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +#define ONE_FOURTH (1 << (LONG_BITS - 2)) +#define ONE_HALF (ONE_FOURTH * 2.0) +#define ONE (ONE_FOURTH * 4.0) + +/* + * Convert float to (unsigned) quad. We do most of our work in double, + * out of sheer paranoia. + * + * Not sure what to do with negative numbers---for now, anything out + * of range becomes UQUAD_MAX. + * + * N.B.: must use new ANSI syntax (sorry). + */ +u_quad_t +__fixunssfdi(float f) +{ + double x, toppart; + union uu t; + + if (f < 0) + return (UQUAD_MAX); /* ??? should be 0? ERANGE??? */ +#ifdef notdef /* this falls afoul of a GCC bug */ + if (f >= UQUAD_MAX) + return (UQUAD_MAX); +#else /* so we wire in 2^64-1 instead */ + if (f >= 18446744073709551615.0) + return (UQUAD_MAX); +#endif + x = f; + /* + * Get the upper part of the result. Note that the divide + * may round up; we want to avoid this if possible, so we + * subtract `1/2' first. + */ + toppart = (x - ONE_HALF) / ONE; + /* + * Now build a u_quad_t out of the top part. The difference + * between x and this is the bottom part (this may introduce + * a few fuzzy bits, but what the heck). With any luck this + * difference will be nonnegative: x should wind up in the + * range [0..ULONG_MAX]. For paranoia, we assume [LONG_MIN.. + * 2*ULONG_MAX] instead. + */ + t.ul[H] = (unsigned long)toppart; + t.ul[L] = 0; + x -= (double)t.uq; + if (x < 0) { + t.ul[H]--; + x += ULONG_MAX; + } + if (x > ULONG_MAX) { + t.ul[H]++; + x -= ULONG_MAX; + } + t.ul[L] = (u_long)x; + return (t.uq); +} diff --git a/src/lib/libc/quad/floatdidf.c b/src/lib/libc/quad/floatdidf.c new file mode 100644 index 0000000..ba0b6a7 --- /dev/null +++ b/src/lib/libc/quad/floatdidf.c @@ -0,0 +1,76 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)floatdidf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/floatdidf.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Convert (signed) quad to double. + */ +double +__floatdidf(x) + quad_t x; +{ + double d; + union uu u; + int neg; + + /* + * Get an unsigned number first, by negating if necessary. + */ + if (x < 0) + u.q = -x, neg = 1; + else + u.q = x, neg = 0; + + /* + * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L] + * has the units. Ideally we could just set d, add LONG_BITS to + * its exponent, and then add the units, but this is portable + * code and does not know how to get at an exponent. Machine- + * specific code may be able to do this more efficiently. + */ + d = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0); + d += u.ul[L]; + + return (neg ? -d : d); +} diff --git a/src/lib/libc/quad/floatdisf.c b/src/lib/libc/quad/floatdisf.c new file mode 100644 index 0000000..bac96c2 --- /dev/null +++ b/src/lib/libc/quad/floatdisf.c @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)floatdisf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/floatdisf.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Convert (signed) quad to float. + */ +float +__floatdisf(x) + quad_t x; +{ + float f; + union uu u; + int neg; + + /* + * Get an unsigned number first, by negating if necessary. + */ + if (x < 0) + u.q = -x, neg = 1; + else + u.q = x, neg = 0; + + /* + * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L] + * has the units. Ideally we could just set f, add LONG_BITS to + * its exponent, and then add the units, but this is portable + * code and does not know how to get at an exponent. Machine- + * specific code may be able to do this more efficiently. + * + * Using double here may be excessive paranoia. + */ + f = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0); + f += u.ul[L]; + + return (neg ? -f : f); +} diff --git a/src/lib/libc/quad/floatunsdidf.c b/src/lib/libc/quad/floatunsdidf.c new file mode 100644 index 0000000..66bf63b --- /dev/null +++ b/src/lib/libc/quad/floatunsdidf.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)floatunsdidf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/floatunsdidf.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Convert (unsigned) quad to double. + * This is exactly like floatdidf.c except that negatives never occur. + */ +double +__floatunsdidf(x) + u_quad_t x; +{ + double d; + union uu u; + + u.uq = x; + d = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0); + d += u.ul[L]; + return (d); +} diff --git a/src/lib/libc/quad/iordi3.c b/src/lib/libc/quad/iordi3.c new file mode 100644 index 0000000..be16676 --- /dev/null +++ b/src/lib/libc/quad/iordi3.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)iordi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/iordi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Return a | b, in quad. + */ +quad_t +__iordi3(a, b) + quad_t a, b; +{ + union uu aa, bb; + + aa.q = a; + bb.q = b; + aa.ul[0] |= bb.ul[0]; + aa.ul[1] |= bb.ul[1]; + return (aa.q); +} diff --git a/src/lib/libc/quad/lshldi3.c b/src/lib/libc/quad/lshldi3.c new file mode 100644 index 0000000..261f4b0 --- /dev/null +++ b/src/lib/libc/quad/lshldi3.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)lshldi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/lshldi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Shift an (unsigned) quad value left (logical shift left). + * This is the same as arithmetic shift left! + */ +quad_t +__lshldi3(a, shift) + quad_t a; + qshift_t shift; +{ + union uu aa; + + aa.q = a; + if (shift >= LONG_BITS) { + aa.ul[H] = shift >= QUAD_BITS ? 0 : + aa.ul[L] << (shift - LONG_BITS); + aa.ul[L] = 0; + } else if (shift > 0) { + aa.ul[H] = (aa.ul[H] << shift) | + (aa.ul[L] >> (LONG_BITS - shift)); + aa.ul[L] <<= shift; + } + return (aa.q); +} diff --git a/src/lib/libc/quad/lshrdi3.c b/src/lib/libc/quad/lshrdi3.c new file mode 100644 index 0000000..9f35ed6 --- /dev/null +++ b/src/lib/libc/quad/lshrdi3.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)lshrdi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/lshrdi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Shift an (unsigned) quad value right (logical shift right). + */ +quad_t +__lshrdi3(a, shift) + quad_t a; + qshift_t shift; +{ + union uu aa; + + aa.q = a; + if (shift >= LONG_BITS) { + aa.ul[L] = shift >= QUAD_BITS ? 0 : + aa.ul[H] >> (shift - LONG_BITS); + aa.ul[H] = 0; + } else if (shift > 0) { + aa.ul[L] = (aa.ul[L] >> shift) | + (aa.ul[H] << (LONG_BITS - shift)); + aa.ul[H] >>= shift; + } + return (aa.q); +} diff --git a/src/lib/libc/quad/moddi3.c b/src/lib/libc/quad/moddi3.c new file mode 100644 index 0000000..7a51dd3 --- /dev/null +++ b/src/lib/libc/quad/moddi3.c @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)moddi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/moddi3.c,v 1.3 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Return remainder after dividing two signed quads. + * + * XXX + * If -1/2 should produce -1 on this machine, this code is wrong. + */ +quad_t +__moddi3(a, b) + quad_t a, b; +{ + u_quad_t ua, ub, ur; + int neg; + + if (a < 0) + ua = -(u_quad_t)a, neg = 1; + else + ua = a, neg = 0; + if (b < 0) + ub = -(u_quad_t)b; + else + ub = b; + (void)__qdivrem(ua, ub, &ur); + return (neg ? -ur : ur); +} diff --git a/src/lib/libc/quad/muldi3.c b/src/lib/libc/quad/muldi3.c new file mode 100644 index 0000000..cc0c887 --- /dev/null +++ b/src/lib/libc/quad/muldi3.c @@ -0,0 +1,248 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)muldi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/muldi3.c,v 1.3 2002/03/21 18:40:57 obrien Exp $"); + +#include "quad.h" + +/* + * Multiply two quads. + * + * Our algorithm is based on the following. Split incoming quad values + * u and v (where u,v >= 0) into + * + * u = 2^n u1 * u0 (n = number of bits in `u_long', usu. 32) + * + * and + * + * v = 2^n v1 * v0 + * + * Then + * + * uv = 2^2n u1 v1 + 2^n u1 v0 + 2^n v1 u0 + u0 v0 + * = 2^2n u1 v1 + 2^n (u1 v0 + v1 u0) + u0 v0 + * + * Now add 2^n u1 v1 to the first term and subtract it from the middle, + * and add 2^n u0 v0 to the last term and subtract it from the middle. + * This gives: + * + * uv = (2^2n + 2^n) (u1 v1) + + * (2^n) (u1 v0 - u1 v1 + u0 v1 - u0 v0) + + * (2^n + 1) (u0 v0) + * + * Factoring the middle a bit gives us: + * + * uv = (2^2n + 2^n) (u1 v1) + [u1v1 = high] + * (2^n) (u1 - u0) (v0 - v1) + [(u1-u0)... = mid] + * (2^n + 1) (u0 v0) [u0v0 = low] + * + * The terms (u1 v1), (u1 - u0) (v0 - v1), and (u0 v0) can all be done + * in just half the precision of the original. (Note that either or both + * of (u1 - u0) or (v0 - v1) may be negative.) + * + * This algorithm is from Knuth vol. 2 (2nd ed), section 4.3.3, p. 278. + * + * Since C does not give us a `long * long = quad' operator, we split + * our input quads into two longs, then split the two longs into two + * shorts. We can then calculate `short * short = long' in native + * arithmetic. + * + * Our product should, strictly speaking, be a `long quad', with 128 + * bits, but we are going to discard the upper 64. In other words, + * we are not interested in uv, but rather in (uv mod 2^2n). This + * makes some of the terms above vanish, and we get: + * + * (2^n)(high) + (2^n)(mid) + (2^n + 1)(low) + * + * or + * + * (2^n)(high + mid + low) + low + * + * Furthermore, `high' and `mid' can be computed mod 2^n, as any factor + * of 2^n in either one will also vanish. Only `low' need be computed + * mod 2^2n, and only because of the final term above. + */ +static quad_t __lmulq(u_long, u_long); + +quad_t +__muldi3(a, b) + quad_t a, b; +{ + union uu u, v, low, prod; + u_long high, mid, udiff, vdiff; + int negall, negmid; +#define u1 u.ul[H] +#define u0 u.ul[L] +#define v1 v.ul[H] +#define v0 v.ul[L] + + /* + * Get u and v such that u, v >= 0. When this is finished, + * u1, u0, v1, and v0 will be directly accessible through the + * longword fields. + */ + if (a >= 0) + u.q = a, negall = 0; + else + u.q = -a, negall = 1; + if (b >= 0) + v.q = b; + else + v.q = -b, negall ^= 1; + + if (u1 == 0 && v1 == 0) { + /* + * An (I hope) important optimization occurs when u1 and v1 + * are both 0. This should be common since most numbers + * are small. Here the product is just u0*v0. + */ + prod.q = __lmulq(u0, v0); + } else { + /* + * Compute the three intermediate products, remembering + * whether the middle term is negative. We can discard + * any upper bits in high and mid, so we can use native + * u_long * u_long => u_long arithmetic. + */ + low.q = __lmulq(u0, v0); + + if (u1 >= u0) + negmid = 0, udiff = u1 - u0; + else + negmid = 1, udiff = u0 - u1; + if (v0 >= v1) + vdiff = v0 - v1; + else + vdiff = v1 - v0, negmid ^= 1; + mid = udiff * vdiff; + + high = u1 * v1; + + /* + * Assemble the final product. + */ + prod.ul[H] = high + (negmid ? -mid : mid) + low.ul[L] + + low.ul[H]; + prod.ul[L] = low.ul[L]; + } + return (negall ? -prod.q : prod.q); +#undef u1 +#undef u0 +#undef v1 +#undef v0 +} + +/* + * Multiply two 2N-bit longs to produce a 4N-bit quad, where N is half + * the number of bits in a long (whatever that is---the code below + * does not care as long as quad.h does its part of the bargain---but + * typically N==16). + * + * We use the same algorithm from Knuth, but this time the modulo refinement + * does not apply. On the other hand, since N is half the size of a long, + * we can get away with native multiplication---none of our input terms + * exceeds (ULONG_MAX >> 1). + * + * Note that, for u_long l, the quad-precision result + * + * l << N + * + * splits into high and low longs as HHALF(l) and LHUP(l) respectively. + */ +static quad_t +__lmulq(u_long u, u_long v) +{ + u_long u1, u0, v1, v0, udiff, vdiff, high, mid, low; + u_long prodh, prodl, was; + union uu prod; + int neg; + + u1 = HHALF(u); + u0 = LHALF(u); + v1 = HHALF(v); + v0 = LHALF(v); + + low = u0 * v0; + + /* This is the same small-number optimization as before. */ + if (u1 == 0 && v1 == 0) + return (low); + + if (u1 >= u0) + udiff = u1 - u0, neg = 0; + else + udiff = u0 - u1, neg = 1; + if (v0 >= v1) + vdiff = v0 - v1; + else + vdiff = v1 - v0, neg ^= 1; + mid = udiff * vdiff; + + high = u1 * v1; + + /* prod = (high << 2N) + (high << N); */ + prodh = high + HHALF(high); + prodl = LHUP(high); + + /* if (neg) prod -= mid << N; else prod += mid << N; */ + if (neg) { + was = prodl; + prodl -= LHUP(mid); + prodh -= HHALF(mid) + (prodl > was); + } else { + was = prodl; + prodl += LHUP(mid); + prodh += HHALF(mid) + (prodl < was); + } + + /* prod += low << N */ + was = prodl; + prodl += LHUP(low); + prodh += HHALF(low) + (prodl < was); + /* ... + low; */ + if ((prodl += low) < low) + prodh++; + + /* return 4N-bit product */ + prod.ul[H] = prodh; + prod.ul[L] = prodl; + return (prod.q); +} diff --git a/src/lib/libc/quad/negdi2.c b/src/lib/libc/quad/negdi2.c new file mode 100644 index 0000000..f1de706 --- /dev/null +++ b/src/lib/libc/quad/negdi2.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)negdi2.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/negdi2.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Return -a (or, equivalently, 0 - a), in quad. See subdi3.c. + */ +quad_t +__negdi2(a) + quad_t a; +{ + union uu aa, res; + + aa.q = a; + res.ul[L] = -aa.ul[L]; + res.ul[H] = -aa.ul[H] - (res.ul[L] > 0); + return (res.q); +} diff --git a/src/lib/libc/quad/notdi2.c b/src/lib/libc/quad/notdi2.c new file mode 100644 index 0000000..354abe5 --- /dev/null +++ b/src/lib/libc/quad/notdi2.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)notdi2.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/notdi2.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Return ~a. For some reason gcc calls this `one's complement' rather + * than `not'. + */ +quad_t +__one_cmpldi2(a) + quad_t a; +{ + union uu aa; + + aa.q = a; + aa.ul[0] = ~aa.ul[0]; + aa.ul[1] = ~aa.ul[1]; + return (aa.q); +} diff --git a/src/lib/libc/quad/qdivrem.c b/src/lib/libc/quad/qdivrem.c new file mode 100644 index 0000000..b57077a --- /dev/null +++ b/src/lib/libc/quad/qdivrem.c @@ -0,0 +1,281 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)qdivrem.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/qdivrem.c,v 1.3 2002/03/21 18:40:57 obrien Exp $"); + +/* + * Multiprecision divide. This algorithm is from Knuth vol. 2 (2nd ed), + * section 4.3.1, pp. 257--259. + */ + +#include "quad.h" + +#define B (1 << HALF_BITS) /* digit base */ + +/* Combine two `digits' to make a single two-digit number. */ +#define COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b)) + +/* select a type for digits in base B: use unsigned short if they fit */ +#if ULONG_MAX == 0xffffffff && USHRT_MAX >= 0xffff +typedef unsigned short digit; +#else +typedef u_long digit; +#endif + +/* + * Shift p[0]..p[len] left `sh' bits, ignoring any bits that + * `fall out' the left (there never will be any such anyway). + * We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS. + */ +static void +shl(digit *p, int len, int sh) +{ + int i; + + for (i = 0; i < len; i++) + p[i] = LHALF(p[i] << sh) | (p[i + 1] >> (HALF_BITS - sh)); + p[i] = LHALF(p[i] << sh); +} + +/* + * __qdivrem(u, v, rem) returns u/v and, optionally, sets *rem to u%v. + * + * We do this in base 2-sup-HALF_BITS, so that all intermediate products + * fit within u_long. As a consequence, the maximum length dividend and + * divisor are 4 `digits' in this base (they are shorter if they have + * leading zeros). + */ +u_quad_t +__qdivrem(uq, vq, arq) + u_quad_t uq, vq, *arq; +{ + union uu tmp; + digit *u, *v, *q; + digit v1, v2; + u_long qhat, rhat, t; + int m, n, d, j, i; + digit uspace[5], vspace[5], qspace[5]; + + /* + * Take care of special cases: divide by zero, and u < v. + */ + if (vq == 0) { + /* divide by zero. */ + static volatile const unsigned int zero = 0; + + tmp.ul[H] = tmp.ul[L] = 1 / zero; + if (arq) + *arq = uq; + return (tmp.q); + } + if (uq < vq) { + if (arq) + *arq = uq; + return (0); + } + u = &uspace[0]; + v = &vspace[0]; + q = &qspace[0]; + + /* + * Break dividend and divisor into digits in base B, then + * count leading zeros to determine m and n. When done, we + * will have: + * u = (u[1]u[2]...u[m+n]) sub B + * v = (v[1]v[2]...v[n]) sub B + * v[1] != 0 + * 1 < n <= 4 (if n = 1, we use a different division algorithm) + * m >= 0 (otherwise u < v, which we already checked) + * m + n = 4 + * and thus + * m = 4 - n <= 2 + */ + tmp.uq = uq; + u[0] = 0; + u[1] = HHALF(tmp.ul[H]); + u[2] = LHALF(tmp.ul[H]); + u[3] = HHALF(tmp.ul[L]); + u[4] = LHALF(tmp.ul[L]); + tmp.uq = vq; + v[1] = HHALF(tmp.ul[H]); + v[2] = LHALF(tmp.ul[H]); + v[3] = HHALF(tmp.ul[L]); + v[4] = LHALF(tmp.ul[L]); + for (n = 4; v[1] == 0; v++) { + if (--n == 1) { + u_long rbj; /* r*B+u[j] (not root boy jim) */ + digit q1, q2, q3, q4; + + /* + * Change of plan, per exercise 16. + * r = 0; + * for j = 1..4: + * q[j] = floor((r*B + u[j]) / v), + * r = (r*B + u[j]) % v; + * We unroll this completely here. + */ + t = v[2]; /* nonzero, by definition */ + q1 = u[1] / t; + rbj = COMBINE(u[1] % t, u[2]); + q2 = rbj / t; + rbj = COMBINE(rbj % t, u[3]); + q3 = rbj / t; + rbj = COMBINE(rbj % t, u[4]); + q4 = rbj / t; + if (arq) + *arq = rbj % t; + tmp.ul[H] = COMBINE(q1, q2); + tmp.ul[L] = COMBINE(q3, q4); + return (tmp.q); + } + } + + /* + * By adjusting q once we determine m, we can guarantee that + * there is a complete four-digit quotient at &qspace[1] when + * we finally stop. + */ + for (m = 4 - n; u[1] == 0; u++) + m--; + for (i = 4 - m; --i >= 0;) + q[i] = 0; + q += 4 - m; + + /* + * Here we run Program D, translated from MIX to C and acquiring + * a few minor changes. + * + * D1: choose multiplier 1 << d to ensure v[1] >= B/2. + */ + d = 0; + for (t = v[1]; t < B / 2; t <<= 1) + d++; + if (d > 0) { + shl(&u[0], m + n, d); /* u <<= d */ + shl(&v[1], n - 1, d); /* v <<= d */ + } + /* + * D2: j = 0. + */ + j = 0; + v1 = v[1]; /* for D3 -- note that v[1..n] are constant */ + v2 = v[2]; /* for D3 */ + do { + digit uj0, uj1, uj2; + + /* + * D3: Calculate qhat (\^q, in TeX notation). + * Let qhat = min((u[j]*B + u[j+1])/v[1], B-1), and + * let rhat = (u[j]*B + u[j+1]) mod v[1]. + * While rhat < B and v[2]*qhat > rhat*B+u[j+2], + * decrement qhat and increase rhat correspondingly. + * Note that if rhat >= B, v[2]*qhat < rhat*B. + */ + uj0 = u[j + 0]; /* for D3 only -- note that u[j+...] change */ + uj1 = u[j + 1]; /* for D3 only */ + uj2 = u[j + 2]; /* for D3 only */ + if (uj0 == v1) { + qhat = B; + rhat = uj1; + goto qhat_too_big; + } else { + u_long n = COMBINE(uj0, uj1); + qhat = n / v1; + rhat = n % v1; + } + while (v2 * qhat > COMBINE(rhat, uj2)) { + qhat_too_big: + qhat--; + if ((rhat += v1) >= B) + break; + } + /* + * D4: Multiply and subtract. + * The variable `t' holds any borrows across the loop. + * We split this up so that we do not require v[0] = 0, + * and to eliminate a final special case. + */ + for (t = 0, i = n; i > 0; i--) { + t = u[i + j] - v[i] * qhat - t; + u[i + j] = LHALF(t); + t = (B - HHALF(t)) & (B - 1); + } + t = u[j] - t; + u[j] = LHALF(t); + /* + * D5: test remainder. + * There is a borrow if and only if HHALF(t) is nonzero; + * in that (rare) case, qhat was too large (by exactly 1). + * Fix it by adding v[1..n] to u[j..j+n]. + */ + if (HHALF(t)) { + qhat--; + for (t = 0, i = n; i > 0; i--) { /* D6: add back. */ + t += u[i + j] + v[i]; + u[i + j] = LHALF(t); + t = HHALF(t); + } + u[j] = LHALF(u[j] + t); + } + q[j] = qhat; + } while (++j <= m); /* D7: loop on j. */ + + /* + * If caller wants the remainder, we have to calculate it as + * u[m..m+n] >> d (this is at most n digits and thus fits in + * u[m+1..m+n], but we may need more source digits). + */ + if (arq) { + if (d) { + for (i = m + n; i > m; --i) + u[i] = (u[i] >> d) | + LHALF(u[i - 1] << (HALF_BITS - d)); + u[i] = 0; + } + tmp.ul[H] = COMBINE(uspace[1], uspace[2]); + tmp.ul[L] = COMBINE(uspace[3], uspace[4]); + *arq = tmp.q; + } + + tmp.ul[H] = COMBINE(qspace[1], qspace[2]); + tmp.ul[L] = COMBINE(qspace[3], qspace[4]); + return (tmp.q); +} diff --git a/src/lib/libc/quad/quad.h b/src/lib/libc/quad/quad.h new file mode 100644 index 0000000..60a2ffb --- /dev/null +++ b/src/lib/libc/quad/quad.h @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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. + * + * @(#)quad.h 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/lib/libc/quad/quad.h,v 1.6 2002/03/21 22:47:55 obrien Exp $ + */ + +/* + * Quad arithmetic. + * + * This library makes the following assumptions: + * + * - The type long long (aka quad_t) exists. + * + * - A quad variable is exactly twice as long as `long'. + * + * - The machine's arithmetic is two's complement. + * + * This library can provide 128-bit arithmetic on a machine with 128-bit + * quads and 64-bit longs, for instance, or 96-bit arithmetic on machines + * with 48-bit longs. + */ + +#include +#include + +/* + * Depending on the desired operation, we view a `long long' (aka quad_t) in + * one or more of the following formats. + */ +union uu { + quad_t q; /* as a (signed) quad */ + quad_t uq; /* as an unsigned quad */ + long sl[2]; /* as two signed longs */ + u_long ul[2]; /* as two unsigned longs */ +}; + +/* + * Define high and low longwords. + */ +#define H _QUAD_HIGHWORD +#define L _QUAD_LOWWORD + +/* + * Total number of bits in a quad_t and in the pieces that make it up. + * These are used for shifting, and also below for halfword extraction + * and assembly. + */ +#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT) +#define LONG_BITS (sizeof(long) * CHAR_BIT) +#define HALF_BITS (sizeof(long) * CHAR_BIT / 2) + +/* + * Extract high and low shortwords from longword, and move low shortword of + * longword to upper half of long, i.e., produce the upper longword of + * ((quad_t)(x) << (number_of_bits_in_long/2)). (`x' must actually be u_long.) + * + * These are used in the multiply code, to split a longword into upper + * and lower halves, and to reassemble a product as a quad_t, shifted left + * (sizeof(long)*CHAR_BIT/2). + */ +#define HHALF(x) ((x) >> HALF_BITS) +#define LHALF(x) ((x) & ((1 << HALF_BITS) - 1)) +#define LHUP(x) ((x) << HALF_BITS) + +quad_t __divdi3(quad_t a, quad_t b); +quad_t __moddi3(quad_t a, quad_t b); +u_quad_t __qdivrem(u_quad_t u, u_quad_t v, u_quad_t *rem); +u_quad_t __udivdi3(u_quad_t a, u_quad_t b); +u_quad_t __umoddi3(u_quad_t a, u_quad_t b); + +/* + * XXX + * Compensate for gcc 1 vs gcc 2. Gcc 1 defines ?sh?di3's second argument + * as u_quad_t, while gcc 2 correctly uses int. Unfortunately, we still use + * both compilers. + */ +#if __GNUC__ >= 2 +typedef unsigned int qshift_t; +#else +typedef u_quad_t qshift_t; +#endif diff --git a/src/lib/libc/quad/subdi3.c b/src/lib/libc/quad/subdi3.c new file mode 100644 index 0000000..64adfda --- /dev/null +++ b/src/lib/libc/quad/subdi3.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)subdi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/subdi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Subtract two quad values. This is trivial since a one-bit carry + * from a single u_long difference x-y occurs if and only if (x-y) > x. + */ +quad_t +__subdi3(a, b) + quad_t a, b; +{ + union uu aa, bb, diff; + + aa.q = a; + bb.q = b; + diff.ul[L] = aa.ul[L] - bb.ul[L]; + diff.ul[H] = aa.ul[H] - bb.ul[H] - (diff.ul[L] > aa.ul[L]); + return (diff.q); +} diff --git a/src/lib/libc/quad/ucmpdi2.c b/src/lib/libc/quad/ucmpdi2.c new file mode 100644 index 0000000..d5958ba --- /dev/null +++ b/src/lib/libc/quad/ucmpdi2.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)ucmpdi2.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/ucmpdi2.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Return 0, 1, or 2 as a <, =, > b respectively. + * Neither a nor b are considered signed. + */ +int +__ucmpdi2(a, b) + u_quad_t a, b; +{ + union uu aa, bb; + + aa.uq = a; + bb.uq = b; + return (aa.ul[H] < bb.ul[H] ? 0 : aa.ul[H] > bb.ul[H] ? 2 : + aa.ul[L] < bb.ul[L] ? 0 : aa.ul[L] > bb.ul[L] ? 2 : 1); +} diff --git a/src/lib/libc/quad/udivdi3.c b/src/lib/libc/quad/udivdi3.c new file mode 100644 index 0000000..f7ce83a --- /dev/null +++ b/src/lib/libc/quad/udivdi3.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)udivdi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/udivdi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Divide two unsigned quads. + */ +u_quad_t +__udivdi3(a, b) + u_quad_t a, b; +{ + + return (__qdivrem(a, b, (u_quad_t *)0)); +} diff --git a/src/lib/libc/quad/umoddi3.c b/src/lib/libc/quad/umoddi3.c new file mode 100644 index 0000000..12703c7 --- /dev/null +++ b/src/lib/libc/quad/umoddi3.c @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)umoddi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/umoddi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Return remainder after dividing two unsigned quads. + */ +u_quad_t +__umoddi3(a, b) + u_quad_t a, b; +{ + u_quad_t r; + + (void)__qdivrem(a, b, &r); + return (r); +} diff --git a/src/lib/libc/quad/xordi3.c b/src/lib/libc/quad/xordi3.c new file mode 100644 index 0000000..73594de --- /dev/null +++ b/src/lib/libc/quad/xordi3.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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[] = "@(#)xordi3.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/quad/xordi3.c,v 1.2 2002/03/22 21:52:43 obrien Exp $"); + +#include "quad.h" + +/* + * Return a ^ b, in quad. + */ +quad_t +__xordi3(a, b) + quad_t a, b; +{ + union uu aa, bb; + + aa.q = a; + bb.q = b; + aa.ul[0] ^= bb.ul[0]; + aa.ul[1] ^= bb.ul[1]; + return (aa.q); +} diff --git a/src/lib/libc/stdio/Makefile b/src/lib/libc/stdio/Makefile new file mode 100644 index 0000000..c416e2b --- /dev/null +++ b/src/lib/libc/stdio/Makefile @@ -0,0 +1,34 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = _flock_stub.o asprintf.o clrerr.o fclose.o fd.o fdopen.o feof.o ferror.o fflush.o fgetc.o fgetln.o fgetpos.o fgets.o fgetwc.o fgetws.o fileno.o findfp.o flags.o fopen.o fprintf.o fpurge.o fputc.o fputs.o fputwc.o fputws.o fread.o freopen.o fscanf.o fseek.o fsetpos.o ftell.o funopen.o fvwrite.o fwalk.o fwide.o fwprintf.o fwrite.o fwscanf.o getc.o getchar.o gets.o getw.o getwc.o getwchar.o makebuf.o mktemp.o perror.o printf.o putc.o putchar.o puts.o putw.o putwc.o putwchar.o refill.o remove.o rewind.o rget.o scanf.o setbuf.o setbuffer.o setvbuf.o snprintf.o sprintf.o sscanf.o stdio.o swprintf.o swscanf.o tempnam.o tmpfile.o tmpnam.o ungetc.o ungetwc.o unlocked.o vasprintf.o vfprintf.o vfscanf.o vfwprintf.o vfwscanf.o vprintf.o vscanf.o vsnprintf.o vsprintf.o vsscanf.o vswprintf.o vswscanf.o vwprintf.o vwscanf.o wbuf.o wprintf.o wscanf.o wsetup.o + +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -I../../../include -I../i386 -I../locale -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdlib -O -I../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdlib -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/stdio/_flock_stub.c b/src/lib/libc/stdio/_flock_stub.c new file mode 100644 index 0000000..3a73ee1 --- /dev/null +++ b/src/lib/libc/stdio/_flock_stub.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 1998 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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. + */ + +/* + * POSIX stdio FILE locking functions. These assume that the locking + * is only required at FILE structure level, not at file descriptor + * level too. + * + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/_flock_stub.c,v 1.14 2004/03/09 04:51:58 jb Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" + +#include "local.h" + + +/* + * Weak symbols for externally visible functions in this file: + */ +__weak_reference(_flockfile, flockfile); +__weak_reference(_flockfile_debug_stub, _flockfile_debug); +__weak_reference(_ftrylockfile, ftrylockfile); +__weak_reference(_funlockfile, funlockfile); + +/* + * We need to retain binary compatibility for a while. So pretend + * that _lock is part of FILE * even though it is dereferenced off + * _extra now. When we stop encoding the size of FILE into binaries + * this can be changed in stdio.h. This will reduce the amount of + * code that has to change in the future (just remove this comment + * and #define). + */ +#define _lock _extra + +void +_flockfile(FILE *fp) +{ + pthread_t curthread = _pthread_self(); + + if (fp->_lock->fl_owner == curthread) + fp->_lock->fl_count++; + else { + /* + * Make sure this mutex is treated as a private + * internal mutex: + */ + _pthread_mutex_lock(&fp->_lock->fl_mutex); + fp->_lock->fl_owner = curthread; + fp->_lock->fl_count = 1; + } +} + +/* + * This can be overriden by the threads library if it is linked in. + */ +void +_flockfile_debug_stub(FILE *fp, char *fname, int lineno) +{ + _flockfile(fp); +} + +int +_ftrylockfile(FILE *fp) +{ + pthread_t curthread = _pthread_self(); + int ret = 0; + + if (fp->_lock->fl_owner == curthread) + fp->_lock->fl_count++; + /* + * Make sure this mutex is treated as a private + * internal mutex: + */ + else if (_pthread_mutex_trylock(&fp->_lock->fl_mutex) == 0) { + fp->_lock->fl_owner = curthread; + fp->_lock->fl_count = 1; + } + else + ret = -1; + return (ret); +} + +void +_funlockfile(FILE *fp) +{ + pthread_t curthread = _pthread_self(); + + /* + * Check if this file is owned by the current thread: + */ + if (fp->_lock->fl_owner == curthread) { + /* + * Check if this thread has locked the FILE + * more than once: + */ + if (fp->_lock->fl_count > 1) + /* + * Decrement the count of the number of + * times the running thread has locked this + * file: + */ + fp->_lock->fl_count--; + else { + /* + * The running thread will release the + * lock now: + */ + fp->_lock->fl_count = 0; + fp->_lock->fl_owner = NULL; + _pthread_mutex_unlock(&fp->_lock->fl_mutex); + } + } +} diff --git a/src/lib/libc/stdio/asprintf.c b/src/lib/libc/stdio/asprintf.c new file mode 100644 index 0000000..02362b0 --- /dev/null +++ b/src/lib/libc/stdio/asprintf.c @@ -0,0 +1,71 @@ +/* $OpenBSD: asprintf.c,v 1.8 2002/02/19 19:39:36 millert Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/asprintf.c,v 1.13 2002/09/26 13:09:48 tjr Exp $"); + +#include +#include +#include +#include + +#include "local.h" + +int +asprintf(char **str, char const *fmt, ...) +{ + int ret; + va_list ap; + FILE f; + struct __sFILEX ext; + + f._file = -1; + f._flags = __SWR | __SSTR | __SALC; + f._bf._base = f._p = (unsigned char *)malloc(128); + if (f._bf._base == NULL) { + *str = NULL; + errno = ENOMEM; + return (-1); + } + f._bf._size = f._w = 127; /* Leave room for the NUL */ + f._extra = &ext; + INITEXTRA(&f); + va_start(ap, fmt); + ret = __vfprintf(&f, fmt, ap); /* Use unlocked __vfprintf */ + va_end(ap); + if (ret < 0) { + free(f._bf._base); + *str = NULL; + errno = ENOMEM; + return (-1); + } + *f._p = '\0'; + *str = (char *)f._bf._base; + return (ret); +} diff --git a/src/lib/libc/stdio/clrerr.c b/src/lib/libc/stdio/clrerr.c new file mode 100644 index 0000000..bfac2c1 --- /dev/null +++ b/src/lib/libc/stdio/clrerr.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/clrerr.c,v 1.9 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" +#undef clearerr + +void +clearerr(fp) + FILE *fp; +{ + FLOCKFILE(fp); + __sclearerr(fp); + FUNLOCKFILE(fp); +} diff --git a/src/lib/libc/stdio/fclose.c b/src/lib/libc/stdio/fclose.c new file mode 100644 index 0000000..ad4dae7 --- /dev/null +++ b/src/lib/libc/stdio/fclose.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fclose.c,v 1.11 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +int +fclose(FILE *fp) +{ + int r; + + if (fp->_flags == 0) { /* not open! */ + errno = EBADF; + return (EOF); + } + FLOCKFILE(fp); + r = fp->_flags & __SWR ? __sflush(fp) : 0; + if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) + r = EOF; + if (fp->_flags & __SMBF) + free((char *)fp->_bf._base); + if (HASUB(fp)) + FREEUB(fp); + if (HASLB(fp)) + FREELB(fp); + fp->_file = -1; + fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ + fp->_flags = 0; /* Release this FILE for reuse. */ + FUNLOCKFILE(fp); + return (r); +} diff --git a/src/lib/libc/stdio/fd.c b/src/lib/libc/stdio/fd.c new file mode 100644 index 0000000..0317e76 --- /dev/null +++ b/src/lib/libc/stdio/fd.c @@ -0,0 +1,44 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +FILE fdTable[3] = { + {0x0}, /* stdin */ + {0x1}, /* stdout */ + {0x2} /* stderr */ + }; + +/*** + $Log$ + Revision 1.2 2004/06/16 19:38:26 reddawg + Updated CW Cleaned Out Dead Code + + END + ***/ diff --git a/src/lib/libc/stdio/fdopen.c b/src/lib/libc/stdio/fdopen.c new file mode 100644 index 0000000..15e7e8f --- /dev/null +++ b/src/lib/libc/stdio/fdopen.c @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fdopen.c,v 1.7 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "local.h" + +FILE * +fdopen(fd, mode) + int fd; + const char *mode; +{ + FILE *fp; + static int nofile; + int flags, oflags, fdflags, tmp; + + if (nofile == 0) + nofile = getdtablesize(); + + if ((flags = __sflags(mode, &oflags)) == 0) + return (NULL); + + /* Make sure the mode the user wants is a subset of the actual mode. */ + if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0) + return (NULL); + tmp = fdflags & O_ACCMODE; + if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { + errno = EINVAL; + return (NULL); + } + + if ((fp = __sfp()) == NULL) + return (NULL); + fp->_flags = flags; + /* + * If opened for appending, but underlying descriptor does not have + * O_APPEND bit set, assert __SAPP so that __swrite() caller + * will _sseek() to the end before write. + */ + if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) + fp->_flags |= __SAPP; + fp->_file = fd; + fp->_cookie = fp; + fp->_read = __sread; + fp->_write = __swrite; + fp->_seek = __sseek; + fp->_close = __sclose; + return (fp); +} diff --git a/src/lib/libc/stdio/feof.c b/src/lib/libc/stdio/feof.c new file mode 100644 index 0000000..7c09187 --- /dev/null +++ b/src/lib/libc/stdio/feof.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/feof.c,v 1.9 2004/03/17 01:43:07 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" + +#undef feof + +int +feof(FILE *fp) +{ + int ret; + + FLOCKFILE(fp); + ret= __sfeof(fp); + FUNLOCKFILE(fp); + return (ret); +} diff --git a/src/lib/libc/stdio/ferror.c b/src/lib/libc/stdio/ferror.c new file mode 100644 index 0000000..0f960f7 --- /dev/null +++ b/src/lib/libc/stdio/ferror.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/ferror.c,v 1.9 2004/03/17 01:43:07 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" + +#undef ferror + +int +ferror(FILE *fp) +{ + int ret; + + FLOCKFILE(fp); + ret = __sferror(fp); + FUNLOCKFILE(fp); + return (ret); +} diff --git a/src/lib/libc/stdio/fflush.c b/src/lib/libc/stdio/fflush.c new file mode 100644 index 0000000..5732410 --- /dev/null +++ b/src/lib/libc/stdio/fflush.c @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fflush.c,v 1.12 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +static int sflush_locked(FILE *); + +/* + * Flush a single file, or (if fp is NULL) all files. + * MT-safe version + */ +int +fflush(FILE *fp) +{ + int retval; + + if (fp == NULL) + return (_fwalk(sflush_locked)); + FLOCKFILE(fp); + if ((fp->_flags & (__SWR | __SRW)) == 0) { + errno = EBADF; + retval = EOF; + } else + retval = __sflush(fp); + FUNLOCKFILE(fp); + return (retval); +} + +/* + * Flush a single file, or (if fp is NULL) all files. + * Non-MT-safe version + */ +int +__fflush(FILE *fp) +{ + int retval; + + if (fp == NULL) + return (_fwalk(sflush_locked)); + if ((fp->_flags & (__SWR | __SRW)) == 0) { + errno = EBADF; + retval = EOF; + } else + retval = __sflush(fp); + return (retval); +} + +int +__sflush(FILE *fp) +{ + unsigned char *p; + int n, t; + + t = fp->_flags; + if ((t & __SWR) == 0) + return (0); + + if ((p = fp->_bf._base) == NULL) + return (0); + + n = fp->_p - p; /* write this much */ + + /* + * Set these immediately to avoid problems with longjmp and to allow + * exchange buffering (via setvbuf) in user write function. + */ + fp->_p = p; + fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size; + + for (; n > 0; n -= t, p += t) { + t = _swrite(fp, (char *)p, n); + if (t <= 0) { + fp->_flags |= __SERR; + return (EOF); + } + } + return (0); +} + +static int +sflush_locked(FILE *fp) +{ + int ret; + + FLOCKFILE(fp); + ret = __sflush(fp); + FUNLOCKFILE(fp); + return (ret); +} diff --git a/src/lib/libc/stdio/fgetc.c b/src/lib/libc/stdio/fgetc.c new file mode 100644 index 0000000..5cd8c7e --- /dev/null +++ b/src/lib/libc/stdio/fgetc.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetc.c,v 1.12 2004/03/19 09:04:56 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +int +fgetc(fp) + FILE *fp; +{ + int retval; + FLOCKFILE(fp); + /* Orientation set by __sgetc() when buffer is empty. */ + /* ORIENT(fp, -1); */ + retval = __sgetc(fp); + FUNLOCKFILE(fp); + return (retval); +} diff --git a/src/lib/libc/stdio/fgetln.c b/src/lib/libc/stdio/fgetln.c new file mode 100644 index 0000000..bad1f9f --- /dev/null +++ b/src/lib/libc/stdio/fgetln.c @@ -0,0 +1,168 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetln.c,v 1.9 2004/03/10 09:28:38 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Expand the line buffer. Return -1 on error. +#ifdef notdef + * The `new size' does not account for a terminating '\0', + * so we add 1 here. +#endif + */ +static int +slbexpand(FILE *fp, size_t newsize) +{ + void *p; + +#ifdef notdef + ++newsize; +#endif + if (fp->_lb._size >= newsize) + return (0); + if ((p = realloc(fp->_lb._base, newsize)) == NULL) + return (-1); + fp->_lb._base = p; + fp->_lb._size = newsize; + return (0); +} + +/* + * Get an input line. The returned pointer often (but not always) + * points into a stdio buffer. Fgetln does not alter the text of + * the returned line (which is thus not a C string because it will + * not necessarily end with '\0'), but does allow callers to modify + * it if they wish. Thus, we set __SMOD in case the caller does. + */ +char * +fgetln(FILE *fp, size_t *lenp) +{ + unsigned char *p; + size_t len; + size_t off; + + FLOCKFILE(fp); + ORIENT(fp, -1); + /* make sure there is input */ + if (fp->_r <= 0 && __srefill(fp)) { + *lenp = 0; + FUNLOCKFILE(fp); + return (NULL); + } + + /* look for a newline in the input */ + if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) { + char *ret; + + /* + * Found one. Flag buffer as modified to keep fseek from + * `optimising' a backward seek, in case the user stomps on + * the text. + */ + p++; /* advance over it */ + ret = (char *)fp->_p; + *lenp = len = p - fp->_p; + fp->_flags |= __SMOD; + fp->_r -= len; + fp->_p = p; + FUNLOCKFILE(fp); + return (ret); + } + + /* + * We have to copy the current buffered data to the line buffer. + * As a bonus, though, we can leave off the __SMOD. + * + * OPTIMISTIC is length that we (optimistically) expect will + * accomodate the `rest' of the string, on each trip through the + * loop below. + */ +#define OPTIMISTIC 80 + + for (len = fp->_r, off = 0;; len += fp->_r) { + size_t diff; + + /* + * Make sure there is room for more bytes. Copy data from + * file buffer to line buffer, refill file and look for + * newline. The loop stops only when we find a newline. + */ + if (slbexpand(fp, len + OPTIMISTIC)) + goto error; + (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, + len - off); + off = len; + if (__srefill(fp)) + break; /* EOF or error: return partial line */ + if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL) + continue; + + /* got it: finish up the line (like code above) */ + p++; + diff = p - fp->_p; + len += diff; + if (slbexpand(fp, len)) + goto error; + (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, + diff); + fp->_r -= diff; + fp->_p = p; + break; + } + *lenp = len; +#ifdef notdef + fp->_lb._base[len] = 0; +#endif + FUNLOCKFILE(fp); + return ((char *)fp->_lb._base); + +error: + *lenp = 0; /* ??? */ + FUNLOCKFILE(fp); + return (NULL); /* ??? */ +} diff --git a/src/lib/libc/stdio/fgetpos.c b/src/lib/libc/stdio/fgetpos.c new file mode 100644 index 0000000..581c5c8 --- /dev/null +++ b/src/lib/libc/stdio/fgetpos.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetpos.c,v 1.12 2002/10/12 16:13:37 mike Exp $"); + +#include + +int +fgetpos(FILE * __restrict fp, fpos_t * __restrict pos) +{ + /* + * ftello is thread-safe; no need to lock fp. + */ + if ((*pos = ftello(fp)) == (fpos_t)-1) + return (-1); + else + return (0); +} diff --git a/src/lib/libc/stdio/fgets.c b/src/lib/libc/stdio/fgets.c new file mode 100644 index 0000000..36ae4fd --- /dev/null +++ b/src/lib/libc/stdio/fgets.c @@ -0,0 +1,116 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fgets.c,v 1.13 2002/08/13 09:30:41 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +/* + * Read at most n-1 characters from the given file. + * Stop when a newline has been read, or the count runs out. + * Return first argument, or NULL if no characters were read. + */ +char * +fgets(buf, n, fp) + char *buf; + int n; + FILE *fp; +{ + size_t len; + char *s; + unsigned char *p, *t; + + if (n <= 0) /* sanity check */ + return (NULL); + + FLOCKFILE(fp); + ORIENT(fp, -1); + s = buf; + n--; /* leave space for NUL */ + while (n != 0) { + /* + * If the buffer is empty, refill it. + */ + if ((len = fp->_r) <= 0) { + if (__srefill(fp)) { + /* EOF/error: stop with partial or no line */ + if (s == buf) { + FUNLOCKFILE(fp); + return (NULL); + } + break; + } + len = fp->_r; + } + p = fp->_p; + + /* + * Scan through at most n bytes of the current buffer, + * looking for '\n'. If found, copy up to and including + * newline, and stop. Otherwise, copy entire chunk + * and loop. + */ + if (len > n) + len = n; + t = memchr((void *)p, '\n', len); + if (t != NULL) { + len = ++t - p; + fp->_r -= len; + fp->_p = t; + (void)memcpy((void *)s, (void *)p, len); + s[len] = 0; + FUNLOCKFILE(fp); + return (buf); + } + fp->_r -= len; + fp->_p += len; + (void)memcpy((void *)s, (void *)p, len); + s += len; + n -= len; + } + *s = 0; + FUNLOCKFILE(fp); + return (buf); +} diff --git a/src/lib/libc/stdio/fgetwc.c b/src/lib/libc/stdio/fgetwc.c new file mode 100644 index 0000000..57d4a95 --- /dev/null +++ b/src/lib/libc/stdio/fgetwc.c @@ -0,0 +1,110 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.8 2004/04/07 09:55:05 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +static __inline wint_t __fgetwc_nbf(FILE *); + +/* + * Non-MT-safe version. + */ +wint_t +__fgetwc(FILE *fp) +{ + wint_t wc; + + if (MB_CUR_MAX == 1) { + /* + * Assume we're using a single-byte locale. A safer test + * might be to check _CurrentRuneLocale->encoding. + */ + wc = (wint_t)__sgetc(fp); + } else + wc = __fgetwc_nbf(fp); + + return (wc); +} + +/* + * MT-safe version. + */ +wint_t +fgetwc(FILE *fp) +{ + wint_t r; + + FLOCKFILE(fp); + ORIENT(fp, 1); + r = __fgetwc(fp); + FUNLOCKFILE(fp); + + return (r); +} + +static __inline wint_t +__fgetwc_nbf(FILE *fp) +{ + static const mbstate_t initial; + mbstate_t mbs; + char buf[MB_LEN_MAX]; + size_t n, nconv; + int c; + wchar_t wc; + + n = 0; + while (n < MB_CUR_MAX) { + if ((c = __sgetc(fp)) == EOF) { + if (n == 0) + return (WEOF); + break; + } + buf[n++] = (char)c; + mbs = initial; + nconv = mbrtowc(&wc, buf, n, &mbs); + if (nconv == n) + return (wc); + else if (nconv == 0) + return (L'\0'); + else if (nconv == (size_t)-1) + break; + } + + while (n-- != 0) + __ungetc((unsigned char)buf[n], fp); + errno = EILSEQ; + fp->_flags |= __SERR; + return (WEOF); +} diff --git a/src/lib/libc/stdio/fgetws.c b/src/lib/libc/stdio/fgetws.c new file mode 100644 index 0000000..d818f62 --- /dev/null +++ b/src/lib/libc/stdio/fgetws.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +wchar_t * +fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp) +{ + wchar_t *wsp; + wint_t wc; + + FLOCKFILE(fp); + ORIENT(fp, 1); + + if (n <= 0) { + errno = EINVAL; + goto error; + } + + wsp = ws; + while (n-- > 1) { + /* XXX Inefficient */ + if ((wc = __fgetwc(fp)) == WEOF && errno == EILSEQ) + goto error; + if (wc == WEOF) { + if (wsp == ws) + /* EOF/error, no characters read yet. */ + goto error; + break; + } + *wsp++ = (wchar_t)wc; + if (wc == L'\n') + break; + } + *wsp++ = L'\0'; + FUNLOCKFILE(fp); + + return (ws); + +error: + FUNLOCKFILE(fp); + return (NULL); +} diff --git a/src/lib/libc/stdio/fileno.c b/src/lib/libc/stdio/fileno.c new file mode 100644 index 0000000..60bac45 --- /dev/null +++ b/src/lib/libc/stdio/fileno.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fileno.c,v 1.10 2004/03/17 01:43:07 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" + +#undef fileno + +int +fileno(FILE *fp) +{ + int fd; + + FLOCKFILE(fp); + fd = __sfileno(fp); + FUNLOCKFILE(fp); + + return (fd); +} diff --git a/src/lib/libc/stdio/findfp.c b/src/lib/libc/stdio/findfp.c new file mode 100644 index 0000000..a90f74a --- /dev/null +++ b/src/lib/libc/stdio/findfp.c @@ -0,0 +1,253 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/findfp.c,v 1.28 2002/11/14 14:06:14 imp Exp $"); + +#include +#include +#include +#include +#include +#include + +#include + +#include "libc_private.h" +#include "local.h" +#include "glue.h" + +int __sdidinit; + +#define NDYNAMIC 10 /* add ten more whenever necessary */ + +#define std(flags, file) \ + {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \ + {0}, __sFX + file} + /* p r w flags file _bf z cookie close read seek write */ + /* _ub _extra */ + /* the usual - (stdin + stdout + stderr) */ +static FILE usual[FOPEN_MAX - 3]; +static struct __sFILEX usual_extra[FOPEN_MAX - 3]; +static struct glue uglue = { NULL, FOPEN_MAX - 3, usual }; + +static struct __sFILEX __sFX[3]; + +/* + * We can't make this 'static' until 6.0-current due to binary + * compatibility concerns. This also means we cannot change the + * sizeof(FILE) until that time either and must continue to use the + * __sFILEX stuff to add to FILE. + */ +FILE __sF[3] = { + std(__SRD, STDIN_FILENO), + std(__SWR, STDOUT_FILENO), + std(__SWR|__SNBF, STDERR_FILENO) +}; + +/* + * The following kludge is done to ensure enough binary compatibility + * with future versions of libc. Or rather it allows us to work with + * libraries that have been built with a newer libc that defines these + * symbols and expects libc to provide them. We only have need to support + * i386 and alpha because they are the only "old" systems we have deployed. + */ +FILE *__stdinp = &__sF[0]; +FILE *__stdoutp = &__sF[1]; +FILE *__stderrp = &__sF[2]; + +struct glue __sglue = { &uglue, 3, __sF }; +static struct glue *lastglue = &uglue; + +static struct glue * moreglue(int); + +static spinlock_t thread_lock = _SPINLOCK_INITIALIZER; +#define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock) +#define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock) + +#if NOT_YET +#define SET_GLUE_PTR(ptr, val) atomic_set_rel_ptr(&(ptr), (uintptr_t)(val)) +#else +#define SET_GLUE_PTR(ptr, val) ptr = val +#endif + +static struct glue * +moreglue(n) + int n; +{ + struct glue *g; + static FILE empty; + static struct __sFILEX emptyx; + FILE *p; + struct __sFILEX *fx; + + g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) + + n * sizeof(struct __sFILEX)); + if (g == NULL) + return (NULL); + p = (FILE *)ALIGN(g + 1); + fx = (struct __sFILEX *)&p[n]; + g->next = NULL; + g->niobs = n; + g->iobs = p; + while (--n >= 0) { + *p = empty; + p->_extra = fx; + *p->_extra = emptyx; + p++, fx++; + } + return (g); +} + +/* + * Find a free FILE for fopen et al. + */ +FILE * +__sfp() +{ + FILE *fp; + int n; + struct glue *g; + + if (!__sdidinit) + __sinit(); + /* + * The list must be locked because a FILE may be updated. + */ + THREAD_LOCK(); + for (g = &__sglue; g != NULL; g = g->next) { + for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) + if (fp->_flags == 0) + goto found; + } + THREAD_UNLOCK(); /* don't hold lock while malloc()ing. */ + if ((g = moreglue(NDYNAMIC)) == NULL) + return (NULL); + THREAD_LOCK(); /* reacquire the lock */ + SET_GLUE_PTR(lastglue->next, g); /* atomically append glue to list */ + lastglue = g; /* not atomic; only accessed when locked */ + fp = g->iobs; +found: + fp->_flags = 1; /* reserve this slot; caller sets real flags */ + THREAD_UNLOCK(); + fp->_p = NULL; /* no current pointer */ + fp->_w = 0; /* nothing to read or write */ + fp->_r = 0; + fp->_bf._base = NULL; /* no buffer */ + fp->_bf._size = 0; + fp->_lbfsize = 0; /* not line buffered */ + fp->_file = -1; /* no file */ +/* fp->_cookie = ; */ /* caller sets cookie, _read/_write etc */ + fp->_ub._base = NULL; /* no ungetc buffer */ + fp->_ub._size = 0; + fp->_lb._base = NULL; /* no line buffer */ + fp->_lb._size = 0; +/* fp->_lock = NULL; */ /* once set always set (reused) */ + fp->_extra->orientation = 0; +#ifdef notdef + /* Stateful encoding/decoding is not yet supported. */ + memset(&fp->_extra->wstate, 0, sizeof(mbstate_t)); + memset(&fp->_extra->rstate, 0, sizeof(mbstate_t)); +#endif + return (fp); +} + +/* + * XXX. Force immediate allocation of internal memory. Not used by stdio, + * but documented historically for certain applications. Bad applications. + */ +__warn_references(f_prealloc, + "warning: this program uses f_prealloc(), which is not recommended."); + +void +f_prealloc() +{ + struct glue *g; + int n; + + n = getdtablesize() - FOPEN_MAX + 20; /* 20 for slop. */ + /* + * It should be safe to walk the list without locking it; + * new nodes are only added to the end and none are ever + * removed. + */ + for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next) + /* void */; + if ((n > 0) && ((g = moreglue(n)) != NULL)) { + THREAD_LOCK(); + SET_GLUE_PTR(lastglue->next, g); + lastglue = g; + THREAD_UNLOCK(); + } +} + +/* + * exit() calls _cleanup() through *__cleanup, set whenever we + * open or buffer a file. This chicanery is done so that programs + * that do not use stdio need not link it all in. + * + * The name `_cleanup' is, alas, fairly well known outside stdio. + */ +void +_cleanup() +{ + /* (void) _fwalk(fclose); */ + (void) _fwalk(__sflush); /* `cheating' */ +} + +/* + * __sinit() is called whenever stdio's internal variables must be set up. + */ +void +__sinit() +{ + int i; + + THREAD_LOCK(); + if (__sdidinit == 0) { + /* Set _extra for the usual suspects. */ + for (i = 0; i < FOPEN_MAX - 3; i++) + usual[i]._extra = &usual_extra[i]; + + /* Make sure we clean up on exit. */ + __cleanup = _cleanup; /* conservative */ + __sdidinit = 1; + } + THREAD_UNLOCK(); +} diff --git a/src/lib/libc/stdio/flags.c b/src/lib/libc/stdio/flags.c new file mode 100644 index 0000000..cd90f83 --- /dev/null +++ b/src/lib/libc/stdio/flags.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/flags.c,v 1.9 2002/03/22 21:53:04 obrien Exp $"); + +#include +#include +#include +#include + +#include "local.h" + +/* + * Return the (stdio) flags for a given mode. Store the flags + * to be passed to an _open() syscall through *optr. + * Return 0 on error. + */ +int +__sflags(mode, optr) + const char *mode; + int *optr; +{ + int ret, m, o; + + switch (*mode++) { + + case 'r': /* open for reading */ + ret = __SRD; + m = O_RDONLY; + o = 0; + break; + + case 'w': /* open for writing */ + ret = __SWR; + m = O_WRONLY; + o = O_CREAT | O_TRUNC; + break; + + case 'a': /* open for appending */ + ret = __SWR; + m = O_WRONLY; + o = O_CREAT | O_APPEND; + break; + + default: /* illegal mode */ + errno = EINVAL; + return (0); + } + + /* [rwa]\+ or [rwa]b\+ means read and write */ + if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) { + ret = __SRW; + m = O_RDWR; + } + *optr = m | o; + return (ret); +} diff --git a/src/lib/libc/stdio/floatio.h b/src/lib/libc/stdio/floatio.h new file mode 100644 index 0000000..83beec7 --- /dev/null +++ b/src/lib/libc/stdio/floatio.h @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)floatio.h 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/lib/libc/stdio/floatio.h,v 1.5 2004/01/18 08:28:47 das Exp $ + */ + +/* + * Floating point scanf/printf (input/output) definitions. + */ + +/* + * MAXEXPDIG is the maximum number of decimal digits needed to store a + * floating point exponent in the largest supported format. It should + * be ceil(log10(LDBL_MAX_10_EXP)) or, if hexadecimal floating point + * conversions are supported, ceil(log10(LDBL_MAX_EXP)). But since it + * is presently never greater than 5 in practice, we fudge it. + */ +#define MAXEXPDIG 6 +#if LDBL_MAX_EXP > 999999 +#error "floating point buffers too small" +#endif + +char *__hdtoa(double, const char *, int, int *, int *, char **); +char *__hldtoa(long double, const char *, int, int *, int *, char **); +char *__ldtoa(long double *, int, int, int *, int *, char **); diff --git a/src/lib/libc/stdio/fopen.c b/src/lib/libc/stdio/fopen.c new file mode 100644 index 0000000..5a043ca --- /dev/null +++ b/src/lib/libc/stdio/fopen.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fopen.c,v 1.10 2002/10/12 16:13:37 mike Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "local.h" + +FILE * +fopen(file, mode) + const char * __restrict file; + const char * __restrict mode; +{ + FILE *fp; + int f; + int flags, oflags; + + if ((flags = __sflags(mode, &oflags)) == 0) + return (NULL); + if ((fp = __sfp()) == NULL) + return (NULL); + if ((f = _open(file, oflags, DEFFILEMODE)) < 0) { + fp->_flags = 0; /* release */ + return (NULL); + } + fp->_file = f; + fp->_flags = flags; + fp->_cookie = fp; + fp->_read = __sread; + fp->_write = __swrite; + fp->_seek = __sseek; + fp->_close = __sclose; + /* + * When opening in append mode, even though we use O_APPEND, + * we need to seek to the end so that ftell() gets the right + * answer. If the user then alters the seek pointer, or + * the file extends, this will fail, but there is not much + * we can do about this. (We could set __SAPP and check in + * fseek and ftell.) + */ + if (oflags & O_APPEND) + (void)_sseek(fp, (fpos_t)0, SEEK_END); + return (fp); +} diff --git a/src/lib/libc/stdio/fprintf.c b/src/lib/libc/stdio/fprintf.c new file mode 100644 index 0000000..35093b0 --- /dev/null +++ b/src/lib/libc/stdio/fprintf.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fprintf.c,v 1.10 2002/09/06 11:23:55 tjr Exp $"); + +#include +#include + +int +fprintf(FILE * __restrict fp, const char * __restrict fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vfprintf(fp, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/src/lib/libc/stdio/fpurge.c b/src/lib/libc/stdio/fpurge.c new file mode 100644 index 0000000..f191843 --- /dev/null +++ b/src/lib/libc/stdio/fpurge.c @@ -0,0 +1,74 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fpurge.c,v 1.10 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +/* + * fpurge: like fflush, but without writing anything: leave the + * given FILE's buffer empty. + */ +int +fpurge(fp) + FILE *fp; +{ + int retval; + FLOCKFILE(fp); + if (!fp->_flags) { + errno = EBADF; + retval = EOF; + } else { + if (HASUB(fp)) + FREEUB(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; + retval = 0; + } + FUNLOCKFILE(fp); + return (retval); +} diff --git a/src/lib/libc/stdio/fputc.c b/src/lib/libc/stdio/fputc.c new file mode 100644 index 0000000..a10af2b --- /dev/null +++ b/src/lib/libc/stdio/fputc.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fputc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +int +fputc(c, fp) + int c; + FILE *fp; +{ + int retval; + FLOCKFILE(fp); + /* Orientation set by __sputc() when buffer is full. */ + /* ORIENT(fp, -1); */ + retval = __sputc(c, fp); + FUNLOCKFILE(fp); + return (retval); +} diff --git a/src/lib/libc/stdio/fputs.c b/src/lib/libc/stdio/fputs.c new file mode 100644 index 0000000..58278ab --- /dev/null +++ b/src/lib/libc/stdio/fputs.c @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fputs.c,v 1.11 2002/10/12 16:13:37 mike Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "fvwrite.h" +#include "libc_private.h" +#include "local.h" + +/* + * Write the given string to the given file. + */ +int +fputs(s, fp) + const char * __restrict s; + FILE * __restrict fp; +{ + int retval; + struct __suio uio; + struct __siov iov; + + iov.iov_base = (void *)s; + iov.iov_len = uio.uio_resid = strlen(s); + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + FLOCKFILE(fp); + ORIENT(fp, -1); + retval = __sfvwrite(fp, &uio); + FUNLOCKFILE(fp); + return (retval); +} diff --git a/src/lib/libc/stdio/fputwc.c b/src/lib/libc/stdio/fputwc.c new file mode 100644 index 0000000..d95840e --- /dev/null +++ b/src/lib/libc/stdio/fputwc.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.8 2004/04/07 09:55:05 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Non-MT-safe version. + */ +wint_t +__fputwc(wchar_t wc, FILE *fp) +{ + static const mbstate_t initial; + mbstate_t mbs; + char buf[MB_LEN_MAX]; + size_t i, len; + + if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) { + /* + * Assume single-byte locale with no special encoding. + * A more careful test would be to check + * _CurrentRuneLocale->encoding. + */ + *buf = (unsigned char)wc; + len = 1; + } else { + mbs = initial; + if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { + fp->_flags |= __SERR; + return (WEOF); + } + } + + for (i = 0; i < len; i++) + if (__sputc((unsigned char)buf[i], fp) == EOF) + return (WEOF); + + return ((wint_t)wc); +} + +/* + * MT-safe version. + */ +wint_t +fputwc(wchar_t wc, FILE *fp) +{ + wint_t r; + + FLOCKFILE(fp); + ORIENT(fp, 1); + r = __fputwc(wc, fp); + FUNLOCKFILE(fp); + + return (r); +} diff --git a/src/lib/libc/stdio/fputws.c b/src/lib/libc/stdio/fputws.c new file mode 100644 index 0000000..b1eb8ed --- /dev/null +++ b/src/lib/libc/stdio/fputws.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +int +fputws(const wchar_t * __restrict ws, FILE * __restrict fp) +{ + + FLOCKFILE(fp); + ORIENT(fp, 1); + /* XXX Inefficient */ + while (*ws != '\0') + if (__fputwc(*ws++, fp) == WEOF) { + FUNLOCKFILE(fp); + return (-1); + } + FUNLOCKFILE(fp); + + return (0); +} diff --git a/src/lib/libc/stdio/fread.c b/src/lib/libc/stdio/fread.c new file mode 100644 index 0000000..ad5d81b --- /dev/null +++ b/src/lib/libc/stdio/fread.c @@ -0,0 +1,91 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fread.c,v 1.12 2002/10/12 16:13:37 mike Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +size_t +fread(buf, size, count, fp) + void * __restrict buf; + size_t size, count; + FILE * __restrict fp; +{ + size_t resid; + char *p; + int r; + size_t total; + + /* + * The ANSI standard requires a return value of 0 for a count + * or a size of 0. Peculiarily, it imposes no such requirements + * on fwrite; it only requires fread to be broken. + */ + if ((resid = count * size) == 0) + return (0); + FLOCKFILE(fp); + ORIENT(fp, -1); + if (fp->_r < 0) + fp->_r = 0; + total = resid; + p = buf; + while (resid > (r = fp->_r)) { + (void)memcpy((void *)p, (void *)fp->_p, (size_t)r); + fp->_p += r; + /* fp->_r = 0 ... done in __srefill */ + p += r; + resid -= r; + if (__srefill(fp)) { + /* no more input: return partial result */ + FUNLOCKFILE(fp); + return ((total - resid) / size); + } + } + (void)memcpy((void *)p, (void *)fp->_p, resid); + fp->_r -= resid; + fp->_p += resid; + FUNLOCKFILE(fp); + return (count); +} diff --git a/src/lib/libc/stdio/freopen.c b/src/lib/libc/stdio/freopen.c new file mode 100644 index 0000000..4412ef8 --- /dev/null +++ b/src/lib/libc/stdio/freopen.c @@ -0,0 +1,220 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/freopen.c,v 1.12 2003/01/26 11:45:54 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Re-direct an existing, open (probably) file to some other file. + * ANSI is written such that the original file gets closed if at + * all possible, no matter what. + */ +FILE * +freopen(file, mode, fp) + const char * __restrict file; + const char * __restrict mode; + FILE *fp; +{ + int f; + int dflags, flags, isopen, oflags, sverrno, wantfd; + + if ((flags = __sflags(mode, &oflags)) == 0) { + (void) fclose(fp); + return (NULL); + } + + FLOCKFILE(fp); + + if (!__sdidinit) + __sinit(); + + /* + * If the filename is a NULL pointer, the caller is asking us to + * re-open the same file with a different mode. We allow this only + * if the modes are compatible. + */ + if (file == NULL) { + /* See comment below regarding freopen() of closed files. */ + if (fp->_flags == 0) { + FUNLOCKFILE(fp); + errno = EINVAL; + return (NULL); + } + if ((dflags = _fcntl(fp->_file, F_GETFL)) < 0) { + sverrno = errno; + fclose(fp); + FUNLOCKFILE(fp); + errno = sverrno; + return (NULL); + } + if ((dflags & O_ACCMODE) != O_RDWR && (dflags & O_ACCMODE) != + (oflags & O_ACCMODE)) { + fclose(fp); + FUNLOCKFILE(fp); + errno = EINVAL; + return (NULL); + } + if ((oflags ^ dflags) & O_APPEND) { + dflags &= ~O_APPEND; + dflags |= oflags & O_APPEND; + if (_fcntl(fp->_file, F_SETFL, dflags) < 0) { + sverrno = errno; + fclose(fp); + FUNLOCKFILE(fp); + errno = sverrno; + return (NULL); + } + } + if (oflags & O_TRUNC) + ftruncate(fp->_file, 0); + if (_fseeko(fp, 0, oflags & O_APPEND ? SEEK_END : SEEK_SET, + 0) < 0 && errno != ESPIPE) { + sverrno = errno; + fclose(fp); + FUNLOCKFILE(fp); + errno = sverrno; + return (NULL); + } + f = fp->_file; + isopen = 0; + wantfd = -1; + goto finish; + } + + /* + * There are actually programs that depend on being able to "freopen" + * descriptors that weren't originally open. Keep this from breaking. + * Remember whether the stream was open to begin with, and which file + * descriptor (if any) was associated with it. If it was attached to + * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin) + * should work. This is unnecessary if it was not a Unix file. + */ + if (fp->_flags == 0) { + fp->_flags = __SEOF; /* hold on to it */ + isopen = 0; + wantfd = -1; + } else { + /* flush the stream; ANSI doesn't require this. */ + if (fp->_flags & __SWR) + (void) __sflush(fp); + /* if close is NULL, closing is a no-op, hence pointless */ + isopen = fp->_close != NULL; + if ((wantfd = fp->_file) < 0 && isopen) { + (void) (*fp->_close)(fp->_cookie); + isopen = 0; + } + } + + /* Get a new descriptor to refer to the new file. */ + f = _open(file, oflags, DEFFILEMODE); + if (f < 0 && isopen) { + /* If out of fd's close the old one and try again. */ + if (errno == ENFILE || errno == EMFILE) { + (void) (*fp->_close)(fp->_cookie); + isopen = 0; + f = _open(file, oflags, DEFFILEMODE); + } + } + sverrno = errno; + +finish: + /* + * Finish closing fp. Even if the open succeeded above, we cannot + * keep fp->_base: it may be the wrong size. This loses the effect + * of any setbuffer calls, but stdio has always done this before. + */ + if (isopen) + (void) (*fp->_close)(fp->_cookie); + if (fp->_flags & __SMBF) + free((char *)fp->_bf._base); + fp->_w = 0; + fp->_r = 0; + fp->_p = NULL; + fp->_bf._base = NULL; + fp->_bf._size = 0; + fp->_lbfsize = 0; + if (HASUB(fp)) + FREEUB(fp); + fp->_ub._size = 0; + if (HASLB(fp)) + FREELB(fp); + fp->_lb._size = 0; + fp->_extra->orientation = 0; + + if (f < 0) { /* did not get it after all */ + fp->_flags = 0; /* set it free */ + errno = sverrno; /* restore in case _close clobbered */ + FUNLOCKFILE(fp); + return (NULL); + } + + /* + * If reopening something that was open before on a real file, try + * to maintain the descriptor. Various C library routines (perror) + * assume stderr is always fd STDERR_FILENO, even if being freopen'd. + */ + if (wantfd >= 0 && f != wantfd) { + if (_dup2(f, wantfd) >= 0) { + (void)_close(f); + f = wantfd; + } + } + + fp->_flags = flags; + fp->_file = f; + fp->_cookie = fp; + fp->_read = __sread; + fp->_write = __swrite; + fp->_seek = __sseek; + fp->_close = __sclose; + FUNLOCKFILE(fp); + return (fp); +} diff --git a/src/lib/libc/stdio/fscanf.c b/src/lib/libc/stdio/fscanf.c new file mode 100644 index 0000000..aaad500 --- /dev/null +++ b/src/lib/libc/stdio/fscanf.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fscanf.c,v 1.12 2003/01/03 23:27:27 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +int +fscanf(FILE * __restrict fp, char const * __restrict fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + FLOCKFILE(fp); + ret = __svfscanf(fp, fmt, ap); + va_end(ap); + FUNLOCKFILE(fp); + return (ret); +} diff --git a/src/lib/libc/stdio/fseek.c b/src/lib/libc/stdio/fseek.c new file mode 100644 index 0000000..3ff409b --- /dev/null +++ b/src/lib/libc/stdio/fseek.c @@ -0,0 +1,312 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.40 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +#define POS_ERR (-(fpos_t)1) + +int +fseek(fp, offset, whence) + FILE *fp; + long offset; + int whence; +{ + int ret; + int serrno = errno; + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + FLOCKFILE(fp); + ret = _fseeko(fp, (off_t)offset, whence, 1); + FUNLOCKFILE(fp); + if (ret == 0) + errno = serrno; + return (ret); +} + +int +fseeko(fp, offset, whence) + FILE *fp; + off_t offset; + int whence; +{ + int ret; + int serrno = errno; + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + FLOCKFILE(fp); + ret = _fseeko(fp, offset, whence, 0); + FUNLOCKFILE(fp); + if (ret == 0) + errno = serrno; + return (ret); +} + +/* + * Seek the given file to the given offset. + * `Whence' must be one of the three SEEK_* macros. + */ +int +_fseeko(fp, offset, whence, ltest) + FILE *fp; + off_t offset; + int whence; + int ltest; +{ + fpos_t (*seekfn)(void *, fpos_t, int); + fpos_t target, curoff, ret; + size_t n; + struct stat st; + int havepos; + + /* + * Have to be able to seek. + */ + if ((seekfn = fp->_seek) == NULL) { + errno = ESPIPE; /* historic practice */ + return (-1); + } + + /* + * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. + * After this, whence is either SEEK_SET or SEEK_END. + */ + switch (whence) { + + case SEEK_CUR: + /* + * In order to seek relative to the current stream offset, + * we have to first find the current stream offset via + * ftell (see ftell for details). + */ + if (_ftello(fp, &curoff)) + return (-1); + if (curoff < 0) { + /* Unspecified position because of ungetc() at 0 */ + errno = ESPIPE; + return (-1); + } + if (offset > 0 && curoff > OFF_MAX - offset) { + errno = EOVERFLOW; + return (-1); + } + offset += curoff; + if (offset < 0) { + errno = EINVAL; + return (-1); + } + if (ltest && offset > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + whence = SEEK_SET; + havepos = 1; + break; + + case SEEK_SET: + if (offset < 0) { + errno = EINVAL; + return (-1); + } + case SEEK_END: + curoff = 0; /* XXX just to keep gcc quiet */ + havepos = 0; + break; + + default: + errno = EINVAL; + return (-1); + } + + /* + * Can only optimise if: + * reading (and not reading-and-writing); + * not unbuffered; and + * this is a `regular' Unix file (and hence seekfn==__sseek). + * We must check __NBF first, because it is possible to have __NBF + * and __SOPT both set. + */ + if (fp->_bf._base == NULL) + __smakebuf(fp); + if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) + goto dumb; + if ((fp->_flags & __SOPT) == 0) { + if (seekfn != __sseek || + fp->_file < 0 || _fstat(fp->_file, &st) || + (st.st_mode & S_IFMT) != S_IFREG) { + fp->_flags |= __SNPT; + goto dumb; + } + fp->_blksize = st.st_blksize; + fp->_flags |= __SOPT; + } + + /* + * We are reading; we can try to optimise. + * Figure out where we are going and where we are now. + */ + if (whence == SEEK_SET) + target = offset; + else { + if (_fstat(fp->_file, &st)) + goto dumb; + if (offset > 0 && st.st_size > OFF_MAX - offset) { + errno = EOVERFLOW; + return (-1); + } + target = st.st_size + offset; + if ((off_t)target < 0) { + errno = EINVAL; + return (-1); + } + if (ltest && (off_t)target > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + } + + if (!havepos && _ftello(fp, &curoff)) + goto dumb; + + /* + * (If the buffer was modified, we have to + * skip this; see fgetln.c.) + */ + if (fp->_flags & __SMOD) + goto abspos; + + /* + * Compute the number of bytes in the input buffer (pretending + * that any ungetc() input has been discarded). Adjust current + * offset backwards by this count so that it represents the + * file offset for the first byte in the current input buffer. + */ + if (HASUB(fp)) { + curoff += fp->_r; /* kill off ungetc */ + n = fp->_extra->_up - fp->_bf._base; + curoff -= n; + n += fp->_ur; + } else { + n = fp->_p - fp->_bf._base; + curoff -= n; + n += fp->_r; + } + + /* + * If the target offset is within the current buffer, + * simply adjust the pointers, clear EOF, undo ungetc(), + * and return. + */ + if (target >= curoff && target < curoff + n) { + size_t o = target - curoff; + + fp->_p = fp->_bf._base + o; + fp->_r = n - o; + if (HASUB(fp)) + FREEUB(fp); + fp->_flags &= ~__SEOF; + return (0); + } + +abspos: + /* + * The place we want to get to is not within the current buffer, + * but we can still be kind to the kernel copyout mechanism. + * By aligning the file offset to a block boundary, we can let + * the kernel use the VM hardware to map pages instead of + * copying bytes laboriously. Using a block boundary also + * ensures that we only read one block, rather than two. + */ + curoff = target & ~(fp->_blksize - 1); + if (_sseek(fp, curoff, SEEK_SET) == POS_ERR) + goto dumb; + fp->_r = 0; + fp->_p = fp->_bf._base; + if (HASUB(fp)) + FREEUB(fp); + n = target - curoff; + if (n) { + if (__srefill(fp) || fp->_r < n) + goto dumb; + fp->_p += n; + fp->_r -= n; + } + fp->_flags &= ~__SEOF; + return (0); + + /* + * We get here if we cannot optimise the seek ... just + * do it. Allow the seek function to change fp->_bf._base. + */ +dumb: + if (__sflush(fp) || + (ret = _sseek(fp, (fpos_t)offset, whence)) == POS_ERR) + return (-1); + /* success: clear EOF indicator and discard ungetc() data */ + if (HASUB(fp)) + FREEUB(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + /* fp->_w = 0; */ /* unnecessary (I think...) */ + fp->_flags &= ~__SEOF; + if (ltest && ret > LONG_MAX) { + fp->_flags |= __SERR; + errno = EOVERFLOW; + return (-1); + } + return (0); +} diff --git a/src/lib/libc/stdio/fsetpos.c b/src/lib/libc/stdio/fsetpos.c new file mode 100644 index 0000000..6d75acd --- /dev/null +++ b/src/lib/libc/stdio/fsetpos.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fsetpos.c,v 1.8 2002/03/22 21:53:04 obrien Exp $"); + +#include +#include + +/* + * fsetpos: like fseek. + */ +int +fsetpos(iop, pos) + FILE *iop; + const fpos_t *pos; +{ + return (fseeko(iop, (off_t)*pos, SEEK_SET)); +} diff --git a/src/lib/libc/stdio/ftell.c b/src/lib/libc/stdio/ftell.c new file mode 100644 index 0000000..477e3a1 --- /dev/null +++ b/src/lib/libc/stdio/ftell.c @@ -0,0 +1,143 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/ftell.c,v 1.26 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +/* + * standard ftell function. + */ +long +ftell(fp) + FILE *fp; +{ + off_t rv; + + rv = ftello(fp); + if (rv > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + return (rv); +} + +/* + * ftello: return current offset. + */ +off_t +ftello(fp) + FILE *fp; +{ + fpos_t rv; + int ret; + + FLOCKFILE(fp); + ret = _ftello(fp, &rv); + FUNLOCKFILE(fp); + if (ret) + return (-1); + if (rv < 0) { /* Unspecified value because of ungetc() at 0 */ + errno = ESPIPE; + return (-1); + } + return (rv); +} + +int +_ftello(fp, offset) + FILE *fp; + fpos_t *offset; +{ + fpos_t pos; + size_t n; + + if (fp->_seek == NULL) { + errno = ESPIPE; /* historic practice */ + return (1); + } + + /* + * Find offset of underlying I/O object, then + * adjust for buffered bytes. + */ + if (fp->_flags & __SOFF) + pos = fp->_offset; + else { + pos = _sseek(fp, (fpos_t)0, SEEK_CUR); + if (pos == -1) + return (1); + } + if (fp->_flags & __SRD) { + /* + * Reading. Any unread characters (including + * those from ungetc) cause the position to be + * smaller than that in the underlying object. + */ + if ((pos -= (HASUB(fp) ? fp->_ur : fp->_r)) < 0) { + fp->_flags |= __SERR; + errno = EIO; + return (1); + } + if (HASUB(fp)) + pos -= fp->_r; /* Can be negative at this point. */ + } else if ((fp->_flags & __SWR) && fp->_p != NULL) { + /* + * Writing. Any buffered characters cause the + * position to be greater than that in the + * underlying object. + */ + n = fp->_p - fp->_bf._base; + if (pos > OFF_MAX - n) { + errno = EOVERFLOW; + return (1); + } + pos += n; + } + *offset = pos; + return (0); +} diff --git a/src/lib/libc/stdio/funopen.c b/src/lib/libc/stdio/funopen.c new file mode 100644 index 0000000..040c806 --- /dev/null +++ b/src/lib/libc/stdio/funopen.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/funopen.c,v 1.5 2002/05/28 16:59:39 alfred Exp $"); + +#include +#include + +#include "local.h" + +FILE * +funopen(cookie, readfn, writefn, seekfn, closefn) + const void *cookie; + int (*readfn)(), (*writefn)(); + fpos_t (*seekfn)(void *cookie, fpos_t off, int whence); + int (*closefn)(); +{ + FILE *fp; + int flags; + + if (readfn == NULL) { + if (writefn == NULL) { /* illegal */ + errno = EINVAL; + return (NULL); + } else + flags = __SWR; /* write only */ + } else { + if (writefn == NULL) + flags = __SRD; /* read only */ + else + flags = __SRW; /* read-write */ + } + if ((fp = __sfp()) == NULL) + return (NULL); + fp->_flags = flags; + fp->_file = -1; + fp->_cookie = (void *)cookie; + fp->_read = readfn; + fp->_write = writefn; + fp->_seek = seekfn; + fp->_close = closefn; + return (fp); +} diff --git a/src/lib/libc/stdio/fvwrite.c b/src/lib/libc/stdio/fvwrite.c new file mode 100644 index 0000000..9d05933 --- /dev/null +++ b/src/lib/libc/stdio/fvwrite.c @@ -0,0 +1,214 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fvwrite.c,v 1.16 2004/03/02 19:43:51 jkh Exp $"); + +#include +#include +#include +#include +#include "local.h" +#include "fvwrite.h" + +/* + * Write some memory regions. Return zero on success, EOF on error. + * + * This routine is large and unsightly, but most of the ugliness due + * to the three different kinds of output buffering is handled here. + */ +int +__sfvwrite(fp, uio) + FILE *fp; + struct __suio *uio; +{ + size_t len; + char *p; + struct __siov *iov; + int w, s; + char *nl; + int nlknown, nldist; + + if ((len = uio->uio_resid) == 0) + return (0); + /* make sure we can write */ + if (cantwrite(fp)) { + errno = EBADF; + return (EOF); + } + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n)) + + iov = uio->uio_iov; + p = iov->iov_base; + len = iov->iov_len; + iov++; +#define GETIOV(extra_work) \ + while (len == 0) { \ + extra_work; \ + p = iov->iov_base; \ + len = iov->iov_len; \ + iov++; \ + } + if (fp->_flags & __SNBF) { + /* + * Unbuffered: write up to BUFSIZ bytes at a time. + */ + do { + GETIOV(;); + w = _swrite(fp, p, MIN(len, BUFSIZ)); + if (w <= 0) + goto err; + p += w; + len -= w; + } while ((uio->uio_resid -= w) != 0); + } else if ((fp->_flags & __SLBF) == 0) { + /* + * Fully buffered: fill partially full buffer, if any, + * and then flush. If there is no partial buffer, write + * one _bf._size byte chunk directly (without copying). + * + * String output is a special case: write as many bytes + * as fit, but pretend we wrote everything. This makes + * snprintf() return the number of bytes needed, rather + * than the number used, and avoids its write function + * (so that the write function can be invalid). + */ + do { + GETIOV(;); + if ((fp->_flags & (__SALC | __SSTR)) == + (__SALC | __SSTR) && fp->_w < len) { + size_t blen = fp->_p - fp->_bf._base; + + /* + * Alloc an extra 128 bytes (+ 1 for NULL) + * so we don't call realloc(3) so often. + */ + fp->_w = len + 128; + fp->_bf._size = blen + len + 128; + fp->_bf._base = + reallocf(fp->_bf._base, fp->_bf._size + 1); + if (fp->_bf._base == NULL) + goto err; + fp->_p = fp->_bf._base + blen; + } + w = fp->_w; + if (fp->_flags & __SSTR) { + if (len < w) + w = len; + if (w > 0) { + COPY(w); /* copy MIN(fp->_w,len), */ + fp->_w -= w; + fp->_p += w; + } + w = len; /* but pretend copied all */ + } else if (fp->_p > fp->_bf._base && len > w) { + /* fill and flush */ + COPY(w); + /* fp->_w -= w; */ /* unneeded */ + fp->_p += w; + if (__fflush(fp)) + goto err; + } else if (len >= (w = fp->_bf._size)) { + /* write directly */ + w = _swrite(fp, p, w); + if (w <= 0) + goto err; + } else { + /* fill and done */ + w = len; + COPY(w); + fp->_w -= w; + fp->_p += w; + } + p += w; + len -= w; + } while ((uio->uio_resid -= w) != 0); + } else { + /* + * Line buffered: like fully buffered, but we + * must check for newlines. Compute the distance + * to the first newline (including the newline), + * or `infinity' if there is none, then pretend + * that the amount to write is MIN(len,nldist). + */ + nlknown = 0; + nldist = 0; /* XXX just to keep gcc happy */ + do { + GETIOV(nlknown = 0); + if (!nlknown) { + nl = memchr((void *)p, '\n', len); + nldist = nl ? nl + 1 - p : len + 1; + nlknown = 1; + } + s = MIN(len, nldist); + w = fp->_w + fp->_bf._size; + if (fp->_p > fp->_bf._base && s > w) { + COPY(w); + /* fp->_w -= w; */ + fp->_p += w; + if (__fflush(fp)) + goto err; + } else if (s >= (w = fp->_bf._size)) { + w = _swrite(fp, p, w); + if (w <= 0) + goto err; + } else { + w = s; + COPY(w); + fp->_w -= w; + fp->_p += w; + } + if ((nldist -= w) == 0) { + /* copied the newline: flush and forget */ + if (__fflush(fp)) + goto err; + nlknown = 0; + } + p += w; + len -= w; + } while ((uio->uio_resid -= w) != 0); + } + return (0); + +err: + fp->_flags |= __SERR; + return (EOF); +} diff --git a/src/lib/libc/stdio/fvwrite.h b/src/lib/libc/stdio/fvwrite.h new file mode 100644 index 0000000..5414ec8 --- /dev/null +++ b/src/lib/libc/stdio/fvwrite.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)fvwrite.h 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/lib/libc/stdio/fvwrite.h,v 1.3 2002/05/28 16:59:39 alfred Exp $ + */ + +/* + * I/O descriptors for __sfvwrite(). + */ +struct __siov { + void *iov_base; + size_t iov_len; +}; +struct __suio { + struct __siov *uio_iov; + int uio_iovcnt; + int uio_resid; +}; + +extern int __sfvwrite(FILE *, struct __suio *); diff --git a/src/lib/libc/stdio/fwalk.c b/src/lib/libc/stdio/fwalk.c new file mode 100644 index 0000000..a8a49fc --- /dev/null +++ b/src/lib/libc/stdio/fwalk.c @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fwalk.c,v 1.9 2002/03/22 21:53:04 obrien Exp $"); + +#include +#include +#include +#include "local.h" +#include "glue.h" + +int +_fwalk(function) + int (*function)(FILE *); +{ + FILE *fp; + int n, ret; + struct glue *g; + + ret = 0; + /* + * It should be safe to walk the list without locking it; + * new nodes are only added to the end and none are ever + * removed. + * + * Avoid locking this list while walking it or else you will + * introduce a potential deadlock in [at least] refill.c. + */ + for (g = &__sglue; g != NULL; g = g->next) + for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) + if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0)) + ret |= (*function)(fp); + return (ret); +} diff --git a/src/lib/libc/stdio/fwide.c b/src/lib/libc/stdio/fwide.c new file mode 100644 index 0000000..1386c48 --- /dev/null +++ b/src/lib/libc/stdio/fwide.c @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fwide.c,v 1.1 2002/08/13 09:30:41 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +int +fwide(FILE *fp, int mode) +{ + int m; + + FLOCKFILE(fp); + /* Only change the orientation if the stream is not oriented yet. */ + if (mode != 0 && fp->_extra->orientation == 0) + fp->_extra->orientation = mode > 0 ? 1 : -1; + m = fp->_extra->orientation; + FUNLOCKFILE(fp); + + return (m); +} diff --git a/src/lib/libc/stdio/fwprintf.c b/src/lib/libc/stdio/fwprintf.c new file mode 100644 index 0000000..dcd6c38 --- /dev/null +++ b/src/lib/libc/stdio/fwprintf.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); + +#include +#include +#include + +int +fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vfwprintf(fp, fmt, ap); + va_end(ap); + + return (ret); +} diff --git a/src/lib/libc/stdio/fwrite.c b/src/lib/libc/stdio/fwrite.c new file mode 100644 index 0000000..27b660e --- /dev/null +++ b/src/lib/libc/stdio/fwrite.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fwrite.c,v 1.11 2002/10/12 16:13:41 mike Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "local.h" +#include "fvwrite.h" +#include "libc_private.h" + +/* + * Write `count' objects (each size `size') from memory to the given file. + * Return the number of whole objects written. + */ +size_t +fwrite(buf, size, count, fp) + const void * __restrict buf; + size_t size, count; + FILE * __restrict fp; +{ + size_t n; + struct __suio uio; + struct __siov iov; + + iov.iov_base = (void *)buf; + uio.uio_resid = iov.iov_len = n = count * size; + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + + FLOCKFILE(fp); + ORIENT(fp, -1); + /* + * The usual case is success (__sfvwrite returns 0); + * skip the divide if this happens, since divides are + * generally slow and since this occurs whenever size==0. + */ + if (__sfvwrite(fp, &uio) != 0) + count = (n - uio.uio_resid) / size; + FUNLOCKFILE(fp); + return (count); +} diff --git a/src/lib/libc/stdio/fwscanf.c b/src/lib/libc/stdio/fwscanf.c new file mode 100644 index 0000000..47e8550 --- /dev/null +++ b/src/lib/libc/stdio/fwscanf.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/fwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); + +#include +#include +#include + +int +fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...) +{ + va_list ap; + int r; + + va_start(ap, fmt); + r = vfwscanf(fp, fmt, ap); + va_end(ap); + + return (r); +} diff --git a/src/lib/libc/stdio/gdtoa.h b/src/lib/libc/stdio/gdtoa.h new file mode 100644 index 0000000..62553f2 --- /dev/null +++ b/src/lib/libc/stdio/gdtoa.h @@ -0,0 +1,159 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + +****************************************************************/ + +/* Please send bug reports to + David M. Gay + Bell Laboratories, Room 2C-463 + 600 Mountain Avenue + Murray Hill, NJ 07974-0636 + U.S.A. + dmg@bell-labs.com + */ + +#ifndef GDTOA_H_INCLUDED +#define GDTOA_H_INCLUDED + +#include "arith.h" + +#ifndef Long +#define Long long +#endif +#ifndef ULong +typedef unsigned Long ULong; +#endif +#ifndef UShort +typedef unsigned short UShort; +#endif + +#ifndef ANSI +#ifdef KR_headers +#define ANSI(x) () +#define Void /*nothing*/ +#else +#define ANSI(x) x +#define Void void +#endif +#endif /* ANSI */ + +#ifndef CONST +#ifdef KR_headers +#define CONST /* blank */ +#else +#define CONST const +#endif +#endif /* CONST */ + + enum { /* return values from strtodg */ + STRTOG_Zero = 0, + STRTOG_Normal = 1, + STRTOG_Denormal = 2, + STRTOG_Infinite = 3, + STRTOG_NaN = 4, + STRTOG_NaNbits = 5, + STRTOG_NoNumber = 6, + STRTOG_Retmask = 7, + + /* The following may be or-ed into one of the above values. */ + + STRTOG_Neg = 0x08, + STRTOG_Inexlo = 0x10, + STRTOG_Inexhi = 0x20, + STRTOG_Inexact = 0x30, + STRTOG_Underflow= 0x40, + STRTOG_Overflow = 0x80 + }; + + typedef struct +FPI { + int nbits; + int emin; + int emax; + int rounding; + int sudden_underflow; + } FPI; + +enum { /* FPI.rounding values: same as FLT_ROUNDS */ + FPI_Round_zero = 0, + FPI_Round_near = 1, + FPI_Round_up = 2, + FPI_Round_down = 3 + }; + +#ifdef __cplusplus +extern "C" { +#endif + +extern char* dtoa ANSI((double d, int mode, int ndigits, int *decpt, + int *sign, char **rve)); +extern char* gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp, + int mode, int ndigits, int *decpt, char **rve)); +extern void freedtoa ANSI((char*)); +extern float strtof ANSI((CONST char *, char **)); +extern double strtod ANSI((CONST char *, char **)); +extern int strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*)); + +extern char* g_ddfmt ANSI((char*, double*, int, unsigned)); +extern char* g_dfmt ANSI((char*, double*, int, unsigned)); +extern char* g_ffmt ANSI((char*, float*, int, unsigned)); +extern char* g_Qfmt ANSI((char*, void*, int, unsigned)); +extern char* g_xfmt ANSI((char*, void*, int, unsigned)); +extern char* g_xLfmt ANSI((char*, void*, int, unsigned)); + +extern int strtoId ANSI((CONST char*, char**, double*, double*)); +extern int strtoIdd ANSI((CONST char*, char**, double*, double*)); +extern int strtoIf ANSI((CONST char*, char**, float*, float*)); +extern int strtoIQ ANSI((CONST char*, char**, void*, void*)); +extern int strtoIx ANSI((CONST char*, char**, void*, void*)); +extern int strtoIxL ANSI((CONST char*, char**, void*, void*)); +extern int strtord ANSI((CONST char*, char**, int, double*)); +extern int strtordd ANSI((CONST char*, char**, int, double*)); +extern int strtorf ANSI((CONST char*, char**, int, float*)); +extern int strtorQ ANSI((CONST char*, char**, int, void*)); +extern int strtorx ANSI((CONST char*, char**, int, void*)); +extern int strtorxL ANSI((CONST char*, char**, int, void*)); +#if 1 +extern int strtodI ANSI((CONST char*, char**, double*)); +extern int strtopd ANSI((CONST char*, char**, double*)); +extern int strtopdd ANSI((CONST char*, char**, double*)); +extern int strtopf ANSI((CONST char*, char**, float*)); +extern int strtopQ ANSI((CONST char*, char**, void*)); +extern int strtopx ANSI((CONST char*, char**, void*)); +extern int strtopxL ANSI((CONST char*, char**, void*)); +#else +#define strtopd(s,se,x) strtord(s,se,1,x) +#define strtopdd(s,se,x) strtordd(s,se,1,x) +#define strtopf(s,se,x) strtorf(s,se,1,x) +#define strtopQ(s,se,x) strtorQ(s,se,1,x) +#define strtopx(s,se,x) strtorx(s,se,1,x) +#define strtopxL(s,se,x) strtorxL(s,se,1,x) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* GDTOA_H_INCLUDED */ diff --git a/src/lib/libc/stdio/getc.c b/src/lib/libc/stdio/getc.c new file mode 100644 index 0000000..0aa9dca --- /dev/null +++ b/src/lib/libc/stdio/getc.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/getc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +#undef getc + +int +getc(FILE *fp) +{ + int retval; + FLOCKFILE(fp); + /* Orientation set by __sgetc() when buffer is empty. */ + /* ORIENT(fp, -1); */ + retval = __sgetc(fp); + FUNLOCKFILE(fp); + return (retval); +} diff --git a/src/lib/libc/stdio/getchar.c b/src/lib/libc/stdio/getchar.c new file mode 100644 index 0000000..2ea530f --- /dev/null +++ b/src/lib/libc/stdio/getchar.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/getchar.c,v 1.12 2004/03/19 09:04:56 tjr Exp $"); + +/* + * A subroutine version of the macro getchar. + */ +#include "namespace.h" +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +#undef getchar + +int +getchar() +{ + int retval; + FLOCKFILE(stdin); + /* Orientation set by __sgetc() when buffer is empty. */ + /* ORIENT(stdin, -1); */ + retval = __sgetc(stdin); + FUNLOCKFILE(stdin); + return (retval); +} diff --git a/src/lib/libc/stdio/gets.c b/src/lib/libc/stdio/gets.c new file mode 100644 index 0000000..5ef23ab --- /dev/null +++ b/src/lib/libc/stdio/gets.c @@ -0,0 +1,81 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/gets.c,v 1.16 2003/01/30 23:32:53 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +__warn_references(gets, "warning: this program uses gets(), which is unsafe."); + +char * +gets(buf) + char *buf; +{ + int c; + char *s; + static int warned; + static char w[] = + "warning: this program uses gets(), which is unsafe.\n"; + + FLOCKFILE(stdin); + ORIENT(stdin, -1); + if (!warned) { + (void) _write(STDERR_FILENO, w, sizeof(w) - 1); + warned = 1; + } + for (s = buf; (c = __sgetc(stdin)) != '\n';) + if (c == EOF) + if (s == buf) { + FUNLOCKFILE(stdin); + return (NULL); + } else + break; + else + *s++ = c; + *s = 0; + FUNLOCKFILE(stdin); + return (buf); +} diff --git a/src/lib/libc/stdio/getw.c b/src/lib/libc/stdio/getw.c new file mode 100644 index 0000000..c7ba04f --- /dev/null +++ b/src/lib/libc/stdio/getw.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)getw.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/getw.c,v 1.7 2002/03/22 21:53:04 obrien Exp $"); + +#include + +int +getw(fp) + FILE *fp; +{ + int x; + + return (fread((void *)&x, sizeof(x), 1, fp) == 1 ? x : EOF); +} diff --git a/src/lib/libc/stdio/getwc.c b/src/lib/libc/stdio/getwc.c new file mode 100644 index 0000000..201b0ab --- /dev/null +++ b/src/lib/libc/stdio/getwc.c @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/getwc.c,v 1.2 2002/09/28 07:43:44 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Synonym for fgetwc(). The only difference is that getwc(), if it is a + * macro, may evaluate `fp' more than once. + */ +wint_t +getwc(FILE *fp) +{ + + return (fgetwc(fp)); +} diff --git a/src/lib/libc/stdio/getwchar.c b/src/lib/libc/stdio/getwchar.c new file mode 100644 index 0000000..b0ae3ba --- /dev/null +++ b/src/lib/libc/stdio/getwchar.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/getwchar.c,v 1.2 2002/09/28 07:43:44 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Synonym for fgetwc(stdin). + */ +wint_t +getwchar(void) +{ + + return (fgetwc(stdin)); +} diff --git a/src/lib/libc/stdio/glue.h b/src/lib/libc/stdio/glue.h new file mode 100644 index 0000000..44223ff --- /dev/null +++ b/src/lib/libc/stdio/glue.h @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)glue.h 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/lib/libc/stdio/glue.h,v 1.2 2002/03/22 23:42:01 obrien Exp $ + */ + +/* + * The first few FILEs are statically allocated; others are dynamically + * allocated and linked in via this glue structure. + */ +struct glue { + struct glue *next; + int niobs; + FILE *iobs; +} __sglue; diff --git a/src/lib/libc/stdio/local.h b/src/lib/libc/stdio/local.h new file mode 100644 index 0000000..127be24 --- /dev/null +++ b/src/lib/libc/stdio/local.h @@ -0,0 +1,148 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)local.h 8.3 (Berkeley) 7/3/94 + * $FreeBSD: src/lib/libc/stdio/local.h,v 1.23 2004/03/09 04:51:58 jb Exp $ + */ + +#include /* for off_t */ +#include +#include +#include + +/* + * Information local to this implementation of stdio, + * in particular, macros and private variables. + */ + +extern int _sread(FILE *, char *, int); +extern int _swrite(FILE *, char const *, int); +extern fpos_t _sseek(FILE *, fpos_t, int); +extern int _ftello(FILE *, fpos_t *); +extern int _fseeko(FILE *, off_t, int, int); +extern int __fflush(FILE *fp); +extern wint_t __fgetwc(FILE *); +extern wint_t __fputwc(wchar_t, FILE *); +extern int __sflush(FILE *); +extern FILE *__sfp(void); +extern int __srefill(FILE *); +extern int __sread(void *, char *, int); +extern int __swrite(void *, char const *, int); +extern fpos_t __sseek(void *, fpos_t, int); +extern int __sclose(void *); +extern void __sinit(void); +extern void _cleanup(void); +extern void (*__cleanup)(void); +extern void __smakebuf(FILE *); +extern int __swhatbuf(FILE *, size_t *, int *); +extern int _fwalk(int (*)(FILE *)); +extern int __svfscanf(FILE *, const char *, __va_list); +extern int __swsetup(FILE *); +extern int __sflags(const char *, int *); +extern int __ungetc(int, FILE *); +extern wint_t __ungetwc(wint_t, FILE *); +extern int __vfprintf(FILE *, const char *, __va_list); +extern int __vfscanf(FILE *, const char *, __va_list); +extern int __vfwprintf(FILE *, const wchar_t *, __va_list); +extern int __vfwscanf(FILE * __restrict, const wchar_t * __restrict, + __va_list); + +extern int __sdidinit; + + +/* hold a buncha junk that would grow the ABI */ +struct __sFILEX { + unsigned char *_up; /* saved _p when _p is doing ungetc data */ + pthread_mutex_t fl_mutex; /* used for MT-safety */ + pthread_t fl_owner; /* current owner */ + int fl_count; /* recursive lock count */ + int orientation; /* orientation for fwide() */ +#ifdef notdef + /* + * XXX These are not used yet -- they will be used to store the + * multibyte conversion state for writing and reading when + * stateful encodings are supported by the locale framework. + */ + mbstate_t wstate; /* write conversion state */ + mbstate_t rstate; /* read conversion state */ +#endif +}; + +/* + * Return true iff the given FILE cannot be written now. + */ +#define cantwrite(fp) \ + ((((fp)->_flags & __SWR) == 0 || \ + ((fp)->_bf._base == NULL && ((fp)->_flags & __SSTR) == 0)) && \ + __swsetup(fp)) + +/* + * Test whether the given stdio file has an active ungetc buffer; + * release such a buffer, without restoring ordinary unread data. + */ +#define HASUB(fp) ((fp)->_ub._base != NULL) +#define FREEUB(fp) { \ + if ((fp)->_ub._base != (fp)->_ubuf) \ + free((char *)(fp)->_ub._base); \ + (fp)->_ub._base = NULL; \ +} + +/* + * test for an fgetln() buffer. + */ +#define HASLB(fp) ((fp)->_lb._base != NULL) +#define FREELB(fp) { \ + free((char *)(fp)->_lb._base); \ + (fp)->_lb._base = NULL; \ +} + +#define INITEXTRA(fp) { \ + (fp)->_extra->_up = NULL; \ + (fp)->_extra->fl_mutex = PTHREAD_MUTEX_INITIALIZER; \ + (fp)->_extra->fl_owner = NULL; \ + (fp)->_extra->fl_count = 0; \ + (fp)->_extra->orientation = 0; \ + /* memset(&(fp)->_extra->wstate, 0, sizeof(mbstate_t)); */ \ + /* memset(&(fp)->_extra->rstate, 0, sizeof(mbstate_t)); */ \ +} + +/* + * Set the orientation for a stream. If o > 0, the stream has wide- + * orientation. If o < 0, the stream has byte-orientation. + */ +#define ORIENT(fp, o) do { \ + if ((fp)->_extra->orientation == 0) \ + (fp)->_extra->orientation = (o); \ +} while (0) diff --git a/src/lib/libc/stdio/makebuf.c b/src/lib/libc/stdio/makebuf.c new file mode 100644 index 0000000..a4c5c36 --- /dev/null +++ b/src/lib/libc/stdio/makebuf.c @@ -0,0 +1,122 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/makebuf.c,v 1.4 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "local.h" +#include "un-namespace.h" + +/* + * Allocate a file buffer, or switch to unbuffered I/O. + * Per the ANSI C standard, ALL tty devices default to line buffered. + * + * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek + * optimisation) right after the _fstat() that finds the buffer size. + */ +void +__smakebuf(fp) + FILE *fp; +{ + void *p; + int flags; + size_t size; + int couldbetty; + + if (fp->_flags & __SNBF) { + fp->_bf._base = fp->_p = fp->_nbuf; + fp->_bf._size = 1; + return; + } + flags = __swhatbuf(fp, &size, &couldbetty); + if ((p = malloc(size)) == NULL) { + fp->_flags |= __SNBF; + fp->_bf._base = fp->_p = fp->_nbuf; + fp->_bf._size = 1; + return; + } + __cleanup = _cleanup; + flags |= __SMBF; + fp->_bf._base = fp->_p = p; + fp->_bf._size = size; + if (couldbetty && isatty(fp->_file)) + flags |= __SLBF; + fp->_flags |= flags; +} + +/* + * Internal routine to determine `proper' buffering for a file. + */ +int +__swhatbuf(fp, bufsize, couldbetty) + FILE *fp; + size_t *bufsize; + int *couldbetty; +{ + struct stat st; + + if (fp->_file < 0 || _fstat(fp->_file, &st) < 0) { + *couldbetty = 0; + *bufsize = BUFSIZ; + return (__SNPT); + } + + /* could be a tty iff it is a character device */ + *couldbetty = (st.st_mode & S_IFMT) == S_IFCHR; + if (st.st_blksize <= 0) { + *bufsize = BUFSIZ; + return (__SNPT); + } + + /* + * Optimise fseek() only if it is a regular file. (The test for + * __sseek is mainly paranoia.) It is safe to set _blksize + * unconditionally; it will only be used if __SOPT is also set. + */ + *bufsize = st.st_blksize; + fp->_blksize = st.st_blksize; + return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ? + __SOPT : __SNPT); +} diff --git a/src/lib/libc/stdio/mktemp.c b/src/lib/libc/stdio/mktemp.c new file mode 100644 index 0000000..8207c17 --- /dev/null +++ b/src/lib/libc/stdio/mktemp.c @@ -0,0 +1,186 @@ +/* + * Copyright (c) 1987, 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[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/mktemp.c,v 1.28 2003/02/16 17:29:10 nectar Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +char *_mktemp(char *); + +static int _gettemp(char *, int *, int, int); + +static const unsigned char padchar[] = +"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +int +mkstemps(path, slen) + char *path; + int slen; +{ + int fd; + + return (_gettemp(path, &fd, 0, slen) ? fd : -1); +} + +int +mkstemp(path) + char *path; +{ + int fd; + + return (_gettemp(path, &fd, 0, 0) ? fd : -1); +} + +char * +mkdtemp(path) + char *path; +{ + return (_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL); +} + +char * +_mktemp(path) + char *path; +{ + return (_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL); +} + +__warn_references(mktemp, + "warning: mktemp() possibly used unsafely; consider using mkstemp()"); + +char * +mktemp(path) + char *path; +{ + return (_mktemp(path)); +} + +static int +_gettemp(path, doopen, domkdir, slen) + char *path; + int *doopen; + int domkdir; + int slen; +{ + char *start, *trv, *suffp; + char *pad; + struct stat sbuf; + int rval; + uint32_t rand; + + if (doopen != NULL && domkdir) { + errno = EINVAL; + return (0); + } + + for (trv = path; *trv != '\0'; ++trv) + ; + trv -= slen; + suffp = trv; + --trv; + if (trv < path) { + errno = EINVAL; + return (0); + } + + /* Fill space with random characters */ + while (trv >= path && *trv == 'X') { + rand = arc4random() % (sizeof(padchar) - 1); + *trv-- = padchar[rand]; + } + start = trv + 1; + + /* + * check the target directory. + */ + if (doopen != NULL || domkdir) { + for (; trv > path; --trv) { + if (*trv == '/') { + *trv = '\0'; + rval = stat(path, &sbuf); + *trv = '/'; + if (rval != 0) + return (0); + if (!S_ISDIR(sbuf.st_mode)) { + errno = ENOTDIR; + return (0); + } + break; + } + } + } + + for (;;) { + if (doopen) { + if ((*doopen = + _open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) + return (1); + if (errno != EEXIST) + return (0); + } else if (domkdir) { + if (mkdir(path, 0700) == 0) + return (1); + if (errno != EEXIST) + return (0); + } else if (lstat(path, &sbuf)) + return (errno == ENOENT); + + /* If we have a collision, cycle through the space of filenames */ + for (trv = start;;) { + if (*trv == '\0' || trv == suffp) + return (0); + pad = strchr(padchar, *trv); + if (pad == NULL || *++pad == '\0') + *trv++ = padchar[0]; + else { + *trv++ = *pad; + break; + } + } + } + /*NOTREACHED*/ +} diff --git a/src/lib/libc/stdio/perror.c b/src/lib/libc/stdio/perror.c new file mode 100644 index 0000000..658b880 --- /dev/null +++ b/src/lib/libc/stdio/perror.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)perror.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/perror.c,v 1.8 2002/12/19 09:53:26 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +void +perror(s) + const char *s; +{ + char msgbuf[NL_TEXTMAX]; + struct iovec *v; + struct iovec iov[4]; + + v = iov; + if (s != NULL && *s != '\0') { + v->iov_base = (char *)s; + v->iov_len = strlen(s); + v++; + v->iov_base = ": "; + v->iov_len = 2; + v++; + } + strerror_r(errno, msgbuf, sizeof(msgbuf)); + v->iov_base = msgbuf; + v->iov_len = strlen(v->iov_base); + v++; + v->iov_base = "\n"; + v->iov_len = 1; + FLOCKFILE(stderr); + __sflush(stderr); + (void)_writev(stderr->_file, iov, (v - iov) + 1); + stderr->_flags &= ~__SOFF; + FUNLOCKFILE(stderr); +} diff --git a/src/lib/libc/stdio/printf.c b/src/lib/libc/stdio/printf.c new file mode 100644 index 0000000..86452e2 --- /dev/null +++ b/src/lib/libc/stdio/printf.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)printf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/printf.c,v 1.10 2002/09/06 11:23:55 tjr Exp $"); + +#include +#include + +int +printf(char const * __restrict fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vfprintf(stdout, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/src/lib/libc/stdio/putc.c b/src/lib/libc/stdio/putc.c new file mode 100644 index 0000000..e78bb42 --- /dev/null +++ b/src/lib/libc/stdio/putc.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/putc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +#undef putc + +int +putc(c, fp) + int c; + FILE *fp; +{ + int retval; + FLOCKFILE(fp); + /* Orientation set by __sputc() when buffer is full. */ + /* ORIENT(fp, -1); */ + retval = __sputc(c, fp); + FUNLOCKFILE(fp); + return (retval); +} diff --git a/src/lib/libc/stdio/putchar.c b/src/lib/libc/stdio/putchar.c new file mode 100644 index 0000000..d23161d --- /dev/null +++ b/src/lib/libc/stdio/putchar.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/putchar.c,v 1.13 2004/03/19 09:04:56 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +#undef putchar + +/* + * A subroutine version of the macro putchar + */ +int +putchar(c) + int c; +{ + int retval; + FILE *so = stdout; + + FLOCKFILE(so); + /* Orientation set by __sputc() when buffer is full. */ + /* ORIENT(so, -1); */ + retval = __sputc(c, so); + FUNLOCKFILE(so); + return (retval); +} diff --git a/src/lib/libc/stdio/puts.c b/src/lib/libc/stdio/puts.c new file mode 100644 index 0000000..9ac915e --- /dev/null +++ b/src/lib/libc/stdio/puts.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/puts.c,v 1.10 2004/03/10 09:15:38 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "fvwrite.h" +#include "libc_private.h" +#include "local.h" + +/* + * Write the given string to stdout, appending a newline. + */ +int +puts(s) + char const *s; +{ + int retval; + size_t c = strlen(s); + struct __suio uio; + struct __siov iov[2]; + + iov[0].iov_base = (void *)s; + iov[0].iov_len = c; + iov[1].iov_base = "\n"; + iov[1].iov_len = 1; + uio.uio_resid = c + 1; + uio.uio_iov = &iov[0]; + uio.uio_iovcnt = 2; + FLOCKFILE(stdout); + ORIENT(stdout, -1); + retval = __sfvwrite(stdout, &uio) ? EOF : '\n'; + FUNLOCKFILE(stdout); + return (retval); +} diff --git a/src/lib/libc/stdio/putw.c b/src/lib/libc/stdio/putw.c new file mode 100644 index 0000000..ee0c23b --- /dev/null +++ b/src/lib/libc/stdio/putw.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/putw.c,v 1.9 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "fvwrite.h" +#include "libc_private.h" + +int +putw(w, fp) + int w; + FILE *fp; +{ + int retval; + struct __suio uio; + struct __siov iov; + + iov.iov_base = &w; + iov.iov_len = uio.uio_resid = sizeof(w); + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + FLOCKFILE(fp); + retval = __sfvwrite(fp, &uio); + FUNLOCKFILE(fp); + return (retval); +} diff --git a/src/lib/libc/stdio/putwc.c b/src/lib/libc/stdio/putwc.c new file mode 100644 index 0000000..a33f78f --- /dev/null +++ b/src/lib/libc/stdio/putwc.c @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/putwc.c,v 1.2 2002/09/28 07:43:44 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Synonym for fputwc(). The only difference is that putwc(), if it is a + * macro, may evaluate `fp' more than once. + */ +wint_t +putwc(wchar_t wc, FILE *fp) +{ + + return (fputwc(wc, fp)); +} diff --git a/src/lib/libc/stdio/putwchar.c b/src/lib/libc/stdio/putwchar.c new file mode 100644 index 0000000..a39e070 --- /dev/null +++ b/src/lib/libc/stdio/putwchar.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/putwchar.c,v 1.2 2002/09/28 07:43:44 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Synonym for fputwc(wc, stdout). + */ +wint_t +putwchar(wchar_t wc) +{ + + return (fputwc(wc, stdout)); +} diff --git a/src/lib/libc/stdio/refill.c b/src/lib/libc/stdio/refill.c new file mode 100644 index 0000000..edd8bb6 --- /dev/null +++ b/src/lib/libc/stdio/refill.c @@ -0,0 +1,150 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/refill.c,v 1.18 2002/08/13 09:30:41 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" +#include "local.h" + +static int lflush(FILE *); + +static int +lflush(FILE *fp) +{ + int ret = 0; + + if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) { + FLOCKFILE(fp); + ret = __sflush(fp); + FUNLOCKFILE(fp); + } + return (ret); +} + +/* + * Refill a stdio buffer. + * Return EOF on eof or error, 0 otherwise. + */ +int +__srefill(FILE *fp) +{ + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + ORIENT(fp, -1); + + fp->_r = 0; /* largely a convenience for callers */ + + /* SysV does not make this test; take it out for compatibility */ + if (fp->_flags & __SEOF) + return (EOF); + + /* if not already reading, have to be reading and writing */ + if ((fp->_flags & __SRD) == 0) { + if ((fp->_flags & __SRW) == 0) { + errno = EBADF; + fp->_flags |= __SERR; + return (EOF); + } + /* switch to reading */ + if (fp->_flags & __SWR) { + if (__sflush(fp)) + return (EOF); + fp->_flags &= ~__SWR; + fp->_w = 0; + fp->_lbfsize = 0; + } + fp->_flags |= __SRD; + } else { + /* + * We were reading. If there is an ungetc buffer, + * we must have been reading from that. Drop it, + * restoring the previous buffer (if any). If there + * is anything in that buffer, return. + */ + if (HASUB(fp)) { + FREEUB(fp); + if ((fp->_r = fp->_ur) != 0) { + fp->_p = fp->_extra->_up; + return (0); + } + } + } + + if (fp->_bf._base == NULL) + __smakebuf(fp); + + /* + * Before reading from a line buffered or unbuffered file, + * flush all line buffered output files, per the ANSI C + * standard. + */ + if (fp->_flags & (__SLBF|__SNBF)) { + /* Ignore this file in _fwalk to avoid potential deadlock. */ + fp->_flags |= __SIGN; + (void) _fwalk(lflush); + fp->_flags &= ~__SIGN; + + /* Now flush this file without locking it. */ + if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) + __sflush(fp); + } + fp->_p = fp->_bf._base; + fp->_r = _sread(fp, (char *)fp->_p, fp->_bf._size); + fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ + if (fp->_r <= 0) { + if (fp->_r == 0) + fp->_flags |= __SEOF; + else { + fp->_r = 0; + fp->_flags |= __SERR; + } + return (EOF); + } + return (0); +} diff --git a/src/lib/libc/stdio/remove.c b/src/lib/libc/stdio/remove.c new file mode 100644 index 0000000..2553f64 --- /dev/null +++ b/src/lib/libc/stdio/remove.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/remove.c,v 1.8 2002/03/22 21:53:04 obrien Exp $"); + +#include +#include +#include +#include + +int +remove(file) + const char *file; +{ + struct stat sb; + + if (lstat(file, &sb) < 0) + return (-1); + if (S_ISDIR(sb.st_mode)) + return (rmdir(file)); + return (unlink(file)); +} diff --git a/src/lib/libc/stdio/rewind.c b/src/lib/libc/stdio/rewind.c new file mode 100644 index 0000000..76f2ed3 --- /dev/null +++ b/src/lib/libc/stdio/rewind.c @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/rewind.c,v 1.11 2002/03/22 21:53:04 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +void +rewind(FILE *fp) +{ + int serrno = errno; + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + FLOCKFILE(fp); + if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) { + clearerr_unlocked(fp); + errno = serrno; + } + FUNLOCKFILE(fp); +} diff --git a/src/lib/libc/stdio/rget.c b/src/lib/libc/stdio/rget.c new file mode 100644 index 0000000..9b7f586 --- /dev/null +++ b/src/lib/libc/stdio/rget.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/rget.c,v 1.5 2002/03/22 21:53:04 obrien Exp $"); + +#include +#include "local.h" + +/* + * Handle getc() when the buffer ran out: + * Refill, then return the first character + * in the newly-filled buffer. + */ +int +__srget(FILE *fp) +{ + if (__srefill(fp) == 0) { + fp->_r--; + return (*fp->_p++); + } + return (EOF); +} diff --git a/src/lib/libc/stdio/scanf.c b/src/lib/libc/stdio/scanf.c new file mode 100644 index 0000000..b4fb1a3 --- /dev/null +++ b/src/lib/libc/stdio/scanf.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/scanf.c,v 1.12 2003/01/03 23:27:27 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +int +scanf(char const * __restrict fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + FLOCKFILE(stdin); + ret = __svfscanf(stdin, fmt, ap); + FUNLOCKFILE(stdin); + va_end(ap); + return (ret); +} diff --git a/src/lib/libc/stdio/setbuf.c b/src/lib/libc/stdio/setbuf.c new file mode 100644 index 0000000..5eb6fb1 --- /dev/null +++ b/src/lib/libc/stdio/setbuf.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/setbuf.c,v 1.4 2002/09/06 11:23:55 tjr Exp $"); + +#include +#include "local.h" + +void +setbuf(FILE * __restrict fp, char * __restrict buf) +{ + (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); +} diff --git a/src/lib/libc/stdio/setbuffer.c b/src/lib/libc/stdio/setbuffer.c new file mode 100644 index 0000000..6ec4376 --- /dev/null +++ b/src/lib/libc/stdio/setbuffer.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/setbuffer.c,v 1.7 2002/03/22 21:53:04 obrien Exp $"); + +#include + +void +setbuffer(fp, buf, size) + FILE *fp; + char *buf; + int size; +{ + + (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size); +} + +/* + * set line buffering + */ +int +setlinebuf(fp) + FILE *fp; +{ + + return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0)); +} diff --git a/src/lib/libc/stdio/setvbuf.c b/src/lib/libc/stdio/setvbuf.c new file mode 100644 index 0000000..166d5b1 --- /dev/null +++ b/src/lib/libc/stdio/setvbuf.c @@ -0,0 +1,165 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/setvbuf.c,v 1.13 2002/09/06 11:23:55 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +/* + * Set one of the three kinds of buffering, optionally including + * a buffer. + */ +int +setvbuf(FILE * __restrict fp, char * __restrict buf, int mode, size_t size) +{ + int ret, flags; + size_t iosize; + int ttyflag; + + /* + * Verify arguments. The `int' limit on `size' is due to this + * particular implementation. Note, buf and size are ignored + * when setting _IONBF. + */ + if (mode != _IONBF) + if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) + return (EOF); + + FLOCKFILE(fp); + /* + * Write current buffer, if any. Discard unread input (including + * ungetc data), cancel line buffering, and free old buffer if + * malloc()ed. We also clear any eof condition, as if this were + * a seek. + */ + ret = 0; + (void)__sflush(fp); + if (HASUB(fp)) + FREEUB(fp); + fp->_r = fp->_lbfsize = 0; + flags = fp->_flags; + if (flags & __SMBF) + free((void *)fp->_bf._base); + flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SOFF | __SNPT | __SEOF); + + /* If setting unbuffered mode, skip all the hard work. */ + if (mode == _IONBF) + goto nbf; + + /* + * Find optimal I/O size for seek optimization. This also returns + * a `tty flag' to suggest that we check isatty(fd), but we do not + * care since our caller told us how to buffer. + */ + flags |= __swhatbuf(fp, &iosize, &ttyflag); + if (size == 0) { + buf = NULL; /* force local allocation */ + size = iosize; + } + + /* Allocate buffer if needed. */ + if (buf == NULL) { + if ((buf = malloc(size)) == NULL) { + /* + * Unable to honor user's request. We will return + * failure, but try again with file system size. + */ + ret = EOF; + if (size != iosize) { + size = iosize; + buf = malloc(size); + } + } + if (buf == NULL) { + /* No luck; switch to unbuffered I/O. */ +nbf: + fp->_flags = flags | __SNBF; + fp->_w = 0; + fp->_bf._base = fp->_p = fp->_nbuf; + fp->_bf._size = 1; + FUNLOCKFILE(fp); + return (ret); + } + flags |= __SMBF; + } + + /* + * Kill any seek optimization if the buffer is not the + * right size. + * + * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)? + */ + if (size != iosize) + flags |= __SNPT; + + /* + * Fix up the FILE fields, and set __cleanup for output flush on + * exit (since we are buffered in some way). + */ + if (mode == _IOLBF) + flags |= __SLBF; + fp->_flags = flags; + fp->_bf._base = fp->_p = (unsigned char *)buf; + fp->_bf._size = size; + /* fp->_lbfsize is still 0 */ + if (flags & __SWR) { + /* + * Begin or continue writing: see __swsetup(). Note + * that __SNBF is impossible (it was handled earlier). + */ + if (flags & __SLBF) { + fp->_w = 0; + fp->_lbfsize = -fp->_bf._size; + } else + fp->_w = size; + } else { + /* begin/continue reading, or stay in intermediate state */ + fp->_w = 0; + } + __cleanup = _cleanup; + + FUNLOCKFILE(fp); + return (ret); +} diff --git a/src/lib/libc/stdio/snprintf.c b/src/lib/libc/stdio/snprintf.c new file mode 100644 index 0000000..b381852 --- /dev/null +++ b/src/lib/libc/stdio/snprintf.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/snprintf.c,v 1.20 2002/09/06 11:23:55 tjr Exp $"); + +#include +#include +#include + +#include "local.h" + +int +snprintf(char * __restrict str, size_t n, char const * __restrict fmt, ...) +{ + size_t on; + int ret; + va_list ap; + FILE f; + struct __sFILEX ext; + + on = n; + if (n != 0) + n--; + if (n > INT_MAX) + n = INT_MAX; + va_start(ap, fmt); + f._file = -1; + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = n; + f._extra = &ext; + INITEXTRA(&f); + ret = __vfprintf(&f, fmt, ap); + if (on > 0) + *f._p = '\0'; + va_end(ap); + return (ret); +} diff --git a/src/lib/libc/stdio/sprintf.c b/src/lib/libc/stdio/sprintf.c new file mode 100644 index 0000000..6b9ed99 --- /dev/null +++ b/src/lib/libc/stdio/sprintf.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/sprintf.c,v 1.14 2002/09/06 11:23:55 tjr Exp $"); + +#include +#include +#include +#include "local.h" + +int +sprintf(char * __restrict str, char const * __restrict fmt, ...) +{ + int ret; + va_list ap; + FILE f; + struct __sFILEX ext; + + f._file = -1; + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = INT_MAX; + f._extra = &ext; + INITEXTRA(&f); + va_start(ap, fmt); + ret = __vfprintf(&f, fmt, ap); + va_end(ap); + *f._p = 0; + return (ret); +} diff --git a/src/lib/libc/stdio/sscanf.c b/src/lib/libc/stdio/sscanf.c new file mode 100644 index 0000000..b4850cd --- /dev/null +++ b/src/lib/libc/stdio/sscanf.c @@ -0,0 +1,82 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/sscanf.c,v 1.11 2002/10/12 16:13:41 mike Exp $"); + +#include +#include +#include +#include "local.h" + +static int eofread(void *, char *, int); + +/* ARGSUSED */ +static int +eofread(cookie, buf, len) + void *cookie; + char *buf; + int len; +{ + + return (0); +} + +int +sscanf(const char * __restrict str, char const * __restrict fmt, ...) +{ + int ret; + va_list ap; + struct __sFILEX extra; + FILE f; + + f._file = -1; + f._flags = __SRD; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._r = strlen(str); + f._read = eofread; + f._ub._base = NULL; + f._lb._base = NULL; + f._extra = &extra; + INITEXTRA(&f); + va_start(ap, fmt); + ret = __svfscanf(&f, fmt, ap); + va_end(ap); + return (ret); +} diff --git a/src/lib/libc/stdio/stdio.c b/src/lib/libc/stdio/stdio.c new file mode 100644 index 0000000..233427c --- /dev/null +++ b/src/lib/libc/stdio/stdio.c @@ -0,0 +1,191 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/stdio.c,v 1.24 2003/01/07 06:17:13 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "local.h" + +/* + * Small standard I/O/seek/close functions. + */ +int +__sread(cookie, buf, n) + void *cookie; + char *buf; + int n; +{ + FILE *fp = cookie; + + return(_read(fp->_file, buf, (size_t)n)); +} + +int +__swrite(cookie, buf, n) + void *cookie; + char const *buf; + int n; +{ + FILE *fp = cookie; + + return (_write(fp->_file, buf, (size_t)n)); +} + +fpos_t +__sseek(cookie, offset, whence) + void *cookie; + fpos_t offset; + int whence; +{ + FILE *fp = cookie; + + return (lseek(fp->_file, (off_t)offset, whence)); +} + +int +__sclose(cookie) + void *cookie; +{ + + return (_close(((FILE *)cookie)->_file)); +} + +/* + * Higher level wrappers. + */ +int +_sread(fp, buf, n) + FILE *fp; + char *buf; + int n; +{ + int ret; + + ret = (*fp->_read)(fp->_cookie, buf, n); + if (ret > 0) { + if (fp->_flags & __SOFF) { + if (fp->_offset <= OFF_MAX - ret) + fp->_offset += ret; + else + fp->_flags &= ~__SOFF; + } + } else if (ret < 0) + fp->_flags &= ~__SOFF; + return (ret); +} + +int +_swrite(fp, buf, n) + FILE *fp; + char const *buf; + int n; +{ + int ret; + int serrno; + + if (fp->_flags & __SAPP) { + serrno = errno; + if (_sseek(fp, (fpos_t)0, SEEK_END) == -1 && + (fp->_flags & __SOPT)) + return (-1); + errno = serrno; + } + ret = (*fp->_write)(fp->_cookie, buf, n); + /* __SOFF removed even on success in case O_APPEND mode is set. */ + if (ret >= 0) { + if ((fp->_flags & (__SAPP|__SOFF)) == (__SAPP|__SOFF) && + fp->_offset <= OFF_MAX - ret) + fp->_offset += ret; + else + fp->_flags &= ~__SOFF; + + } else if (ret < 0) + fp->_flags &= ~__SOFF; + return (ret); +} + +fpos_t +_sseek(fp, offset, whence) + FILE *fp; + fpos_t offset; + int whence; +{ + fpos_t ret; + int serrno, errret; + + serrno = errno; + errno = 0; + ret = (*fp->_seek)(fp->_cookie, offset, whence); + errret = errno; + if (errno == 0) + errno = serrno; + /* + * Disallow negative seeks per POSIX. + * It is needed here to help upper level caller + * in the cases it can't detect. + */ + if (ret < 0) { + if (errret == 0) { + if (offset != 0 || whence != SEEK_CUR) { + if (HASUB(fp)) + FREEUB(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + fp->_flags &= ~__SEOF; + } + fp->_flags |= __SERR; + errno = EINVAL; + } else if (errret == ESPIPE) + fp->_flags &= ~__SAPP; + fp->_flags &= ~__SOFF; + ret = -1; + } else if (fp->_flags & __SOPT) { + fp->_flags |= __SOFF; + fp->_offset = ret; + } + return (ret); +} diff --git a/src/lib/libc/stdio/swprintf.c b/src/lib/libc/stdio/swprintf.c new file mode 100644 index 0000000..190326a --- /dev/null +++ b/src/lib/libc/stdio/swprintf.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/swprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); + +#include +#include +#include + +int +swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vswprintf(s, n, fmt, ap); + va_end(ap); + + return (ret); +} diff --git a/src/lib/libc/stdio/swscanf.c b/src/lib/libc/stdio/swscanf.c new file mode 100644 index 0000000..81ac9f1 --- /dev/null +++ b/src/lib/libc/stdio/swscanf.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/swscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); + +#include +#include +#include + +int +swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...) +{ + va_list ap; + int r; + + va_start(ap, fmt); + r = vswscanf(str, fmt, ap); + va_end(ap); + + return (r); +} diff --git a/src/lib/libc/stdio/tempnam.c b/src/lib/libc/stdio/tempnam.c new file mode 100644 index 0000000..d4dbaa3 --- /dev/null +++ b/src/lib/libc/stdio/tempnam.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/tempnam.c,v 1.10 2002/03/22 21:53:04 obrien Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +__warn_references(tempnam, + "warning: tempnam() possibly used unsafely; consider using mkstemp()"); + +extern char *_mktemp(char *); + +char * +tempnam(dir, pfx) + const char *dir, *pfx; +{ + int sverrno; + char *f, *name; + + if (!(name = malloc(MAXPATHLEN))) + return(NULL); + + if (!pfx) + pfx = "tmp."; + + if (issetugid() == 0 && (f = getenv("TMPDIR"))) { + (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, + *(f + strlen(f) - 1) == '/'? "": "/", pfx); + if ((f = _mktemp(name))) + return(f); + } + + if ((f = (char *)dir)) { + (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, + *(f + strlen(f) - 1) == '/'? "": "/", pfx); + if ((f = _mktemp(name))) + return(f); + } + + f = P_tmpdir; + (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + if ((f = _mktemp(name))) + return(f); + + f = _PATH_TMP; + (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); + if ((f = _mktemp(name))) + return(f); + + sverrno = errno; + free(name); + errno = sverrno; + return(NULL); +} diff --git a/src/lib/libc/stdio/tmpfile.c b/src/lib/libc/stdio/tmpfile.c new file mode 100644 index 0000000..cf5b70a --- /dev/null +++ b/src/lib/libc/stdio/tmpfile.c @@ -0,0 +1,96 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/tmpfile.c,v 1.9 2003/02/06 01:08:19 mtm Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +FILE * +tmpfile() +{ + sigset_t set, oset; + FILE *fp; + int fd, sverrno; +#define TRAILER "tmp.XXXXXX" + char *buf; + const char *tmpdir; + + tmpdir = NULL; + if (issetugid() == 0) + tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL) + tmpdir = _PATH_TMP; + + (void)asprintf(&buf, "%s%s%s", tmpdir, + (tmpdir[strlen(tmpdir) - 1] == '/') ? "" : "/", TRAILER); + if (buf == NULL) + return (NULL); + + sigfillset(&set); + (void)_sigprocmask(SIG_BLOCK, &set, &oset); + + fd = mkstemp(buf); + if (fd != -1) + (void)unlink(buf); + + free(buf); + + (void)_sigprocmask(SIG_SETMASK, &oset, NULL); + + if (fd == -1) + return (NULL); + + if ((fp = fdopen(fd, "w+")) == NULL) { + sverrno = errno; + (void)_close(fd); + errno = sverrno; + return (NULL); + } + return (fp); +} diff --git a/src/lib/libc/stdio/tmpnam.c b/src/lib/libc/stdio/tmpnam.c new file mode 100644 index 0000000..38fcdd6 --- /dev/null +++ b/src/lib/libc/stdio/tmpnam.c @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/tmpnam.c,v 1.5 2002/03/22 21:53:04 obrien Exp $"); + +#include + +#include +#include + +__warn_references(tmpnam, + "warning: tmpnam() possibly used unsafely; consider using mkstemp()"); + +extern char *_mktemp(char *); + +char * +tmpnam(s) + char *s; +{ + static u_long tmpcount; + static char buf[L_tmpnam]; + + if (s == NULL) + s = buf; + (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); + ++tmpcount; + return (_mktemp(s)); +} diff --git a/src/lib/libc/stdio/ungetc.c b/src/lib/libc/stdio/ungetc.c new file mode 100644 index 0000000..2217259 --- /dev/null +++ b/src/lib/libc/stdio/ungetc.c @@ -0,0 +1,172 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetc.c,v 1.16 2004/03/10 12:41:11 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include "un-namespace.h" +#include "local.h" +#include "libc_private.h" + +static int __submore(FILE *); + +/* + * Expand the ungetc buffer `in place'. That is, adjust fp->_p when + * the buffer moves, so that it points the same distance from the end, + * and move the bytes in the buffer around as necessary so that they + * are all at the end (stack-style). + */ +static int +__submore(FILE *fp) +{ + int i; + unsigned char *p; + + if (fp->_ub._base == fp->_ubuf) { + /* + * Get a new buffer (rather than expanding the old one). + */ + if ((p = malloc((size_t)BUFSIZ)) == NULL) + return (EOF); + fp->_ub._base = p; + fp->_ub._size = BUFSIZ; + p += BUFSIZ - sizeof(fp->_ubuf); + for (i = sizeof(fp->_ubuf); --i >= 0;) + p[i] = fp->_ubuf[i]; + fp->_p = p; + return (0); + } + i = fp->_ub._size; + p = realloc(fp->_ub._base, (size_t)(i << 1)); + if (p == NULL) + return (EOF); + /* no overlap (hence can use memcpy) because we doubled the size */ + (void)memcpy((void *)(p + i), (void *)p, (size_t)i); + fp->_p = p + i; + fp->_ub._base = p; + fp->_ub._size = i << 1; + return (0); +} + +/* + * MT-safe version + */ +int +ungetc(int c, FILE *fp) +{ + int ret; + + if (!__sdidinit) + __sinit(); + FLOCKFILE(fp); + ORIENT(fp, -1); + ret = __ungetc(c, fp); + FUNLOCKFILE(fp); + return (ret); +} + +/* + * Non-MT-safe version + */ +int +__ungetc(int c, FILE *fp) +{ + + if (c == EOF) + return (EOF); + if ((fp->_flags & __SRD) == 0) { + /* + * Not already reading: no good unless reading-and-writing. + * Otherwise, flush any current write stuff. + */ + if ((fp->_flags & __SRW) == 0) + return (EOF); + if (fp->_flags & __SWR) { + if (__sflush(fp)) + return (EOF); + fp->_flags &= ~__SWR; + fp->_w = 0; + fp->_lbfsize = 0; + } + fp->_flags |= __SRD; + } + c = (unsigned char)c; + + /* + * If we are in the middle of ungetc'ing, just continue. + * This may require expanding the current ungetc buffer. + */ + if (HASUB(fp)) { + if (fp->_r >= fp->_ub._size && __submore(fp)) + return (EOF); + *--fp->_p = c; + fp->_r++; + return (c); + } + fp->_flags &= ~__SEOF; + + /* + * If we can handle this by simply backing up, do so, + * but never replace the original character. + * (This makes sscanf() work when scanning `const' data.) + */ + if (fp->_bf._base != NULL && fp->_p > fp->_bf._base && + fp->_p[-1] == c) { + fp->_p--; + fp->_r++; + return (c); + } + + /* + * Create an ungetc buffer. + * Initially, we will use the `reserve' buffer. + */ + fp->_ur = fp->_r; + fp->_extra->_up = fp->_p; + fp->_ub._base = fp->_ubuf; + fp->_ub._size = sizeof(fp->_ubuf); + fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; + fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; + fp->_r = 1; + return (c); +} diff --git a/src/lib/libc/stdio/ungetwc.c b/src/lib/libc/stdio/ungetwc.c new file mode 100644 index 0000000..9200746 --- /dev/null +++ b/src/lib/libc/stdio/ungetwc.c @@ -0,0 +1,78 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetwc.c,v 1.7 2004/04/07 09:55:05 tjr Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +/* + * Non-MT-safe version. + */ +wint_t +__ungetwc(wint_t wc, FILE *fp) +{ + static const mbstate_t initial; + mbstate_t mbs; + char buf[MB_LEN_MAX]; + size_t len; + + if (wc == WEOF) + return (WEOF); + mbs = initial; + if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { + fp->_flags |= __SERR; + return (WEOF); + } + while (len-- != 0) + if (__ungetc((unsigned char)buf[len], fp) == EOF) + return (WEOF); + + return (wc); +} + +/* + * MT-safe version. + */ +wint_t +ungetwc(wint_t wc, FILE *fp) +{ + wint_t r; + + FLOCKFILE(fp); + ORIENT(fp, 1); + r = __ungetwc(wc, fp); + FUNLOCKFILE(fp); + + return (r); +} diff --git a/src/lib/libc/stdio/unlocked.c b/src/lib/libc/stdio/unlocked.c new file mode 100644 index 0000000..6b1c0ef --- /dev/null +++ b/src/lib/libc/stdio/unlocked.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2003 Tim J. Robbins. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/unlocked.c,v 1.1 2003/01/10 04:35:08 tjr Exp $"); + +#include + +#undef getchar_unlocked +int +getchar_unlocked(void) +{ + + return (__sgetc(stdin)); +} + +#undef getc_unlocked +int +getc_unlocked(FILE *fp) +{ + + return (__sgetc(fp)); +} + +#undef putchar_unlocked +int +putchar_unlocked(int ch) +{ + + return (__sputc(ch, stdout)); +} + +#undef putc_unlocked +int +putc_unlocked(int ch, FILE *fp) +{ + + return (__sputc(ch, fp)); +} + +#undef feof_unlocked +int +feof_unlocked(FILE *fp) +{ + + return (__sfeof(fp)); +} + +#undef ferror_unlocked +int +ferror_unlocked(FILE *fp) +{ + + return (__sferror(fp)); +} + +#undef clearerr_unlocked +void +clearerr_unlocked(FILE *fp) +{ + + __sclearerr(fp); +} + +#undef fileno_unlocked +int +fileno_unlocked(FILE *fp) +{ + + return (__sfileno(fp)); +} diff --git a/src/lib/libc/stdio/vasprintf.c b/src/lib/libc/stdio/vasprintf.c new file mode 100644 index 0000000..197c427 --- /dev/null +++ b/src/lib/libc/stdio/vasprintf.c @@ -0,0 +1,69 @@ +/* $OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.18 2002/09/26 13:11:24 tjr Exp $"); + +#include +#include +#include +#include "local.h" + +int +vasprintf(str, fmt, ap) + char **str; + const char *fmt; + __va_list ap; +{ + int ret; + FILE f; + struct __sFILEX ext; + + f._file = -1; + f._flags = __SWR | __SSTR | __SALC; + f._bf._base = f._p = (unsigned char *)malloc(128); + if (f._bf._base == NULL) { + *str = NULL; + errno = ENOMEM; + return (-1); + } + f._bf._size = f._w = 127; /* Leave room for the NUL */ + f._extra = &ext; + INITEXTRA(&f); + ret = __vfprintf(&f, fmt, ap); + if (ret < 0) { + free(f._bf._base); + *str = NULL; + errno = ENOMEM; + return (-1); + } + *f._p = '\0'; + *str = (char *)f._bf._base; + return (ret); +} diff --git a/src/lib/libc/stdio/vfprintf.c b/src/lib/libc/stdio/vfprintf.c new file mode 100644 index 0000000..c879874 --- /dev/null +++ b/src/lib/libc/stdio/vfprintf.c @@ -0,0 +1,1644 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.65 2004/05/02 10:55:05 das Exp $"); + +/* + * Actual printf innards. + * + * This code is large and complicated... + */ + +#include "namespace.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "un-namespace.h" + +#include "libc_private.h" +#include "local.h" +#include "fvwrite.h" + +union arg { + int intarg; + u_int uintarg; + long longarg; + u_long ulongarg; + long long longlongarg; + unsigned long long ulonglongarg; + ptrdiff_t ptrdiffarg; + size_t sizearg; + intmax_t intmaxarg; + uintmax_t uintmaxarg; + void *pvoidarg; + char *pchararg; + signed char *pschararg; + short *pshortarg; + int *pintarg; + long *plongarg; + long long *plonglongarg; + ptrdiff_t *pptrdiffarg; + size_t *psizearg; + intmax_t *pintmaxarg; +#ifndef NO_FLOATING_POINT + double doublearg; + long double longdoublearg; +#endif + wint_t wintarg; + wchar_t *pwchararg; +}; + +/* + * Type ids for argument type table. + */ +enum typeid { + T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT, + T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG, + T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET, + T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR, + T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR +}; + +static int __sprint(FILE *, struct __suio *); +static int __sbprintf(FILE *, const char *, va_list) __printflike(2, 0); +static char *__ujtoa(uintmax_t, char *, int, int, const char *, int, char, + const char *); +static char *__ultoa(u_long, char *, int, int, const char *, int, char, + const char *); +static char *__wcsconv(wchar_t *, int); +static void __find_arguments(const char *, va_list, union arg **); +static void __grow_type_table(int, enum typeid **, int *); + +/* + * Flush out all the vectors defined by the given uio, + * then reset it so that it can be reused. + */ +static int +__sprint(FILE *fp, struct __suio *uio) +{ + int err; + + if (uio->uio_resid == 0) { + uio->uio_iovcnt = 0; + return (0); + } + err = __sfvwrite(fp, uio); + uio->uio_resid = 0; + uio->uio_iovcnt = 0; + return (err); +} + +/* + * Helper function for `fprintf to unbuffered unix file': creates a + * temporary buffer. We only work on write-only files; this avoids + * worries about ungetc buffers and so forth. + */ +static int +__sbprintf(FILE *fp, const char *fmt, va_list ap) +{ + int ret; + FILE fake; + unsigned char buf[BUFSIZ]; + + /* copy the important variables */ + fake._flags = fp->_flags & ~__SNBF; + fake._file = fp->_file; + fake._cookie = fp->_cookie; + fake._write = fp->_write; + fake._extra = fp->_extra; + + /* set up the buffer */ + fake._bf._base = fake._p = buf; + fake._bf._size = fake._w = sizeof(buf); + fake._lbfsize = 0; /* not actually used, but Just In Case */ + + /* do the work, then copy any error status */ + ret = __vfprintf(&fake, fmt, ap); + if (ret >= 0 && __fflush(&fake)) + ret = EOF; + if (fake._flags & __SERR) + fp->_flags |= __SERR; + return (ret); +} + +/* + * Macros for converting digits to letters and vice versa + */ +#define to_digit(c) ((c) - '0') +#define is_digit(c) ((unsigned)to_digit(c) <= 9) +#define to_char(n) ((n) + '0') + +/* + * Convert an unsigned long to ASCII for printf purposes, returning + * a pointer to the first character of the string representation. + * Octal numbers can be forced to have a leading zero; hex numbers + * use the given digits. + */ +static char * +__ultoa(u_long val, char *endp, int base, int octzero, const char *xdigs, + int needgrp, char thousep, const char *grp) +{ + char *cp = endp; + long sval; + int ndig; + + /* + * Handle the three cases separately, in the hope of getting + * better/faster code. + */ + switch (base) { + case 10: + if (val < 10) { /* many numbers are 1 digit */ + *--cp = to_char(val); + return (cp); + } + ndig = 0; + /* + * On many machines, unsigned arithmetic is harder than + * signed arithmetic, so we do at most one unsigned mod and + * divide; this is sufficient to reduce the range of + * the incoming value to where signed arithmetic works. + */ + if (val > LONG_MAX) { + *--cp = to_char(val % 10); + ndig++; + sval = val / 10; + } else + sval = val; + do { + *--cp = to_char(sval % 10); + ndig++; + /* + * If (*grp == CHAR_MAX) then no more grouping + * should be performed. + */ + if (needgrp && ndig == *grp && *grp != CHAR_MAX + && sval > 9) { + *--cp = thousep; + ndig = 0; + /* + * If (*(grp+1) == '\0') then we have to + * use *grp character (last grouping rule) + * for all next cases + */ + if (*(grp+1) != '\0') + grp++; + } + sval /= 10; + } while (sval != 0); + break; + + case 8: + do { + *--cp = to_char(val & 7); + val >>= 3; + } while (val); + if (octzero && *cp != '0') + *--cp = '0'; + break; + + case 16: + do { + *--cp = xdigs[val & 15]; + val >>= 4; + } while (val); + break; + + default: /* oops */ + abort(); + } + return (cp); +} + +/* Identical to __ultoa, but for intmax_t. */ +static char * +__ujtoa(uintmax_t val, char *endp, int base, int octzero, const char *xdigs, + int needgrp, char thousep, const char *grp) +{ + char *cp = endp; + intmax_t sval; + int ndig; + + /* quick test for small values; __ultoa is typically much faster */ + /* (perhaps instead we should run until small, then call __ultoa?) */ + if (val <= ULONG_MAX) + return (__ultoa((u_long)val, endp, base, octzero, xdigs, + needgrp, thousep, grp)); + switch (base) { + case 10: + if (val < 10) { + *--cp = to_char(val % 10); + return (cp); + } + ndig = 0; + if (val > INTMAX_MAX) { + *--cp = to_char(val % 10); + ndig++; + sval = val / 10; + } else + sval = val; + do { + *--cp = to_char(sval % 10); + ndig++; + /* + * If (*grp == CHAR_MAX) then no more grouping + * should be performed. + */ + if (needgrp && *grp != CHAR_MAX && ndig == *grp + && sval > 9) { + *--cp = thousep; + ndig = 0; + /* + * If (*(grp+1) == '\0') then we have to + * use *grp character (last grouping rule) + * for all next cases + */ + if (*(grp+1) != '\0') + grp++; + } + sval /= 10; + } while (sval != 0); + break; + + case 8: + do { + *--cp = to_char(val & 7); + val >>= 3; + } while (val); + if (octzero && *cp != '0') + *--cp = '0'; + break; + + case 16: + do { + *--cp = xdigs[val & 15]; + val >>= 4; + } while (val); + break; + + default: + abort(); + } + return (cp); +} + +/* + * Convert a wide character string argument for the %ls format to a multibyte + * string representation. ``prec'' specifies the maximum number of bytes + * to output. If ``prec'' is greater than or equal to zero, we can't assume + * that the wide char. string ends in a null character. + */ +static char * +__wcsconv(wchar_t *wcsarg, int prec) +{ + static const mbstate_t initial; + mbstate_t mbs; + char buf[MB_LEN_MAX]; + wchar_t *p; + char *convbuf, *mbp; + size_t clen, nbytes; + + /* + * Determine the number of bytes to output and allocate space for + * the output. + */ + if (prec >= 0) { + nbytes = 0; + p = wcsarg; + mbs = initial; + for (;;) { + clen = wcrtomb(buf, *p++, &mbs); + if (clen == 0 || clen == (size_t)-1 || + nbytes + clen > prec) + break; + nbytes += clen; + } + } else { + p = wcsarg; + mbs = initial; + nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs); + if (nbytes == (size_t)-1) + return (NULL); + } + if ((convbuf = malloc(nbytes + 1)) == NULL) + return (NULL); + + /* + * Fill the output buffer with the multibyte representations of as + * many wide characters as will fit. + */ + mbp = convbuf; + p = wcsarg; + mbs = initial; + while (mbp - convbuf < nbytes) { + clen = wcrtomb(mbp, *p++, &mbs); + if (clen == 0 || clen == (size_t)-1) + break; + mbp += clen; + } + if (clen == (size_t)-1) { + free(convbuf); + return (NULL); + } + *mbp = '\0'; + + return (convbuf); +} + +/* + * MT-safe version + */ +int +vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap) + +{ + int ret; + + FLOCKFILE(fp); + ret = __vfprintf(fp, fmt0, ap); + FUNLOCKFILE(fp); + return (ret); +} + +#ifndef NO_FLOATING_POINT + +#define dtoa __dtoa +#define freedtoa __freedtoa + +#include +#include +#include "floatio.h" +#include "gdtoa.h" + +#define DEFPREC 6 + +static int exponent(char *, int, int); + +#endif /* !NO_FLOATING_POINT */ + +/* + * The size of the buffer we use as scratch space for integer + * conversions, among other things. Technically, we would need the + * most space for base 10 conversions with thousands' grouping + * characters between each pair of digits. 100 bytes is a + * conservative overestimate even for a 128-bit uintmax_t. + */ +#define BUF 100 + +#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */ + +/* + * Flags used during conversion. + */ +#define ALT 0x001 /* alternate form */ +#define LADJUST 0x004 /* left adjustment */ +#define LONGDBL 0x008 /* long double */ +#define LONGINT 0x010 /* long integer */ +#define LLONGINT 0x020 /* long long integer */ +#define SHORTINT 0x040 /* short integer */ +#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ +#define FPT 0x100 /* Floating point number */ +#define GROUPING 0x200 /* use grouping ("'" flag) */ + /* C99 additional size modifiers: */ +#define SIZET 0x400 /* size_t */ +#define PTRDIFFT 0x800 /* ptrdiff_t */ +#define INTMAXT 0x1000 /* intmax_t */ +#define CHARINT 0x2000 /* print char using int format */ + +/* + * Non-MT-safe version + */ +int +__vfprintf(FILE *fp, const char *fmt0, va_list ap) +{ + char *fmt; /* format string */ + int ch; /* character from fmt */ + int n, n2; /* handy integer (short term usage) */ + char *cp; /* handy char pointer (short term usage) */ + struct __siov *iovp; /* for PRINT macro */ + int flags; /* flags as above */ + int ret; /* return value accumulator */ + int width; /* width from format (%8d), or 0 */ + int prec; /* precision from format; <0 for N/A */ + char sign; /* sign prefix (' ', '+', '-', or \0) */ + char thousands_sep; /* locale specific thousands separator */ + const char *grouping; /* locale specific numeric grouping rules */ +#ifndef NO_FLOATING_POINT + /* + * We can decompose the printed representation of floating + * point numbers into several parts, some of which may be empty: + * + * [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ + * A B ---C--- D E F + * + * A: 'sign' holds this value if present; '\0' otherwise + * B: ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal + * C: cp points to the string MMMNNN. Leading and trailing + * zeros are not in the string and must be added. + * D: expchar holds this character; '\0' if no exponent, e.g. %f + * F: at least two digits for decimal, at least one digit for hex + */ + char *decimal_point; /* locale specific decimal point */ + int signflag; /* true if float is negative */ + union { /* floating point arguments %[aAeEfFgG] */ + double dbl; + long double ldbl; + } fparg; + int expt; /* integer value of exponent */ + char expchar; /* exponent character: [eEpP\0] */ + char *dtoaend; /* pointer to end of converted digits */ + int expsize; /* character count for expstr */ + int lead; /* sig figs before decimal or group sep */ + int ndig; /* actual number of digits returned by dtoa */ + char expstr[MAXEXPDIG+2]; /* buffer for exponent string: e+ZZZ */ + char *dtoaresult; /* buffer allocated by dtoa */ + int nseps; /* number of group separators with ' */ + int nrepeats; /* number of repeats of the last group */ +#endif + u_long ulval; /* integer arguments %[diouxX] */ + uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */ + int base; /* base for [diouxX] conversion */ + int dprec; /* a copy of prec if [diouxX], 0 otherwise */ + int realsz; /* field size expanded by dprec, sign, etc */ + int size; /* size of converted field or string */ + int prsize; /* max size of printed field */ + const char *xdigs; /* digits for %[xX] conversion */ +#define NIOV 8 + struct __suio uio; /* output information: summary */ + struct __siov iov[NIOV];/* ... and individual io vectors */ + char buf[BUF]; /* buffer with space for digits of uintmax_t */ + char ox[2]; /* space for 0x; ox[1] is either x, X, or \0 */ + union arg *argtable; /* args, built due to positional arg */ + union arg statargtable [STATIC_ARG_TBL_SIZE]; + int nextarg; /* 1-based argument index */ + va_list orgap; /* original argument pointer */ + char *convbuf; /* wide to multibyte conversion result */ + + /* + * Choose PADSIZE to trade efficiency vs. size. If larger printf + * fields occur frequently, increase PADSIZE and make the initialisers + * below longer. + */ +#define PADSIZE 16 /* pad chunk size */ + static char blanks[PADSIZE] = + {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; + static char zeroes[PADSIZE] = + {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; + + static const char xdigs_lower[16] = "0123456789abcdef"; + static const char xdigs_upper[16] = "0123456789ABCDEF"; + + /* + * BEWARE, these `goto error' on error, and PAD uses `n'. + */ +#define PRINT(ptr, len) { \ + iovp->iov_base = (ptr); \ + iovp->iov_len = (len); \ + uio.uio_resid += (len); \ + iovp++; \ + if (++uio.uio_iovcnt >= NIOV) { \ + if (__sprint(fp, &uio)) \ + goto error; \ + iovp = iov; \ + } \ +} +#define PAD(howmany, with) { \ + if ((n = (howmany)) > 0) { \ + while (n > PADSIZE) { \ + PRINT(with, PADSIZE); \ + n -= PADSIZE; \ + } \ + PRINT(with, n); \ + } \ +} +#define PRINTANDPAD(p, ep, len, with) do { \ + n2 = (ep) - (p); \ + if (n2 > (len)) \ + n2 = (len); \ + if (n2 > 0) \ + PRINT((p), n2); \ + PAD((len) - (n2 > 0 ? n2 : 0), (with)); \ +} while(0) +#define FLUSH() { \ + if (uio.uio_resid && __sprint(fp, &uio)) \ + goto error; \ + uio.uio_iovcnt = 0; \ + iovp = iov; \ +} + + /* + * Get the argument indexed by nextarg. If the argument table is + * built, use it to get the argument. If its not, get the next + * argument (and arguments must be gotten sequentially). + */ +#define GETARG(type) \ + ((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \ + (nextarg++, va_arg(ap, type))) + + /* + * To extend shorts properly, we need both signed and unsigned + * argument extraction methods. + */ +#define SARG() \ + (flags&LONGINT ? GETARG(long) : \ + flags&SHORTINT ? (long)(short)GETARG(int) : \ + flags&CHARINT ? (long)(signed char)GETARG(int) : \ + (long)GETARG(int)) +#define UARG() \ + (flags&LONGINT ? GETARG(u_long) : \ + flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \ + flags&CHARINT ? (u_long)(u_char)GETARG(int) : \ + (u_long)GETARG(u_int)) +#define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT) +#define SJARG() \ + (flags&INTMAXT ? GETARG(intmax_t) : \ + flags&SIZET ? (intmax_t)GETARG(size_t) : \ + flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \ + (intmax_t)GETARG(long long)) +#define UJARG() \ + (flags&INTMAXT ? GETARG(uintmax_t) : \ + flags&SIZET ? (uintmax_t)GETARG(size_t) : \ + flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \ + (uintmax_t)GETARG(unsigned long long)) + + /* + * Get * arguments, including the form *nn$. Preserve the nextarg + * that the argument can be gotten once the type is determined. + */ +#define GETASTER(val) \ + n2 = 0; \ + cp = fmt; \ + while (is_digit(*cp)) { \ + n2 = 10 * n2 + to_digit(*cp); \ + cp++; \ + } \ + if (*cp == '$') { \ + int hold = nextarg; \ + if (argtable == NULL) { \ + argtable = statargtable; \ + __find_arguments (fmt0, orgap, &argtable); \ + } \ + nextarg = n2; \ + val = GETARG (int); \ + nextarg = hold; \ + fmt = ++cp; \ + } else { \ + val = GETARG (int); \ + } + + + thousands_sep = '\0'; + grouping = NULL; + convbuf = NULL; +#ifndef NO_FLOATING_POINT + dtoaresult = NULL; + decimal_point = localeconv()->decimal_point; +#endif + /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ + if (cantwrite(fp)) + return (EOF); + + /* optimise fprintf(stderr) (and other unbuffered Unix files) */ + if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && + fp->_file >= 0) + return (__sbprintf(fp, fmt0, ap)); + + fmt = (char *)fmt0; + argtable = NULL; + nextarg = 1; + va_copy(orgap, ap); + uio.uio_iov = iovp = iov; + uio.uio_resid = 0; + uio.uio_iovcnt = 0; + ret = 0; + + /* + * Scan the format for conversions (`%' character). + */ + for (;;) { + for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) + /* void */; + if ((n = fmt - cp) != 0) { + if ((unsigned)ret + n > INT_MAX) { + ret = EOF; + goto error; + } + PRINT(cp, n); + ret += n; + } + if (ch == '\0') + goto done; + fmt++; /* skip over '%' */ + + flags = 0; + dprec = 0; + width = 0; + prec = -1; + sign = '\0'; + ox[1] = '\0'; + +rflag: ch = *fmt++; +reswitch: switch (ch) { + case ' ': + /*- + * ``If the space and + flags both appear, the space + * flag will be ignored.'' + * -- ANSI X3J11 + */ + if (!sign) + sign = ' '; + goto rflag; + case '#': + flags |= ALT; + goto rflag; + case '*': + /*- + * ``A negative field width argument is taken as a + * - flag followed by a positive field width.'' + * -- ANSI X3J11 + * They don't exclude field widths read from args. + */ + GETASTER (width); + if (width >= 0) + goto rflag; + width = -width; + /* FALLTHROUGH */ + case '-': + flags |= LADJUST; + goto rflag; + case '+': + sign = '+'; + goto rflag; + case '\'': + flags |= GROUPING; + thousands_sep = *(localeconv()->thousands_sep); + grouping = localeconv()->grouping; + goto rflag; + case '.': + if ((ch = *fmt++) == '*') { + GETASTER (prec); + goto rflag; + } + prec = 0; + while (is_digit(ch)) { + prec = 10 * prec + to_digit(ch); + ch = *fmt++; + } + goto reswitch; + case '0': + /*- + * ``Note that 0 is taken as a flag, not as the + * beginning of a field width.'' + * -- ANSI X3J11 + */ + flags |= ZEROPAD; + goto rflag; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = 0; + do { + n = 10 * n + to_digit(ch); + ch = *fmt++; + } while (is_digit(ch)); + if (ch == '$') { + nextarg = n; + if (argtable == NULL) { + argtable = statargtable; + __find_arguments (fmt0, orgap, + &argtable); + } + goto rflag; + } + width = n; + goto reswitch; +#ifndef NO_FLOATING_POINT + case 'L': + flags |= LONGDBL; + goto rflag; +#endif + case 'h': + if (flags & SHORTINT) { + flags &= ~SHORTINT; + flags |= CHARINT; + } else + flags |= SHORTINT; + goto rflag; + case 'j': + flags |= INTMAXT; + goto rflag; + case 'l': + if (flags & LONGINT) { + flags &= ~LONGINT; + flags |= LLONGINT; + } else + flags |= LONGINT; + goto rflag; + case 'q': + flags |= LLONGINT; /* not necessarily */ + goto rflag; + case 't': + flags |= PTRDIFFT; + goto rflag; + case 'z': + flags |= SIZET; + goto rflag; + case 'C': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'c': + if (flags & LONGINT) { + static const mbstate_t initial; + mbstate_t mbs; + size_t mbseqlen; + + mbs = initial; + mbseqlen = wcrtomb(cp = buf, + (wchar_t)GETARG(wint_t), &mbs); + if (mbseqlen == (size_t)-1) { + fp->_flags |= __SERR; + goto error; + } + size = (int)mbseqlen; + } else { + *(cp = buf) = GETARG(int); + size = 1; + } + sign = '\0'; + break; + case 'D': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'd': + case 'i': + if (flags & INTMAX_SIZE) { + ujval = SJARG(); + if ((intmax_t)ujval < 0) { + ujval = -ujval; + sign = '-'; + } + } else { + ulval = SARG(); + if ((long)ulval < 0) { + ulval = -ulval; + sign = '-'; + } + } + base = 10; + goto number; +#ifndef NO_FLOATING_POINT + case 'a': + case 'A': + if (ch == 'a') { + ox[1] = 'x'; + xdigs = xdigs_lower; + expchar = 'p'; + } else { + ox[1] = 'X'; + xdigs = xdigs_upper; + expchar = 'P'; + } + if (prec >= 0) + prec++; + if (dtoaresult != NULL) + freedtoa(dtoaresult); + if (flags & LONGDBL) { + fparg.ldbl = GETARG(long double); + dtoaresult = cp = + __hldtoa(fparg.ldbl, xdigs, prec, + &expt, &signflag, &dtoaend); + } else { + fparg.dbl = GETARG(double); + dtoaresult = cp = + __hdtoa(fparg.dbl, xdigs, prec, + &expt, &signflag, &dtoaend); + } + if (prec < 0) + prec = dtoaend - cp; + if (expt == INT_MAX) + ox[1] = '\0'; + goto fp_common; + case 'e': + case 'E': + expchar = ch; + if (prec < 0) /* account for digit before decpt */ + prec = DEFPREC + 1; + else + prec++; + goto fp_begin; + case 'f': + case 'F': + expchar = '\0'; + goto fp_begin; + case 'g': + case 'G': + expchar = ch - ('g' - 'e'); + if (prec == 0) + prec = 1; +fp_begin: + if (prec < 0) + prec = DEFPREC; + if (dtoaresult != NULL) + freedtoa(dtoaresult); + if (flags & LONGDBL) { + fparg.ldbl = GETARG(long double); + dtoaresult = cp = + __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec, + &expt, &signflag, &dtoaend); + } else { + fparg.dbl = GETARG(double); + dtoaresult = cp = + dtoa(fparg.dbl, expchar ? 2 : 3, prec, + &expt, &signflag, &dtoaend); + if (expt == 9999) + expt = INT_MAX; + } +fp_common: + if (signflag) + sign = '-'; + if (expt == INT_MAX) { /* inf or nan */ + if (*cp == 'N') { + cp = (ch >= 'a') ? "nan" : "NAN"; + sign = '\0'; + } else + cp = (ch >= 'a') ? "inf" : "INF"; + size = 3; + break; + } + flags |= FPT; + ndig = dtoaend - cp; + if (ch == 'g' || ch == 'G') { + if (expt > -4 && expt <= prec) { + /* Make %[gG] smell like %[fF] */ + expchar = '\0'; + if (flags & ALT) + prec -= expt; + else + prec = ndig - expt; + if (prec < 0) + prec = 0; + } else { + /* + * Make %[gG] smell like %[eE], but + * trim trailing zeroes if no # flag. + */ + if (!(flags & ALT)) + prec = ndig; + } + } + if (expchar) { + expsize = exponent(expstr, expt - 1, expchar); + size = expsize + prec; + if (prec > 1 || flags & ALT) + ++size; + } else { + /* space for digits before decimal point */ + if (expt > 0) + size = expt; + else /* "0" */ + size = 1; + /* space for decimal pt and following digits */ + if (prec || flags & ALT) + size += prec + 1; + if (grouping && expt > 0) { + /* space for thousands' grouping */ + nseps = nrepeats = 0; + lead = expt; + while (*grouping != CHAR_MAX) { + if (lead <= *grouping) + break; + lead -= *grouping; + if (*(grouping+1)) { + nseps++; + grouping++; + } else + nrepeats++; + } + size += nseps + nrepeats; + } else + lead = expt; + } + break; +#endif /* !NO_FLOATING_POINT */ + case 'n': + /* + * Assignment-like behavior is specified if the + * value overflows or is otherwise unrepresentable. + * C99 says to use `signed char' for %hhn conversions. + */ + if (flags & LLONGINT) + *GETARG(long long *) = ret; + else if (flags & SIZET) + *GETARG(ssize_t *) = (ssize_t)ret; + else if (flags & PTRDIFFT) + *GETARG(ptrdiff_t *) = ret; + else if (flags & INTMAXT) + *GETARG(intmax_t *) = ret; + else if (flags & LONGINT) + *GETARG(long *) = ret; + else if (flags & SHORTINT) + *GETARG(short *) = ret; + else if (flags & CHARINT) + *GETARG(signed char *) = ret; + else + *GETARG(int *) = ret; + continue; /* no output */ + case 'O': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'o': + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 8; + goto nosign; + case 'p': + /*- + * ``The argument shall be a pointer to void. The + * value of the pointer is converted to a sequence + * of printable characters, in an implementation- + * defined manner.'' + * -- ANSI X3J11 + */ + ujval = (uintmax_t)(uintptr_t)GETARG(void *); + base = 16; + xdigs = xdigs_lower; + flags = flags | INTMAXT; + ox[1] = 'x'; + goto nosign; + case 'S': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 's': + if (flags & LONGINT) { + wchar_t *wcp; + + if (convbuf != NULL) + free(convbuf); + if ((wcp = GETARG(wchar_t *)) == NULL) + cp = "(null)"; + else { + convbuf = __wcsconv(wcp, prec); + if (convbuf == NULL) { + fp->_flags |= __SERR; + goto error; + } + cp = convbuf; + } + } else if ((cp = GETARG(char *)) == NULL) + cp = "(null)"; + if (prec >= 0) { + /* + * can't use strlen; can only look for the + * NUL in the first `prec' characters, and + * strlen() will go further. + */ + char *p = memchr(cp, 0, (size_t)prec); + + if (p != NULL) { + size = p - cp; + if (size > prec) + size = prec; + } else + size = prec; + } else + size = strlen(cp); + sign = '\0'; + break; + case 'U': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'u': + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 10; + goto nosign; + case 'X': + xdigs = xdigs_upper; + goto hex; + case 'x': + xdigs = xdigs_lower; +hex: + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 16; + /* leading 0x/X only if non-zero */ + if (flags & ALT && + (flags & INTMAX_SIZE ? ujval != 0 : ulval != 0)) + ox[1] = ch; + + flags &= ~GROUPING; + /* unsigned conversions */ +nosign: sign = '\0'; + /*- + * ``... diouXx conversions ... if a precision is + * specified, the 0 flag will be ignored.'' + * -- ANSI X3J11 + */ +number: if ((dprec = prec) >= 0) + flags &= ~ZEROPAD; + + /*- + * ``The result of converting a zero value with an + * explicit precision of zero is no characters.'' + * -- ANSI X3J11 + */ + cp = buf + BUF; + if (flags & INTMAX_SIZE) { + if (ujval != 0 || prec != 0) + cp = __ujtoa(ujval, cp, base, + flags & ALT, xdigs, + flags & GROUPING, thousands_sep, + grouping); + } else { + if (ulval != 0 || prec != 0) + cp = __ultoa(ulval, cp, base, + flags & ALT, xdigs, + flags & GROUPING, thousands_sep, + grouping); + } + size = buf + BUF - cp; + if (size > BUF) /* should never happen */ + abort(); + break; + default: /* "%?" prints ?, unless ? is NUL */ + if (ch == '\0') + goto done; + /* pretend it was %c with argument ch */ + cp = buf; + *cp = ch; + size = 1; + sign = '\0'; + break; + } + + /* + * All reasonable formats wind up here. At this point, `cp' + * points to a string which (if not flags&LADJUST) should be + * padded out to `width' places. If flags&ZEROPAD, it should + * first be prefixed by any sign or other prefix; otherwise, + * it should be blank padded before the prefix is emitted. + * After any left-hand padding and prefixing, emit zeroes + * required by a decimal [diouxX] precision, then print the + * string proper, then emit zeroes required by any leftover + * floating precision; finally, if LADJUST, pad with blanks. + * + * Compute actual size, so we know how much to pad. + * size excludes decimal prec; realsz includes it. + */ + realsz = dprec > size ? dprec : size; + if (sign) + realsz++; + if (ox[1]) + realsz += 2; + + prsize = width > realsz ? width : realsz; + if ((unsigned)ret + prsize > INT_MAX) { + ret = EOF; + goto error; + } + + /* right-adjusting blank padding */ + if ((flags & (LADJUST|ZEROPAD)) == 0) + PAD(width - realsz, blanks); + + /* prefix */ + if (sign) + PRINT(&sign, 1); + + if (ox[1]) { /* ox[1] is either x, X, or \0 */ + ox[0] = '0'; + PRINT(ox, 2); + } + + /* right-adjusting zero padding */ + if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) + PAD(width - realsz, zeroes); + + /* leading zeroes from decimal precision */ + PAD(dprec - size, zeroes); + + /* the string or number proper */ +#ifndef NO_FLOATING_POINT + if ((flags & FPT) == 0) { + PRINT(cp, size); + } else { /* glue together f_p fragments */ + if (!expchar) { /* %[fF] or sufficiently short %[gG] */ + if (expt <= 0) { + PRINT(zeroes, 1); + if (prec || flags & ALT) + PRINT(decimal_point, 1); + PAD(-expt, zeroes); + /* already handled initial 0's */ + prec += expt; + } else { + PRINTANDPAD(cp, dtoaend, lead, zeroes); + cp += lead; + if (grouping) { + while (nseps>0 || nrepeats>0) { + if (nrepeats > 0) + nrepeats--; + else { + grouping--; + nseps--; + } + PRINT(&thousands_sep, + 1); + PRINTANDPAD(cp,dtoaend, + *grouping, zeroes); + cp += *grouping; + } + if (cp > dtoaend) + cp = dtoaend; + } + if (prec || flags & ALT) + PRINT(decimal_point,1); + } + PRINTANDPAD(cp, dtoaend, prec, zeroes); + } else { /* %[eE] or sufficiently long %[gG] */ + if (prec > 1 || flags & ALT) { + buf[0] = *cp++; + buf[1] = *decimal_point; + PRINT(buf, 2); + PRINT(cp, ndig-1); + PAD(prec - ndig, zeroes); + } else /* XeYYY */ + PRINT(cp, 1); + PRINT(expstr, expsize); + } + } +#else + PRINT(cp, size); +#endif + /* left-adjusting padding (always blank) */ + if (flags & LADJUST) + PAD(width - realsz, blanks); + + /* finally, adjust ret */ + ret += prsize; + + FLUSH(); /* copy out the I/O vectors */ + } +done: + FLUSH(); +error: +#ifndef NO_FLOATING_POINT + if (dtoaresult != NULL) + freedtoa(dtoaresult); +#endif + if (convbuf != NULL) + free(convbuf); + if (__sferror(fp)) + ret = EOF; + if ((argtable != NULL) && (argtable != statargtable)) + free (argtable); + return (ret); + /* NOTREACHED */ +} + +/* + * Find all arguments when a positional parameter is encountered. Returns a + * table, indexed by argument number, of pointers to each arguments. The + * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. + * It will be replaces with a malloc-ed one if it overflows. + */ +static void +__find_arguments (const char *fmt0, va_list ap, union arg **argtable) +{ + char *fmt; /* format string */ + int ch; /* character from fmt */ + int n, n2; /* handy integer (short term usage) */ + char *cp; /* handy char pointer (short term usage) */ + int flags; /* flags as above */ + int width; /* width from format (%8d), or 0 */ + enum typeid *typetable; /* table of types */ + enum typeid stattypetable [STATIC_ARG_TBL_SIZE]; + int tablesize; /* current size of type table */ + int tablemax; /* largest used index in table */ + int nextarg; /* 1-based argument index */ + + /* + * Add an argument type to the table, expanding if necessary. + */ +#define ADDTYPE(type) \ + ((nextarg >= tablesize) ? \ + __grow_type_table(nextarg, &typetable, &tablesize) : 0, \ + (nextarg > tablemax) ? tablemax = nextarg : 0, \ + typetable[nextarg++] = type) + +#define ADDSARG() \ + ((flags&INTMAXT) ? ADDTYPE(T_INTMAXT) : \ + ((flags&SIZET) ? ADDTYPE(T_SIZET) : \ + ((flags&PTRDIFFT) ? ADDTYPE(T_PTRDIFFT) : \ + ((flags&LLONGINT) ? ADDTYPE(T_LLONG) : \ + ((flags&LONGINT) ? ADDTYPE(T_LONG) : ADDTYPE(T_INT)))))) + +#define ADDUARG() \ + ((flags&INTMAXT) ? ADDTYPE(T_UINTMAXT) : \ + ((flags&SIZET) ? ADDTYPE(T_SIZET) : \ + ((flags&PTRDIFFT) ? ADDTYPE(T_PTRDIFFT) : \ + ((flags&LLONGINT) ? ADDTYPE(T_U_LLONG) : \ + ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : ADDTYPE(T_U_INT)))))) + + /* + * Add * arguments to the type array. + */ +#define ADDASTER() \ + n2 = 0; \ + cp = fmt; \ + while (is_digit(*cp)) { \ + n2 = 10 * n2 + to_digit(*cp); \ + cp++; \ + } \ + if (*cp == '$') { \ + int hold = nextarg; \ + nextarg = n2; \ + ADDTYPE (T_INT); \ + nextarg = hold; \ + fmt = ++cp; \ + } else { \ + ADDTYPE (T_INT); \ + } + fmt = (char *)fmt0; + typetable = stattypetable; + tablesize = STATIC_ARG_TBL_SIZE; + tablemax = 0; + nextarg = 1; + for (n = 0; n < STATIC_ARG_TBL_SIZE; n++) + typetable[n] = T_UNUSED; + + /* + * Scan the format for conversions (`%' character). + */ + for (;;) { + for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) + /* void */; + if (ch == '\0') + goto done; + fmt++; /* skip over '%' */ + + flags = 0; + width = 0; + +rflag: ch = *fmt++; +reswitch: switch (ch) { + case ' ': + case '#': + goto rflag; + case '*': + ADDASTER (); + goto rflag; + case '-': + case '+': + case '\'': + goto rflag; + case '.': + if ((ch = *fmt++) == '*') { + ADDASTER (); + goto rflag; + } + while (is_digit(ch)) { + ch = *fmt++; + } + goto reswitch; + case '0': + goto rflag; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = 0; + do { + n = 10 * n + to_digit(ch); + ch = *fmt++; + } while (is_digit(ch)); + if (ch == '$') { + nextarg = n; + goto rflag; + } + width = n; + goto reswitch; +#ifndef NO_FLOATING_POINT + case 'L': + flags |= LONGDBL; + goto rflag; +#endif + case 'h': + if (flags & SHORTINT) { + flags &= ~SHORTINT; + flags |= CHARINT; + } else + flags |= SHORTINT; + goto rflag; + case 'j': + flags |= INTMAXT; + goto rflag; + case 'l': + if (flags & LONGINT) { + flags &= ~LONGINT; + flags |= LLONGINT; + } else + flags |= LONGINT; + goto rflag; + case 'q': + flags |= LLONGINT; /* not necessarily */ + goto rflag; + case 't': + flags |= PTRDIFFT; + goto rflag; + case 'z': + flags |= SIZET; + goto rflag; + case 'C': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'c': + if (flags & LONGINT) + ADDTYPE(T_WINT); + else + ADDTYPE(T_INT); + break; + case 'D': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'd': + case 'i': + ADDSARG(); + break; +#ifndef NO_FLOATING_POINT + case 'a': + case 'A': + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + if (flags & LONGDBL) + ADDTYPE(T_LONG_DOUBLE); + else + ADDTYPE(T_DOUBLE); + break; +#endif /* !NO_FLOATING_POINT */ + case 'n': + if (flags & INTMAXT) + ADDTYPE(TP_INTMAXT); + else if (flags & PTRDIFFT) + ADDTYPE(TP_PTRDIFFT); + else if (flags & SIZET) + ADDTYPE(TP_SIZET); + else if (flags & LLONGINT) + ADDTYPE(TP_LLONG); + else if (flags & LONGINT) + ADDTYPE(TP_LONG); + else if (flags & SHORTINT) + ADDTYPE(TP_SHORT); + else if (flags & CHARINT) + ADDTYPE(TP_SCHAR); + else + ADDTYPE(TP_INT); + continue; /* no output */ + case 'O': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'o': + ADDUARG(); + break; + case 'p': + ADDTYPE(TP_VOID); + break; + case 'S': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 's': + if (flags & LONGINT) + ADDTYPE(TP_WCHAR); + else + ADDTYPE(TP_CHAR); + break; + case 'U': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'u': + case 'X': + case 'x': + ADDUARG(); + break; + default: /* "%?" prints ?, unless ? is NUL */ + if (ch == '\0') + goto done; + break; + } + } +done: + /* + * Build the argument table. + */ + if (tablemax >= STATIC_ARG_TBL_SIZE) { + *argtable = (union arg *) + malloc (sizeof (union arg) * (tablemax + 1)); + } + + (*argtable) [0].intarg = 0; + for (n = 1; n <= tablemax; n++) { + switch (typetable [n]) { + case T_UNUSED: /* whoops! */ + (*argtable) [n].intarg = va_arg (ap, int); + break; + case TP_SCHAR: + (*argtable) [n].pschararg = va_arg (ap, signed char *); + break; + case TP_SHORT: + (*argtable) [n].pshortarg = va_arg (ap, short *); + break; + case T_INT: + (*argtable) [n].intarg = va_arg (ap, int); + break; + case T_U_INT: + (*argtable) [n].uintarg = va_arg (ap, unsigned int); + break; + case TP_INT: + (*argtable) [n].pintarg = va_arg (ap, int *); + break; + case T_LONG: + (*argtable) [n].longarg = va_arg (ap, long); + break; + case T_U_LONG: + (*argtable) [n].ulongarg = va_arg (ap, unsigned long); + break; + case TP_LONG: + (*argtable) [n].plongarg = va_arg (ap, long *); + break; + case T_LLONG: + (*argtable) [n].longlongarg = va_arg (ap, long long); + break; + case T_U_LLONG: + (*argtable) [n].ulonglongarg = va_arg (ap, unsigned long long); + break; + case TP_LLONG: + (*argtable) [n].plonglongarg = va_arg (ap, long long *); + break; + case T_PTRDIFFT: + (*argtable) [n].ptrdiffarg = va_arg (ap, ptrdiff_t); + break; + case TP_PTRDIFFT: + (*argtable) [n].pptrdiffarg = va_arg (ap, ptrdiff_t *); + break; + case T_SIZET: + (*argtable) [n].sizearg = va_arg (ap, size_t); + break; + case TP_SIZET: + (*argtable) [n].psizearg = va_arg (ap, ssize_t *); + break; + case T_INTMAXT: + (*argtable) [n].intmaxarg = va_arg (ap, intmax_t); + break; + case T_UINTMAXT: + (*argtable) [n].uintmaxarg = va_arg (ap, uintmax_t); + break; + case TP_INTMAXT: + (*argtable) [n].pintmaxarg = va_arg (ap, intmax_t *); + break; +#ifndef NO_FLOATING_POINT + case T_DOUBLE: + (*argtable) [n].doublearg = va_arg (ap, double); + break; + case T_LONG_DOUBLE: + (*argtable) [n].longdoublearg = va_arg (ap, long double); + break; +#endif + case TP_CHAR: + (*argtable) [n].pchararg = va_arg (ap, char *); + break; + case TP_VOID: + (*argtable) [n].pvoidarg = va_arg (ap, void *); + break; + case T_WINT: + (*argtable) [n].wintarg = va_arg (ap, wint_t); + break; + case TP_WCHAR: + (*argtable) [n].pwchararg = va_arg (ap, wchar_t *); + break; + } + } + + if ((typetable != NULL) && (typetable != stattypetable)) + free (typetable); +} + +/* + * Increase the size of the type table. + */ +static void +__grow_type_table (int nextarg, enum typeid **typetable, int *tablesize) +{ + enum typeid *const oldtable = *typetable; + const int oldsize = *tablesize; + enum typeid *newtable; + int n, newsize = oldsize * 2; + + if (newsize < nextarg + 1) + newsize = nextarg + 1; + if (oldsize == STATIC_ARG_TBL_SIZE) { + if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL) + abort(); /* XXX handle better */ + bcopy(oldtable, newtable, oldsize * sizeof(enum typeid)); + } else { + newtable = reallocf(oldtable, newsize * sizeof(enum typeid)); + if (newtable == NULL) + abort(); /* XXX handle better */ + } + for (n = oldsize; n < newsize; n++) + newtable[n] = T_UNUSED; + + *typetable = newtable; + *tablesize = newsize; +} + + +#ifndef NO_FLOATING_POINT + +static int +exponent(char *p0, int exp, int fmtch) +{ + char *p, *t; + char expbuf[MAXEXPDIG]; + + p = p0; + *p++ = fmtch; + if (exp < 0) { + exp = -exp; + *p++ = '-'; + } + else + *p++ = '+'; + t = expbuf + MAXEXPDIG; + if (exp > 9) { + do { + *--t = to_char(exp % 10); + } while ((exp /= 10) > 9); + *--t = to_char(exp); + for (; t < expbuf + MAXEXPDIG; *p++ = *t++); + } + else { + /* + * Exponents for decimal floating point conversions + * (%[eEgG]) must be at least two characters long, + * whereas exponents for hexadecimal conversions can + * be only one character long. + */ + if (fmtch == 'e' || fmtch == 'E') + *p++ = '0'; + *p++ = to_char(exp); + } + return (p - p0); +} +#endif /* !NO_FLOATING_POINT */ diff --git a/src/lib/libc/stdio/vfscanf.c b/src/lib/libc/stdio/vfscanf.c new file mode 100644 index 0000000..154602d --- /dev/null +++ b/src/lib/libc/stdio/vfscanf.c @@ -0,0 +1,1068 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.37 2004/05/02 10:55:05 das Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "collate.h" +#include "libc_private.h" +#include "local.h" + +#ifndef NO_FLOATING_POINT +#include +#endif + +#define BUF 513 /* Maximum length of numeric string. */ + +/* + * Flags used during conversion. + */ +#define LONG 0x01 /* l: long or double */ +#define LONGDBL 0x02 /* L: long double */ +#define SHORT 0x04 /* h: short */ +#define SUPPRESS 0x08 /* *: suppress assignment */ +#define POINTER 0x10 /* p: void * (as hex) */ +#define NOSKIP 0x20 /* [ or c: do not skip blanks */ +#define LONGLONG 0x400 /* ll: long long (+ deprecated q: quad) */ +#define INTMAXT 0x800 /* j: intmax_t */ +#define PTRDIFFT 0x1000 /* t: ptrdiff_t */ +#define SIZET 0x2000 /* z: size_t */ +#define SHORTSHORT 0x4000 /* hh: char */ +#define UNSIGNED 0x8000 /* %[oupxX] conversions */ + +/* + * The following are used in integral conversions only: + * SIGNOK, NDIGITS, PFXOK, and NZDIGITS + */ +#define SIGNOK 0x40 /* +/- is (still) legal */ +#define NDIGITS 0x80 /* no digits detected */ +#define PFXOK 0x100 /* 0x prefix is (still) legal */ +#define NZDIGITS 0x200 /* no zero digits detected */ +#define HAVESIGN 0x10000 /* sign detected */ + +/* + * Conversion types. + */ +#define CT_CHAR 0 /* %c conversion */ +#define CT_CCL 1 /* %[...] conversion */ +#define CT_STRING 2 /* %s conversion */ +#define CT_INT 3 /* %[dioupxX] conversion */ +#define CT_FLOAT 4 /* %[efgEFG] conversion */ + +static const u_char *__sccl(char *, const u_char *); +static int parsefloat(FILE *, char *, char *); + +int __scanfdebug = 0; + +__weak_reference(__vfscanf, vfscanf); + +/* + * __vfscanf - MT-safe version + */ +int +__vfscanf(FILE *fp, char const *fmt0, va_list ap) +{ + int ret; + + FLOCKFILE(fp); + ret = __svfscanf(fp, fmt0, ap); + FUNLOCKFILE(fp); + return (ret); +} + +/* + * __svfscanf - non-MT-safe version of __vfscanf + */ +int +__svfscanf(FILE *fp, const char *fmt0, va_list ap) +{ + const u_char *fmt = (const u_char *)fmt0; + int c; /* character from format, or conversion */ + size_t width; /* field width, or 0 */ + char *p; /* points into all kinds of strings */ + int n; /* handy integer */ + int flags; /* flags as defined above */ + char *p0; /* saves original value of p when necessary */ + int nassigned; /* number of fields assigned */ + int nconversions; /* number of conversions */ + int nread; /* number of characters consumed from fp */ + int base; /* base argument to conversion function */ + char ccltab[256]; /* character class table for %[...] */ + char buf[BUF]; /* buffer for numeric and mb conversions */ + wchar_t *wcp; /* handy wide character pointer */ + wchar_t *wcp0; /* saves original value of wcp */ + size_t nconv; /* length of multibyte sequence converted */ + static const mbstate_t initial; + mbstate_t mbs; + + /* `basefix' is used to avoid `if' tests in the integer scanner */ + static short basefix[17] = + { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + ORIENT(fp, -1); + + nassigned = 0; + nconversions = 0; + nread = 0; + for (;;) { + c = *fmt++; + if (c == 0) + return (nassigned); + if (isspace(c)) { + while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p)) + nread++, fp->_r--, fp->_p++; + continue; + } + if (c != '%') + goto literal; + width = 0; + flags = 0; + /* + * switch on the format. continue if done; + * break once format type is derived. + */ +again: c = *fmt++; + switch (c) { + case '%': +literal: + if (fp->_r <= 0 && __srefill(fp)) + goto input_failure; + if (*fp->_p != c) + goto match_failure; + fp->_r--, fp->_p++; + nread++; + continue; + + case '*': + flags |= SUPPRESS; + goto again; + case 'j': + flags |= INTMAXT; + goto again; + case 'l': + if (flags & LONG) { + flags &= ~LONG; + flags |= LONGLONG; + } else + flags |= LONG; + goto again; + case 'q': + flags |= LONGLONG; /* not quite */ + goto again; + case 't': + flags |= PTRDIFFT; + goto again; + case 'z': + flags |= SIZET; + goto again; + case 'L': + flags |= LONGDBL; + goto again; + case 'h': + if (flags & SHORT) { + flags &= ~SHORT; + flags |= SHORTSHORT; + } else + flags |= SHORT; + goto again; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + width = width * 10 + c - '0'; + goto again; + + /* + * Conversions. + */ + case 'd': + c = CT_INT; + base = 10; + break; + + case 'i': + c = CT_INT; + base = 0; + break; + + case 'o': + c = CT_INT; + flags |= UNSIGNED; + base = 8; + break; + + case 'u': + c = CT_INT; + flags |= UNSIGNED; + base = 10; + break; + + case 'X': + case 'x': + flags |= PFXOK; /* enable 0x prefixing */ + c = CT_INT; + flags |= UNSIGNED; + base = 16; + break; + +#ifndef NO_FLOATING_POINT + case 'A': case 'E': case 'F': case 'G': + case 'a': case 'e': case 'f': case 'g': + c = CT_FLOAT; + break; +#endif + + case 'S': + flags |= LONG; + /* FALLTHROUGH */ + case 's': + c = CT_STRING; + break; + + case '[': + fmt = __sccl(ccltab, fmt); + flags |= NOSKIP; + c = CT_CCL; + break; + + case 'C': + flags |= LONG; + /* FALLTHROUGH */ + case 'c': + flags |= NOSKIP; + c = CT_CHAR; + break; + + case 'p': /* pointer format is like hex */ + flags |= POINTER | PFXOK; + c = CT_INT; /* assumes sizeof(uintmax_t) */ + flags |= UNSIGNED; /* >= sizeof(uintptr_t) */ + base = 16; + break; + + case 'n': + nconversions++; + if (flags & SUPPRESS) /* ??? */ + continue; + if (flags & SHORTSHORT) + *va_arg(ap, char *) = nread; + else if (flags & SHORT) + *va_arg(ap, short *) = nread; + else if (flags & LONG) + *va_arg(ap, long *) = nread; + else if (flags & LONGLONG) + *va_arg(ap, long long *) = nread; + else if (flags & INTMAXT) + *va_arg(ap, intmax_t *) = nread; + else if (flags & SIZET) + *va_arg(ap, size_t *) = nread; + else if (flags & PTRDIFFT) + *va_arg(ap, ptrdiff_t *) = nread; + else + *va_arg(ap, int *) = nread; + continue; + + default: + goto match_failure; + + /* + * Disgusting backwards compatibility hack. XXX + */ + case '\0': /* compat */ + return (EOF); + } + + /* + * We have a conversion that requires input. + */ + if (fp->_r <= 0 && __srefill(fp)) + goto input_failure; + + /* + * Consume leading white space, except for formats + * that suppress this. + */ + if ((flags & NOSKIP) == 0) { + while (isspace(*fp->_p)) { + nread++; + if (--fp->_r > 0) + fp->_p++; + else if (__srefill(fp)) + goto input_failure; + } + /* + * Note that there is at least one character in + * the buffer, so conversions that do not set NOSKIP + * ca no longer result in an input failure. + */ + } + + /* + * Do the conversion. + */ + switch (c) { + + case CT_CHAR: + /* scan arbitrary characters (sets NOSKIP) */ + if (width == 0) + width = 1; + if (flags & LONG) { + if ((flags & SUPPRESS) == 0) + wcp = va_arg(ap, wchar_t *); + else + wcp = NULL; + n = 0; + while (width != 0) { + if (n == MB_CUR_MAX) { + fp->_flags |= __SERR; + goto input_failure; + } + buf[n++] = *fp->_p; + fp->_p++; + fp->_r--; + mbs = initial; + nconv = mbrtowc(wcp, buf, n, &mbs); + if (nconv == (size_t)-1) { + fp->_flags |= __SERR; + goto input_failure; + } + if (nconv == 0 && !(flags & SUPPRESS)) + *wcp = L'\0'; + if (nconv != (size_t)-2) { + nread += n; + width--; + if (!(flags & SUPPRESS)) + wcp++; + n = 0; + } + if (fp->_r <= 0 && __srefill(fp)) { + if (n != 0) { + fp->_flags |= __SERR; + goto input_failure; + } + break; + } + } + if (!(flags & SUPPRESS)) + nassigned++; + } else if (flags & SUPPRESS) { + size_t sum = 0; + for (;;) { + if ((n = fp->_r) < width) { + sum += n; + width -= n; + fp->_p += n; + if (__srefill(fp)) { + if (sum == 0) + goto input_failure; + break; + } + } else { + sum += width; + fp->_r -= width; + fp->_p += width; + break; + } + } + nread += sum; + } else { + size_t r = fread((void *)va_arg(ap, char *), 1, + width, fp); + + if (r == 0) + goto input_failure; + nread += r; + nassigned++; + } + nconversions++; + break; + + case CT_CCL: + /* scan a (nonempty) character class (sets NOSKIP) */ + if (width == 0) + width = (size_t)~0; /* `infinity' */ + /* take only those things in the class */ + if (flags & LONG) { + wchar_t twc; + int nchars; + + if ((flags & SUPPRESS) == 0) + wcp = wcp0 = va_arg(ap, wchar_t *); + else + wcp = wcp0 = &twc; + n = 0; + nchars = 0; + while (width != 0) { + if (n == MB_CUR_MAX) { + fp->_flags |= __SERR; + goto input_failure; + } + buf[n++] = *fp->_p; + fp->_p++; + fp->_r--; + mbs = initial; + nconv = mbrtowc(wcp, buf, n, &mbs); + if (nconv == (size_t)-1) { + fp->_flags |= __SERR; + goto input_failure; + } + if (nconv == 0) + *wcp = L'\0'; + if (nconv != (size_t)-2) { + if (wctob(*wcp) != EOF && + !ccltab[wctob(*wcp)]) { + while (n != 0) { + n--; + __ungetc(buf[n], + fp); + } + break; + } + nread += n; + width--; + if (!(flags & SUPPRESS)) + wcp++; + nchars++; + n = 0; + } + if (fp->_r <= 0 && __srefill(fp)) { + if (n != 0) { + fp->_flags |= __SERR; + goto input_failure; + } + break; + } + } + if (n != 0) { + fp->_flags |= __SERR; + goto input_failure; + } + n = nchars; + if (n == 0) + goto match_failure; + if (!(flags & SUPPRESS)) { + *wcp = L'\0'; + nassigned++; + } + } else if (flags & SUPPRESS) { + n = 0; + while (ccltab[*fp->_p]) { + n++, fp->_r--, fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) { + if (n == 0) + goto input_failure; + break; + } + } + if (n == 0) + goto match_failure; + } else { + p0 = p = va_arg(ap, char *); + while (ccltab[*fp->_p]) { + fp->_r--; + *p++ = *fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) { + if (p == p0) + goto input_failure; + break; + } + } + n = p - p0; + if (n == 0) + goto match_failure; + *p = 0; + nassigned++; + } + nread += n; + nconversions++; + break; + + case CT_STRING: + /* like CCL, but zero-length string OK, & no NOSKIP */ + if (width == 0) + width = (size_t)~0; + if (flags & LONG) { + wchar_t twc; + + if ((flags & SUPPRESS) == 0) + wcp = va_arg(ap, wchar_t *); + else + wcp = &twc; + n = 0; + while (!isspace(*fp->_p) && width != 0) { + if (n == MB_CUR_MAX) { + fp->_flags |= __SERR; + goto input_failure; + } + buf[n++] = *fp->_p; + fp->_p++; + fp->_r--; + mbs = initial; + nconv = mbrtowc(wcp, buf, n, &mbs); + if (nconv == (size_t)-1) { + fp->_flags |= __SERR; + goto input_failure; + } + if (nconv == 0) + *wcp = L'\0'; + if (nconv != (size_t)-2) { + if (iswspace(*wcp)) { + while (n != 0) { + n--; + __ungetc(buf[n], + fp); + } + break; + } + nread += n; + width--; + if (!(flags & SUPPRESS)) + wcp++; + n = 0; + } + if (fp->_r <= 0 && __srefill(fp)) { + if (n != 0) { + fp->_flags |= __SERR; + goto input_failure; + } + break; + } + } + if (!(flags & SUPPRESS)) { + *wcp = L'\0'; + nassigned++; + } + } else if (flags & SUPPRESS) { + n = 0; + while (!isspace(*fp->_p)) { + n++, fp->_r--, fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) + break; + } + nread += n; + } else { + p0 = p = va_arg(ap, char *); + while (!isspace(*fp->_p)) { + fp->_r--; + *p++ = *fp->_p++; + if (--width == 0) + break; + if (fp->_r <= 0 && __srefill(fp)) + break; + } + *p = 0; + nread += p - p0; + nassigned++; + } + nconversions++; + continue; + + case CT_INT: + /* scan an integer as if by the conversion function */ +#ifdef hardway + if (width == 0 || width > sizeof(buf) - 1) + width = sizeof(buf) - 1; +#else + /* size_t is unsigned, hence this optimisation */ + if (--width > sizeof(buf) - 2) + width = sizeof(buf) - 2; + width++; +#endif + flags |= SIGNOK | NDIGITS | NZDIGITS; + for (p = buf; width; width--) { + c = *fp->_p; + /* + * Switch on the character; `goto ok' + * if we accept it as a part of number. + */ + switch (c) { + + /* + * The digit 0 is always legal, but is + * special. For %i conversions, if no + * digits (zero or nonzero) have been + * scanned (only signs), we will have + * base==0. In that case, we should set + * it to 8 and enable 0x prefixing. + * Also, if we have not scanned zero digits + * before this, do not turn off prefixing + * (someone else will turn it off if we + * have scanned any nonzero digits). + */ + case '0': + if (base == 0) { + base = 8; + flags |= PFXOK; + } + if (flags & NZDIGITS) + flags &= ~(SIGNOK|NZDIGITS|NDIGITS); + else + flags &= ~(SIGNOK|PFXOK|NDIGITS); + goto ok; + + /* 1 through 7 always legal */ + case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + base = basefix[base]; + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* digits 8 and 9 ok iff decimal or hex */ + case '8': case '9': + base = basefix[base]; + if (base <= 8) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* letters ok iff hex */ + case 'A': case 'B': case 'C': + case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': + case 'd': case 'e': case 'f': + /* no need to fix base here */ + if (base <= 10) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* sign ok only as first character */ + case '+': case '-': + if (flags & SIGNOK) { + flags &= ~SIGNOK; + flags |= HAVESIGN; + goto ok; + } + break; + + /* + * x ok iff flag still set & 2nd char (or + * 3rd char if we have a sign). + */ + case 'x': case 'X': + if (flags & PFXOK && p == + buf + 1 + !!(flags & HAVESIGN)) { + base = 16; /* if %i */ + flags &= ~PFXOK; + goto ok; + } + break; + } + + /* + * If we got here, c is not a legal character + * for a number. Stop accumulating digits. + */ + break; + ok: + /* + * c is legal: store it and look at the next. + */ + *p++ = c; + if (--fp->_r > 0) + fp->_p++; + else if (__srefill(fp)) + break; /* EOF */ + } + /* + * If we had only a sign, it is no good; push + * back the sign. If the number ends in `x', + * it was [sign] '0' 'x', so push back the x + * and treat it as [sign] '0'. + */ + if (flags & NDIGITS) { + if (p > buf) + (void) __ungetc(*(u_char *)--p, fp); + goto match_failure; + } + c = ((u_char *)p)[-1]; + if (c == 'x' || c == 'X') { + --p; + (void) __ungetc(c, fp); + } + if ((flags & SUPPRESS) == 0) { + uintmax_t res; + + *p = 0; + if ((flags & UNSIGNED) == 0) + res = strtoimax(buf, (char **)NULL, base); + else + res = strtoumax(buf, (char **)NULL, base); + if (flags & POINTER) + *va_arg(ap, void **) = + (void *)(uintptr_t)res; + else if (flags & SHORTSHORT) + *va_arg(ap, char *) = res; + else if (flags & SHORT) + *va_arg(ap, short *) = res; + else if (flags & LONG) + *va_arg(ap, long *) = res; + else if (flags & LONGLONG) + *va_arg(ap, long long *) = res; + else if (flags & INTMAXT) + *va_arg(ap, intmax_t *) = res; + else if (flags & PTRDIFFT) + *va_arg(ap, ptrdiff_t *) = res; + else if (flags & SIZET) + *va_arg(ap, size_t *) = res; + else + *va_arg(ap, int *) = res; + nassigned++; + } + nread += p - buf; + nconversions++; + break; + +#ifndef NO_FLOATING_POINT + case CT_FLOAT: + /* scan a floating point number as if by strtod */ + if (width == 0 || width > sizeof(buf) - 1) + width = sizeof(buf) - 1; + if ((width = parsefloat(fp, buf, buf + width)) == 0) + goto match_failure; + if ((flags & SUPPRESS) == 0) { + if (flags & LONGDBL) { + long double res = strtold(buf, &p); + *va_arg(ap, long double *) = res; + } else if (flags & LONG) { + double res = strtod(buf, &p); + *va_arg(ap, double *) = res; + } else { + float res = strtof(buf, &p); + *va_arg(ap, float *) = res; + } + if (__scanfdebug && p - buf != width) + abort(); + nassigned++; + } + nread += width; + nconversions++; + break; +#endif /* !NO_FLOATING_POINT */ + } + } +input_failure: + return (nconversions != 0 ? nassigned : EOF); +match_failure: + return (nassigned); +} + +/* + * Fill in the given table from the scanset at the given format + * (just after `['). Return a pointer to the character past the + * closing `]'. The table has a 1 wherever characters should be + * considered part of the scanset. + */ +static const u_char * +__sccl(tab, fmt) + char *tab; + const u_char *fmt; +{ + int c, n, v, i; + + /* first `clear' the whole table */ + c = *fmt++; /* first char hat => negated scanset */ + if (c == '^') { + v = 1; /* default => accept */ + c = *fmt++; /* get new first char */ + } else + v = 0; /* default => reject */ + + /* XXX: Will not work if sizeof(tab*) > sizeof(char) */ + (void) memset(tab, v, 256); + + if (c == 0) + return (fmt - 1);/* format ended before closing ] */ + + /* + * Now set the entries corresponding to the actual scanset + * to the opposite of the above. + * + * The first character may be ']' (or '-') without being special; + * the last character may be '-'. + */ + v = 1 - v; + for (;;) { + tab[c] = v; /* take character c */ +doswitch: + n = *fmt++; /* and examine the next */ + switch (n) { + + case 0: /* format ended too soon */ + return (fmt - 1); + + case '-': + /* + * A scanset of the form + * [01+-] + * is defined as `the digit 0, the digit 1, + * the character +, the character -', but + * the effect of a scanset such as + * [a-zA-Z0-9] + * is implementation defined. The V7 Unix + * scanf treats `a-z' as `the letters a through + * z', but treats `a-a' as `the letter a, the + * character -, and the letter a'. + * + * For compatibility, the `-' is not considerd + * to define a range if the character following + * it is either a close bracket (required by ANSI) + * or is not numerically greater than the character + * we just stored in the table (c). + */ + n = *fmt; + if (n == ']' + || (__collate_load_error ? n < c : + __collate_range_cmp (n, c) < 0 + ) + ) { + c = '-'; + break; /* resume the for(;;) */ + } + fmt++; + /* fill in the range */ + if (__collate_load_error) { + do { + tab[++c] = v; + } while (c < n); + } else { + for (i = 0; i < 256; i ++) + if ( __collate_range_cmp (c, i) < 0 + && __collate_range_cmp (i, n) <= 0 + ) + tab[i] = v; + } +#if 1 /* XXX another disgusting compatibility hack */ + c = n; + /* + * Alas, the V7 Unix scanf also treats formats + * such as [a-c-e] as `the letters a through e'. + * This too is permitted by the standard.... + */ + goto doswitch; +#else + c = *fmt++; + if (c == 0) + return (fmt - 1); + if (c == ']') + return (fmt); +#endif + break; + + case ']': /* end of scanset */ + return (fmt); + + default: /* just another character */ + c = n; + break; + } + } + /* NOTREACHED */ +} + +#ifndef NO_FLOATING_POINT +static int +parsefloat(FILE *fp, char *buf, char *end) +{ + char *commit, *p; + int infnanpos = 0; + enum { + S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX, + S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS + } state = S_START; + unsigned char c; + char decpt = *localeconv()->decimal_point; + _Bool gotmantdig = 0, ishex = 0; + + /* + * We set commit = p whenever the string we have read so far + * constitutes a valid representation of a floating point + * number by itself. At some point, the parse will complete + * or fail, and we will ungetc() back to the last commit point. + * To ensure that the file offset gets updated properly, it is + * always necessary to read at least one character that doesn't + * match; thus, we can't short-circuit "infinity" or "nan(...)". + */ + commit = buf - 1; + for (p = buf; p < end; ) { + c = *fp->_p; +reswitch: + switch (state) { + case S_START: + state = S_GOTSIGN; + if (c == '-' || c == '+') + break; + else + goto reswitch; + case S_GOTSIGN: + switch (c) { + case '0': + state = S_MAYBEHEX; + commit = p; + break; + case 'I': + case 'i': + state = S_INF; + break; + case 'N': + case 'n': + state = S_NAN; + break; + default: + state = S_DIGITS; + goto reswitch; + } + break; + case S_INF: + if (infnanpos > 6 || + (c != "nfinity"[infnanpos] && + c != "NFINITY"[infnanpos])) + goto parsedone; + if (infnanpos == 1 || infnanpos == 6) + commit = p; /* inf or infinity */ + infnanpos++; + break; + case S_NAN: + switch (infnanpos) { + case -1: /* XXX kludge to deal with nan(...) */ + goto parsedone; + case 0: + if (c != 'A' && c != 'a') + goto parsedone; + break; + case 1: + if (c != 'N' && c != 'n') + goto parsedone; + else + commit = p; + break; + case 2: + if (c != '(') + goto parsedone; + break; + default: + if (c == ')') { + commit = p; + infnanpos = -2; + } else if (!isalnum(c) && c != '_') + goto parsedone; + break; + } + infnanpos++; + break; + case S_MAYBEHEX: + state = S_DIGITS; + if (c == 'X' || c == 'x') { + ishex = 1; + break; + } else { /* we saw a '0', but no 'x' */ + gotmantdig = 1; + goto reswitch; + } + case S_DIGITS: + if ((ishex && isxdigit(c)) || isdigit(c)) + gotmantdig = 1; + else { + state = S_FRAC; + if (c != decpt) + goto reswitch; + } + if (gotmantdig) + commit = p; + break; + case S_FRAC: + if (((c == 'E' || c == 'e') && !ishex) || + ((c == 'P' || c == 'p') && ishex)) { + if (!gotmantdig) + goto parsedone; + else + state = S_EXP; + } else if ((ishex && isxdigit(c)) || isdigit(c)) { + commit = p; + gotmantdig = 1; + } else + goto parsedone; + break; + case S_EXP: + state = S_EXPDIGITS; + if (c == '-' || c == '+') + break; + else + goto reswitch; + case S_EXPDIGITS: + if (isdigit(c)) + commit = p; + else + goto parsedone; + break; + default: + abort(); + } + *p++ = c; + if (--fp->_r > 0) + fp->_p++; + else if (__srefill(fp)) + break; /* EOF */ + } + +parsedone: + while (commit < --p) + __ungetc(*(u_char *)p, fp); + *++commit = '\0'; + return (commit - buf); +} +#endif diff --git a/src/lib/libc/stdio/vfwprintf.c b/src/lib/libc/stdio/vfwprintf.c new file mode 100644 index 0000000..f1934b1 --- /dev/null +++ b/src/lib/libc/stdio/vfwprintf.c @@ -0,0 +1,1639 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.20 2004/05/02 20:09:14 obrien Exp $"); + +/* + * Actual wprintf innards. + * + * Avoid making gratuitous changes to this source file; it should be kept + * as close as possible to vfprintf.c for ease of maintenance. + */ + +#include "namespace.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" +#include "local.h" +#include "fvwrite.h" + +union arg { + int intarg; + u_int uintarg; + long longarg; + u_long ulongarg; + long long longlongarg; + unsigned long long ulonglongarg; + ptrdiff_t ptrdiffarg; + size_t sizearg; + intmax_t intmaxarg; + uintmax_t uintmaxarg; + void *pvoidarg; + char *pchararg; + signed char *pschararg; + short *pshortarg; + int *pintarg; + long *plongarg; + long long *plonglongarg; + ptrdiff_t *pptrdiffarg; + size_t *psizearg; + intmax_t *pintmaxarg; +#ifndef NO_FLOATING_POINT + double doublearg; + long double longdoublearg; +#endif + wint_t wintarg; + wchar_t *pwchararg; +}; + +/* + * Type ids for argument type table. + */ +enum typeid { + T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT, + T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG, + T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET, + T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR, + T_DOUBLE, T_LONG_DOUBLE, T_WINT, TP_WCHAR +}; + +static int __sbprintf(FILE *, const wchar_t *, va_list); +static wint_t __xfputwc(wchar_t, FILE *); +static wchar_t *__ujtoa(uintmax_t, wchar_t *, int, int, const char *, int, + char, const char *); +static wchar_t *__ultoa(u_long, wchar_t *, int, int, const char *, int, + char, const char *); +static wchar_t *__mbsconv(char *, int); +static void __find_arguments(const wchar_t *, va_list, union arg **); +static void __grow_type_table(int, enum typeid **, int *); + +/* + * Helper function for `fprintf to unbuffered unix file': creates a + * temporary buffer. We only work on write-only files; this avoids + * worries about ungetc buffers and so forth. + */ +static int +__sbprintf(FILE *fp, const wchar_t *fmt, va_list ap) +{ + int ret; + FILE fake; + unsigned char buf[BUFSIZ]; + + /* copy the important variables */ + fake._flags = fp->_flags & ~__SNBF; + fake._file = fp->_file; + fake._cookie = fp->_cookie; + fake._write = fp->_write; + fake._extra = fp->_extra; + + /* set up the buffer */ + fake._bf._base = fake._p = buf; + fake._bf._size = fake._w = sizeof(buf); + fake._lbfsize = 0; /* not actually used, but Just In Case */ + + /* do the work, then copy any error status */ + ret = __vfwprintf(&fake, fmt, ap); + if (ret >= 0 && __fflush(&fake)) + ret = WEOF; + if (fake._flags & __SERR) + fp->_flags |= __SERR; + return (ret); +} + +/* + * Like __fputwc, but handles fake string (__SSTR) files properly. + * File must already be locked. + */ +static wint_t +__xfputwc(wchar_t wc, FILE *fp) +{ + static const mbstate_t initial; + mbstate_t mbs; + char buf[MB_LEN_MAX]; + struct __suio uio; + struct __siov iov; + size_t len; + + if ((fp->_flags & __SSTR) == 0) + return (__fputwc(wc, fp)); + + mbs = initial; + if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { + fp->_flags |= __SERR; + return (WEOF); + } + uio.uio_iov = &iov; + uio.uio_resid = len; + uio.uio_iovcnt = 1; + iov.iov_base = buf; + iov.iov_len = len; + return (__sfvwrite(fp, &uio) != EOF ? (wint_t)wc : WEOF); +} + +/* + * Macros for converting digits to letters and vice versa + */ +#define to_digit(c) ((c) - '0') +#define is_digit(c) ((unsigned)to_digit(c) <= 9) +#define to_char(n) ((n) + '0') + +/* + * Convert an unsigned long to ASCII for printf purposes, returning + * a pointer to the first character of the string representation. + * Octal numbers can be forced to have a leading zero; hex numbers + * use the given digits. + */ +static wchar_t * +__ultoa(u_long val, wchar_t *endp, int base, int octzero, const char *xdigs, + int needgrp, char thousep, const char *grp) +{ + wchar_t *cp = endp; + long sval; + int ndig; + + /* + * Handle the three cases separately, in the hope of getting + * better/faster code. + */ + switch (base) { + case 10: + if (val < 10) { /* many numbers are 1 digit */ + *--cp = to_char(val); + return (cp); + } + ndig = 0; + /* + * On many machines, unsigned arithmetic is harder than + * signed arithmetic, so we do at most one unsigned mod and + * divide; this is sufficient to reduce the range of + * the incoming value to where signed arithmetic works. + */ + if (val > LONG_MAX) { + *--cp = to_char(val % 10); + ndig++; + sval = val / 10; + } else + sval = val; + do { + *--cp = to_char(sval % 10); + ndig++; + /* + * If (*grp == CHAR_MAX) then no more grouping + * should be performed. + */ + if (needgrp && ndig == *grp && *grp != CHAR_MAX + && sval > 9) { + *--cp = thousep; + ndig = 0; + /* + * If (*(grp+1) == '\0') then we have to + * use *grp character (last grouping rule) + * for all next cases + */ + if (*(grp+1) != '\0') + grp++; + } + sval /= 10; + } while (sval != 0); + break; + + case 8: + do { + *--cp = to_char(val & 7); + val >>= 3; + } while (val); + if (octzero && *cp != '0') + *--cp = '0'; + break; + + case 16: + do { + *--cp = xdigs[val & 15]; + val >>= 4; + } while (val); + break; + + default: /* oops */ + abort(); + } + return (cp); +} + +/* Identical to __ultoa, but for intmax_t. */ +static wchar_t * +__ujtoa(uintmax_t val, wchar_t *endp, int base, int octzero, + const char *xdigs, int needgrp, char thousep, const char *grp) +{ + wchar_t *cp = endp; + intmax_t sval; + int ndig; + + /* quick test for small values; __ultoa is typically much faster */ + /* (perhaps instead we should run until small, then call __ultoa?) */ + if (val <= ULONG_MAX) + return (__ultoa((u_long)val, endp, base, octzero, xdigs, + needgrp, thousep, grp)); + switch (base) { + case 10: + if (val < 10) { + *--cp = to_char(val % 10); + return (cp); + } + ndig = 0; + if (val > INTMAX_MAX) { + *--cp = to_char(val % 10); + ndig++; + sval = val / 10; + } else + sval = val; + do { + *--cp = to_char(sval % 10); + ndig++; + /* + * If (*grp == CHAR_MAX) then no more grouping + * should be performed. + */ + if (needgrp && *grp != CHAR_MAX && ndig == *grp + && sval > 9) { + *--cp = thousep; + ndig = 0; + /* + * If (*(grp+1) == '\0') then we have to + * use *grp character (last grouping rule) + * for all next cases + */ + if (*(grp+1) != '\0') + grp++; + } + sval /= 10; + } while (sval != 0); + break; + + case 8: + do { + *--cp = to_char(val & 7); + val >>= 3; + } while (val); + if (octzero && *cp != '0') + *--cp = '0'; + break; + + case 16: + do { + *--cp = xdigs[val & 15]; + val >>= 4; + } while (val); + break; + + default: + abort(); + } + return (cp); +} + +/* + * Convert a multibyte character string argument for the %s format to a wide + * string representation. ``prec'' specifies the maximum number of bytes + * to output. If ``prec'' is greater than or equal to zero, we can't assume + * that the multibyte char. string ends in a null character. + */ +static wchar_t * +__mbsconv(char *mbsarg, int prec) +{ + static const mbstate_t initial; + mbstate_t mbs; + wchar_t *convbuf, *wcp; + const char *p; + size_t insize, nchars, nconv; + + if (mbsarg == NULL) + return (NULL); + + /* + * Supplied argument is a multibyte string; convert it to wide + * characters first. + */ + if (prec >= 0) { + /* + * String is not guaranteed to be NUL-terminated. Find the + * number of characters to print. + */ + p = mbsarg; + insize = nchars = 0; + mbs = initial; + while (nchars != (size_t)prec) { + nconv = mbrlen(p, MB_CUR_MAX, &mbs); + if (nconv == 0 || nconv == (size_t)-1 || + nconv == (size_t)-2) + break; + p += nconv; + nchars++; + insize += nconv; + } + if (nconv == (size_t)-1 || nconv == (size_t)-2) + return (NULL); + } else + insize = strlen(mbsarg); + + /* + * Allocate buffer for the result and perform the conversion, + * converting at most `size' bytes of the input multibyte string to + * wide characters for printing. + */ + convbuf = malloc((insize + 1) * sizeof(*convbuf)); + if (convbuf == NULL) + return (NULL); + wcp = convbuf; + p = mbsarg; + mbs = initial; + while (insize != 0) { + nconv = mbrtowc(wcp, p, insize, &mbs); + if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2) + break; + wcp++; + p += nconv; + insize -= nconv; + } + if (nconv == (size_t)-1 || nconv == (size_t)-2) { + free(convbuf); + return (NULL); + } + *wcp = L'\0'; + + return (convbuf); +} + +/* + * MT-safe version + */ +int +vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap) + +{ + int ret; + + FLOCKFILE(fp); + ret = __vfwprintf(fp, fmt0, ap); + FUNLOCKFILE(fp); + return (ret); +} + +#ifndef NO_FLOATING_POINT + +#define dtoa __dtoa +#define freedtoa __freedtoa + +#include +#include +#include "floatio.h" +#include "gdtoa.h" + +#define DEFPREC 6 + +static int exponent(wchar_t *, int, wchar_t); + +#endif /* !NO_FLOATING_POINT */ + +/* + * The size of the buffer we use as scratch space for integer + * conversions, among other things. Technically, we would need the + * most space for base 10 conversions with thousands' grouping + * characters between each pair of digits. 100 bytes is a + * conservative overestimate even for a 128-bit uintmax_t. + */ +#define BUF 100 + +#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */ + +/* + * Flags used during conversion. + */ +#define ALT 0x001 /* alternate form */ +#define LADJUST 0x004 /* left adjustment */ +#define LONGDBL 0x008 /* long double */ +#define LONGINT 0x010 /* long integer */ +#define LLONGINT 0x020 /* long long integer */ +#define SHORTINT 0x040 /* short integer */ +#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ +#define FPT 0x100 /* Floating point number */ +#define GROUPING 0x200 /* use grouping ("'" flag) */ + /* C99 additional size modifiers: */ +#define SIZET 0x400 /* size_t */ +#define PTRDIFFT 0x800 /* ptrdiff_t */ +#define INTMAXT 0x1000 /* intmax_t */ +#define CHARINT 0x2000 /* print char using int format */ + +/* + * Non-MT-safe version + */ +int +__vfwprintf(FILE *fp, const wchar_t *fmt0, va_list ap) +{ + wchar_t *fmt; /* format string */ + wchar_t ch; /* character from fmt */ + int n, n2, n3; /* handy integer (short term usage) */ + wchar_t *cp; /* handy char pointer (short term usage) */ + int flags; /* flags as above */ + int ret; /* return value accumulator */ + int width; /* width from format (%8d), or 0 */ + int prec; /* precision from format; <0 for N/A */ + wchar_t sign; /* sign prefix (' ', '+', '-', or \0) */ + char thousands_sep; /* locale specific thousands separator */ + const char *grouping; /* locale specific numeric grouping rules */ +#ifndef NO_FLOATING_POINT + /* + * We can decompose the printed representation of floating + * point numbers into several parts, some of which may be empty: + * + * [+|-| ] [0x|0X] MMM . NNN [e|E|p|P] [+|-] ZZ + * A B ---C--- D E F + * + * A: 'sign' holds this value if present; '\0' otherwise + * B: ox[1] holds the 'x' or 'X'; '\0' if not hexadecimal + * C: cp points to the string MMMNNN. Leading and trailing + * zeros are not in the string and must be added. + * D: expchar holds this character; '\0' if no exponent, e.g. %f + * F: at least two digits for decimal, at least one digit for hex + */ + char *decimal_point; /* locale specific decimal point */ + int signflag; /* true if float is negative */ + union { /* floating point arguments %[aAeEfFgG] */ + double dbl; + long double ldbl; + } fparg; + int expt; /* integer value of exponent */ + char expchar; /* exponent character: [eEpP\0] */ + char *dtoaend; /* pointer to end of converted digits */ + int expsize; /* character count for expstr */ + int lead; /* sig figs before decimal or group sep */ + int ndig; /* actual number of digits returned by dtoa */ + wchar_t expstr[MAXEXPDIG+2]; /* buffer for exponent string: e+ZZZ */ + char *dtoaresult; /* buffer allocated by dtoa */ + int nseps; /* number of group separators with ' */ + int nrepeats; /* number of repeats of the last group */ +#endif + u_long ulval; /* integer arguments %[diouxX] */ + uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */ + int base; /* base for [diouxX] conversion */ + int dprec; /* a copy of prec if [diouxX], 0 otherwise */ + int realsz; /* field size expanded by dprec, sign, etc */ + int size; /* size of converted field or string */ + int prsize; /* max size of printed field */ + const char *xdigs; /* digits for [xX] conversion */ + wchar_t buf[BUF]; /* buffer with space for digits of uintmax_t */ + wchar_t ox[2]; /* space for 0x hex-prefix */ + union arg *argtable; /* args, built due to positional arg */ + union arg statargtable [STATIC_ARG_TBL_SIZE]; + int nextarg; /* 1-based argument index */ + va_list orgap; /* original argument pointer */ + wchar_t *convbuf; /* multibyte to wide conversion result */ + + /* + * Choose PADSIZE to trade efficiency vs. size. If larger printf + * fields occur frequently, increase PADSIZE and make the initialisers + * below longer. + */ +#define PADSIZE 16 /* pad chunk size */ + static wchar_t blanks[PADSIZE] = + {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; + static wchar_t zeroes[PADSIZE] = + {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; + + static const char xdigs_lower[16] = "0123456789abcdef"; + static const char xdigs_upper[16] = "0123456789ABCDEF"; + + /* + * BEWARE, these `goto error' on error, PRINT uses `n2' and + * PAD uses `n'. + */ +#define PRINT(ptr, len) do { \ + for (n3 = 0; n3 < (len); n3++) \ + __xfputwc((ptr)[n3], fp); \ +} while (0) +#define PAD(howmany, with) do { \ + if ((n = (howmany)) > 0) { \ + while (n > PADSIZE) { \ + PRINT(with, PADSIZE); \ + n -= PADSIZE; \ + } \ + PRINT(with, n); \ + } \ +} while (0) +#define PRINTANDPAD(p, ep, len, with) do { \ + n2 = (ep) - (p); \ + if (n2 > (len)) \ + n2 = (len); \ + if (n2 > 0) \ + PRINT((p), n2); \ + PAD((len) - (n2 > 0 ? n2 : 0), (with)); \ +} while(0) + + /* + * Get the argument indexed by nextarg. If the argument table is + * built, use it to get the argument. If its not, get the next + * argument (and arguments must be gotten sequentially). + */ +#define GETARG(type) \ + ((argtable != NULL) ? *((type*)(&argtable[nextarg++])) : \ + (nextarg++, va_arg(ap, type))) + + /* + * To extend shorts properly, we need both signed and unsigned + * argument extraction methods. + */ +#define SARG() \ + (flags&LONGINT ? GETARG(long) : \ + flags&SHORTINT ? (long)(short)GETARG(int) : \ + flags&CHARINT ? (long)(signed char)GETARG(int) : \ + (long)GETARG(int)) +#define UARG() \ + (flags&LONGINT ? GETARG(u_long) : \ + flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \ + flags&CHARINT ? (u_long)(u_char)GETARG(int) : \ + (u_long)GETARG(u_int)) +#define INTMAX_SIZE (INTMAXT|SIZET|PTRDIFFT|LLONGINT) +#define SJARG() \ + (flags&INTMAXT ? GETARG(intmax_t) : \ + flags&SIZET ? (intmax_t)GETARG(size_t) : \ + flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \ + (intmax_t)GETARG(long long)) +#define UJARG() \ + (flags&INTMAXT ? GETARG(uintmax_t) : \ + flags&SIZET ? (uintmax_t)GETARG(size_t) : \ + flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \ + (uintmax_t)GETARG(unsigned long long)) + + /* + * Get * arguments, including the form *nn$. Preserve the nextarg + * that the argument can be gotten once the type is determined. + */ +#define GETASTER(val) \ + n2 = 0; \ + cp = fmt; \ + while (is_digit(*cp)) { \ + n2 = 10 * n2 + to_digit(*cp); \ + cp++; \ + } \ + if (*cp == '$') { \ + int hold = nextarg; \ + if (argtable == NULL) { \ + argtable = statargtable; \ + __find_arguments (fmt0, orgap, &argtable); \ + } \ + nextarg = n2; \ + val = GETARG (int); \ + nextarg = hold; \ + fmt = ++cp; \ + } else { \ + val = GETARG (int); \ + } + + + thousands_sep = '\0'; + grouping = NULL; +#ifndef NO_FLOATING_POINT + decimal_point = localeconv()->decimal_point; +#endif + convbuf = NULL; + /* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */ + if (cantwrite(fp)) + return (EOF); + + /* optimise fprintf(stderr) (and other unbuffered Unix files) */ + if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && + fp->_file >= 0) + return (__sbprintf(fp, fmt0, ap)); + + fmt = (wchar_t *)fmt0; + argtable = NULL; + nextarg = 1; + va_copy(orgap, ap); + ret = 0; + + /* + * Scan the format for conversions (`%' character). + */ + for (;;) { + for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) + /* void */; + if ((n = fmt - cp) != 0) { + if ((unsigned)ret + n > INT_MAX) { + ret = EOF; + goto error; + } + PRINT(cp, n); + ret += n; + } + if (ch == '\0') + goto done; + fmt++; /* skip over '%' */ + + flags = 0; + dprec = 0; + width = 0; + prec = -1; + sign = '\0'; + ox[1] = '\0'; + +rflag: ch = *fmt++; +reswitch: switch (ch) { + case ' ': + /*- + * ``If the space and + flags both appear, the space + * flag will be ignored.'' + * -- ANSI X3J11 + */ + if (!sign) + sign = ' '; + goto rflag; + case '#': + flags |= ALT; + goto rflag; + case '*': + /*- + * ``A negative field width argument is taken as a + * - flag followed by a positive field width.'' + * -- ANSI X3J11 + * They don't exclude field widths read from args. + */ + GETASTER (width); + if (width >= 0) + goto rflag; + width = -width; + /* FALLTHROUGH */ + case '-': + flags |= LADJUST; + goto rflag; + case '+': + sign = '+'; + goto rflag; + case '\'': + flags |= GROUPING; + thousands_sep = *(localeconv()->thousands_sep); + grouping = localeconv()->grouping; + goto rflag; + case '.': + if ((ch = *fmt++) == '*') { + GETASTER (prec); + goto rflag; + } + prec = 0; + while (is_digit(ch)) { + prec = 10 * prec + to_digit(ch); + ch = *fmt++; + } + goto reswitch; + case '0': + /*- + * ``Note that 0 is taken as a flag, not as the + * beginning of a field width.'' + * -- ANSI X3J11 + */ + flags |= ZEROPAD; + goto rflag; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = 0; + do { + n = 10 * n + to_digit(ch); + ch = *fmt++; + } while (is_digit(ch)); + if (ch == '$') { + nextarg = n; + if (argtable == NULL) { + argtable = statargtable; + __find_arguments (fmt0, orgap, + &argtable); + } + goto rflag; + } + width = n; + goto reswitch; +#ifndef NO_FLOATING_POINT + case 'L': + flags |= LONGDBL; + goto rflag; +#endif + case 'h': + if (flags & SHORTINT) { + flags &= ~SHORTINT; + flags |= CHARINT; + } else + flags |= SHORTINT; + goto rflag; + case 'j': + flags |= INTMAXT; + goto rflag; + case 'l': + if (flags & LONGINT) { + flags &= ~LONGINT; + flags |= LLONGINT; + } else + flags |= LONGINT; + goto rflag; + case 'q': + flags |= LLONGINT; /* not necessarily */ + goto rflag; + case 't': + flags |= PTRDIFFT; + goto rflag; + case 'z': + flags |= SIZET; + goto rflag; + case 'C': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'c': + if (flags & LONGINT) + *(cp = buf) = (wchar_t)GETARG(wint_t); + else + *(cp = buf) = (wchar_t)btowc(GETARG(int)); + size = 1; + sign = '\0'; + break; + case 'D': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'd': + case 'i': + if (flags & INTMAX_SIZE) { + ujval = SJARG(); + if ((intmax_t)ujval < 0) { + ujval = -ujval; + sign = '-'; + } + } else { + ulval = SARG(); + if ((long)ulval < 0) { + ulval = -ulval; + sign = '-'; + } + } + base = 10; + goto number; +#ifndef NO_FLOATING_POINT + case 'a': + case 'A': + if (ch == 'a') { + ox[1] = 'x'; + xdigs = xdigs_lower; + expchar = 'p'; + } else { + ox[1] = 'X'; + xdigs = xdigs_upper; + expchar = 'P'; + } + if (prec >= 0) + prec++; + if (flags & LONGDBL) { + fparg.ldbl = GETARG(long double); + dtoaresult = + __hldtoa(fparg.ldbl, xdigs, prec, + &expt, &signflag, &dtoaend); + } else { + fparg.dbl = GETARG(double); + dtoaresult = + __hdtoa(fparg.dbl, xdigs, prec, + &expt, &signflag, &dtoaend); + } + if (prec < 0) + prec = dtoaend - dtoaresult; + if (expt == INT_MAX) + ox[1] = '\0'; + if (convbuf != NULL) + free(convbuf); + ndig = dtoaend - dtoaresult; + cp = convbuf = __mbsconv(dtoaresult, -1); + freedtoa(dtoaresult); + goto fp_common; + case 'e': + case 'E': + expchar = ch; + if (prec < 0) /* account for digit before decpt */ + prec = DEFPREC + 1; + else + prec++; + goto fp_begin; + case 'f': + case 'F': + expchar = '\0'; + goto fp_begin; + case 'g': + case 'G': + expchar = ch - ('g' - 'e'); + if (prec == 0) + prec = 1; +fp_begin: + if (prec < 0) + prec = DEFPREC; + if (convbuf != NULL) + free(convbuf); + if (flags & LONGDBL) { + fparg.ldbl = GETARG(long double); + dtoaresult = + __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec, + &expt, &signflag, &dtoaend); + } else { + fparg.dbl = GETARG(double); + dtoaresult = + dtoa(fparg.dbl, expchar ? 2 : 3, prec, + &expt, &signflag, &dtoaend); + if (expt == 9999) + expt = INT_MAX; + } + ndig = dtoaend - dtoaresult; + cp = convbuf = __mbsconv(dtoaresult, -1); + freedtoa(dtoaresult); +fp_common: + if (signflag) + sign = '-'; + if (expt == INT_MAX) { /* inf or nan */ + if (*cp == 'N') { + cp = (ch >= 'a') ? L"nan" : L"NAN"; + sign = '\0'; + } else + cp = (ch >= 'a') ? L"inf" : L"INF"; + size = 3; + break; + } + flags |= FPT; + if (ch == 'g' || ch == 'G') { + if (expt > -4 && expt <= prec) { + /* Make %[gG] smell like %[fF] */ + expchar = '\0'; + if (flags & ALT) + prec -= expt; + else + prec = ndig - expt; + if (prec < 0) + prec = 0; + } else { + /* + * Make %[gG] smell like %[eE], but + * trim trailing zeroes if no # flag. + */ + if (!(flags & ALT)) + prec = ndig; + } + } + if (expchar) { + expsize = exponent(expstr, expt - 1, expchar); + size = expsize + prec; + if (prec > 1 || flags & ALT) + ++size; + } else { + /* space for digits before decimal point */ + if (expt > 0) + size = expt; + else /* "0" */ + size = 1; + /* space for decimal pt and following digits */ + if (prec || flags & ALT) + size += prec + 1; + if (grouping && expt > 0) { + /* space for thousands' grouping */ + nseps = nrepeats = 0; + lead = expt; + while (*grouping != CHAR_MAX) { + if (lead <= *grouping) + break; + lead -= *grouping; + if (*(grouping+1)) { + nseps++; + grouping++; + } else + nrepeats++; + } + size += nseps + nrepeats; + } else + lead = expt; + } + break; +#endif /* !NO_FLOATING_POINT */ + case 'n': + /* + * Assignment-like behavior is specified if the + * value overflows or is otherwise unrepresentable. + * C99 says to use `signed char' for %hhn conversions. + */ + if (flags & LLONGINT) + *GETARG(long long *) = ret; + else if (flags & SIZET) + *GETARG(ssize_t *) = (ssize_t)ret; + else if (flags & PTRDIFFT) + *GETARG(ptrdiff_t *) = ret; + else if (flags & INTMAXT) + *GETARG(intmax_t *) = ret; + else if (flags & LONGINT) + *GETARG(long *) = ret; + else if (flags & SHORTINT) + *GETARG(short *) = ret; + else if (flags & CHARINT) + *GETARG(signed char *) = ret; + else + *GETARG(int *) = ret; + continue; /* no output */ + case 'O': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'o': + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 8; + goto nosign; + case 'p': + /*- + * ``The argument shall be a pointer to void. The + * value of the pointer is converted to a sequence + * of printable characters, in an implementation- + * defined manner.'' + * -- ANSI X3J11 + */ + ujval = (uintmax_t)(uintptr_t)GETARG(void *); + base = 16; + xdigs = xdigs_lower; + flags = flags | INTMAXT; + ox[1] = 'x'; + goto nosign; + case 'S': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 's': + if (flags & LONGINT) { + if ((cp = GETARG(wchar_t *)) == NULL) + cp = L"(null)"; + } else { + char *mbp; + + if (convbuf != NULL) + free(convbuf); + if ((mbp = GETARG(char *)) == NULL) + cp = L"(null)"; + else { + convbuf = __mbsconv(mbp, prec); + if (convbuf == NULL) { + fp->_flags |= __SERR; + goto error; + } + cp = convbuf; + } + } + + if (prec >= 0) { + /* + * can't use wcslen; can only look for the + * NUL in the first `prec' characters, and + * wcslen() will go further. + */ + wchar_t *p = wmemchr(cp, 0, (size_t)prec); + + if (p != NULL) { + size = p - cp; + if (size > prec) + size = prec; + } else + size = prec; + } else + size = wcslen(cp); + sign = '\0'; + break; + case 'U': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'u': + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 10; + goto nosign; + case 'X': + xdigs = xdigs_upper; + goto hex; + case 'x': + xdigs = xdigs_lower; +hex: + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 16; + /* leading 0x/X only if non-zero */ + if (flags & ALT && + (flags & INTMAX_SIZE ? ujval != 0 : ulval != 0)) + ox[1] = ch; + + flags &= ~GROUPING; + /* unsigned conversions */ +nosign: sign = '\0'; + /*- + * ``... diouXx conversions ... if a precision is + * specified, the 0 flag will be ignored.'' + * -- ANSI X3J11 + */ +number: if ((dprec = prec) >= 0) + flags &= ~ZEROPAD; + + /*- + * ``The result of converting a zero value with an + * explicit precision of zero is no characters.'' + * -- ANSI X3J11 + */ + cp = buf + BUF; + if (flags & INTMAX_SIZE) { + if (ujval != 0 || prec != 0) + cp = __ujtoa(ujval, cp, base, + flags & ALT, xdigs, + flags & GROUPING, thousands_sep, + grouping); + } else { + if (ulval != 0 || prec != 0) + cp = __ultoa(ulval, cp, base, + flags & ALT, xdigs, + flags & GROUPING, thousands_sep, + grouping); + } + size = buf + BUF - cp; + if (size > BUF) /* should never happen */ + abort(); + break; + default: /* "%?" prints ?, unless ? is NUL */ + if (ch == '\0') + goto done; + /* pretend it was %c with argument ch */ + cp = buf; + *cp = ch; + size = 1; + sign = '\0'; + break; + } + + /* + * All reasonable formats wind up here. At this point, `cp' + * points to a string which (if not flags&LADJUST) should be + * padded out to `width' places. If flags&ZEROPAD, it should + * first be prefixed by any sign or other prefix; otherwise, + * it should be blank padded before the prefix is emitted. + * After any left-hand padding and prefixing, emit zeroes + * required by a decimal [diouxX] precision, then print the + * string proper, then emit zeroes required by any leftover + * floating precision; finally, if LADJUST, pad with blanks. + * + * Compute actual size, so we know how much to pad. + * size excludes decimal prec; realsz includes it. + */ + realsz = dprec > size ? dprec : size; + if (sign) + realsz++; + if (ox[1]) + realsz += 2; + + prsize = width > realsz ? width : realsz; + if ((unsigned)ret + prsize > INT_MAX) { + ret = EOF; + goto error; + } + + /* right-adjusting blank padding */ + if ((flags & (LADJUST|ZEROPAD)) == 0) + PAD(width - realsz, blanks); + + /* prefix */ + if (sign) + PRINT(&sign, 1); + + if (ox[1]) { /* ox[1] is either x, X, or \0 */ + ox[0] = '0'; + PRINT(ox, 2); + } + + /* right-adjusting zero padding */ + if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) + PAD(width - realsz, zeroes); + + /* leading zeroes from decimal precision */ + PAD(dprec - size, zeroes); + + /* the string or number proper */ +#ifndef NO_FLOATING_POINT + if ((flags & FPT) == 0) { + PRINT(cp, size); + } else { /* glue together f_p fragments */ + if (!expchar) { /* %[fF] or sufficiently short %[gG] */ + if (expt <= 0) { + PRINT(zeroes, 1); + if (prec || flags & ALT) + PRINT(decimal_point, 1); + PAD(-expt, zeroes); + /* already handled initial 0's */ + prec += expt; + } else { + PRINTANDPAD(cp, convbuf + ndig, lead, zeroes); + cp += lead; + if (grouping) { + while (nseps>0 || nrepeats>0) { + if (nrepeats > 0) + nrepeats--; + else { + grouping--; + nseps--; + } + PRINT(&thousands_sep, + 1); + PRINTANDPAD(cp, + convbuf + ndig, + *grouping, zeroes); + cp += *grouping; + } + if (cp > convbuf + ndig) + cp = convbuf + ndig; + } + if (prec || flags & ALT) { + buf[0] = *decimal_point; + PRINT(buf, 1); + } + } + PRINTANDPAD(cp, convbuf + ndig, prec, zeroes); + } else { /* %[eE] or sufficiently long %[gG] */ + if (prec > 1 || flags & ALT) { + buf[0] = *cp++; + buf[1] = *decimal_point; + PRINT(buf, 2); + PRINT(cp, ndig-1); + PAD(prec - ndig, zeroes); + } else /* XeYYY */ + PRINT(cp, 1); + PRINT(expstr, expsize); + } + } +#else + PRINT(cp, size); +#endif + /* left-adjusting padding (always blank) */ + if (flags & LADJUST) + PAD(width - realsz, blanks); + + /* finally, adjust ret */ + ret += prsize; + } +done: +error: + if (convbuf != NULL) + free(convbuf); + if (__sferror(fp)) + ret = EOF; + if ((argtable != NULL) && (argtable != statargtable)) + free (argtable); + return (ret); + /* NOTREACHED */ +} + +/* + * Find all arguments when a positional parameter is encountered. Returns a + * table, indexed by argument number, of pointers to each arguments. The + * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. + * It will be replaces with a malloc-ed one if it overflows. + */ +static void +__find_arguments (const wchar_t *fmt0, va_list ap, union arg **argtable) +{ + wchar_t *fmt; /* format string */ + wchar_t ch; /* character from fmt */ + int n, n2; /* handy integer (short term usage) */ + wchar_t *cp; /* handy char pointer (short term usage) */ + int flags; /* flags as above */ + int width; /* width from format (%8d), or 0 */ + enum typeid *typetable; /* table of types */ + enum typeid stattypetable [STATIC_ARG_TBL_SIZE]; + int tablesize; /* current size of type table */ + int tablemax; /* largest used index in table */ + int nextarg; /* 1-based argument index */ + + /* + * Add an argument type to the table, expanding if necessary. + */ +#define ADDTYPE(type) \ + ((nextarg >= tablesize) ? \ + __grow_type_table(nextarg, &typetable, &tablesize) : 0, \ + (nextarg > tablemax) ? tablemax = nextarg : 0, \ + typetable[nextarg++] = type) + +#define ADDSARG() \ + ((flags&INTMAXT) ? ADDTYPE(T_INTMAXT) : \ + ((flags&SIZET) ? ADDTYPE(T_SIZET) : \ + ((flags&PTRDIFFT) ? ADDTYPE(T_PTRDIFFT) : \ + ((flags&LLONGINT) ? ADDTYPE(T_LLONG) : \ + ((flags&LONGINT) ? ADDTYPE(T_LONG) : ADDTYPE(T_INT)))))) + +#define ADDUARG() \ + ((flags&INTMAXT) ? ADDTYPE(T_UINTMAXT) : \ + ((flags&SIZET) ? ADDTYPE(T_SIZET) : \ + ((flags&PTRDIFFT) ? ADDTYPE(T_PTRDIFFT) : \ + ((flags&LLONGINT) ? ADDTYPE(T_U_LLONG) : \ + ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : ADDTYPE(T_U_INT)))))) + + /* + * Add * arguments to the type array. + */ +#define ADDASTER() \ + n2 = 0; \ + cp = fmt; \ + while (is_digit(*cp)) { \ + n2 = 10 * n2 + to_digit(*cp); \ + cp++; \ + } \ + if (*cp == '$') { \ + int hold = nextarg; \ + nextarg = n2; \ + ADDTYPE (T_INT); \ + nextarg = hold; \ + fmt = ++cp; \ + } else { \ + ADDTYPE (T_INT); \ + } + fmt = (wchar_t *)fmt0; + typetable = stattypetable; + tablesize = STATIC_ARG_TBL_SIZE; + tablemax = 0; + nextarg = 1; + for (n = 0; n < STATIC_ARG_TBL_SIZE; n++) + typetable[n] = T_UNUSED; + + /* + * Scan the format for conversions (`%' character). + */ + for (;;) { + for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) + /* void */; + if (ch == '\0') + goto done; + fmt++; /* skip over '%' */ + + flags = 0; + width = 0; + +rflag: ch = *fmt++; +reswitch: switch (ch) { + case ' ': + case '#': + goto rflag; + case '*': + ADDASTER (); + goto rflag; + case '-': + case '+': + case '\'': + goto rflag; + case '.': + if ((ch = *fmt++) == '*') { + ADDASTER (); + goto rflag; + } + while (is_digit(ch)) { + ch = *fmt++; + } + goto reswitch; + case '0': + goto rflag; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + n = 0; + do { + n = 10 * n + to_digit(ch); + ch = *fmt++; + } while (is_digit(ch)); + if (ch == '$') { + nextarg = n; + goto rflag; + } + width = n; + goto reswitch; +#ifndef NO_FLOATING_POINT + case 'L': + flags |= LONGDBL; + goto rflag; +#endif + case 'h': + if (flags & SHORTINT) { + flags &= ~SHORTINT; + flags |= CHARINT; + } else + flags |= SHORTINT; + goto rflag; + case 'j': + flags |= INTMAXT; + goto rflag; + case 'l': + if (flags & LONGINT) { + flags &= ~LONGINT; + flags |= LLONGINT; + } else + flags |= LONGINT; + goto rflag; + case 'q': + flags |= LLONGINT; /* not necessarily */ + goto rflag; + case 't': + flags |= PTRDIFFT; + goto rflag; + case 'z': + flags |= SIZET; + goto rflag; + case 'C': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'c': + if (flags & LONGINT) + ADDTYPE(T_WINT); + else + ADDTYPE(T_INT); + break; + case 'D': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'd': + case 'i': + ADDSARG(); + break; +#ifndef NO_FLOATING_POINT + case 'a': + case 'A': + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + if (flags & LONGDBL) + ADDTYPE(T_LONG_DOUBLE); + else + ADDTYPE(T_DOUBLE); + break; +#endif /* !NO_FLOATING_POINT */ + case 'n': + if (flags & INTMAXT) + ADDTYPE(TP_INTMAXT); + else if (flags & PTRDIFFT) + ADDTYPE(TP_PTRDIFFT); + else if (flags & SIZET) + ADDTYPE(TP_SIZET); + else if (flags & LLONGINT) + ADDTYPE(TP_LLONG); + else if (flags & LONGINT) + ADDTYPE(TP_LONG); + else if (flags & SHORTINT) + ADDTYPE(TP_SHORT); + else if (flags & CHARINT) + ADDTYPE(TP_SCHAR); + else + ADDTYPE(TP_INT); + continue; /* no output */ + case 'O': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'o': + ADDUARG(); + break; + case 'p': + ADDTYPE(TP_VOID); + break; + case 'S': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 's': + if (flags & LONGINT) + ADDTYPE(TP_WCHAR); + else + ADDTYPE(TP_CHAR); + break; + case 'U': + flags |= LONGINT; + /*FALLTHROUGH*/ + case 'u': + case 'X': + case 'x': + ADDUARG(); + break; + default: /* "%?" prints ?, unless ? is NUL */ + if (ch == '\0') + goto done; + break; + } + } +done: + /* + * Build the argument table. + */ + if (tablemax >= STATIC_ARG_TBL_SIZE) { + *argtable = (union arg *) + malloc (sizeof (union arg) * (tablemax + 1)); + } + + (*argtable) [0].intarg = 0; + for (n = 1; n <= tablemax; n++) { + switch (typetable [n]) { + case T_UNUSED: /* whoops! */ + (*argtable) [n].intarg = va_arg (ap, int); + break; + case TP_SCHAR: + (*argtable) [n].pschararg = va_arg (ap, signed char *); + break; + case TP_SHORT: + (*argtable) [n].pshortarg = va_arg (ap, short *); + break; + case T_INT: + (*argtable) [n].intarg = va_arg (ap, int); + break; + case T_U_INT: + (*argtable) [n].uintarg = va_arg (ap, unsigned int); + break; + case TP_INT: + (*argtable) [n].pintarg = va_arg (ap, int *); + break; + case T_LONG: + (*argtable) [n].longarg = va_arg (ap, long); + break; + case T_U_LONG: + (*argtable) [n].ulongarg = va_arg (ap, unsigned long); + break; + case TP_LONG: + (*argtable) [n].plongarg = va_arg (ap, long *); + break; + case T_LLONG: + (*argtable) [n].longlongarg = va_arg (ap, long long); + break; + case T_U_LLONG: + (*argtable) [n].ulonglongarg = va_arg (ap, unsigned long long); + break; + case TP_LLONG: + (*argtable) [n].plonglongarg = va_arg (ap, long long *); + break; + case T_PTRDIFFT: + (*argtable) [n].ptrdiffarg = va_arg (ap, ptrdiff_t); + break; + case TP_PTRDIFFT: + (*argtable) [n].pptrdiffarg = va_arg (ap, ptrdiff_t *); + break; + case T_SIZET: + (*argtable) [n].sizearg = va_arg (ap, size_t); + break; + case TP_SIZET: + (*argtable) [n].psizearg = va_arg (ap, ssize_t *); + break; + case T_INTMAXT: + (*argtable) [n].intmaxarg = va_arg (ap, intmax_t); + break; + case T_UINTMAXT: + (*argtable) [n].uintmaxarg = va_arg (ap, uintmax_t); + break; + case TP_INTMAXT: + (*argtable) [n].pintmaxarg = va_arg (ap, intmax_t *); + break; +#ifndef NO_FLOATING_POINT + case T_DOUBLE: + (*argtable) [n].doublearg = va_arg (ap, double); + break; + case T_LONG_DOUBLE: + (*argtable) [n].longdoublearg = va_arg (ap, long double); + break; +#endif + case TP_CHAR: + (*argtable) [n].pchararg = va_arg (ap, char *); + break; + case TP_VOID: + (*argtable) [n].pvoidarg = va_arg (ap, void *); + break; + case T_WINT: + (*argtable) [n].wintarg = va_arg (ap, wint_t); + break; + case TP_WCHAR: + (*argtable) [n].pwchararg = va_arg (ap, wchar_t *); + break; + } + } + + if ((typetable != NULL) && (typetable != stattypetable)) + free (typetable); +} + +/* + * Increase the size of the type table. + */ +static void +__grow_type_table (int nextarg, enum typeid **typetable, int *tablesize) +{ + enum typeid *const oldtable = *typetable; + const int oldsize = *tablesize; + enum typeid *newtable; + int n, newsize = oldsize * 2; + + if (newsize < nextarg + 1) + newsize = nextarg + 1; + if (oldsize == STATIC_ARG_TBL_SIZE) { + if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL) + abort(); /* XXX handle better */ + bcopy(oldtable, newtable, oldsize * sizeof(enum typeid)); + } else { + newtable = reallocf(oldtable, newsize * sizeof(enum typeid)); + if (newtable == NULL) + abort(); /* XXX handle better */ + } + for (n = oldsize; n < newsize; n++) + newtable[n] = T_UNUSED; + + *typetable = newtable; + *tablesize = newsize; +} + + +#ifndef NO_FLOATING_POINT + +static int +exponent(wchar_t *p0, int exp, wchar_t fmtch) +{ + wchar_t *p, *t; + wchar_t expbuf[MAXEXPDIG]; + + p = p0; + *p++ = fmtch; + if (exp < 0) { + exp = -exp; + *p++ = '-'; + } + else + *p++ = '+'; + t = expbuf + MAXEXPDIG; + if (exp > 9) { + do { + *--t = to_char(exp % 10); + } while ((exp /= 10) > 9); + *--t = to_char(exp); + for (; t < expbuf + MAXEXPDIG; *p++ = *t++); + } + else { + /* + * Exponents for decimal floating point conversions + * (%[eEgG]) must be at least two characters long, + * whereas exponents for hexadecimal conversions can + * be only one character long. + */ + if (fmtch == 'e' || fmtch == 'E') + *p++ = '0'; + *p++ = to_char(exp); + } + return (p - p0); +} +#endif /* !NO_FLOATING_POINT */ diff --git a/src/lib/libc/stdio/vfwscanf.c b/src/lib/libc/stdio/vfwscanf.c new file mode 100644 index 0000000..1f489e0 --- /dev/null +++ b/src/lib/libc/stdio/vfwscanf.c @@ -0,0 +1,878 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" +#include "local.h" + +#ifndef NO_FLOATING_POINT +#include +#endif + +#define BUF 513 /* Maximum length of numeric string. */ + +/* + * Flags used during conversion. + */ +#define LONG 0x01 /* l: long or double */ +#define LONGDBL 0x02 /* L: long double */ +#define SHORT 0x04 /* h: short */ +#define SUPPRESS 0x08 /* *: suppress assignment */ +#define POINTER 0x10 /* p: void * (as hex) */ +#define NOSKIP 0x20 /* [ or c: do not skip blanks */ +#define LONGLONG 0x400 /* ll: long long (+ deprecated q: quad) */ +#define INTMAXT 0x800 /* j: intmax_t */ +#define PTRDIFFT 0x1000 /* t: ptrdiff_t */ +#define SIZET 0x2000 /* z: size_t */ +#define SHORTSHORT 0x4000 /* hh: char */ +#define UNSIGNED 0x8000 /* %[oupxX] conversions */ + +/* + * The following are used in integral conversions only: + * SIGNOK, NDIGITS, PFXOK, and NZDIGITS + */ +#define SIGNOK 0x40 /* +/- is (still) legal */ +#define NDIGITS 0x80 /* no digits detected */ +#define PFXOK 0x100 /* 0x prefix is (still) legal */ +#define NZDIGITS 0x200 /* no zero digits detected */ +#define HAVESIGN 0x10000 /* sign detected */ + +/* + * Conversion types. + */ +#define CT_CHAR 0 /* %c conversion */ +#define CT_CCL 1 /* %[...] conversion */ +#define CT_STRING 2 /* %s conversion */ +#define CT_INT 3 /* %[dioupxX] conversion */ +#define CT_FLOAT 4 /* %[efgEFG] conversion */ + +static int parsefloat(FILE *, wchar_t *, wchar_t *); + +extern int __scanfdebug; + +#define INCCL(_c) \ + (cclcompl ? (wmemchr(ccls, (_c), ccle - ccls) == NULL) : \ + (wmemchr(ccls, (_c), ccle - ccls) != NULL)) + +/* + * MT-safe version. + */ +int +vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap) +{ + int ret; + + FLOCKFILE(fp); + ORIENT(fp, 1); + ret = __vfwscanf(fp, fmt, ap); + FUNLOCKFILE(fp); + return (ret); +} + +/* + * Non-MT-safe version. + */ +int +__vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap) +{ + wint_t c; /* character from format, or conversion */ + size_t width; /* field width, or 0 */ + wchar_t *p; /* points into all kinds of strings */ + int n; /* handy integer */ + int flags; /* flags as defined above */ + wchar_t *p0; /* saves original value of p when necessary */ + int nassigned; /* number of fields assigned */ + int nconversions; /* number of conversions */ + int nread; /* number of characters consumed from fp */ + int base; /* base argument to conversion function */ + wchar_t buf[BUF]; /* buffer for numeric conversions */ + const wchar_t *ccls; /* character class start */ + const wchar_t *ccle; /* character class end */ + int cclcompl; /* ccl is complemented? */ + wint_t wi; /* handy wint_t */ + char *mbp; /* multibyte string pointer for %c %s %[ */ + size_t nconv; /* number of bytes in mb. conversion */ + char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */ + static const mbstate_t initial; + mbstate_t mbs; + + /* `basefix' is used to avoid `if' tests in the integer scanner */ + static short basefix[17] = + { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + nassigned = 0; + nconversions = 0; + nread = 0; + ccls = ccle = NULL; + for (;;) { + c = *fmt++; + if (c == 0) + return (nassigned); + if (iswspace(c)) { + while ((c = __fgetwc(fp)) != WEOF && + iswspace(c)) + ; + if (c != WEOF) + __ungetwc(c, fp); + continue; + } + if (c != '%') + goto literal; + width = 0; + flags = 0; + /* + * switch on the format. continue if done; + * break once format type is derived. + */ +again: c = *fmt++; + switch (c) { + case '%': +literal: + if ((wi = __fgetwc(fp)) == WEOF) + goto input_failure; + if (wi != c) { + __ungetwc(wi, fp); + goto input_failure; + } + nread++; + continue; + + case '*': + flags |= SUPPRESS; + goto again; + case 'j': + flags |= INTMAXT; + goto again; + case 'l': + if (flags & LONG) { + flags &= ~LONG; + flags |= LONGLONG; + } else + flags |= LONG; + goto again; + case 'q': + flags |= LONGLONG; /* not quite */ + goto again; + case 't': + flags |= PTRDIFFT; + goto again; + case 'z': + flags |= SIZET; + goto again; + case 'L': + flags |= LONGDBL; + goto again; + case 'h': + if (flags & SHORT) { + flags &= ~SHORT; + flags |= SHORTSHORT; + } else + flags |= SHORT; + goto again; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + width = width * 10 + c - '0'; + goto again; + + /* + * Conversions. + */ + case 'd': + c = CT_INT; + base = 10; + break; + + case 'i': + c = CT_INT; + base = 0; + break; + + case 'o': + c = CT_INT; + flags |= UNSIGNED; + base = 8; + break; + + case 'u': + c = CT_INT; + flags |= UNSIGNED; + base = 10; + break; + + case 'X': + case 'x': + flags |= PFXOK; /* enable 0x prefixing */ + c = CT_INT; + flags |= UNSIGNED; + base = 16; + break; + +#ifndef NO_FLOATING_POINT + case 'A': case 'E': case 'F': case 'G': + case 'a': case 'e': case 'f': case 'g': + c = CT_FLOAT; + break; +#endif + + case 'S': + flags |= LONG; + /* FALLTHROUGH */ + case 's': + c = CT_STRING; + break; + + case '[': + ccls = fmt; + if (*fmt == '^') { + cclcompl = 1; + fmt++; + } else + cclcompl = 0; + if (*fmt == ']') + fmt++; + while (*fmt != '\0' && *fmt != ']') + fmt++; + ccle = fmt; + fmt++; + flags |= NOSKIP; + c = CT_CCL; + break; + + case 'C': + flags |= LONG; + /* FALLTHROUGH */ + case 'c': + flags |= NOSKIP; + c = CT_CHAR; + break; + + case 'p': /* pointer format is like hex */ + flags |= POINTER | PFXOK; + c = CT_INT; /* assumes sizeof(uintmax_t) */ + flags |= UNSIGNED; /* >= sizeof(uintptr_t) */ + base = 16; + break; + + case 'n': + nconversions++; + if (flags & SUPPRESS) /* ??? */ + continue; + if (flags & SHORTSHORT) + *va_arg(ap, char *) = nread; + else if (flags & SHORT) + *va_arg(ap, short *) = nread; + else if (flags & LONG) + *va_arg(ap, long *) = nread; + else if (flags & LONGLONG) + *va_arg(ap, long long *) = nread; + else if (flags & INTMAXT) + *va_arg(ap, intmax_t *) = nread; + else if (flags & SIZET) + *va_arg(ap, size_t *) = nread; + else if (flags & PTRDIFFT) + *va_arg(ap, ptrdiff_t *) = nread; + else + *va_arg(ap, int *) = nread; + continue; + + default: + goto match_failure; + + /* + * Disgusting backwards compatibility hack. XXX + */ + case '\0': /* compat */ + return (EOF); + } + + /* + * Consume leading white space, except for formats + * that suppress this. + */ + if ((flags & NOSKIP) == 0) { + while ((wi = __fgetwc(fp)) != WEOF && iswspace(wi)) + nread++; + if (wi == WEOF) + goto input_failure; + __ungetwc(wi, fp); + } + + /* + * Do the conversion. + */ + switch (c) { + + case CT_CHAR: + /* scan arbitrary characters (sets NOSKIP) */ + if (width == 0) + width = 1; + if (flags & LONG) { + if (!(flags & SUPPRESS)) + p = va_arg(ap, wchar_t *); + n = 0; + while (width-- != 0 && + (wi = __fgetwc(fp)) != WEOF) { + if (!(flags & SUPPRESS)) + *p++ = (wchar_t)wi; + n++; + } + if (n == 0) + goto input_failure; + nread += n; + if (!(flags & SUPPRESS)) + nassigned++; + } else { + if (!(flags & SUPPRESS)) + mbp = va_arg(ap, char *); + n = 0; + mbs = initial; + while (width != 0 && + (wi = __fgetwc(fp)) != WEOF) { + if (width >= MB_CUR_MAX && + !(flags & SUPPRESS)) { + nconv = wcrtomb(mbp, wi, &mbs); + if (nconv == (size_t)-1) + goto input_failure; + } else { + nconv = wcrtomb(mbbuf, wi, + &mbs); + if (nconv == (size_t)-1) + goto input_failure; + if (nconv > width) { + __ungetwc(wi, fp); + break; + } + if (!(flags & SUPPRESS)) + memcpy(mbp, mbbuf, + nconv); + } + if (!(flags & SUPPRESS)) + mbp += nconv; + width -= nconv; + n++; + } + if (n == 0) + goto input_failure; + nread += n; + if (!(flags & SUPPRESS)) + nassigned++; + } + nconversions++; + break; + + case CT_CCL: + /* scan a (nonempty) character class (sets NOSKIP) */ + if (width == 0) + width = (size_t)~0; /* `infinity' */ + /* take only those things in the class */ + if ((flags & SUPPRESS) && (flags & LONG)) { + n = 0; + while ((wi = __fgetwc(fp)) != WEOF && + width-- != 0 && INCCL(wi)) + n++; + if (wi != WEOF) + __ungetwc(wi, fp); + if (n == 0) + goto match_failure; + } else if (flags & LONG) { + p0 = p = va_arg(ap, wchar_t *); + while ((wi = __fgetwc(fp)) != WEOF && + width-- != 0 && INCCL(wi)) + *p++ = (wchar_t)wi; + if (wi != WEOF) + __ungetwc(wi, fp); + n = p - p0; + if (n == 0) + goto match_failure; + *p = 0; + nassigned++; + } else { + if (!(flags & SUPPRESS)) + mbp = va_arg(ap, char *); + n = 0; + mbs = initial; + while ((wi = __fgetwc(fp)) != WEOF && + width != 0 && INCCL(wi)) { + if (width >= MB_CUR_MAX && + !(flags & SUPPRESS)) { + nconv = wcrtomb(mbp, wi, &mbs); + if (nconv == (size_t)-1) + goto input_failure; + } else { + nconv = wcrtomb(mbbuf, wi, + &mbs); + if (nconv == (size_t)-1) + goto input_failure; + if (nconv > width) + break; + if (!(flags & SUPPRESS)) + memcpy(mbp, mbbuf, + nconv); + } + if (!(flags & SUPPRESS)) + mbp += nconv; + width -= nconv; + n++; + } + if (wi != WEOF) + __ungetwc(wi, fp); + if (!(flags & SUPPRESS)) { + *mbp = 0; + nassigned++; + } + } + nread += n; + nconversions++; + break; + + case CT_STRING: + /* like CCL, but zero-length string OK, & no NOSKIP */ + if (width == 0) + width = (size_t)~0; + if ((flags & SUPPRESS) && (flags & LONG)) { + while ((wi = __fgetwc(fp)) != WEOF && + width-- != 0 && + !iswspace(wi)) + nread++; + if (wi != WEOF) + __ungetwc(wi, fp); + } else if (flags & LONG) { + p0 = p = va_arg(ap, wchar_t *); + while ((wi = __fgetwc(fp)) != WEOF && + width-- != 0 && + !iswspace(wi)) { + *p++ = (wchar_t)wi; + nread++; + } + if (wi != WEOF) + __ungetwc(wi, fp); + *p = '\0'; + nassigned++; + } else { + if (!(flags & SUPPRESS)) + mbp = va_arg(ap, char *); + mbs = initial; + while ((wi = __fgetwc(fp)) != WEOF && + width != 0 && + !iswspace(wi)) { + if (width >= MB_CUR_MAX && + !(flags & SUPPRESS)) { + nconv = wcrtomb(mbp, wi, &mbs); + if (nconv == (size_t)-1) + goto input_failure; + } else { + nconv = wcrtomb(mbbuf, wi, + &mbs); + if (nconv == (size_t)-1) + goto input_failure; + if (nconv > width) + break; + if (!(flags & SUPPRESS)) + memcpy(mbp, mbbuf, + nconv); + } + if (!(flags & SUPPRESS)) + mbp += nconv; + width -= nconv; + nread++; + } + if (wi != WEOF) + __ungetwc(wi, fp); + if (!(flags & SUPPRESS)) { + *mbp = 0; + nassigned++; + } + } + nconversions++; + continue; + + case CT_INT: + /* scan an integer as if by the conversion function */ + if (width == 0 || width > sizeof(buf) / + sizeof(*buf) - 1) + width = sizeof(buf) / sizeof(*buf) - 1; + flags |= SIGNOK | NDIGITS | NZDIGITS; + for (p = buf; width; width--) { + c = __fgetwc(fp); + /* + * Switch on the character; `goto ok' + * if we accept it as a part of number. + */ + switch (c) { + + /* + * The digit 0 is always legal, but is + * special. For %i conversions, if no + * digits (zero or nonzero) have been + * scanned (only signs), we will have + * base==0. In that case, we should set + * it to 8 and enable 0x prefixing. + * Also, if we have not scanned zero digits + * before this, do not turn off prefixing + * (someone else will turn it off if we + * have scanned any nonzero digits). + */ + case '0': + if (base == 0) { + base = 8; + flags |= PFXOK; + } + if (flags & NZDIGITS) + flags &= ~(SIGNOK|NZDIGITS|NDIGITS); + else + flags &= ~(SIGNOK|PFXOK|NDIGITS); + goto ok; + + /* 1 through 7 always legal */ + case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + base = basefix[base]; + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* digits 8 and 9 ok iff decimal or hex */ + case '8': case '9': + base = basefix[base]; + if (base <= 8) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* letters ok iff hex */ + case 'A': case 'B': case 'C': + case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': + case 'd': case 'e': case 'f': + /* no need to fix base here */ + if (base <= 10) + break; /* not legal here */ + flags &= ~(SIGNOK | PFXOK | NDIGITS); + goto ok; + + /* sign ok only as first character */ + case '+': case '-': + if (flags & SIGNOK) { + flags &= ~SIGNOK; + flags |= HAVESIGN; + goto ok; + } + break; + + /* + * x ok iff flag still set & 2nd char (or + * 3rd char if we have a sign). + */ + case 'x': case 'X': + if (flags & PFXOK && p == + buf + 1 + !!(flags & HAVESIGN)) { + base = 16; /* if %i */ + flags &= ~PFXOK; + goto ok; + } + break; + } + + /* + * If we got here, c is not a legal character + * for a number. Stop accumulating digits. + */ + if (c != WEOF) + __ungetwc(c, fp); + break; + ok: + /* + * c is legal: store it and look at the next. + */ + *p++ = (wchar_t)c; + } + /* + * If we had only a sign, it is no good; push + * back the sign. If the number ends in `x', + * it was [sign] '0' 'x', so push back the x + * and treat it as [sign] '0'. + */ + if (flags & NDIGITS) { + if (p > buf) + __ungetwc(*--p, fp); + goto match_failure; + } + c = p[-1]; + if (c == 'x' || c == 'X') { + --p; + __ungetwc(c, fp); + } + if ((flags & SUPPRESS) == 0) { + uintmax_t res; + + *p = 0; + if ((flags & UNSIGNED) == 0) + res = wcstoimax(buf, NULL, base); + else + res = wcstoumax(buf, NULL, base); + if (flags & POINTER) + *va_arg(ap, void **) = + (void *)(uintptr_t)res; + else if (flags & SHORTSHORT) + *va_arg(ap, char *) = res; + else if (flags & SHORT) + *va_arg(ap, short *) = res; + else if (flags & LONG) + *va_arg(ap, long *) = res; + else if (flags & LONGLONG) + *va_arg(ap, long long *) = res; + else if (flags & INTMAXT) + *va_arg(ap, intmax_t *) = res; + else if (flags & PTRDIFFT) + *va_arg(ap, ptrdiff_t *) = res; + else if (flags & SIZET) + *va_arg(ap, size_t *) = res; + else + *va_arg(ap, int *) = res; + nassigned++; + } + nread += p - buf; + nconversions++; + break; + +#ifndef NO_FLOATING_POINT + case CT_FLOAT: + /* scan a floating point number as if by strtod */ + if (width == 0 || width > sizeof(buf) / + sizeof(*buf) - 1) + width = sizeof(buf) / sizeof(*buf) - 1; + if ((width = parsefloat(fp, buf, buf + width)) == 0) + goto match_failure; + if ((flags & SUPPRESS) == 0) { + if (flags & LONGDBL) { + long double res = wcstold(buf, &p); + *va_arg(ap, long double *) = res; + } else if (flags & LONG) { + double res = wcstod(buf, &p); + *va_arg(ap, double *) = res; + } else { + float res = wcstof(buf, &p); + *va_arg(ap, float *) = res; + } + if (__scanfdebug && p - buf != width) + abort(); + nassigned++; + } + nread += width; + nconversions++; + break; +#endif /* !NO_FLOATING_POINT */ + } + } +input_failure: + return (nconversions != 0 ? nassigned : EOF); +match_failure: + return (nassigned); +} + +#ifndef NO_FLOATING_POINT +static int +parsefloat(FILE *fp, wchar_t *buf, wchar_t *end) +{ + wchar_t *commit, *p; + int infnanpos = 0; + enum { + S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX, + S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS + } state = S_START; + wchar_t c; + wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point; + _Bool gotmantdig = 0, ishex = 0; + + /* + * We set commit = p whenever the string we have read so far + * constitutes a valid representation of a floating point + * number by itself. At some point, the parse will complete + * or fail, and we will ungetc() back to the last commit point. + * To ensure that the file offset gets updated properly, it is + * always necessary to read at least one character that doesn't + * match; thus, we can't short-circuit "infinity" or "nan(...)". + */ + commit = buf - 1; + c = WEOF; + for (p = buf; p < end; ) { + if ((c = __fgetwc(fp)) == WEOF) + break; +reswitch: + switch (state) { + case S_START: + state = S_GOTSIGN; + if (c == '-' || c == '+') + break; + else + goto reswitch; + case S_GOTSIGN: + switch (c) { + case '0': + state = S_MAYBEHEX; + commit = p; + break; + case 'I': + case 'i': + state = S_INF; + break; + case 'N': + case 'n': + state = S_NAN; + break; + default: + state = S_DIGITS; + goto reswitch; + } + break; + case S_INF: + if (infnanpos > 6 || + (c != "nfinity"[infnanpos] && + c != "NFINITY"[infnanpos])) + goto parsedone; + if (infnanpos == 1 || infnanpos == 6) + commit = p; /* inf or infinity */ + infnanpos++; + break; + case S_NAN: + switch (infnanpos) { + case -1: /* XXX kludge to deal with nan(...) */ + goto parsedone; + case 0: + if (c != 'A' && c != 'a') + goto parsedone; + break; + case 1: + if (c != 'N' && c != 'n') + goto parsedone; + else + commit = p; + break; + case 2: + if (c != '(') + goto parsedone; + break; + default: + if (c == ')') { + commit = p; + infnanpos = -2; + } else if (!iswalnum(c) && c != '_') + goto parsedone; + break; + } + infnanpos++; + break; + case S_MAYBEHEX: + state = S_DIGITS; + if (c == 'X' || c == 'x') { + ishex = 1; + break; + } else { /* we saw a '0', but no 'x' */ + gotmantdig = 1; + goto reswitch; + } + case S_DIGITS: + if ((ishex && iswxdigit(c)) || iswdigit(c)) + gotmantdig = 1; + else { + state = S_FRAC; + if (c != decpt) + goto reswitch; + } + if (gotmantdig) + commit = p; + break; + case S_FRAC: + if (((c == 'E' || c == 'e') && !ishex) || + ((c == 'P' || c == 'p') && ishex)) { + if (!gotmantdig) + goto parsedone; + else + state = S_EXP; + } else if ((ishex && iswxdigit(c)) || iswdigit(c)) { + commit = p; + gotmantdig = 1; + } else + goto parsedone; + break; + case S_EXP: + state = S_EXPDIGITS; + if (c == '-' || c == '+') + break; + else + goto reswitch; + case S_EXPDIGITS: + if (iswdigit(c)) + commit = p; + else + goto parsedone; + break; + default: + abort(); + } + *p++ = c; + c = WEOF; + } + +parsedone: + if (c != WEOF) + __ungetwc(c, fp); + while (commit < --p) + __ungetwc(*p, fp); + *++commit = '\0'; + return (commit - buf); +} +#endif diff --git a/src/lib/libc/stdio/vprintf.c b/src/lib/libc/stdio/vprintf.c new file mode 100644 index 0000000..329bbf0 --- /dev/null +++ b/src/lib/libc/stdio/vprintf.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)vprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vprintf.c,v 1.10 2002/09/06 11:23:56 tjr Exp $"); + +#include + +int +vprintf(const char * __restrict fmt, __va_list ap) +{ + + return (vfprintf(stdout, fmt, ap)); +} diff --git a/src/lib/libc/stdio/vscanf.c b/src/lib/libc/stdio/vscanf.c new file mode 100644 index 0000000..6945736 --- /dev/null +++ b/src/lib/libc/stdio/vscanf.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Donn Seeley at UUNET Technologies, Inc. + * + * 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[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vscanf.c,v 1.12 2003/01/03 23:27:27 tjr Exp $"); + +#include "namespace.h" +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "local.h" + +int +vscanf(fmt, ap) + const char * __restrict fmt; + __va_list ap; +{ + int retval; + + FLOCKFILE(stdin); + retval = __svfscanf(stdin, fmt, ap); + FUNLOCKFILE(stdin); + return (retval); +} diff --git a/src/lib/libc/stdio/vsnprintf.c b/src/lib/libc/stdio/vsnprintf.c new file mode 100644 index 0000000..3a43939 --- /dev/null +++ b/src/lib/libc/stdio/vsnprintf.c @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vsnprintf.c,v 1.22 2003/07/02 07:08:44 jkh Exp $"); + +#include +#include +#include "local.h" + +int +vsnprintf(char * __restrict str, size_t n, const char * __restrict fmt, + __va_list ap) +{ + size_t on; + int ret; + char dummy[2]; + FILE f; + struct __sFILEX ext; + + on = n; + if (n != 0) + n--; + if (n > INT_MAX) + n = INT_MAX; + /* Stdio internals do not deal correctly with zero length buffer */ + if (n == 0) { + if (on > 0) + *str = '\0'; + str = dummy; + n = 1; + } + f._file = -1; + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = n; + f._extra = &ext; + INITEXTRA(&f); + ret = __vfprintf(&f, fmt, ap); + if (on > 0) + *f._p = '\0'; + return (ret); +} diff --git a/src/lib/libc/stdio/vsprintf.c b/src/lib/libc/stdio/vsprintf.c new file mode 100644 index 0000000..698f752 --- /dev/null +++ b/src/lib/libc/stdio/vsprintf.c @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vsprintf.c,v 1.14 2002/09/06 11:23:56 tjr Exp $"); + +#include +#include +#include "local.h" + +int +vsprintf(char * __restrict str, const char * __restrict fmt, __va_list ap) +{ + int ret; + FILE f; + struct __sFILEX ext; + + f._file = -1; + f._flags = __SWR | __SSTR; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._w = INT_MAX; + f._extra = &ext; + INITEXTRA(&f); + ret = __vfprintf(&f, fmt, ap); + *f._p = 0; + return (ret); +} diff --git a/src/lib/libc/stdio/vsscanf.c b/src/lib/libc/stdio/vsscanf.c new file mode 100644 index 0000000..e7bbe25 --- /dev/null +++ b/src/lib/libc/stdio/vsscanf.c @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Donn Seeley at UUNET Technologies, Inc. + * + * 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[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vsscanf.c,v 1.12 2002/10/12 16:13:41 mike Exp $"); + +#include +#include +#include "local.h" + +static int +eofread(void *, char *, int); + +/* ARGSUSED */ +static int +eofread(cookie, buf, len) + void *cookie; + char *buf; + int len; +{ + + return (0); +} + +int +vsscanf(str, fmt, ap) + const char * __restrict str; + const char * __restrict fmt; + __va_list ap; +{ + FILE f; + struct __sFILEX ext; + + f._file = -1; + f._flags = __SRD; + f._bf._base = f._p = (unsigned char *)str; + f._bf._size = f._r = strlen(str); + f._read = eofread; + f._ub._base = NULL; + f._lb._base = NULL; + f._extra = &ext; + INITEXTRA(&f); + return (__svfscanf(&f, fmt, ap)); +} diff --git a/src/lib/libc/stdio/vswprintf.c b/src/lib/libc/stdio/vswprintf.c new file mode 100644 index 0000000..50c9876 --- /dev/null +++ b/src/lib/libc/stdio/vswprintf.c @@ -0,0 +1,95 @@ +/* $OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. + */ + +#include +#if 0 +__FBSDID("FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.16 2002/08/21 16:19:57 mike Exp "); +#endif +__FBSDID("$FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.5 2004/04/07 09:55:05 tjr Exp $"); + +#include +#include +#include +#include +#include "local.h" + +int +vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, + __va_list ap) +{ + static const mbstate_t initial; + mbstate_t mbs; + FILE f; + struct __sFILEX ext; + char *mbp; + int ret, sverrno; + + if (n == 0) { + errno = EINVAL; + return (-1); + } + + f._file = -1; + f._flags = __SWR | __SSTR | __SALC; + f._bf._base = f._p = (unsigned char *)malloc(128); + if (f._bf._base == NULL) { + errno = ENOMEM; + return (-1); + } + f._bf._size = f._w = 127; /* Leave room for the NUL */ + f._extra = &ext; + INITEXTRA(&f); + ret = __vfwprintf(&f, fmt, ap); + if (ret < 0) { + sverrno = errno; + free(f._bf._base); + errno = sverrno; + return (-1); + } + *f._p = '\0'; + mbp = f._bf._base; + /* + * XXX Undo the conversion from wide characters to multibyte that + * fputwc() did in __vfwprintf(). + */ + mbs = initial; + if (mbsrtowcs(s, (const char **)&mbp, n, &mbs) == (size_t)-1) { + free(f._bf._base); + errno = EILSEQ; + return (-1); + } + free(f._bf._base); + if (s[n - 1] != L'\0') { + s[n - 1] = L'\0'; + errno = EOVERFLOW; + return (-1); + } + + return (ret); +} diff --git a/src/lib/libc/stdio/vswscanf.c b/src/lib/libc/stdio/vswscanf.c new file mode 100644 index 0000000..03675d4 --- /dev/null +++ b/src/lib/libc/stdio/vswscanf.c @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Donn Seeley at UUNET Technologies, Inc. + * + * 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. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +__FBSDID("FreeBSD: src/lib/libc/stdio/vsscanf.c,v 1.11 2002/08/21 16:19:57 mike Exp "); +#endif +__FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $"); + +#include +#include +#include +#include +#include +#include +#include "local.h" + +static int eofread(void *, char *, int); + +static int +eofread(void *cookie, char *buf, int len) +{ + + return (0); +} + +int +vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, + va_list ap) +{ + static const mbstate_t initial; + mbstate_t mbs; + FILE f; + struct __sFILEX ext; + char *mbstr; + size_t mlen; + int r; + + /* + * XXX Convert the wide character string to multibyte, which + * __vfwscanf() will convert back to wide characters. + */ + if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL) + return (EOF); + mbs = initial; + if ((mlen = wcsrtombs(mbstr, &str, SIZE_T_MAX, &mbs)) == (size_t)-1) { + free(mbstr); + return (EOF); + } + f._file = -1; + f._flags = __SRD; + f._bf._base = f._p = (unsigned char *)mbstr; + f._bf._size = f._r = mlen; + f._read = eofread; + f._ub._base = NULL; + f._lb._base = NULL; + f._extra = &ext; + INITEXTRA(&f); + r = __vfwscanf(&f, fmt, ap); + free(mbstr); + + return (r); +} diff --git a/src/lib/libc/stdio/vwprintf.c b/src/lib/libc/stdio/vwprintf.c new file mode 100644 index 0000000..4390c06 --- /dev/null +++ b/src/lib/libc/stdio/vwprintf.c @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); + +#include +#include +#include + +int +vwprintf(const wchar_t * __restrict fmt, va_list ap) +{ + + return (vfwprintf(stdout, fmt, ap)); +} diff --git a/src/lib/libc/stdio/vwscanf.c b/src/lib/libc/stdio/vwscanf.c new file mode 100644 index 0000000..6e103d5 --- /dev/null +++ b/src/lib/libc/stdio/vwscanf.c @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/vwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); + +#include +#include +#include + +int +vwscanf(const wchar_t * __restrict fmt, va_list ap) +{ + + return (vfwscanf(stdin, fmt, ap)); +} diff --git a/src/lib/libc/stdio/wbuf.c b/src/lib/libc/stdio/wbuf.c new file mode 100644 index 0000000..000c469 --- /dev/null +++ b/src/lib/libc/stdio/wbuf.c @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/wbuf.c,v 1.10 2002/08/13 09:30:41 tjr Exp $"); + +#include +#include "local.h" + +/* + * Write the given character into the (probably full) buffer for + * the given file. Flush the buffer out if it is or becomes full, + * or if c=='\n' and the file is line buffered. + * + * Non-MT-safe + */ +int +__swbuf(c, fp) + int c; + FILE *fp; +{ + int n; + + /* + * In case we cannot write, or longjmp takes us out early, + * make sure _w is 0 (if fully- or un-buffered) or -_bf._size + * (if line buffered) so that we will get called again. + * If we did not do this, a sufficient number of putc() + * calls might wrap _w from negative to positive. + */ + fp->_w = fp->_lbfsize; + if (cantwrite(fp)) + return (EOF); + c = (unsigned char)c; + + ORIENT(fp, -1); + + /* + * If it is completely full, flush it out. Then, in any case, + * stuff c into the buffer. If this causes the buffer to fill + * completely, or if c is '\n' and the file is line buffered, + * flush it (perhaps a second time). The second flush will always + * happen on unbuffered streams, where _bf._size==1; fflush() + * guarantees that putc() will always call wbuf() by setting _w + * to 0, so we need not do anything else. + */ + n = fp->_p - fp->_bf._base; + if (n >= fp->_bf._size) { + if (__fflush(fp)) + return (EOF); + n = 0; + } + fp->_w--; + *fp->_p++ = c; + if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) + if (__fflush(fp)) + return (EOF); + return (c); +} diff --git a/src/lib/libc/stdio/wprintf.c b/src/lib/libc/stdio/wprintf.c new file mode 100644 index 0000000..4b5596e --- /dev/null +++ b/src/lib/libc/stdio/wprintf.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/wprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); + +#include +#include +#include + +int +wprintf(const wchar_t * __restrict fmt, ...) +{ + int ret; + va_list ap; + + va_start(ap, fmt); + ret = vfwprintf(stdout, fmt, ap); + va_end(ap); + + return (ret); +} diff --git a/src/lib/libc/stdio/wscanf.c b/src/lib/libc/stdio/wscanf.c new file mode 100644 index 0000000..8629027 --- /dev/null +++ b/src/lib/libc/stdio/wscanf.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/wscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); + +#include +#include +#include + +int +wscanf(const wchar_t * __restrict fmt, ...) +{ + va_list ap; + int r; + + va_start(ap, fmt); + r = vfwscanf(stdin, fmt, ap); + va_end(ap); + + return (r); +} diff --git a/src/lib/libc/stdio/wsetup.c b/src/lib/libc/stdio/wsetup.c new file mode 100644 index 0000000..67c9e2f --- /dev/null +++ b/src/lib/libc/stdio/wsetup.c @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdio/wsetup.c,v 1.8 2002/03/22 21:53:04 obrien Exp $"); + +#include +#include +#include "local.h" + +/* + * Various output routines call wsetup to be sure it is safe to write, + * because either _flags does not include __SWR, or _buf is NULL. + * _wsetup returns 0 if OK to write, nonzero otherwise. + */ +int +__swsetup(fp) + FILE *fp; +{ + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + /* + * If we are not writing, we had better be reading and writing. + */ + if ((fp->_flags & __SWR) == 0) { + if ((fp->_flags & __SRW) == 0) + return (EOF); + if (fp->_flags & __SRD) { + /* clobber any ungetc data */ + if (HASUB(fp)) + FREEUB(fp); + fp->_flags &= ~(__SRD|__SEOF); + fp->_r = 0; + fp->_p = fp->_bf._base; + } + fp->_flags |= __SWR; + } + + /* + * Make a buffer if necessary, then set _w. + */ + if (fp->_bf._base == NULL) + __smakebuf(fp); + if (fp->_flags & __SLBF) { + /* + * It is line buffered, so make _lbfsize be -_bufsize + * for the putc() macro. We will change _lbfsize back + * to 0 whenever we turn off __SWR. + */ + fp->_w = 0; + fp->_lbfsize = -fp->_bf._size; + } else + fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; + return (0); +} diff --git a/src/lib/libc/stdlib/Makefile b/src/lib/libc/stdlib/Makefile new file mode 100644 index 0000000..0e48468 --- /dev/null +++ b/src/lib/libc/stdlib/Makefile @@ -0,0 +1,34 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = _Exit.o abort.o abs.o atexit.o atof.o atoi.o atol.o atoll.o bsearch.o calloc.o div.o exit.o getenv.o getopt.o getopt_long.o getsubopt.o grantpt.o hcreate.o heapsort.o imaxabs.o imaxdiv.o insque.o labs.o ldiv.o llabs.o lldiv.o lsearch.o malloc.o merge.o putenv.o qsort.o qsort_r.o radixsort.o rand.o random.o reallocf.o realpath.o remque.o setenv.o strfmon.o strtoimax.o strtol.o strtoll.o strtoq.o strtoul.o strtoull.o strtoumax.o strtouq.o system.o tdelete.o tfind.o tsearch.o twalk.o + +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) -Wall ${CFLAGS} -nostdinc -O -I../include -c -o $@ $< + +.cc.s: + $(CXX) -Wall ${CFLAGS} -nostdinc -O -I../include -S -o $@ $< + +.c.o: + $(CC) -Wall ${CFLAGS} -nostdinc -O -I../include -I../../../include -c $< + +.c.s: + $(CC) -Wall ${CFLAGS} -nostdinc -O -I../include -S -o $@ $< + +.S.o: + $(CC) -Wall ${CFLAGS} -nostdinc -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/stdlib/_Exit.c b/src/lib/libc/stdlib/_Exit.c new file mode 100644 index 0000000..3a2e94e --- /dev/null +++ b/src/lib/libc/stdlib/_Exit.c @@ -0,0 +1,22 @@ +/* + * This file is in the public domain. Written by Garrett A. Wollman, + * 2002-09-07. + * + * $FreeBSD: src/lib/libc/stdlib/_Exit.c,v 1.1 2002/09/10 02:04:49 wollman Exp $ + */ + +#include +#include + +/* + * ISO C99 added this function to provide for Standard C applications + * which needed something like POSIX _exit(). A new interface was created + * in case it turned out that _exit() was insufficient to meet the + * requirements of ISO C. (That's probably not the case, but here + * is where you would put the extra code if it were.) + */ +void +_Exit(int code) +{ + _exit(code); +} diff --git a/src/lib/libc/stdlib/abort.c b/src/lib/libc/stdlib/abort.c new file mode 100644 index 0000000..18d0c73 --- /dev/null +++ b/src/lib/libc/stdlib/abort.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1985, 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[] = "@(#)abort.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/abort.c,v 1.9 2003/08/16 11:43:57 davidxu Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include "un-namespace.h" + +void (*__cleanup)(); + +void +abort() +{ + struct sigaction act; + + /* + * POSIX requires we flush stdio buffers on abort. + * XXX ISO C requires that abort() be async-signal-safe. + */ + if (__cleanup) + (*__cleanup)(); + + sigfillset(&act.sa_mask); + /* + * Don't block SIGABRT to give any handler a chance; we ignore + * any errors -- ISO C doesn't allow abort to return anyway. + */ + sigdelset(&act.sa_mask, SIGABRT); + (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); + (void)raise(SIGABRT); + + /* + * If SIGABRT was ignored, or caught and the handler returns, do + * it again, only harder. + */ + act.sa_handler = SIG_DFL; + act.sa_flags = 0; + sigfillset(&act.sa_mask); + (void)_sigaction(SIGABRT, &act, NULL); + sigdelset(&act.sa_mask, SIGABRT); + (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); + (void)raise(SIGABRT); + exit(1); +} diff --git a/src/lib/libc/stdlib/abs.c b/src/lib/libc/stdlib/abs.c new file mode 100644 index 0000000..26f87eb --- /dev/null +++ b/src/lib/libc/stdlib/abs.c @@ -0,0 +1,47 @@ +/*- + * 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[] = "@(#)abs.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/abs.c,v 1.2 2002/03/22 21:53:09 obrien Exp $"); + +#include + +int +abs(j) + int j; +{ + return(j < 0 ? -j : j); +} diff --git a/src/lib/libc/stdlib/atexit.c b/src/lib/libc/stdlib/atexit.c new file mode 100644 index 0000000..bd94bcd --- /dev/null +++ b/src/lib/libc/stdlib/atexit.c @@ -0,0 +1,189 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)atexit.c 8.2 (Berkeley) 7/3/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/atexit.c,v 1.7 2003/12/19 17:11:20 kan Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "atexit.h" +#include "un-namespace.h" + +#include "libc_private.h" + +#define ATEXIT_FN_EMPTY 0 +#define ATEXIT_FN_STD 1 +#define ATEXIT_FN_CXA 2 + +static pthread_mutex_t atexit_mutex = PTHREAD_MUTEX_INITIALIZER; + +#define _MUTEX_LOCK(x) if (__isthreaded) _pthread_mutex_lock(x) +#define _MUTEX_UNLOCK(x) if (__isthreaded) _pthread_mutex_unlock(x) + +struct atexit { + struct atexit *next; /* next in list */ + int ind; /* next index in this table */ + struct atexit_fn { + int fn_type; /* ATEXIT_? from above */ + union { + void (*std_func)(void); + void (*cxa_func)(void *); + } fn_ptr; /* function pointer */ + void *fn_arg; /* argument for CXA callback */ + void *fn_dso; /* shared module handle */ + } fns[ATEXIT_SIZE]; /* the table itself */ +}; + +static struct atexit *__atexit; /* points to head of LIFO stack */ + +/* + * Register the function described by 'fptr' to be called at application + * exit or owning shared object unload time. This is a helper function + * for atexit and __cxa_atexit. + */ +static int +atexit_register(struct atexit_fn *fptr) +{ + static struct atexit __atexit0; /* one guaranteed table */ + struct atexit *p; + + _MUTEX_LOCK(&atexit_mutex); + if ((p = __atexit) == NULL) + __atexit = p = &__atexit0; + else while (p->ind >= ATEXIT_SIZE) { + struct atexit *old__atexit; + old__atexit = __atexit; + _MUTEX_UNLOCK(&atexit_mutex); + if ((p = (struct atexit *)malloc(sizeof(*p))) == NULL) + return (-1); + _MUTEX_LOCK(&atexit_mutex); + if (old__atexit != __atexit) { + /* Lost race, retry operation */ + _MUTEX_UNLOCK(&atexit_mutex); + free(p); + _MUTEX_LOCK(&atexit_mutex); + p = __atexit; + continue; + } + p->ind = 0; + p->next = __atexit; + __atexit = p; + } + p->fns[p->ind++] = *fptr; + _MUTEX_UNLOCK(&atexit_mutex); + return 0; +} + +/* + * Register a function to be performed at exit. + */ +int +atexit(void (*func)(void)) +{ + struct atexit_fn fn; + int error; + + fn.fn_type = ATEXIT_FN_STD; + fn.fn_ptr.std_func = func;; + fn.fn_arg = NULL; + fn.fn_dso = NULL; + + error = atexit_register(&fn); + return (error); +} + +/* + * Register a function to be performed at exit or when an shared object + * with given dso handle is unloaded dynamically. + */ +int +__cxa_atexit(void (*func)(void *), void *arg, void *dso) +{ + struct atexit_fn fn; + int error; + + fn.fn_type = ATEXIT_FN_CXA; + fn.fn_ptr.cxa_func = func;; + fn.fn_arg = arg; + fn.fn_dso = dso; + + error = atexit_register(&fn); + return (error); +} + +/* + * Call all handlers registered with __cxa_atexit for the shared + * object owning 'dso'. Note: if 'dso' is NULL, then all remaining + * handlers are called. + */ +void +__cxa_finalize(void *dso) +{ + struct atexit *p; + struct atexit_fn fn; + int n; + + _MUTEX_LOCK(&atexit_mutex); + for (p = __atexit; p; p = p->next) { + for (n = p->ind; --n >= 0;) { + if (p->fns[n].fn_type == ATEXIT_FN_EMPTY) + continue; /* already been called */ + if (dso != NULL && dso != p->fns[n].fn_dso) + continue; /* wrong DSO */ + fn = p->fns[n]; + /* + Mark entry to indicate that this particular handler + has already been called. + */ + p->fns[n].fn_type = ATEXIT_FN_EMPTY; + _MUTEX_UNLOCK(&atexit_mutex); + + /* Call the function of correct type. */ + if (fn.fn_type == ATEXIT_FN_CXA) + fn.fn_ptr.cxa_func(fn.fn_arg); + else if (fn.fn_type == ATEXIT_FN_STD) + fn.fn_ptr.std_func(); + _MUTEX_LOCK(&atexit_mutex); + } + } + _MUTEX_UNLOCK(&atexit_mutex); +} diff --git a/src/lib/libc/stdlib/atexit.h b/src/lib/libc/stdlib/atexit.h new file mode 100644 index 0000000..cd30b3f --- /dev/null +++ b/src/lib/libc/stdlib/atexit.h @@ -0,0 +1,40 @@ +/*- + * 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. + * + * @(#)atexit.h 8.2 (Berkeley) 7/3/94 + * $FreeBSD: src/lib/libc/stdlib/atexit.h,v 1.3 2003/12/19 17:11:20 kan Exp $ + */ + +/* must be at least 32 to guarantee ANSI conformance */ +#define ATEXIT_SIZE 32 + +void __cxa_finalize(void *dso); diff --git a/src/lib/libc/stdlib/atof.c b/src/lib/libc/stdlib/atof.c new file mode 100644 index 0000000..ca69ab6 --- /dev/null +++ b/src/lib/libc/stdlib/atof.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)atof.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/atof.c,v 1.5 2004/02/10 20:42:32 cperciva Exp $"); + +#include + +double +atof(ascii) + const char *ascii; +{ + return strtod(ascii, (char **)NULL); +} diff --git a/src/lib/libc/stdlib/atoi.c b/src/lib/libc/stdlib/atoi.c new file mode 100644 index 0000000..3da2fda --- /dev/null +++ b/src/lib/libc/stdlib/atoi.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)atoi.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/atoi.c,v 1.5 2002/03/22 21:53:09 obrien Exp $"); + +#include + +int +atoi(str) + const char *str; +{ + return (int)strtol(str, (char **)NULL, 10); +} diff --git a/src/lib/libc/stdlib/atol.c b/src/lib/libc/stdlib/atol.c new file mode 100644 index 0000000..c66c04e --- /dev/null +++ b/src/lib/libc/stdlib/atol.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)atol.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/atol.c,v 1.4 2002/03/22 21:53:09 obrien Exp $"); + +#include + +long +atol(str) + const char *str; +{ + return strtol(str, (char **)NULL, 10); +} diff --git a/src/lib/libc/stdlib/atoll.c b/src/lib/libc/stdlib/atoll.c new file mode 100644 index 0000000..b7c38b8 --- /dev/null +++ b/src/lib/libc/stdlib/atoll.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1988, 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/atoll.c,v 1.4 2002/03/22 21:53:10 obrien Exp $"); + +#include + +long long +atoll(str) + const char *str; +{ + return strtoll(str, (char **)NULL, 10); +} diff --git a/src/lib/libc/stdlib/bsearch.c b/src/lib/libc/stdlib/bsearch.c new file mode 100644 index 0000000..7717582 --- /dev/null +++ b/src/lib/libc/stdlib/bsearch.c @@ -0,0 +1,83 @@ +/* + * 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[] = "@(#)bsearch.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/bsearch.c,v 1.3 2002/03/21 22:48:41 obrien Exp $"); + +#include +#include + +/* + * Perform a binary search. + * + * The code below is a bit sneaky. After a comparison fails, we + * divide the work in half by moving either left or right. If lim + * is odd, moving left simply involves halving lim: e.g., when lim + * is 5 we look at item 2, so we change lim to 2 so that we will + * look at items 0 & 1. If lim is even, the same applies. If lim + * is odd, moving right again involes halving lim, this time moving + * the base up one item past p: e.g., when lim is 5 we change base + * to item 3 and make lim 2 so that we will look at items 3 and 4. + * If lim is even, however, we have to shrink it by one before + * halving: e.g., when lim is 4, we still looked at item 2, so we + * have to make lim 3, then halve, obtaining 1, so that we will only + * look at item 3. + */ +void * +bsearch(key, base0, nmemb, size, compar) + const void *key; + const void *base0; + size_t nmemb; + size_t size; + int (*compar)(const void *, const void *); +{ + const char *base = base0; + size_t lim; + int cmp; + const void *p; + + for (lim = nmemb; lim != 0; lim >>= 1) { + p = base + (lim >> 1) * size; + cmp = (*compar)(key, p); + if (cmp == 0) + return ((void *)p); + if (cmp > 0) { /* key > p: move right */ + base = (char *)p + size; + lim--; + } /* else move left */ + } + return (NULL); +} diff --git a/src/lib/libc/stdlib/calloc.c b/src/lib/libc/stdlib/calloc.c new file mode 100644 index 0000000..0bdbb23 --- /dev/null +++ b/src/lib/libc/stdlib/calloc.c @@ -0,0 +1,61 @@ +/*- + * 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[] = "@(#)calloc.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/calloc.c,v 1.7 2002/08/04 04:11:48 ache Exp $"); + +#include +#include +#include +#include + +void * +calloc(num, size) + size_t num; + size_t size; +{ + void *p; + + if (size != 0 && SIZE_T_MAX / size < num) { + errno = ENOMEM; + return (NULL); + } + + size *= num; + if ( (p = malloc(size)) ) + bzero(p, size); + return(p); +} diff --git a/src/lib/libc/stdlib/div.c b/src/lib/libc/stdlib/div.c new file mode 100644 index 0000000..54278d6 --- /dev/null +++ b/src/lib/libc/stdlib/div.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)div.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/div.c,v 1.2 2002/03/22 21:53:10 obrien Exp $"); + +#include /* div_t */ + +div_t +div(num, denom) + int num, denom; +{ + div_t r; + + r.quot = num / denom; + r.rem = num % denom; + /* + * The ANSI standard says that |r.quot| <= |n/d|, where + * n/d is to be computed in infinite precision. In other + * words, we should always truncate the quotient towards + * 0, never -infinity. + * + * Machine division and remainer may work either way when + * one or both of n or d is negative. If only one is + * negative and r.quot has been truncated towards -inf, + * r.rem will have the same sign as denom and the opposite + * sign of num; if both are negative and r.quot has been + * truncated towards -inf, r.rem will be positive (will + * have the opposite sign of num). These are considered + * `wrong'. + * + * If both are num and denom are positive, r will always + * be positive. + * + * This all boils down to: + * if num >= 0, but r.rem < 0, we got the wrong answer. + * In that case, to get the right answer, add 1 to r.quot and + * subtract denom from r.rem. + */ + if (num >= 0 && r.rem < 0) { + r.quot++; + r.rem -= denom; + } + return (r); +} diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c new file mode 100644 index 0000000..e71b3db --- /dev/null +++ b/src/lib/libc/stdlib/exit.c @@ -0,0 +1,73 @@ +/*- + * 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[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/exit.c,v 1.7 2003/12/19 17:11:20 kan Exp $"); + +#include "namespace.h" +#include +#include +#include "un-namespace.h" +#include "atexit.h" + +void (*__cleanup)(); + +/* + * This variable is zero until a process has created a thread. + * It is used to avoid calling locking functions in libc when they + * are not required. By default, libc is intended to be(come) + * thread-safe, but without a (significant) penalty to non-threaded + * processes. + */ +int __isthreaded = 0; + +/* + * Exit, flushing stdio buffers if necessary. + */ +void +exit(status) + int status; +{ + /* Ensure that the auto-initialization routine is linked in: */ + extern int _thread_autoinit_dummy_decl; + + _thread_autoinit_dummy_decl = 1; + + __cxa_finalize(NULL); + if (__cleanup) + (*__cleanup)(); + _exit(status); +} diff --git a/src/lib/libc/stdlib/getenv.c b/src/lib/libc/stdlib/getenv.c new file mode 100644 index 0000000..aa15989 --- /dev/null +++ b/src/lib/libc/stdlib/getenv.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 1987, 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[] = "@(#)getenv.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/getenv.c,v 1.4 2002/03/21 22:48:41 obrien Exp $"); + +#include +#include +#include + +inline char *__findenv(const char *, int *); + +/* + * __findenv -- + * Returns pointer to value associated with name, if any, else NULL. + * Sets offset to be the offset of the name/value combination in the + * environmental array, for use by setenv(3) and unsetenv(3). + * Explicitly removes '=' in argument name. + * + * This routine *should* be a static; don't use it. + */ +inline char * +__findenv(name, offset) + const char *name; + int *offset; +{ + extern char **environ; + int len, i; + const char *np; + char **p, *cp; + + if (name == NULL || environ == NULL) + return (NULL); + for (np = name; *np && *np != '='; ++np) + continue; + len = np - name; + for (p = environ; (cp = *p) != NULL; ++p) { + for (np = name, i = len; i && *cp; i--) + if (*cp++ != *np++) + break; + if (i == 0 && *cp++ == '=') { + *offset = p - environ; + return (cp); + } + } + return (NULL); +} + +/* + * getenv -- + * Returns ptr to value associated with name, if any, else NULL. + */ +char * +getenv(name) + const char *name; +{ + int offset; + + return (__findenv(name, &offset)); +} diff --git a/src/lib/libc/stdlib/getopt.c b/src/lib/libc/stdlib/getopt.c new file mode 100644 index 0000000..efcfa0a --- /dev/null +++ b/src/lib/libc/stdlib/getopt.c @@ -0,0 +1,139 @@ +/* $NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $ */ + +/* + * Copyright (c) 1987, 1993, 1994 + * 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[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt.c,v 1.7 2004/03/06 17:05:45 ache Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include "un-namespace.h" + +#include "libc_private.h" + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt(nargc, nargv, ostr) + int nargc; + char * const nargv[]; + const char *ostr; +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || *place == 0) { /* update scanning pointer */ + optreset = 0; + place = nargv[optind]; + if (optind >= nargc || *place++ != '-') { + /* Argument is absent or is not an option */ + place = EMSG; + return (-1); + } + optopt = *place++; + if (optopt == '-' && *place == 0) { + /* "--" => end of options */ + ++optind; + place = EMSG; + return (-1); + } + if (optopt == 0) { + /* Solitary '-', treat as a '-' option + if the program (eg su) is looking for it. */ + place = EMSG; + if (strchr(ostr, '-') == NULL) + return (-1); + optopt = '-'; + } + } else + optopt = *place++; + + /* See if option letter is one the caller wanted... */ + if (optopt == ':' || (oli = strchr(ostr, optopt)) == NULL) { + if (*place == 0) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "%s: illegal option -- %c\n", _getprogname(), + optopt); + return (BADCH); + } + + /* Does this option need an argument? */ + if (oli[1] != ':') { + /* don't need argument */ + optarg = NULL; + if (*place == 0) + ++optind; + } else { + /* Option-argument is either the rest of this argument or the + entire next argument. */ + if (*place) + optarg = place; + else if (nargc > ++optind) + optarg = nargv[optind]; + else { + /* option-argument absent */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "%s: option requires an argument -- %c\n", + _getprogname(), optopt); + return (BADCH); + } + place = EMSG; + ++optind; + } + return (optopt); /* return option letter */ +} diff --git a/src/lib/libc/stdlib/getopt_long.c b/src/lib/libc/stdlib/getopt_long.c new file mode 100644 index 0000000..1de02d4 --- /dev/null +++ b/src/lib/libc/stdlib/getopt_long.c @@ -0,0 +1,641 @@ +/* $OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $ */ +/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ + +/* + * Copyright (c) 2002 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt_long.c,v 1.11 2004/04/01 22:32:28 ache Exp $"); + +#include +#include +#include +#include +#include + +#define GNU_COMPATIBLE /* Be more compatible, configure's use us! */ + +#ifndef GNU_COMPATIBLE +#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */ +#endif + +#ifdef REPLACE_GETOPT +int opterr = 1; /* if error message should be printed */ +int optind = 1; /* index into parent argv vector */ +int optopt = '?'; /* character checked for validity */ +int optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ +#endif + +#define PRINT_ERROR ((opterr) && (*options != ':')) + +#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ +#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */ +#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */ + +/* return values */ +#define BADCH (int)'?' +#define BADARG ((*options == ':') ? (int)':' : (int)'?') +#define INORDER (int)1 + +#define EMSG "" + +#ifdef GNU_COMPATIBLE +#define NO_PREFIX (-1) +#define D_PREFIX 0 +#define DD_PREFIX 1 +#define W_PREFIX 2 +#endif + +static int getopt_internal(int, char * const *, const char *, + const struct option *, int *, int); +static int parse_long_options(char * const *, const char *, + const struct option *, int *, int, int); +static int gcd(int, int); +static void permute_args(int, int, int, char * const *); + +static char *place = EMSG; /* option letter processing */ + +/* XXX: set optreset to 1 rather than these two */ +static int nonopt_start = -1; /* first non option argument (for permute) */ +static int nonopt_end = -1; /* first option after non options (for permute) */ + +/* Error messages */ +static const char recargchar[] = "option requires an argument -- %c"; +static const char illoptchar[] = "illegal option -- %c"; /* From P1003.2 */ +#ifdef GNU_COMPATIBLE +static int dash_prefix = NO_PREFIX; +static const char gnuoptchar[] = "invalid option -- %c"; + +static const char recargstring[] = "option `%s%s' requires an argument"; +static const char ambig[] = "option `%s%.*s' is ambiguous"; +static const char noarg[] = "option `%s%.*s' doesn't allow an argument"; +static const char illoptstring[] = "unrecognized option `%s%s'"; +#else +static const char recargstring[] = "option requires an argument -- %s"; +static const char ambig[] = "ambiguous option -- %.*s"; +static const char noarg[] = "option doesn't take an argument -- %.*s"; +static const char illoptstring[] = "unknown option -- %s"; +#endif + +/* + * Compute the greatest common divisor of a and b. + */ +static int +gcd(int a, int b) +{ + int c; + + c = a % b; + while (c != 0) { + a = b; + b = c; + c = a % b; + } + + return (b); +} + +/* + * Exchange the block from nonopt_start to nonopt_end with the block + * from nonopt_end to opt_end (keeping the same order of arguments + * in each block). + */ +static void +permute_args(int panonopt_start, int panonopt_end, int opt_end, + char * const *nargv) +{ + int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; + char *swap; + + /* + * compute lengths of blocks and number and size of cycles + */ + nnonopts = panonopt_end - panonopt_start; + nopts = opt_end - panonopt_end; + ncycle = gcd(nnonopts, nopts); + cyclelen = (opt_end - panonopt_start) / ncycle; + + for (i = 0; i < ncycle; i++) { + cstart = panonopt_end+i; + pos = cstart; + for (j = 0; j < cyclelen; j++) { + if (pos >= panonopt_end) + pos -= nnonopts; + else + pos += nopts; + swap = nargv[pos]; + /* LINTED const cast */ + ((char **) nargv)[pos] = nargv[cstart]; + /* LINTED const cast */ + ((char **)nargv)[cstart] = swap; + } + } +} + +/* + * parse_long_options -- + * Parse long options in argc/argv argument vector. + * Returns -1 if short_too is set and the option does not match long_options. + */ +static int +parse_long_options(char * const *nargv, const char *options, + const struct option *long_options, int *idx, int short_too, int flags) +{ + char *current_argv, *has_equal; +#ifdef GNU_COMPATIBLE + char *current_dash; +#endif + size_t current_argv_len; + int i, match, exact_match, second_partial_match; + + current_argv = place; +#ifdef GNU_COMPATIBLE + switch (dash_prefix) { + case D_PREFIX: + current_dash = "-"; + break; + case DD_PREFIX: + current_dash = "--"; + break; + case W_PREFIX: + current_dash = "-W "; + break; + default: + current_dash = ""; + break; + } +#endif + match = -1; + exact_match = 0; + second_partial_match = 0; + + optind++; + + if ((has_equal = strchr(current_argv, '=')) != NULL) { + /* argument found (--option=arg) */ + current_argv_len = has_equal - current_argv; + has_equal++; + } else + current_argv_len = strlen(current_argv); + + for (i = 0; long_options[i].name; i++) { + /* find matching long option */ + if (strncmp(current_argv, long_options[i].name, + current_argv_len)) + continue; + + if (strlen(long_options[i].name) == current_argv_len) { + /* exact match */ + match = i; + exact_match = 1; + break; + } + /* + * If this is a known short option, don't allow + * a partial match of a single character. + */ + if (short_too && current_argv_len == 1) + continue; + + if (match == -1) /* first partial match */ + match = i; + else if ((flags & FLAG_LONGONLY) || + long_options[i].has_arg != + long_options[match].has_arg || + long_options[i].flag != long_options[match].flag || + long_options[i].val != long_options[match].val) + second_partial_match = 1; + } + if (!exact_match && second_partial_match) { + /* ambiguous abbreviation */ + if (PRINT_ERROR) + warnx(ambig, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + (int)current_argv_len, + current_argv); + optopt = 0; + return (BADCH); + } + if (match != -1) { /* option found */ + if (long_options[match].has_arg == no_argument + && has_equal) { + if (PRINT_ERROR) + warnx(noarg, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + (int)current_argv_len, + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; +#ifdef GNU_COMPATIBLE + return (BADCH); +#else + return (BADARG); +#endif + } + if (long_options[match].has_arg == required_argument || + long_options[match].has_arg == optional_argument) { + if (has_equal) + optarg = has_equal; + else if (long_options[match].has_arg == + required_argument) { + /* + * optional argument doesn't use next nargv + */ + optarg = nargv[optind++]; + } + } + if ((long_options[match].has_arg == required_argument) + && (optarg == NULL)) { + /* + * Missing argument; leading ':' indicates no error + * should be generated. + */ + if (PRINT_ERROR) + warnx(recargstring, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + current_argv); + /* + * XXX: GNU sets optopt to val regardless of flag + */ + if (long_options[match].flag == NULL) + optopt = long_options[match].val; + else + optopt = 0; + --optind; + return (BADARG); + } + } else { /* unknown option */ + if (short_too) { + --optind; + return (-1); + } + if (PRINT_ERROR) + warnx(illoptstring, +#ifdef GNU_COMPATIBLE + current_dash, +#endif + current_argv); + optopt = 0; + return (BADCH); + } + if (idx) + *idx = match; + if (long_options[match].flag) { + *long_options[match].flag = long_options[match].val; + return (0); + } else + return (long_options[match].val); +} + +/* + * getopt_internal -- + * Parse argc/argv argument vector. Called by user level routines. + */ +static int +getopt_internal(int nargc, char * const *nargv, const char *options, + const struct option *long_options, int *idx, int flags) +{ + char *oli; /* option letter list index */ + int optchar, short_too; + int posixly_correct; + + if (options == NULL) + return (-1); + + /* + * Disable GNU extensions if POSIXLY_CORRECT is set or options + * string begins with a '+'. + */ + posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); +#ifdef GNU_COMPATIBLE + if (*options == '-') + flags |= FLAG_ALLARGS; + else if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; +#else + if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; + else if (*options == '-') + flags |= FLAG_ALLARGS; +#endif + if (*options == '+' || *options == '-') + options++; + + /* + * XXX Some GNU programs (like cvs) set optind to 0 instead of + * XXX using optreset. Work around this braindamage. + */ + if (optind == 0) + optind = optreset = 1; + + optarg = NULL; + if (optreset) + nonopt_start = nonopt_end = -1; +start: + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc) { /* end of argument vector */ + place = EMSG; + if (nonopt_end != -1) { + /* do permutation, if we have to */ + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + else if (nonopt_start != -1) { + /* + * If we skipped non-options, set optind + * to the first of them. + */ + optind = nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + if (*(place = nargv[optind]) != '-' || +#ifdef GNU_COMPATIBLE + place[1] == '\0') { +#else + (place[1] == '\0' && strchr(options, '-') == NULL)) { +#endif + place = EMSG; /* found non-option */ + if (flags & FLAG_ALLARGS) { + /* + * GNU extension: + * return non-option as argument to option 1 + */ + optarg = nargv[optind++]; + return (INORDER); + } + if (!(flags & FLAG_PERMUTE)) { + /* + * If no permutation wanted, stop parsing + * at first non-option. + */ + return (-1); + } + /* do permutation */ + if (nonopt_start == -1) + nonopt_start = optind; + else if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + nonopt_start = optind - + (nonopt_end - nonopt_start); + nonopt_end = -1; + } + optind++; + /* process next argument */ + goto start; + } + if (nonopt_start != -1 && nonopt_end == -1) + nonopt_end = optind; + + /* + * If we have "-" do nothing, if "--" we are done. + */ + if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { + optind++; + place = EMSG; + /* + * We found an option (--), so if we skipped + * non-options, we have to permute. + */ + if (nonopt_end != -1) { + permute_args(nonopt_start, nonopt_end, + optind, nargv); + optind -= nonopt_end - nonopt_start; + } + nonopt_start = nonopt_end = -1; + return (-1); + } + } + + /* + * Check long options if: + * 1) we were passed some + * 2) the arg is not just "-" + * 3) either the arg starts with -- we are getopt_long_only() + */ + if (long_options != NULL && place != nargv[optind] && + (*place == '-' || (flags & FLAG_LONGONLY))) { + short_too = 0; +#ifdef GNU_COMPATIBLE + dash_prefix = D_PREFIX; +#endif + if (*place == '-') { + place++; /* --foo long option */ +#ifdef GNU_COMPATIBLE + dash_prefix = DD_PREFIX; +#endif + } else if (*place != ':' && strchr(options, *place) != NULL) + short_too = 1; /* could be short option too */ + + optchar = parse_long_options(nargv, options, long_options, + idx, short_too, flags); + if (optchar != -1) { + place = EMSG; + return (optchar); + } + } + + if ((optchar = (int)*place++) == (int)':' || + (optchar == (int)'-' && *place != '\0') || + (oli = strchr(options, optchar)) == NULL) { + /* + * If the user specified "-" and '-' isn't listed in + * options, return -1 (non-option) as per POSIX. + * Otherwise, it is an unknown option character (or ':'). + */ + if (optchar == (int)'-' && *place == '\0') + return (-1); + if (!*place) + ++optind; +#ifdef GNU_COMPATIBLE + if (PRINT_ERROR) + warnx(posixly_correct ? illoptchar : gnuoptchar, + optchar); +#else + if (PRINT_ERROR) + warnx(illoptchar, optchar); +#endif + optopt = optchar; + return (BADCH); + } + if (long_options != NULL && optchar == 'W' && oli[1] == ';') { + /* -W long-option */ + if (*place) /* no space */ + /* NOTHING */; + else if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else /* white space */ + place = nargv[optind]; +#ifdef GNU_COMPATIBLE + dash_prefix = W_PREFIX; +#endif + optchar = parse_long_options(nargv, options, long_options, + idx, 0, flags); + place = EMSG; + return (optchar); + } + if (*++oli != ':') { /* doesn't take argument */ + if (!*place) + ++optind; + } else { /* takes (optional) argument */ + optarg = NULL; + if (*place) /* no white space */ + optarg = place; + /* XXX: disable test for :: if PC? (GNU doesn't) */ + else if (oli[1] != ':') { /* arg not optional */ + if (++optind >= nargc) { /* no arg */ + place = EMSG; + if (PRINT_ERROR) + warnx(recargchar, optchar); + optopt = optchar; + return (BADARG); + } else + optarg = nargv[optind]; + } else if (!(flags & FLAG_PERMUTE)) { + /* + * If permutation is disabled, we can accept an + * optional arg separated by whitespace. + */ + if (optind + 1 < nargc) + optarg = nargv[++optind]; + } + place = EMSG; + ++optind; + } + /* dump back option letter */ + return (optchar); +} + +#ifdef REPLACE_GETOPT +/* + * getopt -- + * Parse argc/argv argument vector. + * + * [eventually this will replace the BSD getopt] + */ +int +getopt(int nargc, char * const *nargv, const char *options) +{ + + /* + * We don't pass FLAG_PERMUTE to getopt_internal() since + * the BSD getopt(3) (unlike GNU) has never done this. + * + * Furthermore, since many privileged programs call getopt() + * before dropping privileges it makes sense to keep things + * as simple (and bug-free) as possible. + */ + return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); +} +#endif /* REPLACE_GETOPT */ + +/* + * getopt_long -- + * Parse argc/argv argument vector. + */ +int +getopt_long(nargc, nargv, options, long_options, idx) + int nargc; + char * const *nargv; + const char *options; + const struct option *long_options; + int *idx; +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE)); +} + +/* + * getopt_long_only -- + * Parse argc/argv argument vector. + */ +int +getopt_long_only(nargc, nargv, options, long_options, idx) + int nargc; + char * const *nargv; + const char *options; + const struct option *long_options; + int *idx; +{ + + return (getopt_internal(nargc, nargv, options, long_options, idx, + FLAG_PERMUTE|FLAG_LONGONLY)); +} diff --git a/src/lib/libc/stdlib/getsubopt.c b/src/lib/libc/stdlib/getsubopt.c new file mode 100644 index 0000000..488706a --- /dev/null +++ b/src/lib/libc/stdlib/getsubopt.c @@ -0,0 +1,101 @@ +/*- + * 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[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/getsubopt.c,v 1.6 2004/02/23 03:30:02 ache Exp $"); + +#include +#include + +/* + * The SVID interface to getsubopt provides no way of figuring out which + * part of the suboptions list wasn't matched. This makes error messages + * tricky... The extern variable suboptarg is a pointer to the token + * which didn't match. + */ +char *suboptarg; + +int +getsubopt(optionp, tokens, valuep) + char **optionp, **valuep; + char * const *tokens; +{ + int cnt; + char *p; + + suboptarg = *valuep = NULL; + + if (!optionp || !*optionp) + return(-1); + + /* skip leading white-space, commas */ + for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + + if (!*p) { + *optionp = p; + return(-1); + } + + /* save the start of the token, and skip the rest of the token. */ + for (suboptarg = p; + *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); + + if (*p) { + /* + * If there's an equals sign, set the value pointer, and + * skip over the value part of the token. Terminate the + * token. + */ + if (*p == '=') { + *p = '\0'; + for (*valuep = ++p; + *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); + if (*p) + *p++ = '\0'; + } else + *p++ = '\0'; + /* Skip any whitespace or commas after this token. */ + for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + } + + /* set optionp for next round. */ + *optionp = p; + + for (cnt = 0; *tokens; ++tokens, ++cnt) + if (!strcmp(suboptarg, *tokens)) + return(cnt); + return(-1); +} diff --git a/src/lib/libc/stdlib/grantpt.c b/src/lib/libc/stdlib/grantpt.c new file mode 100644 index 0000000..9902c54 --- /dev/null +++ b/src/lib/libc/stdlib/grantpt.c @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2002 The FreeBSD Project, Inc. + * All rights reserved. + * + * This software includes code contributed to the FreeBSD Project + * by Ryan Younce of North Carolina State University. + * + * 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. Neither the name of the FreeBSD Project 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 FREEBSD PROJECT 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 FREEBSD PROJECT OR ITS 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. + */ + +#include +#ifndef lint +__FBSDID("$FreeBSD: src/lib/libc/stdlib/grantpt.c,v 1.2 2003/01/04 08:10:55 tjr Exp $"); +#endif /* not lint */ + +#include "namespace.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +#define PTM_MAJOR 6 /* pseudo tty master major */ +#define PTS_MAJOR 5 /* pseudo tty slave major */ +#define PTM_PREFIX "pty" /* pseudo tty master naming convention */ +#define PTS_PREFIX "tty" /* pseudo tty slave naming convention */ + +/* + * The following are range values for pseudo TTY devices. Pseudo TTYs have a + * name of /dev/[pt]ty[p-sP-S][0-9a-v], yielding 256 combinations per major. + */ +#define PT_MAX 256 +#define PT_DEV1 "pqrsPQRS" +#define PT_DEV2 "0123456789abcdefghijklmnopqrstuv" + +/* + * grantpt(3) support utility. + */ +#define _PATH_PTCHOWN "/usr/libexec/pt_chown" + +/* + * ISPTM(x) returns 0 for struct stat x if x is not a pty master. + * The bounds checking may be unnecessary but it does eliminate doubt. + */ +#define ISPTM(x) (S_ISCHR((x).st_mode) && \ + major((x).st_rdev) == PTM_MAJOR && \ + minor((x).st_rdev) >= 0 && \ + minor((x).st_rdev) < PT_MAX) + +/* + * grantpt(): grant ownership of a slave pseudo-terminal device to the + * current user. + */ + +int +grantpt(int fildes) +{ + int retval, serrno, status; + pid_t pid, spid; + gid_t gid; + char *slave; + sigset_t oblock, nblock; + struct group *grp; + + retval = -1; + serrno = errno; + + if ((slave = ptsname(fildes)) != NULL) { + /* + * Block SIGCHLD. + */ + (void)sigemptyset(&nblock); + (void)sigaddset(&nblock, SIGCHLD); + (void)_sigprocmask(SIG_BLOCK, &nblock, &oblock); + + switch (pid = fork()) { + case -1: + break; + case 0: /* child */ + /* + * pt_chown expects the master pseudo TTY to be its + * standard input. + */ + (void)_dup2(fildes, STDIN_FILENO); + (void)_sigprocmask(SIG_SETMASK, &oblock, NULL); + execl(_PATH_PTCHOWN, _PATH_PTCHOWN, (char *)NULL); + _exit(EX_UNAVAILABLE); + /* NOTREACHED */ + default: /* parent */ + /* + * Just wait for the process. Error checking is + * done below. + */ + while ((spid = _waitpid(pid, &status, 0)) == -1 && + (errno == EINTR)) + ; + if (spid != -1 && WIFEXITED(status) && + WEXITSTATUS(status) == EX_OK) + retval = 0; + else + errno = EACCES; + break; + } + + /* + * Restore process's signal mask. + */ + (void)_sigprocmask(SIG_SETMASK, &oblock, NULL); + + if (retval) { + /* + * pt_chown failed. Try to manually change the + * permissions for the slave. + */ + gid = (grp = getgrnam("tty")) ? grp->gr_gid : -1; + if (chown(slave, getuid(), gid) == -1 || + chmod(slave, S_IRUSR | S_IWUSR | S_IWGRP) == -1) + errno = EACCES; + else + retval = 0; + } + } + + if (!retval) + errno = serrno; + + return (retval); +} + +/* + * posix_openpt(): open the first available master pseudo-terminal device + * and return descriptor. + */ +int +posix_openpt(int oflag) +{ + char *mc1, *mc2, master[] = _PATH_DEV PTM_PREFIX "XY"; + const char *pc1, *pc2; + int fildes, bflag, serrno; + + fildes = -1; + bflag = 0; + serrno = errno; + + /* + * Check flag validity. POSIX doesn't require it, + * but we still do so. + */ + if (oflag & ~(O_RDWR | O_NOCTTY)) + errno = EINVAL; + else { + mc1 = master + strlen(_PATH_DEV PTM_PREFIX); + mc2 = mc1 + 1; + + /* Cycle through all possible master PTY devices. */ + for (pc1 = PT_DEV1; !bflag && (*mc1 = *pc1); ++pc1) + for (pc2 = PT_DEV2; (*mc2 = *pc2) != '\0'; ++pc2) { + /* + * Break out if we successfully open a PTY, + * or if open() fails due to limits. + */ + if ((fildes = _open(master, oflag)) != -1 || + (errno == EMFILE || errno == ENFILE)) { + ++bflag; + break; + } + } + + if (fildes != -1) + errno = serrno; + else if (!bflag) + errno = EAGAIN; + } + + return (fildes); +} + +/* + * ptsname(): return the pathname of the slave pseudo-terminal device + * associated with the specified master. + */ +char * +ptsname(int fildes) +{ + static char slave[] = _PATH_DEV PTS_PREFIX "XY"; + char *retval; + struct stat sbuf; + + retval = NULL; + + if (_fstat(fildes, &sbuf) == 0) { + if (!ISPTM(sbuf)) + errno = EINVAL; + else { + (void)sprintf(slave, _PATH_DEV PTS_PREFIX "%c%c", + PT_DEV1[minor(sbuf.st_rdev) / 32], + PT_DEV2[minor(sbuf.st_rdev) % 32]); + retval = slave; + } + } + + return (retval); +} + +/* + * unlockpt(): unlock a pseudo-terminal device pair. + */ +int +unlockpt(int fildes) +{ + int retval; + struct stat sbuf; + + /* + * Unlocking a master/slave pseudo-terminal pair has no meaning in a + * non-streams PTY environment. However, we do ensure fildes is a + * valid master pseudo-terminal device. + */ + if ((retval = _fstat(fildes, &sbuf)) == 0 && !ISPTM(sbuf)) { + errno = EINVAL; + retval = -1; + } + + return (retval); +} diff --git a/src/lib/libc/stdlib/hcreate.c b/src/lib/libc/stdlib/hcreate.c new file mode 100644 index 0000000..6ab33e5 --- /dev/null +++ b/src/lib/libc/stdlib/hcreate.c @@ -0,0 +1,185 @@ +/* $NetBSD: hcreate.c,v 1.2 2001/02/19 21:26:04 ross Exp $ */ + +/* + * Copyright (c) 2001 Christopher G. Demetriou + * 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 for the + * NetBSD Project. See http://www.netbsd.org/ for + * information about NetBSD. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * <> + */ + +/* + * hcreate() / hsearch() / hdestroy() + * + * SysV/XPG4 hash table functions. + * + * Implementation done based on NetBSD manual page and Solaris manual page, + * plus my own personal experience about how they're supposed to work. + * + * I tried to look at Knuth (as cited by the Solaris manual page), but + * nobody had a copy in the office, so... + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: hcreate.c,v 1.2 2001/02/19 21:26:04 ross Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/stdlib/hcreate.c,v 1.3 2002/06/27 13:18:27 deischen Exp $"); + +#include +#include +#include +#include +#include +#include + +/* + * DO NOT MAKE THIS STRUCTURE LARGER THAN 32 BYTES (4 ptrs on 64-bit + * ptr machine) without adjusting MAX_BUCKETS_LG2 below. + */ +struct internal_entry { + SLIST_ENTRY(internal_entry) link; + ENTRY ent; +}; +SLIST_HEAD(internal_head, internal_entry); + +#define MIN_BUCKETS_LG2 4 +#define MIN_BUCKETS (1 << MIN_BUCKETS_LG2) + +/* + * max * sizeof internal_entry must fit into size_t. + * assumes internal_entry is <= 32 (2^5) bytes. + */ +#define MAX_BUCKETS_LG2 (sizeof (size_t) * 8 - 1 - 5) +#define MAX_BUCKETS ((size_t)1 << MAX_BUCKETS_LG2) + +/* Default hash function, from db/hash/hash_func.c */ +extern u_int32_t (*__default_hash)(const void *, size_t); + +static struct internal_head *htable; +static size_t htablesize; + +int +hcreate(size_t nel) +{ + size_t idx; + unsigned int p2; + + /* Make sure this this isn't called when a table already exists. */ + if (htable != NULL) { + errno = EINVAL; + return 0; + } + + /* If nel is too small, make it min sized. */ + if (nel < MIN_BUCKETS) + nel = MIN_BUCKETS; + + /* If it's too large, cap it. */ + if (nel > MAX_BUCKETS) + nel = MAX_BUCKETS; + + /* If it's is not a power of two in size, round up. */ + if ((nel & (nel - 1)) != 0) { + for (p2 = 0; nel != 0; p2++) + nel >>= 1; + nel = 1 << p2; + } + + /* Allocate the table. */ + htablesize = nel; + htable = malloc(htablesize * sizeof htable[0]); + if (htable == NULL) { + errno = ENOMEM; + return 0; + } + + /* Initialize it. */ + for (idx = 0; idx < htablesize; idx++) + SLIST_INIT(&htable[idx]); + + return 1; +} + +void +hdestroy(void) +{ + struct internal_entry *ie; + size_t idx; + + if (htable == NULL) + return; + + for (idx = 0; idx < htablesize; idx++) { + while (!SLIST_EMPTY(&htable[idx])) { + ie = SLIST_FIRST(&htable[idx]); + SLIST_REMOVE_HEAD(&htable[idx], link); + free(ie->ent.key); + free(ie); + } + } + free(htable); + htable = NULL; +} + +ENTRY * +hsearch(ENTRY item, ACTION action) +{ + struct internal_head *head; + struct internal_entry *ie; + uint32_t hashval; + size_t len; + + len = strlen(item.key); + hashval = (*__default_hash)(item.key, len); + + head = &htable[hashval & (htablesize - 1)]; + ie = SLIST_FIRST(head); + while (ie != NULL) { + if (strcmp(ie->ent.key, item.key) == 0) + break; + ie = SLIST_NEXT(ie, link); + } + + if (ie != NULL) + return &ie->ent; + else if (action == FIND) + return NULL; + + ie = malloc(sizeof *ie); + if (ie == NULL) + return NULL; + ie->ent.key = item.key; + ie->ent.data = item.data; + + SLIST_INSERT_HEAD(head, ie, link); + return &ie->ent; +} diff --git a/src/lib/libc/stdlib/heapsort.c b/src/lib/libc/stdlib/heapsort.c new file mode 100644 index 0000000..e846be2 --- /dev/null +++ b/src/lib/libc/stdlib/heapsort.c @@ -0,0 +1,185 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ronnie Kon at Mindcraft Inc., Kevin Lew and Elmer Yglesias. + * + * 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[] = "@(#)heapsort.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/heapsort.c,v 1.4 2002/03/21 22:48:41 obrien Exp $"); + +#include +#include +#include + +/* + * Swap two areas of size number of bytes. Although qsort(3) permits random + * blocks of memory to be sorted, sorting pointers is almost certainly the + * common case (and, were it not, could easily be made so). Regardless, it + * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer + * arithmetic gets lost in the time required for comparison function calls. + */ +#define SWAP(a, b, count, size, tmp) { \ + count = size; \ + do { \ + tmp = *a; \ + *a++ = *b; \ + *b++ = tmp; \ + } while (--count); \ +} + +/* Copy one block of size size to another. */ +#define COPY(a, b, count, size, tmp1, tmp2) { \ + count = size; \ + tmp1 = a; \ + tmp2 = b; \ + do { \ + *tmp1++ = *tmp2++; \ + } while (--count); \ +} + +/* + * Build the list into a heap, where a heap is defined such that for + * the records K1 ... KN, Kj/2 >= Kj for 1 <= j/2 <= j <= N. + * + * There two cases. If j == nmemb, select largest of Ki and Kj. If + * j < nmemb, select largest of Ki, Kj and Kj+1. + */ +#define CREATE(initval, nmemb, par_i, child_i, par, child, size, count, tmp) { \ + for (par_i = initval; (child_i = par_i * 2) <= nmemb; \ + par_i = child_i) { \ + child = base + child_i * size; \ + if (child_i < nmemb && compar(child, child + size) < 0) { \ + child += size; \ + ++child_i; \ + } \ + par = base + par_i * size; \ + if (compar(child, par) <= 0) \ + break; \ + SWAP(par, child, count, size, tmp); \ + } \ +} + +/* + * Select the top of the heap and 'heapify'. Since by far the most expensive + * action is the call to the compar function, a considerable optimization + * in the average case can be achieved due to the fact that k, the displaced + * elememt, is ususally quite small, so it would be preferable to first + * heapify, always maintaining the invariant that the larger child is copied + * over its parent's record. + * + * Then, starting from the *bottom* of the heap, finding k's correct place, + * again maintianing the invariant. As a result of the invariant no element + * is 'lost' when k is assigned its correct place in the heap. + * + * The time savings from this optimization are on the order of 15-20% for the + * average case. See Knuth, Vol. 3, page 158, problem 18. + * + * XXX Don't break the #define SELECT line, below. Reiser cpp gets upset. + */ +#define SELECT(par_i, child_i, nmemb, par, child, size, k, count, tmp1, tmp2) { \ + for (par_i = 1; (child_i = par_i * 2) <= nmemb; par_i = child_i) { \ + child = base + child_i * size; \ + if (child_i < nmemb && compar(child, child + size) < 0) { \ + child += size; \ + ++child_i; \ + } \ + par = base + par_i * size; \ + COPY(par, child, count, size, tmp1, tmp2); \ + } \ + for (;;) { \ + child_i = par_i; \ + par_i = child_i / 2; \ + child = base + child_i * size; \ + par = base + par_i * size; \ + if (child_i == 1 || compar(k, par) < 0) { \ + COPY(child, k, count, size, tmp1, tmp2); \ + break; \ + } \ + COPY(child, par, count, size, tmp1, tmp2); \ + } \ +} + +/* + * Heapsort -- Knuth, Vol. 3, page 145. Runs in O (N lg N), both average + * and worst. While heapsort is faster than the worst case of quicksort, + * the BSD quicksort does median selection so that the chance of finding + * a data set that will trigger the worst case is nonexistent. Heapsort's + * only advantage over quicksort is that it requires little additional memory. + */ +int +heapsort(vbase, nmemb, size, compar) + void *vbase; + size_t nmemb, size; + int (*compar)(const void *, const void *); +{ + int cnt, i, j, l; + char tmp, *tmp1, *tmp2; + char *base, *k, *p, *t; + + if (nmemb <= 1) + return (0); + + if (!size) { + errno = EINVAL; + return (-1); + } + + if ((k = malloc(size)) == NULL) + return (-1); + + /* + * Items are numbered from 1 to nmemb, so offset from size bytes + * below the starting address. + */ + base = (char *)vbase - size; + + for (l = nmemb / 2 + 1; --l;) + CREATE(l, nmemb, i, j, t, p, size, cnt, tmp); + + /* + * For each element of the heap, save the largest element into its + * final slot, save the displaced element (k), then recreate the + * heap. + */ + while (nmemb > 1) { + COPY(k, base + nmemb * size, cnt, size, tmp1, tmp2); + COPY(base + nmemb * size, base + size, cnt, size, tmp1, tmp2); + --nmemb; + SELECT(i, j, nmemb, t, p, size, k, cnt, tmp1, tmp2); + } + free(k); + return (0); +} diff --git a/src/lib/libc/stdlib/imaxabs.c b/src/lib/libc/stdlib/imaxabs.c new file mode 100644 index 0000000..531de24 --- /dev/null +++ b/src/lib/libc/stdlib/imaxabs.c @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/imaxabs.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); + +#include + +intmax_t +imaxabs(intmax_t j) +{ + return (j < 0 ? -j : j); +} diff --git a/src/lib/libc/stdlib/imaxdiv.c b/src/lib/libc/stdlib/imaxdiv.c new file mode 100644 index 0000000..ff3087b --- /dev/null +++ b/src/lib/libc/stdlib/imaxdiv.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/imaxdiv.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); + +#include + +/* See comments in div.c for implementation details. */ +imaxdiv_t +imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t retval; + + retval.quot = numer / denom; + retval.rem = numer % denom; + if (numer >= 0 && retval.rem < 0) { + retval.quot++; + retval.rem -= denom; + } + return (retval); +} diff --git a/src/lib/libc/stdlib/insque.c b/src/lib/libc/stdlib/insque.c new file mode 100644 index 0000000..92984b0 --- /dev/null +++ b/src/lib/libc/stdlib/insque.c @@ -0,0 +1,47 @@ +/* + * Initial implementation: + * Copyright (c) 2002 Robert Drehmel + * All rights reserved. + * + * As long as the above copyright statement and this notice remain + * unchanged, you can do what ever you want with this file. + */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/insque.c,v 1.3 2003/01/04 07:34:41 tjr Exp $"); + +#define _SEARCH_PRIVATE +#include +#ifdef DEBUG +#include +#else +#include /* for NULL */ +#endif + +void +insque(void *element, void *pred) +{ + struct que_elem *prev, *next, *elem; + + elem = (struct que_elem *)element; + prev = (struct que_elem *)pred; + + if (prev == NULL) { + elem->prev = elem->next = NULL; + return; + } + + next = prev->next; + if (next != NULL) { +#ifdef DEBUG + if (next->prev != prev) { + fprintf(stderr, "insque: Inconsistency detected:" + " next(%p)->prev(%p) != prev(%p)\n", + next, next->prev, prev); + } +#endif + next->prev = elem; + } + prev->next = elem; + elem->prev = prev; + elem->next = next; +} diff --git a/src/lib/libc/stdlib/labs.c b/src/lib/libc/stdlib/labs.c new file mode 100644 index 0000000..42e63d1 --- /dev/null +++ b/src/lib/libc/stdlib/labs.c @@ -0,0 +1,47 @@ +/*- + * 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[] = "@(#)labs.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/labs.c,v 1.2 2002/03/22 21:53:10 obrien Exp $"); + +#include + +long +labs(j) + long j; +{ + return(j < 0 ? -j : j); +} diff --git a/src/lib/libc/stdlib/ldiv.c b/src/lib/libc/stdlib/ldiv.c new file mode 100644 index 0000000..560d5c2 --- /dev/null +++ b/src/lib/libc/stdlib/ldiv.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)ldiv.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/ldiv.c,v 1.2 2002/03/22 21:53:10 obrien Exp $"); + +#include /* ldiv_t */ + +ldiv_t +ldiv(num, denom) + long num, denom; +{ + ldiv_t r; + + /* see div.c for comments */ + + r.quot = num / denom; + r.rem = num % denom; + if (num >= 0 && r.rem < 0) { + r.quot++; + r.rem -= denom; + } + return (r); +} diff --git a/src/lib/libc/stdlib/llabs.c b/src/lib/libc/stdlib/llabs.c new file mode 100644 index 0000000..4721fce --- /dev/null +++ b/src/lib/libc/stdlib/llabs.c @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/llabs.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); + +#include + +long long +llabs(long long j) +{ + return (j < 0 ? -j : j); +} diff --git a/src/lib/libc/stdlib/lldiv.c b/src/lib/libc/stdlib/lldiv.c new file mode 100644 index 0000000..c9a4853 --- /dev/null +++ b/src/lib/libc/stdlib/lldiv.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/lldiv.c,v 1.1 2001/11/15 02:05:03 mike Exp $"); + +#include + +/* See comments in div.c for implementation details. */ +lldiv_t +lldiv(long long numer, long long denom) +{ + lldiv_t retval; + + retval.quot = numer / denom; + retval.rem = numer % denom; + if (numer >= 0 && retval.rem < 0) { + retval.quot++; + retval.rem -= denom; + } + return (retval); +} diff --git a/src/lib/libc/stdlib/lsearch.c b/src/lib/libc/stdlib/lsearch.c new file mode 100644 index 0000000..791bc49 --- /dev/null +++ b/src/lib/libc/stdlib/lsearch.c @@ -0,0 +1,64 @@ +/* + * Initial implementation: + * Copyright (c) 2002 Robert Drehmel + * All rights reserved. + * + * As long as the above copyright statement and this notice remain + * unchanged, you can do what ever you want with this file. + */ +#include +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/lsearch.c,v 1.1 2002/10/16 14:29:22 robert Exp $"); + +#define _SEARCH_PRIVATE +#include +#include /* for uint8_t */ +#include /* for NULL */ +#include /* for memcpy() prototype */ + +static void *lwork(const void *, const void *, size_t *, size_t, + int (*)(const void *, const void *), int); + +void *lsearch(const void *key, void *base, size_t *nelp, size_t width, + int (*compar)(const void *, const void *)) +{ + + return (lwork(key, base, nelp, width, compar, 1)); +} + +void *lfind(const void *key, const void *base, size_t *nelp, size_t width, + int (*compar)(const void *, const void *)) +{ + + return (lwork(key, base, nelp, width, compar, 0)); +} + +static void * +lwork(const void *key, const void *base, size_t *nelp, size_t width, + int (*compar)(const void *, const void *), int addelem) +{ + uint8_t *ep, *endp; + + /* + * Cast to an integer value first to avoid the warning for removing + * 'const' via a cast. + */ + ep = (uint8_t *)(uintptr_t)base; + for (endp = (uint8_t *)(ep + width * *nelp); ep < endp; ep += width) { + if (compar(key, ep) == 0) + return (ep); + } + + /* lfind() shall return when the key was not found. */ + if (!addelem) + return (NULL); + + /* + * lsearch() adds the key to the end of the table and increments + * the number of elements. + */ + memcpy(endp, key, width); + ++*nelp; + + return (endp); +} diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c new file mode 100644 index 0000000..c1b75a6 --- /dev/null +++ b/src/lib/libc/stdlib/malloc.c @@ -0,0 +1,1168 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.88 2004/05/14 11:50:51 cognet Exp $"); + +/* + * Defining MALLOC_EXTRA_SANITY will enable extra checks which are related + * to internal conditions and consistency in malloc.c. This has a + * noticeable runtime performance hit, and generally will not do you + * any good unless you fiddle with the internals of malloc or want + * to catch random pointer corruption as early as possible. + */ +#ifndef MALLOC_EXTRA_SANITY +#undef MALLOC_EXTRA_SANITY +#endif + +/* + * What to use for Junk. This is the byte value we use to fill with + * when the 'J' option is enabled. + */ +#define SOME_JUNK 0xd0 /* as in "Duh" :-) */ + +/* + * The basic parameters you can tweak. + * + * malloc_pageshift pagesize = 1 << malloc_pageshift + * It's probably best if this is the native + * page size, but it doesn't have to be. + * + * malloc_minsize minimum size of an allocation in bytes. + * If this is too small it's too much work + * to manage them. This is also the smallest + * unit of alignment used for the storage + * returned by malloc/realloc. + * + */ + +#include "namespace.h" +#if defined(__FreeBSD__) +# if defined(__i386__) +# define malloc_pageshift 12U +# define malloc_minsize 16U +# endif +# if defined(__ia64__) +# define malloc_pageshift 13U +# define malloc_minsize 16U +# endif +# if defined(__alpha__) +# define malloc_pageshift 13U +# define malloc_minsize 16U +# endif +# if defined(__sparc64__) +# define malloc_pageshift 13U +# define malloc_minsize 16U +# endif +# if defined(__amd64__) +# define malloc_pageshift 12U +# define malloc_minsize 16U +# endif +# if defined(__arm__) +# define malloc_pageshift 12U +# define malloc_minsize 16U +# endif +# define HAS_UTRACE + /* + * Make malloc/free/realloc thread-safe in libc for use with + * kernel threads. + */ +# include "libc_private.h" +# include "spinlock.h" + static spinlock_t thread_lock = _SPINLOCK_INITIALIZER; + spinlock_t *__malloc_lock = &thread_lock; +# define _MALLOC_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock); +# define _MALLOC_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock); +#endif /* __FreeBSD__ */ + +#if defined(__sparc__) && defined(sun) +# define malloc_pageshift 12U +# define malloc_minsize 16U +# define MAP_ANON (0) + static int fdzero; +# define MMAP_FD fdzero +# define INIT_MMAP() \ + { if ((fdzero = _open(_PATH_DEVZERO, O_RDWR, 0000)) == -1) \ + wrterror("open of /dev/zero"); } +# define MADV_FREE MADV_DONTNEED +#endif /* __sparc__ */ + +/* Insert your combination here... */ +#if defined(__FOOCPU__) && defined(__BAROS__) +# define malloc_pageshift 12U +# define malloc_minsize 16U +#endif /* __FOOCPU__ && __BAROS__ */ + +#ifndef ZEROSIZEPTR +#define ZEROSIZEPTR ((void *)(uintptr_t)(1 << (malloc_pageshift - 1))) +#endif + +/* + * No user serviceable parts behind this point. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" + +/* + * This structure describes a page worth of chunks. + */ + +struct pginfo { + struct pginfo *next; /* next on the free list */ + void *page; /* Pointer to the page */ + u_short size; /* size of this page's chunks */ + u_short shift; /* How far to shift for this size chunks */ + u_short free; /* How many free chunks */ + u_short total; /* How many chunk */ + u_int bits[1]; /* Which chunks are free */ +}; + +/* + * This structure describes a number of free pages. + */ + +struct pgfree { + struct pgfree *next; /* next run of free pages */ + struct pgfree *prev; /* prev run of free pages */ + void *page; /* pointer to free pages */ + void *end; /* pointer to end of free pages */ + size_t size; /* number of bytes free */ +}; + +/* + * How many bits per u_int in the bitmap. + * Change only if not 8 bits/byte + */ +#define MALLOC_BITS (8*sizeof(u_int)) + +/* + * Magic values to put in the page_directory + */ +#define MALLOC_NOT_MINE ((struct pginfo*) 0) +#define MALLOC_FREE ((struct pginfo*) 1) +#define MALLOC_FIRST ((struct pginfo*) 2) +#define MALLOC_FOLLOW ((struct pginfo*) 3) +#define MALLOC_MAGIC ((struct pginfo*) 4) + +#ifndef malloc_pageshift +#define malloc_pageshift 12U +#endif + +#ifndef malloc_minsize +#define malloc_minsize 16U +#endif + +#if !defined(malloc_pagesize) +#define malloc_pagesize (1UL<>1) +#endif + +/* A mask for the offset inside a page. */ +#define malloc_pagemask ((malloc_pagesize)-1) + +#define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask))) +#define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo) + +#ifndef _MALLOC_LOCK +#define _MALLOC_LOCK() +#endif + +#ifndef _MALLOC_UNLOCK +#define _MALLOC_UNLOCK() +#endif + +#ifndef MMAP_FD +#define MMAP_FD (-1) +#endif + +#ifndef INIT_MMAP +#define INIT_MMAP() +#endif + +/* Number of free pages we cache */ +static unsigned malloc_cache = 16; + +/* The offset from pagenumber to index into the page directory */ +static u_long malloc_origo; + +/* The last index in the page directory we care about */ +static u_long last_index; + +/* Pointer to page directory. Allocated "as if with" malloc */ +static struct pginfo **page_dir; + +/* How many slots in the page directory */ +static unsigned malloc_ninfo; + +/* Free pages line up here */ +static struct pgfree free_list; + +/* Abort(), user doesn't handle problems. */ +static int malloc_abort = 1; + +/* Are we trying to die ? */ +static int suicide; + +/* always realloc ? */ +static int malloc_realloc; + +#if defined(MADV_FREE) +/* pass the kernel a hint on free pages ? */ +static int malloc_hint = 0; +#endif + +/* xmalloc behaviour ? */ +static int malloc_xmalloc; + +/* sysv behaviour for malloc(0) ? */ +static int malloc_sysv; + +/* zero fill ? */ +static int malloc_zero; + +/* junk fill ? */ +static int malloc_junk = 1; + +#ifdef HAS_UTRACE + +/* utrace ? */ +static int malloc_utrace; + +struct ut { void *p; size_t s; void *r; }; + +void utrace(struct ut *, int); + +#define UTRACE(a, b, c) \ + if (malloc_utrace) \ + {struct ut u; u.p=a; u.s = b; u.r=c; utrace(&u, sizeof u);} +#else /* !HAS_UTRACE */ +#define UTRACE(a,b,c) +#endif /* HAS_UTRACE */ + +/* my last break. */ +static void *malloc_brk; + +/* one location cache for free-list holders */ +static struct pgfree *px; + +/* compile-time options */ +const char *_malloc_options; + +/* Name of the current public function */ +static const char *malloc_func; + +/* Macro for mmap */ +#define MMAP(size) \ + mmap(NULL, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \ + MMAP_FD, (off_t)0); + +/* + * Necessary function declarations + */ +static int extend_pgdir(u_long index); +static void *imalloc(size_t size); +static void ifree(void *ptr); +static void *irealloc(void *ptr, size_t size); + +static void +wrtmessage(const char *p1, const char *p2, const char *p3, const char *p4) +{ + + _write(STDERR_FILENO, p1, strlen(p1)); + _write(STDERR_FILENO, p2, strlen(p2)); + _write(STDERR_FILENO, p3, strlen(p3)); + _write(STDERR_FILENO, p4, strlen(p4)); +} + +void (*_malloc_message)(const char *p1, const char *p2, const char *p3, + const char *p4) = wrtmessage; + +static void +wrterror(char const *p) +{ + + suicide = 1; + _malloc_message(_getprogname(), malloc_func, " error: ", p); + abort(); +} + +static void +wrtwarning(char *p) +{ + + /* + * Sensitive processes, somewhat arbitrarily defined here as setuid, + * setgid, root and wheel cannot afford to have malloc mistakes. + */ + if (malloc_abort || issetugid() || getuid() == 0 || getgid() == 0) + wrterror(p); + _malloc_message(_getprogname(), malloc_func, " warning: ", p); +} + +/* + * Allocate a number of pages from the OS + */ +static void * +map_pages(size_t pages) +{ + caddr_t result, tail; + + result = (caddr_t)pageround((u_long)sbrk(0)); + tail = result + (pages << malloc_pageshift); + if (tail < result) + return (NULL); + + if (brk(tail)) { +#ifdef MALLOC_EXTRA_SANITY + wrterror("(ES): map_pages fails\n"); +#endif /* MALLOC_EXTRA_SANITY */ + return (NULL); + } + + last_index = ptr2index(tail) - 1; + malloc_brk = tail; + + if ((last_index+1) >= malloc_ninfo && !extend_pgdir(last_index)) + return (NULL); + + return (result); +} + +/* + * Extend page directory + */ +static int +extend_pgdir(u_long index) +{ + struct pginfo **new, **old; + u_long i, oldlen; + + /* Make it this many pages */ + i = index * sizeof *page_dir; + i /= malloc_pagesize; + i += 2; + + /* remember the old mapping size */ + oldlen = malloc_ninfo * sizeof *page_dir; + + /* + * NOTE: we allocate new pages and copy the directory rather than tempt + * fate by trying to "grow" the region.. There is nothing to prevent + * us from accidently re-mapping space that's been allocated by our caller + * via dlopen() or other mmap(). + * + * The copy problem is not too bad, as there is 4K of page index per + * 4MB of malloc arena. + * + * We can totally avoid the copy if we open a file descriptor to associate + * the anon mappings with. Then, when we remap the pages at the new + * address, the old pages will be "magically" remapped.. But this means + * keeping open a "secret" file descriptor..... + */ + + /* Get new pages */ + new = (struct pginfo**) MMAP(i * malloc_pagesize); + if (new == MAP_FAILED) + return (0); + + /* Copy the old stuff */ + memcpy(new, page_dir, + malloc_ninfo * sizeof *page_dir); + + /* register the new size */ + malloc_ninfo = i * malloc_pagesize / sizeof *page_dir; + + /* swap the pointers */ + old = page_dir; + page_dir = new; + + /* Now free the old stuff */ + munmap(old, oldlen); + return (1); +} + +/* + * Initialize the world + */ +static void +malloc_init(void) +{ + const char *p; + char b[64]; + int i, j; + int save_errno = errno; + + INIT_MMAP(); + +#ifdef MALLOC_EXTRA_SANITY + malloc_junk = 1; +#endif /* MALLOC_EXTRA_SANITY */ + + for (i = 0; i < 3; i++) { + if (i == 0) { + j = readlink("/etc/malloc.conf", b, sizeof b - 1); + if (j <= 0) + continue; + b[j] = '\0'; + p = b; + } else if (i == 1 && issetugid() == 0) { + p = getenv("MALLOC_OPTIONS"); + } else if (i == 1) { + continue; + } else { + p = _malloc_options; + } + for (; p != NULL && *p != '\0'; p++) { + switch (*p) { + case '>': malloc_cache <<= 1; break; + case '<': malloc_cache >>= 1; break; + case 'a': malloc_abort = 0; break; + case 'A': malloc_abort = 1; break; +#if defined(MADV_FREE) + case 'h': malloc_hint = 0; break; + case 'H': malloc_hint = 1; break; +#endif + case 'r': malloc_realloc = 0; break; + case 'R': malloc_realloc = 1; break; + case 'j': malloc_junk = 0; break; + case 'J': malloc_junk = 1; break; +#ifdef HAS_UTRACE + case 'u': malloc_utrace = 0; break; + case 'U': malloc_utrace = 1; break; +#endif + case 'v': malloc_sysv = 0; break; + case 'V': malloc_sysv = 1; break; + case 'x': malloc_xmalloc = 0; break; + case 'X': malloc_xmalloc = 1; break; + case 'z': malloc_zero = 0; break; + case 'Z': malloc_zero = 1; break; + default: + _malloc_message(_getprogname(), malloc_func, + " warning: ", "unknown char in MALLOC_OPTIONS\n"); + break; + } + } + } + + + UTRACE(0, 0, 0); + + /* + * We want junk in the entire allocation, and zero only in the part + * the user asked for. + */ + if (malloc_zero) + malloc_junk=1; + + /* Allocate one page for the page directory */ + page_dir = (struct pginfo **) MMAP(malloc_pagesize); + + if (page_dir == MAP_FAILED) + wrterror("mmap(2) failed, check limits\n"); + + /* + * We need a maximum of malloc_pageshift buckets, steal these from the + * front of the page_directory; + */ + malloc_origo = ((u_long)pageround((u_long)sbrk(0))) >> malloc_pageshift; + malloc_origo -= malloc_pageshift; + + malloc_ninfo = malloc_pagesize / sizeof *page_dir; + + /* Recalculate the cache size in bytes, and make sure it's nonzero */ + + if (!malloc_cache) + malloc_cache++; + + malloc_cache <<= malloc_pageshift; + + /* + * This is a nice hack from Kaleb Keithly (kaleb@x.org). + * We can sbrk(2) further back when we keep this on a low address. + */ + px = (struct pgfree *) imalloc (sizeof *px); + errno = save_errno; +} + +/* + * Allocate a number of complete pages + */ +static void * +malloc_pages(size_t size) +{ + void *p, *delay_free = NULL; + size_t i; + struct pgfree *pf; + u_long index; + + size = pageround(size); + + p = NULL; + + /* Look for free pages before asking for more */ + for(pf = free_list.next; pf; pf = pf->next) { + +#ifdef MALLOC_EXTRA_SANITY + if (pf->size & malloc_pagemask) + wrterror("(ES): junk length entry on free_list\n"); + if (!pf->size) + wrterror("(ES): zero length entry on free_list\n"); + if (pf->page == pf->end) + wrterror("(ES): zero entry on free_list\n"); + if (pf->page > pf->end) + wrterror("(ES): sick entry on free_list\n"); + if ((void*)pf->page >= (void*)sbrk(0)) + wrterror("(ES): entry on free_list past brk\n"); + if (page_dir[ptr2index(pf->page)] != MALLOC_FREE) + wrterror("(ES): non-free first page on free-list\n"); + if (page_dir[ptr2index(pf->end)-1] != MALLOC_FREE) + wrterror("(ES): non-free last page on free-list\n"); +#endif /* MALLOC_EXTRA_SANITY */ + + if (pf->size < size) + continue; + + if (pf->size == size) { + p = pf->page; + if (pf->next != NULL) + pf->next->prev = pf->prev; + pf->prev->next = pf->next; + delay_free = pf; + break; + } + + p = pf->page; + pf->page = (char *)pf->page + size; + pf->size -= size; + break; + } + +#ifdef MALLOC_EXTRA_SANITY + if (p != NULL && page_dir[ptr2index(p)] != MALLOC_FREE) + wrterror("(ES): allocated non-free page on free-list\n"); +#endif /* MALLOC_EXTRA_SANITY */ + + size >>= malloc_pageshift; + + /* Map new pages */ + if (p == NULL) + p = map_pages(size); + + if (p != NULL) { + + index = ptr2index(p); + page_dir[index] = MALLOC_FIRST; + for (i=1;ibits[0] * + (((malloc_pagesize >> bits)+MALLOC_BITS-1) / MALLOC_BITS); + + /* Don't waste more than two chunks on this */ + if ((1<<(bits)) <= l+l) { + bp = (struct pginfo *)pp; + } else { + bp = (struct pginfo *)imalloc(l); + if (bp == NULL) { + ifree(pp); + return (0); + } + } + + bp->size = (1<shift = bits; + bp->total = bp->free = malloc_pagesize >> bits; + bp->page = pp; + + /* set all valid bits in the bitmap */ + k = bp->total; + i = 0; + + /* Do a bunch at a time */ + for(;k-i >= MALLOC_BITS; i += MALLOC_BITS) + bp->bits[i / MALLOC_BITS] = ~0; + + for(; i < k; i++) + bp->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS); + + if (bp == bp->page) { + /* Mark the ones we stole for ourselves */ + for(i=0;l > 0;i++) { + bp->bits[i/MALLOC_BITS] &= ~(1<<(i%MALLOC_BITS)); + bp->free--; + bp->total--; + l -= (1 << bits); + } + } + + /* MALLOC_LOCK */ + + page_dir[ptr2index(pp)] = bp; + + bp->next = page_dir[bits]; + page_dir[bits] = bp; + + /* MALLOC_UNLOCK */ + + return (1); +} + +/* + * Allocate a fragment + */ +static void * +malloc_bytes(size_t size) +{ + int i,j; + u_int u; + struct pginfo *bp; + int k; + u_int *lp; + + /* Don't bother with anything less than this */ + if (size < malloc_minsize) + size = malloc_minsize; + + /* Find the right bucket */ + j = 1; + i = size-1; + while (i >>= 1) + j++; + + /* If it's empty, make a page more of that size chunks */ + if (page_dir[j] == NULL && !malloc_make_chunks(j)) + return (NULL); + + bp = page_dir[j]; + + /* Find first word of bitmap which isn't empty */ + for (lp = bp->bits; !*lp; lp++) + ; + + /* Find that bit, and tweak it */ + u = 1; + k = 0; + while (!(*lp & u)) { + u += u; + k++; + } + *lp ^= u; + + /* If there are no more free, remove from free-list */ + if (!--bp->free) { + page_dir[j] = bp->next; + bp->next = NULL; + } + + /* Adjust to the real offset of that chunk */ + k += (lp-bp->bits)*MALLOC_BITS; + k <<= bp->shift; + + if (malloc_junk) + memset((u_char *)bp->page + k, SOME_JUNK, bp->size); + + return ((u_char *)bp->page + k); +} + +/* + * Allocate a piece of memory + */ +static void * +imalloc(size_t size) +{ + void *result; + + if (suicide) + abort(); + + if ((size + malloc_pagesize) < size) /* Check for overflow */ + result = NULL; + else if ((size + malloc_pagesize) >= (uintptr_t)page_dir) + result = NULL; + else if (size <= malloc_maxsize) + result = malloc_bytes(size); + else + result = malloc_pages(size); + + if (malloc_zero && result != NULL) + memset(result, 0, size); + + return (result); +} + +/* + * Change the size of an allocation. + */ +static void * +irealloc(void *ptr, size_t size) +{ + void *p; + u_long osize, index; + struct pginfo **mp; + int i; + + if (suicide) + abort(); + + index = ptr2index(ptr); + + if (index < malloc_pageshift) { + wrtwarning("junk pointer, too low to make sense\n"); + return (NULL); + } + + if (index > last_index) { + wrtwarning("junk pointer, too high to make sense\n"); + return (NULL); + } + + mp = &page_dir[index]; + + if (*mp == MALLOC_FIRST) { /* Page allocation */ + + /* Check the pointer */ + if ((u_long)ptr & malloc_pagemask) { + wrtwarning("modified (page-) pointer\n"); + return (NULL); + } + + /* Find the size in bytes */ + for (osize = malloc_pagesize; *(++mp) == MALLOC_FOLLOW;) + osize += malloc_pagesize; + + if (!malloc_realloc && /* Unless we have to, */ + size <= osize && /* .. or are too small, */ + size > (osize - malloc_pagesize)) { /* .. or can free a page, */ + if (malloc_junk) + memset((u_char *)ptr + size, SOME_JUNK, osize-size); + return (ptr); /* ..don't do anything else. */ + } + + } else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */ + + /* Check the pointer for sane values */ + if (((u_long)ptr & ((*mp)->size-1))) { + wrtwarning("modified (chunk-) pointer\n"); + return (NULL); + } + + /* Find the chunk index in the page */ + i = ((u_long)ptr & malloc_pagemask) >> (*mp)->shift; + + /* Verify that it isn't a free chunk already */ + if ((*mp)->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) { + wrtwarning("chunk is already free\n"); + return (NULL); + } + + osize = (*mp)->size; + + if (!malloc_realloc && /* Unless we have to, */ + size <= osize && /* ..or are too small, */ + (size > osize/2 || /* ..or could use a smaller size, */ + osize == malloc_minsize)) { /* ..(if there is one) */ + if (malloc_junk) + memset((u_char *)ptr + size, SOME_JUNK, osize-size); + return (ptr); /* ..don't do anything else. */ + } + + } else { + wrtwarning("pointer to wrong page\n"); + return (NULL); + } + + p = imalloc(size); + + if (p != NULL) { + /* copy the lesser of the two sizes, and free the old one */ + if (!size || !osize) + ; + else if (osize < size) + memcpy(p, ptr, osize); + else + memcpy(p, ptr, size); + ifree(ptr); + } + return (p); +} + +/* + * Free a sequence of pages + */ + +static __inline__ void +free_pages(void *ptr, u_long index, struct pginfo const *info) +{ + u_long i; + struct pgfree *pf, *pt=NULL; + u_long l; + void *tail; + + if (info == MALLOC_FREE) { + wrtwarning("page is already free\n"); + return; + } + + if (info != MALLOC_FIRST) { + wrtwarning("pointer to wrong page\n"); + return; + } + + if ((u_long)ptr & malloc_pagemask) { + wrtwarning("modified (page-) pointer\n"); + return; + } + + /* Count how many pages and mark them free at the same time */ + page_dir[index] = MALLOC_FREE; + for (i = 1; page_dir[index+i] == MALLOC_FOLLOW; i++) + page_dir[index + i] = MALLOC_FREE; + + l = i << malloc_pageshift; + + if (malloc_junk) + memset(ptr, SOME_JUNK, l); + +#if defined(MADV_FREE) + if (malloc_hint) + madvise(ptr, l, MADV_FREE); +#endif + + tail = (char *)ptr+l; + + /* add to free-list */ + if (px == NULL) + px = imalloc(sizeof *px); /* This cannot fail... */ + px->page = ptr; + px->end = tail; + px->size = l; + if (free_list.next == NULL) { + + /* Nothing on free list, put this at head */ + px->next = free_list.next; + px->prev = &free_list; + free_list.next = px; + pf = px; + px = NULL; + + } else { + + /* Find the right spot, leave pf pointing to the modified entry. */ + tail = (char *)ptr+l; + + for(pf = free_list.next; pf->end < ptr && pf->next != NULL; + pf = pf->next) + ; /* Race ahead here */ + + if (pf->page > tail) { + /* Insert before entry */ + px->next = pf; + px->prev = pf->prev; + pf->prev = px; + px->prev->next = px; + pf = px; + px = NULL; + } else if (pf->end == ptr ) { + /* Append to the previous entry */ + pf->end = (char *)pf->end + l; + pf->size += l; + if (pf->next != NULL && pf->end == pf->next->page ) { + /* And collapse the next too. */ + pt = pf->next; + pf->end = pt->end; + pf->size += pt->size; + pf->next = pt->next; + if (pf->next != NULL) + pf->next->prev = pf; + } + } else if (pf->page == tail) { + /* Prepend to entry */ + pf->size += l; + pf->page = ptr; + } else if (pf->next == NULL) { + /* Append at tail of chain */ + px->next = NULL; + px->prev = pf; + pf->next = px; + pf = px; + px = NULL; + } else { + wrterror("freelist is destroyed\n"); + } + } + + /* Return something to OS ? */ + if (pf->next == NULL && /* If we're the last one, */ + pf->size > malloc_cache && /* ..and the cache is full, */ + pf->end == malloc_brk && /* ..and none behind us, */ + malloc_brk == sbrk(0)) { /* ..and it's OK to do... */ + + /* + * Keep the cache intact. Notice that the '>' above guarantees that + * the pf will always have at least one page afterwards. + */ + pf->end = (char *)pf->page + malloc_cache; + pf->size = malloc_cache; + + brk(pf->end); + malloc_brk = pf->end; + + index = ptr2index(pf->end); + + for(i=index;i <= last_index;) + page_dir[i++] = MALLOC_NOT_MINE; + + last_index = index - 1; + + /* XXX: We could realloc/shrink the pagedir here I guess. */ + } + if (pt != NULL) + ifree(pt); +} + +/* + * Free a chunk, and possibly the page it's on, if the page becomes empty. + */ + +static __inline__ void +free_bytes(void *ptr, u_long index, struct pginfo *info) +{ + int i; + struct pginfo **mp; + void *vp; + + /* Find the chunk number on the page */ + i = ((u_long)ptr & malloc_pagemask) >> info->shift; + + if (((u_long)ptr & (info->size-1))) { + wrtwarning("modified (chunk-) pointer\n"); + return; + } + + if (info->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) { + wrtwarning("chunk is already free\n"); + return; + } + + if (malloc_junk) + memset(ptr, SOME_JUNK, info->size); + + info->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS); + info->free++; + + mp = page_dir + info->shift; + + if (info->free == 1) { + + /* Page became non-full */ + + mp = page_dir + info->shift; + /* Insert in address order */ + while (*mp && (*mp)->next && (*mp)->next->page < info->page) + mp = &(*mp)->next; + info->next = *mp; + *mp = info; + return; + } + + if (info->free != info->total) + return; + + /* Find & remove this page in the queue */ + while (*mp != info) { + mp = &((*mp)->next); +#ifdef MALLOC_EXTRA_SANITY + if (!*mp) + wrterror("(ES): Not on queue\n"); +#endif /* MALLOC_EXTRA_SANITY */ + } + *mp = info->next; + + /* Free the page & the info structure if need be */ + page_dir[ptr2index(info->page)] = MALLOC_FIRST; + vp = info->page; /* Order is important ! */ + if(vp != (void*)info) + ifree(info); + ifree(vp); +} + +static void +ifree(void *ptr) +{ + struct pginfo *info; + u_long index; + + /* This is legal */ + if (ptr == NULL) + return; + + /* If we're already sinking, don't make matters any worse. */ + if (suicide) + return; + + index = ptr2index(ptr); + + if (index < malloc_pageshift) { + wrtwarning("junk pointer, too low to make sense\n"); + return; + } + + if (index > last_index) { + wrtwarning("junk pointer, too high to make sense\n"); + return; + } + + info = page_dir[index]; + + if (info < MALLOC_MAGIC) + free_pages(ptr, index, info); + else + free_bytes(ptr, index, info); + return; +} + +static void * +pubrealloc(void *ptr, size_t size, const char *func) +{ + void *r; + int err = 0; + static int malloc_active; /* Recusion flag for public interface. */ + static unsigned malloc_started; /* Set when initialization has been done */ + + /* + * If a thread is inside our code with a functional lock held, and then + * catches a signal which calls us again, we would get a deadlock if the + * lock is not of a recursive type. + */ + _MALLOC_LOCK(); + malloc_func = func; + if (malloc_active > 0) { + if (malloc_active == 1) { + wrtwarning("recursive call\n"); + malloc_active = 2; + } + _MALLOC_UNLOCK(); + errno = EDOOFUS; + return (NULL); + } + malloc_active = 1; + + if (!malloc_started) { + if (ptr != NULL) { + wrtwarning("malloc() has never been called\n"); + malloc_active = 0; + _MALLOC_UNLOCK(); + errno = EDOOFUS; + return (NULL); + } + malloc_init(); + malloc_started = 1; + } + + if (ptr == ZEROSIZEPTR) + ptr = NULL; + if (malloc_sysv && !size) { + if (ptr != NULL) + ifree(ptr); + r = NULL; + } else if (!size) { + if (ptr != NULL) + ifree(ptr); + r = ZEROSIZEPTR; + } else if (ptr == NULL) { + r = imalloc(size); + err = (r == NULL); + } else { + r = irealloc(ptr, size); + err = (r == NULL); + } + UTRACE(ptr, size, r); + malloc_active = 0; + _MALLOC_UNLOCK(); + if (malloc_xmalloc && err) + wrterror("out of memory\n"); + if (err) + errno = ENOMEM; + return (r); +} + +/* + * These are the public exported interface routines. + */ + +void * +malloc(size_t size) +{ + + return (pubrealloc(NULL, size, " in malloc():")); +} + +void +free(void *ptr) +{ + + pubrealloc(ptr, 0, " in free():"); +} + +void * +realloc(void *ptr, size_t size) +{ + + return (pubrealloc(ptr, size, " in realloc():")); +} + diff --git a/src/lib/libc/stdlib/merge.c b/src/lib/libc/stdlib/merge.c new file mode 100644 index 0000000..711b9cd --- /dev/null +++ b/src/lib/libc/stdlib/merge.c @@ -0,0 +1,352 @@ +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Peter McIlroy. + * + * 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[] = "@(#)merge.c 8.2 (Berkeley) 2/14/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/merge.c,v 1.6 2002/03/21 22:48:42 obrien Exp $"); + +/* + * Hybrid exponential search/linear search merge sort with hybrid + * natural/pairwise first pass. Requires about .3% more comparisons + * for random data than LSMS with pairwise first pass alone. + * It works for objects as small as two bytes. + */ + +#define NATURAL +#define THRESHOLD 16 /* Best choice for natural merge cut-off. */ + +/* #define NATURAL to get hybrid natural merge. + * (The default is pairwise merging.) + */ + +#include + +#include +#include +#include + +static void setup(u_char *, u_char *, size_t, size_t, int (*)()); +static void insertionsort(u_char *, size_t, size_t, int (*)()); + +#define ISIZE sizeof(int) +#define PSIZE sizeof(u_char *) +#define ICOPY_LIST(src, dst, last) \ + do \ + *(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \ + while(src < last) +#define ICOPY_ELT(src, dst, i) \ + do \ + *(int*) dst = *(int*) src, src += ISIZE, dst += ISIZE; \ + while (i -= ISIZE) + +#define CCOPY_LIST(src, dst, last) \ + do \ + *dst++ = *src++; \ + while (src < last) +#define CCOPY_ELT(src, dst, i) \ + do \ + *dst++ = *src++; \ + while (i -= 1) + +/* + * Find the next possible pointer head. (Trickery for forcing an array + * to do double duty as a linked list when objects do not align with word + * boundaries. + */ +/* Assumption: PSIZE is a power of 2. */ +#define EVAL(p) (u_char **) \ + ((u_char *)0 + \ + (((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1))) + +/* + * Arguments are as for qsort. + */ +int +mergesort(base, nmemb, size, cmp) + void *base; + size_t nmemb; + size_t size; + int (*cmp)(const void *, const void *); +{ + int i, sense; + int big, iflag; + u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; + u_char *list2, *list1, *p2, *p, *last, **p1; + + if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ + errno = EINVAL; + return (-1); + } + + if (nmemb == 0) + return (0); + + /* + * XXX + * Stupid subtraction for the Cray. + */ + iflag = 0; + if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE)) + iflag = 1; + + if ((list2 = malloc(nmemb * size + PSIZE)) == NULL) + return (-1); + + list1 = base; + setup(list1, list2, nmemb, size, cmp); + last = list2 + nmemb * size; + i = big = 0; + while (*EVAL(list2) != last) { + l2 = list1; + p1 = EVAL(list1); + for (tp2 = p2 = list2; p2 != last; p1 = EVAL(l2)) { + p2 = *EVAL(p2); + f1 = l2; + f2 = l1 = list1 + (p2 - list2); + if (p2 != last) + p2 = *EVAL(p2); + l2 = list1 + (p2 - list2); + while (f1 < l1 && f2 < l2) { + if ((*cmp)(f1, f2) <= 0) { + q = f2; + b = f1, t = l1; + sense = -1; + } else { + q = f1; + b = f2, t = l2; + sense = 0; + } + if (!big) { /* here i = 0 */ + while ((b += size) < t && cmp(q, b) >sense) + if (++i == 6) { + big = 1; + goto EXPONENTIAL; + } + } else { +EXPONENTIAL: for (i = size; ; i <<= 1) + if ((p = (b + i)) >= t) { + if ((p = t - size) > b && + (*cmp)(q, p) <= sense) + t = p; + else + b = p; + break; + } else if ((*cmp)(q, p) <= sense) { + t = p; + if (i == size) + big = 0; + goto FASTCASE; + } else + b = p; + while (t > b+size) { + i = (((t - b) / size) >> 1) * size; + if ((*cmp)(q, p = b + i) <= sense) + t = p; + else + b = p; + } + goto COPY; +FASTCASE: while (i > size) + if ((*cmp)(q, + p = b + (i >>= 1)) <= sense) + t = p; + else + b = p; +COPY: b = t; + } + i = size; + if (q == f1) { + if (iflag) { + ICOPY_LIST(f2, tp2, b); + ICOPY_ELT(f1, tp2, i); + } else { + CCOPY_LIST(f2, tp2, b); + CCOPY_ELT(f1, tp2, i); + } + } else { + if (iflag) { + ICOPY_LIST(f1, tp2, b); + ICOPY_ELT(f2, tp2, i); + } else { + CCOPY_LIST(f1, tp2, b); + CCOPY_ELT(f2, tp2, i); + } + } + } + if (f2 < l2) { + if (iflag) + ICOPY_LIST(f2, tp2, l2); + else + CCOPY_LIST(f2, tp2, l2); + } else if (f1 < l1) { + if (iflag) + ICOPY_LIST(f1, tp2, l1); + else + CCOPY_LIST(f1, tp2, l1); + } + *p1 = l2; + } + tp2 = list1; /* swap list1, list2 */ + list1 = list2; + list2 = tp2; + last = list2 + nmemb*size; + } + if (base == list2) { + memmove(list2, list1, nmemb*size); + list2 = list1; + } + free(list2); + return (0); +} + +#define swap(a, b) { \ + s = b; \ + i = size; \ + do { \ + tmp = *a; *a++ = *s; *s++ = tmp; \ + } while (--i); \ + a -= size; \ + } +#define reverse(bot, top) { \ + s = top; \ + do { \ + i = size; \ + do { \ + tmp = *bot; *bot++ = *s; *s++ = tmp; \ + } while (--i); \ + s -= size2; \ + } while(bot < s); \ +} + +/* + * Optional hybrid natural/pairwise first pass. Eats up list1 in runs of + * increasing order, list2 in a corresponding linked list. Checks for runs + * when THRESHOLD/2 pairs compare with same sense. (Only used when NATURAL + * is defined. Otherwise simple pairwise merging is used.) + */ +void +setup(list1, list2, n, size, cmp) + size_t n, size; + int (*cmp)(const void *, const void *); + u_char *list1, *list2; +{ + int i, length, size2, tmp, sense; + u_char *f1, *f2, *s, *l2, *last, *p2; + + size2 = size*2; + if (n <= 5) { + insertionsort(list1, n, size, cmp); + *EVAL(list2) = (u_char*) list2 + n*size; + return; + } + /* + * Avoid running pointers out of bounds; limit n to evens + * for simplicity. + */ + i = 4 + (n & 1); + insertionsort(list1 + (n - i) * size, i, size, cmp); + last = list1 + size * (n - i); + *EVAL(list2 + (last - list1)) = list2 + n * size; + +#ifdef NATURAL + p2 = list2; + f1 = list1; + sense = (cmp(f1, f1 + size) > 0); + for (; f1 < last; sense = !sense) { + length = 2; + /* Find pairs with same sense. */ + for (f2 = f1 + size2; f2 < last; f2 += size2) { + if ((cmp(f2, f2+ size) > 0) != sense) + break; + length += 2; + } + if (length < THRESHOLD) { /* Pairwise merge */ + do { + p2 = *EVAL(p2) = f1 + size2 - list1 + list2; + if (sense > 0) + swap (f1, f1 + size); + } while ((f1 += size2) < f2); + } else { /* Natural merge */ + l2 = f2; + for (f2 = f1 + size2; f2 < l2; f2 += size2) { + if ((cmp(f2-size, f2) > 0) != sense) { + p2 = *EVAL(p2) = f2 - list1 + list2; + if (sense > 0) + reverse(f1, f2-size); + f1 = f2; + } + } + if (sense > 0) + reverse (f1, f2-size); + f1 = f2; + if (f2 < last || cmp(f2 - size, f2) > 0) + p2 = *EVAL(p2) = f2 - list1 + list2; + else + p2 = *EVAL(p2) = list2 + n*size; + } + } +#else /* pairwise merge only. */ + for (f1 = list1, p2 = list2; f1 < last; f1 += size2) { + p2 = *EVAL(p2) = p2 + size2; + if (cmp (f1, f1 + size) > 0) + swap(f1, f1 + size); + } +#endif /* NATURAL */ +} + +/* + * This is to avoid out-of-bounds addresses in sorting the + * last 4 elements. + */ +static void +insertionsort(a, n, size, cmp) + u_char *a; + size_t n, size; + int (*cmp)(const void *, const void *); +{ + u_char *ai, *s, *t, *u, tmp; + int i; + + for (ai = a+size; --n >= 1; ai += size) + for (t = ai; t > a; t -= size) { + u = t - size; + if (cmp(u, t) <= 0) + break; + swap(u, t); + } +} diff --git a/src/lib/libc/stdlib/putenv.c b/src/lib/libc/stdlib/putenv.c new file mode 100644 index 0000000..c8f3b60 --- /dev/null +++ b/src/lib/libc/stdlib/putenv.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1988, 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[] = "@(#)putenv.c 8.2 (Berkeley) 3/27/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/putenv.c,v 1.2 2002/03/22 21:53:10 obrien Exp $"); + +#include +#include + +int +putenv(str) + const char *str; +{ + char *p, *equal; + int rval; + + if ((p = strdup(str)) == NULL) + return (-1); + if ((equal = index(p, '=')) == NULL) { + (void)free(p); + return (-1); + } + *equal = '\0'; + rval = setenv(p, equal + 1, 1); + (void)free(p); + return (rval); +} diff --git a/src/lib/libc/stdlib/qsort.c b/src/lib/libc/stdlib/qsort.c new file mode 100644 index 0000000..f1add73 --- /dev/null +++ b/src/lib/libc/stdlib/qsort.c @@ -0,0 +1,197 @@ +/*- + * Copyright (c) 1992, 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[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/qsort.c,v 1.12 2002/09/10 02:04:49 wollman Exp $"); + +#include + +#ifdef I_AM_QSORT_R +typedef int cmp_t(void *, const void *, const void *); +#else +typedef int cmp_t(const void *, const void *); +#endif +static inline char *med3(char *, char *, char *, cmp_t *, void *); +static inline void swapfunc(char *, char *, int, int); + +#define min(a, b) (a) < (b) ? a : b + +/* + * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". + */ +#define swapcode(TYPE, parmi, parmj, n) { \ + long i = (n) / sizeof (TYPE); \ + TYPE *pi = (TYPE *) (parmi); \ + TYPE *pj = (TYPE *) (parmj); \ + do { \ + TYPE t = *pi; \ + *pi++ = *pj; \ + *pj++ = t; \ + } while (--i > 0); \ +} + +#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ + es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; + +static inline void +swapfunc(a, b, n, swaptype) + char *a, *b; + int n, swaptype; +{ + if(swaptype <= 1) + swapcode(long, a, b, n) + else + swapcode(char, a, b, n) +} + +#define swap(a, b) \ + if (swaptype == 0) { \ + long t = *(long *)(a); \ + *(long *)(a) = *(long *)(b); \ + *(long *)(b) = t; \ + } else \ + swapfunc(a, b, es, swaptype) + +#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) + +#ifdef I_AM_QSORT_R +#define CMP(t, x, y) (cmp((t), (x), (y))) +#else +#define CMP(t, x, y) (cmp((x), (y))) +#endif + +static inline char * +med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk +#ifndef I_AM_QSORT_R +__unused +#endif +) +{ + return CMP(thunk, a, b) < 0 ? + (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) + :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); +} + +#ifdef I_AM_QSORT_R +void +qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) +#else +#define thunk NULL +void +qsort(void *a, size_t n, size_t es, cmp_t *cmp) +#endif +{ + char *pa, *pb, *pc, *pd, *pl, *pm, *pn; + int d, r, swaptype, swap_cnt; + +loop: SWAPINIT(a, es); + swap_cnt = 0; + if (n < 7) { + for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) + for (pl = pm; + pl > (char *)a && CMP(thunk, pl - es, pl) > 0; + pl -= es) + swap(pl, pl - es); + return; + } + pm = (char *)a + (n / 2) * es; + if (n > 7) { + pl = a; + pn = (char *)a + (n - 1) * es; + if (n > 40) { + d = (n / 8) * es; + pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk); + pm = med3(pm - d, pm, pm + d, cmp, thunk); + pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk); + } + pm = med3(pl, pm, pn, cmp, thunk); + } + swap(a, pm); + pa = pb = (char *)a + es; + + pc = pd = (char *)a + (n - 1) * es; + for (;;) { + while (pb <= pc && (r = CMP(thunk, pb, a)) <= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pa, pb); + pa += es; + } + pb += es; + } + while (pb <= pc && (r = CMP(thunk, pc, a)) >= 0) { + if (r == 0) { + swap_cnt = 1; + swap(pc, pd); + pd -= es; + } + pc -= es; + } + if (pb > pc) + break; + swap(pb, pc); + swap_cnt = 1; + pb += es; + pc -= es; + } + if (swap_cnt == 0) { /* Switch to insertion sort */ + for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) + for (pl = pm; + pl > (char *)a && CMP(thunk, pl - es, pl) > 0; + pl -= es) + swap(pl, pl - es); + return; + } + + pn = (char *)a + n * es; + r = min(pa - (char *)a, pb - pa); + vecswap(a, pb - r, r); + r = min(pd - pc, pn - pd - es); + vecswap(pb, pn - r, r); + if ((r = pb - pa) > es) +#ifdef I_AM_QSORT_R + qsort_r(a, r / es, es, thunk, cmp); +#else + qsort(a, r / es, es, cmp); +#endif + if ((r = pd - pc) > es) { + /* Iterate rather than recurse to save stack space */ + a = pn - r; + n = r / es; + goto loop; + } +/* qsort(pn - r, r / es, es, cmp);*/ +} diff --git a/src/lib/libc/stdlib/qsort_r.c b/src/lib/libc/stdlib/qsort_r.c new file mode 100644 index 0000000..f7c0e54 --- /dev/null +++ b/src/lib/libc/stdlib/qsort_r.c @@ -0,0 +1,8 @@ +/* + * This file is in the public domain. Originally written by Garrett + * A. Wollman. + * + * $FreeBSD: src/lib/libc/stdlib/qsort_r.c,v 1.1 2002/09/10 02:04:49 wollman Exp $ + */ +#define I_AM_QSORT_R +#include "qsort.c" diff --git a/src/lib/libc/stdlib/radixsort.c b/src/lib/libc/stdlib/radixsort.c new file mode 100644 index 0000000..5f9eaeb --- /dev/null +++ b/src/lib/libc/stdlib/radixsort.c @@ -0,0 +1,331 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Peter McIlroy and by Dan Bernstein at New York University, + * + * 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[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/radixsort.c,v 1.7 2003/11/11 04:59:23 kientzle Exp $"); + +/* + * Radixsort routines. + * + * Program r_sort_a() is unstable but uses O(logN) extra memory for a stack. + * Use radixsort(a, n, trace, endchar) for this case. + * + * For stable sorting (using N extra pointers) use sradixsort(), which calls + * r_sort_b(). + * + * For a description of this code, see D. McIlroy, P. McIlroy, K. Bostic, + * "Engineering Radix Sort". + */ + +#include +#include +#include +#include + +typedef struct { + const u_char **sa; + int sn, si; +} stack; + +static inline void simplesort +(const u_char **, int, int, const u_char *, u_int); +static void r_sort_a(const u_char **, int, int, const u_char *, u_int); +static void r_sort_b(const u_char **, const u_char **, int, int, + const u_char *, u_int); + +#define THRESHOLD 20 /* Divert to simplesort(). */ +#define SIZE 512 /* Default stack size. */ + +#define SETUP { \ + if (tab == NULL) { \ + tr = tr0; \ + for (c = 0; c < endch; c++) \ + tr0[c] = c + 1; \ + tr0[c] = 0; \ + for (c++; c < 256; c++) \ + tr0[c] = c; \ + endch = 0; \ + } else { \ + endch = tab[endch]; \ + tr = tab; \ + if (endch != 0 && endch != 255) { \ + errno = EINVAL; \ + return (-1); \ + } \ + } \ +} + +int +radixsort(a, n, tab, endch) + const u_char **a, *tab; + int n; + u_int endch; +{ + const u_char *tr; + int c; + u_char tr0[256]; + + SETUP; + r_sort_a(a, n, 0, tr, endch); + return (0); +} + +int +sradixsort(a, n, tab, endch) + const u_char **a, *tab; + int n; + u_int endch; +{ + const u_char *tr, **ta; + int c; + u_char tr0[256]; + + SETUP; + if (n < THRESHOLD) + simplesort(a, n, 0, tr, endch); + else { + if ((ta = malloc(n * sizeof(a))) == NULL) + return (-1); + r_sort_b(a, ta, n, 0, tr, endch); + free(ta); + } + return (0); +} + +#define empty(s) (s >= sp) +#define pop(a, n, i) a = (--sp)->sa, n = sp->sn, i = sp->si +#define push(a, n, i) sp->sa = a, sp->sn = n, (sp++)->si = i +#define swap(a, b, t) t = a, a = b, b = t + +/* Unstable, in-place sort. */ +static void +r_sort_a(a, n, i, tr, endch) + const u_char **a; + int n, i; + const u_char *tr; + u_int endch; +{ + static int count[256], nc, bmin; + int c; + const u_char **ak, *r; + stack s[SIZE], *sp, *sp0, *sp1, temp; + int *cp, bigc; + const u_char **an, *t, **aj, **top[256]; + + /* Set up stack. */ + sp = s; + push(a, n, i); + while (!empty(s)) { + pop(a, n, i); + if (n < THRESHOLD) { + simplesort(a, n, i, tr, endch); + continue; + } + an = a + n; + + /* Make character histogram. */ + if (nc == 0) { + bmin = 255; /* First occupied bin, excluding eos. */ + for (ak = a; ak < an;) { + c = tr[(*ak++)[i]]; + if (++count[c] == 1 && c != endch) { + if (c < bmin) + bmin = c; + nc++; + } + } + if (sp + nc > s + SIZE) { /* Get more stack. */ + r_sort_a(a, n, i, tr, endch); + continue; + } + } + + /* + * Special case: if all strings have the same + * character at position i, move on to the next + * character. + */ + if (nc == 1 && count[bmin] == n) { + push(a, n, i+1); + nc = count[bmin] = 0; + continue; + } + + /* + * Set top[]; push incompletely sorted bins onto stack. + * top[] = pointers to last out-of-place element in bins. + * count[] = counts of elements in bins. + * Before permuting: top[c-1] + count[c] = top[c]; + * during deal: top[c] counts down to top[c-1]. + */ + sp0 = sp1 = sp; /* Stack position of biggest bin. */ + bigc = 2; /* Size of biggest bin. */ + if (endch == 0) /* Special case: set top[eos]. */ + top[0] = ak = a + count[0]; + else { + ak = a; + top[255] = an; + } + for (cp = count + bmin; nc > 0; cp++) { + while (*cp == 0) /* Find next non-empty pile. */ + cp++; + if (*cp > 1) { + if (*cp > bigc) { + bigc = *cp; + sp1 = sp; + } + push(ak, *cp, i+1); + } + top[cp-count] = ak += *cp; + nc--; + } + swap(*sp0, *sp1, temp); /* Play it safe -- biggest bin last. */ + + /* + * Permute misplacements home. Already home: everything + * before aj, and in bin[c], items from top[c] on. + * Inner loop: + * r = next element to put in place; + * ak = top[r[i]] = location to put the next element. + * aj = bottom of 1st disordered bin. + * Outer loop: + * Once the 1st disordered bin is done, ie. aj >= ak, + * aj<-aj + count[c] connects the bins in a linked list; + * reset count[c]. + */ + for (aj = a; aj < an; *aj = r, aj += count[c], count[c] = 0) + for (r = *aj; aj < (ak = --top[c = tr[r[i]]]);) + swap(*ak, r, t); + } +} + +/* Stable sort, requiring additional memory. */ +static void +r_sort_b(a, ta, n, i, tr, endch) + const u_char **a, **ta; + int n, i; + const u_char *tr; + u_int endch; +{ + static int count[256], nc, bmin; + int c; + const u_char **ak, **ai; + stack s[512], *sp, *sp0, *sp1, temp; + const u_char **top[256]; + int *cp, bigc; + + sp = s; + push(a, n, i); + while (!empty(s)) { + pop(a, n, i); + if (n < THRESHOLD) { + simplesort(a, n, i, tr, endch); + continue; + } + + if (nc == 0) { + bmin = 255; + for (ak = a + n; --ak >= a;) { + c = tr[(*ak)[i]]; + if (++count[c] == 1 && c != endch) { + if (c < bmin) + bmin = c; + nc++; + } + } + if (sp + nc > s + SIZE) { + r_sort_b(a, ta, n, i, tr, endch); + continue; + } + } + + sp0 = sp1 = sp; + bigc = 2; + if (endch == 0) { + top[0] = ak = a + count[0]; + count[0] = 0; + } else { + ak = a; + top[255] = a + n; + count[255] = 0; + } + for (cp = count + bmin; nc > 0; cp++) { + while (*cp == 0) + cp++; + if ((c = *cp) > 1) { + if (c > bigc) { + bigc = c; + sp1 = sp; + } + push(ak, c, i+1); + } + top[cp-count] = ak += c; + *cp = 0; /* Reset count[]. */ + nc--; + } + swap(*sp0, *sp1, temp); + + for (ak = ta + n, ai = a+n; ak > ta;) /* Copy to temp. */ + *--ak = *--ai; + for (ak = ta+n; --ak >= ta;) /* Deal to piles. */ + *--top[tr[(*ak)[i]]] = *ak; + } +} + +static inline void +simplesort(a, n, b, tr, endch) /* insertion sort */ + const u_char **a; + int n, b; + const u_char *tr; + u_int endch; +{ + u_char ch; + const u_char **ak, **ai, *s, *t; + + for (ak = a+1; --n >= 1; ak++) + for (ai = ak; ai > a; ai--) { + for (s = ai[0] + b, t = ai[-1] + b; + (ch = tr[*s]) != endch; s++, t++) + if (ch != tr[*t]) + break; + if (ch >= tr[*t]) + break; + swap(ai[0], ai[-1], s); + } +} diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c new file mode 100644 index 0000000..359e12a --- /dev/null +++ b/src/lib/libc/stdlib/rand.c @@ -0,0 +1,172 @@ +/*- + * 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. + * + * Posix rand_r function added May 1999 by Wes Peters . + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/rand.c,v 1.15 2003/02/17 03:52:35 ache Exp $"); + +#include "namespace.h" +#include /* for sranddev() */ +#include +#include /* for sranddev() */ +#include +#include /* for sranddev() */ +#include "un-namespace.h" + +#ifdef TEST +#include +#endif /* TEST */ + +static int +do_rand(unsigned long *ctx) +{ +#ifdef USE_WEAK_SEEDING +/* + * Historic implementation compatibility. + * The random sequences do not vary much with the seed, + * even with overflowing. + */ + return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); +#else /* !USE_WEAK_SEEDING */ +/* + * Compute x = (7^5 * x) mod (2^31 - 1) + * wihout overflowing 31 bits: + * (2^31 - 1) = 127773 * (7^5) + 2836 + * From "Random number generators: good ones are hard to find", + * Park and Miller, Communications of the ACM, vol. 31, no. 10, + * October 1988, p. 1195. + */ + long hi, lo, x; + + /* Can't be initialized with 0, so use another value. */ + if (*ctx == 0) + *ctx = 123459876; + hi = *ctx / 127773; + lo = *ctx % 127773; + x = 16807 * lo - 2836 * hi; + if (x < 0) + x += 0x7fffffff; + return ((*ctx = x) % ((u_long)RAND_MAX + 1)); +#endif /* !USE_WEAK_SEEDING */ +} + + +int +rand_r(unsigned int *ctx) +{ + u_long val = (u_long) *ctx; + int r = do_rand(&val); + + *ctx = (unsigned int) val; + return (r); +} + + +static u_long next = 1; + +int +rand() +{ + return (do_rand(&next)); +} + +void +srand(seed) +u_int seed; +{ + next = seed; +} + + +/* + * sranddev: + * + * Many programs choose the seed value in a totally predictable manner. + * This often causes problems. We seed the generator using the much more + * secure random(4) interface. + */ +void +sranddev() +{ + int fd, done; + + done = 0; + fd = _open("/dev/random", O_RDONLY, 0); + if (fd >= 0) { + if (_read(fd, (void *) &next, sizeof(next)) == sizeof(next)) + done = 1; + _close(fd); + } + + if (!done) { + struct timeval tv; + unsigned long junk; + + gettimeofday(&tv, NULL); + srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); + } +} + + +#ifdef TEST + +main() +{ + int i; + unsigned myseed; + + printf("seeding rand with 0x19610910: \n"); + srand(0x19610910); + + printf("generating three pseudo-random numbers:\n"); + for (i = 0; i < 3; i++) + { + printf("next random number = %d\n", rand()); + } + + printf("generating the same sequence with rand_r:\n"); + myseed = 0x19610910; + for (i = 0; i < 3; i++) + { + printf("next random number = %d\n", rand_r(&myseed)); + } + + return 0; +} + +#endif /* TEST */ + diff --git a/src/lib/libc/stdlib/random.c b/src/lib/libc/stdlib/random.c new file mode 100644 index 0000000..f42436a --- /dev/null +++ b/src/lib/libc/stdlib/random.c @@ -0,0 +1,506 @@ +/* + * Copyright (c) 1983, 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[] = "@(#)random.c 8.2 (Berkeley) 5/19/95"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.24 2004/01/20 03:02:18 das Exp $"); + +#include "namespace.h" +#include /* for srandomdev() */ +#include /* for srandomdev() */ +#include +#include +#include +#include /* for srandomdev() */ +#include "un-namespace.h" + +/* + * random.c: + * + * An improved random number generation package. In addition to the standard + * rand()/srand() like interface, this package also has a special state info + * interface. The initstate() routine is called with a seed, an array of + * bytes, and a count of how many bytes are being passed in; this array is + * then initialized to contain information for random number generation with + * that much state information. Good sizes for the amount of state + * information are 32, 64, 128, and 256 bytes. The state can be switched by + * calling the setstate() routine with the same array as was initiallized + * with initstate(). By default, the package runs with 128 bytes of state + * information and generates far better random numbers than a linear + * congruential generator. If the amount of state information is less than + * 32 bytes, a simple linear congruential R.N.G. is used. + * + * Internally, the state information is treated as an array of uint32_t's; the + * zeroeth element of the array is the type of R.N.G. being used (small + * integer); the remainder of the array is the state information for the + * R.N.G. Thus, 32 bytes of state information will give 7 ints worth of + * state information, which will allow a degree seven polynomial. (Note: + * the zeroeth word of state information also has some other information + * stored in it -- see setstate() for details). + * + * The random number generation technique is a linear feedback shift register + * approach, employing trinomials (since there are fewer terms to sum up that + * way). In this approach, the least significant bit of all the numbers in + * the state table will act as a linear feedback shift register, and will + * have period 2^deg - 1 (where deg is the degree of the polynomial being + * used, assuming that the polynomial is irreducible and primitive). The + * higher order bits will have longer periods, since their values are also + * influenced by pseudo-random carries out of the lower bits. The total + * period of the generator is approximately deg*(2**deg - 1); thus doubling + * the amount of state information has a vast influence on the period of the + * generator. Note: the deg*(2**deg - 1) is an approximation only good for + * large deg, when the period of the shift is the dominant factor. + * With deg equal to seven, the period is actually much longer than the + * 7*(2**7 - 1) predicted by this formula. + * + * Modified 28 December 1994 by Jacob S. Rosenberg. + * The following changes have been made: + * All references to the type u_int have been changed to unsigned long. + * All references to type int have been changed to type long. Other + * cleanups have been made as well. A warning for both initstate and + * setstate has been inserted to the effect that on Sparc platforms + * the 'arg_state' variable must be forced to begin on word boundaries. + * This can be easily done by casting a long integer array to char *. + * The overall logic has been left STRICTLY alone. This software was + * tested on both a VAX and Sun SpacsStation with exactly the same + * results. The new version and the original give IDENTICAL results. + * The new version is somewhat faster than the original. As the + * documentation says: "By default, the package runs with 128 bytes of + * state information and generates far better random numbers than a linear + * congruential generator. If the amount of state information is less than + * 32 bytes, a simple linear congruential R.N.G. is used." For a buffer of + * 128 bytes, this new version runs about 19 percent faster and for a 16 + * byte buffer it is about 5 percent faster. + */ + +/* + * For each of the currently supported random number generators, we have a + * break value on the amount of state information (you need at least this + * many bytes of state info to support this random number generator), a degree + * for the polynomial (actually a trinomial) that the R.N.G. is based on, and + * the separation between the two lower order coefficients of the trinomial. + */ +#define TYPE_0 0 /* linear congruential */ +#define BREAK_0 8 +#define DEG_0 0 +#define SEP_0 0 + +#define TYPE_1 1 /* x**7 + x**3 + 1 */ +#define BREAK_1 32 +#define DEG_1 7 +#define SEP_1 3 + +#define TYPE_2 2 /* x**15 + x + 1 */ +#define BREAK_2 64 +#define DEG_2 15 +#define SEP_2 1 + +#define TYPE_3 3 /* x**31 + x**3 + 1 */ +#define BREAK_3 128 +#define DEG_3 31 +#define SEP_3 3 + +#define TYPE_4 4 /* x**63 + x + 1 */ +#define BREAK_4 256 +#define DEG_4 63 +#define SEP_4 1 + +/* + * Array versions of the above information to make code run faster -- + * relies on fact that TYPE_i == i. + */ +#define MAX_TYPES 5 /* max number of types above */ + +#ifdef USE_WEAK_SEEDING +#define NSHUFF 0 +#else /* !USE_WEAK_SEEDING */ +#define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */ +#endif /* !USE_WEAK_SEEDING */ + +static const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; +static const int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; + +/* + * Initially, everything is set up as if from: + * + * initstate(1, randtbl, 128); + * + * Note that this initialization takes advantage of the fact that srandom() + * advances the front and rear pointers 10*rand_deg times, and hence the + * rear pointer which starts at 0 will also end up at zero; thus the zeroeth + * element of the state information, which contains info about the current + * position of the rear pointer is just + * + * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3. + */ + +static uint32_t randtbl[DEG_3 + 1] = { + TYPE_3, +#ifdef USE_WEAK_SEEDING +/* Historic implementation compatibility */ +/* The random sequences do not vary much with the seed */ + 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, + 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, + 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, + 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, + 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, + 0x27fb47b9, +#else /* !USE_WEAK_SEEDING */ + 0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05, + 0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454, + 0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471, + 0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1, + 0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41, + 0xf3bec5da +#endif /* !USE_WEAK_SEEDING */ +}; + +/* + * fptr and rptr are two pointers into the state info, a front and a rear + * pointer. These two pointers are always rand_sep places aparts, as they + * cycle cyclically through the state information. (Yes, this does mean we + * could get away with just one pointer, but the code for random() is more + * efficient this way). The pointers are left positioned as they would be + * from the call + * + * initstate(1, randtbl, 128); + * + * (The position of the rear pointer, rptr, is really 0 (as explained above + * in the initialization of randtbl) because the state table pointer is set + * to point to randtbl[1] (as explained below). + */ +static uint32_t *fptr = &randtbl[SEP_3 + 1]; +static uint32_t *rptr = &randtbl[1]; + +/* + * The following things are the pointer to the state information table, the + * type of the current generator, the degree of the current polynomial being + * used, and the separation between the two pointers. Note that for efficiency + * of random(), we remember the first location of the state information, not + * the zeroeth. Hence it is valid to access state[-1], which is used to + * store the type of the R.N.G. Also, we remember the last location, since + * this is more efficient than indexing every time to find the address of + * the last element to see if the front and rear pointers have wrapped. + */ +static uint32_t *state = &randtbl[1]; +static int rand_type = TYPE_3; +static int rand_deg = DEG_3; +static int rand_sep = SEP_3; +static uint32_t *end_ptr = &randtbl[DEG_3 + 1]; + +static inline uint32_t good_rand(int32_t); + +static inline uint32_t good_rand (x) + int32_t x; +{ +#ifdef USE_WEAK_SEEDING +/* + * Historic implementation compatibility. + * The random sequences do not vary much with the seed, + * even with overflowing. + */ + return (1103515245 * x + 12345); +#else /* !USE_WEAK_SEEDING */ +/* + * Compute x = (7^5 * x) mod (2^31 - 1) + * wihout overflowing 31 bits: + * (2^31 - 1) = 127773 * (7^5) + 2836 + * From "Random number generators: good ones are hard to find", + * Park and Miller, Communications of the ACM, vol. 31, no. 10, + * October 1988, p. 1195. + */ + int32_t hi, lo; + + /* Can't be initialized with 0, so use another value. */ + if (x == 0) + x = 123459876; + hi = x / 127773; + lo = x % 127773; + x = 16807 * lo - 2836 * hi; + if (x < 0) + x += 0x7fffffff; + return (x); +#endif /* !USE_WEAK_SEEDING */ +} + +/* + * srandom: + * + * Initialize the random number generator based on the given seed. If the + * type is the trivial no-state-information type, just remember the seed. + * Otherwise, initializes state[] based on the given "seed" via a linear + * congruential generator. Then, the pointers are set to known locations + * that are exactly rand_sep places apart. Lastly, it cycles the state + * information a given number of times to get rid of any initial dependencies + * introduced by the L.C.R.N.G. Note that the initialization of randtbl[] + * for default usage relies on values produced by this routine. + */ +void +srandom(x) + unsigned long x; +{ + int i, lim; + + state[0] = (uint32_t)x; + if (rand_type == TYPE_0) + lim = NSHUFF; + else { + for (i = 1; i < rand_deg; i++) + state[i] = good_rand(state[i - 1]); + fptr = &state[rand_sep]; + rptr = &state[0]; + lim = 10 * rand_deg; + } + for (i = 0; i < lim; i++) + (void)random(); +} + +/* + * srandomdev: + * + * Many programs choose the seed value in a totally predictable manner. + * This often causes problems. We seed the generator using the much more + * secure random(4) interface. Note that this particular seeding + * procedure can generate states which are impossible to reproduce by + * calling srandom() with any value, since the succeeding terms in the + * state buffer are no longer derived from the LC algorithm applied to + * a fixed seed. + */ +void +srandomdev() +{ + int fd, done; + size_t len; + + if (rand_type == TYPE_0) + len = sizeof state[0]; + else + len = rand_deg * sizeof state[0]; + + done = 0; + fd = _open("/dev/random", O_RDONLY, 0); + if (fd >= 0) { + if (_read(fd, (void *) state, len) == (ssize_t) len) + done = 1; + _close(fd); + } + + if (!done) { + struct timeval tv; + unsigned long junk; + + gettimeofday(&tv, NULL); + srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); + return; + } + + if (rand_type != TYPE_0) { + fptr = &state[rand_sep]; + rptr = &state[0]; + } +} + +/* + * initstate: + * + * Initialize the state information in the given array of n bytes for future + * random number generation. Based on the number of bytes we are given, and + * the break values for the different R.N.G.'s, we choose the best (largest) + * one we can and set things up for it. srandom() is then called to + * initialize the state information. + * + * Note that on return from srandom(), we set state[-1] to be the type + * multiplexed with the current value of the rear pointer; this is so + * successive calls to initstate() won't lose this information and will be + * able to restart with setstate(). + * + * Note: the first thing we do is save the current state, if any, just like + * setstate() so that it doesn't matter when initstate is called. + * + * Returns a pointer to the old state. + * + * Note: The Sparc platform requires that arg_state begin on an int + * word boundary; otherwise a bus error will occur. Even so, lint will + * complain about mis-alignment, but you should disregard these messages. + */ +char * +initstate(seed, arg_state, n) + unsigned long seed; /* seed for R.N.G. */ + char *arg_state; /* pointer to state array */ + long n; /* # bytes of state info */ +{ + char *ostate = (char *)(&state[-1]); + uint32_t *int_arg_state = (uint32_t *)arg_state; + + if (rand_type == TYPE_0) + state[-1] = rand_type; + else + state[-1] = MAX_TYPES * (rptr - state) + rand_type; + if (n < BREAK_0) { + (void)fprintf(stderr, + "random: not enough state (%ld bytes); ignored.\n", n); + return(0); + } + if (n < BREAK_1) { + rand_type = TYPE_0; + rand_deg = DEG_0; + rand_sep = SEP_0; + } else if (n < BREAK_2) { + rand_type = TYPE_1; + rand_deg = DEG_1; + rand_sep = SEP_1; + } else if (n < BREAK_3) { + rand_type = TYPE_2; + rand_deg = DEG_2; + rand_sep = SEP_2; + } else if (n < BREAK_4) { + rand_type = TYPE_3; + rand_deg = DEG_3; + rand_sep = SEP_3; + } else { + rand_type = TYPE_4; + rand_deg = DEG_4; + rand_sep = SEP_4; + } + state = int_arg_state + 1; /* first location */ + end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */ + srandom(seed); + if (rand_type == TYPE_0) + int_arg_state[0] = rand_type; + else + int_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type; + return(ostate); +} + +/* + * setstate: + * + * Restore the state from the given state array. + * + * Note: it is important that we also remember the locations of the pointers + * in the current state information, and restore the locations of the pointers + * from the old state information. This is done by multiplexing the pointer + * location into the zeroeth word of the state information. + * + * Note that due to the order in which things are done, it is OK to call + * setstate() with the same state as the current state. + * + * Returns a pointer to the old state information. + * + * Note: The Sparc platform requires that arg_state begin on an int + * word boundary; otherwise a bus error will occur. Even so, lint will + * complain about mis-alignment, but you should disregard these messages. + */ +char * +setstate(arg_state) + char *arg_state; /* pointer to state array */ +{ + uint32_t *new_state = (uint32_t *)arg_state; + uint32_t type = new_state[0] % MAX_TYPES; + uint32_t rear = new_state[0] / MAX_TYPES; + char *ostate = (char *)(&state[-1]); + + if (rand_type == TYPE_0) + state[-1] = rand_type; + else + state[-1] = MAX_TYPES * (rptr - state) + rand_type; + switch(type) { + case TYPE_0: + case TYPE_1: + case TYPE_2: + case TYPE_3: + case TYPE_4: + rand_type = type; + rand_deg = degrees[type]; + rand_sep = seps[type]; + break; + default: + (void)fprintf(stderr, + "random: state info corrupted; not changed.\n"); + } + state = new_state + 1; + if (rand_type != TYPE_0) { + rptr = &state[rear]; + fptr = &state[(rear + rand_sep) % rand_deg]; + } + end_ptr = &state[rand_deg]; /* set end_ptr too */ + return(ostate); +} + +/* + * random: + * + * If we are using the trivial TYPE_0 R.N.G., just do the old linear + * congruential bit. Otherwise, we do our fancy trinomial stuff, which is + * the same in all the other cases due to all the global variables that have + * been set up. The basic operation is to add the number at the rear pointer + * into the one at the front pointer. Then both pointers are advanced to + * the next location cyclically in the table. The value returned is the sum + * generated, reduced to 31 bits by throwing away the "least random" low bit. + * + * Note: the code takes advantage of the fact that both the front and + * rear pointers can't wrap on the same call by not testing the rear + * pointer if the front one has wrapped. + * + * Returns a 31-bit random number. + */ +long +random() +{ + uint32_t i; + uint32_t *f, *r; + + if (rand_type == TYPE_0) { + i = state[0]; + state[0] = i = (good_rand(i)) & 0x7fffffff; + } else { + /* + * Use local variables rather than static variables for speed. + */ + f = fptr; r = rptr; + *f += *r; + i = (*f >> 1) & 0x7fffffff; /* chucking least random bit */ + if (++f >= end_ptr) { + f = state; + ++r; + } + else if (++r >= end_ptr) { + r = state; + } + + fptr = f; rptr = r; + } + return((long)i); +} diff --git a/src/lib/libc/stdlib/reallocf.c b/src/lib/libc/stdlib/reallocf.c new file mode 100644 index 0000000..d502006 --- /dev/null +++ b/src/lib/libc/stdlib/reallocf.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 1998, M. Warner Losh + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/reallocf.c,v 1.4 2002/03/22 21:53:10 obrien Exp $"); + +#include + +void * +reallocf(void *ptr, size_t size) +{ + void *nptr; + + nptr = realloc(ptr, size); + if (!nptr && ptr) + free(ptr); + return (nptr); +} diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c new file mode 100644 index 0000000..31e0977 --- /dev/null +++ b/src/lib/libc/stdlib/realpath.c @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2003 Constantin S. Svintsoff + * + * 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. The names of the authors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/realpath.c,v 1.20 2003/05/28 08:23:01 fjoe Exp $"); + +#include "namespace.h" +#include +#include + +#include +#include +#include +#include +#include "un-namespace.h" + +/* + * char *realpath(const char *path, char resolved[PATH_MAX]); + * + * Find the real name of path, by removing all ".", ".." and symlink + * components. Returns (resolved) on success, or (NULL) on failure, + * in which case the path which caused trouble is left in (resolved). + */ +char * +realpath(const char *path, char resolved[PATH_MAX]) +{ + struct stat sb; + char *p, *q, *s; + size_t left_len, resolved_len; + unsigned symlinks; + int serrno, slen; + char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX]; + + serrno = errno; + symlinks = 0; + if (path[0] == '/') { + resolved[0] = '/'; + resolved[1] = '\0'; + if (path[1] == '\0') + return (resolved); + resolved_len = 1; + left_len = strlcpy(left, path + 1, sizeof(left)); + } else { + if (getcwd(resolved, PATH_MAX) == NULL) { + strlcpy(resolved, ".", PATH_MAX); + return (NULL); + } + resolved_len = strlen(resolved); + left_len = strlcpy(left, path, sizeof(left)); + } + if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) { + errno = ENAMETOOLONG; + return (NULL); + } + + /* + * Iterate over path components in `left'. + */ + while (left_len != 0) { + /* + * Extract the next path component and adjust `left' + * and its length. + */ + p = strchr(left, '/'); + s = p ? p : left + left_len; + if (s - left >= sizeof(next_token)) { + errno = ENAMETOOLONG; + return (NULL); + } + memcpy(next_token, left, s - left); + next_token[s - left] = '\0'; + left_len -= s - left; + if (p != NULL) + memmove(left, s + 1, left_len + 1); + if (resolved[resolved_len - 1] != '/') { + if (resolved_len + 1 >= PATH_MAX) { + errno = ENAMETOOLONG; + return (NULL); + } + resolved[resolved_len++] = '/'; + resolved[resolved_len] = '\0'; + } + if (next_token[0] == '\0') + continue; + else if (strcmp(next_token, ".") == 0) + continue; + else if (strcmp(next_token, "..") == 0) { + /* + * Strip the last path component except when we have + * single "/" + */ + if (resolved_len > 1) { + resolved[resolved_len - 1] = '\0'; + q = strrchr(resolved, '/') + 1; + *q = '\0'; + resolved_len = q - resolved; + } + continue; + } + + /* + * Append the next path component and lstat() it. If + * lstat() fails we still can return successfully if + * there are no more path components left. + */ + resolved_len = strlcat(resolved, next_token, PATH_MAX); + if (resolved_len >= PATH_MAX) { + errno = ENAMETOOLONG; + return (NULL); + } + if (lstat(resolved, &sb) != 0) { + if (errno == ENOENT && p == NULL) { + errno = serrno; + return (resolved); + } + return (NULL); + } + if (S_ISLNK(sb.st_mode)) { + if (symlinks++ > MAXSYMLINKS) { + errno = ELOOP; + return (NULL); + } + slen = readlink(resolved, symlink, sizeof(symlink) - 1); + if (slen < 0) + return (NULL); + symlink[slen] = '\0'; + if (symlink[0] == '/') { + resolved[1] = 0; + resolved_len = 1; + } else if (resolved_len > 1) { + /* Strip the last path component. */ + resolved[resolved_len - 1] = '\0'; + q = strrchr(resolved, '/') + 1; + *q = '\0'; + resolved_len = q - resolved; + } + + /* + * If there are any path components left, then + * append them to symlink. The result is placed + * in `left'. + */ + if (p != NULL) { + if (symlink[slen - 1] != '/') { + if (slen + 1 >= sizeof(symlink)) { + errno = ENAMETOOLONG; + return (NULL); + } + symlink[slen] = '/'; + symlink[slen + 1] = 0; + } + left_len = strlcat(symlink, left, sizeof(left)); + if (left_len >= sizeof(left)) { + errno = ENAMETOOLONG; + return (NULL); + } + } + left_len = strlcpy(left, symlink, sizeof(left)); + } + } + + /* + * Remove trailing slash except when the resolved pathname + * is a single "/". + */ + if (resolved_len > 1 && resolved[resolved_len - 1] == '/') + resolved[resolved_len - 1] = '\0'; + return (resolved); +} diff --git a/src/lib/libc/stdlib/remque.c b/src/lib/libc/stdlib/remque.c new file mode 100644 index 0000000..068a75f --- /dev/null +++ b/src/lib/libc/stdlib/remque.c @@ -0,0 +1,30 @@ +/* + * Initial implementation: + * Copyright (c) 2002 Robert Drehmel + * All rights reserved. + * + * As long as the above copyright statement and this notice remain + * unchanged, you can do what ever you want with this file. + */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/remque.c,v 1.3 2003/01/04 07:34:41 tjr Exp $"); + +#define _SEARCH_PRIVATE +#include +#include /* for NULL */ + +void +remque(void *element) +{ + struct que_elem *prev, *next, *elem; + + elem = (struct que_elem *)element; + + prev = elem->prev; + next = elem->next; + + if (prev != NULL) + prev->next = next; + if (next != NULL) + next->prev = prev; +} diff --git a/src/lib/libc/stdlib/setenv.c b/src/lib/libc/stdlib/setenv.c new file mode 100644 index 0000000..d7c0394 --- /dev/null +++ b/src/lib/libc/stdlib/setenv.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 1987, 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[] = "@(#)setenv.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/setenv.c,v 1.9 2002/03/22 21:53:10 obrien Exp $"); + +#include +#include +#include + +char *__findenv(const char *, int *); + +/* + * setenv -- + * Set the value of the environmental variable "name" to be + * "value". If rewrite is set, replace any current value. + */ +int +setenv(name, value, rewrite) + const char *name; + const char *value; + int rewrite; +{ + extern char **environ; + static char **alloced; /* if allocated space before */ + char *c; + int l_value, offset; + + if (*value == '=') /* no `=' in value */ + ++value; + l_value = strlen(value); + if ((c = __findenv(name, &offset))) { /* find if already exists */ + if (!rewrite) + return (0); + if (strlen(c) >= l_value) { /* old larger; copy over */ + while ( (*c++ = *value++) ); + return (0); + } + } else { /* create new slot */ + int cnt; + char **p; + + for (p = environ, cnt = 0; *p; ++p, ++cnt); + if (alloced == environ) { /* just increase size */ + p = (char **)realloc((char *)environ, + (size_t)(sizeof(char *) * (cnt + 2))); + if (!p) + return (-1); + alloced = environ = p; + } + else { /* get new space */ + /* copy old entries into it */ + p = malloc((size_t)(sizeof(char *) * (cnt + 2))); + if (!p) + return (-1); + bcopy(environ, p, cnt * sizeof(char *)); + alloced = environ = p; + } + environ[cnt + 1] = NULL; + offset = cnt; + } + for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */ + if (!(environ[offset] = /* name + `=' + value */ + malloc((size_t)((int)(c - name) + l_value + 2)))) + return (-1); + for (c = environ[offset]; (*c = *name++) && *c != '='; ++c); + for (*c++ = '='; (*c++ = *value++); ); + return (0); +} + +/* + * unsetenv(name) -- + * Delete environmental variable "name". + */ +void +unsetenv(name) + const char *name; +{ + extern char **environ; + char **p; + int offset; + + while (__findenv(name, &offset)) /* if set multiple times */ + for (p = &environ[offset];; ++p) + if (!(*p = *(p + 1))) + break; +} diff --git a/src/lib/libc/stdlib/strfmon.c b/src/lib/libc/stdlib/strfmon.c new file mode 100644 index 0000000..db569d5 --- /dev/null +++ b/src/lib/libc/stdlib/strfmon.c @@ -0,0 +1,603 @@ +/*- + * Copyright (c) 2001 Alexey Zelkin + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* internal flags */ +#define NEED_GROUPING 0x01 /* print digits grouped (default) */ +#define SIGN_POSN_USED 0x02 /* '+' or '(' usage flag */ +#define LOCALE_POSN 0x04 /* use locale defined +/- (default) */ +#define PARENTH_POSN 0x08 /* enclose negative amount in () */ +#define SUPRESS_CURR_SYMBOL 0x10 /* supress the currency from output */ +#define LEFT_JUSTIFY 0x20 /* left justify */ +#define USE_INTL_CURRENCY 0x40 /* use international currency symbol */ +#define IS_NEGATIVE 0x80 /* is argument value negative ? */ + +/* internal macros */ +#define PRINT(CH) do { \ + if (dst >= s + maxsize) \ + goto e2big_error; \ + *dst++ = CH; \ +} while (0) + +#define PRINTS(STR) do { \ + char *tmps = STR; \ + while (*tmps != '\0') \ + PRINT(*tmps++); \ +} while (0) + +#define GET_NUMBER(VAR) do { \ + VAR = 0; \ + while (isdigit((unsigned char)*fmt)) { \ + VAR *= 10; \ + VAR += *fmt - '0'; \ + fmt++; \ + } \ +} while (0) + +#define GRPCPY(howmany) do { \ + int i = howmany; \ + while (i-- > 0) { \ + avalue_size--; \ + *--bufend = *(avalue+avalue_size+padded); \ + } \ +} while (0) + +#define GRPSEP do { \ + *--bufend = thousands_sep; \ + groups++; \ +} while (0) + +static void __setup_vars(int, char *, char *, char *, char **); +static int __calc_left_pad(int, char *); +static char *__format_grouped_double(double, int *, int, int, int); + +ssize_t +strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, + ...) +{ + va_list ap; + char *dst; /* output destination pointer */ + const char *fmt; /* current format poistion pointer */ + struct lconv *lc; /* pointer to lconv structure */ + char *asciivalue; /* formatted double pointer */ + + int flags; /* formatting options */ + int pad_char; /* padding character */ + int pad_size; /* pad size */ + int width; /* field width */ + int left_prec; /* left precision */ + int right_prec; /* right precision */ + double value; /* just value */ + char space_char = ' '; /* space after currency */ + + char cs_precedes, /* values gathered from struct lconv */ + sep_by_space, + sign_posn, + *signstr, + *currency_symbol; + + char *tmpptr; /* temporary vars */ + int sverrno; + + va_start(ap, format); + + lc = localeconv(); + dst = s; + fmt = format; + asciivalue = NULL; + currency_symbol = NULL; + pad_size = 0; + + while (*fmt) { + /* pass nonformating characters AS IS */ + if (*fmt != '%') + goto literal; + + /* '%' found ! */ + + /* "%%" mean just '%' */ + if (*(fmt+1) == '%') { + fmt++; + literal: + PRINT(*fmt++); + continue; + } + + /* set up initial values */ + flags = (NEED_GROUPING|LOCALE_POSN); + pad_char = ' '; /* padding character is "space" */ + left_prec = -1; /* no left precision specified */ + right_prec = -1; /* no right precision specified */ + width = -1; /* no width specified */ + value = 0; /* we have no value to print now */ + + /* Flags */ + while (1) { + switch (*++fmt) { + case '=': /* fill character */ + pad_char = *++fmt; + if (pad_char == '\0') + goto format_error; + continue; + case '^': /* not group currency */ + flags &= ~(NEED_GROUPING); + continue; + case '+': /* use locale defined signs */ + if (flags & SIGN_POSN_USED) + goto format_error; + flags |= (SIGN_POSN_USED|LOCALE_POSN); + continue; + case '(': /* enclose negatives with () */ + if (flags & SIGN_POSN_USED) + goto format_error; + flags |= (SIGN_POSN_USED|PARENTH_POSN); + continue; + case '!': /* suppress currency symbol */ + flags |= SUPRESS_CURR_SYMBOL; + continue; + case '-': /* alignment (left) */ + flags |= LEFT_JUSTIFY; + continue; + default: + break; + } + break; + } + + /* field Width */ + if (isdigit((unsigned char)*fmt)) { + GET_NUMBER(width); + /* Do we have enough space to put number with + * required width ? + */ + if (dst + width >= s + maxsize) + goto e2big_error; + } + + /* Left precision */ + if (*fmt == '#') { + if (!isdigit((unsigned char)*++fmt)) + goto format_error; + GET_NUMBER(left_prec); + } + + /* Right precision */ + if (*fmt == '.') { + if (!isdigit((unsigned char)*++fmt)) + goto format_error; + GET_NUMBER(right_prec); + } + + /* Conversion Characters */ + switch (*fmt++) { + case 'i': /* use internaltion currency format */ + flags |= USE_INTL_CURRENCY; + break; + case 'n': /* use national currency format */ + flags &= ~(USE_INTL_CURRENCY); + break; + default: /* required character is missing or + premature EOS */ + goto format_error; + } + + if (flags & USE_INTL_CURRENCY) { + currency_symbol = strdup(lc->int_curr_symbol); + if (currency_symbol != NULL) + space_char = *(currency_symbol+3); + } else + currency_symbol = strdup(lc->currency_symbol); + + if (currency_symbol == NULL) + goto end_error; /* ENOMEM. */ + + /* value itself */ + value = va_arg(ap, double); + + /* detect sign */ + if (value < 0) { + flags |= IS_NEGATIVE; + value = -value; + } + + /* fill left_prec with amount of padding chars */ + if (left_prec >= 0) { + pad_size = __calc_left_pad((flags ^ IS_NEGATIVE), + currency_symbol) - + __calc_left_pad(flags, currency_symbol); + if (pad_size < 0) + pad_size = 0; + } + + asciivalue = __format_grouped_double(value, &flags, + left_prec, right_prec, pad_char); + if (asciivalue == NULL) + goto end_error; /* errno already set */ + /* to ENOMEM by malloc() */ + + /* set some variables for later use */ + __setup_vars(flags, &cs_precedes, &sep_by_space, + &sign_posn, &signstr); + + /* + * Description of some LC_MONETARY's values: + * + * p_cs_precedes & n_cs_precedes + * + * = 1 - $currency_symbol precedes the value + * for a monetary quantity with a non-negative value + * = 0 - symbol succeeds the value + * + * p_sep_by_space & n_sep_by_space + * + * = 0 - no space separates $currency_symbol + * from the value for a monetary quantity with a + * non-negative value + * = 1 - space separates the symbol from the value + * = 2 - space separates the symbol and the sign string, + * if adjacent. + * + * p_sign_posn & n_sign_posn + * + * = 0 - parentheses enclose the quantity and the + * $currency_symbol + * = 1 - the sign string precedes the quantity and the + * $currency_symbol + * = 2 - the sign string succeeds the quantity and the + * $currency_symbol + * = 3 - the sign string precedes the $currency_symbol + * = 4 - the sign string succeeds the $currency_symbol + * + */ + + tmpptr = dst; + + while (pad_size-- > 0) + PRINT(' '); + + if (sign_posn == 0 && (flags & IS_NEGATIVE)) + PRINT('('); + + if (cs_precedes == 1) { + if (sign_posn == 1 || sign_posn == 3) { + PRINTS(signstr); + if (sep_by_space == 2) /* XXX: ? */ + PRINT(' '); + } + + if (!(flags & SUPRESS_CURR_SYMBOL)) { + PRINTS(currency_symbol); + + if (sign_posn == 4) { + if (sep_by_space == 2) + PRINT(space_char); + PRINTS(signstr); + if (sep_by_space == 1) + PRINT(' '); + } else if (sep_by_space == 1) + PRINT(space_char); + } + } else if (sign_posn == 1) + PRINTS(signstr); + + PRINTS(asciivalue); + + if (cs_precedes == 0) { + if (sign_posn == 3) { + if (sep_by_space == 1) + PRINT(' '); + PRINTS(signstr); + } + + if (!(flags & SUPRESS_CURR_SYMBOL)) { + if ((sign_posn == 3 && sep_by_space == 2) + || (sep_by_space == 1 + && (sign_posn == 0 + || sign_posn == 1 + || sign_posn == 2 + || sign_posn == 4))) + PRINT(space_char); + PRINTS(currency_symbol); /* XXX: len */ + if (sign_posn == 4) { + if (sep_by_space == 2) + PRINT(' '); + PRINTS(signstr); + } + } + } + + if (sign_posn == 2) { + if (sep_by_space == 2) + PRINT(' '); + PRINTS(signstr); + } + + if (sign_posn == 0 && (flags & IS_NEGATIVE)) + PRINT(')'); + + if (dst - tmpptr < width) { + if (flags & LEFT_JUSTIFY) { + while (dst - tmpptr < width) + PRINT(' '); + } else { + pad_size = dst-tmpptr; + memmove(tmpptr + width-pad_size, tmpptr, + pad_size); + memset(tmpptr, ' ', width-pad_size); + dst += width-pad_size; + } + } + } + + PRINT('\0'); + va_end(ap); + free(asciivalue); + free(currency_symbol); + return (dst - s - 1); /* return size of put data except trailing '\0' */ + +e2big_error: + errno = E2BIG; + goto end_error; + +format_error: + errno = EINVAL; + +end_error: + sverrno = errno; + if (asciivalue != NULL) + free(asciivalue); + if (currency_symbol != NULL) + free(currency_symbol); + errno = sverrno; + va_end(ap); + return (-1); +} + +static void +__setup_vars(int flags, char *cs_precedes, char *sep_by_space, + char *sign_posn, char **signstr) { + + struct lconv *lc = localeconv(); + + if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) { + *cs_precedes = lc->int_n_cs_precedes; + *sep_by_space = lc->int_n_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn; + *signstr = (lc->negative_sign == '\0') ? "-" + : lc->negative_sign; + } else if (flags & USE_INTL_CURRENCY) { + *cs_precedes = lc->int_p_cs_precedes; + *sep_by_space = lc->int_p_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_p_sign_posn; + *signstr = lc->positive_sign; + } else if (flags & IS_NEGATIVE) { + *cs_precedes = lc->n_cs_precedes; + *sep_by_space = lc->n_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn; + *signstr = (lc->negative_sign == '\0') ? "-" + : lc->negative_sign; + } else { + *cs_precedes = lc->p_cs_precedes; + *sep_by_space = lc->p_sep_by_space; + *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->p_sign_posn; + *signstr = lc->positive_sign; + } + + /* Set defult values for unspecified information. */ + if (*cs_precedes != 0) + *cs_precedes = 1; + if (*sep_by_space == CHAR_MAX) + *sep_by_space = 0; + if (*sign_posn == CHAR_MAX) + *sign_posn = 0; +} + +static int +__calc_left_pad(int flags, char *cur_symb) { + + char cs_precedes, sep_by_space, sign_posn, *signstr; + int left_chars = 0; + + __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); + + if (cs_precedes != 0) { + left_chars += strlen(cur_symb); + if (sep_by_space != 0) + left_chars++; + } + + switch (sign_posn) { + case 1: + left_chars += strlen(signstr); + break; + case 3: + case 4: + if (cs_precedes != 0) + left_chars += strlen(signstr); + } + return (left_chars); +} + +static int +get_groups(int size, char *grouping) { + + int chars = 0; + + if (*grouping == CHAR_MAX || *grouping <= 0) /* no grouping ? */ + return (0); + + while (size > (int)*grouping) { + chars++; + size -= (int)*grouping++; + /* no more grouping ? */ + if (*grouping == CHAR_MAX) + break; + /* rest grouping with same value ? */ + if (*grouping == 0) { + chars += (size - 1) / *(grouping - 1); + break; + } + } + return (chars); +} + +/* convert double to ASCII */ +static char * +__format_grouped_double(double value, int *flags, + int left_prec, int right_prec, int pad_char) { + + char *rslt; + char *avalue; + int avalue_size; + char fmt[32]; + + size_t bufsize; + char *bufend; + + int padded; + + struct lconv *lc = localeconv(); + char *grouping; + char decimal_point; + char thousands_sep; + + int groups = 0; + + grouping = lc->mon_grouping; + decimal_point = *lc->mon_decimal_point; + if (decimal_point == '\0') + decimal_point = *lc->decimal_point; + thousands_sep = *lc->mon_thousands_sep; + if (thousands_sep == '\0') + thousands_sep = *lc->thousands_sep; + + /* fill left_prec with default value */ + if (left_prec == -1) + left_prec = 0; + + /* fill right_prec with default value */ + if (right_prec == -1) { + if (*flags & USE_INTL_CURRENCY) + right_prec = lc->int_frac_digits; + else + right_prec = lc->frac_digits; + + if (right_prec == CHAR_MAX) /* POSIX locale ? */ + right_prec = 2; + } + + if (*flags & NEED_GROUPING) + left_prec += get_groups(left_prec, grouping); + + /* convert to string */ + snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1, + right_prec); + avalue_size = asprintf(&avalue, fmt, value); + if (avalue_size < 0) + return (NULL); + + /* make sure that we've enough space for result string */ + bufsize = strlen(avalue)*2+1; + rslt = malloc(bufsize); + if (rslt == NULL) { + free(avalue); + return (NULL); + } + memset(rslt, 0, bufsize); + bufend = rslt + bufsize - 1; /* reserve space for trailing '\0' */ + + /* skip spaces at beggining */ + padded = 0; + while (avalue[padded] == ' ') { + padded++; + avalue_size--; + } + + if (right_prec > 0) { + bufend -= right_prec; + memcpy(bufend, avalue + avalue_size+padded-right_prec, + right_prec); + *--bufend = decimal_point; + avalue_size -= (right_prec + 1); + } + + if ((*flags & NEED_GROUPING) && + thousands_sep != '\0' && /* XXX: need investigation */ + *grouping != CHAR_MAX && + *grouping > 0) { + while (avalue_size > (int)*grouping) { + GRPCPY(*grouping); + GRPSEP; + grouping++; + + /* no more grouping ? */ + if (*grouping == CHAR_MAX) + break; + + /* rest grouping with same value ? */ + if (*grouping == 0) { + grouping--; + while (avalue_size > *grouping) { + GRPCPY(*grouping); + GRPSEP; + } + } + } + if (avalue_size != 0) + GRPCPY(avalue_size); + padded -= groups; + + } else { + bufend -= avalue_size; + memcpy(bufend, avalue+padded, avalue_size); + if (right_prec == 0) + padded--; /* decrease assumed $decimal_point */ + } + + /* do padding with pad_char */ + if (padded > 0) { + bufend -= padded; + memset(bufend, pad_char, padded); + } + + bufsize = bufsize - (bufend - rslt) + 1; + memmove(rslt, bufend, bufsize); + free(avalue); + return (rslt); +} diff --git a/src/lib/libc/stdlib/strtoimax.c b/src/lib/libc/stdlib/strtoimax.c new file mode 100644 index 0000000..c57d044 --- /dev/null +++ b/src/lib/libc/stdlib/strtoimax.c @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 1992, 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[] = "from @(#)strtol.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoimax.c,v 1.9 2003/01/01 18:48:43 schweikh Exp $"); + +#include +#include +#include +#include + +/* + * Convert a string to an intmax_t integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +intmax_t +strtoimax(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + uintmax_t acc; + char c; + uintmax_t cutoff; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for intmax_t is + * [-9223372036854775808..9223372036854775807] and the input base + * is 10, cutoff will be set to 922337203685477580 and cutlim to + * either 7 (neg==0) or 8 (neg==1), meaning that if we have + * accumulated a value > 922337203685477580, or equal but the + * next digit is > 7 (or 8), the number is too big, and we will + * return a range error. + * + * Set 'any' if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? (uintmax_t)-(INTMAX_MIN + INTMAX_MAX) + INTMAX_MAX + : INTMAX_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? INTMAX_MIN : INTMAX_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/stdlib/strtol.c b/src/lib/libc/stdlib/strtol.c new file mode 100644 index 0000000..2b3fcf4 --- /dev/null +++ b/src/lib/libc/stdlib/strtol.c @@ -0,0 +1,141 @@ +/*- + * 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[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtol.c,v 1.17 2002/09/06 11:23:59 tjr Exp $"); + +#include +#include +#include +#include + + +/* + * Convert a string to a long integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +long +strtol(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long acc; + char c; + unsigned long cutoff; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set 'any' if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? (unsigned long)-(LONG_MIN + LONG_MAX) + LONG_MAX + : LONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_MIN : LONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/stdlib/strtoll.c b/src/lib/libc/stdlib/strtoll.c new file mode 100644 index 0000000..cff57d9 --- /dev/null +++ b/src/lib/libc/stdlib/strtoll.c @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 1992, 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[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoll.c,v 1.19 2002/09/06 11:23:59 tjr Exp $"); + +#include +#include +#include +#include + +/* + * Convert a string to a long long integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +long long +strtoll(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long long acc; + char c; + unsigned long long cutoff; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for quads is + * [-9223372036854775808..9223372036854775807] and the input base + * is 10, cutoff will be set to 922337203685477580 and cutlim to + * either 7 (neg==0) or 8 (neg==1), meaning that if we have + * accumulated a value > 922337203685477580, or equal but the + * next digit is > 7 (or 8), the number is too big, and we will + * return a range error. + * + * Set 'any' if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX + : LLONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LLONG_MIN : LLONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/stdlib/strtoq.c b/src/lib/libc/stdlib/strtoq.c new file mode 100644 index 0000000..6e8bcb8 --- /dev/null +++ b/src/lib/libc/stdlib/strtoq.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1992, 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[] = "@(#)strtoq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoq.c,v 1.11 2002/08/15 09:25:04 robert Exp $"); + +#include + +#include + +/* + * Convert a string to a quad integer. + */ +quad_t +strtoq(const char *nptr, char **endptr, int base) +{ + + return strtoll(nptr, endptr, base); +} diff --git a/src/lib/libc/stdlib/strtoul.c b/src/lib/libc/stdlib/strtoul.c new file mode 100644 index 0000000..40eeba3 --- /dev/null +++ b/src/lib/libc/stdlib/strtoul.c @@ -0,0 +1,119 @@ +/* + * 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[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoul.c,v 1.16 2002/09/06 11:23:59 tjr Exp $"); + +#include +#include +#include +#include + +/* + * Convert a string to an unsigned long integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +unsigned long +strtoul(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long acc; + char c; + unsigned long cutoff; + int neg, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = ULONG_MAX / base; + cutlim = ULONG_MAX % base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/stdlib/strtoull.c b/src/lib/libc/stdlib/strtoull.c new file mode 100644 index 0000000..43f3138 --- /dev/null +++ b/src/lib/libc/stdlib/strtoull.c @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 1992, 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[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoull.c,v 1.18 2002/09/06 11:23:59 tjr Exp $"); + +#include +#include +#include +#include + +/* + * Convert a string to an unsigned long long integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +unsigned long long +strtoull(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long long acc; + char c; + unsigned long long cutoff; + int neg, any, cutlim; + + /* + * See strtoq for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = ULLONG_MAX / base; + cutlim = ULLONG_MAX % base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULLONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/stdlib/strtoumax.c b/src/lib/libc/stdlib/strtoumax.c new file mode 100644 index 0000000..eb714d7 --- /dev/null +++ b/src/lib/libc/stdlib/strtoumax.c @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 1992, 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[] = "from @(#)strtoul.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoumax.c,v 1.8 2002/09/06 11:23:59 tjr Exp $"); + +#include +#include +#include +#include + +/* + * Convert a string to a uintmax_t integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +uintmax_t +strtoumax(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + uintmax_t acc; + char c; + uintmax_t cutoff; + int neg, any, cutlim; + + /* + * See strtoimax for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = UINTMAX_MAX / base; + cutlim = UINTMAX_MAX % base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = UINTMAX_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/lib/libc/stdlib/strtouq.c b/src/lib/libc/stdlib/strtouq.c new file mode 100644 index 0000000..c0e0bef --- /dev/null +++ b/src/lib/libc/stdlib/strtouq.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1992, 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[] = "@(#)strtouq.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/strtouq.c,v 1.11 2002/08/15 09:25:04 robert Exp $"); + +#include + +#include + +/* + * Convert a string to an unsigned quad integer. + */ +u_quad_t +strtouq(const char *nptr, char **endptr, int base) +{ + + return strtoull(nptr, endptr, base); +} diff --git a/src/lib/libc/stdlib/system.c b/src/lib/libc/stdlib/system.c new file mode 100644 index 0000000..fd2cc2a --- /dev/null +++ b/src/lib/libc/stdlib/system.c @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)system.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdlib/system.c,v 1.10 2002/03/22 21:53:10 obrien Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" + +int +__system(command) + const char *command; +{ + pid_t pid, savedpid; + int pstat; + struct sigaction ign, intact, quitact; + sigset_t newsigblock, oldsigblock; + + if (!command) /* just checking... */ + return(1); + + /* + * Ignore SIGINT and SIGQUIT, block SIGCHLD. Remember to save + * existing signal dispositions. + */ + ign.sa_handler = SIG_IGN; + (void)sigemptyset(&ign.sa_mask); + ign.sa_flags = 0; + (void)_sigaction(SIGINT, &ign, &intact); + (void)_sigaction(SIGQUIT, &ign, &quitact); + (void)sigemptyset(&newsigblock); + (void)sigaddset(&newsigblock, SIGCHLD); + (void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); + switch(pid = fork()) { + case -1: /* error */ + break; + case 0: /* child */ + /* + * Restore original signal dispositions and exec the command. + */ + (void)_sigaction(SIGINT, &intact, NULL); + (void)_sigaction(SIGQUIT, &quitact, NULL); + (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); + _exit(127); + default: /* parent */ + savedpid = pid; + do { + pid = _wait4(savedpid, &pstat, 0, (struct rusage *)0); + } while (pid == -1 && errno == EINTR); + break; + } + (void)_sigaction(SIGINT, &intact, NULL); + (void)_sigaction(SIGQUIT, &quitact, NULL); + (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + return(pid == -1 ? -1 : pstat); +} + +__weak_reference(__system, system); +__weak_reference(__system, _system); diff --git a/src/lib/libc/stdlib/tdelete.c b/src/lib/libc/stdlib/tdelete.c new file mode 100644 index 0000000..7fb6893 --- /dev/null +++ b/src/lib/libc/stdlib/tdelete.c @@ -0,0 +1,71 @@ +/* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ + +/* + * Tree search generalized from Knuth (6.2.2) Algorithm T just like + * the AT&T man page says. + * + * The node_t structure is for internal use only, lint doesn't grok it. + * + * Written by reading the System V Interface Definition, not the code. + * + * Totally public domain. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/stdlib/tdelete.c,v 1.6 2003/01/05 02:43:18 tjr Exp $"); + +#define _SEARCH_PRIVATE +#include +#include + + +/* + * delete node with given key + * + * vkey: key to be deleted + * vrootp: address of the root of the tree + * compar: function to carry out node comparisons + */ +void * +tdelete(const void * __restrict vkey, void ** __restrict vrootp, + int (*compar)(const void *, const void *)) +{ + node_t **rootp = (node_t **)vrootp; + node_t *p, *q, *r; + int cmp; + + if (rootp == NULL || (p = *rootp) == NULL) + return NULL; + + while ((cmp = (*compar)(vkey, (*rootp)->key)) != 0) { + p = *rootp; + rootp = (cmp < 0) ? + &(*rootp)->llink : /* follow llink branch */ + &(*rootp)->rlink; /* follow rlink branch */ + if (*rootp == NULL) + return NULL; /* key not found */ + } + r = (*rootp)->rlink; /* D1: */ + if ((q = (*rootp)->llink) == NULL) /* Left NULL? */ + q = r; + else if (r != NULL) { /* Right link is NULL? */ + if (r->llink == NULL) { /* D2: Find successor */ + r->llink = q; + q = r; + } else { /* D3: Find NULL link */ + for (q = r->llink; q->llink != NULL; q = r->llink) + r = q; + r->llink = q->rlink; + q->llink = (*rootp)->llink; + q->rlink = (*rootp)->rlink; + } + } + free(*rootp); /* D4: Free node */ + *rootp = q; /* link parent to new node */ + return p; +} diff --git a/src/lib/libc/stdlib/tfind.c b/src/lib/libc/stdlib/tfind.c new file mode 100644 index 0000000..b58ed88 --- /dev/null +++ b/src/lib/libc/stdlib/tfind.c @@ -0,0 +1,48 @@ +/* $NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ + +/* + * Tree search generalized from Knuth (6.2.2) Algorithm T just like + * the AT&T man page says. + * + * The node_t structure is for internal use only, lint doesn't grok it. + * + * Written by reading the System V Interface Definition, not the code. + * + * Totally public domain. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: tfind.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/stdlib/tfind.c,v 1.5 2003/01/05 02:43:18 tjr Exp $"); + +#define _SEARCH_PRIVATE +#include +#include + +/* find a node, or return 0 */ +void * +tfind(vkey, vrootp, compar) + const void *vkey; /* key to be found */ + void * const *vrootp; /* address of the tree root */ + int (*compar)(const void *, const void *); +{ + node_t **rootp = (node_t **)vrootp; + + if (rootp == NULL) + return NULL; + + while (*rootp != NULL) { /* T1: */ + int r; + + if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ + return *rootp; /* key found */ + rootp = (r < 0) ? + &(*rootp)->llink : /* T3: follow left branch */ + &(*rootp)->rlink; /* T4: follow right branch */ + } + return NULL; +} diff --git a/src/lib/libc/stdlib/tsearch.c b/src/lib/libc/stdlib/tsearch.c new file mode 100644 index 0000000..edeccde --- /dev/null +++ b/src/lib/libc/stdlib/tsearch.c @@ -0,0 +1,58 @@ +/* $NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $ */ + +/* + * Tree search generalized from Knuth (6.2.2) Algorithm T just like + * the AT&T man page says. + * + * The node_t structure is for internal use only, lint doesn't grok it. + * + * Written by reading the System V Interface Definition, not the code. + * + * Totally public domain. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/stdlib/tsearch.c,v 1.4 2003/01/05 02:43:18 tjr Exp $"); + +#define _SEARCH_PRIVATE +#include +#include + +/* find or insert datum into search tree */ +void * +tsearch(vkey, vrootp, compar) + const void *vkey; /* key to be located */ + void **vrootp; /* address of tree root */ + int (*compar)(const void *, const void *); +{ + node_t *q; + node_t **rootp = (node_t **)vrootp; + + if (rootp == NULL) + return NULL; + + while (*rootp != NULL) { /* Knuth's T1: */ + int r; + + if ((r = (*compar)(vkey, (*rootp)->key)) == 0) /* T2: */ + return *rootp; /* we found it! */ + + rootp = (r < 0) ? + &(*rootp)->llink : /* T3: follow left branch */ + &(*rootp)->rlink; /* T4: follow right branch */ + } + + q = malloc(sizeof(node_t)); /* T5: key not found */ + if (q != 0) { /* make new node */ + *rootp = q; /* link new node to old */ + /* LINTED const castaway ok */ + q->key = (void *)vkey; /* initialize new node */ + q->llink = q->rlink = NULL; + } + return q; +} diff --git a/src/lib/libc/stdlib/twalk.c b/src/lib/libc/stdlib/twalk.c new file mode 100644 index 0000000..516ef44 --- /dev/null +++ b/src/lib/libc/stdlib/twalk.c @@ -0,0 +1,58 @@ +/* $NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $ */ + +/* + * Tree search generalized from Knuth (6.2.2) Algorithm T just like + * the AT&T man page says. + * + * The node_t structure is for internal use only, lint doesn't grok it. + * + * Written by reading the System V Interface Definition, not the code. + * + * Totally public domain. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/stdlib/twalk.c,v 1.5 2003/01/05 02:43:18 tjr Exp $"); + +#define _SEARCH_PRIVATE +#include +#include + +static void trecurse(const node_t *, + void (*action)(const void *, VISIT, int), int level); + +/* Walk the nodes of a tree */ +static void +trecurse(root, action, level) + const node_t *root; /* Root of the tree to be walked */ + void (*action)(const void *, VISIT, int); + int level; +{ + + if (root->llink == NULL && root->rlink == NULL) + (*action)(root, leaf, level); + else { + (*action)(root, preorder, level); + if (root->llink != NULL) + trecurse(root->llink, action, level + 1); + (*action)(root, postorder, level); + if (root->rlink != NULL) + trecurse(root->rlink, action, level + 1); + (*action)(root, endorder, level); + } +} + +/* Walk the nodes of a tree */ +void +twalk(vroot, action) + const void *vroot; /* Root of the tree to be walked */ + void (*action)(const void *, VISIT, int); +{ + if (vroot != NULL && action != NULL) + trecurse(vroot, action, 0); +} diff --git a/src/lib/libc/stdtime/asctime.c b/src/lib/libc/stdtime/asctime.c new file mode 100644 index 0000000..6b2da41 --- /dev/null +++ b/src/lib/libc/stdtime/asctime.c @@ -0,0 +1,74 @@ +/* +** This file is in the public domain, so clarified as of +** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +*/ + +#include +#ifndef lint +#ifndef NOID +static char elsieid[] __unused = "@(#)asctime.c 7.7"; +#endif /* !defined NOID */ +#endif /* !defined lint */ +__FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.11 2003/02/16 17:29:11 nectar Exp $"); + +/*LINTLIBRARY*/ + +#include "namespace.h" +#include "private.h" +#include "un-namespace.h" +#include "tzfile.h" + +/* +** A la X3J11, with core dump avoidance. +*/ + + +char * +asctime(timeptr) +const struct tm * timeptr; +{ + static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + + 3 + 2 + 1 + 1]; + return(asctime_r(timeptr, result)); +} + +char * +asctime_r(timeptr, result) +const struct tm * timeptr; +char *result; +{ + static const char wday_name[][3] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + static const char mon_name[][3] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + /* + ** Big enough for something such as + ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n + ** (two three-character abbreviations, five strings denoting integers, + ** three explicit spaces, two explicit colons, a newline, + ** and a trailing ASCII nul). + */ + const char * wn; + const char * mn; + + if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) + wn = "???"; + else wn = wday_name[timeptr->tm_wday]; + if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) + mn = "???"; + else mn = mon_name[timeptr->tm_mon]; + /* + ** The X3J11-suggested format is + ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n" + ** Since the .2 in 02.2d is ignored, we drop it. + */ + (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n", + wn, mn, + timeptr->tm_mday, timeptr->tm_hour, + timeptr->tm_min, timeptr->tm_sec, + TM_YEAR_BASE + timeptr->tm_year); + return result; +} diff --git a/src/lib/libc/stdtime/difftime.c b/src/lib/libc/stdtime/difftime.c new file mode 100644 index 0000000..b7fa1b0 --- /dev/null +++ b/src/lib/libc/stdtime/difftime.c @@ -0,0 +1,81 @@ +/* +** This file is in the public domain, so clarified as of +** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +*/ + +#include +#ifndef lint +#ifndef NOID +static char elsieid[] __unused = "@(#)difftime.c 7.7"; +#endif /* !defined NOID */ +#endif /* !defined lint */ +__FBSDID("$FreeBSD: src/lib/libc/stdtime/difftime.c,v 1.7 2003/02/16 17:29:11 nectar Exp $"); + +/*LINTLIBRARY*/ + +#include "namespace.h" +#include "private.h" +#include "un-namespace.h" + +/* +** Algorithm courtesy Paul Eggert (eggert@twinsun.com). +*/ + +#ifdef HAVE_LONG_DOUBLE +#define long_double long double +#endif /* defined HAVE_LONG_DOUBLE */ +#ifndef HAVE_LONG_DOUBLE +#define long_double double +#endif /* !defined HAVE_LONG_DOUBLE */ + +double +difftime(time1, time0) +const time_t time1; +const time_t time0; +{ + time_t delta; + time_t hibit; + + if (sizeof(time_t) < sizeof(double)) + return (double) time1 - (double) time0; + if (sizeof(time_t) < sizeof(long_double)) + return (long_double) time1 - (long_double) time0; + if (time1 < time0) + return -difftime(time0, time1); + /* + ** As much as possible, avoid loss of precision + ** by computing the difference before converting to double. + */ + delta = time1 - time0; + if (delta >= 0) + return delta; + /* + ** Repair delta overflow. + */ + hibit = (~ (time_t) 0) << (TYPE_BIT(time_t) - 1); + /* + ** The following expression rounds twice, which means + ** the result may not be the closest to the true answer. + ** For example, suppose time_t is 64-bit signed int, + ** long_double is IEEE 754 double with default rounding, + ** time1 = 9223372036854775807 and time0 = -1536. + ** Then the true difference is 9223372036854777343, + ** which rounds to 9223372036854777856 + ** with a total error of 513. + ** But delta overflows to -9223372036854774273, + ** which rounds to -9223372036854774784, and correcting + ** this by subtracting 2 * (long_double) hibit + ** (i.e. by adding 2**64 = 18446744073709551616) + ** yields 9223372036854776832, which + ** rounds to 9223372036854775808 + ** with a total error of 1535 instead. + ** This problem occurs only with very large differences. + ** It's too painful to fix this portably. + ** We are not alone in this problem; + ** some C compilers round twice when converting + ** large unsigned types to small floating types, + ** so if time_t is unsigned the "return delta" above + ** has the same double-rounding problem with those compilers. + */ + return delta - 2 * (long_double) hibit; +} diff --git a/src/lib/libc/stdtime/localtime.c b/src/lib/libc/stdtime/localtime.c new file mode 100644 index 0000000..816a94e --- /dev/null +++ b/src/lib/libc/stdtime/localtime.c @@ -0,0 +1,1750 @@ +/* +** This file is in the public domain, so clarified as of +** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +*/ + +#include +#ifndef lint +#ifndef NOID +static char elsieid[] __unused = "@(#)localtime.c 7.57"; +#endif /* !defined NOID */ +#endif /* !defined lint */ +__FBSDID("$FreeBSD: src/lib/libc/stdtime/localtime.c,v 1.36 2003/02/16 17:29:11 nectar Exp $"); + +/* +** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). +** POSIX-style TZ environment variable handling from Guy Harris +** (guy@auspex.com). +*/ + +/*LINTLIBRARY*/ + +#include "namespace.h" +#include +#include +#include +#include +#include "private.h" +#include "un-namespace.h" + +#include "tzfile.h" + +#include "libc_private.h" + +#define _MUTEX_LOCK(x) if (__isthreaded) _pthread_mutex_lock(x) +#define _MUTEX_UNLOCK(x) if (__isthreaded) _pthread_mutex_unlock(x) + +/* +** SunOS 4.1.1 headers lack O_BINARY. +*/ + +#ifdef O_BINARY +#define OPEN_MODE (O_RDONLY | O_BINARY) +#endif /* defined O_BINARY */ +#ifndef O_BINARY +#define OPEN_MODE O_RDONLY +#endif /* !defined O_BINARY */ + +#ifndef WILDABBR +/* +** Someone might make incorrect use of a time zone abbreviation: +** 1. They might reference tzname[0] before calling tzset (explicitly +** or implicitly). +** 2. They might reference tzname[1] before calling tzset (explicitly +** or implicitly). +** 3. They might reference tzname[1] after setting to a time zone +** in which Daylight Saving Time is never observed. +** 4. They might reference tzname[0] after setting to a time zone +** in which Standard Time is never observed. +** 5. They might reference tm.TM_ZONE after calling offtime. +** What's best to do in the above cases is open to debate; +** for now, we just set things up so that in any of the five cases +** WILDABBR is used. Another possibility: initialize tzname[0] to the +** string "tzname[0] used before set", and similarly for the other cases. +** And another: initialize tzname[0] to "ERA", with an explanation in the +** manual page of what this "time zone abbreviation" means (doing this so +** that tzname[0] has the "normal" length of three characters). +*/ +#define WILDABBR " " +#endif /* !defined WILDABBR */ + +static char wildabbr[] = "WILDABBR"; + +static const char gmt[] = "GMT"; + +struct ttinfo { /* time type information */ + long tt_gmtoff; /* GMT offset in seconds */ + int tt_isdst; /* used to set tm_isdst */ + int tt_abbrind; /* abbreviation list index */ + int tt_ttisstd; /* TRUE if transition is std time */ + int tt_ttisgmt; /* TRUE if transition is GMT */ +}; + +struct lsinfo { /* leap second information */ + time_t ls_trans; /* transition time */ + long ls_corr; /* correction to apply */ +}; + +#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b)) + +#ifdef TZNAME_MAX +#define MY_TZNAME_MAX TZNAME_MAX +#endif /* defined TZNAME_MAX */ +#ifndef TZNAME_MAX +#define MY_TZNAME_MAX 255 +#endif /* !defined TZNAME_MAX */ + +struct state { + int leapcnt; + int timecnt; + int typecnt; + int charcnt; + time_t ats[TZ_MAX_TIMES]; + unsigned char types[TZ_MAX_TIMES]; + struct ttinfo ttis[TZ_MAX_TYPES]; + char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt), + (2 * (MY_TZNAME_MAX + 1)))]; + struct lsinfo lsis[TZ_MAX_LEAPS]; +}; + +struct rule { + int r_type; /* type of rule--see below */ + int r_day; /* day number of rule */ + int r_week; /* week number of rule */ + int r_mon; /* month number of rule */ + long r_time; /* transition time of rule */ +}; + +#define JULIAN_DAY 0 /* Jn - Julian day */ +#define DAY_OF_YEAR 1 /* n - day of year */ +#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */ + +/* +** Prototypes for static functions. +*/ + +static long detzcode(const char * codep); +static const char * getzname(const char * strp); +static const char * getnum(const char * strp, int * nump, int min, + int max); +static const char * getsecs(const char * strp, long * secsp); +static const char * getoffset(const char * strp, long * offsetp); +static const char * getrule(const char * strp, struct rule * rulep); +static void gmtload(struct state * sp); +static void gmtsub(const time_t * timep, long offset, + struct tm * tmp); +static void localsub(const time_t * timep, long offset, + struct tm * tmp); +static int increment_overflow(int * number, int delta); +static int normalize_overflow(int * tensptr, int * unitsptr, + int base); +static void settzname(void); +static time_t time1(struct tm * tmp, + void(*funcp) (const time_t *, + long, struct tm *), + long offset); +static time_t time2(struct tm *tmp, + void(*funcp) (const time_t *, + long, struct tm*), + long offset, int * okayp); +static void timesub(const time_t * timep, long offset, + const struct state * sp, struct tm * tmp); +static int tmcomp(const struct tm * atmp, + const struct tm * btmp); +static time_t transtime(time_t janfirst, int year, + const struct rule * rulep, long offset); +static int tzload(const char * name, struct state * sp); +static int tzparse(const char * name, struct state * sp, + int lastditch); + +#ifdef ALL_STATE +static struct state * lclptr; +static struct state * gmtptr; +#endif /* defined ALL_STATE */ + +#ifndef ALL_STATE +static struct state lclmem; +static struct state gmtmem; +#define lclptr (&lclmem) +#define gmtptr (&gmtmem) +#endif /* State Farm */ + +#ifndef TZ_STRLEN_MAX +#define TZ_STRLEN_MAX 255 +#endif /* !defined TZ_STRLEN_MAX */ + +static char lcl_TZname[TZ_STRLEN_MAX + 1]; +static int lcl_is_set; +static int gmt_is_set; +static pthread_mutex_t lcl_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER; + +char * tzname[2] = { + wildabbr, + wildabbr +}; + +/* +** Section 4.12.3 of X3.159-1989 requires that +** Except for the strftime function, these functions [asctime, +** ctime, gmtime, localtime] return values in one of two static +** objects: a broken-down time structure and an array of char. +** Thanks to Paul Eggert (eggert@twinsun.com) for noting this. +*/ + +static struct tm tm; + +#ifdef USG_COMPAT +time_t timezone = 0; +int daylight = 0; +#endif /* defined USG_COMPAT */ + +#ifdef ALTZONE +time_t altzone = 0; +#endif /* defined ALTZONE */ + +static long +detzcode(codep) +const char * const codep; +{ + long result; + int i; + + result = (codep[0] & 0x80) ? ~0L : 0L; + for (i = 0; i < 4; ++i) + result = (result << 8) | (codep[i] & 0xff); + return result; +} + +static void +settzname(void) +{ + struct state * sp = lclptr; + int i; + + tzname[0] = wildabbr; + tzname[1] = wildabbr; +#ifdef USG_COMPAT + daylight = 0; + timezone = 0; +#endif /* defined USG_COMPAT */ +#ifdef ALTZONE + altzone = 0; +#endif /* defined ALTZONE */ +#ifdef ALL_STATE + if (sp == NULL) { + tzname[0] = tzname[1] = gmt; + return; + } +#endif /* defined ALL_STATE */ + for (i = 0; i < sp->typecnt; ++i) { + const struct ttinfo * const ttisp = &sp->ttis[i]; + + tzname[ttisp->tt_isdst] = + &sp->chars[ttisp->tt_abbrind]; +#ifdef USG_COMPAT + if (ttisp->tt_isdst) + daylight = 1; + if (i == 0 || !ttisp->tt_isdst) + timezone = -(ttisp->tt_gmtoff); +#endif /* defined USG_COMPAT */ +#ifdef ALTZONE + if (i == 0 || ttisp->tt_isdst) + altzone = -(ttisp->tt_gmtoff); +#endif /* defined ALTZONE */ + } + /* + ** And to get the latest zone names into tzname. . . + */ + for (i = 0; i < sp->timecnt; ++i) { + const struct ttinfo * const ttisp = + &sp->ttis[ + sp->types[i]]; + + tzname[ttisp->tt_isdst] = + &sp->chars[ttisp->tt_abbrind]; + } +} + +static int +tzload(name, sp) +const char * name; +struct state * const sp; +{ + const char * p; + int i; + int fid; + + /* XXX The following is from OpenBSD, and I'm not sure it is correct */ + if (name != NULL && issetugid() != 0) + if ((name[0] == ':' && name[1] == '/') || + name[0] == '/' || strchr(name, '.')) + name = NULL; + if (name == NULL && (name = TZDEFAULT) == NULL) + return -1; + { + int doaccess; + struct stat stab; + /* + ** Section 4.9.1 of the C standard says that + ** "FILENAME_MAX expands to an integral constant expression + ** that is the size needed for an array of char large enough + ** to hold the longest file name string that the implementation + ** guarantees can be opened." + */ + char fullname[FILENAME_MAX + 1]; + + if (name[0] == ':') + ++name; + doaccess = name[0] == '/'; + if (!doaccess) { + if ((p = TZDIR) == NULL) + return -1; + if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname) + return -1; + (void) strcpy(fullname, p); + (void) strcat(fullname, "/"); + (void) strcat(fullname, name); + /* + ** Set doaccess if '.' (as in "../") shows up in name. + */ + if (strchr(name, '.') != NULL) + doaccess = TRUE; + name = fullname; + } + if (doaccess && access(name, R_OK) != 0) + return -1; + if ((fid = _open(name, OPEN_MODE)) == -1) + return -1; + if ((_fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) { + _close(fid); + return -1; + } + } + { + struct tzhead * tzhp; + char buf[sizeof *sp + sizeof *tzhp]; + int ttisstdcnt; + int ttisgmtcnt; + + i = _read(fid, buf, sizeof buf); + if (_close(fid) != 0) + return -1; + p = buf; + p += (sizeof tzhp->tzh_magic) + (sizeof tzhp->tzh_reserved); + ttisstdcnt = (int) detzcode(p); + p += 4; + ttisgmtcnt = (int) detzcode(p); + p += 4; + sp->leapcnt = (int) detzcode(p); + p += 4; + sp->timecnt = (int) detzcode(p); + p += 4; + sp->typecnt = (int) detzcode(p); + p += 4; + sp->charcnt = (int) detzcode(p); + p += 4; + if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS || + sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES || + sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES || + sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS || + (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) || + (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0)) + return -1; + if (i - (p - buf) < sp->timecnt * 4 + /* ats */ + sp->timecnt + /* types */ + sp->typecnt * (4 + 2) + /* ttinfos */ + sp->charcnt + /* chars */ + sp->leapcnt * (4 + 4) + /* lsinfos */ + ttisstdcnt + /* ttisstds */ + ttisgmtcnt) /* ttisgmts */ + return -1; + for (i = 0; i < sp->timecnt; ++i) { + sp->ats[i] = detzcode(p); + p += 4; + } + for (i = 0; i < sp->timecnt; ++i) { + sp->types[i] = (unsigned char) *p++; + if (sp->types[i] >= sp->typecnt) + return -1; + } + for (i = 0; i < sp->typecnt; ++i) { + struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + ttisp->tt_gmtoff = detzcode(p); + p += 4; + ttisp->tt_isdst = (unsigned char) *p++; + if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1) + return -1; + ttisp->tt_abbrind = (unsigned char) *p++; + if (ttisp->tt_abbrind < 0 || + ttisp->tt_abbrind > sp->charcnt) + return -1; + } + for (i = 0; i < sp->charcnt; ++i) + sp->chars[i] = *p++; + sp->chars[i] = '\0'; /* ensure '\0' at end */ + for (i = 0; i < sp->leapcnt; ++i) { + struct lsinfo * lsisp; + + lsisp = &sp->lsis[i]; + lsisp->ls_trans = detzcode(p); + p += 4; + lsisp->ls_corr = detzcode(p); + p += 4; + } + for (i = 0; i < sp->typecnt; ++i) { + struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + if (ttisstdcnt == 0) + ttisp->tt_ttisstd = FALSE; + else { + ttisp->tt_ttisstd = *p++; + if (ttisp->tt_ttisstd != TRUE && + ttisp->tt_ttisstd != FALSE) + return -1; + } + } + for (i = 0; i < sp->typecnt; ++i) { + struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + if (ttisgmtcnt == 0) + ttisp->tt_ttisgmt = FALSE; + else { + ttisp->tt_ttisgmt = *p++; + if (ttisp->tt_ttisgmt != TRUE && + ttisp->tt_ttisgmt != FALSE) + return -1; + } + } + } + return 0; +} + +static const int mon_lengths[2][MONSPERYEAR] = { + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } +}; + +static const int year_lengths[2] = { + DAYSPERNYEAR, DAYSPERLYEAR +}; + +/* +** Given a pointer into a time zone string, scan until a character that is not +** a valid character in a zone name is found. Return a pointer to that +** character. +*/ + +static const char * +getzname(strp) +const char * strp; +{ + char c; + + while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' && + c != '+') + ++strp; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number from that string. +** Check that the number is within a specified range; if it is not, return +** NULL. +** Otherwise, return a pointer to the first character not part of the number. +*/ + +static const char * +getnum(strp, nump, min, max) +const char * strp; +int * const nump; +const int min; +const int max; +{ + char c; + int num; + + if (strp == NULL || !is_digit(c = *strp)) + return NULL; + num = 0; + do { + num = num * 10 + (c - '0'); + if (num > max) + return NULL; /* illegal value */ + c = *++strp; + } while (is_digit(c)); + if (num < min) + return NULL; /* illegal value */ + *nump = num; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number of seconds, +** in hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the number +** of seconds. +*/ + +static const char * +getsecs(strp, secsp) +const char * strp; +long * const secsp; +{ + int num; + + /* + ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like + ** "M10.4.6/26", which does not conform to Posix, + ** but which specifies the equivalent of + ** ``02:00 on the first Sunday on or after 23 Oct''. + */ + strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1); + if (strp == NULL) + return NULL; + *secsp = num * (long) SECSPERHOUR; + if (*strp == ':') { + ++strp; + strp = getnum(strp, &num, 0, MINSPERHOUR - 1); + if (strp == NULL) + return NULL; + *secsp += num * SECSPERMIN; + if (*strp == ':') { + ++strp; + /* `SECSPERMIN' allows for leap seconds. */ + strp = getnum(strp, &num, 0, SECSPERMIN); + if (strp == NULL) + return NULL; + *secsp += num; + } + } + return strp; +} + +/* +** Given a pointer into a time zone string, extract an offset, in +** [+-]hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the time. +*/ + +static const char * +getoffset(strp, offsetp) +const char * strp; +long * const offsetp; +{ + int neg = 0; + + if (*strp == '-') { + neg = 1; + ++strp; + } else if (*strp == '+') + ++strp; + strp = getsecs(strp, offsetp); + if (strp == NULL) + return NULL; /* illegal time */ + if (neg) + *offsetp = -*offsetp; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a rule in the form +** date[/time]. See POSIX section 8 for the format of "date" and "time". +** If a valid rule is not found, return NULL. +** Otherwise, return a pointer to the first character not part of the rule. +*/ + +static const char * +getrule(strp, rulep) +const char * strp; +struct rule * const rulep; +{ + if (*strp == 'J') { + /* + ** Julian day. + */ + rulep->r_type = JULIAN_DAY; + ++strp; + strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR); + } else if (*strp == 'M') { + /* + ** Month, week, day. + */ + rulep->r_type = MONTH_NTH_DAY_OF_WEEK; + ++strp; + strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_week, 1, 5); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1); + } else if (is_digit(*strp)) { + /* + ** Day of year. + */ + rulep->r_type = DAY_OF_YEAR; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); + } else return NULL; /* invalid format */ + if (strp == NULL) + return NULL; + if (*strp == '/') { + /* + ** Time specified. + */ + ++strp; + strp = getsecs(strp, &rulep->r_time); + } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */ + return strp; +} + +/* +** Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the +** year, a rule, and the offset from GMT at the time that rule takes effect, +** calculate the Epoch-relative time that rule takes effect. +*/ + +static time_t +transtime(janfirst, year, rulep, offset) +const time_t janfirst; +const int year; +const struct rule * const rulep; +const long offset; +{ + int leapyear; + time_t value; + int i; + int d, m1, yy0, yy1, yy2, dow; + + INITIALIZE(value); + leapyear = isleap(year); + switch (rulep->r_type) { + + case JULIAN_DAY: + /* + ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap + ** years. + ** In non-leap years, or if the day number is 59 or less, just + ** add SECSPERDAY times the day number-1 to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + (rulep->r_day - 1) * SECSPERDAY; + if (leapyear && rulep->r_day >= 60) + value += SECSPERDAY; + break; + + case DAY_OF_YEAR: + /* + ** n - day of year. + ** Just add SECSPERDAY times the day number to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + rulep->r_day * SECSPERDAY; + break; + + case MONTH_NTH_DAY_OF_WEEK: + /* + ** Mm.n.d - nth "dth day" of month m. + */ + value = janfirst; + for (i = 0; i < rulep->r_mon - 1; ++i) + value += mon_lengths[leapyear][i] * SECSPERDAY; + + /* + ** Use Zeller's Congruence to get day-of-week of first day of + ** month. + */ + m1 = (rulep->r_mon + 9) % 12 + 1; + yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; + yy1 = yy0 / 100; + yy2 = yy0 % 100; + dow = ((26 * m1 - 2) / 10 + + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7; + if (dow < 0) + dow += DAYSPERWEEK; + + /* + ** "dow" is the day-of-week of the first day of the month. Get + ** the day-of-month (zero-origin) of the first "dow" day of the + ** month. + */ + d = rulep->r_day - dow; + if (d < 0) + d += DAYSPERWEEK; + for (i = 1; i < rulep->r_week; ++i) { + if (d + DAYSPERWEEK >= + mon_lengths[leapyear][rulep->r_mon - 1]) + break; + d += DAYSPERWEEK; + } + + /* + ** "d" is the day-of-month (zero-origin) of the day we want. + */ + value += d * SECSPERDAY; + break; + } + + /* + ** "value" is the Epoch-relative time of 00:00:00 GMT on the day in + ** question. To get the Epoch-relative time of the specified local + ** time on that day, add the transition time and the current offset + ** from GMT. + */ + return value + rulep->r_time + offset; +} + +/* +** Given a POSIX section 8-style TZ string, fill in the rule tables as +** appropriate. +*/ + +static int +tzparse(name, sp, lastditch) +const char * name; +struct state * const sp; +const int lastditch; +{ + const char * stdname; + const char * dstname; + size_t stdlen; + size_t dstlen; + long stdoffset; + long dstoffset; + time_t * atp; + unsigned char * typep; + char * cp; + int load_result; + + INITIALIZE(dstname); + stdname = name; + if (lastditch) { + stdlen = strlen(name); /* length of standard zone name */ + name += stdlen; + if (stdlen >= sizeof sp->chars) + stdlen = (sizeof sp->chars) - 1; + stdoffset = 0; + } else { + name = getzname(name); + stdlen = name - stdname; + if (stdlen < 3) + return -1; + if (*name == '\0') + return -1; /* was "stdoffset = 0;" */ + else { + name = getoffset(name, &stdoffset); + if (name == NULL) + return -1; + } + } + load_result = tzload(TZDEFRULES, sp); + if (load_result != 0) + sp->leapcnt = 0; /* so, we're off a little */ + if (*name != '\0') { + dstname = name; + name = getzname(name); + dstlen = name - dstname; /* length of DST zone name */ + if (dstlen < 3) + return -1; + if (*name != '\0' && *name != ',' && *name != ';') { + name = getoffset(name, &dstoffset); + if (name == NULL) + return -1; + } else dstoffset = stdoffset - SECSPERHOUR; + if (*name == ',' || *name == ';') { + struct rule start; + struct rule end; + int year; + time_t janfirst; + time_t starttime; + time_t endtime; + + ++name; + if ((name = getrule(name, &start)) == NULL) + return -1; + if (*name++ != ',') + return -1; + if ((name = getrule(name, &end)) == NULL) + return -1; + if (*name != '\0') + return -1; + sp->typecnt = 2; /* standard time and DST */ + /* + ** Two transitions per year, from EPOCH_YEAR to 2037. + */ + sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1); + if (sp->timecnt > TZ_MAX_TIMES) + return -1; + sp->ttis[0].tt_gmtoff = -dstoffset; + sp->ttis[0].tt_isdst = 1; + sp->ttis[0].tt_abbrind = stdlen + 1; + sp->ttis[1].tt_gmtoff = -stdoffset; + sp->ttis[1].tt_isdst = 0; + sp->ttis[1].tt_abbrind = 0; + atp = sp->ats; + typep = sp->types; + janfirst = 0; + for (year = EPOCH_YEAR; year <= 2037; ++year) { + starttime = transtime(janfirst, year, &start, + stdoffset); + endtime = transtime(janfirst, year, &end, + dstoffset); + if (starttime > endtime) { + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + } else { + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + } + janfirst += year_lengths[isleap(year)] * + SECSPERDAY; + } + } else { + long theirstdoffset; + long theirdstoffset; + long theiroffset; + int isdst; + int i; + int j; + + if (*name != '\0') + return -1; + if (load_result != 0) + return -1; + /* + ** Initial values of theirstdoffset and theirdstoffset. + */ + theirstdoffset = 0; + for (i = 0; i < sp->timecnt; ++i) { + j = sp->types[i]; + if (!sp->ttis[j].tt_isdst) { + theirstdoffset = + -sp->ttis[j].tt_gmtoff; + break; + } + } + theirdstoffset = 0; + for (i = 0; i < sp->timecnt; ++i) { + j = sp->types[i]; + if (sp->ttis[j].tt_isdst) { + theirdstoffset = + -sp->ttis[j].tt_gmtoff; + break; + } + } + /* + ** Initially we're assumed to be in standard time. + */ + isdst = FALSE; + theiroffset = theirstdoffset; + /* + ** Now juggle transition times and types + ** tracking offsets as you do. + */ + for (i = 0; i < sp->timecnt; ++i) { + j = sp->types[i]; + sp->types[i] = sp->ttis[j].tt_isdst; + if (sp->ttis[j].tt_ttisgmt) { + /* No adjustment to transition time */ + } else { + /* + ** If summer time is in effect, and the + ** transition time was not specified as + ** standard time, add the summer time + ** offset to the transition time; + ** otherwise, add the standard time + ** offset to the transition time. + */ + /* + ** Transitions from DST to DDST + ** will effectively disappear since + ** POSIX provides for only one DST + ** offset. + */ + if (isdst && !sp->ttis[j].tt_ttisstd) { + sp->ats[i] += dstoffset - + theirdstoffset; + } else { + sp->ats[i] += stdoffset - + theirstdoffset; + } + } + theiroffset = -sp->ttis[j].tt_gmtoff; + if (sp->ttis[j].tt_isdst) + theirdstoffset = theiroffset; + else theirstdoffset = theiroffset; + } + /* + ** Finally, fill in ttis. + ** ttisstd and ttisgmt need not be handled. + */ + sp->ttis[0].tt_gmtoff = -stdoffset; + sp->ttis[0].tt_isdst = FALSE; + sp->ttis[0].tt_abbrind = 0; + sp->ttis[1].tt_gmtoff = -dstoffset; + sp->ttis[1].tt_isdst = TRUE; + sp->ttis[1].tt_abbrind = stdlen + 1; + } + } else { + dstlen = 0; + sp->typecnt = 1; /* only standard time */ + sp->timecnt = 0; + sp->ttis[0].tt_gmtoff = -stdoffset; + sp->ttis[0].tt_isdst = 0; + sp->ttis[0].tt_abbrind = 0; + } + sp->charcnt = stdlen + 1; + if (dstlen != 0) + sp->charcnt += dstlen + 1; + if (sp->charcnt > sizeof sp->chars) + return -1; + cp = sp->chars; + (void) strncpy(cp, stdname, stdlen); + cp += stdlen; + *cp++ = '\0'; + if (dstlen != 0) { + (void) strncpy(cp, dstname, dstlen); + *(cp + dstlen) = '\0'; + } + return 0; +} + +static void +gmtload(sp) +struct state * const sp; +{ + if (tzload(gmt, sp) != 0) + (void) tzparse(gmt, sp, TRUE); +} + +static void +tzsetwall_basic(void) +{ + if (lcl_is_set < 0) + return; + lcl_is_set = -1; + +#ifdef ALL_STATE + if (lclptr == NULL) { + lclptr = (struct state *) malloc(sizeof *lclptr); + if (lclptr == NULL) { + settzname(); /* all we can do */ + return; + } + } +#endif /* defined ALL_STATE */ + if (tzload((char *) NULL, lclptr) != 0) + gmtload(lclptr); + settzname(); +} + +void +tzsetwall(void) +{ + _MUTEX_LOCK(&lcl_mutex); + tzsetwall_basic(); + _MUTEX_UNLOCK(&lcl_mutex); +} + +static void +tzset_basic(void) +{ + const char * name; + + name = getenv("TZ"); + if (name == NULL) { + tzsetwall_basic(); + return; + } + + if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) + return; + lcl_is_set = (strlen(name) < sizeof(lcl_TZname)); + if (lcl_is_set) + (void) strcpy(lcl_TZname, name); + +#ifdef ALL_STATE + if (lclptr == NULL) { + lclptr = (struct state *) malloc(sizeof *lclptr); + if (lclptr == NULL) { + settzname(); /* all we can do */ + return; + } + } +#endif /* defined ALL_STATE */ + if (*name == '\0') { + /* + ** User wants it fast rather than right. + */ + lclptr->leapcnt = 0; /* so, we're off a little */ + lclptr->timecnt = 0; + lclptr->ttis[0].tt_gmtoff = 0; + lclptr->ttis[0].tt_abbrind = 0; + (void) strcpy(lclptr->chars, gmt); + } else if (tzload(name, lclptr) != 0) + if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) + (void) gmtload(lclptr); + settzname(); +} + +void +tzset(void) +{ + _MUTEX_LOCK(&lcl_mutex); + tzset_basic(); + _MUTEX_UNLOCK(&lcl_mutex); +} + +/* +** The easy way to behave "as if no library function calls" localtime +** is to not call it--so we drop its guts into "localsub", which can be +** freely called. (And no, the PANS doesn't require the above behavior-- +** but it *is* desirable.) +** +** The unused offset argument is for the benefit of mktime variants. +*/ + +/*ARGSUSED*/ +static void +localsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ + struct state * sp; + const struct ttinfo * ttisp; + int i; + const time_t t = *timep; + + sp = lclptr; +#ifdef ALL_STATE + if (sp == NULL) { + gmtsub(timep, offset, tmp); + return; + } +#endif /* defined ALL_STATE */ + if (sp->timecnt == 0 || t < sp->ats[0]) { + i = 0; + while (sp->ttis[i].tt_isdst) + if (++i >= sp->typecnt) { + i = 0; + break; + } + } else { + for (i = 1; i < sp->timecnt; ++i) + if (t < sp->ats[i]) + break; + i = sp->types[i - 1]; + } + ttisp = &sp->ttis[i]; + /* + ** To get (wrong) behavior that's compatible with System V Release 2.0 + ** you'd replace the statement below with + ** t += ttisp->tt_gmtoff; + ** timesub(&t, 0L, sp, tmp); + */ + timesub(&t, ttisp->tt_gmtoff, sp, tmp); + tmp->tm_isdst = ttisp->tt_isdst; + tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind]; +#ifdef TM_ZONE + tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind]; +#endif /* defined TM_ZONE */ +} + +struct tm * +localtime_r(timep, p_tm) +const time_t * const timep; +struct tm *p_tm; +{ + _MUTEX_LOCK(&lcl_mutex); + tzset_basic(); + localsub(timep, 0L, p_tm); + _MUTEX_UNLOCK(&lcl_mutex); + return(p_tm); +} + +struct tm * +localtime(timep) +const time_t * const timep; +{ + static pthread_mutex_t localtime_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_key_t localtime_key = -1; + struct tm *p_tm; + + if (__isthreaded != 0) { + _pthread_mutex_lock(&localtime_mutex); + if (localtime_key < 0) { + if (_pthread_key_create(&localtime_key, free) < 0) { + _pthread_mutex_unlock(&localtime_mutex); + return(NULL); + } + } + _pthread_mutex_unlock(&localtime_mutex); + p_tm = _pthread_getspecific(localtime_key); + if (p_tm == NULL) { + if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) + == NULL) + return(NULL); + _pthread_setspecific(localtime_key, p_tm); + } + _pthread_mutex_lock(&lcl_mutex); + tzset_basic(); + localsub(timep, 0L, p_tm); + _pthread_mutex_unlock(&lcl_mutex); + return(p_tm); + } else { + tzset_basic(); + localsub(timep, 0L, &tm); + return(&tm); + } +} + +/* +** gmtsub is to gmtime as localsub is to localtime. +*/ + +static void +gmtsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ + _MUTEX_LOCK(&gmt_mutex); + if (!gmt_is_set) { + gmt_is_set = TRUE; +#ifdef ALL_STATE + gmtptr = (struct state *) malloc(sizeof *gmtptr); + if (gmtptr != NULL) +#endif /* defined ALL_STATE */ + gmtload(gmtptr); + } + _MUTEX_UNLOCK(&gmt_mutex); + timesub(timep, offset, gmtptr, tmp); +#ifdef TM_ZONE + /* + ** Could get fancy here and deliver something such as + ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero, + ** but this is no time for a treasure hunt. + */ + if (offset != 0) + tmp->TM_ZONE = wildabbr; + else { +#ifdef ALL_STATE + if (gmtptr == NULL) + tmp->TM_ZONE = gmt; + else tmp->TM_ZONE = gmtptr->chars; +#endif /* defined ALL_STATE */ +#ifndef ALL_STATE + tmp->TM_ZONE = gmtptr->chars; +#endif /* State Farm */ + } +#endif /* defined TM_ZONE */ +} + +struct tm * +gmtime(timep) +const time_t * const timep; +{ + static pthread_mutex_t gmtime_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_key_t gmtime_key = -1; + struct tm *p_tm; + + if (__isthreaded != 0) { + _pthread_mutex_lock(&gmtime_mutex); + if (gmtime_key < 0) { + if (_pthread_key_create(&gmtime_key, free) < 0) { + _pthread_mutex_unlock(&gmtime_mutex); + return(NULL); + } + } + _pthread_mutex_unlock(&gmtime_mutex); + /* + * Changed to follow POSIX.1 threads standard, which + * is what BSD currently has. + */ + if ((p_tm = _pthread_getspecific(gmtime_key)) == NULL) { + if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) + == NULL) { + return(NULL); + } + _pthread_setspecific(gmtime_key, p_tm); + } + gmtsub(timep, 0L, p_tm); + return(p_tm); + } + else { + gmtsub(timep, 0L, &tm); + return(&tm); + } +} + +struct tm * +gmtime_r(const time_t * timep, struct tm * tm) +{ + gmtsub(timep, 0L, tm); + return(tm); +} + +#ifdef STD_INSPIRED + +struct tm * +offtime(timep, offset) +const time_t * const timep; +const long offset; +{ + gmtsub(timep, offset, &tm); + return &tm; +} + +#endif /* defined STD_INSPIRED */ + +static void +timesub(timep, offset, sp, tmp) +const time_t * const timep; +const long offset; +const struct state * const sp; +struct tm * const tmp; +{ + const struct lsinfo * lp; + long days; + long rem; + long y; + int yleap; + const int * ip; + long corr; + int hit; + int i; + + corr = 0; + hit = 0; +#ifdef ALL_STATE + i = (sp == NULL) ? 0 : sp->leapcnt; +#endif /* defined ALL_STATE */ +#ifndef ALL_STATE + i = sp->leapcnt; +#endif /* State Farm */ + while (--i >= 0) { + lp = &sp->lsis[i]; + if (*timep >= lp->ls_trans) { + if (*timep == lp->ls_trans) { + hit = ((i == 0 && lp->ls_corr > 0) || + lp->ls_corr > sp->lsis[i - 1].ls_corr); + if (hit) + while (i > 0 && + sp->lsis[i].ls_trans == + sp->lsis[i - 1].ls_trans + 1 && + sp->lsis[i].ls_corr == + sp->lsis[i - 1].ls_corr + 1) { + ++hit; + --i; + } + } + corr = lp->ls_corr; + break; + } + } + days = *timep / SECSPERDAY; + rem = *timep % SECSPERDAY; +#ifdef mc68k + if (*timep == 0x80000000) { + /* + ** A 3B1 muffs the division on the most negative number. + */ + days = -24855; + rem = -11648; + } +#endif /* defined mc68k */ + rem += (offset - corr); + while (rem < 0) { + rem += SECSPERDAY; + --days; + } + while (rem >= SECSPERDAY) { + rem -= SECSPERDAY; + ++days; + } + tmp->tm_hour = (int) (rem / SECSPERHOUR); + rem = rem % SECSPERHOUR; + tmp->tm_min = (int) (rem / SECSPERMIN); + /* + ** A positive leap second requires a special + ** representation. This uses "... ??:59:60" et seq. + */ + tmp->tm_sec = (int) (rem % SECSPERMIN) + hit; + tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK); + if (tmp->tm_wday < 0) + tmp->tm_wday += DAYSPERWEEK; + y = EPOCH_YEAR; +#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400) + while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) { + long newy; + + newy = y + days / DAYSPERNYEAR; + if (days < 0) + --newy; + days -= (newy - y) * DAYSPERNYEAR + + LEAPS_THRU_END_OF(newy - 1) - + LEAPS_THRU_END_OF(y - 1); + y = newy; + } + tmp->tm_year = y - TM_YEAR_BASE; + tmp->tm_yday = (int) days; + ip = mon_lengths[yleap]; + for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon)) + days = days - (long) ip[tmp->tm_mon]; + tmp->tm_mday = (int) (days + 1); + tmp->tm_isdst = 0; +#ifdef TM_GMTOFF + tmp->TM_GMTOFF = offset; +#endif /* defined TM_GMTOFF */ +} + +char * +ctime(timep) +const time_t * const timep; +{ +/* +** Section 4.12.3.2 of X3.159-1989 requires that +** The ctime funciton converts the calendar time pointed to by timer +** to local time in the form of a string. It is equivalent to +** asctime(localtime(timer)) +*/ + return asctime(localtime(timep)); +} + +char * +ctime_r(timep, buf) +const time_t * const timep; +char *buf; +{ + struct tm tm; + return asctime_r(localtime_r(timep, &tm), buf); +} + +/* +** Adapted from code provided by Robert Elz, who writes: +** The "best" way to do mktime I think is based on an idea of Bob +** Kridle's (so its said...) from a long time ago. +** [kridle@xinet.com as of 1996-01-16.] +** It does a binary search of the time_t space. Since time_t's are +** just 32 bits, its a max of 32 iterations (even at 64 bits it +** would still be very reasonable). +*/ + +#ifndef WRONG +#define WRONG (-1) +#endif /* !defined WRONG */ + +/* +** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com). +*/ + +static int +increment_overflow(number, delta) +int * number; +int delta; +{ + int number0; + + number0 = *number; + *number += delta; + return (*number < number0) != (delta < 0); +} + +static int +normalize_overflow(tensptr, unitsptr, base) +int * const tensptr; +int * const unitsptr; +const int base; +{ + int tensdelta; + + tensdelta = (*unitsptr >= 0) ? + (*unitsptr / base) : + (-1 - (-1 - *unitsptr) / base); + *unitsptr -= tensdelta * base; + return increment_overflow(tensptr, tensdelta); +} + +static int +tmcomp(atmp, btmp) +const struct tm * const atmp; +const struct tm * const btmp; +{ + int result; + + if ((result = (atmp->tm_year - btmp->tm_year)) == 0 && + (result = (atmp->tm_mon - btmp->tm_mon)) == 0 && + (result = (atmp->tm_mday - btmp->tm_mday)) == 0 && + (result = (atmp->tm_hour - btmp->tm_hour)) == 0 && + (result = (atmp->tm_min - btmp->tm_min)) == 0) + result = atmp->tm_sec - btmp->tm_sec; + return result; +} + +static time_t +time2(tmp, funcp, offset, okayp) +struct tm * const tmp; +void (* const funcp)(const time_t*, long, struct tm*); +const long offset; +int * const okayp; +{ + const struct state * sp; + int dir; + int bits; + int i, j ; + int saved_seconds; + time_t newt; + time_t t; + struct tm yourtm, mytm; + + *okayp = FALSE; + yourtm = *tmp; + if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR)) + return WRONG; + if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY)) + return WRONG; + if (normalize_overflow(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR)) + return WRONG; + /* + ** Turn yourtm.tm_year into an actual year number for now. + ** It is converted back to an offset from TM_YEAR_BASE later. + */ + if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE)) + return WRONG; + while (yourtm.tm_mday <= 0) { + if (increment_overflow(&yourtm.tm_year, -1)) + return WRONG; + i = yourtm.tm_year + (1 < yourtm.tm_mon); + yourtm.tm_mday += year_lengths[isleap(i)]; + } + while (yourtm.tm_mday > DAYSPERLYEAR) { + i = yourtm.tm_year + (1 < yourtm.tm_mon); + yourtm.tm_mday -= year_lengths[isleap(i)]; + if (increment_overflow(&yourtm.tm_year, 1)) + return WRONG; + } + for ( ; ; ) { + i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon]; + if (yourtm.tm_mday <= i) + break; + yourtm.tm_mday -= i; + if (++yourtm.tm_mon >= MONSPERYEAR) { + yourtm.tm_mon = 0; + if (increment_overflow(&yourtm.tm_year, 1)) + return WRONG; + } + } + if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE)) + return WRONG; + if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN) + saved_seconds = 0; + else if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) { + /* + ** We can't set tm_sec to 0, because that might push the + ** time below the minimum representable time. + ** Set tm_sec to 59 instead. + ** This assumes that the minimum representable time is + ** not in the same minute that a leap second was deleted from, + ** which is a safer assumption than using 58 would be. + */ + if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN)) + return WRONG; + saved_seconds = yourtm.tm_sec; + yourtm.tm_sec = SECSPERMIN - 1; + } else { + saved_seconds = yourtm.tm_sec; + yourtm.tm_sec = 0; + } + /* + ** Divide the search space in half + ** (this works whether time_t is signed or unsigned). + */ + bits = TYPE_BIT(time_t) - 1; + /* + ** If we have more than this, we will overflow tm_year for tmcomp(). + ** We should really return an error if we cannot represent it. + */ + if (bits > 56) + bits = 56; + /* + ** If time_t is signed, then 0 is just above the median, + ** assuming two's complement arithmetic. + ** If time_t is unsigned, then (1 << bits) is just above the median. + */ + t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits); + for ( ; ; ) { + (*funcp)(&t, offset, &mytm); + dir = tmcomp(&mytm, &yourtm); + if (dir != 0) { + if (bits-- < 0) + return WRONG; + if (bits < 0) + --t; /* may be needed if new t is minimal */ + else if (dir > 0) + t -= ((time_t) 1) << bits; + else t += ((time_t) 1) << bits; + continue; + } + if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst) + break; + /* + ** Right time, wrong type. + ** Hunt for right time, right type. + ** It's okay to guess wrong since the guess + ** gets checked. + */ + /* + ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's. + */ + sp = (const struct state *) + (((void *) funcp == (void *) localsub) ? + lclptr : gmtptr); +#ifdef ALL_STATE + if (sp == NULL) + return WRONG; +#endif /* defined ALL_STATE */ + for (i = sp->typecnt - 1; i >= 0; --i) { + if (sp->ttis[i].tt_isdst != yourtm.tm_isdst) + continue; + for (j = sp->typecnt - 1; j >= 0; --j) { + if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) + continue; + newt = t + sp->ttis[j].tt_gmtoff - + sp->ttis[i].tt_gmtoff; + (*funcp)(&newt, offset, &mytm); + if (tmcomp(&mytm, &yourtm) != 0) + continue; + if (mytm.tm_isdst != yourtm.tm_isdst) + continue; + /* + ** We have a match. + */ + t = newt; + goto label; + } + } + return WRONG; + } +label: + newt = t + saved_seconds; + if ((newt < t) != (saved_seconds < 0)) + return WRONG; + t = newt; + (*funcp)(&t, offset, tmp); + *okayp = TRUE; + return t; +} + +static time_t +time1(tmp, funcp, offset) +struct tm * const tmp; +void (* const funcp)(const time_t *, long, struct tm *); +const long offset; +{ + time_t t; + const struct state * sp; + int samei, otheri; + int okay; + + if (tmp->tm_isdst > 1) + tmp->tm_isdst = 1; + t = time2(tmp, funcp, offset, &okay); +#ifdef PCTS + /* + ** PCTS code courtesy Grant Sullivan (grant@osf.org). + */ + if (okay) + return t; + if (tmp->tm_isdst < 0) + tmp->tm_isdst = 0; /* reset to std and try again */ +#endif /* defined PCTS */ +#ifndef PCTS + if (okay || tmp->tm_isdst < 0) + return t; +#endif /* !defined PCTS */ + /* + ** We're supposed to assume that somebody took a time of one type + ** and did some math on it that yielded a "struct tm" that's bad. + ** We try to divine the type they started from and adjust to the + ** type they need. + */ + /* + ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's. + */ + sp = (const struct state *) (((void *) funcp == (void *) localsub) ? + lclptr : gmtptr); +#ifdef ALL_STATE + if (sp == NULL) + return WRONG; +#endif /* defined ALL_STATE */ + for (samei = sp->typecnt - 1; samei >= 0; --samei) { + if (sp->ttis[samei].tt_isdst != tmp->tm_isdst) + continue; + for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) { + if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst) + continue; + tmp->tm_sec += sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + t = time2(tmp, funcp, offset, &okay); + if (okay) + return t; + tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + } + } + return WRONG; +} + +time_t +mktime(tmp) +struct tm * const tmp; +{ + time_t mktime_return_value; + _MUTEX_LOCK(&lcl_mutex); + tzset_basic(); + mktime_return_value = time1(tmp, localsub, 0L); + _MUTEX_UNLOCK(&lcl_mutex); + return(mktime_return_value); +} + +#ifdef STD_INSPIRED + +time_t +timelocal(tmp) +struct tm * const tmp; +{ + tmp->tm_isdst = -1; /* in case it wasn't initialized */ + return mktime(tmp); +} + +time_t +timegm(tmp) +struct tm * const tmp; +{ + tmp->tm_isdst = 0; + return time1(tmp, gmtsub, 0L); +} + +time_t +timeoff(tmp, offset) +struct tm * const tmp; +const long offset; +{ + tmp->tm_isdst = 0; + return time1(tmp, gmtsub, offset); +} + +#endif /* defined STD_INSPIRED */ + +#ifdef CMUCS + +/* +** The following is supplied for compatibility with +** previous versions of the CMUCS runtime library. +*/ + +long +gtime(tmp) +struct tm * const tmp; +{ + const time_t t = mktime(tmp); + + if (t == WRONG) + return -1; + return t; +} + +#endif /* defined CMUCS */ + +/* +** XXX--is the below the right way to conditionalize?? +*/ + +#ifdef STD_INSPIRED + +/* +** IEEE Std 1003.1-1988 (POSIX) legislates that 536457599 +** shall correspond to "Wed Dec 31 23:59:59 GMT 1986", which +** is not the case if we are accounting for leap seconds. +** So, we provide the following conversion routines for use +** when exchanging timestamps with POSIX conforming systems. +*/ + +static long +leapcorr(timep) +time_t * timep; +{ + struct state * sp; + struct lsinfo * lp; + int i; + + sp = lclptr; + i = sp->leapcnt; + while (--i >= 0) { + lp = &sp->lsis[i]; + if (*timep >= lp->ls_trans) + return lp->ls_corr; + } + return 0; +} + +time_t +time2posix(t) +time_t t; +{ + tzset(); + return t - leapcorr(&t); +} + +time_t +posix2time(t) +time_t t; +{ + time_t x; + time_t y; + + tzset(); + /* + ** For a positive leap second hit, the result + ** is not unique. For a negative leap second + ** hit, the corresponding time doesn't exist, + ** so we return an adjacent second. + */ + x = t + leapcorr(&t); + y = x - leapcorr(&x); + if (y < t) { + do { + x++; + y = x - leapcorr(&x); + } while (y < t); + if (t != y) + return x - 1; + } else if (y > t) { + do { + --x; + y = x - leapcorr(&x); + } while (y > t); + if (t != y) + return x + 1; + } + return x; +} + +#endif /* defined STD_INSPIRED */ diff --git a/src/lib/libc/stdtime/private.h b/src/lib/libc/stdtime/private.h new file mode 100644 index 0000000..5af1c67 --- /dev/null +++ b/src/lib/libc/stdtime/private.h @@ -0,0 +1,207 @@ +#ifndef PRIVATE_H + +#define PRIVATE_H +/* +** This file is in the public domain, so clarified as of +** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +** +** $FreeBSD: src/lib/libc/stdtime/private.h,v 1.9 2002/05/28 16:59:40 alfred Exp $ +*/ + +/* Stuff moved from Makefile.inc to reduce clutter */ +#ifndef TM_GMTOFF +#define TM_GMTOFF tm_gmtoff +#define TM_ZONE tm_zone +#define STD_INSPIRED 1 +#define PCTS 1 +#define HAVE_LONG_DOUBLE 1 +#define HAVE_STRERROR 1 +#define HAVE_UNISTD_H 1 +#define LOCALE_HOME _PATH_LOCALE +#define TZDIR "/usr/share/zoneinfo" +#endif /* ndef TM_GMTOFF */ + +/* +** This header is for use ONLY with the time conversion code. +** There is no guarantee that it will remain unchanged, +** or that it will remain at all. +** Do NOT copy it to any system include directory. +** Thank you! +*/ + +/* +** ID +*/ + +#ifndef lint +#ifndef NOID +/* +static char privatehid[] = "@(#)private.h 7.43"; +*/ +#endif /* !defined NOID */ +#endif /* !defined lint */ + +/* +** Defaults for preprocessor symbols. +** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'. +*/ + +#ifndef HAVE_ADJTIME +#define HAVE_ADJTIME 1 +#endif /* !defined HAVE_ADJTIME */ + +#ifndef HAVE_GETTEXT +#define HAVE_GETTEXT 0 +#endif /* !defined HAVE_GETTEXT */ + +#ifndef HAVE_SETTIMEOFDAY +#define HAVE_SETTIMEOFDAY 3 +#endif /* !defined HAVE_SETTIMEOFDAY */ + +#ifndef HAVE_STRERROR +#define HAVE_STRERROR 0 +#endif /* !defined HAVE_STRERROR */ + +#ifndef HAVE_UNISTD_H +#define HAVE_UNISTD_H 1 +#endif /* !defined HAVE_UNISTD_H */ + +#ifndef HAVE_UTMPX_H +#define HAVE_UTMPX_H 0 +#endif /* !defined HAVE_UTMPX_H */ + +#ifndef LOCALE_HOME +#define LOCALE_HOME "/usr/lib/locale" +#endif /* !defined LOCALE_HOME */ + +/* +** Nested includes +*/ + +#include "sys/types.h" /* for time_t */ +#include "stdio.h" +#include "errno.h" +#include "string.h" +#include "limits.h" /* for CHAR_BIT */ +#include "time.h" +#include "stdlib.h" + +#if HAVE_GETTEXT - 0 +#include "libintl.h" +#endif /* HAVE_GETTEXT - 0 */ + +#if HAVE_UNISTD_H - 0 +#include "unistd.h" /* for F_OK and R_OK */ +#endif /* HAVE_UNISTD_H - 0 */ + +#if !(HAVE_UNISTD_H - 0) +#ifndef F_OK +#define F_OK 0 +#endif /* !defined F_OK */ +#ifndef R_OK +#define R_OK 4 +#endif /* !defined R_OK */ +#endif /* !(HAVE_UNISTD_H - 0) */ + +/* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ +#define is_digit(c) ((unsigned)(c) - '0' <= 9) + +/* +** SunOS 4.1.1 headers lack FILENAME_MAX. +*/ + +#ifndef FILENAME_MAX + +#ifndef MAXPATHLEN +#ifdef unix +#include "sys/param.h" +#endif /* defined unix */ +#endif /* !defined MAXPATHLEN */ + +#ifdef MAXPATHLEN +#define FILENAME_MAX MAXPATHLEN +#endif /* defined MAXPATHLEN */ +#ifndef MAXPATHLEN +#define FILENAME_MAX 1024 /* Pure guesswork */ +#endif /* !defined MAXPATHLEN */ + +#endif /* !defined FILENAME_MAX */ + +/* +** Finally, some convenience items. +*/ + +#ifndef TRUE +#define TRUE 1 +#endif /* !defined TRUE */ + +#ifndef FALSE +#define FALSE 0 +#endif /* !defined FALSE */ + +#ifndef TYPE_BIT +#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT) +#endif /* !defined TYPE_BIT */ + +#ifndef TYPE_SIGNED +#define TYPE_SIGNED(type) (((type) -1) < 0) +#endif /* !defined TYPE_SIGNED */ + +#ifndef INT_STRLEN_MAXIMUM +/* +** 302 / 1000 is log10(2.0) rounded up. +** Subtract one for the sign bit if the type is signed; +** add one for integer division truncation; +** add one more for a minus sign if the type is signed. +*/ +#define INT_STRLEN_MAXIMUM(type) \ + ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + 1 + TYPE_SIGNED(type)) +#endif /* !defined INT_STRLEN_MAXIMUM */ + +/* +** INITIALIZE(x) +*/ + +#ifndef GNUC_or_lint +#ifdef lint +#define GNUC_or_lint +#endif /* defined lint */ +#ifndef lint +#ifdef __GNUC__ +#define GNUC_or_lint +#endif /* defined __GNUC__ */ +#endif /* !defined lint */ +#endif /* !defined GNUC_or_lint */ + +#ifndef INITIALIZE +#ifdef GNUC_or_lint +#define INITIALIZE(x) ((x) = 0) +#endif /* defined GNUC_or_lint */ +#ifndef GNUC_or_lint +#define INITIALIZE(x) +#endif /* !defined GNUC_or_lint */ +#endif /* !defined INITIALIZE */ + +/* +** For the benefit of GNU folk... +** `_(MSGID)' uses the current locale's message library string for MSGID. +** The default is to use gettext if available, and use MSGID otherwise. +*/ + +#ifndef _ +#if HAVE_GETTEXT - 0 +#define _(msgid) gettext(msgid) +#else /* !(HAVE_GETTEXT - 0) */ +#define _(msgid) msgid +#endif /* !(HAVE_GETTEXT - 0) */ +#endif /* !defined _ */ + +#ifndef TZ_DOMAIN +#define TZ_DOMAIN "tz" +#endif /* !defined TZ_DOMAIN */ + +/* +** UNIX was a registered trademark of UNIX System Laboratories in 1993. +*/ + +#endif /* !defined PRIVATE_H */ diff --git a/src/lib/libc/stdtime/strftime.c b/src/lib/libc/stdtime/strftime.c new file mode 100644 index 0000000..565c6d1 --- /dev/null +++ b/src/lib/libc/stdtime/strftime.c @@ -0,0 +1,447 @@ +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef lint +#ifndef NOID +static const char elsieid[] = "@(#)strftime.c 7.38"; +/* +** Based on the UCB version with the ID appearing below. +** This is ANSIish only when "multibyte character == plain character". +*/ +#endif /* !defined NOID */ +#endif /* !defined lint */ + +#include "namespace.h" +#include "private.h" + +#if defined(LIBC_SCCS) && !defined(lint) +static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.38 2002/09/06 11:24:03 tjr Exp $"); + +#include "tzfile.h" +#include +#include +#include "un-namespace.h" +#include "timelocal.h" + +static char * _add(const char *, char *, const char *); +static char * _conv(int, const char *, char *, const char *); +static char * _fmt(const char *, const struct tm *, char *, const char *); + +size_t strftime(char * __restrict, size_t, const char * __restrict, + const struct tm * __restrict); + +extern char * tzname[]; + +size_t +strftime(char * __restrict s, size_t maxsize, const char * __restrict format, + const struct tm * __restrict t) +{ + char *p; + + tzset(); + p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize); + if (p == s + maxsize) + return 0; + *p = '\0'; + return p - s; +} + +static char * +_fmt(format, t, pt, ptlim) + const char *format; + const struct tm *const t; + char *pt; + const char *const ptlim; +{ + int Ealternative, Oalternative; + struct lc_time_T *tptr = __get_current_time_locale(); + + for ( ; *format; ++format) { + if (*format == '%') { + Ealternative = 0; + Oalternative = 0; +label: + switch (*++format) { + case '\0': + --format; + break; + case 'A': + pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? + "?" : tptr->weekday[t->tm_wday], + pt, ptlim); + continue; + case 'a': + pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ? + "?" : tptr->wday[t->tm_wday], + pt, ptlim); + continue; + case 'B': + pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? + "?" : (Oalternative ? tptr->alt_month : + tptr->month)[t->tm_mon], + pt, ptlim); + continue; + case 'b': + case 'h': + pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ? + "?" : tptr->mon[t->tm_mon], + pt, ptlim); + continue; + case 'C': + /* + ** %C used to do a... + ** _fmt("%a %b %e %X %Y", t); + ** ...whereas now POSIX 1003.2 calls for + ** something completely different. + ** (ado, 5/24/93) + */ + pt = _conv((t->tm_year + TM_YEAR_BASE) / 100, + "%02d", pt, ptlim); + continue; + case 'c': + pt = _fmt(tptr->c_fmt, t, pt, ptlim); + continue; + case 'D': + pt = _fmt("%m/%d/%y", t, pt, ptlim); + continue; + case 'd': + pt = _conv(t->tm_mday, "%02d", pt, ptlim); + continue; + case 'E': + if (Ealternative || Oalternative) + break; + Ealternative++; + goto label; + case 'O': + /* + ** POSIX locale extensions, a la + ** Arnold Robbins' strftime version 3.0. + ** The sequences + ** %Ec %EC %Ex %EX %Ey %EY + ** %Od %oe %OH %OI %Om %OM + ** %OS %Ou %OU %OV %Ow %OW %Oy + ** are supposed to provide alternate + ** representations. + ** (ado, 5/24/93) + ** + ** FreeBSD extensions + ** %OB %Ef %EF + */ + if (Ealternative || Oalternative) + break; + Oalternative++; + goto label; + case 'e': + pt = _conv(t->tm_mday, "%2d", pt, ptlim); + continue; + case 'F': + pt = _fmt("%Y-%m-%d", t, pt, ptlim); + continue; + case 'H': + pt = _conv(t->tm_hour, "%02d", pt, ptlim); + continue; + case 'I': + pt = _conv((t->tm_hour % 12) ? + (t->tm_hour % 12) : 12, + "%02d", pt, ptlim); + continue; + case 'j': + pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim); + continue; + case 'k': + /* + ** This used to be... + ** _conv(t->tm_hour % 12 ? + ** t->tm_hour % 12 : 12, 2, ' '); + ** ...and has been changed to the below to + ** match SunOS 4.1.1 and Arnold Robbins' + ** strftime version 3.0. That is, "%k" and + ** "%l" have been swapped. + ** (ado, 5/24/93) + */ + pt = _conv(t->tm_hour, "%2d", pt, ptlim); + continue; +#ifdef KITCHEN_SINK + case 'K': + /* + ** After all this time, still unclaimed! + */ + pt = _add("kitchen sink", pt, ptlim); + continue; +#endif /* defined KITCHEN_SINK */ + case 'l': + /* + ** This used to be... + ** _conv(t->tm_hour, 2, ' '); + ** ...and has been changed to the below to + ** match SunOS 4.1.1 and Arnold Robbin's + ** strftime version 3.0. That is, "%k" and + ** "%l" have been swapped. + ** (ado, 5/24/93) + */ + pt = _conv((t->tm_hour % 12) ? + (t->tm_hour % 12) : 12, + "%2d", pt, ptlim); + continue; + case 'M': + pt = _conv(t->tm_min, "%02d", pt, ptlim); + continue; + case 'm': + pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim); + continue; + case 'n': + pt = _add("\n", pt, ptlim); + continue; + case 'p': + pt = _add((t->tm_hour >= 12) ? + tptr->pm : + tptr->am, + pt, ptlim); + continue; + case 'R': + pt = _fmt("%H:%M", t, pt, ptlim); + continue; + case 'r': + pt = _fmt(tptr->ampm_fmt, t, pt, ptlim); + continue; + case 'S': + pt = _conv(t->tm_sec, "%02d", pt, ptlim); + continue; + case 's': + { + struct tm tm; + char buf[INT_STRLEN_MAXIMUM( + time_t) + 1]; + time_t mkt; + + tm = *t; + mkt = mktime(&tm); + if (TYPE_SIGNED(time_t)) + (void) sprintf(buf, "%ld", + (long) mkt); + else (void) sprintf(buf, "%lu", + (unsigned long) mkt); + pt = _add(buf, pt, ptlim); + } + continue; + case 'T': + pt = _fmt("%H:%M:%S", t, pt, ptlim); + continue; + case 't': + pt = _add("\t", pt, ptlim); + continue; + case 'U': + pt = _conv((t->tm_yday + 7 - t->tm_wday) / 7, + "%02d", pt, ptlim); + continue; + case 'u': + /* + ** From Arnold Robbins' strftime version 3.0: + ** "ISO 8601: Weekday as a decimal number + ** [1 (Monday) - 7]" + ** (ado, 5/24/93) + */ + pt = _conv((t->tm_wday == 0) ? 7 : t->tm_wday, + "%d", pt, ptlim); + continue; + case 'V': /* ISO 8601 week number */ + case 'G': /* ISO 8601 year (four digits) */ + case 'g': /* ISO 8601 year (two digits) */ +/* +** From Arnold Robbins' strftime version 3.0: "the week number of the +** year (the first Monday as the first day of week 1) as a decimal number +** (01-53)." +** (ado, 1993-05-24) +** +** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn: +** "Week 01 of a year is per definition the first week which has the +** Thursday in this year, which is equivalent to the week which contains +** the fourth day of January. In other words, the first week of a new year +** is the week which has the majority of its days in the new year. Week 01 +** might also contain days from the previous year and the week before week +** 01 of a year is the last week (52 or 53) of the previous year even if +** it contains days from the new year. A week starts with Monday (day 1) +** and ends with Sunday (day 7). For example, the first week of the year +** 1997 lasts from 1996-12-30 to 1997-01-05..." +** (ado, 1996-01-02) +*/ + { + int year; + int yday; + int wday; + int w; + + year = t->tm_year + TM_YEAR_BASE; + yday = t->tm_yday; + wday = t->tm_wday; + for ( ; ; ) { + int len; + int bot; + int top; + + len = isleap(year) ? + DAYSPERLYEAR : + DAYSPERNYEAR; + /* + ** What yday (-3 ... 3) does + ** the ISO year begin on? + */ + bot = ((yday + 11 - wday) % + DAYSPERWEEK) - 3; + /* + ** What yday does the NEXT + ** ISO year begin on? + */ + top = bot - + (len % DAYSPERWEEK); + if (top < -3) + top += DAYSPERWEEK; + top += len; + if (yday >= top) { + ++year; + w = 1; + break; + } + if (yday >= bot) { + w = 1 + ((yday - bot) / + DAYSPERWEEK); + break; + } + --year; + yday += isleap(year) ? + DAYSPERLYEAR : + DAYSPERNYEAR; + } +#ifdef XPG4_1994_04_09 + if ((w == 52 + && t->tm_mon == TM_JANUARY) + || (w == 1 + && t->tm_mon == TM_DECEMBER)) + w = 53; +#endif /* defined XPG4_1994_04_09 */ + if (*format == 'V') + pt = _conv(w, "%02d", + pt, ptlim); + else if (*format == 'g') { + pt = _conv(year % 100, "%02d", + pt, ptlim); + } else pt = _conv(year, "%04d", + pt, ptlim); + } + continue; + case 'v': + /* + ** From Arnold Robbins' strftime version 3.0: + ** "date as dd-bbb-YYYY" + ** (ado, 5/24/93) + */ + pt = _fmt("%e-%b-%Y", t, pt, ptlim); + continue; + case 'W': + pt = _conv((t->tm_yday + 7 - + (t->tm_wday ? + (t->tm_wday - 1) : 6)) / 7, + "%02d", pt, ptlim); + continue; + case 'w': + pt = _conv(t->tm_wday, "%d", pt, ptlim); + continue; + case 'X': + pt = _fmt(tptr->X_fmt, t, pt, ptlim); + continue; + case 'x': + pt = _fmt(tptr->x_fmt, t, pt, ptlim); + continue; + case 'y': + pt = _conv((t->tm_year + TM_YEAR_BASE) % 100, + "%02d", pt, ptlim); + continue; + case 'Y': + pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d", + pt, ptlim); + continue; + case 'Z': + if (t->tm_zone != NULL) + pt = _add(t->tm_zone, pt, ptlim); + else + if (t->tm_isdst == 0 || t->tm_isdst == 1) { + pt = _add(tzname[t->tm_isdst], + pt, ptlim); + } else pt = _add("?", pt, ptlim); + continue; + case 'z': + { + long absoff; + if (t->tm_gmtoff >= 0) { + absoff = t->tm_gmtoff; + pt = _add("+", pt, ptlim); + } else { + absoff = -t->tm_gmtoff; + pt = _add("-", pt, ptlim); + } + pt = _conv(absoff / 3600, "%02d", + pt, ptlim); + pt = _conv((absoff % 3600) / 60, "%02d", + pt, ptlim); + }; + continue; + case '+': + pt = _fmt(tptr->date_fmt, t, pt, ptlim); + continue; + case '%': + /* + * X311J/88-090 (4.12.3.5): if conversion char is + * undefined, behavior is undefined. Print out the + * character itself as printf(3) also does. + */ + default: + break; + } + } + if (pt == ptlim) + break; + *pt++ = *format; + } + return pt; +} + +static char * +_conv(n, format, pt, ptlim) + const int n; + const char *const format; + char *const pt; + const char *const ptlim; +{ + char buf[INT_STRLEN_MAXIMUM(int) + 1]; + + (void) sprintf(buf, format, n); + return _add(buf, pt, ptlim); +} + +static char * +_add(str, pt, ptlim) + const char *str; + char *pt; + const char *const ptlim; +{ + while (pt < ptlim && (*pt = *str++) != '\0') + ++pt; + return pt; +} diff --git a/src/lib/libc/stdtime/strptime.c b/src/lib/libc/stdtime/strptime.c new file mode 100644 index 0000000..901a742 --- /dev/null +++ b/src/lib/libc/stdtime/strptime.c @@ -0,0 +1,538 @@ +/* + * Powerdog Industries kindly requests feedback from anyone modifying + * this function: + * + * Date: Thu, 05 Jun 1997 23:17:17 -0400 + * From: Kevin Ruddy + * To: James FitzGibbon + * Subject: Re: Use of your strptime(3) code (fwd) + * + * The reason for the "no mod" clause was so that modifications would + * come back and we could integrate them and reissue so that a wider + * audience could use it (thereby spreading the wealth). This has + * made it possible to get strptime to work on many operating systems. + * I'm not sure why that's "plain unacceptable" to the FreeBSD team. + * + * Anyway, you can change it to "with or without modification" as + * you see fit. Enjoy. + * + * Kevin Ruddy + * Powerdog Industries, Inc. + */ +/* + * Copyright (c) 1994 Powerdog Industries. 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 Powerdog Industries. + * 4. The name of Powerdog Industries may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``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 POWERDOG INDUSTRIES 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. + */ + +#include +#ifndef lint +#ifndef NOID +static char copyright[] __unused = +"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved."; +static char sccsid[] __unused = "@(#)strptime.c 0.1 (Powerdog) 94/03/27"; +#endif /* !defined NOID */ +#endif /* not lint */ +__FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $"); + +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include "un-namespace.h" +#include "libc_private.h" +#include "timelocal.h" + +static char * _strptime(const char *, const char *, struct tm *, int *); + +#define asizeof(a) (sizeof (a) / sizeof ((a)[0])) + +static char * +_strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp) +{ + char c; + const char *ptr; + int i, + len; + int Ealternative, Oalternative; + struct lc_time_T *tptr = __get_current_time_locale(); + + ptr = fmt; + while (*ptr != 0) { + if (*buf == 0) + break; + + c = *ptr++; + + if (c != '%') { + if (isspace((unsigned char)c)) + while (*buf != 0 && isspace((unsigned char)*buf)) + buf++; + else if (c != *buf++) + return 0; + continue; + } + + Ealternative = 0; + Oalternative = 0; +label: + c = *ptr++; + switch (c) { + case 0: + case '%': + if (*buf++ != '%') + return 0; + break; + + case '+': + buf = _strptime(buf, tptr->date_fmt, tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'C': + if (!isdigit((unsigned char)*buf)) + return 0; + + /* XXX This will break for 3-digit centuries. */ + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i < 19) + return 0; + + tm->tm_year = i * 100 - 1900; + break; + + case 'c': + buf = _strptime(buf, tptr->c_fmt, tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'D': + buf = _strptime(buf, "%m/%d/%y", tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'E': + if (Ealternative || Oalternative) + break; + Ealternative++; + goto label; + + case 'O': + if (Ealternative || Oalternative) + break; + Oalternative++; + goto label; + + case 'F': + buf = _strptime(buf, "%Y-%m-%d", tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'R': + buf = _strptime(buf, "%H:%M", tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'r': + buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'T': + buf = _strptime(buf, "%H:%M:%S", tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'X': + buf = _strptime(buf, tptr->X_fmt, tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'x': + buf = _strptime(buf, tptr->x_fmt, tm, GMTp); + if (buf == 0) + return 0; + break; + + case 'j': + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 3; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i < 1 || i > 366) + return 0; + + tm->tm_yday = i - 1; + break; + + case 'M': + case 'S': + if (*buf == 0 || isspace((unsigned char)*buf)) + break; + + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + + if (c == 'M') { + if (i > 59) + return 0; + tm->tm_min = i; + } else { + if (i > 60) + return 0; + tm->tm_sec = i; + } + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'H': + case 'I': + case 'k': + case 'l': + /* + * Of these, %l is the only specifier explicitly + * documented as not being zero-padded. However, + * there is no harm in allowing zero-padding. + * + * XXX The %l specifier may gobble one too many + * digits if used incorrectly. + */ + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (c == 'H' || c == 'k') { + if (i > 23) + return 0; + } else if (i > 12) + return 0; + + tm->tm_hour = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'p': + /* + * XXX This is bogus if parsed before hour-related + * specifiers. + */ + len = strlen(tptr->am); + if (strncasecmp(buf, tptr->am, len) == 0) { + if (tm->tm_hour > 12) + return 0; + if (tm->tm_hour == 12) + tm->tm_hour = 0; + buf += len; + break; + } + + len = strlen(tptr->pm); + if (strncasecmp(buf, tptr->pm, len) == 0) { + if (tm->tm_hour > 12) + return 0; + if (tm->tm_hour != 12) + tm->tm_hour += 12; + buf += len; + break; + } + + return 0; + + case 'A': + case 'a': + for (i = 0; i < asizeof(tptr->weekday); i++) { + len = strlen(tptr->weekday[i]); + if (strncasecmp(buf, tptr->weekday[i], + len) == 0) + break; + len = strlen(tptr->wday[i]); + if (strncasecmp(buf, tptr->wday[i], + len) == 0) + break; + } + if (i == asizeof(tptr->weekday)) + return 0; + + tm->tm_wday = i; + buf += len; + break; + + case 'U': + case 'W': + /* + * XXX This is bogus, as we can not assume any valid + * information present in the tm structure at this + * point to calculate a real value, so just check the + * range for now. + */ + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i > 53) + return 0; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'w': + if (!isdigit((unsigned char)*buf)) + return 0; + + i = *buf - '0'; + if (i > 6) + return 0; + + tm->tm_wday = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'd': + case 'e': + /* + * The %e specifier is explicitly documented as not + * being zero-padded but there is no harm in allowing + * such padding. + * + * XXX The %e specifier may gobble one too many + * digits if used incorrectly. + */ + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i > 31) + return 0; + + tm->tm_mday = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'B': + case 'b': + case 'h': + for (i = 0; i < asizeof(tptr->month); i++) { + if (Oalternative) { + if (c == 'B') { + len = strlen(tptr->alt_month[i]); + if (strncasecmp(buf, + tptr->alt_month[i], + len) == 0) + break; + } + } else { + len = strlen(tptr->month[i]); + if (strncasecmp(buf, tptr->month[i], + len) == 0) + break; + len = strlen(tptr->mon[i]); + if (strncasecmp(buf, tptr->mon[i], + len) == 0) + break; + } + } + if (i == asizeof(tptr->month)) + return 0; + + tm->tm_mon = i; + buf += len; + break; + + case 'm': + if (!isdigit((unsigned char)*buf)) + return 0; + + len = 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (i < 1 || i > 12) + return 0; + + tm->tm_mon = i - 1; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 's': + { + char *cp; + int sverrno; + long n; + time_t t; + + sverrno = errno; + errno = 0; + n = strtol(buf, &cp, 10); + if (errno == ERANGE || (long)(t = n) != n) { + errno = sverrno; + return 0; + } + errno = sverrno; + buf = cp; + gmtime_r(&t, tm); + *GMTp = 1; + } + break; + + case 'Y': + case 'y': + if (*buf == 0 || isspace((unsigned char)*buf)) + break; + + if (!isdigit((unsigned char)*buf)) + return 0; + + len = (c == 'Y') ? 4 : 2; + for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { + i *= 10; + i += *buf - '0'; + len--; + } + if (c == 'Y') + i -= 1900; + if (c == 'y' && i < 69) + i += 100; + if (i < 0) + return 0; + + tm->tm_year = i; + + if (*buf != 0 && isspace((unsigned char)*buf)) + while (*ptr != 0 && !isspace((unsigned char)*ptr)) + ptr++; + break; + + case 'Z': + { + const char *cp; + char *zonestr; + + for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/} + if (cp - buf) { + zonestr = alloca(cp - buf + 1); + strncpy(zonestr, buf, cp - buf); + zonestr[cp - buf] = '\0'; + tzset(); + if (0 == strcmp(zonestr, "GMT")) { + *GMTp = 1; + } else if (0 == strcmp(zonestr, tzname[0])) { + tm->tm_isdst = 0; + } else if (0 == strcmp(zonestr, tzname[1])) { + tm->tm_isdst = 1; + } else { + return 0; + } + buf += cp - buf; + } + } + break; + } + } + return (char *)buf; +} + + +char * +strptime(const char * __restrict buf, const char * __restrict fmt, + struct tm * __restrict tm) +{ + char *ret; + int gmt; + + gmt = 0; + ret = _strptime(buf, fmt, tm, &gmt); + if (ret && gmt) { + time_t t = timegm(tm); + localtime_r(&t, tm); + } + + return (ret); +} diff --git a/src/lib/libc/stdtime/time32.c b/src/lib/libc/stdtime/time32.c new file mode 100644 index 0000000..5085dd7 --- /dev/null +++ b/src/lib/libc/stdtime/time32.c @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2001 FreeBSD Inc. + * All rights reserved. + * + * These routines are for converting time_t to fixed-bit representations + * for use in protocols or storage. When converting time to a larger + * representation of time_t these routines are expected to assume temporal + * locality and use the 50-year rule to properly set the msb bits. XXX + * + * Redistribution and use under the terms of the COPYRIGHT file at the + * base of the source tree. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdtime/time32.c,v 1.5 2002/06/17 01:42:29 wollman Exp $"); + +#include +#include + +/* + * Convert a 32 bit representation of time_t into time_t. XXX needs to + * implement the 50-year rule to handle post-2038 conversions. + */ +time_t +_time32_to_time(__int32_t t32) +{ + return((time_t)t32); +} + +/* + * Convert time_t to a 32 bit representation. If time_t is 64 bits we can + * simply chop it down. The resulting 32 bit representation can be + * converted back to a temporally local 64 bit time_t using time32_to_time. + */ +__int32_t +_time_to_time32(time_t t) +{ + return((__int32_t)t); +} + +/* + * Convert a 64 bit representation of time_t into time_t. If time_t is + * represented as 32 bits we can simply chop it and not support times + * past 2038. + */ +time_t +_time64_to_time(__int64_t t64) +{ + return((time_t)t64); +} + +/* + * Convert time_t to a 64 bit representation. If time_t is represented + * as 32 bits we simply sign-extend and do not support times past 2038. + */ +__int64_t +_time_to_time64(time_t t) +{ + return((__int64_t)t); +} + +/* + * Convert to/from 'long'. Depending on the sizeof(long) this may or + * may not require using the 50-year rule. + */ +long +_time_to_long(time_t t) +{ + if (sizeof(long) == sizeof(__int64_t)) + return(_time_to_time64(t)); + return((long)t); +} + +time_t +_long_to_time(long tlong) +{ + if (sizeof(long) == sizeof(__int32_t)) + return(_time32_to_time(tlong)); + return((time_t)tlong); +} + +/* + * Convert to/from 'int'. Depending on the sizeof(int) this may or + * may not require using the 50-year rule. + */ +int +_time_to_int(time_t t) +{ + if (sizeof(int) == sizeof(__int64_t)) + return(_time_to_time64(t)); + return((int)t); +} + +time_t +_int_to_time(int tint) +{ + if (sizeof(int) == sizeof(__int32_t)) + return(_time32_to_time(tint)); + return((time_t)tint); +} diff --git a/src/lib/libc/stdtime/timelocal.c b/src/lib/libc/stdtime/timelocal.c new file mode 100644 index 0000000..2aba03c --- /dev/null +++ b/src/lib/libc/stdtime/timelocal.c @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2001 Alexey Zelkin + * Copyright (c) 1997 FreeBSD Inc. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.25 2003/06/13 00:14:07 jkh Exp $"); + +#include + +#include "ldpart.h" +#include "timelocal.h" + +static struct lc_time_T _time_locale; +static int _time_using_locale; +static char *time_locale_buf; + +#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) + +static const struct lc_time_T _C_time_locale = { + { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }, { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, { + "Sun", "Mon", "Tue", "Wed", + "Thu", "Fri", "Sat" + }, { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" + }, + + /* X_fmt */ + "%H:%M:%S", + + /* + * x_fmt + * Since the C language standard calls for + * "date, using locale's date format," anything goes. + * Using just numbers (as here) makes Quakers happier; + * it's also compatible with SVR4. + */ + "%m/%d/%y", + + /* + * c_fmt + */ + "%a %b %e %H:%M:%S %Y", + + /* am */ + "AM", + + /* pm */ + "PM", + + /* date_fmt */ + "%a %b %e %H:%M:%S %Z %Y", + + /* alt_month + * Standalone months forms for %OB + */ + { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, + + /* md_order + * Month / day order in dates + */ + "md", + + /* ampm_fmt + * To determine 12-hour clock format time (empty, if N/A) + */ + "%I:%M:%S %p" +}; + +struct lc_time_T * +__get_current_time_locale(void) +{ + return (_time_using_locale + ? &_time_locale + : (struct lc_time_T *)&_C_time_locale); +} + +int +__time_load_locale(const char *name) +{ + return (__part_load_locale(name, &_time_using_locale, + &time_locale_buf, "LC_TIME", + LCTIME_SIZE, LCTIME_SIZE, + (const char **)&_time_locale)); +} diff --git a/src/lib/libc/stdtime/timelocal.h b/src/lib/libc/stdtime/timelocal.h new file mode 100644 index 0000000..0b0a59a --- /dev/null +++ b/src/lib/libc/stdtime/timelocal.h @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 1997-2002 FreeBSD Project. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/stdtime/timelocal.h,v 1.11 2002/01/24 15:07:44 phantom Exp $ + */ + +#ifndef _TIMELOCAL_H_ +#define _TIMELOCAL_H_ + +/* + * Private header file for the strftime and strptime localization + * stuff. + */ +struct lc_time_T { + const char *mon[12]; + const char *month[12]; + const char *wday[7]; + const char *weekday[7]; + const char *X_fmt; + const char *x_fmt; + const char *c_fmt; + const char *am; + const char *pm; + const char *date_fmt; + const char *alt_month[12]; + const char *md_order; + const char *ampm_fmt; +}; + +struct lc_time_T *__get_current_time_locale(void); +int __time_load_locale(const char *); + +#endif /* !_TIMELOCAL_H_ */ diff --git a/src/lib/libc/stdtime/tzfile.h b/src/lib/libc/stdtime/tzfile.h new file mode 100644 index 0000000..378d7ae --- /dev/null +++ b/src/lib/libc/stdtime/tzfile.h @@ -0,0 +1,192 @@ +#ifndef TZFILE_H +#define TZFILE_H + + +/* +** This file is in the public domain, so clarified as of +** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). +** +** $FreeBSD: src/lib/libc/stdtime/tzfile.h,v 1.8 2002/03/22 23:42:05 obrien Exp $ +*/ + +/* +** This header is for use ONLY with the time conversion code. +** There is no guarantee that it will remain unchanged, +** or that it will remain at all. +** Do NOT copy it to any system include directory. +** Thank you! +*/ + +/* +** ID +*/ + +#ifndef lint +#ifndef NOID +/* +static char tzfilehid[] = "@(#)tzfile.h 7.14"; +*/ +#endif /* !defined NOID */ +#endif /* !defined lint */ + +/* +** Information about time zone files. +*/ + +#ifndef TZDIR +#define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ +#endif /* !defined TZDIR */ + +#ifndef TZDEFAULT +#define TZDEFAULT "/etc/localtime" +#endif /* !defined TZDEFAULT */ + +#ifndef TZDEFRULES +#define TZDEFRULES "posixrules" +#endif /* !defined TZDEFRULES */ + +/* +** Each file begins with. . . +*/ + +#define TZ_MAGIC "TZif" + +struct tzhead { + char tzh_magic[4]; /* TZ_MAGIC */ + char tzh_reserved[16]; /* reserved for future use */ + char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ + char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ + char tzh_leapcnt[4]; /* coded number of leap seconds */ + char tzh_timecnt[4]; /* coded number of transition times */ + char tzh_typecnt[4]; /* coded number of local time types */ + char tzh_charcnt[4]; /* coded number of abbr. chars */ +}; + +/* +** . . .followed by. . . +** +** tzh_timecnt (char [4])s coded transition times a la time(2) +** tzh_timecnt (unsigned char)s types of local time starting at above +** tzh_typecnt repetitions of +** one (char [4]) coded UTC offset in seconds +** one (unsigned char) used to set tm_isdst +** one (unsigned char) that's an abbreviation list index +** tzh_charcnt (char)s '\0'-terminated zone abbreviations +** tzh_leapcnt repetitions of +** one (char [4]) coded leap second transition times +** one (char [4]) total correction after above +** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition +** time is standard time, if FALSE, +** transition time is wall clock time +** if absent, transition times are +** assumed to be wall clock time +** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition +** time is UTC, if FALSE, +** transition time is local time +** if absent, transition times are +** assumed to be local time +*/ + +/* +** In the current implementation, "tzset()" refuses to deal with files that +** exceed any of the limits below. +*/ + +#ifndef TZ_MAX_TIMES +/* +** The TZ_MAX_TIMES value below is enough to handle a bit more than a +** year's worth of solar time (corrected daily to the nearest second) or +** 138 years of Pacific Presidential Election time +** (where there are three time zone transitions every fourth year). +*/ +#define TZ_MAX_TIMES 370 +#endif /* !defined TZ_MAX_TIMES */ + +#ifndef TZ_MAX_TYPES +#ifndef NOSOLAR +#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ +#endif /* !defined NOSOLAR */ +#ifdef NOSOLAR +/* +** Must be at least 14 for Europe/Riga as of Jan 12 1995, +** as noted by Earl Chew . +*/ +#define TZ_MAX_TYPES 20 /* Maximum number of local time types */ +#endif /* !defined NOSOLAR */ +#endif /* !defined TZ_MAX_TYPES */ + +#ifndef TZ_MAX_CHARS +#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ + /* (limited by what unsigned chars can hold) */ +#endif /* !defined TZ_MAX_CHARS */ + +#ifndef TZ_MAX_LEAPS +#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ +#endif /* !defined TZ_MAX_LEAPS */ + +#define SECSPERMIN 60 +#define MINSPERHOUR 60 +#define HOURSPERDAY 24 +#define DAYSPERWEEK 7 +#define DAYSPERNYEAR 365 +#define DAYSPERLYEAR 366 +#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) +#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) +#define MONSPERYEAR 12 + +#define TM_SUNDAY 0 +#define TM_MONDAY 1 +#define TM_TUESDAY 2 +#define TM_WEDNESDAY 3 +#define TM_THURSDAY 4 +#define TM_FRIDAY 5 +#define TM_SATURDAY 6 + +#define TM_JANUARY 0 +#define TM_FEBRUARY 1 +#define TM_MARCH 2 +#define TM_APRIL 3 +#define TM_MAY 4 +#define TM_JUNE 5 +#define TM_JULY 6 +#define TM_AUGUST 7 +#define TM_SEPTEMBER 8 +#define TM_OCTOBER 9 +#define TM_NOVEMBER 10 +#define TM_DECEMBER 11 + +#define TM_YEAR_BASE 1900 + +#define EPOCH_YEAR 1970 +#define EPOCH_WDAY TM_THURSDAY + +/* +** Accurate only for the past couple of centuries; +** that will probably do. +*/ + +#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) + +#ifndef USG + +/* +** Use of the underscored variants may cause problems if you move your code to +** certain System-V-based systems; for maximum portability, use the +** underscore-free variants. The underscored variants are provided for +** backward compatibility only; they may disappear from future versions of +** this file. +*/ + +#define SECS_PER_MIN SECSPERMIN +#define MINS_PER_HOUR MINSPERHOUR +#define HOURS_PER_DAY HOURSPERDAY +#define DAYS_PER_WEEK DAYSPERWEEK +#define DAYS_PER_NYEAR DAYSPERNYEAR +#define DAYS_PER_LYEAR DAYSPERLYEAR +#define SECS_PER_HOUR SECSPERHOUR +#define SECS_PER_DAY SECSPERDAY +#define MONS_PER_YEAR MONSPERYEAR + +#endif /* !defined USG */ + +#endif /* !defined TZFILE_H */ diff --git a/src/lib/libc/string/Makefile b/src/lib/libc/string/Makefile new file mode 100644 index 0000000..5fa4ec8 --- /dev/null +++ b/src/lib/libc/string/Makefile @@ -0,0 +1,33 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc +#Objects +OBJS = bcmp.o bcopy.o bzero.o ffs.o ffsl.o fls.o flsl.o index.o memccpy.o memchr.o memcmp.o memcpy.o memmove.o memset.o rindex.o stpcpy.o strcasecmp.o strcasestr.o strcat.o strchr.o strcmp.o strcoll.o strcpy.o strcspn.o strdup.o strerror.o strlcat.o strlcpy.o strlen.o strmode.o strncat.o strncmp.o strncpy.o strnstr.o strpbrk.o strrchr.o strsep.o strsignal.o strspn.o strstr.o strtok.o strxfrm.o swab.o wcscat.o wcschr.o wcscmp.o wcscoll.o wcscpy.o wcscspn.o wcslcat.o wcslcpy.o wcslen.o wcsncat.o wcsncmp.o wcsncpy.o wcspbrk.o wcsrchr.o wcsspn.o wcsstr.o wcstok.o wcswidth.o wcsxfrm.o wmemchr.o wmemcmp.o wmemcpy.o wmemmove.o wmemset.o + +#Output +OUTPUT = libc.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) $(CFLAGS) -Wall -nostdinc -O -I../include -c -o $@ $< + +.cc.s: + $(CXX) $(CFLAGS) -Wall -nostdinc -O -I../include -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) -Wall -nostdinc -O -I../include -I../../../include -I../locale -c $< + +.c.s: + $(CC) $(CFLAGS) -Wall -nostdinc -O -I../include -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) -Wall -nostdinc -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/string/bcmp.c b/src/lib/libc/string/bcmp.c new file mode 100644 index 0000000..f5227df --- /dev/null +++ b/src/lib/libc/string/bcmp.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1987, 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[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/bcmp.c,v 1.5 2002/08/30 21:07:40 robert Exp $"); + +#include + +/* + * bcmp -- vax cmpc3 instruction + */ +int +bcmp(const void *b1, const void *b2, size_t length) +{ + char *p1, *p2; + + if (length == 0) + return (0); + p1 = (char *)b1; + p2 = (char *)b2; + do + if (*p1++ != *p2++) + break; + while (--length); + return (length); +} diff --git a/src/lib/libc/string/bcopy.c b/src/lib/libc/string/bcopy.c new file mode 100644 index 0000000..983b2fb --- /dev/null +++ b/src/lib/libc/string/bcopy.c @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/bcopy.c,v 1.6 2003/10/26 03:55:58 peter Exp $"); + +#include + +/* + * sizeof(word) MUST BE A POWER OF TWO + * SO THAT wmask BELOW IS ALL ONES + */ +typedef int word; /* "word" used for optimal copy speed */ + +#define wsize sizeof(word) +#define wmask (wsize - 1) + +/* + * Copy a block of memory, handling overlap. + * This is the routine that actually implements + * (the portable versions of) bcopy, memcpy, and memmove. + */ +#if defined(MEMCOPY) || defined(MEMMOVE) +#include + +void * +#ifdef MEMCOPY +memcpy +#else +memmove +#endif +(void *dst0, const void *src0, size_t length) +#else +#include + +void +bcopy(const void *src0, void *dst0, size_t length) +#endif +{ + char *dst = dst0; + const char *src = src0; + size_t t; + + if (length == 0 || dst == src) /* nothing to do */ + goto done; + + /* + * Macros: loop-t-times; and loop-t-times, t>0 + */ +#define TLOOP(s) if (t) TLOOP1(s) +#define TLOOP1(s) do { s; } while (--t) + + if ((unsigned long)dst < (unsigned long)src) { + /* + * Copy forward. + */ + t = (uintptr_t)src; /* only need low bits */ + if ((t | (uintptr_t)dst) & wmask) { + /* + * Try to align operands. This cannot be done + * unless the low bits match. + */ + if ((t ^ (uintptr_t)dst) & wmask || length < wsize) + t = length; + else + t = wsize - (t & wmask); + length -= t; + TLOOP1(*dst++ = *src++); + } + /* + * Copy whole words, then mop up any trailing bytes. + */ + t = length / wsize; + TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize); + t = length & wmask; + TLOOP(*dst++ = *src++); + } else { + /* + * Copy backwards. Otherwise essentially the same. + * Alignment works as before, except that it takes + * (t&wmask) bytes to align, not wsize-(t&wmask). + */ + src += length; + dst += length; + t = (uintptr_t)src; + if ((t | (uintptr_t)dst) & wmask) { + if ((t ^ (uintptr_t)dst) & wmask || length <= wsize) + t = length; + else + t &= wmask; + length -= t; + TLOOP1(*--dst = *--src); + } + t = length / wsize; + TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src); + t = length & wmask; + TLOOP(*--dst = *--src); + } +done: +#if defined(MEMCOPY) || defined(MEMMOVE) + return (dst0); +#else + return; +#endif +} diff --git a/src/lib/libc/string/bzero.c b/src/lib/libc/string/bzero.c new file mode 100644 index 0000000..85bc5e8 --- /dev/null +++ b/src/lib/libc/string/bzero.c @@ -0,0 +1,5 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/bzero.c,v 1.2 2002/03/22 21:53:19 obrien Exp $"); + +#define BZERO +#include "memset.c" diff --git a/src/lib/libc/string/ffs.c b/src/lib/libc/string/ffs.c new file mode 100644 index 0000000..ef4d0f0 --- /dev/null +++ b/src/lib/libc/string/ffs.c @@ -0,0 +1,55 @@ +/*- + * 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 */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/ffs.c,v 1.7 2004/01/14 07:46:36 des Exp $"); + +#include + +/* + * Find First Set bit + */ +int +ffs(int mask) +{ + int bit; + + if (mask == 0) + return(0); + for (bit = 1; !(mask & 1); bit++) + mask = (unsigned int)mask >> 1; + return (bit); +} diff --git a/src/lib/libc/string/ffsl.c b/src/lib/libc/string/ffsl.c new file mode 100644 index 0000000..1c25a0a --- /dev/null +++ b/src/lib/libc/string/ffsl.c @@ -0,0 +1,52 @@ +/*- + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/ffsl.c,v 1.2 2004/01/14 07:46:36 des Exp $"); + +#include + +/* + * Find First Set bit + */ +int +ffsl(long mask) +{ + int bit; + + if (mask == 0) + return(0); + for (bit = 1; !(mask & 1); bit++) + mask = (unsigned long)mask >> 1; + return (bit); +} diff --git a/src/lib/libc/string/fls.c b/src/lib/libc/string/fls.c new file mode 100644 index 0000000..8550cf8 --- /dev/null +++ b/src/lib/libc/string/fls.c @@ -0,0 +1,52 @@ +/*- + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/fls.c,v 1.2 2004/01/14 07:46:36 des Exp $"); + +#include + +/* + * Find Last Set bit + */ +int +fls(int mask) +{ + int bit; + + if (mask == 0) + return (0); + for (bit = 1; mask != 1; bit++) + mask = (unsigned int)mask >> 1; + return (bit); +} diff --git a/src/lib/libc/string/flsl.c b/src/lib/libc/string/flsl.c new file mode 100644 index 0000000..f9612b5 --- /dev/null +++ b/src/lib/libc/string/flsl.c @@ -0,0 +1,52 @@ +/*- + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/flsl.c,v 1.2 2004/01/14 07:46:36 des Exp $"); + +#include + +/* + * Find Last Set bit + */ +int +flsl(long mask) +{ + int bit; + + if (mask == 0) + return (0); + for (bit = 1; mask != 1; bit++) + mask = (unsigned long)mask >> 1; + return (bit); +} diff --git a/src/lib/libc/string/index.c b/src/lib/libc/string/index.c new file mode 100644 index 0000000..be2c052 --- /dev/null +++ b/src/lib/libc/string/index.c @@ -0,0 +1,65 @@ +/*- + * 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[] = "@(#)index.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/index.c,v 1.7 2003/12/18 07:44:53 jkh Exp $"); + +#include + +#ifdef STRCHR +#include + +char * +strchr +#else +#include + +char * +index +#endif +(const char *p, int ch) +{ + char c; + + c = ch; + for (;; ++p) { + if (*p == c) + return ((char *)p); + if (*p == '\0') + return (NULL); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/string/memccpy.c b/src/lib/libc/string/memccpy.c new file mode 100644 index 0000000..0bc6a11 --- /dev/null +++ b/src/lib/libc/string/memccpy.c @@ -0,0 +1,60 @@ +/*- + * 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[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/memccpy.c,v 1.5 2002/03/21 18:44:54 obrien Exp $"); + +#include + +void * +memccpy(t, f, c, n) + void *t; + const void *f; + int c; + size_t n; +{ + + if (n) { + unsigned char *tp = t; + const unsigned char *fp = f; + unsigned char uc = c; + do { + if ((*tp++ = *fp++) == uc) + return (tp); + } while (--n != 0); + } + return (0); +} diff --git a/src/lib/libc/string/memchr.c b/src/lib/libc/string/memchr.c new file mode 100644 index 0000000..e3c6679 --- /dev/null +++ b/src/lib/libc/string/memchr.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/memchr.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include + +void * +memchr(s, c, n) + const void *s; + unsigned char c; + size_t n; +{ + if (n != 0) { + const unsigned char *p = s; + + do { + if (*p++ == c) + return ((void *)(p - 1)); + } while (--n != 0); + } + return (NULL); +} diff --git a/src/lib/libc/string/memcmp.c b/src/lib/libc/string/memcmp.c new file mode 100644 index 0000000..045e4d9 --- /dev/null +++ b/src/lib/libc/string/memcmp.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/memcmp.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include + +/* + * Compare memory regions. + */ +int +memcmp(s1, s2, n) + const void *s1, *s2; + size_t n; +{ + if (n != 0) { + const unsigned char *p1 = s1, *p2 = s2; + + do { + if (*p1++ != *p2++) + return (*--p1 - *--p2); + } while (--n != 0); + } + return (0); +} diff --git a/src/lib/libc/string/memcpy.c b/src/lib/libc/string/memcpy.c new file mode 100644 index 0000000..dfc03ae --- /dev/null +++ b/src/lib/libc/string/memcpy.c @@ -0,0 +1,5 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/memcpy.c,v 1.2 2002/03/22 21:53:19 obrien Exp $"); + +#define MEMCOPY +#include "bcopy.c" diff --git a/src/lib/libc/string/memmove.c b/src/lib/libc/string/memmove.c new file mode 100644 index 0000000..8f44e82 --- /dev/null +++ b/src/lib/libc/string/memmove.c @@ -0,0 +1,5 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/memmove.c,v 1.2 2002/03/22 21:53:19 obrien Exp $"); + +#define MEMMOVE +#include "bcopy.c" diff --git a/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c new file mode 100644 index 0000000..1cb8644 --- /dev/null +++ b/src/lib/libc/string/memset.c @@ -0,0 +1,132 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Hibler and Chris Torek. + * + * 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[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/memset.c,v 1.8 2002/09/01 21:53:46 robert Exp $"); + +#include + +#include + +#define wsize sizeof(u_int) +#define wmask (wsize - 1) + +#ifdef BZERO +#include + +#define RETURN return +#define VAL 0 +#define WIDEVAL 0 + +void +bzero(void *dst0, size_t length) +#else +#include + +#define RETURN return (dst0) +#define VAL c0 +#define WIDEVAL c + +void * +memset(void *dst0, int c0, size_t length) +#endif +{ + size_t t; +#ifndef BZERO + u_int c; +#endif + u_char *dst; + + dst = dst0; + /* + * If not enough words, just fill bytes. A length >= 2 words + * guarantees that at least one of them is `complete' after + * any necessary alignment. For instance: + * + * |-----------|-----------|-----------| + * |00|01|02|03|04|05|06|07|08|09|0A|00| + * ^---------------------^ + * dst dst+length-1 + * + * but we use a minimum of 3 here since the overhead of the code + * to do word writes is substantial. + */ + if (length < 3 * wsize) { + while (length != 0) { + *dst++ = VAL; + --length; + } + RETURN; + } + +#ifndef BZERO + if ((c = (u_char)c0) != 0) { /* Fill the word. */ + c = (c << 8) | c; /* u_int is 16 bits. */ +#if UINT_MAX > 0xffff + c = (c << 16) | c; /* u_int is 32 bits. */ +#endif +#if UINT_MAX > 0xffffffff + c = (c << 32) | c; /* u_int is 64 bits. */ +#endif + } +#endif + /* Align destination by filling in bytes. */ + if ((t = (long)dst & wmask) != 0) { + t = wsize - t; + length -= t; + do { + *dst++ = VAL; + } while (--t != 0); + } + + /* Fill words. Length was >= 2*words so we know t >= 1 here. */ + t = length / wsize; + do { + *(u_int *)dst = WIDEVAL; + dst += wsize; + } while (--t != 0); + + /* Mop up trailing bytes, if any. */ + t = length & wmask; + if (t != 0) + do { + *dst++ = VAL; + } while (--t != 0); + RETURN; +} diff --git a/src/lib/libc/string/rindex.c b/src/lib/libc/string/rindex.c new file mode 100644 index 0000000..697b69a --- /dev/null +++ b/src/lib/libc/string/rindex.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/rindex.c,v 1.7 2003/12/18 07:44:53 jkh Exp $"); + +#include + +#ifdef STRRCHR +#include + +char * +strrchr +#else +#include + +char * +rindex +#endif +(const char *p, int ch) +{ + char *save; + char c; + + c = ch; + for (save = NULL;; ++p) { + if (*p == c) + save = (char *)p; + if (*p == '\0') + return (save); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/string/stpcpy.c b/src/lib/libc/string/stpcpy.c new file mode 100644 index 0000000..2742bf7 --- /dev/null +++ b/src/lib/libc/string/stpcpy.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1999 + * David E. O'Brien + * Copyright (c) 1988, 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. 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[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/stpcpy.c,v 1.1 2002/10/03 19:39:20 obrien Exp $"); + +#include + +char * +stpcpy(char * to, const char * from) +{ + + for (; (*to = *from); ++from, ++to); + return(to); +} diff --git a/src/lib/libc/string/strcasecmp.c b/src/lib/libc/string/strcasecmp.c new file mode 100644 index 0000000..6f400d7 --- /dev/null +++ b/src/lib/libc/string/strcasecmp.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1987, 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[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strcasecmp.c,v 1.6 2002/08/30 15:40:01 robert Exp $"); + +#include +#include + +typedef unsigned char u_char; + +int +strcasecmp(s1, s2) + const char *s1, *s2; +{ + const u_char + *us1 = (const u_char *)s1, + *us2 = (const u_char *)s2; + + while (tolower(*us1) == tolower(*us2++)) + if (*us1++ == '\0') + return (0); + return (tolower(*us1) - tolower(*--us2)); +} + +int +strncasecmp(s1, s2, n) + const char *s1, *s2; + size_t n; +{ + if (n != 0) { + const u_char + *us1 = (const u_char *)s1, + *us2 = (const u_char *)s2; + + do { + if (tolower(*us1) != tolower(*us2++)) + return (tolower(*us1) - tolower(*--us2)); + if (*us1++ == '\0') + break; + } while (--n != 0); + } + return (0); +} diff --git a/src/lib/libc/string/strcasestr.c b/src/lib/libc/string/strcasestr.c new file mode 100644 index 0000000..dafcb79 --- /dev/null +++ b/src/lib/libc/string/strcasestr.c @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strcasestr.c,v 1.3 2002/03/21 18:44:54 obrien Exp $"); + +#include +#include + +/* + * Find the first occurrence of find in s, ignore case. + */ +char * +strcasestr(s, find) + const char *s, *find; +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} diff --git a/src/lib/libc/string/strcat.c b/src/lib/libc/string/strcat.c new file mode 100644 index 0000000..5d28c86 --- /dev/null +++ b/src/lib/libc/string/strcat.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)strcat.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strcat.c,v 1.7 2002/09/06 11:24:06 tjr Exp $"); + +#include + +char * +strcat(char * __restrict s, const char * __restrict append) +{ + char *save = s; + + for (; *s; ++s); + while ((*s++ = *append++)); + return(save); +} diff --git a/src/lib/libc/string/strchr.c b/src/lib/libc/string/strchr.c new file mode 100644 index 0000000..2fb9114 --- /dev/null +++ b/src/lib/libc/string/strchr.c @@ -0,0 +1,5 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strchr.c,v 1.2 2002/03/22 21:53:19 obrien Exp $"); + +#define STRCHR +#include "index.c" diff --git a/src/lib/libc/string/strcmp.c b/src/lib/libc/string/strcmp.c new file mode 100644 index 0000000..1befcbc --- /dev/null +++ b/src/lib/libc/string/strcmp.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strcmp.c,v 1.5 2002/03/21 18:44:54 obrien Exp $"); + +#include + +/* + * Compare strings. + */ +int +strcmp(s1, s2) + const char *s1, *s2; +{ + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); +} diff --git a/src/lib/libc/string/strcoll.c b/src/lib/libc/string/strcoll.c new file mode 100644 index 0000000..b93ce48 --- /dev/null +++ b/src/lib/libc/string/strcoll.c @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 1995 Alex Tatmanjants + * at Electronni Visti IA, Kiev, Ukraine. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strcoll.c,v 1.13 2001/11/07 19:55:16 obrien Exp $"); + +#include +#include +#include "collate.h" + +int +strcoll(s, s2) + const char *s, *s2; +{ + int len, len2, prim, prim2, sec, sec2, ret, ret2; + const char *t, *t2; + char *tt, *tt2; + + if (__collate_load_error) + return strcmp(s, s2); + + len = len2 = 1; + ret = ret2 = 0; + if (__collate_substitute_nontrivial) { + t = tt = __collate_substitute(s); + t2 = tt2 = __collate_substitute(s2); + } else { + tt = tt2 = NULL; + t = s; + t2 = s2; + } + while(*t && *t2) { + prim = prim2 = 0; + while(*t && !prim) { + __collate_lookup(t, &len, &prim, &sec); + t += len; + } + while(*t2 && !prim2) { + __collate_lookup(t2, &len2, &prim2, &sec2); + t2 += len2; + } + if(!prim || !prim2) + break; + if(prim != prim2) { + ret = prim - prim2; + goto end; + } + if(!ret2) + ret2 = sec - sec2; + } + if(!*t && *t2) + ret = -(int)((u_char)*t2); + else if(*t && !*t2) + ret = (u_char)*t; + else if(!*t && !*t2) + ret = ret2; + end: + free(tt); + free(tt2); + + return ret; +} diff --git a/src/lib/libc/string/strcpy.c b/src/lib/libc/string/strcpy.c new file mode 100644 index 0000000..5cd2f45 --- /dev/null +++ b/src/lib/libc/string/strcpy.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strcpy.c,v 1.7 2002/09/06 11:24:06 tjr Exp $"); + +#include + +char * +strcpy(char * __restrict to, const char * __restrict from) +{ + char *save = to; + + for (; (*to = *from); ++from, ++to); + return(save); +} diff --git a/src/lib/libc/string/strcspn.c b/src/lib/libc/string/strcspn.c new file mode 100644 index 0000000..48354a6 --- /dev/null +++ b/src/lib/libc/string/strcspn.c @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)strcspn.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strcspn.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include + +/* + * Span the complement of string s2. + */ +size_t +strcspn(s1, s2) + const char *s1; + const char *s2; +{ + const char *p, *spanp; + char c, sc; + + /* + * Stop as soon as we find any character from s2. Note that there + * must be a NUL in s2; it suffices to stop when we find that, too. + */ + for (p = s1;;) { + c = *p++; + spanp = s2; + do { + if ((sc = *spanp++) == c) + return (p - 1 - s1); + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/string/strdup.c b/src/lib/libc/string/strdup.c new file mode 100644 index 0000000..a9881a1 --- /dev/null +++ b/src/lib/libc/string/strdup.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strdup.c,v 1.4 2001/11/07 19:55:16 obrien Exp $"); + +#include +#include +#include + +char * +strdup(str) + const char *str; +{ + size_t len; + char *copy; + + len = strlen(str) + 1; + if ((copy = malloc(len)) == NULL) + return (NULL); + memcpy(copy, str, len); + return (copy); +} diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c new file mode 100644 index 0000000..b1c4913 --- /dev/null +++ b/src/lib/libc/string/strerror.c @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 1988, 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[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strerror.c,v 1.13 2003/05/01 19:03:14 nectar Exp $"); + +#include +#include +#include + +#define UPREFIX "Unknown error: " + +/* + * Define a buffer size big enough to describe a 64-bit signed integer + * converted to ASCII decimal (19 bytes), with an optional leading sign + * (1 byte); finally, we get the prefix and a trailing NUL from UPREFIX. + */ +#define EBUFSIZE (20 + sizeof(UPREFIX)) + +/* + * Doing this by hand instead of linking with stdio(3) avoids bloat for + * statically linked binaries. + */ +static void +errstr(int num, char *buf, size_t len) +{ + char *t; + unsigned int uerr; + char tmp[EBUFSIZE]; + + t = tmp + sizeof(tmp); + *--t = '\0'; + uerr = (num >= 0) ? num : -num; + do { + *--t = "0123456789"[uerr % 10]; + } while (uerr /= 10); + if (num < 0) + *--t = '-'; + strlcpy(buf, UPREFIX, len); + strlcat(buf, t, len); +} + +int +strerror_r(int errnum, char *strerrbuf, size_t buflen) +{ + + if (errnum < 1 || errnum >= sys_nerr) { + errstr(errnum, strerrbuf, buflen); + return (EINVAL); + } + if (strlcpy(strerrbuf, sys_errlist[errnum], buflen) >= buflen) + return (ERANGE); + return (0); +} + +char * +strerror(int num) +{ + static char ebuf[EBUFSIZE]; + + if (num > 0 && num < sys_nerr) + return ((char *)sys_errlist[num]); + errno = EINVAL; + errstr(num, ebuf, sizeof(ebuf)); + return (ebuf); +} diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c new file mode 100644 index 0000000..19924e5 --- /dev/null +++ b/src/lib/libc/string/strlcat.c @@ -0,0 +1,75 @@ +/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"); +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strlcat.c,v 1.9 2003/05/01 19:03:14 nectar Exp $"); + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c new file mode 100644 index 0000000..eedb6a9 --- /dev/null +++ b/src/lib/libc/string/strlcpy.c @@ -0,0 +1,70 @@ +/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"); +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.7 2003/05/01 19:03:14 nectar Exp $"); + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/src/lib/libc/string/strlen.c b/src/lib/libc/string/strlen.c new file mode 100644 index 0000000..c67667d --- /dev/null +++ b/src/lib/libc/string/strlen.c @@ -0,0 +1,51 @@ +/*- + * 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[] = "@(#)strlen.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strlen.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include + +size_t +strlen(str) + const char *str; +{ + const char *s; + + for (s = str; *s; ++s); + return(s - str); +} + diff --git a/src/lib/libc/string/strmode.c b/src/lib/libc/string/strmode.c new file mode 100644 index 0000000..2409b4e --- /dev/null +++ b/src/lib/libc/string/strmode.c @@ -0,0 +1,154 @@ +/*- + * 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[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strmode.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include +#include +#include + +void +strmode(mode, p) + mode_t mode; + char *p; +{ + /* print type */ + switch (mode & S_IFMT) { + case S_IFDIR: /* directory */ + *p++ = 'd'; + break; + case S_IFCHR: /* character special */ + *p++ = 'c'; + break; + case S_IFBLK: /* block special */ + *p++ = 'b'; + break; + case S_IFREG: /* regular */ + *p++ = '-'; + break; + case S_IFLNK: /* symbolic link */ + *p++ = 'l'; + break; + case S_IFSOCK: /* socket */ + *p++ = 's'; + break; +#ifdef S_IFIFO + case S_IFIFO: /* fifo */ + *p++ = 'p'; + break; +#endif +#ifdef S_IFWHT + case S_IFWHT: /* whiteout */ + *p++ = 'w'; + break; +#endif + default: /* unknown */ + *p++ = '?'; + break; + } + /* usr */ + if (mode & S_IRUSR) + *p++ = 'r'; + else + *p++ = '-'; + if (mode & S_IWUSR) + *p++ = 'w'; + else + *p++ = '-'; + switch (mode & (S_IXUSR | S_ISUID)) { + case 0: + *p++ = '-'; + break; + case S_IXUSR: + *p++ = 'x'; + break; + case S_ISUID: + *p++ = 'S'; + break; + case S_IXUSR | S_ISUID: + *p++ = 's'; + break; + } + /* group */ + if (mode & S_IRGRP) + *p++ = 'r'; + else + *p++ = '-'; + if (mode & S_IWGRP) + *p++ = 'w'; + else + *p++ = '-'; + switch (mode & (S_IXGRP | S_ISGID)) { + case 0: + *p++ = '-'; + break; + case S_IXGRP: + *p++ = 'x'; + break; + case S_ISGID: + *p++ = 'S'; + break; + case S_IXGRP | S_ISGID: + *p++ = 's'; + break; + } + /* other */ + if (mode & S_IROTH) + *p++ = 'r'; + else + *p++ = '-'; + if (mode & S_IWOTH) + *p++ = 'w'; + else + *p++ = '-'; + switch (mode & (S_IXOTH | S_ISVTX)) { + case 0: + *p++ = '-'; + break; + case S_IXOTH: + *p++ = 'x'; + break; + case S_ISVTX: + *p++ = 'T'; + break; + case S_IXOTH | S_ISVTX: + *p++ = 't'; + break; + } + *p++ = ' '; /* will be a '+' if ACL's implemented */ + *p = '\0'; +} diff --git a/src/lib/libc/string/strncat.c b/src/lib/libc/string/strncat.c new file mode 100644 index 0000000..e05e030 --- /dev/null +++ b/src/lib/libc/string/strncat.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strncat.c,v 1.6 2002/09/06 11:24:06 tjr Exp $"); + +#include + +/* + * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes + * are written at dst (at most n+1 bytes being appended). Return dst. + */ +char * +strncat(char * __restrict dst, const char * __restrict src, size_t n) +{ + if (n != 0) { + char *d = dst; + const char *s = src; + + while (*d != 0) + d++; + do { + if ((*d = *s++) == 0) + break; + d++; + } while (--n != 0); + *d = 0; + } + return (dst); +} diff --git a/src/lib/libc/string/strncmp.c b/src/lib/libc/string/strncmp.c new file mode 100644 index 0000000..6b0cfc8 --- /dev/null +++ b/src/lib/libc/string/strncmp.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strncmp.c,v 1.5 2002/03/21 18:44:54 obrien Exp $"); + +#include + +int +strncmp(s1, s2, n) + const char *s1, *s2; + size_t n; +{ + + if (n == 0) + return (0); + do { + if (*s1 != *s2++) + return (*(const unsigned char *)s1 - + *(const unsigned char *)(s2 - 1)); + if (*s1++ == 0) + break; + } while (--n != 0); + return (0); +} diff --git a/src/lib/libc/string/strncpy.c b/src/lib/libc/string/strncpy.c new file mode 100644 index 0000000..2fcc957 --- /dev/null +++ b/src/lib/libc/string/strncpy.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strncpy.c,v 1.6 2002/09/06 11:24:06 tjr Exp $"); + +#include + +/* + * Copy src to dst, truncating or null-padding to always copy n bytes. + * Return dst. + */ +char * +strncpy(char * __restrict dst, const char * __restrict src, size_t n) +{ + if (n != 0) { + char *d = dst; + const char *s = src; + + do { + if ((*d++ = *s++) == 0) { + /* NUL pad the remaining n-1 bytes */ + while (--n != 0) + *d++ = 0; + break; + } + } while (--n != 0); + } + return (dst); +} diff --git a/src/lib/libc/string/strnstr.c b/src/lib/libc/string/strnstr.c new file mode 100644 index 0000000..9f3b038 --- /dev/null +++ b/src/lib/libc/string/strnstr.c @@ -0,0 +1,72 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strnstr.c,v 1.2 2001/11/07 19:55:16 obrien Exp $"); + +#include + +/* + * Find the first occurrence of find in s, where the search is limited to the + * first slen characters of s. + */ +char * +strnstr(s, find, slen) + const char *s; + const char *find; + size_t slen; +{ + char c, sc; + size_t len; + + if ((c = *find++) != '\0') { + len = strlen(find); + do { + do { + if ((sc = *s++) == '\0' || slen-- < 1) + return (NULL); + } while (sc != c); + if (len > slen) + return (NULL); + } while (strncmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} diff --git a/src/lib/libc/string/strpbrk.c b/src/lib/libc/string/strpbrk.c new file mode 100644 index 0000000..fb0e1d4 --- /dev/null +++ b/src/lib/libc/string/strpbrk.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 1985, 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[] = "@(#)strpbrk.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strpbrk.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include + +/* + * Find the first occurrence in s1 of a character in s2 (excluding NUL). + */ +char * +strpbrk(s1, s2) + const char *s1, *s2; +{ + const char *scanp; + int c, sc; + + while ((c = *s1++) != 0) { + for (scanp = s2; (sc = *scanp++) != 0;) + if (sc == c) + return ((char *)(s1 - 1)); + } + return (NULL); +} diff --git a/src/lib/libc/string/strrchr.c b/src/lib/libc/string/strrchr.c new file mode 100644 index 0000000..b8c0500 --- /dev/null +++ b/src/lib/libc/string/strrchr.c @@ -0,0 +1,5 @@ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strrchr.c,v 1.2 2002/03/22 21:53:19 obrien Exp $"); + +#define STRRCHR +#include "rindex.c" diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c new file mode 100644 index 0000000..d0bccce --- /dev/null +++ b/src/lib/libc/string/strsep.c @@ -0,0 +1,81 @@ +/*- + * 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[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strsep.c,v 1.5 2002/03/21 18:44:54 obrien Exp $"); + +#include +#include + +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, strsep returns NULL. + */ +char * +strsep(stringp, delim) + char **stringp; + const char *delim; +{ + char *s; + const char *spanp; + int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/string/strsignal.c b/src/lib/libc/string/strsignal.c new file mode 100644 index 0000000..0cbb4cd --- /dev/null +++ b/src/lib/libc/string/strsignal.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 1988, 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[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strsignal.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include +#include +#include + +char * +strsignal(num) + int num; +{ +#define UPREFIX "Unknown signal: " + static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ + unsigned int signum; + char *p, *t; + char tmp[40]; + + signum = num; /* convert to unsigned */ + if (signum < sys_nsig) + return ((char *)sys_siglist[signum]); + + /* Do this by hand, so we don't link to stdio(3). */ + t = tmp; + if (num < 0) + signum = -signum; + do { + *t++ = "0123456789"[signum % 10]; + } while (signum /= 10); + if (num < 0) + *t++ = '-'; + for (p = ebuf + sizeof(UPREFIX) - 1;;) { + *p++ = *--t; + if (t <= tmp) + break; + } + *p = '\0'; + return (ebuf); +} diff --git a/src/lib/libc/string/strspn.c b/src/lib/libc/string/strspn.c new file mode 100644 index 0000000..ae28642 --- /dev/null +++ b/src/lib/libc/string/strspn.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 1989, 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[] = "@(#)strspn.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strspn.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include + +/* + * Span the string s2 (skip characters that are in s2). + */ +size_t +strspn(s1, s2) + const char *s1; + const char *s2; +{ + const char *p = s1, *spanp; + char c, sc; + + /* + * Skip any characters in s2, excluding the terminating \0. + */ +cont: + c = *p++; + for (spanp = s2; (sc = *spanp++) != 0;) + if (sc == c) + goto cont; + return (p - 1 - s1); +} diff --git a/src/lib/libc/string/strstr.c b/src/lib/libc/string/strstr.c new file mode 100644 index 0000000..f51d170 --- /dev/null +++ b/src/lib/libc/string/strstr.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strstr.c,v 1.4 2002/03/21 18:44:54 obrien Exp $"); + +#include + +/* + * Find the first occurrence of find in s. + */ +char * +strstr(s, find) + const char *s, *find; +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while (sc != c); + } while (strncmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} diff --git a/src/lib/libc/string/strtok.c b/src/lib/libc/string/strtok.c new file mode 100644 index 0000000..6aec194 --- /dev/null +++ b/src/lib/libc/string/strtok.c @@ -0,0 +1,140 @@ +/*- + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 1988, 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 + * notices, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notices, 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 Softweyr LLC, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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[] = "@(#)strtok.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strtok.c,v 1.9 2002/09/07 02:53:19 tjr Exp $"); + +#include +#ifdef DEBUG_STRTOK +#include +#endif +#include + +char *__strtok_r(char *, const char *, char **); + +__weak_reference(__strtok_r, strtok_r); + +char * +__strtok_r(char *s, const char *delim, char **last) +{ + char *spanp, *tok; + int c, sc; + + if (s == NULL && (s = *last) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0;) { + if (c == sc) + goto cont; + } + + if (c == 0) { /* no non-delimiter characters */ + *last = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = (char *)delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = '\0'; + *last = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +char * +strtok(char *s, const char *delim) +{ + static char *last; + + return (__strtok_r(s, delim, &last)); +} + +#ifdef DEBUG_STRTOK +/* + * Test the tokenizer. + */ +int +main(void) +{ + char blah[80], test[80]; + char *brkb, *brkt, *phrase, *sep, *word; + + sep = "\\/:;=-"; + phrase = "foo"; + + printf("String tokenizer test:\n"); + strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); + for (word = strtok(test, sep); word; word = strtok(NULL, sep)) + printf("Next word is \"%s\".\n", word); + strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function."); + + for (word = strtok_r(test, sep, &brkt); word; + word = strtok_r(NULL, sep, &brkt)) { + strcpy(blah, "blah:blat:blab:blag"); + + for (phrase = strtok_r(blah, sep, &brkb); phrase; + phrase = strtok_r(NULL, sep, &brkb)) + printf("So far we're at %s:%s\n", word, phrase); + } + + return (0); +} + +#endif /* DEBUG_STRTOK */ diff --git a/src/lib/libc/string/strxfrm.c b/src/lib/libc/string/strxfrm.c new file mode 100644 index 0000000..3ab7b72 --- /dev/null +++ b/src/lib/libc/string/strxfrm.c @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 1995 Alex Tatmanjants + * at Electronni Visti IA, Kiev, Ukraine. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/strxfrm.c,v 1.15 2002/09/06 11:24:06 tjr Exp $"); + +#include +#include +#include "collate.h" + +size_t +strxfrm(char * __restrict dest, const char * __restrict src, size_t len) +{ + int prim, sec, l; + size_t slen; + char *s, *ss; + + if (!*src) { + if (len > 0) + *dest = '\0'; + return 0; + } + + if (__collate_load_error) { + slen = strlen(src); + if (len > 0) { + if (slen < len) + strcpy(dest, src); + else { + strncpy(dest, src, len - 1); + dest[len - 1] = '\0'; + } + } + return slen; + } + + slen = 0; + prim = sec = 0; + ss = s = __collate_substitute(src); + while (*s) { + while (*s && !prim) { + __collate_lookup(s, &l, &prim, &sec); + s += l; + } + if (prim) { + if (len > 1) { + *dest++ = (char)prim; + len--; + } + slen++; + prim = 0; + } + } + free(ss); + if (len > 0) + *dest = '\0'; + + return slen; +} diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c new file mode 100644 index 0000000..de57703 --- /dev/null +++ b/src/lib/libc/string/swab.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Jeffrey Mogul. + * + * 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[] = "@(#)swab.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/string/swab.c,v 1.5 2002/08/30 20:33:05 robert Exp $"); + +#include + +void +swab(const void * __restrict from, void * __restrict to, size_t len) +{ + unsigned long temp; + int n; + char *fp, *tp; + + n = len >> 1; + fp = (char *)from; + tp = (char *)to; +#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp + /* round to multiple of 8 */ + for (; n & 0x7; --n) + STEP; + for (n >>= 3; n > 0; --n) { + STEP; STEP; STEP; STEP; + STEP; STEP; STEP; STEP; + } +} diff --git a/src/lib/libc/string/wcscat.c b/src/lib/libc/string/wcscat.c new file mode 100644 index 0000000..cf7812f --- /dev/null +++ b/src/lib/libc/string/wcscat.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcscat.c,v 1.8 2002/09/26 09:28:55 tjr Exp $"); + +#include + +wchar_t * +wcscat(s1, s2) + wchar_t * __restrict s1; + const wchar_t * __restrict s2; +{ + wchar_t *cp; + + cp = s1; + while (*cp != L'\0') + cp++; + while ((*cp++ = *s2++) != L'\0') + ; + + return (s1); +} diff --git a/src/lib/libc/string/wcschr.c b/src/lib/libc/string/wcschr.c new file mode 100644 index 0000000..0fae132 --- /dev/null +++ b/src/lib/libc/string/wcschr.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/wcschr.c,v 1.7 2002/10/23 10:47:47 tjr Exp $"); + +#include + +wchar_t * +wcschr(const wchar_t *s, wchar_t c) +{ + + while (*s != c && *s != L'\0') + s++; + if (*s == c) + return ((wchar_t *)s); + return (NULL); +} diff --git a/src/lib/libc/string/wcscmp.c b/src/lib/libc/string/wcscmp.c new file mode 100644 index 0000000..20152b2 --- /dev/null +++ b/src/lib/libc/string/wcscmp.c @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; +#if 0 +__RCSID("$NetBSD: wcscmp.c,v 1.3 2001/01/05 12:13:12 itojun Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ +__FBSDID("$FreeBSD: src/lib/libc/string/wcscmp.c,v 1.7 2002/10/23 11:08:40 tjr Exp $"); + +#include + +/* + * Compare strings. + */ +int +wcscmp(s1, s2) + const wchar_t *s1, *s2; +{ + + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + /* XXX assumes wchar_t = int */ + return (*(const unsigned int *)s1 - *(const unsigned int *)--s2); +} diff --git a/src/lib/libc/string/wcscoll.c b/src/lib/libc/string/wcscoll.c new file mode 100644 index 0000000..5095158 --- /dev/null +++ b/src/lib/libc/string/wcscoll.c @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/wcscoll.c,v 1.3 2004/04/07 09:47:56 tjr Exp $"); + +#include +#include +#include +#include +#include "collate.h" + +static char *__mbsdup(const wchar_t *); + +/* + * Placeholder implementation of wcscoll(). Attempts to use the single-byte + * collation ordering where possible, and falls back on wcscmp() in locales + * with extended character sets. + */ +int +wcscoll(const wchar_t *ws1, const wchar_t *ws2) +{ + char *mbs1, *mbs2; + int diff, sverrno; + + if (__collate_load_error || MB_CUR_MAX > 1) + /* + * Locale has no special collating order, could not be + * loaded, or has an extended character set; do a fast binary + * comparison. + */ + return (wcscmp(ws1, ws2)); + + if ((mbs1 = __mbsdup(ws1)) == NULL || (mbs2 = __mbsdup(ws2)) == NULL) { + /* + * Out of memory or illegal wide chars; fall back to wcscmp() + * but leave errno indicating the error. Callers that don't + * check for error will get a reasonable but often slightly + * incorrect result. + */ + sverrno = errno; + free(mbs1); + errno = sverrno; + return (wcscmp(ws1, ws2)); + } + + diff = strcoll(mbs1, mbs2); + sverrno = errno; + free(mbs1); + free(mbs2); + errno = sverrno; + + return (diff); +} + +static char * +__mbsdup(const wchar_t *ws) +{ + static const mbstate_t initial; + mbstate_t st; + const wchar_t *wcp; + size_t len; + char *mbs; + + wcp = ws; + st = initial; + if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1) + return (NULL); + if ((mbs = malloc(len + 1)) == NULL) + return (NULL); + st = initial; + wcsrtombs(mbs, &ws, len + 1, &st); + + return (mbs); +} diff --git a/src/lib/libc/string/wcscpy.c b/src/lib/libc/string/wcscpy.c new file mode 100644 index 0000000..b4c236a --- /dev/null +++ b/src/lib/libc/string/wcscpy.c @@ -0,0 +1,51 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcscpy.c,v 1.8 2002/09/26 09:23:07 tjr Exp $"); + +#include + +wchar_t * +wcscpy(s1, s2) + wchar_t * __restrict s1; + const wchar_t * __restrict s2; +{ + wchar_t *cp; + + cp = s1; + while ((*cp++ = *s2++) != L'\0') + ; + + return (s1); +} diff --git a/src/lib/libc/string/wcscspn.c b/src/lib/libc/string/wcscspn.c new file mode 100644 index 0000000..c16f270 --- /dev/null +++ b/src/lib/libc/string/wcscspn.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcscspn.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcscspn.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include + +size_t +wcscspn(s, set) + const wchar_t *s; + const wchar_t *set; +{ + const wchar_t *p; + const wchar_t *q; + + p = s; + while (*p) { + q = set; + while (*q) { + if (*p == *q) + goto done; + q++; + } + p++; + } + +done: + return (p - s); +} diff --git a/src/lib/libc/string/wcslcat.c b/src/lib/libc/string/wcslcat.c new file mode 100644 index 0000000..f3b9a63 --- /dev/null +++ b/src/lib/libc/string/wcslcat.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. + * + * from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcslcat.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include +#include + +/* + * Appends src to string dst of size siz (unlike wcsncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns wcslen(initial dst) + wcslen(src); if retval >= siz, + * truncation occurred. + */ +size_t +wcslcat(dst, src, siz) + wchar_t *dst; + const wchar_t *src; + size_t siz; +{ + wchar_t *d = dst; + const wchar_t *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != '\0' && n-- != 0) + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + wcslen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/src/lib/libc/string/wcslcpy.c b/src/lib/libc/string/wcslcpy.c new file mode 100644 index 0000000..273c8fd --- /dev/null +++ b/src/lib/libc/string/wcslcpy.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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. + * + * from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcslcpy.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns wcslen(src); if retval >= siz, truncation occurred. + */ +size_t +wcslcpy(dst, src, siz) + wchar_t *dst; + const wchar_t *src; + size_t siz; +{ + wchar_t *d = dst; + const wchar_t *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/src/lib/libc/string/wcslen.c b/src/lib/libc/string/wcslen.c new file mode 100644 index 0000000..5e462a1 --- /dev/null +++ b/src/lib/libc/string/wcslen.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcslen.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcslen.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include + +size_t +wcslen(s) + const wchar_t *s; +{ + const wchar_t *p; + + p = s; + while (*p) + p++; + + return p - s; +} diff --git a/src/lib/libc/string/wcsncat.c b/src/lib/libc/string/wcsncat.c new file mode 100644 index 0000000..5abb442 --- /dev/null +++ b/src/lib/libc/string/wcsncat.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcsncat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcsncat.c,v 1.7 2002/09/21 00:29:23 tjr Exp $"); + +#include + +wchar_t * +wcsncat(s1, s2, n) + wchar_t * __restrict s1; + const wchar_t * __restrict s2; + size_t n; +{ + wchar_t *p; + wchar_t *q; + const wchar_t *r; + + p = s1; + while (*p) + p++; + q = p; + r = s2; + while (*r && n) { + *q++ = *r++; + n--; + } + *q = '\0'; + return s1; +} diff --git a/src/lib/libc/string/wcsncmp.c b/src/lib/libc/string/wcsncmp.c new file mode 100644 index 0000000..7043e06 --- /dev/null +++ b/src/lib/libc/string/wcsncmp.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1989, 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. + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; +__RCSID("$NetBSD: wcsncmp.c,v 1.3 2001/01/05 12:13:13 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcsncmp.c,v 1.7 2002/10/23 11:08:40 tjr Exp $"); + +#include + +int +wcsncmp(s1, s2, n) + const wchar_t *s1, *s2; + size_t n; +{ + + if (n == 0) + return (0); + do { + if (*s1 != *s2++) { + /* XXX assumes wchar_t = int */ + return (*(const unsigned int *)s1 - + *(const unsigned int *)--s2); + } + if (*s1++ == 0) + break; + } while (--n != 0); + return (0); +} diff --git a/src/lib/libc/string/wcsncpy.c b/src/lib/libc/string/wcsncpy.c new file mode 100644 index 0000000..fb9cef0 --- /dev/null +++ b/src/lib/libc/string/wcsncpy.c @@ -0,0 +1,68 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/string/wcsncpy.c,v 1.9 2002/10/24 02:48:45 tjr Exp $"); + +#include + +/* + * Copy src to dst, truncating or null-padding to always copy n bytes. + * Return dst. + */ +wchar_t * +wcsncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n) +{ + if (n != 0) { + wchar_t *d = dst; + const wchar_t *s = src; + + do { + if ((*d++ = *s++) == L'\0') { + /* NUL pad the remaining n-1 bytes */ + while (--n != 0) + *d++ = L'\0'; + break; + } + } while (--n != 0); + } + return (dst); +} diff --git a/src/lib/libc/string/wcspbrk.c b/src/lib/libc/string/wcspbrk.c new file mode 100644 index 0000000..5502440 --- /dev/null +++ b/src/lib/libc/string/wcspbrk.c @@ -0,0 +1,60 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcspbrk.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcspbrk.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include + +wchar_t * +wcspbrk(s, set) + const wchar_t *s; + const wchar_t *set; +{ + const wchar_t *p; + const wchar_t *q; + + p = s; + while (*p) { + q = set; + while (*q) { + if (*p == *q) { + /* LINTED interface specification */ + return (wchar_t *)p; + } + q++; + } + p++; + } + return NULL; +} diff --git a/src/lib/libc/string/wcsrchr.c b/src/lib/libc/string/wcsrchr.c new file mode 100644 index 0000000..093dd08 --- /dev/null +++ b/src/lib/libc/string/wcsrchr.c @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/wcsrchr.c,v 1.7 2002/10/23 10:52:04 tjr Exp $"); + +#include + +wchar_t * +wcsrchr(const wchar_t *s, wchar_t c) +{ + const wchar_t *last; + + last = NULL; + for (;;) { + if (*s == c) + last = s; + if (*s == L'\0') + break; + s++; + } + + return ((wchar_t *)last); +} diff --git a/src/lib/libc/string/wcsspn.c b/src/lib/libc/string/wcsspn.c new file mode 100644 index 0000000..d4101c7 --- /dev/null +++ b/src/lib/libc/string/wcsspn.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wcsspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wcsspn.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcsspn.c,v 1.7 2002/09/21 00:29:23 tjr Exp $"); + +#include + +size_t +wcsspn(s, set) + const wchar_t *s; + const wchar_t *set; +{ + const wchar_t *p; + const wchar_t *q; + + p = s; + while (*p) { + q = set; + while (*q) { + if (*p == *q) + break; + q++; + } + if (!*q) + goto done; + p++; + } + +done: + return (p - s); +} diff --git a/src/lib/libc/string/wcsstr.c b/src/lib/libc/string/wcsstr.c new file mode 100644 index 0000000..0533e59 --- /dev/null +++ b/src/lib/libc/string/wcsstr.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 0 +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#endif +#include +__FBSDID("$FreeBSD: src/lib/libc/string/wcsstr.c,v 1.8 2002/10/24 02:53:45 tjr Exp $"); + +#include + +/* + * Find the first occurrence of find in s. + */ +wchar_t * +wcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find) +{ + wchar_t c, sc; + size_t len; + + if ((c = *find++) != 0) { + len = wcslen(find); + do { + do { + if ((sc = *s++) == L'\0') + return (NULL); + } while (sc != c); + } while (wcsncmp(s, find, len) != 0); + s--; + } + return ((wchar_t *)s); +} diff --git a/src/lib/libc/string/wcstok.c b/src/lib/libc/string/wcstok.c new file mode 100644 index 0000000..5781adb --- /dev/null +++ b/src/lib/libc/string/wcstok.c @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 1988, 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 + * notices, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notices, 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 Softweyr LLC, 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/wcstok.c,v 1.2 2003/03/12 06:41:49 tjr Exp $"); + +#include + +wchar_t * +wcstok(wchar_t * __restrict s, const wchar_t * __restrict delim, + wchar_t ** __restrict last) +{ + const wchar_t *spanp; + wchar_t *tok; + wchar_t c, sc; + + if (s == NULL && (s = *last) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += wcsspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = delim; (sc = *spanp++) != L'\0';) { + if (c == sc) + goto cont; + } + + if (c == L'\0') { /* no non-delimiter characters */ + *last = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == L'\0') + s = NULL; + else + s[-1] = L'\0'; + *last = s; + return (tok); + } + } while (sc != L'\0'); + } + /* NOTREACHED */ +} diff --git a/src/lib/libc/string/wcswidth.c b/src/lib/libc/string/wcswidth.c new file mode 100644 index 0000000..98a095d --- /dev/null +++ b/src/lib/libc/string/wcswidth.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * 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. + */ + +#include +__FBSDID("$FreeBSD: src/lib/libc/string/wcswidth.c,v 1.6 2002/08/20 02:06:28 ache Exp $"); + +#include + +int +wcswidth(const wchar_t *pwcs, size_t n) +{ + wchar_t wc; + int len, l; + + len = 0; + while (n-- > 0 && (wc = *pwcs++) != L'\0') { + if ((l = wcwidth(wc)) < 0) + return (-1); + len += l; + } + return (len); +} + diff --git a/src/lib/libc/string/wcsxfrm.c b/src/lib/libc/string/wcsxfrm.c new file mode 100644 index 0000000..7aea3d1 --- /dev/null +++ b/src/lib/libc/string/wcsxfrm.c @@ -0,0 +1,116 @@ +/*- + * Copyright (c) 1995 Alex Tatmanjants + * at Electronni Visti IA, Kiev, Ukraine. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#include +#if 0 +__FBSDID("FreeBSD: src/lib/libc/string/strxfrm.c,v 1.15 2002/09/06 11:24:06 tjr Exp "); +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wcsxfrm.c,v 1.3 2004/04/07 09:47:56 tjr Exp $"); + +#include +#include +#include +#include "collate.h" + +static char *__mbsdup(const wchar_t *); + +/* + * Placeholder wcsxfrm() implementation. See wcscoll.c for a description of + * the logic used. + */ +size_t +wcsxfrm(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len) +{ + int prim, sec, l; + size_t slen; + char *mbsrc, *s, *ss; + + if (*src == L'\0') { + if (len != 0) + *dest = L'\0'; + return (0); + } + + if (__collate_load_error || MB_CUR_MAX > 1) { + slen = wcslen(src); + if (len > 0) { + if (slen < len) + wcscpy(dest, src); + else { + wcsncpy(dest, src, len - 1); + dest[len - 1] = L'\0'; + } + } + return (slen); + } + + mbsrc = __mbsdup(src); + slen = 0; + prim = sec = 0; + ss = s = __collate_substitute(mbsrc); + while (*s != '\0') { + while (*s != '\0' && prim == 0) { + __collate_lookup(s, &l, &prim, &sec); + s += l; + } + if (prim != 0) { + if (len > 1) { + *dest++ = (wchar_t)prim; + len--; + } + slen++; + prim = 0; + } + } + free(ss); + free(mbsrc); + if (len != 0) + *dest = L'\0'; + + return (slen); +} + +static char * +__mbsdup(const wchar_t *ws) +{ + static const mbstate_t initial; + mbstate_t st; + const wchar_t *wcp; + size_t len; + char *mbs; + + wcp = ws; + st = initial; + if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1) + return (NULL); + if ((mbs = malloc(len + 1)) == NULL) + return (NULL); + st = initial; + wcsrtombs(mbs, &ws, len + 1, &st); + + return (mbs); +} diff --git a/src/lib/libc/string/wmemchr.c b/src/lib/libc/string/wmemchr.c new file mode 100644 index 0000000..0b09f94 --- /dev/null +++ b/src/lib/libc/string/wmemchr.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wmemchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wmemchr.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include + +wchar_t * +wmemchr(s, c, n) + const wchar_t *s; + wchar_t c; + size_t n; +{ + size_t i; + + for (i = 0; i < n; i++) { + if (*s == c) { + /* LINTED const castaway */ + return (wchar_t *)s; + } + s++; + } + return NULL; +} diff --git a/src/lib/libc/string/wmemcmp.c b/src/lib/libc/string/wmemcmp.c new file mode 100644 index 0000000..3014041 --- /dev/null +++ b/src/lib/libc/string/wmemcmp.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wmemcmp.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wmemcmp.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include + +int +wmemcmp(s1, s2, n) + const wchar_t *s1; + const wchar_t *s2; + size_t n; +{ + size_t i; + + for (i = 0; i < n; i++) { + if (*s1 != *s2) { + /* wchar might be unsigned */ + return *s1 > *s2 ? 1 : -1; + } + s1++; + s2++; + } + return 0; +} diff --git a/src/lib/libc/string/wmemcpy.c b/src/lib/libc/string/wmemcpy.c new file mode 100644 index 0000000..4391309 --- /dev/null +++ b/src/lib/libc/string/wmemcpy.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wmemcpy.c,v 1.7 2002/09/21 00:29:23 tjr Exp $"); + +#include +#include + +wchar_t * +wmemcpy(d, s, n) + wchar_t * __restrict d; + const wchar_t * __restrict s; + size_t n; +{ + + return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t)); +} diff --git a/src/lib/libc/string/wmemmove.c b/src/lib/libc/string/wmemmove.c new file mode 100644 index 0000000..dd2036c --- /dev/null +++ b/src/lib/libc/string/wmemmove.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wmemmove.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wmemmove.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include +#include + +wchar_t * +wmemmove(d, s, n) + wchar_t *d; + const wchar_t *s; + size_t n; +{ + + return (wchar_t *)memmove(d, s, n * sizeof(wchar_t)); +} diff --git a/src/lib/libc/string/wmemset.c b/src/lib/libc/string/wmemset.c new file mode 100644 index 0000000..df91537 --- /dev/null +++ b/src/lib/libc/string/wmemset.c @@ -0,0 +1,54 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#if 0 +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: wmemset.c,v 1.1 2000/12/23 23:14:37 itojun Exp $"); +#endif /* LIBC_SCCS and not lint */ +#endif +__FBSDID("$FreeBSD: src/lib/libc/string/wmemset.c,v 1.6 2002/09/21 00:29:23 tjr Exp $"); + +#include + +wchar_t * +wmemset(s, c, n) + wchar_t *s; + wchar_t c; + size_t n; +{ + size_t i; + wchar_t *p; + + p = (wchar_t *)s; + for (i = 0; i < n; i++) { + *p = c; + p++; + } + return s; +} diff --git a/src/lib/libc/sys/Makefile b/src/lib/libc/sys/Makefile new file mode 100644 index 0000000..349709e --- /dev/null +++ b/src/lib/libc/sys/Makefile @@ -0,0 +1,34 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +#Objects +OBJS = mpi.o startsde.o mmap.o error.o getuptime.o gettime.o getdrives.o setuid.o setgid.o getuid.o getgid.o exec.o getpid.o fork.o pidstatus.o getpage.o sched.o + +#Output +OUTPUT = sys.so + +$(OUTPUT): $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) ${CFLAGS} -Wall -nostdinc -O -I../include -c -o $@ $< + +.cc.s: + $(CXX) ${CFLAGS} -Wall -nostdinc -O -I../include -S -o $@ $< + +.c.o: + $(CC) ${CFLAGS} -Wall -nostdinc -O -I../include -I../../../include -c $< + +.c.s: + $(CC) ${CFLAGS} -Wall -nostdinc -O -I../include -S -o $@ $< + +.S.o: + $(CC) ${CFLAGS} -Wall -nostdinc -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libc/sys/error.c b/src/lib/libc/sys/error.c new file mode 100644 index 0000000..d4489c8 --- /dev/null +++ b/src/lib/libc/sys/error.c @@ -0,0 +1,3 @@ +int * __error(void) { + return(0x0); + } diff --git a/src/lib/libc/sys/exec.c b/src/lib/libc/sys/exec.c new file mode 100644 index 0000000..5e1e933 --- /dev/null +++ b/src/lib/libc/sys/exec.c @@ -0,0 +1,31 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +int exec(char *file,int argc,char **argv) { + int status = 0x1; + asm( + "int %0 \n" + : : "i" (0x80),"a" (3),"b" (file),"c" (argc),"d" (argv) + ); + return(status); + } diff --git a/src/lib/libc/sys/fork.c b/src/lib/libc/sys/fork.c new file mode 100644 index 0000000..5b1b6c5 --- /dev/null +++ b/src/lib/libc/sys/fork.c @@ -0,0 +1,47 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include +#include + +pid_t fork() { + pid_t pid = 0x0; + asm( + "pushl %%eax\n" + "pushl %%ecx\n" + "movl $4,%%eax\n" + "push %%ss\n" + "movl %%esp,%%ecx\n" + "sub $4,%%ecx\n" + "pushl %%ecx\n" + "int $0x80 \n" + "popl %%esp\n" + "pop %%ax\n" + "popl %%ecx\n" + "popl %%eax\n" + : + : "b" (&pid) + ); + return(pid); + } + diff --git a/src/lib/libc/sys/getdrives.c b/src/lib/libc/sys/getdrives.c new file mode 100644 index 0000000..76ed8e4 --- /dev/null +++ b/src/lib/libc/sys/getdrives.c @@ -0,0 +1,11 @@ +#include + + +void *getDrives() { + uInt32 ptr = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (45),"b" (&ptr) + ); + return((void *)ptr); + } \ No newline at end of file diff --git a/src/lib/libc/sys/getgid.c b/src/lib/libc/sys/getgid.c new file mode 100644 index 0000000..c37c63c --- /dev/null +++ b/src/lib/libc/sys/getgid.c @@ -0,0 +1,33 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int getgid(void) { + int gid = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (32),"b" (&gid) + ); + return(gid); + } \ No newline at end of file diff --git a/src/lib/libc/sys/getpage.c b/src/lib/libc/sys/getpage.c new file mode 100644 index 0000000..aa70388 --- /dev/null +++ b/src/lib/libc/sys/getpage.c @@ -0,0 +1,33 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +void *getPage(int count) { + uInt32 pageAddr = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (7),"b" (&pageAddr),"c" (count) + ); + return((void *)pageAddr); + } diff --git a/src/lib/libc/sys/getpid.c b/src/lib/libc/sys/getpid.c new file mode 100644 index 0000000..0bbfbbd --- /dev/null +++ b/src/lib/libc/sys/getpid.c @@ -0,0 +1,34 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int getpid(void) { + int pid = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (1),"b" (&pid) + ); + return(pid); + } + diff --git a/src/lib/libc/sys/gettime.c b/src/lib/libc/sys/gettime.c new file mode 100644 index 0000000..8a753bc --- /dev/null +++ b/src/lib/libc/sys/gettime.c @@ -0,0 +1,34 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int gettime(void) { + int time = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (47),"b" (&time) + ); + return(time); + } + diff --git a/src/lib/libc/sys/getuid.c b/src/lib/libc/sys/getuid.c new file mode 100644 index 0000000..6153b64 --- /dev/null +++ b/src/lib/libc/sys/getuid.c @@ -0,0 +1,33 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int getuid(void) { + int uid = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (31),"b" (&uid) + ); + return(uid); + } \ No newline at end of file diff --git a/src/lib/libc/sys/getuptime.c b/src/lib/libc/sys/getuptime.c new file mode 100644 index 0000000..bf536cf --- /dev/null +++ b/src/lib/libc/sys/getuptime.c @@ -0,0 +1,34 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int getuptime(void) { + int uptime = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (46),"b" (&uptime) + ); + return(uptime); + } + diff --git a/src/lib/libc/sys/mmap.c b/src/lib/libc/sys/mmap.c new file mode 100644 index 0000000..a3fb470 --- /dev/null +++ b/src/lib/libc/sys/mmap.c @@ -0,0 +1,43 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + + +#include + +void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { +/* + asm( + "pushl %%eax \n" + "movl $4,%%eax\n" + "int $0x69 \n" + "popl %%eax \n" + ); +*/ + + return(0x0); + } + +/*** + END + ***/ + diff --git a/src/lib/libc/sys/mpi.c b/src/lib/libc/sys/mpi.c new file mode 100644 index 0000000..9371ad0 --- /dev/null +++ b/src/lib/libc/sys/mpi.c @@ -0,0 +1,89 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +int mpiCreateMbox(char *name) { + int status = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (50),"b" (&status),"c" (name) + ); + + return(status); + } + +int mpiDestroyMbox(char *name) { + int status = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (51),"b" (&status),"c" (name) + ); + + return(status); + } + +int mpiPostMessage(char *name,uInt32 type,void *data) { + asm( + "int %0\n" + : : "i" (0x80),"a" (52),"b" (name),"c" (&type),"d" (data) + ); + return(type); + } + +int mpiFetchMessage(char *name,mpiMessage_t *msg) { + int status = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (53),"b" (name),"c" (msg),"d" (&status) + ); + return(status); + } + +int mpiSpam(uInt32 type,void *data) { + int status = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (54),"b" (type),"c" (data),"d" (&status) + ); + return(status); + } + +/*** + $Log$ + Revision 1.2 2004/05/26 15:39:22 reddawg + mpi: brought mpiDestroyMbox(char *name) in to the userland + + Revision 1.1 2004/05/25 15:43:27 reddawg + Added Userland MPI access + + END + ***/ + diff --git a/src/lib/libc/sys/pidstatus.c b/src/lib/libc/sys/pidstatus.c new file mode 100644 index 0000000..acbb836 --- /dev/null +++ b/src/lib/libc/sys/pidstatus.c @@ -0,0 +1,33 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int pidStatus(int pid) { + int status = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (6),"b" (pid),"c" (&status) + ); + return(status); + } diff --git a/src/lib/libc/sys/sched.c b/src/lib/libc/sys/sched.c new file mode 100644 index 0000000..7e53359 --- /dev/null +++ b/src/lib/libc/sys/sched.c @@ -0,0 +1,13 @@ + +#include + +int sched_yield(void) +{ + int return_val = 0; + asm( + "int %0\n" + : : "i" (0x80),"a" (11) + ); + return return_val; +} + diff --git a/src/lib/libc/sys/setgid.c b/src/lib/libc/sys/setgid.c new file mode 100644 index 0000000..6014b59 --- /dev/null +++ b/src/lib/libc/sys/setgid.c @@ -0,0 +1,33 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int setgid(int gid) { + int status = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (34),"b" (gid),"c" (&status) + ); + return(status); + } \ No newline at end of file diff --git a/src/lib/libc/sys/setuid.c b/src/lib/libc/sys/setuid.c new file mode 100644 index 0000000..1fe8c07 --- /dev/null +++ b/src/lib/libc/sys/setuid.c @@ -0,0 +1,33 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int setuid(int uid) { + int status = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (33),"b" (uid),"c" (&status) + ); + return(status); + } \ No newline at end of file diff --git a/src/lib/libc/sys/startsde.c b/src/lib/libc/sys/startsde.c new file mode 100644 index 0000000..dc922e9 --- /dev/null +++ b/src/lib/libc/sys/startsde.c @@ -0,0 +1,34 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#include + +int startSDE(void) { + int time = 0x0; + asm( + "int %0\n" + : : "i" (0x80),"a" (48) + ); + return(time); + } + diff --git a/src/lib/libcpp/Makefile b/src/lib/libcpp/Makefile new file mode 100644 index 0000000..186fcbf --- /dev/null +++ b/src/lib/libcpp/Makefile @@ -0,0 +1,32 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc +# Objects +OBJS = libcpp.o + +#Include + +INCLUDE = -I./include -I../libc/include + +all: $(OBJS) + +# Compile Types +.cpp.o: + $(CXX) ${CFLAGS} -Wall -DNOBOOL -fno-exceptions -g -c $(INCLUDE) -o $@ $< +.cc.o: + $(CXX) ${CFLAGS} -Wall -DNOBOOL -fno-builtin -fno-rtti -fno-exceptions -fomit-frame-pointer -O $(INCLUDE) -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -Wall -fomit-frame-pointer -O $(INCLUDE) -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O $(INCLUDE) -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O $(INCLUDE) -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/lib/libcpp/include/libcpp.h b/src/lib/libcpp/include/libcpp.h new file mode 100644 index 0000000..78f02c8 --- /dev/null +++ b/src/lib/libcpp/include/libcpp.h @@ -0,0 +1,9 @@ +#ifndef __LIBCPP_H +#define __LIBCPP_H + +void * operator new(unsigned size); +void operator delete(void * ptr); +void * operator new[](unsigned size); +void operator delete[](void * ptr); + +#endif diff --git a/src/lib/libcpp/libcpp.cc b/src/lib/libcpp/libcpp.cc new file mode 100644 index 0000000..836cde0 --- /dev/null +++ b/src/lib/libcpp/libcpp.cc @@ -0,0 +1,37 @@ +extern "C" +{ +#include +/* Don't Touch Mark */ +void __pure_virtual() { while(1); } +void __cxa_pure_virtual() { while(1); } +} + +#include + +/* Don't Touch Mark */ +void * operator new[](unsigned size) +{ + return malloc(size); +} + +void operator delete[](void * ptr) +{ + free(ptr); + + return; +} + +void * operator new(unsigned size) +{ + return malloc(size); +} + +void operator delete(void * ptr) +{ + free(ptr); + + return; +} + +/* End Don't Touch */ + diff --git a/src/lib/libstdc++/Makefile b/src/lib/libstdc++/Makefile new file mode 100644 index 0000000..d9e6ce0 --- /dev/null +++ b/src/lib/libstdc++/Makefile @@ -0,0 +1,42 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Objects +OBJS = sinst.o + +#Sub Sections +SUBS = + +#Output +OUTPUT = libstdc++.so + +#Includes +INCLUDES = -I./include -I. -I../libio -I../../include + +lib.so: $(OBJS) +# $(LD) $(LDFLAGS) -o $(OUTPUT) $(OBJS) ./stdio/*.o ./sys/*.o ./string/*.o ./stdlib/*.o + $(CC) -nostdlib -shared -Wl,-soname,libc.so -o $(OUTPUT) $(OBJS) $(SUBS) + +# Compile the source files +.cc.o: + $(CXX) -Wall -nostdinc -DNOBOOL -DTMP_LIB -O $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -nostdinc -O -I./include -S -o $@ $< + +.c.o: + $(CC) -Wall -nostdinc -O -I./include -c $< + +.c.s: + $(CC) -Wall -nostdinc -O -I./include -S -o $@ $< + +.S.o: + $(CC) -Wall -nostdinc -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) diff --git a/src/lib/libstdc++/sinst.cc b/src/lib/libstdc++/sinst.cc new file mode 100644 index 0000000..809c34b --- /dev/null +++ b/src/lib/libstdc++/sinst.cc @@ -0,0 +1,76 @@ +#include + +extern "C" { + void * __dynamic_cast(void *a,void *b,void *c,void *d) { + return(0x0); + } + void * __rtti_user(void *a,void *b) { + return(0x0); + } + void * __rtti_class(void *a,void *b,void *c,void *d) { + return(0x0); + } + void * __rtti_si(void *a,void *b,void *c) { + return(0x0); + } + void __eprintf(void *a,void *b,void *c,void *d) { + return; + } + void cerr() { + return; + } +} + + +typedef char c; + +template class string_char_traits ; + +ostream& endl(ostream& outs) { + return flush(outs.put('\n')); + } + +ostream& ostream::flush() +{ +// if (_strbuf->sync()) + // set(ios::badbit); + return *this; +} + + + +ostream& flush(ostream& outs) { + return outs.flush(); + } + +ostream& ostream::operator<<(const char *s) { + return(*this); + } + +ostream& ostream::operator<<(char c) { + return(*this); + } + +ostream& ostream::operator<<(int n) { + return(*this); + } + +ostream& ostream::operator<<(unsigned int n) { + return(*this); + } + +ostream& ostream::operator<<(long n) { + return(*this); + } + +ostream& ostream::operator<<(unsigned long n) { + return(*this); + } + +ostream& ostream::operator<<(ostream &(*)(ostream &)) { + return(*this); + } + +void * operator new(unsigned int size,void * ptr) { + return(ptr); + } diff --git a/src/lib/libstdc++/std/straights.h b/src/lib/libstdc++/std/straights.h new file mode 100644 index 0000000..2b81dbd --- /dev/null +++ b/src/lib/libstdc++/std/straights.h @@ -0,0 +1,84 @@ +typedef char charT; +typedef int size_t; + +extern "C++" { + +template struct string_char_traits { + typedef charT char_type; + static char_type eos () { return char_type(); } // the null character + static void assign (char_type& c1, const char_type& c2) { c1 = c2; } + static bool ne (const char_type& c1, const char_type& c2) { return !(c1 == c2); } + static bool lt (const char_type& c1, const char_type& c2) { return (c1 < c2); } + static int compare (const char_type* s1, const char_type* s2, size_t n) { + size_t i; + for (i = 0; i < n; ++i) + if (ne (s1[i], s2[i])) + return lt (s1[i], s2[i]) ? -1 : 1; + return 0; + } + static size_t length (const char_type* s) { + size_t l = 0; + while (ne (*s++, eos ())) + ++l; + return l; + } + static char_type* copy (char_type* s1, const char_type* s2, size_t n) { + for (; n--; ) + assign (s1[n], s2[n]); + return s1; + } + static char_type* move (char_type* s1, const char_type* s2, size_t n) { + char_type a[n]; + size_t i; + for (i = 0; i < n; ++i) + assign (a[i], s2[i]); + for (i = 0; i < n; ++i) + assign (s1[i], a[i]); + return s1; + } + + }; + +class streambuf;class ios;class istream; class ostream; + +typedef ios& (*__manip)(ios&); +typedef istream& (*__imanip)(istream&); +typedef ostream& (*__omanip)(ostream&); + +extern ostream& flush(ostream& outs); + +struct _ios_fields { // The data members of an ios. + void *test; + }; + + +class ios : public _ios_fields { + public: + ios& test(void) { return *this; } + }; + +class ostream : virtual public ios { + public: + ostream() { } + ostream& put(char c) { return *this; } + ostream& flush(); + + + ostream& operator<<(char c); + ostream& operator<<(const char *s); + ostream& operator<<(int n); + ostream& operator<<(unsigned int n); + ostream& operator<<(unsigned long n); + ostream& operator<<(long n); + + ostream& operator<<(ostream &(*)(ostream &)); + + }; + +class basic_string { + public: + void rep(); + }; + + } + diff --git a/src/lib/objgfx40/1.DPF b/src/lib/objgfx40/1.DPF new file mode 100644 index 0000000..a02b207 --- /dev/null +++ b/src/lib/objgfx40/1.DPF Binary files differ diff --git a/src/lib/objgfx40/6X6.DPF b/src/lib/objgfx40/6X6.DPF new file mode 100644 index 0000000..bf94b27 --- /dev/null +++ b/src/lib/objgfx40/6X6.DPF Binary files differ diff --git a/src/lib/objgfx40/BLOCK.DPF b/src/lib/objgfx40/BLOCK.DPF new file mode 100644 index 0000000..12f39f7 --- /dev/null +++ b/src/lib/objgfx40/BLOCK.DPF Binary files differ diff --git a/src/lib/objgfx40/BOLD.DPF b/src/lib/objgfx40/BOLD.DPF new file mode 100644 index 0000000..20800b5 --- /dev/null +++ b/src/lib/objgfx40/BOLD.DPF Binary files differ diff --git a/src/lib/objgfx40/Makefile b/src/lib/objgfx40/Makefile new file mode 100644 index 0000000..45f4b2e --- /dev/null +++ b/src/lib/objgfx40/Makefile @@ -0,0 +1,40 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +include ../../Makefile.inc +include ../Makefile.inc + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = objgfx40.o ogFont.o ogSprite.o ogBlit.o ogPixCon.o ogPixelFmt.o + +#Include +INCLUDE = -I./ -I../../lib/libc/include -I../../lib/libcpp/include + +#Output +OUTPUT = objgfx40.so + +$(OUTPUT): $(OBJS) + $(CC) -fno-builtin -nostdlib -shared -Wl,-soname,$(OUTPUT) -o $(OUTPUT) $(OBJS) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -g -nostdlib -fno-builtin -fno-inline -fno-exceptions -DNOBOOL $(INCLUDE) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -nostdlib -fomit-frame-pointer -O -nobuilting -I../../lib/libc/include -I./include -S -o $@ $< + +.c.o: + $(CC) -Wall -O -I../../lib/libc/include -c -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O -I../../lib/libc/include -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(BINARY) $(OUTPUT) *.core diff --git a/src/lib/objgfx40/OLDENG.DPF b/src/lib/objgfx40/OLDENG.DPF new file mode 100644 index 0000000..e542aca --- /dev/null +++ b/src/lib/objgfx40/OLDENG.DPF Binary files differ diff --git a/src/lib/objgfx40/PACMAN.DPF b/src/lib/objgfx40/PACMAN.DPF new file mode 100644 index 0000000..4db8522 --- /dev/null +++ b/src/lib/objgfx40/PACMAN.DPF Binary files differ diff --git a/src/lib/objgfx40/ROM8X8.DPF b/src/lib/objgfx40/ROM8X8.DPF new file mode 100644 index 0000000..b65b08d --- /dev/null +++ b/src/lib/objgfx40/ROM8X8.DPF Binary files differ diff --git a/src/lib/objgfx40/ROMAN1.DPF b/src/lib/objgfx40/ROMAN1.DPF new file mode 100755 index 0000000..19dc135 --- /dev/null +++ b/src/lib/objgfx40/ROMAN1.DPF Binary files differ diff --git a/src/lib/objgfx40/SCRIPT.DPF b/src/lib/objgfx40/SCRIPT.DPF new file mode 100755 index 0000000..8adf710 --- /dev/null +++ b/src/lib/objgfx40/SCRIPT.DPF Binary files differ diff --git a/src/lib/objgfx40/include/ogDisplay_VESA.h b/src/lib/objgfx40/include/ogDisplay_VESA.h new file mode 100644 index 0000000..8bd61dc --- /dev/null +++ b/src/lib/objgfx40/include/ogDisplay_VESA.h @@ -0,0 +1,100 @@ +#ifndef OGDISPLAY_VESA_H +#define OGDISPLAY_VESA_H + +#include "objgfx40.h" + +struct ogModeInfo { + uInt16 modeAttributes __attribute__((packed)); + uInt8 windowAFlags __attribute__((packed)); + uInt8 windowBFlags __attribute__((packed)); + uInt16 granularity __attribute__((packed)); + uInt16 windowSize __attribute__((packed)); + uInt16 windowASeg __attribute__((packed)); + uInt16 windowBSeg __attribute__((packed)); + void* bankSwitch __attribute__((packed)); + uInt16 bytesPerLine __attribute__((packed)); + uInt16 xRes __attribute__((packed)); + uInt16 yRes __attribute__((packed)); + uInt8 charWidth __attribute__((packed)); + uInt8 charHeight __attribute__((packed)); + uInt8 numBitPlanes __attribute__((packed)); + uInt8 bitsPerPixel __attribute__((packed)); + uInt8 numberOfBanks __attribute__((packed)); + uInt8 memoryModel __attribute__((packed)); + uInt8 bankSize __attribute__((packed)); + uInt8 numOfImagePages __attribute__((packed)); + uInt8 reserved __attribute__((packed)); + // Direct colour fields (required for Direct/6 and YUV/7 memory models + uInt8 redMaskSize __attribute__((packed)); + uInt8 redFieldPosition __attribute__((packed)); + uInt8 greenMaskSize __attribute__((packed)); + uInt8 greenFieldPosition __attribute__((packed)); + uInt8 blueMaskSize __attribute__((packed)); + uInt8 blueFieldPosition __attribute__((packed)); + uInt8 alphaMaskSize __attribute__((packed)); + uInt8 alphaFieldPosition __attribute__((packed)); + uInt8 directColourMode __attribute__((packed)); + // VESA 2.0 specific fields + uInt32 physBasePtr __attribute__((packed)); + void* offScreenMemOffset __attribute__((packed)); + uInt16 offScreenMemSize __attribute__((packed)); + uInt8 paddington[461] __attribute__((packed)); +}; + +struct ogVESAInfo { + char VBESignature[4] __attribute__((packed)); + uInt8 minVersion __attribute__((packed)); + uInt8 majVersion __attribute__((packed)); + uInt32 OEMStringPtr __attribute__((packed)); + uInt32 capabilities __attribute__((packed)); + uInt32 videoModePtr __attribute__((packed)); + uInt16 totalMemory __attribute__((packed)); + // VESA 2.0 specific fields + uInt16 OEMSoftwareRev __attribute__((packed)); + uInt32 OEMVendorNamePtr __attribute__((packed)); + uInt32 OEMProductNamePtr __attribute__((packed)); + uInt32 OEMProductRevPtr __attribute__((packed)); + uInt8 paddington[474] __attribute__((packed)); +}; + +class ogDisplay_VESA : public ogSurface { + protected: + void * pages[2]; + uInt32 activePage; + uInt32 visualPage; + uInt16 screenSelector; + ogVESAInfo * VESAInfo; + ogModeInfo * modeInfo; + bool inGraphics; + uInt16 FindMode(uInt32, uInt32, uInt32); + void GetModeInfo(uInt16); + void GetVESAInfo(void); + void SetMode(uInt16); + virtual uInt32 RawGetPixel(uInt32, uInt32); + virtual void RawSetPixel(uInt32, uInt32, uInt32); + virtual void RawSetPixel(uInt32, uInt32, uInt8, uInt8, uInt8, uInt8); + void SetPal(void); + public: + ogDisplay_VESA(void); + virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32); + virtual bool ogAvail(void); + virtual void ogClear(uInt32); + virtual bool ogClone(ogSurface&); + virtual void ogCopyLineTo(uInt32, uInt32, const void *, uInt32); + virtual void ogCopyLineFrom(uInt32, uInt32, void *, uInt32); + virtual void ogCopyPalette(ogSurface&); + virtual bool ogCreate(uInt32, uInt32, ogPixelFmt); + virtual uInt32 ogGetPixel(int32, int32); + virtual void * ogGetPtr(uInt32, uInt32); + virtual void ogHLine(int32, int32, int32, uInt32); + virtual bool ogLoadPalette(const char *); + virtual void ogSetPalette(const ogRGBA8[]); + virtual void ogSetPixel(int32, int32, uInt32); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8, uInt8); + virtual void ogVFlip(void); + virtual void ogVLine(int32, int32, int32, uInt32); + virtual ~ogDisplay_VESA(void); +}; // ogDisplay_VESA + +#endif diff --git a/src/lib/objgfx40/main.cpp b/src/lib/objgfx40/main.cpp new file mode 100644 index 0000000..cfd5158 --- /dev/null +++ b/src/lib/objgfx40/main.cpp @@ -0,0 +1,611 @@ +/********************************************************************** +will add copyright bs later + +$Id$ +**********************************************************************/ + +#include "ogPixCon.h" +#include "objgfx40.h" +#include "ogFont.h" +#include "ogSprite.h" +#include "ogBlit.h" +#ifdef __DJGPP__ +#include "ogDisplay_VESA.h" +#endif +#include +#include +#include +#include + +using namespace std; + +void +testPixCon(void) { + ogSurface * buf1 = new ogSurface(); + ogSurface * buf2 = new ogSurface(); + ogPixCon * pixCon = new ogPixCon(OG_PIXFMT_32BPP, OG_PIXFMT_16BPP); + uInt8 r, g, b; + + buf1->ogCreate(100, 100, OG_PIXFMT_32BPP); + buf2->ogCreate(100, 200, OG_PIXFMT_16BPP); + + buf1->ogSetPixel(0, 0, buf1->ogPack(128, 42, 69)); + buf2->ogSetPixel(0, 0, pixCon->ConvPix(buf1->ogGetPixel(0, 0))); + + buf2->ogUnpack(buf2->ogGetPixel(0, 0), r, g, b); +// cout << "r: " << (uInt32)r << endl; +// cout << "g: " << (uInt32)g << endl; +// cout << "b: " << (uInt32)b << endl; + return; +}; // textPixCon + +void testSetPixel(ogSurface& buf) { + uInt32 xx,yy; + buf.ogClear(buf.ogPack(0,255,0)); + for (yy = 0; yy<=buf.ogGetMaxY(); yy++) + for (xx = 0; xx<=buf.ogGetMaxX(); xx++) + buf.ogSetPixel(xx,yy,xx*yy); + getc(stdin); + return; +} // testSetPixel + +void testRect(ogSurface& buf) { + uInt32 count; + if (buf.ogGetBPP()==8) + for (count=0; count<1000; count++) + buf.ogRect(buf.ogGetMaxX() / 2 - count, buf.ogGetMaxY() / 2 - count, + buf.ogGetMaxX() / 2 + count, buf.ogGetMaxY() / 2 + count, + count); + else + for (count=0; count<1000; count++) + buf.ogRect(buf.ogGetMaxX() / 2 - count, buf.ogGetMaxY() / 2 - count, + buf.ogGetMaxX() / 2 + count, buf.ogGetMaxY() / 2 + count, + buf.ogPack(count,count,count)); + getc(stdin); + return; +} // testRect + +void testLine(ogSurface & buf) { + uInt32 count; + uInt32 colour; + buf.ogClear(buf.ogPack(0, 0, 0)); + for (count = 150; count > 0; count--) { + buf.ogLine(buf.ogGetMaxX() / 2, buf.ogGetMaxY() / 2, + buf.ogGetMaxX(), count*4, buf.ogPack(192, 192, 192)); + } // for count + getc(stdin); + if (buf.ogGetBPP()==8) + for (count=0; count<(buf.ogGetMaxX()+1); count+=2) { + buf.ogLine(count-10,-10,buf.ogGetMaxX()-count+10,buf.ogGetMaxY()+10,count); + } // for + else { + colour = 255; + for (count = 0; count < (buf.ogGetMaxX()+1)/2; count+=4) { + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + buf.ogGetMaxX()/2-count,buf.ogGetMaxY(), + buf.ogPack(colour,colour,colour)); + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + buf.ogGetMaxX()/2+count,buf.ogGetMaxY(), + buf.ogPack(colour,colour,colour)); + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + buf.ogGetMaxX()/2-count,0, + buf.ogPack(0,colour,0)); + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + buf.ogGetMaxX()/2+count,0, + buf.ogPack(0,colour,0)); + + --colour; + } // for + + colour = 255; + for (count = 0; count < (buf.ogGetMaxY()+1)/2; count+=4) { + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + 0, buf.ogGetMaxY()/2-count, + buf.ogPack(colour,0,0)); + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + 0, buf.ogGetMaxY()/2+count, + buf.ogPack(colour,0,0)); + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + buf.ogGetMaxX(), buf.ogGetMaxY()/2-count, + buf.ogPack(0,0,colour)); + buf.ogLine(buf.ogGetMaxX()/2, buf.ogGetMaxY()/2, + buf.ogGetMaxX(), buf.ogGetMaxY()/2+count, + buf.ogPack(0,0,colour)); + --colour; + } // for + } // else + getc(stdin); + return; +} // testLine + +void testClear(ogSurface & buf) { + uInt32 count; + if (buf.ogGetBPP()==8) + for (count=0; count<256; count++) + buf.ogClear(count); + else { + for (count=0; count<256; count+=8) + buf.ogClear(buf.ogPack(count,0,0)); + for (count=0; count<256; count+=8) + buf.ogClear(buf.ogPack(0,count,0)); + for (count=0; count<256; count+=8) + buf.ogClear(buf.ogPack(0,0,count)); + for (count=0; count<256; count+=8) + buf.ogClear(buf.ogPack(count,count,count)); + } // else + getc(stdin); + return; +} // testClear + +void testCircle(ogSurface & buf) { + uInt32 count; + if (buf.ogGetBPP()==8) + for (count=0; count<1000; count++) + buf.ogCircle(buf.ogGetMaxX()/2,buf.ogGetMaxY()/2, count, count); + else + for (count=0; count<1000; count++) + buf.ogCircle(buf.ogGetMaxX()/2,buf.ogGetMaxY()/2,count,buf.ogPack(count,0,count)); + getc(stdin); +} // testCircle + +void testVFlip(ogSurface & buf) { + buf.ogVFlip(); + getc(stdin); + return; +} // testVFlip + +void testHFlip(ogSurface & buf) { + buf.ogHFlip(); + getc(stdin); + return; +} // testHFlip + +void testArc(ogSurface & buf) { + uInt32 radius; + uInt32 mid_x, mid_y; + mid_x = buf.ogGetMaxX()/2; + mid_y = buf.ogGetMaxY()/2; + if (buf.ogGetBPP()==8) { + for (radius = 1; radius <9; radius++) { + buf.ogArc(mid_x, mid_y, radius*10, 0, 90, radius*15); + buf.ogArc(mid_x, mid_y, radius*10, 180,270, 249-(radius-1)*16); + } // for + } else { + for (radius = 1; radius <255; radius++) { + buf.ogArc(mid_x, mid_y, radius, 0, 90, buf.ogPack(radius,radius,0)); + buf.ogArc(mid_x, mid_y, radius, 180,270,buf.ogPack(0,255-radius,255-radius)); + } // for + } // else + getchar(); + return; +} // testArc + +void testCubicBezierCurve(ogSurface & buf) { + buf.ogCubicBezierCurve(100, 100, + 300,50, + 400,120, + 350,300, + 25, buf.ogPack(255,255,255)); + getchar(); + return; +} // testCubicBezierCurve + +void testCurve(ogSurface & buf) { + buf.ogCurve(10,10,100,30,35,160,20,buf.ogPack(255,255,255)); + getchar(); + return; +} // testCurve + +void testSprite(ogSurface & buf) { + uInt32 count; + uInt32 w,h; + ogSprite * sprite = NULL; + sprite = new ogSprite(); + + buf.ogClear(buf.ogPack(0, 0, 0)); + testLine(buf); + if (buf.ogGetBPP()==8) + sprite->Get(buf, + buf.ogGetMaxX()/2-80,buf.ogGetMaxY()/2-80, + buf.ogGetMaxX()/2+80,buf.ogGetMaxY()/2+80); + else + sprite->Get(buf, + buf.ogGetMaxX()/2-150,buf.ogGetMaxY()/2-150, + buf.ogGetMaxX()/2+150,buf.ogGetMaxY()/2+150); + + sprite->Save("test.spr"); + delete sprite; + sprite = new ogSprite(); + sprite->Load("test.spr"); + w = sprite->GetWidth()/2; + h = sprite->GetHeight()/2; + buf.ogClear(buf.ogPack(0, 0, 0)); + sprite->Put(buf,-10000,-10000); // test *really* off the screen + sprite->Put(buf,10000,10000); // test *really* off the screen + + sprite->Put(buf,buf.ogGetMaxX()/2-w,buf.ogGetMaxY()/2-h); + sprite->Put(buf,-w,-h); + sprite->Put(buf,buf.ogGetMaxX()/2-w,-h); + sprite->Put(buf,buf.ogGetMaxX()-w,-h); + sprite->Put(buf,-w,buf.ogGetMaxY()/2-h); + sprite->Put(buf,buf.ogGetMaxX()-w,buf.ogGetMaxY()/2-h); + sprite->Put(buf,-w,buf.ogGetMaxY()-h); + sprite->Put(buf,buf.ogGetMaxX()/2-w,buf.ogGetMaxY()-h); + sprite->Put(buf,buf.ogGetMaxX()-w,buf.ogGetMaxY()-h); + getc(stdin); + for (count = 0; count < 256; count++) { + sprite->Put(buf,random() % (buf.ogGetMaxX()+sprite->GetWidth()) - sprite->GetWidth(), + random() % (buf.ogGetMaxY()+sprite->GetHeight()) - sprite->GetHeight()); + } // for + delete sprite; + getc(stdin); + return; +} // testSprite + +void testBlit(ogSurface & buf) { + int32 xx, yy, count; + ogBlit * blit = NULL; + ogBlit * blit2 = NULL; + + blit = new ogBlit(); + + buf.ogClear(buf.ogPack(0, 0, 0)); + for (xx= 0; xx<= 20; xx++) { + buf.ogLine(128,0,128-xx*6,255,buf.ogPack(255,255,255)); + buf.ogLine(128,0,128+xx*6,255,buf.ogPack(255,255,255)); + buf.ogLine(128,255,128-xx*6,0,buf.ogPack(255,255,255)); + buf.ogLine(128,255,128+xx*6,0,buf.ogPack(255,255,255)); + } // for + + buf.ogFillCircle(128,128,60,buf.ogPack(255,255,255)); + blit->Get(buf,0,0,255,255); + for (yy = 0; yy<=(int32)buf.ogGetMaxY(); yy++) + for (xx = 0; xx<=(int32)buf.ogGetMaxX(); xx++) + buf.ogSetPixel(xx,yy,xx*yy); + blit->Save("test.blt"); + blit2 = new ogBlit(*blit, true); + + delete blit; + blit2->Save("test2.blt"); + blit = new ogBlit(); + blit->Load("test.blt"); + + blit->Put(buf,-10000,-10000); // test *really* off the screen + blit->Put(buf,10000,10000); // test *really* off the screen + + blit->Put(buf,-128,-128); + blit->Put(buf,buf.ogGetMaxX()/2-128,-128); + blit->Put(buf,buf.ogGetMaxX()-128,-128); + blit->Put(buf,-128,buf.ogGetMaxY()/2-128); + blit->Put(buf,buf.ogGetMaxX()/2-128,buf.ogGetMaxY()/2-128); + blit->Put(buf,buf.ogGetMaxX()-128,buf.ogGetMaxY()/2-128); + blit->Put(buf,-128,buf.ogGetMaxY()-128); + blit->Put(buf,buf.ogGetMaxX()/2-128,buf.ogGetMaxY()-128); + blit->Put(buf,buf.ogGetMaxX()-128,buf.ogGetMaxY()-128); + + getc(stdin); + buf.ogClear(buf.ogPack(0, 0, 0)); + for (yy = 0; yy<=(int32)buf.ogGetMaxY(); yy++) + for (xx = 0; xx<=(int32)buf.ogGetMaxX(); xx++) + buf.ogSetPixel(xx,yy,xx*yy); + blit->GetBlitWithMask(buf, + buf.ogGetMaxX()/2-blit->GetWidth(), + buf.ogGetMaxY()/2-blit->GetHeight()); + buf.ogClear(buf.ogPack(0, 0, 0)); + blit->Put(buf,-10000,-10000); // test *really* off the screen + blit->Put(buf,10000,10000); // test *really* off the screen + + blit->Put(buf,-128,-128); + blit->Put(buf,buf.ogGetMaxX()/2-128,-128); + blit->Put(buf,buf.ogGetMaxX()-128,-128); + blit->Put(buf,-128,buf.ogGetMaxY()/2-128); + blit->Put(buf,buf.ogGetMaxX()/2-128,buf.ogGetMaxY()/2-128); + blit->Put(buf,buf.ogGetMaxX()-128,buf.ogGetMaxY()/2-128); + blit->Put(buf,-128,buf.ogGetMaxY()-128); + blit->Put(buf,buf.ogGetMaxX()/2-128,buf.ogGetMaxY()-128); + blit->Put(buf,buf.ogGetMaxX()-128,buf.ogGetMaxY()-128); + + getc(stdin); + for (count = 0; count < 1000; count++) { + blit->Put(buf,random() % (buf.ogGetMaxX()+blit->GetWidth()) - blit->GetWidth(), + random() % (buf.ogGetMaxY()+blit->GetHeight()) - blit->GetHeight()); + } // for + getc(stdin); + for (yy = 0; yy<=(int32)buf.ogGetMaxY(); yy++) + for (xx = 0; xx<=(int32)buf.ogGetMaxX(); xx++) + buf.ogSetPixel(xx,yy,xx*yy); + + blit->GetBlitWithMask(buf,buf.ogGetMaxX()/2,buf.ogGetMaxY()-128); + buf.ogClear(buf.ogPack(128,128,128)); + blit->Put(buf,buf.ogGetMaxX()/2-128,buf.ogGetMaxY()/2-128); + getc(stdin); + delete blit; + delete blit2; + + return; +} // testBlit + +void +testBlit2(ogSurface & buf) { + ogBlit * blit = new ogBlit(); + ogSurface * buf2 = new ogSurface(); + ogSurface * blitsource = new ogSurface(); + uInt32 xx,yy,count,colour; + buf.ogClear(buf.ogPack(0, 0, 0)); + if (!buf2->ogClone(buf)) cout << "Clone failed!!!" << endl; + if (!blitsource->ogClone(buf)) cout << "Clone failed!!" << endl; + + colour = 255; + for (count = 0; count < (buf2->ogGetMaxX()+1)/2; count+=4) { + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + buf2->ogGetMaxX()/2-count,buf2->ogGetMaxY(), + buf2->ogPack(colour,colour,colour)); + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + buf2->ogGetMaxX()/2+count,buf2->ogGetMaxY(), + buf2->ogPack(colour,colour,colour)); + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + buf2->ogGetMaxX()/2-count,0, + buf2->ogPack(0,colour,0)); + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + buf2->ogGetMaxX()/2+count,0, + buf2->ogPack(0,colour,0)); + --colour; + } // for + + colour = 255; + for (count = 0; count < (buf.ogGetMaxY()+1)/2; count+=4) { + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + 0, buf2->ogGetMaxY()/2-count, + buf2->ogPack(colour,0,0)); + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + 0, buf2->ogGetMaxY()/2+count, + buf2->ogPack(colour,0,0)); + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + buf2->ogGetMaxX(), buf2->ogGetMaxY()/2-count, + buf2->ogPack(0,0,colour)); + buf2->ogLine(buf2->ogGetMaxX()/2, buf2->ogGetMaxY()/2, + buf2->ogGetMaxX(), buf2->ogGetMaxY()/2+count, + buf2->ogPack(0,0,colour)); + --colour; + } // for + for (yy = 0; yy<=buf2->ogGetMaxY(); yy++) + for (xx = 0; xx<=buf2->ogGetMaxX(); xx++) + buf2->ogSetPixel(xx,yy, xx*yy); + for (count = 0; count<200; count++) + blitsource->ogFillCircle(random() % blitsource->ogGetMaxX(), random() % blitsource->ogGetMaxY(), + random() % 35+1,blitsource->ogPack(255,255,255)); + + blit->Get(*blitsource,0,0,blitsource->ogGetMaxX(),blitsource->ogGetMaxY()); + blit->Save("bigblit.blt"); + delete blit; + blit = new ogBlit; + blit->Load("bigblit.blt"); + for (count = 0; count<=256; count+=4) { + for (yy = 0; yy<=buf2->ogGetMaxY(); yy++) + for (xx = 0; xx<=buf2->ogGetMaxX(); xx++) + buf2->ogSetPixel(xx,yy,xx*yy*count); + + blit->GetBlitWithMask(*buf2,0,0); + blit->Put(buf,0,0); + } // for + + getc(stdin); + delete blitsource; + delete buf2; + delete blit; + return; +} // testBlit2 + +void +testBlit3(ogSurface & buf) { + int32 count; + ogBlit * blit = NULL; + ogSurface * buf2 = NULL; + buf2 = new ogSurface(); + blit = new ogBlit(); + buf.ogClear(buf.ogPack(0, 0, 0)); + buf.ogFillCircle(buf.ogGetMaxX()/2,buf.ogGetMaxY()/2,14,buf.ogPack(255,255,255)); + blit->Get(buf,buf.ogGetMaxX()/2-20,buf.ogGetMaxY()/2-20, + buf.ogGetMaxX()/2+20,buf.ogGetMaxY()/2+20); + blit->Put(buf,0,0); + for (count=0; count<(int32)buf.ogGetMaxX(); count++) + buf.ogLine(count,0,count,buf.ogGetMaxY(),count); + buf2->ogClone(buf); + blit->GetBlitWithMask(*buf2,10,10); + buf.ogClear(buf.ogPack(63,63,63)); + for (count=-40; count<(int32)buf.ogGetMaxX()+10; count++) { + blit->GetBlitWithMask(*buf2,count,buf2->ogGetMaxY()/2-20); + blit->Put(buf,count,buf.ogGetMaxY()/2-20); + blit->GetBlitWithMask(*buf2,buf2->ogGetMaxX()/2-20,count); + blit->Put(buf,buf.ogGetMaxX()/2-20,count); + } + getc(stdin); + delete blit; + return; +} // testBlit3 + +void +testSaveLoadPal(ogSurface & buf) { + uInt32 count; + testRect(buf); + for (count=0; count<256; count++) + buf.ogSetPalette(count,count,count,count); + if (buf.ogSavePalette("test.pal")==false) cout << "SavePal() failed" << endl; + for (count=0; count<256; count++) + buf.ogSetPalette(count,0,0,0); + if (buf.ogLoadPalette("test.pal")==false) cout << "LoadPal() failed" << endl; + testRect(buf); +} // testSaveLoadPal + +void +testPolygon(ogSurface & buf) { + ogPoint2d points[16]; + uInt32 count; + buf.ogClear(buf.ogPack(0, 0, 0)); + for (count=0; count<16; count++) { + points[count].x = random() % buf.ogGetMaxX(); + points[count].y = random() % buf.ogGetMaxY(); + } // for + buf.ogFillPolygon(16, points, buf.ogPack(random() & 255,random() & 255,random() & 255)); + getc(stdin); + return; +} // testPolygon + +void +testSpline(ogSurface & buf) { + ogPoint2d points[8]; + uInt32 i; + for (i=0; i<8; i++) { + points[i].x = random() % buf.ogGetMaxX(); + points[i].y = random() % buf.ogGetMaxY(); + } // for + buf.ogClear(buf.ogPack(0, 0, 0)); + buf.ogPolygon(8, points, buf.ogPack(22,229,52)); + buf.ogSpline(8, points, 24, buf.ogPack(64,64,255)); + buf.ogBSpline(8, points, 24, buf.ogPack(255,128,128)); + getchar(); + return; +} // testSpline + +void +testFont(ogSurface & buf) { + uInt32 xx, yy; + ogBitFont * font = new ogBitFont(); + font->Load("SCRIPT.DPF", 0); + font->SetFGColor(255, 255, 255, 255); + font->SetBGColor(0, 0, 0, 255); + + font->PutString(buf, 0, 0, "abAByzYZ"); + + for (yy = 0; yyGetHeight(); yy++) { + for (xx = 0; xx<79; xx++) + if ((buf.ogGetPixel(xx, yy) & buf.ogGetAlphaMasker()) == 0) + cout << " "; + else + cout << "*"; + cout << endl; + } + + delete font; + return; +} // testFont + +void +testGouraud(ogSurface & buf) { + uInt8 r, g, b; + ogPoint2d points[4]; + ogRGBA8 colours[4]; + r = g = b = 0; + + points[0].x = buf.ogGetMaxX() - 150; + points[0].y = 0; + points[1].x = buf.ogGetMaxX(); + points[1].y = 0; + points[2].x = buf.ogGetMaxX(); + points[2].y = 150; + points[3].x = buf.ogGetMaxX() - 250; + points[3].y = 250; + colours[0].red = 255; + colours[0].green = 0; + colours[0].blue = 0; + colours[0].alpha = 255; + colours[1].red = 0; + colours[1].green = 255; + colours[1].blue = 128; + colours[1].alpha = 255; + colours[2].red = 128; + colours[2].green = 255; + colours[2].blue = 128; + colours[2].alpha = 255; + colours[3].red = 63; + colours[3].green = 63; + colours[3].blue = 63; + colours[3].alpha = 255; + buf.ogFillGouraudPolygon(4, points, colours); + getc(stdin); + return; +} // testGouraud + +void +testCopyBuf(ogSurface & buf) { + ogSurface * buf2 = new ogSurface(); + ogPixelFmt pixFmt; + buf.ogGetPixFmt(pixFmt); + buf2->ogCreate(400, 400, OG_PIXFMT_32BPP); + buf2->ogClear(buf2->ogPack(255, 128, 255)); + buf.ogCopyBuf(0, 0, *buf2, 0, 0, buf2->ogGetMaxX(), buf2->ogGetMaxY()); + delete buf2; + getc(stdin); + return; +} + +void +testFillRect(ogSurface & buf) { + uInt32 count; + for (count = 100; count > 0; count--) { + buf.ogFillRect(count, count, 0, 0, buf.ogPack(count*2, count*2, count*2)); + } + getc(stdin); + + return; +} // testFillRect() +int main() { + ogSurface* buf = NULL; + cout << "Starting program" << endl; +#ifdef __DJGPP__ + buf = new ogDisplay_VESA(); + buf->ogCreate(800, 600, OG_PIXFMT_32BPP); +#else + buf = new ogSurface(); + if (buf->ogCreate(1024, 768, OG_PIXFMT_16BPP)==false) exit(1); +#endif + srandom(time(NULL)); + +// buf->SetBlending(true); +// buf->SetAlpha(127); + buf->ogSetAntiAliasing(true); + +//cout << "testPixCon()" << endl; +// testPixCon(); + cout << "testFillRect()" << endl; + testFillRect(*buf); + cout << "testCopyBuf()" << endl; + testCopyBuf(*buf); + cout << "testGouraud()" << endl; + testGouraud(*buf); + cout << "testFont()" << endl; + testFont(*buf); + cout << "TestRect()" << endl; + testRect(*buf); + cout << "testCircle()" << endl; + testCircle(*buf); + cout << "TestLine()" << endl; + testLine(*buf); +cout << "TestVFlip()" << endl; + testVFlip(*buf); +cout << "TestHFlip()" << endl; + testHFlip(*buf); +cout << "TestArc()" << endl; + testArc(*buf); +cout << "TestSetPixel()" << endl; + testSetPixel(*buf); +cout << "TestClear()" << endl; + testClear(*buf); +cout << "TestSprite()" << endl; + testSprite(*buf); +cout << "TestBlit()" << endl; + testBlit(*buf); +cout << "TestBlit2()" << endl; + testBlit2(*buf); +// testBlit3(*buf); // special test for 320x200x8bpp +// testSaveLoadPal(*buf); // use an 8bpp mode +cout << "TestPolygon()" << endl; + testPolygon(*buf); +cout << "TestCurve()" << endl; + testCurve(*buf); +cout << "TestSpline()" << endl; + testSpline(*buf); + delete buf; +// buf->SetPixel(0, 0, buf->Pack(0, 0, 0)); + return(0); +} diff --git a/src/lib/objgfx40/objgfx40.cpp b/src/lib/objgfx40/objgfx40.cpp new file mode 100644 index 0000000..e4ba6d2 --- /dev/null +++ b/src/lib/objgfx40/objgfx40.cpp @@ -0,0 +1,4142 @@ +/******************************************************* +$Id$ +*******************************************************/ + +#ifndef __UBIXOS_KERNEL__ +extern "C" { + #include + #include + #include + #include + } +#endif + +#ifdef __UBIXOS_KERNEL__ +extern "C" { + #include + #include + #include + #include + #include + } + +#define abs(a) (((a) < 0) ? -(a) : (a)) +#endif + +#include +#include +#include +#include + +#ifdef __UBIXOS__ +#include +#endif + +const + uInt32 OG_MASKS[32] = { + 0, + 1, + 3, + 7, + 15, + 31, + 63, + 127, + 255, + 511, + 1023, + 2047, + 4095, + 8191, + 16383, + 32767, + 65535, + 131071, + 262143, + 524287, + 1048575, + 2097151, + 4194303, + 8388607, + 16777215, + 33554431, + 67108863, + 134217727, + 268435455, + 536870911, + 1073741823, + 2147483647 + }; // OG_MASKS[] + +const + float INTENSITIES[32] = { + 1.0, // 0 + 0.984250984251, // 1 + 0.968245836552, // 2 + 0.951971638233, // 3 + 0.935414346693, // 4 + 0.938558653544, // 5 + 0.901387818866, // 6 + 0.883883476483, // 7 + 0.866025403784, // 8 + 0.847791247891, // 9 + 0.829156197589, // 10 + 0.810092587301, // 11 + 0.790569415042, // 12 + 0.770551750371, // 13 + 0.75, // 14 + 0.728868986856, // 15 + 0.707106781187, // 16 + 0.684653196881, // 17 + 0.661437827766, // 18 + 0.637377439199, // 19 + 0.612372435696, // 20 + 0.586301969978, // 21 + 0.559016994375, // 22 + 0.53033008589, // 23 + 0.5, // 24 + 0.467707173347, // 25 + 0.433012701892, // 26 + 0.395284707521, // 27 + 0.353553390593, // 28 + 0.306186217848, // 29 + 0.25, // 30 + 0.176776695297 // 31 + }; // INTENSITIES[] + +// #include "../ubixos-home/src/sys/include/ubixos/types.h" + +// #define ROUND(f) (int)((f) + ((f) > 0 ? 0.5 : -0.5)) + +struct ogHLine { + int32 xStart; + int32 xEnd; +}; + +struct ogHLineList { + int32 length; + int32 yStart; + int32 * xLeft; + int32 * xRight; +}; + +struct ogPointListHeader { + int32 length; + ogPoint2d * PointPtr; +}; + +struct ogEdgeState { + ogEdgeState* nextEdge; + int32 x; + int32 startY; + int32 wholePixelXMove; + int32 xDirection; + int32 errorTerm; + int32 errorTermAdjUp; + int32 errorTermAdjDown; + int32 count; + ogRGBA8 colour; + int32 rStepY; + int32 gStepY; + int32 bStepY; + int32 aStepY; + int32 rIncY; + int32 gIncY; + int32 bIncY; + int32 aIncY; +}; + +class ogEdgeTable { + public: + ogEdgeState * globalEdges; + ogEdgeState * activeEdges; + ogEdgeTable(void) { globalEdges = activeEdges = NULL; return; } + void AdvanceAET(void); + void BuildGET(uInt32 numPoints, ogPoint2d * polyPoints); + void BuildGET_G(uInt32 numPoints, ogPoint2d * polyPoints, ogRGBA8 * colours); + void MoveXSortedToAET(int32 yToMove); + void ScanOutAET(ogSurface & destObject, int32 yToScan, uInt32 colour); + void ScanOutAET_G(ogSurface & destObject, int32 yToScan); + void XSortAET(void); + ~ogEdgeTable(void); +}; // ogEdgeState + +void +ogEdgeTable::AdvanceAET(void) { + ogEdgeState * currentEdge; + ogEdgeState ** currentEdgePtr; + + currentEdgePtr = &activeEdges; + currentEdge = activeEdges; + while (currentEdge!=NULL) { + --currentEdge->count; + if (currentEdge->count == 0) { + // this edge is finished, so remove it from the AET + *currentEdgePtr = currentEdge->nextEdge; + // I'm thinking I should dispose currentEdge here!? + } else { + // advance the edge's x coord by minimum move + currentEdge->x += currentEdge->wholePixelXMove; + // determine whether it's time for X to advance one extra + currentEdge->errorTerm += currentEdge->errorTermAdjUp; + if (currentEdge->errorTerm > 0) { + currentEdge->x += currentEdge->xDirection; + currentEdge->errorTerm -= currentEdge->errorTermAdjDown; + } // if + currentEdgePtr = ¤tEdge->nextEdge; + } // else + currentEdge = *currentEdgePtr; + } // while + return; +} // ogEdgeTable::AdvanceAET + +void +ogEdgeTable::BuildGET(uInt32 numPoints, ogPoint2d * polyPoints) { + int32 i, x1, y1, x2, y2, deltaX, deltaY, width, tmp; + ogEdgeState * newEdgePtr; + ogEdgeState * followingEdge; + ogEdgeState ** followingEdgeLink; + + /* + * Creates a GET in the buffer pointed to by NextFreeEdgeStruc from + * the vertex list. Edge endpoints are flipped, if necessary, to + * guarantee all edges go top to bottom. The GET is sorted primarily + * by ascending Y start coordinate, and secondarily by ascending X + * start coordinate within edges with common Y coordinates } + */ + + // Scan through the vertex list and put all non-0-height edges into + // the GET, sorted by increasing Y start coordinate} + + for (i = 0; i < (int32)numPoints; i++) { + // calculate the edge height and width + x1 = polyPoints[i].x; + y1 = polyPoints[i].y; + + if (0 == i) { + // wrap back around to the end of the list + x2 = polyPoints[numPoints-1].x; + y2 = polyPoints[numPoints-1].y; + } else { + x2 = polyPoints[i-1].x; + y2 = polyPoints[i-1].y; + } // else i!=0 + + if (y1 > y2) { + tmp = x1; + x1 = x2; + x2 = tmp; + + tmp = y1; + y1 = y2; + y2 = tmp; + } // if y1>y2 + + // skip if this can't ever be an active edge (has 0 height) + deltaY = y2-y1; + if (deltaY != 0) { + newEdgePtr = new ogEdgeState; + newEdgePtr->xDirection = ((deltaX = x2-x1) > 0) ? 1 : -1; + width = abs(deltaX); + newEdgePtr->x = x1; + newEdgePtr->startY = y1; + newEdgePtr->count = newEdgePtr->errorTermAdjDown = deltaY; + newEdgePtr->errorTerm = (deltaX >= 0) ? 0 : 1-deltaY; + + if (deltaY >= width) { + newEdgePtr->wholePixelXMove = 0; + newEdgePtr->errorTermAdjUp = width; + } else { + newEdgePtr->wholePixelXMove = (width / deltaY) * newEdgePtr->xDirection; + newEdgePtr->errorTermAdjUp = width % deltaY; + } // else + + followingEdgeLink = &globalEdges; + while (true) { + followingEdge = *followingEdgeLink; + if ((followingEdge == NULL) || + (followingEdge->startY > y1) || + ((followingEdge->startY == y1) && + (followingEdge->x>=x1))) { + newEdgePtr->nextEdge = followingEdge; + *followingEdgeLink = newEdgePtr; + break; + } // if + followingEdgeLink = &followingEdge->nextEdge; + } // while + } // if deltaY!=0 + } // for + return; +} // ogEdgeTable::BuildGET + +void +ogEdgeTable::BuildGET_G(uInt32 numPoints, ogPoint2d * polyPoints, ogRGBA8 * colours) { + + int32 i, x1, y1, x2, y2, deltaX, deltaY, width, tmp; + ogEdgeState * newEdgePtr; + ogEdgeState * followingEdge; + ogEdgeState ** followingEdgeLink; + ogRGBA8 c1, c2, cTmp; + + /* + * Creates a GET in the buffer pointed to by NextFreeEdgeStruc from + * the vertex list. Edge endpoints are flipped, if necessary, to + * guarantee all edges go top to bottom. The GET is sorted primarily + * by ascending Y start coordinate, and secondarily by ascending X + * start coordinate within edges with common Y coordinates } + */ + + // Scan through the vertex list and put all non-0-height edges into + // the GET, sorted by increasing Y start coordinate} + + for (i = 0; i < (int32)numPoints; i++) { + // calculate the edge height and width + x1 = polyPoints[i].x; + y1 = polyPoints[i].y; + c1 = colours[i]; + + if (0 == i) { + // wrap back around to the end of the list + x2 = polyPoints[numPoints-1].x; + y2 = polyPoints[numPoints-1].y; + c2 = colours[numPoints-1]; + } else { + x2 = polyPoints[i-1].x; + y2 = polyPoints[i-1].y; + c2 = colours[i-1]; + } // else i!=0 + + if (y1 > y2) { + tmp = x1; + x1 = x2; + x2 = tmp; + + tmp = y1; + y1 = y2; + y2 = tmp; + + cTmp = c1; + c1 = c2; + c2 = cTmp; + } // if y1>y2 + + // skip if this can't ever be an active edge (has 0 height) + deltaY = y2-y1; + if (deltaY != 0) { + newEdgePtr = new ogEdgeState; + newEdgePtr->colour = c1; + newEdgePtr->xDirection = ((deltaX = x2-x1) > 0) ? 1 : -1; + + newEdgePtr -> rStepY = ((c2.red - c1.red +1) << 16) / deltaY; + newEdgePtr -> gStepY = ((c2.green - c1.green +1) << 16) / deltaY; + newEdgePtr -> bStepY = ((c2.blue - c1.blue +1) << 16) / deltaY; + newEdgePtr -> aStepY = ((c2.alpha - c1.alpha +1) << 16) / deltaY; + + newEdgePtr -> rIncY = newEdgePtr -> gIncY = 0; + newEdgePtr -> bIncY = newEdgePtr -> aIncY = 0; + + width = abs(deltaX); + newEdgePtr->x = x1; + newEdgePtr->startY = y1; + newEdgePtr->count = newEdgePtr->errorTermAdjDown = deltaY; + newEdgePtr->errorTerm = (deltaX >= 0) ? 0 : 1-deltaY; + + if (deltaY >= width) { + newEdgePtr->wholePixelXMove = 0; + newEdgePtr->errorTermAdjUp = width; + } else { + newEdgePtr->wholePixelXMove = (width / deltaY) * newEdgePtr->xDirection; + newEdgePtr->errorTermAdjUp = width % deltaY; + } // else + + followingEdgeLink = &globalEdges; + while (true) { + followingEdge = *followingEdgeLink; + if ((followingEdge == NULL) || + (followingEdge->startY > y1) || + ((followingEdge->startY == y1) && + (followingEdge->x >= x1))) { + newEdgePtr->nextEdge = followingEdge; + *followingEdgeLink = newEdgePtr; + break; + } // if + followingEdgeLink = &followingEdge->nextEdge; + } // while + } // if deltaY!=0 + } // for + return; +} // ogEdgeTable::BuildGET_G + +void +ogEdgeTable::MoveXSortedToAET(int32 yToMove) { + ogEdgeState * AETEdge; + ogEdgeState * tempEdge; + ogEdgeState ** AETEdgePtr; + int32 currentX; + + /* The GET is Y sorted. Any edges that start at the desired Y + * coordinate will be first in the GET, so we'll move edges from + * the GET to AET until the first edge left in the GET is no + * longer at the desired Y coordinate. Also, the GET is X sorted + * within each Y cordinate, so each successive edge we add to the + * AET is guaranteed to belong later in the AET than the one just + * added. + */ + AETEdgePtr = &activeEdges; + while ((globalEdges != NULL) && (globalEdges->startY == yToMove)) { + currentX = globalEdges->x; + // link the new edge into the AET so that the AET is still + // sorted by X coordinate + while (true) { + AETEdge = *AETEdgePtr; + if ((AETEdge == NULL) || (AETEdge->x >= currentX)) { + tempEdge = globalEdges->nextEdge; + *AETEdgePtr = globalEdges; + globalEdges->nextEdge = AETEdge; + AETEdgePtr = &globalEdges->nextEdge; + globalEdges = tempEdge; + break; + } else AETEdgePtr = &AETEdge->nextEdge; + } // while true + } // while globalEdges!=NULL and globalEdges->startY==yToMove + return; +} // ogEdgeTable::MoveXSortedToAET + +void +ogEdgeTable::ScanOutAET(ogSurface & destObject, int32 yToScan, uInt32 colour) { + ogEdgeState * currentEdge; + int32 leftX; + + /* Scan through the AET, drawing line segments as each pair of edge + * crossings is encountered. The nearest pixel on or to the right + * of the left edges is drawn, and the nearest pixel to the left + * of but not on right edges is drawn + */ + currentEdge = activeEdges; + + while (currentEdge != NULL) { + leftX = currentEdge->x; + currentEdge = currentEdge->nextEdge; + + if (currentEdge != NULL) { + if (currentEdge->x > leftX) + destObject.ogHLine(leftX, currentEdge->x-1, yToScan, colour); + currentEdge = currentEdge->nextEdge; + } // if currentEdge != NULL + } // while + + return; +} // ogEdgeTable::ScanOutAET + +void +ogEdgeTable::ScanOutAET_G(ogSurface & destObject, int32 yToScan) { + ogEdgeState * currentEdge; + int32 leftX, count; + int32 rStepX, gStepX, bStepX, aStepX; + int32 rIncX, gIncX, bIncX, aIncX; + int32 lR, lG, lB, lA; + int32 rR, rG, rB, rA; + int32 dR, dG, dB, dA; + int32 dist; + + /* Scan through the AET, drawing line segments as each pair of edge + * crossings is encountered. The nearest pixel on or to the right + * of the left edges is drawn, and the nearest pixel to the left + * of but not on right edges is drawn + */ + currentEdge = activeEdges; + + while (currentEdge != NULL) { + leftX = currentEdge->x; + + lR = currentEdge->colour.red; + lG = currentEdge->colour.green; + lB = currentEdge->colour.blue; + lA = currentEdge->colour.alpha; + + lR += currentEdge->rIncY >> 16; + lG += currentEdge->gIncY >> 16; + lB += currentEdge->bIncY >> 16; + lA += currentEdge->aIncY >> 16; + + currentEdge->rIncY += currentEdge->rStepY; + currentEdge->gIncY += currentEdge->gStepY; + currentEdge->bIncY += currentEdge->bStepY; + currentEdge->aIncY += currentEdge->aStepY; + + + currentEdge = currentEdge->nextEdge; + + if (currentEdge != NULL) { + if (leftX != currentEdge->x) { + rR = currentEdge->colour.red; + rG = currentEdge->colour.green; + rB = currentEdge->colour.blue; + rA = currentEdge->colour.alpha; + + rR += currentEdge->rIncY >> 16; + rG += currentEdge->gIncY >> 16; + rB += currentEdge->bIncY >> 16; + rA += currentEdge->aIncY >> 16; + + currentEdge->rIncY += currentEdge->rStepY; + currentEdge->gIncY += currentEdge->gStepY; + currentEdge->bIncY += currentEdge->bStepY; + currentEdge->aIncY += currentEdge->aStepY; + + dR = rR - lR; + dG = rG - lG; + dB = rB - lB; + dA = rA - lA; + + dist = currentEdge->x - leftX; + + rStepX = (dR << 16) / dist; + gStepX = (dG << 16) / dist; + bStepX = (dB << 16) / dist; + aStepX = (dA << 16) / dist; + rIncX = gIncX = bIncX = aIncX = 0; + + for (count = leftX; count < currentEdge->x; count++) { + destObject.ogSetPixel(count, yToScan, + lR + (rIncX >> 16), + lG + (gIncX >> 16), + lB + (bIncX >> 16), + lA + (aIncX >> 16) ); + rIncX += rStepX; + gIncX += gStepX; + bIncX += bStepX; + aIncX += aStepX; + } // for + } + currentEdge = currentEdge->nextEdge; + } // if currentEdge != NULL + } // while + + return; +} // ogEdgeTable::ScanOutAET_G + +void +ogEdgeTable::XSortAET(void) { + ogEdgeState * currentEdge; + ogEdgeState * tempEdge; + ogEdgeState ** currentEdgePtr; + bool swapOccurred; + + if (activeEdges == NULL) return; + + do { + swapOccurred = false; + currentEdgePtr = &activeEdges; + currentEdge = activeEdges; + while (currentEdge->nextEdge != NULL) { + if (currentEdge->x > currentEdge->nextEdge->x) { + // the second edge has a lower x than the first + // swap them in the AET + tempEdge = currentEdge->nextEdge->nextEdge; + *currentEdgePtr = currentEdge->nextEdge; + currentEdge->nextEdge->nextEdge = currentEdge; + currentEdge->nextEdge = tempEdge; + swapOccurred = true; + } // if + currentEdgePtr = &((*currentEdgePtr)->nextEdge); + currentEdge = *currentEdgePtr; + } // while + } while (swapOccurred); + return; +} // ogEdgeTable::XSortAET + +ogEdgeTable::~ogEdgeTable(void) { + ogEdgeState * edge; + ogEdgeState * tmpEdge; + tmpEdge = globalEdges; + // first walk the global edges and delete any non-null nodes + while (tmpEdge != NULL) { + edge = tmpEdge; + tmpEdge = edge->nextEdge; + delete edge; + } // while + tmpEdge = activeEdges; + // next walk the activeEdges and delete any non-null nodes. Note that this should + // always be null + while (tmpEdge != NULL) { + edge = tmpEdge; + tmpEdge = edge->nextEdge; + delete edge; + } // while + return; +} // ogEdgeTable::~ogEdgeTable + +static bool +fileExists(const char *file) +{ +#ifdef __UBIXOS_KERNEL__ + fileDescriptor *f = fopen(file, "rb"); +#else + FILE *f = fopen(file, "rb"); +#endif + + if (!f) + return false; + fclose(f); + return true; +} + +static int32 calculate(float mu, int32 p0, int32 p1, int32 p2, int32 p3); + +// ogSurface constructor +ogSurface::ogSurface(void) { + version = ogVERSION; + + dataState = ogNone; + buffer = NULL; + lineOfs = NULL; + pal = NULL; + attributes = NULL; + xRes = 0; + yRes = 0; + maxX = 0; + maxY = 0; + bSize = 0; + lSize = 0; + BPP = 0; + bytesPerPix = 0; + pixFmtID = 0; + redShifter = 0; + greenShifter = 0; + blueShifter = 0; + alphaShifter = 0; + redFieldPosition = 0; + greenFieldPosition = 0; + blueFieldPosition = 0; + alphaFieldPosition = 0; + alphaMasker = 0; + lastError = ogOK; + return; +} // ogSurface::ogSurface + +void +ogSurface::AARawLine(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2, uInt32 colour) { + /* + * aaRawLine + * + * private method + * + * draws an unclipped anti-aliased line from (x1,y1) to (x2,y2) using colour + * + */ + uInt32 erradj, erracc; + uInt32 erracctmp, intshift, wgt, wgtCompMask; + int32 dx, dy, tmp, xDir, i; + uInt8 r, g, b, a; + uInt32 alphas[32]; + bool oldBlending; + + if (y1 > y2) { + tmp= y1; + y1 = y2; + y2 = tmp; + + tmp= x1; + x1 = x2; + x2 = tmp; + } // if + + dx = (x2-x1); + if (dx >= 0) xDir=1; else { dx = -dx; xDir=-1; } +// dx = abs(dx); + dy = (y2 - y1); + + if (dy == 0) { + ogHLine(x1, x2, y1, colour); + return; + } + + if (dx == 0) { + ogVLine(x1, y1, y2, colour); + return; + } + + ogUnpack(colour, r, g, b, a); + + if (!ogIsBlending()) a = 255; + + for (i = 0; i < 32; i++) { + alphas[i] = static_cast(INTENSITIES[i]*a + 0.5f); + } // for + + oldBlending = ogSetBlending(true); + + RawSetPixel(x1, y1, r, g, b, a); + + // this is incomplete.. diagonal lines don't travel through the + // center of pixels exactly + + do { + + if (dx == dy) { + for (; dy != 0; dy--) { + x1 += xDir; + ++y1; + RawSetPixel(x1, y1, r, g, b, a); + } // for + break; // pop out to the bottom and restore the old blending state + } // if dx==dy + + erracc = 0; + intshift = 32-5; + wgt = 12; + wgtCompMask = 31; + + if (dy > dx) { + /* y-major. Calculate 32-bit fixed point fractional part of a pixel that + * X advances every time Y advances 1 pixel, truncating the result so that + * we won't overrun the endpoint along the X axis + */ +// erradj = ((uInt64) dx << 32) / (uInt64)dy; + __asm__ __volatile__ ( + " xor %%eax, %%eax \n" + " div %1 \n" + " mov %%eax, %2 \n" + : + : "d" (dx), "b" (dy), "m" (erradj) + ); + + while (--dy) { + erracctmp = erracc; + erracc += erradj; + if (erracc <= erracctmp) x1 += xDir; + y1++; // y-major so always advance Y + /* the nbits most significant bits of erracc give us the intensity + * weighting for this pixel, and the complement of the weighting for + * the paired pixel. + */ + wgt = erracc >> intshift; + ogSetPixel(x1, y1, r, g, b, alphas[wgt]); + ogSetPixel(x1+xDir, y1, r, g, b, alphas[wgt ^ wgtCompMask]); + } // while + + } else { + + /* x-major line. Calculate 32-bit fixed-point fractional part of a pixel + * that Y advances each time X advances 1 pixel, truncating the result so + * that we won't overrun the endpoint along the X axis. + */ +// erradj = ((uInt64)dy << 32) / (uInt64)dx; + __asm__ __volatile__ ( + " xor %%eax, %%eax \n" + " div %1 \n" + " mov %%eax, %2 \n" + : + : "d" (dy), "b" (dx), "m" (erradj) + ); + + // draw all pixels other than the first and last + while (--dx) { + erracctmp = erracc; + erracc += erradj; + if (erracc <= erracctmp) y1++; + x1 += xDir; // x-major so always advance X + /* the nbits most significant bits of erracc give us the intensity + * weighting for this pixel, and the complement of the weighting for + * the paired pixel. + */ + wgt = erracc >> intshift; + ogSetPixel(x1, y1, r, g, b, alphas[wgt]); + ogSetPixel(x1, y1+1, r, g, b, alphas[wgt ^ wgtCompMask]); + } // while + } // else + RawSetPixel(x2, y2, r, g, b, alphas[wgt]); + + } while (false); + + ogSetBlending(oldBlending); + return; +} // ogSurface::AARawLine + +uInt32 +ogSurface::RawGetPixel(uInt32 x, uInt32 y) { + uInt32 result; + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " mov (%%edi),%%eax \n" // eax,word ptr [edi] + " mov %%eax, %3 \n" // mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "m" (result) // %2, %3 + ); + break; + case 3: + __asm__ __volatile__( + " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size + " add %%ecx, %%ecx \n" // add ecx, ecx - adjust for pixel size + " add %%eax, %%ecx \n" // add ecx, eax - adjust for pixel size + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // edx,word ptr [edi] + " xor %%eax, %%eax \n" + " mov 2(%%edi), %%al \n" // mov al, [edi+2] + " shl $16, %%eax \n" // shl eax, 16 + " mov (%%edi), %%ax \n" // mov ax, [edi] + " mov %%eax, %3 \n" // mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "m" (result) // %2, %3 + ); + break; + case 2: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] + " mov %%eax, %0 \n" // mov result, eax + : "=m" (result) + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x) // , "m" (result) // %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " movzbl (%%edi),%%eax \n" // movzx edx,byte ptr [edi] + " mov %%eax, %3 \n" // mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "m" (result) // %2, %3 + ); + break; + } // switch + return result; +} // ogSurface::RawGetPixel + +void +ogSurface::RawSetPixel(uInt32 x, uInt32 y, uInt32 colour) { + uInt32 newR, newG, newB, inverseA; + uInt8 sR, sG, sB, sA; + uInt8 dR, dG, dB; + + do { + if (ogIsBlending()) { + ogUnpack(colour, sR, sG, sB, sA); + if (sA == 0) return; + if (sA == 255) break; + inverseA = 255 - sA; + ogUnpack(RawGetPixel(x, y), dR, dG, dB); + newR = (dR * inverseA + sR * sA) >> 8; + newG = (dG * inverseA + sG * sA) >> 8; + newB = (dB * inverseA + sB * sA) >> 8; + colour = ogPack(newR, newG, newB, inverseA); + } // if + } while (false); + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n" // mov [edi], eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 3: + __asm__ __volatile__( + // Calculate offset, prepare the pixel to be drawn + " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + // " mov %3, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n" // mov [edi], al + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + } // switch + return; +} // ogSurface::RawSetPixel + +void +ogSurface::RawSetPixel(uInt32 x, uInt32 y, uInt8 r, uInt8 g, uInt8 b, uInt8 a) { + uInt32 newR, newG, newB, inverseA; + uInt8 dR, dG, dB; + uInt32 colour; + + do { + if (ogIsBlending()) { + if (a == 0) return; + if (a == 255) { + colour = ogPack(r, g, b, a); + break; + } // if a == 255 + + inverseA = 255 - a; + ogUnpack(RawGetPixel(x, y), dR, dG, dB); + newR = (dR * inverseA + r * a) >> 8; + newG = (dG * inverseA + g * a) >> 8; + newB = (dB * inverseA + b * a) >> 8; + colour = ogPack(newR, newG, newB, inverseA); + } else colour = ogPack(r, g, b, a); + } while (false); + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n" // mov [edi], eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 3: + __asm__ __volatile__( + // Calculate offset, prepare the pixel to be drawn + " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + // " mov %3, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n" // mov [edi], al + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + } // switch + return; +} // ogSurface::RawSetPixel + +bool +ogSurface::ClipLine(int32& x1, int32& y1, int32& x2, int32& y2) { + /* + * clipLine() + * + * private method + * + * clips a line to (0,0),(maxX,maxY); returns true if + * the line segment is in bounds, false if none of the line segment is + * on the screen. Uses HJI's line clipping algorithm. + */ + + int32 tx1, ty1, tx2, ty2; + int32 OutCode; + uInt32 AndResult, OrResult; + AndResult = 15; + OrResult = 0; + OutCode = 0; + if (x1 < 0) OutCode+=8; + if (x1 > (int32)maxX) OutCode+=4; + if (y1 < 0) OutCode+=2; + if (y1 > (int32)maxY) OutCode++; + + AndResult &= OutCode; + OrResult |= OutCode; + OutCode = 0; + + if (x2 < 0) OutCode+=8; + if (x2 > (int32)maxX) OutCode+=4; + if (y2 < 0) OutCode+=2; + if (y2 > (int32)maxY) OutCode++; + + AndResult &= OutCode; + OrResult |= OutCode; + + if (AndResult > 0) return false; + if (OrResult == 0) return true; + + // some clipping is required here. + + tx1 = x1; + ty1 = y1; + tx2 = x2; + ty2 = y2; + + if (x1 < 0) { + ty1 = (x2*y1-x1*y2) / (x2-x1); + tx1 = 0; + } // if + else + if (x2 < 0) { + ty2 = (x2*y1-x1*y2) / (x2-x1); + tx2 = 0; + } // elseif + + if (x1 > (int32)maxX) { + ty1 = (y1*(x2-maxX)+y2*(maxX-x1)) / (x2-x1); + tx1 = maxX; + } // if + else + if (x2 > (int32)maxX) { + ty2 = (y1*(x2-maxX)+y2*(maxX-x1)) / (x2-x1); + tx2 = maxX; + } // elseif + + if (((ty1 < 0) && (ty2 < 0)) || + ((ty1>(int32)maxY) && (ty2>(int32)maxY))) return false; + + if (ty1 < 0) { + tx1 = (x1*y2-x2*y1) / (y2-y1); + ty1 = 0; + } // if + else + if (ty2 < 0) { + tx2 = (x1*y2-x2*y1) / (y2-y1); + ty2 = 0; + } // elseif + + if (ty1 > (int32)maxY) { + tx1 = (x1*(y2-maxY)+x2*(maxY-y1)) / (y2-y1); + ty1 = maxY; + } // if + else + if (ty2 > (int32)maxY) { + tx2 = (x1*(y2-maxY)+x2*(maxY-y1)) / (y2-y1); + ty2 = maxY; + } // elseif + + if (((uInt32)tx1 > maxX) || ((uInt32)tx2 > maxX)) return false; + + x1 = tx1; + y1 = ty1; + x2 = tx2; + y2 = ty2; + + return true; +} // ogSurface::ClipLine + +// wu's double step line algorithm blatently borrowed from: +// http://www.edepot.com/linewu.html + +void ogSurface::RawLine(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2, uInt32 colour) { + int32 dy = y2 - y1; + int32 dx = x2 - x1; + int32 stepx, stepy; + + if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; } + if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } + + RawSetPixel(x1, y1, colour); + RawSetPixel(x2, y2, colour); + + if (dx > dy) { + int32 length = (dx - 1) >> 2; + int32 extras = (dx - 1) & 3; + int32 incr2 = (dy << 2) - (dx << 1); + + if (incr2 < 0) { + int32 c = dy << 1; + int32 incr1 = c << 1; + int32 d = incr1 - dx; + + for (int32 i = 0; i < length; i++) { + x1 += stepx; + x2 -= stepx; + + if (d < 0) { // Pattern: + RawSetPixel(x1, y1, colour); // + RawSetPixel(x1 += stepx, y1, colour); // x o o + RawSetPixel(x2, y2, colour); // + RawSetPixel(x2 -= stepx, y2, colour); + + d += incr1; + } else { + + if (d < c) { // Pattern: + RawSetPixel(x1, y1, colour); // o + RawSetPixel(x1 += stepx, y1 += stepy, colour); // x o + RawSetPixel(x2, y2, colour); // + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } else { + RawSetPixel(x1, y1 += stepy, colour); // Pattern: + RawSetPixel(x1 += stepx, y1, colour); // o o + RawSetPixel(x2, y2 -= stepy, colour); // x + RawSetPixel(x2 -= stepx, y2, colour); // + } // else + + d += incr2; + } // else + } // for i + + if (extras > 0) { + + if (d < 0) { + RawSetPixel(x1 += stepx, y1, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1, colour); + if (extras > 2) RawSetPixel(x2 -= stepx, y2, colour); + } else + if (d < c) { + RawSetPixel(x1 += stepx, y1, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2 -= stepx, y2, colour); + } else { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1, colour); + if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } + } // if extras > 0 + } else { + int32 c = (dy - dx) << 1; + int32 incr1 = c << 1; + int32 d = incr1 + dx; + + for (int32 i = 0; i < length; i++) { + x1 += stepx; + x2 -= stepx; + + if (d > 0) { + RawSetPixel(x1, y1 += stepy, colour); // Pattern: + RawSetPixel(x1 += stepx, y1 += stepy, colour); // o + RawSetPixel(x2, y2 -= stepy, colour); // o + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); // x + d += incr1; + } else { + if (d < c) { + RawSetPixel(x1, y1, colour); // Pattern: + RawSetPixel(x1 += stepx, y1 += stepy, colour); // o + RawSetPixel(x2, y2, colour); // x o + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); // + } else { + RawSetPixel(x1, y1 += stepy, colour); // Pattern: + RawSetPixel(x1 += stepx, y1, colour); // o o + RawSetPixel(x2, y2 -= stepy, colour); // x + RawSetPixel(x2 -= stepx, y2, colour); // + } + + d += incr2; + } // else + } // for i + + if (extras > 0) { + if (d > 0) { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } else + if (d < c) { + RawSetPixel(x1 += stepx, y1, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2 -= stepx, y2, colour); + } else { + + RawSetPixel(x1 += stepx, y1 += stepy, colour); + + if (extras > 1) RawSetPixel(x1 += stepx, y1, colour); + if (extras > 2) { + if (d > c) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + else + RawSetPixel(x2 -= stepx, y2, colour); + } // if extras > 2 + + } // else + } // if extras > 0 + } // else + + } else { + + int32 length = (dy - 1) >> 2; + int32 extras = (dy - 1) & 3; + int32 incr2 = (dx << 2) - (dy << 1); + + if (incr2 < 0) { + int32 c = dx << 1; + int32 incr1 = c << 1; + int32 d = incr1 - dy; + + for (int32 i = 0; i < length; i++) { + y1 += stepy; + y2 -= stepy; + + if (d < 0) { + RawSetPixel(x1, y1, colour); + RawSetPixel(x1, y1 += stepy, colour); + RawSetPixel(x2, y2, colour); + RawSetPixel(x2, y2 -= stepy, colour); + + d += incr1; + } else { + + if (d < c) { + RawSetPixel(x1, y1, colour); + RawSetPixel(x1 += stepx, y1 += stepy, colour); + RawSetPixel(x2, y2, colour); + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } else { + RawSetPixel(x1 += stepx, y1, colour); + RawSetPixel(x1, y1 += stepy, colour); + RawSetPixel(x2 -= stepx, y2, colour); + RawSetPixel(x2, y2 -= stepy, colour); + } // else + + d += incr2; + } // else + } // for i + + if (extras > 0) { + if (d < 0) { + RawSetPixel(x1, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2, y2 -= stepy, colour); + } else + if (d < c) { + RawSetPixel(x1, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2, y2 -= stepy, colour); + } else { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } // else + } // if extras > 0 + } else { + int32 c = (dx - dy) << 1; + int32 incr1 = c << 1; + int32 d = incr1 + dy; + + for (int32 i = 0; i < length; i++) { + y1 += stepy; + y2 -= stepy; + + if (d > 0) { + RawSetPixel(x1 += stepx, y1, colour); + RawSetPixel(x1 += stepx, y1 += stepy, colour); + RawSetPixel(x2 -= stepx, y2, colour); + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + d += incr1; + } else { + if (d < c) { + RawSetPixel(x1, y1, colour); + RawSetPixel(x1 += stepx, y1 += stepy, colour); + RawSetPixel(x2, y2, colour); + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } else { + RawSetPixel(x1 += stepx, y1, colour); + RawSetPixel(x1, y1 += stepy, colour); + RawSetPixel(x2 -= stepx, y2, colour); + RawSetPixel(x2, y2 -= stepy, colour); + } // else + d += incr2; + } // else + } // for + + if (extras > 0) { + if (d > 0) { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + } else + if (d < c) { + RawSetPixel(x1, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 2) RawSetPixel(x2, y2 -= stepy, colour); + } else { + RawSetPixel(x1 += stepx, y1 += stepy, colour); + if (extras > 1) RawSetPixel(x1, y1 += stepy, colour); + if (extras > 2) { + if (d > c) + RawSetPixel(x2 -= stepx, y2 -= stepy, colour); + else + RawSetPixel(x2, y2 -= stepy, colour); + } // if extras > 2 + } // else + } // if extras > 0 + } // else + } // else +} // ogSurface::RawLine + +#if 0 +void +ogSurface::RawLine(uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2, uInt32 colour) { + /* + * ogSurface::RawLine() + * + * private method; draws an unclipped line from (x1,y1) to (x2,y2) + * + */ + int32 tc; + if (!ogAvail()) return; + switch (BPP) { + case 8: + __asm__ __volatile__( + " mov $1, %%ecx \n" // mov ecx, 1 + " bt $15, %%eax \n" // bt eax, 15 + " jnc rlxPositive8 \n" + " or $-1, %%ecx \n" // or ecx, -1 + " neg %%eax \n" // neg eax +"rlxPositive8: \n" + " add %%eax, %%eax \n" // add eax, eax + " bt $15, %%ebx \n" // bt ebx, 15 + " jnc rlyPositive8 \n" + " neg %%edx \n" // neg edx + " neg %%ebx \n" // neg ebx +"rlyPositive8: \n" + " add %%ebx, %%ebx \n" // add ebx, ebx + + " cmp %%ebx, %%eax \n" // cmp eax, ebx + " jle rlyGreater8 \n" + " push %%ecx \n" // push ecx + " mov %%eax, %%ecx \n" // mov ecx, eax + " mov %%ebx, %6 \n" // mov tc, ebx + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" // pop ecx +"rlxTop8: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%al, (%%edi) \n" // mov [edi], al + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone8 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddY8 \n" + " add %%edx, %%edi \n" // add edi, edx + " sub %%eax, %6 \n" // sub tc, eax +"rlNoAddY8: \n" + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ebx, %6 \n" // add tc, ebx + " jmp rlxTop8 \n" + +"rlyGreater8: \n" + " push %%ecx \n" // push ecx + " mov %%ebx, %%ecx \n" // mov ecx, ebx + " mov %%eax, %6 \n" // mov tc, eax + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" +"rlyTop8: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%al, (%%edi) \n" // mov [edi], al + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone8 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddX8 \n" + " add %%ecx, %%edi \n" // add edi, ecx + " sub %%ebx, %6 \n" // sub tc, ebx +"rlNoAddX8: \n" + " add %%edx, %%edi \n" // add edi, edx + " add %%eax, %6 \n" // add tc, eax + " jmp rlyTop8 \n" +"rlDone8: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+x1), // %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+x2), // %1 + "a" (x2-x1), "b" (y2-y1), // %2, %3 + "d" (xRes), "m" (colour), // %4, %5 + "m" (tc) // %6 + ); + break; + case 15: + case 16: + __asm__ __volatile__( + " mov $1, %%ecx \n" // mov ecx, 1 + " bt $15, %%eax \n" // bt eax, 15 + " jnc rlxPositive16 \n" + " or $-1, %%ecx \n" // or ecx, -1 + " neg %%eax \n" // neg eax +"rlxPositive16: \n" + " add %%eax, %%eax \n" // add eax, eax + " bt $15, %%ebx \n" // bt ebx, 15 + " jnc rlyPositive16 \n" + " neg %%edx \n" // neg edx + " neg %%ebx \n" // neg ebx +"rlyPositive16: \n" + " add %%ebx, %%ebx \n" // add ebx, ebx + + " cmp %%ebx, %%eax \n" // cmp eax, ebx + " jle rlyGreater16 \n" + " push %%ecx \n" // push ecx + " mov %%eax, %%ecx \n" // mov ecx, eax + " mov %%ebx, %6 \n" // mov tc, ebx + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" // pop ecx +"rlxTop16: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%ax, (%%edi) \n" // mov [edi], ax + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone16 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddY16 \n" + " add %%edx, %%edi \n" // add edi, edx + " sub %%eax, %6 \n" // sub tc, eax +"rlNoAddY16: \n" + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " add %%ebx, %6 \n" // add tc, ebx + " jmp rlxTop16 \n" + +"rlyGreater16: \n" + " push %%ecx \n" // push ecx + " mov %%ebx, %%ecx \n" // mov ecx, ebx + " mov %%eax, %6 \n" // mov tc, eax + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" +"rlyTop16: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%ax, (%%edi) \n" // mov [edi], ax + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone16 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddX16 \n" + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " sub %%ebx, %6 \n" // sub tc, ebx +"rlNoAddX16: \n" + " add %%edx, %%edi \n" // add edi, edx + " add %%eax, %6 \n" // add tc, eax + " jmp rlyTop16 \n" +"rlDone16: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1 << 1)), // %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+(x2 << 1)), // %1 + "a" (x2-x1), "b" (y2-y1), // %2, %3 + "d" (xRes), "m" (colour), // %4, %5 + "m" (tc) // %6 + ); + break; + case 24: + __asm__ __volatile__( + " mov $1, %%ecx \n" // mov ecx, 1 + " bt $15, %%eax \n" // bt eax, 15 + " jnc rlxPositive24 \n" + " or $-1, %%ecx \n" // or ecx, -1 + " neg %%eax \n" // neg eax +"rlxPositive24: \n" + " add %%eax, %%eax \n" // add eax, eax + " bt $15, %%ebx \n" // bt ebx, 15 + " jnc rlyPositive24 \n" + " neg %%edx \n" // neg edx + " neg %%ebx \n" // neg ebx +"rlyPositive24: \n" + " add %%ebx, %%ebx \n" // add ebx, ebx + + " cmp %%ebx, %%eax \n" // cmp eax, ebx + " jle rlyGreater24 \n" + " push %%ecx \n" // push ecx + " mov %%eax, %%ecx \n" // mov ecx, eax + " mov %%ebx, %6 \n" // mov tc, ebx + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" // pop ecx +"rlxTop24: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone24 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddY24 \n" + " add %%edx, %%edi \n" // add edi, edx + " sub %%eax, %6 \n" // sub tc, eax +"rlNoAddY24: \n" + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ebx, %6 \n" // add tc, ebx + " jmp rlxTop24 \n" + +"rlyGreater24: \n" + " push %%ecx \n" // push ecx + " mov %%ebx, %%ecx \n" // mov ecx, ebx + " mov %%eax, %6 \n" // mov tc, eax + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" +"rlyTop24: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone24 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddX24 \n" + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " add %%ecx, %%edi \n" // add edi, ecx + " sub %%ebx, %6 \n" // sub tc, ebx +"rlNoAddX24: \n" + " add %%edx, %%edi \n" // add edi, edx + " add %%eax, %6 \n" // add tc, eax + " jmp rlyTop24 \n" +"rlDone24: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1*3)), // %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+(x2*3)), // %1 + "a" (x2-x1), "b" (y2-y1), // %2, %3 + "d" (xRes), "m" (colour), // %4, %5 + "m" (tc) // %6 + ); + break; + case 32: + __asm__ __volatile__( + " mov $1, %%ecx \n" // mov ecx, 1 + " bt $15, %%eax \n" // bt eax, 15 + " jnc rlxPositive32 \n" + " or $-1, %%ecx \n" // or ecx, -1 + " neg %%eax \n" // neg eax +"rlxPositive32: \n" + " add %%eax, %%eax \n" // add eax, eax + " bt $15, %%ebx \n" // bt ebx, 15 + " jnc rlyPositive32 \n" + " neg %%edx \n" // neg edx + " neg %%ebx \n" // neg ebx +"rlyPositive32: \n" + " add %%ebx, %%ebx \n" // add ebx, ebx + + " cmp %%ebx, %%eax \n" // cmp eax, ebx + " jle rlyGreater32 \n" + " push %%ecx \n" // push ecx + " mov %%eax, %%ecx \n" // mov ecx, eax + " mov %%ebx, %6 \n" // mov tc, ebx + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" // pop ecx +"rlxTop32: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%eax, (%%edi)\n" // mov [edi], eax + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone32 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddY32 \n" + " add %%edx, %%edi \n" // add edi, edx + " sub %%eax, %6 \n" // sub tc, eax +"rlNoAddY32: \n" + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " add %%ebx, %6 \n" // add tc, ebx + " jmp rlxTop32 \n" + +"rlyGreater32: \n" + " push %%ecx \n" // push ecx + " mov %%ebx, %%ecx \n" // mov ecx, ebx + " mov %%eax, %6 \n" // mov tc, eax + " shr $1, %%ecx \n" // shr ecx, 1 + " sub %%ecx, %6 \n" // sub tc, ecx + " pop %%ecx \n" +"rlyTop32: \n" + " push %%eax \n" // push eax + " mov %5, %%eax \n" // mov eax, colour + " mov %%eax, (%%edi)\n" // mov [edi], eax + " pop %%eax \n" // pop eax + " cmp %%edi, %%esi \n" // cmp esi, edi + " je rlDone32 \n" + " cmp $0, %6 \n" // cmp tc, 0 + " jl rlNoAddX32 \n" + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx - pix size + " add %%ecx, %%edi \n" // add edi, ecx + " sub %%ebx, %6 \n" // sub tc, ebx +"rlNoAddX32: \n" + " add %%edx, %%edi \n" // add edi, edx + " add %%eax, %6 \n" // add tc, eax + " jmp rlyTop32 \n" +"rlDone32: \n" + : + : "D" ((uInt8 *)buffer+lineOfs[y1]+(x1 << 2)), // %0 + "S" ((uInt8 *)buffer+lineOfs[y2]+(x2 << 2)), // %1 + "a" (x2-x1), "b" (y2-y1), // %2, %3 + "d" (xRes), "m" (colour), // %4, %5 + "m" (tc) // %6 + ); + break; + } // switch + return; +} // ogSurface::RawLine +#endif + +bool +ogSurface::ogAlias(ogSurface& src, uInt32 x1, uInt32 y1, uInt32 x2, uInt32 y2) { + uInt32 tmp; + + if (dataState == ogOwner) { + ogSetLastError(ogAlreadyOwner); + return false; + } // if + + if (x2 < x1) { + tmp= x2; + x2 = x1; + x1 = tmp; + } // if + + if (y2 < y1) { + tmp= y2; + y2 = y1; + y1 = tmp; + } // if + + maxX = (x2-x1); + maxY = (y2-y1); + + dataState = ogAliasing; + + bSize = 0; + lSize = 0; + + owner = &src; + buffer =((unsigned char *)(src.buffer)+x1*(src.bytesPerPix)); + lineOfs=((uInt32 *)src.lineOfs)+y1; + attributes = src.attributes; + + pal = src.pal; + xRes = src.xRes; + yRes = src.yRes; + BPP = src.BPP; + bytesPerPix = src.bytesPerPix; + pixFmtID = src.pixFmtID; + + // For 8bpp modes the next part doesn't matter + redFieldPosition = src.redFieldPosition; + greenFieldPosition = src.greenFieldPosition; + blueFieldPosition = src.blueFieldPosition; + alphaFieldPosition = src.alphaFieldPosition; + // The next part is only used by 15/16bpp + redShifter = src.redShifter; + greenShifter = src.greenShifter; + blueShifter = src.blueShifter; + alphaShifter = src.alphaShifter; + + alphaMasker = src.alphaMasker; + + return true; +} // ogSurface::ogAlias + +void +ogSurface::ogArc(int32 xCenter, int32 yCenter, uInt32 radius, + uInt32 sAngle, uInt32 eAngle, uInt32 colour) { + int32 p; + uInt32 x, y, tmp; + double alpha; + + if (radius == 0) { + ogSetPixel(xCenter, yCenter, colour); + return; + } // if + + sAngle %= 361; + eAngle %= 361; + + if (sAngle > eAngle) { + tmp = sAngle; + sAngle = eAngle; + eAngle = tmp; + } // if + + x = 0; + y = radius; + p = 3-2*radius; + + while (x <= y) { + alpha = (180.0/3.14159265358979)*atan((double)x/(double)y); + + if ((alpha >= sAngle) && (alpha <= eAngle)) + ogSetPixel(xCenter-x, yCenter-y, colour); + + if ((90-alpha >= sAngle) && (90-alpha <= eAngle)) + ogSetPixel(xCenter-y, yCenter-x, colour); + + if ((90+alpha >= sAngle) && (90+alpha <= eAngle)) + ogSetPixel(xCenter-y, yCenter+x, colour); + + if ((180-alpha >= sAngle) && (180-alpha <= eAngle)) + ogSetPixel(xCenter-x, yCenter+y, colour); + + if ((180+alpha >= sAngle) && (180+alpha <= eAngle)) + ogSetPixel(xCenter+x, yCenter+y, colour); + + if ((270-alpha >= sAngle) && (270-alpha <= eAngle)) + ogSetPixel(xCenter+y, yCenter+x, colour); + + if ((270+alpha >= sAngle) && (270+alpha <= eAngle)) + ogSetPixel(xCenter+y, yCenter-x, colour); + + if ((360-alpha >= sAngle) && (360-alpha <= eAngle)) + ogSetPixel(xCenter+x, yCenter-y, colour); + + if (p < 0) + p += 4*x+6; + else { + p += 4*(x-y)+10; + --y; + } // else + ++x; + } // while + return; +} // ogSurface::ogArc + +bool +ogSurface::ogAvail(void) { + return ((buffer != NULL) && (lineOfs != NULL)); +} // ogSurface::ogAvail + +static int32 +calculate(float mu, int32 p0, int32 p1, int32 p2, int32 p3) { + float mu2, mu3; + mu2 = mu*mu; + mu3 = mu2*mu; + return (int32)(0.5f+(1.0/6.0)*(mu3*(-p0+3.0*p1-3.0*p2+p3)+ + mu2*(3.0*p0-6.0*p1+3.0*p2)+ + mu*(-3.0*p0+3.0*p2)+(p0+4.0*p1+p2))); +} // calculate + + +void +ogSurface::ogBSpline(uInt32 numPoints, ogPoint2d* points, uInt32 segments, + uInt32 colour) { + float mu, mudelta; + int32 x1, y1, x2, y2; + uInt32 n, h; + + if (points == NULL) return; + + if ((numPoints < 4) || (numPoints > 255) || (segments == 0)) return; + + mudelta = 1.0/segments; + for (n=3; n= 0) { + ogSetPixel(xCenter+x, yCenter+y, colour); + ogSetPixel(xCenter+x, yCenter-y, colour); + ogSetPixel(xCenter-x, yCenter+y, colour); + ogSetPixel(xCenter-x, yCenter-y, colour); + + if (d + y > 0) { + --y; + d -= 2*y+1; + } // if + + if (x > d) { + ++x; + d += 2*x+1; + } // if + } // while + return; +} // ogSurface::ogCircle + +void +ogSurface::ogClear(uInt32 colour) { + uInt32 height = 0; + uInt32 xx, yy; + uInt8 r, g, b, a; + if (!ogAvail()) return; + + do { + if (ogIsBlending()) { + ogUnpack(colour, r, g, b, a); + if (a == 0) return; + if (a == 255) break; + for (yy = 0; yy <= maxY; yy++) + for (xx = 0; xx <= maxX; xx++) + RawSetPixel(xx, yy, r, g, b, a); + return; + } // if + } while (false); + + __asm__ __volatile__("cld\n"); + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxX) + " inc %%ebx \n" // inc ebx (maxY) + " mov %%edx, %%ecx \n" // mov ecx, edx + " shl $2, %%ecx \n" // shl ecx, 2 + " sub %%ecx, %%esi \n" // sub esi, ecx // adjust for pix size + "loop32: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " rep \n" + " stosl \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop32 \n" + + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "a" (colour), "b" (maxY), // %2, %3 + "c" (xRes), "d" (maxX) // %4, %5 + ); + break; + case 3: + __asm__ __volatile__( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxX) + " inc %%ebx \n" // inc ebx (maxY) + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%ebx, %6 \n" // mov height, ebx + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%eax, %%ebx \n" // mov ebx, eax + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " shr $16, %%ebx \n" // shr ebx, 16 + "oloop24: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + "iloop24: \n" + " mov %%ax,(%%edi) \n" // mov [edi],ax + " movb %%bl,2(%%edi) \n" // mov [edi+2],bl + " add $3, %%edi \n" // add edi, 3 + " dec %%ecx \n" // dec ecx + " jnz iloop24 \n" + " add %%esi, %%edi \n" // add edi, esi + " decl %6 \n" // dec height + " jnz oloop24 \n" + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "a" (colour), "b" (maxY), // %2, %3 + "c" (xRes), "d" (maxX), // %4, %5 + "m" (height) // %6 + ); + break; + case 2: + __asm__ __volatile__( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxX) + " inc %%ebx \n" // inc ebx (maxY) + " sub %%edx, %%esi \n" // sub esi, edx + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%ax, %%cx \n" // mov cx, ax + " shl $16, %%eax \n" // shl eax, 16 + " mov %%cx, %%ax \n" // mov ax, cx + "loop16: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " shr $1, %%ecx \n" // shr ecx, 1 + " rep \n" + " stosl \n" + " jnc noc16 \n" + " stosw \n" + "noc16: \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop16 \n" + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "a" (colour), "b" (maxY), // %2, %3 + "c" (xRes), "d" (maxX) // %4, %5 + ); + break; + case 1: + __asm__ __volatile__( + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxY) + " inc %%ebx \n" // inc ebx (maxX) + " sub %%edx, %%esi \n" // sub esi, edx + " mov %%al, %%ah \n" // mov ah, al + " mov %%ax, %%cx \n" // mov cx, ax + " shl $16, %%eax \n" // shl eax, 16 + " mov %%cx, %%ax \n" // mov ax, cx + "loop8: \n" + " push %%edx \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " and $3, %%edx \n" // and edx, 3 + " shr $2, %%ecx \n" // shr ecx, 2 + " rep \n" + " stosl \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " rep \n" + " stosb \n" + " pop %%edx \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop8 \n" + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "a" (colour), "b" (maxY), // %2, %3 + "c" (xRes), "d" (maxX) // %4, %5 + ); + break; + } // switch + return; +} // ogSurface::ogClear + +bool +ogSurface::ogClone(ogSurface& src) { + bool created; + ogPixelFmt pixFmt; + + if (src.dataState == ogNone) { + ogSetLastError(ogNoSurface); + return false; + } // if + + src.ogGetPixFmt(pixFmt); + created = ogCreate(src.maxX+1, src.maxY+1, pixFmt); + if (!created) return false; + + *attributes = *src.attributes; + + ogCopyPalette(src); + ogCopy(src); + return true; +} // ogSurface::ogClone + +void +ogSurface::ogCopy(ogSurface& src) { + uInt32 pixMap[256]; + uInt32 count, xCount, yCount; + uInt32 xx, yy; + uInt8 r, g, b, a; + void * srcPtr; + + if (!ogAvail()) return; + if (!src.ogAvail()) return; + + xCount = src.maxX+1; + if (xCount > maxX+1) xCount = maxX+1; + yCount = src.maxY+1; + if (yCount > maxY+1) yCount = maxY+1; + + if (ogIsBlending()) { + + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) { + src.ogUnpack(src.RawGetPixel(xx, yy), r, g, b, a); + RawSetPixel(xx, yy, r, g, b, a); + } // for xx + + return; + } // if blending + + if (pixFmtID != src.pixFmtID) { + if (src.bytesPerPix == 1) { + for (xx = 0; xx < 256; xx++) + pixMap[xx] = ogPack(src.pal[xx].red, + src.pal[xx].green, + src.pal[xx].blue, + src.pal[xx].alpha); + + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) + RawSetPixel(xx, yy, pixMap[src.RawGetPixel(xx, yy)]); + + } else { // if src.bytesPerPix == 1 + ogPixelFmt srcPixFmt, dstPixFmt; + src.ogGetPixFmt(srcPixFmt); + ogGetPixFmt(dstPixFmt); + ogPixCon * pc = new ogPixCon(srcPixFmt, dstPixFmt); + + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) + RawSetPixel(xx, yy, pc->ConvPix(src.RawGetPixel(xx, yy))); + + delete pc; + } // else + } else { + + xCount *= bytesPerPix; + + for (count = 0; count < yCount; count++) + if ((srcPtr = src.ogGetPtr(0, count)) == NULL) { + /* + * if we are here then we couldn't get a direct memory pointer + * from the source object. This means that it is not a normal + * "memory" buffer and we have to use the implementation inspecific + * interface. We let the source buffer fill a "temporary" buffer + * and then we copy it to where it needs to go. + */ +#ifdef __UBIXOS_KERNEL__ + srcPtr = kmalloc(xCount); // allocate space +#else + srcPtr = malloc(xCount); // allocate space +#endif + if (srcPtr != NULL) { + src.ogCopyLineFrom(0, count, srcPtr, xCount); + ogCopyLineTo(0, count, srcPtr, xCount); +#ifdef __UBIXOS_KERNEL__ + kfree(srcPtr); +#else + free(srcPtr); +#endif + } // if srcPtr!=NULL + } else ogCopyLineTo(0, count, srcPtr, xCount); + } // else +} // ogSurface::ogCopy + +void +ogSurface::ogCopyBuf(int32 dX1, int32 dY1, + ogSurface& src, int32 sX1, int32 sY1, int32 sX2, int32 sY2) { + uInt32 pixMap[256]; + int32 xx, yy, count, xCount, yCount; + uInt8 r, g, b, a; + void *srcPtr; + ogPixCon * pc; + ogPixelFmt srcPixFmt, dstPixFmt; + + if (!ogAvail()) return; + if (!src.ogAvail()) return; + + if ((dX1 > (int32)maxX) || (dY1 > (int32)maxY)) return; + + // if any of the source buffer is out of bounds then do nothing + if (( (uInt32)sX1 > src.maxX) || ((uInt32)sX2 > src.maxX) || + ( (uInt32)sY1 > src.maxY) || ((uInt32)sY2 > src.maxY)) return; + + if (sX1 > sX2) { + xx = sX1; + sX1= sX2; + sX2= xx; + } // if + + if (sY1 > sY2) { + yy = sY1; + sY1= sY2; + sY2= yy; + } // if + + xCount = abs(sX2-sX1)+1; + yCount = abs(sY2-sY1)+1; + + if (dX1+xCount > (int32)maxX+1) xCount = maxX-dX1+1; + if (dY1+yCount > (int32)maxY+1) yCount = maxY-dY1+1; + + if (dX1 < 0) { + xCount += dX1; + sX1 -= dX1; + dX1 = 0; + } // if + + if (dY1 < 0) { + yCount += dY1; + sY1 -= dY1; + dY1 = 0; + } // if + + if ((dX1+xCount < 0) || (dY1+yCount < 0)) return; + + if (ogIsBlending()) { + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) { + src.ogUnpack(src.RawGetPixel(sX1+xx, sY1+yy), r, g, b, a); + RawSetPixel(dX1+xx, dY1+yy, r, g, b, a); + } // for xx + } // if IsBlending + + if (pixFmtID != src.pixFmtID) { + + if (src.bytesPerPix == 1) { + for (xx = 0; xx < 256; xx++) + pixMap[xx] = ogPack(src.pal[xx].red, + src.pal[xx].green, + src.pal[xx].blue, + src.pal[xx].alpha); + + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) + RawSetPixel(dX1+xx,dY1+yy, + pixMap[src.ogGetPixel(sX1+xx,sY1+yy)]); + } else { + + src.ogGetPixFmt(srcPixFmt); + ogGetPixFmt(dstPixFmt); + pc = new ogPixCon(srcPixFmt, dstPixFmt); // allocate the pixel converter + if (pc == NULL) return; + + for (yy = 0; yy < yCount; yy++) + for (xx = 0; xx < xCount; xx++) { + RawSetPixel(dX1+xx, dY1+yy, + pc->ConvPix(src.RawGetPixel(sX1+xx, sY1+yy))); + } // for xx + + delete pc; // destroy the pixel converter + + } // else + } else { + xCount *= bytesPerPix; + + for (count = 0; count < yCount; count++) + if ((srcPtr = src.ogGetPtr(sX1, sY1+count)) == NULL) { + // if we are here then we couldn't get a direct memory pointer + // from the source object. This means that it is not a normal + // "memory" buffer and we have to use the implementation inspecific + // interface. We let the source buffer fill a "temporary" buffer + // and then we copy it to where it needs to go. + +#ifdef __UBIXOS_KERNEL__ + srcPtr = kmalloc(xCount); // allocate space +#else + srcPtr = malloc(xCount); // allocate space +#endif + if (srcPtr != NULL) { + src.ogCopyLineFrom(sX1, sY1+count, srcPtr, xCount); + ogCopyLineTo(dX1, dY1+count, srcPtr, xCount); +#ifdef __UBIXOS_KERNEL__ + kfree(srcPtr); +#else + free(srcPtr); +#endif + } // if srcPtr!=NULL + } else ogCopyLineTo(dX1,dY1+count,srcPtr,xCount); + } // else +} // ogSurface::ogCopyBuf + +void +ogSurface::ogCopyLineTo(uInt32 dx, uInt32 dy, const void * src, uInt32 size) { + /* + * CopyLineTo() + * + * Inputs: + * + * dx - Destination X of the target buffer + * dy - Destination Y of the target buffer + * src - buffer to copy + * size - size in bytes *NOT* pixels + * + * Copies a run of pixels (of the same format) to (x,y) of a buffer + * + * This method is required because of the different implementations of + * copying a run of pixels to a buffer + * + * WARNING!!! This does *NO* error checking. It is assumed that you've + * done all of that. CopyLineTo and CopyLineFrom are the only + * methods that don't check to make sure you're hosing things. Don't + * use this method unless YOU KNOW WHAT YOU'RE DOING!!!!!!!!! + */ + +#ifdef __UBIXOS_KERNEL__ + kmemcpy( (uInt8*)buffer+lineOfs[dy]+dx*bytesPerPix, // dest + src, // src + size); // size +#else + memcpy( (uInt8*)buffer+lineOfs[dy]+dx*bytesPerPix, // dest + src, // src + size); // size +#endif + + return; +} // ogSurface::ogCopyLineTo + +void +ogSurface::ogCopyLineFrom(uInt32 sx, uInt32 sy, void * dst, uInt32 size) { + /* + * CopyLineFrom() + * + * Inputs: + * + * sx - Source X of the target buffer + * sy - Source Y of the target buffer + * dest - where to put it + * size - size in bytes *NOT* pixels + * + * Copies a run of pixels (of the same format) to (x,y) of a buffer + * + * This method is required because of the different implementations of + * copying a run of pixels to a buffer + * + * WARNING!!! This does *NO* error checking. It is assumed that you've + * done all of that. CopyLineTo and CopyLineFrom are the only + * methods that don't check to make sure you're hosing things. Don't + * use this method unless YOU KNOW WHAT YOU'RE DOING!!!!!!!!! + */ + +#ifdef __UBIXOS_KERNEL__ + kmemcpy( dst, // dest + (uInt8*)buffer+lineOfs[sy]+sx*bytesPerPix, // src + size); // size +#else + memcpy( dst, // dest + (uInt8*)buffer+lineOfs[sy]+sx*bytesPerPix, // src + size); // size +#endif + + return; +} // ogSurface::ogCopyLineFrom + +void +ogSurface::ogCopyPalette(ogSurface& src) { + if (src.pal == NULL) return; + if (pal == NULL) pal = new ogRGBA8[256]; + if (pal == NULL) return; + src.ogGetPalette(pal); + // memcpy(pal, src.pal, sizeof(ogRGBA8)*256); + return; +} // ogSurface::ogCopyPalette + +bool +ogSurface::ogCreate(uInt32 _xRes, uInt32 _yRes, ogPixelFmt _pixFormat) { + /* + * ogSurface::ogCreate() + * Allocates memory for a buffer of size _xRes by _yRes with + * the pixel format defined in _pixformat. Allocates memory + * for pal and lineOfs. + */ + void * newBuffer = NULL; + uInt32 * newLineOfs = NULL; + ogRGBA8 * newPal = NULL; + ogAttributes* newAttributes = NULL; + + uInt32 newBSize; + uInt32 newLSize; + uInt32 yy; + + bool status = false; + + switch (_pixFormat.BPP) { + case 8: + case 15: + case 16: + case 24: + case 32: + break; + default: + ogSetLastError(ogBadBPP); + return false; + } // switch + + newBSize = _xRes * _yRes * ((_pixFormat.BPP + 7) >> 3); + newLSize = _yRes * sizeof(uInt32); // number of scan lines * sizeof(uInt32) + +#ifdef __UBIXOS_KERNEL__ + newBuffer = kmalloc(newBSize); +#else + newBuffer = malloc(newBSize); +#endif + newLineOfs = new uInt32[_yRes]; + newPal = new ogRGBA8[256]; + newAttributes = new ogAttributes(); + + do { + + if ((newBuffer == NULL) || (newLineOfs == NULL) || + (newPal == NULL) || (newAttributes == NULL)) { + ogSetLastError(ogMemAllocFail); + break; // break out of do {...} while(false) + } // if + + // check to see if we have already allocated memory .. if so, free it + + if (dataState == ogOwner) { +#ifdef __UBIXOS_KERNEL__ + kfree(buffer); +#else + free(buffer); +#endif + delete [] lineOfs; + delete [] pal; + delete attributes; + } // if dataState + + buffer = newBuffer; + lineOfs = newLineOfs; + pal = newPal; + attributes = newAttributes; + bSize = newBSize; + lSize = newLSize; + + newBuffer = NULL; + newLineOfs = NULL; + newPal = NULL; + newAttributes = NULL; + + BPP = _pixFormat.BPP; + bytesPerPix = (BPP + 7) >> 3; + + ogSetPalette(DEFAULT_PALETTE); + // memcpy(pal, DEFAULT_PALETTE, sizeof(ogRGBA8)*256); + + maxX = _xRes -1; + xRes = _xRes * bytesPerPix; + maxY = _yRes -1; + yRes = _yRes; + + // in the pascal version we go from 1 to maxY .. here we use yy < yRes + // (which is the same) + + lineOfs[0] = 0; + for (yy = 1; yy < yRes; yy++) + lineOfs[yy] = lineOfs[yy-1]+xRes; + + dataState = ogOwner; + + // For 8bpp modes the next part doesn't matter + + redFieldPosition = _pixFormat.redFieldPosition; + greenFieldPosition = _pixFormat.greenFieldPosition; + blueFieldPosition = _pixFormat.blueFieldPosition; + alphaFieldPosition = _pixFormat.alphaFieldPosition; + // The next part is only used by 15/16hpp + redShifter = 8-_pixFormat.redMaskSize; + greenShifter = 8-_pixFormat.greenMaskSize; + blueShifter = 8-_pixFormat.blueMaskSize; + alphaShifter = 8-_pixFormat.alphaMaskSize; + + if (_pixFormat.alphaMaskSize != 0) + alphaMasker = ~(OG_MASKS[_pixFormat.alphaMaskSize] << alphaFieldPosition); + else + alphaMasker = ~0; + + if (bytesPerPix == 1) { + pixFmtID = 0x08080808; + // turn anti aliasing off by default for 8bpp modes + ogSetAntiAliasing(false); + } else { + pixFmtID = (redFieldPosition) | + (greenFieldPosition << 8) | + (blueFieldPosition << 16) | + (alphaFieldPosition << 24); + ogSetAntiAliasing(true); + } // else + + ogClear(ogPack(0, 0, 0)); + + owner = this; + status = true; + } while(false); + +#ifdef __UBIXOS_KERNEL__ + if (newBuffer) kfree(newBuffer); +#else + if (newBuffer) free(newBuffer); +#endif + if (newLineOfs) delete [] newLineOfs; + if (newPal) delete [] newPal; + if (newAttributes) delete newAttributes; + + return status; +} // ogSurface::ogCreate + +void +ogSurface::ogCubicBezierCurve(int32 x1, int32 y1, int32 x2, int32 y2, + int32 x3, int32 y3, int32 x4, int32 y4, + uInt32 segments, uInt32 colour) { + float tX1, tY1, tX2, tY2, tX3, tY3, mu, mu2, mu3, mudelta; + int32 xStart, yStart, xEnd, yEnd; + uInt32 n; + if (segments < 1) return; + if (segments > 128) segments=128; + + mudelta = 1.0/segments; + mu = mudelta; + tX1 =-x1+3*x2-3*x3+x4; + tY1 =-y1+3*y2-3*y3+y4; + tX2 =3*x1-6*x2+3*x3; + tY2 =3*y1-6*y2+3*y3; + tX3 =-3*x1+3*x2; + tY3 =-3*y1+3*y2; + + xStart = x1; + yStart = y1; + + for (n = 1; n < segments; n++) { + mu2 = mu*mu; + mu3 = mu2*mu; + xEnd = static_cast(mu3*tX1+mu2*tX2+mu*tX3+x1 +0.5f); + yEnd = static_cast(mu3*tY1+mu2*tY2+mu*tY3+y1 +0.5f); + ogLine(xStart, yStart, xEnd, yEnd, colour); + mu += mudelta; + xStart = xEnd; + yStart = yEnd; + } // for + return; +} // ogSurface::ogCubicBezierCurve + +void +ogSurface::ogCurve(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3, + uInt32 segments, uInt32 colour) { + int64 ex, ey, fx, fy; + int64 t1, t2; + + if (segments<2) segments=2; else if (segments>128) segments=128; + x2 = (x2*2)-((x1+x3)/2); + y2 = (y2*2)-((y1+y3)/2); + + ex = ((int64)(x2-x1) << 17) / segments; + ey = ((int64)(y2-y1) << 17) / (int64)segments; + fx = ((int64)(x3-(2*x2)+x1) << 16) / (segments*segments); + fy = ((int64)(y3-(2*y2)+y1) << 16) / (int64)(segments*segments); + + while (--segments > 0) { + t1 = x3; + t2 = y3; + x3 = ((int64)((fx*segments+ex)*segments) / 65536L)+x1; + y3 = ((int64)((fy*segments+ey)*segments) / 65536L)+y1; + ogLine(t1, t2, x3, y3, colour); + } // while + ogLine(x3, y3, x1, y1, colour); + return; + +} // ogSurface::ogCurve + +void +ogSurface::ogFillCircle(int32 xCenter, int32 yCenter, + uInt32 radius, uInt32 colour) { + int32 x, y, d; + x = 0; + y = radius; + d = 4*(1-radius); + + while (y >= 0) { + if (d + y > 0) { + ogHLine(xCenter-x, xCenter+x, yCenter-y, colour); + if (y != 0) ogHLine(xCenter-x, xCenter+x, yCenter+y, colour); + + --y; + d -= 4*y+1; + } // if + + + if (x > d) { + ++x; + d += 4*x+1; + } // if + } // while + return; +} // ogSurface::ogFillCircle + +#if 0 +!-/* Scan converts an edge from (X1,Y1) to (X2,Y2), not including the +!- * point at (X2,Y2). This avoids overlapping the end of one line with +!- * the start of the next, and causes the bottom scan line of the +!- * polygon not to be drawn. If SkipFirst != 0, the point at (X1,Y1) +!- * isn't drawn. For each scan line, the pixel closest to the scanned +!- * line without being to the left of the scanned line is chosen +!- */ +!-static void index_forward(int32 & index, uInt32 numPoints) { +!- index = (index + 1) % numPoints; +!- return; +!-} // index_forward +!- +!-static void index_backward(int32 & index, uInt32 numPoints) { +!- index = (index - 1 + numPoints) % numPoints; +!- return; +!-} // index_forward +!- +!-static void index_move(int32 & index, uInt32 numPoints, int32 direction) { +!- if (direction > 0) +!- index_forward(index, numPoints); +!- else +!- index_backward(index, numPoints); +!- return; +!-} // index_move +!- +!-static void scanEdge(int32 x1, int32 y1, int32 x2, int32 y2, +!- uInt32 & eIdx, int32 * xList) { +!- int32 y, deltaX, deltaY; +!- float inverseSlope; +!- +!- deltaX = x2 - x1; +!- deltaY = y2 - y1; +!- if (deltaY <= 0) return; +!- inverseSlope = deltaX / deltaY; +!- +!- // Store the X coordinate of the pixel closest to but not to the +!- // left of the line for each Y coordinate between Y1 and Y2, not +!- // including Y2 +!- y = y1; +!- do { +!- xList[eIdx] = x1+ (int32)(0.5f+((y-y1)*inverseSlope)); +!- y++; +!- eIdx++; +!- } while (y maxPointY) { +!- maxIndex = i; +!- maxPointY = polyPoints[i].y; // new bottom +!- } // else if +!- } // for +!- +!- if (minPointY == maxPointY) return; +!- +!- // scan in ascending order to find the last top-edge point +!- minIndexR = minIndexL; +!- while (polyPoints[minIndexR].y == minPointY) index_forward(minIndexR, numPoints); +!- index_backward(minIndexR, numPoints); // back up to last top-edge point +!- +!- // now scan in descending order to find the first top-edge point +!- while (polyPoints[minIndexL].y == minPointY) index_backward(minIndexL, numPoints); +!- index_forward(minIndexL, numPoints); +!- +!- // figure out which direction through the vertex list from the top +!- // vertex is the left edge and which is the right +!- leftEdgeDir = -1; +!- +!- topIsFlat = (polyPoints[minIndexL].x==polyPoints[minIndexR].x) ? 0 : 1; +!- if (topIsFlat==1) { +!- if (polyPoints[minIndexL].x > polyPoints[minIndexR].x) { +!- leftEdgeDir = 1; +!- temp = minIndexL; +!- minIndexL = minIndexR; +!- minIndexR = temp; +!- } +!- } else { +!- // Point to the downward end of the first line of each of the +!- // two edges down from the top +!- nextIndex = minIndexR; +!- index_forward(nextIndex, numPoints); +!- prevIndex = minIndexL; +!- index_forward(prevIndex, numPoints); +!- +!- deltaXN = polyPoints[nextIndex].x - polyPoints[minIndexL].x; +!- deltaYN = polyPoints[nextIndex].y - polyPoints[minIndexL].y; +!- deltaXP = polyPoints[prevIndex].x - polyPoints[minIndexL].x; +!- deltaYP = polyPoints[prevIndex].y - polyPoints[minIndexL].y; +!- if (deltaXN * deltaYP - deltaYN * deltaXP < 0) { +!- leftEdgeDir = 1; +!- temp = minIndexL; +!- minIndexL = minIndexR; +!- minIndexR = temp; +!- } // if +!- } // else +!- +!- /* Set the # of scan lines in the polygon, skipping the bottom edge +!- * and also skipping the top vertex if the top isn't flat because +!- * in that case the top vertex has a right edge component, and set +!- * the top scan line to draw, which is likewise the second line of +!- * the polygon unles the top if flat +!- */ +!- +!- workingHLineList.length = maxPointY - minPointY; +!- if (workingHLineList.length <= 0) return; +!- workingHLineList.yStart = minPointY; +!- +!- // get memory in which to srote the line list we generate +!- workingHLineList.xLeft = workingHLineList.xRight = NULL; +!- if ((workingHLineList.xLeft = new int32[workingHLineList.length]) == NULL) return; +!- if ((workingHLineList.xRight = new int32[workingHLineList.length]) == NULL) { +!- delete workingHLineList.xLeft; +!- return; +!- } +!- memset(workingHLineList.xLeft,0,workingHLineList.length*sizeof(int32)); +!- memset(workingHLineList.xRight,0,workingHLineList.length*sizeof(int32)); +!- +!- // scan the left edge and store the boundary points int he list +!- // Initial pointer for storing scan converted left-edge coords +!- edgePointIdx = 0; +!- +!- // start from the top of the left edge +!- curIndex = prevIndex = minIndexL; +!- +!- do { +!- index_move(curIndex, numPoints, leftEdgeDir); +!- scanEdge(polyPoints[prevIndex].x, +!- polyPoints[prevIndex].y, +!- polyPoints[curIndex].x, +!- polyPoints[curIndex].y, +!- edgePointIdx, +!- workingHLineList.xLeft); +!- prevIndex = curIndex; +!- } while (curIndex != maxIndex); +!- +!- edgePointIdx = 0; +!- curIndex = prevIndex = minIndexR; +!- // Scan convert the right edge, top to bottom. X coordinates are +!- // adjusted 1 to the left, effectively causing scan conversion of +!- // the nearest points to the left of but not exactly on the edge } +!- do { +!- index_move(curIndex, numPoints, -leftEdgeDir); +!- scanEdge(polyPoints[prevIndex].x, +!- polyPoints[prevIndex].y, +!- polyPoints[curIndex].x, +!- polyPoints[curIndex].y, +!- edgePointIdx, +!- workingHLineList.xRight); +!- prevIndex = curIndex; +!- } while (curIndex != maxIndex); +!- +!- ogPolygon(numPoints, polyPoints, colour); +!- +!- for (i = 0; i < workingHLineList.length; i++) { +!- HLine(workingHLineList.xLeft[i], workingHLineList.xRight[i], +!- workingHLineList.yStart+i, colour); +!- } // for +!- +!- ogPolygon(numPoints, polyPoints, colour); +!- +!- delete workingHLineList.xLeft; +!- delete workingHLineList.xRight; +!- +!- return; +!-} // ogSurface::FillConvexPolygon +#endif + +void +ogSurface::ogFillGouraudPolygon(uInt32 numPoints, ogPoint2d* polyPoints, ogRGBA8 * colours) { + + ogEdgeTable * edges; + int32 currentY = ~0; + + if (numPoints < 3) return; + + edges = new ogEdgeTable(); + + if (edges == NULL) return; // sanity check + + edges->BuildGET_G(numPoints, polyPoints, colours); + + if (edges->globalEdges != NULL) + currentY = edges->globalEdges->startY; + + while ((edges->globalEdges != NULL) || (edges->activeEdges != NULL)) { + edges->MoveXSortedToAET(currentY); + edges->ScanOutAET_G(*this, currentY); + edges->AdvanceAET(); + edges->XSortAET(); + ++currentY; + if (currentY > (int32)maxY) break; // if we've gone past the bottom, stop + } // while + + delete edges; + return; +} // ogSurface::ogFillGouraudPolygon + +void +ogSurface::ogFillPolygon(uInt32 numPoints, ogPoint2d* polyPoints, uInt32 colour) { + ogEdgeTable * edges; + int32 currentY = ~0; + + if (numPoints < 3) return; + + if (!ogIsBlending()) ogPolygon(numPoints, polyPoints, colour); + + edges = new ogEdgeTable(); + + if (edges == NULL) return; // sanity check + + edges->BuildGET(numPoints, polyPoints); + + if (edges->globalEdges != NULL) + currentY = edges->globalEdges->startY; + + while ((edges->globalEdges != NULL) || (edges->activeEdges != NULL)) { + edges->MoveXSortedToAET(currentY); + edges->ScanOutAET(*this, currentY, colour); + edges->AdvanceAET(); + edges->XSortAET(); + ++currentY; + if (currentY > (int32)maxY) break; // if we've gone past the bottom, stop + } // while + delete edges; + return; +} // ogSurface::ogFillPolygon + +void +ogSurface::ogFillRect(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { + int32 yy, tmp; + + if (x2 < x1) { + tmp= x2; + x2 = x1; + x1 = tmp; + } // if + + if (y2 < y1) { + tmp= y2; + y2 = y1; + y1 = tmp; + } // if + + if ((y2 < 0) || (y1 > (int32)maxY)) return; + if (y1 < 0) y1 = 0; + if (y2 > (int32)maxY) y2 = maxY; + for (yy = y1; yy <= y2; yy++) + ogHLine(x1, x2, yy, colour); +} // ogSurface::ogFillRect + +void ogSurface::ogFillTriangle(int32 x1, int32 y1, int32 x2, int32 y2, + int32 x3, int32 y3, uInt32 colour) { + ogPoint2d points[3]; + points[0].x = x1; + points[0].y = y1; + points[1].x = x2; + points[1].y = y2; + points[2].x = x3; + points[2].y = y3; + + ogFillPolygon(3, points, colour); + + return; +} // ogSurface::ogFillTriangle + +uInt32 +ogSurface::ogGetAlpha(void) { + if (attributes != NULL) + return attributes->defaultAlpha; + else + return 255L; +} // ogSurface::ogGetAlpha + +ogErrorCode +ogSurface::ogGetLastError(void) { + ogErrorCode tmp = lastError; + lastError = ogOK; + return tmp; +} // ogSurface::ogGetLastError + +void +ogSurface::ogGetPalette(ogRGBA8 _pal[256]) { +#ifdef __UBIXOS_KERNEL__ + kmemcpy(_pal, pal, sizeof(_pal)); +#else + memcpy(_pal, pal, sizeof(_pal)); +#endif + return; +} // ogSurface::ogGetPalette + +void +ogSurface::ogGetPixFmt(ogPixelFmt& pixfmt) { + pixfmt.BPP = BPP; + pixfmt.redFieldPosition = redFieldPosition; + pixfmt.greenFieldPosition = greenFieldPosition; + pixfmt.blueFieldPosition = blueFieldPosition; + pixfmt.alphaFieldPosition = alphaFieldPosition; + pixfmt.redMaskSize = 8-redShifter; + pixfmt.greenMaskSize = 8-greenShifter; + pixfmt.blueMaskSize = 8-blueShifter; + pixfmt.alphaMaskSize = 8-alphaShifter; + return; +} // ogSurface::ogGetPixFmt + +uInt32 +ogSurface::ogGetPixel(int32 x, int32 y) { + uInt32 result; + if (!ogAvail()) return ogGetTransparentColor(); + + if (((uInt32)x > maxX) || ((uInt32)y > maxY)) return ogGetTransparentColor(); + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " mov (%%edi),%%eax \n" // eax,word ptr [edi] + " mov %%eax, %3 \n" // mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "m" (result) // %2, %3 + ); + break; + case 3: + __asm__ __volatile__( + " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] +// " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size +// " add %%ecx, %%ecx \n" // add ecx, ecx - adjust for pixel size +// " add %%eax, %%ecx \n" // add ecx, eax - adjust for pixel size + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // edx,word ptr [edi] + " xor %%eax, %%eax \n" + " mov 2(%%edi), %%al \n" // mov al, [edi+2] + " shl $16, %%eax \n" // shl eax, 16 + " mov (%%edi), %%ax \n" // mov ax, [edi] + " mov %%eax, %3 \n" // mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "m" (result) // %2, %3 + ); + break; + case 2: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] + " mov %%eax, %0 \n" // mov result, eax + : "=m" (result) + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x) // , "m" (result) // %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " movzbl (%%edi),%%eax \n" // movzx edx,byte ptr [edi] + " mov %%eax, %3 \n" // mov result, eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "m" (result) // %2, %3 + ); + break; + } // switch + return result; +} // ogSurface::ogGetPixel + +void * +ogSurface::ogGetPtr(uInt32 x, uInt32 y) { +// return (Avail() ? ( (uInt8*)buffer+(lineOfs[y]+x*((BPP+7) >> 3)) ) : NULL ); + return ((uInt8*)buffer+(lineOfs[y]+x*bytesPerPix)); +} // ogSurface::ogGetPtr + +uInt32 +ogSurface::ogGetTransparentColor(void) { + if (attributes != NULL) + return attributes->transparentColor; + else + return 0; +} // ogSurface::ogGetTransparentColor + +void +ogSurface::ogHFlip(void) { + void * tmpBuf1; + void * tmpBuf2; + uInt32 xWidth, count; + + if (!ogAvail()) return; + + xWidth = (maxX+1)*bytesPerPix; + +#ifdef __UBIXOS_KERNEL__ + tmpBuf1 = kmalloc(xWidth); + tmpBuf2 = kmalloc(xWidth); +#else + tmpBuf1 = malloc(xWidth); + tmpBuf2 = malloc(xWidth); +#endif + + if ((tmpBuf1 != NULL) && (tmpBuf2 != NULL)) + for (count = 0; count <= (maxY/2); count++) { + ogCopyLineFrom(0, count, tmpBuf1, xWidth); + ogCopyLineFrom(0, maxY-count,tmpBuf2, xWidth); + ogCopyLineTo(0, maxY-count,tmpBuf1, xWidth); + ogCopyLineTo(0, count, tmpBuf2, xWidth); + } // for count + +#ifdef __UBIXOS_KERNEL__ + kfree(tmpBuf2); + kfree(tmpBuf1); +#else + free(tmpBuf2); + free(tmpBuf1); +#endif + + return; +} // ogSurface::ogHFlip + +void +ogSurface::ogHLine(int32 x1, int32 x2, int32 y, uInt32 colour) { + int32 tmp; + uInt8 r, g, b, a; + + if (!ogAvail()) return; + if ((uInt32)y > maxY) return; + + if (x1 > x2) { + tmp= x1; + x1 = x2; + x2 = tmp; + } // if + + if (x1 < 0) x1 = 0; + if (x2 > (int32)maxX) x2 = maxX; + if (x2 < x1) return; + + if (ogIsBlending()) { + ogUnpack(colour, r, g, b, a); + if (a == 0) return; + if (a == 255) { + for (tmp = x1; tmp <= x2; tmp++) + RawSetPixel(tmp, y, r, g, b, a); + return; + } // if a == 255 + } // if blending + + __asm__ __volatile__("cld \n"); + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " add %%esi, %%edi \n" // add edi, esi + " inc %%ecx \n" + " shl $2, %%ebx \n" // shl ebx, 2 + " add %%ebx, %%edi \n" // add edi, ebx + " rep \n" + " stosl \n" + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (colour), "b" (x1), // %2, %3 + "c" (x2) // %4 + ); + break; + case 3: + __asm__ __volatile__( + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " add %%esi, %%edi \n" // add edi, esi + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " inc %%ecx \n" // inc ecx + " add %%edx, %%ebx \n" // add ebx, edx - pix size + " add %%ebx, %%edi \n" // add edi, ebx + " mov %%eax, %%ebx \n" // mov ebx, eax + " shr $16, %%ebx \n" // shr ebx, 16 + "hLlop24: \n" + " mov %%ax, (%%edi) \n" // mov [edi], ax + " mov %%bl, 2(%%edi)\n" // mov [edi+2], bl + " add $3, %%edi \n" // add edi, 3 + " dec %%ecx \n" // dec ecx + " jnz hLlop24 \n" + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (colour), "b" (x1), // %2, %3 + "c" (x2), "d" (x1) // %4, %5 + ); + break; + case 2: + __asm__ __volatile__( + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " inc %%ecx \n" // inc ecx + " add %%ebx, %%edi \n" // add edi, ebx + " add %%esi, %%edi \n" // add edi, esi + " xor %%edx, %%edx \n" // xor edx, edx + " mov %%ax, %%dx \n" // mov dx, ax + " shl $16, %%eax \n" // shl eax, 16 + " add %%edx, %%eax \n" // add eax, edx + + " shr $1, %%ecx \n" // shr ecx, 1 + " rep \n" + " stosl \n" + " jnc hLnoc16 \n" + " stosw \n" + "hLnoc16: \n" + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (colour), "b" (x1), // %2, %3 + "c" (x2) // %4 + ); + break; + case 1: + __asm__ __volatile__( + " add %%ebx, %%edi \n" // add edi, ebx + " add %%esi, %%edi \n" // add edi, esi + " and $0xff, %%eax \n" // and eax, 0ffh + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " mov %%al, %%ah \n" // mov ah, al + " inc %%ecx \n" // inc ecx + " mov %%eax, %%ebx \n" // mov ebx, eax + " shl $16, %%ebx \n" // shl ebx, 16 + " add %%ebx, %%eax \n" // add eax, ebx + + " mov %%ecx, %%edx \n" // mov edx, ecx + " mov $4, %%ecx \n" // mov ecx, 4 + " sub %%edi, %%ecx \n" // sub ecx, edi + " and $3, %%ecx \n" // and ecx, 3 + " sub %%ecx, %%edx \n" // sub edx, ecx + " jle LEndBytes \n" + " rep \n" + " stosb \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " and $3, %%edx \n" // and edx, 3 + " shr $2, %%ecx \n" // shr ecx, 2 + " rep \n" + " stosl \n" + "LEndBytes: \n" + " add %%edx, %%ecx \n" // add ecx, edx + " rep \n" + " stosb \n" + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (colour), "b" (x1), // %2, %3 + "c" (x2) + ); + break; + } // switch + return; +} // ogSurface::ogHLine + +bool +ogSurface::ogIsAntiAliasing(void) { + if (attributes != NULL) + return attributes->antiAlias; + else + return false; +} // ogSurface::ogIsAntiAliasing + +bool +ogSurface::ogIsBlending(void) { + if (attributes != NULL) + return attributes->blending; + else + return false; +} // ogSurface::ogIsBlending + +void +ogSurface::ogLine(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { + if (ClipLine(x1,y1,x2,y2)) { + if (ogIsAntiAliasing()) + AARawLine(x1, y1, x2, y2, colour); + else + RawLine(x1, y1, x2, y2, colour); + } // if clipLine + return; +} // ogSurface::ogLine + +bool +ogSurface::ogLoadPalette(const char *palfile) { + ogRGBA8 oldPalette[256]; +#ifdef __UBIXOS_KERNEL__ + fileDescriptor *f; +#else + FILE *f; +#endif + uInt32 lresult; + bool result; + + if (!fileExists(palfile)) { + ogSetLastError(ogFileNotFound); + return false; + } // if + + if (pal == NULL) { + pal = new ogRGBA8[256]; + if (pal == NULL) { + ogSetLastError(ogMemAllocFail); + return false; + } // if + ogSetPalette(DEFAULT_PALETTE); + // memcpy(pal, DEFAULT_PALETTE, sizeof(ogRGBA8)*256); + } // if + + ogGetPalette(oldPalette); + // memcpy(&oldPalette, pal, sizeof(ogRGBA8)*256); + + if ((f = fopen(palfile, "rb")) == NULL) return false; + + lresult = fread(pal, sizeof(ogRGBA8), 256, f); + result = (lresult == 256); + + if (!result) { + ogSetLastError(ogFileReadError); + ogSetPalette(oldPalette); + // memcpy(pal, &oldPalette, sizeof(ogRGBA8)*256); + } // if + + fclose(f); + return result; +} // ogSurface::ogLoadPalette + +void +ogSurface::ogPolygon(uInt32 numPoints, ogPoint2d* polyPoints, uInt32 colour) { + uInt32 count; + + if (numPoints == 1) + ogSetPixel(polyPoints[0].x, polyPoints[0].y, colour); + else + for (count = 0; count < numPoints; count++) + ogLine(polyPoints[count].x, polyPoints[count].y, + polyPoints[(count+1) % numPoints].x, + polyPoints[(count+1) % numPoints].y, + colour); + return; +} // ogSurface::ogPolygon + +void +ogSurface::ogRect(int32 x1, int32 y1, int32 x2, int32 y2, uInt32 colour) { + int32 tmp; + + if ((x1 == x2) || (y1 == y2)) { + + if ((x1 == x2) && (y1 == y2)) + ogSetPixel(x1, y1, colour); + else + ogLine(x1, y1, x2, y2, colour); + + } else { + + if (y1 > y2) { + tmp= y1; + y1 = y2; + y2 = tmp; + } // if + + ogHLine(x1, x2, y1, colour); // Horizline has built in clipping + ogVLine(x1, y1+1, y2-1, colour); // vertline has built in clipping too + ogVLine(x2, y1+1, y2-1, colour); + ogHLine(x1, x2, y2, colour); + + } // else + + return; +} // ogSurface::ogRect + +uInt32 +ogSurface::ogPack(uInt8 red, uInt8 green, uInt8 blue) { + uInt32 idx, colour; + uInt32 rd, gd, bd, dist, newdist; + + colour = 0; + switch (bytesPerPix) { + case 4: + colour = ( (red << redFieldPosition) | + (green << greenFieldPosition) | + (blue << blueFieldPosition) | + (ogGetAlpha() << alphaFieldPosition) ); + break; + case 3: + colour = ( (red << redFieldPosition) | + (green << greenFieldPosition) | + (blue << blueFieldPosition) ); + break; + case 2: + colour = ((red >> redShifter) << redFieldPosition) | + ((green >> greenShifter) << greenFieldPosition) | + ((blue >> blueShifter) << blueFieldPosition) | + ((ogGetAlpha() >> alphaShifter) << alphaFieldPosition); + break; + case 1: + colour = 0; + dist = 255+255+255; + for (idx = 0; idx <= 255; idx++) { + rd = abs(red-pal[idx].red); + gd = abs(green-pal[idx].green); + bd = abs(blue-pal[idx].blue); + newdist = rd + gd + bd; + + if (newdist < dist) { + dist = newdist; + colour = idx; + } // if + } // for + break; + } // switch + + return colour; + +} // ogSurface::ogPack + +uInt32 +ogSurface::ogPack(uInt8 red, uInt8 green, uInt8 blue, uInt8 alpha) { + uInt32 idx, colour; + uInt32 rd, gd, bd, dist, newdist; + + colour = 0; + switch (bytesPerPix) { + case 4: + colour = ( (red << redFieldPosition) | + (green << greenFieldPosition) | + (blue << blueFieldPosition) | + (alpha << alphaFieldPosition) ); + break; + case 3: + colour = ( (red << redFieldPosition) | + (green << greenFieldPosition) | + (blue << blueFieldPosition) ); + break; + case 2: + colour = ((red >> redShifter) << redFieldPosition) | + ((green >> greenShifter) << greenFieldPosition) | + ((blue >> blueShifter) << blueFieldPosition) | + ((alpha >> alphaShifter) << alphaFieldPosition); + break; + case 1: + colour = 0; + dist = 255+255+255; + for (idx = 0; idx <= 255; idx++) { + rd = abs(red-pal[idx].red); + gd = abs(green-pal[idx].green); + bd = abs(blue-pal[idx].blue); + newdist = rd + gd + bd; + + if (newdist < dist) { + dist = newdist; + colour = idx; + } // if + } // for + break; + } // switch + + return colour; +} // ogSurface::ogPack + +bool +ogSurface::ogSavePalette(const char *palfile) { +#ifdef __UBIXOS_KERNEL__ + fileDescriptor *f; +#else + FILE * f; +#endif + uInt32 lresult; + + if (pal == NULL) { + ogSetLastError(ogNoPalette); + return false; + } + + if ((f = fopen(palfile, "wb"))==NULL) return false; + lresult = fwrite(pal,sizeof(ogRGBA8),256,f); + fclose(f); + + if (lresult == 256) + return true; + else { + ogSetLastError(ogFileWriteError); + return false; + } // else + +} // ogSurface::ogSavePal + +void +ogSurface::ogScale(ogSurface& src) { + ogScaleBuf(0, 0, maxX, maxY, src, 0, 0, src.maxX, src.maxY); + return; +} // ogSurface::ogScale + +void +ogSurface::ogScaleBuf(int32 dX1, int32 dY1, int32 dX2, int32 dY2, + ogSurface& src, + int32 sX1, int32 sY1, int32 sX2, int32 sY2) { + + uInt32 sWidth, dWidth; + uInt32 sHeight, dHeight; + int32 sx, sy, xx, yy; + uInt32 xInc, yInc; + uInt32 origdX1, origdY1; + ogPixelFmt pixFmt; + ogSurface * tmpBuf; + ogSurface * sBuf; + ogSurface * dBuf; + bool doCopyBuf; + + origdX1 = origdY1 = 0; // to keep the compiler from generating a warning + + if (!ogAvail()) return; + if (!src.ogAvail()) return; + + if (sX1 > sX2) { + xx = sX1; + sX1= sX2; + sX2= xx; + } + + if (sY1 > sY2) { + yy = sY1; + sY1= sY2; + sY2= yy; + } + + // if any part of the source falls outside the buffer then don't do anything + + if (((uInt32)sX1 > src.maxX) || ((uInt32)sX2 > src.maxX) || + ((uInt32)sY1 > src.maxY) || ((uInt32)sY2 > src.maxY)) return; + + if (dX1 > dX2) { + xx = dX1; + dX1= dX1; + dX2= xx; + } + + if (dY1 > dY2) { + yy = dY1; + dY1= dY2; + dY2= yy; + } + + dWidth = (dX2-dX1)+1; + if (dWidth <= 0) return; + + dHeight = (dY2-dY1)+1; + if (dHeight <= 0) return; + + sWidth = (sX2-sX1)+1; + sHeight = (sY2-sY1)+1; + + // convert into 16:16 fixed point ratio + xInc = (sWidth << 16) / dWidth; + yInc = (sHeight << 16) / dHeight; + + if (dX2 > (int32)maxX) { + xx = (xInc*(dX1-maxX)) >> 16; + sX1 -= xx; + sWidth -= xx; + dWidth -= (dX1-maxX); + dX1 = maxX; + } + + if (dY2 > (int32)maxY) { + yy = (yInc*(dY2-maxY)) >> 16; + sY2 -= yy; + sHeight -= yy; + dHeight -= (dY2-maxY); + dY2 = maxY; + } + + if (dX1 < 0) { + xx = (xInc*(-dX1)) >> 16; + sX1 += xx; + sWidth -= xx; + dWidth += dX1; + dX1 = 0; + } + + if (dY1 < 0) { + yy = (yInc*(-dY1)) >> 16; + sY1 += yy; + sHeight -= yy; + dHeight += dY1; + dY1 = 0; + } + + if ((dWidth <= 0) || (dHeight <= 0)) return; + if ((sWidth <= 0) || (sHeight <= 0)) return; + + // Do a quick check to see if the scale is 1:1 .. in that case just copy + // the image + + if ((dWidth == sWidth) && (dHeight == sHeight)) { + ogCopyBuf(dX1, dY1, src, sX1, sY1, sX2, sY2); + return; + } + + tmpBuf = NULL; + + /* + * Alright.. this is how we're going to optimize the case of different + * pixel formats. We are going to use copyBuf() to automagically do + * the conversion for us using tmpBuf. Here's how it works: + * If the source buffer is smaller than the dest buffer (ie, we're making + * something bigger) we will convert the source buffer first into the dest + * buffer's pixel format. Then we do the scaling. + * If the source buffer is larger than the dest buffer (ie, we're making + * something smaller) we will scale first and then use copyBuf to do + * the conversion. + * This method puts the onus of conversion on the copyBuf() function which, + * while not excessively fast, does the job. + * The case in which the source and dest are the same size is handled above. + * + */ + if (pixFmtID != src.pixFmtID) { + + tmpBuf = new ogSurface(); + if (tmpBuf == NULL) return; + if (sWidth*sHeight*src.bytesPerPix <= dWidth*dHeight*bytesPerPix) { + // if the number of pixels in the source buffer is less than the + // number of pixels in the dest buffer then... + ogGetPixFmt(pixFmt); + if (!tmpBuf->ogCreate(sWidth, sHeight, pixFmt)) return; + tmpBuf->ogCopyPalette(src); + tmpBuf->ogCopyBuf(0, 0, src, sX1, sY1, sX2, sY2); + sX2 -= sX1; + sY2 -= sY1; + sX1 = 0; + sY1 = 0; + sBuf = tmpBuf; + dBuf = this; + doCopyBuf = false; // do we do a copyBuf later? + } else { + src.ogGetPixFmt(pixFmt); + if (!tmpBuf->ogCreate(dWidth,dHeight,pixFmt)) return; + tmpBuf->ogCopyPalette(*this); + origdX1 = dX1; + origdY1 = dY1; + dX1 = 0; + dY1 = 0; + dX2 = tmpBuf->maxX; + dY2 = tmpBuf->maxY; + sBuf = &src; + dBuf = tmpBuf; + doCopyBuf = true; + } // else + } else { + // pixel formats are identical + sBuf = &src; + dBuf = this; + doCopyBuf = false; + } // else + + sy = sY1 << 16; + + for (yy = dY1; yy <= dY2; yy++) { + sx = 0; + for (xx = dX1; xx <= dX2; xx++) { + dBuf->RawSetPixel(xx, yy, + sBuf->RawGetPixel(sX1+(sx >> 16),(sy>>16))); + sx += xInc; + } // for xx + sy += yInc; + } // for yy + + if ((doCopyBuf) && (tmpBuf != NULL)) + ogCopyBuf(origdX1, origdY1, *tmpBuf, 0, 0, tmpBuf->maxX, tmpBuf->maxY); + + delete tmpBuf; + return; +} // ogSurface::ogScaleBuf + +uInt32 +ogSurface::ogSetAlpha(uInt32 _newAlpha) { + uInt32 tmp; + + if (attributes != NULL) { + tmp = attributes->defaultAlpha; + attributes->defaultAlpha = _newAlpha; + return tmp; + } else return _newAlpha; +} // ogSurface::ogSetAlpha + +bool +ogSurface::ogSetAntiAliasing(bool _antiAliasing) { + bool tmp; + + if (attributes != NULL) { + tmp = attributes->antiAlias; + attributes->antiAlias = _antiAliasing; + return tmp; + } else return _antiAliasing; +} // ogSurface::ogSetAntiAliasing + +bool +ogSurface::ogSetBlending(bool _blending) { + bool tmp; + + if (attributes != NULL) { + tmp = attributes->blending; + attributes->blending = _blending; + return tmp; + } else return _blending; + +} // ogSurface::ogSetBlending; + +ogErrorCode +ogSurface::ogSetLastError(ogErrorCode latestError) { + ogErrorCode tmp = lastError; + lastError = latestError; + return tmp; +} // ogSurface::ogSetLastError + +void +ogSurface::ogSetPalette(const ogRGBA8 newPal[256]) { + if (pal == NULL) return; +#ifdef __UBIXOS_KERNEL__ + kmemcpy(pal, newPal, sizeof(pal)); +#else + memcpy(pal, newPal, sizeof(pal)); +#endif + return; +} // ogSurface::ogSetPalette + +void +ogSurface::ogSetPixel(int32 x, int32 y, uInt32 colour) { + uInt32 newR, newG, newB, inverseA; + uInt8 sR, sG, sB, sA; + uInt8 dR, dG, dB; + + if (!ogAvail()) return; + + if (((uInt32)x > maxX) || ((uInt32)y > maxY)) return; + + do { + if (ogIsBlending()) { + ogUnpack(colour, sR, sG, sB, sA); + if (sA == 0) return; + if (sA == 255) break; + inverseA = 255 - sA; + ogUnpack(RawGetPixel(x, y), dR, dG, dB); + newR = (dR * inverseA + sR * sA) >> 8; + newG = (dG * inverseA + sG * sA) >> 8; + newB = (dB * inverseA + sB * sA) >> 8; + colour = ogPack(newR, newG, newB, inverseA); + } // if + } while (false); + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n" // mov [edi], eax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 3: + __asm__ __volatile__( + // Calculate offset, prepare the pixel to be drawn + " leal (%%ecx, %%ecx, 2), %%ecx \n" // lea ecx, [ecx + ecx*2] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + // " mov %3, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n" // mov [edi], al + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour) // %2, %3 + ); + break; + } // switch + return; +} // ogSurface::ogSetPixel + +void +ogSurface::ogSetPixel(int32 x, int32 y, uInt8 r, uInt8 g, uInt8 b, uInt8 a) { + if (!ogAvail()) return; + if (((uInt32)x > maxX) || ((uInt32)y > maxY)) return; + RawSetPixel(x, y, r, g, b, a); + return; +} // ogSurface::ogSetPixel + +void +ogSurface::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue, uInt8 alpha) { + if (pal == NULL) return; + pal[colour].red = red; + pal[colour].green = green; + pal[colour].blue = blue; + pal[colour].alpha = alpha; + return; +} // ogSurface::ogSetPalette + +void +ogSurface::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue) { + if (pal == NULL) return; + pal[colour].red = red; + pal[colour].green = green; + pal[colour].blue = blue; + pal[colour].alpha = ogGetAlpha(); + return; +} // ogSurface::ogSetPalette + +uInt32 +ogSurface::ogSetTransparentColor(uInt32 colour) { + uInt32 tmp = 0; + + if (attributes != NULL) { + tmp = attributes->transparentColor & ogGetAlphaMasker(); + attributes->transparentColor = colour & ogGetAlphaMasker(); + } // if + + return tmp; +} // ogSurface::ogSetTransparentColor + +static double f(double g) { return g*g*g-g; } + +void +ogSurface::ogSpline(uInt32 numPoints, ogPoint2d* points, uInt32 segments, + uInt32 colour) { + int32 i, oldY, oldX, x, y, j; + float part, t, xx, yy, tmp; + float * zc; + float * dx; + float * dy; + float * u; + float * wndX1; + float * wndY1; + float * px; + float * py; + + bool runOnce; + + if ((numPoints < 2) || (points == NULL)) return; + + zc = new float[numPoints]; + dx = new float[numPoints]; + dy = new float[numPoints]; + u = new float[numPoints]; + wndX1 = new float[numPoints]; + wndY1 = new float[numPoints]; + px = new float[numPoints]; + py = new float[numPoints]; + + do { + if (zc == NULL) break; + if (dx == NULL) break; + if (dy == NULL) break; + if (wndX1 == NULL) break; + if (wndY1 == NULL) break; + if (px == NULL) break; + if (py == NULL) break; + + for (i = 0; (uInt32)i < numPoints; i++) { + zc[i] = dx[i] = dy[i] = u[i] = wndX1[i] = wndY1[i] = px[i] = py[i] = 0.0f; + } + + runOnce = false; + oldX = oldY = 0; + + x = points[0].x; + y = points[0].y; + + for (i = 1; (uInt32)i < numPoints; i++) { + xx = points[i-1].x - points[i].x; + yy = points[i-1].y - points[i].y; + t = sqrt(xx*xx + yy*yy); + zc[i] = zc[i-1]+t; + } // for + + u[0] = zc[1] - zc[0] +1; + for (i = 1; (uInt32)i < numPoints-1; i++) { + u[i] = zc[i+1]-zc[i]+1; + tmp = 2*(zc[i+1]-zc[i-1]); + dx[i] = tmp; + dy[i] = tmp; + wndY1[i] = 6.0f*((points[i+1].y-points[i].y)/u[i]- + (points[i].y-points[i-1].y)/u[i-1]); + wndX1[i] = 6.0f*((points[i+1].x-points[i].x)/u[i]- + (points[i].x-points[i-1].x)/u[i-1]); + } // for + + for (i = 1; (uInt32)i < numPoints-2; i++) { + wndY1[i+1] = wndY1[i+1]-wndY1[i]*u[i]/dy[i]; + dy[i+1] = dy[i+1]-u[i]*u[i]/dy[i]; + wndX1[i+1] = wndX1[i+1]-wndX1[i]*u[i]/dx[i]; + dx[i+1] = dx[i+1]-u[i]*u[i]/dx[i]; + } // for + + for (i = numPoints-2; i > 0; i--) { + py[i] = (wndY1[i]-u[i]*py[i+1])/dy[i]; + px[i] = (wndX1[i]-u[i]*px[i+1])/dx[i]; + } // for + + for (i = 0; (uInt32)i < numPoints-1; i++) { + for (j = 0; (uInt32)j <= segments; j++) { + part = zc[i]-(((zc[i]-zc[i+1])/segments)*j); + t = (part-zc[i])/u[i]; + part = t * points[i+1].y + + (1.0-t)*points[i].y + + u[i] * u[i] * ( f(t) * py[i+1] + f(1.0-t) * py[i]) /6.0; +// y = Round(part); + y = static_cast(part+0.5f); + part = zc[i]-(((zc[i]-zc[i+1])/segments)*j); + t = (part-zc[i])/u[i]; + part = t*points[i+1].x+(1.0-t)*points[i].x+u[i]*u[i]*(f(t)*px[i+1]+ + f(1.0-t)*px[i])/6.0; + +// x = Round(part); + x = static_cast(part+0.5f); + if (runOnce) ogLine(oldX, oldY, x, y, colour); else runOnce = true; + oldX = x; + oldY = y; + } // for j + } // for i + } while (false); + + delete [] py; + delete [] px; + delete [] wndY1; + delete [] wndX1; + delete [] u; + delete [] dy; + delete [] dx; + delete [] zc; + + return; +} // ogSurface::ogSpline + + +void +ogSurface::ogTriangle(int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, + int32 y3, uInt32 colour) { + + ogLine(x1, y1, x2, y2,colour); + ogLine(x2, y2, x3, y3,colour); + ogLine(x3, y3, x1, y1,colour); + return; +} // ogSurface::ogTriangle + +void +ogSurface::ogUnpack(uInt32 colour, uInt8& red, uInt8& green, uInt8& blue) { + + switch (bytesPerPix) { + case 4: + case 3: + red = colour >> redFieldPosition; + green = colour >> greenFieldPosition; + blue = colour >> blueFieldPosition; + break; + case 2: + red = ((colour >> redFieldPosition) << redShifter); + green = ((colour >> greenFieldPosition) << greenShifter); + blue = ((colour >> blueFieldPosition) << blueShifter); + if (red != 0) red += OG_MASKS[redShifter]; + if (green != 0) green += OG_MASKS[greenShifter]; + if (blue != 0) blue += OG_MASKS[blueShifter]; + break; + case 1: + + if (pal == NULL) { + red = green = blue = 0; + return; + } // if pal == null + + if (colour > 255) colour &= 255; + red = pal[colour].red; + green = pal[colour].green; + blue = pal[colour].blue; + break; + default: + red = 0; + green = 0; + blue = 0; + } // switch + + return; +} // ogSurface::ogUnpack + +void +ogSurface::ogUnpack(uInt32 colour, uInt8& red, uInt8& green, uInt8& blue, uInt8& alpha) { + + switch (bytesPerPix) { + case 4: + red = colour >> redFieldPosition; + green = colour >> greenFieldPosition; + blue = colour >> blueFieldPosition; + alpha = colour >> alphaFieldPosition; + break; + case 3: + red = colour >> redFieldPosition; + green = colour >> greenFieldPosition; + blue = colour >> blueFieldPosition; + alpha = ogGetAlpha(); + break; + case 2: + red = ((colour >> redFieldPosition) << redShifter); + green = ((colour >> greenFieldPosition) << greenShifter); + blue = ((colour >> blueFieldPosition) << blueShifter); + if (red != 0) red += OG_MASKS[redShifter]; + if (green != 0) green += OG_MASKS[greenShifter]; + if (blue != 0) blue += OG_MASKS[blueShifter]; + + if (alphaShifter != 8) { + alpha = (colour >> alphaFieldPosition) << alphaShifter; + if (alpha != 0) alpha += OG_MASKS[alphaShifter]; + } else alpha = ogGetAlpha(); + + break; + case 1: + + if (pal == NULL) { + red = green = blue = alpha = 0; + return; + } // if pal == null + + if (colour > 255) colour &= 255; + red = pal[colour].red; + green = pal[colour].green; + blue = pal[colour].blue; + alpha = pal[colour].alpha; + break; + default: + red = green = blue = alpha = 0; + } // switch + + return; +} // ogSurface::ogUnpack + +void +ogSurface::ogVFlip(void) { + uInt32 height; + + if (!ogAvail()) return; + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " add %%edi, %%esi \n" // add esi, edi + "vf32lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf32lop2: \n" + " mov (%%edi),%%eax \n" // mov eax, [edi] + " mov (%%esi),%%ecx \n" // mov ecx, [esi] + " mov %%eax,(%%esi) \n" // mov [esi], eax + " mov %%ecx,(%%edi) \n" // mov [edi], ecx + " add $4, %%edi \n" // add edi, 4 + " sub $4, %%esi \n" // sub esi, 4 + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf32lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " dec %%edx \n" + " jnz vf32lop \n" + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*4), // %0, %1 + "b" (xRes), "d" (maxY+1) // %2, %3 + ); + break; + case 3: + height = maxY + 1; + __asm__ __volatile__( + " add %%edi, %%esi \n" // add esi, edi + "vf24lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf24lop2: \n" + " mov (%%edi),%%ax \n" // mov ax, [edi] + " mov 2(%%edi),%%dl \n" // mov dl, [edi+2] + " mov (%%esi),%%cx \n" // mov cx, [esi] + " mov 2(%%esi),%%dh \n" // mov dh, [esi+2] + " mov %%ax,(%%esi) \n" // mov [esi], ax + " mov %%dl,2(%%esi) \n" // mov [esi+2], dl + " mov %%cx,(%%edi) \n" // mov [edi], cx + " mov %%dh,2(%%edi) \n" // mov [edi+2], dh + " add $3, %%edi \n" // add edi, 3 + " sub $3, %%esi \n" // sub esi, 3 + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf24lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " decl %3 \n" // dec height + " jnz vf24lop \n" + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*3), // %0, %1 + "b" (xRes), "m" (height) // %2, %3 + ); + break; + case 2: + __asm__ __volatile__( + " add %%edi, %%esi \n" // add esi, edi + "vf16lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf16lop2: \n" + " mov (%%edi),%%ax \n" // mov ax, [edi] + " mov (%%esi),%%cx \n" // mov cx, [esi] + " mov %%ax,(%%esi) \n" // mov [esi], ax + " mov %%cx,(%%edi) \n" // mov [edi], cx + " add $2, %%edi \n" // add edi, 2 + " sub $2, %%esi \n" // sub esi, 2 + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf16lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " dec %%edx \n" + " jnz vf16lop \n" + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*2), // %0, %1 + "b" (xRes), "d" (maxY+1) // %2, %3 + ); + break; + case 1: + __asm__ __volatile__( + " add %%edi, %%esi \n" // add esi, edi + "vf8lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf8lop2: \n" + " mov (%%edi),%%al \n" // mov al, [edi] + " mov (%%esi),%%ah \n" // mov ah, [esi] + " mov %%al,(%%esi) \n" // mov [esi], al + " mov %%ah,(%%edi) \n" // mov [edi], ah + " inc %%edi \n" // inc edi + " dec %%esi \n" // dec esi + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf8lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " dec %%edx \n" + " jnz vf8lop \n" + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX), // %0, %1 + "b" (xRes), "d" (maxY+1) // %2, %3 + ); + break; + } // switch + return; +} // ogSurface::ogVFlip + +void +ogSurface::ogVLine(int32 x, int32 y1, int32 y2, uInt32 colour) { + int32 tmp; + uInt8 r, g, b, a; + + if (!ogAvail()) return; + if ((uInt32)x > maxX) return; + + if (y1 > y2) { + tmp= y1; + y1 = y2; + y2 = tmp; + } // if + + if (y1 < 0) y1 = 0; + if (y2 > (int32)maxY) y2 = maxY; + if (y2 < y1) return; + + if (ogIsBlending()) { + + ogUnpack(colour, r, g, b, a); + + if (a == 0) return; + + if (a != 255) { + for (tmp = y1; tmp <= y2; tmp++) + RawSetPixel(x, tmp, r, g, b, a); + return; + } // if + + } // if blending + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " shl $2, %%ebx \n" // shl ebx, 2 - pix size + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " inc %%ecx \n" // inc ecx + "vLlop32: \n" + " mov %%eax, (%%edi)\n" // mov [edi], eax + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop32 \n" + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "a" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1) // %6 + ); + break; + case 3: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " mov %%ebx, %%esi \n" // mov esi, ebx - pix size + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " add %%esi, %%ebx \n" // add ebx, esi - pix size + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " inc %%ecx \n" // inc ecx + " mov %%eax, %%ebx \n" // mov ebx, eax + " shr $16, %%ebx \n" // shr ebx, 16 + "vLlop24: \n" + " mov %%ax, (%%edi) \n" // mov [edi], eax + " mov %%bl, 2(%%edi)\n" // mov [edi+2], bl + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop24 \n" + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "a" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1) // %6 + ); + break; + case 2: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " inc %%ecx \n" // inc ecx + "vLlop16: \n" + " mov %%ax, (%%edi) \n" // mov [edi], ax + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop16 \n" + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "a" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1) // %6 + ); + break; + case 1: + __asm__ __volatile__( + " add %%esi, %%edi \n" // add edi, esi + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " inc %%ecx \n" // inc ecx + "vLlop8: \n" + " mov %%al, (%%edi) \n" // mov [edi], al + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop8 \n" + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "a" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1) // %6 + ); + break; + } // switch + return; +} // ogSurface::ogVLine + +ogSurface::~ogSurface(void) { + + if (dataState == ogOwner) { + delete [] pal; + delete [] lineOfs; + delete attributes; +#ifdef __UBIXOS_KERNEL__ + kfree(buffer); +#else + free(buffer); +#endif + } // if datastate + + pal = NULL; + lineOfs= NULL; + buffer = NULL; + attributes = NULL; + bSize = 0; + lSize = 0; + dataState = ogNone; + return; +} // ogSurface::~ogSurface + + diff --git a/src/lib/objgfx40/objgfx40/defpal.inc b/src/lib/objgfx40/objgfx40/defpal.inc new file mode 100644 index 0000000..da73f83 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/defpal.inc @@ -0,0 +1,259 @@ +const + ogRGBA8 DEFAULT_PALETTE[256] = + {{0, 0, 0, 255}, // 0 + {0, 0, 170, 255}, + {0, 170, 0, 255}, + {0, 170, 170, 255}, // 3 + {170, 0, 0, 255}, + {170, 0, 170, 255}, + {170, 85, 0, 255}, + {170, 170, 170, 255}, // 7 + {85, 85, 85, 255}, + {85, 85, 255, 255}, + {85, 255, 85, 255}, + {85, 255, 255, 255}, // 11 + {255, 85, 85, 255}, + {255, 85, 255, 255}, + {255, 255, 85, 255}, + {255, 255, 255, 255}, //15 + {16, 16, 16, 255}, // 16 + {32, 32, 32, 255}, + {48, 48, 48, 255}, + {64, 64, 64, 255}, + {80, 80, 80, 255}, + {96, 96, 96, 255}, + {112, 112, 112, 255}, + {128, 128, 128, 255}, + {144, 144, 144, 255}, + {160, 160, 160, 255}, + {176, 176, 176, 255}, + {192, 192, 192, 255}, + {208, 208, 208, 255}, + {224, 224, 224, 255}, + {240, 240, 240, 255}, + {255, 255, 255, 255}, //31 + {59, 0, 0, 255}, // 32 + {79, 0, 0, 255}, + {103, 0, 0, 255}, + {123, 0, 0, 255}, + {143, 7, 7, 255}, + {167, 7, 7, 255}, + {187, 11, 11, 255}, + {211, 15, 15, 255}, + {231, 19, 19, 255}, + {255, 27, 27, 255}, + {255, 59, 59, 255}, + {255, 91, 91, 255}, + {255, 119, 119, 255}, + {255, 151, 151, 255}, + {255, 183, 183, 255}, + {255, 215, 215, 255}, + {55, 55, 0, 255}, // 48 + {71, 71, 0, 255}, + {87, 87, 0, 255}, + {103, 103, 7, 255}, + {119, 119, 7, 255}, + {135, 135, 11, 255}, + {155, 155, 19, 255}, + {171, 171, 23, 255}, + {187, 187, 31, 255}, + {203, 203, 35, 255}, + {219, 219, 43, 255}, + {239, 239, 59, 255}, + {255, 255, 63, 255}, + {255, 255, 127, 255}, + {255, 255, 187, 255}, + {255, 255, 255, 255}, + {0, 43, 0, 255}, // 64 + {0, 63, 0, 255}, + {0, 83, 0, 255}, + {0, 103, 0, 255}, + {7, 127, 7, 255}, + {7, 147, 7, 255}, + {11, 167, 11, 255}, + {15, 187, 15, 255}, + {19, 211, 19, 255}, + {27, 231, 27, 255}, + {59, 235, 59, 255}, + {91, 239, 91, 255}, + {127, 239, 127, 255}, + {159, 243, 159, 255}, + {195, 247, 195, 255}, + {231, 251, 231, 255}, + {0, 55, 55, 255}, // 80 + {0, 71, 71, 255}, + {0, 87, 87, 255}, + {7, 103, 103, 255}, + {7, 119, 119, 255}, + {11, 135, 135, 255}, + {19, 155, 155, 255}, + {23, 171, 171, 255}, + {31, 187, 187, 255}, + {35, 203, 203, 255}, + {43, 219, 219, 255}, + {51, 235, 235, 255}, + {63, 255, 255, 255}, + {127, 255, 255, 255}, + {187, 255, 255, 255}, + {255, 255, 255, 255}, + {15, 15, 55, 255}, // 96 + {19, 19, 79, 255}, + {27, 27, 103, 255}, + {31, 31, 127, 255}, + {35, 35, 155, 255}, + {39, 39, 179, 255}, + {43, 43, 203, 255}, + {47, 47, 227, 255}, + {51, 51, 255, 255}, + {71, 71, 255, 255}, + {91, 91, 255, 255}, + {111, 111, 255, 255}, + {131, 131, 255, 255}, + {151, 151, 255, 255}, + {175, 175, 255, 255}, + {195, 195, 255, 255}, + {59, 51, 59, 255}, // 112 + {79, 63, 79, 255}, + {103, 71, 103, 255}, + {123, 75, 123, 255}, + {143, 75, 143, 255}, + {167, 71, 167, 255}, + {187, 67, 187, 255}, + {211, 55, 211, 255}, + {231, 43, 231, 255}, + {255, 27, 255, 255}, + {255, 59, 255, 255}, + {255, 91, 255, 255}, + {255, 119, 255, 255}, + {255, 151, 255, 255}, + {255, 183, 255, 255}, + {255, 215, 255, 255}, + {59, 51, 59, 255}, // 128 + {71, 59, 71, 255}, + {83, 71, 83, 255}, + {95, 83, 95, 255}, + {111, 95, 111, 255}, + {123, 103, 123, 255}, + {135, 115, 135, 255}, + {147, 127, 147, 255}, + {163, 139, 163, 255}, + {175, 151, 175, 255}, + {187, 159, 187, 255}, + {203, 171, 203, 255}, + {215, 183, 215, 255}, + {227, 191, 227, 255}, + {239, 203, 239, 255}, + {255, 215, 255, 255}, + {55, 27, 27, 255}, // 144 + {71, 35, 35, 255}, + {91, 43, 43, 255}, + {107, 55, 55, 255}, + {127, 67, 67, 255}, + {143, 75, 75, 255}, + {163, 87, 87, 255}, + {179, 99, 99, 255}, + {199, 111, 111, 255}, + {203, 127, 127, 255}, + {211, 139, 139, 255}, + {219, 159, 159, 255}, + {223, 175, 175, 255}, + {231, 191, 191, 255}, + {239, 211, 211, 255}, + {247, 231, 231, 255}, + {91, 63, 27, 255}, // 160 + {111, 75, 31, 255}, + {127, 87, 39, 255}, + {147, 103, 43, 255}, + {167, 115, 51, 255}, + {187, 127, 55, 255}, + {207, 139, 63, 255}, + {227, 155, 67, 255}, + {247, 167, 75, 255}, + {247, 175, 95, 255}, + {247, 183, 119, 255}, + {247, 195, 139, 255}, + {247, 203, 159, 255}, + {247, 215, 183, 255}, + {247, 227, 203, 255}, + {251, 239, 227, 255}, + {63, 63, 31, 255}, // 176 + {75, 75, 35, 255}, + {87, 87, 43, 255}, + {99, 99, 51, 255}, + {115, 115, 55, 255}, + {127, 127, 63, 255}, + {139, 139, 67, 255}, + {151, 151, 75, 255}, + {167, 167, 83, 255}, + {175, 175, 95, 255}, + {183, 183, 107, 255}, + {191, 191, 123, 255}, + {203, 203, 139, 255}, + {211, 211, 159, 255}, + {219, 219, 175, 255}, + {231, 231, 195, 255}, + {27, 59, 47, 255}, // 192 + {31, 75, 59, 255}, + {39, 87, 67, 255}, + {47, 103, 79, 255}, + {55, 119, 91, 255}, + {59, 135, 99, 255}, + {67, 151, 111, 255}, + {71, 167, 119, 255}, + {79, 183, 127, 255}, + {87, 199, 139, 255}, + {91, 215, 147, 255}, + {99, 231, 155, 255}, + {127, 235, 183, 255}, + {163, 239, 211, 255}, + {195, 243, 231, 255}, + {231, 251, 247, 255}, + {23, 55, 55, 255}, // 208 + {31, 71, 71, 255}, + {39, 87, 87, 255}, + {47, 103, 103, 255}, + {55, 119, 119, 255}, + {67, 139, 139, 255}, + {75, 155, 155, 255}, + {87, 171, 171, 255}, + {99, 187, 187, 255}, + {111, 203, 203, 255}, + {123, 223, 223, 255}, + {143, 227, 227, 255}, + {163, 231, 231, 255}, + {183, 235, 235, 255}, + {203, 239, 239, 255}, + {227, 247, 247, 255}, + {39, 39, 79, 255}, // 224 + {47, 47, 91, 255}, + {55, 55, 107, 255}, + {63, 63, 123, 255}, + {71, 71, 139, 255}, + {79, 79, 151, 255}, + {87, 87, 167, 255}, + {99, 99, 183, 255}, + {107, 107, 199, 255}, + {123, 123, 203, 255}, + {139, 139, 211, 255}, + {155, 155, 219, 255}, + {171, 171, 223, 255}, + {187, 187, 231, 255}, + {207, 207, 239, 255}, + {227, 227, 247, 255}, + {63, 27, 63, 255}, // 240 + {75, 31, 75, 255}, + {91, 39, 91, 255}, + {103, 47, 103, 255}, + {119, 51, 119, 255}, + {131, 59, 131, 255}, + {147, 67, 147, 255}, + {163, 75, 163, 255}, + {175, 83, 175, 255}, + {191, 91, 191, 255}, + {199, 107, 199, 255}, + {207, 127, 207, 255}, + {215, 147, 215, 255}, + {223, 171, 223, 255}, + {231, 195, 231, 255}, + {243, 219, 243, 255}}; + diff --git a/src/lib/objgfx40/objgfx40/objgfx40.h b/src/lib/objgfx40/objgfx40/objgfx40.h new file mode 100644 index 0000000..3a49404 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/objgfx40.h @@ -0,0 +1,188 @@ +/************************************************************** +$Id$ +**************************************************************/ + +#ifndef OBJGFX40_H +#define OBJGFX40_H + +#include "ogTypes.h" +#include "ogPixelFmt.h" + +#ifndef __UBIXOS_KERNEL__ +#include // for NULL, true, false +#endif + +#define ogVERSION 4.0; + +class ogPixelFmt; + +extern const uInt32 OG_MASKS[32]; + +#if 0 +typedef + class ogPixelFmt { + public: + uInt8 BPP; + uInt8 redFieldPosition; + uInt8 greenFieldPosition; + uInt8 blueFieldPosition; + uInt8 alphaFieldPosition; + uInt8 redMaskSize; + uInt8 greenMaskSize; + uInt8 blueMaskSize; + uInt8 alphaMaskSize; + uInt8 reserved[7]; + ogPixelFmt(uInt8, uInt8, uInt8, uInt8, uInt8, + uInt8, uInt8, uInt8, uInt8); + virtual ~ogPixelFmt(void) {}; + }; +// Default pixel formats +const ogPixelFmt OG_NULL_PIXFMT = { 0, 0,0,0,0,0,0,0,0, {0,0,0,0,0,0}}; +const ogPixelFmt OG_PIXFMT_8BPP = { 8, 0,0,0,0,0,0,0,0, {0,0,0,0,0,0}}; +const ogPixelFmt OG_PIXFMT_15BPP = {15, 10,5,0,15,5,5,5,1, {0,0,0,0,0,0}}; +const ogPixelFmt OG_PIXFMT_16BPP = {16, 11,5,0,0,5,6,5,0, {0,0,0,0,0,0}}; +const ogPixelFmt OG_PIXFMT_24BPP = {24, 16,8,0,0,8,8,8,0, {0,0,0,0,0,0}}; +const ogPixelFmt OG_PIXFMT_32BPP = {32, 16,8,0,24,8,8,8,8, {0,0,0,0,0,0}}; +const ogPixelFmt OG_MAC_PIXFMT_16BPP = {16, 8,4,0,12,4,4,4,4, {0,0,0,0,0,0}}; +#endif + +#if 0 +class + ogAttributes(uInt32 transparentColour = 0, + uInt32 defaultAlpha = 255, + bool antiAlias = true, + bool blending = false); +#endif + +class ogAttributes { + public: + uInt32 transparentColor; + uInt32 defaultAlpha; + bool antiAlias; + bool blending; + ogAttributes():transparentColor(0), + defaultAlpha(255), + antiAlias(true), + blending(false) { } + ogAttributes & operator=( ogAttributes const & copy ) { + transparentColor = copy.transparentColor; + defaultAlpha = copy.defaultAlpha; + antiAlias = copy.antiAlias; + blending = copy.blending; + return * this; + } // operator = +}; // ogAttributes + +class ogSurface { +#ifdef __UBIXOS_KERNEL__ + public: +#else + protected: +#endif + float version; + void * buffer; + ogSurface * owner; + uInt32 * lineOfs; + ogRGBA8 * pal; + ogAttributes*attributes; + + uInt32 xRes, yRes; + uInt32 maxX, maxY; + uInt32 bSize; // buffer size (in bytes) + uInt32 lSize; // LineOfs size (in bytes) + + uInt32 BPP; // bits per pixel + uInt32 bytesPerPix; + uInt32 pixFmtID; + + uInt32 redFieldPosition; + uInt32 greenFieldPosition; + uInt32 blueFieldPosition; + uInt32 alphaFieldPosition; + + uInt32 redShifter; + uInt32 greenShifter; + uInt32 blueShifter; + uInt32 alphaShifter; + uInt32 alphaMasker; + ogErrorCode lastError; + ogDataState dataState; + + bool ClipLine(int32&, int32&, int32&, int32&); + void RawLine(uInt32, uInt32, uInt32, uInt32, uInt32); + virtual uInt32 RawGetPixel(uInt32, uInt32); + virtual void RawSetPixel(uInt32, uInt32, uInt32); + virtual void RawSetPixel(uInt32, uInt32, uInt8, uInt8, uInt8, uInt8); + void AARawLine(uInt32, uInt32, uInt32, uInt32, uInt32); + public: + ogSurface(void); + virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32); + virtual bool ogAvail(void); + void ogArc(int32, int32, uInt32, uInt32, uInt32, uInt32); + void ogBSpline(uInt32, ogPoint2d*, uInt32, uInt32); + void ogCircle(int32, int32, uInt32, uInt32); + virtual void ogClear(uInt32); + virtual bool ogClone(ogSurface&); + void ogCopy(ogSurface&); + void ogCopyBuf(int32, int32, + ogSurface&, int32, int32, int32, int32); + virtual void ogCopyLineTo(uInt32, uInt32, const void *, uInt32); + virtual void ogCopyLineFrom(uInt32, uInt32, void *, uInt32); + virtual void ogCopyPalette(ogSurface&); + virtual bool ogCreate(uInt32, uInt32, ogPixelFmt); + void ogCubicBezierCurve(int32, int32, int32, int32, + int32, int32, int32, int32, uInt32, uInt32); + void ogCurve(int32,int32, int32,int32, int32,int32, uInt32, uInt32); + void ogFillCircle(int32, int32, uInt32, uInt32); + void ogFillGouraudPolygon(uInt32, ogPoint2d*, ogRGBA8 *); + void ogFillPolygon(uInt32, ogPoint2d*, uInt32); + void ogFillRect(int32, int32, int32, int32, uInt32); + void ogFillTriangle(int32,int32, int32,int32, int32,int32, uInt32); + uInt32 ogGetAlpha(void); + uInt32 ogGetAlphaMasker(void) const { return alphaMasker; } + uInt32 ogGetBPP(void) const { return BPP; } + uInt32 ogGetBytesPerPix(void) const { return bytesPerPix; } + ogDataState ogGetDataState(void) const { return dataState; } + ogErrorCode ogGetLastError(void); + uInt32 ogGetMaxX(void) const { return maxX; } + uInt32 ogGetMaxY(void) const { return maxY; } + void ogGetPalette(ogRGBA8[]); + void ogGetPixFmt(ogPixelFmt&); + uInt32 ogGetPixFmtID(void) const { return pixFmtID; } + virtual uInt32 ogGetPixel(int32, int32); + virtual void * ogGetPtr(uInt32, uInt32); + uInt32 ogGetTransparentColor(void); + void ogHFlip(void); + virtual void ogHLine(int32, int32, int32, uInt32); + bool ogIsAntiAliasing(void); + bool ogIsBlending(void); + void ogLine(int32, int32, int32, int32, uInt32); + virtual bool ogLoadPalette(const char *); + void ogPolygon(uInt32, ogPoint2d*, uInt32); + void ogRect(int32, int32, int32, int32, uInt32); + uInt32 ogPack(uInt8, uInt8, uInt8); + uInt32 ogPack(uInt8, uInt8, uInt8, uInt8); + bool ogSavePalette(const char *); + void ogScale(ogSurface&); + void ogScaleBuf(int32, int32, int32, int32, + ogSurface&, int32, int32, int32, int32); + uInt32 ogSetAlpha(uInt32); + bool ogSetAntiAliasing(bool); + bool ogSetBlending(bool); + virtual ogErrorCode ogSetLastError(ogErrorCode); + virtual void ogSetPixel(int32, int32, uInt32); + virtual void ogSetPixel(int32, int32, uInt8, uInt8, uInt8, uInt8); + virtual void ogSetPalette(const ogRGBA8[]); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8, uInt8); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8); + uInt32 ogSetTransparentColor(uInt32); + void ogSpline(uInt32, ogPoint2d*, uInt32, uInt32); + void ogTriangle(int32, int32, int32, int32, int32, int32, uInt32); + void ogUnpack(uInt32, uInt8&, uInt8&, uInt8&); + void ogUnpack(uInt32, uInt8&, uInt8&, uInt8&, uInt8&); + virtual void ogVFlip(void); + virtual void ogVLine(int32, int32, int32, uInt32); + virtual ~ogSurface(void); +}; // ogSurface + +#endif diff --git a/src/lib/objgfx40/objgfx40/ogBlit.h b/src/lib/objgfx40/objgfx40/ogBlit.h new file mode 100644 index 0000000..5d4604d --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogBlit.h @@ -0,0 +1,29 @@ +#ifndef OGBLIT_H +#define OGBLIT_H + +#include "ogSprite.h" + +class ogBlit: public ogSprite { + protected: + uInt8 * blitMask; + uInt32 blitMaskSize; + uInt32 totalPixCount; + int32 startX, startY; + int32 endX, endY; + + void BlitSize(ogSurface&, int32, int32, int32, int32); + public: + ogBlit(void); + ogBlit(const ogBlit &, bool); + virtual void Get(ogSurface&, int32, int32, int32, int32); + void GetBlitMask(ogSurface &, int32, int32, int32, int32); + uInt32 GetBlitMaskSize(void) const { return blitMaskSize; } + void GetBlitWithMask(ogSurface&, int32, int32); + virtual uInt32 GetSize(void); + virtual bool LoadFrom(const char *, uInt32); + virtual void Put(ogSurface&, int32, int32); + virtual bool SaveTo(const char *, int32); + virtual ~ogBlit(void); +}; // ogBlit + +#endif diff --git a/src/lib/objgfx40/objgfx40/ogFont.h b/src/lib/objgfx40/objgfx40/ogFont.h new file mode 100644 index 0000000..28a53c3 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogFont.h @@ -0,0 +1,45 @@ +#ifndef OGFONT_H +#define OGFONT_H + +#include "objgfx40.h" + +enum + ogTextAlign { + leftText, + bottomText = leftText, + centerText, + rightText, + topText = rightText + }; // textAlign + +class + ogBitFont { + protected: + uInt32 fontDataIdx[256]; + uInt32 charWidthTable[256]; + uInt32 charHeightTable[256]; + uInt8 * fontData; + uInt32 fontDataSize; + ogRGBA8 BGColour; + ogRGBA8 FGColour; + uInt16 numOfChars; + uInt8 width, height; + uInt8 startingChar; + public: + ogBitFont(); + void CenterTextX(ogSurface&, int32, const char *); + uInt32 GetWidth(void) const { return width; } + uInt32 GetHeight(void) const { return height; } + void JustifyText(ogSurface&, ogTextAlign, ogTextAlign, const char *); + bool Load(const char *, uInt32); + void PutChar(ogSurface&, int32, int32, const char); + void PutString(ogSurface&, int32, int32, const char *); +// bool Save(const char *); + void SetBGColor(uInt32, uInt32, uInt32, uInt32); + void SetFGColor(uInt32, uInt32, uInt32, uInt32); + uInt32 TextHeight(const char *); + uInt32 TextWidth(const char *); + ~ogBitFont(); +}; // ogBitFont + +#endif diff --git a/src/lib/objgfx40/objgfx40/ogPixCon.h b/src/lib/objgfx40/objgfx40/ogPixCon.h new file mode 100644 index 0000000..eb794e8 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogPixCon.h @@ -0,0 +1,16 @@ +#ifndef OGPIXCON_H +#define OGPIXCON_H + +#include "objgfx40.h" + +class ogPixCon { + protected: + uInt32 srcMasker; + uInt32 srcShifter; + uInt32 dstShifter; + public: + ogPixCon(ogPixelFmt, ogPixelFmt); + uInt32 ConvPix(uInt32); +}; // ogPixCon + +#endif diff --git a/src/lib/objgfx40/objgfx40/ogPixelFmt.h b/src/lib/objgfx40/objgfx40/ogPixelFmt.h new file mode 100644 index 0000000..3ed655a --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogPixelFmt.h @@ -0,0 +1,33 @@ +#ifndef OGPIXELFMT_H +#define OGPIXELFMT_H + +#include "ogTypes.h" +#include "objgfx40.h" + +class ogPixelFmt { + public: + uInt8 BPP; + uInt8 redFieldPosition; + uInt8 greenFieldPosition; + uInt8 blueFieldPosition; + uInt8 alphaFieldPosition; + uInt8 redMaskSize; + uInt8 greenMaskSize; + uInt8 blueMaskSize; + uInt8 alphaMaskSize; + uInt8 reserved[7]; + ogPixelFmt(void); + ogPixelFmt(uInt8, uInt8, uInt8, uInt8, uInt8, + uInt8, uInt8, uInt8, uInt8); + virtual ~ogPixelFmt(void) {} +}; // ogPixelFmt + +static ogPixelFmt OG_NULL_PIXFMT = ogPixelFmt(0, 0,0,0,0, 0,0,0,0); +static ogPixelFmt OG_PIXFMT_8BPP = ogPixelFmt(8, 0,0,0,0, 0,0,0,0); +static ogPixelFmt OG_PIXFMT_15BPP = ogPixelFmt(15, 10,5,0,15, 5,5,5,1); +static ogPixelFmt OG_PIXFMT_16BPP = ogPixelFmt(16, 11,5,0,0, 5,6,5,0); +static ogPixelFmt OG_PIXFMT_24BPP = ogPixelFmt(24, 16,8,0,0, 8,8,8,0); +static ogPixelFmt OG_PIXFMT_32BPP = ogPixelFmt(32, 16,8,0,24, 8,8,8,8); +static ogPixelFmt OG_MAC_PIXFMT_16BPP = ogPixelFmt(16, 8,4,0,12, 4,4,4,4); + +#endif diff --git a/src/lib/objgfx40/objgfx40/ogSprite.h b/src/lib/objgfx40/objgfx40/ogSprite.h new file mode 100644 index 0000000..0767f40 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogSprite.h @@ -0,0 +1,44 @@ +#ifndef OGSPRITE_H +#define OGSPRITE_H + +#include "objgfx40.h" + +class ogSprite { + protected: + void * image; // image data + uInt32 imageSize; // memory size of the image pointer + ogRGBA8 * pal; // palette (used for 8bpp sprites) + uInt32 width, height; // width and height (in pixels) + uInt32 bitDepth; // make this 32-bit just for alignment purposes + uInt32 RFP; // red field position + uInt32 GFP; // green field position + uInt32 BFP; // blue field position + uInt32 AFP; // alpha field position + uInt32 rShift; // red shifter + uInt32 gShift; // green shifter + uInt32 bShift; // blue shifter + uInt32 aShift; // alpha shifter + uInt32 tColour; // original transparent colour + uInt32 pixelFmtID; // pixel format id + uInt32 bytesPerPixel; // bytes per pixel + uInt32 dAlpha; // default alpha + uInt32 GetPixel(void *); + void SetPixel(void *, uInt32); + void Unpack(uInt32, uInt8&, uInt8&, uInt8&, uInt8&); + public: + ogSprite & operator=(ogSprite const &); + ogSprite(void); + ogSprite(const ogSprite &); + void Get(ogSurface&, int32, int32, int32, int32); + uInt32 GetHeight(void) { return height; } + uInt32 GetSize(void); + uInt32 GetWidth(void) { return width; } + bool Load(const char *); + virtual bool LoadFrom(const char *, uInt32); + virtual void Put(ogSurface&, int32, int32); + bool Save(const char *); + virtual bool SaveTo(const char *, int32); + virtual ~ogSprite(void); + +}; // ogSprite +#endif diff --git a/src/lib/objgfx40/objgfx40/ogTypes.h b/src/lib/objgfx40/objgfx40/ogTypes.h new file mode 100644 index 0000000..952e6d6 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/ogTypes.h @@ -0,0 +1,90 @@ +#ifndef OGTYPES_H +#define OGTYPES_H + +typedef signed char int8; +typedef signed short int int16; +typedef signed long int int32; +typedef signed long long int int64; +typedef unsigned char uInt8; +typedef unsigned short int uInt16; +typedef unsigned int uInt32; +typedef unsigned long long int uInt64; + +enum ogDataState { ogNone, ogOwner, ogAliasing }; + +enum ogErrorCode { + ogOK, + ogMemAllocFail, + ogAlreadyOwner, + ogNoSurface, + ogNoPalette, + ogBadBPP, + ogSourceOutOfBounds, + ogDestOutOfBounds, + ogFileNotFound, + ogFileReadError, + ogFileWriteError, + ogNoCloning, + ogNoAliasing, + ogNoModeSupport +}; // ogErrorCode + +class ogRGB8 { + public: + uInt8 red; + uInt8 green; + uInt8 blue; +}; + +class ogRGBA8 { + public: + uInt8 red; + uInt8 green; + uInt8 blue; + uInt8 alpha; +}; + +class ogRGB16 { + public: + uInt16 red; + uInt16 blue; + uInt16 green; +}; + +class ogRGBA16 { + public: + uInt16 red; + uInt16 green; + uInt16 blue; + uInt16 alpha; +}; + +class ogRGB32 { + public: + uInt32 red; + uInt32 green; + uInt32 blue; +}; + +class ogRGBA32 { + public: + uInt32 red; + uInt32 green; + uInt32 blue; + uInt32 alpha; +}; + +class ogPoint2d { + public: + int32 x; + int32 y; +}; + +class ogPoint3d { + public: + int32 x; + int32 y; + int32 z; +}; + +#endif diff --git a/src/lib/objgfx40/objgfx40/vWidget.h b/src/lib/objgfx40/objgfx40/vWidget.h new file mode 100644 index 0000000..26dcada --- /dev/null +++ b/src/lib/objgfx40/objgfx40/vWidget.h @@ -0,0 +1,17 @@ +#ifndef VWIDGET_H +#define VWIDGET_H + +#include + +class vWidget : public ogSurface { + protected: + bool active; + public: + vWidget(void) { active = true; } + virtual void vDraw(void) = 0; + virtual bool vGetActive(void) const { return active; } + virtual bool vSetActive(bool); + virtual bool vCreate(void) = 0; +}; + +#endif diff --git a/src/lib/objgfx40/objgfx40/vWindow.h b/src/lib/objgfx40/objgfx40/vWindow.h new file mode 100644 index 0000000..3865603 --- /dev/null +++ b/src/lib/objgfx40/objgfx40/vWindow.h @@ -0,0 +1,19 @@ +#ifndef VWINDOW_H +#define VWINDOW_H + +#include +#include +#include + +class vWindow : public vWidget { + protected: + ogSurface * realWindow; + ogBitFont * titleFont; + public: + vWindow(void); + virtual void vDraw(void) { return; } + virtual bool vCreate(void); + void vSDECommand(uInt32); + virtual ~vWindow(void); +}; +#endif diff --git a/src/lib/objgfx40/ogBlit.cpp b/src/lib/objgfx40/ogBlit.cpp new file mode 100644 index 0000000..4de049c --- /dev/null +++ b/src/lib/objgfx40/ogBlit.cpp @@ -0,0 +1,851 @@ +extern "C" { + #include + #include + #include + } +#include +#include + +using namespace std; + +static bool +fileExists(const char *file) +{ + FILE *f = fopen(file, "rb"); + if (!f) + return false; + fclose(f); + return true; +} + +ogBlit::ogBlit(ogBlit const & srcBlit, bool doFullCopy = false) : ogSprite() { + + // horrible horrible hack. This is required because I can't have + // two constructors with the same parameter list like I can in pascal. + + // -- begin hack -- + if (doFullCopy) ogSprite::operator=(srcBlit); + // -- end hack -- + + startX = srcBlit.startX; + startY = srcBlit.startY; + endX = srcBlit.endX; + endY = srcBlit.endY; + + totalPixCount = srcBlit.totalPixCount; + blitMaskSize = srcBlit.blitMaskSize; + + blitMask = NULL; + + if (blitMaskSize != 0) { + blitMask = new uInt8[blitMaskSize]; + if ((blitMask != NULL) && (srcBlit.blitMask != NULL)) + memcpy(blitMask, srcBlit.blitMask, blitMaskSize); + } // if + return; +} // ogBlit::ogBlit + +ogBlit::ogBlit(void) : ogSprite() { + blitMask = NULL; + blitMaskSize = 0; + totalPixCount = 0; + startX = 0; + startY = 0; + endX = 0; + endY = 0; + return; +} // ogBlit::ogBlit + +void +ogBlit::BlitSize(ogSurface& src, int32 x1, int32 y1, int32 x2, int32 y2) { + uInt32 aMask; + int32 x,y; + uInt8 zerocount; + uInt8 pixcount; + + bool inZeros; + bool found; + + // first free the image data or the blitMask data if we already have some + + free(image); + delete [] blitMask; + + image = NULL; + blitMask = NULL; + imageSize = 0; + blitMaskSize = 0; + + aMask = src.ogGetAlphaMasker(); + tColour = src.ogGetTransparentColor(); + + startX = x1; + startY = y1; + endX = x2; + endY = y2; + + // start by locating the left-most non-transparent pixel in the region defined + // by (x1,y1) to (x2,y2) + + found = false; + while ((!found) && (startX <= x2)) { + for (y = y1; y <= y2; y++) + found |= ((src.ogGetPixel(startX, y) & aMask) != tColour); + if (!found) ++startX; + } // while + + // now we look for the top-most non-transparent pixel in the regsion + // defined by (startX,y1) to (x2,y2) + + found = false; + while ((!found) && (startY <= y2)) { + for (x = startX; x <= x2; x++) + found |= ((src.ogGetPixel(x,startY) & aMask) != tColour); + if (!found) ++startY; + } // while + + found = false; + while ((!found) && (endX >= startX)) { + for (y = startY; y <= y2; y++) + found |= ((src.ogGetPixel(endX,y) & aMask) != tColour); + if (!found) --endX; + } // while + + found = false; + while ((!found) && (endY >= startY)) { + for (x = startX; x <= endX; x++) + found |= ((src.ogGetPixel(x,endY) & aMask) != tColour); + if (!found) --endY; + } // while + + for (y = startY; y <= endY; y++) { + zerocount = 0; + blitMaskSize++; // save room for xlcount + x = startX; + inZeros = ((src.ogGetPixel(x,y) & aMask) == tColour); + + while (x <= endX) { + switch (inZeros) { + case true: + zerocount = 0; // How many zeros? + + while ((x <= endX) && ((src.ogGetPixel(x,y) & aMask) == tColour)) { + ++x; + + if (zerocount == 255) { + zerocount = 0; + blitMaskSize += 2; + } else ++zerocount; + } // while + + inZeros = false; + break; // case true + + case false: + pixcount = 0; + blitMaskSize += 2; + do { + ++x; + + if (pixcount == 255) { + blitMaskSize += 2; + pixcount = 0; + } else ++pixcount; + + ++totalPixCount; + //mjikaboom imageSize += bm; + } while ((x <= endX) && ((src.ogGetPixel(x,y) & aMask) != tColour)); + inZeros = true; + break; // case false + } // switch + } // while + } // for + + startX -= x1; + startY -= y1; + endX -= x1; + endY -= y1; + + blitMask = new uInt8[blitMaskSize]; //(uInt8 *)malloc(blitMaskSize); +// memset(blitMask,0,blitMaskSize); + return; +} // ogBlit::BlitSize + +void +ogBlit::GetBlitMask(ogSurface& src, int32 x1, int32 y1, + int32 x2, int32 y2) { + + uInt8 * blitMaskPtr; + uInt8 * lineCountPtr; + int32 x, y; + bool inZeros; + uInt8 pixCount, zeroCount; + uInt32 aMask; + uInt32 tmp; + + if (x1 > x2) { + tmp = x1; + x1 = x2; + x2 = tmp; + } // if + + if (y1 > y2) { + tmp = y1; + y1 = y2; + y2 = tmp; + } // if + + // calculate the width/height + + width = (x2 - x1)+1; + height = (y2 - y1)+1; + + bytesPerPixel = src.ogGetBytesPerPix(); + + if (bytesPerPixel == 1) { + if (pal != NULL) pal = new ogRGBA8[256]; + // note that tPal will check for null, so this check may be unnecessary + if (pal != NULL) src.ogGetPalette(pal); +/* for (tmp = 0; tmp < 256; tmp++) + src.Unpack(tmp, + pal[tmp].red, + pal[tmp].green, + pal[tmp].blue, + pal[tmp].alpha); */ + } // if + + // compute the size of the blit mask and allocate memory for it + + BlitSize(src, x1, y1, x2, y2); + + if (blitMask == NULL) return; + + blitMaskPtr = blitMask; + aMask = src.ogGetAlphaMasker(); + tColour = src.ogGetTransparentColor(); + + for (y = y1+startY; y <= y1+endY; y++) { + zeroCount = 0; + lineCountPtr = blitMaskPtr; + *lineCountPtr = 0; + ++blitMaskPtr; + x = x1+startX; + inZeros = ((src.ogGetPixel(x,y) & aMask) == tColour); + + while (x <= x1+endX) { + switch (inZeros) { + case true: + zeroCount = 0; + while ((x <= x1+endX) && ((src.ogGetPixel(x,y) & aMask) == tColour)) { + ++x; + if (zeroCount == 255) { + ++(*lineCountPtr); + *blitMaskPtr = 255; // offset + ++blitMaskPtr; // increment to next byte + *blitMaskPtr = 0; // runcount + ++blitMaskPtr; // increment to next byte + *blitMaskPtr = 0; // offset + zeroCount = 0; + } else ++zeroCount; + } // while + + inZeros = false; // we are no longer in zeros + break; // case true + + case false: + ++(*lineCountPtr); + *blitMaskPtr = zeroCount; + ++blitMaskPtr; + *blitMaskPtr = 0; + pixCount = 0; + + do { + ++x; + + if (pixCount == 255) { + ++(*lineCountPtr); + *blitMaskPtr = 255; // runcount + ++blitMaskPtr; // advance pointer + *blitMaskPtr = 0; // offset to next run + ++blitMaskPtr; // advance pointer + *blitMaskPtr = 0; // next run count (incremented below) + pixCount = 0; + } else ++pixCount; + + ++(*blitMaskPtr); + + } while ((x <= (x1+endX)) && + ((src.ogGetPixel(x,y) & aMask) != tColour)); + ++blitMaskPtr; + inZeros = true; // set inZeros to true to toggle + break; // case false + } // switch + } // while + } // for y + return; +} // ogBlit::GetBlitMask + +void +ogBlit::Get(ogSurface& src, int32 x1, int32 y1, int32 x2, int32 y2) { + int32 tmp; + + if (x1 > x2) { + tmp = x1; + x1 = x2; + x2 = tmp; + } // if + + if (y1 > y2) { + tmp = y1; + y1 = y2; + y2 = tmp; + } // if + + // get the blit mask + GetBlitMask(src, x1, y1, x2, y2); + + // now get the actual blit using the blit mask + GetBlitWithMask(src, x1, y1); + + return; +} // ogBlit::Get + +void +ogBlit::GetBlitWithMask(ogSurface & src, int32 x, int32 y) { + /* + * getBlitWithMask + * + * Retrieves the data portion of a blit using a predefined mask and + * stores the data in the image pointer. If the source buffer is + * a different pixel format, we will adjust the image pointer + * to accommodate the new data and update the pixel format. The put() + * function will adjust the pixels to the dest buffer as needed. + * Before calling this routine, you must call getBlitMask. + */ + + int32 sx, sy; + uInt8 lineCount, offset, pixCount; + uInt32 nsy, ney; + uInt8 *blitMaskPtr; + void *imagePtr; + uInt32 distToEdge, xRight, count; + ogPixelFmt pixFmt; + + if (blitMask == NULL) return; + + if ( (x + startX > (int32)src.ogGetMaxX()) || (x + endX < 0) || + (y + startY > (int32)src.ogGetMaxY()) || (y + endY < 0)) return; + + blitMaskPtr = blitMask; + + // First check to see if the pixel format we got the blitmask from + // is different than what we're dealing with now + // note that the first time through pixelFmtID will be 0, so this + // will get that information + + if (src.ogGetPixFmtID() != pixelFmtID) { + free(image); + image = NULL; + imageSize = 0; + + src.ogGetPixFmt(pixFmt); + + bitDepth = pixFmt.BPP; + RFP = pixFmt.redFieldPosition; + GFP = pixFmt.greenFieldPosition; + BFP = pixFmt.blueFieldPosition; + AFP = pixFmt.alphaFieldPosition; + rShift = 8-pixFmt.redMaskSize; + gShift = 8-pixFmt.greenMaskSize; + bShift = 8-pixFmt.blueMaskSize; + aShift = 8-pixFmt.alphaMaskSize; + + bytesPerPixel = src.ogGetBytesPerPix(); + pixelFmtID = src.ogGetPixFmtID(); + dAlpha = src.ogGetAlpha(); + // tColour = src.ogGetTransparentColor(); // done elsewhere + + } // if + + if (image == NULL) { + imageSize = totalPixCount * bytesPerPixel; + image = malloc(imageSize); + } // if + + imagePtr = image; + // If any part of the blit data is out of bounds, we need to fill it with the + // transparent colour + if ( (x + startX < 0) || (x + endX > (int32)src.ogGetMaxX()) || + (y + startY < 0) || (y + endY > (int32)src.ogGetMaxY())) { + for (count = 0; count < totalPixCount; count++) { + SetPixel(imagePtr, tColour); + (uInt8 *)imagePtr += bytesPerPixel; + } // for count + imagePtr = image; // reset the image pointer + } // if + + // first do clipping on the top edge + nsy = startY; + if (y+startY < 0) { + /* + * If we're here then part of the blit is above the top edge of the + * buffer. The distance to the top of the buffer is abs(y+startY). + * So, we need to loop through the blit geometry and advance the + * relative pointers (BlitMaskPtr and ImagePtr) + */ + for (sy = (y+startY); sy<0; sy++) { + ++nsy; + lineCount = *blitMaskPtr; + ++blitMaskPtr; + while (lineCount > 0) { + ++blitMaskPtr; + pixCount = *blitMaskPtr; + ++blitMaskPtr; + if (pixCount > 0) (uInt8 *)imagePtr += pixCount*bytesPerPixel; + --lineCount; + } // while + } // for sy + } // if + + // Now do clipping on the bottom edge. This is easy. + if (y+endY > (int32)src.ogGetMaxY()) + ney = (src.ogGetMaxY()-y); + else + ney = endY; + + for (sy = nsy; (uInt32)sy <= ney; sy++) { + sx = x+startX; + lineCount = *blitMaskPtr; + ++blitMaskPtr; + + while (lineCount > 0) { + offset = *blitMaskPtr; + ++blitMaskPtr; + sx += offset; + pixCount = *blitMaskPtr; + ++blitMaskPtr; + + if (pixCount > 0) { + if (sx <= (int32)src.ogGetMaxX()) { + if ((sx < 0) && (sx+pixCount > 0)) { + pixCount += sx; // remember, sx is negative + (uInt8*)imagePtr -= sx*bytesPerPixel; // remember, sx is negative + sx = 0; + } // if sx<0 && sx+pixcount>0 + + if (sx+pixCount > (int32)src.ogGetMaxX()+1) { + distToEdge = (src.ogGetMaxX()-sx)+1; + xRight = (pixCount - distToEdge)*bytesPerPixel; + pixCount = distToEdge; + } else xRight = 0; // if sx+pixCount>MaxX + + if (sx >= 0) + src.ogCopyLineFrom(sx, y+sy, imagePtr, pixCount*bytesPerPixel); + + (uInt8*)imagePtr += xRight; // get any remainter from right edge clip + } // if sx <= MaxX + + sx += pixCount; + (uInt8*)imagePtr += pixCount*bytesPerPixel; + + } // if pixCount>0 + --lineCount; + } // while + } // for + + return; +} // ogBlit::GetBlitWithMask + +uInt32 +ogBlit::GetSize(void) { + return ogSprite::GetSize() + + sizeof(totalPixCount) + + sizeof(blitMaskSize) + + blitMaskSize + + sizeof(startX) + + sizeof(startY) + + sizeof(endX) + + sizeof(endY); +} // ogBlit::GetSize + +bool +ogBlit::LoadFrom(const char * filename, uInt32 offset) { + FILE * infile; + uInt32 lresult, tresult, totSize; + uInt32 tmpSize; + char headerIdent[4]; + + if (!fileExists(filename)) return false; + if ((infile = fopen(filename,"rb")) == NULL) return false; + fseek(infile, offset, SEEK_SET); + + // for now just free up the previous image. This will be changed + // later so it doesn't affect the current image (if any) if there + // is a failure loading + + free(image); + delete [] pal; + delete [] blitMask; + imageSize = 0; + blitMaskSize = 0; + + tresult = 0; // total bytes we've read in so far + + lresult = fread(headerIdent, sizeof(headerIdent), 1, infile); + tresult += lresult*sizeof(headerIdent); + if ((headerIdent[0] != 'B') || + (headerIdent[1] != 'L') || + (headerIdent[2] != 'T') || + (headerIdent[3] != (uInt8)0x1A)) { + fclose(infile); + return false; + } + lresult = fread(&totSize, sizeof(totSize), 1, infile); + tresult += lresult*sizeof(totSize); + + lresult = fread(&width, sizeof(width), 1, infile); + tresult += lresult*sizeof(width); + + lresult = fread(&height, sizeof(height), 1, infile); + tresult += lresult*sizeof(height); + + lresult = fread(&bitDepth, sizeof(bitDepth), 1, infile); + tresult += lresult*sizeof(bitDepth); + + lresult = fread(&RFP, sizeof(RFP), 1, infile); + tresult += lresult*sizeof(RFP); + + lresult = fread(&GFP, sizeof(GFP), 1, infile); + tresult += lresult*sizeof(GFP); + + lresult = fread(&BFP, sizeof(BFP), 1, infile); + tresult += lresult*sizeof(BFP); + + lresult = fread(&AFP, sizeof(AFP), 1, infile); + tresult += lresult*sizeof(AFP); + + lresult = fread(&rShift, sizeof(rShift), 1, infile); + tresult += lresult*sizeof(rShift); + + lresult = fread(&gShift, sizeof(gShift), 1, infile); + tresult += lresult*sizeof(gShift); + + lresult = fread(&bShift, sizeof(bShift), 1, infile); + tresult += lresult*sizeof(bShift); + + lresult = fread(&aShift, sizeof(aShift), 1, infile); + tresult += lresult*sizeof(aShift); + + lresult = fread(&tColour, sizeof(tColour), 1, infile); + tresult += lresult*sizeof(tColour); + + lresult = fread(&pixelFmtID, sizeof(pixelFmtID), 1, infile); + tresult += lresult*sizeof(pixelFmtID); + + lresult = fread(&bytesPerPixel, sizeof(bytesPerPixel), 1, infile); + tresult += lresult*sizeof(bytesPerPixel); + + lresult = fread(&dAlpha, sizeof(dAlpha), 1, infile); + tresult += lresult*sizeof(dAlpha); + + lresult = fread(&totalPixCount, sizeof(totalPixCount), 1, infile); + tresult += lresult*sizeof(totalPixCount); + + lresult = fread(&startX, sizeof(startX), 1, infile); + tresult += lresult*sizeof(startX); + + lresult = fread(&startY, sizeof(startY), 1, infile); + tresult += lresult*sizeof(startY); + + lresult = fread(&endX, sizeof(endX), 1, infile); + tresult += lresult*sizeof(endX); + + lresult = fread(&endY, sizeof(endY), 1, infile); + tresult += lresult*sizeof(endY); + + lresult = fread(&blitMaskSize, sizeof(blitMaskSize), 1, infile); + tresult += lresult*sizeof(blitMaskSize); + + lresult = fread(&imageSize, sizeof(imageSize), 1, infile); + tresult += lresult*sizeof(imageSize); + + blitMask = new uInt8[blitMaskSize]; + if (blitMask == NULL) { + fclose(infile); + return false; + } + + image = malloc(imageSize); + if (image == NULL) { + fclose(infile); + return false; + } + + // read in the blit mask + lresult = fread(blitMask, blitMaskSize, 1, infile); + tresult += lresult*blitMaskSize; + + // read in the image data + // it's possible that if we start saving only blit masks this section will be + // blank + lresult = fread(image, 1, imageSize, infile); + tresult += lresult; + + if (bitDepth == 8) { + // 8bpp sprites have palettes + if (pal == NULL) pal = new ogRGBA8[256]; + if (pal == NULL) { + fclose(infile); + return false; + } // if pal==NULL + lresult = fread(&tmpSize, sizeof(tmpSize), 1, infile); + tresult += lresult*sizeof(tmpSize); + + if (tmpSize > sizeof(ogRGBA8)*256) { + fclose(infile); + return false; + } + lresult = fread(pal, tmpSize, 1, infile); + tresult += lresult*tmpSize; + } // if bitDepth == 8 + + fclose(infile); + return (tresult == totSize); +} // ogBlit::LoadFrom + +void +ogBlit::Put(ogSurface& dest, int32 x, int32 y) { + int32 sx, sy; + uInt32 nsy, ney; + uInt8 lineCount, offset, pixCount; + uInt8* blitMaskPtr; + void * imagePtr; + uInt32 distToEdge, xRight, xx; + uInt8 r, g, b, a; + ogPixelFmt pixFmt; + + // can we draw anything? + if ((blitMask == NULL) || (image == NULL)) return; + + if (!dest.ogAvail()) return; + + // see if the blit is oustide the buffer + if ( ((x+startX) > (int32)dest.ogGetMaxX()) || ((x + endX) < 0) || + ((y+startY) > (int32)dest.ogGetMaxY()) || ((y + endY) < 0) ) return; + + blitMaskPtr = blitMask; + imagePtr = image; + + // first do clipping on the top edge + nsy = startY; + if (y+startY < 0) { + /* + * If we're here then part of the blit is above the top edge of the + * buffer. The distance to the top of the buffer is abs(y+startY). + * So, we need to loop through the blit geometry and advance the + * relative pointers (blitMaskPtr and imagePtr) + */ + for (sy = (y+startY); sy < 0; sy++) { + ++nsy; + lineCount = *blitMaskPtr; + ++blitMaskPtr; + + while (lineCount > 0) { + ++blitMaskPtr; + pixCount = *blitMaskPtr; + ++blitMaskPtr; + if (pixCount > 0) (uInt8 *)imagePtr += pixCount*bytesPerPixel; + --lineCount; + } // while + } // for sy + } // if + + // Now do clipping on the bottom edge. This is easy + // y is guaranteed to be >=0 + // I'm going to contradict myself and say that I don't think y is + // guaranteed to be >= 0. + + if (y+endY > (int32)dest.ogGetMaxY()) + ney = (dest.ogGetMaxY()-y); + else + ney = endY; + + dest.ogGetPixFmt(pixFmt); + + if ((dest.ogGetPixFmtID() != pixelFmtID) || (dest.ogIsBlending())) { + for (sy = nsy; (uInt32)sy <= ney; sy++) { + sx = x+startX; + lineCount = *blitMaskPtr; + ++blitMaskPtr; + while (lineCount > 0) { + offset = *blitMaskPtr; + ++blitMaskPtr; + sx += offset; + pixCount = *blitMaskPtr; + ++blitMaskPtr; + + if (pixCount > 0) { + if (sx <= (int32)dest.ogGetMaxX()) { + + if ((sx < 0) && (sx+(int32)pixCount > 0)) { + pixCount += sx; // remember, sx is negative + (uInt8*)imagePtr -= sx*bytesPerPixel; // remember, sx is negative + sx = 0; + } // if sx<0 && sx+pixCount>0 + + if (sx+pixCount > (int32)dest.ogGetMaxX()) { + distToEdge = (dest.ogGetMaxX()-sx)+1; + xRight = (pixCount-distToEdge)*bytesPerPixel; + pixCount = distToEdge; + } else xRight = 0; // if sx+pixCount>MaxX + + if (sx >= 0) + for (xx = 0; xx < pixCount; xx++) { + Unpack(GetPixel((uInt8*)imagePtr+(xx*bytesPerPixel)), + r, g, b, a); + dest.ogSetPixel(sx+xx, sy+y, r, g, b, a); + } // for + (uInt8*)imagePtr += xRight; + } // if sx <= maxX + sx += pixCount; + (uInt8*)imagePtr += pixCount*bytesPerPixel; + } // if pixCount != 0 + --lineCount; + } // while + } // for + } else { + for (sy = nsy; (uInt32)sy <= ney; sy++) { + sx = x+startX; + lineCount = *blitMaskPtr; + ++blitMaskPtr; + + while (lineCount > 0) { + offset = *blitMaskPtr; + ++blitMaskPtr; + sx += offset; + pixCount = *blitMaskPtr; + ++blitMaskPtr; + + if (pixCount > 0) { + if (sx <= (int32)dest.ogGetMaxX()) { + if ((sx < 0) && (sx+pixCount > 0)) { + pixCount += sx; // remember, sx is negative + (uInt8*)imagePtr -= sx*bytesPerPixel; // remember, sx is negative + sx = 0; + } // if sx<0 && sx+pixCount>0 + + if (sx+pixCount > (int32)dest.ogGetMaxX()+1) { + distToEdge = (dest.ogGetMaxX()-sx)+1; + xRight = (pixCount - distToEdge)*bytesPerPixel; + pixCount = distToEdge; + } else xRight = 0; // if sx+pixCount>MaxX + + if (sx >= 0) + dest.ogCopyLineTo(sx, y+sy, imagePtr, pixCount*bytesPerPixel); + (uInt8*)imagePtr += xRight; + } // if sx <= MaxX + sx += pixCount; + (uInt8*)imagePtr += pixCount*bytesPerPixel; + } // if pixCount>0 + --lineCount; + } // while + } // for + } // else + + return; +} // ogBlit::Put + +bool +ogBlit::SaveTo(const char * filename, int32 offset) { + /* + * saveTo + * + * saves a blit to disk. If the file doesn't exit then we will create + * a new one (doing this will ignore any specified offset). If the file + * exists, we will seek to the specified offset and place the bitmap there. + * If offset is -1, then we seek to the end of the file. + * + * This function will fail on files larger than 2GB. + * + */ + FILE * outfile = NULL; + char headerIdent[4]; + uInt32 tmpSize; + + if (image == NULL) return false; + if ((bitDepth == 8) && (pal == NULL)) return false; + + if (!fileExists(filename)) { // file doesn't exist + if ((outfile = fopen(filename,"wb")) == NULL) return false; + } else { + // file exists. Now we check to see where we put it + if (offset==-1) { + if ((outfile = fopen(filename, "ab")) == NULL) return false; + } else { + // we have an existing file and an offset to place the data + if ((outfile = fopen(filename, "wb")) == NULL) return false; + if (offset != 0) fseek(outfile, offset, SEEK_SET); + } // else + } // else + + tmpSize = GetSize(); + + headerIdent[0] = 'B'; + headerIdent[1] = 'L'; + headerIdent[2] = 'T'; + headerIdent[3] = (uInt8)0x1A; // EOF marker + + // we store exactly how bit this sucker is inside the header. This includes + // the header information before it, and the size itself + fwrite(headerIdent, sizeof(headerIdent), 1, outfile); + + fwrite(&tmpSize, sizeof(tmpSize), 1, outfile); + fwrite(&width, sizeof(width), 1, outfile); + fwrite(&height, sizeof(height), 1, outfile); + fwrite(&bitDepth, sizeof(bitDepth), 1, outfile); + + fwrite(&RFP, sizeof(RFP), 1, outfile); + fwrite(&GFP, sizeof(GFP), 1, outfile); + fwrite(&BFP, sizeof(BFP), 1, outfile); + fwrite(&AFP, sizeof(AFP), 1, outfile); + + fwrite(&rShift, sizeof(rShift), 1, outfile); + fwrite(&gShift, sizeof(gShift), 1, outfile); + fwrite(&bShift, sizeof(bShift), 1, outfile); + fwrite(&aShift, sizeof(aShift), 1, outfile); + + fwrite(&tColour, sizeof(tColour), 1, outfile); + fwrite(&pixelFmtID, sizeof(pixelFmtID), 1, outfile); + fwrite(&bytesPerPixel, sizeof(bytesPerPixel), 1, outfile); + fwrite(&dAlpha, sizeof(dAlpha), 1, outfile); + + fwrite(&totalPixCount, sizeof(totalPixCount), 1, outfile); + + fwrite(&startX, sizeof(startX), 1, outfile); + fwrite(&startY, sizeof(startY), 1, outfile); + fwrite(&endX, sizeof(endX), 1, outfile); + fwrite(&endY, sizeof(endY), 1, outfile); + + fwrite(&blitMaskSize, sizeof(blitMaskSize), 1, outfile); + fwrite(&imageSize, sizeof(imageSize), 1, outfile); + + fwrite(blitMask, blitMaskSize, 1, outfile); + fwrite(image, 1, imageSize, outfile); + + if (bitDepth == 8) { + tmpSize = sizeof(ogRGBA8)*256; + fwrite(&tmpSize, sizeof(tmpSize), 1, outfile); + fwrite(pal, sizeof(ogRGBA8), 256, outfile); + } // if bitDepth == 8 + + fclose(outfile); + return true; +} // ogBlit::SaveTo + +ogBlit::~ogBlit(void) { + delete [] blitMask; + blitMask = NULL; + blitMaskSize = 0; + return; +} // ogBlit::~ogBlit + diff --git a/src/lib/objgfx40/ogDisplay_UbixOS.cc b/src/lib/objgfx40/ogDisplay_UbixOS.cc new file mode 100755 index 0000000..a13ef29 --- /dev/null +++ b/src/lib/objgfx40/ogDisplay_UbixOS.cc @@ -0,0 +1,270 @@ +#include +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include + } + +/* + * + * ogDisplay methods + * + */ + +void +initVESAMode(uInt16 mode) { + kprintf("Pre-initVESAMode\n"); + biosCall(0x10,0x4F02,mode,0x0,0x0,0x0,0x0,0x0,0x0); + kprintf("Post-initVESAMode\n"); + return; +} + +ogDisplay_UbixOS::ogDisplay_UbixOS(void) { + pages[0] = pages[1] = NULL; + activePage = visualPage = 0; + pal = new ogRGBA8[256]; + attributes = new ogAttributes(); + + VESAInfo = (ogVESAInfo *)0x11000; + modeInfo = (ogModeInfo *)0x11200; + + getVESAInfo(); + return; +} // ogDisplay_UbixOS::ogDisplay_UbixOS + +void +ogDisplay_UbixOS::GetModeInfo(uInt16 mode) { + kprintf("Pre-getModeInfo\n"); + biosCall(0x10,0x4F01,0x0,mode,0x0,0x0,0x0,0x1120,0x0); + kprintf("Post-getModeInfo\n"); + return; +} // ogDisplay_UbixOS::GetModeInfo + +void +ogDisplay_UbixOS::GetVESAInfo(void) { + VESAInfo->VBESignature[0] = 'V'; // First off initialize the structure. + VESAInfo->VBESignature[1] = 'B'; + VESAInfo->VBESignature[2] = 'E'; + VESAInfo->VBESignature[3] = '2'; + kprintf("Pre-getVESAInfo\n"); + biosCall(0x10,0x4F00,0x0,0x0,0x0,0x0,0x0,0x1100,0x0); + kprintf("Post-getVESAInfo\n"); + return; + } // ogDisplay_UbixOS::GetVESAInfo + +uInt16 +ogDisplay_UbixOS::FindMode(uInt32 _xRes, uInt32 _yRes, uInt32 _BPP) { + uInt16 mode; + + if ((_xRes == 320) && (_yRes == 200) && (_BPP == 8)) return 0x13; + +// if ((VESAInfo==NULL) || (VESAInfo->videoModePtr==NULL)) return 0; + if (modeInfo == NULL) return 0; + + for (mode = 0x100; mode < 0x1FF; mode++) { + getModeInfo(mode); + if ((modeInfo->xRes >= _xRes) && (modeInfo->yRes >= _yRes) && + (modeInfo->bitsPerPixel == _BPP)) + return mode; + } + + return 0; +} // ogDisplay_UbixOS::FindMode + +void ogDisplay_UbixOS::SetMode(uInt16 mode) { + + uInt32 size = 0x0, count = 0x0, i = 0x0; + + if (mode == 0x13) { + + xRes = 320; + yRes = 200; + maxX = 319; + maxY = 199; + BPP = 8; + bytesPerPix = 1; + + redFieldPosition = 0; + greenFieldPosition = 0; + blueFieldPosition = 0; + alphaFieldPosition = 0; + + redShifter = 0; + greenShifter = 0; + blueShifter = 0; + alphaFieldPosition = 0; + + // UBU, THIS IS NULL BECAUSE WE DON'T EVER USE 320x200x256c! + // THIS COMMENT WILL COME BACK TO BITE YOU ON THE ASS + buffer = NULL; + + } else { + buffer = NULL; + mode |= 0x4000; // attempt lfb + getModeInfo(mode); + if (modeInfo->physBasePtr == 0) return; + buffer = (void *)modeInfo->physBasePtr; + size = modeInfo->yRes*modeInfo->bytesPerLine; + + xRes = modeInfo->bytesPerLine; + yRes = modeInfo->yRes; + maxX = modeInfo->xRes-1; + maxY = yRes-1; + + BPP = modeInfo->bitsPerPixel; + bytesPerPix = (BPP + 7) >> 3; + + redFieldPosition = modeInfo->redFieldPosition; + greenFieldPosition = modeInfo->greenFieldPosition; + blueFieldPosition = modeInfo->blueFieldPosition; + alphaFieldPosition = modeInfo->alphaFieldPosition; + + if (bytesPerPix == 4) { + modeInfo->alphaMaskSize = 8; + while ((alphaFieldPosition == redFieldPosition) || + (alphaFieldPosition == greenFieldPosition) || + (alphaFieldPosition == blueFieldPosition)) + alphaFieldPosition += 8; + } // if + + redShifter = 8-modeInfo->redMaskSize; + greenShifter = 8-modeInfo->greenMaskSize; + blueShifter = 8-modeInfo->blueMaskSize; + alphaShifter = 8-modeInfo->alphaMaskSize; + + if (modeInfo->alphaMaskSize != 0) + alphaMasker = ~(OG_MASKS[modeInfo->alphaMaskSize] << alphaFieldPosition); + else + alphaMasker = ~0; + + } // else not mode 0x13 + + owner = this; + dataState = ogAliasing; + + if ((lineOfs != NULL) && (lSize != 0)) delete [] lineOfs; + lSize = yRes*sizeof(uInt32); + lineOfs = new uInt32[yRes];; + if (lineOfs == NULL) return; + + lineOfs[0] = 0; + for (count = 1; count < yRes; count++) + lineOfs[count] = lineOfs[count-1]+xRes; + + initVESAMode(mode); + + ogSetAntiAliasing(BPP > 8); + if (pal == NULL) pal = new ogRGBA8[256]; + ogSetPalette(DEFAULT_PALETTE); + + if (bytesPerPix == 1) { + pixFmtID = 0x08080808; + } else { + pixFmtID = (redFieldPosition) | + (greenFieldPosition << 8) | + (blueFieldPosition << 16) | + (alphaFieldPosition << 24); + } // else + + printOff = 0; + for (i = 0x0; i < ((size)/4096); i++) { + vmmRemapPage(modeInfo->physBasePtr + (i * 0x1000), + modeInfo->physBasePtr + (i * 0x1000)); + } // for i + return; +} // ogDisplay_UbixOS::SetMode + +void ogDisplay_UbixOS::SetPal(void) { + if (bytesPerPix != 1) return; + outportb(0x3c8,0); + for (uInt32 c = 0; c < 256; c++) { + outportb(0x3c9, pal[c].red >> 2); + outportb(0x3c9, pal[c].green >> 2); + outportb(0x3c9, pal[c].blue >> 2); + } // for + return; +} // ogDisplay_UbixOS::SetPal + +bool +ogDisplay_UbixOS::ogAlias(ogSurface& SrcObject, uInt32 x1, + uInt32 y1, uInt32 x2, uInt32 y2) { + ogSetLastError(ogNoAliasing); + return false; +} // ogDisplay_UbixOS::Alias + +bool +ogDisplay_UbixOS::ogCreate(uInt32 _xRes, uInt32 _yRes,ogPixelFmt _pixFormat) { + uInt16 mode; + mode = 0x111; + setMode(mode); + /* + mode = findMode(_xRes, _yRes, _pixFormat.BPP); + if ((mode == 0) && ((_pixFormat.BPP==24) || (_pixFormat.BPP==32))) { + if (_pixFormat.BPP==24) _pixFormat.BPP=32; else _pixFormat.BPP=24; + mode=findMode(_xRes,_yRes,_pixFormat.BPP); + } // if + if (mode!=0) setMode(mode); + */ + return (mode!=0); +} // ogDisplay_UbixOS::ogCreate + +bool +ogDisplay_UbixOS::ogClone(ogSurface& SrcObject) { + ogSetLastError(ogNoCloning); + return false; +} // ogDisplay_UbixOS::Clone + +void +ogDisplay_UbixOS::ogCopyPal(ogSurface& SrcObject) { + ogSurface::ogCopyPal(SrcObject); + SetPal(); + return; +} // ogDisplay_UbixOS::ogCopyPal + +bool +ogDisplay_UbixOS::ogLoadPalette(const char *palfile) { + bool result; + if ((result = ogSurface::LoadPalette(palfile))==true) SetPal(); + return result; +} // ogDisplay_UbixOS::ogLoadPalette + +void +ogDisplay_UbixOS::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 b +lue) { + if (pal == NULL) return; + ogSurface::ogSetRGBPalette(colour, red, green, blue); + outportb(0x3c8, colour); + outportb(0x3c9, red >> 2); + outportb(0x3c9, green >> 2); + outportb(0x3c9, blue >> 2); + + return; +} // ogDisplay_UbixOS::SetPalette + +void +ogDisplay_UbixOS::SetPalette(uInt8 colour, uInt8 red, uInt8 green, + uInt8 blue, uInt8 alpha) { + if (pal == NULL) return; + ogSurface::ogSetPalette(colour, red, green, blue, alpha); + outportb(0x3c8, colour); + outportb(0x3c9, red >> 2); + outportb(0x3c9, green >> 2); + outportb(0x3c9, blue >> 2); + + return; +} // ogDisplay_UbixOS::ogSetPalette + +ogDisplay_UbixOS::~ogDisplay_UbixOS(void) { + delete attributes; + delete [] pal; +//mji delete VESAInfo; +//mji delete modeInfo; + return; +} // ogDisplay_UbixOS::~ogDisplay_UbixOS + diff --git a/src/lib/objgfx40/ogDisplay_VESA.cpp b/src/lib/objgfx40/ogDisplay_VESA.cpp new file mode 100644 index 0000000..eaf097d --- /dev/null +++ b/src/lib/objgfx40/ogDisplay_VESA.cpp @@ -0,0 +1,1450 @@ +#include "objgfx40.h" +#include "defpal.inc" +#include "ogDisplay_VESA.h" +#include // for __tb +#include +#include +#include +#include +#include + +/* + * + * ogDisplay methods + * + */ + +void +initVESAMode(uInt16 mode) { + __dpmi_regs regs; + regs.x.ax = 0x4f02; + regs.x.bx = mode; + __dpmi_int(0x10, ®s); + return; +} + +ogDisplay_VESA::ogDisplay_VESA(void) : ogSurface() { + pages[0] = pages[1] = NULL; + activePage = visualPage = 0; + inGraphics = false; + VESAInfo = new ogVESAInfo; + modeInfo = new ogModeInfo; + pal = new ogRGBA8[256]; + attributes = new ogAttributes(); + + GetVESAInfo(); + + screenSelector = __dpmi_allocate_ldt_descriptors(1); + + return; +} // ogDisplay_VESA::ogDisplay_VESA + +uInt32 +ogDisplay_VESA::RawGetPixel(uInt32 x, uInt32 y) { + uInt32 result; + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx*4] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " mov (%%edi),%%eax \n" // eax,word ptr [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + case 3: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size + " add %%ecx, %%ecx \n" // add ecx, ecx - adjust for pixel size + " add %%eax, %%ecx \n" // add ecx, eax - adjust for pixel size + " add %%esi, %%edi \n" // add edi, esi + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx*4] + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] + " xor %%eax, %%eax \n" + " mov 2(%%edi), %%al \n" // mov al, [edi+2] + " shl $16, %%eax \n" // shl eax, 16 + " mov (%%edi), %%ax \n" // mov ax, [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + case 2: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + case 1: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " movzbl (%%edi),%%eax \n" // movzx edx,byte ptr [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + } // switch + return result; +} // ogDisplay_VESA::RawGetPixel + +void +ogDisplay_VESA::RawSetPixel(uInt32 x, uInt32 y, uInt32 colour) { + uInt32 newR, newG, newB, inverseA; + uInt8 sR, sG, sB, sA; + uInt8 dR, dG, dB; + + do { + if (ogIsBlending()) { + ogUnpack(colour, sR, sG, sB, sA); + if (sA == 0) return; + if (sA == 255) break; + inverseA = 255 - sA; + ogUnpack(RawGetPixel(x, y), dR, dG, dB); + newR = (dR * inverseA + sR * sA) >> 8; + newG = (dG * inverseA + sG * sA) >> 8; + newB = (dB * inverseA + sB * sA) >> 8; + colour = ogPack(newR, newG, newB, inverseA); + } // if + } while (false); + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + + " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n" // mov [edi], eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + case 3: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4),%%edi \n" // add edi, [esi + ebx * 4] + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add edi, ecx {adjust for pixel size} + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], al + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n" // mov [edi], al + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + } // switch + return; +} // ogDisplay_VESA::RawSetPixel + +void +ogDisplay_VESA::RawSetPixel(uInt32 x, uInt32 y, uInt8 r, uInt8 g, uInt8 b, uInt8 a) { + uInt32 newR, newG, newB, inverseA; + uInt8 dR, dG, dB; + uInt32 colour; + + do { + if (ogIsBlending()) { + if (a == 0) return; + if (a == 255) { + colour = ogPack(r, g, b, a); + break; + } // if a == 255 + + inverseA = 255 - a; + ogUnpack(RawGetPixel(x, y), dR, dG, dB); + newR = (dR * inverseA + r * a) >> 8; + newG = (dG * inverseA + g * a) >> 8; + newB = (dB * inverseA + b * a) >> 8; + colour = ogPack(newR, newG, newB, inverseA); + } else colour = ogPack(r, g, b, a); + } while (false); + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + + " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi) \n" // mov [edi], eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + case 3: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4),%%edi \n" // add edi, [esi + ebx * 4] + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add edi, ecx {adjust for pixel size} + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], al + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx * 4] + " push %%ds \n" // push ds + " mov %%dx, %%ds \n" // mov ds, dx + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n" // mov [edi], al + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), // %2, %3 + "d" (screenSelector) // %4 + ); + break; + } // switch + return; +} // ogDisplay_VESA::RawSetPixel + +bool +ogDisplay_VESA::ogAvail(void) { + return ( ((screenSelector != 0) || (buffer != NULL)) && (lineOfs != NULL)); +} // ogDisplay_VESA::Avail + +void +ogDisplay_VESA::GetModeInfo(uInt16 mode) { + __dpmi_regs regs; + memset(modeInfo, 0, sizeof(struct ogModeInfo)); + memset(®s, 0, sizeof(regs)); + dosmemput(modeInfo, sizeof(struct ogModeInfo), __tb); + + int ofs, seg; + + seg = __tb; // __tb is a buffer located in "dos memory". This buffer + ofs = __tb; // is used because the vesa driver cannot acces memory + // above 1 MB (your program is most likely to be located above 1MB). + + ofs &= 0xffff; // Make a real pointer (segment:offse = 16:16) + seg &= 0xffff0000; // from the address of the buffer. + seg >>= 4; + + regs.x.ax = 0x4f01; // Get the modeinfo of a certain vesa video mode, + // this is a structure which contains. + regs.x.cx = mode; // information needed by other functions below. + regs.x.es = seg; + regs.x.di = ofs; + __dpmi_int(0x10, ®s); + + /* This info is located in dos memory, so it has to be moved to your + * program's address space. + */ + dosmemget(__tb, sizeof(struct ogModeInfo), modeInfo); + return; + +} // ogDisplay_VESA::GetModeInfo + +void +ogDisplay_VESA::GetVESAInfo(void) { + unsigned int seg, ofs; + __dpmi_regs regs; + if (NULL == VESAInfo) VESAInfo = new ogVESAInfo; + if (NULL == VESAInfo) return; + + memset(VESAInfo, 0, sizeof(struct ogVESAInfo)); + memset(®s, 0, sizeof(regs)); + VESAInfo->VBESignature[0] = 'V'; // First off initialize the structure. + VESAInfo->VBESignature[1] = 'B'; + VESAInfo->VBESignature[2] = 'E'; + VESAInfo->VBESignature[3] = '2'; + + /* + + Because VBE funtions operate in real mode, we first have to move the + initialized structure to real-mode address space, so the structure can + be filled by the vesa function in real mode. + + */ + dosmemput(VESAInfo, sizeof(struct ogVESAInfo), __tb); + + + seg = __tb; // Calculate real mode address of the buffer. + ofs = __tb; + ofs &= 0xffff; + seg &= 0xffff0000; + seg >>= 4; + + regs.x.ax = 0x4F00; + regs.x.es = seg; + regs.x.di = ofs; + + __dpmi_int(0x10, ®s); // Get vesa info. + + // Move the structure back to + dosmemget(__tb, sizeof(struct ogVESAInfo), VESAInfo); + + VESAInfo->OEMStringPtr = (VESAInfo->OEMStringPtr & 0xFFFF) + + ((VESAInfo->OEMStringPtr & 0xFFFF0000) >> 12); + + VESAInfo->OEMVendorNamePtr= (VESAInfo->OEMVendorNamePtr& 0xFFFF) + + ((VESAInfo->OEMVendorNamePtr& 0xFFFF0000) >> 12); + + VESAInfo->OEMProductNamePtr= (VESAInfo->OEMProductNamePtr& 0xFFFF) + + ((VESAInfo->OEMProductNamePtr& 0xFFFF0000) >> 12); + + VESAInfo->OEMProductRevPtr= (VESAInfo->OEMProductRevPtr& 0xFFFF) + + ((VESAInfo->OEMProductRevPtr& 0xFFFF0000) >> 12); + + VESAInfo->videoModePtr = ((VESAInfo->videoModePtr & 0xFFFF0000) >> 12) + + (VESAInfo->videoModePtr & 0xFFFF); + + return; +} // ogDisplay_VESA::GetVESAInfo + +uInt16 +ogDisplay_VESA::FindMode(uInt32 _xRes, uInt32 _yRes, uInt32 _BPP) { + uInt16 mode; + + if ((_xRes == 320) && (_yRes == 200) && (_BPP == 8)) return 0x13; + +// if ((VESAInfo==NULL) || (VESAInfo->videoModePtr==NULL)) return 0; + if (modeInfo == NULL) return 0; + + for (mode = 0x100; mode < 0x1FF; mode++) { + GetModeInfo(mode); + if ((modeInfo->xRes >= _xRes) && (modeInfo->yRes >= _yRes) && + (modeInfo->bitsPerPixel == _BPP)) + return mode; + } + + return 0; +} // ogDisplay_VESA::FindMode + +void +ogDisplay_VESA::SetMode(uInt16 mode) { + uInt32 size, count; + __dpmi_meminfo mem_info; + + if (mode == 0x13) { + + xRes = 320; + yRes = 200; + maxX = 319; + maxY = 199; + BPP = 8; + bytesPerPix = 1; + + redFieldPosition = 0; + greenFieldPosition = 0; + blueFieldPosition = 0; + alphaFieldPosition = 0; + + redShifter = 0; + greenShifter = 0; + blueShifter = 0; + alphaFieldPosition = 0; + + mem_info.address = 0xA0000; + mem_info.size = 64000; + size = 63999; + buffer = NULL; + __dpmi_physical_address_mapping(&mem_info); + __dpmi_set_segment_base_address(screenSelector, mem_info.address); + __dpmi_set_segment_limit(screenSelector, size); + __dpmi_set_descriptor_access_rights(screenSelector, 0x40F3); + + } else { + buffer = NULL; + mode |= 0x4000; // attempt lfb + GetModeInfo(mode); + if (modeInfo->physBasePtr == 0) return; + size = modeInfo->yRes*modeInfo->bytesPerLine; + + xRes = modeInfo->bytesPerLine; + yRes = modeInfo->yRes; + maxX = modeInfo->xRes-1; + maxY = yRes-1; + + BPP = modeInfo->bitsPerPixel; + bytesPerPix = (BPP + 7) >> 3; + + redFieldPosition = modeInfo->redFieldPosition; + greenFieldPosition = modeInfo->greenFieldPosition; + blueFieldPosition = modeInfo->blueFieldPosition; + alphaFieldPosition = modeInfo->alphaFieldPosition; + + if (4 == bytesPerPix) { + modeInfo->alphaMaskSize = 8; + while ((alphaFieldPosition == redFieldPosition) || + (alphaFieldPosition == greenFieldPosition) || + (alphaFieldPosition == blueFieldPosition)) + alphaFieldPosition += 8; + } // if + + redShifter = 8-modeInfo->redMaskSize; + greenShifter = 8-modeInfo->greenMaskSize; + blueShifter = 8-modeInfo->blueMaskSize; + alphaShifter = 8-modeInfo->alphaMaskSize; + + if (modeInfo->alphaMaskSize != 0) + alphaMasker = ~(OG_MASKS[modeInfo->alphaMaskSize] << alphaFieldPosition); + else + alphaMasker = ~0; + + + mem_info.address = modeInfo->physBasePtr; + mem_info.size = size; + size = ((size+4095) >> 12); + __dpmi_physical_address_mapping(&mem_info); + __dpmi_set_segment_base_address(screenSelector, mem_info.address); + __dpmi_set_segment_limit(screenSelector,size); + __dpmi_set_descriptor_access_rights(screenSelector, 0xC0F3); + } // else + + owner = this; + dataState = ogAliasing; + inGraphics = true; + + if ((lineOfs != NULL) && (lSize != 0)) delete [] lineOfs; + lSize = yRes*sizeof(uInt32); + lineOfs = new uInt32[yRes];; + if (lineOfs == NULL) return; + lineOfs[0] = 0; + for (count=1; count 8); +// antiAlias=(BPP>8); + if (BPP == 8) SetPal(); + ogClear(ogPack(0, 0, 0)); + return; +} // ogDisplay_VESA::SetMode + +void +ogDisplay_VESA::SetPal(void) { + if (bytesPerPix != 1) return; + outportb(0x3c8,0); + for (uInt32 c = 0; c < 256; c++) { + outportb(0x3c9, pal[c].red >> 2); + outportb(0x3c9, pal[c].green >> 2); + outportb(0x3c9, pal[c].blue >> 2); + } // for + return; +} // ogDisplay_VESA::SetPal + +void +ogDisplay_VESA::ogSetPalette(const ogRGBA8 newPal[256]) { + ogSurface::ogSetPalette(newPal); + SetPal(); + return; +} // ogDisplay_VESA::SetPalette; + +bool +ogDisplay_VESA::ogAlias(ogSurface& src, uInt32 x1, uInt32 y1, + uInt32 x2, uInt32 y2) { + + ogSetLastError(ogNoAliasing); + return false; +} // ogDisplay_VESA::Alias + +void +ogDisplay_VESA::ogClear(uInt32 colour) { + uInt32 height = 0; + uInt32 xx, yy; + uInt8 r, g, b, a; + + if (!ogAvail()) return; + + do { + if (ogIsBlending()) { + ogUnpack(colour, r, g, b, a); + if (a == 0) return; + if (a == 255) break; + for (yy = 0; yy <= maxY; yy++) + for (xx = 0; xx <= maxX; xx++) + RawSetPixel(xx, yy, r, g, b, a); + } // if + } while (false); + + __asm__ __volatile__("cld\n"); + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " push %%es \n" // push es + " mov %6, %%ax \n" // mov ax, screenSelector + " mov %%ax, %%es \n" // mov es, ax + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxX) + " inc %%ebx \n" // inc ebx (maxY) + " mov %5, %%eax \n" // mov eax, colour + " mov %%edx, %%ecx \n" // mov ecx, edx + " shl $2, %%ecx \n" // shl ecx, 2 + " sub %%ecx, %%esi \n" // sub esi, ecx // adjust for pix size + "loop32: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " rep \n" + " stosl \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop32 \n" + " pop %%es \n" // pop es + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "b" (maxY), "c" (xRes), "d" (maxX), // %2, %3, %4 + "m" (colour), "m" (screenSelector) // %5, %6 + ); + break; + case 3: + __asm__ __volatile__( + " push %%es \n" // push es + " mov %7, %%ax \n" // mov ax, screenSelector + " mov %%ax, %%es \n" // mov es, ax + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxX) + " inc %%ebx \n" // inc ebx (maxY) + " mov %5, %%eax \n" // mov eax, colour + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%ebx, %6 \n" // mov height, ebx + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%eax, %%ebx \n" // mov ebx, eax + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " shr $16, %%ebx \n" // shr ebx, 16 + "oloop24: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + "iloop24: \n" + " mov %%ax,(%%edi) \n" // mov [edi],ax + " movb %%bl,2(%%edi) \n" // mov [edi+2],bl + " add $3, %%edi \n" // add edi, 3 + " dec %%ecx \n" // dec ecx + " jnz iloop24 \n" + " add %%esi, %%edi \n" // add edi, esi + " decl %6 \n" // dec height + " jnz oloop24 \n" + " pop %%es \n" // pop es + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "b" (maxY), "c" (xRes), "d" (maxX), // %2, %3, %4 + "m" (colour), "m" (height), // %5, %6 + "m" (screenSelector) // %7 + ); + break; + case 2: + __asm__ __volatile__( + " push %%es \n" // push es + " mov %6, %%ax \n" // mov ax, screenSelector + " mov %%ax, %%es \n" // mov es, ax + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxX) + " inc %%ebx \n" // inc ebx (maxY) + " sub %%edx, %%esi \n" // sub esi, edx + " mov %5, %%eax \n" // mov eax, colour + " sub %%edx, %%esi \n" // sub esi, edx // adjust for pix size + " mov %%ax, %%cx \n" // mov cx, ax + " shl $16, %%eax \n" // shl eax, 16 + " mov %%cx, %%ax \n" // mov ax, cx + "loop16: \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " shr $1, %%ecx \n" // shr ecx, 1 + " rep \n" + " stosl \n" + " jnc noc16 \n" + " stosw \n" + "noc16: \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop16 \n" + " pop %%es \n" + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "b" (maxY), "c" (xRes), "d" (maxX), // %2, %3, %4 + "m" (colour), "m" (screenSelector) // %5, %6 + ); + break; + + case 1: + __asm__ __volatile__( + " push %%es \n" // push es + " mov %6, %%ax \n" // mov ax, screenSelector + " mov %%ax, %%es \n" // mov es, ax + " add (%%esi), %%edi \n" // add edi, [esi] + " mov %%ecx, %%esi \n" // mov esi, ecx + " inc %%edx \n" // inc edx (maxY) + " inc %%ebx \n" // inc ebx (maxX) + " mov %5, %%eax \n" // mov eax, colour + " sub %%edx, %%esi \n" // sub esi, edx + " mov %%al, %%ah \n" // mov ah, al + " mov %%ax, %%cx \n" // mov cx, ax + " shl $16, %%eax \n" // shl eax, 16 + " mov %%cx, %%ax \n" // mov ax, cx + "loop8: \n" + " push %%edx \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " and $3, %%edx \n" // and edx, 3 + " shr $2, %%ecx \n" // shr ecx, 2 + " rep \n" + " stosl \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " rep \n" + " stosb \n" + " pop %%edx \n" + " add %%esi, %%edi \n" // add edi, esi + " dec %%ebx \n" + " jnz loop8 \n" + " pop %%es \n" // pop es + : + : "D" (buffer), "S" (lineOfs), // %0, %1 + "b" (maxY), "c" (xRes), "d" (maxX), // %2, %3, %4 + "m" (colour), "m" (screenSelector) // %5, %6 + ); + break; + } // switch + return; +} // ogDisplay_VESA::Clear + +void +ogDisplay_VESA::ogCopyLineTo(uInt32 dx, uInt32 dy, const void * src, + uInt32 size) { + /* + * ogCopyLineTo() + * + * Inputs: + * + * dx - Destination X of the target buffer + * dy - Destination Y of the target buffer + * src - buffer to copy + * size - size in bytes *NOT* pixels + * + * Copies a run of pixels (of the same format) to (x,y) of a buffer + * + * This method is required because of the different implementations of + * copying a run of pixels to a buffer + * + * WARNING!!! This does *NO* error checking. It is assumed that you've + * done all of that. CopyLineTo and CopyLineFrom are the only + * methods that don't check to make sure you're hosing things. Don't + * use this method unless YOU KNOW WHAT YOU'RE DOING!!!!!!!!! + */ + movedata(_my_ds(),(uInt32)src, + screenSelector,(uInt32)((uInt8*)buffer+(lineOfs[dy]+dx*bytesPerPix) ), + size); + + return; +} // ogSurface::ogCopyLineTo + +void +ogDisplay_VESA::ogCopyLineFrom(uInt32 sx, uInt32 sy, void * dest, uInt32 size) { + /* + * CopyLineFrom() + * + * Inputs: + * + * sx - Source X of the target buffer + * sy - Source Y of the target buffer + * dest - where to put it + * size - size in bytes *NOT* pixels + * + * Copies a run of pixels (of the same format) to (x,y) of a buffer + * + * This method is required because of the different implementations of + * copying a run of pixels to a buffer + * + * WARNING!!! This does *NO* error checking. It is assumed that you've + * done all of that. CopyLineTo and CopyLineFrom are the only + * methods that don't check to make sure you're hosing things. Don't + * use this method unless YOU KNOW WHAT YOU'RE DOING!!!!!!!!! + */ + movedata(screenSelector,(uInt32)((uInt8*)buffer+(lineOfs[sy]+sx*bytesPerPix ) ), + _my_ds(),(uInt32)dest, + size); + + return; +} // ogDisplay_VESA::ogCopyLineFrom + +bool +ogDisplay_VESA::ogCreate(uInt32 _xRes, uInt32 _yRes, ogPixelFmt _pixFormat) { + uInt16 mode; + mode = FindMode(_xRes, _yRes, _pixFormat.BPP); + if ((mode == 0) && ((_pixFormat.BPP==24) || (_pixFormat.BPP==32))) { + if (_pixFormat.BPP==24) _pixFormat.BPP=32; else _pixFormat.BPP=24; + mode = FindMode(_xRes,_yRes,_pixFormat.BPP); + } // if + if (mode!=0) SetMode(mode); + return (mode!=0); +} // ogDisplay_VESA::ogCreate + +bool +ogDisplay_VESA::ogClone(ogSurface& src) { + ogSetLastError(ogNoCloning); + return false; +} // ogDisplay_VESA::ogClone + +void +ogDisplay_VESA::ogCopyPalette(ogSurface& src) { + ogSurface::ogCopyPalette(src); + SetPal(); + return; +} // ogDisplay_VESA::ogCopyPalette + +uInt32 +ogDisplay_VESA::ogGetPixel(int32 x, int32 y) { + uInt32 result; + if (!ogAvail()) return ogGetTransparentColor(); + if (((uInt32)x>maxX) || ((uInt32)y>maxY)) + return ogGetTransparentColor(); + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " shl $2, %%ecx \n" // shl ecx, 2 {adjust for pixel size} + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx*4] + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " mov (%%edi),%%eax \n" // eax, dword ptr [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + case 3: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " mov %%ecx, %%eax \n" // mov eax, ecx - adjust for pixel size + " add %%ecx, %%ecx \n" // add ecx, ecx - adjust for pixel size + " add %%eax, %%ecx \n" // add ecx, eax - adjust for pixel size + " add %%esi, %%edi \n" // add edi, esi + // " add (%%esi,%%ebx,4), %%edi \n" // add edi, [esi + ebx*4] + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] + " xor %%eax, %%eax \n" + " mov 2(%%edi), %%al \n" // mov al, [edi+2] + " shl $16, %%eax \n" // shl eax, 16 + " mov (%%edi), %%ax \n" // mov ax, [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + case 2: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add edi, ecx + " movzwl (%%edi),%%eax \n" // movzx edx,word ptr [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + case 1: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax (screenSelector) + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " movzbl (%%edi),%%eax \n" // movzx edx,byte ptr [edi] + " mov %%eax, %4 \n" // mov result, eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (screenSelector), "c" (x), "m" (result) // %2, %3, %4 + ); + break; + } // switch + return result; +} // ogDisplay_VESA::ogGetPixel + +void * +ogDisplay_VESA::ogGetPtr(uInt32 x, uInt32 y) { + return NULL; +} // ogDisplay_VESA::ogGetPtr + +void +ogDisplay_VESA::ogHLine(int32 x1, int32 x2, int32 y, uInt32 colour) { + int32 tmp; + uInt8 r, g, b, a; + + if (!ogAvail()) return; + if ((uInt32)y>maxY) return; + if (x1 > x2) { + tmp= x1; + x1 = x2; + x2 = tmp; + } // if + if (x1 < 0) x1 = 0; + if (x2 > (int32)maxX) x2 = maxX; + if (x2 < x1) return; + + if (ogIsBlending()) { + ogUnpack(colour, r, g, b, a); + if (a == 0) return; + if (a == 255) { + for (tmp = x1; tmp <= x2; tmp++) + RawSetPixel(tmp, y, r, g, b, a); + return; + } // if a == 255 + } // if blending + + __asm__ __volatile__("cld \n"); + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " push %%es \n" // push es + " mov %%dx, %%es \n" // mov es, dx + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " add %%esi, %%edi \n" // add edi, esi + " inc %%ecx \n" + " shl $2, %%ebx \n" // shl ebx, 2 + " add %%ebx, %%edi \n" // add edi, ebx + " rep \n" + " stosl \n" + " pop %%es \n" // pop es + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (colour), "b" (x1), // %2, %3 + "c" (x2), "d" (screenSelector) // %4, %5 + ); + break; + case 3: + __asm__ __volatile__( + " push %%es \n" // push es + " mov %%ax, %%es \n" // mov es, ax + " mov %2, %%eax \n" + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " add %%esi, %%edi \n" // add edi, esi + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " inc %%ecx \n" // inc ecx + " add %%edx, %%ebx \n" // add ebx, edx - pix size + " add %%ebx, %%edi \n" // add edi, ebx + " mov %%eax, %%ebx \n" // mov ebx, eax + " shr $16, %%ebx \n" // shr ebx, 16 + "hLlop24: \n" + " mov %%ax, (%%edi) \n" // mov [edi], ax + " mov %%bl, 2(%%edi)\n" // mov [edi+2], bl + " add $3, %%edi \n" // add edi, 3 + " dec %%ecx \n" // dec ecx + " jnz hLlop24 \n" + " pop %%es \n" // pop es + + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "m" (colour), "b" (x1), // %2, %3 + "c" (x2), "d" (x1), "a" (screenSelector) // %4, %5 + ); + break; + case 2: + __asm__ __volatile__( + " push %%es \n" + " mov %%dx, %%es \n" // mov es, dx + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " inc %%ecx \n" // inc ecx + " add %%ebx, %%edi \n" // add edi, ebx + " add %%esi, %%edi \n" // add edi, esi + " xor %%edx, %%edx \n" // xor edx, edx + " mov %%ax, %%dx \n" // mov dx, ax + " shl $16, %%eax \n" // shl eax, 16 + " add %%edx, %%eax \n" // add eax, edx + + " shr $1, %%ecx \n" // shr ecx, 1 + " rep \n" + " stosl \n" + " jnc hLnoc16 \n" + " stosw \n" + "hLnoc16: \n" + " pop %%es \n" + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (colour), "b" (x1), // %2, %3 + "c" (x2), "d" (screenSelector) + ); + break; + case 1: + __asm__ __volatile__( + " push %%es \n" // push es + " mov %%dx, %%es \n" // mov es, dx + " add %%ebx, %%edi \n" // add edi, ebx + " add %%esi, %%edi \n" // add edi, esi + " and $0xff, %%eax \n" // and eax, 0ffh + " sub %%ebx, %%ecx \n" // sub ecx, ebx + " mov %%al, %%ah \n" // mov ah, al + " inc %%ecx \n" // inc ecx + " mov %%eax, %%ebx \n" // mov ebx, eax + " shl $16, %%ebx \n" // shl ebx, 16 + " add %%ebx, %%eax \n" // add eax, ebx + + " mov %%ecx, %%edx \n" // mov edx, ecx + " mov $4, %%ecx \n" // mov ecx, 4 + " sub %%edi, %%ecx \n" // sub ecx, edi + " and $3, %%ecx \n" // and ecx, 3 + " sub %%ecx, %%edx \n" // sub edx, ecx + " jle LEndBytes \n" + " rep \n" + " stosb \n" + " mov %%edx, %%ecx \n" // mov ecx, edx + " and $3, %%edx \n" // and edx, 3 + " shr $2, %%ecx \n" // shr ecx, 2 + " rep \n" + " stosl \n" + "LEndBytes: \n" + " add %%edx, %%ecx \n" // add ecx, edx + " rep \n" + " stosb \n" + " pop %%es \n" + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "a" (colour), "b" (x1), // %2, %3 + "c" (x2), "d" (screenSelector) + ); + break; + } // switch + return; +} // ogDisplay_VESA::ogHLine + +bool +ogDisplay_VESA::ogLoadPalette(const char *palfile) { + bool result; + if ((result = ogSurface::ogLoadPalette(palfile))==true) SetPal(); + return result; +} // ogDisplay_VESA::ogLoadPalette + +void +ogDisplay_VESA::ogSetPixel(int32 x, int32 y, uInt32 colour) { + uInt32 newR, newG, newB, inverseA; + uInt8 sR, sG, sB, sA; + uInt8 dR, dG, dB; + + if (!ogAvail()) return; + if (((uInt32)x > maxX) || ((uInt32)y > maxY)) return; + + do { + if (ogIsBlending()) { + ogUnpack(colour, sR, sG, sB, sA); + if (sA == 0) return; + if (sA == 255) break; + inverseA = 255 - sA; + ogUnpack(RawGetPixel(x, y), dR, dG, dB); + newR = (dR * inverseA + sR * sA) >> 8; + newG = (dG * inverseA + sG * sA) >> 8; + newB = (dB * inverseA + sB * sA) >> 8; + colour = ogPack(newR, newG, newB, inverseA); + } // if + } while (false); + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" // push ds + " mov %4, %%dx \n" // mov dx, screenSelector + " mov %%dx, %%ds \n" // mov ds, dx + " shl $2, %%ecx \n" // shl eax, 2 {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%eax, (%%edi)\n" // mov [edi], eax + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), "m" (screenSelector) // %2, %3, %4 + ); + break; + case 3: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" // push ds + " mov %4, %%dx \n" // mov dx, screenSelector + " mov %%dx, %%ds \n" // mov ds, dx + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + " add %%ecx, %%edi \n" // add edi, ecx {adjust for pixel size} + " add %%ecx, %%edi \n" // add edi, ecx {adjust for pixel size} + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), "m" (screenSelector) // %2, %3, %4 + ); + break; + case 2: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" + " mov %4, %%dx \n" + " mov %%dx, %%ds \n" + + " add %%ecx, %%ecx \n" // add ecx, ecx {adjust for pixel size} + " add %%esi, %%edi \n" // add edi, esi + " mov %3, %%eax \n" // mov eax, colour + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%ax, (%%edi) \n" // mov [edi], al + " pop %%ds\n" + + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), "m" (screenSelector) // %2, %3, %4 + ); + break; + + case 1: + __asm__ __volatile__( + // { Calculate offset, prepare the pixel to be drawn } + " push %%ds \n" + " mov %4, %%dx \n" + " mov %%dx, %%ds \n" + " add %%esi, %%edi \n" // add edi, esi + " add %%ecx, %%edi \n" // add edi, ecx + // { Draw the pixel } + " mov %%al, (%%edi) \n" // mov [edi], al + " pop %%ds\n" + : + : "D" (buffer), "S" (lineOfs[y]), // %0, %1 + "c" (x), "a" (colour), "m" (screenSelector) // %2, %3, %4 + ); + break; + } // switch + return; +} // ogDisplay_VESA::ogSetPixel + +void +ogDisplay_VESA::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue) { + if (pal == NULL) return; + ogSurface::ogSetPalette(colour,red,green,blue); + outportb(0x3c8, colour); + outportb(0x3c9, red >> 2); + outportb(0x3c9, green >> 2); + outportb(0x3c9, blue >> 2); + + return; +} // ogDisplay_VESA::ogSetPalette + +void +ogDisplay_VESA::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, + uInt8 blue, uInt8 alpha) { + if (pal == NULL) return; + ogSurface::ogSetPalette(colour, red, green, blue, alpha); + outportb(0x3c8, colour); + outportb(0x3c9, red >> 2); + outportb(0x3c9, green >> 2); + outportb(0x3c9, blue >> 2); + + return; +} // ogDisplay_VESA::ogSetPalette + +void +ogDisplay_VESA::ogVFlip(void) { + if (!ogAvail()) return; + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax + " add %%edi, %%esi \n" // add esi, edi + "vf32lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf32lop2: \n" + " mov (%%edi),%%eax \n" // mov eax, [edi] + " mov (%%esi),%%ecx \n" // mov ecx, [esi] + " mov %%eax,(%%esi) \n" // mov [esi], eax + " mov %%ecx,(%%edi) \n" // mov [edi], ecx + " add $4, %%edi \n" // add edi, 4 + " sub $4, %%esi \n" // sub esi, 4 + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf32lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " dec %%edx \n" + " jnz vf32lop \n" + " pop %%ds \n" // pop ds + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*4), // %0, %1 + "b" (xRes), "d" (maxY+1), "a" (screenSelector) // %2, %3, %4 + ); + break; + case 3: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax + " add %%edi, %%esi \n" // add esi, edi + "vf24lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf24lop2: \n" + " mov (%%edi),%%ax \n" // mov ax, [edi] + " mov 2(%%edi),%%dl \n" // mov dl, [edi+2] + " mov (%%esi),%%cx \n" // mov cx, [esi] + " mov 2(%%esi),%%dh \n" // mov dh, [esi+2] + " mov %%ax,(%%esi) \n" // mov [esi], ax + " mov %%dl,2(%%esi) \n" // mov [esi+2], dl + " mov %%cx,(%%edi) \n" // mov [edi], cx + " mov %%dh,2(%%edi) \n" // mov [edi+2], dh + " add $3, %%edi \n" // add edi, 3 + " sub $3, %%esi \n" // sub esi, 3 + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf24lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " decl %3 \n" // dec height + " jnz vf24lop \n" + " pop %%ds \n" // pop ds + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*3), // %0, %1 + "b" (xRes), "d" (maxY+1), "a" (screenSelector) // %2, %3, %4 + ); + break; + case 2: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax + " add %%edi, %%esi \n" // add esi, edi + "vf16lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf16lop2: \n" + " mov (%%edi),%%ax \n" // mov ax, [edi] + " mov (%%esi),%%cx \n" // mov cx, [esi] + " mov %%ax,(%%esi) \n" // mov [esi], ax + " mov %%cx,(%%edi) \n" // mov [edi], cx + " add $2, %%edi \n" // add edi, 2 + " sub $2, %%esi \n" // sub esi, 2 + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf16lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " dec %%edx \n" + " jnz vf16lop \n" + " pop %%ds \n" // pop ds + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX*2), // %0, %1 + "b" (xRes), "d" (maxY+1), "a" (screenSelector) // %2, %3, %4 + ); + break; + case 1: + __asm__ __volatile__( + " push %%ds \n" // push ds + " mov %%ax, %%ds \n" // mov ds, ax + " add %%edi, %%esi \n" // add esi, edi + "vf8lop: \n" + " push %%esi \n" // push esi + " push %%edi \n" // push edi + "vf8lop2: \n" + " mov (%%edi),%%al \n" // mov al, [edi] + " mov (%%esi),%%ah \n" // mov ah, [esi] + " mov %%al,(%%esi) \n" // mov [esi], al + " mov %%ah,(%%edi) \n" // mov [edi], ah + " inc %%edi \n" // inc edi + " dec %%esi \n" // dec esi + " cmp %%esi, %%edi \n" // cmp edi, esi + " jbe vf8lop2 \n" + " pop %%edi \n" // pop edi + " pop %%esi \n" // pop esi + " add %%ebx, %%esi \n" // add esi, ebx + " add %%ebx, %%edi \n" // add edi, ebx + " dec %%edx \n" + " jnz vf8lop \n" + " pop %%ds \n" // pop ds + : + : "D" ((char *)buffer+lineOfs[0]), "S" (maxX), // %0, %1 + "b" (xRes), "d" (maxY+1), "a" (screenSelector) // %2, %3, %4 + ); + break; + } // switch + return; +} // ogDisplay_VESA::ogVFlip + +void +ogDisplay_VESA::ogVLine(int32 x, int32 y1, int32 y2, uInt32 colour) { + int32 tmp; + uInt8 r, g, b, a; + + if (!ogAvail()) return; + if ((uInt32)x > maxX) return; + + if (y1 > y2) { + tmp= y1; + y1 = y2; + y2 = tmp; + } // if + + if (y1 < 0) y1 = 0; + if (y2 > (int32)maxY) y2 = maxY; + if (y2 < y1) return; + + if (ogIsBlending()) { + + ogUnpack(colour, r, g, b, a); + + if (a == 0) return; + + if (a != 255) { + for (tmp = y1; tmp <= y2; tmp++) + RawSetPixel(x, tmp, r, g, b, a); + return; + } // if + + } // if blending + + switch (bytesPerPix) { + case 4: + __asm__ __volatile__( + " push %%ds \n" // push ds + " add %%esi, %%edi \n" // add edi, esi + " shl $2, %%ebx \n" // shl ebx, 2 - pix size + " mov %7, %%si \n" // mov si, screenSelector + " mov %%si, %%ds \n" // mov ds, si + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " mov %2, %%eax \n" // mov eax, colour + " inc %%ecx \n" // inc ecx + "vLlop32: \n" + " mov %%eax, (%%edi)\n" // mov [edi], eax + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop32 \n" + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "m" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1), "m" (screenSelector) // %6, %7 + ); + break; + case 3: + __asm__ __volatile__( + " push %%ds \n" // push ds + " add %%esi, %%edi \n" // add edi, esi + " mov %%ebx, %%esi \n" // mov esi, ebx - pix size + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " add %%esi, %%ebx \n" // add ebx, esi - pix size + " mov %7, %%si \n" // mov si, screenSelector + " mov %%si, %%ds \n" // mov ds, si + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " mov %2, %%eax \n" // mov eax, colour + " inc %%ecx \n" // inc ecx + " mov %%eax, %%ebx \n" // mov ebx, eax + " shr $16, %%ebx \n" // shr ebx, 16 + "vLlop24: \n" + " mov %%ax, (%%edi) \n" // mov [edi], eax + " mov %%bl, 2(%%edi)\n" // mov [edi+2], bl + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop24 \n" + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "m" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1), "m" (screenSelector) // %6, %7 + ); + break; + case 2: + __asm__ __volatile__( + " push %%ds \n" // push ds + " add %%esi, %%edi \n" // add edi, esi + " add %%ebx, %%ebx \n" // add ebx, ebx - pix size + " mov %7, %%si \n" // mov si, screenSelector + " mov %%si, %%ds \n" // mov ds, si + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " mov %2, %%eax \n" // mov eax, colour + " inc %%ecx \n" // inc ecx + "vLlop16: \n" + " mov %%ax, (%%edi) \n" // mov [edi], ax + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop16 \n" + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "m" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1), "m" (screenSelector) // %6, %7 + ); + break; + case 1: + __asm__ __volatile__( + " push %%ds \n" // push ds + " add %%esi, %%edi \n" // add edi, esi + " mov %7, %%si \n" // mov si, screenSelector + " mov %%si, %%ds \n" // mov ds, si + " mov %6, %%esi \n" // mov esi, y1 + " sub %%esi, %%ecx \n" // sub ecx, esi + " add %%ebx, %%edi \n" // add edi, ebx + " mov %2, %%eax \n" // mov eax, colour + " inc %%ecx \n" // inc ecx + "vLlop8: \n" + " mov %%al, (%%edi) \n" // mov [edi], al + " add %%edx, %%edi \n" // add edi, edx + " dec %%ecx \n" // dec ecx + " jnz vLlop8 \n" + " pop %%ds \n" // pop ds + : + : "D" (buffer), "S" (lineOfs[y1]), // %0, %1 + "m" (colour), "b" (x), // %2, %3 + "c" (y2), "d" (xRes), // %4, %5 + "m" (y1), "m" (screenSelector) // %6, %7 + ); + break; + + } // switch + return; +} // ogDisplay_VESA::ogVLine + +ogDisplay_VESA::~ogDisplay_VESA(void) { + __dpmi_regs regs; + if (VESAInfo != NULL) delete VESAInfo; + if (modeInfo != NULL) delete modeInfo; + if (attributes != NULL) delete attributes; + if (inGraphics) { + regs.x.ax = 3; + __dpmi_int(0x10, ®s); + } // if inGraphics + + return; +} diff --git a/src/lib/objgfx40/ogFont.cpp b/src/lib/objgfx40/ogFont.cpp new file mode 100644 index 0000000..83bdea4 --- /dev/null +++ b/src/lib/objgfx40/ogFont.cpp @@ -0,0 +1,319 @@ +#include +#include + +extern "C" { + #include +#ifdef __UBIXOS_KERNEL__ + #include +#else + #include + #include +#endif + } + +using namespace std; +typedef + struct { + char ID[3]; + uInt8 version; + uInt8 width, height; + uInt8 numOfChars; + uInt8 startingChar; + uInt8 colourType; + uInt8 paddington[7]; + } ogDPFHeader; + +static +bool +fileExists(const char *file) +{ +#ifdef __UBIXOS_KERNEL__ + fileDescriptor *f = fopen(file, "rb"); +#else + FILE *f = fopen(file, "rb"); +#endif + if (!f) + return false; + fclose(f); + return true; +} + +ogBitFont::ogBitFont(void) { +#ifdef __UBIXOS_KERNEL__ + kmemset(fontDataIdx, 0, sizeof(fontDataIdx)); + kmemset(charWidthTable, 0, sizeof(charWidthTable)); + kmemset(charHeightTable, 0, sizeof(charHeightTable)); +#else + memset(fontDataIdx, 0, sizeof(fontDataIdx)); + memset(charWidthTable, 0, sizeof(charWidthTable)); + memset(charHeightTable, 0, sizeof(charHeightTable)); +#endif + + fontData = NULL; + fontDataSize = 0; + numOfChars = 0; + width = height = startingChar = 0; + + BGColour.red = 0; + BGColour.green = 0; + BGColour.blue = 0; + BGColour.alpha = 0; + + FGColour.red = 255; + FGColour.green = 255; + FGColour.blue = 255; + FGColour.alpha = 255; + + return; +} // ogBitFont::ogBitFont + +void +ogBitFont::SetBGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { + BGColour.red = red; + BGColour.green = green; + BGColour.blue = blue; + BGColour.alpha = alpha; + return; +} // ogBitFont::SetBGColor + +void +ogBitFont::SetFGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { + FGColour.red = red; + FGColour.green = green; + FGColour.blue = blue; + FGColour.alpha = alpha; + return; +} // ogBitFont::SetFGColor + +ogBitFont::~ogBitFont(void) { +#ifdef __UBIXOS_KERNEL__ + kmemset(fontDataIdx, 0, sizeof(fontDataIdx)); + kmemset(charWidthTable, 0, sizeof(charWidthTable)); + kmemset(charHeightTable, 0, sizeof(charHeightTable)); +#else + memset(fontDataIdx, 0, sizeof(fontDataIdx)); + memset(charWidthTable, 0, sizeof(charWidthTable)); + memset(charHeightTable, 0, sizeof(charHeightTable)); +#endif + delete [] fontData; + fontData = NULL; + fontDataSize = 0; + width = height = startingChar = 0; + return; +} // ogBitFont::~ogBitFont; + +void +ogBitFont::CenterTextX(ogSurface& dest, int32 y, const char * textString) { + int32 x; + x = ((dest.ogGetMaxX()+1) - TextWidth(textString)) / 2; + PutString(dest, x, y, textString); + return; +} // ogBitFont::CenterTextX + +void +ogBitFont::JustifyText(ogSurface& dest, ogTextAlign horiz, ogTextAlign vert, + const char * textString) { + uInt32 x, y; + + switch (horiz) { + case leftText: + x = 0; + break; + case centerText: + x = ((dest.ogGetMaxX())-TextWidth(textString)) / 2; + break; + case rightText: + x = (dest.ogGetMaxX())-TextWidth(textString); + break; + default: + return; + } // switch + + switch (vert) { + case topText: + y = 0; + break; + case centerText: + y = ((dest.ogGetMaxY())-TextHeight(textString)) / 2; + break; + case bottomText: + y = (dest.ogGetMaxY())-TextHeight(textString); + default: + return; + } // switch + + PutString(dest, x, y, textString); + return; +} // ogBitFont::JustifyText + +bool +ogBitFont::Load(const char* fontFile, uInt32 offset = 0) { +#ifdef __UBIXOS_KERNEL__ + fileDescriptor * infile; +#else + FILE * infile; +#endif + ogDPFHeader header; + uInt32 lresult, size; + + if (!fileExists(fontFile)) return false; + + delete [] fontData; + + infile = fopen(fontFile, "rb"); + fseek(infile, offset, SEEK_SET); + lresult = fread(&header, sizeof(header), 1, infile); + width = header.width; + height = header.height; + numOfChars = header.numOfChars; + if (numOfChars == 0) numOfChars = 256; + startingChar = header.startingChar; + +#ifdef __UBIXOS_KERNEL__ + kmemset(fontDataIdx, 0, sizeof(fontDataIdx)); + kmemset(charWidthTable, 0, sizeof(charWidthTable)); + kmemset(charHeightTable, 0, sizeof(charHeightTable)); +#else + memset(fontDataIdx, 0, sizeof(fontDataIdx)); + memset(charWidthTable, 0, sizeof(charWidthTable)); + memset(charHeightTable, 0, sizeof(charHeightTable)); +#endif + + size = (((uInt32)width+7) / 8)*(uInt32)height; + fontDataSize = size* (uInt32)numOfChars; + + for (int32 tmp = startingChar; tmp <= startingChar+numOfChars-1; tmp++) { + charWidthTable[tmp] = width; + charHeightTable[tmp] = height; + fontDataIdx[tmp] = (size*(tmp-startingChar)); + } // for tmp + + fontData = new uInt8[fontDataSize]; + + lresult = fread(fontData, 1, fontDataSize, infile); + + fclose(infile); + return true; +} // ogBitFont::Load + +/* +bool +ogFont::LoadFrom(const char* FontFile, uInt32 Offset) { + return true; +} // ogFont::LoadFrom + + +bool +ogFont::Save(const char* FontFile) { + return saveTo(FontFile,0); +} // ogFont::Save +*/ + +uInt32 +ogBitFont::TextHeight(const char * textString) { + uInt32 size, tmpsize; + size = 0; + const unsigned char * text = (const unsigned char *)textString; + + if (text != NULL) + while (*text) { + tmpsize = charHeightTable[*text++]; + if (tmpsize>size) size = tmpsize; + } // while + + return size; +} // ogBitFont::TextHeight + +uInt32 +ogBitFont::TextWidth(const char * textString) { + uInt32 size = 0; + const unsigned char * text = (const unsigned char *)textString; + + if (text != NULL) + while (*text) + size += charWidthTable[*text++]; + return size; +} // ogBitFont::TextWidth + +/* +bool +ogBitFont::SaveTo(const char * fontFile, int32 offset) { + return true; +} // TDPFont::SaveTo +*/ + +void +ogBitFont::PutChar(ogSurface& dest, int32 x, int32 y, const char ch) { + + uInt32 xx, xCount, yCount; + uInt32 BGC, FGC, tColour; + uInt8 * offset; + uInt8 bits = 0; + const unsigned char c = (const unsigned char)ch; + + if (fontData == NULL) return; + if (!dest.ogAvail()) return; + + if (charWidthTable[c] != 0) { + BGC = dest.ogPack(BGColour.red, + BGColour.green, + BGColour.blue, + BGColour.alpha); + + BGC &= dest.ogGetAlphaMasker(); + + tColour = dest.ogGetTransparentColor(); + + FGC = dest.ogPack(FGColour.red, + FGColour.green, + FGColour.blue, + FGColour.alpha); + + offset = fontData; + offset += fontDataIdx[c]; + + for (yCount = 0; yCount < height; yCount++) { + xCount = charWidthTable[c]; + xx = 0; + + do { + if ((xx & 7) == 0) bits = *(offset++); + if ((bits & 128) != 0) + dest.ogSetPixel(x + xx, y+yCount , FGColour.red, FGColour.green, + FGColour.blue, FGColour.alpha); + else + if (BGC != tColour) + dest.ogSetPixel(x + xx, y+yCount, BGC); + + bits += bits; + ++xx; + } while (--xCount); + } // for yCount + } // if + return; +} // ogBitFont::PutChar + +void +ogBitFont::PutString(ogSurface& dest, int32 x, int32 y, + const char *textString) { + + const unsigned char *text; + unsigned char ch; + + if (textString == NULL) return; +#ifdef __UBIXOS_KERNEL__ + if (0 == kstrlen(textString)) return; +#else + if (0 == strlen(textString)) return; +#endif + if (!dest.ogAvail()) return; + + text = (const unsigned char *)textString; + + while ((ch = *text++) != 0) { + PutChar(dest, x, y, ch); + x += charWidthTable[ch]; + } // while + + return; +} // ogBitFont::PutString diff --git a/src/lib/objgfx40/ogPixCon.cpp b/src/lib/objgfx40/ogPixCon.cpp new file mode 100644 index 0000000..0e0473b --- /dev/null +++ b/src/lib/objgfx40/ogPixCon.cpp @@ -0,0 +1,143 @@ +#include +#include + +// ogPixCon constructor +ogPixCon::ogPixCon(ogPixelFmt srcPixFmt, ogPixelFmt dstPixFmt) { + uInt8 channelIdx[4]; + uInt8 srcFieldSize[4]; + uInt8 srcFieldPos[4]; + uInt8 dstShifters[4]; + + uInt8 tmpb; + int32 i, j; + + channelIdx[0] = 0; + channelIdx[1] = 1; + channelIdx[2] = 2; + channelIdx[3] = 3; + + srcFieldSize[0] = srcPixFmt.alphaMaskSize; + srcFieldSize[1] = srcPixFmt.redMaskSize; + srcFieldSize[2] = srcPixFmt.greenMaskSize; + srcFieldSize[3] = srcPixFmt.blueMaskSize; + + srcFieldPos[0] = srcPixFmt.alphaFieldPosition; + srcFieldPos[1] = srcPixFmt.redFieldPosition; + srcFieldPos[2] = srcPixFmt.greenFieldPosition; + srcFieldPos[3] = srcPixFmt.blueFieldPosition; + + /* + * The dest shifters are 32-(fieldPosition+fieldSize). For things like + * 24bpp where there is no alpha, the field position will be 0, and the + * field size will be 0. 32-(0+0) is 32.. and when the shift takes place + * the 32 will turn into a 0 and the shift will do nothing + */ + + dstShifters[0] = 32-(dstPixFmt.alphaFieldPosition+dstPixFmt.alphaMaskSize); + dstShifters[1] = 32-(dstPixFmt.redFieldPosition+dstPixFmt.redMaskSize); + dstShifters[2] = 32-(dstPixFmt.greenFieldPosition+dstPixFmt.greenMaskSize); + dstShifters[3] = 32-(dstPixFmt.blueFieldPosition+dstPixFmt.blueMaskSize); + + i = srcPixFmt.redMaskSize - dstPixFmt.redMaskSize; + if (i>0) + srcMasker = OG_MASKS[dstPixFmt.redMaskSize] << (srcPixFmt.redFieldPosition+i); + else + srcMasker = OG_MASKS[srcPixFmt.redMaskSize] << srcPixFmt.redFieldPosition; + + i = srcPixFmt.greenMaskSize - dstPixFmt.greenMaskSize; + if (i>0) + srcMasker+= OG_MASKS[dstPixFmt.greenMaskSize] << (srcPixFmt.greenFieldPosition+i); + else + srcMasker+= OG_MASKS[srcPixFmt.greenMaskSize] << srcPixFmt.greenFieldPosition; + + i = srcPixFmt.blueMaskSize - dstPixFmt.blueMaskSize; + if (i>0) + srcMasker+= OG_MASKS[dstPixFmt.blueMaskSize] << (srcPixFmt.blueFieldPosition+i); + else + srcMasker+= OG_MASKS[srcPixFmt.blueMaskSize] << srcPixFmt.blueFieldPosition; + + i = srcPixFmt.alphaMaskSize - dstPixFmt.alphaMaskSize; + if (i>0) + srcMasker+= OG_MASKS[dstPixFmt.alphaMaskSize] << (srcPixFmt.alphaFieldPosition+i); + else + srcMasker+= OG_MASKS[srcPixFmt.alphaMaskSize] << srcPixFmt.alphaFieldPosition; + + /* + * sort in descending order based on srcFieldPos (oth field will hold + * highest position value) + */ + + for (i = 1; i < 4; i++ ) + for (j = 0; j < i; j++) { + if (srcFieldPos[j] < srcFieldPos[i]) { + tmpb = srcFieldPos[j]; + srcFieldPos[j] = srcFieldPos[i]; + srcFieldPos[i] = tmpb; + + tmpb = srcFieldSize[j]; + srcFieldSize[j] = srcFieldSize[i]; + srcFieldSize[i] = tmpb; + + tmpb = channelIdx[j]; + channelIdx[j] = channelIdx[i]; + channelIdx[i] = tmpb; + } // if + } // for j + + srcShifter = ((srcFieldSize[0] << 24) | + (srcFieldSize[1] << 16) | + (srcFieldSize[2] << 8) | + (srcFieldSize[3])); + + dstShifter = ((dstShifters[channelIdx[0]] << 24) | + (dstShifters[channelIdx[1]] << 16) | + (dstShifters[channelIdx[2]] << 8) | + (dstShifters[channelIdx[3]])); + return; +} // ogPixCon::ogPixCon + +uInt32 +ogPixCon::ConvPix(uInt32 pixel) { + __asm__ __volatile__( + " xor %%ebx, %%ebx \n" // xor ebx, ebx + " xor %%edi, %%edi \n" // xor edi, edi + " \n" + " push %%eax \n" // push eax + " \n" + " and %%edx, %%esi \n" // and esi, edx + " xor %%eax, %%eax \n" // xor eax, eax + " xor %%edx, %%edx \n" // xor edx, edx + " \n" + " shrdl %%cl, %%esi, %%eax \n" // shrd eax, esi, cl + " shr %%cl, %%esi \n" // shr esi, cl + " mov %%ch, %%cl \n" // mov cl, ch + " shrdl %%cl, %%esi, %%ebx \n" // shrd ebx, esi, cl + " shr %%cl, %%esi \n" // shr esi, cl + " shr $16, %%ecx \n" // shr ecx, 16 + " shrdl %%cl, %%esi, %%edx \n" // shrd edx, esi, cl + " shr %%cl, %%esi \n" // shr esi, cl + " mov %%ch, %%cl \n" // mov cl, ch + " shrdl %%cl, %%esi, %%edi \n" // shrd edi, esi, cl + " \n" + " pop %%ecx \n" // pop ecx + " \n" + " shr %%cl, %%eax \n" // shr eax, cl + " shr $8, %%ecx \n" // shr ecx, 8 + " shr %%cl, %%ebx \n" // shr ebx, cl + " shr $8, %%ecx \n" // shr ecx, 8 + " shr %%cl, %%edx \n" // shr edx, cl + " shr $8, %%ecx \n" // shr ecx, 8 + " shr %%cl, %%edi \n" // shr edi, cl + " \n" + " or %%ebx, %%eax \n" // or eax, ebx + " or %%edi, %%edx \n" // or edx, edi + " nop \n" // nop + " or %%edx, %%eax \n" // or eax, edx + + : "=a" (pixel) // %0 + : "S" (pixel), "d" (srcMasker), // %1, %2 + "c" (srcShifter), "a" (dstShifter) // %3, %4 + // "ecx" (srcShifter), "eax" (dstShifter) // %2, %3 + ); + return pixel; +}; // ogPixCon::ConvPix diff --git a/src/lib/objgfx40/ogPixelFmt.cpp b/src/lib/objgfx40/ogPixelFmt.cpp new file mode 100644 index 0000000..8f25d98 --- /dev/null +++ b/src/lib/objgfx40/ogPixelFmt.cpp @@ -0,0 +1,35 @@ +#include +#include +#ifdef __UBIXOS_KERNEL__ +#include +#else +#include +#endif + +ogPixelFmt::ogPixelFmt(void) : BPP(0), + redFieldPosition(0), greenFieldPosition(0), + blueFieldPosition(0), alphaFieldPosition(0), + redMaskSize(0), greenMaskSize(0), + blueMaskSize(0), alphaMaskSize(0) { + for (int i = 0; i < 7; i++) reserved[i] = 0; + return; +} + +ogPixelFmt::ogPixelFmt(uInt8 bitsPerPix, + uInt8 RFP, uInt8 GFP, uInt8 BFP, uInt8 AFP, + uInt8 RMS, uInt8 GMS, uInt8 BMS, uInt8 AMS) { + + BPP = bitsPerPix; + redFieldPosition = RFP; + greenFieldPosition = GFP; + blueFieldPosition = BFP; + alphaFieldPosition = AFP; + redMaskSize = RMS; + greenMaskSize = GMS; + blueMaskSize = BMS; + alphaMaskSize = AMS; + + for (int i = 0; i < 7; i++) reserved[i] = 0; + + return; +} // ogPixelFmt::ogPixelFmt() diff --git a/src/lib/objgfx40/ogSprite.cpp b/src/lib/objgfx40/ogSprite.cpp new file mode 100644 index 0000000..72c6434 --- /dev/null +++ b/src/lib/objgfx40/ogSprite.cpp @@ -0,0 +1,702 @@ +extern "C" { + #include + #include + #include + } +#include +#include + +static bool +fileExists(const char *file) +{ + FILE *f = fopen(file, "rb"); + if (!f) + return false; + fclose(f); + return true; +} + +ogSprite::ogSprite(const ogSprite& srcSprite) { + image = NULL; + pal = NULL; + imageSize = 0; + width = 0; + height = 0; + bitDepth = 0; + RFP = 0; + GFP = 0; + BFP = 0; + AFP = 0; + rShift = 0; + gShift = 0; + bShift = 0; + aShift = 0; + tColour = 0; + pixelFmtID = 0; + bytesPerPixel = 0; + dAlpha = 0; + + if ((srcSprite.image == NULL) || (srcSprite.imageSize == 0)) return; + + // allocate space for the sprite + image = malloc(srcSprite.imageSize); + if (image == NULL) return; + + // copy the image size + imageSize = srcSprite.imageSize; + + if (srcSprite.pal != NULL) { + pal = new ogRGBA8[256]; + if (pal != NULL) memcpy(srcSprite.pal, pal, sizeof(ogRGBA8) * 256); + } // if + + width = srcSprite.width; + height = srcSprite.height; + bitDepth = srcSprite.bitDepth; + RFP = srcSprite.RFP; + GFP = srcSprite.GFP; + BFP = srcSprite.BFP; + AFP = srcSprite.AFP; + rShift = srcSprite.rShift; + gShift = srcSprite.gShift; + bShift = srcSprite.bShift; + aShift = srcSprite.aShift; + tColour = srcSprite.tColour; + pixelFmtID = srcSprite.bytesPerPixel; + dAlpha = srcSprite.dAlpha; + + return; +} // ogSprite::ogSprite + +ogSprite::ogSprite(void) { + image = NULL; + pal = NULL; + imageSize = 0; + width = 0; + height = 0; + bitDepth = 0; + RFP = 0; + GFP = 0; + BFP = 0; + AFP = 0; + rShift = 0; + gShift = 0; + bShift = 0; + aShift = 0; + tColour = 0; + pixelFmtID = 0; + bytesPerPixel = 0; + dAlpha = 0; + return; +} // ogSprite::ogSprite + +ogSprite & +ogSprite::operator=(ogSprite const & srcSprite) { + + if ((srcSprite.image == NULL) || (srcSprite.imageSize == NULL)) return *this; + + free(image); + delete [] pal; + + // allocate space for the sprite + image = malloc(srcSprite.imageSize); + + // this is such a bad case it should probably throw an exception + if (image == NULL) return *this; + + // copy the image size + imageSize = srcSprite.imageSize; + + if (srcSprite.pal != NULL) { + pal = new ogRGBA8[256]; + if (pal != NULL) memcpy(srcSprite.pal, pal, sizeof(ogRGBA8) * 256); + } // if + + width = srcSprite.width; + height = srcSprite.height; + bitDepth = srcSprite.bitDepth; + RFP = srcSprite.RFP; + GFP = srcSprite.GFP; + BFP = srcSprite.BFP; + AFP = srcSprite.AFP; + rShift = srcSprite.rShift; + gShift = srcSprite.gShift; + bShift = srcSprite.bShift; + aShift = srcSprite.aShift; + tColour = srcSprite.tColour; + pixelFmtID = srcSprite.bytesPerPixel; + dAlpha = srcSprite.dAlpha; + + return *this; +} +void +ogSprite::Get(ogSurface& srcObject, int32 x1, int32 y1, int32 x2, int32 y2) { + ogPixelFmt pixfmt; + uInt32 xx, yy, xOfs, yOfs; + uInt32 rx1, ry1, rx2, ry2; + uInt32 xCount, yCount, count; + void *p; + uInt32 maxX, maxY; + + if (!srcObject.ogAvail()) return; + + free(image); + free(pal); + + maxX = srcObject.ogGetMaxX(); + maxY = srcObject.ogGetMaxY(); + + srcObject.ogGetPixFmt(pixfmt); + + bitDepth = pixfmt.BPP; + RFP = pixfmt.redFieldPosition; + GFP = pixfmt.greenFieldPosition; + BFP = pixfmt.blueFieldPosition; + AFP = pixfmt.alphaFieldPosition; + rShift = 8-pixfmt.redMaskSize; + gShift = 8-pixfmt.greenMaskSize; + bShift = 8-pixfmt.blueMaskSize; + aShift = 8-pixfmt.alphaMaskSize; + + pixelFmtID = srcObject.ogGetPixFmtID(); + + dAlpha = srcObject.ogGetAlpha(); + tColour = srcObject.ogGetTransparentColor(); + + bytesPerPixel = srcObject.ogGetBytesPerPix(); + + if (bytesPerPixel == 1) { + if (pal == NULL) pal = new ogRGBA8[256]; + if (pal == NULL) return; + srcObject.ogGetPalette(pal); + /* for (count = 0; count < 256; count++) + srcObject.Unpack(count, + pal[count].red, + pal[count].green, + pal[count].blue, + pal[count].alpha); */ + +// memcpy(pal, srcObject.pal, sizeof(ogRGBA8)*256); + } // if + + if (x1 > x2) { + xx = x1; + x1 = x2; + x2 = xx; + } // if + + if (y1 > y2) { + yy = y1; + y1 = y2; + y2 = yy; + } // if + + xCount = abs(x2-x1)+1; + yCount = abs(y2-y1)+1; + width = xCount; + height = yCount; + imageSize = xCount*yCount*bytesPerPixel; + + image = malloc(imageSize); + p = image; + + if ( ((uInt32)x1 > maxX) || ((uInt32)y1 > maxY) || + ((uInt32)x2 > maxX) || ((uInt32)y2 > maxY) ) { + + for (count = 0; count < (xCount*yCount); count++) { + SetPixel(p, tColour); + (uInt8 *)p += bytesPerPixel; + } // for + p = image; // reset the pointer; + } // if + + xOfs = 0; + yOfs = 0; + + if (y1 < 0) { + yCount += y1; + ry1 = 0; + yOfs = xCount*abs(y1); + } else ry1 = y1; + + if (x1 < 0) { + xCount += x1; + rx1 = 0; + xOfs = abs(x1); + } else rx1 = x1; + + if (x2 > (int32)maxX) { + xCount -= maxX-x2+1; + rx2 = maxX; + } else rx2 = x2; + + if (y2 > (int32)maxY) { + yCount -= maxY-y2+1; + ry2 = maxY; + } else ry2 = y2; + + xCount *= bytesPerPixel; + + for (yy = 0; yy < yCount; yy++) { + ( (uInt8 *)p ) += xOfs; + srcObject.ogCopyLineFrom(rx1, ry1+yy, p, xCount); + ( (uInt8 *)p ) += xCount; + } + return; +} // ogSprite::Get + +uInt32 +ogSprite::GetPixel(void * p) { + uInt32 result; + switch (bytesPerPixel) { + case 4: + return *(uInt32 *)p; + break; + case 3: + asm( + " xor %%eax, %%eax \n" // xor eax, eax + " mov 2(%%edi),%%al \n" // mov al, [edi+2] + " shl $16, %%eax \n" // shl eax, 16 + " mov (%%edi), %%ax \n" // mov ax, [edi] + " mov %%eax, %1 \n" // mov result, eax + : + : "D" (p), "m" (result) + ); + return result; + break; + case 2: + return *(uInt16 *)p; + break; + case 1: + return *(uInt8 *)p; + break; + default: + return 0; + break; + } // switch +} // ogSprite::GetPixel + +void +ogSprite::SetPixel(void * p, uInt32 colour) { + + switch (bytesPerPixel) { + case 4: + *(uInt32 *)p = colour; + break; + case 3: + asm( + " mov %%ax, (%%edi) \n" // mov [edi], ax + " shr $16, %%eax \n" // shr eax, 16 + " mov %%al, 2(%%edi)\n" // mov [edi+2],al + : + : "D" (p), "a" (colour) + ); + break; + case 2: + *(uInt16 *)p = (uInt16)colour; + break; + case 1: + *(uInt8 *)p = (uInt8)colour; + break; + } // switch + return; +} // ogSprite::SetPixel + +uInt32 +ogSprite::GetSize(void) { + /* + * getSize + * + * returns the size of the image as it would take on disk. This includes + * all header related information (width/height, bitdepth, pixel format, + * etc) along with an extra sizeof(uInt32) + * for storing the complete size. This allows easy indexing of images, + * since you can figure out exactly how much the image will take up on + * disk. This function computes the size in the exact order it is on disk. + * If the image is 8bpp, then there is a 1024 byte palette stored after the + * image data along with an extra sizeof(uInt32) for the palette size in + * bytes. Currently we store the entire palette, but later I expect we + * will add the ability to optimize the palette so only used entries are + * stored. + * + * If you were to store a single sprite in a file, getSize would equal the + * filesize. + */ + uInt32 tmpsize; + char headerIdent[4]; + + tmpsize = sizeof(headerIdent)+ + sizeof(uInt32)+ // total size + sizeof(width)+sizeof(height)+ // width/height + sizeof(bitDepth)+ // bitDepth + sizeof(RFP)+sizeof(GFP)+sizeof(BFP)+sizeof(AFP)+ // field positions + sizeof(rShift)+sizeof(gShift)+sizeof(bShift)+sizeof(aShift)+ // shifters + sizeof(tColour)+ // tColour + sizeof(bytesPerPixel)+ // bytes per pixel + sizeof(pixelFmtID)+ // pixel format ID + sizeof(dAlpha)+ // default alpha + sizeof(imageSize)+ // image size in bytes + imageSize; // actual image area in bytes + if (bytesPerPixel == 1) tmpsize += sizeof(uInt32)+sizeof(ogRGBA8)*256; + return tmpsize; +} // ogSprite::GetSize + +bool +ogSprite::Load(const char * filename) { + return LoadFrom(filename,0); +} // ogSprite::Load + +bool +ogSprite::LoadFrom(const char * filename, uInt32 offset) { + FILE * infile; + uInt32 lresult, tresult, totSize; + uInt32 tmpSize; + char headerIdent[4]; + + if (!fileExists(filename)) return false; + if ((infile = fopen(filename,"rb")) == NULL) return false; + fseek(infile, offset, SEEK_SET); + + // for now just free up the previous image. This will be changed + // later so it doesn't affect the current image (if any) if there + // is a failure loading + + free(image); + free(pal); + + image = NULL; + imageSize = 0; + pal = NULL; + + tresult = 0; // total bytes we've read in so far + + lresult = fread(&headerIdent, sizeof(headerIdent), 1, infile); + tresult += lresult*sizeof(headerIdent); + if ((headerIdent[0] != 'S') || + (headerIdent[1] != 'P') || + (headerIdent[2] != 'R') || + (headerIdent[3] != (char)0x1A)) { + fclose(infile); + return false; + } + + lresult = fread(&totSize, sizeof(totSize), 1, infile); + tresult += lresult*sizeof(totSize); + + lresult = fread(&width, sizeof(width), 1, infile); + tresult += lresult*sizeof(width); + + lresult = fread(&height, sizeof(height), 1, infile); + tresult += lresult*sizeof(height); + + lresult = fread(&bitDepth, sizeof(bitDepth), 1, infile); + tresult += lresult*sizeof(bitDepth); + + lresult = fread(&RFP, sizeof(RFP), 1, infile); + tresult += lresult*sizeof(RFP); + + lresult = fread(&GFP, sizeof(GFP), 1, infile); + tresult += lresult*sizeof(GFP); + + lresult = fread(&BFP, sizeof(BFP), 1, infile); + tresult += lresult*sizeof(BFP); + + lresult = fread(&AFP, sizeof(AFP), 1, infile); + tresult += lresult*sizeof(AFP); + + lresult = fread(&rShift, sizeof(rShift), 1, infile); + tresult += lresult*sizeof(rShift); + + lresult = fread(&gShift, sizeof(gShift), 1, infile); + tresult += lresult*sizeof(gShift); + + lresult = fread(&bShift, sizeof(bShift), 1, infile); + tresult += lresult*sizeof(bShift); + + lresult = fread(&aShift, sizeof(aShift), 1, infile); + tresult += lresult*sizeof(aShift); + + lresult = fread(&tColour, sizeof(tColour), 1, infile); + tresult += lresult*sizeof(tColour); + + lresult = fread(&pixelFmtID, sizeof(pixelFmtID), 1, infile); + tresult += lresult*sizeof(pixelFmtID); + + lresult = fread(&bytesPerPixel, sizeof(bytesPerPixel), 1, infile); + tresult += lresult*sizeof(bytesPerPixel); + + lresult = fread(&dAlpha, sizeof(dAlpha), 1, infile); + tresult += lresult*sizeof(dAlpha); + + lresult = fread(&imageSize, sizeof(imageSize), 1, infile); + tresult += lresult*sizeof(imageSize); + + image = malloc(imageSize); + if (image == NULL) { + fclose(infile); + return false; + } + + // I suppose we could interchange the imageSize and record count to produce + // the number of bytes we read it... we'll try it this way for now. + lresult = fread(image, imageSize, 1, infile); + tresult += lresult*imageSize; + + if (bytesPerPixel == 1) { + // 8bpp sprites have palettes + if (pal == NULL) pal = new ogRGBA8[256]; + if (pal == NULL) { + fclose(infile); + return false; + } // if pal==NULL + + lresult = fread(&tmpSize, sizeof(tmpSize), 1, infile); + tresult += lresult*sizeof(tmpSize); + + if (tmpSize > sizeof(ogRGBA8)*256) { + fclose(infile); + return false; + } // if + + lresult = fread(pal, tmpSize, 1, infile); + tresult += lresult*tmpSize; + } // if bytesPerPixel == 1 + + fclose(infile); + return (tresult == totSize); +} // ogSprite::LoadFrom; + +void +ogSprite::Put(ogSurface& destObject, int32 x, int32 y) { + uInt32 xx, yy; + int32 xCount, yCount; + uInt32 yOfs; + uInt32 xLeft, xRight; + int32 maxX, maxY; + void * p; + uInt8 r, g, b, a; + ogPixelFmt pixfmt; + + if (image == NULL) return; + if (!destObject.ogAvail()) return; + + maxX = destObject.ogGetMaxX(); + maxY = destObject.ogGetMaxY(); + + xCount = width; + yCount = height; + + // check to see if the image is totally off the screen + if ((x+xCount < 0) || (y+yCount < 0) || + (x > (int32)maxX) || (y > (int32)maxY)) return; + + p = image; + + if (y < 0) { + yOfs = abs(y)*xCount*bytesPerPixel; + yCount += y; + y = 0; + } else yOfs = 0; + + if (x < 0) { + xLeft = abs(x)*bytesPerPixel; + xCount += x; + x = 0; + } else xLeft = 0; + + if (x+xCount > maxX) { + xRight = (xCount - (maxX-x+1))*bytesPerPixel; + xCount = (maxX-x)+1; + } else xRight = 0; + + if ((y+yCount) > maxY) yCount = (maxY-y)+1; + + destObject.ogGetPixFmt(pixfmt); + + (uInt8 *)p += yOfs; + + if ((destObject.ogGetPixFmtID() != pixelFmtID) || (destObject.ogIsBlending())) { + + for (yy = 0; yy < (uInt32)yCount; yy++) { + (uInt8 *)p += xLeft; + + for (xx = 0; xx < (uInt32)xCount; xx++) { + Unpack(GetPixel(p), r, g, b, a); + (uInt8 *)p += bytesPerPixel; + // this could probably be rawSetPixelRGBA instead + destObject.ogSetPixel(x+xx, y+yy, r, g, b, a); + } // for + + (uInt8 *)p += xRight; + } // for yy + + } else { // pixel formats match + xCount *= bytesPerPixel; + + for (yy = 0; yy < (uInt32)yCount; yy++) { + (uInt8 *)p += xLeft; + destObject.ogCopyLineTo(x, y+yy, p, xCount); + (uInt8 *)p += xCount; + (uInt8 *)p += xRight; + } // for + + } // else + return; +} // ogSurface::Put + +bool +ogSprite::Save(const char * filename) { + return SaveTo(filename, 0); +} // ogSprite::Save + +bool +ogSprite::SaveTo(const char * filename, int32 offset) { + /* + * saveTo + * + * saves a bitmap to disk. If the file doesn't exit then we will create + * a new one (doing this will ignore any specified offset). If the file + * exists, we will seek to the specified offset and place the bitmap there. + * If offset is -1, then we seek to the end of the file. + * + * This function will fail on files larger than 2GB. + * + */ + FILE * outfile = NULL; + char headerIdent[4]; + uInt32 tmpSize; + + if (image == NULL) return false; + if ((bytesPerPixel == 1) && (pal == NULL)) return false; + + if (!fileExists(filename)) { // file doesn't exist + if ((outfile = fopen(filename,"wb")) == NULL) return false; + } else { + // file exists. Now we check to see where we put it + if (offset == -1) { + if ((outfile = fopen(filename, "ab")) == NULL) return false; + } else { + // we have an existing file and an offset to place the data + if ((outfile = fopen(filename, "wb")) == NULL) return false; + if (offset != 0) fseek(outfile, offset, SEEK_SET); + } // else + } // else + + headerIdent[0] = 'S'; + headerIdent[1] = 'P'; + headerIdent[2] = 'R'; + headerIdent[3] = (char)0x1A; // EOF marker + + // we store exactly how bit this sucker is inside the header. This includes + // the header information before it, and the size itself + tmpSize = GetSize(); + fwrite(headerIdent, sizeof(headerIdent), 1, outfile); + + fwrite(&tmpSize, sizeof(tmpSize), 1, outfile); + fwrite(&width, sizeof(width), 1, outfile); + fwrite(&height, sizeof(height), 1, outfile); + fwrite(&bitDepth, sizeof(bitDepth), 1, outfile); + + fwrite(&RFP, sizeof(RFP), 1, outfile); + fwrite(&GFP, sizeof(GFP), 1, outfile); + fwrite(&BFP, sizeof(BFP), 1, outfile); + fwrite(&AFP, sizeof(AFP), 1, outfile); + + fwrite(&rShift, sizeof(rShift), 1, outfile); + fwrite(&gShift, sizeof(gShift), 1, outfile); + fwrite(&bShift, sizeof(bShift), 1, outfile); + fwrite(&aShift, sizeof(aShift), 1, outfile); + + fwrite(&tColour, sizeof(tColour), 1, outfile); + fwrite(&pixelFmtID, sizeof(pixelFmtID), 1, outfile); + fwrite(&bytesPerPixel, sizeof(bytesPerPixel), 1, outfile); + fwrite(&dAlpha, sizeof(dAlpha), 1, outfile); + + fwrite(&imageSize, sizeof(imageSize), 1, outfile); + fwrite(image, imageSize, 1, outfile); + + if (bytesPerPixel == 1) { + tmpSize = sizeof(ogRGBA8)*256; + fwrite(&tmpSize, sizeof(tmpSize), 1, outfile); + fwrite(pal, sizeof(ogRGBA8), 256, outfile); + } // if bytesPerPixel == 1 + + fclose(outfile); + return true; +} // ogSprite::SaveTo + +void +ogSprite::Unpack(uInt32 colour, uInt8& red, uInt8& green, uInt8& blue, + uInt8& alpha) { + switch (bytesPerPixel) { + case 4: + red = (uInt8)(colour >> RFP); + green = (uInt8)(colour >> GFP); + blue = (uInt8)(colour >> BFP); + alpha = (uInt8)(colour >> AFP); + break; + case 3: + red = (uInt8)(colour >> RFP); + green = (uInt8)(colour >> GFP); + blue = (uInt8)(colour >> BFP); + alpha = dAlpha; + break; + case 2: + red = (uInt8)(colour >> RFP) << rShift; + green = (uInt8)(colour >> GFP) << gShift; + blue = (uInt8)(colour >> BFP) << bShift; + if (red != 0) red += OG_MASKS[rShift]; + if (green != 0) green += OG_MASKS[gShift]; + if (blue != 0) blue += OG_MASKS[bShift]; + + if (aShift != 8) { + alpha = (uInt8)(colour >> AFP) << aShift; + if (alpha != 0) alpha += OG_MASKS[aShift]; + } else alpha = dAlpha; + + break; + case 1: + + if (pal == NULL) { + red = green = blue = alpha = 0; + return; + } // if + + if (colour > 255) colour &= 255; + red = pal[colour].red; + green = pal[colour].green; + blue = pal[colour].blue; + alpha = pal[colour].alpha; + break; + default: + red = green = blue = alpha = 0; + break; + } // switch + return; +} // ogSprite::Unpack + +ogSprite::~ogSprite(void) { + free(image); + delete [] pal; + image = NULL; + pal = NULL; + imageSize = 0; + width = 0; + height = 0; + bitDepth = 0; + RFP = 0; + GFP = 0; + BFP = 0; + AFP = 0; + rShift = 0; + gShift = 0; + bShift = 0; + aShift = 0; + tColour = 0; + pixelFmtID= 0; + bytesPerPixel = 0; + dAlpha = 0; + return; +} // ogSprite::~ogSprite + + diff --git a/src/lib/objgfx40/rh_opt.gdt b/src/lib/objgfx40/rh_opt.gdt new file mode 100644 index 0000000..26ed536 --- /dev/null +++ b/src/lib/objgfx40/rh_opt.gdt Binary files differ diff --git a/src/lib/objgfx40/rh_opt.gpr b/src/lib/objgfx40/rh_opt.gpr new file mode 100644 index 0000000..a438c71 --- /dev/null +++ b/src/lib/objgfx40/rh_opt.gpr Binary files differ diff --git a/src/lib/objgfx40/rh_opt.mak b/src/lib/objgfx40/rh_opt.mak new file mode 100644 index 0000000..1d41e21 --- /dev/null +++ b/src/lib/objgfx40/rh_opt.mak @@ -0,0 +1,356 @@ +# This file is automatically generated by RHIDE 1.4.9 +# created from within RHIDE +FLAGS_FOR_SUBPROJECTS=RHIDE_OS_="$(RHIDE_OS_)" CFLAGS="$(CFLAGS)"\ + CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" CPPFLAGS="$(CPPFLAGS)" +RHIDE_OS=$(RHIDE_OS_) +ifeq ($(strip $(RHIDE_OS)),) +ifneq ($(strip $(DJDIR)),) +RHIDE_OS_:=DJGPP +else +RHIDE_OS_:=$(patsubst CYGWIN%,CYGWIN,$(shell uname)) +endif +endif + +INCLUDE_DIRS= +LIB_DIRS= +C_DEBUG_FLAGS= +C_OPT_FLAGS=-O4 +C_WARN_FLAGS=-pedantic -Wmain -Wparentheses -Wreturn-type -Wuninitialized\ + -Wall -W -Wpointer-arith -Wmissing-prototypes -Wredundant-decls +C_C_LANG_FLAGS= +C_CXX_LANG_FLAGS= +C_P_LANG_FLAGS= +C_FPC_LANG_FLAGS= +C_F_LANG_FLAGS= +C_ADA_LANG_FLAGS= +LIBS= +LD_EXTRA_FLAGS=-g +C_EXTRA_FLAGS=-Wno-long-long +LOCAL_OPT=$(subst ___~~~___, ,$(subst $(notdir $<)___,,$(filter $(notdir\ + $<)___%,$(LOCAL_OPTIONS)))) + +OBJFILES=main.o objgfx30.o ogBlit.o ogDisplay_VESA.o ogFont.o ogSprite.o +ALL_OBJFILES=main.o objgfx30.o ogBlit.o ogDisplay_VESA.o ogFont.o\ + ogSprite.o +LIBRARIES= +SOURCE_NAME=$< +OUTFILE=$@ +SPECIAL_CFLAGS= +SPECIAL_LDFLAGS= +PROG_ARGS= +SRC_DIRS= +WUC= +EDITORS= +MAIN_TARGET=objgfx.exe +PROJECT_ITEMS=main.cpp objgfx30.cpp ogBlit.cpp ogDisplay_VESA.cpp\ + ogFont.cpp ogSprite.cpp +DEFAULT_MASK=*.cpp +RHIDE_BIN_DIR=c:/djgpp/bin +PASCAL_TYPE=GPC +GET_HOME=$(HOME) +CLEAN_FILES=$(MAIN_TARGET) $(OBJFILES) +RHIDE_GCC=gcc +RHIDE_AS=gcc +RHIDE_GXX=gcc +RHIDE_GPC=gpc +RHIDE_FPC=ppc386 +RHIDE_AR=ar +RHIDE_LD=gcc +RHIDE_G77=g77 +RHIDE_NASM=nasm +RHIDE_LD_PASCAL=gpc +RHIDE_LD_FPC=$(RHIDE_FPC) -E+ +RHIDE_GNATBIND=gnatbind +RHIDE_RM=rm +RHIDE_ARFLAGS=rcs +RHIDE_TYPED_LIBS.f=g2c m +RHIDE_TYPED_LIBS.for=$(RHIDE_TYPED_LIBS.f) +RHIDE_TYPED_LIBS.F=$(RHIDE_TYPED_LIBS.f) +RHIDE_TYPED_LIBS.fpp=$(RHIDE_TYPED_LIBS.f) +RHIDE_TYPED_LIBS_GPC=gpc m +RHIDE_TYPED_LIBS_FPC=fpc +RHIDE_TYPED_LIBS.p=$(RHIDE_TYPED_LIBS_$(PASCAL_TYPE)) +RHIDE_TYPED_LIBS.pas=$(RHIDE_TYPED_LIBS.p) +RHIDE_TYPED_LIBS.pp=$(RHIDE_TYPED_LIBS_FPC) +RHIDE_TYPED_LIBS_$(RHIDE_OS).cc=stdc++ +RHIDE_TYPED_LIBS_DJGPP.cc=stdcxx m +RHIDE_TYPED_LIBS_DJGPP.cc=stdcxx m +RHIDE_TYPED_LIBS.cc=$(RHIDE_TYPED_LIBS_$(RHIDE_OS).cc) +RHIDE_TYPED_LIBS.cpp=$(RHIDE_TYPED_LIBS.cc) +RHIDE_TYPED_LIBS.cxx=$(RHIDE_TYPED_LIBS.cc) +RHIDE_TYPED_LIBS.C=$(RHIDE_TYPED_LIBS.cc) +RHIDE_TYPED_LIBS.ii=$(RHIDE_TYPED_LIBS.cc) +RHIDE_TYPED_LIBS.l=fl +RHIDE_TYPED_LIBS.m=objc +RHIDE_TYPED_LIBS.adb=gnat +RHIDE_TYPED_LIBS_SUFFIXES=$(sort $(foreach item,$(PROJECT_ITEMS),$(suffix\ + $(item)))) +RHIDE_TYPED_LIBS=$(foreach\ + suff,$(RHIDE_TYPED_LIBS_SUFFIXES),$(RHIDE_TYPED_LIBS$(suff))) +RHIDE_INCLUDES=$(SPECIAL_CFLAGS) $(addprefix -I,$(INCLUDE_DIRS)) +RHIDE_LIBDIRS=$(addprefix -L,$(LIB_DIRS)) +RHIDE_LIBS=$(addprefix -l,$(LIBS) $(RHIDE_TYPED_LIBS) $(RHIDE_OS_LIBS)) +RHIDE_LDFLAGS=$(SPECIAL_LDFLAGS) $(addprefix -Xlinker ,$(LD_EXTRA_FLAGS)) +RHIDE_NASM_TARGET_DJGPP=coff +RHIDE_NASM_TARGET_Linux=elf +RHIDE_NASM_TARGET=$(RHIDE_NASM_TARGET_$(RHIDE_OS)) +RHIDE_COMPILE_NASM=$(RHIDE_NASM) -f $(RHIDE_NASM_TARGET) $(LOCAL_OPT) -o\ + $(OUTFILE) $(SOURCE_NAME) +RHIDE_COMPILE_FORTRAN=$(RHIDE_G77) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_F_LANG_FLAGS) $(C_EXTRA_FLAGS)\ + $(LOCAL_OPT) -c $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_COMPILE_FORTRAN_FORCE=$(RHIDE_G77) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_F_LANG_FLAGS) $(C_EXTRA_FLAGS)\ + -x f77 $(LOCAL_OPT) -c $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_COMPILE_C=$(RHIDE_GCC) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_C_LANG_FLAGS) $(C_EXTRA_FLAGS)\ + $(RHIDE_OS_CFLAGS) $(CPPFLAGS) $(CFLAGS) $(LOCAL_OPT) -c\ + $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_COMPILE_C_FORCE=$(RHIDE_GCC) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_C_LANG_FLAGS) $(C_EXTRA_FLAGS)\ + -x c $(RHIDE_OS_CFLAGS) $(CPPFLAGS) $(CFLAGS) $(LOCAL_OPT) -c\ + $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_COMPILE_CC=$(RHIDE_GXX) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_C_LANG_FLAGS)\ + $(C_CXX_LANG_FLAGS) $(C_EXTRA_FLAGS) $(RHIDE_OS_CXXFLAGS)\ + $(CPPFLAGS) $(CXXFLAGS) $(LOCAL_OPT) -c $(SOURCE_NAME) -o\ + $(OUTFILE) +RHIDE_COMPILE_CC_FORCE=$(RHIDE_GXX) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_C_LANG_FLAGS)\ + $(C_CXX_LANG_FLAGS) $(C_EXTRA_FLAGS) $(RHIDE_OS_CXXFLAGS)\ + $(CPPFLAGS) $(CXXFLAGS) -x c++ $(LOCAL_OPT) -c $(SOURCE_NAME) -o\ + $(OUTFILE) +RHIDE_COMPILE_ASM=$(RHIDE_AS) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_EXTRA_FLAGS) $(LOCAL_OPT) -c\ + $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_COMPILE_ASM_FORCE=$(RHIDE_AS) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_EXTRA_FLAGS) -x assembler\ + $(LOCAL_OPT) -c $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_GPC_FLAGS=$(RHIDE_INCLUDES) $(C_DEBUG_FLAGS) $(C_OPT_FLAGS)\ + $(C_WARN_FLAGS) $(C_P_LANG_FLAGS) $(C_EXTRA_FLAGS) +RHIDE_COMPILE_GPC=$(RHIDE_GPC) $(RHIDE_GPC_FLAGS) $(LOCAL_OPT) -c\ + $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_COMPILE_GPC_FORCE=$(RHIDE_GPC) $(RHIDE_GPC_FLAGS) -x pascal\ + $(LOCAL_OPT) -c $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_FPC_FLAGS=$(C_FPC_LANG_FLAGS) $(LOCAL_OPT) $(addprefix\ + -Up,$(INCLUDE_DIRS)) $(C_EXTRA_FLAGS) +RHIDE_COMPILE_FPC=$(RHIDE_FPC) $(RHIDE_FPC_FLAGS) -E- $(SOURCE_NAME) +RHIDE_COMPILE_FPC_FORCE=$(RHIDE_FPC) $(RHIDE_FPC_FLAGS) -B -E-\ + $(SOURCE_NAME) +RHIDE_COMPILE_LINK=$(RHIDE_LD) $(RHIDE_LIBDIRS) $(C_EXTRA_FLAGS) -o\ + $(OUTFILE) $(OBJFILES) $(LIBRARIES) $(LDFLAGS) $(RHIDE_LDFLAGS)\ + $(RHIDE_LIBS) +RHIDE_COMPILE_LINK_GPC=$(RHIDE_LD_PASCAL) $(RHIDE_LIBDIRS) $(C_EXTRA_FLAGS)\ + -o $(OUTFILE) $(OBJFILES) $(LIBRARIES) $(RHIDE_LDFLAGS) $(LDFLAGS)\ + $(RHIDE_LIBS) +RHIDE_COMPILE_LINK_GPC_AUTOMAKE=$(RHIDE_LD_PASCAL) $(RHIDE_LIBDIRS) -o\ + $(OUTFILE) --automake $(RHIDE_GPC_FLAGS) $(SOURCE_NAME)\ + $(LIBRARIES) $(LDFLAGS) $(RHIDE_LDFLAGS) $(RHIDE_LIBS) +RHIDE_COMPILE_PASCAL=$(RHIDE_COMPILE_$(PASCAL_TYPE)) +RHIDE_COMPILE_PASCAL_FORCE=$(RHIDE_COMPILE_$(PASCAL_TYPE)_FORCE) +RHIDE_COMPILE_LINK_PASCAL_AUTOMAKE=$(RHIDE_COMPILE_LINK_$(PASCAL_TYPE)_AUTOMAKE) +RHIDE_COMPILE_LINK_PASCAL=$(RHIDE_COMPILE_LINK_$(PASCAL_TYPE)) +RHIDE_FPC_LIBDIRS_$(RHIDE_OS)=/usr/local/lib /usr/lib /lib +RHIDE_FPC_LIBDIRS_DJGPP=/usr/local/lib /usr/lib /lib +RHIDE_FPC_LIBDIRS_DJGPP=$(DJDIR)/lib +RHIDE_FPC_LIBDIRS=$(RHIDE_FPC_LIBDIRS_$(RHIDE_OS)) +RHIDE_FPC_LINK_FLAGS_$(RHIDE_OS)=$(RHIDE_LIBDIRS) $(addprefix\ + -L,$(RHIDE_FPC_LIBDIRS)) +RHIDE_FPC_LINK_FLAGS_DJGPP=$(RHIDE_LIBDIRS) $(addprefix\ + -L,$(RHIDE_FPC_LIBDIRS)) +RHIDE_FPC_LINK_FLAGS_DJGPP=-O coff-go32-exe $(RHIDE_LIBDIRS) $(addprefix\ + -L,$(RHIDE_FPC_LIBDIRS)) +RHIDE_FPC_LINK_FLAGS=$(RHIDE_FPC_LINK_FLAGS_$(RHIDE_OS)) +RHIDE_COMPILE_LINK_FPC=echo 'separate linking for FPK is not supported.\ + Please define a main source file in Project/Primary file.' 1>&2 +RHIDE_COMPILE_LINK_FPC_AUTOMAKE=$(RHIDE_FPC) -o$(OUTFILE) $(SOURCE_NAME)\ + $(RHIDE_FPC_FLAGS) -E+ +RHIDE_COMPILE_ARCHIVE=$(RHIDE_AR) $(RHIDE_ARFLAGS) $(OUTFILE)\ + $(ALL_OBJFILES) +RHIDE_COMPILE_ADA=$(RHIDE_GCC) $(RHIDE_INCLUDES) $(C_DEBUG_FLAGS)\ + $(C_OPT_FLAGS) $(C_WARN_FLAGS) $(C_C_LANG_FLAGS) $(C_EXTRA_FLAGS)\ + $(LOCAL_OPT) $(C_ADA_LANG_FLAGS) $(RHIDE_OS_CFLAGS) $(CPPFLAGS)\ + $(CFLAGS) -c $(SOURCE_NAME) -o $(OUTFILE) +RHIDE_ADA_BIND_FILE=$(addprefix _,$(setsuffix .c,$(OUTFILE))) +RHIDE_COMPILE_LINK_ADA_BIND=$(RHIDE_GNATBIND) -o $(RHIDE_ADA_BIND_FILE)\ + $(setsuffix .ali,$(OUTFILE)) +RHIDE_COMPILE_LINK_ADA_LINK=$(RHIDE_LD) $(RHIDE_LIBDIRS) $(C_EXTRA_FLAGS) -o\ + $(OUTFILE) $(RHIDE_ADA_BIND_FILE) $(OBJFILES) $(LIBRARIES)\ + $(LDFLAGS) $(RHIDE_LDFLAGS) $(RHIDE_LIBS) +_RHIDE_COMPILE_LINK_ADA=$(RHIDE_COMPILE_LINK_ADA_BIND);\ + $(RHIDE_COMPILE_LINK_ADA_LINK); $(RHIDE_RM)\ + $(RHIDE_ADA_BIND_FILE) +RHIDE_COMPILE_LINK_ADA=gnatbl $(RHIDE_LIBDIRS) $(C_EXTRA_FLAGS) -o\ + $(OUTFILE) $(setsuffix .ali,$(OUTFILE)) $(LIBRARIES) $(LDFLAGS) \ + $(RHIDE_LDFLAGS) $(RHIDE_LIBS) +RHIDE_COMPILE.c.o=$(RHIDE_COMPILE_C) +RHIDE_COMPILE.cc.o=$(RHIDE_COMPILE_CC) +RHIDE_COMPILE.p.o=$(RHIDE_COMPILE_PASCAL) +RHIDE_COMPILE.pas.o=$(RHIDE_COMPILE.p.o) +RHIDE_COMPILE.pp.o=$(RHIDE_COMPILE_FPC) +RHIDE_COMPILE.pas.s.GPC=$(subst -c $(SOURCE_NAME),-S\ + $(SOURCE_NAME),$(RHIDE_COMPILE_GPC)) +RHIDE_COMPILE.pas.s.FPC=$(RHIDE_COMPILE_FPC) -a -s +RHIDE_COMPILE.pas.s=$(RHIDE_COMPILE.pas.s.$(PASCAL_TYPE)) +RHIDE_COMPILE.f.o=$(RHIDE_COMPILE_FORTRAN) +RHIDE_COMPILE.nsm.o=$(RHIDE_COMPILE_NASM) +RHIDE_COMPILE.s.o=$(RHIDE_COMPILE_ASM) +RHIDE_COMPILE.c.s=$(subst -c $(SOURCE_NAME),-S\ + $(SOURCE_NAME),$(RHIDE_COMPILE_C)) +RHIDE_COMPILE.c.i=$(subst -c $(SOURCE_NAME),-E\ + $(SOURCE_NAME),$(RHIDE_COMPILE_C)) +RHIDE_COMPILE.i.s=$(RHIDE_COMPILE.c.s) +RHIDE_COMPILE.cc.s=$(subst -c $(SOURCE_NAME),-S\ + $(SOURCE_NAME),$(RHIDE_COMPILE_CC)) +RHIDE_COMPILE.cc.ii=$(subst -c $(SOURCE_NAME),-E\ + $(SOURCE_NAME),$(RHIDE_COMPILE_CC)) +RHIDE_COMPILE.ii.s=$(RHIDE_COMPILE.cc.s) +RHIDE_COMPILE.cpp.o=$(RHIDE_COMPILE.cc.o) +RHIDE_COMPILE.cxx.o=$(RHIDE_COMPILE.cc.o) +RHIDE_COMPILE.C.o=$(RHIDE_COMPILE.cc.o) +RHIDE_COMPILE.pas.o=$(RHIDE_COMPILE.p.o) +RHIDE_COMPILE.for.o=$(RHIDE_COMPILE.f.o) +RHIDE_COMPILE.F.o=$(RHIDE_COMPILE.f.o) +RHIDE_COMPILE.fpp.o=$(RHIDE_COMPILE.f.o) +RHIDE_COMPILE.asm.o=$(RHIDE_COMPILE.nsm.o) +RHIDE_COMPILE.cpp.s=$(RHIDE_COMPILE.cc.s) +RHIDE_COMPILE.cxx.s=$(RHIDE_COMPILE.cc.s) +RHIDE_COMPILE.C.s=$(RHIDE_COMPILE.cc.s) +RHIDE_COMPILE.cpp.ii=$(RHIDE_COMPILE.cc.ii) +RHIDE_COMPILE.cxx.ii=$(RHIDE_COMPILE.cc.ii) +RHIDE_COMPILE.C.ii=$(RHIDE_COMPILE.cc.ii) +RHIDE_COMPILE.adb.o=$(RHIDE_COMPILE_ADA) +RHIDE_FSDB=fsdb $(OUTFILE) $(addprefix -p ,$(SRC_DIRS)) $(PROG_ARGS) +RHIDE_GDB=gdb $(OUTFILE) $(addprefix -d ,$(SRC_DIRS)) +DEFAULT_GREP_MASK=*.[cfhmnps]* +RHIDE_GREP=grep -n $(prompt arguments for GREP,$(WUC) $(DEFAULT_GREP_MASK)) +RHIDE_GPROF=gprof $(OUTFILE) +RHIDE_RLOG=$(shell rlog -R $(rlog_arg)) +RHIDE_CO=$(shell co -q $(co_arg)) +RHIDE_STANDARD_INCLUDES_$(RHIDE_OS)=$(addprefix /usr/,include include/sys\ + include/g++ include/g++/std) +RHIDE_STANDARD_INCLUDES_DJGPP=$(addprefix /usr/,include include/sys\ + include/g++ include/g++/std) +RHIDE_STANDARD_INCLUDES_DJGPP=$(addprefix $(DJDIR)/,include include/sys\ + lang/cxx lang/cxx/std) +RHIDE_STANDARD_INCLUDES=$(RHIDE_STANDARD_INCLUDES_$(RHIDE_OS)) +RHIDE_CONFIG_DIRS_$(RHIDE_OS)=/usr/local/share/rhide /usr/share/rhide \ + /local/share/rhide /share/rhide +RHIDE_CONFIG_DIRS_DJGPP=/usr/local/share/rhide /usr/share/rhide \ + /local/share/rhide /share/rhide +RHIDE_CONFIG_DIRS_DJGPP=$(DJDIR)/share/rhide +RHIDE_CONFIG_DIRS_COMMON=$(RHIDE_CONFIG_DIRS_$(RHIDE_OS))\ + $(RHIDE_BIN_DIR)/../share/rhide +RHIDE_CONFIG_DIRS=. $(RHIDE_SHARE) $(GET_HOME) $(RHIDE_CONFIG_DIRS_COMMON)\ + $(addsuffix /SET,$(RHIDE_CONFIG_DIRS_COMMON)) $(SET_FILES) +RHIDE_PATH_SEPARATOR_$(RHIDE_OS)=: +RHIDE_PATH_SEPARATOR_DJGPP=: +RHIDE_PATH_SEPARATOR_DJGPP=; +RHIDE_PATH_SEPARATOR=$(RHIDE_PATH_SEPARATOR_$(RHIDE_OS)) +RHIDE_EMPTY= +RHIDE_SPACE=$(RHIDE_EMPTY) $(RHIDE_EMPTY) +RHIDE_TYPED_LIBS_DJGPP.cc=stdcxx m +RHIDE_TYPED_LIBS_DJGPP.cxx=stdcxx m +RHIDE_TYPED_LIBS_DJGPP.cpp=stdcxx m +RHIDE_TYPED_LIBS.f=g2c m +%.o: %.c + $(RHIDE_COMPILE.c.o) +%.o: %.i + $(RHIDE_COMPILE_C) +%.o: %.cc + $(RHIDE_COMPILE.cc.o) +%.o: %.cpp + $(RHIDE_COMPILE.cpp.o) +%.o: %.cxx + $(RHIDE_COMPILE.cxx.o) +%.o: %.C + $(RHIDE_COMPILE.C.o) +%.o: %.ii + $(RHIDE_COMPILE_CC) +%.o: %.s + $(RHIDE_COMPILE.s.o) +%.o: %.S + $(RHIDE_COMPILE_ASM) +%.s: %.c + $(RHIDE_COMPILE.c.s) +%.s: %.i + $(RHIDE_COMPILE.i.s) +%.s: %.cc + $(RHIDE_COMPILE.cc.s) +%.s: %.cpp + $(RHIDE_COMPILE.cpp.s) +%.s: %.cxx + $(RHIDE_COMPILE.cxx.s) +%.s: %.C + $(RHIDE_COMPILE.C.s) +%.o: %.pas + $(RHIDE_COMPILE.pas.o) +%.o: %.p + $(RHIDE_COMPILE.p.o) +%.o: %.pp + $(RHIDE_COMPILE.pp.o) +%.s: %.pas + $(RHIDE_COMPILE.pas.s) +%.o: %.m + $(RHIDE_COMPILE_OBJC) +%.o: %.f + $(RHIDE_COMPILE.f.o) +%.o: %.for + $(RHIDE_COMPILE.for.o) +%.o: %.F + $(RHIDE_COMPILE.F.o) +%.o: %.fpp + $(RHIDE_COMPILE.fpp.o) +%.o: %.asm + $(RHIDE_COMPILE.asm.o) +%.o: %.nsm + $(RHIDE_COMPILE.nsm.o) +%.o: %.adb + $(RHIDE_COMPILE.adb.o) +%.i: %.c + $(RHIDE_COMPILE.c.i) +%.s: %.c + $(RHIDE_COMPILE.c.s) +%.ii: %.cc + $(RHIDE_COMPILE.cc.ii) +%.s: %.cc + $(RHIDE_COMPILE.cc.s) +%.ii: %.cpp + $(RHIDE_COMPILE.cpp.ii) +%.s: %.cpp + $(RHIDE_COMPILE.cpp.s) +%.ii: %.cxx + $(RHIDE_COMPILE.cxx.ii) +%.s: %.cxx + $(RHIDE_COMPILE.cxx.s) +%.ii: %.C + $(RHIDE_COMPILE.C.ii) +%.s: %.C + $(RHIDE_COMPILE.C.s) +clean:: + rm -f $(CLEAN_FILES) +DEPS_0= main.o objgfx30.o ogBlit.o ogDisplay_VESA.o ogFont.o ogSprite.o +NO_LINK= +LINK_FILES=$(filter-out $(NO_LINK),$(DEPS_0)) +objgfx.exe:: $(DEPS_0) + $(RHIDE_COMPILE_LINK) +DEPS_1=main.cpp +main.o:: $(DEPS_1) + $(RHIDE_COMPILE.cpp.o) +DEPS_2=objgfx30.cpp +objgfx30.o:: $(DEPS_2) + $(RHIDE_COMPILE.cpp.o) +DEPS_3=ogBlit.cpp +ogBlit.o:: $(DEPS_3) + $(RHIDE_COMPILE.cpp.o) +DEPS_4=ogDisplay_VESA.cpp +ogDisplay_VESA.o:: $(DEPS_4) + $(RHIDE_COMPILE.cpp.o) +DEPS_5=ogFont.cpp +ogFont.o:: $(DEPS_5) + $(RHIDE_COMPILE.cpp.o) +DEPS_6=ogSprite.cpp +ogSprite.o:: $(DEPS_6) + $(RHIDE_COMPILE.cpp.o) +all:: objgfx.exe + \ No newline at end of file diff --git a/src/lib/objgfx40/vWidget.cpp b/src/lib/objgfx40/vWidget.cpp new file mode 100644 index 0000000..a528250 --- /dev/null +++ b/src/lib/objgfx40/vWidget.cpp @@ -0,0 +1,9 @@ +#include + +bool +vWidget::vSetActive(bool _active) { + bool result = active; + active = _active; + return result; +} // vWidget::vSetActive + diff --git a/src/lib/objgfx40/vWindow.cpp b/src/lib/objgfx40/vWindow.cpp new file mode 100644 index 0000000..5e4da43 --- /dev/null +++ b/src/lib/objgfx40/vWindow.cpp @@ -0,0 +1,44 @@ +extern "C" { + #include + } +#include + +vWindow::vWindow(void) { + realWindow = new ogSurface(); + titleFont = new ogBitFont(); + return; +} // vWindow::vWindow + +bool +vWindow::vCreate(void) { + if (realWindow->Create(400,400,OG_PIXFMT_16BPP) == false) return false; + if (Alias(*realWindow, // window + 0, 0, // [x1, y1] + realWindow->GetMaxX(), realWindow->GetMaxY()) // [x2, y2] + == false) return false; + return true; +} // vWindow::vCreate + +void +vWindow::vSDECommand(uInt32 command) { + asm( + "int %0" + : + : "i" (0x80),"a" (40),"b" (command),"c" (realWindow) + ); + return; +} // vWindow::vSDECommand + +vWindow::~vWindow() { + delete realWindow; + delete titleFont; + return; +} // vWindow::~vWindow + +/* +ogSurface -> vWidget -> vWindow + | \------> vButton + | + | + -- ogDisplay_UbixOS -> SDE +*/ diff --git a/src/lib/ubix/Makefile b/src/lib/ubix/Makefile new file mode 100644 index 0000000..1f49f18 --- /dev/null +++ b/src/lib/ubix/Makefile @@ -0,0 +1,35 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Binary File Name +BINARY = none + +#Objects +OBJS = startup.o + +# Make the Binary +$(BINARY) : $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) -Wall -fomit-frame-pointer -O -I../libc/include -c -o $@ $< + +.cc.s: + $(CXX) -Wall -fomit-frame-pointer -O -I../libc/include -S -o $@ $< + +.c.o: + $(CC) -Wall -O -I../libc/include -c -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O -I../libc/include -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(BINARY) diff --git a/src/lib/ubix/startup.S b/src/lib/ubix/startup.S new file mode 100644 index 0000000..b210c72 --- /dev/null +++ b/src/lib/ubix/startup.S @@ -0,0 +1,56 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +.globl _start,__progname +.text +.code32 +_start: + push %ebp + mov %esp,%ebp + sub $0x8,%esp + add $0xfffffff4,%esp + add $0xfffffff8,%esp + pushl 0xc(%ebp) + pushl 0x8(%ebp) + call main + push %eax + call exit +__progname: + .long 0 + +/*** + $Log$ + Revision 1.2 2004/06/18 14:15:47 reddawg + This may hopefully remove some segfault issues that we experience. + + Revision 1.1 2004/06/18 13:21:34 reddawg + Making this more compiler safe + + END + ***/ diff --git a/src/lib/views/sunlight/Makefile b/src/lib/views/sunlight/Makefile new file mode 100644 index 0000000..0167edf --- /dev/null +++ b/src/lib/views/sunlight/Makefile @@ -0,0 +1,36 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +include ../../../Makefile.inc + +#Objects +OBJS = sStyle.o sTypes.o vContext.o vButton.o vMenuBar.o vView.o vCanvas.o vDesktop.o vTitleTab.o + +#Include +INCLUDE = -I./ -I../../..lib/libc/include -I../../../lib/libcpp/include -I../../objgfx40/objgfx40 -I./include + +#Output +OUTPUT = views.so + +$(OUTPUT): $(OBJS) + $(CXX) -nostdlib -shared -Wl,-soname,$(OUTPUT) -o $(OUTPUT) $(OBJS) + +# Compile the source files +.cpp.o: + $(CXX) -Wall -g -fno-inline -nostdlib -fno-exceptions -DNOBOOL $(INCLUDE) -c -o $@ $< + +.cc.o: + $(CXX) -Wall -nostdlib -fomit-frame-pointer -O -I./include -S -o $@ $< + +.c.o: + $(CC) -Wall -O -I../../../lib/libc/include -c -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O -I../../../lib/libc/include -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(OUTPUT) *.core diff --git a/src/lib/views/sunlight/include/sStyle.h b/src/lib/views/sunlight/include/sStyle.h new file mode 100644 index 0000000..18f15d0 --- /dev/null +++ b/src/lib/views/sunlight/include/sStyle.h @@ -0,0 +1,9 @@ +#ifndef SSTYLE_H +#define SSTYLE_H + +class sStyle { + protected: + public: + virtual ~sStyle(void); +}; // sStyle +#endif diff --git a/src/lib/views/sunlight/include/sTypes.h b/src/lib/views/sunlight/include/sTypes.h new file mode 100644 index 0000000..e9c5d31 --- /dev/null +++ b/src/lib/views/sunlight/include/sTypes.h @@ -0,0 +1,59 @@ +#ifndef STYPES_H +#define STYPES_H + +#include +#include +#include +#include +#include + +class sString : public sStyle, public std::string { + public: + sString(void) : std::string("") { }; + sString(const std::string s) : std::string(s) { }; + virtual ~sString(void) { }; +}; // sString + +class sBGColor : public sStyle { + public: + ogRGBA8 colors[4]; + sBGColor(void); + virtual ~sBGColor(void); +}; // sBGColor + +class sRGB8Color : public sStyle, public ogRGB8 { + public: + sRGB8Color(void) { red = green = blue = 0; } + sRGB8Color(uInt8, uInt8, uInt8); + virtual ~sRGB8Color(void) { }; +}; // sRGB8Color + +class sRGBA8Color : public sStyle, public ogRGBA8 { + public: + sRGBA8Color(void) { red = green = blue = alpha = 0; } + sRGBA8Color(uInt8, uInt8, uInt8, uInt8); + virtual ~sRGBA8Color(void) { }; +}; // sRGBA8Color + +class sSize : public sStyle { + public: + uInt32 size; + uInt32 width; + uInt32 height; + sSize(void) { size = width = height = 0; } + sSize(uInt32 _size) { size = _size; width = height = 0; } + sSize(uInt32, uInt32); + sSize(uInt32, uInt32, uInt32); + virtual ~sSize(void); +}; // sSize + +class sPixelFormat : public sStyle, public ogPixelFmt { + public: +// sPixelFormat(void); + sPixelFormat(uInt8, + uInt8, uInt8, uInt8, uInt8, + uInt8, uInt8, uInt8, uInt8); + virtual ~sPixelFormat(void) { }; +}; // sPixelFormat + +#endif diff --git a/src/lib/views/sunlight/include/vButton.h b/src/lib/views/sunlight/include/vButton.h new file mode 100644 index 0000000..1e2ffac --- /dev/null +++ b/src/lib/views/sunlight/include/vButton.h @@ -0,0 +1,13 @@ +#ifndef VBUTTON_H +#define VBUTTON_H + +#include "vContext.h" + +class vButton : public vContext { + protected: + public: + vButton(vContext *); + virtual bool vCreate(void); + virtual ~vButton(); +}; // vButton +#endif diff --git a/src/lib/views/sunlight/include/vCanvas.h b/src/lib/views/sunlight/include/vCanvas.h new file mode 100644 index 0000000..f6ce306 --- /dev/null +++ b/src/lib/views/sunlight/include/vCanvas.h @@ -0,0 +1,12 @@ +#ifndef VCANVAS_H +#define VCANVAS_H + +#include + +class vCanvas : public vContext { + protected: + public: + vCanvas(vContext *); + virtual ~vCanvas(void); +}; // vCanvas +#endif diff --git a/src/lib/views/sunlight/include/vContext.h b/src/lib/views/sunlight/include/vContext.h new file mode 100644 index 0000000..f3c6f93 --- /dev/null +++ b/src/lib/views/sunlight/include/vContext.h @@ -0,0 +1,39 @@ +#ifndef VCONTEXT_H +#define VCONTEXT_H + +#include +#include +#include +#include +#include + +class vContext : public ogSurface { + protected: + std::map styles; + std::list cContexts; // child contexts + vContext * pContext; // parent context + + ogSurface * realView; + int32 curX, curY; + uInt32 width, height; + bool attached; + public: + vContext(vContext *); + virtual vContext * vAttach(vContext *); + virtual bool vCreate(void) = 0; + virtual void vDeleteAllStyles(void); + virtual bool vDeleteStyle(const std::string); + virtual void vDraw(void) = 0; + virtual vContext * vDetach(vContext *); + virtual uInt32 vGetHeight(void) { return height; }; + virtual sStyle * vGetStyle(const std::string); + virtual uInt32 vGetWidth(void) { return width; }; + virtual bool vIsAttached(void) { return attached; } + virtual void vSetPos(int32, int32); + virtual void vSetSize(uInt32, uInt32); + virtual void vSetStyle(const std::string, sStyle *); + virtual ~vContext(); + +}; // vContext + +#endif diff --git a/src/lib/views/sunlight/include/vDesktop.h b/src/lib/views/sunlight/include/vDesktop.h new file mode 100644 index 0000000..18aac66 --- /dev/null +++ b/src/lib/views/sunlight/include/vDesktop.h @@ -0,0 +1,18 @@ +#ifndef VDESKTOP_H +#define VDESKTOP_H + +#include + +class vDesktop : public vContext { + protected: + public: + vDesktop(vContext *); + virtual void DeleteAllStyles(void); + virtual bool DeleteStyle(const std::string); + virtual sStyle * GetStyle(const std::string); + virtual void SetPos(int32, int32); + virtual void SetStyle(const std::string, sStyle *); + + virtual ~vDesktop(void); +}; // vDesktop +#endif diff --git a/src/lib/views/sunlight/include/vMenuBar.h b/src/lib/views/sunlight/include/vMenuBar.h new file mode 100644 index 0000000..6e834f7 --- /dev/null +++ b/src/lib/views/sunlight/include/vMenuBar.h @@ -0,0 +1,13 @@ +#ifndef VMENUBAR_H +#define VMENUBAR_H + +#include + +class vMenuBar : public vContext { + protected: + public: + vMenuBar(vContext *); + virtual ~vMenuBar(); +}; // vMenuBar + +#endif diff --git a/src/lib/views/sunlight/include/vTitleTab.h b/src/lib/views/sunlight/include/vTitleTab.h new file mode 100644 index 0000000..9ec8ad2 --- /dev/null +++ b/src/lib/views/sunlight/include/vTitleTab.h @@ -0,0 +1,19 @@ +#ifndef VTITLETAB_H +#define VTITLETAB_H + +#include +#include +#include + +class vTitleTab : public vContext { + protected: + ogBitFont * font; + std::string title; + public: + vTitleTab(vContext *); + virtual void vDraw(void); + void vSetTitle(const std::string); + virtual ~vTitleTab(void); +}; // vTitleTab + +#endif diff --git a/src/lib/views/sunlight/include/vView.h b/src/lib/views/sunlight/include/vView.h new file mode 100644 index 0000000..ce48f85 --- /dev/null +++ b/src/lib/views/sunlight/include/vView.h @@ -0,0 +1,15 @@ +#ifndef VVIEW_H +#define VVIEW_H + +#include +#include +#include + +class vView : public vTitleTab, public vCanvas { + protected: + public: + vView(vContext *); + virtual ~vView(void); +}; // vView + +#endif diff --git a/src/lib/views/sunlight/sStyle.cpp b/src/lib/views/sunlight/sStyle.cpp new file mode 100644 index 0000000..a3e0645 --- /dev/null +++ b/src/lib/views/sunlight/sStyle.cpp @@ -0,0 +1,5 @@ +#include + +sStyle::~sStyle(void) { + return; +} // sStyle::~sStyle diff --git a/src/lib/views/sunlight/sTypes.cpp b/src/lib/views/sunlight/sTypes.cpp new file mode 100644 index 0000000..f14338a --- /dev/null +++ b/src/lib/views/sunlight/sTypes.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +sBGColor::sBGColor(void) { + memset(colors, 0, sizeof(colors)); + return; +} // sBGColor::sBGColor + +sBGColor::~sBGColor(void) { + return; +} // sBGColor::~sBGColor + +sRGB8Color::sRGB8Color(uInt8 r, uInt8 g, uInt8 b) { + red = r; + green = g; + blue = b; + return; +} // sRGB8Color::sRGB8Color + +sRGBA8Color::sRGBA8Color(uInt8 r, uInt8 g, uInt8 b, uInt8 a) { + red = r; + green = g; + blue = b; + alpha = a; + return; +} // sRGBA8Color::sRGBAColor + +sSize::sSize(uInt32 w, uInt32 h) { + size = 0; + width = w; + height = h; + return; +} // sSize::sSize + +sSize::sSize(uInt32 s, uInt32 w, uInt32 h) { + size = s; + width = w; + height = h; + return; +} // sSize::sSize + +sSize::~sSize(void) { + return; +} + +sPixelFormat::sPixelFormat(uInt8 bitsPerPix, + uInt8 RFP, uInt8 GFP, uInt8 BFP, uInt8 AFP, + uInt8 RMS, uInt8 GMS, uInt8 BMS, uInt8 AMS) + : ogPixelFmt( bitsPerPix, RFP, GFP, BFP, AFP, RMS, GMS, BMS, AMS) { + return; +} // sPixelFormat::sPixelFormat diff --git a/src/lib/views/sunlight/vButton.cpp b/src/lib/views/sunlight/vButton.cpp new file mode 100644 index 0000000..3021e46 --- /dev/null +++ b/src/lib/views/sunlight/vButton.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include + +#include + +vButton::vButton(vContext * parent) : vContext(parent) { + return; +} // vButton::vButton + +bool +vButton::vCreate(void) { + bool result = false; + sPixelFormat * pixFmt; + sSize * borderSize; +// ogRGBA8 colour; + + do { + borderSize = dynamic_cast(vGetStyle("default.button.border.size")); + if (borderSize == NULL) break; + + pixFmt = dynamic_cast(vGetStyle("default.desktop.pixelformat")); + if (pixFmt == NULL) break; + + if (!realView->ogCreate(vGetWidth()+borderSize->size, + vGetHeight()+borderSize->size, + *pixFmt)) break; + + if (!ogAlias(*realView, + borderSize->size, + borderSize->size, + realView->ogGetMaxX()-borderSize->size, + realView->ogGetMaxY()-borderSize->size)) break; + + result = true; + } while (false); + + return result; +} // vButton::vCreate + +vButton::~vButton(void) { + return; +} // vButton::~vButton diff --git a/src/lib/views/sunlight/vCanvas.cpp b/src/lib/views/sunlight/vCanvas.cpp new file mode 100644 index 0000000..c967aac --- /dev/null +++ b/src/lib/views/sunlight/vCanvas.cpp @@ -0,0 +1,10 @@ +#include +#include + +vCanvas::vCanvas(vContext * parent) : vContext(parent) { + return; +} + +vCanvas::~vCanvas(void) { + return; +} diff --git a/src/lib/views/sunlight/vContext.cpp b/src/lib/views/sunlight/vContext.cpp new file mode 100644 index 0000000..089a0d1 --- /dev/null +++ b/src/lib/views/sunlight/vContext.cpp @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include +#include +#include + +vContext::vContext(vContext * parent) { + pContext = parent; + realView = new ogSurface(); + curX = curY = width = height = 0; + attached = false; + return; +} // vContext::vContext + +vContext * +vContext::vAttach(vContext * context) { + /* + * vContext::vAttach() + * Accepts a vContext as a parameter and attaches it to the + * current child context list. + * Returns the child context pointer + */ + cContexts.push_back(context); + return context; +} // vContext::vAttach + +void +vContext::vDeleteAllStyles(void) { + /* + * vContext::vDeleteAllStyle() + * Deletes all style entries in this node of the style tree. + */ + + if (styles.empty()) return; + + // create a map<> iterator that points to the beginning style + map::iterator curStyle = styles.begin(); + + // loop through the styles, deleting them and calling the style object's + // destructor + + while (curStyle != styles.end()) { + std::string str = curStyle->first; + sStyle * tmpStyle = dynamic_cast(styles[str]); +// if (tmpStyle != NULL) cout << "deleting styles[\"" << str << "\"]" << endl; + styles.erase(curStyle); + delete tmpStyle; + ++curStyle; + } // while + + return; +} // vContext::vDeleteAllStyles + +bool +vContext::vDeleteStyle(const std::string styleKey) { + /* + * vContext::vDeleteStyle() + * returns true if style existed and was deleted + * returns false if style didn't exist (or wasn't deleted) + */ + + sStyle * tmpStyle = styles[styleKey]; + styles.erase(styleKey); + delete tmpStyle; + return (tmpStyle != NULL); +} // vContext::vDeleteStyle + +vContext * +vContext::vDetach(vContext * context) { + cContexts.remove(context); + return context; +} // vContext::vDetach + +/* + * void + * vContext::Draw(void) { + * return; + * } // vContext::Draw + */ + +sStyle * +vContext::vGetStyle(const std::string styleKey) { + /* + * GetStyle() + * retreives a style out of the style map using the styleKey string + * If no style is present in this node, check the parent + */ + sStyle * tmpStyle = styles[styleKey]; + + if ((tmpStyle == NULL) && (pContext != NULL)) { + return pContext->vGetStyle(styleKey); + } // if + + return tmpStyle; +} // vContext::vGetStyle + +void +vContext::vSetPos(int32 newX, int32 newY) { + /* + * vContext::SetPos() + * Sets new position relative to parent's upper left corner + */ + + // I really should detach from the parent here + if ((attached) && (pContext != NULL)) pContext->vDetach(this); + curX = newX; + curY = newY; + // and reattach to parent here + if ((attached) && (pContext != NULL)) pContext->vAttach(this); + return; +} // vContext::vSetPos + +void +vContext::vSetSize(uInt32 newWidth, uInt32 newHeight) { +// if ((attached) && (pContext != NULL)) pContext->vDetach(this); + width = newWidth; + height = newHeight; +// if ((attached) && (pContext != NULL)) pContext->vAttach(this); +} // vContext::vSetSize + +void +vContext::vSetStyle(const std::string styleKey, sStyle * style) { + // I probably should check to see if a style exists before setting it + + // if the style is null, then just exit out without setting it + if (style == NULL) return; + + // set the new style + styles[styleKey] = style; +} // vContext::vSetStyle + +vContext::~vContext(void) { + delete realView; + realView = pContext = NULL; + curX = curY = width = height = 0; + + vDeleteAllStyles(); + + return; +} // vContext::~vContext diff --git a/src/lib/views/sunlight/vDesktop.cpp b/src/lib/views/sunlight/vDesktop.cpp new file mode 100644 index 0000000..b48181e --- /dev/null +++ b/src/lib/views/sunlight/vDesktop.cpp @@ -0,0 +1,40 @@ +#include +#include + +vDesktop::vDesktop(vContext * parent) : vContext(parent) { + return; +} // vDesktop::vDesktop + +void +vDesktop::DeleteAllStyles(void) { + return; +} + +bool +vDesktop::DeleteStyle(const std::string styleName) { + return false; +} + +sStyle * +vDesktop::GetStyle(const std::string styleName) { + /* + * vDesktop::GetStyle + * This will have to send a message to the Launcher to get the actual + * style. For now use NULL + */ + return NULL; +} // vDesktop::GetStyle + +void +vDesktop::SetPos(int32 newX, int32 newY) { + return; +} // vDesktop::SetPos + +void +vDesktop::SetStyle(const std::string nameStyle, sStyle * style) { + return; +} // vDesktop::SetStyle + +vDesktop::~vDesktop(void) { + return; +} // vDesktop::~vDesktop diff --git a/src/lib/views/sunlight/vMenuBar.cpp b/src/lib/views/sunlight/vMenuBar.cpp new file mode 100644 index 0000000..a4e24f4 --- /dev/null +++ b/src/lib/views/sunlight/vMenuBar.cpp @@ -0,0 +1,10 @@ +#include +#include + +vMenuBar::vMenuBar(vContext * parent) : vContext(parent) { + return; +} // vMenuBar::vMenuBar + +vMenuBar::~vMenuBar(void) { + return; +} // vMenuBar::~vMenuBar diff --git a/src/lib/views/sunlight/vTitleTab.cpp b/src/lib/views/sunlight/vTitleTab.cpp new file mode 100644 index 0000000..c342ec8 --- /dev/null +++ b/src/lib/views/sunlight/vTitleTab.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +vTitleTab::vTitleTab(vContext * parent) : vContext(parent) { + // Allocate a new font + font = new ogBitFont(); + + // Set the title to nothing + title = ""; + + // Retrieve the default font filename out of the style tree + sString * fontFileName = dynamic_cast(vGetStyle("default.font.filename")); + + // Attempt to load the font + if (fontFileName != NULL) { + // I should check for failure here, although everything fails quietly... + // so even if it does fail it won't matter much + font->Load(fontFileName->c_str(), 0); + } + + sRGBA8Color * color = dynamic_cast(vGetStyle("default.font.color.background")); + if (NULL != color) + font->SetBGColor(color->red, color->blue, color->green, color->alpha); + + color = dynamic_cast(vGetStyle("default.font.color.foreground")); + if (color != NULL) + font->SetFGColor(color->red, color->blue, color->green, color->alpha); + + return; +} // vTitleTab::vTitleTab + +void +vTitleTab::vDraw(void) { + ogPoint2d points[4]; + sBGColor * BGColor = dynamic_cast(vGetStyle("default.title.color.passive")); + if (BGColor == NULL) return; + + points[0].x = points[0].y = points[1].y = points[3].x = 0; + points[1].x = points[2].x = ogGetMaxX()+1; + points[2].y = points[3].y = ogGetMaxY(); + + ogFillGouraudPolygon(4, points, BGColor->colors); + font->JustifyText(*this, centerText, centerText, title.c_str()); + return; +} // vTitleTab::vDraw() + +void +vTitleTab::vSetTitle(const std::string newTitle) { + title = newTitle; + return; +} // vTitleTab::vSetTitle + +vTitleTab::~vTitleTab(void) { + delete font; + font = NULL; + return; +} // vTitleTab::~vTitleTab diff --git a/src/lib/views/sunlight/vView.cpp b/src/lib/views/sunlight/vView.cpp new file mode 100644 index 0000000..34b586b --- /dev/null +++ b/src/lib/views/sunlight/vView.cpp @@ -0,0 +1,11 @@ +#include +#include +#include + +vView::vView(vContext * parent) : vTitleTab(parent), vCanvas(parent) { + return; +} // vView::vView + +vView::~vView(void) { + return; +} diff --git a/src/sys/Makefile b/src/sys/Makefile new file mode 100644 index 0000000..15267b5 --- /dev/null +++ b/src/sys/Makefile @@ -0,0 +1,81 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +all: net-code sde-code pci-code ubixfs-code vfs-code isa-code kernel-code lib-code vmm-code sys-code boot-code init-code devfs-code mpi-code kernel-img + +boot-code: boot + (cd boot;make) + +init-code: init + (cd init;make) + +kernel-code: kernel + (cd kernel;make) + +isa-code: isa + (cd isa;make) + +pci-code: pci + (cd pci;make) + +sys-code: sys + (cd sys;make) + +vmm-code: vmm + (cd vmm;make) + +ubixfs-code: ubixfs + (cd ubixfs;make) + +devfs-code: devfs + (cd devfs;make) + +graphics-code: graphics + (cd graphics;make) + +ld-code: ld + (cd ld;make) + +lib-code: lib + (cd lib;make) + +sde-code: sde + (cd sde;make) + +vfs-code: vfs + (cd vfs;make) + +net-code: net + (cd net;make) + +mpi-code: mpi + (cd mpi;make) + +kernel-img: compile + (/bin/echo "/* " > ./compile/null.c) + (date >> ./compile/null.c) + (echo $user >> ./compile/null.c) + (/bin/echo " */" >> ./compile/null.c) + (cd compile;make) + +install: + (cd boot;make install) + (cd ../tools/;make format-dsk) + +clean: + (cd boot;make clean) + (cd init;make clean) + (cd compile;make clean) + (cd sys;make clean) + (cd vmm;make clean) + (cd lib;make clean) + (cd kernel;make clean) + (cd isa;make clean) + (cd vfs;make clean) + (cd ubixfs;make clean) + (cd pci;make clean) + (cd sde;make clean) + (cd devfs;make clean) + (cd net;make clean) + (cd mpi;make clean) + (cd ../tools/;make clean) diff --git a/src/sys/Makefile.inc b/src/sys/Makefile.inc new file mode 100644 index 0000000..935481a --- /dev/null +++ b/src/sys/Makefile.inc @@ -0,0 +1,6 @@ +# $Id: +# global 'sys' options + +INCLUDES = -I../include +CFLAGS = -nostdlib -fno-builtin -fno-exceptions -fomit-frame-pointer +KERNEL = ubix.elf diff --git a/src/sys/README b/src/sys/README new file mode 100644 index 0000000..fdae3e6 --- /dev/null +++ b/src/sys/README @@ -0,0 +1,18 @@ +Directory Structure: + + boot - Contains boot strapping code + compile - Contains Information to build UbixOS kernel + devfs - Contains the devfs code + include - All of the kernel include files + init - Initialization code for kernel + isa - ISA drivers + kernel - Kernel code (things not directly connected with the system) + lib - Kernel library + mpi - Message passing interface code + net - Networking subsystem code (LwIP) + pci - PCI drivers and subsystem + sde - Screen drawing engine code + sys - System related code IDT etc. + ubixfs - UbixFS code + vfs - VFS subsystem code + vmm - VMM subsystem code \ No newline at end of file diff --git a/src/sys/boot/Makefile b/src/sys/boot/Makefile new file mode 100644 index 0000000..eef8f5a --- /dev/null +++ b/src/sys/boot/Makefile @@ -0,0 +1,14 @@ +# $Id$ + +FDDEVICE = "/dev/fd0" +#FDDEVICE = /dev/fd1 +all: + (cd mbr;make) + +install: + +clean: + (rm -f writeimg format bootsec *.core boot2/test) + (cd btx;make clean) + (cd boot2;make clean) + (cd mbr;make clean) diff --git a/src/sys/boot/Makefile.inc b/src/sys/boot/Makefile.inc new file mode 100644 index 0000000..65ce9b5 --- /dev/null +++ b/src/sys/boot/Makefile.inc @@ -0,0 +1,7 @@ +# Common defines for all of /sys/boot/i386/ +# +# $FreeBSD: src/sys/boot/i386/Makefile.inc,v 1.1.2.2 2000/12/28 12:04:04 ps Exp $ + +LOADER_ADDRESS?= 0x200000 +CFLAGS+= -mpreferred-stack-boundary=2 +CC = gcc diff --git a/src/sys/boot/boot2/Makefile b/src/sys/boot/boot2/Makefile new file mode 100644 index 0000000..cd404d1 --- /dev/null +++ b/src/sys/boot/boot2/Makefile @@ -0,0 +1,87 @@ +# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.16.2.5 2002/08/07 16:31:53 ru Exp $ + +PROG= boot2 +NOMAN= +STRIP= +BINDIR?= /boot +BINMODE= 444 +CLEANFILES+= boot1 boot1.out boot1.o \ + boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \ + sio.o + +NM?= nm + +# A value of 0x80 enables LBA support. +B1FLAGS= 0x80 + +BOOT_COMCONSOLE_PORT?= 0x3f8 +BOOT_COMCONSOLE_SPEED?= 9600 +B2SIOFMT?= 0x3 + +.if exists(${.OBJDIR}/../btx) +BTX= ${.OBJDIR}/../btx +.else +BTX= ${.CURDIR}/../btx +.endif + +ORG1= 0x7c00 +ORG2= 0x1000 + +CFLAGS= -elf -I${.CURDIR}/../btx/lib -I. \ + -Os -fno-builtin -fforce-addr -fdata-sections \ + -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mrtd \ + -mpreferred-stack-boundary=2 \ + -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \ + -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \ + -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings + +LDFLAGS=-nostdlib -static -N + +all: boot1 boot2 + +boot1: boot1.out + objcopy -S -O binary boot1.out ${.TARGET} + +boot1.out: boot1.o + ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o + +boot1.o: boot1.s + ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} ${.IMPSRC} -o ${.TARGET} + +boot2.h: boot1.out + ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \ + { x = $$1 - ORG1; printf("#define XREADORG 0x7%x\n", x) }' \ + ORG1=`printf "%d" ${ORG1}` > boot2.h + +boot2: boot2.ldr boot2.bin ${BTX}/btx/btx + btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \ + -o boot2.ld -P 1 boot2.bin + @ls -l boot2.ld | awk '{ x = 7680 - $$5; \ + print x " bytes available"; if (x < 0) exit 1 }' + dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null + +boot2.ldr: + dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null + +boot2.bin: boot2.out + objcopy -S -O binary boot2.out ${.TARGET} + +boot2.out: boot2.o sio.o + ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \ + ${BTX}/lib/crt0.o boot2.o sio.o + +boot2.o: boot2.h + +sio.o: sio.s + ${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \ + --defsym SIOFMT=${B2SIOFMT} \ + --defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \ + ${.IMPSRC} -o ${.TARGET} + +install: + ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + boot1 ${DESTDIR}${BINDIR}/boot1 + ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + boot2 ${DESTDIR}${BINDIR}/boot2 + +.include diff --git a/src/sys/boot/boot2/boot1.s b/src/sys/boot/boot2/boot1.s new file mode 100644 index 0000000..b02879e --- /dev/null +++ b/src/sys/boot/boot2/boot1.s @@ -0,0 +1,360 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/boot2/boot1.s,v 1.10.2.3 2001/08/14 22:55:29 jhb Exp $ + +# Memory Locations + .set MEM_REL,0x700 # Relocation address + .set MEM_ARG,0x900 # Arguments + .set MEM_ORG,0x7c00 # Origin + .set MEM_BUF,0x8c00 # Load area + .set MEM_BTX,0x9000 # BTX start + .set MEM_JMP,0x9010 # BTX entry point + .set MEM_USR,0xa000 # Client start + .set BDA_BOOT,0x472 # Boot howto flag + +# Partition Constants + .set PRT_OFF,0x1be # Partition offset + .set PRT_NUM,0x4 # Partitions + .set PRT_BSD,0xAD # Partition type + +# Flag Bits + .set FL_PACKET,0x80 # Packet mode + +# Misc. Constants + .set SIZ_PAG,0x1000 # Page size + .set SIZ_SEC,0x200 # Sector size + + .globl start + .globl xread + .code16 + +start: jmp main # Start recognizably + +# This is the start of a standard BIOS Parameter Block (BPB). Most bootable +# FAT disks have this at the start of their MBR. While normal BIOS's will +# work fine without this section, IBM's El Torito emulation "fixes" up the +# BPB by writing into the memory copy of the MBR. Rather than have data +# written into our xread routine, we'll define a BPB to work around it. +# The data marked with (T) indicates a field required for a ThinkPad to +# recognize the disk and (W) indicates fields written from IBM BIOS code. +# The use of the BPB is based on what OpenBSD and NetBSD implemented in +# their boot code but the required fields were determined by trial and error. +# +# Note: If additional space is needed in boot1, one solution would be to +# move the "prompt" message data (below) to replace the OEM ID. + + .org 0x03, 0x00 +oemid: .space 0x08, 0x00 # OEM ID + + .org 0x0b, 0x00 +bpb: .word 512 # sector size (T) + .byte 0 # sectors/clustor + .word 0 # reserved sectors + .byte 0 # number of FATs + .word 0 # root entries + .word 0 # small sectors + .byte 0 # media type (W) + .word 0 # sectors/fat + .word 18 # sectors per track (T) + .word 2 # number of heads (T) + .long 0 # hidden sectors (W) + .long 0 # large sectors + + .org 0x24, 0x00 +ebpb: .byte 0 # BIOS physical drive number (W) + + .org 0x25,0x90 +# +# Trampoline used by boot2 to call read to read data from the disk via +# the BIOS. Call with: +# +# %cx:%ax - long - LBA to read in +# %es:(%bx) - caddr_t - buffer to read data into +# %dl - byte - drive to read from +# %dh - byte - num sectors to read +# + +xread: push %ss # Address + pop %ds # data +# +# Setup an EDD disk packet and pass it to read +# +xread.1: # Starting + pushl $0x0 # absolute + push %cx # block + push %ax # number + push %es # Address of + push %bx # transfer buffer + xor %ax,%ax # Number of + movb %dh,%al # blocks to + push %ax # transfer + push $0x10 # Size of packet + mov %sp,%bp # Packet pointer + callw read # Read from disk + lea 0x10(%bp),%sp # Clear stack + lret # To far caller +# +# Load the rest of boot2 and BTX up, copy the parts to the right locations, +# and start it all up. +# + +# +# Setup the segment registers to flat addressing (segment 0) and setup the +# stack to end just below the start of our code. +# +main: cld # String ops inc + xor %cx,%cx # Zero + mov %cx,%es # Address + mov %cx,%ds # data + mov %cx,%ss # Set up + mov $start,%sp # stack +# +# Relocate ourself to MEM_REL. Since %cx == 0, the inc %ch sets +# %cx == 0x100. +# + mov %sp,%si # Source + mov $MEM_REL,%di # Destination + incb %ch # Word count + rep # Copy + movsw # code +# +# If we are on a hard drive, then load the MBR and look for the first +# FreeBSD slice. We use the fake partition entry below that points to +# the MBR when we call nread. The first pass looks for the first active +# FreeBSD slice. The second pass looks for the first non-active FreeBSD +# slice if the first one fails. +# + mov $part4,%si # Partition + cmpb $0x80,%dl # Hard drive? + jb main.4 # No + movb $0x1,%dh # Block count + callw nread # Read MBR + mov $0x1,%cx # Two passes +main.1: mov $MEM_BUF+PRT_OFF,%si # Partition table + movb $0x1,%dh # Partition +main.2: cmpb $PRT_BSD,0x4(%si) # Our partition type? + jne main.3 # No + jcxz main.5 # If second pass + testb $0x80,(%si) # Active? + jnz main.5 # Yes +main.3: add $0x10,%si # Next entry + incb %dh # Partition + cmpb $0x1+PRT_NUM,%dh # In table? + jb main.2 # Yes + dec %cx # Do two + jcxz main.1 # passes +# +# If we get here, we didn't find any FreeBSD slices at all, so print an +# error message and die. +# + mov $msg_part,%si # Message + jmp error # Error +# +# Floppies use partition 0 of drive 0. +# +main.4: xor %dx,%dx # Partition:drive +# +# Ok, we have a slice and drive in %dx now, so use that to locate and load +# boot2. %si references the start of the slice we are looking for, so go +# ahead and load up the first 16 sectors (boot1 + boot2) from that. When +# we read it in, we conveniently use 0x8c00 as our transfer buffer. Thus, +# boot1 ends up at 0x8c00, and boot2 starts at 0x8c00 + 0x200 = 0x8e00. +# The first part of boot2 is the disklabel, which is 0x200 bytes long. +# The second part is BTX, which is thus loaded into 0x9000, which is where +# it also runs from. The boot2.bin binary starts right after the end of +# BTX, so we have to figure out where the start of it is and then move the +# binary to 0xb000. Normally, BTX clients start at MEM_USR, or 0xa000, but +# when we use btxld create boot2, we use an entry point of 0x1000. That +# entry point is relative to MEM_USR; thus boot2.bin starts at 0xb000. +# +main.5: mov %dx,MEM_ARG # Save args + movb $0x10,%dh # Sector count + callw nread # Read disk + mov $MEM_BTX,%bx # BTX + mov 0xa(%bx),%si # Get BTX length and set + add %bx,%si # %si to start of boot2.bin + mov $MEM_USR+SIZ_PAG,%di # Client page 1 + mov $MEM_BTX+0xe*SIZ_SEC,%cx # Byte + sub %si,%cx # count + rep # Relocate + movsb # client + sub %di,%cx # Byte count + xorb %al,%al # Zero assumed bss from + rep # the end of boot2.bin + stosb # up to 0x10000 + callw seta20 # Enable A20 + jmp start+MEM_JMP-MEM_ORG # Start BTX +# +# Enable A20 so we can access memory above 1 meg. +# +seta20: cli # Disable interrupts +seta20.1: inb $0x64,%al # Get status + testb $0x2,%al # Busy? + jnz seta20.1 # Yes + movb $0xd1,%al # Command: Write + outb %al,$0x64 # output port +seta20.2: inb $0x64,%al # Get status + testb $0x2,%al # Busy? + jnz seta20.2 # Yes + movb $0xdf,%al # Enable + outb %al,$0x60 # A20 + sti # Enable interrupts + retw # To caller +# +# Trampoline used to call read from within boot1. +# +nread: mov $MEM_BUF,%bx # Transfer buffer + mov 0x8(%si),%ax # Get + mov 0xa(%si),%cx # LBA + push %cs # Read from + callw xread.1 # disk + jnc return # If success, return + mov $msg_read,%si # Otherwise, set the error + # message and fall through to + # the error routine +# +# Print out the error message pointed to by %ds:(%si) followed +# by a prompt, wait for a keypress, and then reboot the machine. +# +error: callw putstr # Display message + mov $prompt,%si # Display + callw putstr # prompt + xorb %ah,%ah # BIOS: Get + int $0x16 # keypress + movw $0x1234, BDA_BOOT # Do a warm boot + ljmp $0xffff,$0x0 # reboot the machine +# +# Display a null-terminated string using the BIOS output. +# +putstr.0: mov $0x7,%bx # Page:attribute + movb $0xe,%ah # BIOS: Display + int $0x10 # character +putstr: lodsb # Get char + testb %al,%al # End of string? + jne putstr.0 # No + +# +# Overused return code. ereturn is used to return an error from the +# read function. Since we assume putstr succeeds, we (ab)use the +# same code when we return from putstr. +# +ereturn: movb $0x1,%ah # Invalid + stc # argument +return: retw # To caller +# +# Reads sectors from the disk. If EDD is enabled, then check if it is +# installed and use it if it is. If it is not installed or not enabled, then +# fall back to using CHS. Since we use a LBA, if we are using CHS, we have to +# fetch the drive parameters from the BIOS and divide it out ourselves. +# Call with: +# +# %dl - byte - drive number +# stack - 10 bytes - EDD Packet +# +read: push %dx # Save + movb $0x8,%ah # BIOS: Get drive + int $0x13 # parameters + movb %dh,%ch # Max head number + pop %dx # Restore + jc return # If error + andb $0x3f,%cl # Sectors per track + jz ereturn # If zero + cli # Disable interrupts + mov 0x8(%bp),%eax # Get LBA + push %dx # Save + movzbl %cl,%ebx # Divide by + xor %edx,%edx # sectors + div %ebx # per track + movb %ch,%bl # Max head number + movb %dl,%ch # Sector number + inc %bx # Divide by + xorb %dl,%dl # number + div %ebx # of heads + movb %dl,%bh # Head number + pop %dx # Restore + cmpl $0x3ff,%eax # Cylinder number supportable? + sti # Enable interrupts + ja read.7 # No, try EDD + xchgb %al,%ah # Set up cylinder + rorb $0x2,%al # number + orb %ch,%al # Merge + inc %ax # sector + xchg %ax,%cx # number + movb %bh,%dh # Head number + subb %ah,%al # Sectors this track + mov 0x2(%bp),%ah # Blocks to read + cmpb %ah,%al # To read + jb read.2 # this + movb %ah,%al # track +read.2: mov $0x5,%di # Try count +read.3: les 0x4(%bp),%bx # Transfer buffer + push %ax # Save + movb $0x2,%ah # BIOS: Read + int $0x13 # from disk + pop %bx # Restore + jnc read.4 # If success + dec %di # Retry? + jz read.6 # No + xorb %ah,%ah # BIOS: Reset + int $0x13 # disk system + xchg %bx,%ax # Block count + jmp read.3 # Continue +read.4: movzbw %bl,%ax # Sectors read + add %ax,0x8(%bp) # Adjust + jnc read.5 # LBA, + incw 0xa(%bp) # transfer +read.5: shlb %bl # buffer + add %bl,0x5(%bp) # pointer, + sub %al,0x2(%bp) # block count + ja read # If not done +read.6: retw # To caller +read.7: testb $FL_PACKET,%cs:MEM_REL+flags-start # LBA support enabled? + jz ereturn # No, so return an error + mov $0x55aa,%bx # Magic + push %dx # Save + movb $0x41,%ah # BIOS: Check + int $0x13 # extensions present + pop %dx # Restore + jc return # If error, return an error + cmp $0xaa55,%bx # Magic? + jne ereturn # No, so return an error + testb $0x1,%cl # Packet interface? + jz ereturn # No, so return an error + mov %bp,%si # Disk packet + movb $0x42,%ah # BIOS: Extended + int $0x13 # read + retw # To caller + +# Messages + +msg_read: .asciz "Read" +msg_part: .asciz "Boot" + +prompt: .asciz " error\r\n" + +flags: .byte FLAGS # Flags + + .org PRT_OFF,0x90 + +# Partition table + + .fill 0x30,0x1,0x0 +part4: .byte 0x80, 0x00, 0x01, 0x00 + .byte 0x2a, 0xff, 0xff, 0xff + .byte 0x00, 0x00, 0x00, 0x00 + .byte 0x50, 0xc3, 0x00, 0x00 # 50000 sectors long, bleh + + .word 0xaa55 # Magic number diff --git a/src/sys/boot/boot2/boot2.c b/src/sys/boot/boot2/boot2.c new file mode 100644 index 0000000..bfdc570 --- /dev/null +++ b/src/sys/boot/boot2/boot2.c @@ -0,0 +1,835 @@ +/* + * Copyright (c) 1998 Robert Nordier + * All rights reserved. + * + * Redistribution and use in source and binary forms are freely + * permitted provided that the above copyright notice and this + * paragraph and the following disclaimer are duplicated in all + * such forms. + * + * This software is provided "AS IS" and without any express or + * implied warranties, including, without limitation, the implied + * warranties of merchantability and fitness for a particular + * purpose. + */ + +/* + * $ID: src/sys/boot/i386/boot2/boot2.c,v 1.28.2.6 2002/03/31 18:12:50 pb Exp $ + */ + + +#include +#include +#include "diskslice.h" +#include "disklabel.h" +#include +#include +#include + +#include + +#include + +#include + +#include "boot2.h" +#include "lib.h" +#include "ubixfs.h" + +#define UBX_RESERVED 0 + +#define RBX_ASKNAME 0x0 /* -a */ +#define RBX_SINGLE 0x1 /* -s */ +#define RBX_DFLTROOT 0x5 /* -r */ +#define RBX_KDB 0x6 /* -d */ +#define RBX_CONFIG 0xa /* -c */ +#define RBX_VERBOSE 0xb /* -v */ +#define RBX_SERIAL 0xc /* -h */ +#define RBX_CDROM 0xd /* -C */ +#define RBX_GDB 0xf /* -g */ +#define RBX_DUAL 0x1d /* -D */ +#define RBX_PROBEKBD 0x1e /* -P */ +#define RBX_NOINTR 0x1f /* -n */ + +#define RBX_MASK 0xffff + +#define PATH_CONFIG "/boot.config" +#define PATH_BOOT3 "/ubix.elf" +#define PATH_KERNEL "/ubix.elf" + +#define ARGS 0x900 +#define NOPT 12 +#define BSIZEMAX 16384 +#define NDEV 5 +#define MEM_BASE 0x12 +#define MEM_EXT 0x15 +#define V86_CY(x) ((x) & 1) +#define V86_ZR(x) ((x) & 0x40) + +#define DRV_HARD 0x80 +#define DRV_MASK 0x7f + +#define TYPE_AD 0 +#define TYPE_WD 1 +#define TYPE_WFD 2 +#define TYPE_FD 3 +#define TYPE_DA 4 + +extern uint32_t _end; + +struct blockAllocationTableEntry *BAT = 0x0; +struct directoryEntry *rootDir = 0x0; + +static const char optstr[NOPT] = "DhaCcdgnPrsv"; +static const unsigned char flags[NOPT] = { + RBX_DUAL, + RBX_SERIAL, + RBX_ASKNAME, + RBX_CDROM, + RBX_CONFIG, + RBX_KDB, + RBX_GDB, + RBX_NOINTR, + RBX_PROBEKBD, + RBX_DFLTROOT, + RBX_SINGLE, + RBX_VERBOSE +}; + +static const char *const dev_nm[] = {"ad", "wd", " ", "fd", "da"}; +static const unsigned dev_maj[] = {30, 0, 1, 2, 4}; + +static struct dsk { + unsigned drive; + unsigned type; + unsigned unit; + unsigned slice; + unsigned part; + unsigned start; + int init; + int meta; +} dsk; +static char cmd[512]; +static char kname[1024]; +static uint32_t opts; +static struct bootinfo bootinfo; +static int ls; +static uint32_t fs_off; +static uint8_t ioctrl = 0x1; + +void exit(int); +static void load(const char *); +static int parse(char *); +static int xfsread(const char *, void *, size_t); +static ssize_t fsread(const char *, void *, size_t); +static int dskread(void *, unsigned, unsigned); +static int printf(const char *,...); +static int putchar(int); +static void *memcpy(void *, const void *, size_t); +static void *malloc(size_t); +static uint32_t memsize(int); +static int drvread(void *, unsigned, unsigned); +static int keyhit(unsigned); +static int xputc(int); +static int xgetc(int); +static int getc(int); + +/* My Functions */ +static void initUbixFS(void); + +static inline void readfile(const char *fname, void *buf, size_t size) { + fs_off = 0; + fsread(fname,buf,size); + } + +static inline int +strcmp(const char *s1, const char *s2) +{ + for (; *s1 == *s2 && *s1; s1++, s2++); + return (u_char)*s1 - (u_char)*s2; +} + +static inline int +fsfind(const char *name, ino_t * ino) +{ + char buf[DEV_BSIZE]; + struct dirent *d; + char *s; + ssize_t n; + fs_off = 0; + while ((n = fsread(name, buf, DEV_BSIZE)) > 0) + for (s = buf; s < buf + DEV_BSIZE;) { + d = (void *)s; + if (ls) + printf("%s ", d->d_name); + else if (!strcmp(name, d->d_name)) { + *ino = d->d_fileno; + return d->d_type; + } + s += d->d_reclen; + } + if (n != -1 && ls) + putchar('\n'); + return 0; +} + +static inline int +getchar(void) +{ + int c; + + c = xgetc(0); + if (c == '\r') + c = '\n'; + return c; +} + +static inline void +getstr(char *str, int size) +{ + char *s; + int c; + + s = str; + do { + switch (c = getchar()) { + case 0: + break; + case '\b': + case '\177': + if (s > str) { + s--; + putchar('\b'); + putchar(' '); + } else + c = 0; + break; + case '\n': + *s = 0; + break; + default: + if (s - str < size - 1) + *s++ = c; + } + if (c) + putchar(c); + } while (c != '\n'); +} + +static inline uint32_t +drvinfo(int drive) +{ + v86.addr = 0x13; + v86.eax = 0x800; + v86.edx = DRV_HARD + drive; + v86int(); + if (V86_CY(v86.efl)) + return 0x4f010f; + return ((v86.ecx & 0xc0) << 18) | ((v86.ecx & 0xff00) << 8) | + (v86.edx & 0xff00) | (v86.ecx & 0x3f); +} + +static inline void +putc(int c) +{ + v86.addr = 0x10; + v86.eax = 0xe00 | (c & 0xff); + v86.ebx = 0x7; + v86int(); +} + +static void initUbixFS() { + BAT = (struct blockAllocationTableEntry *)malloc(4096); + rootDir = (struct directoryEntry *)malloc(4096); + dskread(BAT,0 + UBX_RESERVED,8); + dskread(rootDir,8 + UBX_RESERVED,8); + } + +int +main(void) +{ + int autoboot, i; + + v86.ctl = V86_FLAGS; + dsk.drive = *(uint8_t *)PTOV(ARGS); + dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD; + dsk.unit = dsk.drive & DRV_MASK; + dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1; + bootinfo.bi_version = BOOTINFO_VERSION; + bootinfo.bi_size = sizeof(bootinfo); + bootinfo.bi_basemem = memsize(MEM_BASE); + bootinfo.bi_extmem = memsize(MEM_EXT); + bootinfo.bi_memsizes_valid++; + for (i = 0; i < N_BIOS_GEOM; i++) + bootinfo.bi_bios_geom[i] = drvinfo(i); + autoboot = 2; + + /* Initialize UbixFS */ + initUbixFS(); + + readfile(PATH_CONFIG, cmd, sizeof(cmd)); + if (*cmd) { + printf("%s: %s", PATH_CONFIG, cmd); + if (parse(cmd)) + autoboot = 0; + *cmd = 0; + } + if (autoboot && !*kname) { + if (autoboot == 2) { + memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3)); + if (!keyhit(0x37)) { + load(kname); + autoboot = 1; + } + } + if (autoboot == 1) + memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL)); + } + for (;;) { + printf(" \n>> UbixOS/i386 uBoot\n" + "Default: %u:%s(%u,%c)%s\n" + "boot: ", + dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit, + 'a' + dsk.part, kname); + if (ioctrl & 0x2) + sio_flush(); + if (!autoboot || keyhit(0x5a)) + getstr(cmd, sizeof(cmd)); + else + putchar('\n'); + autoboot = 0; + if (parse(cmd)) + putchar('\a'); + else + load(kname); + } +} + +/* XXX - Needed for btxld to link the boot2 binary; do not remove. */ +void +exit(int x) +{ +} + +static void +load(const char *fname) +{ + union { + struct exec ex; + Elf32_Ehdr eh; + } hdr; + Elf32_Phdr ep[2]; + Elf32_Shdr es[2]; + caddr_t p; + uint32_t addr, x; + int fmt, i, j; + fs_off = 0; + if (xfsread(fname, &hdr, sizeof(hdr))) + return; + if (N_GETMAGIC(hdr.ex) == ZMAGIC) + fmt = 0; + else if (IS_ELF(hdr.eh)) + fmt = 1; + else { + printf("Invalid %s\n", "format"); + return; + } + if (fmt == 0) { + addr = hdr.ex.a_entry & 0xffffff; + p = PTOV(addr); + fs_off = PAGE_SIZE; + if (xfsread(fname, p, hdr.ex.a_text)) + return; + p += roundup2(hdr.ex.a_text, PAGE_SIZE); + if (xfsread(fname, p, hdr.ex.a_data)) + return; + p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE); + bootinfo.bi_symtab = VTOP(p); + memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms)); + p += sizeof(hdr.ex.a_syms); + if (hdr.ex.a_syms) { + if (xfsread(fname, p, hdr.ex.a_syms)) + return; + p += hdr.ex.a_syms; + if (xfsread(fname, p, sizeof(int))) + return; + x = *(uint32_t *)p; + p += sizeof(int); + x -= sizeof(int); + if (xfsread(fname, p, x)) + return; + p += x; + } + } else { + fs_off = hdr.eh.e_phoff; + for (j = i = 0; i < hdr.eh.e_phnum && j < 2; i++) { + if (xfsread(fname, ep + j, sizeof(ep[0]))) + return; + if (ep[j].p_type == PT_LOAD) + j++; + } + for (i = 0; i < 2; i++) { + p = PTOV(ep[i].p_paddr & 0xffffff); + fs_off = ep[i].p_offset; + if (xfsread(fname, p, ep[i].p_filesz)) + return; + } + p += roundup2(ep[1].p_memsz, PAGE_SIZE); + bootinfo.bi_symtab = VTOP(p); + if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) { + fs_off = hdr.eh.e_shoff + sizeof(es[0]) * + (hdr.eh.e_shstrndx + 1); + if (xfsread(fname, &es, sizeof(es))) + return; + for (i = 0; i < 2; i++) { + memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size)); + p += sizeof(es[i].sh_size); + fs_off = es[i].sh_offset; + if (xfsread(fname, p, es[i].sh_size)) + return; + p += es[i].sh_size; + } + } + addr = hdr.eh.e_entry & 0xffffff; + } + bootinfo.bi_esymtab = VTOP(p); + bootinfo.bi_kernelname = VTOP(fname); + bootinfo.bi_bios_dev = dsk.drive; + __exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK), + MAKEBOOTDEV(dev_maj[dsk.type], 0, dsk.slice, dsk.unit, dsk.part), + 0, 0, 0, VTOP(&bootinfo)); +} + +static int +parse(char *arg) +{ + char *p, *q; + int drv, c, i; + + while ((c = *arg++)) { + if (c == ' ' || c == '\t' || c == '\n') + continue; + for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++); + if (*p) + *p++ = 0; + if (c == '-') { + while ((c = *arg++)) { + for (i = 0; c != optstr[i]; i++) + if (i == NOPT - 1) + return -1; + opts ^= 1 << flags[i]; + } + if (opts & 1 << RBX_PROBEKBD) { + i = *(uint8_t *)PTOV(0x496) & 0x10; + printf("Keyboard: %s\n", i ? "yes" : "no"); + if (!i) + opts |= 1 << RBX_DUAL | 1 << RBX_SERIAL; + opts &= ~(1 << RBX_PROBEKBD); + } + ioctrl = opts & 1 << RBX_DUAL ? 0x3 : + opts & 1 << RBX_SERIAL ? 0x2 : 0x1; + if (ioctrl & 0x2) + sio_init(); + } else { + for (q = arg--; *q && *q != '('; q++); + if (*q) { + drv = -1; + if (arg[1] == ':') { + if (*arg < '0' || *arg > '9') + return -1; + drv = *arg - '0'; + arg += 2; + } + if (q - arg != 2) + return -1; + for (i = 0; arg[0] != dev_nm[i][0] || + arg[1] != dev_nm[i][1]; i++) + if (i == NDEV - 1) + return -1; + dsk.type = i; + arg += 3; + if (arg[1] != ',' || *arg < '0' || *arg > '9') + return -1; + dsk.unit = *arg - '0'; + arg += 2; + dsk.slice = WHOLE_DISK_SLICE; + if (arg[1] == ',') { + if (*arg < '0' || *arg > '0' + NDOSPART) + return -1; + if ((dsk.slice = *arg - '0')) + dsk.slice++; + arg += 2; + } + if (arg[1] != ')' || *arg < 'a' || *arg > 'p') + return -1; + dsk.part = *arg - 'a'; + arg += 2; + if (drv == -1) + drv = dsk.unit; + dsk.drive = (dsk.type == TYPE_WD || + dsk.type == TYPE_AD || + dsk.type == TYPE_DA ? DRV_HARD : 0) + drv; + dsk.meta = 0; + fsread(0, NULL, 0); + } + if ((i = p - arg - !*(p - 1))) { + if (i >= sizeof(kname)) + return -1; + memcpy(kname, arg, i + 1); + } + } + arg = p; + } + return 0; +} + +static int +xfsread(const char *fname, void *buf, size_t nbyte) +{ + if (fsread(fname, buf, nbyte) != nbyte) { +/* printf("Invalid %s\n", "format"); */ + return -1; + } + return 0; +} + +/* FSREAD */ +static ssize_t fsread(const char *fname, void *buf, size_t nbyte) { + int i = 0x0,x = 0x0,block = 0x0,bOffset = 0x0,offset = 0x0,lb = -1; + int fBlock = -1; + char *buffer = 0x0; + char *buffer2 = 0x0; + struct directoryEntry *tmpDir = 0x0; + tmpDir = rootDir; + if (*fname == '/') { fname++; } + for (i=0;i<=(4096/sizeof(struct directoryEntry));i++) { + if (!strcmp(tmpDir[i].fileName,fname)) { + fBlock = tmpDir[i].startCluster; + break; + } + } + if (fBlock == -1) { + nbyte = 0; + return(nbyte); + } + buffer = malloc(4096); + buffer2 = buf; + offset = fs_off; + if (offset < 0) { + printf("Error!!!\n"); + offset = 0; + } + for (i=0;i> DEV_BSHIFT; + dsk.meta++; + } + if (!inode) + return 0; + if (inomap != inode) { + if (dskread(blkbuf, fsbtodb(&fs, ino_to_fsba(&fs, inode)), + fsblks)) + return -1; + din = ((struct dinode *)blkbuf)[inode % INOPB(&fs)]; + inomap = inode; + fs_off = 0; + blkmap = indmap = 0; + } + s = buf; + if (nbyte > (n = din.di_size - fs_off)) + nbyte = n; + nb = nbyte; + while (nb) { + lbn = lblkno(&fs, fs_off); + if (lbn < NDADDR) + addr = din.di_db[lbn]; + else { + if (indmap != din.di_ib[0]) { + if (!indbuf) + indbuf = malloc(BSIZEMAX); + if (dskread(indbuf, fsbtodb(&fs, din.di_ib[0]), + fsblks)) + return -1; + indmap = din.di_ib[0]; + } + addr = indbuf[(lbn - NDADDR) % NINDIR(&fs)]; + } + n = dblksize(&fs, &din, lbn); + if (blkmap != addr) { + if (dskread(blkbuf, fsbtodb(&fs, addr), n >> DEV_BSHIFT)) + return -1; + blkmap = addr; + } + off = blkoff(&fs, fs_off); + n -= off; + if (n > nb) + n = nb; + memcpy(s, blkbuf + off, n); + s += n; + fs_off += n; + nb -= n; + } + return nbyte; +} +*/ + +static int +dskread(void *buf, unsigned lba, unsigned nblk) +{ + static char *sec; + struct dos_partition *dp; + struct ubixDiskLabel *d; + unsigned sl, i; + + if (!dsk.meta) { + if (!sec) + sec = malloc(DEV_BSIZE); + dsk.start = 0; + if (drvread(sec, DOSBBSECTOR, 1)) + return -1; + dp = (void *)(sec + DOSPARTOFF); + sl = dsk.slice; + if (sl < BASE_SLICE) { + for (i = 0; i < NDOSPART; i++) + if (dp[i].dp_typ == DOSPTYP_UBX && + (dp[i].dp_flag & 0x80 || sl < BASE_SLICE)) { + sl = BASE_SLICE + i; + if (dp[i].dp_flag & 0x80 || + dsk.slice == COMPATIBILITY_SLICE) + break; + } + if (dsk.slice == WHOLE_DISK_SLICE) + dsk.slice = sl; + } + if (sl != WHOLE_DISK_SLICE) { + if (sl != COMPATIBILITY_SLICE) + dp += sl - BASE_SLICE; + if (dp->dp_typ != DOSPTYP_UBX) { + printf("Invalid %s\n", "slice"); + return -1; + } + dsk.start = dp->dp_start; + } + if (drvread(sec, dsk.start + LABELSECTOR, 1)) + return -1; + d = (void *)(sec + LABELOFFSET); + if (d->magicNum != UBIXDISKMAGIC || d->magicNum2 != UBIXDISKMAGIC) { + if (dsk.part != RAW_PART) { + printf("Invalid %s\n", "label"); + return -1; + } + } else { + if (!dsk.init) { + if (d->driveType == DTYPE_SCSI) + dsk.type = TYPE_DA; + dsk.init++; + } + if (dsk.part >= d->numPartitions || + !d->partitions[dsk.part].p_size) { + printf("Invalid %s\n", "partition"); + return -1; + } + dsk.start = d->partitions[dsk.part].p_offset; + } + } + return drvread(buf, dsk.start + lba, nblk); +} + +static int +printf(const char *fmt,...) +{ + static const char digits[16] = "0123456789abcdef"; + va_list ap; + char buf[10]; + char *s; + unsigned r, u; + int c; + + va_start(ap, fmt); + while ((c = *fmt++)) { + if (c == '%') { + c = *fmt++; + switch (c) { + case 'c': + putchar(va_arg(ap, int)); + continue; + case 's': + for (s = va_arg(ap, char *); *s; s++) + putchar(*s); + continue; + case 'u': + case 'x': + r = c == 'u' ? 10U : 16U; + u = va_arg(ap, unsigned); + s = buf; + do + *s++ = digits[u % r]; + while (u /= r); + while (--s >= buf) + putchar(*s); + continue; + } + } + putchar(c); + } + va_end(ap); + return 0; +} + +static int +putchar(int c) +{ + if (c == '\n') + xputc('\r'); + return xputc(c); +} + +static void * +memcpy(void *dst, const void *src, size_t size) +{ + const char *s; + char *d; + + for (d = dst, s = src; size; size--) + *d++ = *s++; + return dst; +} + +static void * +malloc(size_t size) +{ + static uint32_t next; + void *p; + + if (!next) + next = roundup2(__base + _end, 0x10000) - __base; + p = (void *)next; + next += size; + return p; +} + +static uint32_t +memsize(int type) +{ + v86.addr = type; + v86.eax = 0x8800; + v86int(); + return v86.eax; +} + +static int +drvread(void *buf, unsigned lba, unsigned nblk) +{ + static unsigned c = 0x2d5c7c2f; + + printf("%c\b", c = c << 8 | c >> 24); + v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS; + v86.addr = XREADORG; /* call to xread in boot1 */ + v86.es = VTOPSEG(buf); + v86.eax = lba; + v86.ebx = VTOPOFF(buf); + v86.ecx = lba >> 16; + v86.edx = nblk << 8 | dsk.drive; + v86int(); + v86.ctl = V86_FLAGS; + if (V86_CY(v86.efl)) { + printf("Disk error 0x%x (lba=0x%x)\n", v86.eax >> 8 & 0xff, + lba); + return -1; + } + return 0; +} + +static int +keyhit(unsigned ticks) +{ + uint32_t t0, t1; + + if (opts & 1 << RBX_NOINTR) + return 0; + t0 = 0; + for (;;) { + if (xgetc(1)) + return 1; + t1 = *(uint32_t *)PTOV(0x46c); + if (!t0) + t0 = t1; + if (t1 < t0 || t1 >= t0 + ticks) + return 0; + } +} + +static int +xputc(int c) +{ + if (ioctrl & 0x1) + putc(c); + if (ioctrl & 0x2) + sio_putc(c); + return c; +} + +static int +xgetc(int fn) +{ + if (opts & 1 << RBX_NOINTR) + return 0; + for (;;) { + if (ioctrl & 0x1 && getc(1)) + return fn ? 1 : getc(0); + if (ioctrl & 0x2 && sio_ischar()) + return fn ? 1 : sio_getc(); + if (fn) + return 0; + } +} + +static int +getc(int fn) +{ + v86.addr = 0x16; + v86.eax = fn << 8; + v86int(); + return fn == 0 ? v86.eax & 0xff : !V86_ZR(v86.efl); +} diff --git a/src/sys/boot/boot2/disklabel.h b/src/sys/boot/boot2/disklabel.h new file mode 100644 index 0000000..b646693 --- /dev/null +++ b/src/sys/boot/boot2/disklabel.h @@ -0,0 +1,489 @@ +/* + * Copyright (c) 1987, 1988, 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. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ + */ + +#ifndef _SYS_DISKLABEL_H_ +#define _SYS_DISKLABEL_H_ + +#ifndef _KERNEL +#include +#endif +#include + +/* + * Disk description table, see disktab(5) + */ +#define _PATH_DISKTAB "/etc/disktab" +#define DISKTAB "/etc/disktab" /* deprecated */ + +/* + * Each disk has a label which includes information about the hardware + * disk geometry, filesystem partitions, and drive specific information. + * The label is in block 0 or 1, possibly offset from the beginning + * to leave room for a bootstrap, etc. + */ + +/* XXX these should be defined per controller (or drive) elsewhere, not here! */ +#ifdef __i386__ +#define LABELSECTOR 1 /* sector containing label */ +#define LABELOFFSET 0 /* offset of label in sector */ +#endif + +#ifdef __alpha__ +#define LABELSECTOR 0 +#define LABELOFFSET 64 +#endif + +#ifndef LABELSECTOR +#define LABELSECTOR 0 /* sector containing label */ +#endif + +#ifndef LABELOFFSET +#define LABELOFFSET 64 /* offset of label in sector */ +#endif + +#define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */ +#ifndef MAXPARTITIONS +#define MAXPARTITIONS 8 +#endif + +#define LABEL_PART 2 /* partition containing label */ +#define RAW_PART 2 /* partition containing whole disk */ +#define SWAP_PART 1 /* partition normally containing swap */ + +#ifndef LOCORE +struct disklabel { + u_int32_t d_magic; /* the magic number */ + u_int16_t d_type; /* drive type */ + u_int16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + + /* + * d_packname contains the pack identifier and is returned when + * the disklabel is read off the disk or in-core copy. + * d_boot0 and d_boot1 are the (optional) names of the + * primary (block 0) and secondary (block 1-15) bootstraps + * as found in /boot. These are returned when using + * getdiskbyname(3) to retrieve the values from /etc/disktab. + */ + union { + char un_d_packname[16]; /* pack identifier */ + struct { + char *un_d_boot0; /* primary bootstrap name */ + char *un_d_boot1; /* secondary bootstrap name */ + } un_b; + } d_un; +#define d_packname d_un.un_d_packname +#define d_boot0 d_un.un_b.un_d_boot0 +#define d_boot1 d_un.un_b.un_d_boot1 + + /* disk geometry: */ + u_int32_t d_secsize; /* # of bytes per sector */ + u_int32_t d_nsectors; /* # of data sectors per track */ + u_int32_t d_ntracks; /* # of tracks per cylinder */ + u_int32_t d_ncylinders; /* # of data cylinders per unit */ + u_int32_t d_secpercyl; /* # of data sectors per cylinder */ + u_int32_t d_secperunit; /* # of data sectors per unit */ + + /* + * Spares (bad sector replacements) below are not counted in + * d_nsectors or d_secpercyl. Spare sectors are assumed to + * be physical sectors which occupy space at the end of each + * track and/or cylinder. + */ + u_int16_t d_sparespertrack; /* # of spare sectors per track */ + u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */ + /* + * Alternate cylinders include maintenance, replacement, configuration + * description areas, etc. + */ + u_int32_t d_acylinders; /* # of alt. cylinders per unit */ + + /* hardware characteristics: */ + /* + * d_interleave, d_trackskew and d_cylskew describe perturbations + * in the media format used to compensate for a slow controller. + * Interleave is physical sector interleave, set up by the + * formatter or controller when formatting. When interleaving is + * in use, logically adjacent sectors are not physically + * contiguous, but instead are separated by some number of + * sectors. It is specified as the ratio of physical sectors + * traversed per logical sector. Thus an interleave of 1:1 + * implies contiguous layout, while 2:1 implies that logical + * sector 0 is separated by one sector from logical sector 1. + * d_trackskew is the offset of sector 0 on track N relative to + * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew + * is the offset of sector 0 on cylinder N relative to sector 0 + * on cylinder N-1. + */ + u_int16_t d_rpm; /* rotational speed */ + u_int16_t d_interleave; /* hardware sector interleave */ + u_int16_t d_trackskew; /* sector 0 skew, per track */ + u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ + u_int32_t d_headswitch; /* head switch time, usec */ + u_int32_t d_trkseek; /* track-to-track seek, usec */ + u_int32_t d_flags; /* generic flags */ +#define NDDATA 5 + u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */ +#define NSPARE 5 + u_int32_t d_spare[NSPARE]; /* reserved for future use */ + u_int32_t d_magic2; /* the magic number (again) */ + u_int16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + u_int16_t d_npartitions; /* number of partitions in following */ + u_int32_t d_bbsize; /* size of boot area at sn0, bytes */ + u_int32_t d_sbsize; /* max size of fs superblock, bytes */ + struct partition { /* the partition table */ + u_int32_t p_size; /* number of sectors in partition */ + u_int32_t p_offset; /* starting sector */ + u_int32_t p_fsize; /* filesystem basic fragment size */ + u_int8_t p_fstype; /* filesystem type, see below */ + u_int8_t p_frag; /* filesystem fragments per block */ + union { + u_int16_t cpg; /* UFS: FS cylinders per group */ + u_int16_t sgs; /* LFS: FS segment shift */ + } __partition_u1; +#define p_cpg __partition_u1.cpg +#define p_sgs __partition_u1.sgs + } d_partitions[MAXPARTITIONS]; /* actually may be more */ +}; + +static u_int16_t dkcksum(struct disklabel *lp); + +static __inline u_int16_t +dkcksum(struct disklabel *lp) +{ + u_int16_t *start, *end; + u_int16_t sum = 0; + + start = (u_int16_t *)lp; + end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions]; + while (start < end) + sum ^= *start++; + return (sum); +} + +#else /* LOCORE */ + /* + * offsets for asm boot files. + */ + .set d_secsize,40 + .set d_nsectors,44 + .set d_ntracks,48 + .set d_ncylinders,52 + .set d_secpercyl,56 + .set d_secperunit,60 + .set d_end_,276 /* size of disk label */ +#endif /* LOCORE */ + +/* d_type values: */ +#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define DTYPE_MSCP 2 /* MSCP */ +#define DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define DTYPE_SCSI 4 /* SCSI */ +#define DTYPE_ESDI 5 /* ESDI interface */ +#define DTYPE_ST506 6 /* ST506 etc. */ +#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define DTYPE_HPFL 8 /* HP Fiber-link */ +#define DTYPE_FLOPPY 10 /* floppy */ +#define DTYPE_CCD 11 /* concatenated disk */ +#define DTYPE_VINUM 12 /* vinum volume */ +#define DTYPE_DOC2K 13 /* Msys DiskOnChip */ + +#if defined(PC98) && !defined(PC98_ATCOMPAT) +#define DSTYPE_SEC256 0x80 /* physical sector size=256 */ +#endif + +#ifdef DKTYPENAMES +static char *dktypenames[] = { + "unknown", + "SMD", + "MSCP", + "old DEC", + "SCSI", + "ESDI", + "ST506", + "HP-IB", + "HP-FL", + "type 9", + "floppy", + "CCD", + "Vinum", + "DOC2K", + NULL +}; +#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) +#endif + +/* + * Filesystem type and version. + * Used to interpret other filesystem-specific + * per-partition information. + */ +#define FS_UNUSED 0 /* unused */ +#define FS_SWAP 1 /* swap */ +#define FS_V6 2 /* Sixth Edition */ +#define FS_V7 3 /* Seventh Edition */ +#define FS_SYSV 4 /* System V */ +#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ +#define FS_V8 6 /* Eighth Edition, 4K blocks */ +#define FS_BSDFFS 7 /* 4.2BSD fast file system */ +#define FS_MSDOS 8 /* MSDOS file system */ +#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ +#define FS_OTHER 10 /* in use, but unknown/unsupported */ +#define FS_HPFS 11 /* OS/2 high-performance file system */ +#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ +#define FS_BOOT 13 /* partition contains bootstrap */ +#define FS_VINUM 14 /* Vinum drive */ + +#ifdef DKTYPENAMES +static char *fstypenames[] = { + "unused", + "swap", + "Version 6", + "Version 7", + "System V", + "4.1BSD", + "Eighth Edition", + "4.2BSD", + "MSDOS", + "4.4LFS", + "unknown", + "HPFS", + "ISO9660", + "boot", + "vinum", + NULL +}; +#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) +#endif + +/* + * flags shared by various drives: + */ +#define D_REMOVABLE 0x01 /* removable media */ +#define D_ECC 0x02 /* supports ECC */ +#define D_BADSECT 0x04 /* supports bad sector forw. */ +#define D_RAMDISK 0x08 /* disk emulator */ +#define D_CHAIN 0x10 /* can do back-back transfers */ + +/* + * Drive data for SMD. + */ +#define d_smdflags d_drivedata[0] +#define D_SSE 0x1 /* supports skip sectoring */ +#define d_mindist d_drivedata[1] +#define d_maxdist d_drivedata[2] +#define d_sdist d_drivedata[3] + +/* + * Drive data for ST506. + */ +#define d_precompcyl d_drivedata[0] +#define d_gap3 d_drivedata[1] /* used only when formatting */ + +/* + * Drive data for SCSI. + */ +#define d_blind d_drivedata[0] + +#ifndef LOCORE +/* + * Structure used to perform a format or other raw operation, returning + * data and/or register values. Register identification and format + * are device- and driver-dependent. + */ +struct format_op { + char *df_buf; + int df_count; /* value-result */ + daddr_t df_startblk; + int df_reg[8]; /* result */ +}; + +/* + * Structure used internally to retrieve information about a partition + * on a disk. + */ +struct partinfo { + struct disklabel *disklab; + struct partition *part; +}; + +/* DOS partition table -- located in boot block */ + +#if defined(PC98) && !defined(PC98_ATCOMPAT) +#define DOSBBSECTOR 0 /* DOS boot block relative sector number */ +#define DOSLABELSECTOR 1 /* 0: 256b/s, 1: 512b/s */ +#define DOSPARTOFF 0 +#define NDOSPART 16 +#define DOSPTYP_386BSD 0x94 /* 386BSD partition type */ +#define MBR_PTYPE_FreeBSD 0x94 /* FreeBSD partition type */ + +struct dos_partition { + unsigned char dp_mid; +#define DOSMID_386BSD (0x14|0x80) /* 386bsd|bootable */ + unsigned char dp_sid; +#define DOSSID_386BSD (0x44|0x80) /* 386bsd|active */ + unsigned char dp_dum1; + unsigned char dp_dum2; + unsigned char dp_ipl_sct; + unsigned char dp_ipl_head; + unsigned short dp_ipl_cyl; + unsigned char dp_ssect; /* starting sector */ + unsigned char dp_shd; /* starting head */ + unsigned short dp_scyl; /* starting cylinder */ + unsigned char dp_esect; /* end sector */ + unsigned char dp_ehd; /* end head */ + unsigned short dp_ecyl; /* end cylinder */ + unsigned char dp_name[16]; +}; + +#else /* IBMPC */ +#define DOSBBSECTOR 0 /* DOS boot block relative sector number */ +#define DOSPARTOFF 446 +#define NDOSPART 4 +#define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */ +#define DOSPTYP_LINSWP 0x82 /* Linux swap partition */ +#define DOSPTYP_LINUX 0x83 /* Linux partition */ +#define DOSPTYP_EXT 5 /* DOS extended partition */ + +struct dos_partition { + unsigned char dp_flag; /* bootstrap flags */ + unsigned char dp_shd; /* starting head */ + unsigned char dp_ssect; /* starting sector */ + unsigned char dp_scyl; /* starting cylinder */ + unsigned char dp_typ; /* partition type */ + unsigned char dp_ehd; /* end head */ + unsigned char dp_esect; /* end sector */ + unsigned char dp_ecyl; /* end cylinder */ + u_int32_t dp_start; /* absolute starting sector number */ + u_int32_t dp_size; /* partition size in sectors */ +}; +#endif + +#define DPSECT(s) ((s) & 0x3f) /* isolate relevant bits of sector */ +#define DPCYL(c, s) ((c) + (((s) & 0xc0)<<2)) /* and those that are cylinder */ + +/* + * Disk-specific ioctls. + */ + /* get and set disklabel; DIOCGPART used internally */ +#define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */ +#define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */ +#define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */ +#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ +#define DIOCGDVIRGIN _IOR('d', 105, struct disklabel) /* get virgin label */ + +#define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */ + +#ifdef _KERNEL + +/* + * XXX encoding of disk minor numbers, should be elsewhere. + * + * See for a possibly better encoding. + * + * "cpio -H newc" can be used to back up device files with large minor + * numbers (but not ones >= 2^31). Old cpio formats and all tar formats + * don't have enough bits, and cpio and tar don't notice the lossage. + * There are also some sign extension bugs. + */ + +/* + 3 2 1 0 + 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + _________________________________________________________________ + | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | + ----------------------------------------------------------------- + | TYPE |UNIT_2 | SLICE | MAJOR? | UNIT |PART | + ----------------------------------------------------------------- +*/ + +#define DKMAXUNIT 0x1ff /* Highest disk unit number */ + +#define dkmakeminor(unit, slice, part) \ + (((slice) << 16) | (((unit) & 0x1e0) << 16) | \ + (((unit) & 0x1f) << 3) | (part)) +static __inline dev_t +dkmodpart(dev_t dev, int part) +{ + return (makedev(major(dev), (minor(dev) & ~7) | part)); +} + +static __inline dev_t +dkmodslice(dev_t dev, int slice) +{ + return (makedev(major(dev), (minor(dev) & ~0x1f0000) | (slice << 16))); +} + +#define dkpart(dev) (minor(dev) & 7) +#define dkslice(dev) ((minor(dev) >> 16) & 0x1f) +#define dktype(dev) ((minor(dev) >> 25) & 0x7f) + +static __inline u_int +dkunit(dev_t dev) +{ + return (((minor(dev) >> 16) & 0x1e0) | ((minor(dev) >> 3) & 0x1f)); +} + +struct buf; +struct buf_queue_head; + +int bounds_check_with_label __P((struct buf *bp, struct disklabel *lp, + int wlabel)); +void diskerr __P((struct buf *bp, char *what, int pri, int blkdone, + struct disklabel *lp)); +void disksort __P((struct buf *ap, struct buf *bp)); +char *readdisklabel __P((dev_t dev, struct disklabel *lp)); +void bufqdisksort __P((struct buf_queue_head *ap, struct buf *bp)); +int setdisklabel __P((struct disklabel *olp, struct disklabel *nlp, + u_long openmask)); +int writedisklabel __P((dev_t dev, struct disklabel *lp)); +#ifdef __alpha__ +void alpha_fix_srm_checksum __P((struct buf *bp)); +#endif + +#endif /* _KERNEL */ + +#endif /* LOCORE */ + +#ifndef _KERNEL +__BEGIN_DECLS +struct disklabel *getdiskbyname __P((const char *)); +__END_DECLS +#endif + +#endif /* !_SYS_DISKLABEL_H_ */ diff --git a/src/sys/boot/boot2/diskslice.h b/src/sys/boot/boot2/diskslice.h new file mode 100644 index 0000000..c5d50bb --- /dev/null +++ b/src/sys/boot/boot2/diskslice.h @@ -0,0 +1,107 @@ +/*- + * Copyright (c) 1994 Bruce D. Evans. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/diskslice.h,v 1.36.2.1 2001/01/29 01:50:50 ken Exp $ + */ + +#ifndef _SYS_DISKSLICE_H_ +#define _SYS_DISKSLICE_H_ + +#ifndef _KERNEL +#include +#endif +#include + +#define BASE_SLICE 2 +#define COMPATIBILITY_SLICE 0 +#define DIOCGSLICEINFO _IOR('d', 111, struct diskslices) +#define DIOCSYNCSLICEINFO _IOW('d', 112, int) +#define MAX_SLICES 32 +#define WHOLE_DISK_SLICE 1 + +struct diskslice { + u_long ds_offset; /* starting sector */ + u_long ds_size; /* number of sectors */ + int ds_type; /* (foreign) slice type */ +#ifdef PC98 + int ds_subtype; /* sub slice type */ + u_char ds_name[16]; /* slice name */ +#endif + struct disklabel *ds_label; /* BSD label, if any */ + void *ds_dev; /* devfs token for raw whole slice */ +#ifdef MAXPARTITIONS /* XXX don't depend on disklabel.h */ +#if MAXPARTITIONS != 8 /* but check consistency if possible */ +#error "inconsistent MAXPARTITIONS" +#endif +#else +#define MAXPARTITIONS 8 +#endif + void *ds_devs[MAXPARTITIONS]; /* XXX s.b. in label */ + u_char ds_openmask; /* devs open */ + u_char ds_wlabel; /* nonzero if label is writable */ +}; + +struct diskslices { + struct cdevsw *dss_cdevsw; /* for containing device */ + int dss_first_bsd_slice; /* COMPATIBILITY_SLICE is mapped here */ + u_int dss_nslices; /* actual dimension of dss_slices[] */ + u_int dss_oflags; /* copy of flags for "first" open */ + int dss_secmult; /* block to sector multiplier */ + int dss_secshift; /* block to sector shift (or -1) */ + int dss_secsize; /* sector size */ + struct diskslice + dss_slices[MAX_SLICES]; /* actually usually less */ +}; + +#ifdef _KERNEL + +/* Flags for dsopen(). */ +#define DSO_NOLABELS 1 +#define DSO_ONESLICE 2 +#define DSO_COMPATLABEL 4 + +#define dsgetlabel(dev, ssp) (ssp->dss_slices[dkslice(dev)].ds_label) + +struct buf; +struct disklabel; + +int dscheck __P((struct buf *bp, struct diskslices *ssp)); +void dsclose __P((dev_t dev, int mode, struct diskslices *ssp)); +void dsgone __P((struct diskslices **sspp)); +int dsinit __P((dev_t dev, struct disklabel *lp, + struct diskslices **sspp)); +int dsioctl __P((dev_t dev, u_long cmd, caddr_t data, + int flags, struct diskslices **sspp)); +int dsisopen __P((struct diskslices *ssp)); +struct diskslices *dsmakeslicestruct __P((int nslices, struct disklabel *lp)); +char *dsname __P((dev_t dev, int unit, int slice, int part, + char *partname)); +int dsopen __P((dev_t dev, int mode, u_int flags, + struct diskslices **sspp, struct disklabel *lp)); +int dssize __P((dev_t dev, struct diskslices **sspp)); + +#endif /* _KERNEL */ + +#endif /* !_SYS_DISKSLICE_H_ */ diff --git a/src/sys/boot/boot2/lib.h b/src/sys/boot/boot2/lib.h new file mode 100644 index 0000000..44d1f10 --- /dev/null +++ b/src/sys/boot/boot2/lib.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 1998 Robert Nordier + * All rights reserved. + * + * Redistribution and use in source and binary forms are freely + * permitted provided that the above copyright notice and this + * paragraph and the following disclaimer are duplicated in all + * such forms. + * + * This software is provided "AS IS" and without any express or + * implied warranties, including, without limitation, the implied + * warranties of merchantability and fitness for a particular + * purpose. + */ + +/* + * $FreeBSD: src/sys/boot/i386/boot2/lib.h,v 1.2 1999/08/28 00:40:02 peter Exp $ + */ + +void sio_init(void); +void sio_flush(void); +void sio_putc(int); +int sio_getc(void); +int sio_ischar(void); diff --git a/src/sys/boot/boot2/sio.s b/src/sys/boot/boot2/sio.s new file mode 100644 index 0000000..1e8da20 --- /dev/null +++ b/src/sys/boot/boot2/sio.s @@ -0,0 +1,80 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/boot2/sio.s,v 1.4 1999/08/28 00:40:02 peter Exp $ + + .set SIO_PRT,SIOPRT # Base port + .set SIO_FMT,SIOFMT # 8N1 + .set SIO_DIV,(115200/SIOSPD) # 115200 / SPD + + .globl sio_init + .globl sio_flush + .globl sio_putc + .globl sio_getc + .globl sio_ischar + +# void sio_init(void) + +sio_init: movw $SIO_PRT+0x3,%dx # Data format reg + movb $SIO_FMT|0x80,%al # Set format + outb %al,(%dx) # and DLAB + pushl %edx # Save + subb $0x3,%dl # Divisor latch reg + movw $SIO_DIV,%ax # Set + outw %ax,(%dx) # BPS + popl %edx # Restore + movb $SIO_FMT,%al # Clear + outb %al,(%dx) # DLAB + incl %edx # Modem control reg + movb $0x3,%al # Set RTS, + outb %al,(%dx) # DTR + incl %edx # Line status reg + +# void sio_flush(void) + +sio_flush.0: call sio_getc.1 # Get character +sio_flush: call sio_ischar # Check for character + jnz sio_flush.0 # Till none + ret # To caller + +# void sio_putc(int c) + +sio_putc: movw $SIO_PRT+0x5,%dx # Line status reg + xor %ecx,%ecx # Timeout + movb $0x40,%ch # counter +sio_putc.1: inb (%dx),%al # Transmitter + testb $0x20,%al # buffer empty? + loopz sio_putc.1 # No + jz sio_putc.2 # If timeout + movb 0x4(%esp,1),%al # Get character + subb $0x5,%dl # Transmitter hold reg + outb %al,(%dx) # Write character +sio_putc.2: ret $0x4 # To caller + +# int sio_getc(void) + +sio_getc: call sio_ischar # Character available? + jz sio_getc # No +sio_getc.1: subb $0x5,%dl # Receiver buffer reg + inb (%dx),%al # Read character + ret # To caller + +# int sio_ischar(void) + +sio_ischar: movw $SIO_PRT+0x5,%dx # Line status register + xorl %eax,%eax # Zero + inb (%dx),%al # Received data + andb $0x1,%al # ready? + ret # To caller diff --git a/src/sys/boot/boot2/test.c b/src/sys/boot/boot2/test.c new file mode 100644 index 0000000..6809b01 --- /dev/null +++ b/src/sys/boot/boot2/test.c @@ -0,0 +1,32 @@ +#include +#include + +#include "ubixfs.h" + +int main(int argc,char **argv) { + FILE *fd; + struct ubixDiskLabel *d = (struct ubixDiskLabel *)malloc(512); + printf("Building Disk Label\n"); + d->magicNum = UBIXDISKMAGIC; + d->magicNum2 = UBIXDISKMAGIC; + d->numPartitions = 2; + d->partitions[0].p_size = 204361; + d->partitions[0].p_offset = 50; + d->partitions[0].p_fstype = 0xAD; + d->partitions[0].p_bsize = 0x8; + d->partitions[1].p_size = 2000; + d->partitions[1].p_offset = 1000; + d->partitions[1].p_fstype = 0xAD; + d->partitions[1].p_bsize = 0x8; + d->partitions[2].p_size = 0; + d->partitions[2].p_offset = 0; + d->partitions[2].p_fstype = 0; + d->partitions[2].p_bsize = 0; + d->partitions[3].p_size = 0; + d->partitions[3].p_offset = 0; + d->partitions[3].p_fstype = 0; + d->partitions[3].p_bsize = 0; + fd = fopen(argv[1],"wb"); + fseek(fd,512 * (atoi(argv[2])),0); + fwrite(d,512,1,fd); + } diff --git a/src/sys/boot/boot2/ubixfs.h b/src/sys/boot/boot2/ubixfs.h new file mode 100644 index 0000000..dc11906 --- /dev/null +++ b/src/sys/boot/boot2/ubixfs.h @@ -0,0 +1,44 @@ +#define DOSPTYP_UBX 0xAD /* UbixFS partition type */ +#define UBIXDISKMAGIC ((u_int32_t)0x45) /* The disk magic number */ +#define MAXUBIXPARTITIONS 16 +#define UBIXFSMAGIC ((u_int32_t)0x69) /* The File System Magic Number */ + +typedef unsigned long uLong; +typedef unsigned short uShort; + + +struct ubixDiskLabel { + u_int32_t magicNum; + u_int32_t magicNum2; + u_int16_t driveType; + u_int16_t numPartitions; + struct ubixPartitions { /* the partition table */ + u_int32_t p_size; /* number of sectors in partition */ + u_int32_t p_offset; /* starting sector */ + u_int32_t p_fsize; /* filesystem basic fragment size */ + u_int32_t p_bsize; /* BAT size */ + u_int8_t p_fstype; /* filesystem type, see below */ + u_int8_t p_frag; /* filesystem fragments per block */ + } partitions[MAXUBIXPARTITIONS]; + }; + +//Block Allocation Table Entry +struct blockAllocationTableEntry { + long attributes; //Block Attributes + long realSector; //Real Sector + long nextBlock; //Sector Of Next Block + long reserved; //Reserved + }; + + +struct directoryEntry { + uLong startCluster; //Starting Cluster Of File + uLong size; //Size Of File + uLong creationDate; //Date Created + uLong lastModified; //Date Last Modified + uLong uid; //UID Of Owner + uLong gid; //GID Of Owner + uShort attributes; //Files Attributes + uShort permissions; //Files Permissions + char fileName[256]; //File Name + }; diff --git a/src/sys/boot/btx/Makefile b/src/sys/boot/btx/Makefile new file mode 100644 index 0000000..9a65f19 --- /dev/null +++ b/src/sys/boot/btx/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD: src/sys/boot/i386/btx/Makefile,v 1.6 1999/08/28 00:40:03 peter Exp $ + +SUBDIR= btx btxldr lib + +.include diff --git a/src/sys/boot/btx/btx/Makefile b/src/sys/boot/btx/btx/Makefile new file mode 100644 index 0000000..cdefb50 --- /dev/null +++ b/src/sys/boot/btx/btx/Makefile @@ -0,0 +1,36 @@ +# $FreeBSD: src/sys/boot/i386/btx/btx/Makefile,v 1.7.2.2 2000/12/28 12:08:22 ps Exp $ + +M4?= m4 + +.if defined(PAGING) +M4FLAGS+= -DPAGING +.endif + +.if defined(BOOT_BTX_NOHANG) +BOOT_BTX_FLAGS=0x1 +.else +BOOT_BTX_FLAGS=0x0 +.endif + +AFLAGS+= --defsym BTX_FLAGS=${BOOT_BTX_FLAGS} + +ORG= 0x9000 + +all: btx + +btx: btx.o +.if ${OBJFORMAT} == aout + ${LD} -nostdlib -N -s -T ${ORG} -o btx.out btx.o + dd if=btx.out of=${.TARGET} ibs=32 skip=1 +.else + ${LD} -N -e start -Ttext ${ORG} -o btx.out btx.o + objcopy -S -O binary btx.out ${.TARGET} +.endif + +btx.o: btx.s + (cd ${.CURDIR}; ${M4} ${M4FLAGS} btx.s) | \ + ${AS} ${AFLAGS} -o ${.TARGET} + +CLEANFILES+= btx btx.out btx.o + +.include diff --git a/src/sys/boot/btx/btx/btx.s b/src/sys/boot/btx/btx/btx.s new file mode 100644 index 0000000..0bcf0a9 --- /dev/null +++ b/src/sys/boot/btx/btx/btx.s @@ -0,0 +1,1080 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/btx/btx/btx.s,v 1.15.2.4 2000/12/28 12:08:22 ps Exp $ + +# +# Memory layout. +# + .set MEM_BTX,0x1000 # Start of BTX memory + .set MEM_ESP0,0x1800 # Supervisor stack + .set MEM_BUF,0x1800 # Scratch buffer + .set MEM_ESP1,0x1e00 # Link stack + .set MEM_IDT,0x1e00 # IDT + .set MEM_TSS,0x1f98 # TSS + .set MEM_MAP,0x2000 # I/O bit map + .set MEM_DIR,0x4000 # Page directory + .set MEM_TBL,0x5000 # Page tables + .set MEM_ORG,0x9000 # BTX code + .set MEM_USR,0xa000 # Start of user memory +# +# Paging control. +# + .set PAG_SIZ,0x1000 # Page size + .set PAG_CNT,0x1000 # Pages to map +# +# Segment selectors. +# + .set SEL_SCODE,0x8 # Supervisor code + .set SEL_SDATA,0x10 # Supervisor data + .set SEL_RCODE,0x18 # Real mode code + .set SEL_RDATA,0x20 # Real mode data + .set SEL_UCODE,0x28|3 # User code + .set SEL_UDATA,0x30|3 # User data + .set SEL_TSS,0x38 # TSS +# +# Task state segment fields. +# + .set TSS_ESP0,0x4 # PL 0 ESP + .set TSS_SS0,0x8 # PL 0 SS + .set TSS_ESP1,0xc # PL 1 ESP + .set TSS_MAP,0x66 # I/O bit map base +# +# System calls. +# + .set SYS_EXIT,0x0 # Exit + .set SYS_EXEC,0x1 # Exec +# +# V86 constants. +# + .set V86_FLG,0x208eff # V86 flag mask + .set V86_STK,0x400 # V86 stack allowance +# +# Dump format control bytes. +# + .set DMP_X16,0x1 # Word + .set DMP_X32,0x2 # Long + .set DMP_MEM,0x4 # Memory + .set DMP_EOL,0x8 # End of line +# +# Screen defaults and assumptions. +# + .set SCR_MAT,0x7 # Mode/attribute + .set SCR_COL,0x50 # Columns per row + .set SCR_ROW,0x19 # Rows per screen +# +# BIOS Data Area locations. +# + .set BDA_MEM,0x413 # Free memory + .set BDA_KEYFLAGS,0x417 # Keyboard shift-state flags + .set BDA_SCR,0x449 # Video mode + .set BDA_POS,0x450 # Cursor position + .set BDA_BOOT,0x472 # Boot howto flag +# +# Derivations, for brevity. +# + .set _ESP0H,MEM_ESP0>>0x8 # Byte 1 of ESP0 + .set _ESP1H,MEM_ESP1>>0x8 # Byte 1 of ESP1 + .set _TSSIO,MEM_MAP-MEM_TSS # TSS I/O base + .set _TSSLM,MEM_DIR-MEM_TSS-1 # TSS limit + .set _IDTLM,MEM_TSS-MEM_IDT-1 # IDT limit +# +# Code segment. +# + .globl start + .code16 +start: # Start of code +# +# BTX header. +# +btx_hdr: .byte 0xeb # Machine ID + .byte 0xe # Header size + .ascii "BTX" # Magic + .byte 0x1 # Major version + .byte 0x1 # Minor version + .byte BTX_FLAGS # Flags + .word PAG_CNT-MEM_ORG>>0xc # Paging control + .word break-start # Text size + .long 0x0 # Entry address +# +# Initialization routine. +# +init: cli # Disable interrupts + xor %ax,%ax # Zero/segment + mov %ax,%ss # Set up + mov $MEM_ESP0,%sp # stack + mov %ax,%es # Address + mov %ax,%ds # data + pushl $0x2 # Clear + popfl # flags +# +# Initialize memory. +# + mov $MEM_IDT,%di # Memory to initialize + mov $(MEM_ORG-MEM_IDT)/2,%cx # Words to zero + push %di # Save + rep # Zero-fill + stosw # memory + pop %di # Restore +# +# Create IDT. +# + mov $idtctl,%si # Control string +init.1: lodsb # Get entry + cbw # count + xchg %ax,%cx # as word + jcxz init.4 # If done + lodsb # Get segment + xchg %ax,%dx # P:DPL:type + lodsw # Get control + xchg %ax,%bx # set + lodsw # Get handler offset + mov $SEL_SCODE,%dh # Segment selector +init.2: shr %bx # Handle this int? + jnc init.3 # No + mov %ax,(%di) # Set handler offset + mov %dh,0x2(%di) # and selector + mov %dl,0x5(%di) # Set P:DPL:type + add $0x4,%ax # Next handler +init.3: lea 0x8(%di),%di # Next entry + loop init.2 # Till set done + jmp init.1 # Continue +# +# Initialize TSS. +# +init.4: movb $_ESP0H,TSS_ESP0+1(%di) # Set ESP0 + movb $SEL_SDATA,TSS_SS0(%di) # Set SS0 + movb $_ESP1H,TSS_ESP1+1(%di) # Set ESP1 + movb $_TSSIO,TSS_MAP(%di) # Set I/O bit map base +ifdef(`PAGING',` +# +# Create page directory. +# + xor %edx,%edx # Page + mov $PAG_SIZ>>0x8,%dh # size + xor %eax,%eax # Zero + mov $MEM_DIR,%di # Page directory + mov $PAG_CNT>>0xa,%cl # Entries + mov $MEM_TBL|0x7,%ax # First entry +init.5: stosl # Write entry + add %dx,%ax # To next + loop init.5 # Till done +# +# Create page tables. +# + mov $MEM_TBL,%di # Page table + mov $PAG_CNT>>0x8,%ch # Entries + xor %ax,%ax # Start address +init.6: mov $0x7,%al # Set U:W:P flags + cmp btx_hdr+0x8,%cx # Standard user page? + jb init.7 # Yes + cmp $PAG_CNT-MEM_BTX>>0xc,%cx # BTX memory? + jae init.7 # No or first page + and $~0x2,%al # Clear W flag + cmp $PAG_CNT-MEM_USR>>0xc,%cx # User page zero? + jne init.7 # No + testb $0x80,btx_hdr+0x7 # Unmap it? + jz init.7 # No + and $~0x1,%al # Clear P flag +init.7: stosl # Set entry + add %edx,%eax # Next address + loop init.6 # Till done +') +# +# Bring up the system. +# + mov $0x2820,%bx # Set protected mode + callw setpic # IRQ offsets + lidt idtdesc # Set IDT +ifdef(`PAGING',` + xor %eax,%eax # Set base + mov $MEM_DIR>>0x8,%ah # of page + mov %eax,%cr3 # directory +') + lgdt gdtdesc # Set GDT + mov %cr0,%eax # Switch to protected +ifdef(`PAGING',` + or $0x80000001,%eax # mode and enable paging +',` + or $0x01,%eax # mode +') + mov %eax,%cr0 # + ljmp $SEL_SCODE,$init.8 # To 32-bit code + .code32 +init.8: xorl %ecx,%ecx # Zero + movb $SEL_SDATA,%cl # To 32-bit + movw %cx,%ss # stack +# +# Launch user task. +# + movb $SEL_TSS,%cl # Set task + ltr %cx # register + movl $MEM_USR,%edx # User base address + movzwl %ss:BDA_MEM,%eax # Get free memory + shll $0xa,%eax # To bytes + subl $0x1000,%eax # Less arg space + subl %edx,%eax # Less base + movb $SEL_UDATA,%cl # User data selector + pushl %ecx # Set SS + pushl %eax # Set ESP + push $0x202 # Set flags (IF set) + push $SEL_UCODE # Set CS + pushl btx_hdr+0xc # Set EIP + pushl %ecx # Set GS + pushl %ecx # Set FS + pushl %ecx # Set DS + pushl %ecx # Set ES + pushl %edx # Set EAX + movb $0x7,%cl # Set remaining +init.9: push $0x0 # general + loop init.9 # registers + popa # and initialize + popl %es # Initialize + popl %ds # user + popl %fs # segment + popl %gs # registers + iret # To user mode +# +# Exit routine. +# +exit: cli # Disable interrupts + movl $MEM_ESP0,%esp # Clear stack +# +# Turn off paging. +# + movl %cr0,%eax # Get CR0 +ifdef(`PAGING',` + andl $~0x80000000,%eax # Disable + movl %eax,%cr0 # paging +') + xorl %ecx,%ecx # Zero +ifdef(`PAGING',` + movl %ecx,%cr3 # Flush TLB +') +# +# To 16 bits. +# + ljmpw $SEL_RCODE,$exit.1 # Reload CS + .code16 +exit.1: mov $SEL_RDATA,%cl # 16-bit selector + mov %cx,%ss # Reload SS + mov %cx,%ds # Load + mov %cx,%es # remaining + mov %cx,%fs # segment + mov %cx,%gs # registers +# +# To real-address mode. +# + dec %ax # Switch to + mov %eax,%cr0 # real mode + ljmp $0x0,$exit.2 # Reload CS +exit.2: xor %ax,%ax # Real mode segment + mov %ax,%ss # Reload SS + mov %ax,%ds # Address data + mov $0x7008,%bx # Set real mode + callw setpic # IRQ offsets + lidt ivtdesc # Set IVT +# +# Reboot or await reset. +# + sti # Enable interrupts + testb $0x1,btx_hdr+0x7 # Reboot? +exit.3: jz exit.3 # No + movw $0x1234, BDA_BOOT # Do a warm boot + ljmp $0xffff,$0x0 # reboot the machine +# +# Set IRQ offsets by reprogramming 8259A PICs. +# +setpic: in $0x21,%al # Save master + push %ax # IMR + in $0xa1,%al # Save slave + push %ax # IMR + movb $0x11,%al # ICW1 to + outb %al,$0x20 # master, + outb %al,$0xa0 # slave + movb %bl,%al # ICW2 to + outb %al,$0x21 # master + movb %bh,%al # ICW2 to + outb %al,$0xa1 # slave + movb $0x4,%al # ICW3 to + outb %al,$0x21 # master + movb $0x2,%al # ICW3 to + outb %al,$0xa1 # slave + movb $0x1,%al # ICW4 to + outb %al,$0x21 # master, + outb %al,$0xa1 # slave + pop %ax # Restore slave + outb %al,$0xa1 # IMR + pop %ax # Restore master + outb %al,$0x21 # IMR + retw # To caller + .code32 +# +# Initiate return from V86 mode to user mode. +# +inthlt: hlt # To supervisor mode +# +# Exception jump table. +# +intx00: push $0x0 # Int 0x0: #DE + jmp ex_noc # Divide error + push $0x1 # Int 0x1: #DB + jmp ex_noc # Debug + push $0x3 # Int 0x3: #BP + jmp ex_noc # Breakpoint + push $0x4 # Int 0x4: #OF + jmp ex_noc # Overflow + push $0x5 # Int 0x5: #BR + jmp ex_noc # BOUND range exceeded + push $0x6 # Int 0x6: #UD + jmp ex_noc # Invalid opcode + push $0x7 # Int 0x7: #NM + jmp ex_noc # Device not available + push $0x8 # Int 0x8: #DF + jmp except # Double fault + push $0xa # Int 0xa: #TS + jmp except # Invalid TSS + push $0xb # Int 0xb: #NP + jmp except # Segment not present + push $0xc # Int 0xc: #SS + jmp except # Stack segment fault + push $0xd # Int 0xd: #GP + jmp ex_v86 # General protection + push $0xe # Int 0xe: #PF + jmp except # Page fault +intx10: push $0x10 # Int 0x10: #MF + jmp ex_noc # Floating-point error +# +# Handle #GP exception. +# +ex_v86: testb $0x2,0x12(%esp,1) # V86 mode? + jz except # No + jmp v86mon # To monitor +# +# Save a zero error code. +# +ex_noc: pushl (%esp,1) # Duplicate int no + movb $0x0,0x4(%esp,1) # Fake error code +# +# Handle exception. +# +except: cld # String ops inc + pushl %ds # Save + pushl %es # most + pusha # registers + movb $0x6,%al # Push loop count + testb $0x2,0x3a(%esp,1) # V86 mode? + jnz except.1 # Yes + pushl %gs # Set GS + pushl %fs # Set FS + pushl %ds # Set DS + pushl %es # Set ES + movb $0x2,%al # Push loop count + cmpw $SEL_SCODE,0x44(%esp,1) # Supervisor mode? + jne except.1 # No + pushl %ss # Set SS + leal 0x50(%esp,1),%eax # Set + pushl %eax # ESP + jmp except.2 # Join common code +except.1: pushl 0x50(%esp,1) # Set GS, FS, DS, ES + decb %al # (if V86 mode), and + jne except.1 # SS, ESP +except.2: push $SEL_SDATA # Set up + popl %ds # to + pushl %ds # address + popl %es # data + movl %esp,%ebx # Stack frame + movl $dmpfmt,%esi # Dump format string + movl $MEM_BUF,%edi # Buffer + pushl %edi # Dump to + call dump # buffer + popl %esi # and + call putstr # display + leal 0x18(%esp,1),%esp # Discard frame + popa # Restore + popl %es # registers + popl %ds # saved + cmpb $0x3,(%esp,1) # Breakpoint? + je except.3 # Yes + jmp exit # Exit +except.3: leal 0x8(%esp,1),%esp # Discard err, int no + iret # From interrupt +# +# Return to user mode from V86 mode. +# +intrtn: cld # String ops inc + pushl %ds # Address + popl %es # data + leal 0x3c(%ebp),%edx # V86 Segment registers + movl MEM_TSS+TSS_ESP1,%esi # Link stack pointer + lodsl # INT_V86 args pointer + movl %esi,%ebx # Saved exception frame + testl %eax,%eax # INT_V86 args? + jz intrtn.2 # No + movl $MEM_USR,%edi # User base + movl 0x1c(%esi),%ebx # User ESP + movl %eax,(%edi,%ebx,1) # Restore to user stack + leal 0x8(%edi,%eax,1),%edi # Arg segment registers + testb $0x4,-0x6(%edi) # Return flags? + jz intrtn.1 # No + movl 0x30(%ebp),%eax # Get V86 flags + movw %ax,0x18(%esi) # Set user flags +intrtn.1: leal 0x10(%esi),%ebx # Saved exception frame + xchgl %edx,%esi # Segment registers + movb $0x4,%cl # Update seg regs + rep # in INT_V86 + movsl # args +intrtn.2: movl %edx,%esi # Segment registers + leal 0x28(%ebp),%edi # Set up seg + movb $0x4,%cl # regs for + rep # later + movsl # pop + movl %ebx,%esi # Restore exception + movb $0x5,%cl # frame to + rep # supervisor + movsl # stack + movl %esi,MEM_TSS+TSS_ESP1 # Link stack pointer + popa # Restore + leal 0x8(%esp,1),%esp # Discard err, int no + popl %es # Restore + popl %ds # user + popl %fs # segment + popl %gs # registers + iret # To user mode +# +# V86 monitor. +# +v86mon: cld # String ops inc + pushl $SEL_SDATA # Set up for + popl %ds # flat addressing + pusha # Save registers + movl %esp,%ebp # Address stack frame + movzwl 0x2c(%ebp),%edi # Load V86 CS + shll $0x4,%edi # To linear + movl 0x28(%ebp),%esi # Load V86 IP + addl %edi,%esi # Code pointer + xorl %ecx,%ecx # Zero + movb $0x2,%cl # 16-bit operands + xorl %eax,%eax # Zero +v86mon.1: lodsb # Get opcode + cmpb $0x66,%al # Operand size prefix? + jne v86mon.2 # No + movb $0x4,%cl # 32-bit operands + jmp v86mon.1 # Continue +v86mon.2: cmpb $0xf4,%al # HLT? + jne v86mon.3 # No + cmpl $inthlt+0x1,%esi # Is inthlt? + jne v86mon.7 # No (ignore) + jmp intrtn # Return to user mode +v86mon.3: cmpb $0xf,%al # Prefixed instruction? + jne v86mon.4 # No + cmpb $0x09,(%esi) # Is it a WBINVD? + je v86wbinvd # Yes + cmpb $0x30,(%esi) # Is it a WRMSR? + je v86wrmsr # Yes + cmpb $0x32,(%esi) # Is it a RDMSR? + je v86rdmsr # Yes + cmpb $0x20,(%esi) # Is this a + jne v86mon.4 # MOV EAX,CR0 + cmpb $0xc0,0x1(%esi) # instruction? + je v86mov # Yes +v86mon.4: cmpb $0xfa,%al # CLI? + je v86cli # Yes + cmpb $0xfb,%al # STI? + je v86sti # Yes + movzwl 0x38(%ebp),%ebx # Load V86 SS + shll $0x4,%ebx # To offset + pushl %ebx # Save + addl 0x34(%ebp),%ebx # Add V86 SP + movl 0x30(%ebp),%edx # Load V86 flags + cmpb $0x9c,%al # PUSHF/PUSHFD? + je v86pushf # Yes + cmpb $0x9d,%al # POPF/POPFD? + je v86popf # Yes + cmpb $0xcd,%al # INT imm8? + je v86intn # Yes + cmpb $0xcf,%al # IRET/IRETD? + je v86iret # Yes + popl %ebx # Restore + popa # Restore + jmp except # Handle exception +v86mon.5: movl %edx,0x30(%ebp) # Save V86 flags +v86mon.6: popl %edx # V86 SS adjustment + subl %edx,%ebx # Save V86 + movl %ebx,0x34(%ebp) # SP +v86mon.7: subl %edi,%esi # From linear + movl %esi,0x28(%ebp) # Save V86 IP + popa # Restore + leal 0x8(%esp,1),%esp # Discard int no, error + iret # To V86 mode +# +# Emulate MOV EAX,CR0. +# +v86mov: movl %cr0,%eax # CR0 to + movl %eax,0x1c(%ebp) # saved EAX + incl %esi # Adjust IP +# +# Return from emulating a 0x0f prefixed instruction +# +v86preret: incl %esi # Adjust IP + jmp v86mon.7 # Finish up +# +# Emulate WBINVD +# +v86wbinvd: wbinvd # Write back and invalidate + # cache + jmp v86preret # Finish up +# +# Emulate WRMSR +# +v86wrmsr: movl 0x18(%ebp),%ecx # Get user's %ecx (MSR to write) + movl 0x14(%ebp),%edx # Load the value + movl 0x1c(%ebp),%eax # to write + wrmsr # Write MSR + jmp v86preret # Finish up +# +# Emulate RDMSR +# +v86rdmsr: movl 0x18(%ebp),%ecx # MSR to read + rdmsr # Read the MSR + movl %eax,0x1c(%ebp) # Return the value of + movl %edx,0x14(%ebp) # the MSR to the user + jmp v86preret # Finish up +# +# Emulate CLI. +# +v86cli: andb $~0x2,0x31(%ebp) # Clear IF + jmp v86mon.7 # Finish up +# +# Emulate STI. +# +v86sti: orb $0x2,0x31(%ebp) # Set IF + jmp v86mon.7 # Finish up +# +# Emulate PUSHF/PUSHFD. +# +v86pushf: subl %ecx,%ebx # Adjust SP + cmpb $0x4,%cl # 32-bit + je v86pushf.1 # Yes + data16 # 16-bit +v86pushf.1: movl %edx,(%ebx) # Save flags + jmp v86mon.6 # Finish up +# +# Emulate IRET/IRETD. +# +v86iret: movzwl (%ebx),%esi # Load V86 IP + movzwl 0x2(%ebx),%edi # Load V86 CS + leal 0x4(%ebx),%ebx # Adjust SP + movl %edi,0x2c(%ebp) # Save V86 CS + xorl %edi,%edi # No ESI adjustment +# +# Emulate POPF/POPFD (and remainder of IRET/IRETD). +# +v86popf: cmpb $0x4,%cl # 32-bit? + je v86popf.1 # Yes + movl %edx,%eax # Initialize + data16 # 16-bit +v86popf.1: movl (%ebx),%eax # Load flags + addl %ecx,%ebx # Adjust SP + andl $V86_FLG,%eax # Merge + andl $~V86_FLG,%edx # the + orl %eax,%edx # flags + jmp v86mon.5 # Finish up +# +# trap int 15, function 87 +# reads %es:%si from saved registers on stack to find a GDT containing +# source and destination locations +# reads count of words from saved %cx +# returns success by setting %ah to 0 +# +int15_87: pushl %eax # Save + pushl %ebx # some information + pushl %esi # onto the stack. + pushl %edi + xorl %eax,%eax # clean EAX + xorl %ebx,%ebx # clean EBX + movl 0x4(%ebp),%esi # Get user's ESI + movl 0x3C(%ebp),%ebx # store ES + movw %si,%ax # store SI + shll $0x4,%ebx # Make it a seg. + addl %eax,%ebx # ebx=(es<<4)+si + movb 0x14(%ebx),%al # Grab the + movb 0x17(%ebx),%ah # necessary + shll $0x10,%eax # information + movw 0x12(%ebx),%ax # from + movl %eax,%esi # the + movb 0x1c(%ebx),%al # GDT in order to + movb 0x1f(%ebx),%ah # have %esi offset + shll $0x10,%eax # of source and %edi + movw 0x1a(%ebx),%ax # of destination. + movl %eax,%edi + pushl %ds # Make: + popl %es # es = ds + pushl %ecx # stash ECX + xorl %ecx,%ecx # highw of ECX is clear + movw 0x18(%ebp),%cx # Get user's ECX + shll $0x1,%ecx # Convert from num words to num + # bytes + rep # repeat... + movsb # perform copy. + popl %ecx # Restore + popl %edi + popl %esi # previous + popl %ebx # register + popl %eax # values. + movb $0x0,0x1d(%ebp) # set ah = 0 to indicate + # success + andb $0xfe,%dl # clear CF + jmp v86mon.5 # Finish up + +# +# Reboot the machine by setting the reboot flag and exiting +# +reboot: orb $0x1,btx_hdr+0x7 # Set the reboot flag + jmp exit # Terminate BTX and reboot + +# +# Emulate INT imm8... also make sure to check if it's int 15/87 +# +v86intn: lodsb # Get int no + cmpb $0x19,%al # is it int 19? + je reboot # yes, reboot the machine + cmpb $0x15,%al # is it int 15? + jne v86intn.3 # no, skip parse + pushl %eax # stash EAX + movl 0x1c(%ebp),%eax # user's saved EAX + cmpb $0x87,%ah # is it the memcpy subfunction? + jne v86intn.1 # no, keep checking + popl %eax # get the stack straight + jmp int15_87 # it's our cue +v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout? + jne v86intn.2 # no, handle the int normally + movb BDA_KEYFLAGS,%al # get the shift key state + andb $0xc,%al # mask off just Ctrl and Alt + cmpb $0xc,%al # are both Ctrl and Alt down? + jne v86intn.2 # no, handle the int normally + popl %eax # restore EAX + jmp reboot # reboot the machine +v86intn.2: popl %eax # restore EAX +v86intn.3: subl %edi,%esi # From + shrl $0x4,%edi # linear + movw %dx,-0x2(%ebx) # Save flags + movw %di,-0x4(%ebx) # Save CS + leal -0x6(%ebx),%ebx # Adjust SP + movw %si,(%ebx) # Save IP + shll $0x2,%eax # Scale + movzwl (%eax),%esi # Load IP + movzwl 0x2(%eax),%edi # Load CS + movl %edi,0x2c(%ebp) # Save CS + xorl %edi,%edi # No ESI adjustment + andb $~0x1,%dh # Clear TF + jmp v86mon.5 # Finish up +# +# Hardware interrupt jump table. +# +intx20: push $0x8 # Int 0x20: IRQ0 + jmp int_hw # V86 int 0x8 + push $0x9 # Int 0x21: IRQ1 + jmp int_hw # V86 int 0x9 + push $0xa # Int 0x22: IRQ2 + jmp int_hw # V86 int 0xa + push $0xb # Int 0x23: IRQ3 + jmp int_hw # V86 int 0xb + push $0xc # Int 0x24: IRQ4 + jmp int_hw # V86 int 0xc + push $0xd # Int 0x25: IRQ5 + jmp int_hw # V86 int 0xd + push $0xe # Int 0x26: IRQ6 + jmp int_hw # V86 int 0xe + push $0xf # Int 0x27: IRQ7 + jmp int_hw # V86 int 0xf + push $0x70 # Int 0x28: IRQ8 + jmp int_hw # V86 int 0x70 + push $0x71 # Int 0x29: IRQ9 + jmp int_hw # V86 int 0x71 + push $0x72 # Int 0x2a: IRQ10 + jmp int_hw # V86 int 0x72 + push $0x73 # Int 0x2b: IRQ11 + jmp int_hw # V86 int 0x73 + push $0x74 # Int 0x2c: IRQ12 + jmp int_hw # V86 int 0x74 + push $0x75 # Int 0x2d: IRQ13 + jmp int_hw # V86 int 0x75 + push $0x76 # Int 0x2e: IRQ14 + jmp int_hw # V86 int 0x76 + push $0x77 # Int 0x2f: IRQ15 + jmp int_hw # V86 int 0x77 +# +# Reflect hardware interrupts. +# +int_hw: testb $0x2,0xe(%esp,1) # V86 mode? + jz intusr # No + pushl $SEL_SDATA # Address + popl %ds # data + xchgl %eax,(%esp,1) # Swap EAX, int no + pushl %ebp # Address + movl %esp,%ebp # stack frame + pushl %ebx # Save + shll $0x2,%eax # Get int + movl (%eax),%eax # vector + subl $0x6,0x14(%ebp) # Adjust V86 ESP + movzwl 0x18(%ebp),%ebx # V86 SS + shll $0x4,%ebx # * 0x10 + addl 0x14(%ebp),%ebx # + V86 ESP + xchgw %ax,0x8(%ebp) # Swap V86 IP + rorl $0x10,%eax # Swap words + xchgw %ax,0xc(%ebp) # Swap V86 CS + roll $0x10,%eax # Swap words + movl %eax,(%ebx) # CS:IP for IRET + movl 0x10(%ebp),%eax # V86 flags + movw %ax,0x4(%ebx) # Flags for IRET + andb $~0x3,0x11(%ebp) # Clear IF, TF + popl %ebx # Restore + popl %ebp # saved + popl %eax # registers + iret # To V86 mode +# +# Invoke V86 interrupt from user mode, with arguments. +# +intx31: stc # Have btx_v86 + pushl %eax # Missing int no +# +# Invoke V86 interrupt from user mode. +# +intusr: std # String ops dec + pushl %eax # Expand + pushl %eax # stack + pushl %eax # frame + pusha # Save + pushl %gs # Save + movl %esp,%eax # seg regs + pushl %fs # and + pushl %ds # point + pushl %es # to them + push $SEL_SDATA # Set up + popl %ds # to + pushl %ds # address + popl %es # data + movl $MEM_USR,%ebx # User base + movl %ebx,%edx # address + jc intusr.1 # If btx_v86 + xorl %edx,%edx # Control flags + xorl %ebp,%ebp # btx_v86 pointer +intusr.1: leal 0x50(%esp,1),%esi # Base of frame + pushl %esi # Save + addl -0x4(%esi),%ebx # User ESP + movl MEM_TSS+TSS_ESP1,%edi # Link stack pointer + leal -0x4(%edi),%edi # Adjust for push + xorl %ecx,%ecx # Zero + movb $0x5,%cl # Push exception + rep # frame on + movsl # link stack + xchgl %eax,%esi # Saved seg regs + movl 0x40(%esp,1),%eax # Get int no + testl %edx,%edx # Have btx_v86? + jz intusr.2 # No + movl (%ebx),%ebp # btx_v86 pointer + movb $0x4,%cl # Count + addl %ecx,%ebx # Adjust for pop + rep # Push saved seg regs + movsl # on link stack + addl %ebp,%edx # Flatten btx_v86 ptr + leal 0x14(%edx),%esi # Seg regs pointer + movl 0x4(%edx),%eax # Get int no/address + movzwl 0x2(%edx),%edx # Get control flags +intusr.2: movl %ebp,(%edi) # Push btx_v86 and + movl %edi,MEM_TSS+TSS_ESP1 # save link stack ptr + popl %edi # Base of frame + xchgl %eax,%ebp # Save intno/address + movl 0x48(%esp,1),%eax # Get flags + testb $0x2,%dl # Simulate CALLF? + jnz intusr.3 # Yes + decl %ebx # Push flags + decl %ebx # on V86 + movw %ax,(%ebx) # stack +intusr.3: movb $0x4,%cl # Count + subl %ecx,%ebx # Push return address + movl $inthlt,(%ebx) # on V86 stack + rep # Copy seg regs to + movsl # exception frame + xchgl %eax,%ecx # Save flags + movl %ebx,%eax # User ESP + subl $V86_STK,%eax # Less bytes + ja intusr.4 # to + xorl %eax,%eax # keep +intusr.4: shrl $0x4,%eax # Gives segment + stosl # Set SS + shll $0x4,%eax # To bytes + xchgl %eax,%ebx # Swap + subl %ebx,%eax # Gives offset + stosl # Set ESP + xchgl %eax,%ecx # Get flags + btsl $0x11,%eax # Set VM + andb $~0x1,%ah # Clear TF + stosl # Set EFL + xchgl %eax,%ebp # Get int no/address + testb $0x1,%dl # Address? + jnz intusr.5 # Yes + shll $0x2,%eax # Scale + movl (%eax),%eax # Load int vector +intusr.5: movl %eax,%ecx # Save + shrl $0x10,%eax # Gives segment + stosl # Set CS + movw %cx,%ax # Restore + stosl # Set EIP + leal 0x10(%esp,1),%esp # Discard seg regs + popa # Restore + iret # To V86 mode +# +# System Call. +# +intx30: cmpl $SYS_EXEC,%eax # Exec system call? + jne intx30.1 # No + pushl %ss # Set up + popl %es # all + pushl %es # segment + popl %ds # registers + pushl %ds # for the + popl %fs # program + pushl %fs # we're + popl %gs # invoking + movl $MEM_USR,%eax # User base address + addl 0xc(%esp,1),%eax # Change to user + leal 0x4(%eax),%esp # stack +ifdef(`PAGING',` + movl %cr0,%eax # Turn + andl $~0x80000000,%eax # off + movl %eax,%cr0 # paging + xorl %eax,%eax # Flush + movl %eax,%cr3 # TLB +') + popl %eax # Call + call *%eax # program +intx30.1: incb %ss:btx_hdr+0x7 # Flag reboot + jmp exit # Exit +# +# Dump structure [EBX] to [EDI], using format string [ESI]. +# +dump.0: stosb # Save char +dump: lodsb # Load char + testb %al,%al # End of string? + jz dump.10 # Yes + testb $0x80,%al # Control? + jz dump.0 # No + movb %al,%ch # Save control + movb $'=',%al # Append + stosb # '=' + lodsb # Get offset + pushl %esi # Save + movsbl %al,%esi # To + addl %ebx,%esi # pointer + testb $DMP_X16,%ch # Dump word? + jz dump.1 # No + lodsw # Get and + call hex16 # dump it +dump.1: testb $DMP_X32,%ch # Dump long? + jz dump.2 # No + lodsl # Get and + call hex32 # dump it +dump.2: testb $DMP_MEM,%ch # Dump memory? + jz dump.8 # No + pushl %ds # Save + testb $0x2,0x52(%ebx) # V86 mode? + jnz dump.3 # Yes + verr 0x4(%esi) # Readable selector? + jnz dump.3 # No + ldsl (%esi),%esi # Load pointer + jmp dump.4 # Join common code +dump.3: lodsl # Set offset + xchgl %eax,%edx # Save + lodsl # Get segment + shll $0x4,%eax # * 0x10 + addl %edx,%eax # + offset + xchgl %eax,%esi # Set pointer +dump.4: movb $0x10,%cl # Bytes to dump +dump.5: lodsb # Get byte and + call hex8 # dump it + decb %cl # Keep count + jz dump.7 # If done + movb $'-',%al # Separator + cmpb $0x8,%cl # Half way? + je dump.6 # Yes + movb $' ',%al # Use space +dump.6: stosb # Save separator + jmp dump.5 # Continue +dump.7: popl %ds # Restore +dump.8: popl %esi # Restore + movb $0xa,%al # Line feed + testb $DMP_EOL,%ch # End of line? + jnz dump.9 # Yes + movb $' ',%al # Use spaces + stosb # Save one +dump.9: jmp dump.0 # Continue +dump.10: stosb # Terminate string + ret # To caller +# +# Convert EAX, AX, or AL to hex, saving the result to [EDI]. +# +hex32: pushl %eax # Save + shrl $0x10,%eax # Do upper + call hex16 # 16 + popl %eax # Restore +hex16: call hex16.1 # Do upper 8 +hex16.1: xchgb %ah,%al # Save/restore +hex8: pushl %eax # Save + shrb $0x4,%al # Do upper + call hex8.1 # 4 + popl %eax # Restore +hex8.1: andb $0xf,%al # Get lower 4 + cmpb $0xa,%al # Convert + sbbb $0x69,%al # to hex + das # digit + orb $0x20,%al # To lower case + stosb # Save char + ret # (Recursive) +# +# Output zero-terminated string [ESI] to the console. +# +putstr.0: call putchr # Output char +putstr: lodsb # Load char + testb %al,%al # End of string? + jnz putstr.0 # No + ret # To caller +# +# Output character AL to the console. +# +putchr: pusha # Save + xorl %ecx,%ecx # Zero for loops + movb $SCR_MAT,%ah # Mode/attribute + movl $BDA_POS,%ebx # BDA pointer + movw (%ebx),%dx # Cursor position + movl $0xb8000,%edi # Regen buffer (color) + cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode? + jne putchr.1 # No + xorw %di,%di # Regen buffer (mono) +putchr.1: cmpb $0xa,%al # New line? + je putchr.2 # Yes + xchgl %eax,%ecx # Save char + movb $SCR_COL,%al # Columns per row + mulb %dh # * row position + addb %dl,%al # + column + adcb $0x0,%ah # position + shll %eax # * 2 + xchgl %eax,%ecx # Swap char, offset + movw %ax,(%edi,%ecx,1) # Write attr:char + incl %edx # Bump cursor + cmpb $SCR_COL,%dl # Beyond row? + jb putchr.3 # No +putchr.2: xorb %dl,%dl # Zero column + incb %dh # Bump row +putchr.3: cmpb $SCR_ROW,%dh # Beyond screen? + jb putchr.4 # No + leal 2*SCR_COL(%edi),%esi # New top line + movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move + rep # Scroll + movsl # screen + movb $' ',%al # Space + movb $SCR_COL,%cl # Columns to clear + rep # Clear + stosw # line + movb $SCR_ROW-1,%dh # Bottom line +putchr.4: movw %dx,(%ebx) # Update position + popa # Restore + ret # To caller + + .p2align 4 +# +# Global descriptor table. +# +gdt: .word 0x0,0x0,0x0,0x0 # Null entry + .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE + .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA + .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE + .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA + .word 0xffff,MEM_USR,0xfa00,0xcf# SEL_UCODE + .word 0xffff,MEM_USR,0xf200,0xcf# SEL_UDATA + .word _TSSLM,MEM_TSS,0x8900,0x0 # SEL_TSS +gdt.1: +# +# Pseudo-descriptors. +# +gdtdesc: .word gdt.1-gdt-1,gdt,0x0 # GDT +idtdesc: .word _IDTLM,MEM_IDT,0x0 # IDT +ivtdesc: .word 0x400-0x0-1,0x0,0x0 # IVT +# +# IDT construction control string. +# +idtctl: .byte 0x10, 0x8e # Int 0x0-0xf + .word 0x7dfb,intx00 # (exceptions) + .byte 0x10, 0x8e # Int 0x10 + .word 0x1, intx10 # (exception) + .byte 0x10, 0x8e # Int 0x20-0x2f + .word 0xffff,intx20 # (hardware) + .byte 0x1, 0xee # int 0x30 + .word 0x1, intx30 # (system call) + .byte 0x2, 0xee # Int 0x31-0x32 + .word 0x1, intx31 # (V86, null) + .byte 0x0 # End of string +# +# Dump format string. +# +dmpfmt: .byte '\n' # "\n" + .ascii "int" # "int=" + .byte 0x80|DMP_X32, 0x40 # "00000000 " + .ascii "err" # "err=" + .byte 0x80|DMP_X32, 0x44 # "00000000 " + .ascii "efl" # "efl=" + .byte 0x80|DMP_X32, 0x50 # "00000000 " + .ascii "eip" # "eip=" + .byte 0x80|DMP_X32|DMP_EOL,0x48 # "00000000\n" + .ascii "eax" # "eax=" + .byte 0x80|DMP_X32, 0x34 # "00000000 " + .ascii "ebx" # "ebx=" + .byte 0x80|DMP_X32, 0x28 # "00000000 " + .ascii "ecx" # "ecx=" + .byte 0x80|DMP_X32, 0x30 # "00000000 " + .ascii "edx" # "edx=" + .byte 0x80|DMP_X32|DMP_EOL,0x2c # "00000000\n" + .ascii "esi" # "esi=" + .byte 0x80|DMP_X32, 0x1c # "00000000 " + .ascii "edi" # "edi=" + .byte 0x80|DMP_X32, 0x18 # "00000000 " + .ascii "ebp" # "ebp=" + .byte 0x80|DMP_X32, 0x20 # "00000000 " + .ascii "esp" # "esp=" + .byte 0x80|DMP_X32|DMP_EOL,0x0 # "00000000\n" + .ascii "cs" # "cs=" + .byte 0x80|DMP_X16, 0x4c # "0000 " + .ascii "ds" # "ds=" + .byte 0x80|DMP_X16, 0xc # "0000 " + .ascii "es" # "es=" + .byte 0x80|DMP_X16, 0x8 # "0000 " + .ascii " " # " " + .ascii "fs" # "fs=" + .byte 0x80|DMP_X16, 0x10 # "0000 " + .ascii "gs" # "gs=" + .byte 0x80|DMP_X16, 0x14 # "0000 " + .ascii "ss" # "ss=" + .byte 0x80|DMP_X16|DMP_EOL,0x4 # "0000\n" + .ascii "cs:eip" # "cs:eip=" + .byte 0x80|DMP_MEM|DMP_EOL,0x48 # "00 00 ... 00 00\n" + .ascii "ss:esp" # "ss:esp=" + .byte 0x80|DMP_MEM|DMP_EOL,0x0 # "00 00 ... 00 00\n" + .asciz "BTX halted" # End +# +# End of BTX memory. +# + .p2align 4 +break: diff --git a/src/sys/boot/btx/btxldr/Makefile b/src/sys/boot/btx/btxldr/Makefile new file mode 100644 index 0000000..d421cd5 --- /dev/null +++ b/src/sys/boot/btx/btxldr/Makefile @@ -0,0 +1,28 @@ +# $FreeBSD: src/sys/boot/i386/btx/btxldr/Makefile,v 1.7.2.1 2000/04/15 03:09:41 ps Exp $ + +M4?= m4 +M4FLAGS+= -DLOADER_ADDRESS=${LOADER_ADDRESS} + +.if defined(BTXLDR_VERBOSE) +M4FLAGS+= -DBTXLDR_VERBOSE +.endif + +all: btxldr + +btxldr: btxldr.o +.if ${OBJFORMAT} == aout + ${LD} -nostdlib -N -s -T ${LOADER_ADDRESS} -o btxldr.out btxldr.o + dd if=btxldr.out of=${.TARGET} ibs=32 skip=1 +.else + ${LD} -N -e start -Ttext ${LOADER_ADDRESS} -o btxldr.out btxldr.o + objcopy -S -O binary btxldr.out ${.TARGET} +.endif + +btxldr.o: btxldr.s + (cd ${.CURDIR}; ${M4} ${M4FLAGS} btxldr.s ) | \ + ${AS} ${AFLAGS} -o ${.TARGET} + +CLEANFILES+= btxldr btxldr.out btxldr.o + +.include <${.CURDIR}/../../Makefile.inc> +.include diff --git a/src/sys/boot/btx/btxldr/btxldr.s b/src/sys/boot/btx/btxldr/btxldr.s new file mode 100644 index 0000000..3604c5d --- /dev/null +++ b/src/sys/boot/btx/btxldr/btxldr.s @@ -0,0 +1,396 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/btx/btxldr/btxldr.s,v 1.8.2.2 2000/07/06 23:04:29 obrien Exp $ + +# +# Prototype BTX loader program, written in a couple of hours. The +# real thing should probably be more flexible, and in C. +# + +# +# Memory locations. +# + .set MEM_STUB,0x600 # Real mode stub + .set MEM_ESP,0x1000 # New stack pointer + .set MEM_TBL,0x5000 # BTX page tables + .set MEM_ENTRY,0x9010 # BTX entry point + .set MEM_DATA,start+0x1000 # Data segment +# +# Segment selectors. +# + .set SEL_SCODE,0x8 # 4GB code + .set SEL_SDATA,0x10 # 4GB data + .set SEL_RCODE,0x18 # 64K code + .set SEL_RDATA,0x20 # 64K data +# +# Paging constants. +# + .set PAG_SIZ,0x1000 # Page size + .set PAG_ENT,0x4 # Page entry size +# +# Screen constants. +# + .set SCR_MAT,0x7 # Mode/attribute + .set SCR_COL,0x50 # Columns per row + .set SCR_ROW,0x19 # Rows per screen +# +# BIOS Data Area locations. +# + .set BDA_MEM,0x413 # Free memory + .set BDA_SCR,0x449 # Video mode + .set BDA_POS,0x450 # Cursor position +# +# Required by aout gas inadequacy. +# + .set SIZ_STUB,0x1a # Size of stub +# +# We expect to be loaded by boot2 at the origin defined in ./Makefile. +# + .globl start +# +# BTX program loader for ELF clients. +# +start: cld # String ops inc + movl $m_logo,%esi # Identify + call putstr # ourselves + movzwl BDA_MEM,%eax # Get base memory + shll $0xa,%eax # in bytes + movl %eax,%ebp # Base of user stack +ifdef(`BTXLDR_VERBOSE',` + movl $m_mem,%esi # Display + call hexout # amount of + call putstr # base memory +') + lgdt gdtdesc # Load new GDT +# +# Relocate caller's arguments. +# +ifdef('BTXLDR_VERBOSE',` + movl $m_esp,%esi # Display + movl %esp,%eax # caller + call hexout # stack + call putstr # pointer + movl $m_args,%esi # Format string + leal 0x4(%esp,1),%ebx # First argument + movl $0x6,%ecx # Count +start.1: movl (%ebx),%eax # Get argument and + addl $0x4,%ebx # bump pointer + call hexout # Display it + loop start.1 # Till done + call putstr # End message +') + movl $0x48,%ecx # Allocate space + subl %ecx,%ebp # for bootinfo + movl 0x18(%esp,1),%esi # Source: bootinfo + cmpl $0x0, %esi # If the bootinfo pointer + je start_null_bi # is null, don't copy it + movl %ebp,%edi # Destination + rep # Copy + movsb # it + movl %ebp,0x18(%esp,1) # Update pointer +ifdef(`BTXLDR_VERBOSE',` + movl $m_rel_bi,%esi # Display + movl %ebp,%eax # bootinfo + call hexout # relocation + call putstr # message +') +start_null_bi: movl $0x18,%ecx # Allocate space + subl %ecx,%ebp # for arguments + leal 0x4(%esp,1),%esi # Source + movl %ebp,%edi # Destination + rep # Copy + movsb # them +ifdef(`BTXLDR_VERBOSE',` + movl $m_rel_args,%esi # Display + movl %ebp,%eax # argument + call hexout # relocation + call putstr # message +') +# +# Set up BTX kernel. +# + movl $MEM_ESP,%esp # Set up new stack + movl $MEM_DATA,%ebx # Data segment + movl $m_vers,%esi # Display BTX + call putstr # version message + movb 0x5(%ebx),%al # Get major version + addb $'0',%al # Display + call putchr # it + movb $'.',%al # And a + call putchr # dot + movb 0x6(%ebx),%al # Get minor + xorb %ah,%ah # version + movb $0xa,%dl # Divide + divb %dl,%al # by 10 + addb $'0',%al # Display + call putchr # tens + movb %ah,%al # Get units + addb $'0',%al # Display + call putchr # units + call putstr # End message + movl %ebx,%esi # BTX image + movzwl 0x8(%ebx),%edi # Compute + orl $PAG_SIZ/PAG_ENT-1,%edi # the + incl %edi # BTX + shll $0x2,%edi # load + addl $MEM_TBL,%edi # address + pushl %edi # Save load address + movzwl 0xa(%ebx),%ecx # Image size +ifdef(`BTXLDR_VERBOSE',` + pushl %ecx # Save image size +') + rep # Relocate + movsb # BTX + movl %esi,%ebx # Keep place +ifdef(`BTXLDR_VERBOSE',` + movl $m_rel_btx,%esi # Restore + popl %eax # parameters + call hexout # and +') + popl %ebp # display +ifdef(`BTXLDR_VERBOSE',` + movl %ebp,%eax # the + call hexout # relocation + call putstr # message +') + addl $PAG_SIZ,%ebp # Display +ifdef(`BTXLDR_VERBOSE',` + movl $m_base,%esi # the + movl %ebp,%eax # user + call hexout # base + call putstr # address +') +# +# Set up ELF-format client program. +# + cmpl $0x464c457f,(%ebx) # ELF magic number? + je start.3 # Yes + movl $e_fmt,%esi # Display error + call putstr # message +start.2: jmp start.2 # Hang +start.3: +ifdef(`BTXLDR_VERBOSE',` + movl $m_elf,%esi # Display ELF + call putstr # message + movl $m_segs,%esi # Format string +') + movl $0x2,%edi # Segment count + movl 0x1c(%ebx),%edx # Get e_phoff + addl %ebx,%edx # To pointer + movzwl 0x2c(%ebx),%ecx # Get e_phnum +start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD? + jne start.6 # No +ifdef(`BTXLDR_VERBOSE',` + movl 0x4(%edx),%eax # Display + call hexout # p_offset + movl 0x8(%edx),%eax # Display + call hexout # p_vaddr + movl 0x10(%edx),%eax # Display + call hexout # p_filesz + movl 0x14(%edx),%eax # Display + call hexout # p_memsz + call putstr # End message +') + pushl %esi # Save + pushl %edi # working + pushl %ecx # registers + movl 0x4(%edx),%esi # Get p_offset + addl %ebx,%esi # as pointer + movl 0x8(%edx),%edi # Get p_vaddr + addl %ebp,%edi # as pointer + movl 0x10(%edx),%ecx # Get p_filesz + rep # Set up + movsb # segment + movl 0x14(%edx),%ecx # Any bytes + subl 0x10(%edx),%ecx # to zero? + jz start.5 # No + xorb %al,%al # Then + rep # zero + stosb # them +start.5: popl %ecx # Restore + popl %edi # working + popl %esi # registers + decl %edi # Segments to do + je start.7 # If none +start.6: addl $0x20,%edx # To next entry + loop start.4 # Till done +start.7: +ifdef(`BTXLDR_VERBOSE',` + movl $m_done,%esi # Display done + call putstr # message +') + movl $start.8,%esi # Real mode stub + movl $MEM_STUB,%edi # Destination + movl $start.9-start.8,%ecx # Size + rep # Relocate + movsb # it + ljmp $SEL_RCODE,$MEM_STUB # To 16-bit code + .code16 +start.8: xorw %ax,%ax # Data + movb $SEL_RDATA,%al # selector + movw %ax,%ss # Reload SS + movw %ax,%ds # Reset + movw %ax,%es # other + movw %ax,%fs # segment + movw %ax,%gs # limits + movl %cr0,%eax # Switch to + decw %ax # real + movl %eax,%cr0 # mode + ljmp $0,$MEM_ENTRY # Jump to BTX entry point +start.9: + .code32 +# +# Output message [ESI] followed by EAX in hex. +# +hexout: pushl %eax # Save + call putstr # Display message + popl %eax # Restore + pushl %esi # Save + pushl %edi # caller's + movl $buf,%edi # Buffer + pushl %edi # Save + call hex32 # To hex + xorb %al,%al # Terminate + stosb # string + popl %esi # Restore +hexout.1: lodsb # Get a char + cmpb $'0',%al # Leading zero? + je hexout.1 # Yes + testb %al,%al # End of string? + jne hexout.2 # No + decl %esi # Undo +hexout.2: decl %esi # Adjust for inc + call putstr # Display hex + popl %edi # Restore + popl %esi # caller's + ret # To caller +# +# Output zero-terminated string [ESI] to the console. +# +putstr.0: call putchr # Output char +putstr: lodsb # Load char + testb %al,%al # End of string? + jne putstr.0 # No + ret # To caller +# +# Output character AL to the console. +# +putchr: pusha # Save + xorl %ecx,%ecx # Zero for loops + movb $SCR_MAT,%ah # Mode/attribute + movl $BDA_POS,%ebx # BDA pointer + movw (%ebx),%dx # Cursor position + movl $0xb8000,%edi # Regen buffer (color) + cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode? + jne putchr.1 # No + xorw %di,%di # Regen buffer (mono) +putchr.1: cmpb $0xa,%al # New line? + je putchr.2 # Yes + xchgl %eax,%ecx # Save char + movb $SCR_COL,%al # Columns per row + mulb %dh # * row position + addb %dl,%al # + column + adcb $0x0,%ah # position + shll %eax # * 2 + xchgl %eax,%ecx # Swap char, offset + movw %ax,(%edi,%ecx,1) # Write attr:char + incl %edx # Bump cursor + cmpb $SCR_COL,%dl # Beyond row? + jb putchr.3 # No +putchr.2: xorb %dl,%dl # Zero column + incb %dh # Bump row +putchr.3: cmpb $SCR_ROW,%dh # Beyond screen? + jb putchr.4 # No + leal 2*SCR_COL(%edi),%esi # New top line + movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move + rep # Scroll + movsl # screen + movb $' ',%al # Space + movb $SCR_COL,%cl # Columns to clear + rep # Clear + stosw # line + movb $SCR_ROW-1,%dh # Bottom line +putchr.4: movw %dx,(%ebx) # Update position + popa # Restore + ret # To caller +# +# Convert EAX, AX, or AL to hex, saving the result to [EDI]. +# +hex32: pushl %eax # Save + shrl $0x10,%eax # Do upper + call hex16 # 16 + popl %eax # Restore +hex16: call hex16.1 # Do upper 8 +hex16.1: xchgb %ah,%al # Save/restore +hex8: pushl %eax # Save + shrb $0x4,%al # Do upper + call hex8.1 # 4 + popl %eax # Restore +hex8.1: andb $0xf,%al # Get lower 4 + cmpb $0xa,%al # Convert + sbbb $0x69,%al # to hex + das # digit + orb $0x20,%al # To lower case + stosb # Save char + ret # (Recursive) + + .data + .p2align 4 +# +# Global descriptor table. +# +gdt: .word 0x0,0x0,0x0,0x0 # Null entry + .word 0xffff,0x0,0x9a00,0xcf # SEL_SCODE + .word 0xffff,0x0,0x9200,0xcf # SEL_SDATA + .word 0xffff,0x0,0x9a00,0x0 # SEL_RCODE + .word 0xffff,0x0,0x9200,0x0 # SEL_RDATA +gdt.1: +gdtdesc: .word gdt.1-gdt-1 # Limit + .long gdt # Base +# +# Messages. +# +m_logo: .asciz " \nBTX loader 1.00 " +m_vers: .asciz "BTX version is \0\n" +e_fmt: .asciz "Error: Client format not supported\n" +ifdef(`BTXLDR_VERBOSE',` +m_mem: .asciz "Starting in protected mode (base mem=\0)\n" +m_esp: .asciz "Arguments passed (esp=\0):\n" +m_args: .asciz"\n" +m_rel_bi: .asciz "Relocated bootinfo (size=48) to \0\n" +m_rel_args: .asciz "Relocated arguments (size=18) to \0\n" +m_rel_btx: .asciz "Relocated kernel (size=\0) to \0\n" +m_base: .asciz "Client base address is \0\n" +m_elf: .asciz "Client format is ELF\n" +m_segs: .asciz "text segment: offset=" + .asciz " vaddr=" + .asciz " filesz=" + .asciz " memsz=\0\n" + .asciz "data segment: offset=" + .asciz " vaddr=" + .asciz " filesz=" + .asciz " memsz=\0\n" +m_done: .asciz "Loading complete\n" +') +# +# Uninitialized data area. +# +buf: # Scratch buffer diff --git a/src/sys/boot/btx/lib/Makefile b/src/sys/boot/btx/lib/Makefile new file mode 100644 index 0000000..b2e47b8 --- /dev/null +++ b/src/sys/boot/btx/lib/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD: src/sys/boot/i386/btx/lib/Makefile,v 1.3.2.1 2002/07/19 18:46:28 ru Exp $ + +OBJS= btxcsu.o btxsys.o btxv86.o +AFLAGS+= #-elf +LDFLAGS+= #-elf +CLEANFILES+= crt0.o ${OBJS} + +all: crt0.o + +crt0.o: ${OBJS} + ${LD} ${LDFLAGS} -i -o ${.TARGET} ${OBJS} + +.include + +.s.o: + ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC} diff --git a/src/sys/boot/btx/lib/btxcsu.s b/src/sys/boot/btx/lib/btxcsu.s new file mode 100644 index 0000000..119fda6 --- /dev/null +++ b/src/sys/boot/btx/lib/btxcsu.s @@ -0,0 +1,43 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/btx/lib/btxcsu.s,v 1.3 1999/08/28 00:40:07 peter Exp $ + +# +# BTX C startup code (ELF). +# + +# +# Globals. +# + .global _start +# +# Constants. +# + .set ARGADJ,0xfa0 # Argument adjustment +# +# Client entry point. +# +_start: movl %eax,__base # Set base address + movl %esp,%eax # Set + addl $ARGADJ,%eax # argument + movl %eax,__args # pointer + call main # Invoke client main() + call exit # Invoke client exit() +# +# Data. +# + .comm __base,4 # Client base address + .comm __args,4 # Client arguments diff --git a/src/sys/boot/btx/lib/btxsys.s b/src/sys/boot/btx/lib/btxsys.s new file mode 100644 index 0000000..6bca740 --- /dev/null +++ b/src/sys/boot/btx/lib/btxsys.s @@ -0,0 +1,40 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/btx/lib/btxsys.s,v 1.2 1999/08/28 00:40:07 peter Exp $ + +# +# BTX system calls. +# + +# +# Globals. +# + .global __exit + .global __exec +# +# Constants. +# + .set INT_SYS,0x30 # Interrupt number +# +# System call: exit +# +__exit: xorl %eax,%eax # BTX system + int $INT_SYS # call 0x0 +# +# System call: exec +# +__exec: movl $0x1,%eax # BTX system + int $INT_SYS # call 0x1 diff --git a/src/sys/boot/btx/lib/btxv86.h b/src/sys/boot/btx/lib/btxv86.h new file mode 100644 index 0000000..1ef0712 --- /dev/null +++ b/src/sys/boot/btx/lib/btxv86.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 1998 Robert Nordier + * All rights reserved. + * + * Redistribution and use in source and binary forms are freely + * permitted provided that the above copyright notice and this + * paragraph and the following disclaimer are duplicated in all + * such forms. + * + * This software is provided "AS IS" and without any express or + * implied warranties, including, without limitation, the implied + * warranties of merchantability and fitness for a particular + * purpose. + */ + +/* + * $FreeBSD: src/sys/boot/i386/btx/lib/btxv86.h,v 1.5 1999/08/28 00:40:08 peter Exp $ + */ + +#ifndef _BTXV86_H_ +#define _BTXV86_H_ + +#include + +#define V86_ADDR 0x10000 /* Segment:offset address */ +#define V86_CALLF 0x20000 /* Emulate far call */ +#define V86_FLAGS 0x40000 /* Return flags */ + +struct __v86 { + uint32_t ctl; /* Control flags */ + uint32_t addr; /* Interrupt number or address */ + uint32_t es; /* V86 ES register */ + uint32_t ds; /* V86 DS register */ + uint32_t fs; /* V86 FS register */ + uint32_t gs; /* V86 GS register */ + uint32_t eax; /* V86 EAX register */ + uint32_t ecx; /* V86 ECX register */ + uint32_t edx; /* V86 EDX register */ + uint32_t ebx; /* V86 EBX register */ + uint32_t efl; /* V86 eflags register */ + uint32_t ebp; /* V86 EBP register */ + uint32_t esi; /* V86 ESI register */ + uint32_t edi; /* V86 EDI register */ +}; + +extern struct __v86 __v86; /* V86 interface structure */ +void __v86int(void); + +#define v86 __v86 +#define v86int __v86int + +extern u_int32_t __base; +extern u_int32_t __args; + +#define PTOV(pa) ((caddr_t)(pa) - __base) +#define VTOP(va) ((vm_offset_t)(va) + __base) +#define VTOPSEG(va) (u_int16_t)(VTOP((caddr_t)va) >> 4) +#define VTOPOFF(va) (u_int16_t)(VTOP((caddr_t)va) & 0xf) + +void __exit(int) __attribute__((__noreturn__)); +void __exec(caddr_t, ...); + +#endif /* !_BTXV86_H_ */ diff --git a/src/sys/boot/btx/lib/btxv86.s b/src/sys/boot/btx/lib/btxv86.s new file mode 100644 index 0000000..6d6af19 --- /dev/null +++ b/src/sys/boot/btx/lib/btxv86.s @@ -0,0 +1,85 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/btx/lib/btxv86.s,v 1.3 1999/08/28 00:40:08 peter Exp $ + +# +# BTX V86 interface. +# + +# +# Globals. +# + .global __v86int +# +# Fields in V86 interface structure. +# + .set V86_CTL,0x0 # Control flags + .set V86_ADDR,0x4 # Int number/address + .set V86_ES,0x8 # V86 ES + .set V86_DS,0xc # V86 DS + .set V86_FS,0x10 # V86 FS + .set V86_GS,0x14 # V86 GS + .set V86_EAX,0x18 # V86 EAX + .set V86_ECX,0x1c # V86 ECX + .set V86_EDX,0x20 # V86 EDX + .set V86_EBX,0x24 # V86 EBX + .set V86_EFL,0x28 # V86 eflags + .set V86_EBP,0x2c # V86 EBP + .set V86_ESI,0x30 # V86 ESI + .set V86_EDI,0x34 # V86 EDI +# +# Other constants. +# + .set INT_V86,0x31 # Interrupt number + .set SIZ_V86,0x38 # Size of V86 structure +# +# V86 interface function. +# +__v86int: popl __v86ret # Save return address + pushl $__v86 # Push pointer + call __v86_swap # Load V86 registers + int $INT_V86 # To BTX + call __v86_swap # Load user registers + addl $0x4,%esp # Discard pointer + pushl __v86ret # Restore return address + ret # To user +# +# Swap V86 and user registers. +# +__v86_swap: xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP + xchgl %eax,V86_EAX(%ebp) # Swap EAX + xchgl %ecx,V86_ECX(%ebp) # Swap ECX + xchgl %edx,V86_EDX(%ebp) # Swap EDX + xchgl %ebx,V86_EBX(%ebp) # Swap EBX + pushl %eax # Save + pushf # Put eflags + popl %eax # in EAX + xchgl %eax,V86_EFL(%ebp) # Swap + pushl %eax # Put EAX + popf # in eflags + movl 0x8(%esp,1),%eax # Load EBP + xchgl %eax,V86_EBP(%ebp) # Swap + movl %eax,0x8(%esp,1) # Save EBP + popl %eax # Restore + xchgl %esi,V86_ESI(%ebp) # Swap ESI + xchgl %edi,V86_EDI(%ebp) # Swap EDI + xchgl %ebp,0x4(%esp,1) # Swap pointer, EBP + ret # To caller +# +# V86 interface structure. +# + .comm __v86,SIZ_V86 + .comm __v86ret,4 diff --git a/src/sys/boot/mbr/Makefile b/src/sys/boot/mbr/Makefile new file mode 100644 index 0000000..7b428cf --- /dev/null +++ b/src/sys/boot/mbr/Makefile @@ -0,0 +1,54 @@ +# $Id$ +# Application Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Compiler Flags +CFLAGS = -I../../include -fno-builtin + +#Linker +LD = ld + +#Binary File Name +BINARY = mbr + +#Delete Program +REMOVE = rm -f + +#Objects +OBJS = mbr.o +ORG = 0x600 + +#Startup File +#STARTUP = ../../../lib/ubix/startup.o + +# Link The Binary +$(BINARY) : $(OBJS) +# $(CC) -O -pipe -ffreestanding -mpreferred-stack-boundary=2 -N -e start -Ttext $(ORG) -nostdlib -o $(BINARY).out $(OBJS) + $(CC) -O -pipe -ffreestanding -mpreferred-stack-boundary=2 -N -e start -Wl,-Ttext,$(ORG) -nostdlib -o $(BINARY).out $(OBJS) + objcopy -S -O binary $(BINARY).out $(BINARY) + +# Compile the source files +.cc.o: + $(CXX) -Wall -fomit-frame-pointer -O $(CFLAGS) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -fomit-frame-pointer -O $(CFLAGS) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) -c -o $@ $< + +.s.o: + as -defsym FLAGS=0xf --defsym TICKS=0xb6 --defsym COMSPEED=0xE3 -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O $(CFLAGS) -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean Up The junk +clean: + $(REMOVE) $(OBJS) $(BINARY) $(BINARY).out diff --git a/src/sys/boot/mbr/mbr.s b/src/sys/boot/mbr/mbr.s new file mode 100644 index 0000000..f9c1448 --- /dev/null +++ b/src/sys/boot/mbr/mbr.s @@ -0,0 +1,419 @@ +# +# Copyright (c) 1998 Robert Nordier +# All rights reserved. +# +# Redistribution and use in source and binary forms are freely +# permitted provided that the above copyright notice and this +# paragraph and the following disclaimer are duplicated in all +# such forms. +# +# This software is provided "AS IS" and without any express or +# implied warranties, including, without limitation, the implied +# warranties of merchantability and fitness for a particular +# purpose. +# + +# $FreeBSD: src/sys/boot/i386/boot0/boot0.s,v 1.29 2003/12/11 20:40:12 jhb Exp $ + +# A 512-byte boot manager. + + .set NHRDRV,0x475 # Number of hard drives + .set ORIGIN,0x600 # Execution address + .set FAKE,0x800 # Partition entry + .set LOAD,0x7c00 # Load address + + .set PRT_OFF,0x1be # Partition table + + .set TBL0SZ,0x3 # Table 0 size + .set TBL1SZ,0xb # Table 1 size + + .set MAGIC,0xaa55 # Magic: bootable + .set B0MAGIC,0xbb66 # Identification + + .set KEY_ENTER,0x1c # Enter key scan code + .set KEY_F1,0x3b # F1 key scan code + .set KEY_1,0x02 # #1 key scan code + +# +# Addresses in the sector of embedded data values. +# Accessed with negative offsets from the end of the relocated sector (%ebp). +# + .set _NXTDRV,-0x48 # Next drive + .set _OPT,-0x47 # Default option + .set _SETDRV,-0x46 # Drive to force + .set _FLAGS,-0x45 # Flags + .set _TICKS,-0x44 # Timeout ticks + .set _FAKE,0x0 # Fake partition entry + .set _MNUOPT,0xc # Menu options + + .globl start # Entry point + .code16 # This runs in real mode + +# +# Initialise segments and registers to known values. +# segments start at 0. +# The stack is immediately below the address we were loaded to. +# +start: cld # String ops inc + xorw %ax,%ax # Zero + movw %ax,%es # Address + movw %ax,%ds # data + movw %ax,%ss # Set up + movw $LOAD,%sp # stack + +# +# Copy this code to the address it was linked for +# + movw %sp,%si # Source + movw $start,%di # Destination + movw $0x100,%cx # Word count + rep # Relocate + movsw # code +# +# Set address for variable space beyond code, and clear it. +# Notice that this is also used to point to the values embedded in the block, +# by using negative offsets. +# + movw %di,%bp # Address variables + movb $0x8,%cl # Words to clear + rep # Zero + stosw # them +# +# Relocate to the new copy of the code. +# + incb -0xe(%di) # Sector number + jmp main-LOAD+ORIGIN # To relocated code +# +# Check what flags were loaded with us, specifically, Use a predefined Drive. +# If what the bios gives us is bad, use the '0' in the block instead, as well. +# +main: testb $0x20,_FLAGS(%bp) # Set number drive? + jnz main.1 # Yes + testb %dl,%dl # Drive number valid? + js main.2 # Possibly (0x80 set) +main.1: movb _SETDRV(%bp),%dl # Drive number to use +# +# Whatever we decided to use, now store it into the fake +# partition entry that lives in the data space above us. +# +main.2: movb %dl,_FAKE(%bp) # Save drive number + callw putn # To new line + pushw %dx # Save drive number +# +# Start out with a pointer to the 4th byte of the first table entry +# so that after 4 iterations it's beyond the end of the sector. +# and beyond a 256 byte boundary and has overflowed 8 bits (see next comment). +# (remember that the table starts 2 bytes earlier than you would expect +# as the bootable flag is after it in the block) +# + movw $(partbl+0x4),%bx # Partition table (+4) + xorw %dx,%dx # Item number +# +# Loop around on the partition table, printing values until we +# pass a 256 byte boundary. The end of loop test is at main.5. +# +main.3: movb %ch,-0x4(%bx) # Zero active flag (ch == 0) + btw %dx,_FLAGS(%bp) # Entry enabled? + jnc main.5 # No +# +# If any of the entries in the table are +# the same as the 'type' in the slice table entry, +# then this is an empty or non bootable partition. Skip it. +# + movb (%bx),%al # Load type + movw $tables,%di # Lookup tables + movb $TBL0SZ,%cl # Number of entries + repne # Exclude + scasb # partition? + je main.5 # Yes +# +# Now scan the table of known types +# + movb $TBL1SZ,%cl # Number of entries + repne # Known + scasb # type? + jne main.4 # No +# +# If it matches get the matching element in the +# next array. if it doesn't, we are already +# pointing at its first element which points to a "?". +# + addw $TBL1SZ,%di # Adjust +main.4: movb (%di),%cl # Partition + addw %cx,%di # description + callw putx # Display it +main.5: incw %dx # Next item + addb $0x10,%bl # Next entry + jnc main.3 # Till done +# +# Passed a 256 byte boundary.. +# table is finished. +# Add one to the drive number and check it is valid, +# + popw %ax # Drive number + subb $0x80-0x1,%al # Does next + cmpb NHRDRV,%al # drive exist? (from BIOS?) + jb main.6 # Yes +# If not then if there is only one drive, +# Don't display drive as an option. +# + decw %ax # Already drive 0? + jz main.7 # Yes +# If it was illegal or we cycled through them, +# then go back to drive 0. +# + xorb %al,%al # Drive 0 +# +# Whatever drive we selected, make it an ascii digit and save it back +# to the "next drive" location in the loaded block in case we +# want to save it for next time. +# This also is part of the printed drive string so add 0x80 to indicate +# end of string. +# +main.6: addb $'0'|0x80,%al # Save next + movb %al,_NXTDRV(%bp) # drive number + movw $drive,%di # Display + callw putx # item +# +# Now that we've printed the drive (if we needed to), display a prompt. +# Get ready for the input by noting the time. +# +main.7: movw $prompt,%si # Display + callw putstr # prompt + movb _OPT(%bp),%dl # Display + decw %si # default + callw putkey # key + xorb %ah,%ah # BIOS: Get + int $0x1a # system time + movw %dx,%di # Ticks when + addw _TICKS(%bp),%di # timeout +# +# Busy loop, looking for keystrokes but +# keeping one eye on the time. +# +main.8: movb $0x1,%ah # BIOS: Check + int $0x16 # for keypress + jnz main.11 # Have one + xorb %ah,%ah # BIOS: Get + int $0x1a # system time + cmpw %di,%dx # Timeout? + jb main.8 # No +# +# If timed out or defaulting, come here. +# +main.9: movb _OPT(%bp),%al # Load default + jmp main.12 # Join common code +# +# User's last try was bad, beep in displeasure. +# Since nothing was printed, just continue on as if the user +# hadn't done anything. This gives the effect of the user getting a beep +# for all bad keystrokes but no action until either the timeout +# occurs or the user hits a good key. +# +main.10: movb $0x7,%al # Signal + callw putchr # error +# +# Get the keystroke. +# +main.11: xorb %ah,%ah # BIOS: Get + int $0x16 # keypress + movb %ah,%al # Scan code +# +# If it's CR act as if timed out. +# + cmpb $KEY_ENTER,%al # Enter pressed? + je main.9 # Yes +# +# Otherwise check if legal +# If not ask again. +# + subb $KEY_F1,%al # Less F1 scan code + cmpb $0x4,%al # F1..F5? + jna main.12 # Yes + subb $(KEY_1 - KEY_F1),%al # Less #1 scan code + cmpb $0x4,%al # #1..#5? + ja main.10 # No +# +# We have a selection. +# but if it's a bad selection go back to complain. +# The bits in MNUOPT were set when the options were printed. +# Anything not printed is not an option. +# +main.12: cbtw # Option + btw %ax,_MNUOPT(%bp) # enabled? + jnc main.10 # No +# +# Save the info in the original tables +# for rewriting to the disk. +# + movb %al,_OPT(%bp) # Save option + movw $FAKE,%si # Partition for write + movb (%si),%dl # Drive number + movw %si,%bx # Partition for read + cmpb $0x4,%al # F5/#5 pressed? + pushf # Save + je main.13 # Yes + shlb $0x4,%al # Point to + addw $partbl,%ax # selected + xchgw %bx,%ax # partition + movb $0x80,(%bx) # Flag active +# +# If not asked to do a write-back (flags 0x40) don't do one. +# +main.13: pushw %bx # Save + testb $0x40,_FLAGS(%bp) # No updates? + jnz main.14 # Yes + movw $start,%bx # Data to write + movb $0x3,%ah # Write sector + callw intx13 # to disk +main.14: popw %si # Restore + popf # Restore +# +# If going to next drive, replace drive with selected one. +# Remember to un-ascii it. Hey 0x80 is already set, cool! +# + jne main.15 # If not F5/#5 + movb _NXTDRV(%bp),%dl # Next drive + subb $'0',%dl # number +# +# load selected bootsector to the LOAD location in RAM. +# If it fails to read or isn't marked bootable, treat it +# as a bad selection. +# XXX what does %si carry? +# +main.15: movw $LOAD,%bx # Address for read + movb $0x2,%ah # Read sector + callw intx13 # from disk + jc main.10 # If error + cmpw $MAGIC,0x1fe(%bx) # Bootable? + jne main.10 # No + pushw %si # Save + movw $crlf,%si # Leave some + callw puts # space + popw %si # Restore + jmp *%bx # Invoke bootstrap +# +# Display routines +# + +putkey: movb $'F',%al # Display + callw putchr # 'F' + movb $'1',%al # Prepare + addb %dl,%al # digit + jmp putstr.1 # Display the rest + +# +# Display the option and note that it is a valid option. +# That last point is a bit tricky.. +# +putx: btsw %dx,_MNUOPT(%bp) # Enable menu option + movw $item,%si # Display + callw putkey # key + movw %di,%si # Display the rest + +puts: callw putstr # Display string + +putn: movw $crlf,%si # To next line + +putstr: lodsb # Get byte + testb $0x80,%al # End of string? + jnz putstr.2 # Yes +putstr.1: callw putchr # Display char + jmp putstr # Continue +putstr.2: andb $~0x80,%al # Clear MSB + +putchr: pushw %bx # Save + movw $0x7,%bx # Page:attribute + movb $0xe,%ah # BIOS: Display + int $0x10 # character + popw %bx # Restore + retw # To caller + +# One-sector disk I/O routine + +intx13: movb 0x1(%si),%dh # Load head + movw 0x2(%si),%cx # Load cylinder:sector + movb $0x1,%al # Sector count + pushw %si # Save + movw %sp,%di # Save + testb $0x80,_FLAGS(%bp) # Use packet interface? + jz intx13.1 # No + pushl $0x0 # Set the + pushl 0x8(%si) # LBA address + pushw %es # Set the transfer + pushw %bx # buffer address + push $0x1 # Block count + push $0x10 # Packet size + movw %sp,%si # Packet pointer + decw %ax # Verify off + orb $0x40,%ah # Use disk packet +intx13.1: int $0x13 # BIOS: Disk I/O + movw %di,%sp # Restore + popw %si # Restore + retw # To caller + +# Menu strings + +item: .ascii " "; .byte ' '|0x80 +prompt: .ascii "\nDefault:"; .byte ' '|0x80 +crlf: .ascii "\r"; .byte '\n'|0x80 + +# Partition type tables + +tables: +# +# These entries identify invalid or NON BOOT types and partitions. +# + .byte 0x0, 0x5, 0xf +# +# These values indicate bootable types we know the names of +# + .byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0xad + .byte 0x9f, 0xa5, 0xa6, 0xa9 +# +# These are offsets that match the known names above and point to the strings +# that will be printed. +# + .byte os_misc-. # Unknown + .byte os_dos-. # DOS + .byte os_dos-. # DOS + .byte os_dos-. # DOS + .byte os_dos-. # Windows + .byte os_dos-. # Windows + .byte os_dos-. # Windows + .byte os_ubixos-. # Linux + .byte os_bsd-. # BSD/OS + .byte os_freebsd-. # FreeBSD + .byte os_bsd-. # OpenBSD + .byte os_bsd-. # NetBSD +# +# And here are the strings themselves. 0x80 or'd into a byte indicates +# the end of the string. (not so great for Russians but...) +# +os_misc: .ascii "?"; .byte '?'|0x80 +os_dos: .ascii "DO"; .byte 'S'|0x80 +os_ubixos: .ascii "UbixO"; .byte 'S'|0x80 +os_freebsd: .ascii "Free" +os_bsd: .ascii "BS"; .byte 'D'|0x80 + + .org PRT_OFF-0xe,0x90 + + .word B0MAGIC # Magic number + +# +# These values are sometimes changed before writing back to the drive +# Be especially careful that nxtdrv: must come after drive:, as it +# is part of the same string. +# +drive: .ascii "Drive " +nxtdrv: .byte 0x0 # Next drive number +opt: .byte 0x0 # Option +setdrv: .byte 0x80 # Drive to force +flags: .byte FLAGS # Flags +ticks: .word TICKS # Delay + +# +# here is the 64 byte partition table that fdisk would fiddle with. +# +partbl: .fill 0x40,0x1,0x0 # Partition table + .word MAGIC # Magic number diff --git a/src/sys/compile/Makefile b/src/sys/compile/Makefile new file mode 100644 index 0000000..56da09e --- /dev/null +++ b/src/sys/compile/Makefile @@ -0,0 +1,38 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Objects +OBJS = null.o + +#Kernel Parts +KPARTS = ../init/*.o ../sys/*.o ../vmm/*.o ../lib/*.o ../kernel/*.o ../isa/*.o ../vfs/*.o ../ubixfs/*.o ../pci/*.o ../sde/*.o ../devfs/*.o ../net/core/*.o ../net/net/*.o ../net/api/*.o ../net/netif/*.o ../mpi/*.o +#../graphics/*.o ../ld/*.o -Ttext 0x30000 -Tdata 0x34000 + +# Link the kernel statically with fixed text+data address @1M +$(KERNEL) : $(OBJS) + $(LD) -nostdlib -nostdinc -o $@ $(OBJS) $(KPARTS) -Ttext 0x30000 + /usr/bin/strip $@ + +# Compile the source files +.cc.o: + $(CXX) -Wall -O ${CFLAGS} $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) -Wall -O ${CFLAGS} -O $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) -Wall -O $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(KERNEL) null.c diff --git a/src/sys/devfs/Makefile b/src/sys/devfs/Makefile new file mode 100644 index 0000000..d96b505 --- /dev/null +++ b/src/sys/devfs/Makefile @@ -0,0 +1,33 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Linker +LINKER = ld + +# Remove +REMOVE = rm -fr + +# Objects +OBJS = devfs.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/devfs/devfs.c b/src/sys/devfs/devfs.c new file mode 100644 index 0000000..2d6ead3 --- /dev/null +++ b/src/sys/devfs/devfs.c @@ -0,0 +1,228 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.9 2004/05/26 11:55:25 reddawg + devfs: Added spin locks to fix some possible reentrant issues + + Revision 1.8 2004/05/19 15:31:27 reddawg + Fixed up the rest of the references + + Revision 1.7 2004/05/19 04:07:42 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.6 2004/04/28 21:10:40 reddawg + Lots Of changes to make it work with existing os + + Revision 1.5 2004/04/28 03:05:35 reddawg + Cleaned up some debug'n code + + Revision 1.4 2004/04/28 02:37:34 reddawg + More updates for using the new driver subsystem + + Revision 1.3 2004/04/28 02:22:54 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.2 2004/04/26 22:22:33 reddawg + DevFS now uses correct size of device + + Revision 1.1.1.1 2004/04/15 12:06:54 reddawg + UbixOS v1.0 + + Revision 1.3 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static spinLock_t devfsSpinLock = SPIN_LOCK_INITIALIZER; + + +int devFSEnable() { + //Add DevFS i will + if (vfsRegisterFS(1,devFSInit,devFSRead,devFSWrite,devFSOpen,0x0,0x0,0x0,0x0) != 0x0) { + //sysErr(systemErr,"Unable To Enable DevFS"); + return(0x1); + } + //Return + mount(0x0,0x0,0x0,0x1,"devfs","rw"); // Mount Device File System + return(0x0); + } + +void devFSInit(struct mountPoints *mp) { + struct devFsInfo *fsInfo = 0x0; + mp->fsInfo = (struct devFsInfo *)kmalloc(sizeof(struct devFsInfo)); + + fsInfo = mp->fsInfo; + fsInfo->deviceList = 0x0; + + kprintf("DevFS Initialized\n"); + //Return + return; + } + +int devFSOpen(char *file,fileDescriptor *fd) { + struct devFsInfo *fsInfo = fd->mp->fsInfo; + struct devFsDevices *tmpDev = 0x0; + struct deviceNode *device = 0x0; + + spinLock(&devfsSpinLock); + + for (tmpDev = fsInfo->deviceList;tmpDev != 0x0;tmpDev = tmpDev->next) { + if (kstrcmp(tmpDev->devName,file) == 0x0) { + switch ((fd->mode & 0x3)) { + case 0: + case 1: + device = deviceFind(tmpDev->devMajor,tmpDev->devMinor); + (void *)fd->start = tmpDev; + (void *)fd->size = device->size; + break; + default: + kprintf("Invalid File Mode\n"); + spinUnlock(&devfsSpinLock); + return(-1); + break; + } + spinUnlock(&devfsSpinLock); + return(0x1); + } + } + spinUnlock(&devfsSpinLock); + return(0x0); + } + +/************************************************************************ + +Function: int readDevFS(fileDescriptor *fd,char *data,long offset,long size) +Description: Read File Into Data +Notes: + +************************************************************************/ +int devFSRead(fileDescriptor *fd,char *data,long offset,long size) { + int i = 0x0,x = 0x0; + uInt32 sectors = 0x0; + uInt16 diff = 0x0; + struct deviceNode *device = 0x0; + struct devFsDevices *tmpDev = (void *)fd->start; + + device = deviceFind(tmpDev->devMajor,tmpDev->devMinor); + + + sectors = ((size+511)/512); + diff = (offset - ((offset/512)*512)); + + for (i=0x0;idevInfo->read(device->devInfo->info,fd->buffer,i + (offset/512),1); + for (x=0x0;x<(size - (i*512));x++) { + if (diff > 0) { + data[x] = fd->buffer[x + diff]; + } + else { + data[x] = fd->buffer[x]; + } + } + diff = 0x0; + data += 512; + } + + return(size); + } + +/************************************************************************ + +Function: int writeDevFS(fileDescriptor *fd,char *data,long offset,long size) +Description: Write Data Into File +Notes: + +************************************************************************/ +int devFSWrite(fileDescriptor *fd,char *data,long offset,long size) { + int i = 0x0,x = 0x0; + struct deviceNode *device = 0x0; + struct devFsDevices *tmpDev = (void *)fd->start; + + device = deviceFind(tmpDev->devMajor,tmpDev->devMinor); + for (i=0x0;i<((size+511)/512);i++) { + device->devInfo->read(device->devInfo->info,fd->buffer,i + (offset/512),1); + for (x=0x0;((x < 512) && ((x + (i * 512)) < size));x++) { + fd->buffer[x] = data[x]; + } + device->devInfo->write(device->devInfo->info,fd->buffer,i + (offset/512),1); + data += 512; + } + return(size); + } + + +int devFsMkNod(char *name,uInt8 type,uInt16 major,uInt16 minor) { + struct mountPoints *mp = 0x0; + struct devFsInfo *fsInfo = 0x0; + struct devFsDevices *tmpDev = 0x0; + + spinLock(&devfsSpinLock); + + mp = findMount("devfs"); + + if (mp == 0x0) { + kprintf("Error: Can't Find Mount Point\n"); + spinUnlock(&devfsSpinLock); + return(-1); + } + + fsInfo = mp->fsInfo; + + tmpDev = (struct devFsDevices *)kmalloc(sizeof(struct devFsDevices)); + + tmpDev->devType = type; + tmpDev->devMajor = major; + tmpDev->devMinor = minor; + sprintf(tmpDev->devName,name); + + tmpDev->next = fsInfo->deviceList; + tmpDev->prev = 0x0; + if (fsInfo->deviceList != 0x0) { + fsInfo->deviceList->prev = tmpDev; + } + + fsInfo->deviceList = tmpDev; + + spinUnlock(&devfsSpinLock); + return(0x0); + } + diff --git a/src/sys/device/devices.c b/src/sys/device/devices.c new file mode 100644 index 0000000..ee2f120 --- /dev/null +++ b/src/sys/device/devices.c @@ -0,0 +1,44 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1 2004/05/21 00:10:00 ionix + + : + + Revision 1.2 2004/04/27 20:49:22 reddawg + Update Sample Driver + + Revision 1.1 2004/04/27 12:04:24 reddawg + Sample driver for isa interface + + + + $Id$ +*/ + +#include "devices.h" +static struct devInfo devHead; + diff --git a/src/sys/device/devices.h b/src/sys/device/devices.h new file mode 100644 index 0000000..63af7df --- /dev/null +++ b/src/sys/device/devices.h @@ -0,0 +1,60 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/05/21 00:11:57 ionix + + C + Added lock feature + + Revision 1.1 2004/05/21 00:10:00 ionix + + : + + Revision 1.2 2004/04/27 20:49:22 reddawg + Update Sample Driver + + Revision 1.1 2004/04/27 12:04:24 reddawg + Sample driver for isa interface + + + + $Id$ + +*****************************************************************************************/ + + +struct devInfo { + int irq; + int ioAddr; + int dma; + int udma; + bool locked; + int lockedpid; + }; + +void devRegister; + + diff --git a/src/sys/include/devfs/devfs.h b/src/sys/include/devfs/devfs.h new file mode 100644 index 0000000..ca3c190 --- /dev/null +++ b/src/sys/include/devfs/devfs.h @@ -0,0 +1,65 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DEVFS_H +#define _DEVFS_H + +#include +#include + +struct devFsDevices { + struct devFsDevices *next; + struct devFsDevices *prev; + uInt8 devType; + uInt16 devMajor; + uInt16 devMinor; + char devName[32]; + }; + +struct devFsInfo { + struct devFsDevices *deviceList; + }; + +int devFSOpen(char *file,fileDescriptor *fd); +void devFSInit(struct mountPoints *mp); +int devFSEnable(); +int devFSRead(fileDescriptor *fd,char *data,long offset,long size); +int devFSWrite(fileDescriptor *fd,char *data,long offset,long size); +int devFsMkNod(char *name,uInt8 type,uInt16 major,uInt16 minor); + +#endif + +/*** + $Log$ + Revision 1.3 2004/05/21 14:54:41 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/isa/8259.h b/src/sys/include/isa/8259.h new file mode 100644 index 0000000..869899a --- /dev/null +++ b/src/sys/include/isa/8259.h @@ -0,0 +1,60 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _8259_H +#define _8259_H + +#include + +#define mPic 0x20 // I/O for master PIC +#define mImr 0x21 // I/O for master IMR +#define sPic 0xA0 // I/O for slave PIC +#define sImr 0xA1 // I/O for slace IMR +#define eoi 0x20 // EOI command +#define icw1 0x11 // Cascade, Edge triggered +#define icw4 0x01 // 8088 mode +#define mVec 0x68 // Vector for master +#define sVec 0x70 // Vector for slave +#define ocw3Irr 0x0A // Read IRR +#define ocw3Isr 0x0B // Read ISR + +int init8259(); +void irqEnable(uInt16 irqNo); +void irqDisable(uInt16 irqNo); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 14:57:16 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/isa/atkbd.h b/src/sys/include/isa/atkbd.h new file mode 100644 index 0000000..fab0b7f --- /dev/null +++ b/src/sys/include/isa/atkbd.h @@ -0,0 +1,54 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KEYBOARD_H +#define _KEYBOARD_H + +#define shiftKey 1 +#define controlKey 2 +#define altKey 4 +#define ledNumlock 2 +#define ledScrolllock 1 +#define ledCapslock 4 + +int keyboardInit(); +void keyboardISR(); +void keyboardHandler(); +void setLED(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 14:57:16 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/isa/fdc.h b/src/sys/include/isa/fdc.h new file mode 100644 index 0000000..01bde12 --- /dev/null +++ b/src/sys/include/isa/fdc.h @@ -0,0 +1,93 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _FDC_H +#define _FDC_H + +#include + +typedef struct DrvGeom { + Int8 heads; + Int8 tracks; + Int8 spt; +} drvGeom; + + +#define fdcMsr (0x3f4) +#define fdcData (0x3f5) +#define fdcDir (0x3f7) +#define fdcCcr (0x3f7) +#define fdcDor (0x3f2) +#define fdcDrs (0x3f4) + +#define cmdWrite (0xc5) +#define cmdRead (0xe6) +#define cmdSeek (0x0f) +#define cmdSensei (0x08) +#define cmdRecal (0x07) +#define cmdSpecify (0x03) + +#define dg144Heads 2 /* heads per drive (1.44M) */ +#define dg144Tracks 80 +#define dg144Spt 18 +#define dg144Gap3rw 0x1b +#define dg168Gap3rw 0x1c + + + +void fdcInit(); +void floppyIsr(); +void floppyIsrhndlr(); +void sendByte(int Int8); +int getByte(); +bool fdcRw(int block,Int8 *blockBuffer,bool read,unsigned long numSectors); +void block2Hts(int block,int *head,int *track,int *sector); +void motorOn(void); +void motorOff(void); +bool seek(int track); +bool waitFdc(bool sensei); +int getByte(); +void sendByte(int Int8); +void recalibrate(void); +void reset(void); +bool writeBlock(int block,Int8 *blockBuffer, unsigned long numSectors); +bool readBlock(int block,Int8 *blockBuffer, unsigned long numSectors); +void fdcWrite(void *info,void *,uInt32 startSector,uInt32 sectorCount); +void fdcRead(void *info,void *,uInt32 startSector,uInt32 sectorCount); + +#endif + +/*** + $Log$ + Revision 1.4 2004/05/21 14:57:16 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/isa/mouse.h b/src/sys/include/isa/mouse.h new file mode 100644 index 0000000..fcaf3fd --- /dev/null +++ b/src/sys/include/isa/mouse.h @@ -0,0 +1,45 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MOUE_H +#define _MOUSE_H + +int mouseInit(); +void mouseISR(); +void mouseHandler(); + +#endif + +/*** + $Log$ + Revision 1.1 2004/06/04 10:20:53 reddawg + mouse drive: fixed a few bugs works a bit better now + + END + ***/ diff --git a/src/sys/include/isa/ne2k.h b/src/sys/include/isa/ne2k.h new file mode 100644 index 0000000..8d059e6 --- /dev/null +++ b/src/sys/include/isa/ne2k.h @@ -0,0 +1,184 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _NE2K_H +#define _NE2K_H + +#include +#include + +#define ether_addr ether_addr_t +typedef struct dp_rcvhdr +{ + uInt8 dr_status; /* Copy of rsr */ + uInt8 dr_next; /* Pointer to next packet */ + uInt8 dr_rbcl; /* Receive Byte Count Low */ + uInt8 dr_rbch; /* Receive Byte Count High */ +} dp_rcvhdr_t; + +typedef union etheraddr { + unsigned char bytes[6]; /* byteorder safe initialization */ + unsigned short shorts[3]; /* force 2-byte alignment */ +} ether_addr; + + +struct nicBuffer { + struct nicBuffer *next; + int length; + char *buffer; + }; + +#define RSR_FO 0x08 +#define RSR_PRX 0x01 +#define DEF_ENABLED 0x200 + +#define OK 0 + + +#define startPage 0x4C +#define stopPage 0x80 + + +#define NE_CMD 0x00 +#define NE_PSTART 0x01 +#define NE_PSTOP 0x02 +#define NE_BNRY 0x03 +#define NE_TPSR 0x04 +#define NE_ISR 0x07 +#define NE_CURRENT 0x07 +#define NE_RBCR0 0x0A +#define NE_RBCR1 0x0B +#define NE_RCR 0x0C +#define NE_TCR 0x0D +#define NE_DCR 0x0E +#define NE_IMR 0x0F + + +#define NE_DCR_WTS 0x01 +#define NE_DCR_LS 0x08 +#define NE_DCR_AR 0x10 +#define NE_DCR_FT1 0x40 +#define NE_DCR_FT0 0x20 + + + +#define E8390_STOP 0x01 +#define E8390_NODMA 0x20 +#define E8390_PAGE0 0x00 +#define E8390_PAGE1 0x40 +#define E8390_CMD 0x00 +#define E8390_START 0x02 +#define E8390_RREAD 0x08 +#define E8390_RWRITE 0x10 +#define E8390_RXOFF 0x20 +#define E8390_TXOFF 0x00 +#define E8390_RXCONFIG 0x04 +#define E8390_TXCONFIG 0x00 + +#define EN0_COUNTER0 0x0d +#define EN0_DCFG 0x0e +#define EN0_RCNTLO 0x0a +#define EN0_RCNTHI 0x0b +#define EN0_ISR 0x07 +#define EN0_IMR 0x0f +#define EN0_RSARLO 0x08 +#define EN0_RSARHI 0x09 +#define EN0_TPSR 0x04 +#define EN0_RXCR 0x0c +#define EN0_TXCR 0x0D +#define EN0_STARTPG 0x01 +#define EN0_STOPPG 0x02 +#define EN0_BOUNDARY 0x03 + +#define EN1_PHYS 0x01 +#define EN1_CURPAG 0x07 +#define EN1_MULT 0x08 + +#define NE1SM_START_PG 0x20 +#define NE1SM_STOP_PG 0x40 +#define NESM_START_PG 0x40 +#define NESM_STOP_PG 0x80 + +#define ENISR_ALL 0x3f + +#define ENDCFG_WTS 0x01 + +#define NE_DATAPORT 0x10 + +#define TX_2X_PAGES 12 +#define TX_1X_PAGES 6 +#define TX_PAGES (dev->priv->pingPong ? TX_2X_PAGES : TX_1X_PAGES) + + +#define DP_CURR 0x7 /* Current Page Register */ +#define DP_MAR0 0x8 /* Multicast Address Register 0 */ +#define DP_MAR1 0x9 /* Multicast Address Register 1 */ +#define DP_MAR2 0xA /* Multicast Address Register 2 */ +#define DP_MAR3 0xB /* Multicast Address Register 3 */ +#define DP_MAR4 0xC /* Multicast Address Register 4 */ +#define DP_MAR5 0xD /* Multicast Address Register 5 */ +#define DP_MAR6 0xE /* Multicast Address Register 6 */ +#define DP_MAR7 0xF /* Multicast Address Register 7 */ + +#define DP_CNTR0 0xD /* Tally Counter 0 */ +#define DP_CNTR1 0xE /* Tally Counter 1 */ +#define DP_CNTR2 0xF /* Tally Counter 2 */ + + +#define DP_PAGESIZE 256 + +extern char *nicPacket; +extern uInt32 packetLength; + + +int ne2kInit(uInt32); +int ne2kProbe(int,struct device *); +int ne2kDevInit(struct device *); +void NS8390_init(struct device *dev,int startp); + +void ne2kISR(); +void ne2kHandler(); + +int NICtoPC(struct device *dev,void *packet,int length,int nic_addr); +int PCtoNIC(struct device *dev,void *packet,int length); + +struct nicBuffer *ne2kAllocBuffer(int); +struct nicBuffer *ne2kGetBuffer(); +void ne2kFreeBuffer(struct nicBuffer *); + +#endif + +/*** + $Log$ + Revision 1.5 2004/05/21 14:57:16 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/isa/pit.h b/src/sys/include/isa/pit.h new file mode 100644 index 0000000..424b8eb --- /dev/null +++ b/src/sys/include/isa/pit.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _PIT_H +#define _PIT_H + +#include + +int pitInit(int); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 14:57:16 reddawg + Cleaned up + + + END + ***/ + diff --git a/src/sys/include/lib/bioscall.h b/src/sys/include/lib/bioscall.h new file mode 100644 index 0000000..a8c93cb --- /dev/null +++ b/src/sys/include/lib/bioscall.h @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _BIOSCALL_H +#define _BIOSCALL_H + +#include + +#define EFLAG_TF 0x100 +#define EFLAG_IF 0x200 +#define EFLAG_IOPL3 0x3000 +#define EFLAG_VM 0x20000 + +void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds); +void bios16Code(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/lib/kmalloc.h b/src/sys/include/lib/kmalloc.h new file mode 100644 index 0000000..5faa5ed --- /dev/null +++ b/src/sys/include/lib/kmalloc.h @@ -0,0 +1,78 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KMALLOC_H +#define _KMALLOC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define sysMalloc -2 +#define sysID -2 + +struct memDescriptor { + struct memDescriptor *prev; //4 + struct memDescriptor *next; //4 + void *baseAddr; //4 + uInt32 limit; //4 + uInt8 status; //1 + char reserved[11]; //11 + }; + +void kfree(void *baseAddr); +void *kmalloc(uInt32 len); +void initMalloc(); +void *getEmptyDesc(); +void insertFreeDesc(struct memDescriptor *freeDesc); +void mergeMemBlocks(); +void kfreeProcess(pidType pid); + +extern struct memDescriptor *kernDesc; +extern struct memDescriptor *freeKernDesc; +extern struct memDescriptor *emptyKernDesc; + +extern int mallocLock; + +#ifdef __cplusplus +} +#endif + +#endif + +/*** + $Log$ + Revision 1.3 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/lib/kprint.h b/src/sys/include/lib/kprint.h new file mode 100644 index 0000000..9bd2ed4 --- /dev/null +++ b/src/sys/include/lib/kprint.h @@ -0,0 +1,48 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KPRINT_H +#define _KPRINT_H + +#include + +int kprintf(const char *fmt, ...); + +extern int printOff; + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/lib/kprintf.h b/src/sys/include/lib/kprintf.h new file mode 100644 index 0000000..5937784 --- /dev/null +++ b/src/sys/include/lib/kprintf.h @@ -0,0 +1,50 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KPRINTF_H +#define _KPRINTF_H + +#include + +int kprintf(const char *fmt, ...); +int ogPrintf(char *); + +extern int printOff; +extern int ogprintOff; + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/lib/libcpp.h b/src/sys/include/lib/libcpp.h new file mode 100644 index 0000000..5f92ffa --- /dev/null +++ b/src/sys/include/lib/libcpp.h @@ -0,0 +1,49 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef __LIBCPP_H +#define __LIBCPP_H + +#include + +void * operator new(unsigned size); +void operator delete(void * ptr); +void * operator new[](unsigned size); +void operator delete[](void * ptr); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/lib/string.h b/src/sys/include/lib/string.h new file mode 100644 index 0000000..053141b --- /dev/null +++ b/src/sys/include/lib/string.h @@ -0,0 +1,64 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _STRING_H +#define _STRING_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int kstrcmp(char *str1, char *str2); +int kstrncmp(const char * a, const char * b, size_t c); +void *kmemcpy(const void *dst, const void * src, size_t length); +void *kmemset(void * dst, int c, size_t length); +int kstrlen(const char * string); +int kmemcmp(const void * dst, const void * src, size_t length); +void kstrncpy(char * dest, const char * src, size_t size); +char *strtok(char *str, const char *sep); +char *strtok_r(char *str, const char *sep, char **last); + +int sprintf(char *buf,const char *fmt, ...); + +#ifdef __cplusplus +} +#endif + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:00:27 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/math.h b/src/sys/include/math.h new file mode 100644 index 0000000..07b15ce --- /dev/null +++ b/src/sys/include/math.h @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef __MATH_H +#define __MATH_H + +#include + +typedef long long int quad_t; +typedef unsigned long long int u_quad_t; + +double atan(double x); +double sqrt(double x); +u_quad_t __udivdi3(u_quad_t a,u_quad_t b); +quad_t __divdi3(quad_t a,quad_t b); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:22:35 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/mpi/mpi.h b/src/sys/include/mpi/mpi.h new file mode 100644 index 0000000..36ca7fe --- /dev/null +++ b/src/sys/include/mpi/mpi.h @@ -0,0 +1,90 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MPI_H +#define _MPI_H + +#include +#include + +#define MESSAGE_LENGTH 248 + +struct mpiMessage { + char data[MESSAGE_LENGTH]; + uInt32 type; + struct mpiMessage *next; + }; + +struct mpiMbox { + struct mpiMbox *next; + struct mpiMbox *prev; + struct mpiMessage *msg; + struct mpiMessage *msgLast; + char name[64]; + pidType pid; + }; + +typedef struct mpiMbox mpiMbox_t; +typedef struct mpiMessage mpiMessage_t; + + +int mpiCreateMbox(char *); +int mpiDestroyMbox(char *); +int mpiPostMessage(char *,uInt32,void *); +int mpiFetchMessage(char *,mpiMessage_t *); +int mpiSpam(uInt32,void *); + +#endif + +/*** + $Log$ + Revision 1.7 2004/05/28 03:52:56 reddawg + mpi: took a few suggestions from TCA + + Revision 1.6 2004/05/25 18:33:11 reddawg + We now use 128byte messages I can increase later + + Revision 1.5 2004/05/25 18:29:57 reddawg + We now lock onto a pid + + Revision 1.4 2004/05/25 16:52:22 reddawg + We now have mpiDestroyMbox(char *) This will of course destroy a mail box + + Revision 1.3 2004/05/25 16:28:21 reddawg + Made mpiFindMbox() static + + Revision 1.2 2004/05/25 15:42:19 reddawg + Enabled mpiSpam(); + + Revision 1.1 2004/05/25 14:07:01 reddawg + Sorry we can't forget the headers files + + END + ***/ + diff --git a/src/sys/include/net/api.h b/src/sys/include/net/api.h new file mode 100644 index 0000000..1d97411 --- /dev/null +++ b/src/sys/include/net/api.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_API_H__ +#define __LWIP_API_H__ + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/sys.h" + +#include "net/ipv4/ip.h" + +#include "net/udp.h" +#include "net/tcp.h" + +#include "net/err.h" + +#define NETCONN_NOCOPY 0x00 +#define NETCONN_COPY 0x01 + +enum netconn_type { + NETCONN_TCP, + NETCONN_UDP, + NETCONN_UDPLITE, + NETCONN_UDPNOCHKSUM +}; + +enum netconn_state { + NETCONN_NONE, + NETCONN_WRITE, + NETCONN_ACCEPT, + NETCONN_RECV, + NETCONN_CONNECT, + NETCONN_CLOSE +}; + +struct netbuf { + struct pbuf *p, *ptr; + struct ip_addr *fromaddr; + uInt16 fromport; + err_t err; +}; + +struct netconn { + enum netconn_type type; + enum netconn_state state; + union { + struct tcp_pcb *tcp; + struct udp_pcb *udp; + } pcb; + err_t err; + sys_mbox_t mbox; + sys_mbox_t recvmbox; + sys_mbox_t acceptmbox; + sys_sem_t sem; +}; + +/* Network buffer functions: */ +struct netbuf * netbuf_new (void); +void netbuf_delete (struct netbuf *buf); +void * netbuf_alloc (struct netbuf *buf, uInt16 size); +void netbuf_free (struct netbuf *buf); +void netbuf_ref (struct netbuf *buf, + void *dataptr, uInt16 size); +void netbuf_chain (struct netbuf *head, + struct netbuf *tail); + +uInt16 netbuf_len (struct netbuf *buf); +err_t netbuf_data (struct netbuf *buf, + void **dataptr, uInt16 *len); +Int8 netbuf_next (struct netbuf *buf); +void netbuf_first (struct netbuf *buf); + +void netbuf_copy (struct netbuf *buf, + void *dataptr, uInt16 len); +struct ip_addr * netbuf_fromaddr (struct netbuf *buf); +uInt16 netbuf_fromport (struct netbuf *buf); + +/* Network connection functions: */ +struct netconn * netconn_new (enum netconn_type type); +err_t netconn_delete (struct netconn *conn); +enum netconn_type netconn_type (struct netconn *conn); +err_t netconn_peer (struct netconn *conn, + struct ip_addr **addr, + uInt16 *port); +err_t netconn_addr (struct netconn *conn, + struct ip_addr **addr, + uInt16 *port); +err_t netconn_bind (struct netconn *conn, + struct ip_addr *addr, + uInt16 port); +err_t netconn_connect (struct netconn *conn, + struct ip_addr *addr, + uInt16 port); +err_t netconn_listen (struct netconn *conn); +struct netconn * netconn_accept (struct netconn *conn); +struct netbuf * netconn_recv (struct netconn *conn); +err_t netconn_send (struct netconn *conn, + struct netbuf *buf); +err_t netconn_write (struct netconn *conn, + void *dataptr, uInt16 size, + uInt8 copy); +err_t netconn_close (struct netconn *conn); + +err_t netconn_err (struct netconn *conn); + +void netbuf_copy_partial(struct netbuf *buf, void *dataptr, uInt16 len, uInt16 offset); + +#endif /* __LWIP_API_H__ */ + + diff --git a/src/sys/include/net/api_msg.h b/src/sys/include/net/api_msg.h new file mode 100644 index 0000000..2728f5f --- /dev/null +++ b/src/sys/include/net/api_msg.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_API_MSG_H__ +#define __LWIP_API_MSG_H__ + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/sys.h" + +#include "net/ipv4/ip.h" + +#include "net/udp.h" +#include "net/tcp.h" + +#include "net/api.h" + +enum api_msg_type { + API_MSG_NEWCONN, + API_MSG_DELCONN, + + API_MSG_BIND, + API_MSG_CONNECT, + + API_MSG_LISTEN, + API_MSG_ACCEPT, + + API_MSG_SEND, + API_MSG_RECV, + API_MSG_WRITE, + + API_MSG_CLOSE, + + API_MSG_MAX +}; + +struct api_msg_msg { + struct netconn *conn; + enum netconn_type conntype; + union { + struct pbuf *p; + struct { + struct ip_addr *ipaddr; + uInt16 port; + } bc; + struct { + void *dataptr; + uInt16 len; + unsigned char copy; + } w; + sys_mbox_t mbox; + uInt16 len; + } msg; +}; + +struct api_msg { + enum api_msg_type type; + struct api_msg_msg msg; +}; + +void api_msg_input(struct api_msg *msg); +void api_msg_post(struct api_msg *msg); + +#endif /* __LWIP_API_MSG_H__ */ + diff --git a/src/sys/include/net/arch.h b/src/sys/include/net/arch.h new file mode 100644 index 0000000..8be38c0 --- /dev/null +++ b/src/sys/include/net/arch.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ARCH_H__ +#define __LWIP_ARCH_H__ + +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif + +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif + +#include "arch/cpu.h" +#include "arch/cc.h" + +#ifndef PACK_STRUCT_BEGIN +#define PACK_STRUCT_BEGIN +#endif /* PACK_STRUCT_BEGIN */ + +#ifndef PACK_STRUCT_END +#define PACK_STRUCT_END +#endif /* PACK_STRUCT_END */ + +#ifndef PACK_STRUCT_FIELD +#define PACK_STRUCT_FIELD(x) x +#endif /* PACK_STRUCT_FIELD */ + +#endif /* __LWIP_ARCH_H__ */ diff --git a/src/sys/include/net/arch/cc.h b/src/sys/include/net/arch/cc.h new file mode 100644 index 0000000..a2f83a5 --- /dev/null +++ b/src/sys/include/net/arch/cc.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_CC_H__ +#define __ARCH_CC_H__ + +#define PACK_STRUCT_FIELD(x) x __attribute__((packed)) +#define PACK_STRUCT_STRUCT __attribute__((packed)) +#define PACK_STRUCT_BEGIN +#define PACK_STRUCT_END + +#endif /* __ARCH_CC_H__ */ diff --git a/src/sys/include/net/arch/cpu.h b/src/sys/include/net/arch/cpu.h new file mode 100644 index 0000000..0a6d531 --- /dev/null +++ b/src/sys/include/net/arch/cpu.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_CPU_H__ +#define __ARCH_CPU_H__ + +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif /* BYTE_ORDER */ + +#endif /* __ARCH_CPU_H__ */ diff --git a/src/sys/include/net/arch/init.h b/src/sys/include/net/arch/init.h new file mode 100644 index 0000000..0b5409d --- /dev/null +++ b/src/sys/include/net/arch/init.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_INIT_H__ +#define __ARCH_INIT_H__ + +#define TCPIP_INIT_DONE(arg) sys_sem_signal(*(sys_sem_t *)arg) + +#endif /* __ARCH_INIT_H__ */ + + + + diff --git a/src/sys/include/net/arch/lib.h b/src/sys/include/net/arch/lib.h new file mode 100644 index 0000000..13d5446 --- /dev/null +++ b/src/sys/include/net/arch/lib.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_LIB_H__ +#define __ARCH_LIB_H__ + +#ifndef _STRING_H_ +#ifndef _STRING_H +int strlen(const char *str); +int strncmp(const char *str1, const char *str2, int len); +void bcopy(const void *src, void *dest, int len); +void bzero(void *data, int n); +#endif /* _STRING_H */ +#endif /* _STRING_H_ */ + +#endif /* __ARCH_LIB_H__ */ diff --git a/src/sys/include/net/arch/perf.h b/src/sys/include/net/arch/perf.h new file mode 100644 index 0000000..9b47e5b --- /dev/null +++ b/src/sys/include/net/arch/perf.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_PERF_H__ +#define __ARCH_PERF_H__ + +#include + +#ifdef PERF +#define PERF_START { \ + unsigned long __c1l, __c1h, __c2l, __c2h; \ + __asm__(".byte 0x0f, 0x31" : "=a" (__c1l), "=d" (__c1h)) +#define PERF_STOP(x) __asm__(".byte 0x0f, 0x31" : "=a" (__c2l), "=d" (__c2h)); \ + perf_print(__c1l, __c1h, __c2l, __c2h, x);} + +/*#define PERF_START do { \ + struct tms __perf_start, __perf_end; \ + times(&__perf_start) +#define PERF_STOP(x) times(&__perf_end); \ + perf_print_times(&__perf_start, &__perf_end, x);\ + } while(0)*/ +#else /* PERF */ +#define PERF_START /* null definition */ +#define PERF_STOP(x) /* null definition */ +#endif /* PERF */ + +void perf_print(unsigned long c1l, unsigned long c1h, + unsigned long c2l, unsigned long c2h, + char *key); + +void perf_print_times(struct tms *start, struct tms *end, char *key); + +void perf_init(char *fname); + +#endif /* __ARCH_PERF_H__ */ diff --git a/src/sys/include/net/arch/sys_arch.h b/src/sys/include/net/arch/sys_arch.h new file mode 100644 index 0000000..9ef598f --- /dev/null +++ b/src/sys/include/net/arch/sys_arch.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __ARCH_SYS_ARCH_H__ +#define __ARCH_SYS_ARCH_H__ + +#define SYS_MBOX_NULL NULL +#define SYS_SEM_NULL NULL + +struct sys_sem; +typedef struct sys_sem * sys_sem_t; + +struct sys_mbox; +typedef struct sys_mbox *sys_mbox_t; + +struct sys_thread; +typedef struct sys_thread * sys_thread_t; + +#endif /* __ARCH_SYS_ARCH_H__ */ + diff --git a/src/sys/include/net/debug.h b/src/sys/include/net/debug.h new file mode 100644 index 0000000..3d9899f --- /dev/null +++ b/src/sys/include/net/debug.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_DEBUG_H__ +#define __LWIP_DEBUG_H__ + +#ifdef LWIP_DEBUG + +#define ASSERT(x,y) if(!(y)) {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); fflush(NULL); abort();} + +/* These defines control the amount of debugging output: */ +#define MEM_TRACKING + +#define DEMO_DEBUG 1 + +#define ARP_DEBUG 0 + +#define NETIF_DEBUG 1 +#define PBUF_DEBUG 0 +#define DELIF_DEBUG 0 +#define DROPIF_DEBUG 0 +#define TUNIF_DEBUG 0 +#define UNIXIF_DEBUG 0 +#define TAPIF_DEBUG 0 + +#define API_LIB_DEBUG 0 +#define API_MSG_DEBUG 0 +#define SOCKETS_DEBUG 1 +#define ICMP_DEBUG 0 +#define INET_DEBUG 0 +#define IP_DEBUG 0 +#define IP_REASS_DEBUG 1 +#define MEM_DEBUG 0 +#define MEMP_DEBUG 0 +#define SYS_DEBUG 0 +#define TCP_DEBUG 0 +#define TCP_INPUT_DEBUG 0 +#define TCP_FR_DEBUG 0 +#define TCP_RTO_DEBUG 0 +#define TCP_REXMIT_DEBUG 0 +#define TCP_CWND_DEBUG 0 +#define TCP_WND_DEBUG 0 +#define TCP_OUTPUT_DEBUG 0 +#define TCP_RST_DEBUG 0 +#define TCP_QLEN_DEBUG 0 +#define UDP_DEBUG 0 +#define TCPIP_DEBUG 0 +#define TCPDUMP_DEBUG 0 +#define DHCP_DEBUG 1 + +#include +#define DEBUGF(debug, x) do { if(debug){ printf x; } } while(0) + + +#else /* LWIP_DEBUG */ + +/* DEBUG is not defined, so we define null macros for ASSERT and DEBUGF */ + +#define ASSERT(x,y) +#define DEBUGF(debug, x) + +/* And we define those to be zero: */ + +#define DEMO_DEBUG 0 +#define ARP_DEBUG 0 +#define NETIF_DEBUG 0 +#define PBUF_DEBUG 0 +#define DELIF_DEBUG 0 +#define DROPIF_DEBUG 0 +#define TUNIF_DEBUG 0 +#define UNIXIF_DEBUG 0 +#define TAPIF_DEBUG 0 +#define API_LIB_DEBUG 0 +#define API_MSG_DEBUG 0 +#define SOCKETS_DEBUG 0 +#define ICMP_DEBUG 0 +#define INET_DEBUG 0 +#define IP_DEBUG 0 +#define IP_REASS_DEBUG 0 +#define MEM_DEBUG 0 +#define MEMP_DEBUG 0 +#define SYS_DEBUG 0 +#define TCP_DEBUG 0 +#define TCP_INPUT_DEBUG 0 +#define TCP_FR_DEBUG 0 +#define TCP_RTO_DEBUG 0 +#define TCP_REXMIT_DEBUG 0 +#define TCP_CWND_DEBUG 0 +#define TCP_WND_DEBUG 0 +#define TCP_OUTPUT_DEBUG 0 +#define TCP_RST_DEBUG 0 +#define TCP_QLEN_DEBUG 0 +#define UDP_DEBUG 0 +#define TCPIP_DEBUG 0 +#define TCPDUMP_DEBUG 0 +#define DHCP_DEBUG 0 + +#endif /* LWIP_DEBUG */ + + +#endif /* __LWIP_DEBUG_H__ */ + + + + + + diff --git a/src/sys/include/net/def.h b/src/sys/include/net/def.h new file mode 100644 index 0000000..19e2289 --- /dev/null +++ b/src/sys/include/net/def.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_DEF_H__ +#define __LWIP_DEF_H__ + +#define UMAX(a, b) ((a) > (b) ? (a) : (b)) + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#include "arch/lib.h" + +#endif /* __LWIP_DEF_H__ */ + diff --git a/src/sys/include/net/err.h b/src/sys/include/net/err.h new file mode 100644 index 0000000..ddaba06 --- /dev/null +++ b/src/sys/include/net/err.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ERR_H__ +#define __LWIP_ERR_H__ + +#include + +#include "net/debug.h" + +#include "net/arch/cc.h" + +typedef Int8 err_t; + +/* Definitions for error constants. */ + +#define ERR_OK 0 /* No error, everything OK. */ +#define ERR_MEM -1 /* Out of memory error. */ +#define ERR_BUF -2 /* Buffer error. */ + + +#define ERR_ABRT -3 /* Connection aborted. */ +#define ERR_RST -4 /* Connection reset. */ +#define ERR_CLSD -5 /* Connection closed. */ +#define ERR_CONN -6 /* Not connected. */ + +#define ERR_VAL -7 /* Illegal value. */ + +#define ERR_ARG -8 /* Illegal argument. */ + +#define ERR_RTE -9 /* Routing problem. */ + +#define ERR_USE -10 /* Address in use. */ + + + +#ifdef LWIP_DEBUG +extern char *lwip_strerr(err_t err); +#else +#define lwip_strerr(x) "" +#endif /* LWIP_DEBUG */ +#endif /* __LWIP_ERR_H__ */ diff --git a/src/sys/include/net/ipv4/icmp.h b/src/sys/include/net/ipv4/icmp.h new file mode 100644 index 0000000..0a12aeb --- /dev/null +++ b/src/sys/include/net/ipv4/icmp.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ICMP_H__ +#define __LWIP_ICMP_H__ + +#include "net/arch.h" + +#include "net/opt.h" +#include "net/pbuf.h" + +#include "net/netif.h" + +#define ICMP_ER 0 /* echo reply */ +#define ICMP_DUR 3 /* destination unreachable */ +#define ICMP_SQ 4 /* source quench */ +#define ICMP_RD 5 /* redirect */ +#define ICMP_ECHO 8 /* echo */ +#define ICMP_TE 11 /* time exceeded */ +#define ICMP_PP 12 /* parameter problem */ +#define ICMP_TS 13 /* timestamp */ +#define ICMP_TSR 14 /* timestamp reply */ +#define ICMP_IRQ 15 /* information request */ +#define ICMP_IR 16 /* information reply */ + +enum icmp_dur_type { + ICMP_DUR_NET = 0, /* net unreachable */ + ICMP_DUR_HOST = 1, /* host unreachable */ + ICMP_DUR_PROTO = 2, /* protocol unreachable */ + ICMP_DUR_PORT = 3, /* port unreachable */ + ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */ + ICMP_DUR_SR = 5 /* source route failed */ +}; + +enum icmp_te_type { + ICMP_TE_TTL = 0, /* time to live exceeded in transit */ + ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */ +}; + +void icmp_input(struct pbuf *p, struct netif *inp); + +void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t); +void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); + +struct icmp_echo_hdr { + PACK_STRUCT_FIELD(uInt16 _type_code); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt16 id); + PACK_STRUCT_FIELD(uInt16 seqno); +} PACK_STRUCT_STRUCT; + + + +struct icmp_dur_hdr { + PACK_STRUCT_FIELD(uInt16 _type_code); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt32 unused); +} PACK_STRUCT_STRUCT; + +struct icmp_te_hdr { + PACK_STRUCT_FIELD(uInt16 _type_code); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt32 unused); +} PACK_STRUCT_STRUCT; + +#define ICMPH_TYPE(hdr) (NTOHS((hdr)->_type_code) >> 8) +#define ICMPH_CODE(hdr) (NTOHS((hdr)->_type_code) & 0xff) + +#define ICMPH_TYPE_SET(hdr, type) ((hdr)->_type_code = HTONS(ICMPH_CODE(hdr) | ((type) << 8))) +#define ICMPH_CODE_SET(hdr, code) ((hdr)->_type_code = HTONS((code) | (ICMPH_TYPE(hdr) << 8))) + +#endif /* __LWIP_ICMP_H__ */ + diff --git a/src/sys/include/net/ipv4/inet.h b/src/sys/include/net/ipv4/inet.h new file mode 100644 index 0000000..7752f4e --- /dev/null +++ b/src/sys/include/net/ipv4/inet.h @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_INET_H__ +#define __LWIP_INET_H__ + +#include "net/arch.h" + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/ipv4/ip_addr.h" + +uInt16 inet_chksum(void *dataptr, uInt16 len); +uInt16 inet_chksum_pbuf(struct pbuf *p); +uInt16 inet_chksum_pseudo(struct pbuf *p, + struct ip_addr *src, struct ip_addr *dest, + uInt8 proto, uInt16 proto_len); + +#ifdef HTONS +#undef HTONS +#endif /* HTONS */ +#ifdef NTOHS +#undef NTOHS +#endif /* NTOHS */ +#ifdef HTONL +#undef HTONL +#endif /* HTONL */ +#ifdef NTOHL +#undef NTOHL +#endif /* NTOHL */ + +#ifndef HTONS +# if BYTE_ORDER == BIG_ENDIAN +# define HTONS(n) (n) +# define htons(n) HTONS(n) +# else /* BYTE_ORDER == BIG_ENDIAN */ +# define HTONS(n) (((((uInt16)(n) & 0xff)) << 8) | (((uInt16)(n) & 0xff00) >> 8)) +# endif /* BYTE_ORDER == BIG_ENDIAN */ +#endif /* HTONS */ + +#ifdef NTOHS +#undef NTOHS +#endif /* NTOHS */ + +#ifdef ntohs +#undef ntohs +#endif /* ntohs */ + +#define NTOHS HTONS +#define ntohs htons + + +#ifndef HTONL +# if BYTE_ORDER == BIG_ENDIAN +# define HTONL(n) (n) +# define htonl(n) HTONL(n) +# else /* BYTE_ORDER == BIG_ENDIAN */ +# define HTONL(n) (((((uInt32)(n) & 0xff)) << 24) | \ + ((((uInt32)(n) & 0xff00)) << 8) | \ + ((((uInt32)(n) & 0xff0000)) >> 8) | \ + ((((uInt32)(n) & 0xff000000)) >> 24)) +# endif /* BYTE_ORDER == BIG_ENDIAN */ +#endif /* HTONL */ + +#ifdef ntohl +#undef ntohl +#endif /* ntohl */ + +#ifdef NTOHL +#undef NTOHL +#endif /* NTOHL */ + +#define NTOHL HTONL +#define ntohl htonl + +#ifndef _MACHINE_ENDIAN_H_ +#ifndef _NETINET_IN_H +#ifndef _LINUX_BYTEORDER_GENERIC_H + +#if BYTE_ORDER == LITTLE_ENDIAN +uInt16 htons(uInt16 n); +uInt32 htonl(uInt32 n); +#else +#endif /* BYTE_ORDER == LITTLE_ENDIAN */ + +#endif /* _LINUX_BYTEORDER_GENERIC_H */ +#endif /* _NETINET_IN_H */ +#endif /* _MACHINE_ENDIAN_H_ */ + +#endif /* __LWIP_INET_H__ */ + diff --git a/src/sys/include/net/ipv4/ip.h b/src/sys/include/net/ipv4/ip.h new file mode 100644 index 0000000..fcef881 --- /dev/null +++ b/src/sys/include/net/ipv4/ip.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_H__ +#define __LWIP_IP_H__ + +#include "net/arch.h" + +#include "net/def.h" +#include "net/pbuf.h" +#include "net/ipv4/ip_addr.h" +#include "net/netif.h" + +#include "net/err.h" + +void ip_init(void); +uInt8 ip_lookup(void *header, struct netif *inp); +struct netif *ip_route(struct ip_addr *dest); +err_t ip_input(struct pbuf *p, struct netif *inp); +err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + uInt8 ttl, uInt8 proto); +err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + uInt8 ttl, uInt8 proto, + struct netif *netif); + +#define IP_HLEN 20 + +#define IP_PROTO_ICMP 1 +#define IP_PROTO_UDP 17 +#define IP_PROTO_UDPLITE 170 +#define IP_PROTO_TCP 6 + +/* This is passed as the destination address to ip_output_if (not + to ip_output), meaning that an IP header already is constructed + in the pbuf. This is used when TCP retransmits. */ +#ifdef IP_HDRINCL +#undef IP_HDRINCL +#endif /* IP_HDRINCL */ +#define IP_HDRINCL NULL + +struct ip_hdr { + /* version / header length / type of service */ + PACK_STRUCT_FIELD(uInt16 _v_hl_tos); + /* total length */ + PACK_STRUCT_FIELD(uInt16 _len); + /* identification */ + PACK_STRUCT_FIELD(uInt16 _id); + /* fragment offset field */ + PACK_STRUCT_FIELD(uInt16 _offset); +#define IP_RF 0x8000 /* reserved fragment flag */ +#define IP_DF 0x4000 /* dont fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + /* time to live / protocol*/ + PACK_STRUCT_FIELD(uInt16 _ttl_proto); + /* checksum */ + PACK_STRUCT_FIELD(uInt16 _chksum); + /* source and destination IP addresses */ + PACK_STRUCT_FIELD(struct ip_addr src); + PACK_STRUCT_FIELD(struct ip_addr dest); +} PACK_STRUCT_STRUCT; + +#define IPH_V(hdr) (NTOHS((hdr)->_v_hl_tos) >> 12) +#define IPH_HL(hdr) ((NTOHS((hdr)->_v_hl_tos) >> 8) & 0x0f) +#define IPH_TOS(hdr) HTONS((NTOHS((hdr)->_v_hl_tos) & 0xff)) +#define IPH_LEN(hdr) ((hdr)->_len) +#define IPH_ID(hdr) ((hdr)->_id) +#define IPH_OFFSET(hdr) ((hdr)->_offset) +#define IPH_TTL(hdr) (NTOHS((hdr)->_ttl_proto) >> 8) +#define IPH_PROTO(hdr) (NTOHS((hdr)->_ttl_proto) & 0xff) +#define IPH_CHKSUM(hdr) ((hdr)->_chksum) + +#define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = HTONS(((v) << 12) | ((hl) << 8) | (tos)) +#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) +#define IPH_ID_SET(hdr, id) (hdr)->_id = (id) +#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) +#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = HTONS(IPH_PROTO(hdr) | ((ttl) << 8)) +#define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = HTONS((proto) | (IPH_TTL(hdr) << 8)) +#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) + + + +#if IP_DEBUG +void ip_debug_print(struct pbuf *p); +#endif /* IP_DEBUG */ + +#endif /* __LWIP_IP_H__ */ + + diff --git a/src/sys/include/net/ipv4/ip_addr.h b/src/sys/include/net/ipv4/ip_addr.h new file mode 100644 index 0000000..2fb5168 --- /dev/null +++ b/src/sys/include/net/ipv4/ip_addr.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_ADDR_H__ +#define __LWIP_IP_ADDR_H__ + +#include "net/arch.h" + +#define IP_ADDR_ANY 0 + +#define IP_ADDR_BROADCAST (&ip_addr_broadcast) + +PACK_STRUCT_BEGIN +struct ip_addr { + PACK_STRUCT_FIELD(uInt32 addr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END + +extern struct ip_addr ip_addr_broadcast; + +#define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = htonl(((uInt32)(a & 0xff) << 24) | ((uInt32)(b & 0xff) << 16) | \ + ((uInt32)(c & 0xff) << 8) | (uInt32)(d & 0xff)) + +#define ip_addr_set(dest, src) (dest)->addr = \ + ((src) == IP_ADDR_ANY? IP_ADDR_ANY:\ + ((struct ip_addr *)src)->addr) +#define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \ + (mask)->addr) == \ + ((addr2)->addr & \ + (mask)->addr)) +#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr) + +#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0) + +#define ip_addr_isbroadcast(addr1, mask) (((((addr1)->addr) & ~((mask)->addr)) == \ + (0xffffffff & ~((mask)->addr))) || \ + ((addr1)->addr == 0xffffffff) || \ + ((addr1)->addr == 0x00000000)) + + +#define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000)) + + +#define ip_addr_debug_print(ipaddr) kprintf("%d.%d.%d.%d", \ + (uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff, \ + (uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff, \ + (uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff, \ + (uInt8)ntohl((ipaddr)->addr) & 0xff) + + +#define ip4_addr1(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 24) & 0xff) +#define ip4_addr2(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 16) & 0xff) +#define ip4_addr3(ipaddr) ((uInt8)(ntohl((ipaddr)->addr) >> 8) & 0xff) +#define ip4_addr4(ipaddr) ((uInt8)(ntohl((ipaddr)->addr)) & 0xff) +#endif /* __LWIP_IP_ADDR_H__ */ + + + + + + diff --git a/src/sys/include/net/ipv6/icmp.h b/src/sys/include/net/ipv6/icmp.h new file mode 100644 index 0000000..ac428e9 --- /dev/null +++ b/src/sys/include/net/ipv6/icmp.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_ICMP_H__ +#define __LWIP_ICMP_H__ + +#include "lwip/arch.h" + +#include "lwip/opt.h" +#include "lwip/pbuf.h" + +#include "lwip/netif.h" + +#define ICMP6_DUR 1 +#define ICMP6_TE 3 +#define ICMP6_ECHO 128 /* echo */ +#define ICMP6_ER 129 /* echo reply */ + + +enum icmp_dur_type { + ICMP_DUR_NET = 0, /* net unreachable */ + ICMP_DUR_HOST = 1, /* host unreachable */ + ICMP_DUR_PROTO = 2, /* protocol unreachable */ + ICMP_DUR_PORT = 3, /* port unreachable */ + ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */ + ICMP_DUR_SR = 5 /* source route failed */ +}; + +enum icmp_te_type { + ICMP_TE_TTL = 0, /* time to live exceeded in transit */ + ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */ +}; + +void icmp_input(struct pbuf *p, struct netif *inp); + +void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t); +void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); + +struct icmp_echo_hdr { + u8_t type; + u8_t icode; + u16_t chksum; + u16_t id; + u16_t seqno; +}; + +struct icmp_dur_hdr { + u8_t type; + u8_t icode; + u16_t chksum; + u32_t unused; +}; + +struct icmp_te_hdr { + u8_t type; + u8_t icode; + u16_t chksum; + u32_t unused; +}; + +#endif /* __LWIP_ICMP_H__ */ + diff --git a/src/sys/include/net/ipv6/inet.h b/src/sys/include/net/ipv6/inet.h new file mode 100644 index 0000000..8f1f203 --- /dev/null +++ b/src/sys/include/net/ipv6/inet.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_INET_H__ +#define __LWIP_INET_H__ + +#include "net/arch.h" + +#include "net/opt.h" +#include "net/pbuf.h" +#include "net/ipv6/ip_addr.h" + +u16_t inet_chksum(void *data, u16_t len); +u16_t inet_chksum_pbuf(struct pbuf *p); +u16_t inet_chksum_pseudo(struct pbuf *p, + struct ip_addr *src, struct ip_addr *dest, + u8_t proto, u32_t proto_len); + + +#ifndef _MACHINE_ENDIAN_H_ +#ifndef _NETINET_IN_H +#ifndef _LINUX_BYTEORDER_GENERIC_H +u16_t htons(u16_t n); +u16_t ntohs(u16_t n); +u32_t htonl(u32_t n); +u32_t ntohl(u32_t n); +#endif /* _LINUX_BYTEORDER_GENERIC_H */ +#endif /* _NETINET_IN_H */ +#endif /* _MACHINE_ENDIAN_H_ */ + +#endif /* __LWIP_INET_H__ */ + diff --git a/src/sys/include/net/ipv6/ip.h b/src/sys/include/net/ipv6/ip.h new file mode 100644 index 0000000..82ca272 --- /dev/null +++ b/src/sys/include/net/ipv6/ip.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_H__ +#define __LWIP_IP_H__ + +#include "lwip/debug.h" +#include "lwip/def.h" +#include "lwip/pbuf.h" +#include "lwip/ip_addr.h" + +#include "lwip/err.h" + +#define IP_HLEN 40 + +#define IP_PROTO_ICMP 58 +#define IP_PROTO_UDP 17 +#define IP_PROTO_UDPLITE 170 +#define IP_PROTO_TCP 6 + +/* This is passed as the destination address to ip_output_if (not + to ip_output), meaning that an IP header already is constructed + in the pbuf. This is used when TCP retransmits. */ +#ifdef IP_HDRINCL +#undef IP_HDRINCL +#endif /* IP_HDRINCL */ +#define IP_HDRINCL NULL + + +/* The IPv6 header. */ +struct ip_hdr { +#if BYTE_ORDER == LITTLE_ENDIAN + u8_t tclass1:4, v:4; + u8_t flow1:4, tclass2:4; +#else + u8_t v:4, tclass1:4; + u8_t tclass2:8, flow1:4; +#endif + u16_t flow2; + u16_t len; /* payload length */ + u8_t nexthdr; /* next header */ + u8_t hoplim; /* hop limit (TTL) */ + struct ip_addr src, dest; /* source and destination IP addresses */ +}; + +void ip_init(void); + +#include "lwip/netif.h" + +struct netif *ip_route(struct ip_addr *dest); + +void ip_input(struct pbuf *p, struct netif *inp); + +/* source and destination addresses in network byte order, please */ +err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + unsigned char ttl, unsigned char proto); + +err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + unsigned char ttl, unsigned char proto, + struct netif *netif); + +#if IP_DEBUG +void ip_debug_print(struct pbuf *p); +#endif /* IP_DEBUG */ + +#endif /* __LWIP_IP_H__ */ + + diff --git a/src/sys/include/net/ipv6/ip_addr.h b/src/sys/include/net/ipv6/ip_addr.h new file mode 100644 index 0000000..a082805 --- /dev/null +++ b/src/sys/include/net/ipv6/ip_addr.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_IP_ADDR_H__ +#define __LWIP_IP_ADDR_H__ + +#include "net/arch.h" + +#define IP_ADDR_ANY 0 + +struct ip_addr { + u32_t addr[4]; +}; + +#define IP6_ADDR(ipaddr, a,b,c,d,e,f,g,h) do { (ipaddr)->addr[0] = htonl((u32_t)((a & 0xffff) << 16) | (b & 0xffff)); \ + (ipaddr)->addr[1] = htonl(((c & 0xffff) << 16) | (d & 0xffff)); \ + (ipaddr)->addr[2] = htonl(((e & 0xffff) << 16) | (f & 0xffff)); \ + (ipaddr)->addr[3] = htonl(((g & 0xffff) << 16) | (h & 0xffff)); } while(0) + +int ip_addr_maskcmp(struct ip_addr *addr1, struct ip_addr *addr2, + struct ip_addr *mask); +int ip_addr_cmp(struct ip_addr *addr1, struct ip_addr *addr2); +void ip_addr_set(struct ip_addr *dest, struct ip_addr *src); +int ip_addr_isany(struct ip_addr *addr); + + +#if IP_DEBUG +void ip_addr_debug_print(struct ip_addr *addr); +#endif /* IP_DEBUG */ + +#endif /* __LWIP_IP_ADDR_H__ */ diff --git a/src/sys/include/net/list.h b/src/sys/include/net/list.h new file mode 100644 index 0000000..f2afc5f --- /dev/null +++ b/src/sys/include/net/list.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_LIST_H__ +#define __LWIP_LIST_H__ + +struct list; + +struct list *list_new(int size); +int list_push(struct list *list, void *elem); +void *list_pop(struct list *list); +int list_remove(struct list *list, void *elem); +void *list_first(struct list *list); +int list_elems(struct list *list); +void list_delete(struct list *list); + +void list_map(struct list *list, void (* func)(void *arg)); + +#endif /* __LWIP_LIST_H__ */ diff --git a/src/sys/include/net/lwipopts.h b/src/sys/include/net/lwipopts.h new file mode 100644 index 0000000..1499b27 --- /dev/null +++ b/src/sys/include/net/lwipopts.h @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIPOPTS_H__ +#define __LWIPOPTS_H__ + +/* ---------- Memory options ---------- */ +/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which + lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2 + byte alignment -> define MEM_ALIGNMENT to 2. */ +#define MEM_ALIGNMENT 2 + +/* MEM_SIZE: the size of the heap memory. If the application will send +a lot of data that needs to be copied, this should be set high. */ +#define MEM_SIZE 1000 + +/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application + sends a lot of data out of ROM (or other static memory), this + should be set high. */ +#define MEMP_NUM_PBUF 8 +/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One + per active UDP "connection". */ +#define MEMP_NUM_UDP_PCB 4 +/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP + connections. */ +#define MEMP_NUM_TCP_PCB 5 +/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP + connections. */ +#define MEMP_NUM_TCP_PCB_LISTEN 8 +/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP + segments. */ +#define MEMP_NUM_TCP_SEG 8 +/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active + timeouts. */ +#define MEMP_NUM_SYS_TIMEOUT 3 + + +/* The following four are used only with the sequential API and can be + set to 0 if the application only will use the raw API. */ +/* MEMP_NUM_NETBUF: the number of struct netbufs. */ +#define MEMP_NUM_NETBUF 2 +/* MEMP_NUM_NETCONN: the number of struct netconns. */ +#define MEMP_NUM_NETCONN 4 +/* MEMP_NUM_APIMSG: the number of struct api_msg, used for + communication between the TCP/IP stack and the sequential + programs. */ +#define MEMP_NUM_API_MSG 8 +/* MEMP_NUM_TCPIPMSG: the number of struct tcpip_msg, which is used + for sequential API communication and incoming packets. Used in + src/api/tcpip.c. */ +#define MEMP_NUM_TCPIP_MSG 8 + +/* These two control is reclaimer functions should be compiled + in. Should always be turned on (1). */ +#define MEM_RECLAIM 1 +#define MEMP_RECLAIM 1 + +/* ---------- Pbuf options ---------- */ +/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ +#define PBUF_POOL_SIZE 6 + +/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ +#define PBUF_POOL_BUFSIZE 128 + +/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a + link level header. */ +#define PBUF_LINK_HLEN 16 + +/* ---------- TCP options ---------- */ +#define LWIP_TCP 1 +#define TCP_TTL 255 + +/* Controls if TCP should queue segments that arrive out of + order. Define to 0 if your device is low on memory. */ +#define TCP_QUEUE_OOSEQ 1 + +/* TCP Maximum segment size. */ +#define TCP_MSS 128 + +/* TCP sender buffer space (bytes). */ +#define TCP_SND_BUF 256 + +/* TCP sender buffer space (pbufs). This must be at least = 2 * + TCP_SND_BUF/TCP_MSS for things to work. */ +#define TCP_SND_QUEUELEN 4 * TCP_SND_BUF/TCP_MSS + +/* TCP receive window. */ +#define TCP_WND 1024 + +/* Maximum number of retransmissions of data segments. */ +#define TCP_MAXRTX 12 + +/* Maximum number of retransmissions of SYN segments. */ +#define TCP_SYNMAXRTX 4 + +/* ---------- ARP options ---------- */ +#define ARP_TABLE_SIZE 10 + +/* ---------- IP options ---------- */ +/* Define IP_FORWARD to 1 if you wish to have the ability to forward + IP packets across network interfaces. If you are going to run lwIP + on a device with only one network interface, define this to 0. */ +#define IP_FORWARD 1 + +/* If defined to 1, IP options are allowed (but not parsed). If + defined to 0, all packets with IP options are dropped. */ +#define IP_OPTIONS 1 + +/* ---------- ICMP options ---------- */ +#define ICMP_TTL 255 + + +/* ---------- DHCP options ---------- */ +/* Define LWIP_DHCP to 1 if you want DHCP configuration of + interfaces. DHCP is not implemented in lwIP 0.5.1, however, so + turning this on does currently not work. */ +#define LWIP_DHCP 0 + +/* 1 if you want to do an ARP check on the offered address + (recommended). */ +#define DHCP_DOES_ARP_CHECK 1 + +/* ---------- UDP options ---------- */ +#define LWIP_UDP 1 +#define UDP_TTL 255 + + +/* ---------- Statistics options ---------- */ +#define STATS + +#ifdef STATS +#define LINK_STATS +#define IP_STATS +#define ICMP_STATS +#define UDP_STATS +#define TCP_STATS +#define MEM_STATS +#define MEMP_STATS +#define PBUF_STATS +#define SYS_STATS +#endif /* STATS */ + +#endif /* __LWIPOPTS_H__ */ diff --git a/src/sys/include/net/mem.h b/src/sys/include/net/mem.h new file mode 100644 index 0000000..c8a17eb --- /dev/null +++ b/src/sys/include/net/mem.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_MEM_H__ +#define __LWIP_MEM_H__ + +#include + +#include "net/debug.h" +#include "net/opt.h" +#include "net/arch.h" + +#if MEM_SIZE > 64000l +typedef uInt32 mem_size_t; +#else +typedef uInt16 mem_size_t; +#endif /* MEM_SIZE > 64000 */ + + +void mem_init(void); + +void *mem_malloc(mem_size_t size); +void *mem_malloc2(mem_size_t size); +void mem_free(void *mem); +void *mem_realloc(void *mem, mem_size_t size); +void *mem_reallocm(void *mem, mem_size_t size); + +#ifdef MEM_PERF +void mem_perf_start(void); +void mem_perf_init(char *fname); +#endif /* MEM_PERF */ + +#ifdef MEM_RECLAIM +typedef mem_size_t (*mem_reclaim_func)(void *arg, mem_size_t size); +void mem_register_reclaim(mem_reclaim_func f, void *arg); +void mem_reclaim(unsigned int size); +#else +#define mem_register_reclaim(f, arg) +#endif /* MEM_RECLAIM */ + + +#define MEM_ALIGN_SIZE(size) (size + \ + ((((size) % MEM_ALIGNMENT) == 0)? 0 : \ + (MEM_ALIGNMENT - ((size) % MEM_ALIGNMENT)))) + +#define MEM_ALIGN(addr) (void *)MEM_ALIGN_SIZE((uInt32)addr) + +#endif /* __LWIP_MEM_H__ */ + diff --git a/src/sys/include/net/memp.h b/src/sys/include/net/memp.h new file mode 100644 index 0000000..3e0b849 --- /dev/null +++ b/src/sys/include/net/memp.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#ifndef __LWIP_MEMP_H__ +#define __LWIP_MEMP_H__ + +#include + +#include "net/debug.h" +#include "net/arch/cc.h" +#include "net/lwipopts.h" + +typedef enum { + MEMP_PBUF, + MEMP_UDP_PCB, + MEMP_TCP_PCB, + MEMP_TCP_PCB_LISTEN, + MEMP_TCP_SEG, + + MEMP_NETBUF, + MEMP_NETCONN, + MEMP_API_MSG, + MEMP_TCPIP_MSG, + + MEMP_SYS_TIMEOUT, + + MEMP_MAX +} memp_t; + +void memp_init(void); + +void *memp_malloc(memp_t type); +void *memp_mallocp(memp_t type); +void *memp_malloc2(memp_t type); +void *memp_realloc(memp_t fromtype, memp_t totype, void *mem); +void memp_free(memp_t type, void *mem); +void memp_freep(memp_t type, void *mem); + +#if MEMP_RECLAIM +typedef uInt8 (*memp_reclaim_func)(void *arg, memp_t type); +void memp_register_reclaim(memp_t type, memp_reclaim_func f, void *arg); +#else +#define memp_register_reclaim(t, f, arg) +#endif /* MEMP_RECLAIM */ + +#endif /* __LWIP_MEMP_H__ */ + diff --git a/src/sys/include/net/net.h b/src/sys/include/net/net.h new file mode 100644 index 0000000..697c916 --- /dev/null +++ b/src/sys/include/net/net.h @@ -0,0 +1,36 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _NET_H +#define _NET_H + +#include + +int netInit(); + +#endif + +/*** + END + ***/ + diff --git a/src/sys/include/net/netif.h b/src/sys/include/net/netif.h new file mode 100644 index 0000000..545ec7e --- /dev/null +++ b/src/sys/include/net/netif.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_NETIF_H__ +#define __LWIP_NETIF_H__ + +#include "net/opt.h" + +#include "net/err.h" + +#include "net/ipv4/ip_addr.h" +#include "net/ipv4/inet.h" + +#include "net/pbuf.h" + + +struct netif { + struct netif *next; + uInt8 num; + struct ip_addr ip_addr; + struct ip_addr netmask; /* netmask in network byte order */ + struct ip_addr gw; + char hwaddr[6]; + + /* This function is called by the network device driver + when it wants to pass a packet to the TCP/IP stack. */ + err_t (* input)(struct pbuf *p, struct netif *inp); + + /* The following two fields should be filled in by the + initialization function for the device driver. */ + + char name[2]; + /* This function is called by the IP module when it wants + to send a packet on the interface. */ + err_t (* output)(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); + err_t (* linkoutput)(struct netif *netif, struct pbuf *p); + + /* This field can be set bu the device driver and could point + to state information for the device. */ + void *state; +}; + +/* The list of network interfaces. */ +extern struct netif *netif_list; +extern struct netif *netif_default; + + +/* netif_init() must be called first. */ +void netif_init(); + +struct netif *netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask, + struct ip_addr *gw, + void (* init)(struct netif *netif), + err_t (* input)(struct pbuf *p, struct netif *netif)); + +/* Returns a network interface given its name. The name is of the form + "et0", where the first two letters are the "name" field in the + netif structure, and the digit is in the num field in the same + structure. */ +struct netif *netif_find(char *name); + +void netif_set_default(struct netif *netif); + +void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr); +void netif_set_netmask(struct netif *netif, struct ip_addr *netmast); +void netif_set_gw(struct netif *netif, struct ip_addr *gw); + +#endif /* __LWIP_NETIF_H__ */ diff --git a/src/sys/include/net/opt.h b/src/sys/include/net/opt.h new file mode 100644 index 0000000..71d42c3 --- /dev/null +++ b/src/sys/include/net/opt.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_OPT_H__ +#define __LWIP_OPT_H__ + +#include "net/lwipopts.h" + +/* Define some handy default values for configuration parameters. */ + +#ifndef ICMP_TTL +#define ICMP_TTL 255 +#endif + +#ifndef UDP_TTL +#define UDP_TTL 255 +#endif + +#ifndef TCP_TTL +#define TCP_TTL 255 +#endif + +#ifndef TCP_MSS +#define TCP_MSS 128 /* A *very* conservative default. */ +#endif + +#ifndef TCP_WND +#define TCP_WND 2048 +#endif + +#ifndef TCP_MAXRTX +#define TCP_MAXRTX 12 +#endif + +#ifndef TCP_SYNMAXRTX +#define TCP_SYNMAXRTX 6 +#endif + +#ifndef MEM_ALIGNMENT +#define MEM_ALIGNMENT 1 +#endif + +#ifndef PBUF_POOL_SIZE +#define PBUF_POOL_SIZE 16 +#endif + +#ifndef PBUF_POOL_BUFSIZE +#define PBUF_POOL_BUFSIZE 128 +#endif + +#ifndef PBUF_LINK_HLEN +#define PBUF_LINK_HLEN 0 +#endif + +#ifndef LWIP_UDP +#define LWIP_UDP 1 +#endif + +#ifndef LWIP_TCP +#define LWIP_TCP 1 +#endif + +#endif /* __LWIP_OPT_H__ */ + + + diff --git a/src/sys/include/net/pbuf.h b/src/sys/include/net/pbuf.h new file mode 100644 index 0000000..293ac35 --- /dev/null +++ b/src/sys/include/net/pbuf.h @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +/*-----------------------------------------------------------------------------------*/ +#ifndef __LWIP_PBUF_H__ +#define __LWIP_PBUF_H__ + +#include "net/debug.h" +#include "net/arch.h" + + +#define PBUF_TRANSPORT_HLEN 20 +#define PBUF_IP_HLEN 20 + +typedef enum { + PBUF_TRANSPORT, + PBUF_IP, + PBUF_LINK, + PBUF_RAW +} pbuf_layer; + +typedef enum { + PBUF_RAM, + PBUF_ROM, + PBUF_POOL +} pbuf_flag; + +/* Definitions for the pbuf flag field (these are not the flags that + are passed to pbuf_alloc()). */ +#define PBUF_FLAG_RAM 0x00 /* Flags that pbuf data is stored in RAM. */ +#define PBUF_FLAG_ROM 0x01 /* Flags that pbuf data is stored in ROM. */ +#define PBUF_FLAG_POOL 0x02 /* Flags that the pbuf comes from the + pbuf pool. */ + +struct pbuf { + struct pbuf *next; + + /* high 4 bits, flags, low 4 bits reference count */ + uInt8 flags, ref; + void *payload; + + /* Total length of buffer + additionally chained buffers. */ + uInt16 tot_len; + /* Length of this buffer. */ + uInt16 len; + +}; + +/* pbuf_init(): + + Initializes the pbuf module. The num parameter determines how many + pbufs that should be allocated to the pbuf pool, and the size + parameter specifies the size of the data allocated to those. */ +void pbuf_init(void); + +/* pbuf_alloc(): + + Allocates a pbuf at protocol layer l. The actual memory allocated + for the pbuf is determined by the layer at which the pbuf is + allocated and the requested size (from the size parameter). The + flag parameter decides how and where the pbuf should be allocated + as follows: + + * PBUF_RAM: buffer memory for pbuf is allocated as one large + chunk. This includesprotocol headers as well. + + * RBUF_ROM: no buffer memory is allocated for the pbuf, even for + protocol headers. Additional headers must be + prepended by allocating another pbuf and chain in to + the front of the ROM pbuf. + + * PBUF_ROOL: the pbuf is allocated as a pbuf chain, with pbufs from + the pbuf pool that is allocated during pbuf_init(). */ +struct pbuf *pbuf_alloc(pbuf_layer l, uInt16 size, pbuf_flag flag); + +/* pbuf_realloc(): + + Shrinks the pbuf to the size given by the size parameter. + */ +void pbuf_realloc(struct pbuf *p, uInt16 size); + +/* pbuf_header(): + + Tries to move the p->payload pointer header_size number of bytes + upward within the pbuf. The return value is non-zero if it + fails. If so, an additional pbuf should be allocated for the header + and it should be chained to the front. */ +uInt8 pbuf_header(struct pbuf *p, Int16 header_size); + +/* pbuf_ref(): + + Increments the reference count of the pbuf p. + */ +void pbuf_ref(struct pbuf *p); + +/* pbuf_free(): + + Decrements the reference count and deallocates the pbuf if the + reference count is zero. If the pbuf is a chain all pbufs in the + chain are deallocated. */ +uInt8 pbuf_free(struct pbuf *p); + +/* pbuf_clen(): + + Returns the length of the pbuf chain. */ +uInt8 pbuf_clen(struct pbuf *p); + +/* pbuf_chain(): + + Chains pbuf t on the end of pbuf h. Pbuf h will have it's tot_len + field adjusted accordingly. Pbuf t should no be used any more after + a call to this function, since pbuf t is now a part of pbuf h. */ +void pbuf_chain(struct pbuf *h, struct pbuf *t); + +/* pbuf_dechain(): + + Picks off the first pbuf from the pbuf chain p. Returns the tail of + the pbuf chain or NULL if the pbuf p was not chained. */ +struct pbuf *pbuf_dechain(struct pbuf *p); + +#endif /* __LWIP_PBUF_H__ */ diff --git a/src/sys/include/net/sockets.h b/src/sys/include/net/sockets.h new file mode 100644 index 0000000..577a2eb --- /dev/null +++ b/src/sys/include/net/sockets.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + + +#ifndef __LWIP_SOCKETS_H__ +#define __LWIP_SOCKETS_H__ + +#include + +struct in_addr { + uInt32 s_addr; +}; + + +struct sockaddr_in { + uInt8 sin_len; + uInt8 sin_family; + uInt16 sin_port; + struct in_addr sin_addr; + char sin_zero[8]; +}; + +struct sockaddr { + uInt8 sa_len; + uInt8 sa_family; + char sa_data[14]; +}; + +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 + +#define AF_INET 2 +#define PF_INET AF_INET + +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 + +#define INADDR_ANY 0 +#define INADDR_BROADCAST 0xffffffff + +int lwip_accept(int s, struct sockaddr *addr, int *addrlen); +int lwip_bind(int s, struct sockaddr *name, int namelen); +int lwip_close(int s); +int lwip_connect(int s, struct sockaddr *name, int namelen); +int lwip_listen(int s, int backlog); +int lwip_recv(int s, void *mem, int len, unsigned int flags); +int lwip_read(int s, void *mem, int len); +int lwip_recvfrom(int s, void *mem, int len, unsigned int flags, + struct sockaddr *from, int *fromlen); +int lwip_send(int s, void *dataptr, int size, unsigned int flags); +int lwip_sendto(int s, void *dataptr, int size, unsigned int flags, + struct sockaddr *to, int tolen); +int lwip_socket(int domain, int type, int protocol); +int lwip_write(int s, void *dataptr, int size); + +#ifdef LWIP_COMPAT_SOCKETS +#define accept(a,b,c) lwip_accept(a,b,c) +#define bind(a,b,c) lwip_bind(a,b,c) +#define close(s) lwip_close(s) +#define connect(a,b,c) lwip_connect(a,b,c) +#define listen(a,b) lwip_listen(a,b) +#define recv(a,b,c,d) lwip_recv(a,b,c,d) +#define read(a,b,c) lwip_read(a,b,c) +#define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f) +#define send(a,b,c,d) lwip_send(a,b,c,d) +#define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f) +#define socket(a,b,c) lwip_socket(a,b,c) +#define write(a,b,c) lwip_write(a,b,c) +#endif /* LWIP_NO_COMPAT_SOCKETS */ + +#endif /* __LWIP_SOCKETS_H__ */ + diff --git a/src/sys/include/net/stats.h b/src/sys/include/net/stats.h new file mode 100644 index 0000000..bea1a61 --- /dev/null +++ b/src/sys/include/net/stats.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_STATS_H__ +#define __LWIP_STATS_H__ + +#include "net/opt.h" +#include "net/arch/cc.h" + +#include "net/memp.h" + +#ifdef STATS + +struct stats_proto { + uInt16 xmit; /* Transmitted packets. */ + uInt16 rexmit; /* Retransmitted packets. */ + uInt16 recv; /* Received packets. */ + uInt16 fw; /* Forwarded packets. */ + uInt16 drop; /* Dropped packets. */ + uInt16 chkerr; /* Checksum error. */ + uInt16 lenerr; /* Invalid length error. */ + uInt16 memerr; /* Out of memory error. */ + uInt16 rterr; /* Routing error. */ + uInt16 proterr; /* Protocol error. */ + uInt16 opterr; /* Error in options. */ + uInt16 err; /* Misc error. */ + uInt16 cachehit; +}; + +struct stats_mem { + uInt16 avail; + uInt16 used; + uInt16 max; + uInt16 err; + uInt16 reclaimed; +}; + +struct stats_pbuf { + uInt16 avail; + uInt16 used; + uInt16 max; + uInt16 err; + uInt16 reclaimed; + + uInt16 alloc_locked; + uInt16 refresh_locked; +}; + +struct stats_syselem { + uInt16 used; + uInt16 max; + uInt16 err; +}; + +struct stats_sys { + struct stats_syselem sem; + struct stats_syselem mbox; +}; + +struct stats_ { + struct stats_proto link; + struct stats_proto ip; + struct stats_proto icmp; + struct stats_proto udp; + struct stats_proto tcp; + struct stats_pbuf pbuf; + struct stats_mem mem; + struct stats_mem memp[MEMP_MAX]; + struct stats_sys sys; +}; + +extern struct stats_ stats; + +#endif /* STATS */ + +void stats_init(void); +#endif /* __LWIP_STATS_H__ */ + + + + diff --git a/src/sys/include/net/sys.h b/src/sys/include/net/sys.h new file mode 100644 index 0000000..62302bf --- /dev/null +++ b/src/sys/include/net/sys.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_SYS_H__ +#define __LWIP_SYS_H__ + +#include "arch/cc.h" +#include "arch/sys_arch.h" + +typedef void (* sys_timeout_handler)(void *arg); + +struct sys_timeout { + struct sys_timeout *next; + uInt16 time; + sys_timeout_handler h; + void *arg; +}; + +struct sys_timeouts { + struct sys_timeout *next; +}; + +/* sys_init() must be called before anthing else. */ +void sys_init(void); + +/* + * sys_timeout(): + * + * Schedule a timeout a specified amount of milliseconds in the + * future. When the timeout occurs, the specified timeout handler will + * be called. The handler will be passed the "arg" argument when + * called. + * + */ +void sys_timeout(uInt16 msecs, sys_timeout_handler h, void *arg); +struct sys_timeouts *sys_arch_timeouts(void); + +/* Semaphore functions. */ +sys_sem_t sys_sem_new(uInt8 count); +void sys_sem_signal(sys_sem_t sem); +uInt16 sys_arch_sem_wait(sys_sem_t sem, uInt16 timeout); +void sys_sem_free(sys_sem_t sem); + +void sys_sem_wait(sys_sem_t sem); + +/* Mailbox functions. */ +sys_mbox_t sys_mbox_new(void); +void sys_mbox_post(sys_mbox_t mbox, void *msg); +uInt16 sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, uInt16 timeout); +void sys_mbox_free(sys_mbox_t mbox); + +void sys_mbox_fetch(sys_mbox_t mbox, void **msg); + +/* Thread functions. */ +void sys_thread_new(void (* thread)(void *arg), void *arg); + +/* The following functions are used only in Unix code, and + can be omitted when porting the stack. */ +/* Returns the current time in microseconds. */ +unsigned long sys_now(void); + +#endif /* __LWIP_SYS_H__ */ diff --git a/src/sys/include/net/tcp.h b/src/sys/include/net/tcp.h new file mode 100644 index 0000000..ee58616 --- /dev/null +++ b/src/sys/include/net/tcp.h @@ -0,0 +1,401 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_TCP_H__ +#define __LWIP_TCP_H__ + +#include "net/sys.h" +#include "net/mem.h" + +#include "net/pbuf.h" +#include "net/opt.h" +//UBU +#include "net/ipv4/ip.h" +//UBU +#include "net/ipv4/icmp.h" + +#include "net/sys.h" + +#include "net/err.h" + +struct tcp_pcb; + +/* Functions for interfacing with TCP: */ + +/* Lower layer interface to TCP: */ +void tcp_init (void); /* Must be called first to + initialize TCP. */ +void tcp_tmr (void); /* Must be called every + TCP_TMR_INTERVAL + ms. (Typically 100 ms). */ +/* Application program's interface: */ +struct tcp_pcb * tcp_new (void); + +void tcp_arg (struct tcp_pcb *pcb, void *arg); +void tcp_accept (struct tcp_pcb *pcb, + err_t (* accept)(void *arg, struct tcp_pcb *newpcb, + err_t err)); +void tcp_recv (struct tcp_pcb *pcb, + err_t (* recv)(void *arg, struct tcp_pcb *tpcb, + struct pbuf *p, err_t err)); +void tcp_sent (struct tcp_pcb *pcb, + err_t (* sent)(void *arg, struct tcp_pcb *tpcb, + uInt16 len)); +void tcp_poll (struct tcp_pcb *pcb, + err_t (* poll)(void *arg, struct tcp_pcb *tpcb), + uInt8 interval); +void tcp_err (struct tcp_pcb *pcb, + void (* err)(void *arg, err_t err)); + +#define tcp_sndbuf(pcb) ((pcb)->snd_buf) + +void tcp_recved (struct tcp_pcb *pcb, uInt16 len); +err_t tcp_bind (struct tcp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port); +err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port, err_t (* connected)(void *arg, + struct tcp_pcb *tpcb, + err_t err)); +struct tcp_pcb * tcp_listen (struct tcp_pcb *pcb); +void tcp_abort (struct tcp_pcb *pcb); +err_t tcp_close (struct tcp_pcb *pcb); +err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, uInt16 len, + uInt8 copy); + +/* It is also possible to call these two functions at the right + intervals (instead of calling tcp_tmr()). */ +void tcp_slowtmr (void); +void tcp_fasttmr (void); + + +/* Only used by IP to pass a TCP segment to TCP: */ +void tcp_input (struct pbuf *p, struct netif *inp); +/* Used within the TCP code only: */ +err_t tcp_output (struct tcp_pcb *pcb); + + + + +#define TCP_SEQ_LT(a,b) ((Int32)((a)-(b)) < 0) +#define TCP_SEQ_LEQ(a,b) ((Int32)((a)-(b)) <= 0) +#define TCP_SEQ_GT(a,b) ((Int32)((a)-(b)) > 0) +#define TCP_SEQ_GEQ(a,b) ((Int32)((a)-(b)) >= 0) + +#define TCP_FIN 0x01 +#define TCP_SYN 0x02 +#define TCP_RST 0x04 +#define TCP_PSH 0x08 +#define TCP_ACK 0x10 +#define TCP_URG 0x20 + +/* Length of the TCP header, excluding options. */ +#define TCP_HLEN 20 + +#define TCP_TMR_INTERVAL 100 /* The TCP timer interval in + milliseconds. */ + +#define TCP_FAST_INTERVAL 200 /* the fine grained timeout in + milliseconds */ +#define TCP_SLOW_INTERVAL 500 /* the coarse grained timeout in + milliseconds */ +#define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */ +#define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */ + +#define TCP_OOSEQ_TIMEOUT 6 /* x RTO */ + +#define TCP_MSL 60000 /* The maximum segment lifetime in microseconds */ + +struct tcp_hdr { + PACK_STRUCT_FIELD(uInt16 src); + PACK_STRUCT_FIELD(uInt16 dest); + PACK_STRUCT_FIELD(uInt32 seqno); + PACK_STRUCT_FIELD(uInt32 ackno); + PACK_STRUCT_FIELD(uInt16 _offset_flags); + PACK_STRUCT_FIELD(uInt16 wnd); + PACK_STRUCT_FIELD(uInt16 chksum); + PACK_STRUCT_FIELD(uInt16 urgp); +} PACK_STRUCT_STRUCT; + +#define TCPH_OFFSET(hdr) (NTOHS((hdr)->_offset_flags) >> 8) +#define TCPH_FLAGS(hdr) (NTOHS((hdr)->_offset_flags) & 0xff) + +#define TCPH_OFFSET_SET(hdr, offset) (hdr)->_offset_flags = HTONS(((offset) << 8) | TCPH_FLAGS(hdr)) +#define TCPH_FLAGS_SET(hdr, flags) (hdr)->_offset_flags = HTONS((TCPH_OFFSET(hdr) << 8) | (flags)) + +#define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & TCP_FIN || \ + TCPH_FLAGS((seg)->tcphdr) & TCP_SYN)? 1: 0)) + +enum tcp_state { + CLOSED = 0, + LISTEN = 1, + SYN_SENT = 2, + SYN_RCVD = 3, + ESTABLISHED = 4, + FIN_WAIT_1 = 5, + FIN_WAIT_2 = 6, + CLOSE_WAIT = 7, + CLOSING = 8, + LAST_ACK = 9, + TIME_WAIT = 10 +}; + + +/* the TCP protocol control block */ +struct tcp_pcb { + struct tcp_pcb *next; /* for the linked list */ + + enum tcp_state state; /* TCP state */ + + void *callback_arg; + + /* Function to call when a listener has been connected. */ + err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err); + + struct ip_addr local_ip; + uInt16 local_port; + + struct ip_addr remote_ip; + uInt16 remote_port; + + /* receiver varables */ + uInt32 rcv_nxt; /* next seqno expected */ + uInt16 rcv_wnd; /* receiver window */ + + /* Timers */ + uInt16 tmr; + + /* Retransmission timer. */ + uInt8 rtime; + + uInt16 mss; /* maximum segment size */ + + uInt8 flags; +#define TF_ACK_DELAY 0x01 /* Delayed ACK. */ +#define TF_ACK_NOW 0x02 /* Immediate ACK. */ +#define TF_INFR 0x04 /* In fast recovery. */ +#define TF_RESET 0x08 /* Connection was reset. */ +#define TF_CLOSED 0x10 /* Connection was sucessfully closed. */ +#define TF_GOT_FIN 0x20 /* Connection was closed by the remote end. */ + + /* RTT estimation variables. */ + uInt16 rttest; /* RTT estimate in 500ms ticks */ + uInt32 rtseq; /* sequence number being timed */ + Int32 sa, sv; + + uInt16 rto; /* retransmission time-out */ + uInt8 nrtx; /* number of retransmissions */ + + /* fast retransmit/recovery */ + uInt32 lastack; /* Highest acknowledged seqno. */ + uInt8 dupacks; + + /* congestion avoidance/control variables */ + uInt16 cwnd; + uInt16 ssthresh; + + /* sender variables */ + uInt32 snd_nxt, /* next seqno to be sent */ + snd_max, /* Highest seqno sent. */ + snd_wnd, /* sender window */ + snd_wl1, snd_wl2, + snd_lbb; + + uInt16 snd_buf; /* Avaliable buffer space for sending. */ + uInt8 snd_queuelen; + + /* Function to be called when more send buffer space is avaliable. */ + err_t (* sent)(void *arg, struct tcp_pcb *pcb, uInt16 space); + uInt16 acked; + + /* Function to be called when (in-sequence) data has arrived. */ + err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); + struct pbuf *recv_data; + + /* Function to be called when a connection has been set up. */ + err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err); + + /* Function which is called periodically. */ + err_t (* poll)(void *arg, struct tcp_pcb *pcb); + + /* Function to be called whenever a fatal error occurs. */ + void (* errf)(void *arg, err_t err); + + uInt8 polltmr, pollinterval; + + /* These are ordered by sequence number: */ + struct tcp_seg *unsent; /* Unsent (queued) segments. */ + struct tcp_seg *unacked; /* Sent but unacknowledged segments. */ +#if TCP_QUEUE_OOSEQ + struct tcp_seg *ooseq; /* Received out of sequence segments. */ +#endif /* TCP_QUEUE_OOSEQ */ + +}; + +struct tcp_pcb_listen { + struct tcp_pcb_listen *next; /* for the linked list */ + + enum tcp_state state; /* TCP state */ + + void *callback_arg; + + /* Function to call when a listener has been connected. */ + void (* accept)(void *arg, struct tcp_pcb *newpcb); + + struct ip_addr local_ip; + uInt16 local_port; +}; + +/* This structure is used to repressent TCP segments. */ +struct tcp_seg { + struct tcp_seg *next; /* used when putting segements on a queue */ + struct pbuf *p; /* buffer containing data + TCP header */ + void *dataptr; /* pointer to the TCP data in the pbuf */ + uInt16 len; /* the TCP length of this segment */ + struct tcp_hdr *tcphdr; /* the TCP header */ +}; + +/* Internal functions and global variables: */ +struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb); +void tcp_pcb_purge(struct tcp_pcb *pcb); +void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb); + +uInt8 tcp_segs_free(struct tcp_seg *seg); +uInt8 tcp_seg_free(struct tcp_seg *seg); +struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg); + +#define tcp_ack(pcb) if((pcb)->flags & TF_ACK_DELAY) { \ + (pcb)->flags |= TF_ACK_NOW; \ + tcp_output(pcb); \ + } else { \ + (pcb)->flags |= TF_ACK_DELAY; \ + } + +#define tcp_ack_now(pcb) (pcb)->flags |= TF_ACK_NOW; \ + tcp_output(pcb) + +err_t tcp_send_ctrl(struct tcp_pcb *pcb, uInt8 flags); +err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, uInt16 len, + uInt8 flags, uInt8 copy, + uInt8 *optdata, uInt8 optlen); + +void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg); + +void tcp_rst(uInt32 seqno, uInt32 ackno, + struct ip_addr *local_ip, struct ip_addr *remote_ip, + uInt16 local_port, uInt16 remote_port); + +uInt32 tcp_next_iss(void); + +extern uInt32 tcp_ticks; + +#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG +void tcp_debug_print(struct tcp_hdr *tcphdr); +void tcp_debug_print_flags(uInt8 flags); +void tcp_debug_print_state(enum tcp_state s); +void tcp_debug_print_pcbs(void); +int tcp_pcbs_sane(void); +#else +#define tcp_pcbs_sane() 1 +#endif /* TCP_DEBUG */ + + +/* The TCP PCB lists. */ +extern struct tcp_pcb_listen *tcp_listen_pcbs; /* List of all TCP PCBs in LISTEN state. */ +extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a + state in which they accept or send + data. */ +extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ + +extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ + +/* Axoims about the above lists: + 1) Every TCP PCB that is not CLOSED is in one of the lists. + 2) A PCB is only in one of the lists. + 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. + 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. +*/ + +/* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB + with a PCB list or removes a PCB from a list, respectively. */ +#ifdef LWIP_DEBUG +#define TCP_REG(pcbs, npcb) do {\ + DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \ + for(tcp_tmp_pcb = *pcbs; \ + tcp_tmp_pcb != NULL; \ + tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \ + } \ + ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \ + npcb->next = *pcbs; \ + ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \ + *pcbs = npcb; \ + ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ + } while(0) +#define TCP_RMV(pcbs, npcb) do { \ + ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \ + DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \ + if(*pcbs == npcb) { \ + *pcbs = (*pcbs)->next; \ + } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \ + tcp_tmp_pcb->next = npcb->next; \ + break; \ + } \ + } \ + npcb->next = NULL; \ + ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ + DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \ + } while(0) + +#else /* LWIP_DEBUG */ +#define TCP_REG(pcbs, npcb) do { \ + npcb->next = *pcbs; \ + *pcbs = npcb; \ + } while(0) +#define TCP_RMV(pcbs, npcb) do { \ + if(*pcbs == npcb) { \ + *pcbs = (*pcbs)->next; \ + } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \ + tcp_tmp_pcb->next = npcb->next; \ + break; \ + } \ + } \ + npcb->next = NULL; \ + } while(0) +#endif /* LWIP_DEBUG */ +#endif /* __LWIP_TCP_H__ */ + + + diff --git a/src/sys/include/net/tcpip.h b/src/sys/include/net/tcpip.h new file mode 100644 index 0000000..1b74d57 --- /dev/null +++ b/src/sys/include/net/tcpip.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_TCPIP_H__ +#define __LWIP_TCPIP_H__ + +#include "net/api_msg.h" +#include "net/pbuf.h" + +void tcpip_init(void (* tcpip_init_done)(void *), void *arg); +void tcpip_apimsg(struct api_msg *apimsg); +err_t tcpip_input(struct pbuf *p, struct netif *inp); + +enum tcpip_msg_type { + TCPIP_MSG_API, + TCPIP_MSG_INPUT +}; + +struct tcpip_msg { + enum tcpip_msg_type type; + sys_sem_t *sem; + union { + struct api_msg *apimsg; + struct { + struct pbuf *p; + struct netif *netif; + } inp; + } msg; +}; + + +#endif /* __LWIP_TCPIP_H__ */ diff --git a/src/sys/include/net/udp.h b/src/sys/include/net/udp.h new file mode 100644 index 0000000..c4c8693 --- /dev/null +++ b/src/sys/include/net/udp.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __LWIP_UDP_H__ +#define __LWIP_UDP_H__ + +#include "net/arch.h" + +#include "net/pbuf.h" +//UBU +#include "net/ipv4/inet.h" +//UBU +#include "net/ipv4/ip.h" + +#include "net/err.h" + +#define UDP_HLEN 8 + +struct udp_hdr { + PACK_STRUCT_FIELD(uInt16 src); + PACK_STRUCT_FIELD(uInt16 dest); /* src/dest UDP ports */ + PACK_STRUCT_FIELD(uInt16 len); + PACK_STRUCT_FIELD(uInt16 chksum); +} PACK_STRUCT_STRUCT; + +#define UDP_FLAGS_NOCHKSUM 0x01 +#define UDP_FLAGS_UDPLITE 0x02 + +struct udp_pcb { + struct udp_pcb *next; + + struct ip_addr local_ip, remote_ip; + uInt16 local_port, remote_port; + + uInt8 flags; + uInt16 chksum_len; + + void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p, + struct ip_addr *addr, uInt16 port); + void *recv_arg; +}; + +/* The following functions is the application layer interface to the + UDP code. */ +struct udp_pcb * udp_new (void); +void udp_remove (struct udp_pcb *pcb); +err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port); +err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr, + uInt16 port); +void udp_recv (struct udp_pcb *pcb, + void (* recv)(void *arg, struct udp_pcb *upcb, + struct pbuf *p, + struct ip_addr *addr, + uInt16 port), + void *recv_arg); +err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); + +#define udp_flags(pcb) ((pcb)->flags) +#define udp_setflags(pcb, f) ((pcb)->flags = (f)) + + +/* The following functions is the lower layer interface to UDP. */ +uInt8 udp_lookup (struct ip_hdr *iphdr, struct netif *inp); +void udp_input (struct pbuf *p, struct netif *inp); +void udp_init (void); + + +#endif /* __LWIP_UDP_H__ */ + + diff --git a/src/sys/include/netif/arp.h b/src/sys/include/netif/arp.h new file mode 100644 index 0000000..d799678 --- /dev/null +++ b/src/sys/include/netif/arp.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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 Swedish Institute + * of Computer Science and its contributors. + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + * + */ + +#ifndef __NETIF_ARP_H__ +#define __NETIF_ARP_H__ + +#include "net/pbuf.h" +#include "net/ipv4/ip_addr.h" +#include "net/netif.h" + +struct eth_addr { + PACK_STRUCT_FIELD(uInt8 addr[6]); +} PACK_STRUCT_STRUCT; + +struct eth_hdr { + PACK_STRUCT_FIELD(struct eth_addr dest); + PACK_STRUCT_FIELD(struct eth_addr src); + PACK_STRUCT_FIELD(uInt16 type); +} PACK_STRUCT_STRUCT; + +#define ARP_TMR_INTERVAL 10000 + +#define ETHTYPE_ARP 0x0806 +#define ETHTYPE_IP 0x0800 + +/* Initializes ARP. */ +void arp_init(void); + +/* The arp_tmr() function should be called every ARP_TMR_INTERVAL + microseconds (10 seconds). This function is responsible for + expiring old entries in the ARP table. */ +void arp_tmr(void); + +/* Should be called for all incoming packets of IP kind. The function + does not alter the packet in any way, it just updates the ARP + table. After this function has been called, the normal TCP/IP stack + input function should be called. */ +void arp_ip_input(struct netif *netif, struct pbuf *p); + +/* Should be called for incoming ARP packets. The pbuf in the argument + is freed by this function. If the function returns a pbuf (i.e., + returns non-NULL), that pbuf constitutes an ARP reply and should be + sent out on the Ethernet. */ +struct pbuf *arp_arp_input(struct netif *netif, struct eth_addr *ethaddr, + struct pbuf *p); + +/* arp_loopup() is called to do an IP address -> Ethernet address + translation. If the function returns NULL, there is no mapping and + the arp_query() function should be called. */ +struct eth_addr *arp_lookup(struct ip_addr *ipaddr); + +/* Constructs an ARP query packet for the given IP address. The + function returns a pbuf that contains the reply and that should be + sent out on the Ethernet. */ +struct pbuf *arp_query(struct netif *netif, struct eth_addr *ethaddr, + struct ip_addr *ipaddr); + +#endif /* __NETIF_ARP_H__ */ diff --git a/src/sys/include/netif/ethernetif.h b/src/sys/include/netif/ethernetif.h new file mode 100644 index 0000000..5ea4e5d --- /dev/null +++ b/src/sys/include/netif/ethernetif.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __NETIF_ETHERNETIF_H__ +#define __NETIF_ETHERNETIF_H__ + +#include "net/netif.h" + +void ethernetif_init(struct netif *netif); + +#endif /* __NETIF_ETHERNETIF_H__ */ diff --git a/src/sys/include/netif/loopif.h b/src/sys/include/netif/loopif.h new file mode 100644 index 0000000..fbbf744 --- /dev/null +++ b/src/sys/include/netif/loopif.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __NETIF_LOOPIF_H__ +#define __NETIF_LOOPIF_H__ + +#include "net/netif.h" + +void loopif_init(struct netif *netif); + +#endif /* __NETIF_LOOPIF_H__ */ diff --git a/src/sys/include/netif/tcpdump.h b/src/sys/include/netif/tcpdump.h new file mode 100644 index 0000000..d2d6afc --- /dev/null +++ b/src/sys/include/netif/tcpdump.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __NETIF_TCPDUMP_H__ +#define __NETIF_TCPDUMP_H__ + +#include "net/pbuf.h" + +void tcpdump_init(void); +void tcpdump(struct pbuf *p); + +#endif /* __NETIF_TCPDUMP_H__ */ diff --git a/src/sys/include/objgfx/ogDisplay_VESA.h b/src/sys/include/objgfx/ogDisplay_VESA.h new file mode 100755 index 0000000..00b8e4a --- /dev/null +++ b/src/sys/include/objgfx/ogDisplay_VESA.h @@ -0,0 +1,95 @@ +#ifndef OGDISPLAY_VESA_H +#define OGDISPLAY_VESA_H + +#include "objgfx30.h" + +struct TMode_Rec { + uInt16 ModeAttributes __attribute__((packed)); + uInt8 WindowAFlags __attribute__((packed)); + uInt8 WindowBFlags __attribute__((packed)); + uInt16 Granularity __attribute__((packed)); + uInt16 WindowSize __attribute__((packed)); + uInt16 WindowASeg __attribute__((packed)); + uInt16 WindowBSeg __attribute__((packed)); + void* BankSwitch __attribute__((packed)); + uInt16 BytesPerLine __attribute__((packed)); + uInt16 xRes __attribute__((packed)); + uInt16 yRes __attribute__((packed)); + uInt8 CharWidth __attribute__((packed)); + uInt8 CharHeight __attribute__((packed)); + uInt8 NumBitPlanes __attribute__((packed)); + uInt8 BitsPerPixel __attribute__((packed)); + uInt8 NumberOfBanks __attribute__((packed)); + uInt8 MemoryModel __attribute__((packed)); + uInt8 BankSize __attribute__((packed)); + uInt8 NumOfImagePages __attribute__((packed)); + uInt8 Reserved __attribute__((packed)); + // Direct colour fields (required for Direct/6 and YUV/7 memory models + uInt8 RedMaskSize __attribute__((packed)); + uInt8 RedFieldPosition __attribute__((packed)); + uInt8 GreenMaskSize __attribute__((packed)); + uInt8 GreenFieldPosition __attribute__((packed)); + uInt8 BlueMaskSize __attribute__((packed)); + uInt8 BlueFieldPosition __attribute__((packed)); + uInt8 AlphaMaskSize __attribute__((packed)); + uInt8 AlphaFieldPosition __attribute__((packed)); + uInt8 DirectColourMode __attribute__((packed)); + // VESA 2.0 specific fields + uInt32 physBasePtr __attribute__((packed)); + void* OffScreenMemOffset __attribute__((packed)); + uInt16 OffScreenMemSize __attribute__((packed)); + uInt8 paddington[461] __attribute__((packed)); +}; + +struct TVESA_Rec { + char VBESignature[4] __attribute__((packed)); + uInt8 minVersion __attribute__((packed)); + uInt8 majVersion __attribute__((packed)); + uInt32 OEMStringPtr __attribute__((packed)); + uInt32 Capabilities __attribute__((packed)); + uInt32 VideoModePtr __attribute__((packed)); + uInt16 TotalMemory __attribute__((packed)); + // VESA 2.0 specific fields + uInt16 OEMSoftwareRev __attribute__((packed)); + uInt32 OEMVendorNamePtr __attribute__((packed)); + uInt32 OEMProductNamePtr __attribute__((packed)); + uInt32 OEMProductRevPtr __attribute__((packed)); + uInt8 paddington[474] __attribute__((packed)); +}; + +class ogDisplay_VESA : public ogSurface { + protected: + uInt16 ScreenSelector; + TVESA_Rec* VESARec; + TMode_Rec* ModeRec; + bool InGraphics; + uInt16 findMode(uInt32, uInt32, uInt32); + void getModeInfo(uInt16); + void getVESAInfo(void); + void setMode(uInt16); + virtual uInt32 rawGetPixel(uInt32, uInt32); + virtual void rawSetPixel(uInt32, uInt32, uInt32); + virtual void rawLine(uInt32, uInt32, uInt32, uInt32, uInt32); + void setPal(void); + public: + ogDisplay_VESA(void); + virtual bool ogAvail(void); + virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32); + virtual void ogClear(uInt32); + virtual bool ogClone(ogSurface&); + virtual void ogCopyLineTo(uInt32, uInt32, const void *, uInt32); + virtual void ogCopyLineFrom(uInt32, uInt32, void *, uInt32); + virtual void ogCopyPal(ogSurface&); + virtual bool ogCreate(uInt32, uInt32, ogPixelFmt); + virtual uInt32 ogGetPixel(int32, int32); + virtual void * ogGetPtr(uInt32, uInt32); + virtual void ogHLine(int32, int32, int32, uInt32); + virtual bool ogLoadPal(const char *); + virtual void ogSetPixel(int32, int32, uInt32); + virtual void ogSetRGBPalette(uInt8, uInt8, uInt8, uInt8); + virtual void ogVFlip(void); + virtual void ogVLine(int32, int32, int32, uInt32); + virtual ~ogDisplay_VESA(void); +}; // ogDisplay_VESA + +#endif diff --git a/src/sys/include/pci/hd.h b/src/sys/include/pci/hd.h new file mode 100644 index 0000000..7492fd4 --- /dev/null +++ b/src/sys/include/pci/hd.h @@ -0,0 +1,85 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _HD_H +#define _HD_H + +#include + +#define hdData 0x0 +#define hdError 0x1 +#define hdSecCount 0x2 +#define hdSecNum 0x3 +#define hdCylLow 0x4 +#define hdCylHi 0x5 +#define hdHead 0x6 +#define hdStat 0x7 +#define hdCmd 0x7 + + +struct driveInfo { + struct driveDiskLabel *diskLabel; + char hdSector[512]; + char hdEnable; + char hdDev; + char hdFlags; + char hdShift; + long hdMask; + long hdMulti; + long hdPort; + long hdSize; + long hdCalc; + long parOffset; + }; + +void initHardDisk(); +void hdWrite(struct driveInfo *hdd,void *,uInt32,uInt32); +void hdRead(struct driveInfo *hdd,void *,uInt32,uInt32); +int hdReset(); +int hdIoctl(); +int hdStart(); +int hdStop(); +int hdStandby(); +int hdInit(struct deviceNode *dev); + +extern struct driveInfo *hdd0; +extern struct driveInfo *hdd1; +extern struct driveInfo *hdd2; +extern struct driveInfo *hdd3; + +#endif + +/*** + $Log$ + Revision 1.5 2004/05/21 15:05:07 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/pci/lnc.h b/src/sys/include/pci/lnc.h new file mode 100644 index 0000000..546c7ce --- /dev/null +++ b/src/sys/include/pci/lnc.h @@ -0,0 +1,194 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _LNC_H +#define _LNC_H + +#include + +#define NDESC(len2) (1 << len2) +#define NORMAL 0 +#define MEM_SLEW 8 +#define TRANSBUFSIZE 1518 +#define RECVBUFSIZE 1518 +#define NRDRE 3 +#define NTDRE 3 +#define ETHER_ADDR_LEN 6 +#define NE2100_IOSIZE 24 +#define PCNET_RDP 0x10 /* Register Data Port */ +#define PCNET_RAP 0x12 /* Register Address Port */ +#define PCNET_RESET 0x14 +#define PCNET_BDP 0x16 +#define PCNET_VSW 0x18 +#define NE2100 2 + +/* mem_mode values */ +#define DMA_FIXED 1 +#define DMA_MBUF 2 +#define SHMEM 4 + + +/********** Chip Types **********/ +#define UNKNOWN 0 /* Unknown */ +#define LANCE 1 /* Am7990 */ +#define C_LANCE 2 /* Am79C90 */ +#define PCnet_ISA 3 /* Am79C960 */ +#define PCnet_ISAplus 4 /* Am79C961 */ +#define PCnet_ISA_II 5 /* Am79C961A */ +#define PCnet_32 6 /* Am79C965 */ +#define PCnet_PCI 7 /* Am79C970 */ +#define PCnet_PCI_II 8 /* Am79C970A */ +#define PCnet_FAST 9 /* Am79C971 */ +#define PCnet_FASTplus 10 /* Am79C972 */ +#define PCnet_Home 11 /* Am79C978 */ + +/******** AM7990 Specifics **************/ +#define CSR0 0x0000 +#define CSR1 1 +#define CSR2 2 +#define CSR3 3 +#define CSR88 88 +#define CSR89 89 + +#define ERR 0x8000 +#define BABL 0x4000 +#define CERR 0x2000 +#define MISS 0x1000 +#define MERR 0x0800 +#define RINT 0x0400 +#define TINT 0x0200 +#define IDON 0x0100 +#define INTR 0x0080 +#define INEA 0x0040 +#define RXON 0x0020 +#define TXON 0x0010 +#define TDMD 0x0008 +#define STOP 0x0004 +#define STRT 0x0002 +#define INIT 0x0001 + + +/* CSR88-89: Chip ID masks */ +#define AMD_MASK 0x003 +#define PART_MASK 0xffff +#define Am79C960 0x0003 +#define Am79C961 0x2260 +#define Am79C961A 0x2261 +#define Am79C965 0x2430 +#define Am79C970 0x0242 +#define Am79C970A 0x2621 +#define Am79C971 0x2623 +#define Am79C972 0x2624 +#define Am79C973 0x2625 +#define Am79C978 0x2626 + +/********** Structs **********/ + + + + +struct initBlock { + uInt16 mode; /* Mode register */ + uInt8 padr[6]; /* Ethernet address */ + uInt8 ladrf[8]; /* Logical address filter (multicast) */ + uInt16 rdra; /* Low order pointer to receive ring */ + uInt16 rlen; /* High order pointer and no. rings */ + uInt16 tdra; /* Low order pointer to transmit ring */ + uInt16 tlen; /* High order pointer and no rings */ + }; + +struct mds { + uInt16 md0; + uInt16 md1; + short md2; + uInt16 md3; + }; + +struct hostRingEntry { + struct mds *md; + union { + //struct mbuf *mbuf; + char *data; + }buff; + }; + +struct arpcom { + //struct ifnet ac_if; /* network-visible interface */ + uInt8 ac_enaddr[6]; /* ethernet hardware address */ + int ac_multicnt; /* length of ac_multiaddrs list */ + void *ac_netgraph; /* ng_ether(4) netgraph node info */ + }; + +struct nicInfo { + int ident; /* Type of card */ + int ic; /* Type of ic, Am7990, Am79C960 etc. */ + int memMode; + int iobase; + int mode; /* Mode setting at initialization */ + }; + +struct lncInfo { + struct arpcom arpcom; + struct nicInfo nic; + struct hostRingEntry *recvRing; + struct hostRingEntry *transRings; + struct initBlock *initBloack; + int rap; + int rdp; + int bdp; + int nrdre; + int ntdre; + }; + +extern struct lncInfo *lnc; + +void writeCsr(struct lncInfo *lnc, uInt16 port, uInt16 val); +uInt16 readCsr(struct lncInfo *lnc, uInt16 port); +void writeBcr(struct lncInfo *lnc, uInt16 port, uInt16 val); +uInt16 readBcr(struct lncInfo *lnc, uInt16 port); + +void initLNC(); +int probe(struct lncInfo *lnc); +int lanceProbe(struct lncInfo *lnc); +int lncAttach(struct lncInfo *lnc,int unit); + + +void lncInt(); +void _lncInt(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:05:07 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/pci/pci.h b/src/sys/include/pci/pci.h new file mode 100644 index 0000000..47812a4 --- /dev/null +++ b/src/sys/include/pci/pci.h @@ -0,0 +1,93 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _PCI_H +#define _PCI_H + +#include + + +struct pciConfig { + uInt16 vendorId; + uInt16 deviceId; + + uInt16 command; + uInt16 status; + + uInt8 revisionId; + uInt8 interface; + uInt8 subClass; + uInt8 baseClass; + + uInt8 cacheLineSize; + uInt8 latencyTimer; + uInt8 headerType; + uInt8 bist; + + /* device info */ + uInt8 bus; + uInt8 dev; + uInt8 func; + uInt8 irq; + + /* base registers */ + uInt32 base[6]; + uInt32 size[6]; + + uInt16 subsysVendor; + uInt16 subsys; + + }; + +struct confadd { + uInt8 reg:8; + uInt8 func:3; + uInt8 dev:5; + uInt8 bus:8; + uInt8 rsvd:7; + uInt8 enable:1; + }; + +#define countof(a) (sizeof(a) / sizeof(a[0])) + +int pciInit(); +bool pciProbe(int bus,int dev,int func,struct pciConfig *cfg); +uInt32 pciRead(int bus, int dev, int func, int reg, int bytes); +void pciWrite(int bus,int dev,int func,int reg,uInt32 v,int bytes); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:05:07 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sde/ogDisplay_UbixOS.h b/src/sys/include/sde/ogDisplay_UbixOS.h new file mode 100755 index 0000000..fa8022a --- /dev/null +++ b/src/sys/include/sde/ogDisplay_UbixOS.h @@ -0,0 +1,87 @@ +#ifndef OGDISPLAY_UBIXOS_H +#define OGDISPLAY_UBIXOS_H + +#include + +struct ogModeInfo { + uInt16 modeAttributes __attribute__((packed)); + uInt8 windowAFlags __attribute__((packed)); + uInt8 windowBFlags __attribute__((packed)); + uInt16 granularity __attribute__((packed)); + uInt16 windowSize __attribute__((packed)); + uInt16 windowASeg __attribute__((packed)); + uInt16 windowBSeg __attribute__((packed)); + void* bankSwitch __attribute__((packed)); + uInt16 bytesPerLine __attribute__((packed)); + uInt16 xRes __attribute__((packed)); + uInt16 yRes __attribute__((packed)); + uInt8 charWidth __attribute__((packed)); + uInt8 charHeight __attribute__((packed)); + uInt8 numBitPlanes __attribute__((packed)); + uInt8 bitsPerPixel __attribute__((packed)); + uInt8 numberOfBanks __attribute__((packed)); + uInt8 memoryModel __attribute__((packed)); + uInt8 bankSize __attribute__((packed)); + uInt8 numOfImagePages __attribute__((packed)); + uInt8 reserved __attribute__((packed)); + // Direct colour fields (required for Direct/6 and YUV/7 memory models + uInt8 redMaskSize __attribute__((packed)); + uInt8 redFieldPosition __attribute__((packed)); + uInt8 greenMaskSize __attribute__((packed)); + uInt8 greenFieldPosition __attribute__((packed)); + uInt8 blueMaskSize __attribute__((packed)); + uInt8 blueFieldPosition __attribute__((packed)); + uInt8 alphaMaskSize __attribute__((packed)); + uInt8 alphaFieldPosition __attribute__((packed)); + uInt8 directColourMode __attribute__((packed)); + // VESA 2.0 specific fields + uInt32 physBasePtr __attribute__((packed)); + void* offScreenMemOffset __attribute__((packed)); + uInt16 offScreenMemSize __attribute__((packed)); + uInt8 paddington[461] __attribute__((packed)); +}; + +struct ogVESAInfo { + char VBESignature[4] __attribute__((packed)); + uInt8 minVersion __attribute__((packed)); + uInt8 majVersion __attribute__((packed)); + uInt32 OEMStringPtr __attribute__((packed)); + uInt32 capabilities __attribute__((packed)); + uInt32 videoModePtr __attribute__((packed)); + uInt16 totalMemory __attribute__((packed)); + // VESA 2.0 specific fields + uInt16 OEMSoftwareRev __attribute__((packed)); + uInt32 OEMVendorNamePtr __attribute__((packed)); + uInt32 OEMProductNamePtr __attribute__((packed)); + uInt32 OEMProductRevPtr __attribute__((packed)); + uInt8 paddington[474] __attribute__((packed)); +}; + + +class ogDisplay_UbixOS : public ogSurface { + protected: + void * pages[2]; + uInt32 activePage; + uInt32 visualPage; + ogVESAInfo * VESAInfo; + ogModeInfo * modeInfo; + + uInt16 FindMode(uInt32, uInt32, uInt32); + void GetModeInfo(uInt16); + void GetVESAInfo(void); + void SetMode(uInt16); + void SetPal(void); + public: + ogDisplay_UbixOS(void); + virtual bool ogAlias(ogSurface&, uInt32, uInt32, uInt32, uInt32); + virtual bool ogClone(ogSurface&); + virtual void ogCopyPalette(ogSurface&); + virtual bool ogCreate(uInt32, uInt32, ogPixelFmt); + virtual bool ogLoadPalette(const char *); + virtual void ogSetPalette(const ogRGBA8[]); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8); + virtual void ogSetPalette(uInt8, uInt8, uInt8, uInt8, uInt8); + virtual ~ogDisplay_UbixOS(void); +}; // ogDisplay_UbixOS + +#endif diff --git a/src/sys/include/sde/sde.h b/src/sys/include/sde/sde.h new file mode 100644 index 0000000..0b27d5d --- /dev/null +++ b/src/sys/include/sde/sde.h @@ -0,0 +1,55 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _SDE_H +#define _SDE_H + +#include + +#define registerWindow 1 +#define windowReady 2 +#define drawWindow 3 +#define killWindow 4 + +#ifdef __cplusplus +extern "C" +#endif +void sdeThread(); + +#ifdef __cplusplus +extern "C" +#endif +void sysSDE(uInt32 cmd,void *ptr); + +struct sdeWindows { + struct sdeWindows *next; + struct sdeWindows *prev; + void *buf; + pidType pid; + uInt8 status; + }; + +extern struct sdeWindows *windows; + +#endif + diff --git a/src/sys/include/stdarg.h b/src/sys/include/stdarg.h new file mode 100644 index 0000000..ab45df4 --- /dev/null +++ b/src/sys/include/stdarg.h @@ -0,0 +1,57 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _STDARG_H +#define _STDARG_H + +typedef char *vaList[1]; + +#define vaStart(ap, parm) ((ap)[0] = (char *) &parm \ + + ((sizeof(parm) + sizeof(int) - 1) & ~(sizeof(int) - 1)), (void) 0) + +#define vaArg(ap, type) ((ap)[0] += \ + ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)), \ + (*(type *) ((ap)[0] \ + - ((sizeof(type) + sizeof(int) - 1) & ~(sizeof(int) - 1)) ))) + +#define vaEnd(ap) ((ap)[0] = 0, (void) 0) + + +int vsprintf(char *buf, const char *fmt, vaList args); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:22:35 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/string.h b/src/sys/include/string.h new file mode 100644 index 0000000..4900e01 --- /dev/null +++ b/src/sys/include/string.h @@ -0,0 +1,57 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _STRING_H +#define _STRING_H + +#include + +void * kmemcpy(void * dst, const void * src, size_t length); +void *kmemset(void * dst, int c, size_t length); +int kstrlen(const char * string); +int kstrcmp(char *, char *); + +int sprintf(char * str, const char * format, ...); + +#endif + +/*** + $Log$ + Revision 1.3 2004/06/04 13:29:56 reddawg + libc: modified mkdir(); interface + kpanic: kPanic(); now says kPanic: %s + system: now reboots when receives message for reboot + also when command start sde is received by system the STD is started + + Revision 1.2 2004/05/21 15:22:35 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/_types.h b/src/sys/include/sys/_types.h new file mode 100644 index 0000000..61c9172 --- /dev/null +++ b/src/sys/include/sys/_types.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef __TYPES_H +#define __TYPES_H + +#include + +typedef unsigned long __clock_t; +typedef long __time_t; + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/cdefs.h b/src/sys/include/sys/cdefs.h new file mode 100644 index 0000000..11580f2 --- /dev/null +++ b/src/sys/include/sys/cdefs.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _CDEFS_H +#define _CDRES_H + +#include + +#define __dead2 __attribute__((__noreturn__)) + + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/device.h b/src/sys/include/sys/device.h new file mode 100644 index 0000000..00e83e2 --- /dev/null +++ b/src/sys/include/sys/device.h @@ -0,0 +1,81 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DEVICE_H +#define _DEVICE_H + +#include + +struct deviceNode { + struct deviceNode *prev; + struct deviceNode *next; + struct deviceInterface *devInfo; + char type;; + int minor; + uInt32 size; + }; + +struct deviceInterface { + int major; + void *info; + void (*read)(void *,void *,uInt32,uInt32); + void (*write)(void *,void *,uInt32,uInt32); + void (*reset)(void *); + int (*init)(void *); + void (*ioctl)(void *); + void (*stop)(void *); + void (*start)(void *); + void (*standby)(void *); + }; + + +int deviceAdd(int,char,struct deviceInterface *); +struct deviceNode *deviceFind(int major,int minor); +int deviceRemove(struct deviceNode *); +#endif + +/*** + $Log$ + Revision 1.11 2004/05/22 02:40:04 ionix + + + fixed typo in device.h and initialized previous in device.c :) + + Revision 1.10 2004/05/22 02:34:03 ionix + + + Added proto + + Revision 1.9 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ + diff --git a/src/sys/include/sys/device.old.h b/src/sys/include/sys/device.old.h new file mode 100644 index 0000000..ecd8cb2 --- /dev/null +++ b/src/sys/include/sys/device.old.h @@ -0,0 +1,58 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _DEVICE_H +#define _DEVICE_H + +#include + +struct device { + struct net *net; + uInt16 ioAddr; + uInt32 irq; + struct ei_device *priv; + uInt32 mtu; + }; + +struct net { + char mac[6]; + char broadcast[6]; + }; + +struct ei_device { + int txStartPage; + int rxStartPage; + int stopPage; + int currentPage; + uInt16 word16; + uInt32 pingPong; + int tx1; + int tx2; + }; + +#endif + +/*** + END + ***/ + diff --git a/src/sys/include/sys/dma.h b/src/sys/include/sys/dma.h new file mode 100644 index 0000000..c69b025 --- /dev/null +++ b/src/sys/include/sys/dma.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DMA_H +#define _DMA_H + +#include + +void dmaXfer(uInt8 channel,uInt32 address,uInt length,uInt8 read); +void _dmaXfer(uInt8 dmaChannel,uInt8 page,uInt offset,uInt length,uInt8 mode); + +#endif + +/*** + $Log$ + Revision 1.3 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/driver.h b/src/sys/include/sys/driver.h new file mode 100644 index 0000000..aa12a50 --- /dev/null +++ b/src/sys/include/sys/driver.h @@ -0,0 +1,58 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _DRIVER_H +#define _DRIVER_H + +#include + + +typedef struct devMethodType devMethod; + +struct devMethodType { + }; + +struct driverType { + const char *devName; + devMethod *methods; + } + + + + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/gdt.h b/src/sys/include/sys/gdt.h new file mode 100644 index 0000000..e9af36b --- /dev/null +++ b/src/sys/include/sys/gdt.h @@ -0,0 +1,104 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _GDT_H +#define _GDT_H + +/* Descriptor Definitions */ +#define dCall 0x0C00 /* 386 Call Gate */ +#define dCode 0x1800 /* Code Segment */ +#define dData 0x1000 /* Data Segment */ +#define dInt 0x0E00 /* 386 Interrupt Gate */ +#define dLdt 0x200 /* Local Descriptor Table (LDT) */ +#define dTask 0x500 /* Task gate */ +#define dTrap 0x0F00 /* 386 Trap Gate */ +#define dTss 0x900 /* Task State Segment (TSS) */ + +/* Descriptor Options */ +#define dDpl3 0x6000 /* DPL3 or mask for DPL */ +#define dDpl2 0x4000 /* DPL2 or mask for DPL */ +#define dDpl1 0x2000 /* DPL1 or mask for DPL */ +#define dPresent 0x8000 /* Present */ +#define dNpresent 0x8000 /* Not Present */ +#define dAcc 0x100 /* Accessed (Data or Code) */ +#define dWrite 0x200 /* Writable (Data segments only) */ +#define dRead 0x200 /* Readable (Code segments only) */ +#define dBusy 0xB00 /* Busy (TSS only) was 200 */ +#define dEexdown 0x400 /* Expand down (Data segments only) */ +#define dConform 0x400 /* Conforming (Code segments only) */ +#define dBig 0x40 /* Default to 32 bit mode */ +#define dBiglim 0x80 /* Limit is in 4K units */ + +/* GDT Descriptor */ +struct gdtDescriptor { + unsigned short limitLow; /* Limit 0..15 */ + unsigned short baseLow; /* Base 0..15 */ + unsigned char baseMed; /* Base 16..23 */ + unsigned char access; /* Access Byte */ + unsigned int limitHigh:4; /* Limit 16..19 */ + unsigned int granularity:4; /* Granularity */ + unsigned char baseHigh; /* Base 24..31 */ + } __attribute__ ((packed)); + +struct gdtGate { + unsigned short offsetLow; /* Offset 0..15 */ + unsigned short selector; /* Selector */ + unsigned short access; /* Access Flags */ + unsigned short offsetHigh; /* Offset 16..31 */ + } __attribute__ ((packed)); + +union descriptorTableUnion { + struct gdtDescriptor descriptor; /* Normal descriptor */ + struct gdtGate gate; /* Gate descriptor */ + unsigned long dummy; /* Any other info */ + }; + + +#define ubixDescriptorTable(name,length) union descriptorTableUnion name[length] = +#define ubixStandardDescriptor(base, limit, control) {descriptor: \ + {(limit & 0xffff), \ + (base & 0xffff), \ + ((base >> 16) & 0xff), \ + ((control+dPresent) >> 8), \ + (limit >> 16), \ + ((control & 0xff) >> 4), \ + (base >> 24)}} +#define ubixGateDescriptor(offset, selector, control) {gate: {(offset & 0xffff), selector, \ + (control+dPresent), (offset >> 16) }} + +#endif + +/*** + $Log$ + Revision 1.3 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/idt.h b/src/sys/include/sys/idt.h new file mode 100644 index 0000000..d22c336 --- /dev/null +++ b/src/sys/include/sys/idt.h @@ -0,0 +1,71 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _IDT_H +#define _IDT_H + +#include +#include + +#define EFLAG_TF 0x100 +#define EFLAG_IF 0x200 +#define EFLAG_IOPL3 0x3000 +#define EFLAG_VM 0x20000 + +int idtInit(); +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor); +void setTaskVector(uInt8 interrupt,uInt16 controlMajor,uInt8 selector); +void intNull(); + +void _int0(); +void _int1(); +void _int2(); +void _int3(); +void _int4(); +void _int5(); +void _int6(); +void _int7(); +void _int8(); +void _int9(); +void _int10(); +void _int11(); +void _int12(); +void _int13(); +void timerInt(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/io.h b/src/sys/include/sys/io.h new file mode 100644 index 0000000..ed45a23 --- /dev/null +++ b/src/sys/include/sys/io.h @@ -0,0 +1,50 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _IO_H +#define _IO_H + +inline unsigned char inportByte(unsigned int); +inline unsigned short inportWord(unsigned int); +inline unsigned long inportDWord(unsigned int); +inline void outportByte(unsigned int,unsigned char); +inline void outportByteP(unsigned int port,unsigned char value); +inline void outportWord(unsigned int,unsigned short); +inline void outportDWord(unsigned int port,unsigned long value); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/tss.h b/src/sys/include/sys/tss.h new file mode 100644 index 0000000..a850871 --- /dev/null +++ b/src/sys/include/sys/tss.h @@ -0,0 +1,93 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TSS_H +#define _TSS_H + +struct tssStruct { + short back_link; + short back_link_reserved; + long esp0; + short ss0; + short ss0_reserved; + long esp1; + short ss1; + short ss1_reserved; + long esp2; + short ss2; + short ss2_reserved; + long cr3; + long eip; + long eflags; + long eax,ecx,edx,ebx; + long esp; + long ebp; + long esi; + long edi; + short es; + short es_reserved; + short cs; + short cs_reserved; + short ss; + short ss_reserved; + short ds; + short ds_reserved; + short fs; + short fs_reserved; + short gs; + short gs_reserved; + short ldt; + short ldt_reserved; + //long trace_bitmap; /* bits: trace 0, bitmap 16-31 */ + short trace_bitmap; + short io_map; + char io_space[8192]; + }; + +struct i387Struct { + long cwd; + long swd; + long twd; + long fip; + long fcs; + long foo; + long fos; + long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */ + }; + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/sys/video.h b/src/sys/include/sys/video.h new file mode 100644 index 0000000..d96bdce --- /dev/null +++ b/src/sys/include/sys/video.h @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _VIDEO_H +#define _VIDEO_H + +#include + +#define defaultColor 0x0F + +extern int printColor; + +void clearScreen(); +void kprint(char *string); +void backSpace(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:12:17 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixfs/ubixfs.h b/src/sys/include/ubixfs/ubixfs.h new file mode 100644 index 0000000..ad062d2 --- /dev/null +++ b/src/sys/include/ubixfs/ubixfs.h @@ -0,0 +1,141 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _UBIXFS_H +#define _UBIXFS_H + +#include +#include +#include + +#define UBIXDISKMAGIC ((uInt32)0x45) /* The disk magic number */ +#define MAXUBIXPARTITIONS 16 +#define blockSize 8 +#define blockByteSize blockSize*512 + +#define EOBC -1 + + +#define typeFile 1 +#define typeContainer 2 +#define typeDirectory 4 +#define typeDeleted 8 + +/* Start */ +struct directoryList { + char dirName[256]; + char *dirCache; + uInt32 dirBlock; + struct directoryList *next; + struct directoryList *prev; + }; + +typedef struct directoryList * dirList_t; + +dirList_t ubixFSLoadDir(char *); +/* End */ + +//Partition Information +struct ubixDiskLabel { + uInt32 magicNum; + uInt32 magicNum2; + uInt16 driveType; + uInt16 numPartitions; + struct ubixPartitions { //the partition table + uInt32 pSize; //number of sectors in partition + uInt32 pOffset; //starting sector + uInt32 pFsSize; //filesystem basic fragment size + uInt32 pBatSize; //BAT size + uInt8 pFsType; //filesystem type, see below + uInt8 pFrag; //filesystem fragments per block + } partitions[MAXUBIXPARTITIONS]; + }; + + +struct partitionInformation { + uInt32 size; //Size In Sectors + uInt32 startSector; //Base Sector Of Partition + uInt32 blockAllocationTable; //Base Sector Of BAT + uInt32 rootDirectory; //Base Sector Of Root Directory + }; + +//Block Allocation Table Entry +struct blockAllocationTableEntry { + long attributes; //Block Attributes + long realSector; //Real Sector + long nextBlock; //Sector Of Next Block + long reserved; //Reserved + }; + +//UbixFS Directory Entry +struct directoryEntry { + uInt32 startCluster; //Starting Cluster Of File + uInt32 size; //Size Of File + uInt32 creationDate; //Date Created + uInt32 lastModified; //Date Last Modified + uInt32 uid; //UID Of Owner + uInt32 gid; //GID Of Owner + uInt16 attributes; //Files Attributes + uInt16 permissions; //Files Permissions + char fileName[256]; //File Name + }; + +struct bootSect { + uInt8 jmp[4]; + uInt8 id[6]; + uInt16 version; + uInt16 tmp; + uInt16 fsStart; + uInt16 tmp2; + uInt32 krnl_start; + uInt BytesPerSector; + uInt SectersPerTrack; + uInt TotalHeads; + uInt32 TotalSectors; + uInt8 code[479]; + }; + +struct ubixFSInfo { + struct blockAllocationTableEntry *blockAllocationTable; + uInt32 batEntries; + uInt32 rootDir; + }; + +int readFile(char *file); +int writeFileByte(int ch,fileDescriptor *fd,long offset); +int openFileUbixFS(char *file,fileDescriptor *fd); +int getFreeBlocks(int count,fileDescriptor *fd); +//extern struct ubixDiskLabel *diskLabel; + +//Good Functions +void initUbixFS(struct mountPoints *mp); +int enableUbixFS(); +int readUbixFS(fileDescriptor *fd,char *data,long offset,long size); +int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size); +void syncBat(struct mountPoints *mp); +int freeBlocks(int block,fileDescriptor *fd); +int addDirEntry(struct directoryEntry *dir,fileDescriptor *fd); +void ubixFSUnlink(char *path,struct mountPoints *mp); +int ubixFSmkDir(char *dir,fileDescriptor *fd); + +#endif diff --git a/src/sys/include/ubixos/elf.h b/src/sys/include/ubixos/elf.h new file mode 100644 index 0000000..cfc2006 --- /dev/null +++ b/src/sys/include/ubixos/elf.h @@ -0,0 +1,167 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _ELF_H +#define _ELF_H + +#include + +#define elfExecutable 0x002 +#define elfLibrary 0x003 + +#define R_386_NONE 0 /* none none */ +#define R_386_32 1 /* word32 S + A */ +#define R_386_PC32 2 /* word32 S + A - P */ +#define R_386_GOT32 3 /* word32 G + A - P */ +#define R_386_PLT32 4 /* word32 L + A - P */ +#define R_386_COPY 5 /* none none */ +#define R_386_GLOB_DAT 6 /* word32 S */ +#define R_386_JMP_SLOT 7 /* word32 S */ +#define R_386_RELATIVE 8 /* word32 B + A */ +#define R_386_GOTOFF 9 /* word32 S + A - GOT */ +#define R_386_GOTPC 10 /* word32 GOT + A - P */ + + +/* Elf Types */ +#define ET_NONE 0 // No file type +#define ET_REL 1 // Relocatable file +#define ET_EXEC 2 // Executable file +#define ET_DYN 3 // Shared object file +#define ET_CORE 4 // Core file +#define ET_LOPROC 0xff00 // Processor-specific +#define ET_HIPROC 0xffff +/* End Elf Types */ + +/* Elf Machine Types */ +#define EM_NONE 0 // No machine +#define EM_M32 1 // AT&T WE 32100 +#define EM_SPARC 2 // SPARC +#define EM_386 3 // Intel 80386 +#define EM_68K 4 // Motorola 68000 +#define EM_88K 5 // Motorola 88000 +#define EM_860 7 // Intel 80860 +#define EM_MIPS 8 // MIPS RS3000 +/* End Elf Machines Types */ + +/* Elf Version */ +#define EV_NONE 0 // Invalid version +#define EV_CURRENT 1 // Current version +/* End Elf Version */ + +/* Elf Program Header Types */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +/* End Elf Program Header Types */ + +typedef struct { + uInt8 eIdent[16]; /* File identification. */ + uInt16 eType; /* File type. */ + uInt16 eMachine; /* Machine architecture. */ + uInt32 eVersion; /* ELF format version. */ + uInt32 eEntry; /* Entry point. */ + uInt32 ePhoff; /* Program header file offset. */ + uInt32 eShoff; /* Section header file offset. */ + uInt32 eFlags; /* Architecture-specific flags. */ + uInt16 eEhsize; /* Size of ELF header in bytes. */ + uInt16 ePhentsize; /* Size of program header entry. */ + uInt16 ePhnum; /* Number of program header entries. */ + uInt16 eShentsize; /* Size of section header entry. */ + uInt16 eShnum; /* Number of section header entries. */ + uInt16 eShstrndx; /* Section name strings section. */ + } elfHeader; + +typedef struct { + uInt32 phType; /* Entry type. */ + uInt32 phOffset; /* File offset of contents. */ + uInt32 phVaddr; /* Virtual address in memory image. */ + uInt32 phPaddr; /* Physical address (not used). */ + uInt32 phFilesz; /* Size of contents in file. */ + uInt32 phMemsz; /* Size of contents in memory. */ + uInt32 phFlags; /* Access permission flags. */ + uInt32 phAlign; /* Alignment in memory and file. */ + } elfProgramHeader; + +typedef struct { + uInt32 shName; /* Section name (index into the section header string table). */ + uInt32 shType; /* Section type. */ + uInt32 shFlags; /* Section flags. */ + uInt32 shAddr; /* Address in memory image. */ + uInt32 shOffset; /* Offset in file. */ + uInt32 shSize; /* Size in bytes. */ + uInt32 shLink; /* Index of a related section. */ + uInt32 shInfo; /* Depends on section type. */ + uInt32 shAddralign; /* Alignment in bytes. */ + uInt32 shEntsize; /* Size of each entry in section. */ + } elfSectionHeader; + +typedef struct { + uInt32 pltOffset; + uInt32 pltInfo; + } elfPltInfo; + +typedef struct { + uInt32 dynName; + uInt32 dynValue; + uInt32 dynSize; + uInt32 dynInfo; + } elfDynSym; + +typedef struct { + uInt32 dynVal; + uInt32 dynPtr; + } elfDynamic; + +char *elfGetShType(int); +char *elfGetPhType(int); +char *elfGetRelType(int); + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s, t) ((s)<<8+(unsigned char)(t)) + +#endif + +/*** + $Log$ + Revision 1.6 2004/06/16 14:04:51 reddawg + Renamed a typedef + + Revision 1.5 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.4 2004/06/12 01:27:26 reddawg + shared objects: yes we almost fully support shared objects + + Revision 1.3 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/endtask.h b/src/sys/include/ubixos/endtask.h new file mode 100644 index 0000000..d3f3c4a --- /dev/null +++ b/src/sys/include/ubixos/endtask.h @@ -0,0 +1,46 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _ENDTASK_H +#define _ENDTASK_H + +#include + +void endTask(pidType); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/exec.h b/src/sys/include/ubixos/exec.h new file mode 100644 index 0000000..08fdaf0 --- /dev/null +++ b/src/sys/include/ubixos/exec.h @@ -0,0 +1,48 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _EXEC_H +#define _EXEC_H + +#include +#include + +uInt32 execThread(void (* tproc)(void),int,char *); +void execFile(char *file,int argc,char **argv,int console); + +#endif + +/*** + $Log$ + Revision 1.4 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/fork.h b/src/sys/include/ubixos/fork.h new file mode 100644 index 0000000..c1ffe89 --- /dev/null +++ b/src/sys/include/ubixos/fork.h @@ -0,0 +1,49 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _FORK_H +#define _FORK_H + +#include +#include + +void sysFork(); + +int forkCopyProcess(struct taskStruct *newProcess,long ebp,long edi,long esi,long none,long ebx,long ecx,long edx,long eip,long cs,long eflags,long esp,long ss); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/kpanic.h b/src/sys/include/ubixos/kpanic.h new file mode 100644 index 0000000..91c5d50 --- /dev/null +++ b/src/sys/include/ubixos/kpanic.h @@ -0,0 +1,44 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _KPANIC_H +#define _KPANIC_H + +void kpanic(const char *fmt, ...); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/ld.h b/src/sys/include/ubixos/ld.h new file mode 100644 index 0000000..afc9d62 --- /dev/null +++ b/src/sys/include/ubixos/ld.h @@ -0,0 +1,65 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _LD_H +#define _LD_H + +#include + +#define LD_START 0x1000000 + +uInt32 ldEnable(); + +#endif + +/*** + $Log$ + Revision 1.10 2004/06/17 12:20:32 reddawg + Try this now solarwind + + Revision 1.9 2004/06/17 02:19:29 reddawg + Cleaning out dead code + + Revision 1.8 2004/06/16 17:32:14 reddawg + Removed Dead LD Code now part of ld.so + + Revision 1.7 2004/06/16 17:04:13 reddawg + ld.so: rest of the commit + + Revision 1.4 2004/06/13 03:05:15 reddawg + we now have a dynamic linker + + Revision 1.3 2004/06/12 01:27:26 reddawg + shared objects: yes we almost fully support shared objects + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + END + ***/ diff --git a/src/sys/include/ubixos/sched.h b/src/sys/include/ubixos/sched.h new file mode 100644 index 0000000..41bf9d4 --- /dev/null +++ b/src/sys/include/ubixos/sched.h @@ -0,0 +1,127 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SCHED_H +#define _SCHED_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + + +typedef enum { DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3 } tState; + +struct osInfo { + struct mountPoints *container; + struct taskFileInfo fileInfo; + struct consoleStruct *terminal; + uInt16 sectionCount; + uInt8 timer; + uInt8 v86Task; + bool v86If; + uInt32 curDir; + uInt32 vmStart; + uInt32 stdinSize; + uInt32 controlKeys; + char *stdin; + char *cwd; + }; + +typedef struct taskStruct { + pidType id; + struct taskStruct *prev; + struct taskStruct *next; + struct tssStruct tss; + struct i387Struct i387; + struct osInfo oInfo; + tState state; + uInt32 gid; + uInt32 uid; + uInt16 usedMath; + uInt16 nice; + uInt32 timeSlice; + } kTask_t; + +typedef struct prioQueue { + kTask_t *start; + kTask_t *end; + struct prioQueue *next; + uInt32 prio; +} prioQueue_t; + +#define MAXPRIOLEVELS 11 + +int schedInit(); +void sched(); +void schedYield(); +void schedEndTask(pidType pid); +kTask_t *schedNewTask(); +kTask_t *schedFindTask(uInt32 id); +int deleteTask(uInt32); + +extern kTask_t *taskList; +extern uInt32 nextID; +extern kTask_t *_current; +extern kTask_t *_usedMath; + +#ifdef __cplusplus +} +#endif + +#endif + +/*** + $Log$ + Revision 1.7 2004/06/18 13:01:47 solar + Added nice and timeSlice members to the kTask_t type + + Revision 1.6 2004/06/17 02:12:57 reddawg + Cleaned Out Dead Code + + Revision 1.5 2004/06/16 14:04:51 reddawg + Renamed a typedef + + Revision 1.4 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.3 2004/05/21 15:49:13 reddawg + The os does better housekeeping now when a task is exited + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ + diff --git a/src/sys/include/ubixos/smp.h b/src/sys/include/ubixos/smp.h new file mode 100644 index 0000000..8b9b6e0 --- /dev/null +++ b/src/sys/include/ubixos/smp.h @@ -0,0 +1,64 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SMP_H +#define _SMP_H + +#include + +struct cpuinfo_t { + uInt8 id; + uInt8 ok; // 1=Ok, 0=Bad + uInt8 apic_id,apic_ver; + uInt32 signature; // Family, Model, Stepping + uInt32 feature; + uInt32 max; + char brand[49]; // Brand name + char ident[17]; + }; + + +void smpInit(); +void cpuidDetect(); +uInt8 cpuInfo(); +uInt32 getEflags(); +void setEflags(uInt32); +void cpuid(uInt32,uInt32 *); +void apicMagic(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/spinlock.h b/src/sys/include/ubixos/spinlock.h new file mode 100644 index 0000000..5869793 --- /dev/null +++ b/src/sys/include/ubixos/spinlock.h @@ -0,0 +1,55 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SPINLOCK_H +#define _SPINLOCK_H + +#include + +#define SPIN_LOCK_INITIALIZER 0 + +typedef volatile int spinLock_t; + +extern inline void spinLockInit(spinLock_t *); +extern inline void spinUnlock(spinLock_t *); +extern inline int spinTryLock(spinLock_t *); +extern inline void spinLock(spinLock_t *); +extern inline int spinLockLocked(spinLock_t *); + +#endif + +/*** + $Log$ + Revision 1.3 2004/05/21 12:42:32 reddawg + Cleaned Up + + + END + ***/ + diff --git a/src/sys/include/ubixos/syscall.h b/src/sys/include/ubixos/syscall.h new file mode 100644 index 0000000..c602086 --- /dev/null +++ b/src/sys/include/ubixos/syscall.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSCALL_H +#define _SYSCALL_H + +#include + +void _sysCall(); +void invalidCall(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/syscalls.h b/src/sys/include/ubixos/syscalls.h new file mode 100644 index 0000000..7aa86d0 --- /dev/null +++ b/src/sys/include/ubixos/syscalls.h @@ -0,0 +1,147 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSCALLS_H +#define _SYSCALLS_H + +#include +#include + +void sysGetpid(); +void sysExit(); +void sysExec(); +void sysFork(); +void sysCheckPid(); +void sysGetFreePage(); + +void sysFwrite(); +void sysFgetc(); +void sysFopen(); +void sysFread(); +void sysFclose(); +void sysSchedYield(); +void sysFseek(); +void sysMkDir(); +void sysRmDir(); +void sysGetUid(); +void sysGetGid(); +void sysSetUid(); +void sysSetGid(); +void sysSDE(); +void sysGetDrives(); +void sysGetCwd(); +void sysChDir(); +void sysGetUptime(); +void sysGetTime(); +void sysStartSDE(); +void sysUnlink(); +void sysMpiCreateMbox(); +void sysMpiDestroyMbox(); +void sysMpiPostMessage(); +void sysMpiFetchMessage(); +void sysMpiSpam(); + +typedef void (*functionPTR)(); + +functionPTR systemCalls[] = { + invalidCall, /** 0 **/ + sysGetpid, /** 1 **/ + sysExit, /** 2 **/ + sysExec, /** 3 **/ + sysFork, /** 4 **/ + sysFgetc, /** 5 **/ + sysCheckPid, /** 6 **/ + sysGetFreePage, /** 7 **/ + sysFopen, /** 8 **/ + invalidCall, /** 9 **/ + sysFclose, /** 10 **/ + sysSchedYield, /** 11 **/ + invalidCall, /** 12 **/ + invalidCall, /** 13 **/ + invalidCall, /** 14 **/ + invalidCall, /** 15 **/ + invalidCall, /** 16 **/ + invalidCall, /** 17 **/ + invalidCall, /** 18 **/ + invalidCall, /** 19 **/ + sysFopen, /** 20 Opens A File Node **/ + sysFclose, /** 21 Closes A File Node **/ + sysFread, /** 22 File Read **/ + sysFwrite, /** 23 File Write **/ + sysMkDir, /** 24 Make Directory **/ + sysRmDir, /** 25 Remove Directory **/ + sysGetCwd, /** 26 Get Current Working Dir **/ + sysFseek, /** 27 Set FD Position **/ + sysChDir, /** 28 Change Dir **/ + sysMkDir, /** 29 Create Directory **/ + sysUnlink, /** 30 Unlink **/ + sysGetUid, /** 31 Get User Id **/ + sysGetGid, /** 32 Get Group Id **/ + sysSetUid, /** 33 Set User Id **/ + sysSetGid, /** 34 Set Group Id **/ + invalidCall, /** 35 **/ + invalidCall, /** 36 **/ + invalidCall, /** 37 **/ + invalidCall, /** 38 **/ + invalidCall, /** 39 **/ + sysSDE, /** 40 SDE Kernel Interface **/ + invalidCall, /** 41 **/ + invalidCall, /** 42 **/ + invalidCall, /** 43 **/ + invalidCall, /** 44 **/ + sysGetDrives, /** 45 Get Drives **/ + sysGetUptime, /** 46 Get Uptime **/ + sysGetTime, /** 47 Get Time **/ + sysStartSDE, /** 48 start SDE **/ + invalidCall, /** 49 **/ + sysMpiCreateMbox, /** 50 mpiCreateMbox **/ + sysMpiDestroyMbox, /** 51 mpiDestroyMbox **/ + sysMpiPostMessage, /** 52 mpiPostMessage **/ + sysMpiFetchMessage, /** 53 mpiFetchMessage **/ + sysMpiSpam, /** 54 mpiSpam **/ + }; + +int totalCalls = sizeof(systemCalls)/sizeof(functionPTR); + +#endif + +/*** + $Log$ + Revision 1.4 2004/05/26 15:39:22 reddawg + mpi: brought mpiDestroyMbox(char *name) in to the userland + + Revision 1.3 2004/05/25 15:42:19 reddawg + Enabled mpiSpam(); + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/systemtask.h b/src/sys/include/ubixos/systemtask.h new file mode 100644 index 0000000..227cdea --- /dev/null +++ b/src/sys/include/ubixos/systemtask.h @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _SYSTEMTASK_H +#define _SYSTEMTASK_H + +#include + +void systemTask(); + +#endif + +/*** + $Log$ + Revision 1.2 2004/06/04 17:49:32 reddawg + Wont work with out the makefile updated + + Revision 1.1 2004/06/04 17:33:33 reddawg + Changed idle task to system task + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/time.h b/src/sys/include/ubixos/time.h new file mode 100644 index 0000000..cd16ffe --- /dev/null +++ b/src/sys/include/ubixos/time.h @@ -0,0 +1,94 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TIME_H +#define _TIME_H + +#include +#include + +typedef long suseconds_t; + +#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) + +#define MINUTE 60 +#define HOUR (60*MINUTE) +#define DAY (24*HOUR) +#define YEAR (365*DAY) + +#ifndef _TIME_T_DECLARED +typedef __time_t time_t; +#define _TIME_T_DECLARED +#endif + +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + + + +struct timeStruct { + int sec; + int min; + int hour; + int day; + int mon; + int year; + }; + + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ + }; + +struct timeval { + long tv_sec; /* seconds (XXX should be time_t) */ + suseconds_t tv_usec; /* and microseconds */ + }; + +int gettimeofday(struct timeval *tp,struct timezone *tzp); + + + +int timeInit(); +int timeCmosRead(int); +uInt32 timeMake(struct timeStruct *time); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/times.h b/src/sys/include/ubixos/times.h new file mode 100644 index 0000000..f198dc0 --- /dev/null +++ b/src/sys/include/ubixos/times.h @@ -0,0 +1,57 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TIMES_H +#define _TIMES_H + +#include +#include + +#ifndef _CLOCK_T_DECLARED +typedef __clock_t clock_t; +#define _CLOCK_T_DECLARED +#endif + +struct tms { + clock_t tms_utime; /* User CPU time */ + clock_t tms_stime; /* System CPU time */ + clock_t tms_cutime; /* User CPU time of terminated child procs */ + clock_t tms_cstime; /* System CPU time of terminated child procs */ +}; + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/types.h b/src/sys/include/ubixos/types.h new file mode 100644 index 0000000..d09104c --- /dev/null +++ b/src/sys/include/ubixos/types.h @@ -0,0 +1,67 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _TYPES_H +#define _TYPES_H + +#include + +#ifndef NULL +#define NULL 0x0 +#endif + +typedef unsigned char uInt8; +typedef unsigned short uInt16; +typedef unsigned int uInt32; +typedef unsigned int uInt; +typedef char Int8; +typedef short Int16; +typedef long Int32; + +typedef int pidType; + +typedef int pid_t; +typedef int size_t; /* standart */ +#ifndef NOBOOL +typedef enum { FALSE=0,TRUE=1 } bool; +#endif + +#endif + +/*** + $Log$ + Revision 1.4 2004/06/01 02:50:45 reddawg + Cleanup + + Revision 1.3 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/ubthread.h b/src/sys/include/ubixos/ubthread.h new file mode 100644 index 0000000..a59a124 --- /dev/null +++ b/src/sys/include/ubixos/ubthread.h @@ -0,0 +1,98 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _UBTHREAD_H +#define _UBTHREAD_H + +#include +#include +#include + +#define ETIMEDOUT -1 + +#define LOCKED 1 +#define UNLOCKED 0 + +typedef struct ubthread *ubthread_t; +typedef struct ubthread_cond *ubthread_cond_t; +typedef struct ubthread_mutex *ubthread_mutex_t; + +struct ubthread { + kTask_t *task; + }; + +struct ubthread_cond { + int id; + uInt8 locked; + }; + +struct ubthread_mutex { + int id; + uInt8 locked; + pidType pid; + }; + +struct ubthread_list { + struct ubthread_list *next; + ubthread_t thread; + }; + +struct ubthread_cond_list { + struct ubthread_cond_list *next; + ubthread_cond_t *cond; + }; + +struct ubthread_mutex_list { + struct ubthread_mutex_list *next; + ubthread_mutex_t *mutex; + }; + + +kTask_t *ubthread_self(); +int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr); +int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr); +int ubthread_cond_destroy(ubthread_cond_t *cond); +int ubthread_mutex_destroy(ubthread_mutex_t *mutex); +int ubthread_create(kTask_t **thread,const uInt32 *attr,void *start_routine, void *arg); +int ubthread_mutex_lock(ubthread_mutex_t *mutex); +int ubthread_mutex_unlock(ubthread_mutex_t *mutex); +int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime); +int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex); +int ubthread_cond_signal(ubthread_cond_t *cond); + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/ubixos/vitals.h b/src/sys/include/ubixos/vitals.h new file mode 100644 index 0000000..635c4ce --- /dev/null +++ b/src/sys/include/ubixos/vitals.h @@ -0,0 +1,72 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _VITALS_H +#define _VITALS_H + +#include +#include +#include +#include + +typedef struct vitalsStruct { + uInt32 openFiles; + uInt32 sysTicks; + uInt32 sysUptime; + uInt32 quantum; + uInt32 dQuantum; + uInt32 freePages; + struct fileSystem *fileSystems; + struct mountPoints *mountPoints; + uInt32 timeStart; + void *screen; + void *font; + char *packet; + uInt32 packetLength; + } vitalsNode; + +extern vitalsNode *systemVitals; + +int initVitals(); + +#endif + +/*** + $Log$ + Revision 1.4 2004/06/18 13:01:47 solar + Added nice and timeSlice members to the kTask_t type + + Revision 1.3 2004/06/16 12:04:18 reddawg + systemVitals->quantum = (1000/msPerQuantum) + The timer int now will call scheduler at the rate of the defined quantum + + Revision 1.2 2004/05/21 15:20:00 reddawg + Cleaned up + END + ***/ diff --git a/src/sys/include/vfs/file.h b/src/sys/include/vfs/file.h new file mode 100644 index 0000000..32ba8c4 --- /dev/null +++ b/src/sys/include/vfs/file.h @@ -0,0 +1,60 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _FILE_H +#define _FILE_H + +#include +#include + +#define SEEK_SET 0x0 + +struct taskFileInfo { + char *cwd; + }; + +typedef struct userFileDescriptorStruct { + struct fileDescriptorStruct *fd; + uInt32 fdSize; + } userFileDescriptor; + +extern fileDescriptor *fdTable; +extern fileDescriptor *lastFd; + +fileDescriptor *fopen(const char *file,const char *flags); +int unlink(const char *path); +int fclose(fileDescriptor *fd); +int feof(fileDescriptor *fd); +int fgetc(fileDescriptor *fd); +size_t fread(void *ptr, size_t size, size_t nmemb,fileDescriptor *fd); +size_t fwrite(void *ptr,int size,int nmemb,fileDescriptor *fd); +int fseek(fileDescriptor *,long,int); + +void sysFseek(userFileDescriptor *,long,int); + +//Good +void sysChDir(const char *path); +void chDir(const char *path); +char *verifyDir(const char *path); + +#endif diff --git a/src/sys/include/vfs/mount.h b/src/sys/include/vfs/mount.h new file mode 100644 index 0000000..6bdbeb0 --- /dev/null +++ b/src/sys/include/vfs/mount.h @@ -0,0 +1,55 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _MOUNT_H +#define _MOUNT_H + +#include + +struct mountPoints { + struct mountPoints *prev; + struct mountPoints *next; + struct fileSystem *fs; + struct deviceNode *device; + struct ubixDiskLabel *diskLabel; + void *fsInfo; + int partition; + char mountPoint[1024]; + char perms; + }; + +int mount(int major,int minor,int partition,int fsType,char *mountPoint,char *perms); +int addMount(struct mountPoints *mp); +struct mountPoints *findMount(char *mountPoint); + +#endif + +/*** + END + ***/ diff --git a/src/sys/include/vfs/vfs.h b/src/sys/include/vfs/vfs.h new file mode 100644 index 0000000..f2b04fc --- /dev/null +++ b/src/sys/include/vfs/vfs.h @@ -0,0 +1,84 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _VFS_H +#define _VFS_H + +#include + +#define maxFd 32 +#define fdAvail 1 +#define fdOpen 2 +#define fdRead 3 +#define fdEof 4 + + +#define fileRead 0x0001 +#define fileWrite 0x0002 +#define fileBinary 0x0004 +#define fileAppend 0x0008 + +typedef struct fileDescriptorStruct { + struct fileDescriptorStruct *prev; + struct fileDescriptorStruct *next; + struct mountPoints *mp; + uInt16 status; + uInt16 mode; + uInt32 offset; + uInt32 size; + uInt16 length; + uInt32 start; + uInt8 fileName[22]; + char *buffer; + uInt32 dirBlock; + uInt32 perms; + } fileDescriptor; + +struct fileSystem { + struct fileSystem *prev; + struct fileSystem *next; + int (*vfsInitFS)(void *); + int (*vfsRead)(void *,char *,long,long); + int (*vfsWrite)(void *,char *,long,long); + int (*vfsOpenFile)(void *,void *); + int (*vfsUnlink)(char *,void *); + int (*vfsMakeDir)(char *,void *); + int (*vfsRemDir)(char *); + int (*vfsSync)(void); + int vfsType; + }; + + +/* VFS Functions */ +int vfsInit(); +int vfsRegisterFS(int,void *,void *,void *,void *,void *,void *,void *,void *); +struct fileSystem *vfsFindFS(int); + + + +//File IO +fileDescriptor *fopen(const char *file,const char *flags); + + +#endif + diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h new file mode 100644 index 0000000..35c7d68 --- /dev/null +++ b/src/sys/include/vmm/paging.h @@ -0,0 +1,75 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _PAGING_H +#define _PAGING_H + +#include + +#define pageLength 0x00000400 +#define pageSize 4096 +#define pageEntries (pageSize/4) +#define pagePresent 0x00000001 +#define pageWrite 0x00000002 +#define pageUser 0x00000004 +#define pageCow 0x00000200 +#define pageStack 0x00000400 +#define pageDefault (pagePresent|pageWrite|pageUser) +#define kernelPageDefault (pagePresent|pageWrite) +#define tablesBaseAddress 0xBFC00000 +#define parentPageDirAddr 0x100000 + +int vmmPagingInit(); +int vmmClearVirtualPage(uInt32 pageAddr); +int vmmRemapPage(uInt32,uInt32); +void vmmUnmapPage(uInt32,int); +void vmmUnmapPages(void *,uInt32); +void vmmSetPageAttribute(uInt32,int); +void *vmmMapFromTask(pidType,void *,uInt32); +void *vmmCopyVirtualSpace(pidType); +void *vmmGetFreePage(pidType); +void *vmmGetFreeKernelPage(pidType pid,uInt16 count); +void *vmmGetPhysicalAddr(uInt32); +void *vmmCreateVirtualSpace(pidType); +void *vmmGetFreeVirtualPage(pidType,int); +void vmmPageFault(); +void _vmmPageFault(); + +extern uInt32 *kernelPageDirectory; + +#endif + +/*** + $Log$ + Revision 1.2 2004/05/21 15:21:04 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/include/vmm/vmm.h b/src/sys/include/vmm/vmm.h new file mode 100644 index 0000000..78ce414 --- /dev/null +++ b/src/sys/include/vmm/vmm.h @@ -0,0 +1,69 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#ifndef _VMM_H +#define _VMM_H + +#include +#include + +#define memAvail 1 +#define memNotavail 2 +#define vmmID -3 +#define vmmMemoryMapAddr 0xE6667000 + +typedef struct { + uInt32 pageAddr; + uInt16 status; + pid_t pid; + int cowCounter; + } mMap; + +extern mMap *vmmMemoryMap; +extern int numPages; +extern uInt32 freePages; + +int vmmInit(); +int vmmMemMapInit(); +int countMemory(); +uInt32 vmmFindFreePage(pidType pid); +int freePage(uInt32 pageAddr); +int adjustCowCounter(uInt32 baseAddr,int adjustment); +void vmmFreeProcessPages(pidType pid); + +#endif + +/*** + $Log$ + Revision 1.3 2004/05/21 15:21:04 reddawg + Cleaned up + + + END + ***/ diff --git a/src/sys/init/Makefile b/src/sys/init/Makefile new file mode 100644 index 0000000..5560b72 --- /dev/null +++ b/src/sys/init/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = main.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/init/main.c b/src/sys/init/main.c new file mode 100644 index 0000000..7d1f0bc --- /dev/null +++ b/src/sys/init/main.c @@ -0,0 +1,306 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char kernelStack[8192]; // Stack Space For Our Kernel + +ubixDescriptorTable(ubixGDT,8) { + {dummy:0}, + ubixStandardDescriptor(0x0, 0xFFFFF, (dCode + dRead + dBig + dBiglim)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dData + dWrite + dBig + dBiglim)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dLdt)), + ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dCode + dWrite + dBig + dBiglim + dDpl3)), + ubixStandardDescriptor(0x0, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), + ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), + }; +struct { + unsigned short limit __attribute__ ((packed)); + union descriptorTableUnion *gdt __attribute__ ((packed)); + } loadGDT = { (8 * sizeof(union descriptorTableUnion) - 1), ubixGDT }; + +/***************************************************************************************** + Desc: This is the entry point into the os where all of the kernels sub systems are + started up. + + Notes: + +*****************************************************************************************/ +int main(int argc,char **argv) { + + clearScreen(); /* Do A Clear Screen Just To Make The TEXT Buffer Nice And Empty */ + //smpInit(); /* Initialize SMP */ + + /* Initialize Virtual Memory Manager */ + if (vmmInit() != 0x0) { + kpanic("Error: Initializing VMM Subsystem.\n"); + } + + /* Initialize System Vital Sub System */ + if (initVitals() != 0x0) { + kpanic("Error: Initializing vitals\n"); + } + + /* Initialize VFS(Virtual File System) Layer */ + if (vfsInit() != 0x0) { + kpanic("Error: Initializing VFS\n"); + } + + /* Initialize The Systems 8259 Controller/IRQ Handling */ + if (init8259() != 0x0) { + kpanic("Error: Initializing 8259\n"); + } + + /* Initialize The IDT Subsystem */ + if (idtInit() != 0x0) { + kpanic("Error: Initializing IDT\n"); + } + + /* Initialize The Kernel Scheduler */ + if (schedInit() != 0x0) { + kpanic("Error: Initializing: Scheduler\n"); + } + + /* Initialize The Systems Timer */ + if (pitInit(1000) != 0x0) { + kpanic("Error: Initializing PIT\n"); + } + + /* Initialize The Systems Keyboard */ + if (keyboardInit() != 0x0) { + kpanic("Error: Initializing Keyboard\n"); + } + //mouseInit(); + + /* Initialize PCI Sub System */ + /* + if (pciInit() != 0x0) { + kpanic("Error: Initializing PCI\n"); + } + */ + + /* Sart Time */ + if (timeInit() != 0x0) { + kpanic("Error: Initializing TIME\n"); + } + + /* Initialize Networking Subsystem */ + if (netInit() != 0x0) { + kpanic("Error: Initializing Networking Subsystem\n"); + } + + /* Initialize The NE2000 NIC Device */ + if (ne2kInit(0x240) != 0x0) { + kpanic("Error: Initializing NE2000\n"); + } + + if (devFSEnable() != 0x0) { + kpanic("Error: Enabling devFS\n"); + } + enableUbixFS(); + fdcInit(); + //initHardDisk(); + if (mount(0x0,0x0,0x0,0x0,"sys","rw") != 0x0) { + kprintf("Problem Mounting sys Mount Point\n"); + } + if (mount(0x0,0x0,0x1,0x0,"tmp","rw") != 0x0) { + kprintf("Problem Mounting tmp Mount Point\n"); + } + /* + if (mount(0x1,0x1,0x0,0x0,"hd","rw") != 0x0) { + kprintf("Problem Mounting HD Mount Point\n"); + } + */ + execThread(systemTask,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + execFile("init",0x0,0x0,0x0); + //execFile("shell",0x0,0x0,0x0); + kprintf("Free Pages: [%i]\n",freePages); + kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); + kprintf("Starting Os\n"); + kprintf("argc: %i:%i\n",argc,argv[0]); + irqEnable(0x0); + sched(); + return(0x0); + } + +/************************************************************************ + +Function: _start(); +Description: This Is The Kernels Main Entry Point From Here We Must + Re-Setup Our GDT And Set All Registers To Their Default + Values So We Are Sure Of No Error When The OS Boots Up Also + We Have To Quickly Set Up Our Interrupt Table Because We Do + Not Have Any Fault Protection Yet + +Notes: + +02/17/03 - I'm Unhappy With The Infinite Loop I Decided To Do If The Call + To Main Returns I Think I Shall Change It To A Kernel Panic + At A Later Date Then Reboot The Machine + +************************************************************************/ +void _start(char *args, ...) { + int argc; + char **argv; + argv = &args; + argc = * (int *) (argv - 1); + asm ("pushl $2; popf"); + asm volatile( + "lgdtl (loadGDT) \n" + "movw $0x10,%%ax \n" // Select Ring 0 Data Segment + "movw %%ax,%%ds \n" // Set Default Segment + "movw %%ax,%%es \n" // "" "" + "movw %%ax,%%fs \n" // "" "" + "movw %%ax,%%gs \n" // "" "" + "movw %%ax,%%ss \n" // "" "" + "movl $0x2000,%%esp \n" // Set Default Stack Pointer Its The End Of First Page + "movl $0x2000,%%ebp \n" + "mov $0x18,%%ax \n" // Set Up Dummy LDT + "lldt %%ax \n" // Load The Dummy LDT + "mov $0x20,%%ax \n" // Set Up Dummy TSS + "ltr %%ax \n" // Load The Dummy TSS + "ljmp $0x08,$next \n" + "next: \n" + : + : "r" (ubixGDT), "p" (kernelStack+8192) + : "%eax" + ); + main(argc,argv); + kpanic("We Should Not Get This Far\n"); + } + +/*** + + $Log$ + Revision 1.32 2004/06/04 17:33:33 reddawg + Changed idle task to system task + + Revision 1.31 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.30 2004/05/25 18:38:55 reddawg + Removed sample code + + Revision 1.29 2004/05/25 15:50:43 reddawg + mpiSpam() test + + Revision 1.28 2004/05/23 01:10:35 reddawg + Fixes: Started to fix re-entrancy issues many more to look into + + Revision 1.27 2004/05/21 21:15:04 reddawg + Fixed a few bugs which prevented the system from loadin + + Revision 1.26 2004/05/20 22:54:02 reddawg + Cleaned Up Warrnings + + Revision 1.25 2004/05/19 17:28:28 reddawg + Added the correct endTask Procedure + + Revision 1.24 2004/05/19 04:07:42 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.23 2004/05/19 03:35:02 reddawg + Fixed A Few Ordering Issues In The Service Startup Routine + + Revision 1.22 2004/05/19 01:21:29 reddawg + Tweaked + + Revision 1.21 2004/05/18 10:45:41 reddawg + Bug Fix + + Revision 1.20 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + Revision 1.19 2004/05/08 19:06:24 reddawg + Going to impliment FSTAB + + Revision 1.18 2004/05/04 23:38:24 reddawg + make clean all install + + Revision 1.17 2004/05/04 23:31:01 reddawg + Ok Mark Cleaned Up Boot This + + Revision 1.16 2004/05/02 14:34:21 reddawg + SMP Support Thanks To Some Help From Slowcoder now to make it interface + well with the rest of the kernel + + Revision 1.15 2004/04/30 17:04:23 reddawg + Ok GUI is back on + + Revision 1.14 2004/04/30 16:58:37 reddawg + Turned On PCI Detections + + Revision 1.13 2004/04/30 16:29:34 reddawg + Turned Off Gui + + Revision 1.12 2004/04/30 13:40:34 reddawg + Just doing spring cleaning for the new members + + Revision 1.7 2004/04/26 22:27:36 reddawg + Now mounts our harddrive I need to either impliment fstab or do something similar + + Revision 1.6 2004/04/25 04:35:50 reddawg + Minor bug fixes to set default partition information + + Revision 1.107 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/isa/8259.c b/src/sys/isa/8259.c new file mode 100644 index 0000000..3f449e0 --- /dev/null +++ b/src/sys/isa/8259.c @@ -0,0 +1,112 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static unsigned int irqMask = 0xFFFF; + +/************************************************************************ + + Function: int init8259() + + Description: This function will initialize both PICs for all of our IRQs + + Notes: + +************************************************************************/ +int init8259() { + outportByte(mPic, icw1); /* Initialize Master PIC */ + outportByte(sPic, icw1); /* Initialize Seconary PIC */ + outportByte(mPic+1, mVec); /* Master Interrup Vector */ + outportByte(sPic+1, sVec); /* Secondary Interrupt Vector */ + outportByte(mPic+1, 1<<2); /* Bitmask for cascade on IRQ 2 */ + outportByte(sPic+1, 2); /* Cascade on IRQ 2 */ + outportByte(mPic+1, icw4); /* Finish Primary Initialization */ + outportByte(sPic+1, icw4); /* Finish Seconary Initialization */ + outportByte(mImr, 0xff); /* Mask All Primary Interrupts */ + outportByte(sImr, 0xff); /* Mask All Seconary Interrupts */ + + /* Print out the system info for this */ + kprintf("pic0 - Port: [0x%X]\n",mPic); + kprintf("pic1 - Port: [0x%X]\n",sPic); + + /* Return so the system knows it went well */ + return(0x0); + } + +/************************************************************************ + + Function: int irqEnable() + + Description: This function is used to turn on an IRQ + + Notes: + +************************************************************************/ +void irqEnable(uInt16 irqNo) { + irqMask &= ~(1 << irqNo); + if (irqNo >= 8) { + irqMask &= ~(1 << 2); + } + outportByte(mPic+1, irqMask & 0xFF); + outportByte(sPic+1, (irqMask >> 8) & 0xFF); + } + +/************************************************************************ + + Function: int irqDisable() + + Description: This function is used to turn off an IRQ + + Notes: + +************************************************************************/ +void irqDisable(uInt16 irqNo) { + irqMask |= (1 << irqNo); + if ((irqMask & 0xFF00)==0xFF00) { + irqMask |= (1 << 2); + } + outportByte(mPic+1, irqMask & 0xFF); + outportByte(sPic+1, (irqMask >> 8) & 0xFF); + } + +/*** + $Log$ + Revision 1.3 2004/05/20 22:51:09 reddawg + Cleaned Up Warnings + + Revision 1.2 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + END + ***/ + diff --git a/src/sys/isa/Makefile b/src/sys/isa/Makefile new file mode 100644 index 0000000..75c32c8 --- /dev/null +++ b/src/sys/isa/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = mouse.o ne2k.o atkbd.o fdc.o 8259.o pit.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) -Wall -O $(CLFAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/isa/atkbd.c b/src/sys/isa/atkbd.c new file mode 100644 index 0000000..945a4be --- /dev/null +++ b/src/sys/isa/atkbd.c @@ -0,0 +1,483 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned int keyMap = 0; +static unsigned int ledStatus = 0; + +static unsigned int keyboardMap[][8] = { +/* Ascii, Shift, Ctrl, Alt, Num, Caps, Shift Caps, Shift Num */ + { 0, 0, 0, 0, 0, 0, 0, 0}, +/* ESC */ { 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B}, +/* 1,! */ { 0x31, 0x21, 0, 0, 0x31, 0x31, 0x21, 0x21}, +/* 2,@ */ { 0x32, 0x40, 0, 0, 0x32, 0x32, 0x40, 0x40}, +/* 3,# */ { 0x33, 0x23, 0, 0, 0x33, 0x33, 0x23, 0x23}, +/* 4,$ */ { 0x34, 0x24, 0, 0, 0x34, 0x34, 0x24, 0x24}, +/* 5,% */ { 0x35, 0x25, 0, 0, 0x35, 0x35, 0x25, 0x25}, +/* 6,^ */ { 0x36, 0x5E, 0, 0, 0x36, 0x36, 0x5E, 0x5E}, +/* 7,& */ { 0x37, 0x26, 0, 0, 0x37, 0x37, 0x26, 0x26}, +/* 8,* */ { 0x38, 0x2A, 0, 0, 0x38, 0x38, 0x2A, 0x2A}, +/* 9.( */ { 0x39, 0x28, 0, 0, 0x39, 0x39, 0x28, 0x28}, +/* 0,) */ { 0x30, 0x29, 0, 0, 0x30, 0x30, 0x29, 0x29}, +/* -,_ */ { 0x2D, 0x5F, 0, 0, 0x2D, 0x2D, 0x5F, 0x5F}, +/* =,+ */ { 0x3D, 0x2B, 0, 0, 0x3D, 0x3D, 0x2B, 0x2B}, +/* 14 */ { 0x08, 0x08, 0x8, 0x8, 0x08, 0x08, 0x08, 0x08}, +/* 15 */ { 0x09, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x71, 0x51, 0, 0, 0, 0, 0, 0}, +/* */ { 0x77, 0x57, 0, 0, 0, 0, 0, 0}, +/* */ { 0x65, 0x45, 0, 0, 0, 0, 0, 0}, +/* */ { 0x72, 0x52, 0, 0, 0, 0, 0, 0}, +/* */ { 0x74, 0x54, 0, 0, 0, 0, 0, 0}, +/* */ { 0x79, 0x59, 0, 0, 0, 0, 0, 0}, +/* */ { 0x75, 0x55, 0, 0, 0, 0, 0, 0}, +/* */ { 0x69, 0x49, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6F, 0x4F, 0, 0, 0, 0, 0, 0}, +/* */ { 0x70, 0x50, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5B, 0x7B, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5D, 0x7D, 0, 0, 0, 0, 0, 0}, +/* */ { 0x0A, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* a,A */ { 0x61, 0x41, 0x41, 0, 0, 0, 0, 0}, +/* */ { 0x73, 0x53, 0, 0, 0, 0, 0, 0}, +/* */ { 0x64, 0x44, 0, 0, 0, 0, 0, 0}, +/* */ { 0x66, 0x46, 0, 0, 0, 0, 0, 0}, +/* */ { 0x67, 0x47, 0, 0, 0, 0, 0, 0}, +/* */ { 0x68, 0x48, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6A, 0x4A, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6B, 0x4B, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6C, 0x4C, 0, 0, 0, 0, 0, 0}, +/* */ { 0x3B, 0x3A, 0, 0, 0, 0, 0, 0}, +/* */ { 0x27, 0x22, 0, 0, 0, 0, 0, 0}, +/* */ { 0x60, 0x7E, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2A, 0x0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5C, 0x3C, 0, 0, 0, 0, 0, 0}, +/* */ { 0x7A, 0x5A, 0, 0, 0, 0, 0, 0}, +/* */ { 0x78, 0x58, 0, 0, 0, 0, 0, 0}, +/* c,C */ { 0x63, 0x43, 0x3, 0, 0, 0, 0, 0}, +/* */ { 0x76, 0x56, 0, 0, 0, 0, 0, 0}, +/* */ { 0x62, 0x42, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6E, 0x4E, 0, 0, 0, 0, 0, 0}, +/* */ { 0x6D, 0x4D, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2C, 0x3C, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2E, 0x3E, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2F, 0x3F, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x20, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* F1 */ { 0x3001, 0, 0, 0x3000, 0, 0, 0, 0}, +/* */ { 0x3C00, 0, 0, 0x3001, 0, 0, 0, 0}, +/* */ { 0x3D00, 0, 0, 0x3002, 0, 0, 0, 0}, +/* */ { 0x3E00, 0, 0, 0x3003, 0, 0, 0, 0}, +/* */ { 0x3F00, 0, 0, 0x3004, 0, 0, 0, 0}, +/* */ { 0x4000, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4100, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4200, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4300, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4400, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4700, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4800, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4900, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2D, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4B00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4C00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4D00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x2B, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x4F00, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5000, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5100, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5200, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0x5300, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 1, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0}, +/* */ { 0, 0, 0, 0, 0, 0, 0, 0} + }; + +/************************************************************************ + +Function: int initKeyboard + +Description: This function is used to turn on the keyboard + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int keyboardInit() { + + /* Insert the IDT vector for the keyboard handler */ + setVector(&keyboardISR, mVec+1, dPresent + dInt + dDpl3); + + /* Set the LEDS to their defaults */ + setLED(); + + /* Turn on the keyboard vector */ + outportByte(mPic, eoi); + outportByte(sPic, eoi); + irqEnable(0x1); + outportByte(mPic, eoi); + outportByte(sPic, eoi); + + /* Print out information on keyboard */ + kprintf("atkbd0 - Address: [0x%X]\n",&keyboardISR); + + /* Return so we know everything went well */ + return(0x0); + } + +/* + * 2-23-2004 mji I think the pusha/popa should be pushal/popal + */ + +asm( + ".globl keyboardISR \n" + "keyboardISR: \n" + " pusha \n" /* Save all registers */ + " call keyboardHandler \n" + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +void keyboardHandler() { + unsigned int key = inportByte(0x60); + kTask_t *tmpTask = 0x0; + + tmpTask = schedFindTask(0); + if (tmpTask->oInfo.stdin == 0x0) { + tmpTask->oInfo.stdin = (char *)kmalloc(256); + } + /* Control Key */ + if (key == 0x1D && !(tmpTask->oInfo.controlKeys & controlKey)) { + tmpTask->oInfo.controlKeys |= controlKey; + } + if (key == 0x80 + 0x1D) { + tmpTask->oInfo.controlKeys &= (0xFF - controlKey); + } + /* ALT Key */ + if (key == 0x38 && !(tmpTask->oInfo.controlKeys & altKey)) { + tmpTask->oInfo.controlKeys |= altKey; + } + if (key == 0x80 + 0x38) { + tmpTask->oInfo.controlKeys &= (0xFF - altKey); + } + /* Shift Key */ + if ((key == 0x2A || key == 0x36) && !(tmpTask->oInfo.controlKeys & shiftKey)) { + tmpTask->oInfo.controlKeys |= shiftKey; + } + if ((key == 0x80 + 0x2A) || (key == 0x80 + 0x36)) { + tmpTask->oInfo.controlKeys &= (0xFF - shiftKey); + } + /* Caps Lock */ + if (key == 0x3A) { + ledStatus ^= ledCapslock; + setLED(); + } + /* Num Lock */ + if (key == 0x45) { + ledStatus ^= ledNumlock; + setLED(); + } + /* Scroll Lock */ + if (key == 0x46) { + ledStatus ^= ledScrolllock; + setLED(); + } + /* Pick Which Key Map */ + if (tmpTask->oInfo.controlKeys == 0) { keyMap = 0; } + else if (tmpTask->oInfo.controlKeys == 1) { keyMap = 1; } + else if (tmpTask->oInfo.controlKeys == 2) { keyMap = 2; } + else if (tmpTask->oInfo.controlKeys == 4) { keyMap = 3; } + /* If Key Is Not Null Add It To Handler */ + if (((uInt)(keyboardMap[key][keyMap]) > 0) && ((uInt32)(keyboardMap[key][keyMap]) < 0xFF)) { + switch ((uInt32)keyboardMap[key][keyMap]) { + case 8: + backSpace(); + tmpTask->oInfo.stdin[tmpTask->oInfo.stdinSize] = keyboardMap[key][keyMap]; + tmpTask->oInfo.stdinSize++; + break; + case 0x3: + schedEndTask(tmpTask->id); + break; + default: + tmpTask->oInfo.stdin[tmpTask->oInfo.stdinSize] = keyboardMap[key][keyMap]; + tmpTask->oInfo.stdinSize++; + break; + } + } + else { + switch ((keyboardMap[key][keyMap] >> 8)) { + case 0x30: + kprintf("Changing Consoles[0x%X:0x%X],Free Pages: [%i]\n",_current->id,_current,systemVitals->sysUptime);//schedFindTask(0x0),); + /* changeConsole((keyboardMap[key][keyMap] & 0xFF)); */ + break; + default: + break; + } + } + outportByte(mPic, eoi); + outportByte(sPic, eoi); + /* Return */ + return; + } + +void setLED() { + outportByte(0x60, 0xED); + while(inportByte(0x64) & 2); + outportByte(0x60, ledStatus); + while(inportByte(0x64) & 2); + } + +/* Temp */ +unsigned char getch() { + uInt8 retKey = 0x0; + uInt32 i = 0x0; + kTask_t *tmpTask = 0x0; + + tmpTask = schedFindTask(0); + + while (tmpTask->oInfo.stdinSize == 0); + retKey = tmpTask->oInfo.stdin[0]; + tmpTask->oInfo.stdinSize--; + + for (i=0x0;ioInfo.stdinSize;i++) { + tmpTask->oInfo.stdin[i] = tmpTask->oInfo.stdin[i+0x1]; + } + return(retKey); + } + +/*** + + $Log$ + Revision 1.5 2004/06/17 14:49:14 reddawg + atkbd: converted some variables to static + + Revision 1.4 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.3 2004/05/19 04:07:42 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + Revision 1.1.1.1 2004/04/15 12:07:09 reddawg + UbixOS v1.0 + + Revision 1.19 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/isa/fdc.c b/src/sys/isa/fdc.c new file mode 100644 index 0000000..a535198 --- /dev/null +++ b/src/sys/isa/fdc.c @@ -0,0 +1,352 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile bool done = FALSE; +static drvGeom geometry = { dg144Heads,dg144Tracks,dg144Spt }; +static bool diskChange = FALSE; +static bool motor = FALSE; +static Int8 fdcTrack = 0xff; +static Int8 sr0 = 0; +static volatile int timeOut = 0; +static Int8 statSize = 0; +static Int8 status[7] = { 0 }; + +unsigned long tbaddr = 0x80000L; + +int fdcInit2(struct deviceNode *dev) { + dev->size = (1024 * 1450); + return(0x0); + } + +void fdcInit() { + struct deviceInterface *devInfo = (struct deviceInterface *)kmalloc(sizeof(struct deviceInterface)); + setVector(floppyIsr, mVec+6, (dInt+dPresent)); + irqEnable(6); + reset(); + devInfo->major = 0x0; + devInfo->init = (void *)&fdcInit2; + devInfo->read = fdcRead; + devInfo->write = fdcWrite; + devInfo->reset = (void *)reset; + + deviceAdd(0,'c',devInfo); + devFsMkNod("fd0",'b',0x0,0x0); + return; + } + +asm( + ".globl floppyIsr \n" + "floppyIsr: \n" + " pusha \n" + " pushw %ds \n" + " pushw %es \n" + " pushw %ss \n" + " pushw %ss \n" + " popw %ds \n" + " popw %es \n" + " call floppyIsrhndlr \n" + " popw %es \n" + " popw %ds \n" + " popa \n" + " iret \n" + ); + +void floppyIsrhndlr() { + done = TRUE; + outportByte(0x20,0x20); + outportByte(0xA0,0x20); + } + +void sendByte(int Int8) { + volatile int msr; + int tmo; + for (tmo=0;tmo<128;tmo++) { + msr = inportByte(fdcMsr); + if ((msr & 0xc0) == 0x80) { + outportByte(fdcData,Int8); + return; + } + inportByte(0x80); + } + } + +int getByte() { + volatile int msr; + int tmo; + for (tmo=0;tmo<128;tmo++) { + msr = inportByte(fdcMsr); + if ((msr & 0xd0) == 0xd0) { + return inportByte(fdcData); + } + inportByte(0x80); + } + return(-1); + } + +bool fdcRw(int block,Int8 *blockBuffer,bool read,unsigned long numSectors) { + int head,track,sector,tries, copyCount = 0; + unsigned char *p_tbaddr = (char *)0x80000; + unsigned char *p_blockbuff = blockBuffer; + block2Hts(block,&head,&track,§or); + motorOn(); + if (!read && blockBuffer) { + /* copy data from data buffer into track buffer */ + for (copyCount=0; copyCount<(numSectors*512); copyCount++) { + *p_tbaddr = *p_blockbuff; + p_blockbuff++; + p_tbaddr++; + } + } + for (tries = 0;tries < 3;tries++) { + if (inportByte(fdcDir) & 0x80) { + diskChange = TRUE; + seek(1); /* clear "disk change" status */ + recalibrate(); + motorOff(); + kprint("FDC: Disk change detected. Trying again.\n"); + return fdcRw(block, blockBuffer, read, numSectors); + } + if (!seek(track)) { + motorOff(); + kprintf("FDC: Error seeking to track [%i]\n",block); + return FALSE; + } + outportByte(fdcCcr,0); + if (read) { + dmaXfer(2,tbaddr,numSectors*512,FALSE); + sendByte(cmdRead); + } + else { + dmaXfer(2,tbaddr,numSectors*512,TRUE); + sendByte(cmdWrite); + } + sendByte(head << 2); + sendByte(track); + sendByte(head); + sendByte(sector); + sendByte(2); /* 512 Int8s/sector */ + sendByte(geometry.spt); + if (geometry.spt == dg144Spt) { + sendByte(dg144Gap3rw); /* gap 3 size for 1.44M read/write */ + } + else { + sendByte(dg168Gap3rw); /* gap 3 size for 1.68M read/write */ + } + sendByte(0xff); /* DTL = unused */ + if (!waitFdc(TRUE)) { + kprint("Timed out, trying operation again after reset()\n"); + reset(); + return fdcRw(block, blockBuffer, read, numSectors); + } + if ((status[0] & 0xc0) == 0) break; /* worked! outta here! */ + recalibrate(); /* oops, try again... */ + } + motorOff(); + if (read && blockBuffer) { + p_blockbuff = blockBuffer; + p_tbaddr = (char *) 0x80000; + for (copyCount=0; copyCount<(numSectors*512); copyCount++) { + *p_blockbuff = *p_tbaddr; + p_blockbuff++; + p_tbaddr++; + } + } + return (tries != 3); + } + +void block2Hts(int block,int *head,int *track,int *sector) { + *head = (block % (geometry.spt * geometry.heads)) / (geometry.spt); + *track = block / (geometry.spt * geometry.heads); + *sector = block % geometry.spt + 1; + } + +void motorOn(void) { + if (motor == FALSE) { + outportByte(fdcDor,0x1c); + motor = TRUE; + } + } + +void motorOff(void) { + if (motor == TRUE) { + outportByte(fdcDor,0x1C); + motor = FALSE; + } + } + +bool seek(int track) { + if (fdcTrack == track) { + return(TRUE); + } + sendByte(cmdSeek); + sendByte(0); + sendByte(track); + if (!waitFdc(TRUE)) { + return(FALSE); + } + if ((sr0 != 0x20) || (fdcTrack != track)) { + return(FALSE); + } + else { + return(TRUE); + } + } + +bool readBlock(int block,Int8 *blockBuffer, unsigned long numSectors) { + int track=0, sector=0, head=0, track2=0, result=0, loop=0; + block2Hts(block, &head, &track, §or); + block2Hts(block+numSectors, &head, &track2, §or); + if (track!=track2) { + for (loop=0; loop +#include +#include +#include +#include +#include +#include + +static uInt8 kbdRead() { + unsigned long Timeout; + uInt8 Stat, Data; + + for (Timeout = 50000L; Timeout != 0; Timeout--) { + Stat = inportByte(0x64); + + /* loop until 8042 output buffer full */ + if ((Stat & 0x01) != 0) + { + Data = inportByte(0x60); + + /* loop if parity error or receive timeout */ + if((Stat & 0xC0) == 0) + return Data; + } + } + + return -1; +} + +static void kbdWrite(uInt16 port,uInt8 data) { + uInt32 timeout; + uInt8 stat; + + for (timeout = 500000L; timeout != 0; timeout--) + { + stat = inportByte(0x64); + + if ((stat & 0x02) == 0) + break; + } + + if (timeout != 0) + outportByte(port, data); + } + +static uInt8 kbdWriteRead(uInt16 port,uInt8 data, const char* expect) +{ + int RetVal; + + kbdWrite(port, data); + for (; *expect; expect++) + { + RetVal = kbdRead(); + if ((uInt8) *expect != RetVal) + { + return RetVal; + } + } + + return 0; +} + + + +int mouseInit() { + static uInt8 s1[] = { 0xF3, 0xC8, 0xF3, 0x64, 0xF3, 0x50, 0 }; + static uInt8 s2[] = { 0xF6, 0xE6, 0xF4, 0xF3, 0x64, 0xE8, 0x03, 0 }; + const uInt8* ch; + Int8 cmd = 0x0; + + kbdWrite(0x64,0xA8); + for (ch = s1; *ch; ch++) { + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, *ch,"\xFA"); + } + for (ch = s2; *ch; ch++) { + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, *ch,"\xFA"); + } + kbdWrite(0x64,0xD4); + if (kbdWriteRead(0x60,0xF2,"\xFA") != 0x0) { + kprintf("Error With Mouse\n"); + } + cmd = kbdRead(); + kprintf("CMD: [0x%X]\n",cmd); + kbdWrite(0x64, 0xD4); + kbdWriteRead(0x60, 0xF4,"\xFA"); + + setVector(&mouseISR, mVec+12, dPresent + dInt + dDpl3); + + outportByte(mPic, eoi); + outportByte(sPic, eoi); + irqEnable(12); + outportByte(mPic, eoi); + outportByte(sPic, eoi); + + kprintf("psm0 - Address: [0x%X]\n",&mouseISR); + + /* Return so we know everything went well */ + return(0x0); + } + +asm( + ".globl mouseISR \n" + "mouseISR: \n" + " pusha \n" /* Save all registers */ + " call mouseHandler \n" + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +void mouseHandler() { + kprintf("MOUSE!!!\n"); + + outportByte(mPic, eoi); + outportByte(sPic, eoi); + /* Return */ + return; + } + +/*** + $Log$ + Revision 1.1 2004/06/04 10:20:53 reddawg + mouse drive: fixed a few bugs works a bit better now + + END + ***/ + diff --git a/src/sys/isa/ne2k.c b/src/sys/isa/ne2k.c new file mode 100644 index 0000000..211c057 --- /dev/null +++ b/src/sys/isa/ne2k.c @@ -0,0 +1,366 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static int dp_pkt2user(struct device *dev,int page,int length); +static void getblock(struct device *dev,int page,size_t offset,size_t size,void *dst); +static int dp_recv(struct device *); + +static struct nicBuffer *ne2kBuffer = 0x0; + +asm( + ".globl ne2kISR \n" + "ne2kISR: \n" + " pusha \n" /* Save all registers */ + " call ne2kHandler \n" + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +/************************************************************************ + +Function: int ne2kInit(uInt32 ioAddr) +Description: This Function Will Initialize The Programmable Timer + +Notes: + +************************************************************************/ +int ne2kInit(uInt32 ioAddr) { + struct device *dev = (struct device *)kmalloc(sizeof(struct device)); + dev->ioAddr = 0x280; + dev->irq = 10; + + setVector(&ne2kISR, mVec+10, dPresent + dInt + dDpl3); + outportByte(mPic, eoi); + outportByte(sPic, eoi); + irqEnable(10); + outportByte(mPic, eoi); + outportByte(sPic, eoi); +// kprintf("ne0 - irq: %i, ioAddr: 0x%X MAC: %X:%X:%X:%X:%X:%X\n",dev->irq,dev->ioAddr,dev->net->mac[0] & 0xFF,dev->net->mac[1] & 0xFF,dev->net->mac[2] & 0xFF,dev->net->mac[3] & 0xFF,dev->net->mac[4] & 0xFF,dev->net->mac[5] & 0xFF); + + outportByte(dev->ioAddr + NE_CMD, 0x21); //stop mode + outportByte(dev->ioAddr + NE_DCR,0x29); // 0x29 data config reg + outportByte(dev->ioAddr + NE_RBCR0,0x00); // LOW byte count (remote) + outportByte(dev->ioAddr + NE_RBCR1,0x00); // HIGH byte count (remote) + outportByte(dev->ioAddr + NE_RCR,0x3C); // receive config reg + outportByte(dev->ioAddr + NE_TCR,0x02); // LOOP mode (temp) + outportByte(dev->ioAddr + NE_PSTART,startPage); // 0x26 PAGE start + outportByte(dev->ioAddr + NE_BNRY,startPage); // 0x26 BOUNDARY + outportByte(dev->ioAddr + NE_PSTOP,stopPage); // 0x40 PAGE stop + outportByte(dev->ioAddr + NE_ISR,0xFF); // interrupt status reg + outportByte(dev->ioAddr + NE_IMR,0x0B); + outportByte(dev->ioAddr + NE_CMD,0x61); // PAGE 1 regs + + outportByte(dev->ioAddr + DP_MAR0, 0xFF); + outportByte(dev->ioAddr + DP_MAR1, 0xFF); + outportByte(dev->ioAddr + DP_MAR2, 0xFF); + outportByte(dev->ioAddr + DP_MAR3, 0xFF); + outportByte(dev->ioAddr + DP_MAR4, 0xFF); + outportByte(dev->ioAddr + DP_MAR5, 0xFF); + outportByte(dev->ioAddr + DP_MAR6, 0xFF); + outportByte(dev->ioAddr + DP_MAR7, 0xFF); + outportByte(dev->ioAddr + DP_CURR, startPage + 1); + outportByte(dev->ioAddr + NE_CMD, 0x20); + inportByte(dev->ioAddr + DP_CNTR0); /* reset counters by reading */ + inportByte(dev->ioAddr + DP_CNTR1); + inportByte(dev->ioAddr + DP_CNTR2); + + outportByte(dev->ioAddr + NE_TCR, 0x00); + + outportByte(dev->ioAddr + NE_CMD, 0x0); + outportByte(dev->ioAddr + NE_DCR, 0x29); + + kfree(dev); + kprintf("Initialized"); + /* Return so we know everything went well */ + return(0x0); + } + +int PCtoNIC(struct device *dev,void *packet,int length) { + int i; + uInt16 *packet16 = (uInt16 *)packet; + uInt8 *packet8 = (uInt8 *)packet; + uInt8 word16 = 1; + + if ((inportByte(dev->ioAddr) & 0x04) == 0x04) { + kpanic("Device Not Ready\n"); + } + + if ((word16 == 1) && (length & 0x01)) { + length++; + } + + outportByte(dev->ioAddr+EN0_RCNTLO,(length & 0xFF)); + outportByte(dev->ioAddr+EN0_RCNTHI,(length >> 8)); + + outportByte(dev->ioAddr+EN0_RSARLO,0x0); + outportByte(dev->ioAddr+EN0_RSARHI,0x41); + + outportByte(dev->ioAddr,E8390_RWRITE+E8390_START); + + if (word16 != 0x0) { + for(i=0;iioAddr + NE_DATAPORT,packet16[i]); + } + } + else { + for(i=0;iioAddr + NE_DATAPORT,packet8[i]); + } + } + + for (i = 0;i<=100;i++) { + if ((inportByte(dev->ioAddr+EN0_ISR) & 0x40) == 0x40) { + break; + } + } + + outportByte(dev->ioAddr+EN0_ISR,0x40); + outportByte(dev->ioAddr+EN0_TPSR,0x41);//ei_local->txStartPage); + outportByte(dev->ioAddr+0x05,(length & 0xFF)); + outportByte(dev->ioAddr+0x06,(length >> 8)); + outportByteP(dev->ioAddr,0x26); + //kprintf("SENT\n"); + return(length); + } + +int NICtoPC(struct device *dev,void *packet,int length,int nic_addr) { + int i; + uInt16 *packet16 = (uInt16 *)packet; + + if (length & 0x01) + length++; + + + outportByte(dev->ioAddr+EN0_RCNTLO,(length & 0xFF)); + outportByte(dev->ioAddr+EN0_RCNTHI,(length >> 8)); + + outportByte(dev->ioAddr+EN0_RSARLO,nic_addr & 0xFF); + outportByte(dev->ioAddr+EN0_RSARHI,nic_addr >> 8); + + outportByte(dev->ioAddr,0x0A); + + for(i=0;iioAddr + NE_DATAPORT); + } + /* + for (i = 0;i<=100;i++) { + if ((inportByte(dev->ioAddr+EN0_ISR) & 0x40) == 0x40) + break; + } + */ + outportByte(dev->ioAddr+EN0_ISR,0x40); + return(length); + } + +void ne2kHandler() { + uInt16 isr = 0x0; + uInt16 status = 0x0; + struct device *dev = (struct device *)kmalloc(sizeof(struct device)); + dev->ioAddr = 0x280; + dev->irq = 10; + isr = inportByte(dev->ioAddr + NE_ISR); + if ((isr & 0x02) == 0x02) { + outportByte(dev->ioAddr + NE_ISR, 0x0A); + status = inportByte(0x280 + NE_TPSR); + //kprintf("Pack Transmitted, Status: [0x%X]\n",status); + } + if ((isr & 0x01) == 0x01) { + //kprintf("Status: [0x%X]\n",inportByte(dev->ioAddr + NE_ISR)); + if (dp_recv(dev)) { + kprintf("Error Getting Packet\n"); + } + outportByte(dev->ioAddr + NE_ISR, 0x05); + } + /* + else { + kprintf("Word: [0x%X]\n",isr); + } + */ + outportByte(dev->ioAddr + NE_IMR,0x0); + outportByte(mPic, eoi); + outportByte(sPic, eoi); + outportByte(dev->ioAddr + NE_IMR,0x0B); + kfree(dev); + return; + } + +static int dp_recv(struct device *dev) { + dp_rcvhdr_t header; + unsigned int pageno, curr, next; + int packet_processed = 0x0, r; + uInt16 eth_type; + + uInt32 length = 0x0;//UBU + + pageno = inportByte(dev->ioAddr + NE_BNRY) + 1; + if (pageno == stopPage) pageno = startPage; + + do { + outportByte(dev->ioAddr + NE_CMD, 0x40); + curr = inportByte(dev->ioAddr + NE_CURRENT); + outportByte(dev->ioAddr, 0x0); + if (curr == pageno) break; + getblock(dev, pageno, (size_t)0, sizeof(header), &header); + getblock(dev, pageno, sizeof(header) + 2*sizeof(ether_addr_t), sizeof(eth_type), ð_type); + + length = (header.dr_rbcl | (header.dr_rbch << 8)) - sizeof(dp_rcvhdr_t); + next = header.dr_next; + + //kprintf("length: [0x%X:0x%X:0x%X]\n",header.dr_next,header.dr_status,length); + + if (length < 60 || length > 1514) { + kprintf("dp8390: packet with strange length arrived: %d\n",length); + next= curr; + } + else if (next < startPage || next >= stopPage) { + kprintf("dp8390: strange next page\n"); + next= curr; + } + else if (header.dr_status & RSR_FO) { + kpanic("dp8390: fifo overrun, resetting receive buffer\n"); + next = curr; + } + else if (header.dr_status & RSR_PRX) { + r = dp_pkt2user(dev, pageno, length); + if (r != OK) { + kprintf("FRUIT"); + return(0x0); + } + + packet_processed = 0x1; + } + if (next == startPage) + outportByte(dev->ioAddr + NE_BNRY, stopPage - 1); + else + outportByte(dev->ioAddr + NE_BNRY, next - 1); + + pageno = next; + + } while (packet_processed == 0x0); + return(0x0); + } + +static void getblock(struct device *dev,int page,size_t offset,size_t size,void *dst) { + uInt16 *ha; + int i; + + ha = (uInt16 *) dst; + offset = page * DP_PAGESIZE + offset; + outportByte(dev->ioAddr + NE_RBCR0, size & 0xFF); + outportByte(dev->ioAddr + NE_RBCR1, size >> 8); + outportByte(dev->ioAddr + EN0_RSARLO, offset & 0xFF); + outportByte(dev->ioAddr + EN0_RSARHI, offset >> 8); + outportByte(dev->ioAddr + NE_CMD, E8390_RREAD | E8390_START); + + size /= 2; + for (i= 0; iioAddr + NE_DATAPORT); + outportByte(dev->ioAddr+EN0_ISR,0x40); + } + +static int dp_pkt2user(struct device *dev,int page,int length) { + int last; + struct nicBuffer *tmpBuf = 0x0; + + last = page + (length - 1) / DP_PAGESIZE; + + if (last >= stopPage) { + kprintf("A"); + } + else { + tmpBuf = ne2kAllocBuffer(length); + NICtoPC(dev,tmpBuf->buffer,length,page * DP_PAGESIZE + sizeof(dp_rcvhdr_t)); + } + return(OK); + } + +struct nicBuffer *ne2kAllocBuffer(int length) { + struct nicBuffer *tmpBuf = 0x0; + if (ne2kBuffer == 0x0) { + ne2kBuffer = (struct nicBuffer *)kmalloc(sizeof(struct nicBuffer)); + ne2kBuffer->next = 0x0; + ne2kBuffer->length = length; + ne2kBuffer->buffer = (char *)kmalloc(length); + return(ne2kBuffer); + } + else { + for (tmpBuf = ne2kBuffer;tmpBuf->next != 0x0;tmpBuf = tmpBuf->next); + tmpBuf->next = (struct nicBuffer *)kmalloc(sizeof(struct nicBuffer)); + tmpBuf = tmpBuf->next; + tmpBuf->next = 0x0; + tmpBuf->length = length; + tmpBuf->buffer = (char *)kmalloc(length); + return(tmpBuf); + } + return(0x0); + } + +struct nicBuffer *ne2kGetBuffer() { + struct nicBuffer *tmpBuf = 0x0; + tmpBuf = ne2kBuffer; + ne2kBuffer = ne2kBuffer->next; + return(tmpBuf); + } + +void ne2kFreeBuffer(struct nicBuffer *buf) { + kfree(buf->buffer); + kfree(buf); + return; + } + +/*** + + $Log$ + Revision 1.13 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.12 2004/05/21 12:48:22 reddawg + Cleaned up + + Revision 1.11 2004/05/19 04:07:42 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.10 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + END + ***/ + diff --git a/src/sys/isa/pit.c b/src/sys/isa/pit.c new file mode 100644 index 0000000..363dcfc --- /dev/null +++ b/src/sys/isa/pit.c @@ -0,0 +1,91 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +/***************************************************************************************** + + Function: int pitInit() + + Description: This Function Will Initialize The Programmable Timer + + Notes: + + 0040 r/w PIT counter 0, counter divisor (XT, AT, PS/2) + 0041 r/w PIT counter 1, RAM refresh counter (XT, AT) + 0042 r/w PIT counter 2, cassette & speaker (XT, AT, PS/2) + 0043 r/w PIT mode port, control word register for counters 0-2 + + bit 7-6 = 00 counter 0 select + = 01 counter 1 select (not PS/2) + = 10 counter 2 select + bit 5-4 = 00 counter latch command + = 01 read/write counter bits 0-7 only + = 10 read/write counter bits 8-15 only + = 11 read/write counter bits 0-7 first, then 8-15 + bit 3-1 = 000 mode 0 select + = 001 mode 1 select - programmable one shot + = x10 mode 2 select - rate generator + = x11 mode 3 select - square wave generator + = 100 mode 4 select - software triggered strobe + = 101 mode 5 select - hardware triggered strobe + bit 0 = 0 binary counter 16 bits + = 1 BCD counter + +*****************************************************************************************/ +int pitInit(int timerHz) { + outportByteP(0x43,0x36); + outportByteP(0x40,((1193180/timerHz) & 0xFF)); + outportByte(0x40,(((1193180/timerHz) >> 8) & 0xFF)); + + /* Print out information on the PIT */ + kprintf("pit0 - Port [0x%X], Timer Hz: [%iHz]\n",0x43,timerHz); + + /* Return so we know everything went well */ + return(0x0); + } + +/*** + + $Log$ + Revision 1.4 2004/05/21 12:48:22 reddawg + Cleaned up + + Revision 1.3 2004/05/20 22:51:09 reddawg + Cleaned Up Warnings + + Revision 1.2 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + + END + ***/ + diff --git a/src/sys/isa/rs232.c b/src/sys/isa/rs232.c new file mode 100644 index 0000000..52633fd --- /dev/null +++ b/src/sys/isa/rs232.c @@ -0,0 +1,43 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +void rs232Init() { + return; + } + +/*** + + $Log$ + Revision 1.2 2004/05/10 02:23:24 reddawg + Minor Changes To Source Code To Prepare It For Open Source Release + + + END + ***/ + diff --git a/src/sys/kernel/Makefile b/src/sys/kernel/Makefile new file mode 100644 index 0000000..c5c4da4 --- /dev/null +++ b/src/sys/kernel/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = endtask.o ap-boot.o smp.o spinlock.o bioscall.o ld.o time.o fork.o syscall.o elf.o file.o systemtask.o exec.o sched.o kpanic.o vitals.o ubthread.o timer.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -DNOBOOL -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -DNOBOOL -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/kernel/ap-boot.S b/src/sys/kernel/ap-boot.S new file mode 100644 index 0000000..2645aff --- /dev/null +++ b/src/sys/kernel/ap-boot.S @@ -0,0 +1,105 @@ +/* + * Okay, this file contains the code that's going to bootstrap the AP cpus + */ + + + .globl ap_trampoline_start,ap_trampoline_end + .text + .code16 +ap_trampoline_start: + cli + cld + + movw %cs,%ax // The CPU knows its CS already, so lets use it for the other segments + movw %ax,%ds + movw %ax,%es + movw %ax,%ss + + // Do some bochs-specific bullshit + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + //lgdt ap_gdt; + lgdt ap_trampoline_gdt_limit - ap_trampoline_start + movl %cr0,%eax + orl $0x1,%eax + movl %eax,%cr0 // PMODE! + +.code32 + .byte 0x66 + ljmp $0x08,$(ap_trampoline_32 - ap_trampoline_start) // 0x08 == KERNEL_CS + +ap_trampoline_32: + mov $0x32,%al // '2' + mov $0xe9,%dx + outb %al,%dx + + mov $0x10,%ax + mov %ax,%ds + mov %ax,%es + mov %ax,%fs + mov %ax,%gs + mov %ax,%ss + + // Spinlock + mov ap_trampoline_spl - ap_trampoline_start,%edi +ap_spl: + //cmp $1,(%edi) + //je ap_spl + + mov $1,%eax // Value to be set + xchgl (%edi),%eax + cmp $0,%eax + je ap_spl + // /Spinlock + + mov $0x30,%al // '0' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_stackptr - ap_trampoline_start,%ebx + mov %ebx,%esp + add $0x1000,%ebx + mov %ebx,ap_trampoline_stackptr - ap_trampoline_start + + mov $0x31,%al // '1' + mov $0xe9,%dx + outb %al,%dx + + // spinunlock + mov $0,%eax + mov ap_trampoline_spl - ap_trampoline_start,%edi + xchgl (%edi),%eax + // /spinunlock + + mov $0x33,%al // '3' + mov $0xe9,%dx + outb %al,%dx + + mov ap_trampoline_epoint,%eax + call *%eax +1: + hlt + jmp 1b // Halt if we ever get here somehow + + // Stack.. This sucks, since CPU initialization isn't serialized +ap_trampoline_stackptr: + .long 0x10000 // 256KB +ap_trampoline_epoint: + .long c_ap_boot + +ap_trampoline_spl: + .long 0 +ap_gdt: + .long ubixGDT + + // GDT +ap_trampoline_gdt: + .word 0 +ap_trampoline_gdt_limit: + .word 128 // Room for 32 descriptors +ap_trampoline_gdt_base: + .long 0x20000 // 128KB (move this later) + + +ap_trampoline_end: diff --git a/src/sys/kernel/bioscall.c b/src/sys/kernel/bioscall.c new file mode 100644 index 0000000..03910a7 --- /dev/null +++ b/src/sys/kernel/bioscall.c @@ -0,0 +1,105 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + + +asm ( + ".globl bios16Code\n" + "bios16Code: \n" + "int $0x10 \n" + "int $0x69 \n" + ); + + +void biosCall(int biosInt,int eax,int ebx,int ecx,int edx,int esi,int edi,int es,int ds) { + short segment = 0x0,offset = 0x0; + uInt32 tmpAddr = (uInt32)&bios16Code; + kTask_t *newProcess = 0x0; + + offset = tmpAddr & 0xF; // lower 4 bits + segment = tmpAddr >> 4; + + newProcess = schedNewTask(); + + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = (uInt32)kmalloc(0x2000)+0x2000; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (uInt32)_current->tss.cr3;//(uInt32)vmmCreateVirtualSpace(newProcess->id); + newProcess->tss.eip = offset & 0xFFFF; + newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; + newProcess->tss.eax = eax & 0xFFFF; + newProcess->tss.ebx = ebx & 0xFFFF; + newProcess->tss.ecx = ecx & 0xFFFF; + newProcess->tss.edx = edx & 0xFFFF; + newProcess->tss.esp = 0x1000 & 0xFFFF; + newProcess->tss.ebp = 0x1000 & 0xFFFF; + newProcess->tss.esi = esi & 0xFFFF; + newProcess->tss.edi = edi & 0xFFFF; + newProcess->tss.es = es & 0xFFFF; + newProcess->tss.cs = segment & 0xFFFF; + newProcess->tss.ss = 0x1000 & 0xFFFF; + newProcess->tss.ds = ds & 0xFFFF; + newProcess->tss.fs = 0x0 & 0xFFFF; + newProcess->tss.gs = 0x0 & 0xFFFF; + newProcess->tss.ldt = 0x0 & 0xFFFF; + newProcess->tss.trace_bitmap = 0x0 & 0xFFFF; + newProcess->tss.io_map = 0x0 & 0xFFFF; + newProcess->tss.io_map = sizeof(struct tssStruct)-8192; + newProcess->oInfo.v86Task = 0x1; + newProcess->state = READY; + + while (newProcess->state > 0); + + return; + } + +/*** + $Log$ + Revision 1.4 2004/06/15 12:24:07 reddawg + Cleaned Up + + Revision 1.3 2004/05/19 04:07:42 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + END + ***/ + diff --git a/src/sys/kernel/elf.c b/src/sys/kernel/elf.c new file mode 100644 index 0000000..e813e18 --- /dev/null +++ b/src/sys/kernel/elf.c @@ -0,0 +1,120 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +const struct { + char *elfTypeName; + uInt32 id; + } elfType[] = { + { "ET_NONE", 0 }, + { "ET_REL", 1 }, + { "ET_EXEC", 2 }, + { "ET_DYN", 3 }, + { "ET_CORE", 4 }, + { "ET_LOPROC", 0xff00 }, + { "ET_HIPROC", 0xffff }, + }; + +const struct { + char *phTypeName; + uInt32 id; + } elfPhType[] = { + { "PT_NULL", 0 }, + { "PT_LOAD", 1 }, + { "PT_DYNAMIC", 2 }, + { "PT_INTERP", 3 }, + { "PT_NOTE", 4 }, + { "PT_SHLIB", 5 }, + { "PT_PHDR", 6 }, + { "PT_LOPROC", 0x70000000 }, + { "PT_HIPROC", 0x7fffffff }, + }; + +const struct { + char *shTypeName; + uInt32 id; + } elfShType[] = { + {"SHT_NULL", 0 }, + {"SHT_PROGBITS", 1 }, + {"SHT_SYMTAB", 2 }, + {"SHT_STRTAB", 3 }, + {"SHT_RELA", 4 }, + {"SHT_HASH", 5 }, + {"SHT_DYNAMIC", 6 }, + {"SHT_NOTE", 7 }, + {"SHT_NOBITS", 8 }, + {"SHT_REL", 9 }, + {"SHT_SHLIB", 10 }, + {"SHT_DYNSYM", 11 }, + }; + +const struct { + char *relTypeName; + uInt32 id; + } elfRelType[] = { + {"R_386_NONE", 0 }, + {"R_386_32", 1 }, + {"R_386_PC32", 2 }, + {"R_386_GOT32", 3 }, + {"R_386_PLT32", 4 }, + {"R_386_COPY", 5 }, + {"R_386_GLOB_DAT", 6 }, + {"R_386_JMP_SLOT", 7 }, + {"R_386_RELATIVE", 8 }, + {"R_386_GOTOFF", 9 }, + {"R_386_GOTPC", 10 }, + }; + + +char *elfGetShType(int shType) { + return((char *)elfShType[shType].shTypeName); + } + +char *elfGetPhType(int phType) { + return((char *)elfPhType[phType].phTypeName); + } + +char *elfGetRelType(int relType) { + return((char *)elfRelType[relType].relTypeName); + } + +/*** + $Log$ + Revision 1.4 2004/06/15 12:24:07 reddawg + Cleaned Up + + Revision 1.3 2004/06/12 01:27:26 reddawg + shared objects: yes we almost fully support shared objects + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + END + ***/ + diff --git a/src/sys/kernel/endtask.c b/src/sys/kernel/endtask.c new file mode 100644 index 0000000..2e6ccbf --- /dev/null +++ b/src/sys/kernel/endtask.c @@ -0,0 +1,54 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +void endTask(pidType pid) { + vmmFreeProcessPages(pid); + _current->state = DEAD; + schedYield(); /* I'm pretty sure we need this if the thread is ending itself */ + return; + } + +/*** + $Log$ + Revision 1.3 2004/06/15 12:24:07 reddawg + Cleaned Up + + Revision 1.2 2004/05/21 15:49:13 reddawg + The os does better housekeeping now when a task is exited + + Revision 1.1 2004/05/19 17:28:28 reddawg + Added the correct endTask Procedure + + + END + ***/ diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c new file mode 100644 index 0000000..cd13018 --- /dev/null +++ b/src/sys/kernel/exec.c @@ -0,0 +1,553 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/***************************************************************************************** + + Function: execThread(void (*)(void),int,char *); + Description: This function will create a thread from code in the current memory space + + Notes: + + 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space + so do not use out side of kernel space + +*****************************************************************************************/ +uInt32 execThread(void (* tproc)(void),int stack,char *arg) { + kTask_t * newProcess; + /* Find A New Thread */ + newProcess = schedNewTask(); + + /* Set All The Correct Thread Attributes */ + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = 0x0; + newProcess->tss.ss0 = 0x0; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (unsigned int)kernelPageDirectory; + newProcess->tss.eip = (unsigned int)tproc; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = stack; + newProcess->tss.ebp = stack; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; + + newProcess->tss.es = 0x10; + newProcess->tss.cs = 0x08; + newProcess->tss.ss = 0x10; + newProcess->tss.ds = 0x10; + newProcess->tss.fs = 0x10; + newProcess->tss.gs = 0x10; + newProcess->tss.ldt = 0x18; + + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + newProcess->oInfo.vmStart = 0x6400000; + + /* Set up default stack for thread here filled with arg list 3 times */ + asm volatile( + "pusha \n" + "movl %%esp,%%ecx \n" + "movl %1,%%eax \n" + "movl %%eax,%%esp \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "movl %%esp,%%eax \n" + "movl %%eax,%1 \n" + "movl %%ecx,%%esp \n" + "popa \n" + : + : "b" (arg),"m" (newProcess->tss.esp) + ); + + /* Put new thread into the READY state */ + newProcess->state = READY; + + /* Return with the new process ID */ + return((uInt32)newProcess); + } + +/***************************************************************************************** + + Function: void execFile(char *file); + Description: This Function Executes A Kile Into A New VM Space With Out + Having To Fork + Notes: + + 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few + Memory Leaks The Memory Allocated To Load The Binary Into Is + Now Unmapped So It Can Be Used Again And Not Held Onto Until + The Program Exits + + 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up + The Freshly Allocated Pages With The Correct Permissions + +*****************************************************************************************/ +void execFile(char *file,int argc,char **argv,int console) { + + int i = 0x0; + int x = 0x0; + uInt32 eStart = 0x0; + char *newLoc = 0x0; + char *linker = 0x0; + + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + + /* Get A New Task For This Proccess */ + _current = schedNewTask(); + _current->gid = 0; + _current->uid = 0; + + /* Now We Must Create A Virtual Space For This Proccess To Run In */ + _current->tss.cr3 = (uInt32)vmmCreateVirtualSpace(_current->id); + + /* To Better Load This Application We Will Switch Over To Its VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(_current->tss.cr3)) + ); + + /* Lets Find The File */ + tmpFd = fopen(file,"r"); + + /* If We Dont Find the File Return */ + if (!tmpFd) { + // kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + if (tmpFd->perms == 0) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + fread(binaryHeader,sizeof(elfHeader),1,tmpFd); + + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eType != 2) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + fseek(tmpFd,binaryHeader->ePhoff,0); + fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i=0;iePhnum;i++) { + if (programHeader[i].phType == 1) { + newLoc = (char *)programHeader[i].phVaddr; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x=0;x<=(programHeader[i].phMemsz+4095);x += 0x1000) { + if (vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x)) == 0x0) { + kpanic("Error: vmmFindFreePage Failed\n"); + } + kmemset(((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); + } + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); + /* Now Load Section To Memory */ + fseek(tmpFd,programHeader[i].phOffset,0); + fread(newLoc,programHeader[i].phFilesz,1,tmpFd); + } + else if (programHeader[i].phType == 2) { + newLoc = (char *)programHeader[i].phVaddr; + //elfDynamicS = (elfDynamic *)programHeader[i].phVaddr; + fseek(tmpFd,programHeader[i].phOffset,0); + fread(newLoc,programHeader[i].phFilesz,1,tmpFd); + } + else if (programHeader[i].phType == 3) { + linker = (char *)kmalloc(programHeader[i].phMemsz); + fseek(tmpFd,programHeader[i].phOffset,0); + fread(linker,programHeader[i].phFilesz,1,tmpFd); + } + } + + + /* Set Virtual Memory Start */ + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); + /* Get The Starting Point */ + eStart = binaryHeader->eEntry; + + /* Now Lets Make A Clean Stack */ + newLoc = (char *)0x5DB000; + vmmRemapPage(vmmFindFreePage(_current->id),0x5DC000); + vmmSetPageAttribute(0x5DC000,(pageDefault | pageStack)); + vmmRemapPage(vmmFindFreePage(_current->id),0x5DB000); + vmmSetPageAttribute(0x5DB000,(pageDefault | pageStack)); + vmmRemapPage(vmmFindFreePage(_current->id),0x5DA000); + vmmSetPageAttribute(0x5DA000,(pageDefault | pageStack)); + vmmRemapPage(vmmFindFreePage(_current->id),0x5D9000); + vmmSetPageAttribute(0x5D9000,(pageDefault | pageStack)); + + i = 0x5DD000; + + vmmRemapPage(vmmFindFreePage(_current->id),0x5D3000); + vmmSetPageAttribute(0x5D3000,(pageDefault | pageStack)); + vmmRemapPage(vmmFindFreePage(_current->id),0x5D2000); + vmmSetPageAttribute(0x5D2000,(pageDefault | pageStack)); + vmmRemapPage(vmmFindFreePage(_current->id),0x5D1000); + vmmSetPageAttribute(0x5D1000,(pageDefault | pageStack)); + vmmRemapPage(vmmFindFreePage(_current->id),0x5D0000); + vmmSetPageAttribute(0x5D0000,(pageDefault | pageStack)); + + /* Set All The Proper Information For The Task */ + _current->tss.back_link = 0x0; + _current->tss.esp0 = 0x5D4000; + _current->tss.ss0 = 0x10; + _current->tss.esp1 = 0x0; + _current->tss.ss1 = 0x0; + _current->tss.esp2 = 0x0; + _current->tss.ss2 = 0x0; + _current->tss.eip = (long)eStart; + _current->tss.eflags = 0x206; + _current->tss.esp = i-12; + _current->tss.ebp = i; + _current->tss.esi = 0x0; + _current->tss.edi = 0x0; + + /* Set these up to be ring 3 tasks */ + _current->tss.es = 0x30+3; + _current->tss.cs = 0x28+3; + _current->tss.ss = 0x30+3; + _current->tss.ds = 0x30+3; + _current->tss.fs = 0x30+3; + _current->tss.gs = 0x30+3; + + _current->tss.ldt = 0x18; + _current->tss.trace_bitmap = 0x0000; + _current->tss.io_map = 0x8000; + _current->state = READY; + + /* Set up the defaault stack to be used by this new process */ + + /* + asm volatile( + "pusha \n" + "movl %%esp,%%edx \n" + "movl %2,%%ecx \n" + "movl %%ecx,%%esp \n" + "pushl $0x0 \n" + "pushl $0x0 \n" + "pushl $0x0 \n" + "pushl $0x0 \n" + "pushl %%ebx \n" + "pushl %%eax \n" + "movl %%esp,%%ecx \n" + "movl %%ecx,%2 \n" + "movl %%edx,%%esp \n" + "popa \n" + : + : "a" (argc), "b" (argv), "m" (_current->tss.esp) + ); + */ + + kfree(binaryHeader); + kfree(programHeader); + fclose(tmpFd); + + /* Switch Back To The Kernels VM Space */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + : : "d" ((uInt32 *)(kernelPageDirectory)) + ); + + /* Finally Return */ + return; + } + +/***************************************************************************************** + + Function: void sysExec(); + Description: This Is The System Call To Execute A New Task + + Notes: + 04-22-03 - It Now Loads Sections Not The Full File + +*****************************************************************************************/ +void sysExec(char *file,int argc,char **argv) { + int i = 0x0; + int x = 0x0; + uInt32 eStart = 0x0; + uInt32 *tmp = 0x0; + uInt32 ldAddr = 0x0; + char *newLoc = 0x0; + + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynamic *elfDynamicS = 0x0; + + + tmpFd = fopen(file,"r"); + + /* If We Dont Find the File Return */ + if (tmpFd == 0x0) { + kprintf("Couldn't open file %s\n",file); + return; + } + if (tmpFd->perms == 0) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + fclose(tmpFd); + return; + } + + /* Load ELF Header */ + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + fread(binaryHeader,sizeof(elfHeader),1,tmpFd); + /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ + + /* Check If App Is A Real Application */ + if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eType != 2) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + else if (binaryHeader->eEntry == 0x300000) { + //kprintf("Exec Format Error: Binary File Not Executable.\n"); + kfree(binaryHeader); + fclose(tmpFd); + return; + } + + /* Load The Program Header(s) */ + programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + fseek(tmpFd,binaryHeader->ePhoff,0); + fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); + + sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); + fseek(tmpFd,binaryHeader->eShoff,0); + fread(sectionHeader,sizeof(elfSectionHeader)*binaryHeader->eShnum,1,tmpFd); + + /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + for (i=0;iePhnum;i++) { + if (programHeader[i].phType == 1) { + newLoc = (char *)programHeader[i].phVaddr; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x=0;x<(programHeader[i].phMemsz+4095);x+=0x1000) { + vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x)); + kmemset(((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); + } + _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); + /* Now Load Section To Memory */ + fseek(tmpFd,programHeader[i].phOffset,0); + fread(newLoc,programHeader[i].phFilesz,1,tmpFd); + } + else if (programHeader[i].phType == 2) { + newLoc = (char *)programHeader[i].phVaddr; + elfDynamicS = (elfDynamic *)programHeader[i].phVaddr; + fseek(tmpFd,programHeader[i].phOffset,0); + fread(newLoc,programHeader[i].phFilesz,1,tmpFd); + } + else if (programHeader[i].phType == 3) { + ldAddr = ldEnable(); + } + } + + for (i=0;i<12;i++) { + if (elfDynamicS[i].dynVal == 0x3) { + tmp = (uInt32 *)elfDynamicS[i].dynPtr; + tmp[2] = (uInt32)ldAddr; + tmp[1] = (uInt32)tmpFd; + break; + } + } + + /* Get The Starting Point */ + eStart = binaryHeader->eEntry; + + /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ + kfree(binaryHeader); + kfree(programHeader); + + /* Jump To Start Of New Binary */ + asm volatile( + "pushl %1 \n" + "pushl %%eax \n" + "call *%0 \n" + : + : "g" (eStart),"g" (argv),"a" (argc) + ); + } + +/*** + $Log$ + Revision 1.39 2004/06/18 15:29:38 reddawg + zero out memory + + Revision 1.38 2004/06/18 15:18:04 reddawg + bug fixes: did some double checking on pointers and 0x0 out memory + + Revision 1.37 2004/06/17 13:05:14 reddawg + dynamic linking: fixed int6 issue problem was multiple rel's + + Revision 1.36 2004/06/17 12:28:56 reddawg + debug: show me the output after this is a tested + + Revision 1.35 2004/06/17 02:58:49 reddawg + Cleaned Out Dead Code + + Revision 1.34 2004/06/17 02:19:29 reddawg + Cleaning out dead code + + Revision 1.32 2004/06/17 02:00:53 reddawg + Test + + Revision 1.31 2004/06/17 01:57:52 reddawg + Test + + Revision 1.30 2004/06/17 01:37:00 reddawg + TCA: test now + + Revision 1.29 2004/06/16 17:46:42 reddawg + Cleaned Dead Code + + Revision 1.28 2004/06/16 17:04:13 reddawg + ld.so: rest of the commit + + Revision 1.25 2004/06/15 23:46:05 reddawg + Nig Nog + + Revision 1.24 2004/06/14 13:16:26 reddawg + Works now 0x1000 line 272 + + Revision 1.21 2004/06/14 12:45:12 reddawg + Fixed!!! + + Revision 1.20 2004/06/14 12:40:48 reddawg + Try now + + Revision 1.18 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.17 2004/06/12 01:27:26 reddawg + shared objects: yes we almost fully support shared objects + + Revision 1.16 2004/06/10 13:08:00 reddawg + Minor Bug Fixes + + Revision 1.15 2004/06/04 13:29:56 reddawg + libc: modified mkdir(); interface + kpanic: kPanic(); now says kPanic: %s + system: now reboots when receives message for reboot + also when command start sde is received by system the STD is started + + Revision 1.14 2004/06/01 00:04:53 reddawg + Try now mark + + Revision 1.13 2004/05/25 22:44:08 reddawg + Removed debug code + + Revision 1.12 2004/05/22 21:46:37 reddawg + Fixed some bugs + + Revision 1.11 2004/05/22 02:10:42 reddawg + Added Code To Debug ISsue + + Revision 1.10 2004/05/21 21:15:04 reddawg + Fixed a few bugs which prevented the system from loadin + + Revision 1.9 2004/05/21 15:34:23 reddawg + Fixed a couple of typo + + Revision 1.8 2004/05/21 15:32:06 reddawg + Changed the sys fileExec works it just loads sections needed now instead of fully should be a performance increase of about 40% + + Revision 1.7 2004/05/19 04:31:12 reddawg + Fixed some typedef problems in exec + + Revision 1.6 2004/05/19 04:07:42 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.5 2004/05/19 01:21:29 reddawg + Tweaked + + Revision 1.4 2004/05/15 02:30:28 reddawg + Lots of changes + + Revision 1.3 2004/05/02 03:19:51 reddawg + Added Spinlock Provision For SMP + + Revision 1.2 2004/04/30 14:16:04 reddawg + Fixed all the datatypes to be consistant uInt8,uInt16,uInt32,Int8,Int16,Int32 + + Revision 1.1.1.1 2004/04/15 12:07:18 reddawg + UbixOS v1.0 + + Revision 1.44 2004/04/13 16:16:44 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/src/sys/kernel/file.c b/src/sys/kernel/file.c new file mode 100644 index 0000000..22fcc87 --- /dev/null +++ b/src/sys/kernel/file.c @@ -0,0 +1,271 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +fileDescriptor *fdTable = 0x0; + +/* These Are Temporary */ +int sprintf(char *buf,const char *fmt, ...); +char getch(); + + + +/************************************************************************ + +Function: int feof(fileDescriptor *fd) +Description: Check A File Descriptor For EOF And Return Result +Notes: + +************************************************************************/ +int feof(fileDescriptor *fd) { + if (fd->status == fdEof) { + return(-1); + } + return(0); + } + +/************************************************************************ + +Function: int fputc(int ch,fileDescriptor *fd) +Description: This Will Write Character To FD +Notes: + +************************************************************************/ +int fputc(int ch,fileDescriptor *fd) { + fileDescriptor *tmpFd = 0x0; + /* Search For File Descriptor */ + for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { + /* If Found Return Next Char */ + if (tmpFd == fd) { + ch = tmpFd->mp->fs->vfsWrite(tmpFd,(char *)ch,tmpFd->offset,1); + tmpFd->offset++; + return(ch); + } + } + /* Return NULL If FD Is Not Found */ + return(0x0); + } + +/************************************************************************ + +Function: int fgetc(fileDescriptor *fd) +Description: This Will Return The Next Character In A FD Stream +Notes: + +************************************************************************/ +int fgetc(fileDescriptor *fd) { + int ch = 0x0; + fileDescriptor *tmpFd = 0x0; + /* Search For File Descriptor */ + for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { + /* If Found Return Next Char */ + if (tmpFd == fd) { + tmpFd->mp->fs->vfsRead(tmpFd,(char *)&ch,tmpFd->offset,1); + tmpFd->offset++; + return(ch); + } + } + /* Return NULL If FD Is Not Found */ + return(0x0); + } + +size_t fread(void *ptr,int size,int nmemb,fileDescriptor *fd) { + fileDescriptor *tmpFd = 0x0; + /* Search For File Descriptor */ + for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { + /* If Found Return Next Char */ + if (tmpFd == fd) { + if (nmemb == 0x0) nmemb = 1; //Temp Fix + tmpFd->mp->fs->vfsRead(tmpFd,ptr,tmpFd->offset,size * nmemb); + tmpFd->offset += size * nmemb; + } + } + return(0x0); + } + +size_t fwrite(void *ptr,int size,int nmemb,fileDescriptor *fd) { + fileDescriptor *tmpFd = 0x0; + /* Search For File Descriptor */ + for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { + /* If Found Return Next Char */ + if (tmpFd == fd) { + tmpFd->mp->fs->vfsWrite(tmpFd,ptr,tmpFd->offset,size * nmemb); + tmpFd->offset += size * nmemb; + } + } + return(0x0); + } + +/************************************************************************ + +Function: void sysFopen(); +Description: Opens A File Descriptor For A User Task +Notes: + +************************************************************************/ +void sysFopen(char *file,char *flags,userFileDescriptor *userFd) { + userFd->fd = fopen(file,flags); + if (userFd->fd != 0x0) { + userFd->fdSize = userFd->fd->size; + } + /* Return */ + return; + } + +#if 0 +size_t fread(void *ptr, int size, int nmemb,fileDescriptor *fd) { + + /* YO! what about EOF's in the middle of reading?? */ + + int i = 0x0; + char *data = (char *)ptr; + for (i=0;ifd); + /* Return */ + return; + } + +void sysFwrite(char *ptr,int size,userFileDescriptor *userFd) { + if (userFd->fd == 0x0) { + kprintf(ptr); + } + else { + fwrite(ptr,size,1,userFd->fd); + } + return; + } + +/************************************************************************ + +Function: void sysFclse(); +Description: Closes A File Descriptor For A User Task +Notes: + +************************************************************************/ +void sysFclose(userFileDescriptor *userFd,int *status) { + *status = fclose(userFd->fd); + /* Return */ + return; + } + +void sysFgetc(int *ptr,userFileDescriptor *userFd) { + fileDescriptor *tmpFd = 0x0; + asm("sti"); + tmpFd = userFd->fd; + if (userFd->fd == 0) { + ptr[0] = (int) getch(); + } + else { + ptr[0] = (int) fgetc(tmpFd); + } + } + +void sysRmDir() { + return; + } + +int fseek(fileDescriptor *tmpFd,long offset,int whence) { + tmpFd->offset = offset+whence; + return(tmpFd->offset); + } + +void sysFseek(userFileDescriptor *userFd,long offset,int whence) { + userFd->fd->offset = offset+whence; + } + +void sysChDir(const char *path) { + sprintf(_current->oInfo.cwd,path); + } + +void sysUnlink(const char *path,int *retVal) { + *retVal = unlink(path); + } + +/************************************************************************ + +Function: void chDir(const char *path); +Description: Changes Current Working Dir +Notes: + +************************************************************************/ +void chDir(const char *path) { + if (_current->oInfo.fileInfo.cwd != 0x0) { + kfree(_current->oInfo.fileInfo.cwd); + } + _current->oInfo.fileInfo.cwd = verifyDir(path); + return; + } + +/************************************************************************ + +Function: char *verifyDir(const char *path); +Description: Changes Current Working Dir +Notes: + +************************************************************************/ +char *verifyDir(const char *path) { + return(0x0); + } + +/*** + $Log$ + Revision 1.4 2004/06/16 19:56:35 reddawg + Moved fclose + + Revision 1.3 2004/06/16 16:31:58 reddawg + ld.so: the dynamic linker works and has been tested + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + + + END + ***/ + diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c new file mode 100644 index 0000000..8239706 --- /dev/null +++ b/src/sys/kernel/fork.c @@ -0,0 +1,118 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +/************************************************************************ + +Function: void sysFork(); +Description: This Function Forks A Task +Notes: + +08/01/02 - This Seems To Be Working Fine However I'm Not Sure If I + Chose The Best Path To Impliment It I Guess We Will See + What The Future May Bring + +************************************************************************/ +asm( + ".globl sysFork \n" + "sysFork: \n" + " xor %eax,%eax \n" + " call schedNewTask \n" + " testl %eax,%eax \n" + " je 1f \n" + " pushl %esi \n" + " pushl %edi \n" + " pushl %ebp \n" + " pushl %eax \n" + " call forkCopyProcess \n" + " movl %eax,(%ebx) \n" + " addl $16,%esp \n" + "1: \n" + " ret \n" + ); + +int forkCopyProcess(struct taskStruct *newProcess,long ebp,long edi,long esi,long none,long ebx,long ecx,long edx,long eip,long cs,long eflags,long esp,long ss) { + + /* Set Up New Tasks Information */ + newProcess->uid = _current->uid; + newProcess->gid = _current->gid; + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eflags = eflags; + newProcess->tss.eax = 0x0; + newProcess->tss.ebx = ebx; + newProcess->tss.ecx = ecx; + newProcess->tss.edx = edx; + newProcess->tss.esi = esi; + newProcess->tss.edi = edi; + newProcess->tss.ebp = ebp; + newProcess->tss.esp = esp; + newProcess->tss.cs = cs & 0xFF; + newProcess->tss.ss = ss & 0xFF; + newProcess->tss.ds = _current->tss.ds & 0xFF; + newProcess->tss.fs = _current->tss.fs & 0xFF; + newProcess->tss.gs = _current->tss.gs & 0xFF; + newProcess->tss.es = _current->tss.es & 0xFF; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + newProcess->tss.eip = eip; + /* Create A Copy Of The VM Space For New Task */ + newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); + newProcess->oInfo.curDir = _current->oInfo.curDir; + newProcess->oInfo.container = _current->oInfo.container; + newProcess->state = READY; + /* Return Id of Proccess */ + return(newProcess->id); + } + +/*** + $Log$ + Revision 1.5 2004/06/15 12:24:07 reddawg + Cleaned Up + + Revision 1.4 2004/06/10 13:08:00 reddawg + Minor Bug Fixes + + Revision 1.3 2004/05/19 14:32:06 reddawg + Cleaned up some warning from leaving out typedefs + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + END + ***/ diff --git a/src/sys/kernel/kpanic.c b/src/sys/kernel/kpanic.c new file mode 100644 index 0000000..9c29c84 --- /dev/null +++ b/src/sys/kernel/kpanic.c @@ -0,0 +1,76 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +/************************************************************************ + +Function: int kpanic() + +Description: This function is used to cause a kernel panic + +Notes: + +************************************************************************/ +void kpanic(const char *fmt, ...) { + int i = 0x0; + char buf[1024]; + vaList args; + + vaStart(args, fmt); + i = vsprintf(buf,fmt,args); + vaEnd(args); + kprintf("kPanic: %s",buf); + + /* Halt The System */ + while (1) { + asm("hlt"); + } + } + +/*** + $Log$ + Revision 1.4 2004/06/04 13:29:56 reddawg + libc: modified mkdir(); interface + kpanic: kPanic(); now says kPanic: %s + system: now reboots when receives message for reboot + also when command start sde is received by system the STD is started + + Revision 1.3 2004/05/21 12:39:19 reddawg + Cleaned Up + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + + END + ***/ + diff --git a/src/sys/kernel/ld.c b/src/sys/kernel/ld.c new file mode 100644 index 0000000..5c34c6a --- /dev/null +++ b/src/sys/kernel/ld.c @@ -0,0 +1,228 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +uInt32 ldEnable() { + int i = 0x0; + int x = 0x0; + int rel = 0x0; + int sym = 0x0; + char *newLoc = 0x0; + char *shStr = 0x0; + char *dynStr = 0x0; + uInt32 *reMap = 0x0; + fileDescriptor *ldFd = 0x0; + elfHeader *binaryHeader = 0x0; + elfProgramHeader *programHeader = 0x0; + elfSectionHeader *sectionHeader = 0x0; + elfDynSym *relSymTab = 0x0; + elfPltInfo *elfRel = 0x0; + + ldFd = fopen("ld.so","rb"); + + if (ldFd == 0x0) { + kprintf("Can not open ld.so\n"); + } + + fseek(ldFd,0x0,0x0); + binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); + fread(binaryHeader,sizeof(elfHeader),1,ldFd); + + programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); + fseek(ldFd,binaryHeader->ePhoff,0); + fread(programHeader,sizeof(elfSectionHeader),binaryHeader->ePhnum,ldFd); + + sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum); + fseek(ldFd,binaryHeader->eShoff,0); + fread(sectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,ldFd); + + shStr = (char *)kmalloc(sectionHeader[binaryHeader->eShstrndx].shSize); + fseek(ldFd,sectionHeader[binaryHeader->eShstrndx].shOffset,0); + fread(shStr,sectionHeader[binaryHeader->eShstrndx].shSize,1,ldFd); + + for (i=0;iePhnum;i++) { + switch (programHeader[i].phType) { + case 1: + case 2: + newLoc = (char *)programHeader[i].phVaddr + LD_START; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Correct + Settings so it helps us in the future + */ + for (x=0;x < ((programHeader[i].phMemsz)+4095);x += 0x1000) { + vmmRemapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START)); + kmemset(((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); + } + /* Now Load Section To Memory */ + fseek(ldFd,programHeader[i].phOffset,0x0); + fread(newLoc,programHeader[i].phFilesz,1,ldFd); + break; + default: + kprintf("Unhandled Header\n"); + break; + } + } + + for (i=0x0;ieShnum;i++) { + switch (sectionHeader[i].shType) { + case 3: + if (!kstrcmp((shStr + sectionHeader[i].shName),".dynstr")) { + dynStr = (char *)kmalloc(sectionHeader[i].shSize); + fseek(ldFd,sectionHeader[i].shOffset,0x0); + fread(dynStr,sectionHeader[i].shSize,1,ldFd); + } + break; + case 9: + elfRel = (elfPltInfo *)kmalloc(sectionHeader[i].shSize); + fseek(ldFd,sectionHeader[i].shOffset,0x0); + fread(elfRel,sectionHeader[i].shSize,1,ldFd); + + for (x=0x0;xeEntry + LD_START; + + kfree(dynStr); + kfree(shStr); + kfree(relSymTab); + kfree(sectionHeader); + kfree(programHeader); + kfree(binaryHeader); + fclose(ldFd); + + return((uInt32)i); + } + +/*** + $Log$ + Revision 1.26 2004/06/18 15:18:05 reddawg + bug fixes: did some double checking on pointers and 0x0 out memory + + Revision 1.25 2004/06/17 13:16:55 reddawg + debug: removed all dead debug code + + Revision 1.24 2004/06/17 13:05:14 reddawg + dynamic linking: fixed int6 issue problem was multiple rel's + + Revision 1.23 2004/06/17 12:51:27 reddawg + try now + + Revision 1.22 2004/06/17 12:43:59 reddawg + debug: show me output from this + + Revision 1.21 2004/06/17 12:39:30 reddawg + ok + + Revision 1.20 2004/06/17 12:35:15 reddawg + Test + + Revision 1.19 2004/06/17 12:28:56 reddawg + debug: show me the output after this is a tested + + Revision 1.18 2004/06/17 02:58:49 reddawg + Cleaned Out Dead Code + + Revision 1.17 2004/06/17 02:19:29 reddawg + Cleaning out dead code + + Revision 1.16 2004/06/17 01:52:54 reddawg + Maybe? + + Revision 1.15 2004/06/17 01:23:23 reddawg + Do This + + Revision 1.14 2004/06/17 01:09:25 reddawg + TCA: cvs update make and give me output + + Revision 1.13 2004/06/16 19:45:11 reddawg + Cleaned Up Code + + Revision 1.12 2004/06/16 17:49:02 reddawg + Fixed typo printf <--> kprintf + + Revision 1.11 2004/06/16 17:46:42 reddawg + Cleaned Dead Code + + Revision 1.10 2004/06/16 17:32:14 reddawg + Removed Dead LD Code now part of ld.so + + Revision 1.9 2004/06/16 17:04:13 reddawg + ld.so: rest of the commit + + Revision 1.6 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.5 2004/06/13 03:05:15 reddawg + we now have a dynamic linker + + Revision 1.4 2004/06/12 01:27:26 reddawg + shared objects: yes we almost fully support shared objects + + Revision 1.3 2004/05/15 02:30:28 reddawg + Lots of changes + + END + ***/ + diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c new file mode 100644 index 0000000..65dce58 --- /dev/null +++ b/src/sys/kernel/sched.c @@ -0,0 +1,331 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern union descriptorTableUnion ubixGDT[5]; + +static spinLock_t schedSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t schedTaskSpinLock = SPIN_LOCK_INITIALIZER; + +kTask_t *taskList = 0x0; +uInt32 nextID = -1; +kTask_t *_current = 0x0; +kTask_t *_usedMath = 0x0; + + +prioQueue_t *prioLevels[MAXPRIOLEVELS - 1]; +prioQueue_t *prioQStart = 0x0; +prioQueue_t *_currentQueue = 0x0; + + +/************************************************************************ + +Function: int schedInit() + +Description: This function is used to enable the kernel scheduler + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ + + +int +schedInit() +{ + int i; + kTask_t *tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t)); + + if (tmpTask == 0x0) { + kpanic("Error: kmalloc failed trying to initialize the task list\n"); + return(0x1); + } + + /* Set up the defaults for the initial task */ + tmpTask->prev = 0x0; + tmpTask->next = 0x0; + tmpTask->id = nextID++; + tmpTask->state = DEAD; + tmpTask->nice = MAXPRIOLEVELS/2 + 1; + _current = tmpTask; + + /* Allocating memory for the priority queues */ + for (i = 0; i < MAXPRIOLEVELS; i++) { + prioQueue_t *tmpPrioQ; + + tmpPrioQ = (prioQueue_t *)kmalloc(sizeof(prioQueue_t)); + tmpPrioQ->start = 0x0; + tmpPrioQ->prio = i; + prioLevels[i] = tmpPrioQ; + if (prioQStart == 0) tmpPrioQ->next = 0x0; + else tmpPrioQ->next = prioQStart; + prioQStart = tmpPrioQ; + } + + taskList = prioLevels[tmpTask->nice]->start = tmpTask; + _currentQueue = prioLevels[tmpTask->nice]; + + /* Print out information on scheduler */ + kprintf("sched0 solar - Address: [0x%X]\n", prioQStart); + + /* Return so we know everything went well */ + return(0x0); +} + + +void +sched() +{ + uInt32 memAddr = 0x0; + kTask_t *tmpTask = 0x0; + struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; + + spinLock(&schedSpinLock); + + gpfTSS->eip = (unsigned int)&_int13; + gpfTSS->esp = 0x1CFFF; + gpfTSS->ebp = 0x1CFFF; + gpfTSS->eflags = 0x206; + + schedStart: + /* Yield the next task from the current prio queue */ + for (tmpTask = _current->next; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->state > 0x0) { + _current = tmpTask; + break; + } + } + + /* Finished all the tasks from the current prio queue */ + if (0x0 == tmpTask) { + /* Moving to the next queue which contains tasks */ + do { + if (0x0 == _currentQueue->next) + _currentQueue = prioQStart; + else + _currentQueue = _currentQueue->next; + } while (_currentQueue->start == 0x0); + + _current = _currentQueue->start; + goto schedStart; + } + + /* Setting the timeslice this task is allowed to run */ + systemVitals->quantum = _current->timeSlice; + memAddr = (uInt32)&(_current->tss); + + if (_current->state > 0x0) { + if (_current->oInfo.v86Task == 0x1) { + //kprintf("v86Task\n"); + irqDisable(0x0); + } + + ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); + ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); + ubixGDT[4].descriptor.access = '\x89'; + + spinUnlock(&schedSpinLock); + + asm("ljmp $0x20,$0\n"); + } + + spinUnlock(&schedSpinLock); + + return; +} + + +kTask_t * +schedNewTask() +{ + kTask_t *tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t)); + kTask_t *ll = 0x0; + spinLock(&schedTaskSpinLock); + + /* Filling in tasks attrs */ + tmpTask->usedMath = 0x0; + tmpTask->id = nextID++; + tmpTask->state = NEW; + tmpTask->nice = _current->nice; + tmpTask->timeSlice = systemVitals->dQuantum * tmpTask->nice; + //tmpTask->oInfo.container = findMount("s"); <- No idea what this is + tmpTask->oInfo.cwd = (char *)kmalloc(1024); + + /* Looking for a place in the proper prio queue to place the task */ + for (ll = prioLevels[_current->nice]->start; ll; ll = ll->next) { + if (0x0 == ll->next) { + tmpTask->next = 0x0; + ll->next = tmpTask; + break; + } + } + + /* This prio queue has no task in it */ + if (0x0 == ll) { + tmpTask->next = 0x0; + prioLevels[_current->nice]->start = tmpTask; + } + + spinUnlock(&schedTaskSpinLock); + return(tmpTask); +} + + +/* + * This is at least O(N)... it was written to + * have it functional; soon it will be changed to O(1). + */ + +int +schedDeleteTask(uInt32 id) +{ + kTask_t *tmpTask = 0x0; + prioQueue_t *pQ = 0x0; + + spinLock(&schedTaskSpinLock); + + /* Checking each prio queue */ + for (pQ = prioQStart; pQ; pQ = pQ->next) { + + /* Checking each task from the prio queue */ + for (tmpTask = pQ->start; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + tmpTask->prev->next = tmpTask->next; + + /* We resort back to the initial task*/ + if (_current == tmpTask) { + _current == taskList; + } + } + } + } + + kfree(tmpTask); + spinUnlock(&schedTaskSpinLock); + return(0x0); +} + + +kTask_t * +schedFindTask(uInt32 id) +{ + kTask_t *tmpTask = 0x0; + prioQueue_t *pQ = 0x0; + + for (pQ = prioQStart; pQ; pQ = pQ->next) { + for (tmpTask = pQ->start; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + return(tmpTask); + } + } + } + + return(0x0); +} + + +/************************************************************************ + + Function: void schedEndTask() + + Description: This function will end a task + + Notes: + + 02/20/2004 - Approved for quality + +************************************************************************/ +void +schedEndTask(pidType pid) { + endTask(_current->id); + schedYield(); +} + +/************************************************************************ + +Function: int schedEndTask() + +Description: This function will yield a task + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +void +schedYield() { + sched(); +} + +/*** + $Log$ + Revision 1.10 2004/06/18 13:05:47 solar + Changed the scheduler by adding the first rudiments of priority; vitals.c initializes the system's default quantum to 40 + + Revision 1.9 2004/06/04 13:29:56 reddawg + libc: modified mkdir(); interface + kpanic: kPanic(); now says kPanic: %s + system: now reboots when receives message for reboot + also when command start sde is received by system the STD is started + + Revision 1.8 2004/05/25 16:10:46 reddawg + Spin Locks + + Revision 1.7 2004/05/21 21:15:04 reddawg + Fixed a few bugs which prevented the system from loadin + + Revision 1.6 2004/05/21 15:49:13 reddawg + The os does better housekeeping now when a task is exited + + Revision 1.5 2004/05/21 12:44:17 reddawg + Cleaned Up + + Revision 1.4 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.3 2004/05/15 02:30:28 reddawg + Lots of changes + + + END + ***/ diff --git a/src/sys/kernel/smp.c b/src/sys/kernel/smp.c new file mode 100644 index 0000000..342f564 --- /dev/null +++ b/src/sys/kernel/smp.c @@ -0,0 +1,296 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +static spinLock_t initSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t cpuInfoLock = SPIN_LOCK_INITIALIZER; +static uInt32 cpus = 0; +struct cpuinfo_t cpuinfo[8]; + +uInt8 kernel_function(void); +uInt8 *vram = (uInt8 *)0xB8000; + +static inline unsigned int apicRead(address) { + return *(volatile unsigned int *) (0xFEE00000 + address); + } + +static inline void apicWrite(unsigned int address,unsigned int data) { + *(volatile unsigned int *) (0xFEE00000 + address) = data; + } + +static __inline__ void setDr3 (void *dr3) { + register uInt32 value = (uInt32)dr3; + __asm__ __volatile__ ("mov %0, %%dr3" :: "r" (value)); + } + +static __inline__ uInt32 getDr3 (void) { + register uInt32 value; + __asm__ __volatile__ ("mov %%dr3, %0" : "=r" (value)); + return value; + } + +struct gdt_descr { + uInt16 limit; + uInt32 *base __attribute__ ((packed)); +}; + +static void GDT_fixer() { + struct gdt_descr gdt_descr; + uInt32 *gdt = (uInt32 *)0x20000; // 128KB + + gdt[0] = 0; + gdt[1] = 0; + gdt[2] = 0x0000ffff; // seg 0x8 -- DPL 0 4GB code + gdt[3] = 0x00cf9a00; + gdt[4] = 0x0000ffff; // seg 0x10 -- DPL 0 4GB data + gdt[5] = 0x00cf9200; + gdt[6] = 0x0000ffff; // seg 0x1b -- DPL 3 4GB code + gdt[7] = 0x00cffa00; + gdt[8] = 0x0000ffff; // seg 0x23 -- DPL 3 4GB data + gdt[9] = 0x00cff200; + + gdt_descr.limit = 32 * 4; + gdt_descr.base = gdt; + + /* + asm("lgdt %0;" : : "m" (gdt_descr)); + __asm__ __volatile__ ("ljmp %0,$1f; 1:" :: "i" (0x08)); + __asm__ __volatile__ ("movw %w0,%%ds" :: "r" (0x10)); + __asm__ __volatile__ ("movw %w0,%%es" :: "r" (0x10)); + __asm__ __volatile__ ("movw %w0,%%ss" :: "r" (0x10)); + */ + } + + +void cpu0_thread(void) { + for(;;) { + vram[40+640] = kernel_function(); + vram[42+640]++; + } +} +void cpu1_thread(void) { + for(;;) { + vram[60+640] = kernel_function(); + vram[62+640]++; + } +} +void cpu2_thread(void) { + for(;;) { + vram[80+640] = kernel_function(); + vram[82+640]++; + } +} +void cpu3_thread(void) { + for(;;) { + vram[100+640] = kernel_function(); + vram[102+640]++; + } +} + +static spinLock_t bkl = SPIN_LOCK_INITIALIZER; +uInt8 kernel_function(void) { + struct cpuinfo_t *cpu; + + spinLock(&bkl); + + + cpu = (struct cpuinfo_t *)getDr3(); + + spinUnlock(&bkl); + + return('0' + cpu->id); +} + + +void c_ap_boot(void) { + + while(spinLockLocked(&initSpinLock)); + + switch(cpuInfo()) { + case 1: + cpu1_thread(); + break; + case 2: + cpu2_thread(); + break; + case 3: + cpu3_thread(); + break; + } + + outportByte(0xe9,'5'); + + for(;;) { + asm("nop"); + } +} + + +void smpInit() { + spinLock(&initSpinLock); + GDT_fixer(); + cpuidDetect(); + cpuInfo(); + apicMagic(); + spinUnlock(&initSpinLock); + + //cpu0_thread(); + + } + +void cpuidDetect() { + if (!(getEflags() & (1<<21)) ) { + setEflags(getEflags() | (1<<21)); + if( !(getEflags() & (1<<21)) ) { + kpanic("CPU doesn't support CPUID, get a newer machine\n"); + } + } + } + +uInt8 cpuInfo() { + uInt32 data[4],i; + + if( !(getEflags() & (1<<21)) ) { // If the cpuid bit in eflags not set.. + setEflags(getEflags() | (1<<21)); // ..try and set it to see if it comes on.. + if( !(getEflags() & (1<<21)) ) { // It didn't.. This CPU suck + kpanic("CPU doesn't support CPUID, get a newer machine\n"); + } + } + + spinLock(&cpuInfoLock); + cpuinfo[cpus].ok = 1; + cpuinfo[cpus].apic_id = apicRead(0x20) >> 24; + cpuinfo[cpus].apic_ver = apicRead(0x30) & 0xFF; + + cpuid(0,data); + *(uInt32 *)&cpuinfo[cpus].ident[0] = data[1]; + *(uInt32 *)&cpuinfo[cpus].ident[4] = data[3]; + *(uInt32 *)&cpuinfo[cpus].ident[8] = data[2]; + cpuinfo[cpus].ident[17] = 0; + cpuinfo[cpus].max = data[0]; + + cpuid(1,data); + cpuinfo[cpus].signature = data[0]; + cpuinfo[cpus].feature = data[3]; + + cpuid(0x80000000,data); + if(data[0]>=0x80000004) { + for(i=0;i<3;i++) { + cpuid(0x80000002 + i,data); + + *(unsigned int *)&cpuinfo[cpus].brand[16*i+0] = data[0]; + *(unsigned int *)&cpuinfo[cpus].brand[16*i+4] = data[1]; + *(unsigned int *)&cpuinfo[cpus].brand[16*i+8] = data[2]; + *(unsigned int *)&cpuinfo[cpus].brand[16*i+12] = data[3]; + } + cpuinfo[cpus].brand[48] = 0; + } else { + cpuinfo[cpus].brand[0] = 0; + } + + setDr3(&cpuinfo[cpus]); // DR3 always points to the cpu-struct for that CPU (should be thread-struct of current thread) + cpuinfo[cpus].id = cpus; + + cpus++; + + spinUnlock(&cpuInfoLock); + + return(cpus - 1); + } + +extern void ap_trampoline_start(),ap_trampoline_end(); +void apicMagic(void) { + uInt32 tmp; + + kprintf("Copying %u bytes from 0x%x to 0x00\n",ap_trampoline_end - ap_trampoline_start,ap_trampoline_start); + kmemcpy(0x0,(char *)ap_trampoline_start,ap_trampoline_end - ap_trampoline_start); + apicWrite(0x280,0); + apicRead(0x280); + + apicWrite(0x300,0x000C4500); // INIT IPI to all CPUs + for(tmp=0;tmp<800000;tmp++) asm("nop"); // Sleep a little (should be 10ms) + apicWrite(0x300,0x000C4600); // INIT SIPI to all CPUs + for(tmp=0;tmp<800000;tmp++) asm("nop"); // Sleep a little (should be 200ms) + apicWrite(0x300,0x000C4600); // Second INIT SIPI + for(tmp=0;tmp<800000;tmp++) asm("nop"); // Sleep a little (should be 200ms) + } + + + +uInt32 getEflags() { + uInt32 eflags = 0x0; + asm( + "pushfl \n" + "popl %%eax \n" + : "=a" (eflags) + ); + return(eflags); + } + +void setEflags(uInt32 eflags) { + asm( + "pushl %%eax \n" + "popfl \n" + : + : "a" (eflags) + ); + } + +asm( + ".globl cpuid \n" + "cpuid: \n" + " pushl %ebx \n" + " pushl %edi \n" + " movl 12(%esp),%eax \n" + " movl 16(%esp),%edi \n" + " cpuid \n" + " movl %eax,0(%edi) \n" + " movl %ebx,4(%edi) \n" + " movl %ecx,8(%edi) \n" + " movl %edx,12(%edi) \n" + " popl %edi \n" + " popl %ebx \n" + " ret \n" + ); + +/*** + $Log$ + Revision 1.3 2004/05/15 02:30:28 reddawg + Lots of changes + + + END + ***/ + diff --git a/src/sys/kernel/spinlock.c b/src/sys/kernel/spinlock.c new file mode 100644 index 0000000..f28f106 --- /dev/null +++ b/src/sys/kernel/spinlock.c @@ -0,0 +1,79 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +inline void spinLockInit(spinLock_t *lock) { + *lock = SPIN_LOCK_INITIALIZER; + } + +inline void spinUnlock(spinLock_t *lock) { + register int unlocked; + __asm__ __volatile ( + "xchgl %0, %1" + : "=&r" (unlocked), "=m" (*lock) : "0" (0) + ); + } + +inline int spinTryLock(spinLock_t *lock) { + register int locked; + __asm__ __volatile ("xchgl %0, %1" + : "=&r" (locked), "=m" (*lock) : "0" (1) + ); + return(!locked); + } + +inline void spinLock(spinLock_t *lock) { + while (! spinTryLock(lock)) + while (*lock == 1); + } + +inline int spinLockLocked(spinLock_t *lock) { + return(*lock != 0); + } + + +/*** + $Log$ + Revision 1.4 2004/05/21 12:42:32 reddawg + Cleaned Up + + Revision 1.3 2004/05/15 02:30:28 reddawg + Lots of changes + + Revision 1.2 2004/05/02 14:34:21 reddawg + SMP Support Thanks To Some Help From Slowcoder now to make it interface + well with the rest of the kernel + + Revision 1.1 2004/05/02 03:19:51 reddawg + Added Spinlock Provision For SMP + + END + ***/ + diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c new file mode 100644 index 0000000..01a22de --- /dev/null +++ b/src/sys/kernel/syscall.c @@ -0,0 +1,232 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void sdeTestThread(); + +asm( + ".globl _sysCall \n" + "_sysCall: \n" + " cmpl totalCalls,%eax \n" + " jae invalidSysCall \n" + " pushl %edx \n" + " pushl %ecx \n" + " pushl %ebx \n" + " call *systemCalls(,%eax,4) \n" + " jmp done \n" + "invalidSysCall: \n" + " call invalidCall \n" + "done: \n" + " popl %ebx \n" + " popl %ecx \n" + " popl %edx \n" + " iret \n" /* Exit interrupt */ + ); + +void invalidCall() { + kprintf("Invalid Sys Call!\n"); + } + +void sysGetpid(int *pid) { + *pid = _current->id; + return; + } + +void sysGetUid(int *uid) { + *uid = _current->uid; + return; + } + +void sysGetGid(int *gid) { + *gid = _current->gid; + return; + } + +void sysSetUid(int uid,int *status) { + if (_current->uid == 0x0) { + _current->uid = uid; + *status = 0x0; + } + else { + *status = 1; + } + return; + } + +void sysSetGid(int gid,int *status) { + if (_current->gid == 0x0) { + _current->gid = gid; + *status = 0x0; + } + else { + *status = 1; + } + return; + } + +void sysExit(int status) { + endTask(_current->id); + sched(); + } + +void sysCheckPid(int pid,int *ptr) { + *ptr = schedFindTask(pid)->state; + return; + } + +/************************************************************************ + +Function: void sysGetFreePage(); +Description: Allocs A Page To The Users VM Space +Notes: + +************************************************************************/ +void sysGetFreePage(long *ptr,int count) { + *ptr = (long) vmmGetFreeVirtualPage(_current->id,count); + return; + } + +void sysGetDrives(uInt32 *ptr) { + *ptr = 0x0;//(uInt32)devices; + return; + } + +void sysGetUptime(uInt32 *ptr) { + *ptr = systemVitals->sysTicks; + return; + } + +void sysGetTime(uInt32 *ptr) { + *ptr = systemVitals->sysUptime + systemVitals->timeStart; + return; + } + + +void sysGetCwd(char *data) { + sprintf(data,_current->oInfo.cwd); + return; + } + +void sysSchedYield() { + schedYield(); + } + +void sysStartSDE() { + int i = 0x0; + for (i=0;i<1400;i++) { + asm("hlt"); + } + execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + for (i=0;i<1400;i++) { + asm("hlt"); + } + return; + } + +void sysMpiCreateMbox(uInt32 *status,char *name) { + *status = mpiCreateMbox(name); + return; + } + +void sysMpiDestroyMbox(uInt32 *status,char *name) { + *status = mpiDestroyMbox(name); + return; + } + +void sysMpiPostMessage(char *name,uInt32 *type,void *data) { + *type = mpiPostMessage(name,*type,data); + return; + } + +void sysMpiFetchMessage(char *name,mpiMessage_t *msg,uInt32 *status) { + *status = mpiFetchMessage(name,msg); + return; + } + +void sysMpiSpam(uInt32 type,void *data,uInt32 *status) { + *status = mpiSpam(type,data); + return; + } + +/*** + $Log$ + Revision 1.14 2004/06/17 03:20:47 reddawg + Cleaned Up + + Revision 1.13 2004/05/26 15:39:22 reddawg + mpi: brought mpiDestroyMbox(char *name) in to the userland + + Revision 1.12 2004/05/26 13:07:54 reddawg + mpi: had problem with mpiCreateMbox interface was putting garbage on end + + Revision 1.11 2004/05/25 15:49:03 reddawg + Added Syscall Interface For MPI + + Revision 1.10 2004/05/23 01:10:35 reddawg + Fixes: Started to fix re-entrancy issues many more to look into + + Revision 1.9 2004/05/21 21:15:04 reddawg + Fixed a few bugs which prevented the system from loadin + + Revision 1.8 2004/05/21 12:46:02 reddawg + Cleaned up + + Revision 1.7 2004/05/19 17:28:28 reddawg + Added the correct endTask Procedure + + Revision 1.6 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.5 2004/05/19 01:21:29 reddawg + Tweaked + + Revision 1.4 2004/05/15 02:30:28 reddawg + Lots of changes + + + END + ***/ + diff --git a/src/sys/kernel/systemtask.c b/src/sys/kernel/systemtask.c new file mode 100644 index 0000000..4fb2d90 --- /dev/null +++ b/src/sys/kernel/systemtask.c @@ -0,0 +1,117 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void systemTask() { + mpiMessage_t myMsg; + uInt32 counter = 0x0; + + if (mpiCreateMbox("system") != 0x0) { + kpanic("Error: Error creating mailbox: system\n"); + } + + while(1) { + if (mpiFetchMessage("system",&myMsg) == 0x0) { + switch(myMsg.type) { + case 1000: + kprintf("Restarting the system in 5 seconds\n"); + counter = systemVitals->sysUptime + 5; + while (systemVitals->sysUptime < counter) { + //asm("hlt"); + schedYield(); + } + kprintf("Rebooting NOW!!!\n"); + while(inportByte(0x64) & 0x02); + outportByte(0x64, 0xFE); + break; + case 31337: + kprintf("system: backdoor opened\n"); + break; + case 0x80: + if (!kstrcmp(myMsg.data,"sdeStart")) { + kprintf("Starting SDE\n"); + execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + } + break; + default: + kprintf("system: Received message %i:%s\n",myMsg.type,myMsg.data); + break; + } + } + asm("hlt"); + } + return; + } + +/*** + $Log$ + Revision 1.1 2004/06/04 17:33:33 reddawg + Changed idle task to system task + + Revision 1.9 2004/06/04 13:29:56 reddawg + libc: modified mkdir(); interface + kpanic: kPanic(); now says kPanic: %s + system: now reboots when receives message for reboot + also when command start sde is received by system the STD is started + + Revision 1.8 2004/05/26 23:48:33 reddawg + idletask: tweaked reboot for performance + + Revision 1.7 2004/05/26 23:28:29 reddawg + idletask: This task now also receives all of the systems message + We also gained reboot suport that is msg send type 1000 + + Revision 1.6 2004/05/25 18:42:28 reddawg + Idle task now just does what it is suposed to + + Revision 1.5 2004/05/25 17:30:16 reddawg + IDLE task will be our toy task to test things with + + Revision 1.4 2004/05/25 15:49:03 reddawg + Added Syscall Interface For MPI + + Revision 1.3 2004/05/21 12:36:53 reddawg + Cleaned Up + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + + END + ***/ + diff --git a/src/sys/kernel/time.c b/src/sys/kernel/time.c new file mode 100644 index 0000000..2d6855e --- /dev/null +++ b/src/sys/kernel/time.c @@ -0,0 +1,126 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static int month[12] = { + 0, + DAY*(31), + DAY*(31+29), + DAY*(31+29+31), + DAY*(31+29+31+30), + DAY*(31+29+31+30+31), + DAY*(31+29+31+30+31+30), + DAY*(31+29+31+30+31+30+31), + DAY*(31+29+31+30+31+30+31+31), + DAY*(31+29+31+30+31+30+31+31+30), + DAY*(31+29+31+30+31+30+31+31+30+31), + DAY*(31+29+31+30+31+30+31+31+30+31+30) +}; + + +int timeInit() { + + struct timeStruct time; + int i; + + for (i = 0 ; i < 1000000 ; i++) { + if (!(timeCmosRead(10) & 0x80)) { + break; + } + } + + do { + time.sec = timeCmosRead(0); + time.min = timeCmosRead(2); + time.hour = timeCmosRead(4); + time.day = timeCmosRead(7); + time.mon = timeCmosRead(8); + time.year = timeCmosRead(9); + } while (time.sec != timeCmosRead(0)); + + BCD_TO_BIN(time.sec); + BCD_TO_BIN(time.min); + BCD_TO_BIN(time.hour); + BCD_TO_BIN(time.day); + BCD_TO_BIN(time.mon); + BCD_TO_BIN(time.year); + + kprintf("%i/%i/%i %i:%i.%i\n",time.mon,time.day,time.year,time.hour,time.min,time.sec); + + systemVitals->timeStart = timeMake(&time); + + /* Return so we know all went well */ + return(0x0); + } + +uInt32 timeMake(struct timeStruct *time) { + uInt32 res; + int year; + + year = (time->year+100) - 70; + /* magic offsets (y+1) needed to get leapyears right.*/ + res = YEAR*year + DAY*((year+1)/4); + res += month[time->mon]; + /* and (y+2) here. If it wasn't a leap-year, we have to adjust */ + if (time->mon>1 && ((year+2)%4)) + res -= DAY; + res += DAY*(time->day-1); + res += HOUR*time->hour; + res += MINUTE*time->min; + res += time->sec; + return(res); + } + +int gettimeofday(struct timeval *tp,struct timezone *tzp) { + //tp->tv_sec = systemVitals->timeStart + systemVitals->sysUptime; + tp->tv_sec = 0x0;//systemVitals->sysUptime; + tp->tv_usec = 0x0; + return(0x0); + } + +int timeCmosRead(int addr) { + outportByteP(0x70,addr); + return(inportByte(0x71)); + } + +/*** + $Log$ + Revision 1.3 2004/05/21 12:46:02 reddawg + Cleaned up + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + + END + ***/ + diff --git a/src/sys/kernel/timer.S b/src/sys/kernel/timer.S new file mode 100644 index 0000000..0b17a56 --- /dev/null +++ b/src/sys/kernel/timer.S @@ -0,0 +1,75 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +.globl timerInt +.text +.code32 +timerInt: + pushl %edx /* Push Register That We Are Going To Touch */ + pushl %ecx + pushl %ebx + pushl %eax + movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ + incl 4(%ecx) /* Increment sysTicks our 1000ms counter */ + mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ + mov $0x20,%ax + outb %al,%dx + mov $0xA0,%dx /* The Following Sends Our EOI To The SPID */ + outb %al,%dx + movl 4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ + movl $1000,%ebx /* Have Passed */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz next + incl 8(%ecx) +next: + movl 4(%ecx),%eax /* Test If quantum Has Passed If So Then */ + movl 12(%ecx),%ebx /* We Can CALL sched */ + xor %edx,%edx + div %ebx + test %edx,%edx + jnz done + call sched +done: + popl %eax /* Restore Register And IRET */ + popl %ebx + popl %ecx + popl %edx + iret + +/*** + $Log$ + Revision 1.1 2004/06/17 12:11:14 reddawg + timerInt: removed from src/sys/sys/idt.c and moved into a file by itself + in src/sys/kernel/timer.S + + END + ***/ + diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c new file mode 100644 index 0000000..1140d73 --- /dev/null +++ b/src/sys/kernel/ubthread.c @@ -0,0 +1,147 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct ubthread_cond_list *conds = 0x0; +struct ubthread_mutex_list *mutex = 0x0; + +kTask_t *ubthread_self() { + return(_current); + } + +int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr) { + ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); + ubcond->id = (int)cond; + ubcond->locked = UNLOCKED; + *cond = ubcond; + return(0x0); + } + +int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr) { + ubthread_mutex_t ubmutex = kmalloc(sizeof(struct ubthread_mutex)); + ubmutex->id = (int)mutex; + ubmutex->locked = UNLOCKED; + *mutex = ubmutex; + return(0x0); + } + +int ubthread_cond_destroy(ubthread_cond_t *cond) { + kfree(*cond); + *cond = 0x0; + return(0x0); + } + +int ubthread_mutex_destroy(ubthread_mutex_t *mutex) { + kfree(*mutex); + *mutex = 0x0; + return(0x0); + } + +int ubthread_create(kTask_t **thread,const uInt32 *attr,void *start_routine, void *arg) { + *thread = (void *)execThread((void *)start_routine,(uInt32)(kmalloc(0x2000)+0x2000),arg); + return(0x0); + } + +int ubthread_mutex_lock(ubthread_mutex_t *mutex) { + ubthread_mutex_t ubmutex = *mutex; + if (ubmutex->locked == LOCKED) { + //kprintf("Mutex Already Lock By %x Trying To Be Relocked By %x\n",ubmutex->pid,_current->id); + while (ubmutex->locked == LOCKED); + } + ubmutex->locked = LOCKED; + ubmutex->pid = _current->id; + return(0x0); + } + +int ubthread_mutex_unlock(ubthread_mutex_t *mutex) { + ubthread_mutex_t ubmutex = *mutex; + if (ubmutex->pid == _current->id) { + ubmutex->locked = UNLOCKED; + return(0x0); + } + else { + //kprintf("Trying To Unlock Mutex From No Locking Thread\n"); + ubmutex->locked = UNLOCKED; + return(-1); + } + } + +int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime) { + ubthread_cond_t ubcond = *cond; + ubthread_mutex_t ubmutex = *mutex; + uInt32 enterTime = systemVitals->sysUptime+20; + while (enterTime > systemVitals->sysUptime) { + if (ubcond->locked == UNLOCKED) break; + schedYield(); + } + ubmutex->locked = UNLOCKED; + return(0x0); + } + +int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex) { + ubthread_cond_t ubcond = *cond; + ubthread_mutex_t ubmutex = *mutex; + while (ubcond->locked == LOCKED); + ubmutex->locked = UNLOCKED; + return(0x0); + } + +int ubthread_cond_signal(ubthread_cond_t *cond) { + ubthread_cond_t ubcond = *cond; + ubcond->locked = UNLOCKED; + return(0x0); + } + +/*** + $Log$ + Revision 1.6 2004/06/15 12:24:07 reddawg + Cleaned Up + + Revision 1.5 2004/05/26 03:13:37 reddawg + Changing the way our mutex work + + Revision 1.4 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.3 2004/05/19 01:21:29 reddawg + Tweaked + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + END + ***/ diff --git a/src/sys/kernel/vitals.c b/src/sys/kernel/vitals.c new file mode 100644 index 0000000..d9d63fa --- /dev/null +++ b/src/sys/kernel/vitals.c @@ -0,0 +1,99 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include + +vitalsNode *systemVitals = 0x0; + +/************************************************************************ + +Function: initVitals(); +Description: This will enable the vitals subsystem for ubixos + +Notes: + +02/20/2004 - Approved Its Quality + +************************************************************************/ +int initVitals() { + /* Initialize Memory For The System Vitals Node */ + systemVitals = (vitalsNode *) kmalloc(sizeof(vitalsNode)); + + /* If malloc Failed Then Error */ + if (systemVitals == 0x0) { + kpanic("Error: kmalloc Failed In initVitals\n"); + } + + /* Set all default values */ + systemVitals->freePages = freePages; + systemVitals->sysTicks = 0x0; + systemVitals->sysUptime = 0x0; + systemVitals->quantum = 40; + systemVitals->dQuantum = 40; + systemVitals->fileSystems = 0x0; + systemVitals->mountPoints = 0x0; + systemVitals->timeStart = 0x0; + systemVitals->screen = 0x0; + systemVitals->font = 0x0; + + /* Print Out Info For Vitals: */ + kprintf("vitals0 - Address: [0x%X]\n",systemVitals); + + /* Return so kernel knows that there is no problem */ + return(0x0); + + } + +/*** + $Log$ + Revision 1.6 2004/06/18 13:05:47 solar + Changed the scheduler by adding the first rudiments of priority; vitals.c initializes the system's default quantum to 40 + + Revision 1.5 2004/06/16 12:04:18 reddawg + systemVitals->quantum = (1000/msPerQuantum) + The timer int now will call scheduler at the rate of the defined quantum + + Revision 1.4 2004/06/15 12:24:07 reddawg + Cleaned Up + + Revision 1.3 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/05/15 02:30:28 reddawg + Lots of changes + + + END + ***/ + + diff --git a/src/sys/lib/Makefile b/src/sys/lib/Makefile new file mode 100644 index 0000000..99cd4d9 --- /dev/null +++ b/src/sys/lib/Makefile @@ -0,0 +1,31 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +INCLUDES += -I../../lib/objgfx40/ + +# Objects +OBJS = ogprintf.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kmalloc.o kprintf.o vsprintf.o string.o net.o strtol.o + +all: $(OBJS) + +# Compile Types +.cpp.o: + $(CXX) -Wall -DNOBOOL $(CFLAGS) -fno-rtti $(INCLUDES) -g -c -o $@ $< +.cc.o: + $(CXX) -Wall -DNOBOOL -D__UBIXOS_KERNEL__ -O $(CFLAGS) -fno-rtti $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/lib/atan.c b/src/sys/lib/atan.c new file mode 100644 index 0000000..572cc8b --- /dev/null +++ b/src/sys/lib/atan.c @@ -0,0 +1,52 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +double atan(double x) { + return(x); /* Quick Hack To Make This Work */ + } + +/*** + $Log$ + Revision 1.3 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/lib/divdi3.c b/src/sys/lib/divdi3.c new file mode 100644 index 0000000..7ef73d9 --- /dev/null +++ b/src/sys/lib/divdi3.c @@ -0,0 +1,53 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +u_quad_t __udivdi3(u_quad_t a,u_quad_t b) { + return(0); /* Quick Hack */ + } + +quad_t __divdi3(quad_t a,quad_t b) { + return(0); /* Quick Hack */ + } + +/*** + $Log$ + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c new file mode 100644 index 0000000..fd87868 --- /dev/null +++ b/src/sys/lib/kmalloc.c @@ -0,0 +1,348 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +static struct memDescriptor *kernDesc = 0x0; +static struct memDescriptor *freeKernDesc = 0x0; +static struct memDescriptor *emptyKernDesc = 0x0; + +static spinLock_t mallocSpinLock = SPIN_LOCK_INITIALIZER; + +void initMalloc() { + int i=0; + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + emptyKernDesc = (struct memDescriptor *)vmmGetFreeKernelPage(sysID,4); + tmpDesc1 = emptyKernDesc; + tmpDesc1->prev = 0x0; + tmpDesc1->status = 0x0; + tmpDesc1->limit = 0x0; + for (i=1;i<((4096/sizeof(struct memDescriptor))*4);i++) { + tmpDesc2 = &emptyKernDesc[i]; + tmpDesc2->prev = tmpDesc1; + tmpDesc1->next = tmpDesc2; + tmpDesc2->status = 0x0; + tmpDesc2->limit = 0x0; + tmpDesc1 = tmpDesc2; + } + tmpDesc1->next = 0x0; + //Return + return; + } + +/************************************************************************ + +Function: void *getEmptyDesc() +Description: Find An Empty Descriptor + +Notes: + +02/17/03 - Is This Efficient? + +************************************************************************/ +void *getEmptyDesc() { + struct memDescriptor *tmpDesc = emptyKernDesc; + if (tmpDesc != 0x0) { + emptyKernDesc = tmpDesc->next; + emptyKernDesc->prev = 0x0; + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; + return(tmpDesc); + } + kpanic("Error Finding Empty Descriptor!\n"); + return(0x0); + } + +/************************************************************************ + +Function: void *kmalloc(uInt32 len) +Description: Allocate Kernel Memory + +Notes: + +02/17/03 - Do I Still Need To Pass In The Pid? + +************************************************************************/ +void *kmalloc(uInt32 len) { + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + char *buf = 0x0; + int i = 0x0; + + spinLock(&mallocSpinLock); + + //If Kernel Descriptor Is NULL Initialize Malloc + if (emptyKernDesc == 0x0) { + initMalloc(); + } + len = (len + 15) & 0xFFFFFFF0; + if (len == 0x0) { + kpanic("Malloc of Size 0 Requested\n"); + spinUnlock(&mallocSpinLock); + return(0x0); + } + for (tmpDesc1 = freeKernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { + if (tmpDesc1->limit >= len) { + tmpDesc1->status = 0x1; + if (tmpDesc1->prev != 0x0) { + tmpDesc1->prev->next = tmpDesc1->next; + tmpDesc1->next->prev = tmpDesc1->prev; + } + else { + freeKernDesc = tmpDesc1->next; + freeKernDesc->prev = 0x0; + } + tmpDesc1->prev = 0x0; + tmpDesc1->next = kernDesc; + kernDesc->prev = tmpDesc1; + kernDesc = tmpDesc1; + if (tmpDesc1->limit > (len + 16)) { + tmpDesc2 = getEmptyDesc(); + tmpDesc2->limit = tmpDesc1->limit - len; + tmpDesc1->limit = len; + tmpDesc2->baseAddr = tmpDesc1->baseAddr + len; + tmpDesc2->status = 0x0; + tmpDesc2->next = 0x0; + tmpDesc2->prev = 0x0; + insertFreeDesc(tmpDesc2); + } + buf = (char *)tmpDesc1->baseAddr; + for (i=0;ilimit;i++) { + (char)buf[i] = (char)0x0; + } + spinUnlock(&mallocSpinLock); + return(tmpDesc1->baseAddr); + } + } + tmpDesc1 = getEmptyDesc(); + if (tmpDesc1 != 0x0) { + tmpDesc1->baseAddr = (struct memDescriptor *)vmmGetFreeKernelPage(sysID,((len + 4095)/4096)); + tmpDesc1->limit = len; + tmpDesc1->status = 0x1; + tmpDesc1->next = kernDesc; + tmpDesc1->prev = 0x0; + kernDesc = tmpDesc1; + kernDesc->next->prev = tmpDesc1; + if ((len-4096) > 0) { + tmpDesc2 = getEmptyDesc(); + tmpDesc2->status = 0x0; + tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; + tmpDesc2->limit = ((len + 4095)/4096)*4096 - tmpDesc1->limit; + tmpDesc2->prev = 0x0; + tmpDesc2->next = 0x0; + insertFreeDesc(tmpDesc2); + } + buf = (char *)tmpDesc1->baseAddr; + for (i=0;ilimit;i++) { + (char)buf[i] = (char)0x0; + } + spinUnlock(&mallocSpinLock); + return(tmpDesc1->baseAddr); + } + //Return Null If Unable To Malloc + spinUnlock(&mallocSpinLock); + return(0x0); + } + +/************************************************************************ + +Function: void kfree(void *baseAddr) +Description: This Will Find The Descriptor And Free It + +Notes: + +02/17/03 - I need To Make It Join Descriptors + +************************************************************************/ +void kfree(void *baseAddr) { + uInt32 *data = 0x0; + long i = 0x0; + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + + spinLock(&mallocSpinLock); + + for (tmpDesc1=kernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { + if (tmpDesc1->baseAddr == baseAddr) { + tmpDesc1->status = 0x0; + if (tmpDesc1->prev != 0x0) { + tmpDesc2 = tmpDesc1->prev; + tmpDesc2->next = tmpDesc1->next; + } + if (tmpDesc1->next != 0x0) { + tmpDesc2 = tmpDesc1->next; + tmpDesc2->prev = tmpDesc1->prev; + } + if (kernDesc == tmpDesc1) { + kernDesc = tmpDesc1->next; + } + tmpDesc1->next = 0x0; + tmpDesc1->prev = 0x0; + insertFreeDesc(tmpDesc1); + data = (uInt32 *)baseAddr; + for (i=0;i < (tmpDesc1->limit/4);i++) { + data[i] = 0x0; + } + mergeMemBlocks(); + spinUnlock(&mallocSpinLock); + return; + } + } + kprintf("Error Freeing Descriptor! [0x%X]\n",baseAddr); + spinUnlock(&mallocSpinLock); + return; + } + +/************************************************************************ + +Function: void insertFreeDesc(struct memDescriptor *freeDesc) +Description: This Function Inserts A Free Descriptor On The List Which Is + Kept In Size Order + +Notes: + +02/17/03 - This Was Inspired By TCA's Great Wisdom - + "[20:20:59] You should just insert it in order" + +************************************************************************/ +void insertFreeDesc(struct memDescriptor *freeDesc) { + struct memDescriptor *tmpDesc; + freeDesc->status = 0x0; + if (freeKernDesc != 0x0) { + for (tmpDesc=freeKernDesc;tmpDesc;tmpDesc=tmpDesc->next) { + if ((freeDesc->limit >= tmpDesc->limit) && (!tmpDesc->next)) { + tmpDesc->next = freeDesc; + freeDesc->prev = tmpDesc; + freeDesc->next = 0x0; + return; + } + else if ((freeDesc->limit >= tmpDesc->limit) && (freeDesc->limit <= tmpDesc->next->limit)) { + freeDesc->next = tmpDesc->next; + freeDesc->prev = tmpDesc; + tmpDesc->next->prev = freeDesc; + tmpDesc->next = freeDesc; + return; + } + } + } + else { + freeDesc->prev = 0x0; + freeDesc->next = 0x0; + freeKernDesc = freeDesc; + return; + } + //sysErr("Error With Freeing Blocks"); + return; + } + +/************************************************************************ + +Function: void mergeMemBlocks() +Description: This Function Will Merge Free Blocks And Free Pages + +Notes: + +03/05/03 - We Have A Problem It Seems The First Block Is Limit 0x0 + +************************************************************************/ +void mergeMemBlocks() { + struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc2 = 0x0; + uInt32 baseAddr = 0x0; + + return; + + //Loop The Free Descriptors See If We Can Merge Them + for (tmpDesc1=freeKernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { + /* + Compare The Base Addr With The Other Descriptors If You Find The One + That You Are Looking For Lets Merge Them + */ + if (tmpDesc1->limit != 0x0) { + baseAddr = (uInt32)tmpDesc1->baseAddr + (uInt32)tmpDesc1->limit; + for (tmpDesc2=freeKernDesc;tmpDesc2;tmpDesc2=tmpDesc2->next) { + if ((uInt32)tmpDesc2->baseAddr == baseAddr) { + tmpDesc1->limit += tmpDesc2->limit; + tmpDesc2->baseAddr = 0x0; + tmpDesc2->limit = 0x0; + tmpDesc2->status = 0x0; + if (tmpDesc2->prev) { + tmpDesc2->prev->next = tmpDesc2->next; + } + if (tmpDesc2->next) { + tmpDesc2->next->prev = tmpDesc2->prev; + } + tmpDesc2->prev = 0x0; + tmpDesc2->next = emptyKernDesc; + emptyKernDesc->prev = tmpDesc2; + emptyKernDesc = tmpDesc2; + if (tmpDesc1->prev) { + tmpDesc1->prev->next = tmpDesc1->next; + } + if (tmpDesc1->next) { + tmpDesc1->next->prev = tmpDesc1->prev; + } + tmpDesc1->prev = 0x0; + tmpDesc1->next = 0x0; + insertFreeDesc(tmpDesc1); + tmpDesc1 = freeKernDesc; + break; + } + } + } + } + return; + } + +/*** + $Log$ + Revision 1.8 2004/06/17 14:50:32 reddawg + kmalloc: converted some variables to static + + Revision 1.7 2004/06/17 02:54:54 flameshadow + chg: fixed cast + + Revision 1.6 2004/05/26 11:56:51 reddawg + kmalloc: fixed memrgeMemBlocks hopefully it will prevent future segfault issues + by not having any more overlapping blocks + + Revision 1.5 2004/05/25 14:01:14 reddawg + Implimented Better Spinlocking No More Issues With KMALLOC which actually + was causing bizzare problems + + END + ***/ + diff --git a/src/sys/lib/kprintf.c b/src/sys/lib/kprintf.c new file mode 100644 index 0000000..89b3d2e --- /dev/null +++ b/src/sys/lib/kprintf.c @@ -0,0 +1,87 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.13 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include + +int vsprintf(char *buf, const char *fmt, vaList args); +int ogPrintf(char *s); + +int printOff = 0x0; +int ogprintOff = 0x1; + +int kprintf(const char *fmt, ...) { + char buf[1024]; + vaList args; + int i = 0x0; + vaStart(args, fmt); + i=vsprintf(buf,fmt,args); + vaEnd(args); + if (printOff == 0x0) { + kprint(buf); + } + if (ogprintOff == 0x0) { + ogPrintf(buf); + } + return(i); + } + +int vPrintf(const char *fmt, ...) { + vaList args; + int i; + char buf[512]; + vaStart(args, fmt); + i=vsprintf(buf,fmt,args); + vaEnd(args); + if (printOff == 0x0) + kprint(buf); + return(i); + } + +int sprintf(char *buf,const char *fmt, ...) { + vaList args; + int i; + vaStart(args, fmt); + i=vsprintf(buf,fmt,args); + vaEnd(args); + return(i); + } + +/*** + END + ***/ diff --git a/src/sys/lib/libcpp.cc b/src/sys/lib/libcpp.cc new file mode 100644 index 0000000..8b507bb --- /dev/null +++ b/src/sys/lib/libcpp.cc @@ -0,0 +1,84 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +extern "C" +{ +#include +#include +void __pure_virtual() { while(1); } +void __cxa_pure_virtual() { while(1); } +} + +#include + +void * operator new[](unsigned size) +{ + return kmalloc(size); +} + +void operator delete[](void * ptr) +{ + kfree(ptr); + + return; +} + +void * operator new(unsigned size) +{ + void * ptr = kmalloc(size); + + //kprintf("Malloced: %08x\n", ptr); + + return ptr; +} + +void operator delete(void * ptr) +{ + kfree(ptr); + //kprintf("Freed: %08x\n", ptr); + + return; +} + +/*** + END + ***/ + diff --git a/src/sys/lib/net.c b/src/sys/lib/net.c new file mode 100644 index 0000000..5dc11bb --- /dev/null +++ b/src/sys/lib/net.c @@ -0,0 +1,190 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.4 2004/06/17 03:14:59 flameshadow + chg: added missing #include for kprintf() + + Revision 1.3 2004/05/20 22:54:02 reddawg + Cleaned Up Warrnings + + Revision 1.2 2004/04/30 14:16:04 reddawg + Fixed all the datatypes to be consistant uInt8,uInt16,uInt32,Int8,Int16,Int32 + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.8 2004/04/13 21:29:52 reddawg + We now have sockets working. Lots of functionality to be added to continually + improve on the existing layers now its clean up time to get things in a better + working order. + + Revision 1.7 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +#include "lib/kprintf.h" + +#ifndef _IN_ADDR_T_DECLARED +typedef uInt32 in_addr_t; +#define _IN_ADDR_T_DECLARED +#endif + +uInt32 htonl(uInt32 n) { + uInt32 retVal = 0x0; + retVal += ((n & 0xff) << 24); + retVal += ((n & 0xff00) << 8); + retVal += ((n & 0xff0000) >> 8); + retVal += ((n & 0xff000000) >> 24); + return(retVal); + } + +uInt32 htons(uInt32 n) { + uInt32 retVal = 0x0; + retVal = (((n & 0xff) << 8) | ((n & 0xff00) >> 8)); + return(retVal); + } + +void bcopy(const void *src, void *dest, int len) { + kmemcpy(dest,src,len); + } + +void bzero(void *data, int n) { + kmemset(data, 0, n); + } + + +int inet_aton(cp, addr) + const char *cp; + struct in_addr *addr; +{ + uInt32 parts[4]; + in_addr_t val; + char *c; + char *endptr; + int gotend, n; + + c = (char *)cp; + n = 0; + /* + * Run through the string, grabbing numbers until + * the end of the string, or some error + */ + gotend = 0; + while (!gotend) { + //errno = 0; + val = strtol(c, &endptr, 0); + kprintf("VAL: [%x]",val); + + //if (errno == ERANGE) /* Fail completely if it overflowed. */ + // return (0); + + /* + * If the whole string is invalid, endptr will equal + * c.. this way we can make sure someone hasn't + * gone '.12' or something which would get past + * the next check. + */ + if (endptr == c) + return (0); + parts[n] = val; + c = endptr; + + /* Check the next character past the previous number's end */ + switch (*c) { + case '.' : + /* Make sure we only do 3 dots .. */ + if (n == 3) /* Whoops. Quit. */ + return (0); + n++; + c++; + break; + + case '\0': + gotend = 1; + break; + + default: + /* + if (isspace((unsigned char)*c)) { + gotend = 1; + break; + } else + */ + return (0); /* Invalid character, so fail */ + } + + } + + /* + * Concoct the address according to + * the number of parts specified. + */ + + switch (n) { + case 0: /* a -- 32 bits */ + /* + * Nothing is necessary here. Overflow checking was + * already done in strtoul(). + */ + break; + case 1: /* a.b -- 8.24 bits */ + if (val > 0xffffff || parts[0] > 0xff) + return (0); + val |= parts[0] << 24; + break; + + case 2: /* a.b.c -- 8.8.16 bits */ + if (val > 0xffff || parts[0] > 0xff || parts[1] > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 3: /* a.b.c.d -- 8.8.8.8 bits */ + if (val > 0xff || parts[0] > 0xff || parts[1] > 0xff || + parts[2] > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + + if (addr != NULL) + addr->s_addr = htonl(val); + return (1); +} + +/*** + END + ***/ + diff --git a/src/sys/lib/ogprintf.cc b/src/sys/lib/ogprintf.cc new file mode 100644 index 0000000..c288e18 --- /dev/null +++ b/src/sys/lib/ogprintf.cc @@ -0,0 +1,135 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.5 2004/05/23 23:30:34 reddawg + Fixens + + Revision 1.4 2004/05/23 01:40:19 reddawg + Spinlock + + Revision 1.3 2004/05/19 17:09:50 flameshadow + chg: Undid previous renaming. This now restores me as the EOOUIAD. + + Revision 1.2 2004/04/26 12:56:01 reddawg + Made src/sys/sde Copy and Make the ogPixelFormat.cpp + + Revision 1.1.1.1 2004/04/15 12:07:10 reddawg + UbixOS v1.0 + + Revision 1.19 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +extern "C" { +#include + + +int ogPrintf(char *s); + +int screenRow = 0x0; +int screenCol = 0x1; + +int ogPrintf(char *s) { + int i = 0x0; + int bufHeight; + ogSurface *screen = (ogDisplay_UbixOS *)systemVitals->screen; + ogBitFont *font = (ogBitFont *)systemVitals->font; + + + while ('\0' != s[i]) { + switch (s[i]) { + case '\t': + screenCol += 3; + break; + case '\b': + if (screenCol > 0) --screenCol; + case '\n': + screenCol = 0; + + bufHeight = ((screen->ogGetMaxY()+1) / font->GetHeight())-1; + if (screenRow < bufHeight) + ++screenRow; + else { + screen->ogCopyBuf(0, 0, + *screen, + 0, font->GetHeight(), + screen->ogGetMaxX(), screen->ogGetMaxY()); + screen->ogFillRect(0, bufHeight * font->GetHeight()+1, + screen->ogGetMaxX(), screen->ogGetMaxY(), + screen->ogPack(122, 140, 163)); + } + break; + default: + font->PutChar(*screen, + screenCol * font->GetWidth(), + screenRow * font->GetHeight(), + s[i]); + break; + } /* switch */ + ++screenCol; + ++i; +#if 0 + if (screenRow > (int)((screen->GetMaxY()+1) / font->GetHeight())) { + screen->CopyBuf(0, 0, + *screen, + 0, font->GetHeight(), + screen->GetMaxX(), screen->GetMaxY()); + screen->FillRect(0, screen->GetMaxY() - font->GetHeight(), + screen->GetMaxX(), screen->GetMaxY(), + screen->Pack(122, 140, 163)); + --screenRow; + } /* if */ +#endif + } /* while */ + +#if 0 + screen->ScaleBuf(screen->GetMaxX() - (screen->GetMaxX() / 4), + screen->GetMaxY() - (screen->GetMaxY() / 4), + screen->GetMaxX(), + screen->GetMaxY(), + *screen, + 0, 0, + screen->GetMaxX() / 2, + screen->GetMaxY()); +#endif + return 0; +} // ogPrintf +} + +/*** + END + ***/ + diff --git a/src/sys/lib/sqrt.c b/src/sys/lib/sqrt.c new file mode 100644 index 0000000..d495044 --- /dev/null +++ b/src/sys/lib/sqrt.c @@ -0,0 +1,47 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +double sqrt(double x) { + return(x); /* Quick Hack */ + } + +/*** + $Log$ + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/lib/string.c b/src/sys/lib/string.c new file mode 100644 index 0000000..f748049 --- /dev/null +++ b/src/sys/lib/string.c @@ -0,0 +1,154 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +int kstrcmp(char *str1, char *str2) { + while ((*str1 == *str2) && (*str1 != 0x0) && (*str2 != 0x0)) { + str1++; + str2++; + } + if (*str1 == *str2) { + return(0); + } + else if (*str1 > *str2) { + return(1); + } + else { + return(-1); + } + } + +int kstrncmp(const char * a, const char * b, size_t c) { + int i = 0; + while (i < c) { + if ((a[i] != b[i]) || (a[i] == '\0') || (b[i] == '\0')) + return a[i] - b[i]; + i++; + } + return 0; + } + + + +void *kmemcpy(const void *dst, const void * src, size_t length) { + size_t x = length >> 2; + size_t y = length & 0xf; + size_t i; + + for (i = 0; i < x; i++) { + ((unsigned long *)dst)[i] = ((unsigned long *)src)[i]; + } + + for (i = 0; i < y; i++) { + ((char *) dst)[length-y+i] = ((char *) src)[length-y+i]; + } + + return((void *)dst); + } + + +void *kmemset(void * dst, int c, size_t length) { + size_t x = length >> 2; + size_t y = length & 0xf; + size_t i; + + unsigned int newC = (c << 24) | (c << 16) | (c << 8) | (c); + + for (i = 0; i < x; i++) + ((unsigned long *)dst)[i] = newC; + + for (i = 0; i < y; i++) + ((char *) dst)[length-y+i] = c; + return dst; + } + +int kstrlen(const char * string) { + int i = 0; + + while (1) { + if (string[i] == '\0') + return i; + i++; + } + return 0; + } + +int kmemcmp(const void * dst, const void * src, size_t length) +{ + size_t x = length >> 2; + size_t y = length & 0xf; + size_t i; + + for (i = 0; i < x; i++) + { + if (((unsigned long *)dst)[i] > ((unsigned long *)src)[i]) + return 1; + if (((unsigned long *)dst)[i] < ((unsigned long *)src)[i]) + return -1; + } + + for (i = 0; i < y; i++) + { + if (((char *) dst)[length-y+i] > ((char *) src)[length-y+i]) + return 1; + if (((char *) dst)[length-y+i] < ((char *) src)[length-y+i]) + return -1; + } + + return 0; +} + +void kstrncpy(char * dest, const char * src, size_t size) +{ + if (size == 0) + return; + do + { + *dest = *src; + dest++; src++; + size--; + } + while(('\0' != *(src-1)) && (size)); +} + +/*** + $Log$ + Revision 1.2 2004/05/19 14:40:58 reddawg + Cleaned up some warning from leaving out typedefs + + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.5 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/lib/strtok.c b/src/sys/lib/strtok.c new file mode 100644 index 0000000..551d332 --- /dev/null +++ b/src/sys/lib/strtok.c @@ -0,0 +1,93 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +char *strtok_r(char *s, const char *delim, char **last) { + char *spanp; + int c, sc; + char *tok; + + if ((s == NULL) && ((s = *last) == NULL)) { + return(NULL); + } + +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0; ) { + if (c == sc) { + goto cont; + } + } + if (c == 0) { + *last = NULL; + return(NULL); + } + tok = s - 1; + + for (;;) { + c = *s++; + spanp = (char *)delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) { + s = NULL; + } + else { + char *w = s - 1; + *w = '\0'; + } + *last = s; + return(tok); + } + } while (sc != 0); + } + } + +char *strtok(char *s, const char *delim) { + static char *last; + return (strtok_r(s, delim, &last)); + } + +/*** + $Log$ + Revision 1.2 2004/05/19 03:46:32 reddawg + A Few Quick Hacks To Make Things Work + + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + + diff --git a/src/sys/lib/strtol.c b/src/sys/lib/strtol.c new file mode 100644 index 0000000..2314ad4 --- /dev/null +++ b/src/sys/lib/strtol.c @@ -0,0 +1,102 @@ +#include +//#include +//#include +//#include + +#define LONG_MIN (-0x7fffffffL - 1) +#define LONG_MAX 0x7fffffffL + + + +long +strtol(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long acc; + char c = 0x0; /* to remove warning */ + unsigned long cutoff; + int neg, any, cutlim; + + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + s = nptr; + /* + do { + c = *s++; + } while (isspace((unsigned char)c)); + */ + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set 'any' if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? (unsigned long)-(LONG_MIN + LONG_MAX) + LONG_MAX + : LONG_MAX; + cutlim = cutoff % base; + cutoff /= base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_MIN : LONG_MAX; + //errno = ERANGE; + } else if (!any) { +noconv: + //errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/sys/lib/vsprintf.c b/src/sys/lib/vsprintf.c new file mode 100644 index 0000000..7c90958 --- /dev/null +++ b/src/sys/lib/vsprintf.c @@ -0,0 +1,273 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1.1.1 2004/04/15 12:07:11 reddawg + UbixOS v1.0 + + Revision 1.3 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ +/* + * Wirzenius wrote this portably, Torvalds fucked it up :-) + */ + +#include +#include + +/* we use this so that we can do without the ctype library */ +#define is_digit(c) ((c) >= '0' && (c) <= '9') + +static int skip_atoi(const char **s) +{ + int i=0; + + while (is_digit(**s)) + i = i*10 + *((*s)++) - '0'; + return i; +} + +#define ZEROPAD 1 /* pad with zero */ +#define SIGN 2 /* unsigned/signed long */ +#define PLUS 4 /* show plus */ +#define SPACE 8 /* space if plus */ +#define LEFT 16 /* left justified */ +#define SPECIAL 32 /* 0x */ +#define SMALL 64 /* use 'abcdef' instead of 'ABCDEF' */ + +#define do_div(n,base) ({ \ +int __res; \ +__asm__("divl %4":"=a" (n),"=d" (__res):"0" (n),"1" (0),"r" (base)); \ +__res; }) + +static char * number(char * str, int num, int base, int size, int precision + ,int type) +{ + char c,sign,tmp[36]; + const char *digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int i; + + if (type&SMALL) digits="0123456789abcdefghijklmnopqrstuvwxyz"; + if (type&LEFT) type &= ~ZEROPAD; + if (base<2 || base>36) + return 0; + c = (type & ZEROPAD) ? '0' : ' ' ; + if (type&SIGN && num<0) { + sign='-'; + num = -num; + } else + sign=(type&PLUS) ? '+' : ((type&SPACE) ? ' ' : 0); + if (sign) size--; + if (type&SPECIAL) { + if (base==16) { size -= 2; } + else if (base==8) { size--; } + } + i=0; + if (num==0) + tmp[i++]='0'; + else while (num!=0) + tmp[i++]=digits[do_div(num,base)]; + if (i>precision) precision=i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) + while(size-->0) + *str++ = ' '; + if (sign) + *str++ = sign; + if (type&SPECIAL) { + if (base==8) { + *str++ = '0'; + } + else if (base==16) { + *str++ = '0'; + *str++ = digits[33]; + } + } + if (!(type&LEFT)) + while(size-->0) + *str++ = c; + while(i0) + *str++ = tmp[i]; + while(size-->0) + *str++ = ' '; + return str; +} + +int vsprintf(char *buf, const char *fmt, vaList args) +{ + int len; + int i; + char * str; + char *s; + int *ip; + + int flags; /* flags to number() */ + + int field_width; /* width of output field */ + int precision; /* min. # of digits for integers; max + number of chars for from string */ + int qualifier; /* 'h', 'l', or 'L' for integer fields */ + + for (str=buf ; *fmt ; ++fmt) { + if (*fmt != '%') { + *str++ = *fmt; + continue; + } + + /* process flags */ + flags = 0; + repeat: + ++fmt; /* this also skips first '%' */ + switch (*fmt) { + case '-': flags |= LEFT; goto repeat; + case '+': flags |= PLUS; goto repeat; + case ' ': flags |= SPACE; goto repeat; + case '#': flags |= SPECIAL; goto repeat; + case '0': flags |= ZEROPAD; goto repeat; + } + + /* get field width */ + field_width = -1; + if (is_digit(*fmt)) + field_width = skip_atoi(&fmt); + else if (*fmt == '*') { + /* it's the next argument */ + field_width = vaArg(args, int); + if (field_width < 0) { + field_width = -field_width; + flags |= LEFT; + } + } + + /* get the precision */ + precision = -1; + if (*fmt == '.') { + ++fmt; + if (is_digit(*fmt)) + precision = skip_atoi(&fmt); + else if (*fmt == '*') { + /* it's the next argument */ + precision = vaArg(args, int); + } + if (precision < 0) + precision = 0; + } + + /* get the conversion qualifier */ + qualifier = -1; + if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { + qualifier = *fmt; + ++fmt; + } + + switch (*fmt) { + case 'c': + if (!(flags & LEFT)) + while (--field_width > 0) + *str++ = ' '; + *str++ = (unsigned char) vaArg(args, int); + while (--field_width > 0) + *str++ = ' '; + break; + + case 's': + s = vaArg(args, char *); + len = kstrlen(s); + if (precision < 0) + precision = len; + else if (len > precision) + len = precision; + + if (!(flags & LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = *s++; + while (len < field_width--) + *str++ = ' '; + break; + + case 'o': + str = number(str, vaArg(args, unsigned long), 8, + field_width, precision, flags); + break; + + case 'p': + if (field_width == -1) { + field_width = 8; + flags |= ZEROPAD; + } + str = number(str, + (unsigned long) vaArg(args, void *), 16, + field_width, precision, flags); + break; + + case 'x': + flags |= SMALL; + case 'X': + str = number(str, vaArg(args, unsigned long), 16, + field_width, precision, flags); + break; + + case 'd': + case 'i': + flags |= SIGN; + case 'u': + str = number(str, vaArg(args, unsigned long), 10, + field_width, precision, flags); + break; + + case 'n': + ip = vaArg(args, int *); + *ip = (str - buf); + break; + + default: + if (*fmt != '%') + *str++ = '%'; + if (*fmt) + *str++ = *fmt; + else + --fmt; + break; + } + } + *str = '\0'; + return str-buf; +} + +/*** + END + ***/ + diff --git a/src/sys/mpi/Makefile b/src/sys/mpi/Makefile new file mode 100644 index 0000000..11142f5 --- /dev/null +++ b/src/sys/mpi/Makefile @@ -0,0 +1,27 @@ +# (C) 2002-2004 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = message.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -Wall -DNOBOOL -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -Wall -DNOBOOL -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) -Wall -O $(CLFAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall -O -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/mpi/message.c b/src/sys/mpi/message.c new file mode 100644 index 0000000..ae5b7da --- /dev/null +++ b/src/sys/mpi/message.c @@ -0,0 +1,281 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static mpiMbox_t *mboxList = 0x0; +static spinLock_t mpiSpinLock = SPIN_LOCK_INITIALIZER; + +/***************************************************************************************** + + Function: static mpiMbox_t * mpiFindMbox(char *name) + + Description: This function will find a mail box that matches the supplied name + + Notes: + +*****************************************************************************************/ +static mpiMbox_t * mpiFindMbox(char *name) { + mpiMbox_t *mbox = 0x0; + + for (mbox = mboxList;mbox;mbox = mbox->next) { + if (!kstrcmp(mbox->name,name)) { + spinUnlock(&mpiSpinLock); + return(mbox); + } + } + + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiCreateMbox(char *name) + + Description: This function will create a new mailbox if it fails it will return -1 + otherwise it returns 0x0 + + Notes: + +*****************************************************************************************/ +int mpiCreateMbox(char *name) { + mpiMbox_t *mbox = 0x0; + + spinLock(&mpiSpinLock); + + if (mpiFindMbox(name) != 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + mbox = (mpiMbox_t *)kmalloc(sizeof(mpiMbox_t)); + + sprintf(mbox->name,name); + mbox->pid = _current->id; + + if (mboxList == 0x0) { + mbox->prev = 0x0; + mbox->next = 0x0; + mboxList = mbox; + } + else { + mbox->next = mboxList; + mbox->prev = 0x0; + mboxList->prev = mbox; + mboxList = mbox; + } + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiSpam(uInt32 type,void *data) + + Description: This function will send a message to every mailbox + + Notes: + +*****************************************************************************************/ +int mpiSpam(uInt32 type,void *data) { + mpiMbox_t *mbox = 0x0; + mpiMessage_t *message = 0x0; + + spinLock(&mpiSpinLock); + + for (mbox = mboxList;mbox;mbox = mbox->next) { + message = (mpiMessage_t *)kmalloc(sizeof(mpiMessage_t)); + + message->type = type; + kmemcpy(message->data,data,MESSAGE_LENGTH); + message->next = 0x0; + + if (mbox->msg == 0x0) { + mbox->msg = message; + } + else { + mbox->msgLast->next = message; + mbox->msgLast = message; + } + } + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiPostMessage(char *name,uInt32 type,void *data) + + Description: This function will post a message to specified mailbox + + Notes: + +*****************************************************************************************/ +int mpiPostMessage(char *name,uInt32 type,void *data) { + mpiMbox_t *mbox = 0x0; + mpiMessage_t *message = 0x0; + + spinLock(&mpiSpinLock); + + mbox = mpiFindMbox(name); + + if (mbox == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + message = (mpiMessage_t *)kmalloc(sizeof(mpiMessage_t)); + + message->type = type; + kmemcpy(message->data,data,MESSAGE_LENGTH); + message->next = 0x0; + + if (mbox->msg == 0x0) { + mbox->msg = message; + } + else { + mbox->msgLast->next = message; + mbox->msgLast = message; + } + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiFetchMessage(char *name,mpiMessage_t *msg) + + Description: This function will fetch the next message out of the specified mailbox + + Notes: + +*****************************************************************************************/ +int mpiFetchMessage(char *name,mpiMessage_t *msg) { + mpiMbox_t *mbox = 0x0; + mpiMessage_t *tmpMsg = 0x0; + + spinLock(&mpiSpinLock); + + mbox = mpiFindMbox(name); + + if (mbox == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + if (mbox->msg == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + if (mbox->pid != _current->id) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + msg->type = mbox->msg->type; + kmemcpy(msg->data,mbox->msg->data,MESSAGE_LENGTH); + + tmpMsg = mbox->msg; + mbox->msg = mbox->msg->next; + + kfree(tmpMsg); + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiDestroyMbox(char *name) + + Description: This function will fetch the next message out of the specified mailbox + + Notes: + +*****************************************************************************************/ +int mpiDestroyMbox(char *name) { + mpiMbox_t *mbox = 0x0; + + spinLock(&mpiSpinLock); + + for (mbox = mboxList;mbox;mbox=mbox->next) { + if (!kstrcmp(mbox->name,name)) { + if (mbox->pid != _current->id) { + spinUnlock(&mpiSpinLock); + return(-1); + } + mbox->prev->next = mbox->next; + mbox->next->prev = mbox->prev; + kfree(mbox); + spinUnlock(&mpiSpinLock); + return(0x0); + } + } + + spinUnlock(&mpiSpinLock); + return(-1); + } + +/*** + $Log$ + Revision 1.9 2004/05/26 15:34:29 reddawg + mpi: oops forgot a spinUnlock + + Revision 1.8 2004/05/26 11:58:37 reddawg + mpi: Fixed security now the pid used at time of mpiCreateMbox is the only pid + allowed to do mpiFetchMessage and mpiDestroyMbox against that mail box + + Revision 1.7 2004/05/25 22:25:39 reddawg + Typo Fix + + Revision 1.6 2004/05/25 18:32:02 reddawg + Made MESSAGE_LENGTH define instead of hard coded message size + + Revision 1.4 2004/05/25 16:52:22 reddawg + We now have mpiDestroyMbox(char *) This will of course destroy a mail box + + Revision 1.3 2004/05/25 16:33:26 reddawg + Added some basic documentation + + Revision 1.2 2004/05/25 15:42:18 reddawg + Enabled mpiSpam(); + + Revision 1.1 2004/05/25 14:03:22 reddawg + First insertion of the MPI into our kernel + + END + ***/ + diff --git a/src/sys/net/Makefile b/src/sys/net/Makefile new file mode 100644 index 0000000..f009abf --- /dev/null +++ b/src/sys/net/Makefile @@ -0,0 +1,22 @@ +# $Id$ +# The System Makefile (C) 2002 The UbixOS Project + +all: core-code net-code api-code netif-code + +core-code: core + (cd core;make) + +net-code: net + (cd net;make) + +api-code: api + (cd api;make) + +netif-code: netif + (cd netif;make) + +clean: + (cd core;make clean) + (cd net;make clean) + (cd api;make clean) + (cd netif;make clean) diff --git a/src/sys/net/api/Makefile b/src/sys/net/api/Makefile new file mode 100644 index 0000000..9f74f5c --- /dev/null +++ b/src/sys/net/api/Makefile @@ -0,0 +1,28 @@ +# (C) 2002 The UbixOS Project +# +# $Id$ + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +# Objects +OBJS = api_lib.o api_msg.o err.o sockets.o tcpip.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/net/api/api_lib.c b/src/sys/net/api/api_lib.c new file mode 100644 index 0000000..ed9100b --- /dev/null +++ b/src/sys/net/api/api_lib.c @@ -0,0 +1,648 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +/* This is the part of the API that is linked with + the application */ + +#include + +#include "net/debug.h" +#include "net/api.h" +#include "net/api_msg.h" +#include "net/memp.h" + +#include "net/debug.h" + +#include "lib/kprintf.h" +/*-----------------------------------------------------------------------------------*/ +struct +netbuf *netbuf_new(void) +{ + struct netbuf *buf; + + buf = memp_mallocp(MEMP_NETBUF); + if(buf != NULL) { + buf->p = NULL; + buf->ptr = NULL; + return buf; + } else { + return NULL; + } +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_delete(struct netbuf *buf) +{ + if(buf != NULL) { + if(buf->p != NULL) { + pbuf_free(buf->p); + buf->p = buf->ptr = NULL; + } + memp_freep(MEMP_NETBUF, buf); + } +} +/*-----------------------------------------------------------------------------------*/ +void * +netbuf_alloc(struct netbuf *buf, uInt16 size) +{ + /* Deallocate any previously allocated memory. */ + if(buf->p != NULL) { + pbuf_free(buf->p); + } + buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM); + if(buf->p == NULL) { + return NULL; + } + buf->ptr = buf->p; + return buf->p->payload; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_free(struct netbuf *buf) +{ + if(buf->p != NULL) { + pbuf_free(buf->p); + } + buf->p = buf->ptr = NULL; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_ref(struct netbuf *buf, void *dataptr, uInt16 size) +{ + if(buf->p != NULL) { + pbuf_free(buf->p); + } + buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_ROM); + buf->p->payload = dataptr; + buf->p->len = buf->p->tot_len = size; + buf->ptr = buf->p; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_chain(struct netbuf *head, struct netbuf *tail) +{ + pbuf_chain(head->p, tail->p); + head->ptr = head->p; + memp_freep(MEMP_NETBUF, tail); +} +/*-----------------------------------------------------------------------------------*/ +uInt16 +netbuf_len(struct netbuf *buf) +{ + return buf->p->tot_len; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netbuf_data(struct netbuf *buf, void **dataptr, uInt16 *len) +{ + if(buf->ptr == NULL) { + return ERR_BUF; + } + *dataptr = buf->ptr->payload; + *len = buf->ptr->len; + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +Int8 +netbuf_next(struct netbuf *buf) +{ + if(buf->ptr->next == NULL) { + return -1; + } + buf->ptr = buf->ptr->next; + if(buf->ptr->next == NULL) { + return 1; + } + return 0; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_first(struct netbuf *buf) +{ + buf->ptr = buf->p; +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_copy_partial(struct netbuf *buf, void *dataptr, uInt16 len, uInt16 offset) +{ + struct pbuf *p; + uInt16 i, left; + + left = 0; + + if(buf == NULL) { + return; + } + + /* This implementation is bad. It should use bcopy + instead. */ + for(p = buf->p; left < len && p != NULL; p = p->next) { + if(offset != 0 && offset >= p->len) { + offset -= p->len; + } else { + for(i = offset; i < p->len; ++i) { + ((char *)dataptr)[left] = ((char *)p->payload)[i]; + if(++left >= len) { + return; + } + } + } + } +} +/*-----------------------------------------------------------------------------------*/ +void +netbuf_copy(struct netbuf *buf, void *dataptr, uInt16 len) +{ + netbuf_copy_partial(buf, dataptr, len, 0); +} +/*-----------------------------------------------------------------------------------*/ +struct ip_addr * +netbuf_fromaddr(struct netbuf *buf) +{ + return buf->fromaddr; +} +/*-----------------------------------------------------------------------------------*/ +uInt16 +netbuf_fromport(struct netbuf *buf) +{ + return buf->fromport; +} +/*-----------------------------------------------------------------------------------*/ +struct +netconn *netconn_new(enum netconn_type t) +{ + struct netconn *conn; + + conn = memp_mallocp(MEMP_NETCONN); + if(conn == NULL) { + return NULL; + } + conn->type = t; + conn->pcb.tcp = NULL; + + if((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) { + memp_freep(MEMP_NETCONN, conn); + return NULL; + } + conn->recvmbox = SYS_MBOX_NULL; + conn->acceptmbox = SYS_MBOX_NULL; + conn->sem = SYS_SEM_NULL; + conn->state = NETCONN_NONE; + return conn; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_delete(struct netconn *conn) +{ + struct api_msg *msg; + void *mem; + + if(conn == NULL) { + return ERR_OK; + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return ERR_MEM; + } + + msg->type = API_MSG_DELCONN; + msg->msg.conn = conn; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + + /* Drain the recvmbox. */ + if(conn->recvmbox != SYS_MBOX_NULL) { + while(sys_arch_mbox_fetch(conn->recvmbox, &mem, 1) != 0) { + if(conn->type == NETCONN_TCP) { + pbuf_free((struct pbuf *)mem); + } else { + netbuf_delete((struct netbuf *)mem); + } + } + sys_mbox_free(conn->recvmbox); + conn->recvmbox = SYS_MBOX_NULL; + } + + + /* Drain the acceptmbox. */ + if(conn->acceptmbox != SYS_MBOX_NULL) { + while(sys_arch_mbox_fetch(conn->acceptmbox, &mem, 1) != 0) { + netconn_delete((struct netconn *)mem); + } + + sys_mbox_free(conn->acceptmbox); + conn->acceptmbox = SYS_MBOX_NULL; + } + + sys_mbox_free(conn->mbox); + conn->mbox = SYS_MBOX_NULL; + if(conn->sem != SYS_SEM_NULL) { + sys_sem_free(conn->sem); + } + /* conn->sem = SYS_SEM_NULL;*/ + memp_free(MEMP_NETCONN, conn); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +enum netconn_type +netconn_type(struct netconn *conn) +{ + return conn->type; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_peer(struct netconn *conn, struct ip_addr **addr, + uInt16 *port) +{ + switch(conn->type) { + case NETCONN_UDPLITE: + case NETCONN_UDPNOCHKSUM: + case NETCONN_UDP: + *addr = &(conn->pcb.udp->remote_ip); + *port = conn->pcb.udp->remote_port; + break; + case NETCONN_TCP: + *addr = &(conn->pcb.tcp->remote_ip); + *port = conn->pcb.tcp->remote_port; + break; + } + return (conn->err = ERR_OK); +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_addr(struct netconn *conn, struct ip_addr **addr, + uInt16 *port) +{ + switch(conn->type) { + case NETCONN_UDPLITE: + case NETCONN_UDPNOCHKSUM: + case NETCONN_UDP: + *addr = &(conn->pcb.udp->local_ip); + *port = conn->pcb.udp->local_port; + break; + case NETCONN_TCP: + *addr = &(conn->pcb.tcp->local_ip); + *port = conn->pcb.tcp->local_port; + break; + } + return (conn->err = ERR_OK); +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_bind(struct netconn *conn, struct ip_addr *addr, + uInt16 port) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->type != NETCONN_TCP && + conn->recvmbox == SYS_MBOX_NULL) { + if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + msg->type = API_MSG_BIND; + msg->msg.conn = conn; + msg->msg.msg.bc.ipaddr = addr; + msg->msg.msg.bc.port = port; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_connect(struct netconn *conn, struct ip_addr *addr, + uInt16 port) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + + if(conn->recvmbox == SYS_MBOX_NULL) { + if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return ERR_MEM; + } + msg->type = API_MSG_CONNECT; + msg->msg.conn = conn; + msg->msg.msg.bc.ipaddr = addr; + msg->msg.msg.bc.port = port; + kprintf("1"); + api_msg_post(msg); + kprintf("2: [0x%X]",conn->mbox); + sys_mbox_fetch(conn->mbox, NULL); + kprintf("3"); + memp_freep(MEMP_API_MSG, msg); + kprintf("4"); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_listen(struct netconn *conn) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->acceptmbox == SYS_MBOX_NULL) { + conn->acceptmbox = sys_mbox_new(); + if(conn->acceptmbox == SYS_MBOX_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + msg->type = API_MSG_LISTEN; + msg->msg.conn = conn; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +struct netconn * +netconn_accept(struct netconn *conn) +{ + struct netconn *newconn; + + if(conn == NULL) { + return NULL; + } + + sys_mbox_fetch(conn->acceptmbox, (void **)&newconn); + + return newconn; +} +/*-----------------------------------------------------------------------------------*/ +struct netbuf * +netconn_recv(struct netconn *conn) +{ + struct api_msg *msg; + struct netbuf *buf; + struct pbuf *p; + + if(conn == NULL) { + return NULL; + } + + if(conn->recvmbox == SYS_MBOX_NULL) { + conn->err = ERR_CONN; + return NULL; + } + + if(conn->err != ERR_OK) { + return NULL; + } + + if(conn->type == NETCONN_TCP) { + if(conn->pcb.tcp->state == LISTEN) { + conn->err = ERR_CONN; + return NULL; + } + + + buf = memp_mallocp(MEMP_NETBUF); + + if(buf == NULL) { + conn->err = ERR_MEM; + return NULL; + } + + sys_mbox_fetch(conn->recvmbox, (void **)&p); + + /* If we are closed, we indicate that we no longer wish to recieve + data by setting conn->recvmbox to SYS_MBOX_NULL. */ + if(p == NULL) { + memp_freep(MEMP_NETBUF, buf); + sys_mbox_free(conn->recvmbox); + conn->recvmbox = SYS_MBOX_NULL; + return NULL; + } + + buf->p = p; + buf->ptr = p; + buf->fromport = 0; + buf->fromaddr = NULL; + + /* Let the stack know that we have taken the data. */ + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + conn->err = ERR_MEM; + return buf; + } + msg->type = API_MSG_RECV; + msg->msg.conn = conn; + if(buf != NULL) { + msg->msg.msg.len = buf->p->tot_len; + } else { + msg->msg.msg.len = 1; + } + api_msg_post(msg); + + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + } else { + sys_mbox_fetch(conn->recvmbox, (void **)&buf); + } + + + + + DEBUGF(API_LIB_DEBUG, ("netconn_recv: received %p (err %d)\n", buf, conn->err)); + + + return buf; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_send(struct netconn *conn, struct netbuf *buf) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->err != ERR_OK) { + return conn->err; + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + + DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %d bytes\n", buf->p->tot_len)); + msg->type = API_MSG_SEND; + msg->msg.conn = conn; + msg->msg.msg.p = buf->p; + api_msg_post(msg); + + sys_mbox_fetch(conn->mbox, NULL); + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_write(struct netconn *conn, void *dataptr, uInt16 size, uInt8 copy) +{ + struct api_msg *msg; + uInt16 len; + + if(conn == NULL) { + return ERR_VAL; + } + + if(conn->err != ERR_OK) { + return conn->err; + } + + if(conn->sem == SYS_SEM_NULL) { + conn->sem = sys_sem_new(0); + if(conn->sem == SYS_SEM_NULL) { + return ERR_MEM; + } + } + + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + msg->type = API_MSG_WRITE; + msg->msg.conn = conn; + + + conn->state = NETCONN_WRITE; + while(conn->err == ERR_OK && size > 0) { + msg->msg.msg.w.dataptr = dataptr; + msg->msg.msg.w.copy = copy; + + if(conn->type == NETCONN_TCP) { + if(tcp_sndbuf(conn->pcb.tcp) == 0) { + sys_sem_wait(conn->sem); + if(conn->err != ERR_OK) { + goto ret; + } + } + if(size > tcp_sndbuf(conn->pcb.tcp)) { + /* We cannot send more than one send buffer's worth of data at a + time. */ + len = tcp_sndbuf(conn->pcb.tcp); + } else { + len = size; + } + } else { + len = size; + } + + DEBUGF(API_LIB_DEBUG, ("netconn_write: writing %d bytes (%d)\n", len, copy)); + msg->msg.msg.w.len = len; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + if(conn->err == ERR_OK) { + dataptr = (void *)((char *)dataptr + len); + size -= len; + } else if(conn->err == ERR_MEM) { + conn->err = ERR_OK; + sys_sem_wait(conn->sem); + } else { + goto ret; + } + } + ret: + memp_freep(MEMP_API_MSG, msg); + conn->state = NETCONN_NONE; + if(conn->sem != SYS_SEM_NULL) { + sys_sem_free(conn->sem); + conn->sem = SYS_SEM_NULL; + } + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_close(struct netconn *conn) +{ + struct api_msg *msg; + + if(conn == NULL) { + return ERR_VAL; + } + if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { + return (conn->err = ERR_MEM); + } + + conn->state = NETCONN_CLOSE; + again: + msg->type = API_MSG_CLOSE; + msg->msg.conn = conn; + api_msg_post(msg); + sys_mbox_fetch(conn->mbox, NULL); + if(conn->err == ERR_MEM && + conn->sem != SYS_SEM_NULL) { + sys_sem_wait(conn->sem); + goto again; + } + conn->state = NETCONN_NONE; + memp_freep(MEMP_API_MSG, msg); + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ +err_t +netconn_err(struct netconn *conn) +{ + return conn->err; +} +/*-----------------------------------------------------------------------------------*/ + + + + diff --git a/src/sys/net/api/api_msg.c b/src/sys/net/api/api_msg.c new file mode 100644 index 0000000..a9965d4 --- /dev/null +++ b/src/sys/net/api/api_msg.c @@ -0,0 +1,529 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include + +#include "net/debug.h" +#include "net/arch.h" +#include "net/api_msg.h" +#include "net/memp.h" +#include "net/sys.h" +#include "net/tcpip.h" + +/*-----------------------------------------------------------------------------------*/ +static err_t +recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) +{ + struct netconn *conn; + + conn = arg; + + if(conn == NULL) { + pbuf_free(p); + return ERR_VAL; + } + + if(conn->recvmbox != SYS_MBOX_NULL) { + conn->err = err; + sys_mbox_post(conn->recvmbox, p); + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p, + struct ip_addr *addr, uInt16 port) +{ + struct netbuf *buf; + struct netconn *conn; + + conn = arg; + + if(conn == NULL) { + pbuf_free(p); + return; + } + + if(conn->recvmbox != SYS_MBOX_NULL) { + buf = memp_mallocp(MEMP_NETBUF); + if(buf == NULL) { + pbuf_free(p); + return; + } else { + buf->p = p; + buf->ptr = p; + buf->fromaddr = addr; + buf->fromport = port; + } + + sys_mbox_post(conn->recvmbox, buf); + } +} +/*-----------------------------------------------------------------------------------*/ +static err_t +poll_tcp(void *arg, struct tcp_pcb *pcb) +{ + struct netconn *conn; + + conn = arg; + if(conn != NULL && + (conn->state == NETCONN_WRITE || conn->state == NETCONN_CLOSE) && + conn->sem != SYS_SEM_NULL) { + sys_sem_signal(conn->sem); + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static err_t +sent_tcp(void *arg, struct tcp_pcb *pcb, uInt16 len) +{ + struct netconn *conn; + + conn = arg; + if(conn != NULL && conn->sem != SYS_SEM_NULL) { + sys_sem_signal(conn->sem); + } + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +err_tcp(void *arg, err_t err) +{ + struct netconn *conn; + + conn = arg; + + conn->pcb.tcp = NULL; + + + conn->err = err; + if(conn->recvmbox != SYS_MBOX_NULL) { + sys_mbox_post(conn->recvmbox, NULL); + } + if(conn->mbox != SYS_MBOX_NULL) { + sys_mbox_post(conn->mbox, NULL); + } + if(conn->acceptmbox != SYS_MBOX_NULL) { + sys_mbox_post(conn->acceptmbox, NULL); + } + if(conn->sem != SYS_SEM_NULL) { + sys_sem_signal(conn->sem); + } +} +/*-----------------------------------------------------------------------------------*/ +static void +setup_tcp(struct netconn *conn) +{ + struct tcp_pcb *pcb; + + pcb = conn->pcb.tcp; + tcp_arg(pcb, conn); + tcp_recv(pcb, recv_tcp); + tcp_sent(pcb, sent_tcp); + tcp_poll(pcb, poll_tcp, 4); + tcp_err(pcb, err_tcp); +} +/*-----------------------------------------------------------------------------------*/ +static err_t +accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) +{ + sys_mbox_t *mbox; + struct netconn *newconn; + +#if API_MSG_DEBUG +#if TCP_DEBUG + tcp_debug_print_state(newpcb->state); +#endif /* TCP_DEBUG */ +#endif /* API_MSG_DEBUG */ + mbox = (sys_mbox_t *)arg; + newconn = memp_mallocp(MEMP_NETCONN); + if(newconn == NULL) { + return ERR_MEM; + } + newconn->type = NETCONN_TCP; + newconn->pcb.tcp = newpcb; + setup_tcp(newconn); + newconn->recvmbox = sys_mbox_new(); + if(newconn->recvmbox == SYS_MBOX_NULL) { + memp_free(MEMP_NETCONN, newconn); + return ERR_MEM; + } + newconn->mbox = sys_mbox_new(); + if(newconn->mbox == SYS_MBOX_NULL) { + sys_mbox_free(newconn->recvmbox); + memp_free(MEMP_NETCONN, newconn); + return ERR_MEM; + } + newconn->sem = sys_sem_new(0); + if(newconn->sem == SYS_SEM_NULL) { + sys_mbox_free(newconn->recvmbox); + sys_mbox_free(newconn->mbox); + memp_free(MEMP_NETCONN, newconn); + return ERR_MEM; + } + newconn->acceptmbox = SYS_MBOX_NULL; + newconn->err = err; + sys_mbox_post(*mbox, newconn); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +do_newconn(struct api_msg_msg *msg) +{ +} +/*-----------------------------------------------------------------------------------*/ +static void +do_delconn(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + msg->conn->pcb.udp->recv_arg = NULL; + udp_remove(msg->conn->pcb.udp); + break; + case NETCONN_TCP: + tcp_arg(msg->conn->pcb.tcp, NULL); + tcp_sent(msg->conn->pcb.tcp, NULL); + tcp_recv(msg->conn->pcb.tcp, NULL); + tcp_accept(msg->conn->pcb.tcp, NULL); + tcp_poll(msg->conn->pcb.tcp, NULL, 0); + tcp_err(msg->conn->pcb.tcp, NULL); + if(msg->conn->pcb.tcp->state == LISTEN) { + tcp_close(msg->conn->pcb.tcp); + } else { + if(tcp_close(msg->conn->pcb.tcp) != ERR_OK) { + tcp_abort(msg->conn->pcb.tcp); + } + } + break; + } + } + if(msg->conn->mbox != SYS_MBOX_NULL) { + sys_mbox_post(msg->conn->mbox, NULL); + } +} +/*-----------------------------------------------------------------------------------*/ +static void +do_bind(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp == NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + msg->conn->pcb.udp = udp_new(); + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDPNOCHKSUM: + msg->conn->pcb.udp = udp_new(); + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDP: + msg->conn->pcb.udp = udp_new(); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_TCP: + msg->conn->pcb.tcp = tcp_new(); + setup_tcp(msg->conn); + break; + } + } + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port); + break; + case NETCONN_TCP: + msg->conn->err = tcp_bind(msg->conn->pcb.tcp, + msg->msg.bc.ipaddr, msg->msg.bc.port); + break; + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static err_t +do_connected(void *arg, struct tcp_pcb *pcb, err_t err) +{ + struct netconn *conn; + + conn = arg; + + if(conn == NULL) { + return ERR_VAL; + } + + conn->err = err; + + if(conn->type == NETCONN_TCP && err == ERR_OK) { + setup_tcp(conn); + } + + sys_mbox_post(conn->mbox, NULL); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +static void +do_connect(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp == NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDPNOCHKSUM: + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_UDP: + msg->conn->pcb.udp = udp_new(); + if(msg->conn->pcb.udp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); + break; + case NETCONN_TCP: + msg->conn->pcb.tcp = tcp_new(); + if(msg->conn->pcb.tcp == NULL) { + msg->conn->err = ERR_MEM; + sys_mbox_post(msg->conn->mbox, NULL); + return; + } + break; + } + } + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + udp_connect(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port); + sys_mbox_post(msg->conn->mbox, NULL); + break; + case NETCONN_TCP: + /* tcp_arg(msg->conn->pcb.tcp, msg->conn);*/ + setup_tcp(msg->conn); + tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port, + do_connected); + /*tcp_output(msg->conn->pcb.tcp);*/ + break; + } +} +/*-----------------------------------------------------------------------------------*/ +static void +do_listen(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + DEBUGF(API_MSG_DEBUG, ("api_msg: listen UDP: cannot listen for UDP.\n")); + break; + case NETCONN_TCP: + msg->conn->pcb.tcp = tcp_listen(msg->conn->pcb.tcp); + if(msg->conn->pcb.tcp == NULL) { + msg->conn->err = ERR_MEM; + } else { + if(msg->conn->acceptmbox == SYS_MBOX_NULL) { + msg->conn->acceptmbox = sys_mbox_new(); + if(msg->conn->acceptmbox == SYS_MBOX_NULL) { + msg->conn->err = ERR_MEM; + break; + } + } + tcp_arg(msg->conn->pcb.tcp, (void *)&(msg->conn->acceptmbox)); + tcp_accept(msg->conn->pcb.tcp, accept_function); + } + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_accept(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + DEBUGF(API_MSG_DEBUG, ("api_msg: accept UDP: cannot accept for UDP.\n")); + break; + case NETCONN_TCP: + break; + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +do_send(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + udp_send(msg->conn->pcb.udp, msg->msg.p); + break; + case NETCONN_TCP: + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_recv(struct api_msg_msg *msg) +{ + if(msg->conn->pcb.tcp != NULL) { + if(msg->conn->type == NETCONN_TCP) { + tcp_recved(msg->conn->pcb.tcp, msg->msg.len); + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_write(struct api_msg_msg *msg) +{ + err_t err; + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + msg->conn->err = ERR_VAL; + break; + case NETCONN_TCP: + err = tcp_write(msg->conn->pcb.tcp, msg->msg.w.dataptr, + msg->msg.w.len, msg->msg.w.copy); + /* This is the Nagle algorithm: inhibit the sending of new TCP + segments when new outgoing data arrives from the user if any + previously transmitted data on the connection remains + unacknowledged. */ + if(err == ERR_OK && msg->conn->pcb.tcp->unacked == NULL) { + tcp_output(msg->conn->pcb.tcp); + } + msg->conn->err = err; + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +static void +do_close(struct api_msg_msg *msg) +{ + err_t err; + if(msg->conn->pcb.tcp != NULL) { + switch(msg->conn->type) { + case NETCONN_UDPLITE: + /* FALLTHROUGH */ + case NETCONN_UDPNOCHKSUM: + /* FALLTHROUGH */ + case NETCONN_UDP: + break; + case NETCONN_TCP: + if(msg->conn->pcb.tcp->state == LISTEN) { + err = tcp_close(msg->conn->pcb.tcp); + } else { + err = tcp_close(msg->conn->pcb.tcp); + } + msg->conn->err = err; + break; + } + } + sys_mbox_post(msg->conn->mbox, NULL); +} +/*-----------------------------------------------------------------------------------*/ +typedef void (* api_msg_decode)(struct api_msg_msg *msg); +static api_msg_decode decode[API_MSG_MAX] = { + do_newconn, + do_delconn, + do_bind, + do_connect, + do_listen, + do_accept, + do_send, + do_recv, + do_write, + do_close + }; +void +api_msg_input(struct api_msg *msg) +{ + decode[msg->type](&(msg->msg)); +} +/*-----------------------------------------------------------------------------------*/ +void +api_msg_post(struct api_msg *msg) +{ + tcpip_apimsg(msg); +} +/*-----------------------------------------------------------------------------------*/ + + diff --git a/src/sys/net/api/err.c b/src/sys/net/api/err.c new file mode 100644 index 0000000..43ecf39 --- /dev/null +++ b/src/sys/net/api/err.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include "net/err.h" + +#ifdef LWIP_DEBUG + +static char *err_strerr[] = {"Ok.", + "Out of memory error.", + "Buffer error.", + "Connection aborted.", + "Connection reset.", + "Connection closed.", + "Not connected.", + "Illegal value.", + "Illegal argument.", + "Routing problem.", + "Address in use." +}; + +/*-----------------------------------------------------------------------------------*/ +char * +lwip_strerr(err_t err) +{ + return err_strerr[-err]; + +} +/*-----------------------------------------------------------------------------------*/ + +#endif /* LWIP_DEBUG */ diff --git a/src/sys/net/api/sockets.c b/src/sys/net/api/sockets.c new file mode 100644 index 0000000..4656ba6 --- /dev/null +++ b/src/sys/net/api/sockets.c @@ -0,0 +1,446 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include + +#include "net/debug.h" +#include "net/api.h" + +#include "net/sockets.h" + +#define NUM_SOCKETS 10 + +struct lwip_socket { + struct netconn *conn; + struct netbuf *lastdata; + uInt16 lastoffset; +}; + +static struct lwip_socket sockets[NUM_SOCKETS]; + +/*-----------------------------------------------------------------------------------*/ +static struct lwip_socket * +get_socket(int s) +{ + struct lwip_socket *sock; + + if(s > NUM_SOCKETS) { + /* errno = EBADF; */ + return NULL; + } + + sock = &sockets[s]; + + if(sock->conn == NULL) { + /* errno = EBADF; */ + return NULL; + } + return sock; +} +/*-----------------------------------------------------------------------------------*/ +static int +alloc_socket(struct netconn *newconn) +{ + int i; + + /* allocate a new socket identifier */ + for(i = 0; i < NUM_SOCKETS; ++i) { + if(sockets[i].conn == NULL) { + sockets[i].conn = newconn; + sockets[i].lastdata = NULL; + sockets[i].lastoffset = 0; + return i; + } + } + return -1; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_accept(int s, struct sockaddr *addr, int *addrlen) +{ + struct lwip_socket *sock; + struct netconn *newconn; + struct ip_addr *naddr; + uInt16 port; + int newsock; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + newconn = netconn_accept(sock->conn); + + /* get the IP address and port of the remote host */ + netconn_peer(newconn, &naddr, &port); + + ((struct sockaddr_in *)addr)->sin_addr.s_addr = naddr->addr; + ((struct sockaddr_in *)addr)->sin_port = port; + + newsock = alloc_socket(newconn); + if(newsock == -1) { + netconn_delete(newconn); + /* errno = ENOBUFS; */ + } + return newsock; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_bind(int s, struct sockaddr *name, int namelen) +{ + struct lwip_socket *sock; + struct ip_addr remote_addr; + uInt16 remote_port; + err_t err; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; + remote_port = ((struct sockaddr_in *)name)->sin_port; + + err = netconn_bind(sock->conn, &remote_addr, ntohs(remote_port)); + + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_close(int s) +{ + struct lwip_socket *sock; + + DEBUGF(SOCKETS_DEBUG, ("close: socket %d\n", s)); + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + + netconn_delete(sock->conn); + if(sock->lastdata != NULL) { + netbuf_delete(sock->lastdata); + } + sock->lastdata = NULL; + sock->lastoffset = 0; + sock->conn = NULL; + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_connect(int s, struct sockaddr *name, int namelen) +{ + struct lwip_socket *sock; + struct ip_addr remote_addr; + uInt16 remote_port; + err_t err; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; + remote_port = ((struct sockaddr_in *)name)->sin_port; + + err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port)); + + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_listen(int s, int backlog) +{ + struct lwip_socket *sock; + err_t err; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + err = netconn_listen(sock->conn); + + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return 0; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_recvfrom(int s, void *mem, int len, unsigned int flags, + struct sockaddr *from, int *fromlen) +{ + struct lwip_socket *sock; + struct netbuf *buf; + uInt16 buflen, copylen; + struct ip_addr *addr; + uInt16 port; + + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + /* Check if there is data left from the last recv operation. */ + if(sock->lastdata != NULL) { + buf = sock->lastdata; + } else { + /* No data was left from the previous operation, so we try to get + some from the network. */ + buf = netconn_recv(sock->conn); + + if(buf == NULL) { + /* We should really do some error checking here. */ + return 0; + } + } + + buflen = netbuf_len(buf); + + buflen -= sock->lastoffset; + + if(len > buflen) { + copylen = buflen; + } else { + copylen = len; + } + + /* copy the contents of the received buffer into + the supplied memory pointer mem */ + netbuf_copy_partial(buf, mem, copylen, sock->lastoffset); + + /* If this is a TCP socket, check if there is data left in the + buffer. If so, it should be saved in the sock structure for next + time around. */ + if(netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) { + sock->lastdata = buf; + sock->lastoffset = buflen - copylen; + } else { + sock->lastdata = NULL; + sock->lastoffset = 0; + netbuf_delete(buf); + } + + /* Check to see from where the data was. */ + if(from != NULL && fromlen != NULL) { + addr = netbuf_fromaddr(buf); + port = htons(netbuf_fromport(buf)); + ((struct sockaddr_in *)from)->sin_addr.s_addr = addr->addr; + ((struct sockaddr_in *)from)->sin_port = port; + *fromlen = sizeof(struct sockaddr_in); + } + + + /* if the length of the received data is larger than + len, this data is discarded and we return len. + otherwise we return the actual length of the received + data */ + if(len > copylen) { + return copylen; + } else { + return len; + } +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_read(int s, void *mem, int len) +{ + return lwip_recv(s, mem, len, 0); +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_recv(int s, void *mem, int len, unsigned int flags) +{ + return lwip_recvfrom(s, mem, len, flags, NULL, NULL); +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_send(int s, void *data, int size, unsigned int flags) +{ + struct lwip_socket *sock; + struct netbuf *buf; + err_t err; + + DEBUGF(SOCKETS_DEBUG, ("send: socket %d, size %d\n", s, size)); + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + switch(netconn_type(sock->conn)) { + case NETCONN_UDP: + /* create a buffer */ + buf = netbuf_new(); + + if(buf == NULL) { + /* errno = ENOBUFS; */ + return -1; + } + + /* make the buffer point to the data that should + be sent */ + netbuf_ref(buf, data, size); + + /* send the data */ + err = netconn_send(sock->conn, buf); + + /* deallocated the buffer */ + netbuf_delete(buf); + break; + case NETCONN_TCP: + err = netconn_write(sock->conn, data, size, NETCONN_COPY); + break; + default: + err = ERR_ARG; + break; + } + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + + return size; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_sendto(int s, void *data, int size, unsigned int flags, + struct sockaddr *to, int tolen) +{ + struct lwip_socket *sock; + struct ip_addr remote_addr, *addr; + uInt16 remote_port, port; + int ret; + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + /* get the peer if currently connected */ + netconn_peer(sock->conn, &addr, &port); + + remote_addr.addr = ((struct sockaddr_in *)to)->sin_addr.s_addr; + remote_port = ((struct sockaddr_in *)to)->sin_port; + netconn_connect(sock->conn, &remote_addr, remote_port); + + ret = lwip_send(s, data, size, flags); + + /* reset the remote address and port number + of the connection */ + netconn_connect(sock->conn, addr, port); + return ret; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_socket(int domain, int type, int protocol) +{ + struct netconn *conn; + int i; + + /* create a netconn */ + switch(type) { + case SOCK_DGRAM: + conn = netconn_new(NETCONN_UDP); + break; + case SOCK_STREAM: + conn = netconn_new(NETCONN_TCP); + break; + default: + /* errno = ... */ + return -1; + } + + if(conn == NULL) { + DEBUGF(SOCKETS_DEBUG, ("socket: could not create netconn.\n")); + /* errno = ENOBUFS; */ + return -1; + } + + i = alloc_socket(conn); + + if(i == -1) { + /* errno = ENOBUFS; */ + netconn_delete(conn); + } + return i; +} +/*-----------------------------------------------------------------------------------*/ +int +lwip_write(int s, void *data, int size) +{ + struct lwip_socket *sock; + err_t err; + + DEBUGF(SOCKETS_DEBUG, ("write: socket %d, size %d\n", s, size)); + + sock = get_socket(s); + if(sock == NULL) { + return -1; + } + + switch(netconn_type(sock->conn)) { + case NETCONN_UDP: + return lwip_send(s, data, size, 0); + + case NETCONN_TCP: + err = netconn_write(sock->conn, data, size, NETCONN_COPY); + break; + default: + err = ERR_ARG; + break; + } + if(err != ERR_OK) { + /* errno = ... */ + return -1; + } + return size; +} +/*-----------------------------------------------------------------------------------*/ diff --git a/src/sys/net/api/tcpip.c b/src/sys/net/api/tcpip.c new file mode 100644 index 0000000..62ab8c6 --- /dev/null +++ b/src/sys/net/api/tcpip.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include + +#include "net/debug.h" + +#include "net/opt.h" + +#include "net/sys.h" + +#include "net/memp.h" +#include "net/pbuf.h" + +#include "net/ipv4/ip.h" +#include "net/udp.h" +#include "net/tcp.h" + +#include "net/tcpip.h" + +static void (* tcpip_init_done)(void *arg) = NULL; +static void *tcpip_init_done_arg; +static sys_mbox_t mbox; + +/*-----------------------------------------------------------------------------------*/ +static void +tcpip_tcp_timer(void *arg) +{ + tcp_tmr(); + sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL); +} +/*-----------------------------------------------------------------------------------*/ + +static void +tcpip_thread(void *arg) +{ + struct tcpip_msg *msg; + + ip_init(); + udp_init(); + tcp_init(); + + sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL); + + if(tcpip_init_done != NULL) { + tcpip_init_done(tcpip_init_done_arg); + } + + while(1) { /* MAIN Loop */ + sys_mbox_fetch(mbox, (void *)&msg); + switch(msg->type) { + case TCPIP_MSG_API: + //kprintf("tcpip_thread: API message %p\n", msg); + api_msg_input(msg->msg.apimsg); + break; + case TCPIP_MSG_INPUT: + //kprintf("tcpip_thread: IP packet %p\n", msg); + ip_input(msg->msg.inp.p, msg->msg.inp.netif); + break; + default: + break; + } + memp_freep(MEMP_TCPIP_MSG, msg); + } +} +/*-----------------------------------------------------------------------------------*/ +err_t +tcpip_input(struct pbuf *p, struct netif *inp) +{ + struct tcpip_msg *msg; + + msg = memp_mallocp(MEMP_TCPIP_MSG); + if(msg == NULL) { + //kprintf("BAD MESSAGE!!!\n"); + pbuf_free(p); + return ERR_MEM; + } + //kprintf("GOOD MESSAGE\n"); + + msg->type = TCPIP_MSG_INPUT; + msg->msg.inp.p = p; + msg->msg.inp.netif = inp; + sys_mbox_post(mbox, msg); + return ERR_OK; +} +/*-----------------------------------------------------------------------------------*/ +void +tcpip_apimsg(struct api_msg *apimsg) +{ + struct tcpip_msg *msg; + msg = memp_mallocp(MEMP_TCPIP_MSG); + if(msg == NULL) { + memp_free(MEMP_TCPIP_MSG, apimsg); + return; + } + msg->type = TCPIP_MSG_API; + msg->msg.apimsg = apimsg; + sys_mbox_post(mbox, msg); +} +/*-----------------------------------------------------------------------------------*/ +void +tcpip_init(void (* initfunc)(void *), void *arg) +{ + tcpip_init_done = initfunc; + tcpip_init_done_arg = arg; + mbox = sys_mbox_new(); + sys_thread_new((void *)tcpip_thread, NULL); +} +/*-----------------------------------------------------------------------------------*/ + + + diff --git a/src/sys/net/net/Makefile b/src/sys/net/net/Makefile new file mode 100644 index 0000000..2e8bcfa --- /dev/null +++ b/src/sys/net/net/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +# Objects +OBJS = udpecho.o init.o sys_arch.o shell.o bot.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/net/net/bot.c b/src/sys/net/net/bot.c new file mode 100644 index 0000000..ba945fb --- /dev/null +++ b/src/sys/net/net/bot.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include +#include + +#include "net/mem.h" +#include "net/debug.h" +#include "net/def.h" +#include "net/api.h" +#include "net/stats.h" + +static void sendstr(const char *str, struct netconn *conn) { + netconn_write(conn, (void *)str, kstrlen(str), NETCONN_NOCOPY); + } + +static void botErr() { + kprintf("ERRROR\n"); + } + +static void bot_thread(void *arg) { + struct netconn *conn; + int len; + char bufr[1500]; + struct ip_addr ipaddr; + struct netbuf *buf = 0x0; + + IP4_ADDR(&ipaddr,216,152,77,10); + conn = netconn_new(NETCONN_TCP); + kprintf("Starting UbixOS Bot\n"); + while(1) { + kprintf("[A"); + kprintf("\n\nCONNECT: [%i]\n",netconn_connect(conn,&ipaddr,6667)); + kprintf("B]"); + while (1); + if (buf != NULL) { + buf = netconn_recv(conn); + netbuf_copy(buf, bufr, 1024); + len = netbuf_len(buf); + netbuf_delete(buf); + bufr[len-2] = '\0'; + kprintf("Bufr: [%s:%i]",bufr,len); + //sendstr("BLah\n",conn); + } + } + } + +void bot_init(void) { + sys_thread_new(bot_thread, NULL); + } + +/*** + END + ***/ + diff --git a/src/sys/net/net/init.c b/src/sys/net/net/init.c new file mode 100644 index 0000000..ea9cd39 --- /dev/null +++ b/src/sys/net/net/init.c @@ -0,0 +1,107 @@ +/***************************************************************************************** + Copyright (c) 2004 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +void netMainThread(); +static void tcpip_init_done(void *arg); + +int netInit() { + sys_init(); + mem_init(); + memp_init(); + pbuf_init(); + + sys_thread_new((void *)(netMainThread), NULL); + + return(0x0); + } + + +void netMainThread() { + struct ip_addr ipaddr, netmask, gw; + sys_sem_t sem; + + netif_init(); + sem = sys_sem_new(0); + tcpip_init(tcpip_init_done, &sem); + sys_sem_wait(sem); + sys_sem_free(sem); + kprintf("TCP/IP initialized.\n"); + + /* + IP4_ADDR(&gw, 192,168,0,1); + IP4_ADDR(&ipaddr, 192,168,0,69); + */ + IP4_ADDR(&gw, 10,4,0,1); + IP4_ADDR(&ipaddr, 10,4,0,69); + + IP4_ADDR(&netmask, 255,255,255,0); + netif_set_default(netif_add(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input)); + + IP4_ADDR(&gw, 127,0,0,1); + IP4_ADDR(&ipaddr, 127,0,0,1); + IP4_ADDR(&netmask, 255,0,0,0); + netif_add(&ipaddr, &netmask, &gw, loopif_init, tcpip_input); + + //udpecho_init(); + //shell_init(); + //bot_init(); + + kprintf("Application Started\n"); + + _current->state = DEAD; + schedYield(); + } + + +static void tcpip_init_done(void *arg) { + sys_sem_t *sem = 0x0; + sem = arg; + sys_sem_signal(*sem); + } + +/*** + END + ***/ + diff --git a/src/sys/net/net/shell.c b/src/sys/net/net/shell.c new file mode 100644 index 0000000..920fd71 --- /dev/null +++ b/src/sys/net/net/shell.c @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include + +#include "net/mem.h" +#include "net/debug.h" +#include "net/def.h" +#include "net/api.h" +#include "net/stats.h" + +#include "lib/kprintf.h" +char *buffer = 0x0; + +#define ESUCCESS 0 +#define ESYNTAX -1 +#define ETOOFEW -2 +#define ETOOMANY -3 +#define ECLOSED -4 + +#define NCONNS 10 +static struct netconn *conns[NCONNS]; + +static void sendstr(const char *str, struct netconn *conn) { + netconn_write(conn, (void *)str, kstrlen(str), NETCONN_NOCOPY); + } + +static void prompt(struct netconn *conn) { + sendstr("uBixCube:@sys> ", conn); + } + +static void shell_main(struct netconn *conn) { + struct netbuf *buf = 0x0; + uInt32 len; + int i; + char bufr[1500]; + + do { + if (buf != NULL) { + buf = netconn_recv(conn); + netbuf_copy(buf, buffer, 1024); + len = netbuf_len(buf); + netbuf_delete(buf); + buffer[len-2] = '\0'; + kprintf("Buffer: [%s:%i]",buffer,len); + //sprintf(bufr,"Command: %s not found.\n",buffer); + sendstr("BLah\n",conn); + } + if (buf != NULL) { + prompt(conn); + } + } while(buf != NULL); + kprintf("buf == NULL err %s\n", lwip_strerr(conn->err)); + close: + netconn_close(conn); + + for(i = 0; i < NCONNS; i++) { + if(conns[i] != NULL) { + netconn_delete(conns[i]); + } + conns[i] = NULL; + } + } + +static void shell_thread(void *arg) { + struct netconn *conn, *newconn; + + char *str = (char *)kmalloc(64); + + buffer = (char *)kmalloc(1024); + + conn = netconn_new(NETCONN_TCP); + netconn_bind(conn, NULL, 23); + netconn_listen(conn); + + while(1) { + newconn = netconn_accept(conn); + shell_main(newconn); + netconn_delete(newconn); + } + } + +void shell_init(void) { + sys_thread_new(shell_thread, NULL); + } + +/*** + END + ***/ + diff --git a/src/sys/net/net/shell.h b/src/sys/net/net/shell.h new file mode 100644 index 0000000..3f2ab99 --- /dev/null +++ b/src/sys/net/net/shell.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __SHELL_H__ +#define __SHELL_H__ + +void shell_init(void); + +#endif /* __SHELL_H__ */ diff --git a/src/sys/net/net/sys_arch.c b/src/sys/net/net/sys_arch.c new file mode 100644 index 0000000..1e6e178 --- /dev/null +++ b/src/sys/net/net/sys_arch.c @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * Sub Author: Christopher Olsen + * + * Notes: + * Modified to work with the ubix operating system + * + * $Log$ + * Revision 1.4 2004/05/25 22:49:29 reddawg + * Stupid Old CODE!!! + * + * Revision 1.3 2004/05/19 04:07:43 reddawg + * kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + * + * Revision 1.2 2004/05/19 03:35:02 reddawg + * Fixed A Few Ordering Issues In The Service Startup Routine + * + * Revision 1.1.1.1 2004/04/15 12:07:14 reddawg + * UbixOS v1.0 + * + * Revision 1.13 2004/04/13 21:29:53 reddawg + * We now have sockets working. Lots of functionality to be added to continually + * improve on the existing layers now its clean up time to get things in a better + * working order. + * + * Revision 1.12 2004/04/13 16:08:07 reddawg + * Removed all of the old debug code the problem seems to be in ubthreads with + * ubthread_mutex_init + * + * Revision 1.11 2004/04/13 16:05:40 reddawg + * Function Renaming + * + * + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include + +#include "net/debug.h" +#include "net/sys.h" +#include "net/opt.h" +#include "net/stats.h" + +#define UMAX(a, b) ((a) > (b) ? (a) : (b)) + +static struct sys_thread *threads = NULL; + +struct sys_mbox_msg { + struct sys_mbox_msg *next; + void *msg; +}; + +#define SYS_MBOX_SIZE 100 + +struct sys_mbox { + uInt16 first, last; + void *msgs[SYS_MBOX_SIZE]; + struct sys_sem *mail; + struct sys_sem *mutex; +}; + +struct sys_sem { + unsigned int c; + ubthread_cond_t cond; + ubthread_mutex_t mutex; +}; + +struct sys_thread { + struct sys_thread *next; + struct sys_timeouts timeouts; + kTask_t *ubthread; +}; + + +static struct timeval starttime; + +static struct sys_sem *sys_sem_new_(uInt8 count); +static void sys_sem_free_(struct sys_sem *sem); + +static uInt16 cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uInt16 timeout); + +static struct sys_thread *current_thread(void) { + struct sys_thread *st; + kTask_t *pt; + pt = ubthread_self(); + for(st = threads; st != NULL; st = st->next) { + if(st->ubthread == pt) { + return st; + } + } + kprintf("sys: current_thread: could not find current thread!\n"); + kprintf("This is due to a race condition in the LinuxThreads\n"); + kprintf("ubthreads implementation. Start the program again.\n"); + + kpanic("ABORT"); + return(0x0); + } + + +struct thread_start_param { + struct sys_thread *thread; + void (* function)(void *); + void *arg; + }; + +/* +static void *thread_start(void *arg) { + struct thread_start_param *tp = arg; + tp->thread->ubthread = ubthread_self(); + tp->function(tp->arg); + kfree(tp); + return(NULL); + } +*/ + +void sys_thread_new(void (* function)(void *arg), void *arg) { + struct sys_thread *thread; + struct thread_start_param *thread_param; + + thread = kmalloc(sizeof(struct sys_thread)); + thread->next = threads; + thread->timeouts.next = NULL; + thread->ubthread = 0; + threads = thread; + + thread_param = kmalloc(sizeof(struct thread_start_param)); + + thread_param->function = function; + thread_param->arg = arg; + thread_param->thread = thread; + + if(ubthread_create(&(thread->ubthread), NULL, function, arg) != 0) { + kpanic("sys_thread_new: ubthread_create"); + } + } + +struct sys_mbox *sys_mbox_new() { + struct sys_mbox *mbox; + + mbox = kmalloc(sizeof(struct sys_mbox)); + mbox->first = mbox->last = 0; + mbox->mail = sys_sem_new_(0); + mbox->mutex = sys_sem_new_(1); + + return(mbox); + } + +void sys_mbox_free(struct sys_mbox *mbox) { + if (mbox != SYS_MBOX_NULL) { + sys_sem_wait(mbox->mutex); + + sys_sem_free_(mbox->mail); + sys_sem_free_(mbox->mutex); + mbox->mail = mbox->mutex = NULL; + //kprintf("sys_mbox_free: mbox 0x%lx\n", mbox); + kfree(mbox); + } + } + +void sys_mbox_post(struct sys_mbox *mbox, void *msg) { + uInt8 first; + + sys_sem_wait(mbox->mutex); + + //kprintf("sys_mbox_post: mbox %p msg %p\n", mbox, msg); + + mbox->msgs[mbox->last] = msg; + + if (mbox->last == mbox->first) { + first = 1; + } + else { + first = 0; + } + + mbox->last++; + if(mbox->last == SYS_MBOX_SIZE) { + mbox->last = 0; + } + + if(first) { + sys_sem_signal(mbox->mail); + } + sys_sem_signal(mbox->mutex); + } + +uInt16 sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, uInt16 timeout) { + uInt16 time = 1; + + /* The mutex lock is quick so we don't bother with the timeout + stuff here. */ + sys_arch_sem_wait(mbox->mutex, 0); + + while(mbox->first == mbox->last) { + sys_sem_signal(mbox->mutex); + + /* We block while waiting for a mail to arrive in the mailbox. We + must be prepared to timeout. */ + if(timeout != 0) { + time = sys_arch_sem_wait(mbox->mail, timeout); + + /* If time == 0, the sem_wait timed out, and we return 0. */ + if(time == 0) { + return 0; + } + } else { + sys_arch_sem_wait(mbox->mail, 0); + } + + sys_arch_sem_wait(mbox->mutex, 0); + } + + if(msg != NULL) { + //kprintf("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg); + *msg = mbox->msgs[mbox->first]; + } + + mbox->first++; + if(mbox->first == SYS_MBOX_SIZE) { + mbox->first = 0; + } + + sys_sem_signal(mbox->mutex); + + return(time); + } + +struct sys_sem *sys_sem_new(uInt8 count) { + return sys_sem_new_(count); + } + +static struct sys_sem *sys_sem_new_(uInt8 count) { + struct sys_sem *sem; + + sem = kmalloc(sizeof(struct sys_sem)); + sem->c = count; + + ubthread_cond_init(&(sem->cond), NULL); + ubthread_mutex_init(&(sem->mutex), NULL); + + return sem; + } + +static uInt16 cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uInt16 timeout) { + unsigned int tdiff; + unsigned long sec, usec; + struct timeval rtime1, rtime2; + struct timespec ts; + struct timezone tz; + int retval; + + if (timeout > 0) { + /* Get a timestamp and add the timeout value. */ + gettimeofday(&rtime1, &tz); + sec = rtime1.tv_sec; + usec = rtime1.tv_usec; + usec += timeout % 1000 * 1000; + sec += (int)(timeout / 1000) + (int)(usec / 1000000); + usec = usec % 1000000; + ts.tv_nsec = usec * 1000; + ts.tv_sec = sec; + + retval = ubthread_cond_timedwait(cond, mutex, &ts); + if (retval == ETIMEDOUT) { + return 0; + } + else { + /* Calculate for how long we waited for the cond. */ + gettimeofday(&rtime2, &tz); + tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 + + (rtime2.tv_usec - rtime1.tv_usec) / 1000; + if (tdiff == 0) { + return 1; + } + return tdiff; + } + } + else { + ubthread_cond_wait(cond, mutex); + return 0; + } + } + +uInt16 sys_arch_sem_wait(struct sys_sem *sem, uInt16 timeout) { + uInt16 time = 1; + ubthread_mutex_lock(&(sem->mutex)); + while(sem->c <= 0) { + if(timeout > 0) { + time = cond_wait(&(sem->cond), &(sem->mutex), timeout); + if(time == 0) { + ubthread_mutex_unlock(&(sem->mutex)); + return 0; + } + } else { + cond_wait(&(sem->cond), &(sem->mutex), 0); + } + } + sem->c--; + ubthread_mutex_unlock(&(sem->mutex)); + return(time); + } + +void sys_sem_signal(struct sys_sem *sem) { + ubthread_mutex_lock(&(sem->mutex)); + sem->c++; + if(sem->c > 1) + sem->c = 1; + ubthread_cond_signal(&(sem->cond)); + ubthread_mutex_unlock(&(sem->mutex)); + } + +void sys_sem_free(struct sys_sem *sem) { + if(sem != SYS_SEM_NULL) { + sys_sem_free_(sem); + } + } + +static void sys_sem_free_(struct sys_sem *sem) { + ubthread_cond_destroy(&(sem->cond)); + ubthread_mutex_destroy(&(sem->mutex)); + kfree(sem); + } + +unsigned long sys_unix_now() { + struct timeval tv; + struct timezone tz; + long sec, usec; + unsigned long msec; + gettimeofday(&tv, &tz); + + sec = tv.tv_sec - starttime.tv_sec; + usec = tv.tv_usec - starttime.tv_usec; + msec = sec * 1000 + usec / 1000; + return msec; + } + +void sys_init() { + struct timezone tz; + gettimeofday(&starttime, &tz); + } + +struct sys_timeouts *sys_arch_timeouts(void) { + struct sys_thread *thread; + thread = current_thread(); + return(&thread->timeouts); + } + +/*** + END + ***/ diff --git a/src/sys/net/net/udpecho.c b/src/sys/net/net/udpecho.c new file mode 100644 index 0000000..f8b556a --- /dev/null +++ b/src/sys/net/net/udpecho.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include + +#include "net/api.h" +#include "net/sys.h" + +/*-----------------------------------------------------------------------------------*/ +void +udpecho_thread(void *arg) +{ + static struct netconn *conn; + static struct netbuf *buf; + static struct ip_addr *addr; + static unsigned short port; + char buffer[4096]; + + kprintf("1"); + conn = netconn_new(NETCONN_UDP); + kprintf("2"); + netconn_bind(conn, NULL, 7); + kprintf("3"); + + while(1) { + kprintf("a"); + buf = netconn_recv(conn); + kprintf("b"); + addr = netbuf_fromaddr(buf); + kprintf("c"); + port = netbuf_fromport(buf); + kprintf("d"); + netconn_connect(conn, addr, port); + kprintf("e"); + netconn_send(conn, buf); + kprintf("f"); + netbuf_copy(buf, buffer, sizeof(buffer)); + kprintf("got %s\n", buffer); + netbuf_delete(buf); + kprintf("g"); + } +} +/*-----------------------------------------------------------------------------------*/ +void +udpecho_init(void) +{ + sys_thread_new(udpecho_thread, NULL); +} diff --git a/src/sys/net/net/udpecho.h b/src/sys/net/net/udpecho.h new file mode 100644 index 0000000..9faea8f --- /dev/null +++ b/src/sys/net/net/udpecho.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#ifndef __UDPECHO_H__ +#define __UDPECHO_H__ + +void udpecho_init(void); + +#endif /* __UDPECHO_H__ */ diff --git a/src/sys/net/netif/Makefile b/src/sys/net/netif/Makefile new file mode 100755 index 0000000..d11a495 --- /dev/null +++ b/src/sys/net/netif/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../../Makefile.inc +include ../../Makefile.inc + +# Objects +OBJS = ethernetif.o loopif.o tcpdump.o arp.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/net/netif/arp.c b/src/sys/net/netif/arp.c new file mode 100644 index 0000000..48f74e6 --- /dev/null +++ b/src/sys/net/netif/arp.c @@ -0,0 +1,307 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + * + */ + +#include +#include + +#include "net/debug.h" +#include "net/ipv4/inet.h" +#include "netif/arp.h" +#include "net/ipv4/ip.h" + + +#define ARP_MAXAGE 2 /* 120 * 10 seconds = 20 minutes. */ + +#define HWTYPE_ETHERNET 1 + +#define ARP_REQUEST 1 +#define ARP_REPLY 2 + +/* MUST be compiled with "pack structs" or equivalent! */ +PACK_STRUCT_BEGIN +struct arp_hdr { + PACK_STRUCT_FIELD(struct eth_hdr ethhdr); + PACK_STRUCT_FIELD(uInt16 hwtype); + PACK_STRUCT_FIELD(uInt16 proto); + PACK_STRUCT_FIELD(uInt16 _hwlen_protolen); + PACK_STRUCT_FIELD(uInt16 opcode); + PACK_STRUCT_FIELD(struct eth_addr shwaddr); + PACK_STRUCT_FIELD(struct ip_addr sipaddr); + PACK_STRUCT_FIELD(struct eth_addr dhwaddr); + PACK_STRUCT_FIELD(struct ip_addr dipaddr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END + +#define ARPH_HWLEN(hdr) (NTOHS((hdr)->_hwlen_protolen) >> 8) +#define ARPH_PROTOLEN(hdr) (NTOHS((hdr)->_hwlen_protolen) & 0xff) + + +#define ARPH_HWLEN_SET(hdr, len) (hdr)->_hwlen_protolen = HTONS(ARPH_PROTOLEN(hdr) | ((len) << 8)) +#define ARPH_PROTOLEN_SET(hdr, len) (hdr)->_hwlen_protolen = HTONS((len) | (ARPH_HWLEN(hdr) << 8)) + +PACK_STRUCT_BEGIN +struct ethip_hdr { + PACK_STRUCT_FIELD(struct eth_hdr eth); + PACK_STRUCT_FIELD(struct ip_hdr ip); +}; +PACK_STRUCT_END + +struct arp_entry { + struct ip_addr ipaddr; + struct eth_addr ethaddr; + uInt8 ctime; +}; + +static struct arp_entry arp_table[ARP_TABLE_SIZE]; +static uInt8 ctime; + +/*-----------------------------------------------------------------------------------*/ +void +arp_init(void) +{ + uInt8 i; + + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + ip_addr_set(&(arp_table[i].ipaddr), + IP_ADDR_ANY); + } +} +/*-----------------------------------------------------------------------------------*/ +void +arp_tmr(void) +{ + uInt8 i; + + ++ctime; + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(!ip_addr_isany(&arp_table[i].ipaddr) && + ctime - arp_table[i].ctime >= ARP_MAXAGE) { + DEBUGF(ARP_DEBUG, ("arp_timer: expired entry %d.\n", i)); + ip_addr_set(&(arp_table[i].ipaddr), + IP_ADDR_ANY); + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +add_arp_entry(struct ip_addr *ipaddr, struct eth_addr *ethaddr) +{ + uInt8 i, j, k; + uInt8 maxtime; + + /* Walk through the ARP mapping table and try to find an entry to + update. If none is found, the IP -> MAC address mapping is + inserted in the ARP table. */ + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + + /* Only check those entries that are actually in use. */ + if(!ip_addr_isany(&arp_table[i].ipaddr)) { + /* Check if the source IP address of the incoming packet matches + the IP address in this ARP table entry. */ + if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { + /* An old entry found, update this and return. */ + for(k = 0; k < 6; ++k) { + arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; + } + arp_table[i].ctime = ctime; + return; + } + } + } + + /* If we get here, no existing ARP table entry was found, so we + create one. */ + + /* First, we try to find an unused entry in the ARP table. */ + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(ip_addr_isany(&arp_table[i].ipaddr)) { + break; + } + } + + /* If no unused entry is found, we try to find the oldest entry and + throw it away. */ + if(i == ARP_TABLE_SIZE) { + maxtime = 0; + j = 0; + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(ctime - arp_table[i].ctime > maxtime) { + maxtime = ctime - arp_table[i].ctime; + j = i; + } + } + i = j; + } + + /* Now, i is the ARP table entry which we will fill with the new + information. */ + ip_addr_set(&arp_table[i].ipaddr, ipaddr); + for(k = 0; k < 6; ++k) { + arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; + } + arp_table[i].ctime = ctime; + return; + +} +/*-----------------------------------------------------------------------------------*/ +void +arp_ip_input(struct netif *netif, struct pbuf *p) +{ + struct ethip_hdr *hdr; + + hdr = p->payload; + + /* Only insert/update an entry if the source IP address of the + incoming IP packet comes from a host on the local network. */ + if(!ip_addr_maskcmp(&(hdr->ip.src), &(netif->ip_addr), &(netif->netmask))) { + return; + } + DEBUGF(ARP_DEBUG, ("arp_ip_input: updating ARP table.\n")); + add_arp_entry(&(hdr->ip.src), &(hdr->eth.src)); +} +/*-----------------------------------------------------------------------------------*/ +struct pbuf * +arp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) +{ + struct arp_hdr *hdr; + uInt8 i; + + if(p->tot_len < sizeof(struct arp_hdr)) { + kprintf("arp_arp_input: packet too short (%d/%d)\n", p->tot_len, sizeof(struct arp_hdr)); + pbuf_free(p); + return NULL; + } + + hdr = p->payload; + + switch(htons(hdr->opcode)) { + case ARP_REQUEST: + /* ARP request. If it asked for our address, we send out a + reply. */ + if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { + hdr->opcode = htons(ARP_REPLY); + + ip_addr_set(&(hdr->dipaddr), &(hdr->sipaddr)); + ip_addr_set(&(hdr->sipaddr), &(netif->ip_addr)); + + for(i = 0; i < 6; ++i) { + hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i]; + hdr->shwaddr.addr[i] = ethaddr->addr[i]; + hdr->ethhdr.dest.addr[i] = hdr->dhwaddr.addr[i]; + hdr->ethhdr.src.addr[i] = ethaddr->addr[i]; + } + + hdr->hwtype = htons(HWTYPE_ETHERNET); + ARPH_HWLEN_SET(hdr, 6); + + hdr->proto = htons(ETHTYPE_IP); + ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr)); + + hdr->ethhdr.type = htons(ETHTYPE_ARP); + return p; + } + break; + case ARP_REPLY: + /* ARP reply. We insert or update the ARP table. */ + if(ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr))) { + add_arp_entry(&(hdr->sipaddr), &(hdr->shwaddr)); + } + break; + default: + kprintf("arp_arp_input: unknown type %d\n", htons(hdr->opcode)); + break; + } + + pbuf_free(p); + return NULL; +} +/*-----------------------------------------------------------------------------------*/ +struct eth_addr * +arp_lookup(struct ip_addr *ipaddr) +{ + uInt8 i; + + for(i = 0; i < ARP_TABLE_SIZE; ++i) { + if(ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { + return &arp_table[i].ethaddr; + } + } + return NULL; +} +/*-----------------------------------------------------------------------------------*/ +struct pbuf * +arp_query(struct netif *netif, struct eth_addr *ethaddr, struct ip_addr *ipaddr) +{ + struct arp_hdr *hdr; + struct pbuf *p; + uInt8 i; + + p = pbuf_alloc(PBUF_LINK, sizeof(struct arp_hdr), PBUF_RAM); + if(p == NULL) { + return NULL; + } + + hdr = p->payload; + + hdr->opcode = htons(ARP_REQUEST); + + for(i = 0; i < 6; ++i) { + hdr->dhwaddr.addr[i] = 0x00; + hdr->shwaddr.addr[i] = ethaddr->addr[i]; + } + + ip_addr_set(&(hdr->dipaddr), ipaddr); + ip_addr_set(&(hdr->sipaddr), &(netif->ip_addr)); + + hdr->hwtype = htons(HWTYPE_ETHERNET); + ARPH_HWLEN_SET(hdr, 6); + + hdr->proto = htons(ETHTYPE_IP); + ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr)); + + for(i = 0; i < 6; ++i) { + hdr->ethhdr.dest.addr[i] = 0xff; + hdr->ethhdr.src.addr[i] = ethaddr->addr[i]; + } + + hdr->ethhdr.type = htons(ETHTYPE_ARP); + return p; +} +/*-----------------------------------------------------------------------------------*/ + + + + diff --git a/src/sys/net/netif/ethernetif.c b/src/sys/net/netif/ethernetif.c new file mode 100644 index 0000000..91b6fa1 --- /dev/null +++ b/src/sys/net/netif/ethernetif.c @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +/* + * This file is a skeleton for developing Ethernet network interface + * drivers for lwIP. Add code to the low_level functions and do a + * search-and-replace for the word "ethernetif" to replace it with + * something that better describes your network interface. + */ + +#include +#include +#include +#include +#include + + +#include "net/debug.h" + +#include "net/opt.h" +#include "net/def.h" +#include "net/mem.h" +#include "net/pbuf.h" +#include "net/sys.h" + +#include "netif/arp.h" + +/* Define those to better describe your network interface. */ +#define IFNAME0 'e' +#define IFNAME1 'd' + +struct nicBuffer *tmpBuf = 0x0; + +struct ethernetif { + struct eth_addr *ethaddr; + /* Add whatever per-interface state that is needed here. */ +}; + +static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; + +/* Forward declarations. */ +static void ethernetif_input(struct netif *netif); +static err_t ethernetif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); +static void ethernetif_thread(); +struct device *dev = 0x0; + +/*-----------------------------------------------------------------------------------*/ +static void low_level_init(struct netif *netif) { + struct ethernetif *ethernetif; + + ethernetif = netif->state; + dev = (struct device *)kmalloc(sizeof(struct device)); + dev->ioAddr = 0x280; + dev->irq = 10; + + /* Obtain MAC address from network interface. */ + ethernetif->ethaddr->addr[0] = 0x00; + ethernetif->ethaddr->addr[1] = 0x00; + ethernetif->ethaddr->addr[2] = 0xC0; + ethernetif->ethaddr->addr[3] = 0x97; + ethernetif->ethaddr->addr[4] = 0xC6; + ethernetif->ethaddr->addr[5] = 0x93; + + /* Do whatever else is needed to initialize interface. */ + + sys_thread_new(ethernetif_thread, netif); + + } +/*-----------------------------------------------------------------------------------*/ +/* + * low_level_output(): + * + * Should do the actual transmission of the packet. The packet is + * contained in the pbuf that is passed to the function. This pbuf + * might be chained. + * + */ +/*-----------------------------------------------------------------------------------*/ + +static err_t low_level_output(struct ethernetif *ethernetif, struct pbuf *p) { + struct pbuf *q; + char buf[1500]; + char *bufptr = 0x0; + + dev->ioAddr = 0x280; + dev->irq = 10; + + bufptr = &buf[0]; + + for(q = p; q != NULL; q = q->next) { + bcopy(q->payload, bufptr, q->len); + bufptr += q->len; + } + PCtoNIC(dev,buf,p->tot_len); + //kprintf("Sending Data[%i]\n",p->tot_len); + return ERR_OK; + } + + +/*-----------------------------------------------------------------------------------*/ +/* + * low_level_input(): + * + * Should allocate a pbuf and transfer the bytes of the incoming + * packet from the interface into the pbuf. + * + */ +/*-----------------------------------------------------------------------------------*/ +static struct pbuf *low_level_input(struct ethernetif *ethernetif) { + struct pbuf *p, *q; + uInt16 len; + char *bufptr; + char *buf; + + len = tmpBuf->length; + bufptr = tmpBuf->buffer; + + + /* We allocate a pbuf chain of pbufs from the pool. */ + p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL); + + if(p != NULL) { + /* We iterate over the pbuf chain until we have read the entire + packet into the pbuf. */ + //bufptr = &buf[0]; + for(q = p; q != NULL; q = q->next) { + /* Read enough bytes to fill this pbuf in the chain. The + avaliable data in the pbuf is given by the q->len + variable. */ + /* read data into(q->payload, q->len); */ + bcopy(bufptr, q->payload, q->len); + buf = q->payload; + bufptr += q->len; + } + /* acknowledge that packet has been read(); */ + } else { + /* drop packet(); */ + } + return p; +} + + +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_output(): + * + * This function is called by the TCP/IP stack when an IP packet + * should be sent. It calls the function called low_level_output() to + * do the actuall transmission of the packet. + * + */ +/*-----------------------------------------------------------------------------------*/ +static err_t ethernetif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) { + struct ethernetif *ethernetif; + struct pbuf *q; + struct eth_hdr *ethhdr; + struct eth_addr *dest, mcastaddr; + struct ip_addr *queryaddr; + err_t err; + uInt8 i; + + ethernetif = netif->state; + + + /* Make room for Ethernet header. */ + if(pbuf_header(p, sizeof(struct eth_hdr)) != 0) { + /* The pbuf_header() call shouldn't fail, but we allocate an extra + pbuf just in case. */ + q = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr), PBUF_RAM); + if(q == NULL) { + return ERR_MEM; + } + pbuf_chain(q, p); + p = q; + } + + /* Construct Ethernet header. Start with looking up deciding which + MAC address to use as a destination address. Broadcasts and + multicasts are special, all other addresses are looked up in the + ARP table. */ + queryaddr = ipaddr; + if(ip_addr_isany(ipaddr) || + ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { + dest = (struct eth_addr *)ðbroadcast; + } else if(ip_addr_ismulticast(ipaddr)) { + /* Hash IP multicast address to MAC address. */ + mcastaddr.addr[0] = 0x01; + mcastaddr.addr[1] = 0x0; + mcastaddr.addr[2] = 0x5e; + mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f; + mcastaddr.addr[4] = ip4_addr3(ipaddr); + mcastaddr.addr[5] = ip4_addr4(ipaddr); + dest = &mcastaddr; + } else { + if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { + /* Use destination IP address if the destination is on the same + subnet as we are. */ + queryaddr = ipaddr; + } else { + /* Otherwise we use the default router as the address to send + the Ethernet frame to. */ + queryaddr = &(netif->gw); + } + dest = arp_lookup(queryaddr); + } + + + /* If the arp_lookup() didn't find an address, we send out an ARP + query for the IP address. */ + if(dest == NULL) { + q = arp_query(netif, ethernetif->ethaddr, queryaddr); + if(q != NULL) { + err = low_level_output(ethernetif, q); + pbuf_free(q); + return err; + } + return ERR_MEM; + } + ethhdr = p->payload; + + for(i = 0; i < 6; i++) { + ethhdr->dest.addr[i] = dest->addr[i]; + ethhdr->src.addr[i] = ethernetif->ethaddr->addr[i]; + } + + ethhdr->type = htons(ETHTYPE_IP); + + return low_level_output(ethernetif, p); + +} +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_input(): + * + * This function should be called when a packet is ready to be read + * from the interface. It uses the function low_level_input() that + * should handle the actual reception of bytes from the network + * interface. + * + */ +/*-----------------------------------------------------------------------------------*/ +static void ethernetif_input(struct netif *netif) { + struct ethernetif *ethernetif; + struct eth_hdr *ethhdr; + struct pbuf *p; + + + ethernetif = netif->state; + + p = low_level_input(ethernetif); + + if(p != NULL) { + + ethhdr = p->payload; + + switch(htons(ethhdr->type)) { + case ETHTYPE_IP: + arp_ip_input(netif, p); + pbuf_header(p, -14); + netif->input(p, netif); + break; + case ETHTYPE_ARP: + p = arp_arp_input(netif, ethernetif->ethaddr, p); + if(p != NULL) { + low_level_output(ethernetif, p); + pbuf_free(p); + } + break; + default: + pbuf_free(p); + break; + } + } +} +/*-----------------------------------------------------------------------------------*/ +static void +arp_timer(void *arg) +{ + arp_tmr(); + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); +} + +/*-----------------------------------------------------------------------------------*/ +/* + * ethernetif_init(): + * + * Should be called at the beginning of the program to set up the + * network interface. It calls the function low_level_init() to do the + * actual setup of the hardware. + * + */ +/*-----------------------------------------------------------------------------------*/ +void ethernetif_init(struct netif *netif) { + struct ethernetif *ethernetif; + + ethernetif = mem_malloc(sizeof(struct ethernetif)); + netif->state = ethernetif; + netif->name[0] = IFNAME0; + netif->name[1] = IFNAME1; + netif->output = ethernetif_output; + netif->linkoutput = (void *)low_level_output; + + ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); + + low_level_init(netif); + arp_init(); + + sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); + } + +/*-----------------------------------------------------------------------------------*/ + +void ethernetif_thread(void *arg) { + struct netif *netif; + + netif = arg; + + while (1) { + tmpBuf = ne2kGetBuffer(); + if (tmpBuf->length > 0x0) { + ethernetif_input(netif); + } + } + ne2kFreeBuffer(tmpBuf); + } diff --git a/src/sys/net/netif/loopif.c b/src/sys/net/netif/loopif.c new file mode 100644 index 0000000..fbf42a8 --- /dev/null +++ b/src/sys/net/netif/loopif.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ +#include "net/debug.h" +#include "net/mem.h" +#include "net/opt.h" +#include "netif/loopif.h" +#include "netif/tcpdump.h" + +#include "net/tcp.h" +#include "net/ipv4/ip.h" + +/*-----------------------------------------------------------------------------------*/ +static err_t +loopif_output(struct netif *netif, struct pbuf *p, + struct ip_addr *ipaddr) +{ + struct pbuf *q, *r; + char *ptr; + +#ifdef LWIP_DEBUG + tcpdump(p); +#endif /* LWIP_DEBUG */ + + r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); + if(r != NULL) { + ptr = r->payload; + + for(q = p; q != NULL; q = q->next) { + bcopy(q->payload, ptr, q->len); + ptr += q->len; + } + netif->input(r, netif); + return ERR_OK; + } + return ERR_MEM; +} +/*-----------------------------------------------------------------------------------*/ +void +loopif_init(struct netif *netif) +{ + netif->name[0] = 'l'; + netif->name[1] = 'o'; + netif->output = loopif_output; +} +/*-----------------------------------------------------------------------------------*/ + + + + + + + diff --git a/src/sys/net/netif/tcpdump.c b/src/sys/net/netif/tcpdump.c new file mode 100644 index 0000000..582224f --- /dev/null +++ b/src/sys/net/netif/tcpdump.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * 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. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * $Id$ + */ + +#include +#include + +#include "netif/tcpdump.h" +#include "net/ipv4/ip.h" +#include "net/tcp.h" +#include "net/udp.h" +#include "net/ipv4/inet.h" + +fileDescriptor *file = NULL; + +void tcpdump_init(void) { + char *fname; + + fname = "tcpdump"; + file = fopen(fname, "wb"); + if(file == NULL) { + kpanic("tcpdump_init: fopen\n"); + } + } + +void tcpdump(struct pbuf *p) { + struct ip_hdr *iphdr; + struct tcp_hdr *tcphdr; + struct udp_hdr *udphdr; + char flags[5]; + int i; + int len; + int offset; + + if (file == NULL) { + return; + } + + /* + iphdr = p->payload; + switch(IPH_PROTO(iphdr)) { + case IP_PROTO_TCP: + tcphdr = (struct tcp_hdr *)((char *)iphdr + IP_HLEN); + + pbuf_header(p, -IP_HLEN); + if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), + (struct ip_addr *)&(iphdr->dest), + IP_PROTO_TCP, p->tot_len) != 0) { + DEBUGF(TCPDUMP_DEBUG, ("tcpdump: IP checksum failed!\n")); + fprintf(file, "!chksum "); + } + + i = 0; + if(TCPH_FLAGS(tcphdr) & TCP_SYN) { + flags[i++] = 'S'; + } + if(TCPH_FLAGS(tcphdr) & TCP_PSH) { + flags[i++] = 'P'; + } + if(TCPH_FLAGS(tcphdr) & TCP_FIN) { + flags[i++] = 'F'; + } + if(TCPH_FLAGS(tcphdr) & TCP_RST) { + flags[i++] = 'R'; + } + if(i == 0) { + flags[i++] = '.'; + } + flags[i++] = 0; + + + + fprintf(file, "%d.%d.%d.%d.%u > %d.%d.%d.%d.%u: ", + (int)(ntohl(iphdr->src.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 0) & 0xff, + ntohs(tcphdr->src), + (int)(ntohl(iphdr->dest.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 0) & 0xff, + ntohs(tcphdr->dest)); + offset = TCPH_OFFSET(tcphdr) >> 4; + + len = ntohs(IPH_LEN(iphdr)) - offset * 4 - IP_HLEN; + if(len != 0 || flags[0] != '.') { + fprintf(file, "%s %lu:%lu(%u) ", + flags, + ntohl(tcphdr->seqno), + ntohl(tcphdr->seqno) + len, + len); + } + if(TCPH_FLAGS(tcphdr) & TCP_ACK) { + fprintf(file, "ack %lu ", + ntohl(tcphdr->ackno)); + } + fprintf(file, "wnd %u\n", + ntohs(tcphdr->wnd)); + + fflush(file); + + pbuf_header(p, IP_HLEN); + break; + + case IP_PROTO_UDP: + udphdr = (struct udp_hdr *)((char *)iphdr + IP_HLEN); + + pbuf_header(p, -IP_HLEN); + if(inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), + (struct ip_addr *)&(iphdr->dest), + IP_PROTO_UDP, p->tot_len) != 0) { + kprintf("tcpdump: IP checksum failed!\n"); + fprintf(file, "!chksum "); + } + + fprintf(file, "%d.%d.%d.%d.%u > %d.%d.%d.%d.%u: ", + (int)(ntohl(iphdr->src.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->src.addr) >> 0) & 0xff, + ntohs(udphdr->src), + (int)(ntohl(iphdr->dest.addr) >> 24) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 16) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 8) & 0xff, + (int)(ntohl(iphdr->dest.addr) >> 0) & 0xff, + ntohs(udphdr->dest)); + fprintf(file, "U "); + len = ntohs(IPH_LEN(iphdr)) - sizeof(struct udp_hdr) - IP_HLEN; + fprintf(file, " %d\n", len); + + fflush(file); + + pbuf_header(p, IP_HLEN); + break; + + } + */ + } + +/*** + END + ***/ + diff --git a/src/sys/pci/Makefile b/src/sys/pci/Makefile new file mode 100644 index 0000000..aa4fe8a --- /dev/null +++ b/src/sys/pci/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = hd.o pci.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) -Wall -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/pci/hd.c b/src/sys/pci/hd.c new file mode 100644 index 0000000..bab82a9 --- /dev/null +++ b/src/sys/pci/hd.c @@ -0,0 +1,353 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +struct driveInfo *hdd0; +struct driveInfo *hdd0s1; +struct driveInfo *hdd1; +struct driveInfo *hdd2; +struct driveInfo *hdd3; + +void initHardDisk() { + struct deviceInterface *devInfo = 0x0; + hdd0 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + hdd0s1 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + hdd1 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + hdd2 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + hdd3 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + hdd0->hdPort = 0x1F0; + hdd0->hdDev = 0x40; + hdd0->parOffset = 0x0; + hdd0s1->hdPort = 0x1F0; + hdd0s1->hdDev = 0x40; + hdd0s1->parOffset = 63; + hdd1->hdPort = 0x1F0; + hdd1->hdDev = 0x50; + hdd2->hdPort = 0x177; + hdd2->hdDev = 0x40; + hdd3->hdPort = 0x177; + hdd3->hdDev = 0x50; + + /* Alloc memory for device structure and set it up correctly */ + devInfo = (struct deviceInterface *)kmalloc(sizeof(struct deviceInterface)); + devInfo->read = (void *)&hdRead; + devInfo->write = (void *)&hdWrite; + devInfo->reset = (void *)&hdReset; + devInfo->init = (void *)&hdInit; + devInfo->ioctl = (void *)&hdIoctl; + devInfo->stop = (void *)&hdStop; + devInfo->start = (void *)&hdStart; + devInfo->standby = (void *)&hdStandby; + devInfo->info = hdd0; + devInfo->major = 1; + deviceAdd(0,'c',devInfo); + + //deviceAdd(1,0,'c',hdRead,hdWrite,hdReset,hdInit,hdIoctl,hdStop,hdStart,hdStandby,hdd0); + //deviceAdd(1,1,'c',hdRead,hdWrite,hdReset,hdInit,hdIoctl,hdStop,hdStart,hdStandby,hdd0s1); + devFsMkNod("ad0",'c',0x1,0x0); + devFsMkNod("ad0s1",'c',0x1,0x1); + /* + if (!initDrive(hdd1)) { + addDrive(2,1,hdd1,hdRead,hdWrite,0x0); + } + if (!initDrive(hdd2)) { + addDrive(3,1,hdd2,hdRead,hdWrite,0x0); + } + if (!initDrive(hdd3)) { + addDrive(4,1,hdd3,hdRead,hdWrite,0x0); + } + */ + return; + } + +int hdStandby() { + return(0x0); + } + +int hdStart() { + return(0x0); + } + +int hdStop() { + return(0x0); + } + +int hdIoctl() { + return(0x0); + } + +int hdReset() { + return(0x0); + } + +int hdInit(struct deviceNode *dev) { + char retVal = 0x0; + long counter = 0x0; + short *tmp = 0x0; + struct driveInfo *hdd = dev->devInfo->info; + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat) & 0x80; + if (!retVal) goto ready; + } + kprintf("Error Initializing Drive\n"); + return(1); + ready: + outportByte(hdd->hdPort + hdHead,hdd->hdDev); + outportByte(hdd->hdPort + hdCmd,0xEC); + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat); + if ((retVal & 1) != 0x0) { + kprintf("Error Drive Not Available\n"); + return(1); + } + if ((retVal & 8) != 0x0) { + goto go; + } + } + kprintf("Time Out Waiting On Drive\n"); + return(1); + go: + tmp = (short *)hdd->hdSector; + for (counter = 0;counter < (512/2);counter++) { + tmp[counter] = inportWord(hdd->hdPort + hdData); + } + retVal = tmp[0x2F] & 0xFF; + switch (retVal) { + case 0: + hdd->hdShift = 0; + hdd->hdMulti = 1; + break; + case 2: + hdd->hdShift = 1; + hdd->hdMulti = retVal; + break; + case 4: + hdd->hdShift = 2; + hdd->hdMulti = retVal; + break; + case 8: + hdd->hdShift = 3; + hdd->hdMulti = retVal; + break; + case 16: + hdd->hdShift = 4; + hdd->hdMulti = retVal; + break; + case 32: + hdd->hdShift = 5; + hdd->hdMulti = retVal; + break; + case 64: + hdd->hdShift = 6; + hdd->hdMulti = retVal; + break; + default: + kprintf("Error BLOCK Mode Unavailable: [%i]\n",retVal); + return(1); + } + outportByte(hdd->hdPort + hdSecCount,retVal); + outportByte(hdd->hdPort + hdHead,hdd->hdDev); + outportByte(hdd->hdPort + hdCmd,0xC6); + hdd->hdMask = retVal; + hdd->hdSize = (hdd->hdSector[0x7B] * 256 * 256 * 256) + (hdd->hdSector[0x7A] * 256 * 256) + (hdd->hdSector[0x79] * 256) + hdd->hdSector[0x78]; + hdd->hdEnable = 1; + kprintf("Drive: [0x%X/0x%X], Size: [%iSectors/%iKBytes]\n",hdd->hdPort,hdd->hdDev,hdd->hdSize,((hdd->hdSize*512)/1024)); + dev->size = hdd->hdSize*512; + return(0x0); + } + +void hdWrite(struct driveInfo *hdd,void *baseAddr,uInt32 startSector,uInt32 sectorCount) { + long counter = 0x0; + long retVal = 0x0; + short transactionCount = 0x0; + short *tmp = (short *)baseAddr; + startSector += hdd->parOffset; + if (hdd->hdEnable == 0x0) { + kprintf("Invalid Drive\n"); + return; + } + if ((sectorCount >> hdd->hdShift) == 0x0) { + hdd->hdCalc = sectorCount; /* hdd->hdMask; */ + transactionCount = 1; + } + else { + hdd->hdCalc = hdd->hdMulti; + transactionCount = sectorCount >> hdd->hdShift; + } + for (;transactionCount > 0;transactionCount--) { + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat) & 0x80; + if (!retVal) goto ready; + } + kprintf("Time Out Waiting On Drive\n"); + return; + ready: + outportByte(hdd->hdPort + hdSecCount,hdd->hdCalc); + outportByte(hdd->hdPort + hdSecNum,(startSector & 0xFF)); + retVal = startSector >> 8; + outportByte(hdd->hdPort + hdCylLow,(retVal & 0xFF)); + retVal >>= 8; + outportByte(hdd->hdPort + hdCylHi,(retVal & 0xFF)); + retVal >>= 8; + retVal &= 0x0F; + retVal |= hdd->hdDev; + outportByte(hdd->hdPort + hdHead,(retVal & 0xFF)); + if (hdd->hdShift > 0) + outportByte(hdd->hdPort + hdCmd,0xC5); + else + outportByte(hdd->hdPort + hdCmd,0x30); + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat); + if ((retVal & 1) != 0x0) { + kprintf("HD Write Error\n"); + return; + } + if ((retVal & 8) != 0x0) { + goto go; + } + } + kprintf("Time Out Waiting On Drive\n"); + return; + go: + for (counter = 0;counter < (hdd->hdCalc << 8);counter++) { + outportWord(hdd->hdPort + hdData,(short)tmp[counter]); + } + tmp += (counter + 0); + startSector += hdd->hdCalc; + } + return; + } + +void hdRead(struct driveInfo *hdd,void *baseAddr,uInt32 startSector,uInt32 sectorCount) { + long counter = 0x0; + long retVal = 0x0; + short transactionCount = 0x0; + short *tmp = (short *)baseAddr; + startSector += hdd->parOffset; + if (hdd->hdEnable == 0x0) { + kprintf("Invalid Drive\n"); + return; + } + if ((sectorCount >> hdd->hdShift) == 0x0) { + hdd->hdCalc = sectorCount; /* hdd->hdMask); */ + transactionCount = 1; + } + else { + hdd->hdCalc = hdd->hdMulti; + transactionCount = sectorCount >> hdd->hdShift; + } + for (;transactionCount > 0;transactionCount--) { + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat) & 0x80; + if (!retVal) goto ready; + } + kprintf("Time Out Waiting On Drive\n"); + return; + ready: + outportByte(hdd->hdPort + hdSecCount,hdd->hdCalc); + outportByte(hdd->hdPort + hdSecNum,(startSector & 0xFF)); + retVal = startSector >> 8; + outportByte(hdd->hdPort + hdCylLow,(retVal & 0xFF)); + retVal >>= 8; + outportByte(hdd->hdPort + hdCylHi,(retVal & 0xFF)); + retVal >>= 8; + retVal &= 0x0F; + retVal |= hdd->hdDev; + outportByte(hdd->hdPort + hdHead,(retVal & 0xFF)); + if (hdd->hdShift > 0) + outportByte(hdd->hdPort + hdCmd,0xC4); + else + outportByte(hdd->hdPort + hdCmd,0x20); + for (counter = 1000000;counter >= 0;counter--) { + retVal = inportByte(hdd->hdPort + hdStat); + if ((retVal & 1) != 0x0) { + kprintf("HD Read Error: [%i:0x%X:%i]\n",counter,(uInt32)baseAddr,startSector); + return; + } + if ((retVal & 8) != 0x0) { + goto go; + } + } + kprintf("Error: Time Out Waiting On Drive\n"); + return; + go: + for (counter = 0;counter < (hdd->hdCalc << 8);counter++) { + tmp[counter] = inportWord(hdd->hdPort + hdData); + } + tmp += (counter + 0); + startSector += hdd->hdCalc; + } + return; + } + +/*** + $Log$ + Revision 1.11 2004/05/19 23:36:52 reddawg + Bug Fixes + + Revision 1.10 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.9 2004/05/19 15:07:59 reddawg + Typo defInfo should of been devInfo + + Revision 1.7 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.6 2004/04/28 21:10:40 reddawg + Lots Of changes to make it work with existing os + + Revision 1.5 2004/04/28 02:37:34 reddawg + More updates for using the new driver subsystem + + Revision 1.4 2004/04/28 02:22:54 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.3 2004/04/27 21:05:19 reddawg + Updating drivers to use new model + + Revision 1.2 2004/04/26 22:22:33 reddawg + DevFS now uses correct size of device + + Revision 1.1.1.1 2004/04/15 12:07:16 reddawg + UbixOS v1.0 + + Revision 1.12 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/src/sys/pci/lnc.c b/src/sys/pci/lnc.c new file mode 100644 index 0000000..6eaf811 --- /dev/null +++ b/src/sys/pci/lnc.c @@ -0,0 +1,304 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1.1.1 2004/04/15 12:07:15 reddawg + UbixOS v1.0 + + Revision 1.4 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct lncInfo *lnc = 0x0; + +static char const * const nicIdent[] = { + "Unknown", + "BICC", + "NE2100", + "DEPCA", + "CNET98S", /* PC-98 */ + }; + +static char const * const icIdent[] = { + "Unknown", + "LANCE", + "C-LANCE", + "PCnet-ISA", + "PCnet-ISA+", + "PCnet-ISA II", + "PCnet-32 VL-Bus", + "PCnet-PCI", + "PCnet-PCI II", + "PCnet-FAST", + "PCnet-FAST+", + "PCnet-Home", + }; + +void writeCsr(struct lncInfo *lnc, uInt16 port, uInt16 val) { + outportWord(lnc->rap, port); + outportWord(lnc->rdp, val); + } + +uInt16 readCsr(struct lncInfo *lnc, uInt16 port) { + outportWord(lnc->rap, port); + return(inportWord(lnc->rdp)); + } + +void writeBcr(struct lncInfo *lnc, uInt16 port, uInt16 val) { + outportWord(lnc->rap, port); + outportWord(lnc->bdp, val); + } + +uInt16 readBcr(struct lncInfo *sc, uInt16 port) { + outportWord(sc->rap, port); + return (inportWord(sc->bdp)); + } + + +void initLNC() { + int i = 0x0; + lnc = kmalloc(sizeof(struct lncInfo),-2); + + lnc->rap = 0x1000 + PCNET_RAP; + lnc->rdp = 0x1000 + PCNET_RDP; + lnc->bdp = 0x1000 + PCNET_BDP; + + lnc->nic.ic = probe(lnc); + if ((lnc->nic.ic > 0) && (lnc->nic.ic >= PCnet_32)) { + lnc->nic.ident = NE2100; + lnc->nic.memMode = DMA_FIXED; + + lnc->nrdre = NRDRE; + lnc->ntdre = NTDRE; + + /* Extract MAC address from PROM */ + for (i = 0; i < ETHER_ADDR_LEN; i++) { + lnc->arpcom.ac_enaddr[i] = inportByte(0x1000 + i); + kprintf("[0x%X]",lnc->arpcom.ac_enaddr[i]); + } + } + else { + kprintf("LNC Init Error\n"); + return; + } + lncAttach(lnc,0); + writeCsr(lnc, CSR3, 0); + writeCsr(lnc, CSR0, INIT); + for (i = 0; i < 1000; i++) + if (readCsr(lnc, CSR0) & IDON) + break; + + if (readCsr(lnc, CSR0) & IDON) { + writeCsr(lnc, CSR0, STRT | INEA); + setVector(_lncInt,mVec+9, (dInt + dPresent + dDpl3)); + enableIrq(9); + /* + * sc->arpcom.ac_if.if_flags |= IFF_RUNNING; + * sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; + * lnc_start(&sc->arpcom.ac_if); + */ + } + else { + kprintf("LNC init Error\n"); + return; + } + return; + } + +int probe(struct lncInfo *lnc) { + uInt32 chipId = 0x0; + int type = 0x0; + + if ((type = lanceProbe(lnc))) { + chipId = readCsr(lnc, CSR89); + chipId <<= 16; + chipId |= readCsr(lnc, CSR88); + if (chipId & AMD_MASK) { + chipId >>= 12; + switch (chipId & PART_MASK) { + case Am79C960: + return(PCnet_ISA); + case Am79C961: + return (PCnet_ISAplus); + case Am79C961A: + return (PCnet_ISA_II); + case Am79C965: + return (PCnet_32); + case Am79C970: + return (PCnet_PCI); + case Am79C970A: + return (PCnet_PCI_II); + case Am79C971: + return (PCnet_FAST); + case Am79C972: + case Am79C973: + return (PCnet_FASTplus); + case Am79C978: + return (PCnet_Home); + default: + break; + } + } + } + return (type); + } + +int lanceProbe(struct lncInfo *lnc) { + writeCsr(lnc, CSR0, STOP); + if ((inportWord(lnc->rdp) & STOP) && !(readCsr(lnc, CSR3))) { + writeCsr(lnc, CSR0, INEA); + if (readCsr(lnc, CSR0) & INEA) { + return(C_LANCE); + } + else { + return(LANCE); + } + } + else { + return(UNKNOWN); + } + } + +void lncInt() { + uInt16 csr0 = 0x0; + while ((csr0 = inportWord(lnc->rdp)) & INTR) { + outportWord(lnc->rdp, csr0); + kprintf("CSR0: [0x%X]\n",csr0); + if (csr0 & ERR) { + kprintf("Error: [0x%X]\n",csr0); + } + if (csr0 & RINT) { + kprintf("RINT\n"); + } + if (csr0 & TINT) { + kprintf("TINT\n"); + } + } + kprintf("Finished!!!\n"); + outportByte(0x20,0x20); + return; + } + +asm( + ".global _lncInt \n" + "_lncInt : \n" + + " pusha \n" /* Save all registers */ + " pushw %ds \n" /* Set up the data segment */ + " pushw %es \n" + " pushw %ss \n" /* Note that ss is always valid */ + " pushw %ss \n" + " popw %ds \n" + " popw %es \n" + " call lncInt \n" + " popw %es \n" + " popw %ds \n" /* Restore registers */ + " popa \n" + " iret \n" /* Exit interrupt */ + ); + +int lncAttach(struct lncInfo *lnc,int unit) { + int lncMemSize = 0x0; + + lncMemSize = ((NDESC(lnc->nrdre) + NDESC(lnc->ntdre)) * sizeof(struct hostRingEntry)); + + if (lnc->nic.memMode != SHMEM) + lncMemSize += sizeof(struct initBlock) + (sizeof(struct mds) * (NDESC(lnc->nrdre) + NDESC(lnc->ntdre))) + MEM_SLEW; + + if (lnc->nic.memMode == DMA_FIXED) + lncMemSize += (NDESC(lnc->nrdre) * RECVBUFSIZE) + (NDESC(lnc->ntdre) * TRANSBUFSIZE); + + if (lnc->nic.memMode != SHMEM) { + if (lnc->nic.ic < PCnet_32) { + /* ISA based cards */ + kprintf("ISA Board\n"); + /* sc->recv_ring = contigmalloc(lnc_mem_size, M_DEVBUF, M_NOWAIT,0ul, 0xfffffful, 4ul, 0x1000000); */ + } + else { + /* + * For now it still needs to be below 16MB because the + * descriptor's can only hold 16 bit addresses. + */ + /* sc->recv_ring = contigmalloc(lnc_mem_size, M_DEVBUF, M_NOWAIT,0ul, 0xfffffful, 4ul, 0x1000000); */ + lnc->recvRing = kmalloc(lncMemSize,-2); + kprintf("PCI Board\n"); + } + } + + if (!lnc->recvRing) { + kprintf("lnc%d: Couldn't allocate memory for NIC\n", unit); + return (0); + } + + lnc->nic.mode = NORMAL; + + /* Fill in arpcom structure entries */ + /* + lnc->arpcom.ac_if.if_softc = sc; + lnc->arpcom.ac_if.if_name = lncdriver.name; + lnc->arpcom.ac_if.if_unit = unit; + lnc->arpcom.ac_if.if_mtu = ETHERMTU; + lnc->arpcom.ac_if.if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + lnc->arpcom.ac_if.if_timer = 0; + lnc->arpcom.ac_if.if_output = ether_output; + lnc->arpcom.ac_if.if_start = lnc_start; + lnc->arpcom.ac_if.if_ioctl = lnc_ioctl; + lnc->arpcom.ac_if.if_watchdog = lnc_watchdog; + lnc->arpcom.ac_if.if_init = lnc_init; + lnc->arpcom.ac_if.if_type = IFT_ETHER; + lnc->arpcom.ac_if.if_addrlen = ETHER_ADDR_LEN; + lnc->arpcom.ac_if.if_hdrlen = ETHER_HDR_LEN; + lnc->arpcom.ac_if.if_snd.ifq_maxlen = IFQ_MAXLEN; + */ + /* ether_ifattach(&sc->arpcom.ac_if, ETHER_BPF_SUPPORTED); */ + + kprintf("lnc%d: ", unit); + if (lnc->nic.ic == LANCE || lnc->nic.ic == C_LANCE) + kprintf("%s (%s)",nicIdent[lnc->nic.ident], icIdent[lnc->nic.ic]); + else + kprintf("%s", icIdent[lnc->nic.ic]); + kprintf(" address 0x%X\n", lnc->arpcom.ac_enaddr); + return(1); + } + +/*** + END + ***/ + diff --git a/src/sys/pci/pci.c b/src/sys/pci/pci.c new file mode 100644 index 0000000..a7bff33 --- /dev/null +++ b/src/sys/pci/pci.c @@ -0,0 +1,326 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1.1.1 2004/04/15 12:07:16 reddawg + UbixOS v1.0 + + Revision 1.5 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +const struct { + uInt8 baseClass; + uInt8 subClass; + uInt8 interface; + const char* name; + } pciClasses[] = { + { 0x00, 0x00, 0x00, "Undefined" }, + { 0x00, 0x01, 0x00, "VGA" }, + + { 0x01, 0x00, 0x00, "SCSI" }, + { 0x01, 0x01, 0x00, "IDE" }, + { 0x01, 0x01, 0x8A, "IDE" }, + { 0x01, 0x02, 0x00, "Floppy" }, + { 0x01, 0x03, 0x00, "IPI" }, + { 0x01, 0x04, 0x00, "RAID" }, + { 0x01, 0x80, 0x00, "Other" }, + + { 0x02, 0x00, 0x00, "Ethernet" }, + { 0x02, 0x01, 0x00, "Token Ring" }, + { 0x02, 0x02, 0x00, "FDDI" }, + { 0x02, 0x03, 0x00, "ATM" }, + { 0x02, 0x04, 0x00, "ISDN" }, + { 0x02, 0x80, 0x00, "Other" }, + + { 0x03, 0x00, 0x00, "VGA" }, + { 0x03, 0x00, 0x01, "VGA+8514" }, + { 0x03, 0x01, 0x00, "XGA" }, + { 0x03, 0x02, 0x00, "3D" }, + { 0x03, 0x80, 0x00, "VGA Other" }, + + { 0x04, 0x00, 0x00, "Video" }, + { 0x04, 0x01, 0x00, "Audio" }, + { 0x04, 0x02, 0x00, "Telephony" }, + { 0x04, 0x80, 0x00, "Other" }, + + { 0x05, 0x00, 0x00, "RAM" }, + { 0x05, 0x01, 0x00, "Flash" }, + { 0x05, 0x80, 0x00, "Other" }, + + { 0x06, 0x00, 0x00, "PCI to HOST" }, + { 0x06, 0x01, 0x00, "PCI to ISA" }, + { 0x06, 0x02, 0x00, "PCI to EISA" }, + { 0x06, 0x03, 0x00, "PCI to MCA" }, + { 0x06, 0x04, 0x00, "PCI to PCI" }, + { 0x06, 0x04, 0x01, "PCI to PCI (Subtractive Decode)" }, + { 0x06, 0x05, 0x00, "PCI to PCMCIA" }, + { 0x06, 0x06, 0x00, "PCI to NuBUS" }, + { 0x06, 0x07, 0x00, "PCI to Cardbus" }, + { 0x06, 0x08, 0x00, "PCI to RACEway" }, + { 0x06, 0x09, 0x00, "PCI to PCI" }, + { 0x06, 0x0A, 0x00, "PCI to InfiBand" }, + { 0x06, 0x80, 0x00, "PCI to Other" }, + + { 0x07, 0x00, 0x00, "Serial" }, + { 0x07, 0x00, 0x01, "Serial - 16450" }, + { 0x07, 0x00, 0x02, "Serial - 16550" }, + { 0x07, 0x00, 0x03, "Serial - 16650" }, + { 0x07, 0x00, 0x04, "Serial - 16750" }, + { 0x07, 0x00, 0x05, "Serial - 16850" }, + { 0x07, 0x00, 0x06, "Serial - 16950" }, + { 0x07, 0x01, 0x00, "Parallel" }, + { 0x07, 0x01, 0x01, "Parallel - BiDir" }, + { 0x07, 0x01, 0x02, "Parallel - ECP" }, + { 0x07, 0x01, 0x03, "Parallel - IEEE1284" }, + { 0x07, 0x01, 0xFE, "Parallel - IEEE1284 Target" }, + { 0x07, 0x02, 0x00, "Multiport Serial" }, + { 0x07, 0x03, 0x00, "Hayes Compatible Modem" }, + { 0x07, 0x03, 0x01, "Hayes Compatible Modem, 16450" }, + { 0x07, 0x03, 0x02, "Hayes Compatible Modem, 16550" }, + { 0x07, 0x03, 0x03, "Hayes Compatible Modem, 16650" }, + { 0x07, 0x03, 0x04, "Hayes Compatible Modem, 16750" }, + { 0x07, 0x80, 0x00, "Other" }, + + { 0x08, 0x00, 0x00, "PIC" }, + { 0x08, 0x00, 0x01, "ISA PIC" }, + { 0x08, 0x00, 0x02, "EISA PIC" }, + { 0x08, 0x00, 0x10, "I/O APIC" }, + { 0x08, 0x00, 0x20, "I/O(x) APIC" }, + { 0x08, 0x01, 0x00, "DMA" }, + { 0x08, 0x01, 0x01, "ISA DMA" }, + { 0x08, 0x01, 0x02, "EISA DMA" }, + { 0x08, 0x02, 0x00, "Timer" }, + { 0x08, 0x02, 0x01, "ISA Timer" }, + { 0x08, 0x02, 0x02, "EISA Timer" }, + { 0x08, 0x03, 0x00, "RTC" }, + { 0x08, 0x03, 0x00, "ISA RTC" }, + { 0x08, 0x03, 0x00, "Hot-Plug" }, + { 0x08, 0x80, 0x00, "Other" }, + + { 0x09, 0x00, 0x00, "Keyboard" }, + { 0x09, 0x01, 0x00, "Pen" }, + { 0x09, 0x02, 0x00, "Mouse" }, + { 0x09, 0x03, 0x00, "Scanner" }, + { 0x09, 0x04, 0x00, "Game Port" }, + { 0x09, 0x80, 0x00, "Other" }, + + { 0x0a, 0x00, 0x00, "Generic" }, + { 0x0a, 0x80, 0x00, "Other" }, + + { 0x0b, 0x00, 0x00, "386" }, + { 0x0b, 0x01, 0x00, "486" }, + { 0x0b, 0x02, 0x00, "Pentium" }, + { 0x0b, 0x03, 0x00, "PentiumPro" }, + { 0x0b, 0x10, 0x00, "DEC Alpha" }, + { 0x0b, 0x20, 0x00, "PowerPC" }, + { 0x0b, 0x30, 0x00, "MIPS" }, + { 0x0b, 0x40, 0x00, "Coprocessor" }, + { 0x0b, 0x80, 0x00, "Other" }, + + { 0x0c, 0x00, 0x00, "FireWire" }, + { 0x0c, 0x00, 0x10, "OHCI FireWire" }, + { 0x0c, 0x01, 0x00, "Access.bus" }, + { 0x0c, 0x02, 0x00, "SSA" }, + { 0x0c, 0x03, 0x00, "USB (UHCI)" }, + { 0x0c, 0x03, 0x10, "USB (OHCI)" }, + { 0x0c, 0x03, 0x80, "USB" }, + { 0x0c, 0x03, 0xFE, "USB Device" }, + { 0x0c, 0x04, 0x00, "Fiber" }, + { 0x0c, 0x05, 0x00, "SMBus Controller" }, + { 0x0c, 0x06, 0x00, "InfiniBand" }, + { 0x0c, 0x80, 0x00, "Other" }, + + { 0x0d, 0x00, 0x00, "iRDA" }, + { 0x0d, 0x01, 0x00, "Consumer IR" }, + { 0x0d, 0x10, 0x00, "RF" }, + { 0x0d, 0x80, 0x00, "Other" }, + + { 0x0e, 0x00, 0x00, "I2O" }, + { 0x0e, 0x80, 0x00, "Other" }, + + { 0x0f, 0x01, 0x00, "TV" }, + { 0x0f, 0x02, 0x00, "Audio" }, + { 0x0f, 0x03, 0x00, "Voice" }, + { 0x0f, 0x04, 0x00, "Data" }, + { 0x0f, 0x80, 0x00, "Other" }, + + { 0x10, 0x00, 0x00, "Network" }, + { 0x10, 0x10, 0x00, "Entertainment" }, + { 0x10, 0x80, 0x00, "Other" }, + + { 0x11, 0x00, 0x00, "DPIO Modules" }, + { 0x11, 0x01, 0x00, "Performance Counters" }, + { 0x11, 0x10, 0x00, "Comm Sync, Time+Frequency Measurement" }, + { 0x11, 0x80, 0x00, "Other" }, + + }; + +uInt32 pciRead(int bus,int dev,int func,int reg,int bytes) { + uInt16 base; + + union { + struct confadd c; + uInt32 n; + } u; + + u.n = 0; + u.c.enable = 1; + u.c.rsvd = 0; + u.c.bus = bus; + u.c.dev = dev; + u.c.func = func; + u.c.reg = reg & 0xFC; + + outportDWord(0xCF8, u.n); + + base = 0xCFC + (reg & 0x03); + + switch(bytes){ + case 1: return(inportByte(base)); + case 2: return(inportWord(base)); + case 4: return(inportDWord(base)); + default: return 0; + } + } + +void pciWrite(int bus,int dev,int func,int reg,uInt32 v,int bytes) { + uInt16 base; + + union { + struct confadd c; + uInt32 n; + } u; + + u.n = 0; + u.c.enable = 1; + u.c.rsvd = 0; + u.c.bus = bus; + u.c.dev = dev; + u.c.func = func; + u.c.reg = reg & 0xFC; + + base = 0xCFC + (reg & 0x03); + outportDWord(0xCF8, u.n); + switch(bytes){ + case 1: outportByte(base, (uInt8) v); break; + case 2: outportWord(base, (uInt16) v); break; + case 4: outportDWord(base, v); break; + } + } + + +bool pciProbe(int bus, int dev, int func,struct pciConfig *cfg) { + uInt32 *word = (uInt32 *) cfg; + uInt32 v; + int i; + for(i=0;i<4;i++) { + word[i] = pciRead(bus,dev,func,4*i,4); + } + if(cfg->vendorId == 0xffff) return FALSE; + if(cfg->vendorId == 0x0) return FALSE; /* Quick Hack */ + + cfg->bus = bus; + cfg->dev = dev; + cfg->func = func; + cfg->subsysVendor = pciRead(bus, dev, func, 0x2c, 2); + cfg->subsys = pciRead(bus, dev, func, 0x2e, 2); + kprintf("Device Info: /bus/pci/%d/%d/%d\n",bus,dev,func); + kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n",cfg->vendorId,cfg->deviceId,cfg->baseClass,cfg->subClass,cfg->interface); + kprintf(" * Status: %X Command: %X BIST/Type/Lat/CLS: %X/%X/%X/%X\n",cfg->status, cfg->command, cfg->bist, cfg->headerType,cfg->latencyTimer, cfg->cacheLineSize); + switch(cfg->headerType & 0x7F){ + case 0: /* normal device */ + for(i=0;i<6;i++) { + v = pciRead(bus,dev,func,i*4 + 0x10, 4); + if(v) { + int v2; + pciWrite(bus,dev,func,i*4 + 0x10, 0xffffffff, 4); + v2 = pciRead(bus,dev,func,i*4+0x10, 4) & 0xfffffff0; + pciWrite(bus,dev,func,i*4 + 0x10, v, 4); + v2 = 1 + ~v2; + if(v & 1) { + cfg->base[i] = v & 0xffff; + cfg->size[i] = v2 & 0xffff; + } + else { + cfg->base[i] = v; + cfg->size[i] = v2; + } + } + else { + cfg->base[i] = 0; + cfg->size[i] = 0; + } + } + v = pciRead(bus,dev,func,0x3c,1); + cfg->irq = (v == 0xff ? 0 : v); + break; + case 1: + kprintf(" * PCI <-> PCI Bridge\n"); + break; + default: + kprintf(" * Unknown Header Type\n"); + break; + } + + return(TRUE); + } + +int pciInit() { + uInt16 bus,dev,func; + int i = 0x0; + struct pciConfig pcfg; + for (bus = 0; bus < 255; bus++) { + for (dev = 0; dev < 32; dev++) { + for (func = 0; func < 8; func++) { + if (pciProbe(bus, dev, func, &pcfg) == TRUE) { + /* kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n",pcfg.vendorId,pcfg.deviceId,pcfg.baseClass,pcfg.subClass,pcfg.interface); */ + for (i=0x0;i +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + } + +extern "C" { +void sdeTestThread() { +// uInt32 count, i = 0x0; + uInt8 r, g, b; + ogSurface *screen = 0x0; + ogPoint2d points[4]; + ogRGBA8 colours[4]; + r = g = b = 0; + while (screen == 0x0) { + screen = (ogDisplay_UbixOS *)systemVitals->screen; + } + while (!screen->ogAvail()); + + points[0].x = screen->ogGetMaxX() - 150; + points[0].y = 0; + points[1].x = screen->ogGetMaxX(); + points[1].y = 0; + points[2].x = screen->ogGetMaxX(); + points[2].y = 150; + points[3].x = screen->ogGetMaxX() - 250; + points[3].y = 250; + + colours[0].red = 255; + colours[0].green = 0; + colours[0].blue = 0; + colours[0].alpha = 255; + colours[1].red = 0; + colours[1].green = 255; + colours[1].blue = 128; + colours[1].alpha = 255; + colours[2].red = 128; + colours[2].green = 255; + colours[2].blue = 128; + colours[2].alpha = 255; + colours[3].red = 63; + colours[3].green = 63; + colours[3].blue = 63; + colours[3].alpha = 255; + screen->ogSetAntiAliasing(true); + + while (true) { +#if 0 + for (count = 150; count > 0; count--) { + screen->Line(screen->GetMaxX() / 2, screen->GetMaxY() / 2, + screen->GetMaxX(), count*8, + screen->RGB(r, g, b)); + screen->FillCircle(screen->GetMaxX() - 50, 50, count, + screen->RGB(r, g, b)); + +// screen->FillRect(screen->GetMaxX() - 50 - count, count, +// screen->GetMaxX() - count, 100 - count, +// screen->RGB(r, g, b)); + r -= 8; + g += 8; + b -= 8; + } // for +#endif + screen->ogFillGouraudPolygon(4, points, colours); + //kprintf("colours(0)[0x%X]\n",colours[0]); + colours[0].red -= 8; + colours[0].green += 8; + colours[0].blue -= 8; + colours[1].red += 8; + colours[1].green += 8; + colours[1].blue -= 8; + colours[2].red += 8; + colours[2].green -= 8; + colours[2].blue += 8; + colours[3].red += 8; + colours[3].green += 8; + colours[3].blue += 8; + + } // while + +} // sdeTestThread + +} + +/*** + END + ***/ + diff --git a/src/sys/sde/main.cc b/src/sys/sde/main.cc new file mode 100644 index 0000000..c54628f --- /dev/null +++ b/src/sys/sde/main.cc @@ -0,0 +1,136 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/05/19 17:09:50 flameshadow + chg: Undid previous renaming. This now restores me as the EOOUIAD. + + Revision 1.1.1.1 2004/04/15 12:07:16 reddawg + UbixOS v1.0 + + Revision 1.29 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +extern "C" { + #include + #include + #include + #include + #include + } + +#include +#include +#include +#include + +extern "C" void sdeThread() { + ogSurface *screen = new ogDisplay_UbixOS(); + struct sdeWindows *tmp = 0x0; + ogSurface *buf = 0x0; + ogBitFont * font = new ogBitFont(); + + + font->Load("ROM8X14.DPF",0); + font->SetFGColor(255, 255, 255, 255); + font->SetBGColor(0, 0, 0, 255); + + printOff = 0x1; + + screen->ogCreate(800,600,OG_PIXFMT_16BPP); + screen->ogClear(screen->ogPack(122,140,163)); + + systemVitals->screen = screen; + systemVitals->font = font; + + ogprintOff = (int)0x0; + + screen->ogSetAntiAliasing(false); + + while (1) { + for (tmp = windows;tmp;tmp=tmp->next) { + switch (tmp->status) { + case registerWindow: + buf = (ogSurface *)tmp->buf; + buf->buffer = (void *)vmmMapFromTask(tmp->pid,buf->buffer,buf->bSize); + if (buf->buffer == 0x0) { + kprintf("Error: buf->buffer\n"); + while (1); + } + buf->lineOfs = (uInt32 *)vmmMapFromTask(tmp->pid,buf->lineOfs,buf->lSize); + if (buf->lineOfs == 0x0) { + kprintf("Error: buf->lineOfs\n"); + while (1); + } + tmp->status = windowReady; + //kprintf("Window Registered!\n"); + break; + case drawWindow: + buf = (ogSurface *)tmp->buf; + screen->ogCopyBuf(screen->ogGetMaxX() - buf->ogGetMaxX(), + screen->ogGetMaxY() - buf->ogGetMaxY(), *buf,0, 0, + buf->ogGetMaxX(), buf->ogGetMaxY()); + tmp->status = windowReady; + //kprintf("Draw Window Routines Here\n"); + break; + case killWindow: + //kprintf("Killed Window\n"); + if (tmp->next != 0x0) { + tmp->next->prev = tmp->prev; + if (tmp->prev != 0x0) + tmp->prev->next = tmp->next; + } + else if (tmp->prev != 0x0) { + tmp->prev->next = tmp->next; + if (tmp->next != 0x0) + tmp->next->prev = tmp->prev; + } + else { + windows = 0x0; + } + vmmUnmapPages(buf->buffer,buf->bSize); + vmmUnmapPages(buf->lineOfs,buf->lSize); + // kfree(tmp->buf); + kfree(tmp); + tmp = 0x0; + break; + default: + break; + } + } + //sched_yield(); + } + } + +/*** + END + ***/ + diff --git a/src/sys/sde/ogDisplay_UbixOS.cc b/src/sys/sde/ogDisplay_UbixOS.cc new file mode 100755 index 0000000..9c56226 --- /dev/null +++ b/src/sys/sde/ogDisplay_UbixOS.cc @@ -0,0 +1,321 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/05/19 17:09:50 flameshadow + chg: Undid previous renaming. This now restores me as the EOOUIAD. + + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg + UbixOS v1.0 + + Revision 1.20 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +extern "C" { + #include + #include + #include + #include + #include + #include + } + +/* + * + * ogDisplay methods + * + */ + +void +initVESAMode(uInt16 mode) { + //kprintf("Pre-initVESAMode\n"); + biosCall(0x10,0x4F02,mode,0x0,0x0,0x0,0x0,0x0,0x0); + //kprintf("Post-initVESAMode\n"); + return; +} + +ogDisplay_UbixOS::ogDisplay_UbixOS(void) { + pages[0] = pages[1] = NULL; + activePage = visualPage = 0; + pal = new ogRGBA8[256]; + attributes = new ogAttributes(); + + VESAInfo = (ogVESAInfo *)0x11000; + modeInfo = (ogModeInfo *)0x11200; + GetVESAInfo(); + return; +} // ogDisplay_UbixOS::ogDisplay_UbixOS + +void +ogDisplay_UbixOS::GetModeInfo(uInt16 mode) { + //kprintf("Pre-getModeInfo\n"); + biosCall(0x10,0x4F01,0x0,mode,0x0,0x0,0x0,0x1120,0x0); + //kprintf("Post-getModeInfo\n"); + return; +} // ogDisplay_UbixOS::GetModeInfo + +void +ogDisplay_UbixOS::GetVESAInfo(void) { + VESAInfo->VBESignature[0] = 'V'; // First off initialize the structure. + VESAInfo->VBESignature[1] = 'B'; + VESAInfo->VBESignature[2] = 'E'; + VESAInfo->VBESignature[3] = '2'; + //kprintf("Pre-getVESAInfo\n"); + biosCall(0x10,0x4F00,0x0,0x0,0x0,0x0,0x0,0x1100,0x0); + //kprintf("Post-getVESAInfo\n"); + return; + } // ogDisplay_UbixOS::GetVESAInfo + +uInt16 +ogDisplay_UbixOS::FindMode(uInt32 _xRes, uInt32 _yRes, uInt32 _BPP) { + uInt16 mode; + + if ((_xRes == 320) && (_yRes == 200) && (_BPP == 8)) return 0x13; + +// if ((VESAInfo==NULL) || (VESAInfo->videoModePtr==NULL)) return 0; + if (modeInfo == NULL) return 0; + + for (mode = 0x100; mode < 0x1FF; mode++) { + GetModeInfo(mode); + if ((modeInfo->xRes >= _xRes) && (modeInfo->yRes >= _yRes) && + (modeInfo->bitsPerPixel == _BPP)) + return mode; + } + + return 0; +} // ogDisplay_UbixOS::FindMode + +void ogDisplay_UbixOS::SetMode(uInt16 mode) { + + uInt32 size = 0x0, count = 0x0, i = 0x0; + + if (mode == 0x13) { + + xRes = 320; + yRes = 200; + maxX = 319; + maxY = 199; + BPP = 8; + bytesPerPix = 1; + + redFieldPosition = 0; + greenFieldPosition = 0; + blueFieldPosition = 0; + alphaFieldPosition = 0; + + redShifter = 0; + greenShifter = 0; + blueShifter = 0; + alphaFieldPosition = 0; + + // UBU, THIS IS NULL BECAUSE WE DON'T EVER USE 320x200x256c! + // THIS COMMENT WILL COME BACK TO BITE YOU ON THE ASS + buffer = NULL; + + } else { + buffer = NULL; + mode |= 0x4000; // attempt lfb + GetModeInfo(mode); + if (modeInfo->physBasePtr == 0) return; + buffer = (void *)modeInfo->physBasePtr; + size = (modeInfo->yRes*modeInfo->bytesPerLine+4095); + + xRes = modeInfo->bytesPerLine; + yRes = modeInfo->yRes; + maxX = modeInfo->xRes-1; + maxY = yRes-1; + + BPP = modeInfo->bitsPerPixel; + bytesPerPix = (BPP + 7) >> 3; + + redFieldPosition = modeInfo->redFieldPosition; + greenFieldPosition = modeInfo->greenFieldPosition; + blueFieldPosition = modeInfo->blueFieldPosition; + alphaFieldPosition = modeInfo->alphaFieldPosition; + + if (bytesPerPix == 4) { + modeInfo->alphaMaskSize = 8; + while ((alphaFieldPosition == redFieldPosition) || + (alphaFieldPosition == greenFieldPosition) || + (alphaFieldPosition == blueFieldPosition)) + alphaFieldPosition += 8; + } // if + + redShifter = 8-modeInfo->redMaskSize; + greenShifter = 8-modeInfo->greenMaskSize; + blueShifter = 8-modeInfo->blueMaskSize; + alphaShifter = 8-modeInfo->alphaMaskSize; + + if (modeInfo->alphaMaskSize != 0) + alphaMasker = ~(OG_MASKS[modeInfo->alphaMaskSize] << alphaFieldPosition); + else + alphaMasker = ~0; + + } // else not mode 0x13 + + printOff = 0; + for (i = 0x0; i < ((size)/4096); i++) { + vmmRemapPage(modeInfo->physBasePtr + (i * 0x1000), + modeInfo->physBasePtr + (i * 0x1000)); + } // for i + + owner = this; + dataState = ogAliasing; + + initVESAMode(mode); + + if ((lineOfs != NULL) && (lSize != 0)) delete [] lineOfs; + lSize = yRes*sizeof(uInt32); + lineOfs = new uInt32[yRes];; + if (lineOfs == NULL) return; + + lineOfs[0] = 0; + for (count = 1; count < yRes; count++) + lineOfs[count] = lineOfs[count-1]+xRes; + + if (1 == bytesPerPix) { + pixFmtID = 0x08080808; + } else { + pixFmtID = (redFieldPosition) | + (greenFieldPosition << 8) | + (blueFieldPosition << 16) | + (alphaFieldPosition << 24); + } // else + + ogSetAntiAliasing(BPP > 8); + if (pal == NULL) pal = new ogRGBA8[256]; + ogSetPalette(DEFAULT_PALETTE); + + return; +} // ogDisplay_UbixOS::SetMode + +void +ogDisplay_UbixOS::ogSetPalette(const ogRGBA8 newPal[256]) { + ogSurface::ogSetPalette(newPal); + SetPal(); + return; +} // ogDisplay_UbixOS::ogSetPalette + +void ogDisplay_UbixOS::SetPal(void) { + if (bytesPerPix != 1) return; + outportByte(0x3c8,0); + for (uInt32 c = 0; c < 256; c++) { + outportByte(0x3c9, pal[c].red >> 2); + outportByte(0x3c9, pal[c].green >> 2); + outportByte(0x3c9, pal[c].blue >> 2); + } // for + return; +} // ogDisplay_UbixOS::SetPal + +bool +ogDisplay_UbixOS::ogAlias(ogSurface& SrcObject, uInt32 x1, + uInt32 y1, uInt32 x2, uInt32 y2) { + ogSetLastError(ogNoAliasing); + return false; +} // ogDisplay_UbixOS::ogAlias + +bool +ogDisplay_UbixOS::ogCreate(uInt32 _xRes, uInt32 _yRes,ogPixelFmt _pixFormat) { + uInt16 mode; + mode = 0x114; // was 0x111 + SetMode(mode); + /* + mode = FindMode(_xRes, _yRes, _pixFormat.BPP); + if ((mode == 0) && ((_pixFormat.BPP==24) || (_pixFormat.BPP==32))) { + if (_pixFormat.BPP==24) _pixFormat.BPP=32; else _pixFormat.BPP=24; + mode=FindMode(_xRes,_yRes,_pixFormat.BPP); + } // if + if (mode!=0) SetMode(mode); + */ + return (mode!=0); +} // ogDisplay_UbixOS::ogCreate + +bool +ogDisplay_UbixOS::ogClone(ogSurface& SrcObject) { + ogSetLastError(ogNoCloning); + return false; +} // ogDisplay_UbixOS::ogClone + +void +ogDisplay_UbixOS::ogCopyPalette(ogSurface& SrcObject) { + ogSurface::ogCopyPalette(SrcObject); + SetPal(); + return; +} // ogDisplay_UbixOS::ogCopyPalette + +bool +ogDisplay_UbixOS::ogLoadPalette(const char *palfile) { + bool result; + if ((result = ogSurface::ogLoadPalette(palfile))==true) SetPal(); + return result; +} // ogDisplay_UbixOS::ogLoadPalette + +void +ogDisplay_UbixOS::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, uInt8 blue) { + if (pal == NULL) return; + ogSurface::ogSetPalette(colour, red, green, blue); + outportByte(0x3c8, colour); + outportByte(0x3c9, red >> 2); + outportByte(0x3c9, green >> 2); + outportByte(0x3c9, blue >> 2); + + return; +} // ogDisplay_UbixOS::ogSetPalette + +void +ogDisplay_UbixOS::ogSetPalette(uInt8 colour, uInt8 red, uInt8 green, + uInt8 blue, uInt8 alpha) { + if (pal == NULL) return; + ogSurface::ogSetPalette(colour, red, green, blue, alpha); + outportByte(0x3c8, colour); + outportByte(0x3c9, red >> 2); + outportByte(0x3c9, green >> 2); + outportByte(0x3c9, blue >> 2); + + return; +} // ogDisplay_UbixOS::ogSetPalette + +ogDisplay_UbixOS::~ogDisplay_UbixOS(void) { + delete attributes; + delete pal; +//mji delete VESAInfo; +//mji delete modeInfo; + return; +} // ogDisplay_UbixOS::~ogDisplay_UbixOS + +/*** + END + ***/ + diff --git a/src/sys/sde/sde.cc b/src/sys/sde/sde.cc new file mode 100644 index 0000000..d939e97 --- /dev/null +++ b/src/sys/sde/sde.cc @@ -0,0 +1,144 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg + UbixOS v1.0 + + Revision 1.12 2004/04/13 16:36:33 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + #include +} +#include + +struct sdeWindows *windows = 0x0; + +extern "C" void sysSDE(uInt32 cmd,void *ptr) { + ogSurface *newBuf = 0x0; + ogSurface *oldBuf = (ogSurface *)ptr; + struct sdeWindows *tmp = 0x0; + + for (tmp=windows;tmp;tmp=tmp->next) { + if (tmp->pid == (int)_current->id) + break; + } + + if (tmp != 0x0) { + while (tmp->status != windowReady) + asm("hlt"); + //sched_yield(); + } + else if (tmp == 0x0 && cmd != registerWindow) { + kprintf("Invalid Window\n"); + return; + } + + switch (cmd) { + case drawWindow: + tmp->status = drawWindow; + while (tmp->status != windowReady) { + sched(); + //asm("hlt"); + } + break; + case killWindow: + tmp->status = killWindow; + break; + case registerWindow: + if (oldBuf->buffer != 0x0) { + newBuf = new ogSurface(); + newBuf->version = oldBuf->version; + newBuf->buffer = oldBuf->buffer; + newBuf->owner = oldBuf->owner; + newBuf->lineOfs = oldBuf->lineOfs; + newBuf->pal = oldBuf->pal; + newBuf->attributes = oldBuf->attributes; + newBuf->xRes = oldBuf->xRes; + newBuf->yRes = oldBuf->yRes; + newBuf->maxX = oldBuf->maxX; + newBuf->maxY = oldBuf->maxY; + newBuf->bSize = oldBuf->bSize; + newBuf->lSize = oldBuf->lSize; + newBuf->BPP = oldBuf->BPP; + newBuf->bytesPerPix = oldBuf->bytesPerPix; + newBuf->pixFmtID = oldBuf->pixFmtID; + newBuf->redFieldPosition = oldBuf->redFieldPosition; + newBuf->greenFieldPosition = oldBuf->greenFieldPosition; + newBuf->blueFieldPosition = oldBuf->blueFieldPosition; + newBuf->alphaFieldPosition = oldBuf->alphaFieldPosition; + newBuf->redShifter = oldBuf->redShifter; + newBuf->greenShifter = oldBuf->greenShifter; + newBuf->blueShifter = oldBuf->blueShifter; + newBuf->alphaShifter = oldBuf->alphaShifter; + newBuf->lastError = oldBuf->lastError; + newBuf->dataState = oldBuf->dataState; + tmp = (struct sdeWindows *)kmalloc(sizeof(struct sdeWindows)); + tmp->buf = newBuf; + tmp->status = registerWindow; + tmp->pid = _current->id; + tmp->prev = 0x0; + if (windows == 0x0) { + windows = tmp; + tmp->next = 0x0; + } + else { + tmp->next = windows; + windows->prev = tmp; + windows = tmp; + } + } + else { + kprintf("Invalid Window\n"); + } + break; + default: + kprintf("Invalid SDE Command [0x%X]\n",ptr); + break; + } + return; + } + +/*** + END + ***/ + diff --git a/src/sys/sys/Makefile b/src/sys/sys/Makefile new file mode 100644 index 0000000..065bfdf --- /dev/null +++ b/src/sys/sys/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = dma.o idt.o io.o video.o device.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -Wall -O -I../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -Wall -O -I../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -O -I../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -O -I../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/sys/device.c b/src/sys/sys/device.c new file mode 100644 index 0000000..0106b30 --- /dev/null +++ b/src/sys/sys/device.c @@ -0,0 +1,177 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +/* Linked list of drivers loaded in the system accessable by the subsystem only */ +static struct deviceNode *devices = 0x0; +static spinLock_t deviceSpinLock = SPIN_LOCK_INITIALIZER; + +/***************************************************************************************** + + Function: int deviceAdd(int minor,char type,struct deviceInterface *devInfo); + + Description: This will add a device to the system + + Notes: + + 05/19/2004 - Improving Upon the spec + +*****************************************************************************************/ +int deviceAdd(int minor,char type,struct deviceInterface *devInfo) { + struct deviceNode *tmpDev = 0x0; + + spinLock(&deviceSpinLock); + + tmpDev = (struct deviceNode *)kmalloc(sizeof(struct deviceNode)); + + tmpDev->prev = 0x0; + tmpDev->minor = minor; + tmpDev->type = type; + tmpDev->devInfo = devInfo; + tmpDev->next = devices; + devices = tmpDev; + + spinUnlock(&deviceSpinLock); + + return(tmpDev->devInfo->init(tmpDev)); + } + +/***************************************************************************************** + + Function: struct deviceNode *deviceFind(int major,int minor); + + Description: This will find a device based on major minor + + Notes: + + 05/19/2004 - Improving Upon the spec + +*****************************************************************************************/ +struct deviceNode *deviceFind(int major,int minor) { + struct deviceNode *tmpDev = 0x0; + + spinLock(&deviceSpinLock); + + for (tmpDev = devices;tmpDev;tmpDev=tmpDev->next) { + if ((tmpDev->devInfo->major == major) && (tmpDev->minor == minor)) { + spinUnlock(&deviceSpinLock); + return(tmpDev); + } + } + + spinUnlock(&deviceSpinLock); + return(0x0); + } + + +/******************************************************************************************** + +Function: int deviceRemove(struct *deviceNode); + +Description: This will remove a device based on it's pointer + +*********************************************************************************************/ +int deviceRemove(struct deviceNode *deviceToDelete) +{ +struct deviceNode *current, *previous; + +spinLock(&deviceSpinLock); + +current = devices; +previous=NULL; + while(current != NULL) + { + if(current==deviceToDelete) break; + else + { + previous = current; + current = current->next; + } + } + if(current == NULL) return 1; + else + { + if(current == devices) devices = devices->next; + else previous->next = current->next; + kfree(current); + spinUnlock(&deviceSpinLock); + return 1; + } + + spinUnlock(&deviceSpinLock); +return 0x0; +} + + +/*** + $Log$ + Revision 1.11 2004/06/15 12:14:38 reddawg + Cleaned Up + + Revision 1.10 2004/05/26 11:59:21 reddawg + device: Added spin locks to prevent any possible future reentrant issues + + Revision 1.9 2004/05/22 02:40:04 ionix + + + fixed typo in device.h and initialized previous in device.c :) + + Revision 1.8 2004/05/22 02:34:03 ionix + + + Added proto + + Revision 1.7 2004/05/22 02:28:34 ionix + + Added deviceRemove + + Revision 1.6 2004/05/19 15:31:28 reddawg + Fixed up the rest of the references + + Revision 1.5 2004/05/19 15:06:48 reddawg + Fixing Device Driver System Changed Interface + + Revision 1.4 2004/05/19 14:57:25 reddawg + Changed The Device Interface + + Revision 1.3 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/04/27 12:05:12 reddawg + Updates To Driver Subsystem + + Revision 1.1 2004/04/27 03:49:41 reddawg + Start of new driver system + + END + ***/ + diff --git a/src/sys/sys/dma.c b/src/sys/sys/dma.c new file mode 100644 index 0000000..e8e7fb3 --- /dev/null +++ b/src/sys/sys/dma.c @@ -0,0 +1,88 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/04/30 14:16:04 reddawg + Fixed all the datatypes to be consistant uInt8,uInt16,uInt32,Int8,Int16,Int32 + + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg + UbixOS v1.0 + + Revision 1.2 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +#define lowByte(x) (x & 0x00FF) +#define highByte(x) ((x & 0xFF00) >> 8) + +uInt8 maskReg[8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 }; +uInt8 clearReg[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 }; +uInt8 modeReg[8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 }; +uInt8 addrPort[8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC }; +uInt8 pagePort[8] = { 0x87, 0x83, 0x81, 0x82, 0x8F, 0x8B, 0x89, 0x8A }; +uInt8 countPort[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE }; + +void dmaXfer(uInt8 channel,uInt32 address,uInt length,uInt8 read) { + unsigned char page=0, mode=0; + unsigned int offset = 0; + if (read) { + mode = 0x48 + channel; + } + else { + mode = 0x44 + channel; + } + page = address >> 16; + offset = address & 0xFFFF; + length--; + _dmaXfer(channel, page, offset, length, mode); + } + +void _dmaXfer(uInt8 dmaChannel,uInt8 page,uInt offset,uInt length,uInt8 mode) { + asm("cli"); + outportByte(maskReg[dmaChannel], 0x04 | dmaChannel); + outportByte(clearReg[dmaChannel], 0x00); + outportByte(modeReg[dmaChannel], mode); + outportByte(addrPort[dmaChannel], lowByte(offset)); + outportByte(addrPort[dmaChannel], highByte(offset)); + outportByte(pagePort[dmaChannel], page); + outportByte(countPort[dmaChannel], lowByte(length)); + outportByte(countPort[dmaChannel], highByte(length)); + outportByte(maskReg[dmaChannel], dmaChannel); + asm("sti"); + } + +/*** + END + ***/ + diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c new file mode 100644 index 0000000..3058e67 --- /dev/null +++ b/src/sys/sys/idt.c @@ -0,0 +1,476 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FP_TO_LINEAR(seg, off) ((void*) ((((uInt16) (seg)) << 4) + ((uInt16) (off)))) + +void mathStateRestore(); + +ubixDescriptorTable(ubixIDT, 256) { }; + +struct { + unsigned short limit __attribute__((packed)); + union descriptorTableUnion *idt __attribute__((packed)); + } loadidt = { + (256 * sizeof(union descriptorTableUnion) - 1), ubixIDT + }; + +/************************************************************************ + +Function: int idtInit() +Description: This function is used to enable our IDT subsystem +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int idtInit() { + int i = 0x0; + + struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; + + /* Set up default vector table for all possible 256 interrupts */ + for (i = 0x0; i < 256; i++) { + setVector(intNull, i, dPresent + dInt + dDpl3); + } + + /* Load the IDT into the system */ + asm volatile( + "cli \n" + "lidt (%0) \n" /* Load the IDT */ + "pushfl \n" /* Clear the NT flag */ + "andl $0xffffbfff,(%%esp) \n" + "popfl \n" + "sti \n" + : + : "r" ((char *)&loadidt) + ); + + /* Set up the basic vectors for the reserved ints */ + setVector(_int0, 0, dPresent + dTrap + dDpl3); + setVector(_int1, 1, dPresent + dTrap + dDpl3); + setVector(_int2, 2, dPresent + dTrap + dDpl3); + setVector(_int3, 3, dPresent + dTrap + dDpl3); + setVector(_int4, 4, dPresent + dTrap + dDpl3); + setVector(_int5, 5, dPresent + dTrap + dDpl3); + setVector(_int6, 6, dPresent + dTrap + dDpl3); + setVector(_int7,7,dPresent + dTrap + dDpl3); + setVector(_int9, 9, dPresent + dTrap + dDpl3); + setVector(_int10, 10, dPresent + dTrap + dDpl3); + setVector(_int11, 11, dPresent + dTrap + dDpl3); + setVector(_int12, 12, dPresent + dTrap + dDpl3); + setTaskVector(13, dPresent + dTask + dDpl3, 0x38); + setVector(_vmmPageFault, 14, dPresent + dTrap + dDpl3); + setVector(_sysCall, 128, dPresent + dTrap + dDpl3); + setVector(timerInt, 0x68, (dInt + dPresent + dDpl3)); + + + gpfTSS->back_link = 0x0; + gpfTSS->esp0 = 0x0; + gpfTSS->ss0 = 0x0; + gpfTSS->esp1 = 0x0; + gpfTSS->ss1 = 0x0; + gpfTSS->esp2 = 0x0; + gpfTSS->ss2 = 0x0; + gpfTSS->cr3 = (unsigned int)kernelPageDirectory; + gpfTSS->eip = (unsigned int)&_int13; + gpfTSS->eflags = 0x206; + gpfTSS->esp = 0x1CFFF; + gpfTSS->ebp = 0x1CFFF; + gpfTSS->esi = 0x0; + gpfTSS->edi = 0x0; + gpfTSS->es = 0x10; + gpfTSS->cs = 0x08; + gpfTSS->ss = 0x10; + gpfTSS->ds = 0x10; + gpfTSS->fs = 0x10; + gpfTSS->gs = 0x10; + gpfTSS->ldt = 0x0; + gpfTSS->trace_bitmap = 0x0000; + gpfTSS->io_map = 0x8000; + + + /* Print out information for the IDT */ + kprintf("idt0 - Address: [0x%X]\n", &ubixIDT); + + /* Return so we know all went well */ + return (0x0); + } + + +/* Sets Up IDT Vector */ +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor) { + unsigned short codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = (unsigned short)(((unsigned long)handler) & 0xffff); + ubixIDT[interrupt].gate.selector = codesegment; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = (unsigned short)(((unsigned long)handler) >> 16); +} + +/************************************************************************ + +Function: void setTaskVector(uInt8,uInt16,uInt8); +Description: This Function Sets Up An IDT Task Vector +Notes: + +************************************************************************/ +void +setTaskVector(uInt8 interrupt, uInt16 controlMajor, uInt8 selector) +{ + uInt16 codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = 0x0; + ubixIDT[interrupt].gate.selector = selector; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = 0x0; +} + + +/* Null Intterupt Descriptor */ +void intNull() { + kprintf("Woot Invalid Interrupt[%i]\n",_current->id); + endTask(_current->id); + schedYield(); + } + +void _int0() { + kprintf("int0: Divide-by-Zero\n"); + endTask(_current->id); + schedYield(); + } + +void _int1() { + kprintf("int1: Debug exception\n"); + endTask(_current->id); + schedYield(); + } + +void _int2() { + kprintf("int2: unknown error\n"); + endTask(_current->id); + schedYield(); + } + +void _int3() { + kprintf("int3: Breakpoint\n"); + endTask(_current->id); + schedYield(); + } + +void _int4(){ + kprintf("int4: Overflow\n"); + endTask(_current->id); + schedYield(); + } + +void _int5() { + kprintf("int5: Bounds check\n"); + endTask(_current->id); + schedYield(); + } + +void _int6() { + kprintf("int6: Invalid opcode!\n"); + endTask(_current->id); + schedYield(); + } + +void _int8() { + kprintf("int8: Double Fault!\n"); + endTask(_current->id); + schedYield(); + } + +void _int9() { + kprintf("int9: Coprocessor Segment Overrun!\n"); + endTask(_current->id); + schedYield(); + } + +void _int10() { + kprintf("int10: Invalid TSS!\n"); + endTask(_current->id); + schedYield(); + } + +void _int11() { + kprintf("int11: Segment Not Present!\n"); + endTask(_current->id); + schedYield(); + } + +void _int12() { + kprintf("int12: Stack-Segment Fault!\n"); + endTask(_current->id); + schedYield(); + } + +/* + * void _int13() { kprintf("int13: General Protection Fault!\n"); + * kprintf("Task Id: [%i]\n",_current->id); while(1); } + */ + +void _int13() { + uInt8 *ip = 0x0; + uInt16 *stack = 0x0, *ivt = 0x0; + uInt32 *stack32 = 0x0; + bool isOperand32 = FALSE, isAddress32 = FALSE; + + irqDisable(0x0); + + ip = FP_TO_LINEAR(_current->tss.cs, _current->tss.eip); + ivt = (uInt16 *) 0x0; + stack = (uInt16 *) FP_TO_LINEAR(_current->tss.ss,_current->tss.esp); + stack32 = (uInt32 *) stack; + +gpfStart: + switch (ip[0]) { + case 0xCD: /* INT n */ + switch (ip[1]) { + case 0x69: + kprintf("Exit Bios [0x%X]\n",_current->id); + _current->state = DEAD; + break; + case 0x20: + case 0x21: + kpanic("GPF OP 0x20/0x21\n"); + break; + default: + stack -= 3; + _current->tss.esp = ((_current->tss.esp & 0xffff) - 6) & 0xffff; + stack[0] = (uInt16) (_current->tss.eip + 2); + stack[1] = _current->tss.cs; stack[2] = (uInt16) _current->tss.eflags; + if (_current->oInfo.v86If) + stack[2] |= EFLAG_IF; + else + stack[2] &= ~EFLAG_IF; + _current->tss.cs = ivt[ip[1] * 2 + 1] & 0xFFFF; + _current->tss.eip = ivt[ip[1] * 2] & 0xFFFF; + break; + } + break; + case 0x66: + isOperand32 = TRUE; + ip++; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + goto gpfStart; + break; + case 0x67: + isAddress32 = TRUE; + ip++; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + goto gpfStart; + break; + case 0xF0: + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + kpanic("GPF OP 0xF0\n"); + break; + case 0x9C: + if (isOperand32 == TRUE) { + _current->tss.esp = ((_current->tss.esp & 0xffff) - 4) & 0xffff; + stack32--; + stack32[0] = _current->tss.eflags & 0xDFF; + if (_current->oInfo.v86If == TRUE) + stack32[0] |= EFLAG_IF; + else stack32[0] &= ~EFLAG_IF; + } else { + _current->tss.esp = ((_current->tss.esp & 0xffff) - 2) & 0xffff; + stack--; + + stack[0] = (uInt16) _current->tss.eflags; + if (_current->oInfo.v86If == TRUE) stack[0] |= EFLAG_IF; + else stack[0] &= ~EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + + } + break; + case 0x9D: + if (isOperand32 == TRUE) { + _current->tss.eflags = EFLAG_IF | EFLAG_VM | (stack32[0] & 0xDFF); + _current->oInfo.v86If = (stack32[0] & EFLAG_IF) != 0; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 4) & 0xffff; + } else { + _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[0]; + _current->oInfo.v86If = (stack[0] & EFLAG_IF) != 0; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 2) & 0xffff; + } + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + /* kprintf("popf [0x%X]\n",_current->id); */ + break; + case 0xFA: + _current->oInfo.v86If = FALSE; + _current->tss.eflags &= ~EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->oInfo.timer = 0x1; + break; + case 0xFB: + _current->oInfo.v86If = TRUE; + _current->tss.eflags |= EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->oInfo.timer = 0x0; + /* kprintf("sti [0x%X]\n",_current->id); */ + break; + case 0xCF: + _current->tss.eip = stack[0]; + _current->tss.cs = stack[1]; + _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[2]; + _current->oInfo.v86If = (stack[2] & EFLAG_IF) != 0; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 6) & 0xffff; + /* kprintf("iret [0x%X]\n",_current->id); */ + break; + case 0xEC: /* IN AL,DX */ + _current->tss.eax = (_current->tss.eax & ~0xFF) | inportByte(_current->tss.edx); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xED: /* IN AX,DX */ + _current->tss.eax = (_current->tss.eax & ~0xFFFF) | inportWord(_current->tss.edx); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xEE: /* OUT DX,AL */ + outportByte(_current->tss.edx, _current->tss.eax & 0xFF); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xEF: + outportWord(_current->tss.edx, _current->tss.eax); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + case 0xF4: + _current->tss.eip = (uInt16) (_current->tss.eip + 1); + break; + default: /* something wrong */ + kprintf("NonHandled OpCode [0x%X:0x%X]\n",_current->id,ip[0]); + _current->state = DEAD; + break; + } + irqEnable(0); + while (1); + } + +void _int7(); +__asm__ ( + ".globl _int7 \n" + "_int7: \n" + " pushl %eax \n" + " clts \n" + " movl _current,%eax \n" + " cmpl _usedMath,%eax \n" + " je mathDone \n" + " call mathStateRestore \n" + "mathDone: \n" + " popl %eax \n" + " iret \n" + ); + +void mathStateRestore() { + if (_usedMath != 0x0) { + asm( + "fnsave %0" + : + : "m" (_usedMath->i387) + ); + } + if (_current->usedMath != 0x0) { + asm( + "frstor %0" + : + : "m" (_current->i387) + ); + } + else { + asm("fninit"); + _current->usedMath = 0x1; + } + + _usedMath=_current; + + //Return + } + +/*** + $Log$ + Revision 1.14 2004/06/17 12:11:14 reddawg + timerInt: removed from src/sys/sys/idt.c and moved into a file by itself + in src/sys/kernel/timer.S + + Revision 1.13 2004/06/16 12:27:50 reddawg + Added Comments To Timer Interrupt + + Revision 1.12 2004/06/16 12:04:19 reddawg + systemVitals->quantum = (1000/msPerQuantum) + The timer int now will call scheduler at the rate of the defined quantum + + Revision 1.11 2004/06/15 12:14:38 reddawg + Cleaned Up + + Revision 1.10 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.9 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.8 2004/05/21 16:04:32 reddawg + Typo i hate working in windows then test compiling later + + Revision 1.7 2004/05/21 16:02:49 reddawg + We now end faulted tasks instead of holding them + + Revision 1.6 2004/05/21 16:00:39 reddawg + We now end faulted tasks instead of holding them + + Revision 1.5 2004/05/21 13:33:24 reddawg + Went from 200MS per quantum to 25MS + + Revision 1.4 2004/04/30 13:57:23 reddawg + *** empty log message *** + + Revision 1.3 2004/04/30 13:40:35 reddawg + Just doing spring cleaning for the new members + + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg + UbixOS v1.0 + + Revision 1.29 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/src/sys/sys/io.c b/src/sys/sys/io.c new file mode 100644 index 0000000..4133f3c --- /dev/null +++ b/src/sys/sys/io.c @@ -0,0 +1,159 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +/************************************************************************ + +Function: inline unsigned char inportByte(unsigned int port); +Description: This Funciton Will Input One Byte From A Port +Notes: + +************************************************************************/ +inline unsigned char inportByte(unsigned int port) { + unsigned char retVal; + asm volatile( + "inb %%dx,%%al" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/************************************************************************ + +Function: inline unsigned char inportWord(unsigned int port); +Description: This Funciton Will Input One Word From A Port +Notes: + +************************************************************************/ +inline unsigned short inportWord(unsigned int port) { + unsigned short retVal; + asm volatile( + "inw %%dx,%%ax" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/************************************************************************ + +Function: inline void outportByte(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One Byte To A Port +Notes: + +************************************************************************/ +inline void outportByte(unsigned int port,unsigned char value) { + asm volatile( + "outb %%al,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline void outportByteP(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One Byte To A Port With A Delay +Notes: + +************************************************************************/ +inline void outportByteP(unsigned int port,unsigned char value) { + asm volatile( + "outb %%al,%%dx\n" + "outb %%al,$0x80\n" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline void outportWord(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One Word To A Port +Notes: + +************************************************************************/ +inline void outportWord(unsigned int port,unsigned short value) { + asm volatile( + "outw %%ax,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline void outportDWord(unsigned int port,unsigned char value); +Description: This Funciton Will Outputut One DWord To A Port +Notes: + +************************************************************************/ +inline void outportDWord(unsigned int port,unsigned long value) { + asm volatile( + "outl %%eax,%%dx" + : + : "d" (port), "a" (value) + ); + } + +/************************************************************************ + +Function: inline unsigned char inportDWord(unsigned int port); +Description: This Funciton Will Input One DWord From A Port +Notes: + +************************************************************************/ +inline unsigned long inportDWord(unsigned int port) { + unsigned long retVal; + asm volatile( + "inl %%dx,%%eax" + : "=a" (retVal) + : "d" (port) + ); + return(retVal); + } + +/*** + $Log$ + Revision 1.3 2004/06/15 12:14:38 reddawg + Cleaned Up + + Revision 1.2 2004/05/19 14:32:06 reddawg + Cleaned up some warning from leaving out typedefs + + Revision 1.1.1.1 2004/04/15 12:07:18 reddawg + UbixOS v1.0 + + Revision 1.5 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/src/sys/sys/video.c b/src/sys/sys/video.c new file mode 100644 index 0000000..5b6d5b3 --- /dev/null +++ b/src/sys/sys/video.c @@ -0,0 +1,139 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + +unsigned char *videoBuffer = (char *)0xB8000; +int printColor = defaultColor; +int cv_pos = 0x0; +int printLock = -1; + +void +backSpace() +{ + uInt32 bufferOffset = 0x0; + outportByte(0x3d4, 0x0e); + bufferOffset = inportByte(0x3d5); + bufferOffset <<= 8; /* Shift Address Left 8 Bits */ + outportByte(0x3d4, 0x0f); + bufferOffset += inportByte(0x3d5); + bufferOffset <<= 1; /* Shift Address Left 1 Bits */ + videoBuffer[bufferOffset--] = 0x20; + videoBuffer[bufferOffset--] = printColor; + videoBuffer[bufferOffset] = 0x20; + bufferOffset >>= 1; + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + return; +} /* backSpace() */ + +void +kprint(char *string) +{ + unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; + + videoBuffer = (char *)0xB8000; + + /* We Need To Get The Y Position */ + outportByte(0x3D4, 0x0e); + bufferOffset = inportByte(0x3D5); + bufferOffset <<= 8; /* Shift Address Left 8 Bits */ + /* Then We Need To Add The X Position */ + outportByte(0x3D4, 0x0f); + bufferOffset += inportByte(0x3D5); + bufferOffset <<= 1; /* Shift Address Left 1 Bits */ + + while ((character = *string++)) { + switch (character) { + case '\n': + bufferOffset = (bufferOffset / 160) * 160 + 160; + break; + default: + videoBuffer[bufferOffset++] = character; + videoBuffer[bufferOffset++] = printColor; + break; + } /* switch */ + /* Check To See If We Are Out Of Bounds */ + if (bufferOffset >= 160 * 25) { + for (i = 0; i < 160 * 24; i++) { + videoBuffer[i] = videoBuffer[i + 160]; + } /* for */ + for (i = 0; i < 80; i++) { + videoBuffer[(160 * 24) + (i * 2)] = 0x20; + videoBuffer[(160 * 24) + (i * 2) + 1] = printColor; + } /* for */ + bufferOffset -= 160; + } /* if */ + } /* while */ + bufferOffset >>= 1; /* Set the new cursor position */ + outportByte(0x3D4, 0x0f); + outportByte(0x3D5, ((bufferOffset & 0x0ff) & 0xFF)); + outportByte(0x3D4, 0x0e); + outportByte(0x3D5, ((bufferOffset >> 8) & 0xFF)); + return; +} + +/* Clears The Screen */ +void +clearScreen() +{ + unsigned int i = 0x0; + + videoBuffer = (char *)0xB8000; + for (i = 0x0; i < (80 * 25); i++) { /* Fill the screen with */ + /* background Color */ + videoBuffer[i * 2] = 0x20; + videoBuffer[i * 2 + 1] = defaultColor; + } /* for */ + + outportByte(0x3D4, 0x0f); /* Set the cursor to the */ + outportByte(0x3D5, 0); /* upper-left corner of the */ + outportByte(0x3D4, 0x0e); /* screen */ + outportByte(0x3D5, 0); +} /* clearScreen() */ + +/*** + $Log$ + Revision 1.3 2004/06/15 12:10:31 reddawg + Cleaned Up + + Revision 1.2 2004/04/29 19:49:04 reddawg + Cleaned Out Old Code + + Revision 1.1.1.1 2004/04/15 12:07:18 reddawg + UbixOS v1.0 + + Revision 1.24 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + END + ***/ diff --git a/src/sys/ubixfs/Makefile b/src/sys/ubixfs/Makefile new file mode 100644 index 0000000..335e1fc --- /dev/null +++ b/src/sys/ubixfs/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = ubixfs.o directory.o block.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -Wall -O -I../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -Wall -O -I../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -O -I../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -O -I../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/ubixfs/block.c b/src/sys/ubixfs/block.c new file mode 100644 index 0000000..27c2a17 --- /dev/null +++ b/src/sys/ubixfs/block.c @@ -0,0 +1,108 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.4 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.3 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.2 2004/04/28 02:22:55 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.1.1.1 2004/04/15 12:07:07 reddawg + UbixOS v1.0 + + Revision 1.3 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include + + +void syncBat(struct mountPoints *mp) { + struct ubixFSInfo *fsInfo = mp->fsInfo; + mp->device->devInfo->write(mp->device->devInfo->info,fsInfo->blockAllocationTable,mp->diskLabel->partitions[mp->partition].pOffset,mp->diskLabel->partitions[mp->partition].pBatSize); + } + +int freeBlocks(int block,fileDescriptor *fd) { + int i = block; + + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + while (i != 0x0) { + block = fsInfo->blockAllocationTable[i].nextBlock; + + fsInfo->blockAllocationTable[i].attributes = 0x0; + fsInfo->blockAllocationTable[i].nextBlock = 0x0; + + i = block; + } + syncBat(fd->mp); + return(i); + } + +int getFreeBlocks(int count,fileDescriptor *fd) { + int i = 0x0,x = 0x0; + + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + getBlocks: + for (i=1;i < fsInfo->batEntries;i++) { + if (fsInfo->blockAllocationTable[i].attributes == 0x0) { + for (x = 1; x < count; x++) { + if (fsInfo->blockAllocationTable[i + x].attributes != 0x0) { + goto getBlocks; + } + } + for (x = i; x < i+count;x++) { + fsInfo->blockAllocationTable[x].attributes = 0x1; + if ((x+1) == (i+count)) { + fsInfo->blockAllocationTable[x].nextBlock = -1; + } + else { + fsInfo->blockAllocationTable[x].nextBlock = x+1; + } + } + syncBat(fd->mp); + return(i); + } + } + return(0x0); + } + +/*** + END + ***/ + diff --git a/src/sys/ubixfs/directory.c b/src/sys/ubixfs/directory.c new file mode 100644 index 0000000..612414c --- /dev/null +++ b/src/sys/ubixfs/directory.c @@ -0,0 +1,145 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.6 2004/06/04 13:20:22 reddawg + ubixFSmkDir(): played with it a bit to see if it still worked + + Revision 1.5 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.4 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.3 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.2 2004/04/28 02:22:55 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.1.1.1 2004/04/15 12:07:07 reddawg + UbixOS v1.0 + + Revision 1.6 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +static dirList_t dirList = 0x0; + +dirList_t ubixFSLoadDir(char *data) { + dirList_t tmpDir = 0x0; + + tmpDir = (dirList_t)kmalloc(sizeof(struct directoryList)); + + sprintf(tmpDir->dirName,"%s",data); + + if (0x0 == dirList) { + dirList = tmpDir; + } + else { + tmpDir->next = dirList; + tmpDir->prev = 0x0; + dirList->prev = tmpDir; + dirList = tmpDir; + } + + if (!kstrcmp(":",data)) { + tmpDir->dirCache = (char *)kmalloc(0x4000); + } + + return(tmpDir); + } + +int addDirEntry(struct directoryEntry *dir,fileDescriptor *fd) { + int i = 0x0; + uInt32 entries = 0x0; + struct directoryEntry *tmp = 0x0; + + tmp = (struct directoryEntry *)kmalloc(fd->size); + + readUbixFS(fd,(char *)tmp,fd->offset,fd->size); + entries = fd->size/sizeof(struct directoryEntry); + for (i=0;(tmp[i].attributes != 0x0) && (i < entries);i++); + + if (i == entries) { + tmp = (struct directoryEntry *)kmalloc(0x1000); + i = 0x0; + } + else { + fd->offset = 0x0; + } + kmemcpy(&tmp[i],dir,sizeof(struct directoryEntry)); + + if (writeUbixFS(fd,(char *)tmp,fd->offset,fd->size) == 0x0) { + kprintf("Error Creating Directory\n"); + } + + return(0x0); + } + +int ubixFSmkDir(char *directory,fileDescriptor *fd) { + int block = 0x0; + + struct directoryEntry *dir = 0x0; + struct directoryEntry *entry = 0x0; + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + block = getFreeBlocks(1,fd); + if (block != 0x0) { + dir = (struct directoryEntry *)kmalloc(blockByteSize); + entry = (struct directoryEntry *)kmalloc(sizeof(struct directoryEntry)); + + entry->startCluster = block; + entry->size = blockByteSize; + entry->attributes = 0x8000; + entry->permissions = 0xEAA; + sprintf(entry->fileName,directory); + + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,dir,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[block].realSector,blockSize); + addDirEntry(entry,fd); + kfree(dir); + kfree(entry); + } + + return(0x0); + } + +/*** + END + ***/ diff --git a/src/sys/ubixfs/ubixfs.c b/src/sys/ubixfs/ubixfs.c new file mode 100644 index 0000000..c43c582 --- /dev/null +++ b/src/sys/ubixfs/ubixfs.c @@ -0,0 +1,361 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int sprintf(char *buf,const char *fmt, ...); /* TEMP */ + +int enableUbixFS() { + /* Add UbixFS */ + if (vfsRegisterFS(0,initUbixFS,readUbixFS,writeUbixFS,openFileUbixFS,ubixFSUnlink,ubixFSmkDir,0x0,0x0) != 0x0) { + kpanic("Unable To Enable UbixFS"); + return(0x1); + } + /* Return */ + return(0x0); + } + +void initUbixFS(struct mountPoints *mp) { + struct ubixFSInfo *fsInfo = 0x0; + mp->fsInfo = (struct ubixFSInfo *)kmalloc(sizeof(struct ubixFSInfo)); + fsInfo = mp->fsInfo; + fsInfo->rootDir = 0x0; + //mp->diskLabel->partitions[mp->partition].pOffset -= 63; + if ((mp->diskLabel->magicNum == UBIXDISKMAGIC) && (mp->diskLabel->magicNum2 == UBIXDISKMAGIC)) { + fsInfo->blockAllocationTable = (struct blockAllocationTableEntry *)kmalloc(mp->diskLabel->partitions[mp->partition].pBatSize*512); + /* fsInfo->blockAllocationTable[0].nextBlock = 100; */ + fsInfo->batEntries = ((mp->diskLabel->partitions[mp->partition].pBatSize*512)/sizeof(struct blockAllocationTableEntry)); + kprintf("C"); + mp->device->devInfo->read(mp->device->devInfo->info,fsInfo->blockAllocationTable,mp->diskLabel->partitions[mp->partition].pOffset,mp->diskLabel->partitions[mp->partition].pBatSize); + kprintf("Offset: [%i], Partition: [%i]\n",mp->diskLabel->partitions[mp->partition].pOffset,mp->partition); + kprintf("UbixFS Initialized\n"); + } + else { + kprintf("Insert System Disk!\n"); + while (1); + initUbixFS(mp); + } + /* Return */ + return; + } + +int openFileUbixFS(char *file,fileDescriptor *fd) { + int x=0; + struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(0x4000); + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector),(0x4000/512)); + if ((fd->mode & fileRead) == fileRead) { + for (x=0;x<(0x4000/sizeof(struct directoryEntry));x++) { + if ((int)!kstrcmp(dirEntry[x].fileName,file)) { + fd->start = dirEntry[x].startCluster; + fd->size = dirEntry[x].size; + fd->perms = dirEntry[x].permissions; + fd->dirBlock = 0x0; /* Directory Start Sector */ + kfree(dirEntry); + return((int)1); + } + } + } + else if ((fd->mode & fileWrite) == fileWrite) { + for (x=0;x<(0x4000/sizeof(struct directoryEntry));x++) { + if (!kstrcmp(dirEntry[x].fileName,file)) { + fd->start = dirEntry[x].startCluster; + fd->size = dirEntry[x].size; + fd->perms = dirEntry[x].permissions; + fd->dirBlock = 0x0; /* Directory Start Sector */ + kfree(dirEntry); + return(0x1); + } + if (dirEntry[x].attributes == 0x0) { + sprintf(dirEntry[x].fileName,file); + dirEntry[x].size = 0x0; + dirEntry[x].startCluster = getFreeBlocks(1,fd); + dirEntry[x].attributes = typeFile; + dirEntry[x].permissions = 3754; + fd->size = 0x0; + fd->start = dirEntry[x].startCluster; + fd->dirBlock = 0x0; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector),8); + kfree(dirEntry); + return(0x1); + } + } + } + kfree(dirEntry); + return((int)0); + } + +int writeFileByte(int ch,fileDescriptor *fd,long offset) { + + int blockCount = 0x0,batIndex = 0x0,batIndexPrev = fd->start,i = 0x0; + struct directoryEntry *dirEntry = 0x0; + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + + /* Find Out How Many Blocks Long This File Is */ + blockCount = (offset/4096); + + /* Find The Block If It Doesn't Exist We Will Have To Allocate One */ + for (i=0x0;i<=fd->mp->diskLabel->partitions[fd->mp->partition].pBatSize;i++) { + batIndex = fsInfo->blockAllocationTable[batIndexPrev].nextBlock; + if (batIndex == 0x0) { + break; + } + batIndexPrev = batIndex; + } + + if ((offset%4096 == 0) && (fd->status == fdRead)) { + fd->status = fdOpen; + } + + /* If batIndex == 0x0 Then We Must Allocate A New Block */ + if (batIndex == 0x0) { + for (i=1;i < fsInfo->batEntries;i++) { + if (fsInfo->blockAllocationTable[i].attributes == 0x0) { + fsInfo->blockAllocationTable[batIndexPrev].nextBlock = i; + fsInfo->blockAllocationTable[batIndex].nextBlock = -1; + batIndex = i; + fd->start = i; + break; + } + } + /* fd->mp->drive->read(fd->mp->drive->driveInfoStruct,diskLabel->partitions[0].pOffset+blockAllocationTable[batIndex].realSector,8,fd->buffer); */ + fd->buffer[offset-(blockCount*4096)] = ch; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,8); + } + else { + if (fd->status != fdRead) { + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,8); + fd->status = fdRead; + } + fd->buffer[offset-(blockCount*4096)] = ch; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,8); + } + if (offset > fd->size) { + fd->size = offset; + dirEntry = (struct directoryEntry *)kmalloc(4096); + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),8); + for (i=0x0;i<(4096/sizeof(struct directoryEntry));i++) { + if ((int)!kstrcmp(dirEntry[i].fileName,fd->fileName)) + break; + } + dirEntry[i].size = fd->size; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),8); + kfree(dirEntry); + } + return(ch); + } + +/* Verified Functions */ + +/************************************************************************ + +Function: int readUbixFS(fileDescriptor *fd,char *data,long offset,long size) +Description: Read File Into Data +Notes: + +************************************************************************/ +int readUbixFS(fileDescriptor *fd,char *data,long offset,long size) { + int blockCount = 0x0,batIndex = fd->start; + long i = 0x0; + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + blockCount = ((offset)/4096); + /* Find The Starting Block */ + for (i=1;i<=blockCount;i++) { + batIndex = fsInfo->blockAllocationTable[batIndex].nextBlock; + if (batIndex == 0x0) { + /* sysErr(log, "Invalid File Offset"); */ + return(0); + } + } + /* If The File Size Is Greater Then The Offset Lets Goto Work */ + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,blockSize); + for (i=0x0;i fd->size) { + /* Set File EOF If There Is Nothing To Do */ + data[i] = '\0'; + fd->status = fdEof; + return(size); + } + /* Copy Data From Buffer To Data */ + data[i] = fd->buffer[offset-(blockCount*4096)]; + offset++; + if (offset%4096 == 0 && offset != size) { + batIndex = fsInfo->blockAllocationTable[batIndex].nextBlock; + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[batIndex].realSector,blockSize); + blockCount++; + } + } + /* Return */ + return(size); + } + + + +/************************************************************************ + +Function: int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size) +Description: Write Data Into File +Notes: + +************************************************************************/ +int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size) { + uInt32 blockOffset = 0x0; + uInt32 blockIndex = fd->start; + uInt32 blockIndexPrev = fd->start; + uInt32 i = 0x0; + struct ubixFSInfo *fsInfo = fd->mp->fsInfo; + struct directoryEntry *dirEntry = 0x0; + + blockOffset = (offset/0x1000); + + + if (fd->size != 0x0) { + for (i = 0x0;i < blockOffset;i++) { + blockIndex = fsInfo->blockAllocationTable[blockIndexPrev].nextBlock; + if (blockIndex == EOBC) { + blockIndex = getFreeBlocks(1,fd); + fsInfo->blockAllocationTable[blockIndexPrev].nextBlock = blockIndex; + fsInfo->blockAllocationTable[blockIndex].nextBlock = EOBC; + break; + } + blockIndexPrev = blockIndex; + } + } + + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + for (i = 0x0;i < size;i++) { + + fd->buffer[(offset- (blockOffset *0x1000))] = data[i]; + offset++; + + if (offset%4096 == 0x0) { + blockOffset++; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + + if (fsInfo->blockAllocationTable[blockIndex].nextBlock == EOBC) { + blockIndexPrev = blockIndex; + blockIndex = getFreeBlocks(1,fd); + fsInfo->blockAllocationTable[blockIndexPrev].nextBlock = blockIndex; + fsInfo->blockAllocationTable[blockIndex].nextBlock = EOBC; + } + else { + blockIndex = fsInfo->blockAllocationTable[blockIndex].nextBlock; + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + } + } + } + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,fd->buffer,fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[blockIndex].realSector,blockSize); + + if (offset > fd->size) { + fd->size = offset; + dirEntry = (struct directoryEntry *)kmalloc(4096); + fd->mp->device->devInfo->read(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),blockSize); + for (i=0x0;i<(4096/sizeof(struct directoryEntry));i++) { + if ((int)!kstrcmp(dirEntry[i].fileName,fd->fileName)) + break; + } + dirEntry[i].size = fd->size; + dirEntry[i].startCluster = fd->start; + fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,dirEntry,(fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[fd->dirBlock].realSector),blockSize); + kfree(dirEntry); + } + /* Return */ + return(size); + } + +void ubixFSUnlink(char *path,struct mountPoints *mp) { + int x=0; + struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(0x1000); + struct ubixFSInfo *fsInfo = mp->fsInfo; + + mp->device->devInfo->read(mp->device->devInfo->info,dirEntry,(mp->diskLabel->partitions[mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector),8); + + for (x=0;x<(4096/sizeof(struct directoryEntry));x++) { + if ((int)!kstrcmp(dirEntry[x].fileName,path)) { + dirEntry[x].attributes |= typeDeleted; + dirEntry[x].fileName[0] = '?'; + mp->device->devInfo->write(mp->device->devInfo->info,dirEntry,(mp->diskLabel->partitions[mp->partition].pOffset+fsInfo->blockAllocationTable[fsInfo->rootDir].realSector),8); + return; + } + } + kprintf("File Not Found\n"); + return; + } + +/*** + $Log$ + Revision 1.10 2004/06/04 13:20:22 reddawg + ubixFSmkDir(): played with it a bit to see if it still worked + + Revision 1.9 2004/06/04 10:19:42 reddawg + notes: we compile again, thank g-d anyways i was about to cry + + Revision 1.8 2004/06/01 00:04:53 reddawg + Try now mark + + Revision 1.7 2004/05/19 15:20:06 reddawg + Fixed reference problems due to changes in drive subsystem + + Revision 1.6 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.5 2004/04/29 15:45:19 reddawg + Fixed some bugs so now the automade images will work correctly + + Revision 1.4 2004/04/28 21:10:40 reddawg + Lots Of changes to make it work with existing os + + Revision 1.3 2004/04/28 13:33:09 reddawg + Overhaul to ubixfs and boot loader and MBR to work well with our schema + now BAT and dir and file entries are all offset 64Sectors from the start of the partition + + Revision 1.2 2004/04/28 02:22:55 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.1.1.1 2004/04/15 12:07:08 reddawg + UbixOS v1.0 + + Revision 1.31 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/vfs/Makefile b/src/sys/vfs/Makefile new file mode 100644 index 0000000..7fd5c83 --- /dev/null +++ b/src/sys/vfs/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = mount.o file.o vfs.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -Wall -O -I../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -Wall -O -I../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -O -I../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -O -I../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c new file mode 100644 index 0000000..8500378 --- /dev/null +++ b/src/sys/vfs/file.c @@ -0,0 +1,273 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/************************************************************************ + +Function: int fclose(fileDescriptor *fd); +Description: This Will Close And Free A File Descriptor +Notes: + +************************************************************************/ +int fclose(fileDescriptor *fd) { + fileDescriptor *tmpFd = 0x0; + /* Search For File Descriptor */ + for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { + if (tmpFd == fd) { + /* If Fd Is The First FD Then Reset fdTable */ + if (tmpFd == fdTable) { + fdTable = tmpFd->next; + if (fdTable != 0x0) { + fdTable->prev = 0x0; + } + kfree(fd->buffer); + kfree(fd); + systemVitals->openFiles--; + return(1); + } + else { + tmpFd->prev->next = tmpFd->next; + tmpFd->next->prev = tmpFd->prev; + kfree(fd->buffer); + kfree(fd); + systemVitals->openFiles--; + return(1); + } + } + } + /* Return NULL If Descriptor Was Not Found */ + return(0x0); + } + +/************************************************************************ + +Function: void sysMkDir(const char *path) +Description: This Will Create A New Directory +Notes: + +************************************************************************/ +int sysMkDir(const char *path) { + fileDescriptor *tmpFd = 0x0; + char *dir = 0x0,*mountPoint = 0x0; + + + /* Allocate Memory For File Descriptor */ + tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor)); + tmpFd->mode = fileRead; + + dir = (char *)strtok((char *)path,"@"); + mountPoint = strtok(NULL,"\n"); + + if (mountPoint == 0x0) { + tmpFd->mp = _current->oInfo.container; + } + else { + tmpFd->mp = findMount(mountPoint); + } + if (tmpFd->mp == 0x0) { + kpanic("Invalid Container\n"); + return(0x1); + } + if (tmpFd->mp->fs->vfsOpenFile(":",tmpFd) == 1) { + tmpFd->buffer = (char *)kmalloc(4096); + sprintf(tmpFd->fileName,"%s",":"); + /* Set Its Status To Open */ + tmpFd->status = fdOpen; + /* Initial File Offset Is Zero */ + tmpFd->offset = 0x0; + } + else { + return(0x0); + } + if (tmpFd->mp->fs->vfsMakeDir(dir,tmpFd) != 0x0) { + kpanic("Error Creating Directory\n"); + } + else { + kpanic("Made Directory\n"); + } + kfree(tmpFd->buffer); + kfree(tmpFd); + return(0x0); + } + + +/************************************************************************ + +Function: int unlink(const char *node) +Description: This will unlink a file +Notes: + +************************************************************************/ + +int unlink(const char *node) { + char *path = 0x0,*mountPoint = 0x0; + struct mountPoints *mp = 0x0; + + path = (char *)strtok((char *)node,"@"); + mountPoint = strtok(NULL,"\n"); + if (mountPoint == 0x0) { + mp = findMount("sys"); /* _current->oInfo.container; */ + } + else { + mp = findMount(mountPoint); + } + if (mp == 0x0) { + //kpanic("Mount Point Bad"); + return(0x0); + } + mp->fs->vfsUnlink(path,mp); + return(0x0); + } + + +/************************************************************************ + +Function: fileDescriptor *fopen(const char *file,cont char *flags) +Description: This Will Open A File And Return A File Descriptor +Notes: + +08/05/02 - Just Started A Rewrite Of This Function Should Work Out Well + +************************************************************************/ + +fileDescriptor *fopen(const char *file,const char *flags) { + int i = 0; + fileDescriptor *tmpFd = 0x0; + char *path = 0x0,*mountPoint = 0x0; + /* Allocate Memory For File Descriptor */ + tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor)); + + path = (char *)strtok((char *)file,"@"); + mountPoint = strtok(NULL,"\n"); + if (mountPoint == 0x0) { + tmpFd->mp = findMount("sys"); /* _current->oInfo.container; */ + } + else { + tmpFd->mp = findMount(mountPoint); + } + if (tmpFd->mp == 0x0) { + //kpanic("Mount Point Bad"); + kprintf("Mount Point Bad\n"); + return(0x0); + } + /* This Will Set Up The Descriptor Modes */ + tmpFd->mode = 0x0; + while ('\0' != flags[i]) { + switch(flags[i]) { + case 'w': + case 'W': + tmpFd->mode |= fileWrite; + break; + case 'r': + case 'R': + tmpFd->mode |= fileRead; + break; + case 'b': + case 'B': + tmpFd->mode |= fileBinary; + break; + case 'a': + case 'A': + tmpFd->mode |= fileAppend; + break; + default: + break; + } + i++; + } + /* Search For The File */ + if (tmpFd->mp->fs->vfsOpenFile((char *)file,tmpFd) == 1) { + /* If The File Is Found Then Set Up The Descriptor */ + tmpFd->buffer = (char *)kmalloc(4096); + sprintf(tmpFd->fileName,"%s",file); + /* Set Its Status To Open */ + tmpFd->status = fdOpen; + /* Initial File Offset Is Zero */ + tmpFd->offset = 0x0; + /* Pointer To Next Descriptor Is NULL */ + tmpFd->prev = 0x0; + /* If This Is The First File Descriptor Then Set It Up To Be Starting Fd */ + if (fdTable == 0x0) { + fdTable = tmpFd; + tmpFd->next = 0x0; + tmpFd->prev = 0x0; + } + else { + /* If There Is Already A Starting FD Set This Up As The Last One */ + tmpFd->next = fdTable; + fdTable->prev = tmpFd; + tmpFd->prev = 0x0; + fdTable = tmpFd; + } + /* Increment Number Of Open Files */ + systemVitals->openFiles++; + + /* Return The FD */ + return(fdTable); + } + else { + /* If The File Was Not Found Free The Memory */ + kfree(tmpFd); + } + /* Return NULL */ + return(0x0); + } + +/*** + $Log$ + Revision 1.5 2004/06/16 19:56:35 reddawg + Moved fclose + + Revision 1.4 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.3 2004/06/01 00:04:53 reddawg + Try now mark + + Revision 1.2 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.12 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/vfs/mount.c b/src/sys/vfs/mount.c new file mode 100644 index 0000000..7f2b93c --- /dev/null +++ b/src/sys/vfs/mount.c @@ -0,0 +1,163 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +/************************************************************************ + +Function: mount(int driveId,int partition,int fsType,char *mountPoint,char *perms) + +Description: mount adds a mount point and returns 0 if successful 1 if it fails + +Notes: + +************************************************************************/ +int mount(int major,int minor,int partition,int vfsType,char *mountPoint,char *perms) { + struct mountPoints *mp = 0x0; + struct deviceNode *device = 0x0; + + /* Allocate Memory For Mount Point */ + mp = (struct mountPoints *)kmalloc(sizeof(struct mountPoints)); + + /* Copy Mount Point Into Buffer */ + sprintf(mp->mountPoint,mountPoint); + + /* Set Pointer To Physical Drive */ + device = deviceFind(major,minor); + + /* Set Up Mp Defaults */ + mp->device = device; + mp->fs = vfsFindFS(vfsType); + mp->partition = partition; + mp->perms = *perms; + if (device != 0x0) { + mp->diskLabel = (struct ubixDiskLabel *)kmalloc(512); + mp->device->devInfo->read(mp->device->devInfo->info,mp->diskLabel,1,1); + kprintf("READING SECTOR"); + } + + if (mp->fs == 0x0) { + /* sysErr(systemErr,"File System Type: %i Not Found\n",fsType); */ + kprintf("File System Type: %i Not Found\n",vfsType); + return(0x1); + } + /* Add Mountpoint If It Fails Free And Return */ + if (addMount(mp) != 0x0) { + kfree(mp); + return(0x1); + } + /* Initialize The File System If It Fails Return */ + if (mp->fs->vfsInitFS(mp) == 0x0) { + kfree(mp); + return(0x1); + } + /* Return */ + return(0x0); + } + +/************************************************************************ + +Function: addMount(struct mountPoints *mp) + +Description: This function adds a mount point to the system + +Notes: + +************************************************************************/ +int addMount(struct mountPoints *mp) { + + /* If There Are No Existing Mounts Make It The First */ + if (systemVitals->mountPoints == 0x0) { + mp->prev = 0x0; + mp->next = 0x0; + systemVitals->mountPoints = mp; + } + else { + mp->next = systemVitals->mountPoints; + systemVitals->mountPoints->prev = mp; + mp->prev = 0x0; + systemVitals->mountPoints = mp; + } + /* Return */ + return(0x0); + } + +/************************************************************************ + +Function: findMount(char *mountPoint) + +Description: This function finds a particular mount point + +Notes: + +************************************************************************/ +struct mountPoints *findMount(char *mountPoint) { + struct mountPoints *tmpMp = 0x0; + + for (tmpMp=systemVitals->mountPoints;tmpMp;tmpMp=tmpMp->next) { + if (kstrcmp(tmpMp->mountPoint,mountPoint) == 0x0) { + return(tmpMp); + } + } + /* Return NULL If Mount Point Not Found */ + return(0x0); + } + +/*** + $Log$ + Revision 1.6 2004/05/19 15:22:50 reddawg + Fixed reference issues due to changes in driver subsystem + + Revision 1.5 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.4 2004/04/29 15:45:19 reddawg + Fixed some bugs so now the automade images will work correctly + + Revision 1.3 2004/04/28 21:10:40 reddawg + Lots Of changes to make it work with existing os + + Revision 1.2 2004/04/28 02:22:55 reddawg + This is a fiarly large commit but we are starting to use new driver model + all around + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.4 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/sys/vfs/vfs.c b/src/sys/vfs/vfs.c new file mode 100644 index 0000000..c691df1 --- /dev/null +++ b/src/sys/vfs/vfs.c @@ -0,0 +1,126 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +/************************************************************************ + +Function: void initVFS(); + +Description: This Function Initializes The VFS Layer + +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int vfsInit() { + /* Set up default fileSystems list */ + systemVitals->fileSystems = 0x0; + + /* Print information */ + kprintf("vfs0 - Address: [0x%X]\n",systemVitals->fileSystems); + + /* Return so we know things went well */ + return(0x0); + } + +struct fileSystem *vfsFindFS(int vfsType) { + struct fileSystem *tmp = 0x0; + + /* Search For File System */ + for (tmp=systemVitals->fileSystems;tmp;tmp=tmp->next) { + /* If Found Return File System */ + if (tmp->vfsType == vfsType) { + return(tmp); + } + } + + /* If FS Not Found Return NULL */ + return(0x0); + } + +int vfsRegisterFS(int vfsType,void *vfsInitFS,void *vfsRead,void *vfsWrite,void *vfsOpenFile,void *vfsUnlink,void *vfsMakeDir,void *vfsRemDir,void *vfsSync) { + + struct fileSystem *tmpFs = 0x0; + + /* Allocate Memory */ + tmpFs = (struct fileSystem *)kmalloc(sizeof(struct fileSystem)); + if (tmpFs == 0x0) { + /* Memory Allocation Failed */ + return(0x1); + } + + /* Set Up FS Defaults */ + tmpFs->vfsType = vfsType; + tmpFs->vfsInitFS = vfsInitFS; + tmpFs->vfsRead = vfsRead; + tmpFs->vfsWrite = vfsWrite; + tmpFs->vfsOpenFile = vfsOpenFile; + tmpFs->vfsUnlink = vfsUnlink; + tmpFs->vfsMakeDir = vfsMakeDir; + tmpFs->vfsRemDir = vfsRemDir; + tmpFs->vfsSync = vfsSync; + + if (!systemVitals->fileSystems) { + tmpFs->prev = 0x0; + tmpFs->next = 0x0; + systemVitals->fileSystems = tmpFs; + } + else { + tmpFs->prev = 0x0; + tmpFs->next = systemVitals->fileSystems; + systemVitals->fileSystems->prev = tmpFs; + systemVitals->fileSystems = tmpFs; + } + + return(0x0); + } + +/*** + $Log$ + Revision 1.3 2004/05/21 14:52:39 reddawg + Cleaned up + + Revision 1.2 2004/05/19 04:07:43 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.7 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + END + ***/ + diff --git a/src/sys/vmm/Makefile b/src/sys/vmm/Makefile new file mode 100644 index 0000000..e6475eb --- /dev/null +++ b/src/sys/vmm/Makefile @@ -0,0 +1,27 @@ +# (C) 2002 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = pagefault.o vmminit.o getfreevirtualpage.o copyvirtualspace.o setpageattributes.o unmappage.o getphysicaladdr.o getfreepage.o createvirtualspace.o memory.o paging.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -Wall -O $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -Wall -O $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -O $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -O $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/vmm/README b/src/sys/vmm/README new file mode 100644 index 0000000..68fd016 --- /dev/null +++ b/src/sys/vmm/README @@ -0,0 +1,2 @@ +UbixOS VMM (c) 2002-2004 UbixOS + diff --git a/src/sys/vmm/copyvirtualspace.c b/src/sys/vmm/copyvirtualspace.c new file mode 100644 index 0000000..613cf8e --- /dev/null +++ b/src/sys/vmm/copyvirtualspace.c @@ -0,0 +1,196 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +/************************************************************************ + +Function: void *vmmCopyVirtualSpace(pidType pid); + +Description: Creates A Copy Of A Virtual Space And Set All NON Kernel + Space To COW For A Fork This Will Also Alter The Parents + VM Space To Make That COW As Well + +Notes: + +08/02/02 - Added Passing Of pidType pid So We Can Better Keep Track Of + Which Task Has Which Physical Pages + +************************************************************************/ +void * +vmmCopyVirtualSpace(pidType pid) +{ + void *newPageDirectoryAddress = 0x0; + uInt32 *parentPageDirectory = 0x0, *newPageDirectory = 0x0; + uInt32 *parentPageTable = 0x0, *newPageTable = 0x0; + uInt32 *parentStackPage = 0x0, *newStackPage = 0x0; + int x = 0, i = 0, s = 0; + + /* Set Address Of Parent Page Directory */ + parentPageDirectory = (uInt32 *) parentPageDirAddr; + + /* Allocate A New Page For The New Page Directory */ + newPageDirectory = (uInt32 *) vmmGetFreePage(pid); + + /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ + newPageDirectoryAddress = vmmGetPhysicalAddr((uInt32) newPageDirectory); + /* First Set Up A Flushed Page Directory */ + for (x = 0; x < pageEntries; x++) { + newPageDirectory[x] = (uInt32) 0x0; + } + /* Map The Top 1GB Region Of The VM Space */ + for (x = 768; x < pageEntries; x++) { + newPageDirectory[x] = parentPageDirectory[x]; + } + /* + * Now For The Fun Stuff For Page Tables 1-766 We Must Map These And Set + * The Permissions On Every Mapped Pages To COW This Will Conserve Memory + * Because The Two VM Spaces Will Be Sharing Some Pages + */ + for (x = 1; x <= 766; x++) { + /* If Page Table Exists Map It */ + if (parentPageDirectory[x] != 0) { + /* Set Parent To Propper Page Table */ + parentPageTable = (uInt32 *) (tablesBaseAddress + (4096 * x)); + /* Allocate A New Page Table */ + newPageTable = (uInt32 *) vmmGetFreePage(pid); + /* Set Parent And New Pages To COW */ + for (i = 0; i < pageEntries; i++) { + /* If Page Is Mapped */ + if (parentPageTable[i] != 0x0) { + /* Check To See If Its A Stack Page */ + if (((uInt32) parentPageTable[i] & pageStack) == pageStack) { + /* Alloc A New Page For This Stack Page */ + newStackPage = (uInt32 *) vmmGetFreePage(pid); + /* Set Pointer To Parents Stack Page */ + parentStackPage = (uInt32 *) (((1024 * 4096) * x) + (4096 * i)); + /* Copy The Tack Byte For Byte (I Should Find A Faster Way) */ + for (s = 0; s < pageEntries; s++) { + newStackPage[s] = parentStackPage[s]; + } + /* Insert New Stack Into Page Table */ + newPageTable[i] = ((uInt32) vmmGetPhysicalAddr((uInt32) newStackPage) | pageDefault | pageStack); + /* Unmap From Kernel Space */ + vmmUnmapPage((uInt32) newStackPage, 1); + } else { + /* Set Page To COW In Parent And Child Space */ + newPageTable[i] = (((uInt32) parentPageTable[i] & 0xFFFFF000) | (pagePresent | pageCow)); + /* Increment The COW Counter For This Page */ + if (((uInt32) parentPageTable[i] & pageCow) == pageCow) { + adjustCowCounter(((uInt32) parentPageTable[i] & 0xFFFFF000), 1); + } else { + adjustCowCounter(((uInt32) parentPageTable[i] & 0xFFFFF000), 2); + parentPageTable[i] = newPageTable[i]; + } + } + } else { + newPageTable[i] = (uInt32) 0x0; + } + } + /* Put New Page Table Into New Page Directory */ + newPageDirectory[x] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault); + /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ + vmmUnmapPage((uInt32) newPageTable, 1); + } else { + newPageDirectory[x] = (uInt32) 0x0; + } + } + /* + * Allocate A New Page For The The First Page Table Where We Will Map The + * Lower Region + */ + newPageTable = (uInt32 *) vmmGetFreePage(pid); + /* Flush The Page From Garbage In Memory */ + for (x = 0; x < pageEntries; x++) { + newPageTable[x] = (uInt32) 0x0; + } + /* Map This Into The Page Directory */ + newPageDirectory[0] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault); + /* Set Address Of Parents Page Table */ + parentPageTable = (uInt32 *) tablesBaseAddress; + /* Map The First 1MB Worth Of Pages */ + for (x = 0; x < (pageEntries / 4); x++) { + newPageTable[x] = parentPageTable[x]; + } + /* Map The Next 3MB Worth Of Pages But Make Them COW */ + for (x = (pageEntries / 4) + 1; x < pageEntries; x++) { + /* If Page Is Avaiable Map It */ + if (parentPageTable[x] != 0) { + /* Set Pages To COW */ + newPageTable[x] = (((uInt32) parentPageTable[x] & 0xFFFFF000) | (pagePresent | pageCow)); + /* Increment The COW Counter For This Page */ + if (((uInt32) parentPageTable[x] & pageCow) == pageCow) { + adjustCowCounter(((uInt32) parentPageTable[x] & 0xFFFFF000), 1); + } else { + adjustCowCounter(((uInt32) parentPageTable[x] & 0xFFFFF000), 2); + parentPageTable[x] = newPageTable[x]; + } + } else { + newPageTable[x] = (uInt32) 0x0; + } + } + /* Set Virtual Mapping For Page Directory */ + newPageTable[256] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageDirectory) | pageDefault); + + /* + * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have + * To Worry About Mapping Them In Later How Ever I'm Concerned This May + * Become A Security Issue + */ + /* First Lets Unmap The Previously Allocated Page Table */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Allocate A New Page Table */ + newPageTable = (uInt32 *) vmmGetFreePage(pid); + /* First Set Our Page Directory To Contain This */ + newPageDirectory[767] = (uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault; + /* Now Lets Build The Page Table */ + for (x = 0; x < pageEntries; x++) { + newPageTable[x] = newPageDirectory[x]; + } + /* Now We Are Done So Lets Unmap This Page */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Now We Are Done With The Page Directory So Lets Unmap That Too */ + vmmUnmapPage((uInt32) newPageDirectory, 1); + /* Return Physical Address Of Page Directory */ + return (newPageDirectoryAddress); +} + +/*** + $Log$ + Revision 1.2 2004/06/15 12:35:05 reddawg + Cleaned Up + + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg + UbixOS v1.0 + + Revision 1.14 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/src/sys/vmm/createvirtualspace.c b/src/sys/vmm/createvirtualspace.c new file mode 100644 index 0000000..00d94e8 --- /dev/null +++ b/src/sys/vmm/createvirtualspace.c @@ -0,0 +1,133 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg + UbixOS v1.0 + + Revision 1.8 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include + + +/************************************************************************ + +Function: void *vmmCreateVirtualSpace(pid_t); +Description: Creates A Virtual Space For A New Task +Notes: + +07/30/02 - This Is Going To Create A New VM Space However Its Going To + Share The Same Top 1GB Space With The Kernels VM And Lower + 1MB Of VM Space With The Kernel + +07/30/02 - Note This Is Going To Get The Top 1Gig And Lower 1MB Region + From The Currently Loaded Page Directory This Is Safe Because + All VM Spaces Will Share These Regions + +07/30/02 - Note I Realized A Mistake The First Page Table Will Need To Be + A Copy But The Page Tables For The Top 1GB Will Not Reason For + This Is That We Just Share The First 1MB In The First Page Table + So We Will Just Share Physical Pages. + +08/02/02 - Added Passing Of pid_t pid For Better Tracking Of Who Has Which + Set Of Pages + +************************************************************************/ +void * +vmmCreateVirtualSpace(pid_t pid) +{ + void *newPageDirectoryAddress = 0x0; + uInt32 *parentPageDirectory = 0x0, *newPageDirectory = 0x0; + uInt32 *parentPageTable = 0x0, *newPageTable = 0x0; + int x = 0; + + /* Set Address Of Parent Page Directory */ + parentPageDirectory = (uInt32 *) parentPageDirAddr; + /* Allocate A New Page For The New Page Directory */ + newPageDirectory = (uInt32 *) vmmGetFreePage(pid); + /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ + newPageDirectoryAddress = vmmGetPhysicalAddr((uInt32) newPageDirectory); + /* First Set Up A Flushed Page Directory */ + for (x = 0; x < pageEntries; x++) { + (uInt32) newPageDirectory[x] = (uInt32) 0x0; + } + /* Map The Top 1GB Region Of The VM Space */ + for (x = 768; x < pageEntries; x++) { + newPageDirectory[x] = parentPageDirectory[x]; + } + /* + * Allocate A New Page For The The First Page Table Where We Will Map The + * Lower Region + */ + newPageTable = (uInt32 *) vmmGetFreePage(pid); + /* Flush The Page From Garbage In Memory */ + for (x = 0; x < pageEntries; x++) { + (uInt32) newPageTable[x] = (uInt32) 0x0; + } + /* Map This Into The Page Directory */ + newPageDirectory[0] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault); + /* Set Address Of Parents Page Table */ + parentPageTable = (uInt32 *) tablesBaseAddress; + /* Map The First 1MB Worth Of Pages */ + for (x = 0; x < (pageEntries / 4); x++) { + newPageTable[x] = parentPageTable[x]; + } + /* Set Virtual Mapping For Page Directory */ + newPageTable[256] = ((uInt32) vmmGetPhysicalAddr((uInt32) newPageDirectory) | pageDefault); + + /* + * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have + * To Worry About Mapping Them In Later How Ever I'm Concerned This May + * Become A Security Issue + */ + /* First Lets Unmap The Previously Allocated Page Table */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Allocate A New Page Table */ + newPageTable = (uInt32 *) vmmGetFreePage(pid); + /* First Set Our Page Directory To Contain This */ + newPageDirectory[767] = (uInt32) vmmGetPhysicalAddr((uInt32) newPageTable) | pageDefault; + /* Now Lets Build The Page Table */ + for (x = 0; x < pageEntries; x++) { + newPageTable[x] = newPageDirectory[x]; + } + /* Now We Are Done So Lets Unmap This Page */ + vmmUnmapPage((uInt32) newPageTable, 1); + /* Now We Are Done With The Page Directory So Lets Unmap That Too */ + vmmUnmapPage((uInt32) newPageDirectory, 1); + /* Return Physical Address Of Page Directory */ + return (newPageDirectoryAddress); +} + +/*** + END + ***/ + diff --git a/src/sys/vmm/getfreepage.c b/src/sys/vmm/getfreepage.c new file mode 100644 index 0000000..74c0a87 --- /dev/null +++ b/src/sys/vmm/getfreepage.c @@ -0,0 +1,82 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg + UbixOS v1.0 + + Revision 1.6 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include + +/************************************************************************ + +Function: void *vmmGetFreePage(pidType pid); + +Description: Returns A Free Page Mapped To The VM Space + +Notes: + +07/30/02 - This Returns A Free Page In The Top 1GB For The Kernel + +************************************************************************/ +void * +vmmGetFreePage(pidType pid) +{ + int x = 0x0, y = 0x0; + uInt32 *pageTableSrc = 0x0; + + /* Lets Search For A Free Page */ + for (x = 768; x < 1024; x++) { + + /* Set Page Table Address */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * x)); + for (y = 0x0; y < 1024; y++) { + /* Loop Through The Page Table Find An UnAllocated Page */ + if ((uInt32) pageTableSrc[y] == (uInt32) 0x0) { + /* Map A Physical Page To The Virtual Page */ + vmmRemapPage(vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096))); + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + /* Return The Address Of The Newly Allocate Page */ + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + } + /* If No Free Page Was Found Return NULL */ + return (0x0); +} + +/*** + END + ***/ + diff --git a/src/sys/vmm/getfreevirtualpage.c b/src/sys/vmm/getfreevirtualpage.c new file mode 100644 index 0000000..f0a4e93 --- /dev/null +++ b/src/sys/vmm/getfreevirtualpage.c @@ -0,0 +1,120 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg + UbixOS v1.0 + + Revision 1.10 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include + +/************************************************************************ + +Function: void *vmmGetFreeVirtualPage(pidType pid,int count); +Description: Returns A Free Page Mapped To The VM Space +Notes: + +08/11/02 - This Will Return Next Avilable Free Page Of Tasks VM Space + +************************************************************************/ +void * +vmmGetFreeVirtualPage(pidType pid, int count) +{ + int x = 0, y = 0, c = 0; + uInt32 *pageTableSrc = 0x0; + uInt32 *pageDir = (uInt32 *) parentPageDirAddr; + + /* Lets Search For A Free Page */ + for (x = (_current->oInfo.vmStart / (1024 * 4096)); x < 1024; x++) { + /* Set Page Table Address */ + if ((pageDir[x] & pagePresent) != pagePresent) { + /* If Page Table Is Non Existant Then Set It Up */ + pageDir[x] = (uInt32) vmmFindFreePage(_current->id) | pageDefault; + /* Also Add It To Virtual Space So We Can Make Changes Later */ + pageTableSrc = (uInt32 *) (tablesBaseAddress + (4096 * 767)); + pageTableSrc[x] = pageDir[x]; + y = 1; + /* Reload Page Directory */ + asm( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } + pageTableSrc = (uInt32 *) (tablesBaseAddress + (0x1000 * x)); + if (y != 0x0) { + for (y = 0x0;y 0x1) { + for (c = 0; c < count; c++) { + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + if (c != -1) { + for (c = 0; c < count; c++) { + vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096))); + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); + } + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } else { + /* Map A Physical Page To The Virtual Page */ + + /* + * remapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*4096)) + * ,pid); + */ + vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096))); + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + /* Return The Address Of The Newly Allocate Page */ + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + } + } + /* If No Free Page Was Found Return NULL */ + return (0x0); +} + +/*** + END + ***/ + diff --git a/src/sys/vmm/getphysicaladdr.c b/src/sys/vmm/getphysicaladdr.c new file mode 100644 index 0000000..44ac5a9 --- /dev/null +++ b/src/sys/vmm/getphysicaladdr.c @@ -0,0 +1,63 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ +#include + +/************************************************************************ + +Function: void *vmmGetPhysicalAddr(); +Description: Returns The Physical Address Of The Virtual Page +Notes: + +************************************************************************/ +void *vmmGetPhysicalAddr(uInt32 pageAddr) { + int pageDirectoryIndex = 0, pageTableIndex = 0; + uInt32 *pageTable = 0x0; + + /* Get The Index To The Page Directory */ + pageDirectoryIndex = (pageAddr / (1024 * 4096)); + /* Get The Index To The Page Table */ + pageTableIndex = ((pageAddr - (pageDirectoryIndex * (1024 * 4096))) / 4096); + /* Set pageTable To The Virtual Address Of Table */ + pageTable = (uInt32 *) (tablesBaseAddress + (4096 * pageDirectoryIndex)); + /* Return The Physical Address Of The Page */ + return ((void *)(pageTable[pageTableIndex] & 0xFFFFF000)); + } + +/*** + $Log$ + Revision 1.2 2004/06/16 12:52:51 reddawg + Fixed bug with & + + Revision 1.1.1.1 2004/04/15 12:06:51 reddawg + UbixOS v1.0 + + Revision 1.6 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + END + ***/ diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c new file mode 100644 index 0000000..dec1f61 --- /dev/null +++ b/src/sys/vmm/memory.c @@ -0,0 +1,347 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + + +mMap *vmmMemoryMap = (mMap *) 0x101000; +int numPages = 0x0; +uInt32 freePages = 0; + + +/************************************************************************ + + Function: void vmmMemMapInit(); + Description: This Function Initializes The Memory Map For the System + Notes: + + 02/20/2004 - Made It Report Real And Available Memory + +************************************************************************/ +int vmmMemMapInit() { + int i = 0x0; + int memStart = 0x0; + + /* Count System Memory */ + numPages = countMemory(); + + /* Set Memory Map To Point To First Physical Page That We Will Use */ + vmmMemoryMap = (mMap *) 0x101000; + + /* Initialize Map Make All Pages Not Available */ + for (i = 0x0; i < numPages; i++) { + vmmMemoryMap[i].cowCounter = 0x0; + vmmMemoryMap[i].status = memNotavail; + vmmMemoryMap[i].pid = vmmID; + vmmMemoryMap[i].pageAddr = i * 4096; + } + + /* Calculate Start Of Free Memory */ + memStart = (0x101000 / 0x1000); + memStart += (((sizeof(mMap) * numPages) + (sizeof(mMap) - 1)) / 0x1000); + + /* Initialize All Free Pages To Available */ + vmmMemoryMap[(0x100000 / 0x1000)].status = memAvail; + freePages++; + for (i = memStart; i < numPages; i++) { + vmmMemoryMap[i].status = memAvail; + freePages++; + } + + /* Print Out Amount Of Memory */ + kprintf("Real Memory: %iKB\n", numPages * 4); + kprintf("Available Memory: %iKB\n", freePages * 4); + + /* Return */ + return (0); + } + +/************************************************************************ + + Function: int countMemory(); + Description: This Function Counts The Systems Physical Memory + Notes: + + 02/20/2004 - Inspect For Quality And Approved + +************************************************************************/ +int countMemory() { + register uInt32 *mem = 0x0; + unsigned long memCount = -1, tempMemory = 0x0; + unsigned short memKb = 0; + unsigned char irq1State, irq2State; + unsigned long cr0 = 0x0; + + /* + * Save The States Of Both IRQ 1 And 2 So We Can Turn Them Off And Restore + * Them Later + */ + irq1State = inportByte(0x21); + irq2State = inportByte(0xA1); + + /* Turn Off IRQ 1 And 2 To Prevent Chances Of Faults While Examining Memory */ + outportByte(0x21, 0xFF); + outportByte(0xA1, 0xFF); + + /* Save The State Of Register CR0 */ + asm volatile ( + "movl %%cr0, %%ebx\n" + : "=a" (cr0) + : + : "ebx" + ); + + asm volatile ("wbinvd"); + asm volatile ( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) + : "ebx" + ); + + while (memKb < 4096 && memCount != 0) { + memKb++; + if (memCount == -1) + memCount = 0; + memCount += 1024 * 1024; + mem = (uInt32 *)memCount; + tempMemory = *mem; + *mem = 0x55AA55AA; + asm("": : :"memory"); + if (*mem != 0x55AA55AA) { + memCount = 0; + } + else { + *mem = 0xAA55AA55; + asm("": : :"memory"); + if (*mem != 0xAA55AA55) { + memCount = 0; + } + } + asm("": : :"memory"); + *mem = tempMemory; + } + + asm volatile ( + "movl %%ebx, %%cr0\n" + : + : "a" (cr0) + : "ebx" + ); + + /* Restore States For Both IRQ 1 And 2 */ + outportByte(0x21, irq1State); + outportByte(0xA1, irq2State); + + /* Return Amount Of Memory In Pages */ + return ((memKb * 1024 * 1024) / 4096); + } + +/************************************************************************ + + Function: uInt32 vmmFindFreePage(pid_t pid); + + Description: This Returns A Free Physical Page Address Then Marks It + Not Available As Well As Setting The PID To The Proccess + Allocating This Page + Notes: + +************************************************************************/ +uInt32 vmmFindFreePage(pidType pid) { + int i = 0x0; + + /* Lets Look For A Free Page */ + if (pid < sysID) { + kpanic("Error: invalid PID\n"); + } + + for (i = 0; i <= numPages; i++) { + + /* + * If We Found A Free Page Set It To Not Available After That Set Its Own + * And Return The Address + */ + if ((vmmMemoryMap[i].status == memAvail) && (vmmMemoryMap[i].cowCounter == 0)) { + vmmMemoryMap[i].status = memNotavail; + vmmMemoryMap[i].pid = pid; + freePages--; + systemVitals->freePages = freePages; + return (vmmMemoryMap[i].pageAddr); + } + } + + /* If No Free Memory Is Found Return NULL */ + kpanic("Out Of Memory!!!!"); + return (0x0); + } + + +/************************************************************************ + + Function: int freePage(uInt32 pageAddr); + + Description: This Function Marks The Page As Free + + Notes: + +************************************************************************/ +int freePage(uInt32 pageAddr) { + int pageIndex = 0x0; + + /* Find The Page Index To The Memory Map */ + pageIndex = (pageAddr / 4096); + + /* Check If Page COW Is Greater Then 0 If It Is Dec It If Not Free It */ + if (vmmMemoryMap[pageIndex].cowCounter == 0) { + /* Set Page As Avail So It Can Be Used Again */ + vmmMemoryMap[pageIndex].status = memAvail; + vmmMemoryMap[pageIndex].cowCounter = 0x0; + vmmMemoryMap[pageIndex].pid = -2; + freePages++; + } + else { + /* Adjust The COW Counter */ + adjustCowCounter(((uInt32) vmmMemoryMap[pageIndex].pageAddr), -1); + } + + /* Return */ + return (0); + } + +/************************************************************************ + + Function: int adjustCowCounter(uInt32 baseAddr,int adjustment); + + Description: This Adjust The COW Counter For Page At baseAddr It Will + Error If The Count Goes Below 0 + + Notes: + + 08/01/02 - I Think If Counter Gets To 0 I Should Free The Page + +************************************************************************/ +int adjustCowCounter(uInt32 baseAddr, int adjustment) { + int vmmMemoryMapIndex = (baseAddr / 4096); + + /* Adjust COW Counter */ + vmmMemoryMap[vmmMemoryMapIndex].cowCounter += adjustment; + + /* + * kprintf("(%i[%i]%x)\n",vmmMemoryMapIndex,vmmMemoryMap[vmmMemoryMapIndex].cowCounte + * r,baseAddr); + */ + if (vmmMemoryMap[vmmMemoryMapIndex].cowCounter == 0) { + vmmMemoryMap[vmmMemoryMapIndex].status = memAvail; + vmmMemoryMap[vmmMemoryMapIndex].cowCounter = 0x0; + vmmMemoryMap[vmmMemoryMapIndex].pid = vmmID; + freePages++; + } + + /* Return */ + return (0); + } + +/************************************************************************ + + Function: void vmmFreeProcessPages(pid_t pid); + + Description: This Function Will Free Up Memory For The Exiting Process + + Notes: + + 08/04/02 - Added Checking For COW Pages First + +************************************************************************/ +void vmmFreeProcessPages(pidType pid) { + int i=0,x=0; + uInt32 *tmpPageTable = 0x0; + uInt32 *tmpPageDir = (uInt32 *)parentPageDirAddr; + + /* Check Page Directory For An Avail Page Table */ + for (i=0;i<=0x300;i++) { + if (tmpPageDir[i] != 0) { + /* Set Up Page Table Pointer */ + tmpPageTable = (uInt32 *)(tablesBaseAddress + (i * 0x1000)); + /* Check The Page Table For COW Pages */ + for (x=0;xfreePages = freePages; + } + } + } + /* Return */ + } + +/*** + $Log$ + Revision 1.6 2004/06/14 12:20:54 reddawg + notes: many bugs repaired and ld works 100% now. + + Revision 1.5 2004/05/21 15:34:23 reddawg + Fixed a couple of typo + + Revision 1.4 2004/05/21 14:50:10 reddawg + Cleaned up + + Revision 1.3 2004/05/19 17:28:28 reddawg + Added the correct endTask Procedure + + Revision 1.2 2004/04/30 14:16:04 reddawg + Fixed all the datatypes to be consistant uInt8,uInt16,uInt32,Int8,Int16,Int32 + + Revision 1.1.1.1 2004/04/15 12:06:52 reddawg + UbixOS v1.0 + + Revision 1.27 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + END + ***/ diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c new file mode 100644 index 0000000..8bdfd16 --- /dev/null +++ b/src/sys/vmm/pagefault.c @@ -0,0 +1,167 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/06/10 22:23:56 reddawg + Volatiles + + Revision 1.1.1.1 2004/04/15 12:06:52 reddawg + UbixOS v1.0 + + Revision 1.4 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +/************************************************************************ + +Function: void vmmPageFault(); +Description: This Function Is The Second Half Of The Page Fault ISR + Currently It Handles COW However I Need To Prepar It For + Swapping +Notes: + +07/30/02 - Fixed COW However I Need To Think Of A Way To Impliment + A Paging System Also Start To Add Security Levels + +************************************************************************/ +void vmmPageFault() { + uInt32 memAddr = 0,i = 0, pageTableIndex = 0,pageDirectoryIndex = 0; + uInt32 *pageDir,*pageTable; + uInt32 *src,*dst; + pageDir = (uInt32 *)parentPageDirAddr; + //Get Memory Address For Violation + asm volatile( + "movl %%cr2,%%eax\n" + "movl %%eax,%0\n" + + : "=g" (memAddr) + ); + //Calculate The Page Directory Index + pageDirectoryIndex = (memAddr/(1024*4096)); + //Calculate The Page Table Index + pageTableIndex = ((memAddr-(pageDirectoryIndex*(1024*4096)))/4096); + if (pageDir[pageDirectoryIndex] == 0) { + //Creat A Routine For Non Mapped Memory + kprintf("Segfault At Address: [0x%X][0x%X][%i]\n",memAddr,_current->tss.esp,_current->id); + //if ((uInt32)_current->tss.cr3 != (uInt32)kernelPageDirectory) { + // freeProcessPages(_current->id); + // } + //setTaskStatus(_current->id,EXITING); + //if (_current->id <= -1) { + //kPanic("Kernel Crashed.\n"); + // } + //schedule(); + while (1); + } + else { + //Set pageTable To Point To Virtual Address Of Page Table + pageTable = (uInt32 *)(tablesBaseAddress + (4096 * pageDirectoryIndex)); + if (((uInt32)pageTable[pageTableIndex] & pageCow) == pageCow) { + //Set Src To Base Address Of Page To Copy + src = (uInt32 *) ((1024*4096*pageDirectoryIndex) + (4096*pageTableIndex)); + //Allocate A Free Page For Destination + dst = (uInt32 *) vmmGetFreePage(-1); + //Copy Memory + for (i=0;itss.esp,_current->id); + /* + kprintf("EAX: [0x%X],EBX: [0x%X]\n",_current->tss.eax,_current->tss.ebx); + kprintf("ECX: [0x%X],EDX: [0x%X]\n",_current->tss.ecx,_current->tss.edx); + kprintf("ESP: [0x%X],EPB: [0x%X]\n",_current->tss.esp,_current->tss.ebp); + kprintf("EIP: [0x%X],CR2: [0x%X]\n",_current->tss.eip,memAddr); + kprintf("CS: [0x%X],DS: [0x%X]\n",_current->tss.cs,_current->tss.ds); + kprintf("SS: [0x%X],ES: [0x%X]\n",_current->tss.ss,_current->tss.es); + kprintf("FS: [0x%X],GS: [0x%X]\n",_current->tss.gs,_current->tss.gs); + kprintf("EFLAGS: [0x%X] \n",_current->tss.eflags); + */ + _current->state = DEAD; + /* + if ((uInt32)_current->tss.cr3 != (uInt32)kernelPageDirectory) { + freeProcessPages(_current->id); + } + setTaskStatus(_current->id,EXITING); + if (_current->id <= -1) { + panic(); + } + */ + sched(); + } + } + asm volatile( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } + +/************************************************************************ + +Function: void _pageFault() +Description: This Is The ASM Code That Calls The pageFault() Function +Notes: + +************************************************************************/ +asm( + ".global _vmmPageFault \n" + "_vmmPageFault: \n" + "xchgl %eax,(%esp) \n" + "pushl %ecx \n" + "pushl %edx \n" + "push %ds \n" + "push %es \n" + "push %fs \n" + "call vmmPageFault \n" + "pop %fs \n" + "pop %es \n" + "pop %ds \n" + "popl %edx \n" + "popl %ecx \n" + "popl %eax \n" + "iret \n" + ); + +/*** + END + ***/ diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c new file mode 100644 index 0000000..d4ea0f7 --- /dev/null +++ b/src/sys/vmm/paging.c @@ -0,0 +1,385 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.4 2004/06/10 22:23:56 reddawg + Volatiles + + Revision 1.3 2004/06/10 15:24:35 reddawg + Fixed an asm statement + + Revision 1.2 2004/05/22 21:46:37 reddawg + Fixed some bugs + + Revision 1.1.1.1 2004/04/15 12:06:52 reddawg + UbixOS v1.0 + + Revision 1.30 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +uInt32 *kernelPageDirectory = 0x0; + + +/************************************************************************ + +Function: int vmmPagingInit() +Description: This Function Will Initialize The Operating Systems Paging + Abilities. + +Notes: + +02/20/2004 - Looked Over Code And Have Approved Its Quality + +************************************************************************/ + +int +vmmPagingInit() +{ + uInt32 i = 0x0, x = 0x0; + uInt32 *pageTable = 0x0; + + /* Allocate A Page Of Memory For Kernels Page Directory */ + kernelPageDirectory = (uInt32 *) vmmFindFreePage(sysID); + if (kernelPageDirectory == 0x0) { + kpanic("Error: vmmFindFreePage Failed"); + return (-1); + } + + /* Clear The Memory To Ensure There Is No Garbage */ + for (i = 0; i < pageEntries; i++) { + (uInt32) kernelPageDirectory[i] = (uInt32) 0x0; + } + + /* Allocate A Page For The First 4MB Of Memory */ + pageTable = (uInt32 *) vmmFindFreePage(sysID); + if (pageTable == 0x0) { + kpanic("Error: vmmFindFreePage Failed"); + return (-1); + } + + /* Map The First Page Table For The First 4MB Of Memory */ + kernelPageDirectory[0] = (uInt32) ((uInt32) (pageTable) | pagePresent | pageWrite | pageUser); + + /* Make Sure The Page Table Is Clean */ + for (i = 0; i < pageEntries; i++) { + (uInt32) pageTable[i] = (uInt32) 0x0; + } + + /* Map The First 1MB Of Memory To The Kernel VM Space */ + for (i = 0; i < (pageEntries / 4); i++) { + pageTable[i] = (uInt32) ((i * 0x1000) | pagePresent | pageWrite | pageUser); + } + + /* + * Create Page Tables For The Top 1GB Of VM Space This Is To Be Shared With + * All VM Spaces + */ + for (i = 768; i < pageEntries; i++) { + /* Allocate Page Table */ + pageTable = (uInt32 *) vmmFindFreePage(sysID); + if (pageTable == 0x0) { + kpanic("Error: vmmFindFreePage Failed"); + return (-1); + } + /* Make Sure The Page Table Is Clean */ + for (x = 0; x < pageEntries; x++) { + (uInt32) pageTable[x] = (uInt32) 0x0; + } + /* Map In The Page Directory */ + kernelPageDirectory[i] = (uInt32) ((uInt32) (pageTable) | pagePresent | pageWrite); + } + + /* Allocate Page Table 767 To Be The Map Of All Page Tables Used In Page Directory + pageTable = (uInt32 *) vmmFindFreePage(sysID); + if (pageTable == 0x0) { + kpanic("Error: vmmFindFreePage Failed"); + return (0x1); + } + /* Clean Page Table */ + for (x = 0; x < pageEntries; x++) { + (uInt32) pageTable[x] = (uInt32) 0x0; + } + kernelPageDirectory[767] = ((uInt32) pageTable | pagePresent | pageWrite); + for (i = 0; i < pageEntries; i++) { + pageTable[i] = kernelPageDirectory[i]; + } + /* Also Set Up Page Directory To Be The The First Page In 0xE0400000 */ + pageTable = (uInt32 *) (kernelPageDirectory[0] & 0xFFFFF000); + pageTable[256] = (uInt32) ((uInt32) (kernelPageDirectory) | pagePresent | pageWrite); + + /* Now Lets Turn On Paging With This Initial Page Table */ + asm volatile( + "movl %0,%%eax \n" + "movl %%eax,%%cr3 \n" + "movl %%cr0,%%eax \n" + "orl $0x80010000,%%eax \n" /* Flags To Enable Paging With + * Protection */ + "movl %%eax,%%cr0 \n" + : + : "d"((uInt32 *) (kernelPageDirectory)) + ); + + /* Remap The Memory List */ + for (i = 0x101000; i <= (0x101000 + (numPages * sizeof(mMap))); i += 0x1000) { + vmmRemapPage(i, (vmmMemoryMapAddr + (i - 0x101000))); + } + /* Set New Address For Memory Map Since Its Relocation */ + vmmMemoryMap = (mMap *) vmmMemoryMapAddr; + + /* Print information on paging */ + kprintf("paging0 - Address: [0x%X], PagingISR Address: [0x%X]\n", kernelPageDirectory, &_vmmPageFault); + + /* Return so we know everything went well */ + return (0x0); +} + +/************************************************************************ + +Function: int vmmRemapPage(Physical Source,Virtual Destination) +Description: This Function Will Remap A Physical Page Into Virtual Space +Notes: + +07/29/02 - Rewrote This To Work With Our New Paging System + +07/30/02 - Changed Address Of Page Tables And Page Directory + +************************************************************************/ +int +vmmRemapPage(uInt32 source, uInt32 dest) +{ + uInt16 destPageDirectoryIndex = 0, destPageTableIndex = 0; + uInt32 *pageDir, *pageTable; + int i = 0x0; + + /* + * Set Pointer pageDirectory To Point To The Virtual Mapping Of The Page + * Directory + */ + pageDir = (uInt32 *) parentPageDirAddr; + /* Check To See If Page Table Exists */ + destPageDirectoryIndex = (dest / (1024 * 4096)); + if ((pageDir[destPageDirectoryIndex] & pagePresent) != pagePresent) { + /* If Page Table Is Non Existant Then Set It Up */ + pageDir[destPageDirectoryIndex] = (uInt32) vmmFindFreePage(sysID) | pageDefault; + i = 1; + /* Also Add It To Virtual Space So We Can Make Changes Later */ + pageTable = (uInt32 *) (tablesBaseAddress + (4096 * 767)); + pageTable[destPageDirectoryIndex] = pageDir[destPageDirectoryIndex]; + /* Reload Page Directory */ + asm volatile( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + } + /* Set Address To Page Table */ + pageTable = (uInt32 *) (tablesBaseAddress + (4096 * destPageDirectoryIndex)); + if (i != 0x0) { + for (i=0x0;i 1) { + for (c = 0; c < count; c++) { + if ((uInt32) pageTableSrc[y + c] != (uInt32) 0x0) { + c = -1; + break; + } + } + if (c != -1) { + for (c = 0; c < count; c++) { + vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096))); + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + ((y + c) * 4096))); + } + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } else { + /* Map A Physical Page To The Virtual Page */ + + /* + * vmmRemapPage((uInt32)vmmFindFreePage(pid),((x*(1024*4096))+(y*409 + * 6)),pid); + */ + vmmRemapPage((uInt32) vmmFindFreePage(pid), ((x * (1024 * 4096)) + (y * 4096))); + /* Clear This Page So No Garbage Is There */ + vmmClearVirtualPage((uInt32) ((x * (1024 * 4096)) + (y * 4096))); + /* Return The Address Of The Newly Allocate Page */ + return ((void *)((x * (1024 * 4096)) + (y * 4096))); + } + } + } + } + /* If No Free Page Was Found Return NULL */ + return (0x0); +} + + +/************************************************************************ + +Function: void vmmClearVirtualPage(uInt32 pageAddr); + +Description: This Will Null Out A Page Of Memory + +Notes: + +************************************************************************/ +int +vmmClearVirtualPage(uInt32 pageAddr) +{ + uInt32 *src = 0x0; + int counter = 0x0; + + /* Set Source Pointer To Virtual Page Address */ + src = (uInt32 *) pageAddr; + + /* Clear Out The Page */ + for (counter = 0x0; counter < pageEntries; counter++) { + (uInt32) src[counter] = (uInt32) 0x0; + } + + /* Return */ + return (0x0); +} + + +void *vmmMapFromTask(pidType pid,void *ptr,uInt32 size) { + kTask_t *child = 0x0; + uInt32 i = 0x0,x = 0x0,y = 0x0,count = ((size+4095)/0x1000),c = 0x0; + uInt16 dI = 0x0,tI = 0x0; + uInt32 baseAddr = 0x0,offset = 0x0; + uInt32 *childPageDir = (uInt32 *)0x5A00000; + uInt32 *childPageTable = 0x0; + uInt32 *pageTableSrc = 0x0; + offset = (uInt32)ptr & 0xFFF; + baseAddr = (uInt32)ptr & 0xFFFFF000; + child = schedFindTask(pid); + //Calculate The Page Table Index And Page Directory Index + dI = (baseAddr/(1024*4096)); + tI = ((baseAddr-(dI*(1024*4096)))/4096); + vmmRemapPage(child->tss.cr3,0x5A00000); + for (i=0;i<0x1000;i++) { + vmmRemapPage(childPageDir[i],0x5A01000 + (i * 0x1000)); + } + for (x=(_current->oInfo.vmStart/(1024*4096));x<1024;x++) { + pageTableSrc = (uInt32 *)(tablesBaseAddress + (4096*x)); + for (y=0;y<1024;y++) { + //Loop Through The Page Table Find An UnAllocated Page + if ((uInt32)pageTableSrc[y] == (uInt32)0x0) { + if (count > 1) { + for (c=0;((c= 0x1000) { + dI++; + tI = 0-c; + } + childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); + vmmRemapPage(childPageTable[tI+c],((x*(1024*4096))+((y+c)*4096))); + } + vmmUnmapPage(0x5A00000,1); + for (i=0;i<0x1000;i++) { + vmmUnmapPage((0x5A01000 + (i*0x1000)),1); + } + return((void *)((x*(1024*4096))+(y*4096)+offset)); + } + } + else { + //Map A Physical Page To The Virtual Page + childPageTable = (uInt32 *)(0x5A01000 + (0x1000 * dI)); + vmmRemapPage(childPageTable[tI],((x*(1024*4096))+(y*4096))); + //Return The Address Of The Mapped In Memory + vmmUnmapPage(0x5A00000,1); + for (i=0;i<0x1000;i++) { + vmmUnmapPage((0x5A01000 + (i*0x1000)),1); + } + return((void *)((x*(1024*4096))+(y*4096)+offset)); + } + } + } + } + return(0x0); + } + +/*** + END + ***/ + diff --git a/src/sys/vmm/setpageattributes.c b/src/sys/vmm/setpageattributes.c new file mode 100644 index 0000000..e567f9d --- /dev/null +++ b/src/sys/vmm/setpageattributes.c @@ -0,0 +1,80 @@ +/***************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of +conditions, the following disclaimer and the list of authors. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions, the following +disclaimer and the list of authors in the documentation and/or other materials provided +with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Log$ + Revision 1.2 2004/06/10 22:23:56 reddawg + Volatiles + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.6 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + + + $Id$ + +*****************************************************************************************/ + +#include + +/************************************************************************ + +Function: void vmmSetPageAttributes(uInt32 pageAddr,int attributes; +Description: This Function Will Set The Page Attributes Such As + A Read Only Page, Stack Page, COW Page, ETC. +Notes: + +************************************************************************/ +void +vmmSetPageAttribute(uInt32 pageAddr, int attributes) +{ + int directoryIndex, tableIndex; + uInt32 *pageTable; + + /* Get Index To Page Directory */ + directoryIndex = (pageAddr / (1024 * 4096)); + /* Get Index To Page Table */ + tableIndex = ((pageAddr - (directoryIndex * (1024 * 4096))) / 4096); + /* Set Table Pointer */ + pageTable = (uInt32 *) (tablesBaseAddress + (4096 * directoryIndex)); + /* Set Attribute If Page Is Mapped */ + if (pageTable[tableIndex] != 0) { + pageTable[tableIndex] = ((pageTable[tableIndex] & 0xFFFFF000) | attributes); + } + /* Reload The Page Table; */ + asm volatile( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + /* Return */ + return; +} + +/*** + END + ***/ + diff --git a/src/sys/vmm/unmappage.c b/src/sys/vmm/unmappage.c new file mode 100644 index 0000000..6658ab8 --- /dev/null +++ b/src/sys/vmm/unmappage.c @@ -0,0 +1,129 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +/************************************************************************ + +Function: void vmmUnmapPage(uInt32 pageAddr,int flags); +Description: This Function Will Unmap A Page From The Kernel VM Space + The Flags Variable Decides If Its To Free The Page Or Not + A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It +Notes: + +07/30/02 - I Have Decided That This Should Free The Physical Page There + Is No Reason To Keep It Marked As Not Available + +07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit + Even I Am Not Perfect Ok The Case Where You Wouldn't Want To + Free It Would Be On Something Like Where I Allocated A Page + To Create A New Virtual Space So Now It Has A Flag + +************************************************************************/ +void +vmmUnmapPage(uInt32 pageAddr, int flags) +{ + int pageDirectoryIndex = 0, pageTableIndex = 0; + uInt32 *pageTable = 0x0; + + /* Get The Index To The Page Directory */ + pageDirectoryIndex = (pageAddr / (1024 * 4096)); + /* Get The Index To The Page Table */ + pageTableIndex = ((pageAddr - (pageDirectoryIndex * (1024 * 4096))) / 4096); + /* Set pageTable To The Virtual Address Of Table */ + pageTable = (uInt32 *) (tablesBaseAddress + (4096 * pageDirectoryIndex)); + /* Free The Physical Page If Flags Is 0 */ + if (flags == 0) { + + /* + * This is temp i think its still an issue clearVirtualPage(pageAddr); + * freePage((uInt32)(pageTable[pageTableIndex] & 0xFFFFF000)); + */ + } + /* Unmap The Page */ + pageTable[pageTableIndex] = 0x0; + /* Rehash The Page Directory */ + asm volatile( + "movl %cr3,%eax\n" + "movl %eax,%cr3\n" + ); + /* Return */ + return; +} + + + +/************************************************************************ + +Function: void vmmUnmapPages(uInt32 pageAddr,int flags); +Description: This Function Will Unmap A Page From The Kernel VM Space + The Flags Variable Decides If Its To Free The Page Or Not + A Flag Of 0 Will Free It And A Flag Of 1 Will Keep It +Notes: + +07/30/02 - I Have Decided That This Should Free The Physical Page There + Is No Reason To Keep It Marked As Not Available + +07/30/02 - Ok A Found A Reason To Keep It Marked As Available I Admit + Even I Am Not Perfect Ok The Case Where You Wouldn't Want To + Free It Would Be On Something Like Where I Allocated A Page + To Create A New Virtual Space So Now It Has A Flag + +************************************************************************/ +void vmmUnmapPages(void *ptr,uInt32 size) { + uInt32 baseAddr = (uInt32)ptr & 0xFFFFF000; + uInt32 dI = 0x0,tI = 0x0; + uInt32 y = 0x0; + uInt32 *pageTable = 0x0; + + dI = (baseAddr/(1024*4096)); + tI = ((baseAddr-(dI*(1024*4096)))/4096); + pageTable = (uInt32 *)(tablesBaseAddress + (4096*dI)); + for (y=tI;y<(tI+((size+4095)/4096));y++) { + pageTable[y] = 0x0; + } + return; + } + +/*** + $Log$ + Revision 1.3 2004/06/15 12:35:05 reddawg + Cleaned Up + + Revision 1.2 2004/06/10 22:23:56 reddawg + Volatiles + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.7 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ diff --git a/src/sys/vmm/vmminit.c b/src/sys/vmm/vmminit.c new file mode 100644 index 0000000..9709e33 --- /dev/null +++ b/src/sys/vmm/vmminit.c @@ -0,0 +1,64 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +*****************************************************************************************/ + +#include + +/***************************************************************************************** + + Function: int vmmInit() + + Description: Initializes the vmm subsystem + + Notes: + +*****************************************************************************************/ +int vmmInit() { + if (vmmMemMapInit() != 0x0) { + return (-1); + } + if (vmmPagingInit() != 0x0) { + return (-1); + } + return (0x0); + } + +/*** + $Log$ + Revision 1.2 2004/05/21 14:36:55 reddawg + Cleaned up + + Revision 1.1.1.1 2004/04/15 12:06:53 reddawg + UbixOS v1.0 + + Revision 1.4 2004/04/13 16:36:34 reddawg + Changed our copyright, it is all now under a BSD-Style license + + END + ***/ + diff --git a/src/tools/Makefile b/src/tools/Makefile new file mode 100644 index 0000000..87d03e4 --- /dev/null +++ b/src/tools/Makefile @@ -0,0 +1,70 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../Makefile.inc + +CC=gcc + +#Kernel File Name +BINARY = format + +#Objects +OBJS = format.o + +# Link the kernel statically with fixed text+data address @1M +$(BINARY) : $(OBJS) + $(CC) -o $@ $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) -Wall -fomit-frame-pointer -O -I../sys/include -c -o $@ $< + +.cc.s: + $(CXX) -Wall -fomit-frame-pointer -O -I../sys/include -S -o $@ $< + +.c.o: + $(CC) -Wall -O -c -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O -I../sys/include -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(BINARY) *.core + +format-dsk: + (cp ../sys/compile/ubix.elf ./) + (cp ../bin/init/init ./) + (cp ../bin/login/login ./) + (cp ../bin/shell/shell ./) + (cp ../bin/ls/ls ./) + (cp ../bin/clock/clock ./) + (cp ../lib/libc/libc.so ./) + (cp ../bin/fdisk/fdisk ./) + (cp ../bin/cp/cp ./) + #(cp ../bin/format/format ./) + (cp ../bin/ubistry/ubistry ./) + (cp ../sys/boot/mbr/mbr ./) + (cp ../bin/ld/ld.so ./) + (./format 50 2000 /dev/fd0 ubix.elf 0 login 3754 ROM8X14.DPF 3754 init 3754 ubistry 3754 shell 3754 userdb 3754 ls 3754 motd 3754 fdisk 3754 mbr 3754 cp 3754 clock 3754 libc.so 3754 ld.so 3754) + + #(./format 263 204361 /dev/md1 ubix.elf 0 format 3754 fdisk 3754 ROM8X14.DPF 3754 init 3754 login 3754 shell 3754 userdb 3754 ls 3754 motd 3754 cp 3754) + (./format 1064 2000 /dev/fd0 shell 3754 clock 3754) + #(./format 200 2000 /dev/md1 ubix.elf 0 shell 3754 motd 3754 libc.so 3754) + (rm -fr ubix.elf) + (rm -fr login) + (rm -fr init) + (rm -fr shell) + (rm -fr ls) + (rm -fr clock) + (rm -fr libc.so) + (rm -fr cp) + (rm -fr fdisk) + #(rm -fr format) + (rm -fr mbr) + (rm -fr ubistry) + (rm -fr ld.so) diff --git a/src/tools/OLDENG.DPF b/src/tools/OLDENG.DPF new file mode 100644 index 0000000..e542aca --- /dev/null +++ b/src/tools/OLDENG.DPF Binary files differ diff --git a/src/tools/PACMAN.DPF b/src/tools/PACMAN.DPF new file mode 100644 index 0000000..4db8522 --- /dev/null +++ b/src/tools/PACMAN.DPF Binary files differ diff --git a/src/tools/ROM8X14.DPF b/src/tools/ROM8X14.DPF new file mode 100644 index 0000000..376a5ef --- /dev/null +++ b/src/tools/ROM8X14.DPF Binary files differ diff --git a/src/tools/SCRIPT.DPF b/src/tools/SCRIPT.DPF new file mode 100755 index 0000000..8adf710 --- /dev/null +++ b/src/tools/SCRIPT.DPF Binary files differ diff --git a/src/tools/format.c b/src/tools/format.c new file mode 100644 index 0000000..7763c40 --- /dev/null +++ b/src/tools/format.c @@ -0,0 +1,156 @@ +#include +#include +#include +#include "./ubixfs.h" + +#define typeFile 1 +#define typeContainer 2 +#define typeDirectory 4 + + +//Michelle My Bell + +struct blockAllocationTableEntry *BAT = 0x0; + +int findFreeBlock(int cBlock,int size) { + int i = 0x0; + for (i=1;isize = (size/512); + partInfo->startSector = (startSector+1); + partInfo->blockAllocationTable = (startSector+1); + partInfo->rootDirectory = ((startSector+1) + (batSize/512)); + partInfo->rootDirectorySize = 0x4000/512; + fseek(driveFd,(startSector * 512),0); + fwrite(partInfo,512,1,driveFd); + startSector++; + dirEntry[0].attributes = typeDirectory; + dirEntry[0].permissions = 0xEAA; + dirEntry[0].gid = 0x0; + dirEntry[0].uid = 0x0; + dirEntry[0].startCluster = 0x0; + dirEntry[0].size = 0x4000; + sprintf(dirEntry[0].fileName,":"); + dirEntry[1].attributes = typeDirectory; + dirEntry[1].permissions = 0xEAA; + dirEntry[1].gid = 0x0; + dirEntry[1].uid = 0x0; + dirEntry[1].startCluster = 0x0; + dirEntry[1].size = 0x4000; + sprintf(dirEntry[1].fileName,".."); + BAT[0].nextBlock = 0x1; + BAT[0].attributes = 1; + BAT[0].realSector = (batSize/512); + BAT[1].nextBlock = 0x2; + BAT[1].attributes = 1; + BAT[1].realSector = ((batSize/512) + 1 * 8); + BAT[2].nextBlock = 0x3; + BAT[2].attributes = 1; + BAT[2].realSector = ((batSize/512) + 2 * 8); + BAT[3].nextBlock = -1; + BAT[3].attributes = 1; + BAT[3].realSector = ((batSize/512) + 3 * 8); + + for (i=4;i<(size/4096);i++) { + BAT[i].nextBlock = -1; + BAT[i].attributes = 0x0; + BAT[i].realSector = ((batSize/512) + (i*8)); + BAT[i].reserved = 0x0; + } + file = 0x2; + while (x < argc) { + counter = 0x0; + blockCount = 0x0; + fileFd = fopen(argv[x],"rb"); + block = findFreeBlock(-1,(size/4096)); + dirEntry[file].startCluster = block; + dirEntry[file].attributes = typeFile; + dirEntry[file].permissions = atoi(argv[x+1]); + rewind(driveFd); + /* fseek(driveFd,((BAT[startSector].realSector * 512) + ((batSize/512)+(BAT[block].realSector*4096))),0); */ + fseek(driveFd,((startSector + BAT[block].realSector) * 512),0); + while (!feof(fileFd)) { + if (4096 == (counter - (blockCount * 4096))) { + block = findFreeBlock(block,(size/4096)); + printf("Block: [%i][%s]\n",block,argv[x]); + rewind(driveFd); + /* fseek(driveFd,((startSector * 512) + ((batSize/512)+(BAT[block].realSector*4096))),0); */ + fseek(driveFd,((startSector + BAT[block].realSector) * 512),0); + blockCount++; + } + fputc(fgetc(fileFd),driveFd); + counter++; + } + i = 0; + while((counter + i)%512) { + fputc(0x0,driveFd); + i++; + } + fclose(fileFd); + dirEntry[file].size = (counter - 1); + dirEntry[file].uid = 0x0; + dirEntry[file].gid = 0x0; + sprintf(dirEntry[file].fileName,"%s",argv[x]); + x += 2; + file++; + } + dirEntry[1].attributes = typeDirectory; + dirEntry[1].permissions = 0xEAA; + dirEntry[1].gid = 0x0; + dirEntry[1].uid = 0x0; + dirEntry[1].startCluster = 0x0; + dirEntry[1].size = 0x4000; + sprintf(dirEntry[1].fileName,"fakeDir"); + rewind(driveFd); + fseek(driveFd,(long)(((startSector) * 512) + batSize),0); + fwrite(dirEntry,0x4000,1,driveFd); + rewind(driveFd); + fseek(driveFd,((startSector) * 512),0); + if (fwrite(BAT,batSize,1,driveFd) >= 1) { +/* + * printf("size [%i]\n",partInfo->size); + * printf("startSector: [%i]\n",partInfo->startSector); + * printf("bat: [%i]\n",partInfo->blockAllocationTable); + * printf("rootDir: [%i]\n",partInfo->rootDirectory); + * printf("sizeof: [%i]\n",sizeof(struct blockAllocationTableEntry)); + * printf("size: [%i]\n",(size/4096)); + */ + printf("Formatted!\n"); + } + else { + printf("Error Formatting!!\n"); + } + fclose(driveFd); + return(0); + } diff --git a/src/tools/fstab b/src/tools/fstab new file mode 100644 index 0000000..4e2a6e4 --- /dev/null +++ b/src/tools/fstab @@ -0,0 +1,3 @@ +fd0a@devfs,sys,ubixfs,rw +fd0b@devfs,tmp,ubixfs,rw +ad0a@devfs,hd,ubixfs,rw diff --git a/src/tools/makeuser.c b/src/tools/makeuser.c new file mode 100644 index 0000000..29d6ce5 --- /dev/null +++ b/src/tools/makeuser.c @@ -0,0 +1,52 @@ +#include + +struct passwd { + char username[32]; + char passwd[32]; + int uid; + int gid; + char shell[128]; + char realname[256]; + char path[256]; + }; + +int main(int argc,char **argv) { + int i = 0x0; + struct passwd *password = 0x0; + FILE *out; + password = (struct passwd *)malloc(4096); + out = fopen("./userdb","wbb"); + sprintf(password[0].username,"root"); + sprintf(password[0].passwd,"user"); + sprintf(password[0].shell,"shell@sys"); + sprintf(password[0].realname,"Root User"); + sprintf(password[0].path,"root"); + password[0].uid = 0; + password[0].gid = 0; + sprintf(password[1].username,"guest"); + sprintf(password[1].passwd,"user"); + sprintf(password[1].shell,"shell@sys"); + sprintf(password[1].realname,"Guest User"); + sprintf(password[1].path,"guest"); + password[1].uid = 1; + password[1].gid = 1; + sprintf(password[2].username,"reddawg"); + sprintf(password[2].passwd,"temp123"); + sprintf(password[2].shell,"shell@sys"); + sprintf(password[2].realname,"Christopher"); + sprintf(password[2].path,"reddawg"); + password[2].uid = 1000; + password[2].gid = 1000; + fwrite(password,4096,1,out); + fclose(out); + for (i=0;i<3;i++) { + printf("User: [%s]\n",password[i].username); + printf("Pass: [%s]\n",password[i].passwd); + printf("UID: [%i]\n",password[i].uid); + printf("GID: [%i]\n",password[i].gid); + printf("Shell: [%s]\n",password[i].shell); + printf("Name: [%s]\n",password[i].realname); + printf("Path: [%s]\n",password[i].path); + } + return(0); + } diff --git a/src/tools/mbr.img b/src/tools/mbr.img new file mode 100644 index 0000000..a574013 --- /dev/null +++ b/src/tools/mbr.img Binary files differ diff --git a/src/tools/motd b/src/tools/motd new file mode 100644 index 0000000..e09c887 --- /dev/null +++ b/src/tools/motd @@ -0,0 +1,9 @@ +Welcome to UbixOS + +This is an experimental kernel so it has the potential +to crash if it does please send us some info so we can +fix it or if you have access to the source fix it and +commit the changes. + +All reports can be sent to colsen@ubixos.com + diff --git a/src/tools/ubixfs.h b/src/tools/ubixfs.h new file mode 100644 index 0000000..ba8f525 --- /dev/null +++ b/src/tools/ubixfs.h @@ -0,0 +1,78 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + + $Id$ + +**************************************************************************************/ + +#ifndef _UBIXFS_H +#define _UBIXFS_H + +typedef unsigned long uLong; +typedef unsigned short uShort; +typedef unsigned char uChar; +typedef unsigned int uInt; + +//Partition Information +struct partitionInformation { + uLong size; //Size In Sectors + uLong startSector; //Base Sector Of Partition + uLong blockAllocationTable; //Base Sector Of BAT + uLong rootDirectory; //Base Sector Of Root Directory + uLong rootDirectorySize; /* Size In Sectors Of Root Directory */ + }; + +//Block Allocation Table Entry +struct blockAllocationTableEntry { + long attributes; //Block Attributes + long realSector; //Real Sector + long nextBlock; //Sector Of Next Block + long reserved; //Reserved + }; + +//UbixFS Directory Entry +struct directoryEntry { + uLong startCluster; //Starting Cluster Of File + uLong size; //Size Of File + uLong creationDate; //Date Created + uLong lastModified; //Date Last Modified + uLong uid; //UID Of Owner + uLong gid; //GID Of Owner + uShort attributes; //Files Attributes + uShort permissions; //Files Permissions + char fileName[256]; //File Name + }; + + +struct bootSect { + uChar jmp[4]; + uChar id[6]; + uShort version; + uShort tmp; + uShort fsStart; + uShort tmp2; + uLong krnl_start; + uInt BytesPerSector; + uInt SectersPerTrack; + uInt TotalHeads; + uLong TotalSectors; + uChar code[479]; + }; + +#endif diff --git a/src/tools/user.c b/src/tools/user.c new file mode 100644 index 0000000..4e89daf --- /dev/null +++ b/src/tools/user.c @@ -0,0 +1,31 @@ +#include + +struct passwd { + char username[32]; + char passwd[32]; + int uid; + int gid; + char shell[128]; + char realname[256]; + char path[256]; + }; + +int main(int argc,char **argv) { + int i = 0x0; + struct passwd *password = 0x0; + FILE *in; + password = (struct passwd *)malloc(4096); + in = fopen("./userdb","rb"); + fread(password,4096,1,in); + fclose(in); + for (i=0;i<3;i++) { + printf("User: [%s]\n",password[i].username); + printf("Pass: [%s]\n",password[i].passwd); + printf("UID: [%i]\n",password[i].uid); + printf("GID: [%i]\n",password[i].gid); + printf("Shell: [%s]\n",password[i].shell); + printf("Name: [%s]\n",password[i].realname); + printf("Path: [%s]\n",password[i].path); + } + return(0); + } diff --git a/src/tools/userdb b/src/tools/userdb new file mode 100644 index 0000000..2b1853e --- /dev/null +++ b/src/tools/userdb Binary files differ