├── .gitignore ├── COPYING ├── Config.mk ├── Makefile ├── README ├── app.lds ├── arch └── x86 │ ├── Makefile │ ├── arch.mk │ ├── ioremap.c │ ├── iorw.c │ ├── minios-x86_32.lds │ ├── minios-x86_64.lds │ ├── mm.c │ ├── sched.c │ ├── setup.c │ ├── time.c │ ├── traps.c │ ├── x86_32.S │ └── x86_64.S ├── blkfront.c ├── console ├── console.c ├── console.h ├── xenbus.c └── xencons_ring.c ├── daytime.c ├── domain_config ├── events.c ├── fbfront.c ├── gntmap.c ├── gnttab.c ├── hypervisor.c ├── include ├── arch │ ├── cc.h │ ├── perf.h │ └── sys_arch.h ├── blkfront.h ├── byteorder.h ├── byteswap.h ├── console.h ├── ctype.h ├── endian.h ├── err.h ├── errno-base.h ├── errno.h ├── events.h ├── fbfront.h ├── fcntl.h ├── gntmap.h ├── gnttab.h ├── hypervisor.h ├── ioremap.h ├── iorw.h ├── kernel.h ├── lib-gpl.h ├── lib.h ├── linux │ └── types.h ├── lwip-net.h ├── lwipopts.h ├── mm.h ├── netfront.h ├── netfront_netmap.h ├── netmap.h ├── pcifront.h ├── posix │ ├── arpa │ │ └── inet.h │ ├── dirent.h │ ├── err.h │ ├── fcntl.h │ ├── limits.h │ ├── net │ │ └── if.h │ ├── netdb.h │ ├── netinet │ │ ├── in.h │ │ └── tcp.h │ ├── poll.h │ ├── pthread.h │ ├── signal.h │ ├── stdlib.h │ ├── strings.h │ ├── sys │ │ ├── ioctl.h │ │ ├── mman.h │ │ ├── poll.h │ │ ├── select.h │ │ ├── socket.h │ │ └── stat.h │ ├── syslog.h │ ├── termios.h │ ├── time.h │ └── unistd.h ├── rte_memcpy.h ├── rte_vect.h ├── sched.h ├── semaphore.h ├── shutdown.h ├── spinlock.h ├── sys │ ├── lock.h │ └── time.h ├── time.h ├── tpm_tis.h ├── tpmback.h ├── tpmfront.h ├── types.h ├── wait.h ├── waittypes.h ├── x86 │ ├── arch_endian.h │ ├── arch_limits.h │ ├── arch_mm.h │ ├── arch_sched.h │ ├── arch_spinlock.h │ ├── os.h │ ├── traps.h │ ├── x86_32 │ │ ├── arch_wordsize.h │ │ └── hypercall-x86_32.h │ └── x86_64 │ │ ├── arch_wordsize.h │ │ └── hypercall-x86_64.h ├── xen-features.h ├── xenbus.h └── xmalloc.h ├── kernel.c ├── lib ├── ctype.c ├── math.c ├── printf.c ├── stack_chk_fail.c ├── string.c ├── sys.c ├── xmalloc.c └── xs.c ├── lock.c ├── lwip-arch.c ├── lwip-net.c ├── main.c ├── minios.mk ├── mm.c ├── netfront.c ├── pcifront.c ├── sched.c ├── shutdown.c ├── stub.mk ├── test.c ├── tpm_tis.c ├── tpmback.c ├── tpmfront.c └── xenbus └── xenbus.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | 3 | include/list.h 4 | include/mini-os 5 | include/x86/mini-os 6 | include/xen 7 | 8 | arch/x86/libx86_64.a 9 | mini-os 10 | mini-os.gz 11 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Certain files in this directory are licensed by the GNU 2 | General Public License version 2 (GPLv2). By default these 3 | files are not built and linked into MiniOs. Enabling them 4 | will cause the whole work to become covered by the GPLv2. 5 | 6 | The current set of GPLv2 features are: 7 | CONFIG_TPMFRONT 8 | CONFIG_TPMBACK 9 | CONFIG_TPM_TIS 10 | 11 | Do not use these if you do not want your MiniOS build to become 12 | GPL licensed! 13 | 14 | Copyright (c) 2014, NEC Europe Ltd., NEC Corporation All rights reserved. 15 | 16 | Redistribution and use in source and binary forms, with or without 17 | modification, are permitted provided that the following conditions 18 | are met: 19 | 20 | 1. Redistributions of source code must retain the above copyright 21 | notice, this list of conditions and the following disclaimer. 22 | 2. Redistributions in binary form must reproduce the above copyright 23 | notice, this list of conditions and the following disclaimer in the 24 | documentation and/or other materials provided with the distribution. 25 | 3. Neither the name of the copyright holder nor the names of its 26 | contributors may be used to endorse or promote products derived from 27 | this software without specific prior written permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 30 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 33 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 | SUCH DAMAGE. 40 | 41 | Copyright (c) 2009 Citrix Systems, Inc. All rights reserved. 42 | 43 | Redistribution and use in source and binary forms, with or without 44 | modification, are permitted provided that the following conditions 45 | are met: 46 | 1. Redistributions of source code must retain the above copyright 47 | notice, this list of conditions and the following disclaimer. 48 | 2. Redistributions in binary form must reproduce the above copyright 49 | notice, this list of conditions and the following disclaimer in the 50 | documentation and/or other materials provided with the distribution. 51 | 52 | THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 53 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 | ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 56 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 | SUCH DAMAGE. 63 | 64 | -------------------------------------------------------------------------------- /Config.mk: -------------------------------------------------------------------------------- 1 | 2 | libc = $(stubdom) 3 | 4 | XEN_INTERFACE_VERSION := 0x00030205 5 | export XEN_INTERFACE_VERSION 6 | 7 | # Try to find out the architecture family TARGET_ARCH_FAM. 8 | # First check whether x86_... is contained (for x86_32, x86_32y, x86_64). 9 | # If not x86 then use $(XEN_TARGET_ARCH) 10 | ifeq ($(findstring x86_,$(XEN_TARGET_ARCH)),x86_) 11 | TARGET_ARCH_FAM = x86 12 | else 13 | TARGET_ARCH_FAM = $(XEN_TARGET_ARCH) 14 | endif 15 | 16 | # The architecture family directory below mini-os. 17 | TARGET_ARCH_DIR := arch/$(TARGET_ARCH_FAM) 18 | 19 | # Export these variables for possible use in architecture dependent makefiles. 20 | export TARGET_ARCH_DIR 21 | export TARGET_ARCH_FAM 22 | 23 | # This is used for architecture specific links. 24 | # This can be overwritten from arch specific rules. 25 | ARCH_LINKS = 26 | 27 | # The path pointing to the architecture specific header files. 28 | ARCH_INC := $(TARGET_ARCH_FAM) 29 | 30 | # For possible special header directories. 31 | # This can be overwritten from arch specific rules. 32 | EXTRA_INC = $(ARCH_INC) 33 | 34 | # Include the architecture family's special makerules. 35 | # This must be before include minios.mk! 36 | include $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk 37 | 38 | extra_incl := $(foreach dir,$(EXTRA_INC),-isystem $(MINI-OS_ROOT)/include/$(dir)) 39 | 40 | DEF_CPPFLAGS += -isystem $(MINI-OS_ROOT)/include 41 | DEF_CPPFLAGS += -D__MINIOS__ 42 | 43 | ifeq ($(libc),y) 44 | DEF_CPPFLAGS += -DHAVE_LIBC 45 | DEF_CPPFLAGS += -isystem $(MINI-OS_ROOT)/include/posix 46 | DEF_CPPFLAGS += -isystem $(XEN_ROOT)/tools/xenstore 47 | endif 48 | 49 | ifneq ($(LWIPDIR),) 50 | lwip=y 51 | DEF_CPPFLAGS += -DHAVE_LWIP 52 | DEF_CPPFLAGS += -isystem $(LWIPDIR)/src/include 53 | DEF_CPPFLAGS += -isystem $(LWIPDIR)/src/include/ipv4 54 | endif 55 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Common Makefile for mini-os. 2 | # 3 | # Every architecture directory below mini-os/arch has to have a 4 | # Makefile and a arch.mk. 5 | # 6 | 7 | # Define XEN root directory 8 | XEN_ROOT ?= $(CURDIR)/../.. 9 | export XEN_ROOT 10 | 11 | # Define MiniOS root directory 12 | MINI-OS_ROOT ?= $(CURDIR) 13 | export MINI-OS_ROOT 14 | 15 | include $(XEN_ROOT)/Config.mk 16 | OBJ_DIR ?= $(CURDIR) 17 | 18 | ifeq ($(MINIOS_CONFIG),) 19 | include Config.mk 20 | else 21 | EXTRA_DEPS += $(MINIOS_CONFIG) 22 | include $(MINIOS_CONFIG) 23 | endif 24 | 25 | # Configuration defaults 26 | CONFIG_START_NETWORK ?= y 27 | CONFIG_SPARSE_BSS ?= y 28 | CONFIG_QEMU_XS_ARGS ?= n 29 | CONFIG_TEST ?= n 30 | CONFIG_PCIFRONT ?= n 31 | CONFIG_BLKFRONT ?= y 32 | CONFIG_TPMFRONT ?= n 33 | CONFIG_TPM_TIS ?= n 34 | CONFIG_TPMBACK ?= n 35 | CONFIG_NETFRONT ?= y 36 | CONFIG_FBFRONT ?= y 37 | CONFIG_KBDFRONT ?= y 38 | CONFIG_CONSFRONT ?= y 39 | CONFIG_XENBUS ?= y 40 | CONFIG_XC ?=y 41 | CONFIG_LWIP ?= $(lwip) 42 | 43 | # Export config items as compiler directives 44 | flags-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK 45 | flags-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS 46 | flags-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS 47 | flags-$(CONFIG_PCIFRONT) += -DCONFIG_PCIFRONT 48 | flags-$(CONFIG_BLKFRONT) += -DCONFIG_BLKFRONT 49 | flags-$(CONFIG_TPMFRONT) += -DCONFIG_TPMFRONT 50 | flags-$(CONFIG_TPM_TIS) += -DCONFIG_TPM_TIS 51 | flags-$(CONFIG_TPMBACK) += -DCONFIG_TPMBACK 52 | flags-$(CONFIG_NETFRONT) += -DCONFIG_NETFRONT 53 | flags-$(CONFIG_KBDFRONT) += -DCONFIG_KBDFRONT 54 | flags-$(CONFIG_FBFRONT) += -DCONFIG_FBFRONT 55 | flags-$(CONFIG_CONSFRONT) += -DCONFIG_CONSFRONT 56 | flags-$(CONFIG_XENBUS) += -DCONFIG_XENBUS 57 | 58 | DEF_CFLAGS += $(flags-y) 59 | 60 | # Include common mini-os makerules. 61 | include minios.mk 62 | 63 | # Set tester flags 64 | # CFLAGS += -DBLKTEST_WRITE 65 | 66 | # Define some default flags for linking. 67 | LDLIBS := 68 | APP_LDLIBS := 69 | LDARCHLIB := -L$(OBJ_DIR)/$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME) 70 | LDFLAGS_FINAL := -T $(TARGET_ARCH_DIR)/minios-$(XEN_TARGET_ARCH).lds 71 | 72 | # Prefix for global API names. All other symbols are localised before 73 | # linking with EXTRA_OBJS. 74 | GLOBAL_PREFIX := xenos_ 75 | EXTRA_OBJS = 76 | 77 | TARGET := mini-os 78 | 79 | # Subdirectories common to mini-os 80 | SUBDIRS := lib xenbus console 81 | 82 | src-$(CONFIG_BLKFRONT) += blkfront.c 83 | src-$(CONFIG_TPMFRONT) += tpmfront.c 84 | src-$(CONFIG_TPM_TIS) += tpm_tis.c 85 | src-$(CONFIG_TPMBACK) += tpmback.c 86 | src-y += daytime.c 87 | src-y += events.c 88 | src-$(CONFIG_FBFRONT) += fbfront.c 89 | src-y += gntmap.c 90 | src-y += gnttab.c 91 | src-y += hypervisor.c 92 | src-y += kernel.c 93 | src-y += lock.c 94 | src-y += main.c 95 | src-y += mm.c 96 | src-$(CONFIG_NETFRONT) += netfront.c 97 | src-$(CONFIG_PCIFRONT) += pcifront.c 98 | src-y += sched.c 99 | src-y += shutdown.c 100 | src-$(CONFIG_TEST) += test.c 101 | 102 | src-y += lib/ctype.c 103 | src-y += lib/math.c 104 | src-y += lib/printf.c 105 | src-y += lib/stack_chk_fail.c 106 | src-y += lib/string.c 107 | src-y += lib/sys.c 108 | src-y += lib/xmalloc.c 109 | src-$(CONFIG_XENBUS) += lib/xs.c 110 | 111 | src-$(CONFIG_XENBUS) += xenbus/xenbus.c 112 | 113 | src-y += console/console.c 114 | src-y += console/xencons_ring.c 115 | src-$(CONFIG_CONSFRONT) += console/xenbus.c 116 | 117 | # The common mini-os objects to build. 118 | APP_OBJS := 119 | OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(src-y)) 120 | 121 | .PHONY: default 122 | default: $(OBJ_DIR)/$(TARGET) 123 | 124 | # Create special architecture specific links. The function arch_links 125 | # has to be defined in arch.mk (see include above). 126 | ifneq ($(ARCH_LINKS),) 127 | $(ARCH_LINKS): 128 | $(arch_links) 129 | endif 130 | 131 | include/list.h: $(XEN_ROOT)/tools/include/xen-external/bsd-sys-queue-h-seddery $(XEN_ROOT)/tools/include/xen-external/bsd-sys-queue.h 132 | perl $^ --prefix=minios >$@.new 133 | $(call move-if-changed,$@.new,$@) 134 | 135 | .PHONY: links 136 | links: include/list.h $(ARCH_LINKS) 137 | [ -e include/xen ] || ln -sf $(XEN_ROOT)/xen/include/public include/xen 138 | [ -e include/mini-os ] || ln -sf . include/mini-os 139 | [ -e include/$(TARGET_ARCH_FAM)/mini-os ] || ln -sf . include/$(TARGET_ARCH_FAM)/mini-os 140 | 141 | .PHONY: arch_lib 142 | arch_lib: 143 | $(MAKE) --directory=$(TARGET_ARCH_DIR) OBJ_DIR=$(OBJ_DIR)/$(TARGET_ARCH_DIR) || exit 1; 144 | 145 | ifeq ($(CONFIG_LWIP),y) 146 | # lwIP library 147 | LWC := $(shell find $(LWIPDIR)/src -type f -name '*.c') 148 | LWC := $(filter-out %6.c %ip6_addr.c %ethernetif.c, $(LWC)) 149 | LWO := $(patsubst %.c,%.o,$(LWC)) 150 | LWO += $(OBJ_DIR)/lwip-arch.o 151 | ifeq ($(CONFIG_NETFRONT),y) 152 | LWO += $(OBJ_DIR)/lwip-net.o 153 | endif 154 | 155 | $(OBJ_DIR)/lwip.a: $(LWO) 156 | $(RM) $@ 157 | $(AR) cqs $@ $^ 158 | 159 | OBJS += $(OBJ_DIR)/lwip.a 160 | endif 161 | 162 | OBJS := $(filter-out $(OBJ_DIR)/lwip%.o $(LWO), $(OBJS)) 163 | 164 | ifeq ($(libc),y) 165 | ifeq ($(CONFIG_XC),y) 166 | APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(XEN_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive 167 | endif 168 | APP_LDLIBS += -lpci 169 | APP_LDLIBS += -lz 170 | APP_LDLIBS += -lm 171 | LDLIBS += -lc 172 | endif 173 | 174 | ifneq ($(APP_OBJS)-$(lwip),-y) 175 | OBJS := $(filter-out $(OBJ_DIR)/daytime.o, $(OBJS)) 176 | endif 177 | 178 | $(OBJ_DIR)/$(TARGET)_app.o: $(APP_OBJS) app.lds 179 | $(LD) -r -d $(LDFLAGS) -\( $^ -\) $(APP_LDLIBS) --undefined main -o $@ 180 | 181 | ifneq ($(APP_OBJS),) 182 | APP_O=$(OBJ_DIR)/$(TARGET)_app.o 183 | endif 184 | 185 | $(OBJ_DIR)/$(TARGET): links include/list.h $(OBJS) $(APP_O) arch_lib 186 | $(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o $@.o 187 | $(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o 188 | $(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@ 189 | gzip -f -9 -c $@ >$@.gz 190 | 191 | .PHONY: clean arch_clean 192 | 193 | arch_clean: 194 | $(MAKE) --directory=$(TARGET_ARCH_DIR) OBJ_DIR=$(OBJ_DIR)/$(TARGET_ARCH_DIR) clean || exit 1; 195 | 196 | clean: arch_clean 197 | for dir in $(addprefix $(OBJ_DIR)/,$(SUBDIRS)); do \ 198 | rm -f $$dir/*.o; \ 199 | done 200 | rm -f include/list.h 201 | rm -f $(OBJ_DIR)/*.o *~ $(OBJ_DIR)/core $(OBJ_DIR)/$(TARGET).elf $(OBJ_DIR)/$(TARGET).raw $(OBJ_DIR)/$(TARGET) $(OBJ_DIR)/$(TARGET).gz 202 | find . $(OBJ_DIR) -type l | xargs rm -f 203 | $(RM) $(OBJ_DIR)/lwip.a $(LWO) 204 | rm -f tags TAGS 205 | 206 | 207 | define all_sources 208 | ( find . -follow -name SCCS -prune -o -name '*.[chS]' -print ) 209 | endef 210 | 211 | .PHONY: cscope 212 | cscope: 213 | $(all_sources) > cscope.files 214 | cscope -k -b -q 215 | 216 | .PHONY: tags 217 | tags: 218 | $(all_sources) | xargs ctags 219 | 220 | .PHONY: TAGS 221 | TAGS: 222 | $(all_sources) | xargs etags 223 | 224 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Minimal OS 2 | ---------- 3 | 4 | This shows some of the stuff that any guest OS will have to set up. 5 | 6 | This includes: 7 | 8 | * installing a virtual exception table 9 | * handling virtual exceptions 10 | * handling asynchronous events 11 | * enabling/disabling async events 12 | * parsing start_info struct at start-of-day 13 | * registering virtual interrupt handlers (for timer interrupts) 14 | * a simple page and memory allocator 15 | * minimal libc support 16 | * minimal Copy-on-Write support 17 | * network, block, framebuffer support 18 | * transparent access to FileSystem exports (see tools/fs-back) 19 | 20 | - to build it just type make. 21 | 22 | - to build it with TCP/IP support, download LWIP 1.3.2 source code and type 23 | 24 | make LWIPDIR=/path/to/lwip/source 25 | 26 | - to build it with much better libc support, see the stubdom/ directory 27 | 28 | - to start it do the following in domain0 (assuming xend is running) 29 | # xm create domain_config 30 | 31 | This starts the kernel and prints out a bunch of stuff and then once every 32 | second the system time. 33 | 34 | If you have setup a disk in the config file (e.g. 35 | disk = [ 'file:/tmp/foo,hda,r' ] ), it will loop reading it. If that disk is 36 | writable (e.g. disk = [ 'file:/tmp/foo,hda,w' ] ), it will write data patterns 37 | and re-read them. 38 | 39 | If you have setup a network in the config file (e.g. vif = [''] ), it will 40 | print incoming packets. 41 | 42 | If you have setup a VFB in the config file (e.g. vfb = ['type=sdl'] ), it will 43 | show a mouse with which you can draw color squares. 44 | 45 | If you have compiled it with TCP/IP support, it will run a daytime server on 46 | TCP port 13. 47 | -------------------------------------------------------------------------------- /app.lds: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .app.bss : { 4 | __app_bss_start = . ; 5 | *(.bss .bss.*) 6 | *(COMMON) 7 | *(.lbss .lbss.*) 8 | *(LARGE_COMMON) 9 | __app_bss_end = . ; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /arch/x86/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # x86 architecture specific makefiles. 3 | # It's is used for x86_32, x86_32y and x86_64 4 | # 5 | 6 | include $(XEN_ROOT)/Config.mk 7 | include ../../Config.mk 8 | 9 | # include arch.mk has to be before mini-os.mk! 10 | 11 | include arch.mk 12 | include ../../minios.mk 13 | 14 | # Sources here are all *.c *.S without $(XEN_TARGET_ARCH).S 15 | # This is handled in $(HEAD_ARCH_OBJ) 16 | ARCH_SRCS := $(wildcard *.c) 17 | 18 | # The objects built from the sources. 19 | ARCH_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(ARCH_SRCS)) 20 | 21 | all: $(OBJ_DIR)/$(ARCH_LIB) 22 | 23 | # $(HEAD_ARCH_OBJ) is only build here, needed on linking 24 | # in ../../Makefile. 25 | $(OBJ_DIR)/$(ARCH_LIB): $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ) 26 | $(AR) rv $(OBJ_DIR)/$(ARCH_LIB) $(ARCH_OBJS) 27 | 28 | clean: 29 | rm -f $(OBJ_DIR)/$(ARCH_LIB) $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ) 30 | 31 | -------------------------------------------------------------------------------- /arch/x86/arch.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Architecture special makerules for x86 family 3 | # (including x86_32, x86_32y and x86_64). 4 | # 5 | 6 | ifeq ($(XEN_TARGET_ARCH),x86_32) 7 | ARCH_CFLAGS := -m32 -march=i686 8 | ARCH_LDFLAGS := -m elf_i386 9 | ARCH_ASFLAGS := -m32 10 | EXTRA_INC += $(TARGET_ARCH_FAM)/$(XEN_TARGET_ARCH) 11 | EXTRA_SRC += arch/$(EXTRA_INC) 12 | endif 13 | 14 | ifeq ($(XEN_TARGET_ARCH),x86_64) 15 | ARCH_CFLAGS := -m64 -mno-red-zone -fno-reorder-blocks 16 | ARCH_CFLAGS += -fno-asynchronous-unwind-tables 17 | ARCH_ASFLAGS := -m64 18 | ARCH_LDFLAGS := -m elf_x86_64 19 | EXTRA_INC += $(TARGET_ARCH_FAM)/$(XEN_TARGET_ARCH) 20 | EXTRA_SRC += arch/$(EXTRA_INC) 21 | endif 22 | 23 | -------------------------------------------------------------------------------- /arch/x86/ioremap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009, Netronome Systems, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* Map a physical address range into virtual address space with provided 31 | * flags. Return a virtual address range it is mapped to. */ 32 | static void *__do_ioremap(unsigned long phys_addr, unsigned long size, 33 | unsigned long prot) 34 | { 35 | unsigned long va; 36 | unsigned long mfns, mfn; 37 | unsigned long num_pages, offset; 38 | 39 | /* allow non page aligned addresses but for mapping we need to align them */ 40 | offset = (phys_addr & ~PAGE_MASK); 41 | num_pages = (offset + size + PAGE_SIZE - 1) / PAGE_SIZE; 42 | phys_addr &= PAGE_MASK; 43 | mfns = mfn = phys_addr >> PAGE_SHIFT; 44 | 45 | va = (unsigned long)map_frames_ex(&mfns, num_pages, 0, 1, 1, 46 | DOMID_IO, NULL, prot); 47 | return (void *)(va + offset); 48 | } 49 | 50 | void *ioremap(unsigned long phys_addr, unsigned long size) 51 | { 52 | return __do_ioremap(phys_addr, size, IO_PROT); 53 | } 54 | 55 | void *ioremap_nocache(unsigned long phys_addr, unsigned long size) 56 | { 57 | return __do_ioremap(phys_addr, size, IO_PROT_NOCACHE); 58 | } 59 | 60 | /* Un-map the io-remapped region. Currently no list of existing mappings is 61 | * maintained, so the caller has to supply the size */ 62 | void iounmap(void *virt_addr, unsigned long size) 63 | { 64 | unsigned long num_pages; 65 | unsigned long va = (unsigned long)virt_addr; 66 | 67 | /* work out number of frames to unmap */ 68 | num_pages = ((va & ~PAGE_MASK) + size + PAGE_SIZE - 1) / PAGE_SIZE; 69 | 70 | unmap_frames(va & PAGE_MASK, num_pages); 71 | } 72 | 73 | 74 | 75 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 indent-tabs-mode:nil -*- */ 76 | -------------------------------------------------------------------------------- /arch/x86/iorw.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void iowrite8(volatile void* addr, uint8_t val) 4 | { 5 | *((volatile uint8_t*)addr) = val; 6 | } 7 | void iowrite16(volatile void* addr, uint16_t val) 8 | { 9 | *((volatile uint16_t*)addr) = val; 10 | } 11 | void iowrite32(volatile void* addr, uint32_t val) 12 | { 13 | *((volatile uint32_t*)addr) = val; 14 | } 15 | void iowrite64(volatile void* addr, uint64_t val) 16 | { 17 | *((volatile uint64_t*)addr) = val; 18 | } 19 | 20 | uint8_t ioread8(volatile void* addr) 21 | { 22 | return *((volatile uint8_t*) addr); 23 | } 24 | uint16_t ioread16(volatile void* addr) 25 | { 26 | return *((volatile uint16_t*) addr); 27 | } 28 | uint32_t ioread32(volatile void* addr) 29 | { 30 | return *((volatile uint32_t*) addr); 31 | } 32 | uint64_t ioread64(volatile void* addr) 33 | { 34 | return *((volatile uint64_t*) addr); 35 | } 36 | -------------------------------------------------------------------------------- /arch/x86/minios-x86_32.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") 2 | OUTPUT_ARCH(i386) 3 | ENTRY(_start) 4 | SECTIONS 5 | { 6 | . = 0x0; 7 | _text = .; /* Text and read-only data */ 8 | .text : { 9 | *(.text) 10 | *(.gnu.warning) 11 | } = 0x9090 12 | 13 | _etext = .; /* End of text section */ 14 | 15 | .rodata : { *(.rodata) *(.rodata.*) } 16 | . = ALIGN(4096); 17 | _erodata = .; 18 | 19 | /* newlib initialization functions */ 20 | . = ALIGN(32 / 8); 21 | PROVIDE (__preinit_array_start = .); 22 | .preinit_array : { *(.preinit_array) } 23 | PROVIDE (__preinit_array_end = .); 24 | PROVIDE (__init_array_start = .); 25 | .init_array : { *(.init_array) } 26 | PROVIDE (__init_array_end = .); 27 | PROVIDE (__fini_array_start = .); 28 | .fini_array : { *(.fini_array) } 29 | PROVIDE (__fini_array_end = .); 30 | 31 | .ctors : { 32 | __CTOR_LIST__ = .; 33 | *(.ctors) 34 | CONSTRUCTORS 35 | LONG(0) 36 | __CTOR_END__ = .; 37 | } 38 | 39 | .dtors : { 40 | __DTOR_LIST__ = .; 41 | *(.dtors) 42 | LONG(0) 43 | __DTOR_END__ = .; 44 | } 45 | 46 | .data : { /* Data */ 47 | *(.data) 48 | } 49 | 50 | _edata = .; /* End of data section */ 51 | 52 | __bss_start = .; /* BSS */ 53 | .bss : { 54 | *(.bss) 55 | *(.app.bss) 56 | } 57 | _end = . ; 58 | 59 | /* Sections to be discarded */ 60 | /DISCARD/ : { 61 | *(.text.exit) 62 | *(.data.exit) 63 | *(.exitcall.exit) 64 | } 65 | 66 | /* Stabs debugging sections. */ 67 | .stab 0 : { *(.stab) } 68 | .stabstr 0 : { *(.stabstr) } 69 | .stab.excl 0 : { *(.stab.excl) } 70 | .stab.exclstr 0 : { *(.stab.exclstr) } 71 | .stab.index 0 : { *(.stab.index) } 72 | .stab.indexstr 0 : { *(.stab.indexstr) } 73 | .comment 0 : { *(.comment) } 74 | } 75 | -------------------------------------------------------------------------------- /arch/x86/minios-x86_64.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") 2 | OUTPUT_ARCH(i386:x86-64) 3 | ENTRY(_start) 4 | SECTIONS 5 | { 6 | . = 0x0; 7 | _text = .; /* Text and read-only data */ 8 | .text : { 9 | *(.text) 10 | *(.gnu.warning) 11 | } = 0x9090 12 | 13 | _etext = .; /* End of text section */ 14 | 15 | .rodata : { *(.rodata) *(.rodata.*) } 16 | . = ALIGN(4096); 17 | _erodata = .; 18 | 19 | /* newlib initialization functions */ 20 | . = ALIGN(64 / 8); 21 | PROVIDE (__preinit_array_start = .); 22 | .preinit_array : { *(.preinit_array) } 23 | PROVIDE (__preinit_array_end = .); 24 | PROVIDE (__init_array_start = .); 25 | .init_array : { *(.init_array) } 26 | PROVIDE (__init_array_end = .); 27 | PROVIDE (__fini_array_start = .); 28 | .fini_array : { *(.fini_array) } 29 | PROVIDE (__fini_array_end = .); 30 | 31 | .ctors : { 32 | __CTOR_LIST__ = .; 33 | *(.ctors) 34 | CONSTRUCTORS 35 | QUAD(0) 36 | __CTOR_END__ = .; 37 | } 38 | 39 | .dtors : { 40 | __DTOR_LIST__ = .; 41 | *(.dtors) 42 | QUAD(0) 43 | __DTOR_END__ = .; 44 | } 45 | 46 | .data : { /* Data */ 47 | *(.data) 48 | } 49 | 50 | _edata = .; /* End of data section */ 51 | 52 | __bss_start = .; /* BSS */ 53 | .bss : { 54 | *(.bss) 55 | *(.app.bss) 56 | } 57 | _end = . ; 58 | 59 | /* Sections to be discarded */ 60 | /DISCARD/ : { 61 | *(.text.exit) 62 | *(.data.exit) 63 | *(.exitcall.exit) 64 | } 65 | 66 | /* Stabs debugging sections. */ 67 | .stab 0 : { *(.stab) } 68 | .stabstr 0 : { *(.stabstr) } 69 | .stab.excl 0 : { *(.stab.excl) } 70 | .stab.exclstr 0 : { *(.stab.exclstr) } 71 | .stab.index 0 : { *(.stab.index) } 72 | .stab.indexstr 0 : { *(.stab.indexstr) } 73 | .comment 0 : { *(.comment) } 74 | } 75 | -------------------------------------------------------------------------------- /arch/x86/sched.c: -------------------------------------------------------------------------------- 1 | /* 2 | **************************************************************************** 3 | * (C) 2005 - Grzegorz Milos - Intel Research Cambridge 4 | **************************************************************************** 5 | * 6 | * File: sched.c 7 | * Author: Grzegorz Milos 8 | * Changes: Robert Kaiser 9 | * 10 | * Date: Aug 2005 11 | * 12 | * Environment: Xen Minimal OS 13 | * Description: simple scheduler for Mini-Os 14 | * 15 | * The scheduler is non-preemptive (cooperative), and schedules according 16 | * to Round Robin algorithm. 17 | * 18 | **************************************************************************** 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy 20 | * of this software and associated documentation files (the "Software"), to 21 | * deal in the Software without restriction, including without limitation the 22 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 23 | * sell copies of the Software, and to permit persons to whom the Software is 24 | * furnished to do so, subject to the following conditions: 25 | * 26 | * The above copyright notice and this permission notice shall be included in 27 | * all copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 34 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 35 | * DEALINGS IN THE SOFTWARE. 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | 50 | #ifdef SCHED_DEBUG 51 | #define DEBUG(_f, _a...) \ 52 | printk("MINI_OS(file=sched.c, line=%d) " _f "\n", __LINE__, ## _a) 53 | #else 54 | #define DEBUG(_f, _a...) ((void)0) 55 | #endif 56 | 57 | 58 | void dump_stack(struct thread *thread) 59 | { 60 | unsigned long *bottom = (unsigned long *)(thread->stack + STACK_SIZE); 61 | unsigned long *pointer = (unsigned long *)thread->sp; 62 | int count; 63 | if(thread == current) 64 | { 65 | #ifdef __i386__ 66 | asm("movl %%esp,%0" 67 | : "=r"(pointer)); 68 | #else 69 | asm("movq %%rsp,%0" 70 | : "=r"(pointer)); 71 | #endif 72 | } 73 | printk("The stack for \"%s\"\n", thread->name); 74 | for(count = 0; count < 25 && pointer < bottom; count ++) 75 | { 76 | printk("[0x%lx] 0x%lx\n", pointer, *pointer); 77 | pointer++; 78 | } 79 | 80 | if(pointer < bottom) printk(" ... continues.\n"); 81 | } 82 | 83 | /* Gets run when a new thread is scheduled the first time ever, 84 | defined in x86_[32/64].S */ 85 | extern void thread_starter(void); 86 | 87 | /* Pushes the specified value onto the stack of the specified thread */ 88 | static void stack_push(struct thread *thread, unsigned long value) 89 | { 90 | thread->sp -= sizeof(unsigned long); 91 | *((unsigned long *)thread->sp) = value; 92 | } 93 | 94 | /* Architecture specific setup of thread creation */ 95 | struct thread* arch_create_thread(char *name, void (*function)(void *), 96 | void *data) 97 | { 98 | struct thread *thread; 99 | 100 | thread = xmalloc(struct thread); 101 | /* We can't use lazy allocation here since the trap handler runs on the stack */ 102 | thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER); 103 | thread->name = name; 104 | printk("Thread \"%s\": pointer: 0x%lx, stack: 0x%lx\n", name, thread, 105 | thread->stack); 106 | 107 | thread->sp = (unsigned long)thread->stack + STACK_SIZE; 108 | /* Save pointer to the thread on the stack, used by current macro */ 109 | *((unsigned long *)thread->stack) = (unsigned long)thread; 110 | 111 | stack_push(thread, (unsigned long) function); 112 | stack_push(thread, (unsigned long) data); 113 | thread->ip = (unsigned long) thread_starter; 114 | return thread; 115 | } 116 | 117 | void run_idle_thread(void) 118 | { 119 | /* Switch stacks and run the thread */ 120 | #if defined(__i386__) 121 | __asm__ __volatile__("mov %0,%%esp\n\t" 122 | "push %1\n\t" 123 | "ret" 124 | :"=m" (idle_thread->sp) 125 | :"m" (idle_thread->ip)); 126 | #elif defined(__x86_64__) 127 | __asm__ __volatile__("mov %0,%%rsp\n\t" 128 | "push %1\n\t" 129 | "ret" 130 | :"=m" (idle_thread->sp) 131 | :"m" (idle_thread->ip)); 132 | #endif 133 | } 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /arch/x86/setup.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * common.c 3 | * 4 | * Common stuff special to x86 goes here. 5 | * 6 | * Copyright (c) 2002-2003, K A Fraser & R Neugebauer 7 | * Copyright (c) 2005, Grzegorz Milos, Intel Research Cambridge 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to 11 | * deal in the Software without restriction, including without limitation the 12 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 13 | * sell copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | * DEALINGS IN THE SOFTWARE. 26 | * 27 | */ 28 | 29 | #include 30 | #include /* for printk, memcpy */ 31 | 32 | /* 33 | * Shared page for communicating with the hypervisor. 34 | * Events flags go here, for example. 35 | */ 36 | shared_info_t *HYPERVISOR_shared_info; 37 | 38 | /* 39 | * This pointer holds a reference to the copy of the start_info struct. 40 | */ 41 | static start_info_t *start_info_ptr; 42 | 43 | /* 44 | * This structure contains start-of-day info, such as pagetable base pointer, 45 | * address of the shared_info structure, and things like that. 46 | */ 47 | union start_info_union start_info_union; 48 | 49 | /* 50 | * Just allocate the kernel stack here. SS:ESP is set up to point here 51 | * in head.S. 52 | */ 53 | char stack[2*STACK_SIZE]; 54 | 55 | extern char shared_info[PAGE_SIZE]; 56 | 57 | /* Assembler interface fns in entry.S. */ 58 | void hypervisor_callback(void); 59 | void failsafe_callback(void); 60 | 61 | #if defined(__x86_64__) 62 | #define __pte(x) ((pte_t) { (x) } ) 63 | #else 64 | #define __pte(x) ({ unsigned long long _x = (x); \ 65 | ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) 66 | #endif 67 | 68 | static 69 | shared_info_t *map_shared_info(unsigned long pa) 70 | { 71 | int rc; 72 | 73 | if (!xen_feature(XENFEAT_auto_translated_physmap)) { 74 | if ( (rc = HYPERVISOR_update_va_mapping( 75 | (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG)) ) 76 | { 77 | printk("Failed to map shared_info!! rc=%d\n", rc); 78 | do_exit(); 79 | } 80 | return (shared_info_t *)shared_info; 81 | } 82 | else 83 | return (shared_info_t *)to_virt(start_info.shared_info); 84 | } 85 | 86 | static 87 | void unmap_shared_info(void) 88 | { 89 | int rc; 90 | 91 | if ( (rc = HYPERVISOR_update_va_mapping((unsigned long)HYPERVISOR_shared_info, 92 | __pte((virt_to_mfn(shared_info)<store_mfn = 161 | machine_to_phys_mapping[start_info_ptr->store_mfn]; 162 | start_info_ptr->console.domU.mfn = 163 | machine_to_phys_mapping[start_info_ptr->console.domU.mfn]; 164 | 165 | } 166 | 167 | void 168 | arch_post_suspend(int canceled) 169 | { 170 | if (canceled) { 171 | start_info_ptr->store_mfn = pfn_to_mfn(start_info_ptr->store_mfn); 172 | start_info_ptr->console.domU.mfn = pfn_to_mfn(start_info_ptr->console.domU.mfn); 173 | } else { 174 | memcpy(&start_info, start_info_ptr, sizeof(start_info_t)); 175 | } 176 | 177 | HYPERVISOR_shared_info = map_shared_info(start_info_ptr->shared_info); 178 | 179 | arch_mm_post_suspend(canceled); 180 | } 181 | 182 | void 183 | arch_fini(void) 184 | { 185 | #ifdef __i386__ 186 | HYPERVISOR_set_callbacks(0, 0, 0, 0); 187 | #else 188 | HYPERVISOR_set_callbacks(0, 0, 0); 189 | #endif 190 | } 191 | 192 | void 193 | arch_print_info(void) 194 | { 195 | printk(" stack: %p-%p\n", stack, stack + sizeof(stack)); 196 | } 197 | 198 | 199 | -------------------------------------------------------------------------------- /console/console.c: -------------------------------------------------------------------------------- 1 | /* 2 | **************************************************************************** 3 | * (C) 2006 - Grzegorz Milos - Cambridge University 4 | **************************************************************************** 5 | * 6 | * File: console.h 7 | * Author: Grzegorz Milos 8 | * Changes: 9 | * 10 | * Date: Mar 2006 11 | * 12 | * Environment: Xen Minimal OS 13 | * Description: Console interface. 14 | * 15 | * Handles console I/O. Defines printk. 16 | * 17 | **************************************************************************** 18 | * Permission is hereby granted, free of charge, to any person obtaining a copy 19 | * of this software and associated documentation files (the "Software"), to 20 | * deal in the Software without restriction, including without limitation the 21 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 22 | * sell copies of the Software, and to permit persons to whom the Software is 23 | * furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included in 26 | * all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34 | * DEALINGS IN THE SOFTWARE. 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | 49 | /* Copies all print output to the Xen emergency console apart 50 | of standard dom0 handled console */ 51 | #define USE_XEN_CONSOLE 52 | 53 | 54 | /* If console not initialised the printk will be sent to xen serial line 55 | NOTE: you need to enable verbose in xen/Rules.mk for it to work. */ 56 | static int console_initialised = 0; 57 | 58 | __attribute__((weak)) void console_input(char * buf, unsigned len) 59 | { 60 | if(len > 0) 61 | { 62 | /* Just repeat what's written */ 63 | buf[len] = '\0'; 64 | printk("%s", buf); 65 | 66 | if(buf[len-1] == '\r') 67 | printk("\nNo console input handler.\n"); 68 | } 69 | } 70 | 71 | #ifndef HAVE_LIBC 72 | void xencons_rx(char *buf, unsigned len, struct pt_regs *regs) 73 | { 74 | console_input(buf, len); 75 | } 76 | 77 | void xencons_tx(void) 78 | { 79 | /* Do nothing, handled by _rx */ 80 | } 81 | #endif 82 | 83 | 84 | #ifdef CONFIG_CONSFRONT_SYNC 85 | static inline int ring_send_sync(int (*ring_send_fn)(struct consfront_dev *dev, const char *data, unsigned len), 86 | struct consfront_dev *dev, const char *data, unsigned len) 87 | { 88 | unsigned shift = 0; 89 | int ret = 0; 90 | 91 | /* busy loop until all data has been sent out */ 92 | while (len) { 93 | ret = ring_send_fn(dev, (data + shift), len); 94 | if (ret < 0) 95 | return -1; 96 | shift += ret; 97 | len -= ret; 98 | } 99 | return 0; 100 | } 101 | #endif 102 | 103 | void console_print(struct consfront_dev *dev, char *data, int length) 104 | { 105 | char *curr_char, saved_char; 106 | char copied_str[length+1]; 107 | char *copied_ptr; 108 | int part_len; 109 | int (*ring_send_fn)(struct consfront_dev *dev, const char *data, unsigned length); 110 | 111 | if(!console_initialised) 112 | ring_send_fn = xencons_ring_send_no_notify; 113 | else 114 | ring_send_fn = xencons_ring_send; 115 | 116 | copied_ptr = copied_str; 117 | memcpy(copied_ptr, data, length); 118 | for(curr_char = copied_ptr; curr_char < copied_ptr+length-1; curr_char++) 119 | { 120 | if(*curr_char == '\n') 121 | { 122 | *curr_char = '\r'; 123 | saved_char = *(curr_char+1); 124 | *(curr_char+1) = '\n'; 125 | part_len = curr_char - copied_ptr + 2; 126 | #ifdef CONFIG_CONSFRONT_SYNC 127 | ring_send_sync(ring_send_fn, dev, copied_ptr, part_len); 128 | #else 129 | ring_send_fn(dev, copied_ptr, part_len); 130 | #endif 131 | *(curr_char+1) = saved_char; 132 | copied_ptr = curr_char+1; 133 | length -= part_len - 1; 134 | } 135 | } 136 | 137 | if (copied_ptr[length-1] == '\n') { 138 | copied_ptr[length-1] = '\r'; 139 | copied_ptr[length] = '\n'; 140 | length++; 141 | } 142 | 143 | #ifdef CONFIG_CONSFRONT_SYNC 144 | ring_send_sync(ring_send_fn, dev, copied_ptr, length); 145 | #else 146 | ring_send_fn(dev, copied_ptr, length); 147 | #endif 148 | } 149 | 150 | void print(int direct, const char *fmt, va_list args) 151 | { 152 | static char buf[1024]; 153 | 154 | (void)vsnprintf(buf, sizeof(buf), fmt, args); 155 | 156 | if(direct) 157 | { 158 | (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf); 159 | return; 160 | } else { 161 | #ifndef USE_XEN_CONSOLE 162 | if(!console_initialised) 163 | #endif 164 | (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf); 165 | 166 | console_print(NULL, buf, strlen(buf)); 167 | } 168 | } 169 | 170 | void printk(const char *fmt, ...) 171 | { 172 | va_list args; 173 | va_start(args, fmt); 174 | print(0, fmt, args); 175 | va_end(args); 176 | } 177 | 178 | void xprintk(const char *fmt, ...) 179 | { 180 | va_list args; 181 | va_start(args, fmt); 182 | print(1, fmt, args); 183 | va_end(args); 184 | } 185 | void init_console(void) 186 | { 187 | printk("Initialising console ... "); 188 | xencons_ring_init(); 189 | console_initialised = 1; 190 | /* This is also required to notify the daemon */ 191 | printk("done.\n"); 192 | } 193 | 194 | void suspend_console(void) 195 | { 196 | console_initialised = 0; 197 | xencons_ring_fini(NULL); 198 | } 199 | 200 | void resume_console(void) 201 | { 202 | xencons_ring_resume(NULL); 203 | console_initialised = 1; 204 | } 205 | -------------------------------------------------------------------------------- /console/console.h: -------------------------------------------------------------------------------- 1 | 2 | void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data); 3 | -------------------------------------------------------------------------------- /console/xenbus.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "console.h" 15 | 16 | void free_consfront(struct consfront_dev *dev) 17 | { 18 | char* err = NULL; 19 | XenbusState state; 20 | 21 | char path[strlen(dev->backend) + strlen("/state") + 1]; 22 | char nodename[strlen(dev->nodename) + strlen("/state") + 1]; 23 | 24 | snprintf(path, sizeof(path), "%s/state", dev->backend); 25 | snprintf(nodename, sizeof(nodename), "%s/state", dev->nodename); 26 | 27 | if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosing)) != NULL) { 28 | printk("free_consfront: error changing state to %d: %s\n", 29 | XenbusStateClosing, err); 30 | goto close; 31 | } 32 | state = xenbus_read_integer(path); 33 | while (err == NULL && state < XenbusStateClosing) 34 | err = xenbus_wait_for_state_change(path, &state, &dev->events); 35 | free(err); 36 | 37 | if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != NULL) { 38 | printk("free_consfront: error changing state to %d: %s\n", 39 | XenbusStateClosed, err); 40 | goto close; 41 | } 42 | 43 | close: 44 | free(err); 45 | err = xenbus_unwatch_path_token(XBT_NIL, path, path); 46 | free(err); 47 | 48 | mask_evtchn(dev->evtchn); 49 | unbind_evtchn(dev->evtchn); 50 | free(dev->backend); 51 | free(dev->nodename); 52 | 53 | gnttab_end_access(dev->ring_ref); 54 | 55 | free_page(dev->ring); 56 | free(dev); 57 | } 58 | 59 | struct consfront_dev *init_consfront(char *_nodename) 60 | { 61 | xenbus_transaction_t xbt; 62 | char* err = NULL; 63 | char* message=NULL; 64 | int retry=0; 65 | char* msg = NULL; 66 | char nodename[256]; 67 | char path[256]; 68 | static int consfrontends = 3; 69 | struct consfront_dev *dev; 70 | int res; 71 | 72 | if (!_nodename) 73 | snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends); 74 | else { 75 | strncpy(nodename, _nodename, sizeof(nodename) - 1); 76 | nodename[sizeof(nodename) - 1] = 0; 77 | } 78 | 79 | printk("******************* CONSFRONT for %s **********\n\n\n", nodename); 80 | 81 | consfrontends++; 82 | dev = malloc(sizeof(*dev)); 83 | memset(dev, 0, sizeof(*dev)); 84 | dev->nodename = strdup(nodename); 85 | #ifdef HAVE_LIBC 86 | dev->fd = -1; 87 | #endif 88 | 89 | snprintf(path, sizeof(path), "%s/backend-id", nodename); 90 | if ((res = xenbus_read_integer(path)) < 0) 91 | goto error; 92 | else 93 | dev->dom = res; 94 | evtchn_alloc_unbound(dev->dom, console_handle_input, dev, &dev->evtchn); 95 | 96 | dev->ring = (struct xencons_interface *) alloc_page(); 97 | memset(dev->ring, 0, PAGE_SIZE); 98 | dev->ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(dev->ring), 0); 99 | 100 | dev->events = NULL; 101 | 102 | again: 103 | err = xenbus_transaction_start(&xbt); 104 | if (err) { 105 | printk("starting transaction\n"); 106 | free(err); 107 | } 108 | 109 | err = xenbus_printf(xbt, nodename, "ring-ref","%u", 110 | dev->ring_ref); 111 | if (err) { 112 | message = "writing ring-ref"; 113 | goto abort_transaction; 114 | } 115 | err = xenbus_printf(xbt, nodename, 116 | "port", "%u", dev->evtchn); 117 | if (err) { 118 | message = "writing event-channel"; 119 | goto abort_transaction; 120 | } 121 | err = xenbus_printf(xbt, nodename, 122 | "protocol", "%s", XEN_IO_PROTO_ABI_NATIVE); 123 | if (err) { 124 | message = "writing protocol"; 125 | goto abort_transaction; 126 | } 127 | 128 | snprintf(path, sizeof(path), "%s/state", nodename); 129 | err = xenbus_switch_state(xbt, path, XenbusStateConnected); 130 | if (err) { 131 | message = "switching state"; 132 | goto abort_transaction; 133 | } 134 | 135 | 136 | err = xenbus_transaction_end(xbt, 0, &retry); 137 | free(err); 138 | if (retry) { 139 | goto again; 140 | printk("completing transaction\n"); 141 | } 142 | 143 | goto done; 144 | 145 | abort_transaction: 146 | free(err); 147 | err = xenbus_transaction_end(xbt, 1, &retry); 148 | printk("Abort transaction %s\n", message); 149 | goto error; 150 | 151 | done: 152 | 153 | snprintf(path, sizeof(path), "%s/backend", nodename); 154 | msg = xenbus_read(XBT_NIL, path, &dev->backend); 155 | if (msg) { 156 | printk("Error %s when reading the backend path %s\n", msg, path); 157 | goto error; 158 | } 159 | 160 | printk("backend at %s\n", dev->backend); 161 | 162 | { 163 | XenbusState state; 164 | char path[strlen(dev->backend) + strlen("/state") + 1]; 165 | snprintf(path, sizeof(path), "%s/state", dev->backend); 166 | 167 | xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); 168 | msg = NULL; 169 | state = xenbus_read_integer(path); 170 | while (msg == NULL && state < XenbusStateConnected) 171 | msg = xenbus_wait_for_state_change(path, &state, &dev->events); 172 | if (msg != NULL || state != XenbusStateConnected) { 173 | printk("backend not available, state=%d\n", state); 174 | err = xenbus_unwatch_path_token(XBT_NIL, path, path); 175 | goto error; 176 | } 177 | } 178 | unmask_evtchn(dev->evtchn); 179 | 180 | printk("**************************\n"); 181 | 182 | return dev; 183 | 184 | error: 185 | free(msg); 186 | free(err); 187 | free_consfront(dev); 188 | return NULL; 189 | } 190 | 191 | void fini_console(struct consfront_dev *dev) 192 | { 193 | if (dev) free_consfront(dev); 194 | } 195 | 196 | -------------------------------------------------------------------------------- /console/xencons_ring.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "console.h" 15 | 16 | DECLARE_WAIT_QUEUE_HEAD(console_queue); 17 | 18 | static inline void notify_daemon(struct consfront_dev *dev) 19 | { 20 | /* Use evtchn: this is called early, before irq is set up. */ 21 | if (!dev) 22 | notify_remote_via_evtchn(start_info.console.domU.evtchn); 23 | else 24 | notify_remote_via_evtchn(dev->evtchn); 25 | } 26 | 27 | static inline struct xencons_interface *xencons_interface(void) 28 | { 29 | if (start_info.console.domU.evtchn) 30 | return mfn_to_virt(start_info.console.domU.mfn); 31 | else 32 | return NULL; 33 | } 34 | 35 | int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len) 36 | { 37 | int sent = 0; 38 | struct xencons_interface *intf; 39 | XENCONS_RING_IDX cons, prod; 40 | 41 | if (!dev) 42 | intf = xencons_interface(); 43 | else 44 | intf = dev->ring; 45 | if (!intf) 46 | return sent; 47 | 48 | cons = intf->out_cons; 49 | prod = intf->out_prod; 50 | mb(); 51 | BUG_ON((prod - cons) > sizeof(intf->out)); 52 | 53 | while ((sent < len) && ((prod - cons) < sizeof(intf->out))) 54 | intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; 55 | 56 | wmb(); 57 | intf->out_prod = prod; 58 | 59 | return sent; 60 | } 61 | 62 | int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len) 63 | { 64 | int sent; 65 | 66 | sent = xencons_ring_send_no_notify(dev, data, len); 67 | notify_daemon(dev); 68 | 69 | return sent; 70 | } 71 | 72 | 73 | 74 | void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data) 75 | { 76 | struct consfront_dev *dev = (struct consfront_dev *) data; 77 | #ifdef HAVE_LIBC 78 | int fd = dev ? dev->fd : -1; 79 | 80 | if (fd != -1) 81 | files[fd].read = 1; 82 | 83 | wake_up(&console_queue); 84 | #else 85 | struct xencons_interface *intf = xencons_interface(); 86 | XENCONS_RING_IDX cons, prod; 87 | 88 | cons = intf->in_cons; 89 | prod = intf->in_prod; 90 | mb(); 91 | BUG_ON((prod - cons) > sizeof(intf->in)); 92 | 93 | while (cons != prod) { 94 | xencons_rx(intf->in+MASK_XENCONS_IDX(cons,intf->in), 1, regs); 95 | cons++; 96 | } 97 | 98 | mb(); 99 | intf->in_cons = cons; 100 | 101 | notify_daemon(dev); 102 | 103 | xencons_tx(); 104 | #endif 105 | } 106 | 107 | #ifdef HAVE_LIBC 108 | int xencons_ring_avail(struct consfront_dev *dev) 109 | { 110 | struct xencons_interface *intf; 111 | XENCONS_RING_IDX cons, prod; 112 | 113 | if (!dev) 114 | intf = xencons_interface(); 115 | else 116 | intf = dev->ring; 117 | 118 | cons = intf->in_cons; 119 | prod = intf->in_prod; 120 | mb(); 121 | BUG_ON((prod - cons) > sizeof(intf->in)); 122 | 123 | return prod - cons; 124 | } 125 | 126 | int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len) 127 | { 128 | struct xencons_interface *intf; 129 | XENCONS_RING_IDX cons, prod; 130 | unsigned filled = 0; 131 | 132 | if (!dev) 133 | intf = xencons_interface(); 134 | else 135 | intf = dev->ring; 136 | 137 | cons = intf->in_cons; 138 | prod = intf->in_prod; 139 | mb(); 140 | BUG_ON((prod - cons) > sizeof(intf->in)); 141 | 142 | while (filled < len && cons + filled != prod) { 143 | data[filled] = *(intf->in + MASK_XENCONS_IDX(cons + filled, intf->in)); 144 | filled++; 145 | } 146 | 147 | mb(); 148 | intf->in_cons = cons + filled; 149 | 150 | notify_daemon(dev); 151 | 152 | return filled; 153 | } 154 | #endif 155 | 156 | struct consfront_dev *xencons_ring_init(void) 157 | { 158 | int err; 159 | struct consfront_dev *dev; 160 | 161 | if (!start_info.console.domU.evtchn) 162 | return 0; 163 | 164 | dev = malloc(sizeof(struct consfront_dev)); 165 | memset(dev, 0, sizeof(struct consfront_dev)); 166 | dev->nodename = "device/console"; 167 | dev->dom = 0; 168 | dev->backend = 0; 169 | dev->ring_ref = 0; 170 | 171 | #ifdef HAVE_LIBC 172 | dev->fd = -1; 173 | #endif 174 | dev->evtchn = start_info.console.domU.evtchn; 175 | dev->ring = (struct xencons_interface *) mfn_to_virt(start_info.console.domU.mfn); 176 | 177 | err = bind_evtchn(dev->evtchn, console_handle_input, dev); 178 | if (err <= 0) { 179 | printk("XEN console request chn bind failed %i\n", err); 180 | free(dev); 181 | return NULL; 182 | } 183 | unmask_evtchn(dev->evtchn); 184 | 185 | /* In case we have in-flight data after save/restore... */ 186 | notify_daemon(dev); 187 | 188 | return dev; 189 | } 190 | 191 | void xencons_ring_resume(struct consfront_dev *dev) 192 | { 193 | if (!dev) { 194 | unmask_evtchn(start_info.console.domU.evtchn); 195 | } else { 196 | unmask_evtchn(dev->evtchn); 197 | } 198 | 199 | notify_daemon(dev); 200 | } 201 | 202 | void xencons_ring_fini(struct consfront_dev *dev) 203 | { 204 | if (!dev) { 205 | mask_evtchn(start_info.console.domU.evtchn); 206 | } else { 207 | mask_evtchn(dev->evtchn); 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /daytime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * daytime.c: a simple network service based on lwIP and mini-os 3 | * 4 | * Tim Deegan , July 2007 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static char message[29]; 14 | 15 | void run_server(void *p) 16 | { 17 | struct ip_addr listenaddr = { 0 }; 18 | struct netconn *listener; 19 | struct netconn *session; 20 | struct timeval tv; 21 | err_t rc; 22 | 23 | start_networking(); 24 | 25 | if (0) { 26 | struct ip_addr ipaddr = { htonl(0x0a000001) }; 27 | struct ip_addr netmask = { htonl(0xff000000) }; 28 | struct ip_addr gw = { 0 }; 29 | networking_set_addr(&ipaddr, &netmask, &gw); 30 | } 31 | 32 | tprintk("Opening connection\n"); 33 | 34 | listener = netconn_new(NETCONN_TCP); 35 | tprintk("Connection at %p\n", listener); 36 | 37 | rc = netconn_bind(listener, &listenaddr, 13); 38 | if (rc != ERR_OK) { 39 | tprintk("Failed to bind connection: %i\n", rc); 40 | return; 41 | } 42 | 43 | rc = netconn_listen(listener); 44 | if (rc != ERR_OK) { 45 | tprintk("Failed to listen on connection: %i\n", rc); 46 | return; 47 | } 48 | 49 | while (1) { 50 | session = netconn_accept(listener); 51 | if (session == NULL) 52 | continue; 53 | 54 | gettimeofday(&tv, NULL); 55 | sprintf(message, "%20lu.%6.6lu\n", tv.tv_sec, tv.tv_usec); 56 | (void) netconn_write(session, message, strlen(message), NETCONN_COPY); 57 | (void) netconn_disconnect(session); 58 | (void) netconn_delete(session); 59 | } 60 | } 61 | 62 | 63 | int app_main(start_info_t *si) 64 | { 65 | create_thread("server", run_server, NULL); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /domain_config: -------------------------------------------------------------------------------- 1 | # -*- mode: python; -*- 2 | #============================================================================ 3 | # Python configuration setup for 'xm create'. 4 | # This script sets the parameters used when a domain is created using 'xm create'. 5 | # You use a separate script for each domain you want to create, or 6 | # you can set the parameters for the domain on the xm command line. 7 | #============================================================================ 8 | 9 | #---------------------------------------------------------------------------- 10 | # Kernel image file. 11 | kernel = "mini-os.gz" 12 | 13 | # Initial memory allocation (in megabytes) for the new domain. 14 | memory = 32 15 | 16 | # A name for your domain. All domains must have different names. 17 | name = "Mini-OS" 18 | 19 | on_crash = 'destroy' 20 | -------------------------------------------------------------------------------- /hypervisor.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hypervisor.c 3 | * 4 | * Communication to/from hypervisor. 5 | * 6 | * Copyright (c) 2002-2003, K A Fraser 7 | * Copyright (c) 2005, Grzegorz Milos, gm281@cam.ac.uk,Intel Research Cambridge 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to 11 | * deal in the Software without restriction, including without limitation the 12 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 13 | * sell copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | * DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define active_evtchns(cpu,sh,idx) \ 34 | ((sh)->evtchn_pending[idx] & \ 35 | ~(sh)->evtchn_mask[idx]) 36 | 37 | int in_callback; 38 | 39 | void do_hypervisor_callback(struct pt_regs *regs) 40 | { 41 | unsigned long l1, l2, l1i, l2i; 42 | unsigned int port; 43 | int cpu = 0; 44 | shared_info_t *s = HYPERVISOR_shared_info; 45 | vcpu_info_t *vcpu_info = &s->vcpu_info[cpu]; 46 | 47 | in_callback = 1; 48 | 49 | vcpu_info->evtchn_upcall_pending = 0; 50 | /* NB x86. No need for a barrier here -- XCHG is a barrier on x86. */ 51 | #if !defined(__i386__) && !defined(__x86_64__) 52 | /* Clear master flag /before/ clearing selector flag. */ 53 | wmb(); 54 | #endif 55 | l1 = xchg(&vcpu_info->evtchn_pending_sel, 0); 56 | while ( l1 != 0 ) 57 | { 58 | l1i = __ffs(l1); 59 | l1 &= ~(1UL << l1i); 60 | 61 | while ( (l2 = active_evtchns(cpu, s, l1i)) != 0 ) 62 | { 63 | l2i = __ffs(l2); 64 | l2 &= ~(1UL << l2i); 65 | 66 | port = (l1i * (sizeof(unsigned long) * 8)) + l2i; 67 | do_event(port, regs); 68 | } 69 | } 70 | 71 | in_callback = 0; 72 | } 73 | 74 | void force_evtchn_callback(void) 75 | { 76 | int save; 77 | vcpu_info_t *vcpu; 78 | vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; 79 | save = vcpu->evtchn_upcall_mask; 80 | 81 | while (vcpu->evtchn_upcall_pending) { 82 | vcpu->evtchn_upcall_mask = 1; 83 | barrier(); 84 | do_hypervisor_callback(NULL); 85 | barrier(); 86 | vcpu->evtchn_upcall_mask = save; 87 | barrier(); 88 | }; 89 | } 90 | 91 | inline void mask_evtchn(uint32_t port) 92 | { 93 | shared_info_t *s = HYPERVISOR_shared_info; 94 | synch_set_bit(port, &s->evtchn_mask[0]); 95 | } 96 | 97 | inline void unmask_evtchn(uint32_t port) 98 | { 99 | shared_info_t *s = HYPERVISOR_shared_info; 100 | vcpu_info_t *vcpu_info = &s->vcpu_info[smp_processor_id()]; 101 | 102 | synch_clear_bit(port, &s->evtchn_mask[0]); 103 | 104 | /* 105 | * The following is basically the equivalent of 'hw_resend_irq'. Just like 106 | * a real IO-APIC we 'lose the interrupt edge' if the channel is masked. 107 | */ 108 | if ( synch_test_bit (port, &s->evtchn_pending[0]) && 109 | !synch_test_and_set_bit(port / (sizeof(unsigned long) * 8), 110 | &vcpu_info->evtchn_pending_sel) ) 111 | { 112 | vcpu_info->evtchn_upcall_pending = 1; 113 | if ( !vcpu_info->evtchn_upcall_mask ) 114 | force_evtchn_callback(); 115 | } 116 | } 117 | 118 | inline void clear_evtchn(uint32_t port) 119 | { 120 | shared_info_t *s = HYPERVISOR_shared_info; 121 | synch_clear_bit(port, &s->evtchn_pending[0]); 122 | } 123 | -------------------------------------------------------------------------------- /include/arch/cc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lwip/arch/cc.h 3 | * 4 | * Compiler-specific types and macros for lwIP running on mini-os 5 | * 6 | * Tim Deegan , July 2007 7 | * Simon Kuenzer , October 2014 8 | */ 9 | 10 | #ifndef __LWIP_ARCH_CC_H__ 11 | #define __LWIP_ARCH_CC_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /* Typedefs for the types used by lwip */ 20 | typedef uint8_t u8_t; 21 | typedef int8_t s8_t; 22 | typedef uint16_t u16_t; 23 | typedef int16_t s16_t; 24 | typedef uint32_t u32_t; 25 | typedef int32_t s32_t; 26 | typedef uint64_t u64_t; 27 | typedef int64_t s64_t; 28 | typedef uintptr_t mem_ptr_t; 29 | 30 | #include 31 | #define S16_F PRIi16 32 | #define U16_F PRIu16 33 | #define X16_F PRIx16 34 | #define S32_F PRIi32 35 | #define U32_F PRIu32 36 | #define X32_F PRIx32 37 | #define SZT_F "uz" 38 | 39 | /* byte-swapping */ 40 | #ifdef HAVE_LIBC 41 | #include 42 | #ifndef BIG_ENDIAN 43 | #error endian.h does not define byte order 44 | #endif 45 | #else 46 | #include 47 | #endif 48 | 49 | /* 32 bit checksum calculation */ 50 | #define LWIP_CHKSUM_ALGORITHM 3 51 | #ifdef CONFIG_NETFRONT_PERSISTENT_GRANTS 52 | #define ETH_PAD_SIZE 2 53 | #else 54 | #define ETH_PAD_SIZE 0 55 | #endif 56 | 57 | /* rand */ 58 | #define LWIP_RAND() ((u32_t)rand()) 59 | 60 | /* compiler hints for packing lwip's structures */ 61 | #define PACK_STRUCT_FIELD(_x) _x 62 | #define PACK_STRUCT_STRUCT __attribute__ ((packed)) 63 | #define PACK_STRUCT_BEGIN 64 | #define PACK_STRUCT_END 65 | 66 | /* platform specific diagnostic output */ 67 | #define LWIP_PLATFORM_DIAG(_x) do { printf("lwip: "); printf _x; } while (0) 68 | #define LWIP_PLATFORM_ASSERT(_x) do { printf("lwip: Assertion \"%s\" failed at line %d in %s\n", \ 69 | _x, __LINE__, __FILE__); fflush(stdout); BUG(); } while(0) 70 | 71 | /* lightweight synchronization mechanisms */ 72 | #define SYS_ARCH_DECL_PROTECT(_x) int (_x) 73 | #define SYS_ARCH_PROTECT(_x) local_irq_save((_x)) 74 | #define SYS_ARCH_UNPROTECT(_x) local_irq_restore((_x)) 75 | 76 | #endif /* __LWIP_ARCH_CC_H__ */ 77 | -------------------------------------------------------------------------------- /include/arch/perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lwip/arch/perf.h 3 | * 4 | * Arch-specific performance measurement for lwIP running on mini-os 5 | * 6 | * Tim Deegan , July 2007 7 | */ 8 | 9 | #ifndef __LWIP_ARCH_PERF_H__ 10 | #define __LWIP_ARCH_PERF_H__ 11 | 12 | #define PERF_START do { } while(0) 13 | #define PERF_STOP(_x) do { (void)(_x); } while (0) 14 | 15 | #endif /* __LWIP_ARCH_PERF_H__ */ 16 | -------------------------------------------------------------------------------- /include/arch/sys_arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lwip/arch/sys_arch.h 3 | * 4 | * Arch-specific semaphores and mailboxes for lwIP running on mini-os 5 | * 6 | * Tim Deegan , July 2007 7 | * Simon Kuenzer , October 2014 8 | */ 9 | 10 | #ifndef __LWIP_ARCH_SYS_ARCH_H__ 11 | #define __LWIP_ARCH_SYS_ARCH_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #define LWIP_COMPAT_MUTEX 1 /* enables emulation of mutex with 18 | * binary semaphores */ 19 | 20 | #define SYS_SEM_NULL NULL 21 | #define SYS_MBOX_NULL NULL 22 | 23 | struct lwip_sem { 24 | struct semaphore sem; 25 | int valid; 26 | }; 27 | 28 | struct lwip_mbox { 29 | int count; 30 | void **messages; 31 | struct semaphore read_sem; 32 | struct semaphore write_sem; 33 | int writer; 34 | int reader; 35 | int valid; 36 | }; 37 | 38 | typedef struct lwip_sem sys_sem_t; 39 | typedef struct lwip_mbox sys_mbox_t; 40 | typedef struct thread *sys_thread_t; 41 | typedef unsigned long sys_prot_t; 42 | 43 | #endif /*__LWIP_ARCH_SYS_ARCH_H__ */ 44 | -------------------------------------------------------------------------------- /include/blkfront.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef CONFIG_BLKFRONT_PERSISTENT_GRANTS 6 | #define __LOG2_8BIT(x) (8 - 90/(((x)/4+14)|1) - 2/((x)/2+1)) 7 | #define BLKIF_MAX_PRSNT_GNT_SEGMENTS_PER_REQUEST \ 8 | (1 << (__LOG2_8BIT(BLKIF_MAX_SEGMENTS_PER_REQUEST))) 9 | #endif 10 | 11 | struct blkfront_dev; 12 | struct blk_buffer; 13 | struct blkfront_aiocb 14 | { 15 | struct blkfront_dev *aio_dev; 16 | uint8_t *aio_buf; 17 | size_t aio_nbytes; 18 | off_t aio_offset; 19 | size_t total_bytes; 20 | uint8_t is_write; 21 | void *data; 22 | 23 | #ifdef CONFIG_BLKFRONT_PERSISTENT_GRANTS 24 | struct blk_buffer *prst_buffer[BLKIF_MAX_PRSNT_GNT_SEGMENTS_PER_REQUEST]; 25 | #else 26 | grant_ref_t gref[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 27 | #endif 28 | int n; 29 | 30 | void (*aio_cb)(struct blkfront_aiocb *aiocb, int ret); 31 | }; 32 | struct blkfront_info 33 | { 34 | uint64_t sectors; 35 | unsigned sector_size; 36 | int mode; 37 | int info; 38 | int barrier; 39 | int flush; 40 | }; 41 | struct blkfront_dev *init_blkfront(char *nodename, struct blkfront_info *info); 42 | #ifdef HAVE_LIBC 43 | #include 44 | /* POSIX IO functions: 45 | * use blkfront_open() to get a file descriptor to the block device 46 | * Don't use the other blkfront posix functions here directly, instead use 47 | * read(), write(), lseek() and fstat() on the file descriptor 48 | */ 49 | int blkfront_open(struct blkfront_dev *dev); 50 | int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write); 51 | #define blkfront_posix_write(fd, buf, count) blkfront_posix_rwop(fd, (uint8_t*)buf, count, 1) 52 | #define blkfront_posix_read(fd, buf, count) blkfront_posix_rwop(fd, (uint8_t*)buf, count, 0) 53 | int blkfront_posix_fstat(int fd, struct stat* buf); 54 | #endif 55 | void blkfront_aio(struct blkfront_aiocb *aiocbp, int write); 56 | void blkfront_aio_nosched(struct blkfront_aiocb *aiocbp, int write); 57 | void blkfront_wait_slot(struct blkfront_dev *dev); 58 | void blkfront_wait_slot_nosched(struct blkfront_dev *dev); 59 | int blkfront_aio_enqueue(struct blkfront_aiocb *aiocbp, int write); 60 | void blkfront_aio_submit(struct blkfront_dev *dev); 61 | #define blkfront_aio_read(aiocbp) blkfront_aio(aiocbp, 0) 62 | #define blkfront_aio_write(aiocbp) blkfront_aio(aiocbp, 1) 63 | void blkfront_io(struct blkfront_aiocb *aiocbp, int write); 64 | #define blkfront_read(aiocbp) blkfront_io(aiocbp, 0) 65 | #define blkfront_write(aiocbp) blkfront_io(aiocbp, 1) 66 | void blkfront_aio_push_operation(struct blkfront_aiocb *aiocbp, uint8_t op); 67 | int blkfront_aio_poll(struct blkfront_dev *dev); 68 | void blkfront_sync(struct blkfront_dev *dev); 69 | void shutdown_blkfront(struct blkfront_dev *dev); 70 | 71 | extern struct wait_queue_head blkfront_queue; 72 | -------------------------------------------------------------------------------- /include/byteorder.h: -------------------------------------------------------------------------------- 1 | #ifndef MINIOS_BYTEORDER_H 2 | #define MINIOS_BYTEORDER_H 3 | 4 | #include 5 | #include 6 | 7 | #if __BYTE_ORDER == __LITTLE_ENDIAN 8 | #define be16_to_cpu(v) bswap_16(v) 9 | #define be32_to_cpu(v) bswap_32(v) 10 | #define be64_to_cpu(v) bswap_64(v) 11 | 12 | #define le16_to_cpu(v) (v) 13 | #define le32_to_cpu(v) (v) 14 | #define le64_to_cpu(v) (v) 15 | 16 | #else /*__BIG_ENDIAN*/ 17 | #define be16_to_cpu(v) (v) 18 | #define be32_to_cpu(v) (v) 19 | #define be64_to_cpu(v) (v) 20 | 21 | #define le16_to_cpu(v) bswap_16(v) 22 | #define le32_to_cpu(v) bswap_32(v) 23 | #define le64_to_cpu(v) bswap_64(v) 24 | 25 | #endif 26 | 27 | #define cpu_to_be16(v) be16_to_cpu(v) 28 | #define cpu_to_be32(v) be32_to_cpu(v) 29 | #define cpu_to_be64(v) be64_to_cpu(v) 30 | 31 | #define cpu_to_le16(v) le16_to_cpu(v) 32 | #define cpu_to_le32(v) le32_to_cpu(v) 33 | #define cpu_to_le64(v) le64_to_cpu(v) 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/byteswap.h: -------------------------------------------------------------------------------- 1 | #ifndef _BYTESWAP_H_ 2 | #define _BYTESWAP_H_ 3 | 4 | /* Unfortunately not provided by newlib. */ 5 | 6 | #include 7 | 8 | #define bswap_16(x) ((uint16_t)( \ 9 | (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \ 10 | (((uint16_t)(x) & (uint16_t)0xff00U) >> 8))) 11 | 12 | /* Use gcc optimized versions if they exist */ 13 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) 14 | #define bswap_32(v) __builtin_bswap32(v) 15 | #define bswap_64(v) __builtin_bswap64(v) 16 | #else 17 | 18 | #define bswap_32(x) ((uint32_t)( \ 19 | (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ 20 | (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ 21 | (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ 22 | (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) 23 | 24 | #define bswap_64(x) ((uint64_t)( \ 25 | (((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \ 26 | (((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ 27 | (((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ 28 | (((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ 29 | (((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ 30 | (((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ 31 | (((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ 32 | (((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56))) 33 | 34 | #endif 35 | 36 | 37 | 38 | 39 | #endif /* _BYTESWAP_H */ 40 | -------------------------------------------------------------------------------- /include/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | **************************************************************************** 3 | * (C) 2006 - Grzegorz Milos - Cambridge University 4 | **************************************************************************** 5 | * 6 | * File: console.h 7 | * Author: Grzegorz Milos 8 | * Changes: 9 | * 10 | * Date: Mar 2006 11 | * 12 | * Environment: Xen Minimal OS 13 | * Description: Console interface. 14 | * 15 | * Handles console I/O. Defines printk. 16 | * 17 | **************************************************************************** 18 | * Permission is hereby granted, free of charge, to any person obtaining a copy 19 | * of this software and associated documentation files (the "Software"), to 20 | * deal in the Software without restriction, including without limitation the 21 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 22 | * sell copies of the Software, and to permit persons to whom the Software is 23 | * furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included in 26 | * all copies or substantial portions of the Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 34 | * DEALINGS IN THE SOFTWARE. 35 | */ 36 | #ifndef _LIB_CONSOLE_H_ 37 | #define _LIB_CONSOLE_H_ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | struct consfront_dev { 48 | domid_t dom; 49 | 50 | struct xencons_interface *ring; 51 | grant_ref_t ring_ref; 52 | evtchn_port_t evtchn; 53 | 54 | char *nodename; 55 | char *backend; 56 | 57 | xenbus_event_queue events; 58 | 59 | #ifdef HAVE_LIBC 60 | int fd; 61 | #endif 62 | }; 63 | 64 | 65 | 66 | void print(int direct, const char *fmt, va_list args); 67 | void printk(const char *fmt, ...); 68 | void xprintk(const char *fmt, ...); 69 | 70 | #define tprintk(_fmt, _args...) printk("[%s] " _fmt, current->name, ##_args) 71 | 72 | void xencons_rx(char *buf, unsigned len, struct pt_regs *regs); 73 | void xencons_tx(void); 74 | 75 | void init_console(void); 76 | void console_print(struct consfront_dev *dev, char *data, int length); 77 | void fini_console(struct consfront_dev *dev); 78 | void suspend_console(void); 79 | void resume_console(void); 80 | 81 | /* Low level functions defined in xencons_ring.c */ 82 | extern struct wait_queue_head console_queue; 83 | struct consfront_dev *xencons_ring_init(void); 84 | void xencons_ring_resume(struct consfront_dev *dev); 85 | void xencons_ring_fini(struct consfront_dev *dev); 86 | struct consfront_dev *init_consfront(char *_nodename); 87 | int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len); 88 | int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len); 89 | int xencons_ring_avail(struct consfront_dev *dev); 90 | int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len); 91 | void free_consfront(struct consfront_dev *dev); 92 | 93 | #endif /* _LIB_CONSOLE_H_ */ 94 | -------------------------------------------------------------------------------- /include/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _CTYPE_H 2 | #define _CTYPE_H 3 | 4 | #ifdef HAVE_LIBC 5 | #include_next 6 | #else 7 | /* 8 | * NOTE! This ctype does not handle EOF like the standard C 9 | * library is required to. 10 | */ 11 | 12 | #define _U 0x01 /* upper */ 13 | #define _L 0x02 /* lower */ 14 | #define _D 0x04 /* digit */ 15 | #define _C 0x08 /* cntrl */ 16 | #define _P 0x10 /* punct */ 17 | #define _S 0x20 /* white space (space/lf/tab) */ 18 | #define _X 0x40 /* hex digit */ 19 | #define _SP 0x80 /* hard space (0x20) */ 20 | 21 | 22 | extern unsigned char _ctype[]; 23 | 24 | #define __ismask(x) (_ctype[(int)(unsigned char)(x)]) 25 | 26 | #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0) 27 | #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0) 28 | #define iscntrl(c) ((__ismask(c)&(_C)) != 0) 29 | #define isdigit(c) ((__ismask(c)&(_D)) != 0) 30 | #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0) 31 | #define islower(c) ((__ismask(c)&(_L)) != 0) 32 | #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0) 33 | #define ispunct(c) ((__ismask(c)&(_P)) != 0) 34 | #define isspace(c) ((__ismask(c)&(_S)) != 0) 35 | #define isupper(c) ((__ismask(c)&(_U)) != 0) 36 | #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0) 37 | 38 | #define isascii(c) (((unsigned char)(c))<=0x7f) 39 | #define toascii(c) (((unsigned char)(c))&0x7f) 40 | 41 | static inline unsigned char __tolower(unsigned char c) 42 | { 43 | if (isupper(c)) 44 | c -= 'A'-'a'; 45 | return c; 46 | } 47 | 48 | static inline unsigned char __toupper(unsigned char c) 49 | { 50 | if (islower(c)) 51 | c -= 'a'-'A'; 52 | return c; 53 | } 54 | 55 | #define tolower(c) __tolower(c) 56 | #define toupper(c) __toupper(c) 57 | 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /include/endian.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENDIAN_H_ 2 | #define _ENDIAN_H_ 3 | 4 | #define __LITTLE_ENDIAN 1234 5 | #define __BIG_ENDIAN 4321 6 | #define __PDP_ENDIAN 3412 7 | 8 | #define ARCH_ENDIAN_H 9 | /* This will define __BYTE_ORDER for the current arch */ 10 | #include 11 | #undef ARCH_ENDIAN_H 12 | 13 | #include 14 | 15 | #define BYTE_ORDER __BYTE_ORDER 16 | #define BIG_ENDIAN __BIG_ENDIAN 17 | #define LITTLE_ENDIAN __LITTLE_ENDIAN 18 | 19 | #endif /* endian.h */ 20 | -------------------------------------------------------------------------------- /include/err.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERR_H 2 | #define _ERR_H 3 | 4 | #include 5 | 6 | /* 7 | * Kernel pointers have redundant information, so we can use a 8 | * scheme where we can return either an error code or a dentry 9 | * pointer with the same return value. 10 | * 11 | * This should be a per-architecture thing, to allow different 12 | * error and pointer decisions. 13 | */ 14 | #define IS_ERR_VALUE(x) ((x) > (unsigned long)-1000L) 15 | 16 | static inline void *ERR_PTR(long error) 17 | { 18 | return (void *) error; 19 | } 20 | 21 | static inline long PTR_ERR(const void *ptr) 22 | { 23 | return (long) ptr; 24 | } 25 | 26 | static inline long IS_ERR(const void *ptr) 27 | { 28 | return IS_ERR_VALUE((unsigned long)ptr); 29 | } 30 | 31 | #endif /* _LINUX_ERR_H */ 32 | -------------------------------------------------------------------------------- /include/errno-base.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERRNO_BASE_H 2 | #define _ERRNO_BASE_H 3 | 4 | #define EPERM 1 /* Operation not permitted */ 5 | #define ENOENT 2 /* No such file or directory */ 6 | #define ESRCH 3 /* No such process */ 7 | #define EINTR 4 /* Interrupted system call */ 8 | #define EIO 5 /* I/O error */ 9 | #define ENXIO 6 /* No such device or address */ 10 | #define E2BIG 7 /* Argument list too long */ 11 | #define ENOEXEC 8 /* Exec format error */ 12 | #define EBADF 9 /* Bad file number */ 13 | #define ECHILD 10 /* No child processes */ 14 | #define EAGAIN 11 /* Try again */ 15 | #define ENOMEM 12 /* Out of memory */ 16 | #define EACCES 13 /* Permission denied */ 17 | #define EFAULT 14 /* Bad address */ 18 | #define ENOTBLK 15 /* Block device required */ 19 | #define EBUSY 16 /* Device or resource busy */ 20 | #define EEXIST 17 /* File exists */ 21 | #define EXDEV 18 /* Cross-device link */ 22 | #define ENODEV 19 /* No such device */ 23 | #define ENOTDIR 20 /* Not a directory */ 24 | #define EISDIR 21 /* Is a directory */ 25 | #define EINVAL 22 /* Invalid argument */ 26 | #define ENFILE 23 /* File table overflow */ 27 | #define EMFILE 24 /* Too many open files */ 28 | #define ENOTTY 25 /* Not a typewriter */ 29 | #define ETXTBSY 26 /* Text file busy */ 30 | #define EFBIG 27 /* File too large */ 31 | #define ENOSPC 28 /* No space left on device */ 32 | #define ESPIPE 29 /* Illegal seek */ 33 | #define EROFS 30 /* Read-only file system */ 34 | #define EMLINK 31 /* Too many links */ 35 | #define EPIPE 32 /* Broken pipe */ 36 | #define EDOM 33 /* Math argument out of domain of func */ 37 | #define ERANGE 34 /* Math result not representable */ 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERRNO_H 2 | #define _ERRNO_H 3 | 4 | #include 5 | 6 | typedef int error_t; 7 | 8 | #define EDEADLK 35 /* Resource deadlock would occur */ 9 | #define ENAMETOOLONG 36 /* File name too long */ 10 | #define ENOLCK 37 /* No record locks available */ 11 | #define ENOSYS 38 /* Function not implemented */ 12 | #define ENOTEMPTY 39 /* Directory not empty */ 13 | #define ELOOP 40 /* Too many symbolic links encountered */ 14 | #define EWOULDBLOCK EAGAIN /* Operation would block */ 15 | #define ENOMSG 42 /* No message of desired type */ 16 | #define EIDRM 43 /* Identifier removed */ 17 | #define ECHRNG 44 /* Channel number out of range */ 18 | #define EL2NSYNC 45 /* Level 2 not synchronized */ 19 | #define EL3HLT 46 /* Level 3 halted */ 20 | #define EL3RST 47 /* Level 3 reset */ 21 | #define ELNRNG 48 /* Link number out of range */ 22 | #define EUNATCH 49 /* Protocol driver not attached */ 23 | #define ENOCSI 50 /* No CSI structure available */ 24 | #define EL2HLT 51 /* Level 2 halted */ 25 | #define EBADE 52 /* Invalid exchange */ 26 | #define EBADR 53 /* Invalid request descriptor */ 27 | #define EXFULL 54 /* Exchange full */ 28 | #define ENOANO 55 /* No anode */ 29 | #define EBADRQC 56 /* Invalid request code */ 30 | #define EBADSLT 57 /* Invalid slot */ 31 | 32 | #define EDEADLOCK EDEADLK 33 | 34 | #define EBFONT 59 /* Bad font file format */ 35 | #define ENOSTR 60 /* Device not a stream */ 36 | #define ENODATA 61 /* No data available */ 37 | #define ETIME 62 /* Timer expired */ 38 | #define ENOSR 63 /* Out of streams resources */ 39 | #define ENONET 64 /* Machine is not on the network */ 40 | #define ENOPKG 65 /* Package not installed */ 41 | #define EREMOTE 66 /* Object is remote */ 42 | #define ENOLINK 67 /* Link has been severed */ 43 | #define EADV 68 /* Advertise error */ 44 | #define ESRMNT 69 /* Srmount error */ 45 | #define ECOMM 70 /* Communication error on send */ 46 | #define EPROTO 71 /* Protocol error */ 47 | #define EMULTIHOP 72 /* Multihop attempted */ 48 | #define EDOTDOT 73 /* RFS specific error */ 49 | #define EBADMSG 74 /* Not a data message */ 50 | #define EOVERFLOW 75 /* Value too large for defined data type */ 51 | #define ENOTUNIQ 76 /* Name not unique on network */ 52 | #define EBADFD 77 /* File descriptor in bad state */ 53 | #define EREMCHG 78 /* Remote address changed */ 54 | #define ELIBACC 79 /* Can not access a needed shared library */ 55 | #define ELIBBAD 80 /* Accessing a corrupted shared library */ 56 | #define ELIBSCN 81 /* .lib section in a.out corrupted */ 57 | #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ 58 | #define ELIBEXEC 83 /* Cannot exec a shared library directly */ 59 | #define EILSEQ 84 /* Illegal byte sequence */ 60 | #define ERESTART 85 /* Interrupted system call should be restarted */ 61 | #define ESTRPIPE 86 /* Streams pipe error */ 62 | #define EUSERS 87 /* Too many users */ 63 | #define ENOTSOCK 88 /* Socket operation on non-socket */ 64 | #define EDESTADDRREQ 89 /* Destination address required */ 65 | #define EMSGSIZE 90 /* Message too long */ 66 | #define EPROTOTYPE 91 /* Protocol wrong type for socket */ 67 | #define ENOPROTOOPT 92 /* Protocol not available */ 68 | #define EPROTONOSUPPORT 93 /* Protocol not supported */ 69 | #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ 70 | #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 71 | #define ENOTSUP EOPNOTSUPP 72 | #define EPFNOSUPPORT 96 /* Protocol family not supported */ 73 | #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ 74 | #define EADDRINUSE 98 /* Address already in use */ 75 | #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ 76 | #define ENETDOWN 100 /* Network is down */ 77 | #define ENETUNREACH 101 /* Network is unreachable */ 78 | #define ENETRESET 102 /* Network dropped connection because of reset */ 79 | #define ECONNABORTED 103 /* Software caused connection abort */ 80 | #define ECONNRESET 104 /* Connection reset by peer */ 81 | #define ENOBUFS 105 /* No buffer space available */ 82 | #define EISCONN 106 /* Transport endpoint is already connected */ 83 | #define ENOTCONN 107 /* Transport endpoint is not connected */ 84 | #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ 85 | #define ETOOMANYREFS 109 /* Too many references: cannot splice */ 86 | #define ETIMEDOUT 110 /* Connection timed out */ 87 | #define ECONNREFUSED 111 /* Connection refused */ 88 | #define EHOSTDOWN 112 /* Host is down */ 89 | #define EHOSTUNREACH 113 /* No route to host */ 90 | #define EALREADY 114 /* Operation already in progress */ 91 | #define EINPROGRESS 115 /* Operation now in progress */ 92 | #define ESTALE 116 /* Stale NFS file handle */ 93 | #define EUCLEAN 117 /* Structure needs cleaning */ 94 | #define ENOTNAM 118 /* Not a XENIX named type file */ 95 | #define ENAVAIL 119 /* No XENIX semaphores available */ 96 | #define EISNAM 120 /* Is a named type file */ 97 | #define EREMOTEIO 121 /* Remote I/O error */ 98 | #define EDQUOT 122 /* Quota exceeded */ 99 | 100 | #define ENOMEDIUM 123 /* No medium found */ 101 | #define EMEDIUMTYPE 124 /* Wrong medium type */ 102 | #define ECANCELED 125 /* Operation Canceled */ 103 | #define ENOKEY 126 /* Required key not available */ 104 | #define EKEYEXPIRED 127 /* Key has expired */ 105 | #define EKEYREVOKED 128 /* Key has been revoked */ 106 | #define EKEYREJECTED 129 /* Key was rejected by service */ 107 | 108 | /* for robust mutexes */ 109 | #define EOWNERDEAD 130 /* Owner died */ 110 | #define ENOTRECOVERABLE 131 /* State not recoverable */ 111 | 112 | 113 | #define EFTYPE 132 /* Inappropriate file type or format */ 114 | 115 | #ifdef HAVE_LIBC 116 | #include 117 | extern int errno; 118 | #define ERRNO 119 | #define errno (get_current()->reent._errno) 120 | #endif 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /include/events.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | **************************************************************************** 3 | * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge 4 | * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge 5 | **************************************************************************** 6 | * 7 | * File: events.h 8 | * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) 9 | * Changes: Grzegorz Milos (gm281@cam.ac.uk) 10 | * 11 | * Date: Jul 2003, changes Jun 2005 12 | * 13 | * Environment: Xen Minimal OS 14 | * Description: Deals with events on the event channels 15 | * 16 | **************************************************************************** 17 | */ 18 | 19 | #ifndef _EVENTS_H_ 20 | #define _EVENTS_H_ 21 | 22 | #include 23 | #include 24 | 25 | typedef void (*evtchn_handler_t)(evtchn_port_t, struct pt_regs *, void *); 26 | 27 | /* prototypes */ 28 | int do_event(evtchn_port_t port, struct pt_regs *regs); 29 | evtchn_port_t bind_virq(uint32_t virq, evtchn_handler_t handler, void *data); 30 | evtchn_port_t bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t handler, void *data); 31 | evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler, 32 | void *data); 33 | void unbind_evtchn(evtchn_port_t port); 34 | void init_events(void); 35 | int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler, 36 | void *data, evtchn_port_t *port); 37 | int evtchn_bind_interdomain(domid_t pal, evtchn_port_t remote_port, 38 | evtchn_handler_t handler, void *data, 39 | evtchn_port_t *local_port); 40 | int evtchn_get_peercontext(evtchn_port_t local_port, char *ctx, int size); 41 | void unbind_all_ports(void); 42 | 43 | static inline int notify_remote_via_evtchn(evtchn_port_t port) 44 | { 45 | evtchn_send_t op; 46 | op.port = port; 47 | return HYPERVISOR_event_channel_op(EVTCHNOP_send, &op); 48 | } 49 | 50 | void fini_events(void); 51 | void suspend_events(void); 52 | 53 | #endif /* _EVENTS_H_ */ 54 | -------------------------------------------------------------------------------- /include/fbfront.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* from */ 7 | #ifndef BTN_LEFT 8 | #define BTN_LEFT 0x110 9 | #endif 10 | #ifndef BTN_RIGHT 11 | #define BTN_RIGHT 0x111 12 | #endif 13 | #ifndef BTN_MIDDLE 14 | #define BTN_MIDDLE 0x112 15 | #endif 16 | #ifndef KEY_Q 17 | #define KEY_Q 16 18 | #endif 19 | #ifndef KEY_MAX 20 | #define KEY_MAX 0x1ff 21 | #endif 22 | 23 | 24 | struct kbdfront_dev; 25 | struct kbdfront_dev *init_kbdfront(char *nodename, int abs_pointer); 26 | #ifdef HAVE_LIBC 27 | int kbdfront_open(struct kbdfront_dev *dev); 28 | #endif 29 | 30 | int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n); 31 | extern struct wait_queue_head kbdfront_queue; 32 | 33 | void shutdown_kbdfront(struct kbdfront_dev *dev); 34 | 35 | 36 | struct fbfront_dev *init_fbfront(char *nodename, unsigned long *mfns, int width, int height, int depth, int stride, int n); 37 | #ifdef HAVE_LIBC 38 | int fbfront_open(struct fbfront_dev *dev); 39 | #endif 40 | 41 | int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n); 42 | extern struct wait_queue_head fbfront_queue; 43 | void fbfront_update(struct fbfront_dev *dev, int x, int y, int width, int height); 44 | void fbfront_resize(struct fbfront_dev *dev, int width, int height, int stride, int depth, int offset); 45 | 46 | void shutdown_fbfront(struct fbfront_dev *dev); 47 | -------------------------------------------------------------------------------- /include/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef _I386_FCNTL_H 2 | #define _I386_FCNTL_H 3 | 4 | #ifdef HAVE_LIBC 5 | #include_next 6 | #else 7 | 8 | /* open/fcntl - O_SYNC is only implemented on blocks devices and on files 9 | located on an ext2 file system */ 10 | #define O_ACCMODE 0003 11 | #define O_RDONLY 00 12 | #define O_WRONLY 01 13 | #define O_RDWR 02 14 | #define O_CREAT 0100 /* not fcntl */ 15 | #define O_EXCL 0200 /* not fcntl */ 16 | #define O_NOCTTY 0400 /* not fcntl */ 17 | #define O_TRUNC 01000 /* not fcntl */ 18 | #define O_APPEND 02000 19 | #define O_NONBLOCK 04000 20 | #define O_NDELAY O_NONBLOCK 21 | #define O_SYNC 010000 22 | #define FASYNC 020000 /* fcntl, for BSD compatibility */ 23 | #define O_DIRECT 040000 /* direct disk access hint */ 24 | #define O_LARGEFILE 0100000 25 | #define O_DIRECTORY 0200000 /* must be a directory */ 26 | #define O_NOFOLLOW 0400000 /* don't follow links */ 27 | #define O_NOATIME 01000000 28 | 29 | #define F_DUPFD 0 /* dup */ 30 | #define F_GETFD 1 /* get close_on_exec */ 31 | #define F_SETFD 2 /* set/clear close_on_exec */ 32 | #define F_GETFL 3 /* get file->f_flags */ 33 | #define F_SETFL 4 /* set file->f_flags */ 34 | #define F_GETLK 5 35 | #define F_SETLK 6 36 | #define F_SETLKW 7 37 | 38 | #define F_SETOWN 8 /* for sockets. */ 39 | #define F_GETOWN 9 /* for sockets. */ 40 | #define F_SETSIG 10 /* for sockets. */ 41 | #define F_GETSIG 11 /* for sockets. */ 42 | 43 | #define F_GETLK64 12 /* using 'struct flock64' */ 44 | #define F_SETLK64 13 45 | #define F_SETLKW64 14 46 | 47 | /* for F_[GET|SET]FL */ 48 | #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ 49 | 50 | /* for posix fcntl() and lockf() */ 51 | #define F_RDLCK 0 52 | #define F_WRLCK 1 53 | #define F_UNLCK 2 54 | 55 | /* for old implementation of bsd flock () */ 56 | #define F_EXLCK 4 /* or 3 */ 57 | #define F_SHLCK 8 /* or 4 */ 58 | 59 | /* for leases */ 60 | #define F_INPROGRESS 16 61 | 62 | /* operations for bsd flock(), also used by the kernel implementation */ 63 | #define LOCK_SH 1 /* shared lock */ 64 | #define LOCK_EX 2 /* exclusive lock */ 65 | #define LOCK_NB 4 /* or'd with one of the above to prevent 66 | blocking */ 67 | #define LOCK_UN 8 /* remove lock */ 68 | 69 | #define LOCK_MAND 32 /* This is a mandatory flock */ 70 | #define LOCK_READ 64 /* ... Which allows concurrent read operations */ 71 | #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ 72 | #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ 73 | 74 | /* 75 | struct flock { 76 | short l_type; 77 | short l_whence; 78 | off_t l_start; 79 | off_t l_len; 80 | pid_t l_pid; 81 | }; 82 | 83 | struct flock64 { 84 | short l_type; 85 | short l_whence; 86 | loff_t l_start; 87 | loff_t l_len; 88 | pid_t l_pid; 89 | }; 90 | 91 | #define F_LINUX_SPECIFIC_BASE 1024 92 | */ 93 | 94 | #endif 95 | 96 | int open(const char *path, int flags, ...) asm("open64"); 97 | int fcntl(int fd, int cmd, ...); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /include/gntmap.h: -------------------------------------------------------------------------------- 1 | #ifndef __GNTMAP_H__ 2 | #define __GNTMAP_H__ 3 | 4 | #include 5 | 6 | /* 7 | * Please consider struct gntmap opaque. If instead you choose to disregard 8 | * this message, I insist that you keep an eye out for raptors. 9 | */ 10 | struct gntmap { 11 | int nentries; 12 | struct gntmap_entry *entries; 13 | }; 14 | 15 | int 16 | gntmap_set_max_grants(struct gntmap *map, int count); 17 | 18 | int 19 | gntmap_munmap(struct gntmap *map, unsigned long start_address, int count); 20 | 21 | void* 22 | gntmap_map_grant_refs(struct gntmap *map, 23 | uint32_t count, 24 | uint32_t *domids, 25 | int domids_stride, 26 | uint32_t *refs, 27 | int writable); 28 | 29 | void 30 | gntmap_init(struct gntmap *map); 31 | 32 | void 33 | gntmap_fini(struct gntmap *map); 34 | 35 | #endif /* !__GNTMAP_H__ */ 36 | -------------------------------------------------------------------------------- /include/gnttab.h: -------------------------------------------------------------------------------- 1 | #ifndef __GNTTAB_H__ 2 | #define __GNTTAB_H__ 3 | 4 | #include 5 | 6 | void init_gnttab(void); 7 | grant_ref_t gnttab_alloc_and_grant(void **map); 8 | grant_ref_t gnttab_grant_access(domid_t domid, unsigned long frame, 9 | int readonly); 10 | grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn); 11 | unsigned long gnttab_end_transfer(grant_ref_t gref); 12 | int gnttab_end_access(grant_ref_t ref); 13 | const char *gnttabop_error(int16_t status); 14 | void fini_gnttab(void); 15 | void suspend_gnttab(void); 16 | void resume_gnttab(void); 17 | 18 | #endif /* !__GNTTAB_H__ */ 19 | -------------------------------------------------------------------------------- /include/hypervisor.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hypervisor.h 3 | * 4 | * Hypervisor handling. 5 | * 6 | * 7 | * Copyright (c) 2002, K A Fraser 8 | * Copyright (c) 2005, Grzegorz Milos 9 | * Updates: Aravindh Puthiyaparambil 10 | */ 11 | 12 | #ifndef _HYPERVISOR_H_ 13 | #define _HYPERVISOR_H_ 14 | 15 | #include 16 | #include 17 | #if defined(__i386__) 18 | #include 19 | #elif defined(__x86_64__) 20 | #include 21 | #else 22 | #error "Unsupported architecture" 23 | #endif 24 | #include 25 | 26 | /* 27 | * a placeholder for the start of day information passed up from the hypervisor 28 | */ 29 | union start_info_union 30 | { 31 | start_info_t start_info; 32 | char padding[512]; 33 | }; 34 | extern union start_info_union start_info_union; 35 | #define start_info (start_info_union.start_info) 36 | 37 | /* hypervisor.c */ 38 | void force_evtchn_callback(void); 39 | void do_hypervisor_callback(struct pt_regs *regs); 40 | void mask_evtchn(uint32_t port); 41 | void unmask_evtchn(uint32_t port); 42 | void clear_evtchn(uint32_t port); 43 | 44 | extern int in_callback; 45 | 46 | #endif /* __HYPERVISOR_H__ */ 47 | -------------------------------------------------------------------------------- /include/ioremap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009 Netronome Systems, Inc. All rights reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | 24 | #ifndef _IOREMAP_H_ 25 | #define _IOREMAP_H_ 26 | 27 | void *ioremap(unsigned long phys_addr, unsigned long size); 28 | void *ioremap_nocache(unsigned long phys_addr, unsigned long size); 29 | void iounmap(void *virt_addr, unsigned long size); 30 | 31 | #endif /* _IOREMAP_H_ */ 32 | 33 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 indent-tabs-mode:nil -*- */ 34 | -------------------------------------------------------------------------------- /include/iorw.h: -------------------------------------------------------------------------------- 1 | #ifndef MINIOS_IORW_H 2 | #define MINIOS_IORW_H 3 | 4 | #include 5 | 6 | void iowrite8(volatile void* addr, uint8_t val); 7 | void iowrite16(volatile void* addr, uint16_t val); 8 | void iowrite32(volatile void* addr, uint32_t val); 9 | void iowrite64(volatile void* addr, uint64_t val); 10 | 11 | uint8_t ioread8(volatile void* addr); 12 | uint16_t ioread16(volatile void* addr); 13 | uint32_t ioread32(volatile void* addr); 14 | uint64_t ioread64(volatile void* addr); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef _KERNEL_H_ 2 | #define _KERNEL_H_ 3 | 4 | extern void do_exit(void) __attribute__((noreturn)); 5 | extern void stop_kernel(void); 6 | 7 | void pre_suspend(void); 8 | void post_suspend(int canceled); 9 | 10 | #endif /* _KERNEL_H_ */ 11 | -------------------------------------------------------------------------------- /include/lib-gpl.h: -------------------------------------------------------------------------------- 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, from Linux' 14 | * include/linux/kernel.h 15 | * 16 | * This program is free software; you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation; either version 2 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | * GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program; if not, write to the Free Software 28 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | */ 30 | 31 | #ifndef _LIB_GPL_H_ 32 | #define _LIB_GPL_H_ 33 | 34 | #ifndef HAVE_LIBC 35 | /* printing */ 36 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); 37 | extern long simple_strtol(const char *,char **,unsigned int); 38 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); 39 | extern long long simple_strtoll(const char *,char **,unsigned int); 40 | 41 | extern int sprintf(char * buf, const char * fmt, ...) 42 | __attribute__ ((format (printf, 2, 3))); 43 | extern int vsprintf(char *buf, const char *, va_list) 44 | __attribute__ ((format (printf, 2, 0))); 45 | extern int snprintf(char * buf, size_t size, const char * fmt, ...) 46 | __attribute__ ((format (printf, 3, 4))); 47 | extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) 48 | __attribute__ ((format (printf, 3, 0))); 49 | extern int scnprintf(char * buf, size_t size, const char * fmt, ...) 50 | __attribute__ ((format (printf, 3, 4))); 51 | extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) 52 | __attribute__ ((format (printf, 3, 0))); 53 | extern int sscanf(const char *, const char *, ...) 54 | __attribute__ ((format (scanf, 2, 3))); 55 | extern int vsscanf(const char *, const char *, va_list) 56 | __attribute__ ((format (scanf, 2, 0))); 57 | #endif 58 | 59 | #endif /* _LIB_GPL_H_ */ 60 | -------------------------------------------------------------------------------- /include/linux/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_TYPES_H_ 2 | #define _LINUX_TYPES_H_ 3 | #include 4 | typedef uint64_t __u64; 5 | #endif /* _LINUX_TYPES_H_ */ 6 | -------------------------------------------------------------------------------- /include/lwip-net.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Mini-OS netfront driver for lwIP 3 | * 4 | * Authors: Simon Kuenzer 5 | * 6 | * 7 | * Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the copyright holder nor the names of its 19 | * contributors may be used to endorse or promote products derived from 20 | * this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | */ 35 | #ifndef __LWIP_NET_H__ 36 | #define __LWIP_NET_H__ 37 | 38 | #include 39 | #include "lwip/opt.h" 40 | #include "netif/etharp.h" 41 | #include "netif/ppp/pppoe.h" 42 | 43 | /** 44 | * Helper struct to hold private data used to operate the ethernet interface. 45 | * The user can pre-initialize some values (e.g., providing a mac address, 46 | * passing a opened netfront_dev struct) and lwIP will use those passed data 47 | * instead. For values that are not set (e.g., dev is NULL, hwaddress is 48 | * zero), lwIP will retrieve them from the interface. 49 | * 50 | * If no netfrontif struct is passed (via netif->state), lwIP is opening and 51 | * managing one by itself. lwIP will only close self-opened devices on 52 | * netif_exit(). 53 | */ 54 | struct netfrontif { 55 | uint8_t vif_id; 56 | struct netfront_dev *dev; 57 | struct eth_addr hwaddr; 58 | 59 | /* the following fields are used internally */ 60 | #ifndef CONFIG_LWIP_NOTHREADS 61 | volatile int _thread_exit; 62 | char _thread_name[6]; 63 | #endif 64 | int _state_is_private; 65 | int _dev_is_private; 66 | int _hwaddr_is_private; 67 | }; 68 | 69 | #ifdef CONFIG_LWIP_NOTHREADS 70 | /* NIC I/O handling: has to be called periodically 71 | * to get received by the lwIP stack. 72 | * 73 | * Note: On threaded configuration, this call 74 | * is executed by a thread created for the device. 75 | * In this case, it has just to be ensured that this 76 | * thread get scheduled frequently. 77 | */ 78 | #define netfrontif_poll(netif) \ 79 | network_rx(((struct netfrontif *) ((netif)->state))->dev) 80 | #endif 81 | 82 | err_t netfrontif_init(struct netif *netif); 83 | 84 | #ifdef CONFIG_SELECT_POLL 85 | #define netfrontif_fd(netif) \ 86 | netfront_get_fd(((struct netfrontif *) ((netif)->state))->dev) 87 | #endif 88 | 89 | #endif /* __LWIP_NET_H__ */ 90 | -------------------------------------------------------------------------------- /include/mm.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | * 3 | * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge 4 | * Copyright (c) 2005, Keir A Fraser 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to 8 | * deal in the Software without restriction, including without limitation the 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | * sell copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef _MM_H_ 26 | #define _MM_H_ 27 | 28 | #if defined(__i386__) 29 | #include 30 | #elif defined(__x86_64__) 31 | #include 32 | #else 33 | #error "Unsupported architecture" 34 | #endif 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER 42 | #define STACK_SIZE __STACK_SIZE 43 | 44 | 45 | void init_mm(void); 46 | unsigned long alloc_pages(int order); 47 | #define alloc_page() alloc_pages(0) 48 | void free_pages(void *pointer, int order); 49 | #define free_page(p) free_pages(p, 0) 50 | 51 | unsigned long mm_total_pages(void); 52 | unsigned long mm_free_pages(void); 53 | unsigned long arch_mem_size(void); 54 | #define arch_reserved_mem() \ 55 | (arch_mem_size() - (mm_total_pages() << PAGE_SHIFT)) 56 | 57 | static __inline__ int get_order(unsigned long size) 58 | { 59 | int order; 60 | size = (size-1) >> PAGE_SHIFT; 61 | for ( order = 0; size; order++ ) 62 | size >>= 1; 63 | return order; 64 | } 65 | 66 | void arch_init_demand_mapping_area(unsigned long max_pfn); 67 | void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p); 68 | void arch_init_p2m(unsigned long max_pfn_p); 69 | 70 | unsigned long allocate_ondemand(unsigned long n, unsigned long alignment); 71 | /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */ 72 | void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride, 73 | unsigned long increment, unsigned long alignment, domid_t id, 74 | int *err, unsigned long prot); 75 | void do_map_frames(unsigned long addr, 76 | const unsigned long *f, unsigned long n, unsigned long stride, 77 | unsigned long increment, domid_t id, int *err, unsigned long prot); 78 | int unmap_frames(unsigned long va, unsigned long num_frames); 79 | int share_frames(unsigned long va, unsigned long orig_va, unsigned long num_frames, 80 | int readonly); 81 | unsigned long alloc_contig_pages(int order, unsigned int addr_bits); 82 | #ifdef HAVE_LIBC 83 | extern unsigned long heap, brk, heap_mapped, heap_end; 84 | #define mm_heap_pages() ((heap_mapped - heap) >> PAGE_SHIFT) 85 | #endif 86 | 87 | int free_physical_pages(xen_pfn_t *mfns, int n); 88 | void fini_mm(void); 89 | 90 | #endif /* _MM_H_ */ 91 | -------------------------------------------------------------------------------- /include/netfront.h: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef HAVE_LWIP 3 | #include 4 | #include 5 | #endif 6 | 7 | #if defined CONFIG_NETFRONT_LWIP_ONLY && !defined HAVE_LWIP 8 | #error "netfront: Cannot build netfront purely for lwIP without having lwIP" 9 | #endif 10 | 11 | struct netfront_dev; 12 | void netfront_rx(struct netfront_dev *dev); 13 | #define network_rx(dev) netfront_rx(dev); 14 | #ifndef CONFIG_NETFRONT_LWIP_ONLY 15 | void netfront_set_rx_handler(struct netfront_dev *dev, void (*thenetif_rx)(unsigned char* data, int len, void *arg), void *arg); 16 | void netfront_xmit(struct netfront_dev *dev, unsigned char* data, int len); 17 | #endif 18 | struct netfront_dev *init_netfront(char *nodename, void (*netif_rx)(unsigned char *data, int len, void *arg), unsigned char rawmac[6], char **ip); 19 | #ifdef HAVE_LWIP 20 | void netfront_set_rx_pbuf_handler(struct netfront_dev *dev, void (*thenetif_rx)(struct pbuf *p, void *arg), void *arg); 21 | err_t netfront_xmit_pbuf(struct netfront_dev *dev, struct pbuf *p, int co_type, int push); 22 | void netfront_xmit_push(struct netfront_dev *dev); 23 | #endif 24 | void shutdown_netfront(struct netfront_dev *dev); 25 | void suspend_netfront(void); 26 | void resume_netfront(void); 27 | #ifdef HAVE_LIBC 28 | int netfront_tap_open(char *nodename); 29 | #ifndef CONFIG_NETFRONT_LWIP_ONLY 30 | ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t len); 31 | #endif 32 | #endif 33 | 34 | extern struct wait_queue_head netfront_queue; 35 | 36 | #ifdef HAVE_LWIP 37 | struct eth_addr *netfront_get_hwaddr(struct netfront_dev *dev, struct eth_addr *out); 38 | 39 | #if defined CONFIG_START_NETWORK || defined CONFIG_INCLUDE_START_NETWORK 40 | /* Call this to bring up the netfront interface and the lwIP stack. 41 | * N.B. _must_ be called from a thread; it's not safe to call this from 42 | * app_main(). */ 43 | void start_networking(void); 44 | void stop_networking(void); 45 | #ifdef CONFIG_LWIP_NOTHREADS 46 | /* Note: DHCP is not yet supported when CONFIG_LWIP_NOTHREADS is set */ 47 | void poll_networking(void); 48 | #endif 49 | 50 | void networking_set_addr(struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw); 51 | #endif 52 | #endif 53 | 54 | #ifdef CONFIG_SELECT_POLL 55 | int netfront_get_fd(struct netfront_dev *dev); 56 | #endif 57 | 58 | #ifdef CONFIG_NETFRONT_STATS 59 | void netfront_reset_txcounters(struct netfront_dev *dev); 60 | void netfront_get_txcounters(struct netfront_dev *dev, uint64_t *out_txpkts, uint64_t *out_txbytes); 61 | #endif 62 | -------------------------------------------------------------------------------- /include/netmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniOS 3 | * 4 | * file: netmap.h 5 | * 6 | * Authors: Joao Martins 7 | * 8 | * 9 | * Copyright (c) 2014, NEC Europe Ltd., NEC Corporation. All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. Neither the name of the copyright holder nor the names of its 21 | * contributors may be used to endorse or promote products derived from 22 | * this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | */ 37 | 38 | #ifndef _NET_NETMAP_MINI_H_ 39 | #define _NET_NETMAP_MINI_H_ 40 | 41 | #define NM_CACHE_ALIGN 128 42 | struct netmap_slot { 43 | uint32_t buf_idx; /* buffer index */ 44 | uint16_t len; /* packet length, to be copied to/from the hw ring */ 45 | uint16_t flags; /* buf changed, etc. */ 46 | uint64_t ptr; /* grant reference or indirect buffer */ 47 | }; 48 | 49 | struct netmap_ring { 50 | /* 51 | * buf_ofs is meant to be used through macros. 52 | * It contains the offset of the buffer region from this 53 | * descriptor. 54 | */ 55 | const int64_t buf_ofs; 56 | const uint32_t num_slots; /* number of slots in the ring. */ 57 | const uint32_t nr_buf_size; 58 | const uint16_t ringid; 59 | const uint16_t dir; /* 0: tx, 1: rx */ 60 | 61 | uint32_t head; /* (u) first user slot */ 62 | uint32_t cur; /* (u) wakeup point */ 63 | uint32_t tail; /* (k) first kernel slot */ 64 | 65 | uint32_t flags; 66 | 67 | struct timeval ts; /* (k) time of last *sync() */ 68 | 69 | /* opaque room for a mutex or similar object */ 70 | uint8_t sem[128] __attribute__((__aligned__(NM_CACHE_ALIGN))); 71 | 72 | /* the slots follow. This struct has variable size */ 73 | struct netmap_slot slot[0]; /* array of slots. */ 74 | }; 75 | 76 | #define NETMAP_RING_NEXT(r, i) \ 77 | ((i)+1 == (r)->num_slots ? 0 : (i) + 1 ) 78 | 79 | /* 80 | * check if space is available in the ring. 81 | */ 82 | static inline int 83 | nm_ring_empty(struct netmap_ring *ring) 84 | { 85 | return (ring->cur == ring->tail); 86 | } 87 | 88 | static inline int 89 | nm_ring_space(struct netmap_ring *ring) 90 | { 91 | int ret = ring->tail - ring->cur; 92 | if (ret < 0) 93 | ret += ring->num_slots; 94 | return ret; 95 | } 96 | 97 | static inline 98 | void pkt_copy(const void *_src, void *_dst, int l) 99 | { 100 | const uint64_t *src = _src; 101 | uint64_t *dst = _dst; 102 | for (; l > 0; l-=64) { 103 | *dst++ = *src++; 104 | *dst++ = *src++; 105 | *dst++ = *src++; 106 | *dst++ = *src++; 107 | *dst++ = *src++; 108 | *dst++ = *src++; 109 | *dst++ = *src++; 110 | *dst++ = *src++; 111 | } 112 | } 113 | 114 | 115 | #endif /* _NET_NETMAP_MINI_H_ */ 116 | -------------------------------------------------------------------------------- /include/pcifront.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct pcifront_dev; 4 | void pcifront_watches(void *opaque); 5 | struct pcifront_dev *init_pcifront(char *nodename); 6 | void pcifront_op(struct pcifront_dev *dev, struct xen_pci_op *op); 7 | void pcifront_scan(struct pcifront_dev *dev, void (*fun)(unsigned int domain, unsigned int bus, unsigned slot, unsigned int fun)); 8 | int pcifront_conf_read(struct pcifront_dev *dev, 9 | unsigned int dom, 10 | unsigned int bus, unsigned int slot, unsigned int fun, 11 | unsigned int off, unsigned int size, unsigned int *val); 12 | int pcifront_conf_write(struct pcifront_dev *dev, 13 | unsigned int dom, 14 | unsigned int bus, unsigned int slot, unsigned int fun, 15 | unsigned int off, unsigned int size, unsigned int val); 16 | int pcifront_enable_msi(struct pcifront_dev *dev, 17 | unsigned int dom, 18 | unsigned int bus, unsigned int slot, unsigned int fun); 19 | int pcifront_disable_msi(struct pcifront_dev *dev, 20 | unsigned int dom, 21 | unsigned int bus, unsigned int slot, unsigned int fun); 22 | int pcifront_enable_msix(struct pcifront_dev *dev, 23 | unsigned int dom, 24 | unsigned int bus, unsigned int slot, unsigned int fun, 25 | struct xen_msix_entry *entries, int n); 26 | int pcifront_disable_msix(struct pcifront_dev *dev, 27 | unsigned int dom, 28 | unsigned int bus, unsigned int slot, unsigned int fun); 29 | void shutdown_pcifront(struct pcifront_dev *dev); 30 | -------------------------------------------------------------------------------- /include/posix/arpa/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_ARPA_INET_H_ 2 | #define _POSIX_ARPA_INET_H_ 3 | 4 | #include 5 | 6 | #endif /* _POSIX_ARPA_INET_H_ */ 7 | 8 | -------------------------------------------------------------------------------- /include/posix/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_DIRENT_H 2 | #define _POSIX_DIRENT_H 3 | 4 | #include 5 | 6 | struct dirent { 7 | char *d_name; 8 | }; 9 | 10 | typedef struct { 11 | struct dirent dirent; 12 | char *name; 13 | int32_t offset; 14 | char **entries; 15 | int32_t curentry; 16 | int32_t nbentries; 17 | int has_more; 18 | } DIR; 19 | 20 | DIR *opendir(const char *name); 21 | struct dirent *readdir(DIR *dir); 22 | int closedir(DIR *dir); 23 | 24 | #endif /* _POSIX_DIRENT_H */ 25 | -------------------------------------------------------------------------------- /include/posix/err.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_ERR_H 2 | #define _POSIX_ERR_H 3 | 4 | #include 5 | 6 | void err(int eval, const char *fmt, ...); 7 | void errx(int eval, const char *fmt, ...); 8 | void warn(const char *fmt, ...); 9 | void warnx(const char *fmt, ...); 10 | void verr(int eval, const char *fmt, va_list args); 11 | void verrx(int eval, const char *fmt, va_list args); 12 | void vwarn(const char *fmt, va_list args); 13 | void vwarnx(const char *fmt, va_list args); 14 | 15 | #endif /* _POSIX_ERR_H */ 16 | -------------------------------------------------------------------------------- /include/posix/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_FCNTL_H 2 | #define _POSIX_FCNTL_H 3 | 4 | #include_next 5 | 6 | #define F_ULOCK 0 7 | #define F_LOCK 1 8 | #define F_TLOCK 2 9 | #define F_TEST 3 10 | 11 | #endif /* _POSIX_FCNTL_H */ 12 | -------------------------------------------------------------------------------- /include/posix/limits.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_LIMITS_H 2 | #define _POSIX_LIMITS_H 3 | 4 | #include 5 | 6 | #define CHAR_BIT 8 7 | 8 | #define SCHAR_MAX 0x7f 9 | #define SCHAR_MIN (-SCHAR_MAX-1) 10 | #define UCHAR_MAX 0xff 11 | 12 | #ifdef __CHAR_UNSIGNED__ 13 | # define CHAR_MIN 0 14 | # define CHAR_MAX UCHAR_MAX 15 | #else 16 | # define CHAR_MIN SCHAR_MIN 17 | # define CHAR_MAX SCHAR_MAX 18 | #endif 19 | 20 | #define INT_MAX 0x7fffffff 21 | #define INT_MIN (-INT_MAX-1) 22 | #define UINT_MAX 0xffffffff 23 | 24 | #define SHRT_MIN (-0x8000) 25 | #define SHRT_MAX 0x7fff 26 | #define USHRT_MAX 0xffff 27 | 28 | #if defined(__x86_64__) 29 | # define LONG_MAX 0x7fffffffffffffffL 30 | # define ULONG_MAX 0xffffffffffffffffUL 31 | #else 32 | # define LONG_MAX 0x7fffffffL 33 | # define ULONG_MAX 0xffffffffUL 34 | #endif 35 | #define LONG_MIN (-LONG_MAX-1L) 36 | 37 | #define LLONG_MAX 0x7fffffffffffffffLL 38 | #define LLONG_MIN (-LLONG_MAX-1LL) 39 | #define ULLONG_MAX 0xffffffffffffffffULL 40 | 41 | #define LONG_LONG_MIN LLONG_MIN 42 | #define LONG_LONG_MAX LLONG_MAX 43 | #define ULONG_LONG_MAX ULLONG_MAX 44 | 45 | #define PATH_MAX __PAGE_SIZE 46 | #define PAGE_SIZE __PAGE_SIZE 47 | 48 | #endif /* _POSIX_LIMITS_H */ 49 | -------------------------------------------------------------------------------- /include/posix/net/if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is mostly taken from NetBSD net/if.h 3 | * Changes: Stefano Stabellini 4 | * 5 | ****************************************************************************** 6 | * 7 | * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. 8 | * All rights reserved. 9 | * 10 | * This code is derived from software contributed to The NetBSD Foundation 11 | * by William Studenmund and Jason R. Thorpe. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 23 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 26 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * Copyright (c) 1982, 1986, 1989, 1993 37 | * The Regents of the University of California. All rights reserved. 38 | * 39 | * Redistribution and use in source and binary forms, with or without 40 | * modification, are permitted provided that the following conditions 41 | * are met: 42 | * 1. Redistributions of source code must retain the above copyright 43 | * notice, this list of conditions and the following disclaimer. 44 | * 2. Redistributions in binary form must reproduce the above copyright 45 | * notice, this list of conditions and the following disclaimer in the 46 | * documentation and/or other materials provided with the distribution. 47 | * 3. Neither the name of the University nor the names of its contributors 48 | * may be used to endorse or promote products derived from this software 49 | * without specific prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 61 | * SUCH DAMAGE. 62 | * 63 | */ 64 | 65 | #ifndef _NET_IF_H_ 66 | #define _NET_IF_H_ 67 | 68 | /* 69 | * Length of interface external name, including terminating '\0'. 70 | * Note: this is the same size as a generic device's external name. 71 | */ 72 | #define IF_NAMESIZE 16 73 | 74 | struct if_nameindex { 75 | unsigned int if_index; /* 1, 2, ... */ 76 | char *if_name; /* null terminated name: "le0", ... */ 77 | }; 78 | 79 | unsigned int if_nametoindex(const char *); 80 | char * if_indextoname(unsigned int, char *); 81 | struct if_nameindex * if_nameindex(void); 82 | void if_freenameindex(struct if_nameindex *); 83 | 84 | #endif /* !_NET_IF_H_ */ 85 | 86 | -------------------------------------------------------------------------------- /include/posix/netdb.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_NETDB_H_ 2 | #define _POSIX_NETDB_H_ 3 | 4 | struct hostent { 5 | char *h_addr; 6 | }; 7 | #define gethostbyname(buf) NULL 8 | 9 | #endif /* _POSIX_NETDB_H_ */ 10 | -------------------------------------------------------------------------------- /include/posix/netinet/in.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SYS_IN_H_ 2 | #define _POSIX_SYS_IN_H_ 3 | 4 | #include 5 | #include 6 | 7 | #endif /* _POSIX_SYS_IN_H_ */ 8 | -------------------------------------------------------------------------------- /include/posix/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SYS_TCP_H_ 2 | #define _POSIX_SYS_TCP_H_ 3 | 4 | #include 5 | 6 | #endif /* _POSIX_SYS_TCP_H_ */ 7 | -------------------------------------------------------------------------------- /include/posix/poll.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/posix/pthread.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_PTHREAD_H 2 | #define _POSIX_PTHREAD_H 3 | 4 | #include 5 | 6 | /* Let's be single-threaded for now. */ 7 | 8 | typedef struct { 9 | void *ptr; 10 | } *pthread_key_t; 11 | static inline int pthread_key_create(pthread_key_t *key, void (*destr_function)(void*)) 12 | { 13 | *key = malloc(sizeof(**key)); 14 | (*key)->ptr = NULL; 15 | return 0; 16 | } 17 | static inline int pthread_setspecific(pthread_key_t key, const void *pointer) 18 | { 19 | key->ptr = (void*) pointer; 20 | return 0; 21 | } 22 | static inline void *pthread_getspecific(pthread_key_t key) 23 | { 24 | return key->ptr; 25 | } 26 | static inline int pthread_key_delete(pthread_key_t key) 27 | { 28 | free(key); 29 | return 0; 30 | } 31 | 32 | 33 | 34 | typedef struct {} pthread_mutexattr_t; 35 | static inline int pthread_mutexattr_init(pthread_mutexattr_t *mattr) { return 0; } 36 | #define PTHREAD_MUTEX_NORMAL 0 37 | #define PTHREAD_MUTEX_RECURSIVE 1 38 | static inline int pthread_mutexattr_settype(pthread_mutexattr_t *mattr, int kind) { return 0; } 39 | static inline int pthread_mutexattr_destroy(pthread_mutexattr_t *mattr) { return 0; } 40 | typedef struct {} pthread_mutex_t; 41 | #define PTHREAD_MUTEX_INITIALIZER {} 42 | static inline int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *mattr) { return 0; } 43 | static inline int pthread_mutex_lock(pthread_mutex_t *mutex) { return 0; } 44 | static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) { return 0; } 45 | 46 | 47 | 48 | typedef struct { 49 | int done; 50 | } pthread_once_t; 51 | #define PTHREAD_ONCE_INIT { 0 } 52 | 53 | static inline int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) 54 | { 55 | if (!once_control->done) { 56 | once_control->done = 1; 57 | init_routine(); 58 | } 59 | return 0; 60 | } 61 | 62 | #define __thread 63 | 64 | #endif /* _POSIX_PTHREAD_H */ 65 | -------------------------------------------------------------------------------- /include/posix/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SIGNAL_H 2 | #define _POSIX_SIGNAL_H 3 | 4 | #include_next 5 | 6 | int sigaction(int signum, const struct sigaction * __restrict, 7 | struct sigaction * __restrict); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /include/posix/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_STDLIB_H 2 | #define _POSIX_STDLIB_H 3 | 4 | #include_next 5 | 6 | #define realpath(p,r) strcpy(r,p) 7 | 8 | #endif /* _POSIX_STDLIB_H */ 9 | -------------------------------------------------------------------------------- /include/posix/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_STRINGS_H 2 | #define _POSIX_STRINGS_H 3 | 4 | #include 5 | 6 | #define bzero(ptr, size) (memset((ptr), '\0', (size)), (void) 0) 7 | 8 | int ffs (int i); 9 | int ffsl (long int li); 10 | int ffsll (long long int lli); 11 | 12 | #endif /* _POSIX_STRINGS_H */ 13 | -------------------------------------------------------------------------------- /include/posix/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SYS_IOCTL_H 2 | #define _POSIX_SYS_IOCTL_H 3 | 4 | int ioctl(int fd, int request, ...); 5 | 6 | #define _IOC_NONE 0 7 | #define _IOC_WRITE 1 8 | #define _IOC_READ 2 9 | 10 | #define _IOC(rw, class, n, size) \ 11 | (((rw ) << 30) | \ 12 | ((class) << 22) | \ 13 | ((n ) << 14) | \ 14 | ((size ) << 0)) 15 | 16 | #endif /* _POSIX_SYS_IOCTL_H */ 17 | -------------------------------------------------------------------------------- /include/posix/sys/mman.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SYS_MMAN_H 2 | #define _POSIX_SYS_MMAN_H 3 | 4 | #define PROT_READ 0x1 5 | #define PROT_WRITE 0x2 6 | #define PROT_EXEC 0x4 7 | 8 | #define MAP_SHARED 0x01 9 | #define MAP_PRIVATE 0x02 10 | #define MAP_ANON 0x20 11 | 12 | /* Pages are always resident anyway */ 13 | #define MAP_LOCKED 0x0 14 | 15 | #define MAP_FAILED ((void*)0) 16 | 17 | void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) asm("mmap64"); 18 | int munmap(void *start, size_t length); 19 | static inline mlock(const void *addr, size_t len) { return 0; } 20 | static inline munlock(const void *addr, size_t len) { return 0; } 21 | 22 | #endif /* _POSIX_SYS_MMAN_H */ 23 | -------------------------------------------------------------------------------- /include/posix/sys/poll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This code is mostly taken from FreeBSD sys/sys/poll.h 3 | * Changes: Stefano Stabellini 4 | * 5 | **************************************************************************** 6 | * Copyright (c) 1997 Peter Wemm 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef _POSIX_SYS_POLL_H_ 34 | #define _POSIX_SYS_POLL_H_ 35 | 36 | /* 37 | * This file is intended to be compatible with the traditional poll.h. 38 | */ 39 | 40 | typedef unsigned int nfds_t; 41 | 42 | /* 43 | * This structure is passed as an array to poll(2). 44 | */ 45 | struct pollfd { 46 | int fd; /* which file descriptor to poll */ 47 | short events; /* events we are interested in */ 48 | short revents; /* events found on return */ 49 | }; 50 | 51 | /* 52 | * Requestable events. If poll(2) finds any of these set, they are 53 | * copied to revents on return. 54 | * XXX Note that FreeBSD doesn't make much distinction between POLLPRI 55 | * and POLLRDBAND since none of the file types have distinct priority 56 | * bands - and only some have an urgent "mode". 57 | * XXX Note POLLIN isn't really supported in true SVSV terms. Under SYSV 58 | * POLLIN includes all of normal, band and urgent data. Most poll handlers 59 | * on FreeBSD only treat it as "normal" data. 60 | */ 61 | #define POLLIN 0x0001 /* any readable data available */ 62 | #define POLLPRI 0x0002 /* OOB/Urgent readable data */ 63 | #define POLLOUT 0x0004 /* file descriptor is writeable */ 64 | #define POLLRDNORM 0x0040 /* non-OOB/URG data available */ 65 | #define POLLWRNORM POLLOUT /* no write type differentiation */ 66 | #define POLLRDBAND 0x0080 /* OOB/Urgent readable data */ 67 | #define POLLWRBAND 0x0100 /* OOB/Urgent data can be written */ 68 | 69 | /* 70 | * These events are set if they occur regardless of whether they were 71 | * requested. 72 | */ 73 | #define POLLERR 0x0008 /* some poll error occurred */ 74 | #define POLLHUP 0x0010 /* file descriptor was "hung up" */ 75 | #define POLLNVAL 0x0020 /* requested events "invalid" */ 76 | 77 | int poll(struct pollfd _pfd[], nfds_t _nfds, int _timeout); 78 | 79 | #endif /* _POSIX_SYS_POLL_H_ */ 80 | -------------------------------------------------------------------------------- /include/posix/sys/select.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SELECT_H 2 | #define _POSIX_SELECT_H 3 | 4 | #include 5 | int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); 6 | 7 | #endif /* _POSIX_SELECT_H */ 8 | -------------------------------------------------------------------------------- /include/posix/sys/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SYS_SOCKET_H_ 2 | #define _POSIX_SYS_SOCKET_H_ 3 | 4 | #include 5 | #include 6 | 7 | int accept(int s, struct sockaddr *addr, socklen_t *addrlen); 8 | int bind(int s, struct sockaddr *name, socklen_t namelen); 9 | int shutdown(int s, int how); 10 | int getpeername (int s, struct sockaddr *name, socklen_t *namelen); 11 | int getsockname (int s, struct sockaddr *name, socklen_t *namelen); 12 | int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); 13 | int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); 14 | int close(int s); 15 | int connect(int s, struct sockaddr *name, socklen_t namelen); 16 | int listen(int s, int backlog); 17 | int recv(int s, void *mem, int len, unsigned int flags); 18 | //int read(int s, void *mem, int len); 19 | int recvfrom(int s, void *mem, int len, unsigned int flags, 20 | struct sockaddr *from, socklen_t *fromlen); 21 | int send(int s, void *dataptr, int size, unsigned int flags); 22 | int sendto(int s, void *dataptr, int size, unsigned int flags, 23 | struct sockaddr *to, socklen_t tolen); 24 | int socket(int domain, int type, int protocol); 25 | //int write(int s, void *dataptr, int size); 26 | int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, 27 | struct timeval *timeout); 28 | //int ioctl(int s, long cmd, void *argp); 29 | int getsockname(int s, struct sockaddr *name, socklen_t *namelen); 30 | 31 | #endif /* _POSIX_SYS_SOCKET_H_ */ 32 | -------------------------------------------------------------------------------- /include/posix/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SYS_STAT_H 2 | #define _POSIX_SYS_STAT_H 3 | 4 | #include_next 5 | int fstat(int fd, struct stat *buf) asm("fstat64"); 6 | 7 | #endif /* _POSIX_SYS_STAT_H */ 8 | -------------------------------------------------------------------------------- /include/posix/syslog.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_SYSLOG_H 2 | #define _POSIX_SYSLOG_H 3 | 4 | #include 5 | 6 | #define LOG_PID 0 7 | #define LOG_CONS 0 8 | #define LOG_NDELAY 0 9 | #define LOG_ODELAY 0 10 | #define LOG_NOWAIT 0 11 | 12 | #define LOG_KERN 0 13 | #define LOG_USER 0 14 | #define LOG_MAIL 0 15 | #define LOG_NEWS 0 16 | #define LOG_UUCP 0 17 | #define LOG_DAEMON 0 18 | #define LOG_AUTH 0 19 | #define LOG_CRON 0 20 | #define LOG_LPR 0 21 | 22 | /* TODO: support */ 23 | #define LOG_EMERG 0 24 | #define LOG_ALERT 1 25 | #define LOG_CRIT 2 26 | #define LOG_ERR 3 27 | #define LOG_WARNING 4 28 | #define LOG_NOTICE 5 29 | #define LOG_INFO 6 30 | #define LOG_DEBUG 7 31 | 32 | void openlog(const char *ident, int option, int facility); 33 | void syslog(int priority, const char *format, ...); 34 | void closelog(void); 35 | void vsyslog(int priority, const char *format, va_list ap); 36 | 37 | #endif /* _POSIX_SYSLOG_H */ 38 | -------------------------------------------------------------------------------- /include/posix/termios.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_TERMIOS_H 2 | #define _POSIX_TERMIOS_H 3 | 4 | #define NCC 32 5 | 6 | struct termios { 7 | unsigned long c_iflag; 8 | unsigned long c_oflag; 9 | unsigned long c_lflag; 10 | unsigned long c_cflag; 11 | unsigned char c_cc[NCC]; 12 | }; 13 | 14 | /* modem lines */ 15 | #define TIOCM_DTR 0x002 16 | #define TIOCM_RTS 0x004 17 | #define TIOCM_CTS 0x020 18 | #define TIOCM_CAR 0x040 19 | #define TIOCM_RI 0x080 20 | #define TIOCM_DSR 0x100 21 | 22 | /* c_iflag */ 23 | #define IGNBRK 0x00000001 24 | #define BRKINT 0x00000002 25 | #define IGNPAR 0x00000004 26 | #define PARMRK 0x00000008 27 | #define INPCK 0x00000010 28 | #define ISTRIP 0x00000020 29 | #define INLCR 0x00000040 30 | #define IGNCR 0x00000080 31 | #define ICRNL 0x00000100 32 | #define IUCLC 0x00000200 33 | #define IXON 0x00000400 34 | #define IXANY 0x00000800 35 | #define IXOFF 0x00001000 36 | #define IMAXBEL 0x00002000 37 | #define IUTF8 0x00004000 38 | 39 | /* c_oflag */ 40 | #define OPOST 0x00000001 41 | #define OLCUC 0x00000002 42 | #define ONLCR 0x00000004 43 | #define OCRNL 0x00000008 44 | #define ONOCR 0x00000010 45 | #define ONLRET 0x00000020 46 | #define OFILL 0x00000040 47 | #define OFDEL 0x00000080 48 | 49 | /* c_lflag */ 50 | #define ISIG 0x00000001 51 | #define ICANON 0x00000002 52 | #define XCASE 0x00000004 53 | #define ECHO 0x00000008 54 | #define ECHOE 0x00000010 55 | #define ECHOK 0x00000020 56 | #define ECHONL 0x00000040 57 | #define NOFLSH 0x00000080 58 | #define TOSTOP 0x00000100 59 | #define ECHOCTL 0x00000200 60 | #define ECHOPRT 0x00000400 61 | #define ECHOKE 0x00000800 62 | #define FLUSHO 0x00002000 63 | #define PENDIN 0x00004000 64 | #define IEXTEN 0x00008000 65 | 66 | /* c_cflag */ 67 | #define CSIZE 0x00000030 68 | #define CS8 0x00000030 69 | #define CSTOPB 0x00000040 70 | #define CREAD 0x00000080 71 | #define PARENB 0x00000100 72 | #define PARODD 0x00000200 73 | #define HUPCL 0x00000400 74 | #define CLOCAL 0x00000800 75 | 76 | /* c_cc */ 77 | #define VTIME 5 78 | #define VMIN 6 79 | 80 | #define TCSANOW 0 81 | #define TCSADRAIN 1 82 | #define TCSAFLUSH 2 83 | 84 | int tcsetattr(int fildes, int action, const struct termios *tios); 85 | int tcgetattr(int fildes, struct termios *tios); 86 | 87 | #endif /* _POSIX_TERMIOS_H */ 88 | -------------------------------------------------------------------------------- /include/posix/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_TIME_H 2 | #define _POSIX_TIME_H 3 | 4 | #include 5 | #define CLOCK_MONOTONIC 2 6 | #include_next 7 | 8 | int nanosleep(const struct timespec *req, struct timespec *rem); 9 | int clock_gettime(clockid_t clock_id, struct timespec *tp); 10 | 11 | #endif /* _POSIX_TIME_H */ 12 | -------------------------------------------------------------------------------- /include/posix/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef _POSIX_UNISTD_H 2 | #define _POSIX_UNISTD_H 3 | 4 | #include_next 5 | 6 | uid_t getuid(void); 7 | uid_t geteuid(void); 8 | gid_t getgid(void); 9 | gid_t getegid(void); 10 | int gethostname(char *name, size_t namelen); 11 | size_t getpagesize(void); 12 | int ftruncate(int fd, off_t length); 13 | int lockf(int fd, int cmd, off_t len); 14 | int nice(int inc); 15 | 16 | #endif /* _POSIX_UNISTD_H */ 17 | -------------------------------------------------------------------------------- /include/rte_vect.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * BSD LICENSE 3 | * 4 | * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * * Neither the name of Intel Corporation nor the names of its 18 | * contributors may be used to endorse or promote products derived 19 | * from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef _RTE_VECT_H_ 35 | #define _RTE_VECT_H_ 36 | 37 | /** 38 | * @file 39 | * 40 | * RTE SSE/AVX related header. 41 | */ 42 | 43 | #if (defined(__ICC) || (__GNUC__ == 4 && __GNUC_MINOR__ < 4)) 44 | 45 | #ifdef __SSE__ 46 | #include 47 | #endif 48 | 49 | #ifdef __SSE2__ 50 | #include 51 | #endif 52 | 53 | #ifdef __SSE3__ 54 | #include 55 | #endif 56 | 57 | #if defined(__SSE4_2__) || defined(__SSE4_1__) 58 | #include 59 | #endif 60 | 61 | #if defined(__AVX__) 62 | #include 63 | #endif 64 | 65 | #else 66 | 67 | #include 68 | 69 | #endif 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | typedef __m128i xmm_t; 76 | 77 | #define XMM_SIZE (sizeof(xmm_t)) 78 | #define XMM_MASK (XMM_SIZE - 1) 79 | 80 | typedef union rte_xmm { 81 | xmm_t x; 82 | uint8_t u8[XMM_SIZE / sizeof(uint8_t)]; 83 | uint16_t u16[XMM_SIZE / sizeof(uint16_t)]; 84 | uint32_t u32[XMM_SIZE / sizeof(uint32_t)]; 85 | uint64_t u64[XMM_SIZE / sizeof(uint64_t)]; 86 | double pd[XMM_SIZE / sizeof(double)]; 87 | } rte_xmm_t; 88 | 89 | #ifdef __AVX__ 90 | 91 | typedef __m256i ymm_t; 92 | 93 | #define YMM_SIZE (sizeof(ymm_t)) 94 | #define YMM_MASK (YMM_SIZE - 1) 95 | 96 | typedef union rte_ymm { 97 | ymm_t y; 98 | xmm_t x[YMM_SIZE / sizeof(xmm_t)]; 99 | uint8_t u8[YMM_SIZE / sizeof(uint8_t)]; 100 | uint16_t u16[YMM_SIZE / sizeof(uint16_t)]; 101 | uint32_t u32[YMM_SIZE / sizeof(uint32_t)]; 102 | uint64_t u64[YMM_SIZE / sizeof(uint64_t)]; 103 | double pd[YMM_SIZE / sizeof(double)]; 104 | } rte_ymm_t; 105 | 106 | #endif /* __AVX__ */ 107 | 108 | #ifdef RTE_ARCH_I686 109 | #define _mm_cvtsi128_si64(a) ({ \ 110 | rte_xmm_t m; \ 111 | m.x = (a); \ 112 | (m.u64[0]); \ 113 | }) 114 | #endif 115 | 116 | /* 117 | * Prior to version 12.1 icc doesn't support _mm_set_epi64x. 118 | */ 119 | #if (defined(__ICC) && __ICC < 1210) 120 | #define _mm_set_epi64x(a, b) ({ \ 121 | rte_xmm_t m; \ 122 | m.u64[0] = b; \ 123 | m.u64[1] = a; \ 124 | (m.x); \ 125 | }) 126 | #endif /* (defined(__ICC) && __ICC < 1210) */ 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif /* _RTE_VECT_H_ */ 133 | -------------------------------------------------------------------------------- /include/sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCHED_H__ 2 | #define __SCHED_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #ifdef HAVE_LIBC 8 | #include 9 | #endif 10 | 11 | struct thread 12 | { 13 | char *name; 14 | char *stack; 15 | /* keep in that order */ 16 | unsigned long sp; /* Stack pointer */ 17 | unsigned long ip; /* Instruction pointer */ 18 | MINIOS_TAILQ_ENTRY(struct thread) thread_list; 19 | uint32_t flags; 20 | s_time_t wakeup_time; 21 | #ifdef HAVE_LIBC 22 | struct _reent reent; 23 | #endif 24 | }; 25 | 26 | extern struct thread *idle_thread; 27 | void idle_thread_fn(void *unused); 28 | 29 | #define RUNNABLE_FLAG 0x00000001 30 | 31 | #define is_runnable(_thread) (_thread->flags & RUNNABLE_FLAG) 32 | #define set_runnable(_thread) (_thread->flags |= RUNNABLE_FLAG) 33 | #define clear_runnable(_thread) (_thread->flags &= ~RUNNABLE_FLAG) 34 | 35 | #define switch_threads(prev, next) arch_switch_threads(prev, next) 36 | 37 | /* Architecture specific setup of thread creation. */ 38 | struct thread* arch_create_thread(char *name, void (*function)(void *), 39 | void *data); 40 | 41 | void init_sched(void); 42 | void run_idle_thread(void); 43 | struct thread* create_thread(char *name, void (*function)(void *), void *data); 44 | void exit_thread(void) __attribute__((noreturn)); 45 | void schedule(void); 46 | 47 | #ifdef __INSIDE_MINIOS__ 48 | #define current get_current() 49 | #endif 50 | 51 | void wake(struct thread *thread); 52 | void block(struct thread *thread); 53 | void msleep(uint32_t millisecs); 54 | 55 | #endif /* __SCHED_H__ */ 56 | -------------------------------------------------------------------------------- /include/semaphore.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEMAPHORE_H_ 2 | #define _SEMAPHORE_H_ 3 | 4 | #include 5 | #include 6 | 7 | /* 8 | * Implementation of semaphore in Mini-os is simple, because 9 | * there are no preemptive threads, the atomicity is guaranteed. 10 | */ 11 | 12 | struct semaphore 13 | { 14 | int count; 15 | struct wait_queue_head wait; 16 | }; 17 | 18 | /* 19 | * the semaphore definition 20 | */ 21 | struct rw_semaphore { 22 | signed long count; 23 | spinlock_t wait_lock; 24 | int debug; 25 | }; 26 | 27 | #define __SEMAPHORE_INITIALIZER(name, n) \ 28 | { \ 29 | .count = n, \ 30 | .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \ 31 | } 32 | 33 | #define __MUTEX_INITIALIZER(name) \ 34 | __SEMAPHORE_INITIALIZER(name,1) 35 | 36 | #define __DECLARE_SEMAPHORE_GENERIC(name,count) \ 37 | struct semaphore name = __SEMAPHORE_INITIALIZER(name,count) 38 | 39 | #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) 40 | 41 | #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0) 42 | 43 | static inline void init_SEMAPHORE(struct semaphore *sem, int count) 44 | { 45 | sem->count = count; 46 | init_waitqueue_head(&sem->wait); 47 | } 48 | 49 | #define init_MUTEX(sem) init_SEMAPHORE(sem, 1) 50 | 51 | static inline int trydown(struct semaphore *sem) 52 | { 53 | unsigned long flags; 54 | int ret = 0; 55 | local_irq_save(flags); 56 | if (sem->count > 0) { 57 | ret = 1; 58 | sem->count--; 59 | } 60 | local_irq_restore(flags); 61 | return ret; 62 | } 63 | 64 | static void inline down(struct semaphore *sem) 65 | { 66 | unsigned long flags; 67 | while (1) { 68 | wait_event(sem->wait, sem->count > 0); 69 | local_irq_save(flags); 70 | if (sem->count > 0) 71 | break; 72 | local_irq_restore(flags); 73 | } 74 | sem->count--; 75 | local_irq_restore(flags); 76 | } 77 | 78 | static void inline up(struct semaphore *sem) 79 | { 80 | unsigned long flags; 81 | local_irq_save(flags); 82 | sem->count++; 83 | wake_up(&sem->wait); 84 | local_irq_restore(flags); 85 | } 86 | 87 | /* FIXME! Thre read/write semaphores are unimplemented! */ 88 | static inline void init_rwsem(struct rw_semaphore *sem) 89 | { 90 | sem->count = 1; 91 | } 92 | 93 | static inline void down_read(struct rw_semaphore *sem) 94 | { 95 | } 96 | 97 | 98 | static inline void up_read(struct rw_semaphore *sem) 99 | { 100 | } 101 | 102 | static inline void up_write(struct rw_semaphore *sem) 103 | { 104 | } 105 | 106 | static inline void down_write(struct rw_semaphore *sem) 107 | { 108 | } 109 | 110 | #endif /* _SEMAPHORE_H */ 111 | -------------------------------------------------------------------------------- /include/shutdown.h: -------------------------------------------------------------------------------- 1 | #ifndef _SHUTDOWN_H_ 2 | #define _SHUTDOWN_H_ 3 | 4 | #include 5 | 6 | void init_shutdown(start_info_t *si); 7 | 8 | void kernel_shutdown(int reason) __attribute__((noreturn)); 9 | void kernel_suspend(void); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /include/spinlock.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASM_SPINLOCK_H 2 | #define __ASM_SPINLOCK_H 3 | 4 | #include 5 | 6 | /* 7 | * Your basic SMP spinlocks, allowing only a single CPU anywhere 8 | */ 9 | 10 | typedef struct { 11 | volatile unsigned int slock; 12 | } spinlock_t; 13 | 14 | 15 | #include 16 | 17 | 18 | #define SPINLOCK_MAGIC 0xdead4ead 19 | 20 | #define SPIN_LOCK_UNLOCKED ARCH_SPIN_LOCK_UNLOCKED 21 | 22 | #define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0) 23 | 24 | /* 25 | * Simple spin lock operations. There are two variants, one clears IRQ's 26 | * on the local processor, one does not. 27 | * 28 | * We make no fairness assumptions. They have a cost. 29 | */ 30 | 31 | #define spin_is_locked(x) arch_spin_is_locked(x) 32 | 33 | #define spin_unlock_wait(x) arch_spin_unlock_wait(x) 34 | 35 | 36 | #define _spin_trylock(lock) ({_raw_spin_trylock(lock) ? \ 37 | 1 : ({ 0;});}) 38 | 39 | #define _spin_lock(lock) \ 40 | do { \ 41 | _raw_spin_lock(lock); \ 42 | } while(0) 43 | 44 | #define _spin_unlock(lock) \ 45 | do { \ 46 | _raw_spin_unlock(lock); \ 47 | } while (0) 48 | 49 | 50 | #define spin_lock(lock) _spin_lock(lock) 51 | #define spin_unlock(lock) _spin_unlock(lock) 52 | 53 | #define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/sys/lock.h: -------------------------------------------------------------------------------- 1 | #ifndef _MINIOS_SYS_LOCK_H_ 2 | #define _MINIOS_SYS_LOCK_H_ 3 | 4 | #ifdef HAVE_LIBC 5 | 6 | /* Due to inclusion loop, we can not include sched.h, so have to hide things */ 7 | 8 | #include 9 | 10 | 11 | typedef struct { 12 | int busy; 13 | struct wait_queue_head wait; 14 | } _LOCK_T; 15 | 16 | #define __LOCK_INIT(class,lock) \ 17 | class _LOCK_T lock = { .wait = __WAIT_QUEUE_HEAD_INITIALIZER(lock.wait) } 18 | int ___lock_init(_LOCK_T *lock); 19 | int ___lock_acquire(_LOCK_T *lock); 20 | int ___lock_try_acquire(_LOCK_T *lock); 21 | int ___lock_release(_LOCK_T *lock); 22 | int ___lock_close(_LOCK_T *lock); 23 | #define __lock_init(__lock) ___lock_init(&__lock) 24 | #define __lock_acquire(__lock) ___lock_acquire(&__lock) 25 | #define __lock_release(__lock) ___lock_release(&__lock) 26 | #define __lock_try_acquire(__lock) ___lock_try_acquire(&__lock) 27 | #define __lock_close(__lock) 0 28 | 29 | 30 | typedef struct { 31 | struct thread *owner; 32 | int count; 33 | struct wait_queue_head wait; 34 | } _LOCK_RECURSIVE_T; 35 | 36 | #define __LOCK_INIT_RECURSIVE(class, lock) \ 37 | class _LOCK_RECURSIVE_T lock = { .wait = __WAIT_QUEUE_HEAD_INITIALIZER((lock).wait) } 38 | 39 | int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock); 40 | int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock); 41 | int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock); 42 | int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock); 43 | int ___lock_close_recursive(_LOCK_RECURSIVE_T *lock); 44 | #define __lock_init_recursive(__lock) ___lock_init_recursive(&__lock) 45 | #define __lock_acquire_recursive(__lock) ___lock_acquire_recursive(&__lock) 46 | #define __lock_release_recursive(__lock) ___lock_release_recursive(&__lock) 47 | #define __lock_try_acquire_recursive(__lock) ___lock_try_acquire_recursive(&__lock) 48 | #define __lock_close_recursive(__lock) 0 49 | 50 | #endif 51 | 52 | #endif /* _MINIOS_SYS_LOCK_H_ */ 53 | -------------------------------------------------------------------------------- /include/sys/time.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | **************************************************************************** 3 | * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge 4 | * (C) 2005 - Grzegorz Milos - Intel Research Cambridge 5 | **************************************************************************** 6 | * 7 | * File: time.h 8 | * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) 9 | * Changes: Grzegorz Milos (gm281@cam.ac.uk) 10 | * Robert Kaiser (kaiser@informatik.fh-wiesbaden.de) 11 | * 12 | * Date: Jul 2003, changes: Jun 2005, Sep 2006 13 | * 14 | * Environment: Xen Minimal OS 15 | * Description: Time and timer functions 16 | * 17 | **************************************************************************** 18 | */ 19 | 20 | #ifndef _MINIOS_SYS_TIME_H_ 21 | #define _MINIOS_SYS_TIME_H_ 22 | 23 | #ifdef HAVE_LIBC 24 | #include_next 25 | 26 | #else 27 | struct timespec { 28 | time_t tv_sec; 29 | long tv_nsec; 30 | }; 31 | 32 | struct timezone { 33 | }; 34 | 35 | struct timeval { 36 | time_t tv_sec; /* seconds */ 37 | suseconds_t tv_usec; /* microseconds */ 38 | }; 39 | 40 | int gettimeofday(struct timeval *tv, void *tz); 41 | 42 | #endif 43 | #ifdef HAVE_LIBC 44 | #include 45 | #endif 46 | 47 | #endif /* _MINIOS_SYS_TIME_H_ */ 48 | -------------------------------------------------------------------------------- /include/time.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | **************************************************************************** 3 | * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge 4 | * (C) 2005 - Grzegorz Milos - Intel Research Cambridge 5 | **************************************************************************** 6 | * 7 | * File: time.h 8 | * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) 9 | * Changes: Grzegorz Milos (gm281@cam.ac.uk) 10 | * Robert Kaiser (kaiser@informatik.fh-wiesbaden.de) 11 | * 12 | * Date: Jul 2003, changes: Jun 2005, Sep 2006 13 | * 14 | * Environment: Xen Minimal OS 15 | * Description: Time and timer functions 16 | * 17 | **************************************************************************** 18 | */ 19 | 20 | #ifndef _MINIOS_TIME_H_ 21 | #define _MINIOS_TIME_H_ 22 | #include 23 | 24 | /* 25 | * System Time 26 | * 64 bit value containing the nanoseconds elapsed since boot time. 27 | * This value is adjusted by frequency drift. 28 | * NOW() returns the current time. 29 | * The other macros are for convenience to approximate short intervals 30 | * of real time into system time 31 | */ 32 | typedef int64_t s_time_t; 33 | #define NOW() ((s_time_t)monotonic_clock()) 34 | #define SECONDS(_s) (((s_time_t)(_s)) * 1000000000UL ) 35 | #define TENTHS(_ts) (((s_time_t)(_ts)) * 100000000UL ) 36 | #define HUNDREDTHS(_hs) (((s_time_t)(_hs)) * 10000000UL ) 37 | #define MILLISECS(_ms) (((s_time_t)(_ms)) * 1000000UL ) 38 | #define MICROSECS(_us) (((s_time_t)(_us)) * 1000UL ) 39 | #define Time_Max ((s_time_t) 0x7fffffffffffffffLL) 40 | #define FOREVER Time_Max 41 | #define NSEC_TO_USEC(_nsec) ((_nsec) / 1000UL) 42 | #define NSEC_TO_MSEC(_nsec) ((_nsec) / 1000000ULL) 43 | #define NSEC_TO_SEC(_nsec) ((_nsec) / 1000000000ULL) 44 | 45 | /* wall clock time */ 46 | typedef long time_t; 47 | typedef long suseconds_t; 48 | 49 | #include 50 | 51 | #ifdef HAVE_LIBC 52 | #include_next 53 | #endif 54 | 55 | /* prototypes */ 56 | void init_time(void); 57 | void fini_time(void); 58 | void suspend_time(void); 59 | void resume_time(void); 60 | s_time_t get_s_time(void); 61 | s_time_t get_v_time(void); 62 | uint64_t monotonic_clock(void); 63 | void block_domain(s_time_t until); 64 | 65 | #endif /* _MINIOS_TIME_H_ */ 66 | -------------------------------------------------------------------------------- /include/tpm_tis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 United States Government, as represented by 3 | * the Secretary of Defense. All rights reserved. 4 | * 5 | * This code has been derived from drivers/char/tpm.c 6 | * from the linux kernel 7 | * 8 | * Copyright (C) 2004 IBM Corporation 9 | * 10 | * This code has also been derived from drivers/char/tpm/tpm_tis.c 11 | * from the linux kernel 12 | * 13 | * Copyright (C) 2005, 2006 IBM Corporation 14 | * 15 | * This program is free software; you can redistribute it and/or 16 | * modify it under the terms of the GNU General Public License 17 | * as published by the Free Software Foundation, version 2 18 | * of the License 19 | */ 20 | #ifndef TPM_TIS_H 21 | #define TPM_TIS_H 22 | 23 | #include 24 | #include 25 | 26 | #define TPM_TIS_EN_LOCL0 1 27 | #define TPM_TIS_EN_LOCL1 (1 << 1) 28 | #define TPM_TIS_EN_LOCL2 (1 << 2) 29 | #define TPM_TIS_EN_LOCL3 (1 << 3) 30 | #define TPM_TIS_EN_LOCL4 (1 << 4) 31 | #define TPM_TIS_EN_LOCLALL (TPM_TIS_EN_LOCL0 | TPM_TIS_EN_LOCL1 | TPM_TIS_EN_LOCL2 | TPM_TIS_EN_LOCL3 | TPM_TIS_EN_LOCL4) 32 | #define TPM_TIS_LOCL_INT_TO_FLAG(x) (1 << x) 33 | #define TPM_BASEADDR 0xFED40000 34 | #define TPM_PROBE_IRQ 0xFFFF 35 | 36 | struct tpm_chip; 37 | 38 | struct tpm_chip* init_tpm_tis(unsigned long baseaddr, int localities, unsigned int irq); 39 | void shutdown_tpm_tis(struct tpm_chip* tpm); 40 | 41 | int tpm_tis_request_locality(struct tpm_chip* tpm, int locality); 42 | int tpm_tis_cmd(struct tpm_chip* tpm, uint8_t* req, size_t reqlen, uint8_t** resp, size_t* resplen); 43 | 44 | #ifdef HAVE_LIBC 45 | #include 46 | #include 47 | /* POSIX IO functions: 48 | * use tpm_tis_open() to get a file descriptor to the tpm device 49 | * use write() on the fd to send a command to the backend. You must 50 | * include the entire command in a single call to write(). 51 | * use read() on the fd to read the response. You can use 52 | * fstat() to get the size of the response and lseek() to seek on it. 53 | */ 54 | int tpm_tis_open(struct tpm_chip* tpm); 55 | int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count); 56 | int tpm_tis_posix_write(int fd, const uint8_t* buf, size_t count); 57 | int tpm_tis_posix_fstat(int fd, struct stat* buf); 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /include/tpmback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 United States Government, as represented by 3 | * the Secretary of Defense. All rights reserved. 4 | * 5 | * This code has been derived from drivers/xen/tpmback/tpmback.c 6 | * from the xen 2.6.18 linux kernel 7 | * 8 | * Copyright (c) 2005, IBM Corporation 9 | * 10 | * which was itself derived from drivers/xen/netback/netback.c 11 | * from the xen 2.6.18 linux kernel 12 | * 13 | * Copyright (c) 2002-2004, K A Fraser 14 | * 15 | * This code has also been derived from drivers/xen/tpmback/xenbus.c 16 | * from the xen 2.6.18 linux kernel 17 | * 18 | * Copyright (C) 2005 IBM Corporation 19 | * Copyright (C) 2005 Rusty Russell 20 | * 21 | * This code has also been derived from drivers/xen/tpmback/interface.c 22 | * from the xen 2.6.18 linux kernel 23 | * 24 | * Copyright (c) 2005, IBM Corporation 25 | * 26 | * which was itself also derived from drvivers/xen/netback/interface.c 27 | * from the xen 2.6.18 linux kernel 28 | * 29 | * Copyright (c) 2004, Keir Fraser 30 | * 31 | * This program is free software; you can redistribute it and/or 32 | * modify it under the terms of the GNU General Public License 33 | * as published by the Free Software Foundation, version 2 34 | * of the License 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #ifndef TPMBACK_H 42 | #define TPMBACK_H 43 | 44 | struct tpmcmd { 45 | domid_t domid; /* Domid of the frontend */ 46 | uint8_t locality; /* Locality requested by the frontend */ 47 | unsigned int handle; /* Handle of the frontend */ 48 | void *opaque; /* Opaque pointer taken from the tpmback instance */ 49 | 50 | uint8_t* req; /* tpm command bits, allocated by driver, DON'T FREE IT */ 51 | unsigned int req_len; /* Size of the command in buf - set by tpmback driver */ 52 | unsigned int resp_len; /* Size of the outgoing command, 53 | you set this before passing the cmd object to tpmback_resp */ 54 | uint8_t* resp; /* Buffer for response - YOU MUST ALLOCATE IT, YOU MUST ALSO FREE IT */ 55 | }; 56 | typedef struct tpmcmd tpmcmd_t; 57 | 58 | /* Initialize the tpm backend driver */ 59 | void init_tpmback(void (*open_cb)(domid_t, unsigned int), void (*close_cb)(domid_t, unsigned int)); 60 | 61 | /* Shutdown tpm backend driver */ 62 | void shutdown_tpmback(void); 63 | 64 | /* Blocks until a tpm command is sent from any front end. 65 | * Returns a pointer to the tpm command to handle. 66 | * Do not try to free this pointer or the req buffer 67 | * This function will return NULL if the tpm backend driver 68 | * is shutdown or any other error occurs */ 69 | tpmcmd_t* tpmback_req_any(void); 70 | 71 | /* Blocks until a tpm command from the frontend at domid/handle 72 | * is sent. 73 | * Returns NULL if domid/handle is not connected, tpmback is 74 | * shutdown or shutting down, or if there is an error 75 | */ 76 | tpmcmd_t* tpmback_req(domid_t domid, unsigned int handle); 77 | 78 | /* Send the response to the tpm command back to the frontend 79 | * This function will free the tpmcmd object, but you must free the resp 80 | * buffer yourself */ 81 | void tpmback_resp(tpmcmd_t* tpmcmd); 82 | 83 | /* Waits for the first frontend to connect and then sets domid and handle appropriately. 84 | * If one or more frontends are already connected, this will set domid and handle to one 85 | * of them arbitrarily. The main use for this function is to wait until a single 86 | * frontend connection has occured. 87 | * returns 0 on success, non-zero on failure */ 88 | int tpmback_wait_for_frontend_connect(domid_t *domid, unsigned int *handle); 89 | 90 | /* returns the number of frontends connected */ 91 | int tpmback_num_frontends(void); 92 | 93 | /* Returns the uuid of the specified frontend, NULL on error. 94 | * The return value is internally allocated, so don't free it */ 95 | unsigned char* tpmback_get_uuid(domid_t domid, unsigned int handle); 96 | 97 | /* Get and set the opaque pointer for a tpmback instance */ 98 | void* tpmback_get_opaque(domid_t domid, unsigned int handle); 99 | /* Returns zero if successful, nonzero on failure (no such frontend) */ 100 | int tpmback_set_opaque(domid_t domid, unsigned int handle, void* opaque); 101 | 102 | /* Get the XSM context of the given domain (using the tpmback event channel) */ 103 | int tpmback_get_peercontext(domid_t domid, unsigned int handle, void* buffer, int buflen); 104 | #endif 105 | -------------------------------------------------------------------------------- /include/tpmfront.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 United States Government, as represented by 3 | * the Secretary of Defense. All rights reserved. 4 | * 5 | * This code has been derived from drivers/char/tpm_vtpm.c 6 | * from the xen 2.6.18 linux kernel 7 | * 8 | * Copyright (C) 2006 IBM Corporation 9 | * 10 | * This code has also been derived from drivers/char/tpm_xen.c 11 | * from the xen 2.6.18 linux kernel 12 | * 13 | * Copyright (c) 2005, IBM Corporation 14 | * 15 | * which was itself derived from drivers/xen/netfront/netfront.c 16 | * from the linux kernel 17 | * 18 | * Copyright (c) 2002-2004, K A Fraser 19 | * 20 | * This program is free software; you can redistribute it and/or 21 | * modify it under the terms of the GNU General Public License as 22 | * published by the Free Software Foundation, version 2 of the 23 | * License. 24 | */ 25 | #ifndef TPMFRONT_H 26 | #define TPMFRONT_H 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | struct tpmfront_dev { 37 | grant_ref_t ring_ref; 38 | evtchn_port_t evtchn; 39 | 40 | tpmif_shared_page_t *page; 41 | 42 | domid_t bedomid; 43 | char* nodename; 44 | char* bepath; 45 | 46 | XenbusState state; 47 | 48 | uint8_t waiting; 49 | struct wait_queue_head waitq; 50 | 51 | uint8_t* respbuf; 52 | size_t resplen; 53 | 54 | #ifdef HAVE_LIBC 55 | int fd; 56 | #endif 57 | 58 | }; 59 | 60 | 61 | /*Initialize frontend */ 62 | struct tpmfront_dev* init_tpmfront(const char* nodename); 63 | /*Shutdown frontend */ 64 | void shutdown_tpmfront(struct tpmfront_dev* dev); 65 | 66 | /* Send a tpm command to the backend and wait for the response 67 | * 68 | * @dev - frontend device 69 | * @req - request buffer 70 | * @reqlen - length of request buffer 71 | * @resp - *resp will be set to internal response buffer, don't free it! Value is undefined on error 72 | * @resplen - *resplen will be set to the length of the response. Value is undefined on error 73 | * 74 | * returns 0 on success, non zero on failure. 75 | * */ 76 | int tpmfront_cmd(struct tpmfront_dev* dev, uint8_t* req, size_t reqlen, uint8_t** resp, size_t* resplen); 77 | 78 | /* Set the locality used for communicating with a vTPM */ 79 | int tpmfront_set_locality(struct tpmfront_dev* dev, int locality); 80 | 81 | #ifdef HAVE_LIBC 82 | #include 83 | /* POSIX IO functions: 84 | * use tpmfront_open() to get a file descriptor to the tpm device 85 | * use write() on the fd to send a command to the backend. You must 86 | * include the entire command in a single call to write(). 87 | * use read() on the fd to read the response. You can use 88 | * fstat() to get the size of the response and lseek() to seek on it. 89 | */ 90 | int tpmfront_open(struct tpmfront_dev* dev); 91 | int tpmfront_posix_read(int fd, uint8_t* buf, size_t count); 92 | int tpmfront_posix_write(int fd, const uint8_t* buf, size_t count); 93 | int tpmfront_posix_fstat(int fd, struct stat* buf); 94 | #endif 95 | 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /include/types.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | **************************************************************************** 3 | * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge 4 | **************************************************************************** 5 | * 6 | * File: types.h 7 | * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) 8 | * Changes: 9 | * 10 | * Date: May 2003 11 | * 12 | * Environment: Xen Minimal OS 13 | * Description: a random collection of type definitions 14 | * 15 | **************************************************************************** 16 | * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $ 17 | **************************************************************************** 18 | */ 19 | 20 | #ifndef _TYPES_H_ 21 | #define _TYPES_H_ 22 | #include 23 | 24 | /* FreeBSD compat types */ 25 | #ifndef HAVE_LIBC 26 | typedef unsigned char u_char; 27 | typedef unsigned int u_int; 28 | typedef unsigned long u_long; 29 | #endif 30 | #ifdef __i386__ 31 | typedef long long quad_t; 32 | typedef unsigned long long u_quad_t; 33 | 34 | typedef struct { unsigned long pte_low, pte_high; } pte_t; 35 | 36 | #elif defined(__x86_64__) 37 | typedef long quad_t; 38 | typedef unsigned long u_quad_t; 39 | 40 | typedef struct { unsigned long pte; } pte_t; 41 | #endif /* __i386__ || __x86_64__ */ 42 | 43 | #ifdef __x86_64__ 44 | #define __pte(x) ((pte_t) { (x) } ) 45 | #else 46 | #define __pte(x) ({ unsigned long long _x = (x); \ 47 | ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) 48 | #endif 49 | 50 | #ifdef HAVE_LIBC 51 | #include 52 | #include 53 | #else 54 | #ifdef __i386__ 55 | typedef unsigned int uintptr_t; 56 | typedef int intptr_t; 57 | #elif defined(__x86_64__) 58 | typedef unsigned long uintptr_t; 59 | typedef long intptr_t; 60 | #endif /* __i386__ || __x86_64__ */ 61 | typedef unsigned char uint8_t; 62 | typedef signed char int8_t; 63 | typedef unsigned short uint16_t; 64 | typedef signed short int16_t; 65 | typedef unsigned int uint32_t; 66 | typedef signed int int32_t; 67 | #ifdef __i386__ 68 | typedef signed long long int64_t; 69 | typedef unsigned long long uint64_t; 70 | #elif defined(__x86_64__) 71 | typedef signed long int64_t; 72 | typedef unsigned long uint64_t; 73 | #endif 74 | typedef uint64_t uintmax_t; 75 | typedef int64_t intmax_t; 76 | typedef uint64_t off_t; 77 | #endif 78 | 79 | typedef intptr_t ptrdiff_t; 80 | 81 | 82 | #ifndef HAVE_LIBC 83 | typedef long ssize_t; 84 | #endif 85 | 86 | #endif /* _TYPES_H_ */ 87 | -------------------------------------------------------------------------------- /include/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef __WAIT_H__ 2 | #define __WAIT_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define DEFINE_WAIT(name) \ 9 | struct wait_queue name = { \ 10 | .thread = get_current(), \ 11 | .waiting = 0, \ 12 | } 13 | 14 | 15 | static inline void init_waitqueue_head(struct wait_queue_head *h) 16 | { 17 | MINIOS_STAILQ_INIT(h); 18 | } 19 | 20 | static inline void init_waitqueue_entry(struct wait_queue *q, struct thread *thread) 21 | { 22 | q->thread = thread; 23 | q->waiting = 0; 24 | } 25 | 26 | static inline void add_wait_queue(struct wait_queue_head *h, struct wait_queue *q) 27 | { 28 | if (!q->waiting) { 29 | MINIOS_STAILQ_INSERT_HEAD(h, q, thread_list); 30 | q->waiting = 1; 31 | } 32 | } 33 | 34 | static inline void remove_wait_queue(struct wait_queue_head *h, struct wait_queue *q) 35 | { 36 | if (q->waiting) { 37 | MINIOS_STAILQ_REMOVE(h, q, struct wait_queue, thread_list); 38 | q->waiting = 0; 39 | } 40 | } 41 | 42 | static inline void wake_up(struct wait_queue_head *head) 43 | { 44 | unsigned long flags; 45 | struct wait_queue *curr, *tmp; 46 | local_irq_save(flags); 47 | MINIOS_STAILQ_FOREACH_SAFE(curr, head, thread_list, tmp) 48 | wake(curr->thread); 49 | local_irq_restore(flags); 50 | } 51 | 52 | #define add_waiter(w, wq) do { \ 53 | unsigned long flags; \ 54 | local_irq_save(flags); \ 55 | add_wait_queue(&wq, &w); \ 56 | block(get_current()); \ 57 | local_irq_restore(flags); \ 58 | } while (0) 59 | 60 | #define remove_waiter(w, wq) do { \ 61 | unsigned long flags; \ 62 | local_irq_save(flags); \ 63 | remove_wait_queue(&wq, &w); \ 64 | local_irq_restore(flags); \ 65 | } while (0) 66 | 67 | #define wait_event_deadline(wq, condition, deadline) do { \ 68 | unsigned long flags; \ 69 | DEFINE_WAIT(__wait); \ 70 | if(condition) \ 71 | break; \ 72 | for(;;) \ 73 | { \ 74 | /* protect the list */ \ 75 | local_irq_save(flags); \ 76 | add_wait_queue(&wq, &__wait); \ 77 | get_current()->wakeup_time = deadline; \ 78 | clear_runnable(get_current()); \ 79 | local_irq_restore(flags); \ 80 | if((condition) || (deadline && NOW() >= deadline)) \ 81 | break; \ 82 | schedule(); \ 83 | } \ 84 | local_irq_save(flags); \ 85 | /* need to wake up */ \ 86 | wake(get_current()); \ 87 | remove_wait_queue(&wq, &__wait); \ 88 | local_irq_restore(flags); \ 89 | } while(0) 90 | 91 | #define wait_event(wq, condition) wait_event_deadline(wq, condition, 0) 92 | 93 | 94 | 95 | #endif /* __WAIT_H__ */ 96 | 97 | /* 98 | * Local variables: 99 | * mode: C 100 | * c-file-style: "BSD" 101 | * c-basic-offset: 4 102 | * tab-width: 4 103 | * indent-tabs-mode: nil 104 | * End: 105 | */ 106 | -------------------------------------------------------------------------------- /include/waittypes.h: -------------------------------------------------------------------------------- 1 | #ifndef __WAITTYPE_H__ 2 | #define __WAITTYPE_H__ 3 | 4 | #include 5 | 6 | struct thread; 7 | struct wait_queue 8 | { 9 | int waiting; 10 | struct thread *thread; 11 | MINIOS_STAILQ_ENTRY(struct wait_queue) thread_list; 12 | }; 13 | 14 | /* TODO - lock required? */ 15 | MINIOS_STAILQ_HEAD(wait_queue_head, struct wait_queue); 16 | 17 | #define DECLARE_WAIT_QUEUE_HEAD(name) \ 18 | struct wait_queue_head name = MINIOS_STAILQ_HEAD_INITIALIZER(name) 19 | 20 | #define __WAIT_QUEUE_HEAD_INITIALIZER(name) MINIOS_STAILQ_HEAD_INITIALIZER(name) 21 | 22 | #endif 23 | 24 | /* 25 | * Local variables: 26 | * mode: C 27 | * c-file-style: "BSD" 28 | * c-basic-offset: 4 29 | * tab-width: 4 30 | * indent-tabs-mode: nil 31 | * End: 32 | */ 33 | -------------------------------------------------------------------------------- /include/x86/arch_endian.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCH_ENDIAN_H 2 | #error "Do not include arch_endian by itself, include endian.h" 3 | #else 4 | 5 | #define __BYTE_ORDER __LITTLE_ENDIAN 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /include/x86/arch_limits.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ARCH_LIMITS_H__ 3 | #define __ARCH_LIMITS_H__ 4 | 5 | #define __PAGE_SHIFT 12 6 | 7 | #ifdef __ASSEMBLY__ 8 | #define __PAGE_SIZE (1 << __PAGE_SHIFT) 9 | #else 10 | #ifdef __x86_64__ 11 | #define __PAGE_SIZE (1UL << __PAGE_SHIFT) 12 | #else 13 | #define __PAGE_SIZE (1ULL << __PAGE_SHIFT) 14 | #endif 15 | #endif 16 | 17 | #define __STACK_SIZE_PAGE_ORDER 4 18 | #define __STACK_SIZE (__PAGE_SIZE * (1 << __STACK_SIZE_PAGE_ORDER)) 19 | 20 | #endif /* __ARCH_LIMITS_H__ */ 21 | -------------------------------------------------------------------------------- /include/x86/arch_sched.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __ARCH_SCHED_H__ 3 | #define __ARCH_SCHED_H__ 4 | 5 | #include "arch_limits.h" 6 | 7 | static inline struct thread* get_current(void) 8 | { 9 | struct thread **current; 10 | #ifdef __i386__ 11 | register unsigned long sp asm("esp"); 12 | #else 13 | register unsigned long sp asm("rsp"); 14 | #endif 15 | current = (struct thread**)(unsigned long)(sp & ~(__STACK_SIZE-1)); 16 | return *current; 17 | } 18 | 19 | extern void __arch_switch_threads(unsigned long *prevctx, unsigned long *nextctx); 20 | 21 | #define arch_switch_threads(prev,next) __arch_switch_threads(&(prev)->sp, &(next)->sp) 22 | 23 | 24 | 25 | #endif /* __ARCH_SCHED_H__ */ 26 | -------------------------------------------------------------------------------- /include/x86/arch_spinlock.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __ARCH_ASM_SPINLOCK_H 4 | #define __ARCH_ASM_SPINLOCK_H 5 | 6 | #include 7 | #include "os.h" 8 | 9 | 10 | #define ARCH_SPIN_LOCK_UNLOCKED { 1 } 11 | 12 | /* 13 | * Simple spin lock operations. There are two variants, one clears IRQ's 14 | * on the local processor, one does not. 15 | * 16 | * We make no fairness assumptions. They have a cost. 17 | */ 18 | 19 | #define arch_spin_is_locked(x) (*(volatile signed char *)(&(x)->slock) <= 0) 20 | #define arch_spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) 21 | 22 | #define spin_lock_string \ 23 | "1:\n" \ 24 | LOCK \ 25 | "decb %0\n\t" \ 26 | "jns 3f\n" \ 27 | "2:\t" \ 28 | "rep;nop\n\t" \ 29 | "cmpb $0,%0\n\t" \ 30 | "jle 2b\n\t" \ 31 | "jmp 1b\n" \ 32 | "3:\n\t" 33 | 34 | #define spin_lock_string_flags \ 35 | "1:\n" \ 36 | LOCK \ 37 | "decb %0\n\t" \ 38 | "jns 4f\n\t" \ 39 | "2:\t" \ 40 | "testl $0x200, %1\n\t" \ 41 | "jz 3f\n\t" \ 42 | "#sti\n\t" \ 43 | "3:\t" \ 44 | "rep;nop\n\t" \ 45 | "cmpb $0, %0\n\t" \ 46 | "jle 3b\n\t" \ 47 | "#cli\n\t" \ 48 | "jmp 1b\n" \ 49 | "4:\n\t" 50 | 51 | /* 52 | * This works. Despite all the confusion. 53 | * (except on PPro SMP or if we are using OOSTORE) 54 | * (PPro errata 66, 92) 55 | */ 56 | 57 | #define spin_unlock_string \ 58 | "xchgb %b0, %1" \ 59 | :"=q" (oldval), "=m" (lock->slock) \ 60 | :"0" (oldval) : "memory" 61 | 62 | static inline void _raw_spin_unlock(spinlock_t *lock) 63 | { 64 | char oldval = 1; 65 | __asm__ __volatile__( 66 | spin_unlock_string 67 | ); 68 | } 69 | 70 | static inline int _raw_spin_trylock(spinlock_t *lock) 71 | { 72 | char oldval; 73 | __asm__ __volatile__( 74 | "xchgb %b0,%1\n" 75 | :"=q" (oldval), "=m" (lock->slock) 76 | :"0" (0) : "memory"); 77 | return oldval > 0; 78 | } 79 | 80 | static inline void _raw_spin_lock(spinlock_t *lock) 81 | { 82 | __asm__ __volatile__( 83 | spin_lock_string 84 | :"=m" (lock->slock) : : "memory"); 85 | } 86 | 87 | static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags) 88 | { 89 | __asm__ __volatile__( 90 | spin_lock_string_flags 91 | :"=m" (lock->slock) : "r" (flags) : "memory"); 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /include/x86/traps.h: -------------------------------------------------------------------------------- 1 | /* 2 | **************************************************************************** 3 | * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge 4 | **************************************************************************** 5 | * 6 | * File: traps.h 7 | * Author: Grzegorz Milos (gm281@cam.ac.uk) 8 | * 9 | * Date: Jun 2005 10 | * 11 | * Environment: Xen Minimal OS 12 | * Description: Deals with traps 13 | * 14 | **************************************************************************** 15 | */ 16 | 17 | #ifndef _TRAPS_H_ 18 | #define _TRAPS_H_ 19 | 20 | #ifdef __i386__ 21 | struct pt_regs { 22 | long ebx; 23 | long ecx; 24 | long edx; 25 | long esi; 26 | long edi; 27 | long ebp; 28 | long eax; 29 | int xds; 30 | int xes; 31 | long orig_eax; 32 | long eip; 33 | int xcs; 34 | long eflags; 35 | long esp; 36 | int xss; 37 | }; 38 | #elif __x86_64__ 39 | 40 | struct pt_regs { 41 | unsigned long r15; 42 | unsigned long r14; 43 | unsigned long r13; 44 | unsigned long r12; 45 | unsigned long rbp; 46 | unsigned long rbx; 47 | /* arguments: non interrupts/non tracing syscalls only save upto here*/ 48 | unsigned long r11; 49 | unsigned long r10; 50 | unsigned long r9; 51 | unsigned long r8; 52 | unsigned long rax; 53 | unsigned long rcx; 54 | unsigned long rdx; 55 | unsigned long rsi; 56 | unsigned long rdi; 57 | unsigned long orig_rax; 58 | /* end of arguments */ 59 | /* cpu exception frame or undefined */ 60 | unsigned long rip; 61 | unsigned long cs; 62 | unsigned long eflags; 63 | unsigned long rsp; 64 | unsigned long ss; 65 | /* top of stack page */ 66 | }; 67 | 68 | 69 | #endif 70 | 71 | void dump_regs(struct pt_regs *regs); 72 | void stack_walk(void); 73 | 74 | #define TRAP_PF_PROT 0x1 75 | #define TRAP_PF_WRITE 0x2 76 | #define TRAP_PF_USER 0x4 77 | 78 | #endif /* _TRAPS_H_ */ 79 | -------------------------------------------------------------------------------- /include/x86/x86_32/arch_wordsize.h: -------------------------------------------------------------------------------- 1 | #define __WORDSIZE 32 2 | -------------------------------------------------------------------------------- /include/x86/x86_64/arch_wordsize.h: -------------------------------------------------------------------------------- 1 | #define __WORDSIZE 64 2 | #define __WORDSIZE_COMPAT32 1 3 | -------------------------------------------------------------------------------- /include/xen-features.h: -------------------------------------------------------------------------------- 1 | #ifndef __XEN_FEATURES_H__ 2 | #define __XEN_FEATURES_H__ 3 | 4 | #include 5 | 6 | extern uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32]; 7 | static inline int xen_feature(int flag) 8 | { 9 | return xen_features[flag]; 10 | } 11 | 12 | #endif /* __ASM_XEN_FEATURES_H__ */ 13 | -------------------------------------------------------------------------------- /include/xenbus.h: -------------------------------------------------------------------------------- 1 | #ifndef XENBUS_H__ 2 | #define XENBUS_H__ 3 | 4 | #include 5 | 6 | typedef unsigned long xenbus_transaction_t; 7 | #define XBT_NIL ((xenbus_transaction_t)0) 8 | 9 | #ifdef CONFIG_XENBUS 10 | /* Initialize the XenBus system. */ 11 | void init_xenbus(void); 12 | #else 13 | static inline void init_xenbus(void) 14 | { 15 | } 16 | #endif 17 | 18 | /* Read the value associated with a path. Returns a malloc'd error 19 | string on failure and sets *value to NULL. On success, *value is 20 | set to a malloc'd copy of the value. */ 21 | char *xenbus_read(xenbus_transaction_t xbt, const char *path, char **value); 22 | 23 | /* Watch event queue */ 24 | struct xenbus_event { 25 | /* Keep these two as this for xs.c */ 26 | char *path; 27 | char *token; 28 | struct xenbus_event *next; 29 | }; 30 | typedef struct xenbus_event *xenbus_event_queue; 31 | 32 | char *xenbus_watch_path_token(xenbus_transaction_t xbt, const char *path, const char *token, xenbus_event_queue *events); 33 | char *xenbus_unwatch_path_token(xenbus_transaction_t xbt, const char *path, const char *token); 34 | extern struct wait_queue_head xenbus_watch_queue; 35 | void xenbus_wait_for_watch(xenbus_event_queue *queue); 36 | char **xenbus_wait_for_watch_return(xenbus_event_queue *queue); 37 | void xenbus_release_wait_for_watch(xenbus_event_queue *queue); 38 | char* xenbus_wait_for_value(const char *path, const char *value, xenbus_event_queue *queue); 39 | char *xenbus_wait_for_state_change(const char* path, XenbusState *state, xenbus_event_queue *queue); 40 | char *xenbus_switch_state(xenbus_transaction_t xbt, const char* path, XenbusState state); 41 | 42 | /* When no token is provided, use a global queue. */ 43 | #define XENBUS_WATCH_PATH_TOKEN "xenbus_watch_path" 44 | extern xenbus_event_queue xenbus_events; 45 | #define xenbus_watch_path(xbt, path) xenbus_watch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN, NULL) 46 | #define xenbus_unwatch_path(xbt, path) xenbus_unwatch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN) 47 | 48 | 49 | /* Associates a value with a path. Returns a malloc'd error string on 50 | failure. */ 51 | char *xenbus_write(xenbus_transaction_t xbt, const char *path, const char *value); 52 | 53 | struct write_req { 54 | const void *data; 55 | unsigned len; 56 | }; 57 | 58 | /* Send a message to xenbus, in the same fashion as xb_write, and 59 | block waiting for a reply. The reply is malloced and should be 60 | freed by the caller. */ 61 | struct xsd_sockmsg * 62 | xenbus_msg_reply(int type, 63 | xenbus_transaction_t trans, 64 | struct write_req *io, 65 | int nr_reqs); 66 | 67 | /* Removes the value associated with a path. Returns a malloc'd error 68 | string on failure. */ 69 | char *xenbus_rm(xenbus_transaction_t xbt, const char *path); 70 | 71 | /* List the contents of a directory. Returns a malloc'd error string 72 | on failure and sets *contents to NULL. On success, *contents is 73 | set to a malloc'd array of pointers to malloc'd strings. The array 74 | is NULL terminated. May block. */ 75 | char *xenbus_ls(xenbus_transaction_t xbt, const char *prefix, char ***contents); 76 | 77 | /* Reads permissions associated with a path. Returns a malloc'd error 78 | string on failure and sets *value to NULL. On success, *value is 79 | set to a malloc'd copy of the value. */ 80 | char *xenbus_get_perms(xenbus_transaction_t xbt, const char *path, char **value); 81 | 82 | /* Sets the permissions associated with a path. Returns a malloc'd 83 | error string on failure. */ 84 | char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t dom, char perm); 85 | 86 | /* Start a xenbus transaction. Returns the transaction in xbt on 87 | success or a malloc'd error string otherwise. */ 88 | char *xenbus_transaction_start(xenbus_transaction_t *xbt); 89 | 90 | /* End a xenbus transaction. Returns a malloc'd error string if it 91 | fails. abort says whether the transaction should be aborted. 92 | Returns 1 in *retry iff the transaction should be retried. */ 93 | char *xenbus_transaction_end(xenbus_transaction_t, int abort, 94 | int *retry); 95 | 96 | /* Read path and parse it as an integer. Returns -1 on error. */ 97 | int xenbus_read_integer(const char *path); 98 | 99 | /* Read path and parse it as 16 byte uuid. Returns 1 if 100 | * read and parsing were successful, 0 if not */ 101 | int xenbus_read_uuid(const char* path, unsigned char uuid[16]); 102 | 103 | /* Contraction of snprintf and xenbus_write(path/node). */ 104 | char* xenbus_printf(xenbus_transaction_t xbt, 105 | const char* node, const char* path, 106 | const char* fmt, ...) 107 | __attribute__((__format__(printf, 4, 5))); 108 | 109 | /* Utility function to figure out our domain id */ 110 | domid_t xenbus_get_self_id(void); 111 | 112 | #ifdef CONFIG_XENBUS 113 | /* Reset the XenBus system. */ 114 | void fini_xenbus(void); 115 | #else 116 | static inline void fini_xenbus(void) 117 | { 118 | } 119 | #endif 120 | 121 | #ifdef CONFIG_XENBUS 122 | void suspend_xenbus(void); 123 | #else 124 | static inline void suspend_xenbus(void) 125 | { 126 | } 127 | #endif 128 | 129 | #ifdef CONFIG_XENBUS 130 | void resume_xenbus(int canceled); 131 | #else 132 | static inline void resume_xenbus(int canceled) 133 | { 134 | } 135 | #endif 136 | 137 | #endif /* XENBUS_H__ */ 138 | -------------------------------------------------------------------------------- /include/xmalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef __XMALLOC_H__ 2 | #define __XMALLOC_H__ 3 | 4 | #ifdef HAVE_LIBC 5 | 6 | #include 7 | #include 8 | /* Allocate space for typed object. */ 9 | #define _xmalloc(size, align) memalign(align, size) 10 | #define xfree(ptr) free(ptr) 11 | 12 | #else 13 | 14 | #include 15 | 16 | #define DEFAULT_ALIGN (sizeof(unsigned long)) 17 | 18 | extern void *malloc(size_t size); 19 | extern void *realloc(void *ptr, size_t size); 20 | extern void free(void *ptr); 21 | 22 | /* Free memory from any xmalloc*() call. */ 23 | extern void xfree(const void *); 24 | 25 | /* Underlying functions */ 26 | extern void *_xmalloc(size_t size, size_t align); 27 | 28 | #endif 29 | 30 | static inline void *_xmalloc_array(size_t size, size_t align, size_t num) 31 | { 32 | /* Check for overflow. */ 33 | if (size && num > UINT_MAX / size) 34 | return NULL; 35 | return _xmalloc(size * num, align); 36 | } 37 | 38 | /* Allocate space for typed object. */ 39 | #define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type))) 40 | 41 | /* Allocate space for array of typed objects. */ 42 | #define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) 43 | 44 | #endif /* __XMALLOC_H__ */ 45 | -------------------------------------------------------------------------------- /kernel.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * kernel.c 3 | * 4 | * Assorted crap goes here, including the initial C entry point, jumped at 5 | * from head.S. 6 | * 7 | * Copyright (c) 2002-2003, K A Fraser & R Neugebauer 8 | * Copyright (c) 2005, Grzegorz Milos, Intel Research Cambridge 9 | * Copyright (c) 2006, Robert Kaiser, FH Wiesbaden 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to 13 | * deal in the Software without restriction, including without limitation the 14 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | * sell copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | * DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #ifdef CONFIG_XENBUS 46 | #include 47 | #endif 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32]; 54 | 55 | void setup_xen_features(void) 56 | { 57 | xen_feature_info_t fi; 58 | int i, j; 59 | 60 | for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) 61 | { 62 | fi.submap_idx = i; 63 | if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0) 64 | break; 65 | 66 | for (j=0; j<32; j++) 67 | xen_features[i*32+j] = !!(fi.submap & 1<nr_pages); 99 | printk(" shared_inf: 0x%08lx(MA)\n", si->shared_info); 100 | printk(" pt_base: %p(VA)\n", (void *)si->pt_base); 101 | printk("nr_pt_frames: 0x%lx\n", si->nr_pt_frames); 102 | printk(" mfn_list: %p(VA)\n", (void *)si->mfn_list); 103 | printk(" mod_start: 0x%lx(VA)\n", si->mod_start); 104 | printk(" mod_len: %lu\n", si->mod_len); 105 | printk(" flags: 0x%x\n", (unsigned int)si->flags); 106 | printk(" cmd_line: %s\n", 107 | si->cmd_line ? (const char *)si->cmd_line : "NULL"); 108 | 109 | /* Set up events. */ 110 | init_events(); 111 | 112 | /* ENABLE EVENT DELIVERY. This is disabled at start of day. */ 113 | __sti(); 114 | 115 | arch_print_info(); 116 | 117 | /* Init memory management. */ 118 | init_mm(); 119 | 120 | /* Init time and timers. */ 121 | init_time(); 122 | 123 | /* Init the console driver. */ 124 | init_console(); 125 | 126 | /* Init grant tables */ 127 | init_gnttab(); 128 | 129 | /* Init scheduler. */ 130 | init_sched(); 131 | 132 | /* Init XenBus */ 133 | init_xenbus(); 134 | 135 | #ifdef CONFIG_XENBUS 136 | /* Init shutdown thread */ 137 | init_shutdown(si); 138 | #endif 139 | 140 | /* Call (possibly overridden) app_main() */ 141 | app_main(&start_info); 142 | 143 | /* Everything initialised, start idle thread */ 144 | run_idle_thread(); 145 | } 146 | 147 | void stop_kernel(void) 148 | { 149 | /* TODO: fs import */ 150 | 151 | local_irq_disable(); 152 | 153 | /* Reset grant tables */ 154 | fini_gnttab(); 155 | 156 | /* Reset XenBus */ 157 | fini_xenbus(); 158 | 159 | /* Reset timers */ 160 | fini_time(); 161 | 162 | /* Reset memory management. */ 163 | fini_mm(); 164 | 165 | /* Reset events. */ 166 | fini_events(); 167 | 168 | /* Reset traps */ 169 | trap_fini(); 170 | 171 | /* Reset arch details */ 172 | arch_fini(); 173 | } 174 | 175 | void pre_suspend(void) 176 | { 177 | #ifdef CONFIG_NETFRONT 178 | suspend_netfront(); 179 | #endif 180 | 181 | suspend_xenbus(); 182 | 183 | local_irq_disable(); 184 | 185 | suspend_gnttab(); 186 | 187 | suspend_time(); 188 | 189 | suspend_console(); 190 | 191 | suspend_events(); 192 | } 193 | 194 | void post_suspend(int canceled) 195 | { 196 | resume_console(); 197 | 198 | resume_time(); 199 | 200 | resume_gnttab(); 201 | 202 | local_irq_enable(); 203 | 204 | resume_xenbus(canceled); 205 | 206 | #ifdef CONFIG_NETFRONT 207 | resume_netfront(); 208 | #endif 209 | } 210 | 211 | /* 212 | * do_exit: This is called whenever an IRET fails in entry.S. 213 | * This will generally be because an application has got itself into 214 | * a really bad state (probably a bad CS or SS). It must be killed. 215 | * Of course, minimal OS doesn't have applications :-) 216 | */ 217 | 218 | void do_exit(void) 219 | { 220 | printk("Do_exit called!\n"); 221 | stack_walk(); 222 | for( ;; ) 223 | { 224 | struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_crash }; 225 | HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown); 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /lib/ctype.c: -------------------------------------------------------------------------------- 1 | #ifndef HAVE_LIBC 2 | #include 3 | 4 | unsigned char _ctype[] = { 5 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 6 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ 7 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ 8 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ 9 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ 10 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ 11 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ 12 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ 13 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ 14 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ 15 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ 16 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ 17 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ 18 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ 19 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ 20 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ 21 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ 22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ 23 | _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ 24 | _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ 25 | _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ 26 | _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ 27 | _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ 28 | _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/stack_chk_fail.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void __stack_chk_fail(void) 5 | { 6 | printk("stack smashing detected\n"); 7 | do_exit(); 8 | } 9 | -------------------------------------------------------------------------------- /lib/string.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | **************************************************************************** 3 | * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge 4 | **************************************************************************** 5 | * 6 | * File: string.c 7 | * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) 8 | * Changes: 9 | * 10 | * Date: Aug 2003 11 | * 12 | * Environment: Xen Minimal OS 13 | * Description: Library function for string and memory manipulation 14 | * Origin unknown 15 | * 16 | **************************************************************************** 17 | * $Id: c-insert.c,v 1.7 2002/11/08 16:04:34 rn Exp $ 18 | **************************************************************************** 19 | */ 20 | 21 | #include 22 | 23 | /* newlib defines ffs but not ffsll or ffsl */ 24 | int __ffsti2 (long long int lli) 25 | { 26 | int i, num, t, tmpint, len; 27 | 28 | num = sizeof(long long int) / sizeof(int); 29 | if (num == 1) return (ffs((int) lli)); 30 | len = sizeof(int) * 8; 31 | 32 | for (i = 0; i < num; i++) { 33 | tmpint = (int) (((lli >> len) << len) ^ lli); 34 | 35 | t = ffs(tmpint); 36 | if (t) 37 | return (t + i * len); 38 | lli = lli >> len; 39 | } 40 | return 0; 41 | } 42 | 43 | int __ffsdi2 (long int li) 44 | { 45 | return __ffsti2 ((long long int) li); 46 | } 47 | 48 | int ffsl (long int li) 49 | { 50 | return __ffsti2 ((long long int) li); 51 | } 52 | 53 | int ffsll (long long int lli) 54 | { 55 | return __ffsti2 (lli); 56 | } 57 | 58 | #if !defined HAVE_LIBC 59 | 60 | #include 61 | #include 62 | #include 63 | #include 64 | 65 | int memcmp(const void * cs,const void * ct,size_t count) 66 | { 67 | const unsigned char *su1, *su2; 68 | signed char res = 0; 69 | 70 | for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) 71 | if ((res = *su1 - *su2) != 0) 72 | break; 73 | return res; 74 | } 75 | 76 | void * memcpy(void * dest,const void *src,size_t count) 77 | { 78 | char *tmp = (char *) dest; 79 | const char *s = src; 80 | 81 | while (count--) 82 | *tmp++ = *s++; 83 | 84 | return dest; 85 | } 86 | 87 | int strncmp(const char * cs,const char * ct,size_t count) 88 | { 89 | register signed char __res = 0; 90 | 91 | while (count) { 92 | if ((__res = *cs - *ct++) != 0 || !*cs++) 93 | break; 94 | count--; 95 | } 96 | 97 | return __res; 98 | } 99 | 100 | int strcmp(const char * cs,const char * ct) 101 | { 102 | register signed char __res; 103 | 104 | while (1) { 105 | if ((__res = *cs - *ct++) != 0 || !*cs++) 106 | break; 107 | } 108 | 109 | return __res; 110 | } 111 | 112 | char * strcpy(char * dest,const char *src) 113 | { 114 | char *tmp = dest; 115 | 116 | while ((*dest++ = *src++) != '\0') 117 | /* nothing */; 118 | return tmp; 119 | } 120 | 121 | char * strncpy(char * dest,const char *src,size_t count) 122 | { 123 | char *tmp = dest; 124 | 125 | while (count-- && (*dest++ = *src++) != '\0') 126 | /* nothing */; 127 | 128 | return tmp; 129 | } 130 | 131 | void * memset(void * s,int c,size_t count) 132 | { 133 | char *xs = (char *) s; 134 | 135 | while (count--) 136 | *xs++ = c; 137 | 138 | return s; 139 | } 140 | 141 | size_t strnlen(const char * s, size_t count) 142 | { 143 | const char *sc; 144 | 145 | for (sc = s; count-- && *sc != '\0'; ++sc) 146 | /* nothing */; 147 | return sc - s; 148 | } 149 | 150 | 151 | char * strcat(char * dest, const char * src) 152 | { 153 | char *tmp = dest; 154 | 155 | while (*dest) 156 | dest++; 157 | 158 | while ((*dest++ = *src++) != '\0'); 159 | 160 | return tmp; 161 | } 162 | 163 | size_t strlen(const char * s) 164 | { 165 | const char *sc; 166 | 167 | for (sc = s; *sc != '\0'; ++sc) 168 | /* nothing */; 169 | return sc - s; 170 | } 171 | 172 | char * strchr(const char * s, int c) 173 | { 174 | for(; *s != (char) c; ++s) 175 | if (*s == '\0') 176 | return NULL; 177 | return (char *)s; 178 | } 179 | 180 | char * strrchr(const char * s, int c) 181 | { 182 | const char *res = NULL; 183 | for(; *s != '\0'; ++s) 184 | if (*s == (char) c) 185 | res = s; 186 | return (char *)res; 187 | } 188 | 189 | char * strstr(const char * s1,const char * s2) 190 | { 191 | int l1, l2; 192 | 193 | l2 = strlen(s2); 194 | if (!l2) 195 | return (char *) s1; 196 | l1 = strlen(s1); 197 | while (l1 >= l2) { 198 | l1--; 199 | if (!memcmp(s1,s2,l2)) 200 | return (char *) s1; 201 | s1++; 202 | } 203 | return NULL; 204 | } 205 | 206 | char *strdup(const char *x) 207 | { 208 | int l = strlen(x); 209 | char *res = malloc(l + 1); 210 | if (!res) return NULL; 211 | memcpy(res, x, l + 1); 212 | return res; 213 | } 214 | 215 | int ffs(int i) 216 | { 217 | int c = 1; 218 | 219 | do { 220 | if (i & 1) 221 | return (c); 222 | i = i >> 1; 223 | c++; 224 | } while (i); 225 | return 0; 226 | } 227 | 228 | #endif 229 | -------------------------------------------------------------------------------- /lib/xs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libxs-compatible layer 3 | * 4 | * Samuel Thibault , 2007-2008 5 | * 6 | * Mere wrapper around xenbus_* 7 | */ 8 | 9 | #ifdef HAVE_LIBC 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | static inline int _xs_fileno(struct xs_handle *h) { 18 | return (intptr_t) h; 19 | } 20 | 21 | struct xs_handle *xs_daemon_open() 22 | { 23 | int fd = alloc_fd(FTYPE_XENBUS); 24 | files[fd].xenbus.events = NULL; 25 | printk("xs_daemon_open -> %d, %p\n", fd, &files[fd].xenbus.events); 26 | return (void*)(intptr_t) fd; 27 | } 28 | 29 | void xs_daemon_close(struct xs_handle *h) 30 | { 31 | int fd = _xs_fileno(h); 32 | struct xenbus_event *event, *next; 33 | for (event = files[fd].xenbus.events; event; event = next) 34 | { 35 | next = event->next; 36 | free(event); 37 | } 38 | files[fd].type = FTYPE_NONE; 39 | } 40 | 41 | int xs_fileno(struct xs_handle *h) 42 | { 43 | return _xs_fileno(h); 44 | } 45 | 46 | void *xs_read(struct xs_handle *h, xs_transaction_t t, 47 | const char *path, unsigned int *len) 48 | { 49 | char *value; 50 | char *msg; 51 | 52 | msg = xenbus_read(t, path, &value); 53 | if (msg) { 54 | printk("xs_read(%s): %s\n", path, msg); 55 | free(msg); 56 | return NULL; 57 | } 58 | 59 | if (len) 60 | *len = strlen(value); 61 | return value; 62 | } 63 | 64 | bool xs_write(struct xs_handle *h, xs_transaction_t t, 65 | const char *path, const void *data, unsigned int len) 66 | { 67 | char value[len + 1]; 68 | char *msg; 69 | 70 | memcpy(value, data, len); 71 | value[len] = 0; 72 | 73 | msg = xenbus_write(t, path, value); 74 | if (msg) { 75 | printk("xs_write(%s): %s\n", path, msg); 76 | free(msg); 77 | return false; 78 | } 79 | return true; 80 | } 81 | 82 | static bool xs_bool(char *reply) 83 | { 84 | if (!reply) 85 | return true; 86 | free(reply); 87 | return false; 88 | } 89 | 90 | bool xs_rm(struct xs_handle *h, xs_transaction_t t, const char *path) 91 | { 92 | return xs_bool(xenbus_rm(t, path)); 93 | } 94 | 95 | static void *xs_talkv(struct xs_handle *h, xs_transaction_t t, 96 | enum xsd_sockmsg_type type, 97 | struct write_req *iovec, 98 | unsigned int num_vecs, 99 | unsigned int *len) 100 | { 101 | struct xsd_sockmsg *msg; 102 | void *ret; 103 | 104 | msg = xenbus_msg_reply(type, t, iovec, num_vecs); 105 | ret = malloc(msg->len); 106 | memcpy(ret, (char*) msg + sizeof(*msg), msg->len); 107 | if (len) 108 | *len = msg->len - 1; 109 | free(msg); 110 | return ret; 111 | } 112 | 113 | static void *xs_single(struct xs_handle *h, xs_transaction_t t, 114 | enum xsd_sockmsg_type type, 115 | const char *string, 116 | unsigned int *len) 117 | { 118 | struct write_req iovec; 119 | 120 | iovec.data = (void *)string; 121 | iovec.len = strlen(string) + 1; 122 | 123 | return xs_talkv(h, t, type, &iovec, 1, len); 124 | } 125 | 126 | char *xs_get_domain_path(struct xs_handle *h, unsigned int domid) 127 | { 128 | char domid_str[MAX_STRLEN(domid)]; 129 | 130 | sprintf(domid_str, "%u", domid); 131 | 132 | return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL); 133 | } 134 | 135 | char **xs_directory(struct xs_handle *h, xs_transaction_t t, 136 | const char *path, unsigned int *num) 137 | { 138 | char *msg; 139 | char **entries, **res; 140 | char *entry; 141 | int i, n; 142 | int size; 143 | 144 | msg = xenbus_ls(t, path, &res); 145 | if (msg) { 146 | printk("xs_directory(%s): %s\n", path, msg); 147 | free(msg); 148 | return NULL; 149 | } 150 | 151 | size = 0; 152 | for (n = 0; res[n]; n++) 153 | size += strlen(res[n]) + 1; 154 | 155 | entries = malloc(n * sizeof(char *) + size); 156 | entry = (char *) (&entries[n]); 157 | 158 | for (i = 0; i < n; i++) { 159 | int l = strlen(res[i]) + 1; 160 | memcpy(entry, res[i], l); 161 | free(res[i]); 162 | entries[i] = entry; 163 | entry += l; 164 | } 165 | 166 | *num = n; 167 | free(res); 168 | return entries; 169 | } 170 | 171 | bool xs_watch(struct xs_handle *h, const char *path, const char *token) 172 | { 173 | int fd = _xs_fileno(h); 174 | printk("xs_watch(%s, %s)\n", path, token); 175 | return xs_bool(xenbus_watch_path_token(XBT_NULL, path, token, &files[fd].xenbus.events)); 176 | } 177 | 178 | char **xs_read_watch(struct xs_handle *h, unsigned int *num) 179 | { 180 | int fd = _xs_fileno(h); 181 | struct xenbus_event *event; 182 | event = files[fd].xenbus.events; 183 | files[fd].xenbus.events = event->next; 184 | printk("xs_read_watch() -> %s %s\n", event->path, event->token); 185 | *num = 2; 186 | return (char **) &event->path; 187 | } 188 | 189 | bool xs_unwatch(struct xs_handle *h, const char *path, const char *token) 190 | { 191 | printk("xs_unwatch(%s, %s)\n", path, token); 192 | return xs_bool(xenbus_unwatch_path_token(XBT_NULL, path, token)); 193 | } 194 | #endif 195 | -------------------------------------------------------------------------------- /lock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * locks for newlib 3 | * 4 | * Samuel Thibault , July 20008 5 | */ 6 | 7 | #ifdef HAVE_LIBC 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int ___lock_init(_LOCK_T *lock) 14 | { 15 | lock->busy = 0; 16 | init_waitqueue_head(&lock->wait); 17 | return 0; 18 | } 19 | 20 | int ___lock_acquire(_LOCK_T *lock) 21 | { 22 | unsigned long flags; 23 | while(1) { 24 | wait_event(lock->wait, !lock->busy); 25 | local_irq_save(flags); 26 | if (!lock->busy) 27 | break; 28 | local_irq_restore(flags); 29 | } 30 | lock->busy = 1; 31 | local_irq_restore(flags); 32 | return 0; 33 | } 34 | 35 | int ___lock_try_acquire(_LOCK_T *lock) 36 | { 37 | unsigned long flags; 38 | int ret = -1; 39 | local_irq_save(flags); 40 | if (!lock->busy) { 41 | lock->busy = 1; 42 | ret = 0; 43 | } 44 | local_irq_restore(flags); 45 | return ret; 46 | } 47 | 48 | int ___lock_release(_LOCK_T *lock) 49 | { 50 | unsigned long flags; 51 | local_irq_save(flags); 52 | lock->busy = 0; 53 | wake_up(&lock->wait); 54 | local_irq_restore(flags); 55 | return 0; 56 | } 57 | 58 | 59 | int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock) 60 | { 61 | lock->owner = NULL; 62 | init_waitqueue_head(&lock->wait); 63 | return 0; 64 | } 65 | 66 | int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock) 67 | { 68 | unsigned long flags; 69 | if (lock->owner != get_current()) { 70 | while (1) { 71 | wait_event(lock->wait, lock->owner == NULL); 72 | local_irq_save(flags); 73 | if (lock->owner == NULL) 74 | break; 75 | local_irq_restore(flags); 76 | } 77 | lock->owner = get_current(); 78 | local_irq_restore(flags); 79 | } 80 | lock->count++; 81 | return 0; 82 | } 83 | 84 | int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock) 85 | { 86 | unsigned long flags; 87 | int ret = -1; 88 | local_irq_save(flags); 89 | if (!lock->owner) { 90 | ret = 0; 91 | lock->owner = get_current(); 92 | lock->count++; 93 | } 94 | local_irq_restore(flags); 95 | return ret; 96 | } 97 | 98 | int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock) 99 | { 100 | unsigned long flags; 101 | BUG_ON(lock->owner != get_current()); 102 | if (--lock->count) 103 | return 0; 104 | local_irq_save(flags); 105 | lock->owner = NULL; 106 | wake_up(&lock->wait); 107 | local_irq_restore(flags); 108 | return 0; 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * POSIX-compatible main layer 3 | * 4 | * Samuel Thibault , October 2007 5 | */ 6 | 7 | #ifdef HAVE_LIBC 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | extern int main(int argc, char *argv[], char *envp[]); 21 | extern void __libc_init_array(void); 22 | extern void __libc_fini_array(void); 23 | extern unsigned long __CTOR_LIST__[]; 24 | extern unsigned long __DTOR_LIST__[]; 25 | 26 | #if 0 27 | #include 28 | int main(int argc, char *argv[], char *envp[]) 29 | { 30 | printf("Hello, World!\n"); 31 | return 1; 32 | } 33 | #endif 34 | 35 | void _init(void) 36 | { 37 | } 38 | 39 | void _fini(void) 40 | { 41 | } 42 | 43 | extern char __app_bss_start, __app_bss_end; 44 | static void call_main(void *p) 45 | { 46 | char *c, quote; 47 | #ifdef CONFIG_QEMU_XS_ARGS 48 | char *domargs, *msg; 49 | #endif 50 | int argc; 51 | char **argv; 52 | char *envp[] = { NULL }; 53 | #ifdef CONFIG_QEMU_XS_ARGS 54 | char *vm; 55 | char path[128]; 56 | int domid; 57 | #endif 58 | int i; 59 | 60 | /* Let other parts initialize (including console output) before maybe 61 | * crashing. */ 62 | //sleep(1); 63 | 64 | #ifdef CONFIG_SPARSE_BSS 65 | sparse((unsigned long) &__app_bss_start, &__app_bss_end - &__app_bss_start); 66 | #endif 67 | #if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK) && defined(CONFIG_NETFRONT) 68 | start_networking(); 69 | #endif 70 | #ifdef CONFIG_PCIFRONT 71 | create_thread("pcifront", pcifront_watches, NULL); 72 | #endif 73 | 74 | #ifdef CONFIG_QEMU_XS_ARGS 75 | /* Fetch argc, argv from XenStore */ 76 | domid = xenbus_read_integer("target"); 77 | if (domid == -1) { 78 | printk("Couldn't read target\n"); 79 | do_exit(); 80 | } 81 | 82 | snprintf(path, sizeof(path), "/local/domain/%d/vm", domid); 83 | msg = xenbus_read(XBT_NIL, path, &vm); 84 | if (msg) { 85 | printk("Couldn't read vm path\n"); 86 | do_exit(); 87 | } 88 | printk("dom vm is at %s\n", vm); 89 | 90 | snprintf(path, sizeof(path), "%s/image/dmargs", vm); 91 | free(vm); 92 | msg = xenbus_read(XBT_NIL, path, &domargs); 93 | 94 | if (msg) { 95 | printk("Couldn't get stubdom args: %s\n", msg); 96 | domargs = strdup(""); 97 | } 98 | #endif 99 | 100 | argc = 1; 101 | 102 | #define PARSE_ARGS(ARGS,START,QUOTE,END) \ 103 | c = ARGS; \ 104 | quote = 0; \ 105 | while (*c) { \ 106 | if (*c != ' ') { \ 107 | START; \ 108 | while (*c) { \ 109 | if (quote) { \ 110 | if (*c == quote) { \ 111 | quote = 0; \ 112 | QUOTE; \ 113 | continue; \ 114 | } \ 115 | } else if (*c == ' ') \ 116 | break; \ 117 | if (*c == '"' || *c == '\'') { \ 118 | quote = *c; \ 119 | QUOTE; \ 120 | continue; \ 121 | } \ 122 | c++; \ 123 | } \ 124 | } else { \ 125 | END; \ 126 | while (*c == ' ') \ 127 | c++; \ 128 | } \ 129 | } \ 130 | if (quote) {\ 131 | printk("Warning: unterminated quotation %c\n", quote); \ 132 | quote = 0; \ 133 | } 134 | #define PARSE_ARGS_COUNT(ARGS) PARSE_ARGS(ARGS, argc++, c++, ) 135 | #define PARSE_ARGS_STORE(ARGS) PARSE_ARGS(ARGS, argv[argc++] = c, memmove(c, c + 1, strlen(c + 1) + 1), *c++ = 0) 136 | 137 | PARSE_ARGS_COUNT((char*)start_info.cmd_line); 138 | #ifdef CONFIG_QEMU_XS_ARGS 139 | PARSE_ARGS_COUNT(domargs); 140 | #endif 141 | 142 | argv = alloca((argc + 1) * sizeof(char *)); 143 | argv[0] = "main"; 144 | argc = 1; 145 | 146 | PARSE_ARGS_STORE((char*)start_info.cmd_line) 147 | #ifdef CONFIG_QEMU_XS_ARGS 148 | PARSE_ARGS_STORE(domargs) 149 | #endif 150 | 151 | argv[argc] = NULL; 152 | 153 | for (i = 0; i < argc; i++) 154 | printf("\"%s\" ", argv[i]); 155 | printf("\n"); 156 | 157 | __libc_init_array(); 158 | environ = envp; 159 | for (i = 0; __CTOR_LIST__[i] != 0; i++) 160 | ((void((*)(void)))__CTOR_LIST__[i]) (); 161 | tzset(); 162 | 163 | exit(main(argc, argv, envp)); 164 | } 165 | 166 | void _exit(int ret) 167 | { 168 | int i; 169 | 170 | for (i = 0; __DTOR_LIST__[i] != 0; i++) 171 | ((void((*)(void)))__DTOR_LIST__[i]) (); 172 | close_all_files(); 173 | __libc_fini_array(); 174 | printk("main returned %d\n", ret); 175 | #if defined(HAVE_LWIP) && defined(CONFIG_START_NETWORK) && defined(CONFIG_NETFRONT) 176 | stop_networking(); 177 | #endif 178 | kernel_shutdown(ret); 179 | } 180 | 181 | int app_main(start_info_t *si) 182 | { 183 | printk("Dummy main: start_info=%p\n", si); 184 | main_thread = create_thread("main", call_main, si); 185 | return 0; 186 | } 187 | #endif 188 | -------------------------------------------------------------------------------- /minios.mk: -------------------------------------------------------------------------------- 1 | # 2 | # The file contains the common make rules for building mini-os. 3 | # 4 | 5 | debug = y 6 | pvh = y 7 | 8 | # Define some default flags. 9 | # NB. '-Wcast-qual' is nasty, so I omitted it. 10 | DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format -Wno-redundant-decls 11 | DEF_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) 12 | DEF_CFLAGS += $(call cc-option,$(CC),-fgnu89-inline) 13 | DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline 14 | DEF_CPPFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION) 15 | 16 | DEF_ASFLAGS += -D__ASSEMBLY__ 17 | DEF_LDFLAGS += 18 | 19 | ifeq ($(debug),y) 20 | DEF_CFLAGS += -g 21 | #DEF_CFLAGS += -DMM_DEBUG 22 | #DEF_CFLAGS += -DFS_DEBUG 23 | #DEF_CFLAGS += -DLIBC_DEBUG 24 | #DEF_CFLAGS += -DGNT_DEBUG 25 | #DEF_CFLAGS += -DGNTMAP_DEBUG 26 | else 27 | DEF_CFLAGS += -O3 28 | endif 29 | 30 | ifeq ($(pvh),y) 31 | DEF_CFLAGS += -DCONFIG_PVH 32 | endif 33 | 34 | # Make the headers define our internal stuff 35 | DEF_CFLAGS += -D__INSIDE_MINIOS__ 36 | 37 | # Build the CFLAGS and ASFLAGS for compiling and assembling. 38 | # DEF_... flags are the common mini-os flags, 39 | # ARCH_... flags may be defined in arch/$(TARGET_ARCH_FAM/rules.mk 40 | CFLAGS := $(DEF_CFLAGS) $(ARCH_CFLAGS) 41 | CPPFLAGS := $(DEF_CPPFLAGS) $(ARCH_CPPFLAGS) 42 | ASFLAGS := $(DEF_ASFLAGS) $(ARCH_ASFLAGS) 43 | LDFLAGS := $(DEF_LDFLAGS) $(ARCH_LDFLAGS) 44 | 45 | # Special build dependencies. 46 | # Rebuild all after touching this/these file(s) 47 | EXTRA_DEPS += $(MINI-OS_ROOT)/minios.mk 48 | EXTRA_DEPS += $(MINI-OS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk 49 | 50 | # Find all header files for checking dependencies. 51 | HDRS := $(wildcard $(MINI-OS_ROOT)/include/*.h) 52 | HDRS += $(wildcard $(MINI-OS_ROOT)/include/xen/*.h) 53 | HDRS += $(wildcard $(ARCH_INC)/*.h) 54 | # For special wanted header directories. 55 | extra_heads := $(foreach dir,$(EXTRA_INC),$(wildcard $(dir)/*.h)) 56 | HDRS += $(extra_heads) 57 | 58 | # Add the special header directories to the include paths. 59 | override CPPFLAGS := $(CPPFLAGS) $(extra_incl) 60 | 61 | # The name of the architecture specific library. 62 | # This is on x86_32: libx86_32.a 63 | # $(ARCH_LIB) has to built in the architecture specific directory. 64 | ARCH_LIB_NAME = $(XEN_TARGET_ARCH) 65 | ARCH_LIB := lib$(ARCH_LIB_NAME).a 66 | 67 | # This object contains the entrypoint for startup from Xen. 68 | # $(HEAD_ARCH_OBJ) has to be built in the architecture specific directory. 69 | HEAD_ARCH_OBJ := $(XEN_TARGET_ARCH).o 70 | HEAD_OBJ := $(OBJ_DIR)/$(TARGET_ARCH_DIR)/$(HEAD_ARCH_OBJ) 71 | 72 | 73 | $(OBJ_DIR)/%.o: %.c $(HDRS) Makefile $(EXTRA_DEPS) 74 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 75 | 76 | $(OBJ_DIR)/%.o: %.S $(HDRS) Makefile $(EXTRA_DEPS) 77 | $(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@ 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /shutdown.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MiniOS 3 | * 4 | * file: shutdown.c 5 | * 6 | * Authors: Joao Martins 7 | * 8 | * 9 | * Copyright (c) 2014, NEC Europe Ltd., NEC Corporation. All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. Neither the name of the copyright holder nor the names of its 21 | * contributors may be used to endorse or promote products derived from 22 | * this software without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | 47 | static start_info_t *start_info_ptr; 48 | 49 | static const char *path = "control/shutdown"; 50 | static const char *token = "control/shutdown"; 51 | static xenbus_event_queue events = NULL; 52 | static int end_shutdown_thread = 0; 53 | 54 | /* This should be overridden by the application we are linked against. */ 55 | __attribute__((weak)) void app_shutdown(unsigned reason) 56 | { 57 | printk("Shutdown requested: %d\n", reason); 58 | } 59 | 60 | static void shutdown_thread(void *p) 61 | { 62 | char *shutdown, *err; 63 | unsigned int shutdown_reason; 64 | 65 | xenbus_watch_path_token(XBT_NIL, path, token, &events); 66 | 67 | for ( ;; ) { 68 | xenbus_wait_for_watch(&events); 69 | if ((err = xenbus_read(XBT_NIL, path, &shutdown))) { 70 | free(err); 71 | do_exit(); 72 | } 73 | 74 | if (end_shutdown_thread) 75 | break; 76 | 77 | if (!strcmp(shutdown, "")) { 78 | /* Avoid spurious event on xenbus */ 79 | /* FIXME: investigate the reason of the spurious event */ 80 | free(shutdown); 81 | continue; 82 | } else if (!strcmp(shutdown, "poweroff")) { 83 | shutdown_reason = SHUTDOWN_poweroff; 84 | } else if (!strcmp(shutdown, "reboot")) { 85 | shutdown_reason = SHUTDOWN_reboot; 86 | } else if (!strcmp(shutdown, "suspend")) { 87 | shutdown_reason = SHUTDOWN_suspend; 88 | } else { 89 | shutdown_reason = SHUTDOWN_crash; 90 | } 91 | free(shutdown); 92 | 93 | /* Acknowledge shutdown request */ 94 | if ((err = xenbus_write(XBT_NIL, path, ""))) { 95 | free(err); 96 | do_exit(); 97 | } 98 | 99 | app_shutdown(shutdown_reason); 100 | } 101 | } 102 | 103 | static void fini_shutdown(void) 104 | { 105 | char *err; 106 | 107 | end_shutdown_thread = 1; 108 | xenbus_release_wait_for_watch(&events); 109 | err = xenbus_unwatch_path_token(XBT_NIL, path, token); 110 | if (err) { 111 | free(err); 112 | do_exit(); 113 | } 114 | } 115 | 116 | void init_shutdown(start_info_t *si) 117 | { 118 | start_info_ptr = si; 119 | 120 | end_shutdown_thread = 0; 121 | create_thread("shutdown", shutdown_thread, NULL); 122 | } 123 | 124 | void kernel_shutdown(int reason) 125 | { 126 | char* reason_str = NULL; 127 | 128 | switch(reason) { 129 | case SHUTDOWN_poweroff: 130 | reason_str = "poweroff"; 131 | break; 132 | case SHUTDOWN_reboot: 133 | reason_str = "reboot"; 134 | break; 135 | case SHUTDOWN_crash: 136 | reason_str = "crash"; 137 | break; 138 | default: 139 | do_exit(); 140 | break; 141 | } 142 | 143 | printk("MiniOS will shutdown (reason = %s) ...\n", reason_str); 144 | 145 | fini_shutdown(); 146 | 147 | stop_kernel(); 148 | 149 | for ( ;; ) { 150 | struct sched_shutdown sched_shutdown = { .reason = reason }; 151 | HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown); 152 | } 153 | } 154 | 155 | void kernel_suspend(void) 156 | { 157 | int rc; 158 | 159 | printk("MiniOS will suspend ...\n"); 160 | 161 | pre_suspend(); 162 | arch_pre_suspend(); 163 | 164 | /* 165 | * This hypercall returns 1 if the suspend 166 | * was cancelled and 0 if resuming in a new domain 167 | */ 168 | rc = HYPERVISOR_suspend(virt_to_mfn(start_info_ptr)); 169 | 170 | arch_post_suspend(rc); 171 | post_suspend(rc); 172 | 173 | if (rc) { 174 | printk("MiniOS suspend canceled!"); 175 | } else { 176 | printk("MiniOS resumed from suspend!\n"); 177 | } 178 | } 179 | --------------------------------------------------------------------------------