socsvn commit: r238875 - soc2012/syuu/bhyve-bios/usr.sbin/bhyvebiosload

syuu at FreeBSD.org syuu at FreeBSD.org
Tue Jul 3 01:58:04 UTC 2012


Author: syuu
Date: Tue Jul  3 01:58:01 2012
New Revision: 238875
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238875

Log:
  Put pseudo bios handler on the code

Modified:
  soc2012/syuu/bhyve-bios/usr.sbin/bhyvebiosload/bhyvebiosload.c

Modified: soc2012/syuu/bhyve-bios/usr.sbin/bhyvebiosload/bhyvebiosload.c
==============================================================================
--- soc2012/syuu/bhyve-bios/usr.sbin/bhyvebiosload/bhyvebiosload.c	Tue Jul  3 00:06:14 2012	(r238874)
+++ soc2012/syuu/bhyve-bios/usr.sbin/bhyvebiosload/bhyvebiosload.c	Tue Jul  3 01:58:01 2012	(r238875)
@@ -77,13 +77,10 @@
 
 #include <vmmapi.h>
 
-#include "userboot.h"
-
 #define	MB	(1024 * 1024UL)
 #define	GB	(1024 * 1024 * 1024UL)
 #define	BSP	0
 
-static char *host_base = "/";
 static struct termios term, oldterm;
 static int disk_fd = -1;
 
@@ -91,134 +88,6 @@
 static uint64_t lowmem, highmem;
 static struct vmctx *ctx;
 
-static void cb_exit(void *arg, int v);
-
-/*
- * Host filesystem i/o callbacks
- */
-
-struct cb_file {
-	int cf_isdir;
-	size_t cf_size;
-	struct stat cf_stat;
-	union {
-		int fd;
-		DIR *dir;
-	} cf_u;
-};
-
-static int
-cb_open(void *arg, const char *filename, void **hp)
-{
-	struct stat st;
-	struct cb_file *cf;
-	char path[PATH_MAX];
-
-	if (!host_base)
-		return (ENOENT);
-
-	strlcpy(path, host_base, PATH_MAX);
-	if (path[strlen(path) - 1] == '/')
-		path[strlen(path) - 1] = 0;
-	strlcat(path, filename, PATH_MAX);
-	cf = malloc(sizeof(struct cb_file));
-	if (stat(path, &cf->cf_stat) < 0) {
-		free(cf);
-		return (errno);
-	}
-
-	cf->cf_size = st.st_size;
-	if (S_ISDIR(cf->cf_stat.st_mode)) {
-		cf->cf_isdir = 1;
-		cf->cf_u.dir = opendir(path);
-		if (!cf->cf_u.dir)
-			goto out;
-		*hp = cf;
-		return (0);
-	}
-	if (S_ISREG(cf->cf_stat.st_mode)) {
-		cf->cf_isdir = 0;
-		cf->cf_u.fd = open(path, O_RDONLY);
-		if (cf->cf_u.fd < 0)
-			goto out;
-		*hp = cf;
-		return (0);
-	}
-
-out:
-	free(cf);
-	return (EINVAL);
-}
-
-static int
-cb_close(void *arg, void *h)
-{
-	struct cb_file *cf = h;
-
-	if (cf->cf_isdir)
-		closedir(cf->cf_u.dir);
-	else
-		close(cf->cf_u.fd);
-	free(cf);
-
-	return (0);
-}
-
-static int
-cb_read(void *arg, void *h, void *buf, size_t size, size_t *resid)
-{
-	struct cb_file *cf = h;
-	ssize_t sz;
-
-	if (cf->cf_isdir)
-		return (EINVAL);
-	sz = read(cf->cf_u.fd, buf, size);
-	if (sz < 0)
-		return (EINVAL);
-	*resid = size - sz;
-	return (0);
-}
-
-/*
- * Guest virtual machine i/o callbacks
- */
-static int
-cb_copyin(void *arg, const void *from, uint64_t to, size_t size)
-{
-
-	to &= 0x7fffffff;
-	if (to > lowmem)
-		return (EFAULT);
-	if (to + size > lowmem)
-		size = lowmem - to;
-
-	memcpy(&membase[to], from, size);
-
-	return (0);
-}
-
-static void
-cb_exec(void *arg, uint64_t rip)
-{
-	int error;
-
-	error = vm_setup_bios_registers(ctx, BSP);
-	if (error) {
-		perror("vm_setup_freebsd_registers");
-		cb_exit(NULL, USERBOOT_EXIT_QUIT);
-	}
-
-	cb_exit(NULL, 0);
-}
-
-static void
-cb_exit(void *arg, int v)
-{
-
-	tcsetattr(0, TCSAFLUSH, &oldterm);
-	exit(v);
-}
-
 static void
 usage(void)
 {
@@ -232,12 +101,9 @@
 int
 main(int argc, char** argv)
 {
-	void *h;
 	int opt, error;
 	char *disk_image;
-	struct cb_file *cf;
-	char *buf;
-	size_t res;
+	int i, addr;
 
 	progname = argv[0];
 
@@ -245,16 +111,12 @@
 	highmem = 0;
 	disk_image = NULL;
 
-	while ((opt = getopt(argc, argv, "d:h:m:M:")) != -1) {
+	while ((opt = getopt(argc, argv, "d:m:M:")) != -1) {
 		switch (opt) {
 		case 'd':
 			disk_image = optarg;
 			break;
 
-		case 'h':
-			host_base = optarg;
-			break;
-
 		case 'm':
 			lowmem = strtoul(optarg, NULL, 0) * MB;
 			break;
@@ -315,39 +177,31 @@
 	tcsetattr(0, TCSAFLUSH, &term);
 
 	disk_fd = open(disk_image, O_RDONLY);
-	buf = malloc(512);
-	if (read(disk_fd, buf, 512) != 512) {
+	if (read(disk_fd, &membase[0x7c00], 512) != 512) {
 		perror("read ");
 		return (1);
 	}
-	cb_copyin(NULL, buf, 0x7c00, 512);
-	free(buf);
 	close(disk_fd);
 
-	if (cb_open(NULL, "/pseudobios.bin", &h)) {
-		perror("cb_open ");
-		return (1);
-	}
-	cf = h;
-	buf = malloc(6);
-	if (cb_read(NULL, cf, buf, 6, &res) != 0 || res != 0) {
-		fprintf(stderr, "cb_read\n");
-		return (1);
-	}
-
-	int addr = 0x400;
-	for (int i = 0x0; i < 0x400; i += 0x4) {
+	addr = 0x400;
+	for (i = 0x0; i < 0x400; i += 0x4) {
 		uint16_t *p = (uint16_t *)&membase[i];
-		cb_copyin(NULL, buf, addr, 6);
+		membase[addr + 0] = 0x0f;	/* vmcall(3byte) */
+		membase[addr + 1] = 0x01;
+		membase[addr + 2] = 0xc1;
+		membase[addr + 3] = 0xcf;	/* iret */
 		*p = addr;
 		p = (uint16_t *)&membase[i + 0x2];
 		*p = 0x0;
-		addr += 0x10;
+		addr += 4;
+	}
+	error = vm_setup_bios_registers(ctx, BSP);
+	if (error) {
+		perror("vm_setup_freebsd_registers");
+		return (-1);
 	}
 
-	free(buf);
-	cb_close(NULL, cf);
-	cb_exec(NULL, 0);
+	tcsetattr(0, TCSAFLUSH, &oldterm);
 
 	return (0);
 }


More information about the svn-soc-all mailing list