Date: Mon, 20 Aug 2012 13:15:20 +0000 From: syuu@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r240565 - in soc2012/syuu/bhyve-bios: lib/libbiosemul usr.sbin/bhyve usr.sbin/bhyvebiosload Message-ID: <20120820131520.B5BA01065670@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: syuu Date: Mon Aug 20 13:15:20 2012 New Revision: 240565 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240565 Log: Replaced my own bios emulation code by libbiosemul, which includes interrupt vector with trampoline code, loading boot sector, bios call emulation. Added handling secondary PIC IO(0xa0, 0xa1), keyboard controller IO(0x60, 0x64). Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h soc2012/syuu/bhyve-bios/lib/libbiosemul/callback.c soc2012/syuu/bhyve-bios/lib/libbiosemul/cpu.c soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h soc2012/syuu/bhyve-bios/lib/libbiosemul/int.c soc2012/syuu/bhyve-bios/lib/libbiosemul/int10.c soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c soc2012/syuu/bhyve-bios/lib/libbiosemul/int14.c soc2012/syuu/bhyve-bios/lib/libbiosemul/mouse.c soc2012/syuu/bhyve-bios/lib/libbiosemul/port.c soc2012/syuu/bhyve-bios/lib/libbiosemul/register.h soc2012/syuu/bhyve-bios/lib/libbiosemul/signal.c soc2012/syuu/bhyve-bios/lib/libbiosemul/trap.c soc2012/syuu/bhyve-bios/lib/libbiosemul/tty.c soc2012/syuu/bhyve-bios/lib/libbiosemul/video.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/Makefile soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_call.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_call.h soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int10.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int13.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int16.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/bios_int18.c soc2012/syuu/bhyve-bios/usr.sbin/bhyve/fbsdrun.c soc2012/syuu/bhyve-bios/usr.sbin/bhyvebiosload/bhyvebiosload.c Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/Makefile Mon Aug 20 13:15:20 2012 (r240565) @@ -5,16 +5,18 @@ LIB= biosemul WARNS?= 2 SRCS= biosemul.c \ - bios.c callback.c \ + bios.c callback.c cpu.c \ debug.c i386-pinsn.c \ - int13.c + int.c int10.c int13.c int16.c \ + mouse.c port.c trap.c \ + tty.c video.c ${FONTHDRS} INCS= biosemul.h CFLAGS+= -I. -DDISASSEMBLER FONTFILES= cp437-8x8.pcf.gz cp437-8x14.pcf.gz cp437-8x16.pcf.gz FONTHDRS= font8x8.h font8x14.h font8x16.h CLEANFILES= ${FONTFILES} ${FONTHDRS} -CFLAGS+= -DNO_X -g +CFLAGS+= -DNO_X cp437-8x8.pcf.gz: cp437-8x8.pcf.gz.uu uudecode ${.CURDIR}/cp437-8x8.pcf.gz.uu Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/bios.c Mon Aug 20 13:15:20 2012 (r240565) @@ -82,7 +82,6 @@ int nparallel = 0; u_int32_t rom_config; -#if 0 /* ** BIOS equipment list */ @@ -138,11 +137,13 @@ debug(D_TRAPS | 0x15, "BIOS: Keyboard intercept\n"); /* Don't translate scan code. */ break; -#if 0 case 0x88: - get_raw_extmemory_info(REGS); - break; +#if 0 + get_raw_extmemory_info(REGS); #endif + /* XXX: implement max size */ + R_AX = 0x0; + break; case 0xc0: /* Get configuration */ debug(D_TRAPS | 0x15, "BIOS: Get configuration\n"); PUTVEC(R_ES, R_BX, rom_config); @@ -161,22 +162,17 @@ break; } } -#endif void bios_init(void) { -#if 0 int i, j, k; -#endif u_char *jtab; -#if 0 struct timeval tv; time_t tv_sec; struct timezone tz; struct tm tm; u_int32_t vec; -#endif strcpy((char *)BIOS_copyright, "Copyright (C) 1993 Krystal Technologies/BSDI"); @@ -219,7 +215,6 @@ *(u_char *)BIOS_hardware_id = 0xfc; /* Identify as a PC/AT */ -#if 0 /* * Interrupt revectors F000:0000 - F000:03ff */ @@ -229,13 +224,15 @@ continue; if ((i >= 0x00 && i < 0x2f) || (i >= 0x30 && i < 0xfe)) { - ivec[i] = 0xF0300000L | (k * 1); - jtab = (u_char *)VECPTR(ivec[i]); - *jtab++ = 0xf4; /* HLT */ + ivec[i] = 0xF0300000L | (k * 4); + jtab = (u_char *)(lomem_addr + VECPTR(ivec[i])); + *jtab++ = 0x0f; + *jtab++ = 0x01; + *jtab++ = 0xc1; /* VMCALL */ ++k; } else { ivec[i] = 0xF0000000L | (j * 6); - jtab = (u_char *)VECPTR(ivec[i]); + jtab = (u_char *)(lomem_addr + VECPTR(ivec[i])); *jtab++ = 0xcd; /* INT i */ *jtab++ = i; *jtab++ = 0xca; /* RETF 2 */ @@ -244,13 +241,12 @@ ++j; } } -#endif /* * Misc variables from F000:0400 - F000:0fff */ rom_config = 0xF0000400; - jtab = (u_char *)VECPTR(rom_config); + jtab = (u_char *)(lomem_addr + VECPTR(rom_config)); *jtab++ = 20; /* length of entry */ *jtab++ = 0; *jtab++ = *(u_char *)BIOS_hardware_id; @@ -267,18 +263,17 @@ #if 0 InDOS = jtab++; *InDOS = 0; +#else + jtab++; +#endif mouse_area = jtab; -#endif jtab += 0x10; *(u_short *)&BIOSDATA[0x10] = (1 << 0) | /* Diskette avail for boot */ (1 << 1) | /* Math co-processor */ -#if 0 (nmice << 2) | /* No pointing device */ -#endif - (0 << 2) | (2 << 4) | /* Initial video (80 x 25 C) */ ((nfloppies - 1) << 6) | /* Number of floppies - 1 */ (nserial << 9) | /* Number of serial devices */ @@ -298,7 +293,6 @@ BIOSDATA[0x91] = 0x40; } -#if 0 gettimeofday(&tv, &tz); tv_sec = tv.tv_sec; tm = *localtime(&tv_sec); @@ -313,12 +307,14 @@ ivec[0x12] = vec; register_callback(vec, int12, "int 12"); +#if 0 if(fossil) vec = insert_fossil_softint_trampoline(); else vec = insert_softint_trampoline(); ivec[0x14] = vec; register_callback(vec, int14, "int 14"); +#endif vec = insert_softint_trampoline(); ivec[0x15] = vec; @@ -327,7 +323,7 @@ vec = insert_softint_trampoline(); ivec[0x16] = vec; register_callback(vec, int16, "int 16"); - +#if 0 vec = insert_softint_trampoline(); ivec[0x17] = vec; register_callback(vec, int17, "int 17"); Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.c Mon Aug 20 13:15:20 2012 (r240565) @@ -71,8 +71,8 @@ int raw_kbd = 0; int timer_disable = 0; struct timeval boot_time; -u_int32_t *ivec = (u_int32_t *)0; -char *lomem_addr = NULL; +u_int32_t *ivec; +char *lomem_addr; #ifndef USE_VM86 #define PRB_V86_FORMAT 0x4242 @@ -85,10 +85,12 @@ }; #endif -#if 0 /* local prototypes */ +#if 0 static void setup_boot(regcontext_t *REGS); +#endif static int try_boot(int); +#if 0 static void setup_command(int argc, char *argv[], regcontext_t *REGS); static FILE *find_doscmdrc(void); static int do_args(int argc, char *argv[]); @@ -109,29 +111,33 @@ static struct vm86_init_args kargs; #endif +static int set_modified_regs(struct vmctx *ctx, int vcpu, regcontext_t *orig, regcontext_t *modified); +static int get_all_regs(struct vmctx *ctx, int vcpu, regcontext_t *regs); + #define HDISK_CYL 2610 #define HDISK_HEAD 255 #define HDISK_TRACK 63 #define HDISK_FILE "/home/syuu/test.img" +regcontext_t *saved_regcontext; + /* lobotomise */ -void biosemul_init(char *lomem) +void biosemul_init(struct vmctx *ctx, int vcpu, char *lomem) { lomem_addr = lomem; ivec = (u_int32_t *)lomem_addr; - debugf = stderr; - debug_set(0xfffffff); + init_ints(); + + debugf = stderr; -#if 0 /* Call init functions */ if (raw_kbd) console_init(); init_io_port_handlers(); -#endif bios_init(); init_hdisk(2, HDISK_CYL, HDISK_HEAD, HDISK_TRACK, HDISK_FILE, NULL); -#if 0 + try_boot(booting = 2); /* try C: */ cpu_init(); kbd_init(); kbd_bios_init(); @@ -140,10 +146,13 @@ mouse_init(); video_bios_init(); disk_bios_init(); +#if 0 cmos_init(); timer_init(); +#endif /* iomap_init(); */ +#if 0 gettimeofday(&boot_time, 0); #endif } @@ -157,6 +166,10 @@ static void setup_boot(regcontext_t *REGS) { + int fd; /* don't close this! */ + + fd = try_boot(booting = 2); /* try C: */ + /* initialise registers for entry to bootblock */ R_EFLAGS = 0x20202; R_CS = 0x0000; @@ -176,6 +189,7 @@ R_GS = 0x0000; #endif } +#endif /* ** try_boot @@ -194,7 +208,7 @@ } /* read bootblock */ - if (read(fd, (char *)0x7c00, 512) != 512) { + if (read(fd, (char *)(lomem_addr + 0x7c00), 512) != 512) { debug(D_DISK, "Short read on boot block from %c:\n", drntol(bootdrv)); return -1; } @@ -202,6 +216,7 @@ return fd; } +#if 0 /* ** setup_command ** @@ -768,7 +783,7 @@ } #endif -int +static int get_all_regs(struct vmctx *ctx, int vcpu, regcontext_t *regs) { int error = 0; @@ -806,108 +821,108 @@ if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RAX, ®s->r.eax.r_rx)) != 0) goto done; - if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, ®s->r.eip.r_rx)) != 0) + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSP, ®s->r.esp.r_rx)) != 0) goto done; - if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, ®s->r.cs.r_rx)) != 0) + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_SS, ®s->r.ss.r_rx)) != 0) goto done; - if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, ®s->r.efl.r_rx)) != 0) + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RIP, ®s->r.eip.r_rx)) != 0) goto done; - if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RSP, ®s->r.esp.r_rx)) != 0) + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_CS, ®s->r.cs.r_rx)) != 0) goto done; - if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_SS, ®s->r.ss.r_rx)) != 0) + if ((error = vm_get_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, ®s->r.efl.r_rx)) != 0) goto done; done: return (error); } -int +static int set_modified_regs(struct vmctx *ctx, int vcpu, regcontext_t *orig, regcontext_t *modified) { int error = 0; if ((orig->r.gs.r_rx != modified->r.gs.r_rx) && - printf("%s gs:%lx\n", __func__, modified->r.gs.r_rx) && + fprintf(stderr, "%s gs:%lx\n", __func__, modified->r.gs.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_GS, modified->r.gs.r_rx)) != 0) goto done; if ((orig->r.fs.r_rx != modified->r.fs.r_rx) && - printf("%s fs:%lx\n", __func__, modified->r.fs.r_rx) && + fprintf(stderr, "%s fs:%lx\n", __func__, modified->r.fs.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_FS, modified->r.fs.r_rx)) != 0) goto done; if ((orig->r.es.r_rx != modified->r.es.r_rx) && - printf("%s es:%lx\n", __func__, modified->r.es.r_rx) && + fprintf(stderr, "%s es:%lx\n", __func__, modified->r.es.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_ES, modified->r.es.r_rx)) != 0) goto done; if ((orig->r.ds.r_rx != modified->r.ds.r_rx) && - printf("%s ds:%lx\n", __func__, modified->r.ds.r_rx) && + fprintf(stderr, "%s ds:%lx\n", __func__, modified->r.ds.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_DS, modified->r.es.r_rx)) != 0) goto done; if ((orig->r.edi.r_rx != modified->r.edi.r_rx) && - printf("%s edi:%lx\n", __func__, modified->r.edi.r_rx) && + fprintf(stderr, "%s edi:%lx\n", __func__, modified->r.edi.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RDI, modified->r.edi.r_rx)) != 0) goto done; if ((orig->r.esi.r_rx != modified->r.esi.r_rx) && - printf("%s esi:%lx\n", __func__, modified->r.esi.r_rx) && + fprintf(stderr, "%s esi:%lx\n", __func__, modified->r.esi.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSI, modified->r.esi.r_rx)) != 0) goto done; if ((orig->r.ebp.r_rx != modified->r.ebp.r_rx) && - printf("%s ebp:%lx\n", __func__, modified->r.ebp.r_rx) && + fprintf(stderr, "%s ebp:%lx\n", __func__, modified->r.ebp.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RBP, modified->r.ebp.r_rx)) != 0) goto done; if ((orig->r.ebx.r_rx != modified->r.ebx.r_rx) && - printf("%s ebx:%lx\n", __func__, modified->r.ebx.r_rx) && + fprintf(stderr, "%s ebx:%lx\n", __func__, modified->r.ebx.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RBX, modified->r.ebx.r_rx)) != 0) goto done; if ((orig->r.edx.r_rx != modified->r.edx.r_rx) && - printf("%s edx:%lx\n", __func__, modified->r.edx.r_rx) && + fprintf(stderr, "%s edx:%lx\n", __func__, modified->r.edx.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RDX, modified->r.edx.r_rx)) != 0) goto done; if ((orig->r.ecx.r_rx != modified->r.ecx.r_rx) && - printf("%s ecx:%lx\n", __func__, modified->r.ecx.r_rx) && + fprintf(stderr, "%s ecx:%lx\n", __func__, modified->r.ecx.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RCX, modified->r.ecx.r_rx)) != 0) goto done; if ((orig->r.eax.r_rx != modified->r.eax.r_rx) && - printf("%s eax:%lx\n", __func__, modified->r.eax.r_rx) && + fprintf(stderr, "%s eax:%lx\n", __func__, modified->r.eax.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RAX, modified->r.eax.r_rx)) != 0) goto done; + if ((orig->r.esp.r_rx != modified->r.esp.r_rx) && + fprintf(stderr, "%s esp:%lx\n", __func__, modified->r.esp.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSP, modified->r.esp.r_rx)) != 0) + goto done; + + if ((orig->r.ss.r_rx != modified->r.ss.r_rx) && + fprintf(stderr, "%s ss:%lx\n", __func__, modified->r.ss.r_rx) && + (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_SS, modified->r.ss.r_rx)) != 0) + goto done; + if ((orig->r.eip.r_rx != modified->r.eip.r_rx) && - printf("%s eip:%lx\n", __func__, modified->r.eip.r_rx) && + fprintf(stderr, "%s eip:%lx\n", __func__, modified->r.eip.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RIP, modified->r.eip.r_rx)) != 0) goto done; if ((orig->r.cs.r_rx != modified->r.cs.r_rx) && - printf("%s cs:%lx\n", __func__, modified->r.cs.r_rx) && + fprintf(stderr, "%s cs:%lx\n", __func__, modified->r.cs.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_CS, modified->r.cs.r_rx)) != 0) goto done; if ((orig->r.efl.r_rx != modified->r.efl.r_rx) && - printf("%s eflags:%lx\n", __func__, modified->r.efl.r_rx) && + fprintf(stderr, "%s eflags:%lx\n", __func__, modified->r.efl.r_rx) && (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RFLAGS, modified->r.efl.r_rx)) != 0) goto done; - - if ((orig->r.esp.r_rx != modified->r.esp.r_rx) && - printf("%s esp:%lx\n", __func__, modified->r.esp.r_rx) && - (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RSP, modified->r.esp.r_rx)) != 0) - goto done; - - if ((orig->r.ss.r_rx != modified->r.ss.r_rx) && - printf("%s ss:%lx\n", __func__, modified->r.ss.r_rx) && - (error = vm_set_register(ctx, vcpu, VM_REG_GUEST_SS, modified->r.ss.r_rx)) != 0) - goto done; done: return (error); @@ -920,48 +935,84 @@ { int ret = 0; regcontext_t orig, modified; + regcontext_t *REGS = &modified; get_all_regs(ctx, vcpu, &orig); + { + u_int16_t *sp, eip, cs, efl; + + sp = (uint16_t *)(lomem_addr + orig.r.esp.r_rx); + eip = *sp; + cs = *(--sp); + efl = *(--sp); + fprintf(stderr, "%s eip:%x cs:%x efl:%x\n", + __func__, eip, cs, efl); + } modified = orig; - printf("%s orig RAX=%lx EAX=%x AX=%x AL=%x AH=%x\n", + fprintf(stderr, "%s orig RAX=%lx EAX=%x AX=%x AL=%x AH=%x\n", __func__, orig.r.eax.r_rx, orig.r.eax.r_dw.r_ex, orig.r.eax.r_w.r_x, orig.r.eax.r_b.r_l, orig.r.eax.r_b.r_h); - printf("%s orig RBX=%lx EBX=%x BX=%x BL=%x BH=%x\n", + fprintf(stderr, "%s orig RBX=%lx EBX=%x BX=%x BL=%x BH=%x\n", __func__, orig.r.ebx.r_rx, orig.r.ebx.r_dw.r_ex, orig.r.ebx.r_w.r_x, orig.r.ebx.r_b.r_l, orig.r.ebx.r_b.r_h); - printf("%s modified RAX=%lx EAX=%x AX=%x AL=%x AH=%x\n", + fprintf(stderr, "%s modified RAX=%lx EAX=%x AX=%x AL=%x AH=%x\n", __func__, modified.r.eax.r_rx, modified.r.eax.r_dw.r_ex, modified.r.eax.r_w.r_x, modified.r.eax.r_b.r_l, modified.r.eax.r_b.r_h); - printf("%s modified RBX=%lx EBX=%x BX=%x BL=%x BH=%x\n", + fprintf(stderr, "%s modified RBX=%lx EBX=%x BX=%x BL=%x BH=%x\n", __func__, modified.r.ebx.r_rx, modified.r.ebx.r_dw.r_ex, modified.r.ebx.r_w.r_x, modified.r.ebx.r_b.r_l, modified.r.ebx.r_b.r_h); + callback_t func = find_callback(MAKEVEC(R_CS, R_IP)); + fprintf(stderr, "%s R_CS:%x R_IP:%x MAKEVEC(R_CS, R_IP):%x func:%p\n", + __func__, R_CS, R_IP, MAKEVEC(R_CS, R_IP), func); + if (func) + func(&modified); - switch (intno) { - case 0x13: - printf("call int13\n"); - int13(&modified); - break; - default: - ret = -1; - } set_modified_regs(ctx, vcpu, &orig, &modified); return (ret); } +bool biosemul_inout_registered(int in, int port) +{ + return io_port_defined(in, port); +} + +int biosemul_inout(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, int strict) +{ + regcontext_t orig, modified; + + get_all_regs(ctx, vcpu, &orig); + modified = orig; + saved_regcontext = &modified; + + fprintf(stderr, "%s in:%d port:%x bytes:%d eax:%x strict:%d\n", + __func__, in, port, bytes, *eax, strict); + + if (in) + inb(&modified, port); + else + outb(&modified, port); + + set_modified_regs(ctx, vcpu, &orig, &modified); + + return 0; +} + + Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/biosemul.h Mon Aug 20 13:15:20 2012 (r240565) @@ -2,10 +2,14 @@ #ifndef _BIOSEMUL_H_ #define _BIOSEMUL_H_ +#include <stdbool.h> #include <machine/vmm.h> #include <vmmapi.h> -void biosemul_init(char *lomem); +void biosemul_init(struct vmctx *ctx, int vcpu, char *lomem); int biosemul_call(struct vmctx *ctx, int vcpu, int intno); +bool biosemul_inout_registered(int in, int port); +int biosemul_inout(struct vmctx *ctx, int vcpu, int in, int port, int bytes, + uint32_t *eax, int strict); #endif Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/callback.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/callback.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/callback.c Mon Aug 20 13:15:20 2012 (r240565) @@ -70,7 +70,7 @@ * stack which re-enables interrupts. */ u_char softint_trampoline[] = { - 0xf4, /* HLT */ + 0x0f, 0x01, 0xc1, /* VMCALL */ 0xfb, /* STI */ 0xca, /* RETF 2 */ 2, @@ -85,7 +85,7 @@ * driver is present and what level of functionality it provides. */ u_char fossil_softint_trampoline[] = { - 0xf4, /* HLT */ + 0x0f, 0x01, 0xc1, /* VMCALL */ 0xfb, /* STI */ 0xca, /* RETF 2 */ 2, @@ -96,7 +96,7 @@ 0x1b, /* Max. Supported FOSSIL AH */ }; u_char hardint_trampoline[] = { - 0xf4, /* HLT */ + 0x0f, 0x01, 0xc1, /* VMCALL */ 0xcf, /* IRET */ }; u_char null_trampoline[] = { @@ -110,7 +110,7 @@ u_int32_t where; where = trampoline_rover; - q = (u_char *)VECPTR(where); + q = (u_char *)(lomem_addr + VECPTR(where)); memcpy(q, p, len); trampoline_rover += len; return (where); Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/cpu.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/cpu.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/cpu.c Mon Aug 20 13:15:20 2012 (r240565) @@ -121,7 +121,7 @@ emu_instr(regcontext_t *REGS) { int prefix = 1; - u_int8_t *cs = (u_int8_t *)(uintptr_t)(R_CS << 4); + u_int8_t *cs = (u_int8_t *)(lomem_addr + (uintptr_t)(R_CS << 4)); int ip = R_IP; int dir, i, instrlen; u_int8_t *r8; @@ -400,7 +400,7 @@ if (addr >= 0xa0000 && addr < 0xb0000) return vga_read(addr); else - return *(u_int8_t *)(uintptr_t)addr; + return *(u_int8_t *)(uintptr_t)(lomem_addr + addr); } /* Write an 8-bit value to the location specified by 'addr'. If 'addr' lies @@ -411,7 +411,7 @@ if (addr >= 0xa0000 && addr < 0xb0000) vga_write(addr, val); else - *(u_int8_t *)(uintptr_t)addr = val; + *(u_int8_t *)(uintptr_t)(lomem_addr + addr) = val; return; } @@ -425,7 +425,7 @@ vga_write(addr, (u_int8_t)(val & 0xff)); vga_write(addr + 1, (u_int8_t)((val & 0xff00) >> 8)); } else - *(u_int16_t *)(uintptr_t)addr = val; + *(u_int16_t *)(uintptr_t)(lomem_addr + addr) = val; return; } Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/debug.c Mon Aug 20 13:15:20 2012 (r240565) @@ -162,13 +162,13 @@ debug (D_ALWAYS, "cs=%04x ss=%04x ds=%04x es=%04x\n", R_CS, R_SS, R_DS, R_ES); debug (D_ALWAYS, "ip=%x eflags=%"PRIx32"\n", R_IP, R_EFLAGS); - addr = (u_char *)MAKEPTR(R_CS, R_IP); + addr = (u_char *)(lomem_addr + MAKEPTR(R_CS, R_IP)); for (i = 0; i < 16; i++) debug (D_ALWAYS, "%02x ", addr[i]); debug (D_ALWAYS, "\n"); - addr = (char *)MAKEPTR(R_CS, R_IP); + addr = (char *)(lomem_addr + MAKEPTR(R_CS, R_IP)); i386dis(R_CS, R_IP, addr, buf, 0); debug (D_ALWAYS, "%s\n", buf); Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/doscmd.h Mon Aug 20 13:15:20 2012 (r240565) @@ -50,6 +50,7 @@ #include <string.h> #include <ucontext.h> #include <errno.h> +#include <stdbool.h> #include <sys/signalvar.h> #include <machine/sigframe.h> @@ -96,7 +97,6 @@ extern int nparallel; void bios_init(void); -#if 0 extern volatile int poll_cnt; void wakeup_poll(void); void reset_poll(void); @@ -105,6 +105,8 @@ /* cmos.c */ extern time_t delta_clock; +void cmos_init(void); + /* cpu.c */ void cpu_init(void); int emu_instr(regcontext_t *); @@ -112,7 +114,6 @@ void int01(regcontext_t *); void int03(regcontext_t *); void int0d(regcontext_t *); -#endif /* debug.c */ extern int vflag; @@ -200,7 +201,6 @@ extern int i386dis(unsigned short, unsigned short, unsigned char *, char *, int); -#if 0 /* int.c */ void init_ints(void); int isinhardint(int); @@ -213,7 +213,6 @@ /* int10.c */ extern void int10(regcontext_t *); -#endif /* int13.c */ extern int init_hdisk(int drive, int cyl, int head, int tracksize, @@ -222,13 +221,12 @@ extern int disk_fd(int drive); extern void make_readonly(int drive); extern int search_floppy(int i); -#if 0 extern void disk_bios_init(void); -#endif #if 0 /* int14.c */ extern int fossil; +#endif /* int16.c */ void int16(regcontext_t *); @@ -243,6 +241,7 @@ /* int1a.c */ void int1a(regcontext_t *); +#if 0 /* mem.c */ extern char *dosmem; @@ -251,6 +250,7 @@ extern int mem_adjust(long addr, int size, int *availp); extern void mem_free_owner(int owner); extern void mem_change_owner(long addr, int owner); +#endif /* mouse.c */ void int33(regcontext_t *); @@ -272,20 +272,26 @@ void outsb(regcontext_t *, int); void outsx(regcontext_t *, int); void outx(regcontext_t *, int); +bool io_port_defined(int, int); +#if 0 /* setver.c */ extern void setver(char *, short); extern short getver(char *); /* signal.c */ extern struct sigframe *saved_sigframe; +#endif extern regcontext_t *saved_regcontext; +#if 0 extern int saved_valid; extern void setsignal(int s, void (*h)(struct sigframe *)); +#endif /* timer.c */ extern void timer_init(void); +#if 0 /* trace.c */ extern int resettrace(regcontext_t *); extern void tracetrap(regcontext_t *); Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/int.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/int.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/int.c Mon Aug 20 13:15:20 2012 (r240565) @@ -35,7 +35,7 @@ void *arg; }; -static unsigned char IM; +static unsigned char IM, IM2; static int Irql; static struct IRQ Irqs[8]; @@ -54,7 +54,6 @@ return Irqs[irql].within; } -#if 0 static void set_vip(void) { @@ -74,12 +73,10 @@ R_EFLAGS &= ~PSL_VIP; } -#endif void resume_interrupt(void) { -#if 0 regcontext_t *REGS = saved_regcontext; int irql; @@ -99,7 +96,6 @@ } } set_vip(); -#endif } void @@ -124,7 +120,6 @@ void hardint(int irql) { -#if 0 regcontext_t *REGS = saved_regcontext; u_int32_t vec = ivec[8 + irql]; @@ -132,14 +127,18 @@ ** if we're dead, or there's no vector, or the saved registers ** are invalid */ +#if 0 if (dead || !saved_valid || vec == 0) +#else + if (dead || vec == 0) +#endif return; /* ** if the vector points into the BIOS, or the handler at the ** other end is just an IRET, don't bother */ - if ((vec >> 16) == 0xf000 || *(u_char *)VECPTR(vec) == 0xcf) + if ((vec >> 16) == 0xf000 || *(u_char *)(lomem_addr + VECPTR(vec)) == 0xcf) return; if (!int_allowed(irql)) { @@ -166,18 +165,15 @@ PUSH(R_IP, REGS); R_EFLAGS &= ~PSL_VIF; /* XXX disable interrupts */ PUTVEC(R_CS, R_IP, vec); -#endif } void unpend(int irql) { -#if 0 if (!Irqs[irql].pending) return; Irqs[irql].pending = 0; set_vip(); -#endif } static unsigned char @@ -194,15 +190,22 @@ } static unsigned char -imr_in(int port __unused) +imr_in(int port) { - return IM; + if (port == 0x21) + return IM; + else if (port == 0xa1) + return IM2; + return 0; } static void -imr_out(int port __unused, unsigned char val) +imr_out(int port, unsigned char val) { - IM = val; + if (port == 0x21) + IM = val; + else if (port == 0xa1) + IM2 = val; resume_interrupt(); } @@ -220,14 +223,18 @@ ** if we're dead, or there's no vector or the saved registers are ** invalid */ +#if 0 if (dead || !saved_valid || vec == 0) +#else + if (dead || vec == 0) +#endif return; /* ** if the vector points into the BIOS, or the handler at the other ** end is just an IRET, don't bother. */ - if ((vec >> 16) == 0xf000 || *(u_char *)VECPTR(vec) == 0xcf) + if ((vec >> 16) == 0xf000 || *(u_char *)(lomem_addr + VECPTR(vec)) == 0xcf) return; debug(D_TRAPS | intnum, "INT %02x [%04"PRIx32":%04"PRIx32"]\n", @@ -251,11 +258,16 @@ Irqs[i].within = 0; } - IM = 0x00; + IM = IM2 = 0x00; Irql = 8; define_input_port_handler(0x20, irqc_in); define_output_port_handler(0x20, irqc_out); define_input_port_handler(0x21, imr_in); define_output_port_handler(0x21, imr_out); + + define_input_port_handler(0xa0, irqc_in); + define_output_port_handler(0xa0, irqc_out); + define_input_port_handler(0xa1, imr_in); + define_output_port_handler(0xa1, imr_out); } Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/int10.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/int10.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/int10.c Mon Aug 20 13:15:20 2012 (r240565) @@ -49,6 +49,7 @@ int i, j; int saved_row, saved_col; + debug(D_DISK, "%s:%d AH:%x AL:%x FLAGS:%x\n", __func__, __LINE__, R_AH, R_AL, R_FLAGS); /* * Any call to the video BIOS is enough to reset the poll * count on the keyboard. @@ -157,7 +158,10 @@ debug(D_VIDEO, "Read graphics pixel at %d, %d\n", R_CX, R_DX); break; case 0x0e: /* write character */ +#if 0 tty_write(R_AL, -1); +#endif + tty_write(R_AL, TTYF_REDIRECT); break; case 0x0f: /* get current video mode */ R_AH = DpyCols; /* number of columns */ @@ -176,7 +180,7 @@ VGA_ATC[ATC_OverscanColor] = R_BH; break; case 0x02: /* Set all palette registers */ - addr = (char *)MAKEPTR(R_ES, R_DX); + addr = (char *)(lomem_addr + MAKEPTR(R_ES, R_DX)); for (i = 0; i < 16; i++) palette[i] = *addr++; VGA_ATC[ATC_OverscanColor] = *addr; @@ -192,7 +196,7 @@ R_BH = VGA_ATC[ATC_OverscanColor]; break; case 0x09: /* Read all palette registers */ - addr = (char *)MAKEPTR(R_ES, R_DX); + addr = (char *)(lomem_addr + MAKEPTR(R_ES, R_DX)); for (i = 0; i < 16; i++) *addr++ = palette[i]; *addr = VGA_ATC[ATC_OverscanColor]; @@ -204,7 +208,7 @@ update_pixels(); break; case 0x12: /* Set block of DAC registers */ - addr = (char *)MAKEPTR(R_ES, R_DX); + addr = (char *)(lomem_addr + MAKEPTR(R_ES, R_DX)); for (i = R_BX; i < R_BX + R_CX; i++) { dac_rgb[i].red = *addr++; dac_rgb[i].green = *addr++; @@ -231,7 +235,7 @@ R_CL = dac_rgb[R_BX].blue; break; case 0x17: /* Read block of DAC registers */ - addr = (char *)MAKEPTR(R_ES, R_DX); + addr = (char *)(lomem_addr + MAKEPTR(R_ES, R_DX)); for (i = R_BX; i < R_BX + R_CX; i++) { *addr++ = dac_rgb[i].red; *addr++ = dac_rgb[i].green; @@ -374,7 +378,7 @@ case 0x13: /* write character string */ if (!(xmode || quietmode)) goto unsupported; - addr = (char *)MAKEPTR(R_ES, R_BP); + addr = (char *)(lomem_addr + MAKEPTR(R_ES, R_BP)); switch (R_AL & 0x03) { case 0: tty_report(&saved_row, &saved_col); @@ -415,7 +419,7 @@ break; case 0x1b: /* Video Functionality/State information */ if (R_BX == 0) { - addr = (char *)MAKEPTR(R_ES, R_DI); + addr = (char *)(lomem_addr + MAKEPTR(R_ES, R_DI)); memcpy(addr, vga_status, 64); R_AL = 0x1b; } Modified: soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c ============================================================================== --- soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c Mon Aug 20 12:53:29 2012 (r240564) +++ soc2012/syuu/bhyve-bios/lib/libbiosemul/int13.c Mon Aug 20 13:15:20 2012 (r240565) @@ -589,13 +589,11 @@ int side; int drive; -#if 0 reset_poll(); -#endif R_FLAGS &= ~PSL_C; - printf("%s:%d AH:%x AL:%x FLAGS:%x\n", __func__, __LINE__, R_AH, R_AL, R_FLAGS); + debug(D_DISK, "%s:%d AH:%x AL:%x FLAGS:%x\n", __func__, __LINE__, R_AH, R_AL, R_FLAGS); drive = R_DL; @@ -619,11 +617,11 @@ break; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120820131520.B5BA01065670>