Hi. I made a change so plex86 uses the Linux kernel's memcpy(), memset(),
etc functions instead of the ones in util-nexus.c. The kernel's versions
are written in x86 assembly, and are optimized based on which CPU type you
select when you build the kernel. I figure they have to be faster than
gcc's version of unoptimized c-code. Also, this is for the kernel module,
so it only makes sense...
The patch is included. It's against the cvs tree I got last night. Let
me know if you have any problems.
diff -ur plex86/kernel/Makefile.in plex86.mod1/kernel/Makefile.in
--- plex86/kernel/Makefile.in Mon Sep 10 13:48:14 2001
+++ plex86.mod1/kernel/Makefile.in Wed Mar 6 21:46:48 2002
@@ -64,7 +64,7 @@
$(KERNEL_TARGET): $(HOST_O) monitor-host.o \
nexus.o flag-nexus.o print-nexus.o \
- mode-nexus.o util-nexus.o system-nexus.o \
+ mode-nexus.o system-nexus.o \
fault-mon.o phymem-mon.o panic-mon.o \
paging-mon.o system-mon.o mode-mon.o instrument-mon.o \
segment-mon.o emulation/emu.o iodev/iodev.o
Only in plex86.mod1/kernel/dt: Makefile
diff -ur plex86/kernel/dt/dt-mon.c plex86.mod1/kernel/dt/dt-mon.c
--- plex86/kernel/dt/dt-mon.c Thu May 24 13:54:18 2001
+++ plex86.mod1/kernel/dt/dt-mon.c Wed Mar 6 10:32:30 2002
@@ -20,6 +20,7 @@
*/
+#include <linux/string.h>
#include "plex86.h"
#define IN_MONITOR_SPACE
#include "monitor.h"
@@ -392,7 +393,7 @@
DontZero | AtHead, &tcodeChunkUsed);
dtValidateTcodeAddr(vm, tcodePtr, tcodeLen);
/* Copy tcode sequence to tcode buffer (chunk) area. */
- mon_memcpy(tcodePtr, tcode, tcodeLen);
+ memcpy(tcodePtr, tcode, tcodeLen);
for (o=0; o<tcodeSnippetsN; o++) {
Bit32u tcodeOffset, gOff;
@@ -645,7 +646,7 @@
/* Zero structure if requested. */
if (requests & DoZero)
- mon_memset(dataPtr, 0, size);
+ memset(dataPtr, 0, size);
dtValidateTcodeAddr(vm, dataPtr, size);
return( dataPtr );
@@ -679,7 +680,7 @@
chunk = (cluster<<3) | bit;
tcodeChunkUsage[cluster] |= bitmask; /* Mark chunk in-use */
/* Zero allocated chunk. xxx We could zero only the header here */
- mon_memset(&tcodeChunk[chunk], 0, sizeof(tcodeChunk_t));
+ memset(&tcodeChunk[chunk], 0, sizeof(tcodeChunk_t));
/* Mark the header as used space */
tcodeChunk[chunk].header.head = sizeof(tcodeChunk[0].header);
/* The free-space tail starts at the end of the chunk */
@@ -860,7 +861,7 @@
allocated:
/* Zero allocated meta page. xxx Might be able to avoid this */
- mon_memset(&dtPageMetaTable[metaI], 0, sizeof(dtPageMeta_t));
+ memset(&dtPageMetaTable[metaI], 0, sizeof(dtPageMeta_t));
dtPageMetaTable[metaI].ts.mon_created = vm_rdtsc();
return( metaI );
}
diff -ur plex86/kernel/dt/dt-nexus.c plex86.mod1/kernel/dt/dt-nexus.c
--- plex86/kernel/dt/dt-nexus.c Thu May 24 13:54:18 2001
+++ plex86.mod1/kernel/dt/dt-nexus.c Wed Mar 6 10:32:28 2002
@@ -21,6 +21,7 @@
*/
+#include <linux/string.h>
#include "plex86.h"
#define IN_NEXUS_SPACE
#include "monitor.h"
@@ -34,8 +35,8 @@
dtInitialize(vm_t *vm)
{
/* Zero L2M and G2T hash tables for good measure. */
- mon_memset(vm->addr->dtL2MHash, 0, sizeof(dtL2MHash_t));
- mon_memset(vm->addr->dtG2THash, 0, sizeof(dtG2THash_t));
+ memset(vm->addr->dtL2MHash, 0, sizeof(dtL2MHash_t));
+ memset(vm->addr->dtG2THash, 0, sizeof(dtG2THash_t));
/* Now, init the hash tables. */
dtInitHashTables(vm);
@@ -43,14 +44,14 @@
/* Zero the page meta info table, and usage bitlist. This stores
* DT info about each associated guest code page.
*/
- mon_memset(vm->addr->dtPageMetaTable, 0,
+ memset(vm->addr->dtPageMetaTable, 0,
sizeof(dtPageMeta_t) * DTPageMetaTableN);
- mon_memset(vm->addr->dtPageMetaTableUsage, 0,
+ memset(vm->addr->dtPageMetaTableUsage, 0,
sizeof(Bit8u) * ((DTPageMetaTableN+7) / 8));
/* Initialize the tcode chunks, and usage bitlist. */
- mon_memset(vm->addr->tcodeChunk, 0, SizeOfTcodeBuffer);
- mon_memset(vm->addr->tcodeChunkUsage, 0,
+ memset(vm->addr->tcodeChunk, 0, SizeOfTcodeBuffer);
+ memset(vm->addr->tcodeChunkUsage, 0,
sizeof(Bit8u) * ((TCodeChunkN+7) / 8));
}
diff -ur plex86/kernel/include/monitor.h plex86.mod1/kernel/include/monitor.h
--- plex86/kernel/include/monitor.h Mon Aug 6 04:39:50 2001
+++ plex86.mod1/kernel/include/monitor.h Wed Mar 6 21:54:59 2002
@@ -823,9 +823,6 @@
#define cache_sreg(vm, sreg) ({})
#define cache_selector(vm, sreg) ({})
-void mon_memzero(void *ptr, int size);
-void mon_memcpy(void *dst, void *src, int size);
-void *mon_memset(void *s, unsigned c, unsigned n);
unsigned isV86MCompatible(vm_t *);
#define MON_BASE_FROM_LADDR(laddr) \
diff -ur plex86/kernel/instrument-mon.c plex86.mod1/kernel/instrument-mon.c
--- plex86/kernel/instrument-mon.c Thu May 24 13:55:10 2001
+++ plex86.mod1/kernel/instrument-mon.c Wed Mar 6 10:27:55 2002
@@ -49,7 +49,7 @@
void
instrReset(vm_t *vm)
{
- mon_memzero(&emulateOpcodeFrequency, sizeof(emulateOpcodeFrequency));
+ memset(&emulateOpcodeFrequency, 0, sizeof(emulateOpcodeFrequency));
}
void
instrPrint(vm_t *vm)
diff -ur plex86/kernel/iodev/pic-nexus.c plex86.mod1/kernel/iodev/pic-nexus.c
--- plex86/kernel/iodev/pic-nexus.c Thu Jun 7 10:40:56 2001
+++ plex86.mod1/kernel/iodev/pic-nexus.c Wed Mar 6 10:32:37 2002
@@ -22,6 +22,7 @@
*/
+#include <linux/string.h>
#include "plex86.h"
#define IN_NEXUS_SPACE
#include "monitor.h"
@@ -31,7 +32,7 @@
void
picInit(vm_t *vm)
{
- mon_memzero(&vm->pic, sizeof(vm->pic));
+ memset(&vm->pic, 0, sizeof(vm->pic));
registerIORHandler(vm, MonitorSpace, 0, picIORead, 0x0020, 1, "8259 PIC");
registerIORHandler(vm, MonitorSpace, 0, picIORead, 0x0021, 1, "8259 PIC");
diff -ur plex86/kernel/iodev/pit-nexus.c plex86.mod1/kernel/iodev/pit-nexus.c
--- plex86/kernel/iodev/pit-nexus.c Thu Jun 7 10:40:56 2001
+++ plex86.mod1/kernel/iodev/pit-nexus.c Wed Mar 6 10:32:34 2002
@@ -22,6 +22,7 @@
*/
+#include <linux/string.h>
#include "plex86.h"
#define IN_NEXUS_SPACE
#include "monitor.h"
@@ -138,7 +139,7 @@
{
timerRegister_t timer;
- mon_memzero(&vm->pit, sizeof(vm->pit));
+ memset(&vm->pit, 0, sizeof(vm->pit));
timer.thisPtr = 0; /* Unused for monitor space. */
timer.callback = (void *) pitTimerCallback;
diff -ur plex86/kernel/monitor-host.c plex86.mod1/kernel/monitor-host.c
--- plex86/kernel/monitor-host.c Mon Aug 6 04:39:50 2001
+++ plex86.mod1/kernel/monitor-host.c Wed Mar 6 10:28:36 2002
@@ -21,6 +21,7 @@
*/
+#include <linux/string.h>
#include "plex86.h"
#define IN_HOST_SPACE
#include "monitor.h"
@@ -190,13 +191,13 @@
vm->system.a20IndexMask = 0x000fffff; /* all address lines contribute */
/* Initialize nexus */
- mon_memzero(vm->host.addr.nexus, 4096);
+ memset(vm->host.addr.nexus, 0, 4096);
/* Copy transition code (nexus) into code page allocated for this VM. */
nexus_size = ((Bit32u) &__nexus_end) - ((Bit32u) &__nexus_start);
if (nexus_size > 4096)
goto error;
- mon_memcpy(vm->host.addr.nexus, &__nexus_start, nexus_size);
+ memcpy(vm->host.addr.nexus, &__nexus_start, nexus_size);
/* Init the convenience pointers. */
@@ -210,15 +211,15 @@
(sizeof(guest_context_t) + sizeof(v86_sregs_t)) );
/* Zero out various monitor data structures */
- mon_memzero(vm->host.addr.log_buffer, 4096*LOG_BUFF_PAGES);
- mon_memzero(&vm->log_buffer_info,
+ memset(vm->host.addr.log_buffer, 0, 4096*LOG_BUFF_PAGES);
+ memset(&vm->log_buffer_info, 0,
sizeof(vm->log_buffer_info));
- mon_memzero(vm->host.addr.page_dir, 4096);
- mon_memzero(vm->host.addr.idt, MON_IDT_PAGES*4096);
- mon_memzero(vm->host.addr.gdt, MON_GDT_PAGES*4096);
- mon_memzero(vm->host.addr.ldt, MON_LDT_PAGES*4096);
- mon_memzero(vm->host.addr.tss, MON_TSS_PAGES*4096);
- mon_memzero(vm->host.addr.idt_stubs, MON_IDT_STUBS_PAGES*4096);
+ memset(vm->host.addr.page_dir, 0, 4096);
+ memset(vm->host.addr.idt, 0, MON_IDT_PAGES*4096);
+ memset(vm->host.addr.gdt, 0, MON_GDT_PAGES*4096);
+ memset(vm->host.addr.ldt, 0, MON_LDT_PAGES*4096);
+ memset(vm->host.addr.tss, 0, MON_TSS_PAGES*4096);
+ memset(vm->host.addr.idt_stubs, 0, MON_IDT_STUBS_PAGES*4096);
/*
@@ -262,7 +263,7 @@
/* clear Page Table */
pageTable = vm->host.addr.nexus_page_tbl;
- mon_memzero(pageTable, 4096);
+ memset(pageTable, 0, 4096);
/* xxx Comment here */
laddr = 0;
@@ -567,7 +568,7 @@
/* Clear Page Table; only one PTE is used. */
pageTable = vm->host.addr.transition_PT;
- mon_memzero(pageTable, 4096);
+ memset(pageTable, 0, 4096);
/* Fill in the PTE for identity mapping the code page */
pageTable->pte[pti].fields.base = vm->pages.nexus;
@@ -654,7 +655,7 @@
* Setup the initial guest context
*/
- mon_memzero(vm->host.addr.guest_context, sizeof(guest_context_t));
+ memset(vm->host.addr.guest_context, 0, sizeof(guest_context_t));
/* Wind up the monitor stack such that it looks like we just finished */
/* handling an event (like an interrupt), and are returning back to */
@@ -838,7 +839,7 @@
initGuestPhyMem(vm_t *vm)
{
unsigned i;
- mon_memzero(vm->page_usage, sizeof(vm->page_usage));
+ memset(vm->page_usage, 0, sizeof(vm->page_usage));
for (i=0; i<vm->pages.guest_n_pages; i++) {
/* For now, we start out by preallocating physical pages */
/* for the guest, though not necessarily mapped into linear */
@@ -1128,7 +1129,7 @@
getCpuResetValues(guest_cpu_t *cpu)
{
/* Set fields in a guest_cpu_t structure to RESET values */
- mon_memzero(cpu, sizeof(*cpu));
+ memset(cpu, 0, sizeof(*cpu));
/* General Registers */
cpu->eax = 0; /* processor tests passed */
@@ -1465,7 +1466,7 @@
/* Copy monitor message to user space */
- mon_memcpy(user_msgs, &vm->mon_msgs,
+ memcpy(user_msgs, &vm->mon_msgs,
vm->mon_msgs.header.msg_len + sizeof(vm->mon_msgs.header));
/*if (vm->log_buffer_info.event && !vm->log_buffer_info.locked)
@@ -1479,7 +1480,7 @@
vm->mon_msgs.header.msg_type = VMMessagePanic;
vm->mon_msgs.header.msg_len = 0;
- mon_memcpy(user_msgs, &vm->mon_msgs,
+ memcpy(user_msgs, &vm->mon_msgs,
vm->mon_msgs.header.msg_len + sizeof(vm->mon_msgs.header));
/*if (vm->log_buffer_info.event && !vm->log_buffer_info.locked)
@@ -1594,8 +1595,8 @@
//unsigned size;
/* clear out allocated pages lists */
- mon_memzero(pg, sizeof(*pg));
- mon_memzero(ad, sizeof(*ad));
+ memset(pg, 0, sizeof(*pg));
+ memset(ad, 0, sizeof(*ad));
/* Guest physical memory pages */
@@ -1950,8 +1951,8 @@
/* clear out allocated pages lists */
- mon_memzero(pg, sizeof(*pg));
- mon_memzero(ad, sizeof(*ad));
+ memset(pg, 0, sizeof(*pg));
+ memset(ad, 0, sizeof(*ad));
}
unsigned
diff -ur plex86/kernel/paging-mon.c plex86.mod1/kernel/paging-mon.c
--- plex86/kernel/paging-mon.c Sun Jun 10 12:15:36 2001
+++ plex86.mod1/kernel/paging-mon.c Wed Mar 6 10:27:11 2002
@@ -20,6 +20,7 @@
*/
+#include <linux/string.h>
#include "plex86.h"
#define IN_MONITOR_SPACE
#include "monitor.h"
@@ -706,7 +707,7 @@
/* Allocate PT using paged scheme. */
pt_index = allocatePT(vm, pdi);
monPTbl = &vm->guest.addr.page_tbl[pt_index];
- mon_memzero(monPTbl, sizeof(*monPTbl));
+ memset(monPTbl, 0, sizeof(*monPTbl));
}
if (vm->guest_cpu.cpl==3) {
@@ -747,7 +748,7 @@
/* Allocate PT using non-paged scheme. */
pt_index = allocatePT(vm, pdi);
monPTbl = &vm->guest.addr.page_tbl[pt_index];
- mon_memzero(monPTbl, 4096);
+ memset(monPTbl, 0, 4096);
/* Base/Avail=0/G=0/PS=0/D=0/A=0/PCD=0/PWT=0/US=1/RW=1/P=1 */
monPDE->raw =
(vm->pages.page_tbl[pt_index] << 12) | 0x7;
diff -ur plex86/kernel/system-nexus.c plex86.mod1/kernel/system-nexus.c
--- plex86/kernel/system-nexus.c Thu Jun 7 10:38:42 2001
+++ plex86.mod1/kernel/system-nexus.c Wed Mar 6 10:27:20 2002
@@ -20,6 +20,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <linux/string.h>
#include "plex86.h"
#define IN_NEXUS_SPACE
#include "monitor.h"
@@ -176,7 +177,7 @@
{
unsigned p;
- mon_memzero(&vm->ioHandlers, sizeof(vm->ioHandlers));
+ memset(&vm->ioHandlers, 0, sizeof(vm->ioHandlers));
for (p=0; p<64*1024; p++) {
vm->ioHandlers.readHandlerID[p] = NoIOHandlerID;
vm->ioHandlers.writeHandlerID[p] = NoIOHandlerID;
Only in plex86/kernel: util-nexus.c