Commit graph

50 commits

Author SHA1 Message Date
Ernest Wong afbbf0cc7c Handle simultaneous kbd and mouse streams
Continuing from PR #184, fixes #182.

Two main changes:

1. Pulse the interrupt lines to ensure rising edge. Some say that the
controller clears the interrupt lines themselves after a small delay to
create a pulse:
   - http://www.os2museum.com/wp/ibm-ps2-model-50-keyboard-controller/
   - https://wiki.osdev.org/8259_PIC#What_does_the_8259_PIC_do.3F (paragraph 1)
although that contradicts with:
   - Section "Reading Keyboard Input" paragraph 3
     http://www.computer-engineering.org/ps2keyboard/#General%20Description%20FN
where they say the interrupts are cleared only after reading port 0x60.
Could possibly be because they are referring to the older AT
keyboard controller.

2. Wait until current byte has been read via port 0x60 before
changing between kbd and mouse queues. In hardware terms: inhibit kbd
and mouse communication, and don't overwrite the DBBOUT output buffer
until OBF is cleared. Interesting reading:
   - Section "Reading Keyboard Input" paragraph 1
     http://www.computer-engineering.org/ps2keyboard/#General%20Description%20FN
   - Disassembly "Main Entry" $0102
     http://www.halicery.com/8042/8042_1503033.TXT

Unlike PR #184, this gives kbd data priority over mouse data (as it used
to), and this seems to avoid requiring timers to expire abandoned bytes.
2020-07-21 20:10:13 -05:00
Fabian 975a06269e Squash
2e469796 Minor
fab422ef Improve generation of 0f instructions
08ad7fe9 Improved if-else generation
3f81014d Minor: Align test output
4a3a84ef Generate modrm tests
61aa1875 Simplify
a6e47954 Generate decoding of immediate operands
435b2c10 Fix warnings
e4933042 Add missing immediate operand
3f3810c7 Generate immediate operands for instructions with modrm byte
a0aa7b1f Make memory layout in nasm tests clearer
6b8ef212 Remove 'g' property from instruction table (implied by 'e')
bf15c58c Remove unused declarations
1e543035 Remove useless `| 0` and `>>> 0` javascriptisms
1ccc5d53 Fix headers
8b40c532 Update qemu tests with changes from qemu
ec9b0fb5 Port xchg instructions to C
c73613e7 Port virt_boundary_* to C
d61d1241 Add headers
fd19f22c Make written value in write8 and write16 int32_t
497dcaec Generate read_imm for instructions with a modrm byte
8b7003d6 Generate read_imm8s
0cc75498 Remove read_op
9d716086 Trigger unimplemented_sse for partial sse instructions with prefix
8d5edd03 Remove unimplmented sse c-to-js hack
585d3565 Remove | 0
308124b2 Use int32_t as return value
f193f8e1 Use JS version of cvttsd2si for now
12747b97 Generate trigger_ud for missing modrm branches
770f674e Split 0f00 and 0f01 into multiple instructions depending on modrm bits
1cb372a3 Generate decoder for some 0f-prefix instructions
cec7bc63 Disable unused parameter warnings in instruction functions
807665b1 Generate read_imm for 0f/jmpcc
cdf6eccc Generate modrm decoding for shld
04528429 Create temporary files in /tmp/, not cwd
d8f3fbd8 Generate modrm/imm decoding for shld
00ef0942 Generate modrm decoding for bts
f531984b Generate modrm decoding for shrd and imul
07569c53 Generate modrm decoding cmpxchg
535ff190 Generate modrm decoding for lfs/lgs/lss
2f8ced8d Generate modrm decoding for btr and btc
95de6c66 Generate modrm decoding for movzx
c4d07e7e Generate modrm decoding for bsf and bsr
f0985d26 Generate modrm decoding for movsx
4b30937a Generate modrm decoding for xadd
a422eb27 Generate modrm decoding for movnti
e5501d3c Generate modrm decoding for mov to/from control/debug registers
bce11ec5 Generate modrm decoding for lar/lsl
5729a23c Fix access to DR4 and DR5 when cr4.DE is clear
44269a81 Specify immediate size explicitly instead of inferring it
82b2867a Fix STR instruction
98a9cc89 Log failing assertion
6d2f9964 Fix rdtsc
00260694 Log GP exceptions
7916883d Port trigger_ud and trigger_nm to C
36fedae9 Remove unused code
e08fabd0 Generate modrm decoding for 0f00 and 0f01
8ae8174d Generate modrm decoding for 0fae and 0fc7 (fxsave, cmpxchg8, etc.)
26168164 Generate modrm+immediate decoding for 0fba (bit test with immediate operand)
6adf7fa7 Simplify create_tests.js (unused prefix call)
c77cbdd8 Add comments about the implementation of pop [addr]
4640b4fe Simplify prefix call
a81a5497 Don't use var
3ca5d13d Separate call name and arguments in code generator
3191a543 Simplify other prefix call (8D/lea)
5185080e Update generated code (stylistic changes and #ud generation)
93b51d41 Remove unused wasm externals
e4af0a7f Avoid hardcoding special cases in code generator (lea, pop r/m)
654a2b49 Avoid hardcoding special cases in code generator (enter/jumpf/callf)
fd1a1e86 Commit generated code (only stylistic changes)
7310fd1a Simplify code generator by merging code for with and without 0f prefix
e7eae4af Simplify code generator by merging code for immediate operands
00fafd8a Improve assertions
db084e49 Simplify code generator (modrm if-else)
0a0e4c9e Improve code generation of switch-case
ce292795 Clarify some comments
37cf33fa Generate code in if/else blocks
cbcc33fc Document naming scheme
e30b97eb Generate modrm decoding for 0f12 (sse) instruction
24b72c2f movlpd cannot be used for register-to-register moves
72d72995 Generate modrm decoding for 0f13 (sse) instruction and disable register-to-register moving
75d76fbb Generate modrm decoding for 0f14 (sse) instruction
ac8965a7 Generate modrm decoding for 0f28-0f2b (movap, movntp)
e919d33e Generate modrm decoding for cvttsd2si
5f2ca2b4 Generate modrm decoding for andp and xorp
c8d1c6de Generate modrm decoding for 0f60-0f70 (sse instructions)
ae4ed46d Add multi-byte nop and prefetch to nasm test, generate modrm decoding
718a1acf Print qemu test error message more useful
d1ecc37e Generate modrm decoding for 0f70-0f80 (sse instructions)
6a7219a5 Generate modrm decoding for popcnt
25278217 Generate modrm decoding for 0f71-0f73 (sse shift with immediate byte)
ed1ec81b Generate modrm decoding for the remaining sse instructions (0fc0-0fff)
42bc5a6f Use 64-bit multiplication for native code
dda3fb39 Remove old modrm-decoding functions
717975ef Move register access functions to cpu.c
aee8138f Remove read_op, read_sib, read_op0F, read_disp
f31317f2 Rename xmm/mmx register access functions
a525e70b Remove 32-bit access to reg_xmm and reg_mmx
c803eabc Rename s8/s16/s32 to i8/i16/i32
9fbd2ddf Don't use uninitialised structs
942eb4f7 Use 64-bit load for mmx registers and assert reg64 and reg128 size
f94ec612 Use 64-bit writes for write_xmm64
08022de9 Use more efficient method for some 128-bit stores
9d5b084c Make timestamp counter unsigned
2ef388b3 Pass 64-bit value to safe_write64
4cb2b1be Optimise safe_write64 and safe_write128
b0ab09fb Implement psllq (660ff3)
9935e5d4 Optimise safe_read64s and safe_read128s
af9ea1cc Log cl in cpuid only if relevant
be5fe23e Add multi-op cache (disabled by default through ENABLE_JIT macro) and JIT paging test (similar to QEMU test).
aa2f286e Don't initialise group_dirtiness with 1 as it increases the binary size significantly
b8e14ed9 Remove unused reg_xmm32s
bc726e03 Implement dbg_log for native code with format characters 'd' and 'x'
454039d6 Fix store task register
63a4b349 Remove unnecessary parens and clean up some log statements
4cc96814 Add logop and dbg_trace imports
7940655d Only inhibit interrupts if the interrupt flag was 0 in STI
876c68a7 Split create_tests into create_tests and generate_interpreter
aa82499f Move detection of string instructions to x86_table
f3840ec2 Move C ast to separate file
90400703 Skip tests for lfence/mfence/sfence, clarify their encoding
4a9d8204 elf: Hide log messages when log level is zero
a601c526 Allow setting log level via settings
8a624453 Add cpu_exception_hook to debug builds
f9e335bf Nasm: Test exceptions
599ad088 logop: Format instruction pointer as unsigned
f95cf22b Don't skip zero dividing tests
2a655a0e Remove get_seg_prefix_ds from read_moffs (preparation for calling read_moffs from the code generator)
bc580b71 Remove obsolete comment
e556cee0 Fix nasmtest dependencies in makefile and clean
dcb1e72b Use all cores on travis
86efa737 Replace all instances of u32 & 0xFFFF with the respective u16 accesses
98b9f439 Use u8 instead of bit-shifts and masks from u32
b43f6569 Replace all instances of u32 >> 16 with the respective u16 accesses
9bfa72c7 Remove unnecessary parens
9cf93734 Clean up remaining instance of u32 with a mask instead of u16
22d4117f Correct order of writes in virt_boundary_write32
6734c7c1 Fix keyboard on ios, fixes #105
858a4506 Add missing file, c_ast.js
1d62e39e Move instruction naming scheme into function
f4816852 Reorder some code
69d49788 Minor improvements
0493e05f Add util.js
af9000c1 Improve full test
e5feba31 Add missing export
c7c42065 Replace prefix_call with custom_resolve_modrm
3186e6ad Add support for "%%" format string to dbg_log_wasm for printf import
efe54fad Add barebones instrumentation profiler (disabled by default).
c9f0d462 Implement movlps m64, xmm and enable its test
42869a12 Add tests for cross-page reads/writes confirmed with byte reads/writes
d68976ea Mask word values in port byte reads
9758d51e Add PS2_LOG_VERBOSE
5f52f037 Update NASM Makefile to include all dependencies to prevent unnecessary recompilation
2c71f927 Have NASM test generator use a seedable PRNG to allow for faster incremental tests
e4aa45bb Add chunk{16,32}_rw paging tests; instructions that read and write to memory
bdf538a2 add codegen to cpu constructor
aa76ce8e add resolve_modrm16
14d7ecf1 refactor codegen
b710319f [rebased] Merge branch codegen
0565ea42 minor refactoring
071dff3f temporary fix for automatic cast warnings
57c504f2 fix modrm16 issue
c2db5d9e jit modrm32
85c04245 reinstate modrm_fn0 and modrm_fn1
be65dafd add ip and previous ip manipulating functions
ae00ef89 update codegen js interface
530a74fa squashed commit for refactor
2c692199 add codegen-test to build
c15afe68 prefix gen to codegen api
c9611533 codegen tests fixes
2020-07-21 20:10:12 -05:00
copy 461e3e7b5b PS2 minor changes 2017-05-24 15:09:50 -05:00
copy b185430f21 Minor: Semicolons 2017-05-24 11:50:19 -05:00
copy f43ed236f7 Fix sample rate for reactos, #115 2016-11-28 01:46:41 +01:00
copy a7a8c271cb Correct handling of lowering irqs 2016-11-21 20:09:03 +01:00
copy cdd1c77230 PS2: Disable scaling2 2016-07-18 02:12:15 +02:00
copy 96272495a3 Disable sample rate checks in ps2 for now 2016-02-14 23:55:38 +01:00
copy d3fdc19f3e Small changes 2016-02-05 15:51:20 +01:00
copy 0b54162c82 Report auxillary bit correctly in ps2 controller. Fixes #63 2015-12-31 01:28:53 +01:00
copy d7dac7c9b4 Prepare for Closure Compiler's new type inference 2015-12-30 23:30:54 +01:00
copy 7fba276f86 Fix warnings 2015-09-15 21:58:40 +02:00
copy 9191da081a Increase size of keyboard and mouse buffer 2015-09-15 20:10:24 +02:00
copy f557156256 trailing whitespace 2015-09-12 01:10:38 +02:00
copy f82373d6b2 Build state of emulator explicitly. Fixes #40 2015-05-18 22:18:59 +02:00
copy 3ee6f37ca0 Remove use of get_isr 2015-05-17 01:59:15 +02:00
copy 3a824eda12 Change handling of interrupts to involve APIC 2015-05-17 01:56:50 +02:00
copy ecb7797ad6 Send extra byte after keyboard reset 2015-03-19 15:35:31 +01:00
copy 137c7a481d Fix mouse enabling after restore state 2015-03-18 20:24:23 +01:00
copy 27ced06ac9 Some annotations 2015-02-25 18:21:54 +01:00
copy a0da169168 Make _state_skip work by value (instead of key). Fixes certain Closure Compiler builds 2015-01-12 18:05:10 +01:00
copy b0ac56d85f Renaming 2015-01-09 04:05:32 +01:00
copy 901dfbc8ce start with mouse disabled 2014-12-27 00:22:07 +01:00
copy 13511362d7 refactor communication between emulated devices and browser implementation using Bus. Web worker comming soon ;) 2014-12-25 02:32:18 +01:00
copy b47e5d7233 code restructuring 2014-12-21 18:11:22 +01:00
copy 2e4c5ffe4b speed depends on sample rate, fixes mouse speed in windows 1.01 2014-12-13 00:13:18 +01:00
copy 5fd2a1bd35 Improved handling of IO port operations 2014-10-21 21:51:42 +02:00
Fabian 9b031d4e40 Initial version of save/restore state feature, #18
Everything that is valid json plus arraybuffers and arraybuffer-views
can be restored automatically (without making changes to other code).
Properties that should not be part of the state buffer needed to be
annotated using a magic `_state_skip` property. Shared arraybuffer views
are broken during restoration and also need to be annotated. Adapters
are not (and should never be) saved.

Current limitations:
- Before restoring, the cpu needs to be initialised with the original
  settings. This is not a hard requirement and can be fixed later.
- Pending asynchronous operations are lost. It's a good idea to pause
  the cpu before saving the state.
2014-09-28 22:10:47 -07:00
Fabian 5c4c74b329 Rewrite to prototypical notation 2014-09-26 19:27:50 -07:00
copy fe64919043 Fix PS/2 irq on port data 2014-07-09 02:25:37 +02:00
copy ea428dfa86 Keep last byte sent to port 60h. Fixes clock.com 2014-06-29 21:28:33 +02:00
copy 3505537898 Fix spurious ack 2014-06-22 19:35:50 +02:00
copy dac74191e6 Don't accept inputs when emulator is paused or crashed 2014-06-16 20:56:42 +02:00
copy deeff85f8b Merge branch 'master' of https://github.com/copy/v86
Conflicts:
	src/cpu.macro.js
	src/floppy.js
	src/instructions.macro.js
	src/modrm.macro.js
	src/node/main.js
2014-06-15 22:54:12 +02:00
copy 7a731ca061 Change CPU from closure to prototypical notation.
This change was necessary for several reasons:

- Code is much clearer and more modular
- The CPU object is now serializeable and therefore can be safed and
  restored
- A dynamic translator from instructions to (optimized) JavaScript is
  planned. It would use `new Function` to create functions at runtime.
  Functions created this way don't have access to any scope (except for
  the global scope) and therefore were not have been able to modify
  registers, etc. This is now possible through the cpu object
- Possibly, but not necessarily a speedgain can be achieved.
  See http://mrale.ph/blog/2012/09/23/grokking-v8-closures-for-fun.html

Additionally, some code was moved around.
2014-06-15 22:25:17 +02:00
copy 86f3fc633b Some improvments in PS2 controller 2014-03-27 04:09:50 +01:00
copy 5d64c5e222 Smoother mouse movement 2014-02-23 01:04:31 +01:00
copy 867dd024c8 Some fixes 2014-02-19 22:44:35 +01:00
copy fa7f6db6e7 Send floats to ps2 controller, make default resolution reasonable 2014-02-19 02:20:41 +01:00
copy b08340cf73 resolution and scaling 2014-02-19 01:49:22 +01:00
copy 51c5009cfe Some cleanup 2014-01-10 23:10:47 +01:00
copy 95beea11ea Fix no keyup packet 2014-01-08 03:17:36 +01:00
copy 48f408b5e8 Move Queue to general library 2014-01-06 13:26:56 +01:00
copy 57529427d1 correctly disable mouse streaming 2014-01-05 03:20:29 +01:00
copy 7601ac8614 No IRQ if disabled by controller 2014-01-02 05:06:38 +01:00
copy 02742993de Several fixes in PS2 controller 2014-01-02 00:55:53 +01:00
copy 039a892a76 Fixups 2013-12-30 01:30:58 +01:00
copy 596044378e Improved PS2 mouse/kbd queue 2013-12-30 00:37:42 +01:00
copy 0a401c7a4f small changes in ps2 2013-12-28 23:16:43 +01:00
copy 8180d49f24 first public release 2013-11-06 01:12:55 +01:00