I added:
* Emulation of outsb/outsw/outsd (just like out)
* Emulation of insb/insw/insd (just like in)
* Emulation of hlt - virtual machine shuts down
* "Emulation" of invd, wbinvd - nothing to do because we don't have a cache model
in our vm
* cli/sti - report to user space; adds ability to allow/disallow irqs in the irq-plugin
Also did some reorg of user.c, but have to merge with Ramons, so it comes later.
Other (from last patch):
>> diff -urN freemware/CVS/Entries freemware-jens/CVS/Entries
>> --- freemware/CVS/Entries Wed Jan 12 11:46:02 2000
>> +++ freemware-jens/CVS/Entries Wed Jan 12 15:58:22 2000
>
>What a messy patch... what did you do to your CVS dirs ????
Yes, it bothers me too, does anyone know how to eliminate this?
>> - if (!create_proc_info_entry("freemware", 0, NULL, fmw_read_procmem))
>> + if (!create_proc_info_entry("freemware", 0, NULL, (void *)fmw_read_procmem))
>
>Oops. Is there a argument type mismatch? Don't hide it, fix it ;-)
Yes, came a compiler warning. Guess it should be a void *, so the compiler is friendly
;)
>- The memory-dump now ("vm-core") is not very useful.
> What I'd find interesting is that we'd dump a
> core-like ELF file with the memory and the processor
> state (registers),
I agree. I added this simliest case of a dump because I need it
in some cases (like today... ;) and it was quick and simple to
implement. A core-like ELF file is much better. And also the
ability to instect the guest memory during run time. If we have
this we should jettison the memory dump.
Perhaps we should add an ioctl for translating virtual to linear
and physical addresses for the case we don't have a flat memory
model or paging in the guest. For plugins to calculate adresses
given by segment selector and offset.
jens
-------------------------------------
diff -urN freemware/CVS/Entries freemware-jens/CVS/Entries
--- freemware/CVS/Entries Tue Jan 18 12:01:41 2000
+++ freemware-jens/CVS/Entries Tue Jan 18 12:03:08 2000
@@ -4,10 +4,10 @@
D/guest////
D/kernel////
D/user////
-/Makefile.in/1.5/Mon Jan 3 14:45:27 2000//
-/README/1.3/Mon Jan 10 10:37:07 2000//
-/config.h.in/1.2/Mon Jan 10 10:37:07 2000//
-/configure/1.4/Mon Jan 10 10:37:07 2000//
-/configure.in/1.4/Mon Jan 10 10:37:07 2000//
-/configure.linux/1.3/Mon Jan 10 10:37:07 2000//
-/ChangeLog/1.44/Tue Jan 18 11:01:41 2000//
+/Makefile.in/1.5/Fri Jan 7 13:31:44 2000//
+/README/1.3/Mon Jan 10 10:42:03 2000//
+/config.h.in/1.2/Mon Jan 10 10:42:03 2000//
+/configure/1.4/Mon Jan 10 10:42:04 2000//
+/configure.in/1.4/Mon Jan 10 10:42:04 2000//
+/configure.linux/1.3/Mon Jan 10 10:42:04 2000//
+/ChangeLog/1.44/Tue Jan 18 11:03:08 2000//
diff -urN freemware/guest/CVS/Entries freemware-jens/guest/CVS/Entries
--- freemware/guest/CVS/Entries Thu Dec 2 11:03:52 1999
+++ freemware-jens/guest/CVS/Entries Fri Jan 7 14:31:44 2000
@@ -2,4 +2,4 @@
D/cooperative////
D/preemptive////
D/virtcode////
-/Makefile.in/1.2/Thu Dec 2 10:03:52 1999//
+/Makefile.in/1.2/Fri Jan 7 13:31:44 2000//
diff -urN freemware/guest/cooperative/CVS/Entries
freemware-jens/guest/cooperative/CVS/Entries
--- freemware/guest/cooperative/CVS/Entries Mon Jan 10 11:37:07 2000
+++ freemware-jens/guest/cooperative/CVS/Entries Mon Jan 10 11:42:04 2000
@@ -1,7 +1,7 @@
/gdt.c/1.1/Sun Nov 14 15:06:47 1999//
/main.c/1.1/Sun Nov 14 15:06:47 1999//
D/include////
-/entry.S/1.2/Mon Jan 3 14:45:27 2000//
-/intr.c/1.2/Mon Jan 3 14:45:27 2000//
-/.cvsignore/1.2/Mon Jan 10 10:37:07 2000//
-/Makefile.in/1.4/Mon Jan 10 10:37:07 2000//
+/entry.S/1.2/Fri Jan 7 13:31:44 2000//
+/intr.c/1.2/Fri Jan 7 13:31:44 2000//
+/.cvsignore/1.2/Mon Jan 10 10:42:04 2000//
+/Makefile.in/1.4/Mon Jan 10 10:42:04 2000//
diff -urN freemware/guest/preemptive/CVS/Entries
freemware-jens/guest/preemptive/CVS/Entries
--- freemware/guest/preemptive/CVS/Entries Mon Jan 10 11:37:07 2000
+++ freemware-jens/guest/preemptive/CVS/Entries Mon Jan 10 11:42:04 2000
@@ -1,7 +1,7 @@
/gdt.c/1.1/Sun Nov 14 15:06:47 1999//
/main.c/1.1/Sun Nov 14 15:06:47 1999//
D/include////
-/entry.S/1.2/Mon Jan 3 14:45:27 2000//
-/intr.c/1.2/Mon Jan 3 14:45:27 2000//
-/.cvsignore/1.2/Mon Jan 10 10:37:07 2000//
-/Makefile.in/1.4/Mon Jan 10 10:37:07 2000//
+/entry.S/1.2/Fri Jan 7 13:31:44 2000//
+/intr.c/1.2/Fri Jan 7 13:31:44 2000//
+/.cvsignore/1.2/Mon Jan 10 10:42:04 2000//
+/Makefile.in/1.4/Mon Jan 10 10:42:04 2000//
diff -urN freemware/guest/virtcode/CVS/Entries
freemware-jens/guest/virtcode/CVS/Entries
--- freemware/guest/virtcode/CVS/Entries Mon Jan 17 14:41:37 2000
+++ freemware-jens/guest/virtcode/CVS/Entries Tue Jan 18 12:03:09 2000
@@ -1,4 +1,4 @@
-/.cvsignore/1.2/Mon Jan 10 10:37:07 2000//
-/Makefile.in/1.4/Mon Jan 10 10:37:07 2000//
-/virtcode.c/1.2/Mon Jan 17 13:41:37 2000//
+/.cvsignore/1.2/Mon Jan 10 10:42:04 2000//
+/Makefile.in/1.4/Mon Jan 10 10:42:04 2000//
+/virtcode.c/1.2/Mon Jan 17 19:46:23 2000//
D
diff -urN freemware/kernel/CVS/Entries freemware-jens/kernel/CVS/Entries
--- freemware/kernel/CVS/Entries Mon Jan 17 14:41:38 2000
+++ freemware-jens/kernel/CVS/Entries Tue Jan 18 12:03:09 2000
@@ -1,9 +1,9 @@
/.cvsignore/1.1/Wed Sep 8 19:26:39 1999//
D/include////
-/host-beos.c/1.4/Mon Jan 3 14:45:27 2000//
+/host-beos.c/1.4/Fri Jan 7 13:31:44 2000//
/nexus.S/1.7/Fri Dec 31 20:12:32 1999//
-/Makefile.in/1.9/Mon Jan 10 10:37:07 2000//
-/emulation.c/1.8/Mon Jan 17 13:41:37 2000//
-/fault.c/1.4/Mon Jan 17 13:41:37 2000//
-/host-linux.c/1.23/Mon Jan 17 13:41:37 2000//
-/monitor.c/1.19/Mon Jan 17 13:41:38 2000//
+/Makefile.in/1.9/Mon Jan 10 10:42:04 2000//
+/emulation.c/1.8/Result of merge+Mon Jan 17 13:45:50 2000//
+/host-linux.c/1.23/Result of merge+Mon Jan 17 13:45:50 2000//
+/monitor.c/1.19/Mon Jan 17 13:45:50 2000//
+/fault.c/1.4/Mon Jan 17 13:45:50 2000//
diff -urN freemware/kernel/emulation.c freemware-jens/kernel/emulation.c
--- freemware/kernel/emulation.c Mon Jan 17 14:41:37 2000
+++ freemware-jens/kernel/emulation.c Tue Jan 18 11:32:19 2000
@@ -26,11 +26,11 @@
/*
* Prototypes for instructions faulting in ring 3
*/
-int emulate_hlt(void);
-int emulate_cli(void);
-int emulate_sti(void);
-int emulate_ins(void);
-int emulate_outs(void);
+int emulate_hlt(guest_context_t *context);
+int emulate_cli(guest_context_t *context);
+int emulate_sti(guest_context_t *context);
+int emulate_ins(guest_context_t *context, int op_size);
+int emulate_outs(guest_context_t *context, int op_size);
int emulate_clts(void);
int emulate_rdmsr(void);
int emulate_wrmsr(void);
@@ -452,6 +452,22 @@
action = emulate_load_ds(context, val);
break;
+ case 0x6c: /* insb == ins dx, m8 */
+ action = emulate_ins(context,8);
+ break;
+
+ case 0x6d: /* insw || insd */
+ action = emulate_ins(context, operand_size);
+ break;
+
+ case 0x6e: /* outsb == outs dx, m8 */
+ action = emulate_outs(context,8);
+ break;
+
+ case 0x6f: /* outsw || outsd */
+ action = emulate_outs(context, operand_size);
+ break;
+
case 0x8e: /* mov Sw, Ew */
c = read_guest_byte(&eip); /* RegModRM */
val = decode_rm_operand(context, 16, address_size, c, &eip);
@@ -511,12 +527,17 @@
action = emulate_out(context, operand_size, context->edx & 0xffff);
break;
+ case 0xf4: /* hlt */
+ action = emulate_hlt(context);
+ context->eip=eip;
+ break;
+
case 0xfa: /* cli */
- action = emulate_cli();
+ action = emulate_cli(context);
break;
case 0xfb: /* sti */
- action = emulate_sti();
+ action = emulate_sti(context);
break;
case 0x0f:
@@ -562,6 +583,16 @@
action = emulate_clts();
break;
+ case 0x08: /* invd */
+ action = emulate_invd();
+ context->eip=eip;
+ break;
+
+ case 0x09: /* wbinvd */
+ action = emulate_wbinvd();
+ context->eip=eip;
+ break;
+
case 0xa1: /* pop FS */
val = guest_stack_pop(&esp, operand_size);
action = emulate_load_fs(context, val);
@@ -594,7 +625,6 @@
context->eip = eip;
context->esp = esp;
return 2;
-
case 4: /* Try to emulate in user space */
context->eip = eip;
context->esp = esp;
@@ -604,25 +634,23 @@
int
-emulate_cli(void)
+emulate_cli(guest_context_t *context)
/*
* Emulate cli instruction
*/
{
- /* here may reside some checks or so and emulation code */
- vm_nexus()->debug_msg.msg_code = EMU_CLI_MSG;
- return 0;
+ context->event_info=EMU_INSTR_CLI | (RET_BECAUSE_USEREMU << 8);
+ return 4;
}
int
-emulate_sti(void)
+emulate_sti(guest_context_t *context)
/*
* Emulate sti instruction
*/
{
- /* here may reside some checks or so and emulation code */
- vm_nexus()->debug_msg.msg_code = EMU_STI_MSG;
- return 0;
+ context->event_info=EMU_INSTR_STI | (RET_BECAUSE_USEREMU << 8);
+ return 4;
}
int
@@ -1028,3 +1056,56 @@
return 4;
}
+int
+emulate_outs(guest_context_t *context, int operand_size)
+ /*
+ * Emulate outs instruction
+ */
+{
+ switch(operand_size)
+ {
+ case 8: context->event_info=EMU_INSTR_OUTS_8;break;
+ case 16: context->event_info=EMU_INSTR_OUTS_16;break;
+ case 32: context->event_info=EMU_INSTR_OUTS_32;break;
+ }
+ context->event_info |= (RET_BECAUSE_USEREMU << 8);
+ return 4;
+}
+
+
+int
+emulate_ins(guest_context_t *context, int operand_size)
+ /*
+ * Emulate ins instruction
+ */
+{
+ switch(operand_size)
+ {
+ case 8: context->event_info=EMU_INSTR_INS_8;break;
+ case 16: context->event_info=EMU_INSTR_INS_16;break;
+ case 32: context->event_info=EMU_INSTR_INS_32;break;
+ }
+ context->event_info |= (RET_BECAUSE_USEREMU << 8);
+ return 4;
+}
+
+int
+emulate_invd() {
+
+ /* nothing to do ;) */
+ return 1;
+}
+
+int
+emulate_wbinvd() {
+
+ /* nothing to do ;) */
+ return 1;
+}
+
+int
+emulate_hlt(guest_context_t *context) {
+
+ context->event_info=EMU_INSTR_HLT | (RET_BECAUSE_USEREMU << 8);
+ return 4;
+}
diff -urN freemware/kernel/host-linux.c freemware-jens/kernel/host-linux.c
--- freemware/kernel/host-linux.c Mon Jan 17 14:41:37 2000
+++ freemware-jens/kernel/host-linux.c Tue Jan 18 12:18:14 2000
@@ -121,7 +121,7 @@
// register the /proc entry
#ifdef CONFIG_PROC_FS
#if LINUX_VERSION_CODE >= VERSION_CODE(2,3,25)
- if (!create_proc_info_entry("freemware", 0, NULL, fmw_read_procmem))
+ if (!create_proc_info_entry("freemware", 0, NULL, (void *)fmw_read_procmem))
printk(KERN_ERR "freemware: registering /proc/freewmare failed\n");
#else
proc_register_dynamic(&proc_root, &fmw_proc_entry);
@@ -470,7 +470,6 @@
printk(KERN_WARNING "freemware: trying to load %04x into %cS failed\n",
vm->nexus->debug_msg.para2, vm->nexus->debug_msg.para1);
break;
-
default:
printk(KERN_WARNING "freemware: unknown emulation error (%d) [0x%x :
0x%x]\n",
vm->nexus->debug_msg.msg_code,
diff -urN freemware/kernel/include/CVS/Entries
freemware-jens/kernel/include/CVS/Entries
--- freemware/kernel/include/CVS/Entries Mon Jan 17 14:41:38 2000
+++ freemware-jens/kernel/include/CVS/Entries Mon Jan 17 14:45:50 2000
@@ -5,7 +5,7 @@
/tss.h/1.2/Tue Sep 7 20:13:50 1999//
/elf.h/1.1/Fri Nov 26 19:16:40 1999//
/elf_machine.h/1.1/Fri Nov 26 19:16:40 1999//
-/host-linux.h/1.7/Mon Jan 3 14:45:27 2000//
-/freemware.h/1.4/Mon Jan 17 13:41:38 2000//
-/monitor.h/1.16/Mon Jan 17 13:41:38 2000//
+/host-linux.h/1.7/Fri Jan 7 13:31:45 2000//
+/freemware.h/1.4/Result of merge+Mon Jan 17 13:45:50 2000//
+/monitor.h/1.16/Result of merge//
D
diff -urN freemware/kernel/include/freemware.h
freemware-jens/kernel/include/freemware.h
--- freemware/kernel/include/freemware.h Mon Jan 17 14:41:38 2000
+++ freemware-jens/kernel/include/freemware.h Tue Jan 18 12:18:34 2000
@@ -103,4 +103,16 @@
#define EMU_INSTR_IN_16 5
#define EMU_INSTR_IN_32 6
+#define EMU_INSTR_OUTS_8 7
+#define EMU_INSTR_OUTS_16 8
+#define EMU_INSTR_OUTS_32 9
+#define EMU_INSTR_INS_8 10
+#define EMU_INSTR_INS_16 11
+#define EMU_INSTR_INS_32 12
+
+#define EMU_INSTR_HLT 13
+
+#define EMU_INSTR_CLI 14
+#define EMU_INSTR_STI 15
+
#endif // #ifndef __FREEMWARE_H__
diff -urN freemware/kernel/include/monitor.h freemware-jens/kernel/include/monitor.h
--- freemware/kernel/include/monitor.h Mon Jan 17 14:41:38 2000
+++ freemware-jens/kernel/include/monitor.h Tue Jan 18 12:19:15 2000
@@ -54,7 +54,6 @@
#define EMU_LOAD_SEGREG_MSG 8
-
// Method1: push event info (CPU pushes error code before)
typedef struct {
unsigned char pushl; /* Always 0x68 == pushl */
diff -urN freemware/user/CVS/Entries freemware-jens/user/CVS/Entries
--- freemware/user/CVS/Entries Tue Jan 18 12:01:47 2000
+++ freemware-jens/user/CVS/Entries Tue Jan 18 12:03:10 2000
@@ -1,12 +1,12 @@
-/.cvsignore/1.2/Mon Jan 10 10:37:07 2000//
-/decode.h/1.3/Mon Jan 10 10:37:08 2000//
-/fmw.conf/1.7/Result of merge+Mon Jan 10 10:37:08 2000//
-/resetmod.c/1.5/Mon Jan 10 10:37:08 2000//
+/.cvsignore/1.2/Mon Jan 10 10:42:04 2000//
+/decode.h/1.3/Mon Jan 10 10:42:05 2000//
+/fmw.conf/1.7/Mon Jan 10 10:42:05 2000//
+/resetmod.c/1.5/Mon Jan 10 10:42:05 2000//
/vga_io.log/1.1/Fri Jan 7 22:45:45 2000//
D/plugins////
-/Makefile.in/1.11/Mon Jan 17 13:41:38 2000//
-/decode.c/1.7/Mon Jan 17 13:41:38 2000//
-/plugin.c/1.2/Tue Jan 18 11:01:43 2000//
-/plugin.h/1.2/Tue Jan 18 11:01:43 2000//
-/user.c/1.22/Tue Jan 18 11:01:43 2000//
-/user.h/1.4/Tue Jan 18 11:01:43 2000//
+/Makefile.in/1.11/Mon Jan 17 13:45:50 2000//
+/decode.c/1.7/Mon Jan 17 13:45:51 2000//
+/plugin.c/1.2/Tue Jan 18 11:03:09 2000//
+/plugin.h/1.2/Tue Jan 18 11:03:09 2000//
+/user.c/1.22/Result of merge//
+/user.h/1.4/Tue Jan 18 11:03:09 2000//
diff -urN freemware/user/fmw.conf freemware-jens/user/fmw.conf
--- freemware/user/fmw.conf Mon Jan 10 11:39:32 2000
+++ freemware-jens/user/fmw.conf Mon Jan 10 11:42:05 2000
@@ -3,6 +3,7 @@
####################################################################
+
####################################################################
# General settings
####################################################################
diff -urN freemware/user/plugins/bochs/CVS/Entries
freemware-jens/user/plugins/bochs/CVS/Entries
--- freemware/user/plugins/bochs/CVS/Entries Tue Jan 18 12:01:44 2000
+++ freemware-jens/user/plugins/bochs/CVS/Entries Tue Jan 18 12:03:10 2000
@@ -5,6 +5,6 @@
/state_file.h/1.1/Sun Jan 9 21:49:15 2000//
D/gui////
D/iodev////
-/bochs.h/1.2/Mon Jan 17 13:41:39 2000//
-/io.cc/1.6/Tue Jan 18 11:01:44 2000//
-/state_file.cc/1.4/Tue Jan 18 11:01:44 2000//
+/bochs.h/1.2/Mon Jan 17 13:45:51 2000//
+/io.cc/1.6/Tue Jan 18 11:03:10 2000//
+/state_file.cc/1.4/Tue Jan 18 11:03:10 2000//
diff -urN freemware/user/plugins/bochs/gui/CVS/Entries
freemware-jens/user/plugins/bochs/gui/CVS/Entries
--- freemware/user/plugins/bochs/gui/CVS/Entries Mon Jan 17 14:41:39 2000
+++ freemware-jens/user/plugins/bochs/gui/CVS/Entries Mon Jan 17 14:45:51 2000
@@ -8,4 +8,4 @@
/win32.cc/1.1/Sun Jan 9 21:49:15 2000//
/x.cc/1.1/Sun Jan 9 21:49:15 2000//
D/bitmaps////
-/Makefile.in/1.4/Mon Jan 17 13:41:39 2000//
+/Makefile.in/1.4/Mon Jan 17 13:45:51 2000//
diff -urN freemware/user/plugins/bochs/iodev/CVS/Entries
freemware-jens/user/plugins/bochs/iodev/CVS/Entries
--- freemware/user/plugins/bochs/iodev/CVS/Entries Mon Jan 17 14:41:39 2000
+++ freemware-jens/user/plugins/bochs/iodev/CVS/Entries Mon Jan 17 14:45:51 2000
@@ -4,6 +4,6 @@
/keyboard.h/1.1/Sun Jan 9 21:49:15 2000//
/vga.cc/1.1/Sun Jan 9 21:49:15 2000//
/vga.h/1.1/Sun Jan 9 21:49:15 2000//
-/Makefile.in/1.4/Mon Jan 17 13:41:39 2000//
-/devices.cc/1.2/Mon Jan 17 13:41:39 2000//
+/Makefile.in/1.4/Mon Jan 17 13:45:51 2000//
+/devices.cc/1.2/Mon Jan 17 13:45:51 2000//
D
diff -urN freemware/user/plugins/ice/CVS/Entries
freemware-jens/user/plugins/ice/CVS/Entries
--- freemware/user/plugins/ice/CVS/Entries Tue Jan 18 12:01:47 2000
+++ freemware-jens/user/plugins/ice/CVS/Entries Tue Jan 18 12:03:10 2000
@@ -4,7 +4,7 @@
/low-freemware.c/1.2/Sun Jan 9 23:06:15 2000//
/utils.c/1.1/Sun Jan 9 21:53:47 2000//
/PROTOCOL/1.1/Tue Jan 11 19:54:53 2000//
-/server.c/1.2/Mon Jan 17 13:41:39 2000//
-/server.h/1.2/Mon Jan 17 13:41:39 2000//
-/remote-utils.c/1.3/Tue Jan 18 11:01:47 2000//
+/server.c/1.2/Mon Jan 17 13:45:52 2000//
+/server.h/1.2/Mon Jan 17 13:45:52 2000//
+/remote-utils.c/1.3/Tue Jan 18 11:03:10 2000//
D
diff -urN freemware/user/user.c freemware-jens/user/user.c
--- freemware/user/user.c Tue Jan 18 12:01:43 2000
+++ freemware-jens/user/user.c Tue Jan 18 12:03:09 2000
@@ -728,6 +728,49 @@
plugin_emulate (EVT_OUTPORT, arg, 4, 1, &value);
break;
+ case EMU_INSTR_INS_8:
+ plugin_emulate(EVT_INPORT,context.edx & 0xffff,1,1,&value);
+ /* FIXME: works only with flat memory models without paging and ES == DS
+*/
+ *(u8 *)(ptr+context.edi)=(u8)value;
+ break;
+
+ case EMU_INSTR_INS_16:
+ plugin_emulate(EVT_INPORT,context.edx & 0xffff,2,1,&value);
+ /* FIXME: works only with flat memory models without paging and ES == DS
+*/
+ *(u16 *)(ptr+context.edi)=(u16)value;
+ break;
+
+ case EMU_INSTR_INS_32:
+ plugin_emulate(EVT_INPORT,context.edx & 0xffff,4,1,&value);
+ /* FIXME: works only with flat memory models without paging and ES == DS
+*/
+ *(u32 *)(ptr+context.edi)=value;
+ break;
+
+ case EMU_INSTR_OUTS_8:
+ /* FIXME: works only with flat memory models without paging and ES == DS
+*/
+ value=*(u8 *)(ptr+context.edi);
+ plugin_emulate(EVT_OUTPORT,context.edx & 0xffff,1,1,&value);
+ break;
+
+ case EMU_INSTR_OUTS_16:
+ /* FIXME: works only with flat memory models without paging and ES == DS
+*/
+ value=*(u16 *)(ptr+context.edi);
+ plugin_emulate(EVT_OUTPORT,context.edx & 0xffff,2,1,&value);
+ break;
+
+ case EMU_INSTR_OUTS_32:
+ /* FIXME: works only with flat memory models without paging and ES == DS
+*/
+ value=*(u32 *)(ptr+context.edi);
+ plugin_emulate(EVT_OUTPORT,context.edx & 0xffff,4,1,&value);
+ break;
+
+ case EMU_INSTR_HLT:
+ fprintf(stderr,"HLT -- shutting down virtual machine\n");
+ abort_vm=1;
+ break;
+
+ case EMU_INSTR_CLI:
+ case EMU_INSTR_STI:
default:
fprintf (stderr, "Emulation of instruction 0x%x (0x%04x) not yet
implemented\n",
instr, arg);