├── .gitignore ├── .travis.yml ├── CODING_STYLE ├── COPYING ├── Config.mk ├── Makefile ├── README ├── app.lds ├── arch ├── arm │ ├── arm32.S │ ├── balloon.c │ ├── events.c │ ├── gic.c │ ├── hypercalls32.S │ ├── minios-arm32.lds │ ├── mm.c │ ├── panic.c │ ├── sched.c │ ├── setup.c │ └── time.c └── x86 │ ├── Makefile │ ├── arch.mk │ ├── balloon.c │ ├── events.c │ ├── ioremap.c │ ├── iorw.c │ ├── minios-x86.lds.S │ ├── mm.c │ ├── sched.c │ ├── setup.c │ ├── testbuild │ ├── all-no │ ├── all-yes │ ├── balloon │ ├── newxen │ ├── newxen-yes │ └── std │ ├── time.c │ ├── traps.c │ ├── x86_32.S │ ├── x86_64.S │ └── x86_hvm.S ├── balloon.c ├── 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 ├── arm │ ├── arch_endian.h │ ├── arch_limits.h │ ├── arch_mm.h │ ├── arch_sched.h │ ├── arch_spinlock.h │ ├── arm32 │ │ └── arch_wordsize.h │ ├── asm_macros.h │ ├── gic.h │ ├── hypercall-arm.h │ ├── os.h │ └── traps.h ├── asm_macros.h ├── balloon.h ├── blkfront.h ├── byteorder.h ├── byteswap.h ├── compiler.h ├── console.h ├── ctype.h ├── e820.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.h ├── linux │ └── types.h ├── lwipopts.h ├── minios-external │ ├── README │ ├── bsd-COPYRIGHT │ ├── bsd-queue.3 │ ├── bsd-sys-queue-h-seddery │ └── bsd-sys-queue.h ├── mm.h ├── netfront.h ├── paravirt.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 ├── 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 │ ├── asm_macros.h │ ├── desc.h │ ├── os.h │ ├── traps.h │ ├── x86_32 │ │ ├── arch_wordsize.h │ │ └── hypercall-x86_32.h │ └── x86_64 │ │ ├── arch_wordsize.h │ │ └── hypercall-x86_64.h ├── xen │ ├── COPYING │ ├── arch-arm.h │ ├── arch-arm │ │ ├── hvm │ │ │ └── save.h │ │ └── smccc.h │ ├── arch-x86 │ │ ├── cpufeatureset.h │ │ ├── cpuid.h │ │ ├── hvm │ │ │ ├── save.h │ │ │ └── start_info.h │ │ ├── pmu.h │ │ ├── xen-mca.h │ │ ├── xen-x86_32.h │ │ ├── xen-x86_64.h │ │ └── xen.h │ ├── arch-x86_32.h │ ├── arch-x86_64.h │ ├── callback.h │ ├── dom0_ops.h │ ├── domctl.h │ ├── elfnote.h │ ├── errno.h │ ├── event_channel.h │ ├── features.h │ ├── grant_table.h │ ├── hvm │ │ ├── dm_op.h │ │ ├── e820.h │ │ ├── hvm_info_table.h │ │ ├── hvm_op.h │ │ ├── hvm_vcpu.h │ │ ├── hvm_xs_strings.h │ │ ├── ioreq.h │ │ ├── params.h │ │ ├── pvdrivers.h │ │ └── save.h │ ├── io │ │ ├── 9pfs.h │ │ ├── blkif.h │ │ ├── console.h │ │ ├── displif.h │ │ ├── fbif.h │ │ ├── fsif.h │ │ ├── kbdif.h │ │ ├── libxenvchan.h │ │ ├── netif.h │ │ ├── pciif.h │ │ ├── protocols.h │ │ ├── pvcalls.h │ │ ├── ring.h │ │ ├── sndif.h │ │ ├── tpmif.h │ │ ├── usbif.h │ │ ├── vscsiif.h │ │ ├── xenbus.h │ │ └── xs_wire.h │ ├── kexec.h │ ├── memory.h │ ├── nmi.h │ ├── physdev.h │ ├── platform.h │ ├── pmu.h │ ├── sched.h │ ├── sysctl.h │ ├── tmem.h │ ├── trace.h │ ├── vcpu.h │ ├── version.h │ ├── vm_event.h │ ├── xen-compat.h │ ├── xen.h │ ├── xencomm.h │ ├── xenoprof.h │ └── xsm │ │ └── flask_op.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 ├── scripts └── travis-build ├── shutdown.c ├── test.c ├── tpm_tis.c ├── tpmback.c ├── tpmfront.c └── xenbus └── xenbus.c /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.a 4 | *.swp 5 | cscope.* 6 | GPATH 7 | GRTAGS 8 | GTAGS 9 | TAGS 10 | tags 11 | 12 | arch/x86/minios-x86*.lds 13 | include/list.h 14 | mini-os 15 | mini-os.gz 16 | minios-config.mk 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | dist: trusty 3 | sudo: required 4 | # don't test stable branches 5 | branches: 6 | except: 7 | - /^stable-.*/ 8 | matrix: 9 | include: 10 | - compiler: gcc 11 | addons: 12 | apt: 13 | sources: 14 | - ubuntu-toolchain-r-test 15 | packages: 16 | - libc6-dev-i386 17 | - gcc-5 18 | - g++-5 19 | # we must set CXX manually instead of using 'language: cpp' due to 20 | # travis-ci/travis-ci#3871 21 | before_script: 22 | - export CXX=${CC/cc/++} 23 | - export CXX=${CXX/clang/clang++} 24 | script: 25 | - ./scripts/travis-build 26 | -------------------------------------------------------------------------------- /CODING_STYLE: -------------------------------------------------------------------------------- 1 | Coding Style for Mini-OS 2 | ======================== 3 | 4 | Indentation 5 | ----------- 6 | 7 | Indenting uses spaces, not tabs - in contrast to Linux. An indent 8 | level consists of four spaces. Code within blocks is indented by one 9 | extra indent level. The enclosing braces of a block are indented the 10 | same as the code _outside_ the block. e.g. 11 | 12 | void fun(void) 13 | { 14 | /* One level of indent. */ 15 | 16 | { 17 | /* A second level of indent. */ 18 | } 19 | } 20 | 21 | White space 22 | ----------- 23 | 24 | Space characters are used to spread out logical statements, such as in 25 | the condition of an if or while. Spaces are placed between the 26 | keyword and the brackets surrounding the condition, between the 27 | brackets and the condition itself, and around binary operators (except 28 | the structure access operators, '.' and '->'). e.g. 29 | 30 | if ( (wibble & wombat) == 42 ) 31 | { 32 | ... 33 | 34 | There should be no trailing white space at the end of lines (including 35 | after the opening /* of a comment block). 36 | 37 | Line Length 38 | ----------- 39 | 40 | Lines should be less than 80 characters in length. Long lines should 41 | be split at sensible places and the trailing portions indented. 42 | 43 | User visible strings (e.g., printk() messages) should not be split so 44 | they can searched for more easily. 45 | 46 | Bracing 47 | ------- 48 | 49 | Braces ('{' and '}') are usually placed on a line of their own, except 50 | for the do/while loop. This is unlike the Linux coding style and 51 | unlike K&R. do/while loops are an exception. e.g.: 52 | 53 | if ( condition ) 54 | { 55 | /* Do stuff. */ 56 | } 57 | else 58 | { 59 | /* Other stuff. */ 60 | } 61 | 62 | while ( condition ) 63 | { 64 | /* Do stuff. */ 65 | } 66 | 67 | do { 68 | /* Do stuff. */ 69 | } while ( condition ); 70 | 71 | etc. 72 | 73 | Braces should be omitted for blocks with a single statement. e.g., 74 | 75 | if ( condition ) 76 | single_statement(); 77 | 78 | Comments 79 | -------- 80 | 81 | Only C style /* ... */ comments are to be used. C++ style // comments 82 | should not be used. Multi-word comments should begin with a capital 83 | letter. Comments containing a single sentence may end with a full 84 | stop; comments containing several sentences must have a full stop 85 | after each sentence. 86 | 87 | Multi-line comment blocks should start and end with comment markers on 88 | separate lines and each line should begin with a leading '*'. 89 | 90 | /* 91 | * Example, multi-line comment block. 92 | * 93 | * Note beginning and end markers on separate lines and leading '*'. 94 | */ 95 | 96 | Emacs local variables 97 | --------------------- 98 | 99 | A comment block containing local variables for emacs is permitted at 100 | the end of files. It should be: 101 | 102 | /* 103 | * Local variables: 104 | * mode: C 105 | * c-file-style: "BSD" 106 | * c-basic-offset: 4 107 | * indent-tabs-mode: nil 108 | * End: 109 | */ 110 | -------------------------------------------------------------------------------- /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) 2009 Citrix Systems, Inc. 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 | 1. Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 2. Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | 25 | THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 29 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | SUCH DAMAGE. 36 | 37 | -------------------------------------------------------------------------------- /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 | - Mini-OS can be configured in various ways by specifying a config file: 23 | 24 | MINIOS_CONFIG=config-file make 25 | 26 | config-file can contain various CONFIG_* items set to either "y" or "n". 27 | Their defaults can be found in Config.mk. 28 | It is possible to specify the interface version of Xen via setting 29 | 30 | XEN_INTERFACE_VERSION= 31 | 32 | in the config file. This defaults to 0x00030205, which is the minimal 33 | version supported. The latest available version is specified by setting 34 | 35 | XEN_INTERFACE_VERSION=__XEN_LATEST_INTERFACE_VERSION__ 36 | 37 | - By typing 38 | 39 | make testbuild 40 | 41 | it is possible to test builds of various configurations. This should be 42 | done always after modifying Mini-OS. 43 | 44 | The configurations which are build tested can be found in the directory 45 | arch/*/testbuild with one file per configuration. Those configurations are 46 | being built for each sub-architecture (e.g. x86_32 and x86_64 for the 47 | x86 architecture). 48 | 49 | Please update the current configuration files when adding a new CONFIG_ 50 | item and maybe even add a new configuration file if the new item interacts 51 | with other CONFIG_ items. 52 | 53 | - to build it with TCP/IP support, download LWIP 1.3.2 source code and type 54 | 55 | make LWIPDIR=/path/to/lwip/source 56 | 57 | - to build it with much better libc support, see the stubdom/ directory 58 | 59 | - to start it do the following in domain0 60 | # xl create -c domain_config 61 | 62 | This starts the kernel and prints out a bunch of stuff and then once every 63 | second the system time. 64 | 65 | If you have setup a disk in the config file (e.g. 66 | disk = [ 'file:/tmp/foo,hda,r' ] ), it will loop reading it. If that disk is 67 | writable (e.g. disk = [ 'file:/tmp/foo,hda,w' ] ), it will write data patterns 68 | and re-read them. 69 | 70 | If you have setup a network in the config file (e.g. vif = [''] ), it will 71 | print incoming packets. 72 | 73 | If you have setup a VFB in the config file (e.g. vfb = ['type=sdl'] ), it will 74 | show a mouse with which you can draw color squares. 75 | 76 | If you have compiled it with TCP/IP support, it will run a daytime server on 77 | TCP port 13. 78 | 79 | 80 | ARM notes 81 | ========= 82 | 83 | - The IRQ numbers are currently hard-coded in gic.c and may need to be updated if 84 | future versions of Xen change them. 85 | -------------------------------------------------------------------------------- /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/arm/balloon.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | * 3 | * (C) 2016 - Juergen Gross, SUSE Linux GmbH 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #ifdef CONFIG_BALLOON 27 | 28 | void arch_pfn_add(unsigned long pfn, unsigned long mfn) 29 | { 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /arch/arm/events.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static void virq_debug(evtchn_port_t port, struct pt_regs *regs, void *params) 7 | { 8 | printk("Received a virq_debug event\n"); 9 | } 10 | 11 | evtchn_port_t debug_port = -1; 12 | void arch_init_events(void) 13 | { 14 | debug_port = bind_virq(VIRQ_DEBUG, (evtchn_handler_t)virq_debug, 0); 15 | if(debug_port == -1) 16 | BUG(); 17 | unmask_evtchn(debug_port); 18 | } 19 | 20 | void arch_unbind_ports(void) 21 | { 22 | if(debug_port != -1) 23 | { 24 | mask_evtchn(debug_port); 25 | unbind_evtchn(debug_port); 26 | } 27 | } 28 | 29 | void arch_fini_events(void) 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /arch/arm/hypercalls32.S: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hypercall.S 3 | * 4 | * Xen hypercall wrappers 5 | * 6 | * Stefano Stabellini , Citrix, 2012 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU General Public License version 2 10 | * as published by the Free Software Foundation; or, when distributed 11 | * separately from the Linux kernel or incorporated into other 12 | * software packages, subject to the following license: 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this source file (the "Software"), to deal in the Software without 16 | * restriction, including without limitation the rights to use, copy, modify, 17 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, 18 | * and to permit persons to whom the Software is furnished to do so, subject to 19 | * the following conditions: 20 | * 21 | * The above copyright notice and this permission notice shall be included in 22 | * all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 30 | * IN THE SOFTWARE. 31 | */ 32 | 33 | #include 34 | 35 | #define __HVC(imm16) .long ((0xE1400070 | (((imm16) & 0xFFF0) << 4) | ((imm16) & 0x000F)) & 0xFFFFFFFF) 36 | 37 | #define XEN_IMM 0xEA1 38 | 39 | #define HYPERCALL_SIMPLE(hypercall) \ 40 | .globl HYPERVISOR_##hypercall; \ 41 | .align 4,0x90; \ 42 | HYPERVISOR_##hypercall: \ 43 | mov r12, #__HYPERVISOR_##hypercall; \ 44 | __HVC(XEN_IMM); \ 45 | mov pc, lr; 46 | 47 | #define _hypercall0 HYPERCALL_SIMPLE 48 | #define _hypercall1 HYPERCALL_SIMPLE 49 | #define _hypercall2 HYPERCALL_SIMPLE 50 | #define _hypercall3 HYPERCALL_SIMPLE 51 | #define _hypercall4 HYPERCALL_SIMPLE 52 | 53 | _hypercall2(sched_op); 54 | _hypercall2(memory_op); 55 | _hypercall2(event_channel_op); 56 | _hypercall2(xen_version); 57 | _hypercall3(console_io); 58 | _hypercall1(physdev_op); 59 | _hypercall3(grant_table_op); 60 | _hypercall3(vcpu_op); 61 | _hypercall1(sysctl); 62 | _hypercall1(domctl); 63 | _hypercall2(hvm_op); 64 | _hypercall1(xsm_op); 65 | -------------------------------------------------------------------------------- /arch/arm/minios-arm32.lds: -------------------------------------------------------------------------------- 1 | OUTPUT_ARCH(arm) 2 | ENTRY(_start) 3 | SECTIONS 4 | { 5 | /* Note: we currently assume that Xen will load the kernel image 6 | * at start-of-RAM + 0x8000. We use this initial 32 KB for the stack 7 | * and translation tables. 8 | */ 9 | _boot_stack = 0x400000; /* 16 KB boot stack */ 10 | _boot_stack_end = 0x404000; 11 | _page_dir = 0x404000; /* 16 KB translation table */ 12 | . = 0x408000; 13 | _text = .; /* Text and read-only data */ 14 | .text : { 15 | *(.text) 16 | *(.gnu.warning) 17 | } = 0x9090 18 | 19 | _etext = .; /* End of text section */ 20 | 21 | .rodata : { *(.rodata) *(.rodata.*) } 22 | . = ALIGN(4096); 23 | _erodata = .; 24 | 25 | /* newlib initialization functions */ 26 | . = ALIGN(32 / 8); 27 | PROVIDE (__preinit_array_start = .); 28 | .preinit_array : { *(.preinit_array) } 29 | PROVIDE (__preinit_array_end = .); 30 | PROVIDE (__init_array_start = .); 31 | .init_array : { *(.init_array) } 32 | PROVIDE (__init_array_end = .); 33 | PROVIDE (__fini_array_start = .); 34 | .fini_array : { *(.fini_array) } 35 | PROVIDE (__fini_array_end = .); 36 | 37 | .ctors : { 38 | __CTOR_LIST__ = .; 39 | *(.ctors) 40 | CONSTRUCTORS 41 | LONG(0) 42 | __CTOR_END__ = .; 43 | } 44 | 45 | .dtors : { 46 | __DTOR_LIST__ = .; 47 | *(.dtors) 48 | LONG(0) 49 | __DTOR_END__ = .; 50 | } 51 | 52 | .data : { /* Data */ 53 | *(.data) 54 | } 55 | 56 | /* Note: linker will insert any extra sections here, just before .bss */ 57 | 58 | .bss : { 59 | _edata = .; /* End of data included in image */ 60 | /* Nothing after here is included in the zImage's size */ 61 | 62 | __bss_start = .; 63 | *(.bss) 64 | *(.app.bss) 65 | } 66 | _end = . ; 67 | 68 | /* Sections to be discarded */ 69 | /DISCARD/ : { 70 | *(.text.exit) 71 | *(.data.exit) 72 | *(.exitcall.exit) 73 | } 74 | 75 | /* Stabs debugging sections. */ 76 | .stab 0 : { *(.stab) } 77 | .stabstr 0 : { *(.stabstr) } 78 | .stab.excl 0 : { *(.stab.excl) } 79 | .stab.exclstr 0 : { *(.stab.exclstr) } 80 | .stab.index 0 : { *(.stab.index) } 81 | .stab.indexstr 0 : { *(.stab.indexstr) } 82 | .comment 0 : { *(.comment) } 83 | } 84 | -------------------------------------------------------------------------------- /arch/arm/panic.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * panic.c 3 | * 4 | * Displays a register dump and stack trace for debugging. 5 | * 6 | * Copyright (c) 2014, Thomas Leonard 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to 10 | * deal in the Software without restriction, including without limitation the 11 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 12 | * sell copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | * DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | extern int irqstack[]; 32 | extern int irqstack_end[]; 33 | 34 | typedef void handler(void); 35 | 36 | extern handler fault_reset; 37 | extern handler fault_undefined_instruction; 38 | extern handler fault_svc; 39 | extern handler fault_prefetch_call; 40 | extern handler fault_prefetch_abort; 41 | extern handler fault_data_abort; 42 | 43 | void dump_registers(int *saved_registers) { 44 | static int in_dump = 0; 45 | int *sp, *stack_top, *x; 46 | char *fault_name; 47 | void *fault_handler; 48 | int i; 49 | 50 | if (in_dump) 51 | { 52 | printk("Crash while in dump_registers! Not generating a second report.\n"); 53 | return; 54 | } 55 | 56 | in_dump = 1; 57 | 58 | fault_handler = (handler *) saved_registers[17]; 59 | if (fault_handler == fault_reset) 60 | fault_name = "reset"; 61 | else if (fault_handler == fault_undefined_instruction) 62 | fault_name = "undefined_instruction"; 63 | else if (fault_handler == fault_svc) 64 | fault_name = "svc"; 65 | else if (fault_handler == fault_prefetch_call) 66 | fault_name = "prefetch_call"; 67 | else if (fault_handler == fault_prefetch_abort) 68 | fault_name = "prefetch_abort"; 69 | else if (fault_handler == fault_data_abort) 70 | fault_name = "data_abort"; 71 | else 72 | fault_name = "unknown fault type!"; 73 | 74 | printk("Fault handler at %p called (%s)\n", fault_handler, fault_name); 75 | 76 | for (i = 0; i < 16; i++) { 77 | printk("r%d = %x\n", i, saved_registers[i]); 78 | } 79 | printk("CPSR = %x\n", saved_registers[16]); 80 | 81 | printk("Stack dump (innermost last)\n"); 82 | sp = (int *) saved_registers[13]; 83 | 84 | if (sp >= _boot_stack && sp <= _boot_stack_end) 85 | stack_top = _boot_stack_end; /* The boot stack */ 86 | else if (sp >= irqstack && sp <= irqstack_end) 87 | stack_top = irqstack_end; /* The IRQ stack */ 88 | else 89 | stack_top = (int *) ((((unsigned long) sp) | (__STACK_SIZE-1)) + 1); /* A normal thread stack */ 90 | 91 | for (x = stack_top - 1; x >= sp; x--) 92 | { 93 | printk(" [%8p] %8x\n", x, *x); 94 | } 95 | printk("End of stack\n"); 96 | 97 | in_dump = 0; 98 | } 99 | -------------------------------------------------------------------------------- /arch/arm/sched.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void arm_start_thread(void); 6 | 7 | /* The AAPCS requires the callee (e.g. __arch_switch_threads) to preserve r4-r11. */ 8 | #define CALLEE_SAVED_REGISTERS 8 9 | 10 | /* Architecture specific setup of thread creation */ 11 | struct thread* arch_create_thread(char *name, void (*function)(void *), 12 | void *data) 13 | { 14 | struct thread *thread; 15 | 16 | thread = xmalloc(struct thread); 17 | /* We can't use lazy allocation here since the trap handler runs on the stack */ 18 | thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER); 19 | thread->name = name; 20 | printk("Thread \"%s\": pointer: 0x%p, stack: 0x%p\n", name, thread, 21 | thread->stack); 22 | 23 | /* Save pointer to the thread on the stack, used by current macro */ 24 | *((unsigned long *)thread->stack) = (unsigned long)thread; 25 | 26 | /* Push the details to pass to arm_start_thread onto the stack. */ 27 | int *sp = (int *) (thread->stack + STACK_SIZE); 28 | *(--sp) = (int) function; 29 | *(--sp) = (int) data; 30 | 31 | /* We leave room for the 8 callee-saved registers which we will 32 | * try to restore on thread switch, even though they're not needed 33 | * for the initial switch. */ 34 | thread->sp = (unsigned long) sp - 4 * CALLEE_SAVED_REGISTERS; 35 | 36 | thread->ip = (unsigned long) arm_start_thread; 37 | 38 | return thread; 39 | } 40 | 41 | void run_idle_thread(void) 42 | { 43 | __asm__ __volatile__ ("mov sp, %0; bx %1":: 44 | "r"(idle_thread->sp + 4 * CALLEE_SAVED_REGISTERS), 45 | "r"(idle_thread->ip)); 46 | /* Never arrive here! */ 47 | } 48 | -------------------------------------------------------------------------------- /arch/arm/setup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* 12 | * Shared page for communicating with the hypervisor. 13 | * Events flags go here, for example. 14 | */ 15 | shared_info_t *HYPERVISOR_shared_info; 16 | 17 | void *device_tree; 18 | 19 | /* 20 | * INITIAL C ENTRY POINT. 21 | */ 22 | void arch_init(void *dtb_pointer, uint32_t physical_offset) 23 | { 24 | int r; 25 | 26 | memset(&__bss_start, 0, &_end - &__bss_start); 27 | 28 | physical_address_offset = physical_offset; 29 | 30 | xprintk("Virtual -> physical offset = %x\n", physical_address_offset); 31 | 32 | xprintk("Checking DTB at %p...\n", dtb_pointer); 33 | 34 | if ((r = fdt_check_header(dtb_pointer))) { 35 | xprintk("Invalid DTB from Xen: %s\n", fdt_strerror(r)); 36 | BUG(); 37 | } 38 | device_tree = dtb_pointer; 39 | 40 | /* Map shared_info page */ 41 | HYPERVISOR_shared_info = map_shared_info(NULL); 42 | 43 | get_console(NULL); 44 | get_xenbus(NULL); 45 | 46 | gic_init(); 47 | 48 | start_kernel(); 49 | } 50 | 51 | void 52 | arch_fini(void) 53 | { 54 | } 55 | 56 | void 57 | arch_do_exit(void) 58 | { 59 | } 60 | -------------------------------------------------------------------------------- /arch/arm/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | //#define VTIMER_DEBUG 10 | #ifdef VTIMER_DEBUG 11 | #define DEBUG(_f, _a...) \ 12 | printk("MINI_OS(file=vtimer.c, line=%d) " _f , __LINE__, ## _a) 13 | #else 14 | #define DEBUG(_f, _a...) ((void)0) 15 | #endif 16 | 17 | /************************************************************************ 18 | * Time functions 19 | *************************************************************************/ 20 | 21 | static uint64_t cntvct_at_init; 22 | static uint32_t counter_freq; 23 | 24 | /* Compute with 96 bit intermediate result: (a*b)/c */ 25 | uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) 26 | { 27 | union { 28 | uint64_t ll; 29 | struct { 30 | uint32_t low, high; 31 | } l; 32 | } u, res; 33 | uint64_t rl, rh; 34 | 35 | u.ll = a; 36 | rl = (uint64_t)u.l.low * (uint64_t)b; 37 | rh = (uint64_t)u.l.high * (uint64_t)b; 38 | rh += (rl >> 32); 39 | res.l.high = rh / c; 40 | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; 41 | return res.ll; 42 | } 43 | 44 | static inline s_time_t ticks_to_ns(uint64_t ticks) 45 | { 46 | return muldiv64(ticks, SECONDS(1), counter_freq); 47 | } 48 | 49 | static inline uint64_t ns_to_ticks(s_time_t ns) 50 | { 51 | return muldiv64(ns, counter_freq, SECONDS(1)); 52 | } 53 | 54 | /* Wall-clock time is not currently available on ARM, so this is always zero for now: 55 | * http://wiki.xenproject.org/wiki/Xen_ARM_TODO#Expose_Wallclock_time_to_guests 56 | */ 57 | static struct timespec shadow_ts; 58 | 59 | static inline uint64_t read_virtual_count(void) 60 | { 61 | uint32_t c_lo, c_hi; 62 | __asm__ __volatile__("mrrc p15, 1, %0, %1, c14":"=r"(c_lo), "=r"(c_hi)); 63 | return (((uint64_t) c_hi) << 32) + c_lo; 64 | } 65 | 66 | /* monotonic_clock(): returns # of nanoseconds passed since time_init() 67 | * Note: This function is required to return accurate 68 | * time even in the absence of multiple timer ticks. 69 | */ 70 | uint64_t monotonic_clock(void) 71 | { 72 | return ticks_to_ns(read_virtual_count() - cntvct_at_init); 73 | } 74 | 75 | int gettimeofday(struct timeval *tv, void *tz) 76 | { 77 | uint64_t nsec = monotonic_clock(); 78 | nsec += shadow_ts.tv_nsec; 79 | 80 | tv->tv_sec = shadow_ts.tv_sec; 81 | tv->tv_sec += NSEC_TO_SEC(nsec); 82 | tv->tv_usec = NSEC_TO_USEC(nsec % 1000000000UL); 83 | 84 | return 0; 85 | } 86 | 87 | /* Set the timer and mask. */ 88 | void write_timer_ctl(uint32_t value) { 89 | __asm__ __volatile__( 90 | "mcr p15, 0, %0, c14, c3, 1\n" 91 | "isb"::"r"(value)); 92 | } 93 | 94 | void set_vtimer_compare(uint64_t value) { 95 | DEBUG("New CompareValue : %llx\n", value); 96 | 97 | __asm__ __volatile__("mcrr p15, 3, %0, %H0, c14" 98 | ::"r"(value)); 99 | 100 | /* Enable timer and unmask the output signal */ 101 | write_timer_ctl(1); 102 | } 103 | 104 | void unset_vtimer_compare(void) { 105 | /* Disable timer and mask the output signal */ 106 | write_timer_ctl(2); 107 | } 108 | 109 | void block_domain(s_time_t until) 110 | { 111 | uint64_t until_count = ns_to_ticks(until) + cntvct_at_init; 112 | ASSERT(irqs_disabled()); 113 | if (read_virtual_count() < until_count) 114 | { 115 | set_vtimer_compare(until_count); 116 | __asm__ __volatile__("wfi"); 117 | unset_vtimer_compare(); 118 | 119 | /* Give the IRQ handler a chance to handle whatever woke us up. */ 120 | local_irq_enable(); 121 | local_irq_disable(); 122 | } 123 | } 124 | 125 | void init_time(void) 126 | { 127 | printk("Initialising timer interface\n"); 128 | 129 | __asm__ __volatile__("mrc p15, 0, %0, c14, c0, 0":"=r"(counter_freq)); 130 | cntvct_at_init = read_virtual_count(); 131 | printk("Virtual Count register is %llx, freq = %d Hz\n", cntvct_at_init, counter_freq); 132 | } 133 | 134 | void fini_time(void) 135 | { 136 | } 137 | -------------------------------------------------------------------------------- /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 | TOPLEVEL_DIR = $(CURDIR)/../.. 7 | include ../../Config.mk 8 | 9 | include ../../minios.mk 10 | 11 | # Sources here are all *.c *.S without $(MINIOS_TARGET_ARCH).S 12 | # This is handled in $(HEAD_ARCH_OBJ) 13 | ARCH_SRCS := $(sort $(wildcard *.c)) 14 | 15 | # The objects built from the sources. 16 | ARCH_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(ARCH_SRCS)) 17 | 18 | all: $(OBJ_DIR)/$(ARCH_LIB) 19 | 20 | # $(HEAD_ARCH_OBJ) is only build here, needed on linking 21 | # in ../../Makefile. 22 | $(OBJ_DIR)/$(ARCH_LIB): $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ) 23 | $(AR) rv $(OBJ_DIR)/$(ARCH_LIB) $(ARCH_OBJS) 24 | 25 | clean: 26 | rm -f $(OBJ_DIR)/$(ARCH_LIB) $(ARCH_OBJS) $(OBJ_DIR)/$(HEAD_ARCH_OBJ) 27 | rm -f minios-x86_32.lds minios-x86_64.lds 28 | 29 | -------------------------------------------------------------------------------- /arch/x86/arch.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Architecture special makerules for x86 family 3 | # (including x86_32, x86_32y and x86_64). 4 | # 5 | 6 | MINIOS_TARGET_ARCHS := x86_32 x86_64 7 | 8 | ifeq ($(MINIOS_TARGET_ARCH),x86_32) 9 | ARCH_CFLAGS := -m32 -march=i686 10 | ARCH_LDFLAGS := -m elf_i386 11 | ARCH_ASFLAGS := -m32 12 | EXTRA_INC += $(TARGET_ARCH_FAM)/$(MINIOS_TARGET_ARCH) 13 | EXTRA_SRC += arch/$(EXTRA_INC) 14 | endif 15 | 16 | ifeq ($(MINIOS_TARGET_ARCH),x86_64) 17 | ARCH_CFLAGS := -m64 -mno-red-zone -fno-reorder-blocks 18 | ARCH_CFLAGS += -fno-asynchronous-unwind-tables 19 | ARCH_ASFLAGS := -m64 20 | ARCH_LDFLAGS := -m elf_x86_64 21 | EXTRA_INC += $(TARGET_ARCH_FAM)/$(MINIOS_TARGET_ARCH) 22 | EXTRA_SRC += arch/$(EXTRA_INC) 23 | endif 24 | 25 | ifeq ($(CONFIG_PARAVIRT),n) 26 | ARCH_LDFLAGS_FINAL := --oformat=elf32-i386 27 | ARCH_AS_DEPS += x86_hvm.S 28 | endif 29 | -------------------------------------------------------------------------------- /arch/x86/events.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #if defined(__x86_64__) 6 | char irqstack[2 * STACK_SIZE]; 7 | 8 | static struct pda 9 | { 10 | int irqcount; /* offset 0 (used in x86_64.S) */ 11 | char *irqstackptr; /* 8 */ 12 | } cpu0_pda; 13 | #endif 14 | 15 | void arch_init_events(void) 16 | { 17 | #if defined(__x86_64__) 18 | asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0)); 19 | wrmsrl(0xc0000101, (uint64_t)&cpu0_pda); /* 0xc0000101 is MSR_GS_BASE */ 20 | cpu0_pda.irqcount = -1; 21 | cpu0_pda.irqstackptr = (void*) (((unsigned long)irqstack + 2 * STACK_SIZE) 22 | & ~(STACK_SIZE - 1)); 23 | #endif 24 | } 25 | 26 | void arch_unbind_ports(void) 27 | { 28 | } 29 | 30 | void arch_fini_events(void) 31 | { 32 | #if defined(__x86_64__) 33 | wrmsrl(0xc0000101, 0); /* 0xc0000101 is MSR_GS_BASE */ 34 | #endif 35 | } 36 | -------------------------------------------------------------------------------- /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.lds.S: -------------------------------------------------------------------------------- 1 | #if defined(__x86_64__) 2 | 3 | OUTPUT_FORMAT("elf64-x86-64") 4 | OUTPUT_ARCH(i386:x86-64) 5 | 6 | #elif defined(__i386__) 7 | #undef i386 8 | OUTPUT_FORMAT("elf32-i386") 9 | OUTPUT_ARCH(i386) 10 | 11 | #else 12 | # error Bad architecture to link with 13 | #endif 14 | 15 | ENTRY(_start) 16 | SECTIONS 17 | { 18 | . = 0x0; 19 | _text = .; /* Text and read-only data */ 20 | .text : { 21 | *(.text) 22 | *(.gnu.warning) 23 | } = 0x9090 24 | 25 | _etext = .; /* End of text section */ 26 | 27 | .rodata : { 28 | *(.rodata) 29 | *(.rodata.*) 30 | } 31 | . = ALIGN(4096); 32 | _erodata = .; 33 | 34 | .note : { 35 | *(.note) 36 | *(.note.*) 37 | } 38 | 39 | /* newlib initialization functions */ 40 | #if defined(__x86_64__) 41 | . = ALIGN(64 / 8); 42 | #else /* __i386 __ */ 43 | . = ALIGN(32 / 8); 44 | #endif 45 | PROVIDE (__preinit_array_start = .); 46 | .preinit_array : { 47 | *(.preinit_array) 48 | } 49 | PROVIDE (__preinit_array_end = .); 50 | PROVIDE (__init_array_start = .); 51 | .init_array : { 52 | *(.init_array) 53 | } 54 | PROVIDE (__init_array_end = .); 55 | PROVIDE (__fini_array_start = .); 56 | .fini_array : { 57 | *(.fini_array) 58 | } 59 | PROVIDE (__fini_array_end = .); 60 | 61 | .ctors : { 62 | __CTOR_LIST__ = .; 63 | *(.ctors) 64 | CONSTRUCTORS 65 | #if defined(__x86_64__) 66 | QUAD(0) 67 | #else /* __i386__ */ 68 | LONG(0) 69 | #endif 70 | __CTOR_END__ = .; 71 | } 72 | 73 | .dtors : { 74 | __DTOR_LIST__ = .; 75 | *(.dtors) 76 | #if defined(__x86_64__) 77 | QUAD(0) 78 | #else /* __i386__ */ 79 | LONG(0) 80 | #endif 81 | __DTOR_END__ = .; 82 | } 83 | 84 | .data : { /* Data */ 85 | *(.data) 86 | } 87 | 88 | _edata = .; /* End of data section */ 89 | 90 | __bss_start = .; /* BSS */ 91 | .bss : { 92 | *(.bss) 93 | *(.app.bss) 94 | } 95 | _end = . ; 96 | 97 | /* Sections to be discarded */ 98 | /DISCARD/ : { 99 | *(.text.exit) 100 | *(.data.exit) 101 | *(.exitcall.exit) 102 | } 103 | 104 | /* Stabs debugging sections. */ 105 | .stab 0 : { 106 | *(.stab) 107 | } 108 | .stabstr 0 : { 109 | *(.stabstr) 110 | } 111 | .stab.excl 0 : { 112 | *(.stab.excl) 113 | } 114 | .stab.exclstr 0 : { 115 | *(.stab.exclstr) 116 | } 117 | .stab.index 0 : { 118 | *(.stab.index) 119 | } 120 | .stab.indexstr 0 : { 121 | *(.stab.indexstr) 122 | } 123 | .comment 0 : { 124 | *(.comment) 125 | } 126 | } 127 | 128 | /* 129 | * Local variables: 130 | * tab-width: 8 131 | * indent-tabs-mode: nil 132 | * End: 133 | */ 134 | -------------------------------------------------------------------------------- /arch/x86/testbuild/all-no: -------------------------------------------------------------------------------- 1 | CONFIG_PARAVIRT = n 2 | CONFIG_START_NETWORK = n 3 | CONFIG_SPARSE_BSS = n 4 | CONFIG_QEMU_XS_ARGS = n 5 | CONFIG_TEST = n 6 | CONFIG_PCIFRONT = n 7 | CONFIG_BLKFRONT = n 8 | CONFIG_TPMFRONT = n 9 | CONFIG_TPM_TIS = n 10 | CONFIG_TPMBACK = n 11 | CONFIG_NETFRONT = n 12 | CONFIG_FBFRONT = n 13 | CONFIG_KBDFRONT = n 14 | CONFIG_CONSFRONT = n 15 | CONFIG_XENBUS = n 16 | CONFIG_XC = n 17 | CONFIG_LWIP = n 18 | CONFIG_BALLOON = n 19 | CONFIG_USE_XEN_CONSOLE = n 20 | -------------------------------------------------------------------------------- /arch/x86/testbuild/all-yes: -------------------------------------------------------------------------------- 1 | CONFIG_PARAVIRT = y 2 | CONFIG_START_NETWORK = y 3 | CONFIG_SPARSE_BSS = y 4 | CONFIG_QEMU_XS_ARGS = y 5 | CONFIG_TEST = y 6 | CONFIG_PCIFRONT = y 7 | CONFIG_BLKFRONT = y 8 | CONFIG_TPMFRONT = y 9 | CONFIG_TPM_TIS = y 10 | CONFIG_TPMBACK = y 11 | CONFIG_NETFRONT = y 12 | CONFIG_FBFRONT = y 13 | CONFIG_KBDFRONT = y 14 | CONFIG_CONSFRONT = y 15 | CONFIG_XENBUS = y 16 | CONFIG_XC = y 17 | # LWIP is special: it needs support from outside 18 | CONFIG_LWIP = n 19 | CONFIG_BALLOON = y 20 | CONFIG_USE_XEN_CONSOLE = y 21 | -------------------------------------------------------------------------------- /arch/x86/testbuild/balloon: -------------------------------------------------------------------------------- 1 | CONFIG_PARAVIRT = n 2 | CONFIG_BALLOON = y 3 | -------------------------------------------------------------------------------- /arch/x86/testbuild/newxen: -------------------------------------------------------------------------------- 1 | XEN_INTERFACE_VERSION=__XEN_LATEST_INTERFACE_VERSION__ 2 | -------------------------------------------------------------------------------- /arch/x86/testbuild/newxen-yes: -------------------------------------------------------------------------------- 1 | CONFIG_PARAVIRT = y 2 | CONFIG_START_NETWORK = y 3 | CONFIG_SPARSE_BSS = y 4 | CONFIG_QEMU_XS_ARGS = y 5 | CONFIG_TEST = y 6 | CONFIG_PCIFRONT = y 7 | CONFIG_BLKFRONT = y 8 | CONFIG_TPMFRONT = y 9 | CONFIG_TPM_TIS = y 10 | CONFIG_TPMBACK = y 11 | CONFIG_NETFRONT = y 12 | CONFIG_FBFRONT = y 13 | CONFIG_KBDFRONT = y 14 | CONFIG_CONSFRONT = y 15 | CONFIG_XENBUS = y 16 | CONFIG_XC = y 17 | # LWIP is special: it needs support from outside 18 | CONFIG_LWIP = n 19 | CONFIG_BALLOON = y 20 | CONFIG_USE_XEN_CONSOLE = y 21 | XEN_INTERFACE_VERSION=__XEN_LATEST_INTERFACE_VERSION__ 22 | -------------------------------------------------------------------------------- /arch/x86/testbuild/std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirage/mini-os/48d3b31ce47156d92255a2fe98334dd15a42a097/arch/x86/testbuild/std -------------------------------------------------------------------------------- /arch/x86/x86_hvm.S: -------------------------------------------------------------------------------- 1 | /* Included by x86_[32|64].S */ 2 | 3 | ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long _start) 4 | .text 5 | .code32 /* Always starts in 32bit flat mode. */ 6 | 7 | .globl _start 8 | 9 | _start: 10 | mov $(X86_CR4_PAE | X86_CR4_OSFXSR), %eax 11 | mov %eax, %cr4 12 | mov $page_table_base, %eax 13 | mov %eax, %cr3 14 | 15 | #ifdef __x86_64__ /* EFER.LME = 1 */ 16 | mov $MSR_EFER, %ecx 17 | rdmsr 18 | bts $_EFER_LME, %eax 19 | wrmsr 20 | #endif /* __x86_64__ */ 21 | 22 | mov %cr0, %eax 23 | or $X86_CR0_PG, %eax 24 | mov %eax, %cr0 25 | 26 | lgdt gdt_ptr 27 | 28 | /* Load code segment. */ 29 | ljmp $__KERN_CS, $1f 30 | #ifdef __x86_64__ 31 | .code64 32 | #endif 33 | 34 | /* Load data segments. */ 35 | 1: 36 | mov $__USER_DS, %eax 37 | mov %eax, %ds 38 | mov %eax, %es 39 | mov %eax, %fs 40 | mov %eax, %gs 41 | mov $__KERN_DS, %eax 42 | mov %eax, %ss 43 | 44 | mov %ebx, %esi 45 | 46 | .data 47 | /* 48 | * Macro to create a sequence of page table entries. 49 | * As a loop can be done via recursion only and the nesting level is limited 50 | * we treat the first 32 PTEs in a special way limiting nesting level to 64 51 | * in case of a complete page table (512 PTEs) to be filled. 52 | * prot: protection bits in all PTEs 53 | * addr: physical address of the area to map 54 | * incr: increment of address for each PTE 55 | * idx: index of first PTE in page table 56 | * end: index of last PTE in page table + 1 57 | */ 58 | .macro PTES prot, addr, incr, idx, end 59 | .ifgt \end-\idx-32 60 | PTES \prot, \addr, \incr, \idx, "(\idx+32)" 61 | PTES \prot, "(\addr+32*\incr)", \incr, "(\idx+32)", \end 62 | .else 63 | PTE(\addr + \prot) 64 | .if \end-\idx-1 65 | PTES \prot, "(\addr+\incr)", \incr, "(\idx+1)", \end 66 | .endif 67 | .endif 68 | .endm 69 | .align __PAGE_SIZE 70 | page_table_virt_l1: 71 | PTE(0) 72 | .align __PAGE_SIZE, 0 73 | page_table_l1: 74 | PTES L1_PROT, 0x00000000, 0x00001000, 0, L1_PAGETABLE_ENTRIES 75 | .align __PAGE_SIZE, 0 76 | page_table_l2: 77 | /* Map the first 1GB of memory (on 32 bit 16MB less). */ 78 | PTE(page_table_l1 + L2_PROT) 79 | #ifdef __x86_64__ 80 | PTES L2_PROT|_PAGE_PSE, 0x00200000, 0x00200000, 1, L2_PAGETABLE_ENTRIES 81 | #else 82 | /* At 3f000000 virtual kernel area is starting. */ 83 | PTES L2_PROT|_PAGE_PSE, 0x00200000, 0x00200000, 1, l2_table_offset(VIRT_KERNEL_AREA) 84 | PTE(page_table_virt_l1 + L2_PROT) 85 | #endif 86 | .align __PAGE_SIZE, 0 87 | 88 | .text 89 | -------------------------------------------------------------------------------- /console/console.h: -------------------------------------------------------------------------------- 1 | 2 | void console_handle_input(evtchn_port_t port, struct pt_regs *regs, void *data); 3 | -------------------------------------------------------------------------------- /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(void *p) 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 | -------------------------------------------------------------------------------- /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 | */ 8 | 9 | #ifndef __LWIP_ARCH_CC_H__ 10 | #define __LWIP_ARCH_CC_H__ 11 | 12 | /* Typedefs for the types used by lwip - */ 13 | #include 14 | #include 15 | #include 16 | typedef uint8_t u8_t; 17 | typedef int8_t s8_t; 18 | typedef uint16_t u16_t; 19 | typedef int16_t s16_t; 20 | typedef uint32_t u32_t; 21 | typedef int32_t s32_t; 22 | typedef uint64_t u64_t; 23 | typedef int64_t s64_t; 24 | typedef uintptr_t mem_ptr_t; 25 | 26 | typedef uint16_t u_short; 27 | 28 | /* Compiler hints for packing lwip's structures - */ 29 | #define PACK_STRUCT_FIELD(_x) _x 30 | #define PACK_STRUCT_STRUCT __attribute__ ((packed)) 31 | #define PACK_STRUCT_BEGIN 32 | #define PACK_STRUCT_END 33 | 34 | /* Platform specific diagnostic output - */ 35 | 36 | extern void lwip_printk(char *fmt, ...); 37 | #define LWIP_PLATFORM_DIAG(_x) do { lwip_printk _x ; } while (0) 38 | 39 | extern void lwip_die(char *fmt, ...); 40 | #define LWIP_PLATFORM_ASSERT(_x) do { lwip_die(_x); } while(0) 41 | 42 | /* "lightweight" synchronization mechanisms - */ 43 | /* SYS_ARCH_DECL_PROTECT(x) - declare a protection state variable. */ 44 | /* SYS_ARCH_PROTECT(x) - enter protection mode. */ 45 | /* SYS_ARCH_UNPROTECT(x) - leave protection mode. */ 46 | 47 | /* If the compiler does not provide memset() this file must include a */ 48 | /* definition of it, or include a file which defines it. */ 49 | #include 50 | 51 | /* This file must either include a system-local which defines */ 52 | /* the standard *nix error codes, or it should #define LWIP_PROVIDE_ERRNO */ 53 | /* to make lwip/arch.h define the codes which are used throughout. */ 54 | #include 55 | 56 | /* Not required by the docs, but needed for network-order calculations */ 57 | #ifdef HAVE_LIBC 58 | #include 59 | #ifndef BIG_ENDIAN 60 | #error endian.h does not define byte order 61 | #endif 62 | #else 63 | #include 64 | #endif 65 | 66 | #include 67 | #define S16_F PRIi16 68 | #define U16_F PRIu16 69 | #define X16_F PRIx16 70 | #define S32_F PRIi32 71 | #define U32_F PRIu32 72 | #define X32_F PRIx32 73 | 74 | #if 0 75 | #ifndef DBG_ON 76 | #define DBG_ON LWIP_DBG_ON 77 | #endif 78 | #define LWIP_DEBUG DBG_ON 79 | //#define IP_DEBUG DBG_ON 80 | #define TCP_DEBUG DBG_ON 81 | #define TCP_INPUT_DEBUG DBG_ON 82 | #define TCP_QLEN_DEBUG DBG_ON 83 | #define TCPIP_DEBUG DBG_ON 84 | #define DBG_TYPES_ON DBG_ON 85 | #endif 86 | 87 | #endif /* __LWIP_ARCH_CC_H__ */ 88 | -------------------------------------------------------------------------------- /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 | */ 8 | 9 | #ifndef __LWIP_ARCH_SYS_ARCH_H__ 10 | #define __LWIP_ARCH_SYS_ARCH_H__ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | typedef struct semaphore *sys_sem_t; 17 | #define SYS_SEM_NULL ((sys_sem_t) NULL) 18 | 19 | struct mbox { 20 | int count; 21 | void **messages; 22 | struct semaphore read_sem; 23 | struct semaphore write_sem; 24 | int writer; 25 | int reader; 26 | }; 27 | 28 | typedef struct mbox *sys_mbox_t; 29 | #define SYS_MBOX_NULL ((sys_mbox_t) 0) 30 | 31 | typedef struct thread *sys_thread_t; 32 | 33 | typedef unsigned long sys_prot_t; 34 | 35 | #endif /*__LWIP_ARCH_SYS_ARCH_H__ */ 36 | -------------------------------------------------------------------------------- /include/arm/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/arm/arch_limits.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_LIMITS_H__ 2 | #define __ARCH_LIMITS_H__ 3 | 4 | #include 5 | 6 | #define __STACK_SIZE_PAGE_ORDER 2 7 | #define __STACK_SIZE (4 * PAGE_SIZE) 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /include/arm/arch_mm.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARCH_MM_H_ 2 | #define _ARCH_MM_H_ 3 | 4 | typedef uint64_t paddr_t; 5 | 6 | extern char _text, _etext, _erodata, _edata, _end, __bss_start; 7 | extern int _boot_stack[]; 8 | extern int _boot_stack_end[]; 9 | extern uint32_t physical_address_offset; /* Add this to a virtual address to get the physical address (wraps at 4GB) */ 10 | 11 | #define PAGE_SHIFT 12 12 | #define PAGE_SIZE (1 << PAGE_SHIFT) 13 | #define PAGE_MASK (~(PAGE_SIZE-1)) 14 | 15 | #define L1_PAGETABLE_SHIFT 12 16 | 17 | #define L1_PROT 0 18 | 19 | #define to_phys(x) (((paddr_t)(x)+physical_address_offset) & 0xffffffff) 20 | #define to_virt(x) ((void *)(((x)-physical_address_offset) & 0xffffffff)) 21 | 22 | #define PFN_UP(x) (unsigned long)(((x) + PAGE_SIZE-1) >> L1_PAGETABLE_SHIFT) 23 | #define PFN_DOWN(x) (unsigned long)((x) >> L1_PAGETABLE_SHIFT) 24 | #define PFN_PHYS(x) ((uint64_t)(x) << L1_PAGETABLE_SHIFT) 25 | #define PHYS_PFN(x) (unsigned long)((x) >> L1_PAGETABLE_SHIFT) 26 | 27 | #define virt_to_pfn(_virt) (PFN_DOWN(to_phys(_virt))) 28 | #define virt_to_mfn(_virt) (PFN_DOWN(to_phys(_virt))) 29 | #define mfn_to_virt(_mfn) (to_virt(PFN_PHYS(_mfn))) 30 | #define pfn_to_virt(_pfn) (to_virt(PFN_PHYS(_pfn))) 31 | 32 | #define virtual_to_mfn(_virt) virt_to_mfn(_virt) 33 | 34 | // FIXME 35 | #define map_frames(f, n) (NULL) 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/arm/arch_sched.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_SCHED_H__ 2 | #define __ARCH_SCHED_H__ 3 | 4 | #include "arch_limits.h" 5 | 6 | static inline struct thread* get_current(void) 7 | { 8 | struct thread **current; 9 | unsigned long sp; 10 | __asm__ __volatile__ ("mov %0, sp":"=r"(sp)); 11 | current = (void *)(unsigned long)(sp & ~(__STACK_SIZE-1)); 12 | return *current; 13 | } 14 | 15 | void __arch_switch_threads(unsigned long *prevctx, unsigned long *nextctx); 16 | 17 | #define arch_switch_threads(prev,next) __arch_switch_threads(&(prev)->sp, &(next)->sp) 18 | 19 | #endif /* __ARCH_SCHED_H__ */ 20 | -------------------------------------------------------------------------------- /include/arm/arch_spinlock.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_ASM_SPINLOCK_H 2 | #define __ARCH_ASM_SPINLOCK_H 3 | 4 | #include "os.h" 5 | 6 | #define ARCH_SPIN_LOCK_UNLOCKED { 1 } 7 | 8 | /* 9 | * Simple spin lock operations. There are two variants, one clears IRQ's 10 | * on the local processor, one does not. 11 | * 12 | * We make no fairness assumptions. They have a cost. 13 | */ 14 | 15 | #define arch_spin_is_locked(x) (*(volatile signed char *)(&(x)->slock) <= 0) 16 | #define arch_spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) 17 | 18 | static inline void _raw_spin_unlock(spinlock_t *lock) 19 | { 20 | xchg(&lock->slock, 1); 21 | } 22 | 23 | static inline int _raw_spin_trylock(spinlock_t *lock) 24 | { 25 | return xchg(&lock->slock, 0) != 0 ? 1 : 0; 26 | } 27 | 28 | static inline void _raw_spin_lock(spinlock_t *lock) 29 | { 30 | volatile int was_locked; 31 | do { 32 | was_locked = xchg(&lock->slock, 0) == 0 ? 1 : 0; 33 | } while(was_locked); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/arm/arm32/arch_wordsize.h: -------------------------------------------------------------------------------- 1 | #define __WORDSIZE 32 2 | -------------------------------------------------------------------------------- /include/arm/asm_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARM_ASM_MACRO_H_ 2 | #define _ARM_ASM_MACRO_H_ 3 | 4 | #endif /* _ARM_ASM_MACRO_H_ */ 5 | 6 | /* 7 | * Local variables: 8 | * mode: C 9 | * c-file-style: "BSD" 10 | * c-basic-offset: 4 11 | * tab-width: 4 12 | * indent-tabs-mode: nil 13 | * End: 14 | */ 15 | -------------------------------------------------------------------------------- /include/arm/gic.h: -------------------------------------------------------------------------------- 1 | void gic_init(void); 2 | -------------------------------------------------------------------------------- /include/arm/hypercall-arm.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hypercall-arm.h 3 | * 4 | * Copied from XenLinux. 5 | * 6 | * Copyright (c) 2002-2004, K A Fraser 7 | * 8 | * 64-bit updates: 9 | * Benjamin Liu 10 | * Jun Nakajima 11 | * 12 | * This file may be distributed separately from the Linux kernel, or 13 | * incorporated into other software packages, subject to the following license: 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this source file (the "Software"), to deal in the Software without 17 | * restriction, including without limitation the rights to use, copy, modify, 18 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, 19 | * and to permit persons to whom the Software is furnished to do so, subject to 20 | * the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 31 | * IN THE SOFTWARE. 32 | */ 33 | 34 | #ifndef __HYPERCALL_ARM_H__ 35 | #define __HYPERCALL_ARM_H__ 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int 43 | HYPERVISOR_sched_op( 44 | int cmd, void *arg); 45 | 46 | static inline int 47 | HYPERVISOR_shutdown( 48 | unsigned int reason) 49 | { 50 | struct sched_shutdown shutdown = { .reason = reason }; 51 | HYPERVISOR_sched_op(SCHEDOP_shutdown, &shutdown); 52 | } 53 | 54 | int 55 | HYPERVISOR_memory_op( 56 | unsigned int cmd, void *arg); 57 | 58 | int 59 | HYPERVISOR_event_channel_op( 60 | int cmd, void *op); 61 | 62 | int 63 | HYPERVISOR_xen_version( 64 | int cmd, void *arg); 65 | 66 | int 67 | HYPERVISOR_console_io( 68 | int cmd, int count, char *str); 69 | 70 | int 71 | HYPERVISOR_physdev_op( 72 | void *physdev_op); 73 | 74 | int 75 | HYPERVISOR_grant_table_op( 76 | unsigned int cmd, void *uop, unsigned int count); 77 | 78 | int 79 | HYPERVISOR_vcpu_op( 80 | int cmd, int vcpuid, void *extra_args); 81 | 82 | int 83 | HYPERVISOR_sysctl( 84 | unsigned long op); 85 | 86 | int 87 | HYPERVISOR_domctl( 88 | unsigned long op); 89 | 90 | int 91 | HYPERVISOR_hvm_op( 92 | unsigned long op, void *arg); 93 | 94 | int 95 | HYPERVISOR_xsm_op( 96 | struct xen_flask_op *); 97 | 98 | #endif /* __HYPERCALL_ARM_H__ */ 99 | -------------------------------------------------------------------------------- /include/arm/traps.h: -------------------------------------------------------------------------------- 1 | #ifndef _TRAPS_H_ 2 | #define _TRAPS_H_ 3 | 4 | struct pt_regs { 5 | unsigned long r0; 6 | unsigned long r1; 7 | unsigned long r2; 8 | unsigned long r3; 9 | unsigned long r4; 10 | unsigned long r5; 11 | unsigned long r6; 12 | unsigned long r7; 13 | unsigned long r8; 14 | unsigned long r9; 15 | unsigned long r10; 16 | unsigned long r11; 17 | unsigned long r12; 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/asm_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Macros for assembly files. 3 | */ 4 | 5 | #ifndef _ASM_MACRO_H_ 6 | #define _ASM_MACRO_H_ 7 | 8 | #if defined(__i386__) || defined(__x86_64__) 9 | #include 10 | #elif defined(__arm__) || defined(__aarch64__) 11 | #include 12 | #endif 13 | 14 | #ifdef __ASSEMBLY__ 15 | 16 | #define ELFNOTE(name, type, desc) \ 17 | .pushsection .note.name ; \ 18 | .align 4 ; \ 19 | .long 2f - 1f /* namesz */ ; \ 20 | .long 4f - 3f /* descsz */ ; \ 21 | .long type /* type */ ; \ 22 | 1:.asciz #name /* name */ ; \ 23 | 2:.align 4 ; \ 24 | 3:desc /* desc */ ; \ 25 | 4:.align 4 ; \ 26 | .popsection 27 | 28 | #endif /* __ASSEMBLY__ */ 29 | 30 | #endif /* _ASM_MACRO_H_ */ 31 | 32 | /* 33 | * Local variables: 34 | * mode: C 35 | * c-file-style: "BSD" 36 | * c-basic-offset: 4 37 | * tab-width: 4 38 | * indent-tabs-mode: nil 39 | * End: 40 | */ 41 | -------------------------------------------------------------------------------- /include/balloon.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | * 3 | * (C) 2016 - Juergen Gross, SUSE Linux GmbH 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef _BALLOON_H_ 25 | #define _BALLOON_H_ 26 | 27 | #ifdef CONFIG_BALLOON 28 | 29 | /* 30 | * Always keep some pages free for allocations while ballooning or 31 | * interrupts disabled. 32 | */ 33 | #define BALLOON_EMERGENCY_PAGES 64 34 | 35 | extern unsigned long nr_max_pages; 36 | extern unsigned long nr_mem_pages; 37 | 38 | void get_max_pages(void); 39 | int balloon_up(unsigned long n_pages); 40 | 41 | void mm_alloc_bitmap_remap(void); 42 | void arch_pfn_add(unsigned long pfn, unsigned long mfn); 43 | int chk_free_pages(unsigned long needed); 44 | 45 | #else /* CONFIG_BALLOON */ 46 | 47 | static inline void get_max_pages(void) { } 48 | static inline void mm_alloc_bitmap_remap(void) { } 49 | static inline int chk_free_pages(unsigned long needed) 50 | { 51 | return needed <= nr_free_pages; 52 | } 53 | 54 | #endif /* CONFIG_BALLOON */ 55 | #endif /* _BALLOON_H_ */ 56 | -------------------------------------------------------------------------------- /include/blkfront.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct blkfront_dev; 5 | struct blkfront_aiocb 6 | { 7 | struct blkfront_dev *aio_dev; 8 | uint8_t *aio_buf; 9 | size_t aio_nbytes; 10 | off_t aio_offset; 11 | size_t total_bytes; 12 | uint8_t is_write; 13 | void *data; 14 | 15 | grant_ref_t gref[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 16 | int n; 17 | 18 | void (*aio_cb)(struct blkfront_aiocb *aiocb, int ret); 19 | }; 20 | struct blkfront_info 21 | { 22 | uint64_t sectors; 23 | unsigned sector_size; 24 | int mode; 25 | int info; 26 | int barrier; 27 | int flush; 28 | }; 29 | struct blkfront_dev *init_blkfront(char *nodename, struct blkfront_info *info); 30 | #ifdef HAVE_LIBC 31 | #include 32 | /* POSIX IO functions: 33 | * use blkfront_open() to get a file descriptor to the block device 34 | * Don't use the other blkfront posix functions here directly, instead use 35 | * read(), write(), lseek() and fstat() on the file descriptor 36 | */ 37 | int blkfront_open(struct blkfront_dev *dev); 38 | int blkfront_posix_rwop(int fd, uint8_t* buf, size_t count, int write); 39 | #define blkfront_posix_write(fd, buf, count) blkfront_posix_rwop(fd, (uint8_t*)buf, count, 1) 40 | #define blkfront_posix_read(fd, buf, count) blkfront_posix_rwop(fd, (uint8_t*)buf, count, 0) 41 | int blkfront_posix_fstat(int fd, struct stat* buf); 42 | #endif 43 | void blkfront_aio(struct blkfront_aiocb *aiocbp, int write); 44 | #define blkfront_aio_read(aiocbp) blkfront_aio(aiocbp, 0) 45 | #define blkfront_aio_write(aiocbp) blkfront_aio(aiocbp, 1) 46 | void blkfront_io(struct blkfront_aiocb *aiocbp, int write); 47 | #define blkfront_read(aiocbp) blkfront_io(aiocbp, 0) 48 | #define blkfront_write(aiocbp) blkfront_io(aiocbp, 1) 49 | void blkfront_aio_push_operation(struct blkfront_aiocb *aiocbp, uint8_t op); 50 | int blkfront_aio_poll(struct blkfront_dev *dev); 51 | void blkfront_sync(struct blkfront_dev *dev); 52 | void shutdown_blkfront(struct blkfront_dev *dev); 53 | 54 | extern struct wait_queue_head blkfront_queue; 55 | -------------------------------------------------------------------------------- /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/compiler.h: -------------------------------------------------------------------------------- 1 | #ifndef __MINIOS_COMPILER_H_ 2 | #define __MINIOS_COMPILER_H_ 3 | 4 | #if __GNUC__ == 2 && __GNUC_MINOR__ < 96 5 | #define __builtin_expect(x, expected_value) (x) 6 | #endif 7 | #define unlikely(x) __builtin_expect(!!(x),0) 8 | #define likely(x) __builtin_expect(!!(x),1) 9 | #define __packed __attribute__((__packed__)) 10 | 11 | #endif /* __MINIOS_COMPILER_H_ */ 12 | -------------------------------------------------------------------------------- /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 | #include 47 | 48 | struct consfront_dev { 49 | domid_t dom; 50 | 51 | struct xencons_interface *ring; 52 | grant_ref_t ring_ref; 53 | evtchn_port_t evtchn; 54 | 55 | char *nodename; 56 | char *backend; 57 | 58 | xenbus_event_queue events; 59 | 60 | bool is_raw; 61 | 62 | #ifdef HAVE_LIBC 63 | int fd; 64 | #endif 65 | }; 66 | 67 | extern uint32_t console_evtchn; 68 | 69 | void print(int direct, const char *fmt, va_list args); 70 | void printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); 71 | void xprintk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); 72 | 73 | #define tprintk(_fmt, _args...) printk("[%s] " _fmt, current->name, ##_args) 74 | 75 | void xencons_rx(char *buf, unsigned len, struct pt_regs *regs); 76 | void xencons_tx(void); 77 | 78 | void get_console(void *p); 79 | void init_console(void); 80 | void console_print(struct consfront_dev *dev, char *data, int length); 81 | void fini_consfront(struct consfront_dev *dev); 82 | void suspend_console(void); 83 | void resume_console(void); 84 | 85 | /* Low level functions defined in xencons_ring.c */ 86 | extern struct wait_queue_head console_queue; 87 | struct consfront_dev *xencons_ring_init(void); 88 | void xencons_ring_fini(struct consfront_dev* dev); 89 | void xencons_ring_resume(struct consfront_dev* dev); 90 | struct consfront_dev *init_consfront(char *_nodename); 91 | int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len); 92 | int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len); 93 | int xencons_ring_avail(struct consfront_dev *dev); 94 | int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len); 95 | void free_consfront(struct consfront_dev *dev); 96 | 97 | #endif /* _LIB_CONSOLE_H_ */ 98 | -------------------------------------------------------------------------------- /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/e820.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | * 3 | * (C) 2016 - Juergen Gross, SUSE Linux GmbH 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef __E820_HEADER 25 | #define __E820_HEADER 26 | 27 | /* PC BIOS standard E820 types and structure. */ 28 | #define E820_RAM 1 29 | #define E820_RESERVED 2 30 | #define E820_ACPI 3 31 | #define E820_NVS 4 32 | #define E820_UNUSABLE 5 33 | #define E820_PMEM 7 34 | #define E820_TYPES 8 35 | 36 | struct __packed e820entry { 37 | uint64_t addr; 38 | uint64_t size; 39 | uint32_t type; 40 | }; 41 | 42 | /* Maximum number of entries. */ 43 | #define E820_MAX 128 44 | 45 | extern struct e820entry e820_map[]; 46 | extern unsigned e820_entries; 47 | 48 | #endif /*__E820_HEADER*/ 49 | -------------------------------------------------------------------------------- /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/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 | void arch_init_events(void); 29 | 30 | /* Called by fini_events to close any ports opened by arch-specific code. */ 31 | void arch_unbind_ports(void); 32 | 33 | void arch_fini_events(void); 34 | 35 | int do_event(evtchn_port_t port, struct pt_regs *regs); 36 | evtchn_port_t bind_virq(uint32_t virq, evtchn_handler_t handler, void *data); 37 | evtchn_port_t bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t handler, void *data); 38 | evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler, 39 | void *data); 40 | void unbind_evtchn(evtchn_port_t port); 41 | void init_events(void); 42 | int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler, 43 | void *data, evtchn_port_t *port); 44 | int evtchn_bind_interdomain(domid_t pal, evtchn_port_t remote_port, 45 | evtchn_handler_t handler, void *data, 46 | evtchn_port_t *local_port); 47 | int evtchn_get_peercontext(evtchn_port_t local_port, char *ctx, int size); 48 | void unbind_all_ports(void); 49 | 50 | static inline int notify_remote_via_evtchn(evtchn_port_t port) 51 | { 52 | evtchn_send_t op; 53 | op.port = port; 54 | return HYPERVISOR_event_channel_op(EVTCHNOP_send, &op); 55 | } 56 | 57 | void fini_events(void); 58 | void suspend_events(void); 59 | 60 | #endif /* _EVENTS_H_ */ 61 | -------------------------------------------------------------------------------- /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 | grant_entry_v1_t *arch_init_gnttab(int nr_grant_frames); 18 | void arch_suspend_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames); 19 | void arch_resume_gnttab(grant_entry_v1_t *gnttab_table, int nr_grant_frames); 20 | 21 | #endif /* !__GNTTAB_H__ */ 22 | -------------------------------------------------------------------------------- /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 | #elif defined(__arm__) || defined(__aarch64__) 22 | #include 23 | #else 24 | #error "Unsupported architecture" 25 | #endif 26 | #include 27 | #include 28 | 29 | /* hypervisor.c */ 30 | #ifdef CONFIG_PARAVIRT 31 | /* 32 | * a placeholder for the start of day information passed up from the hypervisor 33 | */ 34 | union start_info_union 35 | { 36 | start_info_t start_info; 37 | char padding[512]; 38 | }; 39 | extern union start_info_union start_info_union; 40 | #define start_info (start_info_union.start_info) 41 | #else 42 | int hvm_get_parameter(int idx, uint64_t *value); 43 | int hvm_set_parameter(int idx, uint64_t value); 44 | #endif 45 | shared_info_t *map_shared_info(void *p); 46 | void unmap_shared_info(void); 47 | void force_evtchn_callback(void); 48 | void do_hypervisor_callback(struct pt_regs *regs); 49 | void mask_evtchn(uint32_t port); 50 | void unmask_evtchn(uint32_t port); 51 | void clear_evtchn(uint32_t port); 52 | 53 | extern int in_callback; 54 | 55 | #endif /* __HYPERVISOR_H__ */ 56 | -------------------------------------------------------------------------------- /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 | #define MAX_CMDLINE_SIZE 1024 5 | extern char cmdline[MAX_CMDLINE_SIZE]; 6 | 7 | void start_kernel(void* par); 8 | void pre_suspend(void); 9 | void post_suspend(int canceled); 10 | void do_exit(void) __attribute__((noreturn)); 11 | void arch_do_exit(void); 12 | void stop_kernel(void); 13 | 14 | #endif /* _KERNEL_H_ */ 15 | -------------------------------------------------------------------------------- /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/lwipopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lwipopts.h 3 | * 4 | * Configuration for lwIP running on mini-os 5 | * 6 | * Tim Deegan , July 2007 7 | */ 8 | 9 | #ifndef __LWIP_LWIPOPTS_H__ 10 | #define __LWIP_LWIPOPTS_H__ 11 | 12 | #define SYS_LIGHTWEIGHT_PROT 1 13 | #define MEM_LIBC_MALLOC 1 14 | #define LWIP_TIMEVAL_PRIVATE 0 15 | #define LWIP_DHCP 1 16 | #define LWIP_COMPAT_SOCKETS 0 17 | #define LWIP_IGMP 1 18 | #define LWIP_USE_HEAP_FROM_INTERRUPT 1 19 | #define MEMP_NUM_SYS_TIMEOUT 10 20 | #define TCP_SND_BUF 3000 21 | #define TCP_MSS 1500 22 | 23 | #endif /* __LWIP_LWIPOPTS_H__ */ 24 | -------------------------------------------------------------------------------- /include/minios-external/README: -------------------------------------------------------------------------------- 1 | WARNING - DO NOT EDIT THINGS IN THIS DIRECTORY 2 | ---------------------------------------------- 3 | 4 | These files were obtained elsewhere and should only be updated by 5 | copying new versions from the source location, as documented below: 6 | 7 | bsd-COPYRIGHT 8 | bsd-sys-queue.h 9 | bsd-queue.3 10 | 11 | Obtained from the FreeBSD SVN using the following commands: 12 | svn co -r 221843 svn://svn.freebsd.org/base/head/sys/sys/ 13 | svn co -r 221843 svn://svn.freebsd.org/base/head/share/man/man3 14 | svn cat -r 221843 http://svn.freebsd.org/base/head/COPYRIGHT >tools/libxl/external/bsd-COPYRIGHT 15 | 16 | Exceptions: 17 | 18 | README 19 | 20 | This file 21 | 22 | bsd-sys-queue-h-seddery 23 | 24 | Script to transform the above into a new namespace. 25 | -------------------------------------------------------------------------------- /include/minios-external/bsd-sys-queue-h-seddery: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -p 2 | # 3 | # This script is part of the Xen build system. It has a very 4 | # permissive licence to avoid complicating the licence of the 5 | # generated header file and to allow this seddery to be reused by 6 | # other projects. 7 | # 8 | # Permission is hereby granted, free of charge, to any person 9 | # obtaining a copy of this individual file (the "Software"), to deal 10 | # in the Software without restriction, including without limitation 11 | # the rights to use, copy, modify, merge, publish, distribute, 12 | # sublicense, and/or sell copies of the Software, and to permit 13 | # persons to whom the Software is furnished to do so, subject to the 14 | # following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be 17 | # included in all copies or substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 23 | # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 24 | # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | # SOFTWARE. 27 | # 28 | # Copyright (C) 2011 Citrix Ltd 29 | 30 | our $namespace, $ucnamespace; 31 | 32 | BEGIN { 33 | die unless @ARGV; 34 | $namespace = pop @ARGV; 35 | $namespace =~ s/^--prefix=// or die; 36 | $ucnamespace = uc $namespace; 37 | 38 | print < 30 | #elif defined(__x86_64__) 31 | #include 32 | #elif defined(__arm__) || defined(__aarch64__) 33 | #include 34 | #else 35 | #error "Unsupported architecture" 36 | #endif 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER 44 | #define STACK_SIZE __STACK_SIZE 45 | 46 | #define round_pgdown(_p) ((_p) & PAGE_MASK) 47 | #define round_pgup(_p) (((_p) + (PAGE_SIZE - 1)) & PAGE_MASK) 48 | 49 | extern unsigned long nr_free_pages; 50 | 51 | extern unsigned long *mm_alloc_bitmap; 52 | extern unsigned long mm_alloc_bitmap_size; 53 | 54 | void init_mm(void); 55 | unsigned long alloc_pages(int order); 56 | #define alloc_page() alloc_pages(0) 57 | void free_pages(void *pointer, int order); 58 | #define free_page(p) free_pages(p, 0) 59 | 60 | static __inline__ int get_order(unsigned long size) 61 | { 62 | int order; 63 | size = (size-1) >> PAGE_SHIFT; 64 | for ( order = 0; size; order++ ) 65 | size >>= 1; 66 | return order; 67 | } 68 | 69 | void arch_init_demand_mapping_area(void); 70 | void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p); 71 | 72 | unsigned long allocate_ondemand(unsigned long n, unsigned long alignment); 73 | /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */ 74 | void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride, 75 | unsigned long increment, unsigned long alignment, domid_t id, 76 | int *err, unsigned long prot); 77 | int do_map_frames(unsigned long addr, 78 | const unsigned long *f, unsigned long n, unsigned long stride, 79 | unsigned long increment, domid_t id, int *err, unsigned long prot); 80 | int unmap_frames(unsigned long va, unsigned long num_frames); 81 | int map_frame_rw(unsigned long addr, unsigned long mfn); 82 | unsigned long map_frame_virt(unsigned long mfn); 83 | #ifdef HAVE_LIBC 84 | extern unsigned long heap, brk, heap_mapped, heap_end; 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 | #endif 5 | struct netfront_dev; 6 | struct netfront_dev *init_netfront(char *nodename, 7 | void (*netif_rx)(unsigned char *data, 8 | int len, void* arg), 9 | unsigned char rawmac[6], 10 | char **ip); 11 | void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len); 12 | void shutdown_netfront(struct netfront_dev *dev); 13 | void suspend_netfront(void); 14 | void resume_netfront(void); 15 | #ifdef HAVE_LIBC 16 | int netfront_tap_open(char *nodename); 17 | ssize_t netfront_receive(struct netfront_dev *dev, unsigned char *data, size_t len); 18 | #endif 19 | 20 | extern struct wait_queue_head netfront_queue; 21 | 22 | #ifdef HAVE_LWIP 23 | /* Call this to bring up the netfront interface and the lwIP stack. 24 | * N.B. _must_ be called from a thread; it's not safe to call this from 25 | * app_main(). */ 26 | void start_networking(void); 27 | void stop_networking(void); 28 | 29 | void networking_set_addr(struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw); 30 | #endif 31 | -------------------------------------------------------------------------------- /include/paravirt.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- 2 | * 3 | * (C) 2016 - Juergen Gross, SUSE Linux GmbH 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef _PARAVIRT_H 25 | #define _PARAVIRT_H 26 | 27 | #if defined(CONFIG_PARAVIRT) 28 | 29 | #define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)]) 30 | #define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)]) 31 | 32 | /* for P2M */ 33 | #ifdef __x86_64__ 34 | #define P2M_SHIFT 9 35 | #else 36 | #define P2M_SHIFT 10 37 | #endif 38 | #define P2M_ENTRIES (1UL << P2M_SHIFT) 39 | #define P2M_MASK (P2M_ENTRIES - 1) 40 | #define L1_P2M_SHIFT P2M_SHIFT 41 | #define L2_P2M_SHIFT (2 * P2M_SHIFT) 42 | #define L3_P2M_SHIFT (3 * P2M_SHIFT) 43 | #define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK) 44 | #define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK) 45 | #define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK) 46 | #define INVALID_P2M_ENTRY (~0UL) 47 | 48 | void p2m_chk_pfn(unsigned long pfn); 49 | 50 | static inline unsigned long p2m_pages(unsigned long pages) 51 | { 52 | return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT; 53 | } 54 | 55 | void arch_init_p2m(unsigned long max_pfn_p); 56 | 57 | #else 58 | 59 | #define mfn_to_pfn(_mfn) ((unsigned long)(_mfn)) 60 | #define pfn_to_mfn(_pfn) ((unsigned long)(_pfn)) 61 | 62 | static inline void arch_init_p2m(unsigned long max_pfn_p) { } 63 | 64 | #endif 65 | 66 | #if defined(CONFIG_PARAVIRT) && defined(CONFIG_BALLOON) 67 | 68 | void arch_remap_p2m(unsigned long max_pfn); 69 | int arch_expand_p2m(unsigned long max_pfn); 70 | 71 | #else 72 | 73 | static inline void arch_remap_p2m(unsigned long max_pfn) { } 74 | static inline int arch_expand_p2m(unsigned long max_pfn) 75 | { 76 | return 0; 77 | } 78 | 79 | #endif 80 | 81 | #endif /* _PARAVIRT_H */ 82 | -------------------------------------------------------------------------------- /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 | void cfmakeraw(struct termios *tios); 87 | 88 | #endif /* _POSIX_TERMIOS_H */ 89 | -------------------------------------------------------------------------------- /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/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 | void fini_shutdown(void); 8 | void kernel_suspend(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /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 | s_time_t get_s_time(void); 59 | s_time_t get_v_time(void); 60 | uint64_t monotonic_clock(void); 61 | void block_domain(s_time_t until); 62 | 63 | #endif /* _MINIOS_TIME_H_ */ 64 | -------------------------------------------------------------------------------- /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 | struct tpm_chip* init_tpm2_tis(unsigned long baseaddr, int localities, unsigned int irq); 40 | void shutdown_tpm_tis(struct tpm_chip* tpm); 41 | 42 | int tpm_tis_request_locality(struct tpm_chip* tpm, int locality); 43 | int tpm_tis_cmd(struct tpm_chip* tpm, uint8_t* req, size_t reqlen, uint8_t** resp, size_t* resplen); 44 | 45 | #ifdef HAVE_LIBC 46 | #include 47 | #include 48 | /* POSIX IO functions: 49 | * use tpm_tis_open() to get a file descriptor to the tpm device 50 | * use write() on the fd to send a command to the backend. You must 51 | * include the entire command in a single call to write(). 52 | * use read() on the fd to read the response. You can use 53 | * fstat() to get the size of the response and lseek() to seek on it. 54 | */ 55 | int tpm_tis_open(struct tpm_chip* tpm); 56 | int tpm_tis_posix_read(int fd, uint8_t* buf, size_t count); 57 | int tpm_tis_posix_write(int fd, const uint8_t* buf, size_t count); 58 | int tpm_tis_posix_fstat(int fd, struct stat* buf); 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /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 | #if defined(__i386__) || defined(__arm__) 31 | typedef long long quad_t; 32 | typedef unsigned long long u_quad_t; 33 | #elif defined(__x86_64__) 34 | typedef long quad_t; 35 | typedef unsigned long u_quad_t; 36 | #endif /* __i386__ || __x86_64__ */ 37 | 38 | #ifdef HAVE_LIBC 39 | #include 40 | #include 41 | #else 42 | #if defined(__i386__) || defined(__arm__) 43 | typedef unsigned int uintptr_t; 44 | typedef int intptr_t; 45 | #elif defined(__x86_64__) || defined(__aarch64__) 46 | typedef unsigned long uintptr_t; 47 | typedef long intptr_t; 48 | #endif /* __i386__ || __x86_64__ */ 49 | typedef unsigned char uint8_t; 50 | typedef signed char int8_t; 51 | typedef unsigned short uint16_t; 52 | typedef signed short int16_t; 53 | typedef unsigned int uint32_t; 54 | typedef signed int int32_t; 55 | #if defined(__i386__) || defined(__arm__) 56 | typedef signed long long int64_t; 57 | typedef unsigned long long uint64_t; 58 | #elif defined(__x86_64__) || defined(__aarch64__) 59 | typedef signed long int64_t; 60 | typedef unsigned long uint64_t; 61 | #endif 62 | typedef uint64_t uintmax_t; 63 | typedef int64_t intmax_t; 64 | typedef int64_t off_t; 65 | #endif 66 | 67 | typedef intptr_t ptrdiff_t; 68 | 69 | 70 | #ifndef HAVE_LIBC 71 | typedef long ssize_t; 72 | #endif 73 | 74 | #endif /* _TYPES_H_ */ 75 | -------------------------------------------------------------------------------- /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 = (void *)(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 = ARCH_SPIN_LOCK_UNLOCKED; 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/asm_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef _X86_ASM_MACRO_H_ 2 | #define _X86_ASM_MACRO_H_ 3 | 4 | #ifdef __ASSEMBLY__ 5 | # if defined(__x86_64__) 6 | # define _WORD .quad 7 | # elif defined(__i386__) 8 | # define _WORD .long 9 | # endif 10 | #else 11 | # if defined(__x86_64__) 12 | # define _WORD ".quad" 13 | # elif defined(__i386__) 14 | # define _WORD ".long" 15 | # endif 16 | #endif 17 | 18 | #endif /* _X86_ASM_MACRO_H_ */ 19 | 20 | /* 21 | * Local variables: 22 | * mode: C 23 | * c-file-style: "BSD" 24 | * c-basic-offset: 4 25 | * tab-width: 4 26 | * indent-tabs-mode: nil 27 | * End: 28 | */ 29 | -------------------------------------------------------------------------------- /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/COPYING: -------------------------------------------------------------------------------- 1 | XEN NOTICE 2 | ========== 3 | 4 | This copyright applies to all files within this subdirectory and its 5 | subdirectories: 6 | include/public/*.h 7 | include/public/hvm/*.h 8 | include/public/io/*.h 9 | 10 | The intention is that these files can be freely copied into the source 11 | tree of an operating system when porting that OS to run on Xen. Doing 12 | so does *not* cause the OS to become subject to the terms of the GPL. 13 | 14 | All other files in the Xen source distribution are covered by version 15 | 2 of the GNU General Public License except where explicitly stated 16 | otherwise within individual source files. 17 | 18 | -- Keir Fraser (on behalf of the Xen team) 19 | 20 | ===================================================================== 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy 23 | of this software and associated documentation files (the "Software"), to 24 | deal in the Software without restriction, including without limitation the 25 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 26 | sell copies of the Software, and to permit persons to whom the Software is 27 | furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in 30 | all copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 37 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 38 | DEALINGS IN THE SOFTWARE. 39 | -------------------------------------------------------------------------------- /include/xen/arch-arm/hvm/save.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Structure definitions for HVM state that is held by Xen and must 3 | * be saved along with the domain's memory and device-model state. 4 | * 5 | * Copyright (c) 2012 Citrix Systems Ltd. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to 9 | * deal in the Software without restriction, including without limitation the 10 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 | * sell copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef __XEN_PUBLIC_HVM_SAVE_ARM_H__ 27 | #define __XEN_PUBLIC_HVM_SAVE_ARM_H__ 28 | 29 | #endif 30 | 31 | /* 32 | * Local variables: 33 | * mode: C 34 | * c-file-style: "BSD" 35 | * c-basic-offset: 4 36 | * tab-width: 4 37 | * indent-tabs-mode: nil 38 | * End: 39 | */ 40 | -------------------------------------------------------------------------------- /include/xen/arch-arm/smccc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * smccc.h 3 | * 4 | * SMC/HVC interface in accordance with SMC Calling Convention. 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 | * Copyright 2017 (C) EPAM Systems 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ 28 | #define __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ 29 | 30 | #include "public/xen.h" 31 | 32 | /* 33 | * Hypervisor Service version. 34 | * 35 | * We can't use XEN version here, because of SMCCC requirements: 36 | * Major revision should change every time SMC/HVC function is removed. 37 | * Minor revision should change every time SMC/HVC function is added. 38 | * So, it is SMCCC protocol revision code, not XEN version. 39 | * 40 | * Those values are subjected to change, when interface will be extended. 41 | */ 42 | #define XEN_SMCCC_MAJOR_REVISION 0 43 | #define XEN_SMCCC_MINOR_REVISION 1 44 | 45 | /* Hypervisor Service UID. Randomly generated with uuidgen. */ 46 | #define XEN_SMCCC_UID XEN_DEFINE_UUID(0xa71812dc, 0xc698, 0x4369, 0x9acf, \ 47 | 0x79, 0xd1, 0x8d, 0xde, 0xe6, 0x67) 48 | 49 | /* Standard Service Service Call version. */ 50 | #define SSSC_SMCCC_MAJOR_REVISION 0 51 | #define SSSC_SMCCC_MINOR_REVISION 1 52 | 53 | /* Standard Service Call UID. Randomly generated with uuidgen. */ 54 | #define SSSC_SMCCC_UID XEN_DEFINE_UUID(0xf863386f, 0x4b39, 0x4cbd, 0x9220,\ 55 | 0xce, 0x16, 0x41, 0xe5, 0x9f, 0x6f) 56 | 57 | #endif /* __XEN_PUBLIC_ARCH_ARM_SMCCC_H__ */ 58 | 59 | /* 60 | * Local variables: 61 | * mode: C 62 | * c-file-style: "BSD" 63 | * c-basic-offset: 4 64 | * indent-tabs-mode: nil 65 | * End:b 66 | */ 67 | -------------------------------------------------------------------------------- /include/xen/arch-x86_32.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * arch-x86_32.h 3 | * 4 | * Guest OS interface to x86 32-bit Xen. 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 | * Copyright (c) 2004-2006, K A Fraser 25 | */ 26 | 27 | #include "arch-x86/xen.h" 28 | -------------------------------------------------------------------------------- /include/xen/arch-x86_64.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * arch-x86_64.h 3 | * 4 | * Guest OS interface to x86 64-bit Xen. 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 | * Copyright (c) 2004-2006, K A Fraser 25 | */ 26 | 27 | #include "arch-x86/xen.h" 28 | 29 | /* 30 | * ` enum neg_errnoval 31 | * ` HYPERVISOR_set_callbacks(unsigned long event_selector, 32 | * ` unsigned long event_address, 33 | * ` unsigned long failsafe_selector, 34 | * ` unsigned long failsafe_address); 35 | * ` 36 | * Register for callbacks on events. When an event (from an event 37 | * channel) occurs, event_address is used as the value of eip. 38 | * 39 | * A similar callback occurs if the segment selectors are invalid. 40 | * failsafe_address is used as the value of eip. 41 | * 42 | * On x86_64, event_selector and failsafe_selector are ignored (???). 43 | */ 44 | -------------------------------------------------------------------------------- /include/xen/hvm/e820.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | * Copyright (c) 2006, Keir Fraser 21 | */ 22 | 23 | #ifndef __XEN_PUBLIC_HVM_E820_H__ 24 | #define __XEN_PUBLIC_HVM_E820_H__ 25 | 26 | #include "../xen.h" 27 | 28 | /* E820 location in HVM virtual address space. */ 29 | #define HVM_E820_PAGE 0x00090000 30 | #define HVM_E820_NR_OFFSET 0x000001E8 31 | #define HVM_E820_OFFSET 0x000002D0 32 | 33 | #define HVM_BELOW_4G_RAM_END 0xF0000000 34 | #define HVM_BELOW_4G_MMIO_START HVM_BELOW_4G_RAM_END 35 | #define HVM_BELOW_4G_MMIO_LENGTH ((xen_mk_ullong(1) << 32) - \ 36 | HVM_BELOW_4G_MMIO_START) 37 | 38 | #endif /* __XEN_PUBLIC_HVM_E820_H__ */ 39 | -------------------------------------------------------------------------------- /include/xen/hvm/hvm_info_table.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hvm/hvm_info_table.h 3 | * 4 | * HVM parameter and information table, written into guest memory map. 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 | * Copyright (c) 2006, Keir Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_HVM_HVM_INFO_TABLE_H__ 28 | #define __XEN_PUBLIC_HVM_HVM_INFO_TABLE_H__ 29 | 30 | #define HVM_INFO_PFN 0x09F 31 | #define HVM_INFO_OFFSET 0x800 32 | #define HVM_INFO_PADDR ((HVM_INFO_PFN << 12) + HVM_INFO_OFFSET) 33 | 34 | /* Maximum we can support with current vLAPIC ID mapping. */ 35 | #define HVM_MAX_VCPUS 128 36 | 37 | /* 38 | * In some cases SMP HVM guests may require knowledge of Xen's idea of vCPU ids 39 | * for their vCPUs. For example, HYPERVISOR_vcpu_op and some EVTCHNOP_* 40 | * hypercalls take vcpu id as a parameter. It is valid for HVM guests to assume 41 | * that Xen's vCPU id always equals to ACPI (not APIC!) id in MADT table which 42 | * is always present for SMP guests. 43 | */ 44 | 45 | struct hvm_info_table { 46 | char signature[8]; /* "HVM INFO" */ 47 | uint32_t length; 48 | uint8_t checksum; 49 | 50 | /* Should firmware build APIC descriptors (APIC MADT / MP BIOS)? */ 51 | uint8_t apic_mode; 52 | 53 | /* How many CPUs does this domain have? */ 54 | uint32_t nr_vcpus; 55 | 56 | /* 57 | * MEMORY MAP provided by HVM domain builder. 58 | * Notes: 59 | * 1. page_to_phys(x) = x << 12 60 | * 2. If a field is zero, the corresponding range does not exist. 61 | */ 62 | /* 63 | * 0x0 to page_to_phys(low_mem_pgend)-1: 64 | * RAM below 4GB (except for VGA hole 0xA0000-0xBFFFF) 65 | */ 66 | uint32_t low_mem_pgend; 67 | /* 68 | * page_to_phys(reserved_mem_pgstart) to 0xFFFFFFFF: 69 | * Reserved for special memory mappings 70 | */ 71 | uint32_t reserved_mem_pgstart; 72 | /* 73 | * 0x100000000 to page_to_phys(high_mem_pgend)-1: 74 | * RAM above 4GB 75 | */ 76 | uint32_t high_mem_pgend; 77 | 78 | /* Bitmap of which CPUs are online at boot time. */ 79 | uint8_t vcpu_online[(HVM_MAX_VCPUS + 7)/8]; 80 | }; 81 | 82 | #endif /* __XEN_PUBLIC_HVM_HVM_INFO_TABLE_H__ */ 83 | -------------------------------------------------------------------------------- /include/xen/hvm/hvm_xs_strings.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * hvm/hvm_xs_strings.h 3 | * 4 | * HVM xenstore strings used in HVMLOADER. 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 | * Copyright (c) 2013, Citrix Systems 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_HVM_HVM_XS_STRINGS_H__ 28 | #define __XEN_PUBLIC_HVM_HVM_XS_STRINGS_H__ 29 | 30 | #define HVM_XS_HVMLOADER "hvmloader" 31 | #define HVM_XS_BIOS "hvmloader/bios" 32 | #define HVM_XS_GENERATION_ID_ADDRESS "hvmloader/generation-id-address" 33 | #define HVM_XS_ALLOW_MEMORY_RELOCATE "hvmloader/allow-memory-relocate" 34 | 35 | /* The following values allow additional ACPI tables to be added to the 36 | * virtual ACPI BIOS that hvmloader constructs. The values specify the guest 37 | * physical address and length of a block of ACPI tables to add. The format of 38 | * the block is simply concatenated raw tables (which specify their own length 39 | * in the ACPI header). 40 | */ 41 | #define HVM_XS_ACPI_PT_ADDRESS "hvmloader/acpi/address" 42 | #define HVM_XS_ACPI_PT_LENGTH "hvmloader/acpi/length" 43 | 44 | /* Any number of SMBIOS types can be passed through to an HVM guest using 45 | * the following xenstore values. The values specify the guest physical 46 | * address and length of a block of SMBIOS structures for hvmloader to use. 47 | * The block is formatted in the following way: 48 | * 49 | * ... 50 | * 51 | * Each length separator is a 32b integer indicating the length of the next 52 | * SMBIOS structure. For DMTF defined types (0 - 121), the passed in struct 53 | * will replace the default structure in hvmloader. In addition, any 54 | * OEM/vendortypes (128 - 255) will all be added. 55 | */ 56 | #define HVM_XS_SMBIOS_PT_ADDRESS "hvmloader/smbios/address" 57 | #define HVM_XS_SMBIOS_PT_LENGTH "hvmloader/smbios/length" 58 | 59 | /* Set to 1 to enable SMBIOS default portable battery (type 22) values. */ 60 | #define HVM_XS_SMBIOS_DEFAULT_BATTERY "hvmloader/smbios/default_battery" 61 | 62 | /* The following xenstore values are used to override some of the default 63 | * string values in the SMBIOS table constructed in hvmloader. 64 | */ 65 | #define HVM_XS_BIOS_STRINGS "bios-strings" 66 | #define HVM_XS_BIOS_VENDOR "bios-strings/bios-vendor" 67 | #define HVM_XS_BIOS_VERSION "bios-strings/bios-version" 68 | #define HVM_XS_SYSTEM_MANUFACTURER "bios-strings/system-manufacturer" 69 | #define HVM_XS_SYSTEM_PRODUCT_NAME "bios-strings/system-product-name" 70 | #define HVM_XS_SYSTEM_VERSION "bios-strings/system-version" 71 | #define HVM_XS_SYSTEM_SERIAL_NUMBER "bios-strings/system-serial-number" 72 | #define HVM_XS_ENCLOSURE_MANUFACTURER "bios-strings/enclosure-manufacturer" 73 | #define HVM_XS_ENCLOSURE_SERIAL_NUMBER "bios-strings/enclosure-serial-number" 74 | #define HVM_XS_ENCLOSURE_ASSET_TAG "bios-strings/enclosure-asset-tag" 75 | #define HVM_XS_BATTERY_MANUFACTURER "bios-strings/battery-manufacturer" 76 | #define HVM_XS_BATTERY_DEVICE_NAME "bios-strings/battery-device-name" 77 | 78 | /* 1 to 99 OEM strings can be set in xenstore using values of the form 79 | * below. These strings will be loaded into the SMBIOS type 11 structure. 80 | */ 81 | #define HVM_XS_OEM_STRINGS "bios-strings/oem-%d" 82 | 83 | #endif /* __XEN_PUBLIC_HVM_HVM_XS_STRINGS_H__ */ 84 | -------------------------------------------------------------------------------- /include/xen/hvm/pvdrivers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pvdrivers.h: Register of PV drivers product numbers. 3 | * Copyright (c) 2012, Citrix Systems Inc. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to 7 | * deal in the Software without restriction, including without limitation the 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | * sell copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef _XEN_PUBLIC_PVDRIVERS_H_ 25 | #define _XEN_PUBLIC_PVDRIVERS_H_ 26 | 27 | /* 28 | * This is the master registry of product numbers for 29 | * PV drivers. 30 | * If you need a new product number allocating, please 31 | * post to xen-devel@lists.xenproject.org. You should NOT use 32 | * a product number without allocating one. 33 | * If you maintain a separate versioning and distribution path 34 | * for PV drivers you should have a separate product number so 35 | * that your drivers can be separated from others. 36 | * 37 | * During development, you may use the product ID to 38 | * indicate a driver which is yet to be released. 39 | */ 40 | 41 | #define PVDRIVERS_PRODUCT_LIST(EACH) \ 42 | EACH("xensource-windows", 0x0001) /* Citrix */ \ 43 | EACH("gplpv-windows", 0x0002) /* James Harper */ \ 44 | EACH("linux", 0x0003) \ 45 | EACH("xenserver-windows-v7.0+", 0x0004) /* Citrix */ \ 46 | EACH("xenserver-windows-v7.2+", 0x0005) /* Citrix */ \ 47 | EACH("experimental", 0xffff) 48 | 49 | #endif /* _XEN_PUBLIC_PVDRIVERS_H_ */ 50 | -------------------------------------------------------------------------------- /include/xen/io/9pfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 9pfs.h -- Xen 9PFS transport 3 | * 4 | * Refer to docs/misc/9pfs.markdown for the specification 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 | * Copyright (C) 2017 Stefano Stabellini 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_IO_9PFS_H__ 28 | #define __XEN_PUBLIC_IO_9PFS_H__ 29 | 30 | #include "../grant_table.h" 31 | #include "ring.h" 32 | 33 | /* 34 | * See docs/misc/9pfs.markdown in xen.git for the full specification: 35 | * https://xenbits.xen.org/docs/unstable/misc/9pfs.html 36 | */ 37 | DEFINE_XEN_FLEX_RING_AND_INTF(xen_9pfs); 38 | 39 | #endif 40 | 41 | /* 42 | * Local variables: 43 | * mode: C 44 | * c-file-style: "BSD" 45 | * c-basic-offset: 4 46 | * tab-width: 4 47 | * indent-tabs-mode: nil 48 | * End: 49 | */ 50 | -------------------------------------------------------------------------------- /include/xen/io/console.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * console.h 3 | * 4 | * Console I/O interface for Xen guest OSes. 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 | * Copyright (c) 2005, Keir Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_IO_CONSOLE_H__ 28 | #define __XEN_PUBLIC_IO_CONSOLE_H__ 29 | 30 | typedef uint32_t XENCONS_RING_IDX; 31 | 32 | #define MASK_XENCONS_IDX(idx, ring) ((idx) & (sizeof(ring)-1)) 33 | 34 | struct xencons_interface { 35 | char in[1024]; 36 | char out[2048]; 37 | XENCONS_RING_IDX in_cons, in_prod; 38 | XENCONS_RING_IDX out_cons, out_prod; 39 | }; 40 | 41 | #ifdef XEN_WANT_FLEX_CONSOLE_RING 42 | #include "ring.h" 43 | DEFINE_XEN_FLEX_RING(xencons); 44 | #endif 45 | 46 | #endif /* __XEN_PUBLIC_IO_CONSOLE_H__ */ 47 | 48 | /* 49 | * Local variables: 50 | * mode: C 51 | * c-file-style: "BSD" 52 | * c-basic-offset: 4 53 | * tab-width: 4 54 | * indent-tabs-mode: nil 55 | * End: 56 | */ 57 | -------------------------------------------------------------------------------- /include/xen/io/libxenvchan.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * @section AUTHORS 4 | * 5 | * Copyright (C) 2010 Rafal Wojtczuk 6 | * 7 | * Authors: 8 | * Rafal Wojtczuk 9 | * Daniel De Graaf 10 | * 11 | * @section LICENSE 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining a copy 14 | * of this software and associated documentation files (the "Software"), to 15 | * deal in the Software without restriction, including without limitation the 16 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 17 | * sell copies of the Software, and to permit persons to whom the Software is 18 | * furnished to do so, subject to the following conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in 21 | * all copies or substantial portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | * DEALINGS IN THE SOFTWARE. 30 | * 31 | * @section DESCRIPTION 32 | * 33 | * Originally borrowed from the Qubes OS Project, http://www.qubes-os.org, 34 | * this code has been substantially rewritten to use the gntdev and gntalloc 35 | * devices instead of raw MFNs and map_foreign_range. 36 | * 37 | * This is a library for inter-domain communication. A standard Xen ring 38 | * buffer is used, with a datagram-based interface built on top. The grant 39 | * reference and event channels are shared in XenStore under a user-specified 40 | * path. 41 | * 42 | * The ring.h macros define an asymmetric interface to a shared data structure 43 | * that assumes all rings reside in a single contiguous memory space. This is 44 | * not suitable for vchan because the interface to the ring is symmetric except 45 | * for the setup. Unlike the producer-consumer rings defined in ring.h, the 46 | * size of the rings used in vchan are determined at execution time instead of 47 | * compile time, so the macros in ring.h cannot be used to access the rings. 48 | */ 49 | 50 | #include 51 | #include 52 | 53 | struct ring_shared { 54 | uint32_t cons, prod; 55 | }; 56 | 57 | #define VCHAN_NOTIFY_WRITE 0x1 58 | #define VCHAN_NOTIFY_READ 0x2 59 | 60 | /** 61 | * vchan_interface: primary shared data structure 62 | */ 63 | struct vchan_interface { 64 | /** 65 | * Standard consumer/producer interface, one pair per buffer 66 | * left is client write, server read 67 | * right is client read, server write 68 | */ 69 | struct ring_shared left, right; 70 | /** 71 | * size of the rings, which determines their location 72 | * 10 - at offset 1024 in ring's page 73 | * 11 - at offset 2048 in ring's page 74 | * 12+ - uses 2^(N-12) grants to describe the multi-page ring 75 | * These should remain constant once the page is shared. 76 | * Only one of the two orders can be 10 (or 11). 77 | */ 78 | uint16_t left_order, right_order; 79 | /** 80 | * Shutdown detection: 81 | * 0: client (or server) has exited 82 | * 1: client (or server) is connected 83 | * 2: client has not yet connected 84 | */ 85 | uint8_t cli_live, srv_live; 86 | /** 87 | * Notification bits: 88 | * VCHAN_NOTIFY_WRITE: send notify when data is written 89 | * VCHAN_NOTIFY_READ: send notify when data is read (consumed) 90 | * cli_notify is used for the client to inform the server of its action 91 | */ 92 | uint8_t cli_notify, srv_notify; 93 | /** 94 | * Grant list: ordering is left, right. Must not extend into actual ring 95 | * or grow beyond the end of the initial shared page. 96 | * These should remain constant once the page is shared, to allow 97 | * for possible remapping by a client that restarts. 98 | */ 99 | uint32_t grants[0]; 100 | }; 101 | 102 | -------------------------------------------------------------------------------- /include/xen/io/pciif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PCI Backend/Frontend Common Data Structures & Macros 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 | * Author: Ryan Wilson 23 | */ 24 | #ifndef __XEN_PCI_COMMON_H__ 25 | #define __XEN_PCI_COMMON_H__ 26 | 27 | /* Be sure to bump this number if you change this file */ 28 | #define XEN_PCI_MAGIC "7" 29 | 30 | /* xen_pci_sharedinfo flags */ 31 | #define _XEN_PCIF_active (0) 32 | #define XEN_PCIF_active (1<<_XEN_PCIF_active) 33 | #define _XEN_PCIB_AERHANDLER (1) 34 | #define XEN_PCIB_AERHANDLER (1<<_XEN_PCIB_AERHANDLER) 35 | #define _XEN_PCIB_active (2) 36 | #define XEN_PCIB_active (1<<_XEN_PCIB_active) 37 | 38 | /* xen_pci_op commands */ 39 | #define XEN_PCI_OP_conf_read (0) 40 | #define XEN_PCI_OP_conf_write (1) 41 | #define XEN_PCI_OP_enable_msi (2) 42 | #define XEN_PCI_OP_disable_msi (3) 43 | #define XEN_PCI_OP_enable_msix (4) 44 | #define XEN_PCI_OP_disable_msix (5) 45 | #define XEN_PCI_OP_aer_detected (6) 46 | #define XEN_PCI_OP_aer_resume (7) 47 | #define XEN_PCI_OP_aer_mmio (8) 48 | #define XEN_PCI_OP_aer_slotreset (9) 49 | #define XEN_PCI_OP_enable_multi_msi (10) 50 | 51 | /* xen_pci_op error numbers */ 52 | #define XEN_PCI_ERR_success (0) 53 | #define XEN_PCI_ERR_dev_not_found (-1) 54 | #define XEN_PCI_ERR_invalid_offset (-2) 55 | #define XEN_PCI_ERR_access_denied (-3) 56 | #define XEN_PCI_ERR_not_implemented (-4) 57 | /* XEN_PCI_ERR_op_failed - backend failed to complete the operation */ 58 | #define XEN_PCI_ERR_op_failed (-5) 59 | 60 | /* 61 | * it should be PAGE_SIZE-sizeof(struct xen_pci_op))/sizeof(struct msix_entry)) 62 | * Should not exceed 128 63 | */ 64 | #define SH_INFO_MAX_VEC 128 65 | 66 | struct xen_msix_entry { 67 | uint16_t vector; 68 | uint16_t entry; 69 | }; 70 | struct xen_pci_op { 71 | /* IN: what action to perform: XEN_PCI_OP_* */ 72 | uint32_t cmd; 73 | 74 | /* OUT: will contain an error number (if any) from errno.h */ 75 | int32_t err; 76 | 77 | /* IN: which device to touch */ 78 | uint32_t domain; /* PCI Domain/Segment */ 79 | uint32_t bus; 80 | uint32_t devfn; 81 | 82 | /* IN: which configuration registers to touch */ 83 | int32_t offset; 84 | int32_t size; 85 | 86 | /* IN/OUT: Contains the result after a READ or the value to WRITE */ 87 | uint32_t value; 88 | /* IN: Contains extra infor for this operation */ 89 | uint32_t info; 90 | /*IN: param for msi-x */ 91 | struct xen_msix_entry msix_entries[SH_INFO_MAX_VEC]; 92 | }; 93 | 94 | /*used for pcie aer handling*/ 95 | struct xen_pcie_aer_op 96 | { 97 | 98 | /* IN: what action to perform: XEN_PCI_OP_* */ 99 | uint32_t cmd; 100 | /*IN/OUT: return aer_op result or carry error_detected state as input*/ 101 | int32_t err; 102 | 103 | /* IN: which device to touch */ 104 | uint32_t domain; /* PCI Domain/Segment*/ 105 | uint32_t bus; 106 | uint32_t devfn; 107 | }; 108 | struct xen_pci_sharedinfo { 109 | /* flags - XEN_PCIF_* */ 110 | uint32_t flags; 111 | struct xen_pci_op op; 112 | struct xen_pcie_aer_op aer_op; 113 | }; 114 | 115 | #endif /* __XEN_PCI_COMMON_H__ */ 116 | 117 | /* 118 | * Local variables: 119 | * mode: C 120 | * c-file-style: "BSD" 121 | * c-basic-offset: 4 122 | * tab-width: 4 123 | * indent-tabs-mode: nil 124 | * End: 125 | */ 126 | -------------------------------------------------------------------------------- /include/xen/io/protocols.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * protocols.h 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 | * Copyright (c) 2008, Keir Fraser 23 | */ 24 | 25 | #ifndef __XEN_PROTOCOLS_H__ 26 | #define __XEN_PROTOCOLS_H__ 27 | 28 | #define XEN_IO_PROTO_ABI_X86_32 "x86_32-abi" 29 | #define XEN_IO_PROTO_ABI_X86_64 "x86_64-abi" 30 | #define XEN_IO_PROTO_ABI_ARM "arm-abi" 31 | 32 | #if defined(__i386__) 33 | # define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_32 34 | #elif defined(__x86_64__) 35 | # define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_64 36 | #elif defined(__arm__) || defined(__aarch64__) 37 | # define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_ARM 38 | #else 39 | # error arch fixup needed here 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/xen/io/xenbus.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * xenbus.h 3 | * 4 | * Xenbus protocol details. 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 | * Copyright (C) 2005 XenSource Ltd. 25 | */ 26 | 27 | #ifndef _XEN_PUBLIC_IO_XENBUS_H 28 | #define _XEN_PUBLIC_IO_XENBUS_H 29 | 30 | /* 31 | * The state of either end of the Xenbus, i.e. the current communication 32 | * status of initialisation across the bus. States here imply nothing about 33 | * the state of the connection between the driver and the kernel's device 34 | * layers. 35 | */ 36 | enum xenbus_state { 37 | XenbusStateUnknown = 0, 38 | 39 | XenbusStateInitialising = 1, 40 | 41 | /* 42 | * InitWait: Finished early initialisation but waiting for information 43 | * from the peer or hotplug scripts. 44 | */ 45 | XenbusStateInitWait = 2, 46 | 47 | /* 48 | * Initialised: Waiting for a connection from the peer. 49 | */ 50 | XenbusStateInitialised = 3, 51 | 52 | XenbusStateConnected = 4, 53 | 54 | /* 55 | * Closing: The device is being closed due to an error or an unplug event. 56 | */ 57 | XenbusStateClosing = 5, 58 | 59 | XenbusStateClosed = 6, 60 | 61 | /* 62 | * Reconfiguring: The device is being reconfigured. 63 | */ 64 | XenbusStateReconfiguring = 7, 65 | 66 | XenbusStateReconfigured = 8 67 | }; 68 | typedef enum xenbus_state XenbusState; 69 | 70 | #endif /* _XEN_PUBLIC_IO_XENBUS_H */ 71 | 72 | /* 73 | * Local variables: 74 | * mode: C 75 | * c-file-style: "BSD" 76 | * c-basic-offset: 4 77 | * tab-width: 4 78 | * indent-tabs-mode: nil 79 | * End: 80 | */ 81 | -------------------------------------------------------------------------------- /include/xen/nmi.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * nmi.h 3 | * 4 | * NMI callback registration and reason codes. 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 | * Copyright (c) 2005, Keir Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_NMI_H__ 28 | #define __XEN_PUBLIC_NMI_H__ 29 | 30 | #include "xen.h" 31 | 32 | /* 33 | * NMI reason codes: 34 | * Currently these are x86-specific, stored in arch_shared_info.nmi_reason. 35 | */ 36 | /* I/O-check error reported via ISA port 0x61, bit 6. */ 37 | #define _XEN_NMIREASON_io_error 0 38 | #define XEN_NMIREASON_io_error (1UL << _XEN_NMIREASON_io_error) 39 | /* PCI SERR reported via ISA port 0x61, bit 7. */ 40 | #define _XEN_NMIREASON_pci_serr 1 41 | #define XEN_NMIREASON_pci_serr (1UL << _XEN_NMIREASON_pci_serr) 42 | #if __XEN_INTERFACE_VERSION__ < 0x00040300 /* legacy alias of the above */ 43 | /* Parity error reported via ISA port 0x61, bit 7. */ 44 | #define _XEN_NMIREASON_parity_error 1 45 | #define XEN_NMIREASON_parity_error (1UL << _XEN_NMIREASON_parity_error) 46 | #endif 47 | /* Unknown hardware-generated NMI. */ 48 | #define _XEN_NMIREASON_unknown 2 49 | #define XEN_NMIREASON_unknown (1UL << _XEN_NMIREASON_unknown) 50 | 51 | /* 52 | * long nmi_op(unsigned int cmd, void *arg) 53 | * NB. All ops return zero on success, else a negative error code. 54 | */ 55 | 56 | /* 57 | * Register NMI callback for this (calling) VCPU. Currently this only makes 58 | * sense for domain 0, vcpu 0. All other callers will be returned EINVAL. 59 | * arg == pointer to xennmi_callback structure. 60 | */ 61 | #define XENNMI_register_callback 0 62 | struct xennmi_callback { 63 | unsigned long handler_address; 64 | unsigned long pad; 65 | }; 66 | typedef struct xennmi_callback xennmi_callback_t; 67 | DEFINE_XEN_GUEST_HANDLE(xennmi_callback_t); 68 | 69 | /* 70 | * Deregister NMI callback for this (calling) VCPU. 71 | * arg == NULL. 72 | */ 73 | #define XENNMI_unregister_callback 1 74 | 75 | #endif /* __XEN_PUBLIC_NMI_H__ */ 76 | 77 | /* 78 | * Local variables: 79 | * mode: C 80 | * c-file-style: "BSD" 81 | * c-basic-offset: 4 82 | * tab-width: 4 83 | * indent-tabs-mode: nil 84 | * End: 85 | */ 86 | -------------------------------------------------------------------------------- /include/xen/tmem.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * tmem.h 3 | * 4 | * Guest OS interface to Xen Transcendent Memory. 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 | * Copyright (c) 2004, K A Fraser 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_TMEM_H__ 28 | #define __XEN_PUBLIC_TMEM_H__ 29 | 30 | #include "xen.h" 31 | 32 | /* version of ABI */ 33 | #define TMEM_SPEC_VERSION 1 34 | 35 | /* Commands to HYPERVISOR_tmem_op() */ 36 | #ifdef __XEN__ 37 | #define TMEM_CONTROL 0 /* Now called XEN_SYSCTL_tmem_op */ 38 | #else 39 | #undef TMEM_CONTROL 40 | #endif 41 | #define TMEM_NEW_POOL 1 42 | #define TMEM_DESTROY_POOL 2 43 | #define TMEM_PUT_PAGE 4 44 | #define TMEM_GET_PAGE 5 45 | #define TMEM_FLUSH_PAGE 6 46 | #define TMEM_FLUSH_OBJECT 7 47 | #if __XEN_INTERFACE_VERSION__ < 0x00040400 48 | #define TMEM_NEW_PAGE 3 49 | #define TMEM_READ 8 50 | #define TMEM_WRITE 9 51 | #define TMEM_XCHG 10 52 | #endif 53 | 54 | /* Privileged commands now called via XEN_SYSCTL_tmem_op. */ 55 | #define TMEM_AUTH 101 /* as XEN_SYSCTL_TMEM_OP_SET_AUTH. */ 56 | #define TMEM_RESTORE_NEW 102 /* as XEN_SYSCTL_TMEM_OP_SET_POOL. */ 57 | 58 | /* Bits for HYPERVISOR_tmem_op(TMEM_NEW_POOL) */ 59 | #define TMEM_POOL_PERSIST 1 60 | #define TMEM_POOL_SHARED 2 61 | #define TMEM_POOL_PRECOMPRESSED 4 62 | #define TMEM_POOL_PAGESIZE_SHIFT 4 63 | #define TMEM_POOL_PAGESIZE_MASK 0xf 64 | #define TMEM_POOL_VERSION_SHIFT 24 65 | #define TMEM_POOL_VERSION_MASK 0xff 66 | #define TMEM_POOL_RESERVED_BITS 0x00ffff00 67 | 68 | /* Bits for client flags (save/restore) */ 69 | #define TMEM_CLIENT_COMPRESS 1 70 | #define TMEM_CLIENT_FROZEN 2 71 | 72 | /* Special errno values */ 73 | #define EFROZEN 1000 74 | #define EEMPTY 1001 75 | 76 | struct xen_tmem_oid { 77 | uint64_t oid[3]; 78 | }; 79 | typedef struct xen_tmem_oid xen_tmem_oid_t; 80 | DEFINE_XEN_GUEST_HANDLE(xen_tmem_oid_t); 81 | 82 | #ifndef __ASSEMBLY__ 83 | #if __XEN_INTERFACE_VERSION__ < 0x00040400 84 | typedef xen_pfn_t tmem_cli_mfn_t; 85 | #endif 86 | typedef XEN_GUEST_HANDLE(char) tmem_cli_va_t; 87 | struct tmem_op { 88 | uint32_t cmd; 89 | int32_t pool_id; 90 | union { 91 | struct { 92 | uint64_t uuid[2]; 93 | uint32_t flags; 94 | uint32_t arg1; 95 | } creat; /* for cmd == TMEM_NEW_POOL. */ 96 | struct { 97 | #if __XEN_INTERFACE_VERSION__ < 0x00040600 98 | uint64_t oid[3]; 99 | #else 100 | xen_tmem_oid_t oid; 101 | #endif 102 | uint32_t index; 103 | uint32_t tmem_offset; 104 | uint32_t pfn_offset; 105 | uint32_t len; 106 | xen_pfn_t cmfn; /* client machine page frame */ 107 | } gen; /* for all other cmd ("generic") */ 108 | } u; 109 | }; 110 | typedef struct tmem_op tmem_op_t; 111 | DEFINE_XEN_GUEST_HANDLE(tmem_op_t); 112 | #endif 113 | 114 | #endif /* __XEN_PUBLIC_TMEM_H__ */ 115 | 116 | /* 117 | * Local variables: 118 | * mode: C 119 | * c-file-style: "BSD" 120 | * c-basic-offset: 4 121 | * tab-width: 4 122 | * indent-tabs-mode: nil 123 | * End: 124 | */ 125 | -------------------------------------------------------------------------------- /include/xen/version.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * version.h 3 | * 4 | * Xen version, type, and compile information. 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 | * Copyright (c) 2005, Nguyen Anh Quynh 25 | * Copyright (c) 2005, Keir Fraser 26 | */ 27 | 28 | #ifndef __XEN_PUBLIC_VERSION_H__ 29 | #define __XEN_PUBLIC_VERSION_H__ 30 | 31 | #include "xen.h" 32 | 33 | /* NB. All ops return zero on success, except XENVER_{version,pagesize} 34 | * XENVER_{version,pagesize,build_id} */ 35 | 36 | /* arg == NULL; returns major:minor (16:16). */ 37 | #define XENVER_version 0 38 | 39 | /* arg == xen_extraversion_t. */ 40 | #define XENVER_extraversion 1 41 | typedef char xen_extraversion_t[16]; 42 | #define XEN_EXTRAVERSION_LEN (sizeof(xen_extraversion_t)) 43 | 44 | /* arg == xen_compile_info_t. */ 45 | #define XENVER_compile_info 2 46 | struct xen_compile_info { 47 | char compiler[64]; 48 | char compile_by[16]; 49 | char compile_domain[32]; 50 | char compile_date[32]; 51 | }; 52 | typedef struct xen_compile_info xen_compile_info_t; 53 | 54 | #define XENVER_capabilities 3 55 | typedef char xen_capabilities_info_t[1024]; 56 | #define XEN_CAPABILITIES_INFO_LEN (sizeof(xen_capabilities_info_t)) 57 | 58 | #define XENVER_changeset 4 59 | typedef char xen_changeset_info_t[64]; 60 | #define XEN_CHANGESET_INFO_LEN (sizeof(xen_changeset_info_t)) 61 | 62 | #define XENVER_platform_parameters 5 63 | struct xen_platform_parameters { 64 | xen_ulong_t virt_start; 65 | }; 66 | typedef struct xen_platform_parameters xen_platform_parameters_t; 67 | 68 | #define XENVER_get_features 6 69 | struct xen_feature_info { 70 | unsigned int submap_idx; /* IN: which 32-bit submap to return */ 71 | uint32_t submap; /* OUT: 32-bit submap */ 72 | }; 73 | typedef struct xen_feature_info xen_feature_info_t; 74 | 75 | /* Declares the features reported by XENVER_get_features. */ 76 | #include "features.h" 77 | 78 | /* arg == NULL; returns host memory page size. */ 79 | #define XENVER_pagesize 7 80 | 81 | /* arg == xen_domain_handle_t. 82 | * 83 | * The toolstack fills it out for guest consumption. It is intended to hold 84 | * the UUID of the guest. 85 | */ 86 | #define XENVER_guest_handle 8 87 | 88 | #define XENVER_commandline 9 89 | typedef char xen_commandline_t[1024]; 90 | 91 | /* 92 | * Return value is the number of bytes written, or XEN_Exx on error. 93 | * Calling with empty parameter returns the size of build_id. 94 | */ 95 | #define XENVER_build_id 10 96 | struct xen_build_id { 97 | uint32_t len; /* IN: size of buf[]. */ 98 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 99 | unsigned char buf[]; 100 | #elif defined(__GNUC__) 101 | unsigned char buf[1]; /* OUT: Variable length buffer with build_id. */ 102 | #endif 103 | }; 104 | typedef struct xen_build_id xen_build_id_t; 105 | 106 | #endif /* __XEN_PUBLIC_VERSION_H__ */ 107 | 108 | /* 109 | * Local variables: 110 | * mode: C 111 | * c-file-style: "BSD" 112 | * c-basic-offset: 4 113 | * tab-width: 4 114 | * indent-tabs-mode: nil 115 | * End: 116 | */ 117 | -------------------------------------------------------------------------------- /include/xen/xen-compat.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * xen-compat.h 3 | * 4 | * Guest OS interface to Xen. Compatibility layer. 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 | * Copyright (c) 2006, Christian Limpach 25 | */ 26 | 27 | #ifndef __XEN_PUBLIC_XEN_COMPAT_H__ 28 | #define __XEN_PUBLIC_XEN_COMPAT_H__ 29 | 30 | #define __XEN_LATEST_INTERFACE_VERSION__ 0x00040900 31 | 32 | #if defined(__XEN__) || defined(__XEN_TOOLS__) 33 | /* Xen is built with matching headers and implements the latest interface. */ 34 | #define __XEN_INTERFACE_VERSION__ __XEN_LATEST_INTERFACE_VERSION__ 35 | #elif !defined(__XEN_INTERFACE_VERSION__) 36 | /* Guests which do not specify a version get the legacy interface. */ 37 | #define __XEN_INTERFACE_VERSION__ 0x00000000 38 | #endif 39 | 40 | #if __XEN_INTERFACE_VERSION__ > __XEN_LATEST_INTERFACE_VERSION__ 41 | #error "These header files do not support the requested interface version." 42 | #endif 43 | 44 | #endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */ 45 | -------------------------------------------------------------------------------- /include/xen/xencomm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Permission is hereby granted, free of charge, to any person obtaining a copy 3 | * of this software and associated documentation files (the "Software"), to 4 | * deal in the Software without restriction, including without limitation the 5 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 6 | * sell copies of the Software, and to permit persons to whom the Software is 7 | * furnished to do so, subject to the following conditions: 8 | * 9 | * The above copyright notice and this permission notice shall be included in 10 | * all copies or substantial portions of the Software. 11 | * 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 | * DEALINGS IN THE SOFTWARE. 19 | * 20 | * Copyright (C) IBM Corp. 2006 21 | */ 22 | 23 | #ifndef _XEN_XENCOMM_H_ 24 | #define _XEN_XENCOMM_H_ 25 | 26 | /* A xencomm descriptor is a scatter/gather list containing physical 27 | * addresses corresponding to a virtually contiguous memory area. The 28 | * hypervisor translates these physical addresses to machine addresses to copy 29 | * to and from the virtually contiguous area. 30 | */ 31 | 32 | #define XENCOMM_MAGIC 0x58434F4D /* 'XCOM' */ 33 | #define XENCOMM_INVALID (~0UL) 34 | 35 | struct xencomm_desc { 36 | uint32_t magic; 37 | uint32_t nr_addrs; /* the number of entries in address[] */ 38 | uint64_t address[0]; 39 | }; 40 | 41 | #endif /* _XEN_XENCOMM_H_ */ 42 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | #include 13 | 14 | int ___lock_init(_LOCK_T *lock) 15 | { 16 | lock->busy = 0; 17 | init_waitqueue_head(&lock->wait); 18 | return 0; 19 | } 20 | 21 | int ___lock_acquire(_LOCK_T *lock) 22 | { 23 | unsigned long flags; 24 | while(1) { 25 | wait_event(lock->wait, !lock->busy); 26 | local_irq_save(flags); 27 | if (!lock->busy) 28 | break; 29 | local_irq_restore(flags); 30 | } 31 | lock->busy = 1; 32 | local_irq_restore(flags); 33 | return 0; 34 | } 35 | 36 | int ___lock_try_acquire(_LOCK_T *lock) 37 | { 38 | unsigned long flags; 39 | int ret = -1; 40 | local_irq_save(flags); 41 | if (!lock->busy) { 42 | lock->busy = 1; 43 | ret = 0; 44 | } 45 | local_irq_restore(flags); 46 | return ret; 47 | } 48 | 49 | int ___lock_release(_LOCK_T *lock) 50 | { 51 | unsigned long flags; 52 | local_irq_save(flags); 53 | lock->busy = 0; 54 | wake_up(&lock->wait); 55 | local_irq_restore(flags); 56 | return 0; 57 | } 58 | 59 | 60 | int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock) 61 | { 62 | lock->owner = NULL; 63 | init_waitqueue_head(&lock->wait); 64 | return 0; 65 | } 66 | 67 | int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock) 68 | { 69 | unsigned long flags; 70 | if (lock->owner != get_current()) { 71 | while (1) { 72 | wait_event(lock->wait, lock->owner == NULL); 73 | local_irq_save(flags); 74 | if (lock->owner == NULL) 75 | break; 76 | local_irq_restore(flags); 77 | } 78 | lock->owner = get_current(); 79 | local_irq_restore(flags); 80 | } 81 | lock->count++; 82 | return 0; 83 | } 84 | 85 | int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock) 86 | { 87 | unsigned long flags; 88 | int ret = -1; 89 | local_irq_save(flags); 90 | if (!lock->owner) { 91 | ret = 0; 92 | lock->owner = get_current(); 93 | lock->count++; 94 | } 95 | local_irq_restore(flags); 96 | return ret; 97 | } 98 | 99 | int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock) 100 | { 101 | unsigned long flags; 102 | BUG_ON(lock->owner != get_current()); 103 | if (--lock->count) 104 | return 0; 105 | local_irq_save(flags); 106 | lock->owner = NULL; 107 | wake_up(&lock->wait); 108 | local_irq_restore(flags); 109 | return 0; 110 | } 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /minios.mk: -------------------------------------------------------------------------------- 1 | # 2 | # The file contains the common make rules for building mini-os. 3 | # 4 | 5 | debug = y 6 | 7 | # Define some default flags. 8 | # NB. '-Wcast-qual' is nasty, so I omitted it. 9 | DEF_CFLAGS += -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format -Wno-redundant-decls -Wformat 10 | DEF_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) 11 | DEF_CFLAGS += $(call cc-option,$(CC),-fgnu89-inline) 12 | DEF_CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline 13 | 14 | DEF_ASFLAGS += -D__ASSEMBLY__ 15 | DEF_LDFLAGS += 16 | 17 | ifeq ($(debug),y) 18 | DEF_CFLAGS += -g 19 | #DEF_CFLAGS += -DMM_DEBUG 20 | #DEF_CFLAGS += -DFS_DEBUG 21 | #DEF_CFLAGS += -DLIBC_DEBUG 22 | #DEF_CFLAGS += -DGNT_DEBUG 23 | #DEF_CFLAGS += -DGNTMAP_DEBUG 24 | else 25 | DEF_CFLAGS += -O3 26 | endif 27 | 28 | # Make the headers define our internal stuff 29 | DEF_CFLAGS += -D__INSIDE_MINIOS__ 30 | 31 | # Build the CFLAGS and ASFLAGS for compiling and assembling. 32 | # DEF_... flags are the common mini-os flags, 33 | # ARCH_... flags may be defined in arch/$(TARGET_ARCH_FAM/rules.mk 34 | CFLAGS := $(DEF_CFLAGS) $(ARCH_CFLAGS) $(DEFINES-y) 35 | CPPFLAGS := $(DEF_CPPFLAGS) $(ARCH_CPPFLAGS) 36 | ASFLAGS := $(DEF_ASFLAGS) $(ARCH_ASFLAGS) $(DEFINES-y) 37 | LDFLAGS := $(DEF_LDFLAGS) $(ARCH_LDFLAGS) 38 | 39 | # Special build dependencies. 40 | # Rebuild all after touching this/these file(s) 41 | EXTRA_DEPS += $(MINIOS_ROOT)/minios.mk 42 | EXTRA_DEPS += $(MINIOS_ROOT)/$(TARGET_ARCH_DIR)/arch.mk 43 | 44 | # Find all header files for checking dependencies. 45 | HDRS := $(wildcard $(MINIOS_ROOT)/include/*.h) 46 | HDRS += $(wildcard $(MINIOS_ROOT)/include/xen/*.h) 47 | HDRS += $(wildcard $(ARCH_INC)/*.h) 48 | # For special wanted header directories. 49 | extra_heads := $(foreach dir,$(EXTRA_INC),$(wildcard $(dir)/*.h)) 50 | HDRS += $(extra_heads) 51 | 52 | # Add the special header directories to the include paths. 53 | override CPPFLAGS := $(CPPFLAGS) $(extra_incl) 54 | 55 | # The name of the architecture specific library. 56 | # This is on x86_32: libx86_32.a 57 | # $(ARCH_LIB) has to built in the architecture specific directory. 58 | ARCH_LIB_NAME = $(MINIOS_TARGET_ARCH) 59 | ARCH_LIB := lib$(ARCH_LIB_NAME).a 60 | 61 | # This object contains the entrypoint for startup from Xen. 62 | # $(HEAD_ARCH_OBJ) has to be built in the architecture specific directory. 63 | HEAD_ARCH_OBJ := $(MINIOS_TARGET_ARCH).o 64 | HEAD_OBJ := $(OBJ_DIR)/$(TARGET_ARCH_DIR)/$(HEAD_ARCH_OBJ) 65 | 66 | 67 | $(OBJ_DIR)/%.o: %.c $(HDRS) Makefile $(EXTRA_DEPS) 68 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 69 | 70 | $(OBJ_DIR)/%.o: %.S $(HDRS) Makefile $(EXTRA_DEPS) $(ARCH_AS_DEPS) 71 | $(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@ 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /scripts/travis-build: -------------------------------------------------------------------------------- 1 | #!/bin/bash -ex 2 | 3 | $CC --version 4 | 5 | make testbuild 6 | --------------------------------------------------------------------------------