History log of /netbsd-current/tests/lib/libnvmm/h_mem_assist.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.20 27-Dec-2020 reinoud

Implement support for trapping REP CMPS instructions in NVMM.

Qemu would abort hard when NVMM would get a memory trap on the instruction
since it didn't know it.


# 1.19 05-Sep-2020 maxv

nvmm: update copyright headers


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.18 22-Nov-2019 maxv

Several improvements. In particular, reduce CS.limit, because Intel CPUs
perform strict sanity checks, and the previous (too high) limit caused the
VM entry to fail.


Revision tags: phil-wifi-20191119
# 1.17 27-Oct-2019 maxv

Add the "nvmm" group, and make nvmm_init() public. Sent to tech-kern@ a few
days ago.


# 1.16 23-Oct-2019 maxv

Three changes in libnvmm:

- Add 'mach' and 'vcpu' backpointers in the nvmm_io and nvmm_mem
structures.

- Rename 'nvmm_callbacks' to 'nvmm_assist_callbacks'.

- Rename and migrate NVMM_MACH_CONF_CALLBACKS to NVMM_VCPU_CONF_CALLBACKS,
it now becomes per-VCPU.


# 1.15 23-Oct-2019 maxv

Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.

- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.

- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().

- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.

- Slightly reorganize the MI/MD definitions, for internal clarity.

- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.

- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t

- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.

- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.

- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.

- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.


# 1.14 14-Oct-2019 maxv

Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.


# 1.13 14-Oct-2019 christos

add missing initializer


# 1.12 13-Oct-2019 maxv

Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.11 08-Jun-2019 maxv

branches: 1.11.2; 1.11.4;
Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.19 05-Sep-2020 maxv

nvmm: update copyright headers


Revision tags: phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.18 22-Nov-2019 maxv

Several improvements. In particular, reduce CS.limit, because Intel CPUs
perform strict sanity checks, and the previous (too high) limit caused the
VM entry to fail.


Revision tags: phil-wifi-20191119
# 1.17 27-Oct-2019 maxv

Add the "nvmm" group, and make nvmm_init() public. Sent to tech-kern@ a few
days ago.


# 1.16 23-Oct-2019 maxv

Three changes in libnvmm:

- Add 'mach' and 'vcpu' backpointers in the nvmm_io and nvmm_mem
structures.

- Rename 'nvmm_callbacks' to 'nvmm_assist_callbacks'.

- Rename and migrate NVMM_MACH_CONF_CALLBACKS to NVMM_VCPU_CONF_CALLBACKS,
it now becomes per-VCPU.


# 1.15 23-Oct-2019 maxv

Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.

- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.

- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().

- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.

- Slightly reorganize the MI/MD definitions, for internal clarity.

- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.

- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t

- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.

- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.

- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.

- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.


# 1.14 14-Oct-2019 maxv

Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.


# 1.13 14-Oct-2019 christos

add missing initializer


# 1.12 13-Oct-2019 maxv

Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.11 08-Jun-2019 maxv

branches: 1.11.2; 1.11.4;
Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.18 22-Nov-2019 maxv

Several improvements. In particular, reduce CS.limit, because Intel CPUs
perform strict sanity checks, and the previous (too high) limit caused the
VM entry to fail.


Revision tags: phil-wifi-20191119
# 1.17 27-Oct-2019 maxv

Add the "nvmm" group, and make nvmm_init() public. Sent to tech-kern@ a few
days ago.


# 1.16 23-Oct-2019 maxv

Three changes in libnvmm:

- Add 'mach' and 'vcpu' backpointers in the nvmm_io and nvmm_mem
structures.

- Rename 'nvmm_callbacks' to 'nvmm_assist_callbacks'.

- Rename and migrate NVMM_MACH_CONF_CALLBACKS to NVMM_VCPU_CONF_CALLBACKS,
it now becomes per-VCPU.


# 1.15 23-Oct-2019 maxv

Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.

- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.

- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().

- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.

- Slightly reorganize the MI/MD definitions, for internal clarity.

- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.

- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t

- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.

- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.

- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.

- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.


# 1.14 14-Oct-2019 maxv

Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.


# 1.13 14-Oct-2019 christos

add missing initializer


# 1.12 13-Oct-2019 maxv

Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.11 08-Jun-2019 maxv

branches: 1.11.2; 1.11.4;
Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.17 27-Oct-2019 maxv

Add the "nvmm" group, and make nvmm_init() public. Sent to tech-kern@ a few
days ago.


# 1.16 23-Oct-2019 maxv

Three changes in libnvmm:

- Add 'mach' and 'vcpu' backpointers in the nvmm_io and nvmm_mem
structures.

- Rename 'nvmm_callbacks' to 'nvmm_assist_callbacks'.

- Rename and migrate NVMM_MACH_CONF_CALLBACKS to NVMM_VCPU_CONF_CALLBACKS,
it now becomes per-VCPU.


# 1.15 23-Oct-2019 maxv

Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.

- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.

- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().

- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.

- Slightly reorganize the MI/MD definitions, for internal clarity.

- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.

- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t

- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.

- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.

- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.

- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.


# 1.14 14-Oct-2019 maxv

Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.


# 1.13 14-Oct-2019 christos

add missing initializer


# 1.12 13-Oct-2019 maxv

Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.11 08-Jun-2019 maxv

branches: 1.11.2;
Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.16 23-Oct-2019 maxv

Three changes in libnvmm:

- Add 'mach' and 'vcpu' backpointers in the nvmm_io and nvmm_mem
structures.

- Rename 'nvmm_callbacks' to 'nvmm_assist_callbacks'.

- Rename and migrate NVMM_MACH_CONF_CALLBACKS to NVMM_VCPU_CONF_CALLBACKS,
it now becomes per-VCPU.


# 1.15 23-Oct-2019 maxv

Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.

- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.

- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().

- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.

- Slightly reorganize the MI/MD definitions, for internal clarity.

- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.

- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t

- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.

- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.

- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.

- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.


# 1.14 14-Oct-2019 maxv

Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.


# 1.13 14-Oct-2019 christos

add missing initializer


# 1.12 13-Oct-2019 maxv

Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.11 08-Jun-2019 maxv

branches: 1.11.2;
Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.15 23-Oct-2019 maxv

Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.

- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.

- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().

- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.

- Slightly reorganize the MI/MD definitions, for internal clarity.

- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.

- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t

- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.

- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.

- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.

- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.


# 1.14 14-Oct-2019 maxv

Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.


# 1.13 14-Oct-2019 christos

add missing initializer


# 1.12 13-Oct-2019 maxv

Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.11 08-Jun-2019 maxv

branches: 1.11.2;
Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.14 14-Oct-2019 maxv

Implement XCHG, add associated tests, and add comments to explain. With
this in place the Windows 95 installer completes successfuly.

Part of PR/54611.


# 1.13 14-Oct-2019 christos

add missing initializer


# 1.12 13-Oct-2019 maxv

Fix incorrect parsing: the R/M field uses a special GPR map when the
address size is 16 bits, regardless of the actual operating mode. With
this special map there can be two registers referenced at once, and
also disp16-only.

Implement this special behavior, and add associated tests. While here
simplify a few things.

With this in place, the Windows 95 installer initializes correctly.

Part of PR/54611.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.11 08-Jun-2019 maxv

branches: 1.11.2;
Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.11 08-Jun-2019 maxv

Change the NVMM API to reduce data movements. Sent to tech-kern@.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.10 11-May-2019 maxv

Rework the machine configuration interface.

Provide three ranges in the conf space: <libnvmm:0-100>, <MI:100-200> and
<MD:200-...>. Remove nvmm_callbacks_register(), and replace it by the conf
op NVMM_MACH_CONF_CALLBACKS, handled by libnvmm. The callbacks are now
per-machine, and the emulators should now do:

- nvmm_callbacks_register(&cbs);
+ nvmm_machine_configure(&mach, NVMM_MACH_CONF_CALLBACKS, &cbs);

This provides more granularity, for example if the process runs two VMs
and wants different callbacks for each.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.


# 1.9 22-Mar-2019 htodd

Fix build break due to typos.


# 1.8 21-Mar-2019 maxv

Make it possible for an emulator to set the protection of the guest pages.
For some reason I had initially concluded that it wasn't doable; verily it
is, so let's do it.

The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes
mmap-like protection codes.


# 1.7 19-Mar-2019 maxv

Add CVS ids, and rename the PTE bits. No functional change.


# 1.6 26-Feb-2019 maxv

Change the layout of the SEG state:

- Reorder it, to match the CPU encoding. This is the universal order,
also used by Qemu. Drop the seg_to_nvmm[] tables.

- Compress it. This divides its size by two.

- Rename some of its fields, to better match the x86 spec. Also, take S
out of Type, this was a NetBSD-ism that was likely confusing to other
people.


# 1.5 07-Feb-2019 maxv

Improvements:

- Emulate the instructions by executing them directly on the host CPU.
This is easier and probably faster than doing it in software
manually.

- Decode SUB from Primary, CMP from Group1, TEST from Group3, and add
associated tests.

- Handle correctly the cases where an instruction that always implicitly
reads the register operand is executed with the mem operand as source
(eg: "orq (%rbx),%rax").

- Fix the MMU handling of 32bit-PAE. Under PAE CR3 is not page-aligned,
so there are extra bits that are valid.

With these changes in place I can boot Windows XP on Qemu+NVMM.


# 1.4 01-Feb-2019 maxv

Fix two issues:

* Uh I put the wrong masks in some GPRs, fuck.

* When the opsize of MOVZX is 4, we need to combine the zero-extend from
the instruction with the natural zero-extend of long mode.

Add two associated tests.


# 1.3 01-Feb-2019 maxv

Put correct values in the seg fields. AMD doesn't check for that, but Intel
does, so they need to be correct.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118
# 1.2 27-Dec-2018 maxv

Several improvements and fixes:

* Change the Assist API. Rather than passing callbacks in each call, the
callbacks are now registered beforehand. Then change the I/O Assist to
fetch MMIO data via the Mem callback. This allows a guest to perform an
I/O string operation on a memory that is itself an MMIO.

* Introduce two new functions internal to libnvmm, read_guest_memory and
write_guest_memory. They can handle mapped memory, MMIO memory and
cross-page transactions.

* Allow nvmm_gva_to_gpa and nvmm_gpa_to_hva to take non-page-aligned
addresses. This simplifies a lot of things.

* Support the MOVS instruction, and add a test for it. This instruction
is special, in that it takes two implicit memory operands. In
particular, it means that the two buffers can both be in MMIO memory,
and we handle this case.

* Fix gross copy-pasto in nvmm_hva_unmap. Also fix a few things here and
there.


Revision tags: pgoyette-compat-1226
# 1.1 23-Dec-2018 maxv

branches: 1.1.2;
Add initial tests for libnvmm's Mem Assist, with 8 test cases.