From: Antti Kantee Date: Sun, 7 Dec 2014 17:57:55 +0000 (+0000) Subject: move "include" to "xen/include" X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c0c0f99768fa941f92cd6fd471549f4c7ff5d3cf;p=rumpuser-xen.git move "include" to "xen/include" All of mini-os is more or less under xen/ now. --- diff --git a/Config.mk b/Config.mk index 8ba9b44..21b253e 100644 --- a/Config.mk +++ b/Config.mk @@ -46,4 +46,4 @@ include $(MINI-OS_ROOT)/xen/$(TARGET_ARCH_DIR)/arch.mk extra_incl := $(foreach dir,$(EXTRA_INC),-isystem $(MINI-OS_ROOT)/include/$(dir)) -DEF_CPPFLAGS += -isystem $(MINI-OS_ROOT)/include +DEF_CPPFLAGS += -isystem $(MINI-OS_ROOT)/xen/include diff --git a/Makefile b/Makefile index ead2f7d..8005853 100644 --- a/Makefile +++ b/Makefile @@ -112,8 +112,8 @@ endif .PHONY: links links: $(ARCH_LINKS) - [ -e include/xen ] || ln -sf $(XEN_HEADERS) include/xen - [ -e include/mini-os/machine ] || ln -sf $(TARGET_ARCH_FAM) include/mini-os/machine + [ -e xen/include/xen ] || ln -sf $(XEN_HEADERS) xen/include/xen + [ -e xen/include/mini-os/machine ] || ln -sf $(TARGET_ARCH_FAM) xen/include/mini-os/machine .PHONY: arch_lib arch_lib: @@ -190,7 +190,7 @@ clean: arch_clean app-tools_clean rm -f $$dir/*.o; \ done rm -f $(OBJ_DIR)/*.o *~ $(OBJ_DIR)/core minios.o rumprun.o rump-kernel - rm -f include/xen include/mini-os/machine + rm -f xen/include/xen xen/include/mini-os/machine rm -f tags TAGS $(MAKE) -C httpd -f Makefile.boot clean $(MAKE) -C tests clean diff --git a/app-tools/specs.configure.in b/app-tools/specs.configure.in index cec70af..80aa8be 100644 --- a/app-tools/specs.configure.in +++ b/app-tools/specs.configure.in @@ -1,7 +1,7 @@ %rename cpp_options old_cpp_options *cpp_options: --nostdinc -isystem !BASE!/rump/include -isystem !BASE!/include %(old_cpp_options) !CPPFLAGS! -D__RUMPUSER_XEN__ -D__RUMPAPP__ -D__NetBSD__ +-nostdinc -isystem !BASE!/rump/include -isystem !BASE!/xen/include %(old_cpp_options) !CPPFLAGS! -D__RUMPUSER_XEN__ -D__RUMPAPP__ -D__NetBSD__ *linker: !APPTOOLS!/ld --stunt-intermediate %g.link1 --stunt-final-script !LDSCRIPT! diff --git a/app-tools/specs.in b/app-tools/specs.in index fa304e8..188166f 100644 --- a/app-tools/specs.in +++ b/app-tools/specs.in @@ -1,7 +1,7 @@ %rename cpp_options old_cpp_options *cpp_options: --nostdinc -isystem !BASE!/rump/include -isystem !BASE!/include %(old_cpp_options) !CPPFLAGS! -D__RUMPUSER_XEN__ -D__RUMPAPP__ -D__NetBSD__ +-nostdinc -isystem !BASE!/rump/include -isystem !BASE!/xen/include %(old_cpp_options) !CPPFLAGS! -D__RUMPUSER_XEN__ -D__RUMPAPP__ -D__NetBSD__ *linker: !APPTOOLS!/ld --stunt-intermediate %g.link1 --stunt-final-script !LDSCRIPT! diff --git a/include/mini-os/blkfront.h b/include/mini-os/blkfront.h deleted file mode 100644 index 18de25b..0000000 --- a/include/mini-os/blkfront.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _MINIOS_BLKFRONT_H_ -#define _MINIOS_BLKFRONT_H_ - -#include -#include -#include -struct blkfront_dev; -struct blkfront_aiocb -{ - struct blkfront_dev *aio_dev; - uint8_t *aio_buf; - size_t aio_nbytes; - off_t aio_offset; - size_t total_bytes; - uint8_t is_write; - void *data; - - grant_ref_t gref[BLKIF_MAX_SEGMENTS_PER_REQUEST]; - int n; - - void (*aio_cb)(struct blkfront_aiocb *aiocb, int ret); -}; -struct blkfront_info -{ - uint64_t sectors; - unsigned sector_size; - int mode; - int info; - int barrier; - int flush; -}; -struct blkfront_dev *blkfront_init(char *nodename, struct blkfront_info *info); -void blkfront_aio(struct blkfront_aiocb *aiocbp, int write); -#define blkfront_aio_read(aiocbp) blkfront_aio(aiocbp, 0) -#define blkfront_aio_write(aiocbp) blkfront_aio(aiocbp, 1) -void blkfront_io(struct blkfront_aiocb *aiocbp, int write); -#define blkfront_read(aiocbp) blkfront_io(aiocbp, 0) -#define blkfront_write(aiocbp) blkfront_io(aiocbp, 1) -void blkfront_aio_push_operation(struct blkfront_aiocb *aiocbp, uint8_t op); -int blkfront_aio_poll(struct blkfront_dev *dev); -void blkfront_sync(struct blkfront_dev *dev); -void blkfront_shutdown(struct blkfront_dev *dev); - -extern struct wait_queue_head blkfront_queue; - -#endif /* _MINIOS_BLKFRONT_H_ */ diff --git a/include/mini-os/console.h b/include/mini-os/console.h deleted file mode 100644 index efb633c..0000000 --- a/include/mini-os/console.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - **************************************************************************** - * (C) 2006 - Grzegorz Milos - Cambridge University - **************************************************************************** - * - * File: console.h - * Author: Grzegorz Milos - * Changes: - * - * Date: Mar 2006 - * - * Environment: Xen Minimal OS - * Description: Console interface. - * - * Handles console I/O. Defines printk. - * - **************************************************************************** - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ -#ifndef _MINIOS_LIB_CONSOLE_H_ -#define _MINIOS_LIB_CONSOLE_H_ - -#include -#include -#include - -#include - -#include -#include -#include - -struct consfront_dev { - domid_t dom; - - struct xencons_interface *ring; - grant_ref_t ring_ref; - evtchn_port_t evtchn; - - char *nodename; - char *backend; - - struct xenbus_event_queue events; - -}; - - - -void print(int direct, const char *fmt, va_list args); -void minios_printk(const char *fmt, ...); -void xprintk(const char *fmt, ...); -void panic(const char *fmt, ...); - -#define tprintk(_fmt, _args...) printk("[%s] " _fmt, current->name, ##_args) - -void xencons_rx(char *buf, unsigned len, struct pt_regs *regs); -void xencons_tx(void); - -void init_console(void); -void minios_console_print(struct consfront_dev *dev, char *data, int length); -void fini_console(struct consfront_dev *dev); - -/* Low level functions defined in xencons_ring.c */ -extern struct wait_queue_head console_queue; -struct consfront_dev *xencons_ring_init(void); -struct consfront_dev *init_consfront(char *_nodename); -int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len); -int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len); -int xencons_ring_avail(struct consfront_dev *dev); -int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len); -void free_consfront(struct consfront_dev *dev); - -#endif /* _MINIOS_LIB_CONSOLE_H_ */ diff --git a/include/mini-os/events.h b/include/mini-os/events.h deleted file mode 100644 index c4878e0..0000000 --- a/include/mini-os/events.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- - **************************************************************************** - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge - * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge - **************************************************************************** - * - * File: events.h - * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) - * Changes: Grzegorz Milos (gm281@cam.ac.uk) - * - * Date: Jul 2003, changes Jun 2005 - * - * Environment: Xen Minimal OS - * Description: Deals with events on the event channels - * - **************************************************************************** - */ - -#ifndef _MINIOS_EVENTS_H_ -#define _MINIOS_EVENTS_H_ - -#include - -typedef void (*evtchn_handler_t)(evtchn_port_t, struct pt_regs *, void *); - -/* prototypes */ -int do_event(evtchn_port_t port, struct pt_regs *regs); -evtchn_port_t minios_bind_virq(uint32_t virq, evtchn_handler_t handler, void *data); -evtchn_port_t minios_bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t handler, void *data); -evtchn_port_t minios_bind_evtchn(evtchn_port_t port, evtchn_handler_t handler, - void *data); -void minios_unbind_evtchn(evtchn_port_t port); -void init_events(void); -int minios_evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler, - void *data, evtchn_port_t *port); -int minios_evtchn_bind_interdomain(domid_t pal, evtchn_port_t remote_port, - evtchn_handler_t handler, void *data, - evtchn_port_t *local_port); -void unbind_all_ports(void); - -static inline int notify_remote_via_evtchn(evtchn_port_t port) -{ - evtchn_send_t op; - op.port = port; - return HYPERVISOR_event_channel_op(EVTCHNOP_send, &op); -} - -void fini_events(void); - -#endif /* _MINIOS_EVENTS_H_ */ diff --git a/include/mini-os/fbfront.h b/include/mini-os/fbfront.h deleted file mode 100644 index ab3107d..0000000 --- a/include/mini-os/fbfront.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _MINIOS_FBFRONT_H_ -#define _MINIOS_FBFRONT_H_ - -#include -#include -#include -#include - -/* from */ -#ifndef BTN_LEFT -#define BTN_LEFT 0x110 -#endif -#ifndef BTN_RIGHT -#define BTN_RIGHT 0x111 -#endif -#ifndef BTN_MIDDLE -#define BTN_MIDDLE 0x112 -#endif -#ifndef KEY_Q -#define KEY_Q 16 -#endif -#ifndef KEY_MAX -#define KEY_MAX 0x1ff -#endif - - -struct kbdfront_dev; -struct kbdfront_dev *init_kbdfront(char *nodename, int abs_pointer); - -int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n); -extern struct wait_queue_head kbdfront_queue; - -void shutdown_kbdfront(struct kbdfront_dev *dev); - - -struct fbfront_dev *init_fbfront(char *nodename, unsigned long *mfns, int width, int height, int depth, int stride, int n); - -int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n); -extern struct wait_queue_head fbfront_queue; -void fbfront_update(struct fbfront_dev *dev, int x, int y, int width, int height); -void fbfront_resize(struct fbfront_dev *dev, int width, int height, int stride, int depth, int offset); - -void shutdown_fbfront(struct fbfront_dev *dev); - -#endif /* _MINIOS_FBFRONT_H_ */ diff --git a/include/mini-os/gntmap.h b/include/mini-os/gntmap.h deleted file mode 100644 index dfcd77e..0000000 --- a/include/mini-os/gntmap.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __MINIOS_GNTMAP_H__ -#define __MINIOS_GNTMAP_H__ - -#include - -/* - * Please consider struct gntmap opaque. If instead you choose to disregard - * this message, I insist that you keep an eye out for raptors. - */ -struct gntmap { - int nentries; - struct gntmap_entry *entries; -}; - -int -gntmap_set_max_grants(struct gntmap *map, int count); - -int -gntmap_munmap(struct gntmap *map, unsigned long start_address, int count); - -void* -gntmap_map_grant_refs(struct gntmap *map, - uint32_t count, - uint32_t *domids, - int domids_stride, - uint32_t *refs, - int writable); - -void -gntmap_init(struct gntmap *map); - -void -gntmap_fini(struct gntmap *map); - -#endif /* !__MINIOS_GNTMAP_H__ */ diff --git a/include/mini-os/gnttab.h b/include/mini-os/gnttab.h deleted file mode 100644 index bc594be..0000000 --- a/include/mini-os/gnttab.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __MINIOS_GNTTAB_H__ -#define __MINIOS_GNTTAB_H__ - -#include - -void init_gnttab(void); -grant_ref_t gnttab_alloc_and_grant(void **map); -grant_ref_t gnttab_grant_access(domid_t domid, unsigned long frame, - int readonly); -grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn); -unsigned long gnttab_end_transfer(grant_ref_t gref); -int gnttab_end_access(grant_ref_t ref); -const char *gnttabop_error(int16_t status); -void fini_gnttab(void); - -#endif /* !__MINIOS_GNTTAB_H__ */ diff --git a/include/mini-os/hypervisor.h b/include/mini-os/hypervisor.h deleted file mode 100644 index 6c70db8..0000000 --- a/include/mini-os/hypervisor.h +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * hypervisor.h - * - * Hypervisor handling. - * - * - * Copyright (c) 2002, K A Fraser - * Copyright (c) 2005, Grzegorz Milos - * Updates: Aravindh Puthiyaparambil - * Updates: Dietmar Hahn for ia64 - */ - -#ifndef _MINIOS_HYPERVISOR_H_ -#define _MINIOS_HYPERVISOR_H_ - -#include -#include -#if defined(__i386__) -#include -#elif defined(__x86_64__) -#include -#else -#error "Unsupported architecture" -#endif -#include - -/* - * a placeholder for the start of day information passed up from the hypervisor - */ -union start_info_union -{ - start_info_t start_info; - char padding[512]; -}; -extern union start_info_union _minios_start_info_union; -#define start_info (_minios_start_info_union.start_info) - -/* hypervisor.c */ -void minios_force_evtchn_callback(void); -void minios_do_hypervisor_callback(struct pt_regs *regs); -void minios_mask_evtchn(uint32_t port); -void minios_unmask_evtchn(uint32_t port); -void minios_clear_evtchn(uint32_t port); - -extern int _minios_in_hypervisor_callback; - -#endif /* __MINIOS_HYPERVISOR_H__ */ diff --git a/include/mini-os/ioremap.h b/include/mini-os/ioremap.h deleted file mode 100644 index a9b08f4..0000000 --- a/include/mini-os/ioremap.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (C) 2009 Netronome Systems, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - - -#ifndef _MINIOS_IOREMAP_H_ -#define _MINIOS_IOREMAP_H_ - -void *ioremap(unsigned long phys_addr, unsigned long size); -void *ioremap_nocache(unsigned long phys_addr, unsigned long size); -void iounmap(void *virt_addr, unsigned long size); - -#endif /* _MINIOS_IOREMAP_H_ */ - -/* -*- Mode:C; c-basic-offset:4; tab-width:4 indent-tabs-mode:nil -*- */ diff --git a/include/mini-os/kernel.h b/include/mini-os/kernel.h deleted file mode 100644 index 2fce906..0000000 --- a/include/mini-os/kernel.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _MINIOS_KERNEL_H_ -#define _MINIOS_KERNEL_H_ - -extern int app_main(start_info_t *); - -extern void minios_do_exit(void) __attribute__((noreturn)); -extern void minios_stop_kernel(void); - -/* Values should mirror SHUTDOWN_* in xen/sched.h */ -#define MINIOS_HALT_POWEROFF 0 -#define MINIOS_HALT_CRASH 3 -extern void minios_do_halt(int reason) __attribute__((noreturn)); - -#endif /* _MINIOS_KERNEL_H_ */ diff --git a/include/mini-os/lib.h b/include/mini-os/lib.h deleted file mode 100644 index 304cb84..0000000 --- a/include/mini-os/lib.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- - **************************************************************************** - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge - **************************************************************************** - * - * File: lib.h - * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) - * Changes: - * - * Date: Aug 2003 - * - * Environment: Xen Minimal OS - * Description: Random useful library functions, contains some freebsd stuff - * - **************************************************************************** - * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $ - **************************************************************************** - * - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#ifndef _MINIOS_LIB_H_ -#define _MINIOS_LIB_H_ - -#include -#include -#include "gntmap.h" - -#include - -#define RAND_MIX 2654435769U - -int rand(void); - -#include - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) - -#define ASSERT(x) \ -do { \ - if (!(x)) { \ - minios_printk("ASSERTION FAILED: %s at %s:%d.\n", \ - # x , \ - __FILE__, \ - __LINE__); \ - BUG(); \ - } \ -} while(0) - -#define BUG_ON(x) ASSERT(!(x)) - -/* Consistency check as much as possible. */ -void sanity_check(void); - - -#endif /* _MINIOS_LIB_H_ */ diff --git a/include/mini-os/mm.h b/include/mini-os/mm.h deleted file mode 100644 index 148ea3c..0000000 --- a/include/mini-os/mm.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- - * - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge - * Copyright (c) 2005, Keir A Fraser - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef _MINIOS_MM_H_ -#define _MINIOS_MM_H_ - -#if defined(__i386__) -#include -#elif defined(__x86_64__) -#include -#elif defined(__ia64__) -#include -#else -#error "Unsupported architecture" -#endif - -#include - -#include -#include - -#define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER -#define STACK_SIZE __STACK_SIZE - - -void init_mm(void); -unsigned long minios_alloc_pages(int order); -#define minios_alloc_page() minios_alloc_pages(0) -void minios_free_pages(void *pointer, int order); -#define minios_free_page(p) minios_free_pages(p, 0) - -static __inline__ int get_order(unsigned long size) -{ - int order; - size = (size-1) >> PAGE_SHIFT; - for ( order = 0; size; order++ ) - size >>= 1; - return order; -} - -void arch_init_demand_mapping_area(unsigned long max_pfn); -void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p); -void arch_init_p2m(unsigned long max_pfn_p); - -unsigned long allocate_ondemand(unsigned long n, unsigned long alignment); -/* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */ -void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride, - unsigned long increment, unsigned long alignment, domid_t id, - int *err, unsigned long prot); -void do_map_frames(unsigned long addr, - const unsigned long *f, unsigned long n, unsigned long stride, - unsigned long increment, domid_t id, int *err, unsigned long prot); -int unmap_frames(unsigned long va, unsigned long num_frames); -unsigned long alloc_contig_pages(int order, unsigned int addr_bits); - -int free_physical_pages(xen_pfn_t *mfns, int n); -void fini_mm(void); -uint64_t minios_get_memsize(void); - -#endif /* _MINIOS_MM_H_ */ diff --git a/include/mini-os/netfront.h b/include/mini-os/netfront.h deleted file mode 100644 index 24bdbe8..0000000 --- a/include/mini-os/netfront.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _MINIOS_NETFRONT_H_ -#define _MINIOS_NETFRONT_H_ - -#include -struct netfront_dev; -struct netfront_dev *netfront_init(char *nodename, void (*netif_rx)(struct netfront_dev *, unsigned char *data, int len), unsigned char rawmac[6], char **ip, void *priv); -void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len); -void netfront_shutdown(struct netfront_dev *dev); - -void *netfront_get_private(struct netfront_dev *); - -extern struct wait_queue_head netfront_queue; - -#endif /* _MINIOS_NETFRONT_H_ */ diff --git a/include/mini-os/os.h b/include/mini-os/os.h deleted file mode 100644 index c5541f5..0000000 --- a/include/mini-os/os.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _MINIOS_OS_H_ -#define _MINIOS_OS_H_ - -#define smp_processor_id() 0 -#define unlikely(x) __builtin_expect((x),0) -#define likely(x) __builtin_expect((x),1) - -#include - -#ifndef __RUMP_KERNEL__ - -#if __GNUC__ == 2 && __GNUC_MINOR__ < 96 -#define __builtin_expect(x, expected_value) (x) -#endif - -#ifndef __ASSEMBLY__ -#include -#include -#endif - -#define USED __attribute__ ((used)) - -#define BUG minios_do_exit - -#include - -#endif /* !__RUMP_KERNEL__ */ - -#endif /* _MINIOS_OS_H_ */ diff --git a/include/mini-os/pcifront.h b/include/mini-os/pcifront.h deleted file mode 100644 index ce7344d..0000000 --- a/include/mini-os/pcifront.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _MINIOS_PCIFRONT_H_ -#define _MINIOS_PCIFRONT_H_ - -#include -#include -struct pcifront_dev; -void pcifront_watches(void *opaque); -struct pcifront_dev *init_pcifront(char *nodename); -void pcifront_op(struct pcifront_dev *dev, struct xen_pci_op *op); -void pcifront_scan(struct pcifront_dev *dev, void (*fun)(unsigned int domain, unsigned int bus, unsigned slot, unsigned int fun)); -int pcifront_conf_read(struct pcifront_dev *dev, - unsigned int dom, - unsigned int bus, unsigned int slot, unsigned long fun, - unsigned int off, unsigned int size, unsigned int *val); -int pcifront_conf_write(struct pcifront_dev *dev, - unsigned int dom, - unsigned int bus, unsigned int slot, unsigned long fun, - unsigned int off, unsigned int size, unsigned int val); -int pcifront_enable_msi(struct pcifront_dev *dev, - unsigned int dom, - unsigned int bus, unsigned int slot, unsigned long fun); -int pcifront_disable_msi(struct pcifront_dev *dev, - unsigned int dom, - unsigned int bus, unsigned int slot, unsigned long fun); -int pcifront_enable_msix(struct pcifront_dev *dev, - unsigned int dom, - unsigned int bus, unsigned int slot, unsigned long fun, - struct xen_msix_entry *entries, int n); -int pcifront_disable_msix(struct pcifront_dev *dev, - unsigned int dom, - unsigned int bus, unsigned int slot, unsigned long fun); -void shutdown_pcifront(struct pcifront_dev *dev); - -#endif /* _MINIOS_PCIFRONT_H_ */ diff --git a/include/mini-os/queue.h b/include/mini-os/queue.h deleted file mode 100644 index bdf52af..0000000 --- a/include/mini-os/queue.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef MINIOS_QUEUE_H__ -#define MINIOS_QUEUE_H__ - -#include - -#define MINIOS_SLIST_EMPTY SLIST_EMPTY -#define MINIOS_SLIST_ENTRY SLIST_ENTRY -#define MINIOS_SLIST_FIRST SLIST_FIRST -#define MINIOS_SLIST_FOREACH SLIST_FOREACH -#define MINIOS_SLIST_FOREACH_SAFE SLIST_FOREACH_SAFE -#define MINIOS_SLIST_HEAD SLIST_HEAD -#define MINIOS_SLIST_HEAD_INITIALIZER SLIST_HEAD_INITIALIZER -#define MINIOS_SLIST_INIT SLIST_INIT -#define MINIOS_SLIST_INSERT_AFTER SLIST_INSERT_AFTER -#define MINIOS_SLIST_INSERT_HEAD SLIST_INSERT_HEAD -#define MINIOS_SLIST_NEXT SLIST_NEXT -#define MINIOS_SLIST_REMOVE_AFTER SLIST_REMOVE_AFTER -#define MINIOS_SLIST_REMOVE_HEAD SLIST_REMOVE_HEAD -#define MINIOS_SLIST_REMOVE SLIST_REMOVE -#define MINIOS_SLIST_SWAP SLIST_SWAP -#define MINIOS_STAILQ_CONCAT STAILQ_CONCAT -#define MINIOS_STAILQ_EMPTY STAILQ_EMPTY -#define MINIOS_STAILQ_ENTRY STAILQ_ENTRY -#define MINIOS_STAILQ_FIRST STAILQ_FIRST -#define MINIOS_STAILQ_FOREACH STAILQ_FOREACH -#define MINIOS_STAILQ_FOREACH_SAFE STAILQ_FOREACH_SAFE -#define MINIOS_STAILQ_HEAD STAILQ_HEAD -#define MINIOS_STAILQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER -#define MINIOS_STAILQ_INIT STAILQ_INIT -#define MINIOS_STAILQ_INSERT_AFTER STAILQ_INSERT_AFTER -#define MINIOS_STAILQ_INSERT_HEAD STAILQ_INSERT_HEAD -#define MINIOS_STAILQ_INSERT_TAIL STAILQ_INSERT_TAIL -#define MINIOS_STAILQ_LAST STAILQ_LAST -#define MINIOS_STAILQ_NEXT STAILQ_NEXT -#define MINIOS_STAILQ_REMOVE_AFTER STAILQ_REMOVE_AFTER -#define MINIOS_STAILQ_REMOVE_HEAD STAILQ_REMOVE_HEAD -#define MINIOS_STAILQ_REMOVE STAILQ_REMOVE -#define MINIOS_STAILQ_SWAP STAILQ_SWAP -#define MINIOS_LIST_EMPTY LIST_EMPTY -#define MINIOS_LIST_ENTRY LIST_ENTRY -#define MINIOS_LIST_FIRST LIST_FIRST -#define MINIOS_LIST_FOREACH LIST_FOREACH -#define MINIOS_LIST_FOREACH_SAFE LIST_FOREACH_SAFE -#define MINIOS_LIST_HEAD LIST_HEAD -#define MINIOS_LIST_HEAD_INITIALIZER LIST_HEAD_INITIALIZER -#define MINIOS_LIST_INIT LIST_INIT -#define MINIOS_LIST_INSERT_AFTER LIST_INSERT_AFTER -#define MINIOS_LIST_INSERT_BEFORE LIST_INSERT_BEFORE -#define MINIOS_LIST_INSERT_HEAD LIST_INSERT_HEAD -#define MINIOS_LIST_NEXT LIST_NEXT -#define MINIOS_LIST_REMOVE LIST_REMOVE -#define MINIOS_LIST_SWAP LIST_SWAP -#define MINIOS_TAILQ_CONCAT TAILQ_CONCAT -#define MINIOS_TAILQ_EMPTY TAILQ_EMPTY -#define MINIOS_TAILQ_ENTRY TAILQ_ENTRY -#define MINIOS_TAILQ_FIRST TAILQ_FIRST -#define MINIOS_TAILQ_FOREACH TAILQ_FOREACH -#define MINIOS_TAILQ_FOREACH_SAFE TAILQ_FOREACH_SAFE -#define MINIOS_TAILQ_FOREACH_REVERSE TAILQ_FOREACH_REVERSE -#define MINIOS_TAILQ_FOREACH_REVERSE_SAFE TAILQ_FOREACH_REVERSE_SAFE -#define MINIOS_TAILQ_HEAD TAILQ_HEAD -#define MINIOS_TAILQ_HEAD_INITIALIZER TAILQ_HEAD_INITIALIZER -#define MINIOS_TAILQ_INIT TAILQ_INIT -#define MINIOS_TAILQ_INSERT_AFTER TAILQ_INSERT_AFTER -#define MINIOS_TAILQ_INSERT_BEFORE TAILQ_INSERT_BEFORE -#define MINIOS_TAILQ_INSERT_HEAD TAILQ_INSERT_HEAD -#define MINIOS_TAILQ_INSERT_TAIL TAILQ_INSERT_TAIL -#define MINIOS_TAILQ_LAST TAILQ_LAST -#define MINIOS_TAILQ_NEXT TAILQ_NEXT -#define MINIOS_TAILQ_PREV TAILQ_PREV -#define MINIOS_TAILQ_REMOVE TAILQ_REMOVE -#define MINIOS_TAILQ_SWAP TAILQ_SWAP - -#endif /* MINIOS_QUEUE_H__ */ diff --git a/include/mini-os/sched.h b/include/mini-os/sched.h deleted file mode 100644 index 3038364..0000000 --- a/include/mini-os/sched.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __MINIOS_SCHED_H__ -#define __MINIOS_SCHED_H__ - -#include -#include - -#include - -struct thread { - const char *name; - char *stack; - size_t stack_size; - struct thread_md md; - TAILQ_ENTRY(thread) thread_list; - uint32_t flags; - s_time_t wakeup_time; - int threrrno; - void *lwp; - void *cookie; -}; - -extern struct thread *idle_thread; -void idle_thread_fn(void *unused); - -#define RUNNABLE_FLAG 0x00000001 -#define THREAD_MUSTJOIN 0x00000002 -#define THREAD_JOINED 0x00000004 -#define THREAD_EXTSTACK 0x00000008 -#define THREAD_TIMEDOUT 0x00000010 - -#define is_runnable(_thread) (_thread->flags & RUNNABLE_FLAG) -#define set_runnable(_thread) (_thread->flags |= RUNNABLE_FLAG) -#define clear_runnable(_thread) (_thread->flags &= ~RUNNABLE_FLAG) - -void switch_threads(struct thread *prev, struct thread *next); - - /* Architecture specific setup of thread creation. */ -struct thread* arch_create_thread(const char *name, void (*function)(void *), - void *data, void *stack); - -void init_sched(void); -void run_idle_thread(void); -struct thread* minios_create_thread(const char *name, void *cookie, - void (*f)(void *), void *data, void *stack); -void minios_exit_thread(void) __attribute__((noreturn)); -void minios_join_thread(struct thread *); -void minios_set_sched_hook(void (*hook)(void *, void *)); -struct thread *minios_init_mainlwp(void *cookie); -void minios_schedule(void); - -#define current get_current() - -void minios_wake(struct thread *thread); -void minios_block(struct thread *thread); -int minios_msleep(uint32_t millisecs); -int minios_absmsleep(uint32_t millisecs); - -#endif /* __MINIOS_SCHED_H__ */ diff --git a/include/mini-os/semaphore.h b/include/mini-os/semaphore.h deleted file mode 100644 index 9f2a37a..0000000 --- a/include/mini-os/semaphore.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef _MINIOS_SEMAPHORE_H_ -#define _MINIOS_SEMAPHORE_H_ - -#include -#include - -/* - * Implementation of semaphore in Mini-os is simple, because - * there are no preemptive threads, the atomicity is guaranteed. - */ - -struct semaphore -{ - int count; - struct wait_queue_head wait; -}; - -/* - * the semaphore definition - */ -struct rw_semaphore { - signed long count; - spinlock_t wait_lock; - int debug; -}; - -#define __SEMAPHORE_INITIALIZER(name, n) \ -{ \ - .count = n, \ - .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \ -} - -#define __MUTEX_INITIALIZER(name) \ - __SEMAPHORE_INITIALIZER(name,1) - -#define __DECLARE_SEMAPHORE_GENERIC(name,count) \ - struct semaphore name = __SEMAPHORE_INITIALIZER(name,count) - -#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) - -#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0) - -static inline void init_SEMAPHORE(struct semaphore *sem, int count) -{ - sem->count = count; - minios_init_waitqueue_head(&sem->wait); -} - -#define init_MUTEX(sem) init_SEMAPHORE(sem, 1) - -static inline int trydown(struct semaphore *sem) -{ - unsigned long flags; - int ret = 0; - local_irq_save(flags); - if (sem->count > 0) { - ret = 1; - sem->count--; - } - local_irq_restore(flags); - return ret; -} - -static void inline down(struct semaphore *sem) -{ - unsigned long flags; - while (1) { - minios_wait_event(sem->wait, sem->count > 0); - local_irq_save(flags); - if (sem->count > 0) - break; - local_irq_restore(flags); - } - sem->count--; - local_irq_restore(flags); -} - -static void inline up(struct semaphore *sem) -{ - unsigned long flags; - local_irq_save(flags); - sem->count++; - minios_wake_up(&sem->wait); - local_irq_restore(flags); -} - -/* FIXME! Thre read/write semaphores are unimplemented! */ -static inline void init_rwsem(struct rw_semaphore *sem) -{ - sem->count = 1; -} - -static inline void down_read(struct rw_semaphore *sem) -{ -} - - -static inline void up_read(struct rw_semaphore *sem) -{ -} - -static inline void up_write(struct rw_semaphore *sem) -{ -} - -static inline void down_write(struct rw_semaphore *sem) -{ -} - -#endif /* _MINIOS_SEMAPHORE_H */ diff --git a/include/mini-os/spinlock.h b/include/mini-os/spinlock.h deleted file mode 100644 index b87ffe5..0000000 --- a/include/mini-os/spinlock.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __MINIOS_ASM_SPINLOCK_H -#define __MINIOS_ASM_SPINLOCK_H - -#ifndef __RUMP_KERNEL__ -#include -#endif - -/* - * Your basic SMP spinlocks, allowing only a single CPU anywhere - */ - -typedef struct { - volatile unsigned int slock; -} spinlock_t; - - -#include - - -#define SPINLOCK_MAGIC 0xdead4ead - -#define SPIN_LOCK_UNLOCKED ARCH_SPIN_LOCK_UNLOCKED - -#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0) - -/* - * Simple spin lock operations. There are two variants, one clears IRQ's - * on the local processor, one does not. - * - * We make no fairness assumptions. They have a cost. - */ - -#define spin_is_locked(x) arch_spin_is_locked(x) - -#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) - - -#define _spin_trylock(lock) ({_raw_spin_trylock(lock) ? \ - 1 : ({ 0;});}) - -#define _spin_lock(lock) \ -do { \ - _raw_spin_lock(lock); \ -} while(0) - -#define _spin_unlock(lock) \ -do { \ - _raw_spin_unlock(lock); \ -} while (0) - - -#define spin_lock(lock) _spin_lock(lock) -#define spin_unlock(lock) _spin_unlock(lock) - -#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED - -#endif diff --git a/include/mini-os/time.h b/include/mini-os/time.h deleted file mode 100644 index 00c90dc..0000000 --- a/include/mini-os/time.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- - **************************************************************************** - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge - * (C) 2005 - Grzegorz Milos - Intel Research Cambridge - **************************************************************************** - * - * File: time.h - * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) - * Changes: Grzegorz Milos (gm281@cam.ac.uk) - * Robert Kaiser (kaiser@informatik.fh-wiesbaden.de) - * - * Date: Jul 2003, changes: Jun 2005, Sep 2006 - * - * Environment: Xen Minimal OS - * Description: Time and timer functions - * - **************************************************************************** - */ - -#ifndef _MINIOS_TIME_H_ -#define _MINIOS_TIME_H_ -#include - -/* - * System Time - * 64 bit value containing the nanoseconds elapsed since boot time. - * This value is adjusted by frequency drift. - * NOW() returns the current time. - * The other macros are for convenience to approximate short intervals - * of real time into system time - */ -typedef int64_t s_time_t; -#define NOW() ((s_time_t)monotonic_clock()) -#define SECONDS(_s) (((s_time_t)(_s)) * 1000000000UL ) -#define TENTHS(_ts) (((s_time_t)(_ts)) * 100000000UL ) -#define HUNDREDTHS(_hs) (((s_time_t)(_hs)) * 10000000UL ) -#define MILLISECS(_ms) (((s_time_t)(_ms)) * 1000000UL ) -#define MICROSECS(_us) (((s_time_t)(_us)) * 1000UL ) -#define Time_Max ((s_time_t) 0x7fffffffffffffffLL) -#define FOREVER Time_Max -#define NSEC_TO_USEC(_nsec) ((_nsec) / 1000UL) -#define NSEC_TO_MSEC(_nsec) ((_nsec) / 1000000ULL) -#define NSEC_TO_SEC(_nsec) ((_nsec) / 1000000000ULL) - -#include - - -/* prototypes */ -void init_time(void); -void fini_time(void); -s_time_t get_s_time(void); -s_time_t get_v_time(void); -uint64_t monotonic_clock(void); -void block_domain(s_time_t until); - -#endif /* _MINIOS_TIME_H_ */ diff --git a/include/mini-os/types.h b/include/mini-os/types.h deleted file mode 100644 index 09b36df..0000000 --- a/include/mini-os/types.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- - **************************************************************************** - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge - **************************************************************************** - * - * File: types.h - * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) - * Changes: - * - * Date: May 2003 - * - * Environment: Xen Minimal OS - * Description: a random collection of type definitions - * - **************************************************************************** - * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $ - **************************************************************************** - */ - -#ifndef _MINIOS_TYPES_H_ -#define _MINIOS_TYPES_H_ - -#include -#include -#include - -#ifdef __i386__ -typedef struct { unsigned long pte_low, pte_high; } pte_t; - -#elif defined(__x86_64__) || defined(__ia64__) - -typedef struct { unsigned long pte; } pte_t; -#endif /* __i386__ || __x86_64__ */ - -#ifdef __x86_64__ -#define __pte(x) ((pte_t) { (x) } ) -#else -#define __pte(x) ({ unsigned long long _x = (x); \ - ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) -#endif - -#endif /* _MINIOS_TYPES_H_ */ diff --git a/include/mini-os/wait.h b/include/mini-os/wait.h deleted file mode 100644 index aa1837a..0000000 --- a/include/mini-os/wait.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef __MINIOS_WAIT_H__ -#define __MINIOS_WAIT_H__ - -#include -#include -#include - -#include - -#define DEFINE_WAIT(name) \ -struct wait_queue name = { \ - .thread = get_current(), \ - .waiting = 0, \ -} - - -static inline void minios_init_waitqueue_head(struct wait_queue_head *h) -{ - STAILQ_INIT(h); -} - -static inline void minios_init_waitqueue_entry(struct wait_queue *q, struct thread *thread) -{ - q->thread = thread; - q->waiting = 0; -} - -static inline void minios_add_wait_queue(struct wait_queue_head *h, struct wait_queue *q) -{ - if (!q->waiting) { - STAILQ_INSERT_HEAD(h, q, thread_list); - q->waiting = 1; - } -} - -static inline void minios_remove_wait_queue(struct wait_queue_head *h, struct wait_queue *q) -{ - if (q->waiting) { - STAILQ_REMOVE(h, q, wait_queue, thread_list); - q->waiting = 0; - } -} - -static inline void minios_wake_up(struct wait_queue_head *head) -{ - unsigned long flags; - struct wait_queue *curr, *tmp; - local_irq_save(flags); - STAILQ_FOREACH_SAFE(curr, head, thread_list, tmp) - minios_wake(curr->thread); - local_irq_restore(flags); -} - -#define minios_add_waiter(w, wq) do { \ - unsigned long flags; \ - local_irq_save(flags); \ - minios_add_wait_queue(&wq, &w); \ - minios_block(get_current()); \ - local_irq_restore(flags); \ -} while (0) - -#define minios_remove_waiter(w, wq) do { \ - unsigned long flags; \ - local_irq_save(flags); \ - minios_remove_wait_queue(&wq, &w); \ - local_irq_restore(flags); \ -} while (0) - -#define minios_wait_event_deadline(wq, condition, deadline) do { \ - unsigned long flags; \ - DEFINE_WAIT(__wait); \ - if(condition) \ - break; \ - for(;;) \ - { \ - /* protect the list */ \ - local_irq_save(flags); \ - minios_add_wait_queue(&wq, &__wait); \ - get_current()->wakeup_time = deadline; \ - clear_runnable(get_current()); \ - local_irq_restore(flags); \ - if((condition) || (deadline && NOW() >= deadline)) \ - break; \ - minios_schedule(); \ - } \ - local_irq_save(flags); \ - /* need to wake up */ \ - minios_wake(get_current()); \ - minios_remove_wait_queue(&wq, &__wait); \ - local_irq_restore(flags); \ -} while(0) - -#define minios_wait_event(wq, condition) minios_wait_event_deadline(wq, condition, 0) - - - -#endif /* __MINIOS_WAIT_H__ */ - -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/mini-os/waittypes.h b/include/mini-os/waittypes.h deleted file mode 100644 index f433ca4..0000000 --- a/include/mini-os/waittypes.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __MINIOS_WAITTYPE_H__ -#define __MINIOS_WAITTYPE_H__ - -#include - -struct thread; -struct wait_queue -{ - int waiting; - struct thread *thread; - STAILQ_ENTRY(wait_queue) thread_list; -}; - -/* TODO - lock required? */ -STAILQ_HEAD(wait_queue_head, wait_queue); - -#define DECLARE_WAIT_QUEUE_HEAD(name) \ - struct wait_queue_head name = STAILQ_HEAD_INITIALIZER(name) - -#define __WAIT_QUEUE_HEAD_INITIALIZER(name) STAILQ_HEAD_INITIALIZER(name) - -#endif - -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/mini-os/x86/limits.h b/include/mini-os/x86/limits.h deleted file mode 100644 index 41f8620..0000000 --- a/include/mini-os/x86/limits.h +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef __ARCH_LIMITS_H__ -#define __ARCH_LIMITS_H__ - -#define __PAGE_SHIFT 12 - -#ifdef __ASSEMBLY__ -#define __PAGE_SIZE (1 << __PAGE_SHIFT) -#else -#ifdef __x86_64__ -#define __PAGE_SIZE (1UL << __PAGE_SHIFT) -#else -#define __PAGE_SIZE (1ULL << __PAGE_SHIFT) -#endif -#endif - -#define __STACK_SIZE_PAGE_ORDER 4 -#define __STACK_SIZE (__PAGE_SIZE * (1 << __STACK_SIZE_PAGE_ORDER)) - -#endif /* __ARCH_LIMITS_H__ */ diff --git a/include/mini-os/x86/mm.h b/include/mini-os/x86/mm.h deleted file mode 100644 index 0b5d308..0000000 --- a/include/mini-os/x86/mm.h +++ /dev/null @@ -1,238 +0,0 @@ -/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- - * - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge - * Copyright (c) 2005, Keir A Fraser - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef _ARCH_MM_H_ -#define _ARCH_MM_H_ - -#ifndef __ASSEMBLY__ -#include -#if defined(__i386__) -#include -#elif defined(__x86_64__) -#include -#else -#error "Unsupported architecture" -#endif -#endif - -#ifndef __RUMP_KERNEL__ - -#define L1_FRAME 1 -#define L2_FRAME 2 -#define L3_FRAME 3 - -#define L1_PAGETABLE_SHIFT 12 - -#if defined(__i386__) - -#define L2_PAGETABLE_SHIFT 21 -#define L3_PAGETABLE_SHIFT 30 - -#define L1_PAGETABLE_ENTRIES 512 -#define L2_PAGETABLE_ENTRIES 512 -#define L3_PAGETABLE_ENTRIES 4 - -#define PADDR_BITS 44 -#define PADDR_MASK ((1ULL << PADDR_BITS)-1) - -#define L2_MASK ((1UL << L3_PAGETABLE_SHIFT) - 1) - -/* - * If starting from virtual address greater than 0xc0000000, - * this value will be 2 to account for final mid-level page - * directory which is always mapped in at this location. - */ -#define NOT_L1_FRAMES 3 -#define PRIpte "016llx" -#ifndef __ASSEMBLY__ -typedef uint64_t pgentry_t; -#endif - -#elif defined(__x86_64__) - -#define L2_PAGETABLE_SHIFT 21 -#define L3_PAGETABLE_SHIFT 30 -#define L4_PAGETABLE_SHIFT 39 - -#define L1_PAGETABLE_ENTRIES 512 -#define L2_PAGETABLE_ENTRIES 512 -#define L3_PAGETABLE_ENTRIES 512 -#define L4_PAGETABLE_ENTRIES 512 - -/* These are page-table limitations. Current CPUs support only 40-bit phys. */ -#define PADDR_BITS 52 -#define VADDR_BITS 48 -#define PADDR_MASK ((1UL << PADDR_BITS)-1) -#define VADDR_MASK ((1UL << VADDR_BITS)-1) - -#define L2_MASK ((1UL << L3_PAGETABLE_SHIFT) - 1) -#define L3_MASK ((1UL << L4_PAGETABLE_SHIFT) - 1) - -#define NOT_L1_FRAMES 3 -#define PRIpte "016lx" -#ifndef __ASSEMBLY__ -typedef unsigned long pgentry_t; -#endif - -#endif - -#define L1_MASK ((1UL << L2_PAGETABLE_SHIFT) - 1) - -/* Given a virtual address, get an entry offset into a page table. */ -#define l1_table_offset(_a) \ - (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1)) -#define l2_table_offset(_a) \ - (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1)) -#define l3_table_offset(_a) \ - (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1)) -#if defined(__x86_64__) -#define l4_table_offset(_a) \ - (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1)) -#endif - -#define _PAGE_PRESENT 0x001ULL -#define _PAGE_RW 0x002ULL -#define _PAGE_USER 0x004ULL -#define _PAGE_PWT 0x008ULL -#define _PAGE_PCD 0x010ULL -#define _PAGE_ACCESSED 0x020ULL -#define _PAGE_DIRTY 0x040ULL -#define _PAGE_PAT 0x080ULL -#define _PAGE_PSE 0x080ULL -#define _PAGE_GLOBAL 0x100ULL - -#if defined(__i386__) -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) -#define L1_PROT_RO (_PAGE_PRESENT|_PAGE_ACCESSED) -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY |_PAGE_USER) -#define L3_PROT (_PAGE_PRESENT) -#elif defined(__x86_64__) -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER) -#define L1_PROT_RO (_PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_USER) -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) -#define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) -#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) -#endif /* __i386__ || __x86_64__ */ - -/* flags for ioremap */ -#define IO_PROT (L1_PROT) -#define IO_PROT_NOCACHE (L1_PROT | _PAGE_PCD) - -/* for P2M */ -#define INVALID_P2M_ENTRY (~0UL) - -#include -#define PAGE_SIZE __PAGE_SIZE -#define PAGE_SHIFT __PAGE_SHIFT -#define PAGE_MASK (~(PAGE_SIZE-1)) - -#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> L1_PAGETABLE_SHIFT) -#define PFN_DOWN(x) ((x) >> L1_PAGETABLE_SHIFT) -#define PFN_PHYS(x) ((uint64_t)(x) << L1_PAGETABLE_SHIFT) -#define PHYS_PFN(x) ((x) >> L1_PAGETABLE_SHIFT) - -/* to align the pointer to the (next) page boundary */ -#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) - -#ifndef __ASSEMBLY__ -/* Definitions for machine and pseudophysical addresses. */ -#ifdef __i386__ -typedef unsigned long long paddr_t; -typedef unsigned long long maddr_t; -#else -typedef unsigned long paddr_t; -typedef unsigned long maddr_t; -#endif - -extern unsigned long *_minios_phys_to_machine_mapping; -extern char _text, _etext, _erodata, _edata, _end; -extern unsigned long _minios_mfn_zero; -#define pfn_to_mfn(_pfn) (_minios_phys_to_machine_mapping[(_pfn)]) -static __inline__ maddr_t phys_to_machine(paddr_t phys) -{ - maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT); - machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK); - return machine; -} - -#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)]) -static __inline__ paddr_t machine_to_phys(maddr_t machine) -{ - paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT); - phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK); - return phys; -} -#endif - -#define VIRT_START ((unsigned long)&_text) - -#define to_phys(x) ((unsigned long)(x)-VIRT_START) -#define to_virt(x) ((void *)((unsigned long)(x)+VIRT_START)) - -#define virt_to_pfn(_virt) (PFN_DOWN(to_phys(_virt))) -#define virt_to_mfn(_virt) (pfn_to_mfn(virt_to_pfn(_virt))) -#define mach_to_virt(_mach) (to_virt(machine_to_phys(_mach))) -#define virt_to_mach(_virt) (phys_to_machine(to_phys(_virt))) -#define mfn_to_virt(_mfn) (to_virt(mfn_to_pfn(_mfn) << PAGE_SHIFT)) -#define pfn_to_virt(_pfn) (to_virt((_pfn) << PAGE_SHIFT)) - -/* Pagetable walking. */ -#define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT) -#define pte_to_virt(_pte) to_virt(mfn_to_pfn(pte_to_mfn(_pte)) << PAGE_SHIFT) - - -#define PT_BASE ((pgentry_t *)start_info.pt_base) - -#ifdef __x86_64__ -#define virtual_to_l3(_virt) ((pgentry_t *)pte_to_virt(PT_BASE[l4_table_offset(_virt)])) -#else -#define virtual_to_l3(_virt) PT_BASE -#endif - -#define virtual_to_l2(_virt) ({ \ - unsigned long __virt2 = (_virt); \ - (pgentry_t *) pte_to_virt(virtual_to_l3(__virt2)[l3_table_offset(__virt2)]); \ -}) - -#define virtual_to_l1(_virt) ({ \ - unsigned long __virt1 = (_virt); \ - (pgentry_t *) pte_to_virt(virtual_to_l2(__virt1)[l2_table_offset(__virt1)]); \ -}) - -#define virtual_to_pte(_virt) ({ \ - unsigned long __virt0 = (unsigned long) (_virt); \ - virtual_to_l1(__virt0)[l1_table_offset(__virt0)]; \ -}) -#define virtual_to_mfn(_virt) pte_to_mfn(virtual_to_pte(_virt)) - -#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, L1_PROT) -#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, NULL, L1_PROT_RO) -#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, NULL, L1_PROT_RO) - -pgentry_t *need_pgt(unsigned long addr); -int mfn_is_ram(unsigned long mfn); - -#endif /* !__RUMP_KERNEL__ */ - -#endif /* _ARCH_MM_H_ */ diff --git a/include/mini-os/x86/os.h b/include/mini-os/x86/os.h deleted file mode 100644 index a9429d9..0000000 --- a/include/mini-os/x86/os.h +++ /dev/null @@ -1,549 +0,0 @@ -/****************************************************************************** - * os.h - * - * random collection of macros and definition - */ - -#ifndef _MINIOS_X86_OS_H_ -#define _MINIOS_X86_OS_H_ - -#include - -#define __KERNEL_CS FLAT_KERNEL_CS -#define __KERNEL_DS FLAT_KERNEL_DS -#define __KERNEL_SS FLAT_KERNEL_SS - -#define TRAP_divide_error 0 -#define TRAP_debug 1 -#define TRAP_nmi 2 -#define TRAP_int3 3 -#define TRAP_overflow 4 -#define TRAP_bounds 5 -#define TRAP_invalid_op 6 -#define TRAP_no_device 7 -#define TRAP_double_fault 8 -#define TRAP_copro_seg 9 -#define TRAP_invalid_tss 10 -#define TRAP_no_segment 11 -#define TRAP_stack_error 12 -#define TRAP_gp_fault 13 -#define TRAP_page_fault 14 -#define TRAP_spurious_int 15 -#define TRAP_copro_error 16 -#define TRAP_alignment_check 17 -#define TRAP_machine_check 18 -#define TRAP_simd_error 19 -#define TRAP_deferred_nmi 31 - -/* Everything below this point is not included by assembler (.S) files. */ -#ifndef __ASSEMBLY__ - -extern shared_info_t *HYPERVISOR_shared_info; - -void trap_init(void); -void trap_fini(void); - -void arch_init(start_info_t *si); -void arch_print_info(void); -void arch_fini(void); - - - - - -/* - * The use of 'barrier' in the following reflects their use as local-lock - * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following - * critical operations are executed. All critical operations must complete - * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also - * includes these barriers, for example. - */ - -#define __cli() \ -do { \ - vcpu_info_t *_vcpu; \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ - _vcpu->evtchn_upcall_mask = 1; \ - barrier(); \ -} while (0) - -#define __sti() \ -do { \ - vcpu_info_t *_vcpu; \ - barrier(); \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ - _vcpu->evtchn_upcall_mask = 0; \ - barrier(); /* unmask then check (avoid races) */ \ - if ( unlikely(_vcpu->evtchn_upcall_pending) ) \ - minios_force_evtchn_callback(); \ -} while (0) - -#define __save_flags(x) \ -do { \ - vcpu_info_t *_vcpu; \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ - (x) = _vcpu->evtchn_upcall_mask; \ -} while (0) - -#define __restore_flags(x) \ -do { \ - vcpu_info_t *_vcpu; \ - barrier(); \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ - if ((_vcpu->evtchn_upcall_mask = (x)) == 0) { \ - barrier(); /* unmask then check (avoid races) */ \ - if ( unlikely(_vcpu->evtchn_upcall_pending) ) \ - minios_force_evtchn_callback(); \ - }\ -} while (0) - -#define safe_halt() ((void)0) - -#define __save_and_cli(x) \ -do { \ - vcpu_info_t *_vcpu; \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ - (x) = _vcpu->evtchn_upcall_mask; \ - _vcpu->evtchn_upcall_mask = 1; \ - barrier(); \ -} while (0) - -#define local_irq_save(x) __save_and_cli(x) -#define local_irq_restore(x) __restore_flags(x) -#define local_save_flags(x) __save_flags(x) -#define local_irq_disable() __cli() -#define local_irq_enable() __sti() - -#define irqs_disabled() \ - HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask - -/* This is a barrier for the compiler only, NOT the processor! */ -#define barrier() __asm__ __volatile__("": : :"memory") - -#if defined(__i386__) -#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") -#define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") -#define wmb() __asm__ __volatile__ ("": : :"memory") -#elif defined(__x86_64__) -#define mb() __asm__ __volatile__ ("mfence":::"memory") -#define rmb() __asm__ __volatile__ ("lfence":::"memory") -#define wmb() __asm__ __volatile__ ("sfence" ::: "memory") /* From CONFIG_UNORDERED_IO (linux) */ -#endif - - -#define LOCK_PREFIX "" -#define LOCK "" -#define ADDR (*(volatile long *) addr) -/* - * Make sure gcc doesn't try to be clever and move things around - * on us. We need to use _exactly_ the address the user gave us, - * not some alias that contains the same information. - */ -typedef struct { volatile int counter; } atomic_t; - - -/************************** i386 *******************************/ -#if defined (__i386__) - -#define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr)))) -struct __xchg_dummy { unsigned long a[100]; }; -#define __xg(x) ((struct __xchg_dummy *)(x)) -static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) -{ - switch (size) { - case 1: - __asm__ __volatile__("xchgb %b0,%1" - :"=q" (x) - :"m" (*__xg(ptr)), "0" (x) - :"memory"); - break; - case 2: - __asm__ __volatile__("xchgw %w0,%1" - :"=r" (x) - :"m" (*__xg(ptr)), "0" (x) - :"memory"); - break; - case 4: - __asm__ __volatile__("xchgl %0,%1" - :"=r" (x) - :"m" (*__xg(ptr)), "0" (x) - :"memory"); - break; - } - return x; -} - -/** - * test_and_clear_bit - Clear a bit and return its old value - * @nr: Bit to clear - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It can be reorderdered on other architectures other than x86. - * It also implies a memory barrier. - */ -static inline int test_and_clear_bit(int nr, volatile unsigned long * addr) -{ - int oldbit; - - __asm__ __volatile__( LOCK - "btrl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"Ir" (nr) : "memory"); - return oldbit; -} - -static inline int constant_test_bit(int nr, const volatile unsigned long *addr) -{ - return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0; -} - -static inline int variable_test_bit(int nr, const volatile unsigned long * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit) - :"m" (ADDR),"Ir" (nr)); - return oldbit; -} - -#define test_bit(nr,addr) \ -(__builtin_constant_p(nr) ? \ - constant_test_bit((nr),(addr)) : \ - variable_test_bit((nr),(addr))) - -/** - * set_bit - Atomically set a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * This function is atomic and may not be reordered. See __set_bit() - * if you do not require the atomic guarantees. - * - * Note: there are no guarantees that this function will not be reordered - * on non x86 architectures, so if you are writting portable code, - * make sure not to rely on its reordering guarantees. - * - * Note that @nr may be almost arbitrarily large; this function is not - * restricted to acting on a single-word quantity. - */ -static inline void set_bit(int nr, volatile unsigned long * addr) -{ - __asm__ __volatile__( LOCK - "btsl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} - -/** - * clear_bit - Clears a bit in memory - * @nr: Bit to clear - * @addr: Address to start counting from - * - * clear_bit() is atomic and may not be reordered. However, it does - * not contain a memory barrier, so if it is used for locking purposes, - * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit() - * in order to ensure changes are visible on other processors. - */ -static inline void clear_bit(int nr, volatile unsigned long * addr) -{ - __asm__ __volatile__( LOCK - "btrl %1,%0" - :"=m" (ADDR) - :"Ir" (nr)); -} - -/** - * __ffs - find first bit in word. - * @word: The word to search - * - * Undefined if no bit exists, so code should check against 0 first. - */ -static inline unsigned long __ffs(unsigned long word) -{ - __asm__("bsfl %1,%0" - :"=r" (word) - :"rm" (word)); - return word; -} - - -/* - * These have to be done with inline assembly: that way the bit-setting - * is guaranteed to be atomic. All bit operations return 0 if the bit - * was cleared before the operation and != 0 if it was not. - * - * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). - */ -#define ADDR (*(volatile long *) addr) - -#define rdtscll(val) \ - __asm__ __volatile__("rdtsc" : "=A" (val)) - - - -#elif defined(__x86_64__)/* ifdef __i386__ */ -/************************** x86_84 *******************************/ - -#define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr)))) -#define __xg(x) ((volatile long *)(x)) -static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) -{ - switch (size) { - case 1: - __asm__ __volatile__("xchgb %b0,%1" - :"=q" (x) - :"m" (*__xg(ptr)), "0" (x) - :"memory"); - break; - case 2: - __asm__ __volatile__("xchgw %w0,%1" - :"=r" (x) - :"m" (*__xg(ptr)), "0" (x) - :"memory"); - break; - case 4: - __asm__ __volatile__("xchgl %k0,%1" - :"=r" (x) - :"m" (*__xg(ptr)), "0" (x) - :"memory"); - break; - case 8: - __asm__ __volatile__("xchgq %0,%1" - :"=r" (x) - :"m" (*__xg(ptr)), "0" (x) - :"memory"); - break; - } - return x; -} - -/** - * test_and_clear_bit - Clear a bit and return its old value - * @nr: Bit to clear - * @addr: Address to count from - * - * This operation is atomic and cannot be reordered. - * It also implies a memory barrier. - */ -static __inline__ int test_and_clear_bit(int nr, volatile void * addr) -{ - int oldbit; - - __asm__ __volatile__( LOCK_PREFIX - "btrl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit),"=m" (ADDR) - :"dIr" (nr) : "memory"); - return oldbit; -} - -static __inline__ int constant_test_bit(int nr, const volatile void * addr) -{ - return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0; -} - -static __inline__ int variable_test_bit(int nr, volatile const void * addr) -{ - int oldbit; - - __asm__ __volatile__( - "btl %2,%1\n\tsbbl %0,%0" - :"=r" (oldbit) - :"m" (ADDR),"dIr" (nr)); - return oldbit; -} - -#define test_bit(nr,addr) \ -(__builtin_constant_p(nr) ? \ - constant_test_bit((nr),(addr)) : \ - variable_test_bit((nr),(addr))) - - -/** - * set_bit - Atomically set a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from - * - * This function is atomic and may not be reordered. See __set_bit() - * if you do not require the atomic guarantees. - * Note that @nr may be almost arbitrarily large; this function is not - * restricted to acting on a single-word quantity. - */ -static __inline__ void set_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( LOCK_PREFIX - "btsl %1,%0" - :"=m" (ADDR) - :"dIr" (nr) : "memory"); -} - -/** - * clear_bit - Clears a bit in memory - * @nr: Bit to clear - * @addr: Address to start counting from - * - * clear_bit() is atomic and may not be reordered. However, it does - * not contain a memory barrier, so if it is used for locking purposes, - * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit() - * in order to ensure changes are visible on other processors. - */ -static __inline__ void clear_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__( LOCK_PREFIX - "btrl %1,%0" - :"=m" (ADDR) - :"dIr" (nr)); -} - -/** - * __ffs - find first bit in word. - * @word: The word to search - * - * Undefined if no bit exists, so code should check against 0 first. - */ -static __inline__ unsigned long __ffs(unsigned long word) -{ - __asm__("bsfq %1,%0" - :"=r" (word) - :"rm" (word)); - return word; -} - -#define ADDR (*(volatile long *) addr) - -#define rdtscll(val) do { \ - unsigned int __a,__d; \ - asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \ - (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \ -} while(0) - -#define wrmsr(msr,val1,val2) \ - __asm__ __volatile__("wrmsr" \ - : /* no outputs */ \ - : "c" (msr), "a" (val1), "d" (val2)) - -#define wrmsrl(msr,val) wrmsr(msr,(uint32_t)((uint64_t)(val)),((uint64_t)(val))>>32) - - -#else /* ifdef __x86_64__ */ -#error "Unsupported architecture" -#endif - -/********************* common i386 and x86_64 ****************************/ -struct __synch_xchg_dummy { unsigned long a[100]; }; -#define __synch_xg(x) ((struct __synch_xchg_dummy *)(x)) - -#define synch_cmpxchg(ptr, old, new) \ -((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\ - (unsigned long)(old), \ - (unsigned long)(new), \ - sizeof(*(ptr)))) - -static inline unsigned long __synch_cmpxchg(volatile void *ptr, - unsigned long old, - unsigned long new, int size) -{ - unsigned long prev; - switch (size) { - case 1: - __asm__ __volatile__("lock; cmpxchgb %b1,%2" - : "=a"(prev) - : "q"(new), "m"(*__synch_xg(ptr)), - "0"(old) - : "memory"); - return prev; - case 2: - __asm__ __volatile__("lock; cmpxchgw %w1,%2" - : "=a"(prev) - : "r"(new), "m"(*__synch_xg(ptr)), - "0"(old) - : "memory"); - return prev; -#ifdef __x86_64__ - case 4: - __asm__ __volatile__("lock; cmpxchgl %k1,%2" - : "=a"(prev) - : "r"(new), "m"(*__synch_xg(ptr)), - "0"(old) - : "memory"); - return prev; - case 8: - __asm__ __volatile__("lock; cmpxchgq %1,%2" - : "=a"(prev) - : "r"(new), "m"(*__synch_xg(ptr)), - "0"(old) - : "memory"); - return prev; -#else - case 4: - __asm__ __volatile__("lock; cmpxchgl %1,%2" - : "=a"(prev) - : "r"(new), "m"(*__synch_xg(ptr)), - "0"(old) - : "memory"); - return prev; -#endif - } - return old; -} - - -static __inline__ void synch_set_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__ ( - "lock btsl %1,%0" - : "=m" (ADDR) : "Ir" (nr) : "memory" ); -} - -static __inline__ void synch_clear_bit(int nr, volatile void * addr) -{ - __asm__ __volatile__ ( - "lock btrl %1,%0" - : "=m" (ADDR) : "Ir" (nr) : "memory" ); -} - -static __inline__ int synch_test_and_set_bit(int nr, volatile void * addr) -{ - int oldbit; - __asm__ __volatile__ ( - "lock btsl %2,%1\n\tsbbl %0,%0" - : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory"); - return oldbit; -} - -static __inline__ int synch_test_and_clear_bit(int nr, volatile void * addr) -{ - int oldbit; - __asm__ __volatile__ ( - "lock btrl %2,%1\n\tsbbl %0,%0" - : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory"); - return oldbit; -} - -static __inline__ int synch_const_test_bit(int nr, const volatile void * addr) -{ - return ((1UL << (nr & 31)) & - (((const volatile unsigned int *) addr)[nr >> 5])) != 0; -} - -static __inline__ int synch_var_test_bit(int nr, volatile void * addr) -{ - int oldbit; - __asm__ __volatile__ ( - "btl %2,%1\n\tsbbl %0,%0" - : "=r" (oldbit) : "m" (ADDR), "Ir" (nr) ); - return oldbit; -} - -#define synch_test_bit(nr,addr) \ -(__builtin_constant_p(nr) ? \ - synch_const_test_bit((nr),(addr)) : \ - synch_var_test_bit((nr),(addr))) - - -#undef ADDR - -#endif /* not assembly */ -#endif /* _MINIOS_X86_OS_H_ */ diff --git a/include/mini-os/x86/sched.h b/include/mini-os/x86/sched.h deleted file mode 100644 index be9b5c4..0000000 --- a/include/mini-os/x86/sched.h +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef __ARCH_SCHED_H__ -#define __ARCH_SCHED_H__ - -#include - -static inline struct thread* get_current(void) -{ - struct thread **current; -#ifdef __i386__ - register unsigned long sp asm("esp"); -#else - register unsigned long sp asm("rsp"); -#endif - current = (void *)(unsigned long)(sp & ~(__STACK_SIZE-1)); - return *current; -}; - -struct thread_md { - unsigned long thrmd_sp; - unsigned long thrmd_ip; -}; -#define thr_sp md.thrmd_sp -#define thr_ip md.thrmd_ip - -extern void _minios_entry_arch_switch_threads(unsigned long *prevctx, unsigned long *nextctx); - -#define arch_switch_threads(prev,next) _minios_entry_arch_switch_threads(&(prev)->thr_sp, &(next)->thr_sp) - -#endif /* __ARCH_SCHED_H__ */ diff --git a/include/mini-os/x86/spinlock.h b/include/mini-os/x86/spinlock.h deleted file mode 100644 index b22f2a4..0000000 --- a/include/mini-os/x86/spinlock.h +++ /dev/null @@ -1,97 +0,0 @@ - - -#ifndef __ARCH_ASM_SPINLOCK_H -#define __ARCH_ASM_SPINLOCK_H - -#ifndef __RUMP_KERNEL__ -#include -#endif - -#include "os.h" - - -#define ARCH_SPIN_LOCK_UNLOCKED { 1 } - -/* - * Simple spin lock operations. There are two variants, one clears IRQ's - * on the local processor, one does not. - * - * We make no fairness assumptions. They have a cost. - */ - -#define arch_spin_is_locked(x) (*(volatile signed char *)(&(x)->slock) <= 0) -#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) - -#define spin_lock_string \ - "1:\n" \ - LOCK \ - "decb %0\n\t" \ - "jns 3f\n" \ - "2:\t" \ - "rep;nop\n\t" \ - "cmpb $0,%0\n\t" \ - "jle 2b\n\t" \ - "jmp 1b\n" \ - "3:\n\t" - -#define spin_lock_string_flags \ - "1:\n" \ - LOCK \ - "decb %0\n\t" \ - "jns 4f\n\t" \ - "2:\t" \ - "testl $0x200, %1\n\t" \ - "jz 3f\n\t" \ - "#sti\n\t" \ - "3:\t" \ - "rep;nop\n\t" \ - "cmpb $0, %0\n\t" \ - "jle 3b\n\t" \ - "#cli\n\t" \ - "jmp 1b\n" \ - "4:\n\t" - -/* - * This works. Despite all the confusion. - * (except on PPro SMP or if we are using OOSTORE) - * (PPro errata 66, 92) - */ - -#define spin_unlock_string \ - "xchgb %b0, %1" \ - :"=q" (oldval), "=m" (lock->slock) \ - :"0" (oldval) : "memory" - -static inline void _raw_spin_unlock(spinlock_t *lock) -{ - char oldval = 1; - __asm__ __volatile__( - spin_unlock_string - ); -} - -static inline int _raw_spin_trylock(spinlock_t *lock) -{ - char oldval; - __asm__ __volatile__( - "xchgb %b0,%1\n" - :"=q" (oldval), "=m" (lock->slock) - :"0" (0) : "memory"); - return oldval > 0; -} - -static inline void _raw_spin_lock(spinlock_t *lock) -{ - __asm__ __volatile__( - spin_lock_string - :"=m" (lock->slock) : : "memory"); -} - -static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags) -{ - __asm__ __volatile__( - spin_lock_string_flags - :"=m" (lock->slock) : "r" (flags) : "memory"); -} - -#endif diff --git a/include/mini-os/x86/traps.h b/include/mini-os/x86/traps.h deleted file mode 100644 index bfb6781..0000000 --- a/include/mini-os/x86/traps.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - **************************************************************************** - * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge - **************************************************************************** - * - * File: traps.h - * Author: Grzegorz Milos (gm281@cam.ac.uk) - * - * Date: Jun 2005 - * - * Environment: Xen Minimal OS - * Description: Deals with traps - * - **************************************************************************** - */ - -#ifndef _TRAPS_H_ -#define _TRAPS_H_ - -#ifdef __i386__ -struct pt_regs { - long ebx; - long ecx; - long edx; - long esi; - long edi; - long ebp; - long eax; - int xds; - int xes; - long orig_eax; - long eip; - int xcs; - long eflags; - long esp; - int xss; -}; -#elif __x86_64__ - -struct pt_regs { - unsigned long r15; - unsigned long r14; - unsigned long r13; - unsigned long r12; - unsigned long rbp; - unsigned long rbx; -/* arguments: non interrupts/non tracing syscalls only save upto here*/ - unsigned long r11; - unsigned long r10; - unsigned long r9; - unsigned long r8; - unsigned long rax; - unsigned long rcx; - unsigned long rdx; - unsigned long rsi; - unsigned long rdi; - unsigned long orig_rax; -/* end of arguments */ -/* cpu exception frame or undefined */ - unsigned long rip; - unsigned long cs; - unsigned long eflags; - unsigned long rsp; - unsigned long ss; -/* top of stack page */ -}; - - -#endif - -void dump_regs(struct pt_regs *regs); -void stack_walk(void); - -#define TRAP_PF_PROT 0x1 -#define TRAP_PF_WRITE 0x2 -#define TRAP_PF_USER 0x4 - -#endif /* _TRAPS_H_ */ diff --git a/include/mini-os/x86/x86_32/hypercall-x86_32.h b/include/mini-os/x86/x86_32/hypercall-x86_32.h deleted file mode 100644 index 789a834..0000000 --- a/include/mini-os/x86/x86_32/hypercall-x86_32.h +++ /dev/null @@ -1,324 +0,0 @@ -/****************************************************************************** - * hypercall-x86_32.h - * - * Copied from XenLinux. - * - * Copyright (c) 2002-2004, K A Fraser - * - * This file may be distributed separately from the Linux kernel, or - * incorporated into other software packages, subject to the following license: - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this source file (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, modify, - * merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifndef __HYPERCALL_X86_32_H__ -#define __HYPERCALL_X86_32_H__ - -#include -#include -#include -#include - -#define __STR(x) #x -#define STR(x) __STR(x) - -extern char _minios_hypercall_page[PAGE_SIZE]; - -#define _hypercall0(type, name) \ -({ \ - long __res; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res) \ - : \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall1(type, name, a1) \ -({ \ - long __res, __ign1; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=b" (__ign1) \ - : "1" ((long)(a1)) \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall2(type, name, a1, a2) \ -({ \ - long __res, __ign1, __ign2; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ - : "1" ((long)(a1)), "2" ((long)(a2)) \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall3(type, name, a1, a2, a3) \ -({ \ - long __res, __ign1, __ign2, __ign3; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ - "=d" (__ign3) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)) \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall4(type, name, a1, a2, a3, a4) \ -({ \ - long __res, __ign1, __ign2, __ign3, __ign4; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ - "=d" (__ign3), "=S" (__ign4) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)), "4" ((long)(a4)) \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ -({ \ - long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ - "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)), "4" ((long)(a4)), \ - "5" ((long)(a5)) \ - : "memory" ); \ - (type)__res; \ -}) - -static inline int -HYPERVISOR_set_trap_table( - trap_info_t *table) -{ - return _hypercall1(int, set_trap_table, table); -} - -static inline int -HYPERVISOR_mmu_update( - mmu_update_t *req, int count, int *success_count, domid_t domid) -{ - return _hypercall4(int, mmu_update, req, count, success_count, domid); -} - -static inline int -HYPERVISOR_mmuext_op( - struct mmuext_op *op, int count, int *success_count, domid_t domid) -{ - return _hypercall4(int, mmuext_op, op, count, success_count, domid); -} - -static inline int -HYPERVISOR_set_gdt( - unsigned long *frame_list, int entries) -{ - return _hypercall2(int, set_gdt, frame_list, entries); -} - -static inline int -HYPERVISOR_stack_switch( - unsigned long ss, unsigned long esp) -{ - return _hypercall2(int, stack_switch, ss, esp); -} - -static inline int -HYPERVISOR_set_callbacks( - unsigned long event_selector, unsigned long event_address, - unsigned long failsafe_selector, unsigned long failsafe_address) -{ - return _hypercall4(int, set_callbacks, - event_selector, event_address, - failsafe_selector, failsafe_address); -} - -static inline int -HYPERVISOR_fpu_taskswitch( - int set) -{ - return _hypercall1(int, fpu_taskswitch, set); -} - -static inline int -HYPERVISOR_sched_op( - int cmd, void *arg) -{ - return _hypercall2(int, sched_op, cmd, arg); -} - -static inline long -HYPERVISOR_set_timer_op( - uint64_t timeout) -{ - unsigned long timeout_hi = (unsigned long)(timeout>>32); - unsigned long timeout_lo = (unsigned long)timeout; - return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi); -} - -static inline int -HYPERVISOR_set_debugreg( - int reg, unsigned long value) -{ - return _hypercall2(int, set_debugreg, reg, value); -} - -static inline unsigned long -HYPERVISOR_get_debugreg( - int reg) -{ - return _hypercall1(unsigned long, get_debugreg, reg); -} - -static inline int -HYPERVISOR_update_descriptor( - uint64_t ma, uint64_t desc) -{ - return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32); -} - -static inline int -HYPERVISOR_memory_op( - unsigned int cmd, void *arg) -{ - return _hypercall2(int, memory_op, cmd, arg); -} - -static inline int -HYPERVISOR_multicall( - void *call_list, int nr_calls) -{ - return _hypercall2(int, multicall, call_list, nr_calls); -} - -static inline int -HYPERVISOR_update_va_mapping( - unsigned long va, pte_t new_val, unsigned long flags) -{ - return _hypercall4(int, update_va_mapping, va, - new_val.pte_low, new_val.pte_high, flags); -} - -static inline int -HYPERVISOR_event_channel_op( - int cmd, void *op) -{ - return _hypercall2(int, event_channel_op, cmd, op); -} - -static inline int -HYPERVISOR_xen_version( - int cmd, void *arg) -{ - return _hypercall2(int, xen_version, cmd, arg); -} - -static inline int -HYPERVISOR_console_io( - int cmd, int count, char *str) -{ - return _hypercall3(int, console_io, cmd, count, str); -} - -static inline int -HYPERVISOR_physdev_op( - void *physdev_op) -{ - return _hypercall1(int, physdev_op, physdev_op); -} - -static inline int -HYPERVISOR_grant_table_op( - unsigned int cmd, void *uop, unsigned int count) -{ - return _hypercall3(int, grant_table_op, cmd, uop, count); -} - -static inline int -HYPERVISOR_update_va_mapping_otherdomain( - unsigned long va, pte_t new_val, unsigned long flags, domid_t domid) -{ - return _hypercall5(int, update_va_mapping_otherdomain, va, - new_val.pte_low, new_val.pte_high, flags, domid); -} - -static inline int -HYPERVISOR_vm_assist( - unsigned int cmd, unsigned int type) -{ - return _hypercall2(int, vm_assist, cmd, type); -} - -static inline int -HYPERVISOR_vcpu_op( - int cmd, int vcpuid, void *extra_args) -{ - return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); -} - -static inline int -HYPERVISOR_suspend( - unsigned long srec) -{ - return _hypercall3(int, sched_op, SCHEDOP_shutdown, - SHUTDOWN_suspend, srec); -} - -static inline int -HYPERVISOR_nmi_op( - unsigned long op, - unsigned long arg) -{ - return _hypercall2(int, nmi_op, op, arg); -} - -static inline int -HYPERVISOR_sysctl( - unsigned long op) -{ - return _hypercall1(int, sysctl, op); -} - -static inline int -HYPERVISOR_domctl( - unsigned long op) -{ - return _hypercall1(int, domctl, op); -} - -#endif /* __HYPERCALL_X86_32_H__ */ - -/* - * Local variables: - * c-file-style: "linux" - * indent-tabs-mode: t - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * End: - */ diff --git a/include/mini-os/x86/x86_64/hypercall-x86_64.h b/include/mini-os/x86/x86_64/hypercall-x86_64.h deleted file mode 100644 index 27d008e..0000000 --- a/include/mini-os/x86/x86_64/hypercall-x86_64.h +++ /dev/null @@ -1,332 +0,0 @@ -/****************************************************************************** - * hypercall-x86_64.h - * - * Copied from XenLinux. - * - * Copyright (c) 2002-2004, K A Fraser - * - * 64-bit updates: - * Benjamin Liu - * Jun Nakajima - * - * This file may be distributed separately from the Linux kernel, or - * incorporated into other software packages, subject to the following license: - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this source file (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, modify, - * merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifndef __HYPERCALL_X86_64_H__ -#define __HYPERCALL_X86_64_H__ - -#include -#include -#include - -#define __STR(x) #x -#define STR(x) __STR(x) - -extern char _minios_hypercall_page[PAGE_SIZE]; - -#define _hypercall0(type, name) \ -({ \ - long __res; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res) \ - : \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall1(type, name, a1) \ -({ \ - long __res, __ign1; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=D" (__ign1) \ - : "1" ((long)(a1)) \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall2(type, name, a1, a2) \ -({ \ - long __res, __ign1, __ign2; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \ - : "1" ((long)(a1)), "2" ((long)(a2)) \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall3(type, name, a1, a2, a3) \ -({ \ - long __res, __ign1, __ign2, __ign3; \ - asm volatile ( \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ - "=d" (__ign3) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)) \ - : "memory" ); \ - (type)__res; \ -}) - -#define _hypercall4(type, name, a1, a2, a3, a4) \ -({ \ - long __res, __ign1, __ign2, __ign3; \ - asm volatile ( \ - "movq %7,%%r10; " \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ - "=d" (__ign3) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)), "g" ((long)(a4)) \ - : "memory", "r10" ); \ - (type)__res; \ -}) - -#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ -({ \ - long __res, __ign1, __ign2, __ign3; \ - asm volatile ( \ - "movq %7,%%r10; movq %8,%%r8; " \ - "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ - : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ - "=d" (__ign3) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)), "g" ((long)(a4)), \ - "g" ((long)(a5)) \ - : "memory", "r10", "r8" ); \ - (type)__res; \ -}) - -static inline int -HYPERVISOR_set_trap_table( - trap_info_t *table) -{ - return _hypercall1(int, set_trap_table, table); -} - -static inline int -HYPERVISOR_mmu_update( - mmu_update_t *req, int count, int *success_count, domid_t domid) -{ - return _hypercall4(int, mmu_update, req, count, success_count, domid); -} - -static inline int -HYPERVISOR_mmuext_op( - struct mmuext_op *op, int count, int *success_count, domid_t domid) -{ - return _hypercall4(int, mmuext_op, op, count, success_count, domid); -} - -static inline int -HYPERVISOR_set_gdt( - unsigned long *frame_list, int entries) -{ - return _hypercall2(int, set_gdt, frame_list, entries); -} - -static inline int -HYPERVISOR_stack_switch( - unsigned long ss, unsigned long esp) -{ - return _hypercall2(int, stack_switch, ss, esp); -} - -static inline int -HYPERVISOR_set_callbacks( - unsigned long event_address, unsigned long failsafe_address, - unsigned long syscall_address) -{ - return _hypercall3(int, set_callbacks, - event_address, failsafe_address, syscall_address); -} - -static inline int -HYPERVISOR_fpu_taskswitch( - int set) -{ - return _hypercall1(int, fpu_taskswitch, set); -} - -static inline int -HYPERVISOR_sched_op( - int cmd, void *arg) -{ - return _hypercall2(int, sched_op, cmd, arg); -} - -static inline long -HYPERVISOR_set_timer_op( - uint64_t timeout) -{ - return _hypercall1(long, set_timer_op, timeout); -} - -static inline int -HYPERVISOR_set_debugreg( - int reg, unsigned long value) -{ - return _hypercall2(int, set_debugreg, reg, value); -} - -static inline unsigned long -HYPERVISOR_get_debugreg( - int reg) -{ - return _hypercall1(unsigned long, get_debugreg, reg); -} - -static inline int -HYPERVISOR_update_descriptor( - unsigned long ma, unsigned long word) -{ - return _hypercall2(int, update_descriptor, ma, word); -} - -static inline int -HYPERVISOR_memory_op( - unsigned int cmd, void *arg) -{ - return _hypercall2(int, memory_op, cmd, arg); -} - -static inline int -HYPERVISOR_multicall( - void *call_list, int nr_calls) -{ - return _hypercall2(int, multicall, call_list, nr_calls); -} - -static inline int -HYPERVISOR_update_va_mapping( - unsigned long va, pte_t new_val, unsigned long flags) -{ - return _hypercall3(int, update_va_mapping, va, new_val.pte, flags); -} - -static inline int -HYPERVISOR_event_channel_op( - int cmd, void *op) -{ - return _hypercall2(int, event_channel_op, cmd, op); -} - -static inline int -HYPERVISOR_xen_version( - int cmd, void *arg) -{ - return _hypercall2(int, xen_version, cmd, arg); -} - -static inline int -HYPERVISOR_console_io( - int cmd, int count, char *str) -{ - return _hypercall3(int, console_io, cmd, count, str); -} - -static inline int -HYPERVISOR_physdev_op( - void *physdev_op) -{ - return _hypercall1(int, physdev_op, physdev_op); -} - -static inline int -HYPERVISOR_grant_table_op( - unsigned int cmd, void *uop, unsigned int count) -{ - return _hypercall3(int, grant_table_op, cmd, uop, count); -} - -static inline int -HYPERVISOR_update_va_mapping_otherdomain( - unsigned long va, pte_t new_val, unsigned long flags, domid_t domid) -{ - return _hypercall4(int, update_va_mapping_otherdomain, va, - new_val.pte, flags, domid); -} - -static inline int -HYPERVISOR_vm_assist( - unsigned int cmd, unsigned int type) -{ - return _hypercall2(int, vm_assist, cmd, type); -} - -static inline int -HYPERVISOR_vcpu_op( - int cmd, int vcpuid, void *extra_args) -{ - return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); -} - -static inline int -HYPERVISOR_set_segment_base( - int reg, unsigned long value) -{ - return _hypercall2(int, set_segment_base, reg, value); -} - -static inline int -HYPERVISOR_suspend( - unsigned long srec) -{ - return _hypercall3(int, sched_op, SCHEDOP_shutdown, - SHUTDOWN_suspend, srec); -} - -static inline int -HYPERVISOR_nmi_op( - unsigned long op, - unsigned long arg) -{ - return _hypercall2(int, nmi_op, op, arg); -} - -static inline int -HYPERVISOR_sysctl( - unsigned long op) -{ - return _hypercall1(int, sysctl, op); -} - -static inline int -HYPERVISOR_domctl( - unsigned long op) -{ - return _hypercall1(int, domctl, op); -} - -#endif /* __HYPERCALL_X86_64_H__ */ - -/* - * Local variables: - * c-file-style: "linux" - * indent-tabs-mode: t - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * End: - */ diff --git a/include/mini-os/xenbus.h b/include/mini-os/xenbus.h deleted file mode 100644 index 0e45d47..0000000 --- a/include/mini-os/xenbus.h +++ /dev/null @@ -1,216 +0,0 @@ -#ifndef MINIOS_XENBUS_H__ -#define MINIOS_XENBUS_H__ - -#include -#include -#include -#include -#include - -typedef unsigned long xenbus_transaction_t; -#define XBT_NIL ((xenbus_transaction_t)0) - -#ifdef CONFIG_XENBUS -/* Initialize the XenBus system. */ -void init_xenbus(void); -#else -static inline void init_xenbus(void) -{ -} -#endif - -/* Read the value associated with a path. Returns a malloc'd error - string on failure and sets *value to NULL. On success, *value is - set to a malloc'd copy of the value. */ -char *xenbus_read(xenbus_transaction_t xbt, const char *path, char **value); - -/* All accesses to an active xenbus_event_queue must occur with this - * lock held. The public functions here will do that for you, but - * your own accesses to the queue (including the contained waitq) - * must be protected by the lock. */ -extern spinlock_t xenbus_req_lock; - -/* Queue for events (watches or async request replies - see below) */ -struct xenbus_event { - union { - struct { - /* must be first, both for the bare minios xs.c, and for - * xenbus_wait_for_watch's handling */ - char *path; - char *token; - }; - struct xsd_sockmsg *reply; - }; - struct xenbus_watch *watch; - MINIOS_STAILQ_ENTRY(xenbus_event) entry; -}; -struct xenbus_event_queue { - MINIOS_STAILQ_HEAD(, xenbus_event) events; - void (*wakeup)(struct xenbus_event_queue*); /* can be safely ignored */ - struct wait_queue_head waitq; -}; - -void xenbus_event_queue_init(struct xenbus_event_queue *queue); - -char *xenbus_watch_path_token(xenbus_transaction_t xbt, const char *path, const char *token, struct xenbus_event_queue *events); -char *xenbus_unwatch_path_token(xenbus_transaction_t xbt, const char *path, const char *token); -void xenbus_wait_for_watch(struct xenbus_event_queue *queue); -char **xenbus_wait_for_watch_return(struct xenbus_event_queue *queue); -char* xenbus_wait_for_value(const char *path, const char *value, struct xenbus_event_queue *queue); -char *xenbus_wait_for_state_change(const char* path, XenbusState *state, struct xenbus_event_queue *queue); -char *xenbus_switch_state(xenbus_transaction_t xbt, const char* path, XenbusState state); - -/* When no token is provided, use a global queue. */ -#define XENBUS_WATCH_PATH_TOKEN "xenbus_watch_path" -extern struct xenbus_event_queue xenbus_default_watch_queue; -#define xenbus_watch_path(xbt, path) xenbus_watch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN, NULL) -#define xenbus_unwatch_path(xbt, path) xenbus_unwatch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN) - - -/* Associates a value with a path. Returns a malloc'd error string on - failure. */ -char *xenbus_write(xenbus_transaction_t xbt, const char *path, const char *value); - -struct write_req { - const void *data; - unsigned len; -}; - -/* Send a message to xenbus, in the same fashion as xb_write, and - block waiting for a reply. The reply is malloced and should be - freed by the caller. */ -struct xsd_sockmsg * -xenbus_msg_reply(int type, - xenbus_transaction_t trans, - struct write_req *io, - int nr_reqs); - -/* Removes the value associated with a path. Returns a malloc'd error - string on failure. */ -char *xenbus_rm(xenbus_transaction_t xbt, const char *path); - -/* List the contents of a directory. Returns a malloc'd error string - on failure and sets *contents to NULL. On success, *contents is - set to a malloc'd array of pointers to malloc'd strings. The array - is NULL terminated. May block. */ -char *xenbus_ls(xenbus_transaction_t xbt, const char *prefix, char ***contents); - -/* Reads permissions associated with a path. Returns a malloc'd error - string on failure and sets *value to NULL. On success, *value is - set to a malloc'd copy of the value. */ -char *xenbus_get_perms(xenbus_transaction_t xbt, const char *path, char **value); - -/* Sets the permissions associated with a path. Returns a malloc'd - error string on failure. */ -char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t dom, char perm); - -/* Start a xenbus transaction. Returns the transaction in xbt on - success or a malloc'd error string otherwise. */ -char *xenbus_transaction_start(xenbus_transaction_t *xbt); - -/* End a xenbus transaction. Returns a malloc'd error string if it - fails. abort says whether the transaction should be aborted. - Returns 1 in *retry iff the transaction should be retried. */ -char *xenbus_transaction_end(xenbus_transaction_t, int abort, - int *retry); - -/* Read path and parse it as an integer. Returns -1 on error. */ -int xenbus_read_integer(const char *path); - -/* Contraction of snprintf and xenbus_write(path/node). */ -char* xenbus_printf(xenbus_transaction_t xbt, - const char* node, const char* path, - const char* fmt, ...) - __attribute__((__format__(printf, 4, 5))); - -/* Utility function to figure out our domain id */ -domid_t xenbus_get_self_id(void); - -/* - * ----- asynchronous low-level interface ----- - */ - -/* - * Use of queue->wakeup: - * - * If queue->wakeup is set, it will be called instead of - * wake_up(&queue->waitq); - * - * queue->wakeup is initialised (to a function which just calls - * wake_up) by xenbus_event_queue_init. The user who wants something - * different should set ->wakeup after the init, but before the queue - * is used for xenbus_id_allocate or xenbus_watch_prepare. - * - * queue->wakeup() is called with the req_lock held. - */ - -/* Allocate an identifier for a xenbus request. Blocks if none are - * available. Cannot fail. On return, we may use the returned value - * as the id in a xenbus request. - * - * for_queue must already be allocated, but may be uninitialised. - * - * for_queue->watch is not touched by the xenbus machinery for - * handling requests/replies but should probably be initialised by the - * caller (probably to NULL) because this will help the caller - * distinguish the reply from any watch events which might end up in - * the same queue. - * - * reply_queue must exist and have been initialised. - * - * When the response arrives, the reply message will stored in - * for_queue->reply and for_queue will be queued on reply_queue. The - * id must be then explicitly released (or, used again, if desired). - * After ->reply is done with the caller must pass it to free(). - * (Do not use the id for more than one request at a time.) */ -int xenbus_id_allocate(struct xenbus_event_queue *reply_queue, - struct xenbus_event *for_queue); -void xenbus_id_release(int id); - -/* Allocating a token for a watch. - * - * To use this: - * - Include struct xenbus_watch in your own struct. - * - Set events; then call prepare. This will set token. - * You may then use token in a WATCH request. - * - You must UNWATCH before you call release. - * Do not modify token yourself. - * entry is private for the xenbus driver. - * - * When the watch fires, a new struct xenbus_event will be allocated - * and queued on events. The field xenbus_event->watch will have been - * set to watch by the xenbus machinery, and xenbus_event->path will - * be the watch path. After the caller is done with the event, - * its pointer should simply be passed to free(). */ -struct xenbus_watch { - char *token; - struct xenbus_event_queue *events; - MINIOS_LIST_ENTRY(xenbus_watch) entry; -}; -void xenbus_watch_init(struct xenbus_watch *watch); /* makes release a noop */ -void xenbus_watch_prepare(struct xenbus_watch *watch); /* need not be init'd */ -void xenbus_watch_release(struct xenbus_watch *watch); /* idempotent */ - - -/* Send data to xenbus. This can block. All of the requests are seen - * by xenbus as if sent atomically. The header is added - * automatically, using type %type, req_id %req_id, and trans_id - * %trans_id. */ -void xenbus_xb_write(int type, int req_id, xenbus_transaction_t trans_id, - const struct write_req *req, int nr_reqs); - -void xenbus_free(void*); -/* If the caller is in a scope which uses a different malloc arena, - * it must use this rather than free() when freeing data received - * from xenbus. */ - -#ifdef CONFIG_XENBUS -/* Reset the XenBus system. */ -void fini_xenbus(void); -#else -static inline void fini_xenbus(void) -{ -} -#endif - -#endif /* MINIOS_XENBUS_H__ */ diff --git a/include/mini-os/xmalloc.h b/include/mini-os/xmalloc.h deleted file mode 100644 index c34b365..0000000 --- a/include/mini-os/xmalloc.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __MINIOS_XMALLOC_H__ -#define __MINIOS_XMALLOC_H__ - - -#include - -void * memalloc(size_t, size_t); -void memfree(void *); -void free(void *); -int posix_memalign(void **, size_t, size_t); -void * realloc(void *, size_t); -void * calloc(size_t, size_t); - -#define DEFAULT_ALIGN (sizeof(unsigned long)) - -/* compat */ -#define _xmalloc(size, align) memalloc(size, align) -#define xfree(ptr) free(ptr) - - -static inline void *_xmalloc_array(size_t size, size_t align, size_t num) -{ - /* Check for overflow. */ - if (size && num > UINT_MAX / size) - return NULL; - return _xmalloc(size * num, align); -} - -/* Allocate space for typed object. */ -#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type))) - -/* Allocate space for array of typed objects. */ -#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) - -#endif /* __MINIOS_XMALLOC_H__ */ diff --git a/xen/include/mini-os/blkfront.h b/xen/include/mini-os/blkfront.h new file mode 100644 index 0000000..18de25b --- /dev/null +++ b/xen/include/mini-os/blkfront.h @@ -0,0 +1,46 @@ +#ifndef _MINIOS_BLKFRONT_H_ +#define _MINIOS_BLKFRONT_H_ + +#include +#include +#include +struct blkfront_dev; +struct blkfront_aiocb +{ + struct blkfront_dev *aio_dev; + uint8_t *aio_buf; + size_t aio_nbytes; + off_t aio_offset; + size_t total_bytes; + uint8_t is_write; + void *data; + + grant_ref_t gref[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + int n; + + void (*aio_cb)(struct blkfront_aiocb *aiocb, int ret); +}; +struct blkfront_info +{ + uint64_t sectors; + unsigned sector_size; + int mode; + int info; + int barrier; + int flush; +}; +struct blkfront_dev *blkfront_init(char *nodename, struct blkfront_info *info); +void blkfront_aio(struct blkfront_aiocb *aiocbp, int write); +#define blkfront_aio_read(aiocbp) blkfront_aio(aiocbp, 0) +#define blkfront_aio_write(aiocbp) blkfront_aio(aiocbp, 1) +void blkfront_io(struct blkfront_aiocb *aiocbp, int write); +#define blkfront_read(aiocbp) blkfront_io(aiocbp, 0) +#define blkfront_write(aiocbp) blkfront_io(aiocbp, 1) +void blkfront_aio_push_operation(struct blkfront_aiocb *aiocbp, uint8_t op); +int blkfront_aio_poll(struct blkfront_dev *dev); +void blkfront_sync(struct blkfront_dev *dev); +void blkfront_shutdown(struct blkfront_dev *dev); + +extern struct wait_queue_head blkfront_queue; + +#endif /* _MINIOS_BLKFRONT_H_ */ diff --git a/xen/include/mini-os/console.h b/xen/include/mini-os/console.h new file mode 100644 index 0000000..efb633c --- /dev/null +++ b/xen/include/mini-os/console.h @@ -0,0 +1,89 @@ +/* + **************************************************************************** + * (C) 2006 - Grzegorz Milos - Cambridge University + **************************************************************************** + * + * File: console.h + * Author: Grzegorz Milos + * Changes: + * + * Date: Mar 2006 + * + * Environment: Xen Minimal OS + * Description: Console interface. + * + * Handles console I/O. Defines printk. + * + **************************************************************************** + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#ifndef _MINIOS_LIB_CONSOLE_H_ +#define _MINIOS_LIB_CONSOLE_H_ + +#include +#include +#include + +#include + +#include +#include +#include + +struct consfront_dev { + domid_t dom; + + struct xencons_interface *ring; + grant_ref_t ring_ref; + evtchn_port_t evtchn; + + char *nodename; + char *backend; + + struct xenbus_event_queue events; + +}; + + + +void print(int direct, const char *fmt, va_list args); +void minios_printk(const char *fmt, ...); +void xprintk(const char *fmt, ...); +void panic(const char *fmt, ...); + +#define tprintk(_fmt, _args...) printk("[%s] " _fmt, current->name, ##_args) + +void xencons_rx(char *buf, unsigned len, struct pt_regs *regs); +void xencons_tx(void); + +void init_console(void); +void minios_console_print(struct consfront_dev *dev, char *data, int length); +void fini_console(struct consfront_dev *dev); + +/* Low level functions defined in xencons_ring.c */ +extern struct wait_queue_head console_queue; +struct consfront_dev *xencons_ring_init(void); +struct consfront_dev *init_consfront(char *_nodename); +int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len); +int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len); +int xencons_ring_avail(struct consfront_dev *dev); +int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len); +void free_consfront(struct consfront_dev *dev); + +#endif /* _MINIOS_LIB_CONSOLE_H_ */ diff --git a/xen/include/mini-os/events.h b/xen/include/mini-os/events.h new file mode 100644 index 0000000..c4878e0 --- /dev/null +++ b/xen/include/mini-os/events.h @@ -0,0 +1,50 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + **************************************************************************** + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge + **************************************************************************** + * + * File: events.h + * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) + * Changes: Grzegorz Milos (gm281@cam.ac.uk) + * + * Date: Jul 2003, changes Jun 2005 + * + * Environment: Xen Minimal OS + * Description: Deals with events on the event channels + * + **************************************************************************** + */ + +#ifndef _MINIOS_EVENTS_H_ +#define _MINIOS_EVENTS_H_ + +#include + +typedef void (*evtchn_handler_t)(evtchn_port_t, struct pt_regs *, void *); + +/* prototypes */ +int do_event(evtchn_port_t port, struct pt_regs *regs); +evtchn_port_t minios_bind_virq(uint32_t virq, evtchn_handler_t handler, void *data); +evtchn_port_t minios_bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t handler, void *data); +evtchn_port_t minios_bind_evtchn(evtchn_port_t port, evtchn_handler_t handler, + void *data); +void minios_unbind_evtchn(evtchn_port_t port); +void init_events(void); +int minios_evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler, + void *data, evtchn_port_t *port); +int minios_evtchn_bind_interdomain(domid_t pal, evtchn_port_t remote_port, + evtchn_handler_t handler, void *data, + evtchn_port_t *local_port); +void unbind_all_ports(void); + +static inline int notify_remote_via_evtchn(evtchn_port_t port) +{ + evtchn_send_t op; + op.port = port; + return HYPERVISOR_event_channel_op(EVTCHNOP_send, &op); +} + +void fini_events(void); + +#endif /* _MINIOS_EVENTS_H_ */ diff --git a/xen/include/mini-os/fbfront.h b/xen/include/mini-os/fbfront.h new file mode 100644 index 0000000..ab3107d --- /dev/null +++ b/xen/include/mini-os/fbfront.h @@ -0,0 +1,45 @@ +#ifndef _MINIOS_FBFRONT_H_ +#define _MINIOS_FBFRONT_H_ + +#include +#include +#include +#include + +/* from */ +#ifndef BTN_LEFT +#define BTN_LEFT 0x110 +#endif +#ifndef BTN_RIGHT +#define BTN_RIGHT 0x111 +#endif +#ifndef BTN_MIDDLE +#define BTN_MIDDLE 0x112 +#endif +#ifndef KEY_Q +#define KEY_Q 16 +#endif +#ifndef KEY_MAX +#define KEY_MAX 0x1ff +#endif + + +struct kbdfront_dev; +struct kbdfront_dev *init_kbdfront(char *nodename, int abs_pointer); + +int kbdfront_receive(struct kbdfront_dev *dev, union xenkbd_in_event *buf, int n); +extern struct wait_queue_head kbdfront_queue; + +void shutdown_kbdfront(struct kbdfront_dev *dev); + + +struct fbfront_dev *init_fbfront(char *nodename, unsigned long *mfns, int width, int height, int depth, int stride, int n); + +int fbfront_receive(struct fbfront_dev *dev, union xenfb_in_event *buf, int n); +extern struct wait_queue_head fbfront_queue; +void fbfront_update(struct fbfront_dev *dev, int x, int y, int width, int height); +void fbfront_resize(struct fbfront_dev *dev, int width, int height, int stride, int depth, int offset); + +void shutdown_fbfront(struct fbfront_dev *dev); + +#endif /* _MINIOS_FBFRONT_H_ */ diff --git a/xen/include/mini-os/gntmap.h b/xen/include/mini-os/gntmap.h new file mode 100644 index 0000000..dfcd77e --- /dev/null +++ b/xen/include/mini-os/gntmap.h @@ -0,0 +1,35 @@ +#ifndef __MINIOS_GNTMAP_H__ +#define __MINIOS_GNTMAP_H__ + +#include + +/* + * Please consider struct gntmap opaque. If instead you choose to disregard + * this message, I insist that you keep an eye out for raptors. + */ +struct gntmap { + int nentries; + struct gntmap_entry *entries; +}; + +int +gntmap_set_max_grants(struct gntmap *map, int count); + +int +gntmap_munmap(struct gntmap *map, unsigned long start_address, int count); + +void* +gntmap_map_grant_refs(struct gntmap *map, + uint32_t count, + uint32_t *domids, + int domids_stride, + uint32_t *refs, + int writable); + +void +gntmap_init(struct gntmap *map); + +void +gntmap_fini(struct gntmap *map); + +#endif /* !__MINIOS_GNTMAP_H__ */ diff --git a/xen/include/mini-os/gnttab.h b/xen/include/mini-os/gnttab.h new file mode 100644 index 0000000..bc594be --- /dev/null +++ b/xen/include/mini-os/gnttab.h @@ -0,0 +1,16 @@ +#ifndef __MINIOS_GNTTAB_H__ +#define __MINIOS_GNTTAB_H__ + +#include + +void init_gnttab(void); +grant_ref_t gnttab_alloc_and_grant(void **map); +grant_ref_t gnttab_grant_access(domid_t domid, unsigned long frame, + int readonly); +grant_ref_t gnttab_grant_transfer(domid_t domid, unsigned long pfn); +unsigned long gnttab_end_transfer(grant_ref_t gref); +int gnttab_end_access(grant_ref_t ref); +const char *gnttabop_error(int16_t status); +void fini_gnttab(void); + +#endif /* !__MINIOS_GNTTAB_H__ */ diff --git a/xen/include/mini-os/hypervisor.h b/xen/include/mini-os/hypervisor.h new file mode 100644 index 0000000..6c70db8 --- /dev/null +++ b/xen/include/mini-os/hypervisor.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * hypervisor.h + * + * Hypervisor handling. + * + * + * Copyright (c) 2002, K A Fraser + * Copyright (c) 2005, Grzegorz Milos + * Updates: Aravindh Puthiyaparambil + * Updates: Dietmar Hahn for ia64 + */ + +#ifndef _MINIOS_HYPERVISOR_H_ +#define _MINIOS_HYPERVISOR_H_ + +#include +#include +#if defined(__i386__) +#include +#elif defined(__x86_64__) +#include +#else +#error "Unsupported architecture" +#endif +#include + +/* + * a placeholder for the start of day information passed up from the hypervisor + */ +union start_info_union +{ + start_info_t start_info; + char padding[512]; +}; +extern union start_info_union _minios_start_info_union; +#define start_info (_minios_start_info_union.start_info) + +/* hypervisor.c */ +void minios_force_evtchn_callback(void); +void minios_do_hypervisor_callback(struct pt_regs *regs); +void minios_mask_evtchn(uint32_t port); +void minios_unmask_evtchn(uint32_t port); +void minios_clear_evtchn(uint32_t port); + +extern int _minios_in_hypervisor_callback; + +#endif /* __MINIOS_HYPERVISOR_H__ */ diff --git a/xen/include/mini-os/ioremap.h b/xen/include/mini-os/ioremap.h new file mode 100644 index 0000000..a9b08f4 --- /dev/null +++ b/xen/include/mini-os/ioremap.h @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2009 Netronome Systems, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +#ifndef _MINIOS_IOREMAP_H_ +#define _MINIOS_IOREMAP_H_ + +void *ioremap(unsigned long phys_addr, unsigned long size); +void *ioremap_nocache(unsigned long phys_addr, unsigned long size); +void iounmap(void *virt_addr, unsigned long size); + +#endif /* _MINIOS_IOREMAP_H_ */ + +/* -*- Mode:C; c-basic-offset:4; tab-width:4 indent-tabs-mode:nil -*- */ diff --git a/xen/include/mini-os/kernel.h b/xen/include/mini-os/kernel.h new file mode 100644 index 0000000..2fce906 --- /dev/null +++ b/xen/include/mini-os/kernel.h @@ -0,0 +1,14 @@ +#ifndef _MINIOS_KERNEL_H_ +#define _MINIOS_KERNEL_H_ + +extern int app_main(start_info_t *); + +extern void minios_do_exit(void) __attribute__((noreturn)); +extern void minios_stop_kernel(void); + +/* Values should mirror SHUTDOWN_* in xen/sched.h */ +#define MINIOS_HALT_POWEROFF 0 +#define MINIOS_HALT_CRASH 3 +extern void minios_do_halt(int reason) __attribute__((noreturn)); + +#endif /* _MINIOS_KERNEL_H_ */ diff --git a/xen/include/mini-os/lib.h b/xen/include/mini-os/lib.h new file mode 100644 index 0000000..304cb84 --- /dev/null +++ b/xen/include/mini-os/lib.h @@ -0,0 +1,82 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + **************************************************************************** + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + **************************************************************************** + * + * File: lib.h + * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) + * Changes: + * + * Date: Aug 2003 + * + * Environment: Xen Minimal OS + * Description: Random useful library functions, contains some freebsd stuff + * + **************************************************************************** + * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $ + **************************************************************************** + * + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef _MINIOS_LIB_H_ +#define _MINIOS_LIB_H_ + +#include +#include +#include "gntmap.h" + +#include + +#define RAND_MIX 2654435769U + +int rand(void); + +#include + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +#define ASSERT(x) \ +do { \ + if (!(x)) { \ + minios_printk("ASSERTION FAILED: %s at %s:%d.\n", \ + # x , \ + __FILE__, \ + __LINE__); \ + BUG(); \ + } \ +} while(0) + +#define BUG_ON(x) ASSERT(!(x)) + +/* Consistency check as much as possible. */ +void sanity_check(void); + + +#endif /* _MINIOS_LIB_H_ */ diff --git a/xen/include/mini-os/mm.h b/xen/include/mini-os/mm.h new file mode 100644 index 0000000..148ea3c --- /dev/null +++ b/xen/include/mini-os/mm.h @@ -0,0 +1,81 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + * + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + * Copyright (c) 2005, Keir A Fraser + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef _MINIOS_MM_H_ +#define _MINIOS_MM_H_ + +#if defined(__i386__) +#include +#elif defined(__x86_64__) +#include +#elif defined(__ia64__) +#include +#else +#error "Unsupported architecture" +#endif + +#include + +#include +#include + +#define STACK_SIZE_PAGE_ORDER __STACK_SIZE_PAGE_ORDER +#define STACK_SIZE __STACK_SIZE + + +void init_mm(void); +unsigned long minios_alloc_pages(int order); +#define minios_alloc_page() minios_alloc_pages(0) +void minios_free_pages(void *pointer, int order); +#define minios_free_page(p) minios_free_pages(p, 0) + +static __inline__ int get_order(unsigned long size) +{ + int order; + size = (size-1) >> PAGE_SHIFT; + for ( order = 0; size; order++ ) + size >>= 1; + return order; +} + +void arch_init_demand_mapping_area(unsigned long max_pfn); +void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p); +void arch_init_p2m(unsigned long max_pfn_p); + +unsigned long allocate_ondemand(unsigned long n, unsigned long alignment); +/* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */ +void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride, + unsigned long increment, unsigned long alignment, domid_t id, + int *err, unsigned long prot); +void do_map_frames(unsigned long addr, + const unsigned long *f, unsigned long n, unsigned long stride, + unsigned long increment, domid_t id, int *err, unsigned long prot); +int unmap_frames(unsigned long va, unsigned long num_frames); +unsigned long alloc_contig_pages(int order, unsigned int addr_bits); + +int free_physical_pages(xen_pfn_t *mfns, int n); +void fini_mm(void); +uint64_t minios_get_memsize(void); + +#endif /* _MINIOS_MM_H_ */ diff --git a/xen/include/mini-os/netfront.h b/xen/include/mini-os/netfront.h new file mode 100644 index 0000000..24bdbe8 --- /dev/null +++ b/xen/include/mini-os/netfront.h @@ -0,0 +1,14 @@ +#ifndef _MINIOS_NETFRONT_H_ +#define _MINIOS_NETFRONT_H_ + +#include +struct netfront_dev; +struct netfront_dev *netfront_init(char *nodename, void (*netif_rx)(struct netfront_dev *, unsigned char *data, int len), unsigned char rawmac[6], char **ip, void *priv); +void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len); +void netfront_shutdown(struct netfront_dev *dev); + +void *netfront_get_private(struct netfront_dev *); + +extern struct wait_queue_head netfront_queue; + +#endif /* _MINIOS_NETFRONT_H_ */ diff --git a/xen/include/mini-os/os.h b/xen/include/mini-os/os.h new file mode 100644 index 0000000..c5541f5 --- /dev/null +++ b/xen/include/mini-os/os.h @@ -0,0 +1,29 @@ +#ifndef _MINIOS_OS_H_ +#define _MINIOS_OS_H_ + +#define smp_processor_id() 0 +#define unlikely(x) __builtin_expect((x),0) +#define likely(x) __builtin_expect((x),1) + +#include + +#ifndef __RUMP_KERNEL__ + +#if __GNUC__ == 2 && __GNUC_MINOR__ < 96 +#define __builtin_expect(x, expected_value) (x) +#endif + +#ifndef __ASSEMBLY__ +#include +#include +#endif + +#define USED __attribute__ ((used)) + +#define BUG minios_do_exit + +#include + +#endif /* !__RUMP_KERNEL__ */ + +#endif /* _MINIOS_OS_H_ */ diff --git a/xen/include/mini-os/pcifront.h b/xen/include/mini-os/pcifront.h new file mode 100644 index 0000000..ce7344d --- /dev/null +++ b/xen/include/mini-os/pcifront.h @@ -0,0 +1,34 @@ +#ifndef _MINIOS_PCIFRONT_H_ +#define _MINIOS_PCIFRONT_H_ + +#include +#include +struct pcifront_dev; +void pcifront_watches(void *opaque); +struct pcifront_dev *init_pcifront(char *nodename); +void pcifront_op(struct pcifront_dev *dev, struct xen_pci_op *op); +void pcifront_scan(struct pcifront_dev *dev, void (*fun)(unsigned int domain, unsigned int bus, unsigned slot, unsigned int fun)); +int pcifront_conf_read(struct pcifront_dev *dev, + unsigned int dom, + unsigned int bus, unsigned int slot, unsigned long fun, + unsigned int off, unsigned int size, unsigned int *val); +int pcifront_conf_write(struct pcifront_dev *dev, + unsigned int dom, + unsigned int bus, unsigned int slot, unsigned long fun, + unsigned int off, unsigned int size, unsigned int val); +int pcifront_enable_msi(struct pcifront_dev *dev, + unsigned int dom, + unsigned int bus, unsigned int slot, unsigned long fun); +int pcifront_disable_msi(struct pcifront_dev *dev, + unsigned int dom, + unsigned int bus, unsigned int slot, unsigned long fun); +int pcifront_enable_msix(struct pcifront_dev *dev, + unsigned int dom, + unsigned int bus, unsigned int slot, unsigned long fun, + struct xen_msix_entry *entries, int n); +int pcifront_disable_msix(struct pcifront_dev *dev, + unsigned int dom, + unsigned int bus, unsigned int slot, unsigned long fun); +void shutdown_pcifront(struct pcifront_dev *dev); + +#endif /* _MINIOS_PCIFRONT_H_ */ diff --git a/xen/include/mini-os/queue.h b/xen/include/mini-os/queue.h new file mode 100644 index 0000000..bdf52af --- /dev/null +++ b/xen/include/mini-os/queue.h @@ -0,0 +1,74 @@ +#ifndef MINIOS_QUEUE_H__ +#define MINIOS_QUEUE_H__ + +#include + +#define MINIOS_SLIST_EMPTY SLIST_EMPTY +#define MINIOS_SLIST_ENTRY SLIST_ENTRY +#define MINIOS_SLIST_FIRST SLIST_FIRST +#define MINIOS_SLIST_FOREACH SLIST_FOREACH +#define MINIOS_SLIST_FOREACH_SAFE SLIST_FOREACH_SAFE +#define MINIOS_SLIST_HEAD SLIST_HEAD +#define MINIOS_SLIST_HEAD_INITIALIZER SLIST_HEAD_INITIALIZER +#define MINIOS_SLIST_INIT SLIST_INIT +#define MINIOS_SLIST_INSERT_AFTER SLIST_INSERT_AFTER +#define MINIOS_SLIST_INSERT_HEAD SLIST_INSERT_HEAD +#define MINIOS_SLIST_NEXT SLIST_NEXT +#define MINIOS_SLIST_REMOVE_AFTER SLIST_REMOVE_AFTER +#define MINIOS_SLIST_REMOVE_HEAD SLIST_REMOVE_HEAD +#define MINIOS_SLIST_REMOVE SLIST_REMOVE +#define MINIOS_SLIST_SWAP SLIST_SWAP +#define MINIOS_STAILQ_CONCAT STAILQ_CONCAT +#define MINIOS_STAILQ_EMPTY STAILQ_EMPTY +#define MINIOS_STAILQ_ENTRY STAILQ_ENTRY +#define MINIOS_STAILQ_FIRST STAILQ_FIRST +#define MINIOS_STAILQ_FOREACH STAILQ_FOREACH +#define MINIOS_STAILQ_FOREACH_SAFE STAILQ_FOREACH_SAFE +#define MINIOS_STAILQ_HEAD STAILQ_HEAD +#define MINIOS_STAILQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER +#define MINIOS_STAILQ_INIT STAILQ_INIT +#define MINIOS_STAILQ_INSERT_AFTER STAILQ_INSERT_AFTER +#define MINIOS_STAILQ_INSERT_HEAD STAILQ_INSERT_HEAD +#define MINIOS_STAILQ_INSERT_TAIL STAILQ_INSERT_TAIL +#define MINIOS_STAILQ_LAST STAILQ_LAST +#define MINIOS_STAILQ_NEXT STAILQ_NEXT +#define MINIOS_STAILQ_REMOVE_AFTER STAILQ_REMOVE_AFTER +#define MINIOS_STAILQ_REMOVE_HEAD STAILQ_REMOVE_HEAD +#define MINIOS_STAILQ_REMOVE STAILQ_REMOVE +#define MINIOS_STAILQ_SWAP STAILQ_SWAP +#define MINIOS_LIST_EMPTY LIST_EMPTY +#define MINIOS_LIST_ENTRY LIST_ENTRY +#define MINIOS_LIST_FIRST LIST_FIRST +#define MINIOS_LIST_FOREACH LIST_FOREACH +#define MINIOS_LIST_FOREACH_SAFE LIST_FOREACH_SAFE +#define MINIOS_LIST_HEAD LIST_HEAD +#define MINIOS_LIST_HEAD_INITIALIZER LIST_HEAD_INITIALIZER +#define MINIOS_LIST_INIT LIST_INIT +#define MINIOS_LIST_INSERT_AFTER LIST_INSERT_AFTER +#define MINIOS_LIST_INSERT_BEFORE LIST_INSERT_BEFORE +#define MINIOS_LIST_INSERT_HEAD LIST_INSERT_HEAD +#define MINIOS_LIST_NEXT LIST_NEXT +#define MINIOS_LIST_REMOVE LIST_REMOVE +#define MINIOS_LIST_SWAP LIST_SWAP +#define MINIOS_TAILQ_CONCAT TAILQ_CONCAT +#define MINIOS_TAILQ_EMPTY TAILQ_EMPTY +#define MINIOS_TAILQ_ENTRY TAILQ_ENTRY +#define MINIOS_TAILQ_FIRST TAILQ_FIRST +#define MINIOS_TAILQ_FOREACH TAILQ_FOREACH +#define MINIOS_TAILQ_FOREACH_SAFE TAILQ_FOREACH_SAFE +#define MINIOS_TAILQ_FOREACH_REVERSE TAILQ_FOREACH_REVERSE +#define MINIOS_TAILQ_FOREACH_REVERSE_SAFE TAILQ_FOREACH_REVERSE_SAFE +#define MINIOS_TAILQ_HEAD TAILQ_HEAD +#define MINIOS_TAILQ_HEAD_INITIALIZER TAILQ_HEAD_INITIALIZER +#define MINIOS_TAILQ_INIT TAILQ_INIT +#define MINIOS_TAILQ_INSERT_AFTER TAILQ_INSERT_AFTER +#define MINIOS_TAILQ_INSERT_BEFORE TAILQ_INSERT_BEFORE +#define MINIOS_TAILQ_INSERT_HEAD TAILQ_INSERT_HEAD +#define MINIOS_TAILQ_INSERT_TAIL TAILQ_INSERT_TAIL +#define MINIOS_TAILQ_LAST TAILQ_LAST +#define MINIOS_TAILQ_NEXT TAILQ_NEXT +#define MINIOS_TAILQ_PREV TAILQ_PREV +#define MINIOS_TAILQ_REMOVE TAILQ_REMOVE +#define MINIOS_TAILQ_SWAP TAILQ_SWAP + +#endif /* MINIOS_QUEUE_H__ */ diff --git a/xen/include/mini-os/sched.h b/xen/include/mini-os/sched.h new file mode 100644 index 0000000..3038364 --- /dev/null +++ b/xen/include/mini-os/sched.h @@ -0,0 +1,58 @@ +#ifndef __MINIOS_SCHED_H__ +#define __MINIOS_SCHED_H__ + +#include +#include + +#include + +struct thread { + const char *name; + char *stack; + size_t stack_size; + struct thread_md md; + TAILQ_ENTRY(thread) thread_list; + uint32_t flags; + s_time_t wakeup_time; + int threrrno; + void *lwp; + void *cookie; +}; + +extern struct thread *idle_thread; +void idle_thread_fn(void *unused); + +#define RUNNABLE_FLAG 0x00000001 +#define THREAD_MUSTJOIN 0x00000002 +#define THREAD_JOINED 0x00000004 +#define THREAD_EXTSTACK 0x00000008 +#define THREAD_TIMEDOUT 0x00000010 + +#define is_runnable(_thread) (_thread->flags & RUNNABLE_FLAG) +#define set_runnable(_thread) (_thread->flags |= RUNNABLE_FLAG) +#define clear_runnable(_thread) (_thread->flags &= ~RUNNABLE_FLAG) + +void switch_threads(struct thread *prev, struct thread *next); + + /* Architecture specific setup of thread creation. */ +struct thread* arch_create_thread(const char *name, void (*function)(void *), + void *data, void *stack); + +void init_sched(void); +void run_idle_thread(void); +struct thread* minios_create_thread(const char *name, void *cookie, + void (*f)(void *), void *data, void *stack); +void minios_exit_thread(void) __attribute__((noreturn)); +void minios_join_thread(struct thread *); +void minios_set_sched_hook(void (*hook)(void *, void *)); +struct thread *minios_init_mainlwp(void *cookie); +void minios_schedule(void); + +#define current get_current() + +void minios_wake(struct thread *thread); +void minios_block(struct thread *thread); +int minios_msleep(uint32_t millisecs); +int minios_absmsleep(uint32_t millisecs); + +#endif /* __MINIOS_SCHED_H__ */ diff --git a/xen/include/mini-os/semaphore.h b/xen/include/mini-os/semaphore.h new file mode 100644 index 0000000..9f2a37a --- /dev/null +++ b/xen/include/mini-os/semaphore.h @@ -0,0 +1,110 @@ +#ifndef _MINIOS_SEMAPHORE_H_ +#define _MINIOS_SEMAPHORE_H_ + +#include +#include + +/* + * Implementation of semaphore in Mini-os is simple, because + * there are no preemptive threads, the atomicity is guaranteed. + */ + +struct semaphore +{ + int count; + struct wait_queue_head wait; +}; + +/* + * the semaphore definition + */ +struct rw_semaphore { + signed long count; + spinlock_t wait_lock; + int debug; +}; + +#define __SEMAPHORE_INITIALIZER(name, n) \ +{ \ + .count = n, \ + .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \ +} + +#define __MUTEX_INITIALIZER(name) \ + __SEMAPHORE_INITIALIZER(name,1) + +#define __DECLARE_SEMAPHORE_GENERIC(name,count) \ + struct semaphore name = __SEMAPHORE_INITIALIZER(name,count) + +#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) + +#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0) + +static inline void init_SEMAPHORE(struct semaphore *sem, int count) +{ + sem->count = count; + minios_init_waitqueue_head(&sem->wait); +} + +#define init_MUTEX(sem) init_SEMAPHORE(sem, 1) + +static inline int trydown(struct semaphore *sem) +{ + unsigned long flags; + int ret = 0; + local_irq_save(flags); + if (sem->count > 0) { + ret = 1; + sem->count--; + } + local_irq_restore(flags); + return ret; +} + +static void inline down(struct semaphore *sem) +{ + unsigned long flags; + while (1) { + minios_wait_event(sem->wait, sem->count > 0); + local_irq_save(flags); + if (sem->count > 0) + break; + local_irq_restore(flags); + } + sem->count--; + local_irq_restore(flags); +} + +static void inline up(struct semaphore *sem) +{ + unsigned long flags; + local_irq_save(flags); + sem->count++; + minios_wake_up(&sem->wait); + local_irq_restore(flags); +} + +/* FIXME! Thre read/write semaphores are unimplemented! */ +static inline void init_rwsem(struct rw_semaphore *sem) +{ + sem->count = 1; +} + +static inline void down_read(struct rw_semaphore *sem) +{ +} + + +static inline void up_read(struct rw_semaphore *sem) +{ +} + +static inline void up_write(struct rw_semaphore *sem) +{ +} + +static inline void down_write(struct rw_semaphore *sem) +{ +} + +#endif /* _MINIOS_SEMAPHORE_H */ diff --git a/xen/include/mini-os/spinlock.h b/xen/include/mini-os/spinlock.h new file mode 100644 index 0000000..b87ffe5 --- /dev/null +++ b/xen/include/mini-os/spinlock.h @@ -0,0 +1,57 @@ +#ifndef __MINIOS_ASM_SPINLOCK_H +#define __MINIOS_ASM_SPINLOCK_H + +#ifndef __RUMP_KERNEL__ +#include +#endif + +/* + * Your basic SMP spinlocks, allowing only a single CPU anywhere + */ + +typedef struct { + volatile unsigned int slock; +} spinlock_t; + + +#include + + +#define SPINLOCK_MAGIC 0xdead4ead + +#define SPIN_LOCK_UNLOCKED ARCH_SPIN_LOCK_UNLOCKED + +#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0) + +/* + * Simple spin lock operations. There are two variants, one clears IRQ's + * on the local processor, one does not. + * + * We make no fairness assumptions. They have a cost. + */ + +#define spin_is_locked(x) arch_spin_is_locked(x) + +#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) + + +#define _spin_trylock(lock) ({_raw_spin_trylock(lock) ? \ + 1 : ({ 0;});}) + +#define _spin_lock(lock) \ +do { \ + _raw_spin_lock(lock); \ +} while(0) + +#define _spin_unlock(lock) \ +do { \ + _raw_spin_unlock(lock); \ +} while (0) + + +#define spin_lock(lock) _spin_lock(lock) +#define spin_unlock(lock) _spin_unlock(lock) + +#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED + +#endif diff --git a/xen/include/mini-os/time.h b/xen/include/mini-os/time.h new file mode 100644 index 0000000..00c90dc --- /dev/null +++ b/xen/include/mini-os/time.h @@ -0,0 +1,56 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + **************************************************************************** + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + * (C) 2005 - Grzegorz Milos - Intel Research Cambridge + **************************************************************************** + * + * File: time.h + * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) + * Changes: Grzegorz Milos (gm281@cam.ac.uk) + * Robert Kaiser (kaiser@informatik.fh-wiesbaden.de) + * + * Date: Jul 2003, changes: Jun 2005, Sep 2006 + * + * Environment: Xen Minimal OS + * Description: Time and timer functions + * + **************************************************************************** + */ + +#ifndef _MINIOS_TIME_H_ +#define _MINIOS_TIME_H_ +#include + +/* + * System Time + * 64 bit value containing the nanoseconds elapsed since boot time. + * This value is adjusted by frequency drift. + * NOW() returns the current time. + * The other macros are for convenience to approximate short intervals + * of real time into system time + */ +typedef int64_t s_time_t; +#define NOW() ((s_time_t)monotonic_clock()) +#define SECONDS(_s) (((s_time_t)(_s)) * 1000000000UL ) +#define TENTHS(_ts) (((s_time_t)(_ts)) * 100000000UL ) +#define HUNDREDTHS(_hs) (((s_time_t)(_hs)) * 10000000UL ) +#define MILLISECS(_ms) (((s_time_t)(_ms)) * 1000000UL ) +#define MICROSECS(_us) (((s_time_t)(_us)) * 1000UL ) +#define Time_Max ((s_time_t) 0x7fffffffffffffffLL) +#define FOREVER Time_Max +#define NSEC_TO_USEC(_nsec) ((_nsec) / 1000UL) +#define NSEC_TO_MSEC(_nsec) ((_nsec) / 1000000ULL) +#define NSEC_TO_SEC(_nsec) ((_nsec) / 1000000000ULL) + +#include + + +/* prototypes */ +void init_time(void); +void fini_time(void); +s_time_t get_s_time(void); +s_time_t get_v_time(void); +uint64_t monotonic_clock(void); +void block_domain(s_time_t until); + +#endif /* _MINIOS_TIME_H_ */ diff --git a/xen/include/mini-os/types.h b/xen/include/mini-os/types.h new file mode 100644 index 0000000..09b36df --- /dev/null +++ b/xen/include/mini-os/types.h @@ -0,0 +1,42 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + **************************************************************************** + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + **************************************************************************** + * + * File: types.h + * Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk) + * Changes: + * + * Date: May 2003 + * + * Environment: Xen Minimal OS + * Description: a random collection of type definitions + * + **************************************************************************** + * $Id: h-insert.h,v 1.4 2002/11/08 16:03:55 rn Exp $ + **************************************************************************** + */ + +#ifndef _MINIOS_TYPES_H_ +#define _MINIOS_TYPES_H_ + +#include +#include +#include + +#ifdef __i386__ +typedef struct { unsigned long pte_low, pte_high; } pte_t; + +#elif defined(__x86_64__) || defined(__ia64__) + +typedef struct { unsigned long pte; } pte_t; +#endif /* __i386__ || __x86_64__ */ + +#ifdef __x86_64__ +#define __pte(x) ((pte_t) { (x) } ) +#else +#define __pte(x) ({ unsigned long long _x = (x); \ + ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); }) +#endif + +#endif /* _MINIOS_TYPES_H_ */ diff --git a/xen/include/mini-os/wait.h b/xen/include/mini-os/wait.h new file mode 100644 index 0000000..aa1837a --- /dev/null +++ b/xen/include/mini-os/wait.h @@ -0,0 +1,107 @@ +#ifndef __MINIOS_WAIT_H__ +#define __MINIOS_WAIT_H__ + +#include +#include +#include + +#include + +#define DEFINE_WAIT(name) \ +struct wait_queue name = { \ + .thread = get_current(), \ + .waiting = 0, \ +} + + +static inline void minios_init_waitqueue_head(struct wait_queue_head *h) +{ + STAILQ_INIT(h); +} + +static inline void minios_init_waitqueue_entry(struct wait_queue *q, struct thread *thread) +{ + q->thread = thread; + q->waiting = 0; +} + +static inline void minios_add_wait_queue(struct wait_queue_head *h, struct wait_queue *q) +{ + if (!q->waiting) { + STAILQ_INSERT_HEAD(h, q, thread_list); + q->waiting = 1; + } +} + +static inline void minios_remove_wait_queue(struct wait_queue_head *h, struct wait_queue *q) +{ + if (q->waiting) { + STAILQ_REMOVE(h, q, wait_queue, thread_list); + q->waiting = 0; + } +} + +static inline void minios_wake_up(struct wait_queue_head *head) +{ + unsigned long flags; + struct wait_queue *curr, *tmp; + local_irq_save(flags); + STAILQ_FOREACH_SAFE(curr, head, thread_list, tmp) + minios_wake(curr->thread); + local_irq_restore(flags); +} + +#define minios_add_waiter(w, wq) do { \ + unsigned long flags; \ + local_irq_save(flags); \ + minios_add_wait_queue(&wq, &w); \ + minios_block(get_current()); \ + local_irq_restore(flags); \ +} while (0) + +#define minios_remove_waiter(w, wq) do { \ + unsigned long flags; \ + local_irq_save(flags); \ + minios_remove_wait_queue(&wq, &w); \ + local_irq_restore(flags); \ +} while (0) + +#define minios_wait_event_deadline(wq, condition, deadline) do { \ + unsigned long flags; \ + DEFINE_WAIT(__wait); \ + if(condition) \ + break; \ + for(;;) \ + { \ + /* protect the list */ \ + local_irq_save(flags); \ + minios_add_wait_queue(&wq, &__wait); \ + get_current()->wakeup_time = deadline; \ + clear_runnable(get_current()); \ + local_irq_restore(flags); \ + if((condition) || (deadline && NOW() >= deadline)) \ + break; \ + minios_schedule(); \ + } \ + local_irq_save(flags); \ + /* need to wake up */ \ + minios_wake(get_current()); \ + minios_remove_wait_queue(&wq, &__wait); \ + local_irq_restore(flags); \ +} while(0) + +#define minios_wait_event(wq, condition) minios_wait_event_deadline(wq, condition, 0) + + + +#endif /* __MINIOS_WAIT_H__ */ + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/mini-os/waittypes.h b/xen/include/mini-os/waittypes.h new file mode 100644 index 0000000..f433ca4 --- /dev/null +++ b/xen/include/mini-os/waittypes.h @@ -0,0 +1,32 @@ +#ifndef __MINIOS_WAITTYPE_H__ +#define __MINIOS_WAITTYPE_H__ + +#include + +struct thread; +struct wait_queue +{ + int waiting; + struct thread *thread; + STAILQ_ENTRY(wait_queue) thread_list; +}; + +/* TODO - lock required? */ +STAILQ_HEAD(wait_queue_head, wait_queue); + +#define DECLARE_WAIT_QUEUE_HEAD(name) \ + struct wait_queue_head name = STAILQ_HEAD_INITIALIZER(name) + +#define __WAIT_QUEUE_HEAD_INITIALIZER(name) STAILQ_HEAD_INITIALIZER(name) + +#endif + +/* + * Local variables: + * mode: C + * c-set-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/mini-os/x86/limits.h b/xen/include/mini-os/x86/limits.h new file mode 100644 index 0000000..41f8620 --- /dev/null +++ b/xen/include/mini-os/x86/limits.h @@ -0,0 +1,20 @@ + +#ifndef __ARCH_LIMITS_H__ +#define __ARCH_LIMITS_H__ + +#define __PAGE_SHIFT 12 + +#ifdef __ASSEMBLY__ +#define __PAGE_SIZE (1 << __PAGE_SHIFT) +#else +#ifdef __x86_64__ +#define __PAGE_SIZE (1UL << __PAGE_SHIFT) +#else +#define __PAGE_SIZE (1ULL << __PAGE_SHIFT) +#endif +#endif + +#define __STACK_SIZE_PAGE_ORDER 4 +#define __STACK_SIZE (__PAGE_SIZE * (1 << __STACK_SIZE_PAGE_ORDER)) + +#endif /* __ARCH_LIMITS_H__ */ diff --git a/xen/include/mini-os/x86/mm.h b/xen/include/mini-os/x86/mm.h new file mode 100644 index 0000000..0b5d308 --- /dev/null +++ b/xen/include/mini-os/x86/mm.h @@ -0,0 +1,238 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + * + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + * Copyright (c) 2005, Keir A Fraser + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef _ARCH_MM_H_ +#define _ARCH_MM_H_ + +#ifndef __ASSEMBLY__ +#include +#if defined(__i386__) +#include +#elif defined(__x86_64__) +#include +#else +#error "Unsupported architecture" +#endif +#endif + +#ifndef __RUMP_KERNEL__ + +#define L1_FRAME 1 +#define L2_FRAME 2 +#define L3_FRAME 3 + +#define L1_PAGETABLE_SHIFT 12 + +#if defined(__i386__) + +#define L2_PAGETABLE_SHIFT 21 +#define L3_PAGETABLE_SHIFT 30 + +#define L1_PAGETABLE_ENTRIES 512 +#define L2_PAGETABLE_ENTRIES 512 +#define L3_PAGETABLE_ENTRIES 4 + +#define PADDR_BITS 44 +#define PADDR_MASK ((1ULL << PADDR_BITS)-1) + +#define L2_MASK ((1UL << L3_PAGETABLE_SHIFT) - 1) + +/* + * If starting from virtual address greater than 0xc0000000, + * this value will be 2 to account for final mid-level page + * directory which is always mapped in at this location. + */ +#define NOT_L1_FRAMES 3 +#define PRIpte "016llx" +#ifndef __ASSEMBLY__ +typedef uint64_t pgentry_t; +#endif + +#elif defined(__x86_64__) + +#define L2_PAGETABLE_SHIFT 21 +#define L3_PAGETABLE_SHIFT 30 +#define L4_PAGETABLE_SHIFT 39 + +#define L1_PAGETABLE_ENTRIES 512 +#define L2_PAGETABLE_ENTRIES 512 +#define L3_PAGETABLE_ENTRIES 512 +#define L4_PAGETABLE_ENTRIES 512 + +/* These are page-table limitations. Current CPUs support only 40-bit phys. */ +#define PADDR_BITS 52 +#define VADDR_BITS 48 +#define PADDR_MASK ((1UL << PADDR_BITS)-1) +#define VADDR_MASK ((1UL << VADDR_BITS)-1) + +#define L2_MASK ((1UL << L3_PAGETABLE_SHIFT) - 1) +#define L3_MASK ((1UL << L4_PAGETABLE_SHIFT) - 1) + +#define NOT_L1_FRAMES 3 +#define PRIpte "016lx" +#ifndef __ASSEMBLY__ +typedef unsigned long pgentry_t; +#endif + +#endif + +#define L1_MASK ((1UL << L2_PAGETABLE_SHIFT) - 1) + +/* Given a virtual address, get an entry offset into a page table. */ +#define l1_table_offset(_a) \ + (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1)) +#define l2_table_offset(_a) \ + (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1)) +#define l3_table_offset(_a) \ + (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1)) +#if defined(__x86_64__) +#define l4_table_offset(_a) \ + (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1)) +#endif + +#define _PAGE_PRESENT 0x001ULL +#define _PAGE_RW 0x002ULL +#define _PAGE_USER 0x004ULL +#define _PAGE_PWT 0x008ULL +#define _PAGE_PCD 0x010ULL +#define _PAGE_ACCESSED 0x020ULL +#define _PAGE_DIRTY 0x040ULL +#define _PAGE_PAT 0x080ULL +#define _PAGE_PSE 0x080ULL +#define _PAGE_GLOBAL 0x100ULL + +#if defined(__i386__) +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) +#define L1_PROT_RO (_PAGE_PRESENT|_PAGE_ACCESSED) +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY |_PAGE_USER) +#define L3_PROT (_PAGE_PRESENT) +#elif defined(__x86_64__) +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER) +#define L1_PROT_RO (_PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_USER) +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) +#define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) +#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) +#endif /* __i386__ || __x86_64__ */ + +/* flags for ioremap */ +#define IO_PROT (L1_PROT) +#define IO_PROT_NOCACHE (L1_PROT | _PAGE_PCD) + +/* for P2M */ +#define INVALID_P2M_ENTRY (~0UL) + +#include +#define PAGE_SIZE __PAGE_SIZE +#define PAGE_SHIFT __PAGE_SHIFT +#define PAGE_MASK (~(PAGE_SIZE-1)) + +#define PFN_UP(x) (((x) + PAGE_SIZE-1) >> L1_PAGETABLE_SHIFT) +#define PFN_DOWN(x) ((x) >> L1_PAGETABLE_SHIFT) +#define PFN_PHYS(x) ((uint64_t)(x) << L1_PAGETABLE_SHIFT) +#define PHYS_PFN(x) ((x) >> L1_PAGETABLE_SHIFT) + +/* to align the pointer to the (next) page boundary */ +#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) + +#ifndef __ASSEMBLY__ +/* Definitions for machine and pseudophysical addresses. */ +#ifdef __i386__ +typedef unsigned long long paddr_t; +typedef unsigned long long maddr_t; +#else +typedef unsigned long paddr_t; +typedef unsigned long maddr_t; +#endif + +extern unsigned long *_minios_phys_to_machine_mapping; +extern char _text, _etext, _erodata, _edata, _end; +extern unsigned long _minios_mfn_zero; +#define pfn_to_mfn(_pfn) (_minios_phys_to_machine_mapping[(_pfn)]) +static __inline__ maddr_t phys_to_machine(paddr_t phys) +{ + maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT); + machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK); + return machine; +} + +#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)]) +static __inline__ paddr_t machine_to_phys(maddr_t machine) +{ + paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT); + phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK); + return phys; +} +#endif + +#define VIRT_START ((unsigned long)&_text) + +#define to_phys(x) ((unsigned long)(x)-VIRT_START) +#define to_virt(x) ((void *)((unsigned long)(x)+VIRT_START)) + +#define virt_to_pfn(_virt) (PFN_DOWN(to_phys(_virt))) +#define virt_to_mfn(_virt) (pfn_to_mfn(virt_to_pfn(_virt))) +#define mach_to_virt(_mach) (to_virt(machine_to_phys(_mach))) +#define virt_to_mach(_virt) (phys_to_machine(to_phys(_virt))) +#define mfn_to_virt(_mfn) (to_virt(mfn_to_pfn(_mfn) << PAGE_SHIFT)) +#define pfn_to_virt(_pfn) (to_virt((_pfn) << PAGE_SHIFT)) + +/* Pagetable walking. */ +#define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT) +#define pte_to_virt(_pte) to_virt(mfn_to_pfn(pte_to_mfn(_pte)) << PAGE_SHIFT) + + +#define PT_BASE ((pgentry_t *)start_info.pt_base) + +#ifdef __x86_64__ +#define virtual_to_l3(_virt) ((pgentry_t *)pte_to_virt(PT_BASE[l4_table_offset(_virt)])) +#else +#define virtual_to_l3(_virt) PT_BASE +#endif + +#define virtual_to_l2(_virt) ({ \ + unsigned long __virt2 = (_virt); \ + (pgentry_t *) pte_to_virt(virtual_to_l3(__virt2)[l3_table_offset(__virt2)]); \ +}) + +#define virtual_to_l1(_virt) ({ \ + unsigned long __virt1 = (_virt); \ + (pgentry_t *) pte_to_virt(virtual_to_l2(__virt1)[l2_table_offset(__virt1)]); \ +}) + +#define virtual_to_pte(_virt) ({ \ + unsigned long __virt0 = (unsigned long) (_virt); \ + virtual_to_l1(__virt0)[l1_table_offset(__virt0)]; \ +}) +#define virtual_to_mfn(_virt) pte_to_mfn(virtual_to_pte(_virt)) + +#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, L1_PROT) +#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, NULL, L1_PROT_RO) +#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, NULL, L1_PROT_RO) + +pgentry_t *need_pgt(unsigned long addr); +int mfn_is_ram(unsigned long mfn); + +#endif /* !__RUMP_KERNEL__ */ + +#endif /* _ARCH_MM_H_ */ diff --git a/xen/include/mini-os/x86/os.h b/xen/include/mini-os/x86/os.h new file mode 100644 index 0000000..a9429d9 --- /dev/null +++ b/xen/include/mini-os/x86/os.h @@ -0,0 +1,549 @@ +/****************************************************************************** + * os.h + * + * random collection of macros and definition + */ + +#ifndef _MINIOS_X86_OS_H_ +#define _MINIOS_X86_OS_H_ + +#include + +#define __KERNEL_CS FLAT_KERNEL_CS +#define __KERNEL_DS FLAT_KERNEL_DS +#define __KERNEL_SS FLAT_KERNEL_SS + +#define TRAP_divide_error 0 +#define TRAP_debug 1 +#define TRAP_nmi 2 +#define TRAP_int3 3 +#define TRAP_overflow 4 +#define TRAP_bounds 5 +#define TRAP_invalid_op 6 +#define TRAP_no_device 7 +#define TRAP_double_fault 8 +#define TRAP_copro_seg 9 +#define TRAP_invalid_tss 10 +#define TRAP_no_segment 11 +#define TRAP_stack_error 12 +#define TRAP_gp_fault 13 +#define TRAP_page_fault 14 +#define TRAP_spurious_int 15 +#define TRAP_copro_error 16 +#define TRAP_alignment_check 17 +#define TRAP_machine_check 18 +#define TRAP_simd_error 19 +#define TRAP_deferred_nmi 31 + +/* Everything below this point is not included by assembler (.S) files. */ +#ifndef __ASSEMBLY__ + +extern shared_info_t *HYPERVISOR_shared_info; + +void trap_init(void); +void trap_fini(void); + +void arch_init(start_info_t *si); +void arch_print_info(void); +void arch_fini(void); + + + + + +/* + * The use of 'barrier' in the following reflects their use as local-lock + * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following + * critical operations are executed. All critical operations must complete + * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also + * includes these barriers, for example. + */ + +#define __cli() \ +do { \ + vcpu_info_t *_vcpu; \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + _vcpu->evtchn_upcall_mask = 1; \ + barrier(); \ +} while (0) + +#define __sti() \ +do { \ + vcpu_info_t *_vcpu; \ + barrier(); \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + _vcpu->evtchn_upcall_mask = 0; \ + barrier(); /* unmask then check (avoid races) */ \ + if ( unlikely(_vcpu->evtchn_upcall_pending) ) \ + minios_force_evtchn_callback(); \ +} while (0) + +#define __save_flags(x) \ +do { \ + vcpu_info_t *_vcpu; \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + (x) = _vcpu->evtchn_upcall_mask; \ +} while (0) + +#define __restore_flags(x) \ +do { \ + vcpu_info_t *_vcpu; \ + barrier(); \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + if ((_vcpu->evtchn_upcall_mask = (x)) == 0) { \ + barrier(); /* unmask then check (avoid races) */ \ + if ( unlikely(_vcpu->evtchn_upcall_pending) ) \ + minios_force_evtchn_callback(); \ + }\ +} while (0) + +#define safe_halt() ((void)0) + +#define __save_and_cli(x) \ +do { \ + vcpu_info_t *_vcpu; \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + (x) = _vcpu->evtchn_upcall_mask; \ + _vcpu->evtchn_upcall_mask = 1; \ + barrier(); \ +} while (0) + +#define local_irq_save(x) __save_and_cli(x) +#define local_irq_restore(x) __restore_flags(x) +#define local_save_flags(x) __save_flags(x) +#define local_irq_disable() __cli() +#define local_irq_enable() __sti() + +#define irqs_disabled() \ + HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask + +/* This is a barrier for the compiler only, NOT the processor! */ +#define barrier() __asm__ __volatile__("": : :"memory") + +#if defined(__i386__) +#define mb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") +#define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") +#define wmb() __asm__ __volatile__ ("": : :"memory") +#elif defined(__x86_64__) +#define mb() __asm__ __volatile__ ("mfence":::"memory") +#define rmb() __asm__ __volatile__ ("lfence":::"memory") +#define wmb() __asm__ __volatile__ ("sfence" ::: "memory") /* From CONFIG_UNORDERED_IO (linux) */ +#endif + + +#define LOCK_PREFIX "" +#define LOCK "" +#define ADDR (*(volatile long *) addr) +/* + * Make sure gcc doesn't try to be clever and move things around + * on us. We need to use _exactly_ the address the user gave us, + * not some alias that contains the same information. + */ +typedef struct { volatile int counter; } atomic_t; + + +/************************** i386 *******************************/ +#if defined (__i386__) + +#define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr)))) +struct __xchg_dummy { unsigned long a[100]; }; +#define __xg(x) ((struct __xchg_dummy *)(x)) +static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) +{ + switch (size) { + case 1: + __asm__ __volatile__("xchgb %b0,%1" + :"=q" (x) + :"m" (*__xg(ptr)), "0" (x) + :"memory"); + break; + case 2: + __asm__ __volatile__("xchgw %w0,%1" + :"=r" (x) + :"m" (*__xg(ptr)), "0" (x) + :"memory"); + break; + case 4: + __asm__ __volatile__("xchgl %0,%1" + :"=r" (x) + :"m" (*__xg(ptr)), "0" (x) + :"memory"); + break; + } + return x; +} + +/** + * test_and_clear_bit - Clear a bit and return its old value + * @nr: Bit to clear + * @addr: Address to count from + * + * This operation is atomic and cannot be reordered. + * It can be reorderdered on other architectures other than x86. + * It also implies a memory barrier. + */ +static inline int test_and_clear_bit(int nr, volatile unsigned long * addr) +{ + int oldbit; + + __asm__ __volatile__( LOCK + "btrl %2,%1\n\tsbbl %0,%0" + :"=r" (oldbit),"=m" (ADDR) + :"Ir" (nr) : "memory"); + return oldbit; +} + +static inline int constant_test_bit(int nr, const volatile unsigned long *addr) +{ + return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0; +} + +static inline int variable_test_bit(int nr, const volatile unsigned long * addr) +{ + int oldbit; + + __asm__ __volatile__( + "btl %2,%1\n\tsbbl %0,%0" + :"=r" (oldbit) + :"m" (ADDR),"Ir" (nr)); + return oldbit; +} + +#define test_bit(nr,addr) \ +(__builtin_constant_p(nr) ? \ + constant_test_bit((nr),(addr)) : \ + variable_test_bit((nr),(addr))) + +/** + * set_bit - Atomically set a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + * + * This function is atomic and may not be reordered. See __set_bit() + * if you do not require the atomic guarantees. + * + * Note: there are no guarantees that this function will not be reordered + * on non x86 architectures, so if you are writting portable code, + * make sure not to rely on its reordering guarantees. + * + * Note that @nr may be almost arbitrarily large; this function is not + * restricted to acting on a single-word quantity. + */ +static inline void set_bit(int nr, volatile unsigned long * addr) +{ + __asm__ __volatile__( LOCK + "btsl %1,%0" + :"=m" (ADDR) + :"Ir" (nr)); +} + +/** + * clear_bit - Clears a bit in memory + * @nr: Bit to clear + * @addr: Address to start counting from + * + * clear_bit() is atomic and may not be reordered. However, it does + * not contain a memory barrier, so if it is used for locking purposes, + * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit() + * in order to ensure changes are visible on other processors. + */ +static inline void clear_bit(int nr, volatile unsigned long * addr) +{ + __asm__ __volatile__( LOCK + "btrl %1,%0" + :"=m" (ADDR) + :"Ir" (nr)); +} + +/** + * __ffs - find first bit in word. + * @word: The word to search + * + * Undefined if no bit exists, so code should check against 0 first. + */ +static inline unsigned long __ffs(unsigned long word) +{ + __asm__("bsfl %1,%0" + :"=r" (word) + :"rm" (word)); + return word; +} + + +/* + * These have to be done with inline assembly: that way the bit-setting + * is guaranteed to be atomic. All bit operations return 0 if the bit + * was cleared before the operation and != 0 if it was not. + * + * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). + */ +#define ADDR (*(volatile long *) addr) + +#define rdtscll(val) \ + __asm__ __volatile__("rdtsc" : "=A" (val)) + + + +#elif defined(__x86_64__)/* ifdef __i386__ */ +/************************** x86_84 *******************************/ + +#define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr)))) +#define __xg(x) ((volatile long *)(x)) +static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size) +{ + switch (size) { + case 1: + __asm__ __volatile__("xchgb %b0,%1" + :"=q" (x) + :"m" (*__xg(ptr)), "0" (x) + :"memory"); + break; + case 2: + __asm__ __volatile__("xchgw %w0,%1" + :"=r" (x) + :"m" (*__xg(ptr)), "0" (x) + :"memory"); + break; + case 4: + __asm__ __volatile__("xchgl %k0,%1" + :"=r" (x) + :"m" (*__xg(ptr)), "0" (x) + :"memory"); + break; + case 8: + __asm__ __volatile__("xchgq %0,%1" + :"=r" (x) + :"m" (*__xg(ptr)), "0" (x) + :"memory"); + break; + } + return x; +} + +/** + * test_and_clear_bit - Clear a bit and return its old value + * @nr: Bit to clear + * @addr: Address to count from + * + * This operation is atomic and cannot be reordered. + * It also implies a memory barrier. + */ +static __inline__ int test_and_clear_bit(int nr, volatile void * addr) +{ + int oldbit; + + __asm__ __volatile__( LOCK_PREFIX + "btrl %2,%1\n\tsbbl %0,%0" + :"=r" (oldbit),"=m" (ADDR) + :"dIr" (nr) : "memory"); + return oldbit; +} + +static __inline__ int constant_test_bit(int nr, const volatile void * addr) +{ + return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0; +} + +static __inline__ int variable_test_bit(int nr, volatile const void * addr) +{ + int oldbit; + + __asm__ __volatile__( + "btl %2,%1\n\tsbbl %0,%0" + :"=r" (oldbit) + :"m" (ADDR),"dIr" (nr)); + return oldbit; +} + +#define test_bit(nr,addr) \ +(__builtin_constant_p(nr) ? \ + constant_test_bit((nr),(addr)) : \ + variable_test_bit((nr),(addr))) + + +/** + * set_bit - Atomically set a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + * + * This function is atomic and may not be reordered. See __set_bit() + * if you do not require the atomic guarantees. + * Note that @nr may be almost arbitrarily large; this function is not + * restricted to acting on a single-word quantity. + */ +static __inline__ void set_bit(int nr, volatile void * addr) +{ + __asm__ __volatile__( LOCK_PREFIX + "btsl %1,%0" + :"=m" (ADDR) + :"dIr" (nr) : "memory"); +} + +/** + * clear_bit - Clears a bit in memory + * @nr: Bit to clear + * @addr: Address to start counting from + * + * clear_bit() is atomic and may not be reordered. However, it does + * not contain a memory barrier, so if it is used for locking purposes, + * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit() + * in order to ensure changes are visible on other processors. + */ +static __inline__ void clear_bit(int nr, volatile void * addr) +{ + __asm__ __volatile__( LOCK_PREFIX + "btrl %1,%0" + :"=m" (ADDR) + :"dIr" (nr)); +} + +/** + * __ffs - find first bit in word. + * @word: The word to search + * + * Undefined if no bit exists, so code should check against 0 first. + */ +static __inline__ unsigned long __ffs(unsigned long word) +{ + __asm__("bsfq %1,%0" + :"=r" (word) + :"rm" (word)); + return word; +} + +#define ADDR (*(volatile long *) addr) + +#define rdtscll(val) do { \ + unsigned int __a,__d; \ + asm volatile("rdtsc" : "=a" (__a), "=d" (__d)); \ + (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \ +} while(0) + +#define wrmsr(msr,val1,val2) \ + __asm__ __volatile__("wrmsr" \ + : /* no outputs */ \ + : "c" (msr), "a" (val1), "d" (val2)) + +#define wrmsrl(msr,val) wrmsr(msr,(uint32_t)((uint64_t)(val)),((uint64_t)(val))>>32) + + +#else /* ifdef __x86_64__ */ +#error "Unsupported architecture" +#endif + +/********************* common i386 and x86_64 ****************************/ +struct __synch_xchg_dummy { unsigned long a[100]; }; +#define __synch_xg(x) ((struct __synch_xchg_dummy *)(x)) + +#define synch_cmpxchg(ptr, old, new) \ +((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\ + (unsigned long)(old), \ + (unsigned long)(new), \ + sizeof(*(ptr)))) + +static inline unsigned long __synch_cmpxchg(volatile void *ptr, + unsigned long old, + unsigned long new, int size) +{ + unsigned long prev; + switch (size) { + case 1: + __asm__ __volatile__("lock; cmpxchgb %b1,%2" + : "=a"(prev) + : "q"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + case 2: + __asm__ __volatile__("lock; cmpxchgw %w1,%2" + : "=a"(prev) + : "r"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; +#ifdef __x86_64__ + case 4: + __asm__ __volatile__("lock; cmpxchgl %k1,%2" + : "=a"(prev) + : "r"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; + case 8: + __asm__ __volatile__("lock; cmpxchgq %1,%2" + : "=a"(prev) + : "r"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; +#else + case 4: + __asm__ __volatile__("lock; cmpxchgl %1,%2" + : "=a"(prev) + : "r"(new), "m"(*__synch_xg(ptr)), + "0"(old) + : "memory"); + return prev; +#endif + } + return old; +} + + +static __inline__ void synch_set_bit(int nr, volatile void * addr) +{ + __asm__ __volatile__ ( + "lock btsl %1,%0" + : "=m" (ADDR) : "Ir" (nr) : "memory" ); +} + +static __inline__ void synch_clear_bit(int nr, volatile void * addr) +{ + __asm__ __volatile__ ( + "lock btrl %1,%0" + : "=m" (ADDR) : "Ir" (nr) : "memory" ); +} + +static __inline__ int synch_test_and_set_bit(int nr, volatile void * addr) +{ + int oldbit; + __asm__ __volatile__ ( + "lock btsl %2,%1\n\tsbbl %0,%0" + : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory"); + return oldbit; +} + +static __inline__ int synch_test_and_clear_bit(int nr, volatile void * addr) +{ + int oldbit; + __asm__ __volatile__ ( + "lock btrl %2,%1\n\tsbbl %0,%0" + : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory"); + return oldbit; +} + +static __inline__ int synch_const_test_bit(int nr, const volatile void * addr) +{ + return ((1UL << (nr & 31)) & + (((const volatile unsigned int *) addr)[nr >> 5])) != 0; +} + +static __inline__ int synch_var_test_bit(int nr, volatile void * addr) +{ + int oldbit; + __asm__ __volatile__ ( + "btl %2,%1\n\tsbbl %0,%0" + : "=r" (oldbit) : "m" (ADDR), "Ir" (nr) ); + return oldbit; +} + +#define synch_test_bit(nr,addr) \ +(__builtin_constant_p(nr) ? \ + synch_const_test_bit((nr),(addr)) : \ + synch_var_test_bit((nr),(addr))) + + +#undef ADDR + +#endif /* not assembly */ +#endif /* _MINIOS_X86_OS_H_ */ diff --git a/xen/include/mini-os/x86/sched.h b/xen/include/mini-os/x86/sched.h new file mode 100644 index 0000000..be9b5c4 --- /dev/null +++ b/xen/include/mini-os/x86/sched.h @@ -0,0 +1,30 @@ + +#ifndef __ARCH_SCHED_H__ +#define __ARCH_SCHED_H__ + +#include + +static inline struct thread* get_current(void) +{ + struct thread **current; +#ifdef __i386__ + register unsigned long sp asm("esp"); +#else + register unsigned long sp asm("rsp"); +#endif + current = (void *)(unsigned long)(sp & ~(__STACK_SIZE-1)); + return *current; +}; + +struct thread_md { + unsigned long thrmd_sp; + unsigned long thrmd_ip; +}; +#define thr_sp md.thrmd_sp +#define thr_ip md.thrmd_ip + +extern void _minios_entry_arch_switch_threads(unsigned long *prevctx, unsigned long *nextctx); + +#define arch_switch_threads(prev,next) _minios_entry_arch_switch_threads(&(prev)->thr_sp, &(next)->thr_sp) + +#endif /* __ARCH_SCHED_H__ */ diff --git a/xen/include/mini-os/x86/spinlock.h b/xen/include/mini-os/x86/spinlock.h new file mode 100644 index 0000000..b22f2a4 --- /dev/null +++ b/xen/include/mini-os/x86/spinlock.h @@ -0,0 +1,97 @@ + + +#ifndef __ARCH_ASM_SPINLOCK_H +#define __ARCH_ASM_SPINLOCK_H + +#ifndef __RUMP_KERNEL__ +#include +#endif + +#include "os.h" + + +#define ARCH_SPIN_LOCK_UNLOCKED { 1 } + +/* + * Simple spin lock operations. There are two variants, one clears IRQ's + * on the local processor, one does not. + * + * We make no fairness assumptions. They have a cost. + */ + +#define arch_spin_is_locked(x) (*(volatile signed char *)(&(x)->slock) <= 0) +#define spin_unlock_wait(x) do { barrier(); } while(spin_is_locked(x)) + +#define spin_lock_string \ + "1:\n" \ + LOCK \ + "decb %0\n\t" \ + "jns 3f\n" \ + "2:\t" \ + "rep;nop\n\t" \ + "cmpb $0,%0\n\t" \ + "jle 2b\n\t" \ + "jmp 1b\n" \ + "3:\n\t" + +#define spin_lock_string_flags \ + "1:\n" \ + LOCK \ + "decb %0\n\t" \ + "jns 4f\n\t" \ + "2:\t" \ + "testl $0x200, %1\n\t" \ + "jz 3f\n\t" \ + "#sti\n\t" \ + "3:\t" \ + "rep;nop\n\t" \ + "cmpb $0, %0\n\t" \ + "jle 3b\n\t" \ + "#cli\n\t" \ + "jmp 1b\n" \ + "4:\n\t" + +/* + * This works. Despite all the confusion. + * (except on PPro SMP or if we are using OOSTORE) + * (PPro errata 66, 92) + */ + +#define spin_unlock_string \ + "xchgb %b0, %1" \ + :"=q" (oldval), "=m" (lock->slock) \ + :"0" (oldval) : "memory" + +static inline void _raw_spin_unlock(spinlock_t *lock) +{ + char oldval = 1; + __asm__ __volatile__( + spin_unlock_string + ); +} + +static inline int _raw_spin_trylock(spinlock_t *lock) +{ + char oldval; + __asm__ __volatile__( + "xchgb %b0,%1\n" + :"=q" (oldval), "=m" (lock->slock) + :"0" (0) : "memory"); + return oldval > 0; +} + +static inline void _raw_spin_lock(spinlock_t *lock) +{ + __asm__ __volatile__( + spin_lock_string + :"=m" (lock->slock) : : "memory"); +} + +static inline void _raw_spin_lock_flags (spinlock_t *lock, unsigned long flags) +{ + __asm__ __volatile__( + spin_lock_string_flags + :"=m" (lock->slock) : "r" (flags) : "memory"); +} + +#endif diff --git a/xen/include/mini-os/x86/traps.h b/xen/include/mini-os/x86/traps.h new file mode 100644 index 0000000..bfb6781 --- /dev/null +++ b/xen/include/mini-os/x86/traps.h @@ -0,0 +1,78 @@ +/* + **************************************************************************** + * (C) 2005 - Grzegorz Milos - Intel Reseach Cambridge + **************************************************************************** + * + * File: traps.h + * Author: Grzegorz Milos (gm281@cam.ac.uk) + * + * Date: Jun 2005 + * + * Environment: Xen Minimal OS + * Description: Deals with traps + * + **************************************************************************** + */ + +#ifndef _TRAPS_H_ +#define _TRAPS_H_ + +#ifdef __i386__ +struct pt_regs { + long ebx; + long ecx; + long edx; + long esi; + long edi; + long ebp; + long eax; + int xds; + int xes; + long orig_eax; + long eip; + int xcs; + long eflags; + long esp; + int xss; +}; +#elif __x86_64__ + +struct pt_regs { + unsigned long r15; + unsigned long r14; + unsigned long r13; + unsigned long r12; + unsigned long rbp; + unsigned long rbx; +/* arguments: non interrupts/non tracing syscalls only save upto here*/ + unsigned long r11; + unsigned long r10; + unsigned long r9; + unsigned long r8; + unsigned long rax; + unsigned long rcx; + unsigned long rdx; + unsigned long rsi; + unsigned long rdi; + unsigned long orig_rax; +/* end of arguments */ +/* cpu exception frame or undefined */ + unsigned long rip; + unsigned long cs; + unsigned long eflags; + unsigned long rsp; + unsigned long ss; +/* top of stack page */ +}; + + +#endif + +void dump_regs(struct pt_regs *regs); +void stack_walk(void); + +#define TRAP_PF_PROT 0x1 +#define TRAP_PF_WRITE 0x2 +#define TRAP_PF_USER 0x4 + +#endif /* _TRAPS_H_ */ diff --git a/xen/include/mini-os/x86/x86_32/hypercall-x86_32.h b/xen/include/mini-os/x86/x86_32/hypercall-x86_32.h new file mode 100644 index 0000000..789a834 --- /dev/null +++ b/xen/include/mini-os/x86/x86_32/hypercall-x86_32.h @@ -0,0 +1,324 @@ +/****************************************************************************** + * hypercall-x86_32.h + * + * Copied from XenLinux. + * + * Copyright (c) 2002-2004, K A Fraser + * + * This file may be distributed separately from the Linux kernel, or + * incorporated into other software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef __HYPERCALL_X86_32_H__ +#define __HYPERCALL_X86_32_H__ + +#include +#include +#include +#include + +#define __STR(x) #x +#define STR(x) __STR(x) + +extern char _minios_hypercall_page[PAGE_SIZE]; + +#define _hypercall0(type, name) \ +({ \ + long __res; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res) \ + : \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall1(type, name, a1) \ +({ \ + long __res, __ign1; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=b" (__ign1) \ + : "1" ((long)(a1)) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall2(type, name, a1, a2) \ +({ \ + long __res, __ign1, __ign2; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ + : "1" ((long)(a1)), "2" ((long)(a2)) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall3(type, name, a1, a2, a3) \ +({ \ + long __res, __ign1, __ign2, __ign3; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall4(type, name, a1, a2, a3, a4) \ +({ \ + long __res, __ign1, __ign2, __ign3, __ign4; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3), "=S" (__ign4) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "4" ((long)(a4)) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ +({ \ + long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ + "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "4" ((long)(a4)), \ + "5" ((long)(a5)) \ + : "memory" ); \ + (type)__res; \ +}) + +static inline int +HYPERVISOR_set_trap_table( + trap_info_t *table) +{ + return _hypercall1(int, set_trap_table, table); +} + +static inline int +HYPERVISOR_mmu_update( + mmu_update_t *req, int count, int *success_count, domid_t domid) +{ + return _hypercall4(int, mmu_update, req, count, success_count, domid); +} + +static inline int +HYPERVISOR_mmuext_op( + struct mmuext_op *op, int count, int *success_count, domid_t domid) +{ + return _hypercall4(int, mmuext_op, op, count, success_count, domid); +} + +static inline int +HYPERVISOR_set_gdt( + unsigned long *frame_list, int entries) +{ + return _hypercall2(int, set_gdt, frame_list, entries); +} + +static inline int +HYPERVISOR_stack_switch( + unsigned long ss, unsigned long esp) +{ + return _hypercall2(int, stack_switch, ss, esp); +} + +static inline int +HYPERVISOR_set_callbacks( + unsigned long event_selector, unsigned long event_address, + unsigned long failsafe_selector, unsigned long failsafe_address) +{ + return _hypercall4(int, set_callbacks, + event_selector, event_address, + failsafe_selector, failsafe_address); +} + +static inline int +HYPERVISOR_fpu_taskswitch( + int set) +{ + return _hypercall1(int, fpu_taskswitch, set); +} + +static inline int +HYPERVISOR_sched_op( + int cmd, void *arg) +{ + return _hypercall2(int, sched_op, cmd, arg); +} + +static inline long +HYPERVISOR_set_timer_op( + uint64_t timeout) +{ + unsigned long timeout_hi = (unsigned long)(timeout>>32); + unsigned long timeout_lo = (unsigned long)timeout; + return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi); +} + +static inline int +HYPERVISOR_set_debugreg( + int reg, unsigned long value) +{ + return _hypercall2(int, set_debugreg, reg, value); +} + +static inline unsigned long +HYPERVISOR_get_debugreg( + int reg) +{ + return _hypercall1(unsigned long, get_debugreg, reg); +} + +static inline int +HYPERVISOR_update_descriptor( + uint64_t ma, uint64_t desc) +{ + return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32); +} + +static inline int +HYPERVISOR_memory_op( + unsigned int cmd, void *arg) +{ + return _hypercall2(int, memory_op, cmd, arg); +} + +static inline int +HYPERVISOR_multicall( + void *call_list, int nr_calls) +{ + return _hypercall2(int, multicall, call_list, nr_calls); +} + +static inline int +HYPERVISOR_update_va_mapping( + unsigned long va, pte_t new_val, unsigned long flags) +{ + return _hypercall4(int, update_va_mapping, va, + new_val.pte_low, new_val.pte_high, flags); +} + +static inline int +HYPERVISOR_event_channel_op( + int cmd, void *op) +{ + return _hypercall2(int, event_channel_op, cmd, op); +} + +static inline int +HYPERVISOR_xen_version( + int cmd, void *arg) +{ + return _hypercall2(int, xen_version, cmd, arg); +} + +static inline int +HYPERVISOR_console_io( + int cmd, int count, char *str) +{ + return _hypercall3(int, console_io, cmd, count, str); +} + +static inline int +HYPERVISOR_physdev_op( + void *physdev_op) +{ + return _hypercall1(int, physdev_op, physdev_op); +} + +static inline int +HYPERVISOR_grant_table_op( + unsigned int cmd, void *uop, unsigned int count) +{ + return _hypercall3(int, grant_table_op, cmd, uop, count); +} + +static inline int +HYPERVISOR_update_va_mapping_otherdomain( + unsigned long va, pte_t new_val, unsigned long flags, domid_t domid) +{ + return _hypercall5(int, update_va_mapping_otherdomain, va, + new_val.pte_low, new_val.pte_high, flags, domid); +} + +static inline int +HYPERVISOR_vm_assist( + unsigned int cmd, unsigned int type) +{ + return _hypercall2(int, vm_assist, cmd, type); +} + +static inline int +HYPERVISOR_vcpu_op( + int cmd, int vcpuid, void *extra_args) +{ + return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); +} + +static inline int +HYPERVISOR_suspend( + unsigned long srec) +{ + return _hypercall3(int, sched_op, SCHEDOP_shutdown, + SHUTDOWN_suspend, srec); +} + +static inline int +HYPERVISOR_nmi_op( + unsigned long op, + unsigned long arg) +{ + return _hypercall2(int, nmi_op, op, arg); +} + +static inline int +HYPERVISOR_sysctl( + unsigned long op) +{ + return _hypercall1(int, sysctl, op); +} + +static inline int +HYPERVISOR_domctl( + unsigned long op) +{ + return _hypercall1(int, domctl, op); +} + +#endif /* __HYPERCALL_X86_32_H__ */ + +/* + * Local variables: + * c-file-style: "linux" + * indent-tabs-mode: t + * c-indent-level: 8 + * c-basic-offset: 8 + * tab-width: 8 + * End: + */ diff --git a/xen/include/mini-os/x86/x86_64/hypercall-x86_64.h b/xen/include/mini-os/x86/x86_64/hypercall-x86_64.h new file mode 100644 index 0000000..27d008e --- /dev/null +++ b/xen/include/mini-os/x86/x86_64/hypercall-x86_64.h @@ -0,0 +1,332 @@ +/****************************************************************************** + * hypercall-x86_64.h + * + * Copied from XenLinux. + * + * Copyright (c) 2002-2004, K A Fraser + * + * 64-bit updates: + * Benjamin Liu + * Jun Nakajima + * + * This file may be distributed separately from the Linux kernel, or + * incorporated into other software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef __HYPERCALL_X86_64_H__ +#define __HYPERCALL_X86_64_H__ + +#include +#include +#include + +#define __STR(x) #x +#define STR(x) __STR(x) + +extern char _minios_hypercall_page[PAGE_SIZE]; + +#define _hypercall0(type, name) \ +({ \ + long __res; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res) \ + : \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall1(type, name, a1) \ +({ \ + long __res, __ign1; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=D" (__ign1) \ + : "1" ((long)(a1)) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall2(type, name, a1, a2) \ +({ \ + long __res, __ign1, __ign2; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \ + : "1" ((long)(a1)), "2" ((long)(a2)) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall3(type, name, a1, a2, a3) \ +({ \ + long __res, __ign1, __ign2, __ign3; \ + asm volatile ( \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + (type)__res; \ +}) + +#define _hypercall4(type, name, a1, a2, a3, a4) \ +({ \ + long __res, __ign1, __ign2, __ign3; \ + asm volatile ( \ + "movq %7,%%r10; " \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "g" ((long)(a4)) \ + : "memory", "r10" ); \ + (type)__res; \ +}) + +#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ +({ \ + long __res, __ign1, __ign2, __ign3; \ + asm volatile ( \ + "movq %7,%%r10; movq %8,%%r8; " \ + "call _minios_hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)), "g" ((long)(a4)), \ + "g" ((long)(a5)) \ + : "memory", "r10", "r8" ); \ + (type)__res; \ +}) + +static inline int +HYPERVISOR_set_trap_table( + trap_info_t *table) +{ + return _hypercall1(int, set_trap_table, table); +} + +static inline int +HYPERVISOR_mmu_update( + mmu_update_t *req, int count, int *success_count, domid_t domid) +{ + return _hypercall4(int, mmu_update, req, count, success_count, domid); +} + +static inline int +HYPERVISOR_mmuext_op( + struct mmuext_op *op, int count, int *success_count, domid_t domid) +{ + return _hypercall4(int, mmuext_op, op, count, success_count, domid); +} + +static inline int +HYPERVISOR_set_gdt( + unsigned long *frame_list, int entries) +{ + return _hypercall2(int, set_gdt, frame_list, entries); +} + +static inline int +HYPERVISOR_stack_switch( + unsigned long ss, unsigned long esp) +{ + return _hypercall2(int, stack_switch, ss, esp); +} + +static inline int +HYPERVISOR_set_callbacks( + unsigned long event_address, unsigned long failsafe_address, + unsigned long syscall_address) +{ + return _hypercall3(int, set_callbacks, + event_address, failsafe_address, syscall_address); +} + +static inline int +HYPERVISOR_fpu_taskswitch( + int set) +{ + return _hypercall1(int, fpu_taskswitch, set); +} + +static inline int +HYPERVISOR_sched_op( + int cmd, void *arg) +{ + return _hypercall2(int, sched_op, cmd, arg); +} + +static inline long +HYPERVISOR_set_timer_op( + uint64_t timeout) +{ + return _hypercall1(long, set_timer_op, timeout); +} + +static inline int +HYPERVISOR_set_debugreg( + int reg, unsigned long value) +{ + return _hypercall2(int, set_debugreg, reg, value); +} + +static inline unsigned long +HYPERVISOR_get_debugreg( + int reg) +{ + return _hypercall1(unsigned long, get_debugreg, reg); +} + +static inline int +HYPERVISOR_update_descriptor( + unsigned long ma, unsigned long word) +{ + return _hypercall2(int, update_descriptor, ma, word); +} + +static inline int +HYPERVISOR_memory_op( + unsigned int cmd, void *arg) +{ + return _hypercall2(int, memory_op, cmd, arg); +} + +static inline int +HYPERVISOR_multicall( + void *call_list, int nr_calls) +{ + return _hypercall2(int, multicall, call_list, nr_calls); +} + +static inline int +HYPERVISOR_update_va_mapping( + unsigned long va, pte_t new_val, unsigned long flags) +{ + return _hypercall3(int, update_va_mapping, va, new_val.pte, flags); +} + +static inline int +HYPERVISOR_event_channel_op( + int cmd, void *op) +{ + return _hypercall2(int, event_channel_op, cmd, op); +} + +static inline int +HYPERVISOR_xen_version( + int cmd, void *arg) +{ + return _hypercall2(int, xen_version, cmd, arg); +} + +static inline int +HYPERVISOR_console_io( + int cmd, int count, char *str) +{ + return _hypercall3(int, console_io, cmd, count, str); +} + +static inline int +HYPERVISOR_physdev_op( + void *physdev_op) +{ + return _hypercall1(int, physdev_op, physdev_op); +} + +static inline int +HYPERVISOR_grant_table_op( + unsigned int cmd, void *uop, unsigned int count) +{ + return _hypercall3(int, grant_table_op, cmd, uop, count); +} + +static inline int +HYPERVISOR_update_va_mapping_otherdomain( + unsigned long va, pte_t new_val, unsigned long flags, domid_t domid) +{ + return _hypercall4(int, update_va_mapping_otherdomain, va, + new_val.pte, flags, domid); +} + +static inline int +HYPERVISOR_vm_assist( + unsigned int cmd, unsigned int type) +{ + return _hypercall2(int, vm_assist, cmd, type); +} + +static inline int +HYPERVISOR_vcpu_op( + int cmd, int vcpuid, void *extra_args) +{ + return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); +} + +static inline int +HYPERVISOR_set_segment_base( + int reg, unsigned long value) +{ + return _hypercall2(int, set_segment_base, reg, value); +} + +static inline int +HYPERVISOR_suspend( + unsigned long srec) +{ + return _hypercall3(int, sched_op, SCHEDOP_shutdown, + SHUTDOWN_suspend, srec); +} + +static inline int +HYPERVISOR_nmi_op( + unsigned long op, + unsigned long arg) +{ + return _hypercall2(int, nmi_op, op, arg); +} + +static inline int +HYPERVISOR_sysctl( + unsigned long op) +{ + return _hypercall1(int, sysctl, op); +} + +static inline int +HYPERVISOR_domctl( + unsigned long op) +{ + return _hypercall1(int, domctl, op); +} + +#endif /* __HYPERCALL_X86_64_H__ */ + +/* + * Local variables: + * c-file-style: "linux" + * indent-tabs-mode: t + * c-indent-level: 8 + * c-basic-offset: 8 + * tab-width: 8 + * End: + */ diff --git a/xen/include/mini-os/xenbus.h b/xen/include/mini-os/xenbus.h new file mode 100644 index 0000000..0e45d47 --- /dev/null +++ b/xen/include/mini-os/xenbus.h @@ -0,0 +1,216 @@ +#ifndef MINIOS_XENBUS_H__ +#define MINIOS_XENBUS_H__ + +#include +#include +#include +#include +#include + +typedef unsigned long xenbus_transaction_t; +#define XBT_NIL ((xenbus_transaction_t)0) + +#ifdef CONFIG_XENBUS +/* Initialize the XenBus system. */ +void init_xenbus(void); +#else +static inline void init_xenbus(void) +{ +} +#endif + +/* Read the value associated with a path. Returns a malloc'd error + string on failure and sets *value to NULL. On success, *value is + set to a malloc'd copy of the value. */ +char *xenbus_read(xenbus_transaction_t xbt, const char *path, char **value); + +/* All accesses to an active xenbus_event_queue must occur with this + * lock held. The public functions here will do that for you, but + * your own accesses to the queue (including the contained waitq) + * must be protected by the lock. */ +extern spinlock_t xenbus_req_lock; + +/* Queue for events (watches or async request replies - see below) */ +struct xenbus_event { + union { + struct { + /* must be first, both for the bare minios xs.c, and for + * xenbus_wait_for_watch's handling */ + char *path; + char *token; + }; + struct xsd_sockmsg *reply; + }; + struct xenbus_watch *watch; + MINIOS_STAILQ_ENTRY(xenbus_event) entry; +}; +struct xenbus_event_queue { + MINIOS_STAILQ_HEAD(, xenbus_event) events; + void (*wakeup)(struct xenbus_event_queue*); /* can be safely ignored */ + struct wait_queue_head waitq; +}; + +void xenbus_event_queue_init(struct xenbus_event_queue *queue); + +char *xenbus_watch_path_token(xenbus_transaction_t xbt, const char *path, const char *token, struct xenbus_event_queue *events); +char *xenbus_unwatch_path_token(xenbus_transaction_t xbt, const char *path, const char *token); +void xenbus_wait_for_watch(struct xenbus_event_queue *queue); +char **xenbus_wait_for_watch_return(struct xenbus_event_queue *queue); +char* xenbus_wait_for_value(const char *path, const char *value, struct xenbus_event_queue *queue); +char *xenbus_wait_for_state_change(const char* path, XenbusState *state, struct xenbus_event_queue *queue); +char *xenbus_switch_state(xenbus_transaction_t xbt, const char* path, XenbusState state); + +/* When no token is provided, use a global queue. */ +#define XENBUS_WATCH_PATH_TOKEN "xenbus_watch_path" +extern struct xenbus_event_queue xenbus_default_watch_queue; +#define xenbus_watch_path(xbt, path) xenbus_watch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN, NULL) +#define xenbus_unwatch_path(xbt, path) xenbus_unwatch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN) + + +/* Associates a value with a path. Returns a malloc'd error string on + failure. */ +char *xenbus_write(xenbus_transaction_t xbt, const char *path, const char *value); + +struct write_req { + const void *data; + unsigned len; +}; + +/* Send a message to xenbus, in the same fashion as xb_write, and + block waiting for a reply. The reply is malloced and should be + freed by the caller. */ +struct xsd_sockmsg * +xenbus_msg_reply(int type, + xenbus_transaction_t trans, + struct write_req *io, + int nr_reqs); + +/* Removes the value associated with a path. Returns a malloc'd error + string on failure. */ +char *xenbus_rm(xenbus_transaction_t xbt, const char *path); + +/* List the contents of a directory. Returns a malloc'd error string + on failure and sets *contents to NULL. On success, *contents is + set to a malloc'd array of pointers to malloc'd strings. The array + is NULL terminated. May block. */ +char *xenbus_ls(xenbus_transaction_t xbt, const char *prefix, char ***contents); + +/* Reads permissions associated with a path. Returns a malloc'd error + string on failure and sets *value to NULL. On success, *value is + set to a malloc'd copy of the value. */ +char *xenbus_get_perms(xenbus_transaction_t xbt, const char *path, char **value); + +/* Sets the permissions associated with a path. Returns a malloc'd + error string on failure. */ +char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t dom, char perm); + +/* Start a xenbus transaction. Returns the transaction in xbt on + success or a malloc'd error string otherwise. */ +char *xenbus_transaction_start(xenbus_transaction_t *xbt); + +/* End a xenbus transaction. Returns a malloc'd error string if it + fails. abort says whether the transaction should be aborted. + Returns 1 in *retry iff the transaction should be retried. */ +char *xenbus_transaction_end(xenbus_transaction_t, int abort, + int *retry); + +/* Read path and parse it as an integer. Returns -1 on error. */ +int xenbus_read_integer(const char *path); + +/* Contraction of snprintf and xenbus_write(path/node). */ +char* xenbus_printf(xenbus_transaction_t xbt, + const char* node, const char* path, + const char* fmt, ...) + __attribute__((__format__(printf, 4, 5))); + +/* Utility function to figure out our domain id */ +domid_t xenbus_get_self_id(void); + +/* + * ----- asynchronous low-level interface ----- + */ + +/* + * Use of queue->wakeup: + * + * If queue->wakeup is set, it will be called instead of + * wake_up(&queue->waitq); + * + * queue->wakeup is initialised (to a function which just calls + * wake_up) by xenbus_event_queue_init. The user who wants something + * different should set ->wakeup after the init, but before the queue + * is used for xenbus_id_allocate or xenbus_watch_prepare. + * + * queue->wakeup() is called with the req_lock held. + */ + +/* Allocate an identifier for a xenbus request. Blocks if none are + * available. Cannot fail. On return, we may use the returned value + * as the id in a xenbus request. + * + * for_queue must already be allocated, but may be uninitialised. + * + * for_queue->watch is not touched by the xenbus machinery for + * handling requests/replies but should probably be initialised by the + * caller (probably to NULL) because this will help the caller + * distinguish the reply from any watch events which might end up in + * the same queue. + * + * reply_queue must exist and have been initialised. + * + * When the response arrives, the reply message will stored in + * for_queue->reply and for_queue will be queued on reply_queue. The + * id must be then explicitly released (or, used again, if desired). + * After ->reply is done with the caller must pass it to free(). + * (Do not use the id for more than one request at a time.) */ +int xenbus_id_allocate(struct xenbus_event_queue *reply_queue, + struct xenbus_event *for_queue); +void xenbus_id_release(int id); + +/* Allocating a token for a watch. + * + * To use this: + * - Include struct xenbus_watch in your own struct. + * - Set events; then call prepare. This will set token. + * You may then use token in a WATCH request. + * - You must UNWATCH before you call release. + * Do not modify token yourself. + * entry is private for the xenbus driver. + * + * When the watch fires, a new struct xenbus_event will be allocated + * and queued on events. The field xenbus_event->watch will have been + * set to watch by the xenbus machinery, and xenbus_event->path will + * be the watch path. After the caller is done with the event, + * its pointer should simply be passed to free(). */ +struct xenbus_watch { + char *token; + struct xenbus_event_queue *events; + MINIOS_LIST_ENTRY(xenbus_watch) entry; +}; +void xenbus_watch_init(struct xenbus_watch *watch); /* makes release a noop */ +void xenbus_watch_prepare(struct xenbus_watch *watch); /* need not be init'd */ +void xenbus_watch_release(struct xenbus_watch *watch); /* idempotent */ + + +/* Send data to xenbus. This can block. All of the requests are seen + * by xenbus as if sent atomically. The header is added + * automatically, using type %type, req_id %req_id, and trans_id + * %trans_id. */ +void xenbus_xb_write(int type, int req_id, xenbus_transaction_t trans_id, + const struct write_req *req, int nr_reqs); + +void xenbus_free(void*); +/* If the caller is in a scope which uses a different malloc arena, + * it must use this rather than free() when freeing data received + * from xenbus. */ + +#ifdef CONFIG_XENBUS +/* Reset the XenBus system. */ +void fini_xenbus(void); +#else +static inline void fini_xenbus(void) +{ +} +#endif + +#endif /* MINIOS_XENBUS_H__ */ diff --git a/xen/include/mini-os/xmalloc.h b/xen/include/mini-os/xmalloc.h new file mode 100644 index 0000000..c34b365 --- /dev/null +++ b/xen/include/mini-os/xmalloc.h @@ -0,0 +1,35 @@ +#ifndef __MINIOS_XMALLOC_H__ +#define __MINIOS_XMALLOC_H__ + + +#include + +void * memalloc(size_t, size_t); +void memfree(void *); +void free(void *); +int posix_memalign(void **, size_t, size_t); +void * realloc(void *, size_t); +void * calloc(size_t, size_t); + +#define DEFAULT_ALIGN (sizeof(unsigned long)) + +/* compat */ +#define _xmalloc(size, align) memalloc(size, align) +#define xfree(ptr) free(ptr) + + +static inline void *_xmalloc_array(size_t size, size_t align, size_t num) +{ + /* Check for overflow. */ + if (size && num > UINT_MAX / size) + return NULL; + return _xmalloc(size * num, align); +} + +/* Allocate space for typed object. */ +#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type))) + +/* Allocate space for array of typed objects. */ +#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) + +#endif /* __MINIOS_XMALLOC_H__ */