socsvn commit: r239263 - soc2012/syuu/bhyve-bios/usr.sbin/bhyve
syuu at FreeBSD.org
syuu at FreeBSD.org
Wed Jul 11 03:21:23 UTC 2012
Author: syuu
Date: Wed Jul 11 03:21:20 2012
New Revision: 239263
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239263
Log:
add bios_int16
Added:
soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int16.c
Modified:
soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile
soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c
soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int18.c
soc2012/syuu/bhyve-bios/usr.sbin/bhyve/pci_virtio_block.c
Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile
==============================================================================
--- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile Wed Jul 11 02:57:32 2012 (r239262)
+++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile Wed Jul 11 03:21:20 2012 (r239263)
@@ -8,7 +8,7 @@
SRCS+= instruction_emul.c mevent.c
SRCS+= pci_emul.c pci_hostbridge.c pci_passthru.c pci_virtio_block.c
SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c post.c rtc.c uart.c xmsr.c
-SRCS+= bios_call.c bios_int10.c bios_int13.c bios_int18.c
+SRCS+= bios_call.c bios_int10.c bios_int13.c bios_int16.c bios_int18.c
NO_MAN=
Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c
==============================================================================
--- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c Wed Jul 11 02:57:32 2012 (r239262)
+++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c Wed Jul 11 03:21:20 2012 (r239263)
@@ -36,22 +36,23 @@
#include <termios.h>
#include <unistd.h>
#include <stdbool.h>
+#include <fcntl.h>
#include <machine/vmm.h>
#include <vmmapi.h>
#include "bios_call.h"
+#include "fbsdrun.h"
-#define MAKEPTR(s, o) (((s) << 4) + (o))
-
-extern int block_drive_c_fd;
+/* XXX */
+#define SECTOR_SIZE 512
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;
+ uint64_t rax, rbx, rcx, rdx, rsi, rflags, es_base, es_select, ds_base, ds_select;
+ uint32_t es_limit, es_access, ds_limit, ds_access;
+ uint16_t bx, ds16, es16, si;
uint8_t al, ah, cl, ch, dl, dh;
int error;
@@ -67,29 +68,162 @@
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_RSI, &rsi)) != 0)
+ goto done;
+
if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, &rflags)) != 0)
goto done;
+ if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_ES, &es_select)) != 0)
+ goto done;
+
+ if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_DS, &ds_select)) != 0)
+ goto done;
+
if ((error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_ES, &es_base,
&es_limit, &es_access)) != 0)
goto done;
+ if ((error = vm_get_desc(ctx, vcpu, VM_REG_GUEST_DS, &ds_base,
+ &ds_limit, &ds_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);
+ dl = (uint8_t)rdx;
+ dh = (uint8_t)(rdx >> 8);
+ es16 = (uint16_t)es_base;
+ ds16 = (uint16_t)ds_base;
+ si = (uint16_t)rsi;
- printf("%s rax=%lx ah=%x al=%x rbx=%lx bx=%x rcx=%lx ch=%x cl=%x rdx=%lx dh=%x dl=%x es_base=%lx es_limit=%x es_access=%x\n",
- __func__, rax, ah, al, rbx, bx, rcx, ch, cl, rdx, dh, dl, es_base, es_limit, es_access);
-
+ printf("int:13h ah:%xh", ah);
switch (ah) {
+ case 0x00:
+ rflags &= ~0x1;
+ error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ printf(" rflags=%lx\n", rflags);
+ break;
case 0x02:
+ {
+ unsigned int pos;
+ ssize_t siz;
+ int fd;
+
+ /* XXX: pass fd from somewhere else */
+ fd = open("diskdev", O_RDWR);
+ if (fd < 0) {
+ perror("open ");
+ goto fail02;
+ }
+
+ /* cylinder */
+ pos = ch * 2 * 18 * SECTOR_SIZE;
+ /* head */
+ pos += dh * 18 * SECTOR_SIZE;
+ /* sector */
+ pos += (cl - 1) * SECTOR_SIZE;
+
+ printf(" cylinder=%x head=%x sector=%x addr=%x:%x count=%x\n",
+ ch, dh, cl, es16, bx, al);
+ siz = pread(fd,
+ paddr_guest2host((es16 << 4) + bx),
+ al * SECTOR_SIZE, pos);
+ if (siz < 0) {
+ perror("read ");
+ error = -1;
+ close(fd);
+ goto fail02;
+ }
+ rflags &= ~0x1;
+ error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ close(fd);
+ break;
+fail02:
+ rflags |= 0x1;
+ vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ break;
+ }
+ case 0x08:
+ printf(" dl=%x rflags=%lx\n", dl, rflags);
+ if (dl == 0x80) {
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, 0)) != 0)
+ break;
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RBX, 0x02)) != 0)
+ break;
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RCX, 0xFFFF)) != 0)
+ break;
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RDX, 0x0101)) != 0)
+ break;
+
+ rflags &= ~0x1;
+ }else{
+ rflags |= 0x1;
+ }
+ error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
break;
case 0x41:
+ printf(" bx=%x cx=%x rflags=%lx\n", bx, (uint32_t)rcx, rflags);
+ if (bx == 0x55aa) {
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RBX, 0xaa55)) != 0)
+ break;
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RCX, cl | 0x01)) != 0)
+ break;
+ rflags &= ~0x1;
+ error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ break;
+ }
rflags |= 0x1;
error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
break;
+ case 0x42:
+ {
+ ssize_t siz;
+ int fd;
+ char *dap;
+ uint16_t sector, segment, offset;
+ uint64_t count;
+
+ /* XXX: pass fd from somewhere else */
+ fd = open("diskdev", O_RDWR);
+ if (fd < 0) {
+ perror("open ");
+ goto fail42;
+ }
+
+ dap = (char *)paddr_guest2host((ds16 << 4) + si);
+ sector = *(uint16_t *)(dap + 0x02);
+ offset = *(uint16_t *)(dap + 0x04);
+ segment = *(uint16_t *)(dap + 0x06);
+ count = *(uint64_t *)(dap + 0x08);
+
+ printf(" dap=%x:%x sector=%x dest=%x:%x count=%lx\n",
+ ds16, si, sector, segment, offset, count);
+
+ siz = pread(fd,
+ paddr_guest2host((segment << 4) + offset),
+ count * SECTOR_SIZE, sector * SECTOR_SIZE);
+ if (siz < 0) {
+ perror("read ");
+ error = siz;
+ close(fd);
+ goto fail42;
+ }
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, al)) != 0)
+ goto fail42;
+
+ rflags &= ~0x1;
+ error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ close(fd);
+ break;
+fail42:
+ rflags |= 0x1;
+ vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ break;
+ }
+
default:
fprintf(stderr, "Not implemented BIOS call int=%x ah=%x\n",
intno, ah);
Added: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int16.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int16.c Wed Jul 11 03:21:20 2012 (r239263)
@@ -0,0 +1,103 @@
+/*-
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include <machine/vmm.h>
+#include <vmmapi.h>
+
+#include "consport.h"
+#include "bios_call.h"
+
+static int
+int16_handler(struct vmctx *ctx, int vcpu, int intno)
+{
+ uint64_t rax, rflags;
+ uint8_t al, ah;
+ int error;
+
+ if (!console_opened) {
+ ttyopen();
+ console_opened = 1;
+ }
+
+ 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_RFLAGS, &rflags)) != 0)
+ goto done;
+
+
+ al = (uint8_t)rax;
+ ah = (uint8_t)(rax >> 8);
+
+ switch (ah) {
+ case 0x00:
+ {
+ int c;
+ while((c = ttyread()) == -1)
+ ;
+
+ error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, c & 0xff);
+ break;
+ }
+ case 0x01:
+ {
+ int c = ttyread();
+ if (c == -1) {
+ rflags |= 0x40;
+ } else {
+ rflags &= ~0x40;
+ if ((error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, c & 0xff)) != 0)
+ goto done;
+ }
+
+ error = vm_set_register(ctx, 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(int16, 0x16, int16_handler);
Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int18.c
==============================================================================
--- soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int18.c Wed Jul 11 02:57:32 2012 (r239262)
+++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int18.c Wed Jul 11 03:21:20 2012 (r239263)
@@ -29,11 +29,13 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <stdio.h>
#include "bios_call.h"
static int
int18_handler(struct vmctx *ctx, int vcpu, int intno)
{
+ printf("int18\n");
return (0);
}
BIOS_CALL(int18, 0x18, int18_handler);
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 11 02:57:32 2012 (r239262)
+++ soc2012/syuu/bhyve-bios/usr.sbin/bhyve/pci_virtio_block.c Wed Jul 11 03:21:20 2012 (r239263)
@@ -136,8 +136,6 @@
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.
@@ -362,10 +360,6 @@
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));
More information about the svn-soc-all
mailing list