ia64/xen-unstable

view extras/mini-os/include/lib.h @ 17042:a905c582a406

Add stubdomain support. See stubdom/README for usage details.

- Move PAGE_SIZE and STACK_SIZE into __PAGE_SIZE and __STACK_SIZE in
arch_limits.h so as to permit getting them from there without
pulling all the internal Mini-OS defines.
- Setup a xen-elf cross-compilation environment in stubdom/cross-root
- Add a POSIX layer on top of Mini-OS by linking against the newlib C
library and lwIP, and implementing the Unixish part in mini-os/lib/sys.c
- Cross-compile zlib and libpci too.
- Add an xs.h-compatible layer on top of Mini-OS' xenbus.
- Cross-compile libxc with an additional xc_minios.c and a few things
disabled.
- Cross-compile ioemu with an additional block-vbd, but without sound,
tpm and other details. A few hacks are needed:
- Align ide and scsi buffers at least on sector size to permit
direct transmission to the block backend. While we are at it, just
page-align it to possibly save a segment. Also, limit the scsi
buffer size because of limitations of the block paravirtualization
protocol.
- Allocate big tables dynamically rather that letting them go to
bss: when Mini-OS gets installed in memory, bss is not lazily
allocated, and doing so during Mini-OS is unnecessarily trick while
we can simply use malloc.
- Had to change the Mini-OS compilation somehow, so as to export
Mini-OS compilation flags to the Makefiles of libxc and ioemu.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Feb 12 14:35:39 2008 +0000 (2008-02-12)
parents 01e178f7ec6d
children 580bcd4c9642
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 ****************************************************************************
3 * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge
4 ****************************************************************************
5 *
6 * File: lib.h
7 * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
8 * Changes:
9 *
10 * Date: Aug 2003
11 *
12 * Environment: Xen Minimal OS
13 * Description: Random useful library functions, contains some freebsd stuff
14 *
15 ****************************************************************************
16 * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $
17 ****************************************************************************
18 *
19 *-
20 * Copyright (c) 1991, 1993
21 * The Regents of the University of California. All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * This product includes software developed by the University of
34 * California, Berkeley and its contributors.
35 * 4. Neither the name of the University nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 *
51 * @(#)stdarg.h 8.1 (Berkeley) 6/10/93
52 * $FreeBSD: src/sys/i386/include/stdarg.h,v 1.10 1999/08/28 00:44:26 peter Exp $
53 */
55 #ifndef _LIB_H_
56 #define _LIB_H_
58 #include <stdarg.h>
59 #include <stddef.h>
60 #include <xen/xen.h>
61 #include <xen/event_channel.h>
63 #ifdef HAVE_LIBC
64 #include <stdio.h>
65 #else
66 /* printing */
67 #define _p(_x) ((void *)(unsigned long)(_x))
68 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
69 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
70 int snprintf(char * buf, size_t size, const char *fmt, ...);
71 int scnprintf(char * buf, size_t size, const char *fmt, ...);
72 int vsprintf(char *buf, const char *fmt, va_list args);
73 int sprintf(char * buf, const char *fmt, ...);
74 int vsscanf(const char * buf, const char * fmt, va_list args);
75 int sscanf(const char * buf, const char * fmt, ...);
76 #endif
78 long simple_strtol(const char *cp,char **endp,unsigned int base);
79 unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);
80 long long simple_strtoll(const char *cp,char **endp,unsigned int base);
81 unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
83 #ifdef HAVE_LIBC
84 #include <string.h>
85 #else
86 /* string and memory manipulation */
87 int memcmp(const void *cs, const void *ct, size_t count);
88 void *memcpy(void *dest, const void *src, size_t count);
89 int strncmp(const char *cs, const char *ct, size_t count);
90 int strcmp(const char *cs, const char *ct);
91 char *strcpy(char *dest, const char *src);
92 char *strncpy(char *dest, const char *src, size_t count);
93 void *memset(void *s,int c, size_t count);
94 size_t strnlen(const char *s, size_t count);
95 size_t strlen(const char *s);
96 char *strchr(const char *s, int c);
97 char *strrchr(const char *s, int c);
98 char *strstr(const char *s1, const char *s2);
99 char * strcat(char * dest, const char * src);
100 char *strdup(const char *s);
101 #endif
102 #include <console.h>
104 #define RAND_MIX 2654435769U
106 int rand(void);
108 #include <xenbus.h>
110 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
112 struct kvec {
113 void *iov_base;
114 size_t iov_len;
115 };
117 #define ASSERT(x) \
118 do { \
119 if (!(x)) { \
120 printk("ASSERTION FAILED: %s at %s:%d.\n", \
121 # x , \
122 __FILE__, \
123 __LINE__); \
124 BUG(); \
125 } \
126 } while(0)
128 #define BUG_ON(x) ASSERT(!(x))
130 /* Consistency check as much as possible. */
131 void sanity_check(void);
133 #ifdef HAVE_LIBC
134 enum fd_type {
135 FTYPE_NONE = 0,
136 FTYPE_CONSOLE,
137 FTYPE_FILE,
138 FTYPE_XENBUS,
139 FTYPE_EVTCHN,
140 FTYPE_SOCKET,
141 FTYPE_TAP,
142 FTYPE_BLK,
143 };
145 #define MAX_EVTCHN_PORTS 16
147 extern struct file {
148 enum fd_type type;
149 union {
150 struct {
151 /* lwIP fd */
152 int fd;
153 } socket;
154 struct {
155 /* FS import fd */
156 int fd;
157 off_t offset;
158 } file;
159 struct {
160 /* To each event channel FD is associated a series of ports which
161 * wakes select for this FD. */
162 struct {
163 evtchn_port_t port;
164 volatile unsigned long pending;
165 int bound;
166 } ports[MAX_EVTCHN_PORTS];
167 } evtchn;
168 struct {
169 struct netfront_dev *dev;
170 } tap;
171 struct {
172 struct blkfront_dev *dev;
173 } blk;
174 struct {
175 /* To each xenbus FD is associated a queue of watch events for this
176 * FD. */
177 struct xenbus_event *volatile events;
178 } xenbus;
179 };
180 volatile int read; /* maybe available for read */
181 } files[];
183 int alloc_fd(enum fd_type type);
184 void close_all_files(void);
185 extern struct thread *main_thread;
186 #endif
188 #endif /* _LIB_H_ */