From owner-svn-soc-all@FreeBSD.ORG Wed Jul 4 20:10:39 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 17C961065670 for ; Wed, 4 Jul 2012 20:10:37 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Wed, 04 Jul 2012 20:10:37 +0000 Date: Wed, 04 Jul 2012 20:10:37 +0000 From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120704201037.17C961065670@hub.freebsd.org> Cc: Subject: socsvn commit: r238973 - soc2012/syuu/bhyve-bios/usr.sbin/bhyve X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2012 20:10:39 -0000 Author: syuu Date: Wed Jul 4 20:10:36 2012 New Revision: 238973 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238973 Log: export console functions to bios_int10.c, add bios_int13.c Added: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/consport.h Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int10.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/consport.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/pci_virtio_block.c Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int10.c ============================================================================== --- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int10.c Wed Jul 4 19:51:25 2012 (r238972) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int10.c Wed Jul 4 20:10:36 2012 (r238973) @@ -40,46 +40,19 @@ #include #include +#include "consport.h" #include "bios_call.h" -#define BVM_CONS_SIG ('b' << 8 | 'v') - -static struct termios tio_orig, tio_new; - -static void -ttyclose(void) -{ - tcsetattr(STDIN_FILENO, TCSANOW, &tio_orig); -} - -static void -ttyopen(void) -{ - tcgetattr(STDIN_FILENO, &tio_orig); - - cfmakeraw(&tio_new); - tcsetattr(STDIN_FILENO, TCSANOW, &tio_new); - - atexit(ttyclose); -} - -static void -ttywrite(unsigned char wb) -{ - (void) write(STDOUT_FILENO, &wb, 1); -} - static int int10_handler(struct vmctx *ctx, int vcpu, int intno) { - static int opened; uint64_t rax, rbx; uint8_t al, ah, bl, bh; int error; - if (!opened) { + if (!console_opened) { ttyopen(); - opened = 1; + console_opened = 1; } if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RAX, &rax)) != 0) Added: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c Wed Jul 4 20:10:36 2012 (r238973) @@ -0,0 +1,102 @@ +/*- + * Copyright (c) 2011 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "bios_call.h" + +#define MAKEPTR(s, o) (((s) << 4) + (o)) + +extern int block_drive_c_fd; + +static int +int13_handler(struct vmctx *ctx, int vcpu, int intno) +{ + uint64_t rax, rbx, rcx, rdx, es_base, rflags; + uint32_t es_limit, es_access; + uint16_t bx; + uint8_t al, ah, cl, ch, dl, dh; + int error; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RAX, &rax)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RBX, &rbx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RCX, &rcx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RDX, &rdx)) != 0) + goto done; + + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, &rflags)) != 0) + goto done; + + if ((error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_ES, &es_base, + &es_limit, &es_access)) != 0) + goto done; + + al = (uint8_t)rax; + ah = (uint8_t)(rax >> 8); + bx = (uint16_t)rbx; + cl = (uint8_t)rcx; + ch = (uint8_t)(rcx >> 8); + + printf("%s ah=%x al=%x ch=%x cl=%x dh=%x dl=%x bx=%x es=%llx:%x:%x\n", + __func__, ah, al, ch, cl, dh, dl, bx, es_base, es_limit, es_access); + + switch (ah) { + case 0x02: + break; + case 0x41: + rflags |= 0x1; + error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RFLAGS, rflags); + break; + default: + fprintf(stderr, "Not implemented BIOS call int=%x ah=%x\n", + intno, ah); + } + +done: + return (error); + +} +BIOS_CALL(int13, 0x13, int13_handler); Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/consport.c ============================================================================== --- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/consport.c Wed Jul 4 19:51:25 2012 (r238972) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/consport.c Wed Jul 4 20:10:36 2012 (r238973) @@ -44,6 +44,7 @@ #define BVM_CONS_SIG ('b' << 8 | 'v') static struct termios tio_orig, tio_new; +int console_opened = 0; static void ttyclose(void) @@ -51,7 +52,7 @@ tcsetattr(STDIN_FILENO, TCSANOW, &tio_orig); } -static void +void ttyopen(void) { tcgetattr(STDIN_FILENO, &tio_orig); @@ -79,7 +80,7 @@ } } -static int +int ttyread(void) { char rb; @@ -92,7 +93,7 @@ } } -static void +void ttywrite(unsigned char wb) { (void) write(STDOUT_FILENO, &wb, 1); @@ -102,8 +103,6 @@ console_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { - static int opened; - if (bytes == 2 && in) { *eax = BVM_CONS_SIG; return (0); @@ -112,9 +111,9 @@ if (bytes != 4) return (-1); - if (!opened) { + if (!console_opened) { ttyopen(); - opened = 1; + console_opened = 1; } if (in) Added: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/consport.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/consport.h Wed Jul 4 20:10:36 2012 (r238973) @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2012 Takuya ASADA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _CONSPORT_H_ +#define _CONSPORT_H_ + +extern int console_opened; +void ttyopen(void); +int ttyread(void); +void ttywrite(unsigned char wb); + + +#endif /* _CONSPORT_H_ */ + Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/pci_virtio_block.c ============================================================================== --- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/pci_virtio_block.c Wed Jul 4 19:51:25 2012 (r238972) +++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/pci_virtio_block.c Wed Jul 4 20:10:36 2012 (r238973) @@ -136,6 +136,8 @@ struct vtblk_config vbsc_cfg; }; +int block_drive_c_fd = -1; + /* * Return the number of available descriptors in the vring taking care * of the 16-bit index wraparound. @@ -359,6 +361,10 @@ close(fd); return (1); } + + if (block_drive_c_fd == -1) { + block_drive_c_fd = fd; + } sc = malloc(sizeof(struct pci_vtblk_softc)); memset(sc, 0, sizeof(struct pci_vtblk_softc));